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) 2016 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad
-/
import Mathlib.Data.Int.Bitwise
import Mathlib.Data.Int.Order.Lemmas
import Mathlib.Data.Set.Function
import Mathlib.Data.Set.Monotone
import Mathlib.Order.Interval.Set.Defs
/-!
# Miscellaneous lemmas about the integers
This file contains lemmas about integers, which require further imports than
`Data.Int.Basic` or `Data.Int.Order`.
-/
open Nat
namespace Int
theorem le_natCast_sub (m n : β) : (m - n : β€) β€ β(m - n : β) := by
by_cases h : m β₯ n
Β· exact le_of_eq (Int.ofNat_sub h).symm
Β· simp [le_of_not_ge h, ofNat_le]
/-! ### `succ` and `pred` -/
theorem succ_natCast_pos (n : β) : 0 < (n : β€) + 1 :=
lt_add_one_iff.mpr (by simp)
/-! ### `natAbs` -/
theorem natAbs_eq_iff_sq_eq {a b : β€} : a.natAbs = b.natAbs β a ^ 2 = b ^ 2 := by
rw [sq, sq]
exact natAbs_eq_iff_mul_self_eq
theorem natAbs_lt_iff_sq_lt {a b : β€} : a.natAbs < b.natAbs β a ^ 2 < b ^ 2 := by
rw [sq, sq]
exact natAbs_lt_iff_mul_self_lt
theorem natAbs_le_iff_sq_le {a b : β€} : a.natAbs β€ b.natAbs β a ^ 2 β€ b ^ 2 := by
rw [sq, sq]
exact natAbs_le_iff_mul_self_le
theorem natAbs_inj_of_nonneg_of_nonneg {a b : β€} (ha : 0 β€ a) (hb : 0 β€ b) :
natAbs a = natAbs b β a = b := by rw [β sq_eq_sqβ ha hb, β natAbs_eq_iff_sq_eq]
theorem natAbs_inj_of_nonpos_of_nonpos {a b : β€} (ha : a β€ 0) (hb : b β€ 0) :
natAbs a = natAbs b β a = b := by
simpa only [Int.natAbs_neg, neg_inj] using
natAbs_inj_of_nonneg_of_nonneg (neg_nonneg_of_nonpos ha) (neg_nonneg_of_nonpos hb)
theorem natAbs_inj_of_nonneg_of_nonpos {a b : β€} (ha : 0 β€ a) (hb : b β€ 0) :
natAbs a = natAbs b β a = -b := by
simpa only [Int.natAbs_neg] using natAbs_inj_of_nonneg_of_nonneg ha (neg_nonneg_of_nonpos hb)
theorem natAbs_inj_of_nonpos_of_nonneg {a b : β€} (ha : a β€ 0) (hb : 0 β€ b) :
natAbs a = natAbs b β -a = b := by
simpa only [Int.natAbs_neg] using natAbs_inj_of_nonneg_of_nonneg (neg_nonneg_of_nonpos ha) hb
/-- A specialization of `abs_sub_le_of_nonneg_of_le` for working with the signed subtraction
of natural numbers. -/
theorem natAbs_coe_sub_coe_le_of_le {a b n : β} (a_le_n : a β€ n) (b_le_n : b β€ n) :
natAbs (a - b : β€) β€ n := by
rw [β Nat.cast_le (Ξ± := β€), natCast_natAbs]
exact abs_sub_le_of_nonneg_of_le (ofNat_nonneg a) (ofNat_le.mpr a_le_n)
(ofNat_nonneg b) (ofNat_le.mpr b_le_n)
/-- A specialization of `abs_sub_lt_of_nonneg_of_lt` for working with the signed subtraction
of natural numbers. -/
theorem natAbs_coe_sub_coe_lt_of_lt {a b n : β} (a_lt_n : a < n) (b_lt_n : b < n) :
natAbs (a - b : β€) < n := by
rw [β Nat.cast_lt (Ξ± := β€), natCast_natAbs]
exact abs_sub_lt_of_nonneg_of_lt (ofNat_nonneg a) (ofNat_lt.mpr a_lt_n)
(ofNat_nonneg b) (ofNat_lt.mpr b_lt_n)
section Intervals
open Set
theorem strictMonoOn_natAbs : StrictMonoOn natAbs (Ici 0) := fun _ ha _ _ hab =>
natAbs_lt_natAbs_of_nonneg_of_lt ha hab
theorem strictAntiOn_natAbs : StrictAntiOn natAbs (Iic 0) := fun a _ b hb hab => by
simpa [Int.natAbs_neg] using
natAbs_lt_natAbs_of_nonneg_of_lt (Right.nonneg_neg_iff.mpr hb) (neg_lt_neg_iff.mpr hab)
theorem injOn_natAbs_Ici : InjOn natAbs (Ici 0) :=
strictMonoOn_natAbs.injOn
theorem injOn_natAbs_Iic : InjOn natAbs (Iic 0) :=
strictAntiOn_natAbs.injOn
end Intervals
/-! ### bitwise ops
| This lemma is orphaned from `Data.Int.Bitwise` as it also requires material from `Data.Int.Order`.
-/
| Mathlib/Data/Int/Lemmas.lean | 104 | 106 |
/-
Copyright (c) 2021 Hunter Monroe. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Hunter Monroe, Kyle Miller, Alena Gusakov
-/
import Mathlib.Combinatorics.SimpleGraph.DeleteEdges
import Mathlib.Data.Fintype.Powerset
/-!
# Subgraphs of a simple graph
A subgraph of a simple graph consists of subsets of the graph's vertices and edges such that the
endpoints of each edge are present in the vertex subset. The edge subset is formalized as a
sub-relation of the adjacency relation of the simple graph.
## Main definitions
* `Subgraph G` is the type of subgraphs of a `G : SimpleGraph V`.
* `Subgraph.neighborSet`, `Subgraph.incidenceSet`, and `Subgraph.degree` are like their
`SimpleGraph` counterparts, but they refer to vertices from `G` to avoid subtype coercions.
* `Subgraph.coe` is the coercion from a `G' : Subgraph G` to a `SimpleGraph G'.verts`.
(In Lean 3 this could not be a `Coe` instance since the destination type depends on `G'`.)
* `Subgraph.IsSpanning` for whether a subgraph is a spanning subgraph and
`Subgraph.IsInduced` for whether a subgraph is an induced subgraph.
* Instances for `Lattice (Subgraph G)` and `BoundedOrder (Subgraph G)`.
* `SimpleGraph.toSubgraph`: If a `SimpleGraph` is a subgraph of another, then you can turn it
into a member of the larger graph's `SimpleGraph.Subgraph` type.
* Graph homomorphisms from a subgraph to a graph (`Subgraph.map_top`) and between subgraphs
(`Subgraph.map`).
## Implementation notes
* Recall that subgraphs are not determined by their vertex sets, so `SetLike` does not apply to
this kind of subobject.
## TODO
* Images of graph homomorphisms as subgraphs.
-/
universe u v
namespace SimpleGraph
/-- A subgraph of a `SimpleGraph` is a subset of vertices along with a restriction of the adjacency
relation that is symmetric and is supported by the vertex subset. They also form a bounded lattice.
Thinking of `V β V β Prop` as `Set (V Γ V)`, a set of darts (i.e., half-edges), then
`Subgraph.adj_sub` is that the darts of a subgraph are a subset of the darts of `G`. -/
@[ext]
structure Subgraph {V : Type u} (G : SimpleGraph V) where
/-- Vertices of the subgraph -/
verts : Set V
/-- Edges of the subgraph -/
Adj : V β V β Prop
adj_sub : β {v w : V}, Adj v w β G.Adj v w
edge_vert : β {v w : V}, Adj v w β v β verts
symm : Symmetric Adj := by aesop_graph -- Porting note: Originally `by obviously`
initialize_simps_projections SimpleGraph.Subgraph (Adj β adj)
variable {ΞΉ : Sort*} {V : Type u} {W : Type v}
/-- The one-vertex subgraph. -/
@[simps]
protected def singletonSubgraph (G : SimpleGraph V) (v : V) : G.Subgraph where
verts := {v}
Adj := β₯
adj_sub := False.elim
edge_vert := False.elim
symm _ _ := False.elim
/-- The one-edge subgraph. -/
@[simps]
def subgraphOfAdj (G : SimpleGraph V) {v w : V} (hvw : G.Adj v w) : G.Subgraph where
verts := {v, w}
Adj a b := s(v, w) = s(a, b)
adj_sub h := by
rw [β G.mem_edgeSet, β h]
exact hvw
edge_vert {a b} h := by
apply_fun fun e β¦ a β e at h
simp only [Sym2.mem_iff, true_or, eq_iff_iff, iff_true] at h
exact h
namespace Subgraph
variable {G : SimpleGraph V} {Gβ Gβ : G.Subgraph} {a b : V}
protected theorem loopless (G' : Subgraph G) : Irreflexive G'.Adj :=
fun v h β¦ G.loopless v (G'.adj_sub h)
theorem adj_comm (G' : Subgraph G) (v w : V) : G'.Adj v w β G'.Adj w v :=
β¨fun x β¦ G'.symm x, fun x β¦ G'.symm xβ©
@[symm]
theorem adj_symm (G' : Subgraph G) {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
protected theorem Adj.symm {G' : Subgraph G} {u v : V} (h : G'.Adj u v) : G'.Adj v u :=
G'.symm h
protected theorem Adj.adj_sub {H : G.Subgraph} {u v : V} (h : H.Adj u v) : G.Adj u v :=
H.adj_sub h
protected theorem Adj.fst_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u β H.verts :=
H.edge_vert h
protected theorem Adj.snd_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : v β H.verts :=
h.symm.fst_mem
protected theorem Adj.ne {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u β v :=
h.adj_sub.ne
theorem adj_congr_of_sym2 {H : G.Subgraph} {u v w x : V} (h2 : s(u, v) = s(w, x)) :
H.Adj u v β H.Adj w x := by
simp only [Sym2.eq, Sym2.rel_iff', Prod.mk.injEq, Prod.swap_prod_mk] at h2
rcases h2 with hl | hr
Β· rw [hl.1, hl.2]
Β· rw [hr.1, hr.2, Subgraph.adj_comm]
/-- Coercion from `G' : Subgraph G` to a `SimpleGraph G'.verts`. -/
@[simps]
protected def coe (G' : Subgraph G) : SimpleGraph G'.verts where
Adj v w := G'.Adj v w
symm _ _ h := G'.symm h
loopless v h := loopless G v (G'.adj_sub h)
@[simp]
theorem coe_adj_sub (G' : Subgraph G) (u v : G'.verts) (h : G'.coe.Adj u v) : G.Adj u v :=
G'.adj_sub h
-- Given `h : H.Adj u v`, then `h.coe : H.coe.Adj β¨u, _β© β¨v, _β©`.
protected theorem Adj.coe {H : G.Subgraph} {u v : V} (h : H.Adj u v) :
H.coe.Adj β¨u, H.edge_vert hβ© β¨v, H.edge_vert h.symmβ© := h
instance (G : SimpleGraph V) (H : Subgraph G) [DecidableRel H.Adj] : DecidableRel H.coe.Adj :=
fun a b β¦ βΉDecidableRel H.AdjβΊ _ _
/-- A subgraph is called a *spanning subgraph* if it contains all the vertices of `G`. -/
def IsSpanning (G' : Subgraph G) : Prop :=
β v : V, v β G'.verts
theorem isSpanning_iff {G' : Subgraph G} : G'.IsSpanning β G'.verts = Set.univ :=
Set.eq_univ_iff_forall.symm
protected alias β¨IsSpanning.verts_eq_univ, _β© := isSpanning_iff
/-- Coercion from `Subgraph G` to `SimpleGraph V`. If `G'` is a spanning
subgraph, then `G'.spanningCoe` yields an isomorphic graph.
In general, this adds in all vertices from `V` as isolated vertices. -/
@[simps]
protected def spanningCoe (G' : Subgraph G) : SimpleGraph V where
Adj := G'.Adj
symm := G'.symm
loopless v hv := G.loopless v (G'.adj_sub hv)
@[simp]
theorem Adj.of_spanningCoe {G' : Subgraph G} {u v : G'.verts} (h : G'.spanningCoe.Adj u v) :
G.Adj u v :=
G'.adj_sub h
lemma spanningCoe_le (G' : G.Subgraph) : G'.spanningCoe β€ G := fun _ _ β¦ G'.3
theorem spanningCoe_inj : Gβ.spanningCoe = Gβ.spanningCoe β Gβ.Adj = Gβ.Adj := by
simp [Subgraph.spanningCoe]
lemma mem_of_adj_spanningCoe {v w : V} {s : Set V} (G : SimpleGraph s)
(hadj : G.spanningCoe.Adj v w) : v β s := by aesop
@[simp]
lemma spanningCoe_subgraphOfAdj {v w : V} (hadj : G.Adj v w) :
(G.subgraphOfAdj hadj).spanningCoe = fromEdgeSet {s(v, w)} := by
ext v w
aesop
/-- `spanningCoe` is equivalent to `coe` for a subgraph that `IsSpanning`. -/
@[simps]
def spanningCoeEquivCoeOfSpanning (G' : Subgraph G) (h : G'.IsSpanning) :
G'.spanningCoe βg G'.coe where
toFun v := β¨v, h vβ©
invFun v := v
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
/-- A subgraph is called an *induced subgraph* if vertices of `G'` are adjacent if
they are adjacent in `G`. -/
def IsInduced (G' : Subgraph G) : Prop :=
β β¦vβ¦, v β G'.verts β β β¦wβ¦, w β G'.verts β G.Adj v w β G'.Adj v w
@[simp] protected lemma IsInduced.adj {G' : G.Subgraph} (hG' : G'.IsInduced) {a b : G'.verts} :
G'.Adj a b β G.Adj a b :=
β¨coe_adj_sub _ _ _, hG' a.2 b.2β©
/-- `H.support` is the set of vertices that form edges in the subgraph `H`. -/
def support (H : Subgraph G) : Set V := Rel.dom H.Adj
theorem mem_support (H : Subgraph G) {v : V} : v β H.support β β w, H.Adj v w := Iff.rfl
theorem support_subset_verts (H : Subgraph G) : H.support β H.verts :=
fun _ β¨_, hβ© β¦ H.edge_vert h
/-- `G'.neighborSet v` is the set of vertices adjacent to `v` in `G'`. -/
def neighborSet (G' : Subgraph G) (v : V) : Set V := {w | G'.Adj v w}
theorem neighborSet_subset (G' : Subgraph G) (v : V) : G'.neighborSet v β G.neighborSet v :=
fun _ β¦ G'.adj_sub
theorem neighborSet_subset_verts (G' : Subgraph G) (v : V) : G'.neighborSet v β G'.verts :=
fun _ h β¦ G'.edge_vert (adj_symm G' h)
@[simp]
theorem mem_neighborSet (G' : Subgraph G) (v w : V) : w β G'.neighborSet v β G'.Adj v w := Iff.rfl
/-- A subgraph as a graph has equivalent neighbor sets. -/
def coeNeighborSetEquiv {G' : Subgraph G} (v : G'.verts) :
G'.coe.neighborSet v β G'.neighborSet v where
toFun w := β¨w, w.2β©
invFun w := β¨β¨w, G'.edge_vert (G'.adj_symm w.2)β©, w.2β©
left_inv _ := rfl
right_inv _ := rfl
/-- The edge set of `G'` consists of a subset of edges of `G`. -/
def edgeSet (G' : Subgraph G) : Set (Sym2 V) := Sym2.fromRel G'.symm
theorem edgeSet_subset (G' : Subgraph G) : G'.edgeSet β G.edgeSet :=
Sym2.ind (fun _ _ β¦ G'.adj_sub)
@[simp]
protected lemma mem_edgeSet {G' : Subgraph G} {v w : V} : s(v, w) β G'.edgeSet β G'.Adj v w := .rfl
@[simp] lemma edgeSet_coe {G' : G.Subgraph} : G'.coe.edgeSet = Sym2.map (β) β»ΒΉ' G'.edgeSet := by
ext e; induction e using Sym2.ind; simp
lemma image_coe_edgeSet_coe (G' : G.Subgraph) : Sym2.map (β) '' G'.coe.edgeSet = G'.edgeSet := by
rw [edgeSet_coe, Set.image_preimage_eq_iff]
rintro e he
induction e using Sym2.ind with | h a b =>
rw [Subgraph.mem_edgeSet] at he
exact β¨s(β¨a, edge_vert _ heβ©, β¨b, edge_vert _ he.symmβ©), Sym2.map_pair_eq ..β©
theorem mem_verts_of_mem_edge {G' : Subgraph G} {e : Sym2 V} {v : V} (he : e β G'.edgeSet)
(hv : v β e) : v β G'.verts := by
induction e
rcases Sym2.mem_iff.mp hv with (rfl | rfl)
Β· exact G'.edge_vert he
Β· exact G'.edge_vert (G'.symm he)
/-- The `incidenceSet` is the set of edges incident to a given vertex. -/
def incidenceSet (G' : Subgraph G) (v : V) : Set (Sym2 V) := {e β G'.edgeSet | v β e}
theorem incidenceSet_subset_incidenceSet (G' : Subgraph G) (v : V) :
G'.incidenceSet v β G.incidenceSet v :=
fun _ h β¦ β¨G'.edgeSet_subset h.1, h.2β©
theorem incidenceSet_subset (G' : Subgraph G) (v : V) : G'.incidenceSet v β G'.edgeSet :=
fun _ h β¦ h.1
/-- Give a vertex as an element of the subgraph's vertex type. -/
abbrev vert (G' : Subgraph G) (v : V) (h : v β G'.verts) : G'.verts := β¨v, hβ©
/--
Create an equal copy of a subgraph (see `copy_eq`) with possibly different definitional equalities.
See Note [range copy pattern].
-/
def copy (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V β V β Prop) (hadj : adj' = G'.Adj) : Subgraph G where
verts := V''
Adj := adj'
adj_sub := hadj.symm βΈ G'.adj_sub
edge_vert := hV.symm βΈ hadj.symm βΈ G'.edge_vert
symm := hadj.symm βΈ G'.symm
theorem copy_eq (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts)
(adj' : V β V β Prop) (hadj : adj' = G'.Adj) : G'.copy V'' hV adj' hadj = G' :=
Subgraph.ext hV hadj
/-- The union of two subgraphs. -/
instance : Max G.Subgraph where
max Gβ Gβ :=
{ verts := Gβ.verts βͺ Gβ.verts
Adj := Gβ.Adj β Gβ.Adj
adj_sub := fun hab => Or.elim hab (fun h => Gβ.adj_sub h) fun h => Gβ.adj_sub h
edge_vert := Or.imp (fun h => Gβ.edge_vert h) fun h => Gβ.edge_vert h
symm := fun _ _ => Or.imp Gβ.adj_symm Gβ.adj_symm }
/-- The intersection of two subgraphs. -/
instance : Min G.Subgraph where
min Gβ Gβ :=
{ verts := Gβ.verts β© Gβ.verts
Adj := Gβ.Adj β Gβ.Adj
adj_sub := fun hab => Gβ.adj_sub hab.1
edge_vert := And.imp (fun h => Gβ.edge_vert h) fun h => Gβ.edge_vert h
symm := fun _ _ => And.imp Gβ.adj_symm Gβ.adj_symm }
/-- The `top` subgraph is `G` as a subgraph of itself. -/
instance : Top G.Subgraph where
top :=
{ verts := Set.univ
Adj := G.Adj
adj_sub := id
edge_vert := @fun v _ _ => Set.mem_univ v
symm := G.symm }
/-- The `bot` subgraph is the subgraph with no vertices or edges. -/
instance : Bot G.Subgraph where
bot :=
{ verts := β
Adj := β₯
adj_sub := False.elim
edge_vert := False.elim
symm := fun _ _ => id }
instance : SupSet G.Subgraph where
sSup s :=
{ verts := β G' β s, verts G'
Adj := fun a b => β G' β s, Adj G' a b
adj_sub := by
rintro a b β¨G', -, habβ©
exact G'.adj_sub hab
edge_vert := by
rintro a b β¨G', hG', habβ©
exact Set.mem_iUnionβ_of_mem hG' (G'.edge_vert hab)
symm := fun a b h => by simpa [adj_comm] using h }
instance : InfSet G.Subgraph where
sInf s :=
{ verts := β G' β s, verts G'
Adj := fun a b => (β β¦G'β¦, G' β s β Adj G' a b) β§ G.Adj a b
adj_sub := And.right
edge_vert := fun hab => Set.mem_iInterβ_of_mem fun G' hG' => G'.edge_vert <| hab.1 hG'
symm := fun _ _ => And.imp (forallβ_imp fun _ _ => Adj.symm) G.adj_symm }
@[simp]
theorem sup_adj : (Gβ β Gβ).Adj a b β Gβ.Adj a b β¨ Gβ.Adj a b :=
Iff.rfl
@[simp]
theorem inf_adj : (Gβ β Gβ).Adj a b β Gβ.Adj a b β§ Gβ.Adj a b :=
Iff.rfl
@[simp]
theorem top_adj : (β€ : Subgraph G).Adj a b β G.Adj a b :=
Iff.rfl
@[simp]
theorem not_bot_adj : Β¬ (β₯ : Subgraph G).Adj a b :=
not_false
@[simp]
theorem verts_sup (Gβ Gβ : G.Subgraph) : (Gβ β Gβ).verts = Gβ.verts βͺ Gβ.verts :=
rfl
@[simp]
theorem verts_inf (Gβ Gβ : G.Subgraph) : (Gβ β Gβ).verts = Gβ.verts β© Gβ.verts :=
rfl
@[simp]
theorem verts_top : (β€ : G.Subgraph).verts = Set.univ :=
rfl
@[simp]
theorem verts_bot : (β₯ : G.Subgraph).verts = β
:=
rfl
@[simp]
theorem sSup_adj {s : Set G.Subgraph} : (sSup s).Adj a b β β G β s, Adj G a b :=
Iff.rfl
@[simp]
theorem sInf_adj {s : Set G.Subgraph} : (sInf s).Adj a b β (β G' β s, Adj G' a b) β§ G.Adj a b :=
Iff.rfl
@[simp]
theorem iSup_adj {f : ΞΉ β G.Subgraph} : (β¨ i, f i).Adj a b β β i, (f i).Adj a b := by
simp [iSup]
@[simp]
theorem iInf_adj {f : ΞΉ β G.Subgraph} : (β¨
i, f i).Adj a b β (β i, (f i).Adj a b) β§ G.Adj a b := by
simp [iInf]
theorem sInf_adj_of_nonempty {s : Set G.Subgraph} (hs : s.Nonempty) :
(sInf s).Adj a b β β G' β s, Adj G' a b :=
sInf_adj.trans <|
and_iff_left_of_imp <| by
obtain β¨G', hG'β© := hs
exact fun h => G'.adj_sub (h _ hG')
theorem iInf_adj_of_nonempty [Nonempty ΞΉ] {f : ΞΉ β G.Subgraph} :
(β¨
i, f i).Adj a b β β i, (f i).Adj a b := by
rw [iInf, sInf_adj_of_nonempty (Set.range_nonempty _)]
simp
@[simp]
theorem verts_sSup (s : Set G.Subgraph) : (sSup s).verts = β G' β s, verts G' :=
rfl
@[simp]
theorem verts_sInf (s : Set G.Subgraph) : (sInf s).verts = β G' β s, verts G' :=
rfl
@[simp]
theorem verts_iSup {f : ΞΉ β G.Subgraph} : (β¨ i, f i).verts = β i, (f i).verts := by simp [iSup]
@[simp]
theorem verts_iInf {f : ΞΉ β G.Subgraph} : (β¨
i, f i).verts = β i, (f i).verts := by simp [iInf]
@[simp] lemma coe_bot : (β₯ : G.Subgraph).coe = β₯ := rfl
@[simp] lemma IsInduced.top : (β€ : G.Subgraph).IsInduced := fun _ _ _ _ β¦ id
/-- The graph isomorphism between the top element of `G.subgraph` and `G`. -/
def topIso : (β€ : G.Subgraph).coe βg G where
toFun := (β)
invFun a := β¨a, Set.mem_univ _β©
left_inv _ := Subtype.eta ..
right_inv _ := rfl
map_rel_iff' := .rfl
theorem verts_spanningCoe_injective :
(fun G' : Subgraph G => (G'.verts, G'.spanningCoe)).Injective := by
intro Gβ Gβ h
rw [Prod.ext_iff] at h
exact Subgraph.ext h.1 (spanningCoe_inj.1 h.2)
/-- For subgraphs `Gβ`, `Gβ`, `Gβ β€ Gβ` iff `Gβ.verts β Gβ.verts` and
`β a b, Gβ.adj a b β Gβ.adj a b`. -/
instance distribLattice : DistribLattice G.Subgraph :=
{ show DistribLattice G.Subgraph from
verts_spanningCoe_injective.distribLattice _
(fun _ _ => rfl) fun _ _ => rfl with
le := fun x y => x.verts β y.verts β§ β β¦v w : Vβ¦, x.Adj v w β y.Adj v w }
instance : BoundedOrder (Subgraph G) where
top := β€
bot := β₯
le_top x := β¨Set.subset_univ _, fun _ _ => x.adj_subβ©
bot_le _ := β¨Set.empty_subset _, fun _ _ => False.elimβ©
/-- Note that subgraphs do not form a Boolean algebra, because of `verts`. -/
def completelyDistribLatticeMinimalAxioms : CompletelyDistribLattice.MinimalAxioms G.Subgraph :=
{ Subgraph.distribLattice with
le := (Β· β€ Β·)
sup := (Β· β Β·)
inf := (Β· β Β·)
top := β€
bot := β₯
le_top := fun G' => β¨Set.subset_univ _, fun _ _ => G'.adj_subβ©
bot_le := fun _ => β¨Set.empty_subset _, fun _ _ => False.elimβ©
sSup := sSup
-- Porting note: needed `apply` here to modify elaboration; previously the term itself was fine.
le_sSup := fun s G' hG' => β¨by apply Set.subset_iUnionβ G' hG', fun _ _ hab => β¨G', hG', habβ©β©
sSup_le := fun s G' hG' =>
β¨Set.iUnionβ_subset fun _ hH => (hG' _ hH).1, by
rintro a b β¨H, hH, habβ©
exact (hG' _ hH).2 habβ©
sInf := sInf
sInf_le := fun _ G' hG' => β¨Set.iInterβ_subset G' hG', fun _ _ hab => hab.1 hG'β©
le_sInf := fun _ G' hG' =>
β¨Set.subset_iInterβ fun _ hH => (hG' _ hH).1, fun _ _ hab =>
β¨fun _ hH => (hG' _ hH).2 hab, G'.adj_sub habβ©β©
iInf_iSup_eq := fun f => Subgraph.ext (by simpa using iInf_iSup_eq)
(by ext; simp [Classical.skolem]) }
instance : CompletelyDistribLattice G.Subgraph :=
.ofMinimalAxioms completelyDistribLatticeMinimalAxioms
@[gcongr] lemma verts_mono {H H' : G.Subgraph} (h : H β€ H') : H.verts β H'.verts := h.1
lemma verts_monotone : Monotone (verts : G.Subgraph β Set V) := fun _ _ h β¦ h.1
@[simps]
instance subgraphInhabited : Inhabited (Subgraph G) := β¨β₯β©
@[simp]
theorem neighborSet_sup {H H' : G.Subgraph} (v : V) :
(H β H').neighborSet v = H.neighborSet v βͺ H'.neighborSet v := rfl
@[simp]
theorem neighborSet_inf {H H' : G.Subgraph} (v : V) :
(H β H').neighborSet v = H.neighborSet v β© H'.neighborSet v := rfl
@[simp]
theorem neighborSet_top (v : V) : (β€ : G.Subgraph).neighborSet v = G.neighborSet v := rfl
@[simp]
theorem neighborSet_bot (v : V) : (β₯ : G.Subgraph).neighborSet v = β
:= rfl
@[simp]
theorem neighborSet_sSup (s : Set G.Subgraph) (v : V) :
(sSup s).neighborSet v = β G' β s, neighborSet G' v := by
ext
simp
@[simp]
theorem neighborSet_sInf (s : Set G.Subgraph) (v : V) :
(sInf s).neighborSet v = (β G' β s, neighborSet G' v) β© G.neighborSet v := by
ext
simp
@[simp]
theorem neighborSet_iSup (f : ΞΉ β G.Subgraph) (v : V) :
(β¨ i, f i).neighborSet v = β i, (f i).neighborSet v := by simp [iSup]
@[simp]
theorem neighborSet_iInf (f : ΞΉ β G.Subgraph) (v : V) :
(β¨
i, f i).neighborSet v = (β i, (f i).neighborSet v) β© G.neighborSet v := by simp [iInf]
@[simp]
theorem edgeSet_top : (β€ : Subgraph G).edgeSet = G.edgeSet := rfl
@[simp]
theorem edgeSet_bot : (β₯ : Subgraph G).edgeSet = β
:=
Set.ext <| Sym2.ind (by simp)
@[simp]
theorem edgeSet_inf {Hβ Hβ : Subgraph G} : (Hβ β Hβ).edgeSet = Hβ.edgeSet β© Hβ.edgeSet :=
Set.ext <| Sym2.ind (by simp)
@[simp]
theorem edgeSet_sup {Hβ Hβ : Subgraph G} : (Hβ β Hβ).edgeSet = Hβ.edgeSet βͺ Hβ.edgeSet :=
Set.ext <| Sym2.ind (by simp)
@[simp]
theorem edgeSet_sSup (s : Set G.Subgraph) : (sSup s).edgeSet = β G' β s, edgeSet G' := by
ext e
induction e
simp
@[simp]
theorem edgeSet_sInf (s : Set G.Subgraph) :
(sInf s).edgeSet = (β G' β s, edgeSet G') β© G.edgeSet := by
ext e
induction e
simp
@[simp]
theorem edgeSet_iSup (f : ΞΉ β G.Subgraph) :
(β¨ i, f i).edgeSet = β i, (f i).edgeSet := by simp [iSup]
@[simp]
theorem edgeSet_iInf (f : ΞΉ β G.Subgraph) :
(β¨
i, f i).edgeSet = (β i, (f i).edgeSet) β© G.edgeSet := by
simp [iInf]
@[simp]
theorem spanningCoe_top : (β€ : Subgraph G).spanningCoe = G := rfl
@[simp]
theorem spanningCoe_bot : (β₯ : Subgraph G).spanningCoe = β₯ := rfl
/-- Turn a subgraph of a `SimpleGraph` into a member of its subgraph type. -/
@[simps]
def _root_.SimpleGraph.toSubgraph (H : SimpleGraph V) (h : H β€ G) : G.Subgraph where
verts := Set.univ
Adj := H.Adj
adj_sub e := h e
edge_vert _ := Set.mem_univ _
symm := H.symm
theorem support_mono {H H' : Subgraph G} (h : H β€ H') : H.support β H'.support :=
Rel.dom_mono h.2
theorem _root_.SimpleGraph.toSubgraph.isSpanning (H : SimpleGraph V) (h : H β€ G) :
(toSubgraph H h).IsSpanning :=
Set.mem_univ
theorem spanningCoe_le_of_le {H H' : Subgraph G} (h : H β€ H') : H.spanningCoe β€ H'.spanningCoe :=
h.2
@[simp]
lemma sup_spanningCoe (H H' : Subgraph G) :
(H β H').spanningCoe = H.spanningCoe β H'.spanningCoe := rfl
/-- The top of the `Subgraph G` lattice is equivalent to the graph itself. -/
def topEquiv : (β€ : Subgraph G).coe βg G where
toFun v := βv
invFun v := β¨v, trivialβ©
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
/-- The bottom of the `Subgraph G` lattice is equivalent to the empty graph on the empty
vertex type. -/
def botEquiv : (β₯ : Subgraph G).coe βg (β₯ : SimpleGraph Empty) where
toFun v := v.property.elim
invFun v := v.elim
left_inv := fun β¨_, hβ© β¦ h.elim
right_inv v := v.elim
map_rel_iff' := Iff.rfl
theorem edgeSet_mono {Hβ Hβ : Subgraph G} (h : Hβ β€ Hβ) : Hβ.edgeSet β€ Hβ.edgeSet :=
Sym2.ind h.2
theorem _root_.Disjoint.edgeSet {Hβ Hβ : Subgraph G} (h : Disjoint Hβ Hβ) :
Disjoint Hβ.edgeSet Hβ.edgeSet :=
disjoint_iff_inf_le.mpr <| by simpa using edgeSet_mono h.le_bot
section map
variable {G' : SimpleGraph W} {f : G βg G'}
/-- Graph homomorphisms induce a covariant function on subgraphs. -/
@[simps]
protected def map (f : G βg G') (H : G.Subgraph) : G'.Subgraph where
verts := f '' H.verts
Adj := Relation.Map H.Adj f f
adj_sub := by
rintro _ _ β¨u, v, h, rfl, rflβ©
exact f.map_rel (H.adj_sub h)
edge_vert := by
rintro _ _ β¨u, v, h, rfl, rflβ©
exact Set.mem_image_of_mem _ (H.edge_vert h)
symm := by
rintro _ _ β¨u, v, h, rfl, rflβ©
exact β¨v, u, H.symm h, rfl, rflβ©
@[simp] lemma map_id (H : G.Subgraph) : H.map Hom.id = H := by ext <;> simp
lemma map_comp {U : Type*} {G'' : SimpleGraph U} (H : G.Subgraph) (f : G βg G') (g : G' βg G'') :
H.map (g.comp f) = (H.map f).map g := by ext <;> simp [Subgraph.map]
@[gcongr] lemma map_mono {Hβ Hβ : G.Subgraph} (hH : Hβ β€ Hβ) : Hβ.map f β€ Hβ.map f := by
constructor
Β· intro
simp only [map_verts, Set.mem_image, forall_exists_index, and_imp]
rintro v hv rfl
exact β¨_, hH.1 hv, rflβ©
Β· rintro _ _ β¨u, v, ha, rfl, rflβ©
exact β¨_, _, hH.2 ha, rfl, rflβ©
lemma map_monotone : Monotone (Subgraph.map f) := fun _ _ β¦ map_mono
theorem map_sup (f : G βg G') (Hβ Hβ : G.Subgraph) : (Hβ β Hβ).map f = Hβ.map f β Hβ.map f := by
ext <;> simp [Set.image_union, map_adj, sup_adj, Relation.Map, or_and_right, exists_or]
@[simp] lemma map_iso_top {H : SimpleGraph W} (e : G βg H) : Subgraph.map e.toHom β€ = β€ := by
ext <;> simp [Relation.Map, e.apply_eq_iff_eq_symm_apply, β e.map_rel_iff]
@[simp] lemma edgeSet_map (f : G βg G') (H : G.Subgraph) :
(H.map f).edgeSet = Sym2.map f '' H.edgeSet := Sym2.fromRel_relationMap ..
end map
/-- Graph homomorphisms induce a contravariant function on subgraphs. -/
@[simps]
protected def comap {G' : SimpleGraph W} (f : G βg G') (H : G'.Subgraph) : G.Subgraph where
verts := f β»ΒΉ' H.verts
Adj u v := G.Adj u v β§ H.Adj (f u) (f v)
adj_sub h := h.1
edge_vert h := Set.mem_preimage.1 (H.edge_vert h.2)
symm _ _ h := β¨G.symm h.1, H.symm h.2β©
theorem comap_monotone {G' : SimpleGraph W} (f : G βg G') : Monotone (Subgraph.comap f) := by
intro H H' h
constructor
Β· intro
simp only [comap_verts, Set.mem_preimage]
apply h.1
Β· intro v w
simp +contextual only [comap_adj, and_imp, true_and]
intro
apply h.2
@[simp] lemma comap_equiv_top {H : SimpleGraph W} (f : G βg H) : Subgraph.comap f β€ = β€ := by
ext <;> simp +contextual [f.map_adj]
theorem map_le_iff_le_comap {G' : SimpleGraph W} (f : G βg G') (H : G.Subgraph) (H' : G'.Subgraph) :
H.map f β€ H' β H β€ H'.comap f := by
refine β¨fun h β¦ β¨fun v hv β¦ ?_, fun v w hvw β¦ ?_β©, fun h β¦ β¨fun v β¦ ?_, fun v w β¦ ?_β©β©
Β· simp only [comap_verts, Set.mem_preimage]
exact h.1 β¨v, hv, rflβ©
Β· simp only [H.adj_sub hvw, comap_adj, true_and]
exact h.2 β¨v, w, hvw, rfl, rflβ©
Β· simp only [map_verts, Set.mem_image, forall_exists_index, and_imp]
rintro w hw rfl
exact h.1 hw
Β· simp only [Relation.Map, map_adj, forall_exists_index, and_imp]
rintro u u' hu rfl rfl
exact (h.2 hu).2
instance [DecidableEq V] [Fintype V] [DecidableRel G.Adj] : Fintype G.Subgraph := by
refine .ofBijective
(Ξ± := {H : Finset V Γ (V β V β Bool) //
(β a b, H.2 a b β G.Adj a b) β§ (β a b, H.2 a b β a β H.1) β§ β a b, H.2 a b = H.2 b a})
(fun H β¦ β¨H.1.1, fun a b β¦ H.1.2 a b, @H.2.1, @H.2.2.1, by simp [Symmetric, H.2.2.2]β©)
β¨?_, fun H β¦ ?_β©
Β· rintro β¨β¨_, _β©, -β© β¨β¨_, _β©, -β©
simp [funext_iff]
Β· classical
exact β¨β¨(H.verts.toFinset, fun a b β¦ H.Adj a b), fun a b β¦ by simpa using H.adj_sub,
fun a b β¦ by simpa using H.edge_vert, by simp [H.adj_comm]β©, by simpβ©
instance [Finite V] : Finite G.Subgraph := by classical cases nonempty_fintype V; infer_instance
/-- Given two subgraphs, one a subgraph of the other, there is an induced injective homomorphism of
the subgraphs as graphs. -/
@[simps]
def inclusion {x y : Subgraph G} (h : x β€ y) : x.coe βg y.coe where
toFun v := β¨βv, And.left h v.propertyβ©
map_rel' hvw := h.2 hvw
theorem inclusion.injective {x y : Subgraph G} (h : x β€ y) : Function.Injective (inclusion h) := by
intro v w h
rw [inclusion, DFunLike.coe, Subtype.mk_eq_mk] at h
exact Subtype.ext h
/-- There is an induced injective homomorphism of a subgraph of `G` into `G`. -/
@[simps]
protected def hom (x : Subgraph G) : x.coe βg G where
toFun v := v
map_rel' := x.adj_sub
@[simp] lemma coe_hom (x : Subgraph G) :
(x.hom : x.verts β V) = (fun (v : x.verts) => (v : V)) := rfl
theorem hom_injective {x : Subgraph G} : Function.Injective x.hom :=
fun _ _ β¦ Subtype.ext
@[deprecated (since := "2025-03-15")] alias hom.injective := hom_injective
@[simp] lemma map_hom_top (G' : G.Subgraph) : Subgraph.map G'.hom β€ = G' := by
aesop (add unfold safe Relation.Map, unsafe G'.edge_vert, unsafe Adj.symm)
/-- There is an induced injective homomorphism of a subgraph of `G` as
a spanning subgraph into `G`. -/
@[simps]
def spanningHom (x : Subgraph G) : x.spanningCoe βg G where
toFun := id
map_rel' := x.adj_sub
theorem spanningHom_injective {x : Subgraph G} : Function.Injective x.spanningHom :=
fun _ _ β¦ id
@[deprecated (since := "2025-03-15")] alias spanningHom.injective := spanningHom_injective
theorem neighborSet_subset_of_subgraph {x y : Subgraph G} (h : x β€ y) (v : V) :
x.neighborSet v β y.neighborSet v :=
fun _ h' β¦ h.2 h'
instance neighborSet.decidablePred (G' : Subgraph G) [h : DecidableRel G'.Adj] (v : V) :
DecidablePred (Β· β G'.neighborSet v) :=
h v
/-- If a graph is locally finite at a vertex, then so is a subgraph of that graph. -/
instance finiteAt {G' : Subgraph G} (v : G'.verts) [DecidableRel G'.Adj]
[Fintype (G.neighborSet v)] : Fintype (G'.neighborSet v) :=
Set.fintypeSubset (G.neighborSet v) (G'.neighborSet_subset v)
/-- If a subgraph is locally finite at a vertex, then so are subgraphs of that subgraph.
This is not an instance because `G''` cannot be inferred. -/
def finiteAtOfSubgraph {G' G'' : Subgraph G} [DecidableRel G'.Adj] (h : G' β€ G'') (v : G'.verts)
[Fintype (G''.neighborSet v)] : Fintype (G'.neighborSet v) :=
Set.fintypeSubset (G''.neighborSet v) (neighborSet_subset_of_subgraph h v)
instance (G' : Subgraph G) [Fintype G'.verts] (v : V) [DecidablePred (Β· β G'.neighborSet v)] :
Fintype (G'.neighborSet v) :=
Set.fintypeSubset G'.verts (neighborSet_subset_verts G' v)
instance coeFiniteAt {G' : Subgraph G} (v : G'.verts) [Fintype (G'.neighborSet v)] :
Fintype (G'.coe.neighborSet v) :=
Fintype.ofEquiv _ (coeNeighborSetEquiv v).symm
theorem IsSpanning.card_verts [Fintype V] {G' : Subgraph G} [Fintype G'.verts] (h : G'.IsSpanning) :
G'.verts.toFinset.card = Fintype.card V := by
simp only [isSpanning_iff.1 h, Set.toFinset_univ]
congr
/-- The degree of a vertex in a subgraph. It's zero for vertices outside the subgraph. -/
def degree (G' : Subgraph G) (v : V) [Fintype (G'.neighborSet v)] : β :=
Fintype.card (G'.neighborSet v)
theorem finset_card_neighborSet_eq_degree {G' : Subgraph G} {v : V} [Fintype (G'.neighborSet v)] :
(G'.neighborSet v).toFinset.card = G'.degree v := by
rw [degree, Set.toFinset_card]
theorem degree_le (G' : Subgraph G) (v : V) [Fintype (G'.neighborSet v)]
[Fintype (G.neighborSet v)] : G'.degree v β€ G.degree v := by
rw [β card_neighborSet_eq_degree]
exact Set.card_le_card (G'.neighborSet_subset v)
theorem degree_le' (G' G'' : Subgraph G) (h : G' β€ G'') (v : V) [Fintype (G'.neighborSet v)]
[Fintype (G''.neighborSet v)] : G'.degree v β€ G''.degree v :=
Set.card_le_card (neighborSet_subset_of_subgraph h v)
@[simp]
theorem coe_degree (G' : Subgraph G) (v : G'.verts) [Fintype (G'.coe.neighborSet v)]
[Fintype (G'.neighborSet v)] : G'.coe.degree v = G'.degree v := by
rw [β card_neighborSet_eq_degree]
exact Fintype.card_congr (coeNeighborSetEquiv v)
@[simp]
theorem degree_spanningCoe {G' : G.Subgraph} (v : V) [Fintype (G'.neighborSet v)]
[Fintype (G'.spanningCoe.neighborSet v)] : G'.spanningCoe.degree v = G'.degree v := by
rw [β card_neighborSet_eq_degree, Subgraph.degree]
congr!
theorem degree_eq_one_iff_unique_adj {G' : Subgraph G} {v : V} [Fintype (G'.neighborSet v)] :
G'.degree v = 1 β β! w : V, G'.Adj v w := by
rw [β finset_card_neighborSet_eq_degree, Finset.card_eq_one, Finset.singleton_iff_unique_mem]
simp only [Set.mem_toFinset, mem_neighborSet]
lemma neighborSet_eq_of_equiv {v : V} {H : Subgraph G}
(h : G.neighborSet v β H.neighborSet v) (hfin : (G.neighborSet v).Finite) :
H.neighborSet v = G.neighborSet v := by
lift H.neighborSet v to Finset V using h.set_finite_iff.mp hfin with s hs
lift G.neighborSet v to Finset V using hfin with t ht
refine congrArg _ <| Finset.eq_of_subset_of_card_le ?_ (Finset.card_eq_of_equiv h).le
rw [β Finset.coe_subset, hs, ht]
exact H.neighborSet_subset _
lemma adj_iff_of_neighborSet_equiv {v : V} {H : Subgraph G}
(h : G.neighborSet v β H.neighborSet v) (hfin : (G.neighborSet v).Finite) :
β {w}, H.Adj v w β G.Adj v w :=
Set.ext_iff.mp (neighborSet_eq_of_equiv h hfin) _
end Subgraph
section MkProperties
/-! ### Properties of `singletonSubgraph` and `subgraphOfAdj` -/
variable {G : SimpleGraph V} {G' : SimpleGraph W}
instance nonempty_singletonSubgraph_verts (v : V) : Nonempty (G.singletonSubgraph v).verts :=
β¨β¨v, Set.mem_singleton vβ©β©
@[simp]
theorem singletonSubgraph_le_iff (v : V) (H : G.Subgraph) :
G.singletonSubgraph v β€ H β v β H.verts := by
refine β¨fun h β¦ h.1 (Set.mem_singleton v), ?_β©
intro h
constructor
Β· rwa [singletonSubgraph_verts, Set.singleton_subset_iff]
Β· exact fun _ _ β¦ False.elim
|
@[simp]
theorem map_singletonSubgraph (f : G βg G') {v : V} :
Subgraph.map f (G.singletonSubgraph v) = G'.singletonSubgraph (f v) := by
ext <;> simp only [Relation.Map, Subgraph.map_adj, singletonSubgraph_adj, Pi.bot_apply,
exists_and_left, and_iff_left_iff_imp, IsEmpty.forall_iff, Subgraph.map_verts,
singletonSubgraph_verts, Set.image_singleton]
| Mathlib/Combinatorics/SimpleGraph/Subgraph.lean | 845 | 851 |
/-
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
Β· rw [pairwise_map]
apply Pairwise.imp _ hl
intro u v
apply disjoint_map
exact fun u v => Nat.add_left_cancel
/-- The lengths of the members of `l.ranges` are those given by `l` -/
theorem ranges_length (l : List β) :
l.ranges.map length = l := by
induction l with
| nil => simp only [ranges, map_nil]
| cons a l hl => -- (a :: l)
simp only [ranges, map_cons, length_range, map_map, cons.injEq, true_and]
conv_rhs => rw [β hl]
apply map_congr_left
intro s _
simp only [Function.comp_apply, length_map]
end Ranges
end List
| Mathlib/Data/List/Range.lean | 191 | 193 | |
/-
Copyright (c) 2024 Etienne Marion. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Etienne Marion
-/
import Mathlib.Data.Finite.Prod
import Mathlib.MeasureTheory.SetSemiring
/-!
# Algebra of sets
In this file we define the notion of algebra of sets and give its basic properties. An algebra
of sets is a family of sets containing the empty set and closed by complement and binary union.
It is therefore similar to a `Ο`-algebra, except that it is not necessarily closed
by countable unions.
We also define the algebra of sets generated by a family of sets and give its basic properties,
and we prove that it is countable when it is generated by a countable family. We prove that
the `Ο`-algebra generated by a family of sets `π` is the same as the one generated by the algebra
of sets generated by `π`.
## Main definitions
* `MeasureTheory.IsSetAlgebra`: property of being an algebra of sets.
* `MeasureTheory.generateSetAlgebra`: the algebra of sets generated by a family of sets.
## Main statements
* `MeasureTheory.mem_generateSetAlgebra_elim`: If a set `s` belongs to the algebra of sets
generated by `π`, then it can be written as a finite union of finite intersections of sets which
are in `π` or have their complement in `π`.
* `MeasureTheory.countable_generateSetAlgebra`: If a family of sets is countable then so is
the algebra of sets generated by it.
## References
* <https://en.wikipedia.org/wiki/Field_of_sets>
## Tags
algebra of sets, generated algebra of sets
-/
open MeasurableSpace Set
namespace MeasureTheory
variable {Ξ± : Type*} {π : Set (Set Ξ±)} {s t : Set Ξ±}
/-! ### Definition and basic properties of an algebra of sets -/
/-- An algebra of sets is a family of sets containing the empty set and closed by complement and
union. Consequently it is also closed by difference (see `IsSetAlgebra.diff_mem`) and intersection
(see `IsSetAlgebra.inter_mem`). -/
structure IsSetAlgebra (π : Set (Set Ξ±)) : Prop where
empty_mem : β
β π
compl_mem : β β¦sβ¦, s β π β sαΆ β π
union_mem : β β¦s tβ¦, s β π β t β π β s βͺ t β π
namespace IsSetAlgebra
/-- An algebra of sets contains the whole set. -/
theorem univ_mem (hπ : IsSetAlgebra π) : univ β π :=
compl_empty βΈ hπ.compl_mem hπ.empty_mem
/-- An algebra of sets is closed by intersection. -/
theorem inter_mem (hπ : IsSetAlgebra π) (s_mem : s β π) (t_mem : t β π) :
s β© t β π :=
inter_eq_compl_compl_union_compl .. βΈ
hπ.compl_mem (hπ.union_mem (hπ.compl_mem s_mem) (hπ.compl_mem t_mem))
/-- An algebra of sets is closed by difference. -/
theorem diff_mem (hπ : IsSetAlgebra π) (s_mem : s β π) (t_mem : t β π) :
s \ t β π := hπ.inter_mem s_mem (hπ.compl_mem t_mem)
/-- An algebra of sets is a ring of sets. -/
theorem isSetRing (hπ : IsSetAlgebra π) : IsSetRing π where
empty_mem := hπ.empty_mem
union_mem := hπ.union_mem
diff_mem := fun _ _ β¦ hπ.diff_mem
/-- An algebra of sets is closed by finite unions. -/
theorem biUnion_mem {ΞΉ : Type*} (hπ : IsSetAlgebra π) {s : ΞΉ β Set Ξ±} (S : Finset ΞΉ)
(hs : β i β S, s i β π) : β i β S, s i β π := hπ.isSetRing.biUnion_mem S hs
/-- An algebra of sets is closed by finite intersections. -/
theorem biInter_mem {ΞΉ : Type*} (hπ : IsSetAlgebra π) {s : ΞΉ β Set Ξ±} (S : Finset ΞΉ)
(hs : β i β S, s i β π) : β i β S, s i β π := by
by_cases h : S = β
Β· rw [h, β Finset.set_biInter_coe, Finset.coe_empty, biInter_empty]
exact hπ.univ_mem
Β· rw [β ne_eq, β Finset.nonempty_iff_ne_empty] at h
exact hπ.isSetRing.biInter_mem S h hs
end IsSetAlgebra
section generateSetAlgebra
/-! ### Definition and properties of the algebra of sets generated by some family -/
/-- `generateSetAlgebra π` is the smallest algebra of sets containing `π`. -/
inductive generateSetAlgebra {Ξ± : Type*} (π : Set (Set Ξ±)) : Set (Set Ξ±)
| base (s : Set Ξ±) (s_mem : s β π) : generateSetAlgebra π s
| empty : generateSetAlgebra π β
| compl (s : Set Ξ±) (hs : generateSetAlgebra π s) : generateSetAlgebra π sαΆ
| union (s t : Set Ξ±) (hs : generateSetAlgebra π s) (ht : generateSetAlgebra π t) :
generateSetAlgebra π (s βͺ t)
/-- The algebra of sets generated by a family of sets is an algebra of sets. -/
theorem isSetAlgebra_generateSetAlgebra :
IsSetAlgebra (generateSetAlgebra π) where
empty_mem := generateSetAlgebra.empty
compl_mem := fun _ hs β¦ generateSetAlgebra.compl _ hs
union_mem := fun _ _ hs ht β¦ generateSetAlgebra.union _ _ hs ht
/-- The algebra of sets generated by `π` contains `π`. -/
theorem self_subset_generateSetAlgebra : π β generateSetAlgebra π :=
fun _ β¦ generateSetAlgebra.base _
/-- The measurable space generated by a family of sets `π` is the same as the one generated
by the algebra of sets generated by `π`. -/
| @[simp]
theorem generateFrom_generateSetAlgebra_eq :
generateFrom (generateSetAlgebra π) = generateFrom π := by
refine le_antisymm (fun s ms β¦ ?_) (generateFrom_mono self_subset_generateSetAlgebra)
induction s, ms using generateFrom_induction with
| hC t ht h =>
clear h
induction ht with
| base u u_mem => exact measurableSet_generateFrom u_mem
| empty => exact @MeasurableSet.empty _ (generateFrom π)
| compl u _ mu => exact mu.compl
| union u v _ _ mu mv => exact MeasurableSet.union mu mv
| empty => exact MeasurableSpace.measurableSet_empty _
| Mathlib/MeasureTheory/SetAlgebra.lean | 122 | 134 |
/-
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β©β©
| Mathlib/NumberTheory/SmoothNumbers.lean | 157 | 164 |
/-
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.Algebra.Order.Group.Unbundled.Int
import Mathlib.Algebra.Ring.Nat
import Mathlib.Data.Int.GCD
/-!
# Congruences modulo a natural number
This file defines the equivalence relation `a β‘ b [MOD n]` on the natural numbers,
and proves basic properties about it such as the Chinese Remainder Theorem
`modEq_and_modEq_iff_modEq_mul`.
## Notations
`a β‘ b [MOD n]` is notation for `nat.ModEq n a b`, which is defined to mean `a % n = b % n`.
## Tags
ModEq, congruence, mod, MOD, modulo
-/
assert_not_exists OrderedAddCommMonoid Function.support
namespace Nat
/-- Modular equality. `n.ModEq a b`, or `a β‘ b [MOD n]`, means that `a - b` is a multiple of `n`. -/
def ModEq (n a b : β) :=
a % n = b % n
@[inherit_doc]
notation:50 a " β‘ " b " [MOD " n "]" => ModEq n a b
variable {m n a b c d : β}
-- Since `ModEq` is semi-reducible, we need to provide the decidable instance manually
instance : Decidable (ModEq n a b) := inferInstanceAs <| Decidable (a % n = b % n)
namespace ModEq
@[refl]
protected theorem refl (a : β) : a β‘ a [MOD n] := rfl
protected theorem rfl : a β‘ a [MOD n] :=
ModEq.refl _
instance : IsRefl _ (ModEq n) :=
β¨ModEq.reflβ©
@[symm]
protected theorem symm : a β‘ b [MOD n] β b β‘ a [MOD n] :=
Eq.symm
@[trans]
protected theorem trans : a β‘ b [MOD n] β b β‘ c [MOD n] β a β‘ c [MOD n] :=
Eq.trans
instance : Trans (ModEq n) (ModEq n) (ModEq n) where
trans := Nat.ModEq.trans
protected theorem comm : a β‘ b [MOD n] β b β‘ a [MOD n] :=
β¨ModEq.symm, ModEq.symmβ©
end ModEq
theorem modEq_zero_iff_dvd : a β‘ 0 [MOD n] β n β£ a := by rw [ModEq, zero_mod, dvd_iff_mod_eq_zero]
theorem _root_.Dvd.dvd.modEq_zero_nat (h : n β£ a) : a β‘ 0 [MOD n] :=
modEq_zero_iff_dvd.2 h
theorem _root_.Dvd.dvd.zero_modEq_nat (h : n β£ a) : 0 β‘ a [MOD n] :=
h.modEq_zero_nat.symm
theorem modEq_iff_dvd : a β‘ b [MOD n] β (n : β€) β£ b - a := by
rw [ModEq, eq_comm, β Int.natCast_inj, Int.natCast_mod, Int.natCast_mod,
Int.emod_eq_emod_iff_emod_sub_eq_zero, Int.dvd_iff_emod_eq_zero]
alias β¨ModEq.dvd, modEq_of_dvdβ© := modEq_iff_dvd
/-- A variant of `modEq_iff_dvd` with `Nat` divisibility -/
theorem modEq_iff_dvd' (h : a β€ b) : a β‘ b [MOD n] β n β£ b - a := by
rw [modEq_iff_dvd, β Int.natCast_dvd_natCast, Int.ofNat_sub h]
theorem mod_modEq (a n) : a % n β‘ a [MOD n] :=
mod_mod _ _
namespace ModEq
lemma of_dvd (d : m β£ n) (h : a β‘ b [MOD n]) : a β‘ b [MOD m] :=
modEq_of_dvd <| Int.ofNat_dvd.mpr d |>.trans h.dvd
protected theorem mul_left' (c : β) (h : a β‘ b [MOD n]) : c * a β‘ c * b [MOD c * n] := by
unfold ModEq at *; rw [mul_mod_mul_left, mul_mod_mul_left, h]
@[gcongr]
protected theorem mul_left (c : β) (h : a β‘ b [MOD n]) : c * a β‘ c * b [MOD n] :=
(h.mul_left' _).of_dvd (dvd_mul_left _ _)
protected theorem mul_right' (c : β) (h : a β‘ b [MOD n]) : a * c β‘ b * c [MOD n * c] := by
rw [mul_comm a, mul_comm b, mul_comm n]; exact h.mul_left' c
@[gcongr]
protected theorem mul_right (c : β) (h : a β‘ b [MOD n]) : a * c β‘ b * c [MOD n] := by
rw [mul_comm a, mul_comm b]; exact h.mul_left c
@[gcongr]
protected theorem mul (hβ : a β‘ b [MOD n]) (hβ : c β‘ d [MOD n]) : a * c β‘ b * d [MOD n] :=
(hβ.mul_left _).trans (hβ.mul_right _)
@[gcongr]
protected theorem pow (m : β) (h : a β‘ b [MOD n]) : a ^ m β‘ b ^ m [MOD n] := by
induction m with
| zero => rfl
| succ d hd =>
rw [Nat.pow_succ, Nat.pow_succ]
exact hd.mul h
@[gcongr]
protected theorem add (hβ : a β‘ b [MOD n]) (hβ : c β‘ d [MOD n]) : a + c β‘ b + d [MOD n] := by
rw [modEq_iff_dvd, Int.natCast_add, Int.natCast_add, add_sub_add_comm]
exact Int.dvd_add hβ.dvd hβ.dvd
@[gcongr]
protected theorem add_left (c : β) (h : a β‘ b [MOD n]) : c + a β‘ c + b [MOD n] :=
ModEq.rfl.add h
@[gcongr]
protected theorem add_right (c : β) (h : a β‘ b [MOD n]) : a + c β‘ b + c [MOD n] :=
h.add ModEq.rfl
protected theorem add_left_cancel (hβ : a β‘ b [MOD n]) (hβ : a + c β‘ b + d [MOD n]) :
c β‘ d [MOD n] := by
simp only [modEq_iff_dvd, Int.natCast_add] at *
rw [add_sub_add_comm] at hβ
convert Int.dvd_sub hβ hβ using 1
rw [add_sub_cancel_left]
protected theorem add_left_cancel' (c : β) (h : c + a β‘ c + b [MOD n]) : a β‘ b [MOD n] :=
ModEq.rfl.add_left_cancel h
protected theorem add_right_cancel (hβ : c β‘ d [MOD n]) (hβ : a + c β‘ b + d [MOD n]) :
a β‘ b [MOD n] := by
| rw [add_comm a, add_comm b] at hβ
exact hβ.add_left_cancel hβ
| Mathlib/Data/Nat/ModEq.lean | 146 | 148 |
/-
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 | 322 | 323 | |
/-
Copyright (c) 2020 Floris van Doorn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Floris van Doorn
-/
import Mathlib.MeasureTheory.Constructions.BorelSpace.Metric
import Mathlib.MeasureTheory.Constructions.BorelSpace.Real
import Mathlib.Topology.Metrizable.Real
import Mathlib.Topology.IndicatorConstPointwise
/-!
# Measurable functions in (pseudo-)metrizable Borel spaces
-/
open Filter MeasureTheory TopologicalSpace Topology NNReal ENNReal MeasureTheory
variable {Ξ± Ξ² : Type*} [MeasurableSpace Ξ±]
section Limits
variable [TopologicalSpace Ξ²] [PseudoMetrizableSpace Ξ²] [MeasurableSpace Ξ²] [BorelSpace Ξ²]
open Metric
/-- A limit (over a general filter) of measurable functions valued in a (pseudo) metrizable space is
measurable. -/
theorem measurable_of_tendsto_metrizable' {ΞΉ} {f : ΞΉ β Ξ± β Ξ²} {g : Ξ± β Ξ²} (u : Filter ΞΉ) [NeBot u]
[IsCountablyGenerated u] (hf : β i, Measurable (f i)) (lim : Tendsto f u (π g)) :
Measurable g := by
letI : PseudoMetricSpace Ξ² := pseudoMetrizableSpacePseudoMetric Ξ²
apply measurable_of_isClosed'
intro s h1s h2s h3s
have : Measurable fun x => infNndist (g x) s := by
suffices Tendsto (fun i x => infNndist (f i x) s) u (π fun x => infNndist (g x) s) from
NNReal.measurable_of_tendsto' u (fun i => (hf i).infNndist) this
rw [tendsto_pi_nhds] at lim β’
intro x
exact ((continuous_infNndist_pt s).tendsto (g x)).comp (lim x)
have h4s : g β»ΒΉ' s = (fun x => infNndist (g x) s) β»ΒΉ' {0} := by
ext x
simp [h1s, β h1s.mem_iff_infDist_zero h2s, β NNReal.coe_eq_zero]
rw [h4s]
exact this (measurableSet_singleton 0)
/-- A sequential limit of measurable functions valued in a (pseudo) metrizable space is
measurable. -/
theorem measurable_of_tendsto_metrizable {f : β β Ξ± β Ξ²} {g : Ξ± β Ξ²} (hf : β i, Measurable (f i))
(lim : Tendsto f atTop (π g)) : Measurable g :=
measurable_of_tendsto_metrizable' atTop hf lim
theorem aemeasurable_of_tendsto_metrizable_ae {ΞΉ} {ΞΌ : Measure Ξ±} {f : ΞΉ β Ξ± β Ξ²} {g : Ξ± β Ξ²}
(u : Filter ΞΉ) [hu : NeBot u] [IsCountablyGenerated u] (hf : β n, AEMeasurable (f n) ΞΌ)
(h_tendsto : βα΅ x βΞΌ, Tendsto (fun n => f n x) u (π (g x))) : AEMeasurable g ΞΌ := by
classical
rcases u.exists_seq_tendsto with β¨v, hvβ©
have h'f : β n, AEMeasurable (f (v n)) ΞΌ := fun n => hf (v n)
set p : Ξ± β (β β Ξ²) β Prop := fun x f' => Tendsto (fun n => f' n) atTop (π (g x))
have hp : βα΅ x βΞΌ, p x fun n => f (v n) x := by
filter_upwards [h_tendsto] with x hx using hx.comp hv
set aeSeqLim := fun x => ite (x β aeSeqSet h'f p) (g x) (β¨f (v 0) xβ© : Nonempty Ξ²).some
refine
β¨aeSeqLim,
measurable_of_tendsto_metrizable' atTop (aeSeq.measurable h'f p)
(tendsto_pi_nhds.mpr fun x => ?_),
?_β©
Β· simp_rw [aeSeqLim, aeSeq]
split_ifs with hx
Β· simp_rw [aeSeq.mk_eq_fun_of_mem_aeSeqSet h'f hx]
exact @aeSeq.fun_prop_of_mem_aeSeqSet _ Ξ± Ξ² _ _ _ _ _ h'f x hx
Β· exact tendsto_const_nhds
Β· exact
(ite_ae_eq_of_measure_compl_zero g (fun x => (β¨f (v 0) xβ© : Nonempty Ξ²).some) (aeSeqSet h'f p)
(aeSeq.measure_compl_aeSeqSet_eq_zero h'f hp)).symm
theorem aemeasurable_of_tendsto_metrizable_ae' {ΞΌ : Measure Ξ±} {f : β β Ξ± β Ξ²} {g : Ξ± β Ξ²}
(hf : β n, AEMeasurable (f n) ΞΌ)
(h_ae_tendsto : βα΅ x βΞΌ, Tendsto (fun n => f n x) atTop (π (g x))) : AEMeasurable g ΞΌ :=
aemeasurable_of_tendsto_metrizable_ae atTop hf h_ae_tendsto
theorem aemeasurable_of_unif_approx {Ξ²} [MeasurableSpace Ξ²] [PseudoMetricSpace Ξ²] [BorelSpace Ξ²]
{ΞΌ : Measure Ξ±} {g : Ξ± β Ξ²}
(hf : β Ξ΅ > (0 : β), β f : Ξ± β Ξ², AEMeasurable f ΞΌ β§ βα΅ x βΞΌ, dist (f x) (g x) β€ Ξ΅) :
AEMeasurable g ΞΌ := by
obtain β¨u, -, u_pos, u_limβ© :
β u : β β β, StrictAnti u β§ (β n : β, 0 < u n) β§ Tendsto u atTop (π 0) :=
exists_seq_strictAnti_tendsto (0 : β)
choose f Hf using fun n : β => hf (u n) (u_pos n)
have : βα΅ x βΞΌ, Tendsto (fun n => f n x) atTop (π (g x)) := by
have : βα΅ x βΞΌ, β n, dist (f n x) (g x) β€ u n := ae_all_iff.2 fun n => (Hf n).2
filter_upwards [this]
intro x hx
rw [tendsto_iff_dist_tendsto_zero]
exact squeeze_zero (fun n => dist_nonneg) hx u_lim
exact aemeasurable_of_tendsto_metrizable_ae' (fun n => (Hf n).1) this
theorem measurable_of_tendsto_metrizable_ae {ΞΌ : Measure Ξ±} [ΞΌ.IsComplete] {f : β β Ξ± β Ξ²}
{g : Ξ± β Ξ²} (hf : β n, Measurable (f n))
(h_ae_tendsto : βα΅ x βΞΌ, Tendsto (fun n => f n x) atTop (π (g x))) : Measurable g :=
aemeasurable_iff_measurable.mp
(aemeasurable_of_tendsto_metrizable_ae' (fun i => (hf i).aemeasurable) h_ae_tendsto)
theorem measurable_limit_of_tendsto_metrizable_ae {ΞΉ} [Countable ΞΉ] [Nonempty ΞΉ] {ΞΌ : Measure Ξ±}
{f : ΞΉ β Ξ± β Ξ²} {L : Filter ΞΉ} [L.IsCountablyGenerated] (hf : β n, AEMeasurable (f n) ΞΌ)
(h_ae_tendsto : βα΅ x βΞΌ, β l : Ξ², Tendsto (fun n => f n x) L (π l)) :
β f_lim : Ξ± β Ξ², Measurable f_lim β§ βα΅ x βΞΌ, Tendsto (fun n => f n x) L (π (f_lim x)) := by
classical
inhabit ΞΉ
rcases eq_or_neBot L with (rfl | hL)
Β· exact β¨(hf default).mk _, (hf default).measurable_mk, Eventually.of_forall fun x => tendsto_botβ©
let p : Ξ± β (ΞΉ β Ξ²) β Prop := fun x f' => β l : Ξ², Tendsto (fun n => f' n) L (π l)
have hp_mem : β x β aeSeqSet hf p, p x fun n => f n x := fun x hx =>
aeSeq.fun_prop_of_mem_aeSeqSet hf hx
have h_ae_eq : βα΅ x βΞΌ, β n, aeSeq hf p n x = f n x := aeSeq.aeSeq_eq_fun_ae hf h_ae_tendsto
set f_lim : Ξ± β Ξ² := fun x => dite (x β aeSeqSet hf p) (fun h => (hp_mem x h).choose)
fun _ => (β¨f default xβ© : Nonempty Ξ²).some
have hf_lim : β x, Tendsto (fun n => aeSeq hf p n x) L (π (f_lim x)) := by
intro x
simp only [aeSeq, f_lim]
split_ifs with h
Β· refine (hp_mem x h).choose_spec.congr fun n => ?_
exact (aeSeq.mk_eq_fun_of_mem_aeSeqSet hf h n).symm
Β· exact tendsto_const_nhds
have h_ae_tendsto_f_lim : βα΅ x βΞΌ, Tendsto (fun n => f n x) L (π (f_lim x)) :=
h_ae_eq.mono fun x hx => (hf_lim x).congr hx
have h_f_lim_meas : Measurable f_lim :=
measurable_of_tendsto_metrizable' L (aeSeq.measurable hf p)
(tendsto_pi_nhds.mpr fun x => hf_lim x)
exact β¨f_lim, h_f_lim_meas, h_ae_tendsto_f_limβ©
end Limits
section TendstoIndicator
variable {Ξ± : Type*} [MeasurableSpace Ξ±] {A : Set Ξ±}
variable {ΞΉ : Type*} (L : Filter ΞΉ) [IsCountablyGenerated L] {As : ΞΉ β Set Ξ±}
/-- If the indicator functions of measurable sets `Aα΅’` converge to the indicator function of
a set `A` along a nontrivial countably generated filter, then `A` is also measurable. -/
lemma measurableSet_of_tendsto_indicator [NeBot L] (As_mble : β i, MeasurableSet (As i))
(h_lim : β x, βαΆ i in L, x β As i β x β A) :
MeasurableSet A := by
simp_rw [β measurable_indicator_const_iff (1 : ββ₯0β)] at As_mble β’
exact ENNReal.measurable_of_tendsto' L As_mble
((tendsto_indicator_const_iff_forall_eventually L (1 : ββ₯0β)).mpr h_lim)
/-- If the indicator functions of a.e.-measurable sets `Aα΅’` converge a.e. to the indicator function
of a set `A` along a nontrivial countably generated filter, then `A` is also a.e.-measurable. -/
lemma nullMeasurableSet_of_tendsto_indicator [NeBot L] {ΞΌ : Measure Ξ±}
(As_mble : β i, NullMeasurableSet (As i) ΞΌ)
(h_lim : βα΅ x βΞΌ, βαΆ i in L, x β As i β x β A) :
NullMeasurableSet A ΞΌ := by
simp_rw [β aemeasurable_indicator_const_iff (1 : ββ₯0β)] at As_mble β’
apply aemeasurable_of_tendsto_metrizable_ae L As_mble
simpa [tendsto_indicator_const_apply_iff_eventually] using h_lim
|
end TendstoIndicator
| Mathlib/MeasureTheory/Constructions/BorelSpace/Metrizable.lean | 155 | 163 |
/-
Copyright (c) 2021 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov, Alex Kontorovich
-/
import Mathlib.Data.Set.Piecewise
import Mathlib.Order.Filter.Tendsto
import Mathlib.Order.Filter.Bases.Finite
/-!
# (Co)product of a family of filters
In this file we define two filters on `Ξ i, Ξ± i` and prove some basic properties of these filters.
* `Filter.pi (f : Ξ i, Filter (Ξ± i))` to be the maximal filter on `Ξ i, Ξ± i` such that
`β i, Filter.Tendsto (Function.eval i) (Filter.pi f) (f i)`. It is defined as
`Ξ i, Filter.comap (Function.eval i) (f i)`. This is a generalization of `Filter.prod` to indexed
products.
* `Filter.coprodα΅’ (f : Ξ i, Filter (Ξ± i))`: a generalization of `Filter.coprod`; it is the supremum
of `comap (eval i) (f i)`.
-/
open Set Function Filter
namespace Filter
variable {ΞΉ : Type*} {Ξ± : ΞΉ β Type*} {f fβ fβ : (i : ΞΉ) β Filter (Ξ± i)} {s : (i : ΞΉ) β Set (Ξ± i)}
{p : β i, Ξ± i β Prop}
section Pi
theorem tendsto_eval_pi (f : β i, Filter (Ξ± i)) (i : ΞΉ) : Tendsto (eval i) (pi f) (f i) :=
tendsto_iInf' i tendsto_comap
theorem tendsto_pi {Ξ² : Type*} {m : Ξ² β β i, Ξ± i} {l : Filter Ξ²} :
Tendsto m l (pi f) β β i, Tendsto (fun x => m x i) l (f i) := by
simp only [pi, tendsto_iInf, tendsto_comap_iff]; rfl
/-- If a function tends to a product `Filter.pi f` of filters, then its `i`-th component tends to
`f i`. See also `Filter.Tendsto.apply_nhds` for the special case of converging to a point in a
product of topological spaces. -/
alias β¨Tendsto.apply, _β© := tendsto_pi
theorem le_pi {g : Filter (β i, Ξ± i)} : g β€ pi f β β i, Tendsto (eval i) g (f i) :=
tendsto_pi
@[mono]
theorem pi_mono (h : β i, fβ i β€ fβ i) : pi fβ β€ pi fβ :=
iInf_mono fun i => comap_mono <| h i
theorem mem_pi_of_mem (i : ΞΉ) {s : Set (Ξ± i)} (hs : s β f i) : eval i β»ΒΉ' s β pi f :=
mem_iInf_of_mem i <| preimage_mem_comap hs
theorem pi_mem_pi {I : Set ΞΉ} (hI : I.Finite) (h : β i β I, s i β f i) : I.pi s β pi f := by
rw [pi_def, biInter_eq_iInter]
refine mem_iInf_of_iInter hI (fun i => ?_) Subset.rfl
exact preimage_mem_comap (h i i.2)
theorem mem_pi {s : Set (β i, Ξ± i)} :
s β pi f β β I : Set ΞΉ, I.Finite β§ β t : β i, Set (Ξ± i), (β i, t i β f i) β§ I.pi t β s := by
constructor
Β· simp only [pi, mem_iInf', mem_comap, pi_def]
rintro β¨I, If, V, hVf, -, rfl, -β©
choose t htf htV using hVf
exact β¨I, If, t, htf, iInterβ_mono fun i _ => htV iβ©
Β· rintro β¨I, If, t, htf, htsβ©
exact mem_of_superset (pi_mem_pi If fun i _ => htf i) hts
theorem mem_pi' {s : Set (β i, Ξ± i)} :
s β pi f β β I : Finset ΞΉ, β t : β i, Set (Ξ± i), (β i, t i β f i) β§ Set.pi (βI) t β s :=
mem_pi.trans exists_finite_iff_finset
theorem mem_of_pi_mem_pi [β i, NeBot (f i)] {I : Set ΞΉ} (h : I.pi s β pi f) {i : ΞΉ} (hi : i β I) :
s i β f i := by
classical
rcases mem_pi.1 h with β¨I', -, t, htf, htsβ©
refine mem_of_superset (htf i) fun x hx => ?_
have : β i, (t i).Nonempty := fun i => nonempty_of_mem (htf i)
choose g hg using this
have : update g i x β I'.pi t := fun j _ => by
rcases eq_or_ne j i with (rfl | hne) <;> simp [*]
simpa using hts this i hi
@[simp]
theorem pi_mem_pi_iff [β i, NeBot (f i)] {I : Set ΞΉ} (hI : I.Finite) :
I.pi s β pi f β β i β I, s i β f i :=
β¨fun h _i hi => mem_of_pi_mem_pi h hi, pi_mem_pi hIβ©
theorem Eventually.eval_pi {i : ΞΉ} (hf : βαΆ x : Ξ± i in f i, p i x) :
βαΆ x : β i : ΞΉ, Ξ± i in pi f, p i (x i) := (tendsto_eval_pi _ _).eventually hf
theorem eventually_pi [Finite ΞΉ] (hf : β i, βαΆ x in f i, p i x) :
βαΆ x : β i, Ξ± i in pi f, β i, p i (x i) := eventually_all.2 fun _i => (hf _).eval_pi
theorem hasBasis_pi {ΞΉ' : ΞΉ β Type*} {s : β i, ΞΉ' i β Set (Ξ± i)} {p : β i, ΞΉ' i β Prop}
(h : β i, (f i).HasBasis (p i) (s i)) :
(pi f).HasBasis (fun If : Set ΞΉ Γ β i, ΞΉ' i => If.1.Finite β§ β i β If.1, p i (If.2 i))
fun If : Set ΞΉ Γ β i, ΞΉ' i => If.1.pi fun i => s i <| If.2 i := by
simpa [Set.pi_def] using hasBasis_iInf' fun i => (h i).comap (eval i : (β j, Ξ± j) β Ξ± i)
theorem hasBasis_pi_same_index {ΞΊ : Type*} {p : ΞΊ β Prop} {s : Ξ i : ΞΉ, ΞΊ β Set (Ξ± i)}
(h : β i : ΞΉ, (f i).HasBasis p (s i))
(h_dir : β I : Set ΞΉ, β k : ΞΉ β ΞΊ, I.Finite β (β i β I, p (k i)) β
β kβ, p kβ β§ β i β I, s i kβ β s i (k i)) :
(pi f).HasBasis (fun Ik : Set ΞΉ Γ ΞΊ β¦ Ik.1.Finite β§ p Ik.2)
(fun Ik β¦ Ik.1.pi (fun i β¦ s i Ik.2)) := by
refine hasBasis_pi h |>.to_hasBasis ?_ ?_
Β· rintro β¨I, kβ© β¨hI, hkβ©
rcases h_dir I k hI hk with β¨kβ, hkβ, hkβ'β©
exact β¨β¨I, kββ©, β¨hI, hkββ©, Set.pi_mono hkβ'β©
Β· rintro β¨I, kβ© β¨hI, hkβ©
exact β¨β¨I, fun _ β¦ kβ©, β¨hI, fun _ _ β¦ hkβ©, subset_rflβ©
theorem HasBasis.pi_self {Ξ± : Type*} {ΞΊ : Type*} {f : Filter Ξ±} {p : ΞΊ β Prop} {s : ΞΊ β Set Ξ±}
(h : f.HasBasis p s) :
(pi fun _ β¦ f).HasBasis (fun Ik : Set ΞΉ Γ ΞΊ β¦ Ik.1.Finite β§ p Ik.2)
(fun Ik β¦ Ik.1.pi (fun _ β¦ s Ik.2)) := by
refine hasBasis_pi_same_index (fun _ β¦ h) (fun I k hI hk β¦ ?_)
rcases h.mem_iff.mp (biInter_mem hI |>.mpr fun i hi β¦ h.mem_of_mem (hk i hi))
with β¨kβ, hkβ, hkβ'β©
exact β¨kβ, hkβ, fun i hi β¦ hkβ'.trans (biInter_subset_of_mem hi)β©
theorem le_pi_principal (s : (i : ΞΉ) β Set (Ξ± i)) :
π (univ.pi s) β€ pi fun i β¦ π (s i) :=
le_pi.2 fun i β¦ tendsto_principal_principal.2 fun _f hf β¦ hf i trivial
/-- The indexed product of finitely many principal filters
is the principal filter corresponding to the cylinder `Set.univ.pi s`.
If the index type is infinite, then `mem_pi_principal` and `hasBasis_pi_principal` may be useful. -/
@[simp]
theorem pi_principal [Finite ΞΉ] (s : (i : ΞΉ) β Set (Ξ± i)) :
pi (fun i β¦ π (s i)) = π (univ.pi s) := by
simp [Filter.pi, Set.pi_def]
/-- The indexed product of a (possibly, infinite) family of principal filters
is generated by the finite `Set.pi` cylinders.
If the index type is finite, then the indexed product of principal filters
is a pricipal filter, see `pi_principal`. -/
theorem mem_pi_principal {t : Set ((i : ΞΉ) β Ξ± i)} :
t β pi (fun i β¦ π (s i)) β β I : Set ΞΉ, I.Finite β§ I.pi s β t :=
(hasBasis_pi (fun i β¦ hasBasis_principal _)).mem_iff.trans <| by simp
/-- The indexed product of a (possibly, infinite) family of principal filters
is generated by the finite `Set.pi` cylinders.
If the index type is finite, then the indexed product of principal filters
is a pricipal filter, see `pi_principal`. -/
theorem hasBasis_pi_principal (s : (i : ΞΉ) β Set (Ξ± i)) :
HasBasis (pi fun i β¦ π (s i)) Set.Finite (Set.pi Β· s) :=
β¨fun _ β¦ mem_pi_principalβ©
/-- The indexed product of finitely many pure filters `pure (f i)` is the pure filter `pure f`.
If the index type is infinite, then `mem_pi_pure` and `hasBasis_pi_pure` below may be useful. -/
@[simp]
theorem pi_pure [Finite ΞΉ] (f : (i : ΞΉ) β Ξ± i) : pi (pure <| f Β·) = pure f := by
simp only [β principal_singleton, pi_principal, univ_pi_singleton]
/-- The indexed product of a (possibly, infinite) family of pure filters `pure (f i)`
is generated by the sets of functions that are equal to `f` on a finite set.
|
If the index type is finite, then the indexed product of pure filters is a pure filter,
| Mathlib/Order/Filter/Pi.lean | 165 | 166 |
/-
Copyright (c) 2022 Aaron Anderson. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Aaron Anderson
-/
import Mathlib.Data.Set.Finite.Lemmas
import Mathlib.ModelTheory.Substructures
/-!
# Finitely Generated First-Order Structures
This file defines what it means for a first-order (sub)structure to be finitely or countably
generated, similarly to other finitely-generated objects in the algebra library.
## Main Definitions
- `FirstOrder.Language.Substructure.FG` indicates that a substructure is finitely generated.
- `FirstOrder.Language.Structure.FG` indicates that a structure is finitely generated.
- `FirstOrder.Language.Substructure.CG` indicates that a substructure is countably generated.
- `FirstOrder.Language.Structure.CG` indicates that a structure is countably generated.
## TODO
Develop a more unified definition of finite generation using the theory of closure operators, or use
this definition of finite generation to define the others.
-/
open FirstOrder Set
namespace FirstOrder
namespace Language
open Structure
variable {L : Language} {M : Type*} [L.Structure M]
namespace Substructure
/-- A substructure of `M` is finitely generated if it is the closure of a finite subset of `M`. -/
def FG (N : L.Substructure M) : Prop :=
β S : Finset M, closure L S = N
theorem fg_def {N : L.Substructure M} : N.FG β β S : Set M, S.Finite β§ closure L S = N :=
β¨fun β¨t, hβ© => β¨_, Finset.finite_toSet t, hβ©, by
rintro β¨t', h, rflβ©
rcases Finite.exists_finset_coe h with β¨t, rflβ©
exact β¨t, rflβ©β©
theorem fg_iff_exists_fin_generating_family {N : L.Substructure M} :
N.FG β β (n : β) (s : Fin n β M), closure L (range s) = N := by
rw [fg_def]
constructor
Β· rintro β¨S, Sfin, hSβ©
obtain β¨n, f, rflβ© := Sfin.fin_embedding
exact β¨n, f, hSβ©
Β· rintro β¨n, s, hsβ©
exact β¨range s, finite_range s, hsβ©
theorem fg_bot : (β₯ : L.Substructure M).FG :=
β¨β
, by rw [Finset.coe_empty, closure_empty]β©
instance instInhabited_fg : Inhabited { S : L.Substructure M // S.FG } := β¨β₯, fg_botβ©
theorem fg_closure {s : Set M} (hs : s.Finite) : FG (closure L s) :=
β¨hs.toFinset, by rw [hs.coe_toFinset]β©
theorem fg_closure_singleton (x : M) : FG (closure L ({x} : Set M)) :=
fg_closure (finite_singleton x)
theorem FG.sup {Nβ Nβ : L.Substructure M} (hNβ : Nβ.FG) (hNβ : Nβ.FG) : (Nβ β Nβ).FG :=
let β¨tβ, htββ© := fg_def.1 hNβ
let β¨tβ, htββ© := fg_def.1 hNβ
fg_def.2 β¨tβ βͺ tβ, htβ.1.union htβ.1, by rw [closure_union, htβ.2, htβ.2]β©
theorem FG.map {N : Type*} [L.Structure N] (f : M β[L] N) {s : L.Substructure M} (hs : s.FG) :
(s.map f).FG :=
let β¨t, htβ© := fg_def.1 hs
fg_def.2 β¨f '' t, ht.1.image _, by rw [closure_image, ht.2]β©
theorem FG.of_map_embedding {N : Type*} [L.Structure N] (f : M βͺ[L] N) {s : L.Substructure M}
(hs : (s.map f.toHom).FG) : s.FG := by
rcases hs with β¨t, hβ©
rw [fg_def]
refine β¨f β»ΒΉ' t, t.finite_toSet.preimage f.injective.injOn, ?_β©
have hf : Function.Injective f.toHom := f.injective
refine map_injective_of_injective hf ?_
rw [β h, map_closure, Embedding.coe_toHom, image_preimage_eq_of_subset]
intro x hx
have h' := subset_closure (L := L) hx
rw [h] at h'
exact Hom.map_le_range h'
theorem FG.of_finite {s : L.Substructure M} [h : Finite s] : s.FG :=
β¨Set.Finite.toFinset h, by simp only [Finite.coe_toFinset, closure_eq]β©
theorem FG.finite [L.IsRelational] {S : L.Substructure M} (h : S.FG) : Finite S := by
obtain β¨s, rflβ© := h
have hs := s.finite_toSet
rw [β closure_eq_of_isRelational L (s : Set M)] at hs
exact hs
theorem fg_iff_finite [L.IsRelational] {S : L.Substructure M} : S.FG β Finite S :=
β¨FG.finite, fun _ => FG.of_finiteβ©
/-- A substructure of `M` is countably generated if it is the closure of a countable subset of `M`.
-/
def CG (N : L.Substructure M) : Prop :=
β S : Set M, S.Countable β§ closure L S = N
theorem cg_def {N : L.Substructure M} : N.CG β β S : Set M, S.Countable β§ closure L S = N :=
Iff.refl _
theorem FG.cg {N : L.Substructure M} (h : N.FG) : N.CG := by
obtain β¨s, hf, rflβ© := fg_def.1 h
exact β¨s, hf.countable, rflβ©
theorem cg_iff_empty_or_exists_nat_generating_family {N : L.Substructure M} :
N.CG β N = (β
: Set M) β¨ β s : β β M, closure L (range s) = N := by
rw [cg_def]
constructor
Β· rintro β¨S, Scount, hSβ©
rcases eq_empty_or_nonempty (N : Set M) with h | h
Β· exact Or.intro_left _ h
obtain β¨f, h'β© :=
(Scount.union (Set.countable_singleton h.some)).exists_eq_range
(singleton_nonempty h.some).inr
refine Or.intro_right _ β¨f, ?_β©
rw [β h', closure_union, hS, sup_eq_left, closure_le]
exact singleton_subset_iff.2 h.some_mem
Β· intro h
rcases h with h | h
Β· refine β¨β
, countable_empty, closure_eq_of_le (empty_subset _) ?_β©
rw [β SetLike.coe_subset_coe, h]
exact empty_subset _
Β· obtain β¨f, rflβ© := h
exact β¨range f, countable_range _, rflβ©
theorem cg_bot : (β₯ : L.Substructure M).CG :=
fg_bot.cg
theorem cg_closure {s : Set M} (hs : s.Countable) : CG (closure L s) :=
β¨s, hs, rflβ©
theorem cg_closure_singleton (x : M) : CG (closure L ({x} : Set M)) :=
(fg_closure_singleton x).cg
theorem CG.sup {Nβ Nβ : L.Substructure M} (hNβ : Nβ.CG) (hNβ : Nβ.CG) : (Nβ β Nβ).CG :=
let β¨tβ, htββ© := cg_def.1 hNβ
let β¨tβ, htββ© := cg_def.1 hNβ
cg_def.2 β¨tβ βͺ tβ, htβ.1.union htβ.1, by rw [closure_union, htβ.2, htβ.2]β©
theorem CG.map {N : Type*} [L.Structure N] (f : M β[L] N) {s : L.Substructure M} (hs : s.CG) :
| (s.map f).CG :=
let β¨t, htβ© := cg_def.1 hs
cg_def.2 β¨f '' t, ht.1.image _, by rw [closure_image, ht.2]β©
| Mathlib/ModelTheory/FinitelyGenerated.lean | 156 | 159 |
/-
Copyright (c) 2021 Anatole Dedecker. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Anatole Dedecker
-/
import Mathlib.Order.Antichain
import Mathlib.Topology.ContinuousOn
/-!
# Left and right continuity
In this file we prove a few lemmas about left and right continuous functions:
* `continuousWithinAt_Ioi_iff_Ici`: two definitions of right continuity
(with `(a, β)` and with `[a, β)`) are equivalent;
* `continuousWithinAt_Iio_iff_Iic`: two definitions of left continuity
(with `(-β, a)` and with `(-β, a]`) are equivalent;
* `continuousAt_iff_continuous_left_right`, `continuousAt_iff_continuous_left'_right'` :
a function is continuous at `a` if and only if it is left and right continuous at `a`.
## Tags
left continuous, right continuous
-/
open Set Filter Topology
section Preorder
variable {Ξ± : Type*} [TopologicalSpace Ξ±] [Preorder Ξ±]
lemma frequently_lt_nhds (a : Ξ±) [NeBot (π[<] a)] : βαΆ x in π a, x < a :=
frequently_iff_neBot.2 βΉ_βΊ
lemma frequently_gt_nhds (a : Ξ±) [NeBot (π[>] a)] : βαΆ x in π a, a < x :=
frequently_iff_neBot.2 βΉ_βΊ
theorem Filter.Eventually.exists_lt {a : Ξ±} [NeBot (π[<] a)] {p : Ξ± β Prop}
(h : βαΆ x in π a, p x) : β b < a, p b :=
((frequently_lt_nhds a).and_eventually h).exists
theorem Filter.Eventually.exists_gt {a : Ξ±} [NeBot (π[>] a)] {p : Ξ± β Prop}
(h : βαΆ x in π a, p x) : β b > a, p b :=
((frequently_gt_nhds a).and_eventually h).exists
theorem nhdsWithin_Ici_neBot {a b : Ξ±} (Hβ : a β€ b) : NeBot (π[Ici a] b) :=
nhdsWithin_neBot_of_mem Hβ
instance nhdsGE_neBot (a : Ξ±) : NeBot (π[β₯] a) := nhdsWithin_Ici_neBot (le_refl a)
@[deprecated nhdsGE_neBot (since := "2024-12-21")]
theorem nhdsWithin_Ici_self_neBot (a : Ξ±) : NeBot (π[β₯] a) := nhdsGE_neBot a
theorem nhdsWithin_Iic_neBot {a b : Ξ±} (H : a β€ b) : NeBot (π[Iic b] a) :=
nhdsWithin_neBot_of_mem H
instance nhdsLE_neBot (a : Ξ±) : NeBot (π[β€] a) := nhdsWithin_Iic_neBot (le_refl a)
@[deprecated nhdsLE_neBot (since := "2024-12-21")]
theorem nhdsWithin_Iic_self_neBot (a : Ξ±) : NeBot (π[β€] a) := nhdsLE_neBot a
theorem nhdsLT_le_nhdsNE (a : Ξ±) : π[<] a β€ π[β ] a :=
nhdsWithin_mono a fun _ => ne_of_lt
@[deprecated (since := "2024-12-21")] alias nhds_left'_le_nhds_ne := nhdsLT_le_nhdsNE
theorem nhdsGT_le_nhdsNE (a : Ξ±) : π[>] a β€ π[β ] a := nhdsWithin_mono a fun _ => ne_of_gt
@[deprecated (since := "2024-12-21")] alias nhds_right'_le_nhds_ne := nhdsGT_le_nhdsNE
-- TODO: add instances for `NeBot (π[<] x)` on (indexed) product types
lemma IsAntichain.interior_eq_empty [β x : Ξ±, (π[<] x).NeBot] {s : Set Ξ±}
(hs : IsAntichain (Β· β€ Β·) s) : interior s = β
:= by
refine eq_empty_of_forall_not_mem fun x hx β¦ ?_
have : βαΆ y in π x, y β s := mem_interior_iff_mem_nhds.1 hx
rcases this.exists_lt with β¨y, hyx, hysβ©
exact hs hys (interior_subset hx) hyx.ne hyx.le
lemma IsAntichain.interior_eq_empty' [β x : Ξ±, (π[>] x).NeBot] {s : Set Ξ±}
(hs : IsAntichain (Β· β€ Β·) s) : interior s = β
:=
have : β x : Ξ±α΅α΅, NeBot (π[<] x) := βΉ_βΊ
hs.to_dual.interior_eq_empty
end Preorder
section PartialOrder
variable {Ξ± Ξ² : Type*} [TopologicalSpace Ξ±] [PartialOrder Ξ±] [TopologicalSpace Ξ²]
theorem continuousWithinAt_Ioi_iff_Ici {a : Ξ±} {f : Ξ± β Ξ²} :
ContinuousWithinAt f (Ioi a) a β ContinuousWithinAt f (Ici a) a := by
simp only [β Ici_diff_left, continuousWithinAt_diff_self]
|
theorem continuousWithinAt_Iio_iff_Iic {a : Ξ±} {f : Ξ± β Ξ²} :
ContinuousWithinAt f (Iio a) a β ContinuousWithinAt f (Iic a) a :=
| Mathlib/Topology/Order/LeftRight.lean | 95 | 97 |
/-
Copyright (c) 2022 Chris Birkbeck. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Birkbeck, David Loeffler
-/
import Mathlib.Algebra.Module.Submodule.Basic
import Mathlib.Analysis.Asymptotics.Lemmas
import Mathlib.Algebra.Algebra.Pi
/-!
# Zero and Bounded at filter
Given a filter `l` we define the notion of a function being `ZeroAtFilter` as well as being
`BoundedAtFilter`. Alongside this we construct the `Submodule`, `AddSubmonoid` of functions
that are `ZeroAtFilter`. Similarly, we construct the `Submodule` and `Subalgebra` of functions
that are `BoundedAtFilter`.
-/
namespace Filter
variable {π Ξ± Ξ² : Type*}
open Topology
/-- If `l` is a filter on `Ξ±`, then a function `f : Ξ± β Ξ²` is `ZeroAtFilter l`
if it tends to zero along `l`. -/
def ZeroAtFilter [Zero Ξ²] [TopologicalSpace Ξ²] (l : Filter Ξ±) (f : Ξ± β Ξ²) : Prop :=
Filter.Tendsto f l (π 0)
theorem zero_zeroAtFilter [Zero Ξ²] [TopologicalSpace Ξ²] (l : Filter Ξ±) :
ZeroAtFilter l (0 : Ξ± β Ξ²) :=
tendsto_const_nhds
nonrec theorem ZeroAtFilter.add [TopologicalSpace Ξ²] [AddZeroClass Ξ²] [ContinuousAdd Ξ²]
{l : Filter Ξ±} {f g : Ξ± β Ξ²} (hf : ZeroAtFilter l f) (hg : ZeroAtFilter l g) :
ZeroAtFilter l (f + g) := by
simpa using hf.add hg
| nonrec theorem ZeroAtFilter.neg [TopologicalSpace Ξ²] [SubtractionMonoid Ξ²] [ContinuousNeg Ξ²]
{l : Filter Ξ±} {f : Ξ± β Ξ²} (hf : ZeroAtFilter l f) : ZeroAtFilter l (-f) := by
simpa using hf.neg
| Mathlib/Order/Filter/ZeroAndBoundedAtFilter.lean | 41 | 44 |
/-
Copyright (c) 2019 Kim Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kim Morrison
-/
import Mathlib.Data.List.Lattice
import Mathlib.Data.Bool.Basic
import Mathlib.Order.Lattice
/-!
# Intervals in β
This file defines intervals of naturals. `List.Ico m n` is the list of integers greater than `m`
and strictly less than `n`.
## TODO
- Define `Ioo` and `Icc`, state basic lemmas about them.
- Also do the versions for integers?
- One could generalise even further, defining 'locally finite partial orders', for which
`Set.Ico a b` is `[Finite]`, and 'locally finite total orders', for which there is a list model.
- Once the above is done, get rid of `Int.range` (and maybe `List.range'`?).
-/
open Nat
namespace List
/-- `Ico n m` is the list of natural numbers `n β€ x < m`.
(Ico stands for "interval, closed-open".)
See also `Mathlib/Order/Interval/Basic.lean` for modelling intervals in general preorders, as well
as sibling definitions alongside it such as `Set.Ico`, `Multiset.Ico` and `Finset.Ico`
for sets, multisets and finite sets respectively.
-/
def Ico (n m : β) : List β :=
range' n (m - n)
namespace Ico
theorem zero_bot (n : β) : Ico 0 n = range n := by rw [Ico, Nat.sub_zero, range_eq_range']
@[simp]
theorem length (n m : β) : length (Ico n m) = m - n := by
dsimp [Ico]
simp [length_range']
theorem pairwise_lt (n m : β) : Pairwise (Β· < Β·) (Ico n m) := by
dsimp [Ico]
simp [pairwise_lt_range']
theorem nodup (n m : β) : Nodup (Ico n m) := by
dsimp [Ico]
simp [nodup_range']
@[simp]
theorem mem {n m l : β} : l β Ico n m β n β€ l β§ l < m := by
suffices n β€ l β§ l < n + (m - n) β n β€ l β§ l < m by simp [Ico, this]
omega
theorem eq_nil_of_le {n m : β} (h : m β€ n) : Ico n m = [] := by
simp [Ico, Nat.sub_eq_zero_iff_le.mpr h]
theorem map_add (n m k : β) : (Ico n m).map (k + Β·) = Ico (n + k) (m + k) := by
rw [Ico, Ico, map_add_range', Nat.add_sub_add_right m k, Nat.add_comm n k]
theorem map_sub (n m k : β) (hβ : k β€ n) :
((Ico n m).map fun x => x - k) = Ico (n - k) (m - k) := by
rw [Ico, Ico, Nat.sub_sub_sub_cancel_right hβ, map_sub_range' hβ]
@[simp]
theorem self_empty {n : β} : Ico n n = [] :=
eq_nil_of_le (le_refl n)
@[simp]
theorem eq_empty_iff {n m : β} : Ico n m = [] β m β€ n :=
Iff.intro (fun h => Nat.sub_eq_zero_iff_le.mp <| by rw [β length, h, List.length]) eq_nil_of_le
theorem append_consecutive {n m l : β} (hnm : n β€ m) (hml : m β€ l) :
Ico n m ++ Ico m l = Ico n l := by
dsimp only [Ico]
convert range'_append using 2
Β· rw [Nat.one_mul, Nat.add_sub_cancel' hnm]
Β· omega
@[simp]
theorem inter_consecutive (n m l : β) : Ico n m β© Ico m l = [] := by
apply eq_nil_iff_forall_not_mem.2
intro a
simp only [and_imp, not_and, not_lt, List.mem_inter_iff, List.Ico.mem]
intro _ hβ hβ
exfalso
exact not_lt_of_ge hβ hβ
@[simp]
theorem bagInter_consecutive (n m l : Nat) :
@List.bagInter β instBEqOfDecidableEq (Ico n m) (Ico m l) = [] :=
(bagInter_nil_iff_inter_nil _ _).2 (by convert inter_consecutive n m l)
@[simp]
theorem succ_singleton {n : β} : Ico n (n + 1) = [n] := by
dsimp [Ico]
simp [range', Nat.add_sub_cancel_left]
theorem succ_top {n m : β} (h : n β€ m) : Ico n (m + 1) = Ico n m ++ [m] := by
rwa [β succ_singleton, append_consecutive]
exact Nat.le_succ _
theorem eq_cons {n m : β} (h : n < m) : Ico n m = n :: Ico (n + 1) m := by
rw [β append_consecutive (Nat.le_succ n) h, succ_singleton]
rfl
@[simp]
theorem pred_singleton {m : β} (h : 0 < m) : Ico (m - 1) m = [m - 1] := by
simp [Ico, Nat.sub_sub_self (succ_le_of_lt h)]
theorem chain'_succ (n m : β) : Chain' (fun a b => b = succ a) (Ico n m) := by
by_cases h : n < m
Β· rw [eq_cons h]
exact chain_succ_range' _ _ 1
Β· rw [eq_nil_of_le (le_of_not_gt h)]
trivial
theorem not_mem_top {n m : β} : m β Ico n m := by simp
theorem filter_lt_of_top_le {n m l : β} (hml : m β€ l) :
((Ico n m).filter fun x => x < l) = Ico n m :=
filter_eq_self.2 fun k hk => by
simp only [(lt_of_lt_of_le (mem.1 hk).2 hml), decide_true]
theorem filter_lt_of_le_bot {n m l : β} (hln : l β€ n) : ((Ico n m).filter fun x => x < l) = [] :=
filter_eq_nil_iff.2 fun k hk => by
simp only [decide_eq_true_eq, not_lt]
apply le_trans hln
exact (mem.1 hk).1
theorem filter_lt_of_ge {n m l : β} (hlm : l β€ m) :
((Ico n m).filter fun x => x < l) = Ico n l := by
rcases le_total n l with hnl | hln
Β· rw [β append_consecutive hnl hlm, filter_append, filter_lt_of_top_le (le_refl l),
filter_lt_of_le_bot (le_refl l), append_nil]
Β· rw [eq_nil_of_le hln, filter_lt_of_le_bot hln]
@[simp]
theorem filter_lt (n m l : β) :
((Ico n m).filter fun x => x < l) = Ico n (min m l) := by
rcases le_total m l with hml | hlm
Β· rw [min_eq_left hml, filter_lt_of_top_le hml]
Β· rw [min_eq_right hlm, filter_lt_of_ge hlm]
theorem filter_le_of_le_bot {n m l : β} (hln : l β€ n) :
((Ico n m).filter fun x => l β€ x) = Ico n m :=
filter_eq_self.2 fun k hk => by
rw [decide_eq_true_eq]
exact le_trans hln (mem.1 hk).1
|
theorem filter_le_of_top_le {n m l : β} (hml : m β€ l) : ((Ico n m).filter fun x => l β€ x) = [] :=
filter_eq_nil_iff.2 fun k hk => by
rw [decide_eq_true_eq]
| Mathlib/Data/List/Intervals.lean | 156 | 159 |
/-
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.Algebra.Defs
import Mathlib.Algebra.Order.Module.Defs
/-!
# Ordered algebras
This file proves properties of algebras where both rings are ordered compatibly.
## TODO
`positivity` extension for `algebraMap`
-/
variable {Ξ± Ξ² : Type*} [CommSemiring Ξ±] [PartialOrder Ξ±]
section OrderedSemiring
variable (Ξ²)
variable [Semiring Ξ²] [PartialOrder Ξ²] [IsOrderedRing Ξ²] [Algebra Ξ± Ξ²] [SMulPosMono Ξ± Ξ²] {a : Ξ±}
@[mono] lemma algebraMap_mono : Monotone (algebraMap Ξ± Ξ²) :=
fun aβ aβ ha β¦ by
simpa only [Algebra.algebraMap_eq_smul_one] using smul_le_smul_of_nonneg_right ha zero_le_one
/-- A version of `algebraMap_mono` for use by `gcongr` since it currently does not preprocess
`Monotone` conclusions. -/
@[gcongr] protected lemma GCongr.algebraMap_le_algebraMap {aβ aβ : Ξ±} (ha : aβ β€ aβ) :
algebraMap Ξ± Ξ² aβ β€ algebraMap Ξ± Ξ² aβ := algebraMap_mono _ ha
| lemma algebraMap_nonneg (ha : 0 β€ a) : 0 β€ algebraMap Ξ± Ξ² a := by simpa using algebraMap_mono Ξ² ha
| Mathlib/Algebra/Order/Module/Algebra.lean | 34 | 34 |
/-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle SΓΆnne, Benjamin Davidson
-/
import Mathlib.Analysis.SpecialFunctions.Trigonometric.Angle
import Mathlib.Analysis.SpecialFunctions.Trigonometric.Inverse
/-!
# The argument of a complex number.
We define `arg : β β β`, returning a real number in the range (-Ο, Ο],
such that for `x β 0`, `sin (arg x) = x.im / x.abs` and `cos (arg x) = x.re / x.abs`,
while `arg 0` defaults to `0`
-/
open Filter Metric Set
open scoped ComplexConjugate Real Topology
namespace Complex
variable {a x z : β}
/-- `arg` returns values in the range (-Ο, Ο], such that for `x β 0`,
`sin (arg x) = x.im / x.abs` and `cos (arg x) = x.re / x.abs`,
`arg 0` defaults to `0` -/
noncomputable def arg (x : β) : β :=
if 0 β€ x.re then Real.arcsin (x.im / βxβ)
else if 0 β€ x.im then Real.arcsin ((-x).im / βxβ) + Ο else Real.arcsin ((-x).im / βxβ) - Ο
theorem sin_arg (x : β) : Real.sin (arg x) = x.im / βxβ := by
unfold arg; split_ifs <;>
simp [sub_eq_add_neg, arg, Real.sin_arcsin (abs_le.1 (abs_im_div_norm_le_one x)).1
(abs_le.1 (abs_im_div_norm_le_one x)).2, Real.sin_add, neg_div, Real.arcsin_neg, Real.sin_neg]
theorem cos_arg {x : β} (hx : x β 0) : Real.cos (arg x) = x.re / βxβ := by
rw [arg]
split_ifs with hβ hβ
Β· rw [Real.cos_arcsin]
field_simp [Real.sqrt_sq, (norm_pos_iff.mpr hx).le, *]
Β· rw [Real.cos_add_pi, Real.cos_arcsin]
field_simp [Real.sqrt_div (sq_nonneg _), Real.sqrt_sq_eq_abs,
_root_.abs_of_neg (not_le.1 hβ), *]
Β· rw [Real.cos_sub_pi, Real.cos_arcsin]
field_simp [Real.sqrt_div (sq_nonneg _), Real.sqrt_sq_eq_abs,
_root_.abs_of_neg (not_le.1 hβ), *]
@[simp]
theorem norm_mul_exp_arg_mul_I (x : β) : βxβ * exp (arg x * I) = x := by
rcases eq_or_ne x 0 with (rfl | hx)
Β· simp
Β· have : βxβ β 0 := norm_ne_zero_iff.mpr hx
apply Complex.ext <;> field_simp [sin_arg, cos_arg hx, this, mul_comm βxβ]
@[simp]
theorem norm_mul_cos_add_sin_mul_I (x : β) : (βxβ * (cos (arg x) + sin (arg x) * I) : β) = x := by
rw [β exp_mul_I, norm_mul_exp_arg_mul_I]
@[simp]
lemma norm_mul_cos_arg (x : β) : βxβ * Real.cos (arg x) = x.re := by
simpa [-norm_mul_cos_add_sin_mul_I] using congr_arg re (norm_mul_cos_add_sin_mul_I x)
@[simp]
lemma norm_mul_sin_arg (x : β) : βxβ * Real.sin (arg x) = x.im := by
simpa [-norm_mul_cos_add_sin_mul_I] using congr_arg im (norm_mul_cos_add_sin_mul_I x)
theorem norm_eq_one_iff (z : β) : βzβ = 1 β β ΞΈ : β, exp (ΞΈ * I) = z := by
refine β¨fun hz => β¨arg z, ?_β©, ?_β©
Β· calc
exp (arg z * I) = βzβ * exp (arg z * I) := by rw [hz, ofReal_one, one_mul]
_ = z :=norm_mul_exp_arg_mul_I z
Β· rintro β¨ΞΈ, rflβ©
exact Complex.norm_exp_ofReal_mul_I ΞΈ
@[deprecated (since := "2025-02-16")] alias abs_mul_exp_arg_mul_I := norm_mul_exp_arg_mul_I
@[deprecated (since := "2025-02-16")] alias abs_mul_cos_add_sin_mul_I := norm_mul_cos_add_sin_mul_I
@[deprecated (since := "2025-02-16")] alias abs_mul_cos_arg := norm_mul_cos_arg
@[deprecated (since := "2025-02-16")] alias abs_mul_sin_arg := norm_mul_sin_arg
@[deprecated (since := "2025-02-16")] alias abs_eq_one_iff := norm_eq_one_iff
@[simp]
theorem range_exp_mul_I : (Set.range fun x : β => exp (x * I)) = Metric.sphere 0 1 := by
ext x
simp only [mem_sphere_zero_iff_norm, norm_eq_one_iff, Set.mem_range]
theorem arg_mul_cos_add_sin_mul_I {r : β} (hr : 0 < r) {ΞΈ : β} (hΞΈ : ΞΈ β Set.Ioc (-Ο) Ο) :
arg (r * (cos ΞΈ + sin ΞΈ * I)) = ΞΈ := by
simp only [arg, norm_mul, norm_cos_add_sin_mul_I, Complex.norm_of_nonneg hr.le, mul_one]
simp only [re_ofReal_mul, im_ofReal_mul, neg_im, β ofReal_cos, β ofReal_sin, β
mk_eq_add_mul_I, neg_div, mul_div_cancel_leftβ _ hr.ne', mul_nonneg_iff_right_nonneg_of_pos hr]
by_cases hβ : ΞΈ β Set.Icc (-(Ο / 2)) (Ο / 2)
Β· rw [if_pos]
exacts [Real.arcsin_sin' hβ, Real.cos_nonneg_of_mem_Icc hβ]
Β· rw [Set.mem_Icc, not_and_or, not_le, not_le] at hβ
rcases hβ with hβ | hβ
Β· replace hΞΈ := hΞΈ.1
have hcos : Real.cos ΞΈ < 0 := by
rw [β neg_pos, β Real.cos_add_pi]
refine Real.cos_pos_of_mem_Ioo β¨?_, ?_β© <;> linarith
have hsin : Real.sin ΞΈ < 0 := Real.sin_neg_of_neg_of_neg_pi_lt (by linarith) hΞΈ
rw [if_neg, if_neg, β Real.sin_add_pi, Real.arcsin_sin, add_sub_cancel_right] <;> [linarith;
linarith; exact hsin.not_le; exact hcos.not_le]
Β· replace hΞΈ := hΞΈ.2
have hcos : Real.cos ΞΈ < 0 := Real.cos_neg_of_pi_div_two_lt_of_lt hβ (by linarith)
have hsin : 0 β€ Real.sin ΞΈ := Real.sin_nonneg_of_mem_Icc β¨by linarith, hΞΈβ©
rw [if_neg, if_pos, β Real.sin_sub_pi, Real.arcsin_sin, sub_add_cancel] <;> [linarith;
linarith; exact hsin; exact hcos.not_le]
theorem arg_cos_add_sin_mul_I {ΞΈ : β} (hΞΈ : ΞΈ β Set.Ioc (-Ο) Ο) : arg (cos ΞΈ + sin ΞΈ * I) = ΞΈ := by
rw [β one_mul (_ + _), β ofReal_one, arg_mul_cos_add_sin_mul_I zero_lt_one hΞΈ]
lemma arg_exp_mul_I (ΞΈ : β) :
arg (exp (ΞΈ * I)) = toIocMod (mul_pos two_pos Real.pi_pos) (-Ο) ΞΈ := by
convert arg_cos_add_sin_mul_I (ΞΈ := toIocMod (mul_pos two_pos Real.pi_pos) (-Ο) ΞΈ) _ using 2
Β· rw [β exp_mul_I, eq_sub_of_add_eq <| toIocMod_add_toIocDiv_zsmul _ _ ΞΈ, ofReal_sub,
ofReal_zsmul, ofReal_mul, ofReal_ofNat, exp_mul_I_periodic.sub_zsmul_eq]
Β· convert toIocMod_mem_Ioc _ _ _
ring
@[simp]
theorem arg_zero : arg 0 = 0 := by simp [arg, le_refl]
theorem ext_norm_arg {x y : β} (hβ : βxβ = βyβ) (hβ : x.arg = y.arg) : x = y := by
| rw [β norm_mul_exp_arg_mul_I x, β norm_mul_exp_arg_mul_I y, hβ, hβ]
theorem ext_norm_arg_iff {x y : β} : x = y β βxβ = βyβ β§ arg x = arg y :=
β¨fun h => h βΈ β¨rfl, rflβ©, and_imp.2 ext_norm_argβ©
@[deprecated (since := "2025-02-16")] alias ext_abs_arg := ext_norm_arg
@[deprecated (since := "2025-02-16")] alias ext_abs_arg_iff := ext_norm_arg_iff
| Mathlib/Analysis/SpecialFunctions/Complex/Arg.lean | 123 | 129 |
/-
Copyright (c) 2023 YaΓ«l Dillies. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: YaΓ«l Dillies
-/
import Mathlib.Algebra.NoZeroSMulDivisors.Basic
import Mathlib.Algebra.Order.GroupWithZero.Action.Synonym
import Mathlib.Tactic.GCongr
import Mathlib.Tactic.Positivity.Core
/-!
# Monotonicity of scalar multiplication by positive elements
This file defines typeclasses to reason about monotonicity of the operations
* `b β¦ a β’ b`, "left scalar multiplication"
* `a β¦ a β’ b`, "right scalar multiplication"
We use eight typeclasses to encode the various properties we care about for those two operations.
These typeclasses are meant to be mostly internal to this file, to set up each lemma in the
appropriate generality.
Less granular typeclasses like `OrderedAddCommMonoid`, `LinearOrderedField`, `OrderedSMul` should be
enough for most purposes, and the system is set up so that they imply the correct granular
typeclasses here. If those are enough for you, you may stop reading here! Else, beware that what
follows is a bit technical.
## Definitions
In all that follows, `Ξ±` and `Ξ²` are orders which have a `0` and such that `Ξ±` acts on `Ξ²` by scalar
multiplication. Note however that we do not use lawfulness of this action in most of the file. Hence
`β’` should be considered here as a mostly arbitrary function `Ξ± β Ξ² β Ξ²`.
We use the following four typeclasses to reason about left scalar multiplication (`b β¦ a β’ b`):
* `PosSMulMono`: If `a β₯ 0`, then `bβ β€ bβ` implies `a β’ bβ β€ a β’ bβ`.
* `PosSMulStrictMono`: If `a > 0`, then `bβ < bβ` implies `a β’ bβ < a β’ bβ`.
* `PosSMulReflectLT`: If `a β₯ 0`, then `a β’ bβ < a β’ bβ` implies `bβ < bβ`.
* `PosSMulReflectLE`: If `a > 0`, then `a β’ bβ β€ a β’ bβ` implies `bβ β€ bβ`.
We use the following four typeclasses to reason about right scalar multiplication (`a β¦ a β’ b`):
* `SMulPosMono`: If `b β₯ 0`, then `aβ β€ aβ` implies `aβ β’ b β€ aβ β’ b`.
* `SMulPosStrictMono`: If `b > 0`, then `aβ < aβ` implies `aβ β’ b < aβ β’ b`.
* `SMulPosReflectLT`: If `b β₯ 0`, then `aβ β’ b < aβ β’ b` implies `aβ < aβ`.
* `SMulPosReflectLE`: If `b > 0`, then `aβ β’ b β€ aβ β’ b` implies `aβ β€ aβ`.
## Constructors
The four typeclasses about nonnegativity can usually be checked only on positive inputs due to their
condition becoming trivial when `a = 0` or `b = 0`. We therefore make the following constructors
available: `PosSMulMono.of_pos`, `PosSMulReflectLT.of_pos`, `SMulPosMono.of_pos`,
`SMulPosReflectLT.of_pos`
## Implications
As `Ξ±` and `Ξ²` get more and more structure, those typeclasses end up being equivalent. The commonly
used implications are:
* When `Ξ±`, `Ξ²` are partial orders:
* `PosSMulStrictMono β PosSMulMono`
* `SMulPosStrictMono β SMulPosMono`
* `PosSMulReflectLE β PosSMulReflectLT`
* `SMulPosReflectLE β SMulPosReflectLT`
* When `Ξ²` is a linear order:
* `PosSMulStrictMono β PosSMulReflectLE`
* `PosSMulReflectLT β PosSMulMono` (not registered as instance)
* `SMulPosReflectLT β SMulPosMono` (not registered as instance)
* `PosSMulReflectLE β PosSMulStrictMono` (not registered as instance)
* `SMulPosReflectLE β SMulPosStrictMono` (not registered as instance)
* When `Ξ±` is a linear order:
* `SMulPosStrictMono β SMulPosReflectLE`
* When `Ξ±` is an ordered ring, `Ξ²` an ordered group and also an `Ξ±`-module:
* `PosSMulMono β SMulPosMono`
* `PosSMulStrictMono β SMulPosStrictMono`
* When `Ξ±` is an linear ordered semifield, `Ξ²` is an `Ξ±`-module:
* `PosSMulStrictMono β PosSMulReflectLT`
* `PosSMulMono β PosSMulReflectLE`
* When `Ξ±` is a semiring, `Ξ²` is an `Ξ±`-module with `NoZeroSMulDivisors`:
* `PosSMulMono β PosSMulStrictMono` (not registered as instance)
* When `Ξ±` is a ring, `Ξ²` is an `Ξ±`-module with `NoZeroSMulDivisors`:
* `SMulPosMono β SMulPosStrictMono` (not registered as instance)
Further, the bundled non-granular typeclasses imply the granular ones like so:
* `OrderedSMul β PosSMulStrictMono`
* `OrderedSMul β PosSMulReflectLT`
Unless otherwise stated, all these implications are registered as instances,
which means that in practice you should not worry about these implications.
However, if you encounter a case where you think a statement is true but
not covered by the current implications, please bring it up on Zulip!
## Implementation notes
This file uses custom typeclasses instead of abbreviations of `CovariantClass`/`ContravariantClass`
because:
* They get displayed as classes in the docs. In particular, one can see their list of instances,
instead of their instances being invariably dumped to the `CovariantClass`/`ContravariantClass`
list.
* They don't pollute other typeclass searches. Having many abbreviations of the same typeclass for
different purposes always felt like a performance issue (more instances with the same key, for no
added benefit), and indeed making the classes here abbreviation previous creates timeouts due to
the higher number of `CovariantClass`/`ContravariantClass` instances.
* `SMulPosReflectLT`/`SMulPosReflectLE` do not fit in the framework since they relate `β€` on two
different types. So we would have to generalise `CovariantClass`/`ContravariantClass` to three
types and two relations.
* Very minor, but the constructors let you work with `a : Ξ±`, `h : 0 β€ a` instead of
`a : {a : Ξ± // 0 β€ a}`. This actually makes some instances surprisingly cleaner to prove.
* The `CovariantClass`/`ContravariantClass` framework is only useful to automate very simple logic
anyway. It is easily copied over.
In the future, it would be good to make the corresponding typeclasses in
`Mathlib.Algebra.Order.GroupWithZero.Unbundled` custom typeclasses too.
## TODO
This file acts as a substitute for `Mathlib.Algebra.Order.SMul`. We now need to
* finish the transition by deleting the duplicate lemmas
* rearrange the non-duplicate lemmas into new files
* generalise (most of) the lemmas from `Mathlib.Algebra.Order.Module` to here
* rethink `OrderedSMul`
-/
open OrderDual
variable (Ξ± Ξ² : Type*)
section Defs
variable [SMul Ξ± Ξ²] [Preorder Ξ±] [Preorder Ξ²]
section Left
variable [Zero Ξ±]
/-- Typeclass for monotonicity of scalar multiplication by nonnegative elements on the left,
namely `bβ β€ bβ β a β’ bβ β€ a β’ bβ` if `0 β€ a`.
You should usually not use this very granular typeclass directly, but rather a typeclass like
`OrderedSMul`. -/
class PosSMulMono : Prop where
/-- Do not use this. Use `smul_le_smul_of_nonneg_left` instead. -/
protected elim β¦a : Ξ±β¦ (ha : 0 β€ a) β¦bβ bβ : Ξ²β¦ (hb : bβ β€ bβ) : a β’ bβ β€ a β’ bβ
/-- Typeclass for strict monotonicity of scalar multiplication by positive elements on the left,
namely `bβ < bβ β a β’ bβ < a β’ bβ` if `0 < a`.
You should usually not use this very granular typeclass directly, but rather a typeclass like
`OrderedSMul`. -/
class PosSMulStrictMono : Prop where
/-- Do not use this. Use `smul_lt_smul_of_pos_left` instead. -/
protected elim β¦a : Ξ±β¦ (ha : 0 < a) β¦bβ bβ : Ξ²β¦ (hb : bβ < bβ) : a β’ bβ < a β’ bβ
/-- Typeclass for strict reverse monotonicity of scalar multiplication by nonnegative elements on
the left, namely `a β’ bβ < a β’ bβ β bβ < bβ` if `0 β€ a`.
You should usually not use this very granular typeclass directly, but rather a typeclass like
`OrderedSMul`. -/
class PosSMulReflectLT : Prop where
/-- Do not use this. Use `lt_of_smul_lt_smul_left` instead. -/
protected elim β¦a : Ξ±β¦ (ha : 0 β€ a) β¦bβ bβ : Ξ²β¦ (hb : a β’ bβ < a β’ bβ) : bβ < bβ
/-- Typeclass for reverse monotonicity of scalar multiplication by positive elements on the left,
namely `a β’ bβ β€ a β’ bβ β bβ β€ bβ` if `0 < a`.
You should usually not use this very granular typeclass directly, but rather a typeclass like
`OrderedSMul`. -/
class PosSMulReflectLE : Prop where
/-- Do not use this. Use `le_of_smul_lt_smul_left` instead. -/
protected elim β¦a : Ξ±β¦ (ha : 0 < a) β¦bβ bβ : Ξ²β¦ (hb : a β’ bβ β€ a β’ bβ) : bβ β€ bβ
end Left
section Right
variable [Zero Ξ²]
/-- Typeclass for monotonicity of scalar multiplication by nonnegative elements on the left,
namely `aβ β€ aβ β aβ β’ b β€ aβ β’ b` if `0 β€ b`.
You should usually not use this very granular typeclass directly, but rather a typeclass like
`OrderedSMul`. -/
class SMulPosMono : Prop where
/-- Do not use this. Use `smul_le_smul_of_nonneg_right` instead. -/
protected elim β¦b : Ξ²β¦ (hb : 0 β€ b) β¦aβ aβ : Ξ±β¦ (ha : aβ β€ aβ) : aβ β’ b β€ aβ β’ b
/-- Typeclass for strict monotonicity of scalar multiplication by positive elements on the left,
namely `aβ < aβ β aβ β’ b < aβ β’ b` if `0 < b`.
You should usually not use this very granular typeclass directly, but rather a typeclass like
`OrderedSMul`. -/
class SMulPosStrictMono : Prop where
/-- Do not use this. Use `smul_lt_smul_of_pos_right` instead. -/
protected elim β¦b : Ξ²β¦ (hb : 0 < b) β¦aβ aβ : Ξ±β¦ (ha : aβ < aβ) : aβ β’ b < aβ β’ b
/-- Typeclass for strict reverse monotonicity of scalar multiplication by nonnegative elements on
the left, namely `aβ β’ b < aβ β’ b β aβ < aβ` if `0 β€ b`.
You should usually not use this very granular typeclass directly, but rather a typeclass like
`OrderedSMul`. -/
class SMulPosReflectLT : Prop where
/-- Do not use this. Use `lt_of_smul_lt_smul_right` instead. -/
protected elim β¦b : Ξ²β¦ (hb : 0 β€ b) β¦aβ aβ : Ξ±β¦ (hb : aβ β’ b < aβ β’ b) : aβ < aβ
/-- Typeclass for reverse monotonicity of scalar multiplication by positive elements on the left,
namely `aβ β’ b β€ aβ β’ b β aβ β€ aβ` if `0 < b`.
You should usually not use this very granular typeclass directly, but rather a typeclass like
`OrderedSMul`. -/
class SMulPosReflectLE : Prop where
/-- Do not use this. Use `le_of_smul_lt_smul_right` instead. -/
protected elim β¦b : Ξ²β¦ (hb : 0 < b) β¦aβ aβ : Ξ±β¦ (hb : aβ β’ b β€ aβ β’ b) : aβ β€ aβ
end Right
end Defs
variable {Ξ± Ξ²} {a aβ aβ : Ξ±} {b bβ bβ : Ξ²}
section Mul
variable [Zero Ξ±] [Mul Ξ±] [Preorder Ξ±]
-- See note [lower instance priority]
instance (priority := 100) PosMulMono.toPosSMulMono [PosMulMono Ξ±] : PosSMulMono Ξ± Ξ± where
elim _a ha _bβ _bβ hb := mul_le_mul_of_nonneg_left hb ha
-- See note [lower instance priority]
instance (priority := 100) PosMulStrictMono.toPosSMulStrictMono [PosMulStrictMono Ξ±] :
PosSMulStrictMono Ξ± Ξ± where
elim _a ha _bβ _bβ hb := mul_lt_mul_of_pos_left hb ha
-- See note [lower instance priority]
instance (priority := 100) PosMulReflectLT.toPosSMulReflectLT [PosMulReflectLT Ξ±] :
PosSMulReflectLT Ξ± Ξ± where
elim _a ha _bβ _bβ h := lt_of_mul_lt_mul_left h ha
-- See note [lower instance priority]
instance (priority := 100) PosMulReflectLE.toPosSMulReflectLE [PosMulReflectLE Ξ±] :
PosSMulReflectLE Ξ± Ξ± where
elim _a ha _bβ _bβ h := le_of_mul_le_mul_left h ha
-- See note [lower instance priority]
instance (priority := 100) MulPosMono.toSMulPosMono [MulPosMono Ξ±] : SMulPosMono Ξ± Ξ± where
elim _b hb _aβ _aβ ha := mul_le_mul_of_nonneg_right ha hb
-- See note [lower instance priority]
instance (priority := 100) MulPosStrictMono.toSMulPosStrictMono [MulPosStrictMono Ξ±] :
SMulPosStrictMono Ξ± Ξ± where
elim _b hb _aβ _aβ ha := mul_lt_mul_of_pos_right ha hb
-- See note [lower instance priority]
instance (priority := 100) MulPosReflectLT.toSMulPosReflectLT [MulPosReflectLT Ξ±] :
SMulPosReflectLT Ξ± Ξ± where
elim _b hb _aβ _aβ h := lt_of_mul_lt_mul_right h hb
-- See note [lower instance priority]
instance (priority := 100) MulPosReflectLE.toSMulPosReflectLE [MulPosReflectLE Ξ±] :
SMulPosReflectLE Ξ± Ξ± where
elim _b hb _aβ _aβ h := le_of_mul_le_mul_right h hb
end Mul
section SMul
variable [SMul Ξ± Ξ²]
section Preorder
variable [Preorder Ξ±] [Preorder Ξ²]
section Left
variable [Zero Ξ±]
lemma monotone_smul_left_of_nonneg [PosSMulMono Ξ± Ξ²] (ha : 0 β€ a) : Monotone ((a β’ Β·) : Ξ² β Ξ²) :=
PosSMulMono.elim ha
lemma strictMono_smul_left_of_pos [PosSMulStrictMono Ξ± Ξ²] (ha : 0 < a) :
StrictMono ((a β’ Β·) : Ξ² β Ξ²) := PosSMulStrictMono.elim ha
@[gcongr] lemma smul_le_smul_of_nonneg_left [PosSMulMono Ξ± Ξ²] (hb : bβ β€ bβ) (ha : 0 β€ a) :
a β’ bβ β€ a β’ bβ := monotone_smul_left_of_nonneg ha hb
@[gcongr] lemma smul_lt_smul_of_pos_left [PosSMulStrictMono Ξ± Ξ²] (hb : bβ < bβ) (ha : 0 < a) :
a β’ bβ < a β’ bβ := strictMono_smul_left_of_pos ha hb
lemma lt_of_smul_lt_smul_left [PosSMulReflectLT Ξ± Ξ²] (h : a β’ bβ < a β’ bβ) (ha : 0 β€ a) : bβ < bβ :=
PosSMulReflectLT.elim ha h
lemma le_of_smul_le_smul_left [PosSMulReflectLE Ξ± Ξ²] (h : a β’ bβ β€ a β’ bβ) (ha : 0 < a) : bβ β€ bβ :=
PosSMulReflectLE.elim ha h
alias lt_of_smul_lt_smul_of_nonneg_left := lt_of_smul_lt_smul_left
alias le_of_smul_le_smul_of_pos_left := le_of_smul_le_smul_left
@[simp]
lemma smul_le_smul_iff_of_pos_left [PosSMulMono Ξ± Ξ²] [PosSMulReflectLE Ξ± Ξ²] (ha : 0 < a) :
a β’ bβ β€ a β’ bβ β bβ β€ bβ :=
β¨fun h β¦ le_of_smul_le_smul_left h ha, fun h β¦ smul_le_smul_of_nonneg_left h ha.leβ©
@[simp]
lemma smul_lt_smul_iff_of_pos_left [PosSMulStrictMono Ξ± Ξ²] [PosSMulReflectLT Ξ± Ξ²] (ha : 0 < a) :
a β’ bβ < a β’ bβ β bβ < bβ :=
β¨fun h β¦ lt_of_smul_lt_smul_left h ha.le, fun hb β¦ smul_lt_smul_of_pos_left hb haβ©
end Left
section Right
variable [Zero Ξ²]
lemma monotone_smul_right_of_nonneg [SMulPosMono Ξ± Ξ²] (hb : 0 β€ b) : Monotone ((Β· β’ b) : Ξ± β Ξ²) :=
SMulPosMono.elim hb
lemma strictMono_smul_right_of_pos [SMulPosStrictMono Ξ± Ξ²] (hb : 0 < b) :
StrictMono ((Β· β’ b) : Ξ± β Ξ²) := SMulPosStrictMono.elim hb
@[gcongr] lemma smul_le_smul_of_nonneg_right [SMulPosMono Ξ± Ξ²] (ha : aβ β€ aβ) (hb : 0 β€ b) :
aβ β’ b β€ aβ β’ b := monotone_smul_right_of_nonneg hb ha
@[gcongr] lemma smul_lt_smul_of_pos_right [SMulPosStrictMono Ξ± Ξ²] (ha : aβ < aβ) (hb : 0 < b) :
aβ β’ b < aβ β’ b := strictMono_smul_right_of_pos hb ha
lemma lt_of_smul_lt_smul_right [SMulPosReflectLT Ξ± Ξ²] (h : aβ β’ b < aβ β’ b) (hb : 0 β€ b) :
aβ < aβ := SMulPosReflectLT.elim hb h
lemma le_of_smul_le_smul_right [SMulPosReflectLE Ξ± Ξ²] (h : aβ β’ b β€ aβ β’ b) (hb : 0 < b) :
aβ β€ aβ := SMulPosReflectLE.elim hb h
alias lt_of_smul_lt_smul_of_nonneg_right := lt_of_smul_lt_smul_right
alias le_of_smul_le_smul_of_pos_right := le_of_smul_le_smul_right
@[simp]
lemma smul_le_smul_iff_of_pos_right [SMulPosMono Ξ± Ξ²] [SMulPosReflectLE Ξ± Ξ²] (hb : 0 < b) :
aβ β’ b β€ aβ β’ b β aβ β€ aβ :=
β¨fun h β¦ le_of_smul_le_smul_right h hb, fun ha β¦ smul_le_smul_of_nonneg_right ha hb.leβ©
@[simp]
lemma smul_lt_smul_iff_of_pos_right [SMulPosStrictMono Ξ± Ξ²] [SMulPosReflectLT Ξ± Ξ²] (hb : 0 < b) :
aβ β’ b < aβ β’ b β aβ < aβ :=
β¨fun h β¦ lt_of_smul_lt_smul_right h hb.le, fun ha β¦ smul_lt_smul_of_pos_right ha hbβ©
end Right
section LeftRight
variable [Zero Ξ±] [Zero Ξ²]
lemma smul_lt_smul_of_le_of_lt [PosSMulStrictMono Ξ± Ξ²] [SMulPosMono Ξ± Ξ²] (ha : aβ β€ aβ)
(hb : bβ < bβ) (hβ : 0 < aβ) (hβ : 0 β€ bβ) : aβ β’ bβ < aβ β’ bβ :=
(smul_lt_smul_of_pos_left hb hβ).trans_le (smul_le_smul_of_nonneg_right ha hβ)
lemma smul_lt_smul_of_le_of_lt' [PosSMulStrictMono Ξ± Ξ²] [SMulPosMono Ξ± Ξ²] (ha : aβ β€ aβ)
(hb : bβ < bβ) (hβ : 0 < aβ) (hβ : 0 β€ bβ) : aβ β’ bβ < aβ β’ bβ :=
(smul_le_smul_of_nonneg_right ha hβ).trans_lt (smul_lt_smul_of_pos_left hb hβ)
lemma smul_lt_smul_of_lt_of_le [PosSMulMono Ξ± Ξ²] [SMulPosStrictMono Ξ± Ξ²] (ha : aβ < aβ)
(hb : bβ β€ bβ) (hβ : 0 β€ aβ) (hβ : 0 < bβ) : aβ β’ bβ < aβ β’ bβ :=
(smul_le_smul_of_nonneg_left hb hβ).trans_lt (smul_lt_smul_of_pos_right ha hβ)
lemma smul_lt_smul_of_lt_of_le' [PosSMulMono Ξ± Ξ²] [SMulPosStrictMono Ξ± Ξ²] (ha : aβ < aβ)
(hb : bβ β€ bβ) (hβ : 0 β€ aβ) (hβ : 0 < bβ) : aβ β’ bβ < aβ β’ bβ :=
(smul_lt_smul_of_pos_right ha hβ).trans_le (smul_le_smul_of_nonneg_left hb hβ)
lemma smul_lt_smul [PosSMulStrictMono Ξ± Ξ²] [SMulPosStrictMono Ξ± Ξ²] (ha : aβ < aβ) (hb : bβ < bβ)
(hβ : 0 < aβ) (hβ : 0 < bβ) : aβ β’ bβ < aβ β’ bβ :=
(smul_lt_smul_of_pos_left hb hβ).trans (smul_lt_smul_of_pos_right ha hβ)
lemma smul_lt_smul' [PosSMulStrictMono Ξ± Ξ²] [SMulPosStrictMono Ξ± Ξ²] (ha : aβ < aβ) (hb : bβ < bβ)
(hβ : 0 < aβ) (hβ : 0 < bβ) : aβ β’ bβ < aβ β’ bβ :=
(smul_lt_smul_of_pos_right ha hβ).trans (smul_lt_smul_of_pos_left hb hβ)
lemma smul_le_smul [PosSMulMono Ξ± Ξ²] [SMulPosMono Ξ± Ξ²] (ha : aβ β€ aβ) (hb : bβ β€ bβ)
(hβ : 0 β€ aβ) (hβ : 0 β€ bβ) : aβ β’ bβ β€ aβ β’ bβ :=
(smul_le_smul_of_nonneg_left hb hβ).trans (smul_le_smul_of_nonneg_right ha hβ)
lemma smul_le_smul' [PosSMulMono Ξ± Ξ²] [SMulPosMono Ξ± Ξ²] (ha : aβ β€ aβ) (hb : bβ β€ bβ) (hβ : 0 β€ aβ)
(hβ : 0 β€ bβ) : aβ β’ bβ β€ aβ β’ bβ :=
(smul_le_smul_of_nonneg_right ha hβ).trans (smul_le_smul_of_nonneg_left hb hβ)
end LeftRight
end Preorder
section LinearOrder
variable [Preorder Ξ±] [LinearOrder Ξ²]
section Left
variable [Zero Ξ±]
-- See note [lower instance priority]
instance (priority := 100) PosSMulStrictMono.toPosSMulReflectLE [PosSMulStrictMono Ξ± Ξ²] :
PosSMulReflectLE Ξ± Ξ² where
elim _a ha _bβ _bβ := (strictMono_smul_left_of_pos ha).le_iff_le.1
lemma PosSMulReflectLE.toPosSMulStrictMono [PosSMulReflectLE Ξ± Ξ²] : PosSMulStrictMono Ξ± Ξ² where
elim _a ha _bβ _bβ hb := not_le.1 fun h β¦ hb.not_le <| le_of_smul_le_smul_left h ha
lemma posSMulStrictMono_iff_PosSMulReflectLE : PosSMulStrictMono Ξ± Ξ² β PosSMulReflectLE Ξ± Ξ² :=
β¨fun _ β¦ inferInstance, fun _ β¦ PosSMulReflectLE.toPosSMulStrictMonoβ©
instance PosSMulMono.toPosSMulReflectLT [PosSMulMono Ξ± Ξ²] : PosSMulReflectLT Ξ± Ξ² where
elim _a ha _bβ _bβ := (monotone_smul_left_of_nonneg ha).reflect_lt
lemma PosSMulReflectLT.toPosSMulMono [PosSMulReflectLT Ξ± Ξ²] : PosSMulMono Ξ± Ξ² where
elim _a ha _bβ _bβ hb := not_lt.1 fun h β¦ hb.not_lt <| lt_of_smul_lt_smul_left h ha
lemma posSMulMono_iff_posSMulReflectLT : PosSMulMono Ξ± Ξ² β PosSMulReflectLT Ξ± Ξ² :=
β¨fun _ β¦ PosSMulMono.toPosSMulReflectLT, fun _ β¦ PosSMulReflectLT.toPosSMulMonoβ©
lemma smul_max_of_nonneg [PosSMulMono Ξ± Ξ²] (ha : 0 β€ a) (bβ bβ : Ξ²) :
a β’ max bβ bβ = max (a β’ bβ) (a β’ bβ) := (monotone_smul_left_of_nonneg ha).map_max
lemma smul_min_of_nonneg [PosSMulMono Ξ± Ξ²] (ha : 0 β€ a) (bβ bβ : Ξ²) :
a β’ min bβ bβ = min (a β’ bβ) (a β’ bβ) := (monotone_smul_left_of_nonneg ha).map_min
end Left
section Right
variable [Zero Ξ²]
lemma SMulPosReflectLE.toSMulPosStrictMono [SMulPosReflectLE Ξ± Ξ²] : SMulPosStrictMono Ξ± Ξ² where
elim _b hb _aβ _aβ ha := not_le.1 fun h β¦ ha.not_le <| le_of_smul_le_smul_of_pos_right h hb
lemma SMulPosReflectLT.toSMulPosMono [SMulPosReflectLT Ξ± Ξ²] : SMulPosMono Ξ± Ξ² where
elim _b hb _aβ _aβ ha := not_lt.1 fun h β¦ ha.not_lt <| lt_of_smul_lt_smul_right h hb
end Right
end LinearOrder
section LinearOrder
variable [LinearOrder Ξ±] [Preorder Ξ²]
section Right
variable [Zero Ξ²]
-- See note [lower instance priority]
instance (priority := 100) SMulPosStrictMono.toSMulPosReflectLE [SMulPosStrictMono Ξ± Ξ²] :
SMulPosReflectLE Ξ± Ξ² where
elim _b hb _aβ _aβ h := not_lt.1 fun ha β¦ h.not_lt <| smul_lt_smul_of_pos_right ha hb
lemma SMulPosMono.toSMulPosReflectLT [SMulPosMono Ξ± Ξ²] : SMulPosReflectLT Ξ± Ξ² where
elim _b hb _aβ _aβ h := not_le.1 fun ha β¦ h.not_le <| smul_le_smul_of_nonneg_right ha hb
end Right
end LinearOrder
section LinearOrder
variable [LinearOrder Ξ±] [LinearOrder Ξ²]
section Right
variable [Zero Ξ²]
lemma smulPosStrictMono_iff_SMulPosReflectLE : SMulPosStrictMono Ξ± Ξ² β SMulPosReflectLE Ξ± Ξ² :=
β¨fun _ β¦ SMulPosStrictMono.toSMulPosReflectLE, fun _ β¦ SMulPosReflectLE.toSMulPosStrictMonoβ©
lemma smulPosMono_iff_smulPosReflectLT : SMulPosMono Ξ± Ξ² β SMulPosReflectLT Ξ± Ξ² :=
β¨fun _ β¦ SMulPosMono.toSMulPosReflectLT, fun _ β¦ SMulPosReflectLT.toSMulPosMonoβ©
end Right
end LinearOrder
end SMul
section SMulZeroClass
variable [Zero Ξ±] [Zero Ξ²] [SMulZeroClass Ξ± Ξ²]
section Preorder
variable [Preorder Ξ±] [Preorder Ξ²]
lemma smul_pos [PosSMulStrictMono Ξ± Ξ²] (ha : 0 < a) (hb : 0 < b) : 0 < a β’ b := by
simpa only [smul_zero] using smul_lt_smul_of_pos_left hb ha
lemma smul_neg_of_pos_of_neg [PosSMulStrictMono Ξ± Ξ²] (ha : 0 < a) (hb : b < 0) : a β’ b < 0 := by
simpa only [smul_zero] using smul_lt_smul_of_pos_left hb ha
@[simp]
lemma smul_pos_iff_of_pos_left [PosSMulStrictMono Ξ± Ξ²] [PosSMulReflectLT Ξ± Ξ²] (ha : 0 < a) :
0 < a β’ b β 0 < b := by
simpa only [smul_zero] using smul_lt_smul_iff_of_pos_left ha (bβ := 0) (bβ := b)
lemma smul_neg_iff_of_pos_left [PosSMulStrictMono Ξ± Ξ²] [PosSMulReflectLT Ξ± Ξ²] (ha : 0 < a) :
a β’ b < 0 β b < 0 := by
simpa only [smul_zero] using smul_lt_smul_iff_of_pos_left ha (bβ := (0 : Ξ²))
lemma smul_nonneg [PosSMulMono Ξ± Ξ²] (ha : 0 β€ a) (hb : 0 β€ bβ) : 0 β€ a β’ bβ := by
simpa only [smul_zero] using smul_le_smul_of_nonneg_left hb ha
lemma smul_nonpos_of_nonneg_of_nonpos [PosSMulMono Ξ± Ξ²] (ha : 0 β€ a) (hb : b β€ 0) : a β’ b β€ 0 := by
simpa only [smul_zero] using smul_le_smul_of_nonneg_left hb ha
lemma pos_of_smul_pos_left [PosSMulReflectLT Ξ± Ξ²] (h : 0 < a β’ b) (ha : 0 β€ a) : 0 < b :=
lt_of_smul_lt_smul_left (by rwa [smul_zero]) ha
lemma neg_of_smul_neg_left [PosSMulReflectLT Ξ± Ξ²] (h : a β’ b < 0) (ha : 0 β€ a) : b < 0 :=
lt_of_smul_lt_smul_left (by rwa [smul_zero]) ha
end Preorder
end SMulZeroClass
section SMulWithZero
variable [Zero Ξ±] [Zero Ξ²] [SMulWithZero Ξ± Ξ²]
section Preorder
variable [Preorder Ξ±] [Preorder Ξ²]
lemma smul_pos' [SMulPosStrictMono Ξ± Ξ²] (ha : 0 < a) (hb : 0 < b) : 0 < a β’ b := by
simpa only [zero_smul] using smul_lt_smul_of_pos_right ha hb
lemma smul_neg_of_neg_of_pos [SMulPosStrictMono Ξ± Ξ²] (ha : a < 0) (hb : 0 < b) : a β’ b < 0 := by
simpa only [zero_smul] using smul_lt_smul_of_pos_right ha hb
@[simp]
lemma smul_pos_iff_of_pos_right [SMulPosStrictMono Ξ± Ξ²] [SMulPosReflectLT Ξ± Ξ²] (hb : 0 < b) :
0 < a β’ b β 0 < a := by
simpa only [zero_smul] using smul_lt_smul_iff_of_pos_right hb (aβ := 0) (aβ := a)
lemma smul_nonneg' [SMulPosMono Ξ± Ξ²] (ha : 0 β€ a) (hb : 0 β€ bβ) : 0 β€ a β’ bβ := by
simpa only [zero_smul] using smul_le_smul_of_nonneg_right ha hb
lemma smul_nonpos_of_nonpos_of_nonneg [SMulPosMono Ξ± Ξ²] (ha : a β€ 0) (hb : 0 β€ b) : a β’ b β€ 0 := by
simpa only [zero_smul] using smul_le_smul_of_nonneg_right ha hb
lemma pos_of_smul_pos_right [SMulPosReflectLT Ξ± Ξ²] (h : 0 < a β’ b) (hb : 0 β€ b) : 0 < a :=
lt_of_smul_lt_smul_right (by rwa [zero_smul]) hb
lemma neg_of_smul_neg_right [SMulPosReflectLT Ξ± Ξ²] (h : a β’ b < 0) (hb : 0 β€ b) : a < 0 :=
lt_of_smul_lt_smul_right (by rwa [zero_smul]) hb
lemma pos_iff_pos_of_smul_pos [PosSMulReflectLT Ξ± Ξ²] [SMulPosReflectLT Ξ± Ξ²] (hab : 0 < a β’ b) :
0 < a β 0 < b :=
β¨pos_of_smul_pos_left hab β le_of_lt, pos_of_smul_pos_right hab β le_of_ltβ©
end Preorder
section PartialOrder
variable [PartialOrder Ξ±] [Preorder Ξ²]
/-- A constructor for `PosSMulMono` requiring you to prove `bβ β€ bβ β a β’ bβ β€ a β’ bβ` only when
`0 < a` -/
lemma PosSMulMono.of_pos (hβ : β a : Ξ±, 0 < a β β bβ bβ : Ξ², bβ β€ bβ β a β’ bβ β€ a β’ bβ) :
PosSMulMono Ξ± Ξ² where
elim a ha bβ bβ h := by
obtain ha | ha := ha.eq_or_lt
Β· simp [β ha]
Β· exact hβ _ ha _ _ h
/-- A constructor for `PosSMulReflectLT` requiring you to prove `a β’ bβ < a β’ bβ β bβ < bβ` only
when `0 < a` -/
lemma PosSMulReflectLT.of_pos (hβ : β a : Ξ±, 0 < a β β bβ bβ : Ξ², a β’ bβ < a β’ bβ β bβ < bβ) :
PosSMulReflectLT Ξ± Ξ² where
elim a ha bβ bβ h := by
obtain ha | ha := ha.eq_or_lt
Β· simp [β ha] at h
Β· exact hβ _ ha _ _ h
end PartialOrder
section PartialOrder
variable [Preorder Ξ±] [PartialOrder Ξ²]
/-- A constructor for `SMulPosMono` requiring you to prove `aβ β€ aβ β aβ β’ b β€ aβ β’ b` only when
`0 < b` -/
lemma SMulPosMono.of_pos (hβ : β b : Ξ², 0 < b β β aβ aβ : Ξ±, aβ β€ aβ β aβ β’ b β€ aβ β’ b) :
SMulPosMono Ξ± Ξ² where
elim b hb aβ aβ h := by
obtain hb | hb := hb.eq_or_lt
Β· simp [β hb]
Β· exact hβ _ hb _ _ h
/-- A constructor for `SMulPosReflectLT` requiring you to prove `aβ β’ b < aβ β’ b β aβ < aβ` only
when `0 < b` -/
lemma SMulPosReflectLT.of_pos (hβ : β b : Ξ², 0 < b β β aβ aβ : Ξ±, aβ β’ b < aβ β’ b β aβ < aβ) :
SMulPosReflectLT Ξ± Ξ² where
elim b hb aβ aβ h := by
obtain hb | hb := hb.eq_or_lt
Β· simp [β hb] at h
Β· exact hβ _ hb _ _ h
end PartialOrder
section PartialOrder
variable [PartialOrder Ξ±] [PartialOrder Ξ²]
-- See note [lower instance priority]
instance (priority := 100) PosSMulStrictMono.toPosSMulMono [PosSMulStrictMono Ξ± Ξ²] :
PosSMulMono Ξ± Ξ² :=
PosSMulMono.of_pos fun _a ha β¦ (strictMono_smul_left_of_pos ha).monotone
-- See note [lower instance priority]
instance (priority := 100) SMulPosStrictMono.toSMulPosMono [SMulPosStrictMono Ξ± Ξ²] :
SMulPosMono Ξ± Ξ² :=
SMulPosMono.of_pos fun _b hb β¦ (strictMono_smul_right_of_pos hb).monotone
-- See note [lower instance priority]
instance (priority := 100) PosSMulReflectLE.toPosSMulReflectLT [PosSMulReflectLE Ξ± Ξ²] :
PosSMulReflectLT Ξ± Ξ² :=
PosSMulReflectLT.of_pos fun a ha bβ bβ h β¦
(le_of_smul_le_smul_of_pos_left h.le ha).lt_of_ne <| by rintro rfl; simp at h
-- See note [lower instance priority]
instance (priority := 100) SMulPosReflectLE.toSMulPosReflectLT [SMulPosReflectLE Ξ± Ξ²] :
SMulPosReflectLT Ξ± Ξ² :=
SMulPosReflectLT.of_pos fun b hb aβ aβ h β¦
(le_of_smul_le_smul_of_pos_right h.le hb).lt_of_ne <| by rintro rfl; simp at h
lemma smul_eq_smul_iff_eq_and_eq_of_pos [PosSMulStrictMono Ξ± Ξ²] [SMulPosStrictMono Ξ± Ξ²]
(ha : aβ β€ aβ) (hb : bβ β€ bβ) (hβ : 0 < aβ) (hβ : 0 < bβ) :
aβ β’ bβ = aβ β’ bβ β aβ = aβ β§ bβ = bβ := by
refine β¨fun h β¦ ?_, by rintro β¨rfl, rflβ©; rflβ©
simp only [eq_iff_le_not_lt, ha, hb, true_and]
refine β¨fun ha β¦ h.not_lt ?_, fun hb β¦ h.not_lt ?_β©
Β· exact (smul_le_smul_of_nonneg_left hb hβ.le).trans_lt (smul_lt_smul_of_pos_right ha hβ)
Β· exact (smul_lt_smul_of_pos_left hb hβ).trans_le (smul_le_smul_of_nonneg_right ha hβ.le)
lemma smul_eq_smul_iff_eq_and_eq_of_pos' [PosSMulStrictMono Ξ± Ξ²] [SMulPosStrictMono Ξ± Ξ²]
(ha : aβ β€ aβ) (hb : bβ β€ bβ) (hβ : 0 < aβ) (hβ : 0 < bβ) :
aβ β’ bβ = aβ β’ bβ β aβ = aβ β§ bβ = bβ := by
refine β¨fun h β¦ ?_, by rintro β¨rfl, rflβ©; rflβ©
simp only [eq_iff_le_not_lt, ha, hb, true_and]
refine β¨fun ha β¦ h.not_lt ?_, fun hb β¦ h.not_lt ?_β©
Β· exact (smul_lt_smul_of_pos_right ha hβ).trans_le (smul_le_smul_of_nonneg_left hb hβ.le)
Β· exact (smul_le_smul_of_nonneg_right ha hβ.le).trans_lt (smul_lt_smul_of_pos_left hb hβ)
end PartialOrder
section LinearOrder
variable [LinearOrder Ξ±] [LinearOrder Ξ²]
lemma pos_and_pos_or_neg_and_neg_of_smul_pos [PosSMulMono Ξ± Ξ²] [SMulPosMono Ξ± Ξ²] (hab : 0 < a β’ b) :
0 < a β§ 0 < b β¨ a < 0 β§ b < 0 := by
obtain ha | rfl | ha := lt_trichotomy a 0
Β· refine Or.inr β¨ha, lt_imp_lt_of_le_imp_le (fun hb β¦ ?_) habβ©
exact smul_nonpos_of_nonpos_of_nonneg ha.le hb
Β· rw [zero_smul] at hab
exact hab.false.elim
Β· refine Or.inl β¨ha, lt_imp_lt_of_le_imp_le (fun hb β¦ ?_) habβ©
exact smul_nonpos_of_nonneg_of_nonpos ha.le hb
lemma neg_of_smul_pos_right [PosSMulMono Ξ± Ξ²] [SMulPosMono Ξ± Ξ²] (h : 0 < a β’ b) (ha : a β€ 0) :
b < 0 := ((pos_and_pos_or_neg_and_neg_of_smul_pos h).resolve_left fun h β¦ h.1.not_le ha).2
lemma neg_of_smul_pos_left [PosSMulMono Ξ± Ξ²] [SMulPosMono Ξ± Ξ²] (h : 0 < a β’ b) (ha : b β€ 0) :
a < 0 := ((pos_and_pos_or_neg_and_neg_of_smul_pos h).resolve_left fun h β¦ h.2.not_le ha).1
lemma neg_iff_neg_of_smul_pos [PosSMulMono Ξ± Ξ²] [SMulPosMono Ξ± Ξ²] (hab : 0 < a β’ b) :
a < 0 β b < 0 :=
β¨neg_of_smul_pos_right hab β le_of_lt, neg_of_smul_pos_left hab β le_of_ltβ©
lemma neg_of_smul_neg_left' [SMulPosMono Ξ± Ξ²] (h : a β’ b < 0) (ha : 0 β€ a) : b < 0 :=
lt_of_not_ge fun hb β¦ (smul_nonneg' ha hb).not_lt h
lemma neg_of_smul_neg_right' [PosSMulMono Ξ± Ξ²] (h : a β’ b < 0) (hb : 0 β€ b) : a < 0 :=
lt_of_not_ge fun ha β¦ (smul_nonneg ha hb).not_lt h
end LinearOrder
end SMulWithZero
section MulAction
variable [Monoid Ξ±] [Zero Ξ²] [MulAction Ξ± Ξ²]
section Preorder
variable [Preorder Ξ±] [Preorder Ξ²]
@[simp]
lemma le_smul_iff_one_le_left [SMulPosMono Ξ± Ξ²] [SMulPosReflectLE Ξ± Ξ²] (hb : 0 < b) :
b β€ a β’ b β 1 β€ a := Iff.trans (by rw [one_smul]) (smul_le_smul_iff_of_pos_right hb)
@[simp]
lemma lt_smul_iff_one_lt_left [SMulPosStrictMono Ξ± Ξ²] [SMulPosReflectLT Ξ± Ξ²] (hb : 0 < b) :
b < a β’ b β 1 < a := Iff.trans (by rw [one_smul]) (smul_lt_smul_iff_of_pos_right hb)
@[simp]
lemma smul_le_iff_le_one_left [SMulPosMono Ξ± Ξ²] [SMulPosReflectLE Ξ± Ξ²] (hb : 0 < b) :
a β’ b β€ b β a β€ 1 := Iff.trans (by rw [one_smul]) (smul_le_smul_iff_of_pos_right hb)
@[simp]
lemma smul_lt_iff_lt_one_left [SMulPosStrictMono Ξ± Ξ²] [SMulPosReflectLT Ξ± Ξ²] (hb : 0 < b) :
a β’ b < b β a < 1 := Iff.trans (by rw [one_smul]) (smul_lt_smul_iff_of_pos_right hb)
lemma smul_le_of_le_one_left [SMulPosMono Ξ± Ξ²] (hb : 0 β€ b) (h : a β€ 1) : a β’ b β€ b := by
simpa only [one_smul] using smul_le_smul_of_nonneg_right h hb
lemma le_smul_of_one_le_left [SMulPosMono Ξ± Ξ²] (hb : 0 β€ b) (h : 1 β€ a) : b β€ a β’ b := by
simpa only [one_smul] using smul_le_smul_of_nonneg_right h hb
lemma smul_lt_of_lt_one_left [SMulPosStrictMono Ξ± Ξ²] (hb : 0 < b) (h : a < 1) : a β’ b < b := by
simpa only [one_smul] using smul_lt_smul_of_pos_right h hb
lemma lt_smul_of_one_lt_left [SMulPosStrictMono Ξ± Ξ²] (hb : 0 < b) (h : 1 < a) : b < a β’ b := by
| simpa only [one_smul] using smul_lt_smul_of_pos_right h hb
end Preorder
| Mathlib/Algebra/Order/Module/Defs.lean | 676 | 678 |
/-
Copyright (c) 2015 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura, Jeremy Avigad, Minchao Wu, Mario Carneiro
-/
import Mathlib.Data.Finset.Attach
import Mathlib.Data.Finset.Disjoint
import Mathlib.Data.Finset.Erase
import Mathlib.Data.Finset.Filter
import Mathlib.Data.Finset.Range
import Mathlib.Data.Finset.SDiff
import Mathlib.Data.Multiset.Basic
import Mathlib.Logic.Equiv.Set
import Mathlib.Order.Directed
import Mathlib.Order.Interval.Set.Defs
import Mathlib.Data.Set.SymmDiff
/-!
# Basic lemmas on finite sets
This file contains lemmas on the interaction of various definitions on the `Finset` type.
For an explanation of `Finset` design decisions, please see `Mathlib/Data/Finset/Defs.lean`.
## Main declarations
### Main definitions
* `Finset.choose`: Given a proof `h` of existence and uniqueness of a certain element
satisfying a predicate, `choose s h` returns the element of `s` satisfying that predicate.
### Equivalences between finsets
* The `Mathlib/Logic/Equiv/Defs.lean` file describes a general type of equivalence, so look in there
for any lemmas. There is some API for rewriting sums and products from `s` to `t` given that
`s β t`.
TODO: examples
## Tags
finite sets, finset
-/
-- Assert that we define `Finset` without the material on `List.sublists`.
-- Note that we cannot use `List.sublists` itself as that is defined very early.
assert_not_exists List.sublistsLen Multiset.powerset CompleteLattice Monoid
open Multiset Subtype Function
universe u
variable {Ξ± : Type*} {Ξ² : Type*} {Ξ³ : Type*}
namespace Finset
-- TODO: these should be global attributes, but this will require fixing other files
attribute [local trans] Subset.trans Superset.trans
set_option linter.deprecated false in
@[deprecated "Deprecated without replacement." (since := "2025-02-07")]
theorem sizeOf_lt_sizeOf_of_mem [SizeOf Ξ±] {x : Ξ±} {s : Finset Ξ±} (hx : x β s) :
SizeOf.sizeOf x < SizeOf.sizeOf s := by
cases s
dsimp [SizeOf.sizeOf, SizeOf.sizeOf, Multiset.sizeOf]
rw [Nat.add_comm]
refine lt_trans ?_ (Nat.lt_succ_self _)
exact Multiset.sizeOf_lt_sizeOf_of_mem hx
/-! ### Lattice structure -/
section Lattice
variable [DecidableEq Ξ±] {s sβ sβ t tβ tβ u v : Finset Ξ±} {a b : Ξ±}
/-! #### union -/
@[simp]
theorem disjUnion_eq_union (s t h) : @disjUnion Ξ± s t h = s βͺ t :=
ext fun a => by simp
@[simp]
theorem disjoint_union_left : Disjoint (s βͺ t) u β Disjoint s u β§ Disjoint t u := by
simp only [disjoint_left, mem_union, or_imp, forall_and]
@[simp]
theorem disjoint_union_right : Disjoint s (t βͺ u) β Disjoint s t β§ Disjoint s u := by
simp only [disjoint_right, mem_union, or_imp, forall_and]
/-! #### inter -/
theorem not_disjoint_iff_nonempty_inter : Β¬Disjoint s t β (s β© t).Nonempty :=
not_disjoint_iff.trans <| by simp [Finset.Nonempty]
alias β¨_, Nonempty.not_disjointβ© := not_disjoint_iff_nonempty_inter
theorem disjoint_or_nonempty_inter (s t : Finset Ξ±) : Disjoint s t β¨ (s β© t).Nonempty := by
rw [β not_disjoint_iff_nonempty_inter]
exact em _
omit [DecidableEq Ξ±] in
theorem disjoint_of_subset_iff_left_eq_empty (h : s β t) :
Disjoint s t β s = β
:=
disjoint_of_le_iff_left_eq_bot h
lemma pairwiseDisjoint_iff {ΞΉ : Type*} {s : Set ΞΉ} {f : ΞΉ β Finset Ξ±} :
s.PairwiseDisjoint f β β β¦iβ¦, i β s β β β¦jβ¦, j β s β (f i β© f j).Nonempty β i = j := by
simp [Set.PairwiseDisjoint, Set.Pairwise, Function.onFun, not_imp_comm (a := _ = _),
not_disjoint_iff_nonempty_inter]
end Lattice
instance isDirected_le : IsDirected (Finset Ξ±) (Β· β€ Β·) := by classical infer_instance
instance isDirected_subset : IsDirected (Finset Ξ±) (Β· β Β·) := isDirected_le
/-! ### erase -/
section Erase
variable [DecidableEq Ξ±] {s t u v : Finset Ξ±} {a b : Ξ±}
@[simp]
theorem erase_empty (a : Ξ±) : erase β
a = β
:=
rfl
protected lemma Nontrivial.erase_nonempty (hs : s.Nontrivial) : (s.erase a).Nonempty :=
(hs.exists_ne a).imp <| by aesop
@[simp] lemma erase_nonempty (ha : a β s) : (s.erase a).Nonempty β s.Nontrivial := by
simp only [Finset.Nonempty, mem_erase, and_comm (b := _ β _)]
refine β¨?_, fun hs β¦ hs.exists_ne aβ©
rintro β¨b, hb, hbaβ©
exact β¨_, hb, _, ha, hbaβ©
@[simp]
theorem erase_singleton (a : Ξ±) : ({a} : Finset Ξ±).erase a = β
:= by
ext x
simp
@[simp]
theorem erase_insert_eq_erase (s : Finset Ξ±) (a : Ξ±) : (insert a s).erase a = s.erase a :=
ext fun x => by
simp +contextual only [mem_erase, mem_insert, and_congr_right_iff,
false_or, iff_self, imp_true_iff]
theorem erase_insert {a : Ξ±} {s : Finset Ξ±} (h : a β s) : erase (insert a s) a = s := by
rw [erase_insert_eq_erase, erase_eq_of_not_mem h]
theorem erase_insert_of_ne {a b : Ξ±} {s : Finset Ξ±} (h : a β b) :
erase (insert a s) b = insert a (erase s b) :=
ext fun x => by
have : x β b β§ x = a β x = a := and_iff_right_of_imp fun hx => hx.symm βΈ h
simp only [mem_erase, mem_insert, and_or_left, this]
theorem erase_cons_of_ne {a b : Ξ±} {s : Finset Ξ±} (ha : a β s) (hb : a β b) :
erase (cons a s ha) b = cons a (erase s b) fun h => ha <| erase_subset _ _ h := by
simp only [cons_eq_insert, erase_insert_of_ne hb]
@[simp] theorem insert_erase (h : a β s) : insert a (erase s a) = s :=
ext fun x => by
simp only [mem_insert, mem_erase, or_and_left, dec_em, true_and]
apply or_iff_right_of_imp
rintro rfl
exact h
lemma erase_eq_iff_eq_insert (hs : a β s) (ht : a β t) : erase s a = t β s = insert a t := by
aesop
lemma insert_erase_invOn :
Set.InvOn (insert a) (fun s β¦ erase s a) {s : Finset Ξ± | a β s} {s : Finset Ξ± | a β s} :=
β¨fun _s β¦ insert_erase, fun _s β¦ erase_insertβ©
theorem erase_ssubset {a : Ξ±} {s : Finset Ξ±} (h : a β s) : s.erase a β s :=
calc
s.erase a β insert a (s.erase a) := ssubset_insert <| not_mem_erase _ _
_ = _ := insert_erase h
theorem ssubset_iff_exists_subset_erase {s t : Finset Ξ±} : s β t β β a β t, s β t.erase a := by
refine β¨fun h => ?_, fun β¨a, ha, hβ© => ssubset_of_subset_of_ssubset h <| erase_ssubset haβ©
obtain β¨a, ht, hsβ© := not_subset.1 h.2
exact β¨a, ht, subset_erase.2 β¨h.1, hsβ©β©
theorem erase_ssubset_insert (s : Finset Ξ±) (a : Ξ±) : s.erase a β insert a s :=
ssubset_iff_exists_subset_erase.2
β¨a, mem_insert_self _ _, erase_subset_erase _ <| subset_insert _ _β©
theorem erase_cons {s : Finset Ξ±} {a : Ξ±} (h : a β s) : (s.cons a h).erase a = s := by
rw [cons_eq_insert, erase_insert_eq_erase, erase_eq_of_not_mem h]
theorem subset_insert_iff {a : Ξ±} {s t : Finset Ξ±} : s β insert a t β erase s a β t := by
simp only [subset_iff, or_iff_not_imp_left, mem_erase, mem_insert, and_imp]
exact forall_congr' fun x => forall_swap
theorem erase_insert_subset (a : Ξ±) (s : Finset Ξ±) : erase (insert a s) a β s :=
subset_insert_iff.1 <| Subset.rfl
theorem insert_erase_subset (a : Ξ±) (s : Finset Ξ±) : s β insert a (erase s a) :=
subset_insert_iff.2 <| Subset.rfl
theorem subset_insert_iff_of_not_mem (h : a β s) : s β insert a t β s β t := by
rw [subset_insert_iff, erase_eq_of_not_mem h]
theorem erase_subset_iff_of_mem (h : a β t) : s.erase a β t β s β t := by
rw [β subset_insert_iff, insert_eq_of_mem h]
theorem erase_injOn' (a : Ξ±) : { s : Finset Ξ± | a β s }.InjOn fun s => erase s a :=
fun s hs t ht (h : s.erase a = _) => by rw [β insert_erase hs, β insert_erase ht, h]
end Erase
lemma Nontrivial.exists_cons_eq {s : Finset Ξ±} (hs : s.Nontrivial) :
β t a ha b hb hab, (cons b t hb).cons a (mem_cons.not.2 <| not_or_intro hab ha) = s := by
classical
obtain β¨a, ha, b, hb, habβ© := hs
have : b β s.erase a := mem_erase.2 β¨hab.symm, hbβ©
refine β¨(s.erase a).erase b, a, ?_, b, ?_, ?_, ?_β© <;>
simp [insert_erase this, insert_erase ha, *]
/-! ### sdiff -/
section Sdiff
variable [DecidableEq Ξ±] {s t u v : Finset Ξ±} {a b : Ξ±}
lemma erase_sdiff_erase (hab : a β b) (hb : b β s) : s.erase a \ s.erase b = {b} := by
ext; aesop
-- TODO: Do we want to delete this lemma and `Finset.disjUnion_singleton`,
-- or instead add `Finset.union_singleton`/`Finset.singleton_union`?
theorem sdiff_singleton_eq_erase (a : Ξ±) (s : Finset Ξ±) : s \ {a} = erase s a := by
ext
rw [mem_erase, mem_sdiff, mem_singleton, and_comm]
-- This lemma matches `Finset.insert_eq` in functionality.
theorem erase_eq (s : Finset Ξ±) (a : Ξ±) : s.erase a = s \ {a} :=
(sdiff_singleton_eq_erase _ _).symm
theorem disjoint_erase_comm : Disjoint (s.erase a) t β Disjoint s (t.erase a) := by
simp_rw [erase_eq, disjoint_sdiff_comm]
lemma disjoint_insert_erase (ha : a β t) : Disjoint (s.erase a) (insert a t) β Disjoint s t := by
rw [disjoint_erase_comm, erase_insert ha]
lemma disjoint_erase_insert (ha : a β s) : Disjoint (insert a s) (t.erase a) β Disjoint s t := by
rw [β disjoint_erase_comm, erase_insert ha]
theorem disjoint_of_erase_left (ha : a β t) (hst : Disjoint (s.erase a) t) : Disjoint s t := by
rw [β erase_insert ha, β disjoint_erase_comm, disjoint_insert_right]
exact β¨not_mem_erase _ _, hstβ©
theorem disjoint_of_erase_right (ha : a β s) (hst : Disjoint s (t.erase a)) : Disjoint s t := by
rw [β erase_insert ha, disjoint_erase_comm, disjoint_insert_left]
exact β¨not_mem_erase _ _, hstβ©
theorem inter_erase (a : Ξ±) (s t : Finset Ξ±) : s β© t.erase a = (s β© t).erase a := by
simp only [erase_eq, inter_sdiff_assoc]
@[simp]
theorem erase_inter (a : Ξ±) (s t : Finset Ξ±) : s.erase a β© t = (s β© t).erase a := by
simpa only [inter_comm t] using inter_erase a t s
theorem erase_sdiff_comm (s t : Finset Ξ±) (a : Ξ±) : s.erase a \ t = (s \ t).erase a := by
simp_rw [erase_eq, sdiff_right_comm]
theorem erase_inter_comm (s t : Finset Ξ±) (a : Ξ±) : s.erase a β© t = s β© t.erase a := by
rw [erase_inter, inter_erase]
theorem erase_union_distrib (s t : Finset Ξ±) (a : Ξ±) : (s βͺ t).erase a = s.erase a βͺ t.erase a := by
simp_rw [erase_eq, union_sdiff_distrib]
theorem insert_inter_distrib (s t : Finset Ξ±) (a : Ξ±) :
insert a (s β© t) = insert a s β© insert a t := by simp_rw [insert_eq, union_inter_distrib_left]
theorem erase_sdiff_distrib (s t : Finset Ξ±) (a : Ξ±) : (s \ t).erase a = s.erase a \ t.erase a := by
simp_rw [erase_eq, sdiff_sdiff, sup_sdiff_eq_sup le_rfl, sup_comm]
theorem erase_union_of_mem (ha : a β t) (s : Finset Ξ±) : s.erase a βͺ t = s βͺ t := by
rw [β insert_erase (mem_union_right s ha), erase_union_distrib, β union_insert, insert_erase ha]
theorem union_erase_of_mem (ha : a β s) (t : Finset Ξ±) : s βͺ t.erase a = s βͺ t := by
rw [β insert_erase (mem_union_left t ha), erase_union_distrib, β insert_union, insert_erase ha]
theorem sdiff_union_erase_cancel (hts : t β s) (ha : a β t) : s \ t βͺ t.erase a = s.erase a := by
simp_rw [erase_eq, sdiff_union_sdiff_cancel hts (singleton_subset_iff.2 ha)]
theorem sdiff_insert (s t : Finset Ξ±) (x : Ξ±) : s \ insert x t = (s \ t).erase x := by
simp_rw [β sdiff_singleton_eq_erase, insert_eq, sdiff_sdiff_left', sdiff_union_distrib,
inter_comm]
theorem sdiff_insert_insert_of_mem_of_not_mem {s t : Finset Ξ±} {x : Ξ±} (hxs : x β s) (hxt : x β t) :
insert x (s \ insert x t) = s \ t := by
rw [sdiff_insert, insert_erase (mem_sdiff.mpr β¨hxs, hxtβ©)]
theorem sdiff_erase (h : a β s) : s \ t.erase a = insert a (s \ t) := by
rw [β sdiff_singleton_eq_erase, sdiff_sdiff_eq_sdiff_union (singleton_subset_iff.2 h), insert_eq,
union_comm]
theorem sdiff_erase_self (ha : a β s) : s \ s.erase a = {a} := by
rw [sdiff_erase ha, Finset.sdiff_self, insert_empty_eq]
theorem erase_eq_empty_iff (s : Finset Ξ±) (a : Ξ±) : s.erase a = β
β s = β
β¨ s = {a} := by
rw [β sdiff_singleton_eq_erase, sdiff_eq_empty_iff_subset, subset_singleton_iff]
--TODO@YaΓ«l: Kill lemmas duplicate with `BooleanAlgebra`
theorem sdiff_disjoint : Disjoint (t \ s) s :=
disjoint_left.2 fun _a ha => (mem_sdiff.1 ha).2
theorem disjoint_sdiff : Disjoint s (t \ s) :=
sdiff_disjoint.symm
theorem disjoint_sdiff_inter (s t : Finset Ξ±) : Disjoint (s \ t) (s β© t) :=
disjoint_of_subset_right inter_subset_right sdiff_disjoint
end Sdiff
/-! ### attach -/
@[simp]
theorem attach_empty : attach (β
: Finset Ξ±) = β
:=
rfl
@[simp]
theorem attach_nonempty_iff {s : Finset Ξ±} : s.attach.Nonempty β s.Nonempty := by
simp [Finset.Nonempty]
@[aesop safe apply (rule_sets := [finsetNonempty])]
protected alias β¨_, Nonempty.attachβ© := attach_nonempty_iff
@[simp]
theorem attach_eq_empty_iff {s : Finset Ξ±} : s.attach = β
β s = β
:= by
simp [eq_empty_iff_forall_not_mem]
/-! ### filter -/
section Filter
variable (p q : Ξ± β Prop) [DecidablePred p] [DecidablePred q] {s t : Finset Ξ±}
theorem filter_singleton (a : Ξ±) : filter p {a} = if p a then {a} else β
:= by
classical
ext x
simp only [mem_singleton, forall_eq, mem_filter]
split_ifs with h <;> by_cases h' : x = a <;> simp [h, h']
theorem filter_cons_of_pos (a : Ξ±) (s : Finset Ξ±) (ha : a β s) (hp : p a) :
filter p (cons a s ha) = cons a (filter p s) ((mem_of_mem_filter _).mt ha) :=
eq_of_veq <| Multiset.filter_cons_of_pos s.val hp
theorem filter_cons_of_neg (a : Ξ±) (s : Finset Ξ±) (ha : a β s) (hp : Β¬p a) :
filter p (cons a s ha) = filter p s :=
eq_of_veq <| Multiset.filter_cons_of_neg s.val hp
theorem disjoint_filter {s : Finset Ξ±} {p q : Ξ± β Prop} [DecidablePred p] [DecidablePred q] :
Disjoint (s.filter p) (s.filter q) β β x β s, p x β Β¬q x := by
constructor <;> simp +contextual [disjoint_left]
theorem disjoint_filter_filter' (s t : Finset Ξ±)
{p q : Ξ± β Prop} [DecidablePred p] [DecidablePred q] (h : Disjoint p q) :
Disjoint (s.filter p) (t.filter q) := by
simp_rw [disjoint_left, mem_filter]
rintro a β¨_, hpβ© β¨_, hqβ©
rw [Pi.disjoint_iff] at h
simpa [hp, hq] using h a
theorem disjoint_filter_filter_neg (s t : Finset Ξ±) (p : Ξ± β Prop)
[DecidablePred p] [β x, Decidable (Β¬p x)] :
Disjoint (s.filter p) (t.filter fun a => Β¬p a) :=
disjoint_filter_filter' s t disjoint_compl_right
theorem filter_disj_union (s : Finset Ξ±) (t : Finset Ξ±) (h : Disjoint s t) :
filter p (disjUnion s t h) = (filter p s).disjUnion (filter p t) (disjoint_filter_filter h) :=
eq_of_veq <| Multiset.filter_add _ _ _
theorem filter_cons {a : Ξ±} (s : Finset Ξ±) (ha : a β s) :
filter p (cons a s ha) =
if p a then cons a (filter p s) ((mem_of_mem_filter _).mt ha) else filter p s := by
split_ifs with h
Β· rw [filter_cons_of_pos _ _ _ ha h]
Β· rw [filter_cons_of_neg _ _ _ ha h]
section
variable [DecidableEq Ξ±]
theorem filter_union (sβ sβ : Finset Ξ±) : (sβ βͺ sβ).filter p = sβ.filter p βͺ sβ.filter p :=
ext fun _ => by simp only [mem_filter, mem_union, or_and_right]
theorem filter_union_right (s : Finset Ξ±) : s.filter p βͺ s.filter q = s.filter fun x => p x β¨ q x :=
ext fun x => by simp [mem_filter, mem_union, β and_or_left]
theorem filter_mem_eq_inter {s t : Finset Ξ±} [β i, Decidable (i β t)] :
(s.filter fun i => i β t) = s β© t :=
ext fun i => by simp [mem_filter, mem_inter]
theorem filter_inter_distrib (s t : Finset Ξ±) : (s β© t).filter p = s.filter p β© t.filter p := by
ext
simp [mem_filter, mem_inter, and_assoc]
theorem filter_inter (s t : Finset Ξ±) : filter p s β© t = filter p (s β© t) := by
ext
simp only [mem_inter, mem_filter, and_right_comm]
theorem inter_filter (s t : Finset Ξ±) : s β© filter p t = filter p (s β© t) := by
rw [inter_comm, filter_inter, inter_comm]
theorem filter_insert (a : Ξ±) (s : Finset Ξ±) :
filter p (insert a s) = if p a then insert a (filter p s) else filter p s := by
ext x
split_ifs with h <;> by_cases h' : x = a <;> simp [h, h']
theorem filter_erase (a : Ξ±) (s : Finset Ξ±) : filter p (erase s a) = erase (filter p s) a := by
ext x
simp only [and_assoc, mem_filter, iff_self, mem_erase]
theorem filter_or (s : Finset Ξ±) : (s.filter fun a => p a β¨ q a) = s.filter p βͺ s.filter q :=
ext fun _ => by simp [mem_filter, mem_union, and_or_left]
theorem filter_and (s : Finset Ξ±) : (s.filter fun a => p a β§ q a) = s.filter p β© s.filter q :=
ext fun _ => by simp [mem_filter, mem_inter, and_comm, and_left_comm, and_self_iff, and_assoc]
theorem filter_not (s : Finset Ξ±) : (s.filter fun a => Β¬p a) = s \ s.filter p :=
ext fun a => by
simp only [Bool.decide_coe, Bool.not_eq_true', mem_filter, and_comm, mem_sdiff, not_and_or,
Bool.not_eq_true, and_or_left, and_not_self, or_false]
lemma filter_and_not (s : Finset Ξ±) (p q : Ξ± β Prop) [DecidablePred p] [DecidablePred q] :
s.filter (fun a β¦ p a β§ Β¬ q a) = s.filter p \ s.filter q := by
rw [filter_and, filter_not, β inter_sdiff_assoc, inter_eq_left.2 (filter_subset _ _)]
theorem sdiff_eq_filter (sβ sβ : Finset Ξ±) : sβ \ sβ = filter (Β· β sβ) sβ :=
ext fun _ => by simp [mem_sdiff, mem_filter]
theorem subset_union_elim {s : Finset Ξ±} {tβ tβ : Set Ξ±} (h : βs β tβ βͺ tβ) :
β sβ sβ : Finset Ξ±, sβ βͺ sβ = s β§ βsβ β tβ β§ βsβ β tβ \ tβ := by
classical
refine β¨s.filter (Β· β tβ), s.filter (Β· β tβ), ?_, ?_, ?_β©
Β· simp [filter_union_right, em]
Β· intro x
simp
Β· intro x
simp only [not_not, coe_filter, Set.mem_setOf_eq, Set.mem_diff, and_imp]
intro hx hxβ
exact β¨Or.resolve_left (h hx) hxβ, hxββ©
-- This is not a good simp lemma, as it would prevent `Finset.mem_filter` from firing
-- on, e.g. `x β s.filter (Eq b)`.
/-- After filtering out everything that does not equal a given value, at most that value remains.
This is equivalent to `filter_eq'` with the equality the other way.
-/
theorem filter_eq [DecidableEq Ξ²] (s : Finset Ξ²) (b : Ξ²) :
s.filter (Eq b) = ite (b β s) {b} β
:= by
split_ifs with h
Β· ext
simp only [mem_filter, mem_singleton, decide_eq_true_eq]
refine β¨fun h => h.2.symm, ?_β©
rintro rfl
exact β¨h, rflβ©
Β· ext
simp only [mem_filter, not_and, iff_false, not_mem_empty, decide_eq_true_eq]
rintro m rfl
exact h m
/-- After filtering out everything that does not equal a given value, at most that value remains.
This is equivalent to `filter_eq` with the equality the other way.
-/
theorem filter_eq' [DecidableEq Ξ²] (s : Finset Ξ²) (b : Ξ²) :
(s.filter fun a => a = b) = ite (b β s) {b} β
:=
_root_.trans (filter_congr fun _ _ => by simp_rw [@eq_comm _ b]) (filter_eq s b)
theorem filter_ne [DecidableEq Ξ²] (s : Finset Ξ²) (b : Ξ²) :
(s.filter fun a => b β a) = s.erase b := by
ext
simp only [mem_filter, mem_erase, Ne, decide_not, Bool.not_eq_true', decide_eq_false_iff_not]
tauto
theorem filter_ne' [DecidableEq Ξ²] (s : Finset Ξ²) (b : Ξ²) : (s.filter fun a => a β b) = s.erase b :=
_root_.trans (filter_congr fun _ _ => by simp_rw [@ne_comm _ b]) (filter_ne s b)
theorem filter_union_filter_of_codisjoint (s : Finset Ξ±) (h : Codisjoint p q) :
s.filter p βͺ s.filter q = s :=
(filter_or _ _ _).symm.trans <| filter_true_of_mem fun x _ => h.top_le x trivial
theorem filter_union_filter_neg_eq [β x, Decidable (Β¬p x)] (s : Finset Ξ±) :
(s.filter p βͺ s.filter fun a => Β¬p a) = s :=
filter_union_filter_of_codisjoint _ _ _ <| @codisjoint_hnot_right _ _ p
end
end Filter
/-! ### range -/
section Range
open Nat
variable {n m l : β}
@[simp]
theorem range_filter_eq {n m : β} : (range n).filter (Β· = m) = if m < n then {m} else β
:= by
convert filter_eq (range n) m using 2
Β· ext
rw [eq_comm]
Β· simp
end Range
end Finset
/-! ### dedup on list and multiset -/
namespace Multiset
variable [DecidableEq Ξ±] {s t : Multiset Ξ±}
@[simp]
theorem toFinset_add (s t : Multiset Ξ±) : toFinset (s + t) = toFinset s βͺ toFinset t :=
Finset.ext <| by simp
@[simp]
theorem toFinset_inter (s t : Multiset Ξ±) : toFinset (s β© t) = toFinset s β© toFinset t :=
Finset.ext <| by simp
@[simp]
theorem toFinset_union (s t : Multiset Ξ±) : (s βͺ t).toFinset = s.toFinset βͺ t.toFinset := by
ext; simp
@[simp]
theorem toFinset_eq_empty {m : Multiset Ξ±} : m.toFinset = β
β m = 0 :=
Finset.val_inj.symm.trans Multiset.dedup_eq_zero
@[simp]
theorem toFinset_nonempty : s.toFinset.Nonempty β s β 0 := by
simp only [toFinset_eq_empty, Ne, Finset.nonempty_iff_ne_empty]
@[aesop safe apply (rule_sets := [finsetNonempty])]
protected alias β¨_, Aesop.toFinset_nonempty_of_neβ© := toFinset_nonempty
@[simp]
theorem toFinset_filter (s : Multiset Ξ±) (p : Ξ± β Prop) [DecidablePred p] :
Multiset.toFinset (s.filter p) = s.toFinset.filter p := by
ext; simp
end Multiset
namespace List
| variable [DecidableEq Ξ±] {l l' : List Ξ±} {a : Ξ±} {f : Ξ± β Ξ²}
{s : Finset Ξ±} {t : Set Ξ²} {t' : Finset Ξ²}
| Mathlib/Data/Finset/Basic.lean | 550 | 552 |
/-
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.Data.Set.SymmDiff
import Mathlib.Order.SuccPred.Relation
import Mathlib.Topology.Irreducible
/-!
# Connected subsets of topological spaces
In this file we define connected subsets of a topological spaces and various other properties and
classes related to connectivity.
## Main definitions
We define the following properties for sets in a topological space:
* `IsConnected`: a nonempty set that has no non-trivial open partition.
See also the section below in the module doc.
* `connectedComponent` is the connected component of an element in the space.
We also have a class stating that the whole space satisfies that property: `ConnectedSpace`
## On the definition of connected sets/spaces
In informal mathematics, connected spaces are assumed to be nonempty.
We formalise the predicate without that assumption as `IsPreconnected`.
In other words, the only difference is whether the empty space counts as connected.
There are good reasons to consider the empty space to be βtoo simple to be simpleβ
See also https://ncatlab.org/nlab/show/too+simple+to+be+simple,
and in particular
https://ncatlab.org/nlab/show/too+simple+to+be+simple#relationship_to_biased_definitions.
-/
open Set Function Topology TopologicalSpace Relation
universe u v
variable {Ξ± : Type u} {Ξ² : Type v} {ΞΉ : Type*} {Ο : ΞΉ β Type*} [TopologicalSpace Ξ±]
{s t u v : Set Ξ±}
section Preconnected
/-- A preconnected set is one where there is no non-trivial open partition. -/
def IsPreconnected (s : Set Ξ±) : Prop :=
β u v : Set Ξ±, IsOpen u β IsOpen v β s β u βͺ v β (s β© u).Nonempty β (s β© v).Nonempty β
(s β© (u β© v)).Nonempty
/-- A connected set is one that is nonempty and where there is no non-trivial open partition. -/
def IsConnected (s : Set Ξ±) : Prop :=
s.Nonempty β§ IsPreconnected s
theorem IsConnected.nonempty {s : Set Ξ±} (h : IsConnected s) : s.Nonempty :=
h.1
theorem IsConnected.isPreconnected {s : Set Ξ±} (h : IsConnected s) : IsPreconnected s :=
h.2
theorem IsPreirreducible.isPreconnected {s : Set Ξ±} (H : IsPreirreducible s) : IsPreconnected s :=
fun _ _ hu hv _ => H _ _ hu hv
theorem IsIrreducible.isConnected {s : Set Ξ±} (H : IsIrreducible s) : IsConnected s :=
β¨H.nonempty, H.isPreirreducible.isPreconnectedβ©
theorem isPreconnected_empty : IsPreconnected (β
: Set Ξ±) :=
isPreirreducible_empty.isPreconnected
theorem isConnected_singleton {x} : IsConnected ({x} : Set Ξ±) :=
isIrreducible_singleton.isConnected
theorem isPreconnected_singleton {x} : IsPreconnected ({x} : Set Ξ±) :=
isConnected_singleton.isPreconnected
theorem Set.Subsingleton.isPreconnected {s : Set Ξ±} (hs : s.Subsingleton) : IsPreconnected s :=
hs.induction_on isPreconnected_empty fun _ => isPreconnected_singleton
/-- If any point of a set is joined to a fixed point by a preconnected subset,
then the original set is preconnected as well. -/
theorem isPreconnected_of_forall {s : Set Ξ±} (x : Ξ±)
(H : β y β s, β t, t β s β§ x β t β§ y β t β§ IsPreconnected t) : IsPreconnected s := by
rintro u v hu hv hs β¨z, zs, zuβ© β¨y, ys, yvβ©
have xs : x β s := by
rcases H y ys with β¨t, ts, xt, -, -β©
exact ts xt
-- Porting note (https://github.com/leanprover-community/mathlib4/issues/11215): TODO: use `wlog xu : x β u := hs xs using u v y z, v u z y`
cases hs xs with
| inl xu =>
rcases H y ys with β¨t, ts, xt, yt, htβ©
have := ht u v hu hv (ts.trans hs) β¨x, xt, xuβ© β¨y, yt, yvβ©
exact this.imp fun z hz => β¨ts hz.1, hz.2β©
| inr xv =>
rcases H z zs with β¨t, ts, xt, zt, htβ©
have := ht v u hv hu (ts.trans <| by rwa [union_comm]) β¨x, xt, xvβ© β¨z, zt, zuβ©
exact this.imp fun _ h => β¨ts h.1, h.2.2, h.2.1β©
/-- If any two points of a set are contained in a preconnected subset,
then the original set is preconnected as well. -/
theorem isPreconnected_of_forall_pair {s : Set Ξ±}
(H : β x β s, β y β s, β t, t β s β§ x β t β§ y β t β§ IsPreconnected t) :
IsPreconnected s := by
rcases eq_empty_or_nonempty s with (rfl | β¨x, hxβ©)
exacts [isPreconnected_empty, isPreconnected_of_forall x fun y => H x hx y]
/-- A union of a family of preconnected sets with a common point is preconnected as well. -/
theorem isPreconnected_sUnion (x : Ξ±) (c : Set (Set Ξ±)) (H1 : β s β c, x β s)
(H2 : β s β c, IsPreconnected s) : IsPreconnected (ββ c) := by
apply isPreconnected_of_forall x
rintro y β¨s, sc, ysβ©
exact β¨s, subset_sUnion_of_mem sc, H1 s sc, ys, H2 s scβ©
theorem isPreconnected_iUnion {ΞΉ : Sort*} {s : ΞΉ β Set Ξ±} (hβ : (β i, s i).Nonempty)
(hβ : β i, IsPreconnected (s i)) : IsPreconnected (β i, s i) :=
Exists.elim hβ fun f hf => isPreconnected_sUnion f _ hf (forall_mem_range.2 hβ)
theorem IsPreconnected.union (x : Ξ±) {s t : Set Ξ±} (H1 : x β s) (H2 : x β t) (H3 : IsPreconnected s)
(H4 : IsPreconnected t) : IsPreconnected (s βͺ t) :=
sUnion_pair s t βΈ isPreconnected_sUnion x {s, t} (by rintro r (rfl | rfl | h) <;> assumption)
(by rintro r (rfl | rfl | h) <;> assumption)
theorem IsPreconnected.union' {s t : Set Ξ±} (H : (s β© t).Nonempty) (hs : IsPreconnected s)
(ht : IsPreconnected t) : IsPreconnected (s βͺ t) := by
rcases H with β¨x, hxs, hxtβ©
exact hs.union x hxs hxt ht
theorem IsConnected.union {s t : Set Ξ±} (H : (s β© t).Nonempty) (Hs : IsConnected s)
(Ht : IsConnected t) : IsConnected (s βͺ t) := by
rcases H with β¨x, hxβ©
refine β¨β¨x, mem_union_left t (mem_of_mem_inter_left hx)β©, ?_β©
exact Hs.isPreconnected.union x (mem_of_mem_inter_left hx) (mem_of_mem_inter_right hx)
Ht.isPreconnected
/-- The directed sUnion of a set S of preconnected subsets is preconnected. -/
theorem IsPreconnected.sUnion_directed {S : Set (Set Ξ±)} (K : DirectedOn (Β· β Β·) S)
(H : β s β S, IsPreconnected s) : IsPreconnected (ββ S) := by
rintro u v hu hv Huv β¨a, β¨s, hsS, hasβ©, hauβ© β¨b, β¨t, htS, hbtβ©, hbvβ©
obtain β¨r, hrS, hsr, htrβ© : β r β S, s β r β§ t β r := K s hsS t htS
have Hnuv : (r β© (u β© v)).Nonempty :=
H _ hrS u v hu hv ((subset_sUnion_of_mem hrS).trans Huv) β¨a, hsr has, hauβ© β¨b, htr hbt, hbvβ©
have Kruv : r β© (u β© v) β ββ S β© (u β© v) := inter_subset_inter_left _ (subset_sUnion_of_mem hrS)
exact Hnuv.mono Kruv
/-- The biUnion of a family of preconnected sets is preconnected if the graph determined by
whether two sets intersect is preconnected. -/
theorem IsPreconnected.biUnion_of_reflTransGen {ΞΉ : Type*} {t : Set ΞΉ} {s : ΞΉ β Set Ξ±}
(H : β i β t, IsPreconnected (s i))
(K : β i, i β t β β j, j β t β ReflTransGen (fun i j => (s i β© s j).Nonempty β§ i β t) i j) :
IsPreconnected (β n β t, s n) := by
let R := fun i j : ΞΉ => (s i β© s j).Nonempty β§ i β t
have P : β i, i β t β β j, j β t β ReflTransGen R i j β
β p, p β t β§ i β p β§ j β p β§ IsPreconnected (β j β p, s j) := fun i hi j hj h => by
induction h with
| refl =>
refine β¨{i}, singleton_subset_iff.mpr hi, mem_singleton i, mem_singleton i, ?_β©
rw [biUnion_singleton]
exact H i hi
| @tail j k _ hjk ih =>
obtain β¨p, hpt, hip, hjp, hpβ© := ih hjk.2
refine β¨insert k p, insert_subset_iff.mpr β¨hj, hptβ©, mem_insert_of_mem k hip,
mem_insert k p, ?_β©
rw [biUnion_insert]
refine (H k hj).union' (hjk.1.mono ?_) hp
rw [inter_comm]
exact inter_subset_inter_right _ (subset_biUnion_of_mem hjp)
refine isPreconnected_of_forall_pair ?_
intro x hx y hy
obtain β¨i : ΞΉ, hi : i β t, hxi : x β s iβ© := mem_iUnionβ.1 hx
obtain β¨j : ΞΉ, hj : j β t, hyj : y β s jβ© := mem_iUnionβ.1 hy
obtain β¨p, hpt, hip, hjp, hpβ© := P i hi j hj (K i hi j hj)
exact β¨β j β p, s j, biUnion_subset_biUnion_left hpt, mem_biUnion hip hxi,
mem_biUnion hjp hyj, hpβ©
/-- The biUnion of a family of preconnected sets is preconnected if the graph determined by
whether two sets intersect is preconnected. -/
theorem IsConnected.biUnion_of_reflTransGen {ΞΉ : Type*} {t : Set ΞΉ} {s : ΞΉ β Set Ξ±}
(ht : t.Nonempty) (H : β i β t, IsConnected (s i))
(K : β i, i β t β β j, j β t β ReflTransGen (fun i j : ΞΉ => (s i β© s j).Nonempty β§ i β t) i j) :
IsConnected (β n β t, s n) :=
β¨nonempty_biUnion.2 <| β¨ht.some, ht.some_mem, (H _ ht.some_mem).nonemptyβ©,
IsPreconnected.biUnion_of_reflTransGen (fun i hi => (H i hi).isPreconnected) Kβ©
/-- Preconnectedness of the iUnion of a family of preconnected sets
indexed by the vertices of a preconnected graph,
where two vertices are joined when the corresponding sets intersect. -/
theorem IsPreconnected.iUnion_of_reflTransGen {ΞΉ : Type*} {s : ΞΉ β Set Ξ±}
(H : β i, IsPreconnected (s i))
(K : β i j, ReflTransGen (fun i j : ΞΉ => (s i β© s j).Nonempty) i j) :
IsPreconnected (β n, s n) := by
rw [β biUnion_univ]
exact IsPreconnected.biUnion_of_reflTransGen (fun i _ => H i) fun i _ j _ => by
simpa [mem_univ] using K i j
theorem IsConnected.iUnion_of_reflTransGen {ΞΉ : Type*} [Nonempty ΞΉ] {s : ΞΉ β Set Ξ±}
(H : β i, IsConnected (s i))
(K : β i j, ReflTransGen (fun i j : ΞΉ => (s i β© s j).Nonempty) i j) : IsConnected (β n, s n) :=
β¨nonempty_iUnion.2 <| Nonempty.elim βΉ_βΊ fun i : ΞΉ => β¨i, (H _).nonemptyβ©,
IsPreconnected.iUnion_of_reflTransGen (fun i => (H i).isPreconnected) Kβ©
section SuccOrder
open Order
variable [LinearOrder Ξ²] [SuccOrder Ξ²] [IsSuccArchimedean Ξ²]
/-- The iUnion of connected sets indexed by a type with an archimedean successor (like `β` or `β€`)
such that any two neighboring sets meet is preconnected. -/
theorem IsPreconnected.iUnion_of_chain {s : Ξ² β Set Ξ±} (H : β n, IsPreconnected (s n))
(K : β n, (s n β© s (succ n)).Nonempty) : IsPreconnected (β n, s n) :=
IsPreconnected.iUnion_of_reflTransGen H fun _ _ =>
reflTransGen_of_succ _ (fun i _ => K i) fun i _ => by
rw [inter_comm]
exact K i
/-- The iUnion of connected sets indexed by a type with an archimedean successor (like `β` or `β€`)
such that any two neighboring sets meet is connected. -/
theorem IsConnected.iUnion_of_chain [Nonempty Ξ²] {s : Ξ² β Set Ξ±} (H : β n, IsConnected (s n))
(K : β n, (s n β© s (succ n)).Nonempty) : IsConnected (β n, s n) :=
IsConnected.iUnion_of_reflTransGen H fun _ _ =>
reflTransGen_of_succ _ (fun i _ => K i) fun i _ => by
rw [inter_comm]
exact K i
/-- The iUnion of preconnected sets indexed by a subset of a type with an archimedean successor
(like `β` or `β€`) such that any two neighboring sets meet is preconnected. -/
theorem IsPreconnected.biUnion_of_chain {s : Ξ² β Set Ξ±} {t : Set Ξ²} (ht : OrdConnected t)
(H : β n β t, IsPreconnected (s n))
(K : β n : Ξ², n β t β succ n β t β (s n β© s (succ n)).Nonempty) :
IsPreconnected (β n β t, s n) := by
have h1 : β {i j k : Ξ²}, i β t β j β t β k β Ico i j β k β t := fun hi hj hk =>
ht.out hi hj (Ico_subset_Icc_self hk)
have h2 : β {i j k : Ξ²}, i β t β j β t β k β Ico i j β succ k β t := fun hi hj hk =>
ht.out hi hj β¨hk.1.trans <| le_succ _, succ_le_of_lt hk.2β©
have h3 : β {i j k : Ξ²}, i β t β j β t β k β Ico i j β (s k β© s (succ k)).Nonempty :=
fun hi hj hk => K _ (h1 hi hj hk) (h2 hi hj hk)
refine IsPreconnected.biUnion_of_reflTransGen H fun i hi j hj => ?_
exact reflTransGen_of_succ _ (fun k hk => β¨h3 hi hj hk, h1 hi hj hkβ©) fun k hk =>
β¨by rw [inter_comm]; exact h3 hj hi hk, h2 hj hi hkβ©
/-- The iUnion of connected sets indexed by a subset of a type with an archimedean successor
(like `β` or `β€`) such that any two neighboring sets meet is preconnected. -/
theorem IsConnected.biUnion_of_chain {s : Ξ² β Set Ξ±} {t : Set Ξ²} (hnt : t.Nonempty)
(ht : OrdConnected t) (H : β n β t, IsConnected (s n))
(K : β n : Ξ², n β t β succ n β t β (s n β© s (succ n)).Nonempty) : IsConnected (β n β t, s n) :=
β¨nonempty_biUnion.2 <| β¨hnt.some, hnt.some_mem, (H _ hnt.some_mem).nonemptyβ©,
IsPreconnected.biUnion_of_chain ht (fun i hi => (H i hi).isPreconnected) Kβ©
end SuccOrder
/-- Theorem of bark and tree: if a set is within a preconnected set and its closure, then it is
preconnected as well. See also `IsConnected.subset_closure`. -/
protected theorem IsPreconnected.subset_closure {s : Set Ξ±} {t : Set Ξ±} (H : IsPreconnected s)
(Kst : s β t) (Ktcs : t β closure s) : IsPreconnected t :=
fun u v hu hv htuv β¨_y, hyt, hyuβ© β¨_z, hzt, hzvβ© =>
let β¨p, hpu, hpsβ© := mem_closure_iff.1 (Ktcs hyt) u hu hyu
let β¨q, hqv, hqsβ© := mem_closure_iff.1 (Ktcs hzt) v hv hzv
let β¨r, hrs, hruvβ© := H u v hu hv (Subset.trans Kst htuv) β¨p, hps, hpuβ© β¨q, hqs, hqvβ©
β¨r, Kst hrs, hruvβ©
/-- Theorem of bark and tree: if a set is within a connected set and its closure, then it is
connected as well. See also `IsPreconnected.subset_closure`. -/
protected theorem IsConnected.subset_closure {s : Set Ξ±} {t : Set Ξ±} (H : IsConnected s)
(Kst : s β t) (Ktcs : t β closure s) : IsConnected t :=
β¨Nonempty.mono Kst H.left, IsPreconnected.subset_closure H.right Kst Ktcsβ©
/-- The closure of a preconnected set is preconnected as well. -/
protected theorem IsPreconnected.closure {s : Set Ξ±} (H : IsPreconnected s) :
IsPreconnected (closure s) :=
IsPreconnected.subset_closure H subset_closure Subset.rfl
/-- The closure of a connected set is connected as well. -/
protected theorem IsConnected.closure {s : Set Ξ±} (H : IsConnected s) : IsConnected (closure s) :=
IsConnected.subset_closure H subset_closure <| Subset.rfl
/-- The image of a preconnected set is preconnected as well. -/
protected theorem IsPreconnected.image [TopologicalSpace Ξ²] {s : Set Ξ±} (H : IsPreconnected s)
(f : Ξ± β Ξ²) (hf : ContinuousOn f s) : IsPreconnected (f '' s) := by
-- Unfold/destruct definitions in hypotheses
rintro u v hu hv huv β¨_, β¨x, xs, rflβ©, xuβ© β¨_, β¨y, ys, rflβ©, yvβ©
rcases continuousOn_iff'.1 hf u hu with β¨u', hu', u'_eqβ©
rcases continuousOn_iff'.1 hf v hv with β¨v', hv', v'_eqβ©
-- Reformulate `huv : f '' s β u βͺ v` in terms of `u'` and `v'`
replace huv : s β u' βͺ v' := by
rw [image_subset_iff, preimage_union] at huv
replace huv := subset_inter huv Subset.rfl
rw [union_inter_distrib_right, u'_eq, v'_eq, β union_inter_distrib_right] at huv
exact (subset_inter_iff.1 huv).1
-- Now `s β u' βͺ v'`, so we can apply `βΉIsPreconnected sβΊ`
obtain β¨z, hzβ© : (s β© (u' β© v')).Nonempty := by
refine H u' v' hu' hv' huv β¨x, ?_β© β¨y, ?_β© <;> rw [inter_comm]
exacts [u'_eq βΈ β¨xu, xsβ©, v'_eq βΈ β¨yv, ysβ©]
rw [β inter_self s, inter_assoc, inter_left_comm s u', β inter_assoc, inter_comm s, inter_comm s,
β u'_eq, β v'_eq] at hz
exact β¨f z, β¨z, hz.1.2, rflβ©, hz.1.1, hz.2.1β©
/-- The image of a connected set is connected as well. -/
protected theorem IsConnected.image [TopologicalSpace Ξ²] {s : Set Ξ±} (H : IsConnected s) (f : Ξ± β Ξ²)
(hf : ContinuousOn f s) : IsConnected (f '' s) :=
β¨image_nonempty.mpr H.nonempty, H.isPreconnected.image f hfβ©
theorem isPreconnected_closed_iff {s : Set Ξ±} :
IsPreconnected s β β t t', IsClosed t β IsClosed t' β
s β t βͺ t' β (s β© t).Nonempty β (s β© t').Nonempty β (s β© (t β© t')).Nonempty :=
β¨by
rintro h t t' ht ht' htt' β¨x, xs, xtβ© β¨y, ys, yt'β©
rw [β not_disjoint_iff_nonempty_inter, β subset_compl_iff_disjoint_right, compl_inter]
intro h'
have xt' : x β t' := (h' xs).resolve_left (absurd xt)
have yt : y β t := (h' ys).resolve_right (absurd yt')
have := h _ _ ht.isOpen_compl ht'.isOpen_compl h' β¨y, ys, ytβ© β¨x, xs, xt'β©
rw [β compl_union] at this
exact this.ne_empty htt'.disjoint_compl_right.inter_eq,
by
rintro h u v hu hv huv β¨x, xs, xuβ© β¨y, ys, yvβ©
rw [β not_disjoint_iff_nonempty_inter, β subset_compl_iff_disjoint_right, compl_inter]
intro h'
have xv : x β v := (h' xs).elim (absurd xu) id
have yu : y β u := (h' ys).elim id (absurd yv)
have := h _ _ hu.isClosed_compl hv.isClosed_compl h' β¨y, ys, yuβ© β¨x, xs, xvβ©
rw [β compl_union] at this
exact this.ne_empty huv.disjoint_compl_right.inter_eqβ©
theorem Topology.IsInducing.isPreconnected_image [TopologicalSpace Ξ²] {s : Set Ξ±} {f : Ξ± β Ξ²}
(hf : IsInducing f) : IsPreconnected (f '' s) β IsPreconnected s := by
refine β¨fun h => ?_, fun h => h.image _ hf.continuous.continuousOnβ©
rintro u v hu' hv' huv β¨x, hxs, hxuβ© β¨y, hys, hyvβ©
rcases hf.isOpen_iff.1 hu' with β¨u, hu, rflβ©
rcases hf.isOpen_iff.1 hv' with β¨v, hv, rflβ©
replace huv : f '' s β u βͺ v := by rwa [image_subset_iff]
rcases h u v hu hv huv β¨f x, mem_image_of_mem _ hxs, hxuβ© β¨f y, mem_image_of_mem _ hys, hyvβ© with
β¨_, β¨z, hzs, rflβ©, hzuvβ©
exact β¨z, hzs, hzuvβ©
@[deprecated (since := "2024-10-28")]
alias Inducing.isPreconnected_image := IsInducing.isPreconnected_image
/- TODO: The following lemmas about connection of preimages hold more generally for strict maps
(the quotient and subspace topologies of the image agree) whose fibers are preconnected. -/
theorem IsPreconnected.preimage_of_isOpenMap [TopologicalSpace Ξ²] {f : Ξ± β Ξ²} {s : Set Ξ²}
(hs : IsPreconnected s) (hinj : Function.Injective f) (hf : IsOpenMap f) (hsf : s β range f) :
IsPreconnected (f β»ΒΉ' s) := fun u v hu hv hsuv hsu hsv => by
replace hsf : f '' (f β»ΒΉ' s) = s := image_preimage_eq_of_subset hsf
obtain β¨_, has, β¨a, hau, rflβ©, havβ© : (s β© (f '' u β© f '' v)).Nonempty := by
refine hs (f '' u) (f '' v) (hf u hu) (hf v hv) ?_ ?_ ?_
Β· simpa only [hsf, image_union] using image_subset f hsuv
Β· simpa only [image_preimage_inter] using hsu.image f
Β· simpa only [image_preimage_inter] using hsv.image f
Β· exact β¨a, has, hau, hinj.mem_set_image.1 havβ©
theorem IsPreconnected.preimage_of_isClosedMap [TopologicalSpace Ξ²] {s : Set Ξ²}
(hs : IsPreconnected s) {f : Ξ± β Ξ²} (hinj : Function.Injective f) (hf : IsClosedMap f)
(hsf : s β range f) : IsPreconnected (f β»ΒΉ' s) :=
isPreconnected_closed_iff.2 fun u v hu hv hsuv hsu hsv => by
replace hsf : f '' (f β»ΒΉ' s) = s := image_preimage_eq_of_subset hsf
obtain β¨_, has, β¨a, hau, rflβ©, havβ© : (s β© (f '' u β© f '' v)).Nonempty := by
refine isPreconnected_closed_iff.1 hs (f '' u) (f '' v) (hf u hu) (hf v hv) ?_ ?_ ?_
Β· simpa only [hsf, image_union] using image_subset f hsuv
Β· simpa only [image_preimage_inter] using hsu.image f
Β· simpa only [image_preimage_inter] using hsv.image f
Β· exact β¨a, has, hau, hinj.mem_set_image.1 havβ©
theorem IsConnected.preimage_of_isOpenMap [TopologicalSpace Ξ²] {s : Set Ξ²} (hs : IsConnected s)
{f : Ξ± β Ξ²} (hinj : Function.Injective f) (hf : IsOpenMap f) (hsf : s β range f) :
IsConnected (f β»ΒΉ' s) :=
β¨hs.nonempty.preimage' hsf, hs.isPreconnected.preimage_of_isOpenMap hinj hf hsfβ©
theorem IsConnected.preimage_of_isClosedMap [TopologicalSpace Ξ²] {s : Set Ξ²} (hs : IsConnected s)
{f : Ξ± β Ξ²} (hinj : Function.Injective f) (hf : IsClosedMap f) (hsf : s β range f) :
IsConnected (f β»ΒΉ' s) :=
β¨hs.nonempty.preimage' hsf, hs.isPreconnected.preimage_of_isClosedMap hinj hf hsfβ©
theorem IsPreconnected.subset_or_subset (hu : IsOpen u) (hv : IsOpen v) (huv : Disjoint u v)
(hsuv : s β u βͺ v) (hs : IsPreconnected s) : s β u β¨ s β v := by
specialize hs u v hu hv hsuv
obtain hsu | hsu := (s β© u).eq_empty_or_nonempty
Β· exact Or.inr ((Set.disjoint_iff_inter_eq_empty.2 hsu).subset_right_of_subset_union hsuv)
Β· replace hs := mt (hs hsu)
simp_rw [Set.not_nonempty_iff_eq_empty, β Set.disjoint_iff_inter_eq_empty,
disjoint_iff_inter_eq_empty.1 huv] at hs
exact Or.inl ((hs s.disjoint_empty).subset_left_of_subset_union hsuv)
theorem IsPreconnected.subset_left_of_subset_union (hu : IsOpen u) (hv : IsOpen v)
(huv : Disjoint u v) (hsuv : s β u βͺ v) (hsu : (s β© u).Nonempty) (hs : IsPreconnected s) :
s β u :=
Disjoint.subset_left_of_subset_union hsuv
(by
by_contra hsv
rw [not_disjoint_iff_nonempty_inter] at hsv
obtain β¨x, _, hxβ© := hs u v hu hv hsuv hsu hsv
exact Set.disjoint_iff.1 huv hx)
theorem IsPreconnected.subset_right_of_subset_union (hu : IsOpen u) (hv : IsOpen v)
(huv : Disjoint u v) (hsuv : s β u βͺ v) (hsv : (s β© v).Nonempty) (hs : IsPreconnected s) :
s β v :=
hs.subset_left_of_subset_union hv hu huv.symm (union_comm u v βΈ hsuv) hsv
/-- If a preconnected set `s` intersects an open set `u`, and limit points of `u` inside `s` are
contained in `u`, then the whole set `s` is contained in `u`. -/
theorem IsPreconnected.subset_of_closure_inter_subset (hs : IsPreconnected s) (hu : IsOpen u)
(h'u : (s β© u).Nonempty) (h : closure u β© s β u) : s β u := by
have A : s β u βͺ (closure u)αΆ := by
intro x hx
by_cases xu : x β u
Β· exact Or.inl xu
Β· right
intro h'x
exact xu (h (mem_inter h'x hx))
apply hs.subset_left_of_subset_union hu isClosed_closure.isOpen_compl _ A h'u
exact disjoint_compl_right.mono_right (compl_subset_compl.2 subset_closure)
theorem IsPreconnected.prod [TopologicalSpace Ξ²] {s : Set Ξ±} {t : Set Ξ²} (hs : IsPreconnected s)
| (ht : IsPreconnected t) : IsPreconnected (s ΓΛ’ t) := by
apply isPreconnected_of_forall_pair
rintro β¨aβ, bββ© β¨haβ, hbββ© β¨aβ, bββ© β¨haβ, hbββ©
refine β¨Prod.mk aβ '' t βͺ flip Prod.mk bβ '' s, ?_, .inl β¨bβ, hbβ, rflβ©, .inr β¨aβ, haβ, rflβ©, ?_β©
Β· rintro _ (β¨y, hy, rflβ© | β¨x, hx, rflβ©)
exacts [β¨haβ, hyβ©, β¨hx, hbββ©]
Β· exact (ht.image _ (by fun_prop)).union (aβ, bβ) β¨bβ, hbβ, rflβ©
β¨aβ, haβ, rflβ© (hs.image _ (Continuous.prodMk_left _).continuousOn)
| Mathlib/Topology/Connected/Basic.lean | 413 | 421 |
/-
Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes HΓΆlzl, Yury Kudryashov
-/
import Mathlib.Data.ENNReal.Operations
/-!
# Results about division in extended non-negative reals
This file establishes basic properties related to the inversion and division operations on `ββ₯0β`.
For instance, as a consequence of being a `DivInvOneMonoid`, `ββ₯0β` inherits a power operation
with integer exponent.
## Main results
A few order isomorphisms are worthy of mention:
- `OrderIso.invENNReal : ββ₯0β βo ββ₯0βα΅α΅`: The map `x β¦ xβ»ΒΉ` as an order isomorphism to the dual.
- `orderIsoIicOneBirational : ββ₯0β βo Iic (1 : ββ₯0β)`: The birational order isomorphism between
`ββ₯0β` and the unit interval `Set.Iic (1 : ββ₯0β)` given by `x β¦ (xβ»ΒΉ + 1)β»ΒΉ` with inverse
`x β¦ (xβ»ΒΉ - 1)β»ΒΉ`
- `orderIsoIicCoe (a : ββ₯0) : Iic (a : ββ₯0β) βo Iic a`: Order isomorphism between an initial
interval in `ββ₯0β` and an initial interval in `ββ₯0` given by the identity map.
- `orderIsoUnitIntervalBirational : ββ₯0β βo Icc (0 : β) 1`: An order isomorphism between
the extended nonnegative real numbers and the unit interval. This is `orderIsoIicOneBirational`
composed with the identity order isomorphism between `Iic (1 : ββ₯0β)` and `Icc (0 : β) 1`.
-/
assert_not_exists Finset
open Set NNReal
namespace ENNReal
noncomputable section Inv
variable {a b c d : ββ₯0β} {r p q : ββ₯0}
protected theorem div_eq_inv_mul : a / b = bβ»ΒΉ * a := by rw [div_eq_mul_inv, mul_comm]
@[simp] theorem inv_zero : (0 : ββ₯0β)β»ΒΉ = β :=
show sInf { b : ββ₯0β | 1 β€ 0 * b } = β by simp
@[simp] theorem inv_top : ββ»ΒΉ = 0 :=
bot_unique <| le_of_forall_gt_imp_ge_of_dense fun a (h : 0 < a) => sInf_le <| by
simp [*, h.ne', top_mul]
theorem coe_inv_le : (βrβ»ΒΉ : ββ₯0β) β€ (βr)β»ΒΉ :=
le_sInf fun b (hb : 1 β€ βr * b) =>
coe_le_iff.2 <| by
rintro b rfl
apply NNReal.inv_le_of_le_mul
rwa [β coe_mul, β coe_one, coe_le_coe] at hb
@[simp, norm_cast]
theorem coe_inv (hr : r β 0) : (βrβ»ΒΉ : ββ₯0β) = (βr)β»ΒΉ :=
coe_inv_le.antisymm <| sInf_le <| mem_setOf.2 <| by rw [β coe_mul, mul_inv_cancelβ hr, coe_one]
@[norm_cast]
theorem coe_inv_two : ((2β»ΒΉ : ββ₯0) : ββ₯0β) = 2β»ΒΉ := by rw [coe_inv _root_.two_ne_zero, coe_two]
@[simp, norm_cast]
theorem coe_div (hr : r β 0) : (β(p / r) : ββ₯0β) = p / r := by
rw [div_eq_mul_inv, div_eq_mul_inv, coe_mul, coe_inv hr]
lemma coe_div_le : β(p / r) β€ (p / r : ββ₯0β) := by
simpa only [div_eq_mul_inv, coe_mul] using mul_le_mul_left' coe_inv_le _
theorem div_zero (h : a β 0) : a / 0 = β := by simp [div_eq_mul_inv, h]
instance : DivInvOneMonoid ββ₯0β :=
{ inferInstanceAs (DivInvMonoid ββ₯0β) with
inv_one := by simpa only [coe_inv one_ne_zero, coe_one] using coe_inj.2 inv_one }
protected theorem inv_pow : β {a : ββ₯0β} {n : β}, (a ^ n)β»ΒΉ = aβ»ΒΉ ^ n
| _, 0 => by simp only [pow_zero, inv_one]
| β€, n + 1 => by simp [top_pow]
| (a : ββ₯0), n + 1 => by
rcases eq_or_ne a 0 with (rfl | ha)
Β· simp [top_pow]
Β· have := pow_ne_zero (n + 1) ha
norm_cast
rw [inv_pow]
protected theorem mul_inv_cancel (h0 : a β 0) (ht : a β β) : a * aβ»ΒΉ = 1 := by
lift a to ββ₯0 using ht
norm_cast at h0; norm_cast
exact mul_inv_cancelβ h0
protected theorem inv_mul_cancel (h0 : a β 0) (ht : a β β) : aβ»ΒΉ * a = 1 :=
mul_comm a aβ»ΒΉ βΈ ENNReal.mul_inv_cancel h0 ht
/-- See `ENNReal.inv_mul_cancel_left` for a simpler version assuming `a β 0`, `a β β`. -/
protected lemma inv_mul_cancel_left' (haβ : a = 0 β b = 0) (ha : a = β β b = 0) :
aβ»ΒΉ * (a * b) = b := by
obtain rfl | haβ := eq_or_ne a 0
Β· simp_all
obtain rfl | ha := eq_or_ne a β€
Β· simp_all
Β· simp [β mul_assoc, ENNReal.inv_mul_cancel, *]
/-- See `ENNReal.inv_mul_cancel_left'` for a stronger version. -/
protected lemma inv_mul_cancel_left (haβ : a β 0) (ha : a β β) : aβ»ΒΉ * (a * b) = b :=
ENNReal.inv_mul_cancel_left' (by simp [haβ]) (by simp [ha])
/-- See `ENNReal.mul_inv_cancel_left` for a simpler version assuming `a β 0`, `a β β`. -/
protected lemma mul_inv_cancel_left' (haβ : a = 0 β b = 0) (ha : a = β β b = 0) :
a * (aβ»ΒΉ * b) = b := by
obtain rfl | haβ := eq_or_ne a 0
Β· simp_all
obtain rfl | ha := eq_or_ne a β€
Β· simp_all
Β· simp [β mul_assoc, ENNReal.mul_inv_cancel, *]
/-- See `ENNReal.mul_inv_cancel_left'` for a stronger version. -/
protected lemma mul_inv_cancel_left (haβ : a β 0) (ha : a β β) : a * (aβ»ΒΉ * b) = b :=
ENNReal.mul_inv_cancel_left' (by simp [haβ]) (by simp [ha])
/-- See `ENNReal.mul_inv_cancel_right` for a simpler version assuming `b β 0`, `b β β`. -/
protected lemma mul_inv_cancel_right' (hbβ : b = 0 β a = 0) (hb : b = β β a = 0) :
a * b * bβ»ΒΉ = a := by
obtain rfl | hbβ := eq_or_ne b 0
Β· simp_all
obtain rfl | hb := eq_or_ne b β€
Β· simp_all
Β· simp [mul_assoc, ENNReal.mul_inv_cancel, *]
/-- See `ENNReal.mul_inv_cancel_right'` for a stronger version. -/
protected lemma mul_inv_cancel_right (hbβ : b β 0) (hb : b β β) : a * b * bβ»ΒΉ = a :=
ENNReal.mul_inv_cancel_right' (by simp [hbβ]) (by simp [hb])
/-- See `ENNReal.inv_mul_cancel_right` for a simpler version assuming `b β 0`, `b β β`. -/
protected lemma inv_mul_cancel_right' (hbβ : b = 0 β a = 0) (hb : b = β β a = 0) :
a * bβ»ΒΉ * b = a := by
obtain rfl | hbβ := eq_or_ne b 0
Β· simp_all
obtain rfl | hb := eq_or_ne b β€
Β· simp_all
Β· simp [mul_assoc, ENNReal.inv_mul_cancel, *]
/-- See `ENNReal.inv_mul_cancel_right'` for a stronger version. -/
protected lemma inv_mul_cancel_right (hbβ : b β 0) (hb : b β β) : a * bβ»ΒΉ * b = a :=
ENNReal.inv_mul_cancel_right' (by simp [hbβ]) (by simp [hb])
/-- See `ENNReal.mul_div_cancel_right` for a simpler version assuming `b β 0`, `b β β`. -/
protected lemma mul_div_cancel_right' (hbβ : b = 0 β a = 0) (hb : b = β β a = 0) :
a * b / b = a := ENNReal.mul_inv_cancel_right' hbβ hb
/-- See `ENNReal.mul_div_cancel_right'` for a stronger version. -/
protected lemma mul_div_cancel_right (hbβ : b β 0) (hb : b β β) : a * b / b = a :=
ENNReal.mul_div_cancel_right' (by simp [hbβ]) (by simp [hb])
/-- See `ENNReal.div_mul_cancel` for a simpler version assuming `a β 0`, `a β β`. -/
protected lemma div_mul_cancel' (haβ : a = 0 β b = 0) (ha : a = β β b = 0) : b / a * a = b :=
ENNReal.inv_mul_cancel_right' haβ ha
/-- See `ENNReal.div_mul_cancel'` for a stronger version. -/
protected lemma div_mul_cancel (haβ : a β 0) (ha : a β β) : b / a * a = b :=
ENNReal.div_mul_cancel' (by simp [haβ]) (by simp [ha])
/-- See `ENNReal.mul_div_cancel` for a simpler version assuming `a β 0`, `a β β`. -/
protected lemma mul_div_cancel' (haβ : a = 0 β b = 0) (ha : a = β β b = 0) : a * (b / a) = b := by
rw [mul_comm, ENNReal.div_mul_cancel' haβ ha]
/-- See `ENNReal.mul_div_cancel'` for a stronger version. -/
protected lemma mul_div_cancel (haβ : a β 0) (ha : a β β) : a * (b / a) = b :=
ENNReal.mul_div_cancel' (by simp [haβ]) (by simp [ha])
protected theorem mul_comm_div : a / b * c = a * (c / b) := by
simp only [div_eq_mul_inv, mul_left_comm, mul_comm, mul_assoc]
protected theorem mul_div_right_comm : a * b / c = a / c * b := by
simp only [div_eq_mul_inv, mul_right_comm]
instance : InvolutiveInv ββ₯0β where
inv_inv a := by
by_cases a = 0 <;> cases a <;> simp_all [none_eq_top, some_eq_coe, -coe_inv, (coe_inv _).symm]
@[simp] protected lemma inv_eq_one : aβ»ΒΉ = 1 β a = 1 := by rw [β inv_inj, inv_inv, inv_one]
@[simp] theorem inv_eq_top : aβ»ΒΉ = β β a = 0 := inv_zero βΈ inv_inj
theorem inv_ne_top : aβ»ΒΉ β β β a β 0 := by simp
@[aesop (rule_sets := [finiteness]) safe apply]
protected alias β¨_, Finiteness.inv_ne_topβ© := ENNReal.inv_ne_top
@[simp]
theorem inv_lt_top {x : ββ₯0β} : xβ»ΒΉ < β β 0 < x := by
simp only [lt_top_iff_ne_top, inv_ne_top, pos_iff_ne_zero]
theorem div_lt_top {x y : ββ₯0β} (h1 : x β β) (h2 : y β 0) : x / y < β :=
mul_lt_top h1.lt_top (inv_ne_top.mpr h2).lt_top
@[simp]
protected theorem inv_eq_zero : aβ»ΒΉ = 0 β a = β :=
inv_top βΈ inv_inj
protected theorem inv_ne_zero : aβ»ΒΉ β 0 β a β β := by simp
protected theorem div_pos (ha : a β 0) (hb : b β β) : 0 < a / b :=
ENNReal.mul_pos ha <| ENNReal.inv_ne_zero.2 hb
protected theorem inv_mul_le_iff {x y z : ββ₯0β} (h1 : x β 0) (h2 : x β β) :
xβ»ΒΉ * y β€ z β y β€ x * z := by
rw [β mul_le_mul_left h1 h2, β mul_assoc, ENNReal.mul_inv_cancel h1 h2, one_mul]
protected theorem mul_inv_le_iff {x y z : ββ₯0β} (h1 : y β 0) (h2 : y β β) :
x * yβ»ΒΉ β€ z β x β€ z * y := by
rw [mul_comm, ENNReal.inv_mul_le_iff h1 h2, mul_comm]
protected theorem div_le_iff {x y z : ββ₯0β} (h1 : y β 0) (h2 : y β β) :
x / y β€ z β x β€ z * y := by
rw [div_eq_mul_inv, ENNReal.mul_inv_le_iff h1 h2]
protected theorem div_le_iff' {x y z : ββ₯0β} (h1 : y β 0) (h2 : y β β) :
x / y β€ z β x β€ y * z := by
rw [mul_comm, ENNReal.div_le_iff h1 h2]
protected theorem mul_inv {a b : ββ₯0β} (ha : a β 0 β¨ b β β) (hb : a β β β¨ b β 0) :
(a * b)β»ΒΉ = aβ»ΒΉ * bβ»ΒΉ := by
induction' b with b
Β· replace ha : a β 0 := ha.neg_resolve_right rfl
simp [ha]
induction' a with a
Β· replace hb : b β 0 := coe_ne_zero.1 (hb.neg_resolve_left rfl)
simp [hb]
by_cases h'a : a = 0
Β· simp only [h'a, top_mul, ENNReal.inv_zero, ENNReal.coe_ne_top, zero_mul, Ne,
not_false_iff, ENNReal.coe_zero, ENNReal.inv_eq_zero]
by_cases h'b : b = 0
Β· simp only [h'b, ENNReal.inv_zero, ENNReal.coe_ne_top, mul_top, Ne, not_false_iff,
mul_zero, ENNReal.coe_zero, ENNReal.inv_eq_zero]
rw [β ENNReal.coe_mul, β ENNReal.coe_inv, β ENNReal.coe_inv h'a, β ENNReal.coe_inv h'b, β
ENNReal.coe_mul, mul_inv_rev, mul_comm]
simp [h'a, h'b]
protected theorem inv_div {a b : ββ₯0β} (htop : b β β β¨ a β β) (hzero : b β 0 β¨ a β 0) :
(a / b)β»ΒΉ = b / a := by
rw [β ENNReal.inv_ne_zero] at htop
rw [β ENNReal.inv_ne_top] at hzero
rw [ENNReal.div_eq_inv_mul, ENNReal.div_eq_inv_mul, ENNReal.mul_inv htop hzero, mul_comm, inv_inv]
protected theorem mul_div_mul_left (a b : ββ₯0β) (hc : c β 0) (hc' : c β β€) :
c * a / (c * b) = a / b := by
rw [div_eq_mul_inv, div_eq_mul_inv, ENNReal.mul_inv (Or.inl hc) (Or.inl hc'), mul_mul_mul_comm,
ENNReal.mul_inv_cancel hc hc', one_mul]
protected theorem mul_div_mul_right (a b : ββ₯0β) (hc : c β 0) (hc' : c β β€) :
a * c / (b * c) = a / b := by
rw [div_eq_mul_inv, div_eq_mul_inv, ENNReal.mul_inv (Or.inr hc') (Or.inr hc), mul_mul_mul_comm,
ENNReal.mul_inv_cancel hc hc', mul_one]
protected theorem sub_div (h : 0 < b β b < a β c β 0) : (a - b) / c = a / c - b / c := by
simp_rw [div_eq_mul_inv]
exact ENNReal.sub_mul (by simpa using h)
@[simp]
protected theorem inv_pos : 0 < aβ»ΒΉ β a β β :=
pos_iff_ne_zero.trans ENNReal.inv_ne_zero
theorem inv_strictAnti : StrictAnti (Inv.inv : ββ₯0β β ββ₯0β) := by
intro a b h
lift a to ββ₯0 using h.ne_top
induction b; Β· simp
rw [coe_lt_coe] at h
rcases eq_or_ne a 0 with (rfl | ha); Β· simp [h]
rw [β coe_inv h.ne_bot, β coe_inv ha, coe_lt_coe]
exact NNReal.inv_lt_inv ha h
@[simp]
protected theorem inv_lt_inv : aβ»ΒΉ < bβ»ΒΉ β b < a :=
inv_strictAnti.lt_iff_lt
theorem inv_lt_iff_inv_lt : aβ»ΒΉ < b β bβ»ΒΉ < a := by
simpa only [inv_inv] using @ENNReal.inv_lt_inv a bβ»ΒΉ
theorem lt_inv_iff_lt_inv : a < bβ»ΒΉ β b < aβ»ΒΉ := by
simpa only [inv_inv] using @ENNReal.inv_lt_inv aβ»ΒΉ b
@[simp]
protected theorem inv_le_inv : aβ»ΒΉ β€ bβ»ΒΉ β b β€ a :=
inv_strictAnti.le_iff_le
theorem inv_le_iff_inv_le : aβ»ΒΉ β€ b β bβ»ΒΉ β€ a := by
simpa only [inv_inv] using @ENNReal.inv_le_inv a bβ»ΒΉ
theorem le_inv_iff_le_inv : a β€ bβ»ΒΉ β b β€ aβ»ΒΉ := by
simpa only [inv_inv] using @ENNReal.inv_le_inv aβ»ΒΉ b
@[gcongr] protected theorem inv_le_inv' (h : a β€ b) : bβ»ΒΉ β€ aβ»ΒΉ :=
ENNReal.inv_strictAnti.antitone h
@[gcongr] protected theorem inv_lt_inv' (h : a < b) : bβ»ΒΉ < aβ»ΒΉ := ENNReal.inv_strictAnti h
@[simp]
protected theorem inv_le_one : aβ»ΒΉ β€ 1 β 1 β€ a := by rw [inv_le_iff_inv_le, inv_one]
protected theorem one_le_inv : 1 β€ aβ»ΒΉ β a β€ 1 := by rw [le_inv_iff_le_inv, inv_one]
@[simp]
protected theorem inv_lt_one : aβ»ΒΉ < 1 β 1 < a := by rw [inv_lt_iff_inv_lt, inv_one]
@[simp]
protected theorem one_lt_inv : 1 < aβ»ΒΉ β a < 1 := by rw [lt_inv_iff_lt_inv, inv_one]
/-- The inverse map `fun x β¦ xβ»ΒΉ` is an order isomorphism between `ββ₯0β` and its `OrderDual` -/
@[simps! apply]
def _root_.OrderIso.invENNReal : ββ₯0β βo ββ₯0βα΅α΅ where
map_rel_iff' := ENNReal.inv_le_inv
toEquiv := (Equiv.inv ββ₯0β).trans OrderDual.toDual
@[simp]
theorem _root_.OrderIso.invENNReal_symm_apply (a : ββ₯0βα΅α΅) :
OrderIso.invENNReal.symm a = (OrderDual.ofDual a)β»ΒΉ :=
rfl
@[simp] theorem div_top : a / β = 0 := by rw [div_eq_mul_inv, inv_top, mul_zero]
theorem top_div : β / a = if a = β then 0 else β := by simp [div_eq_mul_inv, top_mul']
theorem top_div_of_ne_top (h : a β β) : β / a = β := by simp [top_div, h]
@[simp] theorem top_div_coe : β / p = β := top_div_of_ne_top coe_ne_top
theorem top_div_of_lt_top (h : a < β) : β / a = β := top_div_of_ne_top h.ne
@[simp] protected theorem zero_div : 0 / a = 0 := zero_mul aβ»ΒΉ
theorem div_eq_top : a / b = β β a β 0 β§ b = 0 β¨ a = β β§ b β β := by
simp [div_eq_mul_inv, ENNReal.mul_eq_top]
protected theorem le_div_iff_mul_le (h0 : b β 0 β¨ c β 0) (ht : b β β β¨ c β β) :
a β€ c / b β a * b β€ c := by
induction' b with b
Β· lift c to ββ₯0 using ht.neg_resolve_left rfl
rw [div_top, nonpos_iff_eq_zero]
rcases eq_or_ne a 0 with (rfl | ha) <;> simp [*]
rcases eq_or_ne b 0 with (rfl | hb)
Β· have hc : c β 0 := h0.neg_resolve_left rfl
simp [div_zero hc]
Β· rw [β coe_ne_zero] at hb
rw [β ENNReal.mul_le_mul_right hb coe_ne_top, ENNReal.div_mul_cancel hb coe_ne_top]
protected theorem div_le_iff_le_mul (hb0 : b β 0 β¨ c β β) (hbt : b β β β¨ c β 0) :
a / b β€ c β a β€ c * b := by
suffices a * bβ»ΒΉ β€ c β a β€ c / bβ»ΒΉ by simpa [div_eq_mul_inv]
refine (ENNReal.le_div_iff_mul_le ?_ ?_).symm <;> simpa
protected theorem lt_div_iff_mul_lt (hb0 : b β 0 β¨ c β β) (hbt : b β β β¨ c β 0) :
c < a / b β c * b < a :=
lt_iff_lt_of_le_iff_le (ENNReal.div_le_iff_le_mul hb0 hbt)
theorem div_le_of_le_mul (h : a β€ b * c) : a / c β€ b := by
by_cases h0 : c = 0
Β· have : a = 0 := by simpa [h0] using h
simp [*]
by_cases hinf : c = β; Β· simp [hinf]
exact (ENNReal.div_le_iff_le_mul (Or.inl h0) (Or.inl hinf)).2 h
theorem div_le_of_le_mul' (h : a β€ b * c) : a / b β€ c :=
div_le_of_le_mul <| mul_comm b c βΈ h
@[simp] protected theorem div_self_le_one : a / a β€ 1 := div_le_of_le_mul <| by rw [one_mul]
@[simp] protected lemma mul_inv_le_one (a : ββ₯0β) : a * aβ»ΒΉ β€ 1 := ENNReal.div_self_le_one
@[simp] protected lemma inv_mul_le_one (a : ββ₯0β) : aβ»ΒΉ * a β€ 1 := by simp [mul_comm]
@[simp] lemma mul_inv_ne_top (a : ββ₯0β) : a * aβ»ΒΉ β β€ :=
ne_top_of_le_ne_top one_ne_top a.mul_inv_le_one
@[simp] lemma inv_mul_ne_top (a : ββ₯0β) : aβ»ΒΉ * a β β€ := by simp [mul_comm]
theorem mul_le_of_le_div (h : a β€ b / c) : a * c β€ b := by
rw [β inv_inv c]
exact div_le_of_le_mul h
theorem mul_le_of_le_div' (h : a β€ b / c) : c * a β€ b :=
mul_comm a c βΈ mul_le_of_le_div h
protected theorem div_lt_iff (h0 : b β 0 β¨ c β 0) (ht : b β β β¨ c β β) : c / b < a β c < a * b :=
lt_iff_lt_of_le_iff_le <| ENNReal.le_div_iff_mul_le h0 ht
theorem mul_lt_of_lt_div (h : a < b / c) : a * c < b := by
contrapose! h
exact ENNReal.div_le_of_le_mul h
theorem mul_lt_of_lt_div' (h : a < b / c) : c * a < b :=
mul_comm a c βΈ mul_lt_of_lt_div h
theorem div_lt_of_lt_mul (h : a < b * c) : a / c < b :=
mul_lt_of_lt_div <| by rwa [div_eq_mul_inv, inv_inv]
theorem div_lt_of_lt_mul' (h : a < b * c) : a / b < c :=
div_lt_of_lt_mul <| by rwa [mul_comm]
theorem inv_le_iff_le_mul (hβ : b = β β a β 0) (hβ : a = β β b β 0) : aβ»ΒΉ β€ b β 1 β€ a * b := by
rw [β one_div, ENNReal.div_le_iff_le_mul, mul_comm]
exacts [or_not_of_imp hβ, not_or_of_imp hβ]
@[simp 900]
theorem le_inv_iff_mul_le : a β€ bβ»ΒΉ β a * b β€ 1 := by
rw [β one_div, ENNReal.le_div_iff_mul_le] <;>
Β· right
simp
@[gcongr] protected theorem div_le_div (hab : a β€ b) (hdc : d β€ c) : a / c β€ b / d :=
div_eq_mul_inv b d βΈ div_eq_mul_inv a c βΈ mul_le_mul' hab (ENNReal.inv_le_inv.mpr hdc)
@[gcongr] protected theorem div_le_div_left (h : a β€ b) (c : ββ₯0β) : c / b β€ c / a :=
ENNReal.div_le_div le_rfl h
@[gcongr] protected theorem div_le_div_right (h : a β€ b) (c : ββ₯0β) : a / c β€ b / c :=
ENNReal.div_le_div h le_rfl
protected theorem eq_inv_of_mul_eq_one_left (h : a * b = 1) : a = bβ»ΒΉ := by
rw [β mul_one a, β ENNReal.mul_inv_cancel (right_ne_zero_of_mul_eq_one h), β mul_assoc, h,
one_mul]
rintro rfl
simp [left_ne_zero_of_mul_eq_one h] at h
theorem mul_le_iff_le_inv {a b r : ββ₯0β} (hrβ : r β 0) (hrβ : r β β) : r * a β€ b β a β€ rβ»ΒΉ * b := by
rw [β @ENNReal.mul_le_mul_left _ a _ hrβ hrβ, β mul_assoc, ENNReal.mul_inv_cancel hrβ hrβ,
one_mul]
theorem le_of_forall_nnreal_lt {x y : ββ₯0β} (h : β r : ββ₯0, βr < x β βr β€ y) : x β€ y := by
refine le_of_forall_lt_imp_le_of_dense fun r hr => ?_
lift r to ββ₯0 using ne_top_of_lt hr
exact h r hr
lemma eq_of_forall_nnreal_iff {x y : ββ₯0β} (h : β r : ββ₯0, βr β€ x β βr β€ y) : x = y :=
le_antisymm (le_of_forall_nnreal_lt fun _r hr β¦ (h _).1 hr.le)
(le_of_forall_nnreal_lt fun _r hr β¦ (h _).2 hr.le)
theorem le_of_forall_pos_nnreal_lt {x y : ββ₯0β} (h : β r : ββ₯0, 0 < r β βr < x β βr β€ y) : x β€ y :=
le_of_forall_nnreal_lt fun r hr =>
(zero_le r).eq_or_lt.elim (fun h => h βΈ zero_le _) fun h0 => h r h0 hr
theorem eq_top_of_forall_nnreal_le {x : ββ₯0β} (h : β r : ββ₯0, βr β€ x) : x = β :=
top_unique <| le_of_forall_nnreal_lt fun r _ => h r
protected theorem add_div : (a + b) / c = a / c + b / c :=
right_distrib a b cβ»ΒΉ
protected theorem div_add_div_same {a b c : ββ₯0β} : a / c + b / c = (a + b) / c :=
ENNReal.add_div.symm
protected theorem div_self (h0 : a β 0) (hI : a β β) : a / a = 1 :=
ENNReal.mul_inv_cancel h0 hI
theorem mul_div_le : a * (b / a) β€ b :=
mul_le_of_le_div' le_rfl
theorem eq_div_iff (ha : a β 0) (ha' : a β β) : b = c / a β a * b = c :=
β¨fun h => by rw [h, ENNReal.mul_div_cancel ha ha'], fun h => by
rw [β h, mul_div_assoc, ENNReal.mul_div_cancel ha ha']β©
protected theorem div_eq_div_iff (ha : a β 0) (ha' : a β β) (hb : b β 0) (hb' : b β β) :
c / b = d / a β a * c = b * d := by
rw [eq_div_iff ha ha']
conv_rhs => rw [eq_comm]
rw [β eq_div_iff hb hb', mul_div_assoc, eq_comm]
theorem div_eq_one_iff {a b : ββ₯0β} (hbβ : b β 0) (hbβ : b β β) : a / b = 1 β a = b :=
β¨fun h => by rw [β (eq_div_iff hbβ hbβ).mp h.symm, mul_one], fun h =>
h.symm βΈ ENNReal.div_self hbβ hbββ©
theorem inv_two_add_inv_two : (2 : ββ₯0β)β»ΒΉ + 2β»ΒΉ = 1 := by
rw [β two_mul, β div_eq_mul_inv, ENNReal.div_self two_ne_zero ofNat_ne_top]
theorem inv_three_add_inv_three : (3 : ββ₯0β)β»ΒΉ + 3β»ΒΉ + 3β»ΒΉ = 1 := by
rw [β ENNReal.mul_inv_cancel three_ne_zero ofNat_ne_top]
ring
@[simp]
protected theorem add_halves (a : ββ₯0β) : a / 2 + a / 2 = a := by
rw [div_eq_mul_inv, β mul_add, inv_two_add_inv_two, mul_one]
@[simp]
theorem add_thirds (a : ββ₯0β) : a / 3 + a / 3 + a / 3 = a := by
rw [div_eq_mul_inv, β mul_add, β mul_add, inv_three_add_inv_three, mul_one]
@[simp] theorem div_eq_zero_iff : a / b = 0 β a = 0 β¨ b = β := by simp [div_eq_mul_inv]
@[simp] theorem div_pos_iff : 0 < a / b β a β 0 β§ b β β := by simp [pos_iff_ne_zero, not_or]
protected lemma div_ne_zero : a / b β 0 β a β 0 β§ b β β := by
rw [β pos_iff_ne_zero, div_pos_iff]
protected lemma div_mul (a : ββ₯0β) (h0 : b β 0 β¨ c β 0) (htop : b β β β¨ c β β) :
a / b * c = a / (b / c) := by
simp only [div_eq_mul_inv]
rw [ENNReal.mul_inv, inv_inv]
Β· ring
Β· simpa
Β· simpa
protected lemma mul_div_mul_comm (hc : c β 0 β¨ d β β) (hd : c β β β¨ d β 0) :
a * b / (c * d) = a / c * (b / d) := by
simp only [div_eq_mul_inv, ENNReal.mul_inv hc hd]
ring
protected theorem half_pos (h : a β 0) : 0 < a / 2 :=
ENNReal.div_pos h ofNat_ne_top
protected theorem one_half_lt_one : (2β»ΒΉ : ββ₯0β) < 1 :=
ENNReal.inv_lt_one.2 <| one_lt_two
protected theorem half_lt_self (hz : a β 0) (ht : a β β) : a / 2 < a := by
lift a to ββ₯0 using ht
rw [coe_ne_zero] at hz
rw [β coe_two, β coe_div, coe_lt_coe]
exacts [NNReal.half_lt_self hz, two_ne_zero' _]
protected theorem half_le_self : a / 2 β€ a :=
le_add_self.trans_eq <| ENNReal.add_halves _
theorem sub_half (h : a β β) : a - a / 2 = a / 2 := ENNReal.sub_eq_of_eq_add' h a.add_halves.symm
@[simp]
theorem one_sub_inv_two : (1 : ββ₯0β) - 2β»ΒΉ = 2β»ΒΉ := by
rw [β one_div, sub_half one_ne_top]
private lemma exists_lt_mul_left {a b c : ββ₯0β} (hc : c < a * b) : β a' < a, c < a' * b := by
obtain β¨a', hc, ha'β© := exists_between (ENNReal.div_lt_of_lt_mul hc)
exact β¨_, ha', (ENNReal.div_lt_iff (.inl <| by rintro rfl; simp at *)
(.inr <| by rintro rfl; simp at *)).1 hcβ©
private lemma exists_lt_mul_right {a b c : ββ₯0β} (hc : c < a * b) : β b' < b, c < a * b' := by
simp_rw [mul_comm a] at hc β’; exact exists_lt_mul_left hc
lemma mul_le_of_forall_lt {a b c : ββ₯0β} (h : β a' < a, β b' < b, a' * b' β€ c) : a * b β€ c := by
refine le_of_forall_lt_imp_le_of_dense fun d hd β¦ ?_
obtain β¨a', ha', hdβ© := exists_lt_mul_left hd
obtain β¨b', hb', hdβ© := exists_lt_mul_right hd
exact le_trans hd.le <| h _ ha' _ hb'
lemma le_mul_of_forall_lt {a b c : ββ₯0β} (hβ : a β 0 β¨ b β β) (hβ : a β β β¨ b β 0)
(h : β a' > a, β b' > b, c β€ a' * b') : c β€ a * b := by
rw [β ENNReal.inv_le_inv, ENNReal.mul_inv hβ hβ]
exact mul_le_of_forall_lt fun a' ha' b' hb' β¦ ENNReal.le_inv_iff_le_inv.1 <|
(h _ (ENNReal.lt_inv_iff_lt_inv.1 ha') _ (ENNReal.lt_inv_iff_lt_inv.1 hb')).trans_eq
(ENNReal.mul_inv (Or.inr hb'.ne_top) (Or.inl ha'.ne_top)).symm
/-- The birational order isomorphism between `ββ₯0β` and the unit interval `Set.Iic (1 : ββ₯0β)`. -/
@[simps! apply_coe]
def orderIsoIicOneBirational : ββ₯0β βo Iic (1 : ββ₯0β) := by
refine StrictMono.orderIsoOfRightInverse
(fun x => β¨(xβ»ΒΉ + 1)β»ΒΉ, ENNReal.inv_le_one.2 <| le_add_selfβ©)
(fun x y hxy => ?_) (fun x => (x.1β»ΒΉ - 1)β»ΒΉ) fun x => Subtype.ext ?_
Β· simpa only [Subtype.mk_lt_mk, ENNReal.inv_lt_inv, ENNReal.add_lt_add_iff_right one_ne_top]
Β· have : (1 : ββ₯0β) β€ x.1β»ΒΉ := ENNReal.one_le_inv.2 x.2
simp only [inv_inv, Subtype.coe_mk, tsub_add_cancel_of_le this]
@[simp]
theorem orderIsoIicOneBirational_symm_apply (x : Iic (1 : ββ₯0β)) :
orderIsoIicOneBirational.symm x = (x.1β»ΒΉ - 1)β»ΒΉ :=
rfl
/-- Order isomorphism between an initial interval in `ββ₯0β` and an initial interval in `ββ₯0`. -/
@[simps! apply_coe]
def orderIsoIicCoe (a : ββ₯0) : Iic (a : ββ₯0β) βo Iic a :=
OrderIso.symm
{ toFun := fun x => β¨x, coe_le_coe.2 x.2β©
invFun := fun x => β¨ENNReal.toNNReal x, coe_le_coe.1 <| coe_toNNReal_le_self.trans x.2β©
left_inv := fun _ => Subtype.ext <| toNNReal_coe _
right_inv := fun x => Subtype.ext <| coe_toNNReal (ne_top_of_le_ne_top coe_ne_top x.2)
map_rel_iff' := fun {_ _} => by
simp only [Equiv.coe_fn_mk, Subtype.mk_le_mk, coe_le_coe, Subtype.coe_le_coe] }
@[simp]
theorem orderIsoIicCoe_symm_apply_coe (a : ββ₯0) (b : Iic a) :
((orderIsoIicCoe a).symm b : ββ₯0β) = b :=
rfl
/-- An order isomorphism between the extended nonnegative real numbers and the unit interval. -/
def orderIsoUnitIntervalBirational : ββ₯0β βo Icc (0 : β) 1 :=
orderIsoIicOneBirational.trans <| (orderIsoIicCoe 1).trans <| (NNReal.orderIsoIccZeroCoe 1).symm
@[simp]
theorem orderIsoUnitIntervalBirational_apply_coe (x : ββ₯0β) :
(orderIsoUnitIntervalBirational x : β) = (xβ»ΒΉ + 1)β»ΒΉ.toReal :=
rfl
theorem exists_inv_nat_lt {a : ββ₯0β} (h : a β 0) : β n : β, (n : ββ₯0β)β»ΒΉ < a :=
inv_inv a βΈ by simp only [ENNReal.inv_lt_inv, ENNReal.exists_nat_gt (inv_ne_top.2 h)]
theorem exists_nat_pos_mul_gt (ha : a β 0) (hb : b β β) : β n > 0, b < (n : β) * a :=
let β¨n, hnβ© := ENNReal.exists_nat_gt (div_lt_top hb ha).ne
β¨n, Nat.cast_pos.1 ((zero_le _).trans_lt hn), by
rwa [β ENNReal.div_lt_iff (Or.inl ha) (Or.inr hb)]β©
theorem exists_nat_mul_gt (ha : a β 0) (hb : b β β) : β n : β, b < n * a :=
(exists_nat_pos_mul_gt ha hb).imp fun _ => And.right
theorem exists_nat_pos_inv_mul_lt (ha : a β β) (hb : b β 0) :
β n > 0, ((n : β) : ββ₯0β)β»ΒΉ * a < b := by
rcases exists_nat_pos_mul_gt hb ha with β¨n, npos, hnβ©
use n, npos
rw [β ENNReal.div_eq_inv_mul]
exact div_lt_of_lt_mul' hn
theorem exists_nnreal_pos_mul_lt (ha : a β β) (hb : b β 0) : β n > 0, β(n : ββ₯0) * a < b := by
rcases exists_nat_pos_inv_mul_lt ha hb with β¨n, npos : 0 < n, hnβ©
use (n : ββ₯0)β»ΒΉ
simp [*, npos.ne', zero_lt_one]
theorem exists_inv_two_pow_lt (ha : a β 0) : β n : β, 2β»ΒΉ ^ n < a := by
rcases exists_inv_nat_lt ha with β¨n, hnβ©
refine β¨n, lt_trans ?_ hnβ©
rw [β ENNReal.inv_pow, ENNReal.inv_lt_inv]
norm_cast
exact n.lt_two_pow_self
@[simp, norm_cast]
theorem coe_zpow (hr : r β 0) (n : β€) : (β(r ^ n) : ββ₯0β) = (r : ββ₯0β) ^ n := by
rcases n with n | n
Β· simp only [Int.ofNat_eq_coe, coe_pow, zpow_natCast]
Β· have : r ^ n.succ β 0 := pow_ne_zero (n + 1) hr
simp only [zpow_negSucc, coe_inv this, coe_pow]
theorem zpow_pos (ha : a β 0) (h'a : a β β) (n : β€) : 0 < a ^ n := by
cases n
Β· simpa using ENNReal.pow_pos ha.bot_lt _
Β· simp only [h'a, pow_eq_top_iff, zpow_negSucc, Ne, not_false, ENNReal.inv_pos, false_and,
not_false_eq_true]
theorem zpow_lt_top (ha : a β 0) (h'a : a β β) (n : β€) : a ^ n < β := by
cases n
Β· simpa using ENNReal.pow_lt_top h'a.lt_top
Β· simp only [ENNReal.pow_pos ha.bot_lt, zpow_negSucc, inv_lt_top]
theorem exists_mem_Ico_zpow {x y : ββ₯0β} (hx : x β 0) (h'x : x β β) (hy : 1 < y) (h'y : y β β€) :
β n : β€, x β Ico (y ^ n) (y ^ (n + 1)) := by
lift x to ββ₯0 using h'x
lift y to ββ₯0 using h'y
have A : y β 0 := by simpa only [Ne, coe_eq_zero] using (zero_lt_one.trans hy).ne'
obtain β¨n, hn, h'nβ© : β n : β€, y ^ n β€ x β§ x < y ^ (n + 1) := by
refine NNReal.exists_mem_Ico_zpow ?_ (one_lt_coe_iff.1 hy)
simpa only [Ne, coe_eq_zero] using hx
refine β¨n, ?_, ?_β©
Β· rwa [β ENNReal.coe_zpow A, ENNReal.coe_le_coe]
Β· rwa [β ENNReal.coe_zpow A, ENNReal.coe_lt_coe]
theorem exists_mem_Ioc_zpow {x y : ββ₯0β} (hx : x β 0) (h'x : x β β) (hy : 1 < y) (h'y : y β β€) :
β n : β€, x β Ioc (y ^ n) (y ^ (n + 1)) := by
lift x to ββ₯0 using h'x
lift y to ββ₯0 using h'y
have A : y β 0 := by simpa only [Ne, coe_eq_zero] using (zero_lt_one.trans hy).ne'
obtain β¨n, hn, h'nβ© : β n : β€, y ^ n < x β§ x β€ y ^ (n + 1) := by
refine NNReal.exists_mem_Ioc_zpow ?_ (one_lt_coe_iff.1 hy)
simpa only [Ne, coe_eq_zero] using hx
refine β¨n, ?_, ?_β©
Β· rwa [β ENNReal.coe_zpow A, ENNReal.coe_lt_coe]
Β· rwa [β ENNReal.coe_zpow A, ENNReal.coe_le_coe]
theorem Ioo_zero_top_eq_iUnion_Ico_zpow {y : ββ₯0β} (hy : 1 < y) (h'y : y β β€) :
Ioo (0 : ββ₯0β) (β : ββ₯0β) = β n : β€, Ico (y ^ n) (y ^ (n + 1)) := by
ext x
simp only [mem_iUnion, mem_Ioo, mem_Ico]
constructor
Β· rintro β¨hx, h'xβ©
exact exists_mem_Ico_zpow hx.ne' h'x.ne hy h'y
Β· rintro β¨n, hn, h'nβ©
constructor
Β· apply lt_of_lt_of_le _ hn
exact ENNReal.zpow_pos (zero_lt_one.trans hy).ne' h'y _
Β· apply lt_trans h'n _
exact ENNReal.zpow_lt_top (zero_lt_one.trans hy).ne' h'y _
@[gcongr]
theorem zpow_le_of_le {x : ββ₯0β} (hx : 1 β€ x) {a b : β€} (h : a β€ b) : x ^ a β€ x ^ b := by
obtain a | a := a <;> obtain b | b := b
Β· simp only [Int.ofNat_eq_coe, zpow_natCast]
exact pow_right_monoβ hx (Int.le_of_ofNat_le_ofNat h)
Β· apply absurd h (not_le_of_gt _)
exact lt_of_lt_of_le (Int.negSucc_lt_zero _) (Int.ofNat_nonneg _)
Β· simp only [zpow_negSucc, Int.ofNat_eq_coe, zpow_natCast]
refine (ENNReal.inv_le_one.2 ?_).trans ?_ <;> exact one_le_pow_of_one_le' hx _
| Β· simp only [zpow_negSucc, ENNReal.inv_le_inv]
apply pow_right_monoβ hx
simpa only [β Int.ofNat_le, neg_le_neg_iff, Int.natCast_add, Int.ofNat_one] using h
theorem monotone_zpow {x : ββ₯0β} (hx : 1 β€ x) : Monotone ((x ^ Β·) : β€ β ββ₯0β) := fun _ _ h =>
| Mathlib/Data/ENNReal/Inv.lean | 684 | 688 |
/-
Copyright (c) 2022 Joseph Myers. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Joseph Myers, Heather Macbeth
-/
import Mathlib.Analysis.InnerProductSpace.TwoDim
import Mathlib.Geometry.Euclidean.Angle.Unoriented.Basic
/-!
# Oriented angles.
This file defines oriented angles in real inner product spaces.
## Main definitions
* `Orientation.oangle` is the oriented angle between two vectors with respect to an orientation.
## Implementation notes
The definitions here use the `Real.angle` type, angles modulo `2 * Ο`. For some purposes,
angles modulo `Ο` are more convenient, because results are true for such angles with less
configuration dependence. Results that are only equalities modulo `Ο` can be represented
modulo `2 * Ο` as equalities of `(2 : β€) β’ ΞΈ`.
## References
* Evan Chen, Euclidean Geometry in Mathematical Olympiads.
-/
noncomputable section
open Module Complex
open scoped Real RealInnerProductSpace ComplexConjugate
namespace Orientation
attribute [local instance] Complex.finrank_real_complex_fact
variable {V V' : Type*}
variable [NormedAddCommGroup V] [NormedAddCommGroup V']
variable [InnerProductSpace β V] [InnerProductSpace β V']
variable [Fact (finrank β V = 2)] [Fact (finrank β V' = 2)] (o : Orientation β V (Fin 2))
local notation "Ο" => o.areaForm
/-- The oriented angle from `x` to `y`, modulo `2 * Ο`. If either vector is 0, this is 0.
See `InnerProductGeometry.angle` for the corresponding unoriented angle definition. -/
def oangle (x y : V) : Real.Angle :=
Complex.arg (o.kahler x y)
/-- Oriented angles are continuous when the vectors involved are nonzero. -/
@[fun_prop]
theorem continuousAt_oangle {x : V Γ V} (hx1 : x.1 β 0) (hx2 : x.2 β 0) :
ContinuousAt (fun y : V Γ V => o.oangle y.1 y.2) x := by
refine (Complex.continuousAt_arg_coe_angle ?_).comp ?_
Β· exact o.kahler_ne_zero hx1 hx2
exact ((continuous_ofReal.comp continuous_inner).add
((continuous_ofReal.comp o.areaForm'.continuousβ).mul continuous_const)).continuousAt
/-- If the first vector passed to `oangle` is 0, the result is 0. -/
@[simp]
theorem oangle_zero_left (x : V) : o.oangle 0 x = 0 := by simp [oangle]
/-- If the second vector passed to `oangle` is 0, the result is 0. -/
@[simp]
theorem oangle_zero_right (x : V) : o.oangle x 0 = 0 := by simp [oangle]
/-- If the two vectors passed to `oangle` are the same, the result is 0. -/
@[simp]
theorem oangle_self (x : V) : o.oangle x x = 0 := by
rw [oangle, kahler_apply_self, β ofReal_pow]
convert QuotientAddGroup.mk_zero (AddSubgroup.zmultiples (2 * Ο))
apply arg_ofReal_of_nonneg
positivity
/-- If the angle between two vectors is nonzero, the first vector is nonzero. -/
theorem left_ne_zero_of_oangle_ne_zero {x y : V} (h : o.oangle x y β 0) : x β 0 := by
rintro rfl; simp at h
/-- If the angle between two vectors is nonzero, the second vector is nonzero. -/
theorem right_ne_zero_of_oangle_ne_zero {x y : V} (h : o.oangle x y β 0) : y β 0 := by
rintro rfl; simp at h
/-- If the angle between two vectors is nonzero, the vectors are not equal. -/
theorem ne_of_oangle_ne_zero {x y : V} (h : o.oangle x y β 0) : x β y := by
rintro rfl; simp at h
/-- If the angle between two vectors is `Ο`, the first vector is nonzero. -/
theorem left_ne_zero_of_oangle_eq_pi {x y : V} (h : o.oangle x y = Ο) : x β 0 :=
o.left_ne_zero_of_oangle_ne_zero (h.symm βΈ Real.Angle.pi_ne_zero : o.oangle x y β 0)
/-- If the angle between two vectors is `Ο`, the second vector is nonzero. -/
theorem right_ne_zero_of_oangle_eq_pi {x y : V} (h : o.oangle x y = Ο) : y β 0 :=
o.right_ne_zero_of_oangle_ne_zero (h.symm βΈ Real.Angle.pi_ne_zero : o.oangle x y β 0)
/-- If the angle between two vectors is `Ο`, the vectors are not equal. -/
theorem ne_of_oangle_eq_pi {x y : V} (h : o.oangle x y = Ο) : x β y :=
o.ne_of_oangle_ne_zero (h.symm βΈ Real.Angle.pi_ne_zero : o.oangle x y β 0)
/-- If the angle between two vectors is `Ο / 2`, the first vector is nonzero. -/
theorem left_ne_zero_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = (Ο / 2 : β)) : x β 0 :=
o.left_ne_zero_of_oangle_ne_zero (h.symm βΈ Real.Angle.pi_div_two_ne_zero : o.oangle x y β 0)
/-- If the angle between two vectors is `Ο / 2`, the second vector is nonzero. -/
theorem right_ne_zero_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = (Ο / 2 : β)) : y β 0 :=
o.right_ne_zero_of_oangle_ne_zero (h.symm βΈ Real.Angle.pi_div_two_ne_zero : o.oangle x y β 0)
/-- If the angle between two vectors is `Ο / 2`, the vectors are not equal. -/
theorem ne_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = (Ο / 2 : β)) : x β y :=
o.ne_of_oangle_ne_zero (h.symm βΈ Real.Angle.pi_div_two_ne_zero : o.oangle x y β 0)
/-- If the angle between two vectors is `-Ο / 2`, the first vector is nonzero. -/
theorem left_ne_zero_of_oangle_eq_neg_pi_div_two {x y : V} (h : o.oangle x y = (-Ο / 2 : β)) :
x β 0 :=
o.left_ne_zero_of_oangle_ne_zero (h.symm βΈ Real.Angle.neg_pi_div_two_ne_zero : o.oangle x y β 0)
/-- If the angle between two vectors is `-Ο / 2`, the second vector is nonzero. -/
theorem right_ne_zero_of_oangle_eq_neg_pi_div_two {x y : V} (h : o.oangle x y = (-Ο / 2 : β)) :
y β 0 :=
o.right_ne_zero_of_oangle_ne_zero (h.symm βΈ Real.Angle.neg_pi_div_two_ne_zero : o.oangle x y β 0)
/-- If the angle between two vectors is `-Ο / 2`, the vectors are not equal. -/
theorem ne_of_oangle_eq_neg_pi_div_two {x y : V} (h : o.oangle x y = (-Ο / 2 : β)) : x β y :=
o.ne_of_oangle_ne_zero (h.symm βΈ Real.Angle.neg_pi_div_two_ne_zero : o.oangle x y β 0)
/-- If the sign of the angle between two vectors is nonzero, the first vector is nonzero. -/
theorem left_ne_zero_of_oangle_sign_ne_zero {x y : V} (h : (o.oangle x y).sign β 0) : x β 0 :=
o.left_ne_zero_of_oangle_ne_zero (Real.Angle.sign_ne_zero_iff.1 h).1
/-- If the sign of the angle between two vectors is nonzero, the second vector is nonzero. -/
theorem right_ne_zero_of_oangle_sign_ne_zero {x y : V} (h : (o.oangle x y).sign β 0) : y β 0 :=
o.right_ne_zero_of_oangle_ne_zero (Real.Angle.sign_ne_zero_iff.1 h).1
/-- If the sign of the angle between two vectors is nonzero, the vectors are not equal. -/
theorem ne_of_oangle_sign_ne_zero {x y : V} (h : (o.oangle x y).sign β 0) : x β y :=
o.ne_of_oangle_ne_zero (Real.Angle.sign_ne_zero_iff.1 h).1
/-- If the sign of the angle between two vectors is positive, the first vector is nonzero. -/
theorem left_ne_zero_of_oangle_sign_eq_one {x y : V} (h : (o.oangle x y).sign = 1) : x β 0 :=
o.left_ne_zero_of_oangle_sign_ne_zero (h.symm βΈ by decide : (o.oangle x y).sign β 0)
/-- If the sign of the angle between two vectors is positive, the second vector is nonzero. -/
theorem right_ne_zero_of_oangle_sign_eq_one {x y : V} (h : (o.oangle x y).sign = 1) : y β 0 :=
o.right_ne_zero_of_oangle_sign_ne_zero (h.symm βΈ by decide : (o.oangle x y).sign β 0)
/-- If the sign of the angle between two vectors is positive, the vectors are not equal. -/
theorem ne_of_oangle_sign_eq_one {x y : V} (h : (o.oangle x y).sign = 1) : x β y :=
o.ne_of_oangle_sign_ne_zero (h.symm βΈ by decide : (o.oangle x y).sign β 0)
/-- If the sign of the angle between two vectors is negative, the first vector is nonzero. -/
theorem left_ne_zero_of_oangle_sign_eq_neg_one {x y : V} (h : (o.oangle x y).sign = -1) : x β 0 :=
o.left_ne_zero_of_oangle_sign_ne_zero (h.symm βΈ by decide : (o.oangle x y).sign β 0)
/-- If the sign of the angle between two vectors is negative, the second vector is nonzero. -/
theorem right_ne_zero_of_oangle_sign_eq_neg_one {x y : V} (h : (o.oangle x y).sign = -1) : y β 0 :=
o.right_ne_zero_of_oangle_sign_ne_zero (h.symm βΈ by decide : (o.oangle x y).sign β 0)
/-- If the sign of the angle between two vectors is negative, the vectors are not equal. -/
theorem ne_of_oangle_sign_eq_neg_one {x y : V} (h : (o.oangle x y).sign = -1) : x β y :=
o.ne_of_oangle_sign_ne_zero (h.symm βΈ by decide : (o.oangle x y).sign β 0)
/-- Swapping the two vectors passed to `oangle` negates the angle. -/
theorem oangle_rev (x y : V) : o.oangle y x = -o.oangle x y := by
simp only [oangle, o.kahler_swap y x, Complex.arg_conj_coe_angle]
/-- Adding the angles between two vectors in each order results in 0. -/
@[simp]
theorem oangle_add_oangle_rev (x y : V) : o.oangle x y + o.oangle y x = 0 := by
simp [o.oangle_rev y x]
/-- Negating the first vector passed to `oangle` adds `Ο` to the angle. -/
theorem oangle_neg_left {x y : V} (hx : x β 0) (hy : y β 0) :
o.oangle (-x) y = o.oangle x y + Ο := by
simp only [oangle, map_neg]
convert Complex.arg_neg_coe_angle _
exact o.kahler_ne_zero hx hy
/-- Negating the second vector passed to `oangle` adds `Ο` to the angle. -/
theorem oangle_neg_right {x y : V} (hx : x β 0) (hy : y β 0) :
o.oangle x (-y) = o.oangle x y + Ο := by
simp only [oangle, map_neg]
convert Complex.arg_neg_coe_angle _
exact o.kahler_ne_zero hx hy
/-- Negating the first vector passed to `oangle` does not change twice the angle. -/
@[simp]
theorem two_zsmul_oangle_neg_left (x y : V) :
(2 : β€) β’ o.oangle (-x) y = (2 : β€) β’ o.oangle x y := by
by_cases hx : x = 0
Β· simp [hx]
Β· by_cases hy : y = 0
Β· simp [hy]
Β· simp [o.oangle_neg_left hx hy]
/-- Negating the second vector passed to `oangle` does not change twice the angle. -/
@[simp]
theorem two_zsmul_oangle_neg_right (x y : V) :
(2 : β€) β’ o.oangle x (-y) = (2 : β€) β’ o.oangle x y := by
by_cases hx : x = 0
Β· simp [hx]
Β· by_cases hy : y = 0
Β· simp [hy]
Β· simp [o.oangle_neg_right hx hy]
/-- Negating both vectors passed to `oangle` does not change the angle. -/
@[simp]
theorem oangle_neg_neg (x y : V) : o.oangle (-x) (-y) = o.oangle x y := by simp [oangle]
/-- Negating the first vector produces the same angle as negating the second vector. -/
theorem oangle_neg_left_eq_neg_right (x y : V) : o.oangle (-x) y = o.oangle x (-y) := by
rw [β neg_neg y, oangle_neg_neg, neg_neg]
/-- The angle between the negation of a nonzero vector and that vector is `Ο`. -/
@[simp]
theorem oangle_neg_self_left {x : V} (hx : x β 0) : o.oangle (-x) x = Ο := by
simp [oangle_neg_left, hx]
/-- The angle between a nonzero vector and its negation is `Ο`. -/
@[simp]
theorem oangle_neg_self_right {x : V} (hx : x β 0) : o.oangle x (-x) = Ο := by
simp [oangle_neg_right, hx]
/-- Twice the angle between the negation of a vector and that vector is 0. -/
theorem two_zsmul_oangle_neg_self_left (x : V) : (2 : β€) β’ o.oangle (-x) x = 0 := by
by_cases hx : x = 0 <;> simp [hx]
/-- Twice the angle between a vector and its negation is 0. -/
theorem two_zsmul_oangle_neg_self_right (x : V) : (2 : β€) β’ o.oangle x (-x) = 0 := by
by_cases hx : x = 0 <;> simp [hx]
/-- Adding the angles between two vectors in each order, with the first vector in each angle
negated, results in 0. -/
@[simp]
theorem oangle_add_oangle_rev_neg_left (x y : V) : o.oangle (-x) y + o.oangle (-y) x = 0 := by
rw [oangle_neg_left_eq_neg_right, oangle_rev, neg_add_cancel]
/-- Adding the angles between two vectors in each order, with the second vector in each angle
negated, results in 0. -/
@[simp]
theorem oangle_add_oangle_rev_neg_right (x y : V) : o.oangle x (-y) + o.oangle y (-x) = 0 := by
rw [o.oangle_rev (-x), oangle_neg_left_eq_neg_right, add_neg_cancel]
/-- Multiplying the first vector passed to `oangle` by a positive real does not change the
angle. -/
@[simp]
theorem oangle_smul_left_of_pos (x y : V) {r : β} (hr : 0 < r) :
o.oangle (r β’ x) y = o.oangle x y := by simp [oangle, Complex.arg_real_mul _ hr]
/-- Multiplying the second vector passed to `oangle` by a positive real does not change the
angle. -/
@[simp]
theorem oangle_smul_right_of_pos (x y : V) {r : β} (hr : 0 < r) :
o.oangle x (r β’ y) = o.oangle x y := by simp [oangle, Complex.arg_real_mul _ hr]
/-- Multiplying the first vector passed to `oangle` by a negative real produces the same angle
as negating that vector. -/
@[simp]
theorem oangle_smul_left_of_neg (x y : V) {r : β} (hr : r < 0) :
o.oangle (r β’ x) y = o.oangle (-x) y := by
rw [β neg_neg r, neg_smul, β smul_neg, o.oangle_smul_left_of_pos _ _ (neg_pos_of_neg hr)]
/-- Multiplying the second vector passed to `oangle` by a negative real produces the same angle
as negating that vector. -/
@[simp]
theorem oangle_smul_right_of_neg (x y : V) {r : β} (hr : r < 0) :
o.oangle x (r β’ y) = o.oangle x (-y) := by
rw [β neg_neg r, neg_smul, β smul_neg, o.oangle_smul_right_of_pos _ _ (neg_pos_of_neg hr)]
/-- The angle between a nonnegative multiple of a vector and that vector is 0. -/
@[simp]
theorem oangle_smul_left_self_of_nonneg (x : V) {r : β} (hr : 0 β€ r) : o.oangle (r β’ x) x = 0 := by
rcases hr.lt_or_eq with (h | h)
Β· simp [h]
Β· simp [h.symm]
/-- The angle between a vector and a nonnegative multiple of that vector is 0. -/
@[simp]
theorem oangle_smul_right_self_of_nonneg (x : V) {r : β} (hr : 0 β€ r) : o.oangle x (r β’ x) = 0 := by
rcases hr.lt_or_eq with (h | h)
Β· simp [h]
Β· simp [h.symm]
/-- The angle between two nonnegative multiples of the same vector is 0. -/
@[simp]
theorem oangle_smul_smul_self_of_nonneg (x : V) {rβ rβ : β} (hrβ : 0 β€ rβ) (hrβ : 0 β€ rβ) :
o.oangle (rβ β’ x) (rβ β’ x) = 0 := by
rcases hrβ.lt_or_eq with (h | h)
Β· simp [h, hrβ]
Β· simp [h.symm]
/-- Multiplying the first vector passed to `oangle` by a nonzero real does not change twice the
angle. -/
@[simp]
theorem two_zsmul_oangle_smul_left_of_ne_zero (x y : V) {r : β} (hr : r β 0) :
(2 : β€) β’ o.oangle (r β’ x) y = (2 : β€) β’ o.oangle x y := by
rcases hr.lt_or_lt with (h | h) <;> simp [h]
/-- Multiplying the second vector passed to `oangle` by a nonzero real does not change twice the
angle. -/
@[simp]
theorem two_zsmul_oangle_smul_right_of_ne_zero (x y : V) {r : β} (hr : r β 0) :
(2 : β€) β’ o.oangle x (r β’ y) = (2 : β€) β’ o.oangle x y := by
rcases hr.lt_or_lt with (h | h) <;> simp [h]
/-- Twice the angle between a multiple of a vector and that vector is 0. -/
@[simp]
theorem two_zsmul_oangle_smul_left_self (x : V) {r : β} : (2 : β€) β’ o.oangle (r β’ x) x = 0 := by
rcases lt_or_le r 0 with (h | h) <;> simp [h]
/-- Twice the angle between a vector and a multiple of that vector is 0. -/
@[simp]
theorem two_zsmul_oangle_smul_right_self (x : V) {r : β} : (2 : β€) β’ o.oangle x (r β’ x) = 0 := by
rcases lt_or_le r 0 with (h | h) <;> simp [h]
/-- Twice the angle between two multiples of a vector is 0. -/
@[simp]
theorem two_zsmul_oangle_smul_smul_self (x : V) {rβ rβ : β} :
(2 : β€) β’ o.oangle (rβ β’ x) (rβ β’ x) = 0 := by by_cases h : rβ = 0 <;> simp [h]
/-- If the spans of two vectors are equal, twice angles with those vectors on the left are
equal. -/
theorem two_zsmul_oangle_left_of_span_eq {x y : V} (z : V) (h : (β β x) = β β y) :
(2 : β€) β’ o.oangle x z = (2 : β€) β’ o.oangle y z := by
rw [Submodule.span_singleton_eq_span_singleton] at h
rcases h with β¨r, rflβ©
exact (o.two_zsmul_oangle_smul_left_of_ne_zero _ _ (Units.ne_zero _)).symm
/-- If the spans of two vectors are equal, twice angles with those vectors on the right are
equal. -/
theorem two_zsmul_oangle_right_of_span_eq (x : V) {y z : V} (h : (β β y) = β β z) :
(2 : β€) β’ o.oangle x y = (2 : β€) β’ o.oangle x z := by
rw [Submodule.span_singleton_eq_span_singleton] at h
rcases h with β¨r, rflβ©
exact (o.two_zsmul_oangle_smul_right_of_ne_zero _ _ (Units.ne_zero _)).symm
/-- If the spans of two pairs of vectors are equal, twice angles between those vectors are
equal. -/
theorem two_zsmul_oangle_of_span_eq_of_span_eq {w x y z : V} (hwx : (β β w) = β β x)
(hyz : (β β y) = β β z) : (2 : β€) β’ o.oangle w y = (2 : β€) β’ o.oangle x z := by
rw [o.two_zsmul_oangle_left_of_span_eq y hwx, o.two_zsmul_oangle_right_of_span_eq x hyz]
/-- The oriented angle between two vectors is zero if and only if the angle with the vectors
swapped is zero. -/
theorem oangle_eq_zero_iff_oangle_rev_eq_zero {x y : V} : o.oangle x y = 0 β o.oangle y x = 0 := by
rw [oangle_rev, neg_eq_zero]
/-- The oriented angle between two vectors is zero if and only if they are on the same ray. -/
theorem oangle_eq_zero_iff_sameRay {x y : V} : o.oangle x y = 0 β SameRay β x y := by
rw [oangle, kahler_apply_apply, Complex.arg_coe_angle_eq_iff_eq_toReal, Real.Angle.toReal_zero,
Complex.arg_eq_zero_iff]
simpa using o.nonneg_inner_and_areaForm_eq_zero_iff_sameRay x y
/-- The oriented angle between two vectors is `Ο` if and only if the angle with the vectors
swapped is `Ο`. -/
theorem oangle_eq_pi_iff_oangle_rev_eq_pi {x y : V} : o.oangle x y = Ο β o.oangle y x = Ο := by
rw [oangle_rev, neg_eq_iff_eq_neg, Real.Angle.neg_coe_pi]
/-- The oriented angle between two vectors is `Ο` if and only they are nonzero and the first is
on the same ray as the negation of the second. -/
theorem oangle_eq_pi_iff_sameRay_neg {x y : V} :
o.oangle x y = Ο β x β 0 β§ y β 0 β§ SameRay β x (-y) := by
rw [β o.oangle_eq_zero_iff_sameRay]
constructor
Β· intro h
by_cases hx : x = 0; Β· simp [hx, Real.Angle.pi_ne_zero.symm] at h
by_cases hy : y = 0; Β· simp [hy, Real.Angle.pi_ne_zero.symm] at h
refine β¨hx, hy, ?_β©
rw [o.oangle_neg_right hx hy, h, Real.Angle.coe_pi_add_coe_pi]
Β· rintro β¨hx, hy, hβ©
rwa [o.oangle_neg_right hx hy, β Real.Angle.sub_coe_pi_eq_add_coe_pi, sub_eq_zero] at h
/-- The oriented angle between two vectors is zero or `Ο` if and only if those two vectors are
not linearly independent. -/
theorem oangle_eq_zero_or_eq_pi_iff_not_linearIndependent {x y : V} :
o.oangle x y = 0 β¨ o.oangle x y = Ο β Β¬LinearIndependent β ![x, y] := by
rw [oangle_eq_zero_iff_sameRay, oangle_eq_pi_iff_sameRay_neg,
sameRay_or_ne_zero_and_sameRay_neg_iff_not_linearIndependent]
/-- The oriented angle between two vectors is zero or `Ο` if and only if the first vector is zero
or the second is a multiple of the first. -/
theorem oangle_eq_zero_or_eq_pi_iff_right_eq_smul {x y : V} :
o.oangle x y = 0 β¨ o.oangle x y = Ο β x = 0 β¨ β r : β, y = r β’ x := by
rw [oangle_eq_zero_iff_sameRay, oangle_eq_pi_iff_sameRay_neg]
refine β¨fun h => ?_, fun h => ?_β©
Β· rcases h with (h | β¨-, -, hβ©)
Β· by_cases hx : x = 0; Β· simp [hx]
obtain β¨r, -, rflβ© := h.exists_nonneg_left hx
exact Or.inr β¨r, rflβ©
Β· by_cases hx : x = 0; Β· simp [hx]
obtain β¨r, -, hyβ© := h.exists_nonneg_left hx
refine Or.inr β¨-r, ?_β©
simp [hy]
Β· rcases h with (rfl | β¨r, rflβ©); Β· simp
by_cases hx : x = 0; Β· simp [hx]
rcases lt_trichotomy r 0 with (hr | hr | hr)
Β· rw [β neg_smul]
exact Or.inr β¨hx, smul_ne_zero hr.ne hx,
SameRay.sameRay_pos_smul_right x (Left.neg_pos_iff.2 hr)β©
Β· simp [hr]
Β· exact Or.inl (SameRay.sameRay_pos_smul_right x hr)
/-- The oriented angle between two vectors is not zero or `Ο` if and only if those two vectors
are linearly independent. -/
theorem oangle_ne_zero_and_ne_pi_iff_linearIndependent {x y : V} :
o.oangle x y β 0 β§ o.oangle x y β Ο β LinearIndependent β ![x, y] := by
rw [β not_or, β not_iff_not, Classical.not_not,
oangle_eq_zero_or_eq_pi_iff_not_linearIndependent]
/-- Two vectors are equal if and only if they have equal norms and zero angle between them. -/
theorem eq_iff_norm_eq_and_oangle_eq_zero (x y : V) : x = y β βxβ = βyβ β§ o.oangle x y = 0 := by
rw [oangle_eq_zero_iff_sameRay]
constructor
Β· rintro rfl
simp; rfl
Β· rcases eq_or_ne y 0 with (rfl | hy)
Β· simp
rintro β¨hβ, hββ©
obtain β¨r, hr, rflβ© := hβ.exists_nonneg_right hy
have : βyβ β 0 := by simpa using hy
obtain rfl : r = 1 := by
apply mul_right_cancelβ this
simpa [norm_smul, abs_of_nonneg hr] using hβ
simp
/-- Two vectors with equal norms are equal if and only if they have zero angle between them. -/
theorem eq_iff_oangle_eq_zero_of_norm_eq {x y : V} (h : βxβ = βyβ) : x = y β o.oangle x y = 0 :=
β¨fun he => ((o.eq_iff_norm_eq_and_oangle_eq_zero x y).1 he).2, fun ha =>
(o.eq_iff_norm_eq_and_oangle_eq_zero x y).2 β¨h, haβ©β©
/-- Two vectors with zero angle between them are equal if and only if they have equal norms. -/
theorem eq_iff_norm_eq_of_oangle_eq_zero {x y : V} (h : o.oangle x y = 0) : x = y β βxβ = βyβ :=
β¨fun he => ((o.eq_iff_norm_eq_and_oangle_eq_zero x y).1 he).1, fun hn =>
(o.eq_iff_norm_eq_and_oangle_eq_zero x y).2 β¨hn, hβ©β©
/-- Given three nonzero vectors, the angle between the first and the second plus the angle
between the second and the third equals the angle between the first and the third. -/
@[simp]
theorem oangle_add {x y z : V} (hx : x β 0) (hy : y β 0) (hz : z β 0) :
o.oangle x y + o.oangle y z = o.oangle x z := by
simp_rw [oangle]
rw [β Complex.arg_mul_coe_angle, o.kahler_mul y x z]
Β· congr 1
exact mod_cast Complex.arg_real_mul _ (by positivity : 0 < βyβ ^ 2)
Β· exact o.kahler_ne_zero hx hy
Β· exact o.kahler_ne_zero hy hz
/-- Given three nonzero vectors, the angle between the second and the third plus the angle
between the first and the second equals the angle between the first and the third. -/
@[simp]
theorem oangle_add_swap {x y z : V} (hx : x β 0) (hy : y β 0) (hz : z β 0) :
o.oangle y z + o.oangle x y = o.oangle x z := by rw [add_comm, o.oangle_add hx hy hz]
/-- Given three nonzero vectors, the angle between the first and the third minus the angle
between the first and the second equals the angle between the second and the third. -/
@[simp]
theorem oangle_sub_left {x y z : V} (hx : x β 0) (hy : y β 0) (hz : z β 0) :
o.oangle x z - o.oangle x y = o.oangle y z := by
rw [sub_eq_iff_eq_add, o.oangle_add_swap hx hy hz]
/-- Given three nonzero vectors, the angle between the first and the third minus the angle
between the second and the third equals the angle between the first and the second. -/
@[simp]
theorem oangle_sub_right {x y z : V} (hx : x β 0) (hy : y β 0) (hz : z β 0) :
o.oangle x z - o.oangle y z = o.oangle x y := by rw [sub_eq_iff_eq_add, o.oangle_add hx hy hz]
/-- Given three nonzero vectors, adding the angles between them in cyclic order results in 0. -/
@[simp]
theorem oangle_add_cyc3 {x y z : V} (hx : x β 0) (hy : y β 0) (hz : z β 0) :
o.oangle x y + o.oangle y z + o.oangle z x = 0 := by simp [hx, hy, hz]
/-- Given three nonzero vectors, adding the angles between them in cyclic order, with the first
vector in each angle negated, results in Ο. If the vectors add to 0, this is a version of the
sum of the angles of a triangle. -/
@[simp]
theorem oangle_add_cyc3_neg_left {x y z : V} (hx : x β 0) (hy : y β 0) (hz : z β 0) :
o.oangle (-x) y + o.oangle (-y) z + o.oangle (-z) x = Ο := by
rw [o.oangle_neg_left hx hy, o.oangle_neg_left hy hz, o.oangle_neg_left hz hx,
show o.oangle x y + Ο + (o.oangle y z + Ο) + (o.oangle z x + Ο) =
o.oangle x y + o.oangle y z + o.oangle z x + (Ο + Ο + Ο : Real.Angle) by abel,
o.oangle_add_cyc3 hx hy hz, Real.Angle.coe_pi_add_coe_pi, zero_add, zero_add]
/-- Given three nonzero vectors, adding the angles between them in cyclic order, with the second
vector in each angle negated, results in Ο. If the vectors add to 0, this is a version of the
sum of the angles of a triangle. -/
@[simp]
theorem oangle_add_cyc3_neg_right {x y z : V} (hx : x β 0) (hy : y β 0) (hz : z β 0) :
o.oangle x (-y) + o.oangle y (-z) + o.oangle z (-x) = Ο := by
simp_rw [β oangle_neg_left_eq_neg_right, o.oangle_add_cyc3_neg_left hx hy hz]
/-- Pons asinorum, oriented vector angle form. -/
theorem oangle_sub_eq_oangle_sub_rev_of_norm_eq {x y : V} (h : βxβ = βyβ) :
o.oangle x (x - y) = o.oangle (y - x) y := by simp [oangle, h]
/-- The angle at the apex of an isosceles triangle is `Ο` minus twice a base angle, oriented
vector angle form. -/
theorem oangle_eq_pi_sub_two_zsmul_oangle_sub_of_norm_eq {x y : V} (hn : x β y) (h : βxβ = βyβ) :
o.oangle y x = Ο - (2 : β€) β’ o.oangle (y - x) y := by
rw [two_zsmul]
nth_rw 1 [β o.oangle_sub_eq_oangle_sub_rev_of_norm_eq h]
rw [eq_sub_iff_add_eq, β oangle_neg_neg, β add_assoc]
have hy : y β 0 := by
rintro rfl
rw [norm_zero, norm_eq_zero] at h
exact hn h
have hx : x β 0 := norm_ne_zero_iff.1 (h.symm βΈ norm_ne_zero_iff.2 hy)
convert o.oangle_add_cyc3_neg_right (neg_ne_zero.2 hy) hx (sub_ne_zero_of_ne hn.symm) using 1
simp
/-- The angle between two vectors, with respect to an orientation given by `Orientation.map`
with a linear isometric equivalence, equals the angle between those two vectors, transformed by
the inverse of that equivalence, with respect to the original orientation. -/
@[simp]
theorem oangle_map (x y : V') (f : V ββα΅’[β] V') :
(Orientation.map (Fin 2) f.toLinearEquiv o).oangle x y = o.oangle (f.symm x) (f.symm y) := by
simp [oangle, o.kahler_map]
@[simp]
protected theorem _root_.Complex.oangle (w z : β) :
Complex.orientation.oangle w z = Complex.arg (conj w * z) := by
simp [oangle, mul_comm z]
/-- The oriented angle on an oriented real inner product space of dimension 2 can be evaluated in
terms of a complex-number representation of the space. -/
theorem oangle_map_complex (f : V ββα΅’[β] β)
(hf : Orientation.map (Fin 2) f.toLinearEquiv o = Complex.orientation) (x y : V) :
o.oangle x y = Complex.arg (conj (f x) * f y) := by
rw [β Complex.oangle, β hf, o.oangle_map]
iterate 2 rw [LinearIsometryEquiv.symm_apply_apply]
/-- Negating the orientation negates the value of `oangle`. -/
theorem oangle_neg_orientation_eq_neg (x y : V) : (-o).oangle x y = -o.oangle x y := by
simp [oangle]
/-- The inner product of two vectors is the product of the norms and the cosine of the oriented
angle between the vectors. -/
theorem inner_eq_norm_mul_norm_mul_cos_oangle (x y : V) :
βͺx, yβ« = βxβ * βyβ * Real.Angle.cos (o.oangle x y) := by
by_cases hx : x = 0; Β· simp [hx]
by_cases hy : y = 0; Β· simp [hy]
rw [oangle, Real.Angle.cos_coe, Complex.cos_arg, o.norm_kahler]
Β· simp only [kahler_apply_apply, real_smul, add_re, ofReal_re, mul_re, I_re, ofReal_im]
field_simp
Β· exact o.kahler_ne_zero hx hy
/-- The cosine of the oriented angle between two nonzero vectors is the inner product divided by
the product of the norms. -/
theorem cos_oangle_eq_inner_div_norm_mul_norm {x y : V} (hx : x β 0) (hy : y β 0) :
Real.Angle.cos (o.oangle x y) = βͺx, yβ« / (βxβ * βyβ) := by
rw [o.inner_eq_norm_mul_norm_mul_cos_oangle]
field_simp [norm_ne_zero_iff.2 hx, norm_ne_zero_iff.2 hy]
/-- The cosine of the oriented angle between two nonzero vectors equals that of the unoriented
angle. -/
theorem cos_oangle_eq_cos_angle {x y : V} (hx : x β 0) (hy : y β 0) :
Real.Angle.cos (o.oangle x y) = Real.cos (InnerProductGeometry.angle x y) := by
rw [o.cos_oangle_eq_inner_div_norm_mul_norm hx hy, InnerProductGeometry.cos_angle]
/-- The oriented angle between two nonzero vectors is plus or minus the unoriented angle. -/
theorem oangle_eq_angle_or_eq_neg_angle {x y : V} (hx : x β 0) (hy : y β 0) :
o.oangle x y = InnerProductGeometry.angle x y β¨
o.oangle x y = -InnerProductGeometry.angle x y :=
Real.Angle.cos_eq_real_cos_iff_eq_or_eq_neg.1 <| o.cos_oangle_eq_cos_angle hx hy
/-- The unoriented angle between two nonzero vectors is the absolute value of the oriented angle,
converted to a real. -/
theorem angle_eq_abs_oangle_toReal {x y : V} (hx : x β 0) (hy : y β 0) :
InnerProductGeometry.angle x y = |(o.oangle x y).toReal| := by
have h0 := InnerProductGeometry.angle_nonneg x y
have hpi := InnerProductGeometry.angle_le_pi x y
rcases o.oangle_eq_angle_or_eq_neg_angle hx hy with (h | h)
Β· rw [h, eq_comm, Real.Angle.abs_toReal_coe_eq_self_iff]
exact β¨h0, hpiβ©
Β· rw [h, eq_comm, Real.Angle.abs_toReal_neg_coe_eq_self_iff]
exact β¨h0, hpiβ©
/-- If the sign of the oriented angle between two vectors is zero, either one of the vectors is
zero or the unoriented angle is 0 or Ο. -/
theorem eq_zero_or_angle_eq_zero_or_pi_of_sign_oangle_eq_zero {x y : V}
(h : (o.oangle x y).sign = 0) :
x = 0 β¨ y = 0 β¨ InnerProductGeometry.angle x y = 0 β¨ InnerProductGeometry.angle x y = Ο := by
by_cases hx : x = 0; Β· simp [hx]
by_cases hy : y = 0; Β· simp [hy]
rw [o.angle_eq_abs_oangle_toReal hx hy]
rw [Real.Angle.sign_eq_zero_iff] at h
rcases h with (h | h) <;> simp [h, Real.pi_pos.le]
/-- If two unoriented angles are equal, and the signs of the corresponding oriented angles are
equal, then the oriented angles are equal (even in degenerate cases). -/
theorem oangle_eq_of_angle_eq_of_sign_eq {w x y z : V}
(h : InnerProductGeometry.angle w x = InnerProductGeometry.angle y z)
(hs : (o.oangle w x).sign = (o.oangle y z).sign) : o.oangle w x = o.oangle y z := by
by_cases h0 : (w = 0 β¨ x = 0) β¨ y = 0 β¨ z = 0
Β· have hs' : (o.oangle w x).sign = 0 β§ (o.oangle y z).sign = 0 := by
rcases h0 with ((rfl | rfl) | rfl | rfl)
Β· simpa using hs.symm
Β· simpa using hs.symm
Β· simpa using hs
Β· simpa using hs
rcases hs' with β¨hswx, hsyzβ©
have h' : InnerProductGeometry.angle w x = Ο / 2 β§ InnerProductGeometry.angle y z = Ο / 2 := by
rcases h0 with ((rfl | rfl) | rfl | rfl)
Β· simpa using h.symm
Β· simpa using h.symm
Β· simpa using h
Β· simpa using h
rcases h' with β¨hwx, hyzβ©
have hpi : Ο / 2 β Ο := by
intro hpi
rw [div_eq_iff, eq_comm, β sub_eq_zero, mul_two, add_sub_cancel_right] at hpi
Β· exact Real.pi_pos.ne.symm hpi
Β· exact two_ne_zero
have h0wx : w = 0 β¨ x = 0 := by
have h0' := o.eq_zero_or_angle_eq_zero_or_pi_of_sign_oangle_eq_zero hswx
simpa [hwx, Real.pi_pos.ne.symm, hpi] using h0'
have h0yz : y = 0 β¨ z = 0 := by
have h0' := o.eq_zero_or_angle_eq_zero_or_pi_of_sign_oangle_eq_zero hsyz
simpa [hyz, Real.pi_pos.ne.symm, hpi] using h0'
rcases h0wx with (h0wx | h0wx) <;> rcases h0yz with (h0yz | h0yz) <;> simp [h0wx, h0yz]
Β· push_neg at h0
rw [Real.Angle.eq_iff_abs_toReal_eq_of_sign_eq hs]
rwa [o.angle_eq_abs_oangle_toReal h0.1.1 h0.1.2,
o.angle_eq_abs_oangle_toReal h0.2.1 h0.2.2] at h
/-- If the signs of two oriented angles between nonzero vectors are equal, the oriented angles are
equal if and only if the unoriented angles are equal. -/
theorem angle_eq_iff_oangle_eq_of_sign_eq {w x y z : V} (hw : w β 0) (hx : x β 0) (hy : y β 0)
(hz : z β 0) (hs : (o.oangle w x).sign = (o.oangle y z).sign) :
InnerProductGeometry.angle w x = InnerProductGeometry.angle y z β
o.oangle w x = o.oangle y z := by
refine β¨fun h => o.oangle_eq_of_angle_eq_of_sign_eq h hs, fun h => ?_β©
rw [o.angle_eq_abs_oangle_toReal hw hx, o.angle_eq_abs_oangle_toReal hy hz, h]
/-- The oriented angle between two vectors equals the unoriented angle if the sign is positive. -/
theorem oangle_eq_angle_of_sign_eq_one {x y : V} (h : (o.oangle x y).sign = 1) :
o.oangle x y = InnerProductGeometry.angle x y := by
by_cases hx : x = 0; Β· exfalso; simp [hx] at h
by_cases hy : y = 0; Β· exfalso; simp [hy] at h
refine (o.oangle_eq_angle_or_eq_neg_angle hx hy).resolve_right ?_
intro hxy
rw [hxy, Real.Angle.sign_neg, neg_eq_iff_eq_neg, β SignType.neg_iff, β not_le] at h
exact h (Real.Angle.sign_coe_nonneg_of_nonneg_of_le_pi (InnerProductGeometry.angle_nonneg _ _)
(InnerProductGeometry.angle_le_pi _ _))
/-- The oriented angle between two vectors equals minus the unoriented angle if the sign is
negative. -/
theorem oangle_eq_neg_angle_of_sign_eq_neg_one {x y : V} (h : (o.oangle x y).sign = -1) :
o.oangle x y = -InnerProductGeometry.angle x y := by
by_cases hx : x = 0; Β· exfalso; simp [hx] at h
by_cases hy : y = 0; Β· exfalso; simp [hy] at h
refine (o.oangle_eq_angle_or_eq_neg_angle hx hy).resolve_left ?_
intro hxy
rw [hxy, β SignType.neg_iff, β not_le] at h
exact h (Real.Angle.sign_coe_nonneg_of_nonneg_of_le_pi (InnerProductGeometry.angle_nonneg _ _)
(InnerProductGeometry.angle_le_pi _ _))
/-- The oriented angle between two nonzero vectors is zero if and only if the unoriented angle
is zero. -/
theorem oangle_eq_zero_iff_angle_eq_zero {x y : V} (hx : x β 0) (hy : y β 0) :
o.oangle x y = 0 β InnerProductGeometry.angle x y = 0 := by
refine β¨fun h => ?_, fun h => ?_β©
Β· simpa [o.angle_eq_abs_oangle_toReal hx hy]
Β· have ha := o.oangle_eq_angle_or_eq_neg_angle hx hy
rw [h] at ha
simpa using ha
/-- The oriented angle between two vectors is `Ο` if and only if the unoriented angle is `Ο`. -/
theorem oangle_eq_pi_iff_angle_eq_pi {x y : V} :
o.oangle x y = Ο β InnerProductGeometry.angle x y = Ο := by
by_cases hx : x = 0
Β· simp [hx, Real.Angle.pi_ne_zero.symm, div_eq_mul_inv, mul_right_eq_selfβ, not_or,
Real.pi_ne_zero]
by_cases hy : y = 0
Β· simp [hy, Real.Angle.pi_ne_zero.symm, div_eq_mul_inv, mul_right_eq_selfβ, not_or,
Real.pi_ne_zero]
refine β¨fun h => ?_, fun h => ?_β©
Β· rw [o.angle_eq_abs_oangle_toReal hx hy, h]
simp [Real.pi_pos.le]
Β· have ha := o.oangle_eq_angle_or_eq_neg_angle hx hy
rw [h] at ha
simpa using ha
/-- One of two vectors is zero or the oriented angle between them is plus or minus `Ο / 2` if
and only if the inner product of those vectors is zero. -/
theorem eq_zero_or_oangle_eq_iff_inner_eq_zero {x y : V} :
x = 0 β¨ y = 0 β¨ o.oangle x y = (Ο / 2 : β) β¨ o.oangle x y = (-Ο / 2 : β) β βͺx, yβ« = 0 := by
by_cases hx : x = 0; Β· simp [hx]
by_cases hy : y = 0; Β· simp [hy]
rw [InnerProductGeometry.inner_eq_zero_iff_angle_eq_pi_div_two, or_iff_right hx, or_iff_right hy]
refine β¨fun h => ?_, fun h => ?_β©
Β· rwa [o.angle_eq_abs_oangle_toReal hx hy, Real.Angle.abs_toReal_eq_pi_div_two_iff]
Β· convert o.oangle_eq_angle_or_eq_neg_angle hx hy using 2 <;> rw [h]
simp only [neg_div, Real.Angle.coe_neg]
/-- If the oriented angle between two vectors is `Ο / 2`, the inner product of those vectors
is zero. -/
theorem inner_eq_zero_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = (Ο / 2 : β)) :
βͺx, yβ« = 0 :=
o.eq_zero_or_oangle_eq_iff_inner_eq_zero.1 <| Or.inr <| Or.inr <| Or.inl h
/-- If the oriented angle between two vectors is `Ο / 2`, the inner product of those vectors
(reversed) is zero. -/
theorem inner_rev_eq_zero_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = (Ο / 2 : β)) :
βͺy, xβ« = 0 := by rw [real_inner_comm, o.inner_eq_zero_of_oangle_eq_pi_div_two h]
/-- If the oriented angle between two vectors is `-Ο / 2`, the inner product of those vectors
is zero. -/
theorem inner_eq_zero_of_oangle_eq_neg_pi_div_two {x y : V} (h : o.oangle x y = (-Ο / 2 : β)) :
βͺx, yβ« = 0 :=
o.eq_zero_or_oangle_eq_iff_inner_eq_zero.1 <| Or.inr <| Or.inr <| Or.inr h
/-- If the oriented angle between two vectors is `-Ο / 2`, the inner product of those vectors
(reversed) is zero. -/
theorem inner_rev_eq_zero_of_oangle_eq_neg_pi_div_two {x y : V} (h : o.oangle x y = (-Ο / 2 : β)) :
βͺy, xβ« = 0 := by rw [real_inner_comm, o.inner_eq_zero_of_oangle_eq_neg_pi_div_two h]
/-- Negating the first vector passed to `oangle` negates the sign of the angle. -/
@[simp]
theorem oangle_sign_neg_left (x y : V) : (o.oangle (-x) y).sign = -(o.oangle x y).sign := by
by_cases hx : x = 0; Β· simp [hx]
by_cases hy : y = 0; Β· simp [hy]
rw [o.oangle_neg_left hx hy, Real.Angle.sign_add_pi]
/-- Negating the second vector passed to `oangle` negates the sign of the angle. -/
@[simp]
theorem oangle_sign_neg_right (x y : V) : (o.oangle x (-y)).sign = -(o.oangle x y).sign := by
by_cases hx : x = 0; Β· simp [hx]
by_cases hy : y = 0; Β· simp [hy]
rw [o.oangle_neg_right hx hy, Real.Angle.sign_add_pi]
/-- Multiplying the first vector passed to `oangle` by a real multiplies the sign of the angle by
the sign of the real. -/
@[simp]
theorem oangle_sign_smul_left (x y : V) (r : β) :
(o.oangle (r β’ x) y).sign = SignType.sign r * (o.oangle x y).sign := by
rcases lt_trichotomy r 0 with (h | h | h) <;> simp [h]
/-- Multiplying the second vector passed to `oangle` by a real multiplies the sign of the angle by
the sign of the real. -/
@[simp]
| theorem oangle_sign_smul_right (x y : V) (r : β) :
(o.oangle x (r β’ y)).sign = SignType.sign r * (o.oangle x y).sign := by
rcases lt_trichotomy r 0 with (h | h | h) <;> simp [h]
/-- Auxiliary lemma for the proof of `oangle_sign_smul_add_right`; not intended to be used
outside of that proof. -/
theorem oangle_smul_add_right_eq_zero_or_eq_pi_iff {x y : V} (r : β) :
o.oangle x (r β’ x + y) = 0 β¨ o.oangle x (r β’ x + y) = Ο β
o.oangle x y = 0 β¨ o.oangle x y = Ο := by
| Mathlib/Geometry/Euclidean/Angle/Oriented/Basic.lean | 743 | 751 |
/-
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.ModEq
import Mathlib.Algebra.Order.Archimedean.Basic
import Mathlib.Algebra.Ring.Periodic
import Mathlib.Data.Int.SuccPred
import Mathlib.Order.Circular
/-!
# Reducing to an interval modulo its length
This file defines operations that reduce a number (in an `Archimedean`
`LinearOrderedAddCommGroup`) to a number in a given interval, modulo the length of that
interval.
## Main definitions
* `toIcoDiv hp a b` (where `hp : 0 < p`): The unique integer such that this multiple of `p`,
subtracted from `b`, is in `Ico a (a + p)`.
* `toIcoMod hp a b` (where `hp : 0 < p`): Reduce `b` to the interval `Ico a (a + p)`.
* `toIocDiv hp a b` (where `hp : 0 < p`): The unique integer such that this multiple of `p`,
subtracted from `b`, is in `Ioc a (a + p)`.
* `toIocMod hp a b` (where `hp : 0 < p`): Reduce `b` to the interval `Ioc a (a + p)`.
-/
assert_not_exists TwoSidedIdeal
noncomputable section
section LinearOrderedAddCommGroup
variable {Ξ± : Type*} [AddCommGroup Ξ±] [LinearOrder Ξ±] [IsOrderedAddMonoid Ξ±] [hΞ± : Archimedean Ξ±]
{p : Ξ±} (hp : 0 < p)
{a b c : Ξ±} {n : β€}
section
include hp
/--
The unique integer such that this multiple of `p`, subtracted from `b`, is in `Ico a (a + p)`. -/
def toIcoDiv (a b : Ξ±) : β€ :=
(existsUnique_sub_zsmul_mem_Ico hp b a).choose
theorem sub_toIcoDiv_zsmul_mem_Ico (a b : Ξ±) : b - toIcoDiv hp a b β’ p β Set.Ico a (a + p) :=
(existsUnique_sub_zsmul_mem_Ico hp b a).choose_spec.1
theorem toIcoDiv_eq_of_sub_zsmul_mem_Ico (h : b - n β’ p β Set.Ico a (a + p)) :
toIcoDiv hp a b = n :=
((existsUnique_sub_zsmul_mem_Ico hp b a).choose_spec.2 _ h).symm
/--
The unique integer such that this multiple of `p`, subtracted from `b`, is in `Ioc a (a + p)`. -/
def toIocDiv (a b : Ξ±) : β€ :=
(existsUnique_sub_zsmul_mem_Ioc hp b a).choose
theorem sub_toIocDiv_zsmul_mem_Ioc (a b : Ξ±) : b - toIocDiv hp a b β’ p β Set.Ioc a (a + p) :=
(existsUnique_sub_zsmul_mem_Ioc hp b a).choose_spec.1
theorem toIocDiv_eq_of_sub_zsmul_mem_Ioc (h : b - n β’ p β Set.Ioc a (a + p)) :
toIocDiv hp a b = n :=
((existsUnique_sub_zsmul_mem_Ioc hp b a).choose_spec.2 _ h).symm
/-- Reduce `b` to the interval `Ico a (a + p)`. -/
def toIcoMod (a b : Ξ±) : Ξ± :=
b - toIcoDiv hp a b β’ p
/-- Reduce `b` to the interval `Ioc a (a + p)`. -/
def toIocMod (a b : Ξ±) : Ξ± :=
b - toIocDiv hp a b β’ p
theorem toIcoMod_mem_Ico (a b : Ξ±) : toIcoMod hp a b β Set.Ico a (a + p) :=
sub_toIcoDiv_zsmul_mem_Ico hp a b
theorem toIcoMod_mem_Ico' (b : Ξ±) : toIcoMod hp 0 b β Set.Ico 0 p := by
convert toIcoMod_mem_Ico hp 0 b
exact (zero_add p).symm
theorem toIocMod_mem_Ioc (a b : Ξ±) : toIocMod hp a b β Set.Ioc a (a + p) :=
sub_toIocDiv_zsmul_mem_Ioc hp a b
theorem left_le_toIcoMod (a b : Ξ±) : a β€ toIcoMod hp a b :=
(Set.mem_Ico.1 (toIcoMod_mem_Ico hp a b)).1
theorem left_lt_toIocMod (a b : Ξ±) : a < toIocMod hp a b :=
(Set.mem_Ioc.1 (toIocMod_mem_Ioc hp a b)).1
theorem toIcoMod_lt_right (a b : Ξ±) : toIcoMod hp a b < a + p :=
(Set.mem_Ico.1 (toIcoMod_mem_Ico hp a b)).2
theorem toIocMod_le_right (a b : Ξ±) : toIocMod hp a b β€ a + p :=
(Set.mem_Ioc.1 (toIocMod_mem_Ioc hp a b)).2
@[simp]
theorem self_sub_toIcoDiv_zsmul (a b : Ξ±) : b - toIcoDiv hp a b β’ p = toIcoMod hp a b :=
rfl
@[simp]
theorem self_sub_toIocDiv_zsmul (a b : Ξ±) : b - toIocDiv hp a b β’ p = toIocMod hp a b :=
rfl
@[simp]
theorem toIcoDiv_zsmul_sub_self (a b : Ξ±) : toIcoDiv hp a b β’ p - b = -toIcoMod hp a b := by
rw [toIcoMod, neg_sub]
@[simp]
theorem toIocDiv_zsmul_sub_self (a b : Ξ±) : toIocDiv hp a b β’ p - b = -toIocMod hp a b := by
rw [toIocMod, neg_sub]
@[simp]
theorem toIcoMod_sub_self (a b : Ξ±) : toIcoMod hp a b - b = -toIcoDiv hp a b β’ p := by
rw [toIcoMod, sub_sub_cancel_left, neg_smul]
@[simp]
theorem toIocMod_sub_self (a b : Ξ±) : toIocMod hp a b - b = -toIocDiv hp a b β’ p := by
rw [toIocMod, sub_sub_cancel_left, neg_smul]
@[simp]
theorem self_sub_toIcoMod (a b : Ξ±) : b - toIcoMod hp a b = toIcoDiv hp a b β’ p := by
rw [toIcoMod, sub_sub_cancel]
@[simp]
theorem self_sub_toIocMod (a b : Ξ±) : b - toIocMod hp a b = toIocDiv hp a b β’ p := by
rw [toIocMod, sub_sub_cancel]
@[simp]
theorem toIcoMod_add_toIcoDiv_zsmul (a b : Ξ±) : toIcoMod hp a b + toIcoDiv hp a b β’ p = b := by
rw [toIcoMod, sub_add_cancel]
@[simp]
theorem toIocMod_add_toIocDiv_zsmul (a b : Ξ±) : toIocMod hp a b + toIocDiv hp a b β’ p = b := by
rw [toIocMod, sub_add_cancel]
@[simp]
theorem toIcoDiv_zsmul_sub_toIcoMod (a b : Ξ±) : toIcoDiv hp a b β’ p + toIcoMod hp a b = b := by
rw [add_comm, toIcoMod_add_toIcoDiv_zsmul]
@[simp]
theorem toIocDiv_zsmul_sub_toIocMod (a b : Ξ±) : toIocDiv hp a b β’ p + toIocMod hp a b = b := by
rw [add_comm, toIocMod_add_toIocDiv_zsmul]
theorem toIcoMod_eq_iff : toIcoMod hp a b = c β c β Set.Ico a (a + p) β§ β z : β€, b = c + z β’ p := by
refine
β¨fun h =>
β¨h βΈ toIcoMod_mem_Ico hp a b, toIcoDiv hp a b, h βΈ (toIcoMod_add_toIcoDiv_zsmul _ _ _).symmβ©,
?_β©
simp_rw [β @sub_eq_iff_eq_add]
rintro β¨hc, n, rflβ©
rw [β toIcoDiv_eq_of_sub_zsmul_mem_Ico hp hc, toIcoMod]
theorem toIocMod_eq_iff : toIocMod hp a b = c β c β Set.Ioc a (a + p) β§ β z : β€, b = c + z β’ p := by
refine
β¨fun h =>
β¨h βΈ toIocMod_mem_Ioc hp a b, toIocDiv hp a b, h βΈ (toIocMod_add_toIocDiv_zsmul hp _ _).symmβ©,
?_β©
simp_rw [β @sub_eq_iff_eq_add]
rintro β¨hc, n, rflβ©
rw [β toIocDiv_eq_of_sub_zsmul_mem_Ioc hp hc, toIocMod]
@[simp]
theorem toIcoDiv_apply_left (a : Ξ±) : toIcoDiv hp a a = 0 :=
toIcoDiv_eq_of_sub_zsmul_mem_Ico hp <| by simp [hp]
@[simp]
theorem toIocDiv_apply_left (a : Ξ±) : toIocDiv hp a a = -1 :=
toIocDiv_eq_of_sub_zsmul_mem_Ioc hp <| by simp [hp]
@[simp]
theorem toIcoMod_apply_left (a : Ξ±) : toIcoMod hp a a = a := by
rw [toIcoMod_eq_iff hp, Set.left_mem_Ico]
exact β¨lt_add_of_pos_right _ hp, 0, by simpβ©
@[simp]
theorem toIocMod_apply_left (a : Ξ±) : toIocMod hp a a = a + p := by
rw [toIocMod_eq_iff hp, Set.right_mem_Ioc]
exact β¨lt_add_of_pos_right _ hp, -1, by simpβ©
theorem toIcoDiv_apply_right (a : Ξ±) : toIcoDiv hp a (a + p) = 1 :=
toIcoDiv_eq_of_sub_zsmul_mem_Ico hp <| by simp [hp]
theorem toIocDiv_apply_right (a : Ξ±) : toIocDiv hp a (a + p) = 0 :=
toIocDiv_eq_of_sub_zsmul_mem_Ioc hp <| by simp [hp]
theorem toIcoMod_apply_right (a : Ξ±) : toIcoMod hp a (a + p) = a := by
rw [toIcoMod_eq_iff hp, Set.left_mem_Ico]
exact β¨lt_add_of_pos_right _ hp, 1, by simpβ©
theorem toIocMod_apply_right (a : Ξ±) : toIocMod hp a (a + p) = a + p := by
rw [toIocMod_eq_iff hp, Set.right_mem_Ioc]
exact β¨lt_add_of_pos_right _ hp, 0, by simpβ©
@[simp]
theorem toIcoDiv_add_zsmul (a b : Ξ±) (m : β€) : toIcoDiv hp a (b + m β’ p) = toIcoDiv hp a b + m :=
toIcoDiv_eq_of_sub_zsmul_mem_Ico hp <| by
simpa only [add_smul, add_sub_add_right_eq_sub] using sub_toIcoDiv_zsmul_mem_Ico hp a b
@[simp]
theorem toIcoDiv_add_zsmul' (a b : Ξ±) (m : β€) :
toIcoDiv hp (a + m β’ p) b = toIcoDiv hp a b - m := by
refine toIcoDiv_eq_of_sub_zsmul_mem_Ico _ ?_
rw [sub_smul, β sub_add, add_right_comm]
simpa using sub_toIcoDiv_zsmul_mem_Ico hp a b
@[simp]
theorem toIocDiv_add_zsmul (a b : Ξ±) (m : β€) : toIocDiv hp a (b + m β’ p) = toIocDiv hp a b + m :=
toIocDiv_eq_of_sub_zsmul_mem_Ioc hp <| by
simpa only [add_smul, add_sub_add_right_eq_sub] using sub_toIocDiv_zsmul_mem_Ioc hp a b
@[simp]
theorem toIocDiv_add_zsmul' (a b : Ξ±) (m : β€) :
toIocDiv hp (a + m β’ p) b = toIocDiv hp a b - m := by
refine toIocDiv_eq_of_sub_zsmul_mem_Ioc _ ?_
rw [sub_smul, β sub_add, add_right_comm]
simpa using sub_toIocDiv_zsmul_mem_Ioc hp a b
@[simp]
theorem toIcoDiv_zsmul_add (a b : Ξ±) (m : β€) : toIcoDiv hp a (m β’ p + b) = m + toIcoDiv hp a b := by
rw [add_comm, toIcoDiv_add_zsmul, add_comm]
/-! Note we omit `toIcoDiv_zsmul_add'` as `-m + toIcoDiv hp a b` is not very convenient. -/
@[simp]
theorem toIocDiv_zsmul_add (a b : Ξ±) (m : β€) : toIocDiv hp a (m β’ p + b) = m + toIocDiv hp a b := by
rw [add_comm, toIocDiv_add_zsmul, add_comm]
/-! Note we omit `toIocDiv_zsmul_add'` as `-m + toIocDiv hp a b` is not very convenient. -/
@[simp]
theorem toIcoDiv_sub_zsmul (a b : Ξ±) (m : β€) : toIcoDiv hp a (b - m β’ p) = toIcoDiv hp a b - m := by
rw [sub_eq_add_neg, β neg_smul, toIcoDiv_add_zsmul, sub_eq_add_neg]
@[simp]
theorem toIcoDiv_sub_zsmul' (a b : Ξ±) (m : β€) :
toIcoDiv hp (a - m β’ p) b = toIcoDiv hp a b + m := by
rw [sub_eq_add_neg, β neg_smul, toIcoDiv_add_zsmul', sub_neg_eq_add]
@[simp]
theorem toIocDiv_sub_zsmul (a b : Ξ±) (m : β€) : toIocDiv hp a (b - m β’ p) = toIocDiv hp a b - m := by
rw [sub_eq_add_neg, β neg_smul, toIocDiv_add_zsmul, sub_eq_add_neg]
@[simp]
theorem toIocDiv_sub_zsmul' (a b : Ξ±) (m : β€) :
toIocDiv hp (a - m β’ p) b = toIocDiv hp a b + m := by
rw [sub_eq_add_neg, β neg_smul, toIocDiv_add_zsmul', sub_neg_eq_add]
@[simp]
theorem toIcoDiv_add_right (a b : Ξ±) : toIcoDiv hp a (b + p) = toIcoDiv hp a b + 1 := by
simpa only [one_zsmul] using toIcoDiv_add_zsmul hp a b 1
@[simp]
theorem toIcoDiv_add_right' (a b : Ξ±) : toIcoDiv hp (a + p) b = toIcoDiv hp a b - 1 := by
simpa only [one_zsmul] using toIcoDiv_add_zsmul' hp a b 1
@[simp]
theorem toIocDiv_add_right (a b : Ξ±) : toIocDiv hp a (b + p) = toIocDiv hp a b + 1 := by
simpa only [one_zsmul] using toIocDiv_add_zsmul hp a b 1
@[simp]
theorem toIocDiv_add_right' (a b : Ξ±) : toIocDiv hp (a + p) b = toIocDiv hp a b - 1 := by
simpa only [one_zsmul] using toIocDiv_add_zsmul' hp a b 1
@[simp]
theorem toIcoDiv_add_left (a b : Ξ±) : toIcoDiv hp a (p + b) = toIcoDiv hp a b + 1 := by
rw [add_comm, toIcoDiv_add_right]
@[simp]
theorem toIcoDiv_add_left' (a b : Ξ±) : toIcoDiv hp (p + a) b = toIcoDiv hp a b - 1 := by
rw [add_comm, toIcoDiv_add_right']
@[simp]
theorem toIocDiv_add_left (a b : Ξ±) : toIocDiv hp a (p + b) = toIocDiv hp a b + 1 := by
rw [add_comm, toIocDiv_add_right]
@[simp]
theorem toIocDiv_add_left' (a b : Ξ±) : toIocDiv hp (p + a) b = toIocDiv hp a b - 1 := by
rw [add_comm, toIocDiv_add_right']
@[simp]
theorem toIcoDiv_sub (a b : Ξ±) : toIcoDiv hp a (b - p) = toIcoDiv hp a b - 1 := by
simpa only [one_zsmul] using toIcoDiv_sub_zsmul hp a b 1
@[simp]
theorem toIcoDiv_sub' (a b : Ξ±) : toIcoDiv hp (a - p) b = toIcoDiv hp a b + 1 := by
simpa only [one_zsmul] using toIcoDiv_sub_zsmul' hp a b 1
@[simp]
theorem toIocDiv_sub (a b : Ξ±) : toIocDiv hp a (b - p) = toIocDiv hp a b - 1 := by
simpa only [one_zsmul] using toIocDiv_sub_zsmul hp a b 1
@[simp]
theorem toIocDiv_sub' (a b : Ξ±) : toIocDiv hp (a - p) b = toIocDiv hp a b + 1 := by
simpa only [one_zsmul] using toIocDiv_sub_zsmul' hp a b 1
theorem toIcoDiv_sub_eq_toIcoDiv_add (a b c : Ξ±) :
toIcoDiv hp a (b - c) = toIcoDiv hp (a + c) b := by
apply toIcoDiv_eq_of_sub_zsmul_mem_Ico
rw [β sub_right_comm, Set.sub_mem_Ico_iff_left, add_right_comm]
exact sub_toIcoDiv_zsmul_mem_Ico hp (a + c) b
theorem toIocDiv_sub_eq_toIocDiv_add (a b c : Ξ±) :
toIocDiv hp a (b - c) = toIocDiv hp (a + c) b := by
apply toIocDiv_eq_of_sub_zsmul_mem_Ioc
rw [β sub_right_comm, Set.sub_mem_Ioc_iff_left, add_right_comm]
exact sub_toIocDiv_zsmul_mem_Ioc hp (a + c) b
theorem toIcoDiv_sub_eq_toIcoDiv_add' (a b c : Ξ±) :
toIcoDiv hp (a - c) b = toIcoDiv hp a (b + c) := by
rw [β sub_neg_eq_add, toIcoDiv_sub_eq_toIcoDiv_add, sub_eq_add_neg]
theorem toIocDiv_sub_eq_toIocDiv_add' (a b c : Ξ±) :
toIocDiv hp (a - c) b = toIocDiv hp a (b + c) := by
rw [β sub_neg_eq_add, toIocDiv_sub_eq_toIocDiv_add, sub_eq_add_neg]
theorem toIcoDiv_neg (a b : Ξ±) : toIcoDiv hp a (-b) = -(toIocDiv hp (-a) b + 1) := by
suffices toIcoDiv hp a (-b) = -toIocDiv hp (-(a + p)) b by
rwa [neg_add, β sub_eq_add_neg, toIocDiv_sub_eq_toIocDiv_add', toIocDiv_add_right] at this
rw [β neg_eq_iff_eq_neg, eq_comm]
apply toIocDiv_eq_of_sub_zsmul_mem_Ioc
obtain β¨hc, hoβ© := sub_toIcoDiv_zsmul_mem_Ico hp a (-b)
rw [β neg_lt_neg_iff, neg_sub' (-b), neg_neg, β neg_smul] at ho
rw [β neg_le_neg_iff, neg_sub' (-b), neg_neg, β neg_smul] at hc
refine β¨ho, hc.trans_eq ?_β©
rw [neg_add, neg_add_cancel_right]
theorem toIcoDiv_neg' (a b : Ξ±) : toIcoDiv hp (-a) b = -(toIocDiv hp a (-b) + 1) := by
simpa only [neg_neg] using toIcoDiv_neg hp (-a) (-b)
theorem toIocDiv_neg (a b : Ξ±) : toIocDiv hp a (-b) = -(toIcoDiv hp (-a) b + 1) := by
rw [β neg_neg b, toIcoDiv_neg, neg_neg, neg_neg, neg_add', neg_neg, add_sub_cancel_right]
theorem toIocDiv_neg' (a b : Ξ±) : toIocDiv hp (-a) b = -(toIcoDiv hp a (-b) + 1) := by
simpa only [neg_neg] using toIocDiv_neg hp (-a) (-b)
@[simp]
theorem toIcoMod_add_zsmul (a b : Ξ±) (m : β€) : toIcoMod hp a (b + m β’ p) = toIcoMod hp a b := by
rw [toIcoMod, toIcoDiv_add_zsmul, toIcoMod, add_smul]
abel
@[simp]
theorem toIcoMod_add_zsmul' (a b : Ξ±) (m : β€) :
toIcoMod hp (a + m β’ p) b = toIcoMod hp a b + m β’ p := by
simp only [toIcoMod, toIcoDiv_add_zsmul', sub_smul, sub_add]
@[simp]
theorem toIocMod_add_zsmul (a b : Ξ±) (m : β€) : toIocMod hp a (b + m β’ p) = toIocMod hp a b := by
rw [toIocMod, toIocDiv_add_zsmul, toIocMod, add_smul]
abel
@[simp]
theorem toIocMod_add_zsmul' (a b : Ξ±) (m : β€) :
toIocMod hp (a + m β’ p) b = toIocMod hp a b + m β’ p := by
simp only [toIocMod, toIocDiv_add_zsmul', sub_smul, sub_add]
@[simp]
theorem toIcoMod_zsmul_add (a b : Ξ±) (m : β€) : toIcoMod hp a (m β’ p + b) = toIcoMod hp a b := by
rw [add_comm, toIcoMod_add_zsmul]
@[simp]
theorem toIcoMod_zsmul_add' (a b : Ξ±) (m : β€) :
toIcoMod hp (m β’ p + a) b = m β’ p + toIcoMod hp a b := by
rw [add_comm, toIcoMod_add_zsmul', add_comm]
@[simp]
theorem toIocMod_zsmul_add (a b : Ξ±) (m : β€) : toIocMod hp a (m β’ p + b) = toIocMod hp a b := by
rw [add_comm, toIocMod_add_zsmul]
@[simp]
theorem toIocMod_zsmul_add' (a b : Ξ±) (m : β€) :
toIocMod hp (m β’ p + a) b = m β’ p + toIocMod hp a b := by
rw [add_comm, toIocMod_add_zsmul', add_comm]
@[simp]
theorem toIcoMod_sub_zsmul (a b : Ξ±) (m : β€) : toIcoMod hp a (b - m β’ p) = toIcoMod hp a b := by
rw [sub_eq_add_neg, β neg_smul, toIcoMod_add_zsmul]
@[simp]
theorem toIcoMod_sub_zsmul' (a b : Ξ±) (m : β€) :
toIcoMod hp (a - m β’ p) b = toIcoMod hp a b - m β’ p := by
simp_rw [sub_eq_add_neg, β neg_smul, toIcoMod_add_zsmul']
@[simp]
theorem toIocMod_sub_zsmul (a b : Ξ±) (m : β€) : toIocMod hp a (b - m β’ p) = toIocMod hp a b := by
rw [sub_eq_add_neg, β neg_smul, toIocMod_add_zsmul]
@[simp]
theorem toIocMod_sub_zsmul' (a b : Ξ±) (m : β€) :
toIocMod hp (a - m β’ p) b = toIocMod hp a b - m β’ p := by
simp_rw [sub_eq_add_neg, β neg_smul, toIocMod_add_zsmul']
@[simp]
theorem toIcoMod_add_right (a b : Ξ±) : toIcoMod hp a (b + p) = toIcoMod hp a b := by
simpa only [one_zsmul] using toIcoMod_add_zsmul hp a b 1
@[simp]
theorem toIcoMod_add_right' (a b : Ξ±) : toIcoMod hp (a + p) b = toIcoMod hp a b + p := by
simpa only [one_zsmul] using toIcoMod_add_zsmul' hp a b 1
@[simp]
theorem toIocMod_add_right (a b : Ξ±) : toIocMod hp a (b + p) = toIocMod hp a b := by
simpa only [one_zsmul] using toIocMod_add_zsmul hp a b 1
@[simp]
theorem toIocMod_add_right' (a b : Ξ±) : toIocMod hp (a + p) b = toIocMod hp a b + p := by
simpa only [one_zsmul] using toIocMod_add_zsmul' hp a b 1
@[simp]
theorem toIcoMod_add_left (a b : Ξ±) : toIcoMod hp a (p + b) = toIcoMod hp a b := by
rw [add_comm, toIcoMod_add_right]
@[simp]
theorem toIcoMod_add_left' (a b : Ξ±) : toIcoMod hp (p + a) b = p + toIcoMod hp a b := by
rw [add_comm, toIcoMod_add_right', add_comm]
@[simp]
theorem toIocMod_add_left (a b : Ξ±) : toIocMod hp a (p + b) = toIocMod hp a b := by
rw [add_comm, toIocMod_add_right]
@[simp]
theorem toIocMod_add_left' (a b : Ξ±) : toIocMod hp (p + a) b = p + toIocMod hp a b := by
rw [add_comm, toIocMod_add_right', add_comm]
@[simp]
theorem toIcoMod_sub (a b : Ξ±) : toIcoMod hp a (b - p) = toIcoMod hp a b := by
simpa only [one_zsmul] using toIcoMod_sub_zsmul hp a b 1
@[simp]
theorem toIcoMod_sub' (a b : Ξ±) : toIcoMod hp (a - p) b = toIcoMod hp a b - p := by
simpa only [one_zsmul] using toIcoMod_sub_zsmul' hp a b 1
@[simp]
theorem toIocMod_sub (a b : Ξ±) : toIocMod hp a (b - p) = toIocMod hp a b := by
simpa only [one_zsmul] using toIocMod_sub_zsmul hp a b 1
@[simp]
theorem toIocMod_sub' (a b : Ξ±) : toIocMod hp (a - p) b = toIocMod hp a b - p := by
simpa only [one_zsmul] using toIocMod_sub_zsmul' hp a b 1
theorem toIcoMod_sub_eq_sub (a b c : Ξ±) : toIcoMod hp a (b - c) = toIcoMod hp (a + c) b - c := by
simp_rw [toIcoMod, toIcoDiv_sub_eq_toIcoDiv_add, sub_right_comm]
theorem toIocMod_sub_eq_sub (a b c : Ξ±) : toIocMod hp a (b - c) = toIocMod hp (a + c) b - c := by
simp_rw [toIocMod, toIocDiv_sub_eq_toIocDiv_add, sub_right_comm]
theorem toIcoMod_add_right_eq_add (a b c : Ξ±) :
toIcoMod hp a (b + c) = toIcoMod hp (a - c) b + c := by
simp_rw [toIcoMod, toIcoDiv_sub_eq_toIcoDiv_add', sub_add_eq_add_sub]
theorem toIocMod_add_right_eq_add (a b c : Ξ±) :
toIocMod hp a (b + c) = toIocMod hp (a - c) b + c := by
simp_rw [toIocMod, toIocDiv_sub_eq_toIocDiv_add', sub_add_eq_add_sub]
theorem toIcoMod_neg (a b : Ξ±) : toIcoMod hp a (-b) = p - toIocMod hp (-a) b := by
simp_rw [toIcoMod, toIocMod, toIcoDiv_neg, neg_smul, add_smul]
abel
theorem toIcoMod_neg' (a b : Ξ±) : toIcoMod hp (-a) b = p - toIocMod hp a (-b) := by
simpa only [neg_neg] using toIcoMod_neg hp (-a) (-b)
theorem toIocMod_neg (a b : Ξ±) : toIocMod hp a (-b) = p - toIcoMod hp (-a) b := by
simp_rw [toIocMod, toIcoMod, toIocDiv_neg, neg_smul, add_smul]
abel
theorem toIocMod_neg' (a b : Ξ±) : toIocMod hp (-a) b = p - toIcoMod hp a (-b) := by
simpa only [neg_neg] using toIocMod_neg hp (-a) (-b)
theorem toIcoMod_eq_toIcoMod : toIcoMod hp a b = toIcoMod hp a c β β n : β€, c - b = n β’ p := by
refine β¨fun h => β¨toIcoDiv hp a c - toIcoDiv hp a b, ?_β©, fun h => ?_β©
Β· conv_lhs => rw [β toIcoMod_add_toIcoDiv_zsmul hp a b, β toIcoMod_add_toIcoDiv_zsmul hp a c]
rw [h, sub_smul]
abel
Β· rcases h with β¨z, hzβ©
rw [sub_eq_iff_eq_add] at hz
rw [hz, toIcoMod_zsmul_add]
theorem toIocMod_eq_toIocMod : toIocMod hp a b = toIocMod hp a c β β n : β€, c - b = n β’ p := by
refine β¨fun h => β¨toIocDiv hp a c - toIocDiv hp a b, ?_β©, fun h => ?_β©
Β· conv_lhs => rw [β toIocMod_add_toIocDiv_zsmul hp a b, β toIocMod_add_toIocDiv_zsmul hp a c]
rw [h, sub_smul]
abel
Β· rcases h with β¨z, hzβ©
rw [sub_eq_iff_eq_add] at hz
rw [hz, toIocMod_zsmul_add]
/-! ### Links between the `Ico` and `Ioc` variants applied to the same element -/
section IcoIoc
namespace AddCommGroup
theorem modEq_iff_toIcoMod_eq_left : a β‘ b [PMOD p] β toIcoMod hp a b = a :=
modEq_iff_eq_add_zsmul.trans
β¨by
rintro β¨n, rflβ©
rw [toIcoMod_add_zsmul, toIcoMod_apply_left], fun h => β¨toIcoDiv hp a b, eq_add_of_sub_eq hβ©β©
theorem modEq_iff_toIocMod_eq_right : a β‘ b [PMOD p] β toIocMod hp a b = a + p := by
refine modEq_iff_eq_add_zsmul.trans β¨?_, fun h => β¨toIocDiv hp a b + 1, ?_β©β©
Β· rintro β¨z, rflβ©
rw [toIocMod_add_zsmul, toIocMod_apply_left]
Β· rwa [add_one_zsmul, add_left_comm, β sub_eq_iff_eq_add']
alias β¨ModEq.toIcoMod_eq_left, _β© := modEq_iff_toIcoMod_eq_left
alias β¨ModEq.toIcoMod_eq_right, _β© := modEq_iff_toIocMod_eq_right
variable (a b)
open List in
theorem tfae_modEq :
TFAE
[a β‘ b [PMOD p], β z : β€, b - z β’ p β Set.Ioo a (a + p), toIcoMod hp a b β toIocMod hp a b,
toIcoMod hp a b + p = toIocMod hp a b] := by
rw [modEq_iff_toIcoMod_eq_left hp]
tfae_have 3 β 2 := by
rw [β not_exists, not_imp_not]
exact fun β¨i, hiβ© =>
((toIcoMod_eq_iff hp).2 β¨Set.Ioo_subset_Ico_self hi, i, (sub_add_cancel b _).symmβ©).trans
((toIocMod_eq_iff hp).2 β¨Set.Ioo_subset_Ioc_self hi, i, (sub_add_cancel b _).symmβ©).symm
tfae_have 4 β 3
| h => by
rw [β h, Ne, eq_comm, add_eq_left]
exact hp.ne'
tfae_have 1 β 4
| h => by
rw [h, eq_comm, toIocMod_eq_iff, Set.right_mem_Ioc]
refine β¨lt_add_of_pos_right a hp, toIcoDiv hp a b - 1, ?_β©
rw [sub_one_zsmul, add_add_add_comm, add_neg_cancel, add_zero]
conv_lhs => rw [β toIcoMod_add_toIcoDiv_zsmul hp a b, h]
tfae_have 2 β 1 := by
rw [β not_exists, not_imp_comm]
have h' := toIcoMod_mem_Ico hp a b
exact fun h => β¨_, h'.1.lt_of_ne' h, h'.2β©
tfae_finish
variable {a b}
theorem modEq_iff_not_forall_mem_Ioo_mod :
a β‘ b [PMOD p] β β z : β€, b - z β’ p β Set.Ioo a (a + p) :=
(tfae_modEq hp a b).out 0 1
theorem modEq_iff_toIcoMod_ne_toIocMod : a β‘ b [PMOD p] β toIcoMod hp a b β toIocMod hp a b :=
(tfae_modEq hp a b).out 0 2
theorem modEq_iff_toIcoMod_add_period_eq_toIocMod :
a β‘ b [PMOD p] β toIcoMod hp a b + p = toIocMod hp a b :=
(tfae_modEq hp a b).out 0 3
theorem not_modEq_iff_toIcoMod_eq_toIocMod : Β¬a β‘ b [PMOD p] β toIcoMod hp a b = toIocMod hp a b :=
(modEq_iff_toIcoMod_ne_toIocMod _).not_left
theorem not_modEq_iff_toIcoDiv_eq_toIocDiv :
Β¬a β‘ b [PMOD p] β toIcoDiv hp a b = toIocDiv hp a b := by
rw [not_modEq_iff_toIcoMod_eq_toIocMod hp, toIcoMod, toIocMod, sub_right_inj,
zsmul_left_inj hp]
theorem modEq_iff_toIcoDiv_eq_toIocDiv_add_one :
a β‘ b [PMOD p] β toIcoDiv hp a b = toIocDiv hp a b + 1 := by
rw [modEq_iff_toIcoMod_add_period_eq_toIocMod hp, toIcoMod, toIocMod, β eq_sub_iff_add_eq,
sub_sub, sub_right_inj, β add_one_zsmul, zsmul_left_inj hp]
end AddCommGroup
open AddCommGroup
/-- If `a` and `b` fall within the same cycle WRT `c`, then they are congruent modulo `p`. -/
@[simp]
theorem toIcoMod_inj {c : Ξ±} : toIcoMod hp c a = toIcoMod hp c b β a β‘ b [PMOD p] := by
simp_rw [toIcoMod_eq_toIcoMod, modEq_iff_eq_add_zsmul, sub_eq_iff_eq_add']
alias β¨_, AddCommGroup.ModEq.toIcoMod_eq_toIcoModβ© := toIcoMod_inj
theorem Ico_eq_locus_Ioc_eq_iUnion_Ioo :
{ b | toIcoMod hp a b = toIocMod hp a b } = β z : β€, Set.Ioo (a + z β’ p) (a + p + z β’ p) := by
ext1
simp_rw [Set.mem_setOf, Set.mem_iUnion, β Set.sub_mem_Ioo_iff_left, β
not_modEq_iff_toIcoMod_eq_toIocMod, modEq_iff_not_forall_mem_Ioo_mod hp, not_forall,
Classical.not_not]
theorem toIocDiv_wcovBy_toIcoDiv (a b : Ξ±) : toIocDiv hp a b β©Ώ toIcoDiv hp a b := by
suffices toIocDiv hp a b = toIcoDiv hp a b β¨ toIocDiv hp a b + 1 = toIcoDiv hp a b by
rwa [wcovBy_iff_eq_or_covBy, β Order.succ_eq_iff_covBy]
rw [eq_comm, β not_modEq_iff_toIcoDiv_eq_toIocDiv, eq_comm, β
modEq_iff_toIcoDiv_eq_toIocDiv_add_one]
exact em' _
theorem toIcoMod_le_toIocMod (a b : Ξ±) : toIcoMod hp a b β€ toIocMod hp a b := by
rw [toIcoMod, toIocMod, sub_le_sub_iff_left]
exact zsmul_left_mono hp.le (toIocDiv_wcovBy_toIcoDiv _ _ _).le
theorem toIocMod_le_toIcoMod_add (a b : Ξ±) : toIocMod hp a b β€ toIcoMod hp a b + p := by
rw [toIcoMod, toIocMod, sub_add, sub_le_sub_iff_left, sub_le_iff_le_add, β add_one_zsmul,
(zsmul_left_strictMono hp).le_iff_le]
apply (toIocDiv_wcovBy_toIcoDiv _ _ _).le_succ
end IcoIoc
open AddCommGroup
theorem toIcoMod_eq_self : toIcoMod hp a b = b β b β Set.Ico a (a + p) := by
rw [toIcoMod_eq_iff, and_iff_left]
exact β¨0, by simpβ©
theorem toIocMod_eq_self : toIocMod hp a b = b β b β Set.Ioc a (a + p) := by
rw [toIocMod_eq_iff, and_iff_left]
exact β¨0, by simpβ©
@[simp]
theorem toIcoMod_toIcoMod (aβ aβ b : Ξ±) : toIcoMod hp aβ (toIcoMod hp aβ b) = toIcoMod hp aβ b :=
(toIcoMod_eq_toIcoMod _).2 β¨toIcoDiv hp aβ b, self_sub_toIcoMod hp aβ bβ©
@[simp]
theorem toIcoMod_toIocMod (aβ aβ b : Ξ±) : toIcoMod hp aβ (toIocMod hp aβ b) = toIcoMod hp aβ b :=
(toIcoMod_eq_toIcoMod _).2 β¨toIocDiv hp aβ b, self_sub_toIocMod hp aβ bβ©
@[simp]
theorem toIocMod_toIocMod (aβ aβ b : Ξ±) : toIocMod hp aβ (toIocMod hp aβ b) = toIocMod hp aβ b :=
(toIocMod_eq_toIocMod _).2 β¨toIocDiv hp aβ b, self_sub_toIocMod hp aβ bβ©
@[simp]
theorem toIocMod_toIcoMod (aβ aβ b : Ξ±) : toIocMod hp aβ (toIcoMod hp aβ b) = toIocMod hp aβ b :=
(toIocMod_eq_toIocMod _).2 β¨toIcoDiv hp aβ b, self_sub_toIcoMod hp aβ bβ©
theorem toIcoMod_periodic (a : Ξ±) : Function.Periodic (toIcoMod hp a) p :=
toIcoMod_add_right hp a
theorem toIocMod_periodic (a : Ξ±) : Function.Periodic (toIocMod hp a) p :=
toIocMod_add_right hp a
-- helper lemmas for when `a = 0`
section Zero
theorem toIcoMod_zero_sub_comm (a b : Ξ±) : toIcoMod hp 0 (a - b) = p - toIocMod hp 0 (b - a) := by
rw [β neg_sub, toIcoMod_neg, neg_zero]
theorem toIocMod_zero_sub_comm (a b : Ξ±) : toIocMod hp 0 (a - b) = p - toIcoMod hp 0 (b - a) := by
rw [β neg_sub, toIocMod_neg, neg_zero]
theorem toIcoDiv_eq_sub (a b : Ξ±) : toIcoDiv hp a b = toIcoDiv hp 0 (b - a) := by
rw [toIcoDiv_sub_eq_toIcoDiv_add, zero_add]
theorem toIocDiv_eq_sub (a b : Ξ±) : toIocDiv hp a b = toIocDiv hp 0 (b - a) := by
rw [toIocDiv_sub_eq_toIocDiv_add, zero_add]
theorem toIcoMod_eq_sub (a b : Ξ±) : toIcoMod hp a b = toIcoMod hp 0 (b - a) + a := by
rw [toIcoMod_sub_eq_sub, zero_add, sub_add_cancel]
theorem toIocMod_eq_sub (a b : Ξ±) : toIocMod hp a b = toIocMod hp 0 (b - a) + a := by
rw [toIocMod_sub_eq_sub, zero_add, sub_add_cancel]
theorem toIcoMod_add_toIocMod_zero (a b : Ξ±) :
toIcoMod hp 0 (a - b) + toIocMod hp 0 (b - a) = p := by
rw [toIcoMod_zero_sub_comm, sub_add_cancel]
theorem toIocMod_add_toIcoMod_zero (a b : Ξ±) :
toIocMod hp 0 (a - b) + toIcoMod hp 0 (b - a) = p := by
rw [_root_.add_comm, toIcoMod_add_toIocMod_zero]
end Zero
/-- `toIcoMod` as an equiv from the quotient. -/
@[simps symm_apply]
def QuotientAddGroup.equivIcoMod (a : Ξ±) : Ξ± β§Έ AddSubgroup.zmultiples p β Set.Ico a (a + p) where
toFun b :=
β¨(toIcoMod_periodic hp a).lift b, QuotientAddGroup.induction_on b <| toIcoMod_mem_Ico hp aβ©
invFun := (β)
right_inv b := Subtype.ext <| (toIcoMod_eq_self hp).mpr b.prop
left_inv b := by
induction b using QuotientAddGroup.induction_on
dsimp
rw [QuotientAddGroup.eq_iff_sub_mem, toIcoMod_sub_self]
apply AddSubgroup.zsmul_mem_zmultiples
@[simp]
theorem QuotientAddGroup.equivIcoMod_coe (a b : Ξ±) :
QuotientAddGroup.equivIcoMod hp a βb = β¨toIcoMod hp a b, toIcoMod_mem_Ico hp a _β© :=
rfl
@[simp]
theorem QuotientAddGroup.equivIcoMod_zero (a : Ξ±) :
QuotientAddGroup.equivIcoMod hp a 0 = β¨toIcoMod hp a 0, toIcoMod_mem_Ico hp a _β© :=
rfl
/-- `toIocMod` as an equiv from the quotient. -/
@[simps symm_apply]
def QuotientAddGroup.equivIocMod (a : Ξ±) : Ξ± β§Έ AddSubgroup.zmultiples p β Set.Ioc a (a + p) where
toFun b :=
β¨(toIocMod_periodic hp a).lift b, QuotientAddGroup.induction_on b <| toIocMod_mem_Ioc hp aβ©
invFun := (β)
right_inv b := Subtype.ext <| (toIocMod_eq_self hp).mpr b.prop
left_inv b := by
induction b using QuotientAddGroup.induction_on
dsimp
rw [QuotientAddGroup.eq_iff_sub_mem, toIocMod_sub_self]
apply AddSubgroup.zsmul_mem_zmultiples
@[simp]
theorem QuotientAddGroup.equivIocMod_coe (a b : Ξ±) :
QuotientAddGroup.equivIocMod hp a βb = β¨toIocMod hp a b, toIocMod_mem_Ioc hp a _β© :=
rfl
@[simp]
theorem QuotientAddGroup.equivIocMod_zero (a : Ξ±) :
QuotientAddGroup.equivIocMod hp a 0 = β¨toIocMod hp a 0, toIocMod_mem_Ioc hp a _β© :=
rfl
end
/-!
### The circular order structure on `Ξ± β§Έ AddSubgroup.zmultiples p`
-/
section Circular
open AddCommGroup
private theorem toIxxMod_iff (xβ xβ xβ : Ξ±) : toIcoMod hp xβ xβ β€ toIocMod hp xβ xβ β
toIcoMod hp 0 (xβ - xβ) + toIcoMod hp 0 (xβ - xβ) β€ p := by
rw [toIcoMod_eq_sub, toIocMod_eq_sub _ xβ, add_le_add_iff_right, β neg_sub xβ xβ, toIocMod_neg,
neg_zero, le_sub_iff_add_le]
private theorem toIxxMod_cyclic_left {xβ xβ xβ : Ξ±} (h : toIcoMod hp xβ xβ β€ toIocMod hp xβ xβ) :
toIcoMod hp xβ xβ β€ toIocMod hp xβ xβ := by
let xβ' := toIcoMod hp xβ xβ
let xβ' := toIcoMod hp xβ' xβ
have h : xβ' β€ toIocMod hp xβ xβ' := by simpa [xβ']
have hββ : xβ' < xβ + p := toIcoMod_lt_right _ _ _
have hββ : xβ' - p < xβ' := sub_lt_iff_lt_add.2 (toIcoMod_lt_right _ _ _)
suffices hequiv : xβ' β€ toIocMod hp xβ' xβ by
obtain β¨z, hdβ© : β z : β€, xβ = xβ' + z β’ p := ((toIcoMod_eq_iff hp).1 rfl).2
simpa [hd, toIocMod_add_zsmul', toIcoMod_add_zsmul', add_le_add_iff_right]
rcases le_or_lt xβ' (xβ + p) with hββ | hββ
Β· suffices hIocββ : toIocMod hp xβ' xβ = xβ + p from hIocββ.symm.trans_ge hββ
apply (toIocMod_eq_iff hp).2
exact β¨β¨hββ, by simp [xβ', left_le_toIcoMod]β©, -1, by simpβ©
have hIocββ : toIocMod hp xβ xβ' = xβ' - p := by
apply (toIocMod_eq_iff hp).2
exact β¨β¨lt_sub_iff_add_lt.2 hββ, le_of_lt (hββ.trans hββ)β©, 1, by simpβ©
have not_hββ := (h.trans hIocββ.le).not_lt
contradiction
private theorem toIxxMod_antisymm (hβββ : toIcoMod hp a b β€ toIocMod hp a c)
(hβββ : toIcoMod hp a c β€ toIocMod hp a b) :
b β‘ a [PMOD p] β¨ c β‘ b [PMOD p] β¨ a β‘ c [PMOD p] := by
by_contra! h
rw [modEq_comm] at h
rw [β (not_modEq_iff_toIcoMod_eq_toIocMod hp).mp h.2.2] at hβββ
rw [β (not_modEq_iff_toIcoMod_eq_toIocMod hp).mp h.1] at hβββ
exact h.2.1 ((toIcoMod_inj _).1 <| hβββ.antisymm hβββ)
private theorem toIxxMod_total' (a b c : Ξ±) :
toIcoMod hp b a β€ toIocMod hp b c β¨ toIcoMod hp b c β€ toIocMod hp b a := by
/- an essential ingredient is the lemma saying {a-b} + {b-a} = period if a β b (and = 0 if a = b).
Thus if a β b and b β c then ({a-b} + {b-c}) + ({c-b} + {b-a}) = 2 * period, so one of
`{a-b} + {b-c}` and `{c-b} + {b-a}` must be `β€ period` -/
have := congr_argβ (Β· + Β·) (toIcoMod_add_toIocMod_zero hp a b) (toIcoMod_add_toIocMod_zero hp c b)
simp only [add_add_add_comm] at this
rw [_root_.add_comm (toIocMod _ _ _), add_add_add_comm, β two_nsmul] at this
replace := min_le_of_add_le_two_nsmul this.le
rw [min_le_iff] at this
rw [toIxxMod_iff, toIxxMod_iff]
refine this.imp (le_trans <| add_le_add_left ?_ _) (le_trans <| add_le_add_left ?_ _)
Β· apply toIcoMod_le_toIocMod
Β· apply toIcoMod_le_toIocMod
private theorem toIxxMod_total (a b c : Ξ±) :
toIcoMod hp a b β€ toIocMod hp a c β¨ toIcoMod hp c b β€ toIocMod hp c a :=
(toIxxMod_total' _ _ _ _).imp_right <| toIxxMod_cyclic_left _
private theorem toIxxMod_trans {xβ xβ xβ xβ : Ξ±}
(hβββ : toIcoMod hp xβ xβ β€ toIocMod hp xβ xβ β§ Β¬toIcoMod hp xβ xβ β€ toIocMod hp xβ xβ)
(hβββ : toIcoMod hp xβ xβ β€ toIocMod hp xβ xβ β§ Β¬toIcoMod hp xβ xβ β€ toIocMod hp xβ xβ) :
toIcoMod hp xβ xβ β€ toIocMod hp xβ xβ β§ Β¬toIcoMod hp xβ xβ β€ toIocMod hp xβ xβ := by
constructor
Β· suffices h : Β¬xβ β‘ xβ [PMOD p] by
have hβββ' := toIxxMod_cyclic_left _ (toIxxMod_cyclic_left _ hβββ.1)
have hβββ' := toIxxMod_cyclic_left _ (toIxxMod_cyclic_left _ hβββ.1)
rw [(not_modEq_iff_toIcoMod_eq_toIocMod hp).1 h] at hβββ'
exact toIxxMod_cyclic_left _ (hβββ'.trans hβββ')
by_contra h
rw [(modEq_iff_toIcoMod_eq_left hp).1 h] at hβββ
exact hβββ.2 (left_lt_toIocMod _ _ _).le
Β· rw [not_le] at hβββ hβββ β’
exact (hβββ.2.trans_le (toIcoMod_le_toIocMod _ xβ xβ)).trans hβββ.2
namespace QuotientAddGroup
variable [hp' : Fact (0 < p)]
instance : Btw (Ξ± β§Έ AddSubgroup.zmultiples p) where
btw xβ xβ xβ := (equivIcoMod hp'.out 0 (xβ - xβ) : Ξ±) β€ equivIocMod hp'.out 0 (xβ - xβ)
theorem btw_coe_iff' {xβ xβ xβ : Ξ±} :
Btw.btw (xβ : Ξ± β§Έ AddSubgroup.zmultiples p) xβ xβ β
toIcoMod hp'.out 0 (xβ - xβ) β€ toIocMod hp'.out 0 (xβ - xβ) :=
Iff.rfl
-- maybe harder to use than the primed one?
theorem btw_coe_iff {xβ xβ xβ : Ξ±} :
Btw.btw (xβ : Ξ± β§Έ AddSubgroup.zmultiples p) xβ xβ β
toIcoMod hp'.out xβ xβ β€ toIocMod hp'.out xβ xβ := by
rw [btw_coe_iff', toIocMod_sub_eq_sub, toIcoMod_sub_eq_sub, zero_add, sub_le_sub_iff_right]
instance circularPreorder : CircularPreorder (Ξ± β§Έ AddSubgroup.zmultiples p) where
btw_refl x := show _ β€ _ by simp [sub_self, hp'.out.le]
btw_cyclic_left {xβ xβ xβ} h := by
induction xβ using QuotientAddGroup.induction_on
induction xβ using QuotientAddGroup.induction_on
induction xβ using QuotientAddGroup.induction_on
simp_rw [btw_coe_iff] at h β’
apply toIxxMod_cyclic_left _ h
sbtw := _
sbtw_iff_btw_not_btw := Iff.rfl
sbtw_trans_left {xβ xβ xβ xβ} (hβββ : _ β§ _) (hβββ : _ β§ _) :=
show _ β§ _ by
induction xβ using QuotientAddGroup.induction_on
induction xβ using QuotientAddGroup.induction_on
induction xβ using QuotientAddGroup.induction_on
induction xβ using QuotientAddGroup.induction_on
simp_rw [btw_coe_iff] at hβββ hβββ β’
apply toIxxMod_trans _ hβββ hβββ
instance circularOrder : CircularOrder (Ξ± β§Έ AddSubgroup.zmultiples p) :=
{ QuotientAddGroup.circularPreorder with
btw_antisymm := fun {xβ xβ xβ} hβββ hβββ => by
induction xβ using QuotientAddGroup.induction_on
induction xβ using QuotientAddGroup.induction_on
induction xβ using QuotientAddGroup.induction_on
rw [btw_cyclic] at hβββ
simp_rw [btw_coe_iff] at hβββ hβββ
simp_rw [β modEq_iff_eq_mod_zmultiples]
exact toIxxMod_antisymm _ hβββ hβββ
btw_total := fun xβ xβ xβ => by
induction xβ using QuotientAddGroup.induction_on
induction xβ using QuotientAddGroup.induction_on
induction xβ using QuotientAddGroup.induction_on
simp_rw [btw_coe_iff]
apply toIxxMod_total }
end QuotientAddGroup
end Circular
end LinearOrderedAddCommGroup
/-!
### Connections to `Int.floor` and `Int.fract`
-/
section LinearOrderedField
variable {Ξ± : Type*} [Field Ξ±] [LinearOrder Ξ±] [IsStrictOrderedRing Ξ±] [FloorRing Ξ±]
{p : Ξ±} (hp : 0 < p)
theorem toIcoDiv_eq_floor (a b : Ξ±) : toIcoDiv hp a b = β(b - a) / pβ := by
refine toIcoDiv_eq_of_sub_zsmul_mem_Ico hp ?_
rw [Set.mem_Ico, zsmul_eq_mul, β sub_nonneg, add_comm, sub_right_comm, β sub_lt_iff_lt_add,
sub_right_comm _ _ a]
exact β¨Int.sub_floor_div_mul_nonneg _ hp, Int.sub_floor_div_mul_lt _ hpβ©
theorem toIocDiv_eq_neg_floor (a b : Ξ±) : toIocDiv hp a b = -β(a + p - b) / pβ := by
refine toIocDiv_eq_of_sub_zsmul_mem_Ioc hp ?_
rw [Set.mem_Ioc, zsmul_eq_mul, Int.cast_neg, neg_mul, sub_neg_eq_add, β sub_nonneg,
sub_add_eq_sub_sub]
refine β¨?_, Int.sub_floor_div_mul_nonneg _ hpβ©
rw [β add_lt_add_iff_right p, add_assoc, add_comm b, β sub_lt_iff_lt_add, add_comm (_ * _), β
sub_lt_iff_lt_add]
exact Int.sub_floor_div_mul_lt _ hp
theorem toIcoDiv_zero_one (b : Ξ±) : toIcoDiv (zero_lt_one' Ξ±) 0 b = βbβ := by
simp [toIcoDiv_eq_floor]
theorem toIcoMod_eq_add_fract_mul (a b : Ξ±) :
toIcoMod hp a b = a + Int.fract ((b - a) / p) * p := by
rw [toIcoMod, toIcoDiv_eq_floor, Int.fract]
field_simp
ring
theorem toIcoMod_eq_fract_mul (b : Ξ±) : toIcoMod hp 0 b = Int.fract (b / p) * p := by
simp [toIcoMod_eq_add_fract_mul]
theorem toIocMod_eq_sub_fract_mul (a b : Ξ±) :
toIocMod hp a b = a + p - Int.fract ((a + p - b) / p) * p := by
rw [toIocMod, toIocDiv_eq_neg_floor, Int.fract]
field_simp
ring
theorem toIcoMod_zero_one (b : Ξ±) : toIcoMod (zero_lt_one' Ξ±) 0 b = Int.fract b := by
simp [toIcoMod_eq_add_fract_mul]
end LinearOrderedField
/-! ### Lemmas about unions of translates of intervals -/
section Union
open Set Int
section LinearOrderedAddCommGroup
variable {Ξ± : Type*} [AddCommGroup Ξ±] [LinearOrder Ξ±] [IsOrderedAddMonoid Ξ±] [Archimedean Ξ±]
{p : Ξ±} (hp : 0 < p) (a : Ξ±)
include hp
theorem iUnion_Ioc_add_zsmul : β n : β€, Ioc (a + n β’ p) (a + (n + 1) β’ p) = univ := by
refine eq_univ_iff_forall.mpr fun b => mem_iUnion.mpr ?_
rcases sub_toIocDiv_zsmul_mem_Ioc hp a b with β¨hl, hrβ©
refine β¨toIocDiv hp a b, β¨lt_sub_iff_add_lt.mp hl, ?_β©β©
rw [add_smul, one_smul, β add_assoc]
convert sub_le_iff_le_add.mp hr using 1; abel
theorem iUnion_Ico_add_zsmul : β n : β€, Ico (a + n β’ p) (a + (n + 1) β’ p) = univ := by
refine eq_univ_iff_forall.mpr fun b => mem_iUnion.mpr ?_
rcases sub_toIcoDiv_zsmul_mem_Ico hp a b with β¨hl, hrβ©
refine β¨toIcoDiv hp a b, β¨le_sub_iff_add_le.mp hl, ?_β©β©
rw [add_smul, one_smul, β add_assoc]
convert sub_lt_iff_lt_add.mp hr using 1; abel
theorem iUnion_Icc_add_zsmul : β n : β€, Icc (a + n β’ p) (a + (n + 1) β’ p) = univ := by
simpa only [iUnion_Ioc_add_zsmul hp a, univ_subset_iff] using
iUnion_mono fun n : β€ => (Ioc_subset_Icc_self : Ioc (a + n β’ p) (a + (n + 1) β’ p) β Icc _ _)
theorem iUnion_Ioc_zsmul : β n : β€, Ioc (n β’ p) ((n + 1) β’ p) = univ := by
simpa only [zero_add] using iUnion_Ioc_add_zsmul hp 0
theorem iUnion_Ico_zsmul : β n : β€, Ico (n β’ p) ((n + 1) β’ p) = univ := by
simpa only [zero_add] using iUnion_Ico_add_zsmul hp 0
theorem iUnion_Icc_zsmul : β n : β€, Icc (n β’ p) ((n + 1) β’ p) = univ := by
simpa only [zero_add] using iUnion_Icc_add_zsmul hp 0
end LinearOrderedAddCommGroup
section LinearOrderedRing
variable {Ξ± : Type*} [Ring Ξ±] [LinearOrder Ξ±] [IsStrictOrderedRing Ξ±] [Archimedean Ξ±] (a : Ξ±)
theorem iUnion_Ioc_add_intCast : β n : β€, Ioc (a + n) (a + n + 1) = Set.univ := by
simpa only [zsmul_one, Int.cast_add, Int.cast_one, β add_assoc] using
iUnion_Ioc_add_zsmul zero_lt_one a
theorem iUnion_Ico_add_intCast : β n : β€, Ico (a + n) (a + n + 1) = Set.univ := by
simpa only [zsmul_one, Int.cast_add, Int.cast_one, β add_assoc] using
iUnion_Ico_add_zsmul zero_lt_one a
theorem iUnion_Icc_add_intCast : β n : β€, Icc (a + n) (a + n + 1) = Set.univ := by
simpa only [zsmul_one, Int.cast_add, Int.cast_one, β add_assoc] using
iUnion_Icc_add_zsmul zero_lt_one a
variable (Ξ±)
theorem iUnion_Ioc_intCast : β n : β€, Ioc (n : Ξ±) (n + 1) = Set.univ := by
simpa only [zero_add] using iUnion_Ioc_add_intCast (0 : Ξ±)
theorem iUnion_Ico_intCast : β n : β€, Ico (n : Ξ±) (n + 1) = Set.univ := by
simpa only [zero_add] using iUnion_Ico_add_intCast (0 : Ξ±)
theorem iUnion_Icc_intCast : β n : β€, Icc (n : Ξ±) (n + 1) = Set.univ := by
simpa only [zero_add] using iUnion_Icc_add_intCast (0 : Ξ±)
end LinearOrderedRing
end Union
| Mathlib/Algebra/Order/ToIntervalMod.lean | 1,058 | 1,063 | |
/-
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
| Mathlib/Topology/Constructions.lean | 1,052 | 1,054 |
/-
Copyright (c) 2021 David WΓ€rn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David WΓ€rn
-/
import Mathlib.Data.Fintype.Option
import Mathlib.Data.Fintype.Shrink
import Mathlib.Data.Fintype.Sum
import Mathlib.Data.Finite.Prod
import Mathlib.Algebra.BigOperators.Group.Finset.Basic
/-!
# The Hales-Jewett theorem
We prove the Hales-Jewett theorem. We deduce Van der Waerden's theorem and the multidimensional
Hales-Jewett theorem as corollaries.
The Hales-Jewett theorem is a result in Ramsey theory dealing with *combinatorial lines*. Given
an 'alphabet' `Ξ± : Type*` and `a b : Ξ±`, an example of a combinatorial line in `Ξ±^5` is
`{ (a, x, x, b, x) | x : Ξ± }`. See `Combinatorics.Line` for a precise general definition. The
Hales-Jewett theorem states that for any fixed finite types `Ξ±` and `ΞΊ`, there exists a (potentially
huge) finite type `ΞΉ` such that whenever `ΞΉ β Ξ±` is `ΞΊ`-colored (i.e. for any coloring
`C : (ΞΉ β Ξ±) β ΞΊ`), there exists a monochromatic line. We prove the Hales-Jewett theorem using
the idea of *color focusing* and a *product argument*. See the proof of
`Combinatorics.Line.exists_mono_in_high_dimension'` for details.
*Combinatorial subspaces* are higher-dimensional analogues of combinatorial lines. See
`Combinatorics.Subspace`. The multidimensional Hales-Jewett theorem generalises the statement above
from combinatorial lines to combinatorial subspaces of a fixed dimension.
The version of Van der Waerden's theorem in this file states that whenever a commutative monoid `M`
is finitely colored and `S` is a finite subset, there exists a monochromatic homothetic copy of `S`.
This follows from the Hales-Jewett theorem by considering the map `(ΞΉ β S) β M` sending `v`
to `β i : ΞΉ, v i`, which sends a combinatorial line to a homothetic copy of `S`.
## Main results
- `Combinatorics.Line.exists_mono_in_high_dimension`: The Hales-Jewett theorem.
- `Combinatorics.Subspace.exists_mono_in_high_dimension`: The multidimensional Hales-Jewett theorem.
- `Combinatorics.exists_mono_homothetic_copy`: A generalization of Van der Waerden's theorem.
## Implementation details
For convenience, we work directly with finite types instead of natural numbers. That is, we write
`Ξ±, ΞΉ, ΞΊ` for (finite) types where one might traditionally use natural numbers `n, H, c`. This
allows us to work directly with `Ξ±`, `Option Ξ±`, `(ΞΉ β Ξ±) β ΞΊ`, and `ΞΉ β ΞΉ'` instead of `Fin n`,
`Fin (n+1)`, `Fin (c^(n^H))`, and `Fin (H + H')`.
## TODO
- Prove a finitary version of Van der Waerden's theorem (either by compactness or by modifying the
current proof).
- One could reformulate the proof of Hales-Jewett to give explicit upper bounds on the number of
coordinates needed.
## Tags
combinatorial line, Ramsey theory, arithmetic progression
### References
* https://en.wikipedia.org/wiki/Hales%E2%80%93Jewett_theorem
-/
open Function
open scoped Finset
universe u v
variable {Ξ· Ξ± ΞΉ ΞΊ : Type*}
namespace Combinatorics
/-- The type of combinatorial subspaces. A subspace `l : Subspace Ξ· Ξ± ΞΉ` in the hypercube `ΞΉ β Ξ±`
defines a function `(Ξ· β Ξ±) β ΞΉ β Ξ±` from `Ξ· β Ξ±` to the hypercube, such that for each coordinate
`i : ΞΉ` and direction `e : Ξ·`, the function `fun x β¦ l x i` is either `fun x β¦ x e` for some
direction `e : Ξ·` or constant. We require subspaces to be non-degenerate in the sense that, for
every `e : Ξ·`, `fun x β¦ l x i` is `fun x β¦ x e` for at least one `i`.
Formally, a subspace is represented by a word `l.idxFun : ΞΉ β Ξ± β Ξ·` which says whether
`fun x β¦ l x i` is `fun x β¦ x e` (corresponding to `l.idxFun i = Sum.inr e`) or constantly `a`
(corresponding to `l.idxFun i = Sum.inl a`).
When `Ξ±` has size `1` there can be many elements of `Subspace Ξ· Ξ± ΞΉ` defining the same function. -/
@[ext]
structure Subspace (Ξ· Ξ± ΞΉ : Type*) where
/-- The word representing a combinatorial subspace. `l.idxfun i = Sum.inr e` means that
`l x i = x e` for all `x` and `l.idxfun i = some a` means that `l x i = a` for all `x`. -/
idxFun : ΞΉ β Ξ± β Ξ·
/-- We require combinatorial subspaces to be nontrivial in the sense that `fun x β¦ l x i` is
`fun x β¦ x e` for at least one coordinate `i`. -/
proper : β e, β i, idxFun i = Sum.inr e
namespace Subspace
variable {Ξ· Ξ± ΞΉ ΞΊ : Type*} {l : Subspace Ξ· Ξ± ΞΉ} {x : Ξ· β Ξ±} {i : ΞΉ} {a : Ξ±} {e : Ξ·}
/-- The combinatorial subspace corresponding to the identity embedding `(ΞΉ β Ξ±) β (ΞΉ β Ξ±)`. -/
instance : Inhabited (Subspace ΞΉ Ξ± ΞΉ) := β¨β¨Sum.inr, fun i β¦ β¨i, rflβ©β©β©
/-- Consider a subspace `l : Subspace Ξ· Ξ± ΞΉ` as a function `(Ξ· β Ξ±) β ΞΉ β Ξ±`. -/
@[coe] def toFun (l : Subspace Ξ· Ξ± ΞΉ) (x : Ξ· β Ξ±) (i : ΞΉ) : Ξ± := (l.idxFun i).elim id x
instance instCoeFun : CoeFun (Subspace Ξ· Ξ± ΞΉ) (fun _ β¦ (Ξ· β Ξ±) β ΞΉ β Ξ±) := β¨toFunβ©
lemma coe_apply (l : Subspace Ξ· Ξ± ΞΉ) (x : Ξ· β Ξ±) (i : ΞΉ) : l x i = (l.idxFun i).elim id x := rfl
-- Note: This is not made a `FunLike` instance to avoid having two syntactically different coercions
lemma coe_injective [Nontrivial Ξ±] : Injective ((β) : Subspace Ξ· Ξ± ΞΉ β (Ξ· β Ξ±) β ΞΉ β Ξ±) := by
classical
rintro l m hlm
ext i
simp only [funext_iff] at hlm
cases hl : idxFun l i with
| inl a =>
obtain β¨b, hbaβ© := exists_ne a
cases hm : idxFun m i <;> simpa [hl, hm, hba.symm, coe_apply] using hlm (const _ b) i
| inr e =>
cases hm : idxFun m i with
| inl a =>
obtain β¨b, hbaβ© := exists_ne a
simpa [hl, hm, hba, coe_apply] using hlm (const _ b) i
| inr f =>
obtain β¨a, b, habβ© := exists_pair_ne Ξ±
simp only [Sum.inr.injEq]
by_contra! hef
simpa [hl, hm, hef, hab, coe_apply] using hlm (Function.update (const _ a) f b) i
lemma apply_def (l : Subspace Ξ· Ξ± ΞΉ) (x : Ξ· β Ξ±) (i : ΞΉ) : l x i = (l.idxFun i).elim id x := rfl
lemma apply_inl (h : l.idxFun i = Sum.inl a) : l x i = a := by simp [apply_def, h]
lemma apply_inr (h : l.idxFun i = Sum.inr e) : l x i = x e := by simp [apply_def, h]
/-- Given a coloring `C` of `ΞΉ β Ξ±` and a combinatorial subspace `l` of `ΞΉ β Ξ±`, `l.IsMono C`
means that `l` is monochromatic with regard to `C`. -/
def IsMono (C : (ΞΉ β Ξ±) β ΞΊ) (l : Subspace Ξ· Ξ± ΞΉ) : Prop := β c, β x, C (l x) = c
variable {Ξ·' Ξ±' ΞΉ' : Type*}
/-- Change the index types of a subspace. -/
def reindex (l : Subspace Ξ· Ξ± ΞΉ) (eΞ· : Ξ· β Ξ·') (eΞ± : Ξ± β Ξ±') (eΞΉ : ΞΉ β ΞΉ') : Subspace Ξ·' Ξ±' ΞΉ' where
idxFun i := (l.idxFun <| eΞΉ.symm i).map eΞ± eΞ·
proper e := (eΞΉ.exists_congr fun i β¦ by cases h : idxFun l i <;>
simp [*, funext_iff, Equiv.eq_symm_apply]).1 <| l.proper <| eΞ·.symm e
@[simp] lemma reindex_apply (l : Subspace Ξ· Ξ± ΞΉ) (eΞ· : Ξ· β Ξ·') (eΞ± : Ξ± β Ξ±') (eΞΉ : ΞΉ β ΞΉ') (x i) :
l.reindex eΞ· eΞ± eΞΉ x i = eΞ± (l (eΞ±.symm β x β eΞ·) <| eΞΉ.symm i) := by
cases h : l.idxFun (eΞΉ.symm i) <;> simp [h, reindex, coe_apply]
@[simp] lemma reindex_isMono {eΞ· : Ξ· β Ξ·'} {eΞ± : Ξ± β Ξ±'} {eΞΉ : ΞΉ β ΞΉ'} {C : (ΞΉ' β Ξ±') β ΞΊ} :
(l.reindex eΞ· eΞ± eΞΉ).IsMono C β l.IsMono fun x β¦ C <| eΞ± β x β eΞΉ.symm := by
simp only [IsMono, funext (reindex_apply _ _ _ _ _), coe_apply]
exact exists_congr fun c β¦ (eΞ·.arrowCongr eΞ±).symm.forall_congr <| by aesop
protected lemma IsMono.reindex {eΞ· : Ξ· β Ξ·'} {eΞ± : Ξ± β Ξ±'} {eΞΉ : ΞΉ β ΞΉ'} {C : (ΞΉ β Ξ±) β ΞΊ}
(hl : l.IsMono C) : (l.reindex eΞ· eΞ± eΞΉ).IsMono fun x β¦ C <| eΞ±.symm β x β eΞΉ := by
simp [reindex_isMono, Function.comp_assoc]; simpa [β Function.comp_assoc]
end Subspace
/-- The type of combinatorial lines. A line `l : Line Ξ± ΞΉ` in the hypercube `ΞΉ β Ξ±` defines a
function `Ξ± β ΞΉ β Ξ±` from `Ξ±` to the hypercube, such that for each coordinate `i : ΞΉ`, the function
`fun x β¦ l x i` is either `id` or constant. We require lines to be nontrivial in the sense that
`fun x β¦ l x i` is `id` for at least one `i`.
Formally, a line is represented by a word `l.idxFun : ΞΉ β Option Ξ±` which says whether
`fun x β¦ l x i` is `id` (corresponding to `l.idxFun i = none`) or constantly `y` (corresponding to
`l.idxFun i = some y`).
When `Ξ±` has size `1` there can be many elements of `Line Ξ± ΞΉ` defining the same function. -/
@[ext]
structure Line (Ξ± ΞΉ : Type*) where
/-- The word representing a combinatorial line. `l.idxfun i = none` means that
`l x i = x` for all `x` and `l.idxfun i = some y` means that `l x i = y`. -/
idxFun : ΞΉ β Option Ξ±
/-- We require combinatorial lines to be nontrivial in the sense that `fun x β¦ l x i` is `id` for
at least one coordinate `i`. -/
proper : β i, idxFun i = none
namespace Line
variable {l : Line Ξ± ΞΉ} {i : ΞΉ} {a x : Ξ±}
/-- Consider a line `l : Line Ξ± ΞΉ` as a function `Ξ± β ΞΉ β Ξ±`. -/
@[coe] def toFun (l : Line Ξ± ΞΉ) (x : Ξ±) (i : ΞΉ) : Ξ± := (l.idxFun i).getD x
-- This lets us treat a line `l : Line Ξ± ΞΉ` as a function `Ξ± β ΞΉ β Ξ±`.
instance instCoeFun : CoeFun (Line Ξ± ΞΉ) fun _ => Ξ± β ΞΉ β Ξ± := β¨toFunβ©
@[simp] lemma coe_apply (l : Line Ξ± ΞΉ) (x : Ξ±) (i : ΞΉ) : l x i = (l.idxFun i).getD x := rfl
-- Note: This is not made a `FunLike` instance to avoid having two syntactically different coercions
lemma coe_injective [Nontrivial Ξ±] : Injective ((β) : Line Ξ± ΞΉ β Ξ± β ΞΉ β Ξ±) := by
rintro l m hlm
ext i a
obtain β¨b, hbaβ© := exists_ne a
simp only [Option.mem_def, funext_iff] at hlm β’
refine β¨fun h β¦ ?_, fun h β¦ ?_β©
| Β· cases hi : idxFun m i <;> simpa [@eq_comm _ a, hi, h, hba] using hlm b i
Β· cases hi : idxFun l i <;> simpa [@eq_comm _ a, hi, h, hba] using hlm b i
/-- A line is monochromatic if all its points are the same color. -/
| Mathlib/Combinatorics/HalesJewett.lean | 197 | 200 |
/-
Copyright (c) 2024 David Loeffler. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Alex Kontorovich, David Loeffler, Heather Macbeth, SΓ©bastien GouΓ«zel
-/
import Mathlib.Analysis.Calculus.ParametricIntegral
import Mathlib.Analysis.Calculus.ContDiff.CPolynomial
import Mathlib.Analysis.Fourier.AddCircle
import Mathlib.Analysis.Fourier.FourierTransform
import Mathlib.Analysis.Calculus.FDeriv.Analytic
import Mathlib.Analysis.Calculus.LineDeriv.IntegrationByParts
import Mathlib.Analysis.Calculus.ContDiff.Bounds
/-!
# Derivatives of the Fourier transform
In this file we compute the FrΓ©chet derivative of the Fourier transform of `f`, where `f` is a
function such that both `f` and `v β¦ βvβ * βf vβ` are integrable. Here the Fourier transform is
understood as an operator `(V β E) β (W β E)`, where `V` and `W` are normed `β`-vector spaces
and the Fourier transform is taken with respect to a continuous `β`-bilinear
pairing `L : V Γ W β β` and a given reference measure `ΞΌ`.
We also investigate higher derivatives: Assuming that `βvβ^n * βf vβ` is integrable, we show
that the Fourier transform of `f` is `C^n`.
We also study in a parallel way the Fourier transform of the derivative, which is obtained by
tensoring the Fourier transform of the original function with the bilinear form. We also get
results for iterated derivatives.
A consequence of these results is that, if a function is smooth and all its derivatives are
integrable when multiplied by `βvβ^k`, then the same goes for its Fourier transform, with
explicit bounds.
We give specialized versions of these results on inner product spaces (where `L` is the scalar
product) and on the real line, where we express the one-dimensional derivative in more concrete
terms, as the Fourier transform of `-2ΟI x * f x` (or `(-2ΟI x)^n * f x` for higher derivatives).
## Main definitions and results
We introduce two convenience definitions:
* `VectorFourier.fourierSMulRight L f`: given `f : V β E` and `L` a bilinear pairing
between `V` and `W`, then this is the function `fun v β¦ -(2 * Ο * I) (L v β¬) β’ f v`,
from `V` to `Hom (W, E)`.
This is essentially `ContinuousLinearMap.smulRight`, up to the factor `- 2ΟI` designed to make
sure that the Fourier integral of `fourierSMulRight L f` is the derivative of the Fourier
integral of `f`.
* `VectorFourier.fourierPowSMulRight` is the higher order analogue for higher derivatives:
`fourierPowSMulRight L f v n` is informally `(-(2 * Ο * I))^n (L v β¬)^n β’ f v`, in
the space of continuous multilinear maps `W [Γn]βL[β] E`.
With these definitions, the statements read as follows, first in a general context
(arbitrary `L` and `ΞΌ`):
* `VectorFourier.hasFDerivAt_fourierIntegral`: the Fourier integral of `f` is differentiable, with
derivative the Fourier integral of `fourierSMulRight L f`.
* `VectorFourier.differentiable_fourierIntegral`: the Fourier integral of `f` is differentiable.
* `VectorFourier.fderiv_fourierIntegral`: formula for the derivative of the Fourier integral of `f`.
* `VectorFourier.fourierIntegral_fderiv`: formula for the Fourier integral of the derivative of `f`.
* `VectorFourier.hasFTaylorSeriesUpTo_fourierIntegral`: under suitable integrability conditions,
the Fourier integral of `f` has an explicit Taylor series up to order `N`, given by the Fourier
integrals of `fun v β¦ fourierPowSMulRight L f v n`.
* `VectorFourier.contDiff_fourierIntegral`: under suitable integrability conditions,
the Fourier integral of `f` is `C^n`.
* `VectorFourier.iteratedFDeriv_fourierIntegral`: under suitable integrability conditions,
explicit formula for the `n`-th derivative of the Fourier integral of `f`, as the Fourier
integral of `fun v β¦ fourierPowSMulRight L f v n`.
* `VectorFourier.pow_mul_norm_iteratedFDeriv_fourierIntegral_le`: explicit bounds for the `n`-th
derivative of the Fourier integral, multiplied by a power function, in terms of corresponding
integrals for the original function.
These statements are then specialized to the case of the usual Fourier transform on
finite-dimensional inner product spaces with their canonical Lebesgue measure (covering in
particular the case of the real line), replacing the namespace `VectorFourier` by
the namespace `Real` in the above statements.
We also give specialized versions of the one-dimensional real derivative (and iterated derivative)
in `Real.deriv_fourierIntegral` and `Real.iteratedDeriv_fourierIntegral`.
-/
noncomputable section
open Real Complex MeasureTheory Filter TopologicalSpace
open scoped FourierTransform Topology ContDiff
-- without this local instance, Lean tries first the instance
-- `secondCountableTopologyEither_of_right` (whose priority is 100) and takes a very long time to
-- fail. Since we only use the left instance in this file, we make sure it is tried first.
attribute [local instance 101] secondCountableTopologyEither_of_left
namespace Real
lemma hasDerivAt_fourierChar (x : β) : HasDerivAt (π Β· : β β β) (2 * Ο * I * π x) x := by
have h1 (y : β) : π y = fourier 1 (y : UnitAddCircle) := by
rw [fourierChar_apply, fourier_coe_apply]
push_cast
ring_nf
simpa only [h1, Int.cast_one, ofReal_one, div_one, mul_one] using hasDerivAt_fourier 1 1 x
lemma differentiable_fourierChar : Differentiable β (π Β· : β β β) :=
fun x β¦ (Real.hasDerivAt_fourierChar x).differentiableAt
lemma deriv_fourierChar (x : β) : deriv (π Β· : β β β) x = 2 * Ο * I * π x :=
(Real.hasDerivAt_fourierChar x).deriv
variable {V W : Type*} [NormedAddCommGroup V] [NormedSpace β V]
[NormedAddCommGroup W] [NormedSpace β W] (L : V βL[β] W βL[β] β)
lemma hasFDerivAt_fourierChar_neg_bilinear_right (v : V) (w : W) :
HasFDerivAt (fun w β¦ (π (-L v w) : β))
((-2 * Ο * I * π (-L v w)) β’ (ofRealCLM βL (L v))) w := by
have ha : HasFDerivAt (fun w' : W β¦ L v w') (L v) w := ContinuousLinearMap.hasFDerivAt (L v)
convert (hasDerivAt_fourierChar (-L v w)).hasFDerivAt.comp w ha.neg using 1
ext y
simp only [neg_mul, ContinuousLinearMap.coe_smul', ContinuousLinearMap.coe_comp', Pi.smul_apply,
Function.comp_apply, ofRealCLM_apply, smul_eq_mul, ContinuousLinearMap.comp_neg,
ContinuousLinearMap.neg_apply, ContinuousLinearMap.smulRight_apply,
ContinuousLinearMap.one_apply, real_smul, neg_inj]
ring
lemma fderiv_fourierChar_neg_bilinear_right_apply (v : V) (w y : W) :
fderiv β (fun w β¦ (π (-L v w) : β)) w y = -2 * Ο * I * L v y * π (-L v w) := by
simp only [(hasFDerivAt_fourierChar_neg_bilinear_right L v w).fderiv, neg_mul,
ContinuousLinearMap.coe_smul', ContinuousLinearMap.coe_comp', Pi.smul_apply,
Function.comp_apply, ofRealCLM_apply, smul_eq_mul, neg_inj]
ring
lemma differentiable_fourierChar_neg_bilinear_right (v : V) :
Differentiable β (fun w β¦ (π (-L v w) : β)) :=
fun w β¦ (hasFDerivAt_fourierChar_neg_bilinear_right L v w).differentiableAt
lemma hasFDerivAt_fourierChar_neg_bilinear_left (v : V) (w : W) :
HasFDerivAt (fun v β¦ (π (-L v w) : β))
((-2 * Ο * I * π (-L v w)) β’ (ofRealCLM βL (L.flip w))) v :=
hasFDerivAt_fourierChar_neg_bilinear_right L.flip w v
lemma fderiv_fourierChar_neg_bilinear_left_apply (v y : V) (w : W) :
fderiv β (fun v β¦ (π (-L v w) : β)) v y = -2 * Ο * I * L y w * π (-L v w) := by
simp only [(hasFDerivAt_fourierChar_neg_bilinear_left L v w).fderiv, neg_mul,
ContinuousLinearMap.coe_smul', ContinuousLinearMap.coe_comp', Pi.smul_apply,
Function.comp_apply, ContinuousLinearMap.flip_apply, ofRealCLM_apply, smul_eq_mul, neg_inj]
ring
lemma differentiable_fourierChar_neg_bilinear_left (w : W) :
Differentiable β (fun v β¦ (π (-L v w) : β)) :=
fun v β¦ (hasFDerivAt_fourierChar_neg_bilinear_left L v w).differentiableAt
end Real
variable {E : Type*} [NormedAddCommGroup E] [NormedSpace β E]
namespace VectorFourier
variable {V W : Type*} [NormedAddCommGroup V] [NormedSpace β V]
[NormedAddCommGroup W] [NormedSpace β W] (L : V βL[β] W βL[β] β) (f : V β E)
/-- Send a function `f : V β E` to the function `f : V β Hom (W, E)` given by
`v β¦ (w β¦ -2 * Ο * I * L (v, w) β’ f v)`. This is designed so that the Fourier transform of
`fourierSMulRight L f` is the derivative of the Fourier transform of `f`. -/
def fourierSMulRight (v : V) : (W βL[β] E) := -(2 * Ο * I) β’ (L v).smulRight (f v)
@[simp] lemma fourierSMulRight_apply (v : V) (w : W) :
fourierSMulRight L f v w = -(2 * Ο * I) β’ L v w β’ f v := rfl
/-- The `w`-derivative of the Fourier transform integrand. -/
lemma hasFDerivAt_fourierChar_smul (v : V) (w : W) :
HasFDerivAt (fun w' β¦ π (-L v w') β’ f v) (π (-L v w) β’ fourierSMulRight L f v) w := by
have ha : HasFDerivAt (fun w' : W β¦ L v w') (L v) w := ContinuousLinearMap.hasFDerivAt (L v)
convert ((hasDerivAt_fourierChar (-L v w)).hasFDerivAt.comp w ha.neg).smul_const (f v)
ext w' : 1
simp_rw [fourierSMulRight, ContinuousLinearMap.smul_apply, ContinuousLinearMap.smulRight_apply]
rw [ContinuousLinearMap.comp_apply, ContinuousLinearMap.neg_apply,
ContinuousLinearMap.smulRight_apply, ContinuousLinearMap.one_apply, β smul_assoc, smul_comm,
β smul_assoc, real_smul, real_smul, Submonoid.smul_def, smul_eq_mul]
push_cast
ring_nf
lemma norm_fourierSMulRight (L : V βL[β] W βL[β] β) (f : V β E) (v : V) :
βfourierSMulRight L f vβ = (2 * Ο) * βL vβ * βf vβ := by
rw [fourierSMulRight, norm_smul _ (ContinuousLinearMap.smulRight (L v) (f v)),
norm_neg, norm_mul, norm_mul, norm_I, mul_one, Complex.norm_of_nonneg pi_pos.le,
Complex.norm_two, ContinuousLinearMap.norm_smulRight_apply, β mul_assoc]
lemma norm_fourierSMulRight_le (L : V βL[β] W βL[β] β) (f : V β E) (v : V) :
βfourierSMulRight L f vβ β€ 2 * Ο * βLβ * βvβ * βf vβ := calc
βfourierSMulRight L f vβ = (2 * Ο) * βL vβ * βf vβ := norm_fourierSMulRight _ _ _
_ β€ (2 * Ο) * (βLβ * βvβ) * βf vβ := by gcongr; exact L.le_opNorm _
_ = 2 * Ο * βLβ * βvβ * βf vβ := by ring
| lemma _root_.MeasureTheory.AEStronglyMeasurable.fourierSMulRight
[SecondCountableTopologyEither V (W βL[β] β)] [MeasurableSpace V] [BorelSpace V]
{L : V βL[β] W βL[β] β} {f : V β E} {ΞΌ : Measure V}
(hf : AEStronglyMeasurable f ΞΌ) :
AEStronglyMeasurable (fun v β¦ fourierSMulRight L f v) ΞΌ := by
apply AEStronglyMeasurable.const_smul'
have aux0 : Continuous fun p : (W βL[β] β) Γ E β¦ p.1.smulRight p.2 :=
(ContinuousLinearMap.smulRightL β W E).continuousβ
have aux1 : AEStronglyMeasurable (fun v β¦ (L v, f v)) ΞΌ :=
L.continuous.aestronglyMeasurable.prodMk hf
-- Elaboration without the expected type is faster here:
exact (aux0.comp_aestronglyMeasurable aux1 :)
| Mathlib/Analysis/Fourier/FourierTransformDeriv.lean | 191 | 202 |
/-
Copyright (c) 2017 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
-/
import Mathlib.Data.WSeq.Relation
/-!
# Parallel computation
Parallel computation of a computable sequence of computations by
a diagonal enumeration.
The important theorems of this operation are proven as
terminates_parallel and exists_of_mem_parallel.
(This operation is nondeterministic in the sense that it does not
honor sequence equivalence (irrelevance of computation time).)
-/
universe u v
namespace Computation
open Stream'
variable {Ξ± : Type u} {Ξ² : Type v}
private def parallel.aux2 : List (Computation Ξ±) β Ξ± β (List (Computation Ξ±)) :=
List.foldr
(fun c o =>
match o with
| Sum.inl a => Sum.inl a
| Sum.inr ls => rmap (fun c' => c' :: ls) (destruct c))
(Sum.inr [])
private def parallel.aux1 :
List (Computation Ξ±) Γ WSeq (Computation Ξ±) β
Ξ± β (List (Computation Ξ±) Γ WSeq (Computation Ξ±))
| (l, S) =>
rmap
(fun l' =>
match Seq.destruct S with
| none => (l', Seq.nil)
| some (none, S') => (l', S')
| some (some c, S') => (c :: l', S'))
(parallel.aux2 l)
/-- Parallel computation of an infinite stream of computations,
taking the first result -/
def parallel (S : WSeq (Computation Ξ±)) : Computation Ξ± :=
corec parallel.aux1 ([], S)
theorem terminates_parallel.aux :
β {l : List (Computation Ξ±)} {S c},
c β l β Terminates c β Terminates (corec parallel.aux1 (l, S)) := by
have lem1 :
β l S, (β a : Ξ±, parallel.aux2 l = Sum.inl a) β Terminates (corec parallel.aux1 (l, S)) := by
intro l S e
obtain β¨a, eβ© := e
have : corec parallel.aux1 (l, S) = return a := by
apply destruct_eq_pure
simp only [parallel.aux1, rmap, corec_eq]
rw [e]
rw [this]
exact ret_terminates a
intro l S c m T
revert l S
apply @terminatesRecOn _ _ c T _ _
Β· intro a l S m
apply lem1
induction' l with c l IH <;> simp at m
rcases m with e | m
Β· rw [β e]
simp only [parallel.aux2, rmap, List.foldr_cons, destruct_pure]
split <;> simp
Β· obtain β¨a', eβ© := IH m
simp only [parallel.aux2, rmap, List.foldr_cons]
simp? [parallel.aux2] at e says simp only [parallel.aux2, rmap] at e
rw [e]
exact β¨a', rflβ©
Β· intro s IH l S m
have H1 : β l', parallel.aux2 l = Sum.inr l' β s β l' := by
induction' l with c l IH' <;> intro l' e' <;> simp at m
rcases m with e | m <;> simp [parallel.aux2] at e'
Β· rw [β e] at e'
-- Porting note: `revert e'` is required.
revert e'
split
Β· simp
Β· simp only [destruct_think, Sum.inr.injEq]
rintro rfl
simp
Β· induction' e : List.foldr (fun c o =>
match o with
| Sum.inl a => Sum.inl a
| Sum.inr ls => rmap (fun c' => c' :: ls) (destruct c))
(Sum.inr List.nil) l with a' ls <;> erw [e] at e'
Β· contradiction
have := IH' m _ e
-- Porting note: `revert e'` & `intro e'` are required.
revert e'
cases destruct c <;> intro e' <;> [injection e'; injection e' with h']
rw [β h']
simp [this]
induction' h : parallel.aux2 l with a l'
Β· exact lem1 _ _ β¨a, hβ©
Β· have H2 : corec parallel.aux1 (l, S) = think _ := destruct_eq_think (by
simp only [parallel.aux1, rmap, corec_eq]
rw [h])
rw [H2]
refine @Computation.think_terminates _ _ ?_
have := H1 _ h
rcases Seq.destruct S with (_ | β¨_ | c, S'β©) <;> simp [parallel.aux1] <;> apply IH <;>
simp [this]
theorem terminates_parallel {S : WSeq (Computation Ξ±)} {c} (h : c β S) [T : Terminates c] :
Terminates (parallel S) := by
suffices
β (n) (l : List (Computation Ξ±)) (S c),
c β l β¨ some (some c) = Seq.get? S n β Terminates c β Terminates (corec parallel.aux1 (l, S))
from
let β¨n, hβ© := h
this n [] S c (Or.inr h) T
intro n; induction' n with n IH <;> intro l S c o T
Β· rcases o with a | a
Β· exact terminates_parallel.aux a T
have H : Seq.destruct S = some (some c, Seq.tail S) := by simp [Seq.destruct, (Β· <$> Β·), β a]
induction' h : parallel.aux2 l with a l'
Β· have C : corec parallel.aux1 (l, S) = pure a := by
apply destruct_eq_pure
rw [corec_eq, parallel.aux1]
rw [h]
simp only [rmap]
rw [C]
infer_instance
Β· have C : corec parallel.aux1 (l, S) = _ := destruct_eq_think (by
simp only [corec_eq, rmap, parallel.aux1.eq_1]
rw [h, H])
rw [C]
refine @Computation.think_terminates _ _ ?_
apply terminates_parallel.aux _ T
simp
Β· rcases o with a | a
Β· exact terminates_parallel.aux a T
induction' h : parallel.aux2 l with a l'
Β· have C : corec parallel.aux1 (l, S) = pure a := by
apply destruct_eq_pure
rw [corec_eq, parallel.aux1]
rw [h]
simp only [rmap]
rw [C]
infer_instance
Β· have C : corec parallel.aux1 (l, S) = _ := destruct_eq_think (by
simp only [corec_eq, rmap, parallel.aux1.eq_1]
rw [h])
rw [C]
refine @Computation.think_terminates _ _ ?_
have TT : β l', Terminates (corec parallel.aux1 (l', S.tail)) := by
intro
apply IH _ _ _ (Or.inr _) T
rw [a, Seq.get?_tail]
induction' e : Seq.get? S 0 with o
Β· have D : Seq.destruct S = none := by
dsimp [Seq.destruct]
rw [e]
rfl
rw [D]
simp only
have TT := TT l'
rwa [Seq.destruct_eq_none D, Seq.tail_nil] at TT
Β· have D : Seq.destruct S = some (o, S.tail) := by
dsimp [Seq.destruct]
rw [e]
rfl
rw [D]
cases o <;> simp [parallel.aux1, TT]
theorem exists_of_mem_parallel {S : WSeq (Computation Ξ±)} {a} (h : a β parallel S) :
β c β S, a β c := by
suffices
β C, a β C β β (l : List (Computation Ξ±)) (S),
corec parallel.aux1 (l, S) = C β β c, (c β l β¨ c β S) β§ a β c from
let β¨c, h1, h2β© := this _ h [] S rfl
β¨c, h1.resolve_left <| List.not_mem_nil, h2β©
let F : List (Computation Ξ±) β Ξ± β (List (Computation Ξ±)) β Prop := by
intro l a
rcases a with a | l'
Β· exact β c β l, a β c
Β· exact β a', (β c β l', a' β c) β β c β l, a' β c
have lem1 : β l : List (Computation Ξ±), F l (parallel.aux2 l) := by
intro l
induction' l with c l IH <;> simp only [parallel.aux2, List.foldr]
Β· intro a h
rcases h with β¨c, hn, _β©
exact False.elim <| List.not_mem_nil hn
Β· simp only [parallel.aux2] at IH
-- Porting note: `revert IH` & `intro IH` are required.
revert IH
cases List.foldr (fun c o =>
match o with
| Sum.inl a => Sum.inl a
| Sum.inr ls => rmap (fun c' => c' :: ls) (destruct c)) (Sum.inr List.nil) l <;>
intro IH <;> simp only [parallel.aux2]
Β· rcases IH with β¨c', cl, acβ©
exact β¨c', List.Mem.tail _ cl, acβ©
Β· induction' h : destruct c with a c' <;> simp only [rmap]
Β· refine β¨c, List.mem_cons_self, ?_β©
rw [destruct_eq_pure h]
apply ret_mem
Β· intro a' h
rcases h with β¨d, dm, adβ©
simp? at dm says simp only [List.mem_cons] at dm
rcases dm with e | dl
Β· rw [e] at ad
refine β¨c, List.mem_cons_self, ?_β©
rw [destruct_eq_think h]
exact think_mem ad
Β· obtain β¨d, dmβ© := IH a' β¨d, dl, adβ©
obtain β¨dm, adβ© := dm
exact β¨d, List.Mem.tail _ dm, adβ©
intro C aC
-- Porting note: `revert this e'` & `intro this e'` are required.
apply memRecOn aC <;> [skip; intro C' IH] <;> intro l S e <;> have e' := congr_arg destruct e <;>
have := lem1 l <;> simp only [parallel.aux1, corec_eq, destruct_pure, destruct_think] at e' <;>
revert this e' <;> rcases parallel.aux2 l with a' | l' <;> intro this e' <;>
[injection e' with h'; injection e'; injection e'; injection e' with h']
Β· rw [h'] at this
rcases this with β¨c, cl, acβ©
exact β¨c, Or.inl cl, acβ©
Β· induction' e : Seq.destruct S with a <;> rw [e] at h'
Β· exact
let β¨d, o, adβ© := IH _ _ h'
let β¨c, cl, acβ© := this a β¨d, o.resolve_right (WSeq.not_mem_nil _), adβ©
β¨c, Or.inl cl, acβ©
Β· obtain β¨o, S'β© := a
obtain - | c := o <;> simp [parallel.aux1] at h' <;> rcases IH _ _ h' with β¨d, dl | dS', adβ©
Β· exact
let β¨c, cl, acβ© := this a β¨d, dl, adβ©
β¨c, Or.inl cl, acβ©
Β· refine β¨d, Or.inr ?_, adβ©
rw [Seq.destruct_eq_cons e]
exact Seq.mem_cons_of_mem _ dS'
Β· simp at dl
rcases dl with dc | dl
Β· rw [dc] at ad
refine β¨c, Or.inr ?_, adβ©
rw [Seq.destruct_eq_cons e]
apply Seq.mem_cons
Β· exact
let β¨c, cl, acβ© := this a β¨d, dl, adβ©
β¨c, Or.inl cl, acβ©
Β· refine β¨d, Or.inr ?_, adβ©
rw [Seq.destruct_eq_cons e]
exact Seq.mem_cons_of_mem _ dS'
theorem map_parallel (f : Ξ± β Ξ²) (S) : map f (parallel S) = parallel (S.map (map f)) := by
refine
eq_of_bisim
(fun c1 c2 =>
β l S,
c1 = map f (corec parallel.aux1 (l, S)) β§
c2 = corec parallel.aux1 (l.map (map f), S.map (map f)))
?_ β¨[], S, rfl, rflβ©
intro c1 c2 h
exact
match c1, c2, h with
| _, _, β¨l, S, rfl, rflβ© => by
have : parallel.aux2 (l.map (map f))
= lmap f (rmap (List.map (map f)) (parallel.aux2 l)) := by
simp only [parallel.aux2, rmap, lmap]
induction' l with c l IH <;> simp
rw [IH]
cases List.foldr _ _ _
Β· simp
Β· cases destruct c <;> simp
simp only [BisimO, destruct_map, lmap, rmap, corec_eq, parallel.aux1.eq_1]
rw [this]
rcases parallel.aux2 l with a | l' <;> simp
induction' S using WSeq.recOn with c S S <;> simp <;>
exact β¨_, _, rfl, rflβ©
theorem parallel_empty (S : WSeq (Computation Ξ±)) (h : S.head ~> none) : parallel S = empty _ :=
eq_empty_of_not_terminates fun β¨β¨a, mβ©β© => by
let β¨c, cs, _β© := exists_of_mem_parallel m
let β¨n, nmβ© := WSeq.exists_get?_of_mem cs
let β¨c', h'β© := WSeq.head_some_of_get?_some nm
injection h h'
/-- Induction principle for parallel computations.
The reason this isn't trivial from `exists_of_mem_parallel` is because it eliminates to `Sort`. -/
def parallelRec {S : WSeq (Computation Ξ±)} (C : Ξ± β Sort v) (H : β s β S, β a β s, C a) {a}
(h : a β parallel S) : C a := by
let T : WSeq (Computation (Ξ± Γ Computation Ξ±)) := S.map fun c => c.map fun a => (a, c)
have : S = T.map (map fun c => c.1) := by
rw [β WSeq.map_comp]
refine (WSeq.map_id _).symm.trans (congr_arg (fun f => WSeq.map f S) ?_)
funext c
dsimp [id, Function.comp_def]
rw [β map_comp]
exact (map_id _).symm
have pe := congr_arg parallel this
rw [β map_parallel] at pe
have h' := h
rw [pe] at h'
haveI : Terminates (parallel T) := (terminates_map_iff _ _).1 β¨β¨_, h'β©β©
induction' e : get (parallel T) with a' c
have : a β c β§ c β S := by
rcases exists_of_mem_map h' with β¨d, dT, cdβ©
rw [get_eq_of_mem _ dT] at e
cases e
dsimp at cd
cases cd
rcases exists_of_mem_parallel dT with β¨d', dT', ad'β©
rcases WSeq.exists_of_mem_map dT' with β¨c', cs', e'β©
rw [β e'] at ad'
rcases exists_of_mem_map ad' with β¨a', ac', e'β©
injection e' with i1 i2
constructor
Β· rwa [i1, i2] at ac'
Β· rwa [i2] at cs'
obtain β¨ac, csβ© := this
apply H _ cs _ ac
theorem parallel_promises {S : WSeq (Computation Ξ±)} {a} (H : β s β S, s ~> a) : parallel S ~> a :=
fun _ ma' =>
let β¨_, cs, acβ© := exists_of_mem_parallel ma'
H _ cs ac
theorem mem_parallel {S : WSeq (Computation Ξ±)} {a} (H : β s β S, s ~> a) {c} (cs : c β S)
(ac : a β c) : a β parallel S := by
haveI := terminates_of_mem ac
haveI := terminates_parallel cs
exact mem_of_promises _ (parallel_promises H)
theorem parallel_congr_lem {S T : WSeq (Computation Ξ±)} {a} (H : S.LiftRel Equiv T) :
(β s β S, s ~> a) β β t β T, t ~> a :=
β¨fun h1 _ tT =>
let β¨_, sS, seβ© := WSeq.exists_of_liftRel_right H tT
(promises_congr se _).1 (h1 _ sS),
fun h2 _ sS =>
let β¨_, tT, seβ© := WSeq.exists_of_liftRel_left H sS
(promises_congr se _).2 (h2 _ tT)β©
-- The parallel operation is only deterministic when all computation paths lead to the same value
theorem parallel_congr_left {S T : WSeq (Computation Ξ±)} {a} (h1 : β s β S, s ~> a)
(H : S.LiftRel Equiv T) : parallel S ~ parallel T :=
let h2 := (parallel_congr_lem H).1 h1
fun a' =>
β¨fun h => by
have aa := parallel_promises h1 h
rw [β aa]
rw [β aa] at h
exact
let β¨s, sS, asβ© := exists_of_mem_parallel h
let β¨t, tT, stβ© := WSeq.exists_of_liftRel_left H sS
let aT := (st _).1 as
mem_parallel h2 tT aT,
fun h => by
have aa := parallel_promises h2 h
rw [β aa]
rw [β aa] at h
exact
let β¨s, sS, asβ© := exists_of_mem_parallel h
let β¨t, tT, stβ© := WSeq.exists_of_liftRel_right H sS
| let aT := (st _).2 as
mem_parallel h1 tT aTβ©
theorem parallel_congr_right {S T : WSeq (Computation Ξ±)} {a} (h2 : β t β T, t ~> a)
(H : S.LiftRel Equiv T) : parallel S ~ parallel T :=
parallel_congr_left ((parallel_congr_lem H).2 h2) H
end Computation
| Mathlib/Data/Seq/Parallel.lean | 363 | 384 |
/-
Copyright (c) 2022 Moritz Doll. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Moritz Doll, Anatole Dedecker
-/
import Mathlib.Analysis.LocallyConvex.Bounded
import Mathlib.Analysis.Seminorm
import Mathlib.Data.Real.Sqrt
import Mathlib.Topology.Algebra.Equicontinuity
import Mathlib.Topology.MetricSpace.Equicontinuity
import Mathlib.Topology.Algebra.FilterBasis
import Mathlib.Topology.Algebra.Module.LocallyConvex
/-!
# Topology induced by a family of seminorms
## Main definitions
* `SeminormFamily.basisSets`: The set of open seminorm balls for a family of seminorms.
* `SeminormFamily.moduleFilterBasis`: A module filter basis formed by the open balls.
* `Seminorm.IsBounded`: A linear map `f : E ββ[π] F` is bounded iff every seminorm in `F` can be
bounded by a finite number of seminorms in `E`.
## Main statements
* `WithSeminorms.toLocallyConvexSpace`: A space equipped with a family of seminorms is locally
convex.
* `WithSeminorms.firstCountable`: A space is first countable if it's topology is induced by a
countable family of seminorms.
## Continuity of semilinear maps
If `E` and `F` are topological vector space with the topology induced by a family of seminorms, then
we have a direct method to prove that a linear map is continuous:
* `Seminorm.continuous_from_bounded`: A bounded linear map `f : E ββ[π] F` is continuous.
If the topology of a space `E` is induced by a family of seminorms, then we can characterize von
Neumann boundedness in terms of that seminorm family. Together with
`LinearMap.continuous_of_locally_bounded` this gives general criterion for continuity.
* `WithSeminorms.isVonNBounded_iff_finset_seminorm_bounded`
* `WithSeminorms.isVonNBounded_iff_seminorm_bounded`
* `WithSeminorms.image_isVonNBounded_iff_finset_seminorm_bounded`
* `WithSeminorms.image_isVonNBounded_iff_seminorm_bounded`
## Tags
seminorm, locally convex
-/
open NormedField Set Seminorm TopologicalSpace Filter List
open NNReal Pointwise Topology Uniformity
variable {π πβ π πβ E F G ΞΉ ΞΉ' : Type*}
section FilterBasis
variable [NormedField π] [AddCommGroup E] [Module π E]
variable (π E ΞΉ)
/-- An abbreviation for indexed families of seminorms. This is mainly to allow for dot-notation. -/
abbrev SeminormFamily :=
ΞΉ β Seminorm π E
variable {π E ΞΉ}
namespace SeminormFamily
/-- The sets of a filter basis for the neighborhood filter of 0. -/
def basisSets (p : SeminormFamily π E ΞΉ) : Set (Set E) :=
β (s : Finset ΞΉ) (r) (_ : 0 < r), singleton (ball (s.sup p) (0 : E) r)
variable (p : SeminormFamily π E ΞΉ)
theorem basisSets_iff {U : Set E} :
U β p.basisSets β β (i : Finset ΞΉ) (r : β), 0 < r β§ U = ball (i.sup p) 0 r := by
simp only [basisSets, mem_iUnion, exists_prop, mem_singleton_iff]
theorem basisSets_mem (i : Finset ΞΉ) {r : β} (hr : 0 < r) : (i.sup p).ball 0 r β p.basisSets :=
(basisSets_iff _).mpr β¨i, _, hr, rflβ©
theorem basisSets_singleton_mem (i : ΞΉ) {r : β} (hr : 0 < r) : (p i).ball 0 r β p.basisSets :=
(basisSets_iff _).mpr β¨{i}, _, hr, by rw [Finset.sup_singleton]β©
theorem basisSets_nonempty [Nonempty ΞΉ] : p.basisSets.Nonempty := by
let i := Classical.arbitrary ΞΉ
refine nonempty_def.mpr β¨(p i).ball 0 1, ?_β©
exact p.basisSets_singleton_mem i zero_lt_one
theorem basisSets_intersect (U V : Set E) (hU : U β p.basisSets) (hV : V β p.basisSets) :
β z β p.basisSets, z β U β© V := by
classical
rcases p.basisSets_iff.mp hU with β¨s, rβ, hrβ, hUβ©
rcases p.basisSets_iff.mp hV with β¨t, rβ, hrβ, hVβ©
use ((s βͺ t).sup p).ball 0 (min rβ rβ)
refine β¨p.basisSets_mem (s βͺ t) (lt_min_iff.mpr β¨hrβ, hrββ©), ?_β©
rw [hU, hV, ball_finset_sup_eq_iInter _ _ _ (lt_min_iff.mpr β¨hrβ, hrββ©),
ball_finset_sup_eq_iInter _ _ _ hrβ, ball_finset_sup_eq_iInter _ _ _ hrβ]
exact
Set.subset_inter
(Set.iInterβ_mono' fun i hi =>
β¨i, Finset.subset_union_left hi, ball_mono <| min_le_left _ _β©)
(Set.iInterβ_mono' fun i hi =>
β¨i, Finset.subset_union_right hi, ball_mono <| min_le_right _ _β©)
theorem basisSets_zero (U) (hU : U β p.basisSets) : (0 : E) β U := by
rcases p.basisSets_iff.mp hU with β¨ΞΉ', r, hr, hUβ©
rw [hU, mem_ball_zero, map_zero]
exact hr
theorem basisSets_add (U) (hU : U β p.basisSets) :
β V β p.basisSets, V + V β U := by
rcases p.basisSets_iff.mp hU with β¨s, r, hr, hUβ©
use (s.sup p).ball 0 (r / 2)
| refine β¨p.basisSets_mem s (div_pos hr zero_lt_two), ?_β©
refine Set.Subset.trans (ball_add_ball_subset (s.sup p) (r / 2) (r / 2) 0 0) ?_
rw [hU, add_zero, add_halves]
| Mathlib/Analysis/LocallyConvex/WithSeminorms.lean | 117 | 120 |
/-
Copyright (c) 2020 Markus Himmel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Markus Himmel
-/
import Mathlib.CategoryTheory.Abelian.Exact
import Mathlib.CategoryTheory.Comma.Over.Basic
import Mathlib.Algebra.Category.ModuleCat.EpiMono
/-!
# Pseudoelements in abelian categories
A *pseudoelement* of an object `X` in an abelian category `C` is an equivalence class of arrows
ending in `X`, where two arrows are considered equivalent if we can find two epimorphisms with a
common domain making a commutative square with the two arrows. While the construction shows that
pseudoelements are actually subobjects of `X` rather than "elements", it is possible to chase these
pseudoelements through commutative diagrams in an abelian category to prove exactness properties.
This is done using some "diagram-chasing metatheorems" proved in this file. In many cases, a proof
in the category of abelian groups can more or less directly be converted into a proof using
pseudoelements.
A classic application of pseudoelements are diagram lemmas like the four lemma or the snake lemma.
Pseudoelements are in some ways weaker than actual elements in a concrete category. The most
important limitation is that there is no extensionality principle: If `f g : X βΆ Y`, then
`β x β X, f x = g x` does not necessarily imply that `f = g` (however, if `f = 0` or `g = 0`,
it does). A corollary of this is that we can not define arrows in abelian categories by dictating
their action on pseudoelements. Thus, a usual style of proofs in abelian categories is this:
First, we construct some morphism using universal properties, and then we use diagram chasing
of pseudoelements to verify that is has some desirable property such as exactness.
It should be noted that the Freyd-Mitchell embedding theorem
(see `CategoryTheory.Abelian.FreydMitchell`) gives a vastly stronger notion of
pseudoelement (in particular one that gives extensionality) and this file should be updated to
go use that instead!
## Main results
We define the type of pseudoelements of an object and, in particular, the zero pseudoelement.
We prove that every morphism maps the zero pseudoelement to the zero pseudoelement (`apply_zero`)
and that a zero morphism maps every pseudoelement to the zero pseudoelement (`zero_apply`).
Here are the metatheorems we provide:
* A morphism `f` is zero if and only if it is the zero function on pseudoelements.
* A morphism `f` is an epimorphism if and only if it is surjective on pseudoelements.
* A morphism `f` is a monomorphism if and only if it is injective on pseudoelements
if and only if `β a, f a = 0 β f = 0`.
* A sequence `f, g` of morphisms is exact if and only if
`β a, g (f a) = 0` and `β b, g b = 0 β β a, f a = b`.
* If `f` is a morphism and `a, a'` are such that `f a = f a'`, then there is some
pseudoelement `a''` such that `f a'' = 0` and for every `g` we have
`g a' = 0 β g a = g a''`. We can think of `a''` as `a - a'`, but don't get too carried away
by that: pseudoelements of an object do not form an abelian group.
## Notations
We introduce coercions from an object of an abelian category to the set of its pseudoelements
and from a morphism to the function it induces on pseudoelements.
These coercions must be explicitly enabled via local instances:
`attribute [local instance] objectToSort homToFun`
## Implementation notes
It appears that sometimes the coercion from morphisms to functions does not work, i.e.,
writing `g a` raises a "function expected" error. This error can be fixed by writing
`(g : X βΆ Y) a`.
## References
* [F. Borceux, *Handbook of Categorical Algebra 2*][borceux-vol2]
-/
open CategoryTheory
open CategoryTheory.Limits
open CategoryTheory.Abelian
open CategoryTheory.Preadditive
universe v u
namespace CategoryTheory.Abelian
variable {C : Type u} [Category.{v} C]
attribute [local instance] Over.coeFromHom
/-- This is just composition of morphisms in `C`. Another way to express this would be
`(Over.map f).obj a`, but our definition has nicer definitional properties. -/
def app {P Q : C} (f : P βΆ Q) (a : Over P) : Over Q :=
a.hom β« f
@[simp]
theorem app_hom {P Q : C} (f : P βΆ Q) (a : Over P) : (app f a).hom = a.hom β« f := rfl
/-- Two arrows `f : X βΆ P` and `g : Y βΆ P` are called pseudo-equal if there is some object
`R` and epimorphisms `p : R βΆ X` and `q : R βΆ Y` such that `p β« f = q β« g`. -/
def PseudoEqual (P : C) (f g : Over P) : Prop :=
β (R : C) (p : R βΆ f.1) (q : R βΆ g.1) (_ : Epi p) (_ : Epi q), p β« f.hom = q β« g.hom
theorem pseudoEqual_refl {P : C} : Reflexive (PseudoEqual P) :=
fun f => β¨f.1, π f.1, π f.1, inferInstance, inferInstance, by simpβ©
theorem pseudoEqual_symm {P : C} : Symmetric (PseudoEqual P) :=
fun _ _ β¨R, p, q, ep, Eq, commβ© => β¨R, q, p, Eq, ep, comm.symmβ©
variable [Abelian.{v} C]
section
/-- Pseudoequality is transitive: Just take the pullback. The pullback morphisms will
be epimorphisms since in an abelian category, pullbacks of epimorphisms are epimorphisms. -/
theorem pseudoEqual_trans {P : C} : Transitive (PseudoEqual P) := by
intro f g h β¨R, p, q, ep, Eq, commβ© β¨R', p', q', ep', eq', comm'β©
refine β¨pullback q p', pullback.fst _ _ β« p, pullback.snd _ _ β« q',
epi_comp _ _, epi_comp _ _, ?_β©
rw [Category.assoc, comm, β Category.assoc, pullback.condition, Category.assoc, comm',
Category.assoc]
end
/-- The arrows with codomain `P` equipped with the equivalence relation of being pseudo-equal. -/
def Pseudoelement.setoid (P : C) : Setoid (Over P) :=
β¨_, β¨pseudoEqual_refl, @pseudoEqual_symm _ _ _, @pseudoEqual_trans _ _ _ _β©β©
attribute [local instance] Pseudoelement.setoid
/-- A `Pseudoelement` of `P` is just an equivalence class of arrows ending in `P` by being
pseudo-equal. -/
def Pseudoelement (P : C) : Type max u v :=
Quotient (Pseudoelement.setoid P)
namespace Pseudoelement
/-- A coercion from an object of an abelian category to its pseudoelements. -/
def objectToSort : CoeSort C (Type max u v) :=
β¨fun P => Pseudoelement Pβ©
attribute [local instance] objectToSort
scoped[Pseudoelement] attribute [instance] CategoryTheory.Abelian.Pseudoelement.objectToSort
/-- A coercion from an arrow with codomain `P` to its associated pseudoelement. -/
def overToSort {P : C} : Coe (Over P) (Pseudoelement P) :=
β¨Quot.mk (PseudoEqual P)β©
attribute [local instance] overToSort
theorem over_coe_def {P Q : C} (a : Q βΆ P) : (a : Pseudoelement P) = β¦βaβ§ := rfl
/-- If two elements are pseudo-equal, then their composition with a morphism is, too. -/
theorem pseudoApply_aux {P Q : C} (f : P βΆ Q) (a b : Over P) : a β b β app f a β app f b :=
fun β¨R, p, q, ep, Eq, commβ© =>
β¨R, p, q, ep, Eq, show p β« a.hom β« f = q β« b.hom β« f by rw [reassoc_of% comm]β©
/-- A morphism `f` induces a function `pseudoApply f` on pseudoelements. -/
def pseudoApply {P Q : C} (f : P βΆ Q) : P β Q :=
Quotient.map (fun g : Over P => app f g) (pseudoApply_aux f)
/-- A coercion from morphisms to functions on pseudoelements. -/
def homToFun {P Q : C} : CoeFun (P βΆ Q) fun _ => P β Q :=
β¨pseudoApplyβ©
attribute [local instance] homToFun
scoped[Pseudoelement] attribute [instance] CategoryTheory.Abelian.Pseudoelement.homToFun
theorem pseudoApply_mk' {P Q : C} (f : P βΆ Q) (a : Over P) : f β¦aβ§ = β¦β(a.hom β« f)β§ := rfl
/-- Applying a pseudoelement to a composition of morphisms is the same as composing
with each morphism. Sadly, this is not a definitional equality, but at least it is
true. -/
theorem comp_apply {P Q R : C} (f : P βΆ Q) (g : Q βΆ R) (a : P) : (f β« g) a = g (f a) :=
Quotient.inductionOn a fun x =>
Quotient.sound <| by
simp only [app]
rw [β Category.assoc, Over.coe_hom]
/-- Composition of functions on pseudoelements is composition of morphisms. -/
theorem comp_comp {P Q R : C} (f : P βΆ Q) (g : Q βΆ R) : g β f = f β« g :=
funext fun _ => (comp_apply _ _ _).symm
section Zero
/-!
In this section we prove that for every `P` there is an equivalence class that contains
precisely all the zero morphisms ending in `P` and use this to define *the* zero
pseudoelement.
-/
section
attribute [local instance] HasBinaryBiproducts.of_hasBinaryProducts
/-- The arrows pseudo-equal to a zero morphism are precisely the zero morphisms. -/
theorem pseudoZero_aux {P : C} (Q : C) (f : Over P) : f β (0 : Q βΆ P) β f.hom = 0 :=
β¨fun β¨R, p, q, _, _, commβ© => zero_of_epi_comp p (by simp [comm]), fun hf =>
β¨biprod f.1 Q, biprod.fst, biprod.snd, inferInstance, inferInstance, by
rw [hf, Over.coe_hom, HasZeroMorphisms.comp_zero, HasZeroMorphisms.comp_zero]β©β©
end
theorem zero_eq_zero' {P Q R : C} :
(β¦((0 : Q βΆ P) : Over P)β§ : Pseudoelement P) = β¦((0 : R βΆ P) : Over P)β§ :=
Quotient.sound <| (pseudoZero_aux R _).2 rfl
/-- The zero pseudoelement is the class of a zero morphism. -/
def pseudoZero {P : C} : P :=
β¦(0 : P βΆ P)β§
-- Porting note: in mathlib3, we couldn't make this an instance
-- as it would have fired on `coe_sort`.
-- However now that coercions are treated differently, this is a structural instance triggered by
-- the appearance of `Pseudoelement`.
instance hasZero {P : C} : Zero P :=
β¨pseudoZeroβ©
instance {P : C} : Inhabited P :=
β¨0β©
theorem pseudoZero_def {P : C} : (0 : Pseudoelement P) = β¦β(0 : P βΆ P)β§ := rfl
@[simp]
theorem zero_eq_zero {P Q : C} : β¦((0 : Q βΆ P) : Over P)β§ = (0 : Pseudoelement P) :=
zero_eq_zero'
/-- The pseudoelement induced by an arrow is zero precisely when that arrow is zero. -/
theorem pseudoZero_iff {P : C} (a : Over P) : a = (0 : P) β a.hom = 0 := by
rw [β pseudoZero_aux P a]
exact Quotient.eq'
end Zero
open Pseudoelement
/-- Morphisms map the zero pseudoelement to the zero pseudoelement. -/
@[simp]
theorem apply_zero {P Q : C} (f : P βΆ Q) : f 0 = 0 := by
rw [pseudoZero_def, pseudoApply_mk']
simp
/-- The zero morphism maps every pseudoelement to 0. -/
@[simp]
theorem zero_apply {P : C} (Q : C) (a : P) : (0 : P βΆ Q) a = 0 :=
Quotient.inductionOn a fun a' => by
rw [pseudoZero_def, pseudoApply_mk']
simp
/-- An extensionality lemma for being the zero arrow. -/
theorem zero_morphism_ext {P Q : C} (f : P βΆ Q) : (β a, f a = 0) β f = 0 := fun h => by
rw [β Category.id_comp f]
exact (pseudoZero_iff (π P β« f : Over Q)).1 (h (π P))
theorem zero_morphism_ext' {P Q : C} (f : P βΆ Q) : (β a, f a = 0) β 0 = f :=
Eq.symm β zero_morphism_ext f
theorem eq_zero_iff {P Q : C} (f : P βΆ Q) : f = 0 β β a, f a = 0 :=
β¨fun h a => by simp [h], zero_morphism_ext _β©
/-- A monomorphism is injective on pseudoelements. -/
theorem pseudo_injective_of_mono {P Q : C} (f : P βΆ Q) [Mono f] : Function.Injective f := by
intro abar abar'
refine Quotient.inductionOnβ abar abar' fun a a' ha => ?_
apply Quotient.sound
have : (β¦(a.hom β« f : Over Q)β§ : Quotient (setoid Q)) = β¦β(a'.hom β« f)β§ := by convert ha
have β¨R, p, q, ep, Eq, commβ© := Quotient.exact this
exact β¨R, p, q, ep, Eq, (cancel_mono f).1 <| by
simp only [Category.assoc]
exact commβ©
/-- A morphism that is injective on pseudoelements only maps the zero element to zero. -/
theorem zero_of_map_zero {P Q : C} (f : P βΆ Q) : Function.Injective f β β a, f a = 0 β a = 0 :=
fun h a ha => by
rw [β apply_zero f] at ha
exact h ha
/-- A morphism that only maps the zero pseudoelement to zero is a monomorphism. -/
theorem mono_of_zero_of_map_zero {P Q : C} (f : P βΆ Q) : (β a, f a = 0 β a = 0) β Mono f :=
fun h => (mono_iff_cancel_zero _).2 fun _ g hg =>
(pseudoZero_iff (g : Over P)).1 <|
h _ <| show f g = 0 from (pseudoZero_iff (g β« f : Over Q)).2 hg
section
/-- An epimorphism is surjective on pseudoelements. -/
theorem pseudo_surjective_of_epi {P Q : C} (f : P βΆ Q) [Epi f] : Function.Surjective f :=
fun qbar =>
Quotient.inductionOn qbar fun q =>
β¨(pullback.fst f q.hom : Over P),
Quotient.sound <|
β¨pullback f q.hom, π (pullback f q.hom), pullback.snd _ _, inferInstance, inferInstance, by
rw [Category.id_comp, β pullback.condition, app_hom, Over.coe_hom]β©β©
end
/-- A morphism that is surjective on pseudoelements is an epimorphism. -/
theorem epi_of_pseudo_surjective {P Q : C} (f : P βΆ Q) : Function.Surjective f β Epi f := by
intro h
have β¨pbar, hpbarβ© := h (π Q)
have β¨p, hpβ© := Quotient.exists_rep pbar
have : (β¦(p.hom β« f : Over Q)β§ : Quotient (setoid Q)) = β¦β(π Q)β§ := by
rw [β hp] at hpbar
exact hpbar
have β¨R, x, y, _, ey, commβ© := Quotient.exact this
apply @epi_of_epi_fac _ _ _ _ _ (x β« p.hom) f y ey
dsimp at comm
rw [Category.assoc, comm]
apply Category.comp_id
section
/-- Two morphisms in an exact sequence are exact on pseudoelements. -/
theorem pseudo_exact_of_exact {S : ShortComplex C} (hS : S.Exact) :
β b, S.g b = 0 β β a, S.f a = b :=
fun b' =>
Quotient.inductionOn b' fun b hb => by
have hb' : b.hom β« S.g = 0 := (pseudoZero_iff _).1 hb
-- By exactness, `b` factors through `im f = ker g` via some `c`.
obtain β¨c, hcβ© := KernelFork.IsLimit.lift' hS.isLimitImage _ hb'
-- We compute the pullback of the map into the image and `c`.
-- The pseudoelement induced by the first pullback map will be our preimage.
use pullback.fst (Abelian.factorThruImage S.f) c
-- It remains to show that the image of this element under `f` is pseudo-equal to `b`.
apply Quotient.sound
refine β¨pullback (Abelian.factorThruImage S.f) c, π _,
pullback.snd _ _, inferInstance, inferInstance, ?_β©
-- Now we can verify that the diagram commutes.
calc
π (pullback (Abelian.factorThruImage S.f) c) β« pullback.fst _ _ β« S.f =
pullback.fst _ _ β« S.f :=
Category.id_comp _
_ = pullback.fst _ _ β« Abelian.factorThruImage S.f β« kernel.ΞΉ (cokernel.Ο S.f) := by
rw [Abelian.image.fac]
_ = (pullback.snd _ _ β« c) β« kernel.ΞΉ (cokernel.Ο S.f) := by
rw [β Category.assoc, pullback.condition]
_ = pullback.snd _ _ β« b.hom := by
rw [Category.assoc]
congr
end
theorem apply_eq_zero_of_comp_eq_zero {P Q R : C} (f : Q βΆ R) (a : P βΆ Q) : a β« f = 0 β f a = 0 :=
fun h => by simp [over_coe_def, pseudoApply_mk', Over.coe_hom, h]
section
/-- If two morphisms are exact on pseudoelements, they are exact. -/
theorem exact_of_pseudo_exact (S : ShortComplex C)
(hS : β b, S.g b = 0 β β a, S.f a = b) : S.Exact :=
(S.exact_iff_kernel_ΞΉ_comp_cokernel_Ο_zero).2 (by
-- If we apply `g` to the pseudoelement induced by its kernel, we get 0 (of course!).
have : S.g (kernel.ΞΉ S.g) = 0 := apply_eq_zero_of_comp_eq_zero _ _ (kernel.condition _)
-- By pseudo-exactness, we get a preimage.
obtain β¨a', haβ© := hS _ this
obtain β¨a, ha'β© := Quotient.exists_rep a'
rw [β ha'] at ha
obtain β¨Z, r, q, _, eq, commβ© := Quotient.exact ha
-- Consider the pullback of `kernel.ΞΉ (cokernel.Ο f)` and `kernel.ΞΉ g`.
-- The commutative diagram given by the pseudo-equality `f a = b` induces
-- a cone over this pullback, so we get a factorization `z`.
obtain β¨z, _, hzββ© := @pullback.lift' _ _ _ _ _ _ (kernel.ΞΉ (cokernel.Ο S.f))
(kernel.ΞΉ S.g) _ (r β« a.hom β« Abelian.factorThruImage S.f) q (by
simp only [Category.assoc, Abelian.image.fac]
exact comm)
-- Let's give a name to the second pullback morphism.
let j : pullback (kernel.ΞΉ (cokernel.Ο S.f)) (kernel.ΞΉ S.g) βΆ kernel S.g := pullback.snd _ _
-- Since `q` is an epimorphism, in particular this means that `j` is an epimorphism.
haveI pe : Epi j := epi_of_epi_fac hzβ
-- But it is also a monomorphism, because `kernel.ΞΉ (cokernel.Ο f)` is: A kernel is
-- always a monomorphism and the pullback of a monomorphism is a monomorphism.
-- But mono + epi = iso, so `j` is an isomorphism.
haveI : IsIso j := isIso_of_mono_of_epi _
-- But then `kernel.ΞΉ g` can be expressed using all of the maps of the pullback square, and we
-- are done.
rw [(Iso.eq_inv_comp (asIso j)).2 pullback.condition.symm]
simp only [Category.assoc, kernel.condition, HasZeroMorphisms.comp_zero])
end
/-- If two pseudoelements `x` and `y` have the same image under some morphism `f`, then we can form
their "difference" `z`. This pseudoelement has the properties that `f z = 0` and for all
morphisms `g`, if `g y = 0` then `g z = g x`. -/
theorem sub_of_eq_image {P Q : C} (f : P βΆ Q) (x y : P) :
f x = f y β β z, f z = 0 β§ β (R : C) (g : P βΆ R), (g : P βΆ R) y = 0 β g z = g x :=
Quotient.inductionOnβ x y fun a a' h =>
match Quotient.exact h with
| β¨R, p, q, ep, _, commβ© =>
let a'' : R βΆ P := (p β« a.hom : R βΆ P) - (q β« a'.hom : R βΆ P)
β¨a'',
β¨show β¦(a'' β« f : Over Q)β§ = β¦β(0 : Q βΆ Q)β§ by
dsimp at comm
simp [a'', sub_eq_zero.2 comm],
fun Z g hh => by
obtain β¨X, p', q', ep', _, comm'β© := Quotient.exact hh
have : a'.hom β« g = 0 := by
apply (epi_iff_cancel_zero _).1 ep' _ (a'.hom β« g)
simpa using comm'
apply Quotient.sound
-- Can we prevent quotient.sound from giving us this weird `coe_b` thingy?
change app g (a'' : Over P) β app g a
exact β¨R, π R, p, inferInstance, ep, by simp [a'', sub_eq_add_neg, this]β©β©β©
variable [Limits.HasPullbacks C]
/-- If `f : P βΆ R` and `g : Q βΆ R` are morphisms and `p : P` and `q : Q` are pseudoelements such
that `f p = g q`, then there is some `s : pullback f g` such that `fst s = p` and `snd s = q`.
Remark: Borceux claims that `s` is unique, but this is false. See
`Counterexamples/Pseudoelement.lean` for details. -/
theorem pseudo_pullback {P Q R : C} {f : P βΆ R} {g : Q βΆ R} {p : P} {q : Q} :
f p = g q β
β s, pullback.fst f g s = p β§ pullback.snd f g s = q :=
Quotient.inductionOnβ p q fun x y h => by
obtain β¨Z, a, b, ea, eb, commβ© := Quotient.exact h
obtain β¨l, hlβ, hlββ© := @pullback.lift' _ _ _ _ _ _ f g _ (a β« x.hom) (b β« y.hom) (by
simp only [Category.assoc]
exact comm)
exact β¨l, β¨Quotient.sound β¨Z, π Z, a, inferInstance, ea, by rwa [Category.id_comp]β©,
Quotient.sound β¨Z, π Z, b, inferInstance, eb, by rwa [Category.id_comp]β©β©β©
section Module
/-- In the category `Module R`, if `x` and `y` are pseudoequal, then the range of the associated
morphisms is the same. -/
theorem ModuleCat.eq_range_of_pseudoequal {R : Type*} [Ring R] {G : ModuleCat R} {x y : Over G}
(h : PseudoEqual G x y) : LinearMap.range x.hom.hom = LinearMap.range y.hom.hom := by
obtain β¨P, p, q, hp, hq, Hβ© := h
refine Submodule.ext fun a => β¨fun ha => ?_, fun ha => ?_β©
Β· obtain β¨a', ha'β© := ha
obtain β¨a'', ha''β© := (ModuleCat.epi_iff_surjective p).1 hp a'
| refine β¨q a'', ?_β©
dsimp at ha' β’
rw [β LinearMap.comp_apply, β ModuleCat.hom_comp, β H,
ModuleCat.hom_comp, LinearMap.comp_apply, ha'', ha']
Β· obtain β¨a', ha'β© := ha
obtain β¨a'', ha''β© := (ModuleCat.epi_iff_surjective q).1 hq a'
refine β¨p a'', ?_β©
dsimp at ha' β’
rw [β LinearMap.comp_apply, β ModuleCat.hom_comp, H, ModuleCat.hom_comp, LinearMap.comp_apply,
ha'', ha']
end Module
end Pseudoelement
end CategoryTheory.Abelian
| Mathlib/CategoryTheory/Abelian/Pseudoelements.lean | 436 | 454 |
/-
Copyright (c) 2022 Yuma Mizuno. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yuma Mizuno
-/
import Mathlib.CategoryTheory.Bicategory.Coherence
import Mathlib.Tactic.CategoryTheory.BicategoricalComp
/-!
# A `coherence` tactic for bicategories
We provide a `bicategory_coherence` tactic,
which proves that any two 2-morphisms (with the same source and target)
in a bicategory which are built out of associators and unitors
are equal.
This file mainly deals with the type class setup for the coherence tactic. The actual front end
tactic is given in `Mathlib.Tactic.CategoryTheory.Coherence` at the same time as the coherence
tactic for monoidal categories.
-/
noncomputable section
universe w v u
open CategoryTheory CategoryTheory.FreeBicategory
open scoped Bicategory
variable {B : Type u} [Bicategory.{w, v} B] {a b c d : B}
namespace Mathlib.Tactic.BicategoryCoherence
/-- A typeclass carrying a choice of lift of a 1-morphism from `B` to `FreeBicategory B`. -/
class LiftHom {a b : B} (f : a βΆ b) where
/-- A lift of a morphism to the free bicategory.
This should only exist for "structural" morphisms. -/
lift : of.obj a βΆ of.obj b
instance liftHomId : LiftHom (π a) where lift := π (of.obj a)
instance liftHomComp (f : a βΆ b) (g : b βΆ c) [LiftHom f] [LiftHom g] : LiftHom (f β« g) where
lift := LiftHom.lift f β« LiftHom.lift g
instance (priority := 100) liftHomOf (f : a βΆ b) : LiftHom f where lift := of.map f
/-- A typeclass carrying a choice of lift of a 2-morphism from `B` to `FreeBicategory B`. -/
class LiftHomβ {f g : a βΆ b} [LiftHom f] [LiftHom g] (Ξ· : f βΆ g) where
/-- A lift of a 2-morphism to the free bicategory.
This should only exist for "structural" 2-morphisms. -/
lift : LiftHom.lift f βΆ LiftHom.lift g
instance liftHomβId (f : a βΆ b) [LiftHom f] : LiftHomβ (π f) where
lift := π _
instance liftHomβLeftUnitorHom (f : a βΆ b) [LiftHom f] : LiftHomβ (Ξ»_ f).hom where
lift := (Ξ»_ (LiftHom.lift f)).hom
instance liftHomβLeftUnitorInv (f : a βΆ b) [LiftHom f] : LiftHomβ (Ξ»_ f).inv where
lift := (Ξ»_ (LiftHom.lift f)).inv
instance liftHomβRightUnitorHom (f : a βΆ b) [LiftHom f] : LiftHomβ (Ο_ f).hom where
lift := (Ο_ (LiftHom.lift f)).hom
instance liftHomβRightUnitorInv (f : a βΆ b) [LiftHom f] : LiftHomβ (Ο_ f).inv where
lift := (Ο_ (LiftHom.lift f)).inv
instance liftHomβAssociatorHom (f : a βΆ b) (g : b βΆ c) (h : c βΆ d) [LiftHom f] [LiftHom g]
[LiftHom h] : LiftHomβ (Ξ±_ f g h).hom where
lift := (Ξ±_ (LiftHom.lift f) (LiftHom.lift g) (LiftHom.lift h)).hom
instance liftHomβAssociatorInv (f : a βΆ b) (g : b βΆ c) (h : c βΆ d) [LiftHom f] [LiftHom g]
[LiftHom h] : LiftHomβ (Ξ±_ f g h).inv where
lift := (Ξ±_ (LiftHom.lift f) (LiftHom.lift g) (LiftHom.lift h)).inv
instance liftHomβComp {f g h : a βΆ b} [LiftHom f] [LiftHom g] [LiftHom h] (Ξ· : f βΆ g) (ΞΈ : g βΆ h)
[LiftHomβ Ξ·] [LiftHomβ ΞΈ] : LiftHomβ (Ξ· β« ΞΈ) where
lift := LiftHomβ.lift Ξ· β« LiftHomβ.lift ΞΈ
instance liftHomβWhiskerLeft (f : a βΆ b) [LiftHom f] {g h : b βΆ c} (Ξ· : g βΆ h) [LiftHom g]
[LiftHom h] [LiftHomβ Ξ·] : LiftHomβ (f β Ξ·) where
lift := LiftHom.lift f β LiftHomβ.lift Ξ·
instance liftHomβWhiskerRight {f g : a βΆ b} (Ξ· : f βΆ g) [LiftHom f] [LiftHom g] [LiftHomβ Ξ·]
{h : b βΆ c} [LiftHom h] : LiftHomβ (Ξ· β· h) where
lift := LiftHomβ.lift Ξ· β· LiftHom.lift h
open Lean Elab Tactic Meta
/-- Helper function for throwing exceptions. -/
def exception {Ξ± : Type} (g : MVarId) (msg : MessageData) : MetaM Ξ± :=
throwTacticEx `bicategorical_coherence g msg
/-- Helper function for throwing exceptions with respect to the main goal. -/
def exception' (msg : MessageData) : TacticM Unit := do
try
liftMetaTactic (exception (msg := msg))
catch _ =>
-- There might not be any goals
throwError msg
set_option quotPrecheck false in
/-- Auxiliary definition for `bicategorical_coherence`. -/
-- We could construct this expression directly without using `elabTerm`,
-- but it would require preparing many implicit arguments by hand.
def mkLiftMapβLiftExpr (e : Expr) : TermElabM Expr := do
Term.elabTerm
(β ``((FreeBicategory.lift (Prefunctor.id _)).mapβ (LiftHomβ.lift $(β Term.exprToSyntax e))))
none
/-- Coherence tactic for bicategories. -/
def bicategory_coherence (g : MVarId) : TermElabM Unit := g.withContext do
withOptions (fun opts => synthInstance.maxSize.set opts
(max 256 (synthInstance.maxSize.get opts))) do
let thms := [``BicategoricalCoherence.iso, ``Iso.trans, ``Iso.symm, ``Iso.refl,
``Bicategory.whiskerRightIso, ``Bicategory.whiskerLeftIso].foldl
(Β·.addDeclToUnfoldCore Β·) {}
let (ty, _) β dsimp (β g.getType) (β Simp.mkContext (simpTheorems := #[thms]))
let some (_, lhs, rhs) := (β whnfR ty).eq? | exception g "Not an equation of morphisms."
let lift_lhs β mkLiftMapβLiftExpr lhs
let lift_rhs β mkLiftMapβLiftExpr rhs
-- This new equation is defeq to the original by assumption
-- on the `LiftHom` instances.
let gβ β g.change (β mkEq lift_lhs lift_rhs)
let [gβ] β gβ.applyConst ``congrArg
| exception g "congrArg failed in coherence"
let [] β gβ.applyConst ``Subsingleton.elim
| exception g "This shouldn't happen; Subsingleton.elim does not create goals."
/-- Coherence tactic for bicategories.
Use `pure_coherence` instead, which is a frontend to this one. -/
elab "bicategory_coherence" : tactic => do bicategory_coherence (β getMainGoal)
open Lean.Parser.Tactic
/--
Simp lemmas for rewriting a 2-morphism into a normal form.
-/
syntax (name := whisker_simps) "whisker_simps" optConfig : tactic
@[inherit_doc whisker_simps]
elab_rules : tactic
| `(tactic| whisker_simps $cfg) => do
evalTactic (β `(tactic|
simp $cfg only [Category.assoc,
Bicategory.comp_whiskerLeft, Bicategory.id_whiskerLeft,
Bicategory.whiskerRight_comp, Bicategory.whiskerRight_id,
Bicategory.whiskerLeft_comp, Bicategory.whiskerLeft_id,
Bicategory.comp_whiskerRight, Bicategory.id_whiskerRight, Bicategory.whisker_assoc]
))
-- We have unused typeclass arguments here.
-- They are intentional, to ensure that `simp only [assoc_liftHomβ]` only left associates
-- bicategorical structural morphisms.
/-- Auxiliary simp lemma for the `coherence` tactic:
this move brackets to the left in order to expose a maximal prefix
built out of unitors and associators.
-/
@[nolint unusedArguments]
theorem assoc_liftHomβ {f g h i : a βΆ b} [LiftHom f] [LiftHom g] [LiftHom h]
(Ξ· : f βΆ g) (ΞΈ : g βΆ h) (ΞΉ : h βΆ i) [LiftHomβ Ξ·] [LiftHomβ ΞΈ] : Ξ· β« ΞΈ β« ΞΉ = (Ξ· β« ΞΈ) β« ΞΉ :=
(Category.assoc _ _ _).symm
end Mathlib.Tactic.BicategoryCoherence
| Mathlib/Tactic/CategoryTheory/BicategoryCoherence.lean | 242 | 243 | |
/-
Copyright (c) 2017 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Johannes HΓΆlzl, Patrick Massot
-/
import Mathlib.Data.Set.Image
import Mathlib.Data.SProd
/-!
# Sets in product and pi types
This file proves basic properties of product of sets in `Ξ± Γ Ξ²` and in `Ξ i, Ξ± i`, and of the
diagonal of a type.
## Main declarations
This file contains basic results on the following notions, which are defined in `Set.Operations`.
* `Set.prod`: Binary product of sets. For `s : Set Ξ±`, `t : Set Ξ²`, we have
`s.prod t : Set (Ξ± Γ Ξ²)`. Denoted by `s ΓΛ’ t`.
* `Set.diagonal`: Diagonal of a type. `Set.diagonal Ξ± = {(x, x) | x : Ξ±}`.
* `Set.offDiag`: Off-diagonal. `s ΓΛ’ s` without the diagonal.
* `Set.pi`: Arbitrary product of sets.
-/
open Function
namespace Set
/-! ### Cartesian binary product of sets -/
section Prod
variable {Ξ± Ξ² Ξ³ Ξ΄ : Type*} {s sβ sβ : Set Ξ±} {t tβ tβ : Set Ξ²} {a : Ξ±} {b : Ξ²}
theorem Subsingleton.prod (hs : s.Subsingleton) (ht : t.Subsingleton) :
(s ΓΛ’ t).Subsingleton := fun _x hx _y hy β¦
Prod.ext (hs hx.1 hy.1) (ht hx.2 hy.2)
noncomputable instance decidableMemProd [DecidablePred (Β· β s)] [DecidablePred (Β· β t)] :
DecidablePred (Β· β s ΓΛ’ t) := fun x => inferInstanceAs (Decidable (x.1 β s β§ x.2 β t))
@[gcongr]
theorem prod_mono (hs : sβ β sβ) (ht : tβ β tβ) : sβ ΓΛ’ tβ β sβ ΓΛ’ tβ :=
fun _ β¨hβ, hββ© => β¨hs hβ, ht hββ©
@[gcongr]
theorem prod_mono_left (hs : sβ β sβ) : sβ ΓΛ’ t β sβ ΓΛ’ t :=
prod_mono hs Subset.rfl
@[gcongr]
theorem prod_mono_right (ht : tβ β tβ) : s ΓΛ’ tβ β s ΓΛ’ tβ :=
prod_mono Subset.rfl ht
@[simp]
theorem prod_self_subset_prod_self : sβ ΓΛ’ sβ β sβ ΓΛ’ sβ β sβ β sβ :=
β¨fun h _ hx => (h (mk_mem_prod hx hx)).1, fun h _ hx => β¨h hx.1, h hx.2β©β©
@[simp]
theorem prod_self_ssubset_prod_self : sβ ΓΛ’ sβ β sβ ΓΛ’ sβ β sβ β sβ :=
and_congr prod_self_subset_prod_self <| not_congr prod_self_subset_prod_self
theorem prod_subset_iff {P : Set (Ξ± Γ Ξ²)} : s ΓΛ’ t β P β β x β s, β y β t, (x, y) β P :=
β¨fun h _ hx _ hy => h (mk_mem_prod hx hy), fun h β¨_, _β© hp => h _ hp.1 _ hp.2β©
theorem forall_prod_set {p : Ξ± Γ Ξ² β Prop} : (β x β s ΓΛ’ t, p x) β β x β s, β y β t, p (x, y) :=
prod_subset_iff
theorem exists_prod_set {p : Ξ± Γ Ξ² β Prop} : (β x β s ΓΛ’ t, p x) β β x β s, β y β t, p (x, y) := by
simp [and_assoc]
@[simp]
theorem prod_empty : s ΓΛ’ (β
: Set Ξ²) = β
:= by
ext
exact iff_of_eq (and_false _)
@[simp]
theorem empty_prod : (β
: Set Ξ±) ΓΛ’ t = β
:= by
ext
exact iff_of_eq (false_and _)
@[simp, mfld_simps]
theorem univ_prod_univ : @univ Ξ± ΓΛ’ @univ Ξ² = univ := by
ext
exact iff_of_eq (true_and _)
theorem univ_prod {t : Set Ξ²} : (univ : Set Ξ±) ΓΛ’ t = Prod.snd β»ΒΉ' t := by simp [prod_eq]
theorem prod_univ {s : Set Ξ±} : s ΓΛ’ (univ : Set Ξ²) = Prod.fst β»ΒΉ' s := by simp [prod_eq]
@[simp] lemma prod_eq_univ [Nonempty Ξ±] [Nonempty Ξ²] : s ΓΛ’ t = univ β s = univ β§ t = univ := by
simp [eq_univ_iff_forall, forall_and]
theorem singleton_prod : ({a} : Set Ξ±) ΓΛ’ t = Prod.mk a '' t := by
ext β¨x, yβ©
simp [and_left_comm, eq_comm]
theorem prod_singleton : s ΓΛ’ ({b} : Set Ξ²) = (fun a => (a, b)) '' s := by
ext β¨x, yβ©
simp [and_left_comm, eq_comm]
@[simp]
theorem singleton_prod_singleton : ({a} : Set Ξ±) ΓΛ’ ({b} : Set Ξ²) = {(a, b)} := by ext β¨c, dβ©; simp
@[simp]
theorem union_prod : (sβ βͺ sβ) ΓΛ’ t = sβ ΓΛ’ t βͺ sβ ΓΛ’ t := by
ext β¨x, yβ©
simp [or_and_right]
@[simp]
theorem prod_union : s ΓΛ’ (tβ βͺ tβ) = s ΓΛ’ tβ βͺ s ΓΛ’ tβ := by
ext β¨x, yβ©
simp [and_or_left]
theorem inter_prod : (sβ β© sβ) ΓΛ’ t = sβ ΓΛ’ t β© sβ ΓΛ’ t := by
ext β¨x, yβ©
simp only [β and_and_right, mem_inter_iff, mem_prod]
theorem prod_inter : s ΓΛ’ (tβ β© tβ) = s ΓΛ’ tβ β© s ΓΛ’ tβ := by
ext β¨x, yβ©
simp only [β and_and_left, mem_inter_iff, mem_prod]
@[mfld_simps]
theorem prod_inter_prod : sβ ΓΛ’ tβ β© sβ ΓΛ’ tβ = (sβ β© sβ) ΓΛ’ (tβ β© tβ) := by
ext β¨x, yβ©
simp [and_assoc, and_left_comm]
lemma compl_prod_eq_union {Ξ± Ξ² : Type*} (s : Set Ξ±) (t : Set Ξ²) :
(s ΓΛ’ t)αΆ = (sαΆ ΓΛ’ univ) βͺ (univ ΓΛ’ tαΆ) := by
ext p
simp only [mem_compl_iff, mem_prod, not_and, mem_union, mem_univ, and_true, true_and]
constructor <;> intro h
Β· by_cases fst_in_s : p.fst β s
Β· exact Or.inr (h fst_in_s)
Β· exact Or.inl fst_in_s
Β· intro fst_in_s
simpa only [fst_in_s, not_true, false_or] using h
@[simp]
theorem disjoint_prod : Disjoint (sβ ΓΛ’ tβ) (sβ ΓΛ’ tβ) β Disjoint sβ sβ β¨ Disjoint tβ tβ := by
simp_rw [disjoint_left, mem_prod, not_and_or, Prod.forall, and_imp, β @forall_or_right Ξ±, β
@forall_or_left Ξ², β @forall_or_right (_ β sβ), β @forall_or_left (_ β tβ)]
theorem Disjoint.set_prod_left (hs : Disjoint sβ sβ) (tβ tβ : Set Ξ²) :
Disjoint (sβ ΓΛ’ tβ) (sβ ΓΛ’ tβ) :=
disjoint_left.2 fun β¨_a, _bβ© β¨haβ, _β© β¨haβ, _β© => disjoint_left.1 hs haβ haβ
theorem Disjoint.set_prod_right (ht : Disjoint tβ tβ) (sβ sβ : Set Ξ±) :
Disjoint (sβ ΓΛ’ tβ) (sβ ΓΛ’ tβ) :=
disjoint_left.2 fun β¨_a, _bβ© β¨_, hbββ© β¨_, hbββ© => disjoint_left.1 ht hbβ hbβ
theorem prodMap_image_prod (f : Ξ± β Ξ²) (g : Ξ³ β Ξ΄) (s : Set Ξ±) (t : Set Ξ³) :
(Prod.map f g) '' (s ΓΛ’ t) = (f '' s) ΓΛ’ (g '' t) := by
ext
aesop
theorem insert_prod : insert a s ΓΛ’ t = Prod.mk a '' t βͺ s ΓΛ’ t := by
simp only [insert_eq, union_prod, singleton_prod]
theorem prod_insert : s ΓΛ’ insert b t = (fun a => (a, b)) '' s βͺ s ΓΛ’ t := by
simp only [insert_eq, prod_union, prod_singleton]
theorem prod_preimage_eq {f : Ξ³ β Ξ±} {g : Ξ΄ β Ξ²} :
(f β»ΒΉ' s) ΓΛ’ (g β»ΒΉ' t) = (fun p : Ξ³ Γ Ξ΄ => (f p.1, g p.2)) β»ΒΉ' s ΓΛ’ t :=
rfl
theorem prod_preimage_left {f : Ξ³ β Ξ±} :
(f β»ΒΉ' s) ΓΛ’ t = (fun p : Ξ³ Γ Ξ² => (f p.1, p.2)) β»ΒΉ' s ΓΛ’ t :=
rfl
theorem prod_preimage_right {g : Ξ΄ β Ξ²} :
s ΓΛ’ (g β»ΒΉ' t) = (fun p : Ξ± Γ Ξ΄ => (p.1, g p.2)) β»ΒΉ' s ΓΛ’ t :=
rfl
theorem preimage_prod_map_prod (f : Ξ± β Ξ²) (g : Ξ³ β Ξ΄) (s : Set Ξ²) (t : Set Ξ΄) :
Prod.map f g β»ΒΉ' s ΓΛ’ t = (f β»ΒΉ' s) ΓΛ’ (g β»ΒΉ' t) :=
rfl
theorem mk_preimage_prod (f : Ξ³ β Ξ±) (g : Ξ³ β Ξ²) :
(fun x => (f x, g x)) β»ΒΉ' s ΓΛ’ t = f β»ΒΉ' s β© g β»ΒΉ' t :=
rfl
@[simp]
theorem mk_preimage_prod_left (hb : b β t) : (fun a => (a, b)) β»ΒΉ' s ΓΛ’ t = s := by
ext a
simp [hb]
@[simp]
theorem mk_preimage_prod_right (ha : a β s) : Prod.mk a β»ΒΉ' s ΓΛ’ t = t := by
ext b
simp [ha]
@[simp]
theorem mk_preimage_prod_left_eq_empty (hb : b β t) : (fun a => (a, b)) β»ΒΉ' s ΓΛ’ t = β
:= by
ext a
simp [hb]
@[simp]
theorem mk_preimage_prod_right_eq_empty (ha : a β s) : Prod.mk a β»ΒΉ' s ΓΛ’ t = β
:= by
ext b
simp [ha]
theorem mk_preimage_prod_left_eq_if [DecidablePred (Β· β t)] :
(fun a => (a, b)) β»ΒΉ' s ΓΛ’ t = if b β t then s else β
:= by split_ifs with h <;> simp [h]
theorem mk_preimage_prod_right_eq_if [DecidablePred (Β· β s)] :
Prod.mk a β»ΒΉ' s ΓΛ’ t = if a β s then t else β
:= by split_ifs with h <;> simp [h]
theorem mk_preimage_prod_left_fn_eq_if [DecidablePred (Β· β t)] (f : Ξ³ β Ξ±) :
(fun a => (f a, b)) β»ΒΉ' s ΓΛ’ t = if b β t then f β»ΒΉ' s else β
:= by
rw [β mk_preimage_prod_left_eq_if, prod_preimage_left, preimage_preimage]
theorem mk_preimage_prod_right_fn_eq_if [DecidablePred (Β· β s)] (g : Ξ΄ β Ξ²) :
(fun b => (a, g b)) β»ΒΉ' s ΓΛ’ t = if a β s then g β»ΒΉ' t else β
:= by
rw [β mk_preimage_prod_right_eq_if, prod_preimage_right, preimage_preimage]
@[simp]
theorem preimage_swap_prod (s : Set Ξ±) (t : Set Ξ²) : Prod.swap β»ΒΉ' s ΓΛ’ t = t ΓΛ’ s := by
ext β¨x, yβ©
simp [and_comm]
@[simp]
theorem image_swap_prod (s : Set Ξ±) (t : Set Ξ²) : Prod.swap '' s ΓΛ’ t = t ΓΛ’ s := by
rw [image_swap_eq_preimage_swap, preimage_swap_prod]
theorem mapsTo_swap_prod (s : Set Ξ±) (t : Set Ξ²) : MapsTo Prod.swap (s ΓΛ’ t) (t ΓΛ’ s) :=
fun _ β¨hx, hyβ© β¦ β¨hy, hxβ©
| theorem prod_image_image_eq {mβ : Ξ± β Ξ³} {mβ : Ξ² β Ξ΄} :
(mβ '' s) ΓΛ’ (mβ '' t) = (fun p : Ξ± Γ Ξ² => (mβ p.1, mβ p.2)) '' s ΓΛ’ t :=
ext <| by
| Mathlib/Data/Set/Prod.lean | 231 | 233 |
/-
Copyright (c) 2019 SΓ©bastien GouΓ«zel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: SΓ©bastien GouΓ«zel, Yury Kudryashov
-/
import Mathlib.Analysis.Calculus.Deriv.AffineMap
import Mathlib.Analysis.Calculus.Deriv.Comp
import Mathlib.Analysis.Calculus.Deriv.Mul
import Mathlib.Analysis.Calculus.Deriv.Slope
import Mathlib.Analysis.Normed.Group.AddTorsor
import Mathlib.Analysis.Normed.Module.Convex
import Mathlib.Analysis.RCLike.Basic
import Mathlib.Topology.Instances.RealVectorSpace
import Mathlib.Topology.LocallyConstant.Basic
/-!
# The mean value inequality and equalities
In this file we prove the following facts:
* `Convex.norm_image_sub_le_of_norm_deriv_le` : if `f` is differentiable on a convex set `s`
and the norm of its derivative is bounded by `C`, then `f` is Lipschitz continuous on `s` with
constant `C`; also a variant in which what is bounded by `C` is the norm of the difference of the
derivative from a fixed linear map. This lemma and its versions are formulated using `RCLike`,
so they work both for real and complex derivatives.
* `image_le_of*`, `image_norm_le_of_*` : several similar lemmas deducing `f x β€ B x` or
`βf xβ β€ B x` from upper estimates on `f'` or `βf'β`, respectively. These lemmas differ by
their assumptions:
* `of_liminf_*` lemmas assume that limit inferior of some ratio is less than `B' x`;
* `of_deriv_right_*`, `of_norm_deriv_right_*` lemmas assume that the right derivative
or its norm is less than `B' x`;
* `of_*_lt_*` lemmas assume a strict inequality whenever `f x = B x` or `βf xβ = B x`;
* `of_*_le_*` lemmas assume a non-strict inequality everywhere on `[a, b)`;
* name of a lemma ends with `'` if (1) it assumes that `B` is continuous on `[a, b]`
and has a right derivative at every point of `[a, b)`, and (2) the lemma has
a counterpart assuming that `B` is differentiable everywhere on `β`
* `norm_image_sub_le_*_segment` : if derivative of `f` on `[a, b]` is bounded above
by a constant `C`, then `βf x - f aβ β€ C * βx - aβ`; several versions deal with
right derivative and derivative within `[a, b]` (`HasDerivWithinAt` or `derivWithin`).
* `Convex.is_const_of_fderivWithin_eq_zero` : if a function has derivative `0` on a convex set `s`,
then it is a constant on `s`.
* `hasStrictFDerivAt_of_hasFDerivAt_of_continuousAt` : a C^1 function over the reals is
strictly differentiable. (This is a corollary of the mean value inequality.)
-/
variable {E : Type*} [NormedAddCommGroup E] [NormedSpace β E] {F : Type*} [NormedAddCommGroup F]
[NormedSpace β F]
open Metric Set Asymptotics ContinuousLinearMap Filter
open scoped Topology NNReal
/-! ### One-dimensional fencing inequalities -/
/-- General fencing theorem for continuous functions with an estimate on the derivative.
Let `f` and `B` be continuous functions on `[a, b]` such that
* `f a β€ B a`;
* `B` has right derivative `B'` at every point of `[a, b)`;
* for each `x β [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)`
is bounded above by a function `f'`;
* we have `f' x < B' x` whenever `f x = B x`.
Then `f x β€ B x` everywhere on `[a, b]`. -/
theorem image_le_of_liminf_slope_right_lt_deriv_boundary' {f f' : β β β} {a b : β}
(hf : ContinuousOn f (Icc a b))
-- `hf'` actually says `liminf (f z - f x) / (z - x) β€ f' x`
(hf' : β x β Ico a b, β r, f' x < r β βαΆ z in π[>] x, slope f x z < r)
{B B' : β β β} (ha : f a β€ B a) (hB : ContinuousOn B (Icc a b))
(hB' : β x β Ico a b, HasDerivWithinAt B (B' x) (Ici x) x)
(bound : β x β Ico a b, f x = B x β f' x < B' x) : β β¦xβ¦, x β Icc a b β f x β€ B x := by
change Icc a b β { x | f x β€ B x }
set s := { x | f x β€ B x } β© Icc a b
have A : ContinuousOn (fun x => (f x, B x)) (Icc a b) := hf.prodMk hB
have : IsClosed s := by
simp only [s, inter_comm]
exact A.preimage_isClosed_of_isClosed isClosed_Icc OrderClosedTopology.isClosed_le'
apply this.Icc_subset_of_forall_exists_gt ha
rintro x β¨hxB : f x β€ B x, xabβ© y hy
rcases hxB.lt_or_eq with hxB | hxB
Β· -- If `f x < B x`, then all we need is continuity of both sides
refine nonempty_of_mem (inter_mem ?_ (Ioc_mem_nhdsGT hy))
have : βαΆ x in π[Icc a b] x, f x < B x :=
A x (Ico_subset_Icc_self xab) (IsOpen.mem_nhds (isOpen_lt continuous_fst continuous_snd) hxB)
have : βαΆ x in π[>] x, f x < B x := nhdsWithin_le_of_mem (Icc_mem_nhdsGT_of_mem xab) this
exact this.mono fun y => le_of_lt
Β· rcases exists_between (bound x xab hxB) with β¨r, hfr, hrBβ©
specialize hf' x xab r hfr
have HB : βαΆ z in π[>] x, r < slope B x z :=
(hasDerivWithinAt_iff_tendsto_slope' <| lt_irrefl x).1 (hB' x xab).Ioi_of_Ici
(Ioi_mem_nhds hrB)
obtain β¨z, hfz, hzB, hzβ© : β z, slope f x z < r β§ r < slope B x z β§ z β Ioc x y :=
hf'.and_eventually (HB.and (Ioc_mem_nhdsGT hy)) |>.exists
refine β¨z, ?_, hzβ©
have := (hfz.trans hzB).le
rwa [slope_def_field, slope_def_field, div_le_div_iff_of_pos_right (sub_pos.2 hz.1), hxB,
sub_le_sub_iff_right] at this
/-- General fencing theorem for continuous functions with an estimate on the derivative.
Let `f` and `B` be continuous functions on `[a, b]` such that
* `f a β€ B a`;
* `B` has derivative `B'` everywhere on `β`;
* for each `x β [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)`
is bounded above by a function `f'`;
* we have `f' x < B' x` whenever `f x = B x`.
Then `f x β€ B x` everywhere on `[a, b]`. -/
theorem image_le_of_liminf_slope_right_lt_deriv_boundary {f f' : β β β} {a b : β}
(hf : ContinuousOn f (Icc a b))
-- `hf'` actually says `liminf (f z - f x) / (z - x) β€ f' x`
(hf' : β x β Ico a b, β r, f' x < r β βαΆ z in π[>] x, slope f x z < r)
{B B' : β β β} (ha : f a β€ B a) (hB : β x, HasDerivAt B (B' x) x)
(bound : β x β Ico a b, f x = B x β f' x < B' x) : β β¦xβ¦, x β Icc a b β f x β€ B x :=
image_le_of_liminf_slope_right_lt_deriv_boundary' hf hf' ha
(fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound
/-- General fencing theorem for continuous functions with an estimate on the derivative.
Let `f` and `B` be continuous functions on `[a, b]` such that
* `f a β€ B a`;
* `B` has right derivative `B'` at every point of `[a, b)`;
* for each `x β [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)`
is bounded above by `B'`.
Then `f x β€ B x` everywhere on `[a, b]`. -/
theorem image_le_of_liminf_slope_right_le_deriv_boundary {f : β β β} {a b : β}
(hf : ContinuousOn f (Icc a b)) {B B' : β β β} (ha : f a β€ B a) (hB : ContinuousOn B (Icc a b))
(hB' : β x β Ico a b, HasDerivWithinAt B (B' x) (Ici x) x)
-- `bound` actually says `liminf (f z - f x) / (z - x) β€ B' x`
(bound : β x β Ico a b, β r, B' x < r β βαΆ z in π[>] x, slope f x z < r) :
β β¦xβ¦, x β Icc a b β f x β€ B x := by
have Hr : β x β Icc a b, β r > 0, f x β€ B x + r * (x - a) := fun x hx r hr => by
apply image_le_of_liminf_slope_right_lt_deriv_boundary' hf bound
Β· rwa [sub_self, mul_zero, add_zero]
Β· exact hB.add (continuousOn_const.mul (continuousOn_id.sub continuousOn_const))
Β· intro x hx
exact (hB' x hx).add (((hasDerivWithinAt_id x (Ici x)).sub_const a).const_mul r)
Β· intro x _ _
rw [mul_one]
exact (lt_add_iff_pos_right _).2 hr
exact hx
intro x hx
have : ContinuousWithinAt (fun r => B x + r * (x - a)) (Ioi 0) 0 :=
continuousWithinAt_const.add (continuousWithinAt_id.mul continuousWithinAt_const)
convert continuousWithinAt_const.closure_le _ this (Hr x hx) using 1 <;> simp
/-- General fencing theorem for continuous functions with an estimate on the derivative.
Let `f` and `B` be continuous functions on `[a, b]` such that
* `f a β€ B a`;
* `B` has right derivative `B'` at every point of `[a, b)`;
* `f` has right derivative `f'` at every point of `[a, b)`;
* we have `f' x < B' x` whenever `f x = B x`.
Then `f x β€ B x` everywhere on `[a, b]`. -/
theorem image_le_of_deriv_right_lt_deriv_boundary' {f f' : β β β} {a b : β}
(hf : ContinuousOn f (Icc a b)) (hf' : β x β Ico a b, HasDerivWithinAt f (f' x) (Ici x) x)
{B B' : β β β} (ha : f a β€ B a) (hB : ContinuousOn B (Icc a b))
(hB' : β x β Ico a b, HasDerivWithinAt B (B' x) (Ici x) x)
(bound : β x β Ico a b, f x = B x β f' x < B' x) : β β¦xβ¦, x β Icc a b β f x β€ B x :=
image_le_of_liminf_slope_right_lt_deriv_boundary' hf
(fun x hx _ hr => (hf' x hx).liminf_right_slope_le hr) ha hB hB' bound
/-- General fencing theorem for continuous functions with an estimate on the derivative.
Let `f` and `B` be continuous functions on `[a, b]` such that
* `f a β€ B a`;
* `B` has derivative `B'` everywhere on `β`;
* `f` has right derivative `f'` at every point of `[a, b)`;
* we have `f' x < B' x` whenever `f x = B x`.
Then `f x β€ B x` everywhere on `[a, b]`. -/
theorem image_le_of_deriv_right_lt_deriv_boundary {f f' : β β β} {a b : β}
(hf : ContinuousOn f (Icc a b)) (hf' : β x β Ico a b, HasDerivWithinAt f (f' x) (Ici x) x)
{B B' : β β β} (ha : f a β€ B a) (hB : β x, HasDerivAt B (B' x) x)
(bound : β x β Ico a b, f x = B x β f' x < B' x) : β β¦xβ¦, x β Icc a b β f x β€ B x :=
image_le_of_deriv_right_lt_deriv_boundary' hf hf' ha
(fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound
/-- General fencing theorem for continuous functions with an estimate on the derivative.
Let `f` and `B` be continuous functions on `[a, b]` such that
* `f a β€ B a`;
* `B` has derivative `B'` everywhere on `β`;
* `f` has right derivative `f'` at every point of `[a, b)`;
* we have `f' x β€ B' x` on `[a, b)`.
Then `f x β€ B x` everywhere on `[a, b]`. -/
theorem image_le_of_deriv_right_le_deriv_boundary {f f' : β β β} {a b : β}
(hf : ContinuousOn f (Icc a b)) (hf' : β x β Ico a b, HasDerivWithinAt f (f' x) (Ici x) x)
{B B' : β β β} (ha : f a β€ B a) (hB : ContinuousOn B (Icc a b))
(hB' : β x β Ico a b, HasDerivWithinAt B (B' x) (Ici x) x)
(bound : β x β Ico a b, f' x β€ B' x) : β β¦xβ¦, x β Icc a b β f x β€ B x :=
image_le_of_liminf_slope_right_le_deriv_boundary hf ha hB hB' fun x hx _ hr =>
(hf' x hx).liminf_right_slope_le (lt_of_le_of_lt (bound x hx) hr)
/-! ### Vector-valued functions `f : β β E` -/
section
variable {f : β β E} {a b : β}
/-- General fencing theorem for continuous functions with an estimate on the derivative.
Let `f` and `B` be continuous functions on `[a, b]` such that
* `βf aβ β€ B a`;
* `B` has right derivative at every point of `[a, b)`;
* for each `x β [a, b)` the right-side limit inferior of `(βf zβ - βf xβ) / (z - x)`
is bounded above by a function `f'`;
* we have `f' x < B' x` whenever `βf xβ = B x`.
Then `βf xβ β€ B x` everywhere on `[a, b]`. -/
theorem image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary {E : Type*}
[NormedAddCommGroup E] {f : β β E} {f' : β β β} (hf : ContinuousOn f (Icc a b))
-- `hf'` actually says `liminf (βf zβ - βf xβ) / (z - x) β€ f' x`
(hf' : β x β Ico a b, β r, f' x < r β βαΆ z in π[>] x, slope (norm β f) x z < r)
{B B' : β β β} (ha : βf aβ β€ B a) (hB : ContinuousOn B (Icc a b))
(hB' : β x β Ico a b, HasDerivWithinAt B (B' x) (Ici x) x)
(bound : β x β Ico a b, βf xβ = B x β f' x < B' x) : β β¦xβ¦, x β Icc a b β βf xβ β€ B x :=
image_le_of_liminf_slope_right_lt_deriv_boundary' (continuous_norm.comp_continuousOn hf) hf' ha hB
hB' bound
/-- General fencing theorem for continuous functions with an estimate on the norm of the derivative.
Let `f` and `B` be continuous functions on `[a, b]` such that
* `βf aβ β€ B a`;
* `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`;
* the norm of `f'` is strictly less than `B'` whenever `βf xβ = B x`.
Then `βf xβ β€ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions
to make this theorem work for piecewise differentiable functions.
-/
theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary' {f' : β β E}
(hf : ContinuousOn f (Icc a b)) (hf' : β x β Ico a b, HasDerivWithinAt f (f' x) (Ici x) x)
{B B' : β β β} (ha : βf aβ β€ B a) (hB : ContinuousOn B (Icc a b))
(hB' : β x β Ico a b, HasDerivWithinAt B (B' x) (Ici x) x)
(bound : β x β Ico a b, βf xβ = B x β βf' xβ < B' x) : β β¦xβ¦, x β Icc a b β βf xβ β€ B x :=
image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary hf
(fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le hr) ha hB hB' bound
/-- General fencing theorem for continuous functions with an estimate on the norm of the derivative.
Let `f` and `B` be continuous functions on `[a, b]` such that
* `βf aβ β€ B a`;
* `f` has right derivative `f'` at every point of `[a, b)`;
* `B` has derivative `B'` everywhere on `β`;
* the norm of `f'` is strictly less than `B'` whenever `βf xβ = B x`.
Then `βf xβ β€ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions
to make this theorem work for piecewise differentiable functions.
-/
theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary {f' : β β E}
(hf : ContinuousOn f (Icc a b)) (hf' : β x β Ico a b, HasDerivWithinAt f (f' x) (Ici x) x)
{B B' : β β β} (ha : βf aβ β€ B a) (hB : β x, HasDerivAt B (B' x) x)
(bound : β x β Ico a b, βf xβ = B x β βf' xβ < B' x) : β β¦xβ¦, x β Icc a b β βf xβ β€ B x :=
image_norm_le_of_norm_deriv_right_lt_deriv_boundary' hf hf' ha
(fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound
/-- General fencing theorem for continuous functions with an estimate on the norm of the derivative.
Let `f` and `B` be continuous functions on `[a, b]` such that
* `βf aβ β€ B a`;
* `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`;
* we have `βf' xβ β€ B x` everywhere on `[a, b)`.
Then `βf xβ β€ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions
to make this theorem work for piecewise differentiable functions.
-/
theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary' {f' : β β E}
(hf : ContinuousOn f (Icc a b)) (hf' : β x β Ico a b, HasDerivWithinAt f (f' x) (Ici x) x)
{B B' : β β β} (ha : βf aβ β€ B a) (hB : ContinuousOn B (Icc a b))
(hB' : β x β Ico a b, HasDerivWithinAt B (B' x) (Ici x) x)
(bound : β x β Ico a b, βf' xβ β€ B' x) : β β¦xβ¦, x β Icc a b β βf xβ β€ B x :=
image_le_of_liminf_slope_right_le_deriv_boundary (continuous_norm.comp_continuousOn hf) ha hB hB'
fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le ((bound x hx).trans_lt hr)
/-- General fencing theorem for continuous functions with an estimate on the norm of the derivative.
Let `f` and `B` be continuous functions on `[a, b]` such that
* `βf aβ β€ B a`;
* `f` has right derivative `f'` at every point of `[a, b)`;
* `B` has derivative `B'` everywhere on `β`;
* we have `βf' xβ β€ B x` everywhere on `[a, b)`.
Then `βf xβ β€ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions
to make this theorem work for piecewise differentiable functions.
-/
theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary {f' : β β E}
(hf : ContinuousOn f (Icc a b)) (hf' : β x β Ico a b, HasDerivWithinAt f (f' x) (Ici x) x)
{B B' : β β β} (ha : βf aβ β€ B a) (hB : β x, HasDerivAt B (B' x) x)
(bound : β x β Ico a b, βf' xβ β€ B' x) : β β¦xβ¦, x β Icc a b β βf xβ β€ B x :=
image_norm_le_of_norm_deriv_right_le_deriv_boundary' hf hf' ha
(fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound
/-- A function on `[a, b]` with the norm of the right derivative bounded by `C`
satisfies `βf x - f aβ β€ C * (x - a)`. -/
theorem norm_image_sub_le_of_norm_deriv_right_le_segment {f' : β β E} {C : β}
(hf : ContinuousOn f (Icc a b)) (hf' : β x β Ico a b, HasDerivWithinAt f (f' x) (Ici x) x)
(bound : β x β Ico a b, βf' xβ β€ C) : β x β Icc a b, βf x - f aβ β€ C * (x - a) := by
let g x := f x - f a
have hg : ContinuousOn g (Icc a b) := hf.sub continuousOn_const
have hg' : β x β Ico a b, HasDerivWithinAt g (f' x) (Ici x) x := by
intro x hx
simp [g, hf' x hx]
let B x := C * (x - a)
have hB : β x, HasDerivAt B C x := by
intro x
simpa using (hasDerivAt_const x C).mul ((hasDerivAt_id x).sub (hasDerivAt_const x a))
convert image_norm_le_of_norm_deriv_right_le_deriv_boundary hg hg' _ hB bound
simp only [g, B]; rw [sub_self, norm_zero, sub_self, mul_zero]
/-- A function on `[a, b]` with the norm of the derivative within `[a, b]`
bounded by `C` satisfies `βf x - f aβ β€ C * (x - a)`, `HasDerivWithinAt`
version. -/
theorem norm_image_sub_le_of_norm_deriv_le_segment' {f' : β β E} {C : β}
(hf : β x β Icc a b, HasDerivWithinAt f (f' x) (Icc a b) x)
(bound : β x β Ico a b, βf' xβ β€ C) : β x β Icc a b, βf x - f aβ β€ C * (x - a) := by
refine
norm_image_sub_le_of_norm_deriv_right_le_segment (fun x hx => (hf x hx).continuousWithinAt)
(fun x hx => ?_) bound
exact (hf x <| Ico_subset_Icc_self hx).mono_of_mem_nhdsWithin (Icc_mem_nhdsGE_of_mem hx)
/-- A function on `[a, b]` with the norm of the derivative within `[a, b]`
bounded by `C` satisfies `βf x - f aβ β€ C * (x - a)`, `derivWithin`
version. -/
theorem norm_image_sub_le_of_norm_deriv_le_segment {C : β} (hf : DifferentiableOn β f (Icc a b))
(bound : β x β Ico a b, βderivWithin f (Icc a b) xβ β€ C) :
β x β Icc a b, βf x - f aβ β€ C * (x - a) := by
refine norm_image_sub_le_of_norm_deriv_le_segment' ?_ bound
exact fun x hx => (hf x hx).hasDerivWithinAt
/-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]`
bounded by `C` satisfies `βf 1 - f 0β β€ C`, `HasDerivWithinAt`
version. -/
theorem norm_image_sub_le_of_norm_deriv_le_segment_01' {f' : β β E} {C : β}
(hf : β x β Icc (0 : β) 1, HasDerivWithinAt f (f' x) (Icc (0 : β) 1) x)
(bound : β x β Ico (0 : β) 1, βf' xβ β€ C) : βf 1 - f 0β β€ C := by
simpa only [sub_zero, mul_one] using
norm_image_sub_le_of_norm_deriv_le_segment' hf bound 1 (right_mem_Icc.2 zero_le_one)
/-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]`
bounded by `C` satisfies `βf 1 - f 0β β€ C`, `derivWithin` version. -/
theorem norm_image_sub_le_of_norm_deriv_le_segment_01 {C : β}
(hf : DifferentiableOn β f (Icc (0 : β) 1))
(bound : β x β Ico (0 : β) 1, βderivWithin f (Icc (0 : β) 1) xβ β€ C) : βf 1 - f 0β β€ C := by
simpa only [sub_zero, mul_one] using
norm_image_sub_le_of_norm_deriv_le_segment hf bound 1 (right_mem_Icc.2 zero_le_one)
theorem constant_of_has_deriv_right_zero (hcont : ContinuousOn f (Icc a b))
(hderiv : β x β Ico a b, HasDerivWithinAt f 0 (Ici x) x) : β x β Icc a b, f x = f a := by
have : β x β Icc a b, βf x - f aβ β€ 0 * (x - a) := fun x hx =>
norm_image_sub_le_of_norm_deriv_right_le_segment hcont hderiv (fun _ _ => norm_zero.le) x hx
simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using this
theorem constant_of_derivWithin_zero (hdiff : DifferentiableOn β f (Icc a b))
(hderiv : β x β Ico a b, derivWithin f (Icc a b) x = 0) : β x β Icc a b, f x = f a := by
have H : β x β Ico a b, βderivWithin f (Icc a b) xβ β€ 0 := by
simpa only [norm_le_zero_iff] using fun x hx => hderiv x hx
simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using fun x hx =>
norm_image_sub_le_of_norm_deriv_le_segment hdiff H x hx
variable {f' g : β β E}
/-- If two continuous functions on `[a, b]` have the same right derivative and are equal at `a`,
then they are equal everywhere on `[a, b]`. -/
theorem eq_of_has_deriv_right_eq (derivf : β x β Ico a b, HasDerivWithinAt f (f' x) (Ici x) x)
(derivg : β x β Ico a b, HasDerivWithinAt g (f' x) (Ici x) x) (fcont : ContinuousOn f (Icc a b))
(gcont : ContinuousOn g (Icc a b)) (hi : f a = g a) : β y β Icc a b, f y = g y := by
simp only [β @sub_eq_zero _ _ (f _)] at hi β’
exact hi βΈ constant_of_has_deriv_right_zero (fcont.sub gcont) fun y hy => by
simpa only [sub_self] using (derivf y hy).sub (derivg y hy)
/-- If two differentiable functions on `[a, b]` have the same derivative within `[a, b]` everywhere
on `[a, b)` and are equal at `a`, then they are equal everywhere on `[a, b]`. -/
theorem eq_of_derivWithin_eq (fdiff : DifferentiableOn β f (Icc a b))
(gdiff : DifferentiableOn β g (Icc a b))
(hderiv : EqOn (derivWithin f (Icc a b)) (derivWithin g (Icc a b)) (Ico a b)) (hi : f a = g a) :
β y β Icc a b, f y = g y := by
have A : β y β Ico a b, HasDerivWithinAt f (derivWithin f (Icc a b) y) (Ici y) y := fun y hy =>
(fdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem_nhdsWithin
(Icc_mem_nhdsGE_of_mem hy)
have B : β y β Ico a b, HasDerivWithinAt g (derivWithin g (Icc a b) y) (Ici y) y := fun y hy =>
(gdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem_nhdsWithin
(Icc_mem_nhdsGE_of_mem hy)
exact eq_of_has_deriv_right_eq A (fun y hy => (hderiv hy).symm βΈ B y hy) fdiff.continuousOn
gdiff.continuousOn hi
end
/-!
### Vector-valued functions `f : E β G`
Theorems in this section work both for real and complex differentiable functions. We use assumptions
`[NontriviallyNormedField π] [IsRCLikeNormedField π] [NormedSpace π E] [NormedSpace π G]` to
achieve this result. For the domain `E` we also assume `[NormedSpace β E]` to have a notion
of a `Convex` set. -/
section
namespace Convex
variable {π G : Type*} [NontriviallyNormedField π] [IsRCLikeNormedField π]
[NormedSpace π E] [NormedAddCommGroup G] [NormedSpace π G]
{f g : E β G} {C : β} {s : Set E} {x y : E} {f' g' : E β E βL[π] G} {Ο : E βL[π] G}
instance (priority := 100) : PathConnectedSpace π := by
letI : RCLike π := IsRCLikeNormedField.rclike π
infer_instance
/-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C`, then
the function is `C`-Lipschitz. Version with `HasFDerivWithinAt`. -/
theorem norm_image_sub_le_of_norm_hasFDerivWithin_le
(hf : β x β s, HasFDerivWithinAt f (f' x) s x) (bound : β x β s, βf' xβ β€ C) (hs : Convex β s)
(xs : x β s) (ys : y β s) : βf y - f xβ β€ C * βy - xβ := by
letI : RCLike π := IsRCLikeNormedField.rclike π
letI : NormedSpace β G := RestrictScalars.normedSpace β π G
/- By composition with `AffineMap.lineMap x y`, we reduce to a statement for functions defined
on `[0,1]`, for which it is proved in `norm_image_sub_le_of_norm_deriv_le_segment`.
We just have to check the differentiability of the composition and bounds on its derivative,
which is straightforward but tedious for lack of automation. -/
set g := (AffineMap.lineMap x y : β β E)
have segm : MapsTo g (Icc 0 1 : Set β) s := hs.mapsTo_lineMap xs ys
have hD : β t β Icc (0 : β) 1,
HasDerivWithinAt (f β g) (f' (g t) (y - x)) (Icc 0 1) t := fun t ht => by
simpa using ((hf (g t) (segm ht)).restrictScalars β).comp_hasDerivWithinAt _
AffineMap.hasDerivWithinAt_lineMap segm
have bound : β t β Ico (0 : β) 1, βf' (g t) (y - x)β β€ C * βy - xβ := fun t ht =>
le_of_opNorm_le _ (bound _ <| segm <| Ico_subset_Icc_self ht) _
simpa [g] using norm_image_sub_le_of_norm_deriv_le_segment_01' hD bound
/-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on
`s`, then the function is `C`-Lipschitz on `s`. Version with `HasFDerivWithinAt` and
`LipschitzOnWith`. -/
theorem lipschitzOnWith_of_nnnorm_hasFDerivWithin_le {C : ββ₯0}
(hf : β x β s, HasFDerivWithinAt f (f' x) s x) (bound : β x β s, βf' xββ β€ C)
(hs : Convex β s) : LipschitzOnWith C f s := by
rw [lipschitzOnWith_iff_norm_sub_le]
intro x x_in y y_in
exact hs.norm_image_sub_le_of_norm_hasFDerivWithin_le hf bound y_in x_in
/-- Let `s` be a convex set in a real normed vector space `E`, let `f : E β G` be a function
differentiable within `s` in a neighborhood of `x : E` with derivative `f'`. Suppose that `f'` is
continuous within `s` at `x`. Then for any number `K : ββ₯0` larger than `βf' xββ`, `f` is
`K`-Lipschitz on some neighborhood of `x` within `s`. See also
`Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt` for a version that claims
existence of `K` instead of an explicit estimate. -/
theorem exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt (hs : Convex β s)
{f : E β G} (hder : βαΆ y in π[s] x, HasFDerivWithinAt f (f' y) s y)
(hcont : ContinuousWithinAt f' s x) (K : ββ₯0) (hK : βf' xββ < K) :
β t β π[s] x, LipschitzOnWith K f t := by
obtain β¨Ξ΅, Ξ΅0, hΞ΅β© : β Ξ΅ > 0,
ball x Ξ΅ β© s β { y | HasFDerivWithinAt f (f' y) s y β§ βf' yββ < K } :=
mem_nhdsWithin_iff.1 (hder.and <| hcont.nnnorm.eventually (gt_mem_nhds hK))
rw [inter_comm] at hΞ΅
refine β¨s β© ball x Ξ΅, inter_mem_nhdsWithin _ (ball_mem_nhds _ Ξ΅0), ?_β©
exact
(hs.inter (convex_ball _ _)).lipschitzOnWith_of_nnnorm_hasFDerivWithin_le
(fun y hy => (hΞ΅ hy).1.mono inter_subset_left) fun y hy => (hΞ΅ hy).2.le
/-- Let `s` be a convex set in a real normed vector space `E`, let `f : E β G` be a function
differentiable within `s` in a neighborhood of `x : E` with derivative `f'`. Suppose that `f'` is
continuous within `s` at `x`. Then for any number `K : ββ₯0` larger than `βf' xββ`, `f` is Lipschitz
on some neighborhood of `x` within `s`. See also
`Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt` for a version
with an explicit estimate on the Lipschitz constant. -/
theorem exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt (hs : Convex β s) {f : E β G}
(hder : βαΆ y in π[s] x, HasFDerivWithinAt f (f' y) s y) (hcont : ContinuousWithinAt f' s x) :
β K, β t β π[s] x, LipschitzOnWith K f t :=
(exists_gt _).imp <|
hs.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt hder hcont
/-- The mean value theorem on a convex set: if the derivative of a function within this set is
bounded by `C`, then the function is `C`-Lipschitz. Version with `fderivWithin`. -/
theorem norm_image_sub_le_of_norm_fderivWithin_le (hf : DifferentiableOn π f s)
(bound : β x β s, βfderivWithin π f s xβ β€ C) (hs : Convex β s) (xs : x β s) (ys : y β s) :
βf y - f xβ β€ C * βy - xβ :=
hs.norm_image_sub_le_of_norm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) bound
xs ys
/-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on
`s`, then the function is `C`-Lipschitz on `s`. Version with `fderivWithin` and
`LipschitzOnWith`. -/
theorem lipschitzOnWith_of_nnnorm_fderivWithin_le {C : ββ₯0} (hf : DifferentiableOn π f s)
(bound : β x β s, βfderivWithin π f s xββ β€ C) (hs : Convex β s) : LipschitzOnWith C f s :=
hs.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) bound
/-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C`,
then the function is `C`-Lipschitz. Version with `fderiv`. -/
theorem norm_image_sub_le_of_norm_fderiv_le (hf : β x β s, DifferentiableAt π f x)
(bound : β x β s, βfderiv π f xβ β€ C) (hs : Convex β s) (xs : x β s) (ys : y β s) :
βf y - f xβ β€ C * βy - xβ :=
hs.norm_image_sub_le_of_norm_hasFDerivWithin_le
(fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound xs ys
/-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on
`s`, then the function is `C`-Lipschitz on `s`. Version with `fderiv` and `LipschitzOnWith`. -/
theorem lipschitzOnWith_of_nnnorm_fderiv_le {C : ββ₯0} (hf : β x β s, DifferentiableAt π f x)
(bound : β x β s, βfderiv π f xββ β€ C) (hs : Convex β s) : LipschitzOnWith C f s :=
hs.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le
(fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound
/-- The mean value theorem: if the derivative of a function is bounded by `C`, then the function is
`C`-Lipschitz. Version with `fderiv` and `LipschitzWith`. -/
theorem _root_.lipschitzWith_of_nnnorm_fderiv_le
{E : Type*} [NormedAddCommGroup E] [NormedSpace π E] {f : E β G}
{C : ββ₯0} (hf : Differentiable π f)
(bound : β x, βfderiv π f xββ β€ C) : LipschitzWith C f := by
letI : RCLike π := IsRCLikeNormedField.rclike π
let A : NormedSpace β E := RestrictScalars.normedSpace β π E
rw [β lipschitzOnWith_univ]
exact lipschitzOnWith_of_nnnorm_fderiv_le (fun x _ β¦ hf x) (fun x _ β¦ bound x) convex_univ
/-- Variant of the mean value inequality on a convex set, using a bound on the difference between
the derivative and a fixed linear map, rather than a bound on the derivative itself. Version with
`HasFDerivWithinAt`. -/
theorem norm_image_sub_le_of_norm_hasFDerivWithin_le'
(hf : β x β s, HasFDerivWithinAt f (f' x) s x) (bound : β x β s, βf' x - Οβ β€ C)
(hs : Convex β s) (xs : x β s) (ys : y β s) : βf y - f x - Ο (y - x)β β€ C * βy - xβ := by
/- We subtract `Ο` to define a new function `g` for which `g' = 0`, for which the previous theorem
applies, `Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le`. Then, we just need to glue
together the pieces, expressing back `f` in terms of `g`. -/
let g y := f y - Ο y
have hg : β x β s, HasFDerivWithinAt g (f' x - Ο) s x := fun x xs =>
(hf x xs).sub Ο.hasFDerivWithinAt
calc
βf y - f x - Ο (y - x)β = βf y - f x - (Ο y - Ο x)β := by simp
_ = βf y - Ο y - (f x - Ο x)β := by congr 1; abel
_ = βg y - g xβ := by simp [g]
_ β€ C * βy - xβ := Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le hg bound hs xs ys
/-- Variant of the mean value inequality on a convex set. Version with `fderivWithin`. -/
theorem norm_image_sub_le_of_norm_fderivWithin_le' (hf : DifferentiableOn π f s)
(bound : β x β s, βfderivWithin π f s x - Οβ β€ C) (hs : Convex β s) (xs : x β s) (ys : y β s) :
βf y - f x - Ο (y - x)β β€ C * βy - xβ :=
hs.norm_image_sub_le_of_norm_hasFDerivWithin_le' (fun x hx => (hf x hx).hasFDerivWithinAt) bound
xs ys
/-- Variant of the mean value inequality on a convex set. Version with `fderiv`. -/
theorem norm_image_sub_le_of_norm_fderiv_le' (hf : β x β s, DifferentiableAt π f x)
(bound : β x β s, βfderiv π f x - Οβ β€ C) (hs : Convex β s) (xs : x β s) (ys : y β s) :
βf y - f x - Ο (y - x)β β€ C * βy - xβ :=
hs.norm_image_sub_le_of_norm_hasFDerivWithin_le'
(fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound xs ys
/-- If a function has zero FrΓ©chet derivative at every point of a convex set,
then it is a constant on this set. -/
theorem is_const_of_fderivWithin_eq_zero (hs : Convex β s) (hf : DifferentiableOn π f s)
(hf' : β x β s, fderivWithin π f s x = 0) (hx : x β s) (hy : y β s) : f x = f y := by
have bound : β x β s, βfderivWithin π f s xβ β€ 0 := fun x hx => by
simp only [hf' x hx, norm_zero, le_rfl]
simpa only [(dist_eq_norm _ _).symm, zero_mul, dist_le_zero, eq_comm] using
hs.norm_image_sub_le_of_norm_fderivWithin_le hf bound hx hy
theorem _root_.is_const_of_fderiv_eq_zero
{E : Type*} [NormedAddCommGroup E] [NormedSpace π E] {f : E β G}
(hf : Differentiable π f) (hf' : β x, fderiv π f x = 0)
(x y : E) : f x = f y := by
letI : RCLike π := IsRCLikeNormedField.rclike π
let A : NormedSpace β E := RestrictScalars.normedSpace β π E
exact convex_univ.is_const_of_fderivWithin_eq_zero hf.differentiableOn
(fun x _ => by rw [fderivWithin_univ]; exact hf' x) trivial trivial
/-- If two functions have equal FrΓ©chet derivatives at every point of a convex set, and are equal at
one point in that set, then they are equal on that set. -/
theorem eqOn_of_fderivWithin_eq (hs : Convex β s) (hf : DifferentiableOn π f s)
(hg : DifferentiableOn π g s) (hs' : UniqueDiffOn π s)
(hf' : s.EqOn (fderivWithin π f s) (fderivWithin π g s)) (hx : x β s) (hfgx : f x = g x) :
s.EqOn f g := fun y hy => by
suffices f x - g x = f y - g y by rwa [hfgx, sub_self, eq_comm, sub_eq_zero] at this
refine hs.is_const_of_fderivWithin_eq_zero (hf.sub hg) (fun z hz => ?_) hx hy
rw [fderivWithin_sub (hs' _ hz) (hf _ hz) (hg _ hz), sub_eq_zero, hf' hz]
/-- If `f` has zero derivative on an open set, then `f` is locally constant on `s`. -/
-- TODO: change the spelling once we have `IsLocallyConstantOn`.
theorem _root_.IsOpen.isOpen_inter_preimage_of_fderiv_eq_zero
(hs : IsOpen s) (hf : DifferentiableOn π f s)
(hf' : s.EqOn (fderiv π f) 0) (t : Set G) : IsOpen (s β© f β»ΒΉ' t) := by
refine Metric.isOpen_iff.mpr fun y β¨hy, hy'β© β¦ ?_
obtain β¨r, hr, hβ© := Metric.isOpen_iff.mp hs y hy
refine β¨r, hr, Set.subset_inter h fun x hx β¦ ?_β©
have := (convex_ball y r).is_const_of_fderivWithin_eq_zero (hf.mono h) ?_ hx (mem_ball_self hr)
Β· simpa [this]
Β· intro z hz
simpa only [fderivWithin_of_isOpen Metric.isOpen_ball hz] using hf' (h hz)
theorem _root_.isLocallyConstant_of_fderiv_eq_zero (hβ : Differentiable π f)
(hβ : β x, fderiv π f x = 0) : IsLocallyConstant f := by
simpa using isOpen_univ.isOpen_inter_preimage_of_fderiv_eq_zero hβ.differentiableOn fun _ _ β¦ hβ _
/-- If `f` has zero derivative on a connected open set, then `f` is constant on `s`. -/
theorem _root_.IsOpen.exists_is_const_of_fderiv_eq_zero
(hs : IsOpen s) (hs' : IsPreconnected s) (hf : DifferentiableOn π f s)
(hf' : s.EqOn (fderiv π f) 0) : β a, β x β s, f x = a := by
obtain (rfl|β¨y, hyβ©) := s.eq_empty_or_nonempty
Β· exact β¨0, by simpβ©
Β· refine β¨f y, fun x hx β¦ ?_β©
have hβ := hs.isOpen_inter_preimage_of_fderiv_eq_zero hf hf' {f y}
have hβ := hf.continuousOn.comp_continuous continuous_subtype_val (fun x β¦ x.2)
by_contra hβ
obtain β¨t, ht, ht'β© := (isClosed_singleton (x := f y)).preimage hβ
have ht'' : β a β s, a β t β f a β f y := by simpa [Set.ext_iff] using ht'
obtain β¨z, Hβ, Hβ, Hββ© := hs' _ _ hβ ht (fun x h β¦ by simp [h, ht'', eq_or_ne]) β¨y, by simpaβ©
β¨x, by simp [ht'' _ hx, hx, hβ]β©
exact (ht'' _ Hβ).mp Hβ Hβ.2
theorem _root_.IsOpen.is_const_of_fderiv_eq_zero
(hs : IsOpen s) (hs' : IsPreconnected s) (hf : DifferentiableOn π f s)
(hf' : s.EqOn (fderiv π f) 0) {x y : E} (hx : x β s) (hy : y β s) : f x = f y := by
obtain β¨a, haβ© := hs.exists_is_const_of_fderiv_eq_zero hs' hf hf'
rw [ha x hx, ha y hy]
theorem _root_.IsOpen.exists_eq_add_of_fderiv_eq (hs : IsOpen s) (hs' : IsPreconnected s)
(hf : DifferentiableOn π f s) (hg : DifferentiableOn π g s)
(hf' : s.EqOn (fderiv π f) (fderiv π g)) : β a, s.EqOn f (g Β· + a) := by
simp_rw [Set.EqOn, β sub_eq_iff_eq_add']
refine hs.exists_is_const_of_fderiv_eq_zero hs' (hf.sub hg) fun x hx β¦ ?_
rw [fderiv_sub (hf.differentiableAt (hs.mem_nhds hx)) (hg.differentiableAt (hs.mem_nhds hx)),
hf' hx, sub_self, Pi.zero_apply]
/-- If two functions have equal FrΓ©chet derivatives at every point of a connected open set,
and are equal at one point in that set, then they are equal on that set. -/
theorem _root_.IsOpen.eqOn_of_fderiv_eq (hs : IsOpen s) (hs' : IsPreconnected s)
(hf : DifferentiableOn π f s) (hg : DifferentiableOn π g s)
(hf' : β x β s, fderiv π f x = fderiv π g x) (hx : x β s) (hfgx : f x = g x) :
s.EqOn f g := by
obtain β¨a, haβ© := hs.exists_eq_add_of_fderiv_eq hs' hf hg hf'
obtain rfl := left_eq_add.mp (hfgx.symm.trans (ha hx))
simpa using ha
theorem _root_.eq_of_fderiv_eq
{E : Type*} [NormedAddCommGroup E] [NormedSpace π E] {f g : E β G}
(hf : Differentiable π f) (hg : Differentiable π g)
(hf' : β x, fderiv π f x = fderiv π g x) (x : E) (hfgx : f x = g x) : f = g := by
letI : RCLike π := IsRCLikeNormedField.rclike π
let A : NormedSpace β E := RestrictScalars.normedSpace β π E
suffices Set.univ.EqOn f g from funext fun x => this <| mem_univ x
exact convex_univ.eqOn_of_fderivWithin_eq hf.differentiableOn hg.differentiableOn
uniqueDiffOn_univ (fun x _ => by simpa using hf' _) (mem_univ _) hfgx
lemma isLittleO_pow_succ {xβ : E} {n : β} (hs : Convex β s) (hxβs : xβ β s)
(hff' : β x β s, HasFDerivWithinAt f (f' x) s x) (hf' : f' =o[π[s] xβ] fun x β¦ βx - xββ ^ n) :
(fun x β¦ f x - f xβ) =o[π[s] xβ] fun x β¦ βx - xββ ^ (n + 1) := by
rw [Asymptotics.isLittleO_iff] at hf' β’
intro c hc
simp_rw [norm_pow, pow_succ, β mul_assoc, norm_norm]
simp_rw [norm_pow, norm_norm] at hf'
have : βαΆ x in π[s] xβ, segment β xβ x β s β§ β y β segment β xβ x, βf' yβ β€ c * βx - xββ ^ n := by
have h1 : βαΆ x in π[s] xβ, x β s := eventually_mem_nhdsWithin
filter_upwards [h1, hs.eventually_nhdsWithin_segment hxβs (hf' hc)] with x hxs h
refine β¨hs.segment_subset hxβs hxs, fun y hy β¦ (h y hy).trans ?_β©
gcongr
exact norm_sub_le_of_mem_segment hy
filter_upwards [this] with x β¨h_segment, hβ©
convert (convex_segment xβ x).norm_image_sub_le_of_norm_hasFDerivWithin_le
(f := fun x β¦ f x - f xβ) (y := x) (x := xβ) (s := segment β xβ x) ?_ h
(left_mem_segment β xβ x) (right_mem_segment β xβ x) using 1
Β· simp
Β· simp only [hasFDerivWithinAt_sub_const_iff]
exact fun x hx β¦ (hff' x (h_segment hx)).mono h_segment
theorem isLittleO_pow_succ_real {f f' : β β E} {xβ : β} {n : β} {s : Set β}
(hs : Convex β s) (hxβs : xβ β s)
(hff' : β x β s, HasDerivWithinAt f (f' x) s x) (hf' : f' =o[π[s] xβ] fun x β¦ (x - xβ) ^ n) :
(fun x β¦ f x - f xβ) =o[π[s] xβ] fun x β¦ (x - xβ) ^ (n + 1) := by
have h := hs.isLittleO_pow_succ hxβs hff' ?_ (n := n)
Β· rw [Asymptotics.isLittleO_iff] at h β’
simpa using h
Β· rw [Asymptotics.isLittleO_iff] at hf' β’
convert hf' using 4 with c hc x
simp
end Convex
namespace Convex
variable {π G : Type*} [RCLike π] [NormedAddCommGroup G] [NormedSpace π G]
{f f' : π β G} {s : Set π} {x y : π}
/-- The mean value theorem on a convex set in dimension 1: if the derivative of a function is
bounded by `C`, then the function is `C`-Lipschitz. Version with `HasDerivWithinAt`. -/
theorem norm_image_sub_le_of_norm_hasDerivWithin_le {C : β}
(hf : β x β s, HasDerivWithinAt f (f' x) s x) (bound : β x β s, βf' xβ β€ C) (hs : Convex β s)
(xs : x β s) (ys : y β s) : βf y - f xβ β€ C * βy - xβ :=
Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt)
(fun x hx => le_trans (by simp) (bound x hx)) hs xs ys
/-- The mean value theorem on a convex set in dimension 1: if the derivative of a function is
bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`.
Version with `HasDerivWithinAt` and `LipschitzOnWith`. -/
theorem lipschitzOnWith_of_nnnorm_hasDerivWithin_le {C : ββ₯0} (hs : Convex β s)
(hf : β x β s, HasDerivWithinAt f (f' x) s x) (bound : β x β s, βf' xββ β€ C) :
LipschitzOnWith C f s :=
Convex.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt)
(fun x hx => le_trans (by simp) (bound x hx)) hs
/-- The mean value theorem on a convex set in dimension 1: if the derivative of a function within
this set is bounded by `C`, then the function is `C`-Lipschitz. Version with `derivWithin` -/
theorem norm_image_sub_le_of_norm_derivWithin_le {C : β} (hf : DifferentiableOn π f s)
(bound : β x β s, βderivWithin f s xβ β€ C) (hs : Convex β s) (xs : x β s) (ys : y β s) :
βf y - f xβ β€ C * βy - xβ :=
hs.norm_image_sub_le_of_norm_hasDerivWithin_le (fun x hx => (hf x hx).hasDerivWithinAt) bound xs
ys
/-- The mean value theorem on a convex set in dimension 1: if the derivative of a function is
bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`.
Version with `derivWithin` and `LipschitzOnWith`. -/
theorem lipschitzOnWith_of_nnnorm_derivWithin_le {C : ββ₯0} (hs : Convex β s)
(hf : DifferentiableOn π f s) (bound : β x β s, βderivWithin f s xββ β€ C) :
LipschitzOnWith C f s :=
hs.lipschitzOnWith_of_nnnorm_hasDerivWithin_le (fun x hx => (hf x hx).hasDerivWithinAt) bound
/-- The mean value theorem on a convex set in dimension 1: if the derivative of a function is
bounded by `C`, then the function is `C`-Lipschitz. Version with `deriv`. -/
theorem norm_image_sub_le_of_norm_deriv_le {C : β} (hf : β x β s, DifferentiableAt π f x)
(bound : β x β s, βderiv f xβ β€ C) (hs : Convex β s) (xs : x β s) (ys : y β s) :
βf y - f xβ β€ C * βy - xβ :=
hs.norm_image_sub_le_of_norm_hasDerivWithin_le
(fun x hx => (hf x hx).hasDerivAt.hasDerivWithinAt) bound xs ys
/-- The mean value theorem on a convex set in dimension 1: if the derivative of a function is
bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`.
Version with `deriv` and `LipschitzOnWith`. -/
theorem lipschitzOnWith_of_nnnorm_deriv_le {C : ββ₯0} (hf : β x β s, DifferentiableAt π f x)
(bound : β x β s, βderiv f xββ β€ C) (hs : Convex β s) : LipschitzOnWith C f s :=
hs.lipschitzOnWith_of_nnnorm_hasDerivWithin_le
(fun x hx => (hf x hx).hasDerivAt.hasDerivWithinAt) bound
/-- The mean value theorem set in dimension 1: if the derivative of a function is bounded by `C`,
then the function is `C`-Lipschitz. Version with `deriv` and `LipschitzWith`. -/
theorem _root_.lipschitzWith_of_nnnorm_deriv_le {C : ββ₯0} (hf : Differentiable π f)
(bound : β x, βderiv f xββ β€ C) : LipschitzWith C f :=
lipschitzOnWith_univ.1 <|
convex_univ.lipschitzOnWith_of_nnnorm_deriv_le (fun x _ => hf x) fun x _ => bound x
/-- If `f : π β G`, `π = R` or `π = β`, is differentiable everywhere and its derivative equal zero,
then it is a constant function. -/
theorem _root_.is_const_of_deriv_eq_zero (hf : Differentiable π f) (hf' : β x, deriv f x = 0)
(x y : π) : f x = f y :=
is_const_of_fderiv_eq_zero hf (fun z => by ext; simp [β deriv_fderiv, hf']) _ _
theorem _root_.IsOpen.isOpen_inter_preimage_of_deriv_eq_zero
(hs : IsOpen s) (hf : DifferentiableOn π f s)
(hf' : s.EqOn (deriv f) 0) (t : Set G) : IsOpen (s β© f β»ΒΉ' t) :=
hs.isOpen_inter_preimage_of_fderiv_eq_zero hf
(fun x hx β¦ by ext; simp [β deriv_fderiv, hf' hx]) t
theorem _root_.IsOpen.exists_is_const_of_deriv_eq_zero
(hs : IsOpen s) (hs' : IsPreconnected s) (hf : DifferentiableOn π f s)
(hf' : s.EqOn (deriv f) 0) : β a, β x β s, f x = a :=
hs.exists_is_const_of_fderiv_eq_zero hs' hf (fun {x} hx β¦ by ext; simp [β deriv_fderiv, hf' hx])
theorem _root_.IsOpen.is_const_of_deriv_eq_zero
(hs : IsOpen s) (hs' : IsPreconnected s) (hf : DifferentiableOn π f s)
(hf' : s.EqOn (deriv f) 0) {x y : π} (hx : x β s) (hy : y β s) : f x = f y :=
hs.is_const_of_fderiv_eq_zero hs' hf (fun a ha β¦ by ext; simp [β deriv_fderiv, hf' ha]) hx hy
theorem _root_.IsOpen.exists_eq_add_of_deriv_eq {f g : π β G} (hs : IsOpen s)
(hs' : IsPreconnected s)
| (hf : DifferentiableOn π f s) (hg : DifferentiableOn π g s)
(hf' : s.EqOn (deriv f) (deriv g)) : β a, s.EqOn f (g Β· + a) :=
hs.exists_eq_add_of_fderiv_eq hs' hf hg (fun x hx β¦ by ext; simp [β deriv_fderiv, hf' hx])
theorem _root_.IsOpen.eqOn_of_deriv_eq {f g : π β G} (hs : IsOpen s)
(hs' : IsPreconnected s) (hf : DifferentiableOn π f s) (hg : DifferentiableOn π g s)
| Mathlib/Analysis/Calculus/MeanValue.lean | 767 | 772 |
/-
Copyright (c) 2023 JoΓ«l Riou. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: JoΓ«l Riou
-/
import Mathlib.Algebra.Homology.HomotopyCategory.HomComplex
import Mathlib.Algebra.Homology.HomotopyCategory.Shift
/-! Shifting cochains
Let `C` be a preadditive category. Given two cochain complexes (indexed by `β€`),
the type of cochains `HomComplex.Cochain K L n` of degree `n` was introduced
in `Mathlib.Algebra.Homology.HomotopyCategory.HomComplex`. In this file, we
study how these cochains behave with respect to the shift on the complexes `K`
and `L`.
When `n`, `a`, `n'` are integers such that `h : n' + a = n`,
we obtain `rightShiftAddEquiv K L n a n' h : Cochain K L n β+ Cochain K (Lβ¦aβ§) n'`.
This definition does not involve signs, but the analogous definition
of `leftShiftAddEquiv K L n a n' h' : Cochain K L n β+ Cochain (Kβ¦aβ§) L n'`
when `h' : n + a = n'` does involve signs, as we follow the conventions
appearing in the introduction of
[Brian Conrad's book *Grothendieck duality and base change*][conrad2000].
## References
* [Brian Conrad, Grothendieck duality and base change][conrad2000]
-/
assert_not_exists TwoSidedIdeal
open CategoryTheory Category Limits Preadditive
universe v u
variable {C : Type u} [Category.{v} C] [Preadditive C] {R : Type*} [Ring R] [Linear R C]
{K L M : CochainComplex C β€} {n : β€}
namespace CochainComplex.HomComplex
namespace Cochain
variable (Ξ³ Ξ³β Ξ³β : Cochain K L n)
/-- The map `Cochain K L n β Cochain K (Lβ¦aβ§) n'` when `n' + a = n`. -/
def rightShift (a n' : β€) (hn' : n' + a = n) : Cochain K (Lβ¦aβ§) n' :=
Cochain.mk (fun p q hpq => Ξ³.v p (p + n) rfl β«
(L.shiftFunctorObjXIso a q (p + n) (by omega)).inv)
lemma rightShift_v (a n' : β€) (hn' : n' + a = n) (p q : β€) (hpq : p + n' = q)
(p' : β€) (hp' : p + n = p') :
(Ξ³.rightShift a n' hn').v p q hpq = Ξ³.v p p' hp' β«
(L.shiftFunctorObjXIso a q p' (by rw [β hp', β hpq, β hn', add_assoc])).inv := by
subst hp'
dsimp only [rightShift]
simp only [mk_v]
/-- The map `Cochain K L n β Cochain (Kβ¦aβ§) L n'` when `n + a = n'`. -/
def leftShift (a n' : β€) (hn' : n + a = n') : Cochain (Kβ¦aβ§) L n' :=
Cochain.mk (fun p q hpq => (a * n' + ((a * (a-1))/2)).negOnePow β’
(K.shiftFunctorObjXIso a p (p + a) rfl).hom β« Ξ³.v (p+a) q (by omega))
lemma leftShift_v (a n' : β€) (hn' : n + a = n') (p q : β€) (hpq : p + n' = q)
(p' : β€) (hp' : p' + n = q) :
(Ξ³.leftShift a n' hn').v p q hpq = (a * n' + ((a * (a - 1))/2)).negOnePow β’
(K.shiftFunctorObjXIso a p p'
(by rw [β add_left_inj n, hp', add_assoc, add_comm a, hn', hpq])).hom β« Ξ³.v p' q hp' := by
obtain rfl : p' = p + a := by omega
dsimp only [leftShift]
simp only [mk_v]
/-- The map `Cochain K (Lβ¦aβ§) n' β Cochain K L n` when `n' + a = n`. -/
def rightUnshift {n' a : β€} (Ξ³ : Cochain K (Lβ¦aβ§) n') (n : β€) (hn : n' + a = n) :
Cochain K L n :=
Cochain.mk (fun p q hpq => Ξ³.v p (p + n') rfl β«
(L.shiftFunctorObjXIso a (p + n') q (by rw [β hpq, add_assoc, hn])).hom)
lemma rightUnshift_v {n' a : β€} (Ξ³ : Cochain K (Lβ¦aβ§) n') (n : β€) (hn : n' + a = n)
(p q : β€) (hpq : p + n = q) (p' : β€) (hp' : p + n' = p') :
(Ξ³.rightUnshift n hn).v p q hpq = Ξ³.v p p' hp' β«
(L.shiftFunctorObjXIso a p' q (by rw [β hpq, β hn, β add_assoc, hp'])).hom := by
subst hp'
dsimp only [rightUnshift]
simp only [mk_v]
/-- The map `Cochain (Kβ¦aβ§) L n' β Cochain K L n` when `n + a = n'`. -/
def leftUnshift {n' a : β€} (Ξ³ : Cochain (Kβ¦aβ§) L n') (n : β€) (hn : n + a = n') :
Cochain K L n :=
Cochain.mk (fun p q hpq => (a * n' + ((a * (a-1))/2)).negOnePow β’
(K.shiftFunctorObjXIso a (p - a) p (by omega)).inv β« Ξ³.v (p-a) q (by omega))
lemma leftUnshift_v {n' a : β€} (Ξ³ : Cochain (Kβ¦aβ§) L n') (n : β€) (hn : n + a = n')
(p q : β€) (hpq : p + n = q) (p' : β€) (hp' : p' + n' = q) :
(Ξ³.leftUnshift n hn).v p q hpq = (a * n' + ((a * (a-1))/2)).negOnePow β’
(K.shiftFunctorObjXIso a p' p (by omega)).inv β« Ξ³.v p' q (by omega) := by
obtain rfl : p' = p - a := by omega
rfl
/-- The map `Cochain K L n β Cochain (Kβ¦aβ§) (Lβ¦aβ§) n`. -/
def shift (a : β€) : Cochain (Kβ¦aβ§) (Lβ¦aβ§) n :=
Cochain.mk (fun p q hpq => (K.shiftFunctorObjXIso a p _ rfl).hom β«
Ξ³.v (p + a) (q + a) (by omega) β« (L.shiftFunctorObjXIso a q _ rfl).inv)
lemma shift_v (a : β€) (p q : β€) (hpq : p + n = q) (p' q' : β€)
(hp' : p' = p + a) (hq' : q' = q + a) :
(Ξ³.shift a).v p q hpq = (K.shiftFunctorObjXIso a p p' hp').hom β«
Ξ³.v p' q' (by rw [hp', hq', β hpq, add_assoc, add_comm a, add_assoc]) β«
(L.shiftFunctorObjXIso a q q' hq').inv := by
subst hp' hq'
rfl
lemma shift_v' (a : β€) (p q : β€) (hpq : p + n = q) :
(Ξ³.shift a).v p q hpq = Ξ³.v (p + a) (q + a) (by omega) := by
simp only [shift_v Ξ³ a p q hpq _ _ rfl rfl, shiftFunctor_obj_X, shiftFunctorObjXIso,
HomologicalComplex.XIsoOfEq_rfl, Iso.refl_hom, Iso.refl_inv, comp_id, id_comp]
@[simp]
lemma rightUnshift_rightShift (a n' : β€) (hn' : n' + a = n) :
(Ξ³.rightShift a n' hn').rightUnshift n hn' = Ξ³ := by
ext p q hpq
simp only [rightUnshift_v _ n hn' p q hpq (p + n') rfl,
Ξ³.rightShift_v _ _ hn' p (p + n') rfl q hpq,
shiftFunctorObjXIso, assoc, Iso.inv_hom_id, comp_id]
@[simp]
lemma rightShift_rightUnshift {a n' : β€} (Ξ³ : Cochain K (Lβ¦aβ§) n') (n : β€) (hn' : n' + a = n) :
(Ξ³.rightUnshift n hn').rightShift a n' hn' = Ξ³ := by
ext p q hpq
simp only [(Ξ³.rightUnshift n hn').rightShift_v a n' hn' p q hpq (p + n) rfl,
Ξ³.rightUnshift_v n hn' p (p + n) rfl q hpq,
shiftFunctorObjXIso, assoc, Iso.hom_inv_id, comp_id]
@[simp]
lemma leftUnshift_leftShift (a n' : β€) (hn' : n + a = n') :
(Ξ³.leftShift a n' hn').leftUnshift n hn' = Ξ³ := by
ext p q hpq
rw [(Ξ³.leftShift a n' hn').leftUnshift_v n hn' p q hpq (q-n') (by omega),
Ξ³.leftShift_v a n' hn' (q-n') q (by omega) p hpq, Linear.comp_units_smul,
Iso.inv_hom_id_assoc, smul_smul, Int.units_mul_self, one_smul]
@[simp]
lemma leftShift_leftUnshift {a n' : β€} (Ξ³ : Cochain (Kβ¦aβ§) L n') (n : β€) (hn' : n + a = n') :
(Ξ³.leftUnshift n hn').leftShift a n' hn' = Ξ³ := by
ext p q hpq
rw [(Ξ³.leftUnshift n hn').leftShift_v a n' hn' p q hpq (q-n) (by omega),
Ξ³.leftUnshift_v n hn' (q-n) q (by omega) p hpq, Linear.comp_units_smul, smul_smul,
Iso.hom_inv_id_assoc, Int.units_mul_self, one_smul]
@[simp]
lemma rightShift_add (a n' : β€) (hn' : n' + a = n) :
(Ξ³β + Ξ³β).rightShift a n' hn' = Ξ³β.rightShift a n' hn' + Ξ³β.rightShift a n' hn' := by
ext p q hpq
dsimp
simp only [rightShift_v _ a n' hn' p q hpq _ rfl, add_v, add_comp]
@[simp]
lemma leftShift_add (a n' : β€) (hn' : n + a = n') :
(Ξ³β + Ξ³β).leftShift a n' hn' = Ξ³β.leftShift a n' hn' + Ξ³β.leftShift a n' hn' := by
ext p q hpq
dsimp
simp only [leftShift_v _ a n' hn' p q hpq (p + a) (by omega), add_v, comp_add, smul_add]
@[simp]
lemma shift_add (a : β€) :
(Ξ³β + Ξ³β).shift a = Ξ³β.shift a + Ξ³β.shift a := by
ext p q hpq
dsimp
simp only [shift_v', add_v]
variable (K L)
/-- The additive equivalence `Cochain K L n β+ Cochain K Lβ¦aβ§ n'` when `n' + a = n`. -/
@[simps]
def rightShiftAddEquiv (n a n' : β€) (hn' : n' + a = n) :
Cochain K L n β+ Cochain K (Lβ¦aβ§) n' where
toFun Ξ³ := Ξ³.rightShift a n' hn'
invFun Ξ³ := Ξ³.rightUnshift n hn'
left_inv Ξ³ := by simp only [rightUnshift_rightShift]
right_inv Ξ³ := by simp only [rightShift_rightUnshift]
map_add' Ξ³ Ξ³' := by simp only [rightShift_add]
/-- The additive equivalence `Cochain K L n β+ Cochain (Kβ¦aβ§) L n'` when `n + a = n'`. -/
@[simps]
def leftShiftAddEquiv (n a n' : β€) (hn' : n + a = n') :
Cochain K L n β+ Cochain (Kβ¦aβ§) L n' where
toFun Ξ³ := Ξ³.leftShift a n' hn'
invFun Ξ³ := Ξ³.leftUnshift n hn'
left_inv Ξ³ := by simp only [leftUnshift_leftShift]
right_inv Ξ³ := by simp only [leftShift_leftUnshift]
map_add' Ξ³ Ξ³' := by simp only [leftShift_add]
/-- The additive map `Cochain K L n β+ Cochain (Kβ¦aβ§) (Lβ¦aβ§) n`. -/
@[simps!]
def shiftAddHom (n a : β€) : Cochain K L n β+ Cochain (Kβ¦aβ§) (Lβ¦aβ§) n :=
AddMonoidHom.mk' (fun Ξ³ => Ξ³.shift a) (by intros; dsimp; simp only [shift_add])
variable (n)
@[simp]
lemma rightShift_zero (a n' : β€) (hn' : n' + a = n) :
(0 : Cochain K L n).rightShift a n' hn' = 0 := by
change rightShiftAddEquiv K L n a n' hn' 0 = 0
apply map_zero
@[simp]
lemma rightUnshift_zero (a n' : β€) (hn' : n' + a = n) :
(0 : Cochain K (Lβ¦aβ§) n').rightUnshift n hn' = 0 := by
change (rightShiftAddEquiv K L n a n' hn').symm 0 = 0
apply map_zero
@[simp]
lemma leftShift_zero (a n' : β€) (hn' : n + a = n') :
(0 : Cochain K L n).leftShift a n' hn' = 0 := by
change leftShiftAddEquiv K L n a n' hn' 0 = 0
apply map_zero
@[simp]
lemma leftUnshift_zero (a n' : β€) (hn' : n + a = n') :
(0 : Cochain (Kβ¦aβ§) L n').leftUnshift n hn' = 0 := by
change (leftShiftAddEquiv K L n a n' hn').symm 0 = 0
apply map_zero
@[simp]
lemma shift_zero (a : β€) :
(0 : Cochain K L n).shift a = 0 := by
change shiftAddHom K L n a 0 = 0
apply map_zero
variable {K L n}
@[simp]
lemma rightShift_neg (a n' : β€) (hn' : n' + a = n) :
(-Ξ³).rightShift a n' hn' = -Ξ³.rightShift a n' hn' := by
change rightShiftAddEquiv K L n a n' hn' (-Ξ³) = _
apply map_neg
@[simp]
lemma rightUnshift_neg {n' a : β€} (Ξ³ : Cochain K (Lβ¦aβ§) n') (n : β€) (hn : n' + a = n) :
(-Ξ³).rightUnshift n hn = -Ξ³.rightUnshift n hn := by
change (rightShiftAddEquiv K L n a n' hn).symm (-Ξ³) = _
apply map_neg
@[simp]
lemma leftShift_neg (a n' : β€) (hn' : n + a = n') :
(-Ξ³).leftShift a n' hn' = -Ξ³.leftShift a n' hn' := by
| change leftShiftAddEquiv K L n a n' hn' (-Ξ³) = _
apply map_neg
@[simp]
lemma leftUnshift_neg {n' a : β€} (Ξ³ : Cochain (Kβ¦aβ§) L n') (n : β€) (hn : n + a = n') :
| Mathlib/Algebra/Homology/HomotopyCategory/HomComplexShift.lean | 246 | 250 |
/-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle SΓΆnne
-/
import Mathlib.Analysis.SpecialFunctions.Exp
import Mathlib.Data.Nat.Factorization.Defs
import Mathlib.Analysis.NormedSpace.Real
import Mathlib.Data.Rat.Cast.CharZero
/-!
# Real logarithm
In this file we define `Real.log` to be the logarithm of a real number. As usual, we extend it from
its domain `(0, +β)` to a globally defined function. We choose to do it so that `log 0 = 0` and
`log (-x) = log x`.
We prove some basic properties of this function and show that it is continuous.
## Tags
logarithm, continuity
-/
open Set Filter Function
open Topology
noncomputable section
namespace Real
variable {x y : β}
/-- The real logarithm function, equal to the inverse of the exponential for `x > 0`,
to `log |x|` for `x < 0`, and to `0` for `0`. We use this unconventional extension to
`(-β, 0]` as it gives the formula `log (x * y) = log x + log y` for all nonzero `x` and `y`, and
the derivative of `log` is `1/x` away from `0`. -/
@[pp_nodot]
noncomputable def log (x : β) : β :=
if hx : x = 0 then 0 else expOrderIso.symm β¨|x|, abs_pos.2 hxβ©
theorem log_of_ne_zero (hx : x β 0) : log x = expOrderIso.symm β¨|x|, abs_pos.2 hxβ© :=
dif_neg hx
theorem log_of_pos (hx : 0 < x) : log x = expOrderIso.symm β¨x, hxβ© := by
rw [log_of_ne_zero hx.ne']
congr
exact abs_of_pos hx
theorem exp_log_eq_abs (hx : x β 0) : exp (log x) = |x| := by
rw [log_of_ne_zero hx, β coe_expOrderIso_apply, OrderIso.apply_symm_apply, Subtype.coe_mk]
theorem exp_log (hx : 0 < x) : exp (log x) = x := by
rw [exp_log_eq_abs hx.ne']
exact abs_of_pos hx
theorem exp_log_of_neg (hx : x < 0) : exp (log x) = -x := by
rw [exp_log_eq_abs (ne_of_lt hx)]
exact abs_of_neg hx
theorem le_exp_log (x : β) : x β€ exp (log x) := by
by_cases h_zero : x = 0
Β· rw [h_zero, log, dif_pos rfl, exp_zero]
exact zero_le_one
Β· rw [exp_log_eq_abs h_zero]
exact le_abs_self _
@[simp]
theorem log_exp (x : β) : log (exp x) = x :=
exp_injective <| exp_log (exp_pos x)
theorem exp_one_mul_le_exp {x : β} : exp 1 * x β€ exp x := by
by_cases hx0 : x β€ 0
Β· apply le_trans (mul_nonpos_of_nonneg_of_nonpos (exp_pos 1).le hx0) (exp_nonneg x)
Β· have h := add_one_le_exp (log x)
rwa [β exp_le_exp, exp_add, exp_log (lt_of_not_le hx0), mul_comm] at h
theorem two_mul_le_exp {x : β} : 2 * x β€ exp x := by
by_cases hx0 : x < 0
Β· exact le_trans (mul_nonpos_of_nonneg_of_nonpos (by simp only [Nat.ofNat_nonneg]) hx0.le)
(exp_nonneg x)
Β· apply le_trans (mul_le_mul_of_nonneg_right _ (le_of_not_lt hx0)) exp_one_mul_le_exp
have := Real.add_one_le_exp 1
rwa [one_add_one_eq_two] at this
theorem surjOn_log : SurjOn log (Ioi 0) univ := fun x _ => β¨exp x, exp_pos x, log_exp xβ©
theorem log_surjective : Surjective log := fun x => β¨exp x, log_exp xβ©
@[simp]
theorem range_log : range log = univ :=
log_surjective.range_eq
@[simp]
theorem log_zero : log 0 = 0 :=
dif_pos rfl
@[simp]
theorem log_one : log 1 = 0 :=
exp_injective <| by rw [exp_log zero_lt_one, exp_zero]
/-- This holds true for all `x : β` because of the junk values `0 / 0 = 0` and `log 0 = 0`. -/
@[simp] lemma log_div_self (x : β) : log (x / x) = 0 := by
obtain rfl | hx := eq_or_ne x 0 <;> simp [*]
@[simp]
theorem log_abs (x : β) : log |x| = log x := by
by_cases h : x = 0
Β· simp [h]
Β· rw [β exp_eq_exp, exp_log_eq_abs h, exp_log_eq_abs (abs_pos.2 h).ne', abs_abs]
@[simp]
theorem log_neg_eq_log (x : β) : log (-x) = log x := by rw [β log_abs x, β log_abs (-x), abs_neg]
theorem sinh_log {x : β} (hx : 0 < x) : sinh (log x) = (x - xβ»ΒΉ) / 2 := by
rw [sinh_eq, exp_neg, exp_log hx]
theorem cosh_log {x : β} (hx : 0 < x) : cosh (log x) = (x + xβ»ΒΉ) / 2 := by
rw [cosh_eq, exp_neg, exp_log hx]
theorem surjOn_log' : SurjOn log (Iio 0) univ := fun x _ =>
β¨-exp x, neg_lt_zero.2 <| exp_pos x, by rw [log_neg_eq_log, log_exp]β©
theorem log_mul (hx : x β 0) (hy : y β 0) : log (x * y) = log x + log y :=
exp_injective <| by
rw [exp_log_eq_abs (mul_ne_zero hx hy), exp_add, exp_log_eq_abs hx, exp_log_eq_abs hy, abs_mul]
theorem log_div (hx : x β 0) (hy : y β 0) : log (x / y) = log x - log y :=
exp_injective <| by
rw [exp_log_eq_abs (div_ne_zero hx hy), exp_sub, exp_log_eq_abs hx, exp_log_eq_abs hy, abs_div]
@[simp]
theorem log_inv (x : β) : log xβ»ΒΉ = -log x := by
by_cases hx : x = 0; Β· simp [hx]
rw [β exp_eq_exp, exp_log_eq_abs (inv_ne_zero hx), exp_neg, exp_log_eq_abs hx, abs_inv]
theorem log_le_log_iff (h : 0 < x) (hβ : 0 < y) : log x β€ log y β x β€ y := by
rw [β exp_le_exp, exp_log h, exp_log hβ]
@[gcongr, bound]
lemma log_le_log (hx : 0 < x) (hxy : x β€ y) : log x β€ log y :=
(log_le_log_iff hx (hx.trans_le hxy)).2 hxy
@[gcongr, bound]
theorem log_lt_log (hx : 0 < x) (h : x < y) : log x < log y := by
rwa [β exp_lt_exp, exp_log hx, exp_log (lt_trans hx h)]
theorem log_lt_log_iff (hx : 0 < x) (hy : 0 < y) : log x < log y β x < y := by
rw [β exp_lt_exp, exp_log hx, exp_log hy]
theorem log_le_iff_le_exp (hx : 0 < x) : log x β€ y β x β€ exp y := by rw [β exp_le_exp, exp_log hx]
theorem log_lt_iff_lt_exp (hx : 0 < x) : log x < y β x < exp y := by rw [β exp_lt_exp, exp_log hx]
theorem le_log_iff_exp_le (hy : 0 < y) : x β€ log y β exp x β€ y := by rw [β exp_le_exp, exp_log hy]
theorem lt_log_iff_exp_lt (hy : 0 < y) : x < log y β exp x < y := by rw [β exp_lt_exp, exp_log hy]
theorem log_pos_iff (hx : 0 β€ x) : 0 < log x β 1 < x := by
rcases hx.eq_or_lt with (rfl | hx)
| Β· simp [le_refl, zero_le_one]
| Mathlib/Analysis/SpecialFunctions/Log/Basic.lean | 162 | 162 |
/-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Johannes HΓΆlzl, Kim Morrison, Jens Wagemaker, Johan Commelin
-/
import Mathlib.Algebra.Polynomial.BigOperators
import Mathlib.Algebra.Polynomial.RingDivision
import Mathlib.Data.Set.Finite.Lemmas
import Mathlib.RingTheory.Coprime.Lemmas
import Mathlib.RingTheory.Localization.FractionRing
import Mathlib.SetTheory.Cardinal.Order
/-!
# Theory of univariate polynomials
We define the multiset of roots of a polynomial, and prove basic results about it.
## Main definitions
* `Polynomial.roots p`: The multiset containing all the roots of `p`, including their
multiplicities.
* `Polynomial.rootSet p E`: The set of distinct roots of `p` in an algebra `E`.
## Main statements
* `Polynomial.C_leadingCoeff_mul_prod_multiset_X_sub_C`: If a polynomial has as many roots as its
degree, it can be written as the product of its leading coefficient with `β (X - a)` where `a`
ranges through its roots.
-/
assert_not_exists Ideal
open Multiset Finset
noncomputable section
namespace Polynomial
universe u v w z
variable {R : Type u} {S : Type v} {T : Type w} {a b : R} {n : β}
section CommRing
variable [CommRing R] [IsDomain R] {p q : R[X]}
section Roots
/-- `roots p` noncomputably gives a multiset containing all the roots of `p`,
including their multiplicities. -/
noncomputable def roots (p : R[X]) : Multiset R :=
haveI := Classical.decEq R
haveI := Classical.dec (p = 0)
if h : p = 0 then β
else Classical.choose (exists_multiset_roots h)
theorem roots_def [DecidableEq R] (p : R[X]) [Decidable (p = 0)] :
p.roots = if h : p = 0 then β
else Classical.choose (exists_multiset_roots h) := by
rename_i iR ip0
obtain rfl := Subsingleton.elim iR (Classical.decEq R)
obtain rfl := Subsingleton.elim ip0 (Classical.dec (p = 0))
rfl
@[simp]
theorem roots_zero : (0 : R[X]).roots = 0 :=
dif_pos rfl
theorem card_roots (hp0 : p β 0) : (Multiset.card (roots p) : WithBot β) β€ degree p := by
classical
unfold roots
rw [dif_neg hp0]
exact (Classical.choose_spec (exists_multiset_roots hp0)).1
theorem card_roots' (p : R[X]) : Multiset.card p.roots β€ natDegree p := by
by_cases hp0 : p = 0
Β· simp [hp0]
exact WithBot.coe_le_coe.1 (le_trans (card_roots hp0) (le_of_eq <| degree_eq_natDegree hp0))
theorem card_roots_sub_C {p : R[X]} {a : R} (hp0 : 0 < degree p) :
(Multiset.card (p - C a).roots : WithBot β) β€ degree p :=
calc
(Multiset.card (p - C a).roots : WithBot β) β€ degree (p - C a) :=
card_roots <| mt sub_eq_zero.1 fun h => not_le_of_gt hp0 <| h.symm βΈ degree_C_le
_ = degree p := by rw [sub_eq_add_neg, β C_neg]; exact degree_add_C hp0
theorem card_roots_sub_C' {p : R[X]} {a : R} (hp0 : 0 < degree p) :
Multiset.card (p - C a).roots β€ natDegree p :=
WithBot.coe_le_coe.1
(le_trans (card_roots_sub_C hp0)
(le_of_eq <| degree_eq_natDegree fun h => by simp_all [lt_irrefl]))
@[simp]
theorem count_roots [DecidableEq R] (p : R[X]) : p.roots.count a = rootMultiplicity a p := by
classical
by_cases hp : p = 0
Β· simp [hp]
rw [roots_def, dif_neg hp]
exact (Classical.choose_spec (exists_multiset_roots hp)).2 a
@[simp]
theorem mem_roots' : a β p.roots β p β 0 β§ IsRoot p a := by
classical
rw [β count_pos, count_roots p, rootMultiplicity_pos']
theorem mem_roots (hp : p β 0) : a β p.roots β IsRoot p a :=
mem_roots'.trans <| and_iff_right hp
theorem ne_zero_of_mem_roots (h : a β p.roots) : p β 0 :=
(mem_roots'.1 h).1
theorem isRoot_of_mem_roots (h : a β p.roots) : IsRoot p a :=
(mem_roots'.1 h).2
theorem mem_roots_map_of_injective [Semiring S] {p : S[X]} {f : S β+* R}
(hf : Function.Injective f) {x : R} (hp : p β 0) : x β (p.map f).roots β p.evalβ f x = 0 := by
rw [mem_roots ((Polynomial.map_ne_zero_iff hf).mpr hp), IsRoot, eval_map]
lemma mem_roots_iff_aeval_eq_zero {x : R} (w : p β 0) : x β roots p β aeval x p = 0 := by
rw [aeval_def, β mem_roots_map_of_injective (FaithfulSMul.algebraMap_injective _ _) w,
Algebra.id.map_eq_id, map_id]
theorem card_le_degree_of_subset_roots {p : R[X]} {Z : Finset R} (h : Z.val β p.roots) :
#Z β€ p.natDegree :=
(Multiset.card_le_card (Finset.val_le_iff_val_subset.2 h)).trans (Polynomial.card_roots' p)
theorem finite_setOf_isRoot {p : R[X]} (hp : p β 0) : Set.Finite { x | IsRoot p x } := by
classical
simpa only [β Finset.setOf_mem, Multiset.mem_toFinset, mem_roots hp]
using p.roots.toFinset.finite_toSet
theorem eq_zero_of_infinite_isRoot (p : R[X]) (h : Set.Infinite { x | IsRoot p x }) : p = 0 :=
not_imp_comm.mp finite_setOf_isRoot h
theorem exists_max_root [LinearOrder R] (p : R[X]) (hp : p β 0) : β xβ, β x, p.IsRoot x β x β€ xβ :=
Set.exists_upper_bound_image _ _ <| finite_setOf_isRoot hp
theorem exists_min_root [LinearOrder R] (p : R[X]) (hp : p β 0) : β xβ, β x, p.IsRoot x β xβ β€ x :=
Set.exists_lower_bound_image _ _ <| finite_setOf_isRoot hp
theorem eq_of_infinite_eval_eq (p q : R[X]) (h : Set.Infinite { x | eval x p = eval x q }) :
p = q := by
rw [β sub_eq_zero]
apply eq_zero_of_infinite_isRoot
simpa only [IsRoot, eval_sub, sub_eq_zero]
theorem roots_mul {p q : R[X]} (hpq : p * q β 0) : (p * q).roots = p.roots + q.roots := by
classical
exact Multiset.ext.mpr fun r => by
rw [count_add, count_roots, count_roots, count_roots, rootMultiplicity_mul hpq]
theorem roots.le_of_dvd (h : q β 0) : p β£ q β roots p β€ roots q := by
rintro β¨k, rflβ©
exact Multiset.le_iff_exists_add.mpr β¨k.roots, roots_mul hβ©
theorem mem_roots_sub_C' {p : R[X]} {a x : R} : x β (p - C a).roots β p β C a β§ p.eval x = a := by
rw [mem_roots', IsRoot.def, sub_ne_zero, eval_sub, sub_eq_zero, eval_C]
theorem mem_roots_sub_C {p : R[X]} {a x : R} (hp0 : 0 < degree p) :
x β (p - C a).roots β p.eval x = a :=
mem_roots_sub_C'.trans <| and_iff_right fun hp => hp0.not_le <| hp.symm βΈ degree_C_le
@[simp]
theorem roots_X_sub_C (r : R) : roots (X - C r) = {r} := by
classical
ext s
rw [count_roots, rootMultiplicity_X_sub_C, count_singleton]
@[simp]
theorem roots_X_add_C (r : R) : roots (X + C r) = {-r} := by simpa using roots_X_sub_C (-r)
@[simp]
theorem roots_X : roots (X : R[X]) = {0} := by rw [β roots_X_sub_C, C_0, sub_zero]
@[simp]
theorem roots_C (x : R) : (C x).roots = 0 := by
classical exact
if H : x = 0 then by rw [H, C_0, roots_zero]
else
Multiset.ext.mpr fun r => (by
rw [count_roots, count_zero, rootMultiplicity_eq_zero (not_isRoot_C _ _ H)])
@[simp]
theorem roots_one : (1 : R[X]).roots = β
:=
roots_C 1
@[simp]
theorem roots_C_mul (p : R[X]) (ha : a β 0) : (C a * p).roots = p.roots := by
by_cases hp : p = 0 <;>
simp only [roots_mul, *, Ne, mul_eq_zero, C_eq_zero, or_self_iff, not_false_iff, roots_C,
zero_add, mul_zero]
@[simp]
theorem roots_smul_nonzero (p : R[X]) (ha : a β 0) : (a β’ p).roots = p.roots := by
rw [smul_eq_C_mul, roots_C_mul _ ha]
@[simp]
lemma roots_neg (p : R[X]) : (-p).roots = p.roots := by
rw [β neg_one_smul R p, roots_smul_nonzero p (neg_ne_zero.mpr one_ne_zero)]
@[simp]
theorem roots_C_mul_X_sub_C_of_IsUnit (b : R) (a : RΛ£) : (C (a : R) * X - C b).roots =
{aβ»ΒΉ * b} := by
rw [β roots_C_mul _ (Units.ne_zero aβ»ΒΉ), mul_sub, β mul_assoc, β C_mul, β C_mul,
Units.inv_mul, C_1, one_mul]
exact roots_X_sub_C (aβ»ΒΉ * b)
@[simp]
theorem roots_C_mul_X_add_C_of_IsUnit (b : R) (a : RΛ£) : (C (a : R) * X + C b).roots =
{-(aβ»ΒΉ * b)} := by
rw [β sub_neg_eq_add, β C_neg, roots_C_mul_X_sub_C_of_IsUnit, mul_neg]
theorem roots_list_prod (L : List R[X]) :
(0 : R[X]) β L β L.prod.roots = (L : Multiset R[X]).bind roots :=
List.recOn L (fun _ => roots_one) fun hd tl ih H => by
rw [List.mem_cons, not_or] at H
rw [List.prod_cons, roots_mul (mul_ne_zero (Ne.symm H.1) <| List.prod_ne_zero H.2), β
Multiset.cons_coe, Multiset.cons_bind, ih H.2]
theorem roots_multiset_prod (m : Multiset R[X]) : (0 : R[X]) β m β m.prod.roots = m.bind roots := by
rcases m with β¨Lβ©
simpa only [Multiset.prod_coe, quot_mk_to_coe''] using roots_list_prod L
theorem roots_prod {ΞΉ : Type*} (f : ΞΉ β R[X]) (s : Finset ΞΉ) :
| s.prod f β 0 β (s.prod f).roots = s.val.bind fun i => roots (f i) := by
rcases s with β¨m, hmβ©
simpa [Multiset.prod_eq_zero_iff, Multiset.bind_map] using roots_multiset_prod (m.map f)
| Mathlib/Algebra/Polynomial/Roots.lean | 224 | 226 |
/-
Copyright (c) 2020 SΓ©bastien GouΓ«zel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: SΓ©bastien GouΓ«zel, Floris van Doorn
-/
import Mathlib.Geometry.Manifold.IsManifold.ExtChartAt
import Mathlib.Geometry.Manifold.LocalInvariantProperties
/-!
# `C^n` functions between manifolds
We define `CβΏ` functions between manifolds, as functions which are `CβΏ` in charts, and prove
basic properties of these notions. Here, `n` can be finite, or `β`, or `Ο`.
## Main definitions and statements
Let `M` and `M'` be two manifolds, with respect to models with corners `I` and `I'`. Let
`f : M β M'`.
* `ContMDiffWithinAt I I' n f s x` states that the function `f` is `CβΏ` within the set `s`
around the point `x`.
* `ContMDiffAt I I' n f x` states that the function `f` is `CβΏ` around `x`.
* `ContMDiffOn I I' n f s` states that the function `f` is `CβΏ` on the set `s`
* `ContMDiff I I' n f` states that the function `f` is `CβΏ`.
We also give some basic properties of `CβΏ` functions between manifolds, following the API of
`C^n` functions between vector spaces.
See `Basic.lean` for further basic properties of `CβΏ` functions between manifolds,
`NormedSpace.lean` for the equivalence of manifold-smoothness to usual smoothness,
`Product.lean` for smoothness results related to the product of manifolds and
`Atlas.lean` for smoothness of atlas members and local structomorphisms.
## Implementation details
Many properties follow for free from the corresponding properties of functions in vector spaces,
as being `CβΏ` is a local property invariant under the `CβΏ` groupoid. We take advantage of the
general machinery developed in `LocalInvariantProperties.lean` to get these properties
automatically. For instance, the fact that being `CβΏ` does not depend on the chart one considers
is given by `liftPropWithinAt_indep_chart`.
For this to work, the definition of `ContMDiffWithinAt` and friends has to
follow definitionally the setup of local invariant properties. Still, we recast the definition
in terms of extended charts in `contMDiffOn_iff` and `contMDiff_iff`.
-/
open Set Function Filter ChartedSpace IsManifold
open scoped Topology Manifold ContDiff
/-! ### Definition of `CβΏ` functions between manifolds -/
variable {π : Type*} [NontriviallyNormedField π]
-- Prerequisite typeclasses to say that `M` is a manifold over the pair `(E, H)`
{E : Type*}
[NormedAddCommGroup E] [NormedSpace π E] {H : Type*} [TopologicalSpace H]
{I : ModelWithCorners π E H} {M : Type*} [TopologicalSpace M] [ChartedSpace H M]
-- Prerequisite typeclasses to say that `M'` is a manifold over the pair `(E', H')`
{E' : Type*}
[NormedAddCommGroup E'] [NormedSpace π E'] {H' : Type*} [TopologicalSpace H']
{I' : ModelWithCorners π E' H'} {M' : Type*} [TopologicalSpace M'] [ChartedSpace H' M']
-- Prerequisite typeclasses to say that `M''` is a manifold over the pair `(E'', H'')`
{E'' : Type*}
[NormedAddCommGroup E''] [NormedSpace π E''] {H'' : Type*} [TopologicalSpace H'']
{I'' : ModelWithCorners π E'' H''} {M'' : Type*} [TopologicalSpace M''] [ChartedSpace H'' M'']
-- declare functions, sets, points and smoothness indices
{e : PartialHomeomorph M H}
{e' : PartialHomeomorph M' H'} {f fβ : M β M'} {s sβ t : Set M} {x : M} {m n : WithTop ββ}
variable (I I') in
/-- Property in the model space of a model with corners of being `C^n` within at set at a point,
when read in the model vector space. This property will be lifted to manifolds to define `C^n`
functions between manifolds. -/
def ContDiffWithinAtProp (n : WithTop ββ) (f : H β H') (s : Set H) (x : H) : Prop :=
ContDiffWithinAt π n (I' β f β I.symm) (I.symm β»ΒΉ' s β© range I) (I x)
theorem contDiffWithinAtProp_self_source {f : E β H'} {s : Set E} {x : E} :
ContDiffWithinAtProp π(π, E) I' n f s x β ContDiffWithinAt π n (I' β f) s x := by
simp_rw [ContDiffWithinAtProp, modelWithCornersSelf_coe, range_id, inter_univ,
modelWithCornersSelf_coe_symm, CompTriple.comp_eq, preimage_id_eq, id_eq]
theorem contDiffWithinAtProp_self {f : E β E'} {s : Set E} {x : E} :
ContDiffWithinAtProp π(π, E) π(π, E') n f s x β ContDiffWithinAt π n f s x :=
contDiffWithinAtProp_self_source
theorem contDiffWithinAtProp_self_target {f : H β E'} {s : Set H} {x : H} :
ContDiffWithinAtProp I π(π, E') n f s x β
ContDiffWithinAt π n (f β I.symm) (I.symm β»ΒΉ' s β© range I) (I x) :=
Iff.rfl
/-- Being `CβΏ` in the model space is a local property, invariant under `CβΏ` maps. Therefore,
it lifts nicely to manifolds. -/
theorem contDiffWithinAt_localInvariantProp_of_le (n m : WithTop ββ) (hmn : m β€ n) :
(contDiffGroupoid n I).LocalInvariantProp (contDiffGroupoid n I')
(ContDiffWithinAtProp I I' m) where
is_local {s x u f} u_open xu := by
have : I.symm β»ΒΉ' (s β© u) β© range I = I.symm β»ΒΉ' s β© range I β© I.symm β»ΒΉ' u := by
simp only [inter_right_comm, preimage_inter]
rw [ContDiffWithinAtProp, ContDiffWithinAtProp, this]
symm
apply contDiffWithinAt_inter
have : u β π (I.symm (I x)) := by
rw [ModelWithCorners.left_inv]
exact u_open.mem_nhds xu
apply ContinuousAt.preimage_mem_nhds I.continuous_symm.continuousAt this
right_invariance' {s x f e} he hx h := by
rw [ContDiffWithinAtProp] at h β’
have : I x = (I β e.symm β I.symm) (I (e x)) := by simp only [hx, mfld_simps]
rw [this] at h
have : I (e x) β I.symm β»ΒΉ' e.target β© range I := by simp only [hx, mfld_simps]
have := (mem_groupoid_of_pregroupoid.2 he).2.contDiffWithinAt this
convert (h.comp_inter _ (this.of_le hmn)).mono_of_mem_nhdsWithin _
using 1
Β· ext y; simp only [mfld_simps]
refine mem_nhdsWithin.mpr
β¨I.symm β»ΒΉ' e.target, e.open_target.preimage I.continuous_symm, by
simp_rw [mem_preimage, I.left_inv, e.mapsTo hx], ?_β©
mfld_set_tac
congr_of_forall {s x f g} h hx hf := by
apply hf.congr
Β· intro y hy
simp only [mfld_simps] at hy
simp only [h, hy, mfld_simps]
Β· simp only [hx, mfld_simps]
left_invariance' {s x f e'} he' hs hx h := by
rw [ContDiffWithinAtProp] at h β’
have A : (I' β f β I.symm) (I x) β I'.symm β»ΒΉ' e'.source β© range I' := by
simp only [hx, mfld_simps]
have := (mem_groupoid_of_pregroupoid.2 he').1.contDiffWithinAt A
convert (this.of_le hmn).comp _ h _
Β· ext y; simp only [mfld_simps]
Β· intro y hy; simp only [mfld_simps] at hy; simpa only [hy, mfld_simps] using hs hy.1
/-- Being `CβΏ` in the model space is a local property, invariant under `C^n` maps. Therefore,
it lifts nicely to manifolds. -/
theorem contDiffWithinAt_localInvariantProp (n : WithTop ββ) :
(contDiffGroupoid n I).LocalInvariantProp (contDiffGroupoid n I')
(ContDiffWithinAtProp I I' n) :=
contDiffWithinAt_localInvariantProp_of_le n n le_rfl
theorem contDiffWithinAtProp_mono_of_mem_nhdsWithin
(n : WithTop ββ) β¦s x tβ¦ β¦f : H β H'β¦ (hts : s β π[t] x)
(h : ContDiffWithinAtProp I I' n f s x) : ContDiffWithinAtProp I I' n f t x := by
refine h.mono_of_mem_nhdsWithin ?_
refine inter_mem ?_ (mem_of_superset self_mem_nhdsWithin inter_subset_right)
rwa [β Filter.mem_map, β I.image_eq, I.symm_map_nhdsWithin_image]
@[deprecated (since := "2024-10-31")]
alias contDiffWithinAtProp_mono_of_mem := contDiffWithinAtProp_mono_of_mem_nhdsWithin
theorem contDiffWithinAtProp_id (x : H) : ContDiffWithinAtProp I I n id univ x := by
simp only [ContDiffWithinAtProp, id_comp, preimage_univ, univ_inter]
have : ContDiffWithinAt π n id (range I) (I x) := contDiff_id.contDiffAt.contDiffWithinAt
refine this.congr (fun y hy => ?_) ?_
Β· simp only [ModelWithCorners.right_inv I hy, mfld_simps]
Β· simp only [mfld_simps]
variable (I I') in
/-- A function is `n` times continuously differentiable within a set at a point in a manifold if
it is continuous and it is `n` times continuously differentiable in this set around this point, when
read in the preferred chart at this point. -/
def ContMDiffWithinAt (n : WithTop ββ) (f : M β M') (s : Set M) (x : M) :=
LiftPropWithinAt (ContDiffWithinAtProp I I' n) f s x
@[deprecated (since := "2024-11-21")] alias SmoothWithinAt := ContMDiffWithinAt
variable (I I') in
/-- A function is `n` times continuously differentiable at a point in a manifold if
it is continuous and it is `n` times continuously differentiable around this point, when
read in the preferred chart at this point. -/
def ContMDiffAt (n : WithTop ββ) (f : M β M') (x : M) :=
ContMDiffWithinAt I I' n f univ x
theorem contMDiffAt_iff {n : WithTop ββ} {f : M β M'} {x : M} :
ContMDiffAt I I' n f x β
ContinuousAt f x β§
ContDiffWithinAt π n (extChartAt I' (f x) β f β (extChartAt I x).symm) (range I)
(extChartAt I x x) :=
liftPropAt_iff.trans <| by rw [ContDiffWithinAtProp, preimage_univ, univ_inter]; rfl
@[deprecated (since := "2024-11-21")] alias SmoothAt := ContMDiffAt
variable (I I') in
/-- A function is `n` times continuously differentiable in a set of a manifold if it is continuous
and, for any pair of points, it is `n` times continuously differentiable on this set in the charts
around these points. -/
def ContMDiffOn (n : WithTop ββ) (f : M β M') (s : Set M) :=
β x β s, ContMDiffWithinAt I I' n f s x
@[deprecated (since := "2024-11-21")] alias SmoothOn := ContMDiffOn
variable (I I') in
/-- A function is `n` times continuously differentiable in a manifold if it is continuous
and, for any pair of points, it is `n` times continuously differentiable in the charts
around these points. -/
def ContMDiff (n : WithTop ββ) (f : M β M') :=
β x, ContMDiffAt I I' n f x
@[deprecated (since := "2024-11-21")] alias Smooth := ContMDiff
/-! ### Deducing smoothness from higher smoothness -/
theorem ContMDiffWithinAt.of_le (hf : ContMDiffWithinAt I I' n f s x) (le : m β€ n) :
ContMDiffWithinAt I I' m f s x := by
simp only [ContMDiffWithinAt, LiftPropWithinAt] at hf β’
exact β¨hf.1, hf.2.of_le (mod_cast le)β©
theorem ContMDiffAt.of_le (hf : ContMDiffAt I I' n f x) (le : m β€ n) : ContMDiffAt I I' m f x :=
ContMDiffWithinAt.of_le hf le
theorem ContMDiffOn.of_le (hf : ContMDiffOn I I' n f s) (le : m β€ n) : ContMDiffOn I I' m f s :=
fun x hx => (hf x hx).of_le le
theorem ContMDiff.of_le (hf : ContMDiff I I' n f) (le : m β€ n) : ContMDiff I I' m f := fun x =>
(hf x).of_le le
/-! ### Basic properties of `C^n` functions between manifolds -/
@[deprecated (since := "2024-11-20")] alias ContMDiff.smooth := ContMDiff.of_le
@[deprecated (since := "2024-11-20")] alias Smooth.contMDiff := ContMDiff.of_le
@[deprecated (since := "2024-11-20")] alias ContMDiffOn.smoothOn := ContMDiffOn.of_le
@[deprecated (since := "2024-11-20")] alias SmoothOn.contMDiffOn := ContMDiffOn.of_le
@[deprecated (since := "2024-11-20")] alias ContMDiffAt.smoothAt := ContMDiffAt.of_le
@[deprecated (since := "2024-11-20")] alias SmoothAt.contMDiffAt := ContMDiffOn.of_le
@[deprecated (since := "2024-11-20")]
alias ContMDiffWithinAt.smoothWithinAt := ContMDiffWithinAt.of_le
@[deprecated (since := "2024-11-20")]
alias SmoothWithinAt.contMDiffWithinAt := ContMDiffWithinAt.of_le
theorem ContMDiff.contMDiffAt (h : ContMDiff I I' n f) : ContMDiffAt I I' n f x :=
h x
@[deprecated (since := "2024-11-20")] alias Smooth.smoothAt := ContMDiff.contMDiffAt
theorem contMDiffWithinAt_univ : ContMDiffWithinAt I I' n f univ x β ContMDiffAt I I' n f x :=
Iff.rfl
@[deprecated (since := "2024-11-20")] alias smoothWithinAt_univ := contMDiffWithinAt_univ
theorem contMDiffOn_univ : ContMDiffOn I I' n f univ β ContMDiff I I' n f := by
simp only [ContMDiffOn, ContMDiff, contMDiffWithinAt_univ, forall_prop_of_true, mem_univ]
@[deprecated (since := "2024-11-20")] alias smoothOn_univ := contMDiffOn_univ
/-- One can reformulate being `C^n` within a set at a point as continuity within this set at this
point, and being `C^n` in the corresponding extended chart. -/
theorem contMDiffWithinAt_iff :
ContMDiffWithinAt I I' n f s x β
ContinuousWithinAt f s x β§
ContDiffWithinAt π n (extChartAt I' (f x) β f β (extChartAt I x).symm)
((extChartAt I x).symm β»ΒΉ' s β© range I) (extChartAt I x x) := by
simp_rw [ContMDiffWithinAt, liftPropWithinAt_iff']; rfl
/-- One can reformulate being `CβΏ` within a set at a point as continuity within this set at this
point, and being `CβΏ` in the corresponding extended chart. This form states regularity of `f`
written in such a way that the set is restricted to lie within the domain/codomain of the
corresponding charts.
Even though this expression is more complicated than the one in `contMDiffWithinAt_iff`, it is
a smaller set, but their germs at `extChartAt I x x` are equal. It is sometimes useful to rewrite
using this in the goal.
-/
theorem contMDiffWithinAt_iff' :
ContMDiffWithinAt I I' n f s x β
ContinuousWithinAt f s x β§
ContDiffWithinAt π n (extChartAt I' (f x) β f β (extChartAt I x).symm)
((extChartAt I x).target β©
(extChartAt I x).symm β»ΒΉ' (s β© f β»ΒΉ' (extChartAt I' (f x)).source))
(extChartAt I x x) := by
simp only [ContMDiffWithinAt, liftPropWithinAt_iff']
exact and_congr_right fun hc => contDiffWithinAt_congr_set <|
hc.extChartAt_symm_preimage_inter_range_eventuallyEq
/-- One can reformulate being `CβΏ` within a set at a point as continuity within this set at this
point, and being `CβΏ` in the corresponding extended chart in the target. -/
theorem contMDiffWithinAt_iff_target :
ContMDiffWithinAt I I' n f s x β
ContinuousWithinAt f s x β§ ContMDiffWithinAt I π(π, E') n (extChartAt I' (f x) β f) s x := by
simp_rw [ContMDiffWithinAt, liftPropWithinAt_iff', β and_assoc]
have cont :
ContinuousWithinAt f s x β§ ContinuousWithinAt (extChartAt I' (f x) β f) s x β
ContinuousWithinAt f s x :=
and_iff_left_of_imp <| (continuousAt_extChartAt _).comp_continuousWithinAt
simp_rw [cont, ContDiffWithinAtProp, extChartAt, PartialHomeomorph.extend, PartialEquiv.coe_trans,
ModelWithCorners.toPartialEquiv_coe, PartialHomeomorph.coe_coe, modelWithCornersSelf_coe,
chartAt_self_eq, PartialHomeomorph.refl_apply, id_comp]
rfl
@[deprecated (since := "2024-11-20")] alias smoothWithinAt_iff := contMDiffWithinAt_iff
@[deprecated (since := "2024-11-20")]
alias smoothWithinAt_iff_target := contMDiffWithinAt_iff_target
theorem contMDiffAt_iff_target {x : M} :
ContMDiffAt I I' n f x β
ContinuousAt f x β§ ContMDiffAt I π(π, E') n (extChartAt I' (f x) β f) x := by
rw [ContMDiffAt, ContMDiffAt, contMDiffWithinAt_iff_target, continuousWithinAt_univ]
@[deprecated (since := "2024-11-20")] alias smoothAt_iff_target := contMDiffAt_iff_target
/-- One can reformulate being `CβΏ` within a set at a point as being `CβΏ` in the source space when
composing with the extended chart. -/
theorem contMDiffWithinAt_iff_source :
ContMDiffWithinAt I I' n f s x β
ContMDiffWithinAt π(π, E) I' n (f β (extChartAt I x).symm)
((extChartAt I x).symm β»ΒΉ' s β© range I) (extChartAt I x x) := by
simp_rw [ContMDiffWithinAt, liftPropWithinAt_iff']
have : ContinuousWithinAt f s x
β ContinuousWithinAt (f β β(extChartAt I x).symm) (β(extChartAt I x).symm β»ΒΉ' s β© range βI)
(extChartAt I x x) := by
refine β¨fun h β¦ ?_, fun h β¦ ?_β©
Β· apply h.comp_of_eq
Β· exact (continuousAt_extChartAt_symm x).continuousWithinAt
Β· exact (mapsTo_preimage _ _).mono_left inter_subset_left
Β· exact extChartAt_to_inv x
Β· rw [β continuousWithinAt_inter (extChartAt_source_mem_nhds (I := I) x)]
have : ContinuousWithinAt ((f β β(extChartAt I x).symm) β β(extChartAt I x))
(s β© (extChartAt I x).source) x := by
apply h.comp (continuousAt_extChartAt x).continuousWithinAt
intro y hy
have : (chartAt H x).symm ((chartAt H x) y) = y :=
PartialHomeomorph.left_inv _ (by simpa using hy.2)
simpa [this] using hy.1
apply this.congr
Β· intro y hy
have : (chartAt H x).symm ((chartAt H x) y) = y :=
PartialHomeomorph.left_inv _ (by simpa using hy.2)
simp [this]
Β· simp
rw [β this]
simp only [ContDiffWithinAtProp, mfld_simps, preimage_comp, comp_assoc]
/-- One can reformulate being `CβΏ` at a point as being `CβΏ` in the source space when
composing with the extended chart. -/
theorem contMDiffAt_iff_source :
ContMDiffAt I I' n f x β
ContMDiffWithinAt π(π, E) I' n (f β (extChartAt I x).symm) (range I) (extChartAt I x x) := by
rw [β contMDiffWithinAt_univ, contMDiffWithinAt_iff_source]
simp
section IsManifold
theorem contMDiffWithinAt_iff_source_of_mem_maximalAtlas
[IsManifold I n M] (he : e β maximalAtlas I n M) (hx : x β e.source) :
ContMDiffWithinAt I I' n f s x β
ContMDiffWithinAt π(π, E) I' n (f β (e.extend I).symm) ((e.extend I).symm β»ΒΉ' s β© range I)
(e.extend I x) := by
have h2x := hx; rw [β e.extend_source (I := I)] at h2x
simp_rw [ContMDiffWithinAt,
(contDiffWithinAt_localInvariantProp n).liftPropWithinAt_indep_chart_source he hx,
StructureGroupoid.liftPropWithinAt_self_source,
e.extend_symm_continuousWithinAt_comp_right_iff, contDiffWithinAtProp_self_source,
ContDiffWithinAtProp, Function.comp, e.left_inv hx, (e.extend I).left_inv h2x]
rfl
theorem contMDiffWithinAt_iff_source_of_mem_source
[IsManifold I n M] {x' : M} (hx' : x' β (chartAt H x).source) :
ContMDiffWithinAt I I' n f s x' β
ContMDiffWithinAt π(π, E) I' n (f β (extChartAt I x).symm)
((extChartAt I x).symm β»ΒΉ' s β© range I) (extChartAt I x x') :=
contMDiffWithinAt_iff_source_of_mem_maximalAtlas (chart_mem_maximalAtlas x) hx'
theorem contMDiffAt_iff_source_of_mem_source
[IsManifold I n M] {x' : M} (hx' : x' β (chartAt H x).source) :
ContMDiffAt I I' n f x' β
ContMDiffWithinAt π(π, E) I' n (f β (extChartAt I x).symm) (range I) (extChartAt I x x') := by
simp_rw [ContMDiffAt, contMDiffWithinAt_iff_source_of_mem_source hx', preimage_univ, univ_inter]
| theorem contMDiffWithinAt_iff_target_of_mem_source
[IsManifold I' n M'] {x : M} {y : M'} (hy : f x β (chartAt H' y).source) :
ContMDiffWithinAt I I' n f s x β
ContinuousWithinAt f s x β§ ContMDiffWithinAt I π(π, E') n (extChartAt I' y β f) s x := by
| Mathlib/Geometry/Manifold/ContMDiff/Defs.lean | 377 | 380 |
/-
Copyright (c) 2021 Kexing Ying. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kexing Ying, RΓ©my Degenne
-/
import Mathlib.Probability.Process.Adapted
import Mathlib.MeasureTheory.Constructions.BorelSpace.Order
/-!
# Stopping times, stopped processes and stopped values
Definition and properties of stopping times.
## Main definitions
* `MeasureTheory.IsStoppingTime`: a stopping time with respect to some filtration `f` is a
function `Ο` such that for all `i`, the preimage of `{j | j β€ i}` along `Ο` is
`f i`-measurable
* `MeasureTheory.IsStoppingTime.measurableSpace`: the Ο-algebra associated with a stopping time
## Main results
* `ProgMeasurable.stoppedProcess`: the stopped process of a progressively measurable process is
progressively measurable.
* `memLp_stoppedProcess`: if a process belongs to `βp` at every time in `β`, then its stopped
process belongs to `βp` as well.
## Tags
stopping time, stochastic process
-/
open Filter Order TopologicalSpace
open scoped MeasureTheory NNReal ENNReal Topology
namespace MeasureTheory
variable {Ξ© Ξ² ΞΉ : Type*} {m : MeasurableSpace Ξ©}
/-! ### Stopping times -/
/-- A stopping time with respect to some filtration `f` is a function
`Ο` such that for all `i`, the preimage of `{j | j β€ i}` along `Ο` is measurable
with respect to `f i`.
Intuitively, the stopping time `Ο` describes some stopping rule such that at time
`i`, we may determine it with the information we have at time `i`. -/
def IsStoppingTime [Preorder ΞΉ] (f : Filtration ΞΉ m) (Ο : Ξ© β ΞΉ) :=
β i : ΞΉ, MeasurableSet[f i] <| {Ο | Ο Ο β€ i}
theorem isStoppingTime_const [Preorder ΞΉ] (f : Filtration ΞΉ m) (i : ΞΉ) :
IsStoppingTime f fun _ => i := fun j => by simp only [MeasurableSet.const]
section MeasurableSet
section Preorder
variable [Preorder ΞΉ] {f : Filtration ΞΉ m} {Ο : Ξ© β ΞΉ}
protected theorem IsStoppingTime.measurableSet_le (hΟ : IsStoppingTime f Ο) (i : ΞΉ) :
MeasurableSet[f i] {Ο | Ο Ο β€ i} :=
hΟ i
theorem IsStoppingTime.measurableSet_lt_of_pred [PredOrder ΞΉ] (hΟ : IsStoppingTime f Ο) (i : ΞΉ) :
MeasurableSet[f i] {Ο | Ο Ο < i} := by
by_cases hi_min : IsMin i
Β· suffices {Ο : Ξ© | Ο Ο < i} = β
by rw [this]; exact @MeasurableSet.empty _ (f i)
ext1 Ο
simp only [Set.mem_setOf_eq, Set.mem_empty_iff_false, iff_false]
rw [isMin_iff_forall_not_lt] at hi_min
exact hi_min (Ο Ο)
have : {Ο : Ξ© | Ο Ο < i} = Ο β»ΒΉ' Set.Iic (pred i) := by ext; simp [Iic_pred_of_not_isMin hi_min]
rw [this]
exact f.mono (pred_le i) _ (hΟ.measurableSet_le <| pred i)
end Preorder
section CountableStoppingTime
namespace IsStoppingTime
variable [PartialOrder ΞΉ] {Ο : Ξ© β ΞΉ} {f : Filtration ΞΉ m}
protected theorem measurableSet_eq_of_countable_range (hΟ : IsStoppingTime f Ο)
(h_countable : (Set.range Ο).Countable) (i : ΞΉ) : MeasurableSet[f i] {Ο | Ο Ο = i} := by
have : {Ο | Ο Ο = i} = {Ο | Ο Ο β€ i} \ β (j β Set.range Ο) (_ : j < i), {Ο | Ο Ο β€ j} := by
ext1 a
simp only [Set.mem_setOf_eq, Set.mem_range, Set.iUnion_exists, Set.iUnion_iUnion_eq',
Set.mem_diff, Set.mem_iUnion, exists_prop, not_exists, not_and, not_le]
constructor <;> intro h
Β· simp only [h, lt_iff_le_not_le, le_refl, and_imp, imp_self, imp_true_iff, and_self_iff]
Β· exact h.1.eq_or_lt.resolve_right fun h_lt => h.2 a h_lt le_rfl
rw [this]
refine (hΟ.measurableSet_le i).diff ?_
refine MeasurableSet.biUnion h_countable fun j _ => ?_
classical
rw [Set.iUnion_eq_if]
split_ifs with hji
Β· exact f.mono hji.le _ (hΟ.measurableSet_le j)
Β· exact @MeasurableSet.empty _ (f i)
protected theorem measurableSet_eq_of_countable [Countable ΞΉ] (hΟ : IsStoppingTime f Ο) (i : ΞΉ) :
MeasurableSet[f i] {Ο | Ο Ο = i} :=
hΟ.measurableSet_eq_of_countable_range (Set.to_countable _) i
protected theorem measurableSet_lt_of_countable_range (hΟ : IsStoppingTime f Ο)
(h_countable : (Set.range Ο).Countable) (i : ΞΉ) : MeasurableSet[f i] {Ο | Ο Ο < i} := by
have : {Ο | Ο Ο < i} = {Ο | Ο Ο β€ i} \ {Ο | Ο Ο = i} := by ext1 Ο; simp [lt_iff_le_and_ne]
rw [this]
exact (hΟ.measurableSet_le i).diff (hΟ.measurableSet_eq_of_countable_range h_countable i)
protected theorem measurableSet_lt_of_countable [Countable ΞΉ] (hΟ : IsStoppingTime f Ο) (i : ΞΉ) :
MeasurableSet[f i] {Ο | Ο Ο < i} :=
hΟ.measurableSet_lt_of_countable_range (Set.to_countable _) i
protected theorem measurableSet_ge_of_countable_range {ΞΉ} [LinearOrder ΞΉ] {Ο : Ξ© β ΞΉ}
{f : Filtration ΞΉ m} (hΟ : IsStoppingTime f Ο) (h_countable : (Set.range Ο).Countable) (i : ΞΉ) :
MeasurableSet[f i] {Ο | i β€ Ο Ο} := by
have : {Ο | i β€ Ο Ο} = {Ο | Ο Ο < i}αΆ := by
ext1 Ο; simp only [Set.mem_setOf_eq, Set.mem_compl_iff, not_lt]
rw [this]
exact (hΟ.measurableSet_lt_of_countable_range h_countable i).compl
protected theorem measurableSet_ge_of_countable {ΞΉ} [LinearOrder ΞΉ] {Ο : Ξ© β ΞΉ} {f : Filtration ΞΉ m}
[Countable ΞΉ] (hΟ : IsStoppingTime f Ο) (i : ΞΉ) : MeasurableSet[f i] {Ο | i β€ Ο Ο} :=
hΟ.measurableSet_ge_of_countable_range (Set.to_countable _) i
end IsStoppingTime
end CountableStoppingTime
section LinearOrder
variable [LinearOrder ΞΉ] {f : Filtration ΞΉ m} {Ο : Ξ© β ΞΉ}
theorem IsStoppingTime.measurableSet_gt (hΟ : IsStoppingTime f Ο) (i : ΞΉ) :
MeasurableSet[f i] {Ο | i < Ο Ο} := by
have : {Ο | i < Ο Ο} = {Ο | Ο Ο β€ i}αΆ := by
ext1 Ο; simp only [Set.mem_setOf_eq, Set.mem_compl_iff, not_le]
rw [this]
exact (hΟ.measurableSet_le i).compl
section TopologicalSpace
variable [TopologicalSpace ΞΉ] [OrderTopology ΞΉ] [FirstCountableTopology ΞΉ]
/-- Auxiliary lemma for `MeasureTheory.IsStoppingTime.measurableSet_lt`. -/
theorem IsStoppingTime.measurableSet_lt_of_isLUB (hΟ : IsStoppingTime f Ο) (i : ΞΉ)
(h_lub : IsLUB (Set.Iio i) i) : MeasurableSet[f i] {Ο | Ο Ο < i} := by
by_cases hi_min : IsMin i
Β· suffices {Ο | Ο Ο < i} = β
by rw [this]; exact @MeasurableSet.empty _ (f i)
ext1 Ο
simp only [Set.mem_setOf_eq, Set.mem_empty_iff_false, iff_false]
exact isMin_iff_forall_not_lt.mp hi_min (Ο Ο)
obtain β¨seq, -, -, h_tendsto, h_boundβ© :
β seq : β β ΞΉ, Monotone seq β§ (β j, seq j β€ i) β§ Tendsto seq atTop (π i) β§ β j, seq j < i :=
h_lub.exists_seq_monotone_tendsto (not_isMin_iff.mp hi_min)
have h_Ioi_eq_Union : Set.Iio i = β j, {k | k β€ seq j} := by
ext1 k
simp only [Set.mem_Iio, Set.mem_iUnion, Set.mem_setOf_eq]
refine β¨fun hk_lt_i => ?_, fun h_exists_k_le_seq => ?_β©
Β· rw [tendsto_atTop'] at h_tendsto
have h_nhds : Set.Ici k β π i :=
mem_nhds_iff.mpr β¨Set.Ioi k, Set.Ioi_subset_Ici le_rfl, isOpen_Ioi, hk_lt_iβ©
obtain β¨a, haβ© : β a : β, β b : β, b β₯ a β k β€ seq b := h_tendsto (Set.Ici k) h_nhds
exact β¨a, ha a le_rflβ©
Β· obtain β¨j, hk_seq_jβ© := h_exists_k_le_seq
exact hk_seq_j.trans_lt (h_bound j)
have h_lt_eq_preimage : {Ο | Ο Ο < i} = Ο β»ΒΉ' Set.Iio i := by
ext1 Ο; simp only [Set.mem_setOf_eq, Set.mem_preimage, Set.mem_Iio]
rw [h_lt_eq_preimage, h_Ioi_eq_Union]
simp only [Set.preimage_iUnion, Set.preimage_setOf_eq]
exact MeasurableSet.iUnion fun n => f.mono (h_bound n).le _ (hΟ.measurableSet_le (seq n))
theorem IsStoppingTime.measurableSet_lt (hΟ : IsStoppingTime f Ο) (i : ΞΉ) :
MeasurableSet[f i] {Ο | Ο Ο < i} := by
obtain β¨i', hi'_lubβ© : β i', IsLUB (Set.Iio i) i' := exists_lub_Iio i
rcases lub_Iio_eq_self_or_Iio_eq_Iic i hi'_lub with hi'_eq_i | h_Iio_eq_Iic
Β· rw [β hi'_eq_i] at hi'_lub β’
exact hΟ.measurableSet_lt_of_isLUB i' hi'_lub
Β· have h_lt_eq_preimage : {Ο : Ξ© | Ο Ο < i} = Ο β»ΒΉ' Set.Iio i := rfl
rw [h_lt_eq_preimage, h_Iio_eq_Iic]
exact f.mono (lub_Iio_le i hi'_lub) _ (hΟ.measurableSet_le i')
theorem IsStoppingTime.measurableSet_ge (hΟ : IsStoppingTime f Ο) (i : ΞΉ) :
MeasurableSet[f i] {Ο | i β€ Ο Ο} := by
have : {Ο | i β€ Ο Ο} = {Ο | Ο Ο < i}αΆ := by
ext1 Ο; simp only [Set.mem_setOf_eq, Set.mem_compl_iff, not_lt]
rw [this]
exact (hΟ.measurableSet_lt i).compl
theorem IsStoppingTime.measurableSet_eq (hΟ : IsStoppingTime f Ο) (i : ΞΉ) :
MeasurableSet[f i] {Ο | Ο Ο = i} := by
have : {Ο | Ο Ο = i} = {Ο | Ο Ο β€ i} β© {Ο | Ο Ο β₯ i} := by
ext1 Ο; simp only [Set.mem_setOf_eq, Set.mem_inter_iff, le_antisymm_iff]
rw [this]
exact (hΟ.measurableSet_le i).inter (hΟ.measurableSet_ge i)
| theorem IsStoppingTime.measurableSet_eq_le (hΟ : IsStoppingTime f Ο) {i j : ΞΉ} (hle : i β€ j) :
MeasurableSet[f j] {Ο | Ο Ο = i} :=
f.mono hle _ <| hΟ.measurableSet_eq i
theorem IsStoppingTime.measurableSet_lt_le (hΟ : IsStoppingTime f Ο) {i j : ΞΉ} (hle : i β€ j) :
MeasurableSet[f j] {Ο | Ο Ο < i} :=
| Mathlib/Probability/Process/Stopping.lean | 202 | 207 |
/-
Copyright (c) 2020 SΓ©bastien GouΓ«zel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: SΓ©bastien GouΓ«zel, Floris van Doorn
-/
import Mathlib.Geometry.Manifold.IsManifold.ExtChartAt
import Mathlib.Geometry.Manifold.LocalInvariantProperties
/-!
# `C^n` functions between manifolds
We define `CβΏ` functions between manifolds, as functions which are `CβΏ` in charts, and prove
basic properties of these notions. Here, `n` can be finite, or `β`, or `Ο`.
## Main definitions and statements
Let `M` and `M'` be two manifolds, with respect to models with corners `I` and `I'`. Let
`f : M β M'`.
* `ContMDiffWithinAt I I' n f s x` states that the function `f` is `CβΏ` within the set `s`
around the point `x`.
* `ContMDiffAt I I' n f x` states that the function `f` is `CβΏ` around `x`.
* `ContMDiffOn I I' n f s` states that the function `f` is `CβΏ` on the set `s`
* `ContMDiff I I' n f` states that the function `f` is `CβΏ`.
We also give some basic properties of `CβΏ` functions between manifolds, following the API of
`C^n` functions between vector spaces.
See `Basic.lean` for further basic properties of `CβΏ` functions between manifolds,
`NormedSpace.lean` for the equivalence of manifold-smoothness to usual smoothness,
`Product.lean` for smoothness results related to the product of manifolds and
`Atlas.lean` for smoothness of atlas members and local structomorphisms.
## Implementation details
Many properties follow for free from the corresponding properties of functions in vector spaces,
as being `CβΏ` is a local property invariant under the `CβΏ` groupoid. We take advantage of the
general machinery developed in `LocalInvariantProperties.lean` to get these properties
automatically. For instance, the fact that being `CβΏ` does not depend on the chart one considers
is given by `liftPropWithinAt_indep_chart`.
For this to work, the definition of `ContMDiffWithinAt` and friends has to
follow definitionally the setup of local invariant properties. Still, we recast the definition
in terms of extended charts in `contMDiffOn_iff` and `contMDiff_iff`.
-/
open Set Function Filter ChartedSpace IsManifold
open scoped Topology Manifold ContDiff
/-! ### Definition of `CβΏ` functions between manifolds -/
variable {π : Type*} [NontriviallyNormedField π]
-- Prerequisite typeclasses to say that `M` is a manifold over the pair `(E, H)`
{E : Type*}
[NormedAddCommGroup E] [NormedSpace π E] {H : Type*} [TopologicalSpace H]
{I : ModelWithCorners π E H} {M : Type*} [TopologicalSpace M] [ChartedSpace H M]
-- Prerequisite typeclasses to say that `M'` is a manifold over the pair `(E', H')`
{E' : Type*}
[NormedAddCommGroup E'] [NormedSpace π E'] {H' : Type*} [TopologicalSpace H']
{I' : ModelWithCorners π E' H'} {M' : Type*} [TopologicalSpace M'] [ChartedSpace H' M']
-- Prerequisite typeclasses to say that `M''` is a manifold over the pair `(E'', H'')`
{E'' : Type*}
[NormedAddCommGroup E''] [NormedSpace π E''] {H'' : Type*} [TopologicalSpace H'']
{I'' : ModelWithCorners π E'' H''} {M'' : Type*} [TopologicalSpace M''] [ChartedSpace H'' M'']
-- declare functions, sets, points and smoothness indices
{e : PartialHomeomorph M H}
{e' : PartialHomeomorph M' H'} {f fβ : M β M'} {s sβ t : Set M} {x : M} {m n : WithTop ββ}
variable (I I') in
/-- Property in the model space of a model with corners of being `C^n` within at set at a point,
when read in the model vector space. This property will be lifted to manifolds to define `C^n`
functions between manifolds. -/
def ContDiffWithinAtProp (n : WithTop ββ) (f : H β H') (s : Set H) (x : H) : Prop :=
ContDiffWithinAt π n (I' β f β I.symm) (I.symm β»ΒΉ' s β© range I) (I x)
theorem contDiffWithinAtProp_self_source {f : E β H'} {s : Set E} {x : E} :
ContDiffWithinAtProp π(π, E) I' n f s x β ContDiffWithinAt π n (I' β f) s x := by
simp_rw [ContDiffWithinAtProp, modelWithCornersSelf_coe, range_id, inter_univ,
modelWithCornersSelf_coe_symm, CompTriple.comp_eq, preimage_id_eq, id_eq]
theorem contDiffWithinAtProp_self {f : E β E'} {s : Set E} {x : E} :
ContDiffWithinAtProp π(π, E) π(π, E') n f s x β ContDiffWithinAt π n f s x :=
contDiffWithinAtProp_self_source
theorem contDiffWithinAtProp_self_target {f : H β E'} {s : Set H} {x : H} :
ContDiffWithinAtProp I π(π, E') n f s x β
ContDiffWithinAt π n (f β I.symm) (I.symm β»ΒΉ' s β© range I) (I x) :=
Iff.rfl
/-- Being `CβΏ` in the model space is a local property, invariant under `CβΏ` maps. Therefore,
it lifts nicely to manifolds. -/
theorem contDiffWithinAt_localInvariantProp_of_le (n m : WithTop ββ) (hmn : m β€ n) :
(contDiffGroupoid n I).LocalInvariantProp (contDiffGroupoid n I')
(ContDiffWithinAtProp I I' m) where
is_local {s x u f} u_open xu := by
have : I.symm β»ΒΉ' (s β© u) β© range I = I.symm β»ΒΉ' s β© range I β© I.symm β»ΒΉ' u := by
simp only [inter_right_comm, preimage_inter]
rw [ContDiffWithinAtProp, ContDiffWithinAtProp, this]
symm
apply contDiffWithinAt_inter
have : u β π (I.symm (I x)) := by
rw [ModelWithCorners.left_inv]
exact u_open.mem_nhds xu
apply ContinuousAt.preimage_mem_nhds I.continuous_symm.continuousAt this
right_invariance' {s x f e} he hx h := by
rw [ContDiffWithinAtProp] at h β’
have : I x = (I β e.symm β I.symm) (I (e x)) := by simp only [hx, mfld_simps]
rw [this] at h
have : I (e x) β I.symm β»ΒΉ' e.target β© range I := by simp only [hx, mfld_simps]
have := (mem_groupoid_of_pregroupoid.2 he).2.contDiffWithinAt this
convert (h.comp_inter _ (this.of_le hmn)).mono_of_mem_nhdsWithin _
using 1
Β· ext y; simp only [mfld_simps]
refine mem_nhdsWithin.mpr
β¨I.symm β»ΒΉ' e.target, e.open_target.preimage I.continuous_symm, by
simp_rw [mem_preimage, I.left_inv, e.mapsTo hx], ?_β©
mfld_set_tac
congr_of_forall {s x f g} h hx hf := by
apply hf.congr
Β· intro y hy
simp only [mfld_simps] at hy
simp only [h, hy, mfld_simps]
Β· simp only [hx, mfld_simps]
left_invariance' {s x f e'} he' hs hx h := by
rw [ContDiffWithinAtProp] at h β’
have A : (I' β f β I.symm) (I x) β I'.symm β»ΒΉ' e'.source β© range I' := by
simp only [hx, mfld_simps]
have := (mem_groupoid_of_pregroupoid.2 he').1.contDiffWithinAt A
convert (this.of_le hmn).comp _ h _
Β· ext y; simp only [mfld_simps]
Β· intro y hy; simp only [mfld_simps] at hy; simpa only [hy, mfld_simps] using hs hy.1
/-- Being `CβΏ` in the model space is a local property, invariant under `C^n` maps. Therefore,
it lifts nicely to manifolds. -/
theorem contDiffWithinAt_localInvariantProp (n : WithTop ββ) :
(contDiffGroupoid n I).LocalInvariantProp (contDiffGroupoid n I')
(ContDiffWithinAtProp I I' n) :=
contDiffWithinAt_localInvariantProp_of_le n n le_rfl
theorem contDiffWithinAtProp_mono_of_mem_nhdsWithin
(n : WithTop ββ) β¦s x tβ¦ β¦f : H β H'β¦ (hts : s β π[t] x)
(h : ContDiffWithinAtProp I I' n f s x) : ContDiffWithinAtProp I I' n f t x := by
refine h.mono_of_mem_nhdsWithin ?_
refine inter_mem ?_ (mem_of_superset self_mem_nhdsWithin inter_subset_right)
rwa [β Filter.mem_map, β I.image_eq, I.symm_map_nhdsWithin_image]
@[deprecated (since := "2024-10-31")]
alias contDiffWithinAtProp_mono_of_mem := contDiffWithinAtProp_mono_of_mem_nhdsWithin
theorem contDiffWithinAtProp_id (x : H) : ContDiffWithinAtProp I I n id univ x := by
simp only [ContDiffWithinAtProp, id_comp, preimage_univ, univ_inter]
have : ContDiffWithinAt π n id (range I) (I x) := contDiff_id.contDiffAt.contDiffWithinAt
refine this.congr (fun y hy => ?_) ?_
Β· simp only [ModelWithCorners.right_inv I hy, mfld_simps]
Β· simp only [mfld_simps]
variable (I I') in
/-- A function is `n` times continuously differentiable within a set at a point in a manifold if
it is continuous and it is `n` times continuously differentiable in this set around this point, when
read in the preferred chart at this point. -/
def ContMDiffWithinAt (n : WithTop ββ) (f : M β M') (s : Set M) (x : M) :=
LiftPropWithinAt (ContDiffWithinAtProp I I' n) f s x
@[deprecated (since := "2024-11-21")] alias SmoothWithinAt := ContMDiffWithinAt
variable (I I') in
/-- A function is `n` times continuously differentiable at a point in a manifold if
it is continuous and it is `n` times continuously differentiable around this point, when
read in the preferred chart at this point. -/
def ContMDiffAt (n : WithTop ββ) (f : M β M') (x : M) :=
ContMDiffWithinAt I I' n f univ x
theorem contMDiffAt_iff {n : WithTop ββ} {f : M β M'} {x : M} :
ContMDiffAt I I' n f x β
ContinuousAt f x β§
ContDiffWithinAt π n (extChartAt I' (f x) β f β (extChartAt I x).symm) (range I)
(extChartAt I x x) :=
liftPropAt_iff.trans <| by rw [ContDiffWithinAtProp, preimage_univ, univ_inter]; rfl
@[deprecated (since := "2024-11-21")] alias SmoothAt := ContMDiffAt
variable (I I') in
/-- A function is `n` times continuously differentiable in a set of a manifold if it is continuous
and, for any pair of points, it is `n` times continuously differentiable on this set in the charts
around these points. -/
def ContMDiffOn (n : WithTop ββ) (f : M β M') (s : Set M) :=
β x β s, ContMDiffWithinAt I I' n f s x
@[deprecated (since := "2024-11-21")] alias SmoothOn := ContMDiffOn
variable (I I') in
/-- A function is `n` times continuously differentiable in a manifold if it is continuous
and, for any pair of points, it is `n` times continuously differentiable in the charts
around these points. -/
def ContMDiff (n : WithTop ββ) (f : M β M') :=
β x, ContMDiffAt I I' n f x
@[deprecated (since := "2024-11-21")] alias Smooth := ContMDiff
/-! ### Deducing smoothness from higher smoothness -/
theorem ContMDiffWithinAt.of_le (hf : ContMDiffWithinAt I I' n f s x) (le : m β€ n) :
ContMDiffWithinAt I I' m f s x := by
simp only [ContMDiffWithinAt, LiftPropWithinAt] at hf β’
exact β¨hf.1, hf.2.of_le (mod_cast le)β©
theorem ContMDiffAt.of_le (hf : ContMDiffAt I I' n f x) (le : m β€ n) : ContMDiffAt I I' m f x :=
ContMDiffWithinAt.of_le hf le
theorem ContMDiffOn.of_le (hf : ContMDiffOn I I' n f s) (le : m β€ n) : ContMDiffOn I I' m f s :=
fun x hx => (hf x hx).of_le le
theorem ContMDiff.of_le (hf : ContMDiff I I' n f) (le : m β€ n) : ContMDiff I I' m f := fun x =>
(hf x).of_le le
/-! ### Basic properties of `C^n` functions between manifolds -/
@[deprecated (since := "2024-11-20")] alias ContMDiff.smooth := ContMDiff.of_le
@[deprecated (since := "2024-11-20")] alias Smooth.contMDiff := ContMDiff.of_le
@[deprecated (since := "2024-11-20")] alias ContMDiffOn.smoothOn := ContMDiffOn.of_le
@[deprecated (since := "2024-11-20")] alias SmoothOn.contMDiffOn := ContMDiffOn.of_le
@[deprecated (since := "2024-11-20")] alias ContMDiffAt.smoothAt := ContMDiffAt.of_le
@[deprecated (since := "2024-11-20")] alias SmoothAt.contMDiffAt := ContMDiffOn.of_le
@[deprecated (since := "2024-11-20")]
alias ContMDiffWithinAt.smoothWithinAt := ContMDiffWithinAt.of_le
@[deprecated (since := "2024-11-20")]
alias SmoothWithinAt.contMDiffWithinAt := ContMDiffWithinAt.of_le
theorem ContMDiff.contMDiffAt (h : ContMDiff I I' n f) : ContMDiffAt I I' n f x :=
h x
@[deprecated (since := "2024-11-20")] alias Smooth.smoothAt := ContMDiff.contMDiffAt
theorem contMDiffWithinAt_univ : ContMDiffWithinAt I I' n f univ x β ContMDiffAt I I' n f x :=
Iff.rfl
@[deprecated (since := "2024-11-20")] alias smoothWithinAt_univ := contMDiffWithinAt_univ
theorem contMDiffOn_univ : ContMDiffOn I I' n f univ β ContMDiff I I' n f := by
simp only [ContMDiffOn, ContMDiff, contMDiffWithinAt_univ, forall_prop_of_true, mem_univ]
@[deprecated (since := "2024-11-20")] alias smoothOn_univ := contMDiffOn_univ
/-- One can reformulate being `C^n` within a set at a point as continuity within this set at this
point, and being `C^n` in the corresponding extended chart. -/
theorem contMDiffWithinAt_iff :
ContMDiffWithinAt I I' n f s x β
ContinuousWithinAt f s x β§
ContDiffWithinAt π n (extChartAt I' (f x) β f β (extChartAt I x).symm)
((extChartAt I x).symm β»ΒΉ' s β© range I) (extChartAt I x x) := by
simp_rw [ContMDiffWithinAt, liftPropWithinAt_iff']; rfl
/-- One can reformulate being `CβΏ` within a set at a point as continuity within this set at this
point, and being `CβΏ` in the corresponding extended chart. This form states regularity of `f`
written in such a way that the set is restricted to lie within the domain/codomain of the
corresponding charts.
Even though this expression is more complicated than the one in `contMDiffWithinAt_iff`, it is
a smaller set, but their germs at `extChartAt I x x` are equal. It is sometimes useful to rewrite
using this in the goal.
-/
theorem contMDiffWithinAt_iff' :
ContMDiffWithinAt I I' n f s x β
ContinuousWithinAt f s x β§
ContDiffWithinAt π n (extChartAt I' (f x) β f β (extChartAt I x).symm)
((extChartAt I x).target β©
(extChartAt I x).symm β»ΒΉ' (s β© f β»ΒΉ' (extChartAt I' (f x)).source))
(extChartAt I x x) := by
simp only [ContMDiffWithinAt, liftPropWithinAt_iff']
exact and_congr_right fun hc => contDiffWithinAt_congr_set <|
hc.extChartAt_symm_preimage_inter_range_eventuallyEq
/-- One can reformulate being `CβΏ` within a set at a point as continuity within this set at this
point, and being `CβΏ` in the corresponding extended chart in the target. -/
theorem contMDiffWithinAt_iff_target :
ContMDiffWithinAt I I' n f s x β
ContinuousWithinAt f s x β§ ContMDiffWithinAt I π(π, E') n (extChartAt I' (f x) β f) s x := by
simp_rw [ContMDiffWithinAt, liftPropWithinAt_iff', β and_assoc]
have cont :
ContinuousWithinAt f s x β§ ContinuousWithinAt (extChartAt I' (f x) β f) s x β
ContinuousWithinAt f s x :=
and_iff_left_of_imp <| (continuousAt_extChartAt _).comp_continuousWithinAt
simp_rw [cont, ContDiffWithinAtProp, extChartAt, PartialHomeomorph.extend, PartialEquiv.coe_trans,
ModelWithCorners.toPartialEquiv_coe, PartialHomeomorph.coe_coe, modelWithCornersSelf_coe,
chartAt_self_eq, PartialHomeomorph.refl_apply, id_comp]
rfl
@[deprecated (since := "2024-11-20")] alias smoothWithinAt_iff := contMDiffWithinAt_iff
@[deprecated (since := "2024-11-20")]
alias smoothWithinAt_iff_target := contMDiffWithinAt_iff_target
theorem contMDiffAt_iff_target {x : M} :
ContMDiffAt I I' n f x β
ContinuousAt f x β§ ContMDiffAt I π(π, E') n (extChartAt I' (f x) β f) x := by
rw [ContMDiffAt, ContMDiffAt, contMDiffWithinAt_iff_target, continuousWithinAt_univ]
@[deprecated (since := "2024-11-20")] alias smoothAt_iff_target := contMDiffAt_iff_target
/-- One can reformulate being `CβΏ` within a set at a point as being `CβΏ` in the source space when
composing with the extended chart. -/
theorem contMDiffWithinAt_iff_source :
ContMDiffWithinAt I I' n f s x β
ContMDiffWithinAt π(π, E) I' n (f β (extChartAt I x).symm)
((extChartAt I x).symm β»ΒΉ' s β© range I) (extChartAt I x x) := by
simp_rw [ContMDiffWithinAt, liftPropWithinAt_iff']
have : ContinuousWithinAt f s x
β ContinuousWithinAt (f β β(extChartAt I x).symm) (β(extChartAt I x).symm β»ΒΉ' s β© range βI)
(extChartAt I x x) := by
refine β¨fun h β¦ ?_, fun h β¦ ?_β©
Β· apply h.comp_of_eq
Β· exact (continuousAt_extChartAt_symm x).continuousWithinAt
Β· exact (mapsTo_preimage _ _).mono_left inter_subset_left
Β· exact extChartAt_to_inv x
Β· rw [β continuousWithinAt_inter (extChartAt_source_mem_nhds (I := I) x)]
have : ContinuousWithinAt ((f β β(extChartAt I x).symm) β β(extChartAt I x))
(s β© (extChartAt I x).source) x := by
apply h.comp (continuousAt_extChartAt x).continuousWithinAt
intro y hy
have : (chartAt H x).symm ((chartAt H x) y) = y :=
PartialHomeomorph.left_inv _ (by simpa using hy.2)
simpa [this] using hy.1
apply this.congr
Β· intro y hy
have : (chartAt H x).symm ((chartAt H x) y) = y :=
PartialHomeomorph.left_inv _ (by simpa using hy.2)
simp [this]
Β· simp
rw [β this]
simp only [ContDiffWithinAtProp, mfld_simps, preimage_comp, comp_assoc]
/-- One can reformulate being `CβΏ` at a point as being `CβΏ` in the source space when
composing with the extended chart. -/
theorem contMDiffAt_iff_source :
ContMDiffAt I I' n f x β
ContMDiffWithinAt π(π, E) I' n (f β (extChartAt I x).symm) (range I) (extChartAt I x x) := by
rw [β contMDiffWithinAt_univ, contMDiffWithinAt_iff_source]
simp
section IsManifold
theorem contMDiffWithinAt_iff_source_of_mem_maximalAtlas
[IsManifold I n M] (he : e β maximalAtlas I n M) (hx : x β e.source) :
ContMDiffWithinAt I I' n f s x β
ContMDiffWithinAt π(π, E) I' n (f β (e.extend I).symm) ((e.extend I).symm β»ΒΉ' s β© range I)
(e.extend I x) := by
have h2x := hx; rw [β e.extend_source (I := I)] at h2x
simp_rw [ContMDiffWithinAt,
(contDiffWithinAt_localInvariantProp n).liftPropWithinAt_indep_chart_source he hx,
StructureGroupoid.liftPropWithinAt_self_source,
e.extend_symm_continuousWithinAt_comp_right_iff, contDiffWithinAtProp_self_source,
ContDiffWithinAtProp, Function.comp, e.left_inv hx, (e.extend I).left_inv h2x]
rfl
theorem contMDiffWithinAt_iff_source_of_mem_source
[IsManifold I n M] {x' : M} (hx' : x' β (chartAt H x).source) :
ContMDiffWithinAt I I' n f s x' β
ContMDiffWithinAt π(π, E) I' n (f β (extChartAt I x).symm)
((extChartAt I x).symm β»ΒΉ' s β© range I) (extChartAt I x x') :=
contMDiffWithinAt_iff_source_of_mem_maximalAtlas (chart_mem_maximalAtlas x) hx'
theorem contMDiffAt_iff_source_of_mem_source
[IsManifold I n M] {x' : M} (hx' : x' β (chartAt H x).source) :
ContMDiffAt I I' n f x' β
ContMDiffWithinAt π(π, E) I' n (f β (extChartAt I x).symm) (range I) (extChartAt I x x') := by
simp_rw [ContMDiffAt, contMDiffWithinAt_iff_source_of_mem_source hx', preimage_univ, univ_inter]
theorem contMDiffWithinAt_iff_target_of_mem_source
[IsManifold I' n M'] {x : M} {y : M'} (hy : f x β (chartAt H' y).source) :
ContMDiffWithinAt I I' n f s x β
ContinuousWithinAt f s x β§ ContMDiffWithinAt I π(π, E') n (extChartAt I' y β f) s x := by
simp_rw [ContMDiffWithinAt]
rw [(contDiffWithinAt_localInvariantProp n).liftPropWithinAt_indep_chart_target
(chart_mem_maximalAtlas y) hy,
and_congr_right]
intro hf
simp_rw [StructureGroupoid.liftPropWithinAt_self_target]
simp_rw [((chartAt H' y).continuousAt hy).comp_continuousWithinAt hf]
rw [β extChartAt_source (I := I')] at hy
simp_rw [(continuousAt_extChartAt' hy).comp_continuousWithinAt hf]
rfl
theorem contMDiffAt_iff_target_of_mem_source
[IsManifold I' n M'] {x : M} {y : M'} (hy : f x β (chartAt H' y).source) :
ContMDiffAt I I' n f x β
ContinuousAt f x β§ ContMDiffAt I π(π, E') n (extChartAt I' y β f) x := by
rw [ContMDiffAt, contMDiffWithinAt_iff_target_of_mem_source hy, continuousWithinAt_univ,
ContMDiffAt]
| variable [IsManifold I n M] [IsManifold I' n M']
theorem contMDiffWithinAt_iff_of_mem_maximalAtlas {x : M} (he : e β maximalAtlas I n M)
(he' : e' β maximalAtlas I' n M') (hx : x β e.source) (hy : f x β e'.source) :
ContMDiffWithinAt I I' n f s x β
ContinuousWithinAt f s x β§
ContDiffWithinAt π n (e'.extend I' β f β (e.extend I).symm)
((e.extend I).symm β»ΒΉ' s β© range I) (e.extend I x) :=
(contDiffWithinAt_localInvariantProp n).liftPropWithinAt_indep_chart he hx he' hy
| Mathlib/Geometry/Manifold/ContMDiff/Defs.lean | 399 | 407 |
/-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Bhavik Mehta, Stuart Presnell
-/
import Mathlib.Data.Nat.Factorial.Basic
import Mathlib.Order.Monotone.Defs
/-!
# Binomial coefficients
This file defines binomial coefficients and proves simple lemmas (i.e. those not
requiring more imports).
For the lemma that `n.choose k` counts the `k`-element-subsets of an `n`-element set,
see `Fintype.card_powersetCard` in `Mathlib.Data.Finset.Powerset`.
## Main definition and results
* `Nat.choose`: binomial coefficients, defined inductively
* `Nat.choose_eq_factorial_div_factorial`: a proof that `choose n k = n! / (k! * (n - k)!)`
* `Nat.choose_symm`: symmetry of binomial coefficients
* `Nat.choose_le_succ_of_lt_half_left`: `choose n k` is increasing for small values of `k`
* `Nat.choose_le_middle`: `choose n r` is maximised when `r` is `n/2`
* `Nat.descFactorial_eq_factorial_mul_choose`: Relates binomial coefficients to the descending
factorial. This is used to prove `Nat.choose_le_pow` and variants. We provide similar statements
for the ascending factorial.
* `Nat.multichoose`: whereas `choose` counts combinations, `multichoose` counts multicombinations.
The fact that this is indeed the correct counting function for multisets is proved in
`Sym.card_sym_eq_multichoose` in `Data.Sym.Card`.
* `Nat.multichoose_eq` : a proof that `multichoose n k = (n + k - 1).choose k`.
This is central to the "stars and bars" technique in informal mathematics, where we switch between
counting multisets of size `k` over an alphabet of size `n` to counting strings of `k` elements
("stars") separated by `n-1` dividers ("bars"). See `Data.Sym.Card` for more detail.
## Tags
binomial coefficient, combination, multicombination, stars and bars
-/
open Nat
namespace Nat
/-- `choose n k` is the number of `k`-element subsets in an `n`-element set. Also known as binomial
coefficients. For the fact that this is the number of `k`-element-subsets of an `n`-element
set, see `Fintype.card_powersetCard`. -/
def choose : β β β β β
| _, 0 => 1
| 0, _ + 1 => 0
| n + 1, k + 1 => choose n k + choose n (k + 1)
@[simp]
theorem choose_zero_right (n : β) : choose n 0 = 1 := by cases n <;> rfl
@[simp]
theorem choose_zero_succ (k : β) : choose 0 (succ k) = 0 :=
rfl
theorem choose_succ_succ (n k : β) : choose (succ n) (succ k) = choose n k + choose n (succ k) :=
rfl
theorem choose_succ_succ' (n k : β) : choose (n + 1) (k + 1) = choose n k + choose n (k + 1) :=
rfl
theorem choose_succ_left (n k : β) (hk : 0 < k) :
choose (n + 1) k = choose n (k - 1) + choose n k := by
obtain β¨l, rflβ© : β l, k = l + 1 := Nat.exists_eq_add_of_le' hk
rfl
theorem choose_succ_right (n k : β) (hn : 0 < n) :
choose n (k + 1) = choose (n - 1) k + choose (n - 1) (k + 1) := by
obtain β¨l, rflβ© : β l, n = l + 1 := Nat.exists_eq_add_of_le' hn
rfl
theorem choose_eq_choose_pred_add {n k : β} (hn : 0 < n) (hk : 0 < k) :
choose n k = choose (n - 1) (k - 1) + choose (n - 1) k := by
obtain β¨l, rflβ© : β l, k = l + 1 := Nat.exists_eq_add_of_le' hk
rw [choose_succ_right _ _ hn, Nat.add_one_sub_one]
theorem choose_eq_zero_of_lt : β {n k}, n < k β choose n k = 0
| _, 0, hk => absurd hk (Nat.not_lt_zero _)
| 0, _ + 1, _ => choose_zero_succ _
| n + 1, k + 1, hk => by
have hnk : n < k := lt_of_succ_lt_succ hk
have hnk1 : n < k + 1 := lt_of_succ_lt hk
rw [choose_succ_succ, choose_eq_zero_of_lt hnk, choose_eq_zero_of_lt hnk1]
@[simp]
theorem choose_self (n : β) : choose n n = 1 := by
induction n <;> simp [*, choose, choose_eq_zero_of_lt (lt_succ_self _)]
@[simp]
theorem choose_succ_self (n : β) : choose n (succ n) = 0 :=
choose_eq_zero_of_lt (lt_succ_self _)
@[simp]
lemma choose_one_right (n : β) : choose n 1 = n := by induction n <;> simp [*, choose, Nat.add_comm]
-- The `n+1`-st triangle number is `n` more than the `n`-th triangle number
theorem triangle_succ (n : β) : (n + 1) * (n + 1 - 1) / 2 = n * (n - 1) / 2 + n := by
rw [β add_mul_div_left, Nat.mul_comm 2 n, β Nat.mul_add, Nat.add_sub_cancel, Nat.mul_comm]
cases n <;> rfl; apply zero_lt_succ
/-- `choose n 2` is the `n`-th triangle number. -/
theorem choose_two_right (n : β) : choose n 2 = n * (n - 1) / 2 := by
induction' n with n ih
Β· simp
Β· rw [triangle_succ n, choose, ih]
simp [Nat.add_comm]
theorem choose_pos : β {n k}, k β€ n β 0 < choose n k
| 0, _, hk => by rw [Nat.eq_zero_of_le_zero hk]; decide
| n + 1, 0, _ => by simp
| _ + 1, _ + 1, hk => Nat.add_pos_left (choose_pos (le_of_succ_le_succ hk)) _
theorem choose_eq_zero_iff {n k : β} : n.choose k = 0 β n < k :=
β¨fun h => lt_of_not_ge (mt Nat.choose_pos h.symm.not_lt), Nat.choose_eq_zero_of_ltβ©
theorem succ_mul_choose_eq : β n k, succ n * choose n k = choose (succ n) (succ k) * succ k
| 0, 0 => by decide
| 0, k + 1 => by simp [choose]
| n + 1, 0 => by simp [choose, mul_succ, Nat.add_comm]
| n + 1, k + 1 => by
rw [choose_succ_succ (succ n) (succ k), Nat.add_mul, β succ_mul_choose_eq n, mul_succ, β
succ_mul_choose_eq n, Nat.add_right_comm, β Nat.mul_add, β choose_succ_succ, β succ_mul]
theorem choose_mul_factorial_mul_factorial : β {n k}, k β€ n β choose n k * k ! * (n - k)! = n !
| 0, _, hk => by simp [Nat.eq_zero_of_le_zero hk]
| n + 1, 0, _ => by simp
| n + 1, succ k, hk => by
rcases lt_or_eq_of_le hk with hkβ | hkβ
Β· have h : choose n k * k.succ ! * (n - k)! = (k + 1) * n ! := by
rw [β choose_mul_factorial_mul_factorial (le_of_succ_le_succ hk)]
simp [factorial_succ, Nat.mul_comm, Nat.mul_left_comm, Nat.mul_assoc]
have hβ : (n - k)! = (n - k) * (n - k.succ)! := by
rw [β succ_sub_succ, succ_sub (le_of_lt_succ hkβ), factorial_succ]
have hβ : choose n (succ k) * k.succ ! * ((n - k) * (n - k.succ)!) = (n - k) * n ! := by
rw [β choose_mul_factorial_mul_factorial (le_of_lt_succ hkβ)]
simp [factorial_succ, Nat.mul_comm, Nat.mul_left_comm, Nat.mul_assoc]
have hβ : k * n ! β€ n * n ! := Nat.mul_le_mul_right _ (le_of_succ_le_succ hk)
rw [choose_succ_succ, Nat.add_mul, Nat.add_mul, succ_sub_succ, h, hβ, hβ, Nat.add_mul,
Nat.mul_sub_right_distrib, factorial_succ, β Nat.add_sub_assoc hβ, Nat.add_assoc,
β Nat.add_mul, Nat.add_sub_cancel_left, Nat.add_comm]
Β· rw [hkβ]; simp [hkβ, Nat.mul_comm, choose, Nat.sub_self]
theorem choose_mul {n k s : β} (hkn : k β€ n) (hsk : s β€ k) :
n.choose k * k.choose s = n.choose s * (n - s).choose (k - s) :=
have h : 0 < (n - k)! * (k - s)! * s ! := by apply_rules [factorial_pos, Nat.mul_pos]
Nat.mul_right_cancel h <|
calc
n.choose k * k.choose s * ((n - k)! * (k - s)! * s !) =
n.choose k * (k.choose s * s ! * (k - s)!) * (n - k)! := by
rw [Nat.mul_assoc, Nat.mul_assoc, Nat.mul_assoc, Nat.mul_assoc _ s !, Nat.mul_assoc,
Nat.mul_comm (n - k)!, Nat.mul_comm s !]
_ = n ! := by
rw [choose_mul_factorial_mul_factorial hsk, choose_mul_factorial_mul_factorial hkn]
_ = n.choose s * s ! * ((n - s).choose (k - s) * (k - s)! * (n - s - (k - s))!) := by
rw [choose_mul_factorial_mul_factorial (Nat.sub_le_sub_right hkn _),
choose_mul_factorial_mul_factorial (hsk.trans hkn)]
_ = n.choose s * (n - s).choose (k - s) * ((n - k)! * (k - s)! * s !) := by
rw [Nat.sub_sub_sub_cancel_right hsk, Nat.mul_assoc, Nat.mul_left_comm s !, Nat.mul_assoc,
Nat.mul_comm (k - s)!, Nat.mul_comm s !, Nat.mul_right_comm, β Nat.mul_assoc]
theorem choose_eq_factorial_div_factorial {n k : β} (hk : k β€ n) :
choose n k = n ! / (k ! * (n - k)!) := by
rw [β choose_mul_factorial_mul_factorial hk, Nat.mul_assoc]
exact (mul_div_left _ (Nat.mul_pos (factorial_pos _) (factorial_pos _))).symm
theorem add_choose (i j : β) : (i + j).choose j = (i + j)! / (i ! * j !) := by
rw [choose_eq_factorial_div_factorial (Nat.le_add_left j i), Nat.add_sub_cancel_right,
Nat.mul_comm]
theorem add_choose_mul_factorial_mul_factorial (i j : β) :
(i + j).choose j * i ! * j ! = (i + j)! := by
rw [β choose_mul_factorial_mul_factorial (Nat.le_add_left _ _), Nat.add_sub_cancel_right,
Nat.mul_right_comm]
theorem factorial_mul_factorial_dvd_factorial {n k : β} (hk : k β€ n) : k ! * (n - k)! β£ n ! := by
rw [β choose_mul_factorial_mul_factorial hk, Nat.mul_assoc]; exact Nat.dvd_mul_left _ _
theorem factorial_mul_factorial_dvd_factorial_add (i j : β) : i ! * j ! β£ (i + j)! := by
suffices i ! * (i + j - i) ! β£ (i + j)! by
rwa [Nat.add_sub_cancel_left i j] at this
exact factorial_mul_factorial_dvd_factorial (Nat.le_add_right _ _)
@[simp]
theorem choose_symm {n k : β} (hk : k β€ n) : choose n (n - k) = choose n k := by
rw [choose_eq_factorial_div_factorial hk, choose_eq_factorial_div_factorial (Nat.sub_le _ _),
Nat.sub_sub_self hk, Nat.mul_comm]
| theorem choose_symm_of_eq_add {n a b : β} (h : n = a + b) : Nat.choose n a = Nat.choose n b := by
suffices choose n (n - b) = choose n b by
rw [h, Nat.add_sub_cancel_right] at this; rwa [h]
| Mathlib/Data/Nat/Choose/Basic.lean | 192 | 194 |
/-
Copyright (c) 2020 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov
-/
import Mathlib.Analysis.SpecificLimits.Basic
import Mathlib.Order.Iterate
import Mathlib.Order.SemiconjSup
import Mathlib.Topology.Order.MonotoneContinuity
import Mathlib.Algebra.CharP.Defs
/-!
# Translation number of a monotone real map that commutes with `x β¦ x + 1`
Let `f : β β β` be a monotone map such that `f (x + 1) = f x + 1` for all `x`. Then the limit
$$
\tau(f)=\lim_{n\to\infty}{f^n(x)-x}{n}
$$
exists and does not depend on `x`. This number is called the *translation number* of `f`.
Different authors use different notation for this number: `Ο`, `Ο`, `rot`, etc
In this file we define a structure `CircleDeg1Lift` for bundled maps with these properties, define
translation number of `f : CircleDeg1Lift`, prove some estimates relating `f^n(x)-x` to `Ο(f)`. In
case of a continuous map `f` we also prove that `f` admits a point `x` such that `f^n(x)=x+m` if and
only if `Ο(f)=m/n`.
Maps of this type naturally appear as lifts of orientation preserving circle homeomorphisms. More
precisely, let `f` be an orientation preserving homeomorphism of the circle $S^1=β/β€$, and
consider a real number `a` such that
`β¦aβ§ = f 0`, where `β¦β§` means the natural projection `β β β/β€`. Then there exists a unique
continuous function `F : β β β` such that `F 0 = a` and `β¦F xβ§ = f β¦xβ§` for all `x` (this fact is
not formalized yet). This function is strictly monotone, continuous, and satisfies
`F (x + 1) = F x + 1`. The number `β¦Ο Fβ§ : β / β€` is called the *rotation number* of `f`.
It does not depend on the choice of `a`.
## Main definitions
* `CircleDeg1Lift`: a monotone map `f : β β β` such that `f (x + 1) = f x + 1` for all `x`;
the type `CircleDeg1Lift` is equipped with `Lattice` and `Monoid` structures; the
multiplication is given by composition: `(f * g) x = f (g x)`.
* `CircleDeg1Lift.translationNumber`: translation number of `f : CircleDeg1Lift`.
## Main statements
We prove the following properties of `CircleDeg1Lift.translationNumber`.
* `CircleDeg1Lift.translationNumber_eq_of_dist_bounded`: if the distance between `(f^n) 0`
and `(g^n) 0` is bounded from above uniformly in `n : β`, then `f` and `g` have equal
translation numbers.
* `CircleDeg1Lift.translationNumber_eq_of_semiconjBy`: if two `CircleDeg1Lift` maps `f`, `g`
are semiconjugate by a `CircleDeg1Lift` map, then `Ο f = Ο g`.
* `CircleDeg1Lift.translationNumber_units_inv`: if `f` is an invertible `CircleDeg1Lift` map
(equivalently, `f` is a lift of an orientation-preserving circle homeomorphism), then
the translation number of `fβ»ΒΉ` is the negative of the translation number of `f`.
* `CircleDeg1Lift.translationNumber_mul_of_commute`: if `f` and `g` commute, then
`Ο (f * g) = Ο f + Ο g`.
* `CircleDeg1Lift.translationNumber_eq_rat_iff`: the translation number of `f` is equal to
a rational number `m / n` if and only if `(f^n) x = x + m` for some `x`.
* `CircleDeg1Lift.semiconj_of_bijective_of_translationNumber_eq`: if `f` and `g` are two
bijective `CircleDeg1Lift` maps and their translation numbers are equal, then these
maps are semiconjugate to each other.
* `CircleDeg1Lift.semiconj_of_group_action_of_forall_translationNumber_eq`: let `fβ` and `fβ` be
two actions of a group `G` on the circle by degree 1 maps (formally, `fβ` and `fβ` are two
homomorphisms from `G β* CircleDeg1Lift`). If the translation numbers of `fβ g` and `fβ g` are
equal to each other for all `g : G`, then these two actions are semiconjugate by some
`F : CircleDeg1Lift`. This is a version of Proposition 5.4 from [Γtienne Ghys, Groupes
d'homeomorphismes du cercle et cohomologie bornee][ghys87:groupes].
## Notation
We use a local notation `Ο` for the translation number of `f : CircleDeg1Lift`.
## Implementation notes
We define the translation number of `f : CircleDeg1Lift` to be the limit of the sequence
`(f ^ (2 ^ n)) 0 / (2 ^ n)`, then prove that `((f ^ n) x - x) / n` tends to this number for any `x`.
This way it is much easier to prove that the limit exists and basic properties of the limit.
We define translation number for a wider class of maps `f : β β β` instead of lifts of orientation
preserving circle homeomorphisms for two reasons:
* non-strictly monotone circle self-maps with discontinuities naturally appear as PoincarΓ© maps
for some flows on the two-torus (e.g., one can take a constant flow and glue in a few Cherry
cells);
* definition and some basic properties still work for this class.
## References
* [Γtienne Ghys, Groupes d'homeomorphismes du cercle et cohomologie bornee][ghys87:groupes]
## TODO
Here are some short-term goals.
* Introduce a structure or a typeclass for lifts of circle homeomorphisms. We use
`Units CircleDeg1Lift` for now, but it's better to have a dedicated type (or a typeclass?).
* Prove that the `SemiconjBy` relation on circle homeomorphisms is an equivalence relation.
* Introduce `ConditionallyCompleteLattice` structure, use it in the proof of
`CircleDeg1Lift.semiconj_of_group_action_of_forall_translationNumber_eq`.
* Prove that the orbits of the irrational rotation are dense in the circle. Deduce that a
homeomorphism with an irrational rotation is semiconjugate to the corresponding irrational
translation by a continuous `CircleDeg1Lift`.
## Tags
circle homeomorphism, rotation number
-/
open Filter Set Int Topology
open Function hiding Commute
/-!
### Definition and monoid structure
-/
/-- A lift of a monotone degree one map `SΒΉ β SΒΉ`. -/
structure CircleDeg1Lift : Type extends β βo β where
map_add_one' : β x, toFun (x + 1) = toFun x + 1
namespace CircleDeg1Lift
instance : FunLike CircleDeg1Lift β β where
coe f := f.toFun
coe_injective' | β¨β¨_, _β©, _β©, β¨β¨_, _β©, _β©, rfl => rfl
instance : OrderHomClass CircleDeg1Lift β β where
map_rel f _ _ h := f.monotone' h
@[simp] theorem coe_mk (f h) : β(mk f h) = f := rfl
variable (f g : CircleDeg1Lift)
@[simp] theorem coe_toOrderHom : βf.toOrderHom = f := rfl
protected theorem monotone : Monotone f := f.monotone'
@[mono] theorem mono {x y} (h : x β€ y) : f x β€ f y := f.monotone h
theorem strictMono_iff_injective : StrictMono f β Injective f :=
f.monotone.strictMono_iff_injective
@[simp]
theorem map_add_one : β x, f (x + 1) = f x + 1 :=
f.map_add_one'
@[simp]
theorem map_one_add (x : β) : f (1 + x) = 1 + f x := by rw [add_comm, map_add_one, add_comm 1]
@[ext]
theorem ext β¦f g : CircleDeg1Liftβ¦ (h : β x, f x = g x) : f = g :=
DFunLike.ext f g h
instance : Monoid CircleDeg1Lift where
mul f g :=
{ toOrderHom := f.1.comp g.1
map_add_one' := fun x => by simp [map_add_one] }
one := β¨.id, fun _ => rflβ©
mul_one _ := rfl
one_mul _ := rfl
mul_assoc _ _ _ := DFunLike.coe_injective rfl
instance : Inhabited CircleDeg1Lift := β¨1β©
@[simp]
theorem coe_mul : β(f * g) = f β g :=
rfl
theorem mul_apply (x) : (f * g) x = f (g x) :=
rfl
@[simp]
theorem coe_one : β(1 : CircleDeg1Lift) = id :=
rfl
instance unitsHasCoeToFun : CoeFun CircleDeg1LiftΛ£ fun _ => β β β :=
β¨fun f => β(f : CircleDeg1Lift)β©
@[simp]
theorem units_inv_apply_apply (f : CircleDeg1LiftΛ£) (x : β) :
(fβ»ΒΉ : CircleDeg1LiftΛ£) (f x) = x := by simp only [β mul_apply, f.inv_mul, coe_one, id]
@[simp]
theorem units_apply_inv_apply (f : CircleDeg1LiftΛ£) (x : β) :
f ((fβ»ΒΉ : CircleDeg1LiftΛ£) x) = x := by simp only [β mul_apply, f.mul_inv, coe_one, id]
/-- If a lift of a circle map is bijective, then it is an order automorphism of the line. -/
def toOrderIso : CircleDeg1LiftΛ£ β* β βo β where
toFun f :=
{ toFun := f
invFun := βfβ»ΒΉ
left_inv := units_inv_apply_apply f
right_inv := units_apply_inv_apply f
map_rel_iff' := β¨fun h => by simpa using mono (βfβ»ΒΉ) h, mono fβ© }
map_one' := rfl
map_mul' _ _ := rfl
@[simp]
theorem coe_toOrderIso (f : CircleDeg1LiftΛ£) : β(toOrderIso f) = f :=
rfl
@[simp]
theorem coe_toOrderIso_symm (f : CircleDeg1LiftΛ£) :
β(toOrderIso f).symm = (fβ»ΒΉ : CircleDeg1LiftΛ£) :=
rfl
@[simp]
theorem coe_toOrderIso_inv (f : CircleDeg1LiftΛ£) : β(toOrderIso f)β»ΒΉ = (fβ»ΒΉ : CircleDeg1LiftΛ£) :=
rfl
theorem isUnit_iff_bijective {f : CircleDeg1Lift} : IsUnit f β Bijective f :=
β¨fun β¨u, hβ© => h βΈ (toOrderIso u).bijective, fun h =>
Units.isUnit
{ val := f
inv :=
{ toFun := (Equiv.ofBijective f h).symm
monotone' := fun x y hxy =>
(f.strictMono_iff_injective.2 h.1).le_iff_le.1
(by simp only [Equiv.ofBijective_apply_symm_apply f h, hxy])
map_add_one' := fun x =>
h.1 <| by simp only [Equiv.ofBijective_apply_symm_apply f, f.map_add_one] }
val_inv := ext <| Equiv.ofBijective_apply_symm_apply f h
inv_val := ext <| Equiv.ofBijective_symm_apply_apply f h }β©
theorem coe_pow : β n : β, β(f ^ n) = f^[n]
| 0 => rfl
| n + 1 => by
ext x
simp [coe_pow n, pow_succ]
theorem semiconjBy_iff_semiconj {f gβ gβ : CircleDeg1Lift} :
SemiconjBy f gβ gβ β Semiconj f gβ gβ :=
CircleDeg1Lift.ext_iff
theorem commute_iff_commute {f g : CircleDeg1Lift} : Commute f g β Function.Commute f g :=
CircleDeg1Lift.ext_iff
/-!
### Translate by a constant
-/
/-- The map `y β¦ x + y` as a `CircleDeg1Lift`. More precisely, we define a homomorphism from
`Multiplicative β` to `CircleDeg1LiftΛ£`, so the translation by `x` is
`translation (Multiplicative.ofAdd x)`. -/
def translate : Multiplicative β β* CircleDeg1LiftΛ£ := MonoidHom.toHomUnits <|
{ toFun := fun x =>
β¨β¨fun y => x.toAdd + y, fun _ _ h => add_le_add_left h _β©, fun _ =>
(add_assoc _ _ _).symmβ©
map_one' := ext <| zero_add
map_mul' := fun _ _ => ext <| add_assoc _ _ }
@[simp]
theorem translate_apply (x y : β) : translate (Multiplicative.ofAdd x) y = x + y :=
rfl
@[simp]
theorem translate_inv_apply (x y : β) : (translate <| Multiplicative.ofAdd x)β»ΒΉ y = -x + y :=
rfl
@[simp]
theorem translate_zpow (x : β) (n : β€) :
translate (Multiplicative.ofAdd x) ^ n = translate (Multiplicative.ofAdd <| βn * x) := by
simp only [β zsmul_eq_mul, ofAdd_zsmul, MonoidHom.map_zpow]
@[simp]
theorem translate_pow (x : β) (n : β) :
translate (Multiplicative.ofAdd x) ^ n = translate (Multiplicative.ofAdd <| βn * x) :=
translate_zpow x n
@[simp]
theorem translate_iterate (x : β) (n : β) :
(translate (Multiplicative.ofAdd x))^[n] = translate (Multiplicative.ofAdd <| βn * x) := by
rw [β coe_pow, β Units.val_pow_eq_pow_val, translate_pow]
/-!
### Commutativity with integer translations
In this section we prove that `f` commutes with translations by an integer number.
First we formulate these statements (for a natural or an integer number,
addition on the left or on the right, addition or subtraction) using `Function.Commute`,
then reformulate as `simp` lemmas `map_int_add` etc.
-/
theorem commute_nat_add (n : β) : Function.Commute f (n + Β·) := by
simpa only [nsmul_one, add_left_iterate] using Function.Commute.iterate_right f.map_one_add n
theorem commute_add_nat (n : β) : Function.Commute f (Β· + n) := by
simp only [add_comm _ (n : β), f.commute_nat_add n]
theorem commute_sub_nat (n : β) : Function.Commute f (Β· - n) := by
simpa only [sub_eq_add_neg] using
(f.commute_add_nat n).inverses_right (Equiv.addRight _).right_inv (Equiv.addRight _).left_inv
theorem commute_add_int : β n : β€, Function.Commute f (Β· + n)
| (n : β) => f.commute_add_nat n
| -[n+1] => by simpa [sub_eq_add_neg] using f.commute_sub_nat (n + 1)
theorem commute_int_add (n : β€) : Function.Commute f (n + Β·) := by
simpa only [add_comm _ (n : β)] using f.commute_add_int n
theorem commute_sub_int (n : β€) : Function.Commute f (Β· - n) := by
simpa only [sub_eq_add_neg] using
(f.commute_add_int n).inverses_right (Equiv.addRight _).right_inv (Equiv.addRight _).left_inv
@[simp]
theorem map_int_add (m : β€) (x : β) : f (m + x) = m + f x :=
f.commute_int_add m x
@[simp]
theorem map_add_int (x : β) (m : β€) : f (x + m) = f x + m :=
f.commute_add_int m x
@[simp]
theorem map_sub_int (x : β) (n : β€) : f (x - n) = f x - n :=
f.commute_sub_int n x
@[simp]
theorem map_add_nat (x : β) (n : β) : f (x + n) = f x + n :=
f.map_add_int x n
@[simp]
theorem map_nat_add (n : β) (x : β) : f (n + x) = n + f x :=
f.map_int_add n x
@[simp]
theorem map_sub_nat (x : β) (n : β) : f (x - n) = f x - n :=
f.map_sub_int x n
theorem map_int_of_map_zero (n : β€) : f n = f 0 + n := by rw [β f.map_add_int, zero_add]
@[simp]
theorem map_fract_sub_fract_eq (x : β) : f (fract x) - fract x = f x - x := by
rw [Int.fract, f.map_sub_int, sub_sub_sub_cancel_right]
/-!
### Pointwise order on circle maps
-/
/-- Monotone circle maps form a lattice with respect to the pointwise order -/
noncomputable instance : Lattice CircleDeg1Lift where
| sup f g :=
{ toFun := fun x => max (f x) (g x)
| Mathlib/Dynamics/Circle/RotationNumber/TranslationNumber.lean | 351 | 352 |
/-
Copyright (c) 2023 JoΓ«l Riou. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: JoΓ«l Riou
-/
import Mathlib.Algebra.Homology.ShortComplex.LeftHomology
import Mathlib.CategoryTheory.Limits.Opposites
/-!
# Right Homology of short complexes
In this file, we define the dual notions to those defined in
`Algebra.Homology.ShortComplex.LeftHomology`. In particular, if `S : ShortComplex C` is
a short complex consisting of two composable maps `f : Xβ βΆ Xβ` and `g : Xβ βΆ Xβ` such
that `f β« g = 0`, we define `h : S.RightHomologyData` to be the datum of morphisms
`p : Xβ βΆ Q` and `ΞΉ : H βΆ Q` such that `Q` identifies to the cokernel of `f` and `H`
to the kernel of the induced map `g' : Q βΆ Xβ`.
When such a `S.RightHomologyData` exists, we shall say that `[S.HasRightHomology]`
and we define `S.rightHomology` to be the `H` field of a chosen right homology data.
Similarly, we define `S.opcycles` to be the `Q` field.
In `Homology.lean`, when `S` has two compatible left and right homology data
(i.e. they give the same `H` up to a canonical isomorphism), we shall define
`[S.HasHomology]` and `S.homology`.
-/
namespace CategoryTheory
open Category Limits
namespace ShortComplex
variable {C : Type*} [Category C] [HasZeroMorphisms C]
(S : ShortComplex C) {Sβ Sβ Sβ : ShortComplex C}
/-- A right homology data for a short complex `S` consists of morphisms `p : S.Xβ βΆ Q` and
`ΞΉ : H βΆ Q` such that `p` identifies `Q` to the kernel of `f : S.Xβ βΆ S.Xβ`,
and that `ΞΉ` identifies `H` to the kernel of the induced map `g' : Q βΆ S.Xβ` -/
structure RightHomologyData where
/-- a choice of cokernel of `S.f : S.Xβ βΆ S.Xβ` -/
Q : C
/-- a choice of kernel of the induced morphism `S.g' : S.Q βΆ Xβ` -/
H : C
/-- the projection from `S.Xβ` -/
p : S.Xβ βΆ Q
/-- the inclusion of the (right) homology in the chosen cokernel of `S.f` -/
ΞΉ : H βΆ Q
/-- the cokernel condition for `p` -/
wp : S.f β« p = 0
/-- `p : S.Xβ βΆ Q` is a cokernel of `S.f : S.Xβ βΆ S.Xβ` -/
hp : IsColimit (CokernelCofork.ofΟ p wp)
/-- the kernel condition for `ΞΉ` -/
wΞΉ : ΞΉ β« hp.desc (CokernelCofork.ofΟ _ S.zero) = 0
/-- `ΞΉ : H βΆ Q` is a kernel of `S.g' : Q βΆ S.Xβ` -/
hΞΉ : IsLimit (KernelFork.ofΞΉ ΞΉ wΞΉ)
initialize_simps_projections RightHomologyData (-hp, -hΞΉ)
namespace RightHomologyData
/-- The chosen cokernels and kernels of the limits API give a `RightHomologyData` -/
@[simps]
noncomputable def ofHasCokernelOfHasKernel
[HasCokernel S.f] [HasKernel (cokernel.desc S.f S.g S.zero)] :
S.RightHomologyData :=
{ Q := cokernel S.f,
H := kernel (cokernel.desc S.f S.g S.zero),
p := cokernel.Ο _,
ΞΉ := kernel.ΞΉ _,
wp := cokernel.condition _,
hp := cokernelIsCokernel _,
wΞΉ := kernel.condition _,
hΞΉ := kernelIsKernel _, }
attribute [reassoc (attr := simp)] wp wΞΉ
variable {S}
variable (h : S.RightHomologyData) {A : C}
instance : Epi h.p := β¨fun _ _ => Cofork.IsColimit.hom_ext h.hpβ©
instance : Mono h.ΞΉ := β¨fun _ _ => Fork.IsLimit.hom_ext h.hΞΉβ©
/-- Any morphism `k : S.Xβ βΆ A` such that `S.f β« k = 0` descends
to a morphism `Q βΆ A` -/
def descQ (k : S.Xβ βΆ A) (hk : S.f β« k = 0) : h.Q βΆ A :=
h.hp.desc (CokernelCofork.ofΟ k hk)
@[reassoc (attr := simp)]
lemma p_descQ (k : S.Xβ βΆ A) (hk : S.f β« k = 0) : h.p β« h.descQ k hk = k :=
h.hp.fac _ WalkingParallelPair.one
/-- The morphism from the (right) homology attached to a morphism
`k : S.Xβ βΆ A` such that `S.f β« k = 0`. -/
@[simp]
def descH (k : S.Xβ βΆ A) (hk : S.f β« k = 0) : h.H βΆ A :=
h.ΞΉ β« h.descQ k hk
/-- The morphism `h.Q βΆ S.Xβ` induced by `S.g : S.Xβ βΆ S.Xβ` and the fact that
`h.Q` is a cokernel of `S.f : S.Xβ βΆ S.Xβ`. -/
def g' : h.Q βΆ S.Xβ := h.descQ S.g S.zero
@[reassoc (attr := simp)] lemma p_g' : h.p β« h.g' = S.g := p_descQ _ _ _
@[reassoc (attr := simp)] lemma ΞΉ_g' : h.ΞΉ β« h.g' = 0 := h.wΞΉ
@[reassoc]
lemma ΞΉ_descQ_eq_zero_of_boundary (k : S.Xβ βΆ A) (x : S.Xβ βΆ A) (hx : k = S.g β« x) :
h.ΞΉ β« h.descQ k (by rw [hx, S.zero_assoc, zero_comp]) = 0 := by
rw [show 0 = h.ΞΉ β« h.g' β« x by simp]
congr 1
simp only [β cancel_epi h.p, hx, p_descQ, p_g'_assoc]
/-- For `h : S.RightHomologyData`, this is a restatement of `h.hΞΉ`, saying that
`ΞΉ : h.H βΆ h.Q` is a kernel of `h.g' : h.Q βΆ S.Xβ`. -/
def hΞΉ' : IsLimit (KernelFork.ofΞΉ h.ΞΉ h.ΞΉ_g') := h.hΞΉ
/-- The morphism `A βΆ H` induced by a morphism `k : A βΆ Q` such that `k β« g' = 0` -/
def liftH (k : A βΆ h.Q) (hk : k β« h.g' = 0) : A βΆ h.H :=
h.hΞΉ.lift (KernelFork.ofΞΉ k hk)
@[reassoc (attr := simp)]
lemma liftH_ΞΉ (k : A βΆ h.Q) (hk : k β« h.g' = 0) : h.liftH k hk β« h.ΞΉ = k :=
h.hΞΉ.fac (KernelFork.ofΞΉ k hk) WalkingParallelPair.zero
lemma isIso_p (hf : S.f = 0) : IsIso h.p :=
β¨h.descQ (π S.Xβ) (by rw [hf, comp_id]), p_descQ _ _ _, by
simp only [β cancel_epi h.p, p_descQ_assoc, id_comp, comp_id]β©
lemma isIso_ΞΉ (hg : S.g = 0) : IsIso h.ΞΉ := by
have β¨Ο, hΟβ© := KernelFork.IsLimit.lift' h.hΞΉ' (π _)
(by rw [β cancel_epi h.p, id_comp, p_g', comp_zero, hg])
dsimp at hΟ
exact β¨Ο, by rw [β cancel_mono h.ΞΉ, assoc, hΟ, comp_id, id_comp], hΟβ©
variable (S)
/-- When the first map `S.f` is zero, this is the right homology data on `S` given
by any limit kernel fork of `S.g` -/
@[simps]
def ofIsLimitKernelFork (hf : S.f = 0) (c : KernelFork S.g) (hc : IsLimit c) :
S.RightHomologyData where
Q := S.Xβ
H := c.pt
p := π _
ΞΉ := c.ΞΉ
wp := by rw [comp_id, hf]
hp := CokernelCofork.IsColimit.ofId _ hf
wΞΉ := KernelFork.condition _
hΞΉ := IsLimit.ofIsoLimit hc (Fork.ext (Iso.refl _) (by simp))
@[simp] lemma ofIsLimitKernelFork_g' (hf : S.f = 0) (c : KernelFork S.g)
(hc : IsLimit c) : (ofIsLimitKernelFork S hf c hc).g' = S.g := by
rw [β cancel_epi (ofIsLimitKernelFork S hf c hc).p, p_g',
ofIsLimitKernelFork_p, id_comp]
/-- When the first map `S.f` is zero, this is the right homology data on `S` given by
the chosen `kernel S.g` -/
@[simps!]
noncomputable def ofHasKernel [HasKernel S.g] (hf : S.f = 0) : S.RightHomologyData :=
ofIsLimitKernelFork S hf _ (kernelIsKernel _)
/-- When the second map `S.g` is zero, this is the right homology data on `S` given
by any colimit cokernel cofork of `S.g` -/
@[simps]
def ofIsColimitCokernelCofork (hg : S.g = 0) (c : CokernelCofork S.f) (hc : IsColimit c) :
S.RightHomologyData where
Q := c.pt
H := c.pt
p := c.Ο
ΞΉ := π _
wp := CokernelCofork.condition _
hp := IsColimit.ofIsoColimit hc (Cofork.ext (Iso.refl _) (by simp))
wΞΉ := Cofork.IsColimit.hom_ext hc (by simp [hg])
hΞΉ := KernelFork.IsLimit.ofId _ (Cofork.IsColimit.hom_ext hc (by simp [hg]))
@[simp] lemma ofIsColimitCokernelCofork_g' (hg : S.g = 0) (c : CokernelCofork S.f)
(hc : IsColimit c) : (ofIsColimitCokernelCofork S hg c hc).g' = 0 := by
rw [β cancel_epi (ofIsColimitCokernelCofork S hg c hc).p, p_g', hg, comp_zero]
/-- When the second map `S.g` is zero, this is the right homology data on `S` given
by the chosen `cokernel S.f` -/
@[simp]
noncomputable def ofHasCokernel [HasCokernel S.f] (hg : S.g = 0) : S.RightHomologyData :=
ofIsColimitCokernelCofork S hg _ (cokernelIsCokernel _)
/-- When both `S.f` and `S.g` are zero, the middle object `S.Xβ`
gives a right homology data on S -/
@[simps]
def ofZeros (hf : S.f = 0) (hg : S.g = 0) : S.RightHomologyData where
Q := S.Xβ
H := S.Xβ
p := π _
ΞΉ := π _
wp := by rw [comp_id, hf]
hp := CokernelCofork.IsColimit.ofId _ hf
wΞΉ := by
change π _ β« S.g = 0
simp only [hg, comp_zero]
hΞΉ := KernelFork.IsLimit.ofId _ hg
@[simp]
lemma ofZeros_g' (hf : S.f = 0) (hg : S.g = 0) :
(ofZeros S hf hg).g' = 0 := by
rw [β cancel_epi ((ofZeros S hf hg).p), comp_zero, p_g', hg]
end RightHomologyData
/-- A short complex `S` has right homology when there exists a `S.RightHomologyData` -/
class HasRightHomology : Prop where
condition : Nonempty S.RightHomologyData
/-- A chosen `S.RightHomologyData` for a short complex `S` that has right homology -/
noncomputable def rightHomologyData [HasRightHomology S] :
S.RightHomologyData := HasRightHomology.condition.some
variable {S}
namespace HasRightHomology
lemma mk' (h : S.RightHomologyData) : HasRightHomology S := β¨Nonempty.intro hβ©
instance of_hasCokernel_of_hasKernel
[HasCokernel S.f] [HasKernel (cokernel.desc S.f S.g S.zero)] :
S.HasRightHomology := HasRightHomology.mk' (RightHomologyData.ofHasCokernelOfHasKernel S)
instance of_hasKernel {Y Z : C} (g : Y βΆ Z) (X : C) [HasKernel g] :
(ShortComplex.mk (0 : X βΆ Y) g zero_comp).HasRightHomology :=
HasRightHomology.mk' (RightHomologyData.ofHasKernel _ rfl)
instance of_hasCokernel {X Y : C} (f : X βΆ Y) (Z : C) [HasCokernel f] :
(ShortComplex.mk f (0 : Y βΆ Z) comp_zero).HasRightHomology :=
HasRightHomology.mk' (RightHomologyData.ofHasCokernel _ rfl)
instance of_zeros (X Y Z : C) :
(ShortComplex.mk (0 : X βΆ Y) (0 : Y βΆ Z) zero_comp).HasRightHomology :=
HasRightHomology.mk' (RightHomologyData.ofZeros _ rfl rfl)
end HasRightHomology
namespace RightHomologyData
/-- A right homology data for a short complex `S` induces a left homology data for `S.op`. -/
@[simps]
def op (h : S.RightHomologyData) : S.op.LeftHomologyData where
K := Opposite.op h.Q
H := Opposite.op h.H
i := h.p.op
Ο := h.ΞΉ.op
wi := Quiver.Hom.unop_inj h.wp
hi := CokernelCofork.IsColimit.ofΟOp _ _ h.hp
wΟ := Quiver.Hom.unop_inj h.wΞΉ
hΟ := KernelFork.IsLimit.ofΞΉOp _ _ h.hΞΉ
@[simp] lemma op_f' (h : S.RightHomologyData) :
h.op.f' = h.g'.op := rfl
/-- A right homology data for a short complex `S` in the opposite category
induces a left homology data for `S.unop`. -/
@[simps]
def unop {S : ShortComplex Cα΅α΅} (h : S.RightHomologyData) : S.unop.LeftHomologyData where
K := Opposite.unop h.Q
H := Opposite.unop h.H
i := h.p.unop
Ο := h.ΞΉ.unop
wi := Quiver.Hom.op_inj h.wp
hi := CokernelCofork.IsColimit.ofΟUnop _ _ h.hp
wΟ := Quiver.Hom.op_inj h.wΞΉ
hΟ := KernelFork.IsLimit.ofΞΉUnop _ _ h.hΞΉ
@[simp] lemma unop_f' {S : ShortComplex Cα΅α΅} (h : S.RightHomologyData) :
h.unop.f' = h.g'.unop := rfl
end RightHomologyData
namespace LeftHomologyData
/-- A left homology data for a short complex `S` induces a right homology data for `S.op`. -/
@[simps]
def op (h : S.LeftHomologyData) : S.op.RightHomologyData where
Q := Opposite.op h.K
H := Opposite.op h.H
p := h.i.op
ΞΉ := h.Ο.op
wp := Quiver.Hom.unop_inj h.wi
hp := KernelFork.IsLimit.ofΞΉOp _ _ h.hi
wΞΉ := Quiver.Hom.unop_inj h.wΟ
hΞΉ := CokernelCofork.IsColimit.ofΟOp _ _ h.hΟ
@[simp] lemma op_g' (h : S.LeftHomologyData) :
h.op.g' = h.f'.op := rfl
/-- A left homology data for a short complex `S` in the opposite category
induces a right homology data for `S.unop`. -/
@[simps]
def unop {S : ShortComplex Cα΅α΅} (h : S.LeftHomologyData) : S.unop.RightHomologyData where
Q := Opposite.unop h.K
H := Opposite.unop h.H
p := h.i.unop
ΞΉ := h.Ο.unop
wp := Quiver.Hom.op_inj h.wi
hp := KernelFork.IsLimit.ofΞΉUnop _ _ h.hi
wΞΉ := Quiver.Hom.op_inj h.wΟ
hΞΉ := CokernelCofork.IsColimit.ofΟUnop _ _ h.hΟ
@[simp] lemma unop_g' {S : ShortComplex Cα΅α΅} (h : S.LeftHomologyData) :
h.unop.g' = h.f'.unop := rfl
end LeftHomologyData
instance [S.HasLeftHomology] : HasRightHomology S.op :=
HasRightHomology.mk' S.leftHomologyData.op
instance [S.HasRightHomology] : HasLeftHomology S.op :=
HasLeftHomology.mk' S.rightHomologyData.op
lemma hasLeftHomology_iff_op (S : ShortComplex C) :
S.HasLeftHomology β S.op.HasRightHomology :=
β¨fun _ => inferInstance, fun _ => HasLeftHomology.mk' S.op.rightHomologyData.unopβ©
lemma hasRightHomology_iff_op (S : ShortComplex C) :
S.HasRightHomology β S.op.HasLeftHomology :=
β¨fun _ => inferInstance, fun _ => HasRightHomology.mk' S.op.leftHomologyData.unopβ©
lemma hasLeftHomology_iff_unop (S : ShortComplex Cα΅α΅) :
S.HasLeftHomology β S.unop.HasRightHomology :=
S.unop.hasRightHomology_iff_op.symm
lemma hasRightHomology_iff_unop (S : ShortComplex Cα΅α΅) :
S.HasRightHomology β S.unop.HasLeftHomology :=
S.unop.hasLeftHomology_iff_op.symm
section
variable (Ο : Sβ βΆ Sβ) (hβ : Sβ.RightHomologyData) (hβ : Sβ.RightHomologyData)
/-- Given right homology data `hβ` and `hβ` for two short complexes `Sβ` and `Sβ`,
a `RightHomologyMapData` for a morphism `Ο : Sβ βΆ Sβ`
consists of a description of the induced morphisms on the `Q` (opcycles)
and `H` (right homology) fields of `hβ` and `hβ`. -/
structure RightHomologyMapData where
/-- the induced map on opcycles -/
ΟQ : hβ.Q βΆ hβ.Q
/-- the induced map on right homology -/
ΟH : hβ.H βΆ hβ.H
/-- commutation with `p` -/
commp : hβ.p β« ΟQ = Ο.Οβ β« hβ.p := by aesop_cat
/-- commutation with `g'` -/
commg' : ΟQ β« hβ.g' = hβ.g' β« Ο.Οβ := by aesop_cat
/-- commutation with `ΞΉ` -/
commΞΉ : ΟH β« hβ.ΞΉ = hβ.ΞΉ β« ΟQ := by aesop_cat
namespace RightHomologyMapData
attribute [reassoc (attr := simp)] commp commg' commΞΉ
/-- The right homology map data associated to the zero morphism between two short complexes. -/
@[simps]
def zero (hβ : Sβ.RightHomologyData) (hβ : Sβ.RightHomologyData) :
RightHomologyMapData 0 hβ hβ where
ΟQ := 0
ΟH := 0
/-- The right homology map data associated to the identity morphism of a short complex. -/
@[simps]
def id (h : S.RightHomologyData) : RightHomologyMapData (π S) h h where
ΟQ := π _
ΟH := π _
/-- The composition of right homology map data. -/
@[simps]
def comp {Ο : Sβ βΆ Sβ} {Ο' : Sβ βΆ Sβ} {hβ : Sβ.RightHomologyData}
{hβ : Sβ.RightHomologyData} {hβ : Sβ.RightHomologyData}
(Ο : RightHomologyMapData Ο hβ hβ) (Ο' : RightHomologyMapData Ο' hβ hβ) :
RightHomologyMapData (Ο β« Ο') hβ hβ where
ΟQ := Ο.ΟQ β« Ο'.ΟQ
ΟH := Ο.ΟH β« Ο'.ΟH
instance : Subsingleton (RightHomologyMapData Ο hβ hβ) :=
β¨fun Οβ Οβ => by
have hQ : Οβ.ΟQ = Οβ.ΟQ := by rw [β cancel_epi hβ.p, commp, commp]
have hH : Οβ.ΟH = Οβ.ΟH := by rw [β cancel_mono hβ.ΞΉ, commΞΉ, commΞΉ, hQ]
cases Οβ
cases Οβ
congrβ©
instance : Inhabited (RightHomologyMapData Ο hβ hβ) := β¨by
let ΟQ : hβ.Q βΆ hβ.Q := hβ.descQ (Ο.Οβ β« hβ.p) (by rw [β Ο.commββ_assoc, hβ.wp, comp_zero])
have commg' : ΟQ β« hβ.g' = hβ.g' β« Ο.Οβ := by
rw [β cancel_epi hβ.p, RightHomologyData.p_descQ_assoc, assoc,
RightHomologyData.p_g', Ο.commββ, RightHomologyData.p_g'_assoc]
let ΟH : hβ.H βΆ hβ.H := hβ.liftH (hβ.ΞΉ β« ΟQ)
(by rw [assoc, commg', RightHomologyData.ΞΉ_g'_assoc, zero_comp])
exact β¨ΟQ, ΟH, by simp [ΟQ], commg', by simp [ΟH]β©β©
instance : Unique (RightHomologyMapData Ο hβ hβ) := Unique.mk' _
variable {Ο hβ hβ}
lemma congr_ΟH {Ξ³β Ξ³β : RightHomologyMapData Ο hβ hβ} (eq : Ξ³β = Ξ³β) : Ξ³β.ΟH = Ξ³β.ΟH := by rw [eq]
lemma congr_ΟQ {Ξ³β Ξ³β : RightHomologyMapData Ο hβ hβ} (eq : Ξ³β = Ξ³β) : Ξ³β.ΟQ = Ξ³β.ΟQ := by rw [eq]
/-- When `Sβ.f`, `Sβ.g`, `Sβ.f` and `Sβ.g` are all zero, the action on right homology of a
morphism `Ο : Sβ βΆ Sβ` is given by the action `Ο.Οβ` on the middle objects. -/
@[simps]
def ofZeros (Ο : Sβ βΆ Sβ) (hfβ : Sβ.f = 0) (hgβ : Sβ.g = 0) (hfβ : Sβ.f = 0) (hgβ : Sβ.g = 0) :
RightHomologyMapData Ο (RightHomologyData.ofZeros Sβ hfβ hgβ)
(RightHomologyData.ofZeros Sβ hfβ hgβ) where
ΟQ := Ο.Οβ
ΟH := Ο.Οβ
/-- When `Sβ.f` and `Sβ.f` are zero and we have chosen limit kernel forks `cβ` and `cβ`
for `Sβ.g` and `Sβ.g` respectively, the action on right homology of a morphism `Ο : Sβ βΆ Sβ` of
short complexes is given by the unique morphism `f : cβ.pt βΆ cβ.pt` such that
`cβ.ΞΉ β« Ο.Οβ = f β« cβ.ΞΉ`. -/
@[simps]
def ofIsLimitKernelFork (Ο : Sβ βΆ Sβ)
(hfβ : Sβ.f = 0) (cβ : KernelFork Sβ.g) (hcβ : IsLimit cβ)
(hfβ : Sβ.f = 0) (cβ : KernelFork Sβ.g) (hcβ : IsLimit cβ) (f : cβ.pt βΆ cβ.pt)
(comm : cβ.ΞΉ β« Ο.Οβ = f β« cβ.ΞΉ) :
RightHomologyMapData Ο (RightHomologyData.ofIsLimitKernelFork Sβ hfβ cβ hcβ)
(RightHomologyData.ofIsLimitKernelFork Sβ hfβ cβ hcβ) where
ΟQ := Ο.Οβ
ΟH := f
commg' := by simp only [RightHomologyData.ofIsLimitKernelFork_g', Ο.commββ]
commΞΉ := comm.symm
/-- When `Sβ.g` and `Sβ.g` are zero and we have chosen colimit cokernel coforks `cβ` and `cβ`
for `Sβ.f` and `Sβ.f` respectively, the action on right homology of a morphism `Ο : Sβ βΆ Sβ` of
short complexes is given by the unique morphism `f : cβ.pt βΆ cβ.pt` such that
`Ο.Οβ β« cβ.Ο = cβ.Ο β« f`. -/
@[simps]
def ofIsColimitCokernelCofork (Ο : Sβ βΆ Sβ)
(hgβ : Sβ.g = 0) (cβ : CokernelCofork Sβ.f) (hcβ : IsColimit cβ)
(hgβ : Sβ.g = 0) (cβ : CokernelCofork Sβ.f) (hcβ : IsColimit cβ) (f : cβ.pt βΆ cβ.pt)
(comm : Ο.Οβ β« cβ.Ο = cβ.Ο β« f) :
RightHomologyMapData Ο (RightHomologyData.ofIsColimitCokernelCofork Sβ hgβ cβ hcβ)
(RightHomologyData.ofIsColimitCokernelCofork Sβ hgβ cβ hcβ) where
ΟQ := f
ΟH := f
commp := comm.symm
variable (S)
/-- When both maps `S.f` and `S.g` of a short complex `S` are zero, this is the right homology map
data (for the identity of `S`) which relates the right homology data
`RightHomologyData.ofIsLimitKernelFork` and `ofZeros` . -/
@[simps]
def compatibilityOfZerosOfIsLimitKernelFork (hf : S.f = 0) (hg : S.g = 0)
(c : KernelFork S.g) (hc : IsLimit c) :
RightHomologyMapData (π S)
(RightHomologyData.ofIsLimitKernelFork S hf c hc)
(RightHomologyData.ofZeros S hf hg) where
ΟQ := π _
ΟH := c.ΞΉ
/-- When both maps `S.f` and `S.g` of a short complex `S` are zero, this is the right homology map
data (for the identity of `S`) which relates the right homology data `ofZeros` and
`ofIsColimitCokernelCofork`. -/
@[simps]
def compatibilityOfZerosOfIsColimitCokernelCofork (hf : S.f = 0) (hg : S.g = 0)
(c : CokernelCofork S.f) (hc : IsColimit c) :
RightHomologyMapData (π S)
(RightHomologyData.ofZeros S hf hg)
(RightHomologyData.ofIsColimitCokernelCofork S hg c hc) where
ΟQ := c.Ο
ΟH := c.Ο
end RightHomologyMapData
end
section
variable (S)
variable [S.HasRightHomology]
/-- The right homology of a short complex,
given by the `H` field of a chosen right homology data. -/
noncomputable def rightHomology : C := S.rightHomologyData.H
-- `S.rightHomology` is the simp normal form.
@[simp] lemma rightHomologyData_H : S.rightHomologyData.H = S.rightHomology := rfl
/-- The "opcycles" of a short complex, given by the `Q` field of a chosen right homology data.
This is the dual notion to cycles. -/
noncomputable def opcycles : C := S.rightHomologyData.Q
/-- The canonical map `S.rightHomology βΆ S.opcycles`. -/
noncomputable def rightHomologyΞΉ : S.rightHomology βΆ S.opcycles :=
S.rightHomologyData.ΞΉ
/-- The projection `S.Xβ βΆ S.opcycles`. -/
noncomputable def pOpcycles : S.Xβ βΆ S.opcycles := S.rightHomologyData.p
/-- The canonical map `S.opcycles βΆ Xβ`. -/
noncomputable def fromOpcycles : S.opcycles βΆ S.Xβ := S.rightHomologyData.g'
@[reassoc (attr := simp)]
lemma f_pOpcycles : S.f β« S.pOpcycles = 0 := S.rightHomologyData.wp
@[reassoc (attr := simp)]
lemma p_fromOpcycles : S.pOpcycles β« S.fromOpcycles = S.g := S.rightHomologyData.p_g'
instance : Epi S.pOpcycles := by
dsimp only [pOpcycles]
infer_instance
instance : Mono S.rightHomologyΞΉ := by
dsimp only [rightHomologyΞΉ]
infer_instance
lemma rightHomology_ext_iff {A : C} (fβ fβ : A βΆ S.rightHomology) :
fβ = fβ β fβ β« S.rightHomologyΞΉ = fβ β« S.rightHomologyΞΉ := by
rw [cancel_mono]
@[ext]
lemma rightHomology_ext {A : C} (fβ fβ : A βΆ S.rightHomology)
(h : fβ β« S.rightHomologyΞΉ = fβ β« S.rightHomologyΞΉ) : fβ = fβ := by
simpa only [rightHomology_ext_iff]
lemma opcycles_ext_iff {A : C} (fβ fβ : S.opcycles βΆ A) :
fβ = fβ β S.pOpcycles β« fβ = S.pOpcycles β« fβ := by
rw [cancel_epi]
@[ext]
lemma opcycles_ext {A : C} (fβ fβ : S.opcycles βΆ A)
(h : S.pOpcycles β« fβ = S.pOpcycles β« fβ) : fβ = fβ := by
simpa only [opcycles_ext_iff]
lemma isIso_pOpcycles (hf : S.f = 0) : IsIso S.pOpcycles :=
RightHomologyData.isIso_p _ hf
/-- When `S.f = 0`, this is the canonical isomorphism `S.opcycles β
S.Xβ`
induced by `S.pOpcycles`. -/
@[simps! inv]
noncomputable def opcyclesIsoXβ (hf : S.f = 0) : S.opcycles β
S.Xβ := by
have := S.isIso_pOpcycles hf
exact (asIso S.pOpcycles).symm
@[reassoc (attr := simp)]
lemma opcyclesIsoXβ_inv_hom_id (hf : S.f = 0) :
S.pOpcycles β« (S.opcyclesIsoXβ hf).hom = π _ := (S.opcyclesIsoXβ hf).inv_hom_id
@[reassoc (attr := simp)]
lemma opcyclesIsoXβ_hom_inv_id (hf : S.f = 0) :
(S.opcyclesIsoXβ hf).hom β« S.pOpcycles = π _ := (S.opcyclesIsoXβ hf).hom_inv_id
lemma isIso_rightHomologyΞΉ (hg : S.g = 0) : IsIso S.rightHomologyΞΉ :=
RightHomologyData.isIso_ΞΉ _ hg
/-- When `S.g = 0`, this is the canonical isomorphism `S.opcycles β
S.rightHomology` induced
by `S.rightHomologyΞΉ`. -/
@[simps! inv]
noncomputable def opcyclesIsoRightHomology (hg : S.g = 0) : S.opcycles β
S.rightHomology := by
have := S.isIso_rightHomologyΞΉ hg
exact (asIso S.rightHomologyΞΉ).symm
@[reassoc (attr := simp)]
lemma opcyclesIsoRightHomology_inv_hom_id (hg : S.g = 0) :
S.rightHomologyΞΉ β« (S.opcyclesIsoRightHomology hg).hom = π _ :=
(S.opcyclesIsoRightHomology hg).inv_hom_id
@[reassoc (attr := simp)]
lemma opcyclesIsoRightHomology_hom_inv_id (hg : S.g = 0) :
(S.opcyclesIsoRightHomology hg).hom β« S.rightHomologyΞΉ = π _ :=
(S.opcyclesIsoRightHomology hg).hom_inv_id
end
section
variable (Ο : Sβ βΆ Sβ) (hβ : Sβ.RightHomologyData) (hβ : Sβ.RightHomologyData)
/-- The (unique) right homology map data associated to a morphism of short complexes that
are both equipped with right homology data. -/
def rightHomologyMapData : RightHomologyMapData Ο hβ hβ := default
/-- Given a morphism `Ο : Sβ βΆ Sβ` of short complexes and right homology data `hβ` and `hβ`
for `Sβ` and `Sβ` respectively, this is the induced right homology map `hβ.H βΆ hβ.H`. -/
def rightHomologyMap' : hβ.H βΆ hβ.H := (rightHomologyMapData Ο _ _).ΟH
/-- Given a morphism `Ο : Sβ βΆ Sβ` of short complexes and right homology data `hβ` and `hβ`
for `Sβ` and `Sβ` respectively, this is the induced morphism `hβ.K βΆ hβ.K` on opcycles. -/
def opcyclesMap' : hβ.Q βΆ hβ.Q := (rightHomologyMapData Ο _ _).ΟQ
@[reassoc (attr := simp)]
lemma p_opcyclesMap' : hβ.p β« opcyclesMap' Ο hβ hβ = Ο.Οβ β« hβ.p :=
RightHomologyMapData.commp _
@[reassoc (attr := simp)]
lemma opcyclesMap'_g' : opcyclesMap' Ο hβ hβ β« hβ.g' = hβ.g' β« Ο.Οβ := by
simp only [β cancel_epi hβ.p, assoc, Ο.commββ, p_opcyclesMap'_assoc,
RightHomologyData.p_g'_assoc, RightHomologyData.p_g']
@[reassoc (attr := simp)]
lemma rightHomologyΞΉ_naturality' :
rightHomologyMap' Ο hβ hβ β« hβ.ΞΉ = hβ.ΞΉ β« opcyclesMap' Ο hβ hβ :=
RightHomologyMapData.commΞΉ _
end
section
variable [HasRightHomology Sβ] [HasRightHomology Sβ] (Ο : Sβ βΆ Sβ)
/-- The (right) homology map `Sβ.rightHomology βΆ Sβ.rightHomology` induced by a morphism
`Sβ βΆ Sβ` of short complexes. -/
noncomputable def rightHomologyMap : Sβ.rightHomology βΆ Sβ.rightHomology :=
rightHomologyMap' Ο _ _
/-- The morphism `Sβ.opcycles βΆ Sβ.opcycles` induced by a morphism `Sβ βΆ Sβ` of short complexes. -/
noncomputable def opcyclesMap : Sβ.opcycles βΆ Sβ.opcycles :=
opcyclesMap' Ο _ _
@[reassoc (attr := simp)]
lemma p_opcyclesMap : Sβ.pOpcycles β« opcyclesMap Ο = Ο.Οβ β« Sβ.pOpcycles :=
p_opcyclesMap' _ _ _
@[reassoc (attr := simp)]
lemma fromOpcycles_naturality : opcyclesMap Ο β« Sβ.fromOpcycles = Sβ.fromOpcycles β« Ο.Οβ :=
opcyclesMap'_g' _ _ _
@[reassoc (attr := simp)]
lemma rightHomologyΞΉ_naturality :
rightHomologyMap Ο β« Sβ.rightHomologyΞΉ = Sβ.rightHomologyΞΉ β« opcyclesMap Ο :=
rightHomologyΞΉ_naturality' _ _ _
end
namespace RightHomologyMapData
variable {Ο : Sβ βΆ Sβ} {hβ : Sβ.RightHomologyData} {hβ : Sβ.RightHomologyData}
(Ξ³ : RightHomologyMapData Ο hβ hβ)
lemma rightHomologyMap'_eq : rightHomologyMap' Ο hβ hβ = Ξ³.ΟH :=
RightHomologyMapData.congr_ΟH (Subsingleton.elim _ _)
lemma opcyclesMap'_eq : opcyclesMap' Ο hβ hβ = Ξ³.ΟQ :=
RightHomologyMapData.congr_ΟQ (Subsingleton.elim _ _)
end RightHomologyMapData
@[simp]
lemma rightHomologyMap'_id (h : S.RightHomologyData) :
rightHomologyMap' (π S) h h = π _ :=
(RightHomologyMapData.id h).rightHomologyMap'_eq
@[simp]
lemma opcyclesMap'_id (h : S.RightHomologyData) :
opcyclesMap' (π S) h h = π _ :=
(RightHomologyMapData.id h).opcyclesMap'_eq
variable (S)
@[simp]
lemma rightHomologyMap_id [HasRightHomology S] :
rightHomologyMap (π S) = π _ :=
rightHomologyMap'_id _
@[simp]
lemma opcyclesMap_id [HasRightHomology S] :
opcyclesMap (π S) = π _ :=
opcyclesMap'_id _
@[simp]
lemma rightHomologyMap'_zero (hβ : Sβ.RightHomologyData) (hβ : Sβ.RightHomologyData) :
rightHomologyMap' 0 hβ hβ = 0 :=
(RightHomologyMapData.zero hβ hβ).rightHomologyMap'_eq
@[simp]
lemma opcyclesMap'_zero (hβ : Sβ.RightHomologyData) (hβ : Sβ.RightHomologyData) :
opcyclesMap' 0 hβ hβ = 0 :=
(RightHomologyMapData.zero hβ hβ).opcyclesMap'_eq
variable (Sβ Sβ)
@[simp]
lemma rightHomologyMap_zero [HasRightHomology Sβ] [HasRightHomology Sβ] :
rightHomologyMap (0 : Sβ βΆ Sβ) = 0 :=
rightHomologyMap'_zero _ _
@[simp]
lemma opcyclesMap_zero [HasRightHomology Sβ] [HasRightHomology Sβ] :
opcyclesMap (0 : Sβ βΆ Sβ) = 0 :=
opcyclesMap'_zero _ _
variable {Sβ Sβ}
@[reassoc]
lemma rightHomologyMap'_comp (Οβ : Sβ βΆ Sβ) (Οβ : Sβ βΆ Sβ)
(hβ : Sβ.RightHomologyData) (hβ : Sβ.RightHomologyData) (hβ : Sβ.RightHomologyData) :
rightHomologyMap' (Οβ β« Οβ) hβ hβ = rightHomologyMap' Οβ hβ hβ β«
rightHomologyMap' Οβ hβ hβ := by
let Ξ³β := rightHomologyMapData Οβ hβ hβ
let Ξ³β := rightHomologyMapData Οβ hβ hβ
rw [Ξ³β.rightHomologyMap'_eq, Ξ³β.rightHomologyMap'_eq, (Ξ³β.comp Ξ³β).rightHomologyMap'_eq,
RightHomologyMapData.comp_ΟH]
@[reassoc]
lemma opcyclesMap'_comp (Οβ : Sβ βΆ Sβ) (Οβ : Sβ βΆ Sβ)
(hβ : Sβ.RightHomologyData) (hβ : Sβ.RightHomologyData) (hβ : Sβ.RightHomologyData) :
opcyclesMap' (Οβ β« Οβ) hβ hβ = opcyclesMap' Οβ hβ hβ β« opcyclesMap' Οβ hβ hβ := by
let Ξ³β := rightHomologyMapData Οβ hβ hβ
let Ξ³β := rightHomologyMapData Οβ hβ hβ
rw [Ξ³β.opcyclesMap'_eq, Ξ³β.opcyclesMap'_eq, (Ξ³β.comp Ξ³β).opcyclesMap'_eq,
RightHomologyMapData.comp_ΟQ]
@[simp]
lemma rightHomologyMap_comp [HasRightHomology Sβ] [HasRightHomology Sβ] [HasRightHomology Sβ]
(Οβ : Sβ βΆ Sβ) (Οβ : Sβ βΆ Sβ) :
rightHomologyMap (Οβ β« Οβ) = rightHomologyMap Οβ β« rightHomologyMap Οβ :=
rightHomologyMap'_comp _ _ _ _ _
@[simp]
lemma opcyclesMap_comp [HasRightHomology Sβ] [HasRightHomology Sβ] [HasRightHomology Sβ]
(Οβ : Sβ βΆ Sβ) (Οβ : Sβ βΆ Sβ) :
opcyclesMap (Οβ β« Οβ) = opcyclesMap Οβ β« opcyclesMap Οβ :=
opcyclesMap'_comp _ _ _ _ _
attribute [simp] rightHomologyMap_comp opcyclesMap_comp
/-- An isomorphism of short complexes `Sβ β
Sβ` induces an isomorphism on the `H` fields
of right homology data of `Sβ` and `Sβ`. -/
@[simps]
def rightHomologyMapIso' (e : Sβ β
Sβ) (hβ : Sβ.RightHomologyData)
(hβ : Sβ.RightHomologyData) : hβ.H β
hβ.H where
hom := rightHomologyMap' e.hom hβ hβ
inv := rightHomologyMap' e.inv hβ hβ
hom_inv_id := by rw [β rightHomologyMap'_comp, e.hom_inv_id, rightHomologyMap'_id]
inv_hom_id := by rw [β rightHomologyMap'_comp, e.inv_hom_id, rightHomologyMap'_id]
instance isIso_rightHomologyMap'_of_isIso (Ο : Sβ βΆ Sβ) [IsIso Ο]
(hβ : Sβ.RightHomologyData) (hβ : Sβ.RightHomologyData) :
IsIso (rightHomologyMap' Ο hβ hβ) :=
(inferInstance : IsIso (rightHomologyMapIso' (asIso Ο) hβ hβ).hom)
/-- An isomorphism of short complexes `Sβ β
Sβ` induces an isomorphism on the `Q` fields
of right homology data of `Sβ` and `Sβ`. -/
@[simps]
def opcyclesMapIso' (e : Sβ β
Sβ) (hβ : Sβ.RightHomologyData)
(hβ : Sβ.RightHomologyData) : hβ.Q β
hβ.Q where
hom := opcyclesMap' e.hom hβ hβ
inv := opcyclesMap' e.inv hβ hβ
hom_inv_id := by rw [β opcyclesMap'_comp, e.hom_inv_id, opcyclesMap'_id]
inv_hom_id := by rw [β opcyclesMap'_comp, e.inv_hom_id, opcyclesMap'_id]
instance isIso_opcyclesMap'_of_isIso (Ο : Sβ βΆ Sβ) [IsIso Ο]
(hβ : Sβ.RightHomologyData) (hβ : Sβ.RightHomologyData) :
IsIso (opcyclesMap' Ο hβ hβ) :=
(inferInstance : IsIso (opcyclesMapIso' (asIso Ο) hβ hβ).hom)
/-- The isomorphism `Sβ.rightHomology β
Sβ.rightHomology` induced by an isomorphism of
short complexes `Sβ β
Sβ`. -/
@[simps]
noncomputable def rightHomologyMapIso (e : Sβ β
Sβ) [Sβ.HasRightHomology]
[Sβ.HasRightHomology] : Sβ.rightHomology β
Sβ.rightHomology where
hom := rightHomologyMap e.hom
inv := rightHomologyMap e.inv
hom_inv_id := by rw [β rightHomologyMap_comp, e.hom_inv_id, rightHomologyMap_id]
inv_hom_id := by rw [β rightHomologyMap_comp, e.inv_hom_id, rightHomologyMap_id]
instance isIso_rightHomologyMap_of_iso (Ο : Sβ βΆ Sβ) [IsIso Ο] [Sβ.HasRightHomology]
[Sβ.HasRightHomology] :
IsIso (rightHomologyMap Ο) :=
(inferInstance : IsIso (rightHomologyMapIso (asIso Ο)).hom)
/-- The isomorphism `Sβ.opcycles β
Sβ.opcycles` induced by an isomorphism
of short complexes `Sβ β
Sβ`. -/
@[simps]
noncomputable def opcyclesMapIso (e : Sβ β
Sβ) [Sβ.HasRightHomology]
[Sβ.HasRightHomology] : Sβ.opcycles β
Sβ.opcycles where
hom := opcyclesMap e.hom
inv := opcyclesMap e.inv
hom_inv_id := by rw [β opcyclesMap_comp, e.hom_inv_id, opcyclesMap_id]
inv_hom_id := by rw [β opcyclesMap_comp, e.inv_hom_id, opcyclesMap_id]
instance isIso_opcyclesMap_of_iso (Ο : Sβ βΆ Sβ) [IsIso Ο] [Sβ.HasRightHomology]
[Sβ.HasRightHomology] : IsIso (opcyclesMap Ο) :=
(inferInstance : IsIso (opcyclesMapIso (asIso Ο)).hom)
variable {S}
namespace RightHomologyData
variable (h : S.RightHomologyData) [S.HasRightHomology]
/-- The isomorphism `S.rightHomology β
h.H` induced by a right homology data `h` for a
short complex `S`. -/
noncomputable def rightHomologyIso : S.rightHomology β
h.H :=
rightHomologyMapIso' (Iso.refl _) _ _
/-- The isomorphism `S.opcycles β
h.Q` induced by a right homology data `h` for a
short complex `S`. -/
noncomputable def opcyclesIso : S.opcycles β
h.Q :=
| opcyclesMapIso' (Iso.refl _) _ _
@[reassoc (attr := simp)]
lemma p_comp_opcyclesIso_inv : h.p β« h.opcyclesIso.inv = S.pOpcycles := by
| Mathlib/Algebra/Homology/ShortComplex/RightHomology.lean | 799 | 802 |
/-
Copyright (c) 2021 RΓ©my Degenne. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: RΓ©my Degenne, SΓ©bastien GouΓ«zel
-/
import Mathlib.Analysis.Normed.Module.Basic
import Mathlib.MeasureTheory.Function.SimpleFuncDense
/-!
# Strongly measurable and finitely strongly measurable functions
A function `f` is said to be strongly measurable if `f` is the sequential limit of simple functions.
It is said to be finitely strongly measurable with respect to a measure `ΞΌ` if the supports
of those simple functions have finite measure.
If the target space has a second countable topology, strongly measurable and measurable are
equivalent.
If the measure is sigma-finite, strongly measurable and finitely strongly measurable are equivalent.
The main property of finitely strongly measurable functions is
`FinStronglyMeasurable.exists_set_sigmaFinite`: there exists a measurable set `t` such that the
function is supported on `t` and `ΞΌ.restrict t` is sigma-finite. As a consequence, we can prove some
results for those functions as if the measure was sigma-finite.
We provide a solid API for strongly measurable functions, as a basis for the Bochner integral.
## Main definitions
* `StronglyMeasurable f`: `f : Ξ± β Ξ²` is the limit of a sequence `fs : β β SimpleFunc Ξ± Ξ²`.
* `FinStronglyMeasurable f ΞΌ`: `f : Ξ± β Ξ²` is the limit of a sequence `fs : β β SimpleFunc Ξ± Ξ²`
such that for all `n β β`, the measure of the support of `fs n` is finite.
## References
* [HytΓΆnen, Tuomas, Jan Van Neerven, Mark Veraar, and Lutz Weis. Analysis in Banach spaces.
Springer, 2016.][Hytonen_VanNeerven_Veraar_Wies_2016]
-/
-- Guard against import creep
assert_not_exists InnerProductSpace
open MeasureTheory Filter TopologicalSpace Function Set MeasureTheory.Measure
open ENNReal Topology MeasureTheory NNReal
variable {Ξ± Ξ² Ξ³ ΞΉ : Type*} [Countable ΞΉ]
namespace MeasureTheory
local infixr:25 " ββ " => SimpleFunc
section Definitions
variable [TopologicalSpace Ξ²]
/-- A function is `StronglyMeasurable` if it is the limit of simple functions. -/
def StronglyMeasurable [MeasurableSpace Ξ±] (f : Ξ± β Ξ²) : Prop :=
β fs : β β Ξ± ββ Ξ², β x, Tendsto (fun n => fs n x) atTop (π (f x))
/-- The notation for StronglyMeasurable giving the measurable space instance explicitly. -/
scoped notation "StronglyMeasurable[" m "]" => @MeasureTheory.StronglyMeasurable _ _ _ m
/-- A function is `FinStronglyMeasurable` with respect to a measure if it is the limit of simple
functions with support with finite measure. -/
def FinStronglyMeasurable [Zero Ξ²]
{_ : MeasurableSpace Ξ±} (f : Ξ± β Ξ²) (ΞΌ : Measure Ξ± := by volume_tac) : Prop :=
β fs : β β Ξ± ββ Ξ², (β n, ΞΌ (support (fs n)) < β) β§ β x, Tendsto (fun n => fs n x) atTop (π (f x))
end Definitions
open MeasureTheory
/-! ## Strongly measurable functions -/
section StronglyMeasurable
variable {_ : MeasurableSpace Ξ±} {ΞΌ : Measure Ξ±} {f : Ξ± β Ξ²} {g : β β Ξ±} {m : β}
variable [TopologicalSpace Ξ²]
theorem SimpleFunc.stronglyMeasurable (f : Ξ± ββ Ξ²) : StronglyMeasurable f :=
β¨fun _ => f, fun _ => tendsto_const_nhdsβ©
@[simp, nontriviality]
lemma StronglyMeasurable.of_subsingleton_dom [Subsingleton Ξ±] : StronglyMeasurable f :=
β¨fun _ => SimpleFunc.ofFinite f, fun _ => tendsto_const_nhdsβ©
@[simp, nontriviality]
lemma StronglyMeasurable.of_subsingleton_cod [Subsingleton Ξ²] : StronglyMeasurable f := by
let f_sf : Ξ± ββ Ξ² := β¨f, fun x => ?_, Set.Subsingleton.finite Set.subsingleton_of_subsingletonβ©
Β· exact β¨fun _ => f_sf, fun x => tendsto_const_nhdsβ©
Β· simp [Set.preimage, eq_iff_true_of_subsingleton]
@[deprecated StronglyMeasurable.of_subsingleton_cod (since := "2025-04-09")]
lemma Subsingleton.stronglyMeasurable [Subsingleton Ξ²] (f : Ξ± β Ξ²) : StronglyMeasurable f :=
.of_subsingleton_cod
@[deprecated StronglyMeasurable.of_subsingleton_dom (since := "2025-04-09")]
lemma Subsingleton.stronglyMeasurable' [Subsingleton Ξ±] (f : Ξ± β Ξ²) : StronglyMeasurable f :=
.of_subsingleton_dom
theorem stronglyMeasurable_const {b : Ξ²} : StronglyMeasurable fun _ : Ξ± => b :=
β¨fun _ => SimpleFunc.const Ξ± b, fun _ => tendsto_const_nhdsβ©
@[to_additive]
theorem stronglyMeasurable_one [One Ξ²] : StronglyMeasurable (1 : Ξ± β Ξ²) := stronglyMeasurable_const
/-- A version of `stronglyMeasurable_const` that assumes `f x = f y` for all `x, y`.
This version works for functions between empty types. -/
theorem stronglyMeasurable_const' (hf : β x y, f x = f y) : StronglyMeasurable f := by
nontriviality Ξ±
inhabit Ξ±
convert stronglyMeasurable_const (Ξ² := Ξ²) using 1
exact funext fun x => hf x default
variable [MeasurableSingletonClass Ξ±]
section aux
omit [TopologicalSpace Ξ²]
/-- Auxiliary definition for `StronglyMeasurable.of_discrete`. -/
private noncomputable def simpleFuncAux (f : Ξ± β Ξ²) (g : β β Ξ±) : β β SimpleFunc Ξ± Ξ²
| 0 => .const _ (f (g 0))
| n + 1 => .piecewise {g n} (.singleton _) (.const _ <| f (g n)) (simpleFuncAux f g n)
private lemma simpleFuncAux_eq_of_lt : β n > m, simpleFuncAux f g n (g m) = f (g m)
| _, .refl => by simp [simpleFuncAux]
| _, Nat.le.step (m := n) hmn => by
obtain hnm | hnm := eq_or_ne (g n) (g m) <;>
simp [simpleFuncAux, Set.piecewise_eq_of_not_mem , hnm.symm, simpleFuncAux_eq_of_lt _ hmn]
private lemma simpleFuncAux_eventuallyEq : βαΆ n in atTop, simpleFuncAux f g n (g m) = f (g m) :=
eventually_atTop.2 β¨_, simpleFuncAux_eq_of_ltβ©
end aux
lemma StronglyMeasurable.of_discrete [Countable Ξ±] : StronglyMeasurable f := by
nontriviality Ξ±
nontriviality Ξ²
obtain β¨g, hgβ© := exists_surjective_nat Ξ±
exact β¨simpleFuncAux f g, hg.forall.2 fun m β¦
tendsto_nhds_of_eventually_eq simpleFuncAux_eventuallyEqβ©
@[deprecated StronglyMeasurable.of_discrete (since := "2025-04-09")]
theorem StronglyMeasurable.of_finite [Finite Ξ±] : StronglyMeasurable f := .of_discrete
end StronglyMeasurable
namespace StronglyMeasurable
variable {f g : Ξ± β Ξ²}
section BasicPropertiesInAnyTopologicalSpace
variable [TopologicalSpace Ξ²]
/-- A sequence of simple functions such that
`β x, Tendsto (fun n => hf.approx n x) atTop (π (f x))`.
That property is given by `stronglyMeasurable.tendsto_approx`. -/
protected noncomputable def approx {_ : MeasurableSpace Ξ±} (hf : StronglyMeasurable f) :
β β Ξ± ββ Ξ² :=
hf.choose
protected theorem tendsto_approx {_ : MeasurableSpace Ξ±} (hf : StronglyMeasurable f) :
β x, Tendsto (fun n => hf.approx n x) atTop (π (f x)) :=
hf.choose_spec
/-- Similar to `stronglyMeasurable.approx`, but enforces that the norm of every function in the
sequence is less than `c` everywhere. If `βf xβ β€ c` this sequence of simple functions verifies
`Tendsto (fun n => hf.approxBounded n x) atTop (π (f x))`. -/
noncomputable def approxBounded {_ : MeasurableSpace Ξ±} [Norm Ξ²] [SMul β Ξ²]
(hf : StronglyMeasurable f) (c : β) : β β SimpleFunc Ξ± Ξ² := fun n =>
(hf.approx n).map fun x => min 1 (c / βxβ) β’ x
theorem tendsto_approxBounded_of_norm_le {Ξ²} {f : Ξ± β Ξ²} [NormedAddCommGroup Ξ²] [NormedSpace β Ξ²]
{m : MeasurableSpace Ξ±} (hf : StronglyMeasurable[m] f) {c : β} {x : Ξ±} (hfx : βf xβ β€ c) :
Tendsto (fun n => hf.approxBounded c n x) atTop (π (f x)) := by
have h_tendsto := hf.tendsto_approx x
simp only [StronglyMeasurable.approxBounded, SimpleFunc.coe_map, Function.comp_apply]
by_cases hfx0 : βf xβ = 0
Β· rw [norm_eq_zero] at hfx0
rw [hfx0] at h_tendsto β’
have h_tendsto_norm : Tendsto (fun n => βhf.approx n xβ) atTop (π 0) := by
convert h_tendsto.norm
rw [norm_zero]
refine squeeze_zero_norm (fun n => ?_) h_tendsto_norm
calc
βmin 1 (c / βhf.approx n xβ) β’ hf.approx n xβ =
βmin 1 (c / βhf.approx n xβ)β * βhf.approx n xβ :=
norm_smul _ _
_ β€ β(1 : β)β * βhf.approx n xβ := by
refine mul_le_mul_of_nonneg_right ?_ (norm_nonneg _)
rw [norm_one, Real.norm_of_nonneg]
Β· exact min_le_left _ _
Β· exact le_min zero_le_one (div_nonneg ((norm_nonneg _).trans hfx) (norm_nonneg _))
_ = βhf.approx n xβ := by rw [norm_one, one_mul]
rw [β one_smul β (f x)]
refine Tendsto.smul ?_ h_tendsto
have : min 1 (c / βf xβ) = 1 := by
rw [min_eq_left_iff, one_le_div (lt_of_le_of_ne (norm_nonneg _) (Ne.symm hfx0))]
exact hfx
nth_rw 2 [this.symm]
refine Tendsto.min tendsto_const_nhds ?_
exact Tendsto.div tendsto_const_nhds h_tendsto.norm hfx0
theorem tendsto_approxBounded_ae {Ξ²} {f : Ξ± β Ξ²} [NormedAddCommGroup Ξ²] [NormedSpace β Ξ²]
{m m0 : MeasurableSpace Ξ±} {ΞΌ : Measure Ξ±} (hf : StronglyMeasurable[m] f) {c : β}
(hf_bound : βα΅ x βΞΌ, βf xβ β€ c) :
βα΅ x βΞΌ, Tendsto (fun n => hf.approxBounded c n x) atTop (π (f x)) := by
filter_upwards [hf_bound] with x hfx using tendsto_approxBounded_of_norm_le hf hfx
theorem norm_approxBounded_le {Ξ²} {f : Ξ± β Ξ²} [SeminormedAddCommGroup Ξ²] [NormedSpace β Ξ²]
{m : MeasurableSpace Ξ±} {c : β} (hf : StronglyMeasurable[m] f) (hc : 0 β€ c) (n : β) (x : Ξ±) :
βhf.approxBounded c n xβ β€ c := by
simp only [StronglyMeasurable.approxBounded, SimpleFunc.coe_map, Function.comp_apply]
refine (norm_smul_le _ _).trans ?_
by_cases h0 : βhf.approx n xβ = 0
Β· simp only [h0, _root_.div_zero, min_eq_right, zero_le_one, norm_zero, mul_zero]
exact hc
rcases le_total βhf.approx n xβ c with h | h
Β· rw [min_eq_left _]
Β· simpa only [norm_one, one_mul] using h
Β· rwa [one_le_div (lt_of_le_of_ne (norm_nonneg _) (Ne.symm h0))]
Β· rw [min_eq_right _]
Β· rw [norm_div, norm_norm, mul_comm, mul_div, div_eq_mul_inv, mul_comm, β mul_assoc,
inv_mul_cancelβ h0, one_mul, Real.norm_of_nonneg hc]
Β· rwa [div_le_one (lt_of_le_of_ne (norm_nonneg _) (Ne.symm h0))]
theorem _root_.stronglyMeasurable_bot_iff [Nonempty Ξ²] [T2Space Ξ²] :
StronglyMeasurable[β₯] f β β c, f = fun _ => c := by
rcases isEmpty_or_nonempty Ξ± with hΞ± | hΞ±
Β· simp [eq_iff_true_of_subsingleton]
refine β¨fun hf => ?_, fun hf_eq => ?_β©
Β· refine β¨f hΞ±.some, ?_β©
let fs := hf.approx
have h_fs_tendsto : β x, Tendsto (fun n => fs n x) atTop (π (f x)) := hf.tendsto_approx
have : β n, β c, β x, fs n x = c := fun n => SimpleFunc.simpleFunc_bot (fs n)
let cs n := (this n).choose
have h_cs_eq : β n, β(fs n) = fun _ => cs n := fun n => funext (this n).choose_spec
conv at h_fs_tendsto => enter [x, 1, n]; rw [h_cs_eq]
have h_tendsto : Tendsto cs atTop (π (f hΞ±.some)) := h_fs_tendsto hΞ±.some
ext1 x
exact tendsto_nhds_unique (h_fs_tendsto x) h_tendsto
Β· obtain β¨c, rflβ© := hf_eq
exact stronglyMeasurable_const
end BasicPropertiesInAnyTopologicalSpace
theorem finStronglyMeasurable_of_set_sigmaFinite [TopologicalSpace Ξ²] [Zero Ξ²]
{m : MeasurableSpace Ξ±} {ΞΌ : Measure Ξ±} (hf_meas : StronglyMeasurable f) {t : Set Ξ±}
(ht : MeasurableSet t) (hft_zero : β x β tαΆ, f x = 0) (htΞΌ : SigmaFinite (ΞΌ.restrict t)) :
FinStronglyMeasurable f ΞΌ := by
haveI : SigmaFinite (ΞΌ.restrict t) := htΞΌ
let S := spanningSets (ΞΌ.restrict t)
have hS_meas : β n, MeasurableSet (S n) := measurableSet_spanningSets (ΞΌ.restrict t)
let f_approx := hf_meas.approx
let fs n := SimpleFunc.restrict (f_approx n) (S n β© t)
have h_fs_t_compl : β n, β x, x β t β fs n x = 0 := by
intro n x hxt
rw [SimpleFunc.restrict_apply _ ((hS_meas n).inter ht)]
refine Set.indicator_of_not_mem ?_ _
| simp [hxt]
refine β¨fs, ?_, fun x => ?_β©
Β· simp_rw [SimpleFunc.support_eq, β Finset.mem_coe]
classical
refine fun n => measure_biUnion_lt_top {y β (fs n).range | y β 0}.finite_toSet fun y hy => ?_
rw [SimpleFunc.restrict_preimage_singleton _ ((hS_meas n).inter ht)]
swap
Β· letI : (y : Ξ²) β Decidable (y = 0) := fun y => Classical.propDecidable _
rw [Finset.mem_coe, Finset.mem_filter] at hy
exact hy.2
refine (measure_mono Set.inter_subset_left).trans_lt ?_
have h_lt_top := measure_spanningSets_lt_top (ΞΌ.restrict t) n
rwa [Measure.restrict_apply' ht] at h_lt_top
Β· by_cases hxt : x β t
swap
Β· rw [funext fun n => h_fs_t_compl n x hxt, hft_zero x hxt]
exact tendsto_const_nhds
have h : Tendsto (fun n => (f_approx n) x) atTop (π (f x)) := hf_meas.tendsto_approx x
| Mathlib/MeasureTheory/Function/StronglyMeasurable/Basic.lean | 263 | 280 |
/-
Copyright (c) 2022 Jake Levinson. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jake Levinson
-/
import Mathlib.Data.Finset.Preimage
import Mathlib.Data.Finset.Prod
import Mathlib.Data.SetLike.Basic
import Mathlib.Order.UpperLower.Basic
/-!
# Young diagrams
A Young diagram is a finite set of up-left justified boxes:
```text
β‘β‘β‘β‘β‘
β‘β‘β‘
β‘β‘β‘
β‘
```
This Young diagram corresponds to the [5, 3, 3, 1] partition of 12.
We represent it as a lower set in `β Γ β` in the product partial order. We write `(i, j) β ΞΌ`
to say that `(i, j)` (in matrix coordinates) is in the Young diagram `ΞΌ`.
## Main definitions
- `YoungDiagram` : Young diagrams
- `YoungDiagram.card` : the number of cells in a Young diagram (its *cardinality*)
- `YoungDiagram.instDistribLatticeYoungDiagram` : a distributive lattice instance for Young diagrams
ordered by containment, with `(β₯ : YoungDiagram)` the empty diagram.
- `YoungDiagram.row` and `YoungDiagram.rowLen`: rows of a Young diagram and their lengths
- `YoungDiagram.col` and `YoungDiagram.colLen`: columns of a Young diagram and their lengths
## Notation
In "English notation", a Young diagram is drawn so that (i1, j1) β€ (i2, j2)
means (i1, j1) is weakly up-and-left of (i2, j2). This terminology is used
below, e.g. in `YoungDiagram.up_left_mem`.
## Tags
Young diagram
## References
<https://en.wikipedia.org/wiki/Young_tableau>
-/
open Function
/-- A Young diagram is a finite collection of cells on the `β Γ β` grid such that whenever
a cell is present, so are all the ones above and to the left of it. Like matrices, an `(i, j)` cell
is a cell in row `i` and column `j`, where rows are enumerated downward and columns rightward.
Young diagrams are modeled as finite sets in `β Γ β` that are lower sets with respect to the
standard order on products. -/
@[ext]
structure YoungDiagram where
/-- A finite set which represents a finite collection of cells on the `β Γ β` grid. -/
cells : Finset (β Γ β)
/-- Cells are up-left justified, witnessed by the fact that `cells` is a lower set in `β Γ β`. -/
isLowerSet : IsLowerSet (cells : Set (β Γ β))
namespace YoungDiagram
instance : SetLike YoungDiagram (β Γ β) where
-- Porting note (https://github.com/leanprover-community/mathlib4/issues/11215): TODO: figure out how to do this correctly
coe y := y.cells
coe_injective' ΞΌ Ξ½ h := by rwa [YoungDiagram.ext_iff, β Finset.coe_inj]
@[simp]
theorem mem_cells {ΞΌ : YoungDiagram} (c : β Γ β) : c β ΞΌ.cells β c β ΞΌ :=
Iff.rfl
@[simp]
theorem mem_mk (c : β Γ β) (cells) (isLowerSet) :
c β YoungDiagram.mk cells isLowerSet β c β cells :=
Iff.rfl
instance decidableMem (ΞΌ : YoungDiagram) : DecidablePred (Β· β ΞΌ) :=
inferInstanceAs (DecidablePred (Β· β ΞΌ.cells))
/-- In "English notation", a Young diagram is drawn so that (i1, j1) β€ (i2, j2)
means (i1, j1) is weakly up-and-left of (i2, j2). -/
theorem up_left_mem (ΞΌ : YoungDiagram) {i1 i2 j1 j2 : β} (hi : i1 β€ i2) (hj : j1 β€ j2)
(hcell : (i2, j2) β ΞΌ) : (i1, j1) β ΞΌ :=
ΞΌ.isLowerSet (Prod.mk_le_mk.mpr β¨hi, hjβ©) hcell
section DistribLattice
@[simp]
theorem cells_subset_iff {ΞΌ Ξ½ : YoungDiagram} : ΞΌ.cells β Ξ½.cells β ΞΌ β€ Ξ½ :=
Iff.rfl
@[simp]
theorem cells_ssubset_iff {ΞΌ Ξ½ : YoungDiagram} : ΞΌ.cells β Ξ½.cells β ΞΌ < Ξ½ :=
Iff.rfl
instance : Max YoungDiagram where
max ΞΌ Ξ½ :=
{ cells := ΞΌ.cells βͺ Ξ½.cells
isLowerSet := by
rw [Finset.coe_union]
exact ΞΌ.isLowerSet.union Ξ½.isLowerSet }
@[simp]
theorem cells_sup (ΞΌ Ξ½ : YoungDiagram) : (ΞΌ β Ξ½).cells = ΞΌ.cells βͺ Ξ½.cells :=
rfl
@[simp, norm_cast]
theorem coe_sup (ΞΌ Ξ½ : YoungDiagram) : β(ΞΌ β Ξ½) = (ΞΌ βͺ Ξ½ : Set (β Γ β)) :=
Finset.coe_union _ _
@[simp]
theorem mem_sup {ΞΌ Ξ½ : YoungDiagram} {x : β Γ β} : x β ΞΌ β Ξ½ β x β ΞΌ β¨ x β Ξ½ :=
Finset.mem_union
instance : Min YoungDiagram where
min ΞΌ Ξ½ :=
{ cells := ΞΌ.cells β© Ξ½.cells
isLowerSet := by
rw [Finset.coe_inter]
exact ΞΌ.isLowerSet.inter Ξ½.isLowerSet }
@[simp]
theorem cells_inf (ΞΌ Ξ½ : YoungDiagram) : (ΞΌ β Ξ½).cells = ΞΌ.cells β© Ξ½.cells :=
rfl
@[simp, norm_cast]
theorem coe_inf (ΞΌ Ξ½ : YoungDiagram) : β(ΞΌ β Ξ½) = (ΞΌ β© Ξ½ : Set (β Γ β)) :=
Finset.coe_inter _ _
@[simp]
theorem mem_inf {ΞΌ Ξ½ : YoungDiagram} {x : β Γ β} : x β ΞΌ β Ξ½ β x β ΞΌ β§ x β Ξ½ :=
Finset.mem_inter
/-- The empty Young diagram is (β₯ : young_diagram). -/
instance : OrderBot YoungDiagram where
bot :=
{ cells := β
isLowerSet := by
intros a b _ h
simp only [Finset.coe_empty, Set.mem_empty_iff_false]
simp only [Finset.coe_empty, Set.mem_empty_iff_false] at h }
bot_le _ _ := by
intro y
simp only [mem_mk, Finset.not_mem_empty] at y
@[simp]
theorem cells_bot : (β₯ : YoungDiagram).cells = β
:=
rfl
@[simp]
theorem not_mem_bot (x : β Γ β) : x β (β₯ : YoungDiagram) :=
Finset.not_mem_empty x
@[norm_cast]
theorem coe_bot : (β₯ : YoungDiagram) = (β
: Set (β Γ β)) := by
ext; simp
instance : Inhabited YoungDiagram :=
β¨β₯β©
instance : DistribLattice YoungDiagram :=
Function.Injective.distribLattice YoungDiagram.cells (fun ΞΌ Ξ½ h => by rwa [YoungDiagram.ext_iff])
(fun _ _ => rfl) fun _ _ => rfl
end DistribLattice
/-- Cardinality of a Young diagram -/
protected abbrev card (ΞΌ : YoungDiagram) : β :=
ΞΌ.cells.card
section Transpose
/-- The `transpose` of a Young diagram is obtained by swapping i's with j's. -/
def transpose (ΞΌ : YoungDiagram) : YoungDiagram where
cells := (Equiv.prodComm _ _).finsetCongr ΞΌ.cells
isLowerSet _ _ h := by
simp only [Finset.mem_coe, Equiv.finsetCongr_apply, Finset.mem_map_equiv]
intro hcell
apply ΞΌ.isLowerSet _ hcell
simp [h]
@[simp]
theorem mem_transpose {ΞΌ : YoungDiagram} {c : β Γ β} : c β ΞΌ.transpose β c.swap β ΞΌ := by
simp [transpose]
@[simp]
theorem transpose_transpose (ΞΌ : YoungDiagram) : ΞΌ.transpose.transpose = ΞΌ := by
ext x
simp
theorem transpose_eq_iff_eq_transpose {ΞΌ Ξ½ : YoungDiagram} : ΞΌ.transpose = Ξ½ β ΞΌ = Ξ½.transpose := by
constructor <;>
Β· rintro rfl
simp
@[simp]
theorem transpose_eq_iff {ΞΌ Ξ½ : YoungDiagram} : ΞΌ.transpose = Ξ½.transpose β ΞΌ = Ξ½ := by
rw [transpose_eq_iff_eq_transpose]
simp
-- This is effectively both directions of `transpose_le_iff` below.
protected theorem le_of_transpose_le {ΞΌ Ξ½ : YoungDiagram} (h_le : ΞΌ.transpose β€ Ξ½) :
ΞΌ β€ Ξ½.transpose := fun c hc => by
simp only [mem_cells, mem_transpose]
apply h_le
simpa
@[simp]
theorem transpose_le_iff {ΞΌ Ξ½ : YoungDiagram} : ΞΌ.transpose β€ Ξ½.transpose β ΞΌ β€ Ξ½ :=
β¨fun h => by
convert YoungDiagram.le_of_transpose_le h
simp, fun h => by
rw [β transpose_transpose ΞΌ] at h
exact YoungDiagram.le_of_transpose_le h β©
@[mono]
protected theorem transpose_mono {ΞΌ Ξ½ : YoungDiagram} (h_le : ΞΌ β€ Ξ½) : ΞΌ.transpose β€ Ξ½.transpose :=
transpose_le_iff.mpr h_le
/-- Transposing Young diagrams is an `OrderIso`. -/
@[simps]
def transposeOrderIso : YoungDiagram βo YoungDiagram :=
β¨β¨transpose, transpose, fun _ => by simp, fun _ => by simpβ©, by simpβ©
end Transpose
section Rows
/-! ### Rows and row lengths of Young diagrams.
This section defines `ΞΌ.row` and `ΞΌ.rowLen`, with the following API:
1. `(i, j) β ΞΌ β j < ΞΌ.rowLen i`
2. `ΞΌ.row i = {i} ΓΛ’ (Finset.range (ΞΌ.rowLen i))`
3. `ΞΌ.rowLen i = (ΞΌ.row i).card`
4. `β {i1 i2}, i1 β€ i2 β ΞΌ.rowLen i2 β€ ΞΌ.rowLen i1`
Note: #3 is not convenient for defining `ΞΌ.rowLen`; instead, `ΞΌ.rowLen` is defined
as the smallest `j` such that `(i, j) β ΞΌ`. -/
/-- The `i`-th row of a Young diagram consists of the cells whose first coordinate is `i`. -/
def row (ΞΌ : YoungDiagram) (i : β) : Finset (β Γ β) :=
ΞΌ.cells.filter fun c => c.fst = i
theorem mem_row_iff {ΞΌ : YoungDiagram} {i : β} {c : β Γ β} : c β ΞΌ.row i β c β ΞΌ β§ c.fst = i := by
simp [row]
theorem mk_mem_row_iff {ΞΌ : YoungDiagram} {i j : β} : (i, j) β ΞΌ.row i β (i, j) β ΞΌ := by simp [row]
protected theorem exists_not_mem_row (ΞΌ : YoungDiagram) (i : β) : β j, (i, j) β ΞΌ := by
obtain β¨j, hjβ© :=
Infinite.exists_not_mem_finset
(ΞΌ.cells.preimage (Prod.mk i) fun _ _ _ _ h => by
cases h
rfl)
rw [Finset.mem_preimage] at hj
exact β¨j, hjβ©
/-- Length of a row of a Young diagram -/
def rowLen (ΞΌ : YoungDiagram) (i : β) : β :=
Nat.find <| ΞΌ.exists_not_mem_row i
theorem mem_iff_lt_rowLen {ΞΌ : YoungDiagram} {i j : β} : (i, j) β ΞΌ β j < ΞΌ.rowLen i := by
rw [rowLen, Nat.lt_find_iff]
push_neg
exact β¨fun h _ hmj => ΞΌ.up_left_mem (by rfl) hmj h, fun h => h _ (by rfl)β©
theorem row_eq_prod {ΞΌ : YoungDiagram} {i : β} : ΞΌ.row i = {i} ΓΛ’ Finset.range (ΞΌ.rowLen i) := by
ext β¨a, bβ©
simp only [Finset.mem_product, Finset.mem_singleton, Finset.mem_range, mem_row_iff,
mem_iff_lt_rowLen, and_comm, and_congr_right_iff]
rintro rfl
rfl
theorem rowLen_eq_card (ΞΌ : YoungDiagram) {i : β} : ΞΌ.rowLen i = (ΞΌ.row i).card := by
simp [row_eq_prod]
@[mono]
theorem rowLen_anti (ΞΌ : YoungDiagram) (i1 i2 : β) (hi : i1 β€ i2) : ΞΌ.rowLen i2 β€ ΞΌ.rowLen i1 := by
by_contra! h_lt
rw [β lt_self_iff_false (ΞΌ.rowLen i1)]
rw [β mem_iff_lt_rowLen] at h_lt β’
exact ΞΌ.up_left_mem hi (by rfl) h_lt
end Rows
section Columns
/-! ### Columns and column lengths of Young diagrams.
This section has an identical API to the rows section. -/
/-- The `j`-th column of a Young diagram consists of the cells whose second coordinate is `j`. -/
def col (ΞΌ : YoungDiagram) (j : β) : Finset (β Γ β) :=
ΞΌ.cells.filter fun c => c.snd = j
theorem mem_col_iff {ΞΌ : YoungDiagram} {j : β} {c : β Γ β} : c β ΞΌ.col j β c β ΞΌ β§ c.snd = j := by
simp [col]
theorem mk_mem_col_iff {ΞΌ : YoungDiagram} {i j : β} : (i, j) β ΞΌ.col j β (i, j) β ΞΌ := by simp [col]
protected theorem exists_not_mem_col (ΞΌ : YoungDiagram) (j : β) : β i, (i, j) β ΞΌ.cells := by
convert ΞΌ.transpose.exists_not_mem_row j using 1
simp
/-- Length of a column of a Young diagram -/
def colLen (ΞΌ : YoungDiagram) (j : β) : β :=
Nat.find <| ΞΌ.exists_not_mem_col j
@[simp]
theorem colLen_transpose (ΞΌ : YoungDiagram) (j : β) : ΞΌ.transpose.colLen j = ΞΌ.rowLen j := by
simp [rowLen, colLen]
@[simp]
theorem rowLen_transpose (ΞΌ : YoungDiagram) (i : β) : ΞΌ.transpose.rowLen i = ΞΌ.colLen i := by
simp [rowLen, colLen]
theorem mem_iff_lt_colLen {ΞΌ : YoungDiagram} {i j : β} : (i, j) β ΞΌ β i < ΞΌ.colLen j := by
rw [β rowLen_transpose, β mem_iff_lt_rowLen]
simp
theorem col_eq_prod {ΞΌ : YoungDiagram} {j : β} : ΞΌ.col j = Finset.range (ΞΌ.colLen j) ΓΛ’ {j} := by
ext β¨a, bβ©
simp only [Finset.mem_product, Finset.mem_singleton, Finset.mem_range, mem_col_iff,
mem_iff_lt_colLen, and_comm, and_congr_right_iff]
rintro rfl
rfl
theorem colLen_eq_card (ΞΌ : YoungDiagram) {j : β} : ΞΌ.colLen j = (ΞΌ.col j).card := by
simp [col_eq_prod]
@[mono]
theorem colLen_anti (ΞΌ : YoungDiagram) (j1 j2 : β) (hj : j1 β€ j2) : ΞΌ.colLen j2 β€ ΞΌ.colLen j1 := by
convert ΞΌ.transpose.rowLen_anti j1 j2 hj using 1 <;> simp
end Columns
section RowLens
/-! ### The list of row lengths of a Young diagram
This section defines `ΞΌ.rowLens : List β`, the list of row lengths of a Young diagram `ΞΌ`.
1. `YoungDiagram.rowLens_sorted` : It is weakly decreasing (`List.Sorted (Β· β₯ Β·)`).
2. `YoungDiagram.rowLens_pos` : It is strictly positive.
-/
/-- List of row lengths of a Young diagram -/
def rowLens (ΞΌ : YoungDiagram) : List β :=
(List.range <| ΞΌ.colLen 0).map ΞΌ.rowLen
@[simp]
theorem get_rowLens {ΞΌ : YoungDiagram} {i : Nat} {h : i < ΞΌ.rowLens.length} :
ΞΌ.rowLens[i] = ΞΌ.rowLen i := by simp only [rowLens, List.getElem_range, List.getElem_map]
@[simp]
theorem length_rowLens {ΞΌ : YoungDiagram} : ΞΌ.rowLens.length = ΞΌ.colLen 0 := by
simp only [rowLens, List.length_map, List.length_range]
theorem rowLens_sorted (ΞΌ : YoungDiagram) : ΞΌ.rowLens.Sorted (Β· β₯ Β·) :=
List.pairwise_le_range.map _ ΞΌ.rowLen_anti
theorem pos_of_mem_rowLens (ΞΌ : YoungDiagram) (x : β) (hx : x β ΞΌ.rowLens) : 0 < x := by
rw [rowLens, List.mem_map] at hx
obtain β¨i, hi, rfl : ΞΌ.rowLen i = xβ© := hx
rwa [List.mem_range, β mem_iff_lt_colLen, mem_iff_lt_rowLen] at hi
end RowLens
section EquivListRowLens
/-! ### Equivalence between Young diagrams and lists of natural numbers
This section defines the equivalence between Young diagrams `ΞΌ` and weakly decreasing lists `w`
of positive natural numbers, corresponding to row lengths of the diagram:
`YoungDiagram.equivListRowLens :`
`YoungDiagram β {w : List β // w.Sorted (Β· β₯ Β·) β§ β x β w, 0 < x}`
The two directions are `YoungDiagram.rowLens` (defined above) and `YoungDiagram.ofRowLens`.
-/
|
/-- The cells making up a `YoungDiagram` from a list of row lengths -/
| Mathlib/Combinatorics/Young/YoungDiagram.lean | 392 | 393 |
/-
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.OuterMeasure.OfFunction
import Mathlib.MeasureTheory.PiSystem
/-!
# The Caratheodory Ο-algebra of an outer measure
Given an outer measure `m`, the CarathΓ©odory-measurable sets are the sets `s` such that
for all sets `t` we have `m t = m (t β© s) + m (t \ s)`. This forms a measurable space.
## Main definitions and statements
* `MeasureTheory.OuterMeasure.caratheodory` is the CarathΓ©odory-measurable space
of an outer measure.
## References
* <https://en.wikipedia.org/wiki/Outer_measure>
* <https://en.wikipedia.org/wiki/Carath%C3%A9odory%27s_criterion>
## Tags
CarathΓ©odory-measurable, CarathΓ©odory's criterion
-/
noncomputable section
open Set Function Filter
open scoped NNReal Topology ENNReal
namespace MeasureTheory
namespace OuterMeasure
section CaratheodoryMeasurable
universe u
variable {Ξ± : Type u} (m : OuterMeasure Ξ±)
attribute [local simp] Set.inter_comm Set.inter_left_comm Set.inter_assoc
variable {s sβ sβ : Set Ξ±}
/-- A set `s` is CarathΓ©odory-measurable for an outer measure `m` if for all sets `t` we have
`m t = m (t β© s) + m (t \ s)`. -/
def IsCaratheodory (s : Set Ξ±) : Prop :=
β t, m t = m (t β© s) + m (t \ s)
theorem isCaratheodory_iff_le' {s : Set Ξ±} :
IsCaratheodory m s β β t, m (t β© s) + m (t \ s) β€ m t :=
forall_congr' fun _ => le_antisymm_iff.trans <| and_iff_right <| measure_le_inter_add_diff _ _ _
@[simp]
theorem isCaratheodory_empty : IsCaratheodory m β
:= by simp [IsCaratheodory, m.empty, diff_empty]
theorem isCaratheodory_compl : IsCaratheodory m sβ β IsCaratheodory m sβαΆ := by
simp [IsCaratheodory, diff_eq, add_comm]
@[simp]
theorem isCaratheodory_compl_iff : IsCaratheodory m sαΆ β IsCaratheodory m s :=
β¨fun h => by simpa using isCaratheodory_compl m h, isCaratheodory_compl mβ©
theorem isCaratheodory_union (hβ : IsCaratheodory m sβ) (hβ : IsCaratheodory m sβ) :
IsCaratheodory m (sβ βͺ sβ) := fun t => by
rw [hβ t, hβ (t β© sβ), hβ (t \ sβ), hβ (t β© (sβ βͺ sβ)), inter_diff_assoc _ _ sβ,
Set.inter_assoc _ _ sβ, inter_eq_self_of_subset_right Set.subset_union_left,
union_diff_left, hβ (t β© sβ)]
simp [diff_eq, add_assoc]
variable {m} in
lemma IsCaratheodory.biUnion_of_finite {ΞΉ : Type*} {s : ΞΉ β Set Ξ±} {t : Set ΞΉ} (ht : t.Finite)
(h : β i β t, m.IsCaratheodory (s i)) :
m.IsCaratheodory (β i β t, s i) := by
classical
lift t to Finset ΞΉ using ht
induction t using Finset.induction_on with
| empty => simp
| insert i t hi IH =>
simp only [Finset.mem_coe, Finset.mem_insert, iUnion_iUnion_eq_or_left] at h β’
exact m.isCaratheodory_union (h _ <| Or.inl rfl) (IH fun _ hj β¦ h _ <| Or.inr hj)
theorem measure_inter_union (h : sβ β© sβ β β
) (hβ : IsCaratheodory m sβ) {t : Set Ξ±} :
m (t β© (sβ βͺ sβ)) = m (t β© sβ) + m (t β© sβ) := by
rw [hβ, Set.inter_assoc, Set.union_inter_cancel_left, inter_diff_assoc, union_diff_cancel_left h]
theorem isCaratheodory_iUnion_lt {s : β β Set Ξ±} :
β {n : β}, (β i < n, IsCaratheodory m (s i)) β IsCaratheodory m (β i < n, s i)
| 0, _ => by simp [Nat.not_lt_zero]
| n + 1, h => by
rw [biUnion_lt_succ]
exact isCaratheodory_union m
(isCaratheodory_iUnion_lt fun i hi => h i <| lt_of_lt_of_le hi <| Nat.le_succ _)
(h n (le_refl (n + 1)))
theorem isCaratheodory_inter (hβ : IsCaratheodory m sβ) (hβ : IsCaratheodory m sβ) :
IsCaratheodory m (sβ β© sβ) := by
rw [β isCaratheodory_compl_iff, Set.compl_inter]
exact isCaratheodory_union _ (isCaratheodory_compl _ hβ) (isCaratheodory_compl _ hβ)
lemma isCaratheodory_diff (hβ : IsCaratheodory m sβ) (hβ : IsCaratheodory m sβ) :
IsCaratheodory m (sβ \ sβ) := m.isCaratheodory_inter hβ (m.isCaratheodory_compl hβ)
lemma isCaratheodory_partialSups {ΞΉ : Type*} [Preorder ΞΉ] [LocallyFiniteOrderBot ΞΉ]
{s : ΞΉ β Set Ξ±} (h : β i, m.IsCaratheodory (s i)) (i : ΞΉ) :
m.IsCaratheodory (partialSups s i) := by
simpa only [partialSups_apply, Finset.sup'_eq_sup, Finset.sup_set_eq_biUnion, β Finset.mem_coe,
Finset.coe_Iic] using .biUnion_of_finite (finite_Iic _) (fun j _ β¦ h j)
lemma isCaratheodory_disjointed {ΞΉ : Type*} [Preorder ΞΉ] [LocallyFiniteOrderBot ΞΉ]
{s : ΞΉ β Set Ξ±} (h : β i, m.IsCaratheodory (s i)) (i : ΞΉ) :
m.IsCaratheodory (disjointed s i) :=
disjointedRec (fun _ j ht β¦ m.isCaratheodory_diff ht <| h j) (h i)
theorem isCaratheodory_sum {s : β β Set Ξ±} (h : β i, IsCaratheodory m (s i))
(hd : Pairwise (Disjoint on s)) {t : Set Ξ±} :
β {n}, (β i β Finset.range n, m (t β© s i)) = m (t β© β i < n, s i)
| 0 => by simp [Nat.not_lt_zero, m.empty]
| Nat.succ n => by
rw [biUnion_lt_succ, Finset.sum_range_succ, Set.union_comm, isCaratheodory_sum h hd,
m.measure_inter_union _ (h n), add_comm]
intro a
simpa using fun (hβ : a β s n) i (hi : i < n) hβ => (hd (ne_of_gt hi)).le_bot β¨hβ, hββ©
/-- Use `isCaratheodory_iUnion` instead, which does not require the disjoint assumption. -/
theorem isCaratheodory_iUnion_of_disjoint {s : β β Set Ξ±} (h : β i, IsCaratheodory m (s i))
(hd : Pairwise (Disjoint on s)) : IsCaratheodory m (β i, s i) := by
apply (isCaratheodory_iff_le' m).mpr
intro t
have hp : m (t β© β i, s i) β€ β¨ n, m (t β© β i < n, s i) := by
convert measure_iUnion_le (ΞΌ := m) fun i => t β© s i using 1
Β· simp [inter_iUnion]
Β· simp [ENNReal.tsum_eq_iSup_nat, isCaratheodory_sum m h hd]
refine le_trans (add_le_add_right hp _) ?_
rw [ENNReal.iSup_add]
refine iSup_le fun n => le_trans (add_le_add_left ?_ _)
(ge_of_eq (isCaratheodory_iUnion_lt m (fun i _ => h i) _))
refine m.mono (diff_subset_diff_right ?_)
exact iUnionβ_subset fun i _ => subset_iUnion _ i
lemma isCaratheodory_iUnion {s : β β Set Ξ±} (h : β i, m.IsCaratheodory (s i)) :
m.IsCaratheodory (β i, s i) := by
rw [β iUnion_disjointed]
exact m.isCaratheodory_iUnion_of_disjoint (m.isCaratheodory_disjointed h)
(disjoint_disjointed _)
theorem f_iUnion {s : β β Set Ξ±} (h : β i, IsCaratheodory m (s i)) (hd : Pairwise (Disjoint on s)) :
m (β i, s i) = β' i, m (s i) := by
refine le_antisymm (measure_iUnion_le s) ?_
rw [ENNReal.tsum_eq_iSup_nat]
refine iSup_le fun n => ?_
have := @isCaratheodory_sum _ m _ h hd univ n
simp only [inter_comm, inter_univ, univ_inter] at this; simp only [this]
exact m.mono (iUnionβ_subset fun i _ => subset_iUnion _ i)
/-- The CarathΓ©odory-measurable sets for an outer measure `m` form a Dynkin system. -/
def caratheodoryDynkin : MeasurableSpace.DynkinSystem Ξ± where
Has := IsCaratheodory m
has_empty := isCaratheodory_empty m
has_compl s := isCaratheodory_compl m s
has_iUnion_nat _ hf hn := by apply isCaratheodory_iUnion m hf
/-- Given an outer measure `ΞΌ`, the CarathΓ©odory-measurable space is
defined such that `s` is measurable if `βt, ΞΌ t = ΞΌ (t β© s) + ΞΌ (t \ s)`. -/
protected def caratheodory : MeasurableSpace Ξ± := by
apply MeasurableSpace.DynkinSystem.toMeasurableSpace (caratheodoryDynkin m)
intro sβ sβ
apply isCaratheodory_inter
theorem isCaratheodory_iff {s : Set Ξ±} :
MeasurableSet[OuterMeasure.caratheodory m] s β β t, m t = m (t β© s) + m (t \ s) :=
Iff.rfl
theorem isCaratheodory_iff_le {s : Set Ξ±} :
MeasurableSet[OuterMeasure.caratheodory m] s β β t, m (t β© s) + m (t \ s) β€ m t :=
isCaratheodory_iff_le' m
protected theorem iUnion_eq_of_caratheodory {s : β β Set Ξ±}
(h : β i, MeasurableSet[OuterMeasure.caratheodory m] (s i)) (hd : Pairwise (Disjoint on s)) :
m (β i, s i) = β' i, m (s i) :=
f_iUnion m h hd
end CaratheodoryMeasurable
variable {Ξ± : Type*}
theorem ofFunction_caratheodory {m : Set Ξ± β ββ₯0β} {s : Set Ξ±} {hβ : m β
= 0}
(hs : β t, m (t β© s) + m (t \ s) β€ m t) :
MeasurableSet[(OuterMeasure.ofFunction m hβ).caratheodory] s := by
apply (isCaratheodory_iff_le _).mpr
refine fun t => le_iInf fun f => le_iInf fun hf => ?_
refine
le_trans
(add_le_add ((iInf_le_of_le fun i => f i β© s) <| iInf_le _ ?_)
((iInf_le_of_le fun i => f i \ s) <| iInf_le _ ?_))
?_
Β· rw [β iUnion_inter]
exact inter_subset_inter_left _ hf
Β· rw [β iUnion_diff]
exact diff_subset_diff_left hf
Β· rw [β ENNReal.tsum_add]
exact ENNReal.tsum_le_tsum fun i => hs _
theorem boundedBy_caratheodory {m : Set Ξ± β ββ₯0β} {s : Set Ξ±}
(hs : β t, m (t β© s) + m (t \ s) β€ m t) : MeasurableSet[(boundedBy m).caratheodory] s := by
apply ofFunction_caratheodory; intro t
rcases t.eq_empty_or_nonempty with h | h
Β· simp [h, Set.not_nonempty_empty]
Β· convert le_trans _ (hs t)
Β· simp [h]
exact add_le_add iSup_const_le iSup_const_le
@[simp]
theorem zero_caratheodory : (0 : OuterMeasure Ξ±).caratheodory = β€ :=
top_unique fun _ _ _ => (add_zero _).symm
theorem top_caratheodory : (β€ : OuterMeasure Ξ±).caratheodory = β€ :=
top_unique fun s _ =>
(isCaratheodory_iff_le _).2 fun t =>
t.eq_empty_or_nonempty.elim (fun ht => by simp [ht]) fun ht => by
simp only [ht, top_apply, le_top]
theorem le_add_caratheodory (mβ mβ : OuterMeasure Ξ±) :
mβ.caratheodory β mβ.caratheodory β€ (mβ + mβ : OuterMeasure Ξ±).caratheodory :=
fun s β¨hsβ, hsββ© t => by simp [hsβ t, hsβ t, add_left_comm, add_assoc]
theorem le_sum_caratheodory {ΞΉ} (m : ΞΉ β OuterMeasure Ξ±) :
β¨
i, (m i).caratheodory β€ (sum m).caratheodory := fun s h t => by
simp [fun i => MeasurableSpace.measurableSet_iInf.1 h i t, ENNReal.tsum_add]
| theorem le_smul_caratheodory (a : ββ₯0β) (m : OuterMeasure Ξ±) :
m.caratheodory β€ (a β’ m).caratheodory := fun s h t => by
simp only [smul_apply, smul_eq_mul]
rw [(isCaratheodory_iff m).mp h t]
| Mathlib/MeasureTheory/OuterMeasure/Caratheodory.lean | 235 | 238 |
/-
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.RingTheory.MvPowerSeries.Basic
import Mathlib.Data.Finsupp.Interval
import Mathlib.Algebra.MvPolynomial.Eval
/-!
# Formal (multivariate) power series - Truncation
* `MvPowerSeries.trunc n Ο` truncates a formal multivariate power series
to the multivariate polynomial that has the same coefficients as `Ο`,
for all `m < n`, and `0` otherwise.
Note that here, `m` and `n` have types `Ο ββ β`,
so that `m < n` means that `m β n` and `m s β€ n s` for all `s : Ο`.
* `MvPowerSeries.trunc_one` : truncation of the unit power series
* `MvPowerSeries.trunc_C` : truncation of a constant
* `MvPowerSeries.trunc_C_mul` : truncation of constant multiple.
* `MvPowerSeries.trunc' n Ο` truncates a formal multivariate power series
to the multivariate polynomial that has the same coefficients as `Ο`,
for all `m β€ n`, and `0` otherwise.
Here, `m` and `n` have types `Ο ββ β` so that `m β€ n` means that `m s β€ n s` for all `s : Ο`.
* `MvPowerSeries.coeff_mul_eq_coeff_trunc'_mul_trunc'` : compares the coefficients
of a product with those of the product of truncations.
* `MvPowerSeries.trunc'_one` : truncation of a the unit power series.
* `MvPowerSeries.trunc'_C` : truncation of a constant.
* `MvPowerSeries.trunc'_C_mul` : truncation of a constant multiple.
* `MvPowerSeries.trunc'_map` : image of a truncation under a change of rings
## TODO
* Unify both versions using a general purpose API
-/
noncomputable section
open Finset (antidiagonal mem_antidiagonal)
namespace MvPowerSeries
open Finsupp
variable {Ο R S : Type*}
section TruncLT
variable [DecidableEq Ο] [CommSemiring R] (n : Ο ββ β)
/-- Auxiliary definition for the truncation function. -/
def truncFun (Ο : MvPowerSeries Ο R) : MvPolynomial Ο R :=
β m β Finset.Iio n, MvPolynomial.monomial m (coeff R m Ο)
theorem coeff_truncFun (m : Ο ββ β) (Ο : MvPowerSeries Ο R) :
(truncFun n Ο).coeff m = if m < n then coeff R m Ο else 0 := by
classical
simp [truncFun, MvPolynomial.coeff_sum]
variable (R) in
/-- The `n`th truncation of a multivariate formal power series to a multivariate polynomial
If `f : MvPowerSeries Ο R` and `n : Ο ββ β` is a (finitely-supported) function from `Ο`
to the naturals, then `trunc' R n f` is the multivariable power series obtained from `f`
by keeping only the monomials $c\prod_i X_i^{a_i}$ where `a i β€ n i` for all `i`
and $a i < n i` for some `i`. -/
def trunc : MvPowerSeries Ο R β+ MvPolynomial Ο R where
toFun := truncFun n
map_zero' := by
classical
ext
simp [coeff_truncFun]
map_add' := by
classical
intros x y
ext m
simp only [coeff_truncFun, MvPolynomial.coeff_add, ite_add_ite, β map_add, add_zero]
theorem coeff_trunc (m : Ο ββ β) (Ο : MvPowerSeries Ο R) :
| (trunc R n Ο).coeff m = if m < n then coeff R m Ο else 0 := by
classical simp [trunc, coeff_truncFun]
@[simp]
theorem trunc_one (n : Ο ββ β) (hnn : n β 0) : trunc R n 1 = 1 :=
MvPolynomial.ext _ _ fun m β¦ by
| Mathlib/RingTheory/MvPowerSeries/Trunc.lean | 96 | 101 |
/-
Copyright (c) 2017 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Gabriel Ebner
-/
import Mathlib.Data.Int.Cast.Defs
import Mathlib.Algebra.Group.Basic
import Mathlib.Data.Nat.Basic
/-!
# Cast of integers (additional theorems)
This file proves additional properties about the *canonical* homomorphism from
the integers into an additive group with a one (`Int.cast`).
There is also `Data.Int.Cast.Lemmas`,
which includes lemmas stated in terms of algebraic homomorphisms,
and results involving the order structure of `β€`.
By contrast, this file's only import beyond `Data.Int.Cast.Defs` is `Algebra.Group.Basic`.
-/
universe u
namespace Nat
variable {R : Type u} [AddGroupWithOne R]
@[simp, norm_cast]
theorem cast_sub {m n} (h : m β€ n) : ((n - m : β) : R) = n - m :=
eq_sub_of_add_eq <| by rw [β cast_add, Nat.sub_add_cancel h]
-- `HasLiftT` appeared in the type signature
@[simp, norm_cast]
theorem cast_pred : β {n}, 0 < n β ((n - 1 : β) : R) = n - 1
| 0, h => by cases h
| n + 1, _ => by rw [cast_succ, add_sub_cancel_right]; rfl
end Nat
open Nat
namespace Int
variable {R : Type u} [AddGroupWithOne R]
-- TODO: I don't like that `norm_cast` is used here, because it results in `norm_cast`
-- introducing the "implementation detail" `Int.negSucc`.
@[simp, norm_cast squash]
theorem cast_negSucc (n : β) : (-[n+1] : R) = -(n + 1 : β) :=
AddGroupWithOne.intCast_negSucc n
-- expected `n` to be implicit, and `HasLiftT`
@[simp, norm_cast]
theorem cast_zero : ((0 : β€) : R) = 0 :=
(AddGroupWithOne.intCast_ofNat 0).trans Nat.cast_zero
-- type had `HasLiftT`
-- This lemma competes with `Int.ofNat_eq_natCast` to come later
@[simp high, nolint simpNF, norm_cast]
theorem cast_natCast (n : β) : ((n : β€) : R) = n :=
AddGroupWithOne.intCast_ofNat _
-- expected `n` to be implicit, and `HasLiftT`
@[simp, norm_cast]
theorem cast_ofNat (n : β) [n.AtLeastTwo] :
((ofNat(n) : β€) : R) = ofNat(n) := by
simpa only [OfNat.ofNat] using AddGroupWithOne.intCast_ofNat (R := R) n
@[simp, norm_cast]
theorem cast_one : ((1 : β€) : R) = 1 := by
rw [β Int.natCast_one, cast_natCast, Nat.cast_one]
-- type had `HasLiftT`
@[simp, norm_cast]
theorem cast_neg : β n, ((-n : β€) : R) = -n
| (0 : β) => by simp
| (n + 1 : β) => by rw [cast_natCast, neg_ofNat_succ]; simp
| -[n+1] => by rw [Int.neg_negSucc, cast_natCast]; simp
-- type had `HasLiftT`
@[simp, norm_cast]
theorem cast_subNatNat (m n) : ((Int.subNatNat m n : β€) : R) = m - n := by
unfold subNatNat
cases e : n - m
Β· simp only [ofNat_eq_coe]
simp [e, Nat.le_of_sub_eq_zero e]
Β· rw [cast_negSucc, β e, Nat.cast_sub <| _root_.le_of_lt <| Nat.lt_of_sub_eq_succ e, neg_sub]
-- type had `HasLiftT`
@[simp]
theorem cast_negOfNat (n : β) : ((negOfNat n : β€) : R) = -n := by simp [Int.cast_neg, negOfNat_eq]
@[simp, norm_cast]
theorem cast_add : β m n, ((m + n : β€) : R) = m + n
| (m : β), (n : β) => by simp [β Int.natCast_add]
| (m : β), -[n+1] => by erw [cast_subNatNat, cast_natCast, cast_negSucc, sub_eq_add_neg]
| -[m+1], (n : β) => by
#adaptation_note
/-- `_root_` can be removed again after
https://github.com/leanprover/lean4/pull/7359 lands in nightly-2025-03-06. -/
erw [cast_subNatNat, cast_natCast, cast_negSucc, _root_.sub_eq_iff_eq_add, add_assoc,
eq_neg_add_iff_add_eq, β Nat.cast_add, β Nat.cast_add, Nat.add_comm]
| -[m+1], -[n+1] =>
show (-[m + n + 1+1] : R) = _ by
rw [cast_negSucc, cast_negSucc, cast_negSucc, β neg_add_rev, β Nat.cast_add,
Nat.add_right_comm m n 1, Nat.add_assoc, Nat.add_comm]
-- type had `HasLiftT`
@[simp, norm_cast]
theorem cast_sub (m n) : ((m - n : β€) : R) = m - n := by
simp [Int.sub_eq_add_neg, sub_eq_add_neg, Int.cast_neg, Int.cast_add]
-- type had `HasLiftT`
theorem cast_two : ((2 : β€) : R) = 2 := cast_ofNat _
theorem cast_three : ((3 : β€) : R) = 3 := cast_ofNat _
theorem cast_four : ((4 : β€) : R) = 4 := cast_ofNat _
end Int
section zsmul
variable {R : Type*}
@[simp] lemma zsmul_one [AddGroupWithOne R] (n : β€) : n β’ (1 : R) = n := by cases n <;> simp
end zsmul
| Mathlib/Data/Int/Cast/Basic.lean | 137 | 138 | |
/-
Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: SΓ©bastien GouΓ«zel, Johannes HΓΆlzl, Yury Kudryashov, Patrick Massot
-/
import Mathlib.Algebra.GeomSum
import Mathlib.Order.Filter.AtTopBot.Archimedean
import Mathlib.Order.Iterate
import Mathlib.Topology.Algebra.Algebra
import Mathlib.Topology.Algebra.InfiniteSum.Real
import Mathlib.Topology.Instances.EReal.Lemmas
/-!
# A collection of specific limit computations
This file, by design, is independent of `NormedSpace` in the import hierarchy. It contains
important specific limit computations in metric spaces, in ordered rings/fields, and in specific
instances of these such as `β`, `ββ₯0` and `ββ₯0β`.
-/
assert_not_exists Basis NormedSpace
noncomputable section
open Set Function Filter Finset Metric Topology Nat uniformity NNReal ENNReal
variable {Ξ± : Type*} {Ξ² : Type*} {ΞΉ : Type*}
theorem tendsto_inverse_atTop_nhds_zero_nat : Tendsto (fun n : β β¦ (n : β)β»ΒΉ) atTop (π 0) :=
tendsto_inv_atTop_zero.comp tendsto_natCast_atTop_atTop
theorem tendsto_const_div_atTop_nhds_zero_nat (C : β) :
Tendsto (fun n : β β¦ C / n) atTop (π 0) := by
simpa only [mul_zero] using tendsto_const_nhds.mul tendsto_inverse_atTop_nhds_zero_nat
theorem tendsto_one_div_atTop_nhds_zero_nat : Tendsto (fun n : β β¦ 1/(n : β)) atTop (π 0) :=
tendsto_const_div_atTop_nhds_zero_nat 1
theorem NNReal.tendsto_inverse_atTop_nhds_zero_nat :
Tendsto (fun n : β β¦ (n : ββ₯0)β»ΒΉ) atTop (π 0) := by
rw [β NNReal.tendsto_coe]
exact _root_.tendsto_inverse_atTop_nhds_zero_nat
theorem NNReal.tendsto_const_div_atTop_nhds_zero_nat (C : ββ₯0) :
Tendsto (fun n : β β¦ C / n) atTop (π 0) := by
simpa using tendsto_const_nhds.mul NNReal.tendsto_inverse_atTop_nhds_zero_nat
theorem EReal.tendsto_const_div_atTop_nhds_zero_nat {C : EReal} (h : C β β₯) (h' : C β β€) :
Tendsto (fun n : β β¦ C / n) atTop (π 0) := by
have : (fun n : β β¦ C / n) = fun n : β β¦ ((C.toReal / n : β) : EReal) := by
ext n
nth_rw 1 [β coe_toReal h' h, β coe_coe_eq_natCast n, β coe_div C.toReal n]
rw [this, β coe_zero, tendsto_coe]
exact _root_.tendsto_const_div_atTop_nhds_zero_nat C.toReal
theorem tendsto_one_div_add_atTop_nhds_zero_nat :
Tendsto (fun n : β β¦ 1 / ((n : β) + 1)) atTop (π 0) :=
suffices Tendsto (fun n : β β¦ 1 / (β(n + 1) : β)) atTop (π 0) by simpa
(tendsto_add_atTop_iff_nat 1).2 (_root_.tendsto_const_div_atTop_nhds_zero_nat 1)
theorem NNReal.tendsto_algebraMap_inverse_atTop_nhds_zero_nat (π : Type*) [Semiring π]
[Algebra ββ₯0 π] [TopologicalSpace π] [ContinuousSMul ββ₯0 π] :
Tendsto (algebraMap ββ₯0 π β fun n : β β¦ (n : ββ₯0)β»ΒΉ) atTop (π 0) := by
convert (continuous_algebraMap ββ₯0 π).continuousAt.tendsto.comp
tendsto_inverse_atTop_nhds_zero_nat
rw [map_zero]
theorem tendsto_algebraMap_inverse_atTop_nhds_zero_nat (π : Type*) [Semiring π] [Algebra β π]
[TopologicalSpace π] [ContinuousSMul β π] :
Tendsto (algebraMap β π β fun n : β β¦ (n : β)β»ΒΉ) atTop (π 0) :=
NNReal.tendsto_algebraMap_inverse_atTop_nhds_zero_nat π
/-- The limit of `n / (n + x)` is 1, for any constant `x` (valid in `β` or any topological division
algebra over `β`, e.g., `β`).
TODO: introduce a typeclass saying that `1 / n` tends to 0 at top, making it possible to get this
statement simultaneously on `β`, `β` and `β`. -/
theorem tendsto_natCast_div_add_atTop {π : Type*} [DivisionRing π] [TopologicalSpace π]
[CharZero π] [Algebra β π] [ContinuousSMul β π] [IsTopologicalDivisionRing π] (x : π) :
Tendsto (fun n : β β¦ (n : π) / (n + x)) atTop (π 1) := by
convert Tendsto.congr' ((eventually_ne_atTop 0).mp (Eventually.of_forall fun n hn β¦ _)) _
Β· exact fun n : β β¦ 1 / (1 + x / n)
Β· field_simp [Nat.cast_ne_zero.mpr hn]
Β· have : π (1 : π) = π (1 / (1 + x * (0 : π))) := by
rw [mul_zero, add_zero, div_one]
rw [this]
refine tendsto_const_nhds.div (tendsto_const_nhds.add ?_) (by simp)
simp_rw [div_eq_mul_inv]
refine tendsto_const_nhds.mul ?_
have := ((continuous_algebraMap β π).tendsto _).comp tendsto_inverse_atTop_nhds_zero_nat
rw [map_zero, Filter.tendsto_atTop'] at this
refine Iff.mpr tendsto_atTop' ?_
intros
simp_all only [comp_apply, map_invβ, map_natCast]
/-- For any positive `m : β`, `((n % m : β) : β) / (n : β)` tends to `0` as `n` tends to `β`. -/
theorem tendsto_mod_div_atTop_nhds_zero_nat {m : β} (hm : 0 < m) :
Tendsto (fun n : β => ((n % m : β) : β) / (n : β)) atTop (π 0) := by
have h0 : βαΆ n : β in atTop, 0 β€ (fun n : β => ((n % m : β) : β)) n := by aesop
exact tendsto_bdd_div_atTop_nhds_zero h0
(.of_forall (fun n β¦ cast_le.mpr (mod_lt n hm).le)) tendsto_natCast_atTop_atTop
theorem Filter.EventuallyEq.div_mul_cancel {Ξ± G : Type*} [GroupWithZero G] {f g : Ξ± β G}
{l : Filter Ξ±} (hg : Tendsto g l (π {0}αΆ)) : (fun x β¦ f x / g x * g x) =αΆ [l] fun x β¦ f x := by
filter_upwards [hg.le_comap <| preimage_mem_comap (m := g) (mem_principal_self {0}αΆ)] with x hx
aesop
/-- If `g` tends to `β`, then eventually for all `x` we have `(f x / g x) * g x = f x`. -/
theorem Filter.EventuallyEq.div_mul_cancel_atTop {Ξ± K : Type*}
[Semifield K] [LinearOrder K] [IsStrictOrderedRing K]
{f g : Ξ± β K} {l : Filter Ξ±} (hg : Tendsto g l atTop) :
(fun x β¦ f x / g x * g x) =αΆ [l] fun x β¦ f x :=
div_mul_cancel <| hg.mono_right <| le_principal_iff.mpr <|
mem_of_superset (Ioi_mem_atTop 0) <| by simp
/-- If when `x` tends to `β`, `g` tends to `β` and `f x / g x` tends to a positive
constant, then `f` tends to `β`. -/
theorem Tendsto.num {Ξ± K : Type*} [Field K] [LinearOrder K] [IsStrictOrderedRing K]
[TopologicalSpace K] [OrderTopology K]
{f g : Ξ± β K} {l : Filter Ξ±} (hg : Tendsto g l atTop) {a : K} (ha : 0 < a)
(hlim : Tendsto (fun x => f x / g x) l (π a)) :
Tendsto f l atTop :=
(hlim.pos_mul_atTop ha hg).congr' (EventuallyEq.div_mul_cancel_atTop hg)
/-- If when `x` tends to `β`, `g` tends to `β` and `f x / g x` tends to a positive
constant, then `f` tends to `β`. -/
theorem Tendsto.den {Ξ± K : Type*} [Field K] [LinearOrder K] [IsStrictOrderedRing K]
[TopologicalSpace K] [OrderTopology K]
[ContinuousInv K] {f g : Ξ± β K} {l : Filter Ξ±} (hf : Tendsto f l atTop) {a : K} (ha : 0 < a)
(hlim : Tendsto (fun x => f x / g x) l (π a)) :
Tendsto g l atTop :=
have hlim' : Tendsto (fun x => g x / f x) l (π aβ»ΒΉ) := by
simp_rw [β inv_div (f _)]
exact Filter.Tendsto.inv (f := fun x => f x / g x) hlim
(hlim'.pos_mul_atTop (inv_pos_of_pos ha) hf).congr' (.div_mul_cancel_atTop hf)
/-- If when `x` tends to `β`, `f x / g x` tends to a positive constant, then `f` tends to `β` if
and only if `g` tends to `β`. -/
theorem Tendsto.num_atTop_iff_den_atTop {Ξ± K : Type*}
[Field K] [LinearOrder K] [IsStrictOrderedRing K] [TopologicalSpace K]
[OrderTopology K] [ContinuousInv K] {f g : Ξ± β K} {l : Filter Ξ±} {a : K} (ha : 0 < a)
(hlim : Tendsto (fun x => f x / g x) l (π a)) :
Tendsto f l atTop β Tendsto g l atTop :=
β¨fun hf β¦ Tendsto.den hf ha hlim, fun hg β¦ Tendsto.num hg ha hlimβ©
/-! ### Powers -/
theorem tendsto_add_one_pow_atTop_atTop_of_pos
[Semiring Ξ±] [LinearOrder Ξ±] [IsStrictOrderedRing Ξ±] [Archimedean Ξ±] {r : Ξ±}
(h : 0 < r) : Tendsto (fun n : β β¦ (r + 1) ^ n) atTop atTop :=
tendsto_atTop_atTop_of_monotone' (pow_right_monoβ <| le_add_of_nonneg_left h.le) <|
not_bddAbove_iff.2 fun _ β¦ Set.exists_range_iff.2 <| add_one_pow_unbounded_of_pos _ h
theorem tendsto_pow_atTop_atTop_of_one_lt
[Ring Ξ±] [LinearOrder Ξ±] [IsStrictOrderedRing Ξ±] [Archimedean Ξ±] {r : Ξ±}
(h : 1 < r) : Tendsto (fun n : β β¦ r ^ n) atTop atTop :=
sub_add_cancel r 1 βΈ tendsto_add_one_pow_atTop_atTop_of_pos (sub_pos.2 h)
theorem Nat.tendsto_pow_atTop_atTop_of_one_lt {m : β} (h : 1 < m) :
Tendsto (fun n : β β¦ m ^ n) atTop atTop :=
tsub_add_cancel_of_le (le_of_lt h) βΈ tendsto_add_one_pow_atTop_atTop_of_pos (tsub_pos_of_lt h)
theorem tendsto_pow_atTop_nhds_zero_of_lt_one {π : Type*}
[Field π] [LinearOrder π] [IsStrictOrderedRing π] [Archimedean π]
[TopologicalSpace π] [OrderTopology π] {r : π} (hβ : 0 β€ r) (hβ : r < 1) :
Tendsto (fun n : β β¦ r ^ n) atTop (π 0) :=
hβ.eq_or_lt.elim
(fun hr β¦ (tendsto_add_atTop_iff_nat 1).mp <| by
simp [_root_.pow_succ, β hr, tendsto_const_nhds])
(fun hr β¦
have := (one_lt_invβ hr).2 hβ |> tendsto_pow_atTop_atTop_of_one_lt
(tendsto_inv_atTop_zero.comp this).congr fun n β¦ by simp)
@[simp] theorem tendsto_pow_atTop_nhds_zero_iff {π : Type*}
[Field π] [LinearOrder π] [IsStrictOrderedRing π] [Archimedean π]
[TopologicalSpace π] [OrderTopology π] {r : π} :
Tendsto (fun n : β β¦ r ^ n) atTop (π 0) β |r| < 1 := by
rw [tendsto_zero_iff_abs_tendsto_zero]
refine β¨fun h β¦ by_contra (fun hr_le β¦ ?_), fun h β¦ ?_β©
Β· by_cases hr : 1 = |r|
Β· replace h : Tendsto (fun n : β β¦ |r|^n) atTop (π 0) := by simpa only [β abs_pow, h]
simp only [hr.symm, one_pow] at h
exact zero_ne_one <| tendsto_nhds_unique h tendsto_const_nhds
Β· apply @not_tendsto_nhds_of_tendsto_atTop π β _ _ _ _ atTop _ (fun n β¦ |r| ^ n) _ 0 _
Β· refine (pow_right_strictMonoβ <| lt_of_le_of_ne (le_of_not_lt hr_le)
hr).monotone.tendsto_atTop_atTop (fun b β¦ ?_)
obtain β¨n, hnβ© := (pow_unbounded_of_one_lt b (lt_of_le_of_ne (le_of_not_lt hr_le) hr))
exact β¨n, le_of_lt hnβ©
Β· simpa only [β abs_pow]
Β· simpa only [β abs_pow] using (tendsto_pow_atTop_nhds_zero_of_lt_one (abs_nonneg r)) h
theorem tendsto_pow_atTop_nhdsWithin_zero_of_lt_one {π : Type*}
[Field π] [LinearOrder π] [IsStrictOrderedRing π]
[Archimedean π] [TopologicalSpace π] [OrderTopology π] {r : π} (hβ : 0 < r) (hβ : r < 1) :
Tendsto (fun n : β β¦ r ^ n) atTop (π[>] 0) :=
tendsto_inf.2
β¨tendsto_pow_atTop_nhds_zero_of_lt_one hβ.le hβ,
tendsto_principal.2 <| Eventually.of_forall fun _ β¦ pow_pos hβ _β©
theorem uniformity_basis_dist_pow_of_lt_one {Ξ± : Type*} [PseudoMetricSpace Ξ±] {r : β} (hβ : 0 < r)
(hβ : r < 1) :
(uniformity Ξ±).HasBasis (fun _ : β β¦ True) fun k β¦ { p : Ξ± Γ Ξ± | dist p.1 p.2 < r ^ k } :=
Metric.mk_uniformity_basis (fun _ _ β¦ pow_pos hβ _) fun _ Ξ΅0 β¦
(exists_pow_lt_of_lt_one Ξ΅0 hβ).imp fun _ hk β¦ β¨trivial, hk.leβ©
theorem geom_lt {u : β β β} {c : β} (hc : 0 β€ c) {n : β} (hn : 0 < n)
(h : β k < n, c * u k < u (k + 1)) : c ^ n * u 0 < u n := by
apply (monotone_mul_left_of_nonneg hc).seq_pos_lt_seq_of_le_of_lt hn _ _ h
Β· simp
Β· simp [_root_.pow_succ', mul_assoc, le_refl]
theorem geom_le {u : β β β} {c : β} (hc : 0 β€ c) (n : β) (h : β k < n, c * u k β€ u (k + 1)) :
c ^ n * u 0 β€ u n := by
apply (monotone_mul_left_of_nonneg hc).seq_le_seq n _ _ h <;>
simp [_root_.pow_succ', mul_assoc, le_refl]
theorem lt_geom {u : β β β} {c : β} (hc : 0 β€ c) {n : β} (hn : 0 < n)
(h : β k < n, u (k + 1) < c * u k) : u n < c ^ n * u 0 := by
apply (monotone_mul_left_of_nonneg hc).seq_pos_lt_seq_of_lt_of_le hn _ h _
Β· simp
Β· simp [_root_.pow_succ', mul_assoc, le_refl]
theorem le_geom {u : β β β} {c : β} (hc : 0 β€ c) (n : β) (h : β k < n, u (k + 1) β€ c * u k) :
u n β€ c ^ n * u 0 := by
apply (monotone_mul_left_of_nonneg hc).seq_le_seq n _ h _ <;>
simp [_root_.pow_succ', mul_assoc, le_refl]
/-- If a sequence `v` of real numbers satisfies `k * v n β€ v (n+1)` with `1 < k`,
then it goes to +β. -/
theorem tendsto_atTop_of_geom_le {v : β β β} {c : β} (hβ : 0 < v 0) (hc : 1 < c)
(hu : β n, c * v n β€ v (n + 1)) : Tendsto v atTop atTop :=
(tendsto_atTop_mono fun n β¦ geom_le (zero_le_one.trans hc.le) n fun k _ β¦ hu k) <|
(tendsto_pow_atTop_atTop_of_one_lt hc).atTop_mul_const hβ
theorem NNReal.tendsto_pow_atTop_nhds_zero_of_lt_one {r : ββ₯0} (hr : r < 1) :
Tendsto (fun n : β β¦ r ^ n) atTop (π 0) :=
NNReal.tendsto_coe.1 <| by
simp only [NNReal.coe_pow, NNReal.coe_zero,
_root_.tendsto_pow_atTop_nhds_zero_of_lt_one r.coe_nonneg hr]
@[simp]
protected theorem NNReal.tendsto_pow_atTop_nhds_zero_iff {r : ββ₯0} :
Tendsto (fun n : β => r ^ n) atTop (π 0) β r < 1 :=
β¨fun h => by simpa [coe_pow, coe_zero, abs_eq, coe_lt_one, val_eq_coe] using
tendsto_pow_atTop_nhds_zero_iff.mp <| tendsto_coe.mpr h, tendsto_pow_atTop_nhds_zero_of_lt_oneβ©
theorem ENNReal.tendsto_pow_atTop_nhds_zero_of_lt_one {r : ββ₯0β} (hr : r < 1) :
Tendsto (fun n : β β¦ r ^ n) atTop (π 0) := by
rcases ENNReal.lt_iff_exists_coe.1 hr with β¨r, rfl, hr'β©
rw [β ENNReal.coe_zero]
norm_cast at *
apply NNReal.tendsto_pow_atTop_nhds_zero_of_lt_one hr
@[simp]
protected theorem ENNReal.tendsto_pow_atTop_nhds_zero_iff {r : ββ₯0β} :
Tendsto (fun n : β => r ^ n) atTop (π 0) β r < 1 := by
refine β¨fun h β¦ ?_, tendsto_pow_atTop_nhds_zero_of_lt_oneβ©
lift r to NNReal
Β· refine fun hr β¦ top_ne_zero (tendsto_nhds_unique (EventuallyEq.tendsto ?_) (hr βΈ h))
exact eventually_atTop.mpr β¨1, fun _ hn β¦ pow_eq_top_iff.mpr β¨rfl, Nat.pos_iff_ne_zero.mp hnβ©β©
rw [β coe_zero] at h
norm_cast at h β’
exact NNReal.tendsto_pow_atTop_nhds_zero_iff.mp h
@[simp]
protected theorem ENNReal.tendsto_pow_atTop_nhds_top_iff {r : ββ₯0β} :
Tendsto (fun n β¦ r^n) atTop (π β) β 1 < r := by
refine β¨?_, ?_β©
Β· contrapose!
intro r_le_one h_tends
specialize h_tends (Ioi_mem_nhds one_lt_top)
simp only [Filter.mem_map, mem_atTop_sets, ge_iff_le, Set.mem_preimage, Set.mem_Ioi] at h_tends
obtain β¨n, hnβ© := h_tends
exact lt_irrefl _ <| lt_of_lt_of_le (hn n le_rfl) <| pow_le_oneβ (zero_le _) r_le_one
Β· intro r_gt_one
have obs := @Tendsto.inv ββ₯0β β _ _ _ (fun n β¦ (rβ»ΒΉ)^n) atTop 0
simp only [ENNReal.tendsto_pow_atTop_nhds_zero_iff, inv_zero] at obs
simpa [β ENNReal.inv_pow] using obs <| ENNReal.inv_lt_one.mpr r_gt_one
lemma ENNReal.eq_zero_of_le_mul_pow {x r : ββ₯0β} {Ξ΅ : ββ₯0} (hr : r < 1)
(h : β n : β, x β€ Ξ΅ * r ^ n) : x = 0 := by
rw [β nonpos_iff_eq_zero]
refine ge_of_tendsto' (f := fun (n : β) β¦ Ξ΅ * r ^ n) (x := atTop) ?_ h
rw [β mul_zero (Mβ := ββ₯0β) (a := Ξ΅)]
exact Tendsto.const_mul (tendsto_pow_atTop_nhds_zero_of_lt_one hr) (Or.inr coe_ne_top)
/-! ### Geometric series -/
section Geometric
theorem hasSum_geometric_of_lt_one {r : β} (hβ : 0 β€ r) (hβ : r < 1) :
HasSum (fun n : β β¦ r ^ n) (1 - r)β»ΒΉ :=
have : r β 1 := ne_of_lt hβ
have : Tendsto (fun n β¦ (r ^ n - 1) * (r - 1)β»ΒΉ) atTop (π ((0 - 1) * (r - 1)β»ΒΉ)) :=
((tendsto_pow_atTop_nhds_zero_of_lt_one hβ hβ).sub tendsto_const_nhds).mul tendsto_const_nhds
(hasSum_iff_tendsto_nat_of_nonneg (pow_nonneg hβ) _).mpr <| by
simp_all [neg_inv, geom_sum_eq, div_eq_mul_inv]
theorem summable_geometric_of_lt_one {r : β} (hβ : 0 β€ r) (hβ : r < 1) :
Summable fun n : β β¦ r ^ n :=
β¨_, hasSum_geometric_of_lt_one hβ hββ©
theorem tsum_geometric_of_lt_one {r : β} (hβ : 0 β€ r) (hβ : r < 1) : β' n : β, r ^ n = (1 - r)β»ΒΉ :=
(hasSum_geometric_of_lt_one hβ hβ).tsum_eq
theorem hasSum_geometric_two : HasSum (fun n : β β¦ ((1 : β) / 2) ^ n) 2 := by
convert hasSum_geometric_of_lt_one _ _ <;> norm_num
theorem summable_geometric_two : Summable fun n : β β¦ ((1 : β) / 2) ^ n :=
β¨_, hasSum_geometric_twoβ©
theorem summable_geometric_two_encode {ΞΉ : Type*} [Encodable ΞΉ] :
Summable fun i : ΞΉ β¦ (1 / 2 : β) ^ Encodable.encode i :=
summable_geometric_two.comp_injective Encodable.encode_injective
theorem tsum_geometric_two : (β' n : β, ((1 : β) / 2) ^ n) = 2 :=
hasSum_geometric_two.tsum_eq
theorem sum_geometric_two_le (n : β) : (β i β range n, (1 / (2 : β)) ^ i) β€ 2 := by
have : β i, 0 β€ (1 / (2 : β)) ^ i := by
intro i
apply pow_nonneg
norm_num
convert summable_geometric_two.sum_le_tsum (range n) (fun i _ β¦ this i)
exact tsum_geometric_two.symm
| theorem tsum_geometric_inv_two : (β' n : β, (2 : β)β»ΒΉ ^ n) = 2 :=
(inv_eq_one_div (2 : β)).symm βΈ tsum_geometric_two
/-- The sum of `2β»ΒΉ ^ i` for `n β€ i` equals `2 * 2β»ΒΉ ^ n`. -/
theorem tsum_geometric_inv_two_ge (n : β) :
(β' i, ite (n β€ i) ((2 : β)β»ΒΉ ^ i) 0) = 2 * 2β»ΒΉ ^ n := by
have A : Summable fun i : β β¦ ite (n β€ i) ((2β»ΒΉ : β) ^ i) 0 := by
| Mathlib/Analysis/SpecificLimits/Basic.lean | 329 | 335 |
/-
Copyright (c) 2022 Bolton Bailey. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Bolton Bailey, Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle SΓΆnne
-/
import Mathlib.Algebra.BigOperators.Field
import Mathlib.Analysis.SpecialFunctions.Pow.Real
import Mathlib.Data.Int.Log
/-!
# Real logarithm base `b`
In this file we define `Real.logb` to be the logarithm of a real number in a given base `b`. We
define this as the division of the natural logarithms of the argument and the base, so that we have
a globally defined function with `logb b 0 = 0`, `logb b (-x) = logb b x` `logb 0 x = 0` and
`logb (-b) x = logb b x`.
We prove some basic properties of this function and its relation to `rpow`.
## Tags
logarithm, continuity
-/
open Set Filter Function
open Topology
noncomputable section
namespace Real
variable {b x y : β}
/-- The real logarithm in a given base. As with the natural logarithm, we define `logb b x` to
be `logb b |x|` for `x < 0`, and `0` for `x = 0`. -/
@[pp_nodot]
noncomputable def logb (b x : β) : β :=
log x / log b
theorem log_div_log : log x / log b = logb b x :=
rfl
@[simp]
theorem logb_zero : logb b 0 = 0 := by simp [logb]
@[simp]
theorem logb_one : logb b 1 = 0 := by simp [logb]
theorem logb_zero_left : logb 0 x = 0 := by simp only [β log_div_log, log_zero, div_zero]
@[simp] theorem logb_zero_left_eq_zero : logb 0 = 0 := by ext; rw [logb_zero_left, Pi.zero_apply]
theorem logb_one_left : logb 1 x = 0 := by simp only [β log_div_log, log_one, div_zero]
@[simp] theorem logb_one_left_eq_zero : logb 1 = 0 := by ext; rw [logb_one_left, Pi.zero_apply]
@[simp]
lemma logb_self_eq_one (hb : 1 < b) : logb b b = 1 :=
div_self (log_pos hb).ne'
lemma logb_self_eq_one_iff : logb b b = 1 β b β 0 β§ b β 1 β§ b β -1 :=
Iff.trans β¨fun h h' => by simp [logb, h'] at h, div_selfβ© log_ne_zero
@[simp]
theorem logb_abs (x : β) : logb b |x| = logb b x := by rw [logb, logb, log_abs]
@[simp]
theorem logb_neg_eq_logb (x : β) : logb b (-x) = logb b x := by
rw [β logb_abs x, β logb_abs (-x), abs_neg]
theorem logb_mul (hx : x β 0) (hy : y β 0) : logb b (x * y) = logb b x + logb b y := by
simp_rw [logb, log_mul hx hy, add_div]
theorem logb_div (hx : x β 0) (hy : y β 0) : logb b (x / y) = logb b x - logb b y := by
simp_rw [logb, log_div hx hy, sub_div]
@[simp]
theorem logb_inv (x : β) : logb b xβ»ΒΉ = -logb b x := by simp [logb, neg_div]
theorem inv_logb (a b : β) : (logb a b)β»ΒΉ = logb b a := by simp_rw [logb, inv_div]
theorem inv_logb_mul_base {a b : β} (hβ : a β 0) (hβ : b β 0) (c : β) :
(logb (a * b) c)β»ΒΉ = (logb a c)β»ΒΉ + (logb b c)β»ΒΉ := by
simp_rw [inv_logb]; exact logb_mul hβ hβ
theorem inv_logb_div_base {a b : β} (hβ : a β 0) (hβ : b β 0) (c : β) :
(logb (a / b) c)β»ΒΉ = (logb a c)β»ΒΉ - (logb b c)β»ΒΉ := by
simp_rw [inv_logb]; exact logb_div hβ hβ
theorem logb_mul_base {a b : β} (hβ : a β 0) (hβ : b β 0) (c : β) :
logb (a * b) c = ((logb a c)β»ΒΉ + (logb b c)β»ΒΉ)β»ΒΉ := by rw [β inv_logb_mul_base hβ hβ c, inv_inv]
theorem logb_div_base {a b : β} (hβ : a β 0) (hβ : b β 0) (c : β) :
logb (a / b) c = ((logb a c)β»ΒΉ - (logb b c)β»ΒΉ)β»ΒΉ := by rw [β inv_logb_div_base hβ hβ c, inv_inv]
theorem mul_logb {a b c : β} (hβ : b β 0) (hβ : b β 1) (hβ : b β -1) :
logb a b * logb b c = logb a c := by
unfold logb
rw [mul_comm, div_mul_div_cancelβ (log_ne_zero.mpr β¨hβ, hβ, hββ©)]
theorem div_logb {a b c : β} (hβ : c β 0) (hβ : c β 1) (hβ : c β -1) :
logb a c / logb b c = logb a b :=
div_div_div_cancel_left' _ _ <| log_ne_zero.mpr β¨hβ, hβ, hββ©
theorem logb_rpow_eq_mul_logb_of_pos (hx : 0 < x) : logb b (x ^ y) = y * logb b x := by
rw [logb, log_rpow hx, logb, mul_div_assoc]
theorem logb_pow (b x : β) (k : β) : logb b (x ^ k) = k * logb b x := by
rw [logb, logb, log_pow, mul_div_assoc]
section BPosAndNeOne
variable (b_pos : 0 < b) (b_ne_one : b β 1)
include b_pos b_ne_one
private theorem log_b_ne_zero : log b β 0 := by
have b_ne_zero : b β 0 := by linarith
have b_ne_minus_one : b β -1 := by linarith
simp [b_ne_one, b_ne_zero, b_ne_minus_one]
@[simp]
theorem logb_rpow : logb b (b ^ x) = x := by
rw [logb, div_eq_iff, log_rpow b_pos]
exact log_b_ne_zero b_pos b_ne_one
theorem rpow_logb_eq_abs (hx : x β 0) : b ^ logb b x = |x| := by
apply log_injOn_pos
Β· simp only [Set.mem_Ioi]
apply rpow_pos_of_pos b_pos
Β· simp only [abs_pos, mem_Ioi, Ne, hx, not_false_iff]
rw [log_rpow b_pos, logb, log_abs]
field_simp [log_b_ne_zero b_pos b_ne_one]
@[simp]
theorem rpow_logb (hx : 0 < x) : b ^ logb b x = x := by
rw [rpow_logb_eq_abs b_pos b_ne_one hx.ne']
exact abs_of_pos hx
theorem rpow_logb_of_neg (hx : x < 0) : b ^ logb b x = -x := by
rw [rpow_logb_eq_abs b_pos b_ne_one (ne_of_lt hx)]
exact abs_of_neg hx
theorem logb_eq_iff_rpow_eq (hy : 0 < y) : logb b y = x β b ^ x = y := by
constructor <;> rintro rfl
Β· exact rpow_logb b_pos b_ne_one hy
Β· exact logb_rpow b_pos b_ne_one
theorem surjOn_logb : SurjOn (logb b) (Ioi 0) univ := fun x _ =>
β¨b ^ x, rpow_pos_of_pos b_pos x, logb_rpow b_pos b_ne_oneβ©
theorem logb_surjective : Surjective (logb b) := fun x => β¨b ^ x, logb_rpow b_pos b_ne_oneβ©
@[simp]
theorem range_logb : range (logb b) = univ :=
(logb_surjective b_pos b_ne_one).range_eq
theorem surjOn_logb' : SurjOn (logb b) (Iio 0) univ := by
intro x _
use -b ^ x
constructor
Β· simp only [Right.neg_neg_iff, Set.mem_Iio]
apply rpow_pos_of_pos b_pos
Β· rw [logb_neg_eq_logb, logb_rpow b_pos b_ne_one]
end BPosAndNeOne
section OneLtB
variable (hb : 1 < b)
include hb
| private theorem b_pos : 0 < b := by linarith
-- Name has a prime added to avoid clashing with `b_ne_one` further down the file
private theorem b_ne_one' : b β 1 := by linarith
@[simp]
theorem logb_le_logb (h : 0 < x) (hβ : 0 < y) : logb b x β€ logb b y β x β€ y := by
| Mathlib/Analysis/SpecialFunctions/Log/Base.lean | 174 | 180 |
/-
Copyright (c) 2023 Adam Topaz. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Adam Topaz
-/
import Mathlib.CategoryTheory.Limits.Shapes.Products
/-!
# Effective epimorphisms
We define the notion of effective epimorphism and effective epimorphic family of morphisms.
A morphism is an *effective epi* if it is a joint coequalizer of all pairs of
morphisms which it coequalizes.
A family of morphisms with fixed target is *effective epimorphic* if it is initial among families
of morphisms with its sources and a general fixed target, coequalizing every pair of morphisms it
coequalizes (here, the pair of morphisms coequalized can have different targets among the sources
of the family).
We have defined the notion of effective epi for morphisms and families of morphisms in such a
way that avoids requiring the existence of pullbacks. However, if the relevant pullbacks exist
then these definitions are equivalent, see the file
`CategoryTheory/EffectiveEpi/RegularEpi.lean`
See [nlab: *Effective Epimorphism*](https://ncatlab.org/nlab/show/effective+epimorphism) and
[Stacks 00WP](https://stacks.math.columbia.edu/tag/00WP) for the standard definitions. Note that
our notion of `EffectiveEpi` is often called "strict epi" in the literature.
## References
- [Elephant]: *Sketches of an Elephant*, P. T. Johnstone: C2.1, Example 2.1.12.
- [nlab: *Effective Epimorphism*](https://ncatlab.org/nlab/show/effective+epimorphism) and
- [Stacks 00WP](https://stacks.math.columbia.edu/tag/00WP) for the standard definitions.
-/
namespace CategoryTheory
open Limits
variable {C : Type*} [Category C]
/--
This structure encodes the data required for a morphism to be an effective epimorphism.
-/
structure EffectiveEpiStruct {X Y : C} (f : Y βΆ X) where
/--
For every `W` with a morphism `e : Y βΆ W` that coequalizes every pair of morphisms
`gβ gβ : Z βΆ Y` which `f` coequalizes, `desc e h` is a morphism `X βΆ W`...
-/
desc : β {W : C} (e : Y βΆ W),
(β {Z : C} (gβ gβ : Z βΆ Y), gβ β« f = gβ β« f β gβ β« e = gβ β« e) β (X βΆ W)
/-- ...factorizing `e` through `f`... -/
fac : β {W : C} (e : Y βΆ W)
(h : β {Z : C} (gβ gβ : Z βΆ Y), gβ β« f = gβ β« f β gβ β« e = gβ β« e),
f β« desc e h = e
/-- ...and as such, unique. -/
uniq : β {W : C} (e : Y βΆ W)
(h : β {Z : C} (gβ gβ : Z βΆ Y), gβ β« f = gβ β« f β gβ β« e = gβ β« e)
(m : X βΆ W), f β« m = e β m = desc e h
/--
A morphism `f : Y βΆ X` is an effective epimorphism provided that `f` exhibits `X` as a colimit
of the diagram of all "relations" `R β Y`.
If `f` has a kernel pair, then this is equivalent to showing that the corresponding cofork is
a colimit.
-/
class EffectiveEpi {X Y : C} (f : Y βΆ X) : Prop where
/-- `f` is an effective epimorphism if there exists an `EffectiveEpiStruct` for `f`. -/
effectiveEpi : Nonempty (EffectiveEpiStruct f)
/-- Some chosen `EffectiveEpiStruct` associated to an effective epi. -/
noncomputable
def EffectiveEpi.getStruct {X Y : C} (f : Y βΆ X) [EffectiveEpi f] : EffectiveEpiStruct f :=
EffectiveEpi.effectiveEpi.some
/-- Descend along an effective epi. -/
noncomputable
def EffectiveEpi.desc {X Y W : C} (f : Y βΆ X) [EffectiveEpi f]
(e : Y βΆ W) (h : β {Z : C} (gβ gβ : Z βΆ Y), gβ β« f = gβ β« f β gβ β« e = gβ β« e) :
X βΆ W := (EffectiveEpi.getStruct f).desc e h
@[reassoc (attr := simp)]
lemma EffectiveEpi.fac {X Y W : C} (f : Y βΆ X) [EffectiveEpi f]
(e : Y βΆ W) (h : β {Z : C} (gβ gβ : Z βΆ Y), gβ β« f = gβ β« f β gβ β« e = gβ β« e) :
f β« EffectiveEpi.desc f e h = e :=
(EffectiveEpi.getStruct f).fac e h
lemma EffectiveEpi.uniq {X Y W : C} (f : Y βΆ X) [EffectiveEpi f]
(e : Y βΆ W) (h : β {Z : C} (gβ gβ : Z βΆ Y), gβ β« f = gβ β« f β gβ β« e = gβ β« e)
(m : X βΆ W) (hm : f β« m = e) :
m = EffectiveEpi.desc f e h :=
(EffectiveEpi.getStruct f).uniq e h _ hm
instance epiOfEffectiveEpi {X Y : C} (f : Y βΆ X) [EffectiveEpi f] : Epi f := by
constructor
intro W mβ mβ h
have : mβ = EffectiveEpi.desc f (f β« mβ)
(fun {Z} gβ gβ h => by simp only [β Category.assoc, h]) := EffectiveEpi.uniq _ _ _ _ rfl
rw [this]
exact EffectiveEpi.uniq _ _ _ _ h
/--
This structure encodes the data required for a family of morphisms to be effective epimorphic.
-/
structure EffectiveEpiFamilyStruct {B : C} {Ξ± : Type*}
(X : Ξ± β C) (Ο : (a : Ξ±) β (X a βΆ B)) where
/--
For every `W` with a family of morphisms `e a : Y a βΆ W` that coequalizes every pair of morphisms
`gβ : Z βΆ Y aβ`, `gβ : Z βΆ Y aβ` which the family `Ο` coequalizes, `desc e h` is a morphism
`X βΆ W`...
-/
desc : β {W} (e : (a : Ξ±) β (X a βΆ W)),
(β {Z : C} (aβ aβ : Ξ±) (gβ : Z βΆ X aβ) (gβ : Z βΆ X aβ),
gβ β« Ο _ = gβ β« Ο _ β gβ β« e _ = gβ β« e _) β (B βΆ W)
/-- ...factorizing the components of `e` through the components of `Ο`... -/
fac : β {W} (e : (a : Ξ±) β (X a βΆ W))
(h : β {Z : C} (aβ aβ : Ξ±) (gβ : Z βΆ X aβ) (gβ : Z βΆ X aβ),
gβ β« Ο _ = gβ β« Ο _ β gβ β« e _ = gβ β« e _)
(a : Ξ±), Ο a β« desc e h = e a
/-- ...and as such, unique. -/
uniq : β {W} (e : (a : Ξ±) β (X a βΆ W))
(h : β {Z : C} (aβ aβ : Ξ±) (gβ : Z βΆ X aβ) (gβ : Z βΆ X aβ),
gβ β« Ο _ = gβ β« Ο _ β gβ β« e _ = gβ β« e _)
(m : B βΆ W), (β (a : Ξ±), Ο a β« m = e a) β m = desc e h
/--
A family of morphisms `Ο a : X a βΆ B` indexed by `Ξ±` is effective epimorphic
provided that the `Ο a` exhibit `B` as a colimit of the diagram of all "relations"
`R β X aβ`, `R βΆ X aβ` for all `aβ aβ : Ξ±`.
-/
class EffectiveEpiFamily {B : C} {Ξ± : Type*} (X : Ξ± β C) (Ο : (a : Ξ±) β (X a βΆ B)) : Prop where
/-- `Ο` is an effective epimorphic family if there exists an `EffectiveEpiFamilyStruct` for `Ο` -/
effectiveEpiFamily : Nonempty (EffectiveEpiFamilyStruct X Ο)
/-- Some chosen `EffectiveEpiFamilyStruct` associated to an effective epi family. -/
noncomputable
def EffectiveEpiFamily.getStruct {B : C} {Ξ± : Type*} (X : Ξ± β C) (Ο : (a : Ξ±) β (X a βΆ B))
[EffectiveEpiFamily X Ο] : EffectiveEpiFamilyStruct X Ο :=
EffectiveEpiFamily.effectiveEpiFamily.some
/-- Descend along an effective epi family. -/
noncomputable
def EffectiveEpiFamily.desc {B W : C} {Ξ± : Type*} (X : Ξ± β C) (Ο : (a : Ξ±) β (X a βΆ B))
[EffectiveEpiFamily X Ο] (e : (a : Ξ±) β (X a βΆ W))
(h : β {Z : C} (aβ aβ : Ξ±) (gβ : Z βΆ X aβ) (gβ : Z βΆ X aβ),
gβ β« Ο _ = gβ β« Ο _ β gβ β« e _ = gβ β« e _) : B βΆ W :=
(EffectiveEpiFamily.getStruct X Ο).desc e h
@[reassoc (attr := simp)]
lemma EffectiveEpiFamily.fac {B W : C} {Ξ± : Type*} (X : Ξ± β C) (Ο : (a : Ξ±) β (X a βΆ B))
[EffectiveEpiFamily X Ο] (e : (a : Ξ±) β (X a βΆ W))
(h : β {Z : C} (aβ aβ : Ξ±) (gβ : Z βΆ X aβ) (gβ : Z βΆ X aβ),
gβ β« Ο _ = gβ β« Ο _ β gβ β« e _ = gβ β« e _) (a : Ξ±) :
Ο a β« EffectiveEpiFamily.desc X Ο e h = e a :=
(EffectiveEpiFamily.getStruct X Ο).fac e h a
lemma EffectiveEpiFamily.uniq {B W : C} {Ξ± : Type*} (X : Ξ± β C) (Ο : (a : Ξ±) β (X a βΆ B))
[EffectiveEpiFamily X Ο] (e : (a : Ξ±) β (X a βΆ W))
(h : β {Z : C} (aβ aβ : Ξ±) (gβ : Z βΆ X aβ) (gβ : Z βΆ X aβ),
gβ β« Ο _ = gβ β« Ο _ β gβ β« e _ = gβ β« e _)
(m : B βΆ W) (hm : β a, Ο a β« m = e a) :
m = EffectiveEpiFamily.desc X Ο e h :=
(EffectiveEpiFamily.getStruct X Ο).uniq e h m hm
-- TODO: Once we have "jointly epimorphic families", we could rephrase this as such a property.
| lemma EffectiveEpiFamily.hom_ext {B W : C} {Ξ± : Type*} (X : Ξ± β C) (Ο : (a : Ξ±) β (X a βΆ B))
[EffectiveEpiFamily X Ο] (mβ mβ : B βΆ W) (h : β a, Ο a β« mβ = Ο a β« mβ) :
mβ = mβ := by
have : mβ = EffectiveEpiFamily.desc X Ο (fun a => Ο a β« mβ)
(fun aβ aβ gβ gβ h => by simp only [β Category.assoc, h]) := by
apply EffectiveEpiFamily.uniq; intro; rfl
rw [this]
exact EffectiveEpiFamily.uniq _ _ _ _ _ h
| Mathlib/CategoryTheory/EffectiveEpi/Basic.lean | 166 | 173 |
/-
Copyright (c) 2023 Dagur Asgeirsson. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Dagur Asgeirsson
-/
import Mathlib.Topology.Category.Profinite.Nobeling.Basic
import Mathlib.Topology.Category.Profinite.Nobeling.Induction
import Mathlib.Topology.Category.Profinite.Nobeling.Span
import Mathlib.Topology.Category.Profinite.Nobeling.Successor
import Mathlib.Topology.Category.Profinite.Nobeling.ZeroLimit
deprecated_module (since := "2025-04-13")
| Mathlib/Topology/Category/Profinite/Nobeling.lean | 787 | 796 | |
/-
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.Subgroup.Pointwise
import Mathlib.Algebra.Order.Archimedean.Basic
import Mathlib.Order.Filter.Bases.Finite
import Mathlib.Topology.Algebra.Group.Defs
import Mathlib.Topology.Algebra.Monoid
import Mathlib.Topology.Homeomorph.Lemmas
/-!
# Topological groups
This file defines the following typeclasses:
* `IsTopologicalGroup`, `IsTopologicalAddGroup`: multiplicative and additive topological groups,
i.e., groups with continuous `(*)` and `(β»ΒΉ)` / `(+)` and `(-)`;
* `ContinuousSub G` means that `G` has a continuous subtraction operation.
There is an instance deducing `ContinuousSub` from `IsTopologicalGroup` but we use a separate
typeclass because, e.g., `β` and `ββ₯0` have continuous subtraction but are not additive groups.
We also define `Homeomorph` versions of several `Equiv`s: `Homeomorph.mulLeft`,
`Homeomorph.mulRight`, `Homeomorph.inv`, and prove a few facts about neighbourhood filters in
groups.
## Tags
topological space, group, topological group
-/
open Set Filter TopologicalSpace Function Topology MulOpposite Pointwise
universe u v w x
variable {G : Type w} {H : Type x} {Ξ± : Type u} {Ξ² : Type v}
section ContinuousMulGroup
/-!
### Groups with continuous multiplication
In this section we prove a few statements about groups with continuous `(*)`.
-/
variable [TopologicalSpace G] [Group G] [ContinuousMul G]
/-- Multiplication from the left in a topological group as a homeomorphism. -/
@[to_additive "Addition from the left in a topological additive group as a homeomorphism."]
protected def Homeomorph.mulLeft (a : G) : G ββ G :=
{ Equiv.mulLeft a with
continuous_toFun := continuous_const.mul continuous_id
continuous_invFun := continuous_const.mul continuous_id }
@[to_additive (attr := simp)]
theorem Homeomorph.coe_mulLeft (a : G) : β(Homeomorph.mulLeft a) = (a * Β·) :=
rfl
@[to_additive]
theorem Homeomorph.mulLeft_symm (a : G) : (Homeomorph.mulLeft a).symm = Homeomorph.mulLeft aβ»ΒΉ := by
ext
rfl
@[to_additive]
lemma isOpenMap_mul_left (a : G) : IsOpenMap (a * Β·) := (Homeomorph.mulLeft a).isOpenMap
@[to_additive IsOpen.left_addCoset]
theorem IsOpen.leftCoset {U : Set G} (h : IsOpen U) (x : G) : IsOpen (x β’ U) :=
isOpenMap_mul_left x _ h
@[to_additive]
lemma isClosedMap_mul_left (a : G) : IsClosedMap (a * Β·) := (Homeomorph.mulLeft a).isClosedMap
@[to_additive IsClosed.left_addCoset]
theorem IsClosed.leftCoset {U : Set G} (h : IsClosed U) (x : G) : IsClosed (x β’ U) :=
isClosedMap_mul_left x _ h
/-- Multiplication from the right in a topological group as a homeomorphism. -/
@[to_additive "Addition from the right in a topological additive group as a homeomorphism."]
protected def Homeomorph.mulRight (a : G) : G ββ G :=
{ Equiv.mulRight a with
continuous_toFun := continuous_id.mul continuous_const
continuous_invFun := continuous_id.mul continuous_const }
@[to_additive (attr := simp)]
lemma Homeomorph.coe_mulRight (a : G) : β(Homeomorph.mulRight a) = (Β· * a) := rfl
@[to_additive]
theorem Homeomorph.mulRight_symm (a : G) :
(Homeomorph.mulRight a).symm = Homeomorph.mulRight aβ»ΒΉ := by
ext
rfl
@[to_additive]
theorem isOpenMap_mul_right (a : G) : IsOpenMap (Β· * a) :=
(Homeomorph.mulRight a).isOpenMap
@[to_additive IsOpen.right_addCoset]
theorem IsOpen.rightCoset {U : Set G} (h : IsOpen U) (x : G) : IsOpen (op x β’ U) :=
isOpenMap_mul_right x _ h
@[to_additive]
theorem isClosedMap_mul_right (a : G) : IsClosedMap (Β· * a) :=
(Homeomorph.mulRight a).isClosedMap
@[to_additive IsClosed.right_addCoset]
theorem IsClosed.rightCoset {U : Set G} (h : IsClosed U) (x : G) : IsClosed (op x β’ U) :=
isClosedMap_mul_right x _ h
@[to_additive]
theorem discreteTopology_of_isOpen_singleton_one (h : IsOpen ({1} : Set G)) :
DiscreteTopology G := by
rw [β singletons_open_iff_discrete]
intro g
suffices {g} = (gβ»ΒΉ * Β·) β»ΒΉ' {1} by
rw [this]
exact (continuous_mul_left gβ»ΒΉ).isOpen_preimage _ h
simp only [mul_one, Set.preimage_mul_left_singleton, eq_self_iff_true, inv_inv,
Set.singleton_eq_singleton_iff]
@[to_additive]
theorem discreteTopology_iff_isOpen_singleton_one : DiscreteTopology G β IsOpen ({1} : Set G) :=
β¨fun h => forall_open_iff_discrete.mpr h {1}, discreteTopology_of_isOpen_singleton_oneβ©
end ContinuousMulGroup
/-!
### `ContinuousInv` and `ContinuousNeg`
-/
section ContinuousInv
variable [TopologicalSpace G] [Inv G] [ContinuousInv G]
@[to_additive]
theorem ContinuousInv.induced {Ξ± : Type*} {Ξ² : Type*} {F : Type*} [FunLike F Ξ± Ξ²] [Group Ξ±]
[DivisionMonoid Ξ²] [MonoidHomClass F Ξ± Ξ²] [tΞ² : TopologicalSpace Ξ²] [ContinuousInv Ξ²] (f : F) :
@ContinuousInv Ξ± (tΞ².induced f) _ := by
let _tΞ± := tΞ².induced f
refine β¨continuous_induced_rng.2 ?_β©
simp only [Function.comp_def, map_inv]
fun_prop
@[to_additive]
protected theorem Specializes.inv {x y : G} (h : x β€³ y) : (xβ»ΒΉ) β€³ (yβ»ΒΉ) :=
h.map continuous_inv
@[to_additive]
protected theorem Inseparable.inv {x y : G} (h : Inseparable x y) : Inseparable (xβ»ΒΉ) (yβ»ΒΉ) :=
h.map continuous_inv
@[to_additive]
protected theorem Specializes.zpow {G : Type*} [DivInvMonoid G] [TopologicalSpace G]
[ContinuousMul G] [ContinuousInv G] {x y : G} (h : x β€³ y) : β m : β€, (x ^ m) β€³ (y ^ m)
| .ofNat n => by simpa using h.pow n
| .negSucc n => by simpa using (h.pow (n + 1)).inv
@[to_additive]
protected theorem Inseparable.zpow {G : Type*} [DivInvMonoid G] [TopologicalSpace G]
[ContinuousMul G] [ContinuousInv G] {x y : G} (h : Inseparable x y) (m : β€) :
Inseparable (x ^ m) (y ^ m) :=
(h.specializes.zpow m).antisymm (h.specializes'.zpow m)
@[to_additive]
instance : ContinuousInv (ULift G) :=
β¨continuous_uliftUp.comp (continuous_inv.comp continuous_uliftDown)β©
@[to_additive]
theorem continuousOn_inv {s : Set G} : ContinuousOn Inv.inv s :=
continuous_inv.continuousOn
@[to_additive]
theorem continuousWithinAt_inv {s : Set G} {x : G} : ContinuousWithinAt Inv.inv s x :=
continuous_inv.continuousWithinAt
@[to_additive]
theorem continuousAt_inv {x : G} : ContinuousAt Inv.inv x :=
continuous_inv.continuousAt
@[to_additive]
theorem tendsto_inv (a : G) : Tendsto Inv.inv (π a) (π aβ»ΒΉ) :=
continuousAt_inv
variable [TopologicalSpace Ξ±] {f : Ξ± β G} {s : Set Ξ±} {x : Ξ±}
@[to_additive]
instance OrderDual.instContinuousInv : ContinuousInv Gα΅α΅ := βΉContinuousInv GβΊ
@[to_additive]
instance Prod.continuousInv [TopologicalSpace H] [Inv H] [ContinuousInv H] :
ContinuousInv (G Γ H) :=
β¨continuous_inv.fst'.prodMk continuous_inv.snd'β©
variable {ΞΉ : Type*}
@[to_additive]
instance Pi.continuousInv {C : ΞΉ β Type*} [β i, TopologicalSpace (C i)] [β i, Inv (C i)]
[β i, ContinuousInv (C i)] : ContinuousInv (β i, C i) where
continuous_inv := continuous_pi fun i => (continuous_apply i).inv
/-- A version of `Pi.continuousInv` for non-dependent functions. It is needed because sometimes
Lean fails to use `Pi.continuousInv` for non-dependent functions. -/
@[to_additive
"A version of `Pi.continuousNeg` for non-dependent functions. It is needed
because sometimes Lean fails to use `Pi.continuousNeg` for non-dependent functions."]
instance Pi.has_continuous_inv' : ContinuousInv (ΞΉ β G) :=
Pi.continuousInv
@[to_additive]
instance (priority := 100) continuousInv_of_discreteTopology [TopologicalSpace H] [Inv H]
[DiscreteTopology H] : ContinuousInv H :=
β¨continuous_of_discreteTopologyβ©
section PointwiseLimits
variable (Gβ Gβ : Type*) [TopologicalSpace Gβ] [T2Space Gβ]
@[to_additive]
theorem isClosed_setOf_map_inv [Inv Gβ] [Inv Gβ] [ContinuousInv Gβ] :
IsClosed { f : Gβ β Gβ | β x, f xβ»ΒΉ = (f x)β»ΒΉ } := by
simp only [setOf_forall]
exact isClosed_iInter fun i => isClosed_eq (continuous_apply _) (continuous_apply _).inv
end PointwiseLimits
instance [TopologicalSpace H] [Inv H] [ContinuousInv H] : ContinuousNeg (Additive H) where
continuous_neg := @continuous_inv H _ _ _
instance [TopologicalSpace H] [Neg H] [ContinuousNeg H] : ContinuousInv (Multiplicative H) where
continuous_inv := @continuous_neg H _ _ _
end ContinuousInv
section ContinuousInvolutiveInv
variable [TopologicalSpace G] [InvolutiveInv G] [ContinuousInv G] {s : Set G}
@[to_additive]
theorem IsCompact.inv (hs : IsCompact s) : IsCompact sβ»ΒΉ := by
rw [β image_inv_eq_inv]
exact hs.image continuous_inv
variable (G)
/-- Inversion in a topological group as a homeomorphism. -/
@[to_additive "Negation in a topological group as a homeomorphism."]
protected def Homeomorph.inv (G : Type*) [TopologicalSpace G] [InvolutiveInv G]
[ContinuousInv G] : G ββ G :=
{ Equiv.inv G with
continuous_toFun := continuous_inv
continuous_invFun := continuous_inv }
@[to_additive (attr := simp)]
lemma Homeomorph.coe_inv {G : Type*} [TopologicalSpace G] [InvolutiveInv G] [ContinuousInv G] :
β(Homeomorph.inv G) = Inv.inv := rfl
@[to_additive]
theorem nhds_inv (a : G) : π aβ»ΒΉ = (π a)β»ΒΉ :=
((Homeomorph.inv G).map_nhds_eq a).symm
@[to_additive]
theorem isOpenMap_inv : IsOpenMap (Inv.inv : G β G) :=
(Homeomorph.inv _).isOpenMap
@[to_additive]
theorem isClosedMap_inv : IsClosedMap (Inv.inv : G β G) :=
(Homeomorph.inv _).isClosedMap
variable {G}
@[to_additive]
theorem IsOpen.inv (hs : IsOpen s) : IsOpen sβ»ΒΉ :=
hs.preimage continuous_inv
@[to_additive]
theorem IsClosed.inv (hs : IsClosed s) : IsClosed sβ»ΒΉ :=
hs.preimage continuous_inv
@[to_additive]
theorem inv_closure : β s : Set G, (closure s)β»ΒΉ = closure sβ»ΒΉ :=
(Homeomorph.inv G).preimage_closure
variable [TopologicalSpace Ξ±] {f : Ξ± β G} {s : Set Ξ±} {x : Ξ±}
@[to_additive (attr := simp)]
lemma continuous_inv_iff : Continuous fβ»ΒΉ β Continuous f := (Homeomorph.inv G).comp_continuous_iff
@[to_additive (attr := simp)]
lemma continuousAt_inv_iff : ContinuousAt fβ»ΒΉ x β ContinuousAt f x :=
(Homeomorph.inv G).comp_continuousAt_iff _ _
@[to_additive (attr := simp)]
lemma continuousOn_inv_iff : ContinuousOn fβ»ΒΉ s β ContinuousOn f s :=
(Homeomorph.inv G).comp_continuousOn_iff _ _
@[to_additive] alias β¨Continuous.of_inv, _β© := continuous_inv_iff
@[to_additive] alias β¨ContinuousAt.of_inv, _β© := continuousAt_inv_iff
@[to_additive] alias β¨ContinuousOn.of_inv, _β© := continuousOn_inv_iff
end ContinuousInvolutiveInv
section LatticeOps
variable {ΞΉ' : Sort*} [Inv G]
@[to_additive]
theorem continuousInv_sInf {ts : Set (TopologicalSpace G)}
(h : β t β ts, @ContinuousInv G t _) : @ContinuousInv G (sInf ts) _ :=
letI := sInf ts
{ continuous_inv :=
continuous_sInf_rng.2 fun t ht =>
continuous_sInf_dom ht (@ContinuousInv.continuous_inv G t _ (h t ht)) }
@[to_additive]
theorem continuousInv_iInf {ts' : ΞΉ' β TopologicalSpace G}
(h' : β i, @ContinuousInv G (ts' i) _) : @ContinuousInv G (β¨
i, ts' i) _ := by
rw [β sInf_range]
exact continuousInv_sInf (Set.forall_mem_range.mpr h')
@[to_additive]
theorem continuousInv_inf {tβ tβ : TopologicalSpace G} (hβ : @ContinuousInv G tβ _)
(hβ : @ContinuousInv G tβ _) : @ContinuousInv G (tβ β tβ) _ := by
rw [inf_eq_iInf]
refine continuousInv_iInf fun b => ?_
cases b <;> assumption
end LatticeOps
@[to_additive]
theorem Topology.IsInducing.continuousInv {G H : Type*} [Inv G] [Inv H] [TopologicalSpace G]
[TopologicalSpace H] [ContinuousInv H] {f : G β H} (hf : IsInducing f)
(hf_inv : β x, f xβ»ΒΉ = (f x)β»ΒΉ) : ContinuousInv G :=
β¨hf.continuous_iff.2 <| by simpa only [Function.comp_def, hf_inv] using hf.continuous.invβ©
@[deprecated (since := "2024-10-28")] alias Inducing.continuousInv := IsInducing.continuousInv
section IsTopologicalGroup
/-!
### Topological groups
A topological group is a group in which the multiplication and inversion operations are
continuous. Topological additive groups are defined in the same way. Equivalently, we can require
that the division operation `x y β¦ x * yβ»ΒΉ` (resp., subtraction) is continuous.
-/
section Conj
instance ConjAct.units_continuousConstSMul {M} [Monoid M] [TopologicalSpace M]
[ContinuousMul M] : ContinuousConstSMul (ConjAct MΛ£) M :=
β¨fun _ => (continuous_const.mul continuous_id).mul continuous_constβ©
variable [TopologicalSpace G] [Inv G] [Mul G] [ContinuousMul G]
/-- Conjugation is jointly continuous on `G Γ G` when both `mul` and `inv` are continuous. -/
@[to_additive continuous_addConj_prod
"Conjugation is jointly continuous on `G Γ G` when both `add` and `neg` are continuous."]
theorem IsTopologicalGroup.continuous_conj_prod [ContinuousInv G] :
Continuous fun g : G Γ G => g.fst * g.snd * g.fstβ»ΒΉ :=
continuous_mul.mul (continuous_inv.comp continuous_fst)
@[deprecated (since := "2025-03-11")]
alias IsTopologicalAddGroup.continuous_conj_sum := IsTopologicalAddGroup.continuous_addConj_prod
/-- Conjugation by a fixed element is continuous when `mul` is continuous. -/
@[to_additive (attr := continuity)
"Conjugation by a fixed element is continuous when `add` is continuous."]
theorem IsTopologicalGroup.continuous_conj (g : G) : Continuous fun h : G => g * h * gβ»ΒΉ :=
(continuous_mul_right gβ»ΒΉ).comp (continuous_mul_left g)
/-- Conjugation acting on fixed element of the group is continuous when both `mul` and
`inv` are continuous. -/
@[to_additive (attr := continuity)
"Conjugation acting on fixed element of the additive group is continuous when both
`add` and `neg` are continuous."]
theorem IsTopologicalGroup.continuous_conj' [ContinuousInv G] (h : G) :
Continuous fun g : G => g * h * gβ»ΒΉ :=
(continuous_mul_right h).mul continuous_inv
end Conj
variable [TopologicalSpace G] [Group G] [IsTopologicalGroup G] [TopologicalSpace Ξ±] {f : Ξ± β G}
{s : Set Ξ±} {x : Ξ±}
instance : IsTopologicalGroup (ULift G) where
section ZPow
@[to_additive (attr := continuity, fun_prop)]
theorem continuous_zpow : β z : β€, Continuous fun a : G => a ^ z
| Int.ofNat n => by simpa using continuous_pow n
| Int.negSucc n => by simpa using (continuous_pow (n + 1)).inv
instance AddGroup.continuousConstSMul_int {A} [AddGroup A] [TopologicalSpace A]
[IsTopologicalAddGroup A] : ContinuousConstSMul β€ A :=
β¨continuous_zsmulβ©
instance AddGroup.continuousSMul_int {A} [AddGroup A] [TopologicalSpace A]
[IsTopologicalAddGroup A] : ContinuousSMul β€ A :=
β¨continuous_prod_of_discrete_left.mpr continuous_zsmulβ©
@[to_additive (attr := continuity, fun_prop)]
theorem Continuous.zpow {f : Ξ± β G} (h : Continuous f) (z : β€) : Continuous fun b => f b ^ z :=
(continuous_zpow z).comp h
@[to_additive]
theorem continuousOn_zpow {s : Set G} (z : β€) : ContinuousOn (fun x => x ^ z) s :=
(continuous_zpow z).continuousOn
@[to_additive]
theorem continuousAt_zpow (x : G) (z : β€) : ContinuousAt (fun x => x ^ z) x :=
(continuous_zpow z).continuousAt
@[to_additive]
theorem Filter.Tendsto.zpow {Ξ±} {l : Filter Ξ±} {f : Ξ± β G} {x : G} (hf : Tendsto f l (π x))
(z : β€) : Tendsto (fun x => f x ^ z) l (π (x ^ z)) :=
(continuousAt_zpow _ _).tendsto.comp hf
@[to_additive]
theorem ContinuousWithinAt.zpow {f : Ξ± β G} {x : Ξ±} {s : Set Ξ±} (hf : ContinuousWithinAt f s x)
(z : β€) : ContinuousWithinAt (fun x => f x ^ z) s x :=
Filter.Tendsto.zpow hf z
@[to_additive (attr := fun_prop)]
theorem ContinuousAt.zpow {f : Ξ± β G} {x : Ξ±} (hf : ContinuousAt f x) (z : β€) :
ContinuousAt (fun x => f x ^ z) x :=
Filter.Tendsto.zpow hf z
@[to_additive (attr := fun_prop)]
theorem ContinuousOn.zpow {f : Ξ± β G} {s : Set Ξ±} (hf : ContinuousOn f s) (z : β€) :
ContinuousOn (fun x => f x ^ z) s := fun x hx => (hf x hx).zpow z
end ZPow
section OrderedCommGroup
variable [TopologicalSpace H] [CommGroup H] [PartialOrder H] [IsOrderedMonoid H] [ContinuousInv H]
@[to_additive]
theorem tendsto_inv_nhdsGT {a : H} : Tendsto Inv.inv (π[>] a) (π[<] aβ»ΒΉ) :=
(continuous_inv.tendsto a).inf <| by simp [tendsto_principal_principal]
@[deprecated (since := "2024-12-22")]
alias tendsto_neg_nhdsWithin_Ioi := tendsto_neg_nhdsGT
@[to_additive existing, deprecated (since := "2024-12-22")]
alias tendsto_inv_nhdsWithin_Ioi := tendsto_inv_nhdsGT
@[to_additive]
theorem tendsto_inv_nhdsLT {a : H} : Tendsto Inv.inv (π[<] a) (π[>] aβ»ΒΉ) :=
(continuous_inv.tendsto a).inf <| by simp [tendsto_principal_principal]
@[deprecated (since := "2024-12-22")]
alias tendsto_neg_nhdsWithin_Iio := tendsto_neg_nhdsLT
@[to_additive existing, deprecated (since := "2024-12-22")]
alias tendsto_inv_nhdsWithin_Iio := tendsto_inv_nhdsLT
@[to_additive]
theorem tendsto_inv_nhdsGT_inv {a : H} : Tendsto Inv.inv (π[>] aβ»ΒΉ) (π[<] a) := by
simpa only [inv_inv] using tendsto_inv_nhdsGT (a := aβ»ΒΉ)
@[deprecated (since := "2024-12-22")]
alias tendsto_neg_nhdsWithin_Ioi_neg := tendsto_neg_nhdsGT_neg
@[to_additive existing, deprecated (since := "2024-12-22")]
alias tendsto_inv_nhdsWithin_Ioi_inv := tendsto_inv_nhdsGT_inv
@[to_additive]
theorem tendsto_inv_nhdsLT_inv {a : H} : Tendsto Inv.inv (π[<] aβ»ΒΉ) (π[>] a) := by
simpa only [inv_inv] using tendsto_inv_nhdsLT (a := aβ»ΒΉ)
@[deprecated (since := "2024-12-22")]
alias tendsto_neg_nhdsWithin_Iio_neg := tendsto_neg_nhdsLT_neg
@[to_additive existing, deprecated (since := "2024-12-22")]
alias tendsto_inv_nhdsWithin_Iio_inv := tendsto_inv_nhdsLT_inv
@[to_additive]
theorem tendsto_inv_nhdsGE {a : H} : Tendsto Inv.inv (π[β₯] a) (π[β€] aβ»ΒΉ) :=
(continuous_inv.tendsto a).inf <| by simp [tendsto_principal_principal]
@[deprecated (since := "2024-12-22")]
alias tendsto_neg_nhdsWithin_Ici := tendsto_neg_nhdsGE
@[to_additive existing, deprecated (since := "2024-12-22")]
alias tendsto_inv_nhdsWithin_Ici := tendsto_inv_nhdsGE
@[to_additive]
theorem tendsto_inv_nhdsLE {a : H} : Tendsto Inv.inv (π[β€] a) (π[β₯] aβ»ΒΉ) :=
(continuous_inv.tendsto a).inf <| by simp [tendsto_principal_principal]
@[deprecated (since := "2024-12-22")]
alias tendsto_neg_nhdsWithin_Iic := tendsto_neg_nhdsLE
@[to_additive existing, deprecated (since := "2024-12-22")]
alias tendsto_inv_nhdsWithin_Iic := tendsto_inv_nhdsLE
@[to_additive]
theorem tendsto_inv_nhdsGE_inv {a : H} : Tendsto Inv.inv (π[β₯] aβ»ΒΉ) (π[β€] a) := by
simpa only [inv_inv] using tendsto_inv_nhdsGE (a := aβ»ΒΉ)
@[deprecated (since := "2024-12-22")]
alias tendsto_neg_nhdsWithin_Ici_neg := tendsto_neg_nhdsGE_neg
@[to_additive existing, deprecated (since := "2024-12-22")]
alias tendsto_inv_nhdsWithin_Ici_inv := tendsto_inv_nhdsGE_inv
@[to_additive]
theorem tendsto_inv_nhdsLE_inv {a : H} : Tendsto Inv.inv (π[β€] aβ»ΒΉ) (π[β₯] a) := by
simpa only [inv_inv] using tendsto_inv_nhdsLE (a := aβ»ΒΉ)
@[deprecated (since := "2024-12-22")]
alias tendsto_neg_nhdsWithin_Iic_neg := tendsto_neg_nhdsLE_neg
@[to_additive existing, deprecated (since := "2024-12-22")]
alias tendsto_inv_nhdsWithin_Iic_inv := tendsto_inv_nhdsLE_inv
end OrderedCommGroup
@[to_additive]
instance Prod.instIsTopologicalGroup [TopologicalSpace H] [Group H] [IsTopologicalGroup H] :
IsTopologicalGroup (G Γ H) where
continuous_inv := continuous_inv.prodMap continuous_inv
@[to_additive]
instance OrderDual.instIsTopologicalGroup : IsTopologicalGroup Gα΅α΅ where
@[to_additive]
instance Pi.topologicalGroup {C : Ξ² β Type*} [β b, TopologicalSpace (C b)] [β b, Group (C b)]
[β b, IsTopologicalGroup (C b)] : IsTopologicalGroup (β b, C b) where
continuous_inv := continuous_pi fun i => (continuous_apply i).inv
open MulOpposite
@[to_additive]
instance [Inv Ξ±] [ContinuousInv Ξ±] : ContinuousInv Ξ±α΅α΅α΅ :=
opHomeomorph.symm.isInducing.continuousInv unop_inv
/-- If multiplication is continuous in `Ξ±`, then it also is in `Ξ±α΅α΅α΅`. -/
@[to_additive "If addition is continuous in `Ξ±`, then it also is in `Ξ±α΅α΅α΅`."]
instance [Group Ξ±] [IsTopologicalGroup Ξ±] : IsTopologicalGroup Ξ±α΅α΅α΅ where
variable (G)
@[to_additive]
theorem nhds_one_symm : comap Inv.inv (π (1 : G)) = π (1 : G) :=
((Homeomorph.inv G).comap_nhds_eq _).trans (congr_arg nhds inv_one)
@[to_additive]
theorem nhds_one_symm' : map Inv.inv (π (1 : G)) = π (1 : G) :=
((Homeomorph.inv G).map_nhds_eq _).trans (congr_arg nhds inv_one)
@[to_additive]
theorem inv_mem_nhds_one {S : Set G} (hS : S β (π 1 : Filter G)) : Sβ»ΒΉ β π (1 : G) := by
rwa [β nhds_one_symm'] at hS
/-- The map `(x, y) β¦ (x, x * y)` as a homeomorphism. This is a shear mapping. -/
@[to_additive "The map `(x, y) β¦ (x, x + y)` as a homeomorphism. This is a shear mapping."]
protected def Homeomorph.shearMulRight : G Γ G ββ G Γ G :=
{ Equiv.prodShear (Equiv.refl _) Equiv.mulLeft with
continuous_toFun := by dsimp; fun_prop
continuous_invFun := by dsimp; fun_prop }
@[to_additive (attr := simp)]
theorem Homeomorph.shearMulRight_coe :
β(Homeomorph.shearMulRight G) = fun z : G Γ G => (z.1, z.1 * z.2) :=
rfl
@[to_additive (attr := simp)]
theorem Homeomorph.shearMulRight_symm_coe :
β(Homeomorph.shearMulRight G).symm = fun z : G Γ G => (z.1, z.1β»ΒΉ * z.2) :=
rfl
variable {G}
@[to_additive]
protected theorem Topology.IsInducing.topologicalGroup {F : Type*} [Group H] [TopologicalSpace H]
[FunLike F H G] [MonoidHomClass F H G] (f : F) (hf : IsInducing f) : IsTopologicalGroup H :=
{ toContinuousMul := hf.continuousMul _
toContinuousInv := hf.continuousInv (map_inv f) }
@[deprecated (since := "2024-10-28")] alias Inducing.topologicalGroup := IsInducing.topologicalGroup
@[to_additive]
theorem topologicalGroup_induced {F : Type*} [Group H] [FunLike F H G] [MonoidHomClass F H G]
(f : F) :
@IsTopologicalGroup H (induced f βΉ_βΊ) _ :=
letI := induced f βΉ_βΊ
IsInducing.topologicalGroup f β¨rflβ©
namespace Subgroup
@[to_additive]
instance (S : Subgroup G) : IsTopologicalGroup S :=
IsInducing.subtypeVal.topologicalGroup S.subtype
end Subgroup
/-- The (topological-space) closure of a subgroup of a topological group is
itself a subgroup. -/
@[to_additive
"The (topological-space) closure of an additive subgroup of an additive topological group is
itself an additive subgroup."]
def Subgroup.topologicalClosure (s : Subgroup G) : Subgroup G :=
{ s.toSubmonoid.topologicalClosure with
carrier := _root_.closure (s : Set G)
inv_mem' := fun {g} hg => by simpa only [β Set.mem_inv, inv_closure, inv_coe_set] using hg }
@[to_additive (attr := simp)]
theorem Subgroup.topologicalClosure_coe {s : Subgroup G} :
(s.topologicalClosure : Set G) = _root_.closure s :=
rfl
@[to_additive]
theorem Subgroup.le_topologicalClosure (s : Subgroup G) : s β€ s.topologicalClosure :=
_root_.subset_closure
@[to_additive]
theorem Subgroup.isClosed_topologicalClosure (s : Subgroup G) :
IsClosed (s.topologicalClosure : Set G) := isClosed_closure
@[to_additive]
theorem Subgroup.topologicalClosure_minimal (s : Subgroup G) {t : Subgroup G} (h : s β€ t)
(ht : IsClosed (t : Set G)) : s.topologicalClosure β€ t :=
closure_minimal h ht
@[to_additive]
theorem DenseRange.topologicalClosure_map_subgroup [Group H] [TopologicalSpace H]
[IsTopologicalGroup H] {f : G β* H} (hf : Continuous f) (hf' : DenseRange f) {s : Subgroup G}
(hs : s.topologicalClosure = β€) : (s.map f).topologicalClosure = β€ := by
rw [SetLike.ext'_iff] at hs β’
simp only [Subgroup.topologicalClosure_coe, Subgroup.coe_top, β dense_iff_closure_eq] at hs β’
exact hf'.dense_image hf hs
/-- The topological closure of a normal subgroup is normal. -/
@[to_additive "The topological closure of a normal additive subgroup is normal."]
theorem Subgroup.is_normal_topologicalClosure {G : Type*} [TopologicalSpace G] [Group G]
[IsTopologicalGroup G] (N : Subgroup G) [N.Normal] :
(Subgroup.topologicalClosure N).Normal where
conj_mem n hn g := by
apply map_mem_closure (IsTopologicalGroup.continuous_conj g) hn
exact fun m hm => Subgroup.Normal.conj_mem inferInstance m hm g
@[to_additive]
theorem mul_mem_connectedComponent_one {G : Type*} [TopologicalSpace G] [MulOneClass G]
[ContinuousMul G] {g h : G} (hg : g β connectedComponent (1 : G))
(hh : h β connectedComponent (1 : G)) : g * h β connectedComponent (1 : G) := by
rw [connectedComponent_eq hg]
have hmul : g β connectedComponent (g * h) := by
apply Continuous.image_connectedComponent_subset (continuous_mul_left g)
rw [β connectedComponent_eq hh]
exact β¨(1 : G), mem_connectedComponent, by simp only [mul_one]β©
simpa [β connectedComponent_eq hmul] using mem_connectedComponent
@[to_additive]
theorem inv_mem_connectedComponent_one {G : Type*} [TopologicalSpace G] [DivisionMonoid G]
[ContinuousInv G] {g : G} (hg : g β connectedComponent (1 : G)) :
gβ»ΒΉ β connectedComponent (1 : G) := by
rw [β inv_one]
exact
Continuous.image_connectedComponent_subset continuous_inv _
((Set.mem_image _ _ _).mp β¨g, hg, rflβ©)
/-- The connected component of 1 is a subgroup of `G`. -/
@[to_additive "The connected component of 0 is a subgroup of `G`."]
def Subgroup.connectedComponentOfOne (G : Type*) [TopologicalSpace G] [Group G]
[IsTopologicalGroup G] : Subgroup G where
carrier := connectedComponent (1 : G)
one_mem' := mem_connectedComponent
mul_mem' hg hh := mul_mem_connectedComponent_one hg hh
inv_mem' hg := inv_mem_connectedComponent_one hg
/-- If a subgroup of a topological group is commutative, then so is its topological closure.
See note [reducible non-instances]. -/
@[to_additive
"If a subgroup of an additive topological group is commutative, then so is its
topological closure.
See note [reducible non-instances]."]
abbrev Subgroup.commGroupTopologicalClosure [T2Space G] (s : Subgroup G)
(hs : β x y : s, x * y = y * x) : CommGroup s.topologicalClosure :=
{ s.topologicalClosure.toGroup, s.toSubmonoid.commMonoidTopologicalClosure hs with }
variable (G) in
@[to_additive]
lemma Subgroup.coe_topologicalClosure_bot :
((β₯ : Subgroup G).topologicalClosure : Set G) = _root_.closure ({1} : Set G) := by simp
@[to_additive exists_nhds_half_neg]
theorem exists_nhds_split_inv {s : Set G} (hs : s β π (1 : G)) :
β V β π (1 : G), β v β V, β w β V, v / w β s := by
have : (fun p : G Γ G => p.1 * p.2β»ΒΉ) β»ΒΉ' s β π ((1, 1) : G Γ G) :=
continuousAt_fst.mul continuousAt_snd.inv (by simpa)
simpa only [div_eq_mul_inv, nhds_prod_eq, mem_prod_self_iff, prod_subset_iff, mem_preimage] using
this
@[to_additive]
theorem nhds_translation_mul_inv (x : G) : comap (Β· * xβ»ΒΉ) (π 1) = π x :=
((Homeomorph.mulRight xβ»ΒΉ).comap_nhds_eq 1).trans <| show π (1 * xβ»ΒΉβ»ΒΉ) = π x by simp
@[to_additive (attr := simp)]
theorem map_mul_left_nhds (x y : G) : map (x * Β·) (π y) = π (x * y) :=
(Homeomorph.mulLeft x).map_nhds_eq y
@[to_additive]
theorem map_mul_left_nhds_one (x : G) : map (x * Β·) (π 1) = π x := by simp
@[to_additive (attr := simp)]
theorem map_mul_right_nhds (x y : G) : map (Β· * x) (π y) = π (y * x) :=
(Homeomorph.mulRight x).map_nhds_eq y
@[to_additive]
theorem map_mul_right_nhds_one (x : G) : map (Β· * x) (π 1) = π x := by simp
@[to_additive]
theorem Filter.HasBasis.nhds_of_one {ΞΉ : Sort*} {p : ΞΉ β Prop} {s : ΞΉ β Set G}
(hb : HasBasis (π 1 : Filter G) p s) (x : G) :
HasBasis (π x) p fun i => { y | y / x β s i } := by
rw [β nhds_translation_mul_inv]
simp_rw [div_eq_mul_inv]
exact hb.comap _
@[to_additive]
theorem mem_closure_iff_nhds_one {x : G} {s : Set G} :
x β closure s β β U β (π 1 : Filter G), β y β s, y / x β U := by
rw [mem_closure_iff_nhds_basis ((π 1 : Filter G).basis_sets.nhds_of_one x)]
simp_rw [Set.mem_setOf, id]
/-- A monoid homomorphism (a bundled morphism of a type that implements `MonoidHomClass`) from a
topological group to a topological monoid is continuous provided that it is continuous at one. See
also `uniformContinuous_of_continuousAt_one`. -/
@[to_additive
"An additive monoid homomorphism (a bundled morphism of a type that implements
`AddMonoidHomClass`) from an additive topological group to an additive topological monoid is
continuous provided that it is continuous at zero. See also
`uniformContinuous_of_continuousAt_zero`."]
theorem continuous_of_continuousAt_one {M hom : Type*} [MulOneClass M] [TopologicalSpace M]
[ContinuousMul M] [FunLike hom G M] [MonoidHomClass hom G M] (f : hom)
(hf : ContinuousAt f 1) :
Continuous f :=
continuous_iff_continuousAt.2 fun x => by
simpa only [ContinuousAt, β map_mul_left_nhds_one x, tendsto_map'_iff, Function.comp_def,
map_mul, map_one, mul_one] using hf.tendsto.const_mul (f x)
@[to_additive continuous_of_continuousAt_zeroβ]
theorem continuous_of_continuousAt_oneβ {H M : Type*} [CommMonoid M] [TopologicalSpace M]
[ContinuousMul M] [Group H] [TopologicalSpace H] [IsTopologicalGroup H] (f : G β* H β* M)
(hf : ContinuousAt (fun x : G Γ H β¦ f x.1 x.2) (1, 1))
(hl : β x, ContinuousAt (f x) 1) (hr : β y, ContinuousAt (f Β· y) 1) :
Continuous (fun x : G Γ H β¦ f x.1 x.2) := continuous_iff_continuousAt.2 fun (x, y) => by
simp only [ContinuousAt, nhds_prod_eq, β map_mul_left_nhds_one x, β map_mul_left_nhds_one y,
prod_map_map_eq, tendsto_map'_iff, Function.comp_def, map_mul, MonoidHom.mul_apply] at *
refine ((tendsto_const_nhds.mul ((hr y).comp tendsto_fst)).mul
(((hl x).comp tendsto_snd).mul hf)).mono_right (le_of_eq ?_)
simp only [map_one, mul_one, MonoidHom.one_apply]
@[to_additive]
lemma IsTopologicalGroup.isInducing_iff_nhds_one
{H : Type*} [Group H] [TopologicalSpace H] [IsTopologicalGroup H] {F : Type*}
[FunLike F G H] [MonoidHomClass F G H] {f : F} :
Topology.IsInducing f β π (1 : G) = (π (1 : H)).comap f := by
rw [Topology.isInducing_iff_nhds]
refine β¨(map_one f βΈ Β· 1), fun hf x β¦ ?_β©
rw [β nhds_translation_mul_inv, β nhds_translation_mul_inv (f x), Filter.comap_comap, hf,
Filter.comap_comap]
congr 1
ext; simp
@[to_additive]
lemma TopologicalGroup.isOpenMap_iff_nhds_one
{H : Type*} [Monoid H] [TopologicalSpace H] [ContinuousConstSMul H H]
{F : Type*} [FunLike F G H] [MonoidHomClass F G H] {f : F} :
IsOpenMap f β π 1 β€ .map f (π 1) := by
refine β¨fun H β¦ map_one f βΈ H.nhds_le 1, fun h β¦ IsOpenMap.of_nhds_le fun x β¦ ?_β©
have : Filter.map (f x * Β·) (π 1) = π (f x) := by
simpa [-Homeomorph.map_nhds_eq, Units.smul_def] using
(Homeomorph.smul ((toUnits x).map (MonoidHomClass.toMonoidHom f))).map_nhds_eq (1 : H)
rw [β map_mul_left_nhds_one x, Filter.map_map, Function.comp_def, β this]
refine (Filter.map_mono h).trans ?_
simp [Function.comp_def]
-- TODO: unify with `QuotientGroup.isOpenQuotientMap_mk`
/-- Let `A` and `B` be topological groups, and let `Ο : A β B` be a continuous surjective group
homomorphism. Assume furthermore that `Ο` is a quotient map (i.e., `V β B`
is open iff `Οβ»ΒΉ V` is open). Then `Ο` is an open quotient map, and in particular an open map. -/
@[to_additive "Let `A` and `B` be topological additive groups, and let `Ο : A β B` be a continuous
surjective additive group homomorphism. Assume furthermore that `Ο` is a quotient map (i.e., `V β B`
is open iff `Οβ»ΒΉ V` is open). Then `Ο` is an open quotient map, and in particular an open map."]
lemma MonoidHom.isOpenQuotientMap_of_isQuotientMap {A : Type*} [Group A]
[TopologicalSpace A] [ContinuousMul A] {B : Type*} [Group B] [TopologicalSpace B]
{F : Type*} [FunLike F A B] [MonoidHomClass F A B] {Ο : F}
(hΟ : IsQuotientMap Ο) : IsOpenQuotientMap Ο where
surjective := hΟ.surjective
continuous := hΟ.continuous
isOpenMap := by
-- We need to check that if `U β A` is open then `Οβ»ΒΉ (Ο U)` is open.
intro U hU
rw [β hΟ.isOpen_preimage]
-- It suffices to show that `Οβ»ΒΉ (Ο U) = β (U * kβ»ΒΉ)` as `k` runs through the kernel of `Ο`,
-- as `U * kβ»ΒΉ` is open because `x β¦ x * k` is continuous.
-- Remark: here is where we use that we have groups not monoids (you cannot avoid
-- using both `k` and `kβ»ΒΉ` at this point).
suffices βΟ β»ΒΉ' (βΟ '' U) = β k β ker (Ο : A β* B), (fun x β¦ x * k) β»ΒΉ' U by
exact this βΈ isOpen_biUnion (fun k _ β¦ Continuous.isOpen_preimage (by fun_prop) _ hU)
ext x
-- But this is an elementary calculation.
constructor
Β· rintro β¨y, hyU, hyxβ©
apply Set.mem_iUnion_of_mem (xβ»ΒΉ * y)
simp_all
Β· rintro β¨_, β¨k, rflβ©, _, β¨(hk : Ο k = 1), rflβ©, hxβ©
use x * k, hx
rw [map_mul, hk, mul_one]
@[to_additive]
theorem IsTopologicalGroup.ext {G : Type*} [Group G] {t t' : TopologicalSpace G}
(tg : @IsTopologicalGroup G t _) (tg' : @IsTopologicalGroup G t' _)
(h : @nhds G t 1 = @nhds G t' 1) : t = t' :=
TopologicalSpace.ext_nhds fun x β¦ by
rw [β @nhds_translation_mul_inv G t _ _ x, β @nhds_translation_mul_inv G t' _ _ x, β h]
@[to_additive]
theorem IsTopologicalGroup.ext_iff {G : Type*} [Group G] {t t' : TopologicalSpace G}
(tg : @IsTopologicalGroup G t _) (tg' : @IsTopologicalGroup G t' _) :
t = t' β @nhds G t 1 = @nhds G t' 1 :=
β¨fun h => h βΈ rfl, tg.ext tg'β©
@[to_additive]
theorem ContinuousInv.of_nhds_one {G : Type*} [Group G] [TopologicalSpace G]
(hinv : Tendsto (fun x : G => xβ»ΒΉ) (π 1) (π 1))
(hleft : β xβ : G, π xβ = map (fun x : G => xβ * x) (π 1))
(hconj : β xβ : G, Tendsto (fun x : G => xβ * x * xββ»ΒΉ) (π 1) (π 1)) : ContinuousInv G := by
refine β¨continuous_iff_continuousAt.2 fun xβ => ?_β©
have : Tendsto (fun x => xββ»ΒΉ * (xβ * xβ»ΒΉ * xββ»ΒΉ)) (π 1) (map (xββ»ΒΉ * Β·) (π 1)) :=
(tendsto_map.comp <| hconj xβ).comp hinv
simpa only [ContinuousAt, hleft xβ, hleft xββ»ΒΉ, tendsto_map'_iff, Function.comp_def, mul_assoc,
mul_inv_rev, inv_mul_cancel_left] using this
@[to_additive]
theorem IsTopologicalGroup.of_nhds_one' {G : Type u} [Group G] [TopologicalSpace G]
(hmul : Tendsto (uncurry ((Β· * Β·) : G β G β G)) (π 1 ΓΛ’ π 1) (π 1))
(hinv : Tendsto (fun x : G => xβ»ΒΉ) (π 1) (π 1))
(hleft : β xβ : G, π xβ = map (fun x => xβ * x) (π 1))
(hright : β xβ : G, π xβ = map (fun x => x * xβ) (π 1)) : IsTopologicalGroup G :=
{ toContinuousMul := ContinuousMul.of_nhds_one hmul hleft hright
toContinuousInv :=
ContinuousInv.of_nhds_one hinv hleft fun xβ =>
le_of_eq
(by
rw [show (fun x => xβ * x * xββ»ΒΉ) = (fun x => x * xββ»ΒΉ) β fun x => xβ * x from rfl, β
map_map, β hleft, hright, map_map]
simp [(Β· β Β·)]) }
@[to_additive]
theorem IsTopologicalGroup.of_nhds_one {G : Type u} [Group G] [TopologicalSpace G]
(hmul : Tendsto (uncurry ((Β· * Β·) : G β G β G)) (π 1 ΓΛ’ π 1) (π 1))
(hinv : Tendsto (fun x : G => xβ»ΒΉ) (π 1) (π 1))
(hleft : β xβ : G, π xβ = map (xβ * Β·) (π 1))
(hconj : β xβ : G, Tendsto (xβ * Β· * xββ»ΒΉ) (π 1) (π 1)) : IsTopologicalGroup G := by
refine IsTopologicalGroup.of_nhds_one' hmul hinv hleft fun xβ => ?_
replace hconj : β xβ : G, map (xβ * Β· * xββ»ΒΉ) (π 1) = π 1 :=
fun xβ => map_eq_of_inverse (xββ»ΒΉ * Β· * xββ»ΒΉβ»ΒΉ) (by ext; simp [mul_assoc]) (hconj _) (hconj _)
rw [β hconj xβ]
simpa [Function.comp_def] using hleft _
@[to_additive]
theorem IsTopologicalGroup.of_comm_of_nhds_one {G : Type u} [CommGroup G] [TopologicalSpace G]
(hmul : Tendsto (uncurry ((Β· * Β·) : G β G β G)) (π 1 ΓΛ’ π 1) (π 1))
(hinv : Tendsto (fun x : G => xβ»ΒΉ) (π 1) (π 1))
(hleft : β xβ : G, π xβ = map (xβ * Β·) (π 1)) : IsTopologicalGroup G :=
IsTopologicalGroup.of_nhds_one hmul hinv hleft (by simpa using tendsto_id)
variable (G) in
/-- Any first countable topological group has an antitone neighborhood basis `u : β β Set G` for
which `(u (n + 1)) ^ 2 β u n`. The existence of such a neighborhood basis is a key tool for
`QuotientGroup.completeSpace` -/
@[to_additive
"Any first countable topological additive group has an antitone neighborhood basis
`u : β β set G` for which `u (n + 1) + u (n + 1) β u n`.
The existence of such a neighborhood basis is a key tool for `QuotientAddGroup.completeSpace`"]
theorem IsTopologicalGroup.exists_antitone_basis_nhds_one [FirstCountableTopology G] :
β u : β β Set G, (π 1).HasAntitoneBasis u β§ β n, u (n + 1) * u (n + 1) β u n := by
rcases (π (1 : G)).exists_antitone_basis with β¨u, hu, u_antiβ©
have :=
((hu.prod_nhds hu).tendsto_iff hu).mp
(by simpa only [mul_one] using continuous_mul.tendsto ((1, 1) : G Γ G))
simp only [and_self_iff, mem_prod, and_imp, Prod.forall, exists_true_left, Prod.exists,
forall_true_left] at this
have event_mul : β n : β, βαΆ m in atTop, u m * u m β u n := by
intro n
rcases this n with β¨j, k, -, hβ©
refine atTop_basis.eventually_iff.mpr β¨max j k, True.intro, fun m hm => ?_β©
rintro - β¨a, ha, b, hb, rflβ©
exact h a b (u_anti ((le_max_left _ _).trans hm) ha) (u_anti ((le_max_right _ _).trans hm) hb)
obtain β¨Ο, -, hΟ, Ο_anti_basisβ© := HasAntitoneBasis.subbasis_with_rel β¨hu, u_antiβ© event_mul
exact β¨u β Ο, Ο_anti_basis, fun n => hΟ n.lt_succ_selfβ©
end IsTopologicalGroup
section ContinuousDiv
variable [TopologicalSpace G] [Div G] [ContinuousDiv G]
@[to_additive const_sub]
theorem Filter.Tendsto.const_div' (b : G) {c : G} {f : Ξ± β G} {l : Filter Ξ±}
(h : Tendsto f l (π c)) : Tendsto (fun k : Ξ± => b / f k) l (π (b / c)) :=
tendsto_const_nhds.div' h
@[to_additive]
lemma Filter.tendsto_const_div_iff {G : Type*} [CommGroup G] [TopologicalSpace G] [ContinuousDiv G]
(b : G) {c : G} {f : Ξ± β G} {l : Filter Ξ±} :
Tendsto (fun k : Ξ± β¦ b / f k) l (π (b / c)) β Tendsto f l (π c) := by
refine β¨fun h β¦ ?_, Filter.Tendsto.const_div' bβ©
convert h.const_div' b with k <;> rw [div_div_cancel]
@[to_additive sub_const]
theorem Filter.Tendsto.div_const' {c : G} {f : Ξ± β G} {l : Filter Ξ±} (h : Tendsto f l (π c))
(b : G) : Tendsto (f Β· / b) l (π (c / b)) :=
h.div' tendsto_const_nhds
lemma Filter.tendsto_div_const_iff {G : Type*}
[CommGroupWithZero G] [TopologicalSpace G] [ContinuousDiv G]
{b : G} (hb : b β 0) {c : G} {f : Ξ± β G} {l : Filter Ξ±} :
Tendsto (f Β· / b) l (π (c / b)) β Tendsto f l (π c) := by
refine β¨fun h β¦ ?_, fun h β¦ Filter.Tendsto.div_const' h bβ©
convert h.div_const' bβ»ΒΉ with k <;> rw [div_div, mul_inv_cancelβ hb, div_one]
lemma Filter.tendsto_sub_const_iff {G : Type*}
[AddCommGroup G] [TopologicalSpace G] [ContinuousSub G]
(b : G) {c : G} {f : Ξ± β G} {l : Filter Ξ±} :
Tendsto (f Β· - b) l (π (c - b)) β Tendsto f l (π c) := by
refine β¨fun h β¦ ?_, fun h β¦ Filter.Tendsto.sub_const h bβ©
convert h.sub_const (-b) with k <;> rw [sub_sub, β sub_eq_add_neg, sub_self, sub_zero]
variable [TopologicalSpace Ξ±] {f g : Ξ± β G} {s : Set Ξ±} {x : Ξ±}
@[to_additive (attr := continuity) continuous_sub_left]
lemma continuous_div_left' (a : G) : Continuous (a / Β·) := continuous_const.div' continuous_id
@[to_additive (attr := continuity) continuous_sub_right]
lemma continuous_div_right' (a : G) : Continuous (Β· / a) := continuous_id.div' continuous_const
end ContinuousDiv
section DivInvTopologicalGroup
variable [Group G] [TopologicalSpace G] [IsTopologicalGroup G]
/-- A version of `Homeomorph.mulLeft a bβ»ΒΉ` that is defeq to `a / b`. -/
@[to_additive (attr := simps! +simpRhs)
"A version of `Homeomorph.addLeft a (-b)` that is defeq to `a - b`."]
def Homeomorph.divLeft (x : G) : G ββ G :=
{ Equiv.divLeft x with
continuous_toFun := continuous_const.div' continuous_id
continuous_invFun := continuous_inv.mul continuous_const }
@[to_additive]
theorem isOpenMap_div_left (a : G) : IsOpenMap (a / Β·) :=
(Homeomorph.divLeft _).isOpenMap
@[to_additive]
theorem isClosedMap_div_left (a : G) : IsClosedMap (a / Β·) :=
(Homeomorph.divLeft _).isClosedMap
/-- A version of `Homeomorph.mulRight aβ»ΒΉ b` that is defeq to `b / a`. -/
@[to_additive (attr := simps! +simpRhs)
"A version of `Homeomorph.addRight (-a) b` that is defeq to `b - a`. "]
def Homeomorph.divRight (x : G) : G ββ G :=
{ Equiv.divRight x with
continuous_toFun := continuous_id.div' continuous_const
continuous_invFun := continuous_id.mul continuous_const }
@[to_additive]
lemma isOpenMap_div_right (a : G) : IsOpenMap (Β· / a) := (Homeomorph.divRight a).isOpenMap
@[to_additive]
lemma isClosedMap_div_right (a : G) : IsClosedMap (Β· / a) := (Homeomorph.divRight a).isClosedMap
@[to_additive]
theorem tendsto_div_nhds_one_iff {Ξ± : Type*} {l : Filter Ξ±} {x : G} {u : Ξ± β G} :
Tendsto (u Β· / x) l (π 1) β Tendsto u l (π x) :=
haveI A : Tendsto (fun _ : Ξ± => x) l (π x) := tendsto_const_nhds
β¨fun h => by simpa using h.mul A, fun h => by simpa using h.div' Aβ©
@[to_additive]
theorem nhds_translation_div (x : G) : comap (Β· / x) (π 1) = π x := by
simpa only [div_eq_mul_inv] using nhds_translation_mul_inv x
end DivInvTopologicalGroup
section FilterMul
section
variable (G) [TopologicalSpace G] [Group G] [ContinuousMul G]
@[to_additive]
theorem IsTopologicalGroup.t1Space (h : @IsClosed G _ {1}) : T1Space G :=
β¨fun x => by simpa using isClosedMap_mul_right x _ hβ©
end
section
variable [TopologicalSpace G] [Group G] [IsTopologicalGroup G]
variable (S : Subgroup G) [Subgroup.Normal S] [IsClosed (S : Set G)]
/-- A subgroup `S` of a topological group `G` acts on `G` properly discontinuously on the left, if
it is discrete in the sense that `S β© K` is finite for all compact `K`. (See also
`DiscreteTopology`.) -/
@[to_additive
"A subgroup `S` of an additive topological group `G` acts on `G` properly
discontinuously on the left, if it is discrete in the sense that `S β© K` is finite for all compact
`K`. (See also `DiscreteTopology`."]
theorem Subgroup.properlyDiscontinuousSMul_of_tendsto_cofinite (S : Subgroup G)
(hS : Tendsto S.subtype cofinite (cocompact G)) : ProperlyDiscontinuousSMul S G :=
{ finite_disjoint_inter_image := by
intro K L hK hL
have H : Set.Finite _ := hS ((hL.prod hK).image continuous_div').compl_mem_cocompact
rw [preimage_compl, compl_compl] at H
convert H
ext x
simp only [image_smul, mem_setOf_eq, coe_subtype, mem_preimage, mem_image, Prod.exists]
exact Set.smul_inter_ne_empty_iff' }
/-- A subgroup `S` of a topological group `G` acts on `G` properly discontinuously on the right, if
it is discrete in the sense that `S β© K` is finite for all compact `K`. (See also
`DiscreteTopology`.)
If `G` is Hausdorff, this can be combined with `t2Space_of_properlyDiscontinuousSMul_of_t2Space`
to show that the quotient group `G β§Έ S` is Hausdorff. -/
@[to_additive
"A subgroup `S` of an additive topological group `G` acts on `G` properly discontinuously
on the right, if it is discrete in the sense that `S β© K` is finite for all compact `K`.
(See also `DiscreteTopology`.)
If `G` is Hausdorff, this can be combined with `t2Space_of_properlyDiscontinuousVAdd_of_t2Space`
to show that the quotient group `G β§Έ S` is Hausdorff."]
theorem Subgroup.properlyDiscontinuousSMul_opposite_of_tendsto_cofinite (S : Subgroup G)
(hS : Tendsto S.subtype cofinite (cocompact G)) : ProperlyDiscontinuousSMul S.op G :=
{ finite_disjoint_inter_image := by
intro K L hK hL
have : Continuous fun p : G Γ G => (p.1β»ΒΉ, p.2) := continuous_inv.prodMap continuous_id
have H : Set.Finite _ :=
hS ((hK.prod hL).image (continuous_mul.comp this)).compl_mem_cocompact
simp only [preimage_compl, compl_compl, coe_subtype, comp_apply] at H
apply Finite.of_preimage _ (equivOp S).surjective
convert H using 1
ext x
simp only [image_smul, mem_setOf_eq, coe_subtype, mem_preimage, mem_image, Prod.exists]
exact Set.op_smul_inter_ne_empty_iff }
end
section
/-! Some results about an open set containing the product of two sets in a topological group. -/
variable [TopologicalSpace G] [MulOneClass G] [ContinuousMul G]
/-- Given a compact set `K` inside an open set `U`, there is an open neighborhood `V` of `1`
such that `K * V β U`. -/
@[to_additive
"Given a compact set `K` inside an open set `U`, there is an open neighborhood `V` of
`0` such that `K + V β U`."]
theorem compact_open_separated_mul_right {K U : Set G} (hK : IsCompact K) (hU : IsOpen U)
(hKU : K β U) : β V β π (1 : G), K * V β U := by
refine hK.induction_on ?_ ?_ ?_ ?_
Β· exact β¨univ, by simpβ©
Β· rintro s t hst β¨V, hV, hV'β©
exact β¨V, hV, (mul_subset_mul_right hst).trans hV'β©
Β· rintro s t β¨V, V_in, hV'β© β¨W, W_in, hW'β©
use V β© W, inter_mem V_in W_in
rw [union_mul]
exact
union_subset ((mul_subset_mul_left V.inter_subset_left).trans hV')
((mul_subset_mul_left V.inter_subset_right).trans hW')
Β· intro x hx
have := tendsto_mul (show U β π (x * 1) by simpa using hU.mem_nhds (hKU hx))
rw [nhds_prod_eq, mem_map, mem_prod_iff] at this
rcases this with β¨t, ht, s, hs, hβ©
rw [β image_subset_iff, image_mul_prod] at h
exact β¨t, mem_nhdsWithin_of_mem_nhds ht, s, hs, hβ©
open MulOpposite
/-- Given a compact set `K` inside an open set `U`, there is an open neighborhood `V` of `1`
such that `V * K β U`. -/
@[to_additive
"Given a compact set `K` inside an open set `U`, there is an open neighborhood `V` of
`0` such that `V + K β U`."]
theorem compact_open_separated_mul_left {K U : Set G} (hK : IsCompact K) (hU : IsOpen U)
(hKU : K β U) : β V β π (1 : G), V * K β U := by
rcases compact_open_separated_mul_right (hK.image continuous_op) (opHomeomorph.isOpenMap U hU)
(image_subset op hKU) with
β¨V, hV : V β π (op (1 : G)), hV' : op '' K * V β op '' Uβ©
refine β¨op β»ΒΉ' V, continuous_op.continuousAt hV, ?_β©
rwa [β image_preimage_eq V op_surjective, β image_op_mul, image_subset_iff,
preimage_image_eq _ op_injective] at hV'
end
section
variable [TopologicalSpace G] [Group G] [IsTopologicalGroup G]
/-- A compact set is covered by finitely many left multiplicative translates of a set
with non-empty interior. -/
@[to_additive
"A compact set is covered by finitely many left additive translates of a set
with non-empty interior."]
theorem compact_covered_by_mul_left_translates {K V : Set G} (hK : IsCompact K)
(hV : (interior V).Nonempty) : β t : Finset G, K β β g β t, (g * Β·) β»ΒΉ' V := by
obtain β¨t, htβ© : β t : Finset G, K β β x β t, interior ((x * Β·) β»ΒΉ' V) := by
refine
hK.elim_finite_subcover (fun x => interior <| (x * Β·) β»ΒΉ' V) (fun x => isOpen_interior) ?_
obtain β¨gβ, hgββ© := hV
refine fun g _ => mem_iUnion.2 β¨gβ * gβ»ΒΉ, ?_β©
refine preimage_interior_subset_interior_preimage (continuous_const.mul continuous_id) ?_
rwa [mem_preimage, Function.id_def, inv_mul_cancel_right]
exact β¨t, Subset.trans ht <| iUnionβ_mono fun g _ => interior_subsetβ©
/-- Every weakly locally compact separable topological group is Ο-compact.
Note: this is not true if we drop the topological group hypothesis. -/
@[to_additive SeparableWeaklyLocallyCompactAddGroup.sigmaCompactSpace
"Every weakly locally compact separable topological additive group is Ο-compact.
Note: this is not true if we drop the topological group hypothesis."]
instance (priority := 100) SeparableWeaklyLocallyCompactGroup.sigmaCompactSpace [SeparableSpace G]
[WeaklyLocallyCompactSpace G] : SigmaCompactSpace G := by
obtain β¨L, hLc, hL1β© := exists_compact_mem_nhds (1 : G)
refine β¨β¨fun n => (fun x => x * denseSeq G n) β»ΒΉ' L, ?_, ?_β©β©
Β· intro n
exact (Homeomorph.mulRight _).isCompact_preimage.mpr hLc
Β· refine iUnion_eq_univ_iff.2 fun x => ?_
obtain β¨_, β¨n, rflβ©, hnβ© : (range (denseSeq G) β© (fun y => x * y) β»ΒΉ' L).Nonempty := by
rw [β (Homeomorph.mulLeft x).apply_symm_apply 1] at hL1
exact (denseRange_denseSeq G).inter_nhds_nonempty
((Homeomorph.mulLeft x).continuous.continuousAt <| hL1)
exact β¨n, hnβ©
/-- Given two compact sets in a noncompact topological group, there is a translate of the second
one that is disjoint from the first one. -/
@[to_additive
"Given two compact sets in a noncompact additive topological group, there is a
translate of the second one that is disjoint from the first one."]
theorem exists_disjoint_smul_of_isCompact [NoncompactSpace G] {K L : Set G} (hK : IsCompact K)
(hL : IsCompact L) : β g : G, Disjoint K (g β’ L) := by
have A : Β¬K * Lβ»ΒΉ = univ := (hK.mul hL.inv).ne_univ
obtain β¨g, hgβ© : β g, g β K * Lβ»ΒΉ := by
contrapose! A
exact eq_univ_iff_forall.2 A
refine β¨g, ?_β©
refine disjoint_left.2 fun a ha h'a => hg ?_
rcases h'a with β¨b, bL, rflβ©
refine β¨g * b, ha, bβ»ΒΉ, by simpa only [Set.mem_inv, inv_inv] using bL, ?_β©
simp only [smul_eq_mul, mul_inv_cancel_right]
end
section
variable [TopologicalSpace G] [Group G] [IsTopologicalGroup G]
@[to_additive]
theorem nhds_mul (x y : G) : π (x * y) = π x * π y :=
calc
π (x * y) = map (x * Β·) (map (Β· * y) (π 1 * π 1)) := by simp
_ = mapβ (fun a b => x * (a * b * y)) (π 1) (π 1) := by rw [β mapβ_mul, map_mapβ, map_mapβ]
_ = mapβ (fun a b => x * a * (b * y)) (π 1) (π 1) := by simp only [mul_assoc]
_ = π x * π y := by
rw [β map_mul_left_nhds_one x, β map_mul_right_nhds_one y, β mapβ_mul, mapβ_map_left,
mapβ_map_right]
/-- On a topological group, `π : G β Filter G` can be promoted to a `MulHom`. -/
@[to_additive (attr := simps)
"On an additive topological group, `π : G β Filter G` can be promoted to an `AddHom`."]
def nhdsMulHom : G ββ* Filter G where
toFun := π
map_mul' _ _ := nhds_mul _ _
end
end FilterMul
instance {G} [TopologicalSpace G] [Group G] [IsTopologicalGroup G] :
IsTopologicalAddGroup (Additive G) where
continuous_neg := @continuous_inv G _ _ _
instance {G} [TopologicalSpace G] [AddGroup G] [IsTopologicalAddGroup G] :
IsTopologicalGroup (Multiplicative G) where
continuous_inv := @continuous_neg G _ _ _
/-- If `G` is a group with topological `β»ΒΉ`, then it is homeomorphic to its units. -/
@[to_additive "If `G` is an additive group with topological negation, then it is homeomorphic to
its additive units."]
def toUnits_homeomorph [Group G] [TopologicalSpace G] [ContinuousInv G] : G ββ GΛ£ where
toEquiv := toUnits.toEquiv
continuous_toFun := Units.continuous_iff.2 β¨continuous_id, continuous_invβ©
continuous_invFun := Units.continuous_val
@[to_additive] theorem Units.isEmbedding_val [Group G] [TopologicalSpace G] [ContinuousInv G] :
IsEmbedding (val : GΛ£ β G) :=
toUnits_homeomorph.symm.isEmbedding
@[deprecated (since := "2024-10-26")]
alias Units.embedding_val := Units.isEmbedding_val
lemma Continuous.of_coeHom_comp [Group G] [Monoid H] [TopologicalSpace G] [TopologicalSpace H]
[ContinuousInv G] {f : G β* HΛ£} (hf : Continuous ((Units.coeHom H).comp f)) : Continuous f := by
apply continuous_induced_rng.mpr ?_
refine continuous_prodMk.mpr β¨hf, ?_β©
simp_rw [β map_inv]
exact MulOpposite.continuous_op.comp (hf.comp continuous_inv)
namespace Units
open MulOpposite (continuous_op continuous_unop)
variable [Monoid Ξ±] [TopologicalSpace Ξ±] [Monoid Ξ²] [TopologicalSpace Ξ²]
@[to_additive]
instance [ContinuousMul Ξ±] : IsTopologicalGroup Ξ±Λ£ where
continuous_inv := Units.continuous_iff.2 <| β¨continuous_coe_inv, continuous_valβ©
/-- The topological group isomorphism between the units of a product of two monoids, and the product
of the units of each monoid. -/
@[to_additive prodAddUnits
"The topological group isomorphism between the additive units of a product of two
additive monoids, and the product of the additive units of each additive monoid."]
def _root_.Homeomorph.prodUnits : (Ξ± Γ Ξ²)Λ£ ββ Ξ±Λ£ Γ Ξ²Λ£ where
continuous_toFun :=
(continuous_fst.units_map (MonoidHom.fst Ξ± Ξ²)).prodMk
(continuous_snd.units_map (MonoidHom.snd Ξ± Ξ²))
continuous_invFun :=
Units.continuous_iff.2
β¨continuous_val.fst'.prodMk continuous_val.snd',
continuous_coe_inv.fst'.prodMk continuous_coe_inv.snd'β©
toEquiv := MulEquiv.prodUnits.toEquiv
@[deprecated (since := "2025-02-21")]
alias Homeomorph.sumAddUnits := Homeomorph.prodAddUnits
@[deprecated (since := "2025-02-21")]
protected alias Homeomorph.prodUnits := Homeomorph.prodUnits
end Units
section LatticeOps
variable {ΞΉ : Sort*} [Group G]
@[to_additive]
theorem topologicalGroup_sInf {ts : Set (TopologicalSpace G)}
(h : β t β ts, @IsTopologicalGroup G t _) : @IsTopologicalGroup G (sInf ts) _ :=
letI := sInf ts
{ toContinuousInv :=
@continuousInv_sInf _ _ _ fun t ht => @IsTopologicalGroup.toContinuousInv G t _ <| h t ht
toContinuousMul :=
@continuousMul_sInf _ _ _ fun t ht =>
@IsTopologicalGroup.toContinuousMul G t _ <| h t ht }
@[to_additive]
theorem topologicalGroup_iInf {ts' : ΞΉ β TopologicalSpace G}
(h' : β i, @IsTopologicalGroup G (ts' i) _) : @IsTopologicalGroup G (β¨
i, ts' i) _ := by
rw [β sInf_range]
exact topologicalGroup_sInf (Set.forall_mem_range.mpr h')
@[to_additive]
theorem topologicalGroup_inf {tβ tβ : TopologicalSpace G} (hβ : @IsTopologicalGroup G tβ _)
(hβ : @IsTopologicalGroup G tβ _) : @IsTopologicalGroup G (tβ β tβ) _ := by
rw [inf_eq_iInf]
refine topologicalGroup_iInf fun b => ?_
cases b <;> assumption
end LatticeOps
| Mathlib/Topology/Algebra/Group/Basic.lean | 1,305 | 1,307 | |
/-
Copyright (c) 2021 Martin Dvorak. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Martin Dvorak, Kyle Miller, Eric Wieser
-/
import Mathlib.Algebra.Lie.Basic
import Mathlib.Data.Matrix.Notation
import Mathlib.LinearAlgebra.BilinearMap
import Mathlib.LinearAlgebra.LinearIndependent.Lemmas
import Mathlib.LinearAlgebra.Matrix.Determinant.Basic
/-!
# Cross products
This module defines the cross product of vectors in $R^3$ for $R$ a commutative ring,
as a bilinear map.
## Main definitions
* `crossProduct` is the cross product of pairs of vectors in $R^3$.
## Main results
* `triple_product_eq_det`
* `cross_dot_cross`
* `jacobi_cross`
## Notation
The locale `Matrix` gives the following notation:
* `Γβ` for the cross product
## Tags
crossproduct
-/
open Matrix
variable {R : Type*} [CommRing R]
/-- The cross product of two vectors in $R^3$ for $R$ a commutative ring. -/
def crossProduct : (Fin 3 β R) ββ[R] (Fin 3 β R) ββ[R] Fin 3 β R := by
apply LinearMap.mkβ R fun a b : Fin 3 β R =>
![a 1 * b 2 - a 2 * b 1, a 2 * b 0 - a 0 * b 2, a 0 * b 1 - a 1 * b 0]
Β· intros
simp_rw [vec3_add, Pi.add_apply]
apply vec3_eq <;> ring
Β· intros
simp_rw [smul_vec3, Pi.smul_apply, smul_sub, smul_mul_assoc]
Β· intros
simp_rw [vec3_add, Pi.add_apply]
apply vec3_eq <;> ring
Β· intros
simp_rw [smul_vec3, Pi.smul_apply, smul_sub, mul_smul_comm]
@[inherit_doc] scoped[Matrix] infixl:74 " Γβ " => crossProduct
theorem cross_apply (a b : Fin 3 β R) :
a Γβ b = ![a 1 * b 2 - a 2 * b 1, a 2 * b 0 - a 0 * b 2, a 0 * b 1 - a 1 * b 0] := rfl
section ProductsProperties
@[simp]
theorem cross_anticomm (v w : Fin 3 β R) : -(v Γβ w) = w Γβ v := by
simp [cross_apply, mul_comm]
alias neg_cross := cross_anticomm
@[simp]
theorem cross_anticomm' (v w : Fin 3 β R) : v Γβ w + w Γβ v = 0 := by
rw [add_eq_zero_iff_eq_neg, cross_anticomm]
@[simp]
theorem cross_self (v : Fin 3 β R) : v Γβ v = 0 := by
simp [cross_apply, mul_comm]
/-- The cross product of two vectors is perpendicular to the first vector. -/
@[simp]
theorem dot_self_cross (v w : Fin 3 β R) : v β¬α΅₯ v Γβ w = 0 := by
rw [cross_apply, vec3_dotProduct]
dsimp only [Matrix.cons_val]
ring
/-- The cross product of two vectors is perpendicular to the second vector. -/
@[simp]
theorem dot_cross_self (v w : Fin 3 β R) : w β¬α΅₯ v Γβ w = 0 := by
rw [β cross_anticomm, dotProduct_neg, dot_self_cross, neg_zero]
/-- Cyclic permutations preserve the triple product. See also `triple_product_eq_det`. -/
theorem triple_product_permutation (u v w : Fin 3 β R) : u β¬α΅₯ v Γβ w = v β¬α΅₯ w Γβ u := by
| simp_rw [cross_apply, vec3_dotProduct]
dsimp only [Matrix.cons_val]
| Mathlib/LinearAlgebra/CrossProduct.lean | 94 | 95 |
/-
Copyright (c) 2018 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
-/
import Mathlib.Algebra.Order.Ring.Nat
import Mathlib.Logic.Encodable.Pi
import Mathlib.Logic.Function.Iterate
/-!
# The primitive recursive functions
The primitive recursive functions are the least collection of functions
`β β β` which are closed under projections (using the `pair`
pairing function), composition, zero, successor, and primitive recursion
(i.e. `Nat.rec` where the motive is `C n := β`).
We can extend this definition to a large class of basic types by
using canonical encodings of types as natural numbers (GΓΆdel numbering),
which we implement through the type class `Encodable`. (More precisely,
we need that the composition of encode with decode yields a
primitive recursive function, so we have the `Primcodable` type class
for this.)
In the above, the pairing function is primitive recursive by definition.
This deviates from the textbook definition of primitive recursive functions,
which instead work with *`n`-ary* functions. We formalize the textbook
definition in `Nat.Primrec'`. `Nat.Primrec'.prim_iff` then proves it is
equivalent to our chosen formulation. For more discussionn of this and
other design choices in this formalization, see [carneiro2019].
## Main definitions
- `Nat.Primrec f`: `f` is primitive recursive, for functions `f : β β β`
- `Primrec f`: `f` is primitive recursive, for functions between `Primcodable` types
- `Primcodable Ξ±`: well-behaved encoding of `Ξ±` into `β`, i.e. one such that roundtripping through
the encoding functions adds no computational power
## References
* [Mario Carneiro, *Formalizing computability theory via partial recursive functions*][carneiro2019]
-/
open List (Vector)
open Denumerable Encodable Function
namespace Nat
/-- Calls the given function on a pair of entries `n`, encoded via the pairing function. -/
@[simp, reducible]
def unpaired {Ξ±} (f : β β β β Ξ±) (n : β) : Ξ± :=
f n.unpair.1 n.unpair.2
/-- The primitive recursive functions `β β β`. -/
protected inductive Primrec : (β β β) β Prop
| zero : Nat.Primrec fun _ => 0
| protected succ : Nat.Primrec succ
| left : Nat.Primrec fun n => n.unpair.1
| right : Nat.Primrec fun n => n.unpair.2
| pair {f g} : Nat.Primrec f β Nat.Primrec g β Nat.Primrec fun n => pair (f n) (g n)
| comp {f g} : Nat.Primrec f β Nat.Primrec g β Nat.Primrec fun n => f (g n)
| prec {f g} :
Nat.Primrec f β
Nat.Primrec g β
Nat.Primrec (unpaired fun z n => n.rec (f z) fun y IH => g <| pair z <| pair y IH)
namespace Primrec
theorem of_eq {f g : β β β} (hf : Nat.Primrec f) (H : β n, f n = g n) : Nat.Primrec g :=
(funext H : f = g) βΈ hf
theorem const : β n : β, Nat.Primrec fun _ => n
| 0 => zero
| n + 1 => Primrec.succ.comp (const n)
protected theorem id : Nat.Primrec id :=
(left.pair right).of_eq fun n => by simp
theorem prec1 {f} (m : β) (hf : Nat.Primrec f) :
Nat.Primrec fun n => n.rec m fun y IH => f <| Nat.pair y IH :=
((prec (const m) (hf.comp right)).comp (zero.pair Primrec.id)).of_eq fun n => by simp
theorem casesOn1 {f} (m : β) (hf : Nat.Primrec f) : Nat.Primrec (Nat.casesOn Β· m f) :=
(prec1 m (hf.comp left)).of_eq <| by simp
-- Porting note: `Nat.Primrec.casesOn` is already declared as a recursor.
theorem casesOn' {f g} (hf : Nat.Primrec f) (hg : Nat.Primrec g) :
Nat.Primrec (unpaired fun z n => n.casesOn (f z) fun y => g <| Nat.pair z y) :=
(prec hf (hg.comp (pair left (left.comp right)))).of_eq fun n => by simp
protected theorem swap : Nat.Primrec (unpaired (swap Nat.pair)) :=
(pair right left).of_eq fun n => by simp
theorem swap' {f} (hf : Nat.Primrec (unpaired f)) : Nat.Primrec (unpaired (swap f)) :=
(hf.comp .swap).of_eq fun n => by simp
theorem pred : Nat.Primrec pred :=
(casesOn1 0 Primrec.id).of_eq fun n => by cases n <;> simp [*]
theorem add : Nat.Primrec (unpaired (Β· + Β·)) :=
(prec .id ((Primrec.succ.comp right).comp right)).of_eq fun p => by
simp; induction p.unpair.2 <;> simp [*, Nat.add_assoc]
theorem sub : Nat.Primrec (unpaired (Β· - Β·)) :=
(prec .id ((pred.comp right).comp right)).of_eq fun p => by
simp; induction p.unpair.2 <;> simp [*, Nat.sub_add_eq]
theorem mul : Nat.Primrec (unpaired (Β· * Β·)) :=
(prec zero (add.comp (pair left (right.comp right)))).of_eq fun p => by
simp; induction p.unpair.2 <;> simp [*, mul_succ, add_comm _ (unpair p).fst]
theorem pow : Nat.Primrec (unpaired (Β· ^ Β·)) :=
(prec (const 1) (mul.comp (pair (right.comp right) left))).of_eq fun p => by
simp; induction p.unpair.2 <;> simp [*, Nat.pow_succ]
end Primrec
end Nat
/-- A `Primcodable` type is, essentially, an `Encodable` type for which
the encode/decode functions are primitive recursive.
However, such a definition is circular.
Instead, we ask that the composition of `decode : β β Option Ξ±` with
`encode : Option Ξ± β β` is primitive recursive. Said composition is
the identity function, restricted to the image of `encode`.
Thus, in a way, the added requirement ensures that no predicates
can be smuggled in through a cunning choice of the subset of `β` into
which the type is encoded. -/
class Primcodable (Ξ± : Type*) extends Encodable Ξ± where
-- Porting note: was `prim [] `.
-- This means that `prim` does not take the type explicitly in Lean 4
prim : Nat.Primrec fun n => Encodable.encode (decode n)
namespace Primcodable
open Nat.Primrec
instance (priority := 10) ofDenumerable (Ξ±) [Denumerable Ξ±] : Primcodable Ξ± :=
β¨Nat.Primrec.succ.of_eq <| by simpβ©
/-- Builds a `Primcodable` instance from an equivalence to a `Primcodable` type. -/
def ofEquiv (Ξ±) {Ξ²} [Primcodable Ξ±] (e : Ξ² β Ξ±) : Primcodable Ξ² :=
{ __ := Encodable.ofEquiv Ξ± e
prim := (@Primcodable.prim Ξ± _).of_eq fun n => by
rw [decode_ofEquiv]
cases (@decode Ξ± _ n) <;>
simp [encode_ofEquiv] }
instance empty : Primcodable Empty :=
β¨zeroβ©
instance unit : Primcodable PUnit :=
β¨(casesOn1 1 zero).of_eq fun n => by cases n <;> simpβ©
instance option {Ξ± : Type*} [h : Primcodable Ξ±] : Primcodable (Option Ξ±) :=
β¨(casesOn1 1 ((casesOn1 0 (.comp .succ .succ)).comp (@Primcodable.prim Ξ± _))).of_eq fun n => by
cases n with
| zero => rfl
| succ n =>
rw [decode_option_succ]
cases H : @decode Ξ± _ n <;> simp [H]β©
instance bool : Primcodable Bool :=
β¨(casesOn1 1 (casesOn1 2 zero)).of_eq fun n => match n with
| 0 => rfl
| 1 => rfl
| (n + 2) => by rw [decode_ge_two] <;> simpβ©
end Primcodable
/-- `Primrec f` means `f` is primitive recursive (after
encoding its input and output as natural numbers). -/
def Primrec {Ξ± Ξ²} [Primcodable Ξ±] [Primcodable Ξ²] (f : Ξ± β Ξ²) : Prop :=
Nat.Primrec fun n => encode ((@decode Ξ± _ n).map f)
namespace Primrec
variable {Ξ± : Type*} {Ξ² : Type*} {Ο : Type*}
variable [Primcodable Ξ±] [Primcodable Ξ²] [Primcodable Ο]
open Nat.Primrec
protected theorem encode : Primrec (@encode Ξ± _) :=
(@Primcodable.prim Ξ± _).of_eq fun n => by cases @decode Ξ± _ n <;> rfl
protected theorem decode : Primrec (@decode Ξ± _) :=
Nat.Primrec.succ.comp (@Primcodable.prim Ξ± _)
theorem dom_denumerable {Ξ± Ξ²} [Denumerable Ξ±] [Primcodable Ξ²] {f : Ξ± β Ξ²} :
Primrec f β Nat.Primrec fun n => encode (f (ofNat Ξ± n)) :=
β¨fun h => (pred.comp h).of_eq fun n => by simp, fun h =>
(Nat.Primrec.succ.comp h).of_eq fun n => by simpβ©
theorem nat_iff {f : β β β} : Primrec f β Nat.Primrec f :=
dom_denumerable
theorem encdec : Primrec fun n => encode (@decode Ξ± _ n) :=
nat_iff.2 Primcodable.prim
theorem option_some : Primrec (@some Ξ±) :=
((casesOn1 0 (Nat.Primrec.succ.comp .succ)).comp (@Primcodable.prim Ξ± _)).of_eq fun n => by
cases @decode Ξ± _ n <;> simp
theorem of_eq {f g : Ξ± β Ο} (hf : Primrec f) (H : β n, f n = g n) : Primrec g :=
(funext H : f = g) βΈ hf
theorem const (x : Ο) : Primrec fun _ : Ξ± => x :=
((casesOn1 0 (.const (encode x).succ)).comp (@Primcodable.prim Ξ± _)).of_eq fun n => by
cases @decode Ξ± _ n <;> rfl
protected theorem id : Primrec (@id Ξ±) :=
(@Primcodable.prim Ξ±).of_eq <| by simp
theorem comp {f : Ξ² β Ο} {g : Ξ± β Ξ²} (hf : Primrec f) (hg : Primrec g) : Primrec fun a => f (g a) :=
((casesOn1 0 (.comp hf (pred.comp hg))).comp (@Primcodable.prim Ξ± _)).of_eq fun n => by
cases @decode Ξ± _ n <;> simp [encodek]
theorem succ : Primrec Nat.succ :=
nat_iff.2 Nat.Primrec.succ
theorem pred : Primrec Nat.pred :=
nat_iff.2 Nat.Primrec.pred
theorem encode_iff {f : Ξ± β Ο} : (Primrec fun a => encode (f a)) β Primrec f :=
β¨fun h => Nat.Primrec.of_eq h fun n => by cases @decode Ξ± _ n <;> rfl, Primrec.encode.compβ©
theorem ofNat_iff {Ξ± Ξ²} [Denumerable Ξ±] [Primcodable Ξ²] {f : Ξ± β Ξ²} :
Primrec f β Primrec fun n => f (ofNat Ξ± n) :=
dom_denumerable.trans <| nat_iff.symm.trans encode_iff
protected theorem ofNat (Ξ±) [Denumerable Ξ±] : Primrec (ofNat Ξ±) :=
ofNat_iff.1 Primrec.id
theorem option_some_iff {f : Ξ± β Ο} : (Primrec fun a => some (f a)) β Primrec f :=
β¨fun h => encode_iff.1 <| pred.comp <| encode_iff.2 h, option_some.compβ©
theorem of_equiv {Ξ²} {e : Ξ² β Ξ±} :
haveI := Primcodable.ofEquiv Ξ± e
Primrec e :=
letI : Primcodable Ξ² := Primcodable.ofEquiv Ξ± e
encode_iff.1 Primrec.encode
theorem of_equiv_symm {Ξ²} {e : Ξ² β Ξ±} :
haveI := Primcodable.ofEquiv Ξ± e
Primrec e.symm :=
letI := Primcodable.ofEquiv Ξ± e
encode_iff.1 (show Primrec fun a => encode (e (e.symm a)) by simp [Primrec.encode])
theorem of_equiv_iff {Ξ²} (e : Ξ² β Ξ±) {f : Ο β Ξ²} :
haveI := Primcodable.ofEquiv Ξ± e
(Primrec fun a => e (f a)) β Primrec f :=
letI := Primcodable.ofEquiv Ξ± e
β¨fun h => (of_equiv_symm.comp h).of_eq fun a => by simp, of_equiv.compβ©
theorem of_equiv_symm_iff {Ξ²} (e : Ξ² β Ξ±) {f : Ο β Ξ±} :
haveI := Primcodable.ofEquiv Ξ± e
(Primrec fun a => e.symm (f a)) β Primrec f :=
letI := Primcodable.ofEquiv Ξ± e
β¨fun h => (of_equiv.comp h).of_eq fun a => by simp, of_equiv_symm.compβ©
end Primrec
namespace Primcodable
open Nat.Primrec
instance prod {Ξ± Ξ²} [Primcodable Ξ±] [Primcodable Ξ²] : Primcodable (Ξ± Γ Ξ²) :=
β¨((casesOn' zero ((casesOn' zero .succ).comp (pair right ((@Primcodable.prim Ξ²).comp left)))).comp
(pair right ((@Primcodable.prim Ξ±).comp left))).of_eq
fun n => by
simp only [Nat.unpaired, Nat.unpair_pair, decode_prod_val]
cases @decode Ξ± _ n.unpair.1; Β· simp
cases @decode Ξ² _ n.unpair.2 <;> simpβ©
end Primcodable
namespace Primrec
variable {Ξ± : Type*} [Primcodable Ξ±]
open Nat.Primrec
theorem fst {Ξ± Ξ²} [Primcodable Ξ±] [Primcodable Ξ²] : Primrec (@Prod.fst Ξ± Ξ²) :=
((casesOn' zero
((casesOn' zero (Nat.Primrec.succ.comp left)).comp
(pair right ((@Primcodable.prim Ξ²).comp left)))).comp
(pair right ((@Primcodable.prim Ξ±).comp left))).of_eq
fun n => by
simp only [Nat.unpaired, Nat.unpair_pair, decode_prod_val]
cases @decode Ξ± _ n.unpair.1 <;> simp
cases @decode Ξ² _ n.unpair.2 <;> simp
theorem snd {Ξ± Ξ²} [Primcodable Ξ±] [Primcodable Ξ²] : Primrec (@Prod.snd Ξ± Ξ²) :=
((casesOn' zero
((casesOn' zero (Nat.Primrec.succ.comp right)).comp
(pair right ((@Primcodable.prim Ξ²).comp left)))).comp
(pair right ((@Primcodable.prim Ξ±).comp left))).of_eq
fun n => by
simp only [Nat.unpaired, Nat.unpair_pair, decode_prod_val]
cases @decode Ξ± _ n.unpair.1 <;> simp
cases @decode Ξ² _ n.unpair.2 <;> simp
theorem pair {Ξ± Ξ² Ξ³} [Primcodable Ξ±] [Primcodable Ξ²] [Primcodable Ξ³] {f : Ξ± β Ξ²} {g : Ξ± β Ξ³}
(hf : Primrec f) (hg : Primrec g) : Primrec fun a => (f a, g a) :=
((casesOn1 0
(Nat.Primrec.succ.comp <|
.pair (Nat.Primrec.pred.comp hf) (Nat.Primrec.pred.comp hg))).comp
(@Primcodable.prim Ξ± _)).of_eq
fun n => by cases @decode Ξ± _ n <;> simp [encodek]
theorem unpair : Primrec Nat.unpair :=
(pair (nat_iff.2 .left) (nat_iff.2 .right)).of_eq fun n => by simp
theorem list_getElem?β : β l : List Ξ±, Primrec (l[Β·]? : β β Option Ξ±)
| [] => dom_denumerable.2 zero
| a :: l =>
dom_denumerable.2 <|
(casesOn1 (encode a).succ <| dom_denumerable.1 <| list_getElem?β l).of_eq fun n => by
cases n <;> simp
@[deprecated (since := "2025-02-14")] alias list_get?β := list_getElem?β
end Primrec
/-- `Primrecβ f` means `f` is a binary primitive recursive function.
This is technically unnecessary since we can always curry all
the arguments together, but there are enough natural two-arg
functions that it is convenient to express this directly. -/
def Primrecβ {Ξ± Ξ² Ο} [Primcodable Ξ±] [Primcodable Ξ²] [Primcodable Ο] (f : Ξ± β Ξ² β Ο) :=
Primrec fun p : Ξ± Γ Ξ² => f p.1 p.2
/-- `PrimrecPred p` means `p : Ξ± β Prop` is a (decidable)
primitive recursive predicate, which is to say that
`decide β p : Ξ± β Bool` is primitive recursive. -/
def PrimrecPred {Ξ±} [Primcodable Ξ±] (p : Ξ± β Prop) [DecidablePred p] :=
Primrec fun a => decide (p a)
/-- `PrimrecRel p` means `p : Ξ± β Ξ² β Prop` is a (decidable)
primitive recursive relation, which is to say that
`decide β p : Ξ± β Ξ² β Bool` is primitive recursive. -/
def PrimrecRel {Ξ± Ξ²} [Primcodable Ξ±] [Primcodable Ξ²] (s : Ξ± β Ξ² β Prop)
[β a b, Decidable (s a b)] :=
Primrecβ fun a b => decide (s a b)
namespace Primrecβ
variable {Ξ± : Type*} {Ξ² : Type*} {Ο : Type*}
variable [Primcodable Ξ±] [Primcodable Ξ²] [Primcodable Ο]
theorem mk {f : Ξ± β Ξ² β Ο} (hf : Primrec fun p : Ξ± Γ Ξ² => f p.1 p.2) : Primrecβ f := hf
theorem of_eq {f g : Ξ± β Ξ² β Ο} (hg : Primrecβ f) (H : β a b, f a b = g a b) : Primrecβ g :=
(by funext a b; apply H : f = g) βΈ hg
theorem const (x : Ο) : Primrecβ fun (_ : Ξ±) (_ : Ξ²) => x :=
Primrec.const _
protected theorem pair : Primrecβ (@Prod.mk Ξ± Ξ²) :=
Primrec.pair .fst .snd
theorem left : Primrecβ fun (a : Ξ±) (_ : Ξ²) => a :=
.fst
theorem right : Primrecβ fun (_ : Ξ±) (b : Ξ²) => b :=
.snd
theorem natPair : Primrecβ Nat.pair := by simp [Primrecβ, Primrec]; constructor
theorem unpaired {f : β β β β Ξ±} : Primrec (Nat.unpaired f) β Primrecβ f :=
β¨fun h => by simpa using h.comp natPair, fun h => h.comp Primrec.unpairβ©
theorem unpaired' {f : β β β β β} : Nat.Primrec (Nat.unpaired f) β Primrecβ f :=
Primrec.nat_iff.symm.trans unpaired
theorem encode_iff {f : Ξ± β Ξ² β Ο} : (Primrecβ fun a b => encode (f a b)) β Primrecβ f :=
Primrec.encode_iff
theorem option_some_iff {f : Ξ± β Ξ² β Ο} : (Primrecβ fun a b => some (f a b)) β Primrecβ f :=
Primrec.option_some_iff
theorem ofNat_iff {Ξ± Ξ² Ο} [Denumerable Ξ±] [Denumerable Ξ²] [Primcodable Ο] {f : Ξ± β Ξ² β Ο} :
Primrecβ f β Primrecβ fun m n : β => f (ofNat Ξ± m) (ofNat Ξ² n) :=
(Primrec.ofNat_iff.trans <| by simp).trans unpaired
theorem uncurry {f : Ξ± β Ξ² β Ο} : Primrec (Function.uncurry f) β Primrecβ f := by
rw [show Function.uncurry f = fun p : Ξ± Γ Ξ² => f p.1 p.2 from funext fun β¨a, bβ© => rfl]; rfl
theorem curry {f : Ξ± Γ Ξ² β Ο} : Primrecβ (Function.curry f) β Primrec f := by
rw [β uncurry, Function.uncurry_curry]
end Primrecβ
section Comp
variable {Ξ± : Type*} {Ξ² : Type*} {Ξ³ : Type*} {Ξ΄ : Type*} {Ο : Type*}
variable [Primcodable Ξ±] [Primcodable Ξ²] [Primcodable Ξ³] [Primcodable Ξ΄] [Primcodable Ο]
theorem Primrec.compβ {f : Ξ³ β Ο} {g : Ξ± β Ξ² β Ξ³} (hf : Primrec f) (hg : Primrecβ g) :
Primrecβ fun a b => f (g a b) :=
hf.comp hg
theorem Primrecβ.comp {f : Ξ² β Ξ³ β Ο} {g : Ξ± β Ξ²} {h : Ξ± β Ξ³} (hf : Primrecβ f) (hg : Primrec g)
(hh : Primrec h) : Primrec fun a => f (g a) (h a) :=
Primrec.comp hf (hg.pair hh)
theorem Primrecβ.compβ {f : Ξ³ β Ξ΄ β Ο} {g : Ξ± β Ξ² β Ξ³} {h : Ξ± β Ξ² β Ξ΄} (hf : Primrecβ f)
(hg : Primrecβ g) (hh : Primrecβ h) : Primrecβ fun a b => f (g a b) (h a b) :=
hf.comp hg hh
theorem PrimrecPred.comp {p : Ξ² β Prop} [DecidablePred p] {f : Ξ± β Ξ²} :
PrimrecPred p β Primrec f β PrimrecPred fun a => p (f a) :=
Primrec.comp
theorem PrimrecRel.comp {R : Ξ² β Ξ³ β Prop} [β a b, Decidable (R a b)] {f : Ξ± β Ξ²} {g : Ξ± β Ξ³} :
PrimrecRel R β Primrec f β Primrec g β PrimrecPred fun a => R (f a) (g a) :=
Primrecβ.comp
theorem PrimrecRel.compβ {R : Ξ³ β Ξ΄ β Prop} [β a b, Decidable (R a b)] {f : Ξ± β Ξ² β Ξ³}
{g : Ξ± β Ξ² β Ξ΄} :
PrimrecRel R β Primrecβ f β Primrecβ g β PrimrecRel fun a b => R (f a b) (g a b) :=
PrimrecRel.comp
end Comp
theorem PrimrecPred.of_eq {Ξ±} [Primcodable Ξ±] {p q : Ξ± β Prop} [DecidablePred p] [DecidablePred q]
(hp : PrimrecPred p) (H : β a, p a β q a) : PrimrecPred q :=
Primrec.of_eq hp fun a => Bool.decide_congr (H a)
theorem PrimrecRel.of_eq {Ξ± Ξ²} [Primcodable Ξ±] [Primcodable Ξ²] {r s : Ξ± β Ξ² β Prop}
[β a b, Decidable (r a b)] [β a b, Decidable (s a b)] (hr : PrimrecRel r)
(H : β a b, r a b β s a b) : PrimrecRel s :=
Primrecβ.of_eq hr fun a b => Bool.decide_congr (H a b)
namespace Primrecβ
variable {Ξ± : Type*} {Ξ² : Type*} {Ο : Type*}
variable [Primcodable Ξ±] [Primcodable Ξ²] [Primcodable Ο]
open Nat.Primrec
theorem swap {f : Ξ± β Ξ² β Ο} (h : Primrecβ f) : Primrecβ (swap f) :=
h.compβ Primrecβ.right Primrecβ.left
theorem nat_iff {f : Ξ± β Ξ² β Ο} : Primrecβ f β Nat.Primrec
(.unpaired fun m n => encode <| (@decode Ξ± _ m).bind fun a => (@decode Ξ² _ n).map (f a)) := by
have :
β (a : Option Ξ±) (b : Option Ξ²),
Option.map (fun p : Ξ± Γ Ξ² => f p.1 p.2)
(Option.bind a fun a : Ξ± => Option.map (Prod.mk a) b) =
Option.bind a fun a => Option.map (f a) b := fun a b => by
cases a <;> cases b <;> rfl
simp [Primrecβ, Primrec, this]
theorem nat_iff' {f : Ξ± β Ξ² β Ο} :
Primrecβ f β
Primrecβ fun m n : β => (@decode Ξ± _ m).bind fun a => Option.map (f a) (@decode Ξ² _ n) :=
nat_iff.trans <| unpaired'.trans encode_iff
end Primrecβ
namespace Primrec
variable {Ξ± : Type*} {Ξ² : Type*} {Ο : Type*}
variable [Primcodable Ξ±] [Primcodable Ξ²] [Primcodable Ο]
theorem toβ {f : Ξ± Γ Ξ² β Ο} (hf : Primrec f) : Primrecβ fun a b => f (a, b) :=
hf.of_eq fun _ => rfl
theorem nat_rec {f : Ξ± β Ξ²} {g : Ξ± β β Γ Ξ² β Ξ²} (hf : Primrec f) (hg : Primrecβ g) :
Primrecβ fun a (n : β) => n.rec (motive := fun _ => Ξ²) (f a) fun n IH => g a (n, IH) :=
Primrecβ.nat_iff.2 <|
((Nat.Primrec.casesOn' .zero <|
(Nat.Primrec.prec hf <|
.comp hg <|
Nat.Primrec.left.pair <|
(Nat.Primrec.left.comp .right).pair <|
Nat.Primrec.pred.comp <| Nat.Primrec.right.comp .right).comp <|
Nat.Primrec.right.pair <| Nat.Primrec.right.comp Nat.Primrec.left).comp <|
Nat.Primrec.id.pair <| (@Primcodable.prim Ξ±).comp Nat.Primrec.left).of_eq
fun n => by
simp only [Nat.unpaired, id_eq, Nat.unpair_pair, decode_prod_val, decode_nat,
Option.some_bind, Option.map_map, Option.map_some']
rcases @decode Ξ± _ n.unpair.1 with - | a; Β· rfl
simp only [Nat.pred_eq_sub_one, encode_some, Nat.succ_eq_add_one, encodek, Option.map_some',
Option.some_bind, Option.map_map]
induction' n.unpair.2 with m <;> simp [encodek]
simp [*, encodek]
theorem nat_rec' {f : Ξ± β β} {g : Ξ± β Ξ²} {h : Ξ± β β Γ Ξ² β Ξ²}
(hf : Primrec f) (hg : Primrec g) (hh : Primrecβ h) :
Primrec fun a => (f a).rec (motive := fun _ => Ξ²) (g a) fun n IH => h a (n, IH) :=
(nat_rec hg hh).comp .id hf
theorem nat_recβ {f : β β Ξ± β Ξ±} (a : Ξ±) (hf : Primrecβ f) : Primrec (Nat.rec a f) :=
nat_rec' .id (const a) <| compβ hf Primrecβ.right
theorem nat_casesOn' {f : Ξ± β Ξ²} {g : Ξ± β β β Ξ²} (hf : Primrec f) (hg : Primrecβ g) :
Primrecβ fun a (n : β) => (n.casesOn (f a) (g a) : Ξ²) :=
nat_rec hf <| hg.compβ Primrecβ.left <| compβ fst Primrecβ.right
theorem nat_casesOn {f : Ξ± β β} {g : Ξ± β Ξ²} {h : Ξ± β β β Ξ²} (hf : Primrec f) (hg : Primrec g)
(hh : Primrecβ h) : Primrec fun a => ((f a).casesOn (g a) (h a) : Ξ²) :=
(nat_casesOn' hg hh).comp .id hf
theorem nat_casesOnβ {f : β β Ξ±} (a : Ξ±) (hf : Primrec f) :
Primrec (fun (n : β) => (n.casesOn a f : Ξ±)) :=
nat_casesOn .id (const a) (compβ hf .right)
theorem nat_iterate {f : Ξ± β β} {g : Ξ± β Ξ²} {h : Ξ± β Ξ² β Ξ²} (hf : Primrec f) (hg : Primrec g)
(hh : Primrecβ h) : Primrec fun a => (h a)^[f a] (g a) :=
(nat_rec' hf hg (hh.compβ Primrecβ.left <| snd.compβ Primrecβ.right)).of_eq fun a => by
induction f a <;> simp [*, -Function.iterate_succ, Function.iterate_succ']
theorem option_casesOn {o : Ξ± β Option Ξ²} {f : Ξ± β Ο} {g : Ξ± β Ξ² β Ο} (ho : Primrec o)
(hf : Primrec f) (hg : Primrecβ g) :
@Primrec _ Ο _ _ fun a => Option.casesOn (o a) (f a) (g a) :=
encode_iff.1 <|
(nat_casesOn (encode_iff.2 ho) (encode_iff.2 hf) <|
pred.compβ <|
Primrecβ.encode_iff.2 <|
(Primrecβ.nat_iff'.1 hg).compβ ((@Primrec.encode Ξ± _).comp fst).toβ
Primrecβ.right).of_eq
fun a => by rcases o a with - | b <;> simp [encodek]
theorem option_bind {f : Ξ± β Option Ξ²} {g : Ξ± β Ξ² β Option Ο} (hf : Primrec f) (hg : Primrecβ g) :
Primrec fun a => (f a).bind (g a) :=
(option_casesOn hf (const none) hg).of_eq fun a => by cases f a <;> rfl
theorem option_bindβ {f : Ξ± β Option Ο} (hf : Primrec f) : Primrec fun o => Option.bind o f :=
option_bind .id (hf.comp snd).toβ
theorem option_map {f : Ξ± β Option Ξ²} {g : Ξ± β Ξ² β Ο} (hf : Primrec f) (hg : Primrecβ g) :
Primrec fun a => (f a).map (g a) :=
(option_bind hf (option_some.compβ hg)).of_eq fun x => by cases f x <;> rfl
theorem option_mapβ {f : Ξ± β Ο} (hf : Primrec f) : Primrec (Option.map f) :=
option_map .id (hf.comp snd).toβ
theorem option_iget [Inhabited Ξ±] : Primrec (@Option.iget Ξ± _) :=
(option_casesOn .id (const <| @default Ξ± _) .right).of_eq fun o => by cases o <;> rfl
theorem option_isSome : Primrec (@Option.isSome Ξ±) :=
(option_casesOn .id (const false) (const true).toβ).of_eq fun o => by cases o <;> rfl
theorem option_getD : Primrecβ (@Option.getD Ξ±) :=
Primrec.of_eq (option_casesOn Primrecβ.left Primrecβ.right .right) fun β¨o, aβ© => by
cases o <;> rfl
theorem bind_decode_iff {f : Ξ± β Ξ² β Option Ο} :
(Primrecβ fun a n => (@decode Ξ² _ n).bind (f a)) β Primrecβ f :=
β¨fun h => by simpa [encodek] using h.comp fst ((@Primrec.encode Ξ² _).comp snd), fun h =>
option_bind (Primrec.decode.comp snd) <| h.comp (fst.comp fst) sndβ©
theorem map_decode_iff {f : Ξ± β Ξ² β Ο} :
(Primrecβ fun a n => (@decode Ξ² _ n).map (f a)) β Primrecβ f := by
simp only [Option.map_eq_bind]
exact bind_decode_iff.trans Primrecβ.option_some_iff
theorem nat_add : Primrecβ ((Β· + Β·) : β β β β β) :=
Primrecβ.unpaired'.1 Nat.Primrec.add
theorem nat_sub : Primrecβ ((Β· - Β·) : β β β β β) :=
Primrecβ.unpaired'.1 Nat.Primrec.sub
theorem nat_mul : Primrecβ ((Β· * Β·) : β β β β β) :=
Primrecβ.unpaired'.1 Nat.Primrec.mul
theorem cond {c : Ξ± β Bool} {f : Ξ± β Ο} {g : Ξ± β Ο} (hc : Primrec c) (hf : Primrec f)
(hg : Primrec g) : Primrec fun a => bif (c a) then (f a) else (g a) :=
(nat_casesOn (encode_iff.2 hc) hg (hf.comp fst).toβ).of_eq fun a => by cases c a <;> rfl
theorem ite {c : Ξ± β Prop} [DecidablePred c] {f : Ξ± β Ο} {g : Ξ± β Ο} (hc : PrimrecPred c)
(hf : Primrec f) (hg : Primrec g) : Primrec fun a => if c a then f a else g a := by
simpa [Bool.cond_decide] using cond hc hf hg
theorem nat_le : PrimrecRel ((Β· β€ Β·) : β β β β Prop) :=
(nat_casesOn nat_sub (const true) (const false).toβ).of_eq fun p => by
dsimp [swap]
rcases e : p.1 - p.2 with - | n
Β· simp [Nat.sub_eq_zero_iff_le.1 e]
Β· simp [not_le.2 (Nat.lt_of_sub_eq_succ e)]
theorem nat_min : Primrecβ (@min β _) :=
ite nat_le fst snd
theorem nat_max : Primrecβ (@max β _) :=
ite (nat_le.comp fst snd) snd fst
theorem dom_bool (f : Bool β Ξ±) : Primrec f :=
(cond .id (const (f true)) (const (f false))).of_eq fun b => by cases b <;> rfl
theorem dom_boolβ (f : Bool β Bool β Ξ±) : Primrecβ f :=
(cond fst ((dom_bool (f true)).comp snd) ((dom_bool (f false)).comp snd)).of_eq fun β¨a, bβ© => by
cases a <;> rfl
protected theorem not : Primrec not :=
dom_bool _
protected theorem and : Primrecβ and :=
dom_boolβ _
protected theorem or : Primrecβ or :=
dom_boolβ _
theorem _root_.PrimrecPred.not {p : Ξ± β Prop} [DecidablePred p] (hp : PrimrecPred p) :
PrimrecPred fun a => Β¬p a :=
(Primrec.not.comp hp).of_eq fun n => by simp
theorem _root_.PrimrecPred.and {p q : Ξ± β Prop} [DecidablePred p] [DecidablePred q]
(hp : PrimrecPred p) (hq : PrimrecPred q) : PrimrecPred fun a => p a β§ q a :=
(Primrec.and.comp hp hq).of_eq fun n => by simp
theorem _root_.PrimrecPred.or {p q : Ξ± β Prop} [DecidablePred p] [DecidablePred q]
(hp : PrimrecPred p) (hq : PrimrecPred q) : PrimrecPred fun a => p a β¨ q a :=
(Primrec.or.comp hp hq).of_eq fun n => by simp
protected theorem beq [DecidableEq Ξ±] : Primrecβ (@BEq.beq Ξ± _) :=
have : PrimrecRel fun a b : β => a = b :=
(PrimrecPred.and nat_le nat_le.swap).of_eq fun a => by simp [le_antisymm_iff]
(this.compβ (Primrec.encode.compβ Primrecβ.left) (Primrec.encode.compβ Primrecβ.right)).of_eq
fun _ _ => encode_injective.eq_iff
protected theorem eq [DecidableEq Ξ±] : PrimrecRel (@Eq Ξ±) := Primrec.beq
theorem nat_lt : PrimrecRel ((Β· < Β·) : β β β β Prop) :=
(nat_le.comp snd fst).not.of_eq fun p => by simp
theorem option_guard {p : Ξ± β Ξ² β Prop} [β a b, Decidable (p a b)] (hp : PrimrecRel p) {f : Ξ± β Ξ²}
(hf : Primrec f) : Primrec fun a => Option.guard (p a) (f a) :=
ite (hp.comp Primrec.id hf) (option_some_iff.2 hf) (const none)
theorem option_orElse : Primrecβ ((Β· <|> Β·) : Option Ξ± β Option Ξ± β Option Ξ±) :=
(option_casesOn fst snd (fst.comp fst).toβ).of_eq fun β¨oβ, oββ© => by cases oβ <;> cases oβ <;> rfl
protected theorem decodeβ : Primrec (decodeβ Ξ±) :=
option_bind .decode <|
option_guard (Primrec.beq.compβ (by exact encode_iff.mpr snd) (by exact fst.comp fst)) snd
theorem list_findIdxβ {p : Ξ± β Ξ² β Bool} (hp : Primrecβ p) :
β l : List Ξ², Primrec fun a => l.findIdx (p a)
| [] => const 0
| a :: l => (cond (hp.comp .id (const a)) (const 0) (succ.comp (list_findIdxβ hp l))).of_eq fun n =>
by simp [List.findIdx_cons]
theorem list_idxOfβ [DecidableEq Ξ±] (l : List Ξ±) : Primrec fun a => l.idxOf a :=
list_findIdxβ (.swap .beq) l
@[deprecated (since := "2025-01-30")] alias list_indexOfβ := list_idxOfβ
theorem dom_fintype [Finite Ξ±] (f : Ξ± β Ο) : Primrec f :=
let β¨l, _, mβ© := Finite.exists_univ_list Ξ±
option_some_iff.1 <| by
haveI := decidableEqOfEncodable Ξ±
refine ((list_getElem?β (l.map f)).comp (list_idxOfβ l)).of_eq fun a => ?_
rw [List.getElem?_map, List.getElem?_idxOf (m a), Option.map_some']
-- Porting note: These are new lemmas
-- I added it because it actually simplified the proofs
-- and because I couldn't understand the original proof
/-- A function is `PrimrecBounded` if its size is bounded by a primitive recursive function -/
def PrimrecBounded (f : Ξ± β Ξ²) : Prop :=
β g : Ξ± β β, Primrec g β§ β x, encode (f x) β€ g x
theorem nat_findGreatest {f : Ξ± β β} {p : Ξ± β β β Prop} [β x n, Decidable (p x n)]
(hf : Primrec f) (hp : PrimrecRel p) : Primrec fun x => (f x).findGreatest (p x) :=
(nat_rec' (h := fun x nih => if p x (nih.1 + 1) then nih.1 + 1 else nih.2)
hf (const 0) (ite (hp.comp fst (snd |> fst.comp |> succ.comp))
(snd |> fst.comp |> succ.comp) (snd.comp snd))).of_eq fun x => by
induction f x <;> simp [Nat.findGreatest, *]
/-- To show a function `f : Ξ± β β` is primitive recursive, it is enough to show that the function
is bounded by a primitive recursive function and that its graph is primitive recursive -/
theorem of_graph {f : Ξ± β β} (hβ : PrimrecBounded f)
(hβ : PrimrecRel fun a b => f a = b) : Primrec f := by
rcases hβ with β¨g, pg, hg : β x, f x β€ g xβ©
refine (nat_findGreatest pg hβ).of_eq fun n => ?_
exact (Nat.findGreatest_spec (P := fun b => f n = b) (hg n) rfl).symm
-- We show that division is primitive recursive by showing that the graph is
theorem nat_div : Primrecβ ((Β· / Β·) : β β β β β) := by
refine of_graph β¨_, fst, fun p => Nat.div_le_self _ _β© ?_
have : PrimrecRel fun (a : β Γ β) (b : β) => (a.2 = 0 β§ b = 0) β¨
(0 < a.2 β§ b * a.2 β€ a.1 β§ a.1 < (b + 1) * a.2) :=
PrimrecPred.or
(.and (const 0 |> Primrec.eq.comp (fst |> snd.comp)) (const 0 |> Primrec.eq.comp snd))
(.and (nat_lt.comp (const 0) (fst |> snd.comp)) <|
.and (nat_le.comp (nat_mul.comp snd (fst |> snd.comp)) (fst |> fst.comp))
(nat_lt.comp (fst.comp fst) (nat_mul.comp (Primrec.succ.comp snd) (snd.comp fst))))
refine this.of_eq ?_
rintro β¨a, kβ© q
if H : k = 0 then simp [H, eq_comm]
else
have : q * k β€ a β§ a < (q + 1) * k β q = a / k := by
rw [le_antisymm_iff, β (@Nat.lt_succ _ q), Nat.le_div_iff_mul_le (Nat.pos_of_ne_zero H),
Nat.div_lt_iff_lt_mul (Nat.pos_of_ne_zero H)]
simpa [H, zero_lt_iff, eq_comm (b := q)]
theorem nat_mod : Primrecβ ((Β· % Β·) : β β β β β) :=
(nat_sub.comp fst (nat_mul.comp snd nat_div)).toβ.of_eq fun m n => by
apply Nat.sub_eq_of_eq_add
simp [add_comm (m % n), Nat.div_add_mod]
theorem nat_bodd : Primrec Nat.bodd :=
(Primrec.beq.comp (nat_mod.comp .id (const 2)) (const 1)).of_eq fun n => by
cases H : n.bodd <;> simp [Nat.mod_two_of_bodd, H]
theorem nat_div2 : Primrec Nat.div2 :=
(nat_div.comp .id (const 2)).of_eq fun n => n.div2_val.symm
theorem nat_double : Primrec (fun n : β => 2 * n) :=
nat_mul.comp (const _) Primrec.id
theorem nat_double_succ : Primrec (fun n : β => 2 * n + 1) :=
nat_double |> Primrec.succ.comp
end Primrec
section
variable {Ξ± : Type*} {Ξ² : Type*} {Ο : Type*}
variable [Primcodable Ξ±] [Primcodable Ξ²] [Primcodable Ο]
variable (H : Nat.Primrec fun n => Encodable.encode (@decode (List Ξ²) _ n))
open Primrec
private def prim : Primcodable (List Ξ²) := β¨Hβ©
private theorem list_casesOn' {f : Ξ± β List Ξ²} {g : Ξ± β Ο} {h : Ξ± β Ξ² Γ List Ξ² β Ο}
(hf : haveI := prim H; Primrec f) (hg : Primrec g) (hh : haveI := prim H; Primrecβ h) :
@Primrec _ Ο _ _ fun a => List.casesOn (f a) (g a) fun b l => h a (b, l) :=
letI := prim H
have :
@Primrec _ (Option Ο) _ _ fun a =>
(@decode (Option (Ξ² Γ List Ξ²)) _ (encode (f a))).map fun o => Option.casesOn o (g a) (h a) :=
((@map_decode_iff _ (Option (Ξ² Γ List Ξ²)) _ _ _ _ _).2 <|
toβ <|
option_casesOn snd (hg.comp fst) (hh.compβ (fst.compβ Primrecβ.left) Primrecβ.right)).comp
.id (encode_iff.2 hf)
option_some_iff.1 <| this.of_eq fun a => by rcases f a with - | β¨b, lβ© <;> simp [encodek]
private theorem list_foldl' {f : Ξ± β List Ξ²} {g : Ξ± β Ο} {h : Ξ± β Ο Γ Ξ² β Ο}
(hf : haveI := prim H; Primrec f) (hg : Primrec g) (hh : haveI := prim H; Primrecβ h) :
Primrec fun a => (f a).foldl (fun s b => h a (s, b)) (g a) := by
letI := prim H
let G (a : Ξ±) (IH : Ο Γ List Ξ²) : Ο Γ List Ξ² := List.casesOn IH.2 IH fun b l => (h a (IH.1, b), l)
have hG : Primrecβ G := list_casesOn' H (snd.comp snd) snd <|
toβ <|
pair (hh.comp (fst.comp fst) <| pair ((fst.comp snd).comp fst) (fst.comp snd))
(snd.comp snd)
let F := fun (a : Ξ±) (n : β) => (G a)^[n] (g a, f a)
have hF : Primrec fun a => (F a (encode (f a))).1 :=
(fst.comp <|
nat_iterate (encode_iff.2 hf) (pair hg hf) <|
hG)
suffices β a n, F a n = (((f a).take n).foldl (fun s b => h a (s, b)) (g a), (f a).drop n) by
refine hF.of_eq fun a => ?_
rw [this, List.take_of_length_le (length_le_encode _)]
introv
dsimp only [F]
generalize f a = l
generalize g a = x
induction n generalizing l x with
| zero => rfl
| succ n IH =>
simp only [iterate_succ, comp_apply]
rcases l with - | β¨b, lβ© <;> simp [G, IH]
private theorem list_cons' : (haveI := prim H; Primrecβ (@List.cons Ξ²)) :=
letI := prim H
encode_iff.1 (succ.comp <| Primrecβ.natPair.comp (encode_iff.2 fst) (encode_iff.2 snd))
private theorem list_reverse' :
haveI := prim H
Primrec (@List.reverse Ξ²) :=
letI := prim H
(list_foldl' H .id (const []) <| toβ <| ((list_cons' H).comp snd fst).comp snd).of_eq
(suffices β l r, List.foldl (fun (s : List Ξ²) (b : Ξ²) => b :: s) r l = List.reverseAux l r from
fun l => this l []
fun l => by induction l <;> simp [*, List.reverseAux])
end
namespace Primcodable
variable {Ξ± : Type*} {Ξ² : Type*}
variable [Primcodable Ξ±] [Primcodable Ξ²]
open Primrec
instance sum : Primcodable (Ξ± β Ξ²) :=
β¨Primrec.nat_iff.1 <|
(encode_iff.2
(cond nat_bodd
(((@Primrec.decode Ξ² _).comp nat_div2).option_map <|
toβ <| nat_double_succ.comp (Primrec.encode.comp snd))
(((@Primrec.decode Ξ± _).comp nat_div2).option_map <|
toβ <| nat_double.comp (Primrec.encode.comp snd)))).of_eq
fun n =>
show _ = encode (decodeSum n) by
simp only [decodeSum, Nat.boddDiv2_eq]
cases Nat.bodd n <;> simp [decodeSum]
Β· cases @decode Ξ± _ n.div2 <;> rfl
Β· cases @decode Ξ² _ n.div2 <;> rflβ©
instance list : Primcodable (List Ξ±) :=
β¨letI H := @Primcodable.prim (List β) _
have : Primrecβ fun (a : Ξ±) (o : Option (List β)) => o.map (List.cons (encode a)) :=
option_map snd <| (list_cons' H).comp ((@Primrec.encode Ξ± _).comp (fst.comp fst)) snd
have :
Primrec fun n =>
(ofNat (List β) n).reverse.foldl
(fun o m => (@decode Ξ± _ m).bind fun a => o.map (List.cons (encode a))) (some []) :=
list_foldl' H ((list_reverse' H).comp (.ofNat (List β))) (const (some []))
(Primrec.compβ (bind_decode_iff.2 <| .swap this) Primrecβ.right)
nat_iff.1 <|
(encode_iff.2 this).of_eq fun n => by
rw [List.foldl_reverse]
apply Nat.case_strong_induction_on n; Β· simp
intro n IH; simp
rcases @decode Ξ± _ n.unpair.1 with - | a; Β· rfl
simp only [decode_eq_ofNat, Option.some.injEq, Option.some_bind, Option.map_some']
suffices β (o : Option (List β)) (p), encode o = encode p β
encode (Option.map (List.cons (encode a)) o) = encode (Option.map (List.cons a) p) from
this _ _ (IH _ (Nat.unpair_right_le n))
intro o p IH
cases o <;> cases p
Β· rfl
Β· injection IH
Β· injection IH
Β· exact congr_arg (fun k => (Nat.pair (encode a) k).succ.succ) (Nat.succ.inj IH)β©
end Primcodable
namespace Primrec
variable {Ξ± : Type*} {Ξ² : Type*} {Ξ³ : Type*} {Ο : Type*}
variable [Primcodable Ξ±] [Primcodable Ξ²] [Primcodable Ξ³] [Primcodable Ο]
theorem sumInl : Primrec (@Sum.inl Ξ± Ξ²) :=
encode_iff.1 <| nat_double.comp Primrec.encode
theorem sumInr : Primrec (@Sum.inr Ξ± Ξ²) :=
encode_iff.1 <| nat_double_succ.comp Primrec.encode
@[deprecated (since := "2025-02-21")] alias sum_inl := Primrec.sumInl
@[deprecated (since := "2025-02-21")] alias sum_inr := Primrec.sumInr
theorem sumCasesOn {f : Ξ± β Ξ² β Ξ³} {g : Ξ± β Ξ² β Ο} {h : Ξ± β Ξ³ β Ο} (hf : Primrec f)
(hg : Primrecβ g) (hh : Primrecβ h) : @Primrec _ Ο _ _ fun a => Sum.casesOn (f a) (g a) (h a) :=
option_some_iff.1 <|
(cond (nat_bodd.comp <| encode_iff.2 hf)
(option_map (Primrec.decode.comp <| nat_div2.comp <| encode_iff.2 hf) hh)
(option_map (Primrec.decode.comp <| nat_div2.comp <| encode_iff.2 hf) hg)).of_eq
fun a => by rcases f a with b | c <;> simp [Nat.div2_val, encodek]
@[deprecated (since := "2025-02-21")] alias sum_casesOn := Primrec.sumCasesOn
theorem list_cons : Primrecβ (@List.cons Ξ±) :=
list_cons' Primcodable.prim
theorem list_casesOn {f : Ξ± β List Ξ²} {g : Ξ± β Ο} {h : Ξ± β Ξ² Γ List Ξ² β Ο} :
Primrec f β
Primrec g β
Primrecβ h β @Primrec _ Ο _ _ fun a => List.casesOn (f a) (g a) fun b l => h a (b, l) :=
list_casesOn' Primcodable.prim
theorem list_foldl {f : Ξ± β List Ξ²} {g : Ξ± β Ο} {h : Ξ± β Ο Γ Ξ² β Ο} :
Primrec f β
Primrec g β Primrecβ h β Primrec fun a => (f a).foldl (fun s b => h a (s, b)) (g a) :=
list_foldl' Primcodable.prim
theorem list_reverse : Primrec (@List.reverse Ξ±) :=
list_reverse' Primcodable.prim
theorem list_foldr {f : Ξ± β List Ξ²} {g : Ξ± β Ο} {h : Ξ± β Ξ² Γ Ο β Ο} (hf : Primrec f)
(hg : Primrec g) (hh : Primrecβ h) :
Primrec fun a => (f a).foldr (fun b s => h a (b, s)) (g a) :=
(list_foldl (list_reverse.comp hf) hg <| toβ <| hh.comp fst <| (pair snd fst).comp snd).of_eq
fun a => by simp [List.foldl_reverse]
theorem list_head? : Primrec (@List.head? Ξ±) :=
(list_casesOn .id (const none) (option_some_iff.2 <| fst.comp snd).toβ).of_eq fun l => by
cases l <;> rfl
theorem list_headI [Inhabited Ξ±] : Primrec (@List.headI Ξ± _) :=
(option_iget.comp list_head?).of_eq fun l => l.head!_eq_head?.symm
theorem list_tail : Primrec (@List.tail Ξ±) :=
(list_casesOn .id (const []) (snd.comp snd).toβ).of_eq fun l => by cases l <;> rfl
theorem list_rec {f : Ξ± β List Ξ²} {g : Ξ± β Ο} {h : Ξ± β Ξ² Γ List Ξ² Γ Ο β Ο} (hf : Primrec f)
(hg : Primrec g) (hh : Primrecβ h) :
@Primrec _ Ο _ _ fun a => List.recOn (f a) (g a) fun b l IH => h a (b, l, IH) :=
let F (a : Ξ±) := (f a).foldr (fun (b : Ξ²) (s : List Ξ² Γ Ο) => (b :: s.1, h a (b, s))) ([], g a)
have : Primrec F :=
list_foldr hf (pair (const []) hg) <|
toβ <| pair ((list_cons.comp fst (fst.comp snd)).comp snd) hh
(snd.comp this).of_eq fun a => by
suffices F a = (f a, List.recOn (f a) (g a) fun b l IH => h a (b, l, IH)) by rw [this]
dsimp [F]
induction' f a with b l IH <;> simp [*]
theorem list_getElem? : Primrecβ ((Β·[Β·]? : List Ξ± β β β Option Ξ±)) :=
let F (l : List Ξ±) (n : β) :=
l.foldl
(fun (s : β β Ξ±) (a : Ξ±) =>
Sum.casesOn s (@Nat.casesOn (fun _ => β β Ξ±) Β· (Sum.inr a) Sum.inl) Sum.inr)
(Sum.inl n)
have hF : Primrecβ F :=
(list_foldl fst (sumInl.comp snd)
((sumCasesOn fst (nat_casesOn snd (sumInr.comp <| snd.comp fst) (sumInl.comp snd).toβ).toβ
(sumInr.comp snd).toβ).comp
snd).toβ).toβ
have :
@Primrec _ (Option Ξ±) _ _ fun p : List Ξ± Γ β => Sum.casesOn (F p.1 p.2) (fun _ => none) some :=
sumCasesOn hF (const none).toβ (option_some.comp snd).toβ
this.toβ.of_eq fun l n => by
dsimp; symm
induction' l with a l IH generalizing n; Β· rfl
rcases n with - | n
Β· dsimp [F]
clear IH
induction' l with _ l IH <;> simp_all
Β· simpa using IH ..
@[deprecated (since := "2025-02-14")] alias list_get? := list_getElem?
theorem list_getD (d : Ξ±) : Primrecβ fun l n => List.getD l n d := by
simp only [List.getD_eq_getElem?_getD]
exact option_getD.compβ list_getElem? (const _)
theorem list_getI [Inhabited Ξ±] : Primrecβ (@List.getI Ξ± _) :=
list_getD _
theorem list_append : Primrecβ ((Β· ++ Β·) : List Ξ± β List Ξ± β List Ξ±) :=
(list_foldr fst snd <| toβ <| comp (@list_cons Ξ± _) snd).toβ.of_eq fun lβ lβ => by
induction lβ <;> simp [*]
theorem list_concat : Primrecβ fun l (a : Ξ±) => l ++ [a] :=
list_append.comp fst (list_cons.comp snd (const []))
theorem list_map {f : Ξ± β List Ξ²} {g : Ξ± β Ξ² β Ο} (hf : Primrec f) (hg : Primrecβ g) :
Primrec fun a => (f a).map (g a) :=
(list_foldr hf (const []) <|
toβ <| list_cons.comp (hg.comp fst (fst.comp snd)) (snd.comp snd)).of_eq
fun a => by induction f a <;> simp [*]
theorem list_range : Primrec List.range :=
(nat_rec' .id (const []) ((list_concat.comp snd fst).comp snd).toβ).of_eq fun n => by
simp; induction n <;> simp [*, List.range_succ]
theorem list_flatten : Primrec (@List.flatten Ξ±) :=
(list_foldr .id (const []) <| toβ <| comp (@list_append Ξ± _) snd).of_eq fun l => by
dsimp; induction l <;> simp [*]
theorem list_flatMap {f : Ξ± β List Ξ²} {g : Ξ± β Ξ² β List Ο} (hf : Primrec f) (hg : Primrecβ g) :
Primrec (fun a => (f a).flatMap (g a)) := list_flatten.comp (list_map hf hg)
theorem optionToList : Primrec (Option.toList : Option Ξ± β List Ξ±) :=
(option_casesOn Primrec.id (const [])
((list_cons.comp Primrec.id (const [])).compβ Primrecβ.right)).of_eq
(fun o => by rcases o <;> simp)
theorem listFilterMap {f : Ξ± β List Ξ²} {g : Ξ± β Ξ² β Option Ο}
(hf : Primrec f) (hg : Primrecβ g) : Primrec fun a => (f a).filterMap (g a) :=
(list_flatMap hf (compβ optionToList hg)).of_eq
fun _ β¦ Eq.symm <| List.filterMap_eq_flatMap_toList _ _
theorem list_length : Primrec (@List.length Ξ±) :=
(list_foldr (@Primrec.id (List Ξ±) _) (const 0) <| toβ <| (succ.comp <| snd.comp snd).toβ).of_eq
fun l => by dsimp; induction l <;> simp [*]
theorem list_findIdx {f : Ξ± β List Ξ²} {p : Ξ± β Ξ² β Bool}
(hf : Primrec f) (hp : Primrecβ p) : Primrec fun a => (f a).findIdx (p a) :=
(list_foldr hf (const 0) <|
toβ <| cond (hp.comp fst <| fst.comp snd) (const 0) (succ.comp <| snd.comp snd)).of_eq
fun a => by dsimp; induction f a <;> simp [List.findIdx_cons, *]
theorem list_idxOf [DecidableEq Ξ±] : Primrecβ (@List.idxOf Ξ± _) :=
toβ <| list_findIdx snd <| Primrec.beq.compβ snd.toβ (fst.comp fst).toβ
@[deprecated (since := "2025-01-30")] alias list_indexOf := list_idxOf
theorem nat_strong_rec (f : Ξ± β β β Ο) {g : Ξ± β List Ο β Option Ο} (hg : Primrecβ g)
(H : β a n, g a ((List.range n).map (f a)) = some (f a n)) : Primrecβ f :=
suffices Primrecβ fun a n => (List.range n).map (f a) from
Primrecβ.option_some_iff.1 <|
(list_getElem?.comp (this.comp fst (succ.comp snd)) snd).toβ.of_eq fun a n => by
simp [List.getElem?_range (Nat.lt_succ_self n)]
Primrecβ.option_some_iff.1 <|
(nat_rec (const (some []))
(toβ <|
option_bind (snd.comp snd) <|
toβ <|
option_map (hg.comp (fst.comp fst) snd)
(toβ <| list_concat.comp (snd.comp fst) snd))).of_eq
fun a n => by
induction n with
| zero => rfl
| succ n IH => simp [IH, H, List.range_succ]
theorem listLookup [DecidableEq Ξ±] : Primrecβ (List.lookup : Ξ± β List (Ξ± Γ Ξ²) β Option Ξ²) :=
(toβ <| list_rec snd (const none) <|
toβ <|
cond (Primrec.beq.comp (fst.comp fst) (fst.comp <| fst.comp snd))
(option_some.comp <| snd.comp <| fst.comp snd)
(snd.comp <| snd.comp snd)).of_eq
fun a ps => by
induction' ps with p ps ih <;> simp [List.lookup, *]
cases ha : a == p.1 <;> simp [ha]
theorem nat_omega_rec' (f : Ξ² β Ο) {m : Ξ² β β} {l : Ξ² β List Ξ²} {g : Ξ² β List Ο β Option Ο}
(hm : Primrec m) (hl : Primrec l) (hg : Primrecβ g)
(Ord : β b, β b' β l b, m b' < m b)
(H : β b, g b ((l b).map f) = some (f b)) : Primrec f := by
haveI : DecidableEq Ξ² := Encodable.decidableEqOfEncodable Ξ²
let mapGraph (M : List (Ξ² Γ Ο)) (bs : List Ξ²) : List Ο := bs.flatMap (Option.toList <| M.lookup Β·)
let bindList (b : Ξ²) : β β List Ξ² := fun n β¦ n.rec [b] fun _ bs β¦ bs.flatMap l
let graph (b : Ξ²) : β β List (Ξ² Γ Ο) := fun i β¦ i.rec [] fun i ih β¦
(bindList b (m b - i)).filterMap fun b' β¦ (g b' <| mapGraph ih (l b')).map (b', Β·)
have mapGraph_primrec : Primrecβ mapGraph :=
toβ <| list_flatMap snd <| optionToList.compβ <| listLookup.compβ .right (fst.compβ .left)
have bindList_primrec : Primrecβ (bindList) :=
nat_rec' snd
(list_cons.comp fst (const []))
(toβ <| list_flatMap (snd.comp snd) (hl.compβ .right))
have graph_primrec : Primrecβ (graph) :=
toβ <| nat_rec' snd (const []) <|
toβ <| listFilterMap
(bindList_primrec.comp
(fst.comp fst)
(nat_sub.comp (hm.comp <| fst.comp fst) (fst.comp snd))) <|
toβ <| option_map
(hg.comp snd (mapGraph_primrec.comp (snd.comp <| snd.comp fst) (hl.comp snd)))
(Primrecβ.pair.compβ (snd.compβ .left) .right)
have : Primrec (fun b => (graph b (m b + 1))[0]?.map Prod.snd) :=
option_map (list_getElem?.comp (graph_primrec.comp Primrec.id (succ.comp hm)) (const 0))
(snd.compβ Primrecβ.right)
exact option_some_iff.mp <| this.of_eq <| fun b β¦ by
have graph_eq_map_bindList (i : β) (hi : i β€ m b + 1) :
graph b i = (bindList b (m b + 1 - i)).map fun x β¦ (x, f x) := by
have bindList_eq_nil : bindList b (m b + 1) = [] :=
have bindList_m_lt (k : β) : β b' β bindList b k, m b' < m b + 1 - k := by
induction' k with k ih <;> simp [bindList]
intro aβ aβ haβ haβ
have : k β€ m b :=
Nat.lt_succ.mp (by simpa using Nat.add_lt_of_lt_sub <| Nat.zero_lt_of_lt (ih aβ haβ))
have : m aβ β€ m b - k :=
Nat.lt_succ.mp (by rw [β Nat.succ_sub this]; simpa using ih aβ haβ)
exact lt_of_lt_of_le (Ord aβ aβ haβ) this
List.eq_nil_iff_forall_not_mem.mpr
(by intro b' ha'; by_contra; simpa using bindList_m_lt (m b + 1) b' ha')
have mapGraph_graph {bs bs' : List Ξ²} (has : bs' β bs) :
mapGraph (bs.map <| fun x => (x, f x)) bs' = bs'.map f := by
induction' bs' with b bs' ih <;> simp [mapGraph]
Β· have : b β bs β§ bs' β bs := by simpa using has
rcases this with β¨ha, has'β©
simpa [List.lookup_graph f ha] using ih has'
have graph_succ : β i, graph b (i + 1) =
(bindList b (m b - i)).filterMap fun b' =>
(g b' <| mapGraph (graph b i) (l b')).map (b', Β·) := fun _ => rfl
have bindList_succ : β i, bindList b (i + 1) = (bindList b i).flatMap l := fun _ => rfl
induction' i with i ih
Β· symm; simpa [graph] using bindList_eq_nil
Β· simp only [graph_succ, ih (Nat.le_of_lt hi), Nat.succ_sub (Nat.lt_succ.mp hi),
Nat.succ_eq_add_one, bindList_succ, Nat.reduceSubDiff]
apply List.filterMap_eq_map_iff_forall_eq_some.mpr
intro b' ha'; simp; rw [mapGraph_graph]
Β· exact H b'
Β· exact (List.infix_flatMap_of_mem ha' l).subset
simp [graph_eq_map_bindList (m b + 1) (Nat.le_refl _), bindList]
theorem nat_omega_rec (f : Ξ± β Ξ² β Ο) {m : Ξ± β Ξ² β β}
{l : Ξ± β Ξ² β List Ξ²} {g : Ξ± β Ξ² Γ List Ο β Option Ο}
(hm : Primrecβ m) (hl : Primrecβ l) (hg : Primrecβ g)
(Ord : β a b, β b' β l a b, m a b' < m a b)
(H : β a b, g a (b, (l a b).map (f a)) = some (f a b)) : Primrecβ f :=
Primrecβ.uncurry.mp <|
nat_omega_rec' (Function.uncurry f)
(Primrecβ.uncurry.mpr hm)
(list_map (hl.comp fst snd) (Primrecβ.pair.compβ (fst.compβ .left) .right))
(hg.compβ (fst.compβ .left) (Primrecβ.pair.compβ (snd.compβ .left) .right))
(by simpa using Ord) (by simpa [Function.comp] using H)
end Primrec
namespace Primcodable
variable {Ξ± : Type*} [Primcodable Ξ±]
open Primrec
/-- A subtype of a primitive recursive predicate is `Primcodable`. -/
def subtype {p : Ξ± β Prop} [DecidablePred p] (hp : PrimrecPred p) : Primcodable (Subtype p) :=
β¨have : Primrec fun n => (@decode Ξ± _ n).bind fun a => Option.guard p a :=
option_bind .decode (option_guard (hp.comp snd).toβ snd)
nat_iff.1 <| (encode_iff.2 this).of_eq fun n =>
show _ = encode ((@decode Ξ± _ n).bind fun _ => _) by
rcases @decode Ξ± _ n with - | a; Β· rfl
dsimp [Option.guard]
by_cases h : p a <;> simp [h]; rflβ©
instance fin {n} : Primcodable (Fin n) :=
@ofEquiv _ _ (subtype <| nat_lt.comp .id (const n)) Fin.equivSubtype
instance vector {n} : Primcodable (List.Vector Ξ± n) :=
subtype ((@Primrec.eq β _ _).comp list_length (const _))
instance finArrow {n} : Primcodable (Fin n β Ξ±) :=
| ofEquiv _ (Equiv.vectorEquivFin _ _).symm
| Mathlib/Computability/Primrec.lean | 1,109 | 1,111 |
/-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura, Johannes HΓΆlzl, Mario Carneiro
-/
import Mathlib.Logic.Pairwise
import Mathlib.Data.Set.BooleanAlgebra
/-!
# The set lattice
This file is a collection of results on the complete atomic boolean algebra structure of `Set Ξ±`.
Notation for the complete lattice operations can be found in `Mathlib.Order.SetNotation`.
## Main declarations
* `Set.sInter_eq_biInter`, `Set.sUnion_eq_biInter`: Shows that `ββ s = β x β s, x` and
`ββ s = β x β s, x`.
* `Set.completeAtomicBooleanAlgebra`: `Set Ξ±` is a `CompleteAtomicBooleanAlgebra` with `β€ = β`,
`< = β`, `β = β©`, `β = βͺ`, `β¨
= β`, `β¨ = β` and `\` as the set difference.
See `Set.instBooleanAlgebra`.
* `Set.unionEqSigmaOfDisjoint`: Equivalence between `β i, t i` and `Ξ£ i, t i`, where `t` is an
indexed family of disjoint sets.
## Naming convention
In lemma names,
* `β i, s i` is called `iUnion`
* `β i, s i` is called `iInter`
* `β i j, s i j` is called `iUnionβ`. This is an `iUnion` inside an `iUnion`.
* `β i j, s i j` is called `iInterβ`. This is an `iInter` inside an `iInter`.
* `β i β s, t i` is called `biUnion` for "bounded `iUnion`". This is the special case of `iUnionβ`
where `j : i β s`.
* `β i β s, t i` is called `biInter` for "bounded `iInter`". This is the special case of `iInterβ`
where `j : i β s`.
## Notation
* `β`: `Set.iUnion`
* `β`: `Set.iInter`
* `ββ`: `Set.sUnion`
* `ββ`: `Set.sInter`
-/
open Function Set
universe u
variable {Ξ± Ξ² Ξ³ Ξ΄ : Type*} {ΞΉ ΞΉ' ΞΉβ : Sort*} {ΞΊ ΞΊβ ΞΊβ : ΞΉ β Sort*} {ΞΊ' : ΞΉ' β Sort*}
namespace Set
/-! ### Complete lattice and complete Boolean algebra instances -/
theorem mem_iUnionβ {x : Ξ³} {s : β i, ΞΊ i β Set Ξ³} : (x β β (i) (j), s i j) β β i j, x β s i j := by
simp_rw [mem_iUnion]
theorem mem_iInterβ {x : Ξ³} {s : β i, ΞΊ i β Set Ξ³} : (x β β (i) (j), s i j) β β i j, x β s i j := by
simp_rw [mem_iInter]
theorem mem_iUnion_of_mem {s : ΞΉ β Set Ξ±} {a : Ξ±} (i : ΞΉ) (ha : a β s i) : a β β i, s i :=
mem_iUnion.2 β¨i, haβ©
theorem mem_iUnionβ_of_mem {s : β i, ΞΊ i β Set Ξ±} {a : Ξ±} {i : ΞΉ} (j : ΞΊ i) (ha : a β s i j) :
a β β (i) (j), s i j :=
mem_iUnionβ.2 β¨i, j, haβ©
theorem mem_iInter_of_mem {s : ΞΉ β Set Ξ±} {a : Ξ±} (h : β i, a β s i) : a β β i, s i :=
mem_iInter.2 h
theorem mem_iInterβ_of_mem {s : β i, ΞΊ i β Set Ξ±} {a : Ξ±} (h : β i j, a β s i j) :
a β β (i) (j), s i j :=
mem_iInterβ.2 h
/-! ### Union and intersection over an indexed family of sets -/
@[congr]
theorem iUnion_congr_Prop {p q : Prop} {fβ : p β Set Ξ±} {fβ : q β Set Ξ±} (pq : p β q)
(f : β x, fβ (pq.mpr x) = fβ x) : iUnion fβ = iUnion fβ :=
iSup_congr_Prop pq f
@[congr]
theorem iInter_congr_Prop {p q : Prop} {fβ : p β Set Ξ±} {fβ : q β Set Ξ±} (pq : p β q)
(f : β x, fβ (pq.mpr x) = fβ x) : iInter fβ = iInter fβ :=
iInf_congr_Prop pq f
theorem iUnion_plift_up (f : PLift ΞΉ β Set Ξ±) : β i, f (PLift.up i) = β i, f i :=
iSup_plift_up _
theorem iUnion_plift_down (f : ΞΉ β Set Ξ±) : β i, f (PLift.down i) = β i, f i :=
iSup_plift_down _
theorem iInter_plift_up (f : PLift ΞΉ β Set Ξ±) : β i, f (PLift.up i) = β i, f i :=
iInf_plift_up _
theorem iInter_plift_down (f : ΞΉ β Set Ξ±) : β i, f (PLift.down i) = β i, f i :=
iInf_plift_down _
theorem iUnion_eq_if {p : Prop} [Decidable p] (s : Set Ξ±) : β _ : p, s = if p then s else β
:=
iSup_eq_if _
theorem iUnion_eq_dif {p : Prop} [Decidable p] (s : p β Set Ξ±) :
β h : p, s h = if h : p then s h else β
:=
iSup_eq_dif _
theorem iInter_eq_if {p : Prop} [Decidable p] (s : Set Ξ±) : β _ : p, s = if p then s else univ :=
iInf_eq_if _
theorem iInf_eq_dif {p : Prop} [Decidable p] (s : p β Set Ξ±) :
β h : p, s h = if h : p then s h else univ :=
_root_.iInf_eq_dif _
theorem exists_set_mem_of_union_eq_top {ΞΉ : Type*} (t : Set ΞΉ) (s : ΞΉ β Set Ξ²)
(w : β i β t, s i = β€) (x : Ξ²) : β i β t, x β s i := by
have p : x β β€ := Set.mem_univ x
rw [β w, Set.mem_iUnion] at p
simpa using p
theorem nonempty_of_union_eq_top_of_nonempty {ΞΉ : Type*} (t : Set ΞΉ) (s : ΞΉ β Set Ξ±)
(H : Nonempty Ξ±) (w : β i β t, s i = β€) : t.Nonempty := by
obtain β¨x, m, -β© := exists_set_mem_of_union_eq_top t s w H.some
exact β¨x, mβ©
theorem nonempty_of_nonempty_iUnion
{s : ΞΉ β Set Ξ±} (h_Union : (β i, s i).Nonempty) : Nonempty ΞΉ := by
obtain β¨x, hxβ© := h_Union
exact β¨Classical.choose <| mem_iUnion.mp hxβ©
theorem nonempty_of_nonempty_iUnion_eq_univ
{s : ΞΉ β Set Ξ±} [Nonempty Ξ±] (h_Union : β i, s i = univ) : Nonempty ΞΉ :=
nonempty_of_nonempty_iUnion (s := s) (by simpa only [h_Union] using univ_nonempty)
theorem setOf_exists (p : ΞΉ β Ξ² β Prop) : { x | β i, p i x } = β i, { x | p i x } :=
ext fun _ => mem_iUnion.symm
theorem setOf_forall (p : ΞΉ β Ξ² β Prop) : { x | β i, p i x } = β i, { x | p i x } :=
ext fun _ => mem_iInter.symm
theorem iUnion_subset {s : ΞΉ β Set Ξ±} {t : Set Ξ±} (h : β i, s i β t) : β i, s i β t :=
iSup_le h
theorem iUnionβ_subset {s : β i, ΞΊ i β Set Ξ±} {t : Set Ξ±} (h : β i j, s i j β t) :
β (i) (j), s i j β t :=
iUnion_subset fun x => iUnion_subset (h x)
theorem subset_iInter {t : Set Ξ²} {s : ΞΉ β Set Ξ²} (h : β i, t β s i) : t β β i, s i :=
le_iInf h
theorem subset_iInterβ {s : Set Ξ±} {t : β i, ΞΊ i β Set Ξ±} (h : β i j, s β t i j) :
s β β (i) (j), t i j :=
subset_iInter fun x => subset_iInter <| h x
@[simp]
theorem iUnion_subset_iff {s : ΞΉ β Set Ξ±} {t : Set Ξ±} : β i, s i β t β β i, s i β t :=
β¨fun h _ => Subset.trans (le_iSup s _) h, iUnion_subsetβ©
theorem iUnionβ_subset_iff {s : β i, ΞΊ i β Set Ξ±} {t : Set Ξ±} :
β (i) (j), s i j β t β β i j, s i j β t := by simp_rw [iUnion_subset_iff]
@[simp]
theorem subset_iInter_iff {s : Set Ξ±} {t : ΞΉ β Set Ξ±} : (s β β i, t i) β β i, s β t i :=
le_iInf_iff
theorem subset_iInterβ_iff {s : Set Ξ±} {t : β i, ΞΊ i β Set Ξ±} :
(s β β (i) (j), t i j) β β i j, s β t i j := by simp_rw [subset_iInter_iff]
theorem subset_iUnion : β (s : ΞΉ β Set Ξ²) (i : ΞΉ), s i β β i, s i :=
le_iSup
theorem iInter_subset : β (s : ΞΉ β Set Ξ²) (i : ΞΉ), β i, s i β s i :=
iInf_le
lemma iInter_subset_iUnion [Nonempty ΞΉ] {s : ΞΉ β Set Ξ±} : β i, s i β β i, s i := iInf_le_iSup
theorem subset_iUnionβ {s : β i, ΞΊ i β Set Ξ±} (i : ΞΉ) (j : ΞΊ i) : s i j β β (i') (j'), s i' j' :=
le_iSupβ i j
theorem iInterβ_subset {s : β i, ΞΊ i β Set Ξ±} (i : ΞΉ) (j : ΞΊ i) : β (i) (j), s i j β s i j :=
iInfβ_le i j
/-- This rather trivial consequence of `subset_iUnion`is convenient with `apply`, and has `i`
explicit for this purpose. -/
theorem subset_iUnion_of_subset {s : Set Ξ±} {t : ΞΉ β Set Ξ±} (i : ΞΉ) (h : s β t i) : s β β i, t i :=
le_iSup_of_le i h
/-- This rather trivial consequence of `iInter_subset`is convenient with `apply`, and has `i`
explicit for this purpose. -/
theorem iInter_subset_of_subset {s : ΞΉ β Set Ξ±} {t : Set Ξ±} (i : ΞΉ) (h : s i β t) :
β i, s i β t :=
iInf_le_of_le i h
/-- This rather trivial consequence of `subset_iUnionβ` is convenient with `apply`, and has `i` and
`j` explicit for this purpose. -/
theorem subset_iUnionβ_of_subset {s : Set Ξ±} {t : β i, ΞΊ i β Set Ξ±} (i : ΞΉ) (j : ΞΊ i)
(h : s β t i j) : s β β (i) (j), t i j :=
le_iSupβ_of_le i j h
/-- This rather trivial consequence of `iInterβ_subset` is convenient with `apply`, and has `i` and
`j` explicit for this purpose. -/
theorem iInterβ_subset_of_subset {s : β i, ΞΊ i β Set Ξ±} {t : Set Ξ±} (i : ΞΉ) (j : ΞΊ i)
(h : s i j β t) : β (i) (j), s i j β t :=
iInfβ_le_of_le i j h
theorem iUnion_mono {s t : ΞΉ β Set Ξ±} (h : β i, s i β t i) : β i, s i β β i, t i :=
iSup_mono h
@[gcongr]
theorem iUnion_mono'' {s t : ΞΉ β Set Ξ±} (h : β i, s i β t i) : iUnion s β iUnion t :=
iSup_mono h
theorem iUnionβ_mono {s t : β i, ΞΊ i β Set Ξ±} (h : β i j, s i j β t i j) :
β (i) (j), s i j β β (i) (j), t i j :=
iSupβ_mono h
theorem iInter_mono {s t : ΞΉ β Set Ξ±} (h : β i, s i β t i) : β i, s i β β i, t i :=
iInf_mono h
@[gcongr]
theorem iInter_mono'' {s t : ΞΉ β Set Ξ±} (h : β i, s i β t i) : iInter s β iInter t :=
iInf_mono h
theorem iInterβ_mono {s t : β i, ΞΊ i β Set Ξ±} (h : β i j, s i j β t i j) :
β (i) (j), s i j β β (i) (j), t i j :=
iInfβ_mono h
theorem iUnion_mono' {s : ΞΉ β Set Ξ±} {t : ΞΉβ β Set Ξ±} (h : β i, β j, s i β t j) :
β i, s i β β i, t i :=
iSup_mono' h
theorem iUnionβ_mono' {s : β i, ΞΊ i β Set Ξ±} {t : β i', ΞΊ' i' β Set Ξ±}
(h : β i j, β i' j', s i j β t i' j') : β (i) (j), s i j β β (i') (j'), t i' j' :=
iSupβ_mono' h
theorem iInter_mono' {s : ΞΉ β Set Ξ±} {t : ΞΉ' β Set Ξ±} (h : β j, β i, s i β t j) :
β i, s i β β j, t j :=
Set.subset_iInter fun j =>
let β¨i, hiβ© := h j
iInter_subset_of_subset i hi
theorem iInterβ_mono' {s : β i, ΞΊ i β Set Ξ±} {t : β i', ΞΊ' i' β Set Ξ±}
(h : β i' j', β i j, s i j β t i' j') : β (i) (j), s i j β β (i') (j'), t i' j' :=
subset_iInterβ_iff.2 fun i' j' =>
let β¨_, _, hstβ© := h i' j'
(iInterβ_subset _ _).trans hst
theorem iUnionβ_subset_iUnion (ΞΊ : ΞΉ β Sort*) (s : ΞΉ β Set Ξ±) :
β (i) (_ : ΞΊ i), s i β β i, s i :=
iUnion_mono fun _ => iUnion_subset fun _ => Subset.rfl
theorem iInter_subset_iInterβ (ΞΊ : ΞΉ β Sort*) (s : ΞΉ β Set Ξ±) :
β i, s i β β (i) (_ : ΞΊ i), s i :=
iInter_mono fun _ => subset_iInter fun _ => Subset.rfl
theorem iUnion_setOf (P : ΞΉ β Ξ± β Prop) : β i, { x : Ξ± | P i x } = { x : Ξ± | β i, P i x } := by
ext
exact mem_iUnion
theorem iInter_setOf (P : ΞΉ β Ξ± β Prop) : β i, { x : Ξ± | P i x } = { x : Ξ± | β i, P i x } := by
ext
exact mem_iInter
theorem iUnion_congr_of_surjective {f : ΞΉ β Set Ξ±} {g : ΞΉβ β Set Ξ±} (h : ΞΉ β ΞΉβ) (h1 : Surjective h)
(h2 : β x, g (h x) = f x) : β x, f x = β y, g y :=
h1.iSup_congr h h2
theorem iInter_congr_of_surjective {f : ΞΉ β Set Ξ±} {g : ΞΉβ β Set Ξ±} (h : ΞΉ β ΞΉβ) (h1 : Surjective h)
(h2 : β x, g (h x) = f x) : β x, f x = β y, g y :=
h1.iInf_congr h h2
lemma iUnion_congr {s t : ΞΉ β Set Ξ±} (h : β i, s i = t i) : β i, s i = β i, t i := iSup_congr h
lemma iInter_congr {s t : ΞΉ β Set Ξ±} (h : β i, s i = t i) : β i, s i = β i, t i := iInf_congr h
lemma iUnionβ_congr {s t : β i, ΞΊ i β Set Ξ±} (h : β i j, s i j = t i j) :
β (i) (j), s i j = β (i) (j), t i j :=
iUnion_congr fun i => iUnion_congr <| h i
lemma iInterβ_congr {s t : β i, ΞΊ i β Set Ξ±} (h : β i j, s i j = t i j) :
β (i) (j), s i j = β (i) (j), t i j :=
iInter_congr fun i => iInter_congr <| h i
section Nonempty
variable [Nonempty ΞΉ] {f : ΞΉ β Set Ξ±} {s : Set Ξ±}
lemma iUnion_const (s : Set Ξ²) : β _ : ΞΉ, s = s := iSup_const
lemma iInter_const (s : Set Ξ²) : β _ : ΞΉ, s = s := iInf_const
lemma iUnion_eq_const (hf : β i, f i = s) : β i, f i = s :=
(iUnion_congr hf).trans <| iUnion_const _
lemma iInter_eq_const (hf : β i, f i = s) : β i, f i = s :=
(iInter_congr hf).trans <| iInter_const _
end Nonempty
@[simp]
theorem compl_iUnion (s : ΞΉ β Set Ξ²) : (β i, s i)αΆ = β i, (s i)αΆ :=
compl_iSup
theorem compl_iUnionβ (s : β i, ΞΊ i β Set Ξ±) : (β (i) (j), s i j)αΆ = β (i) (j), (s i j)αΆ := by
simp_rw [compl_iUnion]
@[simp]
theorem compl_iInter (s : ΞΉ β Set Ξ²) : (β i, s i)αΆ = β i, (s i)αΆ :=
compl_iInf
theorem compl_iInterβ (s : β i, ΞΊ i β Set Ξ±) : (β (i) (j), s i j)αΆ = β (i) (j), (s i j)αΆ := by
simp_rw [compl_iInter]
-- classical -- complete_boolean_algebra
theorem iUnion_eq_compl_iInter_compl (s : ΞΉ β Set Ξ²) : β i, s i = (β i, (s i)αΆ)αΆ := by
simp only [compl_iInter, compl_compl]
-- classical -- complete_boolean_algebra
theorem iInter_eq_compl_iUnion_compl (s : ΞΉ β Set Ξ²) : β i, s i = (β i, (s i)αΆ)αΆ := by
simp only [compl_iUnion, compl_compl]
theorem inter_iUnion (s : Set Ξ²) (t : ΞΉ β Set Ξ²) : (s β© β i, t i) = β i, s β© t i :=
inf_iSup_eq _ _
theorem iUnion_inter (s : Set Ξ²) (t : ΞΉ β Set Ξ²) : (β i, t i) β© s = β i, t i β© s :=
iSup_inf_eq _ _
theorem iUnion_union_distrib (s : ΞΉ β Set Ξ²) (t : ΞΉ β Set Ξ²) :
β i, s i βͺ t i = (β i, s i) βͺ β i, t i :=
iSup_sup_eq
theorem iInter_inter_distrib (s : ΞΉ β Set Ξ²) (t : ΞΉ β Set Ξ²) :
β i, s i β© t i = (β i, s i) β© β i, t i :=
iInf_inf_eq
theorem union_iUnion [Nonempty ΞΉ] (s : Set Ξ²) (t : ΞΉ β Set Ξ²) : (s βͺ β i, t i) = β i, s βͺ t i :=
sup_iSup
theorem iUnion_union [Nonempty ΞΉ] (s : Set Ξ²) (t : ΞΉ β Set Ξ²) : (β i, t i) βͺ s = β i, t i βͺ s :=
iSup_sup
theorem inter_iInter [Nonempty ΞΉ] (s : Set Ξ²) (t : ΞΉ β Set Ξ²) : (s β© β i, t i) = β i, s β© t i :=
inf_iInf
theorem iInter_inter [Nonempty ΞΉ] (s : Set Ξ²) (t : ΞΉ β Set Ξ²) : (β i, t i) β© s = β i, t i β© s :=
iInf_inf
theorem insert_iUnion [Nonempty ΞΉ] (x : Ξ²) (t : ΞΉ β Set Ξ²) :
insert x (β i, t i) = β i, insert x (t i) := by
simp_rw [β union_singleton, iUnion_union]
-- classical
theorem union_iInter (s : Set Ξ²) (t : ΞΉ β Set Ξ²) : (s βͺ β i, t i) = β i, s βͺ t i :=
sup_iInf_eq _ _
theorem iInter_union (s : ΞΉ β Set Ξ²) (t : Set Ξ²) : (β i, s i) βͺ t = β i, s i βͺ t :=
iInf_sup_eq _ _
theorem insert_iInter (x : Ξ²) (t : ΞΉ β Set Ξ²) : insert x (β i, t i) = β i, insert x (t i) := by
simp_rw [β union_singleton, iInter_union]
theorem iUnion_diff (s : Set Ξ²) (t : ΞΉ β Set Ξ²) : (β i, t i) \ s = β i, t i \ s :=
iUnion_inter _ _
theorem diff_iUnion [Nonempty ΞΉ] (s : Set Ξ²) (t : ΞΉ β Set Ξ²) : (s \ β i, t i) = β i, s \ t i := by
rw [diff_eq, compl_iUnion, inter_iInter]; rfl
theorem diff_iInter (s : Set Ξ²) (t : ΞΉ β Set Ξ²) : (s \ β i, t i) = β i, s \ t i := by
rw [diff_eq, compl_iInter, inter_iUnion]; rfl
theorem iUnion_inter_subset {ΞΉ Ξ±} {s t : ΞΉ β Set Ξ±} : β i, s i β© t i β (β i, s i) β© β i, t i :=
le_iSup_inf_iSup s t
theorem iUnion_inter_of_monotone {ΞΉ Ξ±} [Preorder ΞΉ] [IsDirected ΞΉ (Β· β€ Β·)] {s t : ΞΉ β Set Ξ±}
(hs : Monotone s) (ht : Monotone t) : β i, s i β© t i = (β i, s i) β© β i, t i :=
iSup_inf_of_monotone hs ht
theorem iUnion_inter_of_antitone {ΞΉ Ξ±} [Preorder ΞΉ] [IsDirected ΞΉ (swap (Β· β€ Β·))] {s t : ΞΉ β Set Ξ±}
(hs : Antitone s) (ht : Antitone t) : β i, s i β© t i = (β i, s i) β© β i, t i :=
iSup_inf_of_antitone hs ht
theorem iInter_union_of_monotone {ΞΉ Ξ±} [Preorder ΞΉ] [IsDirected ΞΉ (swap (Β· β€ Β·))] {s t : ΞΉ β Set Ξ±}
(hs : Monotone s) (ht : Monotone t) : β i, s i βͺ t i = (β i, s i) βͺ β i, t i :=
iInf_sup_of_monotone hs ht
theorem iInter_union_of_antitone {ΞΉ Ξ±} [Preorder ΞΉ] [IsDirected ΞΉ (Β· β€ Β·)] {s t : ΞΉ β Set Ξ±}
(hs : Antitone s) (ht : Antitone t) : β i, s i βͺ t i = (β i, s i) βͺ β i, t i :=
iInf_sup_of_antitone hs ht
/-- An equality version of this lemma is `iUnion_iInter_of_monotone` in `Data.Set.Finite`. -/
theorem iUnion_iInter_subset {s : ΞΉ β ΞΉ' β Set Ξ±} : (β j, β i, s i j) β β i, β j, s i j :=
iSup_iInf_le_iInf_iSup (flip s)
theorem iUnion_option {ΞΉ} (s : Option ΞΉ β Set Ξ±) : β o, s o = s none βͺ β i, s (some i) :=
iSup_option s
theorem iInter_option {ΞΉ} (s : Option ΞΉ β Set Ξ±) : β o, s o = s none β© β i, s (some i) :=
iInf_option s
section
variable (p : ΞΉ β Prop) [DecidablePred p]
theorem iUnion_dite (f : β i, p i β Set Ξ±) (g : β i, Β¬p i β Set Ξ±) :
β i, (if h : p i then f i h else g i h) = (β (i) (h : p i), f i h) βͺ β (i) (h : Β¬p i), g i h :=
iSup_dite _ _ _
theorem iUnion_ite (f g : ΞΉ β Set Ξ±) :
β i, (if p i then f i else g i) = (β (i) (_ : p i), f i) βͺ β (i) (_ : Β¬p i), g i :=
iUnion_dite _ _ _
theorem iInter_dite (f : β i, p i β Set Ξ±) (g : β i, Β¬p i β Set Ξ±) :
β i, (if h : p i then f i h else g i h) = (β (i) (h : p i), f i h) β© β (i) (h : Β¬p i), g i h :=
iInf_dite _ _ _
theorem iInter_ite (f g : ΞΉ β Set Ξ±) :
β i, (if p i then f i else g i) = (β (i) (_ : p i), f i) β© β (i) (_ : Β¬p i), g i :=
iInter_dite _ _ _
end
/-! ### Unions and intersections indexed by `Prop` -/
theorem iInter_false {s : False β Set Ξ±} : iInter s = univ :=
iInf_false
theorem iUnion_false {s : False β Set Ξ±} : iUnion s = β
:=
iSup_false
@[simp]
theorem iInter_true {s : True β Set Ξ±} : iInter s = s trivial :=
iInf_true
@[simp]
theorem iUnion_true {s : True β Set Ξ±} : iUnion s = s trivial :=
iSup_true
@[simp]
theorem iInter_exists {p : ΞΉ β Prop} {f : Exists p β Set Ξ±} :
β x, f x = β (i) (h : p i), f β¨i, hβ© :=
iInf_exists
@[simp]
theorem iUnion_exists {p : ΞΉ β Prop} {f : Exists p β Set Ξ±} :
β x, f x = β (i) (h : p i), f β¨i, hβ© :=
iSup_exists
@[simp]
theorem iUnion_empty : (β _ : ΞΉ, β
: Set Ξ±) = β
:=
iSup_bot
@[simp]
theorem iInter_univ : (β _ : ΞΉ, univ : Set Ξ±) = univ :=
iInf_top
section
variable {s : ΞΉ β Set Ξ±}
@[simp]
theorem iUnion_eq_empty : β i, s i = β
β β i, s i = β
:=
iSup_eq_bot
@[simp]
theorem iInter_eq_univ : β i, s i = univ β β i, s i = univ :=
iInf_eq_top
@[simp]
theorem nonempty_iUnion : (β i, s i).Nonempty β β i, (s i).Nonempty := by
simp [nonempty_iff_ne_empty]
theorem nonempty_biUnion {t : Set Ξ±} {s : Ξ± β Set Ξ²} :
(β i β t, s i).Nonempty β β i β t, (s i).Nonempty := by simp
theorem iUnion_nonempty_index (s : Set Ξ±) (t : s.Nonempty β Set Ξ²) :
β h, t h = β x β s, t β¨x, βΉ_βΊβ© :=
iSup_exists
end
@[simp]
theorem iInter_iInter_eq_left {b : Ξ²} {s : β x : Ξ², x = b β Set Ξ±} :
β (x) (h : x = b), s x h = s b rfl :=
iInf_iInf_eq_left
@[simp]
theorem iInter_iInter_eq_right {b : Ξ²} {s : β x : Ξ², b = x β Set Ξ±} :
β (x) (h : b = x), s x h = s b rfl :=
iInf_iInf_eq_right
@[simp]
theorem iUnion_iUnion_eq_left {b : Ξ²} {s : β x : Ξ², x = b β Set Ξ±} :
β (x) (h : x = b), s x h = s b rfl :=
iSup_iSup_eq_left
@[simp]
theorem iUnion_iUnion_eq_right {b : Ξ²} {s : β x : Ξ², b = x β Set Ξ±} :
β (x) (h : b = x), s x h = s b rfl :=
iSup_iSup_eq_right
theorem iInter_or {p q : Prop} (s : p β¨ q β Set Ξ±) :
β h, s h = (β h : p, s (Or.inl h)) β© β h : q, s (Or.inr h) :=
iInf_or
theorem iUnion_or {p q : Prop} (s : p β¨ q β Set Ξ±) :
β h, s h = (β i, s (Or.inl i)) βͺ β j, s (Or.inr j) :=
iSup_or
theorem iUnion_and {p q : Prop} (s : p β§ q β Set Ξ±) : β h, s h = β (hp) (hq), s β¨hp, hqβ© :=
iSup_and
theorem iInter_and {p q : Prop} (s : p β§ q β Set Ξ±) : β h, s h = β (hp) (hq), s β¨hp, hqβ© :=
iInf_and
theorem iUnion_comm (s : ΞΉ β ΞΉ' β Set Ξ±) : β (i) (i'), s i i' = β (i') (i), s i i' :=
iSup_comm
theorem iInter_comm (s : ΞΉ β ΞΉ' β Set Ξ±) : β (i) (i'), s i i' = β (i') (i), s i i' :=
iInf_comm
theorem iUnion_sigma {Ξ³ : Ξ± β Type*} (s : Sigma Ξ³ β Set Ξ²) : β ia, s ia = β i, β a, s β¨i, aβ© :=
iSup_sigma
theorem iUnion_sigma' {Ξ³ : Ξ± β Type*} (s : β i, Ξ³ i β Set Ξ²) :
β i, β a, s i a = β ia : Sigma Ξ³, s ia.1 ia.2 :=
iSup_sigma' _
theorem iInter_sigma {Ξ³ : Ξ± β Type*} (s : Sigma Ξ³ β Set Ξ²) : β ia, s ia = β i, β a, s β¨i, aβ© :=
iInf_sigma
theorem iInter_sigma' {Ξ³ : Ξ± β Type*} (s : β i, Ξ³ i β Set Ξ²) :
β i, β a, s i a = β ia : Sigma Ξ³, s ia.1 ia.2 :=
iInf_sigma' _
theorem iUnionβ_comm (s : β iβ, ΞΊβ iβ β β iβ, ΞΊβ iβ β Set Ξ±) :
β (iβ) (jβ) (iβ) (jβ), s iβ jβ iβ jβ = β (iβ) (jβ) (iβ) (jβ), s iβ jβ iβ jβ :=
iSupβ_comm _
theorem iInterβ_comm (s : β iβ, ΞΊβ iβ β β iβ, ΞΊβ iβ β Set Ξ±) :
β (iβ) (jβ) (iβ) (jβ), s iβ jβ iβ jβ = β (iβ) (jβ) (iβ) (jβ), s iβ jβ iβ jβ :=
iInfβ_comm _
@[simp]
theorem biUnion_and (p : ΞΉ β Prop) (q : ΞΉ β ΞΉ' β Prop) (s : β x y, p x β§ q x y β Set Ξ±) :
β (x : ΞΉ) (y : ΞΉ') (h : p x β§ q x y), s x y h =
β (x : ΞΉ) (hx : p x) (y : ΞΉ') (hy : q x y), s x y β¨hx, hyβ© := by
simp only [iUnion_and, @iUnion_comm _ ΞΉ']
@[simp]
theorem biUnion_and' (p : ΞΉ' β Prop) (q : ΞΉ β ΞΉ' β Prop) (s : β x y, p y β§ q x y β Set Ξ±) :
β (x : ΞΉ) (y : ΞΉ') (h : p y β§ q x y), s x y h =
β (y : ΞΉ') (hy : p y) (x : ΞΉ) (hx : q x y), s x y β¨hy, hxβ© := by
simp only [iUnion_and, @iUnion_comm _ ΞΉ]
@[simp]
theorem biInter_and (p : ΞΉ β Prop) (q : ΞΉ β ΞΉ' β Prop) (s : β x y, p x β§ q x y β Set Ξ±) :
β (x : ΞΉ) (y : ΞΉ') (h : p x β§ q x y), s x y h =
β (x : ΞΉ) (hx : p x) (y : ΞΉ') (hy : q x y), s x y β¨hx, hyβ© := by
simp only [iInter_and, @iInter_comm _ ΞΉ']
@[simp]
theorem biInter_and' (p : ΞΉ' β Prop) (q : ΞΉ β ΞΉ' β Prop) (s : β x y, p y β§ q x y β Set Ξ±) :
β (x : ΞΉ) (y : ΞΉ') (h : p y β§ q x y), s x y h =
β (y : ΞΉ') (hy : p y) (x : ΞΉ) (hx : q x y), s x y β¨hy, hxβ© := by
simp only [iInter_and, @iInter_comm _ ΞΉ]
@[simp]
theorem iUnion_iUnion_eq_or_left {b : Ξ²} {p : Ξ² β Prop} {s : β x : Ξ², x = b β¨ p x β Set Ξ±} :
β (x) (h), s x h = s b (Or.inl rfl) βͺ β (x) (h : p x), s x (Or.inr h) := by
simp only [iUnion_or, iUnion_union_distrib, iUnion_iUnion_eq_left]
@[simp]
theorem iInter_iInter_eq_or_left {b : Ξ²} {p : Ξ² β Prop} {s : β x : Ξ², x = b β¨ p x β Set Ξ±} :
β (x) (h), s x h = s b (Or.inl rfl) β© β (x) (h : p x), s x (Or.inr h) := by
simp only [iInter_or, iInter_inter_distrib, iInter_iInter_eq_left]
lemma iUnion_sum {s : Ξ± β Ξ² β Set Ξ³} : β x, s x = (β x, s (.inl x)) βͺ β x, s (.inr x) := iSup_sum
lemma iInter_sum {s : Ξ± β Ξ² β Set Ξ³} : β x, s x = (β x, s (.inl x)) β© β x, s (.inr x) := iInf_sum
theorem iUnion_psigma {Ξ³ : Ξ± β Type*} (s : PSigma Ξ³ β Set Ξ²) : β ia, s ia = β i, β a, s β¨i, aβ© :=
iSup_psigma _
/-- A reversed version of `iUnion_psigma` with a curried map. -/
theorem iUnion_psigma' {Ξ³ : Ξ± β Type*} (s : β i, Ξ³ i β Set Ξ²) :
β i, β a, s i a = β ia : PSigma Ξ³, s ia.1 ia.2 :=
iSup_psigma' _
theorem iInter_psigma {Ξ³ : Ξ± β Type*} (s : PSigma Ξ³ β Set Ξ²) : β ia, s ia = β i, β a, s β¨i, aβ© :=
iInf_psigma _
/-- A reversed version of `iInter_psigma` with a curried map. -/
theorem iInter_psigma' {Ξ³ : Ξ± β Type*} (s : β i, Ξ³ i β Set Ξ²) :
β i, β a, s i a = β ia : PSigma Ξ³, s ia.1 ia.2 :=
iInf_psigma' _
/-! ### Bounded unions and intersections -/
/-- A specialization of `mem_iUnionβ`. -/
theorem mem_biUnion {s : Set Ξ±} {t : Ξ± β Set Ξ²} {x : Ξ±} {y : Ξ²} (xs : x β s) (ytx : y β t x) :
y β β x β s, t x :=
mem_iUnionβ_of_mem xs ytx
/-- A specialization of `mem_iInterβ`. -/
theorem mem_biInter {s : Set Ξ±} {t : Ξ± β Set Ξ²} {y : Ξ²} (h : β x β s, y β t x) :
y β β x β s, t x :=
mem_iInterβ_of_mem h
/-- A specialization of `subset_iUnionβ`. -/
theorem subset_biUnion_of_mem {s : Set Ξ±} {u : Ξ± β Set Ξ²} {x : Ξ±} (xs : x β s) :
u x β β x β s, u x :=
subset_iUnionβ (s := fun i _ => u i) x xs
/-- A specialization of `iInterβ_subset`. -/
theorem biInter_subset_of_mem {s : Set Ξ±} {t : Ξ± β Set Ξ²} {x : Ξ±} (xs : x β s) :
β x β s, t x β t x :=
iInterβ_subset x xs
lemma biInter_subset_biUnion {s : Set Ξ±} (hs : s.Nonempty) {t : Ξ± β Set Ξ²} :
β x β s, t x β β x β s, t x := biInf_le_biSup hs
theorem biUnion_subset_biUnion_left {s s' : Set Ξ±} {t : Ξ± β Set Ξ²} (h : s β s') :
β x β s, t x β β x β s', t x :=
iUnionβ_subset fun _ hx => subset_biUnion_of_mem <| h hx
theorem biInter_subset_biInter_left {s s' : Set Ξ±} {t : Ξ± β Set Ξ²} (h : s' β s) :
β x β s, t x β β x β s', t x :=
subset_iInterβ fun _ hx => biInter_subset_of_mem <| h hx
theorem biUnion_mono {s s' : Set Ξ±} {t t' : Ξ± β Set Ξ²} (hs : s' β s) (h : β x β s, t x β t' x) :
β x β s', t x β β x β s, t' x :=
(biUnion_subset_biUnion_left hs).trans <| iUnionβ_mono h
theorem biInter_mono {s s' : Set Ξ±} {t t' : Ξ± β Set Ξ²} (hs : s β s') (h : β x β s, t x β t' x) :
β x β s', t x β β x β s, t' x :=
(biInter_subset_biInter_left hs).trans <| iInterβ_mono h
theorem biUnion_eq_iUnion (s : Set Ξ±) (t : β x β s, Set Ξ²) :
β x β s, t x βΉ_βΊ = β x : s, t x x.2 :=
iSup_subtype'
theorem biInter_eq_iInter (s : Set Ξ±) (t : β x β s, Set Ξ²) :
β x β s, t x βΉ_βΊ = β x : s, t x x.2 :=
iInf_subtype'
@[simp] lemma biUnion_const {s : Set Ξ±} (hs : s.Nonempty) (t : Set Ξ²) : β a β s, t = t :=
biSup_const hs
@[simp] lemma biInter_const {s : Set Ξ±} (hs : s.Nonempty) (t : Set Ξ²) : β a β s, t = t :=
biInf_const hs
theorem iUnion_subtype (p : Ξ± β Prop) (s : { x // p x } β Set Ξ²) :
β x : { x // p x }, s x = β (x) (hx : p x), s β¨x, hxβ© :=
iSup_subtype
theorem iInter_subtype (p : Ξ± β Prop) (s : { x // p x } β Set Ξ²) :
β x : { x // p x }, s x = β (x) (hx : p x), s β¨x, hxβ© :=
iInf_subtype
theorem biInter_empty (u : Ξ± β Set Ξ²) : β x β (β
: Set Ξ±), u x = univ :=
iInf_emptyset
theorem biInter_univ (u : Ξ± β Set Ξ²) : β x β @univ Ξ±, u x = β x, u x :=
iInf_univ
@[simp]
theorem biUnion_self (s : Set Ξ±) : β x β s, s = s :=
Subset.antisymm (iUnionβ_subset fun _ _ => Subset.refl s) fun _ hx => mem_biUnion hx hx
@[simp]
theorem iUnion_nonempty_self (s : Set Ξ±) : β _ : s.Nonempty, s = s := by
rw [iUnion_nonempty_index, biUnion_self]
theorem biInter_singleton (a : Ξ±) (s : Ξ± β Set Ξ²) : β x β ({a} : Set Ξ±), s x = s a :=
iInf_singleton
theorem biInter_union (s t : Set Ξ±) (u : Ξ± β Set Ξ²) :
β x β s βͺ t, u x = (β x β s, u x) β© β x β t, u x :=
iInf_union
theorem biInter_insert (a : Ξ±) (s : Set Ξ±) (t : Ξ± β Set Ξ²) :
β x β insert a s, t x = t a β© β x β s, t x := by simp
theorem biInter_pair (a b : Ξ±) (s : Ξ± β Set Ξ²) : β x β ({a, b} : Set Ξ±), s x = s a β© s b := by
rw [biInter_insert, biInter_singleton]
theorem biInter_inter {ΞΉ Ξ± : Type*} {s : Set ΞΉ} (hs : s.Nonempty) (f : ΞΉ β Set Ξ±) (t : Set Ξ±) :
β i β s, f i β© t = (β i β s, f i) β© t := by
haveI : Nonempty s := hs.to_subtype
simp [biInter_eq_iInter, β iInter_inter]
theorem inter_biInter {ΞΉ Ξ± : Type*} {s : Set ΞΉ} (hs : s.Nonempty) (f : ΞΉ β Set Ξ±) (t : Set Ξ±) :
β i β s, t β© f i = t β© β i β s, f i := by
rw [inter_comm, β biInter_inter hs]
simp [inter_comm]
theorem biUnion_empty (s : Ξ± β Set Ξ²) : β x β (β
: Set Ξ±), s x = β
:=
iSup_emptyset
theorem biUnion_univ (s : Ξ± β Set Ξ²) : β x β @univ Ξ±, s x = β x, s x :=
iSup_univ
theorem biUnion_singleton (a : Ξ±) (s : Ξ± β Set Ξ²) : β x β ({a} : Set Ξ±), s x = s a :=
iSup_singleton
@[simp]
theorem biUnion_of_singleton (s : Set Ξ±) : β x β s, {x} = s :=
ext <| by simp
theorem biUnion_union (s t : Set Ξ±) (u : Ξ± β Set Ξ²) :
β x β s βͺ t, u x = (β x β s, u x) βͺ β x β t, u x :=
iSup_union
@[simp]
theorem iUnion_coe_set {Ξ± Ξ² : Type*} (s : Set Ξ±) (f : s β Set Ξ²) :
β i, f i = β i β s, f β¨i, βΉi β sβΊβ© :=
iUnion_subtype _ _
@[simp]
theorem iInter_coe_set {Ξ± Ξ² : Type*} (s : Set Ξ±) (f : s β Set Ξ²) :
β i, f i = β i β s, f β¨i, βΉi β sβΊβ© :=
iInter_subtype _ _
theorem biUnion_insert (a : Ξ±) (s : Set Ξ±) (t : Ξ± β Set Ξ²) :
β x β insert a s, t x = t a βͺ β x β s, t x := by simp
theorem biUnion_pair (a b : Ξ±) (s : Ξ± β Set Ξ²) : β x β ({a, b} : Set Ξ±), s x = s a βͺ s b := by
simp
theorem inter_iUnionβ (s : Set Ξ±) (t : β i, ΞΊ i β Set Ξ±) :
(s β© β (i) (j), t i j) = β (i) (j), s β© t i j := by simp only [inter_iUnion]
theorem iUnionβ_inter (s : β i, ΞΊ i β Set Ξ±) (t : Set Ξ±) :
(β (i) (j), s i j) β© t = β (i) (j), s i j β© t := by simp_rw [iUnion_inter]
theorem union_iInterβ (s : Set Ξ±) (t : β i, ΞΊ i β Set Ξ±) :
(s βͺ β (i) (j), t i j) = β (i) (j), s βͺ t i j := by simp_rw [union_iInter]
theorem iInterβ_union (s : β i, ΞΊ i β Set Ξ±) (t : Set Ξ±) :
(β (i) (j), s i j) βͺ t = β (i) (j), s i j βͺ t := by simp_rw [iInter_union]
theorem mem_sUnion_of_mem {x : Ξ±} {t : Set Ξ±} {S : Set (Set Ξ±)} (hx : x β t) (ht : t β S) :
x β ββ S :=
β¨t, ht, hxβ©
-- is this theorem really necessary?
theorem not_mem_of_not_mem_sUnion {x : Ξ±} {t : Set Ξ±} {S : Set (Set Ξ±)} (hx : x β ββ S)
(ht : t β S) : x β t := fun h => hx β¨t, ht, hβ©
theorem sInter_subset_of_mem {S : Set (Set Ξ±)} {t : Set Ξ±} (tS : t β S) : ββ S β t :=
sInf_le tS
theorem subset_sUnion_of_mem {S : Set (Set Ξ±)} {t : Set Ξ±} (tS : t β S) : t β ββ S :=
le_sSup tS
theorem subset_sUnion_of_subset {s : Set Ξ±} (t : Set (Set Ξ±)) (u : Set Ξ±) (hβ : s β u)
(hβ : u β t) : s β ββ t :=
Subset.trans hβ (subset_sUnion_of_mem hβ)
theorem sUnion_subset {S : Set (Set Ξ±)} {t : Set Ξ±} (h : β t' β S, t' β t) : ββ S β t :=
sSup_le h
@[simp]
theorem sUnion_subset_iff {s : Set (Set Ξ±)} {t : Set Ξ±} : ββ s β t β β t' β s, t' β t :=
sSup_le_iff
/-- `sUnion` is monotone under taking a subset of each set. -/
lemma sUnion_mono_subsets {s : Set (Set Ξ±)} {f : Set Ξ± β Set Ξ±} (hf : β t : Set Ξ±, t β f t) :
ββ s β ββ (f '' s) :=
fun _ β¨t, htx, hxtβ© β¦ β¨f t, mem_image_of_mem f htx, hf t hxtβ©
/-- `sUnion` is monotone under taking a superset of each set. -/
lemma sUnion_mono_supsets {s : Set (Set Ξ±)} {f : Set Ξ± β Set Ξ±} (hf : β t : Set Ξ±, f t β t) :
ββ (f '' s) β ββ s :=
-- If t β f '' s is arbitrary; t = f u for some u : Set Ξ±.
fun _ β¨_, β¨u, hus, hutβ©, hxtβ© β¦ β¨u, hus, (hut βΈ hf u) hxtβ©
theorem subset_sInter {S : Set (Set Ξ±)} {t : Set Ξ±} (h : β t' β S, t β t') : t β ββ S :=
le_sInf h
@[simp]
theorem subset_sInter_iff {S : Set (Set Ξ±)} {t : Set Ξ±} : t β ββ S β β t' β S, t β t' :=
le_sInf_iff
@[gcongr]
theorem sUnion_subset_sUnion {S T : Set (Set Ξ±)} (h : S β T) : ββ S β ββ T :=
sUnion_subset fun _ hs => subset_sUnion_of_mem (h hs)
@[gcongr]
theorem sInter_subset_sInter {S T : Set (Set Ξ±)} (h : S β T) : ββ T β ββ S :=
subset_sInter fun _ hs => sInter_subset_of_mem (h hs)
@[simp]
theorem sUnion_empty : ββ β
= (β
: Set Ξ±) :=
sSup_empty
@[simp]
theorem sInter_empty : ββ β
= (univ : Set Ξ±) :=
sInf_empty
@[simp]
theorem sUnion_singleton (s : Set Ξ±) : ββ {s} = s :=
sSup_singleton
@[simp]
theorem sInter_singleton (s : Set Ξ±) : ββ {s} = s :=
sInf_singleton
@[simp]
theorem sUnion_eq_empty {S : Set (Set Ξ±)} : ββ S = β
β β s β S, s = β
:=
sSup_eq_bot
@[simp]
theorem sInter_eq_univ {S : Set (Set Ξ±)} : ββ S = univ β β s β S, s = univ :=
sInf_eq_top
theorem subset_powerset_iff {s : Set (Set Ξ±)} {t : Set Ξ±} : s β π« t β ββ s β t :=
sUnion_subset_iff.symm
/-- `ββ` and `π«` form a Galois connection. -/
theorem sUnion_powerset_gc :
GaloisConnection (ββ Β· : Set (Set Ξ±) β Set Ξ±) (π« Β· : Set Ξ± β Set (Set Ξ±)) :=
gc_sSup_Iic
/-- `ββ` and `π«` form a Galois insertion. -/
def sUnionPowersetGI :
GaloisInsertion (ββ Β· : Set (Set Ξ±) β Set Ξ±) (π« Β· : Set Ξ± β Set (Set Ξ±)) :=
gi_sSup_Iic
@[deprecated (since := "2024-12-07")] alias sUnion_powerset_gi := sUnionPowersetGI
/-- If all sets in a collection are either `β
` or `Set.univ`, then so is their union. -/
theorem sUnion_mem_empty_univ {S : Set (Set Ξ±)} (h : S β {β
, univ}) :
ββ S β ({β
, univ} : Set (Set Ξ±)) := by
simp only [mem_insert_iff, mem_singleton_iff, or_iff_not_imp_left, sUnion_eq_empty, not_forall]
rintro β¨s, hs, hneβ©
obtain rfl : s = univ := (h hs).resolve_left hne
exact univ_subset_iff.1 <| subset_sUnion_of_mem hs
@[simp]
theorem nonempty_sUnion {S : Set (Set Ξ±)} : (ββ S).Nonempty β β s β S, Set.Nonempty s := by
simp [nonempty_iff_ne_empty]
theorem Nonempty.of_sUnion {s : Set (Set Ξ±)} (h : (ββ s).Nonempty) : s.Nonempty :=
let β¨s, hs, _β© := nonempty_sUnion.1 h
β¨s, hsβ©
theorem Nonempty.of_sUnion_eq_univ [Nonempty Ξ±] {s : Set (Set Ξ±)} (h : ββ s = univ) : s.Nonempty :=
Nonempty.of_sUnion <| h.symm βΈ univ_nonempty
theorem sUnion_union (S T : Set (Set Ξ±)) : ββ (S βͺ T) = ββ S βͺ ββ T :=
sSup_union
theorem sInter_union (S T : Set (Set Ξ±)) : ββ (S βͺ T) = ββ S β© ββ T :=
sInf_union
@[simp]
theorem sUnion_insert (s : Set Ξ±) (T : Set (Set Ξ±)) : ββ insert s T = s βͺ ββ T :=
sSup_insert
@[simp]
theorem sInter_insert (s : Set Ξ±) (T : Set (Set Ξ±)) : ββ insert s T = s β© ββ T :=
sInf_insert
@[simp]
theorem sUnion_diff_singleton_empty (s : Set (Set Ξ±)) : ββ (s \ {β
}) = ββ s :=
sSup_diff_singleton_bot s
@[simp]
theorem sInter_diff_singleton_univ (s : Set (Set Ξ±)) : ββ (s \ {univ}) = ββ s :=
sInf_diff_singleton_top s
theorem sUnion_pair (s t : Set Ξ±) : ββ {s, t} = s βͺ t :=
sSup_pair
theorem sInter_pair (s t : Set Ξ±) : ββ {s, t} = s β© t :=
sInf_pair
@[simp]
theorem sUnion_image (f : Ξ± β Set Ξ²) (s : Set Ξ±) : ββ (f '' s) = β a β s, f a :=
sSup_image
@[simp]
theorem sInter_image (f : Ξ± β Set Ξ²) (s : Set Ξ±) : ββ (f '' s) = β a β s, f a :=
sInf_image
@[simp]
lemma sUnion_image2 (f : Ξ± β Ξ² β Set Ξ³) (s : Set Ξ±) (t : Set Ξ²) :
ββ (image2 f s t) = β (a β s) (b β t), f a b := sSup_image2
@[simp]
lemma sInter_image2 (f : Ξ± β Ξ² β Set Ξ³) (s : Set Ξ±) (t : Set Ξ²) :
ββ (image2 f s t) = β (a β s) (b β t), f a b := sInf_image2
@[simp]
theorem sUnion_range (f : ΞΉ β Set Ξ²) : ββ range f = β x, f x :=
rfl
@[simp]
theorem sInter_range (f : ΞΉ β Set Ξ²) : ββ range f = β x, f x :=
rfl
theorem iUnion_eq_univ_iff {f : ΞΉ β Set Ξ±} : β i, f i = univ β β x, β i, x β f i := by
simp only [eq_univ_iff_forall, mem_iUnion]
theorem iUnionβ_eq_univ_iff {s : β i, ΞΊ i β Set Ξ±} :
β (i) (j), s i j = univ β β a, β i j, a β s i j := by
simp only [iUnion_eq_univ_iff, mem_iUnion]
theorem sUnion_eq_univ_iff {c : Set (Set Ξ±)} : ββ c = univ β β a, β b β c, a β b := by
simp only [eq_univ_iff_forall, mem_sUnion]
-- classical
theorem iInter_eq_empty_iff {f : ΞΉ β Set Ξ±} : β i, f i = β
β β x, β i, x β f i := by
simp [Set.eq_empty_iff_forall_not_mem]
-- classical
theorem iInterβ_eq_empty_iff {s : β i, ΞΊ i β Set Ξ±} :
β (i) (j), s i j = β
β β a, β i j, a β s i j := by
simp only [eq_empty_iff_forall_not_mem, mem_iInter, not_forall]
-- classical
theorem sInter_eq_empty_iff {c : Set (Set Ξ±)} : ββ c = β
β β a, β b β c, a β b := by
simp [Set.eq_empty_iff_forall_not_mem]
-- classical
@[simp]
theorem nonempty_iInter {f : ΞΉ β Set Ξ±} : (β i, f i).Nonempty β β x, β i, x β f i := by
simp [nonempty_iff_ne_empty, iInter_eq_empty_iff]
-- classical
theorem nonempty_iInterβ {s : β i, ΞΊ i β Set Ξ±} :
(β (i) (j), s i j).Nonempty β β a, β i j, a β s i j := by
simp
-- classical
@[simp]
theorem nonempty_sInter {c : Set (Set Ξ±)} : (ββ c).Nonempty β β a, β b β c, a β b := by
simp [nonempty_iff_ne_empty, sInter_eq_empty_iff]
-- classical
theorem compl_sUnion (S : Set (Set Ξ±)) : (ββ S)αΆ = ββ (compl '' S) :=
ext fun x => by simp
-- classical
theorem sUnion_eq_compl_sInter_compl (S : Set (Set Ξ±)) : ββ S = (ββ (compl '' S))αΆ := by
rw [β compl_compl (ββ S), compl_sUnion]
-- classical
theorem compl_sInter (S : Set (Set Ξ±)) : (ββ S)αΆ = ββ (compl '' S) := by
rw [sUnion_eq_compl_sInter_compl, compl_compl_image]
-- classical
theorem sInter_eq_compl_sUnion_compl (S : Set (Set Ξ±)) : ββ S = (ββ (compl '' S))αΆ := by
rw [β compl_compl (ββ S), compl_sInter]
theorem inter_empty_of_inter_sUnion_empty {s t : Set Ξ±} {S : Set (Set Ξ±)} (hs : t β S)
(h : s β© ββ S = β
) : s β© t = β
:=
eq_empty_of_subset_empty <| by
rw [β h]; exact inter_subset_inter_right _ (subset_sUnion_of_mem hs)
theorem range_sigma_eq_iUnion_range {Ξ³ : Ξ± β Type*} (f : Sigma Ξ³ β Ξ²) :
range f = β a, range fun b => f β¨a, bβ© :=
Set.ext <| by simp
theorem iUnion_eq_range_sigma (s : Ξ± β Set Ξ²) : β i, s i = range fun a : Ξ£i, s i => a.2 := by
simp [Set.ext_iff]
theorem iUnion_eq_range_psigma (s : ΞΉ β Set Ξ²) : β i, s i = range fun a : Ξ£'i, s i => a.2 := by
simp [Set.ext_iff]
theorem iUnion_image_preimage_sigma_mk_eq_self {ΞΉ : Type*} {Ο : ΞΉ β Type*} (s : Set (Sigma Ο)) :
β i, Sigma.mk i '' (Sigma.mk i β»ΒΉ' s) = s := by
ext x
simp only [mem_iUnion, mem_image, mem_preimage]
constructor
Β· rintro β¨i, a, h, rflβ©
exact h
Β· intro h
obtain β¨i, aβ© := x
exact β¨i, a, h, rflβ©
theorem Sigma.univ (X : Ξ± β Type*) : (Set.univ : Set (Ξ£a, X a)) = β a, range (Sigma.mk a) :=
Set.ext fun x =>
iff_of_true trivial β¨range (Sigma.mk x.1), Set.mem_range_self _, x.2, Sigma.eta xβ©
alias sUnion_mono := sUnion_subset_sUnion
alias sInter_mono := sInter_subset_sInter
theorem iUnion_subset_iUnion_const {s : Set Ξ±} (h : ΞΉ β ΞΉβ) : β _ : ΞΉ, s β β _ : ΞΉβ, s :=
iSup_const_mono (Ξ± := Set Ξ±) h
@[simp]
theorem iUnion_singleton_eq_range (f : Ξ± β Ξ²) : β x : Ξ±, {f x} = range f := by
ext x
simp [@eq_comm _ x]
theorem iUnion_insert_eq_range_union_iUnion {ΞΉ : Type*} (x : ΞΉ β Ξ²) (t : ΞΉ β Set Ξ²) :
β i, insert (x i) (t i) = range x βͺ β i, t i := by
simp_rw [β union_singleton, iUnion_union_distrib, union_comm, iUnion_singleton_eq_range]
theorem iUnion_of_singleton (Ξ± : Type*) : (β x, {x} : Set Ξ±) = univ := by simp [Set.ext_iff]
theorem iUnion_of_singleton_coe (s : Set Ξ±) : β i : s, ({(i : Ξ±)} : Set Ξ±) = s := by simp
theorem sUnion_eq_biUnion {s : Set (Set Ξ±)} : ββ s = β (i : Set Ξ±) (_ : i β s), i := by
rw [β sUnion_image, image_id']
theorem sInter_eq_biInter {s : Set (Set Ξ±)} : ββ s = β (i : Set Ξ±) (_ : i β s), i := by
rw [β sInter_image, image_id']
theorem sUnion_eq_iUnion {s : Set (Set Ξ±)} : ββ s = β i : s, i := by
simp only [β sUnion_range, Subtype.range_coe]
theorem sInter_eq_iInter {s : Set (Set Ξ±)} : ββ s = β i : s, i := by
simp only [β sInter_range, Subtype.range_coe]
@[simp]
theorem iUnion_of_empty [IsEmpty ΞΉ] (s : ΞΉ β Set Ξ±) : β i, s i = β
:=
iSup_of_empty _
@[simp]
theorem iInter_of_empty [IsEmpty ΞΉ] (s : ΞΉ β Set Ξ±) : β i, s i = univ :=
iInf_of_empty _
theorem union_eq_iUnion {sβ sβ : Set Ξ±} : sβ βͺ sβ = β b : Bool, cond b sβ sβ :=
sup_eq_iSup sβ sβ
theorem inter_eq_iInter {sβ sβ : Set Ξ±} : sβ β© sβ = β b : Bool, cond b sβ sβ :=
inf_eq_iInf sβ sβ
theorem sInter_union_sInter {S T : Set (Set Ξ±)} :
ββ S βͺ ββ T = β p β S ΓΛ’ T, (p : Set Ξ± Γ Set Ξ±).1 βͺ p.2 :=
sInf_sup_sInf
theorem sUnion_inter_sUnion {s t : Set (Set Ξ±)} :
ββ s β© ββ t = β p β s ΓΛ’ t, (p : Set Ξ± Γ Set Ξ±).1 β© p.2 :=
sSup_inf_sSup
theorem biUnion_iUnion (s : ΞΉ β Set Ξ±) (t : Ξ± β Set Ξ²) :
β x β β i, s i, t x = β (i) (x β s i), t x := by simp [@iUnion_comm _ ΞΉ]
theorem biInter_iUnion (s : ΞΉ β Set Ξ±) (t : Ξ± β Set Ξ²) :
β x β β i, s i, t x = β (i) (x β s i), t x := by simp [@iInter_comm _ ΞΉ]
theorem sUnion_iUnion (s : ΞΉ β Set (Set Ξ±)) : ββ β i, s i = β i, ββ s i := by
simp only [sUnion_eq_biUnion, biUnion_iUnion]
theorem sInter_iUnion (s : ΞΉ β Set (Set Ξ±)) : ββ β i, s i = β i, ββ s i := by
simp only [sInter_eq_biInter, biInter_iUnion]
theorem iUnion_range_eq_sUnion {Ξ± Ξ² : Type*} (C : Set (Set Ξ±)) {f : β s : C, Ξ² β (s : Type _)}
(hf : β s : C, Surjective (f s)) : β y : Ξ², range (fun s : C => (f s y).val) = ββ C := by
ext x; constructor
Β· rintro β¨s, β¨y, rflβ©, β¨s, hsβ©, rflβ©
refine β¨_, hs, ?_β©
exact (f β¨s, hsβ© y).2
Β· rintro β¨s, hs, hxβ©
obtain β¨y, hyβ© := hf β¨s, hsβ© β¨x, hxβ©
refine β¨_, β¨y, rflβ©, β¨s, hsβ©, ?_β©
exact congr_arg Subtype.val hy
theorem iUnion_range_eq_iUnion (C : ΞΉ β Set Ξ±) {f : β x : ΞΉ, Ξ² β C x}
(hf : β x : ΞΉ, Surjective (f x)) : β y : Ξ², range (fun x : ΞΉ => (f x y).val) = β x, C x := by
ext x; rw [mem_iUnion, mem_iUnion]; constructor
Β· rintro β¨y, i, rflβ©
exact β¨i, (f i y).2β©
Β· rintro β¨i, hxβ©
obtain β¨y, hyβ© := hf i β¨x, hxβ©
exact β¨y, i, congr_arg Subtype.val hyβ©
theorem union_distrib_iInter_left (s : ΞΉ β Set Ξ±) (t : Set Ξ±) : (t βͺ β i, s i) = β i, t βͺ s i :=
sup_iInf_eq _ _
theorem union_distrib_iInterβ_left (s : Set Ξ±) (t : β i, ΞΊ i β Set Ξ±) :
(s βͺ β (i) (j), t i j) = β (i) (j), s βͺ t i j := by simp_rw [union_distrib_iInter_left]
theorem union_distrib_iInter_right (s : ΞΉ β Set Ξ±) (t : Set Ξ±) : (β i, s i) βͺ t = β i, s i βͺ t :=
iInf_sup_eq _ _
theorem union_distrib_iInterβ_right (s : β i, ΞΊ i β Set Ξ±) (t : Set Ξ±) :
(β (i) (j), s i j) βͺ t = β (i) (j), s i j βͺ t := by simp_rw [union_distrib_iInter_right]
lemma biUnion_lt_eq_iUnion [LT Ξ±] [NoMaxOrder Ξ±] {s : Ξ± β Set Ξ²} :
β (n) (m < n), s m = β n, s n := biSup_lt_eq_iSup
lemma biUnion_le_eq_iUnion [Preorder Ξ±] {s : Ξ± β Set Ξ²} :
β (n) (m β€ n), s m = β n, s n := biSup_le_eq_iSup
lemma biInter_lt_eq_iInter [LT Ξ±] [NoMaxOrder Ξ±] {s : Ξ± β Set Ξ²} :
β (n) (m < n), s m = β (n), s n := biInf_lt_eq_iInf
lemma biInter_le_eq_iInter [Preorder Ξ±] {s : Ξ± β Set Ξ²} :
β (n) (m β€ n), s m = β (n), s n := biInf_le_eq_iInf
lemma biUnion_gt_eq_iUnion [LT Ξ±] [NoMinOrder Ξ±] {s : Ξ± β Set Ξ²} :
β (n) (m > n), s m = β n, s n := biSup_gt_eq_iSup
lemma biUnion_ge_eq_iUnion [Preorder Ξ±] {s : Ξ± β Set Ξ²} :
β (n) (m β₯ n), s m = β n, s n := biSup_ge_eq_iSup
lemma biInter_gt_eq_iInf [LT Ξ±] [NoMinOrder Ξ±] {s : Ξ± β Set Ξ²} :
β (n) (m > n), s m = β n, s n := biInf_gt_eq_iInf
lemma biInter_ge_eq_iInf [Preorder Ξ±] {s : Ξ± β Set Ξ²} :
β (n) (m β₯ n), s m = β n, s n := biInf_ge_eq_iInf
section le
variable {ΞΉ : Type*} [PartialOrder ΞΉ] (s : ΞΉ β Set Ξ±) (i : ΞΉ)
theorem biUnion_le : (β j β€ i, s j) = (β j < i, s j) βͺ s i :=
biSup_le_eq_sup s i
theorem biInter_le : (β j β€ i, s j) = (β j < i, s j) β© s i :=
biInf_le_eq_inf s i
theorem biUnion_ge : (β j β₯ i, s j) = s i βͺ β j > i, s j :=
biSup_ge_eq_sup s i
theorem biInter_ge : (β j β₯ i, s j) = s i β© β j > i, s j :=
biInf_ge_eq_inf s i
end le
section Pi
variable {Ο : Ξ± β Type*}
theorem pi_def (i : Set Ξ±) (s : β a, Set (Ο a)) : pi i s = β a β i, eval a β»ΒΉ' s a := by
ext
simp
theorem univ_pi_eq_iInter (t : β i, Set (Ο i)) : pi univ t = β i, eval i β»ΒΉ' t i := by
simp only [pi_def, iInter_true, mem_univ]
theorem pi_diff_pi_subset (i : Set Ξ±) (s t : β a, Set (Ο a)) :
pi i s \ pi i t β β a β i, eval a β»ΒΉ' (s a \ t a) := by
refine diff_subset_comm.2 fun x hx a ha => ?_
simp only [mem_diff, mem_pi, mem_iUnion, not_exists, mem_preimage, not_and, not_not,
eval_apply] at hx
exact hx.2 _ ha (hx.1 _ ha)
theorem iUnion_univ_pi {ΞΉ : Ξ± β Type*} (t : (a : Ξ±) β ΞΉ a β Set (Ο a)) :
β x : (a : Ξ±) β ΞΉ a, pi univ (fun a => t a (x a)) = pi univ fun a => β j : ΞΉ a, t a j := by
ext
simp [Classical.skolem]
end Pi
section Directed
theorem directedOn_iUnion {r} {f : ΞΉ β Set Ξ±} (hd : Directed (Β· β Β·) f)
(h : β x, DirectedOn r (f x)) : DirectedOn r (β x, f x) := by
simp only [DirectedOn, exists_prop, mem_iUnion, exists_imp]
exact fun aβ bβ fbβ aβ bβ fbβ =>
let β¨z, zbβ, zbββ© := hd bβ bβ
let β¨x, xf, xaβ, xaββ© := h z aβ (zbβ fbβ) aβ (zbβ fbβ)
β¨x, β¨z, xfβ©, xaβ, xaββ©
theorem directedOn_sUnion {r} {S : Set (Set Ξ±)} (hd : DirectedOn (Β· β Β·) S)
(h : β x β S, DirectedOn r x) : DirectedOn r (ββ S) := by
rw [sUnion_eq_iUnion]
exact directedOn_iUnion (directedOn_iff_directed.mp hd) (fun i β¦ h i.1 i.2)
theorem pairwise_iUnionβ {S : Set (Set Ξ±)} (hd : DirectedOn (Β· β Β·) S)
(r : Ξ± β Ξ± β Prop) (h : β s β S, s.Pairwise r) : (β s β S, s).Pairwise r := by
simp only [Set.Pairwise, Set.mem_iUnion, exists_prop, forall_exists_index, and_imp]
intro x S hS hx y T hT hy hne
obtain β¨U, hU, hSU, hTUβ© := hd S hS T hT
exact h U hU (hSU hx) (hTU hy) hne
end Directed
end Set
namespace Function
namespace Surjective
theorem iUnion_comp {f : ΞΉ β ΞΉβ} (hf : Surjective f) (g : ΞΉβ β Set Ξ±) : β x, g (f x) = β y, g y :=
hf.iSup_comp g
theorem iInter_comp {f : ΞΉ β ΞΉβ} (hf : Surjective f) (g : ΞΉβ β Set Ξ±) : β x, g (f x) = β y, g y :=
hf.iInf_comp g
end Surjective
end Function
/-!
### Disjoint sets
-/
section Disjoint
variable {s t : Set Ξ±}
namespace Set
@[simp]
theorem disjoint_iUnion_left {ΞΉ : Sort*} {s : ΞΉ β Set Ξ±} :
Disjoint (β i, s i) t β β i, Disjoint (s i) t :=
iSup_disjoint_iff
@[simp]
theorem disjoint_iUnion_right {ΞΉ : Sort*} {s : ΞΉ β Set Ξ±} :
Disjoint t (β i, s i) β β i, Disjoint t (s i) :=
disjoint_iSup_iff
theorem disjoint_iUnionβ_left {s : β i, ΞΊ i β Set Ξ±} {t : Set Ξ±} :
Disjoint (β (i) (j), s i j) t β β i j, Disjoint (s i j) t :=
iSupβ_disjoint_iff
theorem disjoint_iUnionβ_right {s : Set Ξ±} {t : β i, ΞΊ i β Set Ξ±} :
Disjoint s (β (i) (j), t i j) β β i j, Disjoint s (t i j) :=
disjoint_iSupβ_iff
@[simp]
theorem disjoint_sUnion_left {S : Set (Set Ξ±)} {t : Set Ξ±} :
Disjoint (ββ S) t β β s β S, Disjoint s t :=
sSup_disjoint_iff
@[simp]
theorem disjoint_sUnion_right {s : Set Ξ±} {S : Set (Set Ξ±)} :
Disjoint s (ββ S) β β t β S, Disjoint s t :=
disjoint_sSup_iff
lemma biUnion_compl_eq_of_pairwise_disjoint_of_iUnion_eq_univ {ΞΉ : Type*} {Es : ΞΉ β Set Ξ±}
(Es_union : β i, Es i = univ) (Es_disj : Pairwise fun i j β¦ Disjoint (Es i) (Es j))
(I : Set ΞΉ) :
(β i β I, Es i)αΆ = β i β IαΆ, Es i := by
ext x
obtain β¨i, hixβ© : β i, x β Es i := by simp [β mem_iUnion, Es_union]
have obs : β (J : Set ΞΉ), x β β j β J, Es j β i β J := by
refine fun J β¦ β¨?_, fun i_in_J β¦ by simpa only [mem_iUnion, exists_prop] using β¨i, i_in_J, hixβ©β©
intro x_in_U
simp only [mem_iUnion, exists_prop] at x_in_U
obtain β¨j, j_in_J, hjxβ© := x_in_U
rwa [show i = j by by_contra i_ne_j; exact Disjoint.ne_of_mem (Es_disj i_ne_j) hix hjx rfl]
have obs' : β (J : Set ΞΉ), x β (β j β J, Es j)αΆ β i β J :=
fun J β¦ by simpa only [mem_compl_iff, not_iff_not] using obs J
rw [obs, obs', mem_compl_iff]
end Set
end Disjoint
/-! ### Intervals -/
namespace Set
lemma nonempty_iInter_Iic_iff [Preorder Ξ±] {f : ΞΉ β Ξ±} :
(β i, Iic (f i)).Nonempty β BddBelow (range f) := by
have : (β (i : ΞΉ), Iic (f i)) = lowerBounds (range f) := by
ext c; simp [lowerBounds]
simp [this, BddBelow]
lemma nonempty_iInter_Ici_iff [Preorder Ξ±] {f : ΞΉ β Ξ±} :
(β i, Ici (f i)).Nonempty β BddAbove (range f) :=
nonempty_iInter_Iic_iff (Ξ± := Ξ±α΅α΅)
variable [CompleteLattice Ξ±]
theorem Ici_iSup (f : ΞΉ β Ξ±) : Ici (β¨ i, f i) = β i, Ici (f i) :=
ext fun _ => by simp only [mem_Ici, iSup_le_iff, mem_iInter]
theorem Iic_iInf (f : ΞΉ β Ξ±) : Iic (β¨
i, f i) = β i, Iic (f i) :=
ext fun _ => by simp only [mem_Iic, le_iInf_iff, mem_iInter]
theorem Ici_iSupβ (f : β i, ΞΊ i β Ξ±) : Ici (β¨ (i) (j), f i j) = β (i) (j), Ici (f i j) := by
simp_rw [Ici_iSup]
theorem Iic_iInfβ (f : β i, ΞΊ i β Ξ±) : Iic (β¨
(i) (j), f i j) = β (i) (j), Iic (f i j) := by
simp_rw [Iic_iInf]
theorem Ici_sSup (s : Set Ξ±) : Ici (sSup s) = β a β s, Ici a := by rw [sSup_eq_iSup, Ici_iSupβ]
theorem Iic_sInf (s : Set Ξ±) : Iic (sInf s) = β a β s, Iic a := by rw [sInf_eq_iInf, Iic_iInfβ]
end Set
namespace Set
variable (t : Ξ± β Set Ξ²)
theorem biUnion_diff_biUnion_subset (sβ sβ : Set Ξ±) :
((β x β sβ, t x) \ β x β sβ, t x) β β x β sβ \ sβ, t x := by
simp only [diff_subset_iff, β biUnion_union]
apply biUnion_subset_biUnion_left
rw [union_diff_self]
apply subset_union_right
/-- If `t` is an indexed family of sets, then there is a natural map from `Ξ£ i, t i` to `β i, t i`
sending `β¨i, xβ©` to `x`. -/
def sigmaToiUnion (x : Ξ£i, t i) : β i, t i :=
β¨x.2, mem_iUnion.2 β¨x.1, x.2.2β©β©
theorem sigmaToiUnion_surjective : Surjective (sigmaToiUnion t)
| β¨b, hbβ© =>
have : β a, b β t a := by simpa using hb
let β¨a, hbβ© := this
β¨β¨a, b, hbβ©, rflβ©
theorem sigmaToiUnion_injective (h : Pairwise (Disjoint on t)) :
Injective (sigmaToiUnion t)
| β¨aβ, bβ, hββ©, β¨aβ, bβ, hββ©, eq =>
have b_eq : bβ = bβ := congr_arg Subtype.val eq
have a_eq : aβ = aβ :=
by_contradiction fun ne =>
have : bβ β t aβ β© t aβ := β¨hβ, b_eq.symm βΈ hββ©
(h ne).le_bot this
Sigma.eq a_eq <| Subtype.eq <| by subst b_eq; subst a_eq; rfl
theorem sigmaToiUnion_bijective (h : Pairwise (Disjoint on t)) :
Bijective (sigmaToiUnion t) :=
β¨sigmaToiUnion_injective t h, sigmaToiUnion_surjective tβ©
/-- Equivalence from the disjoint union of a family of sets forming a partition of `Ξ²`, to `Ξ²`
itself. -/
noncomputable def sigmaEquiv (s : Ξ± β Set Ξ²) (hs : β b, β! i, b β s i) :
(Ξ£ i, s i) β Ξ² where
toFun | β¨_, bβ© => b
invFun b := β¨(hs b).choose, b, (hs b).choose_spec.1β©
left_inv | β¨i, b, hbβ© => Sigma.subtype_ext ((hs b).choose_spec.2 i hb).symm rfl
right_inv _ := rfl
/-- Equivalence between a disjoint union and a dependent sum. -/
noncomputable def unionEqSigmaOfDisjoint {t : Ξ± β Set Ξ²}
(h : Pairwise (Disjoint on t)) :
(β i, t i) β Ξ£i, t i :=
(Equiv.ofBijective _ <| sigmaToiUnion_bijective t h).symm
theorem iUnion_ge_eq_iUnion_nat_add (u : β β Set Ξ±) (n : β) : β i β₯ n, u i = β i, u (i + n) :=
iSup_ge_eq_iSup_nat_add u n
theorem iInter_ge_eq_iInter_nat_add (u : β β Set Ξ±) (n : β) : β i β₯ n, u i = β i, u (i + n) :=
iInf_ge_eq_iInf_nat_add u n
theorem _root_.Monotone.iUnion_nat_add {f : β β Set Ξ±} (hf : Monotone f) (k : β) :
β n, f (n + k) = β n, f n :=
hf.iSup_nat_add k
theorem _root_.Antitone.iInter_nat_add {f : β β Set Ξ±} (hf : Antitone f) (k : β) :
β n, f (n + k) = β n, f n :=
hf.iInf_nat_add k
@[simp]
theorem iUnion_iInter_ge_nat_add (f : β β Set Ξ±) (k : β) :
β n, β i β₯ n, f (i + k) = β n, β i β₯ n, f i :=
iSup_iInf_ge_nat_add f k
theorem union_iUnion_nat_succ (u : β β Set Ξ±) : (u 0 βͺ β i, u (i + 1)) = β i, u i :=
sup_iSup_nat_succ u
theorem inter_iInter_nat_succ (u : β β Set Ξ±) : (u 0 β© β i, u (i + 1)) = β i, u i :=
inf_iInf_nat_succ u
end Set
open Set
variable [CompleteLattice Ξ²]
theorem iSup_iUnion (s : ΞΉ β Set Ξ±) (f : Ξ± β Ξ²) : β¨ a β β i, s i, f a = β¨ (i) (a β s i), f a := by
rw [iSup_comm]
simp_rw [mem_iUnion, iSup_exists]
theorem iInf_iUnion (s : ΞΉ β Set Ξ±) (f : Ξ± β Ξ²) : β¨
a β β i, s i, f a = β¨
(i) (a β s i), f a :=
iSup_iUnion (Ξ² := Ξ²α΅α΅) s f
theorem sSup_iUnion (t : ΞΉ β Set Ξ²) : sSup (β i, t i) = β¨ i, sSup (t i) := by
simp_rw [sSup_eq_iSup, iSup_iUnion]
theorem sSup_sUnion (s : Set (Set Ξ²)) : sSup (ββ s) = β¨ t β s, sSup t := by
simp only [sUnion_eq_biUnion, sSup_eq_iSup, iSup_iUnion]
theorem sInf_sUnion (s : Set (Set Ξ²)) : sInf (ββ s) = β¨
t β s, sInf t :=
sSup_sUnion (Ξ² := Ξ²α΅α΅) s
lemma iSup_sUnion (S : Set (Set Ξ±)) (f : Ξ± β Ξ²) :
(β¨ x β ββ S, f x) = β¨ (s β S) (x β s), f x := by
rw [sUnion_eq_iUnion, iSup_iUnion, β iSup_subtype'']
lemma iInf_sUnion (S : Set (Set Ξ±)) (f : Ξ± β Ξ²) :
(β¨
x β ββ S, f x) = β¨
(s β S) (x β s), f x := by
rw [sUnion_eq_iUnion, iInf_iUnion, β iInf_subtype'']
lemma forall_sUnion {S : Set (Set Ξ±)} {p : Ξ± β Prop} :
(β x β ββ S, p x) β β s β S, β x β s, p x := by
simp_rw [β iInf_Prop_eq, iInf_sUnion]
lemma exists_sUnion {S : Set (Set Ξ±)} {p : Ξ± β Prop} :
(β x β ββ S, p x) β β s β S, β x β s, p x := by
simp_rw [β exists_prop, β iSup_Prop_eq, iSup_sUnion]
| Mathlib/Data/Set/Lattice.lean | 1,972 | 1,973 | |
/-
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.Analysis.InnerProductSpace.Convex
import Mathlib.Analysis.InnerProductSpace.PiL2
import Mathlib.Combinatorics.Additive.AP.Three.Defs
import Mathlib.Combinatorics.Pigeonhole
import Mathlib.Data.Complex.ExponentialBounds
/-!
# Behrend's bound on Roth numbers
This file proves Behrend's lower bound on Roth numbers. This says that we can find a subset of
`{1, ..., n}` of size `n / exp (O (sqrt (log n)))` which does not contain arithmetic progressions of
length `3`.
The idea is that the sphere (in the `n` dimensional Euclidean space) doesn't contain arithmetic
progressions (literally) because the corresponding ball is strictly convex. Thus we can take
integer points on that sphere and map them onto `β` in a way that preserves arithmetic progressions
(`Behrend.map`).
## Main declarations
* `Behrend.sphere`: The intersection of the Euclidean sphere with the positive integer quadrant.
This is the set that we will map on `β`.
* `Behrend.map`: Given a natural number `d`, `Behrend.map d : ββΏ β β` reads off the coordinates as
digits in base `d`.
* `Behrend.card_sphere_le_rothNumberNat`: Implicit lower bound on Roth numbers in terms of
`Behrend.sphere`.
* `Behrend.roth_lower_bound`: Behrend's explicit lower bound on Roth numbers.
## References
* [Bryan Gillespie, *Behrendβs Construction*]
(http://www.epsilonsmall.com/resources/behrends-construction/behrend.pdf)
* Behrend, F. A., "On sets of integers which contain no three terms in arithmetical progression"
* [Wikipedia, *Salem-Spencer set*](https://en.wikipedia.org/wiki/SalemβSpencer_set)
## Tags
3AP-free, Salem-Spencer, Behrend construction, arithmetic progression, sphere, strictly convex
-/
assert_not_exists IsConformalMap Conformal
open Nat hiding log
open Finset Metric Real
open scoped Pointwise
/-- The frontier of a closed strictly convex set only contains trivial arithmetic progressions.
The idea is that an arithmetic progression is contained on a line and the frontier of a strictly
convex set does not contain lines. -/
lemma threeAPFree_frontier {π E : Type*} [Field π] [LinearOrder π] [IsStrictOrderedRing π]
[TopologicalSpace E]
[AddCommMonoid E] [Module π E] {s : Set E} (hsβ : IsClosed s) (hsβ : StrictConvex π s) :
ThreeAPFree (frontier s) := by
intro a ha b hb c hc habc
obtain rfl : (1 / 2 : π) β’ a + (1 / 2 : π) β’ c = b := by
rwa [β smul_add, one_div, inv_smul_eq_iffβ (show (2 : π) β 0 by norm_num), two_smul]
have :=
hsβ.eq (hsβ.frontier_subset ha) (hsβ.frontier_subset hc) one_half_pos one_half_pos
(add_halves _) hb.2
simp [this, β add_smul]
ring_nf
simp
lemma threeAPFree_sphere {E : Type*} [NormedAddCommGroup E] [NormedSpace β E]
[StrictConvexSpace β E] (x : E) (r : β) : ThreeAPFree (sphere x r) := by
obtain rfl | hr := eq_or_ne r 0
Β· rw [sphere_zero]
exact threeAPFree_singleton _
Β· convert threeAPFree_frontier isClosed_closedBall (strictConvex_closedBall β x r)
exact (frontier_closedBall _ hr).symm
namespace Behrend
variable {n d k N : β} {x : Fin n β β}
/-!
### Turning the sphere into 3AP-free set
We define `Behrend.sphere`, the intersection of the $L^2$ sphere with the positive quadrant of
integer points. Because the $L^2$ closed ball is strictly convex, the $L^2$ sphere and
`Behrend.sphere` are 3AP-free (`threeAPFree_sphere`). Then we can turn this set in
`Fin n β β` into a set in `β` using `Behrend.map`, which preserves `ThreeAPFree` because it is
an additive monoid homomorphism.
-/
/-- The box `{0, ..., d - 1}^n` as a `Finset`. -/
def box (n d : β) : Finset (Fin n β β) :=
Fintype.piFinset fun _ => range d
theorem mem_box : x β box n d β β i, x i < d := by simp only [box, Fintype.mem_piFinset, mem_range]
@[simp]
theorem card_box : #(box n d) = d ^ n := by simp [box]
@[simp]
theorem box_zero : box (n + 1) 0 = β
:= by simp [box]
/-- The intersection of the sphere of radius `βk` with the integer points in the positive
quadrant. -/
def sphere (n d k : β) : Finset (Fin n β β) := {x β box n d | β i, x i ^ 2 = k}
theorem sphere_zero_subset : sphere n d 0 β 0 := fun x => by simp [sphere, funext_iff]
@[simp]
theorem sphere_zero_right (n k : β) : sphere (n + 1) 0 k = β
:= by simp [sphere]
theorem sphere_subset_box : sphere n d k β box n d :=
filter_subset _ _
theorem norm_of_mem_sphere {x : Fin n β β} (hx : x β sphere n d k) :
β(WithLp.equiv 2 _).symm ((β) β x : Fin n β β)β = ββk := by
rw [EuclideanSpace.norm_eq]
dsimp
simp_rw [abs_cast, β cast_pow, β cast_sum, (mem_filter.1 hx).2]
theorem sphere_subset_preimage_metric_sphere : (sphere n d k : Set (Fin n β β)) β
(fun x : Fin n β β => (WithLp.equiv 2 _).symm ((β) β x : Fin n β β)) β»ΒΉ'
Metric.sphere (0 : PiLp 2 fun _ : Fin n => β) (ββk) :=
fun x hx => by rw [Set.mem_preimage, mem_sphere_zero_iff_norm, norm_of_mem_sphere hx]
/-- The map that appears in Behrend's bound on Roth numbers. -/
@[simps]
def map (d : β) : (Fin n β β) β+ β where
toFun a := β i, a i * d ^ (i : β)
map_zero' := by simp_rw [Pi.zero_apply, zero_mul, sum_const_zero]
map_add' a b := by simp_rw [Pi.add_apply, add_mul, sum_add_distrib]
theorem map_zero (d : β) (a : Fin 0 β β) : map d a = 0 := by simp [map]
theorem map_succ (a : Fin (n + 1) β β) :
map d a = a 0 + (β x : Fin n, a x.succ * d ^ (x : β)) * d := by
simp [map, Fin.sum_univ_succ, _root_.pow_succ, β mul_assoc, β sum_mul]
theorem map_succ' (a : Fin (n + 1) β β) : map d a = a 0 + map d (a β Fin.succ) * d :=
map_succ _
theorem map_monotone (d : β) : Monotone (map d : (Fin n β β) β β) := fun x y h => by
dsimp; exact sum_le_sum fun i _ => Nat.mul_le_mul_right _ <| h i
theorem map_mod (a : Fin n.succ β β) : map d a % d = a 0 % d := by
rw [map_succ, Nat.add_mul_mod_self_right]
theorem map_eq_iff {xβ xβ : Fin n.succ β β} (hxβ : β i, xβ i < d) (hxβ : β i, xβ i < d) :
map d xβ = map d xβ β xβ 0 = xβ 0 β§ map d (xβ β Fin.succ) = map d (xβ β Fin.succ) := by
refine β¨fun h => ?_, fun h => by rw [map_succ', map_succ', h.1, h.2]β©
have : xβ 0 = xβ 0 := by
rw [β mod_eq_of_lt (hxβ _), β map_mod, β mod_eq_of_lt (hxβ _), β map_mod, h]
rw [map_succ, map_succ, this, add_right_inj, mul_eq_mul_right_iff] at h
exact β¨this, h.resolve_right (pos_of_gt (hxβ 0)).ne'β©
theorem map_injOn : {x : Fin n β β | β i, x i < d}.InjOn (map d) := by
intro xβ hxβ xβ hxβ h
induction n with
| zero => simp [eq_iff_true_of_subsingleton]
| succ n ih =>
ext i
have x := (map_eq_iff hxβ hxβ).1 h
exact Fin.cases x.1 (congr_fun <| ih (fun _ => hxβ _) (fun _ => hxβ _) x.2) i
theorem map_le_of_mem_box (hx : x β box n d) :
map (2 * d - 1) x β€ β i : Fin n, (d - 1) * (2 * d - 1) ^ (i : β) :=
map_monotone (2 * d - 1) fun _ => Nat.le_sub_one_of_lt <| mem_box.1 hx _
nonrec theorem threeAPFree_sphere : ThreeAPFree (sphere n d k : Set (Fin n β β)) := by
set f : (Fin n β β) β+ EuclideanSpace β (Fin n) :=
{ toFun := fun f => ((β) : β β β) β f
map_zero' := funext fun _ => cast_zero
map_add' := fun _ _ => funext fun _ => cast_add _ _ }
refine ThreeAPFree.of_image (AddMonoidHomClass.isAddFreimanHom f (Set.mapsTo_image _ _))
cast_injective.comp_left.injOn (Set.subset_univ _) ?_
refine (threeAPFree_sphere 0 (ββk)).mono (Set.image_subset_iff.2 fun x => ?_)
rw [Set.mem_preimage, mem_sphere_zero_iff_norm]
exact norm_of_mem_sphere
theorem threeAPFree_image_sphere :
ThreeAPFree ((sphere n d k).image (map (2 * d - 1)) : Set β) := by
rw [coe_image]
apply ThreeAPFree.image' (Ξ± := Fin n β β) (Ξ² := β) (s := sphere n d k) (map (2 * d - 1))
(map_injOn.mono _) threeAPFree_sphere
rw [Set.add_subset_iff]
rintro a ha b hb i
have hai := mem_box.1 (sphere_subset_box ha) i
have hbi := mem_box.1 (sphere_subset_box hb) i
rw [lt_tsub_iff_right, β succ_le_iff, two_mul]
exact (add_add_add_comm _ _ 1 1).trans_le (_root_.add_le_add hai hbi)
theorem sum_sq_le_of_mem_box (hx : x β box n d) : β i : Fin n, x i ^ 2 β€ n * (d - 1) ^ 2 := by
rw [mem_box] at hx
have : β i, x i ^ 2 β€ (d - 1) ^ 2 := fun i =>
Nat.pow_le_pow_left (Nat.le_sub_one_of_lt (hx i)) _
exact (sum_le_card_nsmul univ _ _ fun i _ => this i).trans (by rw [card_fin, smul_eq_mul])
theorem sum_eq : (β i : Fin n, d * (2 * d + 1) ^ (i : β)) = ((2 * d + 1) ^ n - 1) / 2 := by
refine (Nat.div_eq_of_eq_mul_left zero_lt_two ?_).symm
rw [β sum_range fun i => d * (2 * d + 1) ^ (i : β), β mul_sum, mul_right_comm, mul_comm d, β
geom_sum_mul_add, add_tsub_cancel_right, mul_comm]
theorem sum_lt : (β i : Fin n, d * (2 * d + 1) ^ (i : β)) < (2 * d + 1) ^ n :=
sum_eq.trans_lt <| (Nat.div_le_self _ 2).trans_lt <| pred_lt (pow_pos (succ_pos _) _).ne'
theorem card_sphere_le_rothNumberNat (n d k : β) :
#(sphere n d k) β€ rothNumberNat ((2 * d - 1) ^ n) := by
cases n
Β· dsimp; refine (card_le_univ _).trans_eq ?_; rfl
cases d
Β· simp
apply threeAPFree_image_sphere.le_rothNumberNat _ _ (card_image_of_injOn _)
Β· simp only [subset_iff, mem_image, and_imp, forall_exists_index, mem_range,
forall_apply_eq_imp_iffβ, sphere, mem_filter]
rintro _ x hx _ rfl
exact (map_le_of_mem_box hx).trans_lt sum_lt
apply map_injOn.mono fun x => ?_
simp only [mem_coe, sphere, mem_filter, mem_box, and_imp, two_mul]
exact fun h _ i => (h i).trans_le le_self_add
/-!
### Optimization
Now that we know how to turn the integer points of any sphere into a 3AP-free set, we find a
sphere containing many integer points by the pigeonhole principle. This gives us an implicit bound
that we then optimize by tweaking the parameters. The (almost) optimal parameters are
`Behrend.nValue` and `Behrend.dValue`.
-/
theorem exists_large_sphere_aux (n d : β) : β k β range (n * (d - 1) ^ 2 + 1),
(β(d ^ n) / ((n * (d - 1) ^ 2 :) + 1) : β) β€ #(sphere n d k) := by
refine exists_le_card_fiber_of_nsmul_le_card_of_maps_to (fun x hx => ?_) nonempty_range_succ ?_
Β· rw [mem_range, Nat.lt_succ_iff]
exact sum_sq_le_of_mem_box hx
Β· rw [card_range, _root_.nsmul_eq_mul, mul_div_assoc', cast_add_one, mul_div_cancel_leftβ,
card_box]
exact (cast_add_one_pos _).ne'
theorem exists_large_sphere (n d : β) :
β k, ((d ^ n :) / (n * d ^ 2 :) : β) β€ #(sphere n d k) := by
obtain β¨k, -, hkβ© := exists_large_sphere_aux n d
refine β¨k, ?_β©
obtain rfl | hn := n.eq_zero_or_pos
Β· simp
obtain rfl | hd := d.eq_zero_or_pos
Β· simp
refine (div_le_div_of_nonneg_left ?_ ?_ ?_).trans hk
Β· exact cast_nonneg _
Β· exact cast_add_one_pos _
simp only [β le_sub_iff_add_le', cast_mul, β mul_sub, cast_pow, cast_sub hd, sub_sq, one_pow,
cast_one, mul_one, sub_add, sub_sub_self]
apply one_le_mul_of_one_le_of_one_le
Β· rwa [one_le_cast]
rw [_root_.le_sub_iff_add_le]
norm_num
exact one_le_cast.2 hd
theorem bound_aux' (n d : β) : ((d ^ n :) / (n * d ^ 2 :) : β) β€ rothNumberNat ((2 * d - 1) ^ n) :=
let β¨_, hβ© := exists_large_sphere n d
h.trans <| cast_le.2 <| card_sphere_le_rothNumberNat _ _ _
theorem bound_aux (hd : d β 0) (hn : 2 β€ n) :
(d ^ (n - 2 :) / n : β) β€ rothNumberNat ((2 * d - 1) ^ n) := by
convert bound_aux' n d using 1
rw [cast_mul, cast_pow, mul_comm, β div_div, pow_subβ _ _ hn, β div_eq_mul_inv, cast_pow]
rwa [cast_ne_zero]
open scoped Filter Topology
open Real
section NumericalBounds
theorem log_two_mul_two_le_sqrt_log_eight : log 2 * 2 β€ β(log 8) := by
have : (8 : β) = 2 ^ ((3 : β) : β) := by rw [rpow_natCast]; norm_num
rw [this, log_rpow zero_lt_two (3 : β)]
apply le_sqrt_of_sq_le
rw [mul_pow, sq (log 2), mul_assoc, mul_comm]
refine mul_le_mul_of_nonneg_right ?_ (log_nonneg one_le_two)
rw [β le_div_iffβ]
on_goal 1 => apply log_two_lt_d9.le.trans
all_goals norm_num1
theorem two_div_one_sub_two_div_e_le_eight : 2 / (1 - 2 / exp 1) β€ 8 := by
rw [div_le_iffβ, mul_sub, mul_one, mul_div_assoc', le_sub_comm, div_le_iffβ (exp_pos _)]
Β· linarith [exp_one_gt_d9]
rw [sub_pos, div_lt_one] <;> exact exp_one_gt_d9.trans' (by norm_num)
theorem le_sqrt_log (hN : 4096 β€ N) : log (2 / (1 - 2 / exp 1)) * (69 / 50) β€ β(log βN) := by
have : (12 : β) * log 2 β€ log N := by
rw [β log_rpow zero_lt_two, rpow_natCast]
exact log_le_log (by positivity) (mod_cast hN)
refine (mul_le_mul_of_nonneg_right (log_le_log ?_ two_div_one_sub_two_div_e_le_eight) <| by
norm_num1).trans ?_
Β· refine div_pos zero_lt_two ?_
rw [sub_pos, div_lt_one (exp_pos _)]
exact exp_one_gt_d9.trans_le' (by norm_num1)
have l8 : log 8 = (3 : β) * log 2 := by
rw [β log_rpow zero_lt_two, rpow_natCast]
norm_num
rw [l8]
apply le_sqrt_of_sq_le (le_trans _ this)
rw [mul_right_comm, mul_pow, sq (log 2), β mul_assoc]
apply mul_le_mul_of_nonneg_right _ (log_nonneg one_le_two)
rw [β le_div_iffβ']
Β· exact log_two_lt_d9.le.trans (by norm_num1)
exact sq_pos_of_ne_zero (by norm_num1)
theorem exp_neg_two_mul_le {x : β} (hx : 0 < x) : exp (-2 * x) < exp (2 - βxββ) / βxββ := by
have hβ := ceil_lt_add_one hx.le
have hβ : 1 - x β€ 2 - βxββ := by linarith
calc
_ β€ exp (1 - x) / (x + 1) := ?_
_ β€ exp (2 - βxββ) / (x + 1) := by gcongr
_ < _ := by gcongr
rw [le_div_iffβ (add_pos hx zero_lt_one), β le_div_iffβ' (exp_pos _), β exp_sub, neg_mul,
sub_neg_eq_add, two_mul, sub_add_add_cancel, add_comm _ x]
exact le_trans (le_add_of_nonneg_right zero_le_one) (add_one_le_exp _)
theorem div_lt_floor {x : β} (hx : 2 / (1 - 2 / exp 1) β€ x) : x / exp 1 < (βx / 2ββ : β) := by
apply lt_of_le_of_lt _ (sub_one_lt_floor _)
have : 0 < 1 - 2 / exp 1 := by
rw [sub_pos, div_lt_one (exp_pos _)]
exact lt_of_le_of_lt (by norm_num) exp_one_gt_d9
rwa [le_sub_comm, div_eq_mul_one_div x, div_eq_mul_one_div x, β mul_sub, div_sub', β
div_eq_mul_one_div, mul_div_assoc', one_le_div, β div_le_iffβ this]
Β· exact zero_lt_two
Β· exact two_ne_zero
theorem ceil_lt_mul {x : β} (hx : 50 / 19 β€ x) : (βxββ : β) < 1.38 * x := by
refine (ceil_lt_add_one <| hx.trans' <| by norm_num).trans_le ?_
rw [β le_sub_iff_add_le', β sub_one_mul]
have : (1.38 : β) = 69 / 50 := by norm_num
rwa [this, show (69 / 50 - 1 : β) = (50 / 19)β»ΒΉ by norm_num1, β
div_eq_inv_mul, one_le_div]
norm_num1
end NumericalBounds
/-- The (almost) optimal value of `n` in `Behrend.bound_aux`. -/
noncomputable def nValue (N : β) : β :=
ββ(log N)ββ
/-- The (almost) optimal value of `d` in `Behrend.bound_aux`. -/
noncomputable def dValue (N : β) : β := β(N : β) ^ (nValue N : β)β»ΒΉ / 2ββ
theorem nValue_pos (hN : 2 β€ N) : 0 < nValue N :=
ceil_pos.2 <| Real.sqrt_pos.2 <| log_pos <| one_lt_cast.2 <| hN
theorem three_le_nValue (hN : 64 β€ N) : 3 β€ nValue N := by
rw [nValue, β lt_iff_add_one_le, lt_ceil, cast_two]
apply lt_sqrt_of_sq_lt
have : (2 : β) ^ ((6 : β) : β) β€ N := by
rw [rpow_natCast]
exact (cast_le.2 hN).trans' (by norm_num1)
apply lt_of_lt_of_le _ (log_le_log (rpow_pos_of_pos zero_lt_two _) this)
rw [log_rpow zero_lt_two, β div_lt_iffβ']
Β· exact log_two_gt_d9.trans_le' (by norm_num1)
Β· norm_num1
theorem dValue_pos (hNβ : 8 β€ N) : 0 < dValue N := by
have hNβ : 0 < (N : β) := cast_pos.2 (succ_pos'.trans_le hNβ)
rw [dValue, floor_pos, β log_le_log_iff zero_lt_one, log_one, log_div _ two_ne_zero, log_rpow hNβ,
inv_mul_eq_div, sub_nonneg, le_div_iffβ]
Β· have : (nValue N : β) β€ 2 * β(log N) := by
apply (ceil_lt_add_one <| sqrt_nonneg _).le.trans
rw [two_mul, add_le_add_iff_left]
apply le_sqrt_of_sq_le
rw [one_pow, le_log_iff_exp_le hNβ]
exact (exp_one_lt_d9.le.trans <| by norm_num).trans (cast_le.2 hNβ)
apply (mul_le_mul_of_nonneg_left this <| log_nonneg one_le_two).trans _
rw [β mul_assoc, β le_div_iffβ (Real.sqrt_pos.2 <| log_pos <| one_lt_cast.2 _), div_sqrt]
Β· apply log_two_mul_two_le_sqrt_log_eight.trans
apply Real.sqrt_le_sqrt
exact log_le_log (by norm_num) (mod_cast hNβ)
exact hNβ.trans_lt' (by norm_num)
Β· exact cast_pos.2 (nValue_pos <| hNβ.trans' <| by norm_num)
Β· exact (rpow_pos_of_pos hNβ _).ne'
Β· exact div_pos (rpow_pos_of_pos hNβ _) zero_lt_two
theorem le_N (hN : 2 β€ N) : (2 * dValue N - 1) ^ nValue N β€ N := by
have : (2 * dValue N - 1) ^ nValue N β€ (2 * dValue N) ^ nValue N :=
Nat.pow_le_pow_left (Nat.sub_le _ _) _
apply this.trans
suffices ((2 * dValue N) ^ nValue N : β) β€ N from mod_cast this
suffices i : (2 * dValue N : β) β€ (N : β) ^ (nValue N : β)β»ΒΉ by
rw [β rpow_natCast]
apply (rpow_le_rpow (mul_nonneg zero_le_two (cast_nonneg _)) i (cast_nonneg _)).trans
rw [β rpow_mul (cast_nonneg _), inv_mul_cancelβ, rpow_one]
rw [cast_ne_zero]
apply (nValue_pos hN).ne'
rw [β le_div_iffβ']
Β· exact floor_le (div_nonneg (rpow_nonneg (cast_nonneg _) _) zero_le_two)
apply zero_lt_two
theorem bound (hN : 4096 β€ N) : (N : β) ^ (nValue N : β)β»ΒΉ / exp 1 < dValue N := by
apply div_lt_floor _
| rw [β log_le_log_iff, log_rpow, mul_comm, β div_eq_mul_inv]
Β· apply le_trans _ (div_le_div_of_nonneg_left _ _ (ceil_lt_mul _).le)
Β· rw [mul_comm, β div_div, div_sqrt, le_div_iffβ]
Β· norm_num; exact le_sqrt_log hN
Β· norm_num1
Β· apply log_nonneg
rw [one_le_cast]
exact hN.trans' (by norm_num1)
Β· rw [cast_pos, lt_ceil, cast_zero, Real.sqrt_pos]
refine log_pos ?_
| Mathlib/Combinatorics/Additive/AP/Three/Behrend.lean | 400 | 409 |
/-
Copyright (c) 2020 FrΓ©dΓ©ric Dupuis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: FrΓ©dΓ©ric Dupuis
-/
import Mathlib.Algebra.Algebra.Field
import Mathlib.Algebra.BigOperators.Balance
import Mathlib.Algebra.Order.BigOperators.Expect
import Mathlib.Algebra.Order.Star.Basic
import Mathlib.Analysis.CStarAlgebra.Basic
import Mathlib.Analysis.Normed.Operator.ContinuousLinearMap
import Mathlib.Data.Real.Sqrt
import Mathlib.LinearAlgebra.Basis.VectorSpace
/-!
# `RCLike`: a typeclass for β or β
This file defines the typeclass `RCLike` intended to have only two instances:
β and β. It is meant for definitions and theorems which hold for both the real and the complex case,
and in particular when the real case follows directly from the complex case by setting `re` to `id`,
`im` to zero and so on. Its API follows closely that of β.
Applications include defining inner products and Hilbert spaces for both the real and
complex case. One typically produces the definitions and proof for an arbitrary field of this
typeclass, which basically amounts to doing the complex case, and the two cases then fall out
immediately from the two instances of the class.
The instance for `β` is registered in this file.
The instance for `β` is declared in `Mathlib/Analysis/Complex/Basic.lean`.
## Implementation notes
The coercion from reals into an `RCLike` field is done by registering `RCLike.ofReal` as
a `CoeTC`. For this to work, we must proceed carefully to avoid problems involving circular
coercions in the case `K=β`; in particular, we cannot use the plain `Coe` and must set
priorities carefully. This problem was already solved for `β`, and we copy the solution detailed
in `Mathlib/Data/Nat/Cast/Defs.lean`. See also Note [coercion into rings] for more details.
In addition, several lemmas need to be set at priority 900 to make sure that they do not override
their counterparts in `Mathlib/Analysis/Complex/Basic.lean` (which causes linter errors).
A few lemmas requiring heavier imports are in `Mathlib/Analysis/RCLike/Lemmas.lean`.
-/
open Fintype
open scoped BigOperators ComplexConjugate
section
local notation "π" => algebraMap β _
/--
This typeclass captures properties shared by β and β, with an API that closely matches that of β.
-/
class RCLike (K : semiOutParam Type*) extends DenselyNormedField K, StarRing K,
NormedAlgebra β K, CompleteSpace K where
/-- The real part as an additive monoid homomorphism -/
re : K β+ β
/-- The imaginary part as an additive monoid homomorphism -/
im : K β+ β
/-- Imaginary unit in `K`. Meant to be set to `0` for `K = β`. -/
I : K
I_re_ax : re I = 0
I_mul_I_ax : I = 0 β¨ I * I = -1
re_add_im_ax : β z : K, π (re z) + π (im z) * I = z
ofReal_re_ax : β r : β, re (π r) = r
ofReal_im_ax : β r : β, im (π r) = 0
mul_re_ax : β z w : K, re (z * w) = re z * re w - im z * im w
mul_im_ax : β z w : K, im (z * w) = re z * im w + im z * re w
conj_re_ax : β z : K, re (conj z) = re z
conj_im_ax : β z : K, im (conj z) = -im z
conj_I_ax : conj I = -I
norm_sq_eq_def_ax : β z : K, βzβ ^ 2 = re z * re z + im z * im z
mul_im_I_ax : β z : K, im z * im I = im z
/-- only an instance in the `ComplexOrder` locale -/
[toPartialOrder : PartialOrder K]
le_iff_re_im {z w : K} : z β€ w β re z β€ re w β§ im z = im w
-- note we cannot put this in the `extends` clause
[toDecidableEq : DecidableEq K]
scoped[ComplexOrder] attribute [instance 100] RCLike.toPartialOrder
attribute [instance 100] RCLike.toDecidableEq
end
variable {K E : Type*} [RCLike K]
namespace RCLike
/-- Coercion from `β` to an `RCLike` field. -/
@[coe] abbrev ofReal : β β K := Algebra.cast
/- The priority must be set at 900 to ensure that coercions are tried in the right order.
See Note [coercion into rings], or `Mathlib/Data/Nat/Cast/Basic.lean` for more details. -/
noncomputable instance (priority := 900) algebraMapCoe : CoeTC β K :=
β¨ofRealβ©
theorem ofReal_alg (x : β) : (x : K) = x β’ (1 : K) :=
Algebra.algebraMap_eq_smul_one x
theorem real_smul_eq_coe_mul (r : β) (z : K) : r β’ z = (r : K) * z :=
Algebra.smul_def r z
theorem real_smul_eq_coe_smul [AddCommGroup E] [Module K E] [Module β E] [IsScalarTower β K E]
(r : β) (x : E) : r β’ x = (r : K) β’ x := by rw [RCLike.ofReal_alg, smul_one_smul]
theorem algebraMap_eq_ofReal : β(algebraMap β K) = ofReal :=
rfl
@[simp, rclike_simps]
theorem re_add_im (z : K) : (re z : K) + im z * I = z :=
RCLike.re_add_im_ax z
@[simp, norm_cast, rclike_simps]
theorem ofReal_re : β r : β, re (r : K) = r :=
RCLike.ofReal_re_ax
@[simp, norm_cast, rclike_simps]
theorem ofReal_im : β r : β, im (r : K) = 0 :=
RCLike.ofReal_im_ax
@[simp, rclike_simps]
theorem mul_re : β z w : K, re (z * w) = re z * re w - im z * im w :=
RCLike.mul_re_ax
@[simp, rclike_simps]
theorem mul_im : β z w : K, im (z * w) = re z * im w + im z * re w :=
RCLike.mul_im_ax
theorem ext_iff {z w : K} : z = w β re z = re w β§ im z = im w :=
β¨fun h => h βΈ β¨rfl, rflβ©, fun β¨hβ, hββ© => re_add_im z βΈ re_add_im w βΈ hβ βΈ hβ βΈ rflβ©
theorem ext {z w : K} (hre : re z = re w) (him : im z = im w) : z = w :=
ext_iff.2 β¨hre, himβ©
@[norm_cast]
theorem ofReal_zero : ((0 : β) : K) = 0 :=
algebraMap.coe_zero
@[rclike_simps]
theorem zero_re' : re (0 : K) = (0 : β) :=
map_zero re
@[norm_cast]
theorem ofReal_one : ((1 : β) : K) = 1 :=
map_one (algebraMap β K)
@[simp, rclike_simps]
theorem one_re : re (1 : K) = 1 := by rw [β ofReal_one, ofReal_re]
@[simp, rclike_simps]
theorem one_im : im (1 : K) = 0 := by rw [β ofReal_one, ofReal_im]
theorem ofReal_injective : Function.Injective ((β) : β β K) :=
(algebraMap β K).injective
@[norm_cast]
theorem ofReal_inj {z w : β} : (z : K) = (w : K) β z = w :=
algebraMap.coe_inj
-- replaced by `RCLike.ofNat_re`
-- replaced by `RCLike.ofNat_im`
theorem ofReal_eq_zero {x : β} : (x : K) = 0 β x = 0 :=
algebraMap.lift_map_eq_zero_iff x
theorem ofReal_ne_zero {x : β} : (x : K) β 0 β x β 0 :=
ofReal_eq_zero.not
@[rclike_simps, norm_cast]
theorem ofReal_add (r s : β) : ((r + s : β) : K) = r + s :=
algebraMap.coe_add _ _
-- replaced by `RCLike.ofReal_ofNat`
@[rclike_simps, norm_cast]
theorem ofReal_neg (r : β) : ((-r : β) : K) = -r :=
algebraMap.coe_neg r
@[rclike_simps, norm_cast]
theorem ofReal_sub (r s : β) : ((r - s : β) : K) = r - s :=
map_sub (algebraMap β K) r s
@[rclike_simps, norm_cast]
theorem ofReal_sum {Ξ± : Type*} (s : Finset Ξ±) (f : Ξ± β β) :
((β i β s, f i : β) : K) = β i β s, (f i : K) :=
map_sum (algebraMap β K) _ _
@[simp, rclike_simps, norm_cast]
theorem ofReal_finsupp_sum {Ξ± M : Type*} [Zero M] (f : Ξ± ββ M) (g : Ξ± β M β β) :
((f.sum fun a b => g a b : β) : K) = f.sum fun a b => (g a b : K) :=
map_finsuppSum (algebraMap β K) f g
@[rclike_simps, norm_cast]
theorem ofReal_mul (r s : β) : ((r * s : β) : K) = r * s :=
algebraMap.coe_mul _ _
@[rclike_simps, norm_cast]
theorem ofReal_pow (r : β) (n : β) : ((r ^ n : β) : K) = (r : K) ^ n :=
map_pow (algebraMap β K) r n
@[rclike_simps, norm_cast]
theorem ofReal_prod {Ξ± : Type*} (s : Finset Ξ±) (f : Ξ± β β) :
((β i β s, f i : β) : K) = β i β s, (f i : K) :=
map_prod (algebraMap β K) _ _
@[simp, rclike_simps, norm_cast]
theorem ofReal_finsuppProd {Ξ± M : Type*} [Zero M] (f : Ξ± ββ M) (g : Ξ± β M β β) :
((f.prod fun a b => g a b : β) : K) = f.prod fun a b => (g a b : K) :=
map_finsuppProd _ f g
@[deprecated (since := "2025-04-06")] alias ofReal_finsupp_prod := ofReal_finsuppProd
@[simp, norm_cast, rclike_simps]
theorem real_smul_ofReal (r x : β) : r β’ (x : K) = (r : K) * (x : K) :=
real_smul_eq_coe_mul _ _
@[rclike_simps]
theorem re_ofReal_mul (r : β) (z : K) : re (βr * z) = r * re z := by
simp only [mul_re, ofReal_im, zero_mul, ofReal_re, sub_zero]
@[rclike_simps]
theorem im_ofReal_mul (r : β) (z : K) : im (βr * z) = r * im z := by
simp only [add_zero, ofReal_im, zero_mul, ofReal_re, mul_im]
@[rclike_simps]
theorem smul_re (r : β) (z : K) : re (r β’ z) = r * re z := by
rw [real_smul_eq_coe_mul, re_ofReal_mul]
@[rclike_simps]
theorem smul_im (r : β) (z : K) : im (r β’ z) = r * im z := by
rw [real_smul_eq_coe_mul, im_ofReal_mul]
@[rclike_simps, norm_cast]
theorem norm_ofReal (r : β) : β(r : K)β = |r| :=
norm_algebraMap' K r
/-! ### Characteristic zero -/
-- see Note [lower instance priority]
/-- β and β are both of characteristic zero. -/
instance (priority := 100) charZero_rclike : CharZero K :=
(RingHom.charZero_iff (algebraMap β K).injective).1 inferInstance
@[rclike_simps, norm_cast]
lemma ofReal_expect {Ξ± : Type*} (s : Finset Ξ±) (f : Ξ± β β) : πΌ i β s, f i = πΌ i β s, (f i : K) :=
map_expect (algebraMap ..) ..
@[norm_cast]
lemma ofReal_balance {ΞΉ : Type*} [Fintype ΞΉ] (f : ΞΉ β β) (i : ΞΉ) :
((balance f i : β) : K) = balance ((β) β f) i := map_balance (algebraMap ..) ..
@[simp] lemma ofReal_comp_balance {ΞΉ : Type*} [Fintype ΞΉ] (f : ΞΉ β β) :
ofReal β balance f = balance (ofReal β f : ΞΉ β K) := funext <| ofReal_balance _
/-! ### The imaginary unit, `I` -/
/-- The imaginary unit. -/
@[simp, rclike_simps]
theorem I_re : re (I : K) = 0 :=
I_re_ax
@[simp, rclike_simps]
theorem I_im (z : K) : im z * im (I : K) = im z :=
mul_im_I_ax z
@[simp, rclike_simps]
theorem I_im' (z : K) : im (I : K) * im z = im z := by rw [mul_comm, I_im]
@[rclike_simps] -- Porting note (https://github.com/leanprover-community/mathlib4/issues/11119): was `simp`
theorem I_mul_re (z : K) : re (I * z) = -im z := by
simp only [I_re, zero_sub, I_im', zero_mul, mul_re]
theorem I_mul_I : (I : K) = 0 β¨ (I : K) * I = -1 :=
I_mul_I_ax
variable (π) in
lemma I_eq_zero_or_im_I_eq_one : (I : K) = 0 β¨ im (I : K) = 1 :=
I_mul_I (K := K) |>.imp_right fun h β¦ by simpa [h] using (I_mul_re (I : K)).symm
@[simp, rclike_simps]
theorem conj_re (z : K) : re (conj z) = re z :=
RCLike.conj_re_ax z
@[simp, rclike_simps]
theorem conj_im (z : K) : im (conj z) = -im z :=
RCLike.conj_im_ax z
@[simp, rclike_simps]
theorem conj_I : conj (I : K) = -I :=
RCLike.conj_I_ax
@[simp, rclike_simps]
theorem conj_ofReal (r : β) : conj (r : K) = (r : K) := by
rw [ext_iff]
simp only [ofReal_im, conj_im, eq_self_iff_true, conj_re, and_self_iff, neg_zero]
-- replaced by `RCLike.conj_ofNat`
theorem conj_nat_cast (n : β) : conj (n : K) = n := map_natCast _ _
theorem conj_ofNat (n : β) [n.AtLeastTwo] : conj (ofNat(n) : K) = ofNat(n) :=
map_ofNat _ _
@[rclike_simps, simp]
theorem conj_neg_I : conj (-I) = (I : K) := by rw [map_neg, conj_I, neg_neg]
theorem conj_eq_re_sub_im (z : K) : conj z = re z - im z * I :=
(congr_arg conj (re_add_im z).symm).trans <| by
rw [map_add, map_mul, conj_I, conj_ofReal, conj_ofReal, mul_neg, sub_eq_add_neg]
theorem sub_conj (z : K) : z - conj z = 2 * im z * I :=
calc
z - conj z = re z + im z * I - (re z - im z * I) := by rw [re_add_im, β conj_eq_re_sub_im]
_ = 2 * im z * I := by rw [add_sub_sub_cancel, β two_mul, mul_assoc]
@[rclike_simps]
theorem conj_smul (r : β) (z : K) : conj (r β’ z) = r β’ conj z := by
rw [conj_eq_re_sub_im, conj_eq_re_sub_im, smul_re, smul_im, ofReal_mul, ofReal_mul,
real_smul_eq_coe_mul r (_ - _), mul_sub, mul_assoc]
theorem add_conj (z : K) : z + conj z = 2 * re z :=
calc
z + conj z = re z + im z * I + (re z - im z * I) := by rw [re_add_im, conj_eq_re_sub_im]
_ = 2 * re z := by rw [add_add_sub_cancel, two_mul]
theorem re_eq_add_conj (z : K) : β(re z) = (z + conj z) / 2 := by
rw [add_conj, mul_div_cancel_leftβ (re z : K) two_ne_zero]
theorem im_eq_conj_sub (z : K) : β(im z) = I * (conj z - z) / 2 := by
rw [β neg_inj, β ofReal_neg, β I_mul_re, re_eq_add_conj, map_mul, conj_I, β neg_div, β mul_neg,
neg_sub, mul_sub, neg_mul, sub_eq_add_neg]
open List in
/-- There are several equivalent ways to say that a number `z` is in fact a real number. -/
theorem is_real_TFAE (z : K) : TFAE [conj z = z, β r : β, (r : K) = z, β(re z) = z, im z = 0] := by
tfae_have 1 β 4
| h => by
rw [β @ofReal_inj K, im_eq_conj_sub, h, sub_self, mul_zero, zero_div,
ofReal_zero]
tfae_have 4 β 3
| h => by
conv_rhs => rw [β re_add_im z, h, ofReal_zero, zero_mul, add_zero]
tfae_have 3 β 2 := fun h => β¨_, hβ©
tfae_have 2 β 1 := fun β¨r, hrβ© => hr βΈ conj_ofReal _
tfae_finish
theorem conj_eq_iff_real {z : K} : conj z = z β β r : β, z = (r : K) :=
calc
_ β β r : β, (r : K) = z := (is_real_TFAE z).out 0 1
_ β _ := by simp only [eq_comm]
theorem conj_eq_iff_re {z : K} : conj z = z β (re z : K) = z :=
(is_real_TFAE z).out 0 2
theorem conj_eq_iff_im {z : K} : conj z = z β im z = 0 :=
(is_real_TFAE z).out 0 3
@[simp]
theorem star_def : (Star.star : K β K) = conj :=
rfl
variable (K)
/-- Conjugation as a ring equivalence. This is used to convert the inner product into a
sesquilinear product. -/
abbrev conjToRingEquiv : K β+* Kα΅α΅α΅ :=
starRingEquiv
variable {K} {z : K}
/-- The norm squared function. -/
def normSq : K β*β β where
toFun z := re z * re z + im z * im z
map_zero' := by simp only [add_zero, mul_zero, map_zero]
map_one' := by simp only [one_im, add_zero, mul_one, one_re, mul_zero]
map_mul' z w := by
simp only [mul_im, mul_re]
ring
theorem normSq_apply (z : K) : normSq z = re z * re z + im z * im z :=
rfl
theorem norm_sq_eq_def {z : K} : βzβ ^ 2 = re z * re z + im z * im z :=
norm_sq_eq_def_ax z
theorem normSq_eq_def' (z : K) : normSq z = βzβ ^ 2 :=
norm_sq_eq_def.symm
@[rclike_simps]
theorem normSq_zero : normSq (0 : K) = 0 :=
normSq.map_zero
@[rclike_simps]
theorem normSq_one : normSq (1 : K) = 1 :=
normSq.map_one
theorem normSq_nonneg (z : K) : 0 β€ normSq z :=
add_nonneg (mul_self_nonneg _) (mul_self_nonneg _)
@[rclike_simps] -- Porting note (https://github.com/leanprover-community/mathlib4/issues/11119): was `simp`
theorem normSq_eq_zero {z : K} : normSq z = 0 β z = 0 :=
map_eq_zero _
@[simp, rclike_simps]
theorem normSq_pos {z : K} : 0 < normSq z β z β 0 := by
rw [lt_iff_le_and_ne, Ne, eq_comm]; simp [normSq_nonneg]
@[simp, rclike_simps]
theorem normSq_neg (z : K) : normSq (-z) = normSq z := by simp only [normSq_eq_def', norm_neg]
@[simp, rclike_simps]
theorem normSq_conj (z : K) : normSq (conj z) = normSq z := by
simp only [normSq_apply, neg_mul, mul_neg, neg_neg, rclike_simps]
@[rclike_simps] -- Porting note (https://github.com/leanprover-community/mathlib4/issues/11119): was `simp`
theorem normSq_mul (z w : K) : normSq (z * w) = normSq z * normSq w :=
map_mul _ z w
theorem normSq_add (z w : K) : normSq (z + w) = normSq z + normSq w + 2 * re (z * conj w) := by
simp only [normSq_apply, map_add, rclike_simps]
ring
theorem re_sq_le_normSq (z : K) : re z * re z β€ normSq z :=
le_add_of_nonneg_right (mul_self_nonneg _)
theorem im_sq_le_normSq (z : K) : im z * im z β€ normSq z :=
le_add_of_nonneg_left (mul_self_nonneg _)
theorem mul_conj (z : K) : z * conj z = βzβ ^ 2 := by
apply ext <;> simp [β ofReal_pow, norm_sq_eq_def, mul_comm]
theorem conj_mul (z : K) : conj z * z = βzβ ^ 2 := by rw [mul_comm, mul_conj]
lemma inv_eq_conj (hz : βzβ = 1) : zβ»ΒΉ = conj z :=
inv_eq_of_mul_eq_one_left <| by simp_rw [conj_mul, hz, algebraMap.coe_one, one_pow]
theorem normSq_sub (z w : K) : normSq (z - w) = normSq z + normSq w - 2 * re (z * conj w) := by
simp only [normSq_add, sub_eq_add_neg, map_neg, mul_neg, normSq_neg, map_neg]
theorem sqrt_normSq_eq_norm {z : K} : β(normSq z) = βzβ := by
rw [normSq_eq_def', Real.sqrt_sq (norm_nonneg _)]
/-! ### Inversion -/
@[rclike_simps, norm_cast]
theorem ofReal_inv (r : β) : ((rβ»ΒΉ : β) : K) = (r : K)β»ΒΉ :=
map_invβ _ r
theorem inv_def (z : K) : zβ»ΒΉ = conj z * ((βzβ ^ 2)β»ΒΉ : β) := by
rcases eq_or_ne z 0 with (rfl | hβ)
Β· simp
Β· apply inv_eq_of_mul_eq_one_right
rw [β mul_assoc, mul_conj, ofReal_inv, ofReal_pow, mul_inv_cancelβ]
simpa
@[simp, rclike_simps]
theorem inv_re (z : K) : re zβ»ΒΉ = re z / normSq z := by
rw [inv_def, normSq_eq_def', mul_comm, re_ofReal_mul, conj_re, div_eq_inv_mul]
@[simp, rclike_simps]
theorem inv_im (z : K) : im zβ»ΒΉ = -im z / normSq z := by
rw [inv_def, normSq_eq_def', mul_comm, im_ofReal_mul, conj_im, div_eq_inv_mul]
theorem div_re (z w : K) : re (z / w) = re z * re w / normSq w + im z * im w / normSq w := by
simp only [div_eq_mul_inv, mul_assoc, sub_eq_add_neg, neg_mul, mul_neg, neg_neg, map_neg,
rclike_simps]
theorem div_im (z w : K) : im (z / w) = im z * re w / normSq w - re z * im w / normSq w := by
simp only [div_eq_mul_inv, mul_assoc, sub_eq_add_neg, add_comm, neg_mul, mul_neg, map_neg,
rclike_simps]
@[rclike_simps] -- Porting note (https://github.com/leanprover-community/mathlib4/issues/11119): was `simp`
theorem conj_inv (x : K) : conj xβ»ΒΉ = (conj x)β»ΒΉ :=
star_invβ _
lemma conj_div (x y : K) : conj (x / y) = conj x / conj y := map_div' conj conj_inv _ _
--TODO: Do we rather want the map as an explicit definition?
lemma exists_norm_eq_mul_self (x : K) : β c, βcβ = 1 β§ ββxβ = c * x := by
obtain rfl | hx := eq_or_ne x 0
Β· exact β¨1, by simpβ©
Β· exact β¨βxβ / x, by simp [norm_ne_zero_iff.2, hx]β©
lemma exists_norm_mul_eq_self (x : K) : β c, βcβ = 1 β§ c * βxβ = x := by
obtain rfl | hx := eq_or_ne x 0
Β· exact β¨1, by simpβ©
Β· exact β¨x / βxβ, by simp [norm_ne_zero_iff.2, hx]β©
@[rclike_simps, norm_cast]
theorem ofReal_div (r s : β) : ((r / s : β) : K) = r / s :=
map_divβ (algebraMap β K) r s
theorem div_re_ofReal {z : K} {r : β} : re (z / r) = re z / r := by
rw [div_eq_inv_mul, div_eq_inv_mul, β ofReal_inv, re_ofReal_mul]
@[rclike_simps, norm_cast]
theorem ofReal_zpow (r : β) (n : β€) : ((r ^ n : β) : K) = (r : K) ^ n :=
map_zpowβ (algebraMap β K) r n
theorem I_mul_I_of_nonzero : (I : K) β 0 β (I : K) * I = -1 :=
I_mul_I_ax.resolve_left
@[simp, rclike_simps]
theorem inv_I : (I : K)β»ΒΉ = -I := by
by_cases h : (I : K) = 0
Β· simp [h]
Β· field_simp [I_mul_I_of_nonzero h]
@[simp, rclike_simps]
theorem div_I (z : K) : z / I = -(z * I) := by rw [div_eq_mul_inv, inv_I, mul_neg]
| Mathlib/Analysis/RCLike/Basic.lean | 512 | 512 | |
/-
Copyright (c) 2023 David Loeffler. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Loeffler
-/
import Mathlib.Analysis.Calculus.SmoothSeries
import Mathlib.Analysis.NormedSpace.OperatorNorm.Prod
import Mathlib.Analysis.SpecialFunctions.Gaussian.PoissonSummation
import Mathlib.Data.Complex.FiniteDimensional
/-!
# The two-variable Jacobi theta function
This file defines the two-variable Jacobi theta function
$$\theta(z, \tau) = \sum_{n \in \mathbb{Z}} \exp (2 i \pi n z + i \pi n ^ 2 \tau),$$
and proves the functional equation relating the values at `(z, Ο)` and `(z / Ο, -1 / Ο)`,
using Poisson's summation formula. We also show holomorphy (jointly in both variables).
Additionally, we show some analogous results about the derivative (in the `z`-variable)
$$\theta'(z, Ο) = \sum_{n \in \mathbb{Z}} 2 \pi i n \exp (2 i \pi n z + i \pi n ^ 2 \tau).$$
(Note that the Mellin transform of `ΞΈ` will give us functional equations for `L`-functions
of even Dirichlet characters, and that of `ΞΈ'` will do the same for odd Dirichlet characters.)
-/
open Complex Real Asymptotics Filter Topology
open scoped ComplexConjugate
noncomputable section
section term_defs
/-!
## Definitions of the summands
-/
/-- Summand in the series for the Jacobi theta function. -/
def jacobiThetaβ_term (n : β€) (z Ο : β) : β := cexp (2 * Ο * I * n * z + Ο * I * n ^ 2 * Ο)
/-- Summand in the series for the FrΓ©chet derivative of the Jacobi theta function. -/
def jacobiThetaβ_term_fderiv (n : β€) (z Ο : β) : β Γ β βL[β] β :=
cexp (2 * Ο * I * n * z + Ο * I * n ^ 2 * Ο) β’
((2 * Ο * I * n) β’ (ContinuousLinearMap.fst β β β) +
(Ο * I * n ^ 2) β’ (ContinuousLinearMap.snd β β β))
lemma hasFDerivAt_jacobiThetaβ_term (n : β€) (z Ο : β) :
HasFDerivAt (fun p : β Γ β β¦ jacobiThetaβ_term n p.1 p.2)
(jacobiThetaβ_term_fderiv n z Ο) (z, Ο) := by
let f : β Γ β β β := fun p β¦ 2 * Ο * I * n * p.1 + Ο * I * n ^ 2 * p.2
suffices HasFDerivAt f ((2 * Ο * I * n) β’ (ContinuousLinearMap.fst β β β)
+ (Ο * I * n ^ 2) β’ (ContinuousLinearMap.snd β β β)) (z, Ο) from this.cexp
exact (hasFDerivAt_fst.const_mul _).add (hasFDerivAt_snd.const_mul _)
/-- Summand in the series for the `z`-derivative of the Jacobi theta function. -/
def jacobiThetaβ'_term (n : β€) (z Ο : β) := 2 * Ο * I * n * jacobiThetaβ_term n z Ο
end term_defs
section term_bounds
/-!
## Bounds for the summands
We show that the sums of the three functions `jacobiThetaβ_term`, `jacobiThetaβ'_term` and
`jacobiThetaβ_term_fderiv` are locally uniformly convergent in the domain `0 < im Ο`, and diverge
everywhere else.
-/
lemma norm_jacobiThetaβ_term (n : β€) (z Ο : β) :
βjacobiThetaβ_term n z Οβ = rexp (-Ο * n ^ 2 * Ο.im - 2 * Ο * n * z.im) := by
rw [jacobiThetaβ_term, Complex.norm_exp, (by push_cast; ring :
(2 * Ο : β) * I * n * z + Ο * I * n ^ 2 * Ο = (Ο * (2 * n):) * z * I + (Ο * n ^ 2 :) * Ο * I),
add_re, mul_I_re, im_ofReal_mul, mul_I_re, im_ofReal_mul]
ring_nf
/-- A uniform upper bound for `jacobiThetaβ_term` on compact subsets. -/
lemma norm_jacobiThetaβ_term_le {S T : β} (hT : 0 < T) {z Ο : β}
(hz : |im z| β€ S) (hΟ : T β€ im Ο) (n : β€) :
βjacobiThetaβ_term n z Οβ β€ rexp (-Ο * (T * n ^ 2 - 2 * S * |n|)) := by
simp_rw [norm_jacobiThetaβ_term, Real.exp_le_exp, sub_eq_add_neg, neg_mul, β neg_add,
neg_le_neg_iff, mul_comm (2 : β), mul_assoc Ο, β mul_add, mul_le_mul_left pi_pos,
mul_comm T, mul_comm S]
refine add_le_add (mul_le_mul le_rfl hΟ hT.le (sq_nonneg _)) ?_
rw [β mul_neg, mul_assoc, mul_assoc, mul_le_mul_left two_pos, mul_comm, neg_mul, β mul_neg]
refine le_trans ?_ (neg_abs_le _)
rw [mul_neg, neg_le_neg_iff, abs_mul, Int.cast_abs]
exact mul_le_mul_of_nonneg_left hz (abs_nonneg _)
/-- A uniform upper bound for `jacobiThetaβ'_term` on compact subsets. -/
lemma norm_jacobiThetaβ'_term_le {S T : β} (hT : 0 < T) {z Ο : β}
(hz : |im z| β€ S) (hΟ : T β€ im Ο) (n : β€) :
βjacobiThetaβ'_term n z Οβ β€ 2 * Ο * |n| * rexp (-Ο * (T * n ^ 2 - 2 * S * |n|)) := by
rw [jacobiThetaβ'_term, norm_mul]
refine mul_le_mul (le_of_eq ?_) (norm_jacobiThetaβ_term_le hT hz hΟ n)
(norm_nonneg _) (by positivity)
simp only [norm_mul, Complex.norm_two, norm_I, Complex.norm_of_nonneg pi_pos.le,
norm_intCast, mul_one, Int.cast_abs]
/-- The uniform bound we have given is summable, and remains so after multiplying by any fixed
power of `|n|` (we shall need this for `k = 0, 1, 2`). -/
lemma summable_pow_mul_jacobiThetaβ_term_bound (S : β) {T : β} (hT : 0 < T) (k : β) :
Summable (fun n : β€ β¦ (|n| ^ k : β) * Real.exp (-Ο * (T * n ^ 2 - 2 * S * |n|))) := by
suffices Summable (fun n : β β¦ (n ^ k : β) * Real.exp (-Ο * (T * n ^ 2 - 2 * S * n))) by
apply Summable.of_nat_of_neg <;>
simpa only [Int.cast_neg, neg_sq, abs_neg, Int.cast_natCast, Nat.abs_cast]
apply summable_of_isBigO_nat (summable_pow_mul_exp_neg_nat_mul k zero_lt_one)
apply IsBigO.mul (isBigO_refl _ _)
refine Real.isBigO_exp_comp_exp_comp.mpr (Tendsto.isBoundedUnder_le_atBot ?_)
simp_rw [β tendsto_neg_atTop_iff, Pi.sub_apply]
conv =>
enter [1, n]
rw [show -(-Ο * (T * n ^ 2 - 2 * S * n) - -1 * n) = n * (Ο * T * n - (2 * Ο * S + 1)) by ring]
refine tendsto_natCast_atTop_atTop.atTop_mul_atTopβ (tendsto_atTop_add_const_right _ _ ?_)
exact tendsto_natCast_atTop_atTop.const_mul_atTop (mul_pos pi_pos hT)
/-- The series defining the theta function is summable if and only if `0 < im Ο`. -/
lemma summable_jacobiThetaβ_term_iff (z Ο : β) : Summable (jacobiThetaβ_term Β· z Ο) β 0 < im Ο := by
-- NB. This is a statement of no great mathematical interest; it is included largely to avoid
-- having to impose `0 < im Ο` as a hypothesis on many later lemmas.
refine Iff.symm β¨fun hΟ β¦ ?_, fun h β¦ ?_β© -- do quicker implication first!
Β· refine (summable_pow_mul_jacobiThetaβ_term_bound |im z| hΟ 0).of_norm_bounded _ ?_
simpa only [pow_zero, one_mul] using norm_jacobiThetaβ_term_le hΟ le_rfl le_rfl
Β· by_contra! hΟ
rcases lt_or_eq_of_le hΟ with hΟ | hΟ
Β· -- easy case `im Ο < 0`
suffices Tendsto (fun n : β β¦ βjacobiThetaβ_term βn z Οβ) atTop atTop by
replace h := (h.comp_injective (fun a b β¦ Int.ofNat_inj.mp)).tendsto_atTop_zero.norm
exact atTop_neBot.ne (disjoint_self.mp <| h.disjoint (disjoint_nhds_atTop _) this)
simp only [norm_zero, Function.comp_def, norm_jacobiThetaβ_term, Int.cast_natCast]
conv =>
enter [1, n]
rw [show -Ο * n ^ 2 * Ο.im - 2 * Ο * n * z.im =
n * (n * (-Ο * Ο.im) - 2 * Ο * z.im) by ring]
refine tendsto_exp_atTop.comp (tendsto_natCast_atTop_atTop.atTop_mul_atTopβ ?_)
exact tendsto_atTop_add_const_right _ _ (tendsto_natCast_atTop_atTop.atTop_mul_const
(mul_pos_of_neg_of_neg (neg_lt_zero.mpr pi_pos) hΟ))
Β· -- case im Ο = 0: 3-way split according to `im z`
simp_rw [β summable_norm_iff (E := β), norm_jacobiThetaβ_term, hΟ, mul_zero, zero_sub] at h
rcases lt_trichotomy (im z) 0 with hz | hz | hz
Β· replace h := (h.comp_injective (fun a b β¦ Int.ofNat_inj.mp)).tendsto_atTop_zero
simp_rw [Function.comp_def, Int.cast_natCast] at h
refine atTop_neBot.ne (disjoint_self.mp <| h.disjoint (disjoint_nhds_atTop 0) ?_)
refine tendsto_exp_atTop.comp ?_
simp only [tendsto_neg_atTop_iff, mul_assoc]
apply Filter.Tendsto.const_mul_atBot two_pos
exact (tendsto_natCast_atTop_atTop.atTop_mul_const_of_neg hz).const_mul_atBot pi_pos
Β· revert h
simpa only [hz, mul_zero, neg_zero, Real.exp_zero, summable_const_iff] using one_ne_zero
Β· have : ((-βΒ·) : β β β€).Injective := fun _ _ β¦ by simp only [neg_inj, Nat.cast_inj, imp_self]
replace h := (h.comp_injective this).tendsto_atTop_zero
simp_rw [Function.comp_def, Int.cast_neg, Int.cast_natCast, mul_neg, neg_mul, neg_neg] at h
refine atTop_neBot.ne (disjoint_self.mp <| h.disjoint (disjoint_nhds_atTop 0) ?_)
exact tendsto_exp_atTop.comp ((tendsto_natCast_atTop_atTop.const_mul_atTop
(mul_pos two_pos pi_pos)).atTop_mul_const hz)
lemma norm_jacobiThetaβ_term_fderiv_le (n : β€) (z Ο : β) :
βjacobiThetaβ_term_fderiv n z Οβ β€ 3 * Ο * |n| ^ 2 * βjacobiThetaβ_term n z Οβ := by
-- this is slow to elaborate so do it once and reuse:
have hns (a : β) (f : (β Γ β) βL[β] β) : βa β’ fβ = βaβ * βfβ := norm_smul a f
rw [jacobiThetaβ_term_fderiv, jacobiThetaβ_term, hns,
mul_comm _ βcexp _β, (by norm_num : (3 : β) = 2 + 1), add_mul, add_mul]
refine mul_le_mul_of_nonneg_left ((norm_add_le _ _).trans (add_le_add ?_ ?_)) (norm_nonneg _)
Β· simp_rw [hns, norm_mul, β ofReal_ofNat, β ofReal_intCast,
norm_real, norm_of_nonneg zero_le_two, Real.norm_of_nonneg pi_pos.le, norm_I, mul_one,
Real.norm_eq_abs, Int.cast_abs, mul_assoc]
refine mul_le_mul_of_nonneg_left (mul_le_mul_of_nonneg_left ?_ pi_pos.le) two_pos.le
refine le_trans ?_ (?_ : |(n : β)| β€ |(n : β)| ^ 2)
Β· exact mul_le_of_le_one_right (abs_nonneg _) (ContinuousLinearMap.norm_fst_le ..)
Β· exact_mod_cast Int.le_self_sq |n|
Β· simp_rw [hns, norm_mul, one_mul, norm_I, mul_one,
norm_real, norm_of_nonneg pi_pos.le, β ofReal_intCast, β ofReal_pow, norm_real,
Real.norm_eq_abs, Int.cast_abs, abs_pow]
apply mul_le_of_le_one_right (mul_nonneg pi_pos.le (pow_nonneg (abs_nonneg _) _))
exact ContinuousLinearMap.norm_snd_le ..
lemma norm_jacobiThetaβ_term_fderiv_ge (n : β€) (z Ο : β) :
Ο * |n| ^ 2 * βjacobiThetaβ_term n z Οβ β€ βjacobiThetaβ_term_fderiv n z Οβ := by
have : β(jacobiThetaβ_term_fderiv n z Ο) (0, 1)β β€ βjacobiThetaβ_term_fderiv n z Οβ := by
refine (ContinuousLinearMap.le_opNorm _ _).trans ?_
simp_rw [Prod.norm_def, norm_one, norm_zero, max_eq_right zero_le_one, mul_one, le_refl]
refine le_trans ?_ this
simp_rw [jacobiThetaβ_term_fderiv, jacobiThetaβ_term, ContinuousLinearMap.coe_smul',
Pi.smul_apply, ContinuousLinearMap.add_apply, ContinuousLinearMap.coe_smul',
ContinuousLinearMap.coe_fst', ContinuousLinearMap.coe_snd', Pi.smul_apply, smul_zero, zero_add,
smul_eq_mul, mul_one, mul_comm _ βcexp _β, norm_mul]
refine mul_le_mul_of_nonneg_left (le_of_eq ?_) (norm_nonneg _)
simp_rw [norm_real, norm_of_nonneg pi_pos.le, norm_I, mul_one,
Int.cast_abs, β norm_intCast, norm_pow]
lemma summable_jacobiThetaβ_term_fderiv_iff (z Ο : β) :
Summable (jacobiThetaβ_term_fderiv Β· z Ο) β 0 < im Ο := by
constructor
Β· rw [β summable_jacobiThetaβ_term_iff (z := z)]
intro h
have := h.norm
refine this.of_norm_bounded_eventually _ ?_
have : βαΆ (n : β€) in cofinite, n β 0 :=
Int.cofinite_eq βΈ (mem_sup.mpr β¨eventually_ne_atBot 0, eventually_ne_atTop 0β©)
filter_upwards [this] with n hn
refine le_trans ?_ (norm_jacobiThetaβ_term_fderiv_ge n z Ο)
apply le_mul_of_one_le_left (norm_nonneg _)
refine one_le_pi_div_two.trans (mul_le_mul_of_nonneg_left ?_ pi_pos.le)
refine (by norm_num : 2β»ΒΉ β€ (1 : β)).trans ?_
rw [one_le_sq_iff_one_le_abs, β Int.cast_abs, abs_abs, β Int.cast_one, Int.cast_le]
exact Int.one_le_abs hn
Β· intro hΟ
refine ((summable_pow_mul_jacobiThetaβ_term_bound
|z.im| hΟ 2).mul_left (3 * Ο)).of_norm_bounded _ (fun n β¦ ?_)
refine (norm_jacobiThetaβ_term_fderiv_le n z Ο).trans
(?_ : 3 * Ο * |n| ^ 2 * βjacobiThetaβ_term n z Οβ β€ _)
simp_rw [mul_assoc (3 * Ο)]
refine mul_le_mul_of_nonneg_left ?_ (mul_pos (by norm_num : 0 < (3 : β)) pi_pos).le
refine mul_le_mul_of_nonneg_left ?_ (pow_nonneg (Int.cast_nonneg.mpr (abs_nonneg _)) _)
exact norm_jacobiThetaβ_term_le hΟ le_rfl le_rfl n
lemma summable_jacobiThetaβ'_term_iff (z Ο : β) :
Summable (jacobiThetaβ'_term Β· z Ο) β 0 < im Ο := by
constructor
Β· rw [β summable_jacobiThetaβ_term_iff (z := z)]
refine fun h β¦ (h.norm.mul_left (2 * Ο)β»ΒΉ).of_norm_bounded_eventually _ ?_
have : βαΆ (n : β€) in cofinite, n β 0 :=
Int.cofinite_eq βΈ (mem_sup.mpr β¨eventually_ne_atBot 0, eventually_ne_atTop 0β©)
filter_upwards [this] with n hn
rw [jacobiThetaβ'_term, norm_mul, β mul_assoc]
refine le_mul_of_one_le_left (norm_nonneg _) ?_
simp_rw [norm_mul, norm_I, norm_real, mul_one, norm_of_nonneg pi_pos.le,
β ofReal_ofNat, norm_real, norm_of_nonneg two_pos.le, β ofReal_intCast, norm_real,
Real.norm_eq_abs, β Int.cast_abs, β mul_assoc _ (2 * Ο),
inv_mul_cancelβ (mul_pos two_pos pi_pos).ne', one_mul]
rw [β Int.cast_one, Int.cast_le]
exact Int.one_le_abs hn
Β· refine fun hΟ β¦ ((summable_pow_mul_jacobiThetaβ_term_bound
|z.im| hΟ 1).mul_left (2 * Ο)).of_norm_bounded _ (fun n β¦ ?_)
rw [jacobiThetaβ'_term, norm_mul, β mul_assoc, pow_one]
refine mul_le_mul (le_of_eq ?_) (norm_jacobiThetaβ_term_le hΟ le_rfl le_rfl n)
(norm_nonneg _) (by positivity)
simp_rw [norm_mul, Complex.norm_two, norm_I, Complex.norm_of_nonneg pi_pos.le,
norm_intCast, mul_one, Int.cast_abs]
end term_bounds
/-!
## Definitions of the functions
-/
/-- The two-variable Jacobi theta function,
`ΞΈ z Ο = β' (n : β€), cexp (2 * Ο * I * n * z + Ο * I * n ^ 2 * Ο)`.
-/
def jacobiThetaβ (z Ο : β) : β := β' n : β€, jacobiThetaβ_term n z Ο
/-- FrΓ©chet derivative of the two-variable Jacobi theta function. -/
def jacobiThetaβ_fderiv (z Ο : β) : β Γ β βL[β] β := β' n : β€, jacobiThetaβ_term_fderiv n z Ο
/-- The `z`-derivative of the Jacobi theta function,
`ΞΈ' z Ο = β' (n : β€), 2 * Ο * I * n * cexp (2 * Ο * I * n * z + Ο * I * n ^ 2 * Ο)`.
-/
def jacobiThetaβ' (z Ο : β) := β' n : β€, jacobiThetaβ'_term n z Ο
lemma hasSum_jacobiThetaβ_term (z : β) {Ο : β} (hΟ : 0 < im Ο) :
HasSum (fun n β¦ jacobiThetaβ_term n z Ο) (jacobiThetaβ z Ο) :=
((summable_jacobiThetaβ_term_iff z Ο).mpr hΟ).hasSum
lemma hasSum_jacobiThetaβ_term_fderiv (z : β) {Ο : β} (hΟ : 0 < im Ο) :
HasSum (fun n β¦ jacobiThetaβ_term_fderiv n z Ο) (jacobiThetaβ_fderiv z Ο) :=
((summable_jacobiThetaβ_term_fderiv_iff z Ο).mpr hΟ).hasSum
lemma hasSum_jacobiThetaβ'_term (z : β) {Ο : β} (hΟ : 0 < im Ο) :
HasSum (fun n β¦ jacobiThetaβ'_term n z Ο) (jacobiThetaβ' z Ο) :=
((summable_jacobiThetaβ'_term_iff z Ο).mpr hΟ).hasSum
lemma jacobiThetaβ_undef (z : β) {Ο : β} (hΟ : im Ο β€ 0) : jacobiThetaβ z Ο = 0 := by
apply tsum_eq_zero_of_not_summable
rw [summable_jacobiThetaβ_term_iff]
exact not_lt.mpr hΟ
lemma jacobiThetaβ_fderiv_undef (z : β) {Ο : β} (hΟ : im Ο β€ 0) : jacobiThetaβ_fderiv z Ο = 0 := by
apply tsum_eq_zero_of_not_summable
rw [summable_jacobiThetaβ_term_fderiv_iff]
exact not_lt.mpr hΟ
lemma jacobiThetaβ'_undef (z : β) {Ο : β} (hΟ : im Ο β€ 0) : jacobiThetaβ' z Ο = 0 := by
apply tsum_eq_zero_of_not_summable
rw [summable_jacobiThetaβ'_term_iff]
exact not_lt.mpr hΟ
/-!
## Derivatives and continuity
-/
|
lemma hasFDerivAt_jacobiThetaβ (z : β) {Ο : β} (hΟ : 0 < im Ο) :
HasFDerivAt (fun p : β Γ β β¦ jacobiThetaβ p.1 p.2) (jacobiThetaβ_fderiv z Ο) (z, Ο) := by
obtain β¨T, hT, hΟ'β© := exists_between hΟ
obtain β¨S, hzβ© := exists_gt |im z|
let V := {u | |im u| < S} ΓΛ’ {v | T < im v}
have hVo : IsOpen V := by
refine ((_root_.continuous_abs.comp continuous_im).isOpen_preimage _ isOpen_Iio).prod ?_
exact continuous_im.isOpen_preimage _ isOpen_Ioi
have hVmem : (z, Ο) β V := β¨hz, hΟ'β©
have hVp : IsPreconnected V := by
refine (Convex.isPreconnected ?_).prod (convex_halfSpace_im_gt T).isPreconnected
simpa only [abs_lt] using (convex_halfSpace_im_gt _).inter (convex_halfSpace_im_lt _)
let f : β€ β β Γ β β β := fun n p β¦ jacobiThetaβ_term n p.1 p.2
let f' : β€ β β Γ β β β Γ β βL[β] β := fun n p β¦ jacobiThetaβ_term_fderiv n p.1 p.2
have hf (n : β€) : β p β V, HasFDerivAt (f n) (f' n p) p :=
fun p _ β¦ hasFDerivAt_jacobiThetaβ_term n p.1 p.2
let u : β€ β β := fun n β¦ 3 * Ο * |n| ^ 2 * Real.exp (-Ο * (T * n ^ 2 - 2 * S * |n|))
have hu : β (n : β€), β x β V, βf' n xβ β€ u n := by
refine fun n p hp β¦ (norm_jacobiThetaβ_term_fderiv_le n p.1 p.2).trans ?_
refine mul_le_mul_of_nonneg_left ?_ (by positivity)
exact norm_jacobiThetaβ_term_le hT (le_of_lt hp.1) (le_of_lt hp.2) n
have hu_sum : Summable u := by
simp_rw [u, mul_assoc (3 * Ο)]
exact (summable_pow_mul_jacobiThetaβ_term_bound S hT 2).mul_left _
have hf_sum : Summable fun n : β€ β¦ f n (z, Ο) := by
refine (summable_pow_mul_jacobiThetaβ_term_bound S hT 0).of_norm_bounded _ ?_
simpa only [pow_zero, one_mul] using norm_jacobiThetaβ_term_le hT hz.le hΟ'.le
simpa only [jacobiThetaβ, jacobiThetaβ_fderiv, f, f'] using
| Mathlib/NumberTheory/ModularForms/JacobiTheta/TwoVariable.lean | 291 | 319 |
/-
Copyright (c) 2022 Floris van Doorn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Floris van Doorn
-/
import Mathlib.Analysis.Calculus.ContDiff.Basic
import Mathlib.Analysis.Calculus.ParametricIntegral
import Mathlib.MeasureTheory.Integral.Prod
import Mathlib.MeasureTheory.Function.LocallyIntegrable
import Mathlib.MeasureTheory.Group.Integral
import Mathlib.MeasureTheory.Group.Prod
import Mathlib.MeasureTheory.Integral.IntervalIntegral.Basic
/-!
# Convolution of functions
This file defines the convolution on two functions, i.e. `x β¦ β« f(t)g(x - t) βt`.
In the general case, these functions can be vector-valued, and have an arbitrary (additive)
group as domain. We use a continuous bilinear operation `L` on these function values as
"multiplication". The domain must be equipped with a Haar measure `ΞΌ`
(though many individual results have weaker conditions on `ΞΌ`).
For many applications we can take `L = ContinuousLinearMap.lsmul β β` or
`L = ContinuousLinearMap.mul β β`.
We also define `ConvolutionExists` and `ConvolutionExistsAt` to state that the convolution is
well-defined (everywhere or at a single point). These conditions are needed for pointwise
computations (e.g. `ConvolutionExistsAt.distrib_add`), but are generally not strong enough for any
local (or global) properties of the convolution. For this we need stronger assumptions on `f`
and/or `g`, and generally if we impose stronger conditions on one of the functions, we can impose
weaker conditions on the other.
We have proven many of the properties of the convolution assuming one of these functions
has compact support (in which case the other function only needs to be locally integrable).
We still need to prove the properties for other pairs of conditions (e.g. both functions are
rapidly decreasing)
# Design Decisions
We use a bilinear map `L` to "multiply" the two functions in the integrand.
This generality has several advantages
* This allows us to compute the total derivative of the convolution, in case the functions are
multivariate. The total derivative is again a convolution, but where the codomains of the
functions can be higher-dimensional. See `HasCompactSupport.hasFDerivAt_convolution_right`.
* This allows us to use `@[to_additive]` everywhere (which would not be possible if we would use
`mul`/`smul` in the integral, since `@[to_additive]` will incorrectly also try to additivize
those definitions).
* We need to support the case where at least one of the functions is vector-valued, but if we use
`smul` to multiply the functions, that would be an asymmetric definition.
# Main Definitions
* `MeasureTheory.convolution f g L ΞΌ x = (f β[L, ΞΌ] g) x = β« t, L (f t) (g (x - t)) βΞΌ`
is the convolution of `f` and `g` w.r.t. the continuous bilinear map `L` and measure `ΞΌ`.
* `MeasureTheory.ConvolutionExistsAt f g x L ΞΌ` states that the convolution `(f β[L, ΞΌ] g) x`
is well-defined (i.e. the integral exists).
* `MeasureTheory.ConvolutionExists f g L ΞΌ` states that the convolution `f β[L, ΞΌ] g`
is well-defined at each point.
# Main Results
* `HasCompactSupport.hasFDerivAt_convolution_right` and
`HasCompactSupport.hasFDerivAt_convolution_left`: we can compute the total derivative
of the convolution as a convolution with the total derivative of the right (left) function.
* `HasCompactSupport.contDiff_convolution_right` and
`HasCompactSupport.contDiff_convolution_left`: the convolution is `πβΏ` if one of the functions
is `πβΏ` with compact support and the other function in locally integrable.
Versions of these statements for functions depending on a parameter are also given.
* `MeasureTheory.convolution_tendsto_right`: Given a sequence of nonnegative normalized functions
whose support tends to a small neighborhood around `0`, the convolution tends to the right
argument. This is specialized to bump functions in `ContDiffBump.convolution_tendsto_right`.
# Notation
The following notations are localized in the locale `Convolution`:
* `f β[L, ΞΌ] g` for the convolution. Note: you have to use parentheses to apply the convolution
to an argument: `(f β[L, ΞΌ] g) x`.
* `f β[L] g := f β[L, volume] g`
* `f β g := f β[lsmul β β] g`
# To do
* Existence and (uniform) continuity of the convolution if
one of the maps is in `β^p` and the other in `β^q` with `1 / p + 1 / q = 1`.
This might require a generalization of `MeasureTheory.MemLp.smul` where `smul` is generalized
to a continuous bilinear map.
(see e.g. [Fremlin, *Measure Theory* (volume 2)][fremlin_vol2], 255K)
* The convolution is an `AEStronglyMeasurable` function
(see e.g. [Fremlin, *Measure Theory* (volume 2)][fremlin_vol2], 255I).
* Prove properties about the convolution if both functions are rapidly decreasing.
* Use `@[to_additive]` everywhere (this likely requires changes in `to_additive`)
-/
open Set Function Filter MeasureTheory MeasureTheory.Measure TopologicalSpace
open Bornology ContinuousLinearMap Metric Topology
open scoped Pointwise NNReal Filter
universe uπ uG uE uE' uE'' uF uF' uF'' uP
variable {π : Type uπ} {G : Type uG} {E : Type uE} {E' : Type uE'} {E'' : Type uE''} {F : Type uF}
{F' : Type uF'} {F'' : Type uF''} {P : Type uP}
variable [NormedAddCommGroup E] [NormedAddCommGroup E'] [NormedAddCommGroup E'']
[NormedAddCommGroup F] {f f' : G β E} {g g' : G β E'} {x x' : G} {y y' : E}
namespace MeasureTheory
section NontriviallyNormedField
variable [NontriviallyNormedField π]
variable [NormedSpace π E] [NormedSpace π E'] [NormedSpace π E''] [NormedSpace π F]
variable (L : E βL[π] E' βL[π] F)
section NoMeasurability
variable [AddGroup G] [TopologicalSpace G]
theorem convolution_integrand_bound_right_of_le_of_subset {C : β} (hC : β i, βg iβ β€ C) {x t : G}
{s u : Set G} (hx : x β s) (hu : -tsupport g + s β u) :
βL (f t) (g (x - t))β β€ u.indicator (fun t => βLβ * βf tβ * C) t := by
-- Porting note: had to add `f := _`
refine le_indicator (f := fun t β¦ βL (f t) (g (x - t))β) (fun t _ => ?_) (fun t ht => ?_) t
Β· apply_rules [L.le_of_opNormβ_le_of_le, le_rfl]
Β· have : x - t β support g := by
refine mt (fun hxt => hu ?_) ht
refine β¨_, Set.neg_mem_neg.mpr (subset_closure hxt), _, hx, ?_β©
simp only [neg_sub, sub_add_cancel]
simp only [nmem_support.mp this, (L _).map_zero, norm_zero, le_rfl]
theorem _root_.HasCompactSupport.convolution_integrand_bound_right_of_subset
(hcg : HasCompactSupport g) (hg : Continuous g)
{x t : G} {s u : Set G} (hx : x β s) (hu : -tsupport g + s β u) :
βL (f t) (g (x - t))β β€ u.indicator (fun t => βLβ * βf tβ * β¨ i, βg iβ) t := by
refine convolution_integrand_bound_right_of_le_of_subset _ (fun i => ?_) hx hu
exact le_ciSup (hg.norm.bddAbove_range_of_hasCompactSupport hcg.norm) _
theorem _root_.HasCompactSupport.convolution_integrand_bound_right (hcg : HasCompactSupport g)
(hg : Continuous g) {x t : G} {s : Set G} (hx : x β s) :
βL (f t) (g (x - t))β β€ (-tsupport g + s).indicator (fun t => βLβ * βf tβ * β¨ i, βg iβ) t :=
hcg.convolution_integrand_bound_right_of_subset L hg hx Subset.rfl
theorem _root_.Continuous.convolution_integrand_fst [ContinuousSub G] (hg : Continuous g) (t : G) :
Continuous fun x => L (f t) (g (x - t)) :=
L.continuousβ.compβ continuous_const <| hg.comp <| continuous_id.sub continuous_const
theorem _root_.HasCompactSupport.convolution_integrand_bound_left (hcf : HasCompactSupport f)
(hf : Continuous f) {x t : G} {s : Set G} (hx : x β s) :
βL (f (x - t)) (g t)β β€
(-tsupport f + s).indicator (fun t => (βLβ * β¨ i, βf iβ) * βg tβ) t := by
convert hcf.convolution_integrand_bound_right L.flip hf hx using 1
simp_rw [L.opNorm_flip, mul_right_comm]
end NoMeasurability
section Measurability
variable [MeasurableSpace G] {ΞΌ Ξ½ : Measure G}
/-- The convolution of `f` and `g` exists at `x` when the function `t β¦ L (f t) (g (x - t))` is
integrable. There are various conditions on `f` and `g` to prove this. -/
def ConvolutionExistsAt [Sub G] (f : G β E) (g : G β E') (x : G) (L : E βL[π] E' βL[π] F)
(ΞΌ : Measure G := by volume_tac) : Prop :=
Integrable (fun t => L (f t) (g (x - t))) ΞΌ
/-- The convolution of `f` and `g` exists when the function `t β¦ L (f t) (g (x - t))` is integrable
for all `x : G`. There are various conditions on `f` and `g` to prove this. -/
def ConvolutionExists [Sub G] (f : G β E) (g : G β E') (L : E βL[π] E' βL[π] F)
(ΞΌ : Measure G := by volume_tac) : Prop :=
β x : G, ConvolutionExistsAt f g x L ΞΌ
section ConvolutionExists
variable {L} in
theorem ConvolutionExistsAt.integrable [Sub G] {x : G} (h : ConvolutionExistsAt f g x L ΞΌ) :
Integrable (fun t => L (f t) (g (x - t))) ΞΌ :=
h
section Group
variable [AddGroup G]
theorem AEStronglyMeasurable.convolution_integrand' [MeasurableAddβ G]
[MeasurableNeg G] (hf : AEStronglyMeasurable f Ξ½)
(hg : AEStronglyMeasurable g <| map (fun p : G Γ G => p.1 - p.2) (ΞΌ.prod Ξ½)) :
AEStronglyMeasurable (fun p : G Γ G => L (f p.2) (g (p.1 - p.2))) (ΞΌ.prod Ξ½) :=
L.aestronglyMeasurable_compβ hf.snd <| hg.comp_measurable measurable_sub
section
variable [MeasurableAdd G] [MeasurableNeg G]
theorem AEStronglyMeasurable.convolution_integrand_snd'
(hf : AEStronglyMeasurable f ΞΌ) {x : G}
(hg : AEStronglyMeasurable g <| map (fun t => x - t) ΞΌ) :
AEStronglyMeasurable (fun t => L (f t) (g (x - t))) ΞΌ :=
L.aestronglyMeasurable_compβ hf <| hg.comp_measurable <| measurable_id.const_sub x
theorem AEStronglyMeasurable.convolution_integrand_swap_snd' {x : G}
(hf : AEStronglyMeasurable f <| map (fun t => x - t) ΞΌ) (hg : AEStronglyMeasurable g ΞΌ) :
AEStronglyMeasurable (fun t => L (f (x - t)) (g t)) ΞΌ :=
L.aestronglyMeasurable_compβ (hf.comp_measurable <| measurable_id.const_sub x) hg
/-- A sufficient condition to prove that `f β[L, ΞΌ] g` exists.
We assume that `f` is integrable on a set `s` and `g` is bounded and ae strongly measurable
on `xβ - s` (note that both properties hold if `g` is continuous with compact support). -/
theorem _root_.BddAbove.convolutionExistsAt' {xβ : G} {s : Set G}
(hbg : BddAbove ((fun i => βg iβ) '' ((fun t => -t + xβ) β»ΒΉ' s))) (hs : MeasurableSet s)
(h2s : (support fun t => L (f t) (g (xβ - t))) β s) (hf : IntegrableOn f s ΞΌ)
(hmg : AEStronglyMeasurable g <| map (fun t => xβ - t) (ΞΌ.restrict s)) :
ConvolutionExistsAt f g xβ L ΞΌ := by
rw [ConvolutionExistsAt]
rw [β integrableOn_iff_integrable_of_support_subset h2s]
set s' := (fun t => -t + xβ) β»ΒΉ' s
have : βα΅ t : G βΞΌ.restrict s,
βL (f t) (g (xβ - t))β β€ s.indicator (fun t => βLβ * βf tβ * β¨ i : s', βg iβ) t := by
filter_upwards
refine le_indicator (fun t ht => ?_) fun t ht => ?_
Β· apply_rules [L.le_of_opNormβ_le_of_le, le_rfl]
refine (le_ciSup_set hbg <| mem_preimage.mpr ?_)
rwa [neg_sub, sub_add_cancel]
Β· have : t β support fun t => L (f t) (g (xβ - t)) := mt (fun h => h2s h) ht
rw [nmem_support.mp this, norm_zero]
refine Integrable.mono' ?_ ?_ this
Β· rw [integrable_indicator_iff hs]; exact ((hf.norm.const_mul _).mul_const _).integrableOn
Β· exact hf.aestronglyMeasurable.convolution_integrand_snd' L hmg
/-- If `βfβ *[ΞΌ] βgβ` exists, then `f *[L, ΞΌ] g` exists. -/
theorem ConvolutionExistsAt.of_norm' {xβ : G}
(h : ConvolutionExistsAt (fun x => βf xβ) (fun x => βg xβ) xβ (mul β β) ΞΌ)
(hmf : AEStronglyMeasurable f ΞΌ) (hmg : AEStronglyMeasurable g <| map (fun t => xβ - t) ΞΌ) :
ConvolutionExistsAt f g xβ L ΞΌ := by
refine (h.const_mul βLβ).mono'
(hmf.convolution_integrand_snd' L hmg) (Eventually.of_forall fun x => ?_)
rw [mul_apply', β mul_assoc]
apply L.le_opNormβ
@[deprecated (since := "2025-02-07")]
alias ConvolutionExistsAt.ofNorm' := ConvolutionExistsAt.of_norm'
end
section Left
variable [MeasurableAddβ G] [MeasurableNeg G] [SFinite ΞΌ] [IsAddRightInvariant ΞΌ]
theorem AEStronglyMeasurable.convolution_integrand_snd (hf : AEStronglyMeasurable f ΞΌ)
(hg : AEStronglyMeasurable g ΞΌ) (x : G) :
AEStronglyMeasurable (fun t => L (f t) (g (x - t))) ΞΌ :=
hf.convolution_integrand_snd' L <|
hg.mono_ac <| (quasiMeasurePreserving_sub_left_of_right_invariant ΞΌ x).absolutelyContinuous
theorem AEStronglyMeasurable.convolution_integrand_swap_snd
(hf : AEStronglyMeasurable f ΞΌ) (hg : AEStronglyMeasurable g ΞΌ) (x : G) :
AEStronglyMeasurable (fun t => L (f (x - t)) (g t)) ΞΌ :=
(hf.mono_ac
(quasiMeasurePreserving_sub_left_of_right_invariant ΞΌ
x).absolutelyContinuous).convolution_integrand_swap_snd'
L hg
/-- If `βfβ *[ΞΌ] βgβ` exists, then `f *[L, ΞΌ] g` exists. -/
theorem ConvolutionExistsAt.of_norm {xβ : G}
(h : ConvolutionExistsAt (fun x => βf xβ) (fun x => βg xβ) xβ (mul β β) ΞΌ)
(hmf : AEStronglyMeasurable f ΞΌ) (hmg : AEStronglyMeasurable g ΞΌ) :
ConvolutionExistsAt f g xβ L ΞΌ :=
h.of_norm' L hmf <|
hmg.mono_ac (quasiMeasurePreserving_sub_left_of_right_invariant ΞΌ xβ).absolutelyContinuous
@[deprecated (since := "2025-02-07")]
alias ConvolutionExistsAt.ofNorm := ConvolutionExistsAt.of_norm
end Left
section Right
variable [MeasurableAddβ G] [MeasurableNeg G] [SFinite ΞΌ] [IsAddRightInvariant ΞΌ] [SFinite Ξ½]
theorem AEStronglyMeasurable.convolution_integrand (hf : AEStronglyMeasurable f Ξ½)
(hg : AEStronglyMeasurable g ΞΌ) :
AEStronglyMeasurable (fun p : G Γ G => L (f p.2) (g (p.1 - p.2))) (ΞΌ.prod Ξ½) :=
hf.convolution_integrand' L <|
hg.mono_ac (quasiMeasurePreserving_sub_of_right_invariant ΞΌ Ξ½).absolutelyContinuous
theorem Integrable.convolution_integrand (hf : Integrable f Ξ½) (hg : Integrable g ΞΌ) :
Integrable (fun p : G Γ G => L (f p.2) (g (p.1 - p.2))) (ΞΌ.prod Ξ½) := by
have h_meas : AEStronglyMeasurable (fun p : G Γ G => L (f p.2) (g (p.1 - p.2))) (ΞΌ.prod Ξ½) :=
hf.aestronglyMeasurable.convolution_integrand L hg.aestronglyMeasurable
have h2_meas : AEStronglyMeasurable (fun y : G => β« x : G, βL (f y) (g (x - y))β βΞΌ) Ξ½ :=
h_meas.prod_swap.norm.integral_prod_right'
simp_rw [integrable_prod_iff' h_meas]
refine β¨Eventually.of_forall fun t => (L (f t)).integrable_comp (hg.comp_sub_right t), ?_β©
refine Integrable.mono' ?_ h2_meas
(Eventually.of_forall fun t => (?_ : _ β€ βLβ * βf tβ * β« x, βg (x - t)β βΞΌ))
Β· simp only [integral_sub_right_eq_self (βg Β·β)]
exact (hf.norm.const_mul _).mul_const _
Β· simp_rw [β integral_const_mul]
rw [Real.norm_of_nonneg (by positivity)]
exact integral_mono_of_nonneg (Eventually.of_forall fun t => norm_nonneg _)
((hg.comp_sub_right t).norm.const_mul _) (Eventually.of_forall fun t => L.le_opNormβ _ _)
theorem Integrable.ae_convolution_exists (hf : Integrable f Ξ½) (hg : Integrable g ΞΌ) :
βα΅ x βΞΌ, ConvolutionExistsAt f g x L Ξ½ :=
((integrable_prod_iff <|
hf.aestronglyMeasurable.convolution_integrand L hg.aestronglyMeasurable).mp <|
hf.convolution_integrand L hg).1
end Right
variable [TopologicalSpace G] [IsTopologicalAddGroup G] [BorelSpace G]
theorem _root_.HasCompactSupport.convolutionExistsAt {xβ : G}
(h : HasCompactSupport fun t => L (f t) (g (xβ - t))) (hf : LocallyIntegrable f ΞΌ)
(hg : Continuous g) : ConvolutionExistsAt f g xβ L ΞΌ := by
let u := (Homeomorph.neg G).trans (Homeomorph.addRight xβ)
let v := (Homeomorph.neg G).trans (Homeomorph.addLeft xβ)
apply ((u.isCompact_preimage.mpr h).bddAbove_image hg.norm.continuousOn).convolutionExistsAt' L
isClosed_closure.measurableSet subset_closure (hf.integrableOn_isCompact h)
have A : AEStronglyMeasurable (g β v)
(ΞΌ.restrict (tsupport fun t : G => L (f t) (g (xβ - t)))) := by
apply (hg.comp v.continuous).continuousOn.aestronglyMeasurable_of_isCompact h
exact (isClosed_tsupport _).measurableSet
convert ((v.continuous.measurable.measurePreserving
(ΞΌ.restrict (tsupport fun t => L (f t) (g (xβ - t))))).aestronglyMeasurable_comp_iff
v.measurableEmbedding).1 A
ext x
simp only [v, Homeomorph.neg, sub_eq_add_neg, val_toAddUnits_apply, Homeomorph.trans_apply,
Equiv.neg_apply, Equiv.toFun_as_coe, Homeomorph.homeomorph_mk_coe, Equiv.coe_fn_mk,
Homeomorph.coe_addLeft]
theorem _root_.HasCompactSupport.convolutionExists_right (hcg : HasCompactSupport g)
(hf : LocallyIntegrable f ΞΌ) (hg : Continuous g) : ConvolutionExists f g L ΞΌ := by
intro xβ
refine HasCompactSupport.convolutionExistsAt L ?_ hf hg
refine (hcg.comp_homeomorph (Homeomorph.subLeft xβ)).mono ?_
refine fun t => mt fun ht : g (xβ - t) = 0 => ?_
simp_rw [ht, (L _).map_zero]
theorem _root_.HasCompactSupport.convolutionExists_left_of_continuous_right
(hcf : HasCompactSupport f) (hf : LocallyIntegrable f ΞΌ) (hg : Continuous g) :
ConvolutionExists f g L ΞΌ := by
intro xβ
refine HasCompactSupport.convolutionExistsAt L ?_ hf hg
refine hcf.mono ?_
refine fun t => mt fun ht : f t = 0 => ?_
simp_rw [ht, L.map_zeroβ]
end Group
section CommGroup
variable [AddCommGroup G]
section MeasurableGroup
variable [MeasurableNeg G] [IsAddLeftInvariant ΞΌ]
/-- A sufficient condition to prove that `f β[L, ΞΌ] g` exists.
We assume that the integrand has compact support and `g` is bounded on this support (note that
both properties hold if `g` is continuous with compact support). We also require that `f` is
integrable on the support of the integrand, and that both functions are strongly measurable.
This is a variant of `BddAbove.convolutionExistsAt'` in an abelian group with a left-invariant
measure. This allows us to state the boundedness and measurability of `g` in a more natural way. -/
theorem _root_.BddAbove.convolutionExistsAt [MeasurableAddβ G] [SFinite ΞΌ] {xβ : G} {s : Set G}
(hbg : BddAbove ((fun i => βg iβ) '' ((fun t => xβ - t) β»ΒΉ' s))) (hs : MeasurableSet s)
(h2s : (support fun t => L (f t) (g (xβ - t))) β s) (hf : IntegrableOn f s ΞΌ)
(hmg : AEStronglyMeasurable g ΞΌ) : ConvolutionExistsAt f g xβ L ΞΌ := by
refine BddAbove.convolutionExistsAt' L ?_ hs h2s hf ?_
Β· simp_rw [β sub_eq_neg_add, hbg]
Β· have : AEStronglyMeasurable g (map (fun t : G => xβ - t) ΞΌ) :=
hmg.mono_ac (quasiMeasurePreserving_sub_left_of_right_invariant ΞΌ xβ).absolutelyContinuous
apply this.mono_measure
exact map_mono restrict_le_self (measurable_const.sub measurable_id')
variable {L} [MeasurableAdd G] [IsNegInvariant ΞΌ]
theorem convolutionExistsAt_flip :
ConvolutionExistsAt g f x L.flip ΞΌ β ConvolutionExistsAt f g x L ΞΌ := by
simp_rw [ConvolutionExistsAt, β integrable_comp_sub_left (fun t => L (f t) (g (x - t))) x,
sub_sub_cancel, flip_apply]
theorem ConvolutionExistsAt.integrable_swap (h : ConvolutionExistsAt f g x L ΞΌ) :
Integrable (fun t => L (f (x - t)) (g t)) ΞΌ := by
convert h.comp_sub_left x
simp_rw [sub_sub_self]
theorem convolutionExistsAt_iff_integrable_swap :
ConvolutionExistsAt f g x L ΞΌ β Integrable (fun t => L (f (x - t)) (g t)) ΞΌ :=
convolutionExistsAt_flip.symm
end MeasurableGroup
variable [TopologicalSpace G] [IsTopologicalAddGroup G] [BorelSpace G]
variable [IsAddLeftInvariant ΞΌ] [IsNegInvariant ΞΌ]
theorem _root_.HasCompactSupport.convolutionExists_left
(hcf : HasCompactSupport f) (hf : Continuous f)
(hg : LocallyIntegrable g ΞΌ) : ConvolutionExists f g L ΞΌ := fun xβ =>
convolutionExistsAt_flip.mp <| hcf.convolutionExists_right L.flip hg hf xβ
@[deprecated (since := "2025-02-06")]
alias _root_.HasCompactSupport.convolutionExistsLeft := HasCompactSupport.convolutionExists_left
theorem _root_.HasCompactSupport.convolutionExists_right_of_continuous_left
(hcg : HasCompactSupport g) (hf : Continuous f) (hg : LocallyIntegrable g ΞΌ) :
ConvolutionExists f g L ΞΌ := fun xβ =>
convolutionExistsAt_flip.mp <| hcg.convolutionExists_left_of_continuous_right L.flip hg hf xβ
@[deprecated (since := "2025-02-06")]
alias _root_.HasCompactSupport.convolutionExistsRightOfContinuousLeft :=
HasCompactSupport.convolutionExists_right_of_continuous_left
end CommGroup
end ConvolutionExists
variable [NormedSpace β F]
/-- The convolution of two functions `f` and `g` with respect to a continuous bilinear map `L` and
measure `ΞΌ`. It is defined to be `(f β[L, ΞΌ] g) x = β« t, L (f t) (g (x - t)) βΞΌ`. -/
noncomputable def convolution [Sub G] (f : G β E) (g : G β E') (L : E βL[π] E' βL[π] F)
(ΞΌ : Measure G := by volume_tac) : G β F := fun x =>
β« t, L (f t) (g (x - t)) βΞΌ
/-- The convolution of two functions with respect to a bilinear operation `L` and a measure `ΞΌ`. -/
scoped[Convolution] notation:67 f " β[" L:67 ", " ΞΌ:67 "] " g:66 => convolution f g L ΞΌ
/-- The convolution of two functions with respect to a bilinear operation `L` and the volume. -/
scoped[Convolution]
notation:67 f " β[" L:67 "]" g:66 => convolution f g L MeasureSpace.volume
/-- The convolution of two real-valued functions with respect to volume. -/
scoped[Convolution]
notation:67 f " β " g:66 =>
convolution f g (ContinuousLinearMap.lsmul β β) MeasureSpace.volume
open scoped Convolution
theorem convolution_def [Sub G] : (f β[L, ΞΌ] g) x = β« t, L (f t) (g (x - t)) βΞΌ :=
rfl
/-- The definition of convolution where the bilinear operator is scalar multiplication.
Note: it often helps the elaborator to give the type of the convolution explicitly. -/
theorem convolution_lsmul [Sub G] {f : G β π} {g : G β F} :
(f β[lsmul π π, ΞΌ] g : G β F) x = β« t, f t β’ g (x - t) βΞΌ :=
rfl
/-- The definition of convolution where the bilinear operator is multiplication. -/
theorem convolution_mul [Sub G] [NormedSpace β π] {f : G β π} {g : G β π} :
(f β[mul π π, ΞΌ] g) x = β« t, f t * g (x - t) βΞΌ :=
rfl
section Group
variable {L} [AddGroup G]
theorem smul_convolution [SMulCommClass β π F] {y : π} : y β’ f β[L, ΞΌ] g = y β’ (f β[L, ΞΌ] g) := by
ext; simp only [Pi.smul_apply, convolution_def, β integral_smul, L.map_smulβ]
theorem convolution_smul [SMulCommClass β π F] {y : π} : f β[L, ΞΌ] y β’ g = y β’ (f β[L, ΞΌ] g) := by
ext; simp only [Pi.smul_apply, convolution_def, β integral_smul, (L _).map_smul]
@[simp]
theorem zero_convolution : 0 β[L, ΞΌ] g = 0 := by
ext
simp_rw [convolution_def, Pi.zero_apply, L.map_zeroβ, integral_zero]
@[simp]
theorem convolution_zero : f β[L, ΞΌ] 0 = 0 := by
ext
simp_rw [convolution_def, Pi.zero_apply, (L _).map_zero, integral_zero]
theorem ConvolutionExistsAt.distrib_add {x : G} (hfg : ConvolutionExistsAt f g x L ΞΌ)
(hfg' : ConvolutionExistsAt f g' x L ΞΌ) :
(f β[L, ΞΌ] (g + g')) x = (f β[L, ΞΌ] g) x + (f β[L, ΞΌ] g') x := by
simp only [convolution_def, (L _).map_add, Pi.add_apply, integral_add hfg hfg']
theorem ConvolutionExists.distrib_add (hfg : ConvolutionExists f g L ΞΌ)
(hfg' : ConvolutionExists f g' L ΞΌ) : f β[L, ΞΌ] (g + g') = f β[L, ΞΌ] g + f β[L, ΞΌ] g' := by
ext x
exact (hfg x).distrib_add (hfg' x)
theorem ConvolutionExistsAt.add_distrib {x : G} (hfg : ConvolutionExistsAt f g x L ΞΌ)
(hfg' : ConvolutionExistsAt f' g x L ΞΌ) :
((f + f') β[L, ΞΌ] g) x = (f β[L, ΞΌ] g) x + (f' β[L, ΞΌ] g) x := by
simp only [convolution_def, L.map_addβ, Pi.add_apply, integral_add hfg hfg']
theorem ConvolutionExists.add_distrib (hfg : ConvolutionExists f g L ΞΌ)
(hfg' : ConvolutionExists f' g L ΞΌ) : (f + f') β[L, ΞΌ] g = f β[L, ΞΌ] g + f' β[L, ΞΌ] g := by
ext x
exact (hfg x).add_distrib (hfg' x)
theorem convolution_mono_right {f g g' : G β β} (hfg : ConvolutionExistsAt f g x (lsmul β β) ΞΌ)
(hfg' : ConvolutionExistsAt f g' x (lsmul β β) ΞΌ) (hf : β x, 0 β€ f x) (hg : β x, g x β€ g' x) :
(f β[lsmul β β, ΞΌ] g) x β€ (f β[lsmul β β, ΞΌ] g') x := by
apply integral_mono hfg hfg'
simp only [lsmul_apply, Algebra.id.smul_eq_mul]
intro t
apply mul_le_mul_of_nonneg_left (hg _) (hf _)
theorem convolution_mono_right_of_nonneg {f g g' : G β β}
(hfg' : ConvolutionExistsAt f g' x (lsmul β β) ΞΌ) (hf : β x, 0 β€ f x) (hg : β x, g x β€ g' x)
(hg' : β x, 0 β€ g' x) : (f β[lsmul β β, ΞΌ] g) x β€ (f β[lsmul β β, ΞΌ] g') x := by
by_cases H : ConvolutionExistsAt f g x (lsmul β β) ΞΌ
Β· exact convolution_mono_right H hfg' hf hg
have : (f β[lsmul β β, ΞΌ] g) x = 0 := integral_undef H
rw [this]
exact integral_nonneg fun y => mul_nonneg (hf y) (hg' (x - y))
variable (L)
theorem convolution_congr [MeasurableAddβ G] [MeasurableNeg G] [SFinite ΞΌ]
[IsAddRightInvariant ΞΌ] (h1 : f =α΅[ΞΌ] f') (h2 : g =α΅[ΞΌ] g') : f β[L, ΞΌ] g = f' β[L, ΞΌ] g' := by
ext x
apply integral_congr_ae
exact (h1.prodMk <| h2.comp_tendsto
(quasiMeasurePreserving_sub_left_of_right_invariant ΞΌ x).tendsto_ae).fun_comp βΏfun x y β¦ L x y
theorem support_convolution_subset_swap : support (f β[L, ΞΌ] g) β support g + support f := by
intro x h2x
by_contra hx
apply h2x
simp_rw [Set.mem_add, β exists_and_left, not_exists, not_and_or, nmem_support] at hx
rw [convolution_def]
convert integral_zero G F using 2
ext t
rcases hx (x - t) t with (h | h | h)
Β· rw [h, (L _).map_zero]
Β· rw [h, L.map_zeroβ]
Β· exact (h <| sub_add_cancel x t).elim
section
variable [MeasurableAddβ G] [MeasurableNeg G] [SFinite ΞΌ] [IsAddRightInvariant ΞΌ]
theorem Integrable.integrable_convolution (hf : Integrable f ΞΌ)
(hg : Integrable g ΞΌ) : Integrable (f β[L, ΞΌ] g) ΞΌ :=
(hf.convolution_integrand L hg).integral_prod_left
end
variable [TopologicalSpace G]
variable [IsTopologicalAddGroup G]
protected theorem _root_.HasCompactSupport.convolution [T2Space G] (hcf : HasCompactSupport f)
(hcg : HasCompactSupport g) : HasCompactSupport (f β[L, ΞΌ] g) :=
(hcg.isCompact.add hcf).of_isClosed_subset isClosed_closure <|
closure_minimal
((support_convolution_subset_swap L).trans <| add_subset_add subset_closure subset_closure)
(hcg.isCompact.add hcf).isClosed
variable [BorelSpace G] [TopologicalSpace P]
/-- The convolution `f * g` is continuous if `f` is locally integrable and `g` is continuous and
compactly supported. Version where `g` depends on an additional parameter in a subset `s` of
a parameter space `P` (and the compact support `k` is independent of the parameter in `s`). -/
theorem continuousOn_convolution_right_with_param {g : P β G β E'} {s : Set P} {k : Set G}
(hk : IsCompact k) (hgs : β p, β x, p β s β x β k β g p x = 0)
(hf : LocallyIntegrable f ΞΌ) (hg : ContinuousOn (βΏg) (s ΓΛ’ univ)) :
ContinuousOn (fun q : P Γ G => (f β[L, ΞΌ] g q.1) q.2) (s ΓΛ’ univ) := by
/- First get rid of the case where the space is not locally compact. Then `g` vanishes everywhere
and the conclusion is trivial. -/
by_cases H : β p β s, β x, g p x = 0
Β· apply (continuousOn_const (c := 0)).congr
rintro β¨p, xβ© β¨hp, -β©
apply integral_eq_zero_of_ae (Eventually.of_forall (fun y β¦ ?_))
simp [H p hp _]
have : LocallyCompactSpace G := by
push_neg at H
rcases H with β¨p, hp, x, hxβ©
have A : support (g p) β k := support_subset_iff'.2 (fun y hy β¦ hgs p y hp hy)
have B : Continuous (g p) := by
refine hg.comp_continuous (.prodMk_right _) fun x => ?_
simpa only [prodMk_mem_set_prod_eq, mem_univ, and_true] using hp
rcases eq_zero_or_locallyCompactSpace_of_support_subset_isCompact_of_addGroup hk A B with H|H
Β· simp [H] at hx
Β· exact H
/- Since `G` is locally compact, one may thicken `k` a little bit into a larger compact set
`(-k) + t`, outside of which all functions that appear in the convolution vanish. Then we can
apply a continuity statement for integrals depending on a parameter, with respect to
locally integrable functions and compactly supported continuous functions. -/
rintro β¨qβ, xββ© β¨hqβ, -β©
obtain β¨t, t_comp, htβ© : β t, IsCompact t β§ t β π xβ := exists_compact_mem_nhds xβ
let k' : Set G := (-k) +α΅₯ t
have k'_comp : IsCompact k' := IsCompact.vadd_set hk.neg t_comp
let g' : (P Γ G) β G β E' := fun p x β¦ g p.1 (p.2 - x)
let s' : Set (P Γ G) := s ΓΛ’ t
have A : ContinuousOn g'.uncurry (s' ΓΛ’ univ) := by
have : g'.uncurry = g.uncurry β (fun w β¦ (w.1.1, w.1.2 - w.2)) := by ext y; rfl
rw [this]
refine hg.comp (by fun_prop) ?_
simp +contextual [s', MapsTo]
have B : ContinuousOn (fun a β¦ β« x, L (f x) (g' a x) βΞΌ) s' := by
apply continuousOn_integral_bilinear_of_locally_integrable_of_compact_support L k'_comp A _
(hf.integrableOn_isCompact k'_comp)
rintro β¨p, xβ© y β¨hp, hxβ© hy
apply hgs p _ hp
contrapose! hy
exact β¨y - x, by simpa using hy, x, hx, by simpβ©
apply ContinuousWithinAt.mono_of_mem_nhdsWithin (B (qβ, xβ) β¨hqβ, mem_of_mem_nhds htβ©)
exact mem_nhdsWithin_prod_iff.2 β¨s, self_mem_nhdsWithin, t, nhdsWithin_le_nhds ht, Subset.rflβ©
/-- The convolution `f * g` is continuous if `f` is locally integrable and `g` is continuous and
compactly supported. Version where `g` depends on an additional parameter in an open subset `s` of
a parameter space `P` (and the compact support `k` is independent of the parameter in `s`),
given in terms of compositions with an additional continuous map. -/
theorem continuousOn_convolution_right_with_param_comp {s : Set P} {v : P β G}
(hv : ContinuousOn v s) {g : P β G β E'} {k : Set G} (hk : IsCompact k)
(hgs : β p, β x, p β s β x β k β g p x = 0) (hf : LocallyIntegrable f ΞΌ)
(hg : ContinuousOn (βΏg) (s ΓΛ’ univ)) : ContinuousOn (fun x => (f β[L, ΞΌ] g x) (v x)) s := by
apply
(continuousOn_convolution_right_with_param L hk hgs hf hg).comp (continuousOn_id.prodMk hv)
intro x hx
simp only [hx, prodMk_mem_set_prod_eq, mem_univ, and_self_iff, _root_.id]
/-- The convolution is continuous if one function is locally integrable and the other has compact
support and is continuous. -/
theorem _root_.HasCompactSupport.continuous_convolution_right (hcg : HasCompactSupport g)
(hf : LocallyIntegrable f ΞΌ) (hg : Continuous g) : Continuous (f β[L, ΞΌ] g) := by
rw [continuous_iff_continuousOn_univ]
let g' : G β G β E' := fun _ q => g q
have : ContinuousOn (βΏg') (univ ΓΛ’ univ) := (hg.comp continuous_snd).continuousOn
exact continuousOn_convolution_right_with_param_comp L
(continuous_iff_continuousOn_univ.1 continuous_id) hcg
(fun p x _ hx => image_eq_zero_of_nmem_tsupport hx) hf this
/-- The convolution is continuous if one function is integrable and the other is bounded and
continuous. -/
theorem _root_.BddAbove.continuous_convolution_right_of_integrable
[FirstCountableTopology G] [SecondCountableTopologyEither G E']
(hbg : BddAbove (range fun x => βg xβ)) (hf : Integrable f ΞΌ) (hg : Continuous g) :
Continuous (f β[L, ΞΌ] g) := by
refine continuous_iff_continuousAt.mpr fun xβ => ?_
have : βαΆ x in π xβ, βα΅ t : G βΞΌ, βL (f t) (g (x - t))β β€ βLβ * βf tβ * β¨ i, βg iβ := by
filter_upwards with x; filter_upwards with t
apply_rules [L.le_of_opNormβ_le_of_le, le_rfl, le_ciSup hbg (x - t)]
refine continuousAt_of_dominated ?_ this ?_ ?_
Β· exact Eventually.of_forall fun x =>
hf.aestronglyMeasurable.convolution_integrand_snd' L hg.aestronglyMeasurable
Β· exact (hf.norm.const_mul _).mul_const _
Β· exact Eventually.of_forall fun t => (L.continuousβ.compβ continuous_const <|
hg.comp <| continuous_id.sub continuous_const).continuousAt
end Group
section CommGroup
variable [AddCommGroup G]
theorem support_convolution_subset : support (f β[L, ΞΌ] g) β support f + support g :=
(support_convolution_subset_swap L).trans (add_comm _ _).subset
variable [IsAddLeftInvariant ΞΌ] [IsNegInvariant ΞΌ]
section Measurable
variable [MeasurableNeg G]
variable [MeasurableAdd G]
/-- Commutativity of convolution -/
theorem convolution_flip : g β[L.flip, ΞΌ] f = f β[L, ΞΌ] g := by
ext1 x
simp_rw [convolution_def]
rw [β integral_sub_left_eq_self _ ΞΌ x]
simp_rw [sub_sub_self, flip_apply]
/-- The symmetric definition of convolution. -/
theorem convolution_eq_swap : (f β[L, ΞΌ] g) x = β« t, L (f (x - t)) (g t) βΞΌ := by
rw [β convolution_flip]; rfl
/-- The symmetric definition of convolution where the bilinear operator is scalar multiplication. -/
theorem convolution_lsmul_swap {f : G β π} {g : G β F} :
(f β[lsmul π π, ΞΌ] g : G β F) x = β« t, f (x - t) β’ g t βΞΌ :=
convolution_eq_swap _
/-- The symmetric definition of convolution where the bilinear operator is multiplication. -/
theorem convolution_mul_swap [NormedSpace β π] {f : G β π} {g : G β π} :
(f β[mul π π, ΞΌ] g) x = β« t, f (x - t) * g t βΞΌ :=
convolution_eq_swap _
/-- The convolution of two even functions is also even. -/
theorem convolution_neg_of_neg_eq (h1 : βα΅ x βΞΌ, f (-x) = f x) (h2 : βα΅ x βΞΌ, g (-x) = g x) :
(f β[L, ΞΌ] g) (-x) = (f β[L, ΞΌ] g) x :=
calc
β« t : G, (L (f t)) (g (-x - t)) βΞΌ = β« t : G, (L (f (-t))) (g (x + t)) βΞΌ := by
apply integral_congr_ae
filter_upwards [h1, (eventually_add_left_iff ΞΌ x).2 h2] with t ht h't
simp_rw [ht, β h't, neg_add']
_ = β« t : G, (L (f t)) (g (x - t)) βΞΌ := by
rw [β integral_neg_eq_self]
simp only [neg_neg, β sub_eq_add_neg]
end Measurable
variable [TopologicalSpace G]
variable [IsTopologicalAddGroup G]
variable [BorelSpace G]
theorem _root_.HasCompactSupport.continuous_convolution_left
(hcf : HasCompactSupport f) (hf : Continuous f) (hg : LocallyIntegrable g ΞΌ) :
Continuous (f β[L, ΞΌ] g) := by
rw [β convolution_flip]
exact hcf.continuous_convolution_right L.flip hg hf
theorem _root_.BddAbove.continuous_convolution_left_of_integrable
[FirstCountableTopology G] [SecondCountableTopologyEither G E]
(hbf : BddAbove (range fun x => βf xβ)) (hf : Continuous f) (hg : Integrable g ΞΌ) :
Continuous (f β[L, ΞΌ] g) := by
rw [β convolution_flip]
exact hbf.continuous_convolution_right_of_integrable L.flip hg hf
end CommGroup
section NormedAddCommGroup
| variable [SeminormedAddCommGroup G]
| Mathlib/Analysis/Convolution.lean | 711 | 712 |
/-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Johannes HΓΆlzl, Kim Morrison, Jens Wagemaker, Johan Commelin
-/
import Mathlib.Algebra.Polynomial.BigOperators
import Mathlib.Algebra.Polynomial.RingDivision
import Mathlib.Data.Set.Finite.Lemmas
import Mathlib.RingTheory.Coprime.Lemmas
import Mathlib.RingTheory.Localization.FractionRing
import Mathlib.SetTheory.Cardinal.Order
/-!
# Theory of univariate polynomials
We define the multiset of roots of a polynomial, and prove basic results about it.
## Main definitions
* `Polynomial.roots p`: The multiset containing all the roots of `p`, including their
multiplicities.
* `Polynomial.rootSet p E`: The set of distinct roots of `p` in an algebra `E`.
## Main statements
* `Polynomial.C_leadingCoeff_mul_prod_multiset_X_sub_C`: If a polynomial has as many roots as its
degree, it can be written as the product of its leading coefficient with `β (X - a)` where `a`
ranges through its roots.
-/
assert_not_exists Ideal
open Multiset Finset
noncomputable section
namespace Polynomial
universe u v w z
variable {R : Type u} {S : Type v} {T : Type w} {a b : R} {n : β}
section CommRing
variable [CommRing R] [IsDomain R] {p q : R[X]}
section Roots
/-- `roots p` noncomputably gives a multiset containing all the roots of `p`,
including their multiplicities. -/
noncomputable def roots (p : R[X]) : Multiset R :=
haveI := Classical.decEq R
haveI := Classical.dec (p = 0)
if h : p = 0 then β
else Classical.choose (exists_multiset_roots h)
theorem roots_def [DecidableEq R] (p : R[X]) [Decidable (p = 0)] :
p.roots = if h : p = 0 then β
else Classical.choose (exists_multiset_roots h) := by
rename_i iR ip0
obtain rfl := Subsingleton.elim iR (Classical.decEq R)
obtain rfl := Subsingleton.elim ip0 (Classical.dec (p = 0))
rfl
@[simp]
theorem roots_zero : (0 : R[X]).roots = 0 :=
dif_pos rfl
theorem card_roots (hp0 : p β 0) : (Multiset.card (roots p) : WithBot β) β€ degree p := by
classical
unfold roots
rw [dif_neg hp0]
exact (Classical.choose_spec (exists_multiset_roots hp0)).1
theorem card_roots' (p : R[X]) : Multiset.card p.roots β€ natDegree p := by
by_cases hp0 : p = 0
Β· simp [hp0]
exact WithBot.coe_le_coe.1 (le_trans (card_roots hp0) (le_of_eq <| degree_eq_natDegree hp0))
theorem card_roots_sub_C {p : R[X]} {a : R} (hp0 : 0 < degree p) :
(Multiset.card (p - C a).roots : WithBot β) β€ degree p :=
calc
(Multiset.card (p - C a).roots : WithBot β) β€ degree (p - C a) :=
card_roots <| mt sub_eq_zero.1 fun h => not_le_of_gt hp0 <| h.symm βΈ degree_C_le
_ = degree p := by rw [sub_eq_add_neg, β C_neg]; exact degree_add_C hp0
theorem card_roots_sub_C' {p : R[X]} {a : R} (hp0 : 0 < degree p) :
Multiset.card (p - C a).roots β€ natDegree p :=
WithBot.coe_le_coe.1
(le_trans (card_roots_sub_C hp0)
(le_of_eq <| degree_eq_natDegree fun h => by simp_all [lt_irrefl]))
@[simp]
theorem count_roots [DecidableEq R] (p : R[X]) : p.roots.count a = rootMultiplicity a p := by
classical
by_cases hp : p = 0
Β· simp [hp]
rw [roots_def, dif_neg hp]
exact (Classical.choose_spec (exists_multiset_roots hp)).2 a
@[simp]
theorem mem_roots' : a β p.roots β p β 0 β§ IsRoot p a := by
classical
rw [β count_pos, count_roots p, rootMultiplicity_pos']
theorem mem_roots (hp : p β 0) : a β p.roots β IsRoot p a :=
mem_roots'.trans <| and_iff_right hp
theorem ne_zero_of_mem_roots (h : a β p.roots) : p β 0 :=
(mem_roots'.1 h).1
theorem isRoot_of_mem_roots (h : a β p.roots) : IsRoot p a :=
(mem_roots'.1 h).2
theorem mem_roots_map_of_injective [Semiring S] {p : S[X]} {f : S β+* R}
(hf : Function.Injective f) {x : R} (hp : p β 0) : x β (p.map f).roots β p.evalβ f x = 0 := by
rw [mem_roots ((Polynomial.map_ne_zero_iff hf).mpr hp), IsRoot, eval_map]
lemma mem_roots_iff_aeval_eq_zero {x : R} (w : p β 0) : x β roots p β aeval x p = 0 := by
rw [aeval_def, β mem_roots_map_of_injective (FaithfulSMul.algebraMap_injective _ _) w,
Algebra.id.map_eq_id, map_id]
theorem card_le_degree_of_subset_roots {p : R[X]} {Z : Finset R} (h : Z.val β p.roots) :
#Z β€ p.natDegree :=
(Multiset.card_le_card (Finset.val_le_iff_val_subset.2 h)).trans (Polynomial.card_roots' p)
theorem finite_setOf_isRoot {p : R[X]} (hp : p β 0) : Set.Finite { x | IsRoot p x } := by
classical
simpa only [β Finset.setOf_mem, Multiset.mem_toFinset, mem_roots hp]
using p.roots.toFinset.finite_toSet
theorem eq_zero_of_infinite_isRoot (p : R[X]) (h : Set.Infinite { x | IsRoot p x }) : p = 0 :=
not_imp_comm.mp finite_setOf_isRoot h
theorem exists_max_root [LinearOrder R] (p : R[X]) (hp : p β 0) : β xβ, β x, p.IsRoot x β x β€ xβ :=
Set.exists_upper_bound_image _ _ <| finite_setOf_isRoot hp
theorem exists_min_root [LinearOrder R] (p : R[X]) (hp : p β 0) : β xβ, β x, p.IsRoot x β xβ β€ x :=
Set.exists_lower_bound_image _ _ <| finite_setOf_isRoot hp
theorem eq_of_infinite_eval_eq (p q : R[X]) (h : Set.Infinite { x | eval x p = eval x q }) :
p = q := by
rw [β sub_eq_zero]
apply eq_zero_of_infinite_isRoot
simpa only [IsRoot, eval_sub, sub_eq_zero]
theorem roots_mul {p q : R[X]} (hpq : p * q β 0) : (p * q).roots = p.roots + q.roots := by
classical
exact Multiset.ext.mpr fun r => by
rw [count_add, count_roots, count_roots, count_roots, rootMultiplicity_mul hpq]
theorem roots.le_of_dvd (h : q β 0) : p β£ q β roots p β€ roots q := by
rintro β¨k, rflβ©
exact Multiset.le_iff_exists_add.mpr β¨k.roots, roots_mul hβ©
theorem mem_roots_sub_C' {p : R[X]} {a x : R} : x β (p - C a).roots β p β C a β§ p.eval x = a := by
rw [mem_roots', IsRoot.def, sub_ne_zero, eval_sub, sub_eq_zero, eval_C]
theorem mem_roots_sub_C {p : R[X]} {a x : R} (hp0 : 0 < degree p) :
x β (p - C a).roots β p.eval x = a :=
mem_roots_sub_C'.trans <| and_iff_right fun hp => hp0.not_le <| hp.symm βΈ degree_C_le
@[simp]
theorem roots_X_sub_C (r : R) : roots (X - C r) = {r} := by
classical
ext s
rw [count_roots, rootMultiplicity_X_sub_C, count_singleton]
@[simp]
theorem roots_X_add_C (r : R) : roots (X + C r) = {-r} := by simpa using roots_X_sub_C (-r)
@[simp]
theorem roots_X : roots (X : R[X]) = {0} := by rw [β roots_X_sub_C, C_0, sub_zero]
@[simp]
theorem roots_C (x : R) : (C x).roots = 0 := by
classical exact
if H : x = 0 then by rw [H, C_0, roots_zero]
else
Multiset.ext.mpr fun r => (by
rw [count_roots, count_zero, rootMultiplicity_eq_zero (not_isRoot_C _ _ H)])
@[simp]
theorem roots_one : (1 : R[X]).roots = β
:=
roots_C 1
@[simp]
theorem roots_C_mul (p : R[X]) (ha : a β 0) : (C a * p).roots = p.roots := by
by_cases hp : p = 0 <;>
simp only [roots_mul, *, Ne, mul_eq_zero, C_eq_zero, or_self_iff, not_false_iff, roots_C,
zero_add, mul_zero]
@[simp]
theorem roots_smul_nonzero (p : R[X]) (ha : a β 0) : (a β’ p).roots = p.roots := by
rw [smul_eq_C_mul, roots_C_mul _ ha]
@[simp]
lemma roots_neg (p : R[X]) : (-p).roots = p.roots := by
rw [β neg_one_smul R p, roots_smul_nonzero p (neg_ne_zero.mpr one_ne_zero)]
@[simp]
theorem roots_C_mul_X_sub_C_of_IsUnit (b : R) (a : RΛ£) : (C (a : R) * X - C b).roots =
{aβ»ΒΉ * b} := by
rw [β roots_C_mul _ (Units.ne_zero aβ»ΒΉ), mul_sub, β mul_assoc, β C_mul, β C_mul,
Units.inv_mul, C_1, one_mul]
exact roots_X_sub_C (aβ»ΒΉ * b)
@[simp]
theorem roots_C_mul_X_add_C_of_IsUnit (b : R) (a : RΛ£) : (C (a : R) * X + C b).roots =
{-(aβ»ΒΉ * b)} := by
rw [β sub_neg_eq_add, β C_neg, roots_C_mul_X_sub_C_of_IsUnit, mul_neg]
theorem roots_list_prod (L : List R[X]) :
(0 : R[X]) β L β L.prod.roots = (L : Multiset R[X]).bind roots :=
List.recOn L (fun _ => roots_one) fun hd tl ih H => by
rw [List.mem_cons, not_or] at H
rw [List.prod_cons, roots_mul (mul_ne_zero (Ne.symm H.1) <| List.prod_ne_zero H.2), β
Multiset.cons_coe, Multiset.cons_bind, ih H.2]
theorem roots_multiset_prod (m : Multiset R[X]) : (0 : R[X]) β m β m.prod.roots = m.bind roots := by
rcases m with β¨Lβ©
simpa only [Multiset.prod_coe, quot_mk_to_coe''] using roots_list_prod L
theorem roots_prod {ΞΉ : Type*} (f : ΞΉ β R[X]) (s : Finset ΞΉ) :
s.prod f β 0 β (s.prod f).roots = s.val.bind fun i => roots (f i) := by
rcases s with β¨m, hmβ©
simpa [Multiset.prod_eq_zero_iff, Multiset.bind_map] using roots_multiset_prod (m.map f)
@[simp]
theorem roots_pow (p : R[X]) (n : β) : (p ^ n).roots = n β’ p.roots := by
induction n with
| zero => rw [pow_zero, roots_one, zero_smul, empty_eq_zero]
| succ n ihn =>
rcases eq_or_ne p 0 with (rfl | hp)
Β· rw [zero_pow n.succ_ne_zero, roots_zero, smul_zero]
Β· rw [pow_succ, roots_mul (mul_ne_zero (pow_ne_zero _ hp) hp), ihn, add_smul, one_smul]
theorem roots_X_pow (n : β) : (X ^ n : R[X]).roots = n β’ ({0} : Multiset R) := by
rw [roots_pow, roots_X]
theorem roots_C_mul_X_pow (ha : a β 0) (n : β) :
Polynomial.roots (C a * X ^ n) = n β’ ({0} : Multiset R) := by
rw [roots_C_mul _ ha, roots_X_pow]
@[simp]
theorem roots_monomial (ha : a β 0) (n : β) : (monomial n a).roots = n β’ ({0} : Multiset R) := by
rw [β C_mul_X_pow_eq_monomial, roots_C_mul_X_pow ha]
theorem roots_prod_X_sub_C (s : Finset R) : (s.prod fun a => X - C a).roots = s.val := by
apply (roots_prod (fun a => X - C a) s ?_).trans
Β· simp_rw [roots_X_sub_C]
rw [Multiset.bind_singleton, Multiset.map_id']
Β· refine prod_ne_zero_iff.mpr (fun a _ => X_sub_C_ne_zero a)
@[simp]
theorem roots_multiset_prod_X_sub_C (s : Multiset R) : (s.map fun a => X - C a).prod.roots = s := by
rw [roots_multiset_prod, Multiset.bind_map]
Β· simp_rw [roots_X_sub_C]
rw [Multiset.bind_singleton, Multiset.map_id']
Β· rw [Multiset.mem_map]
rintro β¨a, -, hβ©
exact X_sub_C_ne_zero a h
theorem card_roots_X_pow_sub_C {n : β} (hn : 0 < n) (a : R) :
Multiset.card (roots ((X : R[X]) ^ n - C a)) β€ n :=
WithBot.coe_le_coe.1 <|
calc
(Multiset.card (roots ((X : R[X]) ^ n - C a)) : WithBot β) β€ degree ((X : R[X]) ^ n - C a) :=
card_roots (X_pow_sub_C_ne_zero hn a)
_ = n := degree_X_pow_sub_C hn a
section NthRoots
/-- `nthRoots n a` noncomputably returns the solutions to `x ^ n = a`. -/
def nthRoots (n : β) (a : R) : Multiset R :=
roots ((X : R[X]) ^ n - C a)
@[simp]
theorem mem_nthRoots {n : β} (hn : 0 < n) {a x : R} : x β nthRoots n a β x ^ n = a := by
rw [nthRoots, mem_roots (X_pow_sub_C_ne_zero hn a), IsRoot.def, eval_sub, eval_C, eval_pow,
eval_X, sub_eq_zero]
@[simp]
theorem nthRoots_zero (r : R) : nthRoots 0 r = 0 := by
simp only [empty_eq_zero, pow_zero, nthRoots, β C_1, β C_sub, roots_C]
@[simp]
theorem nthRoots_zero_right {R} [CommRing R] [IsDomain R] (n : β) :
nthRoots n (0 : R) = Multiset.replicate n 0 := by
rw [nthRoots, C.map_zero, sub_zero, roots_pow, roots_X, Multiset.nsmul_singleton]
theorem card_nthRoots (n : β) (a : R) : Multiset.card (nthRoots n a) β€ n := by
classical exact
(if hn : n = 0 then
if h : (X : R[X]) ^ n - C a = 0 then by
simp [Nat.zero_le, nthRoots, roots, h, dif_pos rfl, empty_eq_zero, Multiset.card_zero]
else
WithBot.coe_le_coe.1
(le_trans (card_roots h)
(by
rw [hn, pow_zero, β C_1, β RingHom.map_sub]
exact degree_C_le))
else by
rw [β Nat.cast_le (Ξ± := WithBot β)]
rw [β degree_X_pow_sub_C (Nat.pos_of_ne_zero hn) a]
exact card_roots (X_pow_sub_C_ne_zero (Nat.pos_of_ne_zero hn) a))
@[simp]
theorem nthRoots_two_eq_zero_iff {r : R} : nthRoots 2 r = 0 β Β¬IsSquare r := by
simp_rw [isSquare_iff_exists_sq, eq_zero_iff_forall_not_mem, mem_nthRoots (by norm_num : 0 < 2),
β not_exists, eq_comm]
/-- The multiset `nthRoots βn a` as a Finset. Previously `nthRootsFinset n` was defined to be
`nthRoots n (1 : R)` as a Finset. That situation can be recovered by setting `a` to be `(1 : R)` -/
def nthRootsFinset (n : β) {R : Type*} (a : R) [CommRing R] [IsDomain R] : Finset R :=
haveI := Classical.decEq R
Multiset.toFinset (nthRoots n a)
lemma nthRootsFinset_def (n : β) {R : Type*} (a : R) [CommRing R] [IsDomain R] [DecidableEq R] :
nthRootsFinset n a = Multiset.toFinset (nthRoots n a) := by
unfold nthRootsFinset
convert rfl
@[simp]
theorem mem_nthRootsFinset {n : β} (h : 0 < n) (a : R) {x : R} :
x β nthRootsFinset n a β x ^ (n : β) = a := by
classical
rw [nthRootsFinset_def, mem_toFinset, mem_nthRoots h]
@[simp]
theorem nthRootsFinset_zero (a : R) : nthRootsFinset 0 a = β
:= by
classical simp [nthRootsFinset_def]
theorem map_mem_nthRootsFinset {S F : Type*} [CommRing S] [IsDomain S] [FunLike F R S]
[MonoidHomClass F R S] {a : R} {x : R} (hx : x β nthRootsFinset n a) (f : F) :
f x β nthRootsFinset n (f a) := by
by_cases hn : n = 0
Β· simp [hn] at hx
Β· rw [mem_nthRootsFinset <| Nat.pos_of_ne_zero hn, β map_pow, (mem_nthRootsFinset
(Nat.pos_of_ne_zero hn) a).1 hx]
theorem map_mem_nthRootsFinset_one {S F : Type*} [CommRing S] [IsDomain S] [FunLike F R S]
[RingHomClass F R S] {x : R} (hx : x β nthRootsFinset n 1) (f : F) :
f x β nthRootsFinset n 1 := by
rw [β (map_one f)]
exact map_mem_nthRootsFinset hx _
theorem mul_mem_nthRootsFinset
{Ξ·β Ξ·β : R} {aβ aβ : R} (hΞ·β : Ξ·β β nthRootsFinset n aβ) (hΞ·β : Ξ·β β nthRootsFinset n aβ) :
Ξ·β * Ξ·β β nthRootsFinset n (aβ * aβ) := by
cases n with
| zero =>
simp only [nthRootsFinset_zero, not_mem_empty] at hΞ·β
| succ n =>
rw [mem_nthRootsFinset n.succ_pos] at hΞ·β hΞ·β β’
rw [mul_pow, hΞ·β, hΞ·β]
theorem ne_zero_of_mem_nthRootsFinset {Ξ· : R} {a : R} (ha : a β 0) (hΞ· : Ξ· β nthRootsFinset n a) :
Ξ· β 0 := by
nontriviality R
rintro rfl
cases n with
| zero =>
simp only [nthRootsFinset_zero, not_mem_empty] at hΞ·
| succ n =>
rw [mem_nthRootsFinset n.succ_pos, zero_pow n.succ_ne_zero] at hΞ·
exact ha hΞ·.symm
theorem one_mem_nthRootsFinset (hn : 0 < n) : 1 β nthRootsFinset n (1 : R) := by
rw [mem_nthRootsFinset hn, one_pow]
end NthRoots
theorem zero_of_eval_zero [Infinite R] (p : R[X]) (h : β x, p.eval x = 0) : p = 0 := by
classical
by_contra hp
refine @Fintype.false R _ ?_
exact β¨p.roots.toFinset, fun x => Multiset.mem_toFinset.mpr ((mem_roots hp).mpr (h _))β©
theorem funext [Infinite R] {p q : R[X]} (ext : β r : R, p.eval r = q.eval r) : p = q := by
rw [β sub_eq_zero]
apply zero_of_eval_zero
intro x
rw [eval_sub, sub_eq_zero, ext]
variable [CommRing T]
/-- Given a polynomial `p` with coefficients in a ring `T` and a `T`-algebra `S`, `aroots p S` is
the multiset of roots of `p` regarded as a polynomial over `S`. -/
noncomputable abbrev aroots (p : T[X]) (S) [CommRing S] [IsDomain S] [Algebra T S] : Multiset S :=
(p.map (algebraMap T S)).roots
theorem aroots_def (p : T[X]) (S) [CommRing S] [IsDomain S] [Algebra T S] :
p.aroots S = (p.map (algebraMap T S)).roots :=
rfl
theorem mem_aroots' [CommRing S] [IsDomain S] [Algebra T S] {p : T[X]} {a : S} :
a β p.aroots S β p.map (algebraMap T S) β 0 β§ aeval a p = 0 := by
rw [mem_roots', IsRoot.def, β evalβ_eq_eval_map, aeval_def]
theorem mem_aroots [CommRing S] [IsDomain S] [Algebra T S]
[NoZeroSMulDivisors T S] {p : T[X]} {a : S} : a β p.aroots S β p β 0 β§ aeval a p = 0 := by
rw [mem_aroots', Polynomial.map_ne_zero_iff]
exact FaithfulSMul.algebraMap_injective T S
theorem aroots_mul [CommRing S] [IsDomain S] [Algebra T S]
[NoZeroSMulDivisors T S] {p q : T[X]} (hpq : p * q β 0) :
(p * q).aroots S = p.aroots S + q.aroots S := by
suffices map (algebraMap T S) p * map (algebraMap T S) q β 0 by
rw [aroots_def, Polynomial.map_mul, roots_mul this]
rwa [β Polynomial.map_mul, Polynomial.map_ne_zero_iff
(FaithfulSMul.algebraMap_injective T S)]
@[simp]
theorem aroots_X_sub_C [CommRing S] [IsDomain S] [Algebra T S]
(r : T) : aroots (X - C r) S = {algebraMap T S r} := by
rw [aroots_def, Polynomial.map_sub, map_X, map_C, roots_X_sub_C]
@[simp]
theorem aroots_X [CommRing S] [IsDomain S] [Algebra T S] :
aroots (X : T[X]) S = {0} := by
rw [aroots_def, map_X, roots_X]
@[simp]
theorem aroots_C [CommRing S] [IsDomain S] [Algebra T S] (a : T) : (C a).aroots S = 0 := by
rw [aroots_def, map_C, roots_C]
@[simp]
theorem aroots_zero (S) [CommRing S] [IsDomain S] [Algebra T S] : (0 : T[X]).aroots S = 0 := by
rw [β C_0, aroots_C]
@[simp]
theorem aroots_one [CommRing S] [IsDomain S] [Algebra T S] :
(1 : T[X]).aroots S = 0 :=
aroots_C 1
@[simp]
theorem aroots_neg [CommRing S] [IsDomain S] [Algebra T S] (p : T[X]) :
(-p).aroots S = p.aroots S := by
rw [aroots, Polynomial.map_neg, roots_neg]
@[simp]
theorem aroots_C_mul [CommRing S] [IsDomain S] [Algebra T S]
[NoZeroSMulDivisors T S] {a : T} (p : T[X]) (ha : a β 0) :
(C a * p).aroots S = p.aroots S := by
rw [aroots_def, Polynomial.map_mul, map_C, roots_C_mul]
rwa [map_ne_zero_iff]
exact FaithfulSMul.algebraMap_injective T S
@[simp]
theorem aroots_smul_nonzero [CommRing S] [IsDomain S] [Algebra T S]
[NoZeroSMulDivisors T S] {a : T} (p : T[X]) (ha : a β 0) :
(a β’ p).aroots S = p.aroots S := by
rw [smul_eq_C_mul, aroots_C_mul _ ha]
@[simp]
theorem aroots_pow [CommRing S] [IsDomain S] [Algebra T S] (p : T[X]) (n : β) :
(p ^ n).aroots S = n β’ p.aroots S := by
rw [aroots_def, Polynomial.map_pow, roots_pow]
theorem aroots_X_pow [CommRing S] [IsDomain S] [Algebra T S] (n : β) :
(X ^ n : T[X]).aroots S = n β’ ({0} : Multiset S) := by
rw [aroots_pow, aroots_X]
theorem aroots_C_mul_X_pow [CommRing S] [IsDomain S] [Algebra T S]
[NoZeroSMulDivisors T S] {a : T} (ha : a β 0) (n : β) :
(C a * X ^ n : T[X]).aroots S = n β’ ({0} : Multiset S) := by
rw [aroots_C_mul _ ha, aroots_X_pow]
@[simp]
theorem aroots_monomial [CommRing S] [IsDomain S] [Algebra T S]
[NoZeroSMulDivisors T S] {a : T} (ha : a β 0) (n : β) :
(monomial n a).aroots S = n β’ ({0} : Multiset S) := by
rw [β C_mul_X_pow_eq_monomial, aroots_C_mul_X_pow ha]
variable (R S) in
@[simp]
theorem aroots_map (p : T[X]) [CommRing S] [Algebra T S] [Algebra S R] [Algebra T R]
[IsScalarTower T S R] :
(p.map (algebraMap T S)).aroots R = p.aroots R := by
rw [aroots_def, aroots_def, map_map, IsScalarTower.algebraMap_eq T S R]
/-- The set of distinct roots of `p` in `S`.
If you have a non-separable polynomial, use `Polynomial.aroots` for the multiset
where multiple roots have the appropriate multiplicity. -/
def rootSet (p : T[X]) (S) [CommRing S] [IsDomain S] [Algebra T S] : Set S :=
haveI := Classical.decEq S
(p.aroots S).toFinset
theorem rootSet_def (p : T[X]) (S) [CommRing S] [IsDomain S] [Algebra T S] [DecidableEq S] :
p.rootSet S = (p.aroots S).toFinset := by
rw [rootSet]
convert rfl
@[simp]
theorem rootSet_C [CommRing S] [IsDomain S] [Algebra T S] (a : T) : (C a).rootSet S = β
:= by
classical
rw [rootSet_def, aroots_C, Multiset.toFinset_zero, Finset.coe_empty]
@[simp]
theorem rootSet_zero (S) [CommRing S] [IsDomain S] [Algebra T S] : (0 : T[X]).rootSet S = β
:= by
rw [β C_0, rootSet_C]
@[simp]
theorem rootSet_one (S) [CommRing S] [IsDomain S] [Algebra T S] : (1 : T[X]).rootSet S = β
:= by
rw [β C_1, rootSet_C]
@[simp]
theorem rootSet_neg (p : T[X]) (S) [CommRing S] [IsDomain S] [Algebra T S] :
(-p).rootSet S = p.rootSet S := by
rw [rootSet, aroots_neg, rootSet]
instance rootSetFintype (p : T[X]) (S : Type*) [CommRing S] [IsDomain S] [Algebra T S] :
Fintype (p.rootSet S) :=
FinsetCoe.fintype _
theorem rootSet_finite (p : T[X]) (S : Type*) [CommRing S] [IsDomain S] [Algebra T S] :
(p.rootSet S).Finite :=
Set.toFinite _
/-- The set of roots of all polynomials of bounded degree and having coefficients in a finite set
is finite. -/
theorem bUnion_roots_finite {R S : Type*} [Semiring R] [CommRing S] [IsDomain S] [DecidableEq S]
(m : R β+* S) (d : β) {U : Set R} (h : U.Finite) :
(β (f : R[X]) (_ : f.natDegree β€ d β§ β i, f.coeff i β U),
((f.map m).roots.toFinset.toSet : Set S)).Finite :=
Set.Finite.biUnion
(by
-- We prove that the set of polynomials under consideration is finite because its
-- image by the injective map `Ο` is finite
let Ο : R[X] β Fin (d + 1) β R := fun f i => f.coeff i
refine ((Set.Finite.pi fun _ => h).subset <| ?_).of_finite_image (?_ : Set.InjOn Ο _)
Β· exact Set.image_subset_iff.2 fun f hf i _ => hf.2 i
Β· refine fun x hx y hy hxy => (ext_iff_natDegree_le hx.1 hy.1).2 fun i hi => ?_
exact id congr_fun hxy β¨i, Nat.lt_succ_of_le hiβ©)
fun _ _ => Finset.finite_toSet _
theorem mem_rootSet' {p : T[X]} {S : Type*} [CommRing S] [IsDomain S] [Algebra T S] {a : S} :
a β p.rootSet S β p.map (algebraMap T S) β 0 β§ aeval a p = 0 := by
classical
rw [rootSet_def, Finset.mem_coe, mem_toFinset, mem_aroots']
theorem mem_rootSet {p : T[X]} {S : Type*} [CommRing S] [IsDomain S] [Algebra T S]
[NoZeroSMulDivisors T S] {a : S} : a β p.rootSet S β p β 0 β§ aeval a p = 0 := by
rw [mem_rootSet', Polynomial.map_ne_zero_iff (FaithfulSMul.algebraMap_injective T S)]
theorem mem_rootSet_of_ne {p : T[X]} {S : Type*} [CommRing S] [IsDomain S] [Algebra T S]
[NoZeroSMulDivisors T S] (hp : p β 0) {a : S} : a β p.rootSet S β aeval a p = 0 :=
mem_rootSet.trans <| and_iff_right hp
theorem rootSet_maps_to' {p : T[X]} {S S'} [CommRing S] [IsDomain S] [Algebra T S] [CommRing S']
[IsDomain S'] [Algebra T S'] (hp : p.map (algebraMap T S') = 0 β p.map (algebraMap T S) = 0)
(f : S ββ[T] S') : (p.rootSet S).MapsTo f (p.rootSet S') := fun x hx => by
rw [mem_rootSet'] at hx β’
rw [aeval_algHom, AlgHom.comp_apply, hx.2, _root_.map_zero]
exact β¨mt hp hx.1, rflβ©
theorem ne_zero_of_mem_rootSet {p : T[X]} [CommRing S] [IsDomain S] [Algebra T S] {a : S}
(h : a β p.rootSet S) : p β 0 := fun hf => by rwa [hf, rootSet_zero] at h
theorem aeval_eq_zero_of_mem_rootSet {p : T[X]} [CommRing S] [IsDomain S] [Algebra T S] {a : S}
(hx : a β p.rootSet S) : aeval a p = 0 :=
(mem_rootSet'.1 hx).2
theorem rootSet_mapsTo {p : T[X]} {S S'} [CommRing S] [IsDomain S] [Algebra T S] [CommRing S']
[IsDomain S'] [Algebra T S'] [NoZeroSMulDivisors T S'] (f : S ββ[T] S') :
(p.rootSet S).MapsTo f (p.rootSet S') := by
refine rootSet_maps_to' (fun hβ => ?_) f
obtain rfl : p = 0 :=
map_injective _ (FaithfulSMul.algebraMap_injective T S') (by rwa [Polynomial.map_zero])
exact Polynomial.map_zero _
theorem mem_rootSet_of_injective [CommRing S] {p : S[X]} [Algebra S R]
(h : Function.Injective (algebraMap S R)) {x : R} (hp : p β 0) :
x β p.rootSet R β aeval x p = 0 := by
classical
exact Multiset.mem_toFinset.trans (mem_roots_map_of_injective h hp)
end Roots
lemma eq_zero_of_natDegree_lt_card_of_eval_eq_zero {R} [CommRing R] [IsDomain R]
(p : R[X]) {ΞΉ} [Fintype ΞΉ] {f : ΞΉ β R} (hf : Function.Injective f)
(heval : β i, p.eval (f i) = 0) (hcard : natDegree p < Fintype.card ΞΉ) : p = 0 := by
classical
by_contra hp
refine lt_irrefl #p.roots.toFinset ?_
calc
#p.roots.toFinset β€ Multiset.card p.roots := Multiset.toFinset_card_le _
_ β€ natDegree p := Polynomial.card_roots' p
_ < Fintype.card ΞΉ := hcard
_ = Fintype.card (Set.range f) := (Set.card_range_of_injective hf).symm
_ = #(Finset.univ.image f) := by rw [β Set.toFinset_card, Set.toFinset_range]
_ β€ #p.roots.toFinset := Finset.card_mono ?_
intro _
simp only [Finset.mem_image, Finset.mem_univ, true_and, Multiset.mem_toFinset, mem_roots', ne_eq,
IsRoot.def, forall_exists_index, hp, not_false_eq_true]
rintro x rfl
exact heval _
lemma eq_zero_of_natDegree_lt_card_of_eval_eq_zero' {R} [CommRing R] [IsDomain R]
(p : R[X]) (s : Finset R) (heval : β i β s, p.eval i = 0) (hcard : natDegree p < #s) :
p = 0 :=
eq_zero_of_natDegree_lt_card_of_eval_eq_zero p Subtype.val_injective
(fun i : s β¦ heval i i.prop) (hcard.trans_eq (Fintype.card_coe s).symm)
open Cardinal in
lemma eq_zero_of_forall_eval_zero_of_natDegree_lt_card
(f : R[X]) (hf : β r, f.eval r = 0) (hfR : f.natDegree < #R) : f = 0 := by
obtain hR|hR := finite_or_infinite R
Β· have := Fintype.ofFinite R
apply eq_zero_of_natDegree_lt_card_of_eval_eq_zero f Function.injective_id hf
simpa only [mk_fintype, Nat.cast_lt] using hfR
Β· exact zero_of_eval_zero _ hf
open Cardinal in
lemma exists_eval_ne_zero_of_natDegree_lt_card (f : R[X]) (hf : f β 0) (hfR : f.natDegree < #R) :
β r, f.eval r β 0 := by
contrapose! hf
exact eq_zero_of_forall_eval_zero_of_natDegree_lt_card f hf hfR
section
omit [IsDomain R]
theorem monic_multisetProd_X_sub_C (s : Multiset R) : Monic (s.map fun a => X - C a).prod :=
monic_multiset_prod_of_monic _ _ fun a _ => monic_X_sub_C a
theorem monic_prod_X_sub_C {Ξ± : Type*} (b : Ξ± β R) (s : Finset Ξ±) :
Monic (β a β s, (X - C (b a))) :=
monic_prod_of_monic _ _ fun a _ => monic_X_sub_C (b a)
theorem monic_finprod_X_sub_C {Ξ± : Type*} (b : Ξ± β R) : Monic (βαΆ k, (X - C (b k))) :=
monic_finprod_of_monic _ _ fun a _ => monic_X_sub_C (b a)
end
theorem prod_multiset_root_eq_finset_root [DecidableEq R] :
(p.roots.map fun a => X - C a).prod =
p.roots.toFinset.prod fun a => (X - C a) ^ rootMultiplicity a p := by
simp only [count_roots, Finset.prod_multiset_map_count]
/-- The product `β (X - a)` for `a` inside the multiset `p.roots` divides `p`. -/
theorem prod_multiset_X_sub_C_dvd (p : R[X]) : (p.roots.map fun a => X - C a).prod β£ p := by
classical
rw [β map_dvd_map _ (IsFractionRing.injective R <| FractionRing R)
(monic_multisetProd_X_sub_C p.roots)]
rw [prod_multiset_root_eq_finset_root, Polynomial.map_prod]
refine Finset.prod_dvd_of_coprime (fun a _ b _ h => ?_) fun a _ => ?_
Β· simp_rw [Polynomial.map_pow, Polynomial.map_sub, map_C, map_X]
exact (pairwise_coprime_X_sub_C (IsFractionRing.injective R <| FractionRing R) h).pow
Β· exact Polynomial.map_dvd _ (pow_rootMultiplicity_dvd p a)
/-- A Galois connection. -/
theorem _root_.Multiset.prod_X_sub_C_dvd_iff_le_roots {p : R[X]} (hp : p β 0) (s : Multiset R) :
(s.map fun a => X - C a).prod β£ p β s β€ p.roots := by
classical exact
β¨fun h =>
Multiset.le_iff_count.2 fun r => by
rw [count_roots, le_rootMultiplicity_iff hp, β Multiset.prod_replicate, β
Multiset.map_replicate fun a => X - C a, β Multiset.filter_eq]
exact (Multiset.prod_dvd_prod_of_le <| Multiset.map_le_map <| s.filter_le _).trans h,
fun h =>
(Multiset.prod_dvd_prod_of_le <| Multiset.map_le_map h).trans p.prod_multiset_X_sub_C_dvdβ©
theorem exists_prod_multiset_X_sub_C_mul (p : R[X]) :
β q,
(p.roots.map fun a => X - C a).prod * q = p β§
Multiset.card p.roots + q.natDegree = p.natDegree β§ q.roots = 0 := by
obtain β¨q, heβ© := p.prod_multiset_X_sub_C_dvd
use q, he.symm
obtain rfl | hq := eq_or_ne q 0
Β· rw [mul_zero] at he
subst he
simp
constructor
Β· conv_rhs => rw [he]
rw [(monic_multisetProd_X_sub_C p.roots).natDegree_mul' hq,
natDegree_multiset_prod_X_sub_C_eq_card]
Β· replace he := congr_arg roots he.symm
rw [roots_mul, roots_multiset_prod_X_sub_C] at he
exacts [add_eq_left.1 he, mul_ne_zero (monic_multisetProd_X_sub_C p.roots).ne_zero hq]
/-- A polynomial `p` that has as many roots as its degree
can be written `p = p.leadingCoeff * β(X - a)`, for `a` in `p.roots`. -/
theorem C_leadingCoeff_mul_prod_multiset_X_sub_C (hroots : Multiset.card p.roots = p.natDegree) :
C p.leadingCoeff * (p.roots.map fun a => X - C a).prod = p :=
(eq_leadingCoeff_mul_of_monic_of_dvd_of_natDegree_le (monic_multisetProd_X_sub_C p.roots)
p.prod_multiset_X_sub_C_dvd
((natDegree_multiset_prod_X_sub_C_eq_card _).trans hroots).ge).symm
/-- A monic polynomial `p` that has as many roots as its degree
can be written `p = β(X - a)`, for `a` in `p.roots`. -/
theorem prod_multiset_X_sub_C_of_monic_of_roots_card_eq (hp : p.Monic)
(hroots : Multiset.card p.roots = p.natDegree) : (p.roots.map fun a => X - C a).prod = p := by
convert C_leadingCoeff_mul_prod_multiset_X_sub_C hroots
rw [hp.leadingCoeff, C_1, one_mul]
theorem Monic.isUnit_leadingCoeff_of_dvd {a p : R[X]} (hp : Monic p) (hap : a β£ p) :
IsUnit a.leadingCoeff :=
isUnit_of_dvd_one (by simpa only [hp.leadingCoeff] using leadingCoeff_dvd_leadingCoeff hap)
/-- To check a monic polynomial is irreducible, it suffices to check only for
divisors that have smaller degree.
See also: `Polynomial.Monic.irreducible_iff_natDegree`.
-/
theorem Monic.irreducible_iff_degree_lt {p : R[X]} (p_monic : Monic p) (p_1 : p β 1) :
Irreducible p β β q, degree q β€ β(p.natDegree / 2) β q β£ p β IsUnit q := by
simp only [p_monic.irreducible_iff_lt_natDegree_lt p_1, Finset.mem_Ioc, and_imp,
natDegree_pos_iff_degree_pos, natDegree_le_iff_degree_le]
constructor
Β· rintro h q deg_le dvd
by_contra q_unit
have := degree_pos_of_not_isUnit_of_dvd_monic p_monic q_unit dvd
have hu := p_monic.isUnit_leadingCoeff_of_dvd dvd
refine (h _ (monic_of_isUnit_leadingCoeff_inv_smul hu) ?_ ?_ (dvd_trans ?_ dvd)).elim
Β· rwa [degree_smul_of_smul_regular _ (isSMulRegular_of_group _)]
Β· rwa [degree_smul_of_smul_regular _ (isSMulRegular_of_group _)]
Β· rw [Units.smul_def, Polynomial.smul_eq_C_mul, (isUnit_C.mpr (Units.isUnit _)).mul_left_dvd]
Β· rintro h q _ deg_pos deg_le dvd
exact deg_pos.ne' <| degree_eq_zero_of_isUnit (h q deg_le dvd)
end CommRing
section
variable {A B : Type*} [CommRing A] [CommRing B]
theorem le_rootMultiplicity_map {p : A[X]} {f : A β+* B} (hmap : map f p β 0) (a : A) :
rootMultiplicity a p β€ rootMultiplicity (f a) (p.map f) := by
rw [le_rootMultiplicity_iff hmap]
refine _root_.trans ?_ ((mapRingHom f).map_dvd (pow_rootMultiplicity_dvd p a))
rw [map_pow, map_sub, coe_mapRingHom, map_X, map_C]
theorem eq_rootMultiplicity_map {p : A[X]} {f : A β+* B} (hf : Function.Injective f) (a : A) :
rootMultiplicity a p = rootMultiplicity (f a) (p.map f) := by
by_cases hp0 : p = 0; Β· simp only [hp0, rootMultiplicity_zero, Polynomial.map_zero]
apply le_antisymm (le_rootMultiplicity_map ((Polynomial.map_ne_zero_iff hf).mpr hp0) a)
rw [le_rootMultiplicity_iff hp0, β map_dvd_map f hf ((monic_X_sub_C a).pow _),
Polynomial.map_pow, Polynomial.map_sub, map_X, map_C]
apply pow_rootMultiplicity_dvd
theorem count_map_roots [IsDomain A] [DecidableEq B] {p : A[X]} {f : A β+* B} (hmap : map f p β 0)
(b : B) :
(p.roots.map f).count b β€ rootMultiplicity b (p.map f) := by
rw [le_rootMultiplicity_iff hmap, β Multiset.prod_replicate, β
Multiset.map_replicate fun a => X - C a]
rw [β Multiset.filter_eq]
refine
(Multiset.prod_dvd_prod_of_le <| Multiset.map_le_map <| Multiset.filter_le (Eq b) _).trans ?_
convert Polynomial.map_dvd f p.prod_multiset_X_sub_C_dvd
simp only [Polynomial.map_multiset_prod, Multiset.map_map]
congr; ext1
simp only [Function.comp_apply, Polynomial.map_sub, map_X, map_C]
theorem count_map_roots_of_injective [IsDomain A] [DecidableEq B] (p : A[X]) {f : A β+* B}
(hf : Function.Injective f) (b : B) :
(p.roots.map f).count b β€ rootMultiplicity b (p.map f) := by
by_cases hp0 : p = 0
Β· simp only [hp0, roots_zero, Multiset.map_zero, Multiset.count_zero, Polynomial.map_zero,
rootMultiplicity_zero, le_refl]
Β· exact count_map_roots ((Polynomial.map_ne_zero_iff hf).mpr hp0) b
theorem map_roots_le [IsDomain A] [IsDomain B] {p : A[X]} {f : A β+* B} (h : p.map f β 0) :
p.roots.map f β€ (p.map f).roots := by
classical
exact Multiset.le_iff_count.2 fun b => by
| rw [count_roots]
apply count_map_roots h
theorem map_roots_le_of_injective [IsDomain A] [IsDomain B] (p : A[X]) {f : A β+* B}
(hf : Function.Injective f) : p.roots.map f β€ (p.map f).roots := by
by_cases hp0 : p = 0
Β· simp only [hp0, roots_zero, Multiset.map_zero, Polynomial.map_zero, le_rfl]
exact map_roots_le ((Polynomial.map_ne_zero_iff hf).mpr hp0)
theorem card_roots_le_map [IsDomain A] [IsDomain B] {p : A[X]} {f : A β+* B} (h : p.map f β 0) :
Multiset.card p.roots β€ Multiset.card (p.map f).roots := by
rw [β p.roots.card_map f]
| Mathlib/Algebra/Polynomial/Roots.lean | 768 | 779 |
/-
Copyright (c) 2024 David Loeffler. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Loeffler
-/
import Mathlib.NumberTheory.LSeries.AbstractFuncEq
import Mathlib.NumberTheory.ModularForms.JacobiTheta.Bounds
import Mathlib.Analysis.SpecialFunctions.Gamma.Deligne
import Mathlib.NumberTheory.LSeries.MellinEqDirichlet
import Mathlib.NumberTheory.LSeries.Basic
import Mathlib.Analysis.Complex.RemovableSingularity
/-!
# Even Hurwitz zeta functions
In this file we study the functions on `β` which are the meromorphic continuation of the following
series (convergent for `1 < re s`), where `a β β` is a parameter:
`hurwitzZetaEven a s = 1 / 2 * β' n : β€, 1 / |n + a| ^ s`
and
`cosZeta a s = β' n : β, cos (2 * Ο * a * n) / |n| ^ s`.
Note that the term for `n = -a` in the first sum is omitted if `a` is an integer, and the term for
`n = 0` is omitted in the second sum (always).
Of course, we cannot *define* these functions by the above formulae (since existence of the
meromorphic continuation is not at all obvious); we in fact construct them as Mellin transforms of
various versions of the Jacobi theta function.
We also define completed versions of these functions with nicer functional equations (satisfying
`completedHurwitzZetaEven a s = Gammaβ s * hurwitzZetaEven a s`, and similarly for `cosZeta`); and
modified versions with a subscript `0`, which are entire functions differing from the above by
multiples of `1 / s` and `1 / (1 - s)`.
## Main definitions and theorems
* `hurwitzZetaEven` and `cosZeta`: the zeta functions
* `completedHurwitzZetaEven` and `completedCosZeta`: completed variants
* `differentiableAt_hurwitzZetaEven` and `differentiableAt_cosZeta`:
differentiability away from `s = 1`
* `completedHurwitzZetaEven_one_sub`: the functional equation
`completedHurwitzZetaEven a (1 - s) = completedCosZeta a s`
* `hasSum_int_hurwitzZetaEven` and `hasSum_nat_cosZeta`: relation between the zeta functions and
the corresponding Dirichlet series for `1 < re s`.
-/
noncomputable section
open Complex Filter Topology Asymptotics Real Set MeasureTheory
namespace HurwitzZeta
section kernel_defs
/-!
## Definitions and elementary properties of kernels
-/
/-- Even Hurwitz zeta kernel (function whose Mellin transform will be the even part of the
completed Hurwit zeta function). See `evenKernel_def` for the defining formula, and
`hasSum_int_evenKernel` for an expression as a sum over `β€`. -/
@[irreducible] def evenKernel (a : UnitAddCircle) (x : β) : β :=
(show Function.Periodic
(fun ΞΎ : β β¦ rexp (-Ο * ΞΎ ^ 2 * x) * re (jacobiThetaβ (ΞΎ * I * x) (I * x))) 1 by
intro ΞΎ
simp only [ofReal_add, ofReal_one, add_mul, one_mul, jacobiThetaβ_add_left']
have : cexp (-βΟ * I * ((I * βx) + 2 * (βΞΎ * I * βx))) = rexp (Ο * (x + 2 * ΞΎ * x)) := by
ring_nf
simp [I_sq]
rw [this, re_ofReal_mul, β mul_assoc, β Real.exp_add]
congr
ring).lift a
lemma evenKernel_def (a x : β) :
β(evenKernel βa x) = cexp (-Ο * a ^ 2 * x) * jacobiThetaβ (a * I * x) (I * x) := by
simp [evenKernel, re_eq_add_conj, jacobiThetaβ_conj, β mul_two,
mul_div_cancel_rightβ _ (two_ne_zero' β)]
/-- For `x β€ 0` the defining sum diverges, so the kernel is 0. -/
lemma evenKernel_undef (a : UnitAddCircle) {x : β} (hx : x β€ 0) : evenKernel a x = 0 := by
induction a using QuotientAddGroup.induction_on with
| H a' => simp [β ofReal_inj, evenKernel_def, jacobiThetaβ_undef _ (by simpa : (I * βx).im β€ 0)]
/-- Cosine Hurwitz zeta kernel. See `cosKernel_def` for the defining formula, and
`hasSum_int_cosKernel` for expression as a sum. -/
@[irreducible] def cosKernel (a : UnitAddCircle) (x : β) : β :=
(show Function.Periodic (fun ΞΎ : β β¦ re (jacobiThetaβ ΞΎ (I * x))) 1 by
intro ΞΎ; simp [jacobiThetaβ_add_left]).lift a
lemma cosKernel_def (a x : β) : β(cosKernel βa x) = jacobiThetaβ a (I * x) := by
simp [cosKernel, re_eq_add_conj, jacobiThetaβ_conj, β mul_two,
mul_div_cancel_rightβ _ (two_ne_zero' β)]
lemma cosKernel_undef (a : UnitAddCircle) {x : β} (hx : x β€ 0) : cosKernel a x = 0 := by
induction a using QuotientAddGroup.induction_on with
| H => simp [β ofReal_inj, cosKernel_def, jacobiThetaβ_undef _ (by simpa : (I * βx).im β€ 0)]
/-- For `a = 0`, both kernels agree. -/
lemma evenKernel_eq_cosKernel_of_zero : evenKernel 0 = cosKernel 0 := by
ext1 x
simp [β QuotientAddGroup.mk_zero, β ofReal_inj, evenKernel_def, cosKernel_def]
@[simp]
lemma evenKernel_neg (a : UnitAddCircle) (x : β) : evenKernel (-a) x = evenKernel a x := by
induction a using QuotientAddGroup.induction_on with
| H => simp [β QuotientAddGroup.mk_neg, β ofReal_inj, evenKernel_def, jacobiThetaβ_neg_left]
@[simp]
lemma cosKernel_neg (a : UnitAddCircle) (x : β) : cosKernel (-a) x = cosKernel a x := by
induction a using QuotientAddGroup.induction_on with
| H => simp [β QuotientAddGroup.mk_neg, β ofReal_inj, cosKernel_def]
lemma continuousOn_evenKernel (a : UnitAddCircle) : ContinuousOn (evenKernel a) (Ioi 0) := by
induction a using QuotientAddGroup.induction_on with | H a' =>
apply continuous_re.comp_continuousOn (f := fun x β¦ (evenKernel a' x : β))
simp only [evenKernel_def]
refine continuousOn_of_forall_continuousAt (fun x hx β¦ .mul (by fun_prop) ?_)
exact (continuousAt_jacobiThetaβ (a' * I * x) <| by simpa).comp
(f := fun u : β β¦ (a' * I * u, I * u)) (by fun_prop)
lemma continuousOn_cosKernel (a : UnitAddCircle) : ContinuousOn (cosKernel a) (Ioi 0) := by
induction a using QuotientAddGroup.induction_on with | H a' =>
apply continuous_re.comp_continuousOn (f := fun x β¦ (cosKernel a' x : β))
simp only [cosKernel_def]
refine continuousOn_of_forall_continuousAt (fun x hx β¦ ?_)
exact (continuousAt_jacobiThetaβ a' <| by simpa).comp
(f := fun u : β β¦ ((a' : β), I * u)) (by fun_prop)
lemma evenKernel_functional_equation (a : UnitAddCircle) (x : β) :
evenKernel a x = 1 / x ^ (1 / 2 : β) * cosKernel a (1 / x) := by
rcases le_or_lt x 0 with hx | hx
Β· rw [evenKernel_undef _ hx, cosKernel_undef, mul_zero]
exact div_nonpos_of_nonneg_of_nonpos zero_le_one hx
induction a using QuotientAddGroup.induction_on with | H a =>
rw [β ofReal_inj, ofReal_mul, evenKernel_def, cosKernel_def, jacobiThetaβ_functional_equation]
have h1 : I * β(1 / x) = -1 / (I * x) := by
push_cast
rw [β div_div, mul_one_div, div_I, neg_one_mul, neg_neg]
have hx' : I * x β 0 := mul_ne_zero I_ne_zero (ofReal_ne_zero.mpr hx.ne')
have h2 : a * I * x / (I * x) = a := by
rw [div_eq_iff hx']
ring
have h3 : 1 / (-I * (I * x)) ^ (1 / 2 : β) = 1 / β(x ^ (1 / 2 : β)) := by
rw [neg_mul, β mul_assoc, I_mul_I, neg_one_mul, neg_neg,ofReal_cpow hx.le, ofReal_div,
ofReal_one, ofReal_ofNat]
have h4 : -Ο * I * (a * I * x) ^ 2 / (I * x) = - (-Ο * a ^ 2 * x) := by
rw [mul_pow, mul_pow, I_sq, div_eq_iff hx']
ring
rw [h1, h2, h3, h4, β mul_assoc, mul_comm (cexp _), mul_assoc _ (cexp _) (cexp _),
β Complex.exp_add, neg_add_cancel, Complex.exp_zero, mul_one, ofReal_div, ofReal_one]
end kernel_defs
section asymp
/-!
## Formulae for the kernels as sums
-/
lemma hasSum_int_evenKernel (a : β) {t : β} (ht : 0 < t) :
HasSum (fun n : β€ β¦ rexp (-Ο * (n + a) ^ 2 * t)) (evenKernel a t) := by
rw [β hasSum_ofReal, evenKernel_def]
have (n : β€) : cexp (-(Ο * (n + a) ^ 2 * t)) = cexp (-(Ο * a ^ 2 * t)) *
jacobiThetaβ_term n (a * I * t) (I * t) := by
rw [jacobiThetaβ_term, β Complex.exp_add]
ring_nf
simp
simpa [this] using (hasSum_jacobiThetaβ_term _ (by simpa)).mul_left _
lemma hasSum_int_cosKernel (a : β) {t : β} (ht : 0 < t) :
HasSum (fun n : β€ β¦ cexp (2 * Ο * I * a * n) * rexp (-Ο * n ^ 2 * t)) β(cosKernel a t) := by
rw [cosKernel_def a t]
have (n : β€) : cexp (2 * Ο * I * a * n) * cexp (-(Ο * n ^ 2 * t)) =
jacobiThetaβ_term n a (I * βt) := by
rw [jacobiThetaβ_term, β Complex.exp_add]
ring_nf
simp [sub_eq_add_neg]
simpa [this] using hasSum_jacobiThetaβ_term _ (by simpa)
/-- Modified version of `hasSum_int_evenKernel` omitting the constant term at `β`. -/
lemma hasSum_int_evenKernelβ (a : β) {t : β} (ht : 0 < t) :
HasSum (fun n : β€ β¦ if n + a = 0 then 0 else rexp (-Ο * (n + a) ^ 2 * t))
(evenKernel a t - if (a : UnitAddCircle) = 0 then 1 else 0) := by
haveI := Classical.propDecidable -- speed up instance search for `if / then / else`
simp_rw [AddCircle.coe_eq_zero_iff, zsmul_one]
split_ifs with h
Β· obtain β¨k, rflβ© := h
simpa [β Int.cast_add, add_eq_zero_iff_eq_neg]
using hasSum_ite_sub_hasSum (hasSum_int_evenKernel (k : β) ht) (-k)
Β· suffices β (n : β€), n + a β 0 by simpa [this] using hasSum_int_evenKernel a ht
contrapose! h
let β¨n, hnβ© := h
| exact β¨-n, by simpa [neg_eq_iff_add_eq_zero]β©
lemma hasSum_int_cosKernelβ (a : β) {t : β} (ht : 0 < t) :
HasSum (fun n : β€ β¦ if n = 0 then 0 else cexp (2 * Ο * I * a * n) * rexp (-Ο * n ^ 2 * t))
(β(cosKernel a t) - 1) := by
simpa using hasSum_ite_sub_hasSum (hasSum_int_cosKernel a ht) 0
lemma hasSum_nat_cosKernelβ (a : β) {t : β} (ht : 0 < t) :
HasSum (fun n : β β¦ 2 * Real.cos (2 * Ο * a * (n + 1)) * rexp (-Ο * (n + 1) ^ 2 * t))
(cosKernel a t - 1) := by
rw [β hasSum_ofReal, ofReal_sub, ofReal_one]
have := (hasSum_int_cosKernel a ht).nat_add_neg
rw [β hasSum_nat_add_iff' 1] at this
simp_rw [Finset.sum_range_one, Nat.cast_zero, neg_zero, Int.cast_zero, zero_pow two_ne_zero,
mul_zero, zero_mul, Complex.exp_zero, Real.exp_zero, ofReal_one, mul_one, Int.cast_neg,
Int.cast_natCast, neg_sq, β add_mul, add_sub_assoc, β sub_sub, sub_self, zero_sub,
| Mathlib/NumberTheory/LSeries/HurwitzZetaEven.lean | 192 | 207 |
/-
Copyright (c) 2014 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Y. Lewis, Leonardo de Moura, Mario Carneiro, Floris van Doorn
-/
import Mathlib.Algebra.Field.Basic
import Mathlib.Algebra.GroupWithZero.Units.Lemmas
import Mathlib.Algebra.Order.Ring.Abs
import Mathlib.Order.Bounds.Basic
import Mathlib.Order.Bounds.OrderIso
import Mathlib.Tactic.Positivity.Core
/-!
# Lemmas about linear ordered (semi)fields
-/
open Function OrderDual
variable {ΞΉ Ξ± Ξ² : Type*}
section LinearOrderedSemifield
variable [Semifield Ξ±] [LinearOrder Ξ±] [IsStrictOrderedRing Ξ±] {a b c d e : Ξ±} {m n : β€}
/-!
### Relating two divisions.
-/
@[deprecated div_le_div_iff_of_pos_right (since := "2024-11-12")]
theorem div_le_div_right (hc : 0 < c) : a / c β€ b / c β a β€ b := div_le_div_iff_of_pos_right hc
@[deprecated div_lt_div_iff_of_pos_right (since := "2024-11-12")]
theorem div_lt_div_right (hc : 0 < c) : a / c < b / c β a < b := div_lt_div_iff_of_pos_right hc
@[deprecated div_lt_div_iff_of_pos_left (since := "2024-11-13")]
theorem div_lt_div_left (ha : 0 < a) (hb : 0 < b) (hc : 0 < c) : a / b < a / c β c < b :=
div_lt_div_iff_of_pos_left ha hb hc
@[deprecated div_le_div_iff_of_pos_left (since := "2024-11-12")]
theorem div_le_div_left (ha : 0 < a) (hb : 0 < b) (hc : 0 < c) : a / b β€ a / c β c β€ b :=
div_le_div_iff_of_pos_left ha hb hc
@[deprecated div_lt_div_iffβ (since := "2024-11-12")]
theorem div_lt_div_iff (b0 : 0 < b) (d0 : 0 < d) : a / b < c / d β a * d < c * b :=
div_lt_div_iffβ b0 d0
@[deprecated div_le_div_iffβ (since := "2024-11-12")]
theorem div_le_div_iff (b0 : 0 < b) (d0 : 0 < d) : a / b β€ c / d β a * d β€ c * b :=
div_le_div_iffβ b0 d0
@[deprecated div_le_divβ (since := "2024-11-12")]
theorem div_le_div (hc : 0 β€ c) (hac : a β€ c) (hd : 0 < d) (hbd : d β€ b) : a / b β€ c / d :=
div_le_divβ hc hac hd hbd
@[deprecated div_lt_divβ (since := "2024-11-12")]
theorem div_lt_div (hac : a < c) (hbd : d β€ b) (c0 : 0 β€ c) (d0 : 0 < d) : a / b < c / d :=
div_lt_divβ hac hbd c0 d0
@[deprecated div_lt_divβ' (since := "2024-11-12")]
theorem div_lt_div' (hac : a β€ c) (hbd : d < b) (c0 : 0 < c) (d0 : 0 < d) : a / b < c / d :=
div_lt_divβ' hac hbd c0 d0
/-!
### Relating one division and involving `1`
-/
@[bound]
theorem div_le_self (ha : 0 β€ a) (hb : 1 β€ b) : a / b β€ a := by
simpa only [div_one] using div_le_div_of_nonneg_left ha zero_lt_one hb
@[bound]
theorem div_lt_self (ha : 0 < a) (hb : 1 < b) : a / b < a := by
simpa only [div_one] using div_lt_div_of_pos_left ha zero_lt_one hb
@[bound]
theorem le_div_self (ha : 0 β€ a) (hbβ : 0 < b) (hbβ : b β€ 1) : a β€ a / b := by
simpa only [div_one] using div_le_div_of_nonneg_left ha hbβ hbβ
theorem one_le_div (hb : 0 < b) : 1 β€ a / b β b β€ a := by rw [le_div_iffβ hb, one_mul]
theorem div_le_one (hb : 0 < b) : a / b β€ 1 β a β€ b := by rw [div_le_iffβ hb, one_mul]
theorem one_lt_div (hb : 0 < b) : 1 < a / b β b < a := by rw [lt_div_iffβ hb, one_mul]
theorem div_lt_one (hb : 0 < b) : a / b < 1 β a < b := by rw [div_lt_iffβ hb, one_mul]
theorem one_div_le (ha : 0 < a) (hb : 0 < b) : 1 / a β€ b β 1 / b β€ a := by
simpa using inv_le_commβ ha hb
theorem one_div_lt (ha : 0 < a) (hb : 0 < b) : 1 / a < b β 1 / b < a := by
| simpa using inv_lt_commβ ha hb
| Mathlib/Algebra/Order/Field/Basic.lean | 93 | 93 |
/-
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β
| Mathlib/Algebra/Homology/ShortComplex/LeftHomology.lean | 597 | 605 |
/-
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.Finset.Card
import Mathlib.Data.Fintype.Basic
/-!
# Cardinalities of finite types
This file defines the cardinality `Fintype.card Ξ±` as the number of elements in `(univ : Finset Ξ±)`.
We also include some elementary results on the values of `Fintype.card` on specific types.
## Main declarations
* `Fintype.card Ξ±`: Cardinality of a fintype. Equal to `Finset.univ.card`.
* `Finite.surjective_of_injective`: an injective function from a finite type to
itself is also surjective.
-/
assert_not_exists Monoid
open Function
universe u v
variable {Ξ± Ξ² Ξ³ : Type*}
open Finset Function
namespace Fintype
/-- `card Ξ±` is the number of elements in `Ξ±`, defined when `Ξ±` is a fintype. -/
def card (Ξ±) [Fintype Ξ±] : β :=
(@univ Ξ± _).card
theorem subtype_card {p : Ξ± β Prop} (s : Finset Ξ±) (H : β x : Ξ±, x β s β p x) :
@card { x // p x } (Fintype.subtype s H) = #s :=
Multiset.card_pmap _ _ _
theorem card_of_subtype {p : Ξ± β Prop} (s : Finset Ξ±) (H : β x : Ξ±, x β s β p x)
[Fintype { x // p x }] : card { x // p x } = #s := by
rw [β subtype_card s H]
congr!
@[simp]
theorem card_ofFinset {p : Set Ξ±} (s : Finset Ξ±) (H : β x, x β s β x β p) :
@Fintype.card p (ofFinset s H) = #s :=
Fintype.subtype_card s H
theorem card_of_finset' {p : Set Ξ±} (s : Finset Ξ±) (H : β x, x β s β x β p) [Fintype p] :
Fintype.card p = #s := by rw [β card_ofFinset s H]; congr!
end Fintype
namespace Fintype
theorem ofEquiv_card [Fintype Ξ±] (f : Ξ± β Ξ²) : @card Ξ² (ofEquiv Ξ± f) = card Ξ± :=
Multiset.card_map _ _
theorem card_congr {Ξ± Ξ²} [Fintype Ξ±] [Fintype Ξ²] (f : Ξ± β Ξ²) : card Ξ± = card Ξ² := by
rw [β ofEquiv_card f]; congr!
@[congr]
theorem card_congr' {Ξ± Ξ²} [Fintype Ξ±] [Fintype Ξ²] (h : Ξ± = Ξ²) : card Ξ± = card Ξ² :=
card_congr (by rw [h])
/-- Note: this lemma is specifically about `Fintype.ofSubsingleton`. For a statement about
arbitrary `Fintype` instances, use either `Fintype.card_le_one_iff_subsingleton` or
`Fintype.card_unique`. -/
theorem card_ofSubsingleton (a : Ξ±) [Subsingleton Ξ±] : @Fintype.card _ (ofSubsingleton a) = 1 :=
rfl
@[simp]
theorem card_unique [Unique Ξ±] [h : Fintype Ξ±] : Fintype.card Ξ± = 1 :=
Subsingleton.elim (ofSubsingleton default) h βΈ card_ofSubsingleton _
/-- Note: this lemma is specifically about `Fintype.ofIsEmpty`. For a statement about
arbitrary `Fintype` instances, use `Fintype.card_eq_zero`. -/
theorem card_ofIsEmpty [IsEmpty Ξ±] : @Fintype.card Ξ± Fintype.ofIsEmpty = 0 :=
rfl
end Fintype
namespace Set
variable {s t : Set Ξ±}
-- We use an arbitrary `[Fintype s]` instance here,
-- not necessarily coming from a `[Fintype Ξ±]`.
@[simp]
theorem toFinset_card {Ξ± : Type*} (s : Set Ξ±) [Fintype s] : s.toFinset.card = Fintype.card s :=
Multiset.card_map Subtype.val Finset.univ.val
end Set
@[simp]
theorem Finset.card_univ [Fintype Ξ±] : #(univ : Finset Ξ±) = Fintype.card Ξ± := rfl
theorem Finset.eq_univ_of_card [Fintype Ξ±] (s : Finset Ξ±) (hs : #s = Fintype.card Ξ±) :
s = univ :=
eq_of_subset_of_card_le (subset_univ _) <| by rw [hs, Finset.card_univ]
theorem Finset.card_eq_iff_eq_univ [Fintype Ξ±] (s : Finset Ξ±) : #s = Fintype.card Ξ± β s = univ :=
β¨s.eq_univ_of_card, by
rintro rfl
exact Finset.card_univβ©
theorem Finset.card_le_univ [Fintype Ξ±] (s : Finset Ξ±) : #s β€ Fintype.card Ξ± :=
card_le_card (subset_univ s)
theorem Finset.card_lt_univ_of_not_mem [Fintype Ξ±] {s : Finset Ξ±} {x : Ξ±} (hx : x β s) :
#s < Fintype.card Ξ± :=
card_lt_card β¨subset_univ s, not_forall.2 β¨x, fun hx' => hx (hx' <| mem_univ x)β©β©
theorem Finset.card_lt_iff_ne_univ [Fintype Ξ±] (s : Finset Ξ±) :
#s < Fintype.card Ξ± β s β Finset.univ :=
s.card_le_univ.lt_iff_ne.trans (not_congr s.card_eq_iff_eq_univ)
theorem Finset.card_compl_lt_iff_nonempty [Fintype Ξ±] [DecidableEq Ξ±] (s : Finset Ξ±) :
#sαΆ < Fintype.card Ξ± β s.Nonempty :=
sαΆ.card_lt_iff_ne_univ.trans s.compl_ne_univ_iff_nonempty
theorem Finset.card_univ_diff [DecidableEq Ξ±] [Fintype Ξ±] (s : Finset Ξ±) :
#(univ \ s) = Fintype.card Ξ± - #s :=
Finset.card_sdiff (subset_univ s)
theorem Finset.card_compl [DecidableEq Ξ±] [Fintype Ξ±] (s : Finset Ξ±) : #sαΆ = Fintype.card Ξ± - #s :=
Finset.card_univ_diff s
@[simp]
theorem Finset.card_add_card_compl [DecidableEq Ξ±] [Fintype Ξ±] (s : Finset Ξ±) :
#s + #sαΆ = Fintype.card Ξ± := by
rw [Finset.card_compl, β Nat.add_sub_assoc (card_le_univ s), Nat.add_sub_cancel_left]
@[simp]
theorem Finset.card_compl_add_card [DecidableEq Ξ±] [Fintype Ξ±] (s : Finset Ξ±) :
#sαΆ + #s = Fintype.card Ξ± := by
rw [Nat.add_comm, card_add_card_compl]
theorem Fintype.card_compl_set [Fintype Ξ±] (s : Set Ξ±) [Fintype s] [Fintype (β₯sαΆ : Sort _)] :
Fintype.card (β₯sαΆ : Sort _) = Fintype.card Ξ± - Fintype.card s := by
classical rw [β Set.toFinset_card, β Set.toFinset_card, β Finset.card_compl, Set.toFinset_compl]
theorem Fintype.card_subtype_eq (y : Ξ±) [Fintype { x // x = y }] :
Fintype.card { x // x = y } = 1 :=
Fintype.card_unique
theorem Fintype.card_subtype_eq' (y : Ξ±) [Fintype { x // y = x }] :
Fintype.card { x // y = x } = 1 :=
Fintype.card_unique
theorem Fintype.card_empty : Fintype.card Empty = 0 :=
rfl
theorem Fintype.card_pempty : Fintype.card PEmpty = 0 :=
rfl
theorem Fintype.card_unit : Fintype.card Unit = 1 :=
rfl
@[simp]
theorem Fintype.card_punit : Fintype.card PUnit = 1 :=
rfl
@[simp]
theorem Fintype.card_bool : Fintype.card Bool = 2 :=
rfl
@[simp]
theorem Fintype.card_ulift (Ξ± : Type*) [Fintype Ξ±] : Fintype.card (ULift Ξ±) = Fintype.card Ξ± :=
Fintype.ofEquiv_card _
@[simp]
theorem Fintype.card_plift (Ξ± : Type*) [Fintype Ξ±] : Fintype.card (PLift Ξ±) = Fintype.card Ξ± :=
Fintype.ofEquiv_card _
@[simp]
theorem Fintype.card_orderDual (Ξ± : Type*) [Fintype Ξ±] : Fintype.card Ξ±α΅α΅ = Fintype.card Ξ± :=
rfl
@[simp]
theorem Fintype.card_lex (Ξ± : Type*) [Fintype Ξ±] : Fintype.card (Lex Ξ±) = Fintype.card Ξ± :=
rfl
-- Note: The extra hypothesis `h` is there so that the rewrite lemma applies,
-- no matter what instance of `Fintype (Set.univ : Set Ξ±)` is used.
@[simp]
theorem Fintype.card_setUniv [Fintype Ξ±] {h : Fintype (Set.univ : Set Ξ±)} :
Fintype.card (Set.univ : Set Ξ±) = Fintype.card Ξ± := by
apply Fintype.card_of_finset'
simp
@[simp]
theorem Fintype.card_subtype_true [Fintype Ξ±] {h : Fintype {_a : Ξ± // True}} :
@Fintype.card {_a // True} h = Fintype.card Ξ± := by
apply Fintype.card_of_subtype
simp
/-- Given that `Ξ± β Ξ²` is a fintype, `Ξ±` is also a fintype. This is non-computable as it uses
that `Sum.inl` is an injection, but there's no clear inverse if `Ξ±` is empty. -/
noncomputable def Fintype.sumLeft {Ξ± Ξ²} [Fintype (Ξ± β Ξ²)] : Fintype Ξ± :=
Fintype.ofInjective (Sum.inl : Ξ± β Ξ± β Ξ²) Sum.inl_injective
/-- Given that `Ξ± β Ξ²` is a fintype, `Ξ²` is also a fintype. This is non-computable as it uses
that `Sum.inr` is an injection, but there's no clear inverse if `Ξ²` is empty. -/
noncomputable def Fintype.sumRight {Ξ± Ξ²} [Fintype (Ξ± β Ξ²)] : Fintype Ξ² :=
Fintype.ofInjective (Sum.inr : Ξ² β Ξ± β Ξ²) Sum.inr_injective
theorem Finite.exists_univ_list (Ξ±) [Finite Ξ±] : β l : List Ξ±, l.Nodup β§ β x : Ξ±, x β l := by
cases nonempty_fintype Ξ±
obtain β¨l, eβ© := Quotient.exists_rep (@univ Ξ± _).1
have := And.intro (@univ Ξ± _).2 (@mem_univ_val Ξ± _)
exact β¨_, by rwa [β e] at thisβ©
theorem List.Nodup.length_le_card {Ξ± : Type*} [Fintype Ξ±] {l : List Ξ±} (h : l.Nodup) :
l.length β€ Fintype.card Ξ± := by
classical exact List.toFinset_card_of_nodup h βΈ l.toFinset.card_le_univ
namespace Fintype
variable [Fintype Ξ±] [Fintype Ξ²]
theorem card_le_of_injective (f : Ξ± β Ξ²) (hf : Function.Injective f) : card Ξ± β€ card Ξ² :=
Finset.card_le_card_of_injOn f (fun _ _ => Finset.mem_univ _) fun _ _ _ _ h => hf h
theorem card_le_of_embedding (f : Ξ± βͺ Ξ²) : card Ξ± β€ card Ξ² :=
card_le_of_injective f f.2
theorem card_lt_of_injective_of_not_mem (f : Ξ± β Ξ²) (h : Function.Injective f) {b : Ξ²}
(w : b β Set.range f) : card Ξ± < card Ξ² :=
calc
card Ξ± = (univ.map β¨f, hβ©).card := (card_map _).symm
_ < card Ξ² :=
Finset.card_lt_univ_of_not_mem (x := b) <| by
rwa [β mem_coe, coe_map, coe_univ, Set.image_univ]
theorem card_lt_of_injective_not_surjective (f : Ξ± β Ξ²) (h : Function.Injective f)
(h' : Β¬Function.Surjective f) : card Ξ± < card Ξ² :=
let β¨_y, hyβ© := not_forall.1 h'
card_lt_of_injective_of_not_mem f h hy
theorem card_le_of_surjective (f : Ξ± β Ξ²) (h : Function.Surjective f) : card Ξ² β€ card Ξ± :=
card_le_of_injective _ (Function.injective_surjInv h)
theorem card_range_le {Ξ± Ξ² : Type*} (f : Ξ± β Ξ²) [Fintype Ξ±] [Fintype (Set.range f)] :
Fintype.card (Set.range f) β€ Fintype.card Ξ± :=
Fintype.card_le_of_surjective (fun a => β¨f a, by simpβ©) fun β¨_, a, haβ© => β¨a, by simpa using haβ©
theorem card_range {Ξ± Ξ² F : Type*} [FunLike F Ξ± Ξ²] [EmbeddingLike F Ξ± Ξ²] (f : F) [Fintype Ξ±]
[Fintype (Set.range f)] : Fintype.card (Set.range f) = Fintype.card Ξ± :=
Eq.symm <| Fintype.card_congr <| Equiv.ofInjective _ <| EmbeddingLike.injective f
theorem card_eq_zero_iff : card Ξ± = 0 β IsEmpty Ξ± := by
rw [card, Finset.card_eq_zero, univ_eq_empty_iff]
@[simp] theorem card_eq_zero [IsEmpty Ξ±] : card Ξ± = 0 :=
card_eq_zero_iff.2 βΉ_βΊ
alias card_of_isEmpty := card_eq_zero
/-- A `Fintype` with cardinality zero is equivalent to `Empty`. -/
def cardEqZeroEquivEquivEmpty : card Ξ± = 0 β (Ξ± β Empty) :=
(Equiv.ofIff card_eq_zero_iff).trans (Equiv.equivEmptyEquiv Ξ±).symm
theorem card_pos_iff : 0 < card Ξ± β Nonempty Ξ± :=
Nat.pos_iff_ne_zero.trans <| not_iff_comm.mp <| not_nonempty_iff.trans card_eq_zero_iff.symm
theorem card_pos [h : Nonempty Ξ±] : 0 < card Ξ± :=
card_pos_iff.mpr h
@[simp]
theorem card_ne_zero [Nonempty Ξ±] : card Ξ± β 0 :=
_root_.ne_of_gt card_pos
instance [Nonempty Ξ±] : NeZero (card Ξ±) := β¨card_ne_zeroβ©
theorem existsUnique_iff_card_one {Ξ±} [Fintype Ξ±] (p : Ξ± β Prop) [DecidablePred p] :
(β! a : Ξ±, p a) β #{x | p x} = 1 := by
rw [Finset.card_eq_one]
refine exists_congr fun x => ?_
simp only [forall_true_left, Subset.antisymm_iff, subset_singleton_iff', singleton_subset_iff,
true_and, and_comm, mem_univ, mem_filter]
@[deprecated (since := "2024-12-17")] alias exists_unique_iff_card_one := existsUnique_iff_card_one
nonrec theorem two_lt_card_iff : 2 < card Ξ± β β a b c : Ξ±, a β b β§ a β c β§ b β c := by
simp_rw [β Finset.card_univ, two_lt_card_iff, mem_univ, true_and]
theorem card_of_bijective {f : Ξ± β Ξ²} (hf : Bijective f) : card Ξ± = card Ξ² :=
card_congr (Equiv.ofBijective f hf)
end Fintype
namespace Finite
variable [Finite Ξ±]
| theorem surjective_of_injective {f : Ξ± β Ξ±} (hinj : Injective f) : Surjective f := by
intro x
have := Classical.propDecidable
| Mathlib/Data/Fintype/Card.lean | 301 | 303 |
/-
Copyright (c) 2018 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
-/
import Mathlib.Algebra.Module.LinearMap.End
import Mathlib.Algebra.Module.Submodule.Defs
import Mathlib.Algebra.BigOperators.Group.Finset.Defs
/-!
# Linear maps involving submodules of a module
In this file we define a number of linear maps involving submodules of a module.
## Main declarations
* `Submodule.subtype`: Embedding of a submodule `p` to the ambient space `M` as a `Submodule`.
* `LinearMap.domRestrict`: The restriction of a semilinear map `f : M β Mβ` to a submodule `p β M`
as a semilinear map `p β Mβ`.
* `LinearMap.restrict`: The restriction of a linear map `f : M β Mβ` to a submodule `p β M` and
`q β Mβ` (if `q` contains the codomain).
* `Submodule.inclusion`: the inclusion `p β p'` of submodules `p` and `p'` as a linear map.
## Tags
submodule, subspace, linear map
-/
open Function Set
universe u'' u' u v w
section
variable {G : Type u''} {S : Type u'} {R : Type u} {M : Type v} {ΞΉ : Type w}
namespace SMulMemClass
variable [Semiring R] [AddCommMonoid M] [Module R M] {A : Type*} [SetLike A M]
[AddSubmonoidClass A M] [SMulMemClass A R M] (S' : A)
/-- The natural `R`-linear map from a submodule of an `R`-module `M` to `M`. -/
protected def subtype : S' ββ[R] M where
toFun := Subtype.val
map_add' _ _ := rfl
map_smul' _ _ := rfl
variable {S'} in
@[simp]
lemma subtype_apply (x : S') :
SMulMemClass.subtype S' x = x := rfl
lemma subtype_injective :
Function.Injective (SMulMemClass.subtype S') :=
Subtype.coe_injective
@[simp]
protected theorem coe_subtype : (SMulMemClass.subtype S' : S' β M) = Subtype.val :=
rfl
@[deprecated (since := "2025-02-18")]
protected alias coeSubtype := SMulMemClass.coe_subtype
end SMulMemClass
namespace Submodule
section AddCommMonoid
variable [Semiring R] [AddCommMonoid M]
-- We can infer the module structure implicitly from the bundled submodule,
-- rather than via typeclass resolution.
variable {module_M : Module R M}
variable {p q : Submodule R M}
variable {r : R} {x y : M}
variable (p)
/-- Embedding of a submodule `p` to the ambient space `M`. -/
protected def subtype : p ββ[R] M where
toFun := Subtype.val
map_add' := by simp [coe_smul]
map_smul' := by simp [coe_smul]
variable {p} in
@[simp]
theorem subtype_apply (x : p) : p.subtype x = x :=
rfl
lemma subtype_injective :
Function.Injective p.subtype :=
Subtype.coe_injective
@[simp]
theorem coe_subtype : (Submodule.subtype p : p β M) = Subtype.val :=
rfl
theorem injective_subtype : Injective p.subtype :=
Subtype.coe_injective
/-- Note the `AddSubmonoid` version of this lemma is called `AddSubmonoid.coe_finset_sum`. -/
theorem coe_sum (x : ΞΉ β p) (s : Finset ΞΉ) : β(β i β s, x i) = β i β s, (x i : M) :=
map_sum p.subtype _ _
section AddAction
variable {Ξ± Ξ² : Type*}
/-- The action by a submodule is the action by the underlying module. -/
instance [AddAction M Ξ±] : AddAction p Ξ± :=
AddAction.compHom _ p.subtype.toAddMonoidHom
end AddAction
end AddCommMonoid
end Submodule
end
section
variable {R : Type*} {Rβ : Type*} {Rβ : Type*} {Rβ : Type*}
variable {M : Type*} {Mβ : Type*} {Mβ : Type*} {Mβ : Type*}
variable {ΞΉ : Type*}
namespace LinearMap
section AddCommMonoid
variable [Semiring R] [Semiring Rβ] [Semiring Rβ]
variable [AddCommMonoid M] [AddCommMonoid Mβ] [AddCommMonoid Mβ] [AddCommMonoid Mβ]
variable [Module R M] [Module R Mβ] [Module Rβ Mβ] [Module Rβ Mβ]
variable {Οββ : R β+* Rβ} {Οββ : Rβ β+* Rβ} {Οββ : R β+* Rβ} [RingHomCompTriple Οββ Οββ Οββ]
variable (f : M βββ[Οββ] Mβ) (g : Mβ βββ[Οββ] Mβ)
/-- The restriction of a linear map `f : M β Mβ` to a submodule `p β M` gives a linear map
`p β Mβ`. -/
def domRestrict (f : M βββ[Οββ] Mβ) (p : Submodule R M) : p βββ[Οββ] Mβ :=
f.comp p.subtype
@[simp]
theorem domRestrict_apply (f : M βββ[Οββ] Mβ) (p : Submodule R M) (x : p) :
f.domRestrict p x = f x :=
rfl
/-- A linear map `f : Mβ β M` whose values lie in a submodule `p β M` can be restricted to a
linear map Mβ β p.
See also `LinearMap.codLift`. -/
def codRestrict (p : Submodule Rβ Mβ) (f : M βββ[Οββ] Mβ) (h : β c, f c β p) : M βββ[Οββ] p where
toFun c := β¨f c, h cβ©
map_add' _ _ := by simp
map_smul' _ _ := by simp
@[simp]
theorem codRestrict_apply (p : Submodule Rβ Mβ) (f : M βββ[Οββ] Mβ) {h} (x : M) :
(codRestrict p f h x : Mβ) = f x :=
rfl
@[simp]
theorem comp_codRestrict (p : Submodule Rβ Mβ) (h : β b, g b β p) :
((codRestrict p g h).comp f : M βββ[Οββ] p) = codRestrict p (g.comp f) fun _ => h _ :=
ext fun _ => rfl
@[simp]
theorem subtype_comp_codRestrict (p : Submodule Rβ Mβ) (h : β b, f b β p) :
p.subtype.comp (codRestrict p f h) = f :=
ext fun _ => rfl
section
variable {Mβ' : Type*} [AddCommMonoid Mβ'] [Module Rβ Mβ']
(p : Mβ' ββ[Rβ] Mβ) (hp : Injective p) (h : β c, f c β range p)
/-- A linear map `f : M β Mβ` whose values lie in the image of an injective linear map
`p : Mβ' β Mβ` admits a unique lift to a linear map `M β Mβ'`. -/
noncomputable def codLift :
M βββ[Οββ] Mβ' where
toFun c := (h c).choose
map_add' b c := by apply hp; simp_rw [map_add, (h _).choose_spec, β map_add, (h _).choose_spec]
map_smul' r c := by apply hp; simp_rw [map_smul, (h _).choose_spec, LinearMap.map_smulββ]
@[simp] theorem codLift_apply (x : M) :
(f.codLift p hp h x) = (h x).choose :=
rfl
@[simp]
theorem comp_codLift :
p.comp (f.codLift p hp h) = f := by
ext x
rw [comp_apply, codLift_apply, (h x).choose_spec]
end
/-- Restrict domain and codomain of a linear map. -/
def restrict (f : M ββ[R] Mβ) {p : Submodule R M} {q : Submodule R Mβ} (hf : β x β p, f x β q) :
p ββ[R] q :=
(f.domRestrict p).codRestrict q <| SetLike.forall.2 hf
@[simp]
theorem restrict_coe_apply (f : M ββ[R] Mβ) {p : Submodule R M} {q : Submodule R Mβ}
(hf : β x β p, f x β q) (x : p) : β(f.restrict hf x) = f x :=
rfl
theorem restrict_apply {f : M ββ[R] Mβ} {p : Submodule R M} {q : Submodule R Mβ}
(hf : β x β p, f x β q) (x : p) : f.restrict hf x = β¨f x, hf x.1 x.2β© :=
rfl
lemma restrict_sub {R M Mβ : Type*}
[Ring R] [AddCommGroup M] [AddCommGroup Mβ] [Module R M] [Module R Mβ]
{p : Submodule R M} {q : Submodule R Mβ} {f g : M ββ[R] Mβ}
(hf : MapsTo f p q) (hg : MapsTo g p q)
(hfg : MapsTo (f - g) p q := fun _ hx β¦ q.sub_mem (hf hx) (hg hx)) :
f.restrict hf - g.restrict hg = (f - g).restrict hfg := by
ext; simp
lemma restrict_comp
{Mβ Mβ : Type*} [AddCommMonoid Mβ] [AddCommMonoid Mβ] [Module R Mβ] [Module R Mβ]
{p : Submodule R M} {pβ : Submodule R Mβ} {pβ : Submodule R Mβ}
{f : M ββ[R] Mβ} {g : Mβ ββ[R] Mβ}
(hf : MapsTo f p pβ) (hg : MapsTo g pβ pβ) (hfg : MapsTo (g ββ f) p pβ := hg.comp hf) :
(g ββ f).restrict hfg = (g.restrict hg) ββ (f.restrict hf) :=
rfl
-- TODO Consider defining `Algebra R (p.compatibleMaps p)`, `AlgHom` version of `LinearMap.restrict`
lemma restrict_smul_one
{R M : Type*} [CommSemiring R] [AddCommMonoid M] [Module R M] {p : Submodule R M}
(ΞΌ : R) (h : β x β p, (ΞΌ β’ (1 : Module.End R M)) x β p := fun _ β¦ p.smul_mem ΞΌ) :
(ΞΌ β’ 1 : Module.End R M).restrict h = ΞΌ β’ (1 : Module.End R p) :=
rfl
lemma restrict_commute {f g : M ββ[R] M} (h : Commute f g) {p : Submodule R M}
(hf : MapsTo f p p) (hg : MapsTo g p p) :
Commute (f.restrict hf) (g.restrict hg) := by
change (f ββ g).restrict (hf.comp hg) = (g ββ f).restrict (hg.comp hf)
congr 1
theorem subtype_comp_restrict {f : M ββ[R] Mβ} {p : Submodule R M} {q : Submodule R Mβ}
(hf : β x β p, f x β q) : q.subtype.comp (f.restrict hf) = f.domRestrict p :=
rfl
theorem restrict_eq_codRestrict_domRestrict {f : M ββ[R] Mβ} {p : Submodule R M}
{q : Submodule R Mβ} (hf : β x β p, f x β q) :
f.restrict hf = (f.domRestrict p).codRestrict q fun x => hf x.1 x.2 :=
rfl
theorem restrict_eq_domRestrict_codRestrict {f : M ββ[R] Mβ} {p : Submodule R M}
{q : Submodule R Mβ} (hf : β x, f x β q) :
(f.restrict fun x _ => hf x) = (f.codRestrict q hf).domRestrict p :=
rfl
theorem sum_apply (t : Finset ΞΉ) (f : ΞΉ β M βββ[Οββ] Mβ) (b : M) :
(β d β t, f d) b = β d β t, f d b :=
_root_.map_sum ((AddMonoidHom.eval b).comp toAddMonoidHom') f _
@[simp, norm_cast]
theorem coeFn_sum {ΞΉ : Type*} (t : Finset ΞΉ) (f : ΞΉ β M βββ[Οββ] Mβ) :
β(β i β t, f i) = β i β t, (f i : M β Mβ) :=
| _root_.map_sum
(show AddMonoidHom (M βββ[Οββ] Mβ) (M β Mβ)
from { toFun := DFunLike.coe,
map_zero' := rfl
map_add' := fun _ _ => rfl }) _ _
| Mathlib/Algebra/Module/Submodule/LinearMap.lean | 263 | 268 |
/-
Copyright (c) 2017 Kim Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Tim Baumann, Stephen Morgan, Kim Morrison, Floris van Doorn
-/
import Mathlib.CategoryTheory.Functor.FullyFaithful
import Mathlib.CategoryTheory.ObjectProperty.FullSubcategory
import Mathlib.CategoryTheory.Whiskering
import Mathlib.CategoryTheory.EssentialImage
import Mathlib.Tactic.CategoryTheory.Slice
/-!
# Equivalence of categories
An equivalence of categories `C` and `D` is a pair of functors `F : C β₯€ D` and `G : D β₯€ C` such
that `Ξ· : π C β
F β G` and `Ξ΅ : G β F β
π D`. In many situations, equivalences are a better
notion of "sameness" of categories than the stricter isomorphism of categories.
Recall that one way to express that two functors `F : C β₯€ D` and `G : D β₯€ C` are adjoint is using
two natural transformations `Ξ· : π C βΆ F β G` and `Ξ΅ : G β F βΆ π D`, called the unit and the
counit, such that the compositions `F βΆ FGF βΆ F` and `G βΆ GFG βΆ G` are the identity. Unfortunately,
it is not the case that the natural isomorphisms `Ξ·` and `Ξ΅` in the definition of an equivalence
automatically give an adjunction. However, it is true that
* if one of the two compositions is the identity, then so is the other, and
* given an equivalence of categories, it is always possible to refine `Ξ·` in such a way that the
identities are satisfied.
For this reason, in mathlib we define an equivalence to be a "half-adjoint equivalence", which is
a tuple `(F, G, Ξ·, Ξ΅)` as in the first paragraph such that the composite `F βΆ FGF βΆ F` is the
identity. By the remark above, this already implies that the tuple is an "adjoint equivalence",
i.e., that the composite `G βΆ GFG βΆ G` is also the identity.
We also define essentially surjective functors and show that a functor is an equivalence if and only
if it is full, faithful and essentially surjective.
## Main definitions
* `Equivalence`: bundled (half-)adjoint equivalences of categories
* `Functor.EssSurj`: type class on a functor `F` containing the data of the preimages
and the isomorphisms `F.obj (preimage d) β
d`.
* `Functor.IsEquivalence`: type class on a functor `F` which is full, faithful and
essentially surjective.
## Main results
* `Equivalence.mk`: upgrade an equivalence to a (half-)adjoint equivalence
* `isEquivalence_iff_of_iso`: when `F` and `G` are isomorphic functors,
`F` is an equivalence iff `G` is.
* `Functor.asEquivalenceFunctor`: construction of an equivalence of categories from
a functor `F` which satisfies the property `F.IsEquivalence` (i.e. `F` is full, faithful
and essentially surjective).
## Notations
We write `C β D` (`\backcong`, not to be confused with `β
`/`\cong`) for a bundled equivalence.
-/
namespace CategoryTheory
open CategoryTheory.Functor NatIso Category
-- declare the `v`'s first; see `CategoryTheory.Category` for an explanation
universe vβ vβ vβ uβ uβ uβ
/-- We define an equivalence as a (half)-adjoint equivalence, a pair of functors with
a unit and counit which are natural isomorphisms and the triangle law `FΞ· β« Ξ΅F = 1`, or in other
words the composite `F βΆ FGF βΆ F` is the identity.
In `unit_inverse_comp`, we show that this is actually an adjoint equivalence, i.e., that the
composite `G βΆ GFG βΆ G` is also the identity.
The triangle equation is written as a family of equalities between morphisms, it is more
complicated if we write it as an equality of natural transformations, because then we would have
to insert natural transformations like `F βΆ F1`. -/
@[ext, stacks 001J]
structure Equivalence (C : Type uβ) (D : Type uβ) [Category.{vβ} C] [Category.{vβ} D] where mk' ::
/-- A functor in one direction -/
functor : C β₯€ D
/-- A functor in the other direction -/
inverse : D β₯€ C
/-- The composition `functor β inverse` is isomorphic to the identity -/
unitIso : π C β
functor β inverse
/-- The composition `inverse β functor` is also isomorphic to the identity -/
counitIso : inverse β functor β
π D
/-- The natural isomorphisms compose to the identity. -/
functor_unitIso_comp :
β X : C, functor.map (unitIso.hom.app X) β« counitIso.hom.app (functor.obj X) =
π (functor.obj X) := by aesop_cat
/-- We infix the usual notation for an equivalence -/
infixr:10 " β " => Equivalence
variable {C : Type uβ} [Category.{vβ} C] {D : Type uβ} [Category.{vβ} D]
namespace Equivalence
/-- The unit of an equivalence of categories. -/
abbrev unit (e : C β D) : π C βΆ e.functor β e.inverse :=
e.unitIso.hom
/-- The counit of an equivalence of categories. -/
abbrev counit (e : C β D) : e.inverse β e.functor βΆ π D :=
e.counitIso.hom
/-- The inverse of the unit of an equivalence of categories. -/
abbrev unitInv (e : C β D) : e.functor β e.inverse βΆ π C :=
e.unitIso.inv
/-- The inverse of the counit of an equivalence of categories. -/
abbrev counitInv (e : C β D) : π D βΆ e.inverse β e.functor :=
e.counitIso.inv
/- While these abbreviations are convenient, they also cause some trouble,
preventing structure projections from unfolding. -/
@[simp]
theorem Equivalence_mk'_unit (functor inverse unit_iso counit_iso f) :
(β¨functor, inverse, unit_iso, counit_iso, fβ© : C β D).unit = unit_iso.hom :=
rfl
@[simp]
theorem Equivalence_mk'_counit (functor inverse unit_iso counit_iso f) :
(β¨functor, inverse, unit_iso, counit_iso, fβ© : C β D).counit = counit_iso.hom :=
rfl
@[simp]
theorem Equivalence_mk'_unitInv (functor inverse unit_iso counit_iso f) :
(β¨functor, inverse, unit_iso, counit_iso, fβ© : C β D).unitInv = unit_iso.inv :=
rfl
@[simp]
theorem Equivalence_mk'_counitInv (functor inverse unit_iso counit_iso f) :
(β¨functor, inverse, unit_iso, counit_iso, fβ© : C β D).counitInv = counit_iso.inv :=
rfl
@[reassoc]
theorem counit_naturality (e : C β D) {X Y : D} (f : X βΆ Y) :
e.functor.map (e.inverse.map f) β« e.counit.app Y = e.counit.app X β« f :=
e.counit.naturality f
@[reassoc]
theorem unit_naturality (e : C β D) {X Y : C} (f : X βΆ Y) :
e.unit.app X β« e.inverse.map (e.functor.map f) = f β« e.unit.app Y :=
(e.unit.naturality f).symm
@[reassoc]
theorem counitInv_naturality (e : C β D) {X Y : D} (f : X βΆ Y) :
e.counitInv.app X β« e.functor.map (e.inverse.map f) = f β« e.counitInv.app Y :=
(e.counitInv.naturality f).symm
@[reassoc]
theorem unitInv_naturality (e : C β D) {X Y : C} (f : X βΆ Y) :
e.inverse.map (e.functor.map f) β« e.unitInv.app Y = e.unitInv.app X β« f :=
e.unitInv.naturality f
@[reassoc (attr := simp)]
theorem functor_unit_comp (e : C β D) (X : C) :
e.functor.map (e.unit.app X) β« e.counit.app (e.functor.obj X) = π (e.functor.obj X) :=
e.functor_unitIso_comp X
|
@[reassoc (attr := simp)]
theorem counitInv_functor_comp (e : C β D) (X : C) :
e.counitInv.app (e.functor.obj X) β« e.functor.map (e.unitInv.app X) = π (e.functor.obj X) := by
simpa using Iso.inv_eq_inv
| Mathlib/CategoryTheory/Equivalence.lean | 159 | 163 |
/-
Copyright (c) 2022 Joseph Myers. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Joseph Myers, Heather Macbeth
-/
import Mathlib.Analysis.InnerProductSpace.TwoDim
import Mathlib.Geometry.Euclidean.Angle.Unoriented.Basic
/-!
# Oriented angles.
This file defines oriented angles in real inner product spaces.
## Main definitions
* `Orientation.oangle` is the oriented angle between two vectors with respect to an orientation.
## Implementation notes
The definitions here use the `Real.angle` type, angles modulo `2 * Ο`. For some purposes,
angles modulo `Ο` are more convenient, because results are true for such angles with less
configuration dependence. Results that are only equalities modulo `Ο` can be represented
modulo `2 * Ο` as equalities of `(2 : β€) β’ ΞΈ`.
## References
* Evan Chen, Euclidean Geometry in Mathematical Olympiads.
-/
noncomputable section
open Module Complex
open scoped Real RealInnerProductSpace ComplexConjugate
namespace Orientation
attribute [local instance] Complex.finrank_real_complex_fact
variable {V V' : Type*}
variable [NormedAddCommGroup V] [NormedAddCommGroup V']
variable [InnerProductSpace β V] [InnerProductSpace β V']
variable [Fact (finrank β V = 2)] [Fact (finrank β V' = 2)] (o : Orientation β V (Fin 2))
local notation "Ο" => o.areaForm
/-- The oriented angle from `x` to `y`, modulo `2 * Ο`. If either vector is 0, this is 0.
See `InnerProductGeometry.angle` for the corresponding unoriented angle definition. -/
def oangle (x y : V) : Real.Angle :=
Complex.arg (o.kahler x y)
/-- Oriented angles are continuous when the vectors involved are nonzero. -/
@[fun_prop]
theorem continuousAt_oangle {x : V Γ V} (hx1 : x.1 β 0) (hx2 : x.2 β 0) :
ContinuousAt (fun y : V Γ V => o.oangle y.1 y.2) x := by
refine (Complex.continuousAt_arg_coe_angle ?_).comp ?_
Β· exact o.kahler_ne_zero hx1 hx2
exact ((continuous_ofReal.comp continuous_inner).add
((continuous_ofReal.comp o.areaForm'.continuousβ).mul continuous_const)).continuousAt
/-- If the first vector passed to `oangle` is 0, the result is 0. -/
@[simp]
theorem oangle_zero_left (x : V) : o.oangle 0 x = 0 := by simp [oangle]
/-- If the second vector passed to `oangle` is 0, the result is 0. -/
@[simp]
theorem oangle_zero_right (x : V) : o.oangle x 0 = 0 := by simp [oangle]
/-- If the two vectors passed to `oangle` are the same, the result is 0. -/
@[simp]
theorem oangle_self (x : V) : o.oangle x x = 0 := by
rw [oangle, kahler_apply_self, β ofReal_pow]
convert QuotientAddGroup.mk_zero (AddSubgroup.zmultiples (2 * Ο))
apply arg_ofReal_of_nonneg
positivity
/-- If the angle between two vectors is nonzero, the first vector is nonzero. -/
theorem left_ne_zero_of_oangle_ne_zero {x y : V} (h : o.oangle x y β 0) : x β 0 := by
rintro rfl; simp at h
/-- If the angle between two vectors is nonzero, the second vector is nonzero. -/
theorem right_ne_zero_of_oangle_ne_zero {x y : V} (h : o.oangle x y β 0) : y β 0 := by
rintro rfl; simp at h
/-- If the angle between two vectors is nonzero, the vectors are not equal. -/
theorem ne_of_oangle_ne_zero {x y : V} (h : o.oangle x y β 0) : x β y := by
rintro rfl; simp at h
/-- If the angle between two vectors is `Ο`, the first vector is nonzero. -/
theorem left_ne_zero_of_oangle_eq_pi {x y : V} (h : o.oangle x y = Ο) : x β 0 :=
o.left_ne_zero_of_oangle_ne_zero (h.symm βΈ Real.Angle.pi_ne_zero : o.oangle x y β 0)
/-- If the angle between two vectors is `Ο`, the second vector is nonzero. -/
theorem right_ne_zero_of_oangle_eq_pi {x y : V} (h : o.oangle x y = Ο) : y β 0 :=
o.right_ne_zero_of_oangle_ne_zero (h.symm βΈ Real.Angle.pi_ne_zero : o.oangle x y β 0)
/-- If the angle between two vectors is `Ο`, the vectors are not equal. -/
theorem ne_of_oangle_eq_pi {x y : V} (h : o.oangle x y = Ο) : x β y :=
o.ne_of_oangle_ne_zero (h.symm βΈ Real.Angle.pi_ne_zero : o.oangle x y β 0)
/-- If the angle between two vectors is `Ο / 2`, the first vector is nonzero. -/
theorem left_ne_zero_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = (Ο / 2 : β)) : x β 0 :=
o.left_ne_zero_of_oangle_ne_zero (h.symm βΈ Real.Angle.pi_div_two_ne_zero : o.oangle x y β 0)
/-- If the angle between two vectors is `Ο / 2`, the second vector is nonzero. -/
theorem right_ne_zero_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = (Ο / 2 : β)) : y β 0 :=
o.right_ne_zero_of_oangle_ne_zero (h.symm βΈ Real.Angle.pi_div_two_ne_zero : o.oangle x y β 0)
/-- If the angle between two vectors is `Ο / 2`, the vectors are not equal. -/
theorem ne_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = (Ο / 2 : β)) : x β y :=
o.ne_of_oangle_ne_zero (h.symm βΈ Real.Angle.pi_div_two_ne_zero : o.oangle x y β 0)
/-- If the angle between two vectors is `-Ο / 2`, the first vector is nonzero. -/
theorem left_ne_zero_of_oangle_eq_neg_pi_div_two {x y : V} (h : o.oangle x y = (-Ο / 2 : β)) :
x β 0 :=
o.left_ne_zero_of_oangle_ne_zero (h.symm βΈ Real.Angle.neg_pi_div_two_ne_zero : o.oangle x y β 0)
/-- If the angle between two vectors is `-Ο / 2`, the second vector is nonzero. -/
theorem right_ne_zero_of_oangle_eq_neg_pi_div_two {x y : V} (h : o.oangle x y = (-Ο / 2 : β)) :
y β 0 :=
o.right_ne_zero_of_oangle_ne_zero (h.symm βΈ Real.Angle.neg_pi_div_two_ne_zero : o.oangle x y β 0)
/-- If the angle between two vectors is `-Ο / 2`, the vectors are not equal. -/
theorem ne_of_oangle_eq_neg_pi_div_two {x y : V} (h : o.oangle x y = (-Ο / 2 : β)) : x β y :=
o.ne_of_oangle_ne_zero (h.symm βΈ Real.Angle.neg_pi_div_two_ne_zero : o.oangle x y β 0)
/-- If the sign of the angle between two vectors is nonzero, the first vector is nonzero. -/
theorem left_ne_zero_of_oangle_sign_ne_zero {x y : V} (h : (o.oangle x y).sign β 0) : x β 0 :=
o.left_ne_zero_of_oangle_ne_zero (Real.Angle.sign_ne_zero_iff.1 h).1
/-- If the sign of the angle between two vectors is nonzero, the second vector is nonzero. -/
theorem right_ne_zero_of_oangle_sign_ne_zero {x y : V} (h : (o.oangle x y).sign β 0) : y β 0 :=
o.right_ne_zero_of_oangle_ne_zero (Real.Angle.sign_ne_zero_iff.1 h).1
/-- If the sign of the angle between two vectors is nonzero, the vectors are not equal. -/
theorem ne_of_oangle_sign_ne_zero {x y : V} (h : (o.oangle x y).sign β 0) : x β y :=
o.ne_of_oangle_ne_zero (Real.Angle.sign_ne_zero_iff.1 h).1
/-- If the sign of the angle between two vectors is positive, the first vector is nonzero. -/
theorem left_ne_zero_of_oangle_sign_eq_one {x y : V} (h : (o.oangle x y).sign = 1) : x β 0 :=
o.left_ne_zero_of_oangle_sign_ne_zero (h.symm βΈ by decide : (o.oangle x y).sign β 0)
/-- If the sign of the angle between two vectors is positive, the second vector is nonzero. -/
theorem right_ne_zero_of_oangle_sign_eq_one {x y : V} (h : (o.oangle x y).sign = 1) : y β 0 :=
o.right_ne_zero_of_oangle_sign_ne_zero (h.symm βΈ by decide : (o.oangle x y).sign β 0)
/-- If the sign of the angle between two vectors is positive, the vectors are not equal. -/
theorem ne_of_oangle_sign_eq_one {x y : V} (h : (o.oangle x y).sign = 1) : x β y :=
o.ne_of_oangle_sign_ne_zero (h.symm βΈ by decide : (o.oangle x y).sign β 0)
/-- If the sign of the angle between two vectors is negative, the first vector is nonzero. -/
theorem left_ne_zero_of_oangle_sign_eq_neg_one {x y : V} (h : (o.oangle x y).sign = -1) : x β 0 :=
o.left_ne_zero_of_oangle_sign_ne_zero (h.symm βΈ by decide : (o.oangle x y).sign β 0)
/-- If the sign of the angle between two vectors is negative, the second vector is nonzero. -/
theorem right_ne_zero_of_oangle_sign_eq_neg_one {x y : V} (h : (o.oangle x y).sign = -1) : y β 0 :=
o.right_ne_zero_of_oangle_sign_ne_zero (h.symm βΈ by decide : (o.oangle x y).sign β 0)
/-- If the sign of the angle between two vectors is negative, the vectors are not equal. -/
theorem ne_of_oangle_sign_eq_neg_one {x y : V} (h : (o.oangle x y).sign = -1) : x β y :=
o.ne_of_oangle_sign_ne_zero (h.symm βΈ by decide : (o.oangle x y).sign β 0)
/-- Swapping the two vectors passed to `oangle` negates the angle. -/
theorem oangle_rev (x y : V) : o.oangle y x = -o.oangle x y := by
simp only [oangle, o.kahler_swap y x, Complex.arg_conj_coe_angle]
/-- Adding the angles between two vectors in each order results in 0. -/
@[simp]
theorem oangle_add_oangle_rev (x y : V) : o.oangle x y + o.oangle y x = 0 := by
simp [o.oangle_rev y x]
/-- Negating the first vector passed to `oangle` adds `Ο` to the angle. -/
theorem oangle_neg_left {x y : V} (hx : x β 0) (hy : y β 0) :
o.oangle (-x) y = o.oangle x y + Ο := by
simp only [oangle, map_neg]
convert Complex.arg_neg_coe_angle _
exact o.kahler_ne_zero hx hy
/-- Negating the second vector passed to `oangle` adds `Ο` to the angle. -/
theorem oangle_neg_right {x y : V} (hx : x β 0) (hy : y β 0) :
o.oangle x (-y) = o.oangle x y + Ο := by
simp only [oangle, map_neg]
convert Complex.arg_neg_coe_angle _
exact o.kahler_ne_zero hx hy
/-- Negating the first vector passed to `oangle` does not change twice the angle. -/
@[simp]
theorem two_zsmul_oangle_neg_left (x y : V) :
(2 : β€) β’ o.oangle (-x) y = (2 : β€) β’ o.oangle x y := by
by_cases hx : x = 0
Β· simp [hx]
Β· by_cases hy : y = 0
Β· simp [hy]
Β· simp [o.oangle_neg_left hx hy]
/-- Negating the second vector passed to `oangle` does not change twice the angle. -/
@[simp]
theorem two_zsmul_oangle_neg_right (x y : V) :
(2 : β€) β’ o.oangle x (-y) = (2 : β€) β’ o.oangle x y := by
by_cases hx : x = 0
Β· simp [hx]
Β· by_cases hy : y = 0
Β· simp [hy]
Β· simp [o.oangle_neg_right hx hy]
/-- Negating both vectors passed to `oangle` does not change the angle. -/
@[simp]
theorem oangle_neg_neg (x y : V) : o.oangle (-x) (-y) = o.oangle x y := by simp [oangle]
/-- Negating the first vector produces the same angle as negating the second vector. -/
theorem oangle_neg_left_eq_neg_right (x y : V) : o.oangle (-x) y = o.oangle x (-y) := by
rw [β neg_neg y, oangle_neg_neg, neg_neg]
/-- The angle between the negation of a nonzero vector and that vector is `Ο`. -/
@[simp]
theorem oangle_neg_self_left {x : V} (hx : x β 0) : o.oangle (-x) x = Ο := by
simp [oangle_neg_left, hx]
/-- The angle between a nonzero vector and its negation is `Ο`. -/
@[simp]
theorem oangle_neg_self_right {x : V} (hx : x β 0) : o.oangle x (-x) = Ο := by
simp [oangle_neg_right, hx]
/-- Twice the angle between the negation of a vector and that vector is 0. -/
theorem two_zsmul_oangle_neg_self_left (x : V) : (2 : β€) β’ o.oangle (-x) x = 0 := by
by_cases hx : x = 0 <;> simp [hx]
/-- Twice the angle between a vector and its negation is 0. -/
theorem two_zsmul_oangle_neg_self_right (x : V) : (2 : β€) β’ o.oangle x (-x) = 0 := by
by_cases hx : x = 0 <;> simp [hx]
/-- Adding the angles between two vectors in each order, with the first vector in each angle
negated, results in 0. -/
@[simp]
theorem oangle_add_oangle_rev_neg_left (x y : V) : o.oangle (-x) y + o.oangle (-y) x = 0 := by
rw [oangle_neg_left_eq_neg_right, oangle_rev, neg_add_cancel]
/-- Adding the angles between two vectors in each order, with the second vector in each angle
negated, results in 0. -/
@[simp]
theorem oangle_add_oangle_rev_neg_right (x y : V) : o.oangle x (-y) + o.oangle y (-x) = 0 := by
rw [o.oangle_rev (-x), oangle_neg_left_eq_neg_right, add_neg_cancel]
/-- Multiplying the first vector passed to `oangle` by a positive real does not change the
angle. -/
@[simp]
theorem oangle_smul_left_of_pos (x y : V) {r : β} (hr : 0 < r) :
o.oangle (r β’ x) y = o.oangle x y := by simp [oangle, Complex.arg_real_mul _ hr]
/-- Multiplying the second vector passed to `oangle` by a positive real does not change the
angle. -/
@[simp]
theorem oangle_smul_right_of_pos (x y : V) {r : β} (hr : 0 < r) :
o.oangle x (r β’ y) = o.oangle x y := by simp [oangle, Complex.arg_real_mul _ hr]
/-- Multiplying the first vector passed to `oangle` by a negative real produces the same angle
as negating that vector. -/
@[simp]
theorem oangle_smul_left_of_neg (x y : V) {r : β} (hr : r < 0) :
o.oangle (r β’ x) y = o.oangle (-x) y := by
rw [β neg_neg r, neg_smul, β smul_neg, o.oangle_smul_left_of_pos _ _ (neg_pos_of_neg hr)]
/-- Multiplying the second vector passed to `oangle` by a negative real produces the same angle
as negating that vector. -/
@[simp]
theorem oangle_smul_right_of_neg (x y : V) {r : β} (hr : r < 0) :
o.oangle x (r β’ y) = o.oangle x (-y) := by
rw [β neg_neg r, neg_smul, β smul_neg, o.oangle_smul_right_of_pos _ _ (neg_pos_of_neg hr)]
/-- The angle between a nonnegative multiple of a vector and that vector is 0. -/
@[simp]
theorem oangle_smul_left_self_of_nonneg (x : V) {r : β} (hr : 0 β€ r) : o.oangle (r β’ x) x = 0 := by
rcases hr.lt_or_eq with (h | h)
Β· simp [h]
Β· simp [h.symm]
/-- The angle between a vector and a nonnegative multiple of that vector is 0. -/
@[simp]
theorem oangle_smul_right_self_of_nonneg (x : V) {r : β} (hr : 0 β€ r) : o.oangle x (r β’ x) = 0 := by
rcases hr.lt_or_eq with (h | h)
Β· simp [h]
Β· simp [h.symm]
/-- The angle between two nonnegative multiples of the same vector is 0. -/
@[simp]
theorem oangle_smul_smul_self_of_nonneg (x : V) {rβ rβ : β} (hrβ : 0 β€ rβ) (hrβ : 0 β€ rβ) :
o.oangle (rβ β’ x) (rβ β’ x) = 0 := by
rcases hrβ.lt_or_eq with (h | h)
Β· simp [h, hrβ]
Β· simp [h.symm]
/-- Multiplying the first vector passed to `oangle` by a nonzero real does not change twice the
angle. -/
@[simp]
theorem two_zsmul_oangle_smul_left_of_ne_zero (x y : V) {r : β} (hr : r β 0) :
(2 : β€) β’ o.oangle (r β’ x) y = (2 : β€) β’ o.oangle x y := by
rcases hr.lt_or_lt with (h | h) <;> simp [h]
/-- Multiplying the second vector passed to `oangle` by a nonzero real does not change twice the
angle. -/
@[simp]
theorem two_zsmul_oangle_smul_right_of_ne_zero (x y : V) {r : β} (hr : r β 0) :
(2 : β€) β’ o.oangle x (r β’ y) = (2 : β€) β’ o.oangle x y := by
rcases hr.lt_or_lt with (h | h) <;> simp [h]
/-- Twice the angle between a multiple of a vector and that vector is 0. -/
@[simp]
theorem two_zsmul_oangle_smul_left_self (x : V) {r : β} : (2 : β€) β’ o.oangle (r β’ x) x = 0 := by
rcases lt_or_le r 0 with (h | h) <;> simp [h]
/-- Twice the angle between a vector and a multiple of that vector is 0. -/
@[simp]
theorem two_zsmul_oangle_smul_right_self (x : V) {r : β} : (2 : β€) β’ o.oangle x (r β’ x) = 0 := by
rcases lt_or_le r 0 with (h | h) <;> simp [h]
/-- Twice the angle between two multiples of a vector is 0. -/
@[simp]
theorem two_zsmul_oangle_smul_smul_self (x : V) {rβ rβ : β} :
(2 : β€) β’ o.oangle (rβ β’ x) (rβ β’ x) = 0 := by by_cases h : rβ = 0 <;> simp [h]
/-- If the spans of two vectors are equal, twice angles with those vectors on the left are
equal. -/
theorem two_zsmul_oangle_left_of_span_eq {x y : V} (z : V) (h : (β β x) = β β y) :
(2 : β€) β’ o.oangle x z = (2 : β€) β’ o.oangle y z := by
rw [Submodule.span_singleton_eq_span_singleton] at h
rcases h with β¨r, rflβ©
exact (o.two_zsmul_oangle_smul_left_of_ne_zero _ _ (Units.ne_zero _)).symm
/-- If the spans of two vectors are equal, twice angles with those vectors on the right are
equal. -/
theorem two_zsmul_oangle_right_of_span_eq (x : V) {y z : V} (h : (β β y) = β β z) :
(2 : β€) β’ o.oangle x y = (2 : β€) β’ o.oangle x z := by
rw [Submodule.span_singleton_eq_span_singleton] at h
rcases h with β¨r, rflβ©
exact (o.two_zsmul_oangle_smul_right_of_ne_zero _ _ (Units.ne_zero _)).symm
/-- If the spans of two pairs of vectors are equal, twice angles between those vectors are
equal. -/
theorem two_zsmul_oangle_of_span_eq_of_span_eq {w x y z : V} (hwx : (β β w) = β β x)
(hyz : (β β y) = β β z) : (2 : β€) β’ o.oangle w y = (2 : β€) β’ o.oangle x z := by
rw [o.two_zsmul_oangle_left_of_span_eq y hwx, o.two_zsmul_oangle_right_of_span_eq x hyz]
/-- The oriented angle between two vectors is zero if and only if the angle with the vectors
swapped is zero. -/
theorem oangle_eq_zero_iff_oangle_rev_eq_zero {x y : V} : o.oangle x y = 0 β o.oangle y x = 0 := by
rw [oangle_rev, neg_eq_zero]
/-- The oriented angle between two vectors is zero if and only if they are on the same ray. -/
theorem oangle_eq_zero_iff_sameRay {x y : V} : o.oangle x y = 0 β SameRay β x y := by
rw [oangle, kahler_apply_apply, Complex.arg_coe_angle_eq_iff_eq_toReal, Real.Angle.toReal_zero,
Complex.arg_eq_zero_iff]
simpa using o.nonneg_inner_and_areaForm_eq_zero_iff_sameRay x y
/-- The oriented angle between two vectors is `Ο` if and only if the angle with the vectors
swapped is `Ο`. -/
theorem oangle_eq_pi_iff_oangle_rev_eq_pi {x y : V} : o.oangle x y = Ο β o.oangle y x = Ο := by
rw [oangle_rev, neg_eq_iff_eq_neg, Real.Angle.neg_coe_pi]
/-- The oriented angle between two vectors is `Ο` if and only they are nonzero and the first is
on the same ray as the negation of the second. -/
theorem oangle_eq_pi_iff_sameRay_neg {x y : V} :
o.oangle x y = Ο β x β 0 β§ y β 0 β§ SameRay β x (-y) := by
rw [β o.oangle_eq_zero_iff_sameRay]
constructor
Β· intro h
by_cases hx : x = 0; Β· simp [hx, Real.Angle.pi_ne_zero.symm] at h
by_cases hy : y = 0; Β· simp [hy, Real.Angle.pi_ne_zero.symm] at h
refine β¨hx, hy, ?_β©
rw [o.oangle_neg_right hx hy, h, Real.Angle.coe_pi_add_coe_pi]
Β· rintro β¨hx, hy, hβ©
rwa [o.oangle_neg_right hx hy, β Real.Angle.sub_coe_pi_eq_add_coe_pi, sub_eq_zero] at h
/-- The oriented angle between two vectors is zero or `Ο` if and only if those two vectors are
not linearly independent. -/
theorem oangle_eq_zero_or_eq_pi_iff_not_linearIndependent {x y : V} :
o.oangle x y = 0 β¨ o.oangle x y = Ο β Β¬LinearIndependent β ![x, y] := by
rw [oangle_eq_zero_iff_sameRay, oangle_eq_pi_iff_sameRay_neg,
sameRay_or_ne_zero_and_sameRay_neg_iff_not_linearIndependent]
/-- The oriented angle between two vectors is zero or `Ο` if and only if the first vector is zero
or the second is a multiple of the first. -/
theorem oangle_eq_zero_or_eq_pi_iff_right_eq_smul {x y : V} :
o.oangle x y = 0 β¨ o.oangle x y = Ο β x = 0 β¨ β r : β, y = r β’ x := by
rw [oangle_eq_zero_iff_sameRay, oangle_eq_pi_iff_sameRay_neg]
refine β¨fun h => ?_, fun h => ?_β©
Β· rcases h with (h | β¨-, -, hβ©)
Β· by_cases hx : x = 0; Β· simp [hx]
obtain β¨r, -, rflβ© := h.exists_nonneg_left hx
exact Or.inr β¨r, rflβ©
Β· by_cases hx : x = 0; Β· simp [hx]
obtain β¨r, -, hyβ© := h.exists_nonneg_left hx
refine Or.inr β¨-r, ?_β©
simp [hy]
Β· rcases h with (rfl | β¨r, rflβ©); Β· simp
by_cases hx : x = 0; Β· simp [hx]
rcases lt_trichotomy r 0 with (hr | hr | hr)
Β· rw [β neg_smul]
exact Or.inr β¨hx, smul_ne_zero hr.ne hx,
SameRay.sameRay_pos_smul_right x (Left.neg_pos_iff.2 hr)β©
Β· simp [hr]
Β· exact Or.inl (SameRay.sameRay_pos_smul_right x hr)
/-- The oriented angle between two vectors is not zero or `Ο` if and only if those two vectors
are linearly independent. -/
theorem oangle_ne_zero_and_ne_pi_iff_linearIndependent {x y : V} :
o.oangle x y β 0 β§ o.oangle x y β Ο β LinearIndependent β ![x, y] := by
rw [β not_or, β not_iff_not, Classical.not_not,
oangle_eq_zero_or_eq_pi_iff_not_linearIndependent]
/-- Two vectors are equal if and only if they have equal norms and zero angle between them. -/
theorem eq_iff_norm_eq_and_oangle_eq_zero (x y : V) : x = y β βxβ = βyβ β§ o.oangle x y = 0 := by
rw [oangle_eq_zero_iff_sameRay]
constructor
Β· rintro rfl
simp; rfl
Β· rcases eq_or_ne y 0 with (rfl | hy)
Β· simp
rintro β¨hβ, hββ©
obtain β¨r, hr, rflβ© := hβ.exists_nonneg_right hy
have : βyβ β 0 := by simpa using hy
obtain rfl : r = 1 := by
apply mul_right_cancelβ this
simpa [norm_smul, abs_of_nonneg hr] using hβ
simp
/-- Two vectors with equal norms are equal if and only if they have zero angle between them. -/
theorem eq_iff_oangle_eq_zero_of_norm_eq {x y : V} (h : βxβ = βyβ) : x = y β o.oangle x y = 0 :=
β¨fun he => ((o.eq_iff_norm_eq_and_oangle_eq_zero x y).1 he).2, fun ha =>
(o.eq_iff_norm_eq_and_oangle_eq_zero x y).2 β¨h, haβ©β©
/-- Two vectors with zero angle between them are equal if and only if they have equal norms. -/
theorem eq_iff_norm_eq_of_oangle_eq_zero {x y : V} (h : o.oangle x y = 0) : x = y β βxβ = βyβ :=
β¨fun he => ((o.eq_iff_norm_eq_and_oangle_eq_zero x y).1 he).1, fun hn =>
(o.eq_iff_norm_eq_and_oangle_eq_zero x y).2 β¨hn, hβ©β©
/-- Given three nonzero vectors, the angle between the first and the second plus the angle
between the second and the third equals the angle between the first and the third. -/
@[simp]
theorem oangle_add {x y z : V} (hx : x β 0) (hy : y β 0) (hz : z β 0) :
o.oangle x y + o.oangle y z = o.oangle x z := by
simp_rw [oangle]
rw [β Complex.arg_mul_coe_angle, o.kahler_mul y x z]
Β· congr 1
exact mod_cast Complex.arg_real_mul _ (by positivity : 0 < βyβ ^ 2)
Β· exact o.kahler_ne_zero hx hy
Β· exact o.kahler_ne_zero hy hz
/-- Given three nonzero vectors, the angle between the second and the third plus the angle
between the first and the second equals the angle between the first and the third. -/
@[simp]
theorem oangle_add_swap {x y z : V} (hx : x β 0) (hy : y β 0) (hz : z β 0) :
o.oangle y z + o.oangle x y = o.oangle x z := by rw [add_comm, o.oangle_add hx hy hz]
/-- Given three nonzero vectors, the angle between the first and the third minus the angle
between the first and the second equals the angle between the second and the third. -/
@[simp]
theorem oangle_sub_left {x y z : V} (hx : x β 0) (hy : y β 0) (hz : z β 0) :
o.oangle x z - o.oangle x y = o.oangle y z := by
rw [sub_eq_iff_eq_add, o.oangle_add_swap hx hy hz]
/-- Given three nonzero vectors, the angle between the first and the third minus the angle
between the second and the third equals the angle between the first and the second. -/
@[simp]
theorem oangle_sub_right {x y z : V} (hx : x β 0) (hy : y β 0) (hz : z β 0) :
o.oangle x z - o.oangle y z = o.oangle x y := by rw [sub_eq_iff_eq_add, o.oangle_add hx hy hz]
/-- Given three nonzero vectors, adding the angles between them in cyclic order results in 0. -/
@[simp]
theorem oangle_add_cyc3 {x y z : V} (hx : x β 0) (hy : y β 0) (hz : z β 0) :
o.oangle x y + o.oangle y z + o.oangle z x = 0 := by simp [hx, hy, hz]
/-- Given three nonzero vectors, adding the angles between them in cyclic order, with the first
vector in each angle negated, results in Ο. If the vectors add to 0, this is a version of the
sum of the angles of a triangle. -/
@[simp]
theorem oangle_add_cyc3_neg_left {x y z : V} (hx : x β 0) (hy : y β 0) (hz : z β 0) :
o.oangle (-x) y + o.oangle (-y) z + o.oangle (-z) x = Ο := by
rw [o.oangle_neg_left hx hy, o.oangle_neg_left hy hz, o.oangle_neg_left hz hx,
show o.oangle x y + Ο + (o.oangle y z + Ο) + (o.oangle z x + Ο) =
o.oangle x y + o.oangle y z + o.oangle z x + (Ο + Ο + Ο : Real.Angle) by abel,
o.oangle_add_cyc3 hx hy hz, Real.Angle.coe_pi_add_coe_pi, zero_add, zero_add]
/-- Given three nonzero vectors, adding the angles between them in cyclic order, with the second
vector in each angle negated, results in Ο. If the vectors add to 0, this is a version of the
sum of the angles of a triangle. -/
@[simp]
theorem oangle_add_cyc3_neg_right {x y z : V} (hx : x β 0) (hy : y β 0) (hz : z β 0) :
o.oangle x (-y) + o.oangle y (-z) + o.oangle z (-x) = Ο := by
simp_rw [β oangle_neg_left_eq_neg_right, o.oangle_add_cyc3_neg_left hx hy hz]
/-- Pons asinorum, oriented vector angle form. -/
theorem oangle_sub_eq_oangle_sub_rev_of_norm_eq {x y : V} (h : βxβ = βyβ) :
o.oangle x (x - y) = o.oangle (y - x) y := by simp [oangle, h]
/-- The angle at the apex of an isosceles triangle is `Ο` minus twice a base angle, oriented
vector angle form. -/
theorem oangle_eq_pi_sub_two_zsmul_oangle_sub_of_norm_eq {x y : V} (hn : x β y) (h : βxβ = βyβ) :
o.oangle y x = Ο - (2 : β€) β’ o.oangle (y - x) y := by
rw [two_zsmul]
nth_rw 1 [β o.oangle_sub_eq_oangle_sub_rev_of_norm_eq h]
rw [eq_sub_iff_add_eq, β oangle_neg_neg, β add_assoc]
have hy : y β 0 := by
rintro rfl
rw [norm_zero, norm_eq_zero] at h
exact hn h
have hx : x β 0 := norm_ne_zero_iff.1 (h.symm βΈ norm_ne_zero_iff.2 hy)
convert o.oangle_add_cyc3_neg_right (neg_ne_zero.2 hy) hx (sub_ne_zero_of_ne hn.symm) using 1
simp
/-- The angle between two vectors, with respect to an orientation given by `Orientation.map`
with a linear isometric equivalence, equals the angle between those two vectors, transformed by
the inverse of that equivalence, with respect to the original orientation. -/
@[simp]
theorem oangle_map (x y : V') (f : V ββα΅’[β] V') :
(Orientation.map (Fin 2) f.toLinearEquiv o).oangle x y = o.oangle (f.symm x) (f.symm y) := by
simp [oangle, o.kahler_map]
@[simp]
protected theorem _root_.Complex.oangle (w z : β) :
Complex.orientation.oangle w z = Complex.arg (conj w * z) := by
simp [oangle, mul_comm z]
/-- The oriented angle on an oriented real inner product space of dimension 2 can be evaluated in
terms of a complex-number representation of the space. -/
theorem oangle_map_complex (f : V ββα΅’[β] β)
(hf : Orientation.map (Fin 2) f.toLinearEquiv o = Complex.orientation) (x y : V) :
o.oangle x y = Complex.arg (conj (f x) * f y) := by
rw [β Complex.oangle, β hf, o.oangle_map]
iterate 2 rw [LinearIsometryEquiv.symm_apply_apply]
/-- Negating the orientation negates the value of `oangle`. -/
theorem oangle_neg_orientation_eq_neg (x y : V) : (-o).oangle x y = -o.oangle x y := by
simp [oangle]
/-- The inner product of two vectors is the product of the norms and the cosine of the oriented
angle between the vectors. -/
theorem inner_eq_norm_mul_norm_mul_cos_oangle (x y : V) :
βͺx, yβ« = βxβ * βyβ * Real.Angle.cos (o.oangle x y) := by
by_cases hx : x = 0; Β· simp [hx]
by_cases hy : y = 0; Β· simp [hy]
rw [oangle, Real.Angle.cos_coe, Complex.cos_arg, o.norm_kahler]
Β· simp only [kahler_apply_apply, real_smul, add_re, ofReal_re, mul_re, I_re, ofReal_im]
field_simp
Β· exact o.kahler_ne_zero hx hy
/-- The cosine of the oriented angle between two nonzero vectors is the inner product divided by
the product of the norms. -/
theorem cos_oangle_eq_inner_div_norm_mul_norm {x y : V} (hx : x β 0) (hy : y β 0) :
Real.Angle.cos (o.oangle x y) = βͺx, yβ« / (βxβ * βyβ) := by
rw [o.inner_eq_norm_mul_norm_mul_cos_oangle]
field_simp [norm_ne_zero_iff.2 hx, norm_ne_zero_iff.2 hy]
/-- The cosine of the oriented angle between two nonzero vectors equals that of the unoriented
angle. -/
theorem cos_oangle_eq_cos_angle {x y : V} (hx : x β 0) (hy : y β 0) :
Real.Angle.cos (o.oangle x y) = Real.cos (InnerProductGeometry.angle x y) := by
rw [o.cos_oangle_eq_inner_div_norm_mul_norm hx hy, InnerProductGeometry.cos_angle]
/-- The oriented angle between two nonzero vectors is plus or minus the unoriented angle. -/
theorem oangle_eq_angle_or_eq_neg_angle {x y : V} (hx : x β 0) (hy : y β 0) :
o.oangle x y = InnerProductGeometry.angle x y β¨
o.oangle x y = -InnerProductGeometry.angle x y :=
Real.Angle.cos_eq_real_cos_iff_eq_or_eq_neg.1 <| o.cos_oangle_eq_cos_angle hx hy
/-- The unoriented angle between two nonzero vectors is the absolute value of the oriented angle,
converted to a real. -/
theorem angle_eq_abs_oangle_toReal {x y : V} (hx : x β 0) (hy : y β 0) :
InnerProductGeometry.angle x y = |(o.oangle x y).toReal| := by
have h0 := InnerProductGeometry.angle_nonneg x y
have hpi := InnerProductGeometry.angle_le_pi x y
rcases o.oangle_eq_angle_or_eq_neg_angle hx hy with (h | h)
Β· rw [h, eq_comm, Real.Angle.abs_toReal_coe_eq_self_iff]
exact β¨h0, hpiβ©
Β· rw [h, eq_comm, Real.Angle.abs_toReal_neg_coe_eq_self_iff]
exact β¨h0, hpiβ©
/-- If the sign of the oriented angle between two vectors is zero, either one of the vectors is
zero or the unoriented angle is 0 or Ο. -/
theorem eq_zero_or_angle_eq_zero_or_pi_of_sign_oangle_eq_zero {x y : V}
(h : (o.oangle x y).sign = 0) :
x = 0 β¨ y = 0 β¨ InnerProductGeometry.angle x y = 0 β¨ InnerProductGeometry.angle x y = Ο := by
by_cases hx : x = 0; Β· simp [hx]
by_cases hy : y = 0; Β· simp [hy]
rw [o.angle_eq_abs_oangle_toReal hx hy]
rw [Real.Angle.sign_eq_zero_iff] at h
rcases h with (h | h) <;> simp [h, Real.pi_pos.le]
/-- If two unoriented angles are equal, and the signs of the corresponding oriented angles are
equal, then the oriented angles are equal (even in degenerate cases). -/
theorem oangle_eq_of_angle_eq_of_sign_eq {w x y z : V}
(h : InnerProductGeometry.angle w x = InnerProductGeometry.angle y z)
(hs : (o.oangle w x).sign = (o.oangle y z).sign) : o.oangle w x = o.oangle y z := by
by_cases h0 : (w = 0 β¨ x = 0) β¨ y = 0 β¨ z = 0
Β· have hs' : (o.oangle w x).sign = 0 β§ (o.oangle y z).sign = 0 := by
rcases h0 with ((rfl | rfl) | rfl | rfl)
Β· simpa using hs.symm
Β· simpa using hs.symm
Β· simpa using hs
Β· simpa using hs
rcases hs' with β¨hswx, hsyzβ©
have h' : InnerProductGeometry.angle w x = Ο / 2 β§ InnerProductGeometry.angle y z = Ο / 2 := by
rcases h0 with ((rfl | rfl) | rfl | rfl)
Β· simpa using h.symm
Β· simpa using h.symm
Β· simpa using h
Β· simpa using h
rcases h' with β¨hwx, hyzβ©
have hpi : Ο / 2 β Ο := by
intro hpi
rw [div_eq_iff, eq_comm, β sub_eq_zero, mul_two, add_sub_cancel_right] at hpi
Β· exact Real.pi_pos.ne.symm hpi
Β· exact two_ne_zero
have h0wx : w = 0 β¨ x = 0 := by
have h0' := o.eq_zero_or_angle_eq_zero_or_pi_of_sign_oangle_eq_zero hswx
simpa [hwx, Real.pi_pos.ne.symm, hpi] using h0'
have h0yz : y = 0 β¨ z = 0 := by
have h0' := o.eq_zero_or_angle_eq_zero_or_pi_of_sign_oangle_eq_zero hsyz
simpa [hyz, Real.pi_pos.ne.symm, hpi] using h0'
rcases h0wx with (h0wx | h0wx) <;> rcases h0yz with (h0yz | h0yz) <;> simp [h0wx, h0yz]
Β· push_neg at h0
rw [Real.Angle.eq_iff_abs_toReal_eq_of_sign_eq hs]
rwa [o.angle_eq_abs_oangle_toReal h0.1.1 h0.1.2,
o.angle_eq_abs_oangle_toReal h0.2.1 h0.2.2] at h
/-- If the signs of two oriented angles between nonzero vectors are equal, the oriented angles are
equal if and only if the unoriented angles are equal. -/
theorem angle_eq_iff_oangle_eq_of_sign_eq {w x y z : V} (hw : w β 0) (hx : x β 0) (hy : y β 0)
(hz : z β 0) (hs : (o.oangle w x).sign = (o.oangle y z).sign) :
InnerProductGeometry.angle w x = InnerProductGeometry.angle y z β
o.oangle w x = o.oangle y z := by
refine β¨fun h => o.oangle_eq_of_angle_eq_of_sign_eq h hs, fun h => ?_β©
rw [o.angle_eq_abs_oangle_toReal hw hx, o.angle_eq_abs_oangle_toReal hy hz, h]
/-- The oriented angle between two vectors equals the unoriented angle if the sign is positive. -/
theorem oangle_eq_angle_of_sign_eq_one {x y : V} (h : (o.oangle x y).sign = 1) :
o.oangle x y = InnerProductGeometry.angle x y := by
by_cases hx : x = 0; Β· exfalso; simp [hx] at h
by_cases hy : y = 0; Β· exfalso; simp [hy] at h
refine (o.oangle_eq_angle_or_eq_neg_angle hx hy).resolve_right ?_
intro hxy
rw [hxy, Real.Angle.sign_neg, neg_eq_iff_eq_neg, β SignType.neg_iff, β not_le] at h
exact h (Real.Angle.sign_coe_nonneg_of_nonneg_of_le_pi (InnerProductGeometry.angle_nonneg _ _)
(InnerProductGeometry.angle_le_pi _ _))
/-- The oriented angle between two vectors equals minus the unoriented angle if the sign is
negative. -/
theorem oangle_eq_neg_angle_of_sign_eq_neg_one {x y : V} (h : (o.oangle x y).sign = -1) :
o.oangle x y = -InnerProductGeometry.angle x y := by
by_cases hx : x = 0; Β· exfalso; simp [hx] at h
by_cases hy : y = 0; Β· exfalso; simp [hy] at h
refine (o.oangle_eq_angle_or_eq_neg_angle hx hy).resolve_left ?_
intro hxy
rw [hxy, β SignType.neg_iff, β not_le] at h
exact h (Real.Angle.sign_coe_nonneg_of_nonneg_of_le_pi (InnerProductGeometry.angle_nonneg _ _)
(InnerProductGeometry.angle_le_pi _ _))
/-- The oriented angle between two nonzero vectors is zero if and only if the unoriented angle
is zero. -/
theorem oangle_eq_zero_iff_angle_eq_zero {x y : V} (hx : x β 0) (hy : y β 0) :
o.oangle x y = 0 β InnerProductGeometry.angle x y = 0 := by
refine β¨fun h => ?_, fun h => ?_β©
Β· simpa [o.angle_eq_abs_oangle_toReal hx hy]
Β· have ha := o.oangle_eq_angle_or_eq_neg_angle hx hy
rw [h] at ha
simpa using ha
/-- The oriented angle between two vectors is `Ο` if and only if the unoriented angle is `Ο`. -/
theorem oangle_eq_pi_iff_angle_eq_pi {x y : V} :
o.oangle x y = Ο β InnerProductGeometry.angle x y = Ο := by
by_cases hx : x = 0
Β· simp [hx, Real.Angle.pi_ne_zero.symm, div_eq_mul_inv, mul_right_eq_selfβ, not_or,
Real.pi_ne_zero]
by_cases hy : y = 0
Β· simp [hy, Real.Angle.pi_ne_zero.symm, div_eq_mul_inv, mul_right_eq_selfβ, not_or,
Real.pi_ne_zero]
refine β¨fun h => ?_, fun h => ?_β©
Β· rw [o.angle_eq_abs_oangle_toReal hx hy, h]
simp [Real.pi_pos.le]
Β· have ha := o.oangle_eq_angle_or_eq_neg_angle hx hy
rw [h] at ha
simpa using ha
/-- One of two vectors is zero or the oriented angle between them is plus or minus `Ο / 2` if
and only if the inner product of those vectors is zero. -/
theorem eq_zero_or_oangle_eq_iff_inner_eq_zero {x y : V} :
x = 0 β¨ y = 0 β¨ o.oangle x y = (Ο / 2 : β) β¨ o.oangle x y = (-Ο / 2 : β) β βͺx, yβ« = 0 := by
by_cases hx : x = 0; Β· simp [hx]
by_cases hy : y = 0; Β· simp [hy]
rw [InnerProductGeometry.inner_eq_zero_iff_angle_eq_pi_div_two, or_iff_right hx, or_iff_right hy]
refine β¨fun h => ?_, fun h => ?_β©
Β· rwa [o.angle_eq_abs_oangle_toReal hx hy, Real.Angle.abs_toReal_eq_pi_div_two_iff]
Β· convert o.oangle_eq_angle_or_eq_neg_angle hx hy using 2 <;> rw [h]
simp only [neg_div, Real.Angle.coe_neg]
/-- If the oriented angle between two vectors is `Ο / 2`, the inner product of those vectors
is zero. -/
theorem inner_eq_zero_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = (Ο / 2 : β)) :
βͺx, yβ« = 0 :=
o.eq_zero_or_oangle_eq_iff_inner_eq_zero.1 <| Or.inr <| Or.inr <| Or.inl h
/-- If the oriented angle between two vectors is `Ο / 2`, the inner product of those vectors
(reversed) is zero. -/
theorem inner_rev_eq_zero_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = (Ο / 2 : β)) :
βͺy, xβ« = 0 := by rw [real_inner_comm, o.inner_eq_zero_of_oangle_eq_pi_div_two h]
/-- If the oriented angle between two vectors is `-Ο / 2`, the inner product of those vectors
is zero. -/
theorem inner_eq_zero_of_oangle_eq_neg_pi_div_two {x y : V} (h : o.oangle x y = (-Ο / 2 : β)) :
βͺx, yβ« = 0 :=
o.eq_zero_or_oangle_eq_iff_inner_eq_zero.1 <| Or.inr <| Or.inr <| Or.inr h
/-- If the oriented angle between two vectors is `-Ο / 2`, the inner product of those vectors
(reversed) is zero. -/
theorem inner_rev_eq_zero_of_oangle_eq_neg_pi_div_two {x y : V} (h : o.oangle x y = (-Ο / 2 : β)) :
βͺy, xβ« = 0 := by rw [real_inner_comm, o.inner_eq_zero_of_oangle_eq_neg_pi_div_two h]
/-- Negating the first vector passed to `oangle` negates the sign of the angle. -/
@[simp]
theorem oangle_sign_neg_left (x y : V) : (o.oangle (-x) y).sign = -(o.oangle x y).sign := by
by_cases hx : x = 0; Β· simp [hx]
by_cases hy : y = 0; Β· simp [hy]
rw [o.oangle_neg_left hx hy, Real.Angle.sign_add_pi]
/-- Negating the second vector passed to `oangle` negates the sign of the angle. -/
@[simp]
theorem oangle_sign_neg_right (x y : V) : (o.oangle x (-y)).sign = -(o.oangle x y).sign := by
by_cases hx : x = 0; Β· simp [hx]
by_cases hy : y = 0; Β· simp [hy]
rw [o.oangle_neg_right hx hy, Real.Angle.sign_add_pi]
/-- Multiplying the first vector passed to `oangle` by a real multiplies the sign of the angle by
the sign of the real. -/
@[simp]
theorem oangle_sign_smul_left (x y : V) (r : β) :
(o.oangle (r β’ x) y).sign = SignType.sign r * (o.oangle x y).sign := by
rcases lt_trichotomy r 0 with (h | h | h) <;> simp [h]
/-- Multiplying the second vector passed to `oangle` by a real multiplies the sign of the angle by
the sign of the real. -/
@[simp]
theorem oangle_sign_smul_right (x y : V) (r : β) :
(o.oangle x (r β’ y)).sign = SignType.sign r * (o.oangle x y).sign := by
rcases lt_trichotomy r 0 with (h | h | h) <;> simp [h]
/-- Auxiliary lemma for the proof of `oangle_sign_smul_add_right`; not intended to be used
outside of that proof. -/
theorem oangle_smul_add_right_eq_zero_or_eq_pi_iff {x y : V} (r : β) :
o.oangle x (r β’ x + y) = 0 β¨ o.oangle x (r β’ x + y) = Ο β
o.oangle x y = 0 β¨ o.oangle x y = Ο := by
simp_rw [oangle_eq_zero_or_eq_pi_iff_not_linearIndependent, Fintype.not_linearIndependent_iff,
Fin.sum_univ_two, Fin.exists_fin_two]
refine β¨fun h => ?_, fun h => ?_β©
Β· rcases h with β¨m, h, hmβ©
change m 0 β’ x + m 1 β’ (r β’ x + y) = 0 at h
refine β¨![m 0 + m 1 * r, m 1], ?_β©
change (m 0 + m 1 * r) β’ x + m 1 β’ y = 0 β§ (m 0 + m 1 * r β 0 β¨ m 1 β 0)
rw [smul_add, smul_smul, β add_assoc, β add_smul] at h
refine β¨h, not_and_or.1 fun h0 => ?_β©
obtain β¨h0, h1β© := h0
rw [h1] at h0 hm
rw [zero_mul, add_zero] at h0
simp [h0] at hm
Β· rcases h with β¨m, h, hmβ©
change m 0 β’ x + m 1 β’ y = 0 at h
refine β¨![m 0 - m 1 * r, m 1], ?_β©
change (m 0 - m 1 * r) β’ x + m 1 β’ (r β’ x + y) = 0 β§ (m 0 - m 1 * r β 0 β¨ m 1 β 0)
rw [sub_smul, smul_add, smul_smul, β add_assoc, sub_add_cancel]
refine β¨h, not_and_or.1 fun h0 => ?_β©
obtain β¨h0, h1β© := h0
rw [h1] at h0 hm
rw [zero_mul, sub_zero] at h0
simp [h0] at hm
/-- Adding a multiple of the first vector passed to `oangle` to the second vector does not change
the sign of the angle. -/
@[simp]
theorem oangle_sign_smul_add_right (x y : V) (r : β) :
(o.oangle x (r β’ x + y)).sign = (o.oangle x y).sign := by
by_cases h : o.oangle x y = 0 β¨ o.oangle x y = Ο
Β· rwa [Real.Angle.sign_eq_zero_iff.2 h, Real.Angle.sign_eq_zero_iff,
oangle_smul_add_right_eq_zero_or_eq_pi_iff]
have h' : β r' : β, o.oangle x (r' β’ x + y) β 0 β§ o.oangle x (r' β’ x + y) β Ο := by
intro r'
rwa [β o.oangle_smul_add_right_eq_zero_or_eq_pi_iff r', not_or] at h
let s : Set (V Γ V) := (fun r' : β => (x, r' β’ x + y)) '' Set.univ
have hc : IsConnected s := isConnected_univ.image _ (by fun_prop)
have hf : ContinuousOn (fun z : V Γ V => o.oangle z.1 z.2) s := by
refine continuousOn_of_forall_continuousAt fun z hz => o.continuousAt_oangle ?_ ?_
all_goals
simp_rw [s, Set.mem_image] at hz
obtain β¨r', -, rflβ© := hz
simp only [Prod.fst, Prod.snd]
intro hz
Β· simpa [hz] using (h' 0).1
Β· simpa [hz] using (h' r').1
have hs : β z : V Γ V, z β s β o.oangle z.1 z.2 β 0 β§ o.oangle z.1 z.2 β Ο := by
intro z hz
simp_rw [s, Set.mem_image] at hz
obtain β¨r', -, rflβ© := hz
exact h' r'
have hx : (x, y) β s := by
convert Set.mem_image_of_mem (fun r' : β => (x, r' β’ x + y)) (Set.mem_univ 0)
simp
have hy : (x, r β’ x + y) β s := Set.mem_image_of_mem _ (Set.mem_univ _)
convert Real.Angle.sign_eq_of_continuousOn hc hf hs hx hy
/-- Adding a multiple of the second vector passed to `oangle` to the first vector does not change
the sign of the angle. -/
@[simp]
theorem oangle_sign_add_smul_left (x y : V) (r : β) :
(o.oangle (x + r β’ y) y).sign = (o.oangle x y).sign := by
simp_rw [o.oangle_rev y, Real.Angle.sign_neg, add_comm x, oangle_sign_smul_add_right]
/-- Subtracting a multiple of the first vector passed to `oangle` from the second vector does
not change the sign of the angle. -/
@[simp]
theorem oangle_sign_sub_smul_right (x y : V) (r : β) :
(o.oangle x (y - r β’ x)).sign = (o.oangle x y).sign := by
rw [sub_eq_add_neg, β neg_smul, add_comm, oangle_sign_smul_add_right]
/-- Subtracting a multiple of the second vector passed to `oangle` from the first vector does
not change the sign of the angle. -/
@[simp]
theorem oangle_sign_sub_smul_left (x y : V) (r : β) :
(o.oangle (x - r β’ y) y).sign = (o.oangle x y).sign := by
rw [sub_eq_add_neg, β neg_smul, oangle_sign_add_smul_left]
/-- Adding the first vector passed to `oangle` to the second vector does not change the sign of
the angle. -/
@[simp]
theorem oangle_sign_add_right (x y : V) : (o.oangle x (x + y)).sign = (o.oangle x y).sign := by
rw [β o.oangle_sign_smul_add_right x y 1, one_smul]
/-- Adding the second vector passed to `oangle` to the first vector does not change the sign of
the angle. -/
@[simp]
theorem oangle_sign_add_left (x y : V) : (o.oangle (x + y) y).sign = (o.oangle x y).sign := by
rw [β o.oangle_sign_add_smul_left x y 1, one_smul]
/-- Subtracting the first vector passed to `oangle` from the second vector does not change the
sign of the angle. -/
@[simp]
theorem oangle_sign_sub_right (x y : V) : (o.oangle x (y - x)).sign = (o.oangle x y).sign := by
rw [β o.oangle_sign_sub_smul_right x y 1, one_smul]
/-- Subtracting the second vector passed to `oangle` from the first vector does not change the
sign of the angle. -/
@[simp]
theorem oangle_sign_sub_left (x y : V) : (o.oangle (x - y) y).sign = (o.oangle x y).sign := by
rw [β o.oangle_sign_sub_smul_left x y 1, one_smul]
/-- Subtracting the second vector passed to `oangle` from a multiple of the first vector negates
the sign of the angle. -/
@[simp]
theorem oangle_sign_smul_sub_right (x y : V) (r : β) :
(o.oangle x (r β’ x - y)).sign = -(o.oangle x y).sign := by
rw [β oangle_sign_neg_right, sub_eq_add_neg, oangle_sign_smul_add_right]
/-- Subtracting the first vector passed to `oangle` from a multiple of the second vector negates
the sign of the angle. -/
@[simp]
theorem oangle_sign_smul_sub_left (x y : V) (r : β) :
(o.oangle (r β’ y - x) y).sign = -(o.oangle x y).sign := by
rw [β oangle_sign_neg_left, sub_eq_neg_add, oangle_sign_add_smul_left]
/-- Subtracting the second vector passed to `oangle` from the first vector negates the sign of
the angle. -/
theorem oangle_sign_sub_right_eq_neg (x y : V) :
(o.oangle x (x - y)).sign = -(o.oangle x y).sign := by
rw [β o.oangle_sign_smul_sub_right x y 1, one_smul]
/-- Subtracting the first vector passed to `oangle` from the second vector negates the sign of
the angle. -/
theorem oangle_sign_sub_left_eq_neg (x y : V) :
(o.oangle (y - x) y).sign = -(o.oangle x y).sign := by
rw [β o.oangle_sign_smul_sub_left x y 1, one_smul]
/-- Subtracting the first vector passed to `oangle` from the second vector then swapping the
vectors does not change the sign of the angle. -/
@[simp]
theorem oangle_sign_sub_right_swap (x y : V) : (o.oangle y (y - x)).sign = (o.oangle x y).sign := by
rw [oangle_sign_sub_right_eq_neg, o.oangle_rev y x, Real.Angle.sign_neg]
/-- Subtracting the second vector passed to `oangle` from the first vector then swapping the
vectors does not change the sign of the angle. -/
@[simp]
theorem oangle_sign_sub_left_swap (x y : V) : (o.oangle (x - y) x).sign = (o.oangle x y).sign := by
rw [oangle_sign_sub_left_eq_neg, o.oangle_rev y x, Real.Angle.sign_neg]
/-- The sign of the angle between a vector, and a linear combination of that vector with a second
vector, is the sign of the factor by which the second vector is multiplied in that combination
multiplied by the sign of the angle between the two vectors. -/
theorem oangle_sign_smul_add_smul_right (x y : V) (rβ rβ : β) :
(o.oangle x (rβ β’ x + rβ β’ y)).sign = SignType.sign rβ * (o.oangle x y).sign := by
rw [β o.oangle_sign_smul_add_right x (rβ β’ x + rβ β’ y) (-rβ)]
simp
/-- The sign of the angle between a linear combination of two vectors and the second vector is
the sign of the factor by which the first vector is multiplied in that combination multiplied by
the sign of the angle between the two vectors. -/
theorem oangle_sign_smul_add_smul_left (x y : V) (rβ rβ : β) :
(o.oangle (rβ β’ x + rβ β’ y) y).sign = SignType.sign rβ * (o.oangle x y).sign := by
simp_rw [o.oangle_rev y, Real.Angle.sign_neg, add_comm (rβ β’ x), oangle_sign_smul_add_smul_right,
mul_neg]
/-- The sign of the angle between two linear combinations of two vectors is the sign of the
determinant of the factors in those combinations multiplied by the sign of the angle between the
two vectors. -/
theorem oangle_sign_smul_add_smul_smul_add_smul (x y : V) (rβ rβ rβ rβ : β) :
(o.oangle (rβ β’ x + rβ β’ y) (rβ β’ x + rβ β’ y)).sign =
SignType.sign (rβ * rβ - rβ * rβ) * (o.oangle x y).sign := by
by_cases hrβ : rβ = 0
Β· rw [hrβ, zero_smul, zero_mul, zero_add, zero_sub, Left.sign_neg,
oangle_sign_smul_left, add_comm, oangle_sign_smul_add_smul_right, oangle_rev,
Real.Angle.sign_neg, sign_mul, mul_neg, mul_neg, neg_mul, mul_assoc]
Β· rw [β o.oangle_sign_smul_add_right (rβ β’ x + rβ β’ y) (rβ β’ x + rβ β’ y) (-rβ / rβ), smul_add,
smul_smul, smul_smul, div_mul_cancelβ _ hrβ, neg_smul, β add_assoc, add_comm (-(rβ β’ x)), β
sub_eq_add_neg, sub_add_cancel, β add_smul, oangle_sign_smul_right,
oangle_sign_smul_add_smul_left, β mul_assoc, β sign_mul, add_mul, mul_assoc, mul_comm rβ rβ, β
mul_assoc, div_mul_cancelβ _ hrβ, add_comm, neg_mul, β sub_eq_add_neg, mul_comm rβ,
mul_comm rβ]
/-- A base angle of an isosceles triangle is acute, oriented vector angle form. -/
theorem abs_oangle_sub_left_toReal_lt_pi_div_two {x y : V} (h : βxβ = βyβ) :
|(o.oangle (y - x) y).toReal| < Ο / 2 := by
by_cases hn : x = y; Β· simp [hn, div_pos, Real.pi_pos]
have hs : ((2 : β€) β’ o.oangle (y - x) y).sign = (o.oangle (y - x) y).sign := by
conv_rhs => rw [oangle_sign_sub_left_swap]
rw [o.oangle_eq_pi_sub_two_zsmul_oangle_sub_of_norm_eq hn h, Real.Angle.sign_pi_sub]
rw [Real.Angle.sign_two_zsmul_eq_sign_iff] at hs
rcases hs with (hs | hs)
Β· rw [oangle_eq_pi_iff_oangle_rev_eq_pi, oangle_eq_pi_iff_sameRay_neg, neg_sub] at hs
rcases hs with β¨hy, -, hrβ©
rw [β exists_nonneg_left_iff_sameRay hy] at hr
rcases hr with β¨r, hr0, hrβ©
rw [eq_sub_iff_add_eq] at hr
nth_rw 2 [β one_smul β y] at hr
rw [β add_smul] at hr
rw [β hr, norm_smul, Real.norm_eq_abs, abs_of_pos (Left.add_pos_of_nonneg_of_pos hr0 one_pos),
mul_left_eq_selfβ, or_iff_left (norm_ne_zero_iff.2 hy), add_eq_right] at h
rw [h, zero_add, one_smul] at hr
exact False.elim (hn hr.symm)
Β· exact hs
/-- A base angle of an isosceles triangle is acute, oriented vector angle form. -/
theorem abs_oangle_sub_right_toReal_lt_pi_div_two {x y : V} (h : βxβ = βyβ) :
|(o.oangle x (x - y)).toReal| < Ο / 2 :=
(o.oangle_sub_eq_oangle_sub_rev_of_norm_eq h).symm βΈ o.abs_oangle_sub_left_toReal_lt_pi_div_two h
end Orientation
| Mathlib/Geometry/Euclidean/Angle/Oriented/Basic.lean | 984 | 986 | |
/-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle SΓΆnne
-/
import Mathlib.Analysis.Complex.Asymptotics
import Mathlib.Analysis.SpecificLimits.Normed
import Mathlib.Data.Complex.Trigonometric
/-!
# Complex and real exponential
In this file we prove continuity of `Complex.exp` and `Real.exp`. We also prove a few facts about
limits of `Real.exp` at infinity.
## Tags
exp
-/
noncomputable section
open Asymptotics Bornology Finset Filter Function Metric Set Topology
open scoped Nat
namespace Complex
variable {z y x : β}
theorem exp_bound_sq (x z : β) (hz : βzβ β€ 1) :
βexp (x + z) - exp x - z β’ exp xβ β€ βexp xβ * βzβ ^ 2 :=
calc
βexp (x + z) - exp x - z * exp xβ = βexp x * (exp z - 1 - z)β := by
congr
rw [exp_add]
ring
_ = βexp xβ * βexp z - 1 - zβ := norm_mul _ _
_ β€ βexp xβ * βzβ ^ 2 :=
mul_le_mul_of_nonneg_left (norm_exp_sub_one_sub_id_le hz) (norm_nonneg _)
theorem locally_lipschitz_exp {r : β} (hr_nonneg : 0 β€ r) (hr_le : r β€ 1) (x y : β)
(hyx : βy - xβ < r) : βexp y - exp xβ β€ (1 + r) * βexp xβ * βy - xβ := by
have hy_eq : y = x + (y - x) := by abel
have hyx_sq_le : βy - xβ ^ 2 β€ r * βy - xβ := by
rw [pow_two]
exact mul_le_mul hyx.le le_rfl (norm_nonneg _) hr_nonneg
have h_sq : β z, βzβ β€ 1 β βexp (x + z) - exp xβ β€ βzβ * βexp xβ + βexp xβ * βzβ ^ 2 := by
intro z hz
have : βexp (x + z) - exp x - z β’ exp xβ β€ βexp xβ * βzβ ^ 2 := exp_bound_sq x z hz
rw [β sub_le_iff_le_add', β norm_smul z]
exact (norm_sub_norm_le _ _).trans this
calc
βexp y - exp xβ = βexp (x + (y - x)) - exp xβ := by nth_rw 1 [hy_eq]
_ β€ βy - xβ * βexp xβ + βexp xβ * βy - xβ ^ 2 := h_sq (y - x) (hyx.le.trans hr_le)
_ β€ βy - xβ * βexp xβ + βexp xβ * (r * βy - xβ) :=
(add_le_add_left (mul_le_mul le_rfl hyx_sq_le (sq_nonneg _) (norm_nonneg _)) _)
_ = (1 + r) * βexp xβ * βy - xβ := by ring
-- Porting note: proof by term mode `locally_lipschitz_exp zero_le_one le_rfl x`
-- doesn't work because `βy - xβ` and `dist y x` don't unify
@[continuity]
theorem continuous_exp : Continuous exp :=
continuous_iff_continuousAt.mpr fun x =>
continuousAt_of_locally_lipschitz zero_lt_one (2 * βexp xβ)
(fun y β¦ by
convert locally_lipschitz_exp zero_le_one le_rfl x y using 2
congr
ring)
theorem continuousOn_exp {s : Set β} : ContinuousOn exp s :=
continuous_exp.continuousOn
lemma exp_sub_sum_range_isBigO_pow (n : β) :
(fun x β¦ exp x - β i β Finset.range n, x ^ i / i !) =O[π 0] (Β· ^ n) := by
rcases (zero_le n).eq_or_lt with rfl | hn
Β· simpa using continuous_exp.continuousAt.norm.isBoundedUnder_le
Β· refine .of_bound (n.succ / (n ! * n)) ?_
rw [NormedAddCommGroup.nhds_zero_basis_norm_lt.eventually_iff]
refine β¨1, one_pos, fun x hx β¦ ?_β©
convert exp_bound hx.out.le hn using 1
field_simp [mul_comm]
lemma exp_sub_sum_range_succ_isLittleO_pow (n : β) :
(fun x β¦ exp x - β i β Finset.range (n + 1), x ^ i / i !) =o[π 0] (Β· ^ n) :=
(exp_sub_sum_range_isBigO_pow (n + 1)).trans_isLittleO <| isLittleO_pow_pow n.lt_succ_self
end Complex
section ComplexContinuousExpComp
variable {Ξ± : Type*}
open Complex
theorem Filter.Tendsto.cexp {l : Filter Ξ±} {f : Ξ± β β} {z : β} (hf : Tendsto f l (π z)) :
Tendsto (fun x => exp (f x)) l (π (exp z)) :=
(continuous_exp.tendsto _).comp hf
variable [TopologicalSpace Ξ±] {f : Ξ± β β} {s : Set Ξ±} {x : Ξ±}
nonrec
theorem ContinuousWithinAt.cexp (h : ContinuousWithinAt f s x) :
ContinuousWithinAt (fun y => exp (f y)) s x :=
h.cexp
@[fun_prop]
nonrec
theorem ContinuousAt.cexp (h : ContinuousAt f x) : ContinuousAt (fun y => exp (f y)) x :=
h.cexp
@[fun_prop]
theorem ContinuousOn.cexp (h : ContinuousOn f s) : ContinuousOn (fun y => exp (f y)) s :=
fun x hx => (h x hx).cexp
@[fun_prop]
theorem Continuous.cexp (h : Continuous f) : Continuous fun y => exp (f y) :=
continuous_iff_continuousAt.2 fun _ => h.continuousAt.cexp
/-- The complex exponential function is uniformly continuous on left half planes. -/
lemma UniformContinuousOn.cexp (a : β) : UniformContinuousOn exp {x : β | x.re β€ a} := by
have : Continuous (cexp - 1) := Continuous.sub (Continuous.cexp continuous_id') continuous_one
rw [Metric.uniformContinuousOn_iff, Metric.continuous_iff'] at *
intro Ξ΅ hΞ΅
simp only [gt_iff_lt, Pi.sub_apply, Pi.one_apply, dist_sub_eq_dist_add_right,
sub_add_cancel] at this
have ha : 0 < Ξ΅ / (2 * Real.exp a) := by positivity
have H := this 0 (Ξ΅ / (2 * Real.exp a)) ha
rw [Metric.eventually_nhds_iff] at H
obtain β¨Ξ΄, hΞ΄β© := H
refine β¨Ξ΄, hΞ΄.1, ?_β©
intros x _ y hy hxy
have h3 := hΞ΄.2 (y := x - y) (by simpa only [dist_zero_right] using hxy)
rw [dist_eq_norm, exp_zero] at *
have : cexp x - cexp y = cexp y * (cexp (x - y) - 1) := by
rw [mul_sub_one, β exp_add]
ring_nf
rw [this, mul_comm]
have hya : βcexp yβ β€ Real.exp a := by
simp only [norm_exp, Real.exp_le_exp]
exact hy
simp only [gt_iff_lt, dist_zero_right, Set.mem_setOf_eq, norm_mul, Complex.norm_exp] at *
apply lt_of_le_of_lt (mul_le_mul h3.le hya (Real.exp_nonneg y.re) (le_of_lt ha))
have hrr : Ξ΅ / (2 * a.exp) * a.exp = Ξ΅ / 2 := by
nth_rw 2 [mul_comm]
field_simp [mul_assoc]
rw [hrr]
exact div_two_lt_of_pos hΞ΅
@[deprecated (since := "2025-02-11")] alias UniformlyContinuousOn.cexp := UniformContinuousOn.cexp
end ComplexContinuousExpComp
namespace Real
@[continuity]
theorem continuous_exp : Continuous exp :=
Complex.continuous_re.comp Complex.continuous_ofReal.cexp
theorem continuousOn_exp {s : Set β} : ContinuousOn exp s :=
continuous_exp.continuousOn
lemma exp_sub_sum_range_isBigO_pow (n : β) :
(fun x β¦ exp x - β i β Finset.range n, x ^ i / i !) =O[π 0] (Β· ^ n) := by
have := (Complex.exp_sub_sum_range_isBigO_pow n).comp_tendsto
(Complex.continuous_ofReal.tendsto' 0 0 rfl)
simp only [Function.comp_def] at this
norm_cast at this
lemma exp_sub_sum_range_succ_isLittleO_pow (n : β) :
(fun x β¦ exp x - β i β Finset.range (n + 1), x ^ i / i !) =o[π 0] (Β· ^ n) :=
(exp_sub_sum_range_isBigO_pow (n + 1)).trans_isLittleO <| isLittleO_pow_pow n.lt_succ_self
end Real
section RealContinuousExpComp
variable {Ξ± : Type*}
open Real
theorem Filter.Tendsto.rexp {l : Filter Ξ±} {f : Ξ± β β} {z : β} (hf : Tendsto f l (π z)) :
Tendsto (fun x => exp (f x)) l (π (exp z)) :=
(continuous_exp.tendsto _).comp hf
variable [TopologicalSpace Ξ±] {f : Ξ± β β} {s : Set Ξ±} {x : Ξ±}
nonrec
theorem ContinuousWithinAt.rexp (h : ContinuousWithinAt f s x) :
ContinuousWithinAt (fun y β¦ exp (f y)) s x :=
h.rexp
@[fun_prop]
nonrec
theorem ContinuousAt.rexp (h : ContinuousAt f x) : ContinuousAt (fun y β¦ exp (f y)) x :=
h.rexp
@[fun_prop]
theorem ContinuousOn.rexp (h : ContinuousOn f s) :
ContinuousOn (fun y β¦ exp (f y)) s :=
fun x hx β¦ (h x hx).rexp
@[fun_prop]
theorem Continuous.rexp (h : Continuous f) : Continuous fun y β¦ exp (f y) :=
continuous_iff_continuousAt.2 fun _ β¦ h.continuousAt.rexp
end RealContinuousExpComp
namespace Real
variable {Ξ± : Type*} {x y z : β} {l : Filter Ξ±}
theorem exp_half (x : β) : exp (x / 2) = β(exp x) := by
rw [eq_comm, sqrt_eq_iff_eq_sq, sq, β exp_add, add_halves] <;> exact (exp_pos _).le
/-- The real exponential function tends to `+β` at `+β`. -/
theorem tendsto_exp_atTop : Tendsto exp atTop atTop := by
have A : Tendsto (fun x : β => x + 1) atTop atTop :=
tendsto_atTop_add_const_right atTop 1 tendsto_id
have B : βαΆ x in atTop, x + 1 β€ exp x := eventually_atTop.2 β¨0, fun x _ => add_one_le_exp xβ©
exact tendsto_atTop_mono' atTop B A
/-- The real exponential function tends to `0` at `-β` or, equivalently, `exp(-x)` tends to `0`
at `+β` -/
theorem tendsto_exp_neg_atTop_nhds_zero : Tendsto (fun x => exp (-x)) atTop (π 0) :=
(tendsto_inv_atTop_zero.comp tendsto_exp_atTop).congr fun x => (exp_neg x).symm
/-- The real exponential function tends to `1` at `0`. -/
theorem tendsto_exp_nhds_zero_nhds_one : Tendsto exp (π 0) (π 1) := by
convert continuous_exp.tendsto 0
simp
theorem tendsto_exp_atBot : Tendsto exp atBot (π 0) :=
(tendsto_exp_neg_atTop_nhds_zero.comp tendsto_neg_atBot_atTop).congr fun x =>
congr_arg exp <| neg_neg x
theorem tendsto_exp_atBot_nhdsGT : Tendsto exp atBot (π[>] 0) :=
tendsto_inf.2 β¨tendsto_exp_atBot, tendsto_principal.2 <| Eventually.of_forall exp_posβ©
@[deprecated (since := "2024-12-22")]
alias tendsto_exp_atBot_nhdsWithin := tendsto_exp_atBot_nhdsGT
@[simp]
theorem isBoundedUnder_ge_exp_comp (l : Filter Ξ±) (f : Ξ± β β) :
IsBoundedUnder (Β· β₯ Β·) l fun x => exp (f x) :=
isBoundedUnder_of β¨0, fun _ => (exp_pos _).leβ©
@[simp]
theorem isBoundedUnder_le_exp_comp {f : Ξ± β β} :
(IsBoundedUnder (Β· β€ Β·) l fun x => exp (f x)) β IsBoundedUnder (Β· β€ Β·) l f :=
exp_monotone.isBoundedUnder_le_comp_iff tendsto_exp_atTop
/-- The function `exp(x)/x^n` tends to `+β` at `+β`, for any natural number `n` -/
theorem tendsto_exp_div_pow_atTop (n : β) : Tendsto (fun x => exp x / x ^ n) atTop atTop := by
refine (atTop_basis_Ioi.tendsto_iff (atTop_basis' 1)).2 fun C hCβ => ?_
have hCβ : 0 < C := zero_lt_one.trans_le hCβ
have : 0 < (exp 1 * C)β»ΒΉ := inv_pos.2 (mul_pos (exp_pos _) hCβ)
obtain β¨N, hNβ© : β N : β, β k β₯ N, (βk : β) ^ n / exp 1 ^ k < (exp 1 * C)β»ΒΉ :=
eventually_atTop.1
((tendsto_pow_const_div_const_pow_of_one_lt n (one_lt_exp_iff.2 zero_lt_one)).eventually
(gt_mem_nhds this))
simp only [β exp_nat_mul, mul_one, div_lt_iffβ, exp_pos, β div_eq_inv_mul] at hN
refine β¨N, trivial, fun x hx => ?_β©
rw [Set.mem_Ioi] at hx
have hxβ : 0 < x := (Nat.cast_nonneg N).trans_lt hx
rw [Set.mem_Ici, le_div_iffβ (pow_pos hxβ _), β le_div_iffβ' hCβ]
calc
x ^ n β€ βxββ ^ n := by gcongr; exact Nat.le_ceil _
_ β€ exp βxββ / (exp 1 * C) := mod_cast (hN _ (Nat.lt_ceil.2 hx).le).le
_ β€ exp (x + 1) / (exp 1 * C) := by gcongr; exact (Nat.ceil_lt_add_one hxβ.le).le
_ = exp x / C := by rw [add_comm, exp_add, mul_div_mul_left _ _ (exp_pos _).ne']
/-- The function `x^n * exp(-x)` tends to `0` at `+β`, for any natural number `n`. -/
theorem tendsto_pow_mul_exp_neg_atTop_nhds_zero (n : β) :
Tendsto (fun x => x ^ n * exp (-x)) atTop (π 0) :=
(tendsto_inv_atTop_zero.comp (tendsto_exp_div_pow_atTop n)).congr fun x => by
rw [comp_apply, inv_eq_one_div, div_div_eq_mul_div, one_mul, div_eq_mul_inv, exp_neg]
/-- The function `(b * exp x + c) / (x ^ n)` tends to `+β` at `+β`, for any natural number
`n` and any real numbers `b` and `c` such that `b` is positive. -/
theorem tendsto_mul_exp_add_div_pow_atTop (b c : β) (n : β) (hb : 0 < b) :
Tendsto (fun x => (b * exp x + c) / x ^ n) atTop atTop := by
rcases eq_or_ne n 0 with (rfl | hn)
Β· simp only [pow_zero, div_one]
exact (tendsto_exp_atTop.const_mul_atTop hb).atTop_add tendsto_const_nhds
simp only [add_div, mul_div_assoc]
exact
((tendsto_exp_div_pow_atTop n).const_mul_atTop hb).atTop_add
(tendsto_const_nhds.div_atTop (tendsto_pow_atTop hn))
/-- The function `(x ^ n) / (b * exp x + c)` tends to `0` at `+β`, for any natural number
`n` and any real numbers `b` and `c` such that `b` is nonzero. -/
theorem tendsto_div_pow_mul_exp_add_atTop (b c : β) (n : β) (hb : 0 β b) :
Tendsto (fun x => x ^ n / (b * exp x + c)) atTop (π 0) := by
have H : β d e, 0 < d β Tendsto (fun x : β => x ^ n / (d * exp x + e)) atTop (π 0) := by
intro b' c' h
convert (tendsto_mul_exp_add_div_pow_atTop b' c' n h).inv_tendsto_atTop using 1
ext x
simp
rcases lt_or_gt_of_ne hb with h | h
Β· exact H b c h
| Β· convert (H (-b) (-c) (neg_pos.mpr h)).neg using 1
Β· ext x
field_simp
rw [β neg_add (b * exp x) c, neg_div_neg_eq]
Β· rw [neg_zero]
/-- `Real.exp` as an order isomorphism between `β` and `(0, +β)`. -/
def expOrderIso : β βo Ioi (0 : β) :=
StrictMono.orderIsoOfSurjective _ (exp_strictMono.codRestrict exp_pos) <|
(continuous_exp.subtype_mk _).surjective
(by rw [tendsto_Ioi_atTop]; simp only [tendsto_exp_atTop])
(by rw [tendsto_Ioi_atBot]; simp only [tendsto_exp_atBot_nhdsGT])
@[simp]
| Mathlib/Analysis/SpecialFunctions/Exp.lean | 298 | 311 |
/-
Copyright (c) 2022 Adam Topaz. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Adam Topaz, Junyan Xu, Jack McKoen
-/
import Mathlib.RingTheory.Valuation.ValuationRing
import Mathlib.RingTheory.Localization.AsSubring
import Mathlib.Algebra.Ring.Subring.Pointwise
import Mathlib.Algebra.Ring.Action.Field
import Mathlib.RingTheory.Spectrum.Prime.Basic
import Mathlib.RingTheory.LocalRing.ResidueField.Basic
/-!
# Valuation subrings of a field
## Projects
The order structure on `ValuationSubring K`.
-/
universe u
noncomputable section
variable (K : Type u) [Field K]
/-- A valuation subring of a field `K` is a subring `A` such that for every `x : K`,
either `x β A` or `xβ»ΒΉ β A`.
This is equivalent to being maximal in the domination order
of local subrings (the stacks project definition). See `LocalSubring.isMax_iff`.
-/
structure ValuationSubring extends Subring K where
mem_or_inv_mem' : β x : K, x β carrier β¨ xβ»ΒΉ β carrier
namespace ValuationSubring
variable {K}
variable (A : ValuationSubring K)
instance : SetLike (ValuationSubring K) K where
coe A := A.toSubring
coe_injective' := by
intro β¨_, _β© β¨_, _β© h
replace h := SetLike.coe_injective' h
congr
theorem mem_carrier (x : K) : x β A.carrier β x β A := Iff.refl _
@[simp]
theorem mem_toSubring (x : K) : x β A.toSubring β x β A := Iff.refl _
@[ext]
theorem ext (A B : ValuationSubring K) (h : β x, x β A β x β B) : A = B := SetLike.ext h
theorem zero_mem : (0 : K) β A := A.toSubring.zero_mem
theorem one_mem : (1 : K) β A := A.toSubring.one_mem
theorem add_mem (x y : K) : x β A β y β A β x + y β A := A.toSubring.add_mem
theorem mul_mem (x y : K) : x β A β y β A β x * y β A := A.toSubring.mul_mem
theorem neg_mem (x : K) : x β A β -x β A := A.toSubring.neg_mem
theorem mem_or_inv_mem (x : K) : x β A β¨ xβ»ΒΉ β A := A.mem_or_inv_mem' _
instance : SubringClass (ValuationSubring K) K where
zero_mem := zero_mem
add_mem {_} a b := add_mem _ a b
one_mem := one_mem
mul_mem {_} a b := mul_mem _ a b
neg_mem {_} x := neg_mem _ x
theorem toSubring_injective : Function.Injective (toSubring : ValuationSubring K β Subring K) :=
fun x y h => by cases x; cases y; congr
instance : CommRing A :=
show CommRing A.toSubring by infer_instance
instance : IsDomain A :=
show IsDomain A.toSubring by infer_instance
instance : Top (ValuationSubring K) :=
Top.mk <| { (β€ : Subring K) with mem_or_inv_mem' := fun _ => Or.inl trivial }
theorem mem_top (x : K) : x β (β€ : ValuationSubring K) :=
trivial
theorem le_top : A β€ β€ := fun _a _ha => mem_top _
instance : OrderTop (ValuationSubring K) where
top := β€
le_top := le_top
instance : Inhabited (ValuationSubring K) :=
β¨β€β©
instance : ValuationRing A where
cond' a b := by
by_cases h : (b : K) = 0
Β· use 0
left
ext
simp [h]
by_cases h : (a : K) = 0
Β· use 0; right
ext
simp [h]
rcases A.mem_or_inv_mem (a / b) with hh | hh
Β· use β¨a / b, hhβ©
right
ext
field_simp
Β· rw [show (a / b : K)β»ΒΉ = b / a by field_simp] at hh
use β¨b / a, hhβ©
left
ext
field_simp
instance : Algebra A K :=
show Algebra A.toSubring K by infer_instance
-- Porting note: Somehow it cannot find this instance and I'm too lazy to debug. wrong prio?
instance isLocalRing : IsLocalRing A := ValuationRing.isLocalRing A
@[simp]
theorem algebraMap_apply (a : A) : algebraMap A K a = a := rfl
instance : IsFractionRing A K where
map_units' := fun β¨y, hyβ© =>
(Units.mk0 (y : K) fun c => nonZeroDivisors.ne_zero hy <| Subtype.ext c).isUnit
surj' z := by
by_cases h : z = 0; Β· use (0, 1); simp [h]
rcases A.mem_or_inv_mem z with hh | hh
Β· use (β¨z, hhβ©, 1); simp
Β· refine β¨β¨1, β¨β¨_, hhβ©, ?_β©β©, mul_inv_cancelβ hβ©
exact mem_nonZeroDivisors_iff_ne_zero.2 fun c => h (inv_eq_zero.mp (congr_arg Subtype.val c))
exists_of_eq {a b} h := β¨1, by ext; simpa using hβ©
/-- The value group of the valuation associated to `A`. Note: it is actually a group with zero. -/
def ValueGroup :=
ValuationRing.ValueGroup A K
-- The `LinearOrderedCommGroupWithZero` instance should be constructed by a deriving handler.
-- https://github.com/leanprover-community/mathlib4/issues/380
instance : LinearOrderedCommGroupWithZero (ValueGroup A) := by
unfold ValueGroup
infer_instance
/-- Any valuation subring of `K` induces a natural valuation on `K`. -/
def valuation : Valuation K A.ValueGroup :=
ValuationRing.valuation A K
instance inhabitedValueGroup : Inhabited A.ValueGroup := β¨A.valuation 0β©
theorem valuation_le_one (a : A) : A.valuation a β€ 1 :=
(ValuationRing.mem_integer_iff A K _).2 β¨a, rflβ©
theorem mem_of_valuation_le_one (x : K) (h : A.valuation x β€ 1) : x β A :=
let β¨a, haβ© := (ValuationRing.mem_integer_iff A K x).1 h
ha βΈ a.2
theorem valuation_le_one_iff (x : K) : A.valuation x β€ 1 β x β A :=
β¨mem_of_valuation_le_one _ _, fun ha => A.valuation_le_one β¨x, haβ©β©
theorem valuation_eq_iff (x y : K) : A.valuation x = A.valuation y β β a : AΛ£, (a : K) * y = x :=
Quotient.eq''
theorem valuation_le_iff (x y : K) : A.valuation x β€ A.valuation y β β a : A, (a : K) * y = x :=
Iff.rfl
theorem valuation_surjective : Function.Surjective A.valuation := Quot.mk_surjective
theorem valuation_unit (a : AΛ£) : A.valuation a = 1 := by
rw [β A.valuation.map_one, valuation_eq_iff]; use a; simp
theorem valuation_eq_one_iff (a : A) : IsUnit a β A.valuation a = 1 :=
β¨fun h => A.valuation_unit h.unit, fun h => by
have ha : (a : K) β 0 := by
intro c
rw [c, A.valuation.map_zero] at h
exact zero_ne_one h
have ha' : (a : K)β»ΒΉ β A := by rw [β valuation_le_one_iff, map_invβ, h, inv_one]
apply isUnit_of_mul_eq_one a β¨aβ»ΒΉ, ha'β©; ext; field_simpβ©
theorem valuation_lt_one_or_eq_one (a : A) : A.valuation a < 1 β¨ A.valuation a = 1 :=
lt_or_eq_of_le (A.valuation_le_one a)
theorem valuation_lt_one_iff (a : A) : a β IsLocalRing.maximalIdeal A β A.valuation a < 1 := by
rw [IsLocalRing.mem_maximalIdeal]
dsimp [nonunits]; rw [valuation_eq_one_iff]
exact (A.valuation_le_one a).lt_iff_ne.symm
/-- A subring `R` of `K` such that for all `x : K` either `x β R` or `xβ»ΒΉ β R` is
a valuation subring of `K`. -/
def ofSubring (R : Subring K) (hR : β x : K, x β R β¨ xβ»ΒΉ β R) : ValuationSubring K :=
{ R with mem_or_inv_mem' := hR }
@[simp]
theorem mem_ofSubring (R : Subring K) (hR : β x : K, x β R β¨ xβ»ΒΉ β R) (x : K) :
x β ofSubring R hR β x β R :=
Iff.refl _
/-- An overring of a valuation ring is a valuation ring. -/
def ofLE (R : ValuationSubring K) (S : Subring K) (h : R.toSubring β€ S) : ValuationSubring K :=
{ S with mem_or_inv_mem' := fun x => (R.mem_or_inv_mem x).imp (@h x) (@h _) }
section Order
instance : SemilatticeSup (ValuationSubring K) :=
{ (inferInstance : PartialOrder (ValuationSubring K)) with
sup := fun R S => ofLE R (R.toSubring β S.toSubring) <| le_sup_left
le_sup_left := fun R S _ hx => (le_sup_left : R.toSubring β€ R.toSubring β S.toSubring) hx
le_sup_right := fun R S _ hx => (le_sup_right : S.toSubring β€ R.toSubring β S.toSubring) hx
sup_le := fun R S T hR hT _ hx => (sup_le hR hT : R.toSubring β S.toSubring β€ T.toSubring) hx }
/-- The ring homomorphism induced by the partial order. -/
def inclusion (R S : ValuationSubring K) (h : R β€ S) : R β+* S :=
Subring.inclusion h
/-- The canonical ring homomorphism from a valuation ring to its field of fractions. -/
def subtype (R : ValuationSubring K) : R β+* K :=
Subring.subtype R.toSubring
@[simp]
lemma subtype_apply {R : ValuationSubring K} (x : R) :
R.subtype x = x := rfl
lemma subtype_injective (R : ValuationSubring K) :
Function.Injective R.subtype :=
R.toSubring.subtype_injective
@[simp]
theorem coe_subtype (R : ValuationSubring K) : β(subtype R) = Subtype.val :=
rfl
/-- The canonical map on value groups induced by a coarsening of valuation rings. -/
def mapOfLE (R S : ValuationSubring K) (h : R β€ S) : R.ValueGroup β*β S.ValueGroup where
toFun := Quotient.map' id fun _ _ β¨u, huβ© => β¨Units.map (R.inclusion S h).toMonoidHom u, huβ©
map_zero' := rfl
map_one' := rfl
map_mul' := by rintro β¨β© β¨β©; rfl
@[mono]
theorem monotone_mapOfLE (R S : ValuationSubring K) (h : R β€ S) : Monotone (R.mapOfLE S h) := by
rintro β¨β© β¨β© β¨a, haβ©; exact β¨R.inclusion S h a, haβ©
@[simp]
theorem mapOfLE_comp_valuation (R S : ValuationSubring K) (h : R β€ S) :
R.mapOfLE S h β R.valuation = S.valuation := by ext; rfl
@[simp]
theorem mapOfLE_valuation_apply (R S : ValuationSubring K) (h : R β€ S) (x : K) :
R.mapOfLE S h (R.valuation x) = S.valuation x := rfl
/-- The ideal corresponding to a coarsening of a valuation ring. -/
def idealOfLE (R S : ValuationSubring K) (h : R β€ S) : Ideal R :=
(IsLocalRing.maximalIdeal S).comap (R.inclusion S h)
instance prime_idealOfLE (R S : ValuationSubring K) (h : R β€ S) : (idealOfLE R S h).IsPrime :=
(IsLocalRing.maximalIdeal S).comap_isPrime _
/-- The coarsening of a valuation ring associated to a prime ideal. -/
def ofPrime (A : ValuationSubring K) (P : Ideal A) [P.IsPrime] : ValuationSubring K :=
ofLE A (Localization.subalgebra.ofField K _ P.primeCompl_le_nonZeroDivisors).toSubring
fun a ha => Subalgebra.mem_toSubring.mpr <|
Subalgebra.algebraMap_mem
(Localization.subalgebra.ofField K _ P.primeCompl_le_nonZeroDivisors) (β¨a, haβ© : A)
instance ofPrimeAlgebra (A : ValuationSubring K) (P : Ideal A) [P.IsPrime] :
Algebra A (A.ofPrime P) :=
Subalgebra.algebra (Localization.subalgebra.ofField K _ P.primeCompl_le_nonZeroDivisors)
instance ofPrime_scalar_tower (A : ValuationSubring K) (P : Ideal A) [P.IsPrime] :
letI : SMul A (A.ofPrime P) := SMulZeroClass.toSMul
IsScalarTower A (A.ofPrime P) K :=
IsScalarTower.subalgebra' A K K
(Localization.subalgebra.ofField K _ P.primeCompl_le_nonZeroDivisors)
instance ofPrime_localization (A : ValuationSubring K) (P : Ideal A) [P.IsPrime] :
IsLocalization.AtPrime (A.ofPrime P) P := by
apply
Localization.subalgebra.isLocalization_ofField K P.primeCompl
P.primeCompl_le_nonZeroDivisors
theorem le_ofPrime (A : ValuationSubring K) (P : Ideal A) [P.IsPrime] : A β€ ofPrime A P :=
fun a ha => Subalgebra.mem_toSubring.mpr <| Subalgebra.algebraMap_mem _ (β¨a, haβ© : A)
theorem ofPrime_valuation_eq_one_iff_mem_primeCompl (A : ValuationSubring K) (P : Ideal A)
[P.IsPrime] (x : A) : (ofPrime A P).valuation x = 1 β x β P.primeCompl := by
rw [β IsLocalization.AtPrime.isUnit_to_map_iff (A.ofPrime P) P x, valuation_eq_one_iff]; rfl
@[simp]
theorem idealOfLE_ofPrime (A : ValuationSubring K) (P : Ideal A) [P.IsPrime] :
idealOfLE A (ofPrime A P) (le_ofPrime A P) = P := by
refine Ideal.ext (fun x => ?_)
apply IsLocalization.AtPrime.to_map_mem_maximal_iff
exact isLocalRing (ofPrime A P)
@[simp]
theorem ofPrime_idealOfLE (R S : ValuationSubring K) (h : R β€ S) :
ofPrime R (idealOfLE R S h) = S := by
ext x; constructor
Β· rintro β¨a, r, hr, rflβ©; apply mul_mem; Β· exact h a.2
Β· rw [β valuation_le_one_iff, map_invβ, β inv_one, inv_le_invβ]
Β· exact not_lt.1 ((not_iff_not.2 <| valuation_lt_one_iff S _).1 hr)
Β· simpa [Valuation.pos_iff] using fun hrβ β¦ hrβ βΈ hr <| Ideal.zero_mem (R.idealOfLE S h)
Β· exact zero_lt_one
Β· intro hx; by_cases hr : x β R; Β· exact R.le_ofPrime _ hr
have : x β 0 := fun h => hr (by rw [h]; exact R.zero_mem)
replace hr := (R.mem_or_inv_mem x).resolve_left hr
refine β¨1, β¨xβ»ΒΉ, hrβ©, ?_, ?_β©
Β· simp only [Ideal.primeCompl, Submonoid.mem_mk, Subsemigroup.mem_mk, Set.mem_compl_iff,
SetLike.mem_coe, idealOfLE, Ideal.mem_comap, IsLocalRing.mem_maximalIdeal, mem_nonunits_iff,
not_not]
change IsUnit (β¨xβ»ΒΉ, h hrβ© : S)
apply isUnit_of_mul_eq_one _ (β¨x, hxβ© : S)
ext; field_simp
Β· field_simp
theorem ofPrime_le_of_le (P Q : Ideal A) [P.IsPrime] [Q.IsPrime] (h : P β€ Q) :
ofPrime A Q β€ ofPrime A P := fun _x β¨a, s, hs, heβ© => β¨a, s, fun c => hs (h c), heβ©
theorem idealOfLE_le_of_le (R S : ValuationSubring K) (hR : A β€ R) (hS : A β€ S) (h : R β€ S) :
idealOfLE A S hS β€ idealOfLE A R hR := fun x hx =>
(valuation_lt_one_iff R _).2
(by
by_contra c; push_neg at c; replace c := monotone_mapOfLE R S h c
rw [(mapOfLE _ _ _).map_one, mapOfLE_valuation_apply] at c
apply not_le_of_lt ((valuation_lt_one_iff S _).1 hx) c)
/-- The equivalence between coarsenings of a valuation ring and its prime ideals. -/
@[simps apply]
def primeSpectrumEquiv : PrimeSpectrum A β {S // A β€ S} where
toFun P := β¨ofPrime A P.asIdeal, le_ofPrime _ _β©
invFun S := β¨idealOfLE _ S S.2, inferInstanceβ©
left_inv P := by ext1; simp
right_inv S := by ext1; simp
/-- An ordered variant of `primeSpectrumEquiv`. -/
@[simps!]
def primeSpectrumOrderEquiv : (PrimeSpectrum A)α΅α΅ βo {S // A β€ S} :=
{ OrderDual.ofDual.trans (primeSpectrumEquiv A) with
map_rel_iff' {a b} :=
β¨a.rec <| fun a => b.rec <| fun b => fun h => by
simp only [OrderDual.toDual_le_toDual]
dsimp at h
have := idealOfLE_le_of_le A _ _ ?_ ?_ h
Β· rwa [idealOfLE_ofPrime, idealOfLE_ofPrime] at this
all_goals exact le_ofPrime A (PrimeSpectrum.asIdeal _),
fun h => by apply ofPrime_le_of_le; exact hβ© }
instance le_total_ideal : IsTotal {S // A β€ S} LE.le := by
classical
let _ : IsTotal (PrimeSpectrum A) (Β· β€ Β·) := β¨fun β¨x, _β© β¨y, _β© => LE.isTotal.total x yβ©
exact β¨(primeSpectrumOrderEquiv A).symm.toRelEmbedding.isTotal.totalβ©
open scoped Classical in
instance linearOrderOverring : LinearOrder {S // A β€ S} where
le_total := (le_total_ideal A).1
max_def a b := congr_funβ sup_eq_maxDefault a b
toDecidableLE := _
end Order
end ValuationSubring
namespace Valuation
variable {K}
variable {Ξ Ξβ Ξβ : Type*} [LinearOrderedCommGroupWithZero Ξ]
[LinearOrderedCommGroupWithZero Ξβ] [LinearOrderedCommGroupWithZero Ξβ] (v : Valuation K Ξ)
(vβ : Valuation K Ξβ) (vβ : Valuation K Ξβ)
/-- The valuation subring associated to a valuation. -/
def valuationSubring : ValuationSubring K :=
{ v.integer with
mem_or_inv_mem' := by
intro x
rcases val_le_one_or_val_inv_le_one v x with h | h
exacts [Or.inl h, Or.inr h] }
@[simp]
theorem mem_valuationSubring_iff (x : K) : x β v.valuationSubring β v x β€ 1 := Iff.refl _
theorem isEquiv_iff_valuationSubring :
vβ.IsEquiv vβ β vβ.valuationSubring = vβ.valuationSubring := by
constructor
Β· intro h; ext x; specialize h x 1; simpa using h
Β· intro h; apply isEquiv_of_val_le_one
intro x
have : x β vβ.valuationSubring β x β vβ.valuationSubring := by rw [h]
simpa using this
theorem isEquiv_valuation_valuationSubring : v.IsEquiv v.valuationSubring.valuation := by
rw [isEquiv_iff_val_le_one]
intro x
rw [ValuationSubring.valuation_le_one_iff]
rfl
end Valuation
namespace ValuationSubring
variable {K}
variable (A : ValuationSubring K)
@[simp]
theorem valuationSubring_valuation : A.valuation.valuationSubring = A := by
ext; rw [β A.valuation_le_one_iff]; rfl
section UnitGroup
/-- The unit group of a valuation subring, as a subgroup of `KΛ£`. -/
def unitGroup : Subgroup KΛ£ :=
(A.valuation.toMonoidWithZeroHom.toMonoidHom.comp (Units.coeHom K)).ker
@[simp]
theorem mem_unitGroup_iff (x : KΛ£) : x β A.unitGroup β A.valuation x = 1 := Iff.rfl
/-- For a valuation subring `A`, `A.unitGroup` agrees with the units of `A`. -/
def unitGroupMulEquiv : A.unitGroup β* AΛ£ where
toFun x :=
{ val := β¨(x : KΛ£), mem_of_valuation_le_one A _ x.prop.leβ©
inv := β¨((xβ»ΒΉ : A.unitGroup) : KΛ£), mem_of_valuation_le_one _ _ xβ»ΒΉ.prop.leβ©
-- Porting note: was `Units.mul_inv x`
val_inv := Subtype.ext (by simp)
-- Porting note: was `Units.inv_mul x`
inv_val := Subtype.ext (by simp) }
invFun x := β¨Units.map A.subtype.toMonoidHom x, A.valuation_unit xβ©
left_inv a := by ext; rfl
right_inv a := by ext; rfl
map_mul' a b := by ext; rfl
@[simp]
theorem coe_unitGroupMulEquiv_apply (a : A.unitGroup) :
((A.unitGroupMulEquiv a : A) : K) = ((a : KΛ£) : K) := rfl
@[simp]
theorem coe_unitGroupMulEquiv_symm_apply (a : AΛ£) : ((A.unitGroupMulEquiv.symm a : KΛ£) : K) = a :=
rfl
theorem unitGroup_le_unitGroup {A B : ValuationSubring K} : A.unitGroup β€ B.unitGroup β A β€ B := by
constructor
Β· intro h x hx
rw [β A.valuation_le_one_iff x, le_iff_lt_or_eq] at hx
by_cases h_1 : x = 0; Β· simp only [h_1, zero_mem]
by_cases h_2 : 1 + x = 0
Β· simp only [β add_eq_zero_iff_neg_eq.1 h_2, neg_mem _ _ (one_mem _)]
rcases hx with hx | hx
Β· have := h (show Units.mk0 _ h_2 β A.unitGroup from A.valuation.map_one_add_of_lt hx)
simpa using
B.add_mem _ _ (show 1 + x β B from SetLike.coe_mem (B.unitGroupMulEquiv β¨_, thisβ© : B))
(B.neg_mem _ B.one_mem)
Β· have := h (show Units.mk0 x h_1 β A.unitGroup from hx)
exact SetLike.coe_mem (B.unitGroupMulEquiv β¨_, thisβ© : B)
Β· rintro h x (hx : A.valuation x = 1)
apply_fun A.mapOfLE B h at hx
simpa using hx
theorem unitGroup_injective : Function.Injective (unitGroup : ValuationSubring K β Subgroup _) :=
fun A B h => by simpa only [le_antisymm_iff, unitGroup_le_unitGroup] using h
theorem eq_iff_unitGroup {A B : ValuationSubring K} : A = B β A.unitGroup = B.unitGroup :=
unitGroup_injective.eq_iff.symm
/-- The map on valuation subrings to their unit groups is an order embedding. -/
def unitGroupOrderEmbedding : ValuationSubring K βͺo Subgroup KΛ£ where
toFun A := A.unitGroup
inj' := unitGroup_injective
map_rel_iff' {_A _B} := unitGroup_le_unitGroup
theorem unitGroup_strictMono : StrictMono (unitGroup : ValuationSubring K β Subgroup _) :=
unitGroupOrderEmbedding.strictMono
end UnitGroup
section nonunits
/-- The nonunits of a valuation subring of `K`, as a subsemigroup of `K` -/
def nonunits : Subsemigroup K where
carrier := {x | A.valuation x < 1}
-- Porting note: added `Set.mem_setOf.mp`
mul_mem' ha hb := (mul_lt_mul'' (Set.mem_setOf.mp ha) (Set.mem_setOf.mp hb)
zero_le' zero_le').trans_eq <| mul_one _
theorem mem_nonunits_iff {x : K} : x β A.nonunits β A.valuation x < 1 :=
Iff.rfl
theorem nonunits_le_nonunits {A B : ValuationSubring K} : B.nonunits β€ A.nonunits β A β€ B := by
constructor
Β· intro h x hx
by_cases h_1 : x = 0; Β· simp only [h_1, zero_mem]
rw [β valuation_le_one_iff, β not_lt, Valuation.one_lt_val_iff _ h_1] at hx β’
by_contra h_2; exact hx (h h_2)
Β· intro h x hx
by_contra h_1; exact not_lt.2 (monotone_mapOfLE _ _ h (not_lt.1 h_1)) hx
theorem nonunits_injective : Function.Injective (nonunits : ValuationSubring K β Subsemigroup _) :=
fun A B h => by simpa only [le_antisymm_iff, nonunits_le_nonunits] using h.symm
theorem nonunits_inj {A B : ValuationSubring K} : A.nonunits = B.nonunits β A = B :=
nonunits_injective.eq_iff
/-- The map on valuation subrings to their nonunits is a dual order embedding. -/
def nonunitsOrderEmbedding : ValuationSubring K βͺo (Subsemigroup K)α΅α΅ where
toFun A := A.nonunits
inj' := nonunits_injective
map_rel_iff' {_A _B} := nonunits_le_nonunits
variable {A}
/-- The elements of `A.nonunits` are those of the maximal ideal of `A` after coercion to `K`.
See also `mem_nonunits_iff_exists_mem_maximalIdeal`, which gets rid of the coercion to `K`,
at the expense of a more complicated right hand side.
-/
theorem coe_mem_nonunits_iff {a : A} : (a : K) β A.nonunits β a β IsLocalRing.maximalIdeal A :=
(valuation_lt_one_iff _ _).symm
theorem nonunits_le : A.nonunits β€ A.toSubring.toSubmonoid.toSubsemigroup := fun _a ha =>
(A.valuation_le_one_iff _).mp (A.mem_nonunits_iff.mp ha).le
theorem nonunits_subset : (A.nonunits : Set K) β A :=
nonunits_le
/-- The elements of `A.nonunits` are those of the maximal ideal of `A`.
See also `coe_mem_nonunits_iff`, which has a simpler right hand side but requires the element
to be in `A` already.
-/
theorem mem_nonunits_iff_exists_mem_maximalIdeal {a : K} :
a β A.nonunits β β ha, (β¨a, haβ© : A) β IsLocalRing.maximalIdeal A :=
β¨fun h => β¨nonunits_subset h, coe_mem_nonunits_iff.mp hβ©, fun β¨_, hβ© =>
coe_mem_nonunits_iff.mpr hβ©
/-- `A.nonunits` agrees with the maximal ideal of `A`, after taking its image in `K`. -/
theorem image_maximalIdeal : ((β) : A β K) '' IsLocalRing.maximalIdeal A = A.nonunits := by
ext a
simp only [Set.mem_image, SetLike.mem_coe, mem_nonunits_iff_exists_mem_maximalIdeal]
rw [Subtype.exists]
simp_rw [exists_and_right, exists_eq_right]
end nonunits
section PrincipalUnitGroup
/-- The principal unit group of a valuation subring, as a subgroup of `KΛ£`. -/
def principalUnitGroup : Subgroup KΛ£ where
carrier := {x | A.valuation (x - 1) < 1}
mul_mem' := by
intro a b ha hb
-- Porting note: added
rw [Set.mem_setOf] at ha hb
refine lt_of_le_of_lt ?_ (max_lt hb ha)
-- Porting note: `sub_add_sub_cancel` needed some help
rw [β one_mul (A.valuation (b - 1)), β A.valuation.map_one_add_of_lt ha, add_sub_cancel,
β Valuation.map_mul, mul_sub_one, β sub_add_sub_cancel (β(a * b) : K) _ 1]
exact A.valuation.map_add _ _
one_mem' := by simp
inv_mem' := by
dsimp
intro a ha
conv =>
lhs
rw [β mul_one (A.valuation _), β A.valuation.map_one_add_of_lt ha]
rwa [add_sub_cancel, β Valuation.map_mul, sub_mul, Units.inv_mul, β neg_sub, one_mul,
Valuation.map_neg]
theorem principal_units_le_units : A.principalUnitGroup β€ A.unitGroup := fun a h => by
simpa only [add_sub_cancel] using A.valuation.map_one_add_of_lt h
theorem mem_principalUnitGroup_iff (x : KΛ£) :
x β A.principalUnitGroup β A.valuation ((x : K) - 1) < 1 :=
Iff.rfl
theorem principalUnitGroup_le_principalUnitGroup {A B : ValuationSubring K} :
B.principalUnitGroup β€ A.principalUnitGroup β A β€ B := by
constructor
Β· intro h x hx
by_cases h_1 : x = 0; Β· simp only [h_1, zero_mem]
by_cases h_2 : xβ»ΒΉ + 1 = 0
Β· rw [add_eq_zero_iff_eq_neg, inv_eq_iff_eq_inv, inv_neg, inv_one] at h_2
simpa only [h_2] using B.neg_mem _ B.one_mem
Β· rw [β valuation_le_one_iff, β not_lt, Valuation.one_lt_val_iff _ h_1,
β add_sub_cancel_right xβ»ΒΉ, β Units.val_mk0 h_2, β mem_principalUnitGroup_iff] at hx β’
simpa only [hx] using @h (Units.mk0 (xβ»ΒΉ + 1) h_2)
Β· intro h x hx
by_contra h_1; exact not_lt.2 (monotone_mapOfLE _ _ h (not_lt.1 h_1)) hx
theorem principalUnitGroup_injective :
Function.Injective (principalUnitGroup : ValuationSubring K β Subgroup _) := fun A B h => by
simpa [le_antisymm_iff, principalUnitGroup_le_principalUnitGroup] using h.symm
theorem eq_iff_principalUnitGroup {A B : ValuationSubring K} :
A = B β A.principalUnitGroup = B.principalUnitGroup :=
principalUnitGroup_injective.eq_iff.symm
/-- The map on valuation subrings to their principal unit groups is an order embedding. -/
def principalUnitGroupOrderEmbedding : ValuationSubring K βͺo (Subgroup KΛ£)α΅α΅ where
toFun A := A.principalUnitGroup
inj' := principalUnitGroup_injective
map_rel_iff' {_A _B} := principalUnitGroup_le_principalUnitGroup
theorem coe_mem_principalUnitGroup_iff {x : A.unitGroup} :
(x : KΛ£) β A.principalUnitGroup β
A.unitGroupMulEquiv x β (Units.map (IsLocalRing.residue A).toMonoidHom).ker := by
rw [MonoidHom.mem_ker, Units.ext_iff]
let Ο := Ideal.Quotient.mk (IsLocalRing.maximalIdeal A); convert_to _ β Ο _ = 1
rw [β Ο.map_one, β sub_eq_zero, β Ο.map_sub, Ideal.Quotient.eq_zero_iff_mem, valuation_lt_one_iff]
simp [mem_principalUnitGroup_iff]
/-- The principal unit group agrees with the kernel of the canonical map from
the units of `A` to the units of the residue field of `A`. -/
def principalUnitGroupEquiv :
A.principalUnitGroup β* (Units.map (IsLocalRing.residue A).toMonoidHom).ker where
toFun x :=
β¨A.unitGroupMulEquiv β¨_, A.principal_units_le_units x.2β©,
A.coe_mem_principalUnitGroup_iff.1 x.2β©
invFun x :=
β¨A.unitGroupMulEquiv.symm x, by
rw [A.coe_mem_principalUnitGroup_iff]; simpβ©
left_inv x := by simp
right_inv x := by simp
map_mul' _ _ := rfl
theorem principalUnitGroupEquiv_apply (a : A.principalUnitGroup) :
(((principalUnitGroupEquiv A a : AΛ£) : A) : K) = (a : KΛ£) :=
rfl
theorem principalUnitGroup_symm_apply (a : (Units.map (IsLocalRing.residue A).toMonoidHom).ker) :
((A.principalUnitGroupEquiv.symm a : KΛ£) : K) = ((a : AΛ£) : A) :=
rfl
/-- The canonical map from the unit group of `A` to the units of the residue field of `A`. -/
def unitGroupToResidueFieldUnits : A.unitGroup β* (IsLocalRing.ResidueField A)Λ£ :=
MonoidHom.comp (Units.map <| (Ideal.Quotient.mk _).toMonoidHom) A.unitGroupMulEquiv.toMonoidHom
@[simp]
theorem coe_unitGroupToResidueFieldUnits_apply (x : A.unitGroup) :
(A.unitGroupToResidueFieldUnits x : IsLocalRing.ResidueField A) =
Ideal.Quotient.mk _ (A.unitGroupMulEquiv x : A) :=
rfl
theorem ker_unitGroupToResidueFieldUnits :
A.unitGroupToResidueFieldUnits.ker = A.principalUnitGroup.comap A.unitGroup.subtype := by
ext
simp_rw [Subgroup.mem_comap, Subgroup.coe_subtype, coe_mem_principalUnitGroup_iff,
unitGroupToResidueFieldUnits, IsLocalRing.residue, RingHom.toMonoidHom_eq_coe,
MulEquiv.toMonoidHom_eq_coe, MonoidHom.mem_ker, MonoidHom.coe_comp, MonoidHom.coe_coe,
Function.comp_apply]
theorem surjective_unitGroupToResidueFieldUnits :
Function.Surjective A.unitGroupToResidueFieldUnits :=
(IsLocalRing.surjective_units_map_of_local_ringHom _ Ideal.Quotient.mk_surjective
IsLocalRing.isLocalHom_residue).comp
(MulEquiv.surjective _)
/-- The quotient of the unit group of `A` by the principal unit group of `A` agrees with
the units of the residue field of `A`. -/
def unitsModPrincipalUnitsEquivResidueFieldUnits :
A.unitGroup β§Έ A.principalUnitGroup.comap A.unitGroup.subtype β* (IsLocalRing.ResidueField A)Λ£ :=
(QuotientGroup.quotientMulEquivOfEq A.ker_unitGroupToResidueFieldUnits.symm).trans
(QuotientGroup.quotientKerEquivOfSurjective _ A.surjective_unitGroupToResidueFieldUnits)
/-- Porting note: Lean needs to be reminded of this instance -/
local instance : MulOneClass ({ x // x β unitGroup A } β§Έ
Subgroup.comap (Subgroup.subtype (unitGroup A)) (principalUnitGroup A)) := inferInstance
theorem unitsModPrincipalUnitsEquivResidueFieldUnits_comp_quotientGroup_mk :
(A.unitsModPrincipalUnitsEquivResidueFieldUnits : _ β§Έ Subgroup.comap _ _ β* _).comp
(QuotientGroup.mk' (A.principalUnitGroup.subgroupOf A.unitGroup)) =
A.unitGroupToResidueFieldUnits := rfl
theorem unitsModPrincipalUnitsEquivResidueFieldUnits_comp_quotientGroup_mk_apply
(x : A.unitGroup) :
A.unitsModPrincipalUnitsEquivResidueFieldUnits.toMonoidHom (QuotientGroup.mk x) =
A.unitGroupToResidueFieldUnits x := rfl
end PrincipalUnitGroup
/-! ### Pointwise actions
This transfers the action from `Subring.pointwiseMulAction`, noting that it only applies when
the action is by a group. Notably this provides an instances when `G` is `K β+* K`.
These instances are in the `Pointwise` locale.
The lemmas in this section are copied from the file `Mathlib.Algebra.Ring.Subring.Pointwise`; try
to keep these in sync.
-/
section PointwiseActions
open scoped Pointwise
variable {G : Type*} [Group G] [MulSemiringAction G K]
/-- The action on a valuation subring corresponding to applying the action to every element.
This is available as an instance in the `Pointwise` locale. -/
def pointwiseHasSMul : SMul G (ValuationSubring K) where
smul g S :=-- TODO: if we add `ValuationSubring.map` at a later date, we should use it here
{ g β’ S.toSubring with
mem_or_inv_mem' := fun x =>
(mem_or_inv_mem S (gβ»ΒΉ β’ x)).imp Subring.mem_pointwise_smul_iff_inv_smul_mem.mpr fun h =>
Subring.mem_pointwise_smul_iff_inv_smul_mem.mpr <| by rwa [smul_inv''] }
scoped[Pointwise] attribute [instance] ValuationSubring.pointwiseHasSMul
open scoped Pointwise
@[simp]
theorem coe_pointwise_smul (g : G) (S : ValuationSubring K) : β(g β’ S) = g β’ (S : Set K) := rfl
@[simp]
theorem pointwise_smul_toSubring (g : G) (S : ValuationSubring K) :
(g β’ S).toSubring = g β’ S.toSubring := rfl
/-- The action on a valuation subring corresponding to applying the action to every element.
This is available as an instance in the `Pointwise` locale.
This is a stronger version of `ValuationSubring.pointwiseSMul`. -/
def pointwiseMulAction : MulAction G (ValuationSubring K) :=
toSubring_injective.mulAction toSubring pointwise_smul_toSubring
| scoped[Pointwise] attribute [instance] ValuationSubring.pointwiseMulAction
open scoped Pointwise
theorem smul_mem_pointwise_smul (g : G) (x : K) (S : ValuationSubring K) : x β S β g β’ x β g β’ S :=
(Set.smul_mem_smul_set : _ β _ β g β’ (S : Set K))
instance : CovariantClass G (ValuationSubring K) HSMul.hSMul LE.le :=
| Mathlib/RingTheory/Valuation/ValuationSubring.lean | 733 | 740 |
/-
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
| Mathlib/Analysis/SpecialFunctions/Trigonometric/Deriv.lean | 751 | 758 |
/-
Copyright (c) 2022 Jujian Zhang. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jujian Zhang, Junyan Xu
-/
import Mathlib.Topology.Sheaves.PUnit
import Mathlib.Topology.Sheaves.Stalks
import Mathlib.Topology.Sheaves.Functors
/-!
# Skyscraper (pre)sheaves
A skyscraper (pre)sheaf `π : (Pre)Sheaf C X` is the (pre)sheaf with value `A` at point `pβ` that is
supported only at open sets contain `pβ`, i.e. `π(U) = A` if `pβ β U` and `π(U) = *` if `pβ β U`
where `*` is a terminal object of `C`. In terms of stalks, `π` is supported at all specializations
of `pβ`, i.e. if `pβ β€³ x` then `πβ β
A` and if `Β¬ pβ β€³ x` then `πβ β
*`.
## Main definitions
* `skyscraperPresheaf`: `skyscraperPresheaf pβ A` is the skyscraper presheaf at point `pβ` with
value `A`.
* `skyscraperSheaf`: the skyscraper presheaf satisfies the sheaf condition.
## Main statements
* `skyscraperPresheafStalkOfSpecializes`: if `y β closure {pβ}` then the stalk of
`skyscraperPresheaf pβ A` at `y` is `A`.
* `skyscraperPresheafStalkOfNotSpecializes`: if `y β closure {pβ}` then the stalk of
`skyscraperPresheaf pβ A` at `y` is `*` the terminal object.
TODO: generalize universe level when calculating stalks, after generalizing universe level of stalk.
-/
noncomputable section
open TopologicalSpace TopCat CategoryTheory CategoryTheory.Limits Opposite
open scoped AlgebraicGeometry
universe u v w
variable {X : TopCat.{u}} (pβ : X) [β U : Opens X, Decidable (pβ β U)]
section
variable {C : Type v} [Category.{w} C] [HasTerminal C] (A : C)
/-- A skyscraper presheaf is a presheaf supported at a single point: if `pβ β X` is a specified
point, then the skyscraper presheaf `π` with value `A` is defined by `U β¦ A` if `pβ β U` and
`U β¦ *` if `pβ β A` where `*` is some terminal object.
-/
@[simps]
def skyscraperPresheaf : Presheaf C X where
obj U := if pβ β unop U then A else terminal C
map {U V} i :=
if h : pβ β unop V then eqToHom <| by rw [if_pos h, if_pos (by simpa using i.unop.le h)]
else ((if_neg h).symm.ndrec terminalIsTerminal).from _
map_id U :=
(em (pβ β U.unop)).elim (fun h => dif_pos h) fun h =>
((if_neg h).symm.ndrec terminalIsTerminal).hom_ext _ _
map_comp {U V W} iVU iWV := by
by_cases hW : pβ β unop W
Β· have hV : pβ β unop V := leOfHom iWV.unop hW
simp only [dif_pos hW, dif_pos hV, eqToHom_trans]
Β· dsimp; rw [dif_neg hW]; apply ((if_neg hW).symm.ndrec terminalIsTerminal).hom_ext
theorem skyscraperPresheaf_eq_pushforward
[hd : β U : Opens (TopCat.of PUnit.{u + 1}), Decidable (PUnit.unit β U)] :
skyscraperPresheaf pβ A =
(ofHom (ContinuousMap.const (TopCat.of PUnit) pβ)) _*
skyscraperPresheaf (X := TopCat.of PUnit) PUnit.unit A := by
convert_to @skyscraperPresheaf X pβ (fun U => hd <| (Opens.map <| ofHom <|
ContinuousMap.const _ pβ).obj U)
C _ _ A = _ <;> congr
/-- Taking skyscraper presheaf at a point is functorial: `c β¦ skyscraper pβ c` defines a functor by
sending every `f : a βΆ b` to the natural transformation `Ξ±` defined as: `Ξ±(U) = f : a βΆ b` if
`pβ β U` and the unique morphism to a terminal object in `C` if `pβ β U`.
-/
@[simps]
def SkyscraperPresheafFunctor.map' {a b : C} (f : a βΆ b) :
skyscraperPresheaf pβ a βΆ skyscraperPresheaf pβ b where
app U :=
if h : pβ β U.unop then eqToHom (if_pos h) β« f β« eqToHom (if_pos h).symm
else ((if_neg h).symm.ndrec terminalIsTerminal).from _
naturality U V i := by
simp only [skyscraperPresheaf_map]
by_cases hV : pβ β V.unop
Β· have hU : pβ β U.unop := leOfHom i.unop hV
simp only [skyscraperPresheaf_obj, hU, hV, βreduceDIte, eqToHom_trans_assoc, Category.assoc,
eqToHom_trans]
Β· apply ((if_neg hV).symm.ndrec terminalIsTerminal).hom_ext
theorem SkyscraperPresheafFunctor.map'_id {a : C} :
| SkyscraperPresheafFunctor.map' pβ (π a) = π _ := by
ext U
simp only [SkyscraperPresheafFunctor.map'_app, NatTrans.id_app]; split_ifs <;> aesop_cat
| Mathlib/Topology/Sheaves/Skyscraper.lean | 94 | 97 |
/-
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.Order.Interval.Set.OrderEmbedding
import Mathlib.Order.Antichain
import Mathlib.Order.SetNotation
/-!
# Order-connected sets
We say that a set `s : Set Ξ±` is `OrdConnected` if for all `x y β s` it includes the
interval `[[x, y]]`. If `Ξ±` is a `DenselyOrdered` `ConditionallyCompleteLinearOrder` with
the `OrderTopology`, then this condition is equivalent to `IsPreconnected s`. If `Ξ±` is a
`LinearOrderedField`, then this condition is also equivalent to `Convex Ξ± s`.
In this file we prove that intersection of a family of `OrdConnected` sets is `OrdConnected` and
that all standard intervals are `OrdConnected`.
-/
open scoped Interval
open Set
open OrderDual (toDual ofDual)
namespace Set
section Preorder
variable {Ξ± Ξ² : Type*} [Preorder Ξ±] [Preorder Ξ²] {s : Set Ξ±}
theorem OrdConnected.out (h : OrdConnected s) : β β¦xβ¦ (_ : x β s) β¦yβ¦ (_ : y β s), Icc x y β s :=
h.1
theorem ordConnected_def : OrdConnected s β β β¦xβ¦ (_ : x β s) β¦yβ¦ (_ : y β s), Icc x y β s :=
β¨fun h => h.1, fun h => β¨hβ©β©
/-- It suffices to prove `[[x, y]] β s` for `x y β s`, `x β€ y`. -/
theorem ordConnected_iff : OrdConnected s β β x β s, β y β s, x β€ y β Icc x y β s :=
ordConnected_def.trans
β¨fun hs _ hx _ hy _ => hs hx hy, fun H x hx y hy _ hz => H x hx y hy (le_trans hz.1 hz.2) hzβ©
theorem ordConnected_of_Ioo {Ξ± : Type*} [PartialOrder Ξ±] {s : Set Ξ±}
(hs : β x β s, β y β s, x < y β Ioo x y β s) : OrdConnected s := by
rw [ordConnected_iff]
intro x hx y hy hxy
rcases eq_or_lt_of_le hxy with (rfl | hxy'); Β· simpa
rw [β Ioc_insert_left hxy, β Ioo_insert_right hxy']
exact insert_subset_iff.2 β¨hx, insert_subset_iff.2 β¨hy, hs x hx y hy hxy'β©β©
theorem OrdConnected.preimage_mono {f : Ξ² β Ξ±} (hs : OrdConnected s) (hf : Monotone f) :
OrdConnected (f β»ΒΉ' s) :=
β¨fun _ hx _ hy _ hz => hs.out hx hy β¨hf hz.1, hf hz.2β©β©
theorem OrdConnected.preimage_anti {f : Ξ² β Ξ±} (hs : OrdConnected s) (hf : Antitone f) :
OrdConnected (f β»ΒΉ' s) :=
β¨fun _ hx _ hy _ hz => hs.out hy hx β¨hf hz.2, hf hz.1β©β©
protected theorem Icc_subset (s : Set Ξ±) [hs : OrdConnected s] {x y} (hx : x β s) (hy : y β s) :
Icc x y β s :=
hs.out hx hy
end Preorder
end Set
namespace OrderEmbedding
variable {Ξ± Ξ² : Type*} [Preorder Ξ±] [Preorder Ξ²]
theorem image_Icc (e : Ξ± βͺo Ξ²) (he : OrdConnected (range e)) (x y : Ξ±) :
e '' Icc x y = Icc (e x) (e y) := by
rw [β e.preimage_Icc, image_preimage_eq_inter_range, inter_eq_left.2 (he.out β¨_, rflβ© β¨_, rflβ©)]
theorem image_Ico (e : Ξ± βͺo Ξ²) (he : OrdConnected (range e)) (x y : Ξ±) :
e '' Ico x y = Ico (e x) (e y) := by
rw [β e.preimage_Ico, image_preimage_eq_inter_range,
inter_eq_left.2 <| Ico_subset_Icc_self.trans <| he.out β¨_, rflβ© β¨_, rflβ©]
theorem image_Ioc (e : Ξ± βͺo Ξ²) (he : OrdConnected (range e)) (x y : Ξ±) :
e '' Ioc x y = Ioc (e x) (e y) := by
rw [β e.preimage_Ioc, image_preimage_eq_inter_range,
inter_eq_left.2 <| Ioc_subset_Icc_self.trans <| he.out β¨_, rflβ© β¨_, rflβ©]
theorem image_Ioo (e : Ξ± βͺo Ξ²) (he : OrdConnected (range e)) (x y : Ξ±) :
e '' Ioo x y = Ioo (e x) (e y) := by
rw [β e.preimage_Ioo, image_preimage_eq_inter_range,
inter_eq_left.2 <| Ioo_subset_Icc_self.trans <| he.out β¨_, rflβ© β¨_, rflβ©]
end OrderEmbedding
namespace Set
section Preorder
variable {Ξ± Ξ² : Type*} [Preorder Ξ±] [Preorder Ξ²]
@[simp]
lemma image_subtype_val_Icc {s : Set Ξ±} [OrdConnected s] (x y : s) :
Subtype.val '' Icc x y = Icc x.1 y :=
(OrderEmbedding.subtype (Β· β s)).image_Icc (by simpa) x y
@[simp]
lemma image_subtype_val_Ico {s : Set Ξ±} [OrdConnected s] (x y : s) :
Subtype.val '' Ico x y = Ico x.1 y :=
(OrderEmbedding.subtype (Β· β s)).image_Ico (by simpa) x y
@[simp]
lemma image_subtype_val_Ioc {s : Set Ξ±} [OrdConnected s] (x y : s) :
Subtype.val '' Ioc x y = Ioc x.1 y :=
(OrderEmbedding.subtype (Β· β s)).image_Ioc (by simpa) x y
@[simp]
lemma image_subtype_val_Ioo {s : Set Ξ±} [OrdConnected s] (x y : s) :
Subtype.val '' Ioo x y = Ioo x.1 y :=
(OrderEmbedding.subtype (Β· β s)).image_Ioo (by simpa) x y
theorem OrdConnected.inter {s t : Set Ξ±} (hs : OrdConnected s) (ht : OrdConnected t) :
OrdConnected (s β© t) :=
β¨fun _ hx _ hy => subset_inter (hs.out hx.1 hy.1) (ht.out hx.2 hy.2)β©
instance OrdConnected.inter' {s t : Set Ξ±} [OrdConnected s] [OrdConnected t] :
OrdConnected (s β© t) :=
OrdConnected.inter βΉ_βΊ βΉ_βΊ
theorem OrdConnected.dual {s : Set Ξ±} (hs : OrdConnected s) :
OrdConnected (OrderDual.ofDual β»ΒΉ' s) :=
β¨fun _ hx _ hy _ hz => hs.out hy hx β¨hz.2, hz.1β©β©
theorem ordConnected_dual {s : Set Ξ±} : OrdConnected (OrderDual.ofDual β»ΒΉ' s) β OrdConnected s :=
β¨fun h => by simpa only [ordConnected_def] using h.dual, fun h => h.dualβ©
theorem ordConnected_sInter {S : Set (Set Ξ±)} (hS : β s β S, OrdConnected s) :
OrdConnected (ββ S) :=
β¨fun _x hx _y hy _z hz s hs => (hS s hs).out (hx s hs) (hy s hs) hzβ©
theorem ordConnected_iInter {ΞΉ : Sort*} {s : ΞΉ β Set Ξ±} (hs : β i, OrdConnected (s i)) :
OrdConnected (β i, s i) :=
ordConnected_sInter <| forall_mem_range.2 hs
instance ordConnected_iInter' {ΞΉ : Sort*} {s : ΞΉ β Set Ξ±} [β i, OrdConnected (s i)] :
OrdConnected (β i, s i) :=
ordConnected_iInter βΉ_βΊ
theorem ordConnected_biInter {ΞΉ : Sort*} {p : ΞΉ β Prop} {s : β i, p i β Set Ξ±}
(hs : β i hi, OrdConnected (s i hi)) : OrdConnected (β (i) (hi), s i hi) :=
ordConnected_iInter fun i => ordConnected_iInter <| hs i
theorem ordConnected_pi {ΞΉ : Type*} {Ξ± : ΞΉ β Type*} [β i, Preorder (Ξ± i)] {s : Set ΞΉ}
{t : β i, Set (Ξ± i)} (h : β i β s, OrdConnected (t i)) : OrdConnected (s.pi t) :=
β¨fun _ hx _ hy _ hz i hi => (h i hi).out (hx i hi) (hy i hi) β¨hz.1 i, hz.2 iβ©β©
instance ordConnected_pi' {ΞΉ : Type*} {Ξ± : ΞΉ β Type*} [β i, Preorder (Ξ± i)] {s : Set ΞΉ}
{t : β i, Set (Ξ± i)} [h : β i, OrdConnected (t i)] : OrdConnected (s.pi t) :=
ordConnected_pi fun i _ => h i
@[instance]
theorem ordConnected_Ici {a : Ξ±} : OrdConnected (Ici a) :=
β¨fun _ hx _ _ _ hz => le_trans hx hz.1β©
@[instance]
theorem ordConnected_Iic {a : Ξ±} : OrdConnected (Iic a) :=
β¨fun _ _ _ hy _ hz => le_trans hz.2 hyβ©
@[instance]
theorem ordConnected_Ioi {a : Ξ±} : OrdConnected (Ioi a) :=
β¨fun _ hx _ _ _ hz => lt_of_lt_of_le hx hz.1β©
@[instance]
theorem ordConnected_Iio {a : Ξ±} : OrdConnected (Iio a) :=
β¨fun _ _ _ hy _ hz => lt_of_le_of_lt hz.2 hyβ©
@[instance]
theorem ordConnected_Icc {a b : Ξ±} : OrdConnected (Icc a b) :=
ordConnected_Ici.inter ordConnected_Iic
@[instance]
theorem ordConnected_Ico {a b : Ξ±} : OrdConnected (Ico a b) :=
ordConnected_Ici.inter ordConnected_Iio
@[instance]
theorem ordConnected_Ioc {a b : Ξ±} : OrdConnected (Ioc a b) :=
ordConnected_Ioi.inter ordConnected_Iic
@[instance]
theorem ordConnected_Ioo {a b : Ξ±} : OrdConnected (Ioo a b) :=
ordConnected_Ioi.inter ordConnected_Iio
@[instance]
theorem ordConnected_singleton {Ξ± : Type*} [PartialOrder Ξ±] {a : Ξ±} :
OrdConnected ({a} : Set Ξ±) := by
rw [β Icc_self]
exact ordConnected_Icc
@[instance]
theorem ordConnected_empty : OrdConnected (β
: Set Ξ±) :=
β¨fun _ => False.elimβ©
@[instance]
theorem ordConnected_univ : OrdConnected (univ : Set Ξ±) :=
β¨fun _ _ _ _ => subset_univ _β©
/-- In a dense order `Ξ±`, the subtype from an `OrdConnected` set is also densely ordered. -/
instance instDenselyOrdered [DenselyOrdered Ξ±] {s : Set Ξ±} [hs : OrdConnected s] :
DenselyOrdered s :=
β¨fun a b (h : (a : Ξ±) < b) =>
let β¨x, Hβ© := exists_between h
β¨β¨x, (hs.out a.2 b.2) (Ioo_subset_Icc_self H)β©, Hβ©β©
@[instance]
theorem ordConnected_preimage {F : Type*} [FunLike F Ξ± Ξ²] [OrderHomClass F Ξ± Ξ²] (f : F)
{s : Set Ξ²} [hs : OrdConnected s] : OrdConnected (f β»ΒΉ' s) :=
β¨fun _ hx _ hy _ hz => hs.out hx hy β¨OrderHomClass.mono _ hz.1, OrderHomClass.mono _ hz.2β©β©
@[instance]
theorem ordConnected_image {E : Type*} [EquivLike E Ξ± Ξ²] [OrderIsoClass E Ξ± Ξ²] (e : E) {s : Set Ξ±}
[hs : OrdConnected s] : OrdConnected (e '' s) := by
erw [(e : Ξ± βo Ξ²).image_eq_preimage]
apply ordConnected_preimage (e : Ξ± βo Ξ²).symm
@[instance]
theorem ordConnected_range {E : Type*} [EquivLike E Ξ± Ξ²] [OrderIsoClass E Ξ± Ξ²] (e : E) :
OrdConnected (range e) := by
simp_rw [β image_univ]
exact ordConnected_image (e : Ξ± βo Ξ²)
@[simp]
theorem dual_ordConnected_iff {s : Set Ξ±} : OrdConnected (ofDual β»ΒΉ' s) β OrdConnected s := by
simp_rw [ordConnected_def, toDual.surjective.forall, Icc_toDual, Subtype.forall']
exact forall_swap
@[instance]
theorem dual_ordConnected {s : Set Ξ±} [OrdConnected s] : OrdConnected (ofDual β»ΒΉ' s) :=
dual_ordConnected_iff.2 βΉ_βΊ
end Preorder
section PartialOrder
variable {Ξ± : Type*} [PartialOrder Ξ±] {s : Set Ξ±} {x y : Ξ±}
protected theorem _root_.IsAntichain.ordConnected (hs : IsAntichain (Β· β€ Β·) s) : s.OrdConnected :=
β¨fun x hx y hy z hz => by
obtain rfl := hs.eq hx hy (hz.1.trans hz.2)
rw [Icc_self, mem_singleton_iff] at hz
rwa [hz]β©
lemma ordConnected_inter_Icc_of_subset (h : Ioo x y β s) : OrdConnected (s β© Icc x y) :=
ordConnected_of_Ioo fun _u β¨_, hu, _β© _v β¨_, _, hvβ© _ β¦
Ioo_subset_Ioo hu hv |>.trans <| subset_inter h Ioo_subset_Icc_self
lemma ordConnected_inter_Icc_iff (hx : x β s) (hy : y β s) :
OrdConnected (s β© Icc x y) β Ioo x y β s := by
refine β¨fun h β¦ Ioo_subset_Icc_self.trans fun z hz β¦ ?_, ordConnected_inter_Icc_of_subsetβ©
have hxy : x β€ y := hz.1.trans hz.2
exact h.out β¨hx, left_mem_Icc.2 hxyβ© β¨hy, right_mem_Icc.2 hxyβ© hz |>.1
lemma not_ordConnected_inter_Icc_iff (hx : x β s) (hy : y β s) :
Β¬ OrdConnected (s β© Icc x y) β β z β s, z β Ioo x y := by
simp_rw [ordConnected_inter_Icc_iff hx hy, subset_def, not_forall, exists_prop, and_comm]
end PartialOrder
section LinearOrder
open scoped Interval
variable {Ξ± : Type*} [LinearOrder Ξ±] {s : Set Ξ±} {x : Ξ±}
@[instance]
theorem ordConnected_uIcc {a b : Ξ±} : OrdConnected [[a, b]] :=
ordConnected_Icc
@[instance]
theorem ordConnected_uIoc {a b : Ξ±} : OrdConnected (Ξ a b) :=
ordConnected_Ioc
theorem OrdConnected.uIcc_subset (hs : OrdConnected s) β¦xβ¦ (hx : x β s) β¦yβ¦ (hy : y β s) :
[[x, y]] β s :=
hs.out (min_rec' (Β· β s) hx hy) (max_rec' (Β· β s) hx hy)
theorem OrdConnected.uIoc_subset (hs : OrdConnected s) β¦xβ¦ (hx : x β s) β¦yβ¦ (hy : y β s) :
Ξ x y β s :=
Ioc_subset_Icc_self.trans <| hs.uIcc_subset hx hy
theorem ordConnected_iff_uIcc_subset :
OrdConnected s β β β¦xβ¦ (_ : x β s) β¦yβ¦ (_ : y β s), [[x, y]] β s :=
β¨fun h => h.uIcc_subset, fun H => β¨fun _ hx _ hy => Icc_subset_uIcc.trans <| H hx hyβ©β©
theorem ordConnected_of_uIcc_subset_left (h : β y β s, [[x, y]] β s) : OrdConnected s :=
ordConnected_iff_uIcc_subset.2 fun y hy z hz =>
calc
[[y, z]] β [[y, x]] βͺ [[x, z]] := uIcc_subset_uIcc_union_uIcc
_ = [[x, y]] βͺ [[x, z]] := by rw [uIcc_comm]
_ β s := union_subset (h y hy) (h z hz)
theorem ordConnected_iff_uIcc_subset_left (hx : x β s) :
OrdConnected s β β β¦yβ¦, y β s β [[x, y]] β s :=
β¨fun hs => hs.uIcc_subset hx, ordConnected_of_uIcc_subset_leftβ©
theorem ordConnected_iff_uIcc_subset_right (hx : x β s) :
OrdConnected s β β β¦yβ¦, y β s β [[y, x]] β s := by
simp_rw [ordConnected_iff_uIcc_subset_left hx, uIcc_comm]
end LinearOrder
end Set
| Mathlib/Order/Interval/Set/OrdConnected.lean | 353 | 355 | |
/-
Copyright (c) 2020 Anne Baanen. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Anne Baanen
-/
import Mathlib.Algebra.Group.Defs
/-!
# Invertible elements
This file defines a typeclass `Invertible a` for elements `a` with a two-sided
multiplicative inverse.
The intent of the typeclass is to provide a way to write e.g. `β
2` in a ring
like `β€[1/2]` where some inverses exist but there is no general `β»ΒΉ` operator;
or to specify that a field has characteristic `β 2`.
It is the `Type`-valued analogue to the `Prop`-valued `IsUnit`.
For constructions of the invertible element given a characteristic, see
`Algebra/CharP/Invertible` and other lemmas in that file.
## Notation
* `β
a` is `Invertible.invOf a`, the inverse of `a`
## Implementation notes
The `Invertible` class lives in `Type`, not `Prop`, to make computation easier.
If multiplication is associative, `Invertible` is a subsingleton anyway.
The `simp` normal form tries to normalize `β
a` to `a β»ΒΉ`. Otherwise, it pushes
`β
` inside the expression as much as possible.
Since `Invertible a` is not a `Prop` (but it is a `Subsingleton`), we have to be careful about
coherence issues: we should avoid having multiple non-defeq instances for `Invertible a` in the
same context. This file plays it safe and uses `def` rather than `instance` for most definitions,
users can choose which instances to use at the point of use.
For example, here's how you can use an `Invertible 1` instance:
```lean
variable {Ξ± : Type*} [Monoid Ξ±]
def something_that_needs_inverses (x : Ξ±) [Invertible x] := sorry
section
attribute [local instance] invertibleOne
def something_one := something_that_needs_inverses 1
end
```
### Typeclass search vs. unification for `simp` lemmas
Note that since typeclass search searches the local context first, an instance argument like
`[Invertible a]` might sometimes be filled by a different term than the one we'd find by
unification (i.e., the one that's used as an implicit argument to `β
`).
This can cause issues with `simp`. Therefore, some lemmas are duplicated, with the `@[simp]`
versions using unification and the user-facing ones using typeclass search.
Since unification can make backwards rewriting (e.g. `rw [β mylemma]`) impractical, we still want
the instance-argument versions; therefore the user-facing versions retain the instance arguments
and the original lemma name, whereas the `@[simp]`/unification ones acquire a `'` at the end of
their name.
We modify this file according to the above pattern only as needed; therefore, most `@[simp]` lemmas
here are not part of such a duplicate pair. This is not (yet) intended as a permanent solution.
See Zulip: [https://leanprover.zulipchat.com/#narrow/stream/287929-mathlib4/topic/Invertible.201.20simps/near/320558233]
## Tags
invertible, inverse element, invOf, a half, one half, a third, one third, Β½, β
-/
assert_not_exists MonoidWithZero DenselyOrdered
universe u
variable {Ξ± : Type u}
/-- `Invertible a` gives a two-sided multiplicative inverse of `a`. -/
class Invertible [Mul Ξ±] [One Ξ±] (a : Ξ±) : Type u where
/-- The inverse of an `Invertible` element -/
invOf : Ξ±
/-- `invOf a` is a left inverse of `a` -/
invOf_mul_self : invOf * a = 1
/-- `invOf a` is a right inverse of `a` -/
mul_invOf_self : a * invOf = 1
/-- The inverse of an `Invertible` element -/
-- This notation has the same precedence as `Inv.inv`.
prefix:max "β
" => Invertible.invOf
@[simp]
theorem invOf_mul_self' [Mul Ξ±] [One Ξ±] (a : Ξ±) {_ : Invertible a} : β
a * a = 1 :=
Invertible.invOf_mul_self
theorem invOf_mul_self [Mul Ξ±] [One Ξ±] (a : Ξ±) [Invertible a] : β
a * a = 1 := invOf_mul_self' _
@[simp]
theorem mul_invOf_self' [Mul Ξ±] [One Ξ±] (a : Ξ±) {_ : Invertible a} : a * β
a = 1 :=
Invertible.mul_invOf_self
theorem mul_invOf_self [Mul Ξ±] [One Ξ±] (a : Ξ±) [Invertible a] : a * β
a = 1 := mul_invOf_self' _
@[simp]
theorem invOf_mul_cancel_left' [Monoid Ξ±] (a b : Ξ±) {_ : Invertible a} : β
a * (a * b) = b := by
rw [β mul_assoc, invOf_mul_self, one_mul]
example {G} [Group G] (a b : G) : aβ»ΒΉ * (a * b) = b := inv_mul_cancel_left a b
theorem invOf_mul_cancel_left [Monoid Ξ±] (a b : Ξ±) [Invertible a] : β
a * (a * b) = b :=
invOf_mul_cancel_left' _ _
@[simp]
theorem mul_invOf_cancel_left' [Monoid Ξ±] (a b : Ξ±) {_ : Invertible a} : a * (β
a * b) = b := by
rw [β mul_assoc, mul_invOf_self, one_mul]
example {G} [Group G] (a b : G) : a * (aβ»ΒΉ * b) = b := mul_inv_cancel_left a b
theorem mul_invOf_cancel_left [Monoid Ξ±] (a b : Ξ±) [Invertible a] : a * (β
a * b) = b :=
mul_invOf_cancel_left' a b
@[simp]
theorem invOf_mul_cancel_right' [Monoid Ξ±] (a b : Ξ±) {_ : Invertible b} : a * β
b * b = a := by
simp [mul_assoc]
example {G} [Group G] (a b : G) : a * bβ»ΒΉ * b = a := inv_mul_cancel_right a b
theorem invOf_mul_cancel_right [Monoid Ξ±] (a b : Ξ±) [Invertible b] : a * β
b * b = a :=
invOf_mul_cancel_right' _ _
@[simp]
theorem mul_invOf_cancel_right' [Monoid Ξ±] (a b : Ξ±) {_ : Invertible b} : a * b * β
b = a := by
simp [mul_assoc]
example {G} [Group G] (a b : G) : a * b * bβ»ΒΉ = a := mul_inv_cancel_right a b
| theorem mul_invOf_cancel_right [Monoid Ξ±] (a b : Ξ±) [Invertible b] : a * b * β
b = a :=
mul_invOf_cancel_right' _ _
| Mathlib/Algebra/Group/Invertible/Defs.lean | 136 | 137 |
/-
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, Yury Kudryashov, RΓ©my Degenne
-/
import Mathlib.Data.Set.Subsingleton
import Mathlib.Order.Interval.Set.Defs
/-!
# Intervals
In any preorder, we define intervals (which on each side can be either infinite, open or closed)
using the following naming conventions:
- `i`: infinite
- `o`: open
- `c`: closed
Each interval has the name `I` + letter for left side + letter for right side.
For instance, `Ioc a b` denotes the interval `(a, b]`.
The definitions can be found in `Mathlib.Order.Interval.Set.Defs`.
This file contains basic facts on inclusion of and set operations on intervals
(where the precise statements depend on the order's properties;
statements requiring `LinearOrder` are in `Mathlib.Order.Interval.Set.LinearOrder`).
TODO: This is just the beginning; a lot of rules are missing
-/
assert_not_exists RelIso
open Function
open OrderDual (toDual ofDual)
variable {Ξ± : Type*}
namespace Set
section Preorder
variable [Preorder Ξ±] {a aβ aβ b bβ bβ c x : Ξ±}
instance decidableMemIoo [Decidable (a < x β§ x < b)] : Decidable (x β Ioo a b) := by assumption
instance decidableMemIco [Decidable (a β€ x β§ x < b)] : Decidable (x β Ico a b) := by assumption
instance decidableMemIio [Decidable (x < b)] : Decidable (x β Iio b) := by assumption
instance decidableMemIcc [Decidable (a β€ x β§ x β€ b)] : Decidable (x β Icc a b) := by assumption
instance decidableMemIic [Decidable (x β€ b)] : Decidable (x β Iic b) := by assumption
instance decidableMemIoc [Decidable (a < x β§ x β€ b)] : Decidable (x β Ioc a b) := by assumption
instance decidableMemIci [Decidable (a β€ x)] : Decidable (x β Ici a) := by assumption
instance decidableMemIoi [Decidable (a < x)] : Decidable (x β Ioi a) := by assumption
theorem left_mem_Ioo : a β Ioo a b β False := by simp [lt_irrefl]
theorem left_mem_Ico : a β Ico a b β a < b := by simp [le_refl]
theorem left_mem_Icc : a β Icc a b β a β€ b := by simp [le_refl]
theorem left_mem_Ioc : a β Ioc a b β False := by simp [lt_irrefl]
theorem left_mem_Ici : a β Ici a := by simp
theorem right_mem_Ioo : b β Ioo a b β False := by simp [lt_irrefl]
theorem right_mem_Ico : b β Ico a b β False := by simp [lt_irrefl]
theorem right_mem_Icc : b β Icc a b β a β€ b := by simp [le_refl]
theorem right_mem_Ioc : b β Ioc a b β a < b := by simp [le_refl]
theorem right_mem_Iic : a β Iic a := by simp
@[simp]
theorem Ici_toDual : Ici (toDual a) = ofDual β»ΒΉ' Iic a :=
rfl
@[deprecated (since := "2025-03-20")]
alias dual_Ici := Ici_toDual
@[simp]
theorem Iic_toDual : Iic (toDual a) = ofDual β»ΒΉ' Ici a :=
rfl
@[deprecated (since := "2025-03-20")]
alias dual_Iic := Iic_toDual
@[simp]
theorem Ioi_toDual : Ioi (toDual a) = ofDual β»ΒΉ' Iio a :=
rfl
@[deprecated (since := "2025-03-20")]
alias dual_Ioi := Ioi_toDual
@[simp]
theorem Iio_toDual : Iio (toDual a) = ofDual β»ΒΉ' Ioi a :=
rfl
@[deprecated (since := "2025-03-20")]
alias dual_Iio := Iio_toDual
@[simp]
theorem Icc_toDual : Icc (toDual a) (toDual b) = ofDual β»ΒΉ' Icc b a :=
Set.ext fun _ => and_comm
@[deprecated (since := "2025-03-20")]
alias dual_Icc := Icc_toDual
@[simp]
theorem Ioc_toDual : Ioc (toDual a) (toDual b) = ofDual β»ΒΉ' Ico b a :=
Set.ext fun _ => and_comm
@[deprecated (since := "2025-03-20")]
alias dual_Ioc := Ioc_toDual
@[simp]
theorem Ico_toDual : Ico (toDual a) (toDual b) = ofDual β»ΒΉ' Ioc b a :=
Set.ext fun _ => and_comm
@[deprecated (since := "2025-03-20")]
alias dual_Ico := Ico_toDual
@[simp]
theorem Ioo_toDual : Ioo (toDual a) (toDual b) = ofDual β»ΒΉ' Ioo b a :=
Set.ext fun _ => and_comm
@[deprecated (since := "2025-03-20")]
alias dual_Ioo := Ioo_toDual
@[simp]
theorem Ici_ofDual {x : Ξ±α΅α΅} : Ici (ofDual x) = toDual β»ΒΉ' Iic x :=
rfl
@[simp]
theorem Iic_ofDual {x : Ξ±α΅α΅} : Iic (ofDual x) = toDual β»ΒΉ' Ici x :=
rfl
@[simp]
theorem Ioi_ofDual {x : Ξ±α΅α΅} : Ioi (ofDual x) = toDual β»ΒΉ' Iio x :=
rfl
@[simp]
theorem Iio_ofDual {x : Ξ±α΅α΅} : Iio (ofDual x) = toDual β»ΒΉ' Ioi x :=
rfl
@[simp]
theorem Icc_ofDual {x y : Ξ±α΅α΅} : Icc (ofDual y) (ofDual x) = toDual β»ΒΉ' Icc x y :=
Set.ext fun _ => and_comm
@[simp]
theorem Ico_ofDual {x y : Ξ±α΅α΅} : Ico (ofDual y) (ofDual x) = toDual β»ΒΉ' Ioc x y :=
Set.ext fun _ => and_comm
@[simp]
theorem Ioc_ofDual {x y : Ξ±α΅α΅} : Ioc (ofDual y) (ofDual x) = toDual β»ΒΉ' Ico x y :=
Set.ext fun _ => and_comm
@[simp]
theorem Ioo_ofDual {x y : Ξ±α΅α΅} : Ioo (ofDual y) (ofDual x) = toDual β»ΒΉ' Ioo x y :=
Set.ext fun _ => and_comm
@[simp]
theorem nonempty_Icc : (Icc a b).Nonempty β a β€ b :=
β¨fun β¨_, hxβ© => hx.1.trans hx.2, fun h => β¨a, left_mem_Icc.2 hβ©β©
@[simp]
theorem nonempty_Ico : (Ico a b).Nonempty β a < b :=
β¨fun β¨_, hxβ© => hx.1.trans_lt hx.2, fun h => β¨a, left_mem_Ico.2 hβ©β©
@[simp]
theorem nonempty_Ioc : (Ioc a b).Nonempty β a < b :=
β¨fun β¨_, hxβ© => hx.1.trans_le hx.2, fun h => β¨b, right_mem_Ioc.2 hβ©β©
@[simp]
theorem nonempty_Ici : (Ici a).Nonempty :=
β¨a, left_mem_Iciβ©
@[simp]
theorem nonempty_Iic : (Iic a).Nonempty :=
β¨a, right_mem_Iicβ©
@[simp]
theorem nonempty_Ioo [DenselyOrdered Ξ±] : (Ioo a b).Nonempty β a < b :=
β¨fun β¨_, ha, hbβ© => ha.trans hb, exists_betweenβ©
@[simp]
theorem nonempty_Ioi [NoMaxOrder Ξ±] : (Ioi a).Nonempty :=
exists_gt a
@[simp]
theorem nonempty_Iio [NoMinOrder Ξ±] : (Iio a).Nonempty :=
exists_lt a
theorem nonempty_Icc_subtype (h : a β€ b) : Nonempty (Icc a b) :=
Nonempty.to_subtype (nonempty_Icc.mpr h)
theorem nonempty_Ico_subtype (h : a < b) : Nonempty (Ico a b) :=
Nonempty.to_subtype (nonempty_Ico.mpr h)
theorem nonempty_Ioc_subtype (h : a < b) : Nonempty (Ioc a b) :=
Nonempty.to_subtype (nonempty_Ioc.mpr h)
/-- An interval `Ici a` is nonempty. -/
instance nonempty_Ici_subtype : Nonempty (Ici a) :=
Nonempty.to_subtype nonempty_Ici
/-- An interval `Iic a` is nonempty. -/
instance nonempty_Iic_subtype : Nonempty (Iic a) :=
Nonempty.to_subtype nonempty_Iic
theorem nonempty_Ioo_subtype [DenselyOrdered Ξ±] (h : a < b) : Nonempty (Ioo a b) :=
Nonempty.to_subtype (nonempty_Ioo.mpr h)
/-- In an order without maximal elements, the intervals `Ioi` are nonempty. -/
instance nonempty_Ioi_subtype [NoMaxOrder Ξ±] : Nonempty (Ioi a) :=
Nonempty.to_subtype nonempty_Ioi
/-- In an order without minimal elements, the intervals `Iio` are nonempty. -/
instance nonempty_Iio_subtype [NoMinOrder Ξ±] : Nonempty (Iio a) :=
Nonempty.to_subtype nonempty_Iio
instance [NoMinOrder Ξ±] : NoMinOrder (Iio a) :=
β¨fun a =>
let β¨b, hbβ© := exists_lt (a : Ξ±)
β¨β¨b, lt_trans hb a.2β©, hbβ©β©
instance [NoMinOrder Ξ±] : NoMinOrder (Iic a) :=
β¨fun a =>
let β¨b, hbβ© := exists_lt (a : Ξ±)
β¨β¨b, hb.le.trans a.2β©, hbβ©β©
instance [NoMaxOrder Ξ±] : NoMaxOrder (Ioi a) :=
OrderDual.noMaxOrder (Ξ± := Iio (toDual a))
instance [NoMaxOrder Ξ±] : NoMaxOrder (Ici a) :=
OrderDual.noMaxOrder (Ξ± := Iic (toDual a))
@[simp]
theorem Icc_eq_empty (h : Β¬a β€ b) : Icc a b = β
:=
eq_empty_iff_forall_not_mem.2 fun _ β¨ha, hbβ© => h (ha.trans hb)
@[simp]
theorem Ico_eq_empty (h : Β¬a < b) : Ico a b = β
:=
eq_empty_iff_forall_not_mem.2 fun _ β¨ha, hbβ© => h (ha.trans_lt hb)
@[simp]
theorem Ioc_eq_empty (h : Β¬a < b) : Ioc a b = β
:=
eq_empty_iff_forall_not_mem.2 fun _ β¨ha, hbβ© => h (ha.trans_le hb)
@[simp]
theorem Ioo_eq_empty (h : Β¬a < b) : Ioo a b = β
:=
eq_empty_iff_forall_not_mem.2 fun _ β¨ha, hbβ© => h (ha.trans hb)
@[simp]
theorem Icc_eq_empty_of_lt (h : b < a) : Icc a b = β
:=
Icc_eq_empty h.not_le
@[simp]
theorem Ico_eq_empty_of_le (h : b β€ a) : Ico a b = β
:=
Ico_eq_empty h.not_lt
@[simp]
theorem Ioc_eq_empty_of_le (h : b β€ a) : Ioc a b = β
:=
Ioc_eq_empty h.not_lt
@[simp]
theorem Ioo_eq_empty_of_le (h : b β€ a) : Ioo a b = β
:=
Ioo_eq_empty h.not_lt
theorem Ico_self (a : Ξ±) : Ico a a = β
:=
Ico_eq_empty <| lt_irrefl _
theorem Ioc_self (a : Ξ±) : Ioc a a = β
:=
Ioc_eq_empty <| lt_irrefl _
theorem Ioo_self (a : Ξ±) : Ioo a a = β
:=
Ioo_eq_empty <| lt_irrefl _
@[simp]
theorem Ici_subset_Ici : Ici a β Ici b β b β€ a :=
β¨fun h => h <| left_mem_Ici, fun h _ hx => h.trans hxβ©
@[gcongr] alias β¨_, _root_.GCongr.Ici_subset_Ici_of_leβ© := Ici_subset_Ici
@[simp]
theorem Ici_ssubset_Ici : Ici a β Ici b β b < a where
mp h := by
obtain β¨ab, c, cb, acβ© := ssubset_iff_exists.mp h
exact lt_of_le_not_le (Ici_subset_Ici.mp ab) (fun h' β¦ ac (h'.trans cb))
mpr h := (ssubset_iff_of_subset (Ici_subset_Ici.mpr h.le)).mpr
β¨b, right_mem_Iic, fun h' => h.not_le h'β©
@[gcongr] alias β¨_, _root_.GCongr.Ici_ssubset_Ici_of_leβ© := Ici_ssubset_Ici
@[simp]
theorem Iic_subset_Iic : Iic a β Iic b β a β€ b :=
@Ici_subset_Ici Ξ±α΅α΅ _ _ _
@[gcongr] alias β¨_, _root_.GCongr.Iic_subset_Iic_of_leβ© := Iic_subset_Iic
@[simp]
theorem Iic_ssubset_Iic : Iic a β Iic b β a < b :=
@Ici_ssubset_Ici Ξ±α΅α΅ _ _ _
@[gcongr] alias β¨_, _root_.GCongr.Iic_ssubset_Iic_of_leβ© := Iic_ssubset_Iic
@[simp]
theorem Ici_subset_Ioi : Ici a β Ioi b β b < a :=
β¨fun h => h left_mem_Ici, fun h _ hx => h.trans_le hxβ©
@[simp]
theorem Iic_subset_Iio : Iic a β Iio b β a < b :=
β¨fun h => h right_mem_Iic, fun h _ hx => lt_of_le_of_lt hx hβ©
@[gcongr]
theorem Ioo_subset_Ioo (hβ : aβ β€ aβ) (hβ : bβ β€ bβ) : Ioo aβ bβ β Ioo aβ bβ := fun _ β¨hxβ, hxββ© =>
β¨hβ.trans_lt hxβ, hxβ.trans_le hββ©
@[gcongr]
theorem Ioo_subset_Ioo_left (h : aβ β€ aβ) : Ioo aβ b β Ioo aβ b :=
Ioo_subset_Ioo h le_rfl
@[gcongr]
theorem Ioo_subset_Ioo_right (h : bβ β€ bβ) : Ioo a bβ β Ioo a bβ :=
Ioo_subset_Ioo le_rfl h
@[gcongr]
theorem Ico_subset_Ico (hβ : aβ β€ aβ) (hβ : bβ β€ bβ) : Ico aβ bβ β Ico aβ bβ := fun _ β¨hxβ, hxββ© =>
β¨hβ.trans hxβ, hxβ.trans_le hββ©
@[gcongr]
theorem Ico_subset_Ico_left (h : aβ β€ aβ) : Ico aβ b β Ico aβ b :=
Ico_subset_Ico h le_rfl
@[gcongr]
theorem Ico_subset_Ico_right (h : bβ β€ bβ) : Ico a bβ β Ico a bβ :=
Ico_subset_Ico le_rfl h
@[gcongr]
theorem Icc_subset_Icc (hβ : aβ β€ aβ) (hβ : bβ β€ bβ) : Icc aβ bβ β Icc aβ bβ := fun _ β¨hxβ, hxββ© =>
β¨hβ.trans hxβ, le_trans hxβ hββ©
@[gcongr]
theorem Icc_subset_Icc_left (h : aβ β€ aβ) : Icc aβ b β Icc aβ b :=
Icc_subset_Icc h le_rfl
@[gcongr]
theorem Icc_subset_Icc_right (h : bβ β€ bβ) : Icc a bβ β Icc a bβ :=
Icc_subset_Icc le_rfl h
theorem Icc_subset_Ioo (ha : aβ < aβ) (hb : bβ < bβ) : Icc aβ bβ β Ioo aβ bβ := fun _ hx =>
β¨ha.trans_le hx.1, hx.2.trans_lt hbβ©
theorem Icc_subset_Ici_self : Icc a b β Ici a := fun _ => And.left
theorem Icc_subset_Iic_self : Icc a b β Iic b := fun _ => And.right
theorem Ioc_subset_Iic_self : Ioc a b β Iic b := fun _ => And.right
@[gcongr]
theorem Ioc_subset_Ioc (hβ : aβ β€ aβ) (hβ : bβ β€ bβ) : Ioc aβ bβ β Ioc aβ bβ := fun _ β¨hxβ, hxββ© =>
β¨hβ.trans_lt hxβ, hxβ.trans hββ©
@[gcongr]
theorem Ioc_subset_Ioc_left (h : aβ β€ aβ) : Ioc aβ b β Ioc aβ b :=
Ioc_subset_Ioc h le_rfl
@[gcongr]
theorem Ioc_subset_Ioc_right (h : bβ β€ bβ) : Ioc a bβ β Ioc a bβ :=
Ioc_subset_Ioc le_rfl h
theorem Ico_subset_Ioo_left (hβ : aβ < aβ) : Ico aβ b β Ioo aβ b := fun _ =>
And.imp_left hβ.trans_le
theorem Ioc_subset_Ioo_right (h : bβ < bβ) : Ioc a bβ β Ioo a bβ := fun _ =>
And.imp_right fun h' => h'.trans_lt h
theorem Icc_subset_Ico_right (hβ : bβ < bβ) : Icc a bβ β Ico a bβ := fun _ =>
And.imp_right fun hβ => hβ.trans_lt hβ
theorem Ioo_subset_Ico_self : Ioo a b β Ico a b := fun _ => And.imp_left le_of_lt
theorem Ioo_subset_Ioc_self : Ioo a b β Ioc a b := fun _ => And.imp_right le_of_lt
theorem Ico_subset_Icc_self : Ico a b β Icc a b := fun _ => And.imp_right le_of_lt
theorem Ioc_subset_Icc_self : Ioc a b β Icc a b := fun _ => And.imp_left le_of_lt
theorem Ioo_subset_Icc_self : Ioo a b β Icc a b :=
Subset.trans Ioo_subset_Ico_self Ico_subset_Icc_self
theorem Ico_subset_Iio_self : Ico a b β Iio b := fun _ => And.right
theorem Ioo_subset_Iio_self : Ioo a b β Iio b := fun _ => And.right
theorem Ioc_subset_Ioi_self : Ioc a b β Ioi a := fun _ => And.left
theorem Ioo_subset_Ioi_self : Ioo a b β Ioi a := fun _ => And.left
theorem Ioi_subset_Ici_self : Ioi a β Ici a := fun _ hx => le_of_lt hx
theorem Iio_subset_Iic_self : Iio a β Iic a := fun _ hx => le_of_lt hx
theorem Ico_subset_Ici_self : Ico a b β Ici a := fun _ => And.left
theorem Ioi_ssubset_Ici_self : Ioi a β Ici a :=
β¨Ioi_subset_Ici_self, fun h => lt_irrefl a (h le_rfl)β©
theorem Iio_ssubset_Iic_self : Iio a β Iic a :=
@Ioi_ssubset_Ici_self Ξ±α΅α΅ _ _
theorem Icc_subset_Icc_iff (hβ : aβ β€ bβ) : Icc aβ bβ β Icc aβ bβ β aβ β€ aβ β§ bβ β€ bβ :=
β¨fun h => β¨(h β¨le_rfl, hββ©).1, (h β¨hβ, le_rflβ©).2β©, fun β¨h, h'β© _ β¨hx, hx'β© =>
β¨h.trans hx, hx'.trans h'β©β©
theorem Icc_subset_Ioo_iff (hβ : aβ β€ bβ) : Icc aβ bβ β Ioo aβ bβ β aβ < aβ β§ bβ < bβ :=
β¨fun h => β¨(h β¨le_rfl, hββ©).1, (h β¨hβ, le_rflβ©).2β©, fun β¨h, h'β© _ β¨hx, hx'β© =>
β¨h.trans_le hx, hx'.trans_lt h'β©β©
theorem Icc_subset_Ico_iff (hβ : aβ β€ bβ) : Icc aβ bβ β Ico aβ bβ β aβ β€ aβ β§ bβ < bβ :=
β¨fun h => β¨(h β¨le_rfl, hββ©).1, (h β¨hβ, le_rflβ©).2β©, fun β¨h, h'β© _ β¨hx, hx'β© =>
β¨h.trans hx, hx'.trans_lt h'β©β©
theorem Icc_subset_Ioc_iff (hβ : aβ β€ bβ) : Icc aβ bβ β Ioc aβ bβ β aβ < aβ β§ bβ β€ bβ :=
β¨fun h => β¨(h β¨le_rfl, hββ©).1, (h β¨hβ, le_rflβ©).2β©, fun β¨h, h'β© _ β¨hx, hx'β© =>
β¨h.trans_le hx, hx'.trans h'β©β©
theorem Icc_subset_Iio_iff (hβ : aβ β€ bβ) : Icc aβ bβ β Iio bβ β bβ < bβ :=
β¨fun h => h β¨hβ, le_rflβ©, fun h _ β¨_, hx'β© => hx'.trans_lt hβ©
theorem Icc_subset_Ioi_iff (hβ : aβ β€ bβ) : Icc aβ bβ β Ioi aβ β aβ < aβ :=
β¨fun h => h β¨le_rfl, hββ©, fun h _ β¨hx, _β© => h.trans_le hxβ©
theorem Icc_subset_Iic_iff (hβ : aβ β€ bβ) : Icc aβ bβ β Iic bβ β bβ β€ bβ :=
β¨fun h => h β¨hβ, le_rflβ©, fun h _ β¨_, hx'β© => hx'.trans hβ©
theorem Icc_subset_Ici_iff (hβ : aβ β€ bβ) : Icc aβ bβ β Ici aβ β aβ β€ aβ :=
β¨fun h => h β¨le_rfl, hββ©, fun h _ β¨hx, _β© => h.trans hxβ©
theorem Icc_ssubset_Icc_left (hI : aβ β€ bβ) (ha : aβ < aβ) (hb : bβ β€ bβ) : Icc aβ bβ β Icc aβ bβ :=
(ssubset_iff_of_subset (Icc_subset_Icc (le_of_lt ha) hb)).mpr
β¨aβ, left_mem_Icc.mpr hI, not_and.mpr fun f _ => lt_irrefl aβ (ha.trans_le f)β©
theorem Icc_ssubset_Icc_right (hI : aβ β€ bβ) (ha : aβ β€ aβ) (hb : bβ < bβ) :
Icc aβ bβ β Icc aβ bβ :=
(ssubset_iff_of_subset (Icc_subset_Icc ha (le_of_lt hb))).mpr
β¨bβ, right_mem_Icc.mpr hI, fun f => lt_irrefl bβ (hb.trans_le f.2)β©
/-- If `a β€ b`, then `(b, +β) β (a, +β)`. In preorders, this is just an implication. If you need
the equivalence in linear orders, use `Ioi_subset_Ioi_iff`. -/
@[gcongr]
theorem Ioi_subset_Ioi (h : a β€ b) : Ioi b β Ioi a := fun _ hx => h.trans_lt hx
/-- If `a < b`, then `(b, +β) β (a, +β)`. In preorders, this is just an implication. If you need
the equivalence in linear orders, use `Ioi_ssubset_Ioi_iff`. -/
@[gcongr]
theorem Ioi_ssubset_Ioi (h : a < b) : Ioi b β Ioi a :=
(ssubset_iff_of_subset (Ioi_subset_Ioi h.le)).mpr β¨b, h, lt_irrefl bβ©
/-- If `a β€ b`, then `(b, +β) β [a, +β)`. In preorders, this is just an implication. If you need
the equivalence in dense linear orders, use `Ioi_subset_Ici_iff`. -/
theorem Ioi_subset_Ici (h : a β€ b) : Ioi b β Ici a :=
Subset.trans (Ioi_subset_Ioi h) Ioi_subset_Ici_self
/-- If `a β€ b`, then `(-β, a) β (-β, b)`. In preorders, this is just an implication. If you need
the equivalence in linear orders, use `Iio_subset_Iio_iff`. -/
@[gcongr]
theorem Iio_subset_Iio (h : a β€ b) : Iio a β Iio b := fun _ hx => lt_of_lt_of_le hx h
/-- If `a < b`, then `(-β, a) β (-β, b)`. In preorders, this is just an implication. If you need
the equivalence in linear orders, use `Iio_ssubset_Iio_iff`. -/
@[gcongr]
theorem Iio_ssubset_Iio (h : a < b) : Iio a β Iio b :=
(ssubset_iff_of_subset (Iio_subset_Iio h.le)).mpr β¨a, h, lt_irrefl aβ©
/-- If `a β€ b`, then `(-β, a) β (-β, b]`. In preorders, this is just an implication. If you need
the equivalence in dense linear orders, use `Iio_subset_Iic_iff`. -/
theorem Iio_subset_Iic (h : a β€ b) : Iio a β Iic b :=
Subset.trans (Iio_subset_Iio h) Iio_subset_Iic_self
theorem Ici_inter_Iic : Ici a β© Iic b = Icc a b :=
rfl
theorem Ici_inter_Iio : Ici a β© Iio b = Ico a b :=
rfl
theorem Ioi_inter_Iic : Ioi a β© Iic b = Ioc a b :=
rfl
theorem Ioi_inter_Iio : Ioi a β© Iio b = Ioo a b :=
rfl
theorem Iic_inter_Ici : Iic a β© Ici b = Icc b a :=
inter_comm _ _
theorem Iio_inter_Ici : Iio a β© Ici b = Ico b a :=
inter_comm _ _
theorem Iic_inter_Ioi : Iic a β© Ioi b = Ioc b a :=
inter_comm _ _
theorem Iio_inter_Ioi : Iio a β© Ioi b = Ioo b a :=
inter_comm _ _
theorem mem_Icc_of_Ioo (h : x β Ioo a b) : x β Icc a b :=
Ioo_subset_Icc_self h
theorem mem_Ico_of_Ioo (h : x β Ioo a b) : x β Ico a b :=
Ioo_subset_Ico_self h
theorem mem_Ioc_of_Ioo (h : x β Ioo a b) : x β Ioc a b :=
Ioo_subset_Ioc_self h
theorem mem_Icc_of_Ico (h : x β Ico a b) : x β Icc a b :=
Ico_subset_Icc_self h
theorem mem_Icc_of_Ioc (h : x β Ioc a b) : x β Icc a b :=
Ioc_subset_Icc_self h
theorem mem_Ici_of_Ioi (h : x β Ioi a) : x β Ici a :=
Ioi_subset_Ici_self h
theorem mem_Iic_of_Iio (h : x β Iio a) : x β Iic a :=
Iio_subset_Iic_self h
theorem Icc_eq_empty_iff : Icc a b = β
β Β¬a β€ b := by
rw [β not_nonempty_iff_eq_empty, not_iff_not, nonempty_Icc]
theorem Ico_eq_empty_iff : Ico a b = β
β Β¬a < b := by
rw [β not_nonempty_iff_eq_empty, not_iff_not, nonempty_Ico]
theorem Ioc_eq_empty_iff : Ioc a b = β
β Β¬a < b := by
rw [β not_nonempty_iff_eq_empty, not_iff_not, nonempty_Ioc]
theorem Ioo_eq_empty_iff [DenselyOrdered Ξ±] : Ioo a b = β
β Β¬a < b := by
rw [β not_nonempty_iff_eq_empty, not_iff_not, nonempty_Ioo]
theorem _root_.IsTop.Iic_eq (h : IsTop a) : Iic a = univ :=
eq_univ_of_forall h
theorem _root_.IsBot.Ici_eq (h : IsBot a) : Ici a = univ :=
eq_univ_of_forall h
@[simp] theorem Ioi_eq_empty_iff : Ioi a = β
β IsMax a := by
simp only [isMax_iff_forall_not_lt, eq_empty_iff_forall_not_mem, mem_Ioi]
@[simp] theorem Iio_eq_empty_iff : Iio a = β
β IsMin a := Ioi_eq_empty_iff (Ξ± := Ξ±α΅α΅)
@[simp] alias β¨_, _root_.IsMax.Ioi_eqβ© := Ioi_eq_empty_iff
@[simp] alias β¨_, _root_.IsMin.Iio_eqβ© := Iio_eq_empty_iff
@[simp] lemma Iio_nonempty : (Iio a).Nonempty β Β¬ IsMin a := by simp [nonempty_iff_ne_empty]
@[simp] lemma Ioi_nonempty : (Ioi a).Nonempty β Β¬ IsMax a := by simp [nonempty_iff_ne_empty]
theorem Iic_inter_Ioc_of_le (h : a β€ c) : Iic a β© Ioc b c = Ioc b a :=
ext fun _ => β¨fun H => β¨H.2.1, H.1β©, fun H => β¨H.2, H.1, H.2.trans hβ©β©
theorem not_mem_Icc_of_lt (ha : c < a) : c β Icc a b := fun h => ha.not_le h.1
theorem not_mem_Icc_of_gt (hb : b < c) : c β Icc a b := fun h => hb.not_le h.2
theorem not_mem_Ico_of_lt (ha : c < a) : c β Ico a b := fun h => ha.not_le h.1
theorem not_mem_Ioc_of_gt (hb : b < c) : c β Ioc a b := fun h => hb.not_le h.2
theorem not_mem_Ioi_self : a β Ioi a := lt_irrefl _
theorem not_mem_Iio_self : b β Iio b := lt_irrefl _
theorem not_mem_Ioc_of_le (ha : c β€ a) : c β Ioc a b := fun h => lt_irrefl _ <| h.1.trans_le ha
theorem not_mem_Ico_of_ge (hb : b β€ c) : c β Ico a b := fun h => lt_irrefl _ <| h.2.trans_le hb
theorem not_mem_Ioo_of_le (ha : c β€ a) : c β Ioo a b := fun h => lt_irrefl _ <| h.1.trans_le ha
theorem not_mem_Ioo_of_ge (hb : b β€ c) : c β Ioo a b := fun h => lt_irrefl _ <| h.2.trans_le hb
section matched_intervals
@[simp] theorem Icc_eq_Ioc_same_iff : Icc a b = Ioc a b β Β¬a β€ b where
mp h := by simpa using Set.ext_iff.mp h a
mpr h := by rw [Icc_eq_empty h, Ioc_eq_empty (mt le_of_lt h)]
@[simp] theorem Icc_eq_Ico_same_iff : Icc a b = Ico a b β Β¬a β€ b where
mp h := by simpa using Set.ext_iff.mp h b
mpr h := by rw [Icc_eq_empty h, Ico_eq_empty (mt le_of_lt h)]
@[simp] theorem Icc_eq_Ioo_same_iff : Icc a b = Ioo a b β Β¬a β€ b where
mp h := by simpa using Set.ext_iff.mp h b
mpr h := by rw [Icc_eq_empty h, Ioo_eq_empty (mt le_of_lt h)]
@[simp] theorem Ioc_eq_Ico_same_iff : Ioc a b = Ico a b β Β¬a < b where
mp h := by simpa using Set.ext_iff.mp h a
mpr h := by rw [Ioc_eq_empty h, Ico_eq_empty h]
@[simp] theorem Ioo_eq_Ioc_same_iff : Ioo a b = Ioc a b β Β¬a < b where
mp h := by simpa using Set.ext_iff.mp h b
mpr h := by rw [Ioo_eq_empty h, Ioc_eq_empty h]
@[simp] theorem Ioo_eq_Ico_same_iff : Ioo a b = Ico a b β Β¬a < b where
mp h := by simpa using Set.ext_iff.mp h a
mpr h := by rw [Ioo_eq_empty h, Ico_eq_empty h]
-- Mirrored versions of the above for `simp`.
@[simp] theorem Ioc_eq_Icc_same_iff : Ioc a b = Icc a b β Β¬a β€ b :=
eq_comm.trans Icc_eq_Ioc_same_iff
@[simp] theorem Ico_eq_Icc_same_iff : Ico a b = Icc a b β Β¬a β€ b :=
eq_comm.trans Icc_eq_Ico_same_iff
@[simp] theorem Ioo_eq_Icc_same_iff : Ioo a b = Icc a b β Β¬a β€ b :=
eq_comm.trans Icc_eq_Ioo_same_iff
@[simp] theorem Ico_eq_Ioc_same_iff : Ico a b = Ioc a b β Β¬a < b :=
eq_comm.trans Ioc_eq_Ico_same_iff
@[simp] theorem Ioc_eq_Ioo_same_iff : Ioc a b = Ioo a b β Β¬a < b :=
eq_comm.trans Ioo_eq_Ioc_same_iff
@[simp] theorem Ico_eq_Ioo_same_iff : Ico a b = Ioo a b β Β¬a < b :=
eq_comm.trans Ioo_eq_Ico_same_iff
end matched_intervals
end Preorder
section PartialOrder
variable [PartialOrder Ξ±] {a b c : Ξ±}
@[simp]
theorem Icc_self (a : Ξ±) : Icc a a = {a} :=
Set.ext <| by simp [Icc, le_antisymm_iff, and_comm]
instance instIccUnique : Unique (Set.Icc a a) where
default := β¨a, by simpβ©
uniq y := Subtype.ext <| by simpa using y.2
@[simp]
theorem Icc_eq_singleton_iff : Icc a b = {c} β a = c β§ b = c := by
refine β¨fun h => ?_, ?_β©
Β· have hab : a β€ b := nonempty_Icc.1 (h.symm.subst <| singleton_nonempty c)
exact
β¨eq_of_mem_singleton <| h βΈ left_mem_Icc.2 hab,
eq_of_mem_singleton <| h βΈ right_mem_Icc.2 habβ©
Β· rintro β¨rfl, rflβ©
exact Icc_self _
lemma subsingleton_Icc_of_ge (hba : b β€ a) : Set.Subsingleton (Icc a b) :=
fun _x β¨hax, hxbβ© _y β¨hay, hybβ© β¦ le_antisymm
(le_implies_le_of_le_of_le hxb hay hba) (le_implies_le_of_le_of_le hyb hax hba)
@[simp] lemma subsingleton_Icc_iff {Ξ± : Type*} [LinearOrder Ξ±] {a b : Ξ±} :
Set.Subsingleton (Icc a b) β b β€ a := by
refine β¨fun h β¦ ?_, subsingleton_Icc_of_geβ©
contrapose! h
simp only [gt_iff_lt, not_subsingleton_iff]
exact β¨a, β¨le_refl _, h.leβ©, b, β¨h.le, le_refl _β©, h.neβ©
@[simp]
theorem Icc_diff_left : Icc a b \ {a} = Ioc a b :=
ext fun x => by simp [lt_iff_le_and_ne, eq_comm, and_right_comm]
@[simp]
theorem Icc_diff_right : Icc a b \ {b} = Ico a b :=
ext fun x => by simp [lt_iff_le_and_ne, and_assoc]
@[simp]
theorem Ico_diff_left : Ico a b \ {a} = Ioo a b :=
ext fun x => by simp [and_right_comm, β lt_iff_le_and_ne, eq_comm]
@[simp]
theorem Ioc_diff_right : Ioc a b \ {b} = Ioo a b :=
ext fun x => by simp [and_assoc, β lt_iff_le_and_ne]
@[simp]
theorem Icc_diff_both : Icc a b \ {a, b} = Ioo a b := by
rw [insert_eq, β diff_diff, Icc_diff_left, Ioc_diff_right]
@[simp]
theorem Ici_diff_left : Ici a \ {a} = Ioi a :=
ext fun x => by simp [lt_iff_le_and_ne, eq_comm]
@[simp]
theorem Iic_diff_right : Iic a \ {a} = Iio a :=
ext fun x => by simp [lt_iff_le_and_ne]
@[simp]
theorem Ico_diff_Ioo_same (h : a < b) : Ico a b \ Ioo a b = {a} := by
rw [β Ico_diff_left, diff_diff_cancel_left (singleton_subset_iff.2 <| left_mem_Ico.2 h)]
@[simp]
theorem Ioc_diff_Ioo_same (h : a < b) : Ioc a b \ Ioo a b = {b} := by
rw [β Ioc_diff_right, diff_diff_cancel_left (singleton_subset_iff.2 <| right_mem_Ioc.2 h)]
@[simp]
theorem Icc_diff_Ico_same (h : a β€ b) : Icc a b \ Ico a b = {b} := by
rw [β Icc_diff_right, diff_diff_cancel_left (singleton_subset_iff.2 <| right_mem_Icc.2 h)]
@[simp]
theorem Icc_diff_Ioc_same (h : a β€ b) : Icc a b \ Ioc a b = {a} := by
rw [β Icc_diff_left, diff_diff_cancel_left (singleton_subset_iff.2 <| left_mem_Icc.2 h)]
@[simp]
theorem Icc_diff_Ioo_same (h : a β€ b) : Icc a b \ Ioo a b = {a, b} := by
rw [β Icc_diff_both, diff_diff_cancel_left]
simp [insert_subset_iff, h]
@[simp]
theorem Ici_diff_Ioi_same : Ici a \ Ioi a = {a} := by
rw [β Ici_diff_left, diff_diff_cancel_left (singleton_subset_iff.2 left_mem_Ici)]
@[simp]
theorem Iic_diff_Iio_same : Iic a \ Iio a = {a} := by
rw [β Iic_diff_right, diff_diff_cancel_left (singleton_subset_iff.2 right_mem_Iic)]
theorem Ioi_union_left : Ioi a βͺ {a} = Ici a :=
ext fun x => by simp [eq_comm, le_iff_eq_or_lt]
theorem Iio_union_right : Iio a βͺ {a} = Iic a :=
ext fun _ => le_iff_lt_or_eq.symm
theorem Ioo_union_left (hab : a < b) : Ioo a b βͺ {a} = Ico a b := by
rw [β Ico_diff_left, diff_union_self,
union_eq_self_of_subset_right (singleton_subset_iff.2 <| left_mem_Ico.2 hab)]
theorem Ioo_union_right (hab : a < b) : Ioo a b βͺ {b} = Ioc a b := by
simpa only [Ioo_toDual, Ico_toDual] using Ioo_union_left hab.dual
theorem Ioo_union_both (h : a β€ b) : Ioo a b βͺ {a, b} = Icc a b := by
have : (Icc a b \ {a, b}) βͺ {a, b} = Icc a b := diff_union_of_subset fun
| x, .inl rfl => left_mem_Icc.mpr h
| x, .inr rfl => right_mem_Icc.mpr h
rw [β this, Icc_diff_both]
theorem Ioc_union_left (hab : a β€ b) : Ioc a b βͺ {a} = Icc a b := by
rw [β Icc_diff_left, diff_union_self,
union_eq_self_of_subset_right (singleton_subset_iff.2 <| left_mem_Icc.2 hab)]
theorem Ico_union_right (hab : a β€ b) : Ico a b βͺ {b} = Icc a b := by
simpa only [Ioc_toDual, Icc_toDual] using Ioc_union_left hab.dual
@[simp]
theorem Ico_insert_right (h : a β€ b) : insert b (Ico a b) = Icc a b := by
rw [insert_eq, union_comm, Ico_union_right h]
@[simp]
theorem Ioc_insert_left (h : a β€ b) : insert a (Ioc a b) = Icc a b := by
rw [insert_eq, union_comm, Ioc_union_left h]
@[simp]
theorem Ioo_insert_left (h : a < b) : insert a (Ioo a b) = Ico a b := by
rw [insert_eq, union_comm, Ioo_union_left h]
@[simp]
theorem Ioo_insert_right (h : a < b) : insert b (Ioo a b) = Ioc a b := by
rw [insert_eq, union_comm, Ioo_union_right h]
@[simp]
theorem Iio_insert : insert a (Iio a) = Iic a :=
ext fun _ => le_iff_eq_or_lt.symm
@[simp]
theorem Ioi_insert : insert a (Ioi a) = Ici a :=
ext fun _ => (or_congr_left eq_comm).trans le_iff_eq_or_lt.symm
theorem mem_Ici_Ioi_of_subset_of_subset {s : Set Ξ±} (ho : Ioi a β s) (hc : s β Ici a) :
s β ({Ici a, Ioi a} : Set (Set Ξ±)) :=
by_cases
(fun h : a β s =>
Or.inl <| Subset.antisymm hc <| by rw [β Ioi_union_left, union_subset_iff]; simp [*])
fun h =>
Or.inr <| Subset.antisymm (fun _ hx => lt_of_le_of_ne (hc hx) fun heq => h <| heq.symm βΈ hx) ho
theorem mem_Iic_Iio_of_subset_of_subset {s : Set Ξ±} (ho : Iio a β s) (hc : s β Iic a) :
s β ({Iic a, Iio a} : Set (Set Ξ±)) :=
@mem_Ici_Ioi_of_subset_of_subset Ξ±α΅α΅ _ a s ho hc
theorem mem_Icc_Ico_Ioc_Ioo_of_subset_of_subset {s : Set Ξ±} (ho : Ioo a b β s) (hc : s β Icc a b) :
s β ({Icc a b, Ico a b, Ioc a b, Ioo a b} : Set (Set Ξ±)) := by
classical
by_cases ha : a β s <;> by_cases hb : b β s
Β· refine Or.inl (Subset.antisymm hc ?_)
rwa [β Ico_diff_left, diff_singleton_subset_iff, insert_eq_of_mem ha, β Icc_diff_right,
diff_singleton_subset_iff, insert_eq_of_mem hb] at ho
Β· refine Or.inr <| Or.inl <| Subset.antisymm ?_ ?_
Β· rw [β Icc_diff_right]
exact subset_diff_singleton hc hb
Β· rwa [β Ico_diff_left, diff_singleton_subset_iff, insert_eq_of_mem ha] at ho
Β· refine Or.inr <| Or.inr <| Or.inl <| Subset.antisymm ?_ ?_
Β· rw [β Icc_diff_left]
exact subset_diff_singleton hc ha
Β· rwa [β Ioc_diff_right, diff_singleton_subset_iff, insert_eq_of_mem hb] at ho
Β· refine Or.inr <| Or.inr <| Or.inr <| Subset.antisymm ?_ ho
rw [β Ico_diff_left, β Icc_diff_right]
apply_rules [subset_diff_singleton]
theorem eq_left_or_mem_Ioo_of_mem_Ico {x : Ξ±} (hmem : x β Ico a b) : x = a β¨ x β Ioo a b :=
hmem.1.eq_or_gt.imp_right fun h => β¨h, hmem.2β©
theorem eq_right_or_mem_Ioo_of_mem_Ioc {x : Ξ±} (hmem : x β Ioc a b) : x = b β¨ x β Ioo a b :=
hmem.2.eq_or_lt.imp_right <| And.intro hmem.1
theorem eq_endpoints_or_mem_Ioo_of_mem_Icc {x : Ξ±} (hmem : x β Icc a b) :
x = a β¨ x = b β¨ x β Ioo a b :=
hmem.1.eq_or_gt.imp_right fun h => eq_right_or_mem_Ioo_of_mem_Ioc β¨h, hmem.2β©
theorem _root_.IsMax.Ici_eq (h : IsMax a) : Ici a = {a} :=
eq_singleton_iff_unique_mem.2 β¨left_mem_Ici, fun _ => h.eq_of_geβ©
theorem _root_.IsMin.Iic_eq (h : IsMin a) : Iic a = {a} :=
h.toDual.Ici_eq
theorem Ici_injective : Injective (Ici : Ξ± β Set Ξ±) := fun _ _ =>
eq_of_forall_ge_iff β Set.ext_iff.1
theorem Iic_injective : Injective (Iic : Ξ± β Set Ξ±) := fun _ _ =>
eq_of_forall_le_iff β Set.ext_iff.1
theorem Ici_inj : Ici a = Ici b β a = b :=
Ici_injective.eq_iff
theorem Iic_inj : Iic a = Iic b β a = b :=
Iic_injective.eq_iff
@[simp]
theorem Icc_inter_Icc_eq_singleton (hab : a β€ b) (hbc : b β€ c) : Icc a b β© Icc b c = {b} := by
rw [β Ici_inter_Iic, β Iic_inter_Ici, inter_inter_inter_comm, Iic_inter_Ici]
simp [hab, hbc]
lemma Icc_eq_Icc_iff {d : Ξ±} (h : a β€ b) :
Icc a b = Icc c d β a = c β§ b = d := by
refine β¨fun heq β¦ ?_, by rintro β¨rfl, rflβ©; rflβ©
have h' : c β€ d := by
by_contra contra; rw [Icc_eq_empty_iff.mpr contra, Icc_eq_empty_iff] at heq; contradiction
simp only [Set.ext_iff, mem_Icc] at heq
obtain β¨-, hββ© := (heq b).mp β¨h, le_refl _β©
obtain β¨hβ, -β© := (heq a).mp β¨le_refl _, hβ©
obtain β¨hβ, -β© := (heq c).mpr β¨le_refl _, h'β©
obtain β¨-, hββ© := (heq d).mpr β¨h', le_refl _β©
exact β¨le_antisymm hβ hβ, le_antisymm hβ hββ©
end PartialOrder
section OrderTop
@[simp]
theorem Ici_top [PartialOrder Ξ±] [OrderTop Ξ±] : Ici (β€ : Ξ±) = {β€} :=
isMax_top.Ici_eq
variable [Preorder Ξ±] [OrderTop Ξ±] {a : Ξ±}
theorem Ioi_top : Ioi (β€ : Ξ±) = β
:=
isMax_top.Ioi_eq
@[simp]
theorem Iic_top : Iic (β€ : Ξ±) = univ :=
isTop_top.Iic_eq
@[simp]
theorem Icc_top : Icc a β€ = Ici a := by simp [β Ici_inter_Iic]
@[simp]
theorem Ioc_top : Ioc a β€ = Ioi a := by simp [β Ioi_inter_Iic]
end OrderTop
section OrderBot
@[simp]
theorem Iic_bot [PartialOrder Ξ±] [OrderBot Ξ±] : Iic (β₯ : Ξ±) = {β₯} :=
isMin_bot.Iic_eq
variable [Preorder Ξ±] [OrderBot Ξ±] {a : Ξ±}
theorem Iio_bot : Iio (β₯ : Ξ±) = β
:=
isMin_bot.Iio_eq
@[simp]
theorem Ici_bot : Ici (β₯ : Ξ±) = univ :=
isBot_bot.Ici_eq
@[simp]
theorem Icc_bot : Icc β₯ a = Iic a := by simp [β Ici_inter_Iic]
@[simp]
theorem Ico_bot : Ico β₯ a = Iio a := by simp [β Ici_inter_Iio]
end OrderBot
theorem Icc_bot_top [Preorder Ξ±] [BoundedOrder Ξ±] : Icc (β₯ : Ξ±) β€ = univ := by simp
section Lattice
section Inf
variable [SemilatticeInf Ξ±]
@[simp]
theorem Iic_inter_Iic {a b : Ξ±} : Iic a β© Iic b = Iic (a β b) := by
ext x
simp [Iic]
@[simp]
theorem Ioc_inter_Iic (a b c : Ξ±) : Ioc a b β© Iic c = Ioc a (b β c) := by
rw [β Ioi_inter_Iic, β Ioi_inter_Iic, inter_assoc, Iic_inter_Iic]
end Inf
section Sup
variable [SemilatticeSup Ξ±]
@[simp]
theorem Ici_inter_Ici {a b : Ξ±} : Ici a β© Ici b = Ici (a β b) := by
ext x
simp [Ici]
@[simp]
theorem Ico_inter_Ici (a b c : Ξ±) : Ico a b β© Ici c = Ico (a β c) b := by
rw [β Ici_inter_Iio, β Ici_inter_Iio, β Ici_inter_Ici, inter_right_comm]
end Sup
section Both
variable [Lattice Ξ±] {a b c aβ aβ bβ bβ : Ξ±}
theorem Icc_inter_Icc : Icc aβ bβ β© Icc aβ bβ = Icc (aβ β aβ) (bβ β bβ) := by
simp only [Ici_inter_Iic.symm, Ici_inter_Ici.symm, Iic_inter_Iic.symm]; ac_rfl
end Both
end Lattice
/-! ### Closed intervals in `Ξ± Γ Ξ²` -/
section Prod
variable {Ξ² : Type*} [Preorder Ξ±] [Preorder Ξ²]
@[simp]
theorem Iic_prod_Iic (a : Ξ±) (b : Ξ²) : Iic a ΓΛ’ Iic b = Iic (a, b) :=
rfl
@[simp]
theorem Ici_prod_Ici (a : Ξ±) (b : Ξ²) : Ici a ΓΛ’ Ici b = Ici (a, b) :=
rfl
theorem Ici_prod_eq (a : Ξ± Γ Ξ²) : Ici a = Ici a.1 ΓΛ’ Ici a.2 :=
rfl
theorem Iic_prod_eq (a : Ξ± Γ Ξ²) : Iic a = Iic a.1 ΓΛ’ Iic a.2 :=
rfl
@[simp]
theorem Icc_prod_Icc (aβ aβ : Ξ±) (bβ bβ : Ξ²) : Icc aβ aβ ΓΛ’ Icc bβ bβ = Icc (aβ, bβ) (aβ, bβ) := by
ext β¨x, yβ©
simp [and_assoc, and_comm, and_left_comm]
theorem Icc_prod_eq (a b : Ξ± Γ Ξ²) : Icc a b = Icc a.1 b.1 ΓΛ’ Icc a.2 b.2 := by simp
end Prod
end Set
/-! ### Lemmas about intervals in dense orders -/
section Dense
variable (Ξ±) [Preorder Ξ±] [DenselyOrdered Ξ±] {x y : Ξ±}
instance : NoMinOrder (Set.Ioo x y) :=
β¨fun β¨a, haβ, haββ© => by
rcases exists_between haβ with β¨b, hbβ, hbββ©
exact β¨β¨b, hbβ, hbβ.trans haββ©, hbββ©β©
instance : NoMinOrder (Set.Ioc x y) :=
β¨fun β¨a, haβ, haββ© => by
rcases exists_between haβ with β¨b, hbβ, hbββ©
exact β¨β¨b, hbβ, hbβ.le.trans haββ©, hbββ©β©
instance : NoMinOrder (Set.Ioi x) :=
β¨fun β¨a, haβ© => by
rcases exists_between ha with β¨b, hbβ, hbββ©
exact β¨β¨b, hbββ©, hbββ©β©
instance : NoMaxOrder (Set.Ioo x y) :=
β¨fun β¨a, haβ, haββ© => by
rcases exists_between haβ with β¨b, hbβ, hbββ©
exact β¨β¨b, haβ.trans hbβ, hbββ©, hbββ©β©
instance : NoMaxOrder (Set.Ico x y) :=
β¨fun β¨a, haβ, haββ© => by
rcases exists_between haβ with β¨b, hbβ, hbββ©
exact β¨β¨b, haβ.trans hbβ.le, hbββ©, hbββ©β©
instance : NoMaxOrder (Set.Iio x) :=
β¨fun β¨a, haβ© => by
rcases exists_between ha with β¨b, hbβ, hbββ©
exact β¨β¨b, hbββ©, hbββ©β©
end Dense
/-! ### Intervals in `Prop` -/
namespace Set
@[simp] lemma Iic_False : Iic False = {False} := by aesop
@[simp] lemma Iic_True : Iic True = univ := by aesop
@[simp] lemma Ici_False : Ici False = univ := by aesop
@[simp] lemma Ici_True : Ici True = {True} := by aesop
lemma Iio_False : Iio False = β
:= by aesop
@[simp] lemma Iio_True : Iio True = {False} := by aesop (add simp [Ioi, lt_iff_le_not_le])
@[simp] lemma Ioi_False : Ioi False = {True} := by aesop (add simp [Ioi, lt_iff_le_not_le])
lemma Ioi_True : Ioi True = β
:= by aesop
end Set
| Mathlib/Order/Interval/Set/Basic.lean | 1,842 | 1,843 | |
/-
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.Probability.IdentDistrib
import Mathlib.Probability.Independence.Integrable
import Mathlib.MeasureTheory.Integral.DominatedConvergence
import Mathlib.Analysis.SpecificLimits.FloorPow
import Mathlib.Analysis.PSeries
import Mathlib.Analysis.Asymptotics.SpecificAsymptotics
/-!
# The strong law of large numbers
We prove the strong law of large numbers, in `ProbabilityTheory.strong_law_ae`:
If `X n` is a sequence of independent identically distributed integrable random
variables, then `β i β range n, X i / n` converges almost surely to `πΌ[X 0]`.
We give here the strong version, due to Etemadi, that only requires pairwise independence.
This file also contains the Lα΅ version of the strong law of large numbers provided by
`ProbabilityTheory.strong_law_Lp` which shows `β i β range n, X i / n` converges in Lα΅ to
`πΌ[X 0]` provided `X n` is independent identically distributed and is Lα΅.
## Implementation
The main point is to prove the result for real-valued random variables, as the general case
of Banach-space valued random variables follows from this case and approximation by simple
functions. The real version is given in `ProbabilityTheory.strong_law_ae_real`.
We follow the proof by Etemadi
[Etemadi, *An elementary proof of the strong law of large numbers*][etemadi_strong_law],
which goes as follows.
It suffices to prove the result for nonnegative `X`, as one can prove the general result by
splitting a general `X` into its positive part and negative part.
Consider `Xβ` a sequence of nonnegative integrable identically distributed pairwise independent
random variables. Let `Yβ` be the truncation of `Xβ` up to `n`. We claim that
* Almost surely, `Xβ = Yβ` for all but finitely many indices. Indeed, `β β (Xβ β Yβ)` is bounded by
`1 + πΌ[X]` (see `sum_prob_mem_Ioc_le` and `tsum_prob_mem_Ioi_lt_top`).
* Let `c > 1`. Along the sequence `n = c ^ k`, then `(β_{i=0}^{n-1} Yα΅’ - πΌ[Yα΅’])/n` converges almost
surely to `0`. This follows from a variance control, as
```
β_k β (|β_{i=0}^{c^k - 1} Yα΅’ - πΌ[Yα΅’]| > c^k Ξ΅)
β€ β_k (c^k Ξ΅)^{-2} β_{i=0}^{c^k - 1} Var[Yα΅’] (by Markov inequality)
β€ β_i (C/i^2) Var[Yα΅’] (as β_{c^k > i} 1/(c^k)^2 β€ C/i^2)
β€ β_i (C/i^2) πΌ[Yα΅’^2]
β€ 2C πΌ[X^2] (see `sum_variance_truncation_le`)
```
* As `πΌ[Yα΅’]` converges to `πΌ[X]`, it follows from the two previous items and CesΓ ro that, along
the sequence `n = c^k`, one has `(β_{i=0}^{n-1} Xα΅’) / n β πΌ[X]` almost surely.
* To generalize it to all indices, we use the fact that `β_{i=0}^{n-1} Xα΅’` is nondecreasing and
that, if `c` is close enough to `1`, the gap between `c^k` and `c^(k+1)` is small.
-/
noncomputable section
open MeasureTheory Filter Finset Asymptotics
open Set (indicator)
open scoped Topology MeasureTheory ProbabilityTheory ENNReal NNReal
open scoped Function -- required for scoped `on` notation
namespace ProbabilityTheory
/-! ### Prerequisites on truncations -/
section Truncation
variable {Ξ± : Type*}
/-- Truncating a real-valued function to the interval `(-A, A]`. -/
def truncation (f : Ξ± β β) (A : β) :=
indicator (Set.Ioc (-A) A) id β f
variable {m : MeasurableSpace Ξ±} {ΞΌ : Measure Ξ±} {f : Ξ± β β}
theorem _root_.MeasureTheory.AEStronglyMeasurable.truncation (hf : AEStronglyMeasurable f ΞΌ)
{A : β} : AEStronglyMeasurable (truncation f A) ΞΌ := by
apply AEStronglyMeasurable.comp_aemeasurable _ hf.aemeasurable
exact (stronglyMeasurable_id.indicator measurableSet_Ioc).aestronglyMeasurable
theorem abs_truncation_le_bound (f : Ξ± β β) (A : β) (x : Ξ±) : |truncation f A x| β€ |A| := by
simp only [truncation, Set.indicator, Set.mem_Icc, id, Function.comp_apply]
split_ifs with h
Β· exact abs_le_abs h.2 (neg_le.2 h.1.le)
Β· simp [abs_nonneg]
@[simp]
theorem truncation_zero (f : Ξ± β β) : truncation f 0 = 0 := by simp [truncation]; rfl
theorem abs_truncation_le_abs_self (f : Ξ± β β) (A : β) (x : Ξ±) : |truncation f A x| β€ |f x| := by
simp only [truncation, indicator, Set.mem_Icc, id, Function.comp_apply]
split_ifs
Β· exact le_rfl
Β· simp [abs_nonneg]
theorem truncation_eq_self {f : Ξ± β β} {A : β} {x : Ξ±} (h : |f x| < A) :
truncation f A x = f x := by
simp only [truncation, indicator, Set.mem_Icc, id, Function.comp_apply, ite_eq_left_iff]
intro H
apply H.elim
simp [(abs_lt.1 h).1, (abs_lt.1 h).2.le]
theorem truncation_eq_of_nonneg {f : Ξ± β β} {A : β} (h : β x, 0 β€ f x) :
truncation f A = indicator (Set.Ioc 0 A) id β f := by
ext x
rcases (h x).lt_or_eq with (hx | hx)
Β· simp only [truncation, indicator, hx, Set.mem_Ioc, id, Function.comp_apply]
by_cases h'x : f x β€ A
Β· have : -A < f x := by linarith [h x]
simp only [this, true_and]
Β· simp only [h'x, and_false]
Β· simp only [truncation, indicator, hx, id, Function.comp_apply, ite_self]
theorem truncation_nonneg {f : Ξ± β β} (A : β) {x : Ξ±} (h : 0 β€ f x) : 0 β€ truncation f A x :=
Set.indicator_apply_nonneg fun _ => h
theorem _root_.MeasureTheory.AEStronglyMeasurable.memLp_truncation [IsFiniteMeasure ΞΌ]
(hf : AEStronglyMeasurable f ΞΌ) {A : β} {p : ββ₯0β} : MemLp (truncation f A) p ΞΌ :=
MemLp.of_bound hf.truncation |A| (Eventually.of_forall fun _ => abs_truncation_le_bound _ _ _)
theorem _root_.MeasureTheory.AEStronglyMeasurable.integrable_truncation [IsFiniteMeasure ΞΌ]
(hf : AEStronglyMeasurable f ΞΌ) {A : β} : Integrable (truncation f A) ΞΌ := by
rw [β memLp_one_iff_integrable]; exact hf.memLp_truncation
theorem moment_truncation_eq_intervalIntegral (hf : AEStronglyMeasurable f ΞΌ) {A : β} (hA : 0 β€ A)
{n : β} (hn : n β 0) : β« x, truncation f A x ^ n βΞΌ = β« y in -A..A, y ^ n βMeasure.map f ΞΌ := by
have M : MeasurableSet (Set.Ioc (-A) A) := measurableSet_Ioc
change β« x, (fun z => indicator (Set.Ioc (-A) A) id z ^ n) (f x) βΞΌ = _
rw [β integral_map (f := fun z => _ ^ n) hf.aemeasurable, intervalIntegral.integral_of_le,
β integral_indicator M]
Β· simp only [indicator, zero_pow hn, id, ite_pow]
Β· linarith
Β· exact ((measurable_id.indicator M).pow_const n).aestronglyMeasurable
theorem moment_truncation_eq_intervalIntegral_of_nonneg (hf : AEStronglyMeasurable f ΞΌ) {A : β}
{n : β} (hn : n β 0) (h'f : 0 β€ f) :
β« x, truncation f A x ^ n βΞΌ = β« y in (0)..A, y ^ n βMeasure.map f ΞΌ := by
have M : MeasurableSet (Set.Ioc 0 A) := measurableSet_Ioc
have M' : MeasurableSet (Set.Ioc A 0) := measurableSet_Ioc
rw [truncation_eq_of_nonneg h'f]
change β« x, (fun z => indicator (Set.Ioc 0 A) id z ^ n) (f x) βΞΌ = _
rcases le_or_lt 0 A with (hA | hA)
Β· rw [β integral_map (f := fun z => _ ^ n) hf.aemeasurable, intervalIntegral.integral_of_le hA,
β integral_indicator M]
Β· simp only [indicator, zero_pow hn, id, ite_pow]
Β· exact ((measurable_id.indicator M).pow_const n).aestronglyMeasurable
Β· rw [β integral_map (f := fun z => _ ^ n) hf.aemeasurable, intervalIntegral.integral_of_ge hA.le,
β integral_indicator M']
Β· simp only [Set.Ioc_eq_empty_of_le hA.le, zero_pow hn, Set.indicator_empty, integral_zero,
zero_eq_neg]
apply integral_eq_zero_of_ae
have : βα΅ x βMeasure.map f ΞΌ, (0 : β) β€ x :=
(ae_map_iff hf.aemeasurable measurableSet_Ici).2 (Eventually.of_forall h'f)
filter_upwards [this] with x hx
simp only [indicator, Set.mem_Ioc, Pi.zero_apply, ite_eq_right_iff, and_imp]
intro _ h''x
have : x = 0 := by linarith
simp [this, zero_pow hn]
Β· exact ((measurable_id.indicator M).pow_const n).aestronglyMeasurable
theorem integral_truncation_eq_intervalIntegral (hf : AEStronglyMeasurable f ΞΌ) {A : β}
(hA : 0 β€ A) : β« x, truncation f A x βΞΌ = β« y in -A..A, y βMeasure.map f ΞΌ := by
simpa using moment_truncation_eq_intervalIntegral hf hA one_ne_zero
theorem integral_truncation_eq_intervalIntegral_of_nonneg (hf : AEStronglyMeasurable f ΞΌ) {A : β}
(h'f : 0 β€ f) : β« x, truncation f A x βΞΌ = β« y in (0)..A, y βMeasure.map f ΞΌ := by
simpa using moment_truncation_eq_intervalIntegral_of_nonneg hf one_ne_zero h'f
theorem integral_truncation_le_integral_of_nonneg (hf : Integrable f ΞΌ) (h'f : 0 β€ f) {A : β} :
β« x, truncation f A x βΞΌ β€ β« x, f x βΞΌ := by
apply integral_mono_of_nonneg
(Eventually.of_forall fun x => ?_) hf (Eventually.of_forall fun x => ?_)
Β· exact truncation_nonneg _ (h'f x)
Β· calc
truncation f A x β€ |truncation f A x| := le_abs_self _
_ β€ |f x| := abs_truncation_le_abs_self _ _ _
_ = f x := abs_of_nonneg (h'f x)
/-- If a function is integrable, then the integral of its truncated versions converges to the
integral of the whole function. -/
theorem tendsto_integral_truncation {f : Ξ± β β} (hf : Integrable f ΞΌ) :
Tendsto (fun A => β« x, truncation f A x βΞΌ) atTop (π (β« x, f x βΞΌ)) := by
refine tendsto_integral_filter_of_dominated_convergence (fun x => abs (f x)) ?_ ?_ ?_ ?_
Β· exact Eventually.of_forall fun A β¦ hf.aestronglyMeasurable.truncation
Β· filter_upwards with A
filter_upwards with x
rw [Real.norm_eq_abs]
exact abs_truncation_le_abs_self _ _ _
Β· exact hf.abs
Β· filter_upwards with x
apply tendsto_const_nhds.congr' _
filter_upwards [Ioi_mem_atTop (abs (f x))] with A hA
exact (truncation_eq_self hA).symm
theorem IdentDistrib.truncation {Ξ² : Type*} [MeasurableSpace Ξ²] {Ξ½ : Measure Ξ²} {f : Ξ± β β}
{g : Ξ² β β} (h : IdentDistrib f g ΞΌ Ξ½) {A : β} :
IdentDistrib (truncation f A) (truncation g A) ΞΌ Ξ½ :=
h.comp (measurable_id.indicator measurableSet_Ioc)
end Truncation
section StrongLawAeReal
variable {Ξ© : Type*} [MeasureSpace Ξ©] [IsProbabilityMeasure (β : Measure Ξ©)]
section MomentEstimates
theorem sum_prob_mem_Ioc_le {X : Ξ© β β} (hint : Integrable X) (hnonneg : 0 β€ X) {K : β} {N : β}
(hKN : K β€ N) :
β j β range K, β {Ο | X Ο β Set.Ioc (j : β) N} β€ ENNReal.ofReal (πΌ[X] + 1) := by
let Ο : Measure β := Measure.map X β
haveI : IsProbabilityMeasure Ο := isProbabilityMeasure_map hint.aemeasurable
have A : β j β range K, β« _ in j..N, (1 : β) βΟ β€ πΌ[X] + 1 :=
calc
β j β range K, β« _ in j..N, (1 : β) βΟ =
β j β range K, β i β Ico j N, β« _ in i..(i + 1 : β), (1 : β) βΟ := by
apply sum_congr rfl fun j hj => ?_
rw [intervalIntegral.sum_integral_adjacent_intervals_Ico ((mem_range.1 hj).le.trans hKN)]
intro k _
exact continuous_const.intervalIntegrable _ _
_ = β i β range N, β j β range (min (i + 1) K), β« _ in i..(i + 1 : β), (1 : β) βΟ := by
simp_rw [sum_sigma']
refine sum_nbij' (fun p β¦ β¨p.2, p.1β©) (fun p β¦ β¨p.2, p.1β©) ?_ ?_ ?_ ?_ ?_ <;>
aesop (add simp Nat.lt_succ_iff)
_ β€ β i β range N, (i + 1) * β« _ in i..(i + 1 : β), (1 : β) βΟ := by
apply sum_le_sum fun i _ => ?_
simp only [Nat.cast_add, Nat.cast_one, sum_const, card_range, nsmul_eq_mul, Nat.cast_min]
refine mul_le_mul_of_nonneg_right (min_le_left _ _) ?_
apply intervalIntegral.integral_nonneg
Β· simp only [le_add_iff_nonneg_right, zero_le_one]
Β· simp only [zero_le_one, imp_true_iff]
_ β€ β i β range N, β« x in i..(i + 1 : β), x + 1 βΟ := by
apply sum_le_sum fun i _ => ?_
have I : (i : β) β€ (i + 1 : β) := by
simp only [Nat.cast_add, Nat.cast_one, le_add_iff_nonneg_right, zero_le_one]
simp_rw [intervalIntegral.integral_of_le I, β integral_const_mul]
apply setIntegral_mono_on
Β· exact continuous_const.integrableOn_Ioc
Β· exact (continuous_id.add continuous_const).integrableOn_Ioc
Β· exact measurableSet_Ioc
Β· intro x hx
simp only [Nat.cast_add, Nat.cast_one, Set.mem_Ioc] at hx
simp [hx.1.le]
_ = β« x in (0)..N, x + 1 βΟ := by
rw [intervalIntegral.sum_integral_adjacent_intervals fun k _ => ?_]
Β· norm_cast
Β· exact (continuous_id.add continuous_const).intervalIntegrable _ _
_ = β« x in (0)..N, x βΟ + β« x in (0)..N, 1 βΟ := by
rw [intervalIntegral.integral_add]
Β· exact continuous_id.intervalIntegrable _ _
Β· exact continuous_const.intervalIntegrable _ _
_ = πΌ[truncation X N] + β« x in (0)..N, 1 βΟ := by
rw [integral_truncation_eq_intervalIntegral_of_nonneg hint.1 hnonneg]
_ β€ πΌ[X] + β« x in (0)..N, 1 βΟ :=
(add_le_add_right (integral_truncation_le_integral_of_nonneg hint hnonneg) _)
_ β€ πΌ[X] + 1 := by
refine add_le_add le_rfl ?_
rw [intervalIntegral.integral_of_le (Nat.cast_nonneg _)]
simp only [integral_const, measureReal_restrict_apply', measurableSet_Ioc, Set.univ_inter,
Algebra.id.smul_eq_mul, mul_one]
rw [β ENNReal.toReal_one]
exact ENNReal.toReal_mono ENNReal.one_ne_top prob_le_one
have B : β a b, β {Ο | X Ο β Set.Ioc a b} = ENNReal.ofReal (β« _ in Set.Ioc a b, (1 : β) βΟ) := by
intro a b
rw [ofReal_setIntegral_one Ο _,
Measure.map_apply_of_aemeasurable hint.aemeasurable measurableSet_Ioc]
rfl
calc
β j β range K, β {Ο | X Ο β Set.Ioc (j : β) N} =
β j β range K, ENNReal.ofReal (β« _ in Set.Ioc (j : β) N, (1 : β) βΟ) := by simp_rw [B]
_ = ENNReal.ofReal (β j β range K, β« _ in Set.Ioc (j : β) N, (1 : β) βΟ) := by
simp [ENNReal.ofReal_sum_of_nonneg]
_ = ENNReal.ofReal (β j β range K, β« _ in (j : β)..N, (1 : β) βΟ) := by
congr 1
refine sum_congr rfl fun j hj => ?_
rw [intervalIntegral.integral_of_le (Nat.cast_le.2 ((mem_range.1 hj).le.trans hKN))]
_ β€ ENNReal.ofReal (πΌ[X] + 1) := ENNReal.ofReal_le_ofReal A
theorem tsum_prob_mem_Ioi_lt_top {X : Ξ© β β} (hint : Integrable X) (hnonneg : 0 β€ X) :
(β' j : β, β {Ο | X Ο β Set.Ioi (j : β)}) < β := by
suffices β K : β, β j β range K, β {Ο | X Ο β Set.Ioi (j : β)} β€ ENNReal.ofReal (πΌ[X] + 1) from
(le_of_tendsto_of_tendsto (ENNReal.tendsto_nat_tsum _) tendsto_const_nhds
(Eventually.of_forall this)).trans_lt ENNReal.ofReal_lt_top
intro K
have A : Tendsto (fun N : β => β j β range K, β {Ο | X Ο β Set.Ioc (j : β) N}) atTop
(π (β j β range K, β {Ο | X Ο β Set.Ioi (j : β)})) := by
refine tendsto_finset_sum _ fun i _ => ?_
have : {Ο | X Ο β Set.Ioi (i : β)} = β N : β, {Ο | X Ο β Set.Ioc (i : β) N} := by
apply Set.Subset.antisymm _ _
Β· intro Ο hΟ
obtain β¨N, hNβ© : β N : β, X Ο β€ N := exists_nat_ge (X Ο)
exact Set.mem_iUnion.2 β¨N, hΟ, hNβ©
Β· simp +contextual only [Set.mem_Ioc, Set.mem_Ioi,
Set.iUnion_subset_iff, Set.setOf_subset_setOf, imp_true_iff]
rw [this]
apply tendsto_measure_iUnion_atTop
intro m n hmn x hx
exact β¨hx.1, hx.2.trans (Nat.cast_le.2 hmn)β©
apply le_of_tendsto_of_tendsto A tendsto_const_nhds
filter_upwards [Ici_mem_atTop K] with N hN
exact sum_prob_mem_Ioc_le hint hnonneg hN
theorem sum_variance_truncation_le {X : Ξ© β β} (hint : Integrable X) (hnonneg : 0 β€ X) (K : β) :
β j β range K, ((j : β) ^ 2)β»ΒΉ * πΌ[truncation X j ^ 2] β€ 2 * πΌ[X] := by
set Y := fun n : β => truncation X n
let Ο : Measure β := Measure.map X β
have Y2 : β n, πΌ[Y n ^ 2] = β« x in (0)..n, x ^ 2 βΟ := by
intro n
change πΌ[fun x => Y n x ^ 2] = _
rw [moment_truncation_eq_intervalIntegral_of_nonneg hint.1 two_ne_zero hnonneg]
calc
β j β range K, ((j : β) ^ 2)β»ΒΉ * πΌ[Y j ^ 2] =
β j β range K, ((j : β) ^ 2)β»ΒΉ * β« x in (0)..j, x ^ 2 βΟ := by simp_rw [Y2]
_ = β j β range K, ((j : β) ^ 2)β»ΒΉ * β k β range j, β« x in k..(k + 1 : β), x ^ 2 βΟ := by
congr 1 with j
congr 1
rw [intervalIntegral.sum_integral_adjacent_intervals]
Β· norm_cast
intro k _
exact (continuous_id.pow _).intervalIntegrable _ _
_ = β k β range K, (β j β Ioo k K, ((j : β) ^ 2)β»ΒΉ) * β« x in k..(k + 1 : β), x ^ 2 βΟ := by
simp_rw [mul_sum, sum_mul, sum_sigma']
refine sum_nbij' (fun p β¦ β¨p.2, p.1β©) (fun p β¦ β¨p.2, p.1β©) ?_ ?_ ?_ ?_ ?_ <;>
aesop (add unsafe lt_trans)
_ β€ β k β range K, 2 / (k + 1 : β) * β« x in k..(k + 1 : β), x ^ 2 βΟ := by
apply sum_le_sum fun k _ => ?_
refine mul_le_mul_of_nonneg_right (sum_Ioo_inv_sq_le _ _) ?_
refine intervalIntegral.integral_nonneg_of_forall ?_ fun u => sq_nonneg _
simp only [Nat.cast_add, Nat.cast_one, le_add_iff_nonneg_right, zero_le_one]
_ β€ β k β range K, β« x in k..(k + 1 : β), 2 * x βΟ := by
apply sum_le_sum fun k _ => ?_
have Ik : (k : β) β€ (k + 1 : β) := by simp
rw [β intervalIntegral.integral_const_mul, intervalIntegral.integral_of_le Ik,
intervalIntegral.integral_of_le Ik]
refine setIntegral_mono_on ?_ ?_ measurableSet_Ioc fun x hx => ?_
Β· apply Continuous.integrableOn_Ioc
exact continuous_const.mul (continuous_pow 2)
Β· apply Continuous.integrableOn_Ioc
exact continuous_const.mul continuous_id'
Β· calc
β2 / (βk + β1) * x ^ 2 = x / (k + 1) * (2 * x) := by ring
_ β€ 1 * (2 * x) :=
(mul_le_mul_of_nonneg_right (by
convert (div_le_one _).2 hx.2
Β· norm_cast
simp only [Nat.cast_add, Nat.cast_one]
linarith only [show (0 : β) β€ k from Nat.cast_nonneg k])
(mul_nonneg zero_le_two ((Nat.cast_nonneg k).trans hx.1.le)))
_ = 2 * x := by rw [one_mul]
_ = 2 * β« x in (0 : β)..K, x βΟ := by
rw [intervalIntegral.sum_integral_adjacent_intervals fun k _ => ?_]
swap; Β· exact (continuous_const.mul continuous_id').intervalIntegrable _ _
rw [intervalIntegral.integral_const_mul]
norm_cast
_ β€ 2 * πΌ[X] := mul_le_mul_of_nonneg_left (by
rw [β integral_truncation_eq_intervalIntegral_of_nonneg hint.1 hnonneg]
exact integral_truncation_le_integral_of_nonneg hint hnonneg) zero_le_two
end MomentEstimates
/-! Proof of the strong law of large numbers (almost sure version, assuming only
pairwise independence) for nonnegative random variables, following Etemadi's proof. -/
section StrongLawNonneg
variable (X : β β Ξ© β β) (hint : Integrable (X 0))
(hindep : Pairwise (IndepFun on X)) (hident : β i, IdentDistrib (X i) (X 0))
(hnonneg : β i Ο, 0 β€ X i Ο)
include hint hindep hident hnonneg in
/-- The truncation of `Xα΅’` up to `i` satisfies the strong law of large numbers (with respect to
the truncated expectation) along the sequence `c^n`, for any `c > 1`, up to a given `Ξ΅ > 0`.
This follows from a variance control. -/
theorem strong_law_aux1 {c : β} (c_one : 1 < c) {Ξ΅ : β} (Ξ΅pos : 0 < Ξ΅) : βα΅ Ο, βαΆ n : β in atTop,
|β i β range βc ^ nββ, truncation (X i) i Ο - πΌ[β i β range βc ^ nββ, truncation (X i) i]| <
Ξ΅ * βc ^ nββ := by
/- Let `S n = β i β range n, Y i` where `Y i = truncation (X i) i`. We should show that
`|S k - πΌ[S k]| / k β€ Ξ΅` along the sequence of powers of `c`. For this, we apply Borel-Cantelli:
it suffices to show that the converse probabilities are summable. From Chebyshev inequality,
this will follow from a variance control `β' Var[S (c^i)] / (c^i)^2 < β`. This is checked in
`I2` using pairwise independence to expand the variance of the sum as the sum of the variances,
and then a straightforward but tedious computation (essentially boiling down to the fact that
the sum of `1/(c ^ i)^2` beyond a threshold `j` is comparable to `1/j^2`).
Note that we have written `c^i` in the above proof sketch, but rigorously one should put integer
parts everywhere, making things more painful. We write `u i = βc^iββ` for brevity. -/
have c_pos : 0 < c := zero_lt_one.trans c_one
have hX : β i, AEStronglyMeasurable (X i) β := fun i =>
(hident i).symm.aestronglyMeasurable_snd hint.1
have A : β i, StronglyMeasurable (indicator (Set.Ioc (-i : β) i) id) := fun i =>
stronglyMeasurable_id.indicator measurableSet_Ioc
set Y := fun n : β => truncation (X n) n
set S := fun n => β i β range n, Y i with hS
let u : β β β := fun n => βc ^ nββ
have u_mono : Monotone u := fun i j hij => Nat.floor_mono (pow_right_monoβ c_one.le hij)
have I1 : β K, β j β range K, ((j : β) ^ 2)β»ΒΉ * Var[Y j] β€ 2 * πΌ[X 0] := by
intro K
calc
β j β range K, ((j : β) ^ 2)β»ΒΉ * Var[Y j] β€
β j β range K, ((j : β) ^ 2)β»ΒΉ * πΌ[truncation (X 0) j ^ 2] := by
apply sum_le_sum fun j _ => ?_
refine mul_le_mul_of_nonneg_left ?_ (inv_nonneg.2 (sq_nonneg _))
rw [(hident j).truncation.variance_eq]
exact variance_le_expectation_sq (hX 0).truncation
_ β€ 2 * πΌ[X 0] := sum_variance_truncation_le hint (hnonneg 0) K
let C := c ^ 5 * (c - 1)β»ΒΉ ^ 3 * (2 * πΌ[X 0])
have I2 : β N, β i β range N, ((u i : β) ^ 2)β»ΒΉ * Var[S (u i)] β€ C := by
intro N
calc
β i β range N, ((u i : β) ^ 2)β»ΒΉ * Var[S (u i)] =
β i β range N, ((u i : β) ^ 2)β»ΒΉ * β j β range (u i), Var[Y j] := by
congr 1 with i
congr 1
rw [hS, IndepFun.variance_sum]
Β· intro j _
exact (hident j).aestronglyMeasurable_fst.memLp_truncation
Β· intro k _ l _ hkl
exact (hindep hkl).comp (A k).measurable (A l).measurable
_ = β j β range (u (N - 1)), (β i β range N with j < u i, ((u i : β) ^ 2)β»ΒΉ) * Var[Y j] := by
simp_rw [mul_sum, sum_mul, sum_sigma']
refine sum_nbij' (fun p β¦ β¨p.2, p.1β©) (fun p β¦ β¨p.2, p.1β©) ?_ ?_ ?_ ?_ ?_
Β· simp only [mem_sigma, mem_range, filter_congr_decidable, mem_filter, and_imp,
Sigma.forall]
exact fun a b haN hb β¦ β¨hb.trans_le <| u_mono <| Nat.le_pred_of_lt haN, haN, hbβ©
all_goals simp
_ β€ β j β range (u (N - 1)), c ^ 5 * (c - 1)β»ΒΉ ^ 3 / βj ^ 2 * Var[Y j] := by
apply sum_le_sum fun j hj => ?_
rcases eq_zero_or_pos j with (rfl | hj)
Β· simp only [Nat.cast_zero, zero_pow, Ne, Nat.one_ne_zero,
not_false_iff, div_zero, zero_mul]
simp only [Y, Nat.cast_zero, truncation_zero, variance_zero, mul_zero, le_rfl]
apply mul_le_mul_of_nonneg_right _ (variance_nonneg _ _)
convert sum_div_nat_floor_pow_sq_le_div_sq N (Nat.cast_pos.2 hj) c_one using 2
Β· simp only [u, Nat.cast_lt]
Β· simp only [Y, S, u, C, one_div]
_ = c ^ 5 * (c - 1)β»ΒΉ ^ 3 * β j β range (u (N - 1)), ((j : β) ^ 2)β»ΒΉ * Var[Y j] := by
simp_rw [mul_sum, div_eq_mul_inv, mul_assoc]
_ β€ c ^ 5 * (c - 1)β»ΒΉ ^ 3 * (2 * πΌ[X 0]) := by
apply mul_le_mul_of_nonneg_left (I1 _)
apply mul_nonneg (pow_nonneg c_pos.le _)
exact pow_nonneg (inv_nonneg.2 (sub_nonneg.2 c_one.le)) _
have I3 : β N, β i β range N, β {Ο | (u i * Ξ΅ : β) β€ |S (u i) Ο - πΌ[S (u i)]|} β€
ENNReal.ofReal (Ξ΅β»ΒΉ ^ 2 * C) := by
intro N
calc
β i β range N, β {Ο | (u i * Ξ΅ : β) β€ |S (u i) Ο - πΌ[S (u i)]|} β€
β i β range N, ENNReal.ofReal (Var[S (u i)] / (u i * Ξ΅) ^ 2) := by
refine sum_le_sum fun i _ => ?_
apply meas_ge_le_variance_div_sq
Β· exact memLp_finset_sum' _ fun j _ => (hident j).aestronglyMeasurable_fst.memLp_truncation
Β· apply mul_pos (Nat.cast_pos.2 _) Ξ΅pos
refine zero_lt_one.trans_le ?_
apply Nat.le_floor
rw [Nat.cast_one]
apply one_le_powβ c_one.le
_ = ENNReal.ofReal (β i β range N, Var[S (u i)] / (u i * Ξ΅) ^ 2) := by
rw [ENNReal.ofReal_sum_of_nonneg fun i _ => ?_]
exact div_nonneg (variance_nonneg _ _) (sq_nonneg _)
_ β€ ENNReal.ofReal (Ξ΅β»ΒΉ ^ 2 * C) := by
apply ENNReal.ofReal_le_ofReal
-- Porting note: do most of the rewrites under `conv` so as not to expand `variance`
conv_lhs =>
enter [2, i]
rw [div_eq_inv_mul, β inv_pow, mul_inv, mul_comm _ Ξ΅β»ΒΉ, mul_pow, mul_assoc]
rw [β mul_sum]
refine mul_le_mul_of_nonneg_left ?_ (sq_nonneg _)
conv_lhs => enter [2, i]; rw [inv_pow]
exact I2 N
have I4 : (β' i, β {Ο | (u i * Ξ΅ : β) β€ |S (u i) Ο - πΌ[S (u i)]|}) < β :=
(le_of_tendsto_of_tendsto' (ENNReal.tendsto_nat_tsum _) tendsto_const_nhds I3).trans_lt
ENNReal.ofReal_lt_top
filter_upwards [ae_eventually_not_mem I4.ne] with Ο hΟ
simp_rw [S, not_le, mul_comm, sum_apply] at hΟ
convert hΟ; simp only [Y, S, u, C, sum_apply]
include hint hindep hident hnonneg in
/-- The truncation of `Xα΅’` up to `i` satisfies the strong law of large numbers
(with respect to the truncated expectation) along the sequence
`c^n`, for any `c > 1`. This follows from `strong_law_aux1` by varying `Ξ΅`. -/
theorem strong_law_aux2 {c : β} (c_one : 1 < c) :
βα΅ Ο, (fun n : β => β i β range βc ^ nββ, truncation (X i) i Ο -
πΌ[β i β range βc ^ nββ, truncation (X i) i]) =o[atTop] fun n : β => (βc ^ nββ : β) := by
obtain β¨v, -, v_pos, v_limβ© :
β v : β β β, StrictAnti v β§ (β n : β, 0 < v n) β§ Tendsto v atTop (π 0) :=
exists_seq_strictAnti_tendsto (0 : β)
have := fun i => strong_law_aux1 X hint hindep hident hnonneg c_one (v_pos i)
filter_upwards [ae_all_iff.2 this] with Ο hΟ
apply Asymptotics.isLittleO_iff.2 fun Ξ΅ Ξ΅pos => ?_
obtain β¨i, hiβ© : β i, v i < Ξ΅ := ((tendsto_order.1 v_lim).2 Ξ΅ Ξ΅pos).exists
filter_upwards [hΟ i] with n hn
simp only [Real.norm_eq_abs, abs_abs, Nat.abs_cast]
exact hn.le.trans (mul_le_mul_of_nonneg_right hi.le (Nat.cast_nonneg _))
include hint hident in
/-- The expectation of the truncated version of `Xα΅’` behaves asymptotically like the whole
expectation. This follows from convergence and CesΓ ro averaging. -/
theorem strong_law_aux3 :
(fun n => πΌ[β i β range n, truncation (X i) i] - n * πΌ[X 0]) =o[atTop] ((β) : β β β) := by
have A : Tendsto (fun i => πΌ[truncation (X i) i]) atTop (π πΌ[X 0]) := by
convert (tendsto_integral_truncation hint).comp tendsto_natCast_atTop_atTop using 1
ext i
exact (hident i).truncation.integral_eq
convert Asymptotics.isLittleO_sum_range_of_tendsto_zero (tendsto_sub_nhds_zero_iff.2 A) using 1
ext1 n
simp only [sum_sub_distrib, sum_const, card_range, nsmul_eq_mul, sum_apply, sub_left_inj]
rw [integral_finset_sum _ fun i _ => ?_]
exact ((hident i).symm.integrable_snd hint).1.integrable_truncation
include hint hindep hident hnonneg in
/-- The truncation of `Xα΅’` up to `i` satisfies the strong law of large numbers
(with respect to the original expectation) along the sequence
`c^n`, for any `c > 1`. This follows from the version from the truncated expectation, and the
fact that the truncated and the original expectations have the same asymptotic behavior. -/
theorem strong_law_aux4 {c : β} (c_one : 1 < c) :
βα΅ Ο, (fun n : β => β i β range βc ^ nββ, truncation (X i) i Ο - βc ^ nββ * πΌ[X 0]) =o[atTop]
fun n : β => (βc ^ nββ : β) := by
filter_upwards [strong_law_aux2 X hint hindep hident hnonneg c_one] with Ο hΟ
| have A : Tendsto (fun n : β => βc ^ nββ) atTop atTop :=
tendsto_nat_floor_atTop.comp (tendsto_pow_atTop_atTop_of_one_lt c_one)
convert hΟ.add ((strong_law_aux3 X hint hident).comp_tendsto A) using 1
ext1 n
simp
include hint hident hnonneg in
/-- The truncated and non-truncated versions of `Xα΅’` have the same asymptotic behavior, as they
almost surely coincide at all but finitely many steps. This follows from a probability computation
and Borel-Cantelli. -/
theorem strong_law_aux5 :
| Mathlib/Probability/StrongLaw.lean | 522 | 532 |
/-
Copyright (c) 2021 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov, Alex Kontorovich, Heather Macbeth
-/
import Mathlib.MeasureTheory.Group.Action
import Mathlib.MeasureTheory.Group.Pointwise
import Mathlib.MeasureTheory.Integral.Lebesgue.Map
import Mathlib.MeasureTheory.Integral.Bochner.Set
/-!
# Fundamental domain of a group action
A set `s` is said to be a *fundamental domain* of an action of a group `G` on a measurable space `Ξ±`
with respect to a measure `ΞΌ` if
* `s` is a measurable set;
* the sets `g β’ s` over all `g : G` cover almost all points of the whole space;
* the sets `g β’ s`, are pairwise a.e. disjoint, i.e., `ΞΌ (gβ β’ s β© gβ β’ s) = 0` whenever `gβ β gβ`;
we require this for `gβ = 1` in the definition, then deduce it for any two `gβ β gβ`.
In this file we prove that in case of a countable group `G` and a measure preserving action, any two
fundamental domains have the same measure, and for a `G`-invariant function, its integrals over any
two fundamental domains are equal to each other.
We also generate additive versions of all theorems in this file using the `to_additive` attribute.
* We define the `HasFundamentalDomain` typeclass, in particular to be able to define the `covolume`
of a quotient of `Ξ±` by a group `G`, which under reasonable conditions does not depend on the choice
of fundamental domain.
* We define the `QuotientMeasureEqMeasurePreimage` typeclass to describe a situation in which a
measure `ΞΌ` on `Ξ± β§Έ G` can be computed by taking a measure `Ξ½` on `Ξ±` of the intersection of the
pullback with a fundamental domain.
## Main declarations
* `MeasureTheory.IsFundamentalDomain`: Predicate for a set to be a fundamental domain of the
action of a group
* `MeasureTheory.fundamentalFrontier`: Fundamental frontier of a set under the action of a group.
Elements of `s` that belong to some other translate of `s`.
* `MeasureTheory.fundamentalInterior`: Fundamental interior of a set under the action of a group.
Elements of `s` that do not belong to any other translate of `s`.
-/
open scoped ENNReal Pointwise Topology NNReal ENNReal MeasureTheory
open MeasureTheory MeasureTheory.Measure Set Function TopologicalSpace Filter
namespace MeasureTheory
/-- A measurable set `s` is a *fundamental domain* for an additive action of an additive group `G`
on a measurable space `Ξ±` with respect to a measure `Ξ±` if the sets `g +α΅₯ s`, `g : G`, are pairwise
a.e. disjoint and cover the whole space. -/
structure IsAddFundamentalDomain (G : Type*) {Ξ± : Type*} [Zero G] [VAdd G Ξ±] [MeasurableSpace Ξ±]
(s : Set Ξ±) (ΞΌ : Measure Ξ± := by volume_tac) : Prop where
protected nullMeasurableSet : NullMeasurableSet s ΞΌ
protected ae_covers : βα΅ x βΞΌ, β g : G, g +α΅₯ x β s
protected aedisjoint : Pairwise <| (AEDisjoint ΞΌ on fun g : G => g +α΅₯ s)
/-- A measurable set `s` is a *fundamental domain* for an action of a group `G` on a measurable
space `Ξ±` with respect to a measure `Ξ±` if the sets `g β’ s`, `g : G`, are pairwise a.e. disjoint and
cover the whole space. -/
@[to_additive IsAddFundamentalDomain]
structure IsFundamentalDomain (G : Type*) {Ξ± : Type*} [One G] [SMul G Ξ±] [MeasurableSpace Ξ±]
(s : Set Ξ±) (ΞΌ : Measure Ξ± := by volume_tac) : Prop where
protected nullMeasurableSet : NullMeasurableSet s ΞΌ
protected ae_covers : βα΅ x βΞΌ, β g : G, g β’ x β s
protected aedisjoint : Pairwise <| (AEDisjoint ΞΌ on fun g : G => g β’ s)
variable {G H Ξ± Ξ² E : Type*}
namespace IsFundamentalDomain
variable [Group G] [Group H] [MulAction G Ξ±] [MeasurableSpace Ξ±] [MulAction H Ξ²] [MeasurableSpace Ξ²]
[NormedAddCommGroup E] {s t : Set Ξ±} {ΞΌ : Measure Ξ±}
/-- If for each `x : Ξ±`, exactly one of `g β’ x`, `g : G`, belongs to a measurable set `s`, then `s`
is a fundamental domain for the action of `G` on `Ξ±`. -/
@[to_additive "If for each `x : Ξ±`, exactly one of `g +α΅₯ x`, `g : G`, belongs to a measurable set
`s`, then `s` is a fundamental domain for the additive action of `G` on `Ξ±`."]
theorem mk' (h_meas : NullMeasurableSet s ΞΌ) (h_exists : β x : Ξ±, β! g : G, g β’ x β s) :
IsFundamentalDomain G s ΞΌ where
nullMeasurableSet := h_meas
ae_covers := Eventually.of_forall fun x => (h_exists x).exists
aedisjoint a b hab := Disjoint.aedisjoint <| disjoint_left.2 fun x hxa hxb => by
rw [mem_smul_set_iff_inv_smul_mem] at hxa hxb
exact hab (inv_injective <| (h_exists x).unique hxa hxb)
/-- For `s` to be a fundamental domain, it's enough to check
`MeasureTheory.AEDisjoint (g β’ s) s` for `g β 1`. -/
@[to_additive "For `s` to be a fundamental domain, it's enough to check
`MeasureTheory.AEDisjoint (g +α΅₯ s) s` for `g β 0`."]
theorem mk'' (h_meas : NullMeasurableSet s ΞΌ) (h_ae_covers : βα΅ x βΞΌ, β g : G, g β’ x β s)
(h_ae_disjoint : β g, g β (1 : G) β AEDisjoint ΞΌ (g β’ s) s)
(h_qmp : β g : G, QuasiMeasurePreserving ((g β’ Β·) : Ξ± β Ξ±) ΞΌ ΞΌ) :
IsFundamentalDomain G s ΞΌ where
nullMeasurableSet := h_meas
ae_covers := h_ae_covers
aedisjoint := pairwise_aedisjoint_of_aedisjoint_forall_ne_one h_ae_disjoint h_qmp
/-- If a measurable space has a finite measure `ΞΌ` and a countable group `G` acts
quasi-measure-preservingly, then to show that a set `s` is a fundamental domain, it is sufficient
to check that its translates `g β’ s` are (almost) disjoint and that the sum `β' g, ΞΌ (g β’ s)` is
sufficiently large. -/
@[to_additive
"If a measurable space has a finite measure `ΞΌ` and a countable additive group `G` acts
quasi-measure-preservingly, then to show that a set `s` is a fundamental domain, it is sufficient
to check that its translates `g +α΅₯ s` are (almost) disjoint and that the sum `β' g, ΞΌ (g +α΅₯ s)` is
sufficiently large."]
theorem mk_of_measure_univ_le [IsFiniteMeasure ΞΌ] [Countable G] (h_meas : NullMeasurableSet s ΞΌ)
(h_ae_disjoint : β g β (1 : G), AEDisjoint ΞΌ (g β’ s) s)
(h_qmp : β g : G, QuasiMeasurePreserving (g β’ Β· : Ξ± β Ξ±) ΞΌ ΞΌ)
(h_measure_univ_le : ΞΌ (univ : Set Ξ±) β€ β' g : G, ΞΌ (g β’ s)) : IsFundamentalDomain G s ΞΌ :=
have aedisjoint : Pairwise (AEDisjoint ΞΌ on fun g : G => g β’ s) :=
pairwise_aedisjoint_of_aedisjoint_forall_ne_one h_ae_disjoint h_qmp
{ nullMeasurableSet := h_meas
aedisjoint
ae_covers := by
replace h_meas : β g : G, NullMeasurableSet (g β’ s) ΞΌ := fun g => by
rw [β inv_inv g, β preimage_smul]; exact h_meas.preimage (h_qmp gβ»ΒΉ)
have h_meas' : NullMeasurableSet {a | β g : G, g β’ a β s} ΞΌ := by
rw [β iUnion_smul_eq_setOf_exists]; exact .iUnion h_meas
rw [ae_iff_measure_eq h_meas', β iUnion_smul_eq_setOf_exists]
refine le_antisymm (measure_mono <| subset_univ _) ?_
rw [measure_iUnionβ aedisjoint h_meas]
exact h_measure_univ_le }
@[to_additive]
theorem iUnion_smul_ae_eq (h : IsFundamentalDomain G s ΞΌ) : β g : G, g β’ s =α΅[ΞΌ] univ :=
eventuallyEq_univ.2 <| h.ae_covers.mono fun _ β¨g, hgβ© =>
mem_iUnion.2 β¨gβ»ΒΉ, _, hg, inv_smul_smul _ _β©
@[to_additive]
theorem measure_ne_zero [Countable G] [SMulInvariantMeasure G Ξ± ΞΌ]
(hΞΌ : ΞΌ β 0) (h : IsFundamentalDomain G s ΞΌ) : ΞΌ s β 0 := by
have hc := measure_univ_pos.mpr hΞΌ
contrapose! hc
rw [β measure_congr h.iUnion_smul_ae_eq]
refine le_trans (measure_iUnion_le _) ?_
simp_rw [measure_smul, hc, tsum_zero, le_refl]
@[to_additive]
theorem mono (h : IsFundamentalDomain G s ΞΌ) {Ξ½ : Measure Ξ±} (hle : Ξ½ βͺ ΞΌ) :
IsFundamentalDomain G s Ξ½ :=
β¨h.1.mono_ac hle, hle h.2, h.aedisjoint.mono fun _ _ h => hle hβ©
@[to_additive]
theorem preimage_of_equiv {Ξ½ : Measure Ξ²} (h : IsFundamentalDomain G s ΞΌ) {f : Ξ² β Ξ±}
(hf : QuasiMeasurePreserving f Ξ½ ΞΌ) {e : G β H} (he : Bijective e)
(hef : β g, Semiconj f (e g β’ Β·) (g β’ Β·)) : IsFundamentalDomain H (f β»ΒΉ' s) Ξ½ where
nullMeasurableSet := h.nullMeasurableSet.preimage hf
ae_covers := (hf.ae h.ae_covers).mono fun x β¨g, hgβ© => β¨e g, by rwa [mem_preimage, hef g x]β©
aedisjoint a b hab := by
lift e to G β H using he
have : (e.symm aβ»ΒΉ)β»ΒΉ β (e.symm bβ»ΒΉ)β»ΒΉ := by simp [hab]
have := (h.aedisjoint this).preimage hf
simp only [Semiconj] at hef
simpa only [onFun, β preimage_smul_inv, preimage_preimage, β hef, e.apply_symm_apply, inv_inv]
using this
@[to_additive]
theorem image_of_equiv {Ξ½ : Measure Ξ²} (h : IsFundamentalDomain G s ΞΌ) (f : Ξ± β Ξ²)
(hf : QuasiMeasurePreserving f.symm Ξ½ ΞΌ) (e : H β G)
(hef : β g, Semiconj f (e g β’ Β·) (g β’ Β·)) : IsFundamentalDomain H (f '' s) Ξ½ := by
rw [f.image_eq_preimage]
refine h.preimage_of_equiv hf e.symm.bijective fun g x => ?_
rcases f.surjective x with β¨x, rflβ©
rw [β hef _ _, f.symm_apply_apply, f.symm_apply_apply, e.apply_symm_apply]
@[to_additive]
theorem pairwise_aedisjoint_of_ac {Ξ½} (h : IsFundamentalDomain G s ΞΌ) (hΞ½ : Ξ½ βͺ ΞΌ) :
Pairwise fun gβ gβ : G => AEDisjoint Ξ½ (gβ β’ s) (gβ β’ s) :=
h.aedisjoint.mono fun _ _ H => hΞ½ H
@[to_additive]
theorem smul_of_comm {G' : Type*} [Group G'] [MulAction G' Ξ±] [MeasurableSpace G']
[MeasurableSMul G' Ξ±] [SMulInvariantMeasure G' Ξ± ΞΌ] [SMulCommClass G' G Ξ±]
(h : IsFundamentalDomain G s ΞΌ) (g : G') : IsFundamentalDomain G (g β’ s) ΞΌ :=
h.image_of_equiv (MulAction.toPerm g) (measurePreserving_smul _ _).quasiMeasurePreserving
(Equiv.refl _) <| smul_comm g
variable [MeasurableSpace G] [MeasurableSMul G Ξ±] [SMulInvariantMeasure G Ξ± ΞΌ]
@[to_additive]
theorem nullMeasurableSet_smul (h : IsFundamentalDomain G s ΞΌ) (g : G) :
NullMeasurableSet (g β’ s) ΞΌ :=
h.nullMeasurableSet.smul g
@[to_additive]
theorem restrict_restrict (h : IsFundamentalDomain G s ΞΌ) (g : G) (t : Set Ξ±) :
(ΞΌ.restrict t).restrict (g β’ s) = ΞΌ.restrict (g β’ s β© t) :=
restrict_restrictβ ((h.nullMeasurableSet_smul g).mono restrict_le_self)
@[to_additive]
theorem smul (h : IsFundamentalDomain G s ΞΌ) (g : G) : IsFundamentalDomain G (g β’ s) ΞΌ :=
h.image_of_equiv (MulAction.toPerm g) (measurePreserving_smul _ _).quasiMeasurePreserving
β¨fun g' => gβ»ΒΉ * g' * g, fun g' => g * g' * gβ»ΒΉ, fun g' => by simp [mul_assoc], fun g' => by
simp [mul_assoc]β©
fun g' x => by simp [smul_smul, mul_assoc]
variable [Countable G] {Ξ½ : Measure Ξ±}
@[to_additive]
theorem sum_restrict_of_ac (h : IsFundamentalDomain G s ΞΌ) (hΞ½ : Ξ½ βͺ ΞΌ) :
(sum fun g : G => Ξ½.restrict (g β’ s)) = Ξ½ := by
rw [β restrict_iUnion_ae (h.aedisjoint.mono fun i j h => hΞ½ h) fun g =>
(h.nullMeasurableSet_smul g).mono_ac hΞ½,
restrict_congr_set (hΞ½ h.iUnion_smul_ae_eq), restrict_univ]
@[to_additive]
theorem lintegral_eq_tsum_of_ac (h : IsFundamentalDomain G s ΞΌ) (hΞ½ : Ξ½ βͺ ΞΌ) (f : Ξ± β ββ₯0β) :
β«β» x, f x βΞ½ = β' g : G, β«β» x in g β’ s, f x βΞ½ := by
rw [β lintegral_sum_measure, h.sum_restrict_of_ac hΞ½]
@[to_additive]
theorem sum_restrict (h : IsFundamentalDomain G s ΞΌ) : (sum fun g : G => ΞΌ.restrict (g β’ s)) = ΞΌ :=
h.sum_restrict_of_ac (refl _)
@[to_additive]
theorem lintegral_eq_tsum (h : IsFundamentalDomain G s ΞΌ) (f : Ξ± β ββ₯0β) :
β«β» x, f x βΞΌ = β' g : G, β«β» x in g β’ s, f x βΞΌ :=
h.lintegral_eq_tsum_of_ac (refl _) f
@[to_additive]
theorem lintegral_eq_tsum' (h : IsFundamentalDomain G s ΞΌ) (f : Ξ± β ββ₯0β) :
β«β» x, f x βΞΌ = β' g : G, β«β» x in s, f (gβ»ΒΉ β’ x) βΞΌ :=
calc
β«β» x, f x βΞΌ = β' g : G, β«β» x in g β’ s, f x βΞΌ := h.lintegral_eq_tsum f
_ = β' g : G, β«β» x in gβ»ΒΉ β’ s, f x βΞΌ := ((Equiv.inv G).tsum_eq _).symm
_ = β' g : G, β«β» x in s, f (gβ»ΒΉ β’ x) βΞΌ := tsum_congr fun g => Eq.symm <|
(measurePreserving_smul gβ»ΒΉ ΞΌ).setLIntegral_comp_emb (measurableEmbedding_const_smul _) _ _
@[to_additive] lemma lintegral_eq_tsum'' (h : IsFundamentalDomain G s ΞΌ) (f : Ξ± β ββ₯0β) :
β«β» x, f x βΞΌ = β' g : G, β«β» x in s, f (g β’ x) βΞΌ :=
(lintegral_eq_tsum' h f).trans ((Equiv.inv G).tsum_eq (fun g β¦ β«β» (x : Ξ±) in s, f (g β’ x) βΞΌ))
@[to_additive]
theorem setLIntegral_eq_tsum (h : IsFundamentalDomain G s ΞΌ) (f : Ξ± β ββ₯0β) (t : Set Ξ±) :
β«β» x in t, f x βΞΌ = β' g : G, β«β» x in t β© g β’ s, f x βΞΌ :=
calc
β«β» x in t, f x βΞΌ = β' g : G, β«β» x in g β’ s, f x βΞΌ.restrict t :=
h.lintegral_eq_tsum_of_ac restrict_le_self.absolutelyContinuous _
_ = β' g : G, β«β» x in t β© g β’ s, f x βΞΌ := by simp only [h.restrict_restrict, inter_comm]
@[to_additive]
theorem setLIntegral_eq_tsum' (h : IsFundamentalDomain G s ΞΌ) (f : Ξ± β ββ₯0β) (t : Set Ξ±) :
β«β» x in t, f x βΞΌ = β' g : G, β«β» x in g β’ t β© s, f (gβ»ΒΉ β’ x) βΞΌ :=
calc
β«β» x in t, f x βΞΌ = β' g : G, β«β» x in t β© g β’ s, f x βΞΌ := h.setLIntegral_eq_tsum f t
_ = β' g : G, β«β» x in t β© gβ»ΒΉ β’ s, f x βΞΌ := ((Equiv.inv G).tsum_eq _).symm
_ = β' g : G, β«β» x in gβ»ΒΉ β’ (g β’ t β© s), f x βΞΌ := by simp only [smul_set_inter, inv_smul_smul]
_ = β' g : G, β«β» x in g β’ t β© s, f (gβ»ΒΉ β’ x) βΞΌ := tsum_congr fun g => Eq.symm <|
(measurePreserving_smul gβ»ΒΉ ΞΌ).setLIntegral_comp_emb (measurableEmbedding_const_smul _) _ _
@[to_additive]
theorem measure_eq_tsum_of_ac (h : IsFundamentalDomain G s ΞΌ) (hΞ½ : Ξ½ βͺ ΞΌ) (t : Set Ξ±) :
Ξ½ t = β' g : G, Ξ½ (t β© g β’ s) := by
have H : Ξ½.restrict t βͺ ΞΌ := Measure.restrict_le_self.absolutelyContinuous.trans hΞ½
simpa only [setLIntegral_one, Pi.one_def,
Measure.restrict_applyβ ((h.nullMeasurableSet_smul _).mono_ac H), inter_comm] using
h.lintegral_eq_tsum_of_ac H 1
@[to_additive]
theorem measure_eq_tsum' (h : IsFundamentalDomain G s ΞΌ) (t : Set Ξ±) :
ΞΌ t = β' g : G, ΞΌ (t β© g β’ s) :=
h.measure_eq_tsum_of_ac AbsolutelyContinuous.rfl t
@[to_additive]
theorem measure_eq_tsum (h : IsFundamentalDomain G s ΞΌ) (t : Set Ξ±) :
ΞΌ t = β' g : G, ΞΌ (g β’ t β© s) := by
simpa only [setLIntegral_one] using h.setLIntegral_eq_tsum' (fun _ => 1) t
@[to_additive]
theorem measure_zero_of_invariant (h : IsFundamentalDomain G s ΞΌ) (t : Set Ξ±)
(ht : β g : G, g β’ t = t) (hts : ΞΌ (t β© s) = 0) : ΞΌ t = 0 := by
rw [measure_eq_tsum h]; simp [ht, hts]
/-- Given a measure space with an action of a finite group `G`, the measure of any `G`-invariant set
is determined by the measure of its intersection with a fundamental domain for the action of `G`. -/
@[to_additive measure_eq_card_smul_of_vadd_ae_eq_self "Given a measure space with an action of a
finite additive group `G`, the measure of any `G`-invariant set is determined by the measure of
its intersection with a fundamental domain for the action of `G`."]
theorem measure_eq_card_smul_of_smul_ae_eq_self [Finite G] (h : IsFundamentalDomain G s ΞΌ)
(t : Set Ξ±) (ht : β g : G, (g β’ t : Set Ξ±) =α΅[ΞΌ] t) : ΞΌ t = Nat.card G β’ ΞΌ (t β© s) := by
haveI : Fintype G := Fintype.ofFinite G
rw [h.measure_eq_tsum]
replace ht : β g : G, (g β’ t β© s : Set Ξ±) =α΅[ΞΌ] (t β© s : Set Ξ±) := fun g =>
ae_eq_set_inter (ht g) (ae_eq_refl s)
simp_rw [measure_congr (ht _), tsum_fintype, Finset.sum_const, Nat.card_eq_fintype_card,
Finset.card_univ]
@[to_additive]
protected theorem setLIntegral_eq (hs : IsFundamentalDomain G s ΞΌ) (ht : IsFundamentalDomain G t ΞΌ)
(f : Ξ± β ββ₯0β) (hf : β (g : G) (x), f (g β’ x) = f x) :
β«β» x in s, f x βΞΌ = β«β» x in t, f x βΞΌ :=
calc
β«β» x in s, f x βΞΌ = β' g : G, β«β» x in s β© g β’ t, f x βΞΌ := ht.setLIntegral_eq_tsum _ _
_ = β' g : G, β«β» x in g β’ t β© s, f (gβ»ΒΉ β’ x) βΞΌ := by simp only [hf, inter_comm]
_ = β«β» x in t, f x βΞΌ := (hs.setLIntegral_eq_tsum' _ _).symm
@[to_additive]
theorem measure_set_eq (hs : IsFundamentalDomain G s ΞΌ) (ht : IsFundamentalDomain G t ΞΌ) {A : Set Ξ±}
(hAβ : MeasurableSet A) (hA : β g : G, (fun x => g β’ x) β»ΒΉ' A = A) : ΞΌ (A β© s) = ΞΌ (A β© t) := by
have : β«β» x in s, A.indicator 1 x βΞΌ = β«β» x in t, A.indicator 1 x βΞΌ := by
refine hs.setLIntegral_eq ht (Set.indicator A fun _ => 1) fun g x β¦ ?_
convert (Set.indicator_comp_right (g β’ Β· : Ξ± β Ξ±) (g := fun _ β¦ (1 : ββ₯0β))).symm
rw [hA g]
simpa [Measure.restrict_apply hAβ, lintegral_indicator hAβ] using this
/-- If `s` and `t` are two fundamental domains of the same action, then their measures are equal. -/
@[to_additive "If `s` and `t` are two fundamental domains of the same action, then their measures
are equal."]
protected theorem measure_eq (hs : IsFundamentalDomain G s ΞΌ) (ht : IsFundamentalDomain G t ΞΌ) :
ΞΌ s = ΞΌ t := by
simpa only [setLIntegral_one] using hs.setLIntegral_eq ht (fun _ => 1) fun _ _ => rfl
@[to_additive]
protected theorem aestronglyMeasurable_on_iff {Ξ² : Type*} [TopologicalSpace Ξ²]
[PseudoMetrizableSpace Ξ²] (hs : IsFundamentalDomain G s ΞΌ) (ht : IsFundamentalDomain G t ΞΌ)
{f : Ξ± β Ξ²} (hf : β (g : G) (x), f (g β’ x) = f x) :
AEStronglyMeasurable f (ΞΌ.restrict s) β AEStronglyMeasurable f (ΞΌ.restrict t) :=
calc
AEStronglyMeasurable f (ΞΌ.restrict s) β
AEStronglyMeasurable f (Measure.sum fun g : G => ΞΌ.restrict (g β’ t β© s)) := by
simp only [β ht.restrict_restrict,
ht.sum_restrict_of_ac restrict_le_self.absolutelyContinuous]
_ β β g : G, AEStronglyMeasurable f (ΞΌ.restrict (g β’ (gβ»ΒΉ β’ s β© t))) := by
simp only [smul_set_inter, inter_comm, smul_inv_smul, aestronglyMeasurable_sum_measure_iff]
_ β β g : G, AEStronglyMeasurable f (ΞΌ.restrict (gβ»ΒΉ β’ (gβ»ΒΉβ»ΒΉ β’ s β© t))) :=
inv_surjective.forall
_ β β g : G, AEStronglyMeasurable f (ΞΌ.restrict (gβ»ΒΉ β’ (g β’ s β© t))) := by simp only [inv_inv]
_ β β g : G, AEStronglyMeasurable f (ΞΌ.restrict (g β’ s β© t)) := by
refine forall_congr' fun g => ?_
have he : MeasurableEmbedding (gβ»ΒΉ β’ Β· : Ξ± β Ξ±) := measurableEmbedding_const_smul _
rw [β image_smul, β ((measurePreserving_smul gβ»ΒΉ ΞΌ).restrict_image_emb he
_).aestronglyMeasurable_comp_iff he]
simp only [Function.comp_def, hf]
_ β AEStronglyMeasurable f (ΞΌ.restrict t) := by
simp only [β aestronglyMeasurable_sum_measure_iff, β hs.restrict_restrict,
hs.sum_restrict_of_ac restrict_le_self.absolutelyContinuous]
@[deprecated (since := "2025-04-09")]
alias aEStronglyMeasurable_on_iff := MeasureTheory.IsFundamentalDomain.aestronglyMeasurable_on_iff
@[deprecated (since := "2025-04-09")]
alias _root_.MeasureTheory.IsAddFundamentalDomain.aEStronglyMeasurable_on_iff :=
MeasureTheory.IsAddFundamentalDomain.aestronglyMeasurable_on_iff
@[to_additive]
protected theorem hasFiniteIntegral_on_iff (hs : IsFundamentalDomain G s ΞΌ)
(ht : IsFundamentalDomain G t ΞΌ) {f : Ξ± β E} (hf : β (g : G) (x), f (g β’ x) = f x) :
HasFiniteIntegral f (ΞΌ.restrict s) β HasFiniteIntegral f (ΞΌ.restrict t) := by
dsimp only [HasFiniteIntegral]
rw [hs.setLIntegral_eq ht]
intro g x; rw [hf]
@[to_additive]
protected theorem integrableOn_iff (hs : IsFundamentalDomain G s ΞΌ) (ht : IsFundamentalDomain G t ΞΌ)
{f : Ξ± β E} (hf : β (g : G) (x), f (g β’ x) = f x) : IntegrableOn f s ΞΌ β IntegrableOn f t ΞΌ :=
and_congr (hs.aestronglyMeasurable_on_iff ht hf) (hs.hasFiniteIntegral_on_iff ht hf)
variable [NormedSpace β E]
@[to_additive]
theorem integral_eq_tsum_of_ac (h : IsFundamentalDomain G s ΞΌ) (hΞ½ : Ξ½ βͺ ΞΌ) (f : Ξ± β E)
(hf : Integrable f Ξ½) : β« x, f x βΞ½ = β' g : G, β« x in g β’ s, f x βΞ½ := by
rw [β MeasureTheory.integral_sum_measure, h.sum_restrict_of_ac hΞ½]
rw [h.sum_restrict_of_ac hΞ½]
exact hf
@[to_additive]
theorem integral_eq_tsum (h : IsFundamentalDomain G s ΞΌ) (f : Ξ± β E) (hf : Integrable f ΞΌ) :
β« x, f x βΞΌ = β' g : G, β« x in g β’ s, f x βΞΌ :=
integral_eq_tsum_of_ac h (by rfl) f hf
@[to_additive]
theorem integral_eq_tsum' (h : IsFundamentalDomain G s ΞΌ) (f : Ξ± β E) (hf : Integrable f ΞΌ) :
β« x, f x βΞΌ = β' g : G, β« x in s, f (gβ»ΒΉ β’ x) βΞΌ :=
calc
β« x, f x βΞΌ = β' g : G, β« x in g β’ s, f x βΞΌ := h.integral_eq_tsum f hf
_ = β' g : G, β« x in gβ»ΒΉ β’ s, f x βΞΌ := ((Equiv.inv G).tsum_eq _).symm
_ = β' g : G, β« x in s, f (gβ»ΒΉ β’ x) βΞΌ := tsum_congr fun g =>
(measurePreserving_smul gβ»ΒΉ ΞΌ).setIntegral_image_emb (measurableEmbedding_const_smul _) _ _
@[to_additive] lemma integral_eq_tsum'' (h : IsFundamentalDomain G s ΞΌ)
(f : Ξ± β E) (hf : Integrable f ΞΌ) : β« x, f x βΞΌ = β' g : G, β« x in s, f (g β’ x) βΞΌ :=
(integral_eq_tsum' h f hf).trans ((Equiv.inv G).tsum_eq (fun g β¦ β« (x : Ξ±) in s, f (g β’ x) βΞΌ))
@[to_additive]
theorem setIntegral_eq_tsum (h : IsFundamentalDomain G s ΞΌ) {f : Ξ± β E} {t : Set Ξ±}
(hf : IntegrableOn f t ΞΌ) : β« x in t, f x βΞΌ = β' g : G, β« x in t β© g β’ s, f x βΞΌ :=
calc
β« x in t, f x βΞΌ = β' g : G, β« x in g β’ s, f x βΞΌ.restrict t :=
h.integral_eq_tsum_of_ac restrict_le_self.absolutelyContinuous f hf
_ = β' g : G, β« x in t β© g β’ s, f x βΞΌ := by
simp only [h.restrict_restrict, measure_smul, inter_comm]
@[to_additive]
theorem setIntegral_eq_tsum' (h : IsFundamentalDomain G s ΞΌ) {f : Ξ± β E} {t : Set Ξ±}
(hf : IntegrableOn f t ΞΌ) : β« x in t, f x βΞΌ = β' g : G, β« x in g β’ t β© s, f (gβ»ΒΉ β’ x) βΞΌ :=
calc
β« x in t, f x βΞΌ = β' g : G, β« x in t β© g β’ s, f x βΞΌ := h.setIntegral_eq_tsum hf
_ = β' g : G, β« x in t β© gβ»ΒΉ β’ s, f x βΞΌ := ((Equiv.inv G).tsum_eq _).symm
_ = β' g : G, β« x in gβ»ΒΉ β’ (g β’ t β© s), f x βΞΌ := by simp only [smul_set_inter, inv_smul_smul]
_ = β' g : G, β« x in g β’ t β© s, f (gβ»ΒΉ β’ x) βΞΌ :=
tsum_congr fun g =>
(measurePreserving_smul gβ»ΒΉ ΞΌ).setIntegral_image_emb (measurableEmbedding_const_smul _) _ _
@[to_additive]
protected theorem setIntegral_eq (hs : IsFundamentalDomain G s ΞΌ) (ht : IsFundamentalDomain G t ΞΌ)
{f : Ξ± β E} (hf : β (g : G) (x), f (g β’ x) = f x) : β« x in s, f x βΞΌ = β« x in t, f x βΞΌ := by
by_cases hfs : IntegrableOn f s ΞΌ
Β· have hft : IntegrableOn f t ΞΌ := by rwa [ht.integrableOn_iff hs hf]
calc
β« x in s, f x βΞΌ = β' g : G, β« x in s β© g β’ t, f x βΞΌ := ht.setIntegral_eq_tsum hfs
_ = β' g : G, β« x in g β’ t β© s, f (gβ»ΒΉ β’ x) βΞΌ := by simp only [hf, inter_comm]
_ = β« x in t, f x βΞΌ := (hs.setIntegral_eq_tsum' hft).symm
Β· rw [integral_undef hfs, integral_undef]
rwa [hs.integrableOn_iff ht hf] at hfs
/-- If the action of a countable group `G` admits an invariant measure `ΞΌ` with a fundamental domain
`s`, then every null-measurable set `t` such that the sets `g β’ t β© s` are pairwise a.e.-disjoint
has measure at most `ΞΌ s`. -/
@[to_additive "If the additive action of a countable group `G` admits an invariant measure `ΞΌ` with
a fundamental domain `s`, then every null-measurable set `t` such that the sets `g +α΅₯ t β© s` are
pairwise a.e.-disjoint has measure at most `ΞΌ s`."]
theorem measure_le_of_pairwise_disjoint (hs : IsFundamentalDomain G s ΞΌ)
(ht : NullMeasurableSet t ΞΌ) (hd : Pairwise (AEDisjoint ΞΌ on fun g : G => g β’ t β© s)) :
ΞΌ t β€ ΞΌ s :=
calc
ΞΌ t = β' g : G, ΞΌ (g β’ t β© s) := hs.measure_eq_tsum t
_ = ΞΌ (β g : G, g β’ t β© s) := Eq.symm <| measure_iUnionβ hd fun _ =>
(ht.smul _).inter hs.nullMeasurableSet
_ β€ ΞΌ s := measure_mono (iUnion_subset fun _ => inter_subset_right)
/-- If the action of a countable group `G` admits an invariant measure `ΞΌ` with a fundamental domain
`s`, then every null-measurable set `t` of measure strictly greater than `ΞΌ s` contains two
points `x y` such that `g β’ x = y` for some `g β 1`. -/
@[to_additive "If the additive action of a countable group `G` admits an invariant measure `ΞΌ` with
a fundamental domain `s`, then every null-measurable set `t` of measure strictly greater than
`ΞΌ s` contains two points `x y` such that `g +α΅₯ x = y` for some `g β 0`."]
theorem exists_ne_one_smul_eq (hs : IsFundamentalDomain G s ΞΌ) (htm : NullMeasurableSet t ΞΌ)
(ht : ΞΌ s < ΞΌ t) : β x β t, β y β t, β g, g β (1 : G) β§ g β’ x = y := by
contrapose! ht
refine hs.measure_le_of_pairwise_disjoint htm (Pairwise.aedisjoint fun gβ gβ hne => ?_)
dsimp [Function.onFun]
refine (Disjoint.inf_left _ ?_).inf_right _
rw [Set.disjoint_left]
rintro _ β¨x, hx, rflβ© β¨y, hy, hxy : gβ β’ y = gβ β’ xβ©
refine ht x hx y hy (gββ»ΒΉ * gβ) (mt inv_mul_eq_one.1 hne.symm) ?_
rw [mul_smul, β hxy, inv_smul_smul]
/-- If `f` is invariant under the action of a countable group `G`, and `ΞΌ` is a `G`-invariant
measure with a fundamental domain `s`, then the `essSup` of `f` restricted to `s` is the same as
that of `f` on all of its domain. -/
@[to_additive "If `f` is invariant under the action of a countable additive group `G`, and `ΞΌ` is a
`G`-invariant measure with a fundamental domain `s`, then the `essSup` of `f` restricted to `s`
is the same as that of `f` on all of its domain."]
theorem essSup_measure_restrict (hs : IsFundamentalDomain G s ΞΌ) {f : Ξ± β ββ₯0β}
(hf : β Ξ³ : G, β x : Ξ±, f (Ξ³ β’ x) = f x) : essSup f (ΞΌ.restrict s) = essSup f ΞΌ := by
refine le_antisymm (essSup_mono_measure' Measure.restrict_le_self) ?_
rw [essSup_eq_sInf (ΞΌ.restrict s) f, essSup_eq_sInf ΞΌ f]
refine sInf_le_sInf ?_
rintro a (ha : (ΞΌ.restrict s) {x : Ξ± | a < f x} = 0)
rw [Measure.restrict_applyβ' hs.nullMeasurableSet] at ha
refine measure_zero_of_invariant hs _ ?_ ha
intro Ξ³
ext x
rw [mem_smul_set_iff_inv_smul_mem]
simp only [mem_setOf_eq, hf Ξ³β»ΒΉ x]
end IsFundamentalDomain
/-! ### Interior/frontier of a fundamental domain -/
section MeasurableSpace
variable (G) [Group G] [MulAction G Ξ±] (s : Set Ξ±) {x : Ξ±}
/-- The boundary of a fundamental domain, those points of the domain that also lie in a nontrivial
translate. -/
@[to_additive MeasureTheory.addFundamentalFrontier "The boundary of a fundamental domain, those
points of the domain that also lie in a nontrivial translate."]
def fundamentalFrontier : Set Ξ± :=
s β© β (g : G) (_ : g β 1), g β’ s
/-- The interior of a fundamental domain, those points of the domain not lying in any translate. -/
@[to_additive MeasureTheory.addFundamentalInterior "The interior of a fundamental domain, those
points of the domain not lying in any translate."]
def fundamentalInterior : Set Ξ± :=
s \ β (g : G) (_ : g β 1), g β’ s
variable {G s}
@[to_additive (attr := simp) MeasureTheory.mem_addFundamentalFrontier]
theorem mem_fundamentalFrontier :
x β fundamentalFrontier G s β x β s β§ β g : G, g β 1 β§ x β g β’ s := by
simp [fundamentalFrontier]
@[to_additive (attr := simp) MeasureTheory.mem_addFundamentalInterior]
theorem mem_fundamentalInterior :
x β fundamentalInterior G s β x β s β§ β g : G, g β 1 β x β g β’ s := by
simp [fundamentalInterior]
@[to_additive MeasureTheory.addFundamentalFrontier_subset]
theorem fundamentalFrontier_subset : fundamentalFrontier G s β s :=
inter_subset_left
@[to_additive MeasureTheory.addFundamentalInterior_subset]
theorem fundamentalInterior_subset : fundamentalInterior G s β s :=
diff_subset
variable (G s)
@[to_additive MeasureTheory.disjoint_addFundamentalInterior_addFundamentalFrontier]
theorem disjoint_fundamentalInterior_fundamentalFrontier :
Disjoint (fundamentalInterior G s) (fundamentalFrontier G s) :=
disjoint_sdiff_self_left.mono_right inf_le_right
@[to_additive (attr := simp) MeasureTheory.addFundamentalInterior_union_addFundamentalFrontier]
theorem fundamentalInterior_union_fundamentalFrontier :
fundamentalInterior G s βͺ fundamentalFrontier G s = s :=
diff_union_inter _ _
@[to_additive (attr := simp) MeasureTheory.addFundamentalFrontier_union_addFundamentalInterior]
theorem fundamentalFrontier_union_fundamentalInterior :
fundamentalFrontier G s βͺ fundamentalInterior G s = s :=
inter_union_diff _ _
@[to_additive (attr := simp) MeasureTheory.sdiff_addFundamentalInterior]
theorem sdiff_fundamentalInterior : s \ fundamentalInterior G s = fundamentalFrontier G s :=
sdiff_sdiff_right_self
@[to_additive (attr := simp) MeasureTheory.sdiff_addFundamentalFrontier]
theorem sdiff_fundamentalFrontier : s \ fundamentalFrontier G s = fundamentalInterior G s :=
diff_self_inter
@[to_additive (attr := simp) MeasureTheory.addFundamentalFrontier_vadd]
theorem fundamentalFrontier_smul [Group H] [MulAction H Ξ±] [SMulCommClass H G Ξ±] (g : H) :
fundamentalFrontier G (g β’ s) = g β’ fundamentalFrontier G s := by
simp_rw [fundamentalFrontier, smul_set_inter, smul_set_iUnion, smul_comm g (_ : G) (_ : Set Ξ±)]
@[to_additive (attr := simp) MeasureTheory.addFundamentalInterior_vadd]
theorem fundamentalInterior_smul [Group H] [MulAction H Ξ±] [SMulCommClass H G Ξ±] (g : H) :
fundamentalInterior G (g β’ s) = g β’ fundamentalInterior G s := by
simp_rw [fundamentalInterior, smul_set_sdiff, smul_set_iUnion, smul_comm g (_ : G) (_ : Set Ξ±)]
@[to_additive MeasureTheory.pairwise_disjoint_addFundamentalInterior]
theorem pairwise_disjoint_fundamentalInterior :
Pairwise (Disjoint on fun g : G => g β’ fundamentalInterior G s) := by
refine fun a b hab => disjoint_left.2 ?_
rintro _ β¨x, hx, rflβ© β¨y, hy, hxyβ©
rw [mem_fundamentalInterior] at hx hy
refine hx.2 (aβ»ΒΉ * b) ?_ ?_
Β· rwa [Ne, inv_mul_eq_iff_eq_mul, mul_one, eq_comm]
Β· simpa [mul_smul, β hxy, mem_inv_smul_set_iff] using hy.1
variable [Countable G] [MeasurableSpace G] [MeasurableSpace Ξ±] [MeasurableSMul G Ξ±] {ΞΌ : Measure Ξ±}
[SMulInvariantMeasure G Ξ± ΞΌ]
@[to_additive MeasureTheory.NullMeasurableSet.addFundamentalFrontier]
protected theorem NullMeasurableSet.fundamentalFrontier (hs : NullMeasurableSet s ΞΌ) :
NullMeasurableSet (fundamentalFrontier G s) ΞΌ :=
hs.inter <| .iUnion fun _ => .iUnion fun _ => hs.smul _
@[to_additive MeasureTheory.NullMeasurableSet.addFundamentalInterior]
protected theorem NullMeasurableSet.fundamentalInterior (hs : NullMeasurableSet s ΞΌ) :
NullMeasurableSet (fundamentalInterior G s) ΞΌ :=
hs.diff <| .iUnion fun _ => .iUnion fun _ => hs.smul _
end MeasurableSpace
namespace IsFundamentalDomain
variable [Countable G] [Group G] [MulAction G Ξ±] [MeasurableSpace Ξ±] {ΞΌ : Measure Ξ±} {s : Set Ξ±}
(hs : IsFundamentalDomain G s ΞΌ)
include hs
section Group
@[to_additive MeasureTheory.IsAddFundamentalDomain.measure_addFundamentalFrontier]
theorem measure_fundamentalFrontier : ΞΌ (fundamentalFrontier G s) = 0 := by
simpa only [fundamentalFrontier, iUnionβ_inter, one_smul, measure_iUnion_null_iff, inter_comm s,
Function.onFun] using fun g (hg : g β 1) => hs.aedisjoint hg
@[to_additive MeasureTheory.IsAddFundamentalDomain.measure_addFundamentalInterior]
theorem measure_fundamentalInterior : ΞΌ (fundamentalInterior G s) = ΞΌ s :=
measure_diff_null' hs.measure_fundamentalFrontier
end Group
variable [MeasurableSpace G] [MeasurableSMul G Ξ±] [SMulInvariantMeasure G Ξ± ΞΌ]
protected theorem fundamentalInterior : IsFundamentalDomain G (fundamentalInterior G s) ΞΌ where
nullMeasurableSet := hs.nullMeasurableSet.fundamentalInterior _ _
ae_covers := by
simp_rw [ae_iff, not_exists, β mem_inv_smul_set_iff, setOf_forall, β compl_setOf,
setOf_mem_eq, β compl_iUnion]
have :
((β g : G, gβ»ΒΉ β’ s) \ β g : G, gβ»ΒΉ β’ fundamentalFrontier G s) β
β g : G, gβ»ΒΉ β’ fundamentalInterior G s := by
simp_rw [diff_subset_iff, β iUnion_union_distrib, β smul_set_union (Ξ± := G) (Ξ² := Ξ±),
fundamentalFrontier_union_fundamentalInterior]; rfl
refine eq_bot_mono (ΞΌ.mono <| compl_subset_compl.2 this) ?_
simp only [iUnion_inv_smul, compl_sdiff, ENNReal.bot_eq_zero, himp_eq, sup_eq_union,
@iUnion_smul_eq_setOf_exists _ _ _ _ s]
exact measure_union_null
(measure_iUnion_null fun _ => measure_smul_null hs.measure_fundamentalFrontier _) hs.ae_covers
aedisjoint := (pairwise_disjoint_fundamentalInterior _ _).mono fun _ _ => Disjoint.aedisjoint
end IsFundamentalDomain
section FundamentalDomainMeasure
variable (G) [Group G] [MulAction G Ξ±] [MeasurableSpace Ξ±]
(ΞΌ : Measure Ξ±)
local notation "Ξ±_mod_G" => MulAction.orbitRel G Ξ±
local notation "Ο" => @Quotient.mk _ Ξ±_mod_G
variable {G}
@[to_additive addMeasure_map_restrict_apply]
lemma measure_map_restrict_apply (s : Set Ξ±) {U : Set (Quotient Ξ±_mod_G)}
(meas_U : MeasurableSet U) :
(ΞΌ.restrict s).map Ο U = ΞΌ ((Ο β»ΒΉ' U) β© s) := by
rw [map_apply (f := Ο) (fun V hV β¦ measurableSet_quotient.mp hV) meas_U,
Measure.restrict_apply (t := (Quotient.mk Ξ±_mod_G β»ΒΉ' U)) (measurableSet_quotient.mp meas_U)]
@[to_additive]
lemma IsFundamentalDomain.quotientMeasure_eq [Countable G] [MeasurableSpace G] {s t : Set Ξ±}
[SMulInvariantMeasure G Ξ± ΞΌ] [MeasurableSMul G Ξ±] (fund_dom_s : IsFundamentalDomain G s ΞΌ)
(fund_dom_t : IsFundamentalDomain G t ΞΌ) :
(ΞΌ.restrict s).map Ο = (ΞΌ.restrict t).map Ο := by
ext U meas_U
rw [measure_map_restrict_apply (meas_U := meas_U), measure_map_restrict_apply (meas_U := meas_U)]
apply MeasureTheory.IsFundamentalDomain.measure_set_eq fund_dom_s fund_dom_t
Β· exact measurableSet_quotient.mp meas_U
Β· intro g
ext x
have : Quotient.mk Ξ±_mod_G (g β’ x) = Quotient.mk Ξ±_mod_G x := by
apply Quotient.sound
use g
simp only [mem_preimage, this]
end FundamentalDomainMeasure
/-! ## `HasFundamentalDomain` typeclass
We define `HasFundamentalDomain` in order to be able to define the `covolume` of a quotient of `Ξ±`
by a group `G`, which under reasonable conditions does not depend on the choice of fundamental
domain. Even though any "sensible" action should have a fundamental domain, this is a rather
delicate question which was recently addressed by Misha Kapovich: https://arxiv.org/abs/2301.05325
TODO: Formalize the existence of a Dirichlet domain as in Kapovich's paper.
-/
section HasFundamentalDomain
/-- We say a quotient of `Ξ±` by `G` `HasAddFundamentalDomain` if there is a measurable set
`s` for which `IsAddFundamentalDomain G s` holds. -/
class HasAddFundamentalDomain (G Ξ± : Type*) [Zero G] [VAdd G Ξ±] [MeasurableSpace Ξ±]
(Ξ½ : Measure Ξ± := by volume_tac) : Prop where
ExistsIsAddFundamentalDomain : β s : Set Ξ±, IsAddFundamentalDomain G s Ξ½
/-- We say a quotient of `Ξ±` by `G` `HasFundamentalDomain` if there is a measurable set `s` for
which `IsFundamentalDomain G s` holds. -/
class HasFundamentalDomain (G : Type*) (Ξ± : Type*) [One G] [SMul G Ξ±] [MeasurableSpace Ξ±]
(Ξ½ : Measure Ξ± := by volume_tac) : Prop where
ExistsIsFundamentalDomain : β (s : Set Ξ±), IsFundamentalDomain G s Ξ½
attribute [to_additive existing] MeasureTheory.HasFundamentalDomain
open Classical in
/-- The `covolume` of an action of `G` on `Ξ±` the volume of some fundamental domain, or `0` if
none exists. -/
@[to_additive addCovolume "The `addCovolume` of an action of `G` on `Ξ±` is the volume of some
fundamental domain, or `0` if none exists."]
noncomputable def covolume (G Ξ± : Type*) [One G] [SMul G Ξ±] [MeasurableSpace Ξ±]
(Ξ½ : Measure Ξ± := by volume_tac) : ββ₯0β :=
if funDom : HasFundamentalDomain G Ξ± Ξ½ then Ξ½ funDom.ExistsIsFundamentalDomain.choose else 0
variable [Group G] [MulAction G Ξ±] [MeasurableSpace Ξ±]
/-- If there is a fundamental domain `s`, then `HasFundamentalDomain` holds. -/
@[to_additive]
lemma IsFundamentalDomain.hasFundamentalDomain (Ξ½ : Measure Ξ±) {s : Set Ξ±}
(fund_dom_s : IsFundamentalDomain G s Ξ½) :
HasFundamentalDomain G Ξ± Ξ½ := β¨β¨s, fund_dom_sβ©β©
/-- The `covolume` can be computed by taking the `volume` of any given fundamental domain `s`. -/
@[to_additive]
lemma IsFundamentalDomain.covolume_eq_volume (Ξ½ : Measure Ξ±) [Countable G]
[MeasurableSpace G] [MeasurableSMul G Ξ±] [SMulInvariantMeasure G Ξ± Ξ½] {s : Set Ξ±}
(fund_dom_s : IsFundamentalDomain G s Ξ½) : covolume G Ξ± Ξ½ = Ξ½ s := by
dsimp [covolume]
simp only [(fund_dom_s.hasFundamentalDomain Ξ½), βreduceDIte]
rw [fund_dom_s.measure_eq]
exact (fund_dom_s.hasFundamentalDomain Ξ½).ExistsIsFundamentalDomain.choose_spec
end HasFundamentalDomain
/-! ## `QuotientMeasureEqMeasurePreimage` typeclass
This typeclass describes a situation in which a measure `ΞΌ` on `Ξ± β§Έ G` can be computed by
taking a measure `Ξ½` on `Ξ±` of the intersection of the pullback with a fundamental domain.
It's curious that in measure theory, measures can be pushed forward, while in geometry, volumes can
be pulled back. And yet here, we are describing a situation involving measures in a geometric way.
Another viewpoint is that if a set is small enough to fit in a single fundamental domain, then its
`Ξ½` measure in `Ξ±` is the same as the `ΞΌ` measure of its pushforward in `Ξ± β§Έ G`.
-/
section QuotientMeasureEqMeasurePreimage
section additive
variable [AddGroup G] [AddAction G Ξ±] [MeasurableSpace Ξ±]
local notation "Ξ±_mod_G" => AddAction.orbitRel G Ξ±
local notation "Ο" => @Quotient.mk _ Ξ±_mod_G
/-- A measure `ΞΌ` on the `AddQuotient` of `Ξ±` mod `G` satisfies
`AddQuotientMeasureEqMeasurePreimage` if: for any fundamental domain `t`, and any measurable
subset `U` of the quotient, `ΞΌ U = volume ((Ο β»ΒΉ' U) β© t)`. -/
class AddQuotientMeasureEqMeasurePreimage (Ξ½ : Measure Ξ± := by volume_tac)
(ΞΌ : Measure (Quotient Ξ±_mod_G)) : Prop where
addProjection_respects_measure' : β (t : Set Ξ±) (_ : IsAddFundamentalDomain G t Ξ½),
ΞΌ = (Ξ½.restrict t).map Ο
end additive
variable [Group G] [MulAction G Ξ±] [MeasurableSpace Ξ±]
local notation "Ξ±_mod_G" => MulAction.orbitRel G Ξ±
local notation "Ο" => @Quotient.mk _ Ξ±_mod_G
/-- Measures `Ξ½` on `Ξ±` and `ΞΌ` on the `Quotient` of `Ξ±` mod `G` satisfy
`QuotientMeasureEqMeasurePreimage` if: for any fundamental domain `t`, and any measurable subset
`U` of the quotient, `ΞΌ U = Ξ½ ((Ο β»ΒΉ' U) β© t)`. -/
class QuotientMeasureEqMeasurePreimage (Ξ½ : Measure Ξ± := by volume_tac)
(ΞΌ : Measure (Quotient Ξ±_mod_G)) : Prop where
projection_respects_measure' (t : Set Ξ±) : IsFundamentalDomain G t Ξ½ β ΞΌ = (Ξ½.restrict t).map Ο
attribute [to_additive]
MeasureTheory.QuotientMeasureEqMeasurePreimage
@[to_additive addProjection_respects_measure]
lemma IsFundamentalDomain.projection_respects_measure {Ξ½ : Measure Ξ±}
(ΞΌ : Measure (Quotient Ξ±_mod_G)) [i : QuotientMeasureEqMeasurePreimage Ξ½ ΞΌ] {t : Set Ξ±}
(fund_dom_t : IsFundamentalDomain G t Ξ½) : ΞΌ = (Ξ½.restrict t).map Ο :=
i.projection_respects_measure' t fund_dom_t
@[to_additive addProjection_respects_measure_apply]
lemma IsFundamentalDomain.projection_respects_measure_apply {Ξ½ : Measure Ξ±}
(ΞΌ : Measure (Quotient Ξ±_mod_G)) [i : QuotientMeasureEqMeasurePreimage Ξ½ ΞΌ] {t : Set Ξ±}
(fund_dom_t : IsFundamentalDomain G t Ξ½) {U : Set (Quotient Ξ±_mod_G)}
(meas_U : MeasurableSet U) : ΞΌ U = Ξ½ (Ο β»ΒΉ' U β© t) := by
rw [fund_dom_t.projection_respects_measure (ΞΌ := ΞΌ), measure_map_restrict_apply Ξ½ t meas_U]
variable {Ξ½ : Measure Ξ±}
/-- Any two measures satisfying `QuotientMeasureEqMeasurePreimage` are equal. -/
@[to_additive]
lemma QuotientMeasureEqMeasurePreimage.unique
[hasFun : HasFundamentalDomain G Ξ± Ξ½] (ΞΌ ΞΌ' : Measure (Quotient Ξ±_mod_G))
[QuotientMeasureEqMeasurePreimage Ξ½ ΞΌ] [QuotientMeasureEqMeasurePreimage Ξ½ ΞΌ'] :
ΞΌ = ΞΌ' := by
obtain β¨π, hπβ© := hasFun.ExistsIsFundamentalDomain
rw [hπ.projection_respects_measure (ΞΌ := ΞΌ), hπ.projection_respects_measure (ΞΌ := ΞΌ')]
/-- The quotient map to `Ξ± β§Έ G` is measure-preserving between the restriction of `volume` to a
fundamental domain in `Ξ±` and a related measure satisfying `QuotientMeasureEqMeasurePreimage`. -/
@[to_additive IsAddFundamentalDomain.measurePreserving_add_quotient_mk]
theorem IsFundamentalDomain.measurePreserving_quotient_mk
{π : Set Ξ±} (hπ : IsFundamentalDomain G π Ξ½)
(ΞΌ : Measure (Quotient Ξ±_mod_G)) [QuotientMeasureEqMeasurePreimage Ξ½ ΞΌ] :
MeasurePreserving Ο (Ξ½.restrict π) ΞΌ where
measurable := measurable_quotient_mk' (s := Ξ±_mod_G)
map_eq := by
haveI : HasFundamentalDomain G Ξ± Ξ½ := β¨π, hπβ©
rw [hπ.projection_respects_measure (ΞΌ := ΞΌ)]
variable [SMulInvariantMeasure G Ξ± Ξ½] [Countable G] [MeasurableSpace G] [MeasurableSMul G Ξ±]
/-- Given a measure upstairs (i.e., on `Ξ±`), and a choice `s` of fundamental domain, there's always
an artificial way to generate a measure downstairs such that the pair satisfies the
`QuotientMeasureEqMeasurePreimage` typeclass. -/
@[to_additive]
lemma IsFundamentalDomain.quotientMeasureEqMeasurePreimage_quotientMeasure
{s : Set Ξ±} (fund_dom_s : IsFundamentalDomain G s Ξ½) :
QuotientMeasureEqMeasurePreimage Ξ½ ((Ξ½.restrict s).map Ο) where
projection_respects_measure' t fund_dom_t := by rw [fund_dom_s.quotientMeasure_eq _ fund_dom_t]
/-- One can prove `QuotientMeasureEqMeasurePreimage` by checking behavior with respect to a single
fundamental domain. -/
@[to_additive]
lemma IsFundamentalDomain.quotientMeasureEqMeasurePreimage {ΞΌ : Measure (Quotient Ξ±_mod_G)}
{s : Set Ξ±} (fund_dom_s : IsFundamentalDomain G s Ξ½) (h : ΞΌ = (Ξ½.restrict s).map Ο) :
QuotientMeasureEqMeasurePreimage Ξ½ ΞΌ := by
simpa [h] using fund_dom_s.quotientMeasureEqMeasurePreimage_quotientMeasure
/-- If a fundamental domain has volume 0, then `QuotientMeasureEqMeasurePreimage` holds. -/
@[to_additive]
theorem IsFundamentalDomain.quotientMeasureEqMeasurePreimage_of_zero
{s : Set Ξ±} (fund_dom_s : IsFundamentalDomain G s Ξ½)
(vol_s : Ξ½ s = 0) :
QuotientMeasureEqMeasurePreimage Ξ½ (0 : Measure (Quotient Ξ±_mod_G)) := by
apply fund_dom_s.quotientMeasureEqMeasurePreimage
ext U meas_U
simp only [Measure.coe_zero, Pi.zero_apply]
convert (measure_inter_null_of_null_right (h := vol_s) (Quotient.mk Ξ±_mod_G β»ΒΉ' U)).symm
rw [measure_map_restrict_apply (meas_U := meas_U)]
/-- If a measure `ΞΌ` on a quotient satisfies `QuotientMeasureEqMeasurePreimage` with respect to a
sigma-finite measure `Ξ½`, then it is itself `SigmaFinite`. -/
@[to_additive]
lemma QuotientMeasureEqMeasurePreimage.sigmaFiniteQuotient
[i : SigmaFinite Ξ½] [i' : HasFundamentalDomain G Ξ± Ξ½]
(ΞΌ : Measure (Quotient Ξ±_mod_G)) [QuotientMeasureEqMeasurePreimage Ξ½ ΞΌ] :
SigmaFinite ΞΌ := by
rw [sigmaFinite_iff]
obtain β¨A, hA_meas, hA, hA'β© := Measure.toFiniteSpanningSetsIn (h := i)
simp only [mem_setOf_eq] at hA_meas
refine β¨β¨fun n β¦ Ο '' (A n), by simp, fun n β¦ ?_, ?_β©β©
Β· obtain β¨s, fund_dom_sβ© := i'
have : Ο β»ΒΉ' (Ο '' (A n)) = _ := MulAction.quotient_preimage_image_eq_union_mul (A n) (G := G)
have measΟAn : MeasurableSet (Ο '' A n) := by
let _ : Setoid Ξ± := Ξ±_mod_G
rw [measurableSet_quotient, Quotient.mk''_eq_mk, this]
apply MeasurableSet.iUnion
exact fun g β¦ MeasurableSet.const_smul (hA_meas n) g
rw [fund_dom_s.projection_respects_measure_apply (ΞΌ := ΞΌ) measΟAn, this, iUnion_inter]
refine lt_of_le_of_lt ?_ (hA n)
rw [fund_dom_s.measure_eq_tsum (A n)]
exact measure_iUnion_le _
Β· rw [β image_iUnion, hA']
refine image_univ_of_surjective (by convert Quotient.mk'_surjective)
/-- A measure `ΞΌ` on `Ξ± β§Έ G` satisfying `QuotientMeasureEqMeasurePreimage` and having finite
covolume is a finite measure. -/
@[to_additive]
theorem QuotientMeasureEqMeasurePreimage.isFiniteMeasure_quotient
(ΞΌ : Measure (Quotient Ξ±_mod_G)) [QuotientMeasureEqMeasurePreimage Ξ½ ΞΌ]
[hasFun : HasFundamentalDomain G Ξ± Ξ½] (h : covolume G Ξ± Ξ½ β β) :
IsFiniteMeasure ΞΌ := by
obtain β¨π, hπβ© := hasFun.ExistsIsFundamentalDomain
rw [hπ.projection_respects_measure (ΞΌ := ΞΌ)]
have : Fact (Ξ½ π < β) := by
apply Fact.mk
convert Ne.lt_top h
exact (hπ.covolume_eq_volume Ξ½).symm
infer_instance
/-- A finite measure `ΞΌ` on `Ξ± β§Έ G` satisfying `QuotientMeasureEqMeasurePreimage` has finite
covolume. -/
@[to_additive]
theorem QuotientMeasureEqMeasurePreimage.covolume_ne_top
(ΞΌ : Measure (Quotient Ξ±_mod_G)) [QuotientMeasureEqMeasurePreimage Ξ½ ΞΌ] [IsFiniteMeasure ΞΌ] :
covolume G Ξ± Ξ½ < β := by
by_cases hasFun : HasFundamentalDomain G Ξ± Ξ½
Β· obtain β¨π, hπβ© := hasFun.ExistsIsFundamentalDomain
have H : ΞΌ univ < β := IsFiniteMeasure.measure_univ_lt_top
rw [hπ.projection_respects_measure_apply (ΞΌ := ΞΌ) MeasurableSet.univ] at H
simpa [hπ.covolume_eq_volume Ξ½] using H
Β· simp [covolume, hasFun]
end QuotientMeasureEqMeasurePreimage
section QuotientMeasureEqMeasurePreimage
variable [Group G] [MulAction G Ξ±] [MeasureSpace Ξ±] [Countable G] [MeasurableSpace G]
[SMulInvariantMeasure G Ξ± volume] [MeasurableSMul G Ξ±]
local notation "Ξ±_mod_G" => MulAction.orbitRel G Ξ±
local notation "Ο" => @Quotient.mk _ Ξ±_mod_G
/-- If a measure `ΞΌ` on a quotient satisfies `QuotientVolumeEqVolumePreimage` with respect to a
sigma-finite measure, then it is itself `SigmaFinite`. -/
@[to_additive MeasureTheory.instSigmaFiniteAddQuotientOrbitRelInstMeasurableSpaceToMeasurableSpace]
instance [SigmaFinite (volume : Measure Ξ±)] [HasFundamentalDomain G Ξ±]
| (ΞΌ : Measure (Quotient Ξ±_mod_G)) [QuotientMeasureEqMeasurePreimage volume ΞΌ] :
SigmaFinite ΞΌ :=
QuotientMeasureEqMeasurePreimage.sigmaFiniteQuotient (Ξ½ := (volume : Measure Ξ±)) (ΞΌ := ΞΌ)
end QuotientMeasureEqMeasurePreimage
| Mathlib/MeasureTheory/Group/FundamentalDomain.lean | 895 | 900 |
/-
Copyright (c) 2024 Violeta HernΓ‘ndez Palacios. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Violeta HernΓ‘ndez Palacios
-/
import Mathlib.SetTheory.Cardinal.Arithmetic
import Mathlib.SetTheory.Ordinal.Principal
/-!
# Ordinal arithmetic with cardinals
This file collects results about the cardinality of different ordinal operations.
-/
universe u v
open Cardinal Ordinal Set
/-! ### Cardinal operations with ordinal indices -/
namespace Cardinal
/-- Bounds the cardinal of an ordinal-indexed union of sets. -/
lemma mk_iUnion_Ordinal_lift_le_of_le {Ξ² : Type v} {o : Ordinal.{u}} {c : Cardinal.{v}}
(ho : lift.{v} o.card β€ lift.{u} c) (hc : β΅β β€ c) (A : Ordinal β Set Ξ²)
(hA : β j < o, #(A j) β€ c) : #(β j < o, A j) β€ c := by
simp_rw [β mem_Iio, biUnion_eq_iUnion, iUnion, iSup, β o.enumIsoToType.symm.surjective.range_comp]
rw [β lift_le.{u}]
apply ((mk_iUnion_le_lift _).trans _).trans_eq (mul_eq_self (aleph0_le_lift.2 hc))
rw [mk_toType]
refine mul_le_mul' ho (ciSup_le' ?_)
intro i
simpa using hA _ (o.enumIsoToType.symm i).2
lemma mk_iUnion_Ordinal_le_of_le {Ξ² : Type*} {o : Ordinal} {c : Cardinal}
(ho : o.card β€ c) (hc : β΅β β€ c) (A : Ordinal β Set Ξ²)
(hA : β j < o, #(A j) β€ c) : #(β j < o, A j) β€ c := by
apply mk_iUnion_Ordinal_lift_le_of_le _ hc A hA
rwa [Cardinal.lift_le]
end Cardinal
@[deprecated mk_iUnion_Ordinal_le_of_le (since := "2024-11-02")]
alias Ordinal.Cardinal.mk_iUnion_Ordinal_le_of_le := mk_iUnion_Ordinal_le_of_le
/-! ### Cardinality of ordinals -/
namespace Ordinal
theorem lift_card_iSup_le_sum_card {ΞΉ : Type u} [Small.{v} ΞΉ] (f : ΞΉ β Ordinal.{v}) :
Cardinal.lift.{u} (β¨ i, f i).card β€ Cardinal.sum fun i β¦ (f i).card := by
simp_rw [β mk_toType]
rw [β mk_sigma, β Cardinal.lift_id'.{v} #(Ξ£ _, _), β Cardinal.lift_umax.{v, u}]
apply lift_mk_le_lift_mk_of_surjective (f := enumIsoToType _ β (β¨(enumIsoToType _).symm Β·.2,
(mem_Iio.mp ((enumIsoToType _).symm _).2).trans_le (Ordinal.le_iSup _ _)β©))
rw [EquivLike.comp_surjective]
rintro β¨x, hxβ©
obtain β¨i, hiβ© := Ordinal.lt_iSup_iff.mp hx
exact β¨β¨i, enumIsoToType _ β¨x, hiβ©β©, by simpβ©
theorem card_iSup_le_sum_card {ΞΉ : Type u} (f : ΞΉ β Ordinal.{max u v}) :
(β¨ i, f i).card β€ Cardinal.sum (fun i β¦ (f i).card) := by
have := lift_card_iSup_le_sum_card f
rwa [Cardinal.lift_id'] at this
theorem card_iSup_Iio_le_sum_card {o : Ordinal.{u}} (f : Iio o β Ordinal.{max u v}) :
(β¨ a : Iio o, f a).card β€ Cardinal.sum fun i β¦ (f ((enumIsoToType o).symm i)).card := by
apply le_of_eq_of_le (congr_arg _ _).symm (card_iSup_le_sum_card _)
simpa using (enumIsoToType o).symm.iSup_comp (g := fun x β¦ f x)
theorem card_iSup_Iio_le_card_mul_iSup {o : Ordinal.{u}} (f : Iio o β Ordinal.{max u v}) :
(β¨ a : Iio o, f a).card β€ Cardinal.lift.{v} o.card * β¨ a : Iio o, (f a).card := by
apply (card_iSup_Iio_le_sum_card f).trans
convert β sum_le_iSup_lift _
Β· exact mk_toType o
Β· exact (enumIsoToType o).symm.iSup_comp (g := fun x β¦ (f x).card)
theorem card_opow_le_of_omega0_le_left {a : Ordinal} (ha : Ο β€ a) (b : Ordinal) :
(a ^ b).card β€ max a.card b.card := by
refine limitRecOn b ?_ ?_ ?_
Β· simpa using one_lt_omega0.le.trans ha
Β· intro b IH
rw [opow_succ, card_mul, card_succ, Cardinal.mul_eq_max_of_aleph0_le_right, max_comm]
Β· apply (max_le_max_left _ IH).trans
rw [β max_assoc, max_self]
exact max_le_max_left _ le_self_add
Β· rw [ne_eq, card_eq_zero, opow_eq_zero]
rintro β¨rfl, -β©
cases omega0_pos.not_le ha
Β· rwa [aleph0_le_card]
Β· intro b hb IH
rw [(isNormal_opow (one_lt_omega0.trans_le ha)).apply_of_isLimit hb]
apply (card_iSup_Iio_le_card_mul_iSup _).trans
rw [Cardinal.lift_id, Cardinal.mul_eq_max_of_aleph0_le_right, max_comm]
Β· apply max_le _ (le_max_right _ _)
apply ciSup_le'
intro c
exact (IH c.1 c.2).trans (max_le_max_left _ (card_le_card c.2.le))
Β· simpa using hb.pos.ne'
Β· refine le_ciSup_of_le ?_ β¨1, one_lt_omega0.trans_le <| omega0_le_of_isLimit hbβ© ?_
Β· exact Cardinal.bddAbove_of_small _
Β· simpa
theorem card_opow_le_of_omega0_le_right (a : Ordinal) {b : Ordinal} (hb : Ο β€ b) :
(a ^ b).card β€ max a.card b.card := by
obtain β¨n, rflβ© | ha := eq_nat_or_omega0_le a
Β· apply (card_le_card <| opow_le_opow_left b (nat_lt_omega0 n).le).trans
apply (card_opow_le_of_omega0_le_left le_rfl _).trans
simp [hb]
Β· exact card_opow_le_of_omega0_le_left ha b
theorem card_opow_le (a b : Ordinal) : (a ^ b).card β€ max β΅β (max a.card b.card) := by
obtain β¨n, rflβ© | ha := eq_nat_or_omega0_le a
Β· obtain β¨m, rflβ© | hb := eq_nat_or_omega0_le b
Β· rw [β natCast_opow, card_nat]
exact le_max_of_le_left (nat_lt_aleph0 _).le
Β· exact (card_opow_le_of_omega0_le_right _ hb).trans (le_max_right _ _)
Β· exact (card_opow_le_of_omega0_le_left ha _).trans (le_max_right _ _)
theorem card_opow_eq_of_omega0_le_left {a b : Ordinal} (ha : Ο β€ a) (hb : 0 < b) :
(a ^ b).card = max a.card b.card := by
apply (card_opow_le_of_omega0_le_left ha b).antisymm (max_le _ _) <;> apply card_le_card
Β· exact left_le_opow a hb
Β· exact right_le_opow b (one_lt_omega0.trans_le ha)
theorem card_opow_eq_of_omega0_le_right {a b : Ordinal} (ha : 1 < a) (hb : Ο β€ b) :
(a ^ b).card = max a.card b.card := by
apply (card_opow_le_of_omega0_le_right a hb).antisymm (max_le _ _) <;> apply card_le_card
Β· exact left_le_opow a (omega0_pos.trans_le hb)
Β· exact right_le_opow b ha
theorem card_omega0_opow {a : Ordinal} (h : a β 0) : card (Ο ^ a) = max β΅β a.card := by
rw [card_opow_eq_of_omega0_le_left le_rfl h.bot_lt, card_omega0]
theorem card_opow_omega0 {a : Ordinal} (h : 1 < a) : card (a ^ Ο) = max β΅β a.card := by
rw [card_opow_eq_of_omega0_le_right h le_rfl, card_omega0, max_comm]
theorem principal_opow_omega (o : Ordinal) : Principal (Β· ^ Β·) (Ο_ o) := by
obtain rfl | ho := Ordinal.eq_zero_or_pos o
Β· rw [omega_zero]
exact principal_opow_omega0
Β· intro a b ha hb
rw [lt_omega_iff_card_lt] at ha hb β’
apply (card_opow_le a b).trans_lt (max_lt _ (max_lt ha hb))
rwa [β aleph_zero, aleph_lt_aleph]
theorem IsInitial.principal_opow {o : Ordinal} (h : IsInitial o) (ho : Ο β€ o) :
Principal (Β· ^ Β·) o := by
obtain β¨a, rflβ© := mem_range_omega_iff.2 β¨ho, hβ©
exact principal_opow_omega a
theorem principal_opow_ord {c : Cardinal} (hc : β΅β β€ c) : Principal (Β· ^ Β·) c.ord := by
apply (isInitial_ord c).principal_opow
rwa [omega0_le_ord]
/-! ### Initial ordinals are principal -/
theorem principal_add_ord {c : Cardinal} (hc : β΅β β€ c) : Principal (Β· + Β·) c.ord := by
intro a b ha hb
rw [lt_ord, card_add] at *
exact add_lt_of_lt hc ha hb
theorem IsInitial.principal_add {o : Ordinal} (h : IsInitial o) (ho : Ο β€ o) :
Principal (Β· + Β·) o := by
rw [β h.ord_card]
apply principal_add_ord
rwa [aleph0_le_card]
theorem principal_add_omega (o : Ordinal) : Principal (Β· + Β·) (Ο_ o) :=
(isInitial_omega o).principal_add (omega0_le_omega o)
theorem principal_mul_ord {c : Cardinal} (hc : β΅β β€ c) : Principal (Β· * Β·) c.ord := by
intro a b ha hb
rw [lt_ord, card_mul] at *
exact mul_lt_of_lt hc ha hb
theorem IsInitial.principal_mul {o : Ordinal} (h : IsInitial o) (ho : Ο β€ o) :
Principal (Β· * Β·) o := by
rw [β h.ord_card]
apply principal_mul_ord
rwa [aleph0_le_card]
theorem principal_mul_omega (o : Ordinal) : Principal (Β· * Β·) (Ο_ o) :=
(isInitial_omega o).principal_mul (omega0_le_omega o)
@[deprecated principal_add_omega (since := "2024-11-08")]
theorem _root_.Cardinal.principal_add_aleph (o : Ordinal) : Principal (Β· + Β·) (β΅_ o).ord :=
principal_add_ord <| aleph0_le_aleph o
end Ordinal
| Mathlib/SetTheory/Cardinal/Ordinal.lean | 785 | 786 | |
/-
Copyright (c) 2020 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin
-/
import Mathlib.RingTheory.WittVector.Frobenius
import Mathlib.RingTheory.WittVector.Verschiebung
import Mathlib.RingTheory.WittVector.MulP
/-!
## Identities between operations on the ring of Witt vectors
In this file we derive common identities between the Frobenius and Verschiebung operators.
## Main declarations
* `frobenius_verschiebung`: the composition of Frobenius and Verschiebung is multiplication by `p`
* `verschiebung_mul_frobenius`: the βprojection formulaβ: `V(x * F y) = V x * y`
* `iterate_verschiebung_mul_coeff`: an identity from [Haze09] 6.2
## References
* [Hazewinkel, *Witt Vectors*][Haze09]
* [Commelin and Lewis, *Formalizing the Ring of Witt Vectors*][CL21]
-/
namespace WittVector
variable {p : β} {R : Type*} [hp : Fact p.Prime] [CommRing R]
-- type as `\bbW`
local notation "π" => WittVector p
noncomputable section
-- Porting note: `ghost_calc` failure: `simp only []` and the manual instances had to be added.
/-- The composition of Frobenius and Verschiebung is multiplication by `p`. -/
theorem frobenius_verschiebung (x : π R) : frobenius (verschiebung x) = x * p := by
have : IsPoly p fun {R} [CommRing R] x β¦ frobenius (verschiebung x) :=
| IsPoly.comp (hg := frobenius_isPoly p) (hf := verschiebung_isPoly)
have : IsPoly p fun {R} [CommRing R] x β¦ x * p := mulN_isPoly p p
ghost_calc x
ghost_simp [mul_comm]
/-- Verschiebung is the same as multiplication by `p` on the ring of Witt vectors of `ZMod p`. -/
| Mathlib/RingTheory/WittVector/Identities.lean | 42 | 47 |
/-
Copyright (c) 2020 Riccardo Brasca. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Riccardo Brasca
-/
import Mathlib.RingTheory.Polynomial.Cyclotomic.Basic
import Mathlib.RingTheory.RootsOfUnity.Minpoly
/-!
# Roots of cyclotomic polynomials.
We gather results about roots of cyclotomic polynomials. In particular we show in
`Polynomial.cyclotomic_eq_minpoly` that `cyclotomic n R` is the minimal polynomial of a primitive
root of unity.
## Main results
* `IsPrimitiveRoot.isRoot_cyclotomic` : Any `n`-th primitive root of unity is a root of
`cyclotomic n R`.
* `isRoot_cyclotomic_iff` : if `NeZero (n : R)`, then `ΞΌ` is a root of `cyclotomic n R`
if and only if `ΞΌ` is a primitive root of unity.
* `Polynomial.cyclotomic_eq_minpoly` : `cyclotomic n β€` is the minimal polynomial of a primitive
`n`-th root of unity `ΞΌ`.
* `Polynomial.cyclotomic.irreducible` : `cyclotomic n β€` is irreducible.
## Implementation details
To prove `Polynomial.cyclotomic.irreducible`, the irreducibility of `cyclotomic n β€`, we show in
`Polynomial.cyclotomic_eq_minpoly` that `cyclotomic n β€` is the minimal polynomial of any `n`-th
primitive root of unity `ΞΌ : K`, where `K` is a field of characteristic `0`.
-/
namespace Polynomial
variable {R : Type*} [CommRing R] {n : β}
theorem isRoot_of_unity_of_root_cyclotomic {ΞΆ : R} {i : β} (hi : i β n.divisors)
(h : (cyclotomic i R).IsRoot ΞΆ) : ΞΆ ^ n = 1 := by
rcases n.eq_zero_or_pos with (rfl | hn)
Β· exact pow_zero _
have := congr_arg (eval ΞΆ) (prod_cyclotomic_eq_X_pow_sub_one hn R).symm
rw [eval_sub, eval_pow, eval_X, eval_one] at this
convert eq_add_of_sub_eq' this
convert (add_zero (M := R) _).symm
apply eval_eq_zero_of_dvd_of_eval_eq_zero _ h
exact Finset.dvd_prod_of_mem _ hi
section IsDomain
variable [IsDomain R]
theorem _root_.isRoot_of_unity_iff (h : 0 < n) (R : Type*) [CommRing R] [IsDomain R] {ΞΆ : R} :
ΞΆ ^ n = 1 β β i β n.divisors, (cyclotomic i R).IsRoot ΞΆ := by
rw [β mem_nthRoots h, nthRoots, mem_roots <| X_pow_sub_C_ne_zero h _, C_1, β
prod_cyclotomic_eq_X_pow_sub_one h, isRoot_prod]
/-- Any `n`-th primitive root of unity is a root of `cyclotomic n R`. -/
theorem _root_.IsPrimitiveRoot.isRoot_cyclotomic (hpos : 0 < n) {ΞΌ : R} (h : IsPrimitiveRoot ΞΌ n) :
IsRoot (cyclotomic n R) ΞΌ := by
rw [β mem_roots (cyclotomic_ne_zero n R), cyclotomic_eq_prod_X_sub_primitiveRoots h,
roots_prod_X_sub_C, β Finset.mem_def]
rwa [β mem_primitiveRoots hpos] at h
private theorem isRoot_cyclotomic_iff' {n : β} {K : Type*} [Field K] {ΞΌ : K} [NeZero (n : K)] :
IsRoot (cyclotomic n K) ΞΌ β IsPrimitiveRoot ΞΌ n := by
-- in this proof, `o` stands for `orderOf ΞΌ`
have hnpos : 0 < n := (NeZero.of_neZero_natCast K).out.bot_lt
refine β¨fun hΞΌ => ?_, IsPrimitiveRoot.isRoot_cyclotomic hnposβ©
have hΞΌn : ΞΌ ^ n = 1 := by
rw [isRoot_of_unity_iff hnpos _]
exact β¨n, n.mem_divisors_self hnpos.ne', hΞΌβ©
by_contra hnΞΌ
have ho : 0 < orderOf ΞΌ := (isOfFinOrder_iff_pow_eq_one.2 <| β¨n, hnpos, hΞΌnβ©).orderOf_pos
have := pow_orderOf_eq_one ΞΌ
rw [isRoot_of_unity_iff ho] at this
obtain β¨i, hio, hiΞΌβ© := this
replace hio := Nat.dvd_of_mem_divisors hio
rw [IsPrimitiveRoot.not_iff] at hnΞΌ
rw [β orderOf_dvd_iff_pow_eq_one] at hΞΌn
have key : i < n := (Nat.le_of_dvd ho hio).trans_lt ((Nat.le_of_dvd hnpos hΞΌn).lt_of_ne hnΞΌ)
have key' : i β£ n := hio.trans hΞΌn
rw [β Polynomial.dvd_iff_isRoot] at hΞΌ hiΞΌ
have hni : {i, n} β n.divisors := by simpa [Finset.insert_subset_iff, key'] using hnpos.ne'
obtain β¨k, hkβ© := hiΞΌ
obtain β¨j, hjβ© := hΞΌ
have := prod_cyclotomic_eq_X_pow_sub_one hnpos K
rw [β Finset.prod_sdiff hni, Finset.prod_pair key.ne, hk, hj] at this
have hn := (X_pow_sub_one_separable_iff.mpr <| NeZero.natCast_ne n K).squarefree
rw [β this, Squarefree] at hn
specialize hn (X - C ΞΌ) β¨(β x β n.divisors \ {i, n}, cyclotomic x K) * k * j, by ringβ©
simp [Polynomial.isUnit_iff_degree_eq_zero] at hn
theorem isRoot_cyclotomic_iff [NeZero (n : R)] {ΞΌ : R} :
IsRoot (cyclotomic n R) ΞΌ β IsPrimitiveRoot ΞΌ n := by
have hf : Function.Injective _ := IsFractionRing.injective R (FractionRing R)
haveI : NeZero (n : FractionRing R) := NeZero.nat_of_injective hf
rw [β isRoot_map_iff hf, β IsPrimitiveRoot.map_iff_of_injective hf, map_cyclotomic, β
isRoot_cyclotomic_iff']
theorem roots_cyclotomic_nodup [NeZero (n : R)] : (cyclotomic n R).roots.Nodup := by
obtain h | β¨ΞΆ, hΞΆβ© := (cyclotomic n R).roots.empty_or_exists_mem
Β· exact h.symm βΈ Multiset.nodup_zero
rw [mem_roots <| cyclotomic_ne_zero n R, isRoot_cyclotomic_iff] at hΞΆ
refine Multiset.nodup_of_le
(roots.le_of_dvd (X_pow_sub_C_ne_zero (NeZero.pos_of_neZero_natCast R) 1) <|
cyclotomic.dvd_X_pow_sub_one n R) hΞΆ.nthRoots_one_nodup
theorem cyclotomic.roots_to_finset_eq_primitiveRoots [NeZero (n : R)] :
(β¨(cyclotomic n R).roots, roots_cyclotomic_nodupβ© : Finset _) = primitiveRoots n R := by
ext a
-- Porting note: was
-- `simp [cyclotomic_ne_zero n R, isRoot_cyclotomic_iff, mem_primitiveRoots,`
-- ` NeZero.pos_of_neZero_natCast R]`
simp only [mem_primitiveRoots, NeZero.pos_of_neZero_natCast R]
convert isRoot_cyclotomic_iff (n := n) (ΞΌ := a) using 0
simp [cyclotomic_ne_zero n R]
theorem cyclotomic.roots_eq_primitiveRoots_val [NeZero (n : R)] :
(cyclotomic n R).roots = (primitiveRoots n R).val := by
rw [β cyclotomic.roots_to_finset_eq_primitiveRoots]
/-- If `R` is of characteristic zero, then `ΞΆ` is a root of `cyclotomic n R` if and only if it is a
primitive `n`-th root of unity. -/
theorem isRoot_cyclotomic_iff_charZero {n : β} {R : Type*} [CommRing R] [IsDomain R] [CharZero R]
{ΞΌ : R} (hn : 0 < n) : (Polynomial.cyclotomic n R).IsRoot ΞΌ β IsPrimitiveRoot ΞΌ n :=
| letI := NeZero.of_gt hn
isRoot_cyclotomic_iff
| Mathlib/RingTheory/Polynomial/Cyclotomic/Roots.lean | 127 | 129 |
/-
Copyright (c) 2020 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
-/
import Mathlib.Computability.Halting
import Mathlib.Computability.TuringMachine
import Mathlib.Data.Num.Lemmas
import Mathlib.Tactic.DeriveFintype
import Mathlib.Computability.TMConfig
/-!
# Modelling partial recursive functions using Turing machines
The files `TMConfig` and `TMToPartrec` define a simplified basis for partial recursive functions,
and a `Turing.TM2` model
Turing machine for evaluating these functions. This amounts to a constructive proof that every
`Partrec` function can be evaluated by a Turing machine.
## Main definitions
* `PartrecToTM2.tr`: A TM2 turing machine which can evaluate `code` programs
-/
open List (Vector)
open Function (update)
open Relation
namespace Turing
/-!
## Simulating sequentialized partial recursive functions in TM2
At this point we have a sequential model of partial recursive functions: the `Cfg` type and
`step : Cfg β Option Cfg` function from `TMConfig.lean`. The key feature of this model is that
it does a finite amount of computation (in fact, an amount which is statically bounded by the size
of the program) between each step, and no individual step can diverge (unlike the compositional
semantics, where every sub-part of the computation is potentially divergent). So we can utilize the
same techniques as in the other TM simulations in `Computability.TuringMachine` to prove that
each step corresponds to a finite number of steps in a lower level model. (We don't prove it here,
but in anticipation of the complexity class P, the simulation is actually polynomial-time as well.)
The target model is `Turing.TM2`, which has a fixed finite set of stacks, a bit of local storage,
with programs selected from a potentially infinite (but finitely accessible) set of program
positions, or labels `Ξ`, each of which executes a finite sequence of basic stack commands.
For this program we will need four stacks, each on an alphabet `Ξ'` like so:
inductive Ξ' | consβ | cons | bit0 | bit1
We represent a number as a bit sequence, lists of numbers by putting `cons` after each element, and
lists of lists of natural numbers by putting `consβ` after each list. For example:
0 ~> []
1 ~> [bit1]
6 ~> [bit0, bit1, bit1]
[1, 2] ~> [bit1, cons, bit0, bit1, cons]
[[], [1, 2]] ~> [consβ, bit1, cons, bit0, bit1, cons, consβ]
The four stacks are `main`, `rev`, `aux`, `stack`. In normal mode, `main` contains the input to the
current program (a `List β`) and `stack` contains data (a `List (List β)`) associated to the
current continuation, and in `ret` mode `main` contains the value that is being passed to the
continuation and `stack` contains the data for the continuation. The `rev` and `aux` stacks are
usually empty; `rev` is used to store reversed data when e.g. moving a value from one stack to
another, while `aux` is used as a temporary for a `main`/`stack` swap that happens during `consβ`
evaluation.
The only local store we need is `Option Ξ'`, which stores the result of the last pop
operation. (Most of our working data are natural numbers, which are too large to fit in the local
store.)
The continuations from the previous section are data-carrying, containing all the values that have
been computed and are awaiting other arguments. In order to have only a finite number of
continuations appear in the program so that they can be used in machine states, we separate the
data part (anything with type `List β`) from the `Cont` type, producing a `Cont'` type that lacks
this information. The data is kept on the `stack` stack.
Because we want to have subroutines for e.g. moving an entire stack to another place, we use an
infinite inductive type `Ξ'` so that we can execute a program and then return to do something else
without having to define too many different kinds of intermediate states. (We must nevertheless
prove that only finitely many labels are accessible.) The labels are:
* `move p kβ kβ q`: move elements from stack `kβ` to `kβ` while `p` holds of the value being moved.
The last element, that fails `p`, is placed in neither stack but left in the local store.
At the end of the operation, `kβ` will have the elements of `kβ` in reverse order. Then do `q`.
* `clear p k q`: delete elements from stack `k` until `p` is true. Like `move`, the last element is
left in the local storage. Then do `q`.
* `copy q`: Move all elements from `rev` to both `main` and `stack` (in reverse order),
then do `q`. That is, it takes `(a, b, c, d)` to `(b.reverse ++ a, [], c, b.reverse ++ d)`.
* `push k f q`: push `f s`, where `s` is the local store, to stack `k`, then do `q`. This is a
duplicate of the `push` instruction that is part of the TM2 model, but by having a subroutine
just for this purpose we can build up programs to execute inside a `goto` statement, where we
have the flexibility to be general recursive.
* `read (f : Option Ξ' β Ξ')`: go to state `f s` where `s` is the local store. Again this is only
here for convenience.
* `succ q`: perform a successor operation. Assuming `[n]` is encoded on `main` before,
`[n+1]` will be on main after. This implements successor for binary natural numbers.
* `pred qβ qβ`: perform a predecessor operation or `case` statement. If `[]` is encoded on
`main` before, then we transition to `qβ` with `[]` on main; if `(0 :: v)` is on `main` before
then `v` will be on `main` after and we transition to `qβ`; and if `(n+1 :: v)` is on `main`
before then `n :: v` will be on `main` after and we transition to `qβ`.
* `ret k`: call continuation `k`. Each continuation has its own interpretation of the data in
`stack` and sets up the data for the next continuation.
* `ret (consβ fs k)`: `v :: KData` on `stack` and `ns` on `main`, and the next step expects
`v` on `main` and `ns :: KData` on `stack`. So we have to do a little dance here with six
reverse-moves using the `aux` stack to perform a three-point swap, each of which involves two
reversals.
* `ret (consβ k)`: `ns :: KData` is on `stack` and `v` is on `main`, and we have to put
`ns.headI :: v` on `main` and `KData` on `stack`. This is done using the `head` subroutine.
* `ret (fix f k)`: This stores no data, so we just check if `main` starts with `0` and
if so, remove it and call `k`, otherwise `clear` the first value and call `f`.
* `ret halt`: the stack is empty, and `main` has the output. Do nothing and halt.
In addition to these basic states, we define some additional subroutines that are used in the
above:
* `push'`, `peek'`, `pop'` are special versions of the builtins that use the local store to supply
inputs and outputs.
* `unrev`: special case `move false rev main` to move everything from `rev` back to `main`. Used as
a cleanup operation in several functions.
* `moveExcl p kβ kβ q`: same as `move` but pushes the last value read back onto the source stack.
* `moveβ p kβ kβ q`: double `move`, so that the result comes out in the right order at the target
stack. Implemented as `moveExcl p k rev; move false rev kβ`. Assumes that neither `kβ` nor `kβ`
is `rev` and `rev` is initially empty.
* `head k q`: get the first natural number from stack `k` and reverse-move it to `rev`, then clear
the rest of the list at `k` and then `unrev` to reverse-move the head value to `main`. This is
used with `k = main` to implement regular `head`, i.e. if `v` is on `main` before then `[v.headI]`
will be on `main` after; and also with `k = stack` for the `cons` operation, which has `v` on
`main` and `ns :: KData` on `stack`, and results in `KData` on `stack` and `ns.headI :: v` on
`main`.
* `trNormal` is the main entry point, defining states that perform a given `code` computation.
It mostly just dispatches to functions written above.
The main theorem of this section is `tr_eval`, which asserts that for each that for each code `c`,
the state `init c v` steps to `halt v'` in finitely many steps if and only if
`Code.eval c v = some v'`.
-/
namespace PartrecToTM2
section
open ToPartrec
/-- The alphabet for the stacks in the program. `bit0` and `bit1` are used to represent `β` values
as lists of binary digits, `cons` is used to separate `List β` values, and `consβ` is used to
separate `List (List β)` values. See the section documentation. -/
inductive Ξ'
| consβ
| cons
| bit0
| bit1
deriving DecidableEq, Inhabited, Fintype
/-- The four stacks used by the program. `main` is used to store the input value in `trNormal`
mode and the output value in `Ξ'.ret` mode, while `stack` is used to keep all the data for the
continuations. `rev` is used to store reversed lists when transferring values between stacks, and
`aux` is only used once in `consβ`. See the section documentation. -/
inductive K'
| main
| rev
| aux
| stack
deriving DecidableEq, Inhabited
open K'
/-- Continuations as in `ToPartrec.Cont` but with the data removed. This is done because we want
the set of all continuations in the program to be finite (so that it can ultimately be encoded into
the finite state machine of a Turing machine), but a continuation can handle a potentially infinite
number of data values during execution. -/
inductive Cont'
| halt
| consβ : Code β Cont' β Cont'
| consβ : Cont' β Cont'
| comp : Code β Cont' β Cont'
| fix : Code β Cont' β Cont'
deriving DecidableEq, Inhabited
/-- The set of program positions. We make extensive use of inductive types here to let us describe
"subroutines"; for example `clear p k q` is a program that clears stack `k`, then does `q` where
`q` is another label. In order to prevent this from resulting in an infinite number of distinct
accessible states, we are careful to be non-recursive (although loops are okay). See the section
documentation for a description of all the programs. -/
inductive Ξ'
| move (p : Ξ' β Bool) (kβ kβ : K') (q : Ξ')
| clear (p : Ξ' β Bool) (k : K') (q : Ξ')
| copy (q : Ξ')
| push (k : K') (s : Option Ξ' β Option Ξ') (q : Ξ')
| read (f : Option Ξ' β Ξ')
| succ (q : Ξ')
| pred (qβ qβ : Ξ')
| ret (k : Cont')
compile_inductive% Code
compile_inductive% Cont'
compile_inductive% K'
compile_inductive% Ξ'
instance Ξ'.instInhabited : Inhabited Ξ' :=
β¨Ξ'.ret Cont'.haltβ©
instance Ξ'.instDecidableEq : DecidableEq Ξ' := fun a b => by
induction a generalizing b <;> cases b <;> first
| apply Decidable.isFalse; rintro β¨β¨β©β©; done
| exact decidable_of_iff' _ (by simp [funext_iff]; rfl)
/-- The type of TM2 statements used by this machine. -/
def Stmt' :=
TM2.Stmt (fun _ : K' => Ξ') Ξ' (Option Ξ') deriving Inhabited
/-- The type of TM2 configurations used by this machine. -/
def Cfg' :=
TM2.Cfg (fun _ : K' => Ξ') Ξ' (Option Ξ') deriving Inhabited
open TM2.Stmt
/-- A predicate that detects the end of a natural number, either `Ξ'.cons` or `Ξ'.consβ` (or
implicitly the end of the list), for use in predicate-taking functions like `move` and `clear`. -/
@[simp]
def natEnd : Ξ' β Bool
| Ξ'.consβ => true
| Ξ'.cons => true
| _ => false
attribute [nolint simpNF] natEnd.eq_3
/-- Pop a value from the stack and place the result in local store. -/
@[simp]
def pop' (k : K') : Stmt' β Stmt' :=
pop k fun _ v => v
/-- Peek a value from the stack and place the result in local store. -/
@[simp]
def peek' (k : K') : Stmt' β Stmt' :=
peek k fun _ v => v
/-- Push the value in the local store to the given stack. -/
@[simp]
def push' (k : K') : Stmt' β Stmt' :=
push k fun x => x.iget
/-- Move everything from the `rev` stack to the `main` stack (reversed). -/
def unrev :=
Ξ'.move (fun _ => false) rev main
/-- Move elements from `kβ` to `kβ` while `p` holds, with the last element being left on `kβ`. -/
def moveExcl (p kβ kβ q) :=
Ξ'.move p kβ kβ <| Ξ'.push kβ id q
/-- Move elements from `kβ` to `kβ` without reversion, by performing a double move via the `rev`
stack. -/
def moveβ (p kβ kβ q) :=
moveExcl p kβ rev <| Ξ'.move (fun _ => false) rev kβ q
/-- Assuming `trList v` is on the front of stack `k`, remove it, and push `v.headI` onto `main`.
See the section documentation. -/
def head (k : K') (q : Ξ') : Ξ' :=
Ξ'.move natEnd k rev <|
(Ξ'.push rev fun _ => some Ξ'.cons) <|
Ξ'.read fun s =>
(if s = some Ξ'.consβ then id else Ξ'.clear (fun x => x = Ξ'.consβ) k) <| unrev q
/-- The program that evaluates code `c` with continuation `k`. This expects an initial state where
`trList v` is on `main`, `trContStack k` is on `stack`, and `aux` and `rev` are empty.
See the section documentation for details. -/
@[simp]
def trNormal : Code β Cont' β Ξ'
| Code.zero', k => (Ξ'.push main fun _ => some Ξ'.cons) <| Ξ'.ret k
| Code.succ, k => head main <| Ξ'.succ <| Ξ'.ret k
| Code.tail, k => Ξ'.clear natEnd main <| Ξ'.ret k
| Code.cons f fs, k =>
(Ξ'.push stack fun _ => some Ξ'.consβ) <|
Ξ'.move (fun _ => false) main rev <| Ξ'.copy <| trNormal f (Cont'.consβ fs k)
| Code.comp f g, k => trNormal g (Cont'.comp f k)
| Code.case f g, k => Ξ'.pred (trNormal f k) (trNormal g k)
| Code.fix f, k => trNormal f (Cont'.fix f k)
/-- The main program. See the section documentation for details. -/
def tr : Ξ' β Stmt'
| Ξ'.move p kβ kβ q =>
pop' kβ <|
branch (fun s => s.elim true p) (goto fun _ => q)
(push' kβ <| goto fun _ => Ξ'.move p kβ kβ q)
| Ξ'.push k f q =>
branch (fun s => (f s).isSome) ((push k fun s => (f s).iget) <| goto fun _ => q)
(goto fun _ => q)
| Ξ'.read q => goto q
| Ξ'.clear p k q =>
pop' k <| branch (fun s => s.elim true p) (goto fun _ => q) (goto fun _ => Ξ'.clear p k q)
| Ξ'.copy q =>
pop' rev <|
branch Option.isSome (push' main <| push' stack <| goto fun _ => Ξ'.copy q) (goto fun _ => q)
| Ξ'.succ q =>
pop' main <|
branch (fun s => s = some Ξ'.bit1) ((push rev fun _ => Ξ'.bit0) <| goto fun _ => Ξ'.succ q) <|
branch (fun s => s = some Ξ'.cons)
((push main fun _ => Ξ'.cons) <| (push main fun _ => Ξ'.bit1) <| goto fun _ => unrev q)
((push main fun _ => Ξ'.bit1) <| goto fun _ => unrev q)
| Ξ'.pred qβ qβ =>
pop' main <|
branch (fun s => s = some Ξ'.bit0)
((push rev fun _ => Ξ'.bit1) <| goto fun _ => Ξ'.pred qβ qβ) <|
branch (fun s => natEnd s.iget) (goto fun _ => qβ)
(peek' main <|
branch (fun s => natEnd s.iget) (goto fun _ => unrev qβ)
((push rev fun _ => Ξ'.bit0) <| goto fun _ => unrev qβ))
| Ξ'.ret (Cont'.consβ fs k) =>
goto fun _ =>
moveβ (fun _ => false) main aux <|
moveβ (fun s => s = Ξ'.consβ) stack main <|
moveβ (fun _ => false) aux stack <| trNormal fs (Cont'.consβ k)
| Ξ'.ret (Cont'.consβ k) => goto fun _ => head stack <| Ξ'.ret k
| Ξ'.ret (Cont'.comp f k) => goto fun _ => trNormal f k
| Ξ'.ret (Cont'.fix f k) =>
pop' main <|
goto fun s =>
cond (natEnd s.iget) (Ξ'.ret k) <| Ξ'.clear natEnd main <| trNormal f (Cont'.fix f k)
| Ξ'.ret Cont'.halt => (load fun _ => none) <| halt
@[simp]
theorem tr_move (p kβ kβ q) : tr (Ξ'.move p kβ kβ q) =
pop' kβ (branch (fun s => s.elim true p) (goto fun _ => q)
(push' kβ <| goto fun _ => Ξ'.move p kβ kβ q)) := rfl
@[simp]
theorem tr_push (k f q) : tr (Ξ'.push k f q) = branch (fun s => (f s).isSome)
((push k fun s => (f s).iget) <| goto fun _ => q) (goto fun _ => q) := rfl
@[simp]
theorem tr_read (q) : tr (Ξ'.read q) = goto q := rfl
@[simp]
theorem tr_clear (p k q) : tr (Ξ'.clear p k q) = pop' k (branch
(fun s => s.elim true p) (goto fun _ => q) (goto fun _ => Ξ'.clear p k q)) := rfl
@[simp]
theorem tr_copy (q) : tr (Ξ'.copy q) = pop' rev (branch Option.isSome
(push' main <| push' stack <| goto fun _ => Ξ'.copy q) (goto fun _ => q)) := rfl
@[simp]
theorem tr_succ (q) : tr (Ξ'.succ q) = pop' main (branch (fun s => s = some Ξ'.bit1)
((push rev fun _ => Ξ'.bit0) <| goto fun _ => Ξ'.succ q) <|
branch (fun s => s = some Ξ'.cons)
((push main fun _ => Ξ'.cons) <| (push main fun _ => Ξ'.bit1) <| goto fun _ => unrev q)
((push main fun _ => Ξ'.bit1) <| goto fun _ => unrev q)) := rfl
@[simp]
theorem tr_pred (qβ qβ) : tr (Ξ'.pred qβ qβ) = pop' main (branch (fun s => s = some Ξ'.bit0)
((push rev fun _ => Ξ'.bit1) <| goto fun _ => Ξ'.pred qβ qβ) <|
branch (fun s => natEnd s.iget) (goto fun _ => qβ)
(peek' main <|
branch (fun s => natEnd s.iget) (goto fun _ => unrev qβ)
((push rev fun _ => Ξ'.bit0) <| goto fun _ => unrev qβ))) := rfl
@[simp]
theorem tr_ret_consβ (fs k) : tr (Ξ'.ret (Cont'.consβ fs k)) = goto fun _ =>
moveβ (fun _ => false) main aux <|
moveβ (fun s => s = Ξ'.consβ) stack main <|
moveβ (fun _ => false) aux stack <| trNormal fs (Cont'.consβ k) := rfl
@[simp]
theorem tr_ret_consβ (k) : tr (Ξ'.ret (Cont'.consβ k)) =
goto fun _ => head stack <| Ξ'.ret k := rfl
@[simp]
theorem tr_ret_comp (f k) : tr (Ξ'.ret (Cont'.comp f k)) = goto fun _ => trNormal f k := rfl
@[simp]
theorem tr_ret_fix (f k) : tr (Ξ'.ret (Cont'.fix f k)) = pop' main (goto fun s =>
cond (natEnd s.iget) (Ξ'.ret k) <| Ξ'.clear natEnd main <| trNormal f (Cont'.fix f k)) := rfl
@[simp]
theorem tr_ret_halt : tr (Ξ'.ret Cont'.halt) = (load fun _ => none) halt := rfl
/-- Translating a `Cont` continuation to a `Cont'` continuation simply entails dropping all the
data. This data is instead encoded in `trContStack` in the configuration. -/
def trCont : Cont β Cont'
| Cont.halt => Cont'.halt
| Cont.consβ c _ k => Cont'.consβ c (trCont k)
| Cont.consβ _ k => Cont'.consβ (trCont k)
| Cont.comp c k => Cont'.comp c (trCont k)
| Cont.fix c k => Cont'.fix c (trCont k)
/-- We use `PosNum` to define the translation of binary natural numbers. A natural number is
represented as a little-endian list of `bit0` and `bit1` elements:
1 = [bit1]
2 = [bit0, bit1]
3 = [bit1, bit1]
4 = [bit0, bit0, bit1]
In particular, this representation guarantees no trailing `bit0`'s at the end of the list. -/
def trPosNum : PosNum β List Ξ'
| PosNum.one => [Ξ'.bit1]
| PosNum.bit0 n => Ξ'.bit0 :: trPosNum n
| PosNum.bit1 n => Ξ'.bit1 :: trPosNum n
/-- We use `Num` to define the translation of binary natural numbers. Positive numbers are
translated using `trPosNum`, and `trNum 0 = []`. So there are never any trailing `bit0`'s in
a translated `Num`.
0 = []
1 = [bit1]
2 = [bit0, bit1]
3 = [bit1, bit1]
4 = [bit0, bit0, bit1]
-/
def trNum : Num β List Ξ'
| Num.zero => []
| Num.pos n => trPosNum n
/-- Because we use binary encoding, we define `trNat` in terms of `trNum`, using `Num`, which are
binary natural numbers. (We could also use `Nat.binaryRecOn`, but `Num` and `PosNum` make for
easy inductions.) -/
def trNat (n : β) : List Ξ' :=
trNum n
@[simp]
theorem trNat_zero : trNat 0 = [] := by rw [trNat, Nat.cast_zero]; rfl
theorem trNat_default : trNat default = [] :=
trNat_zero
/-- Lists are translated with a `cons` after each encoded number.
For example:
[] = []
[0] = [cons]
[1] = [bit1, cons]
[6, 0] = [bit0, bit1, bit1, cons, cons]
-/
@[simp]
def trList : List β β List Ξ'
| [] => []
| n::ns => trNat n ++ Ξ'.cons :: trList ns
/-- Lists of lists are translated with a `consβ` after each encoded list.
For example:
[] = []
[[]] = [consβ]
[[], []] = [consβ, consβ]
[[0]] = [cons, consβ]
[[1, 2], [0]] = [bit1, cons, bit0, bit1, cons, consβ, cons, consβ]
-/
@[simp]
def trLList : List (List β) β List Ξ'
| [] => []
| l::ls => trList l ++ Ξ'.consβ :: trLList ls
/-- The data part of a continuation is a list of lists, which is encoded on the `stack` stack
using `trLList`. -/
@[simp]
def contStack : Cont β List (List β)
| Cont.halt => []
| Cont.consβ _ ns k => ns :: contStack k
| Cont.consβ ns k => ns :: contStack k
| Cont.comp _ k => contStack k
| Cont.fix _ k => contStack k
/-- The data part of a continuation is a list of lists, which is encoded on the `stack` stack
using `trLList`. -/
def trContStack (k : Cont) :=
trLList (contStack k)
/-- This is the nondependent eliminator for `K'`, but we use it specifically here in order to
represent the stack data as four lists rather than as a function `K' β List Ξ'`, because this makes
rewrites easier. The theorems `K'.elim_update_main` et. al. show how such a function is updated
after an `update` to one of the components. -/
def K'.elim (a b c d : List Ξ') : K' β List Ξ'
| K'.main => a
| K'.rev => b
| K'.aux => c
| K'.stack => d
-- The equation lemma of `elim` simplifies to `match` structures.
theorem K'.elim_main (a b c d) : K'.elim a b c d K'.main = a := rfl
theorem K'.elim_rev (a b c d) : K'.elim a b c d K'.rev = b := rfl
theorem K'.elim_aux (a b c d) : K'.elim a b c d K'.aux = c := rfl
theorem K'.elim_stack (a b c d) : K'.elim a b c d K'.stack = d := rfl
attribute [simp] K'.elim
@[simp]
theorem K'.elim_update_main {a b c d a'} : update (K'.elim a b c d) main a' = K'.elim a' b c d := by
funext x; cases x <;> rfl
@[simp]
theorem K'.elim_update_rev {a b c d b'} : update (K'.elim a b c d) rev b' = K'.elim a b' c d := by
funext x; cases x <;> rfl
@[simp]
theorem K'.elim_update_aux {a b c d c'} : update (K'.elim a b c d) aux c' = K'.elim a b c' d := by
funext x; cases x <;> rfl
@[simp]
theorem K'.elim_update_stack {a b c d d'} :
update (K'.elim a b c d) stack d' = K'.elim a b c d' := by funext x; cases x <;> rfl
/-- The halting state corresponding to a `List β` output value. -/
def halt (v : List β) : Cfg' :=
β¨none, none, K'.elim (trList v) [] [] []β©
/-- The `Cfg` states map to `Cfg'` states almost one to one, except that in normal operation the
local store contains an arbitrary garbage value. To make the final theorem cleaner we explicitly
clear it in the halt state so that there is exactly one configuration corresponding to output `v`.
-/
def TrCfg : Cfg β Cfg' β Prop
| Cfg.ret k v, c' =>
β s, c' = β¨some (Ξ'.ret (trCont k)), s, K'.elim (trList v) [] [] (trContStack k)β©
| Cfg.halt v, c' => c' = halt v
/-- This could be a general list definition, but it is also somewhat specialized to this
application. `splitAtPred p L` will search `L` for the first element satisfying `p`.
If it is found, say `L = lβ ++ a :: lβ` where `a` satisfies `p` but `lβ` does not, then it returns
`(lβ, some a, lβ)`. Otherwise, if there is no such element, it returns `(L, none, [])`. -/
def splitAtPred {Ξ±} (p : Ξ± β Bool) : List Ξ± β List Ξ± Γ Option Ξ± Γ List Ξ±
| [] => ([], none, [])
| a :: as =>
cond (p a) ([], some a, as) <|
let β¨lβ, o, lββ© := splitAtPred p as
β¨a::lβ, o, lββ©
theorem splitAtPred_eq {Ξ±} (p : Ξ± β Bool) :
β L lβ o lβ,
(β x β lβ, p x = false) β
Option.elim' (L = lβ β§ lβ = []) (fun a => p a = true β§ L = lβ ++ a::lβ) o β
splitAtPred p L = (lβ, o, lβ)
| [], _, none, _, _, β¨rfl, rflβ© => rfl
| [], lβ, some o, lβ, _, β¨_, hββ© => by simp at hβ
| a :: L, lβ, o, lβ, hβ, hβ => by
rw [splitAtPred]
have IH := splitAtPred_eq p L
rcases o with - | o
Β· rcases lβ with - | β¨a', lββ© <;> rcases hβ with β¨β¨β©, rflβ©
rw [hβ a (List.Mem.head _), cond, IH L none [] _ β¨rfl, rflβ©]
exact fun x h => hβ x (List.Mem.tail _ h)
Β· rcases lβ with - | β¨a', lββ© <;> rcases hβ with β¨hβ, β¨β©β©
Β· rw [hβ, cond]
rw [hβ a (List.Mem.head _), cond, IH lβ (some o) lβ _ β¨hβ, _β©] <;> try rfl
exact fun x h => hβ x (List.Mem.tail _ h)
theorem splitAtPred_false {Ξ±} (L : List Ξ±) : splitAtPred (fun _ => false) L = (L, none, []) :=
splitAtPred_eq _ _ _ _ _ (fun _ _ => rfl) β¨rfl, rflβ©
theorem move_ok {p kβ kβ q s Lβ o Lβ} {S : K' β List Ξ'} (hβ : kβ β kβ)
(e : splitAtPred p (S kβ) = (Lβ, o, Lβ)) :
Reachesβ (TM2.step tr) β¨some (Ξ'.move p kβ kβ q), s, Sβ©
β¨some q, o, update (update S kβ Lβ) kβ (Lβ.reverseAux (S kβ))β© := by
induction' Lβ with a Lβ IH generalizing S s
Β· rw [(_ : [].reverseAux _ = _), Function.update_eq_self]
swap
Β· rw [Function.update_of_ne hβ.symm, List.reverseAux_nil]
refine TransGen.head' rfl ?_
rw [tr]; simp only [pop', TM2.stepAux]
revert e; rcases S kβ with - | β¨a, Skβ© <;> intro e
Β· cases e
rfl
simp only [splitAtPred, Option.elim, List.head?, List.tail_cons, Option.iget_some] at e β’
revert e; cases p a <;> intro e <;>
simp only [cond_false, cond_true, Prod.mk.injEq, true_and, false_and, reduceCtorEq] at e β’
simp only [e]
rfl
Β· refine TransGen.head rfl ?_
rw [tr]; simp only [pop', Option.elim, TM2.stepAux, push']
rcases eβ : S kβ with - | β¨a', Skβ© <;> rw [eβ, splitAtPred] at e
Β· cases e
cases eβ : p a' <;> simp only [eβ, cond] at e
swap
Β· cases e
rcases eβ : splitAtPred p Sk with β¨_, _, _β©
rw [eβ] at e
cases e
simp only [List.head?_cons, eβ, List.tail_cons, ne_eq, cond_false]
convert @IH _ (update (update S kβ Sk) kβ (a :: S kβ)) _ using 2 <;>
simp [Function.update_of_ne, hβ, hβ.symm, eβ, List.reverseAux]
simp [Function.update_comm hβ.symm]
theorem unrev_ok {q s} {S : K' β List Ξ'} :
Reachesβ (TM2.step tr) β¨some (unrev q), s, Sβ©
β¨some q, none, update (update S rev []) main (List.reverseAux (S rev) (S main))β© :=
move_ok (by decide) <| splitAtPred_false _
theorem moveβ_ok {p kβ kβ q s Lβ o Lβ} {S : K' β List Ξ'} (hβ : kβ β rev β§ kβ β rev β§ kβ β kβ)
(hβ : S rev = []) (e : splitAtPred p (S kβ) = (Lβ, o, Lβ)) :
Reachesβ (TM2.step tr) β¨some (moveβ p kβ kβ q), s, Sβ©
β¨some q, none, update (update S kβ (o.elim id List.cons Lβ)) kβ (Lβ ++ S kβ)β© := by
refine (move_ok hβ.1 e).trans (TransGen.head rfl ?_)
simp only [TM2.step, Option.mem_def, TM2.stepAux, id_eq, ne_eq, Option.elim]
cases o <;> simp only [Option.elim] <;> rw [tr]
<;> simp only [id, TM2.stepAux, Option.isSome, cond_true, cond_false]
Β· convert move_ok hβ.2.1.symm (splitAtPred_false _) using 2
simp only [Function.update_comm hβ.1, Function.update_idem]
rw [show update S rev [] = S by rw [β hβ, Function.update_eq_self]]
simp only [Function.update_of_ne hβ.2.2.symm, Function.update_of_ne hβ.2.1,
Function.update_of_ne hβ.1.symm, List.reverseAux_eq, hβ, Function.update_self,
List.append_nil, List.reverse_reverse]
Β· convert move_ok hβ.2.1.symm (splitAtPred_false _) using 2
simp only [hβ, Function.update_comm hβ.1, List.reverseAux_eq, Function.update_self,
List.append_nil, Function.update_idem]
rw [show update S rev [] = S by rw [β hβ, Function.update_eq_self]]
simp only [Function.update_of_ne hβ.1.symm, Function.update_of_ne hβ.2.2.symm,
Function.update_of_ne hβ.2.1, Function.update_self, List.reverse_reverse]
theorem clear_ok {p k q s Lβ o Lβ} {S : K' β List Ξ'} (e : splitAtPred p (S k) = (Lβ, o, Lβ)) :
Reachesβ (TM2.step tr) β¨some (Ξ'.clear p k q), s, Sβ© β¨some q, o, update S k Lββ© := by
induction' Lβ with a Lβ IH generalizing S s
Β· refine TransGen.head' rfl ?_
rw [tr]; simp only [pop', TM2.step, Option.mem_def, TM2.stepAux, Option.elim]
revert e; rcases S k with - | β¨a, Skβ© <;> intro e
Β· cases e
rfl
simp only [splitAtPred, Option.elim, List.head?, List.tail_cons] at e β’
revert e; cases p a <;> intro e <;>
simp only [cond_false, cond_true, Prod.mk.injEq, true_and, false_and, reduceCtorEq] at e β’
rcases e with β¨eβ, eββ©
rw [eβ, eβ]
Β· refine TransGen.head rfl ?_
rw [tr]; simp only [pop', TM2.step, Option.mem_def, TM2.stepAux, Option.elim]
rcases eβ : S k with - | β¨a', Skβ© <;> rw [eβ, splitAtPred] at e
Β· cases e
cases eβ : p a' <;> simp only [eβ, cond] at e
swap
Β· cases e
rcases eβ : splitAtPred p Sk with β¨_, _, _β©
rw [eβ] at e
cases e
simp only [List.head?_cons, eβ, List.tail_cons, cond_false]
convert @IH _ (update S k Sk) _ using 2 <;> simp [eβ]
theorem copy_ok (q s a b c d) :
Reachesβ (TM2.step tr) β¨some (Ξ'.copy q), s, K'.elim a b c dβ©
β¨some q, none, K'.elim (List.reverseAux b a) [] c (List.reverseAux b d)β© := by
induction' b with x b IH generalizing a d s
Β· refine TransGen.single ?_
simp
refine TransGen.head rfl ?_
rw [tr]
simp only [TM2.step, Option.mem_def, TM2.stepAux, elim_rev, List.head?_cons, Option.isSome_some,
List.tail_cons, elim_update_rev, ne_eq, Function.update_of_ne, elim_main, elim_update_main,
elim_stack, elim_update_stack, cond_true, List.reverseAux_cons, pop', push']
exact IH _ _ _
theorem trPosNum_natEnd : β (n), β x β trPosNum n, natEnd x = false
| PosNum.one, _, List.Mem.head _ => rfl
| PosNum.bit0 _, _, List.Mem.head _ => rfl
| PosNum.bit0 n, _, List.Mem.tail _ h => trPosNum_natEnd n _ h
| PosNum.bit1 _, _, List.Mem.head _ => rfl
| PosNum.bit1 n, _, List.Mem.tail _ h => trPosNum_natEnd n _ h
theorem trNum_natEnd : β (n), β x β trNum n, natEnd x = false
| Num.pos n, x, h => trPosNum_natEnd n x h
theorem trNat_natEnd (n) : β x β trNat n, natEnd x = false :=
trNum_natEnd _
theorem trList_ne_consβ : β (l), β x β trList l, x β Ξ'.consβ
| a :: l, x, h => by
simp only [trList, List.mem_append, List.mem_cons] at h
obtain h | rfl | h := h
Β· rintro rfl
cases trNat_natEnd _ _ h
Β· rintro β¨β©
Β· exact trList_ne_consβ l _ h
theorem head_main_ok {q s L} {c d : List Ξ'} :
Reachesβ (TM2.step tr) β¨some (head main q), s, K'.elim (trList L) [] c dβ©
β¨some q, none, K'.elim (trList [L.headI]) [] c dβ© := by
let o : Option Ξ' := List.casesOn L none fun _ _ => some Ξ'.cons
refine
(move_ok (by decide)
(splitAtPred_eq _ _ (trNat L.headI) o (trList L.tail) (trNat_natEnd _) ?_)).trans
(TransGen.head rfl (TransGen.head rfl ?_))
Β· cases L <;> simp [o]
rw [tr]
simp only [TM2.step, Option.mem_def, TM2.stepAux, elim_update_main, elim_rev, elim_update_rev,
Function.update_self, trList]
rw [if_neg (show o β some Ξ'.consβ by cases L <;> simp [o])]
refine (clear_ok (splitAtPred_eq _ _ _ none [] ?_ β¨rfl, rflβ©)).trans ?_
Β· exact fun x h => Bool.decide_false (trList_ne_consβ _ _ h)
convert unrev_ok using 2; simp [List.reverseAux_eq]
theorem head_stack_ok {q s Lβ Lβ Lβ} :
Reachesβ (TM2.step tr)
β¨some (head stack q), s, K'.elim (trList Lβ) [] [] (trList Lβ ++ Ξ'.consβ :: Lβ)β©
β¨some q, none, K'.elim (trList (Lβ.headI :: Lβ)) [] [] Lββ© := by
rcases Lβ with - | β¨a, Lββ©
Β· refine
TransGen.trans
(move_ok (by decide)
(splitAtPred_eq _ _ [] (some Ξ'.consβ) Lβ (by rintro _ β¨β©) β¨rfl, rflβ©))
(TransGen.head rfl (TransGen.head rfl ?_))
rw [tr]
simp only [TM2.step, Option.mem_def, TM2.stepAux, ite_true, id_eq, trList, List.nil_append,
elim_update_stack, elim_rev, List.reverseAux_nil, elim_update_rev, Function.update_self,
List.headI_nil, trNat_default]
convert unrev_ok using 2
simp
Β· refine
TransGen.trans
(move_ok (by decide)
(splitAtPred_eq _ _ (trNat a) (some Ξ'.cons) (trList Lβ ++ Ξ'.consβ :: Lβ)
(trNat_natEnd _) β¨rfl, by simpβ©))
(TransGen.head rfl (TransGen.head rfl ?_))
simp only [TM2.step, Option.mem_def, TM2.stepAux, ite_false, trList, List.append_assoc,
List.cons_append, elim_update_stack, elim_rev, elim_update_rev, Function.update_self,
List.headI_cons]
refine
TransGen.trans
(clear_ok
(splitAtPred_eq _ _ (trList Lβ) (some Ξ'.consβ) Lβ
(fun x h => Bool.decide_false (trList_ne_consβ _ _ h)) β¨rfl, by simpβ©))
?_
convert unrev_ok using 2
simp [List.reverseAux_eq]
theorem succ_ok {q s n} {c d : List Ξ'} :
Reachesβ (TM2.step tr) β¨some (Ξ'.succ q), s, K'.elim (trList [n]) [] c dβ©
β¨some q, none, K'.elim (trList [n.succ]) [] c dβ© := by
simp only [TM2.step, trList, trNat.eq_1, Nat.cast_succ, Num.add_one]
rcases (n : Num) with - | a
Β· refine TransGen.head rfl ?_
simp only [Option.mem_def, TM2.stepAux, elim_main, decide_false, elim_update_main, ne_eq,
Function.update_of_ne, elim_rev, elim_update_rev, decide_true, Function.update_self,
cond_true, cond_false]
convert unrev_ok using 1
simp only [elim_update_rev, elim_rev, elim_main, List.reverseAux_nil, elim_update_main]
rfl
simp only [trNum, Num.succ, Num.succ']
suffices β lβ, β lβ' lβ' s',
List.reverseAux lβ (trPosNum a.succ) = List.reverseAux lβ' lβ' β§
Reachesβ (TM2.step tr) β¨some q.succ, s, K'.elim (trPosNum a ++ [Ξ'.cons]) lβ c dβ©
β¨some (unrev q), s', K'.elim (lβ' ++ [Ξ'.cons]) lβ' c dβ© by
obtain β¨lβ', lβ', s', e, hβ© := this []
simp? [List.reverseAux] at e says simp only [List.reverseAux, List.reverseAux_eq] at e
refine h.trans ?_
convert unrev_ok using 2
simp [e, List.reverseAux_eq]
induction' a with m IH m _ generalizing s <;> intro lβ
Β· refine β¨Ξ'.bit0 :: lβ, [Ξ'.bit1], some Ξ'.cons, rfl, TransGen.head rfl (TransGen.single ?_)β©
simp [trPosNum]
Β· obtain β¨lβ', lβ', s', e, hβ© := IH (Ξ'.bit0 :: lβ)
refine β¨lβ', lβ', s', e, TransGen.head ?_ hβ©
simp [PosNum.succ, trPosNum]
rfl
Β· refine β¨lβ, _, some Ξ'.bit0, rfl, TransGen.single ?_β©
simp only [TM2.step]; rw [tr]
simp only [TM2.stepAux, pop', elim_main, elim_update_main, ne_eq, Function.update_of_ne,
elim_rev, elim_update_rev, Function.update_self, Option.mem_def, Option.some.injEq]
rfl
theorem pred_ok (qβ qβ s v) (c d : List Ξ') : β s',
Reachesβ (TM2.step tr) β¨some (Ξ'.pred qβ qβ), s, K'.elim (trList v) [] c dβ©
(v.headI.rec β¨some qβ, s', K'.elim (trList v.tail) [] c dβ© fun n _ =>
β¨some qβ, s', K'.elim (trList (n::v.tail)) [] c dβ©) := by
rcases v with (_ | β¨_ | n, vβ©)
Β· refine β¨none, TransGen.single ?_β©
simp
Β· refine β¨some Ξ'.cons, TransGen.single ?_β©
simp
refine β¨none, ?_β©
simp only [TM2.step, trList, trNat.eq_1, trNum, Nat.cast_succ, Num.add_one, Num.succ,
List.tail_cons, List.headI_cons]
rcases (n : Num) with - | a
Β· simp only [trPosNum, Num.succ', List.singleton_append, List.nil_append]
refine TransGen.head rfl ?_
rw [tr]; simp only [pop', TM2.stepAux, cond_false]
convert unrev_ok using 2
simp
simp only [Num.succ']
suffices β lβ, β lβ' lβ' s',
List.reverseAux lβ (trPosNum a) = List.reverseAux lβ' lβ' β§
Reachesβ (TM2.step tr)
β¨some (qβ.pred qβ), s, K'.elim (trPosNum a.succ ++ Ξ'.cons :: trList v) lβ c dβ©
β¨some (unrev qβ), s', K'.elim (lβ' ++ Ξ'.cons :: trList v) lβ' c dβ© by
obtain β¨lβ', lβ', s', e, hβ© := this []
simp only [List.reverseAux] at e
refine h.trans ?_
convert unrev_ok using 2
simp [e, List.reverseAux_eq]
induction' a with m IH m IH generalizing s <;> intro lβ
Β· refine β¨Ξ'.bit1::lβ, [], some Ξ'.cons, rfl, TransGen.head rfl (TransGen.single ?_)β©
simp [trPosNum, show PosNum.one.succ = PosNum.one.bit0 from rfl]
Β· obtain β¨lβ', lβ', s', e, hβ© := IH (some Ξ'.bit0) (Ξ'.bit1 :: lβ)
refine β¨lβ', lβ', s', e, TransGen.head ?_ hβ©
simp
rfl
Β· obtain β¨a, l, e, hβ© : β a l, (trPosNum m = a::l) β§ natEnd a = false := by
cases m <;> refine β¨_, _, rfl, rflβ©
refine β¨Ξ'.bit0 :: lβ, _, some a, rfl, TransGen.single ?_β©
simp [trPosNum, PosNum.succ, e, h, show some Ξ'.bit1 β some Ξ'.bit0 by decide,
Option.iget, -natEnd]
rfl
theorem trNormal_respects (c k v s) :
β bβ,
TrCfg (stepNormal c k v) bβ β§
Reachesβ (TM2.step tr)
β¨some (trNormal c (trCont k)), s, K'.elim (trList v) [] [] (trContStack k)β© bβ := by
induction c generalizing k v s with
| zero' => refine β¨_, β¨s, rflβ©, TransGen.single ?_β©; simp
| succ => refine β¨_, β¨none, rflβ©, head_main_ok.trans succ_okβ©
| tail =>
let o : Option Ξ' := List.casesOn v none fun _ _ => some Ξ'.cons
refine β¨_, β¨o, rflβ©, ?_β©; convert clear_ok _ using 2
Β· simp; rfl
swap
refine splitAtPred_eq _ _ (trNat v.headI) _ _ (trNat_natEnd _) ?_
cases v <;> simp [o]
| cons f fs IHf _ =>
obtain β¨c, hβ, hββ© := IHf (Cont.consβ fs v k) v none
refine β¨c, hβ, TransGen.head rfl <| (move_ok (by decide) (splitAtPred_false _)).trans ?_β©
simp only [TM2.step, Option.mem_def, elim_stack, elim_update_stack, elim_update_main, ne_eq,
Function.update_of_ne, elim_main, elim_rev, elim_update_rev]
refine (copy_ok _ none [] (trList v).reverse _ _).trans ?_
convert hβ using 2
simp [List.reverseAux_eq, trContStack]
| comp f _ _ IHg => exact IHg (Cont.comp f k) v s
| case f g IHf IHg =>
rw [stepNormal]
simp only
obtain β¨s', hβ© := pred_ok _ _ s v _ _
revert h; rcases v.headI with - | n <;> intro h
Β· obtain β¨c, hβ, hββ© := IHf k _ s'
exact β¨_, hβ, h.trans hββ©
Β· obtain β¨c, hβ, hββ© := IHg k _ s'
exact β¨_, hβ, h.trans hββ©
| fix f IH => apply IH
theorem tr_ret_respects (k v s) : β bβ,
TrCfg (stepRet k v) bβ β§
Reachesβ (TM2.step tr)
β¨some (Ξ'.ret (trCont k)), s, K'.elim (trList v) [] [] (trContStack k)β© bβ := by
induction k generalizing v s with
| halt => exact β¨_, rfl, TransGen.single rflβ©
| consβ fs as k _ =>
obtain β¨s', hβ, hββ© := trNormal_respects fs (Cont.consβ v k) as none
refine β¨s', hβ, TransGen.head rfl ?_β©; simp
refine (moveβ_ok (by decide) ?_ (splitAtPred_false _)).trans ?_; Β· rfl
simp only [TM2.step, Option.mem_def, Option.elim, id_eq, elim_update_main, elim_main, elim_aux,
List.append_nil, elim_update_aux]
refine (moveβ_ok (Lβ := ?_) (o := ?_) (Lβ := ?_) (by decide) rfl ?_).trans ?_
pick_goal 4
Β· exact splitAtPred_eq _ _ _ (some Ξ'.consβ) _
(fun x h => Bool.decide_false (trList_ne_consβ _ _ h)) β¨rfl, rflβ©
refine (moveβ_ok (by decide) ?_ (splitAtPred_false _)).trans ?_; Β· rfl
simp only [TM2.step, Option.mem_def, Option.elim, elim_update_stack, elim_main,
List.append_nil, elim_update_main, id_eq, elim_update_aux, ne_eq, Function.update_of_ne,
elim_aux, elim_stack]
exact hβ
| consβ ns k IH =>
obtain β¨c, hβ, hββ© := IH (ns.headI :: v) none
exact β¨c, hβ, TransGen.head rfl <| head_stack_ok.trans hββ©
| comp f k _ =>
obtain β¨s', hβ, hββ© := trNormal_respects f k v s
exact β¨_, hβ, TransGen.head rfl hββ©
| fix f k IH =>
rw [stepRet]
have :
if v.headI = 0 then natEnd (trList v).head?.iget = true β§ (trList v).tail = trList v.tail
else
natEnd (trList v).head?.iget = false β§
(trList v).tail = (trNat v.headI).tail ++ Ξ'.cons :: trList v.tail := by
obtain - | n := v
Β· exact β¨rfl, rflβ©
rcases n with - | n
Β· simp
rw [trList, List.headI, trNat, Nat.cast_succ, Num.add_one, Num.succ, List.tail]
cases (n : Num).succ' <;> exact β¨rfl, rflβ©
by_cases h : v.headI = 0 <;> simp only [h, ite_true, ite_false] at this β’
Β· obtain β¨c, hβ, hββ© := IH v.tail (trList v).head?
refine β¨c, hβ, TransGen.head rfl ?_β©
rw [trCont, tr]; simp only [pop', TM2.stepAux, elim_main, this, elim_update_main]
exact hβ
Β· obtain β¨s', hβ, hββ© := trNormal_respects f (Cont.fix f k) v.tail (some Ξ'.cons)
refine β¨_, hβ, TransGen.head rfl <| TransGen.trans ?_ hββ©
rw [trCont, tr]; simp only [pop', TM2.stepAux, elim_main, this.1]
convert clear_ok (splitAtPred_eq _ _ (trNat v.headI).tail (some Ξ'.cons) _ _ _) using 2
Β· simp
convert rfl
Β· exact fun x h => trNat_natEnd _ _ (List.tail_subset _ h)
Β· exact β¨rfl, this.2β©
theorem tr_respects : Respects step (TM2.step tr) TrCfg
| Cfg.ret _ _, _, β¨_, rflβ© => tr_ret_respects _ _ _
| Cfg.halt _, _, rfl => rfl
/-- The initial state, evaluating function `c` on input `v`. -/
def init (c : Code) (v : List β) : Cfg' :=
β¨some (trNormal c Cont'.halt), none, K'.elim (trList v) [] [] []β©
theorem tr_init (c v) :
β b, TrCfg (stepNormal c Cont.halt v) b β§ Reachesβ (TM2.step tr) (init c v) b :=
trNormal_respects _ _ _ _
theorem tr_eval (c v) : eval (TM2.step tr) (init c v) = halt <$> Code.eval c v := by
obtain β¨i, hβ, hββ© := tr_init c v
refine Part.ext fun x => ?_
rw [reaches_eval hβ.to_reflTransGen]; simp only [Part.map_eq_map, Part.mem_map_iff]
refine β¨fun h => ?_, ?_β©
Β· obtain β¨c, hcβ, hcββ© := tr_eval_rev tr_respects hβ h
simp [stepNormal_eval] at hcβ
obtain β¨v', hv, rflβ© := hcβ
exact β¨_, hv, hcβ.symmβ©
Β· rintro β¨v', hv, rflβ©
have := Turing.tr_eval (bβ := Cfg.halt v') tr_respects hβ
simp only [stepNormal_eval, Part.map_eq_map, Part.mem_map_iff, Cfg.halt.injEq,
exists_eq_right] at this
obtain β¨_, β¨β©, hβ© := this hv
exact h
/-- The set of machine states reachable via downward label jumps, discounting jumps via `ret`. -/
def trStmtsβ : Ξ' β Finset Ξ'
| Q@(Ξ'.move _ _ _ q) => insert Q <| trStmtsβ q
| Q@(Ξ'.push _ _ q) => insert Q <| trStmtsβ q
| Q@(Ξ'.read q) => insert Q <| Finset.univ.biUnion fun s => trStmtsβ (q s)
| Q@(Ξ'.clear _ _ q) => insert Q <| trStmtsβ q
| Q@(Ξ'.copy q) => insert Q <| trStmtsβ q
| Q@(Ξ'.succ q) => insert Q <| insert (unrev q) <| trStmtsβ q
| Q@(Ξ'.pred qβ qβ) => insert Q <| trStmtsβ qβ βͺ insert (unrev qβ) (trStmtsβ qβ)
| Q@(Ξ'.ret _) => {Q}
theorem trStmtsβ_trans {q q'} : q' β trStmtsβ q β trStmtsβ q' β trStmtsβ q := by
induction q with
| move _ _ _ q q_ih => _ | clear _ _ q q_ih => _ | copy q q_ih => _ | push _ _ q q_ih => _
| read q q_ih => _ | succ q q_ih => _ | pred qβ qβ qβ_ih qβ_ih => _ | ret => _ <;>
all_goals
simp +contextual only [trStmtsβ, Finset.mem_insert, Finset.mem_union,
or_imp, Finset.mem_singleton, Finset.Subset.refl, imp_true_iff, true_and]
repeat exact fun h => Finset.Subset.trans (q_ih h) (Finset.subset_insert _ _)
Β· simp
intro s h x h'
simp only [Finset.mem_biUnion, Finset.mem_univ, true_and, Finset.mem_insert]
exact Or.inr β¨_, q_ih s h h'β©
Β· constructor
Β· rintro rfl
apply Finset.subset_insert
Β· intro h x h'
simp only [Finset.mem_insert]
exact Or.inr (Or.inr <| q_ih h h')
Β· refine β¨fun h x h' => ?_, fun _ x h' => ?_, fun h x h' => ?_β© <;> simp
Β· exact Or.inr (Or.inr <| Or.inl <| qβ_ih h h')
Β· rcases Finset.mem_insert.1 h' with h' | h' <;> simp [h', unrev]
Β· exact Or.inr (Or.inr <| Or.inr <| qβ_ih h h')
theorem trStmtsβ_self (q) : q β trStmtsβ q := by
induction q <;> Β· first |apply Finset.mem_singleton_self|apply Finset.mem_insert_self
/-- The (finite!) set of machine states visited during the course of evaluation of `c`,
including the state `ret k` but not any states after that (that is, the states visited while
evaluating `k`). -/
def codeSupp' : Code β Cont' β Finset Ξ'
| c@Code.zero', k => trStmtsβ (trNormal c k)
| c@Code.succ, k => trStmtsβ (trNormal c k)
| c@Code.tail, k => trStmtsβ (trNormal c k)
| c@(Code.cons f fs), k =>
trStmtsβ (trNormal c k) βͺ
(codeSupp' f (Cont'.consβ fs k) βͺ
(trStmtsβ
(moveβ (fun _ => false) main aux <|
moveβ (fun s => s = Ξ'.consβ) stack main <|
moveβ (fun _ => false) aux stack <| trNormal fs (Cont'.consβ k)) βͺ
(codeSupp' fs (Cont'.consβ k) βͺ trStmtsβ (head stack <| Ξ'.ret k))))
| c@(Code.comp f g), k =>
trStmtsβ (trNormal c k) βͺ
(codeSupp' g (Cont'.comp f k) βͺ (trStmtsβ (trNormal f k) βͺ codeSupp' f k))
| c@(Code.case f g), k => trStmtsβ (trNormal c k) βͺ (codeSupp' f k βͺ codeSupp' g k)
| c@(Code.fix f), k =>
trStmtsβ (trNormal c k) βͺ
(codeSupp' f (Cont'.fix f k) βͺ
(trStmtsβ (Ξ'.clear natEnd main <| trNormal f (Cont'.fix f k)) βͺ {Ξ'.ret k}))
@[simp]
theorem codeSupp'_self (c k) : trStmtsβ (trNormal c k) β codeSupp' c k := by
cases c <;> first | rfl | exact Finset.union_subset_left (fun _ a β¦ a)
/-- The (finite!) set of machine states visited during the course of evaluation of a continuation
`k`, not including the initial state `ret k`. -/
def contSupp : Cont' β Finset Ξ'
| Cont'.consβ fs k =>
trStmtsβ
(moveβ (fun _ => false) main aux <|
moveβ (fun s => s = Ξ'.consβ) stack main <|
moveβ (fun _ => false) aux stack <| trNormal fs (Cont'.consβ k)) βͺ
(codeSupp' fs (Cont'.consβ k) βͺ (trStmtsβ (head stack <| Ξ'.ret k) βͺ contSupp k))
| Cont'.consβ k => trStmtsβ (head stack <| Ξ'.ret k) βͺ contSupp k
| Cont'.comp f k => codeSupp' f k βͺ contSupp k
| Cont'.fix f k => codeSupp' (Code.fix f) k βͺ contSupp k
| Cont'.halt => β
/-- The (finite!) set of machine states visited during the course of evaluation of `c` in
continuation `k`. This is actually closed under forward simulation (see `tr_supports`), and the
existence of this set means that the machine constructed in this section is in fact a proper
Turing machine, with a finite set of states. -/
def codeSupp (c : Code) (k : Cont') : Finset Ξ' :=
codeSupp' c k βͺ contSupp k
@[simp]
theorem codeSupp_self (c k) : trStmtsβ (trNormal c k) β codeSupp c k :=
Finset.Subset.trans (codeSupp'_self _ _) (Finset.union_subset_left fun _ a β¦ a)
@[simp]
theorem codeSupp_zero (k) : codeSupp Code.zero' k = trStmtsβ (trNormal Code.zero' k) βͺ contSupp k :=
rfl
@[simp]
theorem codeSupp_succ (k) : codeSupp Code.succ k = trStmtsβ (trNormal Code.succ k) βͺ contSupp k :=
rfl
@[simp]
theorem codeSupp_tail (k) : codeSupp Code.tail k = trStmtsβ (trNormal Code.tail k) βͺ contSupp k :=
rfl
@[simp]
theorem codeSupp_cons (f fs k) :
codeSupp (Code.cons f fs) k =
trStmtsβ (trNormal (Code.cons f fs) k) βͺ codeSupp f (Cont'.consβ fs k) := by
simp [codeSupp, codeSupp', contSupp, Finset.union_assoc]
@[simp]
theorem codeSupp_comp (f g k) :
codeSupp (Code.comp f g) k =
trStmtsβ (trNormal (Code.comp f g) k) βͺ codeSupp g (Cont'.comp f k) := by
simp only [codeSupp, codeSupp', trNormal, Finset.union_assoc, contSupp]
rw [β Finset.union_assoc _ _ (contSupp k),
Finset.union_eq_right.2 (codeSupp'_self _ _)]
@[simp]
theorem codeSupp_case (f g k) :
codeSupp (Code.case f g) k =
trStmtsβ (trNormal (Code.case f g) k) βͺ (codeSupp f k βͺ codeSupp g k) := by
simp [codeSupp, codeSupp', contSupp, Finset.union_assoc, Finset.union_left_comm]
@[simp]
theorem codeSupp_fix (f k) :
codeSupp (Code.fix f) k = trStmtsβ (trNormal (Code.fix f) k) βͺ codeSupp f (Cont'.fix f k) := by
simp [codeSupp, codeSupp', contSupp, Finset.union_assoc, Finset.union_left_comm,
Finset.union_left_idem]
@[simp]
theorem contSupp_consβ (fs k) :
contSupp (Cont'.consβ fs k) =
trStmtsβ
(moveβ (fun _ => false) main aux <|
moveβ (fun s => s = Ξ'.consβ) stack main <|
moveβ (fun _ => false) aux stack <| trNormal fs (Cont'.consβ k)) βͺ
codeSupp fs (Cont'.consβ k) := by
simp [codeSupp, codeSupp', contSupp, Finset.union_assoc]
@[simp]
theorem contSupp_consβ (k) :
contSupp (Cont'.consβ k) = trStmtsβ (head stack <| Ξ'.ret k) βͺ contSupp k :=
rfl
@[simp]
theorem contSupp_comp (f k) : contSupp (Cont'.comp f k) = codeSupp f k :=
rfl
theorem contSupp_fix (f k) : contSupp (Cont'.fix f k) = codeSupp f (Cont'.fix f k) := by
simp +contextual [codeSupp, codeSupp', contSupp, Finset.union_assoc,
Finset.subset_iff]
@[simp]
theorem contSupp_halt : contSupp Cont'.halt = β
:=
rfl
/-- The statement `Ξ'.Supports S q` means that `contSupp k β S` for any `ret k`
reachable from `q`.
(This is a technical condition used in the proof that the machine is supported.) -/
def Ξ'.Supports (S : Finset Ξ') : Ξ' β Prop
| Ξ'.move _ _ _ q => Ξ'.Supports S q
| Ξ'.push _ _ q => Ξ'.Supports S q
| Ξ'.read q => β s, Ξ'.Supports S (q s)
| Ξ'.clear _ _ q => Ξ'.Supports S q
| Ξ'.copy q => Ξ'.Supports S q
| Ξ'.succ q => Ξ'.Supports S q
| Ξ'.pred qβ qβ => Ξ'.Supports S qβ β§ Ξ'.Supports S qβ
| Ξ'.ret k => contSupp k β S
/-- A shorthand for the predicate that we are proving in the main theorems `trStmtsβ_supports`,
`codeSupp'_supports`, `contSupp_supports`, `codeSupp_supports`. The set `S` is fixed throughout
the proof, and denotes the full set of states in the machine, while `K` is a subset that we are
currently proving a property about. The predicate asserts that every state in `K` is closed in `S`
under forward simulation, i.e. stepping forward through evaluation starting from any state in `K`
stays entirely within `S`. -/
def Supports (K S : Finset Ξ') :=
β q β K, TM2.SupportsStmt S (tr q)
theorem supports_insert {K S q} :
Supports (insert q K) S β TM2.SupportsStmt S (tr q) β§ Supports K S := by simp [Supports]
theorem supports_singleton {S q} : Supports {q} S β TM2.SupportsStmt S (tr q) := by simp [Supports]
theorem supports_union {Kβ Kβ S} : Supports (Kβ βͺ Kβ) S β Supports Kβ S β§ Supports Kβ S := by
simp [Supports, or_imp, forall_and]
theorem supports_biUnion {K : Option Ξ' β Finset Ξ'} {S} :
Supports (Finset.univ.biUnion K) S β β a, Supports (K a) S := by
simpa [Supports] using forall_swap
theorem head_supports {S k q} (H : (q : Ξ').Supports S) : (head k q).Supports S := fun _ => by
dsimp only; split_ifs <;> exact H
theorem ret_supports {S k} (Hβ : contSupp k β S) : TM2.SupportsStmt S (tr (Ξ'.ret k)) := by
have W := fun {q} => trStmtsβ_self q
cases k with
| halt => trivial
| consβ => rw [contSupp_consβ, Finset.union_subset_iff] at Hβ; exact fun _ => Hβ.1 W
| consβ => rw [contSupp_consβ, Finset.union_subset_iff] at Hβ; exact fun _ => Hβ.1 W
| comp => rw [contSupp_comp] at Hβ; exact fun _ => Hβ (codeSupp_self _ _ W)
| fix =>
rw [contSupp_fix] at Hβ
have L := @Finset.mem_union_left; have R := @Finset.mem_union_right
intro s; dsimp only; cases natEnd s.iget
Β· refine Hβ (R _ <| L _ <| R _ <| R _ <| L _ W)
Β· exact Hβ (R _ <| L _ <| R _ <| R _ <| R _ <| Finset.mem_singleton_self _)
theorem trStmtsβ_supports {S q} (Hβ : (q : Ξ').Supports S) (HSβ : trStmtsβ q β S) :
Supports (trStmtsβ q) S := by
have W := fun {q} => trStmtsβ_self q
induction q with
| move _ _ _ q q_ih => _ | clear _ _ q q_ih => _ | copy q q_ih => _ | push _ _ q q_ih => _
| read q q_ih => _ | succ q q_ih => _ | pred qβ qβ qβ_ih qβ_ih => _ | ret => _ <;>
simp [trStmtsβ, -Finset.singleton_subset_iff] at HSβ β’
any_goals
obtain β¨hβ, hββ© := Finset.insert_subset_iff.1 HSβ
first | have hβ := hβ W | try simp [Finset.subset_iff] at hβ
Β· exact supports_insert.2 β¨β¨fun _ => hβ, fun _ => hββ©, q_ih Hβ hββ© -- move
Β· exact supports_insert.2 β¨β¨fun _ => hβ, fun _ => hββ©, q_ih Hβ hββ© -- clear
Β· exact supports_insert.2 β¨β¨fun _ => hβ, fun _ => hββ©, q_ih Hβ hββ© -- copy
Β· exact supports_insert.2 β¨β¨fun _ => hβ, fun _ => hββ©, q_ih Hβ hββ© -- push
Β· refine supports_insert.2 β¨fun _ => hβ _ W, ?_β© -- read
exact supports_biUnion.2 fun _ => q_ih _ (Hβ _) fun _ h => hβ _ h
Β· refine supports_insert.2 β¨β¨fun _ => hβ, fun _ => hβ.1, fun _ => hβ.1β©, ?_β© -- succ
exact supports_insert.2 β¨β¨fun _ => hβ.2 _ W, fun _ => hβ.1β©, q_ih Hβ hβ.2β©
Β· refine -- pred
supports_insert.2 β¨β¨fun _ => hβ, fun _ => hβ.2 _ (Or.inl W),
fun _ => hβ.1, fun _ => hβ.1β©, ?_β©
refine supports_insert.2 β¨β¨fun _ => hβ.2 _ (Or.inr W), fun _ => hβ.1β©, ?_β©
refine supports_union.2 β¨?_, ?_β©
Β· exact qβ_ih Hβ.1 fun _ h => hβ.2 _ (Or.inl h)
Β· exact qβ_ih Hβ.2 fun _ h => hβ.2 _ (Or.inr h)
Β· exact supports_singleton.2 (ret_supports Hβ) -- ret
theorem trStmtsβ_supports' {S q K} (Hβ : (q : Ξ').Supports S) (Hβ : trStmtsβ q βͺ K β S)
(Hβ : K β S β Supports K S) : Supports (trStmtsβ q βͺ K) S := by
simp only [Finset.union_subset_iff] at Hβ
exact supports_union.2 β¨trStmtsβ_supports Hβ Hβ.1, Hβ Hβ.2β©
theorem trNormal_supports {S c k} (Hk : codeSupp c k β S) : (trNormal c k).Supports S := by
induction c generalizing k with simp [Ξ'.Supports, head]
| zero' => exact Finset.union_subset_right Hk
| succ => intro; split_ifs <;> exact Finset.union_subset_right Hk
| tail => exact Finset.union_subset_right Hk
| cons f fs IHf _ =>
apply IHf
rw [codeSupp_cons] at Hk
exact Finset.union_subset_right Hk
| comp f g _ IHg => apply IHg; rw [codeSupp_comp] at Hk; exact Finset.union_subset_right Hk
| case f g IHf IHg =>
simp only [codeSupp_case, Finset.union_subset_iff] at Hk
exact β¨IHf Hk.2.1, IHg Hk.2.2β©
| fix f IHf => apply IHf; rw [codeSupp_fix] at Hk; exact Finset.union_subset_right Hk
theorem codeSupp'_supports {S c k} (H : codeSupp c k β S) : Supports (codeSupp' c k) S := by
induction c generalizing k with
| cons f fs IHf IHfs =>
have H' := H; simp only [codeSupp_cons, Finset.union_subset_iff] at H'
refine trStmtsβ_supports' (trNormal_supports H) (Finset.union_subset_left H) fun h => ?_
refine supports_union.2 β¨IHf H'.2, ?_β©
refine trStmtsβ_supports' (trNormal_supports ?_) (Finset.union_subset_right h) fun h => ?_
Β· simp only [codeSupp, Finset.union_subset_iff, contSupp] at h H β’
exact β¨h.2.2.1, h.2.2.2, H.2β©
refine supports_union.2 β¨IHfs ?_, ?_β©
Β· rw [codeSupp, contSupp_consβ] at H'
exact Finset.union_subset_right (Finset.union_subset_right H'.2)
exact
trStmtsβ_supports (head_supports <| Finset.union_subset_right H)
(Finset.union_subset_right h)
| comp f g IHf IHg =>
have H' := H; rw [codeSupp_comp] at H'; have H' := Finset.union_subset_right H'
refine trStmtsβ_supports' (trNormal_supports H) (Finset.union_subset_left H) fun h => ?_
refine supports_union.2 β¨IHg H', ?_β©
refine trStmtsβ_supports' (trNormal_supports ?_) (Finset.union_subset_right h) fun _ => ?_
Β· simp only [codeSupp', codeSupp, Finset.union_subset_iff, contSupp] at h H β’
exact β¨h.2.2, H.2β©
exact IHf (Finset.union_subset_right H')
| case f g IHf IHg =>
have H' := H; simp only [codeSupp_case, Finset.union_subset_iff] at H'
refine trStmtsβ_supports' (trNormal_supports H) (Finset.union_subset_left H) fun _ => ?_
exact supports_union.2 β¨IHf H'.2.1, IHg H'.2.2β©
| fix f IHf =>
have H' := H; simp only [codeSupp_fix, Finset.union_subset_iff] at H'
refine trStmtsβ_supports' (trNormal_supports H) (Finset.union_subset_left H) fun h => ?_
refine supports_union.2 β¨IHf H'.2, ?_β©
refine trStmtsβ_supports' (trNormal_supports ?_) (Finset.union_subset_right h) fun _ => ?_
Β· simp only [codeSupp', codeSupp, Finset.union_subset_iff, contSupp, trStmtsβ,
Finset.insert_subset_iff] at h H β’
exact β¨h.1, β¨H.1.1, hβ©, H.2β©
exact supports_singleton.2 (ret_supports <| Finset.union_subset_right H)
| _ => exact trStmtsβ_supports (trNormal_supports H) (Finset.Subset.trans (codeSupp_self _ _) H)
theorem contSupp_supports {S k} (H : contSupp k β S) : Supports (contSupp k) S := by
induction k with
| halt => simp [contSupp_halt, Supports]
| consβ f k IH =>
have Hβ := H; rw [contSupp_consβ] at Hβ; have Hβ := Finset.union_subset_right Hβ
refine trStmtsβ_supports' (trNormal_supports Hβ) Hβ fun h => ?_
refine supports_union.2 β¨codeSupp'_supports Hβ, ?_β©
simp only [codeSupp, contSupp_consβ, Finset.union_subset_iff] at Hβ
exact trStmtsβ_supports' (head_supports Hβ.2.2) (Finset.union_subset_right h) IH
| consβ k IH =>
have H' := H; rw [contSupp_consβ] at H'
exact trStmtsβ_supports' (head_supports <| Finset.union_subset_right H') H' IH
| comp f k IH =>
have H' := H; rw [contSupp_comp] at H'; have Hβ := Finset.union_subset_right H'
exact supports_union.2 β¨codeSupp'_supports H', IH Hββ©
| fix f k IH =>
rw [contSupp] at H
exact supports_union.2 β¨codeSupp'_supports H, IH (Finset.union_subset_right H)β©
theorem codeSupp_supports {S c k} (H : codeSupp c k β S) : Supports (codeSupp c k) S :=
supports_union.2 β¨codeSupp'_supports H, contSupp_supports (Finset.union_subset_right H)β©
/-- The set `codeSupp c k` is a finite set that witnesses the effective finiteness of the `tr`
Turing machine. Starting from the initial state `trNormal c k`, forward simulation uses only
states in `codeSupp c k`, so this is a finite state machine. Even though the underlying type of
state labels `Ξ'` is infinite, for a given partial recursive function `c` and continuation `k`,
only finitely many states are accessed, corresponding roughly to subterms of `c`. -/
theorem tr_supports (c k) : @TM2.Supports _ _ _ _ β¨trNormal c kβ© tr (codeSupp c k) :=
β¨codeSupp_self _ _ (trStmtsβ_self _), fun _ => codeSupp_supports (Finset.Subset.refl _) _β©
end
end PartrecToTM2
end Turing
| Mathlib/Computability/TMToPartrec.lean | 1,510 | 1,542 | |
/-
Copyright (c) 2020 SΓ©bastien GouΓ«zel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: SΓ©bastien GouΓ«zel
-/
import Mathlib.Topology.UniformSpace.Cauchy
/-!
# Uniform convergence
A sequence of functions `Fβ` (with values in a metric space) converges uniformly on a set `s` to a
function `f` if, for all `Ξ΅ > 0`, for all large enough `n`, one has for all `y β s` the inequality
`dist (f y, Fβ y) < Ξ΅`. Under uniform convergence, many properties of the `Fβ` pass to the limit,
most notably continuity. We prove this in the file, defining the notion of uniform convergence
in the more general setting of uniform spaces, and with respect to an arbitrary indexing set
endowed with a filter (instead of just `β` with `atTop`).
## Main results
Let `Ξ±` be a topological space, `Ξ²` a uniform space, `Fβ` and `f` be functions from `Ξ±` to `Ξ²`
(where the index `n` belongs to an indexing type `ΞΉ` endowed with a filter `p`).
* `TendstoUniformlyOn F f p s`: the fact that `Fβ` converges uniformly to `f` on `s`. This means
that, for any entourage `u` of the diagonal, for large enough `n` (with respect to `p`), one has
`(f y, Fβ y) β u` for all `y β s`.
* `TendstoUniformly F f p`: same notion with `s = univ`.
* `TendstoUniformlyOn.continuousOn`: a uniform limit on a set of functions which are continuous
on this set is itself continuous on this set.
* `TendstoUniformly.continuous`: a uniform limit of continuous functions is continuous.
* `TendstoUniformlyOn.tendsto_comp`: If `Fβ` tends uniformly to `f` on a set `s`, and `gβ` tends
to `x` within `s`, then `Fβ gβ` tends to `f x` if `f` is continuous at `x` within `s`.
* `TendstoUniformly.tendsto_comp`: If `Fβ` tends uniformly to `f`, and `gβ` tends to `x`, then
`Fβ gβ` tends to `f x`.
Finally, we introduce the notion of a uniform Cauchy sequence, which is to uniform
convergence what a Cauchy sequence is to the usual notion of convergence.
## Implementation notes
We derive most of our initial results from an auxiliary definition `TendstoUniformlyOnFilter`.
This definition in and of itself can sometimes be useful, e.g., when studying the local behavior
of the `Fβ` near a point, which would typically look like `TendstoUniformlyOnFilter F f p (π x)`.
Still, while this may be the "correct" definition (see
`tendstoUniformlyOn_iff_tendstoUniformlyOnFilter`), it is somewhat unwieldy to work with in
practice. Thus, we provide the more traditional definition in `TendstoUniformlyOn`.
## Tags
Uniform limit, uniform convergence, tends uniformly to
-/
noncomputable section
open Topology Uniformity Filter Set Uniform
variable {Ξ± Ξ² Ξ³ ΞΉ : Type*} [UniformSpace Ξ²]
variable {F : ΞΉ β Ξ± β Ξ²} {f : Ξ± β Ξ²} {s s' : Set Ξ±} {x : Ξ±} {p : Filter ΞΉ} {p' : Filter Ξ±}
/-!
### Different notions of uniform convergence
We define uniform convergence, on a set or in the whole space.
-/
/-- A sequence of functions `Fβ` converges uniformly on a filter `p'` to a limiting function `f`
with respect to the filter `p` if, for any entourage of the diagonal `u`, one has
`p ΓΛ’ p'`-eventually `(f x, Fβ x) β u`. -/
def TendstoUniformlyOnFilter (F : ΞΉ β Ξ± β Ξ²) (f : Ξ± β Ξ²) (p : Filter ΞΉ) (p' : Filter Ξ±) :=
β u β π€ Ξ², βαΆ n : ΞΉ Γ Ξ± in p ΓΛ’ p', (f n.snd, F n.fst n.snd) β u
/--
A sequence of functions `Fβ` converges uniformly on a filter `p'` to a limiting function `f` w.r.t.
filter `p` iff the function `(n, x) β¦ (f x, Fβ x)` converges along `p ΓΛ’ p'` to the uniformity.
In other words: one knows nothing about the behavior of `x` in this limit besides it being in `p'`.
-/
theorem tendstoUniformlyOnFilter_iff_tendsto :
TendstoUniformlyOnFilter F f p p' β
Tendsto (fun q : ΞΉ Γ Ξ± => (f q.2, F q.1 q.2)) (p ΓΛ’ p') (π€ Ξ²) :=
Iff.rfl
/-- A sequence of functions `Fβ` converges uniformly on a set `s` to a limiting function `f` with
respect to the filter `p` if, for any entourage of the diagonal `u`, one has `p`-eventually
`(f x, Fβ x) β u` for all `x β s`. -/
def TendstoUniformlyOn (F : ΞΉ β Ξ± β Ξ²) (f : Ξ± β Ξ²) (p : Filter ΞΉ) (s : Set Ξ±) :=
β u β π€ Ξ², βαΆ n in p, β x : Ξ±, x β s β (f x, F n x) β u
theorem tendstoUniformlyOn_iff_tendstoUniformlyOnFilter :
TendstoUniformlyOn F f p s β TendstoUniformlyOnFilter F f p (π s) := by
simp only [TendstoUniformlyOn, TendstoUniformlyOnFilter]
apply forallβ_congr
simp_rw [eventually_prod_principal_iff]
simp
alias β¨TendstoUniformlyOn.tendstoUniformlyOnFilter, TendstoUniformlyOnFilter.tendstoUniformlyOnβ© :=
tendstoUniformlyOn_iff_tendstoUniformlyOnFilter
/-- A sequence of functions `Fβ` converges uniformly on a set `s` to a limiting function `f` w.r.t.
filter `p` iff the function `(n, x) β¦ (f x, Fβ x)` converges along `p ΓΛ’ π s` to the uniformity.
In other words: one knows nothing about the behavior of `x` in this limit besides it being in `s`.
-/
theorem tendstoUniformlyOn_iff_tendsto :
TendstoUniformlyOn F f p s β
Tendsto (fun q : ΞΉ Γ Ξ± => (f q.2, F q.1 q.2)) (p ΓΛ’ π s) (π€ Ξ²) := by
simp [tendstoUniformlyOn_iff_tendstoUniformlyOnFilter, tendstoUniformlyOnFilter_iff_tendsto]
/-- A sequence of functions `Fβ` converges uniformly to a limiting function `f` with respect to a
filter `p` if, for any entourage of the diagonal `u`, one has `p`-eventually
`(f x, Fβ x) β u` for all `x`. -/
def TendstoUniformly (F : ΞΉ β Ξ± β Ξ²) (f : Ξ± β Ξ²) (p : Filter ΞΉ) :=
β u β π€ Ξ², βαΆ n in p, β x : Ξ±, (f x, F n x) β u
theorem tendstoUniformlyOn_univ : TendstoUniformlyOn F f p univ β TendstoUniformly F f p := by
simp [TendstoUniformlyOn, TendstoUniformly]
theorem tendstoUniformly_iff_tendstoUniformlyOnFilter :
TendstoUniformly F f p β TendstoUniformlyOnFilter F f p β€ := by
rw [β tendstoUniformlyOn_univ, tendstoUniformlyOn_iff_tendstoUniformlyOnFilter, principal_univ]
theorem TendstoUniformly.tendstoUniformlyOnFilter (h : TendstoUniformly F f p) :
TendstoUniformlyOnFilter F f p β€ := by rwa [β tendstoUniformly_iff_tendstoUniformlyOnFilter]
theorem tendstoUniformlyOn_iff_tendstoUniformly_comp_coe :
TendstoUniformlyOn F f p s β TendstoUniformly (fun i (x : s) => F i x) (f β (β)) p :=
forallβ_congr fun u _ => by simp
/-- A sequence of functions `Fβ` converges uniformly to a limiting function `f` w.r.t.
filter `p` iff the function `(n, x) β¦ (f x, Fβ x)` converges along `p ΓΛ’ β€` to the uniformity.
In other words: one knows nothing about the behavior of `x` in this limit.
-/
theorem tendstoUniformly_iff_tendsto :
TendstoUniformly F f p β Tendsto (fun q : ΞΉ Γ Ξ± => (f q.2, F q.1 q.2)) (p ΓΛ’ β€) (π€ Ξ²) := by
simp [tendstoUniformly_iff_tendstoUniformlyOnFilter, tendstoUniformlyOnFilter_iff_tendsto]
/-- Uniform convergence implies pointwise convergence. -/
theorem TendstoUniformlyOnFilter.tendsto_at (h : TendstoUniformlyOnFilter F f p p')
(hx : π {x} β€ p') : Tendsto (fun n => F n x) p <| π (f x) := by
refine Uniform.tendsto_nhds_right.mpr fun u hu => mem_map.mpr ?_
filter_upwards [(h u hu).curry]
intro i h
simpa using h.filter_mono hx
/-- Uniform convergence implies pointwise convergence. -/
theorem TendstoUniformlyOn.tendsto_at (h : TendstoUniformlyOn F f p s) (hx : x β s) :
Tendsto (fun n => F n x) p <| π (f x) :=
h.tendstoUniformlyOnFilter.tendsto_at
(le_principal_iff.mpr <| mem_principal.mpr <| singleton_subset_iff.mpr <| hx)
/-- Uniform convergence implies pointwise convergence. -/
theorem TendstoUniformly.tendsto_at (h : TendstoUniformly F f p) (x : Ξ±) :
Tendsto (fun n => F n x) p <| π (f x) :=
h.tendstoUniformlyOnFilter.tendsto_at le_top
theorem TendstoUniformlyOnFilter.mono_left {p'' : Filter ΞΉ} (h : TendstoUniformlyOnFilter F f p p')
(hp : p'' β€ p) : TendstoUniformlyOnFilter F f p'' p' := fun u hu =>
(h u hu).filter_mono (p'.prod_mono_left hp)
theorem TendstoUniformlyOnFilter.mono_right {p'' : Filter Ξ±} (h : TendstoUniformlyOnFilter F f p p')
(hp : p'' β€ p') : TendstoUniformlyOnFilter F f p p'' := fun u hu =>
(h u hu).filter_mono (p.prod_mono_right hp)
theorem TendstoUniformlyOn.mono (h : TendstoUniformlyOn F f p s) (h' : s' β s) :
TendstoUniformlyOn F f p s' :=
tendstoUniformlyOn_iff_tendstoUniformlyOnFilter.mpr
(h.tendstoUniformlyOnFilter.mono_right (le_principal_iff.mpr <| mem_principal.mpr h'))
theorem TendstoUniformlyOnFilter.congr {F' : ΞΉ β Ξ± β Ξ²} (hf : TendstoUniformlyOnFilter F f p p')
(hff' : βαΆ n : ΞΉ Γ Ξ± in p ΓΛ’ p', F n.fst n.snd = F' n.fst n.snd) :
TendstoUniformlyOnFilter F' f p p' := by
refine fun u hu => ((hf u hu).and hff').mono fun n h => ?_
rw [β h.right]
exact h.left
theorem TendstoUniformlyOn.congr {F' : ΞΉ β Ξ± β Ξ²} (hf : TendstoUniformlyOn F f p s)
(hff' : βαΆ n in p, Set.EqOn (F n) (F' n) s) : TendstoUniformlyOn F' f p s := by
rw [tendstoUniformlyOn_iff_tendstoUniformlyOnFilter] at hf β’
refine hf.congr ?_
rw [eventually_iff] at hff' β’
simp only [Set.EqOn] at hff'
simp only [mem_prod_principal, hff', mem_setOf_eq]
lemma tendstoUniformly_congr {F' : ΞΉ β Ξ± β Ξ²} (hF : F =αΆ [p] F') :
TendstoUniformly F f p β TendstoUniformly F' f p := by
simp_rw [β tendstoUniformlyOn_univ] at *
have HF := EventuallyEq.exists_mem hF
exact β¨fun h => h.congr (by aesop), fun h => h.congr (by simp_rw [eqOn_comm]; aesop)β©
theorem TendstoUniformlyOn.congr_right {g : Ξ± β Ξ²} (hf : TendstoUniformlyOn F f p s)
(hfg : EqOn f g s) : TendstoUniformlyOn F g p s := fun u hu => by
filter_upwards [hf u hu] with i hi a ha using hfg ha βΈ hi a ha
protected theorem TendstoUniformly.tendstoUniformlyOn (h : TendstoUniformly F f p) :
TendstoUniformlyOn F f p s :=
(tendstoUniformlyOn_univ.2 h).mono (subset_univ s)
/-- Composing on the right by a function preserves uniform convergence on a filter -/
theorem TendstoUniformlyOnFilter.comp (h : TendstoUniformlyOnFilter F f p p') (g : Ξ³ β Ξ±) :
TendstoUniformlyOnFilter (fun n => F n β g) (f β g) p (p'.comap g) := by
rw [tendstoUniformlyOnFilter_iff_tendsto] at h β’
exact h.comp (tendsto_id.prodMap tendsto_comap)
/-- Composing on the right by a function preserves uniform convergence on a set -/
theorem TendstoUniformlyOn.comp (h : TendstoUniformlyOn F f p s) (g : Ξ³ β Ξ±) :
TendstoUniformlyOn (fun n => F n β g) (f β g) p (g β»ΒΉ' s) := by
rw [tendstoUniformlyOn_iff_tendstoUniformlyOnFilter] at h β’
simpa [TendstoUniformlyOn, comap_principal] using TendstoUniformlyOnFilter.comp h g
/-- Composing on the right by a function preserves uniform convergence -/
theorem TendstoUniformly.comp (h : TendstoUniformly F f p) (g : Ξ³ β Ξ±) :
TendstoUniformly (fun n => F n β g) (f β g) p := by
rw [tendstoUniformly_iff_tendstoUniformlyOnFilter] at h β’
simpa [principal_univ, comap_principal] using h.comp g
/-- Composing on the left by a uniformly continuous function preserves
uniform convergence on a filter -/
theorem UniformContinuous.comp_tendstoUniformlyOnFilter [UniformSpace Ξ³] {g : Ξ² β Ξ³}
(hg : UniformContinuous g) (h : TendstoUniformlyOnFilter F f p p') :
TendstoUniformlyOnFilter (fun i => g β F i) (g β f) p p' := fun _u hu => h _ (hg hu)
/-- Composing on the left by a uniformly continuous function preserves
uniform convergence on a set -/
theorem UniformContinuous.comp_tendstoUniformlyOn [UniformSpace Ξ³] {g : Ξ² β Ξ³}
(hg : UniformContinuous g) (h : TendstoUniformlyOn F f p s) :
TendstoUniformlyOn (fun i => g β F i) (g β f) p s := fun _u hu => h _ (hg hu)
/-- Composing on the left by a uniformly continuous function preserves uniform convergence -/
theorem UniformContinuous.comp_tendstoUniformly [UniformSpace Ξ³] {g : Ξ² β Ξ³}
(hg : UniformContinuous g) (h : TendstoUniformly F f p) :
TendstoUniformly (fun i => g β F i) (g β f) p := fun _u hu => h _ (hg hu)
theorem TendstoUniformlyOnFilter.prodMap {ΞΉ' Ξ±' Ξ²' : Type*} [UniformSpace Ξ²'] {F' : ΞΉ' β Ξ±' β Ξ²'}
{f' : Ξ±' β Ξ²'} {q : Filter ΞΉ'} {q' : Filter Ξ±'} (h : TendstoUniformlyOnFilter F f p p')
(h' : TendstoUniformlyOnFilter F' f' q q') :
TendstoUniformlyOnFilter (fun i : ΞΉ Γ ΞΉ' => Prod.map (F i.1) (F' i.2)) (Prod.map f f') (p ΓΛ’ q)
(p' ΓΛ’ q') := by
rw [tendstoUniformlyOnFilter_iff_tendsto] at h h' β’
rw [uniformity_prod_eq_comap_prod, tendsto_comap_iff, β map_swap4_prod, tendsto_map'_iff]
simpa using h.prodMap h'
@[deprecated (since := "2025-03-10")]
alias TendstoUniformlyOnFilter.prod_map := TendstoUniformlyOnFilter.prodMap
theorem TendstoUniformlyOn.prodMap {ΞΉ' Ξ±' Ξ²' : Type*} [UniformSpace Ξ²'] {F' : ΞΉ' β Ξ±' β Ξ²'}
{f' : Ξ±' β Ξ²'} {p' : Filter ΞΉ'} {s' : Set Ξ±'} (h : TendstoUniformlyOn F f p s)
(h' : TendstoUniformlyOn F' f' p' s') :
TendstoUniformlyOn (fun i : ΞΉ Γ ΞΉ' => Prod.map (F i.1) (F' i.2)) (Prod.map f f') (p ΓΛ’ p')
(s ΓΛ’ s') := by
rw [tendstoUniformlyOn_iff_tendstoUniformlyOnFilter] at h h' β’
simpa only [prod_principal_principal] using h.prodMap h'
@[deprecated (since := "2025-03-10")]
alias TendstoUniformlyOn.prod_map := TendstoUniformlyOn.prodMap
theorem TendstoUniformly.prodMap {ΞΉ' Ξ±' Ξ²' : Type*} [UniformSpace Ξ²'] {F' : ΞΉ' β Ξ±' β Ξ²'}
{f' : Ξ±' β Ξ²'} {p' : Filter ΞΉ'} (h : TendstoUniformly F f p) (h' : TendstoUniformly F' f' p') :
TendstoUniformly (fun i : ΞΉ Γ ΞΉ' => Prod.map (F i.1) (F' i.2)) (Prod.map f f') (p ΓΛ’ p') := by
rw [β tendstoUniformlyOn_univ, β univ_prod_univ] at *
exact h.prodMap h'
@[deprecated (since := "2025-03-10")]
alias TendstoUniformly.prod_map := TendstoUniformly.prodMap
theorem TendstoUniformlyOnFilter.prodMk {ΞΉ' Ξ²' : Type*} [UniformSpace Ξ²'] {F' : ΞΉ' β Ξ± β Ξ²'}
{f' : Ξ± β Ξ²'} {q : Filter ΞΉ'} (h : TendstoUniformlyOnFilter F f p p')
(h' : TendstoUniformlyOnFilter F' f' q p') :
TendstoUniformlyOnFilter (fun (i : ΞΉ Γ ΞΉ') a => (F i.1 a, F' i.2 a)) (fun a => (f a, f' a))
(p ΓΛ’ q) p' :=
fun u hu => ((h.prodMap h') u hu).diag_of_prod_right
@[deprecated (since := "2025-03-10")]
alias TendstoUniformlyOnFilter.prod := TendstoUniformlyOnFilter.prodMk
protected theorem TendstoUniformlyOn.prodMk {ΞΉ' Ξ²' : Type*} [UniformSpace Ξ²'] {F' : ΞΉ' β Ξ± β Ξ²'}
{f' : Ξ± β Ξ²'} {p' : Filter ΞΉ'} (h : TendstoUniformlyOn F f p s)
(h' : TendstoUniformlyOn F' f' p' s) :
TendstoUniformlyOn (fun (i : ΞΉ Γ ΞΉ') a => (F i.1 a, F' i.2 a)) (fun a => (f a, f' a)) (p ΓΛ’ p')
s :=
(congr_arg _ s.inter_self).mp ((h.prodMap h').comp fun a => (a, a))
@[deprecated (since := "2025-03-10")]
alias TendstoUniformlyOn.prod := TendstoUniformlyOn.prodMk
theorem TendstoUniformly.prodMk {ΞΉ' Ξ²' : Type*} [UniformSpace Ξ²'] {F' : ΞΉ' β Ξ± β Ξ²'} {f' : Ξ± β Ξ²'}
{p' : Filter ΞΉ'} (h : TendstoUniformly F f p) (h' : TendstoUniformly F' f' p') :
TendstoUniformly (fun (i : ΞΉ Γ ΞΉ') a => (F i.1 a, F' i.2 a)) (fun a => (f a, f' a)) (p ΓΛ’ p') :=
(h.prodMap h').comp fun a => (a, a)
@[deprecated (since := "2025-03-10")]
alias TendstoUniformly.prod := TendstoUniformly.prodMk
/-- Uniform convergence on a filter `p'` to a constant function is equivalent to convergence in
`p ΓΛ’ p'`. -/
theorem tendsto_prod_filter_iff {c : Ξ²} :
Tendsto (βΏF) (p ΓΛ’ p') (π c) β TendstoUniformlyOnFilter F (fun _ => c) p p' := by
simp_rw [nhds_eq_comap_uniformity, tendsto_comap_iff]
rfl
/-- Uniform convergence on a set `s` to a constant function is equivalent to convergence in
`p ΓΛ’ π s`. -/
theorem tendsto_prod_principal_iff {c : Ξ²} :
Tendsto (βΏF) (p ΓΛ’ π s) (π c) β TendstoUniformlyOn F (fun _ => c) p s := by
rw [tendstoUniformlyOn_iff_tendstoUniformlyOnFilter]
exact tendsto_prod_filter_iff
/-- Uniform convergence to a constant function is equivalent to convergence in `p ΓΛ’ β€`. -/
theorem tendsto_prod_top_iff {c : Ξ²} :
Tendsto (βΏF) (p ΓΛ’ β€) (π c) β TendstoUniformly F (fun _ => c) p := by
rw [tendstoUniformly_iff_tendstoUniformlyOnFilter]
exact tendsto_prod_filter_iff
/-- Uniform convergence on the empty set is vacuously true -/
theorem tendstoUniformlyOn_empty : TendstoUniformlyOn F f p β
:= fun u _ => by simp
/-- Uniform convergence on a singleton is equivalent to regular convergence -/
theorem tendstoUniformlyOn_singleton_iff_tendsto :
TendstoUniformlyOn F f p {x} β Tendsto (fun n : ΞΉ => F n x) p (π (f x)) := by
simp_rw [tendstoUniformlyOn_iff_tendsto, Uniform.tendsto_nhds_right, tendsto_def]
exact forallβ_congr fun u _ => by simp [mem_prod_principal, preimage]
/-- If a sequence `g` converges to some `b`, then the sequence of constant functions
`fun n β¦ fun a β¦ g n` converges to the constant function `fun a β¦ b` on any set `s` -/
theorem Filter.Tendsto.tendstoUniformlyOnFilter_const {g : ΞΉ β Ξ²} {b : Ξ²} (hg : Tendsto g p (π b))
(p' : Filter Ξ±) :
TendstoUniformlyOnFilter (fun n : ΞΉ => fun _ : Ξ± => g n) (fun _ : Ξ± => b) p p' := by
simpa only [nhds_eq_comap_uniformity, tendsto_comap_iff] using hg.comp (tendsto_fst (g := p'))
/-- If a sequence `g` converges to some `b`, then the sequence of constant functions
`fun n β¦ fun a β¦ g n` converges to the constant function `fun a β¦ b` on any set `s` -/
theorem Filter.Tendsto.tendstoUniformlyOn_const {g : ΞΉ β Ξ²} {b : Ξ²} (hg : Tendsto g p (π b))
(s : Set Ξ±) : TendstoUniformlyOn (fun n : ΞΉ => fun _ : Ξ± => g n) (fun _ : Ξ± => b) p s :=
tendstoUniformlyOn_iff_tendstoUniformlyOnFilter.mpr (hg.tendstoUniformlyOnFilter_const (π s))
theorem UniformContinuousOn.tendstoUniformlyOn [UniformSpace Ξ±] [UniformSpace Ξ³] {U : Set Ξ±}
{V : Set Ξ²} {F : Ξ± β Ξ² β Ξ³} (hF : UniformContinuousOn (βΏF) (U ΓΛ’ V)) (hU : x β U) :
TendstoUniformlyOn F (F x) (π[U] x) V := by
set Ο := fun q : Ξ± Γ Ξ² => ((x, q.2), q)
rw [tendstoUniformlyOn_iff_tendsto]
change Tendsto (Prod.map (βΏF) βΏF β Ο) (π[U] x ΓΛ’ π V) (π€ Ξ³)
simp only [nhdsWithin, Filter.prod_eq_inf, comap_inf, inf_assoc, comap_principal, inf_principal]
refine hF.comp (Tendsto.inf ?_ <| tendsto_principal_principal.2 fun x hx => β¨β¨hU, hx.2β©, hxβ©)
simp only [uniformity_prod_eq_comap_prod, tendsto_comap_iff, (Β· β Β·),
nhds_eq_comap_uniformity, comap_comap]
exact tendsto_comap.prodMk (tendsto_diag_uniformity _ _)
theorem UniformContinuousOn.tendstoUniformly [UniformSpace Ξ±] [UniformSpace Ξ³] {U : Set Ξ±}
(hU : U β π x) {F : Ξ± β Ξ² β Ξ³} (hF : UniformContinuousOn (βΏF) (U ΓΛ’ (univ : Set Ξ²))) :
TendstoUniformly F (F x) (π x) := by
simpa only [tendstoUniformlyOn_univ, nhdsWithin_eq_nhds.2 hU]
using hF.tendstoUniformlyOn (mem_of_mem_nhds hU)
theorem UniformContinuousβ.tendstoUniformly [UniformSpace Ξ±] [UniformSpace Ξ³] {f : Ξ± β Ξ² β Ξ³}
(h : UniformContinuousβ f) : TendstoUniformly f (f x) (π x) :=
UniformContinuousOn.tendstoUniformly univ_mem <| by rwa [univ_prod_univ, uniformContinuousOn_univ]
/-- A sequence is uniformly Cauchy if eventually all of its pairwise differences are
uniformly bounded -/
def UniformCauchySeqOnFilter (F : ΞΉ β Ξ± β Ξ²) (p : Filter ΞΉ) (p' : Filter Ξ±) : Prop :=
β u β π€ Ξ², βαΆ m : (ΞΉ Γ ΞΉ) Γ Ξ± in (p ΓΛ’ p) ΓΛ’ p', (F m.fst.fst m.snd, F m.fst.snd m.snd) β u
/-- A sequence is uniformly Cauchy if eventually all of its pairwise differences are
uniformly bounded -/
def UniformCauchySeqOn (F : ΞΉ β Ξ± β Ξ²) (p : Filter ΞΉ) (s : Set Ξ±) : Prop :=
β u β π€ Ξ², βαΆ m : ΞΉ Γ ΞΉ in p ΓΛ’ p, β x : Ξ±, x β s β (F m.fst x, F m.snd x) β u
theorem uniformCauchySeqOn_iff_uniformCauchySeqOnFilter :
UniformCauchySeqOn F p s β UniformCauchySeqOnFilter F p (π s) := by
simp only [UniformCauchySeqOn, UniformCauchySeqOnFilter]
refine forallβ_congr fun u hu => ?_
rw [eventually_prod_principal_iff]
theorem UniformCauchySeqOn.uniformCauchySeqOnFilter (hF : UniformCauchySeqOn F p s) :
UniformCauchySeqOnFilter F p (π s) := by rwa [β uniformCauchySeqOn_iff_uniformCauchySeqOnFilter]
/-- A sequence that converges uniformly is also uniformly Cauchy -/
theorem TendstoUniformlyOnFilter.uniformCauchySeqOnFilter (hF : TendstoUniformlyOnFilter F f p p') :
UniformCauchySeqOnFilter F p p' := by
intro u hu
rcases comp_symm_of_uniformity hu with β¨t, ht, htsymm, htmemβ©
have := tendsto_swap4_prod.eventually ((hF t ht).prod_mk (hF t ht))
apply this.diag_of_prod_right.mono
simp only [and_imp, Prod.forall]
intro n1 n2 x hl hr
exact Set.mem_of_mem_of_subset (prodMk_mem_compRel (htsymm hl) hr) htmem
/-- A sequence that converges uniformly is also uniformly Cauchy -/
theorem TendstoUniformlyOn.uniformCauchySeqOn (hF : TendstoUniformlyOn F f p s) :
UniformCauchySeqOn F p s :=
uniformCauchySeqOn_iff_uniformCauchySeqOnFilter.mpr
hF.tendstoUniformlyOnFilter.uniformCauchySeqOnFilter
/-- A uniformly Cauchy sequence converges uniformly to its limit -/
theorem UniformCauchySeqOnFilter.tendstoUniformlyOnFilter_of_tendsto
(hF : UniformCauchySeqOnFilter F p p')
(hF' : βαΆ x : Ξ± in p', Tendsto (fun n => F n x) p (π (f x))) :
TendstoUniformlyOnFilter F f p p' := by
rcases p.eq_or_neBot with rfl | _
Β· simp only [TendstoUniformlyOnFilter, bot_prod, eventually_bot, implies_true]
-- Proof idea: |f_n(x) - f(x)| β€ |f_n(x) - f_m(x)| + |f_m(x) - f(x)|. We choose `n`
-- so that |f_n(x) - f_m(x)| is uniformly small across `s` whenever `m β₯ n`. Then for
-- a fixed `x`, we choose `m` sufficiently large such that |f_m(x) - f(x)| is small.
intro u hu
rcases comp_symm_of_uniformity hu with β¨t, ht, htsymm, htmemβ©
-- We will choose n, x, and m simultaneously. n and x come from hF. m comes from hF'
-- But we need to promote hF' to the full product filter to use it
have hmc : βαΆ x in (p ΓΛ’ p) ΓΛ’ p', Tendsto (fun n : ΞΉ => F n x.snd) p (π (f x.snd)) := by
rw [eventually_prod_iff]
exact β¨fun _ => True, by simp, _, hF', by simpβ©
| -- To apply filter operations we'll need to do some order manipulation
rw [Filter.eventually_swap_iff]
have := tendsto_prodAssoc.eventually (tendsto_prod_swap.eventually ((hF t ht).and hmc))
apply this.curry.mono
simp only [Equiv.prodAssoc_apply, eventually_and, eventually_const, Prod.snd_swap, Prod.fst_swap,
| Mathlib/Topology/UniformSpace/UniformConvergence.lean | 407 | 411 |
/-
Copyright (c) 2018 Simon Hudon. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Simon Hudon
-/
import Mathlib.Control.Applicative
import Mathlib.Control.Traversable.Basic
import Mathlib.Data.List.Forall2
import Mathlib.Data.Set.Functor
/-!
# LawfulTraversable instances
This file provides instances of `LawfulTraversable` for types from the core library: `Option`,
`List` and `Sum`.
-/
universe u v
section Option
open Functor
variable {F G : Type u β Type u}
variable [Applicative F] [Applicative G]
variable [LawfulApplicative G]
theorem Option.id_traverse {Ξ±} (x : Option Ξ±) : Option.traverse (pure : Ξ± β Id Ξ±) x = x := by
cases x <;> rfl
theorem Option.comp_traverse {Ξ± Ξ² Ξ³} (f : Ξ² β F Ξ³) (g : Ξ± β G Ξ²) (x : Option Ξ±) :
Option.traverse (Comp.mk β (f <$> Β·) β g) x =
Comp.mk (Option.traverse f <$> Option.traverse g x) := by
cases x <;> (simp! [functor_norm] <;> rfl)
theorem Option.traverse_eq_map_id {Ξ± Ξ²} (f : Ξ± β Ξ²) (x : Option Ξ±) :
Option.traverse ((pure : _ β Id _) β f) x = (pure : _ β Id _) (f <$> x) := by cases x <;> rfl
variable (Ξ· : ApplicativeTransformation F G)
theorem Option.naturality [LawfulApplicative F] {Ξ± Ξ²} (f : Ξ± β F Ξ²) (x : Option Ξ±) :
Ξ· (Option.traverse f x) = Option.traverse (@Ξ· _ β f) x := by
-- Porting note: added `ApplicativeTransformation` theorems
rcases x with - | x <;> simp! [*, functor_norm, ApplicativeTransformation.preserves_map,
ApplicativeTransformation.preserves_seq, ApplicativeTransformation.preserves_pure]
end Option
instance : LawfulTraversable Option :=
{ show LawfulMonad Option from inferInstance with
id_traverse := Option.id_traverse
comp_traverse := Option.comp_traverse
traverse_eq_map_id := Option.traverse_eq_map_id
naturality := fun Ξ· _ _ f x => Option.naturality Ξ· f x }
namespace List
variable {F G : Type u β Type u}
variable [Applicative F] [Applicative G]
section
variable [LawfulApplicative G]
open Applicative Functor List
protected theorem id_traverse {Ξ±} (xs : List Ξ±) : List.traverse (pure : Ξ± β Id Ξ±) xs = xs := by
induction xs <;> simp! [*, List.traverse, functor_norm]; rfl
protected theorem comp_traverse {Ξ± Ξ² Ξ³} (f : Ξ² β F Ξ³) (g : Ξ± β G Ξ²) (x : List Ξ±) :
List.traverse (Comp.mk β (f <$> Β·) β g) x =
Comp.mk (List.traverse f <$> List.traverse g x) := by
induction x <;> simp! [*, functor_norm] <;> rfl
protected theorem traverse_eq_map_id {Ξ± Ξ²} (f : Ξ± β Ξ²) (x : List Ξ±) :
List.traverse ((pure : _ β Id _) β f) x = (pure : _ β Id _) (f <$> x) := by
induction x <;> simp! [*, functor_norm]; rfl
variable [LawfulApplicative F] (Ξ· : ApplicativeTransformation F G)
protected theorem naturality {Ξ± Ξ²} (f : Ξ± β F Ξ²) (x : List Ξ±) :
Ξ· (List.traverse f x) = List.traverse (@Ξ· _ β f) x := by
-- Porting note: added `ApplicativeTransformation` theorems
induction x <;> simp! [*, functor_norm, ApplicativeTransformation.preserves_map,
ApplicativeTransformation.preserves_seq, ApplicativeTransformation.preserves_pure]
instance : LawfulTraversable.{u} List :=
{ show LawfulMonad List from inferInstance with
id_traverse := List.id_traverse
comp_traverse := List.comp_traverse
traverse_eq_map_id := List.traverse_eq_map_id
naturality := List.naturality }
end
section Traverse
variable {Ξ±' Ξ²' : Type u} (f : Ξ±' β F Ξ²')
@[simp]
theorem traverse_nil : traverse f ([] : List Ξ±') = (pure [] : F (List Ξ²')) :=
rfl
@[simp]
theorem traverse_cons (a : Ξ±') (l : List Ξ±') :
traverse f (a :: l) = (Β· :: Β·) <$> f a <*> traverse f l :=
rfl
variable [LawfulApplicative F]
@[simp]
theorem traverse_append :
β as bs : List Ξ±', traverse f (as ++ bs) = (Β· ++ Β·) <$> traverse f as <*> traverse f bs
| [], bs => by simp [functor_norm]
| a :: as, bs => by simp [traverse_append as bs, functor_norm]; congr
theorem mem_traverse {f : Ξ±' β Set Ξ²'} :
β (l : List Ξ±') (n : List Ξ²'), n β traverse f l β Forallβ (fun b a => b β f a) n l
| [], [] => by simp
| a :: as, [] => by simp
| [], b :: bs => by simp
| a :: as, b :: bs => by simp [mem_traverse as bs]
end Traverse
end List
namespace Sum
section Traverse
variable {Ο : Type u}
variable {F G : Type u β Type u}
variable [Applicative F] [Applicative G]
open Applicative Functor
protected theorem traverse_map {Ξ± Ξ² Ξ³ : Type u} (g : Ξ± β Ξ²) (f : Ξ² β G Ξ³) (x : Ο β Ξ±) :
Sum.traverse f (g <$> x) = Sum.traverse (f β g) x := by
cases x <;> simp [Sum.traverse, id_map, functor_norm] <;> rfl
protected theorem id_traverse {Ο Ξ±} (x : Ο β Ξ±) :
Sum.traverse (pure : Ξ± β Id Ξ±) x = x := by cases x <;> rfl
variable [LawfulApplicative G]
protected theorem comp_traverse {Ξ± Ξ² Ξ³ : Type u} (f : Ξ² β F Ξ³) (g : Ξ± β G Ξ²) (x : Ο β Ξ±) :
Sum.traverse (Comp.mk β (f <$> Β·) β g) x =
Comp.mk.{u} (Sum.traverse f <$> Sum.traverse g x) := by
cases x <;> (simp! [Sum.traverse, map_id, functor_norm] <;> rfl)
protected theorem traverse_eq_map_id {Ξ± Ξ²} (f : Ξ± β Ξ²) (x : Ο β Ξ±) :
Sum.traverse ((pure : _ β Id _) β f) x = (pure : _ β Id _) (f <$> x) := by
induction x <;> simp! [*, functor_norm] <;> rfl
protected theorem map_traverse {Ξ± Ξ² Ξ³} (g : Ξ± β G Ξ²) (f : Ξ² β Ξ³) (x : Ο β Ξ±) :
(f <$> Β·) <$> Sum.traverse g x = Sum.traverse (f <$> g Β·) x := by
cases x <;> simp [Sum.traverse, id_map, functor_norm] <;> congr
variable [LawfulApplicative F] (Ξ· : ApplicativeTransformation F G)
protected theorem naturality {Ξ± Ξ²} (f : Ξ± β F Ξ²) (x : Ο β Ξ±) :
| Ξ· (Sum.traverse f x) = Sum.traverse (@Ξ· _ β f) x := by
-- Porting note: added `ApplicativeTransformation` theorems
cases x <;> simp! [Sum.traverse, functor_norm, ApplicativeTransformation.preserves_map,
ApplicativeTransformation.preserves_seq, ApplicativeTransformation.preserves_pure]
| Mathlib/Control/Traversable/Instances.lean | 164 | 167 |
/-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle SΓΆnne, Benjamin Davidson
-/
import Mathlib.Algebra.Field.NegOnePow
import Mathlib.Algebra.Field.Periodic
import Mathlib.Algebra.QuadraticDiscriminant
import Mathlib.Analysis.SpecialFunctions.Exp
/-!
# Trigonometric functions
## Main definitions
This file contains the definition of `Ο`.
See also `Analysis.SpecialFunctions.Trigonometric.Inverse` and
`Analysis.SpecialFunctions.Trigonometric.Arctan` for the inverse trigonometric functions.
See also `Analysis.SpecialFunctions.Complex.Arg` and
`Analysis.SpecialFunctions.Complex.Log` for the complex argument function
and the complex logarithm.
## Main statements
Many basic inequalities on the real trigonometric functions are established.
The continuity of the usual trigonometric functions is proved.
Several facts about the real trigonometric functions have the proofs deferred to
`Analysis.SpecialFunctions.Trigonometric.Complex`,
as they are most easily proved by appealing to the corresponding fact for
complex trigonometric functions.
See also `Analysis.SpecialFunctions.Trigonometric.Chebyshev` for the multiple angle formulas
in terms of Chebyshev polynomials.
## Tags
sin, cos, tan, angle
-/
noncomputable section
open Topology Filter Set
namespace Complex
@[continuity, fun_prop]
theorem continuous_sin : Continuous sin := by
change Continuous fun z => (exp (-z * I) - exp (z * I)) * I / 2
fun_prop
@[fun_prop]
theorem continuousOn_sin {s : Set β} : ContinuousOn sin s :=
continuous_sin.continuousOn
@[continuity, fun_prop]
theorem continuous_cos : Continuous cos := by
change Continuous fun z => (exp (z * I) + exp (-z * I)) / 2
fun_prop
@[fun_prop]
theorem continuousOn_cos {s : Set β} : ContinuousOn cos s :=
continuous_cos.continuousOn
@[continuity, fun_prop]
theorem continuous_sinh : Continuous sinh := by
change Continuous fun z => (exp z - exp (-z)) / 2
fun_prop
@[continuity, fun_prop]
theorem continuous_cosh : Continuous cosh := by
change Continuous fun z => (exp z + exp (-z)) / 2
fun_prop
end Complex
namespace Real
variable {x y z : β}
@[continuity, fun_prop]
theorem continuous_sin : Continuous sin :=
Complex.continuous_re.comp (Complex.continuous_sin.comp Complex.continuous_ofReal)
@[fun_prop]
theorem continuousOn_sin {s} : ContinuousOn sin s :=
continuous_sin.continuousOn
@[continuity, fun_prop]
theorem continuous_cos : Continuous cos :=
Complex.continuous_re.comp (Complex.continuous_cos.comp Complex.continuous_ofReal)
@[fun_prop]
theorem continuousOn_cos {s} : ContinuousOn cos s :=
continuous_cos.continuousOn
@[continuity, fun_prop]
theorem continuous_sinh : Continuous sinh :=
Complex.continuous_re.comp (Complex.continuous_sinh.comp Complex.continuous_ofReal)
@[continuity, fun_prop]
theorem continuous_cosh : Continuous cosh :=
Complex.continuous_re.comp (Complex.continuous_cosh.comp Complex.continuous_ofReal)
end Real
namespace Real
theorem exists_cos_eq_zero : 0 β cos '' Icc (1 : β) 2 :=
intermediate_value_Icc' (by norm_num) continuousOn_cos
β¨le_of_lt cos_two_neg, le_of_lt cos_one_posβ©
/-- The number Ο = 3.14159265... Defined here using choice as twice a zero of cos in [1,2], from
which one can derive all its properties. For explicit bounds on Ο, see `Data.Real.Pi.Bounds`.
Denoted `Ο`, once the `Real` namespace is opened. -/
protected noncomputable def pi : β :=
2 * Classical.choose exists_cos_eq_zero
@[inherit_doc]
scoped notation "Ο" => Real.pi
@[simp]
theorem cos_pi_div_two : cos (Ο / 2) = 0 := by
rw [Real.pi, mul_div_cancel_leftβ _ (two_ne_zero' β)]
exact (Classical.choose_spec exists_cos_eq_zero).2
theorem one_le_pi_div_two : (1 : β) β€ Ο / 2 := by
rw [Real.pi, mul_div_cancel_leftβ _ (two_ne_zero' β)]
exact (Classical.choose_spec exists_cos_eq_zero).1.1
theorem pi_div_two_le_two : Ο / 2 β€ 2 := by
rw [Real.pi, mul_div_cancel_leftβ _ (two_ne_zero' β)]
exact (Classical.choose_spec exists_cos_eq_zero).1.2
theorem two_le_pi : (2 : β) β€ Ο :=
(div_le_div_iff_of_pos_right (show (0 : β) < 2 by norm_num)).1
(by rw [div_self (two_ne_zero' β)]; exact one_le_pi_div_two)
theorem pi_le_four : Ο β€ 4 :=
(div_le_div_iff_of_pos_right (show (0 : β) < 2 by norm_num)).1
(calc
Ο / 2 β€ 2 := pi_div_two_le_two
_ = 4 / 2 := by norm_num)
@[bound]
theorem pi_pos : 0 < Ο :=
lt_of_lt_of_le (by norm_num) two_le_pi
@[bound]
theorem pi_nonneg : 0 β€ Ο :=
pi_pos.le
theorem pi_ne_zero : Ο β 0 :=
pi_pos.ne'
theorem pi_div_two_pos : 0 < Ο / 2 :=
half_pos pi_pos
theorem two_pi_pos : 0 < 2 * Ο := by linarith [pi_pos]
end Real
namespace Mathlib.Meta.Positivity
open Lean.Meta Qq
/-- Extension for the `positivity` tactic: `Ο` is always positive. -/
@[positivity Real.pi]
def evalRealPi : PositivityExt where eval {u Ξ±} _zΞ± _pΞ± e := do
match u, Ξ±, e with
| 0, ~q(β), ~q(Real.pi) =>
assertInstancesCommute
pure (.positive q(Real.pi_pos))
| _, _, _ => throwError "not Real.pi"
end Mathlib.Meta.Positivity
namespace NNReal
open Real
open Real NNReal
/-- `Ο` considered as a nonnegative real. -/
noncomputable def pi : ββ₯0 :=
β¨Ο, Real.pi_pos.leβ©
@[simp]
theorem coe_real_pi : (pi : β) = Ο :=
rfl
theorem pi_pos : 0 < pi := mod_cast Real.pi_pos
theorem pi_ne_zero : pi β 0 :=
pi_pos.ne'
end NNReal
namespace Real
@[simp]
theorem sin_pi : sin Ο = 0 := by
rw [β mul_div_cancel_leftβ Ο (two_ne_zero' β), two_mul, add_div, sin_add, cos_pi_div_two]; simp
@[simp]
theorem cos_pi : cos Ο = -1 := by
rw [β mul_div_cancel_leftβ Ο (two_ne_zero' β), mul_div_assoc, cos_two_mul, cos_pi_div_two]
norm_num
@[simp]
theorem sin_two_pi : sin (2 * Ο) = 0 := by simp [two_mul, sin_add]
@[simp]
theorem cos_two_pi : cos (2 * Ο) = 1 := by simp [two_mul, cos_add]
theorem sin_antiperiodic : Function.Antiperiodic sin Ο := by simp [sin_add]
theorem sin_periodic : Function.Periodic sin (2 * Ο) :=
sin_antiperiodic.periodic_two_mul
@[simp]
theorem sin_add_pi (x : β) : sin (x + Ο) = -sin x :=
sin_antiperiodic x
@[simp]
theorem sin_add_two_pi (x : β) : sin (x + 2 * Ο) = sin x :=
sin_periodic x
@[simp]
theorem sin_sub_pi (x : β) : sin (x - Ο) = -sin x :=
sin_antiperiodic.sub_eq x
@[simp]
theorem sin_sub_two_pi (x : β) : sin (x - 2 * Ο) = sin x :=
sin_periodic.sub_eq x
@[simp]
theorem sin_pi_sub (x : β) : sin (Ο - x) = sin x :=
neg_neg (sin x) βΈ sin_neg x βΈ sin_antiperiodic.sub_eq'
@[simp]
theorem sin_two_pi_sub (x : β) : sin (2 * Ο - x) = -sin x :=
sin_neg x βΈ sin_periodic.sub_eq'
@[simp]
theorem sin_nat_mul_pi (n : β) : sin (n * Ο) = 0 :=
sin_antiperiodic.nat_mul_eq_of_eq_zero sin_zero n
@[simp]
theorem sin_int_mul_pi (n : β€) : sin (n * Ο) = 0 :=
sin_antiperiodic.int_mul_eq_of_eq_zero sin_zero n
@[simp]
theorem sin_add_nat_mul_two_pi (x : β) (n : β) : sin (x + n * (2 * Ο)) = sin x :=
sin_periodic.nat_mul n x
@[simp]
theorem sin_add_int_mul_two_pi (x : β) (n : β€) : sin (x + n * (2 * Ο)) = sin x :=
sin_periodic.int_mul n x
@[simp]
theorem sin_sub_nat_mul_two_pi (x : β) (n : β) : sin (x - n * (2 * Ο)) = sin x :=
sin_periodic.sub_nat_mul_eq n
@[simp]
theorem sin_sub_int_mul_two_pi (x : β) (n : β€) : sin (x - n * (2 * Ο)) = sin x :=
sin_periodic.sub_int_mul_eq n
@[simp]
theorem sin_nat_mul_two_pi_sub (x : β) (n : β) : sin (n * (2 * Ο) - x) = -sin x :=
sin_neg x βΈ sin_periodic.nat_mul_sub_eq n
@[simp]
theorem sin_int_mul_two_pi_sub (x : β) (n : β€) : sin (n * (2 * Ο) - x) = -sin x :=
sin_neg x βΈ sin_periodic.int_mul_sub_eq n
theorem sin_add_int_mul_pi (x : β) (n : β€) : sin (x + n * Ο) = (-1) ^ n * sin x :=
n.cast_negOnePow β βΈ sin_antiperiodic.add_int_mul_eq n
theorem sin_add_nat_mul_pi (x : β) (n : β) : sin (x + n * Ο) = (-1) ^ n * sin x :=
sin_antiperiodic.add_nat_mul_eq n
theorem sin_sub_int_mul_pi (x : β) (n : β€) : sin (x - n * Ο) = (-1) ^ n * sin x :=
n.cast_negOnePow β βΈ sin_antiperiodic.sub_int_mul_eq n
theorem sin_sub_nat_mul_pi (x : β) (n : β) : sin (x - n * Ο) = (-1) ^ n * sin x :=
sin_antiperiodic.sub_nat_mul_eq n
theorem sin_int_mul_pi_sub (x : β) (n : β€) : sin (n * Ο - x) = -((-1) ^ n * sin x) := by
simpa only [sin_neg, mul_neg, Int.cast_negOnePow] using sin_antiperiodic.int_mul_sub_eq n
theorem sin_nat_mul_pi_sub (x : β) (n : β) : sin (n * Ο - x) = -((-1) ^ n * sin x) := by
simpa only [sin_neg, mul_neg] using sin_antiperiodic.nat_mul_sub_eq n
theorem cos_antiperiodic : Function.Antiperiodic cos Ο := by simp [cos_add]
theorem cos_periodic : Function.Periodic cos (2 * Ο) :=
cos_antiperiodic.periodic_two_mul
@[simp]
theorem abs_cos_int_mul_pi (k : β€) : |cos (k * Ο)| = 1 := by
simp [abs_cos_eq_sqrt_one_sub_sin_sq]
@[simp]
theorem cos_add_pi (x : β) : cos (x + Ο) = -cos x :=
cos_antiperiodic x
@[simp]
theorem cos_add_two_pi (x : β) : cos (x + 2 * Ο) = cos x :=
cos_periodic x
@[simp]
theorem cos_sub_pi (x : β) : cos (x - Ο) = -cos x :=
cos_antiperiodic.sub_eq x
@[simp]
theorem cos_sub_two_pi (x : β) : cos (x - 2 * Ο) = cos x :=
cos_periodic.sub_eq x
@[simp]
theorem cos_pi_sub (x : β) : cos (Ο - x) = -cos x :=
cos_neg x βΈ cos_antiperiodic.sub_eq'
@[simp]
theorem cos_two_pi_sub (x : β) : cos (2 * Ο - x) = cos x :=
cos_neg x βΈ cos_periodic.sub_eq'
@[simp]
theorem cos_nat_mul_two_pi (n : β) : cos (n * (2 * Ο)) = 1 :=
(cos_periodic.nat_mul_eq n).trans cos_zero
@[simp]
theorem cos_int_mul_two_pi (n : β€) : cos (n * (2 * Ο)) = 1 :=
(cos_periodic.int_mul_eq n).trans cos_zero
@[simp]
theorem cos_add_nat_mul_two_pi (x : β) (n : β) : cos (x + n * (2 * Ο)) = cos x :=
cos_periodic.nat_mul n x
@[simp]
theorem cos_add_int_mul_two_pi (x : β) (n : β€) : cos (x + n * (2 * Ο)) = cos x :=
cos_periodic.int_mul n x
@[simp]
theorem cos_sub_nat_mul_two_pi (x : β) (n : β) : cos (x - n * (2 * Ο)) = cos x :=
cos_periodic.sub_nat_mul_eq n
@[simp]
theorem cos_sub_int_mul_two_pi (x : β) (n : β€) : cos (x - n * (2 * Ο)) = cos x :=
cos_periodic.sub_int_mul_eq n
@[simp]
theorem cos_nat_mul_two_pi_sub (x : β) (n : β) : cos (n * (2 * Ο) - x) = cos x :=
cos_neg x βΈ cos_periodic.nat_mul_sub_eq n
@[simp]
theorem cos_int_mul_two_pi_sub (x : β) (n : β€) : cos (n * (2 * Ο) - x) = cos x :=
cos_neg x βΈ cos_periodic.int_mul_sub_eq n
theorem cos_add_int_mul_pi (x : β) (n : β€) : cos (x + n * Ο) = (-1) ^ n * cos x :=
n.cast_negOnePow β βΈ cos_antiperiodic.add_int_mul_eq n
theorem cos_add_nat_mul_pi (x : β) (n : β) : cos (x + n * Ο) = (-1) ^ n * cos x :=
cos_antiperiodic.add_nat_mul_eq n
theorem cos_sub_int_mul_pi (x : β) (n : β€) : cos (x - n * Ο) = (-1) ^ n * cos x :=
n.cast_negOnePow β βΈ cos_antiperiodic.sub_int_mul_eq n
theorem cos_sub_nat_mul_pi (x : β) (n : β) : cos (x - n * Ο) = (-1) ^ n * cos x :=
cos_antiperiodic.sub_nat_mul_eq n
theorem cos_int_mul_pi_sub (x : β) (n : β€) : cos (n * Ο - x) = (-1) ^ n * cos x :=
n.cast_negOnePow β βΈ cos_neg x βΈ cos_antiperiodic.int_mul_sub_eq n
theorem cos_nat_mul_pi_sub (x : β) (n : β) : cos (n * Ο - x) = (-1) ^ n * cos x :=
cos_neg x βΈ cos_antiperiodic.nat_mul_sub_eq n
theorem cos_nat_mul_two_pi_add_pi (n : β) : cos (n * (2 * Ο) + Ο) = -1 := by
simpa only [cos_zero] using (cos_periodic.nat_mul n).add_antiperiod_eq cos_antiperiodic
theorem cos_int_mul_two_pi_add_pi (n : β€) : cos (n * (2 * Ο) + Ο) = -1 := by
simpa only [cos_zero] using (cos_periodic.int_mul n).add_antiperiod_eq cos_antiperiodic
theorem cos_nat_mul_two_pi_sub_pi (n : β) : cos (n * (2 * Ο) - Ο) = -1 := by
simpa only [cos_zero] using (cos_periodic.nat_mul n).sub_antiperiod_eq cos_antiperiodic
theorem cos_int_mul_two_pi_sub_pi (n : β€) : cos (n * (2 * Ο) - Ο) = -1 := by
simpa only [cos_zero] using (cos_periodic.int_mul n).sub_antiperiod_eq cos_antiperiodic
theorem sin_pos_of_pos_of_lt_pi {x : β} (h0x : 0 < x) (hxp : x < Ο) : 0 < sin x :=
if hx2 : x β€ 2 then sin_pos_of_pos_of_le_two h0x hx2
else
have : (2 : β) + 2 = 4 := by norm_num
have : Ο - x β€ 2 :=
sub_le_iff_le_add.2 (le_trans pi_le_four (this βΈ add_le_add_left (le_of_not_ge hx2) _))
sin_pi_sub x βΈ sin_pos_of_pos_of_le_two (sub_pos.2 hxp) this
theorem sin_pos_of_mem_Ioo {x : β} (hx : x β Ioo 0 Ο) : 0 < sin x :=
sin_pos_of_pos_of_lt_pi hx.1 hx.2
theorem sin_nonneg_of_mem_Icc {x : β} (hx : x β Icc 0 Ο) : 0 β€ sin x := by
rw [β closure_Ioo pi_ne_zero.symm] at hx
exact
closure_lt_subset_le continuous_const continuous_sin
(closure_mono (fun y => sin_pos_of_mem_Ioo) hx)
theorem sin_nonneg_of_nonneg_of_le_pi {x : β} (h0x : 0 β€ x) (hxp : x β€ Ο) : 0 β€ sin x :=
sin_nonneg_of_mem_Icc β¨h0x, hxpβ©
theorem sin_neg_of_neg_of_neg_pi_lt {x : β} (hx0 : x < 0) (hpx : -Ο < x) : sin x < 0 :=
neg_pos.1 <| sin_neg x βΈ sin_pos_of_pos_of_lt_pi (neg_pos.2 hx0) (neg_lt.1 hpx)
theorem sin_nonpos_of_nonnpos_of_neg_pi_le {x : β} (hx0 : x β€ 0) (hpx : -Ο β€ x) : sin x β€ 0 :=
neg_nonneg.1 <| sin_neg x βΈ sin_nonneg_of_nonneg_of_le_pi (neg_nonneg.2 hx0) (neg_le.1 hpx)
@[simp]
theorem sin_pi_div_two : sin (Ο / 2) = 1 :=
have : sin (Ο / 2) = 1 β¨ sin (Ο / 2) = -1 := by
simpa [sq, mul_self_eq_one_iff] using sin_sq_add_cos_sq (Ο / 2)
this.resolve_right fun h =>
show Β¬(0 : β) < -1 by norm_num <|
h βΈ sin_pos_of_pos_of_lt_pi pi_div_two_pos (half_lt_self pi_pos)
theorem sin_add_pi_div_two (x : β) : sin (x + Ο / 2) = cos x := by simp [sin_add]
theorem sin_sub_pi_div_two (x : β) : sin (x - Ο / 2) = -cos x := by simp [sub_eq_add_neg, sin_add]
theorem sin_pi_div_two_sub (x : β) : sin (Ο / 2 - x) = cos x := by simp [sub_eq_add_neg, sin_add]
theorem cos_add_pi_div_two (x : β) : cos (x + Ο / 2) = -sin x := by simp [cos_add]
theorem cos_sub_pi_div_two (x : β) : cos (x - Ο / 2) = sin x := by simp [sub_eq_add_neg, cos_add]
theorem cos_pi_div_two_sub (x : β) : cos (Ο / 2 - x) = sin x := by
rw [β cos_neg, neg_sub, cos_sub_pi_div_two]
theorem cos_pos_of_mem_Ioo {x : β} (hx : x β Ioo (-(Ο / 2)) (Ο / 2)) : 0 < cos x :=
sin_add_pi_div_two x βΈ sin_pos_of_mem_Ioo β¨by linarith [hx.1], by linarith [hx.2]β©
theorem cos_nonneg_of_mem_Icc {x : β} (hx : x β Icc (-(Ο / 2)) (Ο / 2)) : 0 β€ cos x :=
sin_add_pi_div_two x βΈ sin_nonneg_of_mem_Icc β¨by linarith [hx.1], by linarith [hx.2]β©
theorem cos_nonneg_of_neg_pi_div_two_le_of_le {x : β} (hl : -(Ο / 2) β€ x) (hu : x β€ Ο / 2) :
0 β€ cos x :=
cos_nonneg_of_mem_Icc β¨hl, huβ©
theorem cos_neg_of_pi_div_two_lt_of_lt {x : β} (hxβ : Ο / 2 < x) (hxβ : x < Ο + Ο / 2) :
cos x < 0 :=
neg_pos.1 <| cos_pi_sub x βΈ cos_pos_of_mem_Ioo β¨by linarith, by linarithβ©
theorem cos_nonpos_of_pi_div_two_le_of_le {x : β} (hxβ : Ο / 2 β€ x) (hxβ : x β€ Ο + Ο / 2) :
cos x β€ 0 :=
neg_nonneg.1 <| cos_pi_sub x βΈ cos_nonneg_of_mem_Icc β¨by linarith, by linarithβ©
theorem sin_eq_sqrt_one_sub_cos_sq {x : β} (hl : 0 β€ x) (hu : x β€ Ο) :
sin x = β(1 - cos x ^ 2) := by
rw [β abs_sin_eq_sqrt_one_sub_cos_sq, abs_of_nonneg (sin_nonneg_of_nonneg_of_le_pi hl hu)]
theorem cos_eq_sqrt_one_sub_sin_sq {x : β} (hl : -(Ο / 2) β€ x) (hu : x β€ Ο / 2) :
cos x = β(1 - sin x ^ 2) := by
rw [β abs_cos_eq_sqrt_one_sub_sin_sq, abs_of_nonneg (cos_nonneg_of_mem_Icc β¨hl, huβ©)]
lemma cos_half {x : β} (hl : -Ο β€ x) (hr : x β€ Ο) : cos (x / 2) = sqrt ((1 + cos x) / 2) := by
have : 0 β€ cos (x / 2) := cos_nonneg_of_mem_Icc <| by constructor <;> linarith
rw [β sqrt_sq this, cos_sq, add_div, two_mul, add_halves]
lemma abs_sin_half (x : β) : |sin (x / 2)| = sqrt ((1 - cos x) / 2) := by
rw [β sqrt_sq_eq_abs, sin_sq_eq_half_sub, two_mul, add_halves, sub_div]
lemma sin_half_eq_sqrt {x : β} (hl : 0 β€ x) (hr : x β€ 2 * Ο) :
sin (x / 2) = sqrt ((1 - cos x) / 2) := by
rw [β abs_sin_half, abs_of_nonneg]
apply sin_nonneg_of_nonneg_of_le_pi <;> linarith
lemma sin_half_eq_neg_sqrt {x : β} (hl : -(2 * Ο) β€ x) (hr : x β€ 0) :
sin (x / 2) = -sqrt ((1 - cos x) / 2) := by
rw [β abs_sin_half, abs_of_nonpos, neg_neg]
apply sin_nonpos_of_nonnpos_of_neg_pi_le <;> linarith
theorem sin_eq_zero_iff_of_lt_of_lt {x : β} (hxβ : -Ο < x) (hxβ : x < Ο) : sin x = 0 β x = 0 :=
β¨fun h => by
contrapose! h
cases h.lt_or_lt with
| inl h0 => exact (sin_neg_of_neg_of_neg_pi_lt h0 hxβ).ne
| inr h0 => exact (sin_pos_of_pos_of_lt_pi h0 hxβ).ne',
fun h => by simp [h]β©
theorem sin_eq_zero_iff {x : β} : sin x = 0 β β n : β€, (n : β) * Ο = x :=
β¨fun h =>
β¨βx / Οβ,
le_antisymm (sub_nonneg.1 (Int.sub_floor_div_mul_nonneg _ pi_pos))
(sub_nonpos.1 <|
le_of_not_gt fun hβ =>
(sin_pos_of_pos_of_lt_pi hβ (Int.sub_floor_div_mul_lt _ pi_pos)).ne
(by simp [sub_eq_add_neg, sin_add, h, sin_int_mul_pi]))β©,
fun β¨_, hnβ© => hn βΈ sin_int_mul_pi _β©
theorem sin_ne_zero_iff {x : β} : sin x β 0 β β n : β€, (n : β) * Ο β x := by
rw [β not_exists, not_iff_not, sin_eq_zero_iff]
theorem sin_eq_zero_iff_cos_eq {x : β} : sin x = 0 β cos x = 1 β¨ cos x = -1 := by
rw [β mul_self_eq_one_iff, β sin_sq_add_cos_sq x, sq, sq, β sub_eq_iff_eq_add, sub_self]
exact β¨fun h => by rw [h, mul_zero], eq_zero_of_mul_self_eq_zero β Eq.symmβ©
theorem cos_eq_one_iff (x : β) : cos x = 1 β β n : β€, (n : β) * (2 * Ο) = x :=
β¨fun h =>
let β¨n, hnβ© := sin_eq_zero_iff.1 (sin_eq_zero_iff_cos_eq.2 (Or.inl h))
β¨n / 2,
(Int.emod_two_eq_zero_or_one n).elim
(fun hn0 => by
rwa [β mul_assoc, β @Int.cast_two β, β Int.cast_mul,
Int.ediv_mul_cancel (Int.dvd_iff_emod_eq_zero.2 hn0)])
fun hn1 => by
rw [β Int.emod_add_ediv n 2, hn1, Int.cast_add, Int.cast_one, add_mul, one_mul, add_comm,
mul_comm (2 : β€), Int.cast_mul, mul_assoc, Int.cast_two] at hn
rw [β hn, cos_int_mul_two_pi_add_pi] at h
exact absurd h (by norm_num)β©,
fun β¨_, hnβ© => hn βΈ cos_int_mul_two_pi _β©
theorem cos_eq_one_iff_of_lt_of_lt {x : β} (hxβ : -(2 * Ο) < x) (hxβ : x < 2 * Ο) :
cos x = 1 β x = 0 :=
β¨fun h => by
rcases (cos_eq_one_iff _).1 h with β¨n, rflβ©
rw [mul_lt_iff_lt_one_left two_pi_pos] at hxβ
rw [neg_lt, neg_mul_eq_neg_mul, mul_lt_iff_lt_one_left two_pi_pos] at hxβ
norm_cast at hxβ hxβ
obtain rfl : n = 0 := le_antisymm (by omega) (by omega)
simp, fun h => by simp [h]β©
theorem sin_lt_sin_of_lt_of_le_pi_div_two {x y : β} (hxβ : -(Ο / 2) β€ x) (hyβ : y β€ Ο / 2)
(hxy : x < y) : sin x < sin y := by
rw [β sub_pos, sin_sub_sin]
have : 0 < sin ((y - x) / 2) := by apply sin_pos_of_pos_of_lt_pi <;> linarith
have : 0 < cos ((y + x) / 2) := by refine cos_pos_of_mem_Ioo β¨?_, ?_β© <;> linarith
positivity
theorem strictMonoOn_sin : StrictMonoOn sin (Icc (-(Ο / 2)) (Ο / 2)) := fun _ hx _ hy hxy =>
sin_lt_sin_of_lt_of_le_pi_div_two hx.1 hy.2 hxy
theorem cos_lt_cos_of_nonneg_of_le_pi {x y : β} (hxβ : 0 β€ x) (hyβ : y β€ Ο) (hxy : x < y) :
cos y < cos x := by
rw [β sin_pi_div_two_sub, β sin_pi_div_two_sub]
apply sin_lt_sin_of_lt_of_le_pi_div_two <;> linarith
theorem cos_lt_cos_of_nonneg_of_le_pi_div_two {x y : β} (hxβ : 0 β€ x) (hyβ : y β€ Ο / 2)
(hxy : x < y) : cos y < cos x :=
cos_lt_cos_of_nonneg_of_le_pi hxβ (hyβ.trans (by linarith)) hxy
theorem strictAntiOn_cos : StrictAntiOn cos (Icc 0 Ο) := fun _ hx _ hy hxy =>
cos_lt_cos_of_nonneg_of_le_pi hx.1 hy.2 hxy
theorem cos_le_cos_of_nonneg_of_le_pi {x y : β} (hxβ : 0 β€ x) (hyβ : y β€ Ο) (hxy : x β€ y) :
cos y β€ cos x :=
(strictAntiOn_cos.le_iff_le β¨hxβ.trans hxy, hyββ© β¨hxβ, hxy.trans hyββ©).2 hxy
theorem sin_le_sin_of_le_of_le_pi_div_two {x y : β} (hxβ : -(Ο / 2) β€ x) (hyβ : y β€ Ο / 2)
(hxy : x β€ y) : sin x β€ sin y :=
(strictMonoOn_sin.le_iff_le β¨hxβ, hxy.trans hyββ© β¨hxβ.trans hxy, hyββ©).2 hxy
theorem injOn_sin : InjOn sin (Icc (-(Ο / 2)) (Ο / 2)) :=
strictMonoOn_sin.injOn
theorem injOn_cos : InjOn cos (Icc 0 Ο) :=
strictAntiOn_cos.injOn
theorem surjOn_sin : SurjOn sin (Icc (-(Ο / 2)) (Ο / 2)) (Icc (-1) 1) := by
simpa only [sin_neg, sin_pi_div_two] using
intermediate_value_Icc (neg_le_self pi_div_two_pos.le) continuous_sin.continuousOn
theorem surjOn_cos : SurjOn cos (Icc 0 Ο) (Icc (-1) 1) := by
simpa only [cos_zero, cos_pi] using intermediate_value_Icc' pi_pos.le continuous_cos.continuousOn
theorem sin_mem_Icc (x : β) : sin x β Icc (-1 : β) 1 :=
β¨neg_one_le_sin x, sin_le_one xβ©
theorem cos_mem_Icc (x : β) : cos x β Icc (-1 : β) 1 :=
β¨neg_one_le_cos x, cos_le_one xβ©
theorem mapsTo_sin (s : Set β) : MapsTo sin s (Icc (-1 : β) 1) := fun x _ => sin_mem_Icc x
theorem mapsTo_cos (s : Set β) : MapsTo cos s (Icc (-1 : β) 1) := fun x _ => cos_mem_Icc x
theorem bijOn_sin : BijOn sin (Icc (-(Ο / 2)) (Ο / 2)) (Icc (-1) 1) :=
β¨mapsTo_sin _, injOn_sin, surjOn_sinβ©
theorem bijOn_cos : BijOn cos (Icc 0 Ο) (Icc (-1) 1) :=
β¨mapsTo_cos _, injOn_cos, surjOn_cosβ©
@[simp]
theorem range_cos : range cos = (Icc (-1) 1 : Set β) :=
Subset.antisymm (range_subset_iff.2 cos_mem_Icc) surjOn_cos.subset_range
@[simp]
theorem range_sin : range sin = (Icc (-1) 1 : Set β) :=
Subset.antisymm (range_subset_iff.2 sin_mem_Icc) surjOn_sin.subset_range
theorem range_cos_infinite : (range Real.cos).Infinite := by
rw [Real.range_cos]
exact Icc_infinite (by norm_num)
theorem range_sin_infinite : (range Real.sin).Infinite := by
rw [Real.range_sin]
exact Icc_infinite (by norm_num)
section CosDivSq
variable (x : β)
/-- the series `sqrtTwoAddSeries x n` is `sqrt(2 + sqrt(2 + ... ))` with `n` square roots,
starting with `x`. We define it here because `cos (pi / 2 ^ (n+1)) = sqrtTwoAddSeries 0 n / 2`
-/
@[simp]
noncomputable def sqrtTwoAddSeries (x : β) : β β β
| 0 => x
| n + 1 => β(2 + sqrtTwoAddSeries x n)
theorem sqrtTwoAddSeries_zero : sqrtTwoAddSeries x 0 = x := by simp
theorem sqrtTwoAddSeries_one : sqrtTwoAddSeries 0 1 = β2 := by simp
theorem sqrtTwoAddSeries_two : sqrtTwoAddSeries 0 2 = β(2 + β2) := by simp
theorem sqrtTwoAddSeries_zero_nonneg : β n : β, 0 β€ sqrtTwoAddSeries 0 n
| 0 => le_refl 0
| _ + 1 => sqrt_nonneg _
theorem sqrtTwoAddSeries_nonneg {x : β} (h : 0 β€ x) : β n : β, 0 β€ sqrtTwoAddSeries x n
| 0 => h
| _ + 1 => sqrt_nonneg _
theorem sqrtTwoAddSeries_lt_two : β n : β, sqrtTwoAddSeries 0 n < 2
| 0 => by norm_num
| n + 1 => by
refine lt_of_lt_of_le ?_ (sqrt_sq zero_lt_two.le).le
rw [sqrtTwoAddSeries, sqrt_lt_sqrt_iff, β lt_sub_iff_add_lt']
Β· refine (sqrtTwoAddSeries_lt_two n).trans_le ?_
norm_num
Β· exact add_nonneg zero_le_two (sqrtTwoAddSeries_zero_nonneg n)
theorem sqrtTwoAddSeries_succ (x : β) :
β n : β, sqrtTwoAddSeries x (n + 1) = sqrtTwoAddSeries (β(2 + x)) n
| 0 => rfl
| n + 1 => by rw [sqrtTwoAddSeries, sqrtTwoAddSeries_succ _ _, sqrtTwoAddSeries]
theorem sqrtTwoAddSeries_monotone_left {x y : β} (h : x β€ y) :
β n : β, sqrtTwoAddSeries x n β€ sqrtTwoAddSeries y n
| 0 => h
| n + 1 => by
rw [sqrtTwoAddSeries, sqrtTwoAddSeries]
exact sqrt_le_sqrt (add_le_add_left (sqrtTwoAddSeries_monotone_left h _) _)
@[simp]
theorem cos_pi_over_two_pow : β n : β, cos (Ο / 2 ^ (n + 1)) = sqrtTwoAddSeries 0 n / 2
| 0 => by simp
| n + 1 => by
have A : (1 : β) < 2 ^ (n + 1) := one_lt_powβ one_lt_two n.succ_ne_zero
have B : Ο / 2 ^ (n + 1) < Ο := div_lt_self pi_pos A
have C : 0 < Ο / 2 ^ (n + 1) := by positivity
rw [pow_succ, div_mul_eq_div_div, cos_half, cos_pi_over_two_pow n, sqrtTwoAddSeries,
add_div_eq_mul_add_div, one_mul, β div_mul_eq_div_div, sqrt_div, sqrt_mul_self] <;>
linarith [sqrtTwoAddSeries_nonneg le_rfl n]
theorem sin_sq_pi_over_two_pow (n : β) :
sin (Ο / 2 ^ (n + 1)) ^ 2 = 1 - (sqrtTwoAddSeries 0 n / 2) ^ 2 := by
rw [sin_sq, cos_pi_over_two_pow]
theorem sin_sq_pi_over_two_pow_succ (n : β) :
sin (Ο / 2 ^ (n + 2)) ^ 2 = 1 / 2 - sqrtTwoAddSeries 0 n / 4 := by
rw [sin_sq_pi_over_two_pow, sqrtTwoAddSeries, div_pow, sq_sqrt, add_div, β sub_sub]
Β· congr
Β· norm_num
Β· norm_num
Β· exact add_nonneg two_pos.le (sqrtTwoAddSeries_zero_nonneg _)
@[simp]
theorem sin_pi_over_two_pow_succ (n : β) :
sin (Ο / 2 ^ (n + 2)) = β(2 - sqrtTwoAddSeries 0 n) / 2 := by
rw [eq_div_iff_mul_eq two_ne_zero, eq_comm, sqrt_eq_iff_eq_sq, mul_pow,
sin_sq_pi_over_two_pow_succ, sub_mul]
Β· congr <;> norm_num
Β· rw [sub_nonneg]
exact (sqrtTwoAddSeries_lt_two _).le
refine mul_nonneg (sin_nonneg_of_nonneg_of_le_pi ?_ ?_) zero_le_two
Β· positivity
Β· exact div_le_self pi_pos.le <| one_le_powβ one_le_two
@[simp]
theorem cos_pi_div_four : cos (Ο / 4) = β2 / 2 := by
trans cos (Ο / 2 ^ 2)
Β· congr
norm_num
Β· simp
@[simp]
theorem sin_pi_div_four : sin (Ο / 4) = β2 / 2 := by
trans sin (Ο / 2 ^ 2)
Β· congr
norm_num
Β· simp
@[simp]
theorem cos_pi_div_eight : cos (Ο / 8) = β(2 + β2) / 2 := by
trans cos (Ο / 2 ^ 3)
Β· congr
norm_num
Β· simp
@[simp]
theorem sin_pi_div_eight : sin (Ο / 8) = β(2 - β2) / 2 := by
trans sin (Ο / 2 ^ 3)
Β· congr
norm_num
Β· simp
@[simp]
theorem cos_pi_div_sixteen : cos (Ο / 16) = β(2 + β(2 + β2)) / 2 := by
trans cos (Ο / 2 ^ 4)
Β· congr
norm_num
Β· simp
@[simp]
theorem sin_pi_div_sixteen : sin (Ο / 16) = β(2 - β(2 + β2)) / 2 := by
trans sin (Ο / 2 ^ 4)
Β· congr
norm_num
Β· simp
@[simp]
theorem cos_pi_div_thirty_two : cos (Ο / 32) = β(2 + β(2 + β(2 + β2))) / 2 := by
trans cos (Ο / 2 ^ 5)
Β· congr
norm_num
Β· simp
@[simp]
theorem sin_pi_div_thirty_two : sin (Ο / 32) = β(2 - β(2 + β(2 + β2))) / 2 := by
trans sin (Ο / 2 ^ 5)
Β· congr
norm_num
Β· simp
-- This section is also a convenient location for other explicit values of `sin` and `cos`.
/-- The cosine of `Ο / 3` is `1 / 2`. -/
@[simp]
theorem cos_pi_div_three : cos (Ο / 3) = 1 / 2 := by
have hβ : (2 * cos (Ο / 3) - 1) ^ 2 * (2 * cos (Ο / 3) + 2) = 0 := by
have : cos (3 * (Ο / 3)) = cos Ο := by
congr 1
ring
linarith [cos_pi, cos_three_mul (Ο / 3)]
rcases mul_eq_zero.mp hβ with h | h
Β· linarith [pow_eq_zero h]
Β· have : cos Ο < cos (Ο / 3) := by
refine cos_lt_cos_of_nonneg_of_le_pi ?_ le_rfl ?_ <;> linarith [pi_pos]
linarith [cos_pi]
/-- The cosine of `Ο / 6` is `β3 / 2`. -/
@[simp]
theorem cos_pi_div_six : cos (Ο / 6) = β3 / 2 := by
rw [show (6 : β) = 3 * 2 by norm_num, div_mul_eq_div_div, cos_half, cos_pi_div_three, one_add_div,
β div_mul_eq_div_div, two_add_one_eq_three, sqrt_div, sqrt_mul_self] <;> linarith [pi_pos]
/-- The square of the cosine of `Ο / 6` is `3 / 4` (this is sometimes more convenient than the
result for cosine itself). -/
theorem sq_cos_pi_div_six : cos (Ο / 6) ^ 2 = 3 / 4 := by
rw [cos_pi_div_six, div_pow, sq_sqrt] <;> norm_num
/-- The sine of `Ο / 6` is `1 / 2`. -/
@[simp]
theorem sin_pi_div_six : sin (Ο / 6) = 1 / 2 := by
rw [β cos_pi_div_two_sub, β cos_pi_div_three]
congr
ring
/-- The square of the sine of `Ο / 3` is `3 / 4` (this is sometimes more convenient than the
result for cosine itself). -/
theorem sq_sin_pi_div_three : sin (Ο / 3) ^ 2 = 3 / 4 := by
rw [β cos_pi_div_two_sub, β sq_cos_pi_div_six]
congr
ring
/-- The sine of `Ο / 3` is `β3 / 2`. -/
@[simp]
theorem sin_pi_div_three : sin (Ο / 3) = β3 / 2 := by
rw [β cos_pi_div_two_sub, β cos_pi_div_six]
congr
ring
theorem quadratic_root_cos_pi_div_five :
letI c := cos (Ο / 5)
4 * c ^ 2 - 2 * c - 1 = 0 := by
set ΞΈ := Ο / 5 with hΞΈ
set c := cos ΞΈ
set s := sin ΞΈ
suffices 2 * c = 4 * c ^ 2 - 1 by simp [this]
have hs : s β 0 := by
rw [ne_eq, sin_eq_zero_iff, hΞΈ]
push_neg
intro n hn
replace hn : n * 5 = 1 := by field_simp [mul_comm _ Ο, mul_assoc] at hn; norm_cast at hn
omega
suffices s * (2 * c) = s * (4 * c ^ 2 - 1) from mul_left_cancelβ hs this
calc s * (2 * c) = 2 * s * c := by rw [β mul_assoc, mul_comm 2]
_ = sin (2 * ΞΈ) := by rw [sin_two_mul]
_ = sin (Ο - 2 * ΞΈ) := by rw [sin_pi_sub]
_ = sin (2 * ΞΈ + ΞΈ) := by congr; field_simp [hΞΈ]; linarith
_ = sin (2 * ΞΈ) * c + cos (2 * ΞΈ) * s := sin_add (2 * ΞΈ) ΞΈ
_ = 2 * s * c * c + cos (2 * ΞΈ) * s := by rw [sin_two_mul]
_ = 2 * s * c * c + (2 * c ^ 2 - 1) * s := by rw [cos_two_mul]
_ = s * (2 * c * c) + s * (2 * c ^ 2 - 1) := by linarith
_ = s * (4 * c ^ 2 - 1) := by linarith
open Polynomial in
theorem Polynomial.isRoot_cos_pi_div_five :
(4 β’ X ^ 2 - 2 β’ X - C 1 : β[X]).IsRoot (cos (Ο / 5)) := by
simpa using quadratic_root_cos_pi_div_five
/-- The cosine of `Ο / 5` is `(1 + β5) / 4`. -/
@[simp]
theorem cos_pi_div_five : cos (Ο / 5) = (1 + β5) / 4 := by
set c := cos (Ο / 5)
have : 4 * (c * c) + (-2) * c + (-1) = 0 := by
rw [β sq, neg_mul, β sub_eq_add_neg, β sub_eq_add_neg]
exact quadratic_root_cos_pi_div_five
have hd : discrim 4 (-2) (-1) = (2 * β5) * (2 * β5) := by norm_num [discrim, mul_mul_mul_comm]
rcases (quadratic_eq_zero_iff (by norm_num) hd c).mp this with h | h
Β· field_simp [h]; linarith
Β· absurd (show 0 β€ c from cos_nonneg_of_mem_Icc <| by constructor <;> linarith [pi_pos.le])
rw [not_le, h]
exact div_neg_of_neg_of_pos (by norm_num [lt_sqrt]) (by positivity)
end CosDivSq
/-- `Real.sin` as an `OrderIso` between `[-(Ο / 2), Ο / 2]` and `[-1, 1]`. -/
def sinOrderIso : Icc (-(Ο / 2)) (Ο / 2) βo Icc (-1 : β) 1 :=
(strictMonoOn_sin.orderIso _ _).trans <| OrderIso.setCongr _ _ bijOn_sin.image_eq
@[simp]
theorem coe_sinOrderIso_apply (x : Icc (-(Ο / 2)) (Ο / 2)) : (sinOrderIso x : β) = sin x :=
rfl
theorem sinOrderIso_apply (x : Icc (-(Ο / 2)) (Ο / 2)) : sinOrderIso x = β¨sin x, sin_mem_Icc xβ© :=
rfl
@[simp]
theorem tan_pi_div_four : tan (Ο / 4) = 1 := by
rw [tan_eq_sin_div_cos, cos_pi_div_four, sin_pi_div_four]
have h : β2 / 2 > 0 := by positivity
exact div_self (ne_of_gt h)
@[simp]
theorem tan_pi_div_two : tan (Ο / 2) = 0 := by simp [tan_eq_sin_div_cos]
@[simp]
theorem tan_pi_div_six : tan (Ο / 6) = 1 / sqrt 3 := by
rw [tan_eq_sin_div_cos, sin_pi_div_six, cos_pi_div_six]
ring
@[simp]
theorem tan_pi_div_three : tan (Ο / 3) = sqrt 3 := by
rw [tan_eq_sin_div_cos, sin_pi_div_three, cos_pi_div_three]
ring
theorem tan_pos_of_pos_of_lt_pi_div_two {x : β} (h0x : 0 < x) (hxp : x < Ο / 2) : 0 < tan x := by
rw [tan_eq_sin_div_cos]
exact div_pos (sin_pos_of_pos_of_lt_pi h0x (by linarith)) (cos_pos_of_mem_Ioo β¨by linarith, hxpβ©)
theorem tan_nonneg_of_nonneg_of_le_pi_div_two {x : β} (h0x : 0 β€ x) (hxp : x β€ Ο / 2) : 0 β€ tan x :=
match lt_or_eq_of_le h0x, lt_or_eq_of_le hxp with
| Or.inl hx0, Or.inl hxp => le_of_lt (tan_pos_of_pos_of_lt_pi_div_two hx0 hxp)
| Or.inl _, Or.inr hxp => by simp [hxp, tan_eq_sin_div_cos]
| Or.inr hx0, _ => by simp [hx0.symm]
theorem tan_neg_of_neg_of_pi_div_two_lt {x : β} (hx0 : x < 0) (hpx : -(Ο / 2) < x) : tan x < 0 :=
neg_pos.1 (tan_neg x βΈ tan_pos_of_pos_of_lt_pi_div_two (by linarith) (by linarith [pi_pos]))
theorem tan_nonpos_of_nonpos_of_neg_pi_div_two_le {x : β} (hx0 : x β€ 0) (hpx : -(Ο / 2) β€ x) :
tan x β€ 0 :=
neg_nonneg.1 (tan_neg x βΈ tan_nonneg_of_nonneg_of_le_pi_div_two (by linarith) (by linarith))
theorem strictMonoOn_tan : StrictMonoOn tan (Ioo (-(Ο / 2)) (Ο / 2)) := by
rintro x hx y hy hlt
rw [tan_eq_sin_div_cos, tan_eq_sin_div_cos,
div_lt_div_iffβ (cos_pos_of_mem_Ioo hx) (cos_pos_of_mem_Ioo hy), mul_comm, β sub_pos, β sin_sub]
exact sin_pos_of_pos_of_lt_pi (sub_pos.2 hlt) <| by linarith [hx.1, hy.2]
theorem tan_lt_tan_of_lt_of_lt_pi_div_two {x y : β} (hxβ : -(Ο / 2) < x) (hyβ : y < Ο / 2)
(hxy : x < y) : tan x < tan y :=
strictMonoOn_tan β¨hxβ, hxy.trans hyββ© β¨hxβ.trans hxy, hyββ© hxy
theorem tan_lt_tan_of_nonneg_of_lt_pi_div_two {x y : β} (hxβ : 0 β€ x) (hyβ : y < Ο / 2)
(hxy : x < y) : tan x < tan y :=
tan_lt_tan_of_lt_of_lt_pi_div_two (by linarith) hyβ hxy
theorem injOn_tan : InjOn tan (Ioo (-(Ο / 2)) (Ο / 2)) :=
strictMonoOn_tan.injOn
theorem tan_inj_of_lt_of_lt_pi_div_two {x y : β} (hxβ : -(Ο / 2) < x) (hxβ : x < Ο / 2)
(hyβ : -(Ο / 2) < y) (hyβ : y < Ο / 2) (hxy : tan x = tan y) : x = y :=
injOn_tan β¨hxβ, hxββ© β¨hyβ, hyββ© hxy
theorem tan_periodic : Function.Periodic tan Ο := by
simpa only [Function.Periodic, tan_eq_sin_div_cos] using sin_antiperiodic.div cos_antiperiodic
@[simp]
theorem tan_pi : tan Ο = 0 := by rw [tan_periodic.eq, tan_zero]
theorem tan_add_pi (x : β) : tan (x + Ο) = tan x :=
tan_periodic x
theorem tan_sub_pi (x : β) : tan (x - Ο) = tan x :=
tan_periodic.sub_eq x
theorem tan_pi_sub (x : β) : tan (Ο - x) = -tan x :=
tan_neg x βΈ tan_periodic.sub_eq'
theorem tan_pi_div_two_sub (x : β) : tan (Ο / 2 - x) = (tan x)β»ΒΉ := by
rw [tan_eq_sin_div_cos, tan_eq_sin_div_cos, inv_div, sin_pi_div_two_sub, cos_pi_div_two_sub]
theorem tan_nat_mul_pi (n : β) : tan (n * Ο) = 0 :=
tan_zero βΈ tan_periodic.nat_mul_eq n
theorem tan_int_mul_pi (n : β€) : tan (n * Ο) = 0 :=
tan_zero βΈ tan_periodic.int_mul_eq n
theorem tan_add_nat_mul_pi (x : β) (n : β) : tan (x + n * Ο) = tan x :=
tan_periodic.nat_mul n x
theorem tan_add_int_mul_pi (x : β) (n : β€) : tan (x + n * Ο) = tan x :=
tan_periodic.int_mul n x
theorem tan_sub_nat_mul_pi (x : β) (n : β) : tan (x - n * Ο) = tan x :=
tan_periodic.sub_nat_mul_eq n
theorem tan_sub_int_mul_pi (x : β) (n : β€) : tan (x - n * Ο) = tan x :=
tan_periodic.sub_int_mul_eq n
theorem tan_nat_mul_pi_sub (x : β) (n : β) : tan (n * Ο - x) = -tan x :=
tan_neg x βΈ tan_periodic.nat_mul_sub_eq n
theorem tan_int_mul_pi_sub (x : β) (n : β€) : tan (n * Ο - x) = -tan x :=
tan_neg x βΈ tan_periodic.int_mul_sub_eq n
theorem tendsto_sin_pi_div_two : Tendsto sin (π[<] (Ο / 2)) (π 1) := by
convert continuous_sin.continuousWithinAt.tendsto
simp
theorem tendsto_cos_pi_div_two : Tendsto cos (π[<] (Ο / 2)) (π[>] 0) := by
apply tendsto_nhdsWithin_of_tendsto_nhds_of_eventually_within
Β· convert continuous_cos.continuousWithinAt.tendsto
simp
Β· filter_upwards [Ioo_mem_nhdsLT (neg_lt_self pi_div_two_pos)] with x hx
exact cos_pos_of_mem_Ioo hx
theorem tendsto_tan_pi_div_two : Tendsto tan (π[<] (Ο / 2)) atTop := by
convert tendsto_cos_pi_div_two.inv_tendsto_nhdsGT_zero.atTop_mul_pos zero_lt_one
tendsto_sin_pi_div_two using 1
simp only [Pi.inv_apply, β div_eq_inv_mul, β tan_eq_sin_div_cos]
theorem tendsto_sin_neg_pi_div_two : Tendsto sin (π[>] (-(Ο / 2))) (π (-1)) := by
convert continuous_sin.continuousWithinAt.tendsto using 2
simp
theorem tendsto_cos_neg_pi_div_two : Tendsto cos (π[>] (-(Ο / 2))) (π[>] 0) := by
apply tendsto_nhdsWithin_of_tendsto_nhds_of_eventually_within
Β· convert continuous_cos.continuousWithinAt.tendsto
simp
Β· filter_upwards [Ioo_mem_nhdsGT (neg_lt_self pi_div_two_pos)] with x hx
exact cos_pos_of_mem_Ioo hx
theorem tendsto_tan_neg_pi_div_two : Tendsto tan (π[>] (-(Ο / 2))) atBot := by
convert tendsto_cos_neg_pi_div_two.inv_tendsto_nhdsGT_zero.atTop_mul_neg (by norm_num)
tendsto_sin_neg_pi_div_two using 1
simp only [Pi.inv_apply, β div_eq_inv_mul, β tan_eq_sin_div_cos]
end Real
namespace Complex
open Real
theorem sin_eq_zero_iff_cos_eq {z : β} : sin z = 0 β cos z = 1 β¨ cos z = -1 := by
rw [β mul_self_eq_one_iff, β sin_sq_add_cos_sq, sq, sq, β sub_eq_iff_eq_add, sub_self]
exact β¨fun h => by rw [h, mul_zero], eq_zero_of_mul_self_eq_zero β Eq.symmβ©
@[simp]
theorem cos_pi_div_two : cos (Ο / 2) = 0 :=
calc
cos (Ο / 2) = Real.cos (Ο / 2) := by rw [ofReal_cos]; simp
_ = 0 := by simp
@[simp]
theorem sin_pi_div_two : sin (Ο / 2) = 1 :=
calc
sin (Ο / 2) = Real.sin (Ο / 2) := by rw [ofReal_sin]; simp
_ = 1 := by simp
@[simp]
theorem sin_pi : sin Ο = 0 := by rw [β ofReal_sin, Real.sin_pi]; simp
@[simp]
theorem cos_pi : cos Ο = -1 := by rw [β ofReal_cos, Real.cos_pi]; simp
@[simp]
theorem sin_two_pi : sin (2 * Ο) = 0 := by simp [two_mul, sin_add]
@[simp]
theorem cos_two_pi : cos (2 * Ο) = 1 := by simp [two_mul, cos_add]
theorem sin_antiperiodic : Function.Antiperiodic sin Ο := by simp [sin_add]
theorem sin_periodic : Function.Periodic sin (2 * Ο) :=
sin_antiperiodic.periodic_two_mul
theorem sin_add_pi (x : β) : sin (x + Ο) = -sin x :=
sin_antiperiodic x
theorem sin_add_two_pi (x : β) : sin (x + 2 * Ο) = sin x :=
sin_periodic x
theorem sin_sub_pi (x : β) : sin (x - Ο) = -sin x :=
sin_antiperiodic.sub_eq x
theorem sin_sub_two_pi (x : β) : sin (x - 2 * Ο) = sin x :=
sin_periodic.sub_eq x
theorem sin_pi_sub (x : β) : sin (Ο - x) = sin x :=
neg_neg (sin x) βΈ sin_neg x βΈ sin_antiperiodic.sub_eq'
theorem sin_two_pi_sub (x : β) : sin (2 * Ο - x) = -sin x :=
sin_neg x βΈ sin_periodic.sub_eq'
theorem sin_nat_mul_pi (n : β) : sin (n * Ο) = 0 :=
sin_antiperiodic.nat_mul_eq_of_eq_zero sin_zero n
theorem sin_int_mul_pi (n : β€) : sin (n * Ο) = 0 :=
sin_antiperiodic.int_mul_eq_of_eq_zero sin_zero n
theorem sin_add_nat_mul_two_pi (x : β) (n : β) : sin (x + n * (2 * Ο)) = sin x :=
sin_periodic.nat_mul n x
theorem sin_add_int_mul_two_pi (x : β) (n : β€) : sin (x + n * (2 * Ο)) = sin x :=
sin_periodic.int_mul n x
theorem sin_sub_nat_mul_two_pi (x : β) (n : β) : sin (x - n * (2 * Ο)) = sin x :=
sin_periodic.sub_nat_mul_eq n
theorem sin_sub_int_mul_two_pi (x : β) (n : β€) : sin (x - n * (2 * Ο)) = sin x :=
sin_periodic.sub_int_mul_eq n
theorem sin_nat_mul_two_pi_sub (x : β) (n : β) : sin (n * (2 * Ο) - x) = -sin x :=
sin_neg x βΈ sin_periodic.nat_mul_sub_eq n
theorem sin_int_mul_two_pi_sub (x : β) (n : β€) : sin (n * (2 * Ο) - x) = -sin x :=
sin_neg x βΈ sin_periodic.int_mul_sub_eq n
theorem cos_antiperiodic : Function.Antiperiodic cos Ο := by simp [cos_add]
theorem cos_periodic : Function.Periodic cos (2 * Ο) :=
cos_antiperiodic.periodic_two_mul
theorem cos_add_pi (x : β) : cos (x + Ο) = -cos x :=
cos_antiperiodic x
theorem cos_add_two_pi (x : β) : cos (x + 2 * Ο) = cos x :=
cos_periodic x
theorem cos_sub_pi (x : β) : cos (x - Ο) = -cos x :=
cos_antiperiodic.sub_eq x
theorem cos_sub_two_pi (x : β) : cos (x - 2 * Ο) = cos x :=
cos_periodic.sub_eq x
theorem cos_pi_sub (x : β) : cos (Ο - x) = -cos x :=
cos_neg x βΈ cos_antiperiodic.sub_eq'
theorem cos_two_pi_sub (x : β) : cos (2 * Ο - x) = cos x :=
cos_neg x βΈ cos_periodic.sub_eq'
theorem cos_nat_mul_two_pi (n : β) : cos (n * (2 * Ο)) = 1 :=
(cos_periodic.nat_mul_eq n).trans cos_zero
theorem cos_int_mul_two_pi (n : β€) : cos (n * (2 * Ο)) = 1 :=
(cos_periodic.int_mul_eq n).trans cos_zero
theorem cos_add_nat_mul_two_pi (x : β) (n : β) : cos (x + n * (2 * Ο)) = cos x :=
cos_periodic.nat_mul n x
theorem cos_add_int_mul_two_pi (x : β) (n : β€) : cos (x + n * (2 * Ο)) = cos x :=
cos_periodic.int_mul n x
theorem cos_sub_nat_mul_two_pi (x : β) (n : β) : cos (x - n * (2 * Ο)) = cos x :=
cos_periodic.sub_nat_mul_eq n
theorem cos_sub_int_mul_two_pi (x : β) (n : β€) : cos (x - n * (2 * Ο)) = cos x :=
cos_periodic.sub_int_mul_eq n
theorem cos_nat_mul_two_pi_sub (x : β) (n : β) : cos (n * (2 * Ο) - x) = cos x :=
cos_neg x βΈ cos_periodic.nat_mul_sub_eq n
theorem cos_int_mul_two_pi_sub (x : β) (n : β€) : cos (n * (2 * Ο) - x) = cos x :=
cos_neg x βΈ cos_periodic.int_mul_sub_eq n
theorem cos_nat_mul_two_pi_add_pi (n : β) : cos (n * (2 * Ο) + Ο) = -1 := by
simpa only [cos_zero] using (cos_periodic.nat_mul n).add_antiperiod_eq cos_antiperiodic
theorem cos_int_mul_two_pi_add_pi (n : β€) : cos (n * (2 * Ο) + Ο) = -1 := by
simpa only [cos_zero] using (cos_periodic.int_mul n).add_antiperiod_eq cos_antiperiodic
theorem cos_nat_mul_two_pi_sub_pi (n : β) : cos (n * (2 * Ο) - Ο) = -1 := by
simpa only [cos_zero] using (cos_periodic.nat_mul n).sub_antiperiod_eq cos_antiperiodic
theorem cos_int_mul_two_pi_sub_pi (n : β€) : cos (n * (2 * Ο) - Ο) = -1 := by
simpa only [cos_zero] using (cos_periodic.int_mul n).sub_antiperiod_eq cos_antiperiodic
theorem sin_add_pi_div_two (x : β) : sin (x + Ο / 2) = cos x := by simp [sin_add]
theorem sin_sub_pi_div_two (x : β) : sin (x - Ο / 2) = -cos x := by simp [sub_eq_add_neg, sin_add]
theorem sin_pi_div_two_sub (x : β) : sin (Ο / 2 - x) = cos x := by simp [sub_eq_add_neg, sin_add]
theorem cos_add_pi_div_two (x : β) : cos (x + Ο / 2) = -sin x := by simp [cos_add]
theorem cos_sub_pi_div_two (x : β) : cos (x - Ο / 2) = sin x := by simp [sub_eq_add_neg, cos_add]
theorem cos_pi_div_two_sub (x : β) : cos (Ο / 2 - x) = sin x := by
rw [β cos_neg, neg_sub, cos_sub_pi_div_two]
theorem tan_periodic : Function.Periodic tan Ο := by
simpa only [tan_eq_sin_div_cos] using sin_antiperiodic.div cos_antiperiodic
theorem tan_add_pi (x : β) : tan (x + Ο) = tan x :=
tan_periodic x
theorem tan_sub_pi (x : β) : tan (x - Ο) = tan x :=
tan_periodic.sub_eq x
theorem tan_pi_sub (x : β) : tan (Ο - x) = -tan x :=
tan_neg x βΈ tan_periodic.sub_eq'
theorem tan_pi_div_two_sub (x : β) : tan (Ο / 2 - x) = (tan x)β»ΒΉ := by
rw [tan_eq_sin_div_cos, tan_eq_sin_div_cos, inv_div, sin_pi_div_two_sub, cos_pi_div_two_sub]
theorem tan_nat_mul_pi (n : β) : tan (n * Ο) = 0 :=
tan_zero βΈ tan_periodic.nat_mul_eq n
theorem tan_int_mul_pi (n : β€) : tan (n * Ο) = 0 :=
tan_zero βΈ tan_periodic.int_mul_eq n
theorem tan_add_nat_mul_pi (x : β) (n : β) : tan (x + n * Ο) = tan x :=
tan_periodic.nat_mul n x
theorem tan_add_int_mul_pi (x : β) (n : β€) : tan (x + n * Ο) = tan x :=
tan_periodic.int_mul n x
theorem tan_sub_nat_mul_pi (x : β) (n : β) : tan (x - n * Ο) = tan x :=
tan_periodic.sub_nat_mul_eq n
theorem tan_sub_int_mul_pi (x : β) (n : β€) : tan (x - n * Ο) = tan x :=
tan_periodic.sub_int_mul_eq n
theorem tan_nat_mul_pi_sub (x : β) (n : β) : tan (n * Ο - x) = -tan x :=
tan_neg x βΈ tan_periodic.nat_mul_sub_eq n
theorem tan_int_mul_pi_sub (x : β) (n : β€) : tan (n * Ο - x) = -tan x :=
tan_neg x βΈ tan_periodic.int_mul_sub_eq n
theorem exp_antiperiodic : Function.Antiperiodic exp (Ο * I) := by simp [exp_add, exp_mul_I]
theorem exp_periodic : Function.Periodic exp (2 * Ο * I) :=
(mul_assoc (2 : β) Ο I).symm βΈ exp_antiperiodic.periodic_two_mul
theorem exp_mul_I_antiperiodic : Function.Antiperiodic (fun x => exp (x * I)) Ο := by
simpa only [mul_inv_cancel_rightβ I_ne_zero] using exp_antiperiodic.mul_const I_ne_zero
theorem exp_mul_I_periodic : Function.Periodic (fun x => exp (x * I)) (2 * Ο) :=
exp_mul_I_antiperiodic.periodic_two_mul
@[simp]
theorem exp_pi_mul_I : exp (Ο * I) = -1 :=
exp_zero βΈ exp_antiperiodic.eq
@[simp]
theorem exp_two_pi_mul_I : exp (2 * Ο * I) = 1 :=
exp_periodic.eq.trans exp_zero
@[simp]
lemma exp_pi_div_two_mul_I : exp (Ο / 2 * I) = I := by
rw [β cos_add_sin_I, cos_pi_div_two, sin_pi_div_two, one_mul, zero_add]
@[simp]
lemma exp_neg_pi_div_two_mul_I : exp (-Ο / 2 * I) = -I := by
rw [β cos_add_sin_I, neg_div, cos_neg, cos_pi_div_two, sin_neg, sin_pi_div_two, zero_add, neg_mul,
one_mul]
@[simp]
theorem exp_nat_mul_two_pi_mul_I (n : β) : exp (n * (2 * Ο * I)) = 1 :=
(exp_periodic.nat_mul_eq n).trans exp_zero
@[simp]
theorem exp_int_mul_two_pi_mul_I (n : β€) : exp (n * (2 * Ο * I)) = 1 :=
(exp_periodic.int_mul_eq n).trans exp_zero
@[simp]
theorem exp_add_pi_mul_I (z : β) : exp (z + Ο * I) = -exp z :=
exp_antiperiodic z
@[simp]
theorem exp_sub_pi_mul_I (z : β) : exp (z - Ο * I) = -exp z :=
exp_antiperiodic.sub_eq z
/-- A supporting lemma for the **Phragmen-LindelΓΆf principle** in a horizontal strip. If `z : β`
belongs to a horizontal strip `|Complex.im z| β€ b`, `b β€ Ο / 2`, and `a β€ 0`, then
$$\left|exp^{a\left(e^{z}+e^{-z}\right)}\right| \le e^{a\cos b \exp^{|re z|}}.$$
-/
theorem norm_exp_mul_exp_add_exp_neg_le_of_abs_im_le {a b : β} (ha : a β€ 0) {z : β}
(hz : |z.im| β€ b) (hb : b β€ Ο / 2) :
βexp (a * (exp z + exp (-z)))β β€ Real.exp (a * Real.cos b * Real.exp |z.re|) := by
simp only [norm_exp, Real.exp_le_exp, re_ofReal_mul, add_re, exp_re, neg_im, Real.cos_neg, β
add_mul, mul_assoc, mul_comm (Real.cos b), neg_re, β Real.cos_abs z.im]
have : Real.exp |z.re| β€ Real.exp z.re + Real.exp (-z.re) :=
apply_abs_le_add_of_nonneg (fun x => (Real.exp_pos x).le) z.re
refine mul_le_mul_of_nonpos_left (mul_le_mul this ?_ ?_ ((Real.exp_pos _).le.trans this)) ha
Β· exact
Real.cos_le_cos_of_nonneg_of_le_pi (_root_.abs_nonneg _)
(hb.trans <| half_le_self <| Real.pi_pos.le) hz
Β· refine Real.cos_nonneg_of_mem_Icc β¨?_, hbβ©
exact (neg_nonpos.2 <| Real.pi_div_two_pos.le).trans ((_root_.abs_nonneg _).trans hz)
@[deprecated (since := "2025-02-16")] alias abs_exp_mul_exp_add_exp_neg_le_of_abs_im_le :=
norm_exp_mul_exp_add_exp_neg_le_of_abs_im_le
end Complex
| Mathlib/Analysis/SpecialFunctions/Trigonometric/Basic.lean | 1,301 | 1,301 | |
/-
Copyright (c) 2020 Anatole Dedecker. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Anatole Dedecker
-/
import Mathlib.Analysis.Calculus.Deriv.Inv
import Mathlib.Analysis.Calculus.Deriv.MeanValue
/-!
# L'HΓ΄pital's rule for 0/0 indeterminate forms
In this file, we prove several forms of "L'HΓ΄pital's rule" for computing 0/0
indeterminate forms. The proof of `HasDerivAt.lhopital_zero_right_on_Ioo`
is based on the one given in the corresponding
[Wikibooks](https://en.wikibooks.org/wiki/Calculus/L%27H%C3%B4pital%27s_Rule)
chapter, and all other statements are derived from this one by composing by
carefully chosen functions.
Note that the filter `f'/g'` tends to isn't required to be one of `π a`,
`atTop` or `atBot`. In fact, we give a slightly stronger statement by
allowing it to be any filter on `β`.
Each statement is available in a `HasDerivAt` form and a `deriv` form, which
is denoted by each statement being in either the `HasDerivAt` or the `deriv`
namespace.
## Tags
L'HΓ΄pital's rule, L'Hopital's rule
-/
open Filter Set
open scoped Filter Topology Pointwise
variable {a b : β} {l : Filter β} {f f' g g' : β β β}
/-!
## Interval-based versions
We start by proving statements where all conditions (derivability, `g' β 0`) have
to be satisfied on an explicitly-provided interval.
-/
namespace HasDerivAt
theorem lhopital_zero_right_on_Ioo (hab : a < b) (hff' : β x β Ioo a b, HasDerivAt f (f' x) x)
(hgg' : β x β Ioo a b, HasDerivAt g (g' x) x) (hg' : β x β Ioo a b, g' x β 0)
(hfa : Tendsto f (π[>] a) (π 0)) (hga : Tendsto g (π[>] a) (π 0))
(hdiv : Tendsto (fun x => f' x / g' x) (π[>] a) l) :
Tendsto (fun x => f x / g x) (π[>] a) l := by
have sub : β x β Ioo a b, Ioo a x β Ioo a b := fun x hx =>
Ioo_subset_Ioo (le_refl a) (le_of_lt hx.2)
have hg : β x β Ioo a b, g x β 0 := by
intro x hx h
have : Tendsto g (π[<] x) (π 0) := by
rw [β h, β nhdsWithin_Ioo_eq_nhdsLT hx.1]
exact ((hgg' x hx).continuousAt.continuousWithinAt.mono <| sub x hx).tendsto
obtain β¨y, hyx, hyβ© : β c β Ioo a x, g' c = 0 :=
exists_hasDerivAt_eq_zero' hx.1 hga this fun y hy => hgg' y <| sub x hx hy
exact hg' y (sub x hx hyx) hy
have : β x β Ioo a b, β c β Ioo a x, f x * g' c = g x * f' c := by
intro x hx
rw [β sub_zero (f x), β sub_zero (g x)]
exact exists_ratio_hasDerivAt_eq_ratio_slope' g g' hx.1 f f' (fun y hy => hgg' y <| sub x hx hy)
(fun y hy => hff' y <| sub x hx hy) hga hfa
(tendsto_nhdsWithin_of_tendsto_nhds (hgg' x hx).continuousAt.tendsto)
(tendsto_nhdsWithin_of_tendsto_nhds (hff' x hx).continuousAt.tendsto)
choose! c hc using this
have : β x β Ioo a b, ((fun x' => f' x' / g' x') β c) x = f x / g x := by
intro x hx
rcases hc x hx with β¨hβ, hββ©
field_simp [hg x hx, hg' (c x) ((sub x hx) hβ)]
simp only [hβ]
rw [mul_comm]
have cmp : β x β Ioo a b, a < c x β§ c x < x := fun x hx => (hc x hx).1
rw [β nhdsWithin_Ioo_eq_nhdsGT hab]
apply tendsto_nhdsWithin_congr this
apply hdiv.comp
refine tendsto_nhdsWithin_of_tendsto_nhds_of_eventually_within _
(tendsto_of_tendsto_of_tendsto_of_le_of_le' tendsto_const_nhds
(tendsto_nhdsWithin_of_tendsto_nhds tendsto_id) ?_ ?_) ?_
all_goals
apply eventually_nhdsWithin_of_forall
intro x hx
have := cmp x hx
try simp
linarith [this]
theorem lhopital_zero_right_on_Ico (hab : a < b) (hff' : β x β Ioo a b, HasDerivAt f (f' x) x)
(hgg' : β x β Ioo a b, HasDerivAt g (g' x) x) (hcf : ContinuousOn f (Ico a b))
(hcg : ContinuousOn g (Ico a b)) (hg' : β x β Ioo a b, g' x β 0) (hfa : f a = 0) (hga : g a = 0)
(hdiv : Tendsto (fun x => f' x / g' x) (π[>] a) l) :
Tendsto (fun x => f x / g x) (π[>] a) l := by
refine lhopital_zero_right_on_Ioo hab hff' hgg' hg' ?_ ?_ hdiv
Β· rw [β hfa, β nhdsWithin_Ioo_eq_nhdsGT hab]
exact ((hcf a <| left_mem_Ico.mpr hab).mono Ioo_subset_Ico_self).tendsto
Β· rw [β hga, β nhdsWithin_Ioo_eq_nhdsGT hab]
exact ((hcg a <| left_mem_Ico.mpr hab).mono Ioo_subset_Ico_self).tendsto
theorem lhopital_zero_left_on_Ioo (hab : a < b) (hff' : β x β Ioo a b, HasDerivAt f (f' x) x)
(hgg' : β x β Ioo a b, HasDerivAt g (g' x) x) (hg' : β x β Ioo a b, g' x β 0)
(hfb : Tendsto f (π[<] b) (π 0)) (hgb : Tendsto g (π[<] b) (π 0))
(hdiv : Tendsto (fun x => f' x / g' x) (π[<] b) l) :
Tendsto (fun x => f x / g x) (π[<] b) l := by
-- Here, we essentially compose by `Neg.neg`. The following is mostly technical details.
have hdnf : β x β -Ioo a b, HasDerivAt (f β Neg.neg) (f' (-x) * -1) x := fun x hx =>
comp x (hff' (-x) hx) (hasDerivAt_neg x)
have hdng : β x β -Ioo a b, HasDerivAt (g β Neg.neg) (g' (-x) * -1) x := fun x hx =>
comp x (hgg' (-x) hx) (hasDerivAt_neg x)
rw [neg_Ioo] at hdnf
rw [neg_Ioo] at hdng
have := lhopital_zero_right_on_Ioo (neg_lt_neg hab) hdnf hdng (by
intro x hx h
apply hg' _ (by rw [β neg_Ioo] at hx; exact hx)
rwa [mul_comm, β neg_eq_neg_one_mul, neg_eq_zero] at h)
(hfb.comp tendsto_neg_nhdsGT_neg) (hgb.comp tendsto_neg_nhdsGT_neg)
(by
simp only [neg_div_neg_eq, mul_one, mul_neg]
exact hdiv.comp tendsto_neg_nhdsGT_neg)
have := this.comp tendsto_neg_nhdsLT
unfold Function.comp at this
simpa only [neg_neg]
theorem lhopital_zero_left_on_Ioc (hab : a < b) (hff' : β x β Ioo a b, HasDerivAt f (f' x) x)
(hgg' : β x β Ioo a b, HasDerivAt g (g' x) x) (hcf : ContinuousOn f (Ioc a b))
(hcg : ContinuousOn g (Ioc a b)) (hg' : β x β Ioo a b, g' x β 0) (hfb : f b = 0) (hgb : g b = 0)
(hdiv : Tendsto (fun x => f' x / g' x) (π[<] b) l) :
Tendsto (fun x => f x / g x) (π[<] b) l := by
refine lhopital_zero_left_on_Ioo hab hff' hgg' hg' ?_ ?_ hdiv
Β· rw [β hfb, β nhdsWithin_Ioo_eq_nhdsLT hab]
exact ((hcf b <| right_mem_Ioc.mpr hab).mono Ioo_subset_Ioc_self).tendsto
Β· rw [β hgb, β nhdsWithin_Ioo_eq_nhdsLT hab]
exact ((hcg b <| right_mem_Ioc.mpr hab).mono Ioo_subset_Ioc_self).tendsto
theorem lhopital_zero_atTop_on_Ioi (hff' : β x β Ioi a, HasDerivAt f (f' x) x)
(hgg' : β x β Ioi a, HasDerivAt g (g' x) x) (hg' : β x β Ioi a, g' x β 0)
(hftop : Tendsto f atTop (π 0)) (hgtop : Tendsto g atTop (π 0))
(hdiv : Tendsto (fun x => f' x / g' x) atTop l) : Tendsto (fun x => f x / g x) atTop l := by
obtain β¨a', haa', ha'β© : β a', a < a' β§ 0 < a' := β¨1 + max a 0,
β¨lt_of_le_of_lt (le_max_left a 0) (lt_one_add _),
lt_of_le_of_lt (le_max_right a 0) (lt_one_add _)β©β©
have fact1 : β x : β, x β Ioo 0 a'β»ΒΉ β x β 0 := fun _ hx => (ne_of_lt hx.1).symm
have fact2 (x) (hx : x β Ioo 0 a'β»ΒΉ) : a < xβ»ΒΉ := lt_trans haa' ((lt_inv_commβ ha' hx.1).mpr hx.2)
have hdnf : β x β Ioo 0 a'β»ΒΉ, HasDerivAt (f β Inv.inv) (f' xβ»ΒΉ * -(x ^ 2)β»ΒΉ) x := fun x hx =>
comp x (hff' xβ»ΒΉ <| fact2 x hx) (hasDerivAt_inv <| fact1 x hx)
have hdng : β x β Ioo 0 a'β»ΒΉ, HasDerivAt (g β Inv.inv) (g' xβ»ΒΉ * -(x ^ 2)β»ΒΉ) x := fun x hx =>
comp x (hgg' xβ»ΒΉ <| fact2 x hx) (hasDerivAt_inv <| fact1 x hx)
have := lhopital_zero_right_on_Ioo (inv_pos.mpr ha') hdnf hdng
(by
intro x hx
refine mul_ne_zero ?_ (neg_ne_zero.mpr <| inv_ne_zero <| pow_ne_zero _ <| fact1 x hx)
exact hg' _ (fact2 x hx))
(hftop.comp tendsto_inv_nhdsGT_zero) (hgtop.comp tendsto_inv_nhdsGT_zero)
(by
refine (tendsto_congr' ?_).mp (hdiv.comp tendsto_inv_nhdsGT_zero)
filter_upwards [self_mem_nhdsWithin] with x (hx : 0 < x)
simp only [Function.comp_def]
rw [mul_div_mul_right]
exact neg_ne_zero.mpr (by positivity))
have := this.comp tendsto_inv_atTop_nhdsGT_zero
unfold Function.comp at this
simpa only [inv_inv]
theorem lhopital_zero_atBot_on_Iio (hff' : β x β Iio a, HasDerivAt f (f' x) x)
(hgg' : β x β Iio a, HasDerivAt g (g' x) x) (hg' : β x β Iio a, g' x β 0)
(hfbot : Tendsto f atBot (π 0)) (hgbot : Tendsto g atBot (π 0))
(hdiv : Tendsto (fun x => f' x / g' x) atBot l) : Tendsto (fun x => f x / g x) atBot l := by
-- Here, we essentially compose by `Neg.neg`. The following is mostly technical details.
have hdnf : β x β -Iio a, HasDerivAt (f β Neg.neg) (f' (-x) * -1) x := fun x hx =>
comp x (hff' (-x) hx) (hasDerivAt_neg x)
have hdng : β x β -Iio a, HasDerivAt (g β Neg.neg) (g' (-x) * -1) x := fun x hx =>
comp x (hgg' (-x) hx) (hasDerivAt_neg x)
rw [neg_Iio] at hdnf
rw [neg_Iio] at hdng
have := lhopital_zero_atTop_on_Ioi hdnf hdng
(by
intro x hx h
apply hg' _ (by rw [β neg_Iio] at hx; exact hx)
rwa [mul_comm, β neg_eq_neg_one_mul, neg_eq_zero] at h)
(hfbot.comp tendsto_neg_atTop_atBot) (hgbot.comp tendsto_neg_atTop_atBot)
(by
simp only [mul_one, mul_neg, neg_div_neg_eq]
exact (hdiv.comp tendsto_neg_atTop_atBot))
have := this.comp tendsto_neg_atBot_atTop
unfold Function.comp at this
simpa only [neg_neg]
end HasDerivAt
namespace deriv
theorem lhopital_zero_right_on_Ioo (hab : a < b) (hdf : DifferentiableOn β f (Ioo a b))
(hg' : β x β Ioo a b, deriv g x β 0) (hfa : Tendsto f (π[>] a) (π 0))
(hga : Tendsto g (π[>] a) (π 0))
(hdiv : Tendsto (fun x => (deriv f) x / (deriv g) x) (π[>] a) l) :
Tendsto (fun x => f x / g x) (π[>] a) l := by
have hdf : β x β Ioo a b, DifferentiableAt β f x := fun x hx =>
(hdf x hx).differentiableAt (Ioo_mem_nhds hx.1 hx.2)
have hdg : β x β Ioo a b, DifferentiableAt β g x := fun x hx =>
by_contradiction fun h => hg' x hx (deriv_zero_of_not_differentiableAt h)
exact HasDerivAt.lhopital_zero_right_on_Ioo hab (fun x hx => (hdf x hx).hasDerivAt)
(fun x hx => (hdg x hx).hasDerivAt) hg' hfa hga hdiv
theorem lhopital_zero_right_on_Ico (hab : a < b) (hdf : DifferentiableOn β f (Ioo a b))
(hcf : ContinuousOn f (Ico a b)) (hcg : ContinuousOn g (Ico a b))
(hg' : β x β Ioo a b, (deriv g) x β 0) (hfa : f a = 0) (hga : g a = 0)
(hdiv : Tendsto (fun x => (deriv f) x / (deriv g) x) (π[>] a) l) :
Tendsto (fun x => f x / g x) (π[>] a) l := by
refine lhopital_zero_right_on_Ioo hab hdf hg' ?_ ?_ hdiv
Β· rw [β hfa, β nhdsWithin_Ioo_eq_nhdsGT hab]
exact ((hcf a <| left_mem_Ico.mpr hab).mono Ioo_subset_Ico_self).tendsto
Β· rw [β hga, β nhdsWithin_Ioo_eq_nhdsGT hab]
exact ((hcg a <| left_mem_Ico.mpr hab).mono Ioo_subset_Ico_self).tendsto
theorem lhopital_zero_left_on_Ioo (hab : a < b) (hdf : DifferentiableOn β f (Ioo a b))
(hg' : β x β Ioo a b, (deriv g) x β 0) (hfb : Tendsto f (π[<] b) (π 0))
(hgb : Tendsto g (π[<] b) (π 0))
(hdiv : Tendsto (fun x => (deriv f) x / (deriv g) x) (π[<] b) l) :
Tendsto (fun x => f x / g x) (π[<] b) l := by
have hdf : β x β Ioo a b, DifferentiableAt β f x := fun x hx =>
(hdf x hx).differentiableAt (Ioo_mem_nhds hx.1 hx.2)
have hdg : β x β Ioo a b, DifferentiableAt β g x := fun x hx =>
by_contradiction fun h => hg' x hx (deriv_zero_of_not_differentiableAt h)
exact HasDerivAt.lhopital_zero_left_on_Ioo hab (fun x hx => (hdf x hx).hasDerivAt)
(fun x hx => (hdg x hx).hasDerivAt) hg' hfb hgb hdiv
theorem lhopital_zero_atTop_on_Ioi (hdf : DifferentiableOn β f (Ioi a))
(hg' : β x β Ioi a, (deriv g) x β 0) (hftop : Tendsto f atTop (π 0))
(hgtop : Tendsto g atTop (π 0)) (hdiv : Tendsto (fun x => (deriv f) x / (deriv g) x) atTop l) :
Tendsto (fun x => f x / g x) atTop l := by
have hdf : β x β Ioi a, DifferentiableAt β f x := fun x hx =>
(hdf x hx).differentiableAt (Ioi_mem_nhds hx)
have hdg : β x β Ioi a, DifferentiableAt β g x := fun x hx =>
by_contradiction fun h => hg' x hx (deriv_zero_of_not_differentiableAt h)
exact HasDerivAt.lhopital_zero_atTop_on_Ioi (fun x hx => (hdf x hx).hasDerivAt)
(fun x hx => (hdg x hx).hasDerivAt) hg' hftop hgtop hdiv
theorem lhopital_zero_atBot_on_Iio (hdf : DifferentiableOn β f (Iio a))
(hg' : β x β Iio a, (deriv g) x β 0) (hfbot : Tendsto f atBot (π 0))
(hgbot : Tendsto g atBot (π 0)) (hdiv : Tendsto (fun x => (deriv f) x / (deriv g) x) atBot l) :
Tendsto (fun x => f x / g x) atBot l := by
have hdf : β x β Iio a, DifferentiableAt β f x := fun x hx =>
(hdf x hx).differentiableAt (Iio_mem_nhds hx)
have hdg : β x β Iio a, DifferentiableAt β g x := fun x hx =>
by_contradiction fun h => hg' x hx (deriv_zero_of_not_differentiableAt h)
exact HasDerivAt.lhopital_zero_atBot_on_Iio (fun x hx => (hdf x hx).hasDerivAt)
(fun x hx => (hdg x hx).hasDerivAt) hg' hfbot hgbot hdiv
end deriv
/-!
## Generic versions
The following statements no longer any explicit interval, as they only require
conditions holding eventually.
-/
namespace HasDerivAt
/-- L'HΓ΄pital's rule for approaching a real from the right, `HasDerivAt` version -/
theorem lhopital_zero_nhdsGT (hff' : βαΆ x in π[>] a, HasDerivAt f (f' x) x)
(hgg' : βαΆ x in π[>] a, HasDerivAt g (g' x) x) (hg' : βαΆ x in π[>] a, g' x β 0)
(hfa : Tendsto f (π[>] a) (π 0)) (hga : Tendsto g (π[>] a) (π 0))
(hdiv : Tendsto (fun x => f' x / g' x) (π[>] a) l) :
Tendsto (fun x => f x / g x) (π[>] a) l := by
rw [eventually_iff_exists_mem] at *
rcases hff' with β¨sβ, hsβ, hff'β©
rcases hgg' with β¨sβ, hsβ, hgg'β©
rcases hg' with β¨sβ, hsβ, hg'β©
let s := sβ β© sβ β© sβ
have hs : s β π[>] a := inter_mem (inter_mem hsβ hsβ) hsβ
rw [mem_nhdsGT_iff_exists_Ioo_subset] at hs
rcases hs with β¨u, hau, huβ©
refine lhopital_zero_right_on_Ioo hau ?_ ?_ ?_ hfa hga hdiv <;>
intro x hx <;> apply_assumption <;>
first | exact (hu hx).1.1 | exact (hu hx).1.2 | exact (hu hx).2
@[deprecated (since := "2025-03-02")]
alias lhopital_zero_nhds_right := lhopital_zero_nhdsGT
/-- L'HΓ΄pital's rule for approaching a real from the left, `HasDerivAt` version -/
theorem lhopital_zero_nhdsLT (hff' : βαΆ x in π[<] a, HasDerivAt f (f' x) x)
(hgg' : βαΆ x in π[<] a, HasDerivAt g (g' x) x) (hg' : βαΆ x in π[<] a, g' x β 0)
(hfa : Tendsto f (π[<] a) (π 0)) (hga : Tendsto g (π[<] a) (π 0))
(hdiv : Tendsto (fun x => f' x / g' x) (π[<] a) l) :
Tendsto (fun x => f x / g x) (π[<] a) l := by
rw [eventually_iff_exists_mem] at *
rcases hff' with β¨sβ, hsβ, hff'β©
rcases hgg' with β¨sβ, hsβ, hgg'β©
rcases hg' with β¨sβ, hsβ, hg'β©
let s := sβ β© sβ β© sβ
have hs : s β π[<] a := inter_mem (inter_mem hsβ hsβ) hsβ
rw [mem_nhdsLT_iff_exists_Ioo_subset] at hs
rcases hs with β¨l, hal, hlβ©
refine lhopital_zero_left_on_Ioo hal ?_ ?_ ?_ hfa hga hdiv <;> intro x hx <;> apply_assumption <;>
first | exact (hl hx).1.1| exact (hl hx).1.2| exact (hl hx).2
|
@[deprecated (since := "2025-03-02")]
alias lhopital_zero_nhds_left := lhopital_zero_nhdsLT
/-- L'HΓ΄pital's rule for approaching a real, `HasDerivAt` version. This
does not require anything about the situation at `a` -/
theorem lhopital_zero_nhdsNE (hff' : βαΆ x in π[β ] a, HasDerivAt f (f' x) x)
(hgg' : βαΆ x in π[β ] a, HasDerivAt g (g' x) x) (hg' : βαΆ x in π[β ] a, g' x β 0)
(hfa : Tendsto f (π[β ] a) (π 0)) (hga : Tendsto g (π[β ] a) (π 0))
(hdiv : Tendsto (fun x => f' x / g' x) (π[β ] a) l) :
Tendsto (fun x => f x / g x) (π[β ] a) l := by
simp only [β Iio_union_Ioi, nhdsWithin_union, tendsto_sup, eventually_sup] at *
exact β¨lhopital_zero_nhdsLT hff'.1 hgg'.1 hg'.1 hfa.1 hga.1 hdiv.1,
lhopital_zero_nhdsGT hff'.2 hgg'.2 hg'.2 hfa.2 hga.2 hdiv.2β©
| Mathlib/Analysis/Calculus/LHopital.lean | 300 | 314 |
/-
Copyright (c) 2020 Anne Baanen. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Anne Baanen, Kexing Ying, Moritz Doll
-/
import Mathlib.Algebra.GroupWithZero.Action.Opposite
import Mathlib.LinearAlgebra.Finsupp.VectorSpace
import Mathlib.LinearAlgebra.Matrix.Basis
import Mathlib.LinearAlgebra.Matrix.Nondegenerate
import Mathlib.LinearAlgebra.Matrix.NonsingularInverse
import Mathlib.LinearAlgebra.Matrix.ToLinearEquiv
import Mathlib.LinearAlgebra.SesquilinearForm
import Mathlib.LinearAlgebra.Basis.Bilinear
/-!
# Sesquilinear form
This file defines the conversion between sesquilinear maps and matrices.
## Main definitions
* `Matrix.toLinearMapβ` given a basis define a bilinear map
* `Matrix.toLinearMapβ'` define the bilinear map on `n β R`
* `LinearMap.toMatrixβ`: calculate the matrix coefficients of a bilinear map
* `LinearMap.toMatrixβ'`: calculate the matrix coefficients of a bilinear map on `n β R`
## TODO
At the moment this is quite a literal port from `Matrix.BilinearForm`. Everything should be
generalized to fully semibilinear forms.
## Tags
Sesquilinear form, Sesquilinear map, matrix, basis
-/
variable {R Rβ Sβ Rβ Sβ Mβ Mβ Mβ' Mβ' Nβ n m n' m' ΞΉ : Type*}
open Finset LinearMap Matrix
open Matrix
open scoped RightActions
section AuxToLinearMap
variable [Semiring Rβ] [Semiring Sβ] [Semiring Rβ] [Semiring Sβ] [AddCommMonoid Nβ]
[Module Sβ Nβ] [Module Sβ Nβ] [SMulCommClass Sβ Sβ Nβ]
variable [Fintype n] [Fintype m]
variable (Οβ : Rβ β+* Sβ) (Οβ : Rβ β+* Sβ)
/-- The map from `Matrix n n R` to bilinear maps on `n β R`.
This is an auxiliary definition for the equivalence `Matrix.toLinearMapβ'`. -/
def Matrix.toLinearMapβ'Aux (f : Matrix n m Nβ) : (n β Rβ) βββ[Οβ] (m β Rβ) βββ[Οβ] Nβ :=
-- porting note: we don't seem to have `β i j` as valid notation yet
mkβ'ββ Οβ Οβ (fun (v : n β Rβ) (w : m β Rβ) => β i, β j, Οβ (w j) β’ Οβ (v i) β’ f i j)
(fun _ _ _ => by simp only [Pi.add_apply, map_add, smul_add, sum_add_distrib, add_smul])
(fun c v w => by
simp only [Pi.smul_apply, smul_sum, smul_eq_mul, Οβ.map_mul, β smul_comm _ (Οβ c),
MulAction.mul_smul])
(fun _ _ _ => by simp only [Pi.add_apply, map_add, add_smul, smul_add, sum_add_distrib])
(fun _ v w => by
simp only [Pi.smul_apply, smul_eq_mul, map_mul, MulAction.mul_smul, smul_sum])
variable [DecidableEq n] [DecidableEq m]
theorem Matrix.toLinearMapβ'Aux_single (f : Matrix n m Nβ) (i : n) (j : m) :
f.toLinearMapβ'Aux Οβ Οβ (Pi.single i 1) (Pi.single j 1) = f i j := by
rw [Matrix.toLinearMapβ'Aux, mkβ'ββ_apply]
have : (β i', β j', (if i = i' then (1 : Sβ) else (0 : Sβ)) β’
(if j = j' then (1 : Sβ) else (0 : Sβ)) β’ f i' j') =
f i j := by
simp_rw [β Finset.smul_sum]
simp only [op_smul_eq_smul, ite_smul, one_smul, zero_smul, sum_ite_eq, mem_univ, βreduceIte]
rw [β this]
exact Finset.sum_congr rfl fun _ _ => Finset.sum_congr rfl fun _ _ => by aesop
end AuxToLinearMap
section AuxToMatrix
section CommSemiring
variable [CommSemiring R] [Semiring Rβ] [Semiring Sβ] [Semiring Rβ] [Semiring Sβ]
variable [AddCommMonoid Mβ] [Module Rβ Mβ] [AddCommMonoid Mβ] [Module Rβ Mβ] [AddCommMonoid Nβ]
[Module R Nβ] [Module Sβ Nβ] [Module Sβ Nβ] [SMulCommClass Sβ R Nβ] [SMulCommClass Sβ R Nβ]
[SMulCommClass Sβ Sβ Nβ]
variable {Οβ : Rβ β+* Sβ} {Οβ : Rβ β+* Sβ}
variable (R)
/-- The linear map from sesquilinear maps to `Matrix n m Nβ` given an `n`-indexed basis for `Mβ`
and an `m`-indexed basis for `Mβ`.
This is an auxiliary definition for the equivalence `Matrix.toLinearMapβββ'`. -/
def LinearMap.toMatrixβAux (bβ : n β Mβ) (bβ : m β Mβ) :
(Mβ βββ[Οβ] Mβ βββ[Οβ] Nβ) ββ[R] Matrix n m Nβ where
toFun f := of fun i j => f (bβ i) (bβ j)
map_add' _f _g := rfl
map_smul' _f _g := rfl
@[simp]
theorem LinearMap.toMatrixβAux_apply (f : Mβ βββ[Οβ] Mβ βββ[Οβ] Nβ) (bβ : n β Mβ) (bβ : m β Mβ)
(i : n) (j : m) : LinearMap.toMatrixβAux R bβ bβ f i j = f (bβ i) (bβ j) :=
rfl
variable [Fintype n] [Fintype m]
variable [DecidableEq n] [DecidableEq m]
theorem LinearMap.toLinearMapβ'Aux_toMatrixβAux (f : (n β Rβ) βββ[Οβ] (m β Rβ) βββ[Οβ] Nβ) :
Matrix.toLinearMapβ'Aux Οβ Οβ
(LinearMap.toMatrixβAux R (fun i => Pi.single i 1) (fun j => Pi.single j 1) f) =
f := by
refine ext_basis (Pi.basisFun Rβ n) (Pi.basisFun Rβ m) fun i j => ?_
simp_rw [Pi.basisFun_apply, Matrix.toLinearMapβ'Aux_single, LinearMap.toMatrixβAux_apply]
theorem Matrix.toMatrixβAux_toLinearMapβ'Aux (f : Matrix n m Nβ) :
LinearMap.toMatrixβAux R (fun i => Pi.single i 1)
(fun j => Pi.single j 1) (f.toLinearMapβ'Aux Οβ Οβ) =
f := by
ext i j
simp_rw [LinearMap.toMatrixβAux_apply, Matrix.toLinearMapβ'Aux_single]
end CommSemiring
end AuxToMatrix
section ToMatrix'
/-! ### Bilinear maps over `n β R`
This section deals with the conversion between matrices and sesquilinear maps on `n β R`.
-/
variable [CommSemiring R] [AddCommMonoid Nβ] [Module R Nβ] [Semiring Rβ] [Semiring Rβ]
[Semiring Sβ] [Semiring Sβ] [Module Sβ Nβ] [Module Sβ Nβ]
[SMulCommClass Sβ R Nβ] [SMulCommClass Sβ R Nβ] [SMulCommClass Sβ Sβ Nβ]
variable {Οβ : Rβ β+* Sβ} {Οβ : Rβ β+* Sβ}
variable [Fintype n] [Fintype m]
variable [DecidableEq n] [DecidableEq m]
variable (R)
/-- The linear equivalence between sesquilinear maps and `n Γ m` matrices -/
def LinearMap.toMatrixβββ' : ((n β Rβ) βββ[Οβ] (m β Rβ) βββ[Οβ] Nβ) ββ[R] Matrix n m Nβ :=
{ LinearMap.toMatrixβAux R (fun i => Pi.single i 1) (fun j => Pi.single j 1) with
toFun := LinearMap.toMatrixβAux R _ _
invFun := Matrix.toLinearMapβ'Aux Οβ Οβ
left_inv := LinearMap.toLinearMapβ'Aux_toMatrixβAux R
right_inv := Matrix.toMatrixβAux_toLinearMapβ'Aux R }
/-- The linear equivalence between bilinear maps and `n Γ m` matrices -/
def LinearMap.toMatrixβ' : ((n β Sβ) ββ[Sβ] (m β Sβ) ββ[Sβ] Nβ) ββ[R] Matrix n m Nβ :=
LinearMap.toMatrixβββ' R
variable (Οβ Οβ)
/-- The linear equivalence between `n Γ n` matrices and sesquilinear maps on `n β R` -/
def Matrix.toLinearMapβββ' : Matrix n m Nβ ββ[R] (n β Rβ) βββ[Οβ] (m β Rβ) βββ[Οβ] Nβ :=
(LinearMap.toMatrixβββ' R).symm
/-- The linear equivalence between `n Γ n` matrices and bilinear maps on `n β R` -/
def Matrix.toLinearMapβ' : Matrix n m Nβ ββ[R] (n β Sβ) ββ[Sβ] (m β Sβ) ββ[Sβ] Nβ :=
(LinearMap.toMatrixβ' R).symm
variable {R}
theorem Matrix.toLinearMapβββ'_aux_eq (M : Matrix n m Nβ) :
Matrix.toLinearMapβ'Aux Οβ Οβ M = Matrix.toLinearMapβββ' R Οβ Οβ M :=
rfl
theorem Matrix.toLinearMapβββ'_apply (M : Matrix n m Nβ) (x : n β Rβ) (y : m β Rβ) :
-- porting note: we don't seem to have `β i j` as valid notation yet
Matrix.toLinearMapβββ' R Οβ Οβ M x y = β i, β j, Οβ (x i) β’ Οβ (y j) β’ M i j := by
rw [toLinearMapβββ', toMatrixβββ', LinearEquiv.coe_symm_mk, toLinearMapβ'Aux, mkβ'ββ_apply]
apply Finset.sum_congr rfl fun _ _ => Finset.sum_congr rfl fun _ _ => by
rw [smul_comm]
theorem Matrix.toLinearMapβ'_apply (M : Matrix n m Nβ) (x : n β Sβ) (y : m β Sβ) :
-- porting note: we don't seem to have `β i j` as valid notation yet
Matrix.toLinearMapβ' R M x y = β i, β j, x i β’ y j β’ M i j :=
Finset.sum_congr rfl fun _ _ => Finset.sum_congr rfl fun _ _ => by
rw [RingHom.id_apply, RingHom.id_apply, smul_comm]
theorem Matrix.toLinearMapβ'_apply' {T : Type*} [CommSemiring T] (M : Matrix n m T) (v : n β T)
(w : m β T) : Matrix.toLinearMapβ' T M v w = dotProduct v (M *α΅₯ w) := by
simp_rw [Matrix.toLinearMapβ'_apply, dotProduct, Matrix.mulVec, dotProduct]
refine Finset.sum_congr rfl fun _ _ => ?_
rw [Finset.mul_sum]
refine Finset.sum_congr rfl fun _ _ => ?_
rw [smul_eq_mul, smul_eq_mul, mul_comm (w _), β mul_assoc]
@[simp]
theorem Matrix.toLinearMapβββ'_single (M : Matrix n m Nβ) (i : n) (j : m) :
Matrix.toLinearMapβββ' R Οβ Οβ M (Pi.single i 1) (Pi.single j 1) = M i j :=
Matrix.toLinearMapβ'Aux_single Οβ Οβ M i j
@[simp]
theorem Matrix.toLinearMapβ'_single (M : Matrix n m Nβ) (i : n) (j : m) :
Matrix.toLinearMapβ' R M (Pi.single i 1) (Pi.single j 1) = M i j :=
Matrix.toLinearMapβ'Aux_single _ _ M i j
@[simp]
theorem LinearMap.toMatrixβββ'_symm :
((LinearMap.toMatrixβββ' R).symm : Matrix n m Nβ ββ[R] _) = Matrix.toLinearMapβββ' R Οβ Οβ :=
rfl
@[simp]
theorem Matrix.toLinearMapβββ'_symm :
((Matrix.toLinearMapβββ' R Οβ Οβ).symm : _ ββ[R] Matrix n m Nβ) = LinearMap.toMatrixβββ' R :=
(LinearMap.toMatrixβββ' R).symm_symm
@[simp]
theorem Matrix.toLinearMapβββ'_toMatrix' (B : (n β Rβ) βββ[Οβ] (m β Rβ) βββ[Οβ] Nβ) :
Matrix.toLinearMapβββ' R Οβ Οβ (LinearMap.toMatrixβββ' R B) = B :=
(Matrix.toLinearMapβββ' R Οβ Οβ).apply_symm_apply B
@[simp]
theorem Matrix.toLinearMapβ'_toMatrix' (B : (n β Sβ) ββ[Sβ] (m β Sβ) ββ[Sβ] Nβ) :
Matrix.toLinearMapβ' R (LinearMap.toMatrixβ' R B) = B :=
(Matrix.toLinearMapβ' R).apply_symm_apply B
@[simp]
theorem LinearMap.toMatrix'_toLinearMapβββ' (M : Matrix n m Nβ) :
LinearMap.toMatrixβββ' R (Matrix.toLinearMapβββ' R Οβ Οβ M) = M :=
(LinearMap.toMatrixβββ' R).apply_symm_apply M
@[simp]
theorem LinearMap.toMatrix'_toLinearMapβ' (M : Matrix n m Nβ) :
LinearMap.toMatrixβ' R (Matrix.toLinearMapβ' R (Sβ := Sβ) (Sβ := Sβ) M) = M :=
(LinearMap.toMatrixβββ' R).apply_symm_apply M
@[simp]
theorem LinearMap.toMatrixβββ'_apply (B : (n β Rβ) βββ[Οβ] (m β Rβ) βββ[Οβ] Nβ) (i : n) (j : m) :
LinearMap.toMatrixβββ' R B i j = B (Pi.single i 1) (Pi.single j 1) :=
rfl
@[simp]
theorem LinearMap.toMatrixβ'_apply (B : (n β Sβ) ββ[Sβ] (m β Sβ) ββ[Sβ] Nβ) (i : n) (j : m) :
LinearMap.toMatrixβ' R B i j = B (Pi.single i 1) (Pi.single j 1) :=
rfl
end ToMatrix'
section CommToMatrix'
-- TODO: Introduce matrix multiplication by matrices of scalars
variable {R : Type*} [CommSemiring R]
variable [Fintype n] [Fintype m]
variable [DecidableEq n] [DecidableEq m]
variable [Fintype n'] [Fintype m']
variable [DecidableEq n'] [DecidableEq m']
@[simp]
theorem LinearMap.toMatrixβ'_complββ (B : (n β R) ββ[R] (m β R) ββ[R] R) (l : (n' β R) ββ[R] n β R)
(r : (m' β R) ββ[R] m β R) :
toMatrixβ' R (B.complββ l r) = (toMatrix' l)α΅ * toMatrixβ' R B * toMatrix' r := by
ext i j
simp only [LinearMap.toMatrixβ'_apply, LinearMap.complββ_apply, transpose_apply, Matrix.mul_apply,
LinearMap.toMatrix', LinearEquiv.coe_mk, sum_mul]
rw [sum_comm]
conv_lhs => rw [β LinearMap.sum_repr_mul_repr_mul (Pi.basisFun R n) (Pi.basisFun R m) (l _) (r _)]
rw [Finsupp.sum_fintype]
Β· apply sum_congr rfl
rintro i' -
rw [Finsupp.sum_fintype]
Β· apply sum_congr rfl
rintro j' -
simp only [smul_eq_mul, Pi.basisFun_repr, mul_assoc, mul_comm, mul_left_comm,
Pi.basisFun_apply, of_apply]
Β· intros
simp only [zero_smul, smul_zero]
Β· intros
simp only [zero_smul, Finsupp.sum_zero]
theorem LinearMap.toMatrixβ'_comp (B : (n β R) ββ[R] (m β R) ββ[R] R) (f : (n' β R) ββ[R] n β R) :
toMatrixβ' R (B.comp f) = (toMatrix' f)α΅ * toMatrixβ' R B := by
rw [β LinearMap.complβ_id (B.comp f), β LinearMap.complββ]
simp
theorem LinearMap.toMatrixβ'_complβ (B : (n β R) ββ[R] (m β R) ββ[R] R) (f : (m' β R) ββ[R] m β R) :
toMatrixβ' R (B.complβ f) = toMatrixβ' R B * toMatrix' f := by
rw [β LinearMap.comp_id B, β LinearMap.complββ]
simp
theorem LinearMap.mul_toMatrixβ'_mul (B : (n β R) ββ[R] (m β R) ββ[R] R) (M : Matrix n' n R)
(N : Matrix m m' R) :
M * toMatrixβ' R B * N = toMatrixβ' R (B.complββ (toLin' Mα΅) (toLin' N)) := by
simp
theorem LinearMap.mul_toMatrix' (B : (n β R) ββ[R] (m β R) ββ[R] R) (M : Matrix n' n R) :
M * toMatrixβ' R B = toMatrixβ' R (B.comp <| toLin' Mα΅) := by
simp only [B.toMatrixβ'_comp, transpose_transpose, toMatrix'_toLin']
theorem LinearMap.toMatrixβ'_mul (B : (n β R) ββ[R] (m β R) ββ[R] R) (M : Matrix m m' R) :
toMatrixβ' R B * M = toMatrixβ' R (B.complβ <| toLin' M) := by
simp only [B.toMatrixβ'_complβ, toMatrix'_toLin']
theorem Matrix.toLinearMapβ'_comp (M : Matrix n m R) (P : Matrix n n' R) (Q : Matrix m m' R) :
LinearMap.complββ (Matrix.toLinearMapβ' R M) (toLin' P) (toLin' Q) =
toLinearMapβ' R (Pα΅ * M * Q) :=
(LinearMap.toMatrixβ' R).injective (by simp)
end CommToMatrix'
section ToMatrix
/-! ### Bilinear maps over arbitrary vector spaces
This section deals with the conversion between matrices and bilinear maps on
a module with a fixed basis.
-/
variable [CommSemiring R]
variable [AddCommMonoid Mβ] [Module R Mβ] [AddCommMonoid Mβ] [Module R Mβ] [AddCommMonoid Nβ]
[Module R Nβ]
variable [DecidableEq n] [Fintype n]
variable [DecidableEq m] [Fintype m]
section
variable (bβ : Basis n R Mβ) (bβ : Basis m R Mβ)
/-- `LinearMap.toMatrixβ bβ bβ` is the equivalence between `R`-bilinear maps on `M` and
`n`-by-`m` matrices with entries in `R`, if `bβ` and `bβ` are `R`-bases for `Mβ` and `Mβ`,
respectively. -/
noncomputable def LinearMap.toMatrixβ : (Mβ ββ[R] Mβ ββ[R] Nβ) ββ[R] Matrix n m Nβ :=
(bβ.equivFun.arrowCongr (bβ.equivFun.arrowCongr (LinearEquiv.refl R Nβ))).trans
(LinearMap.toMatrixβ' R)
/-- `Matrix.toLinearMapβ bβ bβ` is the equivalence between `R`-bilinear maps on `M` and
`n`-by-`m` matrices with entries in `R`, if `bβ` and `bβ` are `R`-bases for `Mβ` and `Mβ`,
respectively; this is the reverse direction of `LinearMap.toMatrixβ bβ bβ`. -/
noncomputable def Matrix.toLinearMapβ : Matrix n m Nβ ββ[R] Mβ ββ[R] Mβ ββ[R] Nβ :=
(LinearMap.toMatrixβ bβ bβ).symm
-- We make this and not `LinearMap.toMatrixβ` a `simp` lemma to avoid timeouts
@[simp]
theorem LinearMap.toMatrixβ_apply (B : Mβ ββ[R] Mβ ββ[R] Nβ) (i : n) (j : m) :
LinearMap.toMatrixβ bβ bβ B i j = B (bβ i) (bβ j) := by
simp only [toMatrixβ, LinearEquiv.trans_apply, toMatrixβ'_apply, LinearEquiv.arrowCongr_apply,
Basis.equivFun_symm_apply, Pi.single_apply, ite_smul, one_smul, zero_smul, sum_ite_eq',
mem_univ, βreduceIte, LinearEquiv.refl_apply]
@[simp]
theorem Matrix.toLinearMapβ_apply (M : Matrix n m Nβ) (x : Mβ) (y : Mβ) :
Matrix.toLinearMapβ bβ bβ M x y = β i, β j, bβ.repr x i β’ bβ.repr y j β’ M i j :=
Finset.sum_congr rfl fun _ _ => Finset.sum_congr rfl fun _ _ =>
smul_algebra_smul_comm ((RingHom.id R) ((Basis.equivFun bβ) x _))
((RingHom.id R) ((Basis.equivFun bβ) y _)) (M _ _)
-- Not a `simp` lemma since `LinearMap.toMatrixβ` needs an extra argument
theorem LinearMap.toMatrixβAux_eq (B : Mβ ββ[R] Mβ ββ[R] Nβ) :
LinearMap.toMatrixβAux R bβ bβ B = LinearMap.toMatrixβ bβ bβ B :=
Matrix.ext fun i j => by rw [LinearMap.toMatrixβ_apply, LinearMap.toMatrixβAux_apply]
@[simp]
theorem LinearMap.toMatrixβ_symm :
(LinearMap.toMatrixβ bβ bβ).symm = Matrix.toLinearMapβ (Nβ := Nβ) bβ bβ :=
rfl
@[simp]
theorem Matrix.toLinearMapβ_symm :
(Matrix.toLinearMapβ bβ bβ).symm = LinearMap.toMatrixβ (Nβ := Nβ) bβ bβ :=
(LinearMap.toMatrixβ bβ bβ).symm_symm
theorem Matrix.toLinearMapβ_basisFun :
Matrix.toLinearMapβ (Pi.basisFun R n) (Pi.basisFun R m) =
Matrix.toLinearMapβ' R (Nβ := Nβ) := by
ext M
simp only [coe_comp, coe_single, Function.comp_apply, toLinearMapβ_apply, Pi.basisFun_repr,
toLinearMapβ'_apply]
theorem LinearMap.toMatrixβ_basisFun :
LinearMap.toMatrixβ (Pi.basisFun R n) (Pi.basisFun R m) =
LinearMap.toMatrixβ' R (Nβ := Nβ) := by
ext B
rw [LinearMap.toMatrixβ_apply, LinearMap.toMatrixβ'_apply, Pi.basisFun_apply, Pi.basisFun_apply]
@[simp]
theorem Matrix.toLinearMapβ_toMatrixβ (B : Mβ ββ[R] Mβ ββ[R] Nβ) :
Matrix.toLinearMapβ bβ bβ (LinearMap.toMatrixβ bβ bβ B) = B :=
(Matrix.toLinearMapβ bβ bβ).apply_symm_apply B
@[simp]
theorem LinearMap.toMatrixβ_toLinearMapβ (M : Matrix n m Nβ) :
LinearMap.toMatrixβ bβ bβ (Matrix.toLinearMapβ bβ bβ M) = M :=
(LinearMap.toMatrixβ bβ bβ).apply_symm_apply M
variable (bβ : Basis n R Mβ) (bβ : Basis m R Mβ)
variable [AddCommMonoid Mβ'] [Module R Mβ']
variable [AddCommMonoid Mβ'] [Module R Mβ']
variable (bβ' : Basis n' R Mβ')
variable (bβ' : Basis m' R Mβ')
variable [Fintype n'] [Fintype m']
variable [DecidableEq n'] [DecidableEq m']
-- Cannot be a `simp` lemma because `bβ` and `bβ` must be inferred.
theorem LinearMap.toMatrixβ_complββ (B : Mβ ββ[R] Mβ ββ[R] R) (l : Mβ' ββ[R] Mβ)
(r : Mβ' ββ[R] Mβ) :
LinearMap.toMatrixβ bβ' bβ' (B.complββ l r) =
(toMatrix bβ' bβ l)α΅ * LinearMap.toMatrixβ bβ bβ B * toMatrix bβ' bβ r := by
ext i j
simp only [LinearMap.toMatrixβ_apply, complββ_apply, transpose_apply, Matrix.mul_apply,
LinearMap.toMatrix_apply, LinearEquiv.coe_mk, sum_mul]
rw [sum_comm]
conv_lhs => rw [β LinearMap.sum_repr_mul_repr_mul bβ bβ]
rw [Finsupp.sum_fintype]
Β· apply sum_congr rfl
rintro i' -
rw [Finsupp.sum_fintype]
Β· apply sum_congr rfl
rintro j' -
simp only [smul_eq_mul, LinearMap.toMatrix_apply, Basis.equivFun_apply, mul_assoc, mul_comm,
mul_left_comm]
Β· intros
simp only [zero_smul, smul_zero]
Β· intros
simp only [zero_smul, Finsupp.sum_zero]
theorem LinearMap.toMatrixβ_comp (B : Mβ ββ[R] Mβ ββ[R] R) (f : Mβ' ββ[R] Mβ) :
LinearMap.toMatrixβ bβ' bβ (B.comp f) =
(toMatrix bβ' bβ f)α΅ * LinearMap.toMatrixβ bβ bβ B := by
rw [β LinearMap.complβ_id (B.comp f), β LinearMap.complββ, LinearMap.toMatrixβ_complββ bβ bβ]
simp
theorem LinearMap.toMatrixβ_complβ (B : Mβ ββ[R] Mβ ββ[R] R) (f : Mβ' ββ[R] Mβ) :
LinearMap.toMatrixβ bβ bβ' (B.complβ f) =
LinearMap.toMatrixβ bβ bβ B * toMatrix bβ' bβ f := by
rw [β LinearMap.comp_id B, β LinearMap.complββ, LinearMap.toMatrixβ_complββ bβ bβ]
simp
@[simp]
theorem LinearMap.toMatrixβ_mul_basis_toMatrix (cβ : Basis n' R Mβ) (cβ : Basis m' R Mβ)
(B : Mβ ββ[R] Mβ ββ[R] R) :
(bβ.toMatrix cβ)α΅ * LinearMap.toMatrixβ bβ bβ B * bβ.toMatrix cβ =
LinearMap.toMatrixβ cβ cβ B := by
simp_rw [β LinearMap.toMatrix_id_eq_basis_toMatrix]
rw [β LinearMap.toMatrixβ_complββ, LinearMap.complββ_id_id]
theorem LinearMap.mul_toMatrixβ_mul (B : Mβ ββ[R] Mβ ββ[R] R) (M : Matrix n' n R)
(N : Matrix m m' R) :
M * LinearMap.toMatrixβ bβ bβ B * N =
LinearMap.toMatrixβ bβ' bβ' (B.complββ (toLin bβ' bβ Mα΅) (toLin bβ' bβ N)) := by
simp_rw [LinearMap.toMatrixβ_complββ bβ bβ, toMatrix_toLin, transpose_transpose]
theorem LinearMap.mul_toMatrixβ (B : Mβ ββ[R] Mβ ββ[R] R) (M : Matrix n' n R) :
M * LinearMap.toMatrixβ bβ bβ B =
LinearMap.toMatrixβ bβ' bβ (B.comp (toLin bβ' bβ Mα΅)) := by
rw [LinearMap.toMatrixβ_comp bβ, toMatrix_toLin, transpose_transpose]
theorem LinearMap.toMatrixβ_mul (B : Mβ ββ[R] Mβ ββ[R] R) (M : Matrix m m' R) :
LinearMap.toMatrixβ bβ bβ B * M =
LinearMap.toMatrixβ bβ bβ' (B.complβ (toLin bβ' bβ M)) := by
rw [LinearMap.toMatrixβ_complβ bβ bβ, toMatrix_toLin]
theorem Matrix.toLinearMapβ_complββ (M : Matrix n m R) (P : Matrix n n' R) (Q : Matrix m m' R) :
(Matrix.toLinearMapβ bβ bβ M).complββ (toLin bβ' bβ P) (toLin bβ' bβ Q) =
Matrix.toLinearMapβ bβ' bβ' (Pα΅ * M * Q) :=
(LinearMap.toMatrixβ bβ' bβ').injective
(by
simp only [LinearMap.toMatrixβ_complββ bβ bβ, LinearMap.toMatrixβ_toLinearMapβ,
toMatrix_toLin])
end
end ToMatrix
/-! ### Adjoint pairs -/
section MatrixAdjoints
open Matrix
variable [CommRing R]
variable [AddCommMonoid Mβ] [Module R Mβ] [AddCommMonoid Mβ] [Module R Mβ]
variable [Fintype n] [Fintype n']
variable (bβ : Basis n R Mβ) (bβ : Basis n' R Mβ)
variable (J Jβ : Matrix n n R) (J' : Matrix n' n' R)
variable (A : Matrix n' n R) (A' : Matrix n n' R)
variable (Aβ Aβ : Matrix n n R)
/-- The condition for the matrices `A`, `A'` to be an adjoint pair with respect to the square
matrices `J`, `Jβ`. -/
def Matrix.IsAdjointPair :=
Aα΅ * J' = J * A'
/-- The condition for a square matrix `A` to be self-adjoint with respect to the square matrix
`J`. -/
def Matrix.IsSelfAdjoint :=
Matrix.IsAdjointPair J J Aβ Aβ
/-- The condition for a square matrix `A` to be skew-adjoint with respect to the square matrix
`J`. -/
def Matrix.IsSkewAdjoint :=
Matrix.IsAdjointPair J J Aβ (-Aβ)
variable [DecidableEq n] [DecidableEq n']
@[simp]
theorem isAdjointPair_toLinearMapβ' :
LinearMap.IsAdjointPair (Matrix.toLinearMapβ' R J) (Matrix.toLinearMapβ' R J')
(Matrix.toLin' A) (Matrix.toLin' A') β
Matrix.IsAdjointPair J J' A A' := by
rw [isAdjointPair_iff_comp_eq_complβ]
have h :
β B B' : (n β R) ββ[R] (n' β R) ββ[R] R,
B = B' β LinearMap.toMatrixβ' R B = LinearMap.toMatrixβ' R B' := by
intro B B'
constructor <;> intro h
Β· rw [h]
Β· exact (LinearMap.toMatrixβ' R).injective h
simp_rw [h, LinearMap.toMatrixβ'_comp, LinearMap.toMatrixβ'_complβ,
LinearMap.toMatrix'_toLin', LinearMap.toMatrix'_toLinearMapβ']
rfl
@[simp]
theorem isAdjointPair_toLinearMapβ :
LinearMap.IsAdjointPair (Matrix.toLinearMapβ bβ bβ J)
(Matrix.toLinearMapβ bβ bβ J') (Matrix.toLin bβ bβ A) (Matrix.toLin bβ bβ A') β
Matrix.IsAdjointPair J J' A A' := by
rw [isAdjointPair_iff_comp_eq_complβ]
have h :
β B B' : Mβ ββ[R] Mβ ββ[R] R,
B = B' β LinearMap.toMatrixβ bβ bβ B = LinearMap.toMatrixβ bβ bβ B' := by
intro B B'
constructor <;> intro h
Β· rw [h]
Β· exact (LinearMap.toMatrixβ bβ bβ).injective h
simp_rw [h, LinearMap.toMatrixβ_comp bβ bβ, LinearMap.toMatrixβ_complβ bβ bβ,
LinearMap.toMatrix_toLin, LinearMap.toMatrixβ_toLinearMapβ]
rfl
theorem Matrix.isAdjointPair_equiv (P : Matrix n n R) (h : IsUnit P) :
(Pα΅ * J * P).IsAdjointPair (Pα΅ * J * P) Aβ Aβ β
J.IsAdjointPair J (P * Aβ * Pβ»ΒΉ) (P * Aβ * Pβ»ΒΉ) := by
have h' : IsUnit P.det := P.isUnit_iff_isUnit_det.mp h
let u := P.nonsingInvUnit h'
let v := Pα΅.nonsingInvUnit (P.isUnit_det_transpose h')
let x := Aβα΅ * Pα΅ * J
let y := J * P * Aβ
suffices x * u = v * y β vβ»ΒΉ * x = y * uβ»ΒΉ by
dsimp only [Matrix.IsAdjointPair]
simp only [Matrix.transpose_mul]
simp only [β mul_assoc, P.transpose_nonsing_inv]
convert this using 2
Β· rw [mul_assoc, mul_assoc, β mul_assoc J]
rfl
Β· rw [mul_assoc, mul_assoc, β mul_assoc _ _ J]
rfl
rw [Units.eq_mul_inv_iff_mul_eq]
conv_rhs => rw [mul_assoc]
rw [v.inv_mul_eq_iff_eq_mul]
/-- The submodule of pair-self-adjoint matrices with respect to bilinear forms corresponding to
given matrices `J`, `Jβ`. -/
def pairSelfAdjointMatricesSubmodule : Submodule R (Matrix n n R) :=
| (isPairSelfAdjointSubmodule (Matrix.toLinearMapβ' R J)
(Matrix.toLinearMapβ' R Jβ)).map
((LinearMap.toMatrix' : ((n β R) ββ[R] n β R) ββ[R] Matrix n n R) :
((n β R) ββ[R] n β R) ββ[R] Matrix n n R)
@[simp]
theorem mem_pairSelfAdjointMatricesSubmodule :
Aβ β pairSelfAdjointMatricesSubmodule J Jβ β Matrix.IsAdjointPair J Jβ Aβ Aβ := by
simp only [pairSelfAdjointMatricesSubmodule, LinearEquiv.coe_coe, LinearMap.toMatrix'_apply,
Submodule.mem_map, mem_isPairSelfAdjointSubmodule]
constructor
Β· rintro β¨f, hf, hAβ©
have hf' : f = toLin' Aβ := by rw [β hA, Matrix.toLin'_toMatrix']
rw [hf'] at hf
rw [β isAdjointPair_toLinearMapβ']
exact hf
Β· intro h
refine β¨toLin' Aβ, ?_, LinearMap.toMatrix'_toLin' _β©
exact (isAdjointPair_toLinearMapβ' _ _ _ _).mpr h
/-- The submodule of self-adjoint matrices with respect to the bilinear form corresponding to
the matrix `J`. -/
| Mathlib/LinearAlgebra/Matrix/SesquilinearForm.lean | 563 | 584 |
/-
Copyright (c) 2022 Oliver Nash. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Oliver Nash
-/
import Mathlib.Analysis.Normed.Group.Quotient
import Mathlib.Analysis.NormedSpace.Pointwise
import Mathlib.Topology.Instances.AddCircle
/-!
# The additive circle as a normed group
We define the normed group structure on `AddCircle p`, for `p : β`. For example if `p = 1` then:
`β(x : AddCircle 1)β = |x - round x|` for any `x : β` (see `UnitAddCircle.norm_eq`).
## Main definitions:
* `AddCircle.norm_eq`: a characterisation of the norm on `AddCircle p`
## TODO
* The fact `InnerProductGeometry.angle (Real.cos ΞΈ) (Real.sin ΞΈ) = β(ΞΈ : Real.Angle)β`
-/
noncomputable section
open Metric QuotientAddGroup Set
open Int hiding mem_zmultiples_iff
open AddSubgroup
namespace AddCircle
variable (p : β)
instance : NormedAddCommGroup (AddCircle p) := QuotientAddGroup.instNormedAddCommGroup _
@[simp]
theorem norm_coe_mul (x : β) (t : β) :
β(β(t * x) : AddCircle (t * p))β = |t| * β(x : AddCircle p)β := by
obtain rfl | ht := eq_or_ne t 0
Β· simp
simp only [norm_eq_infDist, Real.norm_eq_abs, β Real.norm_eq_abs, β infDist_smulβ ht, smul_zero]
congr with m
simp only [zmultiples, eq_iff_sub_mem, zsmul_eq_mul, mem_mk, mem_setOf_eq,
mem_smul_set_iff_inv_smul_memβ ht, smul_eq_mul]
simp_rw [mul_left_comm, β smul_eq_mul, Set.range_smul, mem_smul_set_iff_inv_smul_memβ ht]
simp [mul_sub, ht, -mem_range]
theorem norm_neg_period (x : β) : β(x : AddCircle (-p))β = β(x : AddCircle p)β := by
suffices β(β(-1 * x) : AddCircle (-1 * p))β = β(x : AddCircle p)β by
rw [β this, neg_one_mul]
simp
simp only [norm_coe_mul, abs_neg, abs_one, one_mul]
@[simp]
theorem norm_eq_of_zero {x : β} : β(x : AddCircle (0 : β))β = |x| := by
suffices { y : β | (y : AddCircle (0 : β)) = (x : AddCircle (0 : β)) } = {x} by
simp [norm_eq_infDist, this]
ext y
simp [eq_iff_sub_mem, mem_zmultiples_iff, sub_eq_zero]
theorem norm_eq {x : β} : β(x : AddCircle p)β = |x - round (pβ»ΒΉ * x) * p| := by
suffices β x : β, β(x : AddCircle (1 : β))β = |x - round x| by
rcases eq_or_ne p 0 with (rfl | hp)
Β· simp
have hx := norm_coe_mul p x pβ»ΒΉ
rw [abs_inv, eq_inv_mul_iff_mul_eqβ ((not_congr abs_eq_zero).mpr hp)] at hx
rw [β hx, inv_mul_cancelβ hp, this, β abs_mul, mul_sub, mul_inv_cancel_leftβ hp, mul_comm p]
clear! x p
intros x
simp only [le_antisymm_iff, le_norm_iff, Real.norm_eq_abs]
refine β¨le_of_forall_le fun r hr β¦ ?_, ?_β©
Β· rw [abs_sub_round_eq_min, le_inf_iff]
rw [le_norm_iff] at hr
constructor
Β· simpa [abs_of_nonneg] using hr (fract x)
Β· simpa [abs_sub_comm (fract x)]
using hr (fract x - 1) (by simp [β self_sub_floor, β sub_eq_zero, sub_sub]; simp)
Β· simpa [zmultiples, QuotientAddGroup.eq, zsmul_eq_mul, mul_one, mem_mk, mem_range, and_imp,
forall_exists_index, eq_neg_add_iff_add_eq, β eq_sub_iff_add_eq, forall_swap (Ξ± := β)]
using round_le _
theorem norm_eq' (hp : 0 < p) {x : β} : β(x : AddCircle p)β = p * |pβ»ΒΉ * x - round (pβ»ΒΉ * x)| := by
conv_rhs =>
congr
rw [β abs_eq_self.mpr hp.le]
rw [β abs_mul, mul_sub, mul_inv_cancel_leftβ hp.ne.symm, norm_eq, mul_comm p]
theorem norm_le_half_period {x : AddCircle p} (hp : p β 0) : βxβ β€ |p| / 2 := by
obtain β¨xβ© := x
change β(x : AddCircle p)β β€ |p| / 2
rw [norm_eq, β mul_le_mul_left (abs_pos.mpr (inv_ne_zero hp)), β abs_mul, mul_sub, mul_left_comm,
β mul_div_assoc, β abs_mul, inv_mul_cancelβ hp, mul_one, abs_one]
exact abs_sub_round (pβ»ΒΉ * x)
@[simp]
theorem norm_half_period_eq : β(β(p / 2) : AddCircle p)β = |p| / 2 := by
rcases eq_or_ne p 0 with (rfl | hp); Β· simp
rw [norm_eq, β mul_div_assoc, inv_mul_cancelβ hp, one_div, round_two_inv, Int.cast_one,
one_mul, (by linarith : p / 2 - p = -(p / 2)), abs_neg, abs_div, abs_two]
theorem norm_coe_eq_abs_iff {x : β} (hp : p β 0) : β(x : AddCircle p)β = |x| β |x| β€ |p| / 2 := by
refine β¨fun hx => hx βΈ norm_le_half_period p hp, fun hx => ?_β©
suffices β p : β, 0 < p β |x| β€ p / 2 β β(x : AddCircle p)β = |x| by
rcases hp.symm.lt_or_lt with (hp | hp)
Β· rw [abs_eq_self.mpr hp.le] at hx
exact this p hp hx
Β· rw [β norm_neg_period]
rw [abs_eq_neg_self.mpr hp.le] at hx
exact this (-p) (neg_pos.mpr hp) hx
clear hx
intro p hp hx
rcases eq_or_ne x (p / (2 : β)) with (rfl | hx')
Β· simp [abs_div, abs_two]
suffices round (pβ»ΒΉ * x) = 0 by simp [norm_eq, this]
rw [round_eq_zero_iff]
obtain β¨hxβ, hxββ© := abs_le.mp hx
replace hxβ := Ne.lt_of_le hx' hxβ
constructor
Β· rwa [β mul_le_mul_left hp, β mul_assoc, mul_inv_cancelβ hp.ne.symm, one_mul, mul_neg, β
mul_div_assoc, mul_one]
Β· rwa [β mul_lt_mul_left hp, β mul_assoc, mul_inv_cancelβ hp.ne.symm, one_mul, β mul_div_assoc,
mul_one]
open Metric
theorem closedBall_eq_univ_of_half_period_le (hp : p β 0) (x : AddCircle p) {Ξ΅ : β}
(hΞ΅ : |p| / 2 β€ Ξ΅) : closedBall x Ξ΅ = univ :=
eq_univ_iff_forall.mpr fun x => by
simpa only [mem_closedBall, dist_eq_norm] using (norm_le_half_period p hp).trans hΞ΅
@[simp]
theorem coe_real_preimage_closedBall_period_zero (x Ξ΅ : β) :
(β) β»ΒΉ' closedBall (x : AddCircle (0 : β)) Ξ΅ = closedBall x Ξ΅ := by
ext y
simp [dist_eq_norm, β QuotientAddGroup.mk_sub]
theorem coe_real_preimage_closedBall_eq_iUnion (x Ξ΅ : β) :
(β) β»ΒΉ' closedBall (x : AddCircle p) Ξ΅ = β z : β€, closedBall (x + z β’ p) Ξ΅ := by
rcases eq_or_ne p 0 with (rfl | hp)
Β· simp [iUnion_const]
ext y
simp only [dist_eq_norm, mem_preimage, mem_closedBall, zsmul_eq_mul, mem_iUnion, Real.norm_eq_abs,
β QuotientAddGroup.mk_sub, norm_eq, β sub_sub]
refine β¨fun h => β¨round (pβ»ΒΉ * (y - x)), hβ©, ?_β©
rintro β¨n, hnβ©
rw [β mul_le_mul_left (abs_pos.mpr <| inv_ne_zero hp), β abs_mul, mul_sub, mul_comm _ p,
inv_mul_cancel_leftβ hp] at hn β’
exact (round_le (pβ»ΒΉ * (y - x)) n).trans hn
theorem coe_real_preimage_closedBall_inter_eq {x Ξ΅ : β} (s : Set β)
(hs : s β closedBall x (|p| / 2)) :
(β) β»ΒΉ' closedBall (x : AddCircle p) Ξ΅ β© s = if Ξ΅ < |p| / 2 then closedBall x Ξ΅ β© s else s := by
rcases le_or_lt (|p| / 2) Ξ΅ with hΞ΅ | hΞ΅
Β· rcases eq_or_ne p 0 with (rfl | hp)
Β· simp only [abs_zero, zero_div] at hΞ΅
simp only [not_lt.mpr hΞ΅, coe_real_preimage_closedBall_period_zero, abs_zero, zero_div,
if_false, inter_eq_right]
exact hs.trans (closedBall_subset_closedBall <| by simp [hΞ΅])
simp [closedBall_eq_univ_of_half_period_le p hp (βx) hΞ΅, not_lt.mpr hΞ΅]
Β· suffices β z : β€, closedBall (x + z β’ p) Ξ΅ β© s = if z = 0 then closedBall x Ξ΅ β© s else β
by
simp [-zsmul_eq_mul, β QuotientAddGroup.mk_zero, coe_real_preimage_closedBall_eq_iUnion,
iUnion_inter, iUnion_ite, this, hΞ΅]
intro z
simp only [Real.closedBall_eq_Icc, zero_sub, zero_add] at hs β’
rcases eq_or_ne z 0 with (rfl | hz)
Β· simp
simp only [hz, zsmul_eq_mul, if_false, eq_empty_iff_forall_not_mem]
rintro y β¨β¨hyβ, hyββ©, hyββ©
obtain β¨hyβ, hyββ© := hs hyβ
rcases lt_trichotomy 0 p with (hp | (rfl : 0 = p) | hp)
Β· rcases Int.cast_le_neg_one_or_one_le_cast_of_ne_zero β hz with hz' | hz'
Β· have : βz * p β€ -p := by nlinarith
linarith [abs_eq_self.mpr hp.le]
Β· have : p β€ βz * p := by nlinarith
linarith [abs_eq_self.mpr hp.le]
Β· simp only [mul_zero, add_zero, abs_zero, zero_div] at hyβ hyβ hΞ΅
linarith
Β· rcases Int.cast_le_neg_one_or_one_le_cast_of_ne_zero β hz with hz' | hz'
Β· have : -p β€ βz * p := by nlinarith
linarith [abs_eq_neg_self.mpr hp.le]
Β· have : βz * p β€ p := by nlinarith
linarith [abs_eq_neg_self.mpr hp.le]
section FiniteOrderPoints
variable {p} [hp : Fact (0 < p)]
theorem norm_div_natCast {m n : β} :
β(β(βm / βn * p) : AddCircle p)β = p * (β(min (m % n) (n - m % n)) / n) := by
have : pβ»ΒΉ * (βm / βn * p) = βm / βn := by rw [mul_comm _ p, inv_mul_cancel_leftβ hp.out.ne.symm]
rw [norm_eq' p hp.out, this, abs_sub_round_div_natCast_eq]
theorem exists_norm_eq_of_isOfFinAddOrder {u : AddCircle p} (hu : IsOfFinAddOrder u) :
β k : β, βuβ = p * (k / addOrderOf u) := by
let n := addOrderOf u
change β k : β, βuβ = p * (k / n)
obtain β¨m, -, -, hmβ© := exists_gcd_eq_one_of_isOfFinAddOrder hu
refine β¨min (m % n) (n - m % n), ?_β©
rw [β hm, norm_div_natCast]
theorem le_add_order_smul_norm_of_isOfFinAddOrder {u : AddCircle p} (hu : IsOfFinAddOrder u)
(hu' : u β 0) : p β€ addOrderOf u β’ βuβ := by
obtain β¨n, hnβ© := exists_norm_eq_of_isOfFinAddOrder hu
replace hu : (addOrderOf u : β) β 0 := by
norm_cast
exact (addOrderOf_pos_iff.mpr hu).ne'
conv_lhs => rw [β mul_one p]
rw [hn, nsmul_eq_mul, β mul_assoc, mul_comm _ p, mul_assoc, mul_div_cancelβ _ hu,
mul_le_mul_left hp.out, Nat.one_le_cast, Nat.one_le_iff_ne_zero]
contrapose! hu'
simpa only [hu', Nat.cast_zero, zero_div, mul_zero, norm_eq_zero] using hn
end FiniteOrderPoints
end AddCircle
namespace UnitAddCircle
theorem norm_eq {x : β} : β(x : UnitAddCircle)β = |x - round x| := by simp [AddCircle.norm_eq]
end UnitAddCircle
| Mathlib/Analysis/Normed/Group/AddCircle.lean | 259 | 269 | |
/-
Copyright (c) 2014 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Y. Lewis, Leonardo de Moura, Johannes HΓΆlzl, Mario Carneiro
-/
import Mathlib.Algebra.Field.Defs
import Mathlib.Algebra.Ring.Commute
import Mathlib.Algebra.Ring.Invertible
import Mathlib.Order.Synonym
/-!
# Lemmas about division (semi)rings and (semi)fields
-/
open Function OrderDual Set
universe u
variable {K L : Type*}
section DivisionSemiring
variable [DivisionSemiring K] {a b c d : K}
theorem add_div (a b c : K) : (a + b) / c = a / c + b / c := by simp_rw [div_eq_mul_inv, add_mul]
@[field_simps]
theorem div_add_div_same (a b c : K) : a / c + b / c = (a + b) / c :=
(add_div _ _ _).symm
theorem same_add_div (h : b β 0) : (b + a) / b = 1 + a / b := by rw [β div_self h, add_div]
theorem div_add_same (h : b β 0) : (a + b) / b = a / b + 1 := by rw [β div_self h, add_div]
theorem one_add_div (h : b β 0) : 1 + a / b = (b + a) / b :=
(same_add_div h).symm
theorem div_add_one (h : b β 0) : a / b + 1 = (a + b) / b :=
| (div_add_same h).symm
| Mathlib/Algebra/Field/Basic.lean | 40 | 40 |
/-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Johannes HΓΆlzl, Kim Morrison, Jens Wagemaker
-/
import Mathlib.Algebra.Polynomial.Reverse
import Mathlib.Algebra.Regular.SMul
/-!
# Theory of monic polynomials
We give several tools for proving that polynomials are monic, e.g.
`Monic.mul`, `Monic.map`, `Monic.pow`.
-/
noncomputable section
open Finset
open Polynomial
namespace Polynomial
universe u v y
variable {R : Type u} {S : Type v} {a b : R} {m n : β} {ΞΉ : Type y}
section Semiring
variable [Semiring R] {p q r : R[X]}
theorem monic_zero_iff_subsingleton : Monic (0 : R[X]) β Subsingleton R :=
subsingleton_iff_zero_eq_one
theorem not_monic_zero_iff : Β¬Monic (0 : R[X]) β (0 : R) β 1 :=
(monic_zero_iff_subsingleton.trans subsingleton_iff_zero_eq_one.symm).not
theorem monic_zero_iff_subsingleton' :
Monic (0 : R[X]) β (β f g : R[X], f = g) β§ β a b : R, a = b :=
Polynomial.monic_zero_iff_subsingleton.trans
β¨by
intro
simp [eq_iff_true_of_subsingleton], fun h => subsingleton_iff.mpr h.2β©
theorem Monic.as_sum (hp : p.Monic) :
p = X ^ p.natDegree + β i β range p.natDegree, C (p.coeff i) * X ^ i := by
conv_lhs => rw [p.as_sum_range_C_mul_X_pow, sum_range_succ_comm]
suffices C (p.coeff p.natDegree) = 1 by rw [this, one_mul]
exact congr_arg C hp
theorem ne_zero_of_ne_zero_of_monic (hp : p β 0) (hq : Monic q) : q β 0 := by
rintro rfl
rw [Monic.def, leadingCoeff_zero] at hq
rw [β mul_one p, β C_1, β hq, C_0, mul_zero] at hp
exact hp rfl
theorem Monic.map [Semiring S] (f : R β+* S) (hp : Monic p) : Monic (p.map f) := by
unfold Monic
nontriviality
have : f p.leadingCoeff β 0 := by
rw [show _ = _ from hp, f.map_one]
exact one_ne_zero
rw [Polynomial.leadingCoeff, coeff_map]
suffices p.coeff (p.map f).natDegree = 1 by simp [this]
rwa [natDegree_eq_of_degree_eq (degree_map_eq_of_leadingCoeff_ne_zero f this)]
theorem monic_C_mul_of_mul_leadingCoeff_eq_one {b : R} (hp : b * p.leadingCoeff = 1) :
Monic (C b * p) := by
unfold Monic
nontriviality
rw [leadingCoeff_mul' _] <;> simp [leadingCoeff_C b, hp]
theorem monic_mul_C_of_leadingCoeff_mul_eq_one {b : R} (hp : p.leadingCoeff * b = 1) :
Monic (p * C b) := by
unfold Monic
nontriviality
rw [leadingCoeff_mul' _] <;> simp [leadingCoeff_C b, hp]
theorem monic_of_degree_le (n : β) (H1 : degree p β€ n) (H2 : coeff p n = 1) : Monic p :=
Decidable.byCases
(fun H : degree p < n => eq_of_zero_eq_one (H2 βΈ (coeff_eq_zero_of_degree_lt H).symm) _ _)
fun H : Β¬degree p < n => by
rwa [Monic, Polynomial.leadingCoeff, natDegree, (lt_or_eq_of_le H1).resolve_left H]
theorem monic_X_pow_add {n : β} (H : degree p < n) : Monic (X ^ n + p) :=
monic_of_degree_le n
(le_trans (degree_add_le _ _) (max_le (degree_X_pow_le _) (le_of_lt H)))
(by rw [coeff_add, coeff_X_pow, if_pos rfl, coeff_eq_zero_of_degree_lt H, add_zero])
variable (a) in
theorem monic_X_pow_add_C {n : β} (h : n β 0) : (X ^ n + C a).Monic :=
monic_X_pow_add <| (lt_of_le_of_lt degree_C_le
(by simp only [Nat.cast_pos, Nat.pos_iff_ne_zero, ne_eq, h, not_false_eq_true]))
theorem monic_X_add_C (x : R) : Monic (X + C x) :=
pow_one (X : R[X]) βΈ monic_X_pow_add_C x one_ne_zero
theorem Monic.mul (hp : Monic p) (hq : Monic q) : Monic (p * q) :=
letI := Classical.decEq R
if h0 : (0 : R) = 1 then
haveI := subsingleton_of_zero_eq_one h0
Subsingleton.elim _ _
else by
have : p.leadingCoeff * q.leadingCoeff β 0 := by
simp [Monic.def.1 hp, Monic.def.1 hq, Ne.symm h0]
rw [Monic.def, leadingCoeff_mul' this, Monic.def.1 hp, Monic.def.1 hq, one_mul]
theorem Monic.pow (hp : Monic p) : β n : β, Monic (p ^ n)
| 0 => monic_one
| n + 1 => by
rw [pow_succ]
exact (Monic.pow hp n).mul hp
theorem Monic.add_of_left (hp : Monic p) (hpq : degree q < degree p) : Monic (p + q) := by
rwa [Monic, add_comm, leadingCoeff_add_of_degree_lt hpq]
theorem Monic.add_of_right (hq : Monic q) (hpq : degree p < degree q) : Monic (p + q) := by
rwa [Monic, leadingCoeff_add_of_degree_lt hpq]
theorem Monic.of_mul_monic_left (hp : p.Monic) (hpq : (p * q).Monic) : q.Monic := by
contrapose! hpq
rw [Monic.def] at hpq β’
rwa [leadingCoeff_monic_mul hp]
theorem Monic.of_mul_monic_right (hq : q.Monic) (hpq : (p * q).Monic) : p.Monic := by
contrapose! hpq
rw [Monic.def] at hpq β’
rwa [leadingCoeff_mul_monic hq]
namespace Monic
lemma comp (hp : p.Monic) (hq : q.Monic) (h : q.natDegree β 0) : (p.comp q).Monic := by
nontriviality R
have : (p.comp q).natDegree = p.natDegree * q.natDegree :=
natDegree_comp_eq_of_mul_ne_zero <| by simp [hp.leadingCoeff, hq.leadingCoeff]
rw [Monic.def, Polynomial.leadingCoeff, this, coeff_comp_degree_mul_degree h, hp.leadingCoeff,
hq.leadingCoeff, one_pow, mul_one]
lemma comp_X_add_C (hp : p.Monic) (r : R) : (p.comp (X + C r)).Monic := by
nontriviality R
refine hp.comp (monic_X_add_C _) fun ha β¦ ?_
rw [natDegree_X_add_C] at ha
exact one_ne_zero ha
@[simp]
theorem natDegree_eq_zero_iff_eq_one (hp : p.Monic) : p.natDegree = 0 β p = 1 := by
constructor <;> intro h
swap
Β· rw [h]
exact natDegree_one
have : p = C (p.coeff 0) := by
rw [β Polynomial.degree_le_zero_iff]
rwa [Polynomial.natDegree_eq_zero_iff_degree_le_zero] at h
rw [this]
rw [β h, β Polynomial.leadingCoeff, Monic.def.1 hp, C_1]
@[simp]
theorem degree_le_zero_iff_eq_one (hp : p.Monic) : p.degree β€ 0 β p = 1 := by
rw [β hp.natDegree_eq_zero_iff_eq_one, natDegree_eq_zero_iff_degree_le_zero]
theorem natDegree_mul (hp : p.Monic) (hq : q.Monic) :
(p * q).natDegree = p.natDegree + q.natDegree := by
nontriviality R
apply natDegree_mul'
simp [hp.leadingCoeff, hq.leadingCoeff]
theorem degree_mul_comm (hp : p.Monic) (q : R[X]) : (p * q).degree = (q * p).degree := by
by_cases h : q = 0
Β· simp [h]
rw [degree_mul', hp.degree_mul]
Β· exact add_comm _ _
Β· rwa [hp.leadingCoeff, one_mul, leadingCoeff_ne_zero]
nonrec theorem natDegree_mul' (hp : p.Monic) (hq : q β 0) :
(p * q).natDegree = p.natDegree + q.natDegree := by
rw [natDegree_mul']
simpa [hp.leadingCoeff, leadingCoeff_ne_zero]
theorem natDegree_mul_comm (hp : p.Monic) (q : R[X]) : (p * q).natDegree = (q * p).natDegree := by
by_cases h : q = 0
Β· simp [h]
rw [hp.natDegree_mul' h, Polynomial.natDegree_mul', add_comm]
simpa [hp.leadingCoeff, leadingCoeff_ne_zero]
theorem not_dvd_of_natDegree_lt (hp : Monic p) (h0 : q β 0) (hl : natDegree q < natDegree p) :
Β¬p β£ q := by
rintro β¨r, rflβ©
rw [hp.natDegree_mul' <| right_ne_zero_of_mul h0] at hl
exact hl.not_le (Nat.le_add_right _ _)
theorem not_dvd_of_degree_lt (hp : Monic p) (h0 : q β 0) (hl : degree q < degree p) : Β¬p β£ q :=
Monic.not_dvd_of_natDegree_lt hp h0 <| natDegree_lt_natDegree h0 hl
theorem nextCoeff_mul (hp : Monic p) (hq : Monic q) :
nextCoeff (p * q) = nextCoeff p + nextCoeff q := by
nontriviality
simp only [β coeff_one_reverse]
rw [reverse_mul] <;> simp [hp.leadingCoeff, hq.leadingCoeff, mul_coeff_one, add_comm]
theorem nextCoeff_pow (hp : p.Monic) (n : β) : (p ^ n).nextCoeff = n β’ p.nextCoeff := by
induction n with
| | zero => rw [pow_zero, zero_smul, β map_one (f := C), nextCoeff_C_eq_zero]
| succ n ih => rw [pow_succ, (hp.pow n).nextCoeff_mul hp, ih, succ_nsmul]
theorem eq_one_of_map_eq_one {S : Type*} [Semiring S] [Nontrivial S] (f : R β+* S) (hp : p.Monic)
(map_eq : p.map f = 1) : p = 1 := by
| Mathlib/Algebra/Polynomial/Monic.lean | 203 | 207 |
/-
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, Yuyang Zhao
-/
import Mathlib.Algebra.Group.Units.Basic
import Mathlib.Algebra.Order.Monoid.Defs
import Mathlib.Algebra.Order.Monoid.Unbundled.ExistsOfLE
import Mathlib.Algebra.NeZero
import Mathlib.Order.BoundedOrder.Basic
/-!
# Canonically ordered monoids
-/
universe u
variable {Ξ± : Type u}
/-- An ordered additive monoid is `CanonicallyOrderedAdd`
if the ordering coincides with the subtractibility relation,
which is to say, `a β€ b` iff there exists `c` with `b = a + c`.
This is satisfied by the natural numbers, for example, but not
the integers or other nontrivial `OrderedAddCommGroup`s. -/
class CanonicallyOrderedAdd (Ξ± : Type*) [Add Ξ±] [LE Ξ±] : Prop
extends ExistsAddOfLE Ξ± where
/-- For any `a` and `b`, `a β€ a + b` -/
protected le_self_add : β a b : Ξ±, a β€ a + b
attribute [instance 50] CanonicallyOrderedAdd.toExistsAddOfLE
/-- An ordered monoid is `CanonicallyOrderedMul`
if the ordering coincides with the divisibility relation,
which is to say, `a β€ b` iff there exists `c` with `b = a * c`.
Examples seem rare; it seems more likely that the `OrderDual`
of a naturally-occurring lattice satisfies this than the lattice
itself (for example, dual of the lattice of ideals of a PID or
Dedekind domain satisfy this; collections of all things β€ 1 seem to
be more natural that collections of all things β₯ 1). -/
@[to_additive]
class CanonicallyOrderedMul (Ξ± : Type*) [Mul Ξ±] [LE Ξ±] : Prop
extends ExistsMulOfLE Ξ± where
/-- For any `a` and `b`, `a β€ a * b` -/
protected le_self_mul : β a b : Ξ±, a β€ a * b
attribute [instance 50] CanonicallyOrderedMul.toExistsMulOfLE
set_option linter.deprecated false in
/-- A canonically ordered additive monoid is an ordered commutative additive monoid
in which the ordering coincides with the subtractibility relation,
which is to say, `a β€ b` iff there exists `c` with `b = a + c`.
This is satisfied by the natural numbers, for example, but not
the integers or other nontrivial `OrderedAddCommGroup`s. -/
@[deprecated "Use `[OrderedAddCommMonoid Ξ±] [CanonicallyOrderedAdd Ξ±]` instead."
(since := "2025-01-13")]
structure CanonicallyOrderedAddCommMonoid (Ξ± : Type*) extends
OrderedAddCommMonoid Ξ±, OrderBot Ξ± where
/-- For `a β€ b`, there is a `c` so `b = a + c`. -/
protected exists_add_of_le : β {a b : Ξ±}, a β€ b β β c, b = a + c
/-- For any `a` and `b`, `a β€ a + b` -/
protected le_self_add : β a b : Ξ±, a β€ a + b
set_option linter.deprecated false in
set_option linter.existingAttributeWarning false in
/-- A canonically ordered monoid is an ordered commutative monoid
in which the ordering coincides with the divisibility relation,
which is to say, `a β€ b` iff there exists `c` with `b = a * c`.
Examples seem rare; it seems more likely that the `OrderDual`
of a naturally-occurring lattice satisfies this than the lattice
itself (for example, dual of the lattice of ideals of a PID or
Dedekind domain satisfy this; collections of all things β€ 1 seem to
be more natural that collections of all things β₯ 1).
-/
@[to_additive,
deprecated "Use `[OrderedCommMonoid Ξ±] [CanonicallyOrderedMul Ξ±]` instead."
(since := "2025-01-13")]
structure CanonicallyOrderedCommMonoid (Ξ± : Type*) extends OrderedCommMonoid Ξ±, OrderBot Ξ± where
/-- For `a β€ b`, there is a `c` so `b = a * c`. -/
protected exists_mul_of_le : β {a b : Ξ±}, a β€ b β β c, b = a * c
/-- For any `a` and `b`, `a β€ a * b` -/
protected le_self_mul : β a b : Ξ±, a β€ a * b
section Mul
variable [Mul Ξ±]
section LE
variable [LE Ξ±] [CanonicallyOrderedMul Ξ±] {a b c : Ξ±}
@[to_additive]
theorem le_self_mul : a β€ a * b :=
CanonicallyOrderedMul.le_self_mul _ _
@[to_additive (attr := simp)]
theorem self_le_mul_right (a b : Ξ±) : a β€ a * b :=
le_self_mul
@[to_additive]
theorem le_iff_exists_mul : a β€ b β β c, b = a * c :=
β¨exists_mul_of_le, by
rintro β¨c, rflβ©
exact le_self_mulβ©
end LE
section Preorder
variable [Preorder Ξ±] [CanonicallyOrderedMul Ξ±] {a b c : Ξ±}
@[to_additive]
theorem le_of_mul_le_left : a * b β€ c β a β€ c :=
le_self_mul.trans
@[to_additive]
theorem le_mul_of_le_left : a β€ b β a β€ b * c :=
le_self_mul.trans'
@[to_additive] alias le_mul_right := le_mul_of_le_left
end Preorder
end Mul
section CommMagma
variable [CommMagma Ξ±]
section LE
variable [LE Ξ±] [CanonicallyOrderedMul Ξ±] {a b : Ξ±}
@[to_additive]
theorem le_mul_self : a β€ b * a := by
rw [mul_comm]
exact le_self_mul
@[to_additive (attr := simp)]
theorem self_le_mul_left (a b : Ξ±) : a β€ b * a :=
le_mul_self
end LE
section Preorder
variable [Preorder Ξ±] [CanonicallyOrderedMul Ξ±] {a b c : Ξ±}
@[to_additive]
theorem le_of_mul_le_right : a * b β€ c β b β€ c :=
le_mul_self.trans
@[to_additive]
theorem le_mul_of_le_right : a β€ c β a β€ b * c :=
le_mul_self.trans'
@[to_additive] alias le_mul_left := le_mul_of_le_right
@[to_additive]
theorem le_iff_exists_mul' : a β€ b β β c, b = c * a := by
simp only [mul_comm _ a, le_iff_exists_mul]
end Preorder
end CommMagma
section MulOneClass
variable [MulOneClass Ξ±]
section LE
variable [LE Ξ±] [CanonicallyOrderedMul Ξ±] {a b : Ξ±}
@[to_additive (attr := simp) zero_le]
theorem one_le (a : Ξ±) : 1 β€ a :=
le_self_mul.trans_eq (one_mul _)
@[to_additive]
instance (priority := 10) CanonicallyOrderedMul.toOrderBot : OrderBot Ξ± where
bot := 1
bot_le := one_le
@[to_additive] theorem bot_eq_one : (β₯ : Ξ±) = 1 := rfl
end LE
section Preorder
variable [Preorder Ξ±] [CanonicallyOrderedMul Ξ±] {a b : Ξ±}
@[to_additive (attr := simp)]
theorem one_lt_of_gt (h : a < b) : 1 < b :=
h.bot_lt
alias LT.lt.pos := pos_of_gt
@[to_additive existing] alias LT.lt.one_lt := one_lt_of_gt
end Preorder
section PartialOrder
variable [PartialOrder Ξ±] [CanonicallyOrderedMul Ξ±] {a b c : Ξ±}
@[to_additive (attr := simp)] theorem le_one_iff_eq_one : a β€ 1 β a = 1 := le_bot_iff
@[to_additive] theorem one_lt_iff_ne_one : 1 < a β a β 1 := bot_lt_iff_ne_bot
@[to_additive] theorem one_lt_of_ne_one (h : a β 1) : 1 < a := h.bot_lt
@[to_additive] theorem eq_one_or_one_lt (a : Ξ±) : a = 1 β¨ 1 < a := eq_bot_or_bot_lt a
@[to_additive] lemma one_not_mem_iff {s : Set Ξ±} : 1 β s β β x β s, 1 < x := bot_not_mem_iff
alias NE.ne.pos := pos_of_ne_zero
@[to_additive existing] alias NE.ne.one_lt := one_lt_of_ne_one
@[to_additive]
theorem exists_one_lt_mul_of_lt (h : a < b) : β (c : _) (_ : 1 < c), a * c = b := by
obtain β¨c, hcβ© := le_iff_exists_mul.1 h.le
refine β¨c, one_lt_iff_ne_one.2 ?_, hc.symmβ©
rintro rfl
simp [hc, lt_irrefl] at h
@[to_additive]
theorem lt_iff_exists_mul [MulLeftStrictMono Ξ±] : a < b β β c > 1, b = a * c := by
rw [lt_iff_le_and_ne, le_iff_exists_mul, β exists_and_right]
apply exists_congr
intro c
rw [and_comm, and_congr_left_iff, gt_iff_lt]
rintro rfl
constructor
Β· rw [one_lt_iff_ne_one]
apply mt
rintro rfl
rw [mul_one]
Β· rw [β (self_le_mul_right a c).lt_iff_ne]
apply lt_mul_of_one_lt_right'
end PartialOrder
end MulOneClass
section Semigroup
variable [Semigroup Ξ±]
section LE
variable [LE Ξ±] [CanonicallyOrderedMul Ξ±]
-- see Note [lower instance priority]
@[to_additive]
instance (priority := 10) CanonicallyOrderedMul.toMulLeftMono :
MulLeftMono Ξ± where
elim a b c hbc := by
obtain β¨c, hc, rflβ© := exists_mul_of_le hbc
rw [le_iff_exists_mul]
exact β¨c, (mul_assoc _ _ _).symmβ©
end LE
end Semigroup
-- TODO: make it an instance
@[to_additive]
lemma CanonicallyOrderedMul.toIsOrderedMonoid
[CommMonoid Ξ±] [PartialOrder Ξ±] [CanonicallyOrderedMul Ξ±] : IsOrderedMonoid Ξ± where
mul_le_mul_left _ _ := mul_le_mul_left'
section Monoid
variable [Monoid Ξ±]
section PartialOrder
variable [PartialOrder Ξ±] [CanonicallyOrderedMul Ξ±] {a b c : Ξ±}
@[to_additive] instance CanonicallyOrderedCommMonoid.toUniqueUnits : Unique Ξ±Λ£ where
uniq a := Units.ext <| le_one_iff_eq_one.mp (le_of_mul_le_left a.mul_inv.le)
end PartialOrder
end Monoid
section CommMonoid
variable [CommMonoid Ξ±]
section PartialOrder
variable [PartialOrder Ξ±] [CanonicallyOrderedMul Ξ±] {a b c : Ξ±}
@[to_additive (attr := simp) add_pos_iff]
theorem one_lt_mul_iff : 1 < a * b β 1 < a β¨ 1 < b := by
simp only [one_lt_iff_ne_one, Ne, mul_eq_one, not_and_or]
end PartialOrder
end CommMonoid
namespace NeZero
theorem pos {M} [AddZeroClass M] [PartialOrder M] [CanonicallyOrderedAdd M]
(a : M) [NeZero a] : 0 < a :=
(zero_le a).lt_of_ne <| NeZero.out.symm
theorem of_gt {M} [AddZeroClass M] [Preorder M] [CanonicallyOrderedAdd M]
{x y : M} (h : x < y) : NeZero y :=
of_pos <| pos_of_gt h
-- 1 < p is still an often-used `Fact`, due to `Nat.Prime` implying it, and it implying `Nontrivial`
-- on `ZMod`'s ring structure. We cannot just set this to be any `x < y`, else that becomes a
-- metavariable and it will hugely slow down typeclass inference.
instance (priority := 10) of_gt' {M : Type*} [AddZeroClass M] [Preorder M] [CanonicallyOrderedAdd M]
[One M] {y : M}
[Fact (1 < y)] : NeZero y := of_gt <| @Fact.out (1 < y) _
end NeZero
set_option linter.deprecated false in
/-- A canonically linear-ordered additive monoid is a canonically ordered additive monoid
whose ordering is a linear order. -/
@[deprecated "Use `[LinearOrderedAddCommMonoid Ξ±] [CanonicallyOrderedAdd Ξ±]` instead."
(since := "2025-01-13")]
structure CanonicallyLinearOrderedAddCommMonoid (Ξ± : Type*)
extends CanonicallyOrderedAddCommMonoid Ξ±, LinearOrderedAddCommMonoid Ξ±
set_option linter.deprecated false in
set_option linter.existingAttributeWarning false in
/-- A canonically linear-ordered monoid is a canonically ordered monoid
whose ordering is a linear order. -/
@[to_additive,
deprecated "Use `[LinearOrderedCommMonoid Ξ±] [CanonicallyOrderedMul Ξ±]` instead."
(since := "2025-01-13")]
structure CanonicallyLinearOrderedCommMonoid (Ξ± : Type*)
extends CanonicallyOrderedCommMonoid Ξ±, LinearOrderedCommMonoid Ξ±
attribute [nolint docBlame] CanonicallyLinearOrderedAddCommMonoid.toLinearOrderedAddCommMonoid
attribute [nolint docBlame] CanonicallyLinearOrderedCommMonoid.toLinearOrderedCommMonoid
section CanonicallyLinearOrderedCommMonoid
variable [CommMonoid Ξ±] [LinearOrder Ξ±] [CanonicallyOrderedMul Ξ±]
@[to_additive]
theorem min_mul_distrib (a b c : Ξ±) : min a (b * c) = min a (min a b * min a c) := by
rcases le_total a b with hb | hb
Β· simp [hb, le_mul_right]
Β· rcases le_total a c with hc | hc
Β· simp [hc, le_mul_left]
Β· simp [hb, hc]
@[to_additive]
theorem min_mul_distrib' (a b c : Ξ±) : min (a * b) c = min (min a c * min b c) c := by
simpa [min_comm _ c] using min_mul_distrib c a b
@[to_additive]
theorem one_min (a : Ξ±) : min 1 a = 1 :=
min_eq_left (one_le a)
@[to_additive]
theorem min_one (a : Ξ±) : min a 1 = 1 :=
min_eq_right (one_le a)
|
/-- In a linearly ordered monoid, we are happy for `bot_eq_one` to be a `@[simp]` lemma. -/
@[to_additive (attr := simp)
"In a linearly ordered monoid, we are happy for `bot_eq_zero` to be a `@[simp]` lemma"]
theorem bot_eq_one' : (β₯ : Ξ±) = 1 :=
bot_eq_one
| Mathlib/Algebra/Order/Monoid/Canonical/Defs.lean | 344 | 349 |
/-
Copyright (c) 2021 Benjamin Davidson. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Benjamin Davidson
-/
import Mathlib.Analysis.SpecialFunctions.Log.NegMulLog
import Mathlib.Analysis.SpecialFunctions.NonIntegrable
import Mathlib.Analysis.SpecialFunctions.Pow.Deriv
import Mathlib.Analysis.SpecialFunctions.Trigonometric.ArctanDeriv
import Mathlib.MeasureTheory.Integral.IntervalIntegral.IntegrationByParts
/-!
# Integration of specific interval integrals
This file contains proofs of the integrals of various specific functions. This includes:
* Integrals of simple functions, such as `id`, `pow`, `inv`, `exp`, `log`
* Integrals of some trigonometric functions, such as `sin`, `cos`, `1 / (1 + x^2)`
* The integral of `cos x ^ 2 - sin x ^ 2`
* Reduction formulae for the integrals of `sin x ^ n` and `cos x ^ n` for `n β₯ 2`
* The computation of `β« x in 0..Ο, sin x ^ n` as a product for even and odd `n` (used in proving the
Wallis product for pi)
* Integrals of the form `sin x ^ m * cos x ^ n`
With these lemmas, many simple integrals can be computed by `simp` or `norm_num`.
This file also contains some facts about the interval integrability of specific functions.
This file is still being developed.
## Tags
integrate, integration, integrable, integrability
-/
open Real Set Finset
open scoped Real Interval
variable {a b : β} (n : β)
namespace intervalIntegral
open MeasureTheory
variable {f : β β β} {ΞΌ : Measure β} [IsLocallyFiniteMeasure ΞΌ] (c d : β)
/-! ### Interval integrability -/
@[simp]
theorem intervalIntegrable_pow : IntervalIntegrable (fun x => x ^ n) ΞΌ a b :=
(continuous_pow n).intervalIntegrable a b
theorem intervalIntegrable_zpow {n : β€} (h : 0 β€ n β¨ (0 : β) β [[a, b]]) :
IntervalIntegrable (fun x => x ^ n) ΞΌ a b :=
(continuousOn_id.zpowβ n fun _ hx => h.symm.imp (ne_of_mem_of_not_mem hx) id).intervalIntegrable
/-- See `intervalIntegrable_rpow'` for a version with a weaker hypothesis on `r`, but assuming the
measure is volume. -/
theorem intervalIntegrable_rpow {r : β} (h : 0 β€ r β¨ (0 : β) β [[a, b]]) :
IntervalIntegrable (fun x => x ^ r) ΞΌ a b :=
(continuousOn_id.rpow_const fun _ hx =>
h.symm.imp (ne_of_mem_of_not_mem hx) id).intervalIntegrable
/-- See `intervalIntegrable_rpow` for a version applying to any locally finite measure, but with a
stronger hypothesis on `r`. -/
theorem intervalIntegrable_rpow' {r : β} (h : -1 < r) :
IntervalIntegrable (fun x => x ^ r) volume a b := by
suffices β c : β, IntervalIntegrable (fun x => x ^ r) volume 0 c by
exact IntervalIntegrable.trans (this a).symm (this b)
have : β c : β, 0 β€ c β IntervalIntegrable (fun x => x ^ r) volume 0 c := by
intro c hc
rw [intervalIntegrable_iff, uIoc_of_le hc]
have hderiv : β x β Ioo 0 c, HasDerivAt (fun x : β => x ^ (r + 1) / (r + 1)) (x ^ r) x := by
intro x hx
convert (Real.hasDerivAt_rpow_const (p := r + 1) (Or.inl hx.1.ne')).div_const (r + 1) using 1
field_simp [(by linarith : r + 1 β 0)]
apply integrableOn_deriv_of_nonneg _ hderiv
Β· intro x hx; apply rpow_nonneg hx.1.le
Β· refine (continuousOn_id.rpow_const ?_).div_const _; intro x _; right; linarith
intro c; rcases le_total 0 c with (hc | hc)
Β· exact this c hc
Β· rw [IntervalIntegrable.iff_comp_neg, neg_zero]
have m := (this (-c) (by linarith)).smul (cos (r * Ο))
rw [intervalIntegrable_iff] at m β’
refine m.congr_fun ?_ measurableSet_Ioc; intro x hx
rw [uIoc_of_le (by linarith : 0 β€ -c)] at hx
simp only [Pi.smul_apply, Algebra.id.smul_eq_mul, log_neg_eq_log, mul_comm,
rpow_def_of_pos hx.1, rpow_def_of_neg (by linarith [hx.1] : -x < 0)]
/-- The power function `x β¦ x^s` is integrable on `(0, t)` iff `-1 < s`. -/
lemma integrableOn_Ioo_rpow_iff {s t : β} (ht : 0 < t) :
IntegrableOn (fun x β¦ x ^ s) (Ioo (0 : β) t) β -1 < s := by
refine β¨fun h β¦ ?_, fun h β¦ by simpa [intervalIntegrable_iff_integrableOn_Ioo_of_le ht.le]
using intervalIntegrable_rpow' h (a := 0) (b := t)β©
contrapose! h
intro H
have I : 0 < min 1 t := lt_min zero_lt_one ht
have H' : IntegrableOn (fun x β¦ x ^ s) (Ioo 0 (min 1 t)) :=
H.mono (Set.Ioo_subset_Ioo le_rfl (min_le_right _ _)) le_rfl
have : IntegrableOn (fun x β¦ xβ»ΒΉ) (Ioo 0 (min 1 t)) := by
apply H'.mono' measurable_inv.aestronglyMeasurable
filter_upwards [ae_restrict_mem measurableSet_Ioo] with x hx
simp only [norm_inv, Real.norm_eq_abs, abs_of_nonneg (le_of_lt hx.1)]
rwa [β Real.rpow_neg_one x, Real.rpow_le_rpow_left_iff_of_base_lt_one hx.1]
exact lt_of_lt_of_le hx.2 (min_le_left _ _)
have : IntervalIntegrable (fun x β¦ xβ»ΒΉ) volume 0 (min 1 t) := by
rwa [intervalIntegrable_iff_integrableOn_Ioo_of_le I.le]
simp [intervalIntegrable_inv_iff, I.ne] at this
/-- See `intervalIntegrable_cpow'` for a version with a weaker hypothesis on `r`, but assuming the
measure is volume. -/
theorem intervalIntegrable_cpow {r : β} (h : 0 β€ r.re β¨ (0 : β) β [[a, b]]) :
IntervalIntegrable (fun x : β => (x : β) ^ r) ΞΌ a b := by
by_cases h2 : (0 : β) β [[a, b]]
Β· -- Easy case #1: 0 β [a, b] -- use continuity.
refine (continuousOn_of_forall_continuousAt fun x hx => ?_).intervalIntegrable
exact Complex.continuousAt_ofReal_cpow_const _ _ (Or.inr <| ne_of_mem_of_not_mem hx h2)
rw [eq_false h2, or_false] at h
rcases lt_or_eq_of_le h with (h' | h')
Β· -- Easy case #2: 0 < re r -- again use continuity
exact (Complex.continuous_ofReal_cpow_const h').intervalIntegrable _ _
-- Now the hard case: re r = 0 and 0 is in the interval.
refine (IntervalIntegrable.intervalIntegrable_norm_iff ?_).mp ?_
Β· refine (measurable_of_continuousOn_compl_singleton (0 : β) ?_).aestronglyMeasurable
exact continuousOn_of_forall_continuousAt fun x hx =>
Complex.continuousAt_ofReal_cpow_const x r (Or.inr hx)
-- reduce to case of integral over `[0, c]`
suffices β c : β, IntervalIntegrable (fun x : β => β(x : β) ^ rβ) ΞΌ 0 c from
(this a).symm.trans (this b)
intro c
rcases le_or_lt 0 c with (hc | hc)
Β· -- case `0 β€ c`: integrand is identically 1
have : IntervalIntegrable (fun _ => 1 : β β β) ΞΌ 0 c := intervalIntegrable_const
rw [intervalIntegrable_iff_integrableOn_Ioc_of_le hc] at this β’
refine IntegrableOn.congr_fun this (fun x hx => ?_) measurableSet_Ioc
dsimp only
rw [Complex.norm_cpow_eq_rpow_re_of_pos hx.1, β h', rpow_zero]
Β· -- case `c < 0`: integrand is identically constant, *except* at `x = 0` if `r β 0`.
apply IntervalIntegrable.symm
rw [intervalIntegrable_iff_integrableOn_Ioc_of_le hc.le]
rw [β Ioo_union_right hc, integrableOn_union, and_comm]; constructor
Β· refine integrableOn_singleton_iff.mpr (Or.inr ?_)
exact isFiniteMeasureOnCompacts_of_isLocallyFiniteMeasure.lt_top_of_isCompact
isCompact_singleton
Β· have : β x : β, x β Ioo c 0 β βComplex.exp (βΟ * Complex.I * r)β = β(x : β) ^ rβ := by
intro x hx
rw [Complex.ofReal_cpow_of_nonpos hx.2.le, norm_mul, β Complex.ofReal_neg,
Complex.norm_cpow_eq_rpow_re_of_pos (neg_pos.mpr hx.2), β h',
rpow_zero, one_mul]
refine IntegrableOn.congr_fun ?_ this measurableSet_Ioo
rw [integrableOn_const]
refine Or.inr ((measure_mono Set.Ioo_subset_Icc_self).trans_lt ?_)
exact isFiniteMeasureOnCompacts_of_isLocallyFiniteMeasure.lt_top_of_isCompact isCompact_Icc
/-- See `intervalIntegrable_cpow` for a version applying to any locally finite measure, but with a
stronger hypothesis on `r`. -/
theorem intervalIntegrable_cpow' {r : β} (h : -1 < r.re) :
IntervalIntegrable (fun x : β => (x : β) ^ r) volume a b := by
suffices β c : β, IntervalIntegrable (fun x => (x : β) ^ r) volume 0 c by
exact IntervalIntegrable.trans (this a).symm (this b)
have : β c : β, 0 β€ c β IntervalIntegrable (fun x => (x : β) ^ r) volume 0 c := by
intro c hc
rw [β IntervalIntegrable.intervalIntegrable_norm_iff]
Β· rw [intervalIntegrable_iff]
apply IntegrableOn.congr_fun
Β· rw [β intervalIntegrable_iff]; exact intervalIntegral.intervalIntegrable_rpow' h
Β· intro x hx
rw [uIoc_of_le hc] at hx
dsimp only
rw [Complex.norm_cpow_eq_rpow_re_of_pos hx.1]
Β· exact measurableSet_uIoc
Β· refine ContinuousOn.aestronglyMeasurable ?_ measurableSet_uIoc
refine continuousOn_of_forall_continuousAt fun x hx => ?_
rw [uIoc_of_le hc] at hx
refine (continuousAt_cpow_const (Or.inl ?_)).comp Complex.continuous_ofReal.continuousAt
rw [Complex.ofReal_re]
exact hx.1
intro c; rcases le_total 0 c with (hc | hc)
Β· exact this c hc
Β· rw [IntervalIntegrable.iff_comp_neg, neg_zero]
have m := (this (-c) (by linarith)).const_mul (Complex.exp (Ο * Complex.I * r))
rw [intervalIntegrable_iff, uIoc_of_le (by linarith : 0 β€ -c)] at m β’
refine m.congr_fun (fun x hx => ?_) measurableSet_Ioc
dsimp only
have : -x β€ 0 := by linarith [hx.1]
rw [Complex.ofReal_cpow_of_nonpos this, mul_comm]
simp
/-- The complex power function `x β¦ x^s` is integrable on `(0, t)` iff `-1 < s.re`. -/
theorem integrableOn_Ioo_cpow_iff {s : β} {t : β} (ht : 0 < t) :
IntegrableOn (fun x : β β¦ (x : β) ^ s) (Ioo (0 : β) t) β -1 < s.re := by
refine β¨fun h β¦ ?_, fun h β¦ by simpa [intervalIntegrable_iff_integrableOn_Ioo_of_le ht.le]
using intervalIntegrable_cpow' h (a := 0) (b := t)β©
have B : IntegrableOn (fun a β¦ a ^ s.re) (Ioo 0 t) := by
apply (integrableOn_congr_fun _ measurableSet_Ioo).1 h.norm
intro a ha
simp [Complex.norm_cpow_eq_rpow_re_of_pos ha.1]
rwa [integrableOn_Ioo_rpow_iff ht] at B
@[simp]
theorem intervalIntegrable_id : IntervalIntegrable (fun x => x) ΞΌ a b :=
continuous_id.intervalIntegrable a b
theorem intervalIntegrable_const : IntervalIntegrable (fun _ => c) ΞΌ a b :=
continuous_const.intervalIntegrable a b
theorem intervalIntegrable_one_div (h : β x : β, x β [[a, b]] β f x β 0)
(hf : ContinuousOn f [[a, b]]) : IntervalIntegrable (fun x => 1 / f x) ΞΌ a b :=
(continuousOn_const.div hf h).intervalIntegrable
@[simp]
theorem intervalIntegrable_inv (h : β x : β, x β [[a, b]] β f x β 0)
(hf : ContinuousOn f [[a, b]]) : IntervalIntegrable (fun x => (f x)β»ΒΉ) ΞΌ a b := by
simpa only [one_div] using intervalIntegrable_one_div h hf
@[simp]
theorem intervalIntegrable_exp : IntervalIntegrable exp ΞΌ a b :=
continuous_exp.intervalIntegrable a b
@[simp]
theorem _root_.IntervalIntegrable.log (hf : ContinuousOn f [[a, b]])
(h : β x : β, x β [[a, b]] β f x β 0) :
IntervalIntegrable (fun x => log (f x)) ΞΌ a b :=
(ContinuousOn.log hf h).intervalIntegrable
/-- See `intervalIntegrable_log'` for a version without any hypothesis on the interval, but
assuming the measure is volume. -/
@[simp]
theorem intervalIntegrable_log (h : (0 : β) β [[a, b]]) : IntervalIntegrable log ΞΌ a b :=
IntervalIntegrable.log continuousOn_id fun _ hx => ne_of_mem_of_not_mem hx h
/-- The real logarithm is interval integrable (with respect to the volume measure) on every
interval. See `intervalIntegrable_log` for a version applying to any locally finite measure,
but with an additional hypothesis on the interval. -/
@[simp]
theorem intervalIntegrable_log' : IntervalIntegrable log volume a b := by
-- Log is even, so it suffices to consider the case 0 < a and b = 0
apply intervalIntegrable_of_even (log_neg_eq_log Β· |>.symm)
intro x hx
-- Split integral
apply IntervalIntegrable.trans (b := 1)
Β· -- Show integrability on [0β¦1] using non-negativity of the derivative
rw [β neg_neg log]
apply IntervalIntegrable.neg
apply intervalIntegrable_deriv_of_nonneg (g := fun x β¦ -(x * log x - x))
Β· exact (continuous_mul_log.continuousOn.sub continuous_id.continuousOn).neg
Β· intro s β¨hs, _β©
norm_num at *
simpa using (hasDerivAt_id s).sub (hasDerivAt_mul_log hs.ne.symm)
Β· intro s β¨hsβ, hsββ©
norm_num at *
exact (log_nonpos_iff hsβ.le).mpr hsβ.le
Β· -- Show integrability on [1β¦t] by continuity
apply ContinuousOn.intervalIntegrable
apply Real.continuousOn_log.mono
apply Set.not_mem_uIcc_of_lt zero_lt_one at hx
simpa
@[simp]
theorem intervalIntegrable_sin : IntervalIntegrable sin ΞΌ a b :=
continuous_sin.intervalIntegrable a b
@[simp]
theorem intervalIntegrable_cos : IntervalIntegrable cos ΞΌ a b :=
continuous_cos.intervalIntegrable a b
theorem intervalIntegrable_one_div_one_add_sq :
IntervalIntegrable (fun x : β => 1 / (β1 + x ^ 2)) ΞΌ a b := by
refine (continuous_const.div ?_ fun x => ?_).intervalIntegrable a b
Β· fun_prop
Β· nlinarith
@[simp]
theorem intervalIntegrable_inv_one_add_sq :
IntervalIntegrable (fun x : β => (β1 + x ^ 2)β»ΒΉ) ΞΌ a b := by
field_simp; exact mod_cast intervalIntegrable_one_div_one_add_sq
/-! ### Integrals of the form `c * β« x in a..b, f (c * x + d)` -/
section
@[simp]
theorem mul_integral_comp_mul_right : (c * β« x in a..b, f (x * c)) = β« x in a * c..b * c, f x :=
smul_integral_comp_mul_right f c
@[simp]
theorem mul_integral_comp_mul_left : (c * β« x in a..b, f (c * x)) = β« x in c * a..c * b, f x :=
smul_integral_comp_mul_left f c
@[simp]
theorem inv_mul_integral_comp_div : (cβ»ΒΉ * β« x in a..b, f (x / c)) = β« x in a / c..b / c, f x :=
inv_smul_integral_comp_div f c
@[simp]
theorem mul_integral_comp_mul_add :
(c * β« x in a..b, f (c * x + d)) = β« x in c * a + d..c * b + d, f x :=
smul_integral_comp_mul_add f c d
@[simp]
theorem mul_integral_comp_add_mul :
(c * β« x in a..b, f (d + c * x)) = β« x in d + c * a..d + c * b, f x :=
smul_integral_comp_add_mul f c d
@[simp]
theorem inv_mul_integral_comp_div_add :
(cβ»ΒΉ * β« x in a..b, f (x / c + d)) = β« x in a / c + d..b / c + d, f x :=
inv_smul_integral_comp_div_add f c d
@[simp]
theorem inv_mul_integral_comp_add_div :
(cβ»ΒΉ * β« x in a..b, f (d + x / c)) = β« x in d + a / c..d + b / c, f x :=
inv_smul_integral_comp_add_div f c d
@[simp]
theorem mul_integral_comp_mul_sub :
(c * β« x in a..b, f (c * x - d)) = β« x in c * a - d..c * b - d, f x :=
smul_integral_comp_mul_sub f c d
@[simp]
theorem mul_integral_comp_sub_mul :
(c * β« x in a..b, f (d - c * x)) = β« x in d - c * b..d - c * a, f x :=
smul_integral_comp_sub_mul f c d
@[simp]
theorem inv_mul_integral_comp_div_sub :
(cβ»ΒΉ * β« x in a..b, f (x / c - d)) = β« x in a / c - d..b / c - d, f x :=
inv_smul_integral_comp_div_sub f c d
@[simp]
theorem inv_mul_integral_comp_sub_div :
(cβ»ΒΉ * β« x in a..b, f (d - x / c)) = β« x in d - b / c..d - a / c, f x :=
inv_smul_integral_comp_sub_div f c d
end
end intervalIntegral
open intervalIntegral
/-! ### Integrals of simple functions -/
theorem integral_cpow {r : β} (h : -1 < r.re β¨ r β -1 β§ (0 : β) β [[a, b]]) :
(β« x : β in a..b, (x : β) ^ r) = ((b : β) ^ (r + 1) - (a : β) ^ (r + 1)) / (r + 1) := by
rw [sub_div]
have hr : r + 1 β 0 := by
rcases h with h | h
Β· apply_fun Complex.re
rw [Complex.add_re, Complex.one_re, Complex.zero_re, Ne, add_eq_zero_iff_eq_neg]
exact h.ne'
Β· rw [Ne, β add_eq_zero_iff_eq_neg] at h; exact h.1
by_cases hab : (0 : β) β [[a, b]]
Β· apply integral_eq_sub_of_hasDerivAt (fun x hx => ?_)
(intervalIntegrable_cpow (r := r) <| Or.inr hab)
refine hasDerivAt_ofReal_cpow_const' (ne_of_mem_of_not_mem hx hab) ?_
contrapose! hr; rwa [add_eq_zero_iff_eq_neg]
replace h : -1 < r.re := by tauto
suffices β c : β, (β« x : β in (0)..c, (x : β) ^ r) =
(c : β) ^ (r + 1) / (r + 1) - (0 : β) ^ (r + 1) / (r + 1) by
rw [β integral_add_adjacent_intervals (@intervalIntegrable_cpow' a 0 r h)
(@intervalIntegrable_cpow' 0 b r h), integral_symm, this a, this b, Complex.zero_cpow hr]
ring
intro c
apply integral_eq_sub_of_hasDeriv_right
Β· refine ((Complex.continuous_ofReal_cpow_const ?_).div_const _).continuousOn
rwa [Complex.add_re, Complex.one_re, β neg_lt_iff_pos_add]
Β· refine fun x hx => (hasDerivAt_ofReal_cpow_const' ?_ ?_).hasDerivWithinAt
Β· rcases le_total c 0 with (hc | hc)
Β· rw [max_eq_left hc] at hx; exact hx.2.ne
Β· rw [min_eq_left hc] at hx; exact hx.1.ne'
Β· contrapose! hr; rw [hr]; ring
Β· exact intervalIntegrable_cpow' h
theorem integral_rpow {r : β} (h : -1 < r β¨ r β -1 β§ (0 : β) β [[a, b]]) :
β« x in a..b, x ^ r = (b ^ (r + 1) - a ^ (r + 1)) / (r + 1) := by
have h' : -1 < (r : β).re β¨ (r : β) β -1 β§ (0 : β) β [[a, b]] := by
cases h
Β· left; rwa [Complex.ofReal_re]
Β· right; rwa [β Complex.ofReal_one, β Complex.ofReal_neg, Ne, Complex.ofReal_inj]
have :
(β« x in a..b, (x : β) ^ (r : β)) = ((b : β) ^ (r + 1 : β) - (a : β) ^ (r + 1 : β)) / (r + 1) :=
integral_cpow h'
apply_fun Complex.re at this; convert this
Β· simp_rw [intervalIntegral_eq_integral_uIoc, Complex.real_smul, Complex.re_ofReal_mul, rpow_def,
β RCLike.re_eq_complex_re, smul_eq_mul]
rw [integral_re]
refine intervalIntegrable_iff.mp ?_
rcases h' with h' | h'
Β· exact intervalIntegrable_cpow' h'
Β· exact intervalIntegrable_cpow (Or.inr h'.2)
Β· rw [(by push_cast; rfl : (r : β) + 1 = ((r + 1 : β) : β))]
simp_rw [div_eq_inv_mul, β Complex.ofReal_inv, Complex.re_ofReal_mul, Complex.sub_re, rpow_def]
theorem integral_zpow {n : β€} (h : 0 β€ n β¨ n β -1 β§ (0 : β) β [[a, b]]) :
β« x in a..b, x ^ n = (b ^ (n + 1) - a ^ (n + 1)) / (n + 1) := by
replace h : -1 < (n : β) β¨ (n : β) β -1 β§ (0 : β) β [[a, b]] := mod_cast h
exact mod_cast integral_rpow h
@[simp]
theorem integral_pow : β« x in a..b, x ^ n = (b ^ (n + 1) - a ^ (n + 1)) / (n + 1) := by
simpa only [β Int.natCast_succ, zpow_natCast] using integral_zpow (Or.inl n.cast_nonneg)
/-- Integral of `|x - a| ^ n` over `Ξ a b`. This integral appears in the proof of the
Picard-LindelΓΆf/Cauchy-Lipschitz theorem. -/
theorem integral_pow_abs_sub_uIoc : β« x in Ξ a b, |x - a| ^ n = |b - a| ^ (n + 1) / (n + 1) := by
rcases le_or_lt a b with hab | hab
Β· calc
β« x in Ξ a b, |x - a| ^ n = β« x in a..b, |x - a| ^ n := by
rw [uIoc_of_le hab, β integral_of_le hab]
_ = β« x in (0)..(b - a), x ^ n := by
simp only [integral_comp_sub_right fun x => |x| ^ n, sub_self]
refine integral_congr fun x hx => congr_argβ Pow.pow (abs_of_nonneg <| ?_) rfl
rw [uIcc_of_le (sub_nonneg.2 hab)] at hx
exact hx.1
_ = |b - a| ^ (n + 1) / (n + 1) := by simp [abs_of_nonneg (sub_nonneg.2 hab)]
Β· calc
β« x in Ξ a b, |x - a| ^ n = β« x in b..a, |x - a| ^ n := by
rw [uIoc_of_ge hab.le, β integral_of_le hab.le]
_ = β« x in b - a..0, (-x) ^ n := by
simp only [integral_comp_sub_right fun x => |x| ^ n, sub_self]
refine integral_congr fun x hx => congr_argβ Pow.pow (abs_of_nonpos <| ?_) rfl
rw [uIcc_of_le (sub_nonpos.2 hab.le)] at hx
exact hx.2
_ = |b - a| ^ (n + 1) / (n + 1) := by
simp [integral_comp_neg fun x => x ^ n, abs_of_neg (sub_neg.2 hab)]
@[simp]
theorem integral_id : β« x in a..b, x = (b ^ 2 - a ^ 2) / 2 := by
have := @integral_pow a b 1
norm_num at this
exact this
theorem integral_one : (β« _ in a..b, (1 : β)) = b - a := by
simp only [mul_one, smul_eq_mul, integral_const]
theorem integral_const_on_unit_interval : β« _ in a..a + 1, b = b := by simp
@[simp]
theorem integral_inv (h : (0 : β) β [[a, b]]) : β« x in a..b, xβ»ΒΉ = log (b / a) := by
have h' := fun x (hx : x β [[a, b]]) => ne_of_mem_of_not_mem hx h
rw [integral_deriv_eq_sub' _ deriv_log' (fun x hx => differentiableAt_log (h' x hx))
(continuousOn_invβ.mono <| subset_compl_singleton_iff.mpr h),
log_div (h' b right_mem_uIcc) (h' a left_mem_uIcc)]
@[simp]
theorem integral_inv_of_pos (ha : 0 < a) (hb : 0 < b) : β« x in a..b, xβ»ΒΉ = log (b / a) :=
integral_inv <| not_mem_uIcc_of_lt ha hb
@[simp]
theorem integral_inv_of_neg (ha : a < 0) (hb : b < 0) : β« x in a..b, xβ»ΒΉ = log (b / a) :=
integral_inv <| not_mem_uIcc_of_gt ha hb
theorem integral_one_div (h : (0 : β) β [[a, b]]) : β« x : β in a..b, 1 / x = log (b / a) := by
simp only [one_div, integral_inv h]
theorem integral_one_div_of_pos (ha : 0 < a) (hb : 0 < b) :
β« x : β in a..b, 1 / x = log (b / a) := by simp only [one_div, integral_inv_of_pos ha hb]
theorem integral_one_div_of_neg (ha : a < 0) (hb : b < 0) :
β« x : β in a..b, 1 / x = log (b / a) := by simp only [one_div, integral_inv_of_neg ha hb]
@[simp]
theorem integral_exp : β« x in a..b, exp x = exp b - exp a := by
rw [integral_deriv_eq_sub']
Β· simp
Β· exact fun _ _ => differentiableAt_exp
Β· exact continuousOn_exp
theorem integral_exp_mul_complex {c : β} (hc : c β 0) :
(β« x in a..b, Complex.exp (c * x)) = (Complex.exp (c * b) - Complex.exp (c * a)) / c := by
have D : β x : β, HasDerivAt (fun y : β => Complex.exp (c * y) / c) (Complex.exp (c * x)) x := by
intro x
conv => congr
rw [β mul_div_cancel_rightβ (Complex.exp (c * x)) hc]
apply ((Complex.hasDerivAt_exp _).comp x _).div_const c
simpa only [mul_one] using ((hasDerivAt_id (x : β)).const_mul _).comp_ofReal
rw [integral_deriv_eq_sub' _ (funext fun x => (D x).deriv) fun x _ => (D x).differentiableAt]
Β· ring
Β· fun_prop
/-- Helper lemma for `integral_log`: case where `a = 0` and `b` is positive. -/
lemma integral_log_from_zero_of_pos (ht : 0 < b) : β« s in (0)..b, log s = b * log b - b := by
-- Compute the integral by giving a primitive and considering it limit as x approaches 0 from the
-- right. The following lines were suggested by Gareth Ma on Zulip.
rw [integral_eq_sub_of_hasDerivAt_of_tendsto (f := fun x β¦ x * log x - x)
(fa := 0) (fb := b * log b - b) (hint := intervalIntegrable_log')]
Β· abel
Β· exact ht
Β· intro s β¨hs, _ β©
simpa using (hasDerivAt_mul_log hs.ne.symm).sub (hasDerivAt_id s)
Β· simpa [mul_comm] using ((tendsto_log_mul_rpow_nhdsGT_zero zero_lt_one).sub
(tendsto_nhdsWithin_of_tendsto_nhds Filter.tendsto_id))
Β· exact tendsto_nhdsWithin_of_tendsto_nhds (ContinuousAt.tendsto (by fun_prop))
/-- Helper lemma for `integral_log`: case where `a = 0`. -/
lemma integral_log_from_zero {b : β} : β« s in (0)..b, log s = b * log b - b := by
rcases lt_trichotomy b 0 with h | h | h
Β· -- If t is negative, use that log is an even function to reduce to the positive case.
conv => arg 1; arg 1; intro t; rw [β log_neg_eq_log]
rw [intervalIntegral.integral_comp_neg, intervalIntegral.integral_symm, neg_zero,
integral_log_from_zero_of_pos (Left.neg_pos_iff.mpr h), log_neg_eq_log]
ring
Β· simp [h]
Β· exact integral_log_from_zero_of_pos h
@[simp]
theorem integral_log : β« s in a..b, log s = b * log b - a * log a - b + a := by
rw [β intervalIntegral.integral_add_adjacent_intervals (b := 0)]
Β· rw [intervalIntegral.integral_symm, integral_log_from_zero, integral_log_from_zero]
ring
all_goals exact intervalIntegrable_log'
@[deprecated (since := "2025-01-12")]
alias integral_log_of_pos := integral_log
@[deprecated (since := "2025-01-12")]
alias integral_log_of_neg := integral_log
@[simp]
theorem integral_sin : β« x in a..b, sin x = cos a - cos b := by
rw [integral_deriv_eq_sub' fun x => -cos x]
Β· ring
Β· norm_num
Β· simp only [differentiableAt_neg_iff, differentiableAt_cos, implies_true]
Β· exact continuousOn_sin
@[simp]
theorem integral_cos : β« x in a..b, cos x = sin b - sin a := by
rw [integral_deriv_eq_sub']
Β· norm_num
Β· simp only [differentiableAt_sin, implies_true]
Β· exact continuousOn_cos
theorem integral_cos_mul_complex {z : β} (hz : z β 0) (a b : β) :
(β« x in a..b, Complex.cos (z * x)) = Complex.sin (z * b) / z - Complex.sin (z * a) / z := by
apply integral_eq_sub_of_hasDerivAt
swap
Β· apply Continuous.intervalIntegrable
exact Complex.continuous_cos.comp (continuous_const.mul Complex.continuous_ofReal)
intro x _
have a := Complex.hasDerivAt_sin (βx * z)
have b : HasDerivAt (fun y => y * z : β β β) z βx := hasDerivAt_mul_const _
have c : HasDerivAt (Complex.sin β fun y : β => (y * z)) _ βx := HasDerivAt.comp (π := β) x a b
have d := HasDerivAt.comp_ofReal (c.div_const z)
simp only [mul_comm] at d
| convert d using 1
conv_rhs => arg 1; rw [mul_comm]
rw [mul_div_cancel_rightβ _ hz]
theorem integral_cos_sq_sub_sin_sq :
β« x in a..b, cos x ^ 2 - sin x ^ 2 = sin b * cos b - sin a * cos a := by
simpa only [sq, sub_eq_add_neg, neg_mul_eq_mul_neg] using
integral_deriv_mul_eq_sub (fun x _ => hasDerivAt_sin x) (fun x _ => hasDerivAt_cos x)
continuousOn_cos.intervalIntegrable continuousOn_sin.neg.intervalIntegrable
theorem integral_one_div_one_add_sq :
(β« x : β in a..b, β1 / (β1 + x ^ 2)) = arctan b - arctan a := by
refine integral_deriv_eq_sub' _ Real.deriv_arctan (fun _ _ => differentiableAt_arctan _)
(continuous_const.div ?_ fun x => ?_).continuousOn
Β· fun_prop
| Mathlib/Analysis/SpecialFunctions/Integrals.lean | 547 | 561 |
/-
Copyright (c) 2018 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Johannes HΓΆlzl, Sander Dahmen, Kim Morrison
-/
import Mathlib.SetTheory.Cardinal.Cofinality
import Mathlib.LinearAlgebra.FreeModule.Finite.Basic
import Mathlib.LinearAlgebra.Dimension.StrongRankCondition
import Mathlib.LinearAlgebra.Dimension.Constructions
/-!
# Conditions for rank to be finite
Also contains characterization for when rank equals zero or rank equals one.
-/
noncomputable section
universe u v v' w
variable {R : Type u} {M Mβ : Type v} {M' : Type v'} {ΞΉ : Type w}
variable [Ring R] [AddCommGroup M] [AddCommGroup M'] [AddCommGroup Mβ]
variable [Module R M] [Module R M'] [Module R Mβ]
attribute [local instance] nontrivial_of_invariantBasisNumber
open Basis Cardinal Function Module Set Submodule
/-- If every finite set of linearly independent vectors has cardinality at most `n`,
then the same is true for arbitrary sets of linearly independent vectors.
-/
theorem linearIndependent_bounded_of_finset_linearIndependent_bounded {n : β}
(H : β s : Finset M, (LinearIndependent R fun i : s => (i : M)) β s.card β€ n) :
β s : Set M, LinearIndependent R ((β) : s β M) β #s β€ n := by
intro s li
apply Cardinal.card_le_of
intro t
rw [β Finset.card_map (Embedding.subtype s)]
apply H
apply linearIndependent_finset_map_embedding_subtype _ li
theorem rank_le {n : β}
(H : β s : Finset M, (LinearIndependent R fun i : s => (i : M)) β s.card β€ n) :
Module.rank R M β€ n := by
rw [Module.rank_def]
apply ciSup_le'
rintro β¨s, liβ©
exact linearIndependent_bounded_of_finset_linearIndependent_bounded H _ li
section RankZero
/-- See `rank_zero_iff` for a stronger version with `NoZeroSMulDivisor R M`. -/
lemma rank_eq_zero_iff :
Module.rank R M = 0 β β x : M, β a : R, a β 0 β§ a β’ x = 0 := by
nontriviality R
constructor
Β· contrapose!
rintro β¨x, hxβ©
rw [β Cardinal.one_le_iff_ne_zero]
have : LinearIndependent R (fun _ : Unit β¦ x) :=
linearIndependent_iff.mpr (fun l hl β¦ Finsupp.unique_ext <| not_not.mp fun H β¦
hx _ H ((Finsupp.linearCombination_unique _ _ _).symm.trans hl))
simpa using this.cardinal_lift_le_rank
Β· intro h
rw [β le_zero_iff, Module.rank_def]
apply ciSup_le'
intro β¨s, hsβ©
rw [nonpos_iff_eq_zero, Cardinal.mk_eq_zero_iff, β not_nonempty_iff]
rintro β¨i : sβ©
obtain β¨a, ha, ha'β© := h i
apply ha
simpa using DFunLike.congr_fun (linearIndependent_iff.mp hs (Finsupp.single i a) (by simpa)) i
theorem rank_pos_of_free [Module.Free R M] [Nontrivial M] :
0 < Module.rank R M :=
have := Module.nontrivial R M
(pos_of_ne_zero <| Cardinal.mk_ne_zero _).trans_le
(Free.chooseBasis R M).linearIndependent.cardinal_le_rank
variable [Nontrivial R]
section
variable [NoZeroSMulDivisors R M]
theorem rank_zero_iff_forall_zero :
Module.rank R M = 0 β β x : M, x = 0 := by
simp_rw [rank_eq_zero_iff, smul_eq_zero, and_or_left, not_and_self_iff, false_or,
exists_and_right, and_iff_right (exists_ne (0 : R))]
/-- See `rank_subsingleton` for the reason that `Nontrivial R` is needed.
Also see `rank_eq_zero_iff` for the version without `NoZeroSMulDivisor R M`. -/
theorem rank_zero_iff : Module.rank R M = 0 β Subsingleton M :=
rank_zero_iff_forall_zero.trans (subsingleton_iff_forall_eq 0).symm
theorem rank_pos_iff_exists_ne_zero : 0 < Module.rank R M β β x : M, x β 0 := by
rw [β not_iff_not]
simpa using rank_zero_iff_forall_zero
theorem rank_pos_iff_nontrivial : 0 < Module.rank R M β Nontrivial M :=
rank_pos_iff_exists_ne_zero.trans (nontrivial_iff_exists_ne 0).symm
theorem rank_pos [Nontrivial M] : 0 < Module.rank R M :=
rank_pos_iff_nontrivial.mpr βΉ_βΊ
end
variable (R M)
/-- See `rank_subsingleton` that assumes `Subsingleton R` instead. -/
@[nontriviality]
theorem rank_subsingleton' [Subsingleton M] : Module.rank R M = 0 :=
rank_eq_zero_iff.mpr fun _ β¦ β¨1, one_ne_zero, Subsingleton.elim _ _β©
@[simp]
theorem rank_punit : Module.rank R PUnit = 0 := rank_subsingleton' _ _
@[simp]
theorem rank_bot : Module.rank R (β₯ : Submodule R M) = 0 := rank_subsingleton' _ _
variable {R M}
theorem exists_mem_ne_zero_of_rank_pos {s : Submodule R M} (h : 0 < Module.rank R s) :
β b : M, b β s β§ b β 0 :=
exists_mem_ne_zero_of_ne_bot fun eq => by rw [eq, rank_bot] at h; exact lt_irrefl _ h
end RankZero
section Finite
theorem Module.finite_of_rank_eq_nat [Module.Free R M] {n : β} (h : Module.rank R M = n) :
Module.Finite R M := by
nontriviality R
obtain β¨β¨ΞΉ, bβ©β© := Module.Free.exists_basis (R := R) (M := M)
have := mk_lt_aleph0_iff.mp <|
b.linearIndependent.cardinal_le_rank |>.trans_eq h |>.trans_lt <| nat_lt_aleph0 n
exact Module.Finite.of_basis b
theorem Module.finite_of_rank_eq_zero [NoZeroSMulDivisors R M]
(h : Module.rank R M = 0) :
Module.Finite R M := by
nontriviality R
rw [rank_zero_iff] at h
infer_instance
theorem Module.finite_of_rank_eq_one [Module.Free R M] (h : Module.rank R M = 1) :
Module.Finite R M :=
Module.finite_of_rank_eq_nat <| h.trans Nat.cast_one.symm
section
variable [StrongRankCondition R]
/-- If a module has a finite dimension, all bases are indexed by a finite type. -/
theorem Basis.nonempty_fintype_index_of_rank_lt_aleph0 {ΞΉ : Type*} (b : Basis ΞΉ R M)
(h : Module.rank R M < β΅β) : Nonempty (Fintype ΞΉ) := by
rwa [β Cardinal.lift_lt, β b.mk_eq_rank, Cardinal.lift_aleph0, Cardinal.lift_lt_aleph0,
Cardinal.lt_aleph0_iff_fintype] at h
/-- If a module has a finite dimension, all bases are indexed by a finite type. -/
noncomputable def Basis.fintypeIndexOfRankLtAleph0 {ΞΉ : Type*} (b : Basis ΞΉ R M)
(h : Module.rank R M < β΅β) : Fintype ΞΉ :=
Classical.choice (b.nonempty_fintype_index_of_rank_lt_aleph0 h)
/-- If a module has a finite dimension, all bases are indexed by a finite set. -/
theorem Basis.finite_index_of_rank_lt_aleph0 {ΞΉ : Type*} {s : Set ΞΉ} (b : Basis s R M)
(h : Module.rank R M < β΅β) : s.Finite :=
finite_def.2 (b.nonempty_fintype_index_of_rank_lt_aleph0 h)
end
namespace LinearIndependent
variable [StrongRankCondition R]
theorem cardinalMk_le_finrank [Module.Finite R M]
{ΞΉ : Type w} {b : ΞΉ β M} (h : LinearIndependent R b) : #ΞΉ β€ finrank R M := by
rw [β lift_le.{max v w}]
simpa only [β finrank_eq_rank, lift_natCast, lift_le_nat_iff] using h.cardinal_lift_le_rank
@[deprecated (since := "2024-11-10")] alias cardinal_mk_le_finrank := cardinalMk_le_finrank
theorem fintype_card_le_finrank [Module.Finite R M]
{ΞΉ : Type*} [Fintype ΞΉ] {b : ΞΉ β M} (h : LinearIndependent R b) :
Fintype.card ΞΉ β€ finrank R M := by
simpa using h.cardinalMk_le_finrank
theorem finset_card_le_finrank [Module.Finite R M]
{b : Finset M} (h : LinearIndependent R (fun x => x : b β M)) :
b.card β€ finrank R M := by
rw [β Fintype.card_coe]
exact h.fintype_card_le_finrank
theorem lt_aleph0_of_finite {ΞΉ : Type w}
[Module.Finite R M] {v : ΞΉ β M} (h : LinearIndependent R v) : #ΞΉ < β΅β := by
apply Cardinal.lift_lt.1
apply lt_of_le_of_lt
Β· apply h.cardinal_lift_le_rank
Β· rw [β finrank_eq_rank, Cardinal.lift_aleph0, Cardinal.lift_natCast]
apply Cardinal.nat_lt_aleph0
theorem finite [Module.Finite R M] {ΞΉ : Type*} {f : ΞΉ β M}
(h : LinearIndependent R f) : Finite ΞΉ :=
Cardinal.lt_aleph0_iff_finite.1 <| h.lt_aleph0_of_finite
theorem setFinite [Module.Finite R M] {b : Set M}
(h : LinearIndependent R fun x : b => (x : M)) : b.Finite :=
Cardinal.lt_aleph0_iff_set_finite.mp h.lt_aleph0_of_finite
end LinearIndependent
lemma exists_set_linearIndependent_of_lt_rank {n : Cardinal} (hn : n < Module.rank R M) :
β s : Set M, #s = n β§ LinearIndepOn R id s := by
obtain β¨β¨s, hsβ©, hs'β© := exists_lt_of_lt_ciSup' (hn.trans_eq (Module.rank_def R M))
obtain β¨t, ht, ht'β© := le_mk_iff_exists_subset.mp hs'.le
exact β¨t, ht', hs.mono htβ©
lemma exists_finset_linearIndependent_of_le_rank {n : β} (hn : n β€ Module.rank R M) :
β s : Finset M, s.card = n β§ LinearIndepOn R id (s : Set M) := by
have := nonempty_linearIndependent_set
rcases hn.eq_or_lt with h | h
Β· obtain β¨β¨s, hsβ©, hs'β© := Cardinal.exists_eq_natCast_of_iSup_eq _
(Cardinal.bddAbove_range _) _ (h.trans (Module.rank_def R M)).symm
have : Finite s := lt_aleph0_iff_finite.mp (hs' βΈ nat_lt_aleph0 n)
cases nonempty_fintype s
refine β¨s.toFinset, by simpa using hs', by simpaβ©
Β· obtain β¨s, hs, hs'β© := exists_set_linearIndependent_of_lt_rank h
have : Finite s := lt_aleph0_iff_finite.mp (hs βΈ nat_lt_aleph0 n)
cases nonempty_fintype s
exact β¨s.toFinset, by simpa using hs, by simpaβ©
lemma exists_linearIndependent_of_le_rank {n : β} (hn : n β€ Module.rank R M) :
β f : Fin n β M, LinearIndependent R f :=
have β¨_, hs, hs'β© := exists_finset_linearIndependent_of_le_rank hn
β¨_, (linearIndependent_equiv (Finset.equivFinOfCardEq hs).symm).mpr hs'β©
lemma natCast_le_rank_iff [Nontrivial R] {n : β} :
n β€ Module.rank R M β β f : Fin n β M, LinearIndependent R f :=
β¨exists_linearIndependent_of_le_rank,
fun H β¦ by simpa using H.choose_spec.cardinal_lift_le_rankβ©
lemma natCast_le_rank_iff_finset [Nontrivial R] {n : β} :
n β€ Module.rank R M β β s : Finset M, s.card = n β§ LinearIndependent R ((β) : s β M) :=
β¨exists_finset_linearIndependent_of_le_rank,
fun β¨s, hβ, hββ© β¦ by simpa [hβ] using hβ.cardinal_le_rankβ©
lemma exists_finset_linearIndependent_of_le_finrank {n : β} (hn : n β€ finrank R M) :
β s : Finset M, s.card = n β§ LinearIndependent R ((β) : s β M) := by
by_cases h : finrank R M = 0
Β· rw [le_zero_iff.mp (hn.trans_eq h)]
exact β¨β
, rfl, by convert linearIndependent_empty R M using 2 <;> aesopβ©
exact exists_finset_linearIndependent_of_le_rank
((Nat.cast_le.mpr hn).trans_eq (cast_toNat_of_lt_aleph0 (toNat_ne_zero.mp h).2))
lemma exists_linearIndependent_of_le_finrank {n : β} (hn : n β€ finrank R M) :
β f : Fin n β M, LinearIndependent R f :=
have β¨_, hs, hs'β© := exists_finset_linearIndependent_of_le_finrank hn
β¨_, (linearIndependent_equiv (Finset.equivFinOfCardEq hs).symm).mpr hs'β©
variable [Module.Finite R M] [StrongRankCondition R] in
theorem Module.Finite.not_linearIndependent_of_infinite {ΞΉ : Type*} [Infinite ΞΉ]
(v : ΞΉ β M) : Β¬LinearIndependent R v := mt LinearIndependent.finite <| @not_finite _ _
section
variable [NoZeroSMulDivisors R M]
theorem iSupIndep.subtype_ne_bot_le_rank [Nontrivial R]
{V : ΞΉ β Submodule R M} (hV : iSupIndep V) :
Cardinal.lift.{v} #{ i : ΞΉ // V i β β₯ } β€ Cardinal.lift.{w} (Module.rank R M) := by
set I := { i : ΞΉ // V i β β₯ }
have hI : β i : I, β v β V i, v β (0 : M) := by
intro i
rw [β Submodule.ne_bot_iff]
exact i.prop
choose v hvV hv using hI
have : LinearIndependent R v := (hV.comp Subtype.coe_injective).linearIndependent _ hvV hv
exact this.cardinal_lift_le_rank
@[deprecated (since := "2024-11-24")]
alias CompleteLattice.Independent.subtype_ne_bot_le_rank := iSupIndep.subtype_ne_bot_le_rank
variable [Module.Finite R M] [StrongRankCondition R]
theorem iSupIndep.subtype_ne_bot_le_finrank_aux
{p : ΞΉ β Submodule R M} (hp : iSupIndep p) :
#{ i // p i β β₯ } β€ (finrank R M : Cardinal.{w}) := by
suffices Cardinal.lift.{v} #{ i // p i β β₯ } β€ Cardinal.lift.{v} (finrank R M : Cardinal.{w}) by
rwa [Cardinal.lift_le] at this
calc
Cardinal.lift.{v} #{ i // p i β β₯ } β€ Cardinal.lift.{w} (Module.rank R M) :=
hp.subtype_ne_bot_le_rank
_ = Cardinal.lift.{w} (finrank R M : Cardinal.{v}) := by rw [finrank_eq_rank]
_ = Cardinal.lift.{v} (finrank R M : Cardinal.{w}) := by simp
/-- If `p` is an independent family of submodules of a `R`-finite module `M`, then the
number of nontrivial subspaces in the family `p` is finite. -/
noncomputable def iSupIndep.fintypeNeBotOfFiniteDimensional
{p : ΞΉ β Submodule R M} (hp : iSupIndep p) :
Fintype { i : ΞΉ // p i β β₯ } := by
suffices #{ i // p i β β₯ } < (β΅β : Cardinal.{w}) by
rw [Cardinal.lt_aleph0_iff_fintype] at this
exact this.some
refine lt_of_le_of_lt hp.subtype_ne_bot_le_finrank_aux ?_
simp [Cardinal.nat_lt_aleph0]
/-- If `p` is an independent family of submodules of a `R`-finite module `M`, then the
number of nontrivial subspaces in the family `p` is bounded above by the dimension of `M`.
Note that the `Fintype` hypothesis required here can be provided by
`iSupIndep.fintypeNeBotOfFiniteDimensional`. -/
theorem iSupIndep.subtype_ne_bot_le_finrank
{p : ΞΉ β Submodule R M} (hp : iSupIndep p) [Fintype { i // p i β β₯ }] :
Fintype.card { i // p i β β₯ } β€ finrank R M := by simpa using hp.subtype_ne_bot_le_finrank_aux
end
variable [Module.Finite R M] [StrongRankCondition R]
section
open Finset
/-- If a finset has cardinality larger than the rank of a module,
then there is a nontrivial linear relation amongst its elements. -/
theorem Module.exists_nontrivial_relation_of_finrank_lt_card {t : Finset M}
(h : finrank R M < t.card) : β f : M β R, β e β t, f e β’ e = 0 β§ β x β t, f x β 0 := by
obtain β¨g, sum, z, nonzeroβ© := Fintype.not_linearIndependent_iff.mp
(mt LinearIndependent.finset_card_le_finrank h.not_le)
refine β¨Subtype.val.extend g 0, ?_, z, z.2, by rwa [Subtype.val_injective.extend_apply]β©
rw [β Finset.sum_finset_coe]; convert sum; apply Subtype.val_injective.extend_apply
/-- If a finset has cardinality larger than `finrank + 1`,
then there is a nontrivial linear relation amongst its elements,
such that the coefficients of the relation sum to zero. -/
theorem Module.exists_nontrivial_relation_sum_zero_of_finrank_succ_lt_card
{t : Finset M} (h : finrank R M + 1 < t.card) :
β f : M β R, β e β t, f e β’ e = 0 β§ β e β t, f e = 0 β§ β x β t, f x β 0 := by
-- Pick an element xβ β t,
obtain β¨xβ, xβ_memβ© := card_pos.1 ((Nat.succ_pos _).trans h)
-- and apply the previous lemma to the {xα΅’ - xβ}
let shift : M βͺ M := β¨(Β· - xβ), sub_left_injectiveβ©
classical
let t' := (t.erase xβ).map shift
have h' : finrank R M < t'.card := by
rw [card_map, card_erase_of_mem xβ_mem]
exact Nat.lt_pred_iff.mpr h
-- to obtain a function `g`.
obtain β¨g, gsum, xβ, xβ_mem, nzβ© := exists_nontrivial_relation_of_finrank_lt_card h'
-- Then obtain `f` by translating back by `xβ`,
-- and setting the value of `f` at `xβ` to ensure `β e β t, f e = 0`.
let f : M β R := fun z β¦ if z = xβ then -β z β t.erase xβ, g (z - xβ) else g (z - xβ)
refine β¨f, ?_, ?_, ?_β©
-- After this, it's a matter of verifying the properties,
-- based on the corresponding properties for `g`.
Β· rw [sum_map, Embedding.coeFn_mk] at gsum
simp_rw [f, β t.sum_erase_add _ xβ_mem, if_pos, neg_smul, sum_smul,
β sub_eq_add_neg, β sum_sub_distrib, β gsum, smul_sub]
refine sum_congr rfl fun x x_mem β¦ ?_
rw [if_neg (mem_erase.mp x_mem).1]
Β· simp_rw [f, β t.sum_erase_add _ xβ_mem, if_pos, add_neg_eq_zero]
exact sum_congr rfl fun x x_mem β¦ if_neg (mem_erase.mp x_mem).1
Β· obtain β¨xβ, xβ_mem', rflβ© := Finset.mem_map.mp xβ_mem
have := mem_erase.mp xβ_mem'
exact β¨xβ, by
simpa only [f, Embedding.coeFn_mk, sub_add_cancel, this.2, true_and, if_neg this.1]β©
end
end Finite
section FinrankZero
section
variable [Nontrivial R]
/-- A (finite dimensional) space that is a subsingleton has zero `finrank`. -/
@[nontriviality]
theorem Module.finrank_zero_of_subsingleton [Subsingleton M] :
finrank R M = 0 := by
rw [finrank, rank_subsingleton', map_zero]
lemma LinearIndependent.finrank_eq_zero_of_infinite {ΞΉ} [Infinite ΞΉ] {v : ΞΉ β M}
(hv : LinearIndependent R v) : finrank R M = 0 := toNat_eq_zero.mpr <| .inr hv.aleph0_le_rank
section
variable [NoZeroSMulDivisors R M]
/-- A finite dimensional space is nontrivial if it has positive `finrank`. -/
theorem Module.nontrivial_of_finrank_pos (h : 0 < finrank R M) : Nontrivial M :=
rank_pos_iff_nontrivial.mp (lt_rank_of_lt_finrank h)
/-- A finite dimensional space is nontrivial if it has `finrank` equal to the successor of a
natural number. -/
theorem Module.nontrivial_of_finrank_eq_succ {n : β}
(hn : finrank R M = n.succ) : Nontrivial M :=
nontrivial_of_finrank_pos (R := R) (by rw [hn]; exact n.succ_pos)
end
variable (R M)
@[simp]
theorem finrank_bot : finrank R (β₯ : Submodule R M) = 0 :=
finrank_eq_of_rank_eq (rank_bot _ _)
end
section StrongRankCondition
variable [StrongRankCondition R] [Module.Finite R M]
/-- A finite rank torsion-free module has positive `finrank` iff it has a nonzero element. -/
theorem Module.finrank_pos_iff_exists_ne_zero [NoZeroSMulDivisors R M] :
0 < finrank R M β β x : M, x β 0 := by
rw [β @rank_pos_iff_exists_ne_zero R M, β finrank_eq_rank]
norm_cast
/-- An `R`-finite torsion-free module has positive `finrank` iff it is nontrivial. -/
theorem Module.finrank_pos_iff [NoZeroSMulDivisors R M] :
0 < finrank R M β Nontrivial M := by
rw [β rank_pos_iff_nontrivial (R := R), β finrank_eq_rank]
norm_cast
/-- A nontrivial finite dimensional space has positive `finrank`. -/
theorem Module.finrank_pos [NoZeroSMulDivisors R M] [h : Nontrivial M] :
0 < finrank R M :=
finrank_pos_iff.mpr h
/-- See `Module.finrank_zero_iff`
for the stronger version with `NoZeroSMulDivisors R M`. -/
theorem Module.finrank_eq_zero_iff :
finrank R M = 0 β β x : M, β a : R, a β 0 β§ a β’ x = 0 := by
rw [β rank_eq_zero_iff (R := R), β finrank_eq_rank]
norm_cast
/-- A finite dimensional space has zero `finrank` iff it is a subsingleton.
This is the `finrank` version of `rank_zero_iff`. -/
theorem Module.finrank_zero_iff [NoZeroSMulDivisors R M] :
finrank R M = 0 β Subsingleton M := by
rw [β rank_zero_iff (R := R), β finrank_eq_rank]
norm_cast
/-- Similar to `rank_quotient_add_rank_le` but for `finrank` and a finite `M`. -/
lemma Module.finrank_quotient_add_finrank_le (N : Submodule R M) :
finrank R (M β§Έ N) + finrank R N β€ finrank R M := by
haveI := nontrivial_of_invariantBasisNumber R
have := rank_quotient_add_rank_le N
rw [β finrank_eq_rank R M, β finrank_eq_rank R, β N.finrank_eq_rank] at this
exact mod_cast this
end StrongRankCondition
theorem Module.finrank_eq_zero_of_rank_eq_zero (h : Module.rank R M = 0) :
finrank R M = 0 := by
delta finrank
rw [h, zero_toNat]
theorem Submodule.bot_eq_top_of_rank_eq_zero [NoZeroSMulDivisors R M] (h : Module.rank R M = 0) :
(β₯ : Submodule R M) = β€ := by
nontriviality R
rw [rank_zero_iff] at h
subsingleton
/-- See `rank_subsingleton` for the reason that `Nontrivial R` is needed. -/
@[simp]
theorem Submodule.rank_eq_zero [Nontrivial R] [NoZeroSMulDivisors R M] {S : Submodule R M} :
Module.rank R S = 0 β S = β₯ :=
β¨fun h =>
(Submodule.eq_bot_iff _).2 fun x hx =>
congr_arg Subtype.val <|
((Submodule.eq_bot_iff _).1 <| Eq.symm <| Submodule.bot_eq_top_of_rank_eq_zero h) β¨x, hxβ©
Submodule.mem_top,
fun h => by rw [h, rank_bot]β©
@[simp]
theorem Submodule.finrank_eq_zero [StrongRankCondition R] [NoZeroSMulDivisors R M]
{S : Submodule R M} [Module.Finite R S] :
finrank R S = 0 β S = β₯ := by
rw [β Submodule.rank_eq_zero, β finrank_eq_rank, β @Nat.cast_zero Cardinal, Nat.cast_inj]
| @[simp]
lemma Submodule.one_le_finrank_iff [StrongRankCondition R] [NoZeroSMulDivisors R M]
{S : Submodule R M} [Module.Finite R S] :
1 β€ finrank R S β S β β₯ := by
| Mathlib/LinearAlgebra/Dimension/Finite.lean | 479 | 482 |
/-
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.Algebra.Module.Card
import Mathlib.Analysis.SpecificLimits.Normed
import Mathlib.SetTheory.Cardinal.Continuum
import Mathlib.SetTheory.Cardinal.CountableCover
import Mathlib.LinearAlgebra.Basis.VectorSpace
import Mathlib.Topology.MetricSpace.Perfect
/-!
# Cardinality of open subsets of vector spaces
Any nonempty open subset of a topological vector space over a nontrivially normed field has the same
cardinality as the whole space. This is proved in `cardinal_eq_of_isOpen`.
We deduce that a countable set in a nontrivial vector space over a complete nontrivially normed
field has dense complement, in `Set.Countable.dense_compl`. This follows from the previous
argument and the fact that a complete nontrivially normed field has cardinality at least
continuum, proved in `continuum_le_cardinal_of_nontriviallyNormedField`.
-/
universe u v
open Filter Pointwise Set Function Cardinal
open scoped Cardinal Topology
/-- A complete nontrivially normed field has cardinality at least continuum. -/
theorem continuum_le_cardinal_of_nontriviallyNormedField
(π : Type*) [NontriviallyNormedField π] [CompleteSpace π] : π β€ #π := by
suffices β f : (β β Bool) β π, range f β univ β§ Continuous f β§ Injective f by
rcases this with β¨f, -, -, f_injβ©
simpa using lift_mk_le_lift_mk_of_injective f_inj
apply Perfect.exists_nat_bool_injection _ univ_nonempty
refine β¨isClosed_univ, preperfect_iff_nhds.2 (fun x _ U hU β¦ ?_)β©
rcases NormedField.exists_norm_lt_one π with β¨c, c_pos, hcβ©
have A : Tendsto (fun n β¦ x + c^n) atTop (π (x + 0)) :=
tendsto_const_nhds.add (tendsto_pow_atTop_nhds_zero_of_norm_lt_one hc)
rw [add_zero] at A
have B : βαΆ n in atTop, x + c^n β U := tendsto_def.1 A U hU
rcases B.exists with β¨n, hnβ©
refine β¨x + c^n, by simpa using hn, ?_β©
simp only [add_ne_left]
apply pow_ne_zero
simpa using c_pos
/-- A nontrivial module over a complete nontrivially normed field has cardinality at least
continuum. -/
theorem continuum_le_cardinal_of_module
(π : Type u) (E : Type v) [NontriviallyNormedField π] [CompleteSpace π]
[AddCommGroup E] [Module π E] [Nontrivial E] : π β€ #E := by
have A : lift.{v} (π : Cardinal.{u}) β€ lift.{v} (#π) := by
simpa using continuum_le_cardinal_of_nontriviallyNormedField π
simpa using A.trans (Cardinal.mk_le_of_module π E)
/-- In a topological vector space over a nontrivially normed field, any neighborhood of zero has
the same cardinality as the whole space.
See also `cardinal_eq_of_mem_nhds`. -/
lemma cardinal_eq_of_mem_nhds_zero
{E : Type*} (π : Type*) [NontriviallyNormedField π] [Zero E] [MulActionWithZero π E]
[TopologicalSpace E] [ContinuousSMul π E] {s : Set E} (hs : s β π (0 : E)) : #s = #E := by
/- As `s` is a neighborhood of `0`, the space is covered by the rescaled sets `c^n β’ s`,
where `c` is any element of `π` with norm `> 1`. All these sets are in bijection and have
therefore the same cardinality. The conclusion follows. -/
obtain β¨c, hcβ© : β x : π , 1 < βxβ := NormedField.exists_lt_norm π 1
have cn_ne : β n, c^n β 0 := by
intro n
apply pow_ne_zero
rintro rfl
simp only [norm_zero] at hc
exact lt_irrefl _ (hc.trans zero_lt_one)
have A : β (x : E), βαΆ n in (atTop : Filter β), x β c^n β’ s := by
intro x
have : Tendsto (fun n β¦ (c^n) β»ΒΉ β’ x) atTop (π ((0 : π) β’ x)) := by
have : Tendsto (fun n β¦ (c^n)β»ΒΉ) atTop (π 0) := by
simp_rw [β inv_pow]
apply tendsto_pow_atTop_nhds_zero_of_norm_lt_one
rw [norm_inv]
exact inv_lt_one_of_one_ltβ hc
exact Tendsto.smul_const this x
rw [zero_smul] at this
filter_upwards [this hs] with n (hn : (c ^ n)β»ΒΉ β’ x β s)
exact (mem_smul_set_iff_inv_smul_memβ (cn_ne n) _ _).2 hn
have B : β n, #(c^n β’ s :) = #s := by
intro n
have : (c^n β’ s :) β s :=
{ toFun := fun x β¦ β¨(c^n)β»ΒΉ β’ x.1, (mem_smul_set_iff_inv_smul_memβ (cn_ne n) _ _).1 x.2β©
invFun := fun x β¦ β¨(c^n) β’ x.1, smul_mem_smul_set x.2β©
left_inv := fun x β¦ by simp [smul_smul, mul_inv_cancelβ (cn_ne n)]
right_inv := fun x β¦ by simp [smul_smul, inv_mul_cancelβ (cn_ne n)] }
exact Cardinal.mk_congr this
apply (Cardinal.mk_of_countable_eventually_mem A B).symm
/-- In a topological vector space over a nontrivially normed field, any neighborhood of a point has
the same cardinality as the whole space. -/
theorem cardinal_eq_of_mem_nhds
{E : Type*} (π : Type*) [NontriviallyNormedField π] [AddGroup E] [MulActionWithZero π E]
[TopologicalSpace E] [ContinuousAdd E] [ContinuousSMul π E]
{s : Set E} {x : E} (hs : s β π x) : #s = #E := by
let g := Homeomorph.addLeft x
let t := g β»ΒΉ' s
have : t β π 0 := g.continuous.continuousAt.preimage_mem_nhds (by simpa [g] using hs)
have A : #t = #E := cardinal_eq_of_mem_nhds_zero π this
have B : #t = #s := Cardinal.mk_subtype_of_equiv s g.toEquiv
rwa [B] at A
/-- In a topological vector space over a nontrivially normed field, any nonempty open set has
the same cardinality as the whole space. -/
theorem cardinal_eq_of_isOpen
{E : Type*} (π : Type*) [NontriviallyNormedField π] [AddGroup E] [MulActionWithZero π E]
[TopologicalSpace E] [ContinuousAdd E] [ContinuousSMul π E] {s : Set E}
(hs : IsOpen s) (h's : s.Nonempty) : #s = #E := by
rcases h's with β¨x, hxβ©
exact cardinal_eq_of_mem_nhds π (hs.mem_nhds hx)
/-- In a nontrivial topological vector space over a complete nontrivially normed field, any nonempty
open set has cardinality at least continuum. -/
theorem continuum_le_cardinal_of_isOpen
{E : Type*} (π : Type*) [NontriviallyNormedField π] [CompleteSpace π] [AddCommGroup E]
[Module π E] [Nontrivial E] [TopologicalSpace E] [ContinuousAdd E] [ContinuousSMul π E]
{s : Set E} (hs : IsOpen s) (h's : s.Nonempty) : π β€ #s := by
simpa [cardinal_eq_of_isOpen π hs h's] using continuum_le_cardinal_of_module π E
/-- In a nontrivial topological vector space over a complete nontrivially normed field, any
| countable set has dense complement. -/
theorem Set.Countable.dense_compl
{E : Type u} (π : Type*) [NontriviallyNormedField π] [CompleteSpace π] [AddCommGroup E]
[Module π E] [Nontrivial E] [TopologicalSpace E] [ContinuousAdd E] [ContinuousSMul π E]
{s : Set E} (hs : s.Countable) : Dense sαΆ := by
rw [β interior_eq_empty_iff_dense_compl]
by_contra H
apply lt_irrefl (β΅β : Cardinal.{u})
calc
(β΅β : Cardinal.{u}) < π := aleph0_lt_continuum
_ β€ #(interior s) :=
continuum_le_cardinal_of_isOpen π isOpen_interior (nmem_singleton_empty.1 H)
_ β€ #s := mk_le_mk_of_subset interior_subset
| Mathlib/Topology/Algebra/Module/Cardinality.lean | 127 | 139 |
/-
Copyright (c) 2017 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
-/
import Mathlib.Data.WSeq.Basic
import Mathlib.Data.WSeq.Defs
import Mathlib.Data.WSeq.Productive
import Mathlib.Data.WSeq.Relation
deprecated_module (since := "2025-04-13")
| Mathlib/Data/Seq/WSeq.lean | 1,091 | 1,094 | |
/-
Copyright (c) 2019 Kim Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kim Morrison
-/
import Mathlib.Algebra.Category.MonCat.Basic
import Mathlib.CategoryTheory.Limits.HasLimits
import Mathlib.CategoryTheory.ConcreteCategory.Elementwise
/-!
# The category of monoids has all colimits.
We do this construction knowing nothing about monoids.
In particular, I want to claim that this file could be produced by a python script
that just looks at what Lean 3's `#print monoid` printed a long time ago (it no longer looks like
this due to the addition of `npow` fields):
```
structure monoid : Type u β Type u
fields:
monoid.mul : Ξ {M : Type u} [self : monoid M], M β M β M
monoid.mul_assoc : β {M : Type u} [self : monoid M] (a b c : M), a * b * c = a * (b * c)
monoid.one : Ξ {M : Type u} [self : monoid M], M
monoid.one_mul : β {M : Type u} [self : monoid M] (a : M), 1 * a = a
monoid.mul_one : β {M : Type u} [self : monoid M] (a : M), a * 1 = a
```
and if we'd fed it the output of Lean 3's `#print comm_ring`, this file would instead build
colimits of commutative rings.
A slightly bolder claim is that we could do this with tactics, as well.
Note: `Monoid` and `CommRing` are no longer flat structures in Mathlib4, and so `#print Monoid`
gives the less clear
```
inductive Monoid.{u} : Type u β Type u
number of parameters: 1
constructors:
Monoid.mk : {M : Type u} β
[toSemigroup : Semigroup M] β
[toOne : One M] β
(β (a : M), 1 * a = a) β
(β (a : M), a * 1 = a) β
(npow : β β M β M) β
autoParam (β (x : M), npow 0 x = 1) _autoβ β
autoParam (β (n : β) (x : M), npow (n + 1) x = x * npow n x) _autoβΒΉ β Monoid M
```
-/
assert_not_exists MonoidWithZero
universe v u
open CategoryTheory
open CategoryTheory.Limits
namespace MonCat.Colimits
/-!
We build the colimit of a diagram in `MonCat` by constructing the
free monoid on the disjoint union of all the monoids in the diagram,
then taking the quotient by the monoid laws within each monoid,
and the identifications given by the morphisms in the diagram.
-/
variable {J : Type v} [Category.{u} J] (F : J β₯€ MonCat.{v})
/-- An inductive type representing all monoid expressions (without relations)
on a collection of types indexed by the objects of `J`.
-/
inductive Prequotient
-- There's always `of`
| of : β (j : J) (_ : F.obj j), Prequotient
-- Then one generator for each operation
| one : Prequotient
| mul : Prequotient β Prequotient β Prequotient
instance : Inhabited (Prequotient F) :=
β¨Prequotient.oneβ©
open Prequotient
/-- The relation on `Prequotient` saying when two expressions are equal
because of the monoid laws, or
because one element is mapped to another by a morphism in the diagram.
-/
inductive Relation : Prequotient F β Prequotient F β Prop-- Make it an equivalence relation:
| refl : β x, Relation x x
| symm : β (x y) (_ : Relation x y), Relation y x
| trans : β (x y z) (_ : Relation x y) (_ : Relation y z),
Relation x z-- There's always a `map` relation
| map :
β (j j' : J) (f : j βΆ j') (x : F.obj j),
Relation (Prequotient.of j' ((F.map f) x))
(Prequotient.of j x)-- Then one relation per operation, describing the interaction with `of`
| mul : β (j) (x y : F.obj j), Relation (Prequotient.of j (x * y))
(mul (Prequotient.of j x) (Prequotient.of j y))
| one : β j, Relation (Prequotient.of j 1) one-- Then one relation per argument of each operation
| mul_1 : β (x x' y) (_ : Relation x x'), Relation (mul x y) (mul x' y)
| mul_2 : β (x y y') (_ : Relation y y'), Relation (mul x y) (mul x y')
-- And one relation per axiom
| mul_assoc : β x y z, Relation (mul (mul x y) z) (mul x (mul y z))
| one_mul : β x, Relation (mul one x) x
| mul_one : β x, Relation (mul x one) x
/-- The setoid corresponding to monoid expressions modulo monoid relations and identifications.
-/
def colimitSetoid : Setoid (Prequotient F) where
r := Relation F
iseqv := β¨Relation.refl, Relation.symm _ _, Relation.trans _ _ _β©
attribute [instance] colimitSetoid
/-- The underlying type of the colimit of a diagram in `MonCat`.
-/
def ColimitType : Type v :=
Quotient (colimitSetoid F)
instance : Inhabited (ColimitType F) := by
dsimp [ColimitType]
infer_instance
instance monoidColimitType : Monoid (ColimitType F) where
one := Quotient.mk _ one
mul := Quotient.mapβ mul fun _ x' rx y _ ry =>
Setoid.trans (Relation.mul_1 _ _ y rx) (Relation.mul_2 x' _ _ ry)
one_mul := Quotient.ind fun _ => Quotient.sound <| Relation.one_mul _
mul_one := Quotient.ind fun _ => Quotient.sound <| Relation.mul_one _
mul_assoc := Quotient.ind fun _ => Quotient.indβ fun _ _ =>
Quotient.sound <| Relation.mul_assoc _ _ _
@[simp]
theorem quot_one : Quot.mk Setoid.r one = (1 : ColimitType F) :=
rfl
@[simp]
theorem quot_mul (x y : Prequotient F) : Quot.mk Setoid.r (mul x y) =
@HMul.hMul (ColimitType F) (ColimitType F) (ColimitType F) _
(Quot.mk Setoid.r x) (Quot.mk Setoid.r y) :=
rfl
/-- The bundled monoid giving the colimit of a diagram. -/
def colimit : MonCat :=
of (ColimitType F)
/-- The function from a given monoid in the diagram to the colimit monoid. -/
def coconeFun (j : J) (x : F.obj j) : ColimitType F :=
Quot.mk _ (Prequotient.of j x)
/-- The monoid homomorphism from a given monoid in the diagram to the colimit monoid. -/
def coconeMorphism (j : J) : F.obj j βΆ colimit F :=
ofHom
{ toFun := coconeFun F j
map_one' := Quot.sound (Relation.one _)
map_mul' _ _ := Quot.sound (Relation.mul _ _ _) }
@[simp]
theorem cocone_naturality {j j' : J} (f : j βΆ j') :
F.map f β« coconeMorphism F j' = coconeMorphism F j := by
ext
apply Quot.sound
apply Relation.map
@[simp]
theorem cocone_naturality_components (j j' : J) (f : j βΆ j') (x : F.obj j) :
(coconeMorphism F j') (F.map f x) = (coconeMorphism F j) x := by
rw [β cocone_naturality F f]
rfl
/-- The cocone over the proposed colimit monoid. -/
def colimitCocone : Cocone F where
pt := colimit F
ΞΉ := { app := coconeMorphism F }
/-- The function from the free monoid on the diagram to the cone point of any other cocone. -/
@[simp]
def descFunLift (s : Cocone F) : Prequotient F β s.pt
| Prequotient.of j x => (s.ΞΉ.app j) x
| one => 1
| mul x y => descFunLift _ x * descFunLift _ y
/-- The function from the colimit monoid to the cone point of any other cocone. -/
def descFun (s : Cocone F) : ColimitType F β s.pt := by
fapply Quot.lift
Β· exact descFunLift F s
Β· intro x y r
| induction r with
| refl x => rfl
| symm x y _ h => exact h.symm
| trans x y z _ _ hβ hβ => exact hβ.trans hβ
| Mathlib/Algebra/Category/MonCat/Colimits.lean | 188 | 191 |
/-
Copyright (c) 2019 Zhouhang Zhou. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Zhouhang Zhou, SΓ©bastien GouΓ«zel, FrΓ©dΓ©ric Dupuis
-/
import Mathlib.Algebra.BigOperators.Field
import Mathlib.Analysis.Complex.Basic
import Mathlib.Analysis.InnerProductSpace.Defs
import Mathlib.GroupTheory.MonoidLocalization.Basic
/-!
# Properties of inner product spaces
This file proves many basic properties of inner product spaces (real or complex).
## Main results
- `inner_mul_inner_self_le`: the Cauchy-Schwartz inequality (one of many variants).
- `norm_inner_eq_norm_iff`: the equality criteion in the Cauchy-Schwartz inequality (also in many
variants).
- `inner_eq_sum_norm_sq_div_four`: the polarization identity.
## Tags
inner product space, Hilbert space, norm
-/
noncomputable section
open RCLike Real Filter Topology ComplexConjugate Finsupp
open LinearMap (BilinForm)
variable {π E F : Type*} [RCLike π]
section BasicProperties_Seminormed
open scoped InnerProductSpace
variable [SeminormedAddCommGroup E] [InnerProductSpace π E]
variable [SeminormedAddCommGroup F] [InnerProductSpace β F]
local notation "βͺ" x ", " y "β«" => @inner π _ _ x y
local postfix:90 "β " => starRingEnd _
export InnerProductSpace (norm_sq_eq_re_inner)
@[simp]
theorem inner_conj_symm (x y : E) : βͺy, xβ«β = βͺx, yβ« :=
InnerProductSpace.conj_inner_symm _ _
theorem real_inner_comm (x y : F) : βͺy, xβ«_β = βͺx, yβ«_β :=
@inner_conj_symm β _ _ _ _ x y
theorem inner_eq_zero_symm {x y : E} : βͺx, yβ« = 0 β βͺy, xβ« = 0 := by
rw [β inner_conj_symm]
exact star_eq_zero
@[simp]
theorem inner_self_im (x : E) : im βͺx, xβ« = 0 := by rw [β @ofReal_inj π, im_eq_conj_sub]; simp
theorem inner_add_left (x y z : E) : βͺx + y, zβ« = βͺx, zβ« + βͺy, zβ« :=
InnerProductSpace.add_left _ _ _
theorem inner_add_right (x y z : E) : βͺx, y + zβ« = βͺx, yβ« + βͺx, zβ« := by
rw [β inner_conj_symm, inner_add_left, RingHom.map_add]
simp only [inner_conj_symm]
theorem inner_re_symm (x y : E) : re βͺx, yβ« = re βͺy, xβ« := by rw [β inner_conj_symm, conj_re]
theorem inner_im_symm (x y : E) : im βͺx, yβ« = -im βͺy, xβ« := by rw [β inner_conj_symm, conj_im]
section Algebra
variable {π : Type*} [CommSemiring π] [StarRing π] [Algebra π π] [Module π E]
[IsScalarTower π π E] [StarModule π π]
/-- See `inner_smul_left` for the common special when `π = π`. -/
lemma inner_smul_left_eq_star_smul (x y : E) (r : π) : βͺr β’ x, yβ« = rβ β’ βͺx, yβ« := by
rw [β algebraMap_smul π r, InnerProductSpace.smul_left, starRingEnd_apply, starRingEnd_apply,
β algebraMap_star_comm, β smul_eq_mul, algebraMap_smul]
/-- Special case of `inner_smul_left_eq_star_smul` when the acting ring has a trivial star
(eg `β`, `β€`, `ββ₯0`, `β`, `β`). -/
lemma inner_smul_left_eq_smul [TrivialStar π] (x y : E) (r : π) : βͺr β’ x, yβ« = r β’ βͺx, yβ« := by
rw [inner_smul_left_eq_star_smul, starRingEnd_apply, star_trivial]
/-- See `inner_smul_right` for the common special when `π = π`. -/
lemma inner_smul_right_eq_smul (x y : E) (r : π) : βͺx, r β’ yβ« = r β’ βͺx, yβ« := by
rw [β inner_conj_symm, inner_smul_left_eq_star_smul, starRingEnd_apply, starRingEnd_apply,
star_smul, star_star, β starRingEnd_apply, inner_conj_symm]
end Algebra
/-- See `inner_smul_left_eq_star_smul` for the case of a general algebra action. -/
theorem inner_smul_left (x y : E) (r : π) : βͺr β’ x, yβ« = rβ * βͺx, yβ« :=
inner_smul_left_eq_star_smul ..
theorem real_inner_smul_left (x y : F) (r : β) : βͺr β’ x, yβ«_β = r * βͺx, yβ«_β :=
inner_smul_left _ _ _
theorem inner_smul_real_left (x y : E) (r : β) : βͺ(r : π) β’ x, yβ« = r β’ βͺx, yβ« := by
rw [inner_smul_left, conj_ofReal, Algebra.smul_def]
/-- See `inner_smul_right_eq_smul` for the case of a general algebra action. -/
theorem inner_smul_right (x y : E) (r : π) : βͺx, r β’ yβ« = r * βͺx, yβ« :=
inner_smul_right_eq_smul ..
theorem real_inner_smul_right (x y : F) (r : β) : βͺx, r β’ yβ«_β = r * βͺx, yβ«_β :=
inner_smul_right _ _ _
theorem inner_smul_real_right (x y : E) (r : β) : βͺx, (r : π) β’ yβ« = r β’ βͺx, yβ« := by
rw [inner_smul_right, Algebra.smul_def]
/-- The inner product as a sesquilinear form.
Note that in the case `π = β` this is a bilinear form. -/
@[simps!]
def sesqFormOfInner : E ββ[π] E βββ[π] π :=
LinearMap.mkβ'ββ (RingHom.id π) (starRingEnd _) (fun x y => βͺy, xβ«)
(fun _x _y _z => inner_add_right _ _ _) (fun _r _x _y => inner_smul_right _ _ _)
(fun _x _y _z => inner_add_left _ _ _) fun _r _x _y => inner_smul_left _ _ _
/-- The real inner product as a bilinear form.
Note that unlike `sesqFormOfInner`, this does not reverse the order of the arguments. -/
@[simps!]
def bilinFormOfRealInner : BilinForm β F := sesqFormOfInner.flip
/-- An inner product with a sum on the left. -/
theorem sum_inner {ΞΉ : Type*} (s : Finset ΞΉ) (f : ΞΉ β E) (x : E) :
βͺβ i β s, f i, xβ« = β i β s, βͺf i, xβ« :=
map_sum (sesqFormOfInner (π := π) (E := E) x) _ _
/-- An inner product with a sum on the right. -/
theorem inner_sum {ΞΉ : Type*} (s : Finset ΞΉ) (f : ΞΉ β E) (x : E) :
βͺx, β i β s, f iβ« = β i β s, βͺx, f iβ« :=
map_sum (LinearMap.flip sesqFormOfInner x) _ _
/-- An inner product with a sum on the left, `Finsupp` version. -/
protected theorem Finsupp.sum_inner {ΞΉ : Type*} (l : ΞΉ ββ π) (v : ΞΉ β E) (x : E) :
βͺl.sum fun (i : ΞΉ) (a : π) => a β’ v i, xβ« = l.sum fun (i : ΞΉ) (a : π) => conj a β’ βͺv i, xβ« := by
convert sum_inner (π := π) l.support (fun a => l a β’ v a) x
simp only [inner_smul_left, Finsupp.sum, smul_eq_mul]
/-- An inner product with a sum on the right, `Finsupp` version. -/
protected theorem Finsupp.inner_sum {ΞΉ : Type*} (l : ΞΉ ββ π) (v : ΞΉ β E) (x : E) :
βͺx, l.sum fun (i : ΞΉ) (a : π) => a β’ v iβ« = l.sum fun (i : ΞΉ) (a : π) => a β’ βͺx, v iβ« := by
convert inner_sum (π := π) l.support (fun a => l a β’ v a) x
simp only [inner_smul_right, Finsupp.sum, smul_eq_mul]
protected theorem DFinsupp.sum_inner {ΞΉ : Type*} [DecidableEq ΞΉ] {Ξ± : ΞΉ β Type*}
[β i, AddZeroClass (Ξ± i)] [β (i) (x : Ξ± i), Decidable (x β 0)] (f : β i, Ξ± i β E)
(l : Ξ β i, Ξ± i) (x : E) : βͺl.sum f, xβ« = l.sum fun i a => βͺf i a, xβ« := by
simp +contextual only [DFinsupp.sum, sum_inner, smul_eq_mul]
protected theorem DFinsupp.inner_sum {ΞΉ : Type*} [DecidableEq ΞΉ] {Ξ± : ΞΉ β Type*}
[β i, AddZeroClass (Ξ± i)] [β (i) (x : Ξ± i), Decidable (x β 0)] (f : β i, Ξ± i β E)
(l : Ξ β i, Ξ± i) (x : E) : βͺx, l.sum fβ« = l.sum fun i a => βͺx, f i aβ« := by
simp +contextual only [DFinsupp.sum, inner_sum, smul_eq_mul]
@[simp]
theorem inner_zero_left (x : E) : βͺ0, xβ« = 0 := by
rw [β zero_smul π (0 : E), inner_smul_left, RingHom.map_zero, zero_mul]
theorem inner_re_zero_left (x : E) : re βͺ0, xβ« = 0 := by
simp only [inner_zero_left, AddMonoidHom.map_zero]
@[simp]
theorem inner_zero_right (x : E) : βͺx, 0β« = 0 := by
rw [β inner_conj_symm, inner_zero_left, RingHom.map_zero]
theorem inner_re_zero_right (x : E) : re βͺx, 0β« = 0 := by
simp only [inner_zero_right, AddMonoidHom.map_zero]
theorem inner_self_nonneg {x : E} : 0 β€ re βͺx, xβ« :=
PreInnerProductSpace.toCore.re_inner_nonneg x
theorem real_inner_self_nonneg {x : F} : 0 β€ βͺx, xβ«_β :=
@inner_self_nonneg β F _ _ _ x
@[simp]
theorem inner_self_ofReal_re (x : E) : (re βͺx, xβ« : π) = βͺx, xβ« :=
((RCLike.is_real_TFAE (βͺx, xβ« : π)).out 2 3).2 (inner_self_im (π := π) x)
theorem inner_self_eq_norm_sq_to_K (x : E) : βͺx, xβ« = (βxβ : π) ^ 2 := by
rw [β inner_self_ofReal_re, β norm_sq_eq_re_inner, ofReal_pow]
theorem inner_self_re_eq_norm (x : E) : re βͺx, xβ« = ββͺx, xβ«β := by
conv_rhs => rw [β inner_self_ofReal_re]
symm
exact norm_of_nonneg inner_self_nonneg
theorem inner_self_ofReal_norm (x : E) : (ββͺx, xβ«β : π) = βͺx, xβ« := by
rw [β inner_self_re_eq_norm]
exact inner_self_ofReal_re _
theorem real_inner_self_abs (x : F) : |βͺx, xβ«_β| = βͺx, xβ«_β :=
@inner_self_ofReal_norm β F _ _ _ x
theorem norm_inner_symm (x y : E) : ββͺx, yβ«β = ββͺy, xβ«β := by rw [β inner_conj_symm, norm_conj]
@[simp]
theorem inner_neg_left (x y : E) : βͺ-x, yβ« = -βͺx, yβ« := by
rw [β neg_one_smul π x, inner_smul_left]
simp
@[simp]
theorem inner_neg_right (x y : E) : βͺx, -yβ« = -βͺx, yβ« := by
rw [β inner_conj_symm, inner_neg_left]; simp only [RingHom.map_neg, inner_conj_symm]
theorem inner_neg_neg (x y : E) : βͺ-x, -yβ« = βͺx, yβ« := by simp
theorem inner_self_conj (x : E) : βͺx, xβ«β = βͺx, xβ« := inner_conj_symm _ _
theorem inner_sub_left (x y z : E) : βͺx - y, zβ« = βͺx, zβ« - βͺy, zβ« := by
simp [sub_eq_add_neg, inner_add_left]
theorem inner_sub_right (x y z : E) : βͺx, y - zβ« = βͺx, yβ« - βͺx, zβ« := by
simp [sub_eq_add_neg, inner_add_right]
theorem inner_mul_symm_re_eq_norm (x y : E) : re (βͺx, yβ« * βͺy, xβ«) = ββͺx, yβ« * βͺy, xβ«β := by
rw [β inner_conj_symm, mul_comm]
exact re_eq_norm_of_mul_conj (inner y x)
/-- Expand `βͺx + y, x + yβ«` -/
theorem inner_add_add_self (x y : E) : βͺx + y, x + yβ« = βͺx, xβ« + βͺx, yβ« + βͺy, xβ« + βͺy, yβ« := by
simp only [inner_add_left, inner_add_right]; ring
/-- Expand `βͺx + y, x + yβ«_β` -/
theorem real_inner_add_add_self (x y : F) :
βͺx + y, x + yβ«_β = βͺx, xβ«_β + 2 * βͺx, yβ«_β + βͺy, yβ«_β := by
have : βͺy, xβ«_β = βͺx, yβ«_β := by rw [β inner_conj_symm]; rfl
simp only [inner_add_add_self, this, add_left_inj]
ring
-- Expand `βͺx - y, x - yβ«`
theorem inner_sub_sub_self (x y : E) : βͺx - y, x - yβ« = βͺx, xβ« - βͺx, yβ« - βͺy, xβ« + βͺy, yβ« := by
simp only [inner_sub_left, inner_sub_right]; ring
/-- Expand `βͺx - y, x - yβ«_β` -/
theorem real_inner_sub_sub_self (x y : F) :
βͺx - y, x - yβ«_β = βͺx, xβ«_β - 2 * βͺx, yβ«_β + βͺy, yβ«_β := by
have : βͺy, xβ«_β = βͺx, yβ«_β := by rw [β inner_conj_symm]; rfl
simp only [inner_sub_sub_self, this, add_left_inj]
ring
/-- Parallelogram law -/
theorem parallelogram_law {x y : E} : βͺx + y, x + yβ« + βͺx - y, x - yβ« = 2 * (βͺx, xβ« + βͺy, yβ«) := by
simp only [inner_add_add_self, inner_sub_sub_self]
ring
/-- **CauchyβSchwarz inequality**. -/
theorem inner_mul_inner_self_le (x y : E) : ββͺx, yβ«β * ββͺy, xβ«β β€ re βͺx, xβ« * re βͺy, yβ« :=
letI cd : PreInnerProductSpace.Core π E := PreInnerProductSpace.toCore
InnerProductSpace.Core.inner_mul_inner_self_le x y
/-- CauchyβSchwarz inequality for real inner products. -/
theorem real_inner_mul_inner_self_le (x y : F) : βͺx, yβ«_β * βͺx, yβ«_β β€ βͺx, xβ«_β * βͺy, yβ«_β :=
calc
βͺx, yβ«_β * βͺx, yβ«_β β€ ββͺx, yβ«_ββ * ββͺy, xβ«_ββ := by
rw [real_inner_comm y, β norm_mul]
exact le_abs_self _
_ β€ βͺx, xβ«_β * βͺy, yβ«_β := @inner_mul_inner_self_le β _ _ _ _ x y
end BasicProperties_Seminormed
section BasicProperties
variable [NormedAddCommGroup E] [InnerProductSpace π E]
variable [NormedAddCommGroup F] [InnerProductSpace β F]
local notation "βͺ" x ", " y "β«" => @inner π _ _ x y
export InnerProductSpace (norm_sq_eq_re_inner)
@[simp]
theorem inner_self_eq_zero {x : E} : βͺx, xβ« = 0 β x = 0 := by
rw [inner_self_eq_norm_sq_to_K, sq_eq_zero_iff, ofReal_eq_zero, norm_eq_zero]
theorem inner_self_ne_zero {x : E} : βͺx, xβ« β 0 β x β 0 :=
inner_self_eq_zero.not
variable (π)
theorem ext_inner_left {x y : E} (h : β v, βͺv, xβ« = βͺv, yβ«) : x = y := by
rw [β sub_eq_zero, β @inner_self_eq_zero π, inner_sub_right, sub_eq_zero, h (x - y)]
theorem ext_inner_right {x y : E} (h : β v, βͺx, vβ« = βͺy, vβ«) : x = y := by
rw [β sub_eq_zero, β @inner_self_eq_zero π, inner_sub_left, sub_eq_zero, h (x - y)]
variable {π}
@[simp]
theorem re_inner_self_nonpos {x : E} : re βͺx, xβ« β€ 0 β x = 0 := by
rw [β norm_sq_eq_re_inner, (sq_nonneg _).le_iff_eq, sq_eq_zero_iff, norm_eq_zero]
@[simp]
lemma re_inner_self_pos {x : E} : 0 < re βͺx, xβ« β x β 0 := by
simpa [-re_inner_self_nonpos] using re_inner_self_nonpos (π := π) (x := x).not
@[deprecated (since := "2025-04-22")] alias inner_self_nonpos := re_inner_self_nonpos
@[deprecated (since := "2025-04-22")] alias inner_self_pos := re_inner_self_pos
open scoped InnerProductSpace in
theorem real_inner_self_nonpos {x : F} : βͺx, xβ«_β β€ 0 β x = 0 := re_inner_self_nonpos (π := β)
open scoped InnerProductSpace in
theorem real_inner_self_pos {x : F} : 0 < βͺx, xβ«_β β x β 0 := re_inner_self_pos (π := β)
/-- A family of vectors is linearly independent if they are nonzero
and orthogonal. -/
theorem linearIndependent_of_ne_zero_of_inner_eq_zero {ΞΉ : Type*} {v : ΞΉ β E} (hz : β i, v i β 0)
(ho : Pairwise fun i j => βͺv i, v jβ« = 0) : LinearIndependent π v := by
rw [linearIndependent_iff']
intro s g hg i hi
have h' : g i * inner (v i) (v i) = inner (v i) (β j β s, g j β’ v j) := by
rw [inner_sum]
symm
convert Finset.sum_eq_single (M := π) i ?_ ?_
Β· rw [inner_smul_right]
Β· intro j _hj hji
rw [inner_smul_right, ho hji.symm, mul_zero]
Β· exact fun h => False.elim (h hi)
simpa [hg, hz] using h'
end BasicProperties
section Norm_Seminormed
open scoped InnerProductSpace
variable [SeminormedAddCommGroup E] [InnerProductSpace π E]
variable [SeminormedAddCommGroup F] [InnerProductSpace β F]
local notation "βͺ" x ", " y "β«" => @inner π _ _ x y
local notation "IK" => @RCLike.I π _
theorem norm_eq_sqrt_re_inner (x : E) : βxβ = β(re βͺx, xβ«) :=
calc
βxβ = β(βxβ ^ 2) := (sqrt_sq (norm_nonneg _)).symm
_ = β(re βͺx, xβ«) := congr_arg _ (norm_sq_eq_re_inner _)
@[deprecated (since := "2025-04-22")] alias norm_eq_sqrt_inner := norm_eq_sqrt_re_inner
theorem norm_eq_sqrt_real_inner (x : F) : βxβ = ββͺx, xβ«_β :=
@norm_eq_sqrt_re_inner β _ _ _ _ x
theorem inner_self_eq_norm_mul_norm (x : E) : re βͺx, xβ« = βxβ * βxβ := by
rw [@norm_eq_sqrt_re_inner π, β sqrt_mul inner_self_nonneg (re βͺx, xβ«),
sqrt_mul_self inner_self_nonneg]
theorem inner_self_eq_norm_sq (x : E) : re βͺx, xβ« = βxβ ^ 2 := by
rw [pow_two, inner_self_eq_norm_mul_norm]
theorem real_inner_self_eq_norm_mul_norm (x : F) : βͺx, xβ«_β = βxβ * βxβ := by
have h := @inner_self_eq_norm_mul_norm β F _ _ _ x
simpa using h
theorem real_inner_self_eq_norm_sq (x : F) : βͺx, xβ«_β = βxβ ^ 2 := by
rw [pow_two, real_inner_self_eq_norm_mul_norm]
/-- Expand the square -/
theorem norm_add_sq (x y : E) : βx + yβ ^ 2 = βxβ ^ 2 + 2 * re βͺx, yβ« + βyβ ^ 2 := by
repeat' rw [sq (M := β), β @inner_self_eq_norm_mul_norm π]
rw [inner_add_add_self, two_mul]
simp only [add_assoc, add_left_inj, add_right_inj, AddMonoidHom.map_add]
rw [β inner_conj_symm, conj_re]
alias norm_add_pow_two := norm_add_sq
/-- Expand the square -/
theorem norm_add_sq_real (x y : F) : βx + yβ ^ 2 = βxβ ^ 2 + 2 * βͺx, yβ«_β + βyβ ^ 2 := by
have h := @norm_add_sq β _ _ _ _ x y
simpa using h
alias norm_add_pow_two_real := norm_add_sq_real
/-- Expand the square -/
theorem norm_add_mul_self (x y : E) :
βx + yβ * βx + yβ = βxβ * βxβ + 2 * re βͺx, yβ« + βyβ * βyβ := by
repeat' rw [β sq (M := β)]
exact norm_add_sq _ _
/-- Expand the square -/
theorem norm_add_mul_self_real (x y : F) :
βx + yβ * βx + yβ = βxβ * βxβ + 2 * βͺx, yβ«_β + βyβ * βyβ := by
have h := @norm_add_mul_self β _ _ _ _ x y
simpa using h
/-- Expand the square -/
theorem norm_sub_sq (x y : E) : βx - yβ ^ 2 = βxβ ^ 2 - 2 * re βͺx, yβ« + βyβ ^ 2 := by
rw [sub_eq_add_neg, @norm_add_sq π _ _ _ _ x (-y), norm_neg, inner_neg_right, map_neg, mul_neg,
sub_eq_add_neg]
alias norm_sub_pow_two := norm_sub_sq
/-- Expand the square -/
theorem norm_sub_sq_real (x y : F) : βx - yβ ^ 2 = βxβ ^ 2 - 2 * βͺx, yβ«_β + βyβ ^ 2 :=
@norm_sub_sq β _ _ _ _ _ _
alias norm_sub_pow_two_real := norm_sub_sq_real
/-- Expand the square -/
theorem norm_sub_mul_self (x y : E) :
βx - yβ * βx - yβ = βxβ * βxβ - 2 * re βͺx, yβ« + βyβ * βyβ := by
repeat' rw [β sq (M := β)]
exact norm_sub_sq _ _
/-- Expand the square -/
theorem norm_sub_mul_self_real (x y : F) :
βx - yβ * βx - yβ = βxβ * βxβ - 2 * βͺx, yβ«_β + βyβ * βyβ := by
have h := @norm_sub_mul_self β _ _ _ _ x y
simpa using h
/-- CauchyβSchwarz inequality with norm -/
theorem norm_inner_le_norm (x y : E) : ββͺx, yβ«β β€ βxβ * βyβ := by
rw [norm_eq_sqrt_re_inner (π := π) x, norm_eq_sqrt_re_inner (π := π) y]
letI : PreInnerProductSpace.Core π E := PreInnerProductSpace.toCore
exact InnerProductSpace.Core.norm_inner_le_norm x y
theorem nnnorm_inner_le_nnnorm (x y : E) : ββͺx, yβ«ββ β€ βxββ * βyββ :=
norm_inner_le_norm x y
theorem re_inner_le_norm (x y : E) : re βͺx, yβ« β€ βxβ * βyβ :=
le_trans (re_le_norm (inner x y)) (norm_inner_le_norm x y)
/-- CauchyβSchwarz inequality with norm -/
theorem abs_real_inner_le_norm (x y : F) : |βͺx, yβ«_β| β€ βxβ * βyβ :=
(Real.norm_eq_abs _).ge.trans (norm_inner_le_norm x y)
/-- CauchyβSchwarz inequality with norm -/
theorem real_inner_le_norm (x y : F) : βͺx, yβ«_β β€ βxβ * βyβ :=
le_trans (le_abs_self _) (abs_real_inner_le_norm _ _)
lemma inner_eq_zero_of_left {x : E} (y : E) (h : βxβ = 0) : βͺx, yβ«_π = 0 := by
rw [β norm_eq_zero]
refine le_antisymm ?_ (by positivity)
exact norm_inner_le_norm _ _ |>.trans <| by simp [h]
lemma inner_eq_zero_of_right (x : E) {y : E} (h : βyβ = 0) : βͺx, yβ«_π = 0 := by
rw [inner_eq_zero_symm, inner_eq_zero_of_left _ h]
variable (π)
include π in
theorem parallelogram_law_with_norm (x y : E) :
βx + yβ * βx + yβ + βx - yβ * βx - yβ = 2 * (βxβ * βxβ + βyβ * βyβ) := by
simp only [β @inner_self_eq_norm_mul_norm π]
rw [β re.map_add, parallelogram_law, two_mul, two_mul]
simp only [re.map_add]
include π in
theorem parallelogram_law_with_nnnorm (x y : E) :
βx + yββ * βx + yββ + βx - yββ * βx - yββ = 2 * (βxββ * βxββ + βyββ * βyββ) :=
Subtype.ext <| parallelogram_law_with_norm π x y
variable {π}
/-- Polarization identity: The real part of the inner product, in terms of the norm. -/
theorem re_inner_eq_norm_add_mul_self_sub_norm_mul_self_sub_norm_mul_self_div_two (x y : E) :
re βͺx, yβ« = (βx + yβ * βx + yβ - βxβ * βxβ - βyβ * βyβ) / 2 := by
rw [@norm_add_mul_self π]
ring
/-- Polarization identity: The real part of the inner product, in terms of the norm. -/
theorem re_inner_eq_norm_mul_self_add_norm_mul_self_sub_norm_sub_mul_self_div_two (x y : E) :
re βͺx, yβ« = (βxβ * βxβ + βyβ * βyβ - βx - yβ * βx - yβ) / 2 := by
rw [@norm_sub_mul_self π]
ring
/-- Polarization identity: The real part of the inner product, in terms of the norm. -/
theorem re_inner_eq_norm_add_mul_self_sub_norm_sub_mul_self_div_four (x y : E) :
re βͺx, yβ« = (βx + yβ * βx + yβ - βx - yβ * βx - yβ) / 4 := by
rw [@norm_add_mul_self π, @norm_sub_mul_self π]
ring
/-- Polarization identity: The imaginary part of the inner product, in terms of the norm. -/
theorem im_inner_eq_norm_sub_i_smul_mul_self_sub_norm_add_i_smul_mul_self_div_four (x y : E) :
im βͺx, yβ« = (βx - IK β’ yβ * βx - IK β’ yβ - βx + IK β’ yβ * βx + IK β’ yβ) / 4 := by
simp only [@norm_add_mul_self π, @norm_sub_mul_self π, inner_smul_right, I_mul_re]
ring
/-- Polarization identity: The inner product, in terms of the norm. -/
theorem inner_eq_sum_norm_sq_div_four (x y : E) :
βͺx, yβ« = ((βx + yβ : π) ^ 2 - (βx - yβ : π) ^ 2 +
((βx - IK β’ yβ : π) ^ 2 - (βx + IK β’ yβ : π) ^ 2) * IK) / 4 := by
rw [β re_add_im βͺx, yβ«, re_inner_eq_norm_add_mul_self_sub_norm_sub_mul_self_div_four,
im_inner_eq_norm_sub_i_smul_mul_self_sub_norm_add_i_smul_mul_self_div_four]
push_cast
simp only [sq, β mul_div_right_comm, β add_div]
/-- Polarization identity: The real inner product, in terms of the norm. -/
theorem real_inner_eq_norm_add_mul_self_sub_norm_mul_self_sub_norm_mul_self_div_two (x y : F) :
βͺx, yβ«_β = (βx + yβ * βx + yβ - βxβ * βxβ - βyβ * βyβ) / 2 :=
re_to_real.symm.trans <|
re_inner_eq_norm_add_mul_self_sub_norm_mul_self_sub_norm_mul_self_div_two x y
/-- Polarization identity: The real inner product, in terms of the norm. -/
theorem real_inner_eq_norm_mul_self_add_norm_mul_self_sub_norm_sub_mul_self_div_two (x y : F) :
βͺx, yβ«_β = (βxβ * βxβ + βyβ * βyβ - βx - yβ * βx - yβ) / 2 :=
re_to_real.symm.trans <|
re_inner_eq_norm_mul_self_add_norm_mul_self_sub_norm_sub_mul_self_div_two x y
/-- Pythagorean theorem, if-and-only-if vector inner product form. -/
theorem norm_add_sq_eq_norm_sq_add_norm_sq_iff_real_inner_eq_zero (x y : F) :
βx + yβ * βx + yβ = βxβ * βxβ + βyβ * βyβ β βͺx, yβ«_β = 0 := by
rw [@norm_add_mul_self β, add_right_cancel_iff, add_eq_left, mul_eq_zero]
norm_num
/-- Pythagorean theorem, if-and-if vector inner product form using square roots. -/
theorem norm_add_eq_sqrt_iff_real_inner_eq_zero {x y : F} :
βx + yβ = β(βxβ * βxβ + βyβ * βyβ) β βͺx, yβ«_β = 0 := by
rw [β norm_add_sq_eq_norm_sq_add_norm_sq_iff_real_inner_eq_zero, eq_comm, sqrt_eq_iff_mul_self_eq,
eq_comm] <;> positivity
/-- Pythagorean theorem, vector inner product form. -/
theorem norm_add_sq_eq_norm_sq_add_norm_sq_of_inner_eq_zero (x y : E) (h : βͺx, yβ« = 0) :
βx + yβ * βx + yβ = βxβ * βxβ + βyβ * βyβ := by
rw [@norm_add_mul_self π, add_right_cancel_iff, add_eq_left, mul_eq_zero]
apply Or.inr
simp only [h, zero_re']
/-- Pythagorean theorem, vector inner product form. -/
theorem norm_add_sq_eq_norm_sq_add_norm_sq_real {x y : F} (h : βͺx, yβ«_β = 0) :
βx + yβ * βx + yβ = βxβ * βxβ + βyβ * βyβ :=
(norm_add_sq_eq_norm_sq_add_norm_sq_iff_real_inner_eq_zero x y).2 h
/-- Pythagorean theorem, subtracting vectors, if-and-only-if vector
inner product form. -/
theorem norm_sub_sq_eq_norm_sq_add_norm_sq_iff_real_inner_eq_zero (x y : F) :
βx - yβ * βx - yβ = βxβ * βxβ + βyβ * βyβ β βͺx, yβ«_β = 0 := by
rw [@norm_sub_mul_self β, add_right_cancel_iff, sub_eq_add_neg, add_eq_left, neg_eq_zero,
mul_eq_zero]
norm_num
/-- Pythagorean theorem, subtracting vectors, if-and-if vector inner product form using square
roots. -/
theorem norm_sub_eq_sqrt_iff_real_inner_eq_zero {x y : F} :
βx - yβ = β(βxβ * βxβ + βyβ * βyβ) β βͺx, yβ«_β = 0 := by
rw [β norm_sub_sq_eq_norm_sq_add_norm_sq_iff_real_inner_eq_zero, eq_comm, sqrt_eq_iff_mul_self_eq,
eq_comm] <;> positivity
/-- Pythagorean theorem, subtracting vectors, vector inner product
form. -/
theorem norm_sub_sq_eq_norm_sq_add_norm_sq_real {x y : F} (h : βͺx, yβ«_β = 0) :
βx - yβ * βx - yβ = βxβ * βxβ + βyβ * βyβ :=
(norm_sub_sq_eq_norm_sq_add_norm_sq_iff_real_inner_eq_zero x y).2 h
/-- The sum and difference of two vectors are orthogonal if and only
if they have the same norm. -/
theorem real_inner_add_sub_eq_zero_iff (x y : F) : βͺx + y, x - yβ«_β = 0 β βxβ = βyβ := by
conv_rhs => rw [β mul_self_inj_of_nonneg (norm_nonneg _) (norm_nonneg _)]
simp only [β @inner_self_eq_norm_mul_norm β, inner_add_left, inner_sub_right, real_inner_comm y x,
sub_eq_zero, re_to_real]
constructor
Β· intro h
rw [add_comm] at h
linarith
Β· intro h
linarith
/-- Given two orthogonal vectors, their sum and difference have equal norms. -/
theorem norm_sub_eq_norm_add {v w : E} (h : βͺv, wβ« = 0) : βw - vβ = βw + vβ := by
rw [β mul_self_inj_of_nonneg (norm_nonneg _) (norm_nonneg _)]
simp only [h, β @inner_self_eq_norm_mul_norm π, sub_neg_eq_add, sub_zero, map_sub, zero_re',
zero_sub, add_zero, map_add, inner_add_right, inner_sub_left, inner_sub_right, inner_re_symm,
zero_add]
/-- The real inner product of two vectors, divided by the product of their
norms, has absolute value at most 1. -/
theorem abs_real_inner_div_norm_mul_norm_le_one (x y : F) : |βͺx, yβ«_β / (βxβ * βyβ)| β€ 1 := by
rw [abs_div, abs_mul, abs_norm, abs_norm]
exact div_le_one_of_leβ (abs_real_inner_le_norm x y) (by positivity)
/-- The inner product of a vector with a multiple of itself. -/
theorem real_inner_smul_self_left (x : F) (r : β) : βͺr β’ x, xβ«_β = r * (βxβ * βxβ) := by
rw [real_inner_smul_left, β real_inner_self_eq_norm_mul_norm]
/-- The inner product of a vector with a multiple of itself. -/
theorem real_inner_smul_self_right (x : F) (r : β) : βͺx, r β’ xβ«_β = r * (βxβ * βxβ) := by
rw [inner_smul_right, β real_inner_self_eq_norm_mul_norm]
/-- The inner product of two weighted sums, where the weights in each
sum add to 0, in terms of the norms of pairwise differences. -/
theorem inner_sum_smul_sum_smul_of_sum_eq_zero {ΞΉβ : Type*} {sβ : Finset ΞΉβ} {wβ : ΞΉβ β β}
(vβ : ΞΉβ β F) (hβ : β i β sβ, wβ i = 0) {ΞΉβ : Type*} {sβ : Finset ΞΉβ} {wβ : ΞΉβ β β}
(vβ : ΞΉβ β F) (hβ : β i β sβ, wβ i = 0) :
βͺβ iβ β sβ, wβ iβ β’ vβ iβ, β iβ β sβ, wβ iβ β’ vβ iββ«_β =
(-β iβ β sβ, β iβ β sβ, wβ iβ * wβ iβ * (βvβ iβ - vβ iββ * βvβ iβ - vβ iββ)) / 2 := by
simp_rw [sum_inner, inner_sum, real_inner_smul_left, real_inner_smul_right,
real_inner_eq_norm_mul_self_add_norm_mul_self_sub_norm_sub_mul_self_div_two, β div_sub_div_same,
β div_add_div_same, mul_sub_left_distrib, left_distrib, Finset.sum_sub_distrib,
Finset.sum_add_distrib, β Finset.mul_sum, β Finset.sum_mul, hβ, hβ, zero_mul,
mul_zero, Finset.sum_const_zero, zero_add, zero_sub, Finset.mul_sum, neg_div,
Finset.sum_div, mul_div_assoc, mul_assoc]
end Norm_Seminormed
section Norm
open scoped InnerProductSpace
variable [NormedAddCommGroup E] [InnerProductSpace π E]
variable [NormedAddCommGroup F] [InnerProductSpace β F]
variable {ΞΉ : Type*}
local notation "βͺ" x ", " y "β«" => @inner π _ _ x y
/-- Formula for the distance between the images of two nonzero points under an inversion with center
zero. See also `EuclideanGeometry.dist_inversion_inversion` for inversions around a general
point. -/
theorem dist_div_norm_sq_smul {x y : F} (hx : x β 0) (hy : y β 0) (R : β) :
dist ((R / βxβ) ^ 2 β’ x) ((R / βyβ) ^ 2 β’ y) = R ^ 2 / (βxβ * βyβ) * dist x y :=
calc
dist ((R / βxβ) ^ 2 β’ x) ((R / βyβ) ^ 2 β’ y) =
β(β(R / βxβ) ^ 2 β’ x - (R / βyβ) ^ 2 β’ yβ ^ 2) := by
rw [dist_eq_norm, sqrt_sq (norm_nonneg _)]
_ = β((R ^ 2 / (βxβ * βyβ)) ^ 2 * βx - yβ ^ 2) :=
congr_arg sqrt <| by
field_simp [sq, norm_sub_mul_self_real, norm_smul, real_inner_smul_left, inner_smul_right,
Real.norm_of_nonneg (mul_self_nonneg _)]
ring
_ = R ^ 2 / (βxβ * βyβ) * dist x y := by
rw [sqrt_mul, sqrt_sq, sqrt_sq, dist_eq_norm] <;> positivity
/-- The inner product of a nonzero vector with a nonzero multiple of
itself, divided by the product of their norms, has absolute value
1. -/
theorem norm_inner_div_norm_mul_norm_eq_one_of_ne_zero_of_ne_zero_mul {x : E} {r : π} (hx : x β 0)
(hr : r β 0) : ββͺx, r β’ xβ«β / (βxβ * βr β’ xβ) = 1 := by
have hx' : βxβ β 0 := by simp [hx]
have hr' : βrβ β 0 := by simp [hr]
rw [inner_smul_right, norm_mul, β inner_self_re_eq_norm, inner_self_eq_norm_mul_norm, norm_smul]
rw [β mul_assoc, β div_div, mul_div_cancel_rightβ _ hx', β div_div, mul_comm,
mul_div_cancel_rightβ _ hr', div_self hx']
/-- The inner product of a nonzero vector with a nonzero multiple of
itself, divided by the product of their norms, has absolute value
1. -/
theorem abs_real_inner_div_norm_mul_norm_eq_one_of_ne_zero_of_ne_zero_mul {x : F} {r : β}
(hx : x β 0) (hr : r β 0) : |βͺx, r β’ xβ«_β| / (βxβ * βr β’ xβ) = 1 :=
norm_inner_div_norm_mul_norm_eq_one_of_ne_zero_of_ne_zero_mul hx hr
/-- The inner product of a nonzero vector with a positive multiple of
itself, divided by the product of their norms, has value 1. -/
theorem real_inner_div_norm_mul_norm_eq_one_of_ne_zero_of_pos_mul {x : F} {r : β} (hx : x β 0)
(hr : 0 < r) : βͺx, r β’ xβ«_β / (βxβ * βr β’ xβ) = 1 := by
rw [real_inner_smul_self_right, norm_smul, Real.norm_eq_abs, β mul_assoc βxβ, mul_comm _ |r|,
mul_assoc, abs_of_nonneg hr.le, div_self]
exact mul_ne_zero hr.ne' (mul_self_ne_zero.2 (norm_ne_zero_iff.2 hx))
/-- The inner product of a nonzero vector with a negative multiple of
itself, divided by the product of their norms, has value -1. -/
theorem real_inner_div_norm_mul_norm_eq_neg_one_of_ne_zero_of_neg_mul {x : F} {r : β} (hx : x β 0)
(hr : r < 0) : βͺx, r β’ xβ«_β / (βxβ * βr β’ xβ) = -1 := by
rw [real_inner_smul_self_right, norm_smul, Real.norm_eq_abs, β mul_assoc βxβ, mul_comm _ |r|,
mul_assoc, abs_of_neg hr, neg_mul, div_neg_eq_neg_div, div_self]
exact mul_ne_zero hr.ne (mul_self_ne_zero.2 (norm_ne_zero_iff.2 hx))
theorem norm_inner_eq_norm_tfae (x y : E) :
List.TFAE [ββͺx, yβ«β = βxβ * βyβ,
x = 0 β¨ y = (βͺx, yβ« / βͺx, xβ«) β’ x,
x = 0 β¨ β r : π, y = r β’ x,
x = 0 β¨ y β π β x] := by
tfae_have 1 β 2 := by
refine fun h => or_iff_not_imp_left.2 fun hxβ => ?_
have : βxβ ^ 2 β 0 := pow_ne_zero _ (norm_ne_zero_iff.2 hxβ)
rw [β sq_eq_sqβ, mul_pow, β mul_right_inj' this, eq_comm, β sub_eq_zero, β mul_sub] at h <;>
try positivity
simp only [@norm_sq_eq_re_inner π] at h
letI : InnerProductSpace.Core π E := InnerProductSpace.toCore
erw [β InnerProductSpace.Core.cauchy_schwarz_aux (π := π) (F := E)] at h
rw [InnerProductSpace.Core.normSq_eq_zero, sub_eq_zero] at h
rw [div_eq_inv_mul, mul_smul, h, inv_smul_smulβ]
rwa [inner_self_ne_zero]
tfae_have 2 β 3 := fun h => h.imp_right fun h' => β¨_, h'β©
tfae_have 3 β 1 := by
rintro (rfl | β¨r, rflβ©) <;>
simp [inner_smul_right, norm_smul, inner_self_eq_norm_sq_to_K, inner_self_eq_norm_mul_norm,
sq, mul_left_comm]
tfae_have 3 β 4 := by simp only [Submodule.mem_span_singleton, eq_comm]
tfae_finish
/-- If the inner product of two vectors is equal to the product of their norms, then the two vectors
are multiples of each other. One form of the equality case for Cauchy-Schwarz.
Compare `inner_eq_norm_mul_iff`, which takes the stronger hypothesis `βͺx, yβ« = βxβ * βyβ`. -/
theorem norm_inner_eq_norm_iff {x y : E} (hxβ : x β 0) (hyβ : y β 0) :
ββͺx, yβ«β = βxβ * βyβ β β r : π, r β 0 β§ y = r β’ x :=
calc
ββͺx, yβ«β = βxβ * βyβ β x = 0 β¨ β r : π, y = r β’ x :=
(@norm_inner_eq_norm_tfae π _ _ _ _ x y).out 0 2
_ β β r : π, y = r β’ x := or_iff_right hxβ
_ β β r : π, r β 0 β§ y = r β’ x :=
β¨fun β¨r, hβ© => β¨r, fun hrβ => hyβ <| h.symm βΈ smul_eq_zero.2 <| Or.inl hrβ, hβ©,
fun β¨r, _hrβ, hβ© => β¨r, hβ©β©
/-- The inner product of two vectors, divided by the product of their
norms, has absolute value 1 if and only if they are nonzero and one is
a multiple of the other. One form of equality case for Cauchy-Schwarz. -/
theorem norm_inner_div_norm_mul_norm_eq_one_iff (x y : E) :
ββͺx, yβ« / (βxβ * βyβ)β = 1 β x β 0 β§ β r : π, r β 0 β§ y = r β’ x := by
constructor
Β· intro h
have hxβ : x β 0 := fun hβ => by simp [hβ] at h
have hyβ : y β 0 := fun hβ => by simp [hβ] at h
refine β¨hxβ, (norm_inner_eq_norm_iff hxβ hyβ).1 <| eq_of_div_eq_one ?_β©
simpa using h
Β· rintro β¨hx, β¨r, β¨hr, rflβ©β©β©
simp only [norm_div, norm_mul, norm_ofReal, abs_norm]
exact norm_inner_div_norm_mul_norm_eq_one_of_ne_zero_of_ne_zero_mul hx hr
/-- The inner product of two vectors, divided by the product of their
norms, has absolute value 1 if and only if they are nonzero and one is
a multiple of the other. One form of equality case for Cauchy-Schwarz. -/
theorem abs_real_inner_div_norm_mul_norm_eq_one_iff (x y : F) :
|βͺx, yβ«_β / (βxβ * βyβ)| = 1 β x β 0 β§ β r : β, r β 0 β§ y = r β’ x :=
@norm_inner_div_norm_mul_norm_eq_one_iff β F _ _ _ x y
theorem inner_eq_norm_mul_iff_div {x y : E} (hβ : x β 0) :
βͺx, yβ« = (βxβ : π) * βyβ β (βyβ / βxβ : π) β’ x = y := by
have hβ' := hβ
rw [β norm_ne_zero_iff, Ne, β @ofReal_eq_zero π] at hβ'
constructor <;> intro h
Β· have : x = 0 β¨ y = (βͺx, yβ« / βͺx, xβ« : π) β’ x :=
((@norm_inner_eq_norm_tfae π _ _ _ _ x y).out 0 1).1 (by simp [h])
rw [this.resolve_left hβ, h]
simp [norm_smul, inner_self_ofReal_norm, mul_div_cancel_rightβ _ hβ']
Β· conv_lhs => rw [β h, inner_smul_right, inner_self_eq_norm_sq_to_K]
field_simp [sq, mul_left_comm]
/-- If the inner product of two vectors is equal to the product of their norms (i.e.,
`βͺx, yβ« = βxβ * βyβ`), then the two vectors are nonnegative real multiples of each other. One form
of the equality case for Cauchy-Schwarz.
Compare `norm_inner_eq_norm_iff`, which takes the weaker hypothesis `abs βͺx, yβ« = βxβ * βyβ`. -/
theorem inner_eq_norm_mul_iff {x y : E} :
βͺx, yβ« = (βxβ : π) * βyβ β (βyβ : π) β’ x = (βxβ : π) β’ y := by
rcases eq_or_ne x 0 with (rfl | hβ)
Β· simp
Β· rw [inner_eq_norm_mul_iff_div hβ, div_eq_inv_mul, mul_smul, inv_smul_eq_iffβ]
rwa [Ne, ofReal_eq_zero, norm_eq_zero]
/-- If the inner product of two vectors is equal to the product of their norms (i.e.,
`βͺx, yβ« = βxβ * βyβ`), then the two vectors are nonnegative real multiples of each other. One form
of the equality case for Cauchy-Schwarz.
Compare `norm_inner_eq_norm_iff`, which takes the weaker hypothesis `abs βͺx, yβ« = βxβ * βyβ`. -/
theorem inner_eq_norm_mul_iff_real {x y : F} : βͺx, yβ«_β = βxβ * βyβ β βyβ β’ x = βxβ β’ y :=
inner_eq_norm_mul_iff
/-- The inner product of two vectors, divided by the product of their
norms, has value 1 if and only if they are nonzero and one is
a positive multiple of the other. -/
theorem real_inner_div_norm_mul_norm_eq_one_iff (x y : F) :
βͺx, yβ«_β / (βxβ * βyβ) = 1 β x β 0 β§ β r : β, 0 < r β§ y = r β’ x := by
constructor
Β· intro h
have hxβ : x β 0 := fun hβ => by simp [hβ] at h
have hyβ : y β 0 := fun hβ => by simp [hβ] at h
refine β¨hxβ, βyβ / βxβ, div_pos (norm_pos_iff.2 hyβ) (norm_pos_iff.2 hxβ), ?_β©
exact ((inner_eq_norm_mul_iff_div hxβ).1 (eq_of_div_eq_one h)).symm
Β· rintro β¨hx, β¨r, β¨hr, rflβ©β©β©
exact real_inner_div_norm_mul_norm_eq_one_of_ne_zero_of_pos_mul hx hr
/-- The inner product of two vectors, divided by the product of their
norms, has value -1 if and only if they are nonzero and one is
a negative multiple of the other. -/
theorem real_inner_div_norm_mul_norm_eq_neg_one_iff (x y : F) :
βͺx, yβ«_β / (βxβ * βyβ) = -1 β x β 0 β§ β r : β, r < 0 β§ y = r β’ x := by
rw [β neg_eq_iff_eq_neg, β neg_div, β inner_neg_right, β norm_neg y,
real_inner_div_norm_mul_norm_eq_one_iff, (@neg_surjective β _).exists]
refine Iff.rfl.and (exists_congr fun r => ?_)
rw [neg_pos, neg_smul, neg_inj]
/-- If the inner product of two unit vectors is `1`, then the two vectors are equal. One form of
the equality case for Cauchy-Schwarz. -/
theorem inner_eq_one_iff_of_norm_one {x y : E} (hx : βxβ = 1) (hy : βyβ = 1) :
βͺx, yβ« = 1 β x = y := by
convert inner_eq_norm_mul_iff (π := π) (E := E) using 2 <;> simp [hx, hy]
theorem inner_lt_norm_mul_iff_real {x y : F} : βͺx, yβ«_β < βxβ * βyβ β βyβ β’ x β βxβ β’ y :=
calc
βͺx, yβ«_β < βxβ * βyβ β βͺx, yβ«_β β βxβ * βyβ :=
β¨ne_of_lt, lt_of_le_of_ne (real_inner_le_norm _ _)β©
_ β βyβ β’ x β βxβ β’ y := not_congr inner_eq_norm_mul_iff_real
/-- If the inner product of two unit vectors is strictly less than `1`, then the two vectors are
distinct. One form of the equality case for Cauchy-Schwarz. -/
theorem inner_lt_one_iff_real_of_norm_one {x y : F} (hx : βxβ = 1) (hy : βyβ = 1) :
βͺx, yβ«_β < 1 β x β y := by convert inner_lt_norm_mul_iff_real (F := F) <;> simp [hx, hy]
/-- The sphere of radius `r = βyβ` is tangent to the plane `βͺx, yβ« = βyβ ^ 2` at `x = y`. -/
theorem eq_of_norm_le_re_inner_eq_norm_sq {x y : E} (hle : βxβ β€ βyβ) (h : re βͺx, yβ« = βyβ ^ 2) :
x = y := by
suffices H : re βͺx - y, x - yβ« β€ 0 by rwa [re_inner_self_nonpos, sub_eq_zero] at H
have Hβ : βxβ ^ 2 β€ βyβ ^ 2 := by gcongr
have Hβ : re βͺy, xβ« = βyβ ^ 2 := by rwa [β inner_conj_symm, conj_re]
simpa [inner_sub_left, inner_sub_right, β norm_sq_eq_re_inner, h, Hβ] using Hβ
end Norm
section RCLike
local notation "βͺ" x ", " y "β«" => @inner π _ _ x y
/-- A field `π` satisfying `RCLike` is itself a `π`-inner product space. -/
instance RCLike.innerProductSpace : InnerProductSpace π π where
inner x y := y * conj x
norm_sq_eq_re_inner x := by simp only [inner, mul_conj, β ofReal_pow, ofReal_re]
conj_inner_symm x y := by simp only [mul_comm, map_mul, starRingEnd_self_apply]
add_left x y z := by simp only [mul_add, map_add]
smul_left x y z := by simp only [mul_comm (conj z), mul_assoc, smul_eq_mul, map_mul]
@[simp]
theorem RCLike.inner_apply (x y : π) : βͺx, yβ« = y * conj x :=
rfl
/-- A version of `RCLike.inner_apply` that swaps the order of multiplication. -/
theorem RCLike.inner_apply' (x y : π) : βͺx, yβ« = conj x * y := mul_comm _ _
end RCLike
section RCLikeToReal
open scoped InnerProductSpace
variable {G : Type*}
variable (π E)
variable [SeminormedAddCommGroup E] [InnerProductSpace π E]
local notation "βͺ" x ", " y "β«" => @inner π _ _ x y
/-- A general inner product implies a real inner product. This is not registered as an instance
since `π` does not appear in the return type `Inner β E`. -/
def Inner.rclikeToReal : Inner β E where inner x y := re βͺx, yβ«
/-- A general inner product space structure implies a real inner product structure.
This is not registered as an instance since
* `π` does not appear in the return type `InnerProductSpace β E`,
* It is likely to create instance diamonds, as it builds upon the diamond-prone
`NormedSpace.restrictScalars`.
However, it can be used in a proof to obtain a real inner product space structure from a given
`π`-inner product space structure. -/
-- See note [reducible non instances]
abbrev InnerProductSpace.rclikeToReal : InnerProductSpace β E :=
{ Inner.rclikeToReal π E,
NormedSpace.restrictScalars β π
E with
norm_sq_eq_re_inner := norm_sq_eq_re_inner
conj_inner_symm := fun _ _ => inner_re_symm _ _
add_left := fun x y z => by
change re βͺx + y, zβ« = re βͺx, zβ« + re βͺy, zβ«
simp only [inner_add_left, map_add]
smul_left := fun x y r => by
change re βͺ(r : π) β’ x, yβ« = r * re βͺx, yβ«
simp only [inner_smul_left, conj_ofReal, re_ofReal_mul] }
variable {E}
theorem real_inner_eq_re_inner (x y : E) :
@Inner.inner β E (Inner.rclikeToReal π E) x y = re βͺx, yβ« :=
rfl
theorem real_inner_I_smul_self (x : E) :
@Inner.inner β E (Inner.rclikeToReal π E) x ((I : π) β’ x) = 0 := by
simp [real_inner_eq_re_inner π, inner_smul_right]
/-- A complex inner product implies a real inner product. This cannot be an instance since it
creates a diamond with `PiLp.innerProductSpace` because `re (sum i, inner (x i) (y i))` and
`sum i, re (inner (x i) (y i))` are not defeq. -/
def InnerProductSpace.complexToReal [SeminormedAddCommGroup G] [InnerProductSpace β G] :
InnerProductSpace β G :=
InnerProductSpace.rclikeToReal β G
instance : InnerProductSpace β β := InnerProductSpace.complexToReal
@[simp]
protected theorem Complex.inner (w z : β) : βͺw, zβ«_β = (z * conj w).re :=
rfl
end RCLikeToReal
/-- An `RCLike` field is a real inner product space. -/
noncomputable instance RCLike.toInnerProductSpaceReal : InnerProductSpace β π where
__ := Inner.rclikeToReal π π
norm_sq_eq_re_inner := norm_sq_eq_re_inner
conj_inner_symm x y := inner_re_symm ..
add_left x y z :=
show re (_ * _) = re (_ * _) + re (_ * _) by simp only [map_add, mul_re, conj_re, conj_im]; ring
smul_left x y r :=
show re (_ * _) = _ * re (_ * _) by
simp only [mul_re, conj_re, conj_im, conj_trivial, smul_re, smul_im]; ring
-- The instance above does not create diamonds for concrete `π`:
example : (innerProductSpace : InnerProductSpace β β) = RCLike.toInnerProductSpaceReal := rfl
example :
(instInnerProductSpaceRealComplex : InnerProductSpace β β) = RCLike.toInnerProductSpaceReal := rfl
| Mathlib/Analysis/InnerProductSpace/Basic.lean | 902 | 910 | |
/-
Copyright (c) 2020 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin
-/
import Mathlib.Algebra.CharP.Reduced
import Mathlib.RingTheory.IntegralDomain
-- TODO: remove Mathlib.Algebra.CharP.Reduced and move the last two lemmas to Lemmas
/-!
# Roots of unity
We define roots of unity in the context of an arbitrary commutative monoid,
as a subgroup of the group of units.
## Main definitions
* `rootsOfUnity n M`, for `n : β` is the subgroup of the units of a commutative monoid `M`
consisting of elements `x` that satisfy `x ^ n = 1`.
## Main results
* `rootsOfUnity.isCyclic`: the roots of unity in an integral domain form a cyclic group.
## Implementation details
It is desirable that `rootsOfUnity` is a subgroup,
and it will mainly be applied to rings (e.g. the ring of integers in a number field) and fields.
We therefore implement it as a subgroup of the units of a commutative monoid.
We have chosen to define `rootsOfUnity n` for `n : β` and add a `[NeZero n]` typeclass
assumption when we need `n` to be non-zero (which is the case for most interesting statements).
Note that `rootsOfUnity 0 M` is the top subgroup of `MΛ£` (as the condition `ΞΆ^0 = 1` is
satisfied for all units).
-/
noncomputable section
open Polynomial
open Finset
variable {M N G R S F : Type*}
variable [CommMonoid M] [CommMonoid N] [DivisionCommMonoid G]
section rootsOfUnity
variable {k l : β}
/-- `rootsOfUnity k M` is the subgroup of elements `m : MΛ£` that satisfy `m ^ k = 1`. -/
def rootsOfUnity (k : β) (M : Type*) [CommMonoid M] : Subgroup MΛ£ where
carrier := {ΞΆ | ΞΆ ^ k = 1}
one_mem' := one_pow _
mul_mem' _ _ := by simp_all only [Set.mem_setOf_eq, mul_pow, one_mul]
inv_mem' _ := by simp_all only [Set.mem_setOf_eq, inv_pow, inv_one]
@[simp]
theorem mem_rootsOfUnity (k : β) (ΞΆ : MΛ£) : ΞΆ β rootsOfUnity k M β ΞΆ ^ k = 1 :=
Iff.rfl
/-- A variant of `mem_rootsOfUnity` using `ΞΆ : MΛ£`. -/
theorem mem_rootsOfUnity' (k : β) (ΞΆ : MΛ£) : ΞΆ β rootsOfUnity k M β (ΞΆ : M) ^ k = 1 := by
rw [mem_rootsOfUnity]; norm_cast
@[simp]
theorem rootsOfUnity_one (M : Type*) [CommMonoid M] : rootsOfUnity 1 M = β₯ := by
ext1
simp only [mem_rootsOfUnity, pow_one, Subgroup.mem_bot]
@[simp]
lemma rootsOfUnity_zero (M : Type*) [CommMonoid M] : rootsOfUnity 0 M = β€ := by
ext1
simp only [mem_rootsOfUnity, pow_zero, Subgroup.mem_top]
theorem rootsOfUnity.coe_injective {n : β} :
Function.Injective (fun x : rootsOfUnity n M β¦ x.val.val) :=
Units.ext.comp fun _ _ β¦ Subtype.eq
/-- Make an element of `rootsOfUnity` from a member of the base ring, and a proof that it has
a positive power equal to one. -/
@[simps! coe_val]
def rootsOfUnity.mkOfPowEq (ΞΆ : M) {n : β} [NeZero n] (h : ΞΆ ^ n = 1) : rootsOfUnity n M :=
β¨Units.ofPowEqOne ΞΆ n h <| NeZero.ne n, Units.pow_ofPowEqOne _ _β©
@[simp]
theorem rootsOfUnity.coe_mkOfPowEq {ΞΆ : M} {n : β} [NeZero n] (h : ΞΆ ^ n = 1) :
((rootsOfUnity.mkOfPowEq _ h : MΛ£) : M) = ΞΆ :=
rfl
theorem rootsOfUnity_le_of_dvd (h : k β£ l) : rootsOfUnity k M β€ rootsOfUnity l M := by
obtain β¨d, rflβ© := h
intro ΞΆ h
simp_all only [mem_rootsOfUnity, pow_mul, one_pow]
theorem map_rootsOfUnity (f : MΛ£ β* NΛ£) (k : β) : (rootsOfUnity k M).map f β€ rootsOfUnity k N := by
rintro _ β¨ΞΆ, h, rflβ©
simp_all only [β map_pow, mem_rootsOfUnity, SetLike.mem_coe, MonoidHom.map_one]
@[norm_cast]
theorem rootsOfUnity.coe_pow [CommMonoid R] (ΞΆ : rootsOfUnity k R) (m : β) :
(((ΞΆ ^ m :) : RΛ£) : R) = ((ΞΆ : RΛ£) : R) ^ m := by
rw [Subgroup.coe_pow, Units.val_pow_eq_pow_val]
/-- The canonical isomorphism from the `n`th roots of unity in `MΛ£`
to the `n`th roots of unity in `M`. -/
def rootsOfUnityUnitsMulEquiv (M : Type*) [CommMonoid M] (n : β) :
rootsOfUnity n MΛ£ β* rootsOfUnity n M where
toFun ΞΆ := β¨ΞΆ.val, (mem_rootsOfUnity ..).mpr <| (mem_rootsOfUnity' ..).mp ΞΆ.propβ©
invFun ΞΆ := β¨toUnits ΞΆ.val, by
simp only [mem_rootsOfUnity, β map_pow, EmbeddingLike.map_eq_one_iff]
exact (mem_rootsOfUnity ..).mp ΞΆ.propβ©
left_inv ΞΆ := by simp only [toUnits_val_apply, Subtype.coe_eta]
right_inv ΞΆ := by simp only [val_toUnits_apply, Subtype.coe_eta]
map_mul' ΞΆ ΞΆ' := by simp only [Subgroup.coe_mul, Units.val_mul, MulMemClass.mk_mul_mk]
section CommMonoid
variable [CommMonoid R] [CommMonoid S] [FunLike F R S]
/-- Restrict a ring homomorphism to the nth roots of unity. -/
def restrictRootsOfUnity [MonoidHomClass F R S] (Ο : F) (n : β) :
rootsOfUnity n R β* rootsOfUnity n S :=
{ toFun := fun ΞΎ β¦ β¨Units.map Ο (ΞΎ : RΛ£), by
rw [mem_rootsOfUnity, β map_pow, Units.ext_iff, Units.coe_map, ΞΎ.prop]
exact map_one Οβ©
map_one' := by ext1; simp only [OneMemClass.coe_one, map_one]
map_mul' := fun ΞΎβ ΞΎβ β¦ by
ext1; simp only [Subgroup.coe_mul, map_mul, MulMemClass.mk_mul_mk] }
@[simp]
theorem restrictRootsOfUnity_coe_apply [MonoidHomClass F R S] (Ο : F) (ΞΆ : rootsOfUnity k R) :
(restrictRootsOfUnity Ο k ΞΆ : SΛ£) = Ο (ΞΆ : RΛ£) :=
rfl
/-- Restrict a monoid isomorphism to the nth roots of unity. -/
nonrec def MulEquiv.restrictRootsOfUnity (Ο : R β* S) (n : β) :
rootsOfUnity n R β* rootsOfUnity n S where
toFun := restrictRootsOfUnity Ο n
invFun := restrictRootsOfUnity Ο.symm n
left_inv ΞΎ := by ext; exact Ο.symm_apply_apply _
right_inv ΞΎ := by ext; exact Ο.apply_symm_apply _
map_mul' := (restrictRootsOfUnity _ n).map_mul
@[simp]
theorem MulEquiv.restrictRootsOfUnity_coe_apply (Ο : R β* S) (ΞΆ : rootsOfUnity k R) :
(Ο.restrictRootsOfUnity k ΞΆ : SΛ£) = Ο (ΞΆ : RΛ£) :=
rfl
@[simp]
theorem MulEquiv.restrictRootsOfUnity_symm (Ο : R β* S) :
(Ο.restrictRootsOfUnity k).symm = Ο.symm.restrictRootsOfUnity k :=
rfl
end CommMonoid
section IsDomain
-- The following results need `k` to be nonzero.
variable [NeZero k] [CommRing R] [IsDomain R]
theorem mem_rootsOfUnity_iff_mem_nthRoots {ΞΆ : RΛ£} :
ΞΆ β rootsOfUnity k R β (ΞΆ : R) β nthRoots k (1 : R) := by
simp only [mem_rootsOfUnity, mem_nthRoots (NeZero.pos k), Units.ext_iff, Units.val_one,
Units.val_pow_eq_pow_val]
variable (k R)
/-- Equivalence between the `k`-th roots of unity in `R` and the `k`-th roots of `1`.
This is implemented as equivalence of subtypes,
because `rootsOfUnity` is a subgroup of the group of units,
whereas `nthRoots` is a multiset. -/
def rootsOfUnityEquivNthRoots : rootsOfUnity k R β { x // x β nthRoots k (1 : R) } where
toFun x := β¨(x : RΛ£), mem_rootsOfUnity_iff_mem_nthRoots.mp x.2β©
invFun x := by
refine β¨β¨x, βx ^ (k - 1 : β), ?_, ?_β©, ?_β©
all_goals
rcases x with β¨x, hxβ©; rw [mem_nthRoots <| NeZero.pos k] at hx
simp only [β pow_succ, β pow_succ', hx, tsub_add_cancel_of_le NeZero.one_le]
simp only [mem_rootsOfUnity, Units.ext_iff, Units.val_pow_eq_pow_val, hx, Units.val_one]
left_inv := by rintro β¨x, hxβ©; ext; rfl
right_inv := by rintro β¨x, hxβ©; ext; rfl
variable {k R}
@[simp]
theorem rootsOfUnityEquivNthRoots_apply (x : rootsOfUnity k R) :
(rootsOfUnityEquivNthRoots R k x : R) = ((x : RΛ£) : R) :=
rfl
@[simp]
theorem rootsOfUnityEquivNthRoots_symm_apply (x : { x // x β nthRoots k (1 : R) }) :
(((rootsOfUnityEquivNthRoots R k).symm x : RΛ£) : R) = (x : R) :=
rfl
variable (k R)
instance rootsOfUnity.fintype : Fintype (rootsOfUnity k R) := by
classical
exact Fintype.ofEquiv { x // x β nthRoots k (1 : R) } (rootsOfUnityEquivNthRoots R k).symm
instance rootsOfUnity.isCyclic : IsCyclic (rootsOfUnity k R) :=
isCyclic_of_subgroup_isDomain ((Units.coeHom R).comp (rootsOfUnity k R).subtype) coe_injective
theorem card_rootsOfUnity : Fintype.card (rootsOfUnity k R) β€ k := by
classical
calc
Fintype.card (rootsOfUnity k R) = Fintype.card { x // x β nthRoots k (1 : R) } :=
Fintype.card_congr (rootsOfUnityEquivNthRoots R k)
_ β€ Multiset.card (nthRoots k (1 : R)).attach := Multiset.card_le_card (Multiset.dedup_le _)
_ = Multiset.card (nthRoots k (1 : R)) := Multiset.card_attach
_ β€ k := card_nthRoots k 1
variable {k R}
theorem map_rootsOfUnity_eq_pow_self [FunLike F R R] [MonoidHomClass F R R] (Ο : F)
(ΞΆ : rootsOfUnity k R) :
β m : β, Ο (ΞΆ : RΛ£) = ((ΞΆ : RΛ£) : R) ^ m := by
obtain β¨m, hmβ© := MonoidHom.map_cyclic (restrictRootsOfUnity Ο k)
rw [β restrictRootsOfUnity_coe_apply, hm, β zpow_mod_orderOf, β Int.toNat_of_nonneg
(m.emod_nonneg (Int.natCast_ne_zero.mpr (pos_iff_ne_zero.mp (orderOf_pos ΞΆ)))),
zpow_natCast, rootsOfUnity.coe_pow]
exact β¨(m % orderOf ΞΆ).toNat, rflβ©
end IsDomain
section Reduced
variable (R) [CommRing R] [IsReduced R]
-- @[simp] -- Porting note: simp normal form is `mem_rootsOfUnity_prime_pow_mul_iff'`
theorem mem_rootsOfUnity_prime_pow_mul_iff (p k : β) (m : β) [ExpChar R p] {ΞΆ : RΛ£} :
ΞΆ β rootsOfUnity (p ^ k * m) R β ΞΆ β rootsOfUnity m R := by
simp only [mem_rootsOfUnity', ExpChar.pow_prime_pow_mul_eq_one_iff]
/-- A variant of `mem_rootsOfUnity_prime_pow_mul_iff` in terms of `ΞΆ ^ _` -/
@[simp]
theorem mem_rootsOfUnity_prime_pow_mul_iff' (p k : β) (m : β) [ExpChar R p] {ΞΆ : RΛ£} :
ΞΆ ^ (p ^ k * m) = 1 β ΞΆ β rootsOfUnity m R := by
rw [β mem_rootsOfUnity, mem_rootsOfUnity_prime_pow_mul_iff]
end Reduced
end rootsOfUnity
section cyclic
namespace IsCyclic
/-- The isomorphism from the group of group homomorphisms from a finite cyclic group `G` of order
`n` into another group `G'` to the group of `n`th roots of unity in `G'` determined by a generator
`g` of `G`. It sends `Ο : G β* G'` to `Ο g`. -/
noncomputable
def monoidHomMulEquivRootsOfUnityOfGenerator {G : Type*} [CommGroup G] {g : G}
(hg : β (x : G), x β Subgroup.zpowers g) (G' : Type*) [CommGroup G'] :
(G β* G') β* rootsOfUnity (Nat.card G) G' where
toFun Ο := β¨(IsUnit.map Ο <| Group.isUnit g).unit, by
simp only [mem_rootsOfUnity, Units.ext_iff, Units.val_pow_eq_pow_val, IsUnit.unit_spec,
β map_pow, pow_card_eq_one', map_one, Units.val_one]β©
invFun ΞΆ := monoidHomOfForallMemZpowers hg (g' := (ΞΆ.val : G')) <| by
simpa only [orderOf_eq_card_of_forall_mem_zpowers hg, orderOf_dvd_iff_pow_eq_one,
β Units.val_pow_eq_pow_val, Units.val_eq_one] using ΞΆ.prop
left_inv Ο := (MonoidHom.eq_iff_eq_on_generator hg _ Ο).mpr <| by
simp only [IsUnit.unit_spec, monoidHomOfForallMemZpowers_apply_gen]
right_inv Ο := Subtype.ext <| by
simp only [monoidHomOfForallMemZpowers_apply_gen, IsUnit.unit_of_val_units]
map_mul' x y := by
simp only [MonoidHom.mul_apply, MulMemClass.mk_mul_mk, Subtype.mk.injEq, Units.ext_iff,
IsUnit.unit_spec, Units.val_mul]
/-- The group of group homomorphisms from a finite cyclic group `G` of order `n` into another
group `G'` is (noncanonically) isomorphic to the group of `n`th roots of unity in `G'`. -/
lemma monoidHom_mulEquiv_rootsOfUnity (G : Type*) [CommGroup G] [IsCyclic G]
(G' : Type*) [CommGroup G'] :
Nonempty <| (G β* G') β* rootsOfUnity (Nat.card G) G' := by
obtain β¨g, hgβ© := IsCyclic.exists_generator (Ξ± := G)
exact β¨monoidHomMulEquivRootsOfUnityOfGenerator hg G'β©
end IsCyclic
end cyclic
| Mathlib/RingTheory/RootsOfUnity/Basic.lean | 779 | 790 | |
/-
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]
| Mathlib/Analysis/SpecialFunctions/Log/Base.lean | 49 | 49 |
/-
Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes HΓΆlzl, Mario Carneiro
-/
import Mathlib.Data.ENNReal.Action
import Mathlib.MeasureTheory.MeasurableSpace.Constructions
import Mathlib.MeasureTheory.OuterMeasure.Caratheodory
/-!
# Induced Outer Measure
We can extend a function defined on a subset of `Set Ξ±` to an outer measure.
The underlying function is called `extend`, and the measure it induces is called
`inducedOuterMeasure`.
Some lemmas below are proven twice, once in the general case, and one where the function `m`
is only defined on measurable sets (i.e. when `P = MeasurableSet`). In the latter cases, we can
remove some hypotheses in the statement. The general version has the same name, but with a prime
at the end.
## Tags
outer measure
-/
noncomputable section
open Set Function Filter
open scoped NNReal Topology ENNReal
namespace MeasureTheory
open OuterMeasure
section Extend
variable {Ξ± : Type*} {P : Ξ± β Prop}
variable (m : β s : Ξ±, P s β ββ₯0β)
/-- We can trivially extend a function defined on a subclass of objects (with codomain `ββ₯0β`)
to all objects by defining it to be `β` on the objects not in the class. -/
def extend (s : Ξ±) : ββ₯0β :=
β¨
h : P s, m s h
theorem extend_eq {s : Ξ±} (h : P s) : extend m s = m s h := by simp [extend, h]
theorem extend_eq_top {s : Ξ±} (h : Β¬P s) : extend m s = β := by simp [extend, h]
theorem smul_extend {R} [Zero R] [SMulWithZero R ββ₯0β] [IsScalarTower R ββ₯0β ββ₯0β]
[NoZeroSMulDivisors R ββ₯0β] {c : R} (hc : c β 0) :
c β’ extend m = extend fun s h => c β’ m s h := by
classical
ext1 s
dsimp [extend]
by_cases h : P s
Β· simp [h]
Β· simp [h, ENNReal.smul_top, hc]
theorem le_extend {s : Ξ±} (h : P s) : m s h β€ extend m s := by
simp only [extend, le_iInf_iff]
intro
| rfl
-- TODO: why this is a bad `congr` lemma?
theorem extend_congr {Ξ² : Type*} {Pb : Ξ² β Prop} {mb : β s : Ξ², Pb s β ββ₯0β} {sa : Ξ±} {sb : Ξ²}
| Mathlib/MeasureTheory/OuterMeasure/Induced.lean | 65 | 68 |
/-
Copyright (c) 2020 Bhavik Mehta. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Bhavik Mehta, JoΓ«l Riou
-/
import Mathlib.CategoryTheory.Comma.Presheaf.Basic
import Mathlib.CategoryTheory.Elements
import Mathlib.CategoryTheory.Functor.KanExtension.Adjunction
import Mathlib.CategoryTheory.Limits.Final
import Mathlib.CategoryTheory.Limits.Over
/-!
# Colimit of representables
This file constructs an adjunction `Presheaf.yonedaAdjunction` between `(Cα΅α΅ β₯€ Type u)` and
`β°` given a functor `A : C β₯€ β°`, where the right adjoint `restrictedYoneda`
sends `(E : β°)` to `c β¦ (A.obj c βΆ E)`, and the left adjoint `(Cα΅α΅ β₯€ Type vβ) β₯€ β°`
is a pointwise left Kan extension of `A` along the Yoneda embedding, which
exists provided `β°` has colimits)
We also show that every presheaf is a colimit of representables. This result
is also known as the density theorem, the co-Yoneda lemma and
the Ninja Yoneda lemma. Two formulations are given:
* `colimitOfRepresentable` uses the category of elements of a functor to types;
* `isColimitTautologicalCocone` uses the category of costructured arrows.
In the lemma `isLeftKanExtension_along_yoneda_iff`, we show that
if `L : (Cα΅α΅ β₯€ Type vβ) β₯€ β°)` and `Ξ± : A βΆ yoneda β L`, then
`Ξ±` makes `L` the left Kan extension of `L` along yoneda if and only if
`Ξ±` is an isomorphism (i.e. `L` extends `A`) and `L` preserves colimits.
`uniqueExtensionAlongYoneda` shows `yoneda.leftKanExtension A` is unique amongst
functors preserving colimits with this property, establishing the
presheaf category as the free cocompletion of a category.
Given a functor `F : C β₯€ D`, we also show construct an
isomorphism `compYonedaIsoYonedaCompLan : F β yoneda β
yoneda β F.op.lan`, and
show that it makes `F.op.lan` a left Kan extension of `F β yoneda`.
## Tags
colimit, representable, presheaf, free cocompletion
## References
* [S. MacLane, I. Moerdijk, *Sheaves in Geometry and Logic*][MM92]
* https://ncatlab.org/nlab/show/Yoneda+extension
-/
namespace CategoryTheory
open Category Limits
universe vβ vβ vβ uβ uβ uβ
namespace Presheaf
variable {C : Type uβ} [Category.{vβ} C]
variable {β° : Type uβ} [Category.{vβ} β°] (A : C β₯€ β°)
/--
The functor taking `(E : β°) (c : Cα΅α΅)` to the homset `(A.obj C βΆ E)`. It is shown in `L_adjunction`
that this functor has a left adjoint (provided `E` has colimits) given by taking colimits over
categories of elements.
In the case where `β° = Cα΅α΅ β₯€ Type u` and `A = yoneda`, this functor is isomorphic to the identity.
Defined as in [MM92], Chapter I, Section 5, Theorem 2.
-/
@[simps!]
def restrictedYoneda : β° β₯€ Cα΅α΅ β₯€ Type vβ :=
yoneda β (whiskeringLeft _ _ (Type vβ)).obj (Functor.op A)
/-- Auxiliary definition for `restrictedYonedaHomEquiv`. -/
def restrictedYonedaHomEquiv' (P : Cα΅α΅ β₯€ Type vβ) (E : β°) :
(CostructuredArrow.proj yoneda P β A βΆ
(Functor.const (CostructuredArrow yoneda P)).obj E) β
(P βΆ (restrictedYoneda A).obj E) where
toFun f :=
{ app := fun _ x => f.app (CostructuredArrow.mk (yonedaEquiv.symm x))
naturality := fun {Xβ Xβ} Ο => by
ext x
let Ο : CostructuredArrow.mk (yonedaEquiv.symm (P.toPrefunctor.map Ο x)) βΆ
CostructuredArrow.mk (yonedaEquiv.symm x) := CostructuredArrow.homMk Ο.unop (by
dsimp [yonedaEquiv]
aesop_cat )
simpa using (f.naturality Ο).symm }
invFun g :=
{ app := fun y => yonedaEquiv (y.hom β« g)
naturality := fun {Xβ Xβ} Ο => by
dsimp
rw [β CostructuredArrow.w Ο]
dsimp [yonedaEquiv]
simp only [comp_id, id_comp]
refine (congr_fun (g.naturality Ο.left.op) (Xβ.hom.app (Opposite.op Xβ.left)
(π _))).symm.trans ?_
dsimp
apply congr_arg
simpa using congr_fun (Xβ.hom.naturality Ο.left.op).symm (π _) }
left_inv f := by
ext β¨X, β¨β¨β©β©, Οβ©
suffices yonedaEquiv.symm (Ο.app (Opposite.op X) (π X)) = Ο by
dsimp
erw [yonedaEquiv_apply]
dsimp [CostructuredArrow.mk]
erw [this]
exact yonedaEquiv.injective (by aesop_cat)
right_inv g := by
ext X x
dsimp
erw [yonedaEquiv_apply]
dsimp
rw [yonedaEquiv_symm_app_apply]
simp
section
example [HasColimitsOfSize.{vβ, max uβ vβ} β°] :
yoneda.HasPointwiseLeftKanExtension A := inferInstance
variable [yoneda.HasPointwiseLeftKanExtension A]
variable {A}
variable (L : (Cα΅α΅ β₯€ Type vβ) β₯€ β°) (Ξ± : A βΆ yoneda β L) [L.IsLeftKanExtension Ξ±]
/-- Auxiliary definition for `yonedaAdjunction`. -/
noncomputable def restrictedYonedaHomEquiv (P : Cα΅α΅ β₯€ Type vβ) (E : β°) :
(L.obj P βΆ E) β (P βΆ (restrictedYoneda A).obj E) :=
((Functor.isPointwiseLeftKanExtensionOfIsLeftKanExtension _ Ξ± P).homEquiv E).trans
(restrictedYonedaHomEquiv' A P E)
/-- If `L : (Cα΅α΅ β₯€ Type vβ) β₯€ β°` is a pointwise left Kan extension
of a functor `A : C β₯€ β°` along the Yoneda embedding,
then `L` is a left adjoint of `restrictedYoneda A : β° β₯€ Cα΅α΅ β₯€ Type vβ` -/
noncomputable def yonedaAdjunction : L β£ restrictedYoneda A :=
Adjunction.mkOfHomEquiv
{ homEquiv := restrictedYonedaHomEquiv L Ξ±
homEquiv_naturality_left_symm := fun {P Q X} f g => by
obtain β¨g, rflβ© := (restrictedYonedaHomEquiv L Ξ± Q X).surjective g
apply (restrictedYonedaHomEquiv L Ξ± P X).injective
simp only [Equiv.apply_symm_apply, Equiv.symm_apply_apply]
ext Y y
dsimp [restrictedYonedaHomEquiv, restrictedYonedaHomEquiv', IsColimit.homEquiv]
rw [assoc, assoc, β L.map_comp_assoc]
congr 3
apply yonedaEquiv.injective
simp [yonedaEquiv]
homEquiv_naturality_right := fun {P X Y} f g => by
apply (restrictedYonedaHomEquiv L Ξ± P Y).symm.injective
simp only [Equiv.symm_apply_apply]
dsimp [restrictedYonedaHomEquiv, restrictedYonedaHomEquiv', IsColimit.homEquiv]
apply (Functor.isPointwiseLeftKanExtensionOfIsLeftKanExtension L Ξ± P).hom_ext
intro p
rw [IsColimit.fac]
dsimp [restrictedYoneda, yonedaEquiv]
simp only [assoc]
congr 3
apply yonedaEquiv.injective
simp [yonedaEquiv] }
|
include Ξ± in
/-- Any left Kan extension along the Yoneda embedding preserves colimits. -/
lemma preservesColimitsOfSize_of_isLeftKanExtension :
PreservesColimitsOfSize.{vβ, uβ} L :=
(yonedaAdjunction L Ξ±).leftAdjoint_preservesColimits
lemma isIso_of_isLeftKanExtension : IsIso Ξ± :=
(Functor.isPointwiseLeftKanExtensionOfIsLeftKanExtension _ Ξ±).isIso_hom
variable (A)
/-- See Property 2 of https://ncatlab.org/nlab/show/Yoneda+extension#properties. -/
noncomputable instance preservesColimitsOfSize_leftKanExtension :
PreservesColimitsOfSize.{vβ, uβ} (yoneda.leftKanExtension A) :=
(yonedaAdjunction _ (yoneda.leftKanExtensionUnit A)).leftAdjoint_preservesColimits
instance : IsIso (yoneda.leftKanExtensionUnit A) :=
| Mathlib/CategoryTheory/Limits/Presheaf.lean | 157 | 174 |
/-
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, Johan Commelin
-/
import Mathlib.Analysis.Analytic.Basic
import Mathlib.Combinatorics.Enumerative.Composition
/-!
# Composition of analytic functions
In this file we prove that the composition of analytic functions is analytic.
The argument is the following. Assume `g z = β' qβ (z, ..., z)` and `f y = β' pβ (y, ..., y)`. Then
`g (f y) = β' qβ (β' pβ (y, ..., y), ..., β' pβ (y, ..., y))
= β' qβ (p_{iβ} (y, ..., y), ..., p_{iβ} (y, ..., y))`.
For each `n` and `iβ, ..., iβ`, define a `iβ + ... + iβ` multilinear function mapping
`(yβ, ..., y_{iβ + ... + iβ - 1})` to
`qβ (p_{iβ} (yβ, ..., y_{iβ-1}), p_{iβ} (y_{iβ}, ..., y_{iβ + iβ - 1}), ..., p_{iβ} (....)))`.
Then `g β f` is obtained by summing all these multilinear functions.
To formalize this, we use compositions of an integer `N`, i.e., its decompositions into
a sum `iβ + ... + iβ` of positive integers. Given such a composition `c` and two formal
multilinear series `q` and `p`, let `q.compAlongComposition p c` be the above multilinear
function. Then the `N`-th coefficient in the power series expansion of `g β f` is the sum of these
terms over all `c : Composition N`.
To complete the proof, we need to show that this power series has a positive radius of convergence.
This follows from the fact that `Composition N` has cardinality `2^(N-1)` and estimates on
the norm of `qβ` and `pβ`, which give summability. We also need to show that it indeed converges to
`g β f`. For this, we note that the composition of partial sums converges to `g β f`, and that it
corresponds to a part of the whole sum, on a subset that increases to the whole space. By
summability of the norms, this implies the overall convergence.
## Main results
* `q.comp p` is the formal composition of the formal multilinear series `q` and `p`.
* `HasFPowerSeriesAt.comp` states that if two functions `g` and `f` admit power series expansions
`q` and `p`, then `g β f` admits a power series expansion given by `q.comp p`.
* `AnalyticAt.comp` states that the composition of analytic functions is analytic.
* `FormalMultilinearSeries.comp_assoc` states that composition is associative on formal
multilinear series.
## Implementation details
The main technical difficulty is to write down things. In particular, we need to define precisely
`q.compAlongComposition p c` and to show that it is indeed a continuous multilinear
function. This requires a whole interface built on the class `Composition`. Once this is set,
the main difficulty is to reorder the sums, writing the composition of the partial sums as a sum
over some subset of `Ξ£ n, Composition n`. We need to check that the reordering is a bijection,
running over difficulties due to the dependent nature of the types under consideration, that are
controlled thanks to the interface for `Composition`.
The associativity of composition on formal multilinear series is a nontrivial result: it does not
follow from the associativity of composition of analytic functions, as there is no uniqueness for
the formal multilinear series representing a function (and also, it holds even when the radius of
convergence of the series is `0`). Instead, we give a direct proof, which amounts to reordering
double sums in a careful way. The change of variables is a canonical (combinatorial) bijection
`Composition.sigmaEquivSigmaPi` between `(Ξ£ (a : Composition n), Composition a.length)` and
`(Ξ£ (c : Composition n), Ξ (i : Fin c.length), Composition (c.blocksFun i))`, and is described
in more details below in the paragraph on associativity.
-/
noncomputable section
variable {π : Type*} {E F G H : Type*}
open Filter List
open scoped Topology NNReal ENNReal
section Topological
variable [CommRing π] [AddCommGroup E] [AddCommGroup F] [AddCommGroup G]
variable [Module π E] [Module π F] [Module π G]
variable [TopologicalSpace E] [TopologicalSpace F] [TopologicalSpace G]
/-! ### Composing formal multilinear series -/
namespace FormalMultilinearSeries
variable [IsTopologicalAddGroup E] [ContinuousConstSMul π E]
variable [IsTopologicalAddGroup F] [ContinuousConstSMul π F]
variable [IsTopologicalAddGroup G] [ContinuousConstSMul π G]
/-!
In this paragraph, we define the composition of formal multilinear series, by summing over all
possible compositions of `n`.
-/
/-- Given a formal multilinear series `p`, a composition `c` of `n` and the index `i` of a
block of `c`, we may define a function on `Fin n β E` by picking the variables in the `i`-th block
of `n`, and applying the corresponding coefficient of `p` to these variables. This function is
called `p.applyComposition c v i` for `v : Fin n β E` and `i : Fin c.length`. -/
def applyComposition (p : FormalMultilinearSeries π E F) {n : β} (c : Composition n) :
(Fin n β E) β Fin c.length β F := fun v i => p (c.blocksFun i) (v β c.embedding i)
theorem applyComposition_ones (p : FormalMultilinearSeries π E F) (n : β) :
p.applyComposition (Composition.ones n) = fun v i =>
p 1 fun _ => v (Fin.castLE (Composition.length_le _) i) := by
funext v i
apply p.congr (Composition.ones_blocksFun _ _)
intro j hjn hj1
obtain rfl : j = 0 := by omega
refine congr_arg v ?_
rw [Fin.ext_iff, Fin.coe_castLE, Composition.ones_embedding, Fin.val_mk]
theorem applyComposition_single (p : FormalMultilinearSeries π E F) {n : β} (hn : 0 < n)
(v : Fin n β E) : p.applyComposition (Composition.single n hn) v = fun _j => p n v := by
ext j
refine p.congr (by simp) fun i hi1 hi2 => ?_
dsimp
congr 1
convert Composition.single_embedding hn β¨i, hi2β© using 1
obtain β¨j_val, j_propertyβ© := j
have : j_val = 0 := le_bot_iff.1 (Nat.lt_succ_iff.1 j_property)
congr!
simp
@[simp]
theorem removeZero_applyComposition (p : FormalMultilinearSeries π E F) {n : β}
(c : Composition n) : p.removeZero.applyComposition c = p.applyComposition c := by
ext v i
simp [applyComposition, zero_lt_one.trans_le (c.one_le_blocksFun i), removeZero_of_pos]
/-- Technical lemma stating how `p.applyComposition` commutes with updating variables. This
will be the key point to show that functions constructed from `applyComposition` retain
multilinearity. -/
theorem applyComposition_update (p : FormalMultilinearSeries π E F) {n : β} (c : Composition n)
(j : Fin n) (v : Fin n β E) (z : E) :
p.applyComposition c (Function.update v j z) =
Function.update (p.applyComposition c v) (c.index j)
(p (c.blocksFun (c.index j))
(Function.update (v β c.embedding (c.index j)) (c.invEmbedding j) z)) := by
ext k
by_cases h : k = c.index j
Β· rw [h]
let r : Fin (c.blocksFun (c.index j)) β Fin n := c.embedding (c.index j)
simp only [Function.update_self]
change p (c.blocksFun (c.index j)) (Function.update v j z β r) = _
let j' := c.invEmbedding j
suffices B : Function.update v j z β r = Function.update (v β r) j' z by rw [B]
suffices C : Function.update v (r j') z β r = Function.update (v β r) j' z by
convert C; exact (c.embedding_comp_inv j).symm
exact Function.update_comp_eq_of_injective _ (c.embedding _).injective _ _
Β· simp only [h, Function.update_eq_self, Function.update_of_ne, Ne, not_false_iff]
let r : Fin (c.blocksFun k) β Fin n := c.embedding k
change p (c.blocksFun k) (Function.update v j z β r) = p (c.blocksFun k) (v β r)
suffices B : Function.update v j z β r = v β r by rw [B]
apply Function.update_comp_eq_of_not_mem_range
rwa [c.mem_range_embedding_iff']
@[simp]
theorem compContinuousLinearMap_applyComposition {n : β} (p : FormalMultilinearSeries π F G)
(f : E βL[π] F) (c : Composition n) (v : Fin n β E) :
(p.compContinuousLinearMap f).applyComposition c v = p.applyComposition c (f β v) := by
simp (config := {unfoldPartialApp := true}) [applyComposition]; rfl
end FormalMultilinearSeries
namespace ContinuousMultilinearMap
open FormalMultilinearSeries
variable [IsTopologicalAddGroup E] [ContinuousConstSMul π E]
variable [IsTopologicalAddGroup F] [ContinuousConstSMul π F]
/-- Given a formal multilinear series `p`, a composition `c` of `n` and a continuous multilinear
map `f` in `c.length` variables, one may form a continuous multilinear map in `n` variables by
applying the right coefficient of `p` to each block of the composition, and then applying `f` to
the resulting vector. It is called `f.compAlongComposition p c`. -/
def compAlongComposition {n : β} (p : FormalMultilinearSeries π E F) (c : Composition n)
(f : F [Γc.length]βL[π] G) : E [Γn]βL[π] G where
toMultilinearMap :=
MultilinearMap.mk' (fun v β¦ f (p.applyComposition c v))
(fun v i x y β¦ by simp only [applyComposition_update, map_update_add])
(fun v i c x β¦ by simp only [applyComposition_update, map_update_smul])
cont :=
f.cont.comp <|
continuous_pi fun _ => (coe_continuous _).comp <| continuous_pi fun _ => continuous_apply _
@[simp]
theorem compAlongComposition_apply {n : β} (p : FormalMultilinearSeries π E F) (c : Composition n)
(f : F [Γc.length]βL[π] G) (v : Fin n β E) :
(f.compAlongComposition p c) v = f (p.applyComposition c v) :=
rfl
end ContinuousMultilinearMap
namespace FormalMultilinearSeries
variable [IsTopologicalAddGroup E] [ContinuousConstSMul π E]
variable [IsTopologicalAddGroup F] [ContinuousConstSMul π F]
variable [IsTopologicalAddGroup G] [ContinuousConstSMul π G]
/-- Given two formal multilinear series `q` and `p` and a composition `c` of `n`, one may
form a continuous multilinear map in `n` variables by applying the right coefficient of `p` to each
block of the composition, and then applying `q c.length` to the resulting vector. It is
called `q.compAlongComposition p c`. -/
def compAlongComposition {n : β} (q : FormalMultilinearSeries π F G)
(p : FormalMultilinearSeries π E F) (c : Composition n) : (E [Γn]βL[π] G) :=
(q c.length).compAlongComposition p c
@[simp]
theorem compAlongComposition_apply {n : β} (q : FormalMultilinearSeries π F G)
(p : FormalMultilinearSeries π E F) (c : Composition n) (v : Fin n β E) :
(q.compAlongComposition p c) v = q c.length (p.applyComposition c v) :=
rfl
/-- Formal composition of two formal multilinear series. The `n`-th coefficient in the composition
is defined to be the sum of `q.compAlongComposition p c` over all compositions of
`n`. In other words, this term (as a multilinear function applied to `v_0, ..., v_{n-1}`) is
`β'_{k} β'_{iβ + ... + iβ = n} qβ (p_{i_1} (...), ..., p_{i_k} (...))`, where one puts all variables
`v_0, ..., v_{n-1}` in increasing order in the dots.
In general, the composition `q β p` only makes sense when the constant coefficient of `p` vanishes.
We give a general formula but which ignores the value of `p 0` instead.
-/
protected def comp (q : FormalMultilinearSeries π F G) (p : FormalMultilinearSeries π E F) :
FormalMultilinearSeries π E G := fun n => β c : Composition n, q.compAlongComposition p c
/-- The `0`-th coefficient of `q.comp p` is `q 0`. Since these maps are multilinear maps in zero
variables, but on different spaces, we can not state this directly, so we state it when applied to
arbitrary vectors (which have to be the zero vector). -/
theorem comp_coeff_zero (q : FormalMultilinearSeries π F G) (p : FormalMultilinearSeries π E F)
(v : Fin 0 β E) (v' : Fin 0 β F) : (q.comp p) 0 v = q 0 v' := by
let c : Composition 0 := Composition.ones 0
dsimp [FormalMultilinearSeries.comp]
have : {c} = (Finset.univ : Finset (Composition 0)) := by
apply Finset.eq_of_subset_of_card_le <;> simp [Finset.card_univ, composition_card 0]
rw [β this, Finset.sum_singleton, compAlongComposition_apply]
symm; congr! -- Porting note: needed the stronger `congr!`!
@[simp]
theorem comp_coeff_zero' (q : FormalMultilinearSeries π F G) (p : FormalMultilinearSeries π E F)
(v : Fin 0 β E) : (q.comp p) 0 v = q 0 fun _i => 0 :=
q.comp_coeff_zero p v _
/-- The `0`-th coefficient of `q.comp p` is `q 0`. When `p` goes from `E` to `E`, this can be
expressed as a direct equality -/
theorem comp_coeff_zero'' (q : FormalMultilinearSeries π E F) (p : FormalMultilinearSeries π E E) :
(q.comp p) 0 = q 0 := by ext v; exact q.comp_coeff_zero p _ _
/-- The first coefficient of a composition of formal multilinear series is the composition of the
first coefficients seen as continuous linear maps. -/
theorem comp_coeff_one (q : FormalMultilinearSeries π F G) (p : FormalMultilinearSeries π E F)
(v : Fin 1 β E) : (q.comp p) 1 v = q 1 fun _i => p 1 v := by
have : {Composition.ones 1} = (Finset.univ : Finset (Composition 1)) :=
Finset.eq_univ_of_card _ (by simp [composition_card])
simp only [FormalMultilinearSeries.comp, compAlongComposition_apply, β this,
Finset.sum_singleton]
refine q.congr (by simp) fun i hi1 hi2 => ?_
simp only [applyComposition_ones]
exact p.congr rfl fun j _hj1 hj2 => by congr! -- Porting note: needed the stronger `congr!`
/-- Only `0`-th coefficient of `q.comp p` depends on `q 0`. -/
theorem removeZero_comp_of_pos (q : FormalMultilinearSeries π F G)
(p : FormalMultilinearSeries π E F) {n : β} (hn : 0 < n) :
q.removeZero.comp p n = q.comp p n := by
ext v
simp only [FormalMultilinearSeries.comp, compAlongComposition,
ContinuousMultilinearMap.compAlongComposition_apply, ContinuousMultilinearMap.sum_apply]
refine Finset.sum_congr rfl fun c _hc => ?_
rw [removeZero_of_pos _ (c.length_pos_of_pos hn)]
@[simp]
theorem comp_removeZero (q : FormalMultilinearSeries π F G) (p : FormalMultilinearSeries π E F) :
q.comp p.removeZero = q.comp p := by ext n; simp [FormalMultilinearSeries.comp]
end FormalMultilinearSeries
end Topological
variable [NontriviallyNormedField π] [NormedAddCommGroup E] [NormedSpace π E] [NormedAddCommGroup F]
[NormedSpace π F] [NormedAddCommGroup G] [NormedSpace π G] [NormedAddCommGroup H]
[NormedSpace π H]
namespace FormalMultilinearSeries
/-- The norm of `f.compAlongComposition p c` is controlled by the product of
the norms of the relevant bits of `f` and `p`. -/
theorem compAlongComposition_bound {n : β} (p : FormalMultilinearSeries π E F) (c : Composition n)
(f : F [Γc.length]βL[π] G) (v : Fin n β E) :
βf.compAlongComposition p c vβ β€ (βfβ * β i, βp (c.blocksFun i)β) * β i : Fin n, βv iβ :=
calc
βf.compAlongComposition p c vβ = βf (p.applyComposition c v)β := rfl
_ β€ βfβ * β i, βp.applyComposition c v iβ := ContinuousMultilinearMap.le_opNorm _ _
_ β€ βfβ * β i, βp (c.blocksFun i)β * β j : Fin (c.blocksFun i), β(v β c.embedding i) jβ := by
apply mul_le_mul_of_nonneg_left _ (norm_nonneg _)
refine Finset.prod_le_prod (fun i _hi => norm_nonneg _) fun i _hi => ?_
apply ContinuousMultilinearMap.le_opNorm
_ = (βfβ * β i, βp (c.blocksFun i)β) *
β i, β j : Fin (c.blocksFun i), β(v β c.embedding i) jβ := by
rw [Finset.prod_mul_distrib, mul_assoc]
_ = (βfβ * β i, βp (c.blocksFun i)β) * β i : Fin n, βv iβ := by
rw [β c.blocksFinEquiv.prod_comp, β Finset.univ_sigma_univ, Finset.prod_sigma]
congr
/-- The norm of `q.compAlongComposition p c` is controlled by the product of
the norms of the relevant bits of `q` and `p`. -/
theorem compAlongComposition_norm {n : β} (q : FormalMultilinearSeries π F G)
(p : FormalMultilinearSeries π E F) (c : Composition n) :
βq.compAlongComposition p cβ β€ βq c.lengthβ * β i, βp (c.blocksFun i)β :=
ContinuousMultilinearMap.opNorm_le_bound (by positivity) (compAlongComposition_bound _ _ _)
theorem compAlongComposition_nnnorm {n : β} (q : FormalMultilinearSeries π F G)
(p : FormalMultilinearSeries π E F) (c : Composition n) :
βq.compAlongComposition p cββ β€ βq c.lengthββ * β i, βp (c.blocksFun i)ββ := by
rw [β NNReal.coe_le_coe]; push_cast; exact q.compAlongComposition_norm p c
/-!
### The identity formal power series
We will now define the identity power series, and show that it is a neutral element for left and
right composition.
-/
section
variable (π E)
/-- The identity formal multilinear series, with all coefficients equal to `0` except for `n = 1`
where it is (the continuous multilinear version of) the identity. We allow an arbitrary
constant coefficient `x`. -/
def id (x : E) : FormalMultilinearSeries π E E
| 0 => ContinuousMultilinearMap.uncurry0 π _ x
| 1 => (continuousMultilinearCurryFin1 π E E).symm (ContinuousLinearMap.id π E)
| _ => 0
@[simp] theorem id_apply_zero (x : E) (v : Fin 0 β E) :
(FormalMultilinearSeries.id π E x) 0 v = x := rfl
/-- The first coefficient of `id π E` is the identity. -/
@[simp]
theorem id_apply_one (x : E) (v : Fin 1 β E) : (FormalMultilinearSeries.id π E x) 1 v = v 0 :=
rfl
/-- The `n`th coefficient of `id π E` is the identity when `n = 1`. We state this in a dependent
way, as it will often appear in this form. -/
theorem id_apply_one' (x : E) {n : β} (h : n = 1) (v : Fin n β E) :
(id π E x) n v = v β¨0, h.symm βΈ zero_lt_oneβ© := by
subst n
apply id_apply_one
/-- For `n β 1`, the `n`-th coefficient of `id π E` is zero, by definition. -/
@[simp]
theorem id_apply_of_one_lt (x : E) {n : β} (h : 1 < n) :
(FormalMultilinearSeries.id π E x) n = 0 := by
match n with
| 0 => contradiction
| 1 => contradiction
| n + 2 => rfl
end
@[simp]
theorem comp_id (p : FormalMultilinearSeries π E F) (x : E) : p.comp (id π E x) = p := by
ext1 n
dsimp [FormalMultilinearSeries.comp]
rw [Finset.sum_eq_single (Composition.ones n)]
Β· show compAlongComposition p (id π E x) (Composition.ones n) = p n
ext v
rw [compAlongComposition_apply]
apply p.congr (Composition.ones_length n)
intros
rw [applyComposition_ones]
refine congr_arg v ?_
rw [Fin.ext_iff, Fin.coe_castLE, Fin.val_mk]
Β· show
β b : Composition n,
b β Finset.univ β b β Composition.ones n β compAlongComposition p (id π E x) b = 0
intro b _ hb
obtain β¨k, hk, lt_kβ© : β (k : β), k β Composition.blocks b β§ 1 < k :=
Composition.ne_ones_iff.1 hb
obtain β¨i, hiβ© : β (i : Fin b.blocks.length), b.blocks[i] = k :=
List.get_of_mem hk
let j : Fin b.length := β¨i.val, b.blocks_length βΈ i.propβ©
have A : 1 < b.blocksFun j := by convert lt_k
ext v
rw [compAlongComposition_apply, ContinuousMultilinearMap.zero_apply]
apply ContinuousMultilinearMap.map_coord_zero _ j
dsimp [applyComposition]
rw [id_apply_of_one_lt _ _ _ A, ContinuousMultilinearMap.zero_apply]
Β· simp
@[simp]
theorem id_comp (p : FormalMultilinearSeries π E F) (v0 : Fin 0 β E) :
(id π F (p 0 v0)).comp p = p := by
ext1 n
obtain rfl | n_pos := n.eq_zero_or_pos
Β· ext v
simp only [comp_coeff_zero', id_apply_zero]
congr with i
exact i.elim0
Β· dsimp [FormalMultilinearSeries.comp]
rw [Finset.sum_eq_single (Composition.single n n_pos)]
Β· show compAlongComposition (id π F (p 0 v0)) p (Composition.single n n_pos) = p n
ext v
rw [compAlongComposition_apply, id_apply_one' _ _ _ (Composition.single_length n_pos)]
dsimp [applyComposition]
refine p.congr rfl fun i him hin => congr_arg v <| ?_
ext; simp
Β· show
β b : Composition n, b β Finset.univ β b β Composition.single n n_pos β
compAlongComposition (id π F (p 0 v0)) p b = 0
intro b _ hb
have A : 1 < b.length := by
have : b.length β 1 := by simpa [Composition.eq_single_iff_length] using hb
have : 0 < b.length := Composition.length_pos_of_pos b n_pos
omega
ext v
rw [compAlongComposition_apply, id_apply_of_one_lt _ _ _ A,
ContinuousMultilinearMap.zero_apply, ContinuousMultilinearMap.zero_apply]
Β· simp
/-- Variant of `id_comp` in which the zero coefficient is given by an equality hypothesis instead
of a definitional equality. Useful for rewriting or simplifying out in some situations. -/
theorem id_comp' (p : FormalMultilinearSeries π E F) (x : F) (v0 : Fin 0 β E) (h : x = p 0 v0) :
(id π F x).comp p = p := by
simp [h]
/-! ### Summability properties of the composition of formal power series -/
section
/-- If two formal multilinear series have positive radius of convergence, then the terms appearing
in the definition of their composition are also summable (when multiplied by a suitable positive
geometric term). -/
theorem comp_summable_nnreal (q : FormalMultilinearSeries π F G) (p : FormalMultilinearSeries π E F)
(hq : 0 < q.radius) (hp : 0 < p.radius) :
β r > (0 : ββ₯0),
Summable fun i : Ξ£ n, Composition n => βq.compAlongComposition p i.2ββ * r ^ i.1 := by
/- This follows from the fact that the growth rate of `βqββ` and `βpββ` is at most geometric,
giving a geometric bound on each `βq.compAlongComposition p opβ`, together with the
fact that there are `2^(n-1)` compositions of `n`, giving at most a geometric loss. -/
rcases ENNReal.lt_iff_exists_nnreal_btwn.1 (lt_min zero_lt_one hq) with β¨rq, rq_pos, hrqβ©
rcases ENNReal.lt_iff_exists_nnreal_btwn.1 (lt_min zero_lt_one hp) with β¨rp, rp_pos, hrpβ©
simp only [lt_min_iff, ENNReal.coe_lt_one_iff, ENNReal.coe_pos] at hrp hrq rp_pos rq_pos
obtain β¨Cq, _hCq0, hCqβ© : β Cq > 0, β n, βq nββ * rq ^ n β€ Cq :=
q.nnnorm_mul_pow_le_of_lt_radius hrq.2
obtain β¨Cp, hCp1, hCpβ© : β Cp β₯ 1, β n, βp nββ * rp ^ n β€ Cp := by
rcases p.nnnorm_mul_pow_le_of_lt_radius hrp.2 with β¨Cp, -, hCpβ©
exact β¨max Cp 1, le_max_right _ _, fun n => (hCp n).trans (le_max_left _ _)β©
let r0 : ββ₯0 := (4 * Cp)β»ΒΉ
have r0_pos : 0 < r0 := inv_pos.2 (mul_pos zero_lt_four (zero_lt_one.trans_le hCp1))
set r : ββ₯0 := rp * rq * r0
have r_pos : 0 < r := mul_pos (mul_pos rp_pos rq_pos) r0_pos
have I :
β i : Ξ£ n : β, Composition n, βq.compAlongComposition p i.2ββ * r ^ i.1 β€ Cq / 4 ^ i.1 := by
rintro β¨n, cβ©
have A := calc
βq c.lengthββ * rq ^ n β€ βq c.lengthββ * rq ^ c.length :=
mul_le_mul' le_rfl (pow_le_pow_of_le_one rq.2 hrq.1.le c.length_le)
_ β€ Cq := hCq _
have B := calc
(β i, βp (c.blocksFun i)ββ) * rp ^ n = β i, βp (c.blocksFun i)ββ * rp ^ c.blocksFun i := by
simp only [Finset.prod_mul_distrib, Finset.prod_pow_eq_pow_sum, c.sum_blocksFun]
_ β€ β _i : Fin c.length, Cp := Finset.prod_le_prod' fun i _ => hCp _
_ = Cp ^ c.length := by simp
_ β€ Cp ^ n := pow_right_monoβ hCp1 c.length_le
calc
βq.compAlongComposition p cββ * r ^ n β€
(βq c.lengthββ * β i, βp (c.blocksFun i)ββ) * r ^ n :=
mul_le_mul' (q.compAlongComposition_nnnorm p c) le_rfl
_ = βq c.lengthββ * rq ^ n * ((β i, βp (c.blocksFun i)ββ) * rp ^ n) * r0 ^ n := by
ring
_ β€ Cq * Cp ^ n * r0 ^ n := mul_le_mul' (mul_le_mul' A B) le_rfl
_ = Cq / 4 ^ n := by
simp only [r0]
field_simp [mul_pow, (zero_lt_one.trans_le hCp1).ne']
ring
refine β¨r, r_pos, NNReal.summable_of_le I ?_β©
simp_rw [div_eq_mul_inv]
refine Summable.mul_left _ ?_
have : β n : β, HasSum (fun c : Composition n => (4 ^ n : ββ₯0)β»ΒΉ) (2 ^ (n - 1) / 4 ^ n) := by
intro n
convert hasSum_fintype fun c : Composition n => (4 ^ n : ββ₯0)β»ΒΉ
simp [Finset.card_univ, composition_card, div_eq_mul_inv]
refine NNReal.summable_sigma.2 β¨fun n => (this n).summable, (NNReal.summable_nat_add_iff 1).1 ?_β©
convert (NNReal.summable_geometric (NNReal.div_lt_one_of_lt one_lt_two)).mul_left (1 / 4) using 1
ext1 n
rw [(this _).tsum_eq, add_tsub_cancel_right]
field_simp [β mul_assoc, pow_succ, mul_pow, show (4 : ββ₯0) = 2 * 2 by norm_num,
mul_right_comm]
end
/-- Bounding below the radius of the composition of two formal multilinear series assuming
summability over all compositions. -/
theorem le_comp_radius_of_summable (q : FormalMultilinearSeries π F G)
(p : FormalMultilinearSeries π E F) (r : ββ₯0)
(hr : Summable fun i : Ξ£ n, Composition n => βq.compAlongComposition p i.2ββ * r ^ i.1) :
(r : ββ₯0β) β€ (q.comp p).radius := by
refine
le_radius_of_bound_nnreal _
(β' i : Ξ£ n, Composition n, βcompAlongComposition q p i.sndββ * r ^ i.fst) fun n => ?_
calc
βFormalMultilinearSeries.comp q p nββ * r ^ n β€
β' c : Composition n, βcompAlongComposition q p cββ * r ^ n := by
rw [tsum_fintype, β Finset.sum_mul]
exact mul_le_mul' (nnnorm_sum_le _ _) le_rfl
_ β€ β' i : Ξ£ n : β, Composition n, βcompAlongComposition q p i.sndββ * r ^ i.fst :=
NNReal.tsum_comp_le_tsum_of_inj hr sigma_mk_injective
/-!
### Composing analytic functions
Now, we will prove that the composition of the partial sums of `q` and `p` up to order `N` is
given by a sum over some large subset of `Ξ£ n, Composition n` of `q.compAlongComposition p`, to
deduce that the series for `q.comp p` indeed converges to `g β f` when `q` is a power series for
`g` and `p` is a power series for `f`.
This proof is a big reindexing argument of a sum. Since it is a bit involved, we define first
the source of the change of variables (`compPartialSumSource`), its target
(`compPartialSumTarget`) and the change of variables itself (`compChangeOfVariables`) before
giving the main statement in `comp_partialSum`. -/
/-- Source set in the change of variables to compute the composition of partial sums of formal
power series.
See also `comp_partialSum`. -/
def compPartialSumSource (m M N : β) : Finset (Ξ£ n, Fin n β β) :=
Finset.sigma (Finset.Ico m M) (fun n : β => Fintype.piFinset fun _i : Fin n => Finset.Ico 1 N :)
@[simp]
theorem mem_compPartialSumSource_iff (m M N : β) (i : Ξ£ n, Fin n β β) :
i β compPartialSumSource m M N β
(m β€ i.1 β§ i.1 < M) β§ β a : Fin i.1, 1 β€ i.2 a β§ i.2 a < N := by
simp only [compPartialSumSource, Finset.mem_Ico, Fintype.mem_piFinset, Finset.mem_sigma]
/-- Change of variables appearing to compute the composition of partial sums of formal
power series -/
def compChangeOfVariables (m M N : β) (i : Ξ£ n, Fin n β β) (hi : i β compPartialSumSource m M N) :
Ξ£ n, Composition n := by
rcases i with β¨n, fβ©
rw [mem_compPartialSumSource_iff] at hi
refine β¨β j, f j, ofFn fun a => f a, fun {i} hi' => ?_, by simp [sum_ofFn]β©
obtain β¨j, rflβ© : β j : Fin n, f j = i := by rwa [mem_ofFn', Set.mem_range] at hi'
exact (hi.2 j).1
@[simp]
theorem compChangeOfVariables_length (m M N : β) {i : Ξ£ n, Fin n β β}
(hi : i β compPartialSumSource m M N) :
Composition.length (compChangeOfVariables m M N i hi).2 = i.1 := by
rcases i with β¨k, blocks_funβ©
dsimp [compChangeOfVariables]
simp only [Composition.length, map_ofFn, length_ofFn]
theorem compChangeOfVariables_blocksFun (m M N : β) {i : Ξ£ n, Fin n β β}
(hi : i β compPartialSumSource m M N) (j : Fin i.1) :
(compChangeOfVariables m M N i hi).2.blocksFun
β¨j, (compChangeOfVariables_length m M N hi).symm βΈ j.2β© =
i.2 j := by
rcases i with β¨n, fβ©
dsimp [Composition.blocksFun, Composition.blocks, compChangeOfVariables]
simp only [map_ofFn, List.getElem_ofFn, Function.comp_apply]
/-- Target set in the change of variables to compute the composition of partial sums of formal
power series, here given a a set. -/
def compPartialSumTargetSet (m M N : β) : Set (Ξ£ n, Composition n) :=
{i | m β€ i.2.length β§ i.2.length < M β§ β j : Fin i.2.length, i.2.blocksFun j < N}
theorem compPartialSumTargetSet_image_compPartialSumSource (m M N : β)
(i : Ξ£ n, Composition n) (hi : i β compPartialSumTargetSet m M N) :
β (j : _) (hj : j β compPartialSumSource m M N), compChangeOfVariables m M N j hj = i := by
rcases i with β¨n, cβ©
refine β¨β¨c.length, c.blocksFunβ©, ?_, ?_β©
Β· simp only [compPartialSumTargetSet, Set.mem_setOf_eq] at hi
simp only [mem_compPartialSumSource_iff, hi.left, hi.right, true_and, and_true]
exact fun a => c.one_le_blocks' _
Β· dsimp [compChangeOfVariables]
rw [Composition.sigma_eq_iff_blocks_eq]
simp only [Composition.blocksFun, Composition.blocks, Subtype.coe_eta]
conv_rhs => rw [β List.ofFn_get c.blocks]
/-- Target set in the change of variables to compute the composition of partial sums of formal
power series, here given a a finset.
See also `comp_partialSum`. -/
def compPartialSumTarget (m M N : β) : Finset (Ξ£ n, Composition n) :=
Set.Finite.toFinset <|
((Finset.finite_toSet _).dependent_image _).subset <|
compPartialSumTargetSet_image_compPartialSumSource m M N
@[simp]
theorem mem_compPartialSumTarget_iff {m M N : β} {a : Ξ£ n, Composition n} :
a β compPartialSumTarget m M N β
m β€ a.2.length β§ a.2.length < M β§ β j : Fin a.2.length, a.2.blocksFun j < N := by
simp [compPartialSumTarget, compPartialSumTargetSet]
/-- `compChangeOfVariables m M N` is a bijection between `compPartialSumSource m M N`
and `compPartialSumTarget m M N`, yielding equal sums for functions that correspond to each
other under the bijection. As `compChangeOfVariables m M N` is a dependent function, stating
that it is a bijection is not directly possible, but the consequence on sums can be stated
more easily. -/
theorem compChangeOfVariables_sum {Ξ± : Type*} [AddCommMonoid Ξ±] (m M N : β)
(f : (Ξ£ n : β, Fin n β β) β Ξ±) (g : (Ξ£ n, Composition n) β Ξ±)
(h : β (e) (he : e β compPartialSumSource m M N), f e = g (compChangeOfVariables m M N e he)) :
β e β compPartialSumSource m M N, f e = β e β compPartialSumTarget m M N, g e := by
apply Finset.sum_bij (compChangeOfVariables m M N)
-- We should show that the correspondence we have set up is indeed a bijection
-- between the index sets of the two sums.
-- 1 - show that the image belongs to `compPartialSumTarget m N N`
Β· rintro β¨k, blocks_funβ© H
rw [mem_compPartialSumSource_iff] at H
simp only [mem_compPartialSumTarget_iff, Composition.length, Composition.blocks, H.left,
map_ofFn, length_ofFn, true_and, compChangeOfVariables]
intro j
simp only [Composition.blocksFun, (H.right _).right, List.get_ofFn]
-- 2 - show that the map is injective
Β· rintro β¨k, blocks_funβ© H β¨k', blocks_fun'β© H' heq
obtain rfl : k = k' := by
have := (compChangeOfVariables_length m M N H).symm
rwa [heq, compChangeOfVariables_length] at this
congr
funext i
calc
blocks_fun i = (compChangeOfVariables m M N _ H).2.blocksFun _ :=
(compChangeOfVariables_blocksFun m M N H i).symm
_ = (compChangeOfVariables m M N _ H').2.blocksFun _ := by
apply Composition.blocksFun_congr <;>
first | rw [heq] | rfl
_ = blocks_fun' i := compChangeOfVariables_blocksFun m M N H' i
-- 3 - show that the map is surjective
Β· intro i hi
apply compPartialSumTargetSet_image_compPartialSumSource m M N i
simpa [compPartialSumTarget] using hi
-- 4 - show that the composition gives the `compAlongComposition` application
Β· rintro β¨k, blocks_funβ© H
rw [h]
/-- The auxiliary set corresponding to the composition of partial sums asymptotically contains
all possible compositions. -/
theorem compPartialSumTarget_tendsto_prod_atTop :
Tendsto (fun (p : β Γ β) => compPartialSumTarget 0 p.1 p.2) atTop atTop := by
apply Monotone.tendsto_atTop_finset
Β· intro m n hmn a ha
have : β i, i < m.1 β i < n.1 := fun i hi => lt_of_lt_of_le hi hmn.1
have : β i, i < m.2 β i < n.2 := fun i hi => lt_of_lt_of_le hi hmn.2
aesop
Β· rintro β¨n, cβ©
simp only [mem_compPartialSumTarget_iff]
obtain β¨n, hnβ© : BddAbove ((Finset.univ.image fun i : Fin c.length => c.blocksFun i) : Set β) :=
Finset.bddAbove _
refine
β¨max n c.length + 1, bot_le, lt_of_le_of_lt (le_max_right n c.length) (lt_add_one _), fun j =>
lt_of_le_of_lt (le_trans ?_ (le_max_left _ _)) (lt_add_one _)β©
apply hn
simp only [Finset.mem_image_of_mem, Finset.mem_coe, Finset.mem_univ]
/-- The auxiliary set corresponding to the composition of partial sums asymptotically contains
all possible compositions. -/
theorem compPartialSumTarget_tendsto_atTop :
Tendsto (fun N => compPartialSumTarget 0 N N) atTop atTop := by
apply Tendsto.comp compPartialSumTarget_tendsto_prod_atTop tendsto_atTop_diagonal
/-- Composing the partial sums of two multilinear series coincides with the sum over all
compositions in `compPartialSumTarget 0 N N`. This is precisely the motivation for the
definition of `compPartialSumTarget`. -/
theorem comp_partialSum (q : FormalMultilinearSeries π F G) (p : FormalMultilinearSeries π E F)
(M N : β) (z : E) :
q.partialSum M (β i β Finset.Ico 1 N, p i fun _j => z) =
β i β compPartialSumTarget 0 M N, q.compAlongComposition p i.2 fun _j => z := by
-- we expand the composition, using the multilinearity of `q` to expand along each coordinate.
suffices H :
(β n β Finset.range M,
β r β Fintype.piFinset fun i : Fin n => Finset.Ico 1 N,
q n fun i : Fin n => p (r i) fun _j => z) =
β i β compPartialSumTarget 0 M N, q.compAlongComposition p i.2 fun _j => z by
simpa only [FormalMultilinearSeries.partialSum, ContinuousMultilinearMap.map_sum_finset] using H
-- rewrite the first sum as a big sum over a sigma type, in the finset
-- `compPartialSumTarget 0 N N`
rw [Finset.range_eq_Ico, Finset.sum_sigma']
-- use `compChangeOfVariables_sum`, saying that this change of variables respects sums
apply compChangeOfVariables_sum 0 M N
rintro β¨k, blocks_funβ© H
apply congr _ (compChangeOfVariables_length 0 M N H).symm
intros
rw [β compChangeOfVariables_blocksFun 0 M N H, applyComposition, Function.comp_def]
end FormalMultilinearSeries
open FormalMultilinearSeries
/-- If two functions `g` and `f` have power series `q` and `p` respectively at `f x` and `x`, within
two sets `s` and `t` such that `f` maps `s` to `t`, then `g β f` admits the power
series `q.comp p` at `x` within `s`. -/
theorem HasFPowerSeriesWithinAt.comp {g : F β G} {f : E β F} {q : FormalMultilinearSeries π F G}
{p : FormalMultilinearSeries π E F} {x : E} {t : Set F} {s : Set E}
(hg : HasFPowerSeriesWithinAt g q t (f x)) (hf : HasFPowerSeriesWithinAt f p s x)
(hs : Set.MapsTo f s t) : HasFPowerSeriesWithinAt (g β f) (q.comp p) s x := by
/- Consider `rf` and `rg` such that `f` and `g` have power series expansion on the disks
of radius `rf` and `rg`. -/
rcases hg with β¨rg, Hgβ©
rcases hf with β¨rf, Hfβ©
-- The terms defining `q.comp p` are geometrically summable in a disk of some radius `r`.
rcases q.comp_summable_nnreal p Hg.radius_pos Hf.radius_pos with β¨r, r_pos : 0 < r, hrβ©
/- We will consider `y` which is smaller than `r` and `rf`, and also small enough that
`f (x + y)` is close enough to `f x` to be in the disk where `g` is well behaved. Let
`min (r, rf, Ξ΄)` be this new radius. -/
obtain β¨Ξ΄, Ξ΄pos, hΞ΄β© :
β Ξ΄ : ββ₯0β, 0 < Ξ΄ β§ β {z : E}, z β insert x s β© EMetric.ball x Ξ΄
β f z β insert (f x) t β© EMetric.ball (f x) rg := by
have : insert (f x) t β© EMetric.ball (f x) rg β π[insert (f x) t] (f x) := by
apply inter_mem_nhdsWithin
exact EMetric.ball_mem_nhds _ Hg.r_pos
have := Hf.analyticWithinAt.continuousWithinAt_insert.tendsto_nhdsWithin (hs.insert x) this
rcases EMetric.mem_nhdsWithin_iff.1 this with β¨Ξ΄, Ξ΄pos, HΞ΄β©
exact β¨Ξ΄, Ξ΄pos, fun {z} hz => HΞ΄ (by rwa [Set.inter_comm])β©
let rf' := min rf Ξ΄
have min_pos : 0 < min rf' r := by
simp only [rf', r_pos, Hf.r_pos, Ξ΄pos, lt_min_iff, ENNReal.coe_pos, and_self_iff]
/- We will show that `g β f` admits the power series `q.comp p` in the disk of
radius `min (r, rf', Ξ΄)`. -/
refine β¨min rf' r, ?_β©
refine
β¨le_trans (min_le_right rf' r) (FormalMultilinearSeries.le_comp_radius_of_summable q p r hr),
min_pos, fun {y} h'y hy β¦ ?_β©
/- Let `y` satisfy `βyβ < min (r, rf', Ξ΄)`. We want to show that `g (f (x + y))` is the sum of
`q.comp p` applied to `y`. -/
-- First, check that `y` is small enough so that estimates for `f` and `g` apply.
have y_mem : y β EMetric.ball (0 : E) rf :=
(EMetric.ball_subset_ball (le_trans (min_le_left _ _) (min_le_left _ _))) hy
have fy_mem : f (x + y) β insert (f x) t β© EMetric.ball (f x) rg := by
apply hΞ΄
have : y β EMetric.ball (0 : E) Ξ΄ :=
(EMetric.ball_subset_ball (le_trans (min_le_left _ _) (min_le_right _ _))) hy
simpa [-Set.mem_insert_iff, edist_eq_enorm_sub, h'y]
/- Now the proof starts. To show that the sum of `q.comp p` at `y` is `g (f (x + y))`,
we will write `q.comp p` applied to `y` as a big sum over all compositions.
Since the sum is summable, to get its convergence it suffices to get
the convergence along some increasing sequence of sets.
We will use the sequence of sets `compPartialSumTarget 0 n n`,
along which the sum is exactly the composition of the partial sums of `q` and `p`, by design.
To show that it converges to `g (f (x + y))`, pointwise convergence would not be enough,
but we have uniform convergence to save the day. -/
-- First step: the partial sum of `p` converges to `f (x + y)`.
have A : Tendsto (fun n β¦ (n, β a β Finset.Ico 1 n, p a fun _ β¦ y))
atTop (atTop ΓΛ’ π (f (x + y) - f x)) := by
apply Tendsto.prodMk tendsto_id
have L : βαΆ n in atTop, (β a β Finset.range n, p a fun _b β¦ y) - f x
= β a β Finset.Ico 1 n, p a fun _b β¦ y := by
rw [eventually_atTop]
refine β¨1, fun n hn => ?_β©
symm
rw [eq_sub_iff_add_eq', Finset.range_eq_Ico, β Hf.coeff_zero fun _i => y,
Finset.sum_eq_sum_Ico_succ_bot hn]
have :
Tendsto (fun n => (β a β Finset.range n, p a fun _b => y) - f x) atTop
(π (f (x + y) - f x)) :=
(Hf.hasSum h'y y_mem).tendsto_sum_nat.sub tendsto_const_nhds
exact Tendsto.congr' L this
-- Second step: the composition of the partial sums of `q` and `p` converges to `g (f (x + y))`.
have B : Tendsto (fun n => q.partialSum n (β a β Finset.Ico 1 n, p a fun _b β¦ y)) atTop
(π (g (f (x + y)))) := by
-- we use the fact that the partial sums of `q` converge to `g (f (x + y))`, uniformly on a
-- neighborhood of `f (x + y)`.
have : Tendsto (fun (z : β Γ F) β¦ q.partialSum z.1 z.2)
(atTop ΓΛ’ π (f (x + y) - f x)) (π (g (f x + (f (x + y) - f x)))) := by
apply Hg.tendsto_partialSum_prod (y := f (x + y) - f x)
Β· simpa [edist_eq_enorm_sub] using fy_mem.2
Β· simpa using fy_mem.1
simpa using this.comp A
-- Third step: the sum over all compositions in `compPartialSumTarget 0 n n` converges to
-- `g (f (x + y))`. As this sum is exactly the composition of the partial sum, this is a direct
-- consequence of the second step
have C :
Tendsto
(fun n => β i β compPartialSumTarget 0 n n, q.compAlongComposition p i.2 fun _j => y)
atTop (π (g (f (x + y)))) := by
simpa [comp_partialSum] using B
-- Fourth step: the sum over all compositions is `g (f (x + y))`. This follows from the
-- convergence along a subsequence proved in the third step, and the fact that the sum is Cauchy
-- thanks to the summability properties.
have D :
HasSum (fun i : Ξ£ n, Composition n => q.compAlongComposition p i.2 fun _j => y)
(g (f (x + y))) :=
haveI cau :
CauchySeq fun s : Finset (Ξ£ n, Composition n) =>
β i β s, q.compAlongComposition p i.2 fun _j => y := by
apply cauchySeq_finset_of_norm_bounded _ (NNReal.summable_coe.2 hr) _
simp only [coe_nnnorm, NNReal.coe_mul, NNReal.coe_pow]
rintro β¨n, cβ©
calc
β(compAlongComposition q p c) fun _j : Fin n => yβ β€
βcompAlongComposition q p cβ * β _j : Fin n, βyβ := by
apply ContinuousMultilinearMap.le_opNorm
_ β€ βcompAlongComposition q p cβ * (r : β) ^ n := by
rw [Finset.prod_const, Finset.card_fin]
gcongr
rw [EMetric.mem_ball, edist_zero_eq_enorm] at hy
have := le_trans (le_of_lt hy) (min_le_right _ _)
rwa [enorm_le_coe, β NNReal.coe_le_coe, coe_nnnorm] at this
tendsto_nhds_of_cauchySeq_of_subseq cau compPartialSumTarget_tendsto_atTop C
-- Fifth step: the sum over `n` of `q.comp p n` can be expressed as a particular resummation of
-- the sum over all compositions, by grouping together the compositions of the same
-- integer `n`. The convergence of the whole sum therefore implies the converence of the sum
-- of `q.comp p n`
have E : HasSum (fun n => (q.comp p) n fun _j => y) (g (f (x + y))) := by
apply D.sigma
intro n
simp only [compAlongComposition_apply, FormalMultilinearSeries.comp,
ContinuousMultilinearMap.sum_apply]
exact hasSum_fintype _
rw [Function.comp_apply]
exact E
/-- If two functions `g` and `f` have power series `q` and `p` respectively at `f x` and `x`,
then `g β f` admits the power series `q.comp p` at `x` within `s`. -/
theorem HasFPowerSeriesAt.comp {g : F β G} {f : E β F} {q : FormalMultilinearSeries π F G}
{p : FormalMultilinearSeries π E F} {x : E}
(hg : HasFPowerSeriesAt g q (f x)) (hf : HasFPowerSeriesAt f p x) :
HasFPowerSeriesAt (g β f) (q.comp p) x := by
rw [β hasFPowerSeriesWithinAt_univ] at hf hg β’
apply hg.comp hf (by simp)
/-- If two functions `g` and `f` are analytic respectively at `f x` and `x`, within
two sets `s` and `t` such that `f` maps `s` to `t`, then `g β f` is analytic at `x` within `s`. -/
theorem AnalyticWithinAt.comp {g : F β G} {f : E β F} {x : E} {t : Set F} {s : Set E}
(hg : AnalyticWithinAt π g t (f x)) (hf : AnalyticWithinAt π f s x) (h : Set.MapsTo f s t) :
AnalyticWithinAt π (g β f) s x := by
let β¨_q, hqβ© := hg
let β¨_p, hpβ© := hf
exact (hq.comp hp h).analyticWithinAt
/-- Version of `AnalyticWithinAt.comp` where point equality is a separate hypothesis. -/
theorem AnalyticWithinAt.comp_of_eq {g : F β G} {f : E β F} {y : F} {x : E} {t : Set F} {s : Set E}
(hg : AnalyticWithinAt π g t y) (hf : AnalyticWithinAt π f s x) (h : Set.MapsTo f s t)
(hy : f x = y) :
AnalyticWithinAt π (g β f) s x := by
rw [β hy] at hg
exact hg.comp hf h
lemma AnalyticOn.comp {f : F β G} {g : E β F} {s : Set F}
{t : Set E} (hf : AnalyticOn π f s) (hg : AnalyticOn π g t) (h : Set.MapsTo g t s) :
AnalyticOn π (f β g) t :=
fun x m β¦ (hf _ (h m)).comp (hg x m) h
/-- If two functions `g` and `f` are analytic respectively at `f x` and `x`, then `g β f` is
analytic at `x`. -/
@[fun_prop]
theorem AnalyticAt.comp {g : F β G} {f : E β F} {x : E} (hg : AnalyticAt π g (f x))
(hf : AnalyticAt π f x) : AnalyticAt π (g β f) x := by
rw [β analyticWithinAt_univ] at hg hf β’
apply hg.comp hf (by simp)
/-- If two functions `g` and `f` are analytic respectively at `f x` and `x`, then `g β f` is
analytic at `x`. -/
@[fun_prop]
theorem AnalyticAt.comp' {g : F β G} {f : E β F} {x : E} (hg : AnalyticAt π g (f x))
(hf : AnalyticAt π f x) : AnalyticAt π (fun z β¦ g (f z)) x :=
hg.comp hf
/-- Version of `AnalyticAt.comp` where point equality is a separate hypothesis. -/
theorem AnalyticAt.comp_of_eq {g : F β G} {f : E β F} {y : F} {x : E} (hg : AnalyticAt π g y)
(hf : AnalyticAt π f x) (hy : f x = y) : AnalyticAt π (g β f) x := by
rw [β hy] at hg
exact hg.comp hf
/-- Version of `AnalyticAt.comp` where point equality is a separate hypothesis. -/
theorem AnalyticAt.comp_of_eq' {g : F β G} {f : E β F} {y : F} {x : E} (hg : AnalyticAt π g y)
(hf : AnalyticAt π f x) (hy : f x = y) : AnalyticAt π (fun z β¦ g (f z)) x := by
apply hg.comp_of_eq hf hy
theorem AnalyticAt.comp_analyticWithinAt {g : F β G} {f : E β F} {x : E} {s : Set E}
(hg : AnalyticAt π g (f x)) (hf : AnalyticWithinAt π f s x) :
AnalyticWithinAt π (g β f) s x := by
rw [β analyticWithinAt_univ] at hg
exact hg.comp hf (Set.mapsTo_univ _ _)
theorem AnalyticAt.comp_analyticWithinAt_of_eq {g : F β G} {f : E β F} {x : E} {y : F} {s : Set E}
(hg : AnalyticAt π g y) (hf : AnalyticWithinAt π f s x) (h : f x = y) :
AnalyticWithinAt π (g β f) s x := by
rw [β h] at hg
exact hg.comp_analyticWithinAt hf
/-- If two functions `g` and `f` are analytic respectively on `s.image f` and `s`, then `g β f` is
analytic on `s`. -/
theorem AnalyticOnNhd.comp' {s : Set E} {g : F β G} {f : E β F} (hg : AnalyticOnNhd π g (s.image f))
(hf : AnalyticOnNhd π f s) : AnalyticOnNhd π (g β f) s :=
fun z hz => (hg (f z) (Set.mem_image_of_mem f hz)).comp (hf z hz)
theorem AnalyticOnNhd.comp {s : Set E} {t : Set F} {g : F β G} {f : E β F}
(hg : AnalyticOnNhd π g t) (hf : AnalyticOnNhd π f s) (st : Set.MapsTo f s t) :
AnalyticOnNhd π (g β f) s :=
comp' (mono hg (Set.mapsTo'.mp st)) hf
lemma AnalyticOnNhd.comp_analyticOn {f : F β G} {g : E β F} {s : Set F}
{t : Set E} (hf : AnalyticOnNhd π f s) (hg : AnalyticOn π g t) (h : Set.MapsTo g t s) :
AnalyticOn π (f β g) t :=
fun x m β¦ (hf _ (h m)).comp_analyticWithinAt (hg x m)
/-!
### Associativity of the composition of formal multilinear series
In this paragraph, we prove the associativity of the composition of formal power series.
By definition,
```
(r.comp q).comp p n v
= β_{iβ + ... + iβ = n} (r.comp q)β (p_{iβ} (vβ, ..., v_{iβ -1}), p_{iβ} (...), ..., p_{iβ}(...))
= β_{a : Composition n} (r.comp q) a.length (applyComposition p a v)
```
decomposing `r.comp q` in the same way, we get
```
(r.comp q).comp p n v
= β_{a : Composition n} β_{b : Composition a.length}
r b.length (applyComposition q b (applyComposition p a v))
```
On the other hand,
```
r.comp (q.comp p) n v = β_{c : Composition n} r c.length (applyComposition (q.comp p) c v)
```
Here, `applyComposition (q.comp p) c v` is a vector of length `c.length`, whose `i`-th term is
given by `(q.comp p) (c.blocksFun i) (v_l, v_{l+1}, ..., v_{m-1})` where `{l, ..., m-1}` is the
`i`-th block in the composition `c`, of length `c.blocksFun i` by definition. To compute this term,
we expand it as `β_{dα΅’ : Composition (c.blocksFun i)} q dα΅’.length (applyComposition p dα΅’ v')`,
where `v' = (v_l, v_{l+1}, ..., v_{m-1})`. Therefore, we get
```
r.comp (q.comp p) n v =
β_{c : Composition n} β_{dβ : Composition (c.blocksFun 0),
..., d_{c.length - 1} : Composition (c.blocksFun (c.length - 1))}
r c.length (fun i β¦ q dα΅’.length (applyComposition p dα΅’ v'α΅’))
```
To show that these terms coincide, we need to explain how to reindex the sums to put them in
bijection (and then the terms we are summing will correspond to each other). Suppose we have a
composition `a` of `n`, and a composition `b` of `a.length`. Then `b` indicates how to group
together some blocks of `a`, giving altogether `b.length` blocks of blocks. These blocks of blocks
can be called `dβ, ..., d_{a.length - 1}`, and one obtains a composition `c` of `n` by saying that
each `dα΅’` is one single block. Conversely, if one starts from `c` and the `dα΅’`s, one can concatenate
the `dα΅’`s to obtain a composition `a` of `n`, and register the lengths of the `dα΅’`s in a composition
`b` of `a.length`.
An example might be enlightening. Suppose `a = [2, 2, 3, 4, 2]`. It is a composition of
length 5 of 13. The content of the blocks may be represented as `0011222333344`.
Now take `b = [2, 3]` as a composition of `a.length = 5`. It says that the first 2 blocks of `a`
should be merged, and the last 3 blocks of `a` should be merged, giving a new composition of `13`
made of two blocks of length `4` and `9`, i.e., `c = [4, 9]`. But one can also remember that
the new first block was initially made of two blocks of size `2`, so `dβ = [2, 2]`, and the new
second block was initially made of three blocks of size `3`, `4` and `2`, so `dβ = [3, 4, 2]`.
This equivalence is called `Composition.sigmaEquivSigmaPi n` below.
We start with preliminary results on compositions, of a very specialized nature, then define the
equivalence `Composition.sigmaEquivSigmaPi n`, and we deduce finally the associativity of
composition of formal multilinear series in `FormalMultilinearSeries.comp_assoc`.
-/
namespace Composition
variable {n : β}
/-- Rewriting equality in the dependent type `Ξ£ (a : Composition n), Composition a.length)` in
non-dependent terms with lists, requiring that the blocks coincide. -/
theorem sigma_composition_eq_iff (i j : Ξ£ a : Composition n, Composition a.length) :
i = j β i.1.blocks = j.1.blocks β§ i.2.blocks = j.2.blocks := by
refine β¨by rintro rfl; exact β¨rfl, rflβ©, ?_β©
rcases i with β¨a, bβ©
rcases j with β¨a', b'β©
rintro β¨h, h'β©
obtain rfl : a = a' := by ext1; exact h
obtain rfl : b = b' := by ext1; exact h'
rfl
/-- Rewriting equality in the dependent type
`Ξ£ (c : Composition n), Ξ (i : Fin c.length), Composition (c.blocksFun i)` in
non-dependent terms with lists, requiring that the lists of blocks coincide. -/
theorem sigma_pi_composition_eq_iff
(u v : Ξ£ c : Composition n, β i : Fin c.length, Composition (c.blocksFun i)) :
u = v β (ofFn fun i => (u.2 i).blocks) = ofFn fun i => (v.2 i).blocks := by
refine β¨fun H => by rw [H], fun H => ?_β©
rcases u with β¨a, bβ©
rcases v with β¨a', b'β©
dsimp at H
obtain rfl : a = a' := by
ext1
have :
map List.sum (ofFn fun i : Fin (Composition.length a) => (b i).blocks) =
map List.sum (ofFn fun i : Fin (Composition.length a') => (b' i).blocks) := by
rw [H]
simp only [map_ofFn] at this
change
(ofFn fun i : Fin (Composition.length a) => (b i).blocks.sum) =
ofFn fun i : Fin (Composition.length a') => (b' i).blocks.sum at this
simpa [Composition.blocks_sum, Composition.ofFn_blocksFun] using this
ext1
Β· rfl
Β· simp only [heq_eq_eq, ofFn_inj] at H β’
ext1 i
ext1
exact congrFun H i
/-- When `a` is a composition of `n` and `b` is a composition of `a.length`, `a.gather b` is the
composition of `n` obtained by gathering all the blocks of `a` corresponding to a block of `b`.
For instance, if `a = [6, 5, 3, 5, 2]` and `b = [2, 3]`, one should gather together
the first two blocks of `a` and its last three blocks, giving `a.gather b = [11, 10]`. -/
def gather (a : Composition n) (b : Composition a.length) : Composition n where
blocks := (a.blocks.splitWrtComposition b).map sum
blocks_pos := by
rw [forall_mem_map]
intro j hj
suffices H : β i β j, 1 β€ i from calc
0 < j.length := length_pos_of_mem_splitWrtComposition hj
_ β€ j.sum := length_le_sum_of_one_le _ H
intro i hi
apply a.one_le_blocks
rw [β a.blocks.flatten_splitWrtComposition b]
exact mem_flatten_of_mem hj hi
blocks_sum := by rw [β sum_flatten, flatten_splitWrtComposition, a.blocks_sum]
theorem length_gather (a : Composition n) (b : Composition a.length) :
length (a.gather b) = b.length :=
show (map List.sum (a.blocks.splitWrtComposition b)).length = b.blocks.length by
rw [length_map, length_splitWrtComposition]
/-- An auxiliary function used in the definition of `sigmaEquivSigmaPi` below, associating to
two compositions `a` of `n` and `b` of `a.length`, and an index `i` bounded by the length of
`a.gather b`, the subcomposition of `a` made of those blocks belonging to the `i`-th block of
`a.gather b`. -/
def sigmaCompositionAux (a : Composition n) (b : Composition a.length)
(i : Fin (a.gather b).length) : Composition ((a.gather b).blocksFun i) where
| blocks :=
(a.blocks.splitWrtComposition b)[i.val]'(by
rw [length_splitWrtComposition, β length_gather]; exact i.2)
blocks_pos {i} hi :=
a.blocks_pos
(by
rw [β a.blocks.flatten_splitWrtComposition b]
| Mathlib/Analysis/Analytic/Composition.lean | 1,028 | 1,034 |
/-
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.Finset.Basic
import Mathlib.Data.Finset.Image
import Mathlib.Data.Multiset.Fold
/-!
# The fold operation for a commutative associative operation over a finset.
-/
assert_not_exists Monoid
namespace Finset
open Multiset
variable {Ξ± Ξ² Ξ³ : Type*}
/-! ### fold -/
section Fold
variable (op : Ξ² β Ξ² β Ξ²) [hc : Std.Commutative op] [ha : Std.Associative op]
local notation a " * " b => op a b
/-- `fold op b f s` folds the commutative associative operation `op` over the
`f`-image of `s`, i.e. `fold (+) b f {1,2,3} = f 1 + f 2 + f 3 + b`. -/
def fold (b : Ξ²) (f : Ξ± β Ξ²) (s : Finset Ξ±) : Ξ² :=
(s.1.map f).fold op b
variable {op} {f : Ξ± β Ξ²} {b : Ξ²} {s : Finset Ξ±} {a : Ξ±}
@[simp]
theorem fold_empty : (β
: Finset Ξ±).fold op b f = b :=
rfl
@[simp]
theorem fold_cons (h : a β s) : (cons a s h).fold op b f = f a * s.fold op b f := by
dsimp only [fold]
rw [cons_val, Multiset.map_cons, fold_cons_left]
@[simp]
theorem fold_insert [DecidableEq Ξ±] (h : a β s) :
(insert a s).fold op b f = f a * s.fold op b f := by
unfold fold
rw [insert_val, ndinsert_of_not_mem h, Multiset.map_cons, fold_cons_left]
@[simp]
theorem fold_singleton : ({a} : Finset Ξ±).fold op b f = f a * b :=
rfl
@[simp]
theorem fold_map {g : Ξ³ βͺ Ξ±} {s : Finset Ξ³} : (s.map g).fold op b f = s.fold op b (f β g) := by
simp only [fold, map, Multiset.map_map]
@[simp]
theorem fold_image [DecidableEq Ξ±] {g : Ξ³ β Ξ±} {s : Finset Ξ³}
(H : β x β s, β y β s, g x = g y β x = y) : (s.image g).fold op b f = s.fold op b (f β g) := by
simp only [fold, image_val_of_injOn H, Multiset.map_map]
@[congr]
theorem fold_congr {g : Ξ± β Ξ²} (H : β x β s, f x = g x) : s.fold op b f = s.fold op b g := by
rw [fold, fold, map_congr rfl H]
theorem fold_op_distrib {f g : Ξ± β Ξ²} {bβ bβ : Ξ²} :
(s.fold op (bβ * bβ) fun x => f x * g x) = s.fold op bβ f * s.fold op bβ g := by
simp only [fold, fold_distrib]
theorem fold_const [hd : Decidable (s = β
)] (c : Ξ²) (h : op c (op b c) = op b c) :
Finset.fold op b (fun _ => c) s = if s = β
then b else op b c := by
classical
induction' s using Finset.induction_on with x s hx IH generalizing hd
Β· simp
Β· simp only [Finset.fold_insert hx, IH, if_false, Finset.insert_ne_empty]
split_ifs
Β· rw [hc.comm]
Β· exact h
theorem fold_hom {op' : Ξ³ β Ξ³ β Ξ³} [Std.Commutative op'] [Std.Associative op'] {m : Ξ² β Ξ³}
(hm : β x y, m (op x y) = op' (m x) (m y)) :
(s.fold op' (m b) fun x => m (f x)) = m (s.fold op b f) := by
rw [fold, fold, β Multiset.fold_hom op hm, Multiset.map_map]
simp only [Function.comp_apply]
theorem fold_disjUnion {sβ sβ : Finset Ξ±} {bβ bβ : Ξ²} (h) :
(sβ.disjUnion sβ h).fold op (bβ * bβ) f = sβ.fold op bβ f * sβ.fold op bβ f :=
(congr_arg _ <| Multiset.map_add _ _ _).trans (Multiset.fold_add _ _ _ _ _)
theorem fold_union_inter [DecidableEq Ξ±] {sβ sβ : Finset Ξ±} {bβ bβ : Ξ²} :
((sβ βͺ sβ).fold op bβ f * (sβ β© sβ).fold op bβ f) = sβ.fold op bβ f * sβ.fold op bβ f := by
unfold fold
rw [β fold_add op, β Multiset.map_add, union_val, inter_val, union_add_inter, Multiset.map_add,
hc.comm, fold_add]
@[simp]
theorem fold_insert_idem [DecidableEq Ξ±] [hi : Std.IdempotentOp op] :
(insert a s).fold op b f = f a * s.fold op b f := by
by_cases h : a β s
Β· rw [β insert_erase h]
simp [β ha.assoc, hi.idempotent]
Β· apply fold_insert h
theorem fold_image_idem [DecidableEq Ξ±] {g : Ξ³ β Ξ±} {s : Finset Ξ³} [hi : Std.IdempotentOp op] :
(image g s).fold op b f = s.fold op b (f β g) := by
induction' s using Finset.cons_induction with x xs hx ih
Β· rw [fold_empty, image_empty, fold_empty]
Β· haveI := Classical.decEq Ξ³
rw [fold_cons, cons_eq_insert, image_insert, fold_insert_idem, ih]
simp only [Function.comp_apply]
/-- A stronger version of `Finset.fold_ite`, but relies on
an explicit proof of idempotency on the seed element, rather
than relying on typeclass idempotency over the whole type. -/
theorem fold_ite' {g : Ξ± β Ξ²} (hb : op b b = b) (p : Ξ± β Prop) [DecidablePred p] :
Finset.fold op b (fun i => ite (p i) (f i) (g i)) s =
op (Finset.fold op b f (s.filter p)) (Finset.fold op b g (s.filter fun i => Β¬p i)) := by
classical
induction' s using Finset.induction_on with x s hx IH
Β· simp [hb]
Β· simp only [Finset.fold_insert hx]
split_ifs with h
Β· have : x β Finset.filter p s := by simp [hx]
simp [Finset.filter_insert, h, Finset.fold_insert this, ha.assoc, IH]
Β· have : x β Finset.filter (fun i => Β¬ p i) s := by simp [hx]
simp [Finset.filter_insert, h, Finset.fold_insert this, IH, β ha.assoc, hc.comm]
/-- A weaker version of `Finset.fold_ite'`,
relying on typeclass idempotency over the whole type,
instead of solely on the seed element.
However, this is easier to use because it does not generate side goals. -/
theorem fold_ite [Std.IdempotentOp op] {g : Ξ± β Ξ²} (p : Ξ± β Prop) [DecidablePred p] :
Finset.fold op b (fun i => ite (p i) (f i) (g i)) s =
op (Finset.fold op b f (s.filter p)) (Finset.fold op b g (s.filter fun i => Β¬p i)) :=
fold_ite' (Std.IdempotentOp.idempotent _) _
theorem fold_op_rel_iff_and {r : Ξ² β Ξ² β Prop} (hr : β {x y z}, r x (op y z) β r x y β§ r x z)
{c : Ξ²} : r c (s.fold op b f) β r c b β§ β x β s, r c (f x) := by
classical
induction' s using Finset.induction_on with a s ha IH
Β· simp
rw [Finset.fold_insert ha, hr, IH, β and_assoc, @and_comm (r c (f a)), and_assoc]
apply and_congr Iff.rfl
constructor
Β· rintro β¨hβ, hββ©
intro b hb
rw [Finset.mem_insert] at hb
rcases hb with (rfl | hb) <;> solve_by_elim
Β· intro h
constructor
Β· exact h a (Finset.mem_insert_self _ _)
Β· exact fun b hb => h b <| Finset.mem_insert_of_mem hb
theorem fold_op_rel_iff_or {r : Ξ² β Ξ² β Prop} (hr : β {x y z}, r x (op y z) β r x y β¨ r x z)
{c : Ξ²} : r c (s.fold op b f) β r c b β¨ β x β s, r c (f x) := by
classical
induction' s using Finset.induction_on with a s ha IH
Β· simp
rw [Finset.fold_insert ha, hr, IH, β or_assoc, @or_comm (r c (f a)), or_assoc]
apply or_congr Iff.rfl
constructor
Β· rintro (hβ | β¨x, hx, hββ©)
Β· use a
simp [hβ]
Β· refine β¨x, by simp [hx], hββ©
Β· rintro β¨x, hx, hβ©
exact (mem_insert.mp hx).imp (fun hx => by rwa [hx] at h) (fun hx => β¨x, hx, hβ©)
@[simp]
theorem fold_union_empty_singleton [DecidableEq Ξ±] (s : Finset Ξ±) :
Finset.fold (Β· βͺ Β·) β
singleton s = s := by
induction' s using Finset.induction_on with a s has ih
Β· simp only [fold_empty]
Β· rw [fold_insert has, ih, insert_eq]
theorem fold_sup_bot_singleton [DecidableEq Ξ±] (s : Finset Ξ±) :
Finset.fold (Β· β Β·) β₯ singleton s = s :=
fold_union_empty_singleton s
section Order
variable [LinearOrder Ξ²] (c : Ξ²)
theorem le_fold_min : c β€ s.fold min b f β c β€ b β§ β x β s, c β€ f x :=
fold_op_rel_iff_and le_min_iff
theorem fold_min_le : s.fold min b f β€ c β b β€ c β¨ β x β s, f x β€ c := by
show _ β₯ _ β _
apply fold_op_rel_iff_or
intro x y z
show _ β€ _ β _
exact min_le_iff
theorem lt_fold_min : c < s.fold min b f β c < b β§ β x β s, c < f x :=
fold_op_rel_iff_and lt_min_iff
theorem fold_min_lt : s.fold min b f < c β b < c β¨ β x β s, f x < c := by
show _ > _ β _
apply fold_op_rel_iff_or
intro x y z
show _ < _ β _
exact min_lt_iff
theorem fold_max_le : s.fold max b f β€ c β b β€ c β§ β x β s, f x β€ c := by
show _ β₯ _ β _
apply fold_op_rel_iff_and
intro x y z
show _ β€ _ β _
exact max_le_iff
theorem le_fold_max : c β€ s.fold max b f β c β€ b β¨ β x β s, c β€ f x :=
fold_op_rel_iff_or le_max_iff
theorem fold_max_lt : s.fold max b f < c β b < c β§ β x β s, f x < c := by
show _ > _ β _
apply fold_op_rel_iff_and
intro x y z
show _ < _ β _
| exact max_lt_iff
theorem lt_fold_max : c < s.fold max b f β c < b β¨ β x β s, c < f x :=
fold_op_rel_iff_or lt_max_iff
end Order
| Mathlib/Data/Finset/Fold.lean | 223 | 228 |
/-
Copyright (c) 2018 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin
-/
import Mathlib.Algebra.BigOperators.Expect
import Mathlib.Algebra.Order.BigOperators.Ring.Finset
import Mathlib.Algebra.Order.Field.Canonical
import Mathlib.Algebra.Order.Nonneg.Floor
import Mathlib.Data.Real.Pointwise
import Mathlib.Data.NNReal.Defs
import Mathlib.Order.ConditionallyCompleteLattice.Group
/-!
# Basic results on nonnegative real numbers
This file contains all results on `NNReal` that do not directly follow from its basic structure.
As a consequence, it is a bit of a random collection of results, and is a good target for cleanup.
## Notations
This file uses `ββ₯0` as a localized notation for `NNReal`.
-/
assert_not_exists Star
open Function
open scoped BigOperators
namespace NNReal
noncomputable instance : FloorSemiring ββ₯0 := Nonneg.floorSemiring
@[simp, norm_cast]
theorem coe_indicator {Ξ±} (s : Set Ξ±) (f : Ξ± β ββ₯0) (a : Ξ±) :
((s.indicator f a : ββ₯0) : β) = s.indicator (fun x => β(f x)) a :=
(toRealHom : ββ₯0 β+ β).map_indicator _ _ _
@[norm_cast]
theorem coe_list_sum (l : List ββ₯0) : ((l.sum : ββ₯0) : β) = (l.map (β)).sum :=
map_list_sum toRealHom l
@[norm_cast]
theorem coe_list_prod (l : List ββ₯0) : ((l.prod : ββ₯0) : β) = (l.map (β)).prod :=
map_list_prod toRealHom l
@[norm_cast]
theorem coe_multiset_sum (s : Multiset ββ₯0) : ((s.sum : ββ₯0) : β) = (s.map (β)).sum :=
map_multiset_sum toRealHom s
@[norm_cast]
theorem coe_multiset_prod (s : Multiset ββ₯0) : ((s.prod : ββ₯0) : β) = (s.map (β)).prod :=
map_multiset_prod toRealHom s
variable {ΞΉ : Type*} {s : Finset ΞΉ} {f : ΞΉ β β}
@[simp, norm_cast]
theorem coe_sum (s : Finset ΞΉ) (f : ΞΉ β ββ₯0) : β i β s, f i = β i β s, (f i : β) :=
map_sum toRealHom _ _
@[simp, norm_cast]
lemma coe_expect (s : Finset ΞΉ) (f : ΞΉ β ββ₯0) : πΌ i β s, f i = πΌ i β s, (f i : β) :=
map_expect toRealHom ..
theorem _root_.Real.toNNReal_sum_of_nonneg (hf : β i β s, 0 β€ f i) :
Real.toNNReal (β a β s, f a) = β a β s, Real.toNNReal (f a) := by
rw [β coe_inj, NNReal.coe_sum, Real.coe_toNNReal _ (Finset.sum_nonneg hf)]
exact Finset.sum_congr rfl fun x hxs => by rw [Real.coe_toNNReal _ (hf x hxs)]
@[simp, norm_cast]
theorem coe_prod (s : Finset ΞΉ) (f : ΞΉ β ββ₯0) : β(β a β s, f a) = β a β s, (f a : β) :=
map_prod toRealHom _ _
theorem _root_.Real.toNNReal_prod_of_nonneg (hf : β a, a β s β 0 β€ f a) :
Real.toNNReal (β a β s, f a) = β a β s, Real.toNNReal (f a) := by
rw [β coe_inj, NNReal.coe_prod, Real.coe_toNNReal _ (Finset.prod_nonneg hf)]
exact Finset.prod_congr rfl fun x hxs => by rw [Real.coe_toNNReal _ (hf x hxs)]
theorem le_iInf_add_iInf {ΞΉ ΞΉ' : Sort*} [Nonempty ΞΉ] [Nonempty ΞΉ'] {f : ΞΉ β ββ₯0} {g : ΞΉ' β ββ₯0}
{a : ββ₯0} (h : β i j, a β€ f i + g j) : a β€ (β¨
i, f i) + β¨
j, g j := by
rw [β NNReal.coe_le_coe, NNReal.coe_add, coe_iInf, coe_iInf]
exact le_ciInf_add_ciInf h
theorem mul_finset_sup {Ξ±} (r : ββ₯0) (s : Finset Ξ±) (f : Ξ± β ββ₯0) :
r * s.sup f = s.sup fun a => r * f a :=
Finset.comp_sup_eq_sup_comp _ (NNReal.mul_sup r) (mul_zero r)
theorem finset_sup_mul {Ξ±} (s : Finset Ξ±) (f : Ξ± β ββ₯0) (r : ββ₯0) :
s.sup f * r = s.sup fun a => f a * r :=
Finset.comp_sup_eq_sup_comp (Β· * r) (fun x y => NNReal.sup_mul x y r) (zero_mul r)
theorem finset_sup_div {Ξ±} {f : Ξ± β ββ₯0} {s : Finset Ξ±} (r : ββ₯0) :
s.sup f / r = s.sup fun a => f a / r := by simp only [div_eq_inv_mul, mul_finset_sup]
open Real
section Sub
/-!
### Lemmas about subtraction
In this section we provide a few lemmas about subtraction that do not fit well into any other
typeclass. For lemmas about subtraction and addition see lemmas about `OrderedSub` in the file
`Mathlib.Algebra.Order.Sub.Basic`. See also `mul_tsub` and `tsub_mul`.
-/
theorem sub_div (a b c : ββ₯0) : (a - b) / c = a / c - b / c :=
tsub_div _ _ _
end Sub
section Csupr
open Set
variable {ΞΉ : Sort*} {f : ΞΉ β ββ₯0}
theorem iInf_mul (f : ΞΉ β ββ₯0) (a : ββ₯0) : iInf f * a = β¨
i, f i * a := by
rw [β coe_inj, NNReal.coe_mul, coe_iInf, coe_iInf]
exact Real.iInf_mul_of_nonneg (NNReal.coe_nonneg _) _
theorem mul_iInf (f : ΞΉ β ββ₯0) (a : ββ₯0) : a * iInf f = β¨
i, a * f i := by
simpa only [mul_comm] using iInf_mul f a
theorem mul_iSup (f : ΞΉ β ββ₯0) (a : ββ₯0) : (a * β¨ i, f i) = β¨ i, a * f i := by
rw [β coe_inj, NNReal.coe_mul, NNReal.coe_iSup, NNReal.coe_iSup]
exact Real.mul_iSup_of_nonneg (NNReal.coe_nonneg _) _
theorem iSup_mul (f : ΞΉ β ββ₯0) (a : ββ₯0) : (β¨ i, f i) * a = β¨ i, f i * a := by
rw [mul_comm, mul_iSup]
simp_rw [mul_comm]
theorem iSup_div (f : ΞΉ β ββ₯0) (a : ββ₯0) : (β¨ i, f i) / a = β¨ i, f i / a := by
simp only [div_eq_mul_inv, iSup_mul]
theorem mul_iSup_le {a : ββ₯0} {g : ββ₯0} {h : ΞΉ β ββ₯0} (H : β j, g * h j β€ a) : g * iSup h β€ a := by
rw [mul_iSup]
exact ciSup_le' H
theorem iSup_mul_le {a : ββ₯0} {g : ΞΉ β ββ₯0} {h : ββ₯0} (H : β i, g i * h β€ a) : iSup g * h β€ a := by
rw [iSup_mul]
exact ciSup_le' H
theorem iSup_mul_iSup_le {a : ββ₯0} {g h : ΞΉ β ββ₯0} (H : β i j, g i * h j β€ a) :
iSup g * iSup h β€ a :=
iSup_mul_le fun _ => mul_iSup_le <| H _
variable [Nonempty ΞΉ]
theorem le_mul_iInf {a : ββ₯0} {g : ββ₯0} {h : ΞΉ β ββ₯0} (H : β j, a β€ g * h j) : a β€ g * iInf h := by
rw [mul_iInf]
exact le_ciInf H
theorem le_iInf_mul {a : ββ₯0} {g : ΞΉ β ββ₯0} {h : ββ₯0} (H : β i, a β€ g i * h) : a β€ iInf g * h := by
rw [iInf_mul]
exact le_ciInf H
theorem le_iInf_mul_iInf {a : ββ₯0} {g h : ΞΉ β ββ₯0} (H : β i j, a β€ g i * h j) :
a β€ iInf g * iInf h :=
le_iInf_mul fun i => le_mul_iInf <| H i
end Csupr
end NNReal
| Mathlib/Data/NNReal/Basic.lean | 1,104 | 1,105 | |
/-
Copyright (c) 2020 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov
-/
import Mathlib.Analysis.SpecialFunctions.Pow.NNReal
import Mathlib.Analysis.SpecialFunctions.Pow.Continuity
import Mathlib.Analysis.SumOverResidueClass
/-!
# Convergence of `p`-series
In this file we prove that the series `β' k in β, 1 / k ^ p` converges if and only if `p > 1`.
The proof is based on the
[Cauchy condensation test](https://en.wikipedia.org/wiki/Cauchy_condensation_test): `β k, f k`
converges if and only if so does `β k, 2 ^ k f (2 ^ k)`. We prove this test in
`NNReal.summable_condensed_iff` and `summable_condensed_iff_of_nonneg`, then use it to prove
`summable_one_div_rpow`. After this transformation, a `p`-series turns into a geometric series.
## Tags
p-series, Cauchy condensation test
-/
/-!
### SchlΓΆmilch's generalization of the Cauchy condensation test
In this section we prove the SchlΓΆmilch's generalization of the Cauchy condensation test:
for a strictly increasing `u : β β β` with ratio of successive differences bounded and an
antitone `f : β β ββ₯0` or `f : β β β`, `β k, f k` converges if and only if
so does `β k, (u (k + 1) - u k) * f (u k)`. Instead of giving a monolithic proof, we split it
into a series of lemmas with explicit estimates of partial sums of each series in terms of the
partial sums of the other series.
-/
/--
A sequence `u` has the property that its ratio of successive differences is bounded
when there is a positive real number `C` such that, for all n β β,
(u (n + 2) - u (n + 1)) β€ C * (u (n + 1) - u n)
-/
def SuccDiffBounded (C : β) (u : β β β) : Prop :=
β n : β, u (n + 2) - u (n + 1) β€ C β’ (u (n + 1) - u n)
namespace Finset
variable {M : Type*} [AddCommMonoid M] [PartialOrder M] [IsOrderedAddMonoid M]
{f : β β M} {u : β β β}
theorem le_sum_schlomilch' (hf : β β¦m nβ¦, 0 < m β m β€ n β f n β€ f m) (h_pos : β n, 0 < u n)
(hu : Monotone u) (n : β) :
(β k β Ico (u 0) (u n), f k) β€ β k β range n, (u (k + 1) - u k) β’ f (u k) := by
induction n with
| zero => simp
| succ n ihn =>
suffices (β k β Ico (u n) (u (n + 1)), f k) β€ (u (n + 1) - u n) β’ f (u n) by
rw [sum_range_succ, β sum_Ico_consecutive]
Β· exact add_le_add ihn this
exacts [hu n.zero_le, hu n.le_succ]
have : β k β Ico (u n) (u (n + 1)), f k β€ f (u n) := fun k hk =>
hf (Nat.succ_le_of_lt (h_pos n)) (mem_Ico.mp hk).1
convert sum_le_sum this
simp [pow_succ, mul_two]
theorem le_sum_condensed' (hf : β β¦m nβ¦, 0 < m β m β€ n β f n β€ f m) (n : β) :
(β k β Ico 1 (2 ^ n), f k) β€ β k β range n, 2 ^ k β’ f (2 ^ k) := by
convert le_sum_schlomilch' hf (fun n => pow_pos zero_lt_two n)
(fun m n hm => pow_right_monoβ one_le_two hm) n using 2
simp [pow_succ, mul_two, two_mul]
theorem le_sum_schlomilch (hf : β β¦m nβ¦, 0 < m β m β€ n β f n β€ f m) (h_pos : β n, 0 < u n)
(hu : Monotone u) (n : β) :
(β k β range (u n), f k) β€
β k β range (u 0), f k + β k β range n, (u (k + 1) - u k) β’ f (u k) := by
convert add_le_add_left (le_sum_schlomilch' hf h_pos hu n) (β k β range (u 0), f k)
rw [β sum_range_add_sum_Ico _ (hu n.zero_le)]
theorem le_sum_condensed (hf : β β¦m nβ¦, 0 < m β m β€ n β f n β€ f m) (n : β) :
(β k β range (2 ^ n), f k) β€ f 0 + β k β range n, 2 ^ k β’ f (2 ^ k) := by
convert add_le_add_left (le_sum_condensed' hf n) (f 0)
rw [β sum_range_add_sum_Ico _ n.one_le_two_pow, sum_range_succ, sum_range_zero, zero_add]
theorem sum_schlomilch_le' (hf : β β¦m nβ¦, 1 < m β m β€ n β f n β€ f m) (h_pos : β n, 0 < u n)
(hu : Monotone u) (n : β) :
(β k β range n, (u (k + 1) - u k) β’ f (u (k + 1))) β€ β k β Ico (u 0 + 1) (u n + 1), f k := by
induction n with
| zero => simp
| succ n ihn =>
suffices (u (n + 1) - u n) β’ f (u (n + 1)) β€ β k β Ico (u n + 1) (u (n + 1) + 1), f k by
rw [sum_range_succ, β sum_Ico_consecutive]
exacts [add_le_add ihn this,
(add_le_add_right (hu n.zero_le) _ : u 0 + 1 β€ u n + 1),
add_le_add_right (hu n.le_succ) _]
have : β k β Ico (u n + 1) (u (n + 1) + 1), f (u (n + 1)) β€ f k := fun k hk =>
hf (Nat.lt_of_le_of_lt (Nat.succ_le_of_lt (h_pos n)) <| (Nat.lt_succ_of_le le_rfl).trans_le
(mem_Ico.mp hk).1) (Nat.le_of_lt_succ <| (mem_Ico.mp hk).2)
convert sum_le_sum this
simp [pow_succ, mul_two]
theorem sum_condensed_le' (hf : β β¦m nβ¦, 1 < m β m β€ n β f n β€ f m) (n : β) :
(β k β range n, 2 ^ k β’ f (2 ^ (k + 1))) β€ β k β Ico 2 (2 ^ n + 1), f k := by
convert sum_schlomilch_le' hf (fun n => pow_pos zero_lt_two n)
(fun m n hm => pow_right_monoβ one_le_two hm) n using 2
simp [pow_succ, mul_two, two_mul]
theorem sum_schlomilch_le {C : β} (hf : β β¦m nβ¦, 1 < m β m β€ n β f n β€ f m) (h_pos : β n, 0 < u n)
(h_nonneg : β n, 0 β€ f n) (hu : Monotone u) (h_succ_diff : SuccDiffBounded C u) (n : β) :
β k β range (n + 1), (u (k + 1) - u k) β’ f (u k) β€
(u 1 - u 0) β’ f (u 0) + C β’ β k β Ico (u 0 + 1) (u n + 1), f k := by
rw [sum_range_succ', add_comm]
gcongr
suffices β k β range n, (u (k + 2) - u (k + 1)) β’ f (u (k + 1)) β€
C β’ β k β range n, ((u (k + 1) - u k) β’ f (u (k + 1))) by
refine this.trans (nsmul_le_nsmul_right ?_ _)
exact sum_schlomilch_le' hf h_pos hu n
have : β k β range n, (u (k + 2) - u (k + 1)) β’ f (u (k + 1)) β€
C β’ ((u (k + 1) - u k) β’ f (u (k + 1))) := by
intro k _
rw [smul_smul]
gcongr
Β· exact h_nonneg (u (k + 1))
exact mod_cast h_succ_diff k
convert sum_le_sum this
simp [smul_sum]
theorem sum_condensed_le (hf : β β¦m nβ¦, 1 < m β m β€ n β f n β€ f m) (n : β) :
(β k β range (n + 1), 2 ^ k β’ f (2 ^ k)) β€ f 1 + 2 β’ β k β Ico 2 (2 ^ n + 1), f k := by
convert add_le_add_left (nsmul_le_nsmul_right (sum_condensed_le' hf n) 2) (f 1)
simp [sum_range_succ', add_comm, pow_succ', mul_nsmul', sum_nsmul]
end Finset
namespace ENNReal
open Filter Finset
variable {u : β β β} {f : β β ββ₯0β}
open NNReal in
theorem le_tsum_schlomilch (hf : β β¦m nβ¦, 0 < m β m β€ n β f n β€ f m) (h_pos : β n, 0 < u n)
(hu : StrictMono u) :
β' k , f k β€ β k β range (u 0), f k + β' k : β, (u (k + 1) - u k) * f (u k) := by
rw [ENNReal.tsum_eq_iSup_nat' hu.tendsto_atTop]
refine iSup_le fun n =>
(Finset.le_sum_schlomilch hf h_pos hu.monotone n).trans (add_le_add_left ?_ _)
have (k : β) : (u (k + 1) - u k : ββ₯0β) = (u (k + 1) - (u k : β) : β) := by
simp [NNReal.coe_sub (Nat.cast_le (Ξ± := ββ₯0).mpr <| (hu k.lt_succ_self).le)]
simp only [nsmul_eq_mul, this]
apply ENNReal.sum_le_tsum
theorem le_tsum_condensed (hf : β β¦m nβ¦, 0 < m β m β€ n β f n β€ f m) :
β' k, f k β€ f 0 + β' k : β, 2 ^ k * f (2 ^ k) := by
rw [ENNReal.tsum_eq_iSup_nat' (Nat.tendsto_pow_atTop_atTop_of_one_lt _root_.one_lt_two)]
refine iSup_le fun n => (Finset.le_sum_condensed hf n).trans (add_le_add_left ?_ _)
simp only [nsmul_eq_mul, Nat.cast_pow, Nat.cast_two]
apply ENNReal.sum_le_tsum
theorem tsum_schlomilch_le {C : β} (hf : β β¦m nβ¦, 1 < m β m β€ n β f n β€ f m) (h_pos : β n, 0 < u n)
(h_nonneg : β n, 0 β€ f n) (hu : Monotone u) (h_succ_diff : SuccDiffBounded C u) :
β' k : β, (u (k + 1) - u k) * f (u k) β€ (u 1 - u 0) * f (u 0) + C * β' k, f k := by
rw [ENNReal.tsum_eq_iSup_nat' (tendsto_atTop_mono Nat.le_succ tendsto_id)]
refine
iSup_le fun n =>
le_trans ?_
(add_le_add_left
(mul_le_mul_of_nonneg_left (ENNReal.sum_le_tsum <| Finset.Ico (u 0 + 1) (u n + 1)) ?_) _)
Β· simpa using Finset.sum_schlomilch_le hf h_pos h_nonneg hu h_succ_diff n
Β· exact zero_le _
theorem tsum_condensed_le (hf : β β¦m nβ¦, 1 < m β m β€ n β f n β€ f m) :
(β' k : β, 2 ^ k * f (2 ^ k)) β€ f 1 + 2 * β' k, f k := by
rw [ENNReal.tsum_eq_iSup_nat' (tendsto_atTop_mono Nat.le_succ tendsto_id), two_mul, β two_nsmul]
refine
iSup_le fun n =>
le_trans ?_
(add_le_add_left
(nsmul_le_nsmul_right (ENNReal.sum_le_tsum <| Finset.Ico 2 (2 ^ n + 1)) _) _)
simpa using Finset.sum_condensed_le hf n
end ENNReal
namespace NNReal
open Finset
open ENNReal in
/-- for a series of `NNReal` version. -/
theorem summable_schlomilch_iff {C : β} {u : β β β} {f : β β ββ₯0}
(hf : β β¦m nβ¦, 0 < m β m β€ n β f n β€ f m)
(h_pos : β n, 0 < u n) (hu_strict : StrictMono u)
(hC_nonzero : C β 0) (h_succ_diff : SuccDiffBounded C u) :
(Summable fun k : β => (u (k + 1) - (u k : ββ₯0)) * f (u k)) β Summable f := by
simp only [β tsum_coe_ne_top_iff_summable, Ne, not_iff_not, ENNReal.coe_mul]
constructor <;> intro h
Β· replace hf : β m n, 1 < m β m β€ n β (f n : ββ₯0β) β€ f m := fun m n hm hmn =>
ENNReal.coe_le_coe.2 (hf (zero_lt_one.trans hm) hmn)
have h_nonneg : β n, 0 β€ (f n : ββ₯0β) := fun n =>
ENNReal.coe_le_coe.2 (f n).2
obtain hC := tsum_schlomilch_le hf h_pos h_nonneg hu_strict.monotone h_succ_diff
simpa [add_eq_top, mul_ne_top, mul_eq_top, hC_nonzero] using eq_top_mono hC h
Β· replace hf : β m n, 0 < m β m β€ n β (f n : ββ₯0β) β€ f m := fun m n hm hmn =>
ENNReal.coe_le_coe.2 (hf hm hmn)
have : β k β range (u 0), (f k : ββ₯0β) β β := sum_ne_top.2 fun a _ => coe_ne_top
simpa [h, add_eq_top, this] using le_tsum_schlomilch hf h_pos hu_strict
open ENNReal in
theorem summable_condensed_iff {f : β β ββ₯0} (hf : β β¦m nβ¦, 0 < m β m β€ n β f n β€ f m) :
(Summable fun k : β => (2 : ββ₯0) ^ k * f (2 ^ k)) β Summable f := by
have h_succ_diff : SuccDiffBounded 2 (2 ^ Β·) := by
intro n
simp [pow_succ, mul_two, two_mul]
convert summable_schlomilch_iff hf (pow_pos zero_lt_two) (pow_right_strictMonoβ _root_.one_lt_two)
two_ne_zero h_succ_diff
simp [pow_succ, mul_two, two_mul]
end NNReal
open NNReal in
/-- for series of nonnegative real numbers. -/
theorem summable_schlomilch_iff_of_nonneg {C : β} {u : β β β} {f : β β β} (h_nonneg : β n, 0 β€ f n)
(hf : β β¦m nβ¦, 0 < m β m β€ n β f n β€ f m) (h_pos : β n, 0 < u n)
(hu_strict : StrictMono u) (hC_nonzero : C β 0) (h_succ_diff : SuccDiffBounded C u) :
(Summable fun k : β => (u (k + 1) - (u k : β)) * f (u k)) β Summable f := by
lift f to β β ββ₯0 using h_nonneg
simp only [NNReal.coe_le_coe] at *
have (k : β) : (u (k + 1) - (u k : β)) = ((u (k + 1) : ββ₯0) - (u k : ββ₯0) : ββ₯0) := by
have := Nat.cast_le (Ξ± := ββ₯0).mpr <| (hu_strict k.lt_succ_self).le
simp [NNReal.coe_sub this]
simp_rw [this]
exact_mod_cast NNReal.summable_schlomilch_iff hf h_pos hu_strict hC_nonzero h_succ_diff
/-- Cauchy condensation test for antitone series of nonnegative real numbers. -/
theorem summable_condensed_iff_of_nonneg {f : β β β} (h_nonneg : β n, 0 β€ f n)
(h_mono : β β¦m nβ¦, 0 < m β m β€ n β f n β€ f m) :
(Summable fun k : β => (2 : β) ^ k * f (2 ^ k)) β Summable f := by
have h_succ_diff : SuccDiffBounded 2 (2 ^ Β·) := by
intro n
simp [pow_succ, mul_two, two_mul]
convert summable_schlomilch_iff_of_nonneg h_nonneg h_mono (pow_pos zero_lt_two)
(pow_right_strictMonoβ one_lt_two) two_ne_zero h_succ_diff
simp [pow_succ, mul_two, two_mul]
section p_series
/-!
### Convergence of the `p`-series
In this section we prove that for a real number `p`, the series `β' n : β, 1 / (n ^ p)` converges if
and only if `1 < p`. There are many different proofs of this fact. The proof in this file uses the
Cauchy condensation test we formalized above. This test implies that `β n, 1 / (n ^ p)` converges if
and only if `β n, 2 ^ n / ((2 ^ n) ^ p)` converges, and the latter series is a geometric series with
common ratio `2 ^ {1 - p}`. -/
namespace Real
open Filter
/-- Test for convergence of the `p`-series: the real-valued series `β' n : β, (n ^ p)β»ΒΉ` converges
if and only if `1 < p`. -/
@[simp]
theorem summable_nat_rpow_inv {p : β} :
Summable (fun n => ((n : β) ^ p)β»ΒΉ : β β β) β 1 < p := by
rcases le_or_lt 0 p with hp | hp
/- Cauchy condensation test applies only to antitone sequences, so we consider the
cases `0 β€ p` and `p < 0` separately. -/
Β· rw [β summable_condensed_iff_of_nonneg]
Β· simp_rw [Nat.cast_pow, Nat.cast_two, β rpow_natCast, β rpow_mul zero_lt_two.le, mul_comm _ p,
rpow_mul zero_lt_two.le, rpow_natCast, β inv_pow, β mul_pow,
summable_geometric_iff_norm_lt_one]
nth_rw 1 [β rpow_one 2]
rw [β division_def, β rpow_sub zero_lt_two, norm_eq_abs,
abs_of_pos (rpow_pos_of_pos zero_lt_two _), rpow_lt_one_iff zero_lt_two.le]
norm_num
Β· intro n
positivity
Β· intro m n hm hmn
gcongr
-- If `p < 0`, then `1 / n ^ p` tends to infinity, thus the series diverges.
Β· suffices Β¬Summable (fun n => ((n : β) ^ p)β»ΒΉ : β β β) by
have : Β¬1 < p := fun hpβ => hp.not_le (zero_le_one.trans hpβ.le)
simpa only [this, iff_false]
intro h
obtain β¨k : β, hkβ : ((k : β) ^ p)β»ΒΉ < 1, hkβ : k β 0β© :=
((h.tendsto_cofinite_zero.eventually (gt_mem_nhds zero_lt_one)).and
(eventually_cofinite_ne 0)).exists
apply hkβ
rw [β pos_iff_ne_zero, β @Nat.cast_pos β] at hkβ
simpa [inv_lt_oneβ (rpow_pos_of_pos hkβ _), one_lt_rpow_iff_of_pos hkβ, hp,
hp.not_lt, hkβ] using hkβ
@[simp]
theorem summable_nat_rpow {p : β} : Summable (fun n => (n : β) ^ p : β β β) β p < -1 := by
rcases neg_surjective p with β¨p, rflβ©
simp [rpow_neg]
/-- Test for convergence of the `p`-series: the real-valued series `β' n : β, 1 / n ^ p` converges
if and only if `1 < p`. -/
theorem summable_one_div_nat_rpow {p : β} :
Summable (fun n => 1 / (n : β) ^ p : β β β) β 1 < p := by
simp
/-- Test for convergence of the `p`-series: the real-valued series `β' n : β, (n ^ p)β»ΒΉ` converges
if and only if `1 < p`. -/
@[simp]
theorem summable_nat_pow_inv {p : β} :
Summable (fun n => ((n : β) ^ p)β»ΒΉ : β β β) β 1 < p := by
simp only [β rpow_natCast, summable_nat_rpow_inv, Nat.one_lt_cast]
/-- Test for convergence of the `p`-series: the real-valued series `β' n : β, 1 / n ^ p` converges
if and only if `1 < p`. -/
theorem summable_one_div_nat_pow {p : β} :
Summable (fun n => 1 / (n : β) ^ p : β β β) β 1 < p := by
simp only [one_div, Real.summable_nat_pow_inv]
/-- Summability of the `p`-series over `β€`. -/
theorem summable_one_div_int_pow {p : β} :
(Summable fun n : β€ β¦ 1 / (n : β) ^ p) β 1 < p := by
refine β¨fun h β¦ summable_one_div_nat_pow.mp (h.comp_injective Nat.cast_injective),
fun h β¦ .of_nat_of_neg (summable_one_div_nat_pow.mpr h)
(((summable_one_div_nat_pow.mpr h).mul_left <| 1 / (-1 : β) ^ p).congr fun n β¦ ?_)β©
rw [Int.cast_neg, Int.cast_natCast, neg_eq_neg_one_mul (n : β), mul_pow, mul_one_div, div_div]
theorem summable_abs_int_rpow {b : β} (hb : 1 < b) :
Summable fun n : β€ => |(n : β)| ^ (-b) := by
apply Summable.of_nat_of_neg
on_goal 2 => simp_rw [Int.cast_neg, abs_neg]
all_goals
simp_rw [Int.cast_natCast, fun n : β => abs_of_nonneg (n.cast_nonneg : 0 β€ (n : β))]
rwa [summable_nat_rpow, neg_lt_neg_iff]
/-- Harmonic series is not unconditionally summable. -/
theorem not_summable_natCast_inv : Β¬Summable (fun n => nβ»ΒΉ : β β β) := by
have : Β¬Summable (fun n => ((n : β) ^ 1)β»ΒΉ : β β β) :=
mt (summable_nat_pow_inv (p := 1)).1 (lt_irrefl 1)
simpa
/-- Harmonic series is not unconditionally summable. -/
theorem not_summable_one_div_natCast : Β¬Summable (fun n => 1 / n : β β β) := by
simpa only [inv_eq_one_div] using not_summable_natCast_inv
/-- **Divergence of the Harmonic Series** -/
theorem tendsto_sum_range_one_div_nat_succ_atTop :
Tendsto (fun n => β i β Finset.range n, (1 / (i + 1) : β)) atTop atTop := by
rw [β not_summable_iff_tendsto_nat_atTop_of_nonneg]
Β· exact_mod_cast mt (_root_.summable_nat_add_iff 1).1 not_summable_one_div_natCast
Β· exact fun i => by positivity
end Real
namespace NNReal
@[simp]
theorem summable_rpow_inv {p : β} :
Summable (fun n => ((n : ββ₯0) ^ p)β»ΒΉ : β β ββ₯0) β 1 < p := by
simp [β NNReal.summable_coe]
@[simp]
theorem summable_rpow {p : β} : Summable (fun n => (n : ββ₯0) ^ p : β β ββ₯0) β p < -1 := by
simp [β NNReal.summable_coe]
theorem summable_one_div_rpow {p : β} :
Summable (fun n => 1 / (n : ββ₯0) ^ p : β β ββ₯0) β 1 < p := by
simp
|
end NNReal
end p_series
| Mathlib/Analysis/PSeries.lean | 363 | 367 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.