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) 2020 Aaron Anderson, Jalex Stark, Kyle Miller. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Aaron Anderson, Jalex Stark, Kyle Miller, Alena Gusakov, Hunter Monroe
-/
import Mathlib.Combinatorics.SimpleGraph.Init
import Mathlib.Data.Finite.Prod
import Mathlib.Data.Rel
import Mathlib.Data.Set.Finite.Basic
import Mathlib.Data.Sym.Sym2
/-!
# Simple graphs
This module defines simple graphs on a vertex type `V` as an irreflexive symmetric relation.
## Main definitions
* `SimpleGraph` is a structure for symmetric, irreflexive relations.
* `SimpleGraph.neighborSet` is the `Set` of vertices adjacent to a given vertex.
* `SimpleGraph.commonNeighbors` is the intersection of the neighbor sets of two given vertices.
* `SimpleGraph.incidenceSet` is the `Set` of edges containing a given vertex.
* `CompleteAtomicBooleanAlgebra` instance: Under the subgraph relation, `SimpleGraph` forms a
`CompleteAtomicBooleanAlgebra`. In other words, this is the complete lattice of spanning subgraphs
of the complete graph.
## TODO
* This is the simplest notion of an unoriented graph.
This should eventually fit into a more complete combinatorics hierarchy which includes
multigraphs and directed graphs.
We begin with simple graphs in order to start learning what the combinatorics hierarchy should
look like.
-/
attribute [aesop norm unfold (rule_sets := [SimpleGraph])] Symmetric
attribute [aesop norm unfold (rule_sets := [SimpleGraph])] Irreflexive
/--
A variant of the `aesop` tactic for use in the graph library. Changes relative
to standard `aesop`:
- We use the `SimpleGraph` rule set in addition to the default rule sets.
- We instruct Aesop's `intro` rule to unfold with `default` transparency.
- We instruct Aesop to fail if it can't fully solve the goal. This allows us to
use `aesop_graph` for auto-params.
-/
macro (name := aesop_graph) "aesop_graph" c:Aesop.tactic_clause* : tactic =>
`(tactic|
aesop $c*
(config := { introsTransparency? := some .default, terminal := true })
(rule_sets := [$(Lean.mkIdent `SimpleGraph):ident]))
/--
Use `aesop_graph?` to pass along a `Try this` suggestion when using `aesop_graph`
-/
macro (name := aesop_graph?) "aesop_graph?" c:Aesop.tactic_clause* : tactic =>
`(tactic|
aesop? $c*
(config := { introsTransparency? := some .default, terminal := true })
(rule_sets := [$(Lean.mkIdent `SimpleGraph):ident]))
/--
A variant of `aesop_graph` which does not fail if it is unable to solve the goal.
Use this only for exploration! Nonterminal Aesop is even worse than nonterminal `simp`.
-/
macro (name := aesop_graph_nonterminal) "aesop_graph_nonterminal" c:Aesop.tactic_clause* : tactic =>
`(tactic|
aesop $c*
(config := { introsTransparency? := some .default, warnOnNonterminal := false })
(rule_sets := [$(Lean.mkIdent `SimpleGraph):ident]))
open Finset Function
universe u v w
/-- A simple graph is an irreflexive symmetric relation `Adj` on a vertex type `V`.
The relation describes which pairs of vertices are adjacent.
There is exactly one edge for every pair of adjacent vertices;
see `SimpleGraph.edgeSet` for the corresponding edge set.
-/
@[ext, aesop safe constructors (rule_sets := [SimpleGraph])]
structure SimpleGraph (V : Type u) where
/-- The adjacency relation of a simple graph. -/
Adj : V → V → Prop
symm : Symmetric Adj := by aesop_graph
loopless : Irreflexive Adj := by aesop_graph
initialize_simps_projections SimpleGraph (Adj → adj)
/-- Constructor for simple graphs using a symmetric irreflexive boolean function. -/
@[simps]
def SimpleGraph.mk' {V : Type u} :
{adj : V → V → Bool // (∀ x y, adj x y = adj y x) ∧ (∀ x, ¬ adj x x)} ↪ SimpleGraph V where
toFun x := ⟨fun v w ↦ x.1 v w, fun v w ↦ by simp [x.2.1], fun v ↦ by simp [x.2.2]⟩
inj' := by
rintro ⟨adj, _⟩ ⟨adj', _⟩
simp only [mk.injEq, Subtype.mk.injEq]
intro h
funext v w
simpa [Bool.coe_iff_coe] using congr_fun₂ h v w
/-- We can enumerate simple graphs by enumerating all functions `V → V → Bool`
and filtering on whether they are symmetric and irreflexive. -/
instance {V : Type u} [Fintype V] [DecidableEq V] : Fintype (SimpleGraph V) where
elems := Finset.univ.map SimpleGraph.mk'
complete := by
classical
rintro ⟨Adj, hs, hi⟩
simp only [mem_map, mem_univ, true_and, Subtype.exists, Bool.not_eq_true]
refine ⟨fun v w ↦ Adj v w, ⟨?_, ?_⟩, ?_⟩
· simp [hs.iff]
· intro v; simp [hi v]
· ext
simp
/-- There are finitely many simple graphs on a given finite type. -/
instance SimpleGraph.instFinite {V : Type u} [Finite V] : Finite (SimpleGraph V) :=
.of_injective SimpleGraph.Adj fun _ _ ↦ SimpleGraph.ext
/-- Construct the simple graph induced by the given relation. It
symmetrizes the relation and makes it irreflexive. -/
def SimpleGraph.fromRel {V : Type u} (r : V → V → Prop) : SimpleGraph V where
Adj a b := a ≠ b ∧ (r a b ∨ r b a)
symm := fun _ _ ⟨hn, hr⟩ => ⟨hn.symm, hr.symm⟩
loopless := fun _ ⟨hn, _⟩ => hn rfl
@[simp]
theorem SimpleGraph.fromRel_adj {V : Type u} (r : V → V → Prop) (v w : V) :
(SimpleGraph.fromRel r).Adj v w ↔ v ≠ w ∧ (r v w ∨ r w v) :=
Iff.rfl
attribute [aesop safe (rule_sets := [SimpleGraph])] Ne.symm
attribute [aesop safe (rule_sets := [SimpleGraph])] Ne.irrefl
/-- The complete graph on a type `V` is the simple graph with all pairs of distinct vertices
adjacent. In `Mathlib`, this is usually referred to as `⊤`. -/
def completeGraph (V : Type u) : SimpleGraph V where Adj := Ne
/-- The graph with no edges on a given vertex type `V`. `Mathlib` prefers the notation `⊥`. -/
def emptyGraph (V : Type u) : SimpleGraph V where Adj _ _ := False
/-- Two vertices are adjacent in the complete bipartite graph on two vertex types
if and only if they are not from the same side.
Any bipartite graph may be regarded as a subgraph of one of these. -/
@[simps]
def completeBipartiteGraph (V W : Type*) : SimpleGraph (V ⊕ W) where
Adj v w := v.isLeft ∧ w.isRight ∨ v.isRight ∧ w.isLeft
symm v w := by cases v <;> cases w <;> simp
loopless v := by cases v <;> simp
namespace SimpleGraph
variable {ι : Sort*} {V : Type u} (G : SimpleGraph V) {a b c u v w : V} {e : Sym2 V}
@[simp]
protected theorem irrefl {v : V} : ¬G.Adj v v :=
G.loopless v
theorem adj_comm (u v : V) : G.Adj u v ↔ G.Adj v u :=
⟨fun x => G.symm x, fun x => G.symm x⟩
@[symm]
theorem adj_symm (h : G.Adj u v) : G.Adj v u :=
G.symm h
theorem Adj.symm {G : SimpleGraph V} {u v : V} (h : G.Adj u v) : G.Adj v u :=
G.symm h
theorem ne_of_adj (h : G.Adj a b) : a ≠ b := by
rintro rfl
exact G.irrefl h
protected theorem Adj.ne {G : SimpleGraph V} {a b : V} (h : G.Adj a b) : a ≠ b :=
G.ne_of_adj h
protected theorem Adj.ne' {G : SimpleGraph V} {a b : V} (h : G.Adj a b) : b ≠ a :=
h.ne.symm
theorem ne_of_adj_of_not_adj {v w x : V} (h : G.Adj v x) (hn : ¬G.Adj w x) : v ≠ w := fun h' =>
hn (h' ▸ h)
theorem adj_injective : Injective (Adj : SimpleGraph V → V → V → Prop) :=
fun _ _ => SimpleGraph.ext
@[simp]
theorem adj_inj {G H : SimpleGraph V} : G.Adj = H.Adj ↔ G = H :=
adj_injective.eq_iff
theorem adj_congr_of_sym2 {u v w x : V} (h : s(u, v) = s(w, x)) : G.Adj u v ↔ G.Adj w x := by
simp only [Sym2.eq, Sym2.rel_iff', Prod.mk.injEq, Prod.swap_prod_mk] at h
rcases h with hl | hr
· rw [hl.1, hl.2]
· rw [hr.1, hr.2, adj_comm]
section Order
/-- The relation that one `SimpleGraph` is a subgraph of another.
Note that this should be spelled `≤`. -/
def IsSubgraph (x y : SimpleGraph V) : Prop :=
∀ ⦃v w : V⦄, x.Adj v w → y.Adj v w
instance : LE (SimpleGraph V) :=
⟨IsSubgraph⟩
@[simp]
theorem isSubgraph_eq_le : (IsSubgraph : SimpleGraph V → SimpleGraph V → Prop) = (· ≤ ·) :=
rfl
/-- The supremum of two graphs `x ⊔ y` has edges where either `x` or `y` have edges. -/
instance : Max (SimpleGraph V) where
max x y :=
{ Adj := x.Adj ⊔ y.Adj
symm := fun v w h => by rwa [Pi.sup_apply, Pi.sup_apply, x.adj_comm, y.adj_comm] }
@[simp]
theorem sup_adj (x y : SimpleGraph V) (v w : V) : (x ⊔ y).Adj v w ↔ x.Adj v w ∨ y.Adj v w :=
Iff.rfl
/-- The infimum of two graphs `x ⊓ y` has edges where both `x` and `y` have edges. -/
instance : Min (SimpleGraph V) where
min x y :=
{ Adj := x.Adj ⊓ y.Adj
symm := fun v w h => by rwa [Pi.inf_apply, Pi.inf_apply, x.adj_comm, y.adj_comm] }
@[simp]
theorem inf_adj (x y : SimpleGraph V) (v w : V) : (x ⊓ y).Adj v w ↔ x.Adj v w ∧ y.Adj v w :=
Iff.rfl
/-- We define `Gᶜ` to be the `SimpleGraph V` such that no two adjacent vertices in `G`
are adjacent in the complement, and every nonadjacent pair of vertices is adjacent
(still ensuring that vertices are not adjacent to themselves). -/
instance hasCompl : HasCompl (SimpleGraph V) where
compl G :=
{ Adj := fun v w => v ≠ w ∧ ¬G.Adj v w
symm := fun v w ⟨hne, _⟩ => ⟨hne.symm, by rwa [adj_comm]⟩
loopless := fun _ ⟨hne, _⟩ => (hne rfl).elim }
@[simp]
theorem compl_adj (G : SimpleGraph V) (v w : V) : Gᶜ.Adj v w ↔ v ≠ w ∧ ¬G.Adj v w :=
Iff.rfl
/-- The difference of two graphs `x \ y` has the edges of `x` with the edges of `y` removed. -/
instance sdiff : SDiff (SimpleGraph V) where
sdiff x y :=
{ Adj := x.Adj \ y.Adj
symm := fun v w h => by change x.Adj w v ∧ ¬y.Adj w v; rwa [x.adj_comm, y.adj_comm] }
@[simp]
theorem sdiff_adj (x y : SimpleGraph V) (v w : V) : (x \ y).Adj v w ↔ x.Adj v w ∧ ¬y.Adj v w :=
Iff.rfl
instance supSet : SupSet (SimpleGraph V) where
sSup s :=
{ Adj := fun a b => ∃ G ∈ s, Adj G a b
symm := fun _ _ => Exists.imp fun _ => And.imp_right Adj.symm
loopless := by
rintro a ⟨G, _, ha⟩
exact ha.ne rfl }
instance infSet : InfSet (SimpleGraph V) where
sInf s :=
{ Adj := fun a b => (∀ ⦃G⦄, G ∈ s → Adj G a b) ∧ a ≠ b
symm := fun _ _ => And.imp (forall₂_imp fun _ _ => Adj.symm) Ne.symm
loopless := fun _ h => h.2 rfl }
@[simp]
theorem sSup_adj {s : Set (SimpleGraph V)} {a b : V} : (sSup s).Adj a b ↔ ∃ G ∈ s, Adj G a b :=
Iff.rfl
@[simp]
theorem sInf_adj {s : Set (SimpleGraph V)} : (sInf s).Adj a b ↔ (∀ G ∈ s, Adj G a b) ∧ a ≠ b :=
Iff.rfl
@[simp]
theorem iSup_adj {f : ι → SimpleGraph V} : (⨆ i, f i).Adj a b ↔ ∃ i, (f i).Adj a b := by simp [iSup]
@[simp]
theorem iInf_adj {f : ι → SimpleGraph V} : (⨅ i, f i).Adj a b ↔ (∀ i, (f i).Adj a b) ∧ a ≠ b := by
simp [iInf]
theorem sInf_adj_of_nonempty {s : Set (SimpleGraph V)} (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 => (h _ hG).ne
theorem iInf_adj_of_nonempty [Nonempty ι] {f : ι → SimpleGraph V} :
(⨅ i, f i).Adj a b ↔ ∀ i, (f i).Adj a b := by
rw [iInf, sInf_adj_of_nonempty (Set.range_nonempty _), Set.forall_mem_range]
/-- For graphs `G`, `H`, `G ≤ H` iff `∀ a b, G.Adj a b → H.Adj a b`. -/
instance distribLattice : DistribLattice (SimpleGraph V) :=
{ show DistribLattice (SimpleGraph V) from
adj_injective.distribLattice _ (fun _ _ => rfl) fun _ _ => rfl with
le := fun G H => ∀ ⦃a b⦄, G.Adj a b → H.Adj a b }
instance completeAtomicBooleanAlgebra : CompleteAtomicBooleanAlgebra (SimpleGraph V) :=
{ SimpleGraph.distribLattice with
le := (· ≤ ·)
sup := (· ⊔ ·)
inf := (· ⊓ ·)
compl := HasCompl.compl
sdiff := (· \ ·)
top := completeGraph V
bot := emptyGraph V
le_top := fun x _ _ h => x.ne_of_adj h
bot_le := fun _ _ _ h => h.elim
sdiff_eq := fun x y => by
ext v w
refine ⟨fun h => ⟨h.1, ⟨?_, h.2⟩⟩, fun h => ⟨h.1, h.2.2⟩⟩
rintro rfl
exact x.irrefl h.1
inf_compl_le_bot := fun _ _ _ h => False.elim <| h.2.2 h.1
top_le_sup_compl := fun G v w hvw => by
by_cases h : G.Adj v w
· exact Or.inl h
· exact Or.inr ⟨hvw, h⟩
sSup := sSup
le_sSup := fun _ G hG _ _ hab => ⟨G, hG, hab⟩
sSup_le := fun s G hG a b => by
rintro ⟨H, hH, hab⟩
exact hG _ hH hab
sInf := sInf
sInf_le := fun _ _ hG _ _ hab => hab.1 hG
le_sInf := fun _ _ hG _ _ hab => ⟨fun _ hH => hG _ hH hab, hab.ne⟩
iInf_iSup_eq := fun f => by ext; simp [Classical.skolem] }
@[simp]
theorem top_adj (v w : V) : (⊤ : SimpleGraph V).Adj v w ↔ v ≠ w :=
Iff.rfl
@[simp]
theorem bot_adj (v w : V) : (⊥ : SimpleGraph V).Adj v w ↔ False :=
Iff.rfl
@[simp]
theorem completeGraph_eq_top (V : Type u) : completeGraph V = ⊤ :=
rfl
@[simp]
theorem emptyGraph_eq_bot (V : Type u) : emptyGraph V = ⊥ :=
rfl
@[simps]
instance (V : Type u) : Inhabited (SimpleGraph V) :=
⟨⊥⟩
instance [Subsingleton V] : Unique (SimpleGraph V) where
default := ⊥
uniq G := by ext a b; have := Subsingleton.elim a b; simp [this]
instance [Nontrivial V] : Nontrivial (SimpleGraph V) :=
⟨⟨⊥, ⊤, fun h ↦ not_subsingleton V ⟨by simpa only [← adj_inj, funext_iff, bot_adj,
top_adj, ne_eq, eq_iff_iff, false_iff, not_not] using h⟩⟩⟩
section Decidable
variable (V) (H : SimpleGraph V) [DecidableRel G.Adj] [DecidableRel H.Adj]
instance Bot.adjDecidable : DecidableRel (⊥ : SimpleGraph V).Adj :=
inferInstanceAs <| DecidableRel fun _ _ => False
instance Sup.adjDecidable : DecidableRel (G ⊔ H).Adj :=
inferInstanceAs <| DecidableRel fun v w => G.Adj v w ∨ H.Adj v w
instance Inf.adjDecidable : DecidableRel (G ⊓ H).Adj :=
inferInstanceAs <| DecidableRel fun v w => G.Adj v w ∧ H.Adj v w
instance Sdiff.adjDecidable : DecidableRel (G \ H).Adj :=
inferInstanceAs <| DecidableRel fun v w => G.Adj v w ∧ ¬H.Adj v w
variable [DecidableEq V]
instance Top.adjDecidable : DecidableRel (⊤ : SimpleGraph V).Adj :=
inferInstanceAs <| DecidableRel fun v w => v ≠ w
instance Compl.adjDecidable : DecidableRel (Gᶜ.Adj) :=
inferInstanceAs <| DecidableRel fun v w => v ≠ w ∧ ¬G.Adj v w
end Decidable
end Order
/-- `G.support` is the set of vertices that form edges in `G`. -/
def support : Set V :=
Rel.dom G.Adj
theorem mem_support {v : V} : v ∈ G.support ↔ ∃ w, G.Adj v w :=
Iff.rfl
theorem support_mono {G G' : SimpleGraph V} (h : G ≤ G') : G.support ⊆ G'.support :=
Rel.dom_mono h
/-- `G.neighborSet v` is the set of vertices adjacent to `v` in `G`. -/
def neighborSet (v : V) : Set V := {w | G.Adj v w}
instance neighborSet.memDecidable (v : V) [DecidableRel G.Adj] :
DecidablePred (· ∈ G.neighborSet v) :=
inferInstanceAs <| DecidablePred (Adj G v)
lemma neighborSet_subset_support (v : V) : G.neighborSet v ⊆ G.support :=
fun _ hadj ↦ ⟨v, hadj.symm⟩
section EdgeSet
variable {G₁ G₂ : SimpleGraph V}
/-- The edges of G consist of the unordered pairs of vertices related by
`G.Adj`. This is the order embedding; for the edge set of a particular graph, see
`SimpleGraph.edgeSet`.
The way `edgeSet` is defined is such that `mem_edgeSet` is proved by `Iff.rfl`.
(That is, `s(v, w) ∈ G.edgeSet` is definitionally equal to `G.Adj v w`.)
-/
-- Porting note: We need a separate definition so that dot notation works.
def edgeSetEmbedding (V : Type*) : SimpleGraph V ↪o Set (Sym2 V) :=
OrderEmbedding.ofMapLEIff (fun G => Sym2.fromRel G.symm) fun _ _ =>
⟨fun h a b => @h s(a, b), fun h e => Sym2.ind @h e⟩
/-- `G.edgeSet` is the edge set for `G`.
This is an abbreviation for `edgeSetEmbedding G` that permits dot notation. -/
abbrev edgeSet (G : SimpleGraph V) : Set (Sym2 V) := edgeSetEmbedding V G
@[simp]
theorem mem_edgeSet : s(v, w) ∈ G.edgeSet ↔ G.Adj v w :=
Iff.rfl
theorem not_isDiag_of_mem_edgeSet : e ∈ edgeSet G → ¬e.IsDiag :=
Sym2.ind (fun _ _ => Adj.ne) e
theorem edgeSet_inj : G₁.edgeSet = G₂.edgeSet ↔ G₁ = G₂ := (edgeSetEmbedding V).eq_iff_eq
@[simp]
theorem edgeSet_subset_edgeSet : edgeSet G₁ ⊆ edgeSet G₂ ↔ G₁ ≤ G₂ :=
(edgeSetEmbedding V).le_iff_le
@[simp]
theorem edgeSet_ssubset_edgeSet : edgeSet G₁ ⊂ edgeSet G₂ ↔ G₁ < G₂ :=
(edgeSetEmbedding V).lt_iff_lt
theorem edgeSet_injective : Injective (edgeSet : SimpleGraph V → Set (Sym2 V)) :=
(edgeSetEmbedding V).injective
alias ⟨_, edgeSet_mono⟩ := edgeSet_subset_edgeSet
alias ⟨_, edgeSet_strict_mono⟩ := edgeSet_ssubset_edgeSet
attribute [mono] edgeSet_mono edgeSet_strict_mono
variable (G₁ G₂)
@[simp]
theorem edgeSet_bot : (⊥ : SimpleGraph V).edgeSet = ∅ :=
Sym2.fromRel_bot
@[simp]
theorem edgeSet_top : (⊤ : SimpleGraph V).edgeSet = {e | ¬e.IsDiag} :=
Sym2.fromRel_ne
@[simp]
theorem edgeSet_subset_setOf_not_isDiag : G.edgeSet ⊆ {e | ¬e.IsDiag} :=
fun _ h => (Sym2.fromRel_irreflexive (sym := G.symm)).mp G.loopless h
@[simp]
theorem edgeSet_sup : (G₁ ⊔ G₂).edgeSet = G₁.edgeSet ∪ G₂.edgeSet := by
ext ⟨x, y⟩
rfl
@[simp]
theorem edgeSet_inf : (G₁ ⊓ G₂).edgeSet = G₁.edgeSet ∩ G₂.edgeSet := by
ext ⟨x, y⟩
rfl
@[simp]
theorem edgeSet_sdiff : (G₁ \ G₂).edgeSet = G₁.edgeSet \ G₂.edgeSet := by
ext ⟨x, y⟩
rfl
variable {G G₁ G₂}
@[simp] lemma disjoint_edgeSet : Disjoint G₁.edgeSet G₂.edgeSet ↔ Disjoint G₁ G₂ := by
rw [Set.disjoint_iff, disjoint_iff_inf_le, ← edgeSet_inf, ← edgeSet_bot, ← Set.le_iff_subset,
OrderEmbedding.le_iff_le]
@[simp] lemma edgeSet_eq_empty : G.edgeSet = ∅ ↔ G = ⊥ := by rw [← edgeSet_bot, edgeSet_inj]
@[simp] lemma edgeSet_nonempty : G.edgeSet.Nonempty ↔ G ≠ ⊥ := by
rw [Set.nonempty_iff_ne_empty, edgeSet_eq_empty.ne]
/-- This lemma, combined with `edgeSet_sdiff` and `edgeSet_from_edgeSet`,
allows proving `(G \ from_edgeSet s).edge_set = G.edgeSet \ s` by `simp`. -/
@[simp]
theorem edgeSet_sdiff_sdiff_isDiag (G : SimpleGraph V) (s : Set (Sym2 V)) :
G.edgeSet \ (s \ { e | e.IsDiag }) = G.edgeSet \ s := by
ext e
simp only [Set.mem_diff, Set.mem_setOf_eq, not_and, not_not, and_congr_right_iff]
intro h
simp only [G.not_isDiag_of_mem_edgeSet h, imp_false]
/-- Two vertices are adjacent iff there is an edge between them. The
condition `v ≠ w` ensures they are different endpoints of the edge,
which is necessary since when `v = w` the existential
`∃ (e ∈ G.edgeSet), v ∈ e ∧ w ∈ e` is satisfied by every edge
incident to `v`. -/
theorem adj_iff_exists_edge {v w : V} : G.Adj v w ↔ v ≠ w ∧ ∃ e ∈ G.edgeSet, v ∈ e ∧ w ∈ e := by
refine ⟨fun _ => ⟨G.ne_of_adj ‹_›, s(v, w), by simpa⟩, ?_⟩
rintro ⟨hne, e, he, hv⟩
rw [Sym2.mem_and_mem_iff hne] at hv
subst e
rwa [mem_edgeSet] at he
theorem adj_iff_exists_edge_coe : G.Adj a b ↔ ∃ e : G.edgeSet, e.val = s(a, b) := by
simp only [mem_edgeSet, exists_prop, SetCoe.exists, exists_eq_right, Subtype.coe_mk]
variable (G G₁ G₂)
theorem edge_other_ne {e : Sym2 V} (he : e ∈ G.edgeSet) {v : V} (h : v ∈ e) :
Sym2.Mem.other h ≠ v := by
rw [← Sym2.other_spec h, Sym2.eq_swap] at he
exact G.ne_of_adj he
instance decidableMemEdgeSet [DecidableRel G.Adj] : DecidablePred (· ∈ G.edgeSet) :=
Sym2.fromRel.decidablePred G.symm
instance fintypeEdgeSet [Fintype (Sym2 V)] [DecidableRel G.Adj] : Fintype G.edgeSet :=
Subtype.fintype _
instance fintypeEdgeSetBot : Fintype (⊥ : SimpleGraph V).edgeSet := by
rw [edgeSet_bot]
infer_instance
instance fintypeEdgeSetSup [DecidableEq V] [Fintype G₁.edgeSet] [Fintype G₂.edgeSet] :
Fintype (G₁ ⊔ G₂).edgeSet := by
rw [edgeSet_sup]
infer_instance
instance fintypeEdgeSetInf [DecidableEq V] [Fintype G₁.edgeSet] [Fintype G₂.edgeSet] :
Fintype (G₁ ⊓ G₂).edgeSet := by
rw [edgeSet_inf]
exact Set.fintypeInter _ _
instance fintypeEdgeSetSdiff [DecidableEq V] [Fintype G₁.edgeSet] [Fintype G₂.edgeSet] :
Fintype (G₁ \ G₂).edgeSet := by
rw [edgeSet_sdiff]
exact Set.fintypeDiff _ _
end EdgeSet
section FromEdgeSet
variable (s : Set (Sym2 V))
/-- `fromEdgeSet` constructs a `SimpleGraph` from a set of edges, without loops. -/
def fromEdgeSet : SimpleGraph V where
Adj := Sym2.ToRel s ⊓ Ne
symm _ _ h := ⟨Sym2.toRel_symmetric s h.1, h.2.symm⟩
@[simp]
theorem fromEdgeSet_adj : (fromEdgeSet s).Adj v w ↔ s(v, w) ∈ s ∧ v ≠ w :=
Iff.rfl
-- Note: we need to make sure `fromEdgeSet_adj` and this lemma are confluent.
-- In particular, both yield `s(u, v) ∈ (fromEdgeSet s).edgeSet` ==> `s(v, w) ∈ s ∧ v ≠ w`.
@[simp]
theorem edgeSet_fromEdgeSet : (fromEdgeSet s).edgeSet = s \ { e | e.IsDiag } := by
ext e
exact Sym2.ind (by simp) e
@[simp]
theorem fromEdgeSet_edgeSet : fromEdgeSet G.edgeSet = G := by
ext v w
exact ⟨fun h => h.1, fun h => ⟨h, G.ne_of_adj h⟩⟩
@[simp]
theorem fromEdgeSet_empty : fromEdgeSet (∅ : Set (Sym2 V)) = ⊥ := by
ext v w
simp only [fromEdgeSet_adj, Set.mem_empty_iff_false, false_and, bot_adj]
@[simp]
theorem fromEdgeSet_univ : fromEdgeSet (Set.univ : Set (Sym2 V)) = ⊤ := by
ext v w
simp only [fromEdgeSet_adj, Set.mem_univ, true_and, top_adj]
@[simp]
theorem fromEdgeSet_inter (s t : Set (Sym2 V)) :
fromEdgeSet (s ∩ t) = fromEdgeSet s ⊓ fromEdgeSet t := by
ext v w
simp only [fromEdgeSet_adj, Set.mem_inter_iff, Ne, inf_adj]
tauto
@[simp]
theorem fromEdgeSet_union (s t : Set (Sym2 V)) :
fromEdgeSet (s ∪ t) = fromEdgeSet s ⊔ fromEdgeSet t := by
ext v w
simp [Set.mem_union, or_and_right]
@[simp]
theorem fromEdgeSet_sdiff (s t : Set (Sym2 V)) :
fromEdgeSet (s \ t) = fromEdgeSet s \ fromEdgeSet t := by
ext v w
constructor <;> simp +contextual
@[gcongr, mono]
theorem fromEdgeSet_mono {s t : Set (Sym2 V)} (h : s ⊆ t) : fromEdgeSet s ≤ fromEdgeSet t := by
rintro v w
simp +contextual only [fromEdgeSet_adj, Ne, not_false_iff,
and_true, and_imp]
exact fun vws _ => h vws
@[simp] lemma disjoint_fromEdgeSet : Disjoint G (fromEdgeSet s) ↔ Disjoint G.edgeSet s := by
conv_rhs => rw [← Set.diff_union_inter s {e : Sym2 V | e.IsDiag}]
rw [← disjoint_edgeSet, edgeSet_fromEdgeSet, Set.disjoint_union_right, and_iff_left]
exact Set.disjoint_left.2 fun e he he' ↦ not_isDiag_of_mem_edgeSet _ he he'.2
@[simp] lemma fromEdgeSet_disjoint : Disjoint (fromEdgeSet s) G ↔ Disjoint s G.edgeSet := by
rw [disjoint_comm, disjoint_fromEdgeSet, disjoint_comm]
instance [DecidableEq V] [Fintype s] : Fintype (fromEdgeSet s).edgeSet := by
rw [edgeSet_fromEdgeSet s]
infer_instance
end FromEdgeSet
/-! ### Incidence set -/
/-- Set of edges incident to a given vertex, aka incidence set. -/
def incidenceSet (v : V) : Set (Sym2 V) :=
{ e ∈ G.edgeSet | v ∈ e }
theorem incidenceSet_subset (v : V) : G.incidenceSet v ⊆ G.edgeSet := fun _ h => h.1
theorem mk'_mem_incidenceSet_iff : s(b, c) ∈ G.incidenceSet a ↔ G.Adj b c ∧ (a = b ∨ a = c) :=
and_congr_right' Sym2.mem_iff
theorem mk'_mem_incidenceSet_left_iff : s(a, b) ∈ G.incidenceSet a ↔ G.Adj a b :=
and_iff_left <| Sym2.mem_mk_left _ _
theorem mk'_mem_incidenceSet_right_iff : s(a, b) ∈ G.incidenceSet b ↔ G.Adj a b :=
and_iff_left <| Sym2.mem_mk_right _ _
theorem edge_mem_incidenceSet_iff {e : G.edgeSet} : ↑e ∈ G.incidenceSet a ↔ a ∈ (e : Sym2 V) :=
and_iff_right e.2
theorem incidenceSet_inter_incidenceSet_subset (h : a ≠ b) :
G.incidenceSet a ∩ G.incidenceSet b ⊆ {s(a, b)} := fun _e he =>
(Sym2.mem_and_mem_iff h).1 ⟨he.1.2, he.2.2⟩
theorem incidenceSet_inter_incidenceSet_of_adj (h : G.Adj a b) :
G.incidenceSet a ∩ G.incidenceSet b = {s(a, b)} := by
refine (G.incidenceSet_inter_incidenceSet_subset <| h.ne).antisymm ?_
rintro _ (rfl : _ = s(a, b))
exact ⟨G.mk'_mem_incidenceSet_left_iff.2 h, G.mk'_mem_incidenceSet_right_iff.2 h⟩
theorem adj_of_mem_incidenceSet (h : a ≠ b) (ha : e ∈ G.incidenceSet a)
(hb : e ∈ G.incidenceSet b) : G.Adj a b := by
rwa [← mk'_mem_incidenceSet_left_iff, ←
Set.mem_singleton_iff.1 <| G.incidenceSet_inter_incidenceSet_subset h ⟨ha, hb⟩]
theorem incidenceSet_inter_incidenceSet_of_not_adj (h : ¬G.Adj a b) (hn : a ≠ b) :
G.incidenceSet a ∩ G.incidenceSet b = ∅ := by
simp_rw [Set.eq_empty_iff_forall_not_mem, Set.mem_inter_iff, not_and]
intro u ha hb
exact h (G.adj_of_mem_incidenceSet hn ha hb)
instance decidableMemIncidenceSet [DecidableEq V] [DecidableRel G.Adj] (v : V) :
DecidablePred (· ∈ G.incidenceSet v) :=
inferInstanceAs <| DecidablePred fun e => e ∈ G.edgeSet ∧ v ∈ e
@[simp]
theorem mem_neighborSet (v w : V) : w ∈ G.neighborSet v ↔ G.Adj v w :=
Iff.rfl
lemma not_mem_neighborSet_self : a ∉ G.neighborSet a := by simp
@[simp]
theorem mem_incidenceSet (v w : V) : s(v, w) ∈ G.incidenceSet v ↔ G.Adj v w := by
simp [incidenceSet]
theorem mem_incidence_iff_neighbor {v w : V} :
s(v, w) ∈ G.incidenceSet v ↔ w ∈ G.neighborSet v := by
simp only [mem_incidenceSet, mem_neighborSet]
theorem adj_incidenceSet_inter {v : V} {e : Sym2 V} (he : e ∈ G.edgeSet) (h : v ∈ e) :
G.incidenceSet v ∩ G.incidenceSet (Sym2.Mem.other h) = {e} := by
ext e'
simp only [incidenceSet, Set.mem_sep_iff, Set.mem_inter_iff, Set.mem_singleton_iff]
refine ⟨fun h' => ?_, ?_⟩
· rw [← Sym2.other_spec h]
exact (Sym2.mem_and_mem_iff (edge_other_ne G he h).symm).mp ⟨h'.1.2, h'.2.2⟩
· rintro rfl
exact ⟨⟨he, h⟩, he, Sym2.other_mem _⟩
theorem compl_neighborSet_disjoint (G : SimpleGraph V) (v : V) :
Disjoint (G.neighborSet v) (Gᶜ.neighborSet v) := by
rw [Set.disjoint_iff]
rintro w ⟨h, h'⟩
rw [mem_neighborSet, compl_adj] at h'
exact h'.2 h
theorem neighborSet_union_compl_neighborSet_eq (G : SimpleGraph V) (v : V) :
G.neighborSet v ∪ Gᶜ.neighborSet v = {v}ᶜ := by
ext w
have h := @ne_of_adj _ G
simp_rw [Set.mem_union, mem_neighborSet, compl_adj, Set.mem_compl_iff, Set.mem_singleton_iff]
tauto
theorem card_neighborSet_union_compl_neighborSet [Fintype V] (G : SimpleGraph V) (v : V)
[Fintype (G.neighborSet v ∪ Gᶜ.neighborSet v : Set V)] :
#(G.neighborSet v ∪ Gᶜ.neighborSet v).toFinset = Fintype.card V - 1 := by
classical simp_rw [neighborSet_union_compl_neighborSet_eq, Set.toFinset_compl,
Finset.card_compl, Set.toFinset_card, Set.card_singleton]
theorem neighborSet_compl (G : SimpleGraph V) (v : V) :
Gᶜ.neighborSet v = (G.neighborSet v)ᶜ \ {v} := by
ext w
simp [and_comm, eq_comm]
/-- The set of common neighbors between two vertices `v` and `w` in a graph `G` is the
intersection of the neighbor sets of `v` and `w`. -/
def commonNeighbors (v w : V) : Set V :=
G.neighborSet v ∩ G.neighborSet w
theorem commonNeighbors_eq (v w : V) : G.commonNeighbors v w = G.neighborSet v ∩ G.neighborSet w :=
rfl
theorem mem_commonNeighbors {u v w : V} : u ∈ G.commonNeighbors v w ↔ G.Adj v u ∧ G.Adj w u :=
Iff.rfl
theorem commonNeighbors_symm (v w : V) : G.commonNeighbors v w = G.commonNeighbors w v :=
Set.inter_comm _ _
theorem not_mem_commonNeighbors_left (v w : V) : v ∉ G.commonNeighbors v w := fun h =>
ne_of_adj G h.1 rfl
theorem not_mem_commonNeighbors_right (v w : V) : w ∉ G.commonNeighbors v w := fun h =>
ne_of_adj G h.2 rfl
theorem commonNeighbors_subset_neighborSet_left (v w : V) :
G.commonNeighbors v w ⊆ G.neighborSet v :=
Set.inter_subset_left
theorem commonNeighbors_subset_neighborSet_right (v w : V) :
G.commonNeighbors v w ⊆ G.neighborSet w :=
Set.inter_subset_right
instance decidableMemCommonNeighbors [DecidableRel G.Adj] (v w : V) :
DecidablePred (· ∈ G.commonNeighbors v w) :=
inferInstanceAs <| DecidablePred fun u => u ∈ G.neighborSet v ∧ u ∈ G.neighborSet w
theorem commonNeighbors_top_eq {v w : V} :
(⊤ : SimpleGraph V).commonNeighbors v w = Set.univ \ {v, w} := by
ext u
simp [commonNeighbors, eq_comm, not_or]
section Incidence
variable [DecidableEq V]
/-- Given an edge incident to a particular vertex, get the other vertex on the edge. -/
def otherVertexOfIncident {v : V} {e : Sym2 V} (h : e ∈ G.incidenceSet v) : V :=
Sym2.Mem.other' h.2
theorem edge_other_incident_set {v : V} {e : Sym2 V} (h : e ∈ G.incidenceSet v) :
e ∈ G.incidenceSet (G.otherVertexOfIncident h) := by
use h.1
simp [otherVertexOfIncident, Sym2.other_mem']
theorem incidence_other_prop {v : V} {e : Sym2 V} (h : e ∈ G.incidenceSet v) :
G.otherVertexOfIncident h ∈ G.neighborSet v := by
obtain ⟨he, hv⟩ := h
rwa [← Sym2.other_spec' hv, mem_edgeSet] at he
-- Porting note: as a simp lemma this does not apply even to itself
theorem incidence_other_neighbor_edge {v w : V} (h : w ∈ G.neighborSet v) :
G.otherVertexOfIncident (G.mem_incidence_iff_neighbor.mpr h) = w :=
Sym2.congr_right.mp (Sym2.other_spec' (G.mem_incidence_iff_neighbor.mpr h).right)
/-- There is an equivalence between the set of edges incident to a given
vertex and the set of vertices adjacent to the vertex. -/
@[simps]
def incidenceSetEquivNeighborSet (v : V) : G.incidenceSet v ≃ G.neighborSet v where
toFun e := ⟨G.otherVertexOfIncident e.2, G.incidence_other_prop e.2⟩
invFun w := ⟨s(v, w.1), G.mem_incidence_iff_neighbor.mpr w.2⟩
left_inv x := by simp [otherVertexOfIncident]
right_inv := fun ⟨w, hw⟩ => by
simp only [mem_neighborSet, Subtype.mk.injEq]
exact incidence_other_neighbor_edge _ hw
end Incidence
end SimpleGraph
| Mathlib/Combinatorics/SimpleGraph/Basic.lean | 878 | 881 | |
/-
Copyright (c) 2014 Parikshit Khanna. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Parikshit Khanna, Jeremy Avigad, Leonardo de Moura, Floris van Doorn, Mario Carneiro
-/
import Mathlib.Control.Basic
import Mathlib.Data.Nat.Basic
import Mathlib.Data.Option.Basic
import Mathlib.Data.List.Defs
import Mathlib.Data.List.Monad
import Mathlib.Logic.OpClass
import Mathlib.Logic.Unique
import Mathlib.Order.Basic
import Mathlib.Tactic.Common
/-!
# Basic properties of lists
-/
assert_not_exists GroupWithZero
assert_not_exists Lattice
assert_not_exists Prod.swap_eq_iff_eq_swap
assert_not_exists Ring
assert_not_exists Set.range
open Function
open Nat hiding one_pos
namespace List
universe u v w
variable {ι : Type*} {α : Type u} {β : Type v} {γ : Type w} {l₁ l₂ : List α}
/-- There is only one list of an empty type -/
instance uniqueOfIsEmpty [IsEmpty α] : Unique (List α) :=
{ instInhabitedList with
uniq := fun l =>
match l with
| [] => rfl
| a :: _ => isEmptyElim a }
instance : Std.LawfulIdentity (α := List α) Append.append [] where
left_id := nil_append
right_id := append_nil
instance : Std.Associative (α := List α) Append.append where
assoc := append_assoc
@[simp] theorem cons_injective {a : α} : Injective (cons a) := fun _ _ => tail_eq_of_cons_eq
theorem singleton_injective : Injective fun a : α => [a] := fun _ _ h => (cons_eq_cons.1 h).1
theorem set_of_mem_cons (l : List α) (a : α) : { x | x ∈ a :: l } = insert a { x | x ∈ l } :=
Set.ext fun _ => mem_cons
/-! ### mem -/
theorem _root_.Decidable.List.eq_or_ne_mem_of_mem [DecidableEq α]
{a b : α} {l : List α} (h : a ∈ b :: l) : a = b ∨ a ≠ b ∧ a ∈ l := by
by_cases hab : a = b
· exact Or.inl hab
· exact ((List.mem_cons.1 h).elim Or.inl (fun h => Or.inr ⟨hab, h⟩))
lemma mem_pair {a b c : α} : a ∈ [b, c] ↔ a = b ∨ a = c := by
rw [mem_cons, mem_singleton]
-- The simpNF linter says that the LHS can be simplified via `List.mem_map`.
-- However this is a higher priority lemma.
-- It seems the side condition `hf` is not applied by `simpNF`.
-- https://github.com/leanprover/std4/issues/207
@[simp 1100, nolint simpNF]
theorem mem_map_of_injective {f : α → β} (H : Injective f) {a : α} {l : List α} :
f a ∈ map f l ↔ a ∈ l :=
⟨fun m => let ⟨_, m', e⟩ := exists_of_mem_map m; H e ▸ m', mem_map_of_mem⟩
@[simp]
theorem _root_.Function.Involutive.exists_mem_and_apply_eq_iff {f : α → α}
(hf : Function.Involutive f) (x : α) (l : List α) : (∃ y : α, y ∈ l ∧ f y = x) ↔ f x ∈ l :=
⟨by rintro ⟨y, h, rfl⟩; rwa [hf y], fun h => ⟨f x, h, hf _⟩⟩
theorem mem_map_of_involutive {f : α → α} (hf : Involutive f) {a : α} {l : List α} :
a ∈ map f l ↔ f a ∈ l := by rw [mem_map, hf.exists_mem_and_apply_eq_iff]
/-! ### length -/
alias ⟨_, length_pos_of_ne_nil⟩ := length_pos_iff
theorem length_pos_iff_ne_nil {l : List α} : 0 < length l ↔ l ≠ [] :=
⟨ne_nil_of_length_pos, length_pos_of_ne_nil⟩
theorem exists_of_length_succ {n} : ∀ l : List α, l.length = n + 1 → ∃ h t, l = h :: t
| [], H => absurd H.symm <| succ_ne_zero n
| h :: t, _ => ⟨h, t, rfl⟩
@[simp] lemma length_injective_iff : Injective (List.length : List α → ℕ) ↔ Subsingleton α := by
constructor
· intro h; refine ⟨fun x y => ?_⟩; (suffices [x] = [y] by simpa using this); apply h; rfl
· intros hα l1 l2 hl
induction l1 generalizing l2 <;> cases l2
· rfl
· cases hl
· cases hl
· next ih _ _ =>
congr
· subsingleton
· apply ih; simpa using hl
@[simp default+1] -- Raise priority above `length_injective_iff`.
lemma length_injective [Subsingleton α] : Injective (length : List α → ℕ) :=
length_injective_iff.mpr inferInstance
theorem length_eq_two {l : List α} : l.length = 2 ↔ ∃ a b, l = [a, b] :=
⟨fun _ => let [a, b] := l; ⟨a, b, rfl⟩, fun ⟨_, _, e⟩ => e ▸ rfl⟩
theorem length_eq_three {l : List α} : l.length = 3 ↔ ∃ a b c, l = [a, b, c] :=
⟨fun _ => let [a, b, c] := l; ⟨a, b, c, rfl⟩, fun ⟨_, _, _, e⟩ => e ▸ rfl⟩
/-! ### set-theoretic notation of lists -/
instance instSingletonList : Singleton α (List α) := ⟨fun x => [x]⟩
instance [DecidableEq α] : Insert α (List α) := ⟨List.insert⟩
instance [DecidableEq α] : LawfulSingleton α (List α) :=
{ insert_empty_eq := fun x =>
show (if x ∈ ([] : List α) then [] else [x]) = [x] from if_neg not_mem_nil }
theorem singleton_eq (x : α) : ({x} : List α) = [x] :=
rfl
theorem insert_neg [DecidableEq α] {x : α} {l : List α} (h : x ∉ l) :
Insert.insert x l = x :: l :=
insert_of_not_mem h
theorem insert_pos [DecidableEq α] {x : α} {l : List α} (h : x ∈ l) : Insert.insert x l = l :=
insert_of_mem h
theorem doubleton_eq [DecidableEq α] {x y : α} (h : x ≠ y) : ({x, y} : List α) = [x, y] := by
rw [insert_neg, singleton_eq]
rwa [singleton_eq, mem_singleton]
/-! ### bounded quantifiers over lists -/
theorem forall_mem_of_forall_mem_cons {p : α → Prop} {a : α} {l : List α} (h : ∀ x ∈ a :: l, p x) :
∀ x ∈ l, p x := (forall_mem_cons.1 h).2
theorem exists_mem_cons_of {p : α → Prop} {a : α} (l : List α) (h : p a) : ∃ x ∈ a :: l, p x :=
⟨a, mem_cons_self, h⟩
theorem exists_mem_cons_of_exists {p : α → Prop} {a : α} {l : List α} : (∃ x ∈ l, p x) →
∃ x ∈ a :: l, p x :=
fun ⟨x, xl, px⟩ => ⟨x, mem_cons_of_mem _ xl, px⟩
theorem or_exists_of_exists_mem_cons {p : α → Prop} {a : α} {l : List α} : (∃ x ∈ a :: l, p x) →
p a ∨ ∃ x ∈ l, p x :=
fun ⟨x, xal, px⟩ =>
Or.elim (eq_or_mem_of_mem_cons xal) (fun h : x = a => by rw [← h]; left; exact px)
fun h : x ∈ l => Or.inr ⟨x, h, px⟩
theorem exists_mem_cons_iff (p : α → Prop) (a : α) (l : List α) :
(∃ x ∈ a :: l, p x) ↔ p a ∨ ∃ x ∈ l, p x :=
Iff.intro or_exists_of_exists_mem_cons fun h =>
Or.elim h (exists_mem_cons_of l) exists_mem_cons_of_exists
/-! ### list subset -/
theorem cons_subset_of_subset_of_mem {a : α} {l m : List α}
(ainm : a ∈ m) (lsubm : l ⊆ m) : a::l ⊆ m :=
cons_subset.2 ⟨ainm, lsubm⟩
theorem append_subset_of_subset_of_subset {l₁ l₂ l : List α} (l₁subl : l₁ ⊆ l) (l₂subl : l₂ ⊆ l) :
l₁ ++ l₂ ⊆ l :=
fun _ h ↦ (mem_append.1 h).elim (@l₁subl _) (@l₂subl _)
theorem map_subset_iff {l₁ l₂ : List α} (f : α → β) (h : Injective f) :
map f l₁ ⊆ map f l₂ ↔ l₁ ⊆ l₂ := by
refine ⟨?_, map_subset f⟩; intro h2 x hx
rcases mem_map.1 (h2 (mem_map_of_mem hx)) with ⟨x', hx', hxx'⟩
cases h hxx'; exact hx'
/-! ### append -/
theorem append_eq_has_append {L₁ L₂ : List α} : List.append L₁ L₂ = L₁ ++ L₂ :=
rfl
theorem append_right_injective (s : List α) : Injective fun t ↦ s ++ t :=
fun _ _ ↦ append_cancel_left
theorem append_left_injective (t : List α) : Injective fun s ↦ s ++ t :=
fun _ _ ↦ append_cancel_right
/-! ### replicate -/
theorem eq_replicate_length {a : α} : ∀ {l : List α}, l = replicate l.length a ↔ ∀ b ∈ l, b = a
| [] => by simp
| (b :: l) => by simp [eq_replicate_length, replicate_succ]
theorem replicate_add (m n) (a : α) : replicate (m + n) a = replicate m a ++ replicate n a := by
rw [replicate_append_replicate]
theorem replicate_subset_singleton (n) (a : α) : replicate n a ⊆ [a] := fun _ h =>
mem_singleton.2 (eq_of_mem_replicate h)
theorem subset_singleton_iff {a : α} {L : List α} : L ⊆ [a] ↔ ∃ n, L = replicate n a := by
simp only [eq_replicate_iff, subset_def, mem_singleton, exists_eq_left']
theorem replicate_right_injective {n : ℕ} (hn : n ≠ 0) : Injective (@replicate α n) :=
fun _ _ h => (eq_replicate_iff.1 h).2 _ <| mem_replicate.2 ⟨hn, rfl⟩
theorem replicate_right_inj {a b : α} {n : ℕ} (hn : n ≠ 0) :
replicate n a = replicate n b ↔ a = b :=
(replicate_right_injective hn).eq_iff
theorem replicate_right_inj' {a b : α} : ∀ {n},
replicate n a = replicate n b ↔ n = 0 ∨ a = b
| 0 => by simp
| n + 1 => (replicate_right_inj n.succ_ne_zero).trans <| by simp only [n.succ_ne_zero, false_or]
theorem replicate_left_injective (a : α) : Injective (replicate · a) :=
LeftInverse.injective (length_replicate (n := ·))
theorem replicate_left_inj {a : α} {n m : ℕ} : replicate n a = replicate m a ↔ n = m :=
(replicate_left_injective a).eq_iff
@[simp]
theorem head?_flatten_replicate {n : ℕ} (h : n ≠ 0) (l : List α) :
(List.replicate n l).flatten.head? = l.head? := by
obtain ⟨n, rfl⟩ := Nat.exists_eq_succ_of_ne_zero h
induction l <;> simp [replicate]
@[simp]
theorem getLast?_flatten_replicate {n : ℕ} (h : n ≠ 0) (l : List α) :
(List.replicate n l).flatten.getLast? = l.getLast? := by
rw [← List.head?_reverse, ← List.head?_reverse, List.reverse_flatten, List.map_replicate,
List.reverse_replicate, head?_flatten_replicate h]
/-! ### pure -/
theorem mem_pure (x y : α) : x ∈ (pure y : List α) ↔ x = y := by simp
/-! ### bind -/
@[simp]
theorem bind_eq_flatMap {α β} (f : α → List β) (l : List α) : l >>= f = l.flatMap f :=
rfl
/-! ### concat -/
/-! ### reverse -/
theorem reverse_cons' (a : α) (l : List α) : reverse (a :: l) = concat (reverse l) a := by
simp only [reverse_cons, concat_eq_append]
theorem reverse_concat' (l : List α) (a : α) : (l ++ [a]).reverse = a :: l.reverse := by
rw [reverse_append]; rfl
@[simp]
theorem reverse_singleton (a : α) : reverse [a] = [a] :=
rfl
@[simp]
theorem reverse_involutive : Involutive (@reverse α) :=
reverse_reverse
@[simp]
theorem reverse_injective : Injective (@reverse α) :=
reverse_involutive.injective
theorem reverse_surjective : Surjective (@reverse α) :=
reverse_involutive.surjective
theorem reverse_bijective : Bijective (@reverse α) :=
reverse_involutive.bijective
theorem concat_eq_reverse_cons (a : α) (l : List α) : concat l a = reverse (a :: reverse l) := by
simp only [concat_eq_append, reverse_cons, reverse_reverse]
theorem map_reverseAux (f : α → β) (l₁ l₂ : List α) :
map f (reverseAux l₁ l₂) = reverseAux (map f l₁) (map f l₂) := by
simp only [reverseAux_eq, map_append, map_reverse]
-- TODO: Rename `List.reverse_perm` to `List.reverse_perm_self`
@[simp] lemma reverse_perm' : l₁.reverse ~ l₂ ↔ l₁ ~ l₂ where
mp := l₁.reverse_perm.symm.trans
mpr := l₁.reverse_perm.trans
@[simp] lemma perm_reverse : l₁ ~ l₂.reverse ↔ l₁ ~ l₂ where
mp hl := hl.trans l₂.reverse_perm
mpr hl := hl.trans l₂.reverse_perm.symm
/-! ### getLast -/
attribute [simp] getLast_cons
theorem getLast_append_singleton {a : α} (l : List α) :
getLast (l ++ [a]) (append_ne_nil_of_right_ne_nil l (cons_ne_nil a _)) = a := by
simp [getLast_append]
theorem getLast_append_of_right_ne_nil (l₁ l₂ : List α) (h : l₂ ≠ []) :
getLast (l₁ ++ l₂) (append_ne_nil_of_right_ne_nil l₁ h) = getLast l₂ h := by
induction l₁ with
| nil => simp
| cons _ _ ih => simp only [cons_append]; rw [List.getLast_cons]; exact ih
@[deprecated (since := "2025-02-06")]
alias getLast_append' := getLast_append_of_right_ne_nil
theorem getLast_concat' {a : α} (l : List α) : getLast (concat l a) (by simp) = a := by
simp
@[simp]
theorem getLast_singleton' (a : α) : getLast [a] (cons_ne_nil a []) = a := rfl
@[simp]
theorem getLast_cons_cons (a₁ a₂ : α) (l : List α) :
getLast (a₁ :: a₂ :: l) (cons_ne_nil _ _) = getLast (a₂ :: l) (cons_ne_nil a₂ l) :=
rfl
theorem dropLast_append_getLast : ∀ {l : List α} (h : l ≠ []), dropLast l ++ [getLast l h] = l
| [], h => absurd rfl h
| [_], _ => rfl
| a :: b :: l, h => by
rw [dropLast_cons₂, cons_append, getLast_cons (cons_ne_nil _ _)]
congr
exact dropLast_append_getLast (cons_ne_nil b l)
theorem getLast_congr {l₁ l₂ : List α} (h₁ : l₁ ≠ []) (h₂ : l₂ ≠ []) (h₃ : l₁ = l₂) :
getLast l₁ h₁ = getLast l₂ h₂ := by subst l₁; rfl
theorem getLast_replicate_succ (m : ℕ) (a : α) :
(replicate (m + 1) a).getLast (ne_nil_of_length_eq_add_one length_replicate) = a := by
simp only [replicate_succ']
exact getLast_append_singleton _
@[deprecated (since := "2025-02-07")]
alias getLast_filter' := getLast_filter_of_pos
/-! ### getLast? -/
theorem mem_getLast?_eq_getLast : ∀ {l : List α} {x : α}, x ∈ l.getLast? → ∃ h, x = getLast l h
| [], x, hx => False.elim <| by simp at hx
| [a], x, hx =>
have : a = x := by simpa using hx
this ▸ ⟨cons_ne_nil a [], rfl⟩
| a :: b :: l, x, hx => by
rw [getLast?_cons_cons] at hx
rcases mem_getLast?_eq_getLast hx with ⟨_, h₂⟩
use cons_ne_nil _ _
assumption
theorem getLast?_eq_getLast_of_ne_nil : ∀ {l : List α} (h : l ≠ []), l.getLast? = some (l.getLast h)
| [], h => (h rfl).elim
| [_], _ => rfl
| _ :: b :: l, _ => @getLast?_eq_getLast_of_ne_nil (b :: l) (cons_ne_nil _ _)
theorem mem_getLast?_cons {x y : α} : ∀ {l : List α}, x ∈ l.getLast? → x ∈ (y :: l).getLast?
| [], _ => by contradiction
| _ :: _, h => h
theorem dropLast_append_getLast? : ∀ {l : List α}, ∀ a ∈ l.getLast?, dropLast l ++ [a] = l
| [], a, ha => (Option.not_mem_none a ha).elim
| [a], _, rfl => rfl
| a :: b :: l, c, hc => by
rw [getLast?_cons_cons] at hc
rw [dropLast_cons₂, cons_append, dropLast_append_getLast? _ hc]
theorem getLastI_eq_getLast? [Inhabited α] : ∀ l : List α, l.getLastI = l.getLast?.iget
| [] => by simp [getLastI, Inhabited.default]
| [_] => rfl
| [_, _] => rfl
| [_, _, _] => rfl
| _ :: _ :: c :: l => by simp [getLastI, getLastI_eq_getLast? (c :: l)]
theorem getLast?_append_cons :
∀ (l₁ : List α) (a : α) (l₂ : List α), getLast? (l₁ ++ a :: l₂) = getLast? (a :: l₂)
| [], _, _ => rfl
| [_], _, _ => rfl
| b :: c :: l₁, a, l₂ => by rw [cons_append, cons_append, getLast?_cons_cons,
← cons_append, getLast?_append_cons (c :: l₁)]
theorem getLast?_append_of_ne_nil (l₁ : List α) :
∀ {l₂ : List α} (_ : l₂ ≠ []), getLast? (l₁ ++ l₂) = getLast? l₂
| [], hl₂ => by contradiction
| b :: l₂, _ => getLast?_append_cons l₁ b l₂
theorem mem_getLast?_append_of_mem_getLast? {l₁ l₂ : List α} {x : α} (h : x ∈ l₂.getLast?) :
x ∈ (l₁ ++ l₂).getLast? := by
cases l₂
· contradiction
· rw [List.getLast?_append_cons]
exact h
/-! ### head(!?) and tail -/
@[simp]
theorem head!_nil [Inhabited α] : ([] : List α).head! = default := rfl
@[simp] theorem head_cons_tail (x : List α) (h : x ≠ []) : x.head h :: x.tail = x := by
cases x <;> simp at h ⊢
theorem head_eq_getElem_zero {l : List α} (hl : l ≠ []) :
l.head hl = l[0]'(length_pos_iff.2 hl) :=
(getElem_zero _).symm
theorem head!_eq_head? [Inhabited α] (l : List α) : head! l = (head? l).iget := by cases l <;> rfl
theorem surjective_head! [Inhabited α] : Surjective (@head! α _) := fun x => ⟨[x], rfl⟩
theorem surjective_head? : Surjective (@head? α) :=
Option.forall.2 ⟨⟨[], rfl⟩, fun x => ⟨[x], rfl⟩⟩
theorem surjective_tail : Surjective (@tail α)
| [] => ⟨[], rfl⟩
| a :: l => ⟨a :: a :: l, rfl⟩
theorem eq_cons_of_mem_head? {x : α} : ∀ {l : List α}, x ∈ l.head? → l = x :: tail l
| [], h => (Option.not_mem_none _ h).elim
| a :: l, h => by
simp only [head?, Option.mem_def, Option.some_inj] at h
exact h ▸ rfl
@[simp] theorem head!_cons [Inhabited α] (a : α) (l : List α) : head! (a :: l) = a := rfl
@[simp]
theorem head!_append [Inhabited α] (t : List α) {s : List α} (h : s ≠ []) :
head! (s ++ t) = head! s := by
induction s
· contradiction
· rfl
theorem mem_head?_append_of_mem_head? {s t : List α} {x : α} (h : x ∈ s.head?) :
x ∈ (s ++ t).head? := by
cases s
· contradiction
· exact h
theorem head?_append_of_ne_nil :
∀ (l₁ : List α) {l₂ : List α} (_ : l₁ ≠ []), head? (l₁ ++ l₂) = head? l₁
| _ :: _, _, _ => rfl
theorem tail_append_singleton_of_ne_nil {a : α} {l : List α} (h : l ≠ nil) :
tail (l ++ [a]) = tail l ++ [a] := by
induction l
· contradiction
· rw [tail, cons_append, tail]
theorem cons_head?_tail : ∀ {l : List α} {a : α}, a ∈ head? l → a :: tail l = l
| [], a, h => by contradiction
| b :: l, a, h => by
simp? at h says simp only [head?_cons, Option.mem_def, Option.some.injEq] at h
simp [h]
theorem head!_mem_head? [Inhabited α] : ∀ {l : List α}, l ≠ [] → head! l ∈ head? l
| [], h => by contradiction
| _ :: _, _ => rfl
theorem cons_head!_tail [Inhabited α] {l : List α} (h : l ≠ []) : head! l :: tail l = l :=
cons_head?_tail (head!_mem_head? h)
theorem head!_mem_self [Inhabited α] {l : List α} (h : l ≠ nil) : l.head! ∈ l := by
have h' : l.head! ∈ l.head! :: l.tail := mem_cons_self
rwa [cons_head!_tail h] at h'
theorem get_eq_getElem? (l : List α) (i : Fin l.length) :
l.get i = l[i]?.get (by simp [getElem?_eq_getElem]) := by
simp
@[deprecated (since := "2025-02-15")] alias get_eq_get? := get_eq_getElem?
theorem exists_mem_iff_getElem {l : List α} {p : α → Prop} :
(∃ x ∈ l, p x) ↔ ∃ (i : ℕ) (_ : i < l.length), p l[i] := by
simp only [mem_iff_getElem]
exact ⟨fun ⟨_x, ⟨i, hi, hix⟩, hxp⟩ ↦ ⟨i, hi, hix ▸ hxp⟩, fun ⟨i, hi, hp⟩ ↦ ⟨_, ⟨i, hi, rfl⟩, hp⟩⟩
theorem forall_mem_iff_getElem {l : List α} {p : α → Prop} :
(∀ x ∈ l, p x) ↔ ∀ (i : ℕ) (_ : i < l.length), p l[i] := by
simp [mem_iff_getElem, @forall_swap α]
theorem get_tail (l : List α) (i) (h : i < l.tail.length)
(h' : i + 1 < l.length := (by simp only [length_tail] at h; omega)) :
l.tail.get ⟨i, h⟩ = l.get ⟨i + 1, h'⟩ := by
cases l <;> [cases h; rfl]
/-! ### sublists -/
attribute [refl] List.Sublist.refl
theorem Sublist.cons_cons {l₁ l₂ : List α} (a : α) (s : l₁ <+ l₂) : a :: l₁ <+ a :: l₂ :=
Sublist.cons₂ _ s
lemma cons_sublist_cons' {a b : α} : a :: l₁ <+ b :: l₂ ↔ a :: l₁ <+ l₂ ∨ a = b ∧ l₁ <+ l₂ := by
constructor
· rintro (_ | _)
· exact Or.inl ‹_›
· exact Or.inr ⟨rfl, ‹_›⟩
· rintro (h | ⟨rfl, h⟩)
· exact h.cons _
· rwa [cons_sublist_cons]
theorem sublist_cons_of_sublist (a : α) (h : l₁ <+ l₂) : l₁ <+ a :: l₂ := h.cons _
@[deprecated (since := "2025-02-07")]
alias sublist_nil_iff_eq_nil := sublist_nil
@[simp] lemma sublist_singleton {l : List α} {a : α} : l <+ [a] ↔ l = [] ∨ l = [a] := by
constructor <;> rintro (_ | _) <;> aesop
theorem Sublist.antisymm (s₁ : l₁ <+ l₂) (s₂ : l₂ <+ l₁) : l₁ = l₂ :=
s₁.eq_of_length_le s₂.length_le
/-- If the first element of two lists are different, then a sublist relation can be reduced. -/
theorem Sublist.of_cons_of_ne {a b} (h₁ : a ≠ b) (h₂ : a :: l₁ <+ b :: l₂) : a :: l₁ <+ l₂ :=
match h₁, h₂ with
| _, .cons _ h => h
/-! ### indexOf -/
section IndexOf
variable [DecidableEq α]
theorem idxOf_cons_eq {a b : α} (l : List α) : b = a → idxOf a (b :: l) = 0
| e => by rw [← e]; exact idxOf_cons_self
@[deprecated (since := "2025-01-30")] alias indexOf_cons_eq := idxOf_cons_eq
@[simp]
theorem idxOf_cons_ne {a b : α} (l : List α) : b ≠ a → idxOf a (b :: l) = succ (idxOf a l)
| h => by simp only [idxOf_cons, Bool.cond_eq_ite, beq_iff_eq, if_neg h]
@[deprecated (since := "2025-01-30")] alias indexOf_cons_ne := idxOf_cons_ne
theorem idxOf_eq_length_iff {a : α} {l : List α} : idxOf a l = length l ↔ a ∉ l := by
induction l with
| nil => exact iff_of_true rfl not_mem_nil
| cons b l ih =>
simp only [length, mem_cons, idxOf_cons, eq_comm]
rw [cond_eq_if]
split_ifs with h <;> simp at h
· exact iff_of_false (by rintro ⟨⟩) fun H => H <| Or.inl h.symm
· simp only [Ne.symm h, false_or]
rw [← ih]
exact succ_inj
@[simp]
theorem idxOf_of_not_mem {l : List α} {a : α} : a ∉ l → idxOf a l = length l :=
idxOf_eq_length_iff.2
@[deprecated (since := "2025-01-30")] alias indexOf_of_not_mem := idxOf_of_not_mem
theorem idxOf_le_length {a : α} {l : List α} : idxOf a l ≤ length l := by
induction l with | nil => rfl | cons b l ih => ?_
simp only [length, idxOf_cons, cond_eq_if, beq_iff_eq]
by_cases h : b = a
· rw [if_pos h]; exact Nat.zero_le _
· rw [if_neg h]; exact succ_le_succ ih
@[deprecated (since := "2025-01-30")] alias indexOf_le_length := idxOf_le_length
theorem idxOf_lt_length_iff {a} {l : List α} : idxOf a l < length l ↔ a ∈ l :=
⟨fun h => Decidable.byContradiction fun al => Nat.ne_of_lt h <| idxOf_eq_length_iff.2 al,
fun al => (lt_of_le_of_ne idxOf_le_length) fun h => idxOf_eq_length_iff.1 h al⟩
@[deprecated (since := "2025-01-30")] alias indexOf_lt_length_iff := idxOf_lt_length_iff
theorem idxOf_append_of_mem {a : α} (h : a ∈ l₁) : idxOf a (l₁ ++ l₂) = idxOf a l₁ := by
induction l₁ with
| nil =>
exfalso
exact not_mem_nil h
| cons d₁ t₁ ih =>
rw [List.cons_append]
by_cases hh : d₁ = a
· iterate 2 rw [idxOf_cons_eq _ hh]
rw [idxOf_cons_ne _ hh, idxOf_cons_ne _ hh, ih (mem_of_ne_of_mem (Ne.symm hh) h)]
@[deprecated (since := "2025-01-30")] alias indexOf_append_of_mem := idxOf_append_of_mem
theorem idxOf_append_of_not_mem {a : α} (h : a ∉ l₁) :
idxOf a (l₁ ++ l₂) = l₁.length + idxOf a l₂ := by
induction l₁ with
| nil => rw [List.nil_append, List.length, Nat.zero_add]
| cons d₁ t₁ ih =>
rw [List.cons_append, idxOf_cons_ne _ (ne_of_not_mem_cons h).symm, List.length,
ih (not_mem_of_not_mem_cons h), Nat.succ_add]
@[deprecated (since := "2025-01-30")] alias indexOf_append_of_not_mem := idxOf_append_of_not_mem
end IndexOf
/-! ### nth element -/
section deprecated
@[simp]
theorem getElem?_length (l : List α) : l[l.length]? = none := getElem?_eq_none le_rfl
/-- A version of `getElem_map` that can be used for rewriting. -/
theorem getElem_map_rev (f : α → β) {l} {n : Nat} {h : n < l.length} :
f l[n] = (map f l)[n]'((l.length_map f).symm ▸ h) := Eq.symm (getElem_map _)
theorem get_length_sub_one {l : List α} (h : l.length - 1 < l.length) :
l.get ⟨l.length - 1, h⟩ = l.getLast (by rintro rfl; exact Nat.lt_irrefl 0 h) :=
(getLast_eq_getElem _).symm
theorem take_one_drop_eq_of_lt_length {l : List α} {n : ℕ} (h : n < l.length) :
(l.drop n).take 1 = [l.get ⟨n, h⟩] := by
rw [drop_eq_getElem_cons h, take, take]
simp
theorem ext_getElem?' {l₁ l₂ : List α} (h' : ∀ n < max l₁.length l₂.length, l₁[n]? = l₂[n]?) :
l₁ = l₂ := by
apply ext_getElem?
intro n
rcases Nat.lt_or_ge n <| max l₁.length l₂.length with hn | hn
· exact h' n hn
· simp_all [Nat.max_le, getElem?_eq_none]
@[deprecated (since := "2025-02-15")] alias ext_get?' := ext_getElem?'
@[deprecated (since := "2025-02-15")] alias ext_get?_iff := List.ext_getElem?_iff
theorem ext_get_iff {l₁ l₂ : List α} :
l₁ = l₂ ↔ l₁.length = l₂.length ∧ ∀ n h₁ h₂, get l₁ ⟨n, h₁⟩ = get l₂ ⟨n, h₂⟩ := by
constructor
· rintro rfl
exact ⟨rfl, fun _ _ _ ↦ rfl⟩
· intro ⟨h₁, h₂⟩
exact ext_get h₁ h₂
theorem ext_getElem?_iff' {l₁ l₂ : List α} : l₁ = l₂ ↔
∀ n < max l₁.length l₂.length, l₁[n]? = l₂[n]? :=
⟨by rintro rfl _ _; rfl, ext_getElem?'⟩
@[deprecated (since := "2025-02-15")] alias ext_get?_iff' := ext_getElem?_iff'
/-- If two lists `l₁` and `l₂` are the same length and `l₁[n]! = l₂[n]!` for all `n`,
then the lists are equal. -/
theorem ext_getElem! [Inhabited α] (hl : length l₁ = length l₂) (h : ∀ n : ℕ, l₁[n]! = l₂[n]!) :
l₁ = l₂ :=
ext_getElem hl fun n h₁ h₂ ↦ by simpa only [← getElem!_pos] using h n
@[simp]
theorem getElem_idxOf [DecidableEq α] {a : α} : ∀ {l : List α} (h : idxOf a l < l.length),
l[idxOf a l] = a
| b :: l, h => by
by_cases h' : b = a <;>
simp [h', if_pos, if_false, getElem_idxOf]
@[deprecated (since := "2025-01-30")] alias getElem_indexOf := getElem_idxOf
-- This is incorrectly named and should be `get_idxOf`;
-- this already exists, so will require a deprecation dance.
theorem idxOf_get [DecidableEq α] {a : α} {l : List α} (h) : get l ⟨idxOf a l, h⟩ = a := by
simp
@[deprecated (since := "2025-01-30")] alias indexOf_get := idxOf_get
@[simp]
theorem getElem?_idxOf [DecidableEq α] {a : α} {l : List α} (h : a ∈ l) :
l[idxOf a l]? = some a := by
rw [getElem?_eq_getElem, getElem_idxOf (idxOf_lt_length_iff.2 h)]
@[deprecated (since := "2025-01-30")] alias getElem?_indexOf := getElem?_idxOf
@[deprecated (since := "2025-02-15")] alias idxOf_get? := getElem?_idxOf
@[deprecated (since := "2025-01-30")] alias indexOf_get? := getElem?_idxOf
theorem idxOf_inj [DecidableEq α] {l : List α} {x y : α} (hx : x ∈ l) (hy : y ∈ l) :
idxOf x l = idxOf y l ↔ x = y :=
⟨fun h => by
have x_eq_y :
get l ⟨idxOf x l, idxOf_lt_length_iff.2 hx⟩ =
get l ⟨idxOf y l, idxOf_lt_length_iff.2 hy⟩ := by
simp only [h]
simp only [idxOf_get] at x_eq_y; exact x_eq_y, fun h => by subst h; rfl⟩
@[deprecated (since := "2025-01-30")] alias indexOf_inj := idxOf_inj
theorem get_reverse' (l : List α) (n) (hn') :
l.reverse.get n = l.get ⟨l.length - 1 - n, hn'⟩ := by
simp
theorem eq_cons_of_length_one {l : List α} (h : l.length = 1) : l = [l.get ⟨0, by omega⟩] := by
refine ext_get (by convert h) fun n h₁ h₂ => ?_
simp
congr
omega
end deprecated
@[simp]
theorem getElem_set_of_ne {l : List α} {i j : ℕ} (h : i ≠ j) (a : α)
(hj : j < (l.set i a).length) :
(l.set i a)[j] = l[j]'(by simpa using hj) := by
rw [← Option.some_inj, ← List.getElem?_eq_getElem, List.getElem?_set_ne h,
List.getElem?_eq_getElem]
/-! ### map -/
-- `List.map_const` (the version with `Function.const` instead of a lambda) is already tagged
-- `simp` in Core
-- TODO: Upstream the tagging to Core?
attribute [simp] map_const'
theorem flatMap_pure_eq_map (f : α → β) (l : List α) : l.flatMap (pure ∘ f) = map f l :=
.symm <| map_eq_flatMap ..
theorem flatMap_congr {l : List α} {f g : α → List β} (h : ∀ x ∈ l, f x = g x) :
l.flatMap f = l.flatMap g :=
(congr_arg List.flatten <| map_congr_left h :)
theorem infix_flatMap_of_mem {a : α} {as : List α} (h : a ∈ as) (f : α → List α) :
f a <:+: as.flatMap f :=
infix_of_mem_flatten (mem_map_of_mem h)
@[simp]
theorem map_eq_map {α β} (f : α → β) (l : List α) : f <$> l = map f l :=
rfl
/-- A single `List.map` of a composition of functions is equal to
composing a `List.map` with another `List.map`, fully applied.
This is the reverse direction of `List.map_map`.
-/
theorem comp_map (h : β → γ) (g : α → β) (l : List α) : map (h ∘ g) l = map h (map g l) :=
map_map.symm
/-- Composing a `List.map` with another `List.map` is equal to
a single `List.map` of composed functions.
-/
@[simp]
theorem map_comp_map (g : β → γ) (f : α → β) : map g ∘ map f = map (g ∘ f) := by
ext l; rw [comp_map, Function.comp_apply]
section map_bijectivity
theorem _root_.Function.LeftInverse.list_map {f : α → β} {g : β → α} (h : LeftInverse f g) :
LeftInverse (map f) (map g)
| [] => by simp_rw [map_nil]
| x :: xs => by simp_rw [map_cons, h x, h.list_map xs]
nonrec theorem _root_.Function.RightInverse.list_map {f : α → β} {g : β → α}
(h : RightInverse f g) : RightInverse (map f) (map g) :=
h.list_map
nonrec theorem _root_.Function.Involutive.list_map {f : α → α}
(h : Involutive f) : Involutive (map f) :=
Function.LeftInverse.list_map h
@[simp]
theorem map_leftInverse_iff {f : α → β} {g : β → α} :
LeftInverse (map f) (map g) ↔ LeftInverse f g :=
⟨fun h x => by injection h [x], (·.list_map)⟩
@[simp]
theorem map_rightInverse_iff {f : α → β} {g : β → α} :
RightInverse (map f) (map g) ↔ RightInverse f g := map_leftInverse_iff
@[simp]
theorem map_involutive_iff {f : α → α} :
Involutive (map f) ↔ Involutive f := map_leftInverse_iff
theorem _root_.Function.Injective.list_map {f : α → β} (h : Injective f) :
Injective (map f)
| [], [], _ => rfl
| x :: xs, y :: ys, hxy => by
injection hxy with hxy hxys
rw [h hxy, h.list_map hxys]
@[simp]
theorem map_injective_iff {f : α → β} : Injective (map f) ↔ Injective f := by
refine ⟨fun h x y hxy => ?_, (·.list_map)⟩
suffices [x] = [y] by simpa using this
apply h
simp [hxy]
theorem _root_.Function.Surjective.list_map {f : α → β} (h : Surjective f) :
Surjective (map f) :=
let ⟨_, h⟩ := h.hasRightInverse; h.list_map.surjective
@[simp]
theorem map_surjective_iff {f : α → β} : Surjective (map f) ↔ Surjective f := by
refine ⟨fun h x => ?_, (·.list_map)⟩
let ⟨[y], hxy⟩ := h [x]
exact ⟨_, List.singleton_injective hxy⟩
theorem _root_.Function.Bijective.list_map {f : α → β} (h : Bijective f) : Bijective (map f) :=
⟨h.1.list_map, h.2.list_map⟩
@[simp]
theorem map_bijective_iff {f : α → β} : Bijective (map f) ↔ Bijective f := by
simp_rw [Function.Bijective, map_injective_iff, map_surjective_iff]
end map_bijectivity
theorem eq_of_mem_map_const {b₁ b₂ : β} {l : List α} (h : b₁ ∈ map (const α b₂) l) :
b₁ = b₂ := by rw [map_const] at h; exact eq_of_mem_replicate h
/-- `eq_nil_or_concat` in simp normal form -/
lemma eq_nil_or_concat' (l : List α) : l = [] ∨ ∃ L b, l = L ++ [b] := by
simpa using l.eq_nil_or_concat
/-! ### foldl, foldr -/
theorem foldl_ext (f g : α → β → α) (a : α) {l : List β} (H : ∀ a : α, ∀ b ∈ l, f a b = g a b) :
foldl f a l = foldl g a l := by
induction l generalizing a with
| nil => rfl
| cons hd tl ih =>
unfold foldl
rw [ih _ fun a b bin => H a b <| mem_cons_of_mem _ bin, H a hd mem_cons_self]
theorem foldr_ext (f g : α → β → β) (b : β) {l : List α} (H : ∀ a ∈ l, ∀ b : β, f a b = g a b) :
foldr f b l = foldr g b l := by
induction l with | nil => rfl | cons hd tl ih => ?_
simp only [mem_cons, or_imp, forall_and, forall_eq] at H
simp only [foldr, ih H.2, H.1]
theorem foldl_concat
(f : β → α → β) (b : β) (x : α) (xs : List α) :
List.foldl f b (xs ++ [x]) = f (List.foldl f b xs) x := by
simp only [List.foldl_append, List.foldl]
theorem foldr_concat
(f : α → β → β) (b : β) (x : α) (xs : List α) :
List.foldr f b (xs ++ [x]) = (List.foldr f (f x b) xs) := by
simp only [List.foldr_append, List.foldr]
theorem foldl_fixed' {f : α → β → α} {a : α} (hf : ∀ b, f a b = a) : ∀ l : List β, foldl f a l = a
| [] => rfl
| b :: l => by rw [foldl_cons, hf b, foldl_fixed' hf l]
theorem foldr_fixed' {f : α → β → β} {b : β} (hf : ∀ a, f a b = b) : ∀ l : List α, foldr f b l = b
| [] => rfl
| a :: l => by rw [foldr_cons, foldr_fixed' hf l, hf a]
@[simp]
theorem foldl_fixed {a : α} : ∀ l : List β, foldl (fun a _ => a) a l = a :=
foldl_fixed' fun _ => rfl
@[simp]
theorem foldr_fixed {b : β} : ∀ l : List α, foldr (fun _ b => b) b l = b :=
foldr_fixed' fun _ => rfl
@[deprecated foldr_cons_nil (since := "2025-02-10")]
theorem foldr_eta (l : List α) : foldr cons [] l = l := foldr_cons_nil
theorem reverse_foldl {l : List α} : reverse (foldl (fun t h => h :: t) [] l) = l := by
simp
theorem foldl_hom₂ (l : List ι) (f : α → β → γ) (op₁ : α → ι → α) (op₂ : β → ι → β)
(op₃ : γ → ι → γ) (a : α) (b : β) (h : ∀ a b i, f (op₁ a i) (op₂ b i) = op₃ (f a b) i) :
foldl op₃ (f a b) l = f (foldl op₁ a l) (foldl op₂ b l) :=
Eq.symm <| by
revert a b
induction l <;> intros <;> [rfl; simp only [*, foldl]]
theorem foldr_hom₂ (l : List ι) (f : α → β → γ) (op₁ : ι → α → α) (op₂ : ι → β → β)
(op₃ : ι → γ → γ) (a : α) (b : β) (h : ∀ a b i, f (op₁ i a) (op₂ i b) = op₃ i (f a b)) :
foldr op₃ (f a b) l = f (foldr op₁ a l) (foldr op₂ b l) := by
revert a
induction l <;> intros <;> [rfl; simp only [*, foldr]]
theorem injective_foldl_comp {l : List (α → α)} {f : α → α}
(hl : ∀ f ∈ l, Function.Injective f) (hf : Function.Injective f) :
Function.Injective (@List.foldl (α → α) (α → α) Function.comp f l) := by
induction l generalizing f with
| nil => exact hf
| cons lh lt l_ih =>
apply l_ih fun _ h => hl _ (List.mem_cons_of_mem _ h)
apply Function.Injective.comp hf
apply hl _ mem_cons_self
/-- Consider two lists `l₁` and `l₂` with designated elements `a₁` and `a₂` somewhere in them:
`l₁ = x₁ ++ [a₁] ++ z₁` and `l₂ = x₂ ++ [a₂] ++ z₂`.
Assume the designated element `a₂` is present in neither `x₁` nor `z₁`.
We conclude that the lists are equal (`l₁ = l₂`) if and only if their respective parts are equal
(`x₁ = x₂ ∧ a₁ = a₂ ∧ z₁ = z₂`). -/
lemma append_cons_inj_of_not_mem {x₁ x₂ z₁ z₂ : List α} {a₁ a₂ : α}
(notin_x : a₂ ∉ x₁) (notin_z : a₂ ∉ z₁) :
x₁ ++ a₁ :: z₁ = x₂ ++ a₂ :: z₂ ↔ x₁ = x₂ ∧ a₁ = a₂ ∧ z₁ = z₂ := by
constructor
· simp only [append_eq_append_iff, cons_eq_append_iff, cons_eq_cons]
rintro (⟨c, rfl, ⟨rfl, rfl, rfl⟩ | ⟨d, rfl, rfl⟩⟩ |
⟨c, rfl, ⟨rfl, rfl, rfl⟩ | ⟨d, rfl, rfl⟩⟩) <;> simp_all
· rintro ⟨rfl, rfl, rfl⟩
rfl
section FoldlEqFoldr
-- foldl and foldr coincide when f is commutative and associative
variable {f : α → α → α}
theorem foldl1_eq_foldr1 [hassoc : Std.Associative f] :
∀ a b l, foldl f a (l ++ [b]) = foldr f b (a :: l)
| _, _, nil => rfl
| a, b, c :: l => by
simp only [cons_append, foldl_cons, foldr_cons, foldl1_eq_foldr1 _ _ l]
rw [hassoc.assoc]
theorem foldl_eq_of_comm_of_assoc [hcomm : Std.Commutative f] [hassoc : Std.Associative f] :
∀ a b l, foldl f a (b :: l) = f b (foldl f a l)
| a, b, nil => hcomm.comm a b
| a, b, c :: l => by
simp only [foldl_cons]
have : RightCommutative f := inferInstance
rw [← foldl_eq_of_comm_of_assoc .., this.right_comm, foldl_cons]
theorem foldl_eq_foldr [Std.Commutative f] [Std.Associative f] :
∀ a l, foldl f a l = foldr f a l
| _, nil => rfl
| a, b :: l => by
simp only [foldr_cons, foldl_eq_of_comm_of_assoc]
rw [foldl_eq_foldr a l]
end FoldlEqFoldr
section FoldlEqFoldlr'
variable {f : α → β → α}
variable (hf : ∀ a b c, f (f a b) c = f (f a c) b)
include hf
theorem foldl_eq_of_comm' : ∀ a b l, foldl f a (b :: l) = f (foldl f a l) b
| _, _, [] => rfl
| a, b, c :: l => by rw [foldl, foldl, foldl, ← foldl_eq_of_comm' .., foldl, hf]
theorem foldl_eq_foldr' : ∀ a l, foldl f a l = foldr (flip f) a l
| _, [] => rfl
| a, b :: l => by rw [foldl_eq_of_comm' hf, foldr, foldl_eq_foldr' ..]; rfl
end FoldlEqFoldlr'
section FoldlEqFoldlr'
variable {f : α → β → β}
theorem foldr_eq_of_comm' (hf : ∀ a b c, f a (f b c) = f b (f a c)) :
∀ a b l, foldr f a (b :: l) = foldr f (f b a) l
| _, _, [] => rfl
| a, b, c :: l => by rw [foldr, foldr, foldr, hf, ← foldr_eq_of_comm' hf ..]; rfl
end FoldlEqFoldlr'
section
variable {op : α → α → α} [ha : Std.Associative op]
/-- Notation for `op a b`. -/
local notation a " ⋆ " b => op a b
/-- Notation for `foldl op a l`. -/
local notation l " <*> " a => foldl op a l
theorem foldl_op_eq_op_foldr_assoc :
∀ {l : List α} {a₁ a₂}, ((l <*> a₁) ⋆ a₂) = a₁ ⋆ l.foldr (· ⋆ ·) a₂
| [], _, _ => rfl
| a :: l, a₁, a₂ => by
simp only [foldl_cons, foldr_cons, foldl_assoc, ha.assoc]; rw [foldl_op_eq_op_foldr_assoc]
variable [hc : Std.Commutative op]
theorem foldl_assoc_comm_cons {l : List α} {a₁ a₂} : ((a₁ :: l) <*> a₂) = a₁ ⋆ l <*> a₂ := by
rw [foldl_cons, hc.comm, foldl_assoc]
end
/-! ### foldlM, foldrM, mapM -/
section FoldlMFoldrM
variable {m : Type v → Type w} [Monad m]
variable [LawfulMonad m]
theorem foldrM_eq_foldr (f : α → β → m β) (b l) :
foldrM f b l = foldr (fun a mb => mb >>= f a) (pure b) l := by induction l <;> simp [*]
theorem foldlM_eq_foldl (f : β → α → m β) (b l) :
List.foldlM f b l = foldl (fun mb a => mb >>= fun b => f b a) (pure b) l := by
suffices h :
∀ mb : m β, (mb >>= fun b => List.foldlM f b l) = foldl (fun mb a => mb >>= fun b => f b a) mb l
by simp [← h (pure b)]
induction l with
| nil => intro; simp
| cons _ _ l_ih => intro; simp only [List.foldlM, foldl, ← l_ih, functor_norm]
end FoldlMFoldrM
/-! ### intersperse -/
@[deprecated (since := "2025-02-07")] alias intersperse_singleton := intersperse_single
@[deprecated (since := "2025-02-07")] alias intersperse_cons_cons := intersperse_cons₂
/-! ### map for partial functions -/
@[deprecated "Deprecated without replacement." (since := "2025-02-07")]
theorem sizeOf_lt_sizeOf_of_mem [SizeOf α] {x : α} {l : List α} (hx : x ∈ l) :
SizeOf.sizeOf x < SizeOf.sizeOf l := by
induction l with | nil => ?_ | cons h t ih => ?_ <;> cases hx <;> rw [cons.sizeOf_spec]
· omega
· specialize ih ‹_›
omega
/-! ### filter -/
theorem length_eq_length_filter_add {l : List (α)} (f : α → Bool) :
l.length = (l.filter f).length + (l.filter (! f ·)).length := by
simp_rw [← List.countP_eq_length_filter, l.length_eq_countP_add_countP f, Bool.not_eq_true,
Bool.decide_eq_false]
/-! ### filterMap -/
theorem filterMap_eq_flatMap_toList (f : α → Option β) (l : List α) :
l.filterMap f = l.flatMap fun a ↦ (f a).toList := by
induction l with | nil => ?_ | cons a l ih => ?_ <;> simp [filterMap_cons]
rcases f a <;> simp [ih]
theorem filterMap_congr {f g : α → Option β} {l : List α}
(h : ∀ x ∈ l, f x = g x) : l.filterMap f = l.filterMap g := by
induction l <;> simp_all [filterMap_cons]
theorem filterMap_eq_map_iff_forall_eq_some {f : α → Option β} {g : α → β} {l : List α} :
l.filterMap f = l.map g ↔ ∀ x ∈ l, f x = some (g x) where
mp := by
induction l with | nil => simp | cons a l ih => ?_
rcases ha : f a with - | b <;> simp [ha, filterMap_cons]
· intro h
simpa [show (filterMap f l).length = l.length + 1 from by simp[h], Nat.add_one_le_iff]
using List.length_filterMap_le f l
· rintro rfl h
exact ⟨rfl, ih h⟩
mpr h := Eq.trans (filterMap_congr <| by simpa) (congr_fun filterMap_eq_map _)
/-! ### filter -/
section Filter
variable {p : α → Bool}
theorem filter_singleton {a : α} : [a].filter p = bif p a then [a] else [] :=
rfl
theorem filter_eq_foldr (p : α → Bool) (l : List α) :
filter p l = foldr (fun a out => bif p a then a :: out else out) [] l := by
induction l <;> simp [*, filter]; rfl
#adaptation_note /-- nightly-2024-07-27
This has to be temporarily renamed to avoid an unintentional collision.
The prime should be removed at nightly-2024-07-27. -/
@[simp]
theorem filter_subset' (l : List α) : filter p l ⊆ l :=
filter_sublist.subset
theorem of_mem_filter {a : α} {l} (h : a ∈ filter p l) : p a := (mem_filter.1 h).2
theorem mem_of_mem_filter {a : α} {l} (h : a ∈ filter p l) : a ∈ l :=
filter_subset' l h
theorem mem_filter_of_mem {a : α} {l} (h₁ : a ∈ l) (h₂ : p a) : a ∈ filter p l :=
mem_filter.2 ⟨h₁, h₂⟩
@[deprecated (since := "2025-02-07")] alias monotone_filter_left := filter_subset
variable (p)
theorem monotone_filter_right (l : List α) ⦃p q : α → Bool⦄
(h : ∀ a, p a → q a) : l.filter p <+ l.filter q := by
induction l with
| nil => rfl
| cons hd tl IH =>
by_cases hp : p hd
· rw [filter_cons_of_pos hp, filter_cons_of_pos (h _ hp)]
exact IH.cons_cons hd
· rw [filter_cons_of_neg hp]
by_cases hq : q hd
· rw [filter_cons_of_pos hq]
exact sublist_cons_of_sublist hd IH
· rw [filter_cons_of_neg hq]
exact IH
lemma map_filter {f : α → β} (hf : Injective f) (l : List α)
[DecidablePred fun b => ∃ a, p a ∧ f a = b] :
(l.filter p).map f = (l.map f).filter fun b => ∃ a, p a ∧ f a = b := by
simp [comp_def, filter_map, hf.eq_iff]
@[deprecated (since := "2025-02-07")] alias map_filter' := map_filter
lemma filter_attach' (l : List α) (p : {a // a ∈ l} → Bool) [DecidableEq α] :
l.attach.filter p =
(l.filter fun x => ∃ h, p ⟨x, h⟩).attach.map (Subtype.map id fun _ => mem_of_mem_filter) := by
classical
refine map_injective_iff.2 Subtype.coe_injective ?_
simp [comp_def, map_filter _ Subtype.coe_injective]
lemma filter_attach (l : List α) (p : α → Bool) :
(l.attach.filter fun x => p x : List {x // x ∈ l}) =
(l.filter p).attach.map (Subtype.map id fun _ => mem_of_mem_filter) :=
map_injective_iff.2 Subtype.coe_injective <| by
simp_rw [map_map, comp_def, Subtype.map, id, ← Function.comp_apply (g := Subtype.val),
← filter_map, attach_map_subtype_val]
lemma filter_comm (q) (l : List α) : filter p (filter q l) = filter q (filter p l) := by
simp [Bool.and_comm]
@[simp]
theorem filter_true (l : List α) :
filter (fun _ => true) l = l := by induction l <;> simp [*, filter]
@[simp]
theorem filter_false (l : List α) :
filter (fun _ => false) l = [] := by induction l <;> simp [*, filter]
end Filter
/-! ### eraseP -/
section eraseP
variable {p : α → Bool}
@[simp]
theorem length_eraseP_add_one {l : List α} {a} (al : a ∈ l) (pa : p a) :
(l.eraseP p).length + 1 = l.length := by
let ⟨_, l₁, l₂, _, _, h₁, h₂⟩ := exists_of_eraseP al pa
rw [h₂, h₁, length_append, length_append]
rfl
end eraseP
/-! ### erase -/
section Erase
variable [DecidableEq α]
@[simp] theorem length_erase_add_one {a : α} {l : List α} (h : a ∈ l) :
(l.erase a).length + 1 = l.length := by
rw [erase_eq_eraseP, length_eraseP_add_one h (decide_eq_true rfl)]
theorem map_erase [DecidableEq β] {f : α → β} (finj : Injective f) {a : α} (l : List α) :
map f (l.erase a) = (map f l).erase (f a) := by
have this : (a == ·) = (f a == f ·) := by ext b; simp [beq_eq_decide, finj.eq_iff]
rw [erase_eq_eraseP, erase_eq_eraseP, eraseP_map, this]; rfl
theorem map_foldl_erase [DecidableEq β] {f : α → β} (finj : Injective f) {l₁ l₂ : List α} :
map f (foldl List.erase l₁ l₂) = foldl (fun l a => l.erase (f a)) (map f l₁) l₂ := by
induction l₂ generalizing l₁ <;> [rfl; simp only [foldl_cons, map_erase finj, *]]
theorem erase_getElem [DecidableEq ι] {l : List ι} {i : ℕ} (hi : i < l.length) :
Perm (l.erase l[i]) (l.eraseIdx i) := by
induction l generalizing i with
| nil => simp
| cons a l IH =>
cases i with
| zero => simp
| succ i =>
have hi' : i < l.length := by simpa using hi
if ha : a = l[i] then
simpa [ha] using .trans (perm_cons_erase (getElem_mem _)) (.cons _ (IH hi'))
else
simpa [ha] using IH hi'
theorem length_eraseIdx_add_one {l : List ι} {i : ℕ} (h : i < l.length) :
(l.eraseIdx i).length + 1 = l.length := by
rw [length_eraseIdx]
split <;> omega
end Erase
/-! ### diff -/
section Diff
variable [DecidableEq α]
@[simp]
theorem map_diff [DecidableEq β] {f : α → β} (finj : Injective f) {l₁ l₂ : List α} :
map f (l₁.diff l₂) = (map f l₁).diff (map f l₂) := by
simp only [diff_eq_foldl, foldl_map, map_foldl_erase finj]
@[deprecated (since := "2025-04-10")]
alias erase_diff_erase_sublist_of_sublist := Sublist.erase_diff_erase_sublist
end Diff
section Choose
variable (p : α → Prop) [DecidablePred p] (l : List α)
theorem choose_spec (hp : ∃ a, a ∈ l ∧ p a) : choose p l hp ∈ l ∧ p (choose p l hp) :=
(chooseX p l hp).property
theorem choose_mem (hp : ∃ a, a ∈ l ∧ p a) : choose p l hp ∈ l :=
(choose_spec _ _ _).1
theorem choose_property (hp : ∃ a, a ∈ l ∧ p a) : p (choose p l hp) :=
(choose_spec _ _ _).2
end Choose
/-! ### Forall -/
section Forall
variable {p q : α → Prop} {l : List α}
@[simp]
theorem forall_cons (p : α → Prop) (x : α) : ∀ l : List α, Forall p (x :: l) ↔ p x ∧ Forall p l
| [] => (and_iff_left_of_imp fun _ ↦ trivial).symm
| _ :: _ => Iff.rfl
@[simp]
theorem forall_append {p : α → Prop} : ∀ {xs ys : List α},
Forall p (xs ++ ys) ↔ Forall p xs ∧ Forall p ys
| [] => by simp
| _ :: _ => by simp [forall_append, and_assoc]
theorem forall_iff_forall_mem : ∀ {l : List α}, Forall p l ↔ ∀ x ∈ l, p x
| [] => (iff_true_intro <| forall_mem_nil _).symm
| x :: l => by rw [forall_mem_cons, forall_cons, forall_iff_forall_mem]
theorem Forall.imp (h : ∀ x, p x → q x) : ∀ {l : List α}, Forall p l → Forall q l
| [] => id
| x :: l => by
simp only [forall_cons, and_imp]
rw [← and_imp]
exact And.imp (h x) (Forall.imp h)
@[simp]
theorem forall_map_iff {p : β → Prop} (f : α → β) : Forall p (l.map f) ↔ Forall (p ∘ f) l := by
induction l <;> simp [*]
instance (p : α → Prop) [DecidablePred p] : DecidablePred (Forall p) := fun _ =>
decidable_of_iff' _ forall_iff_forall_mem
end Forall
/-! ### Miscellaneous lemmas -/
theorem get_attach (l : List α) (i) :
(l.attach.get i).1 = l.get ⟨i, length_attach (l := l) ▸ i.2⟩ := by simp
section Disjoint
/-- The images of disjoint lists under a partially defined map are disjoint -/
theorem disjoint_pmap {p : α → Prop} {f : ∀ a : α, p a → β} {s t : List α}
(hs : ∀ a ∈ s, p a) (ht : ∀ a ∈ t, p a)
(hf : ∀ (a a' : α) (ha : p a) (ha' : p a'), f a ha = f a' ha' → a = a')
(h : Disjoint s t) :
Disjoint (s.pmap f hs) (t.pmap f ht) := by
simp only [Disjoint, mem_pmap]
rintro b ⟨a, ha, rfl⟩ ⟨a', ha', ha''⟩
apply h ha
rwa [hf a a' (hs a ha) (ht a' ha') ha''.symm]
/-- The images of disjoint lists under an injective map are disjoint -/
theorem disjoint_map {f : α → β} {s t : List α} (hf : Function.Injective f)
(h : Disjoint s t) : Disjoint (s.map f) (t.map f) := by
rw [← pmap_eq_map (fun _ _ ↦ trivial), ← pmap_eq_map (fun _ _ ↦ trivial)]
exact disjoint_pmap _ _ (fun _ _ _ _ h' ↦ hf h') h
alias Disjoint.map := disjoint_map
theorem Disjoint.of_map {f : α → β} {s t : List α} (h : Disjoint (s.map f) (t.map f)) :
Disjoint s t := fun _a has hat ↦
h (mem_map_of_mem has) (mem_map_of_mem hat)
theorem Disjoint.map_iff {f : α → β} {s t : List α} (hf : Function.Injective f) :
Disjoint (s.map f) (t.map f) ↔ Disjoint s t :=
⟨fun h ↦ h.of_map, fun h ↦ h.map hf⟩
theorem Perm.disjoint_left {l₁ l₂ l : List α} (p : List.Perm l₁ l₂) :
Disjoint l₁ l ↔ Disjoint l₂ l := by
simp_rw [List.disjoint_left, p.mem_iff]
theorem Perm.disjoint_right {l₁ l₂ l : List α} (p : List.Perm l₁ l₂) :
Disjoint l l₁ ↔ Disjoint l l₂ := by
simp_rw [List.disjoint_right, p.mem_iff]
@[simp]
theorem disjoint_reverse_left {l₁ l₂ : List α} : Disjoint l₁.reverse l₂ ↔ Disjoint l₁ l₂ :=
reverse_perm _ |>.disjoint_left
@[simp]
theorem disjoint_reverse_right {l₁ l₂ : List α} : Disjoint l₁ l₂.reverse ↔ Disjoint l₁ l₂ :=
reverse_perm _ |>.disjoint_right
end Disjoint
section lookup
variable [BEq α] [LawfulBEq α]
lemma lookup_graph (f : α → β) {a : α} {as : List α} (h : a ∈ as) :
lookup a (as.map fun x => (x, f x)) = some (f a) := by
induction as with
| nil => exact (not_mem_nil h).elim
| cons a' as ih =>
by_cases ha : a = a'
· simp [ha, lookup_cons]
· simpa [lookup_cons, beq_false_of_ne ha] using ih (List.mem_of_ne_of_mem ha h)
end lookup
section range'
@[simp]
lemma range'_0 (a b : ℕ) :
range' a b 0 = replicate b a := by
induction b with
| zero => simp
| succ b ih => simp [range'_succ, ih, replicate_succ]
lemma left_le_of_mem_range' {a b s x : ℕ}
(hx : x ∈ List.range' a b s) : a ≤ x := by
obtain ⟨i, _, rfl⟩ := List.mem_range'.mp hx
exact le_add_right a (s * i)
end range'
end List
| Mathlib/Data/List/Basic.lean | 3,443 | 3,452 | |
/-
Copyright (c) 2020 Bhavik Mehta. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Bhavik Mehta
-/
import Mathlib.CategoryTheory.Adjunction.FullyFaithful
import Mathlib.CategoryTheory.Functor.EpiMono
import Mathlib.CategoryTheory.HomCongr
/-!
# Reflective functors
Basic properties of reflective functors, especially those relating to their essential image.
Note properties of reflective functors relating to limits and colimits are included in
`Mathlib.CategoryTheory.Monad.Limits`.
-/
universe v₁ v₂ v₃ u₁ u₂ u₃
noncomputable section
namespace CategoryTheory
open Category Adjunction
variable {C : Type u₁} {D : Type u₂} {E : Type u₃}
variable [Category.{v₁} C] [Category.{v₂} D] [Category.{v₃} E]
/--
A functor is *reflective*, or *a reflective inclusion*, if it is fully faithful and right adjoint.
-/
class Reflective (R : D ⥤ C) extends R.Full, R.Faithful where
/-- a choice of a left adjoint to `R` -/
L : C ⥤ D
/-- `R` is a right adjoint -/
adj : L ⊣ R
variable (i : D ⥤ C)
/-- The reflector `C ⥤ D` when `R : D ⥤ C` is reflective. -/
def reflector [Reflective i] : C ⥤ D := Reflective.L (R := i)
/-- The adjunction `reflector i ⊣ i` when `i` is reflective. -/
def reflectorAdjunction [Reflective i] : reflector i ⊣ i := Reflective.adj
instance [Reflective i] : i.IsRightAdjoint := ⟨_, ⟨reflectorAdjunction i⟩⟩
instance [Reflective i] : (reflector i).IsLeftAdjoint := ⟨_, ⟨reflectorAdjunction i⟩⟩
/-- A reflective functor is fully faithful. -/
def Functor.fullyFaithfulOfReflective [Reflective i] : i.FullyFaithful :=
(reflectorAdjunction i).fullyFaithfulROfIsIsoCounit
-- TODO: This holds more generally for idempotent adjunctions, not just reflective adjunctions.
/-- For a reflective functor `i` (with left adjoint `L`), with unit `η`, we have `η_iL = iL η`.
-/
theorem unit_obj_eq_map_unit [Reflective i] (X : C) :
(reflectorAdjunction i).unit.app (i.obj ((reflector i).obj X)) =
i.map ((reflector i).map ((reflectorAdjunction i).unit.app X)) := by
rw [← cancel_mono (i.map ((reflectorAdjunction i).counit.app ((reflector i).obj X))),
← i.map_comp]
simp
/--
When restricted to objects in `D` given by `i : D ⥤ C`, the unit is an isomorphism. In other words,
`η_iX` is an isomorphism for any `X` in `D`.
More generally this applies to objects essentially in the reflective subcategory, see
`Functor.essImage.unit_isIso`.
-/
example [Reflective i] {B : D} : IsIso ((reflectorAdjunction i).unit.app (i.obj B)) :=
inferInstance
variable {i}
/-- If `A` is essentially in the image of a reflective functor `i`, then `η_A` is an isomorphism.
This gives that the "witness" for `A` being in the essential image can instead be given as the
reflection of `A`, with the isomorphism as `η_A`.
(For any `B` in the reflective subcategory, we automatically have that `ε_B` is an iso.)
-/
theorem Functor.essImage.unit_isIso [Reflective i] {A : C} (h : i.essImage A) :
IsIso ((reflectorAdjunction i).unit.app A) := by
rwa [isIso_unit_app_iff_mem_essImage]
/-- If `η_A` is a split monomorphism, then `A` is in the reflective subcategory. -/
theorem mem_essImage_of_unit_isSplitMono [Reflective i] {A : C}
[IsSplitMono ((reflectorAdjunction i).unit.app A)] : i.essImage A := by
let η : 𝟭 C ⟶ reflector i ⋙ i := (reflectorAdjunction i).unit
haveI : IsIso (η.app (i.obj ((reflector i).obj A))) :=
Functor.essImage.unit_isIso ((i.obj_mem_essImage _))
have : Epi (η.app A) := by
refine @epi_of_epi _ _ _ _ _ (retraction (η.app A)) (η.app A) ?_
rw [show retraction _ ≫ η.app A = _ from η.naturality (retraction (η.app A))]
apply epi_comp (η.app (i.obj ((reflector i).obj A)))
haveI := isIso_of_epi_of_isSplitMono (η.app A)
exact (reflectorAdjunction i).mem_essImage_of_unit_isIso A
/-- Composition of reflective functors. -/
instance Reflective.comp (F : C ⥤ D) (G : D ⥤ E) [Reflective F] [Reflective G] :
Reflective (F ⋙ G) where
L := reflector G ⋙ reflector F
adj := (reflectorAdjunction G).comp (reflectorAdjunction F)
/-- (Implementation) Auxiliary definition for `unitCompPartialBijective`. -/
def unitCompPartialBijectiveAux [Reflective i] (A : C) (B : D) :
(A ⟶ i.obj B) ≃ (i.obj ((reflector i).obj A) ⟶ i.obj B) :=
((reflectorAdjunction i).homEquiv _ _).symm.trans
(Functor.FullyFaithful.ofFullyFaithful i).homEquiv
/-- The description of the inverse of the bijection `unitCompPartialBijectiveAux`. -/
theorem unitCompPartialBijectiveAux_symm_apply [Reflective i] {A : C} {B : D}
(f : i.obj ((reflector i).obj A) ⟶ i.obj B) :
(unitCompPartialBijectiveAux _ _).symm f = (reflectorAdjunction i).unit.app A ≫ f := by
simp [unitCompPartialBijectiveAux, Adjunction.homEquiv_unit]
/-- If `i` has a reflector `L`, then the function `(i.obj (L.obj A) ⟶ B) → (A ⟶ B)` given by
precomposing with `η.app A` is a bijection provided `B` is in the essential image of `i`.
That is, the function `fun (f : i.obj (L.obj A) ⟶ B) ↦ η.app A ≫ f` is bijective,
as long as `B` is in the essential image of `i`.
This definition gives an equivalence: the key property that the inverse can be described
nicely is shown in `unitCompPartialBijective_symm_apply`.
This establishes there is a natural bijection `(A ⟶ B) ≃ (i.obj (L.obj A) ⟶ B)`. In other words,
from the point of view of objects in `D`, `A` and `i.obj (L.obj A)` look the same: specifically
that `η.app A` is an isomorphism.
-/
def unitCompPartialBijective [Reflective i] (A : C) {B : C} (hB : i.essImage B) :
(A ⟶ B) ≃ (i.obj ((reflector i).obj A) ⟶ B) :=
calc
(A ⟶ B) ≃ (A ⟶ i.obj (Functor.essImage.witness hB)) := Iso.homCongr (Iso.refl _) hB.getIso.symm
_ ≃ (i.obj _ ⟶ i.obj (Functor.essImage.witness hB)) := unitCompPartialBijectiveAux _ _
_ ≃ (i.obj ((reflector i).obj A) ⟶ B) :=
Iso.homCongr (Iso.refl _) (Functor.essImage.getIso hB)
@[simp]
theorem unitCompPartialBijective_symm_apply [Reflective i] (A : C) {B : C} (hB : i.essImage B)
(f) : (unitCompPartialBijective A hB).symm f = (reflectorAdjunction i).unit.app A ≫ f := by
simp [unitCompPartialBijective, unitCompPartialBijectiveAux_symm_apply]
theorem unitCompPartialBijective_symm_natural [Reflective i] (A : C) {B B' : C} (h : B ⟶ B')
(hB : i.essImage B) (hB' : i.essImage B') (f : i.obj ((reflector i).obj A) ⟶ B) :
(unitCompPartialBijective A hB').symm (f ≫ h) = (unitCompPartialBijective A hB).symm f ≫ h := by
simp
theorem unitCompPartialBijective_natural [Reflective i] (A : C) {B B' : C} (h : B ⟶ B')
(hB : i.essImage B) (hB' : i.essImage B') (f : A ⟶ B) :
(unitCompPartialBijective A hB') (f ≫ h) = unitCompPartialBijective A hB f ≫ h := by
rw [← Equiv.eq_symm_apply, unitCompPartialBijective_symm_natural A h, Equiv.symm_apply_apply]
instance [Reflective i] (X : Functor.EssImageSubcategory i) :
IsIso (NatTrans.app (reflectorAdjunction i).unit X.obj) :=
Functor.essImage.unit_isIso X.property
-- These attributes are necessary to make automation work in `equivEssImageOfReflective`.
-- Making them global doesn't break anything elsewhere, but this is enough for now.
-- TODO: investigate further.
attribute [local simp 900] ObjectProperty.ι_map in
attribute [local ext] Functor.essImage_ext in
/-- If `i : D ⥤ C` is reflective, the inverse functor of `i ≌ F.essImage` can be explicitly
defined by the reflector. -/
@[simps]
def equivEssImageOfReflective [Reflective i] : D ≌ i.EssImageSubcategory where
functor := i.toEssImage
inverse := i.essImage.ι ⋙ reflector i
unitIso := (asIso <| (reflectorAdjunction i).counit).symm
counitIso := Functor.fullyFaithfulCancelRight i.essImage.ι <|
NatIso.ofComponents (fun X ↦ (asIso ((reflectorAdjunction i).unit.app X.obj)).symm)
/--
A functor is *coreflective*, or *a coreflective inclusion*, if it is fully faithful and left
adjoint.
-/
class Coreflective (L : C ⥤ D) extends L.Full, L.Faithful where
/-- a choice of a right adjoint to `L` -/
R : D ⥤ C
/-- `L` is a left adjoint -/
adj : L ⊣ R
|
variable (j : C ⥤ D)
/-- The coreflector `D ⥤ C` when `L : C ⥤ D` is coreflective. -/
def coreflector [Coreflective j] : D ⥤ C := Coreflective.R (L := j)
/-- The adjunction `j ⊣ coreflector j` when `j` is coreflective. -/
def coreflectorAdjunction [Coreflective j] : j ⊣ coreflector j := Coreflective.adj
| Mathlib/CategoryTheory/Adjunction/Reflective.lean | 180 | 187 |
/-
Copyright (c) 2021 Rémy Degenne. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Rémy Degenne
-/
import Mathlib.Analysis.InnerProductSpace.Continuous
import Mathlib.Analysis.Normed.Module.Dual
import Mathlib.MeasureTheory.Function.AEEqOfLIntegral
import Mathlib.MeasureTheory.Function.StronglyMeasurable.Lp
import Mathlib.MeasureTheory.Integral.Bochner.ContinuousLinearMap
import Mathlib.Order.Filter.Ring
/-! # From equality of integrals to equality of functions
This file provides various statements of the general form "if two functions have the same integral
on all sets, then they are equal almost everywhere".
The different lemmas use various hypotheses on the class of functions, on the target space or on the
possible finiteness of the measure.
This file is about Bochner integrals. See the file `AEEqOfLIntegral` for Lebesgue integrals.
## Main statements
All results listed below apply to two functions `f, g`, together with two main hypotheses,
* `f` and `g` are integrable on all measurable sets with finite measure,
* for all measurable sets `s` with finite measure, `∫ x in s, f x ∂μ = ∫ x in s, g x ∂μ`.
The conclusion is then `f =ᵐ[μ] g`. The main lemmas are:
* `ae_eq_of_forall_setIntegral_eq_of_sigmaFinite`: case of a sigma-finite measure.
* `AEFinStronglyMeasurable.ae_eq_of_forall_setIntegral_eq`: for functions which are
`AEFinStronglyMeasurable`.
* `Lp.ae_eq_of_forall_setIntegral_eq`: for elements of `Lp`, for `0 < p < ∞`.
* `Integrable.ae_eq_of_forall_setIntegral_eq`: for integrable functions.
For each of these results, we also provide a lemma about the equality of one function and 0. For
example, `Lp.ae_eq_zero_of_forall_setIntegral_eq_zero`.
Generally useful lemmas which are not related to integrals:
* `ae_eq_zero_of_forall_inner`: if for all constants `c`, `fun x => inner c (f x) =ᵐ[μ] 0` then
`f =ᵐ[μ] 0`.
* `ae_eq_zero_of_forall_dual`: if for all constants `c` in the dual space,
`fun x => c (f x) =ᵐ[μ] 0` then `f =ᵐ[μ] 0`.
-/
open MeasureTheory TopologicalSpace NormedSpace Filter
open scoped ENNReal NNReal MeasureTheory Topology
namespace MeasureTheory
section AeEqOfForall
variable {α E 𝕜 : Type*} {m : MeasurableSpace α} {μ : Measure α} [RCLike 𝕜]
theorem ae_eq_zero_of_forall_inner [NormedAddCommGroup E] [InnerProductSpace 𝕜 E]
[SecondCountableTopology E] {f : α → E} (hf : ∀ c : E, (fun x => (inner c (f x) : 𝕜)) =ᵐ[μ] 0) :
f =ᵐ[μ] 0 := by
let s := denseSeq E
have hs : DenseRange s := denseRange_denseSeq E
have hf' : ∀ᵐ x ∂μ, ∀ n : ℕ, inner (s n) (f x) = (0 : 𝕜) := ae_all_iff.mpr fun n => hf (s n)
refine hf'.mono fun x hx => ?_
rw [Pi.zero_apply, ← @inner_self_eq_zero 𝕜]
have h_closed : IsClosed {c : E | inner c (f x) = (0 : 𝕜)} :=
isClosed_eq (continuous_id.inner continuous_const) continuous_const
exact @isClosed_property ℕ E _ s (fun c => inner c (f x) = (0 : 𝕜)) hs h_closed hx _
local notation "⟪" x ", " y "⟫" => y x
variable (𝕜)
theorem ae_eq_zero_of_forall_dual_of_isSeparable [NormedAddCommGroup E] [NormedSpace 𝕜 E]
{t : Set E} (ht : TopologicalSpace.IsSeparable t) {f : α → E}
(hf : ∀ c : Dual 𝕜 E, (fun x => ⟪f x, c⟫) =ᵐ[μ] 0) (h't : ∀ᵐ x ∂μ, f x ∈ t) : f =ᵐ[μ] 0 := by
rcases ht with ⟨d, d_count, hd⟩
haveI : Encodable d := d_count.toEncodable
have : ∀ x : d, ∃ g : E →L[𝕜] 𝕜, ‖g‖ ≤ 1 ∧ g x = ‖(x : E)‖ :=
fun x => exists_dual_vector'' 𝕜 (x : E)
choose s hs using this
have A : ∀ a : E, a ∈ t → (∀ x, ⟪a, s x⟫ = (0 : 𝕜)) → a = 0 := by
intro a hat ha
contrapose! ha
have a_pos : 0 < ‖a‖ := by simp only [ha, norm_pos_iff, Ne, not_false_iff]
have a_mem : a ∈ closure d := hd hat
obtain ⟨x, hx⟩ : ∃ x : d, dist a x < ‖a‖ / 2 := by
rcases Metric.mem_closure_iff.1 a_mem (‖a‖ / 2) (half_pos a_pos) with ⟨x, h'x, hx⟩
exact ⟨⟨x, h'x⟩, hx⟩
use x
have I : ‖a‖ / 2 < ‖(x : E)‖ := by
have : ‖a‖ ≤ ‖(x : E)‖ + ‖a - x‖ := norm_le_insert' _ _
have : ‖a - x‖ < ‖a‖ / 2 := by rwa [dist_eq_norm] at hx
linarith
intro h
apply lt_irrefl ‖s x x‖
calc
‖s x x‖ = ‖s x (x - a)‖ := by simp only [h, sub_zero, ContinuousLinearMap.map_sub]
_ ≤ 1 * ‖(x : E) - a‖ := ContinuousLinearMap.le_of_opNorm_le _ (hs x).1 _
_ < ‖a‖ / 2 := by rw [one_mul]; rwa [dist_eq_norm'] at hx
_ < ‖(x : E)‖ := I
_ = ‖s x x‖ := by rw [(hs x).2, RCLike.norm_coe_norm]
have hfs : ∀ y : d, ∀ᵐ x ∂μ, ⟪f x, s y⟫ = (0 : 𝕜) := fun y => hf (s y)
have hf' : ∀ᵐ x ∂μ, ∀ y : d, ⟪f x, s y⟫ = (0 : 𝕜) := by rwa [ae_all_iff]
filter_upwards [hf', h't] with x hx h'x
exact A (f x) h'x hx
theorem ae_eq_zero_of_forall_dual [NormedAddCommGroup E] [NormedSpace 𝕜 E]
[SecondCountableTopology E] {f : α → E} (hf : ∀ c : Dual 𝕜 E, (fun x => ⟪f x, c⟫) =ᵐ[μ] 0) :
f =ᵐ[μ] 0 :=
ae_eq_zero_of_forall_dual_of_isSeparable 𝕜 (.of_separableSpace Set.univ) hf
(Eventually.of_forall fun _ => Set.mem_univ _)
variable {𝕜}
end AeEqOfForall
variable {α E : Type*} {m m0 : MeasurableSpace α} {μ : Measure α}
[NormedAddCommGroup E] [NormedSpace ℝ E] [CompleteSpace E] {p : ℝ≥0∞}
section AeEqOfForallSetIntegralEq
section Real
variable {f : α → ℝ}
theorem ae_nonneg_of_forall_setIntegral_nonneg (hf : Integrable f μ)
(hf_zero : ∀ s, MeasurableSet s → μ s < ∞ → 0 ≤ ∫ x in s, f x ∂μ) : 0 ≤ᵐ[μ] f := by
simp_rw [EventuallyLE, Pi.zero_apply]
rw [ae_const_le_iff_forall_lt_measure_zero]
intro b hb_neg
let s := {x | f x ≤ b}
have hs : NullMeasurableSet s μ := nullMeasurableSet_le hf.1.aemeasurable aemeasurable_const
have mus : μ s < ∞ := Integrable.measure_le_lt_top hf hb_neg
have h_int_gt : (∫ x in s, f x ∂μ) ≤ b * μ.real s := by
have h_const_le : (∫ x in s, f x ∂μ) ≤ ∫ _ in s, b ∂μ := by
refine setIntegral_mono_ae_restrict hf.integrableOn (integrableOn_const.mpr (Or.inr mus)) ?_
rw [EventuallyLE, ae_restrict_iff₀ (hs.mono μ.restrict_le_self)]
exact Eventually.of_forall fun x hxs => hxs
rwa [setIntegral_const, smul_eq_mul, mul_comm] at h_const_le
contrapose! h_int_gt with H
calc
b * μ.real s < 0 := mul_neg_of_neg_of_pos hb_neg <| ENNReal.toReal_pos H mus.ne
_ ≤ ∫ x in s, f x ∂μ := by
rw [← μ.restrict_toMeasurable mus.ne]
exact hf_zero _ (measurableSet_toMeasurable ..) (by rwa [measure_toMeasurable])
theorem ae_le_of_forall_setIntegral_le {f g : α → ℝ} (hf : Integrable f μ) (hg : Integrable g μ)
(hf_le : ∀ s, MeasurableSet s → μ s < ∞ → (∫ x in s, f x ∂μ) ≤ ∫ x in s, g x ∂μ) :
f ≤ᵐ[μ] g := by
rw [← eventually_sub_nonneg]
refine ae_nonneg_of_forall_setIntegral_nonneg (hg.sub hf) fun s hs => ?_
rw [integral_sub' hg.integrableOn hf.integrableOn, sub_nonneg]
exact hf_le s hs
theorem ae_nonneg_restrict_of_forall_setIntegral_nonneg_inter {f : α → ℝ} {t : Set α}
(hf : IntegrableOn f t μ)
(hf_zero : ∀ s, MeasurableSet s → μ (s ∩ t) < ∞ → 0 ≤ ∫ x in s ∩ t, f x ∂μ) :
0 ≤ᵐ[μ.restrict t] f := by
refine ae_nonneg_of_forall_setIntegral_nonneg hf fun s hs h's => ?_
simp_rw [Measure.restrict_restrict hs]
apply hf_zero s hs
rwa [Measure.restrict_apply hs] at h's
theorem ae_nonneg_of_forall_setIntegral_nonneg_of_sigmaFinite [SigmaFinite μ] {f : α → ℝ}
(hf_int_finite : ∀ s, MeasurableSet s → μ s < ∞ → IntegrableOn f s μ)
(hf_zero : ∀ s, MeasurableSet s → μ s < ∞ → 0 ≤ ∫ x in s, f x ∂μ) : 0 ≤ᵐ[μ] f := by
apply ae_of_forall_measure_lt_top_ae_restrict
intro t t_meas t_lt_top
apply ae_nonneg_restrict_of_forall_setIntegral_nonneg_inter (hf_int_finite t t_meas t_lt_top)
intro s s_meas _
exact
hf_zero _ (s_meas.inter t_meas)
(lt_of_le_of_lt (measure_mono (Set.inter_subset_right)) t_lt_top)
theorem AEFinStronglyMeasurable.ae_nonneg_of_forall_setIntegral_nonneg {f : α → ℝ}
(hf : AEFinStronglyMeasurable f μ)
(hf_int_finite : ∀ s, MeasurableSet s → μ s < ∞ → IntegrableOn f s μ)
(hf_zero : ∀ s, MeasurableSet s → μ s < ∞ → 0 ≤ ∫ x in s, f x ∂μ) : 0 ≤ᵐ[μ] f := by
let t := hf.sigmaFiniteSet
suffices 0 ≤ᵐ[μ.restrict t] f from
ae_of_ae_restrict_of_ae_restrict_compl _ this hf.ae_eq_zero_compl.symm.le
haveI : SigmaFinite (μ.restrict t) := hf.sigmaFinite_restrict
refine
ae_nonneg_of_forall_setIntegral_nonneg_of_sigmaFinite (fun s hs hμts => ?_) fun s hs hμts => ?_
· rw [IntegrableOn, Measure.restrict_restrict hs]
rw [Measure.restrict_apply hs] at hμts
exact hf_int_finite (s ∩ t) (hs.inter hf.measurableSet) hμts
· rw [Measure.restrict_restrict hs]
rw [Measure.restrict_apply hs] at hμts
exact hf_zero (s ∩ t) (hs.inter hf.measurableSet) hμts
theorem ae_nonneg_restrict_of_forall_setIntegral_nonneg {f : α → ℝ}
(hf_int_finite : ∀ s, MeasurableSet s → μ s < ∞ → IntegrableOn f s μ)
(hf_zero : ∀ s, MeasurableSet s → μ s < ∞ → 0 ≤ ∫ x in s, f x ∂μ) {t : Set α}
(ht : MeasurableSet t) (hμt : μ t ≠ ∞) : 0 ≤ᵐ[μ.restrict t] f := by
refine
ae_nonneg_restrict_of_forall_setIntegral_nonneg_inter
(hf_int_finite t ht (lt_top_iff_ne_top.mpr hμt)) fun s hs _ => ?_
refine hf_zero (s ∩ t) (hs.inter ht) ?_
exact (measure_mono Set.inter_subset_right).trans_lt (lt_top_iff_ne_top.mpr hμt)
theorem ae_eq_zero_restrict_of_forall_setIntegral_eq_zero_real {f : α → ℝ}
(hf_int_finite : ∀ s, MeasurableSet s → μ s < ∞ → IntegrableOn f s μ)
(hf_zero : ∀ s, MeasurableSet s → μ s < ∞ → ∫ x in s, f x ∂μ = 0) {t : Set α}
(ht : MeasurableSet t) (hμt : μ t ≠ ∞) : f =ᵐ[μ.restrict t] 0 := by
suffices h_and : f ≤ᵐ[μ.restrict t] 0 ∧ 0 ≤ᵐ[μ.restrict t] f from
h_and.1.mp (h_and.2.mono fun x hx1 hx2 => le_antisymm hx2 hx1)
refine
⟨?_,
ae_nonneg_restrict_of_forall_setIntegral_nonneg hf_int_finite
(fun s hs hμs => (hf_zero s hs hμs).symm.le) ht hμt⟩
suffices h_neg : 0 ≤ᵐ[μ.restrict t] -f by
refine h_neg.mono fun x hx => ?_
rw [Pi.neg_apply] at hx
simpa using hx
refine
ae_nonneg_restrict_of_forall_setIntegral_nonneg (fun s hs hμs => (hf_int_finite s hs hμs).neg)
(fun s hs hμs => ?_) ht hμt
simp_rw [Pi.neg_apply]
rw [integral_neg, neg_nonneg]
exact (hf_zero s hs hμs).le
end Real
theorem ae_eq_zero_restrict_of_forall_setIntegral_eq_zero {f : α → E}
(hf_int_finite : ∀ s, MeasurableSet s → μ s < ∞ → IntegrableOn f s μ)
(hf_zero : ∀ s : Set α, MeasurableSet s → μ s < ∞ → ∫ x in s, f x ∂μ = 0) {t : Set α}
(ht : MeasurableSet t) (hμt : μ t ≠ ∞) : f =ᵐ[μ.restrict t] 0 := by
rcases (hf_int_finite t ht hμt.lt_top).aestronglyMeasurable.isSeparable_ae_range with
| ⟨u, u_sep, hu⟩
refine ae_eq_zero_of_forall_dual_of_isSeparable ℝ u_sep (fun c => ?_) hu
refine ae_eq_zero_restrict_of_forall_setIntegral_eq_zero_real ?_ ?_ ht hμt
· intro s hs hμs
exact ContinuousLinearMap.integrable_comp c (hf_int_finite s hs hμs)
· intro s hs hμs
rw [ContinuousLinearMap.integral_comp_comm c (hf_int_finite s hs hμs), hf_zero s hs hμs]
exact ContinuousLinearMap.map_zero _
theorem ae_eq_restrict_of_forall_setIntegral_eq {f g : α → E}
(hf_int_finite : ∀ s, MeasurableSet s → μ s < ∞ → IntegrableOn f s μ)
(hg_int_finite : ∀ s, MeasurableSet s → μ s < ∞ → IntegrableOn g s μ)
(hfg_zero : ∀ s : Set α, MeasurableSet s → μ s < ∞ → ∫ x in s, f x ∂μ = ∫ x in s, g x ∂μ)
| Mathlib/MeasureTheory/Function/AEEqOfIntegral.lean | 229 | 241 |
/-
Copyright (c) 2024 Andrew Yang. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Andrew Yang
-/
import Mathlib.Algebra.Small.Module
import Mathlib.LinearAlgebra.FreeModule.Finite.Basic
import Mathlib.LinearAlgebra.Isomorphisms
import Mathlib.LinearAlgebra.TensorProduct.RightExactness
import Mathlib.RingTheory.Finiteness.Projective
import Mathlib.RingTheory.Localization.BaseChange
import Mathlib.RingTheory.Noetherian.Basic
import Mathlib.RingTheory.TensorProduct.Finite
/-!
# Finitely Presented Modules
## Main definition
- `Module.FinitePresentation`: A module is finitely presented if it is generated by some
finite set `s` and the kernel of the presentation `Rˢ → M` is also finitely generated.
## Main results
- `Module.finitePresentation_iff_finite`: If `R` is noetherian, then f.p. iff f.g. on `R`-modules.
Suppose `0 → K → M → N → 0` is an exact sequence of `R`-modules.
- `Module.finitePresentation_of_surjective`: If `M` is f.p., `K` is f.g., then `N` is f.p.
- `Module.FinitePresentation.fg_ker`: If `M` is f.g., `N` is f.p., then `K` is f.g.
- `Module.finitePresentation_of_ker`: If `N` and `K` is f.p., then `M` is also f.p.
- `Module.FinitePresentation.isLocalizedModule_map`: If `M` and `N` are `R`-modules and `M` is f.p.,
and `S` is a submonoid of `R`, then `Hom(Mₛ, Nₛ)` is the localization of `Hom(M, N)`.
Also the instances finite + free => f.p. => finite are also provided
## TODO
Suppose `S` is an `R`-algebra, `M` is an `S`-module. Then
1. If `S` is f.p., then `M` is `R`-f.p. implies `M` is `S`-f.p.
2. If `S` is both f.p. (as an algebra) and finite (as a module),
then `M` is `S`-fp implies that `M` is `R`-f.p.
3. If `S` is f.p. as a module, then `S` is f.p. as an algebra.
In particular,
4. `S` is f.p. as an `R`-module iff it is f.p. as an algebra and is finite as a module.
For finitely presented algebras, see `Algebra.FinitePresentation`
in file `Mathlib.RingTheory.FinitePresentation`.
-/
open Finsupp
section Semiring
variable (R M) [Semiring R] [AddCommMonoid M] [Module R M]
/--
A module is finitely presented if it is finitely generated by some set `s`
and the kernel of the presentation `Rˢ → M` is also finitely generated.
-/
class Module.FinitePresentation : Prop where
out : ∃ (s : Finset M), Submodule.span R (s : Set M) = ⊤ ∧
(LinearMap.ker (Finsupp.linearCombination R ((↑) : s → M))).FG
instance (priority := 100) [h : Module.FinitePresentation R M] : Module.Finite R M := by
obtain ⟨s, hs₁, _⟩ := h
exact ⟨s, hs₁⟩
end Semiring
section Ring
section
universe u v
variable (R : Type u) (M : Type*) [Ring R] [AddCommGroup M] [Module R M]
theorem Module.FinitePresentation.exists_fin [fp : Module.FinitePresentation R M] :
∃ (n : ℕ) (K : Submodule R (Fin n → R)) (_ : M ≃ₗ[R] (Fin n → R) ⧸ K), K.FG := by
have ⟨ι, ⟨hι₁, hι₂⟩⟩ := fp
refine ⟨_, LinearMap.ker (linearCombination R Subtype.val ∘ₗ
(lcongr ι.equivFin (.refl ..) ≪≫ₗ linearEquivFunOnFinite R R _).symm.toLinearMap),
(LinearMap.quotKerEquivOfSurjective _ <| LinearMap.range_eq_top.mp ?_).symm, ?_⟩
· simpa [range_linearCombination] using hι₁
· simpa [LinearMap.ker_comp, Submodule.comap_equiv_eq_map_symm] using hι₂.map _
/-- A finitely presented module is isomorphic to the quotient of a finite free module by a finitely
generated submodule. -/
theorem Module.FinitePresentation.equiv_quotient [Module.FinitePresentation R M] [Small.{v} R] :
∃ (L : Type v) (_ : AddCommGroup L) (_ : Module R L) (K : Submodule R L)
(_ : M ≃ₗ[R] L ⧸ K), Module.Free R L ∧ Module.Finite R L ∧ K.FG :=
have ⟨_n, _K, e, fg⟩ := Module.FinitePresentation.exists_fin R M
let es := linearEquivShrink
⟨_, inferInstance, inferInstance, _, e ≪≫ₗ Submodule.Quotient.equiv _ _ (es ..) rfl,
.of_equiv (es ..), .equiv (es ..), fg.map (es ..).toLinearMap⟩
end
variable (R M N) [Ring R] [AddCommGroup M] [Module R M] [AddCommGroup N] [Module R N]
-- Ideally this should be an instance but it makes mathlib much slower.
lemma Module.finitePresentation_of_finite [IsNoetherianRing R] [h : Module.Finite R M] :
Module.FinitePresentation R M := by
obtain ⟨s, hs⟩ := h
exact ⟨s, hs, IsNoetherian.noetherian _⟩
lemma Module.finitePresentation_iff_finite [IsNoetherianRing R] :
Module.FinitePresentation R M ↔ Module.Finite R M :=
⟨fun _ ↦ inferInstance, fun _ ↦ finitePresentation_of_finite R M⟩
variable {R M N}
lemma Module.finitePresentation_of_free_of_surjective [Module.Free R M] [Module.Finite R M]
(l : M →ₗ[R] N)
(hl : Function.Surjective l) (hl' : (LinearMap.ker l).FG) :
Module.FinitePresentation R N := by
classical
let b := Module.Free.chooseBasis R M
let π : Free.ChooseBasisIndex R M → (Set.finite_range (l ∘ b)).toFinset :=
fun i ↦ ⟨l (b i), by simp⟩
have : π.Surjective := fun ⟨x, hx⟩ ↦ by
obtain ⟨y, rfl⟩ : ∃ a, l (b a) = x := by simpa using hx
exact ⟨y, rfl⟩
choose σ hσ using this
have hπ : Subtype.val ∘ π = l ∘ b := rfl
have hσ₁ : π ∘ σ = id := by ext i; exact congr_arg Subtype.val (hσ i)
| have hσ₂ : l ∘ b ∘ σ = Subtype.val := by ext i; exact congr_arg Subtype.val (hσ i)
refine ⟨(Set.finite_range (l ∘ b)).toFinset,
by simpa [Set.range_comp, LinearMap.range_eq_top], ?_⟩
let f : M →ₗ[R] (Set.finite_range (l ∘ b)).toFinset →₀ R :=
| Mathlib/Algebra/Module/FinitePresentation.lean | 131 | 134 |
/-
Copyright (c) 2024 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin
-/
import Mathlib.Algebra.MvPolynomial.Monad
import Mathlib.LinearAlgebra.Charpoly.ToMatrix
import Mathlib.LinearAlgebra.FreeModule.StrongRankCondition
import Mathlib.LinearAlgebra.Matrix.Charpoly.Univ
import Mathlib.RingTheory.TensorProduct.Finite
import Mathlib.RingTheory.TensorProduct.Free
/-!
# Characteristic polynomials of linear families of endomorphisms
The coefficients of the characteristic polynomials of a linear family of endomorphisms
are homogeneous polynomials in the parameters.
This result is used in Lie theory
to establish the existence of regular elements and Cartan subalgebras,
and ultimately a well-defined notion of rank for Lie algebras.
In this file we prove this result about characteristic polynomials.
Let `L` and `M` be modules over a nontrivial commutative ring `R`,
and let `φ : L →ₗ[R] Module.End R M` be a linear map.
Let `b` be a basis of `L`, indexed by `ι`.
Then we define a multivariate polynomial with variables indexed by `ι`
that evaluates on elements `x` of `L` to the characteristic polynomial of `φ x`.
## Main declarations
* `Matrix.toMvPolynomial M i`: the family of multivariate polynomials that evaluates on `c : n → R`
to the dot product of the `i`-th row of `M` with `c`.
`Matrix.toMvPolynomial M i` is the sum of the monomials `C (M i j) * X j`.
* `LinearMap.toMvPolynomial b₁ b₂ f`: a version of `Matrix.toMvPolynomial` for linear maps `f`
with respect to bases `b₁` and `b₂` of the domain and codomain.
* `LinearMap.polyCharpoly`: the multivariate polynomial that evaluates on elements `x` of `L`
to the characteristic polynomial of `φ x`.
* `LinearMap.polyCharpoly_map_eq_charpoly`: the evaluation of `polyCharpoly` on elements `x` of `L`
is the characteristic polynomial of `φ x`.
* `LinearMap.polyCharpoly_coeff_isHomogeneous`: the coefficients of `polyCharpoly`
are homogeneous polynomials in the parameters.
* `LinearMap.nilRank`: the smallest index at which `polyCharpoly` has a non-zero coefficient,
which is independent of the choice of basis for `L`.
* `LinearMap.IsNilRegular`: an element `x` of `L` is *nil-regular* with respect to `φ`
if the `n`-th coefficient of the characteristic polynomial of `φ x` is non-zero,
where `n` denotes the nil-rank of `φ`.
## Implementation details
We show that `LinearMap.polyCharpoly` does not depend on the choice of basis of the target module.
This is done via `LinearMap.polyCharpoly_eq_polyCharpolyAux`
and `LinearMap.polyCharpolyAux_basisIndep`.
The latter is proven by considering
the base change of the `R`-linear map `φ : L →ₗ[R] End R M`
to the multivariate polynomial ring `MvPolynomial ι R`,
and showing that `polyCharpolyAux φ` is equal to the characteristic polynomial of this base change.
The proof concludes because characteristic polynomials are independent of the chosen basis.
## References
* [barnes1967]: "On Cartan subalgebras of Lie algebras" by D.W. Barnes.
-/
open scoped Matrix
namespace Matrix
variable {m n o R S : Type*}
variable [Fintype n] [Fintype o] [CommSemiring R] [CommSemiring S]
open MvPolynomial
/-- Let `M` be an `(m × n)`-matrix over `R`.
Then `Matrix.toMvPolynomial M` is the family (indexed by `i : m`)
of multivariate polynomials in `n` variables over `R` that evaluates on `c : n → R`
to the dot product of the `i`-th row of `M` with `c`:
`Matrix.toMvPolynomial M i` is the sum of the monomials `C (M i j) * X j`. -/
noncomputable
def toMvPolynomial (M : Matrix m n R) (i : m) : MvPolynomial n R :=
∑ j, monomial (.single j 1) (M i j)
lemma toMvPolynomial_eval_eq_apply (M : Matrix m n R) (i : m) (c : n → R) :
eval c (M.toMvPolynomial i) = (M *ᵥ c) i := by
simp only [toMvPolynomial, map_sum, eval_monomial, pow_zero, Finsupp.prod_single_index, pow_one,
mulVec, dotProduct]
lemma toMvPolynomial_map (f : R →+* S) (M : Matrix m n R) (i : m) :
(M.map f).toMvPolynomial i = MvPolynomial.map f (M.toMvPolynomial i) := by
simp only [toMvPolynomial, map_apply, map_sum, map_monomial]
lemma toMvPolynomial_isHomogeneous (M : Matrix m n R) (i : m) :
(M.toMvPolynomial i).IsHomogeneous 1 := by
apply MvPolynomial.IsHomogeneous.sum
rintro j -
apply MvPolynomial.isHomogeneous_monomial _ _
simp [Finsupp.degree, Finsupp.support_single_ne_zero _ one_ne_zero, Finset.sum_singleton,
Finsupp.single_eq_same]
lemma toMvPolynomial_totalDegree_le (M : Matrix m n R) (i : m) :
(M.toMvPolynomial i).totalDegree ≤ 1 := by
apply (toMvPolynomial_isHomogeneous _ _).totalDegree_le
@[simp]
lemma toMvPolynomial_constantCoeff (M : Matrix m n R) (i : m) :
constantCoeff (M.toMvPolynomial i) = 0 := by
simp only [toMvPolynomial, ← C_mul_X_eq_monomial, map_sum, map_mul, constantCoeff_X,
mul_zero, Finset.sum_const_zero]
@[simp]
lemma toMvPolynomial_zero : (0 : Matrix m n R).toMvPolynomial = 0 := by
ext; simp only [toMvPolynomial, zero_apply, map_zero, Finset.sum_const_zero, Pi.zero_apply]
@[simp]
lemma toMvPolynomial_one [DecidableEq n] : (1 : Matrix n n R).toMvPolynomial = X := by
ext i : 1
rw [toMvPolynomial, Finset.sum_eq_single i]
· simp only [one_apply_eq, ← C_mul_X_eq_monomial, C_1, one_mul]
· rintro j - hj
simp only [one_apply_ne hj.symm, map_zero]
· intro h
exact (h (Finset.mem_univ _)).elim
lemma toMvPolynomial_add (M N : Matrix m n R) :
(M + N).toMvPolynomial = M.toMvPolynomial + N.toMvPolynomial := by
ext i : 1
simp only [toMvPolynomial, add_apply, map_add, Finset.sum_add_distrib, Pi.add_apply]
lemma toMvPolynomial_mul (M : Matrix m n R) (N : Matrix n o R) (i : m) :
(M * N).toMvPolynomial i = bind₁ N.toMvPolynomial (M.toMvPolynomial i) := by
simp only [toMvPolynomial, mul_apply, map_sum, Finset.sum_comm (γ := o), bind₁, aeval,
AlgHom.coe_mk, coe_eval₂Hom, eval₂_monomial, algebraMap_apply, Algebra.id.map_eq_id,
RingHom.id_apply, C_apply, pow_zero, Finsupp.prod_single_index, pow_one, Finset.mul_sum,
monomial_mul, zero_add]
end Matrix
namespace LinearMap
open MvPolynomial
section
variable {R M₁ M₂ ι₁ ι₂ : Type*}
variable [CommRing R] [AddCommGroup M₁] [AddCommGroup M₂]
variable [Module R M₁] [Module R M₂]
variable [Fintype ι₁] [Finite ι₂]
variable [DecidableEq ι₁]
variable (b₁ : Basis ι₁ R M₁) (b₂ : Basis ι₂ R M₂)
/-- Let `f : M₁ →ₗ[R] M₂` be an `R`-linear map
between modules `M₁` and `M₂` with bases `b₁` and `b₂` respectively.
Then `LinearMap.toMvPolynomial b₁ b₂ f` is the family of multivariate polynomials over `R`
that evaluates on an element `x` of `M₁` (represented on the basis `b₁`)
to the element `f x` of `M₂` (represented on the basis `b₂`). -/
noncomputable
def toMvPolynomial (f : M₁ →ₗ[R] M₂) (i : ι₂) :
MvPolynomial ι₁ R :=
(toMatrix b₁ b₂ f).toMvPolynomial i
lemma toMvPolynomial_eval_eq_apply (f : M₁ →ₗ[R] M₂) (i : ι₂) (c : ι₁ →₀ R) :
eval c (f.toMvPolynomial b₁ b₂ i) = b₂.repr (f (b₁.repr.symm c)) i := by
rw [toMvPolynomial, Matrix.toMvPolynomial_eval_eq_apply,
← LinearMap.toMatrix_mulVec_repr b₁ b₂, LinearEquiv.apply_symm_apply]
| open Algebra.TensorProduct in
lemma toMvPolynomial_baseChange (f : M₁ →ₗ[R] M₂) (i : ι₂) (A : Type*) [CommRing A] [Algebra R A] :
(f.baseChange A).toMvPolynomial (basis A b₁) (basis A b₂) i =
MvPolynomial.map (algebraMap R A) (f.toMvPolynomial b₁ b₂ i) := by
| Mathlib/Algebra/Module/LinearMap/Polynomial.lean | 166 | 169 |
/-
Copyright (c) 2020 Thomas Browning. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Thomas Browning
-/
import Mathlib.Algebra.BigOperators.NatAntidiagonal
import Mathlib.Algebra.Polynomial.Reverse
/-!
# "Mirror" of a univariate polynomial
In this file we define `Polynomial.mirror`, a variant of `Polynomial.reverse`. The difference
between `reverse` and `mirror` is that `reverse` will decrease the degree if the polynomial is
divisible by `X`.
## Main definitions
- `Polynomial.mirror`
## Main results
- `Polynomial.mirror_mul_of_domain`: `mirror` preserves multiplication.
- `Polynomial.irreducible_of_mirror`: an irreducibility criterion involving `mirror`
-/
namespace Polynomial
section Semiring
variable {R : Type*} [Semiring R] (p q : R[X])
/-- mirror of a polynomial: reverses the coefficients while preserving `Polynomial.natDegree` -/
noncomputable def mirror :=
p.reverse * X ^ p.natTrailingDegree
@[simp]
theorem mirror_zero : (0 : R[X]).mirror = 0 := by simp [mirror]
theorem mirror_monomial (n : ℕ) (a : R) : (monomial n a).mirror = monomial n a := by
classical
by_cases ha : a = 0
· rw [ha, monomial_zero_right, mirror_zero]
· rw [mirror, reverse, natDegree_monomial n a, if_neg ha, natTrailingDegree_monomial ha, ←
C_mul_X_pow_eq_monomial, reflect_C_mul_X_pow, revAt_le (le_refl n), tsub_self, pow_zero,
mul_one]
theorem mirror_C (a : R) : (C a).mirror = C a :=
mirror_monomial 0 a
theorem mirror_X : X.mirror = (X : R[X]) :=
mirror_monomial 1 (1 : R)
theorem mirror_natDegree : p.mirror.natDegree = p.natDegree := by
by_cases hp : p = 0
· rw [hp, mirror_zero]
nontriviality R
rw [mirror, natDegree_mul', reverse_natDegree, natDegree_X_pow,
tsub_add_cancel_of_le p.natTrailingDegree_le_natDegree]
rwa [leadingCoeff_X_pow, mul_one, reverse_leadingCoeff, Ne, trailingCoeff_eq_zero]
theorem mirror_natTrailingDegree : p.mirror.natTrailingDegree = p.natTrailingDegree := by
by_cases hp : p = 0
· rw [hp, mirror_zero]
· rw [mirror, natTrailingDegree_mul_X_pow ((mt reverse_eq_zero.mp) hp),
natTrailingDegree_reverse, zero_add]
theorem coeff_mirror (n : ℕ) :
p.mirror.coeff n = p.coeff (revAt (p.natDegree + p.natTrailingDegree) n) := by
by_cases h2 : p.natDegree < n
· rw [coeff_eq_zero_of_natDegree_lt (by rwa [mirror_natDegree])]
by_cases h1 : n ≤ p.natDegree + p.natTrailingDegree
· rw [revAt_le h1, coeff_eq_zero_of_lt_natTrailingDegree]
exact (tsub_lt_iff_left h1).mpr (Nat.add_lt_add_right h2 _)
· rw [← revAtFun_eq, revAtFun, if_neg h1, coeff_eq_zero_of_natDegree_lt h2]
rw [not_lt] at h2
rw [revAt_le (h2.trans (Nat.le_add_right _ _))]
by_cases h3 : p.natTrailingDegree ≤ n
· rw [← tsub_add_eq_add_tsub h2, ← tsub_tsub_assoc h2 h3, mirror, coeff_mul_X_pow', if_pos h3,
coeff_reverse, revAt_le (tsub_le_self.trans h2)]
rw [not_le] at h3
rw [coeff_eq_zero_of_natDegree_lt (lt_tsub_iff_right.mpr (Nat.add_lt_add_left h3 _))]
exact coeff_eq_zero_of_lt_natTrailingDegree (by rwa [mirror_natTrailingDegree])
--TODO: Extract `Finset.sum_range_rev_at` lemma.
theorem mirror_eval_one : p.mirror.eval 1 = p.eval 1 := by
simp_rw [eval_eq_sum_range, one_pow, mul_one, mirror_natDegree]
refine Finset.sum_bij_ne_zero ?_ ?_ ?_ ?_ ?_
· exact fun n _ _ => revAt (p.natDegree + p.natTrailingDegree) n
· intro n hn hp
rw [Finset.mem_range_succ_iff] at *
rw [revAt_le (hn.trans (Nat.le_add_right _ _))]
rw [tsub_le_iff_tsub_le, add_comm, add_tsub_cancel_right, ← mirror_natTrailingDegree]
exact natTrailingDegree_le_of_ne_zero hp
· exact fun n₁ _ _ _ _ _ h => by rw [← @revAt_invol _ n₁, h, revAt_invol]
· intro n hn hp
use revAt (p.natDegree + p.natTrailingDegree) n
refine ⟨?_, ?_, revAt_invol⟩
· rw [Finset.mem_range_succ_iff] at *
rw [revAt_le (hn.trans (Nat.le_add_right _ _))]
rw [tsub_le_iff_tsub_le, add_comm, add_tsub_cancel_right]
exact natTrailingDegree_le_of_ne_zero hp
· change p.mirror.coeff _ ≠ 0
rwa [coeff_mirror, revAt_invol]
· exact fun n _ _ => p.coeff_mirror n
theorem mirror_mirror : p.mirror.mirror = p :=
Polynomial.ext fun n => by
rw [coeff_mirror, coeff_mirror, mirror_natDegree, mirror_natTrailingDegree, revAt_invol]
variable {p q}
theorem mirror_involutive : Function.Involutive (mirror : R[X] → R[X]) :=
mirror_mirror
theorem mirror_eq_iff : p.mirror = q ↔ p = q.mirror :=
mirror_involutive.eq_iff
@[simp]
theorem mirror_inj : p.mirror = q.mirror ↔ p = q :=
mirror_involutive.injective.eq_iff
@[simp]
theorem mirror_eq_zero : p.mirror = 0 ↔ p = 0 :=
⟨fun h => by rw [← p.mirror_mirror, h, mirror_zero], fun h => by rw [h, mirror_zero]⟩
variable (p q)
@[simp]
theorem mirror_trailingCoeff : p.mirror.trailingCoeff = p.leadingCoeff := by
rw [leadingCoeff, trailingCoeff, mirror_natTrailingDegree, coeff_mirror,
revAt_le (Nat.le_add_left _ _), add_tsub_cancel_right]
@[simp]
theorem mirror_leadingCoeff : p.mirror.leadingCoeff = p.trailingCoeff := by
rw [← p.mirror_mirror, mirror_trailingCoeff, p.mirror_mirror]
theorem coeff_mul_mirror :
(p * p.mirror).coeff (p.natDegree + p.natTrailingDegree) = p.sum fun _ => (· ^ 2) := by
rw [coeff_mul, Finset.Nat.sum_antidiagonal_eq_sum_range_succ_mk]
refine
(Finset.sum_congr rfl fun n hn => ?_).trans
(p.sum_eq_of_subset (fun _ ↦ (· ^ 2)) (fun _ ↦ zero_pow two_ne_zero) fun n hn ↦
Finset.mem_range_succ_iff.mpr
((le_natDegree_of_mem_supp n hn).trans (Nat.le_add_right _ _))).symm
rw [coeff_mirror, ← revAt_le (Finset.mem_range_succ_iff.mp hn), revAt_invol, ← sq]
variable [NoZeroDivisors R]
theorem natDegree_mul_mirror : (p * p.mirror).natDegree = 2 * p.natDegree := by
by_cases hp : p = 0
· rw [hp, zero_mul, natDegree_zero, mul_zero]
rw [natDegree_mul hp (mt mirror_eq_zero.mp hp), mirror_natDegree, two_mul]
theorem natTrailingDegree_mul_mirror :
(p * p.mirror).natTrailingDegree = 2 * p.natTrailingDegree := by
by_cases hp : p = 0
· rw [hp, zero_mul, natTrailingDegree_zero, mul_zero]
rw [natTrailingDegree_mul hp (mt mirror_eq_zero.mp hp), mirror_natTrailingDegree, two_mul]
end Semiring
section Ring
variable {R : Type*} [Ring R] (p q : R[X])
theorem mirror_neg : (-p).mirror = -p.mirror := by
rw [mirror, mirror, reverse_neg, natTrailingDegree_neg, neg_mul_eq_neg_mul]
variable [NoZeroDivisors R]
theorem mirror_mul_of_domain : (p * q).mirror = p.mirror * q.mirror := by
by_cases hp : p = 0
· rw [hp, zero_mul, mirror_zero, zero_mul]
by_cases hq : q = 0
· rw [hq, mul_zero, mirror_zero, mul_zero]
rw [mirror, mirror, mirror, reverse_mul_of_domain, natTrailingDegree_mul hp hq, pow_add]
rw [mul_assoc, ← mul_assoc q.reverse, ← X_pow_mul (p := reverse q)]
repeat' rw [mul_assoc]
theorem mirror_smul (a : R) : (a • p).mirror = a • p.mirror := by
rw [← C_mul', ← C_mul', mirror_mul_of_domain, mirror_C]
end Ring
section CommRing
variable {R : Type*} [CommRing R] [NoZeroDivisors R] {f : R[X]}
theorem irreducible_of_mirror (h1 : ¬IsUnit f)
(h2 : ∀ k, f * f.mirror = k * k.mirror → k = f ∨ k = -f ∨ k = f.mirror ∨ k = -f.mirror)
(h3 : IsRelPrime f f.mirror) : Irreducible f := by
constructor
· exact h1
· intro g h fgh
let k := g * h.mirror
have key : f * f.mirror = k * k.mirror := by
| rw [fgh, mirror_mul_of_domain, mirror_mul_of_domain, mirror_mirror, mul_assoc, mul_comm h,
mul_comm g.mirror, mul_assoc, ← mul_assoc]
have g_dvd_f : g ∣ f := by
rw [fgh]
exact dvd_mul_right g h
have h_dvd_f : h ∣ f := by
rw [fgh]
exact dvd_mul_left h g
| Mathlib/Algebra/Polynomial/Mirror.lean | 199 | 206 |
/-
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)
(hf' : s.EqOn (deriv f) (deriv g)) (hx : x ∈ s) (hfgx : f x = g x) :
s.EqOn f g :=
hs.eqOn_of_fderiv_eq hs' hf hg (fun _ hx ↦ ContinuousLinearMap.ext_ring (hf' hx)) hx hfgx
end Convex
end
section RCLike
/-!
### Vector-valued functions `f : E → F`. Strict differentiability.
A `C^1` function is strictly differentiable, when the field is `ℝ` or `ℂ`. This follows from the
mean value inequality on balls, which is a particular case of the above results after restricting
the scalars to `ℝ`. Note that it does not make sense to talk of a convex set over `ℂ`, but balls
make sense and are enough. Many formulations of the mean value inequality could be generalized to
balls over `ℝ` or `ℂ`. For now, we only include the ones that we need.
-/
variable {𝕜 : Type*} [RCLike 𝕜] {G : Type*} [NormedAddCommGroup G] [NormedSpace 𝕜 G] {H : Type*}
[NormedAddCommGroup H] [NormedSpace 𝕜 H] {f : G → H} {f' : G → G →L[𝕜] H} {x : G}
/-- Over the reals or the complexes, a continuously differentiable function is strictly
differentiable. -/
theorem hasStrictFDerivAt_of_hasFDerivAt_of_continuousAt
(hder : ∀ᶠ y in 𝓝 x, HasFDerivAt f (f' y) y) (hcont : ContinuousAt f' x) :
HasStrictFDerivAt f (f' x) x := by
-- turn little-o definition of strict_fderiv into an epsilon-delta statement
rw [hasStrictFDerivAt_iff_isLittleO, isLittleO_iff]
refine fun c hc => Metric.eventually_nhds_iff_ball.mpr ?_
-- the correct ε is the modulus of continuity of f'
rcases Metric.mem_nhds_iff.mp (inter_mem hder (hcont <| ball_mem_nhds _ hc)) with ⟨ε, ε0, hε⟩
refine ⟨ε, ε0, ?_⟩
-- simplify formulas involving the product E × E
rintro ⟨a, b⟩ h
rw [← ball_prod_same, prodMk_mem_set_prod_eq] at h
-- exploit the choice of ε as the modulus of continuity of f'
have hf' : ∀ x' ∈ ball x ε, ‖f' x' - f' x‖ ≤ c := fun x' H' => by
rw [← dist_eq_norm]
exact le_of_lt (hε H').2
-- apply mean value theorem
letI : NormedSpace ℝ G := RestrictScalars.normedSpace ℝ 𝕜 G
refine (convex_ball _ _).norm_image_sub_le_of_norm_hasFDerivWithin_le' ?_ hf' h.2 h.1
exact fun y hy => (hε hy).1.hasFDerivWithinAt
/-- Over the reals or the complexes, a continuously differentiable function is strictly
differentiable. -/
theorem hasStrictDerivAt_of_hasDerivAt_of_continuousAt {f f' : 𝕜 → G} {x : 𝕜}
(hder : ∀ᶠ y in 𝓝 x, HasDerivAt f (f' y) y) (hcont : ContinuousAt f' x) :
HasStrictDerivAt f (f' x) x :=
hasStrictFDerivAt_of_hasFDerivAt_of_continuousAt (hder.mono fun _ hy => hy.hasFDerivAt) <|
(smulRightL 𝕜 𝕜 G 1).continuous.continuousAt.comp hcont
end RCLike
| Mathlib/Analysis/Calculus/MeanValue.lean | 981 | 987 | |
/-
Copyright (c) 2015, 2017 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Robert Y. Lewis, Johannes Hölzl, Mario Carneiro, Sébastien Gouëzel
-/
import Mathlib.Algebra.Order.BigOperators.Group.Finset
import Mathlib.Order.Interval.Finset.Nat
import Mathlib.Topology.EMetricSpace.Defs
import Mathlib.Topology.UniformSpace.Compact
import Mathlib.Topology.UniformSpace.LocallyUniformConvergence
import Mathlib.Topology.UniformSpace.UniformEmbedding
/-!
# Extended metric spaces
Further results about extended metric spaces.
-/
open Set Filter
universe u v w
variable {α : Type u} {β : Type v} {X : Type*}
open scoped Uniformity Topology NNReal ENNReal Pointwise
variable [PseudoEMetricSpace α]
/-- The triangle (polygon) inequality for sequences of points; `Finset.Ico` version. -/
theorem edist_le_Ico_sum_edist (f : ℕ → α) {m n} (h : m ≤ n) :
edist (f m) (f n) ≤ ∑ i ∈ Finset.Ico m n, edist (f i) (f (i + 1)) := by
induction n, h using Nat.le_induction with
| base => rw [Finset.Ico_self, Finset.sum_empty, edist_self]
| succ n hle ihn =>
calc
edist (f m) (f (n + 1)) ≤ edist (f m) (f n) + edist (f n) (f (n + 1)) := edist_triangle _ _ _
_ ≤ (∑ i ∈ Finset.Ico m n, _) + _ := add_le_add ihn le_rfl
_ = ∑ i ∈ Finset.Ico m (n + 1), _ := by
{ rw [Nat.Ico_succ_right_eq_insert_Ico hle, Finset.sum_insert, add_comm]; simp }
/-- The triangle (polygon) inequality for sequences of points; `Finset.range` version. -/
theorem edist_le_range_sum_edist (f : ℕ → α) (n : ℕ) :
edist (f 0) (f n) ≤ ∑ i ∈ Finset.range n, edist (f i) (f (i + 1)) :=
Nat.Ico_zero_eq_range ▸ edist_le_Ico_sum_edist f (Nat.zero_le n)
/-- A version of `edist_le_Ico_sum_edist` with each intermediate distance replaced
with an upper estimate. -/
theorem edist_le_Ico_sum_of_edist_le {f : ℕ → α} {m n} (hmn : m ≤ n) {d : ℕ → ℝ≥0∞}
(hd : ∀ {k}, m ≤ k → k < n → edist (f k) (f (k + 1)) ≤ d k) :
edist (f m) (f n) ≤ ∑ i ∈ Finset.Ico m n, d i :=
le_trans (edist_le_Ico_sum_edist f hmn) <|
Finset.sum_le_sum fun _k hk => hd (Finset.mem_Ico.1 hk).1 (Finset.mem_Ico.1 hk).2
/-- A version of `edist_le_range_sum_edist` with each intermediate distance replaced
with an upper estimate. -/
theorem edist_le_range_sum_of_edist_le {f : ℕ → α} (n : ℕ) {d : ℕ → ℝ≥0∞}
(hd : ∀ {k}, k < n → edist (f k) (f (k + 1)) ≤ d k) :
edist (f 0) (f n) ≤ ∑ i ∈ Finset.range n, d i :=
Nat.Ico_zero_eq_range ▸ edist_le_Ico_sum_of_edist_le (zero_le n) fun _ => hd
namespace EMetric
theorem isUniformInducing_iff [PseudoEMetricSpace β] {f : α → β} :
IsUniformInducing f ↔ UniformContinuous f ∧
∀ δ > 0, ∃ ε > 0, ∀ {a b : α}, edist (f a) (f b) < ε → edist a b < δ :=
isUniformInducing_iff'.trans <| Iff.rfl.and <|
((uniformity_basis_edist.comap _).le_basis_iff uniformity_basis_edist).trans <| by
simp only [subset_def, Prod.forall]; rfl
/-- ε-δ characterization of uniform embeddings on pseudoemetric spaces -/
nonrec theorem isUniformEmbedding_iff [PseudoEMetricSpace β] {f : α → β} :
IsUniformEmbedding f ↔ Function.Injective f ∧ UniformContinuous f ∧
∀ δ > 0, ∃ ε > 0, ∀ {a b : α}, edist (f a) (f b) < ε → edist a b < δ :=
(isUniformEmbedding_iff _).trans <| and_comm.trans <| Iff.rfl.and isUniformInducing_iff
/-- If a map between pseudoemetric spaces is a uniform embedding then the edistance between `f x`
and `f y` is controlled in terms of the distance between `x` and `y`.
In fact, this lemma holds for a `IsUniformInducing` map.
TODO: generalize? -/
theorem controlled_of_isUniformEmbedding [PseudoEMetricSpace β] {f : α → β}
(h : IsUniformEmbedding f) :
(∀ ε > 0, ∃ δ > 0, ∀ {a b : α}, edist a b < δ → edist (f a) (f b) < ε) ∧
∀ δ > 0, ∃ ε > 0, ∀ {a b : α}, edist (f a) (f b) < ε → edist a b < δ :=
⟨uniformContinuous_iff.1 h.uniformContinuous, (isUniformEmbedding_iff.1 h).2.2⟩
/-- ε-δ characterization of Cauchy sequences on pseudoemetric spaces -/
protected theorem cauchy_iff {f : Filter α} :
Cauchy f ↔ f ≠ ⊥ ∧ ∀ ε > 0, ∃ t ∈ f, ∀ x, x ∈ t → ∀ y, y ∈ t → edist x y < ε := by
rw [← neBot_iff]; exact uniformity_basis_edist.cauchy_iff
/-- A very useful criterion to show that a space is complete is to show that all sequences
which satisfy a bound of the form `edist (u n) (u m) < B N` for all `n m ≥ N` are
converging. This is often applied for `B N = 2^{-N}`, i.e., with a very fast convergence to
`0`, which makes it possible to use arguments of converging series, while this is impossible
to do in general for arbitrary Cauchy sequences. -/
theorem complete_of_convergent_controlled_sequences (B : ℕ → ℝ≥0∞) (hB : ∀ n, 0 < B n)
(H : ∀ u : ℕ → α, (∀ N n m : ℕ, N ≤ n → N ≤ m → edist (u n) (u m) < B N) →
∃ x, Tendsto u atTop (𝓝 x)) :
CompleteSpace α :=
UniformSpace.complete_of_convergent_controlled_sequences
(fun n => { p : α × α | edist p.1 p.2 < B n }) (fun n => edist_mem_uniformity <| hB n) H
/-- A sequentially complete pseudoemetric space is complete. -/
theorem complete_of_cauchySeq_tendsto :
(∀ u : ℕ → α, CauchySeq u → ∃ a, Tendsto u atTop (𝓝 a)) → CompleteSpace α :=
UniformSpace.complete_of_cauchySeq_tendsto
/-- Expressing locally uniform convergence on a set using `edist`. -/
theorem tendstoLocallyUniformlyOn_iff {ι : Type*} [TopologicalSpace β] {F : ι → β → α} {f : β → α}
{p : Filter ι} {s : Set β} :
TendstoLocallyUniformlyOn F f p s ↔
∀ ε > 0, ∀ x ∈ s, ∃ t ∈ 𝓝[s] x, ∀ᶠ n in p, ∀ y ∈ t, edist (f y) (F n y) < ε := by
refine ⟨fun H ε hε => H _ (edist_mem_uniformity hε), fun H u hu x hx => ?_⟩
rcases mem_uniformity_edist.1 hu with ⟨ε, εpos, hε⟩
rcases H ε εpos x hx with ⟨t, ht, Ht⟩
exact ⟨t, ht, Ht.mono fun n hs x hx => hε (hs x hx)⟩
/-- Expressing uniform convergence on a set using `edist`. -/
theorem tendstoUniformlyOn_iff {ι : Type*} {F : ι → β → α} {f : β → α} {p : Filter ι} {s : Set β} :
TendstoUniformlyOn F f p s ↔ ∀ ε > 0, ∀ᶠ n in p, ∀ x ∈ s, edist (f x) (F n x) < ε := by
refine ⟨fun H ε hε => H _ (edist_mem_uniformity hε), fun H u hu => ?_⟩
rcases mem_uniformity_edist.1 hu with ⟨ε, εpos, hε⟩
exact (H ε εpos).mono fun n hs x hx => hε (hs x hx)
/-- Expressing locally uniform convergence using `edist`. -/
theorem tendstoLocallyUniformly_iff {ι : Type*} [TopologicalSpace β] {F : ι → β → α} {f : β → α}
{p : Filter ι} :
TendstoLocallyUniformly F f p ↔
∀ ε > 0, ∀ x : β, ∃ t ∈ 𝓝 x, ∀ᶠ n in p, ∀ y ∈ t, edist (f y) (F n y) < ε := by
simp only [← tendstoLocallyUniformlyOn_univ, tendstoLocallyUniformlyOn_iff, mem_univ,
forall_const, exists_prop, nhdsWithin_univ]
/-- Expressing uniform convergence using `edist`. -/
theorem tendstoUniformly_iff {ι : Type*} {F : ι → β → α} {f : β → α} {p : Filter ι} :
TendstoUniformly F f p ↔ ∀ ε > 0, ∀ᶠ n in p, ∀ x, edist (f x) (F n x) < ε := by
simp only [← tendstoUniformlyOn_univ, tendstoUniformlyOn_iff, mem_univ, forall_const]
end EMetric
open EMetric
namespace EMetric
variable {x y z : α} {ε ε₁ ε₂ : ℝ≥0∞} {s t : Set α}
theorem inseparable_iff : Inseparable x y ↔ edist x y = 0 := by
simp [inseparable_iff_mem_closure, mem_closure_iff, edist_comm, forall_lt_iff_le']
alias ⟨_root_.Inseparable.edist_eq_zero, _⟩ := EMetric.inseparable_iff
-- see Note [nolint_ge]
/-- In a pseudoemetric space, Cauchy sequences are characterized by the fact that, eventually,
the pseudoedistance between its elements is arbitrarily small -/
theorem cauchySeq_iff [Nonempty β] [SemilatticeSup β] {u : β → α} :
CauchySeq u ↔ ∀ ε > 0, ∃ N, ∀ m, N ≤ m → ∀ n, N ≤ n → edist (u m) (u n) < ε :=
uniformity_basis_edist.cauchySeq_iff
/-- A variation around the emetric characterization of Cauchy sequences -/
theorem cauchySeq_iff' [Nonempty β] [SemilatticeSup β] {u : β → α} :
CauchySeq u ↔ ∀ ε > (0 : ℝ≥0∞), ∃ N, ∀ n ≥ N, edist (u n) (u N) < ε :=
uniformity_basis_edist.cauchySeq_iff'
/-- A variation of the emetric characterization of Cauchy sequences that deals with
`ℝ≥0` upper bounds. -/
theorem cauchySeq_iff_NNReal [Nonempty β] [SemilatticeSup β] {u : β → α} :
CauchySeq u ↔ ∀ ε : ℝ≥0, 0 < ε → ∃ N, ∀ n, N ≤ n → edist (u n) (u N) < ε :=
uniformity_basis_edist_nnreal.cauchySeq_iff'
theorem totallyBounded_iff {s : Set α} :
TotallyBounded s ↔ ∀ ε > 0, ∃ t : Set α, t.Finite ∧ s ⊆ ⋃ y ∈ t, ball y ε :=
⟨fun H _ε ε0 => H _ (edist_mem_uniformity ε0), fun H _r ru =>
let ⟨ε, ε0, hε⟩ := mem_uniformity_edist.1 ru
let ⟨t, ft, h⟩ := H ε ε0
⟨t, ft, h.trans <| iUnion₂_mono fun _ _ _ => hε⟩⟩
theorem totallyBounded_iff' {s : Set α} :
TotallyBounded s ↔ ∀ ε > 0, ∃ t, t ⊆ s ∧ Set.Finite t ∧ s ⊆ ⋃ y ∈ t, ball y ε :=
⟨fun H _ε ε0 => (totallyBounded_iff_subset.1 H) _ (edist_mem_uniformity ε0), fun H _r ru =>
let ⟨ε, ε0, hε⟩ := mem_uniformity_edist.1 ru
let ⟨t, _, ft, h⟩ := H ε ε0
⟨t, ft, h.trans <| iUnion₂_mono fun _ _ _ => hε⟩⟩
section Compact
-- TODO: generalize to metrizable spaces
/-- A compact set in a pseudo emetric space is separable, i.e., it is a subset of the closure of a
countable set. -/
theorem subset_countable_closure_of_compact {s : Set α} (hs : IsCompact s) :
∃ t, t ⊆ s ∧ t.Countable ∧ s ⊆ closure t := by
refine subset_countable_closure_of_almost_dense_set s fun ε hε => ?_
rcases totallyBounded_iff'.1 hs.totallyBounded ε hε with ⟨t, -, htf, hst⟩
exact ⟨t, htf.countable, hst.trans <| iUnion₂_mono fun _ _ => ball_subset_closedBall⟩
end Compact
section SecondCountable
open TopologicalSpace
variable (α) in
/-- A sigma compact pseudo emetric space has second countable topology. -/
instance (priority := 90) secondCountable_of_sigmaCompact [SigmaCompactSpace α] :
SecondCountableTopology α := by
suffices SeparableSpace α by exact UniformSpace.secondCountable_of_separable α
choose T _ hTc hsubT using fun n =>
subset_countable_closure_of_compact (isCompact_compactCovering α n)
refine ⟨⟨⋃ n, T n, countable_iUnion hTc, fun x => ?_⟩⟩
rcases iUnion_eq_univ_iff.1 (iUnion_compactCovering α) x with ⟨n, hn⟩
exact closure_mono (subset_iUnion _ n) (hsubT _ hn)
theorem secondCountable_of_almost_dense_set
(hs : ∀ ε > 0, ∃ t : Set α, t.Countable ∧ ⋃ x ∈ t, closedBall x ε = univ) :
SecondCountableTopology α := by
suffices SeparableSpace α from UniformSpace.secondCountable_of_separable α
have : ∀ ε > 0, ∃ t : Set α, Set.Countable t ∧ univ ⊆ ⋃ x ∈ t, closedBall x ε := by
simpa only [univ_subset_iff] using hs
rcases subset_countable_closure_of_almost_dense_set (univ : Set α) this with ⟨t, -, htc, ht⟩
exact ⟨⟨t, htc, fun x => ht (mem_univ x)⟩⟩
end SecondCountable
end EMetric
variable {γ : Type w} [EMetricSpace γ]
-- see Note [lower instance priority]
/-- An emetric space is separated -/
instance (priority := 100) EMetricSpace.instT0Space : T0Space γ where
t0 _ _ h := eq_of_edist_eq_zero <| inseparable_iff.1 h
/-- A map between emetric spaces is a uniform embedding if and only if the edistance between `f x`
and `f y` is controlled in terms of the distance between `x` and `y` and conversely. -/
theorem EMetric.isUniformEmbedding_iff' [PseudoEMetricSpace β] {f : γ → β} :
IsUniformEmbedding f ↔
(∀ ε > 0, ∃ δ > 0, ∀ {a b : γ}, edist a b < δ → edist (f a) (f b) < ε) ∧
∀ δ > 0, ∃ ε > 0, ∀ {a b : γ}, edist (f a) (f b) < ε → edist a b < δ := by
rw [isUniformEmbedding_iff_isUniformInducing, isUniformInducing_iff, uniformContinuous_iff]
/-- If a `PseudoEMetricSpace` is a T₀ space, then it is an `EMetricSpace`. -/
-- TODO: make it an instance?
abbrev EMetricSpace.ofT0PseudoEMetricSpace (α : Type*) [PseudoEMetricSpace α] [T0Space α] :
EMetricSpace α :=
{ ‹PseudoEMetricSpace α› with
eq_of_edist_eq_zero := fun h => (EMetric.inseparable_iff.2 h).eq }
/-- The product of two emetric spaces, with the max distance, is an extended
metric spaces. We make sure that the uniform structure thus constructed is the one
corresponding to the product of uniform spaces, to avoid diamond problems. -/
instance Prod.emetricSpaceMax [EMetricSpace β] : EMetricSpace (γ × β) :=
.ofT0PseudoEMetricSpace _
namespace EMetric
/-- A compact set in an emetric space is separable, i.e., it is the closure of a countable set. -/
theorem countable_closure_of_compact {s : Set γ} (hs : IsCompact s) :
∃ t, t ⊆ s ∧ t.Countable ∧ s = closure t := by
rcases subset_countable_closure_of_compact hs with ⟨t, hts, htc, hsub⟩
exact ⟨t, hts, htc, hsub.antisymm (closure_minimal hts hs.isClosed)⟩
end EMetric
/-!
### Separation quotient
-/
instance [PseudoEMetricSpace X] : EDist (SeparationQuotient X) where
edist := SeparationQuotient.lift₂ edist fun _ _ _ _ hx hy =>
edist_congr (EMetric.inseparable_iff.1 hx) (EMetric.inseparable_iff.1 hy)
@[simp] theorem SeparationQuotient.edist_mk [PseudoEMetricSpace X] (x y : X) :
edist (mk x) (mk y) = edist x y :=
rfl
open SeparationQuotient in
instance [PseudoEMetricSpace X] : EMetricSpace (SeparationQuotient X) :=
@EMetricSpace.ofT0PseudoEMetricSpace (SeparationQuotient X)
{ edist_self := surjective_mk.forall.2 edist_self,
edist_comm := surjective_mk.forall₂.2 edist_comm,
edist_triangle := surjective_mk.forall₃.2 edist_triangle,
toUniformSpace := inferInstance,
uniformity_edist := comap_injective (surjective_mk.prodMap surjective_mk) <| by
simp [comap_mk_uniformity, PseudoEMetricSpace.uniformity_edist] } _
namespace TopologicalSpace
section Compact
open Topology
/-- If a set `s` is separable in a (pseudo extended) metric space, then it admits a countable dense
subset. This is not obvious, as the countable set whose closure covers `s` given by the definition
of separability does not need in general to be contained in `s`. -/
theorem IsSeparable.exists_countable_dense_subset
{s : Set α} (hs : IsSeparable s) : ∃ t, t ⊆ s ∧ t.Countable ∧ s ⊆ closure t := by
have : ∀ ε > 0, ∃ t : Set α, t.Countable ∧ s ⊆ ⋃ x ∈ t, closedBall x ε := fun ε ε0 => by
rcases hs with ⟨t, htc, hst⟩
refine ⟨t, htc, hst.trans fun x hx => ?_⟩
rcases mem_closure_iff.1 hx ε ε0 with ⟨y, hyt, hxy⟩
exact mem_iUnion₂.2 ⟨y, hyt, mem_closedBall.2 hxy.le⟩
exact subset_countable_closure_of_almost_dense_set _ this
/-- If a set `s` is separable, then the corresponding subtype is separable in a (pseudo extended)
metric space. This is not obvious, as the countable set whose closure covers `s` does not need in
general to be contained in `s`. -/
theorem IsSeparable.separableSpace {s : Set α} (hs : IsSeparable s) :
SeparableSpace s := by
rcases hs.exists_countable_dense_subset with ⟨t, hts, htc, hst⟩
lift t to Set s using hts
refine ⟨⟨t, countable_of_injective_of_countable_image Subtype.coe_injective.injOn htc, ?_⟩⟩
rwa [IsInducing.subtypeVal.dense_iff, Subtype.forall]
end Compact
end TopologicalSpace
section LebesgueNumberLemma
variable {s : Set α}
theorem lebesgue_number_lemma_of_emetric {ι : Sort*} {c : ι → Set α} (hs : IsCompact s)
(hc₁ : ∀ i, IsOpen (c i)) (hc₂ : s ⊆ ⋃ i, c i) : ∃ δ > 0, ∀ x ∈ s, ∃ i, ball x δ ⊆ c i := by
simpa only [ball, UniformSpace.ball, preimage_setOf_eq, edist_comm]
using uniformity_basis_edist.lebesgue_number_lemma hs hc₁ hc₂
theorem lebesgue_number_lemma_of_emetric_nhds' {c : (x : α) → x ∈ s → Set α} (hs : IsCompact s)
(hc : ∀ x hx, c x hx ∈ 𝓝 x) : ∃ δ > 0, ∀ x ∈ s, ∃ y : s, ball x δ ⊆ c y y.2 := by
simpa only [ball, UniformSpace.ball, preimage_setOf_eq, edist_comm]
using uniformity_basis_edist.lebesgue_number_lemma_nhds' hs hc
theorem lebesgue_number_lemma_of_emetric_nhds {c : α → Set α} (hs : IsCompact s)
(hc : ∀ x ∈ s, c x ∈ 𝓝 x) : ∃ δ > 0, ∀ x ∈ s, ∃ y, ball x δ ⊆ c y := by
simpa only [ball, UniformSpace.ball, preimage_setOf_eq, edist_comm]
using uniformity_basis_edist.lebesgue_number_lemma_nhds hs hc
theorem lebesgue_number_lemma_of_emetric_nhdsWithin' {c : (x : α) → x ∈ s → Set α}
(hs : IsCompact s) (hc : ∀ x hx, c x hx ∈ 𝓝[s] x) :
∃ δ > 0, ∀ x ∈ s, ∃ y : s, ball x δ ∩ s ⊆ c y y.2 := by
simpa only [ball, UniformSpace.ball, preimage_setOf_eq, edist_comm]
using uniformity_basis_edist.lebesgue_number_lemma_nhdsWithin' hs hc
theorem lebesgue_number_lemma_of_emetric_nhdsWithin {c : α → Set α} (hs : IsCompact s)
(hc : ∀ x ∈ s, c x ∈ 𝓝[s] x) : ∃ δ > 0, ∀ x ∈ s, ∃ y, ball x δ ∩ s ⊆ c y := by
simpa only [ball, UniformSpace.ball, preimage_setOf_eq, edist_comm]
using uniformity_basis_edist.lebesgue_number_lemma_nhdsWithin hs hc
theorem lebesgue_number_lemma_of_emetric_sUnion {c : Set (Set α)} (hs : IsCompact s)
(hc₁ : ∀ t ∈ c, IsOpen t) (hc₂ : s ⊆ ⋃₀ c) : ∃ δ > 0, ∀ x ∈ s, ∃ t ∈ c, ball x δ ⊆ t := by
rw [sUnion_eq_iUnion] at hc₂; simpa using lebesgue_number_lemma_of_emetric hs (by simpa) hc₂
end LebesgueNumberLemma
| Mathlib/Topology/EMetricSpace/Basic.lean | 959 | 960 | |
/-
Copyright (c) 2021 Riccardo Brasca. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Riccardo Brasca
-/
import Mathlib.LinearAlgebra.Dimension.LinearMap
import Mathlib.LinearAlgebra.FreeModule.StrongRankCondition
import Mathlib.LinearAlgebra.Matrix.ToLin
/-!
# Finite and free modules using matrices
We provide some instances for finite and free modules involving matrices.
## Main results
* `Module.Free.linearMap` : if `M` and `N` are finite and free, then `M →ₗ[R] N` is free.
* `Module.Finite.ofBasis` : A free module with a basis indexed by a `Fintype` is finite.
* `Module.Finite.linearMap` : if `M` and `N` are finite and free, then `M →ₗ[R] N`
is finite.
-/
universe u u' v w
variable (R : Type u) (S : Type u') (M : Type v) (N : Type w)
open Module.Free (chooseBasis ChooseBasisIndex)
open Module (finrank)
section Ring
variable [Ring R] [Ring S] [AddCommGroup M] [Module R M] [Module.Free R M] [Module.Finite R M]
variable [AddCommGroup N] [Module R N] [Module S N] [SMulCommClass R S N]
private noncomputable def linearMapEquivFun : (M →ₗ[R] N) ≃ₗ[S] ChooseBasisIndex R M → N :=
(chooseBasis R M).repr.congrLeft N S ≪≫ₗ (Finsupp.lsum S).symm ≪≫ₗ
LinearEquiv.piCongrRight fun _ ↦ LinearMap.ringLmapEquivSelf R S N
instance Module.Free.linearMap [Module.Free S N] : Module.Free S (M →ₗ[R] N) :=
Module.Free.of_equiv (linearMapEquivFun R S M N).symm
instance Module.Finite.linearMap [Module.Finite S N] : Module.Finite S (M →ₗ[R] N) :=
Module.Finite.equiv (linearMapEquivFun R S M N).symm
variable [StrongRankCondition R] [StrongRankCondition S] [Module.Free S N]
open Cardinal
theorem Module.rank_linearMap :
Module.rank S (M →ₗ[R] N) = lift.{w} (Module.rank R M) * lift.{v} (Module.rank S N) := by
rw [(linearMapEquivFun R S M N).rank_eq, rank_fun_eq_lift_mul,
← finrank_eq_card_chooseBasisIndex, ← finrank_eq_rank R, lift_natCast]
/-- The finrank of `M →ₗ[R] N` as an `S`-module is `(finrank R M) * (finrank S N)`. -/
theorem Module.finrank_linearMap :
finrank S (M →ₗ[R] N) = finrank R M * finrank S N := by
simp_rw [finrank, rank_linearMap, toNat_mul, toNat_lift]
variable [Module R S] [SMulCommClass R S S]
theorem Module.rank_linearMap_self :
Module.rank S (M →ₗ[R] S) = lift.{u'} (Module.rank R M) := by
rw [rank_linearMap, rank_self, lift_one, mul_one]
theorem Module.finrank_linearMap_self : finrank S (M →ₗ[R] S) = finrank R M := by
rw [finrank_linearMap, finrank_self, mul_one]
end Ring
section AlgHom
variable (K M : Type*) (L : Type v) [CommRing K] [Ring M] [Algebra K M]
[Module.Free K M] [Module.Finite K M] [CommRing L] [IsDomain L] [Algebra K L]
instance Finite.algHom : Finite (M →ₐ[K] L) :=
(linearIndependent_algHom_toLinearMap K M L).finite
open Cardinal
theorem cardinalMk_algHom_le_rank : #(M →ₐ[K] L) ≤ lift.{v} (Module.rank K M) := by
convert (linearIndependent_algHom_toLinearMap K M L).cardinal_lift_le_rank
· rw [lift_id]
· have := Module.nontrivial K L
rw [lift_id, Module.rank_linearMap_self]
@[deprecated (since := "2024-11-10")] alias cardinal_mk_algHom_le_rank := cardinalMk_algHom_le_rank
@[stacks 09HS]
theorem card_algHom_le_finrank : Nat.card (M →ₐ[K] L) ≤ finrank K M := by
convert toNat_le_toNat (cardinalMk_algHom_le_rank K M L) ?_
· rw [toNat_lift, finrank]
· rw [lift_lt_aleph0]; have := Module.nontrivial K L; apply Module.rank_lt_aleph0
end AlgHom
section Integer
variable [AddCommGroup M] [Module.Finite ℤ M] [Module.Free ℤ M] [AddCommGroup N]
instance Module.Finite.addMonoidHom [Module.Finite ℤ N] : Module.Finite ℤ (M →+ N) :=
Module.Finite.equiv (addMonoidHomLequivInt ℤ).symm
instance Module.Free.addMonoidHom [Module.Free ℤ N] : Module.Free ℤ (M →+ N) :=
letI : Module.Free ℤ (M →ₗ[ℤ] N) := Module.Free.linearMap _ _ _ _
Module.Free.of_equiv (addMonoidHomLequivInt ℤ).symm
end Integer
theorem Matrix.rank_vecMulVec {K m n : Type u} [CommRing K] [Fintype n]
[DecidableEq n] (w : m → K) (v : n → K) : (Matrix.vecMulVec w v).toLin'.rank ≤ 1 := by
nontriviality K
| rw [Matrix.vecMulVec_eq (Fin 1), Matrix.toLin'_mul]
refine le_trans (LinearMap.rank_comp_le_left _ _) ?_
refine (LinearMap.rank_le_domain _).trans_eq ?_
rw [rank_fun', Fintype.card_ofSubsingleton, Nat.cast_one]
| Mathlib/LinearAlgebra/FreeModule/Finite/Matrix.lean | 113 | 119 |
/-
Copyright (c) 2023 Dagur Asgeirsson. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Dagur Asgeirsson, Filippo A. E. Nuccio, Riccardo Brasca
-/
import Mathlib.CategoryTheory.EffectiveEpi.Preserves
import Mathlib.CategoryTheory.Limits.Final.ParallelPair
import Mathlib.CategoryTheory.Preadditive.Projective.Basic
import Mathlib.CategoryTheory.Sites.Canonical
import Mathlib.CategoryTheory.Sites.Coherent.Basic
import Mathlib.CategoryTheory.Sites.EffectiveEpimorphic
/-!
# Sheaves for the regular topology
This file characterises sheaves for the regular topology.
## Main results
* `equalizerCondition_iff_isSheaf`: In a preregular category with pullbacks, the sheaves for the
regular topology are precisely the presheaves satisfying an equaliser condition with respect to
effective epimorphisms.
* `isSheaf_of_projective`: In a preregular category in which every object is projective, every
presheaf is a sheaf for the regular topology.
-/
namespace CategoryTheory
open Limits
variable {C D E : Type*} [Category C] [Category D] [Category E]
open Opposite Presieve Functor
/-- A presieve is *regular* if it consists of a single effective epimorphism. -/
class Presieve.regular {X : C} (R : Presieve X) : Prop where
/-- `R` consists of a single epimorphism. -/
single_epi : ∃ (Y : C) (f : Y ⟶ X), R = Presieve.ofArrows (fun (_ : Unit) ↦ Y)
(fun (_ : Unit) ↦ f) ∧ EffectiveEpi f
namespace regularTopology
lemma equalizerCondition_w (P : Cᵒᵖ ⥤ D) {X B : C} {π : X ⟶ B} (c : PullbackCone π π) :
P.map π.op ≫ P.map c.fst.op = P.map π.op ≫ P.map c.snd.op := by
simp only [← Functor.map_comp, ← op_comp, c.condition]
/--
A contravariant functor on `C` satisfies `SingleEqualizerCondition` with respect to a morphism `π`
if it takes its kernel pair to an equalizer diagram.
-/
def SingleEqualizerCondition (P : Cᵒᵖ ⥤ D) ⦃X B : C⦄ (π : X ⟶ B) : Prop :=
∀ (c : PullbackCone π π) (_ : IsLimit c),
Nonempty (IsLimit (Fork.ofι (P.map π.op) (equalizerCondition_w P c)))
/--
A contravariant functor on `C` satisfies `EqualizerCondition` if it takes kernel pairs of effective
epimorphisms to equalizer diagrams.
-/
def EqualizerCondition (P : Cᵒᵖ ⥤ D) : Prop :=
∀ ⦃X B : C⦄ (π : X ⟶ B) [EffectiveEpi π], SingleEqualizerCondition P π
/-- The equalizer condition is preserved by natural isomorphism. -/
theorem equalizerCondition_of_natIso {P P' : Cᵒᵖ ⥤ D} (i : P ≅ P')
(hP : EqualizerCondition P) : EqualizerCondition P' := fun X B π _ c hc ↦
⟨Fork.isLimitOfIsos _ (hP π c hc).some _ (i.app _) (i.app _) (i.app _)⟩
/-- Precomposing with a pullback-preserving functor preserves the equalizer condition. -/
theorem equalizerCondition_precomp_of_preservesPullback (P : Cᵒᵖ ⥤ D) (F : E ⥤ C)
[∀ {X B} (π : X ⟶ B) [EffectiveEpi π], PreservesLimit (cospan π π) F]
[F.PreservesEffectiveEpis] (hP : EqualizerCondition P) : EqualizerCondition (F.op ⋙ P) := by
intro X B π _ c hc
have h : P.map (F.map π).op = (F.op ⋙ P).map π.op := by simp
refine ⟨(IsLimit.equivIsoLimit (ForkOfι.ext ?_ _ h)) ?_⟩
· simp only [Functor.comp_map, op_map, Quiver.Hom.unop_op, ← map_comp, ← op_comp, c.condition]
· refine (hP (F.map π) (PullbackCone.mk (F.map c.fst) (F.map c.snd) ?_) ?_).some
· simp only [← map_comp, c.condition]
· exact (isLimitMapConePullbackConeEquiv F c.condition)
(isLimitOfPreserves F (hc.ofIsoLimit (PullbackCone.ext (Iso.refl _) (by simp) (by simp))))
/-- The canonical map to the explicit equalizer. -/
def MapToEqualizer (P : Cᵒᵖ ⥤ Type*) {W X B : C} (f : X ⟶ B)
(g₁ g₂ : W ⟶ X) (w : g₁ ≫ f = g₂ ≫ f) :
P.obj (op B) → { x : P.obj (op X) | P.map g₁.op x = P.map g₂.op x } := fun t ↦
⟨P.map f.op t, by simp only [Set.mem_setOf_eq, ← FunctorToTypes.map_comp_apply, ← op_comp, w]⟩
theorem EqualizerCondition.bijective_mapToEqualizer_pullback (P : Cᵒᵖ ⥤ Type*)
(hP : EqualizerCondition P) : ∀ (X B : C) (π : X ⟶ B) [EffectiveEpi π] [HasPullback π π],
Function.Bijective
(MapToEqualizer P π (pullback.fst π π) (pullback.snd π π) pullback.condition) := by
intro X B π _ _
specialize hP π _ (pullbackIsPullback π π)
rw [Types.type_equalizer_iff_unique] at hP
rw [Function.bijective_iff_existsUnique]
intro ⟨b, hb⟩
obtain ⟨a, ha₁, ha₂⟩ := hP b hb
refine ⟨a, ?_, ?_⟩
· simpa [MapToEqualizer] using ha₁
· simpa [MapToEqualizer] using ha₂
theorem EqualizerCondition.mk (P : Cᵒᵖ ⥤ Type*)
(hP : ∀ (X B : C) (π : X ⟶ B) [EffectiveEpi π] [HasPullback π π], Function.Bijective
(MapToEqualizer P π (pullback.fst π π) (pullback.snd π π)
pullback.condition)) : EqualizerCondition P := by
intro X B π _ c hc
have : HasPullback π π := ⟨c, hc⟩
specialize hP X B π
rw [Types.type_equalizer_iff_unique]
rw [Function.bijective_iff_existsUnique] at hP
intro b hb
have h₁ : ((pullbackIsPullback π π).conePointUniqueUpToIso hc).hom ≫ c.fst =
pullback.fst π π := by simp
have hb' : P.map (pullback.fst π π).op b = P.map (pullback.snd _ _).op b := by
rw [← h₁, op_comp, FunctorToTypes.map_comp_apply, hb]
simp [← FunctorToTypes.map_comp_apply, ← op_comp]
obtain ⟨a, ha₁, ha₂⟩ := hP ⟨b, hb'⟩
refine ⟨a, ?_, ?_⟩
· simpa [MapToEqualizer] using ha₁
· simpa [MapToEqualizer] using ha₂
lemma equalizerCondition_w' (P : Cᵒᵖ ⥤ Type*) {X B : C} (π : X ⟶ B)
[HasPullback π π] : P.map π.op ≫ P.map (pullback.fst π π).op =
P.map π.op ≫ P.map (pullback.snd π π).op := by
simp only [← Functor.map_comp, ← op_comp, pullback.condition]
lemma mapToEqualizer_eq_comp (P : Cᵒᵖ ⥤ Type*) {X B : C} (π : X ⟶ B) [HasPullback π π] :
MapToEqualizer P π (pullback.fst π π) (pullback.snd π π) pullback.condition =
equalizer.lift (P.map π.op) (equalizerCondition_w' P π) ≫
(Types.equalizerIso _ _).hom := by
rw [← Iso.comp_inv_eq (α := Types.equalizerIso _ _)]
apply equalizer.hom_ext
aesop
/-- An alternative phrasing of the explicit equalizer condition, using more categorical language. -/
theorem equalizerCondition_iff_isIso_lift (P : Cᵒᵖ ⥤ Type*) : EqualizerCondition P ↔
∀ (X B : C) (π : X ⟶ B) [EffectiveEpi π] [HasPullback π π],
IsIso (equalizer.lift (P.map π.op) (equalizerCondition_w' P π)) := by
constructor
· intro hP X B π _ _
have h := hP.bijective_mapToEqualizer_pullback _ X B π
rw [← isIso_iff_bijective, mapToEqualizer_eq_comp] at h
exact IsIso.of_isIso_comp_right (equalizer.lift (P.map π.op)
(equalizerCondition_w' P π))
(Types.equalizerIso _ _).hom
· intro hP
apply EqualizerCondition.mk
intro X B π _ _
rw [mapToEqualizer_eq_comp, ← isIso_iff_bijective]
infer_instance
/-- `P` satisfies the equalizer condition iff its precomposition by an equivalence does. -/
theorem equalizerCondition_iff_of_equivalence (P : Cᵒᵖ ⥤ D)
(e : C ≌ E) : EqualizerCondition P ↔ EqualizerCondition (e.op.inverse ⋙ P) :=
⟨fun h ↦ equalizerCondition_precomp_of_preservesPullback P e.inverse h, fun h ↦
equalizerCondition_of_natIso (e.op.funInvIdAssoc P)
(equalizerCondition_precomp_of_preservesPullback (e.op.inverse ⋙ P) e.functor h)⟩
open WalkingParallelPair WalkingParallelPairHom in
theorem parallelPair_pullback_initial {X B : C} (π : X ⟶ B)
| (c : PullbackCone π π) (hc : IsLimit c) :
(parallelPair (C := (Sieve.ofArrows (fun (_ : Unit) => X) (fun _ => π)).arrows.categoryᵒᵖ)
(Y := op ((Presieve.categoryMk _ (c.fst ≫ π) ⟨_, c.fst, π, ofArrows.mk (), rfl⟩)))
(X := op ((Presieve.categoryMk _ π (Sieve.ofArrows_mk _ _ Unit.unit))))
(Quiver.Hom.op (Over.homMk c.fst))
(Quiver.Hom.op (Over.homMk c.snd c.condition.symm))).Initial := by
apply Limits.parallelPair_initial_mk
· intro ⟨Z⟩
obtain ⟨_, f, g, ⟨⟩, hh⟩ := Z.property
let X' : (Presieve.ofArrows (fun () ↦ X) (fun () ↦ π)).category :=
Presieve.categoryMk _ π (ofArrows.mk ())
let f' : Z.obj.left ⟶ X'.obj.left := f
exact ⟨(Over.homMk f').op⟩
· intro ⟨Z⟩ ⟨i⟩ ⟨j⟩
let ij := PullbackCone.IsLimit.lift hc i.left j.left (by erw [i.w, j.w]; rfl)
refine ⟨Quiver.Hom.op (Over.homMk ij (by simpa [ij] using i.w)), ?_, ?_⟩
all_goals congr
all_goals exact Comma.hom_ext _ _ (by erw [Over.comp_left]; simp [ij]) rfl
| Mathlib/CategoryTheory/Sites/Coherent/RegularSheaves.lean | 160 | 178 |
/-
Copyright (c) 2021 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sébastien Gouëzel, Floris van Doorn, Yury Kudryashov
-/
import Mathlib.MeasureTheory.Constructions.BorelSpace.Order
import Mathlib.MeasureTheory.Group.MeasurableEquiv
import Mathlib.Topology.MetricSpace.HausdorffDistance
/-!
# Regular measures
A measure is `OuterRegular` if the measure of any measurable set `A` is the infimum of `μ U` over
all open sets `U` containing `A`.
A measure is `WeaklyRegular` if it satisfies the following properties:
* it is outer regular;
* it is inner regular for open sets with respect to closed sets: the measure of any open set `U`
is the supremum of `μ F` over all closed sets `F` contained in `U`.
A measure is `Regular` if it satisfies the following properties:
* it is finite on compact sets;
* it is outer regular;
* it is inner regular for open sets with respect to compacts closed sets: the measure of any open
set `U` is the supremum of `μ K` over all compact sets `K` contained in `U`.
A measure is `InnerRegular` if it is inner regular for measurable sets with respect to compact
sets: the measure of any measurable set `s` is the supremum of `μ K` over all compact
sets contained in `s`.
A measure is `InnerRegularCompactLTTop` if it is inner regular for measurable sets of finite
measure with respect to compact sets: the measure of any measurable set `s` is the supremum
of `μ K` over all compact sets contained in `s`.
There is a reason for this zoo of regularity classes:
* A finite measure on a metric space is always weakly regular. Therefore, in probability theory,
weakly regular measures play a prominent role.
* In locally compact topological spaces, there are two competing notions of Radon measures: the
ones that are regular, and the ones that are inner regular. For any of these two notions, there is
a Riesz representation theorem, and an existence and uniqueness statement for the Haar measure in
locally compact topological groups. The two notions coincide in sigma-compact spaces, but they
differ in general, so it is worth having the two of them.
* Both notions of Haar measure satisfy the weaker notion `InnerRegularCompactLTTop`, so it is worth
trying to express theorems using this weaker notion whenever possible, to make sure that it
applies to both Haar measures simultaneously.
While traditional textbooks on measure theory on locally compact spaces emphasize regular measures,
more recent textbooks emphasize that inner regular Haar measures are better behaved than regular
Haar measures, so we will develop both notions.
The five conditions above are registered as typeclasses for a measure `μ`, and implications between
them are recorded as instances. For example, in a Hausdorff topological space, regularity implies
weak regularity. Also, regularity or inner regularity both imply `InnerRegularCompactLTTop`.
In a regular locally compact finite measure space, then regularity, inner regularity
and `InnerRegularCompactLTTop` are all equivalent.
In order to avoid code duplication, we also define a measure `μ` to be `InnerRegularWRT` for sets
satisfying a predicate `q` with respect to sets satisfying a predicate `p` if for any set
`U ∈ {U | q U}` and a number `r < μ U` there exists `F ⊆ U` such that `p F` and `r < μ F`.
There are two main nontrivial results in the development below:
* `InnerRegularWRT.measurableSet_of_isOpen` shows that, for an outer regular measure, inner
regularity for open sets with respect to compact sets or closed sets implies inner regularity for
all measurable sets of finite measure (with respect to compact sets or closed sets respectively).
* `InnerRegularWRT.weaklyRegular_of_finite` shows that a finite measure which is inner regular for
open sets with respect to closed sets (for instance a finite measure on a metric space) is weakly
regular.
All other results are deduced from these ones.
Here is an example showing how regularity and inner regularity may differ even on locally compact
spaces. Consider the group `ℝ × ℝ` where the first factor has the discrete topology and the second
one the usual topology. It is a locally compact Hausdorff topological group, with Haar measure equal
to Lebesgue measure on each vertical fiber. Let us consider the regular version of Haar measure.
Then the set `ℝ × {0}` has infinite measure (by outer regularity), but any compact set it contains
has zero measure (as it is finite). In fact, this set only contains subset with measure zero or
infinity. The inner regular version of Haar measure, on the other hand, gives zero mass to the
set `ℝ × {0}`.
Another interesting example is the sum of the Dirac masses at rational points in the real line.
It is a σ-finite measure on a locally compact metric space, but it is not outer regular: for
outer regularity, one needs additional locally finite assumptions. On the other hand, it is
inner regular.
Several authors require both regularity and inner regularity for their measures. We have opted
for the more fine grained definitions above as they apply more generally.
## Main definitions
* `MeasureTheory.Measure.OuterRegular μ`: a typeclass registering that a measure `μ` on a
topological space is outer regular.
* `MeasureTheory.Measure.Regular μ`: a typeclass registering that a measure `μ` on a topological
space is regular.
* `MeasureTheory.Measure.WeaklyRegular μ`: a typeclass registering that a measure `μ` on a
topological space is weakly regular.
* `MeasureTheory.Measure.InnerRegularWRT μ p q`: a non-typeclass predicate saying that a measure `μ`
is inner regular for sets satisfying `q` with respect to sets satisfying `p`.
* `MeasureTheory.Measure.InnerRegular μ`: a typeclass registering that a measure `μ` on a
topological space is inner regular for measurable sets with respect to compact sets.
* `MeasureTheory.Measure.InnerRegularCompactLTTop μ`: a typeclass registering that a measure `μ`
on a topological space is inner regular for measurable sets of finite measure with respect to
compact sets.
## Main results
### Outer regular measures
* `Set.measure_eq_iInf_isOpen` asserts that, when `μ` is outer regular, the measure of a
set is the infimum of the measure of open sets containing it.
* `Set.exists_isOpen_lt_of_lt` asserts that, when `μ` is outer regular, for every set `s`
and `r > μ s` there exists an open superset `U ⊇ s` of measure less than `r`.
* push forward of an outer regular measure is outer regular, and scalar multiplication of a regular
measure by a finite number is outer regular.
### Weakly regular measures
* `IsOpen.measure_eq_iSup_isClosed` asserts that the measure of an open set is the supremum of
the measure of closed sets it contains.
* `IsOpen.exists_lt_isClosed`: for an open set `U` and `r < μ U`, there exists a closed `F ⊆ U`
of measure greater than `r`;
* `MeasurableSet.measure_eq_iSup_isClosed_of_ne_top` asserts that the measure of a measurable set
of finite measure is the supremum of the measure of closed sets it contains.
* `MeasurableSet.exists_lt_isClosed_of_ne_top` and `MeasurableSet.exists_isClosed_lt_add`:
a measurable set of finite measure can be approximated by a closed subset (stated as
`r < μ F` and `μ s < μ F + ε`, respectively).
* `MeasureTheory.Measure.WeaklyRegular.of_pseudoMetrizableSpace_of_isFiniteMeasure` is an
instance registering that a finite measure on a metric space is weakly regular (in fact, a pseudo
metrizable space is enough);
* `MeasureTheory.Measure.WeaklyRegular.of_pseudoMetrizableSpace_secondCountable_of_locallyFinite`
is an instance registering that a locally finite measure on a second countable metric space (or
even a pseudo metrizable space) is weakly regular.
### Regular measures
* `IsOpen.measure_eq_iSup_isCompact` asserts that the measure of an open set is the supremum of
the measure of compact sets it contains.
* `IsOpen.exists_lt_isCompact`: for an open set `U` and `r < μ U`, there exists a compact `K ⊆ U`
of measure greater than `r`;
* `MeasureTheory.Measure.Regular.of_sigmaCompactSpace_of_isLocallyFiniteMeasure` is an
instance registering that a locally finite measure on a `σ`-compact metric space is regular (in
fact, an emetric space is enough).
### Inner regular measures
* `MeasurableSet.measure_eq_iSup_isCompact` asserts that the measure of a measurable set is the
supremum of the measure of compact sets it contains.
* `MeasurableSet.exists_lt_isCompact`: for a measurable set `s` and `r < μ s`, there exists a
compact `K ⊆ s` of measure greater than `r`;
### Inner regular measures for finite measure sets with respect to compact sets
* `MeasurableSet.measure_eq_iSup_isCompact_of_ne_top` asserts that the measure of a measurable set
of finite measure is the supremum of the measure of compact sets it contains.
* `MeasurableSet.exists_lt_isCompact_of_ne_top` and `MeasurableSet.exists_isCompact_lt_add`:
a measurable set of finite measure can be approximated by a compact subset (stated as
`r < μ K` and `μ s < μ K + ε`, respectively).
## Implementation notes
The main nontrivial statement is `MeasureTheory.Measure.InnerRegular.weaklyRegular_of_finite`,
expressing that in a finite measure space, if every open set can be approximated from inside by
closed sets, then the measure is in fact weakly regular. To prove that we show that any measurable
set can be approximated from inside by closed sets and from outside by open sets. This statement is
proved by measurable induction, starting from open sets and checking that it is stable by taking
complements (this is the point of this condition, being symmetrical between inside and outside) and
countable disjoint unions.
Once this statement is proved, one deduces results for `σ`-finite measures from this statement, by
restricting them to finite measure sets (and proving that this restriction is weakly regular, using
again the same statement).
For non-Hausdorff spaces, one may argue whether the right condition for inner regularity is with
respect to compact sets, or to compact closed sets. For instance,
[Fremlin, *Measure Theory* (volume 4, 411J)][fremlin_vol4] considers measures which are inner
regular with respect to compact closed sets (and calls them *tight*). However, since most of the
literature uses mere compact sets, we have chosen to follow this convention. It doesn't make a
difference in Hausdorff spaces, of course. In locally compact topological groups, the two
conditions coincide, since if a compact set `k` is contained in a measurable set `u`, then the
closure of `k` is a compact closed set still contained in `u`, see
`IsCompact.closure_subset_of_measurableSet_of_group`.
## References
[Halmos, Measure Theory, §52][halmos1950measure]. Note that Halmos uses an unusual definition of
Borel sets (for him, they are elements of the `σ`-algebra generated by compact sets!), so his
proofs or statements do not apply directly.
[Billingsley, Convergence of Probability Measures][billingsley1999]
[Bogachev, Measure Theory, volume 2, Theorem 7.11.1][bogachev2007]
-/
open Set Filter ENNReal NNReal TopologicalSpace
open scoped symmDiff Topology
namespace MeasureTheory
namespace Measure
/-- We say that a measure `μ` is *inner regular* with respect to predicates `p q : Set α → Prop`,
if for every `U` such that `q U` and `r < μ U`, there exists a subset `K ⊆ U` satisfying `p K`
of measure greater than `r`.
This definition is used to prove some facts about regular and weakly regular measures without
repeating the proofs. -/
def InnerRegularWRT {α} {_ : MeasurableSpace α} (μ : Measure α) (p q : Set α → Prop) :=
∀ ⦃U⦄, q U → ∀ r < μ U, ∃ K, K ⊆ U ∧ p K ∧ r < μ K
namespace InnerRegularWRT
variable {α : Type*} {m : MeasurableSpace α} {μ : Measure α} {p q : Set α → Prop} {U : Set α}
{ε : ℝ≥0∞}
theorem measure_eq_iSup (H : InnerRegularWRT μ p q) (hU : q U) :
μ U = ⨆ (K) (_ : K ⊆ U) (_ : p K), μ K := by
refine
le_antisymm (le_of_forall_lt fun r hr => ?_) (iSup₂_le fun K hK => iSup_le fun _ => μ.mono hK)
simpa only [lt_iSup_iff, exists_prop] using H hU r hr
theorem exists_subset_lt_add (H : InnerRegularWRT μ p q) (h0 : p ∅) (hU : q U) (hμU : μ U ≠ ∞)
(hε : ε ≠ 0) : ∃ K, K ⊆ U ∧ p K ∧ μ U < μ K + ε := by
rcases eq_or_ne (μ U) 0 with h₀ | h₀
· refine ⟨∅, empty_subset _, h0, ?_⟩
rwa [measure_empty, h₀, zero_add, pos_iff_ne_zero]
· rcases H hU _ (ENNReal.sub_lt_self hμU h₀ hε) with ⟨K, hKU, hKc, hrK⟩
exact ⟨K, hKU, hKc, ENNReal.lt_add_of_sub_lt_right (Or.inl hμU) hrK⟩
protected theorem map {α β} [MeasurableSpace α] [MeasurableSpace β]
{μ : Measure α} {pa qa : Set α → Prop}
(H : InnerRegularWRT μ pa qa) {f : α → β} (hf : AEMeasurable f μ) {pb qb : Set β → Prop}
(hAB : ∀ U, qb U → qa (f ⁻¹' U)) (hAB' : ∀ K, pa K → pb (f '' K))
(hB₂ : ∀ U, qb U → MeasurableSet U) :
InnerRegularWRT (map f μ) pb qb := by
intro U hU r hr
rw [map_apply_of_aemeasurable hf (hB₂ _ hU)] at hr
rcases H (hAB U hU) r hr with ⟨K, hKU, hKc, hK⟩
refine ⟨f '' K, image_subset_iff.2 hKU, hAB' _ hKc, ?_⟩
exact hK.trans_le (le_map_apply_image hf _)
theorem map' {α β} [MeasurableSpace α] [MeasurableSpace β] {μ : Measure α} {pa qa : Set α → Prop}
(H : InnerRegularWRT μ pa qa) (f : α ≃ᵐ β) {pb qb : Set β → Prop}
(hAB : ∀ U, qb U → qa (f ⁻¹' U)) (hAB' : ∀ K, pa K → pb (f '' K)) :
InnerRegularWRT (map f μ) pb qb := by
intro U hU r hr
rw [f.map_apply U] at hr
rcases H (hAB U hU) r hr with ⟨K, hKU, hKc, hK⟩
refine ⟨f '' K, image_subset_iff.2 hKU, hAB' _ hKc, ?_⟩
rwa [f.map_apply, f.preimage_image]
theorem smul (H : InnerRegularWRT μ p q) (c : ℝ≥0∞) : InnerRegularWRT (c • μ) p q := by
intro U hU r hr
rw [smul_apply, H.measure_eq_iSup hU, smul_eq_mul] at hr
simpa only [ENNReal.mul_iSup, lt_iSup_iff, exists_prop] using hr
theorem trans {q' : Set α → Prop} (H : InnerRegularWRT μ p q) (H' : InnerRegularWRT μ q q') :
InnerRegularWRT μ p q' := by
intro U hU r hr
rcases H' hU r hr with ⟨F, hFU, hqF, hF⟩; rcases H hqF _ hF with ⟨K, hKF, hpK, hrK⟩
exact ⟨K, hKF.trans hFU, hpK, hrK⟩
theorem rfl {p : Set α → Prop} : InnerRegularWRT μ p p :=
fun U hU _r hr ↦ ⟨U, Subset.rfl, hU, hr⟩
theorem of_imp (h : ∀ s, q s → p s) : InnerRegularWRT μ p q :=
fun U hU _ hr ↦ ⟨U, Subset.rfl, h U hU, hr⟩
theorem mono {p' q' : Set α → Prop} (H : InnerRegularWRT μ p q)
(h : ∀ s, q' s → q s) (h' : ∀ s, p s → p' s) : InnerRegularWRT μ p' q' :=
of_imp h' |>.trans H |>.trans (of_imp h)
end InnerRegularWRT
variable {α β : Type*} [MeasurableSpace α] {μ : Measure α}
section Classes
variable [TopologicalSpace α]
/-- A measure `μ` is outer regular if `μ(A) = inf {μ(U) | A ⊆ U open}` for a measurable set `A`.
This definition implies the same equality for any (not necessarily measurable) set, see
`Set.measure_eq_iInf_isOpen`. -/
class OuterRegular (μ : Measure α) : Prop where
protected outerRegular :
∀ ⦃A : Set α⦄, MeasurableSet A → ∀ r > μ A, ∃ U, U ⊇ A ∧ IsOpen U ∧ μ U < r
/-- A measure `μ` is regular if
- it is finite on all compact sets;
- it is outer regular: `μ(A) = inf {μ(U) | A ⊆ U open}` for `A` measurable;
- it is inner regular for open sets, using compact sets:
`μ(U) = sup {μ(K) | K ⊆ U compact}` for `U` open. -/
class Regular (μ : Measure α) : Prop extends IsFiniteMeasureOnCompacts μ, OuterRegular μ where
innerRegular : InnerRegularWRT μ IsCompact IsOpen
/-- A measure `μ` is weakly regular if
- it is outer regular: `μ(A) = inf {μ(U) | A ⊆ U open}` for `A` measurable;
- it is inner regular for open sets, using closed sets:
`μ(U) = sup {μ(F) | F ⊆ U closed}` for `U` open. -/
class WeaklyRegular (μ : Measure α) : Prop extends OuterRegular μ where
protected innerRegular : InnerRegularWRT μ IsClosed IsOpen
/-- A measure `μ` is inner regular if, for any measurable set `s`, then
`μ(s) = sup {μ(K) | K ⊆ s compact}`. -/
class InnerRegular (μ : Measure α) : Prop where
protected innerRegular : InnerRegularWRT μ IsCompact MeasurableSet
/-- A measure `μ` is inner regular for finite measure sets with respect to compact sets:
for any measurable set `s` with finite measure, then `μ(s) = sup {μ(K) | K ⊆ s compact}`.
The main interest of this class is that it is satisfied for both natural Haar measures (the
regular one and the inner regular one). -/
class InnerRegularCompactLTTop (μ : Measure α) : Prop where
protected innerRegular : InnerRegularWRT μ IsCompact (fun s ↦ MeasurableSet s ∧ μ s ≠ ∞)
-- see Note [lower instance priority]
/-- A regular measure is weakly regular in an R₁ space. -/
instance (priority := 100) Regular.weaklyRegular [R1Space α] [Regular μ] :
WeaklyRegular μ where
innerRegular := fun _U hU r hr ↦
let ⟨K, KU, K_comp, hK⟩ := Regular.innerRegular hU r hr
⟨closure K, K_comp.closure_subset_of_isOpen hU KU, isClosed_closure,
hK.trans_le (measure_mono subset_closure)⟩
end Classes
namespace OuterRegular
variable [TopologicalSpace α]
instance zero : OuterRegular (0 : Measure α) :=
⟨fun A _ _r hr => ⟨univ, subset_univ A, isOpen_univ, hr⟩⟩
/-- Given `r` larger than the measure of a set `A`, there exists an open superset of `A` with
measure less than `r`. -/
theorem _root_.Set.exists_isOpen_lt_of_lt [OuterRegular μ] (A : Set α) (r : ℝ≥0∞) (hr : μ A < r) :
∃ U, U ⊇ A ∧ IsOpen U ∧ μ U < r := by
rcases OuterRegular.outerRegular (measurableSet_toMeasurable μ A) r
(by rwa [measure_toMeasurable]) with
⟨U, hAU, hUo, hU⟩
exact ⟨U, (subset_toMeasurable _ _).trans hAU, hUo, hU⟩
/-- For an outer regular measure, the measure of a set is the infimum of the measures of open sets
containing it. -/
theorem _root_.Set.measure_eq_iInf_isOpen (A : Set α) (μ : Measure α) [OuterRegular μ] :
μ A = ⨅ (U : Set α) (_ : A ⊆ U) (_ : IsOpen U), μ U := by
refine le_antisymm (le_iInf₂ fun s hs => le_iInf fun _ => μ.mono hs) ?_
refine le_of_forall_lt' fun r hr => ?_
simpa only [iInf_lt_iff, exists_prop] using A.exists_isOpen_lt_of_lt r hr
theorem _root_.Set.exists_isOpen_lt_add [OuterRegular μ] (A : Set α) (hA : μ A ≠ ∞) {ε : ℝ≥0∞}
(hε : ε ≠ 0) : ∃ U, U ⊇ A ∧ IsOpen U ∧ μ U < μ A + ε :=
A.exists_isOpen_lt_of_lt _ (ENNReal.lt_add_right hA hε)
theorem _root_.Set.exists_isOpen_le_add (A : Set α) (μ : Measure α) [OuterRegular μ] {ε : ℝ≥0∞}
(hε : ε ≠ 0) : ∃ U, U ⊇ A ∧ IsOpen U ∧ μ U ≤ μ A + ε := by
rcases eq_or_ne (μ A) ∞ with (H | H)
· exact ⟨univ, subset_univ _, isOpen_univ, by simp only [H, _root_.top_add, le_top]⟩
· rcases A.exists_isOpen_lt_add H hε with ⟨U, AU, U_open, hU⟩
exact ⟨U, AU, U_open, hU.le⟩
theorem _root_.MeasurableSet.exists_isOpen_diff_lt [OuterRegular μ] {A : Set α}
| (hA : MeasurableSet A) (hA' : μ A ≠ ∞) {ε : ℝ≥0∞} (hε : ε ≠ 0) :
∃ U, U ⊇ A ∧ IsOpen U ∧ μ U < ∞ ∧ μ (U \ A) < ε := by
rcases A.exists_isOpen_lt_add hA' hε with ⟨U, hAU, hUo, hU⟩
use U, hAU, hUo, hU.trans_le le_top
exact measure_diff_lt_of_lt_add hA.nullMeasurableSet hAU hA' hU
| Mathlib/MeasureTheory/Measure/Regular.lean | 361 | 366 |
/-
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.Data.Set.Image
/-!
### Recursion on the natural numbers and `Set.range`
-/
namespace Nat
section Set
open Set
theorem zero_union_range_succ : {0} ∪ range succ = univ := by
ext n
| cases n <;> simp
@[simp]
| Mathlib/Data/Nat/Set.lean | 21 | 23 |
/-
Copyright (c) 2020 Kenny Lau. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kenny Lau, Judith Ludwig, Christian Merten
-/
import Mathlib.Algebra.GeomSum
import Mathlib.LinearAlgebra.SModEq
import Mathlib.RingTheory.Jacobson.Ideal
import Mathlib.RingTheory.Ideal.Quotient.PowTransition
/-!
# Completion of a module with respect to an ideal.
In this file we define the notions of Hausdorff, precomplete, and complete for an `R`-module `M`
with respect to an ideal `I`:
## Main definitions
- `IsHausdorff I M`: this says that the intersection of `I^n M` is `0`.
- `IsPrecomplete I M`: this says that every Cauchy sequence converges.
- `IsAdicComplete I M`: this says that `M` is Hausdorff and precomplete.
- `Hausdorffification I M`: this is the universal Hausdorff module with a map from `M`.
- `AdicCompletion I M`: if `I` is finitely generated, then this is the universal complete module
(TODO) with a map from `M`. This map is injective iff `M` is Hausdorff and surjective iff `M` is
precomplete.
-/
suppress_compilation
open Submodule
variable {R S T : Type*} [CommRing R] (I : Ideal R)
variable (M : Type*) [AddCommGroup M] [Module R M]
variable {N : Type*} [AddCommGroup N] [Module R N]
/-- A module `M` is Hausdorff with respect to an ideal `I` if `⋂ I^n M = 0`. -/
class IsHausdorff : Prop where
haus' : ∀ x : M, (∀ n : ℕ, x ≡ 0 [SMOD (I ^ n • ⊤ : Submodule R M)]) → x = 0
/-- A module `M` is precomplete with respect to an ideal `I` if every Cauchy sequence converges. -/
class IsPrecomplete : Prop where
prec' : ∀ f : ℕ → M, (∀ {m n}, m ≤ n → f m ≡ f n [SMOD (I ^ m • ⊤ : Submodule R M)]) →
∃ L : M, ∀ n, f n ≡ L [SMOD (I ^ n • ⊤ : Submodule R M)]
/-- A module `M` is `I`-adically complete if it is Hausdorff and precomplete. -/
class IsAdicComplete : Prop extends IsHausdorff I M, IsPrecomplete I M
variable {I M}
theorem IsHausdorff.haus (_ : IsHausdorff I M) :
∀ x : M, (∀ n : ℕ, x ≡ 0 [SMOD (I ^ n • ⊤ : Submodule R M)]) → x = 0 :=
IsHausdorff.haus'
theorem isHausdorff_iff :
IsHausdorff I M ↔ ∀ x : M, (∀ n : ℕ, x ≡ 0 [SMOD (I ^ n • ⊤ : Submodule R M)]) → x = 0 :=
⟨IsHausdorff.haus, fun h => ⟨h⟩⟩
theorem IsHausdorff.eq_iff_smodEq [IsHausdorff I M] {x y : M} :
x = y ↔ ∀ n, x ≡ y [SMOD (I ^ n • ⊤ : Submodule R M)] := by
refine ⟨fun h _ ↦ h ▸ rfl, fun h ↦ ?_⟩
rw [← sub_eq_zero]
apply IsHausdorff.haus' (I := I) (x - y)
simpa [SModEq.sub_mem] using h
theorem IsPrecomplete.prec (_ : IsPrecomplete I M) {f : ℕ → M} :
(∀ {m n}, m ≤ n → f m ≡ f n [SMOD (I ^ m • ⊤ : Submodule R M)]) →
∃ L : M, ∀ n, f n ≡ L [SMOD (I ^ n • ⊤ : Submodule R M)] :=
IsPrecomplete.prec' _
theorem isPrecomplete_iff :
IsPrecomplete I M ↔
∀ f : ℕ → M,
(∀ {m n}, m ≤ n → f m ≡ f n [SMOD (I ^ m • ⊤ : Submodule R M)]) →
∃ L : M, ∀ n, f n ≡ L [SMOD (I ^ n • ⊤ : Submodule R M)] :=
⟨fun h => h.1, fun h => ⟨h⟩⟩
variable (I M)
/-- The Hausdorffification of a module with respect to an ideal. -/
abbrev Hausdorffification : Type _ :=
M ⧸ (⨅ n : ℕ, I ^ n • ⊤ : Submodule R M)
/-- The canonical linear map `M ⧸ (I ^ n • ⊤) →ₗ[R] M ⧸ (I ^ m • ⊤)` for `m ≤ n` used
to define `AdicCompletion`. -/
abbrev AdicCompletion.transitionMap {m n : ℕ} (hmn : m ≤ n) := factorPow I M hmn
/-- The completion of a module with respect to an ideal.
This is Hausdorff but not necessarily complete: a classical sufficient condition for
completeness is that `M` be finitely generated [Stacks, 0G1Q]. -/
def AdicCompletion : Type _ :=
{ f : ∀ n : ℕ, M ⧸ (I ^ n • ⊤ : Submodule R M) //
∀ {m n} (hmn : m ≤ n), AdicCompletion.transitionMap I M hmn (f n) = f m }
namespace IsHausdorff
instance bot : IsHausdorff (⊥ : Ideal R) M :=
⟨fun x hx => by simpa only [pow_one ⊥, bot_smul, SModEq.bot] using hx 1⟩
variable {M} in
protected theorem subsingleton (h : IsHausdorff (⊤ : Ideal R) M) : Subsingleton M :=
⟨fun x y => eq_of_sub_eq_zero <| h.haus (x - y) fun n => by
rw [Ideal.top_pow, top_smul]
exact SModEq.top⟩
instance (priority := 100) of_subsingleton [Subsingleton M] : IsHausdorff I M :=
| ⟨fun _ _ => Subsingleton.elim _ _⟩
variable {I M}
| Mathlib/RingTheory/AdicCompletion/Basic.lean | 108 | 111 |
/-
Copyright (c) 2020 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov
-/
import Mathlib.Algebra.Module.Basic
import Mathlib.LinearAlgebra.AffineSpace.AffineEquiv
/-!
# Midpoint of a segment
## Main definitions
* `midpoint R x y`: midpoint of the segment `[x, y]`. We define it for `x` and `y`
in a module over a ring `R` with invertible `2`.
* `AddMonoidHom.ofMapMidpoint`: construct an `AddMonoidHom` given a map `f` such that
`f` sends zero to zero and midpoints to midpoints.
## Main theorems
* `midpoint_eq_iff`: `z` is the midpoint of `[x, y]` if and only if `x + y = z + z`,
* `midpoint_unique`: `midpoint R x y` does not depend on `R`;
* `midpoint x y` is linear both in `x` and `y`;
* `pointReflection_midpoint_left`, `pointReflection_midpoint_right`:
`Equiv.pointReflection (midpoint R x y)` swaps `x` and `y`.
We do not mark most lemmas as `@[simp]` because it is hard to tell which side is simpler.
## Tags
midpoint, AddMonoidHom
-/
open AffineMap AffineEquiv
section
variable (R : Type*) {V V' P P' : Type*} [Ring R] [Invertible (2 : R)] [AddCommGroup V]
[Module R V] [AddTorsor V P] [AddCommGroup V'] [Module R V'] [AddTorsor V' P']
/-- `midpoint x y` is the midpoint of the segment `[x, y]`. -/
def midpoint (x y : P) : P :=
lineMap x y (⅟ 2 : R)
variable {R} {x y z : P}
@[simp]
theorem AffineMap.map_midpoint (f : P →ᵃ[R] P') (a b : P) :
f (midpoint R a b) = midpoint R (f a) (f b) :=
f.apply_lineMap a b _
@[simp]
theorem AffineEquiv.map_midpoint (f : P ≃ᵃ[R] P') (a b : P) :
f (midpoint R a b) = midpoint R (f a) (f b) :=
f.apply_lineMap a b _
theorem AffineEquiv.pointReflection_midpoint_left (x y : P) :
pointReflection R (midpoint R x y) x = y := by
rw [midpoint, pointReflection_apply, lineMap_apply, vadd_vsub, vadd_vadd, ← add_smul, ← two_mul,
mul_invOf_self, one_smul, vsub_vadd]
@[simp]
theorem Equiv.pointReflection_midpoint_left (x y : P) :
(Equiv.pointReflection (midpoint R x y)) x = y := by
rw [midpoint, pointReflection_apply, lineMap_apply, vadd_vsub, vadd_vadd, ← add_smul, ← two_mul,
mul_invOf_self, one_smul, vsub_vadd]
theorem midpoint_comm (x y : P) : midpoint R x y = midpoint R y x := by
rw [midpoint, ← lineMap_apply_one_sub, one_sub_invOf_two, midpoint]
theorem AffineEquiv.pointReflection_midpoint_right (x y : P) :
pointReflection R (midpoint R x y) y = x := by
rw [midpoint_comm, AffineEquiv.pointReflection_midpoint_left]
@[simp]
theorem Equiv.pointReflection_midpoint_right (x y : P) :
(Equiv.pointReflection (midpoint R x y)) y = x := by
rw [midpoint_comm, Equiv.pointReflection_midpoint_left]
theorem midpoint_vsub_midpoint (p₁ p₂ p₃ p₄ : P) :
midpoint R p₁ p₂ -ᵥ midpoint R p₃ p₄ = midpoint R (p₁ -ᵥ p₃) (p₂ -ᵥ p₄) :=
lineMap_vsub_lineMap _ _ _ _ _
theorem midpoint_vadd_midpoint (v v' : V) (p p' : P) :
midpoint R v v' +ᵥ midpoint R p p' = midpoint R (v +ᵥ p) (v' +ᵥ p') :=
lineMap_vadd_lineMap _ _ _ _ _
theorem midpoint_eq_iff {x y z : P} : midpoint R x y = z ↔ pointReflection R z x = y :=
eq_comm.trans
((injective_pointReflection_left_of_module R x).eq_iff'
(AffineEquiv.pointReflection_midpoint_left x y)).symm
@[simp]
theorem midpoint_pointReflection_left (x y : P) :
midpoint R (Equiv.pointReflection x y) y = x :=
midpoint_eq_iff.2 <| Equiv.pointReflection_involutive _ _
@[simp]
theorem midpoint_pointReflection_right (x y : P) :
midpoint R y (Equiv.pointReflection x y) = x :=
midpoint_eq_iff.2 rfl
nonrec lemma AffineEquiv.midpoint_pointReflection_left (x y : P) :
midpoint R (pointReflection R x y) y = x :=
midpoint_pointReflection_left x y
nonrec lemma AffineEquiv.midpoint_pointReflection_right (x y : P) :
midpoint R y (pointReflection R x y) = x :=
midpoint_pointReflection_right x y
@[simp]
theorem midpoint_vsub_left (p₁ p₂ : P) : midpoint R p₁ p₂ -ᵥ p₁ = (⅟ 2 : R) • (p₂ -ᵥ p₁) :=
lineMap_vsub_left _ _ _
@[simp]
theorem midpoint_vsub_right (p₁ p₂ : P) : midpoint R p₁ p₂ -ᵥ p₂ = (⅟ 2 : R) • (p₁ -ᵥ p₂) := by
rw [midpoint_comm, midpoint_vsub_left]
@[simp]
theorem left_vsub_midpoint (p₁ p₂ : P) : p₁ -ᵥ midpoint R p₁ p₂ = (⅟ 2 : R) • (p₁ -ᵥ p₂) :=
left_vsub_lineMap _ _ _
@[simp]
theorem right_vsub_midpoint (p₁ p₂ : P) : p₂ -ᵥ midpoint R p₁ p₂ = (⅟ 2 : R) • (p₂ -ᵥ p₁) := by
rw [midpoint_comm, left_vsub_midpoint]
theorem midpoint_vsub (p₁ p₂ p : P) :
midpoint R p₁ p₂ -ᵥ p = (⅟ 2 : R) • (p₁ -ᵥ p) + (⅟ 2 : R) • (p₂ -ᵥ p) := by
rw [← vsub_sub_vsub_cancel_right p₁ p p₂, smul_sub, sub_eq_add_neg, ← smul_neg,
neg_vsub_eq_vsub_rev, add_assoc, invOf_two_smul_add_invOf_two_smul, ← vadd_vsub_assoc,
midpoint_comm, midpoint, lineMap_apply]
theorem vsub_midpoint (p₁ p₂ p : P) :
p -ᵥ midpoint R p₁ p₂ = (⅟ 2 : R) • (p -ᵥ p₁) + (⅟ 2 : R) • (p -ᵥ p₂) := by
rw [← neg_vsub_eq_vsub_rev, midpoint_vsub, neg_add, ← smul_neg, ← smul_neg, neg_vsub_eq_vsub_rev,
neg_vsub_eq_vsub_rev]
@[simp]
theorem midpoint_sub_left (v₁ v₂ : V) : midpoint R v₁ v₂ - v₁ = (⅟ 2 : R) • (v₂ - v₁) :=
midpoint_vsub_left v₁ v₂
@[simp]
theorem midpoint_sub_right (v₁ v₂ : V) : midpoint R v₁ v₂ - v₂ = (⅟ 2 : R) • (v₁ - v₂) :=
midpoint_vsub_right v₁ v₂
@[simp]
theorem left_sub_midpoint (v₁ v₂ : V) : v₁ - midpoint R v₁ v₂ = (⅟ 2 : R) • (v₁ - v₂) :=
left_vsub_midpoint v₁ v₂
@[simp]
theorem right_sub_midpoint (v₁ v₂ : V) : v₂ - midpoint R v₁ v₂ = (⅟ 2 : R) • (v₂ - v₁) :=
right_vsub_midpoint v₁ v₂
variable (R)
@[simp]
theorem midpoint_eq_left_iff {x y : P} : midpoint R x y = x ↔ x = y := by
rw [midpoint_eq_iff, pointReflection_self]
@[simp]
theorem left_eq_midpoint_iff {x y : P} : x = midpoint R x y ↔ x = y := by
rw [eq_comm, midpoint_eq_left_iff]
@[simp]
theorem midpoint_eq_right_iff {x y : P} : midpoint R x y = y ↔ x = y := by
rw [midpoint_comm, midpoint_eq_left_iff, eq_comm]
@[simp]
theorem right_eq_midpoint_iff {x y : P} : y = midpoint R x y ↔ x = y := by
rw [eq_comm, midpoint_eq_right_iff]
theorem midpoint_eq_midpoint_iff_vsub_eq_vsub {x x' y y' : P} :
midpoint R x y = midpoint R x' y' ↔ x -ᵥ x' = y' -ᵥ y := by
rw [← @vsub_eq_zero_iff_eq V, midpoint_vsub_midpoint, midpoint_eq_iff, pointReflection_apply,
vsub_eq_sub, zero_sub, vadd_eq_add, add_zero, neg_eq_iff_eq_neg, neg_vsub_eq_vsub_rev]
theorem midpoint_eq_iff' {x y z : P} : midpoint R x y = z ↔ Equiv.pointReflection z x = y :=
midpoint_eq_iff
/-- `midpoint` does not depend on the ring `R`. -/
theorem midpoint_unique (R' : Type*) [Ring R'] [Invertible (2 : R')] [Module R' V] (x y : P) :
midpoint R x y = midpoint R' x y :=
(midpoint_eq_iff' R).2 <| (midpoint_eq_iff' R').1 rfl
@[simp]
theorem midpoint_self (x : P) : midpoint R x x = x :=
lineMap_same_apply _ _
@[simp]
theorem midpoint_add_self (x y : V) : midpoint R x y + midpoint R x y = x + y :=
calc
midpoint R x y +ᵥ midpoint R x y = midpoint R x y +ᵥ midpoint R y x := by rw [midpoint_comm]
_ = x + y := by rw [midpoint_vadd_midpoint, vadd_eq_add, vadd_eq_add, add_comm, midpoint_self]
theorem midpoint_zero_add (x y : V) : midpoint R 0 (x + y) = midpoint R x y :=
(midpoint_eq_midpoint_iff_vsub_eq_vsub R).2 <| by simp [sub_add_eq_sub_sub_swap]
theorem midpoint_eq_smul_add (x y : V) : midpoint R x y = (⅟ 2 : R) • (x + y) := by
rw [midpoint_eq_iff, pointReflection_apply, vsub_eq_sub, vadd_eq_add, sub_add_eq_add_sub, ←
two_smul R, smul_smul, mul_invOf_self, one_smul, add_sub_cancel_left]
@[simp]
theorem midpoint_self_neg (x : V) : midpoint R x (-x) = 0 := by
rw [midpoint_eq_smul_add, add_neg_cancel, smul_zero]
@[simp]
theorem midpoint_neg_self (x : V) : midpoint R (-x) x = 0 := by simpa using midpoint_self_neg R (-x)
@[simp]
theorem midpoint_sub_add (x y : V) : midpoint R (x - y) (x + y) = x := by
rw [sub_eq_add_neg, ← vadd_eq_add, ← vadd_eq_add, ← midpoint_vadd_midpoint]; simp
@[simp]
theorem midpoint_add_sub (x y : V) : midpoint R (x + y) (x - y) = x := by
rw [midpoint_comm]; simp
end
namespace AddMonoidHom
|
variable (R R' : Type*) {E F : Type*} [Ring R] [Invertible (2 : R)] [AddCommGroup E] [Module R E]
[Ring R'] [Invertible (2 : R')] [AddCommGroup F] [Module R' F]
| Mathlib/LinearAlgebra/AffineSpace/Midpoint.lean | 220 | 222 |
/-
Copyright (c) 2016 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.Set.Defs
import Mathlib.Logic.Basic
import Mathlib.Logic.ExistsUnique
import Mathlib.Logic.Nonempty
import Mathlib.Logic.Nontrivial.Defs
import Batteries.Tactic.Init
import Mathlib.Order.Defs.Unbundled
/-!
# Miscellaneous function constructions and lemmas
-/
open Function
universe u v w
namespace Function
section
variable {α β γ : Sort*} {f : α → β}
/-- Evaluate a function at an argument. Useful if you want to talk about the partially applied
`Function.eval x : (∀ x, β x) → β x`. -/
@[reducible, simp] def eval {β : α → Sort*} (x : α) (f : ∀ x, β x) : β x := f x
theorem eval_apply {β : α → Sort*} (x : α) (f : ∀ x, β x) : eval x f = f x :=
rfl
theorem const_def {y : β} : (fun _ : α ↦ y) = const α y :=
rfl
theorem const_injective [Nonempty α] : Injective (const α : β → α → β) := fun _ _ h ↦
let ⟨x⟩ := ‹Nonempty α›
congr_fun h x
@[simp]
theorem const_inj [Nonempty α] {y₁ y₂ : β} : const α y₁ = const α y₂ ↔ y₁ = y₂ :=
⟨fun h ↦ const_injective h, fun h ↦ h ▸ rfl⟩
theorem onFun_apply (f : β → β → γ) (g : α → β) (a b : α) : onFun f g a b = f (g a) (g b) :=
rfl
lemma hfunext {α α' : Sort u} {β : α → Sort v} {β' : α' → Sort v} {f : ∀a, β a} {f' : ∀a, β' a}
(hα : α = α') (h : ∀a a', HEq a a' → HEq (f a) (f' a')) : HEq f f' := by
subst hα
have : ∀a, HEq (f a) (f' a) := fun a ↦ h a a (HEq.refl a)
have : β = β' := by funext a; exact type_eq_of_heq (this a)
subst this
apply heq_of_eq
funext a
exact eq_of_heq (this a)
theorem ne_iff {β : α → Sort*} {f₁ f₂ : ∀ a, β a} : f₁ ≠ f₂ ↔ ∃ a, f₁ a ≠ f₂ a :=
funext_iff.not.trans not_forall
lemma funext_iff_of_subsingleton [Subsingleton α] {g : α → β} (x y : α) :
f x = g y ↔ f = g := by
refine ⟨fun h ↦ funext fun z ↦ ?_, fun h ↦ ?_⟩
· rwa [Subsingleton.elim x z, Subsingleton.elim y z] at h
· rw [h, Subsingleton.elim x y]
theorem swap_lt {α} [LT α] : swap (· < · : α → α → _) = (· > ·) := rfl
theorem swap_le {α} [LE α] : swap (· ≤ · : α → α → _) = (· ≥ ·) := rfl
theorem swap_gt {α} [LT α] : swap (· > · : α → α → _) = (· < ·) := rfl
theorem swap_ge {α} [LE α] : swap (· ≥ · : α → α → _) = (· ≤ ·) := rfl
protected theorem Bijective.injective {f : α → β} (hf : Bijective f) : Injective f := hf.1
protected theorem Bijective.surjective {f : α → β} (hf : Bijective f) : Surjective f := hf.2
theorem not_injective_iff : ¬ Injective f ↔ ∃ a b, f a = f b ∧ a ≠ b := by
simp only [Injective, not_forall, exists_prop]
/-- If the co-domain `β` of an injective function `f : α → β` has decidable equality, then
the domain `α` also has decidable equality. -/
protected def Injective.decidableEq [DecidableEq β] (I : Injective f) : DecidableEq α :=
fun _ _ ↦ decidable_of_iff _ I.eq_iff
theorem Injective.of_comp {g : γ → α} (I : Injective (f ∘ g)) : Injective g :=
fun _ _ h ↦ I <| congr_arg f h
@[simp]
theorem Injective.of_comp_iff (hf : Injective f) (g : γ → α) :
Injective (f ∘ g) ↔ Injective g :=
⟨Injective.of_comp, hf.comp⟩
theorem Injective.of_comp_right {g : γ → α} (I : Injective (f ∘ g)) (hg : Surjective g) :
Injective f := fun x y h ↦ by
obtain ⟨x, rfl⟩ := hg x
obtain ⟨y, rfl⟩ := hg y
exact congr_arg g (I h)
theorem Surjective.bijective₂_of_injective {g : γ → α} (hf : Surjective f) (hg : Surjective g)
(I : Injective (f ∘ g)) : Bijective f ∧ Bijective g :=
⟨⟨I.of_comp_right hg, hf⟩, I.of_comp, hg⟩
@[simp]
theorem Injective.of_comp_iff' (f : α → β) {g : γ → α} (hg : Bijective g) :
Injective (f ∘ g) ↔ Injective f :=
⟨fun I ↦ I.of_comp_right hg.2, fun h ↦ h.comp hg.injective⟩
theorem Injective.piMap {ι : Sort*} {α β : ι → Sort*} {f : ∀ i, α i → β i}
(hf : ∀ i, Injective (f i)) : Injective (Pi.map f) := fun _ _ h ↦
funext fun i ↦ hf i <| congrFun h _
/-- Composition by an injective function on the left is itself injective. -/
theorem Injective.comp_left {g : β → γ} (hg : Injective g) : Injective (g ∘ · : (α → β) → α → γ) :=
.piMap fun _ ↦ hg
theorem injective_comp_left_iff [Nonempty α] {g : β → γ} :
Injective (g ∘ · : (α → β) → α → γ) ↔ Injective g :=
⟨fun h b₁ b₂ eq ↦ Nonempty.elim ‹_›
(congr_fun <| h (a₁ := fun _ ↦ b₁) (a₂ := fun _ ↦ b₂) <| funext fun _ ↦ eq), (·.comp_left)⟩
@[nontriviality] theorem injective_of_subsingleton [Subsingleton α] (f : α → β) : Injective f :=
fun _ _ _ ↦ Subsingleton.elim _ _
@[nontriviality] theorem bijective_of_subsingleton [Subsingleton α] (f : α → α) : Bijective f :=
⟨injective_of_subsingleton f, fun a ↦ ⟨a, Subsingleton.elim ..⟩⟩
lemma Injective.dite (p : α → Prop) [DecidablePred p]
{f : {a : α // p a} → β} {f' : {a : α // ¬ p a} → β}
| (hf : Injective f) (hf' : Injective f')
(im_disj : ∀ {x x' : α} {hx : p x} {hx' : ¬ p x'}, f ⟨x, hx⟩ ≠ f' ⟨x', hx'⟩) :
Function.Injective (fun x ↦ if h : p x then f ⟨x, h⟩ else f' ⟨x, h⟩) := fun x₁ x₂ h => by
dsimp only at h
by_cases h₁ : p x₁ <;> by_cases h₂ : p x₂
| Mathlib/Logic/Function/Basic.lean | 128 | 132 |
/-
Copyright (c) 2021 Patrick Massot. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Massot
-/
import Mathlib.Topology.Algebra.Module.Basic
/-!
# Group and ring filter bases
A `GroupFilterBasis` is a `FilterBasis` on a group with some properties relating
the basis to the group structure. The main theorem is that a `GroupFilterBasis`
on a group gives a topology on the group which makes it into a topological group
with neighborhoods of the neutral element generated by the given basis.
## Main definitions and results
Given a group `G` and a ring `R`:
* `GroupFilterBasis G`: the type of filter bases that will become neighborhood of `1`
for a topology on `G` compatible with the group structure
* `GroupFilterBasis.topology`: the associated topology
* `GroupFilterBasis.isTopologicalGroup`: the compatibility between the above topology
and the group structure
* `RingFilterBasis R`: the type of filter bases that will become neighborhood of `0`
for a topology on `R` compatible with the ring structure
* `RingFilterBasis.topology`: the associated topology
* `RingFilterBasis.isTopologicalRing`: the compatibility between the above topology
and the ring structure
## References
* [N. Bourbaki, *General Topology*][bourbaki1966]
-/
open Filter Set TopologicalSpace Function
open Topology Filter Pointwise
universe u
/-- A `GroupFilterBasis` on a group is a `FilterBasis` satisfying some additional axioms.
Example : if `G` is a topological group then the neighbourhoods of the identity are a
`GroupFilterBasis`. Conversely given a `GroupFilterBasis` one can define a topology
compatible with the group structure on `G`. -/
class GroupFilterBasis (G : Type u) [Group G] extends FilterBasis G where
one' : ∀ {U}, U ∈ sets → (1 : G) ∈ U
mul' : ∀ {U}, U ∈ sets → ∃ V ∈ sets, V * V ⊆ U
inv' : ∀ {U}, U ∈ sets → ∃ V ∈ sets, V ⊆ (fun x ↦ x⁻¹) ⁻¹' U
conj' : ∀ x₀, ∀ {U}, U ∈ sets → ∃ V ∈ sets, V ⊆ (fun x ↦ x₀ * x * x₀⁻¹) ⁻¹' U
/-- An `AddGroupFilterBasis` on an additive group is a `FilterBasis` satisfying some additional
axioms. Example : if `G` is a topological group then the neighbourhoods of the identity are an
`AddGroupFilterBasis`. Conversely given an `AddGroupFilterBasis` one can define a topology
compatible with the group structure on `G`. -/
class AddGroupFilterBasis (A : Type u) [AddGroup A] extends FilterBasis A where
zero' : ∀ {U}, U ∈ sets → (0 : A) ∈ U
add' : ∀ {U}, U ∈ sets → ∃ V ∈ sets, V + V ⊆ U
neg' : ∀ {U}, U ∈ sets → ∃ V ∈ sets, V ⊆ (fun x ↦ -x) ⁻¹' U
conj' : ∀ x₀, ∀ {U}, U ∈ sets → ∃ V ∈ sets, V ⊆ (fun x ↦ x₀ + x + -x₀) ⁻¹' U
attribute [to_additive existing] GroupFilterBasis GroupFilterBasis.conj'
GroupFilterBasis.toFilterBasis
/-- `GroupFilterBasis` constructor in the commutative group case. -/
@[to_additive "`AddGroupFilterBasis` constructor in the additive commutative group case."]
def groupFilterBasisOfComm {G : Type*} [CommGroup G] (sets : Set (Set G))
(nonempty : sets.Nonempty) (inter_sets : ∀ x y, x ∈ sets → y ∈ sets → ∃ z ∈ sets, z ⊆ x ∩ y)
(one : ∀ U ∈ sets, (1 : G) ∈ U) (mul : ∀ U ∈ sets, ∃ V ∈ sets, V * V ⊆ U)
(inv : ∀ U ∈ sets, ∃ V ∈ sets, V ⊆ (fun x ↦ x⁻¹) ⁻¹' U) : GroupFilterBasis G :=
{ sets := sets
nonempty := nonempty
inter_sets := inter_sets _ _
one' := one _
mul' := mul _
inv' := inv _
conj' := fun x U U_in ↦ ⟨U, U_in, by simp only [mul_inv_cancel_comm, preimage_id']; rfl⟩ }
namespace GroupFilterBasis
variable {G : Type u} [Group G] {B : GroupFilterBasis G}
@[to_additive]
instance : Membership (Set G) (GroupFilterBasis G) :=
⟨fun f s ↦ s ∈ f.sets⟩
@[to_additive]
theorem one {U : Set G} : U ∈ B → (1 : G) ∈ U :=
GroupFilterBasis.one'
@[to_additive]
theorem mul {U : Set G} : U ∈ B → ∃ V ∈ B, V * V ⊆ U :=
GroupFilterBasis.mul'
@[to_additive]
theorem inv {U : Set G} : U ∈ B → ∃ V ∈ B, V ⊆ (fun x ↦ x⁻¹) ⁻¹' U :=
GroupFilterBasis.inv'
@[to_additive]
theorem conj : ∀ x₀, ∀ {U}, U ∈ B → ∃ V ∈ B, V ⊆ (fun x ↦ x₀ * x * x₀⁻¹) ⁻¹' U :=
GroupFilterBasis.conj'
/-- The trivial group filter basis consists of `{1}` only. The associated topology
is discrete. -/
@[to_additive "The trivial additive group filter basis consists of `{0}` only. The associated
topology is discrete."]
instance : Inhabited (GroupFilterBasis G) where
default := {
sets := {{1}}
nonempty := singleton_nonempty _
inter_sets := by simp
one' := by simp
mul' := by simp
inv' := by simp
conj' := by simp }
@[to_additive]
theorem subset_mul_self (B : GroupFilterBasis G) {U : Set G} (h : U ∈ B) : U ⊆ U * U :=
fun x x_in ↦ ⟨1, one h, x, x_in, one_mul x⟩
/-- The neighborhood function of a `GroupFilterBasis`. -/
@[to_additive "The neighborhood function of an `AddGroupFilterBasis`."]
def N (B : GroupFilterBasis G) : G → Filter G :=
fun x ↦ map (fun y ↦ x * y) B.toFilterBasis.filter
@[to_additive (attr := simp)]
theorem N_one (B : GroupFilterBasis G) : B.N 1 = B.toFilterBasis.filter := by
simp only [N, one_mul, map_id']
@[to_additive]
protected theorem hasBasis (B : GroupFilterBasis G) (x : G) :
HasBasis (B.N x) (fun V : Set G ↦ V ∈ B) fun V ↦ (fun y ↦ x * y) '' V :=
HasBasis.map (fun y ↦ x * y) toFilterBasis.hasBasis
/-- The topological space structure coming from a group filter basis. -/
@[to_additive "The topological space structure coming from an additive group filter basis."]
def topology (B : GroupFilterBasis G) : TopologicalSpace G :=
TopologicalSpace.mkOfNhds B.N
@[to_additive]
theorem nhds_eq (B : GroupFilterBasis G) {x₀ : G} : @nhds G B.topology x₀ = B.N x₀ := by
apply TopologicalSpace.nhds_mkOfNhds_of_hasBasis (fun x ↦ (FilterBasis.hasBasis _).map _)
· intro a U U_in
exact ⟨1, B.one U_in, mul_one a⟩
· intro a U U_in
rcases GroupFilterBasis.mul U_in with ⟨V, V_in, hVU⟩
filter_upwards [image_mem_map (B.mem_filter_of_mem V_in)]
rintro _ ⟨x, hx, rfl⟩
calc
(a * x) • V ∈ (a * x) • B.filter := smul_set_mem_smul_filter <| B.mem_filter_of_mem V_in
_ = a • x • V := smul_smul .. |>.symm
_ ⊆ a • (V * V) := smul_set_mono <| smul_set_subset_smul hx
_ ⊆ a • U := smul_set_mono hVU
@[to_additive]
theorem nhds_one_eq (B : GroupFilterBasis G) :
@nhds G B.topology (1 : G) = B.toFilterBasis.filter := by
rw [B.nhds_eq]
simp only [N, one_mul]
exact map_id
@[to_additive]
theorem nhds_hasBasis (B : GroupFilterBasis G) (x₀ : G) :
HasBasis (@nhds G B.topology x₀) (fun V : Set G ↦ V ∈ B) fun V ↦ (fun y ↦ x₀ * y) '' V := by
rw [B.nhds_eq]
apply B.hasBasis
@[to_additive]
theorem nhds_one_hasBasis (B : GroupFilterBasis G) :
HasBasis (@nhds G B.topology 1) (fun V : Set G ↦ V ∈ B) id := by
rw [B.nhds_one_eq]
exact B.toFilterBasis.hasBasis
@[to_additive]
theorem mem_nhds_one (B : GroupFilterBasis G) {U : Set G} (hU : U ∈ B) :
U ∈ @nhds G B.topology 1 := by
rw [B.nhds_one_hasBasis.mem_iff]
exact ⟨U, hU, rfl.subset⟩
-- See note [lower instance priority]
/-- If a group is endowed with a topological structure coming from a group filter basis then it's a
topological group. -/
@[to_additive "If a group is endowed with a topological structure coming from a group filter basis
then it's a topological group."]
instance (priority := 100) isTopologicalGroup (B : GroupFilterBasis G) :
@IsTopologicalGroup G B.topology _ := by
letI := B.topology
have basis := B.nhds_one_hasBasis
have basis' := basis.prod basis
refine IsTopologicalGroup.of_nhds_one ?_ ?_ ?_ ?_
· rw [basis'.tendsto_iff basis]
suffices ∀ U ∈ B, ∃ V W, (V ∈ B ∧ W ∈ B) ∧ ∀ a b, a ∈ V → b ∈ W → a * b ∈ U by simpa
intro U U_in
rcases mul U_in with ⟨V, V_in, hV⟩
refine ⟨V, V, ⟨V_in, V_in⟩, ?_⟩
intro a b a_in b_in
exact hV <| mul_mem_mul a_in b_in
· rw [basis.tendsto_iff basis]
intro U U_in
simpa using inv U_in
· intro x₀
rw [nhds_eq, nhds_one_eq]
rfl
| · intro x₀
rw [basis.tendsto_iff basis]
intro U U_in
exact conj x₀ U_in
| Mathlib/Topology/Algebra/FilterBasis.lean | 205 | 208 |
/-
Copyright (c) 2021 Anatole Dedecker. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Anatole Dedecker, Bhavik Mehta
-/
import Mathlib.Analysis.Calculus.Deriv.Support
import Mathlib.Analysis.SpecialFunctions.Pow.Deriv
import Mathlib.MeasureTheory.Function.Jacobian
import Mathlib.MeasureTheory.Integral.IntervalIntegral.IntegrationByParts
import Mathlib.MeasureTheory.Measure.Haar.NormedSpace
import Mathlib.MeasureTheory.Measure.Haar.Unique
/-!
# Links between an integral and its "improper" version
In its current state, mathlib only knows how to talk about definite ("proper") integrals,
in the sense that it treats integrals over `[x, +∞)` the same as it treats integrals over
`[y, z]`. For example, the integral over `[1, +∞)` is **not** defined to be the limit of
the integral over `[1, x]` as `x` tends to `+∞`, which is known as an **improper integral**.
Indeed, the "proper" definition is stronger than the "improper" one. The usual counterexample
is `x ↦ sin(x)/x`, which has an improper integral over `[1, +∞)` but no definite integral.
Although definite integrals have better properties, they are hardly usable when it comes to
computing integrals on unbounded sets, which is much easier using limits. Thus, in this file,
we prove various ways of studying the proper integral by studying the improper one.
## Definitions
The main definition of this file is `MeasureTheory.AECover`. It is a rather technical definition
whose sole purpose is generalizing and factoring proofs. Given an index type `ι`, a countably
generated filter `l` over `ι`, and an `ι`-indexed family `φ` of subsets of a measurable space `α`
equipped with a measure `μ`, one should think of a hypothesis `hφ : MeasureTheory.AECover μ l φ` as
a sufficient condition for being able to interpret `∫ x, f x ∂μ` (if it exists) as the limit of `∫ x
in φ i, f x ∂μ` as `i` tends to `l`.
When using this definition with a measure restricted to a set `s`, which happens fairly often, one
should not try too hard to use a `MeasureTheory.AECover` of subsets of `s`, as it often makes proofs
more complicated than necessary. See for example the proof of
`MeasureTheory.integrableOn_Iic_of_intervalIntegral_norm_tendsto` where we use `(fun x ↦ oi x)` as a
`MeasureTheory.AECover` w.r.t. `μ.restrict (Iic b)`, instead of using `(fun x ↦ Ioc x b)`.
## Main statements
- `MeasureTheory.AECover.lintegral_tendsto_of_countably_generated` : if `φ` is a
`MeasureTheory.AECover μ l`, where `l` is a countably generated filter, and if `f` is a measurable
`ENNReal`-valued function, then `∫⁻ x in φ n, f x ∂μ` tends to `∫⁻ x, f x ∂μ` as `n` tends to `l`
- `MeasureTheory.AECover.integrable_of_integral_norm_tendsto` : if `φ` is a
`MeasureTheory.AECover μ l`, where `l` is a countably generated filter, if `f` is measurable and
integrable on each `φ n`, and if `∫ x in φ n, ‖f x‖ ∂μ` tends to some `I : ℝ` as n tends to `l`,
then `f` is integrable
- `MeasureTheory.AECover.integral_tendsto_of_countably_generated` : if `φ` is a
`MeasureTheory.AECover μ l`, where `l` is a countably generated filter, and if `f` is measurable
and integrable (globally), then `∫ x in φ n, f x ∂μ` tends to `∫ x, f x ∂μ` as `n` tends to `+∞`.
We then specialize these lemmas to various use cases involving intervals, which are frequent
in analysis. In particular,
- `MeasureTheory.integral_Ioi_of_hasDerivAt_of_tendsto` is a version of FTC-2 on the interval
`(a, +∞)`, giving the formula `∫ x in (a, +∞), g' x = l - g a` if `g'` is integrable and
`g` tends to `l` at `+∞`.
- `MeasureTheory.integral_Ioi_of_hasDerivAt_of_nonneg` gives the same result assuming that
`g'` is nonnegative instead of integrable. Its automatic integrability in this context is proved
in `MeasureTheory.integrableOn_Ioi_deriv_of_nonneg`.
- `MeasureTheory.integral_comp_smul_deriv_Ioi` is a version of the change of variables formula
on semi-infinite intervals.
- `MeasureTheory.tendsto_limUnder_of_hasDerivAt_of_integrableOn_Ioi` shows that a function whose
derivative is integrable on `(a, +∞)` has a limit at `+∞`.
- `MeasureTheory.tendsto_zero_of_hasDerivAt_of_integrableOn_Ioi` shows that an integrable function
whose derivative is integrable on `(a, +∞)` tends to `0` at `+∞`.
Versions of these results are also given on the intervals `(-∞, a]` and `(-∞, +∞)`, as well as
the corresponding versions of integration by parts.
-/
open MeasureTheory Filter Set TopologicalSpace Topology
open scoped ENNReal NNReal
namespace MeasureTheory
section AECover
variable {α ι : Type*} [MeasurableSpace α] (μ : Measure α) (l : Filter ι)
/-- A sequence `φ` of subsets of `α` is a `MeasureTheory.AECover` w.r.t. a measure `μ` and a filter
`l` if almost every point (w.r.t. `μ`) of `α` eventually belongs to `φ n` (w.r.t. `l`), and if
each `φ n` is measurable. This definition is a technical way to avoid duplicating a lot of
proofs. It should be thought of as a sufficient condition for being able to interpret
`∫ x, f x ∂μ` (if it exists) as the limit of `∫ x in φ n, f x ∂μ` as `n` tends to `l`.
See for example `MeasureTheory.AECover.lintegral_tendsto_of_countably_generated`,
`MeasureTheory.AECover.integrable_of_integral_norm_tendsto` and
`MeasureTheory.AECover.integral_tendsto_of_countably_generated`. -/
structure AECover (φ : ι → Set α) : Prop where
ae_eventually_mem : ∀ᵐ x ∂μ, ∀ᶠ i in l, x ∈ φ i
protected measurableSet : ∀ i, MeasurableSet <| φ i
variable {μ} {l}
namespace AECover
/-!
## Operations on `AECover`s
-/
/-- Elementwise intersection of two `AECover`s is an `AECover`. -/
theorem inter {φ ψ : ι → Set α} (hφ : AECover μ l φ) (hψ : AECover μ l ψ) :
AECover μ l (fun i ↦ φ i ∩ ψ i) where
ae_eventually_mem := hψ.1.mp <| hφ.1.mono fun _ ↦ Eventually.and
measurableSet _ := (hφ.2 _).inter (hψ.2 _)
theorem superset {φ ψ : ι → Set α} (hφ : AECover μ l φ) (hsub : ∀ i, φ i ⊆ ψ i)
(hmeas : ∀ i, MeasurableSet (ψ i)) : AECover μ l ψ :=
⟨hφ.1.mono fun _x hx ↦ hx.mono fun i hi ↦ hsub i hi, hmeas⟩
theorem mono_ac {ν : Measure α} {φ : ι → Set α} (hφ : AECover μ l φ) (hle : ν ≪ μ) :
AECover ν l φ := ⟨hle hφ.1, hφ.2⟩
theorem mono {ν : Measure α} {φ : ι → Set α} (hφ : AECover μ l φ) (hle : ν ≤ μ) :
AECover ν l φ := hφ.mono_ac hle.absolutelyContinuous
end AECover
section MetricSpace
variable [PseudoMetricSpace α] [OpensMeasurableSpace α]
theorem aecover_ball {x : α} {r : ι → ℝ} (hr : Tendsto r l atTop) :
AECover μ l (fun i ↦ Metric.ball x (r i)) where
measurableSet _ := Metric.isOpen_ball.measurableSet
ae_eventually_mem := by
filter_upwards with y
filter_upwards [hr (Ioi_mem_atTop (dist x y))] with a ha using by simpa [dist_comm] using ha
theorem aecover_closedBall {x : α} {r : ι → ℝ} (hr : Tendsto r l atTop) :
AECover μ l (fun i ↦ Metric.closedBall x (r i)) where
measurableSet _ := Metric.isClosed_closedBall.measurableSet
ae_eventually_mem := by
filter_upwards with y
filter_upwards [hr (Ici_mem_atTop (dist x y))] with a ha using by simpa [dist_comm] using ha
end MetricSpace
section Preorderα
variable [Preorder α] [TopologicalSpace α] [OrderClosedTopology α] [OpensMeasurableSpace α]
{a b : ι → α}
theorem aecover_Ici (ha : Tendsto a l atBot) : AECover μ l fun i => Ici (a i) where
ae_eventually_mem := ae_of_all μ ha.eventually_le_atBot
measurableSet _ := measurableSet_Ici
theorem aecover_Iic (hb : Tendsto b l atTop) : AECover μ l fun i => Iic <| b i :=
aecover_Ici (α := αᵒᵈ) hb
theorem aecover_Icc (ha : Tendsto a l atBot) (hb : Tendsto b l atTop) :
AECover μ l fun i => Icc (a i) (b i) :=
(aecover_Ici ha).inter (aecover_Iic hb)
end Preorderα
section LinearOrderα
variable [LinearOrder α] [TopologicalSpace α] [OrderClosedTopology α] [OpensMeasurableSpace α]
{a b : ι → α} (ha : Tendsto a l atBot) (hb : Tendsto b l atTop)
include ha in
theorem aecover_Ioi [NoMinOrder α] : AECover μ l fun i => Ioi (a i) where
ae_eventually_mem := ae_of_all μ ha.eventually_lt_atBot
measurableSet _ := measurableSet_Ioi
include hb in
theorem aecover_Iio [NoMaxOrder α] : AECover μ l fun i => Iio (b i) := aecover_Ioi (α := αᵒᵈ) hb
include ha hb
theorem aecover_Ioo [NoMinOrder α] [NoMaxOrder α] : AECover μ l fun i => Ioo (a i) (b i) :=
(aecover_Ioi ha).inter (aecover_Iio hb)
theorem aecover_Ioc [NoMinOrder α] : AECover μ l fun i => Ioc (a i) (b i) :=
(aecover_Ioi ha).inter (aecover_Iic hb)
theorem aecover_Ico [NoMaxOrder α] : AECover μ l fun i => Ico (a i) (b i) :=
(aecover_Ici ha).inter (aecover_Iio hb)
end LinearOrderα
section FiniteIntervals
variable [LinearOrder α] [TopologicalSpace α] [OrderClosedTopology α] [OpensMeasurableSpace α]
{a b : ι → α} {A B : α} (ha : Tendsto a l (𝓝 A)) (hb : Tendsto b l (𝓝 B))
include ha in
theorem aecover_Ioi_of_Ioi : AECover (μ.restrict (Ioi A)) l fun i ↦ Ioi (a i) where
ae_eventually_mem := (ae_restrict_mem measurableSet_Ioi).mono fun _x hx ↦ ha.eventually <|
eventually_lt_nhds hx
measurableSet _ := measurableSet_Ioi
include hb in
theorem aecover_Iio_of_Iio : AECover (μ.restrict (Iio B)) l fun i ↦ Iio (b i) :=
aecover_Ioi_of_Ioi (α := αᵒᵈ) hb
include ha in
theorem aecover_Ioi_of_Ici : AECover (μ.restrict (Ioi A)) l fun i ↦ Ici (a i) :=
(aecover_Ioi_of_Ioi ha).superset (fun _ ↦ Ioi_subset_Ici_self) fun _ ↦ measurableSet_Ici
include hb in
theorem aecover_Iio_of_Iic : AECover (μ.restrict (Iio B)) l fun i ↦ Iic (b i) :=
aecover_Ioi_of_Ici (α := αᵒᵈ) hb
include ha hb in
theorem aecover_Ioo_of_Ioo : AECover (μ.restrict <| Ioo A B) l fun i => Ioo (a i) (b i) :=
((aecover_Ioi_of_Ioi ha).mono <| Measure.restrict_mono Ioo_subset_Ioi_self le_rfl).inter
((aecover_Iio_of_Iio hb).mono <| Measure.restrict_mono Ioo_subset_Iio_self le_rfl)
include ha hb in
theorem aecover_Ioo_of_Icc : AECover (μ.restrict <| Ioo A B) l fun i => Icc (a i) (b i) :=
(aecover_Ioo_of_Ioo ha hb).superset (fun _ ↦ Ioo_subset_Icc_self) fun _ ↦ measurableSet_Icc
include ha hb in
theorem aecover_Ioo_of_Ico : AECover (μ.restrict <| Ioo A B) l fun i => Ico (a i) (b i) :=
(aecover_Ioo_of_Ioo ha hb).superset (fun _ ↦ Ioo_subset_Ico_self) fun _ ↦ measurableSet_Ico
include ha hb in
theorem aecover_Ioo_of_Ioc : AECover (μ.restrict <| Ioo A B) l fun i => Ioc (a i) (b i) :=
(aecover_Ioo_of_Ioo ha hb).superset (fun _ ↦ Ioo_subset_Ioc_self) fun _ ↦ measurableSet_Ioc
variable [NoAtoms μ]
theorem aecover_Ioc_of_Icc (ha : Tendsto a l (𝓝 A)) (hb : Tendsto b l (𝓝 B)) :
AECover (μ.restrict <| Ioc A B) l fun i => Icc (a i) (b i) :=
(aecover_Ioo_of_Icc ha hb).mono (Measure.restrict_congr_set Ioo_ae_eq_Ioc).ge
theorem aecover_Ioc_of_Ico (ha : Tendsto a l (𝓝 A)) (hb : Tendsto b l (𝓝 B)) :
AECover (μ.restrict <| Ioc A B) l fun i => Ico (a i) (b i) :=
(aecover_Ioo_of_Ico ha hb).mono (Measure.restrict_congr_set Ioo_ae_eq_Ioc).ge
theorem aecover_Ioc_of_Ioc (ha : Tendsto a l (𝓝 A)) (hb : Tendsto b l (𝓝 B)) :
AECover (μ.restrict <| Ioc A B) l fun i => Ioc (a i) (b i) :=
(aecover_Ioo_of_Ioc ha hb).mono (Measure.restrict_congr_set Ioo_ae_eq_Ioc).ge
theorem aecover_Ioc_of_Ioo (ha : Tendsto a l (𝓝 A)) (hb : Tendsto b l (𝓝 B)) :
AECover (μ.restrict <| Ioc A B) l fun i => Ioo (a i) (b i) :=
(aecover_Ioo_of_Ioo ha hb).mono (Measure.restrict_congr_set Ioo_ae_eq_Ioc).ge
theorem aecover_Ico_of_Icc (ha : Tendsto a l (𝓝 A)) (hb : Tendsto b l (𝓝 B)) :
AECover (μ.restrict <| Ico A B) l fun i => Icc (a i) (b i) :=
(aecover_Ioo_of_Icc ha hb).mono (Measure.restrict_congr_set Ioo_ae_eq_Ico).ge
theorem aecover_Ico_of_Ico (ha : Tendsto a l (𝓝 A)) (hb : Tendsto b l (𝓝 B)) :
AECover (μ.restrict <| Ico A B) l fun i => Ico (a i) (b i) :=
(aecover_Ioo_of_Ico ha hb).mono (Measure.restrict_congr_set Ioo_ae_eq_Ico).ge
theorem aecover_Ico_of_Ioc (ha : Tendsto a l (𝓝 A)) (hb : Tendsto b l (𝓝 B)) :
AECover (μ.restrict <| Ico A B) l fun i => Ioc (a i) (b i) :=
(aecover_Ioo_of_Ioc ha hb).mono (Measure.restrict_congr_set Ioo_ae_eq_Ico).ge
theorem aecover_Ico_of_Ioo (ha : Tendsto a l (𝓝 A)) (hb : Tendsto b l (𝓝 B)) :
AECover (μ.restrict <| Ico A B) l fun i => Ioo (a i) (b i) :=
(aecover_Ioo_of_Ioo ha hb).mono (Measure.restrict_congr_set Ioo_ae_eq_Ico).ge
theorem aecover_Icc_of_Icc (ha : Tendsto a l (𝓝 A)) (hb : Tendsto b l (𝓝 B)) :
AECover (μ.restrict <| Icc A B) l fun i => Icc (a i) (b i) :=
(aecover_Ioo_of_Icc ha hb).mono (Measure.restrict_congr_set Ioo_ae_eq_Icc).ge
theorem aecover_Icc_of_Ico (ha : Tendsto a l (𝓝 A)) (hb : Tendsto b l (𝓝 B)) :
AECover (μ.restrict <| Icc A B) l fun i => Ico (a i) (b i) :=
(aecover_Ioo_of_Ico ha hb).mono (Measure.restrict_congr_set Ioo_ae_eq_Icc).ge
theorem aecover_Icc_of_Ioc (ha : Tendsto a l (𝓝 A)) (hb : Tendsto b l (𝓝 B)) :
AECover (μ.restrict <| Icc A B) l fun i => Ioc (a i) (b i) :=
(aecover_Ioo_of_Ioc ha hb).mono (Measure.restrict_congr_set Ioo_ae_eq_Icc).ge
theorem aecover_Icc_of_Ioo (ha : Tendsto a l (𝓝 A)) (hb : Tendsto b l (𝓝 B)) :
AECover (μ.restrict <| Icc A B) l fun i => Ioo (a i) (b i) :=
(aecover_Ioo_of_Ioo ha hb).mono (Measure.restrict_congr_set Ioo_ae_eq_Icc).ge
end FiniteIntervals
protected theorem AECover.restrict {φ : ι → Set α} (hφ : AECover μ l φ) {s : Set α} :
AECover (μ.restrict s) l φ :=
hφ.mono Measure.restrict_le_self
theorem aecover_restrict_of_ae_imp {s : Set α} {φ : ι → Set α} (hs : MeasurableSet s)
(ae_eventually_mem : ∀ᵐ x ∂μ, x ∈ s → ∀ᶠ n in l, x ∈ φ n)
(measurable : ∀ n, MeasurableSet <| φ n) : AECover (μ.restrict s) l φ where
ae_eventually_mem := by rwa [ae_restrict_iff' hs]
measurableSet := measurable
theorem AECover.inter_restrict {φ : ι → Set α} (hφ : AECover μ l φ) {s : Set α}
(hs : MeasurableSet s) : AECover (μ.restrict s) l fun i => φ i ∩ s :=
aecover_restrict_of_ae_imp hs
(hφ.ae_eventually_mem.mono fun _x hx hxs => hx.mono fun _i hi => ⟨hi, hxs⟩) fun i =>
(hφ.measurableSet i).inter hs
theorem AECover.ae_tendsto_indicator {β : Type*} [Zero β] [TopologicalSpace β] (f : α → β)
{φ : ι → Set α} (hφ : AECover μ l φ) :
∀ᵐ x ∂μ, Tendsto (fun i => (φ i).indicator f x) l (𝓝 <| f x) :=
hφ.ae_eventually_mem.mono fun _x hx =>
tendsto_const_nhds.congr' <| hx.mono fun _n hn => (indicator_of_mem hn _).symm
theorem AECover.aemeasurable {β : Type*} [MeasurableSpace β] [l.IsCountablyGenerated] [l.NeBot]
{f : α → β} {φ : ι → Set α} (hφ : AECover μ l φ)
(hfm : ∀ i, AEMeasurable f (μ.restrict <| φ i)) : AEMeasurable f μ := by
obtain ⟨u, hu⟩ := l.exists_seq_tendsto
have := aemeasurable_iUnion_iff.mpr fun n : ℕ => hfm (u n)
rwa [Measure.restrict_eq_self_of_ae_mem] at this
filter_upwards [hφ.ae_eventually_mem] with x hx using
mem_iUnion.mpr (hu.eventually hx).exists
theorem AECover.aestronglyMeasurable {β : Type*} [TopologicalSpace β] [PseudoMetrizableSpace β]
[l.IsCountablyGenerated] [l.NeBot] {f : α → β} {φ : ι → Set α} (hφ : AECover μ l φ)
(hfm : ∀ i, AEStronglyMeasurable f (μ.restrict <| φ i)) : AEStronglyMeasurable f μ := by
obtain ⟨u, hu⟩ := l.exists_seq_tendsto
have := aestronglyMeasurable_iUnion_iff.mpr fun n : ℕ => hfm (u n)
rwa [Measure.restrict_eq_self_of_ae_mem] at this
filter_upwards [hφ.ae_eventually_mem] with x hx using mem_iUnion.mpr (hu.eventually hx).exists
end AECover
theorem AECover.comp_tendsto {α ι ι' : Type*} [MeasurableSpace α] {μ : Measure α} {l : Filter ι}
{l' : Filter ι'} {φ : ι → Set α} (hφ : AECover μ l φ) {u : ι' → ι} (hu : Tendsto u l' l) :
AECover μ l' (φ ∘ u) where
ae_eventually_mem := hφ.ae_eventually_mem.mono fun _x hx => hu.eventually hx
measurableSet i := hφ.measurableSet (u i)
section AECoverUnionInterCountable
variable {α ι : Type*} [Countable ι] [MeasurableSpace α] {μ : Measure α}
theorem AECover.biUnion_Iic_aecover [Preorder ι] {φ : ι → Set α} (hφ : AECover μ atTop φ) :
AECover μ atTop fun n : ι => ⋃ (k) (_h : k ∈ Iic n), φ k :=
hφ.superset (fun _ ↦ subset_biUnion_of_mem right_mem_Iic) fun _ ↦ .biUnion (to_countable _)
fun _ _ ↦ (hφ.2 _)
theorem AECover.biInter_Ici_aecover [Preorder ι] {φ : ι → Set α}
(hφ : AECover μ atTop φ) : AECover μ atTop fun n : ι => ⋂ (k) (_h : k ∈ Ici n), φ k where
ae_eventually_mem := hφ.ae_eventually_mem.mono fun x h ↦ by
simpa only [mem_iInter, mem_Ici, eventually_forall_ge_atTop]
measurableSet _ := .biInter (to_countable _) fun n _ => hφ.measurableSet n
end AECoverUnionInterCountable
section Lintegral
variable {α ι : Type*} [MeasurableSpace α] {μ : Measure α} {l : Filter ι}
private theorem lintegral_tendsto_of_monotone_of_nat {φ : ℕ → Set α} (hφ : AECover μ atTop φ)
(hmono : Monotone φ) {f : α → ℝ≥0∞} (hfm : AEMeasurable f μ) :
Tendsto (fun i => ∫⁻ x in φ i, f x ∂μ) atTop (𝓝 <| ∫⁻ x, f x ∂μ) :=
let F n := (φ n).indicator f
have key₁ : ∀ n, AEMeasurable (F n) μ := fun n => hfm.indicator (hφ.measurableSet n)
have key₂ : ∀ᵐ x : α ∂μ, Monotone fun n => F n x := ae_of_all _ fun x _i _j hij =>
indicator_le_indicator_of_subset (hmono hij) (fun x => zero_le <| f x) x
have key₃ : ∀ᵐ x : α ∂μ, Tendsto (fun n => F n x) atTop (𝓝 (f x)) := hφ.ae_tendsto_indicator f
(lintegral_tendsto_of_tendsto_of_monotone key₁ key₂ key₃).congr fun n =>
lintegral_indicator (hφ.measurableSet n) _
theorem AECover.lintegral_tendsto_of_nat {φ : ℕ → Set α} (hφ : AECover μ atTop φ) {f : α → ℝ≥0∞}
(hfm : AEMeasurable f μ) : Tendsto (∫⁻ x in φ ·, f x ∂μ) atTop (𝓝 <| ∫⁻ x, f x ∂μ) := by
have lim₁ := lintegral_tendsto_of_monotone_of_nat hφ.biInter_Ici_aecover
(fun i j hij => biInter_subset_biInter_left (Ici_subset_Ici.mpr hij)) hfm
have lim₂ := lintegral_tendsto_of_monotone_of_nat hφ.biUnion_Iic_aecover
(fun i j hij => biUnion_subset_biUnion_left (Iic_subset_Iic.mpr hij)) hfm
refine tendsto_of_tendsto_of_tendsto_of_le_of_le lim₁ lim₂ (fun n ↦ ?_) fun n ↦ ?_
exacts [lintegral_mono_set (biInter_subset_of_mem left_mem_Ici),
lintegral_mono_set (subset_biUnion_of_mem right_mem_Iic)]
theorem AECover.lintegral_tendsto_of_countably_generated [l.IsCountablyGenerated] {φ : ι → Set α}
(hφ : AECover μ l φ) {f : α → ℝ≥0∞} (hfm : AEMeasurable f μ) :
Tendsto (fun i => ∫⁻ x in φ i, f x ∂μ) l (𝓝 <| ∫⁻ x, f x ∂μ) :=
tendsto_of_seq_tendsto fun _u hu => (hφ.comp_tendsto hu).lintegral_tendsto_of_nat hfm
theorem AECover.lintegral_eq_of_tendsto [l.NeBot] [l.IsCountablyGenerated] {φ : ι → Set α}
(hφ : AECover μ l φ) {f : α → ℝ≥0∞} (I : ℝ≥0∞) (hfm : AEMeasurable f μ)
(htendsto : Tendsto (fun i => ∫⁻ x in φ i, f x ∂μ) l (𝓝 I)) : ∫⁻ x, f x ∂μ = I :=
tendsto_nhds_unique (hφ.lintegral_tendsto_of_countably_generated hfm) htendsto
theorem AECover.iSup_lintegral_eq_of_countably_generated [Nonempty ι] [l.NeBot]
[l.IsCountablyGenerated] {φ : ι → Set α} (hφ : AECover μ l φ) {f : α → ℝ≥0∞}
(hfm : AEMeasurable f μ) : ⨆ i : ι, ∫⁻ x in φ i, f x ∂μ = ∫⁻ x, f x ∂μ := by
have := hφ.lintegral_tendsto_of_countably_generated hfm
refine ciSup_eq_of_forall_le_of_forall_lt_exists_gt
(fun i => lintegral_mono' Measure.restrict_le_self le_rfl) fun w hw => ?_
exact (this.eventually_const_lt hw).exists
end Lintegral
section Integrable
variable {α ι E : Type*} [MeasurableSpace α] {μ : Measure α} {l : Filter ι} [NormedAddCommGroup E]
theorem AECover.integrable_of_lintegral_enorm_bounded [l.NeBot] [l.IsCountablyGenerated]
{φ : ι → Set α} (hφ : AECover μ l φ) {f : α → E} (I : ℝ) (hfm : AEStronglyMeasurable f μ)
(hbounded : ∀ᶠ i in l, ∫⁻ x in φ i, ‖f x‖ₑ ∂μ ≤ ENNReal.ofReal I) : Integrable f μ := by
refine ⟨hfm, (le_of_tendsto ?_ hbounded).trans_lt ENNReal.ofReal_lt_top⟩
exact hφ.lintegral_tendsto_of_countably_generated hfm.enorm
@[deprecated (since := "2025-01-22")]
alias AECover.integrable_of_lintegral_nnnorm_bounded :=
AECover.integrable_of_lintegral_enorm_bounded
theorem AECover.integrable_of_lintegral_enorm_tendsto [l.NeBot] [l.IsCountablyGenerated]
{φ : ι → Set α} (hφ : AECover μ l φ) {f : α → E} (I : ℝ) (hfm : AEStronglyMeasurable f μ)
(htendsto : Tendsto (fun i => ∫⁻ x in φ i, ‖f x‖ₑ ∂μ) l (𝓝 <| .ofReal I)) :
Integrable f μ := by
refine hφ.integrable_of_lintegral_enorm_bounded (max 1 (I + 1)) hfm ?_
refine htendsto.eventually (ge_mem_nhds ?_)
refine (ENNReal.ofReal_lt_ofReal_iff (lt_max_of_lt_left zero_lt_one)).2 ?_
exact lt_max_of_lt_right (lt_add_one I)
@[deprecated (since := "2025-01-22")]
alias AECover.integrable_of_lintegral_nnnorm_tendsto :=
AECover.integrable_of_lintegral_enorm_tendsto
theorem AECover.integrable_of_lintegral_enorm_bounded' [l.NeBot] [l.IsCountablyGenerated]
{φ : ι → Set α} (hφ : AECover μ l φ) {f : α → E} (I : ℝ≥0) (hfm : AEStronglyMeasurable f μ)
(hbounded : ∀ᶠ i in l, ∫⁻ x in φ i, ‖f x‖ₑ ∂μ ≤ I) : Integrable f μ :=
hφ.integrable_of_lintegral_enorm_bounded I hfm
(by simpa only [ENNReal.ofReal_coe_nnreal] using hbounded)
@[deprecated (since := "2025-01-22")]
alias AECover.integrable_of_lintegral_nnnorm_bounded' :=
AECover.integrable_of_lintegral_enorm_bounded'
theorem AECover.integrable_of_lintegral_enorm_tendsto' [l.NeBot] [l.IsCountablyGenerated]
{φ : ι → Set α} (hφ : AECover μ l φ) {f : α → E} (I : ℝ≥0) (hfm : AEStronglyMeasurable f μ)
(htendsto : Tendsto (fun i => ∫⁻ x in φ i, ‖f x‖ₑ ∂μ) l (𝓝 I)) : Integrable f μ :=
hφ.integrable_of_lintegral_enorm_tendsto I hfm
(by simpa only [ENNReal.ofReal_coe_nnreal] using htendsto)
@[deprecated (since := "2025-01-22")]
alias AECover.integrable_of_lintegral_nnnorm_tendsto' :=
AECover.integrable_of_lintegral_enorm_tendsto'
theorem AECover.integrable_of_integral_norm_bounded [l.NeBot] [l.IsCountablyGenerated]
{φ : ι → Set α} (hφ : AECover μ l φ) {f : α → E} (I : ℝ) (hfi : ∀ i, IntegrableOn f (φ i) μ)
(hbounded : ∀ᶠ i in l, (∫ x in φ i, ‖f x‖ ∂μ) ≤ I) : Integrable f μ := by
have hfm : AEStronglyMeasurable f μ :=
hφ.aestronglyMeasurable fun i => (hfi i).aestronglyMeasurable
refine hφ.integrable_of_lintegral_enorm_bounded I hfm ?_
conv at hbounded in integral _ _ =>
rw [integral_eq_lintegral_of_nonneg_ae (ae_of_all _ fun x => @norm_nonneg E _ (f x))
hfm.norm.restrict]
conv at hbounded in ENNReal.ofReal _ =>
rw [← coe_nnnorm, ENNReal.ofReal_coe_nnreal]
refine hbounded.mono fun i hi => ?_
rw [← ENNReal.ofReal_toReal <| ne_top_of_lt <| hasFiniteIntegral_iff_enorm.mp (hfi i).2]
apply ENNReal.ofReal_le_ofReal hi
theorem AECover.integrable_of_integral_norm_tendsto [l.NeBot] [l.IsCountablyGenerated]
{φ : ι → Set α} (hφ : AECover μ l φ) {f : α → E} (I : ℝ) (hfi : ∀ i, IntegrableOn f (φ i) μ)
(htendsto : Tendsto (fun i => ∫ x in φ i, ‖f x‖ ∂μ) l (𝓝 I)) : Integrable f μ :=
let ⟨I', hI'⟩ := htendsto.isBoundedUnder_le
hφ.integrable_of_integral_norm_bounded I' hfi hI'
theorem AECover.integrable_of_integral_bounded_of_nonneg_ae [l.NeBot] [l.IsCountablyGenerated]
{φ : ι → Set α} (hφ : AECover μ l φ) {f : α → ℝ} (I : ℝ) (hfi : ∀ i, IntegrableOn f (φ i) μ)
(hnng : ∀ᵐ x ∂μ, 0 ≤ f x) (hbounded : ∀ᶠ i in l, (∫ x in φ i, f x ∂μ) ≤ I) : Integrable f μ :=
hφ.integrable_of_integral_norm_bounded I hfi <| hbounded.mono fun _i hi =>
(integral_congr_ae <| ae_restrict_of_ae <| hnng.mono fun _ => Real.norm_of_nonneg).le.trans hi
theorem AECover.integrable_of_integral_tendsto_of_nonneg_ae [l.NeBot] [l.IsCountablyGenerated]
{φ : ι → Set α} (hφ : AECover μ l φ) {f : α → ℝ} (I : ℝ) (hfi : ∀ i, IntegrableOn f (φ i) μ)
(hnng : ∀ᵐ x ∂μ, 0 ≤ f x) (htendsto : Tendsto (fun i => ∫ x in φ i, f x ∂μ) l (𝓝 I)) :
Integrable f μ :=
let ⟨I', hI'⟩ := htendsto.isBoundedUnder_le
hφ.integrable_of_integral_bounded_of_nonneg_ae I' hfi hnng hI'
end Integrable
section Integral
variable {α ι E : Type*} [MeasurableSpace α] {μ : Measure α} {l : Filter ι} [NormedAddCommGroup E]
[NormedSpace ℝ E]
theorem AECover.integral_tendsto_of_countably_generated [l.IsCountablyGenerated] {φ : ι → Set α}
(hφ : AECover μ l φ) {f : α → E} (hfi : Integrable f μ) :
Tendsto (fun i => ∫ x in φ i, f x ∂μ) l (𝓝 <| ∫ x, f x ∂μ) :=
suffices h : Tendsto (fun i => ∫ x : α, (φ i).indicator f x ∂μ) l (𝓝 (∫ x : α, f x ∂μ)) from by
convert h using 2; rw [integral_indicator (hφ.measurableSet _)]
tendsto_integral_filter_of_dominated_convergence (fun x => ‖f x‖)
(Eventually.of_forall fun i => hfi.aestronglyMeasurable.indicator <| hφ.measurableSet i)
(Eventually.of_forall fun _ => ae_of_all _ fun _ => norm_indicator_le_norm_self _ _) hfi.norm
(hφ.ae_tendsto_indicator f)
/-- Slight reformulation of
`MeasureTheory.AECover.integral_tendsto_of_countably_generated`. -/
theorem AECover.integral_eq_of_tendsto [l.NeBot] [l.IsCountablyGenerated] {φ : ι → Set α}
(hφ : AECover μ l φ) {f : α → E} (I : E) (hfi : Integrable f μ)
(h : Tendsto (fun n => ∫ x in φ n, f x ∂μ) l (𝓝 I)) : ∫ x, f x ∂μ = I :=
tendsto_nhds_unique (hφ.integral_tendsto_of_countably_generated hfi) h
theorem AECover.integral_eq_of_tendsto_of_nonneg_ae [l.NeBot] [l.IsCountablyGenerated]
{φ : ι → Set α} (hφ : AECover μ l φ) {f : α → ℝ} (I : ℝ) (hnng : 0 ≤ᵐ[μ] f)
(hfi : ∀ n, IntegrableOn f (φ n) μ) (htendsto : Tendsto (fun n => ∫ x in φ n, f x ∂μ) l (𝓝 I)) :
∫ x, f x ∂μ = I :=
have hfi' : Integrable f μ := hφ.integrable_of_integral_tendsto_of_nonneg_ae I hfi hnng htendsto
hφ.integral_eq_of_tendsto I hfi' htendsto
end Integral
section IntegrableOfIntervalIntegral
variable {ι E : Type*} {μ : Measure ℝ} {l : Filter ι} [Filter.NeBot l] [IsCountablyGenerated l]
[NormedAddCommGroup E] {a b : ι → ℝ} {f : ℝ → E}
theorem integrable_of_intervalIntegral_norm_bounded (I : ℝ)
(hfi : ∀ i, IntegrableOn f (Ioc (a i) (b i)) μ) (ha : Tendsto a l atBot)
(hb : Tendsto b l atTop) (h : ∀ᶠ i in l, (∫ x in a i..b i, ‖f x‖ ∂μ) ≤ I) : Integrable f μ := by
have hφ : AECover μ l _ := aecover_Ioc ha hb
refine hφ.integrable_of_integral_norm_bounded I hfi (h.mp ?_)
filter_upwards [ha.eventually (eventually_le_atBot 0),
hb.eventually (eventually_ge_atTop 0)] with i hai hbi ht
rwa [← intervalIntegral.integral_of_le (hai.trans hbi)]
/-- If `f` is integrable on intervals `Ioc (a i) (b i)`,
where `a i` tends to -∞ and `b i` tends to ∞, and
`∫ x in a i .. b i, ‖f x‖ ∂μ` converges to `I : ℝ` along a filter `l`,
then `f` is integrable on the interval (-∞, ∞) -/
theorem integrable_of_intervalIntegral_norm_tendsto (I : ℝ)
(hfi : ∀ i, IntegrableOn f (Ioc (a i) (b i)) μ) (ha : Tendsto a l atBot)
(hb : Tendsto b l atTop) (h : Tendsto (fun i => ∫ x in a i..b i, ‖f x‖ ∂μ) l (𝓝 I)) :
Integrable f μ :=
let ⟨I', hI'⟩ := h.isBoundedUnder_le
integrable_of_intervalIntegral_norm_bounded I' hfi ha hb hI'
theorem integrableOn_Iic_of_intervalIntegral_norm_bounded (I b : ℝ)
(hfi : ∀ i, IntegrableOn f (Ioc (a i) b) μ) (ha : Tendsto a l atBot)
(h : ∀ᶠ i in l, (∫ x in a i..b, ‖f x‖ ∂μ) ≤ I) : IntegrableOn f (Iic b) μ := by
have hφ : AECover (μ.restrict <| Iic b) l _ := aecover_Ioi ha
have hfi : ∀ i, IntegrableOn f (Ioi (a i)) (μ.restrict <| Iic b) := by
intro i
rw [IntegrableOn, Measure.restrict_restrict (hφ.measurableSet i)]
exact hfi i
refine hφ.integrable_of_integral_norm_bounded I hfi (h.mp ?_)
filter_upwards [ha.eventually (eventually_le_atBot b)] with i hai
rw [intervalIntegral.integral_of_le hai, Measure.restrict_restrict (hφ.measurableSet i)]
exact id
/-- If `f` is integrable on intervals `Ioc (a i) b`,
where `a i` tends to -∞, and
`∫ x in a i .. b, ‖f x‖ ∂μ` converges to `I : ℝ` along a filter `l`,
then `f` is integrable on the interval (-∞, b) -/
theorem integrableOn_Iic_of_intervalIntegral_norm_tendsto (I b : ℝ)
(hfi : ∀ i, IntegrableOn f (Ioc (a i) b) μ) (ha : Tendsto a l atBot)
(h : Tendsto (fun i => ∫ x in a i..b, ‖f x‖ ∂μ) l (𝓝 I)) : IntegrableOn f (Iic b) μ :=
let ⟨I', hI'⟩ := h.isBoundedUnder_le
integrableOn_Iic_of_intervalIntegral_norm_bounded I' b hfi ha hI'
theorem integrableOn_Ioi_of_intervalIntegral_norm_bounded (I a : ℝ)
(hfi : ∀ i, IntegrableOn f (Ioc a (b i)) μ) (hb : Tendsto b l atTop)
(h : ∀ᶠ i in l, (∫ x in a..b i, ‖f x‖ ∂μ) ≤ I) : IntegrableOn f (Ioi a) μ := by
have hφ : AECover (μ.restrict <| Ioi a) l _ := aecover_Iic hb
have hfi : ∀ i, IntegrableOn f (Iic (b i)) (μ.restrict <| Ioi a) := by
intro i
rw [IntegrableOn, Measure.restrict_restrict (hφ.measurableSet i), inter_comm]
exact hfi i
refine hφ.integrable_of_integral_norm_bounded I hfi (h.mp ?_)
filter_upwards [hb.eventually (eventually_ge_atTop a)] with i hbi
rw [intervalIntegral.integral_of_le hbi, Measure.restrict_restrict (hφ.measurableSet i),
inter_comm]
exact id
/-- If `f` is integrable on intervals `Ioc a (b i)`,
where `b i` tends to ∞, and
`∫ x in a .. b i, ‖f x‖ ∂μ` converges to `I : ℝ` along a filter `l`,
then `f` is integrable on the interval (a, ∞) -/
theorem integrableOn_Ioi_of_intervalIntegral_norm_tendsto (I a : ℝ)
(hfi : ∀ i, IntegrableOn f (Ioc a (b i)) μ) (hb : Tendsto b l atTop)
(h : Tendsto (fun i => ∫ x in a..b i, ‖f x‖ ∂μ) l (𝓝 <| I)) : IntegrableOn f (Ioi a) μ :=
let ⟨I', hI'⟩ := h.isBoundedUnder_le
integrableOn_Ioi_of_intervalIntegral_norm_bounded I' a hfi hb hI'
theorem integrableOn_Ioc_of_intervalIntegral_norm_bounded {I a₀ b₀ : ℝ}
(hfi : ∀ i, IntegrableOn f <| Ioc (a i) (b i)) (ha : Tendsto a l <| 𝓝 a₀)
(hb : Tendsto b l <| 𝓝 b₀) (h : ∀ᶠ i in l, (∫ x in Ioc (a i) (b i), ‖f x‖) ≤ I) :
IntegrableOn f (Ioc a₀ b₀) := by
refine (aecover_Ioc_of_Ioc ha hb).integrable_of_integral_norm_bounded I
(fun i => (hfi i).restrict) (h.mono fun i hi ↦ ?_)
rw [Measure.restrict_restrict measurableSet_Ioc]
refine le_trans (setIntegral_mono_set (hfi i).norm ?_ ?_) hi <;> apply ae_of_all
· simp only [Pi.zero_apply, norm_nonneg, forall_const]
· intro c hc; exact hc.1
theorem integrableOn_Ioc_of_intervalIntegral_norm_bounded_left {I a₀ b : ℝ}
(hfi : ∀ i, IntegrableOn f <| Ioc (a i) b) (ha : Tendsto a l <| 𝓝 a₀)
(h : ∀ᶠ i in l, (∫ x in Ioc (a i) b, ‖f x‖) ≤ I) : IntegrableOn f (Ioc a₀ b) :=
integrableOn_Ioc_of_intervalIntegral_norm_bounded hfi ha tendsto_const_nhds h
theorem integrableOn_Ioc_of_intervalIntegral_norm_bounded_right {I a b₀ : ℝ}
(hfi : ∀ i, IntegrableOn f <| Ioc a (b i)) (hb : Tendsto b l <| 𝓝 b₀)
(h : ∀ᶠ i in l, (∫ x in Ioc a (b i), ‖f x‖) ≤ I) : IntegrableOn f (Ioc a b₀) :=
integrableOn_Ioc_of_intervalIntegral_norm_bounded hfi tendsto_const_nhds hb h
end IntegrableOfIntervalIntegral
section IntegralOfIntervalIntegral
variable {ι E : Type*} {μ : Measure ℝ} {l : Filter ι} [IsCountablyGenerated l]
[NormedAddCommGroup E] [NormedSpace ℝ E] {a b : ι → ℝ} {f : ℝ → E}
theorem intervalIntegral_tendsto_integral (hfi : Integrable f μ) (ha : Tendsto a l atBot)
(hb : Tendsto b l atTop) : Tendsto (fun i => ∫ x in a i..b i, f x ∂μ) l (𝓝 <| ∫ x, f x ∂μ) := by
let φ i := Ioc (a i) (b i)
have hφ : AECover μ l φ := aecover_Ioc ha hb
refine (hφ.integral_tendsto_of_countably_generated hfi).congr' ?_
filter_upwards [ha.eventually (eventually_le_atBot 0),
hb.eventually (eventually_ge_atTop 0)] with i hai hbi
exact (intervalIntegral.integral_of_le (hai.trans hbi)).symm
theorem intervalIntegral_tendsto_integral_Iic (b : ℝ) (hfi : IntegrableOn f (Iic b) μ)
(ha : Tendsto a l atBot) :
Tendsto (fun i => ∫ x in a i..b, f x ∂μ) l (𝓝 <| ∫ x in Iic b, f x ∂μ) := by
let φ i := Ioi (a i)
have hφ : AECover (μ.restrict <| Iic b) l φ := aecover_Ioi ha
refine (hφ.integral_tendsto_of_countably_generated hfi).congr' ?_
filter_upwards [ha.eventually (eventually_le_atBot <| b)] with i hai
rw [intervalIntegral.integral_of_le hai, Measure.restrict_restrict (hφ.measurableSet i)]
rfl
theorem intervalIntegral_tendsto_integral_Ioi (a : ℝ) (hfi : IntegrableOn f (Ioi a) μ)
(hb : Tendsto b l atTop) :
Tendsto (fun i => ∫ x in a..b i, f x ∂μ) l (𝓝 <| ∫ x in Ioi a, f x ∂μ) := by
let φ i := Iic (b i)
have hφ : AECover (μ.restrict <| Ioi a) l φ := aecover_Iic hb
refine (hφ.integral_tendsto_of_countably_generated hfi).congr' ?_
filter_upwards [hb.eventually (eventually_ge_atTop <| a)] with i hbi
rw [intervalIntegral.integral_of_le hbi, Measure.restrict_restrict (hφ.measurableSet i),
inter_comm]
rfl
end IntegralOfIntervalIntegral
open Real
open scoped Interval
section IoiFTC
variable {E : Type*} {f f' : ℝ → E} {g g' : ℝ → ℝ} {a l : ℝ} {m : E} [NormedAddCommGroup E]
[NormedSpace ℝ E]
/-- If the derivative of a function defined on the real line is integrable close to `+∞`, then
the function has a limit at `+∞`. -/
theorem tendsto_limUnder_of_hasDerivAt_of_integrableOn_Ioi [CompleteSpace E]
(hderiv : ∀ x ∈ Ioi a, HasDerivAt f (f' x) x) (f'int : IntegrableOn f' (Ioi a)) :
Tendsto f atTop (𝓝 (limUnder atTop f)) := by
suffices ∃ a, Tendsto f atTop (𝓝 a) from tendsto_nhds_limUnder this
suffices CauchySeq f from cauchySeq_tendsto_of_complete this
apply Metric.cauchySeq_iff'.2 (fun ε εpos ↦ ?_)
have A : ∀ᶠ (n : ℕ) in atTop, ∫ (x : ℝ) in Ici ↑n, ‖f' x‖ < ε := by
have L : Tendsto (fun (n : ℕ) ↦ ∫ x in Ici (n : ℝ), ‖f' x‖) atTop
(𝓝 (∫ x in ⋂ (n : ℕ), Ici (n : ℝ), ‖f' x‖)) := by
apply tendsto_setIntegral_of_antitone (fun n ↦ measurableSet_Ici)
· intro m n hmn
exact Ici_subset_Ici.2 (Nat.cast_le.mpr hmn)
· rcases exists_nat_gt a with ⟨n, hn⟩
exact ⟨n, IntegrableOn.mono_set f'int.norm (Ici_subset_Ioi.2 hn)⟩
have B : ⋂ (n : ℕ), Ici (n : ℝ) = ∅ := by
apply eq_empty_of_forall_not_mem (fun x ↦ ?_)
simpa only [mem_iInter, mem_Ici, not_forall, not_le] using exists_nat_gt x
simp only [B, Measure.restrict_empty, integral_zero_measure] at L
exact (tendsto_order.1 L).2 _ εpos
have B : ∀ᶠ (n : ℕ) in atTop, a < n := by
rcases exists_nat_gt a with ⟨n, hn⟩
filter_upwards [Ioi_mem_atTop n] with m (hm : n < m) using hn.trans (Nat.cast_lt.mpr hm)
rcases (A.and B).exists with ⟨N, hN, h'N⟩
refine ⟨N, fun x hx ↦ ?_⟩
calc
dist (f x) (f ↑N)
= ‖f x - f N‖ := dist_eq_norm _ _
_ = ‖∫ t in Ioc ↑N x, f' t‖ := by
rw [← intervalIntegral.integral_of_le hx, intervalIntegral.integral_eq_sub_of_hasDerivAt]
· intro y hy
simp only [hx, uIcc_of_le, mem_Icc] at hy
exact hderiv _ (h'N.trans_le hy.1)
· rw [intervalIntegrable_iff_integrableOn_Ioc_of_le hx]
exact f'int.mono_set (Ioc_subset_Ioi_self.trans (Ioi_subset_Ioi h'N.le))
_ ≤ ∫ t in Ioc ↑N x, ‖f' t‖ := norm_integral_le_integral_norm fun a ↦ f' a
_ ≤ ∫ t in Ici ↑N, ‖f' t‖ := by
apply setIntegral_mono_set
· apply IntegrableOn.mono_set f'int.norm (Ici_subset_Ioi.2 h'N)
· filter_upwards with x using norm_nonneg _
· have : Ioc (↑N) x ⊆ Ici ↑N := Ioc_subset_Ioi_self.trans Ioi_subset_Ici_self
exact this.eventuallyLE
_ < ε := hN
open UniformSpace in
/-- If a function and its derivative are integrable on `(a, +∞)`, then the function tends to zero
at `+∞`. -/
theorem tendsto_zero_of_hasDerivAt_of_integrableOn_Ioi
(hderiv : ∀ x ∈ Ioi a, HasDerivAt f (f' x) x)
(f'int : IntegrableOn f' (Ioi a)) (fint : IntegrableOn f (Ioi a)) :
Tendsto f atTop (𝓝 0) := by
let F : E →L[ℝ] Completion E := Completion.toComplL
have Fderiv : ∀ x ∈ Ioi a, HasDerivAt (F ∘ f) (F (f' x)) x :=
fun x hx ↦ F.hasFDerivAt.comp_hasDerivAt _ (hderiv x hx)
have Fint : IntegrableOn (F ∘ f) (Ioi a) := by apply F.integrable_comp fint
have F'int : IntegrableOn (F ∘ f') (Ioi a) := by apply F.integrable_comp f'int
have A : Tendsto (F ∘ f) atTop (𝓝 (limUnder atTop (F ∘ f))) := by
apply tendsto_limUnder_of_hasDerivAt_of_integrableOn_Ioi Fderiv F'int
have B : limUnder atTop (F ∘ f) = F 0 := by
have : IntegrableAtFilter (F ∘ f) atTop := by exact ⟨Ioi a, Ioi_mem_atTop _, Fint⟩
apply IntegrableAtFilter.eq_zero_of_tendsto this ?_ A
intro s hs
rcases mem_atTop_sets.1 hs with ⟨b, hb⟩
rw [← top_le_iff, ← volume_Ici (a := b)]
exact measure_mono hb
rwa [B, ← IsEmbedding.tendsto_nhds_iff] at A
exact (Completion.isUniformEmbedding_coe E).isEmbedding
variable [CompleteSpace E]
/-- **Fundamental theorem of calculus-2**, on semi-infinite intervals `(a, +∞)`.
When a function has a limit at infinity `m`, and its derivative is integrable, then the
integral of the derivative on `(a, +∞)` is `m - f a`. Version assuming differentiability
on `(a, +∞)` and continuity at `a⁺`.
Note that such a function always has a limit at infinity,
see `tendsto_limUnder_of_hasDerivAt_of_integrableOn_Ioi`. -/
theorem integral_Ioi_of_hasDerivAt_of_tendsto (hcont : ContinuousWithinAt f (Ici a) a)
(hderiv : ∀ x ∈ Ioi a, HasDerivAt f (f' x) x) (f'int : IntegrableOn f' (Ioi a))
(hf : Tendsto f atTop (𝓝 m)) : ∫ x in Ioi a, f' x = m - f a := by
have hcont : ContinuousOn f (Ici a) := by
intro x hx
rcases hx.out.eq_or_lt with rfl|hx
· exact hcont
· exact (hderiv x hx).continuousAt.continuousWithinAt
refine tendsto_nhds_unique (intervalIntegral_tendsto_integral_Ioi a f'int tendsto_id) ?_
apply Tendsto.congr' _ (hf.sub_const _)
filter_upwards [Ioi_mem_atTop a] with x hx
have h'x : a ≤ id x := le_of_lt hx
symm
apply
intervalIntegral.integral_eq_sub_of_hasDerivAt_of_le h'x (hcont.mono Icc_subset_Ici_self)
fun y hy => hderiv y hy.1
rw [intervalIntegrable_iff_integrableOn_Ioc_of_le h'x]
exact f'int.mono (fun y hy => hy.1) le_rfl
/-- **Fundamental theorem of calculus-2**, on semi-infinite intervals `(a, +∞)`.
When a function has a limit at infinity `m`, and its derivative is integrable, then the
integral of the derivative on `(a, +∞)` is `m - f a`. Version assuming differentiability
on `[a, +∞)`.
Note that such a function always has a limit at infinity,
see `tendsto_limUnder_of_hasDerivAt_of_integrableOn_Ioi`. -/
theorem integral_Ioi_of_hasDerivAt_of_tendsto' (hderiv : ∀ x ∈ Ici a, HasDerivAt f (f' x) x)
(f'int : IntegrableOn f' (Ioi a)) (hf : Tendsto f atTop (𝓝 m)) :
∫ x in Ioi a, f' x = m - f a := by
refine integral_Ioi_of_hasDerivAt_of_tendsto ?_ (fun x hx => hderiv x hx.out.le)
f'int hf
exact (hderiv a left_mem_Ici).continuousAt.continuousWithinAt
/-- A special case of `integral_Ioi_of_hasDerivAt_of_tendsto` where we assume that `f` is C^1 with
compact support. -/
theorem _root_.HasCompactSupport.integral_Ioi_deriv_eq (hf : ContDiff ℝ 1 f)
(h2f : HasCompactSupport f) (b : ℝ) : ∫ x in Ioi b, deriv f x = - f b := by
have := fun x (_ : x ∈ Ioi b) ↦ hf.differentiable le_rfl x |>.hasDerivAt
rw [integral_Ioi_of_hasDerivAt_of_tendsto hf.continuous.continuousWithinAt this, zero_sub]
· refine hf.continuous_deriv le_rfl |>.integrable_of_hasCompactSupport h2f.deriv |>.integrableOn
rw [hasCompactSupport_iff_eventuallyEq, Filter.coclosedCompact_eq_cocompact] at h2f
exact h2f.filter_mono _root_.atTop_le_cocompact |>.tendsto
/-- When a function has a limit at infinity, and its derivative is nonnegative, then the derivative
is automatically integrable on `(a, +∞)`. Version assuming differentiability
on `(a, +∞)` and continuity at `a⁺`. -/
theorem integrableOn_Ioi_deriv_of_nonneg (hcont : ContinuousWithinAt g (Ici a) a)
(hderiv : ∀ x ∈ Ioi a, HasDerivAt g (g' x) x) (g'pos : ∀ x ∈ Ioi a, 0 ≤ g' x)
(hg : Tendsto g atTop (𝓝 l)) : IntegrableOn g' (Ioi a) := by
have hcont : ContinuousOn g (Ici a) := by
intro x hx
rcases hx.out.eq_or_lt with rfl|hx
· exact hcont
· exact (hderiv x hx).continuousAt.continuousWithinAt
refine integrableOn_Ioi_of_intervalIntegral_norm_tendsto (l - g a) a (fun x => ?_) tendsto_id ?_
· exact intervalIntegral.integrableOn_deriv_of_nonneg (hcont.mono Icc_subset_Ici_self)
(fun y hy => hderiv y hy.1) fun y hy => g'pos y hy.1
apply Tendsto.congr' _ (hg.sub_const _)
filter_upwards [Ioi_mem_atTop a] with x hx
have h'x : a ≤ id x := le_of_lt hx
calc
g x - g a = ∫ y in a..id x, g' y := by
symm
apply intervalIntegral.integral_eq_sub_of_hasDerivAt_of_le h'x
(hcont.mono Icc_subset_Ici_self) fun y hy => hderiv y hy.1
rw [intervalIntegrable_iff_integrableOn_Ioc_of_le h'x]
exact intervalIntegral.integrableOn_deriv_of_nonneg (hcont.mono Icc_subset_Ici_self)
(fun y hy => hderiv y hy.1) fun y hy => g'pos y hy.1
_ = ∫ y in a..id x, ‖g' y‖ := by
simp_rw [intervalIntegral.integral_of_le h'x]
refine setIntegral_congr_fun measurableSet_Ioc fun y hy => ?_
dsimp
rw [abs_of_nonneg]
exact g'pos _ hy.1
/-- When a function has a limit at infinity, and its derivative is nonnegative, then the derivative
is automatically integrable on `(a, +∞)`. Version assuming differentiability
on `[a, +∞)`. -/
theorem integrableOn_Ioi_deriv_of_nonneg' (hderiv : ∀ x ∈ Ici a, HasDerivAt g (g' x) x)
(g'pos : ∀ x ∈ Ioi a, 0 ≤ g' x) (hg : Tendsto g atTop (𝓝 l)) : IntegrableOn g' (Ioi a) := by
refine integrableOn_Ioi_deriv_of_nonneg ?_ (fun x hx => hderiv x hx.out.le) g'pos hg
exact (hderiv a left_mem_Ici).continuousAt.continuousWithinAt
/-- When a function has a limit at infinity `l`, and its derivative is nonnegative, then the
integral of the derivative on `(a, +∞)` is `l - g a` (and the derivative is integrable, see
`integrable_on_Ioi_deriv_of_nonneg`). Version assuming differentiability on `(a, +∞)` and
continuity at `a⁺`. -/
theorem integral_Ioi_of_hasDerivAt_of_nonneg (hcont : ContinuousWithinAt g (Ici a) a)
(hderiv : ∀ x ∈ Ioi a, HasDerivAt g (g' x) x) (g'pos : ∀ x ∈ Ioi a, 0 ≤ g' x)
(hg : Tendsto g atTop (𝓝 l)) : ∫ x in Ioi a, g' x = l - g a :=
integral_Ioi_of_hasDerivAt_of_tendsto hcont hderiv
(integrableOn_Ioi_deriv_of_nonneg hcont hderiv g'pos hg) hg
/-- When a function has a limit at infinity `l`, and its derivative is nonnegative, then the
integral of the derivative on `(a, +∞)` is `l - g a` (and the derivative is integrable, see
`integrable_on_Ioi_deriv_of_nonneg'`). Version assuming differentiability on `[a, +∞)`. -/
theorem integral_Ioi_of_hasDerivAt_of_nonneg' (hderiv : ∀ x ∈ Ici a, HasDerivAt g (g' x) x)
(g'pos : ∀ x ∈ Ioi a, 0 ≤ g' x) (hg : Tendsto g atTop (𝓝 l)) : ∫ x in Ioi a, g' x = l - g a :=
integral_Ioi_of_hasDerivAt_of_tendsto' hderiv (integrableOn_Ioi_deriv_of_nonneg' hderiv g'pos hg)
hg
/-- When a function has a limit at infinity, and its derivative is nonpositive, then the derivative
is automatically integrable on `(a, +∞)`. Version assuming differentiability
on `(a, +∞)` and continuity at `a⁺`. -/
theorem integrableOn_Ioi_deriv_of_nonpos (hcont : ContinuousWithinAt g (Ici a) a)
(hderiv : ∀ x ∈ Ioi a, HasDerivAt g (g' x) x) (g'neg : ∀ x ∈ Ioi a, g' x ≤ 0)
(hg : Tendsto g atTop (𝓝 l)) : IntegrableOn g' (Ioi a) := by
apply integrable_neg_iff.1
exact integrableOn_Ioi_deriv_of_nonneg hcont.neg (fun x hx => (hderiv x hx).neg)
(fun x hx => neg_nonneg_of_nonpos (g'neg x hx)) hg.neg
/-- When a function has a limit at infinity, and its derivative is nonpositive, then the derivative
is automatically integrable on `(a, +∞)`. Version assuming differentiability
on `[a, +∞)`. -/
theorem integrableOn_Ioi_deriv_of_nonpos' (hderiv : ∀ x ∈ Ici a, HasDerivAt g (g' x) x)
(g'neg : ∀ x ∈ Ioi a, g' x ≤ 0) (hg : Tendsto g atTop (𝓝 l)) : IntegrableOn g' (Ioi a) := by
refine integrableOn_Ioi_deriv_of_nonpos ?_ (fun x hx ↦ hderiv x hx.out.le) g'neg hg
exact (hderiv a left_mem_Ici).continuousAt.continuousWithinAt
/-- When a function has a limit at infinity `l`, and its derivative is nonpositive, then the
integral of the derivative on `(a, +∞)` is `l - g a` (and the derivative is integrable, see
`integrable_on_Ioi_deriv_of_nonneg`). Version assuming differentiability on `(a, +∞)` and
continuity at `a⁺`. -/
theorem integral_Ioi_of_hasDerivAt_of_nonpos (hcont : ContinuousWithinAt g (Ici a) a)
(hderiv : ∀ x ∈ Ioi a, HasDerivAt g (g' x) x) (g'neg : ∀ x ∈ Ioi a, g' x ≤ 0)
(hg : Tendsto g atTop (𝓝 l)) : ∫ x in Ioi a, g' x = l - g a :=
integral_Ioi_of_hasDerivAt_of_tendsto hcont hderiv
(integrableOn_Ioi_deriv_of_nonpos hcont hderiv g'neg hg) hg
/-- When a function has a limit at infinity `l`, and its derivative is nonpositive, then the
integral of the derivative on `(a, +∞)` is `l - g a` (and the derivative is integrable, see
`integrable_on_Ioi_deriv_of_nonneg'`). Version assuming differentiability on `[a, +∞)`. -/
theorem integral_Ioi_of_hasDerivAt_of_nonpos' (hderiv : ∀ x ∈ Ici a, HasDerivAt g (g' x) x)
(g'neg : ∀ x ∈ Ioi a, g' x ≤ 0) (hg : Tendsto g atTop (𝓝 l)) : ∫ x in Ioi a, g' x = l - g a :=
integral_Ioi_of_hasDerivAt_of_tendsto' hderiv (integrableOn_Ioi_deriv_of_nonpos' hderiv g'neg hg)
hg
end IoiFTC
section IicFTC
variable {E : Type*} {f f' : ℝ → E} {a : ℝ} {m : E} [NormedAddCommGroup E]
[NormedSpace ℝ E]
/-- If the derivative of a function defined on the real line is integrable close to `-∞`, then
the function has a limit at `-∞`. -/
theorem tendsto_limUnder_of_hasDerivAt_of_integrableOn_Iic [CompleteSpace E]
(hderiv : ∀ x ∈ Iic a, HasDerivAt f (f' x) x) (f'int : IntegrableOn f' (Iic a)) :
Tendsto f atBot (𝓝 (limUnder atBot f)) := by
suffices ∃ a, Tendsto f atBot (𝓝 a) from tendsto_nhds_limUnder this
let g := f ∘ (fun x ↦ -x)
have hdg : ∀ x ∈ Ioi (-a), HasDerivAt g (-f' (-x)) x := by
intro x hx
have : -x ∈ Iic a := by simp only [mem_Iic, mem_Ioi, neg_le] at *; exact hx.le
simpa using HasDerivAt.scomp x (hderiv (-x) this) (hasDerivAt_neg' x)
have L : Tendsto g atTop (𝓝 (limUnder atTop g)) := by
apply tendsto_limUnder_of_hasDerivAt_of_integrableOn_Ioi hdg
exact ((MeasurePreserving.integrableOn_comp_preimage (Measure.measurePreserving_neg _)
(Homeomorph.neg ℝ).measurableEmbedding).2 f'int.neg).mono_set (by simp)
refine ⟨limUnder atTop g, ?_⟩
have : Tendsto (fun x ↦ g (-x)) atBot (𝓝 (limUnder atTop g)) := L.comp tendsto_neg_atBot_atTop
simpa [g] using this
open UniformSpace in
/-- If a function and its derivative are integrable on `(-∞, a]`, then the function tends to zero
at `-∞`. -/
theorem tendsto_zero_of_hasDerivAt_of_integrableOn_Iic
(hderiv : ∀ x ∈ Iic a, HasDerivAt f (f' x) x)
(f'int : IntegrableOn f' (Iic a)) (fint : IntegrableOn f (Iic a)) :
Tendsto f atBot (𝓝 0) := by
let F : E →L[ℝ] Completion E := Completion.toComplL
have Fderiv : ∀ x ∈ Iic a, HasDerivAt (F ∘ f) (F (f' x)) x :=
fun x hx ↦ F.hasFDerivAt.comp_hasDerivAt _ (hderiv x hx)
have Fint : IntegrableOn (F ∘ f) (Iic a) := by apply F.integrable_comp fint
| have F'int : IntegrableOn (F ∘ f') (Iic a) := by apply F.integrable_comp f'int
have A : Tendsto (F ∘ f) atBot (𝓝 (limUnder atBot (F ∘ f))) := by
apply tendsto_limUnder_of_hasDerivAt_of_integrableOn_Iic Fderiv F'int
have B : limUnder atBot (F ∘ f) = F 0 := by
| Mathlib/MeasureTheory/Integral/IntegralEqImproper.lean | 898 | 901 |
/-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Thomas Browning
-/
import Mathlib.Algebra.Order.Archimedean.Basic
import Mathlib.Data.SetLike.Fintype
import Mathlib.GroupTheory.PGroup
import Mathlib.GroupTheory.NoncommPiCoprod
/-!
# Sylow theorems
The Sylow theorems are the following results for every finite group `G` and every prime number `p`.
* There exists a Sylow `p`-subgroup of `G`.
* All Sylow `p`-subgroups of `G` are conjugate to each other.
* Let `nₚ` be the number of Sylow `p`-subgroups of `G`, then `nₚ` divides the index of the Sylow
`p`-subgroup, `nₚ ≡ 1 [MOD p]`, and `nₚ` is equal to the index of the normalizer of the Sylow
`p`-subgroup in `G`.
## Main definitions
* `Sylow p G` : The type of Sylow `p`-subgroups of `G`.
## Main statements
* `Sylow.exists_subgroup_card_pow_prime`: A generalization of Sylow's first theorem:
For every prime power `pⁿ` dividing the cardinality of `G`,
there exists a subgroup of `G` of order `pⁿ`.
* `IsPGroup.exists_le_sylow`: A generalization of Sylow's first theorem:
Every `p`-subgroup is contained in a Sylow `p`-subgroup.
* `Sylow.card_eq_multiplicity`: The cardinality of a Sylow subgroup is `p ^ n`
where `n` is the multiplicity of `p` in the group order.
* `Sylow.isPretransitive_of_finite`: a generalization of Sylow's second theorem:
If the number of Sylow `p`-subgroups is finite, then all Sylow `p`-subgroups are conjugate.
* `card_sylow_modEq_one`: a generalization of Sylow's third theorem:
If the number of Sylow `p`-subgroups is finite, then it is congruent to `1` modulo `p`.
-/
open MulAction Subgroup
section InfiniteSylow
variable (p : ℕ) (G : Type*) [Group G]
/-- A Sylow `p`-subgroup is a maximal `p`-subgroup. -/
structure Sylow extends Subgroup G where
isPGroup' : IsPGroup p toSubgroup
is_maximal' : ∀ {Q : Subgroup G}, IsPGroup p Q → toSubgroup ≤ Q → Q = toSubgroup
variable {p} {G}
namespace Sylow
attribute [coe] toSubgroup
instance : CoeOut (Sylow p G) (Subgroup G) :=
⟨toSubgroup⟩
@[ext]
theorem ext {P Q : Sylow p G} (h : (P : Subgroup G) = Q) : P = Q := by cases P; cases Q; congr
instance : SetLike (Sylow p G) G where
coe := (↑)
coe_injective' _ _ h := ext (SetLike.coe_injective h)
instance : SubgroupClass (Sylow p G) G where
mul_mem := Subgroup.mul_mem _
one_mem _ := Subgroup.one_mem _
inv_mem := Subgroup.inv_mem _
/-- A `p`-subgroup with index indivisible by `p` is a Sylow subgroup. -/
def _root_.IsPGroup.toSylow [Fact p.Prime] {P : Subgroup G}
(hP1 : IsPGroup p P) (hP2 : ¬ p ∣ P.index) : Sylow p G :=
{ P with
isPGroup' := hP1
is_maximal' := by
intro Q hQ hPQ
have : P.FiniteIndex := ⟨fun h ↦ hP2 (h ▸ (dvd_zero p))⟩
obtain ⟨k, hk⟩ := (hQ.to_quotient (P.normalCore.subgroupOf Q)).exists_card_eq
have h := hk ▸ Nat.Prime.coprime_pow_of_not_dvd (m := k) Fact.out hP2
exact le_antisymm (Subgroup.relindex_eq_one.mp
(Nat.eq_one_of_dvd_coprimes h (Subgroup.relindex_dvd_index_of_le hPQ)
(Subgroup.relindex_dvd_of_le_left Q P.normalCore_le))) hPQ }
@[simp] theorem _root_.IsPGroup.toSylow_coe [Fact p.Prime] {P : Subgroup G}
(hP1 : IsPGroup p P) (hP2 : ¬ p ∣ P.index) : (hP1.toSylow hP2) = P :=
rfl
@[simp] theorem _root_.IsPGroup.mem_toSylow [Fact p.Prime] {P : Subgroup G}
(hP1 : IsPGroup p P) (hP2 : ¬ p ∣ P.index) {g : G} : g ∈ hP1.toSylow hP2 ↔ g ∈ P :=
.rfl
/-- A subgroup with cardinality `p ^ n` is a Sylow subgroup
where `n` is the multiplicity of `p` in the group order. -/
def ofCard [Finite G] {p : ℕ} [Fact p.Prime] (H : Subgroup G)
(card_eq : Nat.card H = p ^ (Nat.card G).factorization p) : Sylow p G :=
(IsPGroup.of_card card_eq).toSylow (by
rw [← mul_dvd_mul_iff_left (Nat.card_pos (α := H)).ne', card_mul_index, card_eq, ← pow_succ]
exact Nat.pow_succ_factorization_not_dvd Nat.card_pos.ne' Fact.out)
@[simp, norm_cast]
theorem coe_ofCard [Finite G] {p : ℕ} [Fact p.Prime] (H : Subgroup G)
(card_eq : Nat.card H = p ^ (Nat.card G).factorization p) : ofCard H card_eq = H :=
rfl
variable (P : Sylow p G)
variable {K : Type*} [Group K] (ϕ : K →* G) {N : Subgroup G}
/-- The preimage of a Sylow subgroup under a p-group-kernel homomorphism is a Sylow subgroup. -/
def comapOfKerIsPGroup (hϕ : IsPGroup p ϕ.ker) (h : P ≤ ϕ.range) : Sylow p K :=
{ P.1.comap ϕ with
isPGroup' := P.2.comap_of_ker_isPGroup ϕ hϕ
is_maximal' := fun {Q} hQ hle => by
show Q = P.1.comap ϕ
rw [← P.3 (hQ.map ϕ) (le_trans (ge_of_eq (map_comap_eq_self h)) (map_mono hle))]
exact (comap_map_eq_self ((P.1.ker_le_comap ϕ).trans hle)).symm }
@[simp]
theorem coe_comapOfKerIsPGroup (hϕ : IsPGroup p ϕ.ker) (h : P ≤ ϕ.range) :
P.comapOfKerIsPGroup ϕ hϕ h = P.comap ϕ :=
rfl
/-- The preimage of a Sylow subgroup under an injective homomorphism is a Sylow subgroup. -/
def comapOfInjective (hϕ : Function.Injective ϕ) (h : P ≤ ϕ.range) : Sylow p K :=
P.comapOfKerIsPGroup ϕ (IsPGroup.ker_isPGroup_of_injective hϕ) h
@[simp]
theorem coe_comapOfInjective (hϕ : Function.Injective ϕ) (h : P ≤ ϕ.range) :
P.comapOfInjective ϕ hϕ h = P.comap ϕ :=
rfl
/-- A sylow subgroup of G is also a sylow subgroup of a subgroup of G. -/
protected def subtype (h : P ≤ N) : Sylow p N :=
P.comapOfInjective N.subtype Subtype.coe_injective (by rwa [range_subtype])
@[simp]
theorem coe_subtype (h : P ≤ N) : P.subtype h = subgroupOf P N :=
rfl
theorem subtype_injective {P Q : Sylow p G} {hP : P ≤ N} {hQ : Q ≤ N}
(h : P.subtype hP = Q.subtype hQ) : P = Q := by
rw [SetLike.ext_iff] at h ⊢
exact fun g => ⟨fun hg => (h ⟨g, hP hg⟩).mp hg, fun hg => (h ⟨g, hQ hg⟩).mpr hg⟩
end Sylow
/-- A generalization of **Sylow's first theorem**.
Every `p`-subgroup is contained in a Sylow `p`-subgroup. -/
theorem IsPGroup.exists_le_sylow {P : Subgroup G} (hP : IsPGroup p P) : ∃ Q : Sylow p G, P ≤ Q :=
Exists.elim
(zorn_le_nonempty₀ { Q : Subgroup G | IsPGroup p Q }
(fun c hc1 hc2 Q hQ =>
⟨{ carrier := ⋃ R : c, R
one_mem' := ⟨Q, ⟨⟨Q, hQ⟩, rfl⟩, Q.one_mem⟩
inv_mem' := fun {_} ⟨_, ⟨R, rfl⟩, hg⟩ => ⟨R, ⟨R, rfl⟩, R.1.inv_mem hg⟩
mul_mem' := fun {_} _ ⟨_, ⟨R, rfl⟩, hg⟩ ⟨_, ⟨S, rfl⟩, hh⟩ =>
(hc2.total R.2 S.2).elim (fun T => ⟨S, ⟨S, rfl⟩, S.1.mul_mem (T hg) hh⟩) fun T =>
⟨R, ⟨R, rfl⟩, R.1.mul_mem hg (T hh)⟩ },
fun ⟨g, _, ⟨S, rfl⟩, hg⟩ => by
refine Exists.imp (fun k hk => ?_) (hc1 S.2 ⟨g, hg⟩)
rwa [Subtype.ext_iff, coe_pow] at hk ⊢, fun M hM _ hg => ⟨M, ⟨⟨M, hM⟩, rfl⟩, hg⟩⟩)
P hP)
fun {Q} h => ⟨⟨Q, h.2.prop, h.2.eq_of_ge⟩, h.1⟩
namespace Sylow
instance nonempty : Nonempty (Sylow p G) :=
nonempty_of_exists IsPGroup.of_bot.exists_le_sylow
noncomputable instance inhabited : Inhabited (Sylow p G) :=
Classical.inhabited_of_nonempty nonempty
theorem exists_comap_eq_of_ker_isPGroup {H : Type*} [Group H] (P : Sylow p H) {f : H →* G}
(hf : IsPGroup p f.ker) : ∃ Q : Sylow p G, Q.comap f = P :=
Exists.imp (fun Q hQ => P.3 (Q.2.comap_of_ker_isPGroup f hf) (map_le_iff_le_comap.mp hQ))
(P.2.map f).exists_le_sylow
theorem exists_comap_eq_of_injective {H : Type*} [Group H] (P : Sylow p H) {f : H →* G}
(hf : Function.Injective f) : ∃ Q : Sylow p G, Q.comap f = P :=
P.exists_comap_eq_of_ker_isPGroup (IsPGroup.ker_isPGroup_of_injective hf)
theorem exists_comap_subtype_eq {H : Subgroup G} (P : Sylow p H) :
∃ Q : Sylow p G, Q.comap H.subtype = P :=
P.exists_comap_eq_of_injective Subtype.coe_injective
/-- If the kernel of `f : H →* G` is a `p`-group,
then `Finite (Sylow p G)` implies `Finite (Sylow p H)`. -/
theorem finite_of_ker_is_pGroup {H : Type*} [Group H] {f : H →* G}
(hf : IsPGroup p f.ker) [Finite (Sylow p G)] : Finite (Sylow p H) :=
let h_exists := fun P : Sylow p H => P.exists_comap_eq_of_ker_isPGroup hf
let g : Sylow p H → Sylow p G := fun P => Classical.choose (h_exists P)
have hg : ∀ P : Sylow p H, (g P).1.comap f = P := fun P => Classical.choose_spec (h_exists P)
Finite.of_injective g fun P Q h => ext (by rw [← hg, h]; exact (h_exists Q).choose_spec)
/-- If `f : H →* G` is injective, then `Finite (Sylow p G)` implies `Finite (Sylow p H)`. -/
theorem finite_of_injective {H : Type*} [Group H] {f : H →* G}
(hf : Function.Injective f) [Finite (Sylow p G)] : Finite (Sylow p H) :=
finite_of_ker_is_pGroup (IsPGroup.ker_isPGroup_of_injective hf)
/-- If `H` is a subgroup of `G`, then `Finite (Sylow p G)` implies `Finite (Sylow p H)`. -/
instance (H : Subgroup G) [Finite (Sylow p G)] : Finite (Sylow p H) :=
finite_of_injective H.subtype_injective
open Pointwise
/-- `Subgroup.pointwiseMulAction` preserves Sylow subgroups. -/
instance pointwiseMulAction {α : Type*} [Group α] [MulDistribMulAction α G] :
MulAction α (Sylow p G) where
smul g P :=
⟨g • P.toSubgroup, P.2.map _, fun {Q} hQ hS =>
inv_smul_eq_iff.mp
(P.3 (hQ.map _) fun s hs =>
(congr_arg (· ∈ g⁻¹ • Q) (inv_smul_smul g s)).mp
(smul_mem_pointwise_smul (g • s) g⁻¹ Q (hS (smul_mem_pointwise_smul s g P hs))))⟩
one_smul P := ext (one_smul α P.toSubgroup)
mul_smul g h P := ext (mul_smul g h P.toSubgroup)
theorem pointwise_smul_def {α : Type*} [Group α] [MulDistribMulAction α G] {g : α}
{P : Sylow p G} : ↑(g • P) = g • (P : Subgroup G) :=
rfl
instance mulAction : MulAction G (Sylow p G) :=
compHom _ MulAut.conj
theorem smul_def {g : G} {P : Sylow p G} : g • P = MulAut.conj g • P :=
rfl
theorem coe_subgroup_smul {g : G} {P : Sylow p G} :
↑(g • P) = MulAut.conj g • (P : Subgroup G) :=
rfl
theorem coe_smul {g : G} {P : Sylow p G} : ↑(g • P) = MulAut.conj g • (P : Set G) :=
rfl
theorem smul_le {P : Sylow p G} {H : Subgroup G} (hP : P ≤ H) (h : H) : ↑(h • P) ≤ H :=
Subgroup.conj_smul_le_of_le hP h
theorem smul_subtype {P : Sylow p G} {H : Subgroup G} (hP : P ≤ H) (h : H) :
h • P.subtype hP = (h • P).subtype (smul_le hP h) :=
ext (Subgroup.conj_smul_subgroupOf hP h)
theorem smul_eq_iff_mem_normalizer {g : G} {P : Sylow p G} :
g • P = P ↔ g ∈ P.normalizer := by
rw [eq_comm, SetLike.ext_iff, ← inv_mem_iff (G := G) (H := normalizer P.toSubgroup),
mem_normalizer_iff, inv_inv]
exact
forall_congr' fun h =>
iff_congr Iff.rfl
⟨fun ⟨a, b, c⟩ => c ▸ by simpa [mul_assoc] using b,
fun hh => ⟨(MulAut.conj g)⁻¹ h, hh, MulAut.apply_inv_self G (MulAut.conj g) h⟩⟩
theorem smul_eq_of_normal {g : G} {P : Sylow p G} [h : P.Normal] :
g • P = P := by simp only [smul_eq_iff_mem_normalizer, P.normalizer_eq_top, mem_top]
end Sylow
theorem Subgroup.sylow_mem_fixedPoints_iff (H : Subgroup G) {P : Sylow p G} :
P ∈ fixedPoints H (Sylow p G) ↔ H ≤ P.normalizer := by
simp_rw [SetLike.le_def, ← Sylow.smul_eq_iff_mem_normalizer]; exact Subtype.forall
theorem IsPGroup.inf_normalizer_sylow {P : Subgroup G} (hP : IsPGroup p P) (Q : Sylow p G) :
P ⊓ Q.normalizer = P ⊓ Q :=
le_antisymm
(le_inf inf_le_left
(sup_eq_right.mp
(Q.3 (hP.to_inf_left.to_sup_of_normal_right' Q.2 inf_le_right) le_sup_right)))
(inf_le_inf_left P le_normalizer)
theorem IsPGroup.sylow_mem_fixedPoints_iff {P : Subgroup G} (hP : IsPGroup p P) {Q : Sylow p G} :
Q ∈ fixedPoints P (Sylow p G) ↔ P ≤ Q := by
rw [P.sylow_mem_fixedPoints_iff, ← inf_eq_left, hP.inf_normalizer_sylow, inf_eq_left]
/-- A generalization of **Sylow's second theorem**.
If the number of Sylow `p`-subgroups is finite, then all Sylow `p`-subgroups are conjugate. -/
instance Sylow.isPretransitive_of_finite [hp : Fact p.Prime] [Finite (Sylow p G)] :
IsPretransitive G (Sylow p G) :=
⟨fun P Q => by
classical
have H := fun {R : Sylow p G} {S : orbit G P} =>
calc
S ∈ fixedPoints R (orbit G P) ↔ S.1 ∈ fixedPoints R (Sylow p G) :=
forall_congr' fun a => Subtype.ext_iff
_ ↔ R.1 ≤ S := R.2.sylow_mem_fixedPoints_iff
_ ↔ S.1.1 = R := ⟨fun h => R.3 S.1.2 h, ge_of_eq⟩
suffices Set.Nonempty (fixedPoints Q (orbit G P)) by
exact Exists.elim this fun R hR => by
rw [← Sylow.ext (H.mp hR)]
exact R.2
apply Q.2.nonempty_fixed_point_of_prime_not_dvd_card
refine fun h => hp.out.not_dvd_one (Nat.modEq_zero_iff_dvd.mp ?_)
calc
1 = Nat.card (fixedPoints P (orbit G P)) := ?_
_ ≡ Nat.card (orbit G P) [MOD p] := (P.2.card_modEq_card_fixedPoints (orbit G P)).symm
_ ≡ 0 [MOD p] := Nat.modEq_zero_iff_dvd.mpr h
rw [← Nat.card_unique (α := ({⟨P, mem_orbit_self P⟩} : Set (orbit G P))), eq_comm]
congr
rw [Set.eq_singleton_iff_unique_mem]
exact ⟨H.mpr rfl, fun R h => Subtype.ext (Sylow.ext (H.mp h))⟩⟩
variable (p) (G)
/-- A generalization of **Sylow's third theorem**.
If the number of Sylow `p`-subgroups is finite, then it is congruent to `1` modulo `p`. -/
theorem card_sylow_modEq_one [Fact p.Prime] [Finite (Sylow p G)] :
Nat.card (Sylow p G) ≡ 1 [MOD p] := by
refine Sylow.nonempty.elim fun P : Sylow p G => ?_
have : fixedPoints P.1 (Sylow p G) = {P} :=
Set.ext fun Q : Sylow p G =>
calc
Q ∈ fixedPoints P (Sylow p G) ↔ P.1 ≤ Q := P.2.sylow_mem_fixedPoints_iff
_ ↔ Q.1 = P.1 := ⟨P.3 Q.2, ge_of_eq⟩
_ ↔ Q ∈ {P} := Sylow.ext_iff.symm.trans Set.mem_singleton_iff.symm
have : Nat.card (fixedPoints P.1 (Sylow p G)) = 1 := by simp [this]
exact (P.2.card_modEq_card_fixedPoints (Sylow p G)).trans (by rw [this])
theorem not_dvd_card_sylow [hp : Fact p.Prime] [Finite (Sylow p G)] : ¬p ∣ Nat.card (Sylow p G) :=
fun h =>
hp.1.ne_one
(Nat.dvd_one.mp
((Nat.modEq_iff_dvd' zero_le_one).mp
| ((Nat.modEq_zero_iff_dvd.mpr h).symm.trans (card_sylow_modEq_one p G))))
variable {p} {G}
namespace Sylow
/-- Sylow subgroups are isomorphic -/
nonrec def equivSMul (P : Sylow p G) (g : G) : P ≃* (g • P : Sylow p G) :=
equivSMul (MulAut.conj g) P.toSubgroup
/-- Sylow subgroups are isomorphic -/
noncomputable def equiv [Fact p.Prime] [Finite (Sylow p G)] (P Q : Sylow p G) : P ≃* Q := by
rw [← Classical.choose_spec (exists_smul_eq G P Q)]
exact P.equivSMul (Classical.choose (exists_smul_eq G P Q))
| Mathlib/GroupTheory/Sylow.lean | 325 | 339 |
/-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Abhimanyu Pallavi Sudhir
-/
import Mathlib.Algebra.CharP.Defs
import Mathlib.Algebra.Order.CauSeq.BigOperators
import Mathlib.Algebra.Order.Star.Basic
import Mathlib.Data.Complex.BigOperators
import Mathlib.Data.Complex.Norm
import Mathlib.Data.Nat.Choose.Sum
/-!
# Exponential Function
This file contains the definitions of the real and complex exponential function.
## Main definitions
* `Complex.exp`: The complex exponential function, defined via its Taylor series
* `Real.exp`: The real exponential function, defined as the real part of the complex exponential
-/
open CauSeq Finset IsAbsoluteValue
open scoped ComplexConjugate
namespace Complex
theorem isCauSeq_norm_exp (z : ℂ) :
IsCauSeq abs fun n => ∑ m ∈ range n, ‖z ^ m / m.factorial‖ :=
let ⟨n, hn⟩ := exists_nat_gt ‖z‖
have hn0 : (0 : ℝ) < n := lt_of_le_of_lt (norm_nonneg _) hn
IsCauSeq.series_ratio_test n (‖z‖ / n) (div_nonneg (norm_nonneg _) (le_of_lt hn0))
(by rwa [div_lt_iff₀ hn0, one_mul]) fun m hm => by
rw [abs_norm, abs_norm, Nat.factorial_succ, pow_succ', mul_comm m.succ, Nat.cast_mul,
← div_div, mul_div_assoc, mul_div_right_comm, Complex.norm_mul, Complex.norm_div,
norm_natCast]
gcongr
exact le_trans hm (Nat.le_succ _)
@[deprecated (since := "2025-02-16")] alias isCauSeq_abs_exp := isCauSeq_norm_exp
noncomputable section
theorem isCauSeq_exp (z : ℂ) : IsCauSeq (‖·‖) fun n => ∑ m ∈ range n, z ^ m / m.factorial :=
(isCauSeq_norm_exp z).of_abv
/-- The Cauchy sequence consisting of partial sums of the Taylor series of
the complex exponential function -/
@[pp_nodot]
def exp' (z : ℂ) : CauSeq ℂ (‖·‖) :=
⟨fun n => ∑ m ∈ range n, z ^ m / m.factorial, isCauSeq_exp z⟩
/-- The complex exponential function, defined via its Taylor series -/
@[pp_nodot]
def exp (z : ℂ) : ℂ :=
CauSeq.lim (exp' z)
/-- scoped notation for the complex exponential function -/
scoped notation "cexp" => Complex.exp
end
end Complex
namespace Real
open Complex
noncomputable section
/-- The real exponential function, defined as the real part of the complex exponential -/
@[pp_nodot]
nonrec def exp (x : ℝ) : ℝ :=
(exp x).re
/-- scoped notation for the real exponential function -/
scoped notation "rexp" => Real.exp
end
end Real
namespace Complex
variable (x y : ℂ)
@[simp]
theorem exp_zero : exp 0 = 1 := by
rw [exp]
refine lim_eq_of_equiv_const fun ε ε0 => ⟨1, fun j hj => ?_⟩
convert (config := .unfoldSameFun) ε0 -- ε0 : ε > 0 but goal is _ < ε
rcases j with - | j
· exact absurd hj (not_le_of_gt zero_lt_one)
· dsimp [exp']
induction' j with j ih
· dsimp [exp']; simp [show Nat.succ 0 = 1 from rfl]
· rw [← ih (by simp [Nat.succ_le_succ])]
simp only [sum_range_succ, pow_succ]
simp
theorem exp_add : exp (x + y) = exp x * exp y := by
have hj : ∀ j : ℕ, (∑ m ∈ range j, (x + y) ^ m / m.factorial) =
∑ i ∈ range j, ∑ k ∈ range (i + 1), x ^ k / k.factorial *
(y ^ (i - k) / (i - k).factorial) := by
intro j
refine Finset.sum_congr rfl fun m _ => ?_
rw [add_pow, div_eq_mul_inv, sum_mul]
refine Finset.sum_congr rfl fun I hi => ?_
have h₁ : (m.choose I : ℂ) ≠ 0 :=
Nat.cast_ne_zero.2 (pos_iff_ne_zero.1 (Nat.choose_pos (Nat.le_of_lt_succ (mem_range.1 hi))))
have h₂ := Nat.choose_mul_factorial_mul_factorial (Nat.le_of_lt_succ <| Finset.mem_range.1 hi)
rw [← h₂, Nat.cast_mul, Nat.cast_mul, mul_inv, mul_inv]
simp only [mul_left_comm (m.choose I : ℂ), mul_assoc, mul_left_comm (m.choose I : ℂ)⁻¹,
mul_comm (m.choose I : ℂ)]
rw [inv_mul_cancel₀ h₁]
simp [div_eq_mul_inv, mul_comm, mul_assoc, mul_left_comm]
simp_rw [exp, exp', lim_mul_lim]
apply (lim_eq_lim_of_equiv _).symm
simp only [hj]
exact cauchy_product (isCauSeq_norm_exp x) (isCauSeq_exp y)
/-- the exponential function as a monoid hom from `Multiplicative ℂ` to `ℂ` -/
@[simps]
noncomputable def expMonoidHom : MonoidHom (Multiplicative ℂ) ℂ :=
{ toFun := fun z => exp z.toAdd,
map_one' := by simp,
map_mul' := by simp [exp_add] }
theorem exp_list_sum (l : List ℂ) : exp l.sum = (l.map exp).prod :=
map_list_prod (M := Multiplicative ℂ) expMonoidHom l
theorem exp_multiset_sum (s : Multiset ℂ) : exp s.sum = (s.map exp).prod :=
@MonoidHom.map_multiset_prod (Multiplicative ℂ) ℂ _ _ expMonoidHom s
theorem exp_sum {α : Type*} (s : Finset α) (f : α → ℂ) :
exp (∑ x ∈ s, f x) = ∏ x ∈ s, exp (f x) :=
map_prod (β := Multiplicative ℂ) expMonoidHom f s
lemma exp_nsmul (x : ℂ) (n : ℕ) : exp (n • x) = exp x ^ n :=
@MonoidHom.map_pow (Multiplicative ℂ) ℂ _ _ expMonoidHom _ _
theorem exp_nat_mul (x : ℂ) : ∀ n : ℕ, exp (n * x) = exp x ^ n
| 0 => by rw [Nat.cast_zero, zero_mul, exp_zero, pow_zero]
| Nat.succ n => by rw [pow_succ, Nat.cast_add_one, add_mul, exp_add, ← exp_nat_mul _ n, one_mul]
@[simp]
theorem exp_ne_zero : exp x ≠ 0 := fun h =>
zero_ne_one (α := ℂ) <| by rw [← exp_zero, ← add_neg_cancel x, exp_add, h]; simp
theorem exp_neg : exp (-x) = (exp x)⁻¹ := by
rw [← mul_right_inj' (exp_ne_zero x), ← exp_add]; simp [mul_inv_cancel₀ (exp_ne_zero x)]
theorem exp_sub : exp (x - y) = exp x / exp y := by
simp [sub_eq_add_neg, exp_add, exp_neg, div_eq_mul_inv]
theorem exp_int_mul (z : ℂ) (n : ℤ) : Complex.exp (n * z) = Complex.exp z ^ n := by
cases n
· simp [exp_nat_mul]
· simp [exp_add, add_mul, pow_add, exp_neg, exp_nat_mul]
@[simp]
theorem exp_conj : exp (conj x) = conj (exp x) := by
dsimp [exp]
rw [← lim_conj]
refine congr_arg CauSeq.lim (CauSeq.ext fun _ => ?_)
dsimp [exp', Function.comp_def, cauSeqConj]
rw [map_sum (starRingEnd _)]
refine sum_congr rfl fun n _ => ?_
rw [map_div₀, map_pow, ← ofReal_natCast, conj_ofReal]
@[simp]
theorem ofReal_exp_ofReal_re (x : ℝ) : ((exp x).re : ℂ) = exp x :=
conj_eq_iff_re.1 <| by rw [← exp_conj, conj_ofReal]
@[simp, norm_cast]
theorem ofReal_exp (x : ℝ) : (Real.exp x : ℂ) = exp x :=
ofReal_exp_ofReal_re _
@[simp]
theorem exp_ofReal_im (x : ℝ) : (exp x).im = 0 := by rw [← ofReal_exp_ofReal_re, ofReal_im]
theorem exp_ofReal_re (x : ℝ) : (exp x).re = Real.exp x :=
rfl
end Complex
namespace Real
open Complex
variable (x y : ℝ)
@[simp]
theorem exp_zero : exp 0 = 1 := by simp [Real.exp]
nonrec theorem exp_add : exp (x + y) = exp x * exp y := by simp [exp_add, exp]
/-- the exponential function as a monoid hom from `Multiplicative ℝ` to `ℝ` -/
@[simps]
noncomputable def expMonoidHom : MonoidHom (Multiplicative ℝ) ℝ :=
{ toFun := fun x => exp x.toAdd,
map_one' := by simp,
map_mul' := by simp [exp_add] }
theorem exp_list_sum (l : List ℝ) : exp l.sum = (l.map exp).prod :=
map_list_prod (M := Multiplicative ℝ) expMonoidHom l
theorem exp_multiset_sum (s : Multiset ℝ) : exp s.sum = (s.map exp).prod :=
@MonoidHom.map_multiset_prod (Multiplicative ℝ) ℝ _ _ expMonoidHom s
theorem exp_sum {α : Type*} (s : Finset α) (f : α → ℝ) :
exp (∑ x ∈ s, f x) = ∏ x ∈ s, exp (f x) :=
map_prod (β := Multiplicative ℝ) expMonoidHom f s
lemma exp_nsmul (x : ℝ) (n : ℕ) : exp (n • x) = exp x ^ n :=
@MonoidHom.map_pow (Multiplicative ℝ) ℝ _ _ expMonoidHom _ _
nonrec theorem exp_nat_mul (x : ℝ) (n : ℕ) : exp (n * x) = exp x ^ n :=
ofReal_injective (by simp [exp_nat_mul])
@[simp]
nonrec theorem exp_ne_zero : exp x ≠ 0 := fun h =>
exp_ne_zero x <| by rw [exp, ← ofReal_inj] at h; simp_all
nonrec theorem exp_neg : exp (-x) = (exp x)⁻¹ :=
ofReal_injective <| by simp [exp_neg]
theorem exp_sub : exp (x - y) = exp x / exp y := by
simp [sub_eq_add_neg, exp_add, exp_neg, div_eq_mul_inv]
open IsAbsoluteValue Nat
theorem sum_le_exp_of_nonneg {x : ℝ} (hx : 0 ≤ x) (n : ℕ) : ∑ i ∈ range n, x ^ i / i ! ≤ exp x :=
calc
∑ i ∈ range n, x ^ i / i ! ≤ lim (⟨_, isCauSeq_re (exp' x)⟩ : CauSeq ℝ abs) := by
refine le_lim (CauSeq.le_of_exists ⟨n, fun j hj => ?_⟩)
simp only [exp', const_apply, re_sum]
norm_cast
refine sum_le_sum_of_subset_of_nonneg (range_mono hj) fun _ _ _ ↦ ?_
positivity
_ = exp x := by rw [exp, Complex.exp, ← cauSeqRe, lim_re]
lemma pow_div_factorial_le_exp (hx : 0 ≤ x) (n : ℕ) : x ^ n / n ! ≤ exp x :=
calc
x ^ n / n ! ≤ ∑ k ∈ range (n + 1), x ^ k / k ! :=
single_le_sum (f := fun k ↦ x ^ k / k !) (fun k _ ↦ by positivity) (self_mem_range_succ n)
_ ≤ exp x := sum_le_exp_of_nonneg hx _
theorem quadratic_le_exp_of_nonneg {x : ℝ} (hx : 0 ≤ x) : 1 + x + x ^ 2 / 2 ≤ exp x :=
calc
1 + x + x ^ 2 / 2 = ∑ i ∈ range 3, x ^ i / i ! := by
simp only [sum_range_succ, range_one, sum_singleton, _root_.pow_zero, factorial, cast_one,
ne_eq, one_ne_zero, not_false_eq_true, div_self, pow_one, mul_one, div_one, Nat.mul_one,
cast_succ, add_right_inj]
ring_nf
_ ≤ exp x := sum_le_exp_of_nonneg hx 3
private theorem add_one_lt_exp_of_pos {x : ℝ} (hx : 0 < x) : x + 1 < exp x :=
(by nlinarith : x + 1 < 1 + x + x ^ 2 / 2).trans_le (quadratic_le_exp_of_nonneg hx.le)
private theorem add_one_le_exp_of_nonneg {x : ℝ} (hx : 0 ≤ x) : x + 1 ≤ exp x := by
rcases eq_or_lt_of_le hx with (rfl | h)
· simp
exact (add_one_lt_exp_of_pos h).le
theorem one_le_exp {x : ℝ} (hx : 0 ≤ x) : 1 ≤ exp x := by linarith [add_one_le_exp_of_nonneg hx]
@[bound]
theorem exp_pos (x : ℝ) : 0 < exp x :=
(le_total 0 x).elim (lt_of_lt_of_le zero_lt_one ∘ one_le_exp) fun h => by
rw [← neg_neg x, Real.exp_neg]
exact inv_pos.2 (lt_of_lt_of_le zero_lt_one (one_le_exp (neg_nonneg.2 h)))
@[bound]
lemma exp_nonneg (x : ℝ) : 0 ≤ exp x := x.exp_pos.le
@[simp]
theorem abs_exp (x : ℝ) : |exp x| = exp x :=
abs_of_pos (exp_pos _)
lemma exp_abs_le (x : ℝ) : exp |x| ≤ exp x + exp (-x) := by
cases le_total x 0 <;> simp [abs_of_nonpos, abs_of_nonneg, exp_nonneg, *]
@[mono]
theorem exp_strictMono : StrictMono exp := fun x y h => by
rw [← sub_add_cancel y x, Real.exp_add]
exact (lt_mul_iff_one_lt_left (exp_pos _)).2
(lt_of_lt_of_le (by linarith) (add_one_le_exp_of_nonneg (by linarith)))
@[gcongr]
theorem exp_lt_exp_of_lt {x y : ℝ} (h : x < y) : exp x < exp y := exp_strictMono h
@[mono]
theorem exp_monotone : Monotone exp :=
exp_strictMono.monotone
@[gcongr, bound]
theorem exp_le_exp_of_le {x y : ℝ} (h : x ≤ y) : exp x ≤ exp y := exp_monotone h
@[simp]
theorem exp_lt_exp {x y : ℝ} : exp x < exp y ↔ x < y :=
exp_strictMono.lt_iff_lt
@[simp]
theorem exp_le_exp {x y : ℝ} : exp x ≤ exp y ↔ x ≤ y :=
exp_strictMono.le_iff_le
theorem exp_injective : Function.Injective exp :=
exp_strictMono.injective
@[simp]
theorem exp_eq_exp {x y : ℝ} : exp x = exp y ↔ x = y :=
exp_injective.eq_iff
@[simp]
theorem exp_eq_one_iff : exp x = 1 ↔ x = 0 :=
exp_injective.eq_iff' exp_zero
@[simp]
theorem one_lt_exp_iff {x : ℝ} : 1 < exp x ↔ 0 < x := by rw [← exp_zero, exp_lt_exp]
@[bound] private alias ⟨_, Bound.one_lt_exp_of_pos⟩ := one_lt_exp_iff
@[simp]
theorem exp_lt_one_iff {x : ℝ} : exp x < 1 ↔ x < 0 := by rw [← exp_zero, exp_lt_exp]
@[simp]
theorem exp_le_one_iff {x : ℝ} : exp x ≤ 1 ↔ x ≤ 0 :=
exp_zero ▸ exp_le_exp
@[simp]
theorem one_le_exp_iff {x : ℝ} : 1 ≤ exp x ↔ 0 ≤ x :=
exp_zero ▸ exp_le_exp
end Real
namespace Complex
theorem sum_div_factorial_le {α : Type*} [Field α] [LinearOrder α] [IsStrictOrderedRing α]
(n j : ℕ) (hn : 0 < n) :
(∑ m ∈ range j with n ≤ m, (1 / m.factorial : α)) ≤ n.succ / (n.factorial * n) :=
calc
(∑ m ∈ range j with n ≤ m, (1 / m.factorial : α)) =
∑ m ∈ range (j - n), (1 / ((m + n).factorial : α)) := by
refine sum_nbij' (· - n) (· + n) ?_ ?_ ?_ ?_ ?_ <;>
simp +contextual [lt_tsub_iff_right, tsub_add_cancel_of_le]
_ ≤ ∑ m ∈ range (j - n), ((n.factorial : α) * (n.succ : α) ^ m)⁻¹ := by
simp_rw [one_div]
gcongr
rw [← Nat.cast_pow, ← Nat.cast_mul, Nat.cast_le, add_comm]
exact Nat.factorial_mul_pow_le_factorial
_ = (n.factorial : α)⁻¹ * ∑ m ∈ range (j - n), (n.succ : α)⁻¹ ^ m := by
simp [mul_inv, ← mul_sum, ← sum_mul, mul_comm, inv_pow]
_ = ((n.succ : α) - n.succ * (n.succ : α)⁻¹ ^ (j - n)) / (n.factorial * n) := by
have h₁ : (n.succ : α) ≠ 1 :=
@Nat.cast_one α _ ▸ mt Nat.cast_inj.1 (mt Nat.succ.inj (pos_iff_ne_zero.1 hn))
have h₂ : (n.succ : α) ≠ 0 := by positivity
have h₃ : (n.factorial * n : α) ≠ 0 := by positivity
have h₄ : (n.succ - 1 : α) = n := by simp
rw [geom_sum_inv h₁ h₂, eq_div_iff_mul_eq h₃, mul_comm _ (n.factorial * n : α),
← mul_assoc (n.factorial⁻¹ : α), ← mul_inv_rev, h₄, ← mul_assoc (n.factorial * n : α),
mul_comm (n : α) n.factorial, mul_inv_cancel₀ h₃, one_mul, mul_comm]
_ ≤ n.succ / (n.factorial * n : α) := by gcongr; apply sub_le_self; positivity
theorem exp_bound {x : ℂ} (hx : ‖x‖ ≤ 1) {n : ℕ} (hn : 0 < n) :
‖exp x - ∑ m ∈ range n, x ^ m / m.factorial‖ ≤
‖x‖ ^ n * ((n.succ : ℝ) * (n.factorial * n : ℝ)⁻¹) := by
rw [← lim_const (abv := norm) (∑ m ∈ range n, _), exp, sub_eq_add_neg,
← lim_neg, lim_add, ← lim_norm]
refine lim_le (CauSeq.le_of_exists ⟨n, fun j hj => ?_⟩)
simp_rw [← sub_eq_add_neg]
show
‖(∑ m ∈ range j, x ^ m / m.factorial) - ∑ m ∈ range n, x ^ m / m.factorial‖ ≤
‖x‖ ^ n * ((n.succ : ℝ) * (n.factorial * n : ℝ)⁻¹)
rw [sum_range_sub_sum_range hj]
calc
‖∑ m ∈ range j with n ≤ m, (x ^ m / m.factorial : ℂ)‖
= ‖∑ m ∈ range j with n ≤ m, (x ^ n * (x ^ (m - n) / m.factorial) : ℂ)‖ := by
refine congr_arg norm (sum_congr rfl fun m hm => ?_)
rw [mem_filter, mem_range] at hm
rw [← mul_div_assoc, ← pow_add, add_tsub_cancel_of_le hm.2]
_ ≤ ∑ m ∈ range j with n ≤ m, ‖x ^ n * (x ^ (m - n) / m.factorial)‖ :=
IsAbsoluteValue.abv_sum norm ..
_ ≤ ∑ m ∈ range j with n ≤ m, ‖x‖ ^ n * (1 / m.factorial) := by
simp_rw [Complex.norm_mul, Complex.norm_pow, Complex.norm_div, norm_natCast]
gcongr
rw [Complex.norm_pow]
exact pow_le_one₀ (norm_nonneg _) hx
_ = ‖x‖ ^ n * ∑ m ∈ range j with n ≤ m, (1 / m.factorial : ℝ) := by
simp [abs_mul, abv_pow abs, abs_div, ← mul_sum]
_ ≤ ‖x‖ ^ n * (n.succ * (n.factorial * n : ℝ)⁻¹) := by
gcongr
exact sum_div_factorial_le _ _ hn
theorem exp_bound' {x : ℂ} {n : ℕ} (hx : ‖x‖ / n.succ ≤ 1 / 2) :
‖exp x - ∑ m ∈ range n, x ^ m / m.factorial‖ ≤ ‖x‖ ^ n / n.factorial * 2 := by
rw [← lim_const (abv := norm) (∑ m ∈ range n, _),
exp, sub_eq_add_neg, ← lim_neg, lim_add, ← lim_norm]
refine lim_le (CauSeq.le_of_exists ⟨n, fun j hj => ?_⟩)
simp_rw [← sub_eq_add_neg]
show ‖(∑ m ∈ range j, x ^ m / m.factorial) - ∑ m ∈ range n, x ^ m / m.factorial‖ ≤
‖x‖ ^ n / n.factorial * 2
let k := j - n
have hj : j = n + k := (add_tsub_cancel_of_le hj).symm
rw [hj, sum_range_add_sub_sum_range]
calc
‖∑ i ∈ range k, x ^ (n + i) / ((n + i).factorial : ℂ)‖ ≤
∑ i ∈ range k, ‖x ^ (n + i) / ((n + i).factorial : ℂ)‖ :=
IsAbsoluteValue.abv_sum _ _ _
_ ≤ ∑ i ∈ range k, ‖x‖ ^ (n + i) / (n + i).factorial := by
simp [norm_natCast, Complex.norm_pow]
_ ≤ ∑ i ∈ range k, ‖x‖ ^ (n + i) / ((n.factorial : ℝ) * (n.succ : ℝ) ^ i) := ?_
_ = ∑ i ∈ range k, ‖x‖ ^ n / n.factorial * (‖x‖ ^ i / (n.succ : ℝ) ^ i) := ?_
_ ≤ ‖x‖ ^ n / ↑n.factorial * 2 := ?_
· gcongr
exact mod_cast Nat.factorial_mul_pow_le_factorial
· refine Finset.sum_congr rfl fun _ _ => ?_
simp only [pow_add, div_eq_inv_mul, mul_inv, mul_left_comm, mul_assoc]
· rw [← mul_sum]
gcongr
simp_rw [← div_pow]
rw [geom_sum_eq, div_le_iff_of_neg]
· trans (-1 : ℝ)
· linarith
· simp only [neg_le_sub_iff_le_add, div_pow, Nat.cast_succ, le_add_iff_nonneg_left]
positivity
· linarith
· linarith
theorem norm_exp_sub_one_le {x : ℂ} (hx : ‖x‖ ≤ 1) : ‖exp x - 1‖ ≤ 2 * ‖x‖ :=
calc
‖exp x - 1‖ = ‖exp x - ∑ m ∈ range 1, x ^ m / m.factorial‖ := by simp [sum_range_succ]
_ ≤ ‖x‖ ^ 1 * ((Nat.succ 1 : ℝ) * ((Nat.factorial 1) * (1 : ℕ) : ℝ)⁻¹) :=
(exp_bound hx (by decide))
_ = 2 * ‖x‖ := by simp [two_mul, mul_two, mul_add, mul_comm, add_mul, Nat.factorial]
theorem norm_exp_sub_one_sub_id_le {x : ℂ} (hx : ‖x‖ ≤ 1) : ‖exp x - 1 - x‖ ≤ ‖x‖ ^ 2 :=
calc
‖exp x - 1 - x‖ = ‖exp x - ∑ m ∈ range 2, x ^ m / m.factorial‖ := by
simp [sub_eq_add_neg, sum_range_succ_comm, add_assoc, Nat.factorial]
_ ≤ ‖x‖ ^ 2 * ((Nat.succ 2 : ℝ) * (Nat.factorial 2 * (2 : ℕ) : ℝ)⁻¹) :=
(exp_bound hx (by decide))
_ ≤ ‖x‖ ^ 2 * 1 := by gcongr; norm_num [Nat.factorial]
_ = ‖x‖ ^ 2 := by rw [mul_one]
lemma norm_exp_sub_sum_le_exp_norm_sub_sum (x : ℂ) (n : ℕ) :
‖exp x - ∑ m ∈ range n, x ^ m / m.factorial‖
≤ Real.exp ‖x‖ - ∑ m ∈ range n, ‖x‖ ^ m / m.factorial := by
rw [← CauSeq.lim_const (abv := norm) (∑ m ∈ range n, _), Complex.exp, sub_eq_add_neg,
← CauSeq.lim_neg, CauSeq.lim_add, ← lim_norm]
refine CauSeq.lim_le (CauSeq.le_of_exists ⟨n, fun j hj => ?_⟩)
simp_rw [← sub_eq_add_neg]
calc ‖(∑ m ∈ range j, x ^ m / m.factorial) - ∑ m ∈ range n, x ^ m / m.factorial‖
_ ≤ (∑ m ∈ range j, ‖x‖ ^ m / m.factorial) - ∑ m ∈ range n, ‖x‖ ^ m / m.factorial := by
rw [sum_range_sub_sum_range hj, sum_range_sub_sum_range hj]
refine (IsAbsoluteValue.abv_sum norm ..).trans_eq ?_
congr with i
simp [Complex.norm_pow]
_ ≤ Real.exp ‖x‖ - ∑ m ∈ range n, ‖x‖ ^ m / m.factorial := by
gcongr
exact Real.sum_le_exp_of_nonneg (norm_nonneg _) _
lemma norm_exp_le_exp_norm (x : ℂ) : ‖exp x‖ ≤ Real.exp ‖x‖ := by
convert norm_exp_sub_sum_le_exp_norm_sub_sum x 0 using 1 <;> simp
lemma norm_exp_sub_sum_le_norm_mul_exp (x : ℂ) (n : ℕ) :
‖exp x - ∑ m ∈ range n, x ^ m / m.factorial‖ ≤ ‖x‖ ^ n * Real.exp ‖x‖ := by
rw [← CauSeq.lim_const (abv := norm) (∑ m ∈ range n, _), Complex.exp, sub_eq_add_neg,
← CauSeq.lim_neg, CauSeq.lim_add, ← lim_norm]
refine CauSeq.lim_le (CauSeq.le_of_exists ⟨n, fun j hj => ?_⟩)
simp_rw [← sub_eq_add_neg]
show ‖(∑ m ∈ range j, x ^ m / m.factorial) - ∑ m ∈ range n, x ^ m / m.factorial‖ ≤ _
rw [sum_range_sub_sum_range hj]
calc
‖∑ m ∈ range j with n ≤ m, (x ^ m / m.factorial : ℂ)‖
= ‖∑ m ∈ range j with n ≤ m, (x ^ n * (x ^ (m - n) / m.factorial) : ℂ)‖ := by
refine congr_arg norm (sum_congr rfl fun m hm => ?_)
rw [mem_filter, mem_range] at hm
rw [← mul_div_assoc, ← pow_add, add_tsub_cancel_of_le hm.2]
_ ≤ ∑ m ∈ range j with n ≤ m, ‖x ^ n * (x ^ (m - n) / m.factorial)‖ :=
IsAbsoluteValue.abv_sum norm ..
_ ≤ ∑ m ∈ range j with n ≤ m, ‖x‖ ^ n * (‖x‖ ^ (m - n) / (m - n).factorial) := by
simp_rw [Complex.norm_mul, Complex.norm_pow, Complex.norm_div, norm_natCast]
gcongr with i hi
· rw [Complex.norm_pow]
· simp
_ = ‖x‖ ^ n * ∑ m ∈ range j with n ≤ m, (‖x‖ ^ (m - n) / (m - n).factorial) := by
rw [← mul_sum]
_ = ‖x‖ ^ n * ∑ m ∈ range (j - n), (‖x‖ ^ m / m.factorial) := by
congr 1
refine (sum_bij (fun m hm ↦ m + n) ?_ ?_ ?_ ?_).symm
· intro a ha
simp only [mem_filter, mem_range, le_add_iff_nonneg_left, zero_le, and_true]
simp only [mem_range] at ha
rwa [← lt_tsub_iff_right]
· intro a ha b hb hab
simpa using hab
· intro b hb
simp only [mem_range, exists_prop]
simp only [mem_filter, mem_range] at hb
refine ⟨b - n, ?_, ?_⟩
· rw [tsub_lt_tsub_iff_right hb.2]
exact hb.1
· rw [tsub_add_cancel_of_le hb.2]
· simp
_ ≤ ‖x‖ ^ n * Real.exp ‖x‖ := by
gcongr
refine Real.sum_le_exp_of_nonneg ?_ _
exact norm_nonneg _
@[deprecated (since := "2025-02-16")] alias abs_exp_sub_one_le := norm_exp_sub_one_le
@[deprecated (since := "2025-02-16")] alias abs_exp_sub_one_sub_id_le := norm_exp_sub_one_sub_id_le
@[deprecated (since := "2025-02-16")] alias abs_exp_sub_sum_le_exp_abs_sub_sum :=
norm_exp_sub_sum_le_exp_norm_sub_sum
@[deprecated (since := "2025-02-16")] alias abs_exp_le_exp_abs := norm_exp_le_exp_norm
@[deprecated (since := "2025-02-16")] alias abs_exp_sub_sum_le_abs_mul_exp :=
norm_exp_sub_sum_le_norm_mul_exp
end Complex
namespace Real
open Complex Finset
nonrec theorem exp_bound {x : ℝ} (hx : |x| ≤ 1) {n : ℕ} (hn : 0 < n) :
|exp x - ∑ m ∈ range n, x ^ m / m.factorial| ≤ |x| ^ n * (n.succ / (n.factorial * n)) := by
have hxc : ‖(x : ℂ)‖ ≤ 1 := mod_cast hx
convert exp_bound hxc hn using 2 <;>
norm_cast
theorem exp_bound' {x : ℝ} (h1 : 0 ≤ x) (h2 : x ≤ 1) {n : ℕ} (hn : 0 < n) :
Real.exp x ≤ (∑ m ∈ Finset.range n, x ^ m / m.factorial) +
x ^ n * (n + 1) / (n.factorial * n) := by
have h3 : |x| = x := by simpa
have h4 : |x| ≤ 1 := by rwa [h3]
have h' := Real.exp_bound h4 hn
rw [h3] at h'
have h'' := (abs_sub_le_iff.1 h').1
have t := sub_le_iff_le_add'.1 h''
simpa [mul_div_assoc] using t
theorem abs_exp_sub_one_le {x : ℝ} (hx : |x| ≤ 1) : |exp x - 1| ≤ 2 * |x| := by
have : ‖(x : ℂ)‖ ≤ 1 := mod_cast hx
exact_mod_cast Complex.norm_exp_sub_one_le (x := x) this
theorem abs_exp_sub_one_sub_id_le {x : ℝ} (hx : |x| ≤ 1) : |exp x - 1 - x| ≤ x ^ 2 := by
rw [← sq_abs]
have : ‖(x : ℂ)‖ ≤ 1 := mod_cast hx
exact_mod_cast Complex.norm_exp_sub_one_sub_id_le this
/-- A finite initial segment of the exponential series, followed by an arbitrary tail.
For fixed `n` this is just a linear map wrt `r`, and each map is a simple linear function
of the previous (see `expNear_succ`), with `expNear n x r ⟶ exp x` as `n ⟶ ∞`,
for any `r`. -/
noncomputable def expNear (n : ℕ) (x r : ℝ) : ℝ :=
(∑ m ∈ range n, x ^ m / m.factorial) + x ^ n / n.factorial * r
@[simp]
theorem expNear_zero (x r) : expNear 0 x r = r := by simp [expNear]
@[simp]
theorem expNear_succ (n x r) : expNear (n + 1) x r = expNear n x (1 + x / (n + 1) * r) := by
simp [expNear, range_succ, mul_add, add_left_comm, add_assoc, pow_succ, div_eq_mul_inv,
mul_inv, Nat.factorial]
ac_rfl
theorem expNear_sub (n x r₁ r₂) : expNear n x r₁ -
expNear n x r₂ = x ^ n / n.factorial * (r₁ - r₂) := by
simp [expNear, mul_sub]
theorem exp_approx_end (n m : ℕ) (x : ℝ) (e₁ : n + 1 = m) (h : |x| ≤ 1) :
|exp x - expNear m x 0| ≤ |x| ^ m / m.factorial * ((m + 1) / m) := by
simp only [expNear, mul_zero, add_zero]
convert exp_bound (n := m) h ?_ using 1
· field_simp [mul_comm]
· omega
theorem exp_approx_succ {n} {x a₁ b₁ : ℝ} (m : ℕ) (e₁ : n + 1 = m) (a₂ b₂ : ℝ)
(e : |1 + x / m * a₂ - a₁| ≤ b₁ - |x| / m * b₂)
(h : |exp x - expNear m x a₂| ≤ |x| ^ m / m.factorial * b₂) :
|exp x - expNear n x a₁| ≤ |x| ^ n / n.factorial * b₁ := by
refine (abs_sub_le _ _ _).trans ((add_le_add_right h _).trans ?_)
subst e₁; rw [expNear_succ, expNear_sub, abs_mul]
convert mul_le_mul_of_nonneg_left (a := |x| ^ n / ↑(Nat.factorial n))
(le_sub_iff_add_le'.1 e) ?_ using 1
· simp [mul_add, pow_succ', div_eq_mul_inv, abs_mul, abs_inv, ← pow_abs, mul_inv, Nat.factorial]
ac_rfl
· simp [div_nonneg, abs_nonneg]
theorem exp_approx_end' {n} {x a b : ℝ} (m : ℕ) (e₁ : n + 1 = m) (rm : ℝ) (er : ↑m = rm)
(h : |x| ≤ 1) (e : |1 - a| ≤ b - |x| / rm * ((rm + 1) / rm)) :
|exp x - expNear n x a| ≤ |x| ^ n / n.factorial * b := by
subst er
exact exp_approx_succ _ e₁ _ _ (by simpa using e) (exp_approx_end _ _ _ e₁ h)
theorem exp_1_approx_succ_eq {n} {a₁ b₁ : ℝ} {m : ℕ} (en : n + 1 = m) {rm : ℝ} (er : ↑m = rm)
(h : |exp 1 - expNear m 1 ((a₁ - 1) * rm)| ≤ |1| ^ m / m.factorial * (b₁ * rm)) :
|exp 1 - expNear n 1 a₁| ≤ |1| ^ n / n.factorial * b₁ := by
subst er
refine exp_approx_succ _ en _ _ ?_ h
field_simp [show (m : ℝ) ≠ 0 by norm_cast; omega]
theorem exp_approx_start (x a b : ℝ) (h : |exp x - expNear 0 x a| ≤ |x| ^ 0 / Nat.factorial 0 * b) :
|exp x - a| ≤ b := by simpa using h
theorem exp_bound_div_one_sub_of_interval' {x : ℝ} (h1 : 0 < x) (h2 : x < 1) :
Real.exp x < 1 / (1 - x) := by
have H : 0 < 1 - (1 + x + x ^ 2) * (1 - x) := calc
0 < x ^ 3 := by positivity
_ = 1 - (1 + x + x ^ 2) * (1 - x) := by ring
calc
exp x ≤ _ := exp_bound' h1.le h2.le zero_lt_three
_ ≤ 1 + x + x ^ 2 := by
-- Porting note: was `norm_num [Finset.sum] <;> nlinarith`
-- This proof should be restored after the norm_num plugin for big operators is ported.
-- (It may also need the positivity extensions in https://github.com/leanprover-community/mathlib4/pull/3907.)
rw [show 3 = 1 + 1 + 1 from rfl]
repeat rw [Finset.sum_range_succ]
norm_num [Nat.factorial]
nlinarith
_ < 1 / (1 - x) := by rw [lt_div_iff₀] <;> nlinarith
theorem exp_bound_div_one_sub_of_interval {x : ℝ} (h1 : 0 ≤ x) (h2 : x < 1) :
Real.exp x ≤ 1 / (1 - x) := by
rcases eq_or_lt_of_le h1 with (rfl | h1)
· simp
· exact (exp_bound_div_one_sub_of_interval' h1 h2).le
theorem add_one_lt_exp {x : ℝ} (hx : x ≠ 0) : x + 1 < Real.exp x := by
obtain hx | hx := hx.symm.lt_or_lt
· exact add_one_lt_exp_of_pos hx
obtain h' | h' := le_or_lt 1 (-x)
· linarith [x.exp_pos]
have hx' : 0 < x + 1 := by linarith
simpa [add_comm, exp_neg, inv_lt_inv₀ (exp_pos _) hx']
using exp_bound_div_one_sub_of_interval' (neg_pos.2 hx) h'
theorem add_one_le_exp (x : ℝ) : x + 1 ≤ Real.exp x := by
obtain rfl | hx := eq_or_ne x 0
· simp
· exact (add_one_lt_exp hx).le
lemma one_sub_lt_exp_neg {x : ℝ} (hx : x ≠ 0) : 1 - x < exp (-x) :=
(sub_eq_neg_add _ _).trans_lt <| add_one_lt_exp <| neg_ne_zero.2 hx
lemma one_sub_le_exp_neg (x : ℝ) : 1 - x ≤ exp (-x) :=
(sub_eq_neg_add _ _).trans_le <| add_one_le_exp _
theorem one_sub_div_pow_le_exp_neg {n : ℕ} {t : ℝ} (ht' : t ≤ n) : (1 - t / n) ^ n ≤ exp (-t) := by
rcases eq_or_ne n 0 with (rfl | hn)
· simp
rwa [Nat.cast_zero] at ht'
calc
(1 - t / n) ^ n ≤ rexp (-(t / n)) ^ n := by
gcongr
· exact sub_nonneg.2 <| div_le_one_of_le₀ ht' n.cast_nonneg
· exact one_sub_le_exp_neg _
_ = rexp (-t) := by rw [← Real.exp_nat_mul, mul_neg, mul_comm, div_mul_cancel₀]; positivity
lemma le_inv_mul_exp (x : ℝ) {c : ℝ} (hc : 0 < c) : x ≤ c⁻¹ * exp (c * x) := by
rw [le_inv_mul_iff₀ hc]
calc c * x
_ ≤ c * x + 1 := le_add_of_nonneg_right zero_le_one
_ ≤ _ := Real.add_one_le_exp (c * x)
end Real
namespace Mathlib.Meta.Positivity
open Lean.Meta Qq
/-- Extension for the `positivity` tactic: `Real.exp` is always positive. -/
@[positivity Real.exp _]
def evalExp : PositivityExt where eval {u α} _ _ e := do
match u, α, e with
| 0, ~q(ℝ), ~q(Real.exp $a) =>
assertInstancesCommute
pure (.positive q(Real.exp_pos $a))
| _, _, _ => throwError "not Real.exp"
end Mathlib.Meta.Positivity
namespace Complex
@[simp]
theorem norm_exp_ofReal (x : ℝ) : ‖exp x‖ = Real.exp x := by
rw [← ofReal_exp]
exact Complex.norm_of_nonneg (le_of_lt (Real.exp_pos _))
@[deprecated (since := "2025-02-16")] alias abs_exp_ofReal := norm_exp_ofReal
end Complex
| Mathlib/Data/Complex/Exponential.lean | 1,686 | 1,696 | |
/-
Copyright (c) 2018 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl
-/
import Mathlib.Data.Multiset.Bind
/-!
# The cartesian product of multisets
## Main definitions
* `Multiset.pi`: Cartesian product of multisets indexed by a multiset.
-/
namespace Multiset
section Pi
open Function
namespace Pi
variable {α : Type*} [DecidableEq α] {δ : α → Sort*}
/-- Given `δ : α → Sort*`, `Pi.empty δ` is the trivial dependent function out of the empty
multiset. -/
def empty (δ : α → Sort*) : ∀ a ∈ (0 : Multiset α), δ a :=
nofun
variable (m : Multiset α) (a : α)
/-- Given `δ : α → Sort*`, a multiset `m` and a term `a`, as well as a term `b : δ a` and a
function `f` such that `f a' : δ a'` for all `a'` in `m`, `Pi.cons m a b f` is a function `g` such
that `g a'' : δ a''` for all `a''` in `a ::ₘ m`. -/
def cons (b : δ a) (f : ∀ a ∈ m, δ a) : ∀ a' ∈ a ::ₘ m, δ a' :=
fun a' ha' => if h : a' = a then Eq.ndrec b h.symm else f a' <| (mem_cons.1 ha').resolve_left h
variable {m a}
theorem cons_same {b : δ a} {f : ∀ a ∈ m, δ a} (h : a ∈ a ::ₘ m) :
cons m a b f a h = b :=
dif_pos rfl
theorem cons_ne {a a' : α} {b : δ a} {f : ∀ a ∈ m, δ a} (h' : a' ∈ a ::ₘ m)
(h : a' ≠ a) : Pi.cons m a b f a' h' = f a' ((mem_cons.1 h').resolve_left h) :=
dif_neg h
theorem cons_swap {a a' : α} {b : δ a} {b' : δ a'} {m : Multiset α} {f : ∀ a ∈ m, δ a}
(h : a ≠ a') : HEq (Pi.cons (a' ::ₘ m) a b (Pi.cons m a' b' f))
(Pi.cons (a ::ₘ m) a' b' (Pi.cons m a b f)) := by
apply hfunext rfl
simp only [heq_iff_eq]
rintro a'' _ rfl
refine hfunext (by rw [Multiset.cons_swap]) fun ha₁ ha₂ _ => ?_
rcases Decidable.ne_or_eq a'' a with (h₁ | rfl)
on_goal 1 => rcases Decidable.eq_or_ne a'' a' with (rfl | h₂)
all_goals simp [*, Pi.cons_same, Pi.cons_ne]
@[simp]
theorem cons_eta {m : Multiset α} {a : α} (f : ∀ a' ∈ a ::ₘ m, δ a') :
(cons m a (f _ (mem_cons_self _ _)) fun a' ha' => f a' (mem_cons_of_mem ha')) = f := by
ext a' h'
by_cases h : a' = a
· subst h
rw [Pi.cons_same]
· rw [Pi.cons_ne _ h]
theorem cons_map (b : δ a) (f : ∀ a' ∈ m, δ a')
{δ' : α → Sort*} (φ : ∀ ⦃a'⦄, δ a' → δ' a') :
Pi.cons _ _ (φ b) (fun a' ha' ↦ φ (f a' ha')) = (fun a' ha' ↦ φ ((cons _ _ b f) a' ha')) := by
ext a' ha'
refine (congrArg₂ _ ?_ rfl).trans (apply_dite (@φ _) (a' = a) _ _).symm
ext rfl
rfl
theorem forall_rel_cons_ext {r : ∀ ⦃a⦄, δ a → δ a → Prop} {b₁ b₂ : δ a} {f₁ f₂ : ∀ a' ∈ m, δ a'}
(hb : r b₁ b₂) (hf : ∀ (a : α) (ha : a ∈ m), r (f₁ a ha) (f₂ a ha)) :
∀ a ha, r (cons _ _ b₁ f₁ a ha) (cons _ _ b₂ f₂ a ha) := by
intro a ha
dsimp [cons]
split_ifs with H
· cases H
exact hb
· exact hf _ _
theorem cons_injective {a : α} {b : δ a} {s : Multiset α} (hs : a ∉ s) :
Function.Injective (Pi.cons s a b) := fun f₁ f₂ eq =>
funext fun a' =>
funext fun h' =>
have ne : a ≠ a' := fun h => hs <| h.symm ▸ h'
have : a' ∈ a ::ₘ s := mem_cons_of_mem h'
calc
f₁ a' h' = Pi.cons s a b f₁ a' this := by rw [Pi.cons_ne this ne.symm]
_ = Pi.cons s a b f₂ a' this := by rw [eq]
_ = f₂ a' h' := by rw [Pi.cons_ne this ne.symm]
end Pi
section
variable {α : Type*} [DecidableEq α] {β : α → Type*}
/-- `pi m t` constructs the Cartesian product over `t` indexed by `m`. -/
def pi (m : Multiset α) (t : ∀ a, Multiset (β a)) : Multiset (∀ a ∈ m, β a) :=
m.recOn {Pi.empty β}
(fun a m (p : Multiset (∀ a ∈ m, β a)) => (t a).bind fun b => p.map <| Pi.cons m a b)
(by
intro a a' m n
by_cases eq : a = a'
· subst eq; rfl
· simp only [map_bind, map_map, comp_apply, bind_bind (t a') (t a)]
apply bind_hcongr
· rw [cons_swap a a']
intro b _
apply bind_hcongr
· rw [cons_swap a a']
intro b' _
apply map_hcongr
· rw [cons_swap a a']
| intro f _
exact Pi.cons_swap eq)
@[simp]
theorem pi_zero (t : ∀ a, Multiset (β a)) : pi 0 t = {Pi.empty β} :=
rfl
@[simp]
theorem pi_cons (m : Multiset α) (t : ∀ a, Multiset (β a)) (a : α) :
pi (a ::ₘ m) t = (t a).bind fun b => (pi m t).map <| Pi.cons m a b :=
recOn_cons a m
theorem card_pi (m : Multiset α) (t : ∀ a, Multiset (β a)) :
card (pi m t) = prod (m.map fun a => card (t a)) :=
Multiset.induction_on m (by simp) (by simp +contextual [mul_comm])
protected theorem Nodup.pi {s : Multiset α} {t : ∀ a, Multiset (β a)} :
| Mathlib/Data/Multiset/Pi.lean | 120 | 136 |
/-
Copyright (c) 2019 Kenny Lau. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kenny Lau
-/
import Mathlib.Algebra.CharP.Defs
import Mathlib.Algebra.GeomSum
import Mathlib.Algebra.MvPolynomial.CommRing
import Mathlib.Algebra.MvPolynomial.Equiv
import Mathlib.Algebra.Polynomial.BigOperators
import Mathlib.RingTheory.Noetherian.Basic
/-!
# Ring-theoretic supplement of Algebra.Polynomial.
## Main results
* `MvPolynomial.isDomain`:
If a ring is an integral domain, then so is its polynomial ring over finitely many variables.
* `Polynomial.isNoetherianRing`:
Hilbert basis theorem, that if a ring is noetherian then so is its polynomial ring.
-/
noncomputable section
open Polynomial
open Finset
universe u v w
variable {R : Type u} {S : Type*}
namespace Polynomial
section Semiring
variable [Semiring R]
instance instCharP (p : ℕ) [h : CharP R p] : CharP R[X] p :=
let ⟨h⟩ := h
⟨fun n => by rw [← map_natCast C, ← C_0, C_inj, h]⟩
instance instExpChar (p : ℕ) [h : ExpChar R p] : ExpChar R[X] p := by
cases h; exacts [ExpChar.zero, ExpChar.prime ‹_›]
variable (R)
/-- The `R`-submodule of `R[X]` consisting of polynomials of degree ≤ `n`. -/
def degreeLE (n : WithBot ℕ) : Submodule R R[X] :=
⨅ k : ℕ, ⨅ _ : ↑k > n, LinearMap.ker (lcoeff R k)
/-- The `R`-submodule of `R[X]` consisting of polynomials of degree < `n`. -/
def degreeLT (n : ℕ) : Submodule R R[X] :=
⨅ k : ℕ, ⨅ (_ : k ≥ n), LinearMap.ker (lcoeff R k)
variable {R}
theorem mem_degreeLE {n : WithBot ℕ} {f : R[X]} : f ∈ degreeLE R n ↔ degree f ≤ n := by
simp only [degreeLE, Submodule.mem_iInf, degree_le_iff_coeff_zero, LinearMap.mem_ker]; rfl
@[mono]
theorem degreeLE_mono {m n : WithBot ℕ} (H : m ≤ n) : degreeLE R m ≤ degreeLE R n := fun _ hf =>
mem_degreeLE.2 (le_trans (mem_degreeLE.1 hf) H)
theorem degreeLE_eq_span_X_pow [DecidableEq R] {n : ℕ} :
degreeLE R n = Submodule.span R ↑((Finset.range (n + 1)).image fun n => (X : R[X]) ^ n) := by
apply le_antisymm
· intro p hp
replace hp := mem_degreeLE.1 hp
rw [← Polynomial.sum_monomial_eq p, Polynomial.sum]
refine Submodule.sum_mem _ fun k hk => ?_
have := WithBot.coe_le_coe.1 (Finset.sup_le_iff.1 hp k hk)
rw [← C_mul_X_pow_eq_monomial, C_mul']
refine
Submodule.smul_mem _ _
(Submodule.subset_span <|
Finset.mem_coe.2 <|
Finset.mem_image.2 ⟨_, Finset.mem_range.2 (Nat.lt_succ_of_le this), rfl⟩)
rw [Submodule.span_le, Finset.coe_image, Set.image_subset_iff]
intro k hk
apply mem_degreeLE.2
exact
(degree_X_pow_le _).trans (WithBot.coe_le_coe.2 <| Nat.le_of_lt_succ <| Finset.mem_range.1 hk)
theorem mem_degreeLT {n : ℕ} {f : R[X]} : f ∈ degreeLT R n ↔ degree f < n := by
rw [degreeLT, Submodule.mem_iInf]
conv_lhs => intro i; rw [Submodule.mem_iInf]
rw [degree, Finset.max_eq_sup_coe]
rw [Finset.sup_lt_iff ?_]
rotate_left
· apply WithBot.bot_lt_coe
conv_rhs =>
simp only [mem_support_iff]
intro b
rw [Nat.cast_withBot, WithBot.coe_lt_coe, lt_iff_not_le, Ne, not_imp_not]
rfl
@[mono]
theorem degreeLT_mono {m n : ℕ} (H : m ≤ n) : degreeLT R m ≤ degreeLT R n := fun _ hf =>
mem_degreeLT.2 (lt_of_lt_of_le (mem_degreeLT.1 hf) <| WithBot.coe_le_coe.2 H)
theorem degreeLT_eq_span_X_pow [DecidableEq R] {n : ℕ} :
degreeLT R n = Submodule.span R ↑((Finset.range n).image fun n => X ^ n : Finset R[X]) := by
apply le_antisymm
· intro p hp
replace hp := mem_degreeLT.1 hp
rw [← Polynomial.sum_monomial_eq p, Polynomial.sum]
refine Submodule.sum_mem _ fun k hk => ?_
have := WithBot.coe_lt_coe.1 ((Finset.sup_lt_iff <| WithBot.bot_lt_coe n).1 hp k hk)
rw [← C_mul_X_pow_eq_monomial, C_mul']
refine
Submodule.smul_mem _ _
(Submodule.subset_span <|
Finset.mem_coe.2 <| Finset.mem_image.2 ⟨_, Finset.mem_range.2 this, rfl⟩)
rw [Submodule.span_le, Finset.coe_image, Set.image_subset_iff]
intro k hk
apply mem_degreeLT.2
exact lt_of_le_of_lt (degree_X_pow_le _) (WithBot.coe_lt_coe.2 <| Finset.mem_range.1 hk)
/-- The first `n` coefficients on `degreeLT n` form a linear equivalence with `Fin n → R`. -/
def degreeLTEquiv (R) [Semiring R] (n : ℕ) : degreeLT R n ≃ₗ[R] Fin n → R where
toFun p n := (↑p : R[X]).coeff n
invFun f :=
⟨∑ i : Fin n, monomial i (f i),
(degreeLT R n).sum_mem fun i _ =>
mem_degreeLT.mpr
(lt_of_le_of_lt (degree_monomial_le i (f i)) (WithBot.coe_lt_coe.mpr i.is_lt))⟩
map_add' p q := by
ext
dsimp
rw [coeff_add]
map_smul' x p := by
ext
dsimp
rw [coeff_smul]
rfl
left_inv := by
rintro ⟨p, hp⟩
ext1
simp only [Submodule.coe_mk]
by_cases hp0 : p = 0
· subst hp0
simp only [coeff_zero, LinearMap.map_zero, Finset.sum_const_zero]
rw [mem_degreeLT, degree_eq_natDegree hp0, Nat.cast_lt] at hp
conv_rhs => rw [p.as_sum_range' n hp, ← Fin.sum_univ_eq_sum_range]
right_inv f := by
ext i
simp only [finset_sum_coeff, Submodule.coe_mk]
rw [Finset.sum_eq_single i, coeff_monomial, if_pos rfl]
· rintro j - hji
rw [coeff_monomial, if_neg]
rwa [← Fin.ext_iff]
· intro h
exact (h (Finset.mem_univ _)).elim
theorem degreeLTEquiv_eq_zero_iff_eq_zero {n : ℕ} {p : R[X]} (hp : p ∈ degreeLT R n) :
degreeLTEquiv _ _ ⟨p, hp⟩ = 0 ↔ p = 0 := by simp
theorem eval_eq_sum_degreeLTEquiv {n : ℕ} {p : R[X]} (hp : p ∈ degreeLT R n) (x : R) :
p.eval x = ∑ i, degreeLTEquiv _ _ ⟨p, hp⟩ i * x ^ (i : ℕ) := by
simp_rw [eval_eq_sum]
exact (sum_fin _ (by simp_rw [zero_mul, forall_const]) (mem_degreeLT.mp hp)).symm
theorem degreeLT_succ_eq_degreeLE {n : ℕ} : degreeLT R (n + 1) = degreeLE R n := by
ext x
by_cases x_zero : x = 0
· simp_rw [x_zero, Submodule.zero_mem]
· rw [mem_degreeLT, mem_degreeLE, ← natDegree_lt_iff_degree_lt (by rwa [ne_eq]),
← natDegree_le_iff_degree_le, Nat.lt_succ]
/-- The equivalence between monic polynomials of degree `n` and polynomials of degree less than
`n`, formed by adding a term `X ^ n`. -/
def monicEquivDegreeLT [Nontrivial R] (n : ℕ) :
{ p : R[X] // p.Monic ∧ p.natDegree = n } ≃ degreeLT R n where
toFun p := ⟨p.1.eraseLead, by
rcases p with ⟨p, hp, rfl⟩
simp only [mem_degreeLT]
refine lt_of_lt_of_le ?_ degree_le_natDegree
exact degree_eraseLead_lt (ne_zero_of_ne_zero_of_monic one_ne_zero hp)⟩
invFun := fun p =>
⟨X^n + p.1, monic_X_pow_add (mem_degreeLT.1 p.2), by
rw [natDegree_add_eq_left_of_degree_lt]
· simp
· simp [mem_degreeLT.1 p.2]⟩
left_inv := by
rintro ⟨p, hp, rfl⟩
ext1
simp only
conv_rhs => rw [← eraseLead_add_C_mul_X_pow p]
simp [Monic.def.1 hp, add_comm]
right_inv := by
rintro ⟨p, hp⟩
ext1
simp only
rw [eraseLead_add_of_degree_lt_left]
· simp
· simp [mem_degreeLT.1 hp]
/-- For every polynomial `p` in the span of a set `s : Set R[X]`, there exists a polynomial of
`p' ∈ s` with higher degree. See also `Polynomial.exists_degree_le_of_mem_span_of_finite`. -/
theorem exists_degree_le_of_mem_span {s : Set R[X]} {p : R[X]}
(hs : s.Nonempty) (hp : p ∈ Submodule.span R s) :
∃ p' ∈ s, degree p ≤ degree p' := by
by_contra! h
by_cases hp_zero : p = 0
· rw [hp_zero, degree_zero] at h
rcases hs with ⟨x, hx⟩
exact not_lt_bot (h x hx)
· have : p ∈ degreeLT R (natDegree p) := by
refine (Submodule.span_le.mpr fun p' p'_mem => ?_) hp
rw [SetLike.mem_coe, mem_degreeLT, Nat.cast_withBot]
exact lt_of_lt_of_le (h p' p'_mem) degree_le_natDegree
rwa [mem_degreeLT, Nat.cast_withBot, degree_eq_natDegree hp_zero,
Nat.cast_withBot, lt_self_iff_false] at this
/-- A stronger version of `Polynomial.exists_degree_le_of_mem_span` under the assumption that the
set `s : R[X]` is finite. There exists a polynomial `p' ∈ s` whose degree dominates the degree of
every element of `p ∈ span R s`. -/
theorem exists_degree_le_of_mem_span_of_finite {s : Set R[X]} (s_fin : s.Finite) (hs : s.Nonempty) :
∃ p' ∈ s, ∀ (p : R[X]), p ∈ Submodule.span R s → degree p ≤ degree p' := by
rcases Set.Finite.exists_maximal_wrt degree s s_fin hs with ⟨a, has, hmax⟩
refine ⟨a, has, fun p hp => ?_⟩
rcases exists_degree_le_of_mem_span hs hp with ⟨p', hp'⟩
by_cases h : degree a ≤ degree p'
· rw [← hmax p' hp'.left h] at hp'; exact hp'.right
· exact le_trans hp'.right (not_le.mp h).le
/-- The span of every finite set of polynomials is contained in a `degreeLE n` for some `n`. -/
theorem span_le_degreeLE_of_finite {s : Set R[X]} (s_fin : s.Finite) :
∃ n : ℕ, Submodule.span R s ≤ degreeLE R n := by
by_cases s_emp : s.Nonempty
· rcases exists_degree_le_of_mem_span_of_finite s_fin s_emp with ⟨p', _, hp'max⟩
exact ⟨natDegree p', fun p hp => mem_degreeLE.mpr ((hp'max _ hp).trans degree_le_natDegree)⟩
· rw [Set.not_nonempty_iff_eq_empty] at s_emp
rw [s_emp, Submodule.span_empty]
exact ⟨0, bot_le⟩
/-- The span of every finite set of polynomials is contained in a `degreeLT n` for some `n`. -/
theorem span_of_finite_le_degreeLT {s : Set R[X]} (s_fin : s.Finite) :
∃ n : ℕ, Submodule.span R s ≤ degreeLT R n := by
rcases span_le_degreeLE_of_finite s_fin with ⟨n, _⟩
exact ⟨n + 1, by rwa [degreeLT_succ_eq_degreeLE]⟩
/-- If `R` is a nontrivial ring, the polynomials `R[X]` are not finite as an `R`-module. When `R` is
a field, this is equivalent to `R[X]` being an infinite-dimensional vector space over `R`. -/
theorem not_finite [Nontrivial R] : ¬ Module.Finite R R[X] := by
rw [Module.finite_def, Submodule.fg_def]
push_neg
intro s hs contra
rcases span_le_degreeLE_of_finite hs with ⟨n,hn⟩
have : ((X : R[X]) ^ (n + 1)) ∈ Polynomial.degreeLE R ↑n := by
rw [contra] at hn
exact hn Submodule.mem_top
rw [mem_degreeLE, degree_X_pow, Nat.cast_le, add_le_iff_nonpos_right, nonpos_iff_eq_zero] at this
exact one_ne_zero this
theorem geom_sum_X_comp_X_add_one_eq_sum (n : ℕ) :
(∑ i ∈ range n, (X : R[X]) ^ i).comp (X + 1) =
(Finset.range n).sum fun i : ℕ => (n.choose (i + 1) : R[X]) * X ^ i := by
ext i
trans (n.choose (i + 1) : R); swap
· simp only [finset_sum_coeff, ← C_eq_natCast, coeff_C_mul_X_pow]
rw [Finset.sum_eq_single i, if_pos rfl]
· simp +contextual only [@eq_comm _ i, if_false, eq_self_iff_true,
imp_true_iff]
· simp +contextual only [Nat.lt_add_one_iff, Nat.choose_eq_zero_of_lt,
Nat.cast_zero, Finset.mem_range, not_lt, eq_self_iff_true, if_true, imp_true_iff]
induction' n with n ih generalizing i
· dsimp; simp only [zero_comp, coeff_zero, Nat.cast_zero]
· simp only [geom_sum_succ', ih, add_comp, X_pow_comp, coeff_add, Nat.choose_succ_succ,
Nat.cast_add, coeff_X_add_one_pow]
theorem Monic.geom_sum {P : R[X]} (hP : P.Monic) (hdeg : 0 < P.natDegree) {n : ℕ} (hn : n ≠ 0) :
(∑ i ∈ range n, P ^ i).Monic := by
nontriviality R
obtain ⟨n, rfl⟩ := Nat.exists_eq_succ_of_ne_zero hn
rw [geom_sum_succ']
refine (hP.pow _).add_of_left ?_
refine lt_of_le_of_lt (degree_sum_le _ _) ?_
rw [Finset.sup_lt_iff]
· simp only [Finset.mem_range, degree_eq_natDegree (hP.pow _).ne_zero]
simp only [Nat.cast_lt, hP.natDegree_pow]
intro k
exact nsmul_lt_nsmul_left hdeg
· rw [bot_lt_iff_ne_bot, Ne, degree_eq_bot]
exact (hP.pow _).ne_zero
theorem Monic.geom_sum' {P : R[X]} (hP : P.Monic) (hdeg : 0 < P.degree) {n : ℕ} (hn : n ≠ 0) :
(∑ i ∈ range n, P ^ i).Monic :=
hP.geom_sum (natDegree_pos_iff_degree_pos.2 hdeg) hn
theorem monic_geom_sum_X {n : ℕ} (hn : n ≠ 0) : (∑ i ∈ range n, (X : R[X]) ^ i).Monic := by
nontriviality R
apply monic_X.geom_sum _ hn
simp only [natDegree_X, zero_lt_one]
end Semiring
section Ring
variable [Ring R]
/-- Given a polynomial, return the polynomial whose coefficients are in
the ring closure of the original coefficients. -/
def restriction (p : R[X]) : Polynomial (Subring.closure (↑p.coeffs : Set R)) :=
∑ i ∈ p.support,
monomial i
(⟨p.coeff i,
letI := Classical.decEq R
if H : p.coeff i = 0 then H.symm ▸ (Subring.closure _).zero_mem
else Subring.subset_closure (p.coeff_mem_coeffs _ H)⟩ :
Subring.closure (↑p.coeffs : Set R))
@[simp]
theorem coeff_restriction {p : R[X]} {n : ℕ} : ↑(coeff (restriction p) n) = coeff p n := by
classical
simp only [restriction, coeff_monomial, finset_sum_coeff, mem_support_iff, Finset.sum_ite_eq',
Ne, ite_not]
split_ifs with h
· rw [h]
rfl
· rfl
theorem coeff_restriction' {p : R[X]} {n : ℕ} : (coeff (restriction p) n).1 = coeff p n := by
simp
@[simp]
theorem support_restriction (p : R[X]) : support (restriction p) = support p := by
ext i
simp only [mem_support_iff, not_iff_not, Ne]
conv_rhs => rw [← coeff_restriction]
exact ⟨fun H => by rw [H, ZeroMemClass.coe_zero], fun H => Subtype.coe_injective H⟩
@[simp]
theorem map_restriction {R : Type u} [CommRing R] (p : R[X]) :
p.restriction.map (algebraMap _ _) = p :=
ext fun n => by rw [coeff_map, Algebra.algebraMap_ofSubring_apply, coeff_restriction]
@[simp]
theorem degree_restriction {p : R[X]} : (restriction p).degree = p.degree := by simp [degree]
@[simp]
theorem natDegree_restriction {p : R[X]} : (restriction p).natDegree = p.natDegree := by
simp [natDegree]
@[simp]
theorem monic_restriction {p : R[X]} : Monic (restriction p) ↔ Monic p := by
simp only [Monic, leadingCoeff, natDegree_restriction]
rw [← @coeff_restriction _ _ p]
exact ⟨fun H => by rw [H, OneMemClass.coe_one], fun H => Subtype.coe_injective H⟩
@[simp]
theorem restriction_zero : restriction (0 : R[X]) = 0 := by
simp only [restriction, Finset.sum_empty, support_zero]
@[simp]
theorem restriction_one : restriction (1 : R[X]) = 1 :=
ext fun i => Subtype.eq <| by rw [coeff_restriction', coeff_one, coeff_one]; split_ifs <;> rfl
variable [Semiring S] {f : R →+* S} {x : S}
theorem eval₂_restriction {p : R[X]} :
eval₂ f x p =
eval₂ (f.comp (Subring.subtype (Subring.closure (p.coeffs : Set R)))) x p.restriction := by
simp only [eval₂_eq_sum, sum, support_restriction, ← @coeff_restriction _ _ p, RingHom.comp_apply,
Subring.coe_subtype]
section ToSubring
variable (p : R[X]) (T : Subring R)
/-- Given a polynomial `p` and a subring `T` that contains the coefficients of `p`,
return the corresponding polynomial whose coefficients are in `T`. -/
def toSubring (hp : (↑p.coeffs : Set R) ⊆ T) : T[X] :=
∑ i ∈ p.support,
monomial i
(⟨p.coeff i,
letI := Classical.decEq R
if H : p.coeff i = 0 then H.symm ▸ T.zero_mem else hp (p.coeff_mem_coeffs _ H)⟩ : T)
variable (hp : (↑p.coeffs : Set R) ⊆ T)
@[simp]
theorem coeff_toSubring {n : ℕ} : ↑(coeff (toSubring p T hp) n) = coeff p n := by
classical
simp only [toSubring, coeff_monomial, finset_sum_coeff, mem_support_iff, Finset.sum_ite_eq',
Ne, ite_not]
split_ifs with h
· rw [h]
rfl
· rfl
theorem coeff_toSubring' {n : ℕ} : (coeff (toSubring p T hp) n).1 = coeff p n := by
simp
@[simp]
theorem support_toSubring : support (toSubring p T hp) = support p := by
ext i
simp only [mem_support_iff, not_iff_not, Ne]
conv_rhs => rw [← coeff_toSubring p T hp]
exact ⟨fun H => by rw [H, ZeroMemClass.coe_zero], fun H => Subtype.coe_injective H⟩
@[simp]
theorem degree_toSubring : (toSubring p T hp).degree = p.degree := by simp [degree]
@[simp]
theorem natDegree_toSubring : (toSubring p T hp).natDegree = p.natDegree := by simp [natDegree]
@[simp]
theorem monic_toSubring : Monic (toSubring p T hp) ↔ Monic p := by
simp_rw [Monic, leadingCoeff, natDegree_toSubring, ← coeff_toSubring p T hp]
exact ⟨fun H => by rw [H, OneMemClass.coe_one], fun H => Subtype.coe_injective H⟩
@[simp]
theorem toSubring_zero : toSubring (0 : R[X]) T (by simp [coeffs]) = 0 := by
ext i
simp
@[simp]
theorem toSubring_one :
toSubring (1 : R[X]) T
(Set.Subset.trans coeffs_one <| Finset.singleton_subset_set_iff.2 T.one_mem) =
1 :=
ext fun i => Subtype.eq <| by
rw [coeff_toSubring', coeff_one, coeff_one, apply_ite Subtype.val, ZeroMemClass.coe_zero,
OneMemClass.coe_one]
@[simp]
theorem map_toSubring : (p.toSubring T hp).map (Subring.subtype T) = p := by
ext n
simp [coeff_map]
end ToSubring
variable (T : Subring R)
/-- Given a polynomial whose coefficients are in some subring, return
the corresponding polynomial whose coefficients are in the ambient ring. -/
def ofSubring (p : T[X]) : R[X] :=
∑ i ∈ p.support, monomial i (p.coeff i : R)
theorem coeff_ofSubring (p : T[X]) (n : ℕ) : coeff (ofSubring T p) n = (coeff p n : T) := by
simp only [ofSubring, coeff_monomial, finset_sum_coeff, mem_support_iff, Finset.sum_ite_eq',
ite_eq_right_iff, Ne, ite_not, Classical.not_not, ite_eq_left_iff]
intro h
rw [h, ZeroMemClass.coe_zero]
@[simp]
theorem coeffs_ofSubring {p : T[X]} : (↑(p.ofSubring T).coeffs : Set R) ⊆ T := by
classical
intro i hi
simp only [coeffs, Set.mem_image, mem_support_iff, Ne, Finset.mem_coe,
(Finset.coe_image)] at hi
rcases hi with ⟨n, _, h'n⟩
rw [← h'n, coeff_ofSubring]
exact Subtype.mem (coeff p n : T)
end Ring
end Polynomial
namespace Ideal
open Polynomial
section Semiring
variable [Semiring R]
/-- Transport an ideal of `R[X]` to an `R`-submodule of `R[X]`. -/
def ofPolynomial (I : Ideal R[X]) : Submodule R R[X] where
carrier := I.carrier
zero_mem' := I.zero_mem
add_mem' := I.add_mem
smul_mem' c x H := by
rw [← C_mul']
exact I.mul_mem_left _ H
variable {I : Ideal R[X]}
theorem mem_ofPolynomial (x) : x ∈ I.ofPolynomial ↔ x ∈ I :=
Iff.rfl
variable (I)
/-- Given an ideal `I` of `R[X]`, make the `R`-submodule of `I`
consisting of polynomials of degree ≤ `n`. -/
def degreeLE (n : WithBot ℕ) : Submodule R R[X] :=
Polynomial.degreeLE R n ⊓ I.ofPolynomial
/-- Given an ideal `I` of `R[X]`, make the ideal in `R` of
leading coefficients of polynomials in `I` with degree ≤ `n`. -/
def leadingCoeffNth (n : ℕ) : Ideal R :=
(I.degreeLE n).map <| lcoeff R n
/-- Given an ideal `I` in `R[X]`, make the ideal in `R` of the
leading coefficients in `I`. -/
def leadingCoeff : Ideal R :=
⨆ n : ℕ, I.leadingCoeffNth n
end Semiring
section CommSemiring
variable [CommSemiring R] [Semiring S]
/-- If every coefficient of a polynomial is in an ideal `I`, then so is the polynomial itself -/
theorem polynomial_mem_ideal_of_coeff_mem_ideal (I : Ideal R[X]) (p : R[X])
(hp : ∀ n : ℕ, p.coeff n ∈ I.comap (C : R →+* R[X])) : p ∈ I :=
sum_C_mul_X_pow_eq p ▸ Submodule.sum_mem I fun n _ => I.mul_mem_right _ (hp n)
/-- The push-forward of an ideal `I` of `R` to `R[X]` via inclusion
is exactly the set of polynomials whose coefficients are in `I` -/
theorem mem_map_C_iff {I : Ideal R} {f : R[X]} :
f ∈ (Ideal.map (C : R →+* R[X]) I : Ideal R[X]) ↔ ∀ n : ℕ, f.coeff n ∈ I := by
constructor
· intro hf
refine Submodule.span_induction ?_ ?_ ?_ ?_ hf
· intro f hf n
obtain ⟨x, hx⟩ := (Set.mem_image _ _ _).mp hf
rw [← hx.right, coeff_C]
by_cases h : n = 0
· simpa [h] using hx.left
· simp [h]
· simp
· exact fun f g _ _ hf hg n => by simp [I.add_mem (hf n) (hg n)]
· refine fun f g _ hg n => ?_
rw [smul_eq_mul, coeff_mul]
exact I.sum_mem fun c _ => I.mul_mem_left (f.coeff c.fst) (hg c.snd)
· intro hf
rw [← sum_monomial_eq f]
refine (I.map C : Ideal R[X]).sum_mem fun n _ => ?_
simp only [← C_mul_X_pow_eq_monomial, ne_eq]
rw [mul_comm]
exact (I.map C : Ideal R[X]).mul_mem_left _ (mem_map_of_mem _ (hf n))
theorem _root_.Polynomial.ker_mapRingHom (f : R →+* S) :
RingHom.ker (Polynomial.mapRingHom f) = (RingHom.ker f).map (C : R →+* R[X]) := by
ext
simp only [RingHom.mem_ker, coe_mapRingHom]
rw [mem_map_C_iff, Polynomial.ext_iff]
simp [RingHom.mem_ker]
variable (I : Ideal R[X])
theorem mem_leadingCoeffNth (n : ℕ) (x) :
x ∈ I.leadingCoeffNth n ↔ ∃ p ∈ I, degree p ≤ n ∧ p.leadingCoeff = x := by
simp only [leadingCoeffNth, degreeLE, Submodule.mem_map, lcoeff_apply, Submodule.mem_inf,
mem_degreeLE]
constructor
· rintro ⟨p, ⟨hpdeg, hpI⟩, rfl⟩
rcases lt_or_eq_of_le hpdeg with hpdeg | hpdeg
· refine ⟨0, I.zero_mem, bot_le, ?_⟩
rw [leadingCoeff_zero, eq_comm]
exact coeff_eq_zero_of_degree_lt hpdeg
· refine ⟨p, hpI, le_of_eq hpdeg, ?_⟩
rw [Polynomial.leadingCoeff, natDegree, hpdeg, Nat.cast_withBot, WithBot.unbotD_coe]
· rintro ⟨p, hpI, hpdeg, rfl⟩
have : natDegree p + (n - natDegree p) = n :=
add_tsub_cancel_of_le (natDegree_le_of_degree_le hpdeg)
refine ⟨p * X ^ (n - natDegree p), ⟨?_, I.mul_mem_right _ hpI⟩, ?_⟩
· apply le_trans (degree_mul_le _ _) _
apply le_trans (add_le_add degree_le_natDegree (degree_X_pow_le _)) _
rw [← Nat.cast_add, this]
· rw [Polynomial.leadingCoeff, ← coeff_mul_X_pow p (n - natDegree p), this]
theorem mem_leadingCoeffNth_zero (x) : x ∈ I.leadingCoeffNth 0 ↔ C x ∈ I :=
(mem_leadingCoeffNth _ _ _).trans
⟨fun ⟨p, hpI, hpdeg, hpx⟩ => by
rwa [← hpx, Polynomial.leadingCoeff,
Nat.eq_zero_of_le_zero (natDegree_le_of_degree_le hpdeg), ← eq_C_of_degree_le_zero hpdeg],
fun hx => ⟨C x, hx, degree_C_le, leadingCoeff_C x⟩⟩
theorem leadingCoeffNth_mono {m n : ℕ} (H : m ≤ n) : I.leadingCoeffNth m ≤ I.leadingCoeffNth n := by
intro r hr
simp only [SetLike.mem_coe, mem_leadingCoeffNth] at hr ⊢
rcases hr with ⟨p, hpI, hpdeg, rfl⟩
refine ⟨p * X ^ (n - m), I.mul_mem_right _ hpI, ?_, leadingCoeff_mul_X_pow⟩
refine le_trans (degree_mul_le _ _) ?_
refine le_trans (add_le_add hpdeg (degree_X_pow_le _)) ?_
rw [← Nat.cast_add, add_tsub_cancel_of_le H]
theorem mem_leadingCoeff (x) : x ∈ I.leadingCoeff ↔ ∃ p ∈ I, Polynomial.leadingCoeff p = x := by
rw [leadingCoeff, Submodule.mem_iSup_of_directed]
· simp only [mem_leadingCoeffNth]
constructor
· rintro ⟨i, p, hpI, _, rfl⟩
exact ⟨p, hpI, rfl⟩
rintro ⟨p, hpI, rfl⟩
exact ⟨natDegree p, p, hpI, degree_le_natDegree, rfl⟩
intro i j
exact
⟨i + j, I.leadingCoeffNth_mono (Nat.le_add_right _ _),
I.leadingCoeffNth_mono (Nat.le_add_left _ _)⟩
/-- If `I` is an ideal, and `pᵢ` is a finite family of polynomials each satisfying
`∀ k, (pᵢ)ₖ ∈ Iⁿⁱ⁻ᵏ` for some `nᵢ`, then `p = ∏ pᵢ` also satisfies `∀ k, pₖ ∈ Iⁿ⁻ᵏ` with `n = ∑ nᵢ`.
-/
theorem _root_.Polynomial.coeff_prod_mem_ideal_pow_tsub {ι : Type*} (s : Finset ι) (f : ι → R[X])
(I : Ideal R) (n : ι → ℕ) (h : ∀ i ∈ s, ∀ (k), (f i).coeff k ∈ I ^ (n i - k)) (k : ℕ) :
(s.prod f).coeff k ∈ I ^ (s.sum n - k) := by
classical
induction' s using Finset.induction with a s ha hs generalizing k
· rw [sum_empty, prod_empty, coeff_one, zero_tsub, pow_zero, Ideal.one_eq_top]
exact Submodule.mem_top
· rw [sum_insert ha, prod_insert ha, coeff_mul]
apply sum_mem
rintro ⟨i, j⟩ e
obtain rfl : i + j = k := mem_antidiagonal.mp e
apply Ideal.pow_le_pow_right add_tsub_add_le_tsub_add_tsub
rw [pow_add]
exact
Ideal.mul_mem_mul (h _ (Finset.mem_insert.mpr <| Or.inl rfl) _)
(hs (fun i hi k => h _ (Finset.mem_insert.mpr <| Or.inr hi) _) j)
end CommSemiring
section Ring
variable [Ring R]
/-- `R[X]` is never a field for any ring `R`. -/
theorem polynomial_not_isField : ¬IsField R[X] := by
nontriviality R
intro hR
obtain ⟨p, hp⟩ := hR.mul_inv_cancel X_ne_zero
have hp0 : p ≠ 0 := right_ne_zero_of_mul_eq_one hp
have := degree_lt_degree_mul_X hp0
rw [← X_mul, congr_arg degree hp, degree_one, Nat.WithBot.lt_zero_iff, degree_eq_bot] at this
exact hp0 this
/-- The only constant in a maximal ideal over a field is `0`. -/
theorem eq_zero_of_constant_mem_of_maximal (hR : IsField R) (I : Ideal R[X]) [hI : I.IsMaximal]
(x : R) (hx : C x ∈ I) : x = 0 := by
refine Classical.by_contradiction fun hx0 => hI.ne_top ((eq_top_iff_one I).2 ?_)
obtain ⟨y, hy⟩ := hR.mul_inv_cancel hx0
convert I.mul_mem_left (C y) hx
rw [← C.map_mul, hR.mul_comm y x, hy, RingHom.map_one]
end Ring
section CommRing
variable [CommRing R]
/-- If `P` is a prime ideal of `R`, then `P.R[x]` is a prime ideal of `R[x]`. -/
theorem isPrime_map_C_iff_isPrime (P : Ideal R) :
IsPrime (map (C : R →+* R[X]) P : Ideal R[X]) ↔ IsPrime P := by
-- Note: the following proof avoids quotient rings
-- It can be golfed substantially by using something like
-- `(Quotient.isDomain_iff_prime (map C P : Ideal R[X]))`
constructor
· intro H
have := comap_isPrime C (map C P)
convert this using 1
ext x
simp only [mem_comap, mem_map_C_iff]
constructor
· rintro h (- | n)
· rwa [coeff_C_zero]
· simp only [coeff_C_ne_zero (Nat.succ_ne_zero _), Submodule.zero_mem]
· intro h
simpa only [coeff_C_zero] using h 0
· intro h
constructor
· rw [Ne, eq_top_iff_one, mem_map_C_iff, not_forall]
use 0
rw [coeff_one_zero, ← eq_top_iff_one]
exact h.1
· intro f g
simp only [mem_map_C_iff]
contrapose!
rintro ⟨hf, hg⟩
classical
let m := Nat.find hf
let n := Nat.find hg
refine ⟨m + n, ?_⟩
rw [coeff_mul, ← Finset.insert_erase ((Finset.mem_antidiagonal (a := (m,n))).mpr rfl),
Finset.sum_insert (Finset.not_mem_erase _ _), (P.add_mem_iff_left _).not]
· apply mt h.2
rw [not_or]
exact ⟨Nat.find_spec hf, Nat.find_spec hg⟩
apply P.sum_mem
rintro ⟨i, j⟩ hij
rw [Finset.mem_erase, Finset.mem_antidiagonal] at hij
simp only [Ne, Prod.mk_inj, not_and_or] at hij
obtain hi | hj : i < m ∨ j < n := by
omega
· rw [mul_comm]
apply P.mul_mem_left
exact Classical.not_not.1 (Nat.find_min hf hi)
· apply P.mul_mem_left
exact Classical.not_not.1 (Nat.find_min hg hj)
/-- If `P` is a prime ideal of `R`, then `P.R[x]` is a prime ideal of `R[x]`. -/
theorem isPrime_map_C_of_isPrime {P : Ideal R} (H : IsPrime P) :
IsPrime (map (C : R →+* R[X]) P : Ideal R[X]) :=
(isPrime_map_C_iff_isPrime P).mpr H
theorem is_fg_degreeLE [IsNoetherianRing R] (I : Ideal R[X]) (n : ℕ) :
Submodule.FG (I.degreeLE n) :=
letI := Classical.decEq R
isNoetherian_submodule_left.1
(isNoetherian_of_fg_of_noetherian _ ⟨_, degreeLE_eq_span_X_pow.symm⟩) _
end CommRing
end Ideal
section Ideal
open Submodule Set
variable [Semiring R] {f : R[X]} {I : Ideal R[X]}
/-- If the coefficients of a polynomial belong to an ideal, then that ideal contains
the ideal spanned by the coefficients of the polynomial. -/
theorem span_le_of_C_coeff_mem (cf : ∀ i : ℕ, C (f.coeff i) ∈ I) :
Ideal.span { g | ∃ i, g = C (f.coeff i) } ≤ I := by
simp only [@eq_comm _ _ (C _)]
exact (Ideal.span_le.trans range_subset_iff).mpr cf
theorem mem_span_C_coeff : f ∈ Ideal.span { g : R[X] | ∃ i : ℕ, g = C (coeff f i) } := by
let p := Ideal.span { g : R[X] | ∃ i : ℕ, g = C (coeff f i) }
nth_rw 2 [(sum_C_mul_X_pow_eq f).symm]
refine Submodule.sum_mem _ fun n _hn => ?_
dsimp
have : C (coeff f n) ∈ p := by
apply subset_span
rw [mem_setOf_eq]
use n
have : monomial n (1 : R) • C (coeff f n) ∈ p := p.smul_mem _ this
convert this using 1
simp only [monomial_mul_C, one_mul, smul_eq_mul]
rw [← C_mul_X_pow_eq_monomial]
theorem exists_C_coeff_not_mem : f ∉ I → ∃ i : ℕ, C (coeff f i) ∉ I :=
Not.imp_symm fun cf => span_le_of_C_coeff_mem (not_exists_not.mp cf) mem_span_C_coeff
end Ideal
variable {σ : Type v} {M : Type w}
variable [CommRing R] [CommRing S] [AddCommGroup M] [Module R M]
section Prime
variable (σ) {r : R}
namespace Polynomial
theorem prime_C_iff : Prime (C r) ↔ Prime r :=
⟨comap_prime C (evalRingHom (0 : R)) fun _ => eval_C, fun hr => by
have := hr.1
rw [← Ideal.span_singleton_prime] at hr ⊢
· rw [← Set.image_singleton, ← Ideal.map_span]
apply Ideal.isPrime_map_C_of_isPrime hr
· intro h; apply (this (C_eq_zero.mp h))
· assumption⟩
end Polynomial
namespace MvPolynomial
private theorem prime_C_iff_of_fintype {R : Type u} (σ : Type v) {r : R} [CommRing R] [Fintype σ] :
Prime (C r : MvPolynomial σ R) ↔ Prime r := by
rw [← MulEquiv.prime_iff (renameEquiv R (Fintype.equivFin σ))]
convert_to Prime (C r) ↔ _
· congr!
simp only [renameEquiv_apply, algHom_C, algebraMap_eq]
· induction' Fintype.card σ with d hd
· exact MulEquiv.prime_iff (isEmptyAlgEquiv R (Fin 0)).symm (p := r)
· convert MulEquiv.prime_iff (finSuccEquiv R d).symm (p := Polynomial.C (C r))
· simp [← finSuccEquiv_comp_C_eq_C]
· simp [← hd, Polynomial.prime_C_iff]
theorem prime_C_iff : Prime (C r : MvPolynomial σ R) ↔ Prime r :=
⟨comap_prime C constantCoeff (constantCoeff_C _), fun hr =>
⟨fun h => hr.1 <| by
rw [← C_inj, h]
simp,
fun h =>
hr.2.1 <| by
rw [← constantCoeff_C _ r]
exact h.map _,
fun a b hd => by
obtain ⟨s, a', b', rfl, rfl⟩ := exists_finset_rename₂ a b
rw [← algebraMap_eq] at hd
have : algebraMap R _ r ∣ a' * b' := by
convert killCompl Subtype.coe_injective |>.toRingHom.map_dvd hd <;> simp
rw [← rename_C ((↑) : s → σ)]
let f := (rename (R := R) ((↑) : s → σ)).toRingHom
exact (((prime_C_iff_of_fintype s).2 hr).2.2 a' b' this).imp f.map_dvd f.map_dvd⟩⟩
variable {σ}
theorem prime_rename_iff (s : Set σ) {p : MvPolynomial s R} :
Prime (rename ((↑) : s → σ) p) ↔ Prime (p : MvPolynomial s R) := by
classical
symm
let eqv :=
(sumAlgEquiv R (↥sᶜ) s).symm.trans
(renameEquiv R <| (Equiv.sumComm (↥sᶜ) s).trans <| Equiv.Set.sumCompl s)
have : (rename (↑)).toRingHom = eqv.toAlgHom.toRingHom.comp C := by
apply ringHom_ext
· intro
simp only [eqv, AlgHom.toRingHom_eq_coe, RingHom.coe_coe, rename_C,
AlgEquiv.toAlgHom_eq_coe, AlgEquiv.toAlgHom_toRingHom, RingHom.coe_comp,
AlgEquiv.coe_trans, Function.comp_apply, MvPolynomial.sumAlgEquiv_symm_apply,
iterToSum_C_C, renameEquiv_apply, Equiv.coe_trans, Equiv.sumComm_apply]
· intro
simp only [eqv, AlgHom.toRingHom_eq_coe, RingHom.coe_coe, rename_X,
AlgEquiv.toAlgHom_eq_coe, AlgEquiv.toAlgHom_toRingHom, RingHom.coe_comp,
AlgEquiv.coe_trans, Function.comp_apply, MvPolynomial.sumAlgEquiv_symm_apply,
iterToSum_C_X, renameEquiv_apply, Equiv.coe_trans, Equiv.sumComm_apply, Sum.swap_inr,
Equiv.Set.sumCompl_apply_inl]
apply_fun (· p) at this
simp only [AlgHom.toRingHom_eq_coe, RingHom.coe_coe, AlgEquiv.toAlgHom_eq_coe,
AlgEquiv.toAlgHom_toRingHom, RingHom.coe_comp, Function.comp_apply] at this
rw [this, MulEquiv.prime_iff, prime_C_iff]
end MvPolynomial
end Prime
/-- **Hilbert basis theorem**: a polynomial ring over a Noetherian ring is a Noetherian ring. -/
protected theorem Polynomial.isNoetherianRing [inst : IsNoetherianRing R] : IsNoetherianRing R[X] :=
isNoetherianRing_iff.2
⟨fun I : Ideal R[X] =>
let M := inst.wf.min (Set.range I.leadingCoeffNth) ⟨_, ⟨0, rfl⟩⟩
have hm : M ∈ Set.range I.leadingCoeffNth := WellFounded.min_mem _ _ _
let ⟨N, HN⟩ := hm
let ⟨s, hs⟩ := I.is_fg_degreeLE N
have hm2 : ∀ k, I.leadingCoeffNth k ≤ M := fun k =>
Or.casesOn (le_or_lt k N) (fun h => HN ▸ I.leadingCoeffNth_mono h) fun h _ hx =>
Classical.by_contradiction fun hxm =>
haveI : IsNoetherian R R := inst
have : ¬M < I.leadingCoeffNth k := by
refine WellFounded.not_lt_min inst.wf _ _ ?_; exact ⟨k, rfl⟩
this ⟨HN ▸ I.leadingCoeffNth_mono (le_of_lt h), fun H => hxm (H hx)⟩
have hs2 : ∀ {x}, x ∈ I.degreeLE N → x ∈ Ideal.span (↑s : Set R[X]) :=
hs ▸ fun hx =>
Submodule.span_induction (hx := hx) (fun _ hx => Ideal.subset_span hx) (Ideal.zero_mem _)
(fun _ _ _ _ => Ideal.add_mem _) fun c f _ hf => f.C_mul' c ▸ Ideal.mul_mem_left _ _ hf
⟨s, le_antisymm (Ideal.span_le.2 fun x hx =>
have : x ∈ I.degreeLE N := hs ▸ Submodule.subset_span hx
this.2) <| by
have : Submodule.span R[X] ↑s = Ideal.span ↑s := rfl
rw [this]
intro p hp
generalize hn : p.natDegree = k
induction' k using Nat.strong_induction_on with k ih generalizing p
rcases le_or_lt k N with h | h
· subst k
refine hs2 ⟨Polynomial.mem_degreeLE.2
(le_trans Polynomial.degree_le_natDegree <| WithBot.coe_le_coe.2 h), hp⟩
· have hp0 : p ≠ 0 := by
rintro rfl
cases hn
exact Nat.not_lt_zero _ h
have : (0 : R) ≠ 1 := by
intro h
apply hp0
ext i
refine (mul_one _).symm.trans ?_
rw [← h, mul_zero]
rfl
haveI : Nontrivial R := ⟨⟨0, 1, this⟩⟩
have : p.leadingCoeff ∈ I.leadingCoeffNth N := by
rw [HN]
exact hm2 k ((I.mem_leadingCoeffNth _ _).2
⟨_, hp, hn ▸ Polynomial.degree_le_natDegree, rfl⟩)
rw [I.mem_leadingCoeffNth] at this
rcases this with ⟨q, hq, hdq, hlqp⟩
have hq0 : q ≠ 0 := by
intro H
rw [← Polynomial.leadingCoeff_eq_zero] at H
rw [hlqp, Polynomial.leadingCoeff_eq_zero] at H
exact hp0 H
have h1 : p.degree = (q * Polynomial.X ^ (k - q.natDegree)).degree := by
rw [Polynomial.degree_mul', Polynomial.degree_X_pow]
· rw [Polynomial.degree_eq_natDegree hp0, Polynomial.degree_eq_natDegree hq0]
rw [← Nat.cast_add, add_tsub_cancel_of_le, hn]
· refine le_trans (Polynomial.natDegree_le_of_degree_le hdq) (le_of_lt h)
rw [Polynomial.leadingCoeff_X_pow, mul_one]
exact mt Polynomial.leadingCoeff_eq_zero.1 hq0
have h2 : p.leadingCoeff = (q * Polynomial.X ^ (k - q.natDegree)).leadingCoeff := by
rw [← hlqp, Polynomial.leadingCoeff_mul_X_pow]
have := Polynomial.degree_sub_lt h1 hp0 h2
rw [Polynomial.degree_eq_natDegree hp0] at this
rw [← sub_add_cancel p (q * Polynomial.X ^ (k - q.natDegree))]
convert (Ideal.span ↑s).add_mem _ ((Ideal.span (s : Set R[X])).mul_mem_right _ _)
· by_cases hpq : p - q * Polynomial.X ^ (k - q.natDegree) = 0
· rw [hpq]
exact Ideal.zero_mem _
refine ih _ ?_ (I.sub_mem hp (I.mul_mem_right _ hq)) rfl
rwa [Polynomial.degree_eq_natDegree hpq, Nat.cast_lt, hn] at this
exact hs2 ⟨Polynomial.mem_degreeLE.2 hdq, hq⟩⟩⟩
attribute [instance] Polynomial.isNoetherianRing
namespace Polynomial
theorem linearIndependent_powers_iff_aeval (f : M →ₗ[R] M) (v : M) :
(LinearIndependent R fun n : ℕ => (f ^ n) v) ↔ ∀ p : R[X], aeval f p v = 0 → p = 0 := by
rw [linearIndependent_iff]
simp only [Finsupp.linearCombination_apply, aeval_endomorphism, forall_iff_forall_finsupp, Sum,
support, coeff, ofFinsupp_eq_zero]
exact Iff.rfl
theorem disjoint_ker_aeval_of_isCoprime (f : M →ₗ[R] M) {p q : R[X]} (hpq : IsCoprime p q) :
Disjoint (LinearMap.ker (aeval f p)) (LinearMap.ker (aeval f q)) := by
rw [disjoint_iff_inf_le]
intro v hv
rcases hpq with ⟨p', q', hpq'⟩
simpa [LinearMap.mem_ker.1 (Submodule.mem_inf.1 hv).1,
LinearMap.mem_ker.1 (Submodule.mem_inf.1 hv).2] using
congr_arg (fun p : R[X] => aeval f p v) hpq'.symm
@[deprecated (since := "2025-01-23")]
alias disjoint_ker_aeval_of_coprime := disjoint_ker_aeval_of_isCoprime
theorem sup_aeval_range_eq_top_of_isCoprime (f : M →ₗ[R] M) {p q : R[X]} (hpq : IsCoprime p q) :
LinearMap.range (aeval f p) ⊔ LinearMap.range (aeval f q) = ⊤ := by
rw [eq_top_iff]
intro v _
rw [Submodule.mem_sup]
rcases hpq with ⟨p', q', hpq'⟩
use aeval f (p * p') v
use LinearMap.mem_range.2 ⟨aeval f p' v, by simp only [Module.End.mul_apply, aeval_mul]⟩
use aeval f (q * q') v
use LinearMap.mem_range.2 ⟨aeval f q' v, by simp only [Module.End.mul_apply, aeval_mul]⟩
simpa only [mul_comm p p', mul_comm q q', aeval_one, aeval_add] using
congr_arg (fun p : R[X] => aeval f p v) hpq'
@[deprecated (since := "2025-01-23")]
alias sup_aeval_range_eq_top_of_coprime := sup_aeval_range_eq_top_of_isCoprime
theorem sup_ker_aeval_le_ker_aeval_mul {f : M →ₗ[R] M} {p q : R[X]} :
LinearMap.ker (aeval f p) ⊔ LinearMap.ker (aeval f q) ≤ LinearMap.ker (aeval f (p * q)) := by
intro v hv
rcases Submodule.mem_sup.1 hv with ⟨x, hx, y, hy, hxy⟩
have h_eval_x : aeval f (p * q) x = 0 := by
rw [mul_comm, aeval_mul, Module.End.mul_apply, LinearMap.mem_ker.1 hx, LinearMap.map_zero]
have h_eval_y : aeval f (p * q) y = 0 := by
rw [aeval_mul, Module.End.mul_apply, LinearMap.mem_ker.1 hy, LinearMap.map_zero]
rw [LinearMap.mem_ker, ← hxy, LinearMap.map_add, h_eval_x, h_eval_y, add_zero]
theorem sup_ker_aeval_eq_ker_aeval_mul_of_coprime (f : M →ₗ[R] M) {p q : R[X]}
(hpq : IsCoprime p q) :
LinearMap.ker (aeval f p) ⊔ LinearMap.ker (aeval f q) = LinearMap.ker (aeval f (p * q)) := by
apply le_antisymm sup_ker_aeval_le_ker_aeval_mul
intro v hv
rw [Submodule.mem_sup]
rcases hpq with ⟨p', q', hpq'⟩
have h_eval₂_qpp' :=
calc
aeval f (q * (p * p')) v = aeval f (p' * (p * q)) v := by
rw [mul_comm, mul_assoc, mul_comm, mul_assoc, mul_comm q p]
_ = 0 := by rw [aeval_mul, Module.End.mul_apply, LinearMap.mem_ker.1 hv, LinearMap.map_zero]
have h_eval₂_pqq' :=
calc
aeval f (p * (q * q')) v = aeval f (q' * (p * q)) v := by rw [← mul_assoc, mul_comm]
_ = 0 := by rw [aeval_mul, Module.End.mul_apply, LinearMap.mem_ker.1 hv, LinearMap.map_zero]
rw [aeval_mul] at h_eval₂_qpp' h_eval₂_pqq'
refine
⟨aeval f (q * q') v, LinearMap.mem_ker.1 h_eval₂_pqq', aeval f (p * p') v,
LinearMap.mem_ker.1 h_eval₂_qpp', ?_⟩
rw [add_comm, mul_comm p p', mul_comm q q']
simpa only [map_add, map_mul, aeval_one] using congr_arg (fun p : R[X] => aeval f p v) hpq'
end Polynomial
namespace MvPolynomial
lemma aeval_natDegree_le {R : Type*} [CommSemiring R] {m n : ℕ}
(F : MvPolynomial σ R) (hF : F.totalDegree ≤ m)
(f : σ → Polynomial R) (hf : ∀ i, (f i).natDegree ≤ n) :
(MvPolynomial.aeval f F).natDegree ≤ m * n := by
rw [MvPolynomial.aeval_def, MvPolynomial.eval₂]
apply (Polynomial.natDegree_sum_le _ _).trans
apply Finset.sup_le
intro d hd
simp_rw [Function.comp_apply, ← C_eq_algebraMap]
apply (Polynomial.natDegree_C_mul_le _ _).trans
apply (Polynomial.natDegree_prod_le _ _).trans
have : ∑ i ∈ d.support, (d i) * n ≤ m * n := by
rw [← Finset.sum_mul]
apply mul_le_mul' (.trans _ hF) le_rfl
rw [MvPolynomial.totalDegree]
exact Finset.le_sup_of_le hd le_rfl
apply (Finset.sum_le_sum _).trans this
rintro i -
apply Polynomial.natDegree_pow_le.trans
exact mul_le_mul' le_rfl (hf i)
theorem isNoetherianRing_fin_0 [IsNoetherianRing R] :
IsNoetherianRing (MvPolynomial (Fin 0) R) := by
apply isNoetherianRing_of_ringEquiv R
symm; apply MvPolynomial.isEmptyRingEquiv R (Fin 0)
theorem isNoetherianRing_fin [IsNoetherianRing R] :
∀ {n : ℕ}, IsNoetherianRing (MvPolynomial (Fin n) R)
| 0 => isNoetherianRing_fin_0
| n + 1 =>
@isNoetherianRing_of_ringEquiv (Polynomial (MvPolynomial (Fin n) R)) _ _ _
(MvPolynomial.finSuccEquiv _ n).toRingEquiv.symm
(@Polynomial.isNoetherianRing (MvPolynomial (Fin n) R) _ isNoetherianRing_fin)
/-- The multivariate polynomial ring in finitely many variables over a noetherian ring
is itself a noetherian ring. -/
instance isNoetherianRing [Finite σ] [IsNoetherianRing R] :
IsNoetherianRing (MvPolynomial σ R) := by
cases nonempty_fintype σ
exact
@isNoetherianRing_of_ringEquiv (MvPolynomial (Fin (Fintype.card σ)) R) _ _ _
(renameEquiv R (Fintype.equivFin σ).symm).toRingEquiv isNoetherianRing_fin
/-- Auxiliary lemma:
Multivariate polynomials over an integral domain
with variables indexed by `Fin n` form an integral domain.
This fact is proven inductively,
and then used to prove the general case without any finiteness hypotheses.
See `MvPolynomial.noZeroDivisors` for the general case. -/
theorem noZeroDivisors_fin (R : Type u) [CommSemiring R] [NoZeroDivisors R] :
∀ n : ℕ, NoZeroDivisors (MvPolynomial (Fin n) R)
| 0 => (MvPolynomial.isEmptyAlgEquiv R _).injective.noZeroDivisors _ (map_zero _) (map_mul _)
| n + 1 =>
haveI := noZeroDivisors_fin R n
(MvPolynomial.finSuccEquiv R n).injective.noZeroDivisors _ (map_zero _) (map_mul _)
/-- Auxiliary definition:
Multivariate polynomials in finitely many variables over an integral domain form an integral domain.
This fact is proven by transport of structure from the `MvPolynomial.noZeroDivisors_fin`,
and then used to prove the general case without finiteness hypotheses.
See `MvPolynomial.noZeroDivisors` for the general case. -/
theorem noZeroDivisors_of_finite (R : Type u) (σ : Type v) [CommSemiring R] [Finite σ]
[NoZeroDivisors R] : NoZeroDivisors (MvPolynomial σ R) := by
cases nonempty_fintype σ
haveI := noZeroDivisors_fin R (Fintype.card σ)
exact (renameEquiv R (Fintype.equivFin σ)).injective.noZeroDivisors _ (map_zero _) (map_mul _)
instance {R : Type u} [CommSemiring R] [NoZeroDivisors R] {σ : Type v} :
NoZeroDivisors (MvPolynomial σ R) where
eq_zero_or_eq_zero_of_mul_eq_zero {p q} h := by
obtain ⟨s, p, q, rfl, rfl⟩ := exists_finset_rename₂ p q
let _nzd := MvPolynomial.noZeroDivisors_of_finite R s
have : p * q = 0 := by
apply rename_injective _ Subtype.val_injective
simpa using h
rw [mul_eq_zero] at this
apply this.imp <;> rintro rfl <;> simp
/-- The multivariate polynomial ring over an integral domain is an integral domain. -/
instance isDomain {R : Type u} {σ : Type v} [CommRing R] [IsDomain R] :
IsDomain (MvPolynomial σ R) := by
apply @NoZeroDivisors.to_isDomain (MvPolynomial σ R) _ ?_ _
apply AddMonoidAlgebra.nontrivial
-- instance {R : Type u} {σ : Type v} [CommRing R] [IsDomain R] :
-- IsDomain (MvPolynomial σ R)[X] := inferInstance
theorem map_mvPolynomial_eq_eval₂ {S : Type*} [CommSemiring S] [Finite σ]
(ϕ : MvPolynomial σ R →+* S) (p : MvPolynomial σ R) :
ϕ p = MvPolynomial.eval₂ (ϕ.comp MvPolynomial.C) (fun s => ϕ (MvPolynomial.X s)) p := by
cases nonempty_fintype σ
refine Trans.trans (congr_arg ϕ (MvPolynomial.as_sum p)) ?_
rw [MvPolynomial.eval₂_eq', map_sum ϕ]
congr
ext
simp only [monomial_eq, ϕ.map_pow, map_prod ϕ, ϕ.comp_apply, ϕ.map_mul, Finsupp.prod_pow]
/-- If every coefficient of a polynomial is in an ideal `I`, then so is the polynomial itself,
multivariate version. -/
theorem mem_ideal_of_coeff_mem_ideal (I : Ideal (MvPolynomial σ R)) (p : MvPolynomial σ R)
(hcoe : ∀ m : σ →₀ ℕ, p.coeff m ∈ I.comap (C : R →+* MvPolynomial σ R)) : p ∈ I := by
rw [as_sum p]
suffices ∀ m ∈ p.support, monomial m (MvPolynomial.coeff m p) ∈ I by
exact Submodule.sum_mem I this
intro m _
rw [← mul_one (coeff m p), ← C_mul_monomial]
suffices C (coeff m p) ∈ I by exact I.mul_mem_right (monomial m 1) this
simpa [Ideal.mem_comap] using hcoe m
|
/-- The push-forward of an ideal `I` of `R` to `MvPolynomial σ R` via inclusion
is exactly the set of polynomials whose coefficients are in `I` -/
theorem mem_map_C_iff {I : Ideal R} {f : MvPolynomial σ R} :
f ∈ (Ideal.map (C : R →+* MvPolynomial σ R) I : Ideal (MvPolynomial σ R)) ↔
∀ m : σ →₀ ℕ, f.coeff m ∈ I := by
classical
constructor
· intro hf
| Mathlib/RingTheory/Polynomial/Basic.lean | 1,085 | 1,093 |
/-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Floris van Doorn
-/
import Mathlib.Algebra.Order.SuccPred
import Mathlib.Data.Sum.Order
import Mathlib.SetTheory.Cardinal.Basic
import Mathlib.Tactic.PPWithUniv
/-!
# Ordinals
Ordinals are defined as equivalences of well-ordered sets under order isomorphism. They are endowed
with a total order, where an ordinal is smaller than another one if it embeds into it as an
initial segment (or, equivalently, in any way). This total order is well founded.
## Main definitions
* `Ordinal`: the type of ordinals (in a given universe)
* `Ordinal.type r`: given a well-founded order `r`, this is the corresponding ordinal
* `Ordinal.typein r a`: given a well-founded order `r` on a type `α`, and `a : α`, the ordinal
corresponding to all elements smaller than `a`.
* `enum r ⟨o, h⟩`: given a well-order `r` on a type `α`, and an ordinal `o` strictly smaller than
the ordinal corresponding to `r` (this is the assumption `h`), returns the `o`-th element of `α`.
In other words, the elements of `α` can be enumerated using ordinals up to `type r`.
* `Ordinal.card o`: the cardinality of an ordinal `o`.
* `Ordinal.lift` lifts an ordinal in universe `u` to an ordinal in universe `max u v`.
For a version registering additionally that this is an initial segment embedding, see
`Ordinal.liftInitialSeg`.
For a version registering that it is a principal segment embedding if `u < v`, see
`Ordinal.liftPrincipalSeg`.
* `Ordinal.omega0` or `ω` is the order type of `ℕ`. It is called this to match `Cardinal.aleph0`
and so that the omega function can be named `Ordinal.omega`. This definition is universe
polymorphic: `Ordinal.omega0.{u} : Ordinal.{u}` (contrast with `ℕ : Type`, which lives in
a specific universe). In some cases the universe level has to be given explicitly.
* `o₁ + o₂` is the order on the disjoint union of `o₁` and `o₂` obtained by declaring that
every element of `o₁` is smaller than every element of `o₂`.
The main properties of addition (and the other operations on ordinals) are stated and proved in
`Mathlib/SetTheory/Ordinal/Arithmetic.lean`.
Here, we only introduce it and prove its basic properties to deduce the fact that the order on
ordinals is total (and well founded).
* `succ o` is the successor of the ordinal `o`.
* `Cardinal.ord c`: when `c` is a cardinal, `ord c` is the smallest ordinal with this cardinality.
It is the canonical way to represent a cardinal with an ordinal.
A conditionally complete linear order with bot structure is registered on ordinals, where `⊥` is
`0`, the ordinal corresponding to the empty type, and `Inf` is the minimum for nonempty sets and `0`
for the empty set by convention.
## Notations
* `ω` is a notation for the first infinite ordinal in the locale `Ordinal`.
-/
assert_not_exists Module Field
noncomputable section
open Function Cardinal Set Equiv Order
open scoped Cardinal InitialSeg
universe u v w
variable {α : Type u} {β : Type v} {γ : Type w}
{r : α → α → Prop} {s : β → β → Prop} {t : γ → γ → Prop}
/-! ### Definition of ordinals -/
/-- Bundled structure registering a well order on a type. Ordinals will be defined as a quotient
of this type. -/
structure WellOrder : Type (u + 1) where
/-- The underlying type of the order. -/
α : Type u
/-- The underlying relation of the order. -/
r : α → α → Prop
/-- The proposition that `r` is a well-ordering for `α`. -/
wo : IsWellOrder α r
attribute [instance] WellOrder.wo
namespace WellOrder
instance inhabited : Inhabited WellOrder :=
⟨⟨PEmpty, _, inferInstanceAs (IsWellOrder PEmpty EmptyRelation)⟩⟩
end WellOrder
/-- Equivalence relation on well orders on arbitrary types in universe `u`, given by order
isomorphism. -/
instance Ordinal.isEquivalent : Setoid WellOrder where
r := fun ⟨_, r, _⟩ ⟨_, s, _⟩ => Nonempty (r ≃r s)
iseqv :=
⟨fun _ => ⟨RelIso.refl _⟩, fun ⟨e⟩ => ⟨e.symm⟩, fun ⟨e₁⟩ ⟨e₂⟩ => ⟨e₁.trans e₂⟩⟩
/-- `Ordinal.{u}` is the type of well orders in `Type u`, up to order isomorphism. -/
@[pp_with_univ]
def Ordinal : Type (u + 1) :=
Quotient Ordinal.isEquivalent
/-- A "canonical" type order-isomorphic to the ordinal `o`, living in the same universe. This is
defined through the axiom of choice.
Use this over `Iio o` only when it is paramount to have a `Type u` rather than a `Type (u + 1)`. -/
def Ordinal.toType (o : Ordinal.{u}) : Type u :=
o.out.α
instance hasWellFounded_toType (o : Ordinal) : WellFoundedRelation o.toType :=
⟨o.out.r, o.out.wo.wf⟩
instance linearOrder_toType (o : Ordinal) : LinearOrder o.toType :=
@IsWellOrder.linearOrder _ o.out.r o.out.wo
instance wellFoundedLT_toType_lt (o : Ordinal) : WellFoundedLT o.toType :=
o.out.wo.toIsWellFounded
namespace Ordinal
noncomputable instance (o : Ordinal) : SuccOrder o.toType :=
SuccOrder.ofLinearWellFoundedLT o.toType
/-! ### Basic properties of the order type -/
/-- The order type of a well order is an ordinal. -/
def type (r : α → α → Prop) [wo : IsWellOrder α r] : Ordinal :=
⟦⟨α, r, wo⟩⟧
/-- `typeLT α` is an abbreviation for the order type of the `<` relation of `α`. -/
scoped notation "typeLT " α:70 => @Ordinal.type α (· < ·) inferInstance
instance zero : Zero Ordinal :=
⟨type <| @EmptyRelation PEmpty⟩
instance inhabited : Inhabited Ordinal :=
⟨0⟩
instance one : One Ordinal :=
⟨type <| @EmptyRelation PUnit⟩
@[simp]
theorem type_toType (o : Ordinal) : typeLT o.toType = o :=
o.out_eq
theorem type_eq {α β} {r : α → α → Prop} {s : β → β → Prop} [IsWellOrder α r] [IsWellOrder β s] :
type r = type s ↔ Nonempty (r ≃r s) :=
Quotient.eq'
theorem _root_.RelIso.ordinal_type_eq {α β} {r : α → α → Prop} {s : β → β → Prop} [IsWellOrder α r]
[IsWellOrder β s] (h : r ≃r s) : type r = type s :=
type_eq.2 ⟨h⟩
theorem type_eq_zero_of_empty (r) [IsWellOrder α r] [IsEmpty α] : type r = 0 :=
(RelIso.relIsoOfIsEmpty r _).ordinal_type_eq
@[simp]
theorem type_eq_zero_iff_isEmpty [IsWellOrder α r] : type r = 0 ↔ IsEmpty α :=
⟨fun h =>
let ⟨s⟩ := type_eq.1 h
s.toEquiv.isEmpty,
@type_eq_zero_of_empty α r _⟩
theorem type_ne_zero_iff_nonempty [IsWellOrder α r] : type r ≠ 0 ↔ Nonempty α := by simp
theorem type_ne_zero_of_nonempty (r) [IsWellOrder α r] [h : Nonempty α] : type r ≠ 0 :=
type_ne_zero_iff_nonempty.2 h
theorem type_pEmpty : type (@EmptyRelation PEmpty) = 0 :=
rfl
theorem type_empty : type (@EmptyRelation Empty) = 0 :=
type_eq_zero_of_empty _
theorem type_eq_one_of_unique (r) [IsWellOrder α r] [Nonempty α] [Subsingleton α] : type r = 1 := by
cases nonempty_unique α
exact (RelIso.ofUniqueOfIrrefl r _).ordinal_type_eq
@[simp]
theorem type_eq_one_iff_unique [IsWellOrder α r] : type r = 1 ↔ Nonempty (Unique α) :=
⟨fun h ↦ let ⟨s⟩ := type_eq.1 h; ⟨s.toEquiv.unique⟩,
fun ⟨_⟩ ↦ type_eq_one_of_unique r⟩
theorem type_pUnit : type (@EmptyRelation PUnit) = 1 :=
rfl
theorem type_unit : type (@EmptyRelation Unit) = 1 :=
rfl
@[simp]
theorem toType_empty_iff_eq_zero {o : Ordinal} : IsEmpty o.toType ↔ o = 0 := by
rw [← @type_eq_zero_iff_isEmpty o.toType (· < ·), type_toType]
instance isEmpty_toType_zero : IsEmpty (toType 0) :=
toType_empty_iff_eq_zero.2 rfl
@[simp]
theorem toType_nonempty_iff_ne_zero {o : Ordinal} : Nonempty o.toType ↔ o ≠ 0 := by
rw [← @type_ne_zero_iff_nonempty o.toType (· < ·), type_toType]
protected theorem one_ne_zero : (1 : Ordinal) ≠ 0 :=
type_ne_zero_of_nonempty _
instance nontrivial : Nontrivial Ordinal.{u} :=
⟨⟨1, 0, Ordinal.one_ne_zero⟩⟩
/-- `Quotient.inductionOn` specialized to ordinals.
Not to be confused with well-founded recursion `Ordinal.induction`. -/
@[elab_as_elim]
theorem inductionOn {C : Ordinal → Prop} (o : Ordinal)
(H : ∀ (α r) [IsWellOrder α r], C (type r)) : C o :=
Quot.inductionOn o fun ⟨α, r, wo⟩ => @H α r wo
/-- `Quotient.inductionOn₂` specialized to ordinals.
Not to be confused with well-founded recursion `Ordinal.induction`. -/
@[elab_as_elim]
theorem inductionOn₂ {C : Ordinal → Ordinal → Prop} (o₁ o₂ : Ordinal)
(H : ∀ (α r) [IsWellOrder α r] (β s) [IsWellOrder β s], C (type r) (type s)) : C o₁ o₂ :=
Quotient.inductionOn₂ o₁ o₂ fun ⟨α, r, wo₁⟩ ⟨β, s, wo₂⟩ => @H α r wo₁ β s wo₂
/-- `Quotient.inductionOn₃` specialized to ordinals.
Not to be confused with well-founded recursion `Ordinal.induction`. -/
@[elab_as_elim]
theorem inductionOn₃ {C : Ordinal → Ordinal → Ordinal → Prop} (o₁ o₂ o₃ : Ordinal)
(H : ∀ (α r) [IsWellOrder α r] (β s) [IsWellOrder β s] (γ t) [IsWellOrder γ t],
C (type r) (type s) (type t)) : C o₁ o₂ o₃ :=
Quotient.inductionOn₃ o₁ o₂ o₃ fun ⟨α, r, wo₁⟩ ⟨β, s, wo₂⟩ ⟨γ, t, wo₃⟩ =>
@H α r wo₁ β s wo₂ γ t wo₃
open Classical in
/-- To prove a result on ordinals, it suffices to prove it for order types of well-orders. -/
@[elab_as_elim]
theorem inductionOnWellOrder {C : Ordinal → Prop} (o : Ordinal)
(H : ∀ (α) [LinearOrder α] [WellFoundedLT α], C (typeLT α)) : C o :=
inductionOn o fun α r wo ↦ @H α (linearOrderOfSTO r) wo.toIsWellFounded
open Classical in
/-- To define a function on ordinals, it suffices to define them on order types of well-orders.
Since `LinearOrder` is data-carrying, `liftOnWellOrder_type` is not a definitional equality, unlike
`Quotient.liftOn_mk` which is always def-eq. -/
def liftOnWellOrder {δ : Sort v} (o : Ordinal) (f : ∀ (α) [LinearOrder α] [WellFoundedLT α], δ)
(c : ∀ (α) [LinearOrder α] [WellFoundedLT α] (β) [LinearOrder β] [WellFoundedLT β],
typeLT α = typeLT β → f α = f β) : δ :=
Quotient.liftOn o (fun w ↦ @f w.α (linearOrderOfSTO w.r) w.wo.toIsWellFounded)
fun w₁ w₂ h ↦ @c
w₁.α (linearOrderOfSTO w₁.r) w₁.wo.toIsWellFounded
w₂.α (linearOrderOfSTO w₂.r) w₂.wo.toIsWellFounded
(Quotient.sound h)
@[simp]
theorem liftOnWellOrder_type {δ : Sort v} (f : ∀ (α) [LinearOrder α] [WellFoundedLT α], δ)
(c : ∀ (α) [LinearOrder α] [WellFoundedLT α] (β) [LinearOrder β] [WellFoundedLT β],
typeLT α = typeLT β → f α = f β) {γ} [LinearOrder γ] [WellFoundedLT γ] :
liftOnWellOrder (typeLT γ) f c = f γ := by
change Quotient.liftOn' ⟦_⟧ _ _ = _
rw [Quotient.liftOn'_mk]
congr
exact LinearOrder.ext_lt fun _ _ ↦ Iff.rfl
/-! ### The order on ordinals -/
/--
For `Ordinal`:
* less-equal is defined such that well orders `r` and `s` satisfy `type r ≤ type s` if there exists
a function embedding `r` as an *initial* segment of `s`.
* less-than is defined such that well orders `r` and `s` satisfy `type r < type s` if there exists
a function embedding `r` as a *principal* segment of `s`.
Note that most of the relevant results on initial and principal segments are proved in the
`Order.InitialSeg` file.
-/
instance partialOrder : PartialOrder Ordinal where
le a b :=
Quotient.liftOn₂ a b (fun ⟨_, r, _⟩ ⟨_, s, _⟩ => Nonempty (r ≼i s))
fun _ _ _ _ ⟨f⟩ ⟨g⟩ => propext
⟨fun ⟨h⟩ => ⟨f.symm.toInitialSeg.trans <| h.trans g.toInitialSeg⟩, fun ⟨h⟩ =>
⟨f.toInitialSeg.trans <| h.trans g.symm.toInitialSeg⟩⟩
lt a b :=
Quotient.liftOn₂ a b (fun ⟨_, r, _⟩ ⟨_, s, _⟩ => Nonempty (r ≺i s))
fun _ _ _ _ ⟨f⟩ ⟨g⟩ => propext
⟨fun ⟨h⟩ => ⟨PrincipalSeg.relIsoTrans f.symm <| h.transRelIso g⟩,
fun ⟨h⟩ => ⟨PrincipalSeg.relIsoTrans f <| h.transRelIso g.symm⟩⟩
le_refl := Quot.ind fun ⟨_, _, _⟩ => ⟨InitialSeg.refl _⟩
le_trans a b c :=
Quotient.inductionOn₃ a b c fun _ _ _ ⟨f⟩ ⟨g⟩ => ⟨f.trans g⟩
lt_iff_le_not_le a b :=
Quotient.inductionOn₂ a b fun _ _ =>
⟨fun ⟨f⟩ => ⟨⟨f⟩, fun ⟨g⟩ => (f.transInitial g).irrefl⟩, fun ⟨⟨f⟩, h⟩ =>
f.principalSumRelIso.recOn (fun g => ⟨g⟩) fun g => (h ⟨g.symm.toInitialSeg⟩).elim⟩
le_antisymm a b :=
Quotient.inductionOn₂ a b fun _ _ ⟨h₁⟩ ⟨h₂⟩ =>
Quot.sound ⟨InitialSeg.antisymm h₁ h₂⟩
instance : LinearOrder Ordinal :=
{inferInstanceAs (PartialOrder Ordinal) with
le_total := fun a b => Quotient.inductionOn₂ a b fun ⟨_, r, _⟩ ⟨_, s, _⟩ =>
(InitialSeg.total r s).recOn (fun f => Or.inl ⟨f⟩) fun f => Or.inr ⟨f⟩
toDecidableLE := Classical.decRel _ }
theorem _root_.InitialSeg.ordinal_type_le {α β} {r : α → α → Prop} {s : β → β → Prop}
[IsWellOrder α r] [IsWellOrder β s] (h : r ≼i s) : type r ≤ type s :=
⟨h⟩
theorem _root_.RelEmbedding.ordinal_type_le {α β} {r : α → α → Prop} {s : β → β → Prop}
[IsWellOrder α r] [IsWellOrder β s] (h : r ↪r s) : type r ≤ type s :=
⟨h.collapse⟩
theorem _root_.PrincipalSeg.ordinal_type_lt {α β} {r : α → α → Prop} {s : β → β → Prop}
[IsWellOrder α r] [IsWellOrder β s] (h : r ≺i s) : type r < type s :=
⟨h⟩
@[simp]
protected theorem zero_le (o : Ordinal) : 0 ≤ o :=
inductionOn o fun _ r _ => (InitialSeg.ofIsEmpty _ r).ordinal_type_le
instance : OrderBot Ordinal where
bot := 0
bot_le := Ordinal.zero_le
@[simp]
theorem bot_eq_zero : (⊥ : Ordinal) = 0 :=
rfl
instance instIsEmptyIioZero : IsEmpty (Iio (0 : Ordinal)) := by
simp [← bot_eq_zero]
@[simp]
protected theorem le_zero {o : Ordinal} : o ≤ 0 ↔ o = 0 :=
le_bot_iff
protected theorem pos_iff_ne_zero {o : Ordinal} : 0 < o ↔ o ≠ 0 :=
bot_lt_iff_ne_bot
protected theorem not_lt_zero (o : Ordinal) : ¬o < 0 :=
not_lt_bot
theorem eq_zero_or_pos : ∀ a : Ordinal, a = 0 ∨ 0 < a :=
eq_bot_or_bot_lt
instance : ZeroLEOneClass Ordinal :=
⟨Ordinal.zero_le _⟩
instance instNeZeroOne : NeZero (1 : Ordinal) :=
⟨Ordinal.one_ne_zero⟩
theorem type_le_iff {α β} {r : α → α → Prop} {s : β → β → Prop} [IsWellOrder α r]
[IsWellOrder β s] : type r ≤ type s ↔ Nonempty (r ≼i s) :=
Iff.rfl
theorem type_le_iff' {α β} {r : α → α → Prop} {s : β → β → Prop} [IsWellOrder α r]
[IsWellOrder β s] : type r ≤ type s ↔ Nonempty (r ↪r s) :=
⟨fun ⟨f⟩ => ⟨f⟩, fun ⟨f⟩ => ⟨f.collapse⟩⟩
theorem type_lt_iff {α β} {r : α → α → Prop} {s : β → β → Prop} [IsWellOrder α r]
[IsWellOrder β s] : type r < type s ↔ Nonempty (r ≺i s) :=
Iff.rfl
/-- Given two ordinals `α ≤ β`, then `initialSegToType α β` is the initial segment embedding of
`α.toType` into `β.toType`. -/
def initialSegToType {α β : Ordinal} (h : α ≤ β) : α.toType ≤i β.toType := by
apply Classical.choice (type_le_iff.mp _)
rwa [type_toType, type_toType]
/-- Given two ordinals `α < β`, then `principalSegToType α β` is the principal segment embedding
of `α.toType` into `β.toType`. -/
def principalSegToType {α β : Ordinal} (h : α < β) : α.toType <i β.toType := by
apply Classical.choice (type_lt_iff.mp _)
rwa [type_toType, type_toType]
/-! ### Enumerating elements in a well-order with ordinals -/
/-- The order type of an element inside a well order.
This is registered as a principal segment embedding into the ordinals, with top `type r`. -/
def typein (r : α → α → Prop) [IsWellOrder α r] : @PrincipalSeg α Ordinal.{u} r (· < ·) := by
refine ⟨RelEmbedding.ofMonotone _ fun a b ha ↦
((PrincipalSeg.ofElement r a).codRestrict _ ?_ ?_).ordinal_type_lt, type r, fun a ↦ ⟨?_, ?_⟩⟩
· rintro ⟨c, hc⟩
exact trans hc ha
· exact ha
· rintro ⟨b, rfl⟩
exact (PrincipalSeg.ofElement _ _).ordinal_type_lt
· refine inductionOn a ?_
rintro β s wo ⟨g⟩
exact ⟨_, g.subrelIso.ordinal_type_eq⟩
@[simp]
theorem type_subrel (r : α → α → Prop) [IsWellOrder α r] (a : α) :
type (Subrel r (r · a)) = typein r a :=
rfl
@[simp]
theorem top_typein (r : α → α → Prop) [IsWellOrder α r] : (typein r).top = type r :=
rfl
theorem typein_lt_type (r : α → α → Prop) [IsWellOrder α r] (a : α) : typein r a < type r :=
(typein r).lt_top a
theorem typein_lt_self {o : Ordinal} (i : o.toType) : typein (α := o.toType) (· < ·) i < o := by
simp_rw [← type_toType o]
apply typein_lt_type
@[simp]
theorem typein_top {α β} {r : α → α → Prop} {s : β → β → Prop}
[IsWellOrder α r] [IsWellOrder β s] (f : r ≺i s) : typein s f.top = type r :=
f.subrelIso.ordinal_type_eq
@[simp]
theorem typein_lt_typein (r : α → α → Prop) [IsWellOrder α r] {a b : α} :
typein r a < typein r b ↔ r a b :=
(typein r).map_rel_iff
@[simp]
theorem typein_le_typein (r : α → α → Prop) [IsWellOrder α r] {a b : α} :
typein r a ≤ typein r b ↔ ¬r b a := by
rw [← not_lt, typein_lt_typein]
theorem typein_injective (r : α → α → Prop) [IsWellOrder α r] : Injective (typein r) :=
(typein r).injective
theorem typein_inj (r : α → α → Prop) [IsWellOrder α r] {a b} : typein r a = typein r b ↔ a = b :=
(typein_injective r).eq_iff
theorem mem_range_typein_iff (r : α → α → Prop) [IsWellOrder α r] {o} :
o ∈ Set.range (typein r) ↔ o < type r :=
(typein r).mem_range_iff_rel
theorem typein_surj (r : α → α → Prop) [IsWellOrder α r] {o} (h : o < type r) :
o ∈ Set.range (typein r) :=
(typein r).mem_range_of_rel_top h
theorem typein_surjOn (r : α → α → Prop) [IsWellOrder α r] :
Set.SurjOn (typein r) Set.univ (Set.Iio (type r)) :=
(typein r).surjOn
/-- A well order `r` is order-isomorphic to the set of ordinals smaller than `type r`.
`enum r ⟨o, h⟩` is the `o`-th element of `α` ordered by `r`.
That is, `enum` maps an initial segment of the ordinals, those less than the order type of `r`, to
| the elements of `α`. -/
@[simps! symm_apply_coe]
def enum (r : α → α → Prop) [IsWellOrder α r] : (· < · : Iio (type r) → Iio (type r) → Prop) ≃r r :=
(typein r).subrelIso
| Mathlib/SetTheory/Ordinal/Basic.lean | 445 | 448 |
/-
Copyright (c) 2019 Kim Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kim Morrison, Bhavik Mehta
-/
import Mathlib.CategoryTheory.Comma.Over.Basic
import Mathlib.CategoryTheory.Discrete.Basic
import Mathlib.CategoryTheory.EpiMono
import Mathlib.CategoryTheory.Limits.Shapes.Terminal
/-!
# Binary (co)products
We define a category `WalkingPair`, which is the index category
for a binary (co)product diagram. A convenience method `pair X Y`
constructs the functor from the walking pair, hitting the given objects.
We define `prod X Y` and `coprod X Y` as limits and colimits of such functors.
Typeclasses `HasBinaryProducts` and `HasBinaryCoproducts` assert the existence
of (co)limits shaped as walking pairs.
We include lemmas for simplifying equations involving projections and coprojections, and define
braiding and associating isomorphisms, and the product comparison morphism.
## References
* [Stacks: Products of pairs](https://stacks.math.columbia.edu/tag/001R)
* [Stacks: coproducts of pairs](https://stacks.math.columbia.edu/tag/04AN)
-/
universe v v₁ u u₁ u₂
open CategoryTheory
namespace CategoryTheory.Limits
/-- The type of objects for the diagram indexing a binary (co)product. -/
inductive WalkingPair : Type
| left
| right
deriving DecidableEq, Inhabited
open WalkingPair
/-- The equivalence swapping left and right.
-/
def WalkingPair.swap : WalkingPair ≃ WalkingPair where
toFun
| left => right
| right => left
invFun
| left => right
| right => left
left_inv j := by cases j <;> rfl
right_inv j := by cases j <;> rfl
@[simp]
theorem WalkingPair.swap_apply_left : WalkingPair.swap left = right :=
rfl
@[simp]
theorem WalkingPair.swap_apply_right : WalkingPair.swap right = left :=
rfl
@[simp]
theorem WalkingPair.swap_symm_apply_tt : WalkingPair.swap.symm left = right :=
rfl
@[simp]
theorem WalkingPair.swap_symm_apply_ff : WalkingPair.swap.symm right = left :=
rfl
/-- An equivalence from `WalkingPair` to `Bool`, sometimes useful when reindexing limits.
-/
def WalkingPair.equivBool : WalkingPair ≃ Bool where
toFun
| left => true
| right => false
-- to match equiv.sum_equiv_sigma_bool
invFun b := Bool.recOn b right left
left_inv j := by cases j <;> rfl
right_inv b := by cases b <;> rfl
@[simp]
theorem WalkingPair.equivBool_apply_left : WalkingPair.equivBool left = true :=
rfl
@[simp]
theorem WalkingPair.equivBool_apply_right : WalkingPair.equivBool right = false :=
rfl
@[simp]
theorem WalkingPair.equivBool_symm_apply_true : WalkingPair.equivBool.symm true = left :=
rfl
@[simp]
theorem WalkingPair.equivBool_symm_apply_false : WalkingPair.equivBool.symm false = right :=
rfl
variable {C : Type u}
/-- The function on the walking pair, sending the two points to `X` and `Y`. -/
def pairFunction (X Y : C) : WalkingPair → C := fun j => WalkingPair.casesOn j X Y
@[simp]
theorem pairFunction_left (X Y : C) : pairFunction X Y left = X :=
rfl
@[simp]
theorem pairFunction_right (X Y : C) : pairFunction X Y right = Y :=
rfl
variable [Category.{v} C]
/-- The diagram on the walking pair, sending the two points to `X` and `Y`. -/
def pair (X Y : C) : Discrete WalkingPair ⥤ C :=
Discrete.functor fun j => WalkingPair.casesOn j X Y
@[simp]
theorem pair_obj_left (X Y : C) : (pair X Y).obj ⟨left⟩ = X :=
rfl
@[simp]
theorem pair_obj_right (X Y : C) : (pair X Y).obj ⟨right⟩ = Y :=
rfl
section
variable {F G : Discrete WalkingPair ⥤ C} (f : F.obj ⟨left⟩ ⟶ G.obj ⟨left⟩)
(g : F.obj ⟨right⟩ ⟶ G.obj ⟨right⟩)
attribute [local aesop safe tactic (rule_sets := [CategoryTheory])]
CategoryTheory.Discrete.discreteCases
/-- The natural transformation between two functors out of the
walking pair, specified by its components. -/
def mapPair : F ⟶ G where
app
| ⟨left⟩ => f
| ⟨right⟩ => g
naturality := fun ⟨X⟩ ⟨Y⟩ ⟨⟨u⟩⟩ => by aesop_cat
@[simp]
theorem mapPair_left : (mapPair f g).app ⟨left⟩ = f :=
rfl
@[simp]
theorem mapPair_right : (mapPair f g).app ⟨right⟩ = g :=
rfl
/-- The natural isomorphism between two functors out of the walking pair, specified by its
components. -/
@[simps!]
def mapPairIso (f : F.obj ⟨left⟩ ≅ G.obj ⟨left⟩) (g : F.obj ⟨right⟩ ≅ G.obj ⟨right⟩) : F ≅ G :=
NatIso.ofComponents (fun j ↦ match j with
| ⟨left⟩ => f
| ⟨right⟩ => g)
(fun ⟨⟨u⟩⟩ => by aesop_cat)
end
/-- Every functor out of the walking pair is naturally isomorphic (actually, equal) to a `pair` -/
@[simps!]
def diagramIsoPair (F : Discrete WalkingPair ⥤ C) :
F ≅ pair (F.obj ⟨WalkingPair.left⟩) (F.obj ⟨WalkingPair.right⟩) :=
mapPairIso (Iso.refl _) (Iso.refl _)
section
variable {D : Type u₁} [Category.{v₁} D]
/-- The natural isomorphism between `pair X Y ⋙ F` and `pair (F.obj X) (F.obj Y)`. -/
def pairComp (X Y : C) (F : C ⥤ D) : pair X Y ⋙ F ≅ pair (F.obj X) (F.obj Y) :=
diagramIsoPair _
end
/-- A binary fan is just a cone on a diagram indexing a product. -/
abbrev BinaryFan (X Y : C) :=
Cone (pair X Y)
/-- The first projection of a binary fan. -/
abbrev BinaryFan.fst {X Y : C} (s : BinaryFan X Y) :=
s.π.app ⟨WalkingPair.left⟩
/-- The second projection of a binary fan. -/
abbrev BinaryFan.snd {X Y : C} (s : BinaryFan X Y) :=
s.π.app ⟨WalkingPair.right⟩
@[simp]
theorem BinaryFan.π_app_left {X Y : C} (s : BinaryFan X Y) : s.π.app ⟨WalkingPair.left⟩ = s.fst :=
rfl
@[simp]
theorem BinaryFan.π_app_right {X Y : C} (s : BinaryFan X Y) : s.π.app ⟨WalkingPair.right⟩ = s.snd :=
rfl
/-- Constructs an isomorphism of `BinaryFan`s out of an isomorphism of the tips that commutes with
the projections. -/
def BinaryFan.ext {A B : C} {c c' : BinaryFan A B} (e : c.pt ≅ c'.pt)
(h₁ : c.fst = e.hom ≫ c'.fst) (h₂ : c.snd = e.hom ≫ c'.snd) : c ≅ c' :=
Cones.ext e (fun j => by rcases j with ⟨⟨⟩⟩ <;> assumption)
@[simp]
lemma BinaryFan.ext_hom_hom {A B : C} {c c' : BinaryFan A B} (e : c.pt ≅ c'.pt)
(h₁ : c.fst = e.hom ≫ c'.fst) (h₂ : c.snd = e.hom ≫ c'.snd) :
(ext e h₁ h₂).hom.hom = e.hom := rfl
/-- A convenient way to show that a binary fan is a limit. -/
def BinaryFan.IsLimit.mk {X Y : C} (s : BinaryFan X Y)
(lift : ∀ {T : C} (_ : T ⟶ X) (_ : T ⟶ Y), T ⟶ s.pt)
(hl₁ : ∀ {T : C} (f : T ⟶ X) (g : T ⟶ Y), lift f g ≫ s.fst = f)
(hl₂ : ∀ {T : C} (f : T ⟶ X) (g : T ⟶ Y), lift f g ≫ s.snd = g)
(uniq :
∀ {T : C} (f : T ⟶ X) (g : T ⟶ Y) (m : T ⟶ s.pt) (_ : m ≫ s.fst = f) (_ : m ≫ s.snd = g),
m = lift f g) :
IsLimit s :=
Limits.IsLimit.mk (fun t => lift (BinaryFan.fst t) (BinaryFan.snd t))
(by
rintro t (rfl | rfl)
· exact hl₁ _ _
· exact hl₂ _ _)
fun _ _ h => uniq _ _ _ (h ⟨WalkingPair.left⟩) (h ⟨WalkingPair.right⟩)
theorem BinaryFan.IsLimit.hom_ext {W X Y : C} {s : BinaryFan X Y} (h : IsLimit s) {f g : W ⟶ s.pt}
(h₁ : f ≫ s.fst = g ≫ s.fst) (h₂ : f ≫ s.snd = g ≫ s.snd) : f = g :=
h.hom_ext fun j => Discrete.recOn j fun j => WalkingPair.casesOn j h₁ h₂
/-- A binary cofan is just a cocone on a diagram indexing a coproduct. -/
abbrev BinaryCofan (X Y : C) := Cocone (pair X Y)
/-- The first inclusion of a binary cofan. -/
abbrev BinaryCofan.inl {X Y : C} (s : BinaryCofan X Y) := s.ι.app ⟨WalkingPair.left⟩
/-- The second inclusion of a binary cofan. -/
abbrev BinaryCofan.inr {X Y : C} (s : BinaryCofan X Y) := s.ι.app ⟨WalkingPair.right⟩
/-- Constructs an isomorphism of `BinaryCofan`s out of an isomorphism of the tips that commutes with
the injections. -/
def BinaryCofan.ext {A B : C} {c c' : BinaryCofan A B} (e : c.pt ≅ c'.pt)
(h₁ : c.inl ≫ e.hom = c'.inl) (h₂ : c.inr ≫ e.hom = c'.inr) : c ≅ c' :=
Cocones.ext e (fun j => by rcases j with ⟨⟨⟩⟩ <;> assumption)
@[simp]
lemma BinaryCofan.ext_hom_hom {A B : C} {c c' : BinaryCofan A B} (e : c.pt ≅ c'.pt)
(h₁ : c.inl ≫ e.hom = c'.inl) (h₂ : c.inr ≫ e.hom = c'.inr) :
(ext e h₁ h₂).hom.hom = e.hom := rfl
@[simp]
theorem BinaryCofan.ι_app_left {X Y : C} (s : BinaryCofan X Y) :
s.ι.app ⟨WalkingPair.left⟩ = s.inl := rfl
@[simp]
theorem BinaryCofan.ι_app_right {X Y : C} (s : BinaryCofan X Y) :
s.ι.app ⟨WalkingPair.right⟩ = s.inr := rfl
/-- A convenient way to show that a binary cofan is a colimit. -/
def BinaryCofan.IsColimit.mk {X Y : C} (s : BinaryCofan X Y)
(desc : ∀ {T : C} (_ : X ⟶ T) (_ : Y ⟶ T), s.pt ⟶ T)
(hd₁ : ∀ {T : C} (f : X ⟶ T) (g : Y ⟶ T), s.inl ≫ desc f g = f)
(hd₂ : ∀ {T : C} (f : X ⟶ T) (g : Y ⟶ T), s.inr ≫ desc f g = g)
(uniq :
∀ {T : C} (f : X ⟶ T) (g : Y ⟶ T) (m : s.pt ⟶ T) (_ : s.inl ≫ m = f) (_ : s.inr ≫ m = g),
m = desc f g) :
IsColimit s :=
Limits.IsColimit.mk (fun t => desc (BinaryCofan.inl t) (BinaryCofan.inr t))
(by
rintro t (rfl | rfl)
· exact hd₁ _ _
· exact hd₂ _ _)
fun _ _ h => uniq _ _ _ (h ⟨WalkingPair.left⟩) (h ⟨WalkingPair.right⟩)
theorem BinaryCofan.IsColimit.hom_ext {W X Y : C} {s : BinaryCofan X Y} (h : IsColimit s)
{f g : s.pt ⟶ W} (h₁ : s.inl ≫ f = s.inl ≫ g) (h₂ : s.inr ≫ f = s.inr ≫ g) : f = g :=
h.hom_ext fun j => Discrete.recOn j fun j => WalkingPair.casesOn j h₁ h₂
variable {X Y : C}
section
attribute [local aesop safe tactic (rule_sets := [CategoryTheory])]
CategoryTheory.Discrete.discreteCases
-- Porting note: would it be okay to use this more generally?
attribute [local aesop safe cases (rule_sets := [CategoryTheory])] Eq
/-- A binary fan with vertex `P` consists of the two projections `π₁ : P ⟶ X` and `π₂ : P ⟶ Y`. -/
@[simps pt]
def BinaryFan.mk {P : C} (π₁ : P ⟶ X) (π₂ : P ⟶ Y) : BinaryFan X Y where
pt := P
π := { app := fun | { as := j } => match j with | left => π₁ | right => π₂ }
/-- A binary cofan with vertex `P` consists of the two inclusions `ι₁ : X ⟶ P` and `ι₂ : Y ⟶ P`. -/
@[simps pt]
def BinaryCofan.mk {P : C} (ι₁ : X ⟶ P) (ι₂ : Y ⟶ P) : BinaryCofan X Y where
pt := P
ι := { app := fun | { as := j } => match j with | left => ι₁ | right => ι₂ }
end
@[simp]
theorem BinaryFan.mk_fst {P : C} (π₁ : P ⟶ X) (π₂ : P ⟶ Y) : (BinaryFan.mk π₁ π₂).fst = π₁ :=
rfl
@[simp]
theorem BinaryFan.mk_snd {P : C} (π₁ : P ⟶ X) (π₂ : P ⟶ Y) : (BinaryFan.mk π₁ π₂).snd = π₂ :=
rfl
@[simp]
theorem BinaryCofan.mk_inl {P : C} (ι₁ : X ⟶ P) (ι₂ : Y ⟶ P) : (BinaryCofan.mk ι₁ ι₂).inl = ι₁ :=
rfl
@[simp]
theorem BinaryCofan.mk_inr {P : C} (ι₁ : X ⟶ P) (ι₂ : Y ⟶ P) : (BinaryCofan.mk ι₁ ι₂).inr = ι₂ :=
rfl
/-- Every `BinaryFan` is isomorphic to an application of `BinaryFan.mk`. -/
def isoBinaryFanMk {X Y : C} (c : BinaryFan X Y) : c ≅ BinaryFan.mk c.fst c.snd :=
Cones.ext (Iso.refl _) fun ⟨l⟩ => by cases l; repeat simp
/-- Every `BinaryFan` is isomorphic to an application of `BinaryFan.mk`. -/
def isoBinaryCofanMk {X Y : C} (c : BinaryCofan X Y) : c ≅ BinaryCofan.mk c.inl c.inr :=
Cocones.ext (Iso.refl _) fun ⟨l⟩ => by cases l; repeat simp
/-- This is a more convenient formulation to show that a `BinaryFan` constructed using
`BinaryFan.mk` is a limit cone.
-/
def BinaryFan.isLimitMk {W : C} {fst : W ⟶ X} {snd : W ⟶ Y} (lift : ∀ s : BinaryFan X Y, s.pt ⟶ W)
(fac_left : ∀ s : BinaryFan X Y, lift s ≫ fst = s.fst)
(fac_right : ∀ s : BinaryFan X Y, lift s ≫ snd = s.snd)
(uniq :
∀ (s : BinaryFan X Y) (m : s.pt ⟶ W) (_ : m ≫ fst = s.fst) (_ : m ≫ snd = s.snd),
m = lift s) :
IsLimit (BinaryFan.mk fst snd) :=
{ lift := lift
fac := fun s j => by
rcases j with ⟨⟨⟩⟩
exacts [fac_left s, fac_right s]
uniq := fun s m w => uniq s m (w ⟨WalkingPair.left⟩) (w ⟨WalkingPair.right⟩) }
/-- This is a more convenient formulation to show that a `BinaryCofan` constructed using
`BinaryCofan.mk` is a colimit cocone.
-/
def BinaryCofan.isColimitMk {W : C} {inl : X ⟶ W} {inr : Y ⟶ W}
(desc : ∀ s : BinaryCofan X Y, W ⟶ s.pt)
(fac_left : ∀ s : BinaryCofan X Y, inl ≫ desc s = s.inl)
(fac_right : ∀ s : BinaryCofan X Y, inr ≫ desc s = s.inr)
(uniq :
∀ (s : BinaryCofan X Y) (m : W ⟶ s.pt) (_ : inl ≫ m = s.inl) (_ : inr ≫ m = s.inr),
m = desc s) :
IsColimit (BinaryCofan.mk inl inr) :=
{ desc := desc
fac := fun s j => by
rcases j with ⟨⟨⟩⟩
exacts [fac_left s, fac_right s]
uniq := fun s m w => uniq s m (w ⟨WalkingPair.left⟩) (w ⟨WalkingPair.right⟩) }
/-- If `s` is a limit binary fan over `X` and `Y`, then every pair of morphisms `f : W ⟶ X` and
`g : W ⟶ Y` induces a morphism `l : W ⟶ s.pt` satisfying `l ≫ s.fst = f` and `l ≫ s.snd = g`.
-/
@[simps]
def BinaryFan.IsLimit.lift' {W X Y : C} {s : BinaryFan X Y} (h : IsLimit s) (f : W ⟶ X)
(g : W ⟶ Y) : { l : W ⟶ s.pt // l ≫ s.fst = f ∧ l ≫ s.snd = g } :=
⟨h.lift <| BinaryFan.mk f g, h.fac _ _, h.fac _ _⟩
/-- If `s` is a colimit binary cofan over `X` and `Y`,, then every pair of morphisms `f : X ⟶ W` and
`g : Y ⟶ W` induces a morphism `l : s.pt ⟶ W` satisfying `s.inl ≫ l = f` and `s.inr ≫ l = g`.
-/
@[simps]
def BinaryCofan.IsColimit.desc' {W X Y : C} {s : BinaryCofan X Y} (h : IsColimit s) (f : X ⟶ W)
(g : Y ⟶ W) : { l : s.pt ⟶ W // s.inl ≫ l = f ∧ s.inr ≫ l = g } :=
⟨h.desc <| BinaryCofan.mk f g, h.fac _ _, h.fac _ _⟩
/-- Binary products are symmetric. -/
def BinaryFan.isLimitFlip {X Y : C} {c : BinaryFan X Y} (hc : IsLimit c) :
IsLimit (BinaryFan.mk c.snd c.fst) :=
BinaryFan.isLimitMk (fun s => hc.lift (BinaryFan.mk s.snd s.fst)) (fun _ => hc.fac _ _)
(fun _ => hc.fac _ _) fun s _ e₁ e₂ =>
BinaryFan.IsLimit.hom_ext hc
(e₂.trans (hc.fac (BinaryFan.mk s.snd s.fst) ⟨WalkingPair.left⟩).symm)
(e₁.trans (hc.fac (BinaryFan.mk s.snd s.fst) ⟨WalkingPair.right⟩).symm)
theorem BinaryFan.isLimit_iff_isIso_fst {X Y : C} (h : IsTerminal Y) (c : BinaryFan X Y) :
Nonempty (IsLimit c) ↔ IsIso c.fst := by
constructor
· rintro ⟨H⟩
obtain ⟨l, hl, -⟩ := BinaryFan.IsLimit.lift' H (𝟙 X) (h.from X)
exact
⟨⟨l,
BinaryFan.IsLimit.hom_ext H (by simpa [hl, -Category.comp_id] using Category.comp_id _)
(h.hom_ext _ _),
hl⟩⟩
· intro
exact
⟨BinaryFan.IsLimit.mk _ (fun f _ => f ≫ inv c.fst) (fun _ _ => by simp)
(fun _ _ => h.hom_ext _ _) fun _ _ _ e _ => by simp [← e]⟩
theorem BinaryFan.isLimit_iff_isIso_snd {X Y : C} (h : IsTerminal X) (c : BinaryFan X Y) :
Nonempty (IsLimit c) ↔ IsIso c.snd := by
refine Iff.trans ?_ (BinaryFan.isLimit_iff_isIso_fst h (BinaryFan.mk c.snd c.fst))
exact
⟨fun h => ⟨BinaryFan.isLimitFlip h.some⟩, fun h =>
⟨(BinaryFan.isLimitFlip h.some).ofIsoLimit (isoBinaryFanMk c).symm⟩⟩
/-- If `X' ≅ X`, then `X × Y` also is the product of `X'` and `Y`. -/
noncomputable def BinaryFan.isLimitCompLeftIso {X Y X' : C} (c : BinaryFan X Y) (f : X ⟶ X')
[IsIso f] (h : IsLimit c) : IsLimit (BinaryFan.mk (c.fst ≫ f) c.snd) := by
fapply BinaryFan.isLimitMk
· exact fun s => h.lift (BinaryFan.mk (s.fst ≫ inv f) s.snd)
· intro s -- Porting note: simp timed out here
simp only [Category.comp_id,BinaryFan.π_app_left,IsIso.inv_hom_id,
BinaryFan.mk_fst,IsLimit.fac_assoc,eq_self_iff_true,Category.assoc]
· intro s -- Porting note: simp timed out here
simp only [BinaryFan.π_app_right,BinaryFan.mk_snd,eq_self_iff_true,IsLimit.fac]
· intro s m e₁ e₂
-- Porting note: simpa timed out here also
apply BinaryFan.IsLimit.hom_ext h
· simpa only
[BinaryFan.π_app_left,BinaryFan.mk_fst,Category.assoc,IsLimit.fac,IsIso.eq_comp_inv]
· simpa only [BinaryFan.π_app_right,BinaryFan.mk_snd,IsLimit.fac]
/-- If `Y' ≅ Y`, then `X x Y` also is the product of `X` and `Y'`. -/
noncomputable def BinaryFan.isLimitCompRightIso {X Y Y' : C} (c : BinaryFan X Y) (f : Y ⟶ Y')
[IsIso f] (h : IsLimit c) : IsLimit (BinaryFan.mk c.fst (c.snd ≫ f)) :=
BinaryFan.isLimitFlip <| BinaryFan.isLimitCompLeftIso _ f (BinaryFan.isLimitFlip h)
/-- Binary coproducts are symmetric. -/
def BinaryCofan.isColimitFlip {X Y : C} {c : BinaryCofan X Y} (hc : IsColimit c) :
IsColimit (BinaryCofan.mk c.inr c.inl) :=
BinaryCofan.isColimitMk (fun s => hc.desc (BinaryCofan.mk s.inr s.inl)) (fun _ => hc.fac _ _)
(fun _ => hc.fac _ _) fun s _ e₁ e₂ =>
BinaryCofan.IsColimit.hom_ext hc
(e₂.trans (hc.fac (BinaryCofan.mk s.inr s.inl) ⟨WalkingPair.left⟩).symm)
(e₁.trans (hc.fac (BinaryCofan.mk s.inr s.inl) ⟨WalkingPair.right⟩).symm)
theorem BinaryCofan.isColimit_iff_isIso_inl {X Y : C} (h : IsInitial Y) (c : BinaryCofan X Y) :
Nonempty (IsColimit c) ↔ IsIso c.inl := by
constructor
· rintro ⟨H⟩
obtain ⟨l, hl, -⟩ := BinaryCofan.IsColimit.desc' H (𝟙 X) (h.to X)
refine ⟨⟨l, hl, BinaryCofan.IsColimit.hom_ext H (?_) (h.hom_ext _ _)⟩⟩
rw [Category.comp_id]
have e : (inl c ≫ l) ≫ inl c = 𝟙 X ≫ inl c := congrArg (·≫inl c) hl
rwa [Category.assoc,Category.id_comp] at e
· intro
exact
⟨BinaryCofan.IsColimit.mk _ (fun f _ => inv c.inl ≫ f)
(fun _ _ => IsIso.hom_inv_id_assoc _ _) (fun _ _ => h.hom_ext _ _) fun _ _ _ e _ =>
(IsIso.eq_inv_comp _).mpr e⟩
theorem BinaryCofan.isColimit_iff_isIso_inr {X Y : C} (h : IsInitial X) (c : BinaryCofan X Y) :
Nonempty (IsColimit c) ↔ IsIso c.inr := by
refine Iff.trans ?_ (BinaryCofan.isColimit_iff_isIso_inl h (BinaryCofan.mk c.inr c.inl))
exact
⟨fun h => ⟨BinaryCofan.isColimitFlip h.some⟩, fun h =>
⟨(BinaryCofan.isColimitFlip h.some).ofIsoColimit (isoBinaryCofanMk c).symm⟩⟩
/-- If `X' ≅ X`, then `X ⨿ Y` also is the coproduct of `X'` and `Y`. -/
noncomputable def BinaryCofan.isColimitCompLeftIso {X Y X' : C} (c : BinaryCofan X Y) (f : X' ⟶ X)
[IsIso f] (h : IsColimit c) : IsColimit (BinaryCofan.mk (f ≫ c.inl) c.inr) := by
fapply BinaryCofan.isColimitMk
· exact fun s => h.desc (BinaryCofan.mk (inv f ≫ s.inl) s.inr)
· intro s
-- Porting note: simp timed out here too
simp only [IsColimit.fac,BinaryCofan.ι_app_left,eq_self_iff_true,
Category.assoc,BinaryCofan.mk_inl,IsIso.hom_inv_id_assoc]
· intro s
-- Porting note: simp timed out here too
simp only [IsColimit.fac,BinaryCofan.ι_app_right,eq_self_iff_true,BinaryCofan.mk_inr]
· intro s m e₁ e₂
apply BinaryCofan.IsColimit.hom_ext h
· rw [← cancel_epi f]
-- Porting note: simp timed out here too
simpa only [IsColimit.fac,BinaryCofan.ι_app_left,eq_self_iff_true,
Category.assoc,BinaryCofan.mk_inl,IsIso.hom_inv_id_assoc] using e₁
-- Porting note: simp timed out here too
· simpa only [IsColimit.fac,BinaryCofan.ι_app_right,eq_self_iff_true,BinaryCofan.mk_inr]
/-- If `Y' ≅ Y`, then `X ⨿ Y` also is the coproduct of `X` and `Y'`. -/
noncomputable def BinaryCofan.isColimitCompRightIso {X Y Y' : C} (c : BinaryCofan X Y) (f : Y' ⟶ Y)
[IsIso f] (h : IsColimit c) : IsColimit (BinaryCofan.mk c.inl (f ≫ c.inr)) :=
BinaryCofan.isColimitFlip <| BinaryCofan.isColimitCompLeftIso _ f (BinaryCofan.isColimitFlip h)
/-- An abbreviation for `HasLimit (pair X Y)`. -/
abbrev HasBinaryProduct (X Y : C) :=
HasLimit (pair X Y)
/-- An abbreviation for `HasColimit (pair X Y)`. -/
abbrev HasBinaryCoproduct (X Y : C) :=
HasColimit (pair X Y)
/-- If we have a product of `X` and `Y`, we can access it using `prod X Y` or
`X ⨯ Y`. -/
noncomputable abbrev prod (X Y : C) [HasBinaryProduct X Y] :=
limit (pair X Y)
/-- If we have a coproduct of `X` and `Y`, we can access it using `coprod X Y` or
`X ⨿ Y`. -/
noncomputable abbrev coprod (X Y : C) [HasBinaryCoproduct X Y] :=
colimit (pair X Y)
/-- Notation for the product -/
notation:20 X " ⨯ " Y:20 => prod X Y
/-- Notation for the coproduct -/
notation:20 X " ⨿ " Y:20 => coprod X Y
/-- The projection map to the first component of the product. -/
noncomputable abbrev prod.fst {X Y : C} [HasBinaryProduct X Y] : X ⨯ Y ⟶ X :=
limit.π (pair X Y) ⟨WalkingPair.left⟩
/-- The projection map to the second component of the product. -/
noncomputable abbrev prod.snd {X Y : C} [HasBinaryProduct X Y] : X ⨯ Y ⟶ Y :=
limit.π (pair X Y) ⟨WalkingPair.right⟩
/-- The inclusion map from the first component of the coproduct. -/
noncomputable abbrev coprod.inl {X Y : C} [HasBinaryCoproduct X Y] : X ⟶ X ⨿ Y :=
colimit.ι (pair X Y) ⟨WalkingPair.left⟩
/-- The inclusion map from the second component of the coproduct. -/
noncomputable abbrev coprod.inr {X Y : C} [HasBinaryCoproduct X Y] : Y ⟶ X ⨿ Y :=
colimit.ι (pair X Y) ⟨WalkingPair.right⟩
/-- The binary fan constructed from the projection maps is a limit. -/
noncomputable def prodIsProd (X Y : C) [HasBinaryProduct X Y] :
IsLimit (BinaryFan.mk (prod.fst : X ⨯ Y ⟶ X) prod.snd) :=
(limit.isLimit _).ofIsoLimit (Cones.ext (Iso.refl _) (fun ⟨u⟩ => by
cases u
· dsimp; simp only [Category.id_comp]; rfl
· dsimp; simp only [Category.id_comp]; rfl
))
/-- The binary cofan constructed from the coprojection maps is a colimit. -/
noncomputable def coprodIsCoprod (X Y : C) [HasBinaryCoproduct X Y] :
IsColimit (BinaryCofan.mk (coprod.inl : X ⟶ X ⨿ Y) coprod.inr) :=
(colimit.isColimit _).ofIsoColimit (Cocones.ext (Iso.refl _) (fun ⟨u⟩ => by
cases u
· dsimp; simp only [Category.comp_id]
· dsimp; simp only [Category.comp_id]
))
@[ext 1100]
theorem prod.hom_ext {W X Y : C} [HasBinaryProduct X Y] {f g : W ⟶ X ⨯ Y}
(h₁ : f ≫ prod.fst = g ≫ prod.fst) (h₂ : f ≫ prod.snd = g ≫ prod.snd) : f = g :=
BinaryFan.IsLimit.hom_ext (limit.isLimit _) h₁ h₂
@[ext 1100]
theorem coprod.hom_ext {W X Y : C} [HasBinaryCoproduct X Y] {f g : X ⨿ Y ⟶ W}
(h₁ : coprod.inl ≫ f = coprod.inl ≫ g) (h₂ : coprod.inr ≫ f = coprod.inr ≫ g) : f = g :=
BinaryCofan.IsColimit.hom_ext (colimit.isColimit _) h₁ h₂
/-- If the product of `X` and `Y` exists, then every pair of morphisms `f : W ⟶ X` and `g : W ⟶ Y`
induces a morphism `prod.lift f g : W ⟶ X ⨯ Y`. -/
noncomputable abbrev prod.lift {W X Y : C} [HasBinaryProduct X Y]
(f : W ⟶ X) (g : W ⟶ Y) : W ⟶ X ⨯ Y :=
limit.lift _ (BinaryFan.mk f g)
/-- diagonal arrow of the binary product in the category `fam I` -/
noncomputable abbrev diag (X : C) [HasBinaryProduct X X] : X ⟶ X ⨯ X :=
prod.lift (𝟙 _) (𝟙 _)
/-- If the coproduct of `X` and `Y` exists, then every pair of morphisms `f : X ⟶ W` and
`g : Y ⟶ W` induces a morphism `coprod.desc f g : X ⨿ Y ⟶ W`. -/
noncomputable abbrev coprod.desc {W X Y : C} [HasBinaryCoproduct X Y]
(f : X ⟶ W) (g : Y ⟶ W) : X ⨿ Y ⟶ W :=
colimit.desc _ (BinaryCofan.mk f g)
/-- codiagonal arrow of the binary coproduct -/
noncomputable abbrev codiag (X : C) [HasBinaryCoproduct X X] : X ⨿ X ⟶ X :=
coprod.desc (𝟙 _) (𝟙 _)
@[reassoc]
theorem prod.lift_fst {W X Y : C} [HasBinaryProduct X Y] (f : W ⟶ X) (g : W ⟶ Y) :
prod.lift f g ≫ prod.fst = f :=
limit.lift_π _ _
@[reassoc]
theorem prod.lift_snd {W X Y : C} [HasBinaryProduct X Y] (f : W ⟶ X) (g : W ⟶ Y) :
prod.lift f g ≫ prod.snd = g :=
limit.lift_π _ _
@[reassoc]
theorem coprod.inl_desc {W X Y : C} [HasBinaryCoproduct X Y] (f : X ⟶ W) (g : Y ⟶ W) :
coprod.inl ≫ coprod.desc f g = f :=
colimit.ι_desc _ _
@[reassoc]
theorem coprod.inr_desc {W X Y : C} [HasBinaryCoproduct X Y] (f : X ⟶ W) (g : Y ⟶ W) :
coprod.inr ≫ coprod.desc f g = g :=
colimit.ι_desc _ _
instance prod.mono_lift_of_mono_left {W X Y : C} [HasBinaryProduct X Y] (f : W ⟶ X) (g : W ⟶ Y)
[Mono f] : Mono (prod.lift f g) :=
mono_of_mono_fac <| prod.lift_fst _ _
instance prod.mono_lift_of_mono_right {W X Y : C} [HasBinaryProduct X Y] (f : W ⟶ X) (g : W ⟶ Y)
[Mono g] : Mono (prod.lift f g) :=
mono_of_mono_fac <| prod.lift_snd _ _
instance coprod.epi_desc_of_epi_left {W X Y : C} [HasBinaryCoproduct X Y] (f : X ⟶ W) (g : Y ⟶ W)
[Epi f] : Epi (coprod.desc f g) :=
epi_of_epi_fac <| coprod.inl_desc _ _
instance coprod.epi_desc_of_epi_right {W X Y : C} [HasBinaryCoproduct X Y] (f : X ⟶ W) (g : Y ⟶ W)
[Epi g] : Epi (coprod.desc f g) :=
epi_of_epi_fac <| coprod.inr_desc _ _
/-- If the product of `X` and `Y` exists, then every pair of morphisms `f : W ⟶ X` and `g : W ⟶ Y`
induces a morphism `l : W ⟶ X ⨯ Y` satisfying `l ≫ Prod.fst = f` and `l ≫ Prod.snd = g`. -/
noncomputable def prod.lift' {W X Y : C} [HasBinaryProduct X Y] (f : W ⟶ X) (g : W ⟶ Y) :
{ l : W ⟶ X ⨯ Y // l ≫ prod.fst = f ∧ l ≫ prod.snd = g } :=
⟨prod.lift f g, prod.lift_fst _ _, prod.lift_snd _ _⟩
/-- If the coproduct of `X` and `Y` exists, then every pair of morphisms `f : X ⟶ W` and
`g : Y ⟶ W` induces a morphism `l : X ⨿ Y ⟶ W` satisfying `coprod.inl ≫ l = f` and
`coprod.inr ≫ l = g`. -/
noncomputable def coprod.desc' {W X Y : C} [HasBinaryCoproduct X Y] (f : X ⟶ W) (g : Y ⟶ W) :
{ l : X ⨿ Y ⟶ W // coprod.inl ≫ l = f ∧ coprod.inr ≫ l = g } :=
⟨coprod.desc f g, coprod.inl_desc _ _, coprod.inr_desc _ _⟩
/-- If the products `W ⨯ X` and `Y ⨯ Z` exist, then every pair of morphisms `f : W ⟶ Y` and
`g : X ⟶ Z` induces a morphism `prod.map f g : W ⨯ X ⟶ Y ⨯ Z`. -/
noncomputable def prod.map {W X Y Z : C} [HasBinaryProduct W X] [HasBinaryProduct Y Z]
(f : W ⟶ Y) (g : X ⟶ Z) : W ⨯ X ⟶ Y ⨯ Z :=
limMap (mapPair f g)
/-- If the coproducts `W ⨿ X` and `Y ⨿ Z` exist, then every pair of morphisms `f : W ⟶ Y` and
`g : W ⟶ Z` induces a morphism `coprod.map f g : W ⨿ X ⟶ Y ⨿ Z`. -/
noncomputable def coprod.map {W X Y Z : C} [HasBinaryCoproduct W X] [HasBinaryCoproduct Y Z]
(f : W ⟶ Y) (g : X ⟶ Z) : W ⨿ X ⟶ Y ⨿ Z :=
colimMap (mapPair f g)
noncomputable section ProdLemmas
-- Making the reassoc version of this a simp lemma seems to be more harmful than helpful.
@[reassoc, simp]
theorem prod.comp_lift {V W X Y : C} [HasBinaryProduct X Y] (f : V ⟶ W) (g : W ⟶ X) (h : W ⟶ Y) :
f ≫ prod.lift g h = prod.lift (f ≫ g) (f ≫ h) := by ext <;> simp
theorem prod.comp_diag {X Y : C} [HasBinaryProduct Y Y] (f : X ⟶ Y) :
f ≫ diag Y = prod.lift f f := by simp
@[reassoc (attr := simp)]
theorem prod.map_fst {W X Y Z : C} [HasBinaryProduct W X] [HasBinaryProduct Y Z] (f : W ⟶ Y)
(g : X ⟶ Z) : prod.map f g ≫ prod.fst = prod.fst ≫ f :=
limMap_π _ _
@[reassoc (attr := simp)]
theorem prod.map_snd {W X Y Z : C} [HasBinaryProduct W X] [HasBinaryProduct Y Z] (f : W ⟶ Y)
(g : X ⟶ Z) : prod.map f g ≫ prod.snd = prod.snd ≫ g :=
limMap_π _ _
@[simp]
theorem prod.map_id_id {X Y : C} [HasBinaryProduct X Y] : prod.map (𝟙 X) (𝟙 Y) = 𝟙 _ := by
ext <;> simp
@[simp]
theorem prod.lift_fst_snd {X Y : C} [HasBinaryProduct X Y] :
prod.lift prod.fst prod.snd = 𝟙 (X ⨯ Y) := by ext <;> simp
@[reassoc (attr := simp)]
theorem prod.lift_map {V W X Y Z : C} [HasBinaryProduct W X] [HasBinaryProduct Y Z] (f : V ⟶ W)
(g : V ⟶ X) (h : W ⟶ Y) (k : X ⟶ Z) :
prod.lift f g ≫ prod.map h k = prod.lift (f ≫ h) (g ≫ k) := by ext <;> simp
@[simp]
theorem prod.lift_fst_comp_snd_comp {W X Y Z : C} [HasBinaryProduct W Y] [HasBinaryProduct X Z]
(g : W ⟶ X) (g' : Y ⟶ Z) : prod.lift (prod.fst ≫ g) (prod.snd ≫ g') = prod.map g g' := by
rw [← prod.lift_map]
simp
-- We take the right hand side here to be simp normal form, as this way composition lemmas for
-- `f ≫ h` and `g ≫ k` can fire (eg `id_comp`) , while `map_fst` and `map_snd` can still work just
-- as well.
@[reassoc (attr := simp)]
theorem prod.map_map {A₁ A₂ A₃ B₁ B₂ B₃ : C} [HasBinaryProduct A₁ B₁] [HasBinaryProduct A₂ B₂]
[HasBinaryProduct A₃ B₃] (f : A₁ ⟶ A₂) (g : B₁ ⟶ B₂) (h : A₂ ⟶ A₃) (k : B₂ ⟶ B₃) :
prod.map f g ≫ prod.map h k = prod.map (f ≫ h) (g ≫ k) := by ext <;> simp
-- TODO: is it necessary to weaken the assumption here?
@[reassoc]
theorem prod.map_swap {A B X Y : C} (f : A ⟶ B) (g : X ⟶ Y)
[HasLimitsOfShape (Discrete WalkingPair) C] :
prod.map (𝟙 X) f ≫ prod.map g (𝟙 B) = prod.map g (𝟙 A) ≫ prod.map (𝟙 Y) f := by simp
@[reassoc]
theorem prod.map_comp_id {X Y Z W : C} (f : X ⟶ Y) (g : Y ⟶ Z) [HasBinaryProduct X W]
[HasBinaryProduct Z W] [HasBinaryProduct Y W] :
prod.map (f ≫ g) (𝟙 W) = prod.map f (𝟙 W) ≫ prod.map g (𝟙 W) := by simp
@[reassoc]
theorem prod.map_id_comp {X Y Z W : C} (f : X ⟶ Y) (g : Y ⟶ Z) [HasBinaryProduct W X]
[HasBinaryProduct W Y] [HasBinaryProduct W Z] :
prod.map (𝟙 W) (f ≫ g) = prod.map (𝟙 W) f ≫ prod.map (𝟙 W) g := by simp
/-- If the products `W ⨯ X` and `Y ⨯ Z` exist, then every pair of isomorphisms `f : W ≅ Y` and
`g : X ≅ Z` induces an isomorphism `prod.mapIso f g : W ⨯ X ≅ Y ⨯ Z`. -/
@[simps]
def prod.mapIso {W X Y Z : C} [HasBinaryProduct W X] [HasBinaryProduct Y Z] (f : W ≅ Y)
(g : X ≅ Z) : W ⨯ X ≅ Y ⨯ Z where
hom := prod.map f.hom g.hom
inv := prod.map f.inv g.inv
instance isIso_prod {W X Y Z : C} [HasBinaryProduct W X] [HasBinaryProduct Y Z] (f : W ⟶ Y)
(g : X ⟶ Z) [IsIso f] [IsIso g] : IsIso (prod.map f g) :=
(prod.mapIso (asIso f) (asIso g)).isIso_hom
instance prod.map_mono {C : Type*} [Category C] {W X Y Z : C} (f : W ⟶ Y) (g : X ⟶ Z) [Mono f]
[Mono g] [HasBinaryProduct W X] [HasBinaryProduct Y Z] : Mono (prod.map f g) :=
⟨fun i₁ i₂ h => by
ext
· rw [← cancel_mono f]
simpa using congr_arg (fun f => f ≫ prod.fst) h
· rw [← cancel_mono g]
simpa using congr_arg (fun f => f ≫ prod.snd) h⟩
@[reassoc]
theorem prod.diag_map {X Y : C} (f : X ⟶ Y) [HasBinaryProduct X X] [HasBinaryProduct Y Y] :
diag X ≫ prod.map f f = f ≫ diag Y := by simp
@[reassoc]
theorem prod.diag_map_fst_snd {X Y : C} [HasBinaryProduct X Y] [HasBinaryProduct (X ⨯ Y) (X ⨯ Y)] :
diag (X ⨯ Y) ≫ prod.map prod.fst prod.snd = 𝟙 (X ⨯ Y) := by simp
@[reassoc]
theorem prod.diag_map_fst_snd_comp [HasLimitsOfShape (Discrete WalkingPair) C] {X X' Y Y' : C}
(g : X ⟶ Y) (g' : X' ⟶ Y') :
diag (X ⨯ X') ≫ prod.map (prod.fst ≫ g) (prod.snd ≫ g') = prod.map g g' := by simp
instance {X : C} [HasBinaryProduct X X] : IsSplitMono (diag X) :=
IsSplitMono.mk' { retraction := prod.fst }
end ProdLemmas
noncomputable section CoprodLemmas
@[reassoc, simp]
theorem coprod.desc_comp {V W X Y : C} [HasBinaryCoproduct X Y] (f : V ⟶ W) (g : X ⟶ V)
(h : Y ⟶ V) : coprod.desc g h ≫ f = coprod.desc (g ≫ f) (h ≫ f) := by
ext <;> simp
theorem coprod.diag_comp {X Y : C} [HasBinaryCoproduct X X] (f : X ⟶ Y) :
codiag X ≫ f = coprod.desc f f := by simp
@[reassoc (attr := simp)]
theorem coprod.inl_map {W X Y Z : C} [HasBinaryCoproduct W X] [HasBinaryCoproduct Y Z] (f : W ⟶ Y)
(g : X ⟶ Z) : coprod.inl ≫ coprod.map f g = f ≫ coprod.inl :=
ι_colimMap _ _
@[reassoc (attr := simp)]
theorem coprod.inr_map {W X Y Z : C} [HasBinaryCoproduct W X] [HasBinaryCoproduct Y Z] (f : W ⟶ Y)
(g : X ⟶ Z) : coprod.inr ≫ coprod.map f g = g ≫ coprod.inr :=
ι_colimMap _ _
@[simp]
theorem coprod.map_id_id {X Y : C} [HasBinaryCoproduct X Y] : coprod.map (𝟙 X) (𝟙 Y) = 𝟙 _ := by
ext <;> simp
@[simp]
theorem coprod.desc_inl_inr {X Y : C} [HasBinaryCoproduct X Y] :
coprod.desc coprod.inl coprod.inr = 𝟙 (X ⨿ Y) := by ext <;> simp
-- The simp linter says simp can prove the reassoc version of this lemma.
@[reassoc, simp]
| theorem coprod.map_desc {S T U V W : C} [HasBinaryCoproduct U W] [HasBinaryCoproduct T V]
(f : U ⟶ S) (g : W ⟶ S) (h : T ⟶ U) (k : V ⟶ W) :
coprod.map h k ≫ coprod.desc f g = coprod.desc (h ≫ f) (k ≫ g) := by
| Mathlib/CategoryTheory/Limits/Shapes/BinaryProducts.lean | 765 | 767 |
/-
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.Algebra.Polynomial.Splits
import Mathlib.FieldTheory.RatFunc.AsPolynomial
import Mathlib.NumberTheory.ArithmeticFunction
import Mathlib.RingTheory.RootsOfUnity.Complex
/-!
# Cyclotomic polynomials.
For `n : ℕ` and an integral domain `R`, we define a modified version of the `n`-th cyclotomic
polynomial with coefficients in `R`, denoted `cyclotomic' n R`, as `∏ (X - μ)`, where `μ` varies
over the primitive `n`th roots of unity. If there is a primitive `n`th root of unity in `R` then
this the standard definition. We then define the standard cyclotomic polynomial `cyclotomic n R`
with coefficients in any ring `R`.
## Main definition
* `cyclotomic n R` : the `n`-th cyclotomic polynomial with coefficients in `R`.
## Main results
* `Polynomial.degree_cyclotomic` : The degree of `cyclotomic n` is `totient n`.
* `Polynomial.prod_cyclotomic_eq_X_pow_sub_one` : `X ^ n - 1 = ∏ (cyclotomic i)`, where `i`
divides `n`.
* `Polynomial.cyclotomic_eq_prod_X_pow_sub_one_pow_moebius` : The Möbius inversion formula for
`cyclotomic n R` over an abstract fraction field for `R[X]`.
## Implementation details
Our definition of `cyclotomic' n R` makes sense in any integral domain `R`, but the interesting
results hold if there is a primitive `n`-th root of unity in `R`. In particular, our definition is
not the standard one unless there is a primitive `n`th root of unity in `R`. For example,
`cyclotomic' 3 ℤ = 1`, since there are no primitive cube roots of unity in `ℤ`. The main example is
`R = ℂ`, we decided to work in general since the difficulties are essentially the same.
To get the standard cyclotomic polynomials, we use `unique_int_coeff_of_cycl`, with `R = ℂ`,
to get a polynomial with integer coefficients and then we map it to `R[X]`, for any ring `R`.
-/
open scoped Polynomial
noncomputable section
universe u
namespace Polynomial
section Cyclotomic'
section IsDomain
variable {R : Type*} [CommRing R] [IsDomain R]
/-- The modified `n`-th cyclotomic polynomial with coefficients in `R`, it is the usual cyclotomic
polynomial if there is a primitive `n`-th root of unity in `R`. -/
def cyclotomic' (n : ℕ) (R : Type*) [CommRing R] [IsDomain R] : R[X] :=
∏ μ ∈ primitiveRoots n R, (X - C μ)
/-- The zeroth modified cyclotomic polyomial is `1`. -/
@[simp]
theorem cyclotomic'_zero (R : Type*) [CommRing R] [IsDomain R] : cyclotomic' 0 R = 1 := by
simp only [cyclotomic', Finset.prod_empty, primitiveRoots_zero]
/-- The first modified cyclotomic polyomial is `X - 1`. -/
@[simp]
theorem cyclotomic'_one (R : Type*) [CommRing R] [IsDomain R] : cyclotomic' 1 R = X - 1 := by
simp only [cyclotomic', Finset.prod_singleton, RingHom.map_one,
IsPrimitiveRoot.primitiveRoots_one]
/-- The second modified cyclotomic polyomial is `X + 1` if the characteristic of `R` is not `2`. -/
@[simp]
theorem cyclotomic'_two (R : Type*) [CommRing R] [IsDomain R] (p : ℕ) [CharP R p] (hp : p ≠ 2) :
cyclotomic' 2 R = X + 1 := by
rw [cyclotomic']
have prim_root_two : primitiveRoots 2 R = {(-1 : R)} := by
simp only [Finset.eq_singleton_iff_unique_mem, mem_primitiveRoots two_pos]
exact ⟨IsPrimitiveRoot.neg_one p hp, fun x => IsPrimitiveRoot.eq_neg_one_of_two_right⟩
simp only [prim_root_two, Finset.prod_singleton, RingHom.map_neg, RingHom.map_one, sub_neg_eq_add]
/-- `cyclotomic' n R` is monic. -/
theorem cyclotomic'.monic (n : ℕ) (R : Type*) [CommRing R] [IsDomain R] :
(cyclotomic' n R).Monic :=
monic_prod_of_monic _ _ fun _ _ => monic_X_sub_C _
/-- `cyclotomic' n R` is different from `0`. -/
theorem cyclotomic'_ne_zero (n : ℕ) (R : Type*) [CommRing R] [IsDomain R] : cyclotomic' n R ≠ 0 :=
(cyclotomic'.monic n R).ne_zero
/-- The natural degree of `cyclotomic' n R` is `totient n` if there is a primitive root of
unity in `R`. -/
theorem natDegree_cyclotomic' {ζ : R} {n : ℕ} (h : IsPrimitiveRoot ζ n) :
(cyclotomic' n R).natDegree = Nat.totient n := by
rw [cyclotomic']
rw [natDegree_prod (primitiveRoots n R) fun z : R => X - C z]
· simp only [IsPrimitiveRoot.card_primitiveRoots h, mul_one, natDegree_X_sub_C, Nat.cast_id,
Finset.sum_const, nsmul_eq_mul]
intro z _
exact X_sub_C_ne_zero z
/-- The degree of `cyclotomic' n R` is `totient n` if there is a primitive root of unity in `R`. -/
theorem degree_cyclotomic' {ζ : R} {n : ℕ} (h : IsPrimitiveRoot ζ n) :
(cyclotomic' n R).degree = Nat.totient n := by
simp only [degree_eq_natDegree (cyclotomic'_ne_zero n R), natDegree_cyclotomic' h]
/-- The roots of `cyclotomic' n R` are the primitive `n`-th roots of unity. -/
theorem roots_of_cyclotomic (n : ℕ) (R : Type*) [CommRing R] [IsDomain R] :
(cyclotomic' n R).roots = (primitiveRoots n R).val := by
rw [cyclotomic']; exact roots_prod_X_sub_C (primitiveRoots n R)
/-- If there is a primitive `n`th root of unity in `K`, then `X ^ n - 1 = ∏ (X - μ)`, where `μ`
varies over the `n`-th roots of unity. -/
theorem X_pow_sub_one_eq_prod {ζ : R} {n : ℕ} (hpos : 0 < n) (h : IsPrimitiveRoot ζ n) :
X ^ n - 1 = ∏ ζ ∈ nthRootsFinset n (1 : R), (X - C ζ) := by
classical
rw [nthRootsFinset, ← Multiset.toFinset_eq (IsPrimitiveRoot.nthRoots_one_nodup h)]
simp only [Finset.prod_mk, RingHom.map_one]
rw [nthRoots]
have hmonic : (X ^ n - C (1 : R)).Monic := monic_X_pow_sub_C (1 : R) (ne_of_lt hpos).symm
symm
apply prod_multiset_X_sub_C_of_monic_of_roots_card_eq hmonic
rw [@natDegree_X_pow_sub_C R _ _ n 1, ← nthRoots]
exact IsPrimitiveRoot.card_nthRoots_one h
end IsDomain
section Field
variable {K : Type*} [Field K]
/-- `cyclotomic' n K` splits. -/
theorem cyclotomic'_splits (n : ℕ) : Splits (RingHom.id K) (cyclotomic' n K) := by
apply splits_prod (RingHom.id K)
intro z _
simp only [splits_X_sub_C (RingHom.id K)]
/-- If there is a primitive `n`-th root of unity in `K`, then `X ^ n - 1` splits. -/
theorem X_pow_sub_one_splits {ζ : K} {n : ℕ} (h : IsPrimitiveRoot ζ n) :
Splits (RingHom.id K) (X ^ n - C (1 : K)) := by
rw [splits_iff_card_roots, ← nthRoots, IsPrimitiveRoot.card_nthRoots_one h, natDegree_X_pow_sub_C]
/-- If there is a primitive `n`-th root of unity in `K`, then
`∏ i ∈ Nat.divisors n, cyclotomic' i K = X ^ n - 1`. -/
theorem prod_cyclotomic'_eq_X_pow_sub_one {K : Type*} [CommRing K] [IsDomain K] {ζ : K} {n : ℕ}
(hpos : 0 < n) (h : IsPrimitiveRoot ζ n) :
∏ i ∈ Nat.divisors n, cyclotomic' i K = X ^ n - 1 := by
classical
have hd : (n.divisors : Set ℕ).PairwiseDisjoint fun k => primitiveRoots k K :=
fun x _ y _ hne => IsPrimitiveRoot.disjoint hne
simp only [X_pow_sub_one_eq_prod hpos h, cyclotomic', ← Finset.prod_biUnion hd,
IsPrimitiveRoot.nthRoots_one_eq_biUnion_primitiveRoots]
/-- If there is a primitive `n`-th root of unity in `K`, then
`cyclotomic' n K = (X ^ k - 1) /ₘ (∏ i ∈ Nat.properDivisors k, cyclotomic' i K)`. -/
theorem cyclotomic'_eq_X_pow_sub_one_div {K : Type*} [CommRing K] [IsDomain K] {ζ : K} {n : ℕ}
(hpos : 0 < n) (h : IsPrimitiveRoot ζ n) :
cyclotomic' n K = (X ^ n - 1) /ₘ ∏ i ∈ Nat.properDivisors n, cyclotomic' i K := by
rw [← prod_cyclotomic'_eq_X_pow_sub_one hpos h, ← Nat.cons_self_properDivisors hpos.ne',
Finset.prod_cons]
have prod_monic : (∏ i ∈ Nat.properDivisors n, cyclotomic' i K).Monic := by
apply monic_prod_of_monic
intro i _
exact cyclotomic'.monic i K
rw [(div_modByMonic_unique (cyclotomic' n K) 0 prod_monic _).1]
simp only [degree_zero, zero_add]
refine ⟨by rw [mul_comm], ?_⟩
rw [bot_lt_iff_ne_bot]
intro h
exact Monic.ne_zero prod_monic (degree_eq_bot.1 h)
/-- If there is a primitive `n`-th root of unity in `K`, then `cyclotomic' n K` comes from a
monic polynomial with integer coefficients. -/
theorem int_coeff_of_cyclotomic' {K : Type*} [CommRing K] [IsDomain K] {ζ : K} {n : ℕ}
(h : IsPrimitiveRoot ζ n) : ∃ P : ℤ[X], map (Int.castRingHom K) P =
cyclotomic' n K ∧ P.degree = (cyclotomic' n K).degree ∧ P.Monic := by
refine lifts_and_degree_eq_and_monic ?_ (cyclotomic'.monic n K)
induction' n using Nat.strong_induction_on with k ihk generalizing ζ
rcases k.eq_zero_or_pos with (rfl | hpos)
· use 1
simp only [cyclotomic'_zero, coe_mapRingHom, Polynomial.map_one]
let B : K[X] := ∏ i ∈ Nat.properDivisors k, cyclotomic' i K
have Bmo : B.Monic := by
apply monic_prod_of_monic
intro i _
exact cyclotomic'.monic i K
have Bint : B ∈ lifts (Int.castRingHom K) := by
refine Subsemiring.prod_mem (lifts (Int.castRingHom K)) ?_
intro x hx
have xsmall := (Nat.mem_properDivisors.1 hx).2
obtain ⟨d, hd⟩ := (Nat.mem_properDivisors.1 hx).1
rw [mul_comm] at hd
exact ihk x xsmall (h.pow hpos hd)
replace Bint := lifts_and_degree_eq_and_monic Bint Bmo
obtain ⟨B₁, hB₁, _, hB₁mo⟩ := Bint
let Q₁ : ℤ[X] := (X ^ k - 1) /ₘ B₁
have huniq : 0 + B * cyclotomic' k K = X ^ k - 1 ∧ (0 : K[X]).degree < B.degree := by
constructor
· rw [zero_add, mul_comm, ← prod_cyclotomic'_eq_X_pow_sub_one hpos h, ←
Nat.cons_self_properDivisors hpos.ne', Finset.prod_cons]
· simpa only [degree_zero, bot_lt_iff_ne_bot, Ne, degree_eq_bot] using Bmo.ne_zero
replace huniq := div_modByMonic_unique (cyclotomic' k K) (0 : K[X]) Bmo huniq
simp only [lifts, RingHom.mem_rangeS]
use Q₁
rw [coe_mapRingHom, map_divByMonic (Int.castRingHom K) hB₁mo, hB₁, ← huniq.1]
simp
/-- If `K` is of characteristic `0` and there is a primitive `n`-th root of unity in `K`,
then `cyclotomic n K` comes from a unique polynomial with integer coefficients. -/
theorem unique_int_coeff_of_cycl {K : Type*} [CommRing K] [IsDomain K] [CharZero K] {ζ : K}
{n : ℕ+} (h : IsPrimitiveRoot ζ n) :
∃! P : ℤ[X], map (Int.castRingHom K) P = cyclotomic' n K := by
obtain ⟨P, hP⟩ := int_coeff_of_cyclotomic' h
refine ⟨P, hP.1, fun Q hQ => ?_⟩
apply map_injective (Int.castRingHom K) Int.cast_injective
rw [hP.1, hQ]
end Field
end Cyclotomic'
section Cyclotomic
/-- The `n`-th cyclotomic polynomial with coefficients in `R`. -/
def cyclotomic (n : ℕ) (R : Type*) [Ring R] : R[X] :=
if h : n = 0 then 1
else map (Int.castRingHom R) (int_coeff_of_cyclotomic' (Complex.isPrimitiveRoot_exp n h)).choose
theorem int_cyclotomic_rw {n : ℕ} (h : n ≠ 0) :
cyclotomic n ℤ = (int_coeff_of_cyclotomic' (Complex.isPrimitiveRoot_exp n h)).choose := by
simp only [cyclotomic, h, dif_neg, not_false_iff]
ext i
simp only [coeff_map, Int.cast_id, eq_intCast]
/-- `cyclotomic n R` comes from `cyclotomic n ℤ`. -/
theorem map_cyclotomic_int (n : ℕ) (R : Type*) [Ring R] :
map (Int.castRingHom R) (cyclotomic n ℤ) = cyclotomic n R := by
by_cases hzero : n = 0
· simp only [hzero, cyclotomic, dif_pos, Polynomial.map_one]
simp [cyclotomic, hzero]
theorem int_cyclotomic_spec (n : ℕ) :
map (Int.castRingHom ℂ) (cyclotomic n ℤ) = cyclotomic' n ℂ ∧
(cyclotomic n ℤ).degree = (cyclotomic' n ℂ).degree ∧ (cyclotomic n ℤ).Monic := by
by_cases hzero : n = 0
· simp only [hzero, cyclotomic, degree_one, monic_one, cyclotomic'_zero, dif_pos,
eq_self_iff_true, Polynomial.map_one, and_self_iff]
rw [int_cyclotomic_rw hzero]
exact (int_coeff_of_cyclotomic' (Complex.isPrimitiveRoot_exp n hzero)).choose_spec
theorem int_cyclotomic_unique {n : ℕ} {P : ℤ[X]} (h : map (Int.castRingHom ℂ) P = cyclotomic' n ℂ) :
P = cyclotomic n ℤ := by
apply map_injective (Int.castRingHom ℂ) Int.cast_injective
rw [h, (int_cyclotomic_spec n).1]
/-- The definition of `cyclotomic n R` commutes with any ring homomorphism. -/
@[simp]
theorem map_cyclotomic (n : ℕ) {R S : Type*} [Ring R] [Ring S] (f : R →+* S) :
map f (cyclotomic n R) = cyclotomic n S := by
rw [← map_cyclotomic_int n R, ← map_cyclotomic_int n S, map_map]
have : Subsingleton (ℤ →+* S) := inferInstance
congr!
theorem cyclotomic.eval_apply {R S : Type*} (q : R) (n : ℕ) [Ring R] [Ring S] (f : R →+* S) :
eval (f q) (cyclotomic n S) = f (eval q (cyclotomic n R)) := by
rw [← map_cyclotomic n f, eval_map, eval₂_at_apply]
@[simp] theorem cyclotomic.eval_apply_ofReal (q : ℝ) (n : ℕ) :
eval (q : ℂ) (cyclotomic n ℂ) = (eval q (cyclotomic n ℝ)) :=
cyclotomic.eval_apply q n (algebraMap ℝ ℂ)
/-- The zeroth cyclotomic polyomial is `1`. -/
@[simp]
theorem cyclotomic_zero (R : Type*) [Ring R] : cyclotomic 0 R = 1 := by
simp only [cyclotomic, dif_pos]
/-- The first cyclotomic polyomial is `X - 1`. -/
@[simp]
theorem cyclotomic_one (R : Type*) [Ring R] : cyclotomic 1 R = X - 1 := by
have hspec : map (Int.castRingHom ℂ) (X - 1) = cyclotomic' 1 ℂ := by
simp only [cyclotomic'_one, PNat.one_coe, map_X, Polynomial.map_one, Polynomial.map_sub]
symm
rw [← map_cyclotomic_int, ← int_cyclotomic_unique hspec]
simp only [map_X, Polynomial.map_one, Polynomial.map_sub]
/-- `cyclotomic n` is monic. -/
theorem cyclotomic.monic (n : ℕ) (R : Type*) [Ring R] : (cyclotomic n R).Monic := by
rw [← map_cyclotomic_int]
exact (int_cyclotomic_spec n).2.2.map _
/-- `cyclotomic n` is primitive. -/
theorem cyclotomic.isPrimitive (n : ℕ) (R : Type*) [CommRing R] : (cyclotomic n R).IsPrimitive :=
(cyclotomic.monic n R).isPrimitive
/-- `cyclotomic n R` is different from `0`. -/
theorem cyclotomic_ne_zero (n : ℕ) (R : Type*) [Ring R] [Nontrivial R] : cyclotomic n R ≠ 0 :=
(cyclotomic.monic n R).ne_zero
/-- The degree of `cyclotomic n` is `totient n`. -/
theorem degree_cyclotomic (n : ℕ) (R : Type*) [Ring R] [Nontrivial R] :
(cyclotomic n R).degree = Nat.totient n := by
rw [← map_cyclotomic_int]
rw [degree_map_eq_of_leadingCoeff_ne_zero (Int.castRingHom R) _]
· rcases n with - | k
· simp only [cyclotomic, degree_one, dif_pos, Nat.totient_zero, CharP.cast_eq_zero]
rw [← degree_cyclotomic' (Complex.isPrimitiveRoot_exp k.succ (Nat.succ_ne_zero k))]
exact (int_cyclotomic_spec k.succ).2.1
simp only [(int_cyclotomic_spec n).right.right, eq_intCast, Monic.leadingCoeff, Int.cast_one,
Ne, not_false_iff, one_ne_zero]
/-- The natural degree of `cyclotomic n` is `totient n`. -/
theorem natDegree_cyclotomic (n : ℕ) (R : Type*) [Ring R] [Nontrivial R] :
(cyclotomic n R).natDegree = Nat.totient n := by
rw [natDegree, degree_cyclotomic]; norm_cast
/-- The degree of `cyclotomic n R` is positive. -/
theorem degree_cyclotomic_pos (n : ℕ) (R : Type*) (hpos : 0 < n) [Ring R] [Nontrivial R] :
0 < (cyclotomic n R).degree := by
rwa [degree_cyclotomic n R, Nat.cast_pos, Nat.totient_pos]
open Finset
/-- `∏ i ∈ Nat.divisors n, cyclotomic i R = X ^ n - 1`. -/
theorem prod_cyclotomic_eq_X_pow_sub_one {n : ℕ} (hpos : 0 < n) (R : Type*) [CommRing R] :
∏ i ∈ Nat.divisors n, cyclotomic i R = X ^ n - 1 := by
have integer : ∏ i ∈ Nat.divisors n, cyclotomic i ℤ = X ^ n - 1 := by
apply map_injective (Int.castRingHom ℂ) Int.cast_injective
simp only [Polynomial.map_prod, int_cyclotomic_spec, Polynomial.map_pow, map_X,
Polynomial.map_one, Polynomial.map_sub]
exact prod_cyclotomic'_eq_X_pow_sub_one hpos (Complex.isPrimitiveRoot_exp n hpos.ne')
simpa only [Polynomial.map_prod, map_cyclotomic_int, Polynomial.map_sub, Polynomial.map_one,
Polynomial.map_pow, Polynomial.map_X] using congr_arg (map (Int.castRingHom R)) integer
theorem cyclotomic.dvd_X_pow_sub_one (n : ℕ) (R : Type*) [Ring R] :
cyclotomic n R ∣ X ^ n - 1 := by
suffices cyclotomic n ℤ ∣ X ^ n - 1 by
simpa only [map_cyclotomic_int, Polynomial.map_sub, Polynomial.map_one, Polynomial.map_pow,
Polynomial.map_X] using map_dvd (Int.castRingHom R) this
rcases n.eq_zero_or_pos with (rfl | hn)
· simp
rw [← prod_cyclotomic_eq_X_pow_sub_one hn]
exact Finset.dvd_prod_of_mem _ (n.mem_divisors_self hn.ne')
theorem prod_cyclotomic_eq_geom_sum {n : ℕ} (h : 0 < n) (R) [CommRing R] :
∏ i ∈ n.divisors.erase 1, cyclotomic i R = ∑ i ∈ Finset.range n, X ^ i := by
suffices (∏ i ∈ n.divisors.erase 1, cyclotomic i ℤ) = ∑ i ∈ Finset.range n, X ^ i by
simpa only [Polynomial.map_prod, map_cyclotomic_int, Polynomial.map_sum, Polynomial.map_pow,
Polynomial.map_X] using congr_arg (map (Int.castRingHom R)) this
rw [← mul_left_inj' (cyclotomic_ne_zero 1 ℤ), prod_erase_mul _ _ (Nat.one_mem_divisors.2 h.ne'),
cyclotomic_one, geom_sum_mul, prod_cyclotomic_eq_X_pow_sub_one h]
/-- If `p` is prime, then `cyclotomic p R = ∑ i ∈ range p, X ^ i`. -/
theorem cyclotomic_prime (R : Type*) [Ring R] (p : ℕ) [hp : Fact p.Prime] :
cyclotomic p R = ∑ i ∈ Finset.range p, X ^ i := by
suffices cyclotomic p ℤ = ∑ i ∈ range p, X ^ i by
simpa only [map_cyclotomic_int, Polynomial.map_sum, Polynomial.map_pow, Polynomial.map_X] using
congr_arg (map (Int.castRingHom R)) this
rw [← prod_cyclotomic_eq_geom_sum hp.out.pos, hp.out.divisors,
erase_insert (mem_singleton.not.2 hp.out.ne_one.symm), prod_singleton]
theorem cyclotomic_prime_mul_X_sub_one (R : Type*) [Ring R] (p : ℕ) [hn : Fact (Nat.Prime p)] :
cyclotomic p R * (X - 1) = X ^ p - 1 := by rw [cyclotomic_prime, geom_sum_mul]
@[simp]
theorem cyclotomic_two (R : Type*) [Ring R] : cyclotomic 2 R = X + 1 := by simp [cyclotomic_prime]
@[simp]
theorem cyclotomic_three (R : Type*) [Ring R] : cyclotomic 3 R = X ^ 2 + X + 1 := by
simp [cyclotomic_prime, sum_range_succ']
theorem cyclotomic_dvd_geom_sum_of_dvd (R) [Ring R] {d n : ℕ} (hdn : d ∣ n) (hd : d ≠ 1) :
cyclotomic d R ∣ ∑ i ∈ Finset.range n, X ^ i := by
suffices cyclotomic d ℤ ∣ ∑ i ∈ Finset.range n, X ^ i by
simpa only [map_cyclotomic_int, Polynomial.map_sum, Polynomial.map_pow, Polynomial.map_X] using
map_dvd (Int.castRingHom R) this
rcases n.eq_zero_or_pos with (rfl | hn)
· simp
rw [← prod_cyclotomic_eq_geom_sum hn]
apply Finset.dvd_prod_of_mem
simp [hd, hdn, hn.ne']
theorem X_pow_sub_one_mul_prod_cyclotomic_eq_X_pow_sub_one_of_dvd (R) [CommRing R] {d n : ℕ}
(h : d ∈ n.properDivisors) :
((X ^ d - 1) * ∏ x ∈ n.divisors \ d.divisors, cyclotomic x R) = X ^ n - 1 := by
| obtain ⟨hd, hdn⟩ := Nat.mem_properDivisors.mp h
have h0n : 0 < n := pos_of_gt hdn
have h0d : 0 < d := Nat.pos_of_dvd_of_pos hd h0n
rw [← prod_cyclotomic_eq_X_pow_sub_one h0d, ← prod_cyclotomic_eq_X_pow_sub_one h0n, mul_comm,
Finset.prod_sdiff (Nat.divisors_subset_of_dvd h0n.ne' hd)]
theorem X_pow_sub_one_mul_cyclotomic_dvd_X_pow_sub_one_of_dvd (R) [CommRing R] {d n : ℕ}
| Mathlib/RingTheory/Polynomial/Cyclotomic/Basic.lean | 387 | 393 |
/-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes
-/
import Mathlib.Algebra.CharP.Basic
import Mathlib.Algebra.Module.End
import Mathlib.Algebra.Ring.Prod
import Mathlib.Data.Fintype.Units
import Mathlib.GroupTheory.GroupAction.SubMulAction
import Mathlib.GroupTheory.OrderOfElement
import Mathlib.Tactic.FinCases
/-!
# Integers mod `n`
Definition of the integers mod n, and the field structure on the integers mod p.
## Definitions
* `ZMod n`, which is for integers modulo a nat `n : ℕ`
* `val a` is defined as a natural number:
- for `a : ZMod 0` it is the absolute value of `a`
- for `a : ZMod n` with `0 < n` it is the least natural number in the equivalence class
* A coercion `cast` is defined from `ZMod n` into any ring.
This is a ring hom if the ring has characteristic dividing `n`
-/
assert_not_exists Field Submodule TwoSidedIdeal
open Function ZMod
namespace ZMod
/-- For non-zero `n : ℕ`, the ring `Fin n` is equivalent to `ZMod n`. -/
def finEquiv : ∀ (n : ℕ) [NeZero n], Fin n ≃+* ZMod n
| 0, h => (h.ne _ rfl).elim
| _ + 1, _ => .refl _
instance charZero : CharZero (ZMod 0) := inferInstanceAs (CharZero ℤ)
/-- `val a` is a natural number defined as:
- for `a : ZMod 0` it is the absolute value of `a`
- for `a : ZMod n` with `0 < n` it is the least natural number in the equivalence class
See `ZMod.valMinAbs` for a variant that takes values in the integers.
-/
def val : ∀ {n : ℕ}, ZMod n → ℕ
| 0 => Int.natAbs
| n + 1 => ((↑) : Fin (n + 1) → ℕ)
theorem val_lt {n : ℕ} [NeZero n] (a : ZMod n) : a.val < n := by
cases n
· cases NeZero.ne 0 rfl
exact Fin.is_lt a
theorem val_le {n : ℕ} [NeZero n] (a : ZMod n) : a.val ≤ n :=
a.val_lt.le
@[simp]
theorem val_zero : ∀ {n}, (0 : ZMod n).val = 0
| 0 => rfl
| _ + 1 => rfl
@[simp]
theorem val_one' : (1 : ZMod 0).val = 1 :=
rfl
@[simp]
theorem val_neg' {n : ZMod 0} : (-n).val = n.val :=
Int.natAbs_neg n
@[simp]
theorem val_mul' {m n : ZMod 0} : (m * n).val = m.val * n.val :=
Int.natAbs_mul m n
@[simp]
theorem val_natCast (n a : ℕ) : (a : ZMod n).val = a % n := by
cases n
· rw [Nat.mod_zero]
exact Int.natAbs_natCast a
· apply Fin.val_natCast
lemma val_natCast_of_lt {n a : ℕ} (h : a < n) : (a : ZMod n).val = a := by
rwa [val_natCast, Nat.mod_eq_of_lt]
lemma val_ofNat (n a : ℕ) [a.AtLeastTwo] : (ofNat(a) : ZMod n).val = ofNat(a) % n := val_natCast ..
lemma val_ofNat_of_lt {n a : ℕ} [a.AtLeastTwo] (han : a < n) : (ofNat(a) : ZMod n).val = ofNat(a) :=
val_natCast_of_lt han
theorem val_unit' {n : ZMod 0} : IsUnit n ↔ n.val = 1 := by
simp only [val]
rw [Int.isUnit_iff, Int.natAbs_eq_iff, Nat.cast_one]
lemma eq_one_of_isUnit_natCast {n : ℕ} (h : IsUnit (n : ZMod 0)) : n = 1 := by
rw [← Nat.mod_zero n, ← val_natCast, val_unit'.mp h]
instance charP (n : ℕ) : CharP (ZMod n) n where
cast_eq_zero_iff := by
intro k
rcases n with - | n
· simp [zero_dvd_iff, Int.natCast_eq_zero]
· exact Fin.natCast_eq_zero
@[simp]
theorem addOrderOf_one (n : ℕ) : addOrderOf (1 : ZMod n) = n :=
CharP.eq _ (CharP.addOrderOf_one _) (ZMod.charP n)
/-- This lemma works in the case in which `ZMod n` is not infinite, i.e. `n ≠ 0`. The version
where `a ≠ 0` is `addOrderOf_coe'`. -/
@[simp]
theorem addOrderOf_coe (a : ℕ) {n : ℕ} (n0 : n ≠ 0) : addOrderOf (a : ZMod n) = n / n.gcd a := by
rcases a with - | a
· simp only [Nat.cast_zero, addOrderOf_zero, Nat.gcd_zero_right,
Nat.pos_of_ne_zero n0, Nat.div_self]
rw [← Nat.smul_one_eq_cast, addOrderOf_nsmul' _ a.succ_ne_zero, ZMod.addOrderOf_one]
/-- This lemma works in the case in which `a ≠ 0`. The version where
`ZMod n` is not infinite, i.e. `n ≠ 0`, is `addOrderOf_coe`. -/
@[simp]
theorem addOrderOf_coe' {a : ℕ} (n : ℕ) (a0 : a ≠ 0) : addOrderOf (a : ZMod n) = n / n.gcd a := by
rw [← Nat.smul_one_eq_cast, addOrderOf_nsmul' _ a0, ZMod.addOrderOf_one]
/-- We have that `ringChar (ZMod n) = n`. -/
theorem ringChar_zmod_n (n : ℕ) : ringChar (ZMod n) = n := by
rw [ringChar.eq_iff]
exact ZMod.charP n
theorem natCast_self (n : ℕ) : (n : ZMod n) = 0 :=
CharP.cast_eq_zero (ZMod n) n
@[simp]
theorem natCast_self' (n : ℕ) : (n + 1 : ZMod (n + 1)) = 0 := by
rw [← Nat.cast_add_one, natCast_self (n + 1)]
section UniversalProperty
variable {n : ℕ} {R : Type*}
section
variable [AddGroupWithOne R]
/-- Cast an integer modulo `n` to another semiring.
This function is a morphism if the characteristic of `R` divides `n`.
See `ZMod.castHom` for a bundled version. -/
def cast : ∀ {n : ℕ}, ZMod n → R
| 0 => Int.cast
| _ + 1 => fun i => i.val
@[simp]
theorem cast_zero : (cast (0 : ZMod n) : R) = 0 := by
delta ZMod.cast
cases n
· exact Int.cast_zero
· simp
theorem cast_eq_val [NeZero n] (a : ZMod n) : (cast a : R) = a.val := by
cases n
· cases NeZero.ne 0 rfl
rfl
variable {S : Type*} [AddGroupWithOne S]
@[simp]
theorem _root_.Prod.fst_zmod_cast (a : ZMod n) : (cast a : R × S).fst = cast a := by
cases n
· rfl
· simp [ZMod.cast]
@[simp]
theorem _root_.Prod.snd_zmod_cast (a : ZMod n) : (cast a : R × S).snd = cast a := by
cases n
· rfl
· simp [ZMod.cast]
end
/-- So-named because the coercion is `Nat.cast` into `ZMod`. For `Nat.cast` into an arbitrary ring,
see `ZMod.natCast_val`. -/
theorem natCast_zmod_val {n : ℕ} [NeZero n] (a : ZMod n) : (a.val : ZMod n) = a := by
cases n
· cases NeZero.ne 0 rfl
· apply Fin.cast_val_eq_self
theorem natCast_rightInverse [NeZero n] : Function.RightInverse val ((↑) : ℕ → ZMod n) :=
natCast_zmod_val
theorem natCast_zmod_surjective [NeZero n] : Function.Surjective ((↑) : ℕ → ZMod n) :=
natCast_rightInverse.surjective
/-- So-named because the outer coercion is `Int.cast` into `ZMod`. For `Int.cast` into an arbitrary
ring, see `ZMod.intCast_cast`. -/
@[norm_cast]
theorem intCast_zmod_cast (a : ZMod n) : ((cast a : ℤ) : ZMod n) = a := by
cases n
· simp [ZMod.cast, ZMod]
· dsimp [ZMod.cast]
rw [Int.cast_natCast, natCast_zmod_val]
theorem intCast_rightInverse : Function.RightInverse (cast : ZMod n → ℤ) ((↑) : ℤ → ZMod n) :=
intCast_zmod_cast
theorem intCast_surjective : Function.Surjective ((↑) : ℤ → ZMod n) :=
intCast_rightInverse.surjective
lemma «forall» {P : ZMod n → Prop} : (∀ x, P x) ↔ ∀ x : ℤ, P x := intCast_surjective.forall
lemma «exists» {P : ZMod n → Prop} : (∃ x, P x) ↔ ∃ x : ℤ, P x := intCast_surjective.exists
theorem cast_id : ∀ (n) (i : ZMod n), (ZMod.cast i : ZMod n) = i
| 0, _ => Int.cast_id
| _ + 1, i => natCast_zmod_val i
@[simp]
theorem cast_id' : (ZMod.cast : ZMod n → ZMod n) = id :=
funext (cast_id n)
variable (R) [Ring R]
/-- The coercions are respectively `Nat.cast` and `ZMod.cast`. -/
@[simp]
theorem natCast_comp_val [NeZero n] : ((↑) : ℕ → R) ∘ (val : ZMod n → ℕ) = cast := by
cases n
· cases NeZero.ne 0 rfl
rfl
/-- The coercions are respectively `Int.cast`, `ZMod.cast`, and `ZMod.cast`. -/
@[simp]
theorem intCast_comp_cast : ((↑) : ℤ → R) ∘ (cast : ZMod n → ℤ) = cast := by
cases n
· exact congr_arg (Int.cast ∘ ·) ZMod.cast_id'
· ext
simp [ZMod, ZMod.cast]
variable {R}
@[simp]
theorem natCast_val [NeZero n] (i : ZMod n) : (i.val : R) = cast i :=
congr_fun (natCast_comp_val R) i
@[simp]
theorem intCast_cast (i : ZMod n) : ((cast i : ℤ) : R) = cast i :=
congr_fun (intCast_comp_cast R) i
theorem cast_add_eq_ite {n : ℕ} (a b : ZMod n) :
(cast (a + b) : ℤ) =
if (n : ℤ) ≤ cast a + cast b then (cast a + cast b - n : ℤ) else cast a + cast b := by
rcases n with - | n
· simp; rfl
change Fin (n + 1) at a b
change ((((a + b) : Fin (n + 1)) : ℕ) : ℤ) = if ((n + 1 : ℕ) : ℤ) ≤ (a : ℕ) + b then _ else _
simp only [Fin.val_add_eq_ite, Int.natCast_succ, Int.ofNat_le]
norm_cast
split_ifs with h
· rw [Nat.cast_sub h]
congr
· rfl
section CharDvd
/-! If the characteristic of `R` divides `n`, then `cast` is a homomorphism. -/
variable {m : ℕ} [CharP R m]
@[simp]
theorem cast_one (h : m ∣ n) : (cast (1 : ZMod n) : R) = 1 := by
rcases n with - | n
· exact Int.cast_one
show ((1 % (n + 1) : ℕ) : R) = 1
cases n
· rw [Nat.dvd_one] at h
subst m
subsingleton [CharP.CharOne.subsingleton]
rw [Nat.mod_eq_of_lt]
· exact Nat.cast_one
exact Nat.lt_of_sub_eq_succ rfl
theorem cast_add (h : m ∣ n) (a b : ZMod n) : (cast (a + b : ZMod n) : R) = cast a + cast b := by
cases n
· apply Int.cast_add
symm
dsimp [ZMod, ZMod.cast, ZMod.val]
rw [← Nat.cast_add, Fin.val_add, ← sub_eq_zero, ← Nat.cast_sub (Nat.mod_le _ _),
@CharP.cast_eq_zero_iff R _ m]
exact h.trans (Nat.dvd_sub_mod _)
theorem cast_mul (h : m ∣ n) (a b : ZMod n) : (cast (a * b : ZMod n) : R) = cast a * cast b := by
cases n
· apply Int.cast_mul
symm
dsimp [ZMod, ZMod.cast, ZMod.val]
rw [← Nat.cast_mul, Fin.val_mul, ← sub_eq_zero, ← Nat.cast_sub (Nat.mod_le _ _),
@CharP.cast_eq_zero_iff R _ m]
exact h.trans (Nat.dvd_sub_mod _)
/-- The canonical ring homomorphism from `ZMod n` to a ring of characteristic dividing `n`.
See also `ZMod.lift` for a generalized version working in `AddGroup`s.
-/
def castHom (h : m ∣ n) (R : Type*) [Ring R] [CharP R m] : ZMod n →+* R where
toFun := cast
map_zero' := cast_zero
map_one' := cast_one h
map_add' := cast_add h
map_mul' := cast_mul h
@[simp]
theorem castHom_apply {h : m ∣ n} (i : ZMod n) : castHom h R i = cast i :=
rfl
@[simp]
theorem cast_sub (h : m ∣ n) (a b : ZMod n) : (cast (a - b : ZMod n) : R) = cast a - cast b :=
(castHom h R).map_sub a b
@[simp]
theorem cast_neg (h : m ∣ n) (a : ZMod n) : (cast (-a : ZMod n) : R) = -(cast a) :=
(castHom h R).map_neg a
@[simp]
theorem cast_pow (h : m ∣ n) (a : ZMod n) (k : ℕ) : (cast (a ^ k : ZMod n) : R) = (cast a) ^ k :=
(castHom h R).map_pow a k
@[simp, norm_cast]
theorem cast_natCast (h : m ∣ n) (k : ℕ) : (cast (k : ZMod n) : R) = k :=
map_natCast (castHom h R) k
@[simp, norm_cast]
theorem cast_intCast (h : m ∣ n) (k : ℤ) : (cast (k : ZMod n) : R) = k :=
map_intCast (castHom h R) k
end CharDvd
section CharEq
/-! Some specialised simp lemmas which apply when `R` has characteristic `n`. -/
variable [CharP R n]
@[simp]
theorem cast_one' : (cast (1 : ZMod n) : R) = 1 :=
cast_one dvd_rfl
@[simp]
theorem cast_add' (a b : ZMod n) : (cast (a + b : ZMod n) : R) = cast a + cast b :=
cast_add dvd_rfl a b
@[simp]
theorem cast_mul' (a b : ZMod n) : (cast (a * b : ZMod n) : R) = cast a * cast b :=
cast_mul dvd_rfl a b
@[simp]
theorem cast_sub' (a b : ZMod n) : (cast (a - b : ZMod n) : R) = cast a - cast b :=
cast_sub dvd_rfl a b
@[simp]
theorem cast_pow' (a : ZMod n) (k : ℕ) : (cast (a ^ k : ZMod n) : R) = (cast a : R) ^ k :=
cast_pow dvd_rfl a k
@[simp, norm_cast]
theorem cast_natCast' (k : ℕ) : (cast (k : ZMod n) : R) = k :=
cast_natCast dvd_rfl k
@[simp, norm_cast]
theorem cast_intCast' (k : ℤ) : (cast (k : ZMod n) : R) = k :=
cast_intCast dvd_rfl k
variable (R)
theorem castHom_injective : Function.Injective (ZMod.castHom (dvd_refl n) R) := by
rw [injective_iff_map_eq_zero]
intro x
obtain ⟨k, rfl⟩ := ZMod.intCast_surjective x
rw [map_intCast, CharP.intCast_eq_zero_iff R n, CharP.intCast_eq_zero_iff (ZMod n) n]
exact id
theorem castHom_bijective [Fintype R] (h : Fintype.card R = n) :
Function.Bijective (ZMod.castHom (dvd_refl n) R) := by
haveI : NeZero n :=
⟨by
intro hn
rw [hn] at h
exact (Fintype.card_eq_zero_iff.mp h).elim' 0⟩
rw [Fintype.bijective_iff_injective_and_card, ZMod.card, h, eq_self_iff_true, and_true]
apply ZMod.castHom_injective
/-- The unique ring isomorphism between `ZMod n` and a ring `R`
of characteristic `n` and cardinality `n`. -/
noncomputable def ringEquiv [Fintype R] (h : Fintype.card R = n) : ZMod n ≃+* R :=
RingEquiv.ofBijective _ (ZMod.castHom_bijective R h)
/-- The unique ring isomorphism between `ZMod p` and a ring `R` of cardinality a prime `p`.
If you need any property of this isomorphism, first of all use `ringEquivOfPrime_eq_ringEquiv`
below (after `have : CharP R p := ...`) and deduce it by the results about `ZMod.ringEquiv`. -/
noncomputable def ringEquivOfPrime [Fintype R] {p : ℕ} (hp : p.Prime) (hR : Fintype.card R = p) :
ZMod p ≃+* R :=
have : Nontrivial R := Fintype.one_lt_card_iff_nontrivial.1 (hR ▸ hp.one_lt)
-- The following line exists as `charP_of_card_eq_prime` in `Mathlib.Algebra.CharP.CharAndCard`.
have : CharP R p := (CharP.charP_iff_prime_eq_zero hp).2 (hR ▸ Nat.cast_card_eq_zero R)
ZMod.ringEquiv R hR
@[simp]
lemma ringEquivOfPrime_eq_ringEquiv [Fintype R] {p : ℕ} [CharP R p] (hp : p.Prime)
(hR : Fintype.card R = p) : ringEquivOfPrime R hp hR = ringEquiv R hR := rfl
/-- The identity between `ZMod m` and `ZMod n` when `m = n`, as a ring isomorphism. -/
def ringEquivCongr {m n : ℕ} (h : m = n) : ZMod m ≃+* ZMod n := by
rcases m with - | m <;> rcases n with - | n
· exact RingEquiv.refl _
· exfalso
exact n.succ_ne_zero h.symm
· exfalso
exact m.succ_ne_zero h
· exact
{ finCongr h with
map_mul' := fun a b => by
dsimp [ZMod]
ext
rw [Fin.coe_cast, Fin.coe_mul, Fin.coe_mul, Fin.coe_cast, Fin.coe_cast, ← h]
map_add' := fun a b => by
dsimp [ZMod]
ext
rw [Fin.coe_cast, Fin.val_add, Fin.val_add, Fin.coe_cast, Fin.coe_cast, ← h] }
@[simp] lemma ringEquivCongr_refl (a : ℕ) : ringEquivCongr (rfl : a = a) = .refl _ := by
cases a <;> rfl
lemma ringEquivCongr_refl_apply {a : ℕ} (x : ZMod a) : ringEquivCongr rfl x = x := by
rw [ringEquivCongr_refl]
rfl
lemma ringEquivCongr_symm {a b : ℕ} (hab : a = b) :
(ringEquivCongr hab).symm = ringEquivCongr hab.symm := by
subst hab
cases a <;> rfl
lemma ringEquivCongr_trans {a b c : ℕ} (hab : a = b) (hbc : b = c) :
(ringEquivCongr hab).trans (ringEquivCongr hbc) = ringEquivCongr (hab.trans hbc) := by
subst hab hbc
cases a <;> rfl
lemma ringEquivCongr_ringEquivCongr_apply {a b c : ℕ} (hab : a = b) (hbc : b = c) (x : ZMod a) :
ringEquivCongr hbc (ringEquivCongr hab x) = ringEquivCongr (hab.trans hbc) x := by
rw [← ringEquivCongr_trans hab hbc]
rfl
lemma ringEquivCongr_val {a b : ℕ} (h : a = b) (x : ZMod a) :
ZMod.val ((ZMod.ringEquivCongr h) x) = ZMod.val x := by
subst h
cases a <;> rfl
lemma ringEquivCongr_intCast {a b : ℕ} (h : a = b) (z : ℤ) :
ZMod.ringEquivCongr h z = z := by
subst h
cases a <;> rfl
end CharEq
end UniversalProperty
variable {m n : ℕ}
@[simp]
theorem val_eq_zero : ∀ {n : ℕ} (a : ZMod n), a.val = 0 ↔ a = 0
| 0, _ => Int.natAbs_eq_zero
| n + 1, a => by
rw [Fin.ext_iff]
exact Iff.rfl
theorem intCast_eq_intCast_iff (a b : ℤ) (c : ℕ) : (a : ZMod c) = (b : ZMod c) ↔ a ≡ b [ZMOD c] :=
CharP.intCast_eq_intCast (ZMod c) c
theorem intCast_eq_intCast_iff' (a b : ℤ) (c : ℕ) : (a : ZMod c) = (b : ZMod c) ↔ a % c = b % c :=
ZMod.intCast_eq_intCast_iff a b c
theorem val_intCast {n : ℕ} (a : ℤ) [NeZero n] : ↑(a : ZMod n).val = a % n := by
have hle : (0 : ℤ) ≤ ↑(a : ZMod n).val := Int.natCast_nonneg _
have hlt : ↑(a : ZMod n).val < (n : ℤ) := Int.ofNat_lt.mpr (ZMod.val_lt a)
refine (Int.emod_eq_of_lt hle hlt).symm.trans ?_
rw [← ZMod.intCast_eq_intCast_iff', Int.cast_natCast, ZMod.natCast_val, ZMod.cast_id]
theorem natCast_eq_natCast_iff (a b c : ℕ) : (a : ZMod c) = (b : ZMod c) ↔ a ≡ b [MOD c] := by
simpa [Int.natCast_modEq_iff] using ZMod.intCast_eq_intCast_iff a b c
theorem natCast_eq_natCast_iff' (a b c : ℕ) : (a : ZMod c) = (b : ZMod c) ↔ a % c = b % c :=
ZMod.natCast_eq_natCast_iff a b c
theorem intCast_zmod_eq_zero_iff_dvd (a : ℤ) (b : ℕ) : (a : ZMod b) = 0 ↔ (b : ℤ) ∣ a := by
rw [← Int.cast_zero, ZMod.intCast_eq_intCast_iff, Int.modEq_zero_iff_dvd]
theorem intCast_eq_intCast_iff_dvd_sub (a b : ℤ) (c : ℕ) : (a : ZMod c) = ↑b ↔ ↑c ∣ b - a := by
rw [ZMod.intCast_eq_intCast_iff, Int.modEq_iff_dvd]
theorem natCast_zmod_eq_zero_iff_dvd (a b : ℕ) : (a : ZMod b) = 0 ↔ b ∣ a := by
rw [← Nat.cast_zero, ZMod.natCast_eq_natCast_iff, Nat.modEq_zero_iff_dvd]
theorem coe_intCast (a : ℤ) : cast (a : ZMod n) = a % n := by
cases n
· rw [Int.ofNat_zero, Int.emod_zero, Int.cast_id]; rfl
· rw [← val_intCast, val]; rfl
lemma intCast_cast_add (x y : ZMod n) : (cast (x + y) : ℤ) = (cast x + cast y) % n := by
rw [← ZMod.coe_intCast, Int.cast_add, ZMod.intCast_zmod_cast, ZMod.intCast_zmod_cast]
lemma intCast_cast_mul (x y : ZMod n) : (cast (x * y) : ℤ) = cast x * cast y % n := by
rw [← ZMod.coe_intCast, Int.cast_mul, ZMod.intCast_zmod_cast, ZMod.intCast_zmod_cast]
lemma intCast_cast_sub (x y : ZMod n) : (cast (x - y) : ℤ) = (cast x - cast y) % n := by
rw [← ZMod.coe_intCast, Int.cast_sub, ZMod.intCast_zmod_cast, ZMod.intCast_zmod_cast]
lemma intCast_cast_neg (x : ZMod n) : (cast (-x) : ℤ) = -cast x % n := by
rw [← ZMod.coe_intCast, Int.cast_neg, ZMod.intCast_zmod_cast]
@[simp]
theorem val_neg_one (n : ℕ) : (-1 : ZMod n.succ).val = n := by
dsimp [val, Fin.coe_neg]
cases n
· simp [Nat.mod_one]
· dsimp [ZMod, ZMod.cast]
rw [Fin.coe_neg_one]
/-- `-1 : ZMod n` lifts to `n - 1 : R`. This avoids the characteristic assumption in `cast_neg`. -/
theorem cast_neg_one {R : Type*} [Ring R] (n : ℕ) : cast (-1 : ZMod n) = (n - 1 : R) := by
rcases n with - | n
· dsimp [ZMod, ZMod.cast]; simp
· rw [← natCast_val, val_neg_one, Nat.cast_succ, add_sub_cancel_right]
theorem cast_sub_one {R : Type*} [Ring R] {n : ℕ} (k : ZMod n) :
(cast (k - 1 : ZMod n) : R) = (if k = 0 then (n : R) else cast k) - 1 := by
split_ifs with hk
· rw [hk, zero_sub, ZMod.cast_neg_one]
· cases n
· dsimp [ZMod, ZMod.cast]
rw [Int.cast_sub, Int.cast_one]
· dsimp [ZMod, ZMod.cast, ZMod.val]
rw [Fin.coe_sub_one, if_neg]
· rw [Nat.cast_sub, Nat.cast_one]
rwa [Fin.ext_iff, Fin.val_zero, ← Ne, ← Nat.one_le_iff_ne_zero] at hk
· exact hk
theorem natCast_eq_iff (p : ℕ) (n : ℕ) (z : ZMod p) [NeZero p] :
↑n = z ↔ ∃ k, n = z.val + p * k := by
constructor
· rintro rfl
refine ⟨n / p, ?_⟩
rw [val_natCast, Nat.mod_add_div]
· rintro ⟨k, rfl⟩
rw [Nat.cast_add, natCast_zmod_val, Nat.cast_mul, natCast_self, zero_mul,
add_zero]
theorem intCast_eq_iff (p : ℕ) (n : ℤ) (z : ZMod p) [NeZero p] :
↑n = z ↔ ∃ k, n = z.val + p * k := by
constructor
· rintro rfl
refine ⟨n / p, ?_⟩
rw [val_intCast, Int.emod_add_ediv]
· rintro ⟨k, rfl⟩
rw [Int.cast_add, Int.cast_mul, Int.cast_natCast, Int.cast_natCast, natCast_val,
ZMod.natCast_self, zero_mul, add_zero, cast_id]
@[push_cast, simp]
theorem intCast_mod (a : ℤ) (b : ℕ) : ((a % b : ℤ) : ZMod b) = (a : ZMod b) := by
rw [ZMod.intCast_eq_intCast_iff]
apply Int.mod_modEq
theorem ker_intCastAddHom (n : ℕ) :
(Int.castAddHom (ZMod n)).ker = AddSubgroup.zmultiples (n : ℤ) := by
ext
rw [Int.mem_zmultiples_iff, AddMonoidHom.mem_ker, Int.coe_castAddHom,
intCast_zmod_eq_zero_iff_dvd]
theorem cast_injective_of_le {m n : ℕ} [nzm : NeZero m] (h : m ≤ n) :
Function.Injective (@cast (ZMod n) _ m) := by
cases m with
| zero => cases nzm; simp_all
| succ m =>
rintro ⟨x, hx⟩ ⟨y, hy⟩ f
simp only [cast, val, natCast_eq_natCast_iff',
Nat.mod_eq_of_lt (hx.trans_le h), Nat.mod_eq_of_lt (hy.trans_le h)] at f
apply Fin.ext
exact f
theorem cast_zmod_eq_zero_iff_of_le {m n : ℕ} [NeZero m] (h : m ≤ n) (a : ZMod m) :
(cast a : ZMod n) = 0 ↔ a = 0 := by
rw [← ZMod.cast_zero (n := m)]
exact Injective.eq_iff' (cast_injective_of_le h) rfl
@[simp]
theorem natCast_toNat (p : ℕ) : ∀ {z : ℤ} (_h : 0 ≤ z), (z.toNat : ZMod p) = z
| (n : ℕ), _h => by simp only [Int.cast_natCast, Int.toNat_natCast]
| Int.negSucc n, h => by simp at h
theorem val_injective (n : ℕ) [NeZero n] : Function.Injective (val : ZMod n → ℕ) := by
cases n
· cases NeZero.ne 0 rfl
intro a b h
dsimp [ZMod]
ext
exact h
theorem val_one_eq_one_mod (n : ℕ) : (1 : ZMod n).val = 1 % n := by
rw [← Nat.cast_one, val_natCast]
theorem val_two_eq_two_mod (n : ℕ) : (2 : ZMod n).val = 2 % n := by
rw [← Nat.cast_two, val_natCast]
theorem val_one (n : ℕ) [Fact (1 < n)] : (1 : ZMod n).val = 1 := by
rw [val_one_eq_one_mod]
exact Nat.mod_eq_of_lt Fact.out
lemma val_one'' : ∀ {n}, n ≠ 1 → (1 : ZMod n).val = 1
| 0, _ => rfl
| 1, hn => by cases hn rfl
| n + 2, _ =>
haveI : Fact (1 < n + 2) := ⟨by simp⟩
ZMod.val_one _
theorem val_add {n : ℕ} [NeZero n] (a b : ZMod n) : (a + b).val = (a.val + b.val) % n := by
cases n
· cases NeZero.ne 0 rfl
· apply Fin.val_add
theorem val_add_of_lt {n : ℕ} {a b : ZMod n} (h : a.val + b.val < n) :
(a + b).val = a.val + b.val := by
have : NeZero n := by constructor; rintro rfl; simp at h
rw [ZMod.val_add, Nat.mod_eq_of_lt h]
theorem val_add_val_of_le {n : ℕ} [NeZero n] {a b : ZMod n} (h : n ≤ a.val + b.val) :
a.val + b.val = (a + b).val + n := by
rw [val_add, Nat.add_mod_add_of_le_add_mod, Nat.mod_eq_of_lt (val_lt _),
Nat.mod_eq_of_lt (val_lt _)]
rwa [Nat.mod_eq_of_lt (val_lt _), Nat.mod_eq_of_lt (val_lt _)]
theorem val_add_of_le {n : ℕ} [NeZero n] {a b : ZMod n} (h : n ≤ a.val + b.val) :
(a + b).val = a.val + b.val - n := by
rw [val_add_val_of_le h]
exact eq_tsub_of_add_eq rfl
theorem val_add_le {n : ℕ} (a b : ZMod n) : (a + b).val ≤ a.val + b.val := by
cases n
· simpa [ZMod.val] using Int.natAbs_add_le _ _
· simpa [ZMod.val_add] using Nat.mod_le _ _
theorem val_mul {n : ℕ} (a b : ZMod n) : (a * b).val = a.val * b.val % n := by
cases n
· rw [Nat.mod_zero]
apply Int.natAbs_mul
· apply Fin.val_mul
theorem val_mul_le {n : ℕ} (a b : ZMod n) : (a * b).val ≤ a.val * b.val := by
rw [val_mul]
apply Nat.mod_le
theorem val_mul_of_lt {n : ℕ} {a b : ZMod n} (h : a.val * b.val < n) :
(a * b).val = a.val * b.val := by
rw [val_mul]
apply Nat.mod_eq_of_lt h
theorem val_mul_iff_lt {n : ℕ} [NeZero n] (a b : ZMod n) :
(a * b).val = a.val * b.val ↔ a.val * b.val < n := by
constructor <;> intro h
· rw [← h]; apply ZMod.val_lt
· apply ZMod.val_mul_of_lt h
instance nontrivial (n : ℕ) [Fact (1 < n)] : Nontrivial (ZMod n) :=
⟨⟨0, 1, fun h =>
zero_ne_one <|
calc
0 = (0 : ZMod n).val := by rw [val_zero]
_ = (1 : ZMod n).val := congr_arg ZMod.val h
_ = 1 := val_one n
⟩⟩
instance nontrivial' : Nontrivial (ZMod 0) := by
delta ZMod; infer_instance
lemma one_eq_zero_iff {n : ℕ} : (1 : ZMod n) = 0 ↔ n = 1 := by
rw [← Nat.cast_one, natCast_zmod_eq_zero_iff_dvd, Nat.dvd_one]
/-- The inversion on `ZMod n`.
It is setup in such a way that `a * a⁻¹` is equal to `gcd a.val n`.
In particular, if `a` is coprime to `n`, and hence a unit, `a * a⁻¹ = 1`. -/
def inv : ∀ n : ℕ, ZMod n → ZMod n
| 0, i => Int.sign i
| n + 1, i => Nat.gcdA i.val (n + 1)
instance (n : ℕ) : Inv (ZMod n) :=
⟨inv n⟩
theorem inv_zero : ∀ n : ℕ, (0 : ZMod n)⁻¹ = 0
| 0 => Int.sign_zero
| n + 1 =>
show (Nat.gcdA _ (n + 1) : ZMod (n + 1)) = 0 by
rw [val_zero]
unfold Nat.gcdA Nat.xgcd Nat.xgcdAux
rfl
theorem mul_inv_eq_gcd {n : ℕ} (a : ZMod n) : a * a⁻¹ = Nat.gcd a.val n := by
rcases n with - | n
· dsimp [ZMod] at a ⊢
calc
_ = a * Int.sign a := rfl
_ = a.natAbs := by rw [Int.mul_sign_self]
_ = a.natAbs.gcd 0 := by rw [Nat.gcd_zero_right]
· calc
a * a⁻¹ = a * a⁻¹ + n.succ * Nat.gcdB (val a) n.succ := by
rw [natCast_self, zero_mul, add_zero]
_ = ↑(↑a.val * Nat.gcdA (val a) n.succ + n.succ * Nat.gcdB (val a) n.succ) := by
push_cast
rw [natCast_zmod_val]
rfl
_ = Nat.gcd a.val n.succ := by rw [← Nat.gcd_eq_gcd_ab a.val n.succ]; rfl
@[simp] protected lemma inv_one (n : ℕ) : (1⁻¹ : ZMod n) = 1 := by
obtain rfl | hn := eq_or_ne n 1
· exact Subsingleton.elim _ _
· simpa [ZMod.val_one'' hn] using mul_inv_eq_gcd (1 : ZMod n)
@[simp]
theorem natCast_mod (a : ℕ) (n : ℕ) : ((a % n : ℕ) : ZMod n) = a := by
conv =>
rhs
rw [← Nat.mod_add_div a n]
simp
theorem eq_iff_modEq_nat (n : ℕ) {a b : ℕ} : (a : ZMod n) = b ↔ a ≡ b [MOD n] := by
cases n
· simp [Nat.ModEq, Int.natCast_inj, Nat.mod_zero]
· rw [Fin.ext_iff, Nat.ModEq, ← val_natCast, ← val_natCast]
exact Iff.rfl
theorem eq_zero_iff_even {n : ℕ} : (n : ZMod 2) = 0 ↔ Even n :=
(CharP.cast_eq_zero_iff (ZMod 2) 2 n).trans even_iff_two_dvd.symm
theorem eq_one_iff_odd {n : ℕ} : (n : ZMod 2) = 1 ↔ Odd n := by
rw [← @Nat.cast_one (ZMod 2), ZMod.eq_iff_modEq_nat, Nat.odd_iff, Nat.ModEq]
theorem ne_zero_iff_odd {n : ℕ} : (n : ZMod 2) ≠ 0 ↔ Odd n := by
constructor <;>
· contrapose
simp [eq_zero_iff_even]
theorem coe_mul_inv_eq_one {n : ℕ} (x : ℕ) (h : Nat.Coprime x n) :
((x : ZMod n) * (x : ZMod n)⁻¹) = 1 := by
rw [Nat.Coprime, Nat.gcd_comm, Nat.gcd_rec] at h
rw [mul_inv_eq_gcd, val_natCast, h, Nat.cast_one]
lemma mul_val_inv (hmn : m.Coprime n) : (m * (m⁻¹ : ZMod n).val : ZMod n) = 1 := by
obtain rfl | hn := eq_or_ne n 0
· simp [m.coprime_zero_right.1 hmn]
haveI : NeZero n := ⟨hn⟩
rw [ZMod.natCast_zmod_val, ZMod.coe_mul_inv_eq_one _ hmn]
lemma val_inv_mul (hmn : m.Coprime n) : ((m⁻¹ : ZMod n).val * m : ZMod n) = 1 := by
rw [mul_comm, mul_val_inv hmn]
/-- `unitOfCoprime` makes an element of `(ZMod n)ˣ` given
a natural number `x` and a proof that `x` is coprime to `n` -/
def unitOfCoprime {n : ℕ} (x : ℕ) (h : Nat.Coprime x n) : (ZMod n)ˣ :=
⟨x, x⁻¹, coe_mul_inv_eq_one x h, by rw [mul_comm, coe_mul_inv_eq_one x h]⟩
@[simp]
theorem coe_unitOfCoprime {n : ℕ} (x : ℕ) (h : Nat.Coprime x n) :
(unitOfCoprime x h : ZMod n) = x :=
rfl
theorem val_coe_unit_coprime {n : ℕ} (u : (ZMod n)ˣ) : Nat.Coprime (u : ZMod n).val n := by
rcases n with - | n
· rcases Int.units_eq_one_or u with (rfl | rfl) <;> simp
apply Nat.coprime_of_mul_modEq_one ((u⁻¹ : Units (ZMod (n + 1))) : ZMod (n + 1)).val
have := Units.ext_iff.1 (mul_inv_cancel u)
rw [Units.val_one] at this
rw [← eq_iff_modEq_nat, Nat.cast_one, ← this]; clear this
rw [← natCast_zmod_val ((u * u⁻¹ : Units (ZMod (n + 1))) : ZMod (n + 1))]
rw [Units.val_mul, val_mul, natCast_mod]
lemma isUnit_iff_coprime (m n : ℕ) : IsUnit (m : ZMod n) ↔ m.Coprime n := by
refine ⟨fun H ↦ ?_, fun H ↦ (unitOfCoprime m H).isUnit⟩
have H' := val_coe_unit_coprime H.unit
rw [IsUnit.unit_spec, val_natCast, Nat.coprime_iff_gcd_eq_one] at H'
rw [Nat.coprime_iff_gcd_eq_one, Nat.gcd_comm, ← H']
exact Nat.gcd_rec n m
lemma isUnit_prime_iff_not_dvd {n p : ℕ} (hp : p.Prime) : IsUnit (p : ZMod n) ↔ ¬p ∣ n := by
rw [isUnit_iff_coprime, Nat.Prime.coprime_iff_not_dvd hp]
lemma isUnit_prime_of_not_dvd {n p : ℕ} (hp : p.Prime) (h : ¬ p ∣ n) : IsUnit (p : ZMod n) :=
(isUnit_prime_iff_not_dvd hp).mpr h
@[simp]
theorem inv_coe_unit {n : ℕ} (u : (ZMod n)ˣ) : (u : ZMod n)⁻¹ = (u⁻¹ : (ZMod n)ˣ) := by
have := congr_arg ((↑) : ℕ → ZMod n) (val_coe_unit_coprime u)
rw [← mul_inv_eq_gcd, Nat.cast_one] at this
let u' : (ZMod n)ˣ := ⟨u, (u : ZMod n)⁻¹, this, by rwa [mul_comm]⟩
have h : u = u' := by
apply Units.ext
rfl
rw [h]
rfl
theorem mul_inv_of_unit {n : ℕ} (a : ZMod n) (h : IsUnit a) : a * a⁻¹ = 1 := by
rcases h with ⟨u, rfl⟩
rw [inv_coe_unit, u.mul_inv]
theorem inv_mul_of_unit {n : ℕ} (a : ZMod n) (h : IsUnit a) : a⁻¹ * a = 1 := by
rw [mul_comm, mul_inv_of_unit a h]
-- TODO: If we changed `⁻¹` so that `ZMod n` is always a `DivisionMonoid`,
-- then we could use the general lemma `inv_eq_of_mul_eq_one`
protected theorem inv_eq_of_mul_eq_one (n : ℕ) (a b : ZMod n) (h : a * b = 1) : a⁻¹ = b :=
left_inv_eq_right_inv (inv_mul_of_unit a ⟨⟨a, b, h, mul_comm a b ▸ h⟩, rfl⟩) h
lemma inv_mul_eq_one_of_isUnit {n : ℕ} {a : ZMod n} (ha : IsUnit a) (b : ZMod n) :
a⁻¹ * b = 1 ↔ a = b := by
-- ideally, this would be `ha.inv_mul_eq_one`, but `ZMod n` is not a `DivisionMonoid`...
-- (see the "TODO" above)
refine ⟨fun H ↦ ?_, fun H ↦ H ▸ a.inv_mul_of_unit ha⟩
apply_fun (a * ·) at H
rwa [← mul_assoc, a.mul_inv_of_unit ha, one_mul, mul_one, eq_comm] at H
-- TODO: this equivalence is true for `ZMod 0 = ℤ`, but needs to use different functions.
/-- Equivalence between the units of `ZMod n` and
the subtype of terms `x : ZMod n` for which `x.val` is coprime to `n` -/
def unitsEquivCoprime {n : ℕ} [NeZero n] : (ZMod n)ˣ ≃ { x : ZMod n // Nat.Coprime x.val n } where
toFun x := ⟨x, val_coe_unit_coprime x⟩
invFun x := unitOfCoprime x.1.val x.2
left_inv := fun ⟨_, _, _, _⟩ => Units.ext (natCast_zmod_val _)
right_inv := fun ⟨_, _⟩ => by simp
/-- The **Chinese remainder theorem**. For a pair of coprime natural numbers, `m` and `n`,
the rings `ZMod (m * n)` and `ZMod m × ZMod n` are isomorphic.
See `Ideal.quotientInfRingEquivPiQuotient` for the Chinese remainder theorem for ideals in any
ring.
-/
def chineseRemainder {m n : ℕ} (h : m.Coprime n) : ZMod (m * n) ≃+* ZMod m × ZMod n :=
let to_fun : ZMod (m * n) → ZMod m × ZMod n :=
ZMod.castHom (show m.lcm n ∣ m * n by simp [Nat.lcm_dvd_iff]) (ZMod m × ZMod n)
let inv_fun : ZMod m × ZMod n → ZMod (m * n) := fun x =>
if m * n = 0 then
if m = 1 then cast (RingHom.snd _ (ZMod n) x) else cast (RingHom.fst (ZMod m) _ x)
else Nat.chineseRemainder h x.1.val x.2.val
have inv : Function.LeftInverse inv_fun to_fun ∧ Function.RightInverse inv_fun to_fun :=
if hmn0 : m * n = 0 then by
rcases h.eq_of_mul_eq_zero hmn0 with (⟨rfl, rfl⟩ | ⟨rfl, rfl⟩)
· constructor
· intro x; rfl
· rintro ⟨x, y⟩
fin_cases y
simp [to_fun, inv_fun, castHom, Prod.ext_iff, eq_iff_true_of_subsingleton]
· constructor
· intro x; rfl
· rintro ⟨x, y⟩
fin_cases x
simp [to_fun, inv_fun, castHom, Prod.ext_iff, eq_iff_true_of_subsingleton]
else by
haveI : NeZero (m * n) := ⟨hmn0⟩
haveI : NeZero m := ⟨left_ne_zero_of_mul hmn0⟩
haveI : NeZero n := ⟨right_ne_zero_of_mul hmn0⟩
have left_inv : Function.LeftInverse inv_fun to_fun := by
intro x
dsimp only [to_fun, inv_fun, ZMod.castHom_apply]
conv_rhs => rw [← ZMod.natCast_zmod_val x]
rw [if_neg hmn0, ZMod.eq_iff_modEq_nat, ← Nat.modEq_and_modEq_iff_modEq_mul h,
Prod.fst_zmod_cast, Prod.snd_zmod_cast]
refine
⟨(Nat.chineseRemainder h (cast x : ZMod m).val (cast x : ZMod n).val).2.left.trans ?_,
(Nat.chineseRemainder h (cast x : ZMod m).val (cast x : ZMod n).val).2.right.trans ?_⟩
· rw [← ZMod.eq_iff_modEq_nat, ZMod.natCast_zmod_val, ZMod.natCast_val]
· rw [← ZMod.eq_iff_modEq_nat, ZMod.natCast_zmod_val, ZMod.natCast_val]
exact ⟨left_inv, left_inv.rightInverse_of_card_le (by simp)⟩
{ toFun := to_fun,
invFun := inv_fun,
map_mul' := RingHom.map_mul _
map_add' := RingHom.map_add _
left_inv := inv.1
right_inv := inv.2 }
lemma subsingleton_iff {n : ℕ} : Subsingleton (ZMod n) ↔ n = 1 := by
constructor
· obtain (_ | _ | n) := n
· simpa [ZMod] using not_subsingleton _
· simp [ZMod]
· simpa [ZMod] using not_subsingleton _
· rintro rfl
infer_instance
lemma nontrivial_iff {n : ℕ} : Nontrivial (ZMod n) ↔ n ≠ 1 := by
rw [← not_subsingleton_iff_nontrivial, subsingleton_iff]
-- todo: this can be made a `Unique` instance.
instance subsingleton_units : Subsingleton (ZMod 2)ˣ :=
⟨by decide⟩
@[simp]
theorem add_self_eq_zero_iff_eq_zero {n : ℕ} (hn : Odd n) {a : ZMod n} :
a + a = 0 ↔ a = 0 := by
rw [Nat.odd_iff, ← Nat.two_dvd_ne_zero, ← Nat.prime_two.coprime_iff_not_dvd] at hn
rw [← mul_two, ← @Nat.cast_two (ZMod n), ← ZMod.coe_unitOfCoprime 2 hn, Units.mul_left_eq_zero]
theorem ne_neg_self {n : ℕ} (hn : Odd n) {a : ZMod n} (ha : a ≠ 0) : a ≠ -a := by
rwa [Ne, eq_neg_iff_add_eq_zero, add_self_eq_zero_iff_eq_zero hn]
theorem neg_one_ne_one {n : ℕ} [Fact (2 < n)] : (-1 : ZMod n) ≠ 1 :=
CharP.neg_one_ne_one (ZMod n) n
@[simp]
theorem neg_eq_self_mod_two (a : ZMod 2) : -a = a := by
fin_cases a <;> apply Fin.ext <;> simp [Fin.coe_neg, Int.natMod]; rfl
@[simp]
theorem natAbs_mod_two (a : ℤ) : (a.natAbs : ZMod 2) = a := by
cases a
· simp only [Int.natAbs_natCast, Int.cast_natCast, Int.ofNat_eq_coe]
· simp only [neg_eq_self_mod_two, Nat.cast_succ, Int.natAbs, Int.cast_negSucc]
theorem val_ne_zero {n : ℕ} (a : ZMod n) : a.val ≠ 0 ↔ a ≠ 0 :=
(val_eq_zero a).not
theorem val_pos {n : ℕ} {a : ZMod n} : 0 < a.val ↔ a ≠ 0 := by
simp [pos_iff_ne_zero]
theorem val_eq_one : ∀ {n : ℕ} (_ : 1 < n) (a : ZMod n), a.val = 1 ↔ a = 1
| 0, hn, _
| 1, hn, _ => by simp at hn
| n + 2, _, _ => by simp only [val, ZMod, Fin.ext_iff, Fin.val_one]
theorem neg_eq_self_iff {n : ℕ} (a : ZMod n) : -a = a ↔ a = 0 ∨ 2 * a.val = n := by
rw [neg_eq_iff_add_eq_zero, ← two_mul]
cases n
· rw [@mul_eq_zero ℤ, @mul_eq_zero ℕ, val_eq_zero]
exact
⟨fun h => h.elim (by simp) Or.inl, fun h =>
Or.inr (h.elim id fun h => h.elim (by simp) id)⟩
conv_lhs =>
rw [← a.natCast_zmod_val, ← Nat.cast_two, ← Nat.cast_mul, natCast_zmod_eq_zero_iff_dvd]
constructor
· rintro ⟨m, he⟩
rcases m with - | m
· rw [mul_zero, mul_eq_zero] at he
rcases he with (⟨⟨⟩⟩ | he)
exact Or.inl (a.val_eq_zero.1 he)
cases m
· right
rwa [show 0 + 1 = 1 from rfl, mul_one] at he
refine (a.val_lt.not_le <| Nat.le_of_mul_le_mul_left ?_ zero_lt_two).elim
rw [he, mul_comm]
apply Nat.mul_le_mul_left
simp
· rintro (rfl | h)
· rw [val_zero, mul_zero]
apply dvd_zero
· rw [h]
theorem val_cast_of_lt {n : ℕ} {a : ℕ} (h : a < n) : (a : ZMod n).val = a := by
rw [val_natCast, Nat.mod_eq_of_lt h]
theorem val_cast_zmod_lt {m : ℕ} [NeZero m] (n : ℕ) [NeZero n] (a : ZMod m) :
(a.cast : ZMod n).val < m := by
rcases m with (⟨⟩|⟨m⟩); · cases NeZero.ne 0 rfl
by_cases h : m < n
· rcases n with (⟨⟩|⟨n⟩); · simp at h
rw [← natCast_val, val_cast_of_lt]
· apply a.val_lt
apply lt_of_le_of_lt (Nat.le_of_lt_succ (ZMod.val_lt a)) h
· rw [not_lt] at h
apply lt_of_lt_of_le (ZMod.val_lt _) (le_trans h (Nat.le_succ m))
theorem neg_val' {n : ℕ} [NeZero n] (a : ZMod n) : (-a).val = (n - a.val) % n :=
calc
(-a).val = val (-a) % n := by rw [Nat.mod_eq_of_lt (-a).val_lt]
_ = (n - val a) % n :=
Nat.ModEq.add_right_cancel' (val a)
(by
rw [Nat.ModEq, ← val_add, neg_add_cancel, tsub_add_cancel_of_le a.val_le, Nat.mod_self,
val_zero])
theorem neg_val {n : ℕ} [NeZero n] (a : ZMod n) : (-a).val = if a = 0 then 0 else n - a.val := by
rw [neg_val']
by_cases h : a = 0; · rw [if_pos h, h, val_zero, tsub_zero, Nat.mod_self]
rw [if_neg h]
apply Nat.mod_eq_of_lt
apply Nat.sub_lt (NeZero.pos n)
contrapose! h
rwa [Nat.le_zero, val_eq_zero] at h
theorem val_neg_of_ne_zero {n : ℕ} [nz : NeZero n] (a : ZMod n) [na : NeZero a] :
(- a).val = n - a.val := by simp_all [neg_val a, na.out]
theorem val_sub {n : ℕ} [NeZero n] {a b : ZMod n} (h : b.val ≤ a.val) :
(a - b).val = a.val - b.val := by
by_cases hb : b = 0
· cases hb; simp
· have : NeZero b := ⟨hb⟩
rw [sub_eq_add_neg, val_add, val_neg_of_ne_zero, ← Nat.add_sub_assoc (le_of_lt (val_lt _)),
add_comm, Nat.add_sub_assoc h, Nat.add_mod_left]
apply Nat.mod_eq_of_lt (tsub_lt_of_lt (val_lt _))
theorem val_cast_eq_val_of_lt {m n : ℕ} [nzm : NeZero m] {a : ZMod m}
(h : a.val < n) : (a.cast : ZMod n).val = a.val := by
have nzn : NeZero n := by constructor; rintro rfl; simp at h
cases m with
| zero => cases nzm; simp_all
| succ m =>
cases n with
| zero => cases nzn; simp_all
| succ n => exact Fin.val_cast_of_lt h
theorem cast_cast_zmod_of_le {m n : ℕ} [hm : NeZero m] (h : m ≤ n) (a : ZMod m) :
(cast (cast a : ZMod n) : ZMod m) = a := by
have : NeZero n := ⟨((Nat.zero_lt_of_ne_zero hm.out).trans_le h).ne'⟩
rw [cast_eq_val, val_cast_eq_val_of_lt (a.val_lt.trans_le h), natCast_zmod_val]
theorem val_pow {m n : ℕ} {a : ZMod n} [ilt : Fact (1 < n)] (h : a.val ^ m < n) :
(a ^ m).val = a.val ^ m := by
induction m with
| zero => simp [ZMod.val_one]
| succ m ih =>
have : a.val ^ m < n := by
obtain rfl | ha := eq_or_ne a 0
· by_cases hm : m = 0
· cases hm; simp [ilt.out]
· simp only [val_zero, ne_eq, hm, not_false_eq_true, zero_pow, Nat.zero_lt_of_lt h]
· exact lt_of_le_of_lt
(Nat.pow_le_pow_right (by rwa [gt_iff_lt, ZMod.val_pos]) (Nat.le_succ m)) h
rw [pow_succ, ZMod.val_mul, ih this, ← pow_succ, Nat.mod_eq_of_lt h]
theorem val_pow_le {m n : ℕ} [Fact (1 < n)] {a : ZMod n} : (a ^ m).val ≤ a.val ^ m := by
induction m with
| zero => simp [ZMod.val_one]
| succ m ih =>
rw [pow_succ, pow_succ]
apply le_trans (ZMod.val_mul_le _ _)
apply Nat.mul_le_mul_right _ ih
theorem natAbs_min_of_le_div_two (n : ℕ) (x y : ℤ) (he : (x : ZMod n) = y) (hl : x.natAbs ≤ n / 2) :
x.natAbs ≤ y.natAbs := by
rw [intCast_eq_intCast_iff_dvd_sub] at he
obtain ⟨m, he⟩ := he
rw [sub_eq_iff_eq_add] at he
subst he
obtain rfl | hm := eq_or_ne m 0
· rw [mul_zero, zero_add]
apply hl.trans
rw [← add_le_add_iff_right x.natAbs]
refine le_trans (le_trans ((add_le_add_iff_left _).2 hl) ?_) (Int.natAbs_sub_le _ _)
rw [add_sub_cancel_right, Int.natAbs_mul, Int.natAbs_natCast]
refine le_trans ?_ (Nat.le_mul_of_pos_right _ <| Int.natAbs_pos.2 hm)
rw [← mul_two]; apply Nat.div_mul_le_self
end ZMod
theorem RingHom.ext_zmod {n : ℕ} {R : Type*} [NonAssocSemiring R] (f g : ZMod n →+* R) : f = g := by
ext a
obtain ⟨k, rfl⟩ := ZMod.intCast_surjective a
let φ : ℤ →+* R := f.comp (Int.castRingHom (ZMod n))
let ψ : ℤ →+* R := g.comp (Int.castRingHom (ZMod n))
show φ k = ψ k
rw [φ.ext_int ψ]
namespace ZMod
variable {n : ℕ} {R : Type*}
instance subsingleton_ringHom [Semiring R] : Subsingleton (ZMod n →+* R) :=
⟨RingHom.ext_zmod⟩
instance subsingleton_ringEquiv [Semiring R] : Subsingleton (ZMod n ≃+* R) :=
⟨fun f g => by
rw [RingEquiv.coe_ringHom_inj_iff]
apply RingHom.ext_zmod _ _⟩
@[simp]
theorem ringHom_map_cast [NonAssocRing R] (f : R →+* ZMod n) (k : ZMod n) : f (cast k) = k := by
cases n
· dsimp [ZMod, ZMod.cast] at f k ⊢; simp
· dsimp [ZMod.cast]
rw [map_natCast, natCast_zmod_val]
/-- Any ring homomorphism into `ZMod n` has a right inverse. -/
theorem ringHom_rightInverse [NonAssocRing R] (f : R →+* ZMod n) :
Function.RightInverse (cast : ZMod n → R) f :=
ringHom_map_cast f
/-- Any ring homomorphism into `ZMod n` is surjective. -/
theorem ringHom_surjective [NonAssocRing R] (f : R →+* ZMod n) : Function.Surjective f :=
(ringHom_rightInverse f).surjective
@[simp]
lemma castHom_self : ZMod.castHom dvd_rfl (ZMod n) = RingHom.id (ZMod n) :=
Subsingleton.elim _ _
@[simp]
lemma castHom_comp {m d : ℕ} (hm : n ∣ m) (hd : m ∣ d) :
(castHom hm (ZMod n)).comp (castHom hd (ZMod m)) = castHom (dvd_trans hm hd) (ZMod n) :=
RingHom.ext_zmod _ _
section lift
variable (n) {A : Type*} [AddGroup A]
/-- The map from `ZMod n` induced by `f : ℤ →+ A` that maps `n` to `0`. -/
def lift : { f : ℤ →+ A // f n = 0 } ≃ (ZMod n →+ A) :=
(Equiv.subtypeEquivRight <| by
intro f
rw [ker_intCastAddHom]
constructor
· rintro hf _ ⟨x, rfl⟩
simp only [f.map_zsmul, zsmul_zero, f.mem_ker, hf]
· intro h
exact h (AddSubgroup.mem_zmultiples _)).trans <|
(Int.castAddHom (ZMod n)).liftOfRightInverse cast intCast_zmod_cast
variable (f : { f : ℤ →+ A // f n = 0 })
@[simp]
theorem lift_coe (x : ℤ) : lift n f (x : ZMod n) = f.val x :=
AddMonoidHom.liftOfRightInverse_comp_apply _ _ (fun _ => intCast_zmod_cast _) _ _
theorem lift_castAddHom (x : ℤ) : lift n f (Int.castAddHom (ZMod n) x) = f.1 x :=
AddMonoidHom.liftOfRightInverse_comp_apply _ _ (fun _ => intCast_zmod_cast _) _ _
@[simp]
theorem lift_comp_coe : ZMod.lift n f ∘ ((↑) : ℤ → _) = f :=
funext <| lift_coe _ _
@[simp]
theorem lift_comp_castAddHom : (ZMod.lift n f).comp (Int.castAddHom (ZMod n)) = f :=
AddMonoidHom.ext <| lift_castAddHom _ _
lemma lift_injective {f : {f : ℤ →+ A // f n = 0}} :
Injective (lift n f) ↔ ∀ m, f.1 m = 0 → (m : ZMod n) = 0 := by
simp only [← AddMonoidHom.ker_eq_bot_iff, eq_bot_iff, SetLike.le_def,
ZMod.intCast_surjective.forall, ZMod.lift_coe, AddMonoidHom.mem_ker, AddSubgroup.mem_bot]
end lift
end ZMod
/-!
### Groups of bounded torsion
For `G` a group and `n` a natural number, `G` having torsion dividing `n`
(`∀ x : G, n • x = 0`) can be derived from `Module R G` where `R` has characteristic dividing `n`.
It is however painful to have the API for such groups `G` stated in this generality, as `R` does not
appear anywhere in the lemmas' return type. Instead of writing the API in terms of a general `R`, we
therefore specialise to the canonical ring of order `n`, namely `ZMod n`.
This spelling `Module (ZMod n) G` has the extra advantage of providing the canonical action by
`ZMod n`. It is however Type-valued, so we might want to acquire a Prop-valued version in the
future.
-/
section Module
variable {n : ℕ} {S G : Type*} [AddCommGroup G] [SetLike S G] [AddSubgroupClass S G] {K : S} {x : G}
section general
variable [Module (ZMod n) G] {x : G}
lemma zmod_smul_mem (hx : x ∈ K) : ∀ a : ZMod n, a • x ∈ K := by
simpa [ZMod.forall, Int.cast_smul_eq_zsmul] using zsmul_mem hx
/-- This cannot be made an instance because of the `[Module (ZMod n) G]` argument and the fact that
`n` only appears in the second argument of `SMulMemClass`, which is an `OutParam`. -/
lemma smulMemClass : SMulMemClass S (ZMod n) G where smul_mem _ _ {_x} hx := zmod_smul_mem hx _
namespace AddSubgroupClass
instance instZModSMul : SMul (ZMod n) K where smul a x := ⟨a • x, zmod_smul_mem x.2 _⟩
@[simp, norm_cast] lemma coe_zmod_smul (a : ZMod n) (x : K) : ↑(a • x) = (a • x : G) := rfl
instance instZModModule : Module (ZMod n) K :=
Subtype.coe_injective.module _ (AddSubmonoidClass.subtype K) coe_zmod_smul
end AddSubgroupClass
variable (n)
lemma ZModModule.char_nsmul_eq_zero (x : G) : n • x = 0 := by
simp [← Nat.cast_smul_eq_nsmul (ZMod n)]
variable (G) in
lemma ZModModule.char_ne_one [Nontrivial G] : n ≠ 1 := by
rintro rfl
obtain ⟨x, hx⟩ := exists_ne (0 : G)
exact hx <| by simpa using char_nsmul_eq_zero 1 x
variable (G) in
lemma ZModModule.two_le_char [NeZero n] [Nontrivial G] : 2 ≤ n := by
have := NeZero.ne n
have := char_ne_one n G
omega
lemma ZModModule.periodicPts_add_left [NeZero n] (x : G) : periodicPts (x + ·) = .univ :=
Set.eq_univ_of_forall fun y ↦ ⟨n, NeZero.pos n, by
simpa [char_nsmul_eq_zero, IsPeriodicPt] using isFixedPt_id _⟩
end general
section two
variable [Module (ZMod 2) G]
lemma ZModModule.add_self (x : G) : x + x = 0 := by
simpa [two_nsmul] using char_nsmul_eq_zero 2 x
lemma ZModModule.neg_eq_self (x : G) : -x = x := by simp [add_self, eq_comm, ← sub_eq_zero]
lemma ZModModule.sub_eq_add (x y : G) : x - y = x + y := by simp [neg_eq_self, sub_eq_add_neg]
lemma ZModModule.add_add_add_cancel (x y z : G) : (x + y) + (y + z) = x + z := by
simpa [sub_eq_add] using sub_add_sub_cancel x y z
end two
end Module
section AddGroup
variable {α : Type*} [AddGroup α] {n : ℕ}
@[simp]
lemma nsmul_zmod_val_inv_nsmul (hn : (Nat.card α).Coprime n) (a : α) :
n • (n⁻¹ : ZMod (Nat.card α)).val • a = a := by
rw [← mul_nsmul', ← mod_natCard_nsmul, ← ZMod.val_natCast, Nat.cast_mul,
ZMod.mul_val_inv hn.symm, ZMod.val_one_eq_one_mod, mod_natCard_nsmul, one_nsmul]
@[simp]
lemma zmod_val_inv_nsmul_nsmul (hn : (Nat.card α).Coprime n) (a : α) :
(n⁻¹ : ZMod (Nat.card α)).val • n • a = a := by
rw [nsmul_left_comm, nsmul_zmod_val_inv_nsmul hn]
end AddGroup
section Group
variable {α : Type*} [Group α] {n : ℕ}
-- TODO: Without the `existing`, `to_additive` chokes on `Inv (ZMod n)`.
@[to_additive existing (attr := simp) nsmul_zmod_val_inv_nsmul]
lemma pow_zmod_val_inv_pow (hn : (Nat.card α).Coprime n) (a : α) :
(a ^ (n⁻¹ : ZMod (Nat.card α)).val) ^ n = a := by
rw [← pow_mul', ← pow_mod_natCard, ← ZMod.val_natCast, Nat.cast_mul, ZMod.mul_val_inv hn.symm,
ZMod.val_one_eq_one_mod, pow_mod_natCard, pow_one]
@[to_additive existing (attr := simp) zmod_val_inv_nsmul_nsmul]
lemma pow_pow_zmod_val_inv (hn : (Nat.card α).Coprime n) (a : α) :
(a ^ n) ^ (n⁻¹ : ZMod (Nat.card α)).val = a := by rw [pow_right_comm, pow_zmod_val_inv_pow hn]
end Group
open ZMod
/-- The range of `(m * · + k)` on natural numbers is the set of elements `≥ k` in the
residue class of `k` mod `m`. -/
lemma Nat.range_mul_add (m k : ℕ) :
Set.range (fun n : ℕ ↦ m * n + k) = {n : ℕ | (n : ZMod m) = k ∧ k ≤ n} := by
ext n
simp only [Set.mem_range, Set.mem_setOf_eq]
conv => enter [1, 1, y]; rw [add_comm, eq_comm]
refine ⟨fun ⟨a, ha⟩ ↦ ⟨?_, le_iff_exists_add.mpr ⟨_, ha⟩⟩, fun ⟨H₁, H₂⟩ ↦ ?_⟩
· simpa using congr_arg ((↑) : ℕ → ZMod m) ha
· obtain ⟨a, ha⟩ := le_iff_exists_add.mp H₂
simp only [ha, Nat.cast_add, add_eq_left, ZMod.natCast_zmod_eq_zero_iff_dvd] at H₁
obtain ⟨b, rfl⟩ := H₁
exact ⟨b, ha⟩
/-- Equivalence between `ℕ` and `ZMod N × ℕ`, sending `n` to `(n mod N, n / N)`. -/
def Nat.residueClassesEquiv (N : ℕ) [NeZero N] : ℕ ≃ ZMod N × ℕ where
toFun n := (↑n, n / N)
invFun p := p.1.val + N * p.2
left_inv n := by simpa only [val_natCast] using mod_add_div n N
right_inv p := by
ext1
· simp only [add_comm p.1.val, cast_add, cast_mul, natCast_self, zero_mul, natCast_val,
cast_id', id_eq, zero_add]
· simp only [add_comm p.1.val, mul_add_div (NeZero.pos _),
(Nat.div_eq_zero_iff).2 <| .inr p.1.val_lt, add_zero]
| Mathlib/Data/ZMod/Basic.lean | 1,324 | 1,337 | |
/-
Copyright (c) 2019 Kim Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kim Morrison, Jakob von Raumer
-/
import Mathlib.CategoryTheory.Limits.Shapes.FiniteProducts
import Mathlib.CategoryTheory.Limits.Shapes.Kernels
/-!
# Biproducts and binary biproducts
We introduce the notion of (finite) biproducts.
Binary biproducts are defined in `CategoryTheory.Limits.Shapes.BinaryBiproducts`.
These are slightly unusual relative to the other shapes in the library,
as they are simultaneously limits and colimits.
(Zero objects are similar; they are "biterminal".)
For results about biproducts in preadditive categories see
`CategoryTheory.Preadditive.Biproducts`.
For biproducts indexed by a `Fintype J`, a `bicone` consists of a cone point `X`
and morphisms `π j : X ⟶ F j` and `ι j : F j ⟶ X` for each `j`,
such that `ι j ≫ π j'` is the identity when `j = j'` and zero otherwise.
## Notation
As `⊕` is already taken for the sum of types, we introduce the notation `X ⊞ Y` for
a binary biproduct. We introduce `⨁ f` for the indexed biproduct.
## Implementation notes
Prior to https://github.com/leanprover-community/mathlib3/pull/14046,
`HasFiniteBiproducts` required a `DecidableEq` instance on the indexing type.
As this had no pay-off (everything about limits is non-constructive in mathlib),
and occasional cost
(constructing decidability instances appropriate for constructions involving the indexing type),
we made everything classical.
-/
noncomputable section
universe w w' v u
open CategoryTheory Functor
namespace CategoryTheory.Limits
variable {J : Type w}
universe uC' uC uD' uD
variable {C : Type uC} [Category.{uC'} C] [HasZeroMorphisms C]
variable {D : Type uD} [Category.{uD'} D] [HasZeroMorphisms D]
open scoped Classical in
/-- A `c : Bicone F` is:
* an object `c.pt` and
* morphisms `π j : pt ⟶ F j` and `ι j : F j ⟶ pt` for each `j`,
* such that `ι j ≫ π j'` is the identity when `j = j'` and zero otherwise.
-/
structure Bicone (F : J → C) where
pt : C
π : ∀ j, pt ⟶ F j
ι : ∀ j, F j ⟶ pt
ι_π : ∀ j j', ι j ≫ π j' =
if h : j = j' then eqToHom (congrArg F h) else 0 := by aesop
attribute [inherit_doc Bicone] Bicone.pt Bicone.π Bicone.ι Bicone.ι_π
@[reassoc (attr := simp)]
theorem bicone_ι_π_self {F : J → C} (B : Bicone F) (j : J) : B.ι j ≫ B.π j = 𝟙 (F j) := by
simpa using B.ι_π j j
@[reassoc (attr := simp)]
theorem bicone_ι_π_ne {F : J → C} (B : Bicone F) {j j' : J} (h : j ≠ j') : B.ι j ≫ B.π j' = 0 := by
simpa [h] using B.ι_π j j'
variable {F : J → C}
/-- A bicone morphism between two bicones for the same diagram is a morphism of the bicone points
which commutes with the cone and cocone legs. -/
structure BiconeMorphism {F : J → C} (A B : Bicone F) where
/-- A morphism between the two vertex objects of the bicones -/
hom : A.pt ⟶ B.pt
/-- The triangle consisting of the two natural transformations and `hom` commutes -/
wπ : ∀ j : J, hom ≫ B.π j = A.π j := by aesop_cat
/-- The triangle consisting of the two natural transformations and `hom` commutes -/
wι : ∀ j : J, A.ι j ≫ hom = B.ι j := by aesop_cat
attribute [reassoc (attr := simp)] BiconeMorphism.wι BiconeMorphism.wπ
/-- The category of bicones on a given diagram. -/
@[simps]
instance Bicone.category : Category (Bicone F) where
Hom A B := BiconeMorphism A B
comp f g := { hom := f.hom ≫ g.hom }
id B := { hom := 𝟙 B.pt }
-- Porting note: if we do not have `simps` automatically generate the lemma for simplifying
-- the `hom` field of a category, we need to write the `ext` lemma in terms of the categorical
-- morphism, rather than the underlying structure.
@[ext]
theorem BiconeMorphism.ext {c c' : Bicone F} (f g : c ⟶ c') (w : f.hom = g.hom) : f = g := by
cases f
cases g
congr
namespace Bicones
/-- To give an isomorphism between cocones, it suffices to give an
isomorphism between their vertices which commutes with the cocone
maps. -/
@[aesop apply safe (rule_sets := [CategoryTheory]), simps]
def ext {c c' : Bicone F} (φ : c.pt ≅ c'.pt)
(wι : ∀ j, c.ι j ≫ φ.hom = c'.ι j := by aesop_cat)
(wπ : ∀ j, φ.hom ≫ c'.π j = c.π j := by aesop_cat) : c ≅ c' where
hom := { hom := φ.hom }
inv :=
{ hom := φ.inv
wι := fun j => φ.comp_inv_eq.mpr (wι j).symm
wπ := fun j => φ.inv_comp_eq.mpr (wπ j).symm }
variable (F) in
/-- A functor `G : C ⥤ D` sends bicones over `F` to bicones over `G.obj ∘ F` functorially. -/
@[simps]
def functoriality (G : C ⥤ D) [Functor.PreservesZeroMorphisms G] :
Bicone F ⥤ Bicone (G.obj ∘ F) where
obj A :=
{ pt := G.obj A.pt
π := fun j => G.map (A.π j)
ι := fun j => G.map (A.ι j)
ι_π := fun i j => (Functor.map_comp _ _ _).symm.trans <| by
rw [A.ι_π]
aesop_cat }
map f :=
{ hom := G.map f.hom
wπ := fun j => by simp [-BiconeMorphism.wπ, ← f.wπ j]
wι := fun j => by simp [-BiconeMorphism.wι, ← f.wι j] }
variable (G : C ⥤ D)
instance functoriality_full [G.PreservesZeroMorphisms] [G.Full] [G.Faithful] :
(functoriality F G).Full where
map_surjective t :=
⟨{ hom := G.preimage t.hom
wι := fun j => G.map_injective (by simpa using t.wι j)
wπ := fun j => G.map_injective (by simpa using t.wπ j) }, by aesop_cat⟩
instance functoriality_faithful [G.PreservesZeroMorphisms] [G.Faithful] :
(functoriality F G).Faithful where
map_injective {_X} {_Y} f g h :=
BiconeMorphism.ext f g <| G.map_injective <| congr_arg BiconeMorphism.hom h
end Bicones
namespace Bicone
attribute [local aesop safe tactic (rule_sets := [CategoryTheory])]
CategoryTheory.Discrete.discreteCases
-- Porting note: would it be okay to use this more generally?
attribute [local aesop safe cases (rule_sets := [CategoryTheory])] Eq
/-- Extract the cone from a bicone. -/
def toConeFunctor : Bicone F ⥤ Cone (Discrete.functor F) where
obj B := { pt := B.pt, π := { app := fun j => B.π j.as } }
map {_ _} F := { hom := F.hom, w := fun _ => F.wπ _ }
/-- A shorthand for `toConeFunctor.obj` -/
abbrev toCone (B : Bicone F) : Cone (Discrete.functor F) := toConeFunctor.obj B
-- TODO Consider changing this API to `toFan (B : Bicone F) : Fan F`.
@[simp] theorem toCone_pt (B : Bicone F) : B.toCone.pt = B.pt := rfl
@[simp] theorem toCone_π_app (B : Bicone F) (j : Discrete J) : B.toCone.π.app j = B.π j.as := rfl
theorem toCone_π_app_mk (B : Bicone F) (j : J) : B.toCone.π.app ⟨j⟩ = B.π j := rfl
@[simp] theorem toCone_proj (B : Bicone F) (j : J) : Fan.proj B.toCone j = B.π j := rfl
/-- Extract the cocone from a bicone. -/
def toCoconeFunctor : Bicone F ⥤ Cocone (Discrete.functor F) where
obj B := { pt := B.pt, ι := { app := fun j => B.ι j.as } }
map {_ _} F := { hom := F.hom, w := fun _ => F.wι _ }
/-- A shorthand for `toCoconeFunctor.obj` -/
abbrev toCocone (B : Bicone F) : Cocone (Discrete.functor F) := toCoconeFunctor.obj B
@[simp] theorem toCocone_pt (B : Bicone F) : B.toCocone.pt = B.pt := rfl
@[simp]
theorem toCocone_ι_app (B : Bicone F) (j : Discrete J) : B.toCocone.ι.app j = B.ι j.as := rfl
@[simp] theorem toCocone_inj (B : Bicone F) (j : J) : Cofan.inj B.toCocone j = B.ι j := rfl
theorem toCocone_ι_app_mk (B : Bicone F) (j : J) : B.toCocone.ι.app ⟨j⟩ = B.ι j := rfl
open scoped Classical in
/-- We can turn any limit cone over a discrete collection of objects into a bicone. -/
@[simps]
def ofLimitCone {f : J → C} {t : Cone (Discrete.functor f)} (ht : IsLimit t) : Bicone f where
pt := t.pt
π j := t.π.app ⟨j⟩
ι j := ht.lift (Fan.mk _ fun j' => if h : j = j' then eqToHom (congr_arg f h) else 0)
ι_π j j' := by simp
open scoped Classical in
theorem ι_of_isLimit {f : J → C} {t : Bicone f} (ht : IsLimit t.toCone) (j : J) :
t.ι j = ht.lift (Fan.mk _ fun j' => if h : j = j' then eqToHom (congr_arg f h) else 0) :=
ht.hom_ext fun j' => by
rw [ht.fac]
simp [t.ι_π]
open scoped Classical in
/-- We can turn any colimit cocone over a discrete collection of objects into a bicone. -/
@[simps]
def ofColimitCocone {f : J → C} {t : Cocone (Discrete.functor f)} (ht : IsColimit t) :
Bicone f where
pt := t.pt
π j := ht.desc (Cofan.mk _ fun j' => if h : j' = j then eqToHom (congr_arg f h) else 0)
ι j := t.ι.app ⟨j⟩
ι_π j j' := by simp
open scoped Classical in
theorem π_of_isColimit {f : J → C} {t : Bicone f} (ht : IsColimit t.toCocone) (j : J) :
t.π j = ht.desc (Cofan.mk _ fun j' => if h : j' = j then eqToHom (congr_arg f h) else 0) :=
ht.hom_ext fun j' => by
rw [ht.fac]
simp [t.ι_π]
/-- Structure witnessing that a bicone is both a limit cone and a colimit cocone. -/
structure IsBilimit {F : J → C} (B : Bicone F) where
isLimit : IsLimit B.toCone
isColimit : IsColimit B.toCocone
attribute [inherit_doc IsBilimit] IsBilimit.isLimit IsBilimit.isColimit
attribute [simp] IsBilimit.mk.injEq
attribute [local ext] Bicone.IsBilimit
instance subsingleton_isBilimit {f : J → C} {c : Bicone f} : Subsingleton c.IsBilimit :=
⟨fun _ _ => Bicone.IsBilimit.ext (Subsingleton.elim _ _) (Subsingleton.elim _ _)⟩
section Whisker
variable {K : Type w'}
/-- Whisker a bicone with an equivalence between the indexing types. -/
@[simps]
def whisker {f : J → C} (c : Bicone f) (g : K ≃ J) : Bicone (f ∘ g) where
pt := c.pt
π k := c.π (g k)
ι k := c.ι (g k)
ι_π k k' := by
simp only [c.ι_π]
split_ifs with h h' h' <;> simp [Equiv.apply_eq_iff_eq g] at h h' <;> tauto
/-- Taking the cone of a whiskered bicone results in a cone isomorphic to one gained
by whiskering the cone and postcomposing with a suitable isomorphism. -/
def whiskerToCone {f : J → C} (c : Bicone f) (g : K ≃ J) :
(c.whisker g).toCone ≅
(Cones.postcompose (Discrete.functorComp f g).inv).obj
(c.toCone.whisker (Discrete.functor (Discrete.mk ∘ g))) :=
Cones.ext (Iso.refl _) (by simp)
/-- Taking the cocone of a whiskered bicone results in a cone isomorphic to one gained
by whiskering the cocone and precomposing with a suitable isomorphism. -/
def whiskerToCocone {f : J → C} (c : Bicone f) (g : K ≃ J) :
(c.whisker g).toCocone ≅
(Cocones.precompose (Discrete.functorComp f g).hom).obj
(c.toCocone.whisker (Discrete.functor (Discrete.mk ∘ g))) :=
Cocones.ext (Iso.refl _) (by simp)
/-- Whiskering a bicone with an equivalence between types preserves being a bilimit bicone. -/
noncomputable def whiskerIsBilimitIff {f : J → C} (c : Bicone f) (g : K ≃ J) :
(c.whisker g).IsBilimit ≃ c.IsBilimit := by
refine equivOfSubsingletonOfSubsingleton (fun hc => ⟨?_, ?_⟩) fun hc => ⟨?_, ?_⟩
· let this := IsLimit.ofIsoLimit hc.isLimit (Bicone.whiskerToCone c g)
let this := (IsLimit.postcomposeHomEquiv (Discrete.functorComp f g).symm _) this
exact IsLimit.ofWhiskerEquivalence (Discrete.equivalence g) this
· let this := IsColimit.ofIsoColimit hc.isColimit (Bicone.whiskerToCocone c g)
let this := (IsColimit.precomposeHomEquiv (Discrete.functorComp f g) _) this
exact IsColimit.ofWhiskerEquivalence (Discrete.equivalence g) this
· apply IsLimit.ofIsoLimit _ (Bicone.whiskerToCone c g).symm
apply (IsLimit.postcomposeHomEquiv (Discrete.functorComp f g).symm _).symm _
exact IsLimit.whiskerEquivalence hc.isLimit (Discrete.equivalence g)
· apply IsColimit.ofIsoColimit _ (Bicone.whiskerToCocone c g).symm
apply (IsColimit.precomposeHomEquiv (Discrete.functorComp f g) _).symm _
exact IsColimit.whiskerEquivalence hc.isColimit (Discrete.equivalence g)
end Whisker
end Bicone
/-- A bicone over `F : J → C`, which is both a limit cone and a colimit cocone. -/
structure LimitBicone (F : J → C) where
bicone : Bicone F
isBilimit : bicone.IsBilimit
attribute [inherit_doc LimitBicone] LimitBicone.bicone LimitBicone.isBilimit
/-- `HasBiproduct F` expresses the mere existence of a bicone which is
simultaneously a limit and a colimit of the diagram `F`. -/
class HasBiproduct (F : J → C) : Prop where mk' ::
exists_biproduct : Nonempty (LimitBicone F)
attribute [inherit_doc HasBiproduct] HasBiproduct.exists_biproduct
theorem HasBiproduct.mk {F : J → C} (d : LimitBicone F) : HasBiproduct F :=
⟨Nonempty.intro d⟩
/-- Use the axiom of choice to extract explicit `BiproductData F` from `HasBiproduct F`. -/
def getBiproductData (F : J → C) [HasBiproduct F] : LimitBicone F :=
Classical.choice HasBiproduct.exists_biproduct
/-- A bicone for `F` which is both a limit cone and a colimit cocone. -/
def biproduct.bicone (F : J → C) [HasBiproduct F] : Bicone F :=
(getBiproductData F).bicone
/-- `biproduct.bicone F` is a bilimit bicone. -/
def biproduct.isBilimit (F : J → C) [HasBiproduct F] : (biproduct.bicone F).IsBilimit :=
(getBiproductData F).isBilimit
/-- `biproduct.bicone F` is a limit cone. -/
def biproduct.isLimit (F : J → C) [HasBiproduct F] : IsLimit (biproduct.bicone F).toCone :=
(getBiproductData F).isBilimit.isLimit
/-- `biproduct.bicone F` is a colimit cocone. -/
def biproduct.isColimit (F : J → C) [HasBiproduct F] : IsColimit (biproduct.bicone F).toCocone :=
(getBiproductData F).isBilimit.isColimit
instance (priority := 100) hasProduct_of_hasBiproduct [HasBiproduct F] : HasProduct F :=
HasLimit.mk
{ cone := (biproduct.bicone F).toCone
isLimit := biproduct.isLimit F }
instance (priority := 100) hasCoproduct_of_hasBiproduct [HasBiproduct F] : HasCoproduct F :=
HasColimit.mk
{ cocone := (biproduct.bicone F).toCocone
isColimit := biproduct.isColimit F }
variable (J C)
/-- `C` has biproducts of shape `J` if we have
a limit and a colimit, with the same cone points,
of every function `F : J → C`. -/
class HasBiproductsOfShape : Prop where
has_biproduct : ∀ F : J → C, HasBiproduct F
attribute [instance 100] HasBiproductsOfShape.has_biproduct
/-- `HasFiniteBiproducts C` represents a choice of biproduct for every family of objects in `C`
indexed by a finite type. -/
class HasFiniteBiproducts : Prop where
out : ∀ n, HasBiproductsOfShape (Fin n) C
attribute [inherit_doc HasFiniteBiproducts] HasFiniteBiproducts.out
variable {J}
theorem hasBiproductsOfShape_of_equiv {K : Type w'} [HasBiproductsOfShape K C] (e : J ≃ K) :
HasBiproductsOfShape J C :=
⟨fun F =>
let ⟨⟨h⟩⟩ := HasBiproductsOfShape.has_biproduct (F ∘ e.symm)
let ⟨c, hc⟩ := h
HasBiproduct.mk <| by
simpa only [Function.comp_def, e.symm_apply_apply] using
LimitBicone.mk (c.whisker e) ((c.whiskerIsBilimitIff _).2 hc)⟩
instance (priority := 100) hasBiproductsOfShape_finite [HasFiniteBiproducts C] [Finite J] :
HasBiproductsOfShape J C := by
rcases Finite.exists_equiv_fin J with ⟨n, ⟨e⟩⟩
haveI : HasBiproductsOfShape (Fin n) C := HasFiniteBiproducts.out n
exact hasBiproductsOfShape_of_equiv C e
instance (priority := 100) hasFiniteProducts_of_hasFiniteBiproducts [HasFiniteBiproducts C] :
HasFiniteProducts C where
out _ := ⟨fun _ => hasLimit_of_iso Discrete.natIsoFunctor.symm⟩
instance (priority := 100) hasFiniteCoproducts_of_hasFiniteBiproducts [HasFiniteBiproducts C] :
HasFiniteCoproducts C where
out _ := ⟨fun _ => hasColimit_of_iso Discrete.natIsoFunctor⟩
instance (priority := 100) hasProductsOfShape_of_hasBiproductsOfShape [HasBiproductsOfShape J C] :
HasProductsOfShape J C where
has_limit _ := hasLimit_of_iso Discrete.natIsoFunctor.symm
instance (priority := 100) hasCoproductsOfShape_of_hasBiproductsOfShape [HasBiproductsOfShape J C] :
HasCoproductsOfShape J C where
has_colimit _ := hasColimit_of_iso Discrete.natIsoFunctor
variable {C}
/-- The isomorphism between the specified limit and the specified colimit for
a functor with a bilimit. -/
def biproductIso (F : J → C) [HasBiproduct F] : Limits.piObj F ≅ Limits.sigmaObj F :=
(IsLimit.conePointUniqueUpToIso (limit.isLimit _) (biproduct.isLimit F)).trans <|
IsColimit.coconePointUniqueUpToIso (biproduct.isColimit F) (colimit.isColimit _)
variable {J : Type w} {K : Type*}
variable {C : Type u} [Category.{v} C] [HasZeroMorphisms C]
/-- `biproduct f` computes the biproduct of a family of elements `f`. (It is defined as an
abbreviation for `limit (Discrete.functor f)`, so for most facts about `biproduct f`, you will
just use general facts about limits and colimits.) -/
abbrev biproduct (f : J → C) [HasBiproduct f] : C :=
(biproduct.bicone f).pt
@[inherit_doc biproduct]
notation "⨁ " f:20 => biproduct f
/-- The projection onto a summand of a biproduct. -/
abbrev biproduct.π (f : J → C) [HasBiproduct f] (b : J) : ⨁ f ⟶ f b :=
(biproduct.bicone f).π b
@[simp]
theorem biproduct.bicone_π (f : J → C) [HasBiproduct f] (b : J) :
(biproduct.bicone f).π b = biproduct.π f b := rfl
/-- The inclusion into a summand of a biproduct. -/
abbrev biproduct.ι (f : J → C) [HasBiproduct f] (b : J) : f b ⟶ ⨁ f :=
(biproduct.bicone f).ι b
@[simp]
theorem biproduct.bicone_ι (f : J → C) [HasBiproduct f] (b : J) :
(biproduct.bicone f).ι b = biproduct.ι f b := rfl
/-- Note that as this lemma has an `if` in the statement, we include a `DecidableEq` argument.
This means you may not be able to `simp` using this lemma unless you `open scoped Classical`. -/
@[reassoc]
theorem biproduct.ι_π [DecidableEq J] (f : J → C) [HasBiproduct f] (j j' : J) :
biproduct.ι f j ≫ biproduct.π f j' = if h : j = j' then eqToHom (congr_arg f h) else 0 := by
convert (biproduct.bicone f).ι_π j j'
@[reassoc] -- Porting note: both versions proven by simp
theorem biproduct.ι_π_self (f : J → C) [HasBiproduct f] (j : J) :
biproduct.ι f j ≫ biproduct.π f j = 𝟙 _ := by simp [biproduct.ι_π]
@[reassoc (attr := simp)]
theorem biproduct.ι_π_ne (f : J → C) [HasBiproduct f] {j j' : J} (h : j ≠ j') :
biproduct.ι f j ≫ biproduct.π f j' = 0 := by simp [biproduct.ι_π, h]
-- The `simpNF` linter incorrectly identifies these as simp lemmas that could never apply.
-- It seems the side condition `w` is not applied by `simpNF`.
-- https://github.com/leanprover-community/mathlib4/issues/5049
-- They are used by `simp` in `biproduct.whiskerEquiv` below.
@[reassoc (attr := simp, nolint simpNF)]
theorem biproduct.eqToHom_comp_ι (f : J → C) [HasBiproduct f] {j j' : J} (w : j = j') :
eqToHom (by simp [w]) ≫ biproduct.ι f j' = biproduct.ι f j := by
cases w
simp
-- The `simpNF` linter incorrectly identifies these as simp lemmas that could never apply.
-- It seems the side condition `w` is not applied by `simpNF`.
-- https://github.com/leanprover-community/mathlib4/issues/5049
-- They are used by `simp` in `biproduct.whiskerEquiv` below.
@[reassoc (attr := simp, nolint simpNF)]
theorem biproduct.π_comp_eqToHom (f : J → C) [HasBiproduct f] {j j' : J} (w : j = j') :
biproduct.π f j ≫ eqToHom (by simp [w]) = biproduct.π f j' := by
cases w
simp
/-- Given a collection of maps into the summands, we obtain a map into the biproduct. -/
abbrev biproduct.lift {f : J → C} [HasBiproduct f] {P : C} (p : ∀ b, P ⟶ f b) : P ⟶ ⨁ f :=
(biproduct.isLimit f).lift (Fan.mk P p)
/-- Given a collection of maps out of the summands, we obtain a map out of the biproduct. -/
abbrev biproduct.desc {f : J → C} [HasBiproduct f] {P : C} (p : ∀ b, f b ⟶ P) : ⨁ f ⟶ P :=
(biproduct.isColimit f).desc (Cofan.mk P p)
@[reassoc (attr := simp)]
theorem biproduct.lift_π {f : J → C} [HasBiproduct f] {P : C} (p : ∀ b, P ⟶ f b) (j : J) :
biproduct.lift p ≫ biproduct.π f j = p j := (biproduct.isLimit f).fac _ ⟨j⟩
@[reassoc (attr := simp)]
theorem biproduct.ι_desc {f : J → C} [HasBiproduct f] {P : C} (p : ∀ b, f b ⟶ P) (j : J) :
biproduct.ι f j ≫ biproduct.desc p = p j := (biproduct.isColimit f).fac _ ⟨j⟩
/-- Given a collection of maps between corresponding summands of a pair of biproducts
indexed by the same type, we obtain a map between the biproducts. -/
abbrev biproduct.map {f g : J → C} [HasBiproduct f] [HasBiproduct g] (p : ∀ b, f b ⟶ g b) :
⨁ f ⟶ ⨁ g :=
IsLimit.map (biproduct.bicone f).toCone (biproduct.isLimit g)
(Discrete.natTrans (fun j => p j.as))
/-- An alternative to `biproduct.map` constructed via colimits.
This construction only exists in order to show it is equal to `biproduct.map`. -/
abbrev biproduct.map' {f g : J → C} [HasBiproduct f] [HasBiproduct g] (p : ∀ b, f b ⟶ g b) :
⨁ f ⟶ ⨁ g :=
IsColimit.map (biproduct.isColimit f) (biproduct.bicone g).toCocone
(Discrete.natTrans fun j => p j.as)
-- We put this at slightly higher priority than `biproduct.hom_ext'`,
-- to get the matrix indices in the "right" order.
@[ext 1001]
theorem biproduct.hom_ext {f : J → C} [HasBiproduct f] {Z : C} (g h : Z ⟶ ⨁ f)
(w : ∀ j, g ≫ biproduct.π f j = h ≫ biproduct.π f j) : g = h :=
(biproduct.isLimit f).hom_ext fun j => w j.as
@[ext]
theorem biproduct.hom_ext' {f : J → C} [HasBiproduct f] {Z : C} (g h : ⨁ f ⟶ Z)
(w : ∀ j, biproduct.ι f j ≫ g = biproduct.ι f j ≫ h) : g = h :=
(biproduct.isColimit f).hom_ext fun j => w j.as
/-- The canonical isomorphism between the chosen biproduct and the chosen product. -/
def biproduct.isoProduct (f : J → C) [HasBiproduct f] : ⨁ f ≅ ∏ᶜ f :=
IsLimit.conePointUniqueUpToIso (biproduct.isLimit f) (limit.isLimit _)
@[simp]
theorem biproduct.isoProduct_hom {f : J → C} [HasBiproduct f] :
(biproduct.isoProduct f).hom = Pi.lift (biproduct.π f) :=
limit.hom_ext fun j => by simp [biproduct.isoProduct]
@[simp]
theorem biproduct.isoProduct_inv {f : J → C} [HasBiproduct f] :
(biproduct.isoProduct f).inv = biproduct.lift (Pi.π f) :=
biproduct.hom_ext _ _ fun j => by simp [Iso.inv_comp_eq]
/-- The canonical isomorphism between the chosen biproduct and the chosen coproduct. -/
def biproduct.isoCoproduct (f : J → C) [HasBiproduct f] : ⨁ f ≅ ∐ f :=
IsColimit.coconePointUniqueUpToIso (biproduct.isColimit f) (colimit.isColimit _)
@[simp]
theorem biproduct.isoCoproduct_inv {f : J → C} [HasBiproduct f] :
(biproduct.isoCoproduct f).inv = Sigma.desc (biproduct.ι f) :=
colimit.hom_ext fun j => by simp [biproduct.isoCoproduct]
@[simp]
theorem biproduct.isoCoproduct_hom {f : J → C} [HasBiproduct f] :
(biproduct.isoCoproduct f).hom = biproduct.desc (Sigma.ι f) :=
| biproduct.hom_ext' _ _ fun j => by simp [← Iso.eq_comp_inv]
/-- If a category has biproducts of a shape `J`, its `colim` and `lim` functor on diagrams over `J`
are isomorphic. -/
| Mathlib/CategoryTheory/Limits/Shapes/Biproducts.lean | 530 | 533 |
/-
Copyright (c) 2022 George Peter Banyard, Yaël Dillies, Kyle Miller. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: George Peter Banyard, Yaël Dillies, Kyle Miller
-/
import Mathlib.Combinatorics.SimpleGraph.Path
import Mathlib.Combinatorics.SimpleGraph.Metric
/-!
# Graph products
This file defines the box product of graphs and other product constructions. The box product of `G`
and `H` is the graph on the product of the vertices such that `x` and `y` are related iff they agree
on one component and the other one is related via either `G` or `H`. For example, the box product of
two edges is a square.
## Main declarations
* `SimpleGraph.boxProd`: The box product.
## Notation
* `G □ H`: The box product of `G` and `H`.
## TODO
Define all other graph products!
-/
variable {α β γ : Type*}
namespace SimpleGraph
variable {G : SimpleGraph α} {H : SimpleGraph β}
/-- Box product of simple graphs. It relates `(a₁, b)` and `(a₂, b)` if `G` relates `a₁` and `a₂`,
and `(a, b₁)` and `(a, b₂)` if `H` relates `b₁` and `b₂`. -/
def boxProd (G : SimpleGraph α) (H : SimpleGraph β) : SimpleGraph (α × β) where
Adj x y := G.Adj x.1 y.1 ∧ x.2 = y.2 ∨ H.Adj x.2 y.2 ∧ x.1 = y.1
symm x y := by simp [and_comm, or_comm, eq_comm, adj_comm]
loopless x := by simp
/-- Box product of simple graphs. It relates `(a₁, b)` and `(a₂, b)` if `G` relates `a₁` and `a₂`,
and `(a, b₁)` and `(a, b₂)` if `H` relates `b₁` and `b₂`. -/
infixl:70 " □ " => boxProd
@[simp]
theorem boxProd_adj {x y : α × β} :
(G □ H).Adj x y ↔ G.Adj x.1 y.1 ∧ x.2 = y.2 ∨ H.Adj x.2 y.2 ∧ x.1 = y.1 :=
Iff.rfl
theorem boxProd_adj_left {a₁ : α} {b : β} {a₂ : α} :
(G □ H).Adj (a₁, b) (a₂, b) ↔ G.Adj a₁ a₂ := by
simp only [boxProd_adj, and_true, SimpleGraph.irrefl, false_and, or_false]
theorem boxProd_adj_right {a : α} {b₁ b₂ : β} : (G □ H).Adj (a, b₁) (a, b₂) ↔ H.Adj b₁ b₂ := by
simp only [boxProd_adj, SimpleGraph.irrefl, false_and, and_true, false_or]
theorem boxProd_neighborSet (x : α × β) :
(G □ H).neighborSet x = G.neighborSet x.1 ×ˢ {x.2} ∪ {x.1} ×ˢ H.neighborSet x.2 := by
ext ⟨a', b'⟩
simp only [mem_neighborSet, Set.mem_union, boxProd_adj, Set.mem_prod, Set.mem_singleton_iff]
simp only [eq_comm, and_comm]
variable (G H)
/-- The box product is commutative up to isomorphism. `Equiv.prodComm` as a graph isomorphism. -/
@[simps!]
def boxProdComm : G □ H ≃g H □ G := ⟨Equiv.prodComm _ _, or_comm⟩
/-- The box product is associative up to isomorphism. `Equiv.prodAssoc` as a graph isomorphism. -/
@[simps!]
def boxProdAssoc (I : SimpleGraph γ) : G □ H □ I ≃g G □ (H □ I) :=
⟨Equiv.prodAssoc _ _ _, fun {x y} => by
simp only [boxProd_adj, Equiv.prodAssoc_apply, or_and_right, or_assoc, Prod.ext_iff,
and_assoc, @and_comm (x.fst.fst = _)]⟩
/-- The embedding of `G` into `G □ H` given by `b`. -/
@[simps]
def boxProdLeft (b : β) : G ↪g G □ H where
toFun a := (a, b)
inj' _ _ := congr_arg Prod.fst
map_rel_iff' {_ _} := boxProd_adj_left
/-- The embedding of `H` into `G □ H` given by `a`. -/
@[simps]
def boxProdRight (a : α) : H ↪g G □ H where
toFun := Prod.mk a
inj' _ _ := congr_arg Prod.snd
map_rel_iff' {_ _} := boxProd_adj_right
namespace Walk
variable {G}
/-- Turn a walk on `G` into a walk on `G □ H`. -/
protected def boxProdLeft {a₁ a₂ : α} (b : β) : G.Walk a₁ a₂ → (G □ H).Walk (a₁, b) (a₂, b) :=
Walk.map (G.boxProdLeft H b).toHom
variable (G) {H}
/-- Turn a walk on `H` into a walk on `G □ H`. -/
protected def boxProdRight {b₁ b₂ : β} (a : α) : H.Walk b₁ b₂ → (G □ H).Walk (a, b₁) (a, b₂) :=
Walk.map (G.boxProdRight H a).toHom
variable {G}
/-- Project a walk on `G □ H` to a walk on `G` by discarding the moves in the direction of `H`. -/
def ofBoxProdLeft [DecidableEq β] [DecidableRel G.Adj] {x y : α × β} :
(G □ H).Walk x y → G.Walk x.1 y.1
| nil => nil
| cons h w =>
Or.by_cases h
(fun hG => w.ofBoxProdLeft.cons hG.1)
(fun hH => hH.2 ▸ w.ofBoxProdLeft)
/-- Project a walk on `G □ H` to a walk on `H` by discarding the moves in the direction of `G`. -/
def ofBoxProdRight [DecidableEq α] [DecidableRel H.Adj] {x y : α × β} :
(G □ H).Walk x y → H.Walk x.2 y.2
| nil => nil
| cons h w =>
(Or.symm h).by_cases
(fun hH => w.ofBoxProdRight.cons hH.1)
(fun hG => hG.2 ▸ w.ofBoxProdRight)
@[simp]
theorem ofBoxProdLeft_boxProdLeft [DecidableEq β] [DecidableRel G.Adj] {a₁ a₂ : α} {b : β} :
∀ (w : G.Walk a₁ a₂), (w.boxProdLeft H b).ofBoxProdLeft = w
| nil => rfl
| cons' x y z h w => by
rw [Walk.boxProdLeft, map_cons, ofBoxProdLeft, Or.by_cases, dif_pos, ← Walk.boxProdLeft]
· simp [ofBoxProdLeft_boxProdLeft]
· exact ⟨h, rfl⟩
@[simp]
theorem ofBoxProdLeft_boxProdRight [DecidableEq α] [DecidableRel G.Adj] {a b₁ b₂ : α} :
∀ (w : G.Walk b₁ b₂), (w.boxProdRight G a).ofBoxProdRight = w
| nil => rfl
| cons' x y z h w => by
rw [Walk.boxProdRight, map_cons, ofBoxProdRight, Or.by_cases, dif_pos, ←
Walk.boxProdRight]
· simp [ofBoxProdLeft_boxProdRight]
· exact ⟨h, rfl⟩
lemma length_boxProd {a₁ a₂ : α} {b₁ b₂ : β} [DecidableEq α] [DecidableEq β]
[DecidableRel G.Adj] [DecidableRel H.Adj] (w : (G □ H).Walk (a₁, b₁) (a₂, b₂)) :
w.length = w.ofBoxProdLeft.length + w.ofBoxProdRight.length := by
match w with
| .nil => simp [ofBoxProdLeft, ofBoxProdRight]
| .cons x w' => next c =>
unfold ofBoxProdLeft ofBoxProdRight
rw [length_cons, length_boxProd w']
have disj : (G.Adj a₁ c.1 ∧ b₁ = c.2) ∨ (H.Adj b₁ c.2 ∧ a₁ = c.1) := by aesop
rcases disj with h₁ | h₂
· simp only [h₁, irrefl, false_and, and_self, ↓reduceDIte, length_cons, Or.by_cases]
rw [add_comm, add_comm w'.ofBoxProdLeft.length 1, add_assoc]
congr <;> simp [h₁.2.symm]
· simp only [h₂, irrefl, false_and, ↓reduceDIte, length_cons, add_assoc, Or.by_cases]
congr <;> simp [h₂.2.symm]
end Walk
variable {G H}
protected theorem Preconnected.boxProd (hG : G.Preconnected) (hH : H.Preconnected) :
(G □ H).Preconnected := by
rintro x y
obtain ⟨w₁⟩ := hG x.1 y.1
obtain ⟨w₂⟩ := hH x.2 y.2
exact ⟨(w₁.boxProdLeft _ _).append (w₂.boxProdRight _ _)⟩
protected theorem Preconnected.ofBoxProdLeft [Nonempty β] (h : (G □ H).Preconnected) :
G.Preconnected := by
classical
rintro a₁ a₂
obtain ⟨w⟩ := h (a₁, Classical.arbitrary _) (a₂, Classical.arbitrary _)
exact ⟨w.ofBoxProdLeft⟩
protected theorem Preconnected.ofBoxProdRight [Nonempty α] (h : (G □ H).Preconnected) :
H.Preconnected := by
classical
rintro b₁ b₂
obtain ⟨w⟩ := h (Classical.arbitrary _, b₁) (Classical.arbitrary _, b₂)
exact ⟨w.ofBoxProdRight⟩
protected theorem Connected.boxProd (hG : G.Connected) (hH : H.Connected) : (G □ H).Connected := by
haveI := hG.nonempty
haveI := hH.nonempty
exact ⟨hG.preconnected.boxProd hH.preconnected⟩
protected theorem Connected.ofBoxProdLeft (h : (G □ H).Connected) : G.Connected := by
haveI := (nonempty_prod.1 h.nonempty).1
haveI := (nonempty_prod.1 h.nonempty).2
exact ⟨h.preconnected.ofBoxProdLeft⟩
protected theorem Connected.ofBoxProdRight (h : (G □ H).Connected) : H.Connected := by
haveI := (nonempty_prod.1 h.nonempty).1
| haveI := (nonempty_prod.1 h.nonempty).2
exact ⟨h.preconnected.ofBoxProdRight⟩
@[simp]
| Mathlib/Combinatorics/SimpleGraph/Prod.lean | 198 | 201 |
/-
Copyright (c) 2021 Patrick Massot. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Massot, Riccardo Brasca
-/
import Mathlib.Analysis.Normed.Module.Basic
import Mathlib.Analysis.Normed.Group.Hom
import Mathlib.RingTheory.Ideal.Quotient.Operations
import Mathlib.Topology.MetricSpace.HausdorffDistance
/-!
# Quotients of seminormed groups
For any `SeminormedAddCommGroup M` and any `S : AddSubgroup M`, we provide a
`SeminormedAddCommGroup`, the group quotient `M ⧸ S`.
If `S` is closed, we provide `NormedAddCommGroup (M ⧸ S)` (regardless of whether `M` itself is
separated). The two main properties of these structures are the underlying topology is the quotient
topology and the projection is a normed group homomorphism which is norm non-increasing
(better, it has operator norm exactly one unless `S` is dense in `M`). The corresponding
universal property is that every normed group hom defined on `M` which vanishes on `S` descends
to a normed group hom defined on `M ⧸ S`.
This file also introduces a predicate `IsQuotient` characterizing normed group homs that
are isomorphic to the canonical projection onto a normed group quotient.
In addition, this file also provides normed structures for quotients of modules by submodules, and
of (commutative) rings by ideals. The `SeminormedAddCommGroup` and `NormedAddCommGroup`
instances described above are transferred directly, but we also define instances of `NormedSpace`,
`SeminormedCommRing`, `NormedCommRing` and `NormedAlgebra` under appropriate type class
assumptions on the original space. Moreover, while `QuotientAddGroup.completeSpace` works
out-of-the-box for quotients of `NormedAddCommGroup`s by `AddSubgroup`s, we need to transfer
this instance in `Submodule.Quotient.completeSpace` so that it applies to these other quotients.
## Main definitions
We use `M` and `N` to denote seminormed groups and `S : AddSubgroup M`.
All the following definitions are in the `AddSubgroup` namespace. Hence we can access
`AddSubgroup.normedMk S` as `S.normedMk`.
* `seminormedAddCommGroupQuotient` : The seminormed group structure on the quotient by
an additive subgroup. This is an instance so there is no need to explicitly use it.
* `normedAddCommGroupQuotient` : The normed group structure on the quotient by
a closed additive subgroup. This is an instance so there is no need to explicitly use it.
* `normedMk S` : the normed group hom from `M` to `M ⧸ S`.
* `lift S f hf`: implements the universal property of `M ⧸ S`. Here
`(f : NormedAddGroupHom M N)`, `(hf : ∀ s ∈ S, f s = 0)` and
`lift S f hf : NormedAddGroupHom (M ⧸ S) N`.
* `IsQuotient`: given `f : NormedAddGroupHom M N`, `IsQuotient f` means `N` is isomorphic
to a quotient of `M` by a subgroup, with projection `f`. Technically it asserts `f` is
surjective and the norm of `f x` is the infimum of the norms of `x + m` for `m` in `f.ker`.
## Main results
* `norm_normedMk` : the operator norm of the projection is `1` if the subspace is not dense.
* `IsQuotient.norm_lift`: Provided `f : normed_hom M N` satisfies `IsQuotient f`, for every
`n : N` and positive `ε`, there exists `m` such that `f m = n ∧ ‖m‖ < ‖n‖ + ε`.
## Implementation details
For any `SeminormedAddCommGroup M` and any `S : AddSubgroup M` we define a norm on `M ⧸ S` by
`‖x‖ = sInf (norm '' {m | mk' S m = x})`. This formula is really an implementation detail, it
shouldn't be needed outside of this file setting up the theory.
Since `M ⧸ S` is automatically a topological space (as any quotient of a topological space),
one needs to be careful while defining the `SeminormedAddCommGroup` instance to avoid having two
different topologies on this quotient. This is not purely a technological issue.
Mathematically there is something to prove. The main point is proved in the auxiliary lemma
`quotient_nhd_basis` that has no use beyond this verification and states that zero in the quotient
admits as basis of neighborhoods in the quotient topology the sets `{x | ‖x‖ < ε}` for positive `ε`.
Once this mathematical point is settled, we have two topologies that are propositionally equal. This
is not good enough for the type class system. As usual we ensure *definitional* equality
using forgetful inheritance, see Note [forgetful inheritance]. A (semi)-normed group structure
includes a uniform space structure which includes a topological space structure, together
with propositional fields asserting compatibility conditions.
The usual way to define a `SeminormedAddCommGroup` is to let Lean build a uniform space structure
using the provided norm, and then trivially build a proof that the norm and uniform structure are
compatible. Here the uniform structure is provided using `IsTopologicalAddGroup.toUniformSpace`
which uses the topological structure and the group structure to build the uniform structure. This
uniform structure induces the correct topological structure by construction, but the fact that it
is compatible with the norm is not obvious; this is where the mathematical content explained in
the previous paragraph kicks in.
-/
noncomputable section
open Metric Set Topology NNReal
namespace QuotientGroup
variable {M : Type*} [SeminormedCommGroup M] {S : Subgroup M} {x : M ⧸ S} {m : M} {r ε : ℝ}
@[to_additive add_norm_aux]
private lemma norm_aux (x : M ⧸ S) : {m : M | (m : M ⧸ S) = x}.Nonempty := Quot.exists_rep x
/-- The norm of `x` on the quotient by a subgroup `S` is defined as the infimum of the norm on
`x * M`. -/
@[to_additive
"The norm of `x` on the quotient by a subgroup `S` is defined as the infimum of the norm on
`x + S`."]
noncomputable def groupSeminorm : GroupSeminorm (M ⧸ S) where
toFun x := infDist 1 {m : M | (m : M ⧸ S) = x}
map_one' := infDist_zero_of_mem (by simpa using S.one_mem)
mul_le' x y := by
simp only [infDist_eq_iInf]
have := (norm_aux x).to_subtype
have := (norm_aux y).to_subtype
refine le_ciInf_add_ciInf ?_
rintro ⟨a, rfl⟩ ⟨b, rfl⟩
refine ciInf_le_of_le ⟨0, forall_mem_range.2 fun _ ↦ dist_nonneg⟩ ⟨a * b, rfl⟩ ?_
simpa using norm_mul_le' _ _
inv' x := eq_of_forall_le_iff fun r ↦ by
simp only [le_infDist (norm_aux _)]
exact (Equiv.inv _).forall_congr (by simp [← inv_eq_iff_eq_inv])
/-- The norm of `x` on the quotient by a subgroup `S` is defined as the infimum of the norm on
`x * S`. -/
@[to_additive
"The norm of `x` on the quotient by a subgroup `S` is defined as the infimum of the norm on
`x + S`."]
noncomputable instance instNorm : Norm (M ⧸ S) where norm := groupSeminorm
@[to_additive]
lemma norm_eq_groupSeminorm (x : M ⧸ S) : ‖x‖ = groupSeminorm x := rfl
@[to_additive]
lemma norm_eq_infDist (x : M ⧸ S) : ‖x‖ = infDist 1 {m : M | (m : M ⧸ S) = x} := rfl
@[to_additive]
lemma le_norm_iff : r ≤ ‖x‖ ↔ ∀ m : M, ↑m = x → r ≤ ‖m‖ := by
simp [norm_eq_infDist, le_infDist (norm_aux _)]
@[to_additive]
lemma norm_lt_iff : ‖x‖ < r ↔ ∃ m : M, ↑m = x ∧ ‖m‖ < r := by
simp [norm_eq_infDist, infDist_lt_iff (norm_aux _)]
@[to_additive]
lemma nhds_one_hasBasis : (𝓝 (1 : M ⧸ S)).HasBasis (fun ε ↦ 0 < ε) fun ε ↦ {x | ‖x‖ < ε} := by
have : ∀ ε : ℝ, mk '' ball (1 : M) ε = {x : M ⧸ S | ‖x‖ < ε} := by
refine fun ε ↦ Set.ext <| forall_mk.2 fun x ↦ ?_
rw [ball_one_eq, mem_setOf_eq, norm_lt_iff, mem_image]
exact exists_congr fun _ ↦ and_comm
rw [← mk_one, nhds_eq, ← funext this]
exact .map _ Metric.nhds_basis_ball
/-- An alternative definition of the norm on the quotient group: the norm of `((x : M) : M ⧸ S)` is
equal to the distance from `x` to `S`. -/
@[to_additive
"An alternative definition of the norm on the quotient group: the norm of `((x : M) : M ⧸ S)` is
equal to the distance from `x` to `S`."]
lemma norm_mk (x : M) : ‖(x : M ⧸ S)‖ = infDist x S := by
rw [norm_eq_infDist, ← infDist_image (IsometryEquiv.divLeft x).isometry,
← IsometryEquiv.preimage_symm]
simp
/-- The norm of the projection is smaller or equal to the norm of the original element. -/
@[to_additive "The norm of the projection is smaller or equal to the norm of the original element."]
lemma norm_mk_le_norm : ‖(m : M ⧸ S)‖ ≤ ‖m‖ :=
(infDist_le_dist_of_mem (by simp)).trans_eq (dist_one_left _)
/-- The norm of the image of `m : M` in the quotient by `S` is zero if and only if `m` belongs
to the closure of `S`. -/
@[to_additive "The norm of the image of `m : M` in the quotient by `S` is zero if and only if `m`
belongs to the closure of `S`."]
lemma norm_mk_eq_zero_iff_mem_closure : ‖(m : M ⧸ S)‖ = 0 ↔ m ∈ closure (S : Set M) := by
rw [norm_mk, ← mem_closure_iff_infDist_zero]
exact ⟨1, S.one_mem⟩
/-- The norm of the image of `m : M` in the quotient by a closed subgroup `S` is zero if and only if
`m ∈ S`. -/
@[to_additive "The norm of the image of `m : M` in the quotient by a closed subgroup `S` is zero if
| and only if `m ∈ S`."]
lemma norm_mk_eq_zero [hS : IsClosed (S : Set M)] : ‖(m : M ⧸ S)‖ = 0 ↔ m ∈ S := by
rw [norm_mk_eq_zero_iff_mem_closure, hS.closure_eq, SetLike.mem_coe]
| Mathlib/Analysis/Normed/Group/Quotient.lean | 180 | 183 |
/-
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, Chris Hughes, Anne Baanen
-/
import Mathlib.Algebra.Algebra.Subalgebra.Lattice
import Mathlib.LinearAlgebra.Basis.Prod
import Mathlib.LinearAlgebra.Dimension.Free
import Mathlib.LinearAlgebra.TensorProduct.Basis
/-!
# Rank of various constructions
## Main statements
- `rank_quotient_add_rank_le` : `rank M/N + rank N ≤ rank M`.
- `lift_rank_add_lift_rank_le_rank_prod`: `rank M × N ≤ rank M + rank N`.
- `rank_span_le_of_finite`: `rank (span s) ≤ #s` for finite `s`.
For free modules, we have
- `rank_prod` : `rank M × N = rank M + rank N`.
- `rank_finsupp` : `rank (ι →₀ M) = #ι * rank M`
- `rank_directSum`: `rank (⨁ Mᵢ) = ∑ rank Mᵢ`
- `rank_tensorProduct`: `rank (M ⊗ N) = rank M * rank N`.
Lemmas for ranks of submodules and subalgebras are also provided.
We have finrank variants for most lemmas as well.
-/
noncomputable section
universe u u' v v' u₁' w w'
variable {R : Type u} {S : Type u'} {M : Type v} {M' : Type v'} {M₁ : Type v}
variable {ι : Type w} {ι' : Type w'} {η : Type u₁'} {φ : η → Type*}
open Basis Cardinal DirectSum Function Module Set Submodule
section Quotient
variable [Ring R] [CommRing S] [AddCommGroup M] [AddCommGroup M'] [AddCommGroup M₁]
variable [Module R M]
theorem LinearIndependent.sumElim_of_quotient
{M' : Submodule R M} {ι₁ ι₂} {f : ι₁ → M'} (hf : LinearIndependent R f) (g : ι₂ → M)
(hg : LinearIndependent R (Submodule.Quotient.mk (p := M') ∘ g)) :
LinearIndependent R (Sum.elim (f · : ι₁ → M) g) := by
refine .sum_type (hf.map' M'.subtype M'.ker_subtype) (.of_comp M'.mkQ hg) ?_
refine disjoint_def.mpr fun x h₁ h₂ ↦ ?_
have : x ∈ M' := span_le.mpr (Set.range_subset_iff.mpr fun i ↦ (f i).prop) h₁
obtain ⟨c, rfl⟩ := Finsupp.mem_span_range_iff_exists_finsupp.mp h₂
simp_rw [← Quotient.mk_eq_zero, ← mkQ_apply, map_finsuppSum, map_smul, mkQ_apply] at this
rw [linearIndependent_iff.mp hg _ this, Finsupp.sum_zero_index]
@[deprecated (since := "2025-02-21")]
alias LinearIndependent.sum_elim_of_quotient := LinearIndependent.sumElim_of_quotient
theorem LinearIndepOn.union_of_quotient {s t : Set ι} {f : ι → M} (hs : LinearIndepOn R f s)
(ht : LinearIndepOn R (mkQ (span R (f '' s)) ∘ f) t) : LinearIndepOn R f (s ∪ t) := by
apply hs.union ht.of_comp
convert (Submodule.range_ker_disjoint ht).symm
· simp
aesop
theorem LinearIndepOn.union_id_of_quotient {M' : Submodule R M}
{s : Set M} (hs : s ⊆ M') (hs' : LinearIndepOn R id s) {t : Set M}
(ht : LinearIndepOn R (mkQ M') t) : LinearIndepOn R id (s ∪ t) :=
hs'.union_of_quotient <| by
rw [image_id]
exact ht.of_comp ((span R s).mapQ M' (LinearMap.id) (span_le.2 hs))
@[deprecated (since := "2025-02-16")] alias LinearIndependent.union_of_quotient :=
LinearIndepOn.union_id_of_quotient
theorem linearIndepOn_union_iff_quotient {s t : Set ι} {f : ι → M} (hst : Disjoint s t) :
LinearIndepOn R f (s ∪ t) ↔
LinearIndepOn R f s ∧ LinearIndepOn R (mkQ (span R (f '' s)) ∘ f) t := by
refine ⟨fun h ↦ ⟨?_, ?_⟩, fun h ↦ h.1.union_of_quotient h.2⟩
· exact h.mono subset_union_left
apply (h.mono subset_union_right).map
simpa [← image_eq_range] using ((linearIndepOn_union_iff hst).1 h).2.2.symm
theorem LinearIndepOn.quotient_iff_union {s t : Set ι} {f : ι → M} (hs : LinearIndepOn R f s)
(hst : Disjoint s t) :
LinearIndepOn R (mkQ (span R (f '' s)) ∘ f) t ↔ LinearIndepOn R f (s ∪ t) := by
rw [linearIndepOn_union_iff_quotient hst, and_iff_right hs]
theorem rank_quotient_add_rank_le [Nontrivial R] (M' : Submodule R M) :
Module.rank R (M ⧸ M') + Module.rank R M' ≤ Module.rank R M := by
conv_lhs => simp only [Module.rank_def]
have := nonempty_linearIndependent_set R (M ⧸ M')
have := nonempty_linearIndependent_set R M'
rw [Cardinal.ciSup_add_ciSup _ (bddAbove_range _) _ (bddAbove_range _)]
refine ciSup_le fun ⟨s, hs⟩ ↦ ciSup_le fun ⟨t, ht⟩ ↦ ?_
choose f hf using Submodule.Quotient.mk_surjective M'
simpa [add_comm] using (LinearIndependent.sumElim_of_quotient ht (fun (i : s) ↦ f i)
(by simpa [Function.comp_def, hf] using hs)).cardinal_le_rank
theorem rank_quotient_le (p : Submodule R M) : Module.rank R (M ⧸ p) ≤ Module.rank R M :=
(mkQ p).rank_le_of_surjective Quot.mk_surjective
/-- The dimension of a quotient is bounded by the dimension of the ambient space. -/
theorem Submodule.finrank_quotient_le [StrongRankCondition R] [Module.Finite R M]
(s : Submodule R M) : finrank R (M ⧸ s) ≤ finrank R M :=
toNat_le_toNat ((Submodule.mkQ s).rank_le_of_surjective Quot.mk_surjective)
(rank_lt_aleph0 _ _)
end Quotient
variable [Semiring R] [CommSemiring S] [AddCommMonoid M] [AddCommMonoid M'] [AddCommMonoid M₁]
variable [Module R M]
section ULift
@[simp]
theorem rank_ulift : Module.rank R (ULift.{w} M) = Cardinal.lift.{w} (Module.rank R M) :=
Cardinal.lift_injective.{v} <| Eq.symm <| (lift_lift _).trans ULift.moduleEquiv.symm.lift_rank_eq
@[simp]
theorem finrank_ulift : finrank R (ULift M) = finrank R M := by
simp_rw [finrank, rank_ulift, toNat_lift]
end ULift
section Prod
variable (R M M')
variable [Module R M₁] [Module R M']
theorem rank_add_rank_le_rank_prod [Nontrivial R] :
Module.rank R M + Module.rank R M₁ ≤ Module.rank R (M × M₁) := by
conv_lhs => simp only [Module.rank_def]
have := nonempty_linearIndependent_set R M
have := nonempty_linearIndependent_set R M₁
rw [Cardinal.ciSup_add_ciSup _ (bddAbove_range _) _ (bddAbove_range _)]
exact ciSup_le fun ⟨s, hs⟩ ↦ ciSup_le fun ⟨t, ht⟩ ↦
(linearIndependent_inl_union_inr' hs ht).cardinal_le_rank
theorem lift_rank_add_lift_rank_le_rank_prod [Nontrivial R] :
lift.{v'} (Module.rank R M) + lift.{v} (Module.rank R M') ≤ Module.rank R (M × M') := by
rw [← rank_ulift, ← rank_ulift]
exact (rank_add_rank_le_rank_prod R _).trans_eq
(ULift.moduleEquiv.prodCongr ULift.moduleEquiv).rank_eq
variable {R M M'}
variable [StrongRankCondition R] [Module.Free R M] [Module.Free R M'] [Module.Free R M₁]
open Module.Free
/-- If `M` and `M'` are free, then the rank of `M × M'` is
`(Module.rank R M).lift + (Module.rank R M').lift`. -/
@[simp]
theorem rank_prod : Module.rank R (M × M') =
Cardinal.lift.{v'} (Module.rank R M) + Cardinal.lift.{v, v'} (Module.rank R M') := by
simpa [rank_eq_card_chooseBasisIndex R M, rank_eq_card_chooseBasisIndex R M', lift_umax]
using ((chooseBasis R M).prod (chooseBasis R M')).mk_eq_rank.symm
/-- If `M` and `M'` are free (and lie in the same universe), the rank of `M × M'` is
`(Module.rank R M) + (Module.rank R M')`. -/
theorem rank_prod' : Module.rank R (M × M₁) = Module.rank R M + Module.rank R M₁ := by simp
/-- The finrank of `M × M'` is `(finrank R M) + (finrank R M')`. -/
@[simp]
theorem Module.finrank_prod [Module.Finite R M] [Module.Finite R M'] :
finrank R (M × M') = finrank R M + finrank R M' := by
simp [finrank, rank_lt_aleph0 R M, rank_lt_aleph0 R M']
end Prod
section Finsupp
variable (R M M')
variable [StrongRankCondition R] [Module.Free R M] [Module R M'] [Module.Free R M']
open Module.Free
@[simp]
theorem rank_finsupp (ι : Type w) :
Module.rank R (ι →₀ M) = Cardinal.lift.{v} #ι * Cardinal.lift.{w} (Module.rank R M) := by
obtain ⟨⟨_, bs⟩⟩ := Module.Free.exists_basis (R := R) (M := M)
rw [← bs.mk_eq_rank'', ← (Finsupp.basis fun _ : ι => bs).mk_eq_rank'', Cardinal.mk_sigma,
Cardinal.sum_const]
theorem rank_finsupp' (ι : Type v) : Module.rank R (ι →₀ M) = #ι * Module.rank R M := by
simp [rank_finsupp]
/-- The rank of `(ι →₀ R)` is `(#ι).lift`. -/
theorem rank_finsupp_self (ι : Type w) : Module.rank R (ι →₀ R) = Cardinal.lift.{u} #ι := by
simp
/-- If `R` and `ι` lie in the same universe, the rank of `(ι →₀ R)` is `# ι`. -/
theorem rank_finsupp_self' {ι : Type u} : Module.rank R (ι →₀ R) = #ι := by simp
/-- The rank of the direct sum is the sum of the ranks. -/
@[simp]
theorem rank_directSum {ι : Type v} (M : ι → Type w) [∀ i : ι, AddCommMonoid (M i)]
[∀ i : ι, Module R (M i)] [∀ i : ι, Module.Free R (M i)] :
Module.rank R (⨁ i, M i) = Cardinal.sum fun i => Module.rank R (M i) := by
let B i := chooseBasis R (M i)
let b : Basis _ R (⨁ i, M i) := DFinsupp.basis fun i => B i
simp [← b.mk_eq_rank'', fun i => (B i).mk_eq_rank'']
/-- If `m` and `n` are finite, the rank of `m × n` matrices over a module `M` is
`(#m).lift * (#n).lift * rank R M`. -/
@[simp]
theorem rank_matrix_module (m : Type w) (n : Type w') [Finite m] [Finite n] :
Module.rank R (Matrix m n M) =
lift.{max v w'} #m * lift.{max v w} #n * lift.{max w w'} (Module.rank R M) := by
cases nonempty_fintype m
cases nonempty_fintype n
obtain ⟨I, b⟩ := Module.Free.exists_basis (R := R) (M := M)
rw [← (b.matrix m n).mk_eq_rank'']
simp only [mk_prod, lift_mul, lift_lift, ← mul_assoc, b.mk_eq_rank'']
/-- If `m` and `n` are finite and lie in the same universe, the rank of `m × n` matrices over a
module `M` is `(#m * #n).lift * rank R M`. -/
@[simp high]
theorem rank_matrix_module' (m n : Type w) [Finite m] [Finite n] :
Module.rank R (Matrix m n M) =
lift.{max v} (#m * #n) * lift.{w} (Module.rank R M) := by
rw [rank_matrix_module, lift_mul, lift_umax.{w, v}]
/-- If `m` and `n` are finite, the rank of `m × n` matrices is `(#m).lift * (#n).lift`. -/
theorem rank_matrix (m : Type v) (n : Type w) [Finite m] [Finite n] :
Module.rank R (Matrix m n R) =
Cardinal.lift.{max v w u, v} #m * Cardinal.lift.{max v w u, w} #n := by
rw [rank_matrix_module, rank_self, lift_one, mul_one, ← lift_lift.{v, max u w}, lift_id,
← lift_lift.{w, max u v}, lift_id]
/-- If `m` and `n` are finite and lie in the same universe, the rank of `m × n` matrices is
`(#n * #m).lift`. -/
theorem rank_matrix' (m n : Type v) [Finite m] [Finite n] :
Module.rank R (Matrix m n R) = Cardinal.lift.{u} (#m * #n) := by
rw [rank_matrix, lift_mul, lift_umax.{v, u}]
/-- If `m` and `n` are finite and lie in the same universe as `R`, the rank of `m × n` matrices
is `# m * # n`. -/
theorem rank_matrix'' (m n : Type u) [Finite m] [Finite n] :
Module.rank R (Matrix m n R) = #m * #n := by simp
open Fintype
namespace Module
@[simp]
theorem finrank_finsupp {ι : Type v} [Fintype ι] : finrank R (ι →₀ M) = card ι * finrank R M := by
rw [finrank, finrank, rank_finsupp, ← mk_toNat_eq_card, toNat_mul, toNat_lift, toNat_lift]
/-- The finrank of `(ι →₀ R)` is `Fintype.card ι`. -/
@[simp]
theorem finrank_finsupp_self {ι : Type v} [Fintype ι] : finrank R (ι →₀ R) = card ι := by
rw [finrank, rank_finsupp_self, ← mk_toNat_eq_card, toNat_lift]
/-- The finrank of the direct sum is the sum of the finranks. -/
@[simp]
theorem finrank_directSum {ι : Type v} [Fintype ι] (M : ι → Type w) [∀ i : ι, AddCommMonoid (M i)]
[∀ i : ι, Module R (M i)] [∀ i : ι, Module.Free R (M i)] [∀ i : ι, Module.Finite R (M i)] :
finrank R (⨁ i, M i) = ∑ i, finrank R (M i) := by
letI := nontrivial_of_invariantBasisNumber R
simp only [finrank, fun i => rank_eq_card_chooseBasisIndex R (M i), rank_directSum, ← mk_sigma,
mk_toNat_eq_card, card_sigma]
/-- If `m` and `n` are `Fintype`, the finrank of `m × n` matrices over a module `M` is
`(Fintype.card m) * (Fintype.card n) * finrank R M`. -/
theorem finrank_matrix (m n : Type*) [Fintype m] [Fintype n] :
finrank R (Matrix m n M) = card m * card n * finrank R M := by simp [finrank]
end Module
end Finsupp
section Pi
variable [StrongRankCondition R] [Module.Free R M]
variable [∀ i, AddCommMonoid (φ i)] [∀ i, Module R (φ i)] [∀ i, Module.Free R (φ i)]
open Module.Free
open LinearMap
/-- The rank of a finite product of free modules is the sum of the ranks. -/
-- this result is not true without the freeness assumption
@[simp]
theorem rank_pi [Finite η] : Module.rank R (∀ i, φ i) =
Cardinal.sum fun i => Module.rank R (φ i) := by
cases nonempty_fintype η
let B i := chooseBasis R (φ i)
let b : Basis _ R (∀ i, φ i) := Pi.basis fun i => B i
simp [← b.mk_eq_rank'', fun i => (B i).mk_eq_rank'']
variable (R)
/-- The finrank of `(ι → R)` is `Fintype.card ι`. -/
theorem Module.finrank_pi {ι : Type v} [Fintype ι] :
finrank R (ι → R) = Fintype.card ι := by
simp [finrank]
--TODO: this should follow from `LinearEquiv.finrank_eq`, that is over a field.
/-- The finrank of a finite product is the sum of the finranks. -/
theorem Module.finrank_pi_fintype
{ι : Type v} [Fintype ι] {M : ι → Type w} [∀ i : ι, AddCommMonoid (M i)]
| [∀ i : ι, Module R (M i)] [∀ i : ι, Module.Free R (M i)] [∀ i : ι, Module.Finite R (M i)] :
finrank R (∀ i, M i) = ∑ i, finrank R (M i) := by
letI := nontrivial_of_invariantBasisNumber R
| Mathlib/LinearAlgebra/Dimension/Constructions.lean | 306 | 308 |
/-
Copyright (c) 2024 David Loeffler. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Loeffler
-/
import Mathlib.NumberTheory.LSeries.AbstractFuncEq
import Mathlib.NumberTheory.ModularForms.JacobiTheta.Bounds
import Mathlib.Analysis.SpecialFunctions.Gamma.Deligne
import Mathlib.NumberTheory.LSeries.MellinEqDirichlet
import Mathlib.NumberTheory.LSeries.Basic
import Mathlib.Analysis.Complex.RemovableSingularity
/-!
# Even Hurwitz zeta functions
In this file we study the functions on `ℂ` which are the meromorphic continuation of the following
series (convergent for `1 < re s`), where `a ∈ ℝ` is a parameter:
`hurwitzZetaEven a s = 1 / 2 * ∑' n : ℤ, 1 / |n + a| ^ s`
and
`cosZeta a s = ∑' n : ℕ, cos (2 * π * a * n) / |n| ^ s`.
Note that the term for `n = -a` in the first sum is omitted if `a` is an integer, and the term for
`n = 0` is omitted in the second sum (always).
Of course, we cannot *define* these functions by the above formulae (since existence of the
meromorphic continuation is not at all obvious); we in fact construct them as Mellin transforms of
various versions of the Jacobi theta function.
We also define completed versions of these functions with nicer functional equations (satisfying
`completedHurwitzZetaEven a s = Gammaℝ s * hurwitzZetaEven a s`, and similarly for `cosZeta`); and
modified versions with a subscript `0`, which are entire functions differing from the above by
multiples of `1 / s` and `1 / (1 - s)`.
## Main definitions and theorems
* `hurwitzZetaEven` and `cosZeta`: the zeta functions
* `completedHurwitzZetaEven` and `completedCosZeta`: completed variants
* `differentiableAt_hurwitzZetaEven` and `differentiableAt_cosZeta`:
differentiability away from `s = 1`
* `completedHurwitzZetaEven_one_sub`: the functional equation
`completedHurwitzZetaEven a (1 - s) = completedCosZeta a s`
* `hasSum_int_hurwitzZetaEven` and `hasSum_nat_cosZeta`: relation between the zeta functions and
the corresponding Dirichlet series for `1 < re s`.
-/
noncomputable section
open Complex Filter Topology Asymptotics Real Set MeasureTheory
namespace HurwitzZeta
section kernel_defs
/-!
## Definitions and elementary properties of kernels
-/
/-- Even Hurwitz zeta kernel (function whose Mellin transform will be the even part of the
completed Hurwit zeta function). See `evenKernel_def` for the defining formula, and
`hasSum_int_evenKernel` for an expression as a sum over `ℤ`. -/
@[irreducible] def evenKernel (a : UnitAddCircle) (x : ℝ) : ℝ :=
(show Function.Periodic
(fun ξ : ℝ ↦ rexp (-π * ξ ^ 2 * x) * re (jacobiTheta₂ (ξ * I * x) (I * x))) 1 by
intro ξ
simp only [ofReal_add, ofReal_one, add_mul, one_mul, jacobiTheta₂_add_left']
have : cexp (-↑π * I * ((I * ↑x) + 2 * (↑ξ * I * ↑x))) = rexp (π * (x + 2 * ξ * x)) := by
ring_nf
simp [I_sq]
rw [this, re_ofReal_mul, ← mul_assoc, ← Real.exp_add]
congr
ring).lift a
lemma evenKernel_def (a x : ℝ) :
↑(evenKernel ↑a x) = cexp (-π * a ^ 2 * x) * jacobiTheta₂ (a * I * x) (I * x) := by
simp [evenKernel, re_eq_add_conj, jacobiTheta₂_conj, ← mul_two,
mul_div_cancel_right₀ _ (two_ne_zero' ℂ)]
/-- For `x ≤ 0` the defining sum diverges, so the kernel is 0. -/
lemma evenKernel_undef (a : UnitAddCircle) {x : ℝ} (hx : x ≤ 0) : evenKernel a x = 0 := by
induction a using QuotientAddGroup.induction_on with
| H a' => simp [← ofReal_inj, evenKernel_def, jacobiTheta₂_undef _ (by simpa : (I * ↑x).im ≤ 0)]
/-- Cosine Hurwitz zeta kernel. See `cosKernel_def` for the defining formula, and
`hasSum_int_cosKernel` for expression as a sum. -/
@[irreducible] def cosKernel (a : UnitAddCircle) (x : ℝ) : ℝ :=
(show Function.Periodic (fun ξ : ℝ ↦ re (jacobiTheta₂ ξ (I * x))) 1 by
intro ξ; simp [jacobiTheta₂_add_left]).lift a
lemma cosKernel_def (a x : ℝ) : ↑(cosKernel ↑a x) = jacobiTheta₂ a (I * x) := by
simp [cosKernel, re_eq_add_conj, jacobiTheta₂_conj, ← mul_two,
mul_div_cancel_right₀ _ (two_ne_zero' ℂ)]
lemma cosKernel_undef (a : UnitAddCircle) {x : ℝ} (hx : x ≤ 0) : cosKernel a x = 0 := by
induction a using QuotientAddGroup.induction_on with
| H => simp [← ofReal_inj, cosKernel_def, jacobiTheta₂_undef _ (by simpa : (I * ↑x).im ≤ 0)]
/-- For `a = 0`, both kernels agree. -/
lemma evenKernel_eq_cosKernel_of_zero : evenKernel 0 = cosKernel 0 := by
ext1 x
simp [← QuotientAddGroup.mk_zero, ← ofReal_inj, evenKernel_def, cosKernel_def]
@[simp]
lemma evenKernel_neg (a : UnitAddCircle) (x : ℝ) : evenKernel (-a) x = evenKernel a x := by
induction a using QuotientAddGroup.induction_on with
| H => simp [← QuotientAddGroup.mk_neg, ← ofReal_inj, evenKernel_def, jacobiTheta₂_neg_left]
@[simp]
lemma cosKernel_neg (a : UnitAddCircle) (x : ℝ) : cosKernel (-a) x = cosKernel a x := by
induction a using QuotientAddGroup.induction_on with
| H => simp [← QuotientAddGroup.mk_neg, ← ofReal_inj, cosKernel_def]
lemma continuousOn_evenKernel (a : UnitAddCircle) : ContinuousOn (evenKernel a) (Ioi 0) := by
induction a using QuotientAddGroup.induction_on with | H a' =>
apply continuous_re.comp_continuousOn (f := fun x ↦ (evenKernel a' x : ℂ))
simp only [evenKernel_def]
refine continuousOn_of_forall_continuousAt (fun x hx ↦ .mul (by fun_prop) ?_)
exact (continuousAt_jacobiTheta₂ (a' * I * x) <| by simpa).comp
(f := fun u : ℝ ↦ (a' * I * u, I * u)) (by fun_prop)
lemma continuousOn_cosKernel (a : UnitAddCircle) : ContinuousOn (cosKernel a) (Ioi 0) := by
induction a using QuotientAddGroup.induction_on with | H a' =>
apply continuous_re.comp_continuousOn (f := fun x ↦ (cosKernel a' x : ℂ))
simp only [cosKernel_def]
refine continuousOn_of_forall_continuousAt (fun x hx ↦ ?_)
exact (continuousAt_jacobiTheta₂ a' <| by simpa).comp
(f := fun u : ℝ ↦ ((a' : ℂ), I * u)) (by fun_prop)
lemma evenKernel_functional_equation (a : UnitAddCircle) (x : ℝ) :
evenKernel a x = 1 / x ^ (1 / 2 : ℝ) * cosKernel a (1 / x) := by
rcases le_or_lt x 0 with hx | hx
· rw [evenKernel_undef _ hx, cosKernel_undef, mul_zero]
exact div_nonpos_of_nonneg_of_nonpos zero_le_one hx
induction a using QuotientAddGroup.induction_on with | H a =>
rw [← ofReal_inj, ofReal_mul, evenKernel_def, cosKernel_def, jacobiTheta₂_functional_equation]
have h1 : I * ↑(1 / x) = -1 / (I * x) := by
push_cast
rw [← div_div, mul_one_div, div_I, neg_one_mul, neg_neg]
have hx' : I * x ≠ 0 := mul_ne_zero I_ne_zero (ofReal_ne_zero.mpr hx.ne')
have h2 : a * I * x / (I * x) = a := by
rw [div_eq_iff hx']
ring
have h3 : 1 / (-I * (I * x)) ^ (1 / 2 : ℂ) = 1 / ↑(x ^ (1 / 2 : ℝ)) := by
rw [neg_mul, ← mul_assoc, I_mul_I, neg_one_mul, neg_neg,ofReal_cpow hx.le, ofReal_div,
ofReal_one, ofReal_ofNat]
have h4 : -π * I * (a * I * x) ^ 2 / (I * x) = - (-π * a ^ 2 * x) := by
rw [mul_pow, mul_pow, I_sq, div_eq_iff hx']
ring
rw [h1, h2, h3, h4, ← mul_assoc, mul_comm (cexp _), mul_assoc _ (cexp _) (cexp _),
← Complex.exp_add, neg_add_cancel, Complex.exp_zero, mul_one, ofReal_div, ofReal_one]
end kernel_defs
section asymp
/-!
## Formulae for the kernels as sums
-/
lemma hasSum_int_evenKernel (a : ℝ) {t : ℝ} (ht : 0 < t) :
HasSum (fun n : ℤ ↦ rexp (-π * (n + a) ^ 2 * t)) (evenKernel a t) := by
rw [← hasSum_ofReal, evenKernel_def]
have (n : ℤ) : cexp (-(π * (n + a) ^ 2 * t)) = cexp (-(π * a ^ 2 * t)) *
jacobiTheta₂_term n (a * I * t) (I * t) := by
rw [jacobiTheta₂_term, ← Complex.exp_add]
ring_nf
simp
simpa [this] using (hasSum_jacobiTheta₂_term _ (by simpa)).mul_left _
lemma hasSum_int_cosKernel (a : ℝ) {t : ℝ} (ht : 0 < t) :
HasSum (fun n : ℤ ↦ cexp (2 * π * I * a * n) * rexp (-π * n ^ 2 * t)) ↑(cosKernel a t) := by
rw [cosKernel_def a t]
have (n : ℤ) : cexp (2 * π * I * a * n) * cexp (-(π * n ^ 2 * t)) =
jacobiTheta₂_term n a (I * ↑t) := by
rw [jacobiTheta₂_term, ← Complex.exp_add]
ring_nf
simp [sub_eq_add_neg]
simpa [this] using hasSum_jacobiTheta₂_term _ (by simpa)
/-- Modified version of `hasSum_int_evenKernel` omitting the constant term at `∞`. -/
lemma hasSum_int_evenKernel₀ (a : ℝ) {t : ℝ} (ht : 0 < t) :
HasSum (fun n : ℤ ↦ if n + a = 0 then 0 else rexp (-π * (n + a) ^ 2 * t))
(evenKernel a t - if (a : UnitAddCircle) = 0 then 1 else 0) := by
haveI := Classical.propDecidable -- speed up instance search for `if / then / else`
simp_rw [AddCircle.coe_eq_zero_iff, zsmul_one]
split_ifs with h
· obtain ⟨k, rfl⟩ := h
simpa [← Int.cast_add, add_eq_zero_iff_eq_neg]
using hasSum_ite_sub_hasSum (hasSum_int_evenKernel (k : ℝ) ht) (-k)
· suffices ∀ (n : ℤ), n + a ≠ 0 by simpa [this] using hasSum_int_evenKernel a ht
contrapose! h
let ⟨n, hn⟩ := h
exact ⟨-n, by simpa [neg_eq_iff_add_eq_zero]⟩
lemma hasSum_int_cosKernel₀ (a : ℝ) {t : ℝ} (ht : 0 < t) :
HasSum (fun n : ℤ ↦ if n = 0 then 0 else cexp (2 * π * I * a * n) * rexp (-π * n ^ 2 * t))
(↑(cosKernel a t) - 1) := by
simpa using hasSum_ite_sub_hasSum (hasSum_int_cosKernel a ht) 0
lemma hasSum_nat_cosKernel₀ (a : ℝ) {t : ℝ} (ht : 0 < t) :
HasSum (fun n : ℕ ↦ 2 * Real.cos (2 * π * a * (n + 1)) * rexp (-π * (n + 1) ^ 2 * t))
(cosKernel a t - 1) := by
rw [← hasSum_ofReal, ofReal_sub, ofReal_one]
have := (hasSum_int_cosKernel a ht).nat_add_neg
rw [← hasSum_nat_add_iff' 1] at this
simp_rw [Finset.sum_range_one, Nat.cast_zero, neg_zero, Int.cast_zero, zero_pow two_ne_zero,
mul_zero, zero_mul, Complex.exp_zero, Real.exp_zero, ofReal_one, mul_one, Int.cast_neg,
Int.cast_natCast, neg_sq, ← add_mul, add_sub_assoc, ← sub_sub, sub_self, zero_sub,
← sub_eq_add_neg, mul_neg] at this
refine this.congr_fun fun n ↦ ?_
push_cast
rw [Complex.cos, mul_div_cancel₀ _ two_ne_zero]
congr 3 <;> ring
/-!
## Asymptotics of the kernels as `t → ∞`
-/
/-- The function `evenKernel a - L` has exponential decay at `+∞`, where `L = 1` if
`a = 0` and `L = 0` otherwise. -/
lemma isBigO_atTop_evenKernel_sub (a : UnitAddCircle) : ∃ p : ℝ, 0 < p ∧
(evenKernel a · - (if a = 0 then 1 else 0)) =O[atTop] (rexp <| -p * ·) := by
induction a using QuotientAddGroup.induction_on with | H b =>
obtain ⟨p, hp, hp'⟩ := HurwitzKernelBounds.isBigO_atTop_F_int_zero_sub b
refine ⟨p, hp, (EventuallyEq.isBigO ?_).trans hp'⟩
filter_upwards [eventually_gt_atTop 0] with t h
simp [← (hasSum_int_evenKernel b h).tsum_eq, HurwitzKernelBounds.F_int, HurwitzKernelBounds.f_int]
/-- The function `cosKernel a - 1` has exponential decay at `+∞`, for any `a`. -/
lemma isBigO_atTop_cosKernel_sub (a : UnitAddCircle) :
∃ p, 0 < p ∧ IsBigO atTop (cosKernel a · - 1) (fun x ↦ Real.exp (-p * x)) := by
induction a using QuotientAddGroup.induction_on with | H a =>
obtain ⟨p, hp, hp'⟩ := HurwitzKernelBounds.isBigO_atTop_F_nat_zero_sub zero_le_one
refine ⟨p, hp, (Eventually.isBigO ?_).trans (hp'.const_mul_left 2)⟩
filter_upwards [eventually_gt_atTop 0] with t ht
simp only [eq_false_intro one_ne_zero, if_false, sub_zero,
← (hasSum_nat_cosKernel₀ a ht).tsum_eq, HurwitzKernelBounds.F_nat]
apply tsum_of_norm_bounded ((HurwitzKernelBounds.summable_f_nat 0 1 ht).hasSum.mul_left 2)
intro n
rw [norm_mul, norm_mul, norm_two, mul_assoc, mul_le_mul_iff_of_pos_left two_pos,
norm_of_nonneg (exp_pos _).le, HurwitzKernelBounds.f_nat, pow_zero, one_mul, Real.norm_eq_abs]
exact mul_le_of_le_one_left (exp_pos _).le (abs_cos_le_one _)
end asymp
section FEPair
/-!
## Construction of a FE-pair
-/
/-- A `WeakFEPair` structure with `f = evenKernel a` and `g = cosKernel a`. -/
def hurwitzEvenFEPair (a : UnitAddCircle) : WeakFEPair ℂ where
f := ofReal ∘ evenKernel a
g := ofReal ∘ cosKernel a
hf_int := (continuous_ofReal.comp_continuousOn (continuousOn_evenKernel a)).locallyIntegrableOn
measurableSet_Ioi
hg_int := (continuous_ofReal.comp_continuousOn (continuousOn_cosKernel a)).locallyIntegrableOn
measurableSet_Ioi
k := 1 / 2
hk := one_half_pos
ε := 1
hε := one_ne_zero
f₀ := if a = 0 then 1 else 0
hf_top r := by
let ⟨v, hv, hv'⟩ := isBigO_atTop_evenKernel_sub a
rw [← isBigO_norm_left] at hv' ⊢
conv at hv' =>
enter [2, x]; rw [← norm_real, ofReal_sub, apply_ite ((↑) : ℝ → ℂ), ofReal_one, ofReal_zero]
exact hv'.trans (isLittleO_exp_neg_mul_rpow_atTop hv _).isBigO
g₀ := 1
hg_top r := by
obtain ⟨p, hp, hp'⟩ := isBigO_atTop_cosKernel_sub a
simpa using isBigO_ofReal_left.mpr <| hp'.trans (isLittleO_exp_neg_mul_rpow_atTop hp r).isBigO
h_feq x hx := by simp [← ofReal_mul, evenKernel_functional_equation, inv_rpow (le_of_lt hx)]
@[simp]
lemma hurwitzEvenFEPair_zero_symm :
(hurwitzEvenFEPair 0).symm = hurwitzEvenFEPair 0 := by
unfold hurwitzEvenFEPair WeakFEPair.symm
congr 1 <;> simp [evenKernel_eq_cosKernel_of_zero]
@[simp]
lemma hurwitzEvenFEPair_neg (a : UnitAddCircle) : hurwitzEvenFEPair (-a) = hurwitzEvenFEPair a := by
unfold hurwitzEvenFEPair
congr 1 <;> simp [Function.comp_def]
/-!
## Definition of the completed even Hurwitz zeta function
-/
/--
The meromorphic function of `s` which agrees with
`1 / 2 * Gamma (s / 2) * π ^ (-s / 2) * ∑' (n : ℤ), 1 / |n + a| ^ s` for `1 < re s`.
-/
def completedHurwitzZetaEven (a : UnitAddCircle) (s : ℂ) : ℂ :=
((hurwitzEvenFEPair a).Λ (s / 2)) / 2
/-- The entire function differing from `completedHurwitzZetaEven a s` by a linear combination of
`1 / s` and `1 / (1 - s)`. -/
def completedHurwitzZetaEven₀ (a : UnitAddCircle) (s : ℂ) : ℂ :=
((hurwitzEvenFEPair a).Λ₀ (s / 2)) / 2
lemma completedHurwitzZetaEven_eq (a : UnitAddCircle) (s : ℂ) :
completedHurwitzZetaEven a s =
completedHurwitzZetaEven₀ a s - (if a = 0 then 1 else 0) / s - 1 / (1 - s) := by
rw [completedHurwitzZetaEven, WeakFEPair.Λ, sub_div, sub_div]
congr 1
· change completedHurwitzZetaEven₀ a s - (1 / (s / 2)) • (if a = 0 then 1 else 0) / 2 =
completedHurwitzZetaEven₀ a s - (if a = 0 then 1 else 0) / s
rw [smul_eq_mul, mul_comm, mul_div_assoc, div_div, div_mul_cancel₀ _ two_ne_zero, mul_one_div]
· change (1 / (↑(1 / 2 : ℝ) - s / 2)) • 1 / 2 = 1 / (1 - s)
push_cast
rw [smul_eq_mul, mul_one, ← sub_div, div_div, div_mul_cancel₀ _ two_ne_zero]
/--
The meromorphic function of `s` which agrees with
`Gamma (s / 2) * π ^ (-s / 2) * ∑' n : ℕ, cos (2 * π * a * n) / n ^ s` for `1 < re s`.
-/
def completedCosZeta (a : UnitAddCircle) (s : ℂ) : ℂ :=
((hurwitzEvenFEPair a).symm.Λ (s / 2)) / 2
/-- The entire function differing from `completedCosZeta a s` by a linear combination of
`1 / s` and `1 / (1 - s)`. -/
def completedCosZeta₀ (a : UnitAddCircle) (s : ℂ) : ℂ :=
((hurwitzEvenFEPair a).symm.Λ₀ (s / 2)) / 2
lemma completedCosZeta_eq (a : UnitAddCircle) (s : ℂ) :
completedCosZeta a s =
completedCosZeta₀ a s - 1 / s - (if a = 0 then 1 else 0) / (1 - s) := by
rw [completedCosZeta, WeakFEPair.Λ, sub_div, sub_div]
congr 1
· rw [completedCosZeta₀, WeakFEPair.symm, hurwitzEvenFEPair, smul_eq_mul, mul_one, div_div,
div_mul_cancel₀ _ (two_ne_zero' ℂ)]
· simp_rw [WeakFEPair.symm, hurwitzEvenFEPair, push_cast, inv_one, smul_eq_mul,
mul_comm _ (if _ then _ else _), mul_div_assoc, div_div, ← sub_div,
div_mul_cancel₀ _ (two_ne_zero' ℂ), mul_one_div]
/-!
## Parity and functional equations
-/
@[simp]
lemma completedHurwitzZetaEven_neg (a : UnitAddCircle) (s : ℂ) :
completedHurwitzZetaEven (-a) s = completedHurwitzZetaEven a s := by
simp [completedHurwitzZetaEven]
@[simp]
lemma completedHurwitzZetaEven₀_neg (a : UnitAddCircle) (s : ℂ) :
completedHurwitzZetaEven₀ (-a) s = completedHurwitzZetaEven₀ a s := by
simp [completedHurwitzZetaEven₀]
@[simp]
lemma completedCosZeta_neg (a : UnitAddCircle) (s : ℂ) :
completedCosZeta (-a) s = completedCosZeta a s := by
simp [completedCosZeta]
@[simp]
lemma completedCosZeta₀_neg (a : UnitAddCircle) (s : ℂ) :
completedCosZeta₀ (-a) s = completedCosZeta₀ a s := by
simp [completedCosZeta₀]
/-- Functional equation for the even Hurwitz zeta function. -/
lemma completedHurwitzZetaEven_one_sub (a : UnitAddCircle) (s : ℂ) :
completedHurwitzZetaEven a (1 - s) = completedCosZeta a s := by
rw [completedHurwitzZetaEven, completedCosZeta, sub_div,
(by norm_num : (1 / 2 : ℂ) = ↑(1 / 2 : ℝ)),
(by rfl : (1 / 2 : ℝ) = (hurwitzEvenFEPair a).k),
(hurwitzEvenFEPair a).functional_equation (s / 2),
(by rfl : (hurwitzEvenFEPair a).ε = 1),
one_smul]
/-- Functional equation for the even Hurwitz zeta function with poles removed. -/
lemma completedHurwitzZetaEven₀_one_sub (a : UnitAddCircle) (s : ℂ) :
completedHurwitzZetaEven₀ a (1 - s) = completedCosZeta₀ a s := by
rw [completedHurwitzZetaEven₀, completedCosZeta₀, sub_div,
(by norm_num : (1 / 2 : ℂ) = ↑(1 / 2 : ℝ)),
(by rfl : (1 / 2 : ℝ) = (hurwitzEvenFEPair a).k),
(hurwitzEvenFEPair a).functional_equation₀ (s / 2),
(by rfl : (hurwitzEvenFEPair a).ε = 1),
one_smul]
/-- Functional equation for the even Hurwitz zeta function (alternative form). -/
lemma completedCosZeta_one_sub (a : UnitAddCircle) (s : ℂ) :
completedCosZeta a (1 - s) = completedHurwitzZetaEven a s := by
rw [← completedHurwitzZetaEven_one_sub, sub_sub_cancel]
/-- Functional equation for the even Hurwitz zeta function with poles removed (alternative form). -/
lemma completedCosZeta₀_one_sub (a : UnitAddCircle) (s : ℂ) :
completedCosZeta₀ a (1 - s) = completedHurwitzZetaEven₀ a s := by
rw [← completedHurwitzZetaEven₀_one_sub, sub_sub_cancel]
|
end FEPair
/-!
## Differentiability and residues
-/
section FEPair
| Mathlib/NumberTheory/LSeries/HurwitzZetaEven.lean | 390 | 398 |
/-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura, Simon Hudon, Mario Carneiro
-/
import Aesop
import Mathlib.Algebra.Group.Defs
import Mathlib.Data.Nat.Init
import Mathlib.Data.Int.Init
import Mathlib.Logic.Function.Iterate
import Mathlib.Tactic.SimpRw
import Mathlib.Tactic.SplitIfs
/-!
# Basic lemmas about semigroups, monoids, and groups
This file lists various basic lemmas about semigroups, monoids, and groups. Most proofs are
one-liners from the corresponding axioms. For the definitions of semigroups, monoids and groups, see
`Algebra/Group/Defs.lean`.
-/
assert_not_exists MonoidWithZero DenselyOrdered
open Function
variable {α β G M : Type*}
section ite
variable [Pow α β]
@[to_additive (attr := simp) dite_smul]
lemma pow_dite (p : Prop) [Decidable p] (a : α) (b : p → β) (c : ¬ p → β) :
a ^ (if h : p then b h else c h) = if h : p then a ^ b h else a ^ c h := by split_ifs <;> rfl
@[to_additive (attr := simp) smul_dite]
lemma dite_pow (p : Prop) [Decidable p] (a : p → α) (b : ¬ p → α) (c : β) :
(if h : p then a h else b h) ^ c = if h : p then a h ^ c else b h ^ c := by split_ifs <;> rfl
@[to_additive (attr := simp) ite_smul]
lemma pow_ite (p : Prop) [Decidable p] (a : α) (b c : β) :
a ^ (if p then b else c) = if p then a ^ b else a ^ c := pow_dite _ _ _ _
@[to_additive (attr := simp) smul_ite]
lemma ite_pow (p : Prop) [Decidable p] (a b : α) (c : β) :
(if p then a else b) ^ c = if p then a ^ c else b ^ c := dite_pow _ _ _ _
set_option linter.existingAttributeWarning false in
attribute [to_additive (attr := simp)] dite_smul smul_dite ite_smul smul_ite
end ite
section Semigroup
variable [Semigroup α]
@[to_additive]
instance Semigroup.to_isAssociative : Std.Associative (α := α) (· * ·) := ⟨mul_assoc⟩
/-- Composing two multiplications on the left by `y` then `x`
is equal to a multiplication on the left by `x * y`.
-/
@[to_additive (attr := simp) "Composing two additions on the left by `y` then `x`
is equal to an addition on the left by `x + y`."]
theorem comp_mul_left (x y : α) : (x * ·) ∘ (y * ·) = (x * y * ·) := by
ext z
simp [mul_assoc]
/-- Composing two multiplications on the right by `y` and `x`
is equal to a multiplication on the right by `y * x`.
-/
@[to_additive (attr := simp) "Composing two additions on the right by `y` and `x`
is equal to an addition on the right by `y + x`."]
theorem comp_mul_right (x y : α) : (· * x) ∘ (· * y) = (· * (y * x)) := by
ext z
simp [mul_assoc]
end Semigroup
@[to_additive]
instance CommMagma.to_isCommutative [CommMagma G] : Std.Commutative (α := G) (· * ·) := ⟨mul_comm⟩
section MulOneClass
variable [MulOneClass M]
@[to_additive]
theorem ite_mul_one {P : Prop} [Decidable P] {a b : M} :
ite P (a * b) 1 = ite P a 1 * ite P b 1 := by
by_cases h : P <;> simp [h]
@[to_additive]
theorem ite_one_mul {P : Prop} [Decidable P] {a b : M} :
ite P 1 (a * b) = ite P 1 a * ite P 1 b := by
by_cases h : P <;> simp [h]
@[to_additive]
theorem eq_one_iff_eq_one_of_mul_eq_one {a b : M} (h : a * b = 1) : a = 1 ↔ b = 1 := by
constructor <;> (rintro rfl; simpa using h)
@[to_additive]
theorem one_mul_eq_id : ((1 : M) * ·) = id :=
funext one_mul
@[to_additive]
theorem mul_one_eq_id : (· * (1 : M)) = id :=
funext mul_one
end MulOneClass
section CommSemigroup
variable [CommSemigroup G]
@[to_additive]
theorem mul_left_comm (a b c : G) : a * (b * c) = b * (a * c) := by
rw [← mul_assoc, mul_comm a, mul_assoc]
@[to_additive]
theorem mul_right_comm (a b c : G) : a * b * c = a * c * b := by
rw [mul_assoc, mul_comm b, mul_assoc]
@[to_additive]
theorem mul_mul_mul_comm (a b c d : G) : a * b * (c * d) = a * c * (b * d) := by
simp only [mul_left_comm, mul_assoc]
@[to_additive]
theorem mul_rotate (a b c : G) : a * b * c = b * c * a := by
simp only [mul_left_comm, mul_comm]
@[to_additive]
theorem mul_rotate' (a b c : G) : a * (b * c) = b * (c * a) := by
simp only [mul_left_comm, mul_comm]
end CommSemigroup
attribute [local simp] mul_assoc sub_eq_add_neg
section Monoid
variable [Monoid M] {a b : M} {m n : ℕ}
@[to_additive boole_nsmul]
lemma pow_boole (P : Prop) [Decidable P] (a : M) :
(a ^ if P then 1 else 0) = if P then a else 1 := by simp only [pow_ite, pow_one, pow_zero]
@[to_additive nsmul_add_sub_nsmul]
lemma pow_mul_pow_sub (a : M) (h : m ≤ n) : a ^ m * a ^ (n - m) = a ^ n := by
rw [← pow_add, Nat.add_comm, Nat.sub_add_cancel h]
@[to_additive sub_nsmul_nsmul_add]
lemma pow_sub_mul_pow (a : M) (h : m ≤ n) : a ^ (n - m) * a ^ m = a ^ n := by
rw [← pow_add, Nat.sub_add_cancel h]
@[to_additive sub_one_nsmul_add]
lemma mul_pow_sub_one (hn : n ≠ 0) (a : M) : a * a ^ (n - 1) = a ^ n := by
rw [← pow_succ', Nat.sub_add_cancel <| Nat.one_le_iff_ne_zero.2 hn]
@[to_additive add_sub_one_nsmul]
lemma pow_sub_one_mul (hn : n ≠ 0) (a : M) : a ^ (n - 1) * a = a ^ n := by
rw [← pow_succ, Nat.sub_add_cancel <| Nat.one_le_iff_ne_zero.2 hn]
/-- If `x ^ n = 1`, then `x ^ m` is the same as `x ^ (m % n)` -/
@[to_additive nsmul_eq_mod_nsmul "If `n • x = 0`, then `m • x` is the same as `(m % n) • x`"]
lemma pow_eq_pow_mod (m : ℕ) (ha : a ^ n = 1) : a ^ m = a ^ (m % n) := by
calc
a ^ m = a ^ (m % n + n * (m / n)) := by rw [Nat.mod_add_div]
_ = a ^ (m % n) := by simp [pow_add, pow_mul, ha]
@[to_additive] lemma pow_mul_pow_eq_one : ∀ n, a * b = 1 → a ^ n * b ^ n = 1
| 0, _ => by simp
| n + 1, h =>
calc
a ^ n.succ * b ^ n.succ = a ^ n * a * (b * b ^ n) := by rw [pow_succ, pow_succ']
_ = a ^ n * (a * b) * b ^ n := by simp only [mul_assoc]
_ = 1 := by simp [h, pow_mul_pow_eq_one]
@[to_additive (attr := simp)]
lemma mul_left_iterate (a : M) : ∀ n : ℕ, (a * ·)^[n] = (a ^ n * ·)
| 0 => by ext; simp
| n + 1 => by ext; simp [pow_succ, mul_left_iterate]
@[to_additive (attr := simp)]
lemma mul_right_iterate (a : M) : ∀ n : ℕ, (· * a)^[n] = (· * a ^ n)
| 0 => by ext; simp
| n + 1 => by ext; simp [pow_succ', mul_right_iterate]
@[to_additive]
lemma mul_left_iterate_apply_one (a : M) : (a * ·)^[n] 1 = a ^ n := by simp [mul_right_iterate]
@[to_additive]
lemma mul_right_iterate_apply_one (a : M) : (· * a)^[n] 1 = a ^ n := by simp [mul_right_iterate]
@[to_additive (attr := simp)]
lemma pow_iterate (k : ℕ) : ∀ n : ℕ, (fun x : M ↦ x ^ k)^[n] = (· ^ k ^ n)
| 0 => by ext; simp
| n + 1 => by ext; simp [pow_iterate, Nat.pow_succ', pow_mul]
end Monoid
section CommMonoid
variable [CommMonoid M] {x y z : M}
@[to_additive]
theorem inv_unique (hy : x * y = 1) (hz : x * z = 1) : y = z :=
left_inv_eq_right_inv (Trans.trans (mul_comm _ _) hy) hz
@[to_additive nsmul_add] lemma mul_pow (a b : M) : ∀ n, (a * b) ^ n = a ^ n * b ^ n
| 0 => by rw [pow_zero, pow_zero, pow_zero, one_mul]
| n + 1 => by rw [pow_succ', pow_succ', pow_succ', mul_pow, mul_mul_mul_comm]
end CommMonoid
section LeftCancelMonoid
variable [Monoid M] [IsLeftCancelMul M] {a b : M}
@[to_additive (attr := simp)]
theorem mul_eq_left : a * b = a ↔ b = 1 := calc
a * b = a ↔ a * b = a * 1 := by rw [mul_one]
_ ↔ b = 1 := mul_left_cancel_iff
@[deprecated (since := "2025-03-05")] alias mul_right_eq_self := mul_eq_left
@[deprecated (since := "2025-03-05")] alias add_right_eq_self := add_eq_left
set_option linter.existingAttributeWarning false in
attribute [to_additive existing] mul_right_eq_self
@[to_additive (attr := simp)]
theorem left_eq_mul : a = a * b ↔ b = 1 :=
eq_comm.trans mul_eq_left
@[deprecated (since := "2025-03-05")] alias self_eq_mul_right := left_eq_mul
@[deprecated (since := "2025-03-05")] alias self_eq_add_right := left_eq_add
set_option linter.existingAttributeWarning false in
attribute [to_additive existing] self_eq_mul_right
@[to_additive]
theorem mul_ne_left : a * b ≠ a ↔ b ≠ 1 := mul_eq_left.not
@[deprecated (since := "2025-03-05")] alias mul_right_ne_self := mul_ne_left
@[deprecated (since := "2025-03-05")] alias add_right_ne_self := add_ne_left
set_option linter.existingAttributeWarning false in
attribute [to_additive existing] mul_right_ne_self
@[to_additive]
theorem left_ne_mul : a ≠ a * b ↔ b ≠ 1 := left_eq_mul.not
@[deprecated (since := "2025-03-05")] alias self_ne_mul_right := left_ne_mul
@[deprecated (since := "2025-03-05")] alias self_ne_add_right := left_ne_add
set_option linter.existingAttributeWarning false in
attribute [to_additive existing] self_ne_mul_right
end LeftCancelMonoid
section RightCancelMonoid
variable [RightCancelMonoid M] {a b : M}
@[to_additive (attr := simp)]
theorem mul_eq_right : a * b = b ↔ a = 1 := calc
a * b = b ↔ a * b = 1 * b := by rw [one_mul]
_ ↔ a = 1 := mul_right_cancel_iff
@[deprecated (since := "2025-03-05")] alias mul_left_eq_self := mul_eq_right
@[deprecated (since := "2025-03-05")] alias add_left_eq_self := add_eq_right
set_option linter.existingAttributeWarning false in
attribute [to_additive existing] mul_left_eq_self
@[to_additive (attr := simp)]
theorem right_eq_mul : b = a * b ↔ a = 1 :=
eq_comm.trans mul_eq_right
@[deprecated (since := "2025-03-05")] alias self_eq_mul_left := right_eq_mul
@[deprecated (since := "2025-03-05")] alias self_eq_add_left := right_eq_add
set_option linter.existingAttributeWarning false in
attribute [to_additive existing] self_eq_mul_left
@[to_additive]
theorem mul_ne_right : a * b ≠ b ↔ a ≠ 1 := mul_eq_right.not
@[deprecated (since := "2025-03-05")] alias mul_left_ne_self := mul_ne_right
@[deprecated (since := "2025-03-05")] alias add_left_ne_self := add_ne_right
set_option linter.existingAttributeWarning false in
attribute [to_additive existing] mul_left_ne_self
@[to_additive]
theorem right_ne_mul : b ≠ a * b ↔ a ≠ 1 := right_eq_mul.not
@[deprecated (since := "2025-03-05")] alias self_ne_mul_left := right_ne_mul
@[deprecated (since := "2025-03-05")] alias self_ne_add_left := right_ne_add
set_option linter.existingAttributeWarning false in
attribute [to_additive existing] self_ne_mul_left
end RightCancelMonoid
section CancelCommMonoid
variable [CancelCommMonoid α] {a b c d : α}
@[to_additive] lemma eq_iff_eq_of_mul_eq_mul (h : a * b = c * d) : a = c ↔ b = d := by aesop
@[to_additive] lemma ne_iff_ne_of_mul_eq_mul (h : a * b = c * d) : a ≠ c ↔ b ≠ d := by aesop
end CancelCommMonoid
section InvolutiveInv
variable [InvolutiveInv G] {a b : G}
@[to_additive (attr := simp)]
theorem inv_involutive : Function.Involutive (Inv.inv : G → G) :=
inv_inv
@[to_additive (attr := simp)]
theorem inv_surjective : Function.Surjective (Inv.inv : G → G) :=
inv_involutive.surjective
@[to_additive]
theorem inv_injective : Function.Injective (Inv.inv : G → G) :=
| inv_involutive.injective
@[to_additive (attr := simp)]
| Mathlib/Algebra/Group/Basic.lean | 323 | 325 |
/-
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.Finite.Defs
import Mathlib.Data.Finset.BooleanAlgebra
import Mathlib.Data.Finset.Image
import Mathlib.Data.Fintype.Defs
import Mathlib.Data.Fintype.OfMap
import Mathlib.Data.Fintype.Sets
import Mathlib.Data.List.FinRange
/-!
# Instances for finite types
This file is a collection of basic `Fintype` instances for types such as `Fin`, `Prod` and pi types.
-/
assert_not_exists Monoid
open Function
open Nat
universe u v
variable {α β γ : Type*}
open Finset
instance Fin.fintype (n : ℕ) : Fintype (Fin n) :=
⟨⟨List.finRange n, List.nodup_finRange n⟩, List.mem_finRange⟩
theorem Fin.univ_def (n : ℕ) : (univ : Finset (Fin n)) = ⟨List.finRange n, List.nodup_finRange n⟩ :=
rfl
theorem Finset.val_univ_fin (n : ℕ) : (Finset.univ : Finset (Fin n)).val = List.finRange n := rfl
/-- See also `nonempty_encodable`, `nonempty_denumerable`. -/
theorem nonempty_fintype (α : Type*) [Finite α] : Nonempty (Fintype α) := by
rcases Finite.exists_equiv_fin α with ⟨n, ⟨e⟩⟩
exact ⟨.ofEquiv _ e.symm⟩
@[simp] theorem List.toFinset_finRange (n : ℕ) : (List.finRange n).toFinset = Finset.univ := by
ext; simp
@[simp] theorem Fin.univ_val_map {n : ℕ} (f : Fin n → α) :
Finset.univ.val.map f = List.ofFn f := by
simp [List.ofFn_eq_map, univ_def]
theorem Fin.univ_image_def {n : ℕ} [DecidableEq α] (f : Fin n → α) :
Finset.univ.image f = (List.ofFn f).toFinset := by
simp [Finset.image]
theorem Fin.univ_map_def {n : ℕ} (f : Fin n ↪ α) :
Finset.univ.map f = ⟨List.ofFn f, List.nodup_ofFn.mpr f.injective⟩ := by
simp [Finset.map]
@[simp]
theorem Fin.image_succAbove_univ {n : ℕ} (i : Fin (n + 1)) : univ.image i.succAbove = {i}ᶜ := by
ext m
simp
@[simp]
theorem Fin.image_succ_univ (n : ℕ) : (univ : Finset (Fin n)).image Fin.succ = {0}ᶜ := by
rw [← Fin.succAbove_zero, Fin.image_succAbove_univ]
@[simp]
theorem Fin.image_castSucc (n : ℕ) :
(univ : Finset (Fin n)).image Fin.castSucc = {Fin.last n}ᶜ := by
rw [← Fin.succAbove_last, Fin.image_succAbove_univ]
/- The following three lemmas use `Finset.cons` instead of `insert` and `Finset.map` instead of
`Finset.image` to reduce proof obligations downstream. -/
/-- Embed `Fin n` into `Fin (n + 1)` by prepending zero to the `univ` -/
theorem Fin.univ_succ (n : ℕ) :
(univ : Finset (Fin (n + 1))) =
Finset.cons 0 (univ.map ⟨Fin.succ, Fin.succ_injective _⟩) (by simp [map_eq_image]) := by
simp [map_eq_image]
/-- Embed `Fin n` into `Fin (n + 1)` by appending a new `Fin.last n` to the `univ` -/
theorem Fin.univ_castSuccEmb (n : ℕ) :
(univ : Finset (Fin (n + 1))) =
Finset.cons (Fin.last n) (univ.map Fin.castSuccEmb) (by simp [map_eq_image]) := by
simp [map_eq_image]
/-- Embed `Fin n` into `Fin (n + 1)` by inserting
around a specified pivot `p : Fin (n + 1)` into the `univ` -/
theorem Fin.univ_succAbove (n : ℕ) (p : Fin (n + 1)) :
(univ : Finset (Fin (n + 1))) = Finset.cons p (univ.map <| Fin.succAboveEmb p) (by simp) := by
simp [map_eq_image]
@[simp] theorem Fin.univ_image_get [DecidableEq α] (l : List α) :
Finset.univ.image l.get = l.toFinset := by
simp [univ_image_def]
@[simp] theorem Fin.univ_image_getElem' [DecidableEq β] (l : List α) (f : α → β) :
Finset.univ.image (fun i : Fin l.length => f <| l[(i : Nat)]) = (l.map f).toFinset := by
simp only [univ_image_def, List.ofFn_getElem_eq_map]
theorem Fin.univ_image_get' [DecidableEq β] (l : List α) (f : α → β) :
Finset.univ.image (f <| l.get ·) = (l.map f).toFinset := by
simp
@[instance]
def Unique.fintype {α : Type*} [Unique α] : Fintype α :=
Fintype.ofSubsingleton default
/-- Short-circuit instance to decrease search for `Unique.fintype`,
since that relies on a subsingleton elimination for `Unique`. -/
instance Fintype.subtypeEq (y : α) : Fintype { x // x = y } :=
Fintype.subtype {y} (by simp)
/-- Short-circuit instance to decrease search for `Unique.fintype`,
since that relies on a subsingleton elimination for `Unique`. -/
instance Fintype.subtypeEq' (y : α) : Fintype { x // y = x } :=
Fintype.subtype {y} (by simp [eq_comm])
theorem Fintype.univ_empty : @univ Empty _ = ∅ :=
rfl
theorem Fintype.univ_pempty : @univ PEmpty _ = ∅ :=
rfl
instance Unit.fintype : Fintype Unit :=
Fintype.ofSubsingleton ()
theorem Fintype.univ_unit : @univ Unit _ = {()} :=
rfl
instance PUnit.fintype : Fintype PUnit :=
Fintype.ofSubsingleton PUnit.unit
theorem Fintype.univ_punit : @univ PUnit _ = {PUnit.unit} :=
rfl
@[simp]
theorem Fintype.univ_bool : @univ Bool _ = {true, false} :=
rfl
/-- Given that `α × β` is a fintype, `α` is also a fintype. -/
def Fintype.prodLeft {α β} [DecidableEq α] [Fintype (α × β)] [Nonempty β] : Fintype α :=
⟨(@univ (α × β) _).image Prod.fst, fun a => by simp⟩
/-- Given that `α × β` is a fintype, `β` is also a fintype. -/
def Fintype.prodRight {α β} [DecidableEq β] [Fintype (α × β)] [Nonempty α] : Fintype β :=
⟨(@univ (α × β) _).image Prod.snd, fun b => by simp⟩
instance ULift.fintype (α : Type*) [Fintype α] : Fintype (ULift α) :=
Fintype.ofEquiv _ Equiv.ulift.symm
instance PLift.fintype (α : Type*) [Fintype α] : Fintype (PLift α) :=
Fintype.ofEquiv _ Equiv.plift.symm
instance PLift.fintypeProp (p : Prop) [Decidable p] : Fintype (PLift p) :=
⟨if h : p then {⟨h⟩} else ∅, fun ⟨h⟩ => by simp [h]⟩
instance Quotient.fintype [Fintype α] (s : Setoid α) [DecidableRel ((· ≈ ·) : α → α → Prop)] :
Fintype (Quotient s) :=
Fintype.ofSurjective Quotient.mk'' Quotient.mk''_surjective
instance PSigma.fintypePropLeft {α : Prop} {β : α → Type*} [Decidable α] [∀ a, Fintype (β a)] :
Fintype (Σ'a, β a) :=
if h : α then Fintype.ofEquiv (β h) ⟨fun x => ⟨h, x⟩, PSigma.snd, fun _ => rfl, fun ⟨_, _⟩ => rfl⟩
else ⟨∅, fun x => (h x.1).elim⟩
instance PSigma.fintypePropRight {α : Type*} {β : α → Prop} [∀ a, Decidable (β a)] [Fintype α] :
Fintype (Σ'a, β a) :=
Fintype.ofEquiv { a // β a }
⟨fun ⟨x, y⟩ => ⟨x, y⟩, fun ⟨x, y⟩ => ⟨x, y⟩, fun ⟨_, _⟩ => rfl, fun ⟨_, _⟩ => rfl⟩
instance PSigma.fintypePropProp {α : Prop} {β : α → Prop} [Decidable α] [∀ a, Decidable (β a)] :
Fintype (Σ'a, β a) :=
if h : ∃ a, β a then ⟨{⟨h.fst, h.snd⟩}, fun ⟨_, _⟩ => by simp⟩ else ⟨∅, fun ⟨x, y⟩ =>
(h ⟨x, y⟩).elim⟩
instance pfunFintype (p : Prop) [Decidable p] (α : p → Type*) [∀ hp, Fintype (α hp)] :
Fintype (∀ hp : p, α hp) :=
if hp : p then Fintype.ofEquiv (α hp) ⟨fun a _ => a, fun f => f hp, fun _ => rfl, fun _ => rfl⟩
else ⟨singleton fun h => (hp h).elim, fun h => mem_singleton.2
(funext fun x => by contradiction)⟩
section Trunc
/-- For `s : Multiset α`, we can lift the existential statement that `∃ x, x ∈ s` to a `Trunc α`.
-/
def truncOfMultisetExistsMem {α} (s : Multiset α) : (∃ x, x ∈ s) → Trunc α :=
Quotient.recOnSubsingleton s fun l h =>
match l, h with
| [], _ => False.elim (by tauto)
| a :: _, _ => Trunc.mk a
/-- A `Nonempty` `Fintype` constructively contains an element.
-/
def truncOfNonemptyFintype (α) [Nonempty α] [Fintype α] : Trunc α :=
truncOfMultisetExistsMem Finset.univ.val (by simp)
/-- By iterating over the elements of a fintype, we can lift an existential statement `∃ a, P a`
to `Trunc (Σ' a, P a)`, containing data.
-/
def truncSigmaOfExists {α} [Fintype α] {P : α → Prop} [DecidablePred P] (h : ∃ a, P a) :
Trunc (Σ'a, P a) :=
@truncOfNonemptyFintype (Σ'a, P a) ((Exists.elim h) fun a ha => ⟨⟨a, ha⟩⟩) _
end Trunc
namespace Multiset
variable [Fintype α] [Fintype β]
@[simp]
theorem count_univ [DecidableEq α] (a : α) : count a Finset.univ.val = 1 :=
count_eq_one_of_mem Finset.univ.nodup (Finset.mem_univ _)
@[simp]
theorem map_univ_val_equiv (e : α ≃ β) :
map e univ.val = univ.val := by
rw [← congr_arg Finset.val (Finset.map_univ_equiv e), Finset.map_val, Equiv.coe_toEmbedding]
/-- For functions on finite sets, they are bijections iff they map universes into universes. -/
@[simp]
theorem bijective_iff_map_univ_eq_univ (f : α → β) :
f.Bijective ↔ map f (Finset.univ : Finset α).val = univ.val :=
⟨fun bij ↦ congr_arg (·.val) (map_univ_equiv <| Equiv.ofBijective f bij),
fun eq ↦ ⟨
fun a₁ a₂ ↦ inj_on_of_nodup_map (eq.symm ▸ univ.nodup) _ (mem_univ a₁) _ (mem_univ a₂),
fun b ↦ have ⟨a, _, h⟩ := mem_map.mp (eq.symm ▸ mem_univ_val b); ⟨a, h⟩⟩⟩
end Multiset
/-- Auxiliary definition to show `exists_seq_of_forall_finset_exists`. -/
noncomputable def seqOfForallFinsetExistsAux {α : Type*} [DecidableEq α] (P : α → Prop)
(r : α → α → Prop) (h : ∀ s : Finset α, ∃ y, (∀ x ∈ s, P x) → P y ∧ ∀ x ∈ s, r x y) : ℕ → α
| n =>
Classical.choose
(h
(Finset.image (fun i : Fin n => seqOfForallFinsetExistsAux P r h i)
(Finset.univ : Finset (Fin n))))
/-- Induction principle to build a sequence, by adding one point at a time satisfying a given
relation with respect to all the previously chosen points.
More precisely, Assume that, for any finite set `s`, one can find another point satisfying
some relation `r` with respect to all the points in `s`. Then one may construct a
function `f : ℕ → α` such that `r (f m) (f n)` holds whenever `m < n`.
We also ensure that all constructed points satisfy a given predicate `P`. -/
theorem exists_seq_of_forall_finset_exists {α : Type*} (P : α → Prop) (r : α → α → Prop)
(h : ∀ s : Finset α, (∀ x ∈ s, P x) → ∃ y, P y ∧ ∀ x ∈ s, r x y) :
∃ f : ℕ → α, (∀ n, P (f n)) ∧ ∀ m n, m < n → r (f m) (f n) := by
classical
have : Nonempty α := by
rcases h ∅ (by simp) with ⟨y, _⟩
exact ⟨y⟩
choose! F hF using h
have h' : ∀ s : Finset α, ∃ y, (∀ x ∈ s, P x) → P y ∧ ∀ x ∈ s, r x y := fun s => ⟨F s, hF s⟩
set f := seqOfForallFinsetExistsAux P r h' with hf
have A : ∀ n : ℕ, P (f n) := by
intro n
induction' n using Nat.strong_induction_on with n IH
have IH' : ∀ x : Fin n, P (f x) := fun n => IH n.1 n.2
rw [hf, seqOfForallFinsetExistsAux]
exact
(Classical.choose_spec
(h' (Finset.image (fun i : Fin n => f i) (Finset.univ : Finset (Fin n))))
(by simp [IH'])).1
refine ⟨f, A, fun m n hmn => ?_⟩
conv_rhs => rw [hf]
rw [seqOfForallFinsetExistsAux]
apply
(Classical.choose_spec
(h' (Finset.image (fun i : Fin n => f i) (Finset.univ : Finset (Fin n)))) (by simp [A])).2
exact Finset.mem_image.2 ⟨⟨m, hmn⟩, Finset.mem_univ _, rfl⟩
/-- Induction principle to build a sequence, by adding one point at a time satisfying a given
symmetric relation with respect to all the previously chosen points.
More precisely, Assume that, for any finite set `s`, one can find another point satisfying
some relation `r` with respect to all the points in `s`. Then one may construct a
function `f : ℕ → α` such that `r (f m) (f n)` holds whenever `m ≠ n`.
We also ensure that all constructed points satisfy a given predicate `P`. -/
theorem exists_seq_of_forall_finset_exists' {α : Type*} (P : α → Prop) (r : α → α → Prop)
[IsSymm α r] (h : ∀ s : Finset α, (∀ x ∈ s, P x) → ∃ y, P y ∧ ∀ x ∈ s, r x y) :
∃ f : ℕ → α, (∀ n, P (f n)) ∧ Pairwise (r on f) := by
rcases exists_seq_of_forall_finset_exists P r h with ⟨f, hf, hf'⟩
refine ⟨f, hf, fun m n hmn => ?_⟩
rcases lt_trichotomy m n with (h | rfl | h)
· exact hf' m n h
· exact (hmn rfl).elim
· unfold Function.onFun
apply symm
exact hf' n m h
| Mathlib/Data/Fintype/Basic.lean | 863 | 866 | |
/-
Copyright (c) 2019 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Patrick Massot, Casper Putz, Anne Baanen
-/
import Mathlib.Algebra.Algebra.Subalgebra.Tower
import Mathlib.Data.Finite.Sum
import Mathlib.Data.Matrix.Block
import Mathlib.Data.Matrix.Notation
import Mathlib.LinearAlgebra.Basis.Basic
import Mathlib.LinearAlgebra.Basis.Fin
import Mathlib.LinearAlgebra.Basis.Prod
import Mathlib.LinearAlgebra.Basis.SMul
import Mathlib.LinearAlgebra.Matrix.StdBasis
import Mathlib.RingTheory.AlgebraTower
import Mathlib.RingTheory.Ideal.Span
/-!
# Linear maps and matrices
This file defines the maps to send matrices to a linear map,
and to send linear maps between modules with a finite bases
to matrices. This defines a linear equivalence between linear maps
between finite-dimensional vector spaces and matrices indexed by
the respective bases.
## Main definitions
In the list below, and in all this file, `R` is a commutative ring (semiring
is sometimes enough), `M` and its variations are `R`-modules, `ι`, `κ`, `n` and `m` are finite
types used for indexing.
* `LinearMap.toMatrix`: given bases `v₁ : ι → M₁` and `v₂ : κ → M₂`,
the `R`-linear equivalence from `M₁ →ₗ[R] M₂` to `Matrix κ ι R`
* `Matrix.toLin`: the inverse of `LinearMap.toMatrix`
* `LinearMap.toMatrix'`: the `R`-linear equivalence from `(m → R) →ₗ[R] (n → R)`
to `Matrix m n R` (with the standard basis on `m → R` and `n → R`)
* `Matrix.toLin'`: the inverse of `LinearMap.toMatrix'`
* `algEquivMatrix`: given a basis indexed by `n`, the `R`-algebra equivalence between
`R`-endomorphisms of `M` and `Matrix n n R`
## Issues
This file was originally written without attention to non-commutative rings,
and so mostly only works in the commutative setting. This should be fixed.
In particular, `Matrix.mulVec` gives us a linear equivalence
`Matrix m n R ≃ₗ[R] (n → R) →ₗ[Rᵐᵒᵖ] (m → R)`
while `Matrix.vecMul` gives us a linear equivalence
`Matrix m n R ≃ₗ[Rᵐᵒᵖ] (m → R) →ₗ[R] (n → R)`.
At present, the first equivalence is developed in detail but only for commutative rings
(and we omit the distinction between `Rᵐᵒᵖ` and `R`),
while the second equivalence is developed only in brief, but for not-necessarily-commutative rings.
Naming is slightly inconsistent between the two developments.
In the original (commutative) development `linear` is abbreviated to `lin`,
although this is not consistent with the rest of mathlib.
In the new (non-commutative) development `linear` is not abbreviated, and declarations use `_right`
to indicate they use the right action of matrices on vectors (via `Matrix.vecMul`).
When the two developments are made uniform, the names should be made uniform, too,
by choosing between `linear` and `lin` consistently,
and (presumably) adding `_left` where necessary.
## Tags
linear_map, matrix, linear_equiv, diagonal, det, trace
-/
noncomputable section
open LinearMap Matrix Set Submodule
section ToMatrixRight
variable {R : Type*} [Semiring R]
variable {l m n : Type*}
/-- `Matrix.vecMul M` is a linear map. -/
def Matrix.vecMulLinear [Fintype m] (M : Matrix m n R) : (m → R) →ₗ[R] n → R where
toFun x := x ᵥ* M
map_add' _ _ := funext fun _ ↦ add_dotProduct _ _ _
map_smul' _ _ := funext fun _ ↦ smul_dotProduct _ _ _
@[simp] theorem Matrix.vecMulLinear_apply [Fintype m] (M : Matrix m n R) (x : m → R) :
M.vecMulLinear x = x ᵥ* M := rfl
theorem Matrix.coe_vecMulLinear [Fintype m] (M : Matrix m n R) :
(M.vecMulLinear : _ → _) = M.vecMul := rfl
variable [Fintype m]
theorem range_vecMulLinear (M : Matrix m n R) :
LinearMap.range M.vecMulLinear = span R (range M.row) := by
letI := Classical.decEq m
simp_rw [range_eq_map, ← iSup_range_single, Submodule.map_iSup, range_eq_map, ←
Ideal.span_singleton_one, Ideal.span, Submodule.map_span, image_image, image_singleton,
Matrix.vecMulLinear_apply, iSup_span, range_eq_iUnion, iUnion_singleton_eq_range,
LinearMap.single, LinearMap.coe_mk, AddHom.coe_mk, row_def]
unfold vecMul
simp_rw [single_dotProduct, one_mul]
theorem Matrix.vecMul_injective_iff {R : Type*} [Ring R] {M : Matrix m n R} :
Function.Injective M.vecMul ↔ LinearIndependent R M.row := by
rw [← coe_vecMulLinear]
simp only [← LinearMap.ker_eq_bot, Fintype.linearIndependent_iff, Submodule.eq_bot_iff,
LinearMap.mem_ker, vecMulLinear_apply, row_def]
refine ⟨fun h c h0 ↦ congr_fun <| h c ?_, fun h c h0 ↦ funext <| h c ?_⟩
· rw [← h0]
ext i
simp [vecMul, dotProduct]
· rw [← h0]
ext j
simp [vecMul, dotProduct]
lemma Matrix.linearIndependent_rows_of_isUnit {R : Type*} [Ring R] {A : Matrix m m R}
[DecidableEq m] (ha : IsUnit A) : LinearIndependent R A.row := by
rw [← Matrix.vecMul_injective_iff]
exact Matrix.vecMul_injective_of_isUnit ha
section
variable [DecidableEq m]
/-- Linear maps `(m → R) →ₗ[R] (n → R)` are linearly equivalent over `Rᵐᵒᵖ` to `Matrix m n R`,
by having matrices act by right multiplication.
-/
def LinearMap.toMatrixRight' : ((m → R) →ₗ[R] n → R) ≃ₗ[Rᵐᵒᵖ] Matrix m n R where
toFun f i j := f (single R (fun _ ↦ R) i 1) j
invFun := Matrix.vecMulLinear
right_inv M := by
ext i j
simp
left_inv f := by
apply (Pi.basisFun R m).ext
intro j; ext i
simp
map_add' f g := by
ext i j
simp only [Pi.add_apply, LinearMap.add_apply, Matrix.add_apply]
map_smul' c f := by
ext i j
simp only [Pi.smul_apply, LinearMap.smul_apply, RingHom.id_apply, Matrix.smul_apply]
/-- A `Matrix m n R` is linearly equivalent over `Rᵐᵒᵖ` to a linear map `(m → R) →ₗ[R] (n → R)`,
by having matrices act by right multiplication. -/
abbrev Matrix.toLinearMapRight' [DecidableEq m] : Matrix m n R ≃ₗ[Rᵐᵒᵖ] (m → R) →ₗ[R] n → R :=
LinearEquiv.symm LinearMap.toMatrixRight'
@[simp]
theorem Matrix.toLinearMapRight'_apply (M : Matrix m n R) (v : m → R) :
(Matrix.toLinearMapRight') M v = v ᵥ* M := rfl
@[simp]
theorem Matrix.toLinearMapRight'_mul [Fintype l] [DecidableEq l] (M : Matrix l m R)
(N : Matrix m n R) :
Matrix.toLinearMapRight' (M * N) =
(Matrix.toLinearMapRight' N).comp (Matrix.toLinearMapRight' M) :=
LinearMap.ext fun _x ↦ (vecMul_vecMul _ M N).symm
theorem Matrix.toLinearMapRight'_mul_apply [Fintype l] [DecidableEq l] (M : Matrix l m R)
(N : Matrix m n R) (x) :
Matrix.toLinearMapRight' (M * N) x =
Matrix.toLinearMapRight' N (Matrix.toLinearMapRight' M x) :=
(vecMul_vecMul _ M N).symm
@[simp]
theorem Matrix.toLinearMapRight'_one :
Matrix.toLinearMapRight' (1 : Matrix m m R) = LinearMap.id := by
ext
simp [Module.End.one_apply]
/-- If `M` and `M'` are each other's inverse matrices, they provide an equivalence between `n → A`
and `m → A` corresponding to `M.vecMul` and `M'.vecMul`. -/
@[simps]
def Matrix.toLinearEquivRight'OfInv [Fintype n] [DecidableEq n] {M : Matrix m n R}
{M' : Matrix n m R} (hMM' : M * M' = 1) (hM'M : M' * M = 1) : (n → R) ≃ₗ[R] m → R :=
{ LinearMap.toMatrixRight'.symm M' with
toFun := Matrix.toLinearMapRight' M'
invFun := Matrix.toLinearMapRight' M
left_inv := fun x ↦ by
rw [← Matrix.toLinearMapRight'_mul_apply, hM'M, Matrix.toLinearMapRight'_one, id_apply]
right_inv := fun x ↦ by
rw [← Matrix.toLinearMapRight'_mul_apply, hMM', Matrix.toLinearMapRight'_one, id_apply] }
end
end ToMatrixRight
/-!
From this point on, we only work with commutative rings,
and fail to distinguish between `Rᵐᵒᵖ` and `R`.
This should eventually be remedied.
-/
section mulVec
variable {R : Type*} [CommSemiring R]
variable {k l m n : Type*}
/-- `Matrix.mulVec M` is a linear map. -/
def Matrix.mulVecLin [Fintype n] (M : Matrix m n R) : (n → R) →ₗ[R] m → R where
toFun := M.mulVec
map_add' _ _ := funext fun _ ↦ dotProduct_add _ _ _
map_smul' _ _ := funext fun _ ↦ dotProduct_smul _ _ _
theorem Matrix.coe_mulVecLin [Fintype n] (M : Matrix m n R) :
(M.mulVecLin : _ → _) = M.mulVec := rfl
@[simp]
theorem Matrix.mulVecLin_apply [Fintype n] (M : Matrix m n R) (v : n → R) :
M.mulVecLin v = M *ᵥ v :=
rfl
@[simp]
theorem Matrix.mulVecLin_zero [Fintype n] : Matrix.mulVecLin (0 : Matrix m n R) = 0 :=
LinearMap.ext zero_mulVec
@[simp]
theorem Matrix.mulVecLin_add [Fintype n] (M N : Matrix m n R) :
(M + N).mulVecLin = M.mulVecLin + N.mulVecLin :=
LinearMap.ext fun _ ↦ add_mulVec _ _ _
@[simp] theorem Matrix.mulVecLin_transpose [Fintype m] (M : Matrix m n R) :
Mᵀ.mulVecLin = M.vecMulLinear := by
ext; simp [mulVec_transpose]
@[simp] theorem Matrix.vecMulLinear_transpose [Fintype n] (M : Matrix m n R) :
Mᵀ.vecMulLinear = M.mulVecLin := by
ext; simp [vecMul_transpose]
theorem Matrix.mulVecLin_submatrix [Fintype n] [Fintype l] (f₁ : m → k) (e₂ : n ≃ l)
(M : Matrix k l R) :
(M.submatrix f₁ e₂).mulVecLin = funLeft R R f₁ ∘ₗ M.mulVecLin ∘ₗ funLeft _ _ e₂.symm :=
LinearMap.ext fun _ ↦ submatrix_mulVec_equiv _ _ _ _
/-- A variant of `Matrix.mulVecLin_submatrix` that keeps around `LinearEquiv`s. -/
theorem Matrix.mulVecLin_reindex [Fintype n] [Fintype l] (e₁ : k ≃ m) (e₂ : l ≃ n)
(M : Matrix k l R) :
(reindex e₁ e₂ M).mulVecLin =
↑(LinearEquiv.funCongrLeft R R e₁.symm) ∘ₗ
M.mulVecLin ∘ₗ ↑(LinearEquiv.funCongrLeft R R e₂) :=
Matrix.mulVecLin_submatrix _ _ _
variable [Fintype n]
@[simp]
theorem Matrix.mulVecLin_one [DecidableEq n] :
Matrix.mulVecLin (1 : Matrix n n R) = LinearMap.id := by
ext; simp [Matrix.one_apply, Pi.single_apply, eq_comm]
@[simp]
theorem Matrix.mulVecLin_mul [Fintype m] (M : Matrix l m R) (N : Matrix m n R) :
Matrix.mulVecLin (M * N) = (Matrix.mulVecLin M).comp (Matrix.mulVecLin N) :=
LinearMap.ext fun _ ↦ (mulVec_mulVec _ _ _).symm
theorem Matrix.ker_mulVecLin_eq_bot_iff {M : Matrix m n R} :
(LinearMap.ker M.mulVecLin) = ⊥ ↔ ∀ v, M *ᵥ v = 0 → v = 0 := by
simp only [Submodule.eq_bot_iff, LinearMap.mem_ker, Matrix.mulVecLin_apply]
theorem Matrix.range_mulVecLin (M : Matrix m n R) :
LinearMap.range M.mulVecLin = span R (range M.col) := by
rw [← vecMulLinear_transpose, range_vecMulLinear, row_transpose]
theorem Matrix.mulVec_injective_iff {R : Type*} [CommRing R] {M : Matrix m n R} :
Function.Injective M.mulVec ↔ LinearIndependent R M.col := by
change Function.Injective (fun x ↦ _) ↔ _
simp_rw [← M.vecMul_transpose, vecMul_injective_iff, row_transpose]
lemma Matrix.linearIndependent_cols_of_isUnit {R : Type*} [CommRing R] [Fintype m]
{A : Matrix m m R} [DecidableEq m] (ha : IsUnit A) :
LinearIndependent R A.col := by
rw [← Matrix.mulVec_injective_iff]
exact Matrix.mulVec_injective_of_isUnit ha
end mulVec
section ToMatrix'
variable {R : Type*} [CommSemiring R]
variable {k l m n : Type*} [DecidableEq n] [Fintype n]
/-- Linear maps `(n → R) →ₗ[R] (m → R)` are linearly equivalent to `Matrix m n R`. -/
def LinearMap.toMatrix' : ((n → R) →ₗ[R] m → R) ≃ₗ[R] Matrix m n R where
toFun f := of fun i j ↦ f (Pi.single j 1) i
invFun := Matrix.mulVecLin
right_inv M := by
ext i j
simp only [Matrix.mulVec_single_one, Matrix.mulVecLin_apply, of_apply, transpose_apply]
left_inv f := by
apply (Pi.basisFun R n).ext
intro j; ext i
simp only [Pi.basisFun_apply, Matrix.mulVec_single_one,
Matrix.mulVecLin_apply, of_apply, transpose_apply]
map_add' f g := by
ext i j
simp only [Pi.add_apply, LinearMap.add_apply, of_apply, Matrix.add_apply]
map_smul' c f := by
ext i j
simp only [Pi.smul_apply, LinearMap.smul_apply, RingHom.id_apply, of_apply, Matrix.smul_apply]
/-- A `Matrix m n R` is linearly equivalent to a linear map `(n → R) →ₗ[R] (m → R)`.
Note that the forward-direction does not require `DecidableEq` and is `Matrix.vecMulLin`. -/
def Matrix.toLin' : Matrix m n R ≃ₗ[R] (n → R) →ₗ[R] m → R :=
LinearMap.toMatrix'.symm
theorem Matrix.toLin'_apply' (M : Matrix m n R) : Matrix.toLin' M = M.mulVecLin :=
rfl
@[simp]
theorem LinearMap.toMatrix'_symm :
(LinearMap.toMatrix'.symm : Matrix m n R ≃ₗ[R] _) = Matrix.toLin' :=
rfl
@[simp]
theorem Matrix.toLin'_symm :
(Matrix.toLin'.symm : ((n → R) →ₗ[R] m → R) ≃ₗ[R] _) = LinearMap.toMatrix' :=
rfl
@[simp]
theorem LinearMap.toMatrix'_toLin' (M : Matrix m n R) : LinearMap.toMatrix' (Matrix.toLin' M) = M :=
LinearMap.toMatrix'.apply_symm_apply M
@[simp]
theorem Matrix.toLin'_toMatrix' (f : (n → R) →ₗ[R] m → R) :
Matrix.toLin' (LinearMap.toMatrix' f) = f :=
Matrix.toLin'.apply_symm_apply f
@[simp]
theorem LinearMap.toMatrix'_apply (f : (n → R) →ₗ[R] m → R) (i j) :
LinearMap.toMatrix' f i j = f (fun j' ↦ if j' = j then 1 else 0) i := by
simp only [LinearMap.toMatrix', LinearEquiv.coe_mk, of_apply]
congr! with i
split_ifs with h
· rw [h, Pi.single_eq_same]
apply Pi.single_eq_of_ne h
@[simp]
theorem Matrix.toLin'_apply (M : Matrix m n R) (v : n → R) : Matrix.toLin' M v = M *ᵥ v :=
rfl
@[simp]
theorem Matrix.toLin'_one : Matrix.toLin' (1 : Matrix n n R) = LinearMap.id :=
Matrix.mulVecLin_one
@[simp]
theorem LinearMap.toMatrix'_id : LinearMap.toMatrix' (LinearMap.id : (n → R) →ₗ[R] n → R) = 1 := by
ext
rw [Matrix.one_apply, LinearMap.toMatrix'_apply, id_apply]
@[simp]
theorem LinearMap.toMatrix'_one : LinearMap.toMatrix' (1 : (n → R) →ₗ[R] n → R) = 1 :=
LinearMap.toMatrix'_id
@[simp]
theorem Matrix.toLin'_mul [Fintype m] [DecidableEq m] (M : Matrix l m R) (N : Matrix m n R) :
Matrix.toLin' (M * N) = (Matrix.toLin' M).comp (Matrix.toLin' N) :=
Matrix.mulVecLin_mul _ _
@[simp]
theorem Matrix.toLin'_submatrix [Fintype l] [DecidableEq l] (f₁ : m → k) (e₂ : n ≃ l)
(M : Matrix k l R) :
Matrix.toLin' (M.submatrix f₁ e₂) =
funLeft R R f₁ ∘ₗ (Matrix.toLin' M) ∘ₗ funLeft _ _ e₂.symm :=
Matrix.mulVecLin_submatrix _ _ _
/-- A variant of `Matrix.toLin'_submatrix` that keeps around `LinearEquiv`s. -/
theorem Matrix.toLin'_reindex [Fintype l] [DecidableEq l] (e₁ : k ≃ m) (e₂ : l ≃ n)
(M : Matrix k l R) :
Matrix.toLin' (reindex e₁ e₂ M) =
↑(LinearEquiv.funCongrLeft R R e₁.symm) ∘ₗ (Matrix.toLin' M) ∘ₗ
↑(LinearEquiv.funCongrLeft R R e₂) :=
Matrix.mulVecLin_reindex _ _ _
/-- Shortcut lemma for `Matrix.toLin'_mul` and `LinearMap.comp_apply` -/
theorem Matrix.toLin'_mul_apply [Fintype m] [DecidableEq m] (M : Matrix l m R) (N : Matrix m n R)
(x) : Matrix.toLin' (M * N) x = Matrix.toLin' M (Matrix.toLin' N x) := by
rw [Matrix.toLin'_mul, LinearMap.comp_apply]
theorem LinearMap.toMatrix'_comp [Fintype l] [DecidableEq l] (f : (n → R) →ₗ[R] m → R)
(g : (l → R) →ₗ[R] n → R) :
LinearMap.toMatrix' (f.comp g) = LinearMap.toMatrix' f * LinearMap.toMatrix' g := by
suffices f.comp g = Matrix.toLin' (LinearMap.toMatrix' f * LinearMap.toMatrix' g) by
rw [this, LinearMap.toMatrix'_toLin']
rw [Matrix.toLin'_mul, Matrix.toLin'_toMatrix', Matrix.toLin'_toMatrix']
theorem LinearMap.toMatrix'_mul [Fintype m] [DecidableEq m] (f g : (m → R) →ₗ[R] m → R) :
LinearMap.toMatrix' (f * g) = LinearMap.toMatrix' f * LinearMap.toMatrix' g :=
LinearMap.toMatrix'_comp f g
@[simp]
theorem LinearMap.toMatrix'_algebraMap (x : R) :
LinearMap.toMatrix' (algebraMap R (Module.End R (n → R)) x) = scalar n x := by
simp [Module.algebraMap_end_eq_smul_id, smul_eq_diagonal_mul]
theorem Matrix.ker_toLin'_eq_bot_iff {M : Matrix n n R} :
LinearMap.ker (Matrix.toLin' M) = ⊥ ↔ ∀ v, M *ᵥ v = 0 → v = 0 :=
Matrix.ker_mulVecLin_eq_bot_iff
theorem Matrix.range_toLin' (M : Matrix m n R) :
LinearMap.range (Matrix.toLin' M) = span R (range M.col) :=
Matrix.range_mulVecLin _
/-- If `M` and `M'` are each other's inverse matrices, they provide an equivalence between `m → A`
and `n → A` corresponding to `M.mulVec` and `M'.mulVec`. -/
@[simps]
def Matrix.toLin'OfInv [Fintype m] [DecidableEq m] {M : Matrix m n R} {M' : Matrix n m R}
(hMM' : M * M' = 1) (hM'M : M' * M = 1) : (m → R) ≃ₗ[R] n → R :=
{ Matrix.toLin' M' with
toFun := Matrix.toLin' M'
invFun := Matrix.toLin' M
left_inv := fun x ↦ by rw [← Matrix.toLin'_mul_apply, hMM', Matrix.toLin'_one, id_apply]
right_inv := fun x ↦ by
rw [← Matrix.toLin'_mul_apply, hM'M, Matrix.toLin'_one, id_apply] }
/-- Linear maps `(n → R) →ₗ[R] (n → R)` are algebra equivalent to `Matrix n n R`. -/
def LinearMap.toMatrixAlgEquiv' : ((n → R) →ₗ[R] n → R) ≃ₐ[R] Matrix n n R :=
AlgEquiv.ofLinearEquiv LinearMap.toMatrix' LinearMap.toMatrix'_one LinearMap.toMatrix'_mul
/-- A `Matrix n n R` is algebra equivalent to a linear map `(n → R) →ₗ[R] (n → R)`. -/
def Matrix.toLinAlgEquiv' : Matrix n n R ≃ₐ[R] (n → R) →ₗ[R] n → R :=
LinearMap.toMatrixAlgEquiv'.symm
@[simp]
theorem LinearMap.toMatrixAlgEquiv'_symm :
(LinearMap.toMatrixAlgEquiv'.symm : Matrix n n R ≃ₐ[R] _) = Matrix.toLinAlgEquiv' :=
rfl
@[simp]
theorem Matrix.toLinAlgEquiv'_symm :
(Matrix.toLinAlgEquiv'.symm : ((n → R) →ₗ[R] n → R) ≃ₐ[R] _) = LinearMap.toMatrixAlgEquiv' :=
rfl
@[simp]
theorem LinearMap.toMatrixAlgEquiv'_toLinAlgEquiv' (M : Matrix n n R) :
LinearMap.toMatrixAlgEquiv' (Matrix.toLinAlgEquiv' M) = M :=
LinearMap.toMatrixAlgEquiv'.apply_symm_apply M
@[simp]
theorem Matrix.toLinAlgEquiv'_toMatrixAlgEquiv' (f : (n → R) →ₗ[R] n → R) :
Matrix.toLinAlgEquiv' (LinearMap.toMatrixAlgEquiv' f) = f :=
Matrix.toLinAlgEquiv'.apply_symm_apply f
@[simp]
theorem LinearMap.toMatrixAlgEquiv'_apply (f : (n → R) →ₗ[R] n → R) (i j) :
LinearMap.toMatrixAlgEquiv' f i j = f (fun j' ↦ if j' = j then 1 else 0) i := by
simp [LinearMap.toMatrixAlgEquiv']
@[simp]
theorem Matrix.toLinAlgEquiv'_apply (M : Matrix n n R) (v : n → R) :
Matrix.toLinAlgEquiv' M v = M *ᵥ v :=
rfl
theorem Matrix.toLinAlgEquiv'_one : Matrix.toLinAlgEquiv' (1 : Matrix n n R) = LinearMap.id :=
Matrix.toLin'_one
@[simp]
theorem LinearMap.toMatrixAlgEquiv'_id :
LinearMap.toMatrixAlgEquiv' (LinearMap.id : (n → R) →ₗ[R] n → R) = 1 :=
LinearMap.toMatrix'_id
theorem LinearMap.toMatrixAlgEquiv'_comp (f g : (n → R) →ₗ[R] n → R) :
LinearMap.toMatrixAlgEquiv' (f.comp g) =
LinearMap.toMatrixAlgEquiv' f * LinearMap.toMatrixAlgEquiv' g :=
LinearMap.toMatrix'_comp _ _
theorem LinearMap.toMatrixAlgEquiv'_mul (f g : (n → R) →ₗ[R] n → R) :
LinearMap.toMatrixAlgEquiv' (f * g) =
LinearMap.toMatrixAlgEquiv' f * LinearMap.toMatrixAlgEquiv' g :=
LinearMap.toMatrixAlgEquiv'_comp f g
end ToMatrix'
section ToMatrix
section Finite
variable {R : Type*} [CommSemiring R]
variable {l m n : Type*} [Fintype n] [Finite m] [DecidableEq n]
variable {M₁ M₂ : Type*} [AddCommMonoid M₁] [AddCommMonoid M₂] [Module R M₁] [Module R M₂]
variable (v₁ : Basis n R M₁) (v₂ : Basis m R M₂)
/-- Given bases of two modules `M₁` and `M₂` over a commutative ring `R`, we get a linear
equivalence between linear maps `M₁ →ₗ M₂` and matrices over `R` indexed by the bases. -/
def LinearMap.toMatrix : (M₁ →ₗ[R] M₂) ≃ₗ[R] Matrix m n R :=
LinearEquiv.trans (LinearEquiv.arrowCongr v₁.equivFun v₂.equivFun) LinearMap.toMatrix'
/-- `LinearMap.toMatrix'` is a particular case of `LinearMap.toMatrix`, for the standard basis
`Pi.basisFun R n`. -/
theorem LinearMap.toMatrix_eq_toMatrix' :
LinearMap.toMatrix (Pi.basisFun R n) (Pi.basisFun R n) = LinearMap.toMatrix' :=
rfl
/-- Given bases of two modules `M₁` and `M₂` over a commutative ring `R`, we get a linear
equivalence between matrices over `R` indexed by the bases and linear maps `M₁ →ₗ M₂`. -/
def Matrix.toLin : Matrix m n R ≃ₗ[R] M₁ →ₗ[R] M₂ :=
(LinearMap.toMatrix v₁ v₂).symm
/-- `Matrix.toLin'` is a particular case of `Matrix.toLin`, for the standard basis
`Pi.basisFun R n`. -/
theorem Matrix.toLin_eq_toLin' : Matrix.toLin (Pi.basisFun R n) (Pi.basisFun R m) = Matrix.toLin' :=
rfl
@[simp]
theorem LinearMap.toMatrix_symm : (LinearMap.toMatrix v₁ v₂).symm = Matrix.toLin v₁ v₂ :=
rfl
@[simp]
theorem Matrix.toLin_symm : (Matrix.toLin v₁ v₂).symm = LinearMap.toMatrix v₁ v₂ :=
rfl
@[simp]
theorem Matrix.toLin_toMatrix (f : M₁ →ₗ[R] M₂) :
Matrix.toLin v₁ v₂ (LinearMap.toMatrix v₁ v₂ f) = f := by
rw [← Matrix.toLin_symm, LinearEquiv.apply_symm_apply]
@[simp]
theorem LinearMap.toMatrix_toLin (M : Matrix m n R) :
LinearMap.toMatrix v₁ v₂ (Matrix.toLin v₁ v₂ M) = M := by
rw [← Matrix.toLin_symm, LinearEquiv.symm_apply_apply]
theorem LinearMap.toMatrix_apply (f : M₁ →ₗ[R] M₂) (i : m) (j : n) :
LinearMap.toMatrix v₁ v₂ f i j = v₂.repr (f (v₁ j)) i := by
rw [LinearMap.toMatrix, LinearEquiv.trans_apply, LinearMap.toMatrix'_apply,
LinearEquiv.arrowCongr_apply, Basis.equivFun_symm_apply, Finset.sum_eq_single j, if_pos rfl,
one_smul, Basis.equivFun_apply]
· intro j' _ hj'
rw [if_neg hj', zero_smul]
· intro hj
have := Finset.mem_univ j
contradiction
theorem LinearMap.toMatrix_transpose_apply (f : M₁ →ₗ[R] M₂) (j : n) :
(LinearMap.toMatrix v₁ v₂ f)ᵀ j = v₂.repr (f (v₁ j)) :=
funext fun i ↦ f.toMatrix_apply _ _ i j
theorem LinearMap.toMatrix_apply' (f : M₁ →ₗ[R] M₂) (i : m) (j : n) :
LinearMap.toMatrix v₁ v₂ f i j = v₂.repr (f (v₁ j)) i :=
LinearMap.toMatrix_apply v₁ v₂ f i j
theorem LinearMap.toMatrix_transpose_apply' (f : M₁ →ₗ[R] M₂) (j : n) :
(LinearMap.toMatrix v₁ v₂ f)ᵀ j = v₂.repr (f (v₁ j)) :=
LinearMap.toMatrix_transpose_apply v₁ v₂ f j
/-- This will be a special case of `LinearMap.toMatrix_id_eq_basis_toMatrix`. -/
theorem LinearMap.toMatrix_id : LinearMap.toMatrix v₁ v₁ id = 1 := by
ext i j
simp [LinearMap.toMatrix_apply, Matrix.one_apply, Finsupp.single_apply, eq_comm]
@[simp]
theorem LinearMap.toMatrix_one : LinearMap.toMatrix v₁ v₁ 1 = 1 :=
LinearMap.toMatrix_id v₁
@[simp]
lemma LinearMap.toMatrix_singleton {ι : Type*} [Unique ι] (f : R →ₗ[R] R) (i j : ι) :
f.toMatrix (.singleton ι R) (.singleton ι R) i j = f 1 := by
simp [toMatrix, Subsingleton.elim j default]
@[simp]
theorem Matrix.toLin_one : Matrix.toLin v₁ v₁ 1 = LinearMap.id := by
rw [← LinearMap.toMatrix_id v₁, Matrix.toLin_toMatrix]
theorem LinearMap.toMatrix_reindexRange [DecidableEq M₁] (f : M₁ →ₗ[R] M₂) (k : m) (i : n) :
LinearMap.toMatrix v₁.reindexRange v₂.reindexRange f ⟨v₂ k, Set.mem_range_self k⟩
⟨v₁ i, Set.mem_range_self i⟩ =
LinearMap.toMatrix v₁ v₂ f k i := by
simp_rw [LinearMap.toMatrix_apply, Basis.reindexRange_self, Basis.reindexRange_repr]
@[simp]
theorem LinearMap.toMatrix_algebraMap (x : R) :
LinearMap.toMatrix v₁ v₁ (algebraMap R (Module.End R M₁) x) = scalar n x := by
simp [Module.algebraMap_end_eq_smul_id, LinearMap.toMatrix_id, smul_eq_diagonal_mul]
theorem LinearMap.toMatrix_mulVec_repr (f : M₁ →ₗ[R] M₂) (x : M₁) :
LinearMap.toMatrix v₁ v₂ f *ᵥ v₁.repr x = v₂.repr (f x) := by
ext i
rw [← Matrix.toLin'_apply, LinearMap.toMatrix, LinearEquiv.trans_apply, Matrix.toLin'_toMatrix',
LinearEquiv.arrowCongr_apply, v₂.equivFun_apply]
congr
exact v₁.equivFun.symm_apply_apply x
@[simp]
theorem LinearMap.toMatrix_basis_equiv [Fintype l] [DecidableEq l] (b : Basis l R M₁)
(b' : Basis l R M₂) :
LinearMap.toMatrix b' b (b'.equiv b (Equiv.refl l) : M₂ →ₗ[R] M₁) = 1 := by
ext i j
simp [LinearMap.toMatrix_apply, Matrix.one_apply, Finsupp.single_apply, eq_comm]
theorem LinearMap.toMatrix_smulBasis_left {G} [Group G] [DistribMulAction G M₁]
[SMulCommClass G R M₁] (g : G) (f : M₁ →ₗ[R] M₂) :
LinearMap.toMatrix (g • v₁) v₂ f =
LinearMap.toMatrix v₁ v₂ (f ∘ₗ DistribMulAction.toLinearMap _ _ g) := by
ext
rw [LinearMap.toMatrix_apply, LinearMap.toMatrix_apply]
dsimp
theorem LinearMap.toMatrix_smulBasis_right {G} [Group G] [DistribMulAction G M₂]
[SMulCommClass G R M₂] (g : G) (f : M₁ →ₗ[R] M₂) :
LinearMap.toMatrix v₁ (g • v₂) f =
LinearMap.toMatrix v₁ v₂ (DistribMulAction.toLinearMap _ _ g⁻¹ ∘ₗ f) := by
ext
rw [LinearMap.toMatrix_apply, LinearMap.toMatrix_apply]
dsimp
end Finite
variable {R : Type*} [CommSemiring R]
variable {l m n : Type*} [Fintype n] [Fintype m] [DecidableEq n]
variable {M₁ M₂ : Type*} [AddCommMonoid M₁] [AddCommMonoid M₂] [Module R M₁] [Module R M₂]
variable (v₁ : Basis n R M₁) (v₂ : Basis m R M₂)
theorem Matrix.toLin_apply (M : Matrix m n R) (v : M₁) :
Matrix.toLin v₁ v₂ M v = ∑ j, (M *ᵥ v₁.repr v) j • v₂ j :=
show v₂.equivFun.symm (Matrix.toLin' M (v₁.repr v)) = _ by
rw [Matrix.toLin'_apply, v₂.equivFun_symm_apply]
@[simp]
theorem Matrix.toLin_self (M : Matrix m n R) (i : n) :
Matrix.toLin v₁ v₂ M (v₁ i) = ∑ j, M j i • v₂ j := by
rw [Matrix.toLin_apply, Finset.sum_congr rfl fun j _hj ↦ ?_]
rw [Basis.repr_self, Matrix.mulVec, dotProduct, Finset.sum_eq_single i, Finsupp.single_eq_same,
mul_one]
· intro i' _ i'_ne
rw [Finsupp.single_eq_of_ne i'_ne.symm, mul_zero]
· intros
have := Finset.mem_univ i
contradiction
variable {M₃ : Type*} [AddCommMonoid M₃] [Module R M₃] (v₃ : Basis l R M₃)
theorem LinearMap.toMatrix_comp [Finite l] [DecidableEq m] (f : M₂ →ₗ[R] M₃) (g : M₁ →ₗ[R] M₂) :
LinearMap.toMatrix v₁ v₃ (f.comp g) =
LinearMap.toMatrix v₂ v₃ f * LinearMap.toMatrix v₁ v₂ g := by
simp_rw [LinearMap.toMatrix, LinearEquiv.trans_apply, LinearEquiv.arrowCongr_comp _ v₂.equivFun,
LinearMap.toMatrix'_comp]
theorem LinearMap.toMatrix_mul (f g : M₁ →ₗ[R] M₁) :
LinearMap.toMatrix v₁ v₁ (f * g) = LinearMap.toMatrix v₁ v₁ f * LinearMap.toMatrix v₁ v₁ g := by
rw [Module.End.mul_eq_comp, LinearMap.toMatrix_comp v₁ v₁ v₁ f g]
lemma LinearMap.toMatrix_pow (f : M₁ →ₗ[R] M₁) (k : ℕ) :
(toMatrix v₁ v₁ f) ^ k = toMatrix v₁ v₁ (f ^ k) := by
induction k with
| zero => simp
| succ k ih => rw [pow_succ, pow_succ, ih, ← toMatrix_mul]
theorem Matrix.toLin_mul [Finite l] [DecidableEq m] (A : Matrix l m R) (B : Matrix m n R) :
Matrix.toLin v₁ v₃ (A * B) = (Matrix.toLin v₂ v₃ A).comp (Matrix.toLin v₁ v₂ B) := by
apply (LinearMap.toMatrix v₁ v₃).injective
haveI : DecidableEq l := fun _ _ ↦ Classical.propDecidable _
rw [LinearMap.toMatrix_comp v₁ v₂ v₃]
repeat' rw [LinearMap.toMatrix_toLin]
/-- Shortcut lemma for `Matrix.toLin_mul` and `LinearMap.comp_apply`. -/
theorem Matrix.toLin_mul_apply [Finite l] [DecidableEq m] (A : Matrix l m R) (B : Matrix m n R)
(x) : Matrix.toLin v₁ v₃ (A * B) x = (Matrix.toLin v₂ v₃ A) (Matrix.toLin v₁ v₂ B x) := by
rw [Matrix.toLin_mul v₁ v₂, LinearMap.comp_apply]
/-- If `M` and `M` are each other's inverse matrices, `Matrix.toLin M` and `Matrix.toLin M'`
form a linear equivalence. -/
@[simps]
def Matrix.toLinOfInv [DecidableEq m] {M : Matrix m n R} {M' : Matrix n m R} (hMM' : M * M' = 1)
(hM'M : M' * M = 1) : M₁ ≃ₗ[R] M₂ :=
{ Matrix.toLin v₁ v₂ M with
toFun := Matrix.toLin v₁ v₂ M
invFun := Matrix.toLin v₂ v₁ M'
left_inv := fun x ↦ by rw [← Matrix.toLin_mul_apply, hM'M, Matrix.toLin_one, id_apply]
right_inv := fun x ↦ by
rw [← Matrix.toLin_mul_apply, hMM', Matrix.toLin_one, id_apply] }
/-- Given a basis of a module `M₁` over a commutative ring `R`, we get an algebra
equivalence between linear maps `M₁ →ₗ M₁` and square matrices over `R` indexed by the basis. -/
def LinearMap.toMatrixAlgEquiv : (M₁ →ₗ[R] M₁) ≃ₐ[R] Matrix n n R :=
AlgEquiv.ofLinearEquiv
(LinearMap.toMatrix v₁ v₁) (LinearMap.toMatrix_one v₁) (LinearMap.toMatrix_mul v₁)
/-- Given a basis of a module `M₁` over a commutative ring `R`, we get an algebra
equivalence between square matrices over `R` indexed by the basis and linear maps `M₁ →ₗ M₁`. -/
def Matrix.toLinAlgEquiv : Matrix n n R ≃ₐ[R] M₁ →ₗ[R] M₁ :=
(LinearMap.toMatrixAlgEquiv v₁).symm
@[simp]
theorem LinearMap.toMatrixAlgEquiv_symm :
(LinearMap.toMatrixAlgEquiv v₁).symm = Matrix.toLinAlgEquiv v₁ :=
rfl
@[simp]
theorem Matrix.toLinAlgEquiv_symm :
(Matrix.toLinAlgEquiv v₁).symm = LinearMap.toMatrixAlgEquiv v₁ :=
rfl
@[simp]
theorem Matrix.toLinAlgEquiv_toMatrixAlgEquiv (f : M₁ →ₗ[R] M₁) :
Matrix.toLinAlgEquiv v₁ (LinearMap.toMatrixAlgEquiv v₁ f) = f := by
rw [← Matrix.toLinAlgEquiv_symm, AlgEquiv.apply_symm_apply]
@[simp]
theorem LinearMap.toMatrixAlgEquiv_toLinAlgEquiv (M : Matrix n n R) :
LinearMap.toMatrixAlgEquiv v₁ (Matrix.toLinAlgEquiv v₁ M) = M := by
rw [← Matrix.toLinAlgEquiv_symm, AlgEquiv.symm_apply_apply]
| theorem LinearMap.toMatrixAlgEquiv_apply (f : M₁ →ₗ[R] M₁) (i j : n) :
LinearMap.toMatrixAlgEquiv v₁ f i j = v₁.repr (f (v₁ j)) i := by
simp [LinearMap.toMatrixAlgEquiv, LinearMap.toMatrix_apply]
| Mathlib/LinearAlgebra/Matrix/ToLin.lean | 701 | 703 |
/-
Copyright (c) 2019 Amelia Livingston. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Amelia Livingston, Bryan Gin-ge Chen, Patrick Massot, Wen Yang, Johan Commelin
-/
import Mathlib.Data.Set.Finite.Range
import Mathlib.Order.Partition.Finpartition
/-!
# Equivalence relations: partitions
This file comprises properties of equivalence relations viewed as partitions.
There are two implementations of partitions here:
* A collection `c : Set (Set α)` of sets is a partition of `α` if `∅ ∉ c` and each element `a : α`
belongs to a unique set `b ∈ c`. This is expressed as `IsPartition c`
* An indexed partition is a map `s : ι → α` whose image is a partition. This is
expressed as `IndexedPartition s`.
Of course both implementations are related to `Quotient` and `Setoid`.
`Setoid.isPartition.partition` and `Finpartition.isPartition_parts` furnish
a link between `Setoid.IsPartition` and `Finpartition`.
## TODO
Could the design of `Finpartition` inform the one of `Setoid.IsPartition`? Maybe bundling it and
changing it from `Set (Set α)` to `Set α` where `[Lattice α] [OrderBot α]` would make it more
usable.
## Tags
setoid, equivalence, iseqv, relation, equivalence relation, partition, equivalence class
-/
namespace Setoid
variable {α : Type*}
/-- If x ∈ α is in 2 elements of a set of sets partitioning α, those 2 sets are equal. -/
theorem eq_of_mem_eqv_class {c : Set (Set α)} (H : ∀ a, ∃! b ∈ c, a ∈ b) {x b b'}
(hc : b ∈ c) (hb : x ∈ b) (hc' : b' ∈ c) (hb' : x ∈ b') : b = b' :=
(H x).unique ⟨hc, hb⟩ ⟨hc', hb'⟩
/-- Makes an equivalence relation from a set of sets partitioning α. -/
def mkClasses (c : Set (Set α)) (H : ∀ a, ∃! b ∈ c, a ∈ b) : Setoid α where
r x y := ∀ s ∈ c, x ∈ s → y ∈ s
iseqv.refl := fun _ _ _ hx => hx
iseqv.symm := fun {x _y} h s hs hy => by
obtain ⟨t, ⟨ht, hx⟩, _⟩ := H x
rwa [eq_of_mem_eqv_class H hs hy ht (h t ht hx)]
iseqv.trans := fun {_x _ _} h1 h2 s hs hx => h2 s hs (h1 s hs hx)
/-- Makes the equivalence classes of an equivalence relation. -/
def classes (r : Setoid α) : Set (Set α) :=
{ s | ∃ y, s = { x | r x y } }
theorem mem_classes (r : Setoid α) (y) : { x | r x y } ∈ r.classes :=
⟨y, rfl⟩
theorem classes_ker_subset_fiber_set {β : Type*} (f : α → β) :
(Setoid.ker f).classes ⊆ Set.range fun y => { x | f x = y } := by
rintro s ⟨x, rfl⟩
rw [Set.mem_range]
exact ⟨f x, rfl⟩
|
theorem finite_classes_ker {α β : Type*} [Finite β] (f : α → β) : (Setoid.ker f).classes.Finite :=
(Set.finite_range _).subset <| classes_ker_subset_fiber_set f
theorem card_classes_ker_le {α β : Type*} [Fintype β] (f : α → β)
| Mathlib/Data/Setoid/Partition.lean | 67 | 71 |
/-
Copyright (c) 2019 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sébastien Gouëzel
-/
import Mathlib.Topology.PartialHomeomorph
import Mathlib.Topology.Connected.LocPathConnected
/-!
# Charted spaces
A smooth manifold is a topological space `M` locally modelled on a euclidean space (or a euclidean
half-space for manifolds with boundaries, or an infinite dimensional vector space for more general
notions of manifolds), i.e., the manifold is covered by open subsets on which there are local
homeomorphisms (the charts) going to a model space `H`, and the changes of charts should be smooth
maps.
In this file, we introduce a general framework describing these notions, where the model space is an
arbitrary topological space. We avoid the word *manifold*, which should be reserved for the
situation where the model space is a (subset of a) vector space, and use the terminology
*charted space* instead.
If the changes of charts satisfy some additional property (for instance if they are smooth), then
`M` inherits additional structure (it makes sense to talk about smooth manifolds). There are
therefore two different ingredients in a charted space:
* the set of charts, which is data
* the fact that changes of charts belong to some group (in fact groupoid), which is additional Prop.
We separate these two parts in the definition: the charted space structure is just the set of
charts, and then the different smoothness requirements (smooth manifold, orientable manifold,
contact manifold, and so on) are additional properties of these charts. These properties are
formalized through the notion of structure groupoid, i.e., a set of partial homeomorphisms stable
under composition and inverse, to which the change of coordinates should belong.
## Main definitions
* `StructureGroupoid H` : a subset of partial homeomorphisms of `H` stable under composition,
inverse and restriction (ex: partial diffeomorphisms).
* `continuousGroupoid H` : the groupoid of all partial homeomorphisms of `H`.
* `ChartedSpace H M` : charted space structure on `M` modelled on `H`, given by an atlas of
partial homeomorphisms from `M` to `H` whose sources cover `M`. This is a type class.
* `HasGroupoid M G` : when `G` is a structure groupoid on `H` and `M` is a charted space
modelled on `H`, require that all coordinate changes belong to `G`. This is a type class.
* `atlas H M` : when `M` is a charted space modelled on `H`, the atlas of this charted
space structure, i.e., the set of charts.
* `G.maximalAtlas M` : when `M` is a charted space modelled on `H` and admitting `G` as a
structure groupoid, one can consider all the partial homeomorphisms from `M` to `H` such that
changing coordinate from any chart to them belongs to `G`. This is a larger atlas, called the
maximal atlas (for the groupoid `G`).
* `Structomorph G M M'` : the type of diffeomorphisms between the charted spaces `M` and `M'` for
the groupoid `G`. We avoid the word diffeomorphism, keeping it for the smooth category.
As a basic example, we give the instance
`instance chartedSpaceSelf (H : Type*) [TopologicalSpace H] : ChartedSpace H H`
saying that a topological space is a charted space over itself, with the identity as unique chart.
This charted space structure is compatible with any groupoid.
Additional useful definitions:
* `Pregroupoid H` : a subset of partial maps of `H` stable under composition and
restriction, but not inverse (ex: smooth maps)
* `Pregroupoid.groupoid` : construct a groupoid from a pregroupoid, by requiring that a map and
its inverse both belong to the pregroupoid (ex: construct diffeos from smooth maps)
* `chartAt H x` is a preferred chart at `x : M` when `M` has a charted space structure modelled on
`H`.
* `G.compatible he he'` states that, for any two charts `e` and `e'` in the atlas, the composition
of `e.symm` and `e'` belongs to the groupoid `G` when `M` admits `G` as a structure groupoid.
* `G.compatible_of_mem_maximalAtlas he he'` states that, for any two charts `e` and `e'` in the
maximal atlas associated to the groupoid `G`, the composition of `e.symm` and `e'` belongs to the
`G` if `M` admits `G` as a structure groupoid.
* `ChartedSpaceCore.toChartedSpace`: consider a space without a topology, but endowed with a set
of charts (which are partial equivs) for which the change of coordinates are partial homeos.
Then one can construct a topology on the space for which the charts become partial homeos,
defining a genuine charted space structure.
## Implementation notes
The atlas in a charted space is *not* a maximal atlas in general: the notion of maximality depends
on the groupoid one considers, and changing groupoids changes the maximal atlas. With the current
formalization, it makes sense first to choose the atlas, and then to ask whether this precise atlas
defines a smooth manifold, an orientable manifold, and so on. A consequence is that structomorphisms
between `M` and `M'` do *not* induce a bijection between the atlases of `M` and `M'`: the
definition is only that, read in charts, the structomorphism locally belongs to the groupoid under
consideration. (This is equivalent to inducing a bijection between elements of the maximal atlas).
A consequence is that the invariance under structomorphisms of properties defined in terms of the
atlas is not obvious in general, and could require some work in theory (amounting to the fact
that these properties only depend on the maximal atlas, for instance). In practice, this does not
create any real difficulty.
We use the letter `H` for the model space thinking of the case of manifolds with boundary, where the
model space is a half space.
Manifolds are sometimes defined as topological spaces with an atlas of local diffeomorphisms, and
sometimes as spaces with an atlas from which a topology is deduced. We use the former approach:
otherwise, there would be an instance from manifolds to topological spaces, which means that any
instance search for topological spaces would try to find manifold structures involving a yet
unknown model space, leading to problems. However, we also introduce the latter approach,
through a structure `ChartedSpaceCore` making it possible to construct a topology out of a set of
partial equivs with compatibility conditions (but we do not register it as an instance).
In the definition of a charted space, the model space is written as an explicit parameter as there
can be several model spaces for a given topological space. For instance, a complex manifold
(modelled over `ℂ^n`) will also be seen sometimes as a real manifold modelled over `ℝ^(2n)`.
## Notations
In the locale `Manifold`, we denote the composition of partial homeomorphisms with `≫ₕ`, and the
composition of partial equivs with `≫`.
-/
noncomputable section
open TopologicalSpace Topology
universe u
variable {H : Type u} {H' : Type*} {M : Type*} {M' : Type*} {M'' : Type*}
/- Notational shortcut for the composition of partial homeomorphisms and partial equivs, i.e.,
`PartialHomeomorph.trans` and `PartialEquiv.trans`.
Note that, as is usual for equivs, the composition is from left to right, hence the direction of
the arrow. -/
@[inherit_doc] scoped[Manifold] infixr:100 " ≫ₕ " => PartialHomeomorph.trans
@[inherit_doc] scoped[Manifold] infixr:100 " ≫ " => PartialEquiv.trans
open Set PartialHomeomorph Manifold -- Porting note: Added `Manifold`
/-! ### Structure groupoids -/
section Groupoid
/-! One could add to the definition of a structure groupoid the fact that the restriction of an
element of the groupoid to any open set still belongs to the groupoid.
(This is in Kobayashi-Nomizu.)
I am not sure I want this, for instance on `H × E` where `E` is a vector space, and the groupoid is
made of functions respecting the fibers and linear in the fibers (so that a charted space over this
groupoid is naturally a vector bundle) I prefer that the members of the groupoid are always
defined on sets of the form `s × E`. There is a typeclass `ClosedUnderRestriction` for groupoids
which have the restriction property.
The only nontrivial requirement is locality: if a partial homeomorphism belongs to the groupoid
around each point in its domain of definition, then it belongs to the groupoid. Without this
requirement, the composition of structomorphisms does not have to be a structomorphism. Note that
this implies that a partial homeomorphism with empty source belongs to any structure groupoid, as
it trivially satisfies this condition.
There is also a technical point, related to the fact that a partial homeomorphism is by definition a
global map which is a homeomorphism when restricted to its source subset (and its values outside
of the source are not relevant). Therefore, we also require that being a member of the groupoid only
depends on the values on the source.
We use primes in the structure names as we will reformulate them below (without primes) using a
`Membership` instance, writing `e ∈ G` instead of `e ∈ G.members`.
-/
/-- A structure groupoid is a set of partial homeomorphisms of a topological space stable under
composition and inverse. They appear in the definition of the smoothness class of a manifold. -/
structure StructureGroupoid (H : Type u) [TopologicalSpace H] where
/-- Members of the structure groupoid are partial homeomorphisms. -/
members : Set (PartialHomeomorph H H)
/-- Structure groupoids are stable under composition. -/
trans' : ∀ e e' : PartialHomeomorph H H, e ∈ members → e' ∈ members → e ≫ₕ e' ∈ members
/-- Structure groupoids are stable under inverse. -/
symm' : ∀ e : PartialHomeomorph H H, e ∈ members → e.symm ∈ members
/-- The identity morphism lies in the structure groupoid. -/
id_mem' : PartialHomeomorph.refl H ∈ members
/-- Let `e` be a partial homeomorphism. If for every `x ∈ e.source`, the restriction of e to some
open set around `x` lies in the groupoid, then `e` lies in the groupoid. -/
locality' : ∀ e : PartialHomeomorph H H,
(∀ x ∈ e.source, ∃ s, IsOpen s ∧ x ∈ s ∧ e.restr s ∈ members) → e ∈ members
/-- Membership in a structure groupoid respects the equivalence of partial homeomorphisms. -/
mem_of_eqOnSource' : ∀ e e' : PartialHomeomorph H H, e ∈ members → e' ≈ e → e' ∈ members
variable [TopologicalSpace H]
instance : Membership (PartialHomeomorph H H) (StructureGroupoid H) :=
⟨fun (G : StructureGroupoid H) (e : PartialHomeomorph H H) ↦ e ∈ G.members⟩
instance (H : Type u) [TopologicalSpace H] :
SetLike (StructureGroupoid H) (PartialHomeomorph H H) where
coe s := s.members
coe_injective' N O h := by cases N; cases O; congr
instance : Min (StructureGroupoid H) :=
⟨fun G G' => StructureGroupoid.mk
(members := G.members ∩ G'.members)
(trans' := fun e e' he he' =>
⟨G.trans' e e' he.left he'.left, G'.trans' e e' he.right he'.right⟩)
(symm' := fun e he => ⟨G.symm' e he.left, G'.symm' e he.right⟩)
(id_mem' := ⟨G.id_mem', G'.id_mem'⟩)
(locality' := by
intro e hx
apply (mem_inter_iff e G.members G'.members).mpr
refine And.intro (G.locality' e ?_) (G'.locality' e ?_)
all_goals
intro x hex
rcases hx x hex with ⟨s, hs⟩
use s
refine And.intro hs.left (And.intro hs.right.left ?_)
· exact hs.right.right.left
· exact hs.right.right.right)
(mem_of_eqOnSource' := fun e e' he hee' =>
⟨G.mem_of_eqOnSource' e e' he.left hee', G'.mem_of_eqOnSource' e e' he.right hee'⟩)⟩
instance : InfSet (StructureGroupoid H) :=
⟨fun S => StructureGroupoid.mk
(members := ⋂ s ∈ S, s.members)
(trans' := by
simp only [mem_iInter]
intro e e' he he' i hi
exact i.trans' e e' (he i hi) (he' i hi))
(symm' := by
simp only [mem_iInter]
intro e he i hi
exact i.symm' e (he i hi))
(id_mem' := by
simp only [mem_iInter]
intro i _
exact i.id_mem')
(locality' := by
simp only [mem_iInter]
intro e he i hi
refine i.locality' e ?_
intro x hex
rcases he x hex with ⟨s, hs⟩
exact ⟨s, ⟨hs.left, ⟨hs.right.left, hs.right.right i hi⟩⟩⟩)
(mem_of_eqOnSource' := by
simp only [mem_iInter]
intro e e' he he'e
exact fun i hi => i.mem_of_eqOnSource' e e' (he i hi) he'e)⟩
theorem StructureGroupoid.trans (G : StructureGroupoid H) {e e' : PartialHomeomorph H H}
(he : e ∈ G) (he' : e' ∈ G) : e ≫ₕ e' ∈ G :=
G.trans' e e' he he'
theorem StructureGroupoid.symm (G : StructureGroupoid H) {e : PartialHomeomorph H H} (he : e ∈ G) :
e.symm ∈ G :=
G.symm' e he
theorem StructureGroupoid.id_mem (G : StructureGroupoid H) : PartialHomeomorph.refl H ∈ G :=
G.id_mem'
theorem StructureGroupoid.locality (G : StructureGroupoid H) {e : PartialHomeomorph H H}
(h : ∀ x ∈ e.source, ∃ s, IsOpen s ∧ x ∈ s ∧ e.restr s ∈ G) : e ∈ G :=
G.locality' e h
theorem StructureGroupoid.mem_of_eqOnSource (G : StructureGroupoid H) {e e' : PartialHomeomorph H H}
(he : e ∈ G) (h : e' ≈ e) : e' ∈ G :=
G.mem_of_eqOnSource' e e' he h
theorem StructureGroupoid.mem_iff_of_eqOnSource {G : StructureGroupoid H}
{e e' : PartialHomeomorph H H} (h : e ≈ e') : e ∈ G ↔ e' ∈ G :=
⟨fun he ↦ G.mem_of_eqOnSource he (Setoid.symm h), fun he' ↦ G.mem_of_eqOnSource he' h⟩
/-- Partial order on the set of groupoids, given by inclusion of the members of the groupoid. -/
instance StructureGroupoid.partialOrder : PartialOrder (StructureGroupoid H) :=
PartialOrder.lift StructureGroupoid.members fun a b h ↦ by
cases a
cases b
dsimp at h
induction h
rfl
theorem StructureGroupoid.le_iff {G₁ G₂ : StructureGroupoid H} : G₁ ≤ G₂ ↔ ∀ e, e ∈ G₁ → e ∈ G₂ :=
Iff.rfl
/-- The trivial groupoid, containing only the identity (and maps with empty source, as this is
necessary from the definition). -/
def idGroupoid (H : Type u) [TopologicalSpace H] : StructureGroupoid H where
members := {PartialHomeomorph.refl H} ∪ { e : PartialHomeomorph H H | e.source = ∅ }
trans' e e' he he' := by
rcases he with he | he
· simpa only [mem_singleton_iff.1 he, refl_trans]
· have : (e ≫ₕ e').source ⊆ e.source := sep_subset _ _
rw [he] at this
have : e ≫ₕ e' ∈ { e : PartialHomeomorph H H | e.source = ∅ } := eq_bot_iff.2 this
exact (mem_union _ _ _).2 (Or.inr this)
symm' e he := by
rcases (mem_union _ _ _).1 he with E | E
· simp [mem_singleton_iff.mp E]
· right
simpa only [e.toPartialEquiv.image_source_eq_target.symm, mfld_simps] using E
id_mem' := mem_union_left _ rfl
locality' e he := by
rcases e.source.eq_empty_or_nonempty with h | h
· right
exact h
· left
rcases h with ⟨x, hx⟩
rcases he x hx with ⟨s, open_s, xs, hs⟩
have x's : x ∈ (e.restr s).source := by
rw [restr_source, open_s.interior_eq]
exact ⟨hx, xs⟩
rcases hs with hs | hs
· replace hs : PartialHomeomorph.restr e s = PartialHomeomorph.refl H := by
simpa only using hs
have : (e.restr s).source = univ := by
rw [hs]
simp
have : e.toPartialEquiv.source ∩ interior s = univ := this
have : univ ⊆ interior s := by
rw [← this]
exact inter_subset_right
have : s = univ := by rwa [open_s.interior_eq, univ_subset_iff] at this
simpa only [this, restr_univ] using hs
· exfalso
rw [mem_setOf_eq] at hs
rwa [hs] at x's
mem_of_eqOnSource' e e' he he'e := by
rcases he with he | he
· left
have : e = e' := by
refine eq_of_eqOnSource_univ (Setoid.symm he'e) ?_ ?_ <;>
rw [Set.mem_singleton_iff.1 he] <;> rfl
rwa [← this]
· right
have he : e.toPartialEquiv.source = ∅ := he
rwa [Set.mem_setOf_eq, EqOnSource.source_eq he'e]
/-- Every structure groupoid contains the identity groupoid. -/
instance instStructureGroupoidOrderBot : OrderBot (StructureGroupoid H) where
bot := idGroupoid H
bot_le := by
intro u f hf
have hf : f ∈ {PartialHomeomorph.refl H} ∪ { e : PartialHomeomorph H H | e.source = ∅ } := hf
simp only [singleton_union, mem_setOf_eq, mem_insert_iff] at hf
rcases hf with hf | hf
· rw [hf]
apply u.id_mem
· apply u.locality
intro x hx
rw [hf, mem_empty_iff_false] at hx
exact hx.elim
instance : Inhabited (StructureGroupoid H) := ⟨idGroupoid H⟩
/-- To construct a groupoid, one may consider classes of partial homeomorphisms such that
both the function and its inverse have some property. If this property is stable under composition,
one gets a groupoid. `Pregroupoid` bundles the properties needed for this construction, with the
groupoid of smooth functions with smooth inverses as an application. -/
structure Pregroupoid (H : Type*) [TopologicalSpace H] where
/-- Property describing membership in this groupoid: the pregroupoid "contains"
all functions `H → H` having the pregroupoid property on some `s : Set H` -/
property : (H → H) → Set H → Prop
/-- The pregroupoid property is stable under composition -/
comp : ∀ {f g u v}, property f u → property g v →
IsOpen u → IsOpen v → IsOpen (u ∩ f ⁻¹' v) → property (g ∘ f) (u ∩ f ⁻¹' v)
/-- Pregroupoids contain the identity map (on `univ`) -/
id_mem : property id univ
/-- The pregroupoid property is "local", in the sense that `f` has the pregroupoid property on `u`
iff its restriction to each open subset of `u` has it -/
locality :
∀ {f u}, IsOpen u → (∀ x ∈ u, ∃ v, IsOpen v ∧ x ∈ v ∧ property f (u ∩ v)) → property f u
/-- If `f = g` on `u` and `property f u`, then `property g u` -/
congr : ∀ {f g : H → H} {u}, IsOpen u → (∀ x ∈ u, g x = f x) → property f u → property g u
/-- Construct a groupoid of partial homeos for which the map and its inverse have some property,
from a pregroupoid asserting that this property is stable under composition. -/
def Pregroupoid.groupoid (PG : Pregroupoid H) : StructureGroupoid H where
members := { e : PartialHomeomorph H H | PG.property e e.source ∧ PG.property e.symm e.target }
trans' e e' he he' := by
constructor
· apply PG.comp he.1 he'.1 e.open_source e'.open_source
apply e.continuousOn_toFun.isOpen_inter_preimage e.open_source e'.open_source
· apply PG.comp he'.2 he.2 e'.open_target e.open_target
apply e'.continuousOn_invFun.isOpen_inter_preimage e'.open_target e.open_target
symm' _ he := ⟨he.2, he.1⟩
id_mem' := ⟨PG.id_mem, PG.id_mem⟩
locality' e he := by
constructor
· refine PG.locality e.open_source fun x xu ↦ ?_
rcases he x xu with ⟨s, s_open, xs, hs⟩
refine ⟨s, s_open, xs, ?_⟩
convert hs.1 using 1
dsimp [PartialHomeomorph.restr]
rw [s_open.interior_eq]
· refine PG.locality e.open_target fun x xu ↦ ?_
rcases he (e.symm x) (e.map_target xu) with ⟨s, s_open, xs, hs⟩
refine ⟨e.target ∩ e.symm ⁻¹' s, ?_, ⟨xu, xs⟩, ?_⟩
· exact ContinuousOn.isOpen_inter_preimage e.continuousOn_invFun e.open_target s_open
· rw [← inter_assoc, inter_self]
convert hs.2 using 1
dsimp [PartialHomeomorph.restr]
rw [s_open.interior_eq]
mem_of_eqOnSource' e e' he ee' := by
constructor
· apply PG.congr e'.open_source ee'.2
simp only [ee'.1, he.1]
· have A := EqOnSource.symm' ee'
apply PG.congr e'.symm.open_source A.2
-- Porting note: was
-- convert he.2
-- rw [A.1]
-- rfl
rw [A.1, symm_toPartialEquiv, PartialEquiv.symm_source]
exact he.2
theorem mem_groupoid_of_pregroupoid {PG : Pregroupoid H} {e : PartialHomeomorph H H} :
e ∈ PG.groupoid ↔ PG.property e e.source ∧ PG.property e.symm e.target :=
Iff.rfl
theorem groupoid_of_pregroupoid_le (PG₁ PG₂ : Pregroupoid H)
(h : ∀ f s, PG₁.property f s → PG₂.property f s) : PG₁.groupoid ≤ PG₂.groupoid := by
refine StructureGroupoid.le_iff.2 fun e he ↦ ?_
rw [mem_groupoid_of_pregroupoid] at he ⊢
exact ⟨h _ _ he.1, h _ _ he.2⟩
theorem mem_pregroupoid_of_eqOnSource (PG : Pregroupoid H) {e e' : PartialHomeomorph H H}
(he' : e ≈ e') (he : PG.property e e.source) : PG.property e' e'.source := by
rw [← he'.1]
exact PG.congr e.open_source he'.eqOn.symm he
/-- The pregroupoid of all partial maps on a topological space `H`. -/
abbrev continuousPregroupoid (H : Type*) [TopologicalSpace H] : Pregroupoid H where
property _ _ := True
comp _ _ _ _ _ := trivial
id_mem := trivial
locality _ _ := trivial
congr _ _ _ := trivial
instance (H : Type*) [TopologicalSpace H] : Inhabited (Pregroupoid H) :=
⟨continuousPregroupoid H⟩
/-- The groupoid of all partial homeomorphisms on a topological space `H`. -/
def continuousGroupoid (H : Type*) [TopologicalSpace H] : StructureGroupoid H :=
Pregroupoid.groupoid (continuousPregroupoid H)
/-- Every structure groupoid is contained in the groupoid of all partial homeomorphisms. -/
instance instStructureGroupoidOrderTop : OrderTop (StructureGroupoid H) where
top := continuousGroupoid H
le_top _ _ _ := ⟨trivial, trivial⟩
instance : CompleteLattice (StructureGroupoid H) :=
{ SetLike.instPartialOrder,
completeLatticeOfInf _ (by
exact fun s =>
⟨fun S Ss F hF => mem_iInter₂.mp hF S Ss,
fun T Tl F fT => mem_iInter₂.mpr (fun i his => Tl his fT)⟩) with
le := (· ≤ ·)
lt := (· < ·)
bot := instStructureGroupoidOrderBot.bot
bot_le := instStructureGroupoidOrderBot.bot_le
top := instStructureGroupoidOrderTop.top
le_top := instStructureGroupoidOrderTop.le_top
inf := (· ⊓ ·)
le_inf := fun _ _ _ h₁₂ h₁₃ _ hm ↦ ⟨h₁₂ hm, h₁₃ hm⟩
inf_le_left := fun _ _ _ ↦ And.left
inf_le_right := fun _ _ _ ↦ And.right }
/-- A groupoid is closed under restriction if it contains all restrictions of its element local
homeomorphisms to open subsets of the source. -/
class ClosedUnderRestriction (G : StructureGroupoid H) : Prop where
closedUnderRestriction :
∀ {e : PartialHomeomorph H H}, e ∈ G → ∀ s : Set H, IsOpen s → e.restr s ∈ G
theorem closedUnderRestriction' {G : StructureGroupoid H} [ClosedUnderRestriction G]
{e : PartialHomeomorph H H} (he : e ∈ G) {s : Set H} (hs : IsOpen s) : e.restr s ∈ G :=
ClosedUnderRestriction.closedUnderRestriction he s hs
/-- The trivial restriction-closed groupoid, containing only partial homeomorphisms equivalent
to the restriction of the identity to the various open subsets. -/
def idRestrGroupoid : StructureGroupoid H where
members := { e | ∃ (s : Set H) (h : IsOpen s), e ≈ PartialHomeomorph.ofSet s h }
trans' := by
rintro e e' ⟨s, hs, hse⟩ ⟨s', hs', hse'⟩
refine ⟨s ∩ s', hs.inter hs', ?_⟩
have := PartialHomeomorph.EqOnSource.trans' hse hse'
rwa [PartialHomeomorph.ofSet_trans_ofSet] at this
symm' := by
rintro e ⟨s, hs, hse⟩
refine ⟨s, hs, ?_⟩
rw [← ofSet_symm]
exact PartialHomeomorph.EqOnSource.symm' hse
id_mem' := ⟨univ, isOpen_univ, by simp only [mfld_simps, refl]⟩
locality' := by
intro e h
refine ⟨e.source, e.open_source, by simp only [mfld_simps], ?_⟩
intro x hx
rcases h x hx with ⟨s, hs, hxs, s', hs', hes'⟩
have hes : x ∈ (e.restr s).source := by
rw [e.restr_source]
refine ⟨hx, ?_⟩
rw [hs.interior_eq]
exact hxs
simpa only [mfld_simps] using PartialHomeomorph.EqOnSource.eqOn hes' hes
mem_of_eqOnSource' := by
rintro e e' ⟨s, hs, hse⟩ hee'
exact ⟨s, hs, Setoid.trans hee' hse⟩
theorem idRestrGroupoid_mem {s : Set H} (hs : IsOpen s) : ofSet s hs ∈ @idRestrGroupoid H _ :=
⟨s, hs, refl _⟩
/-- The trivial restriction-closed groupoid is indeed `ClosedUnderRestriction`. -/
instance closedUnderRestriction_idRestrGroupoid : ClosedUnderRestriction (@idRestrGroupoid H _) :=
⟨by
rintro e ⟨s', hs', he⟩ s hs
use s' ∩ s, hs'.inter hs
refine Setoid.trans (PartialHomeomorph.EqOnSource.restr he s) ?_
exact ⟨by simp only [hs.interior_eq, mfld_simps], by simp only [mfld_simps, eqOn_refl]⟩⟩
/-- A groupoid is closed under restriction if and only if it contains the trivial restriction-closed
groupoid. -/
theorem closedUnderRestriction_iff_id_le (G : StructureGroupoid H) :
ClosedUnderRestriction G ↔ idRestrGroupoid ≤ G := by
constructor
· intro _i
rw [StructureGroupoid.le_iff]
rintro e ⟨s, hs, hes⟩
refine G.mem_of_eqOnSource ?_ hes
convert closedUnderRestriction' G.id_mem hs
-- Porting note: was
-- change s = _ ∩ _
-- rw [hs.interior_eq]
-- simp only [mfld_simps]
ext
· rw [PartialHomeomorph.restr_apply, PartialHomeomorph.refl_apply, id, ofSet_apply, id_eq]
· simp [hs]
· simp [hs.interior_eq]
· intro h
constructor
intro e he s hs
rw [← ofSet_trans (e : PartialHomeomorph H H) hs]
refine G.trans ?_ he
apply StructureGroupoid.le_iff.mp h
exact idRestrGroupoid_mem hs
/-- The groupoid of all partial homeomorphisms on a topological space `H`
is closed under restriction. -/
instance : ClosedUnderRestriction (continuousGroupoid H) :=
(closedUnderRestriction_iff_id_le _).mpr le_top
end Groupoid
/-! ### Charted spaces -/
/-- A charted space is a topological space endowed with an atlas, i.e., a set of local
homeomorphisms taking value in a model space `H`, called charts, such that the domains of the charts
cover the whole space. We express the covering property by choosing for each `x` a member
`chartAt x` of the atlas containing `x` in its source: in the smooth case, this is convenient to
construct the tangent bundle in an efficient way.
The model space is written as an explicit parameter as there can be several model spaces for a
given topological space. For instance, a complex manifold (modelled over `ℂ^n`) will also be seen
sometimes as a real manifold over `ℝ^(2n)`.
-/
@[ext]
class ChartedSpace (H : Type*) [TopologicalSpace H] (M : Type*) [TopologicalSpace M] where
/-- The atlas of charts in the `ChartedSpace`. -/
protected atlas : Set (PartialHomeomorph M H)
/-- The preferred chart at each point in the charted space. -/
protected chartAt : M → PartialHomeomorph M H
protected mem_chart_source : ∀ x, x ∈ (chartAt x).source
protected chart_mem_atlas : ∀ x, chartAt x ∈ atlas
/-- The atlas of charts in a `ChartedSpace`. -/
abbrev atlas (H : Type*) [TopologicalSpace H] (M : Type*) [TopologicalSpace M]
[ChartedSpace H M] : Set (PartialHomeomorph M H) :=
ChartedSpace.atlas
/-- The preferred chart at a point `x` in a charted space `M`. -/
abbrev chartAt (H : Type*) [TopologicalSpace H] {M : Type*} [TopologicalSpace M]
[ChartedSpace H M] (x : M) : PartialHomeomorph M H :=
ChartedSpace.chartAt x
@[simp, mfld_simps]
lemma mem_chart_source (H : Type*) {M : Type*} [TopologicalSpace H] [TopologicalSpace M]
[ChartedSpace H M] (x : M) : x ∈ (chartAt H x).source :=
ChartedSpace.mem_chart_source x
@[simp, mfld_simps]
lemma chart_mem_atlas (H : Type*) {M : Type*} [TopologicalSpace H] [TopologicalSpace M]
[ChartedSpace H M] (x : M) : chartAt H x ∈ atlas H M :=
ChartedSpace.chart_mem_atlas x
lemma nonempty_of_chartedSpace {H : Type*} {M : Type*} [TopologicalSpace H] [TopologicalSpace M]
[ChartedSpace H M] (x : M) : Nonempty H :=
⟨chartAt H x x⟩
lemma isEmpty_of_chartedSpace (H : Type*) {M : Type*} [TopologicalSpace H] [TopologicalSpace M]
[ChartedSpace H M] [IsEmpty H] : IsEmpty M := by
rcases isEmpty_or_nonempty M with hM | ⟨⟨x⟩⟩
· exact hM
· exact (IsEmpty.false (chartAt H x x)).elim
section ChartedSpace
section
variable (H) [TopologicalSpace H] [TopologicalSpace M] [ChartedSpace H M]
-- Porting note: Added `(H := H)` to avoid typeclass instance problem.
theorem mem_chart_target (x : M) : chartAt H x x ∈ (chartAt H x).target :=
(chartAt H x).map_source (mem_chart_source _ _)
theorem chart_source_mem_nhds (x : M) : (chartAt H x).source ∈ 𝓝 x :=
(chartAt H x).open_source.mem_nhds <| mem_chart_source H x
theorem chart_target_mem_nhds (x : M) : (chartAt H x).target ∈ 𝓝 (chartAt H x x) :=
(chartAt H x).open_target.mem_nhds <| mem_chart_target H x
variable (M) in
@[simp]
theorem iUnion_source_chartAt : (⋃ x : M, (chartAt H x).source) = (univ : Set M) :=
eq_univ_iff_forall.mpr fun x ↦ mem_iUnion.mpr ⟨x, mem_chart_source H x⟩
theorem ChartedSpace.isOpen_iff (s : Set M) :
IsOpen s ↔ ∀ x : M, IsOpen <| chartAt H x '' ((chartAt H x).source ∩ s) := by
rw [isOpen_iff_of_cover (fun i ↦ (chartAt H i).open_source) (iUnion_source_chartAt H M)]
simp only [(chartAt H _).isOpen_image_iff_of_subset_source inter_subset_left]
/-- `achart H x` is the chart at `x`, considered as an element of the atlas.
Especially useful for working with `BasicContMDiffVectorBundleCore`. -/
def achart (x : M) : atlas H M :=
⟨chartAt H x, chart_mem_atlas H x⟩
theorem achart_def (x : M) : achart H x = ⟨chartAt H x, chart_mem_atlas H x⟩ :=
rfl
@[simp, mfld_simps]
theorem coe_achart (x : M) : (achart H x : PartialHomeomorph M H) = chartAt H x :=
rfl
@[simp, mfld_simps]
theorem achart_val (x : M) : (achart H x).1 = chartAt H x :=
rfl
theorem mem_achart_source (x : M) : x ∈ (achart H x).1.source :=
mem_chart_source H x
open TopologicalSpace
theorem ChartedSpace.secondCountable_of_countable_cover [SecondCountableTopology H] {s : Set M}
(hs : ⋃ (x) (_ : x ∈ s), (chartAt H x).source = univ) (hsc : s.Countable) :
SecondCountableTopology M := by
haveI : ∀ x : M, SecondCountableTopology (chartAt H x).source :=
fun x ↦ (chartAt (H := H) x).secondCountableTopology_source
haveI := hsc.toEncodable
rw [biUnion_eq_iUnion] at hs
exact secondCountableTopology_of_countable_cover (fun x : s ↦ (chartAt H (x : M)).open_source) hs
variable (M)
theorem ChartedSpace.secondCountable_of_sigmaCompact [SecondCountableTopology H]
[SigmaCompactSpace M] : SecondCountableTopology M := by
obtain ⟨s, hsc, hsU⟩ : ∃ s, Set.Countable s ∧ ⋃ (x) (_ : x ∈ s), (chartAt H x).source = univ :=
countable_cover_nhds_of_sigmaCompact fun x : M ↦ chart_source_mem_nhds H x
exact ChartedSpace.secondCountable_of_countable_cover H hsU hsc
@[deprecated (since := "2024-11-13")] alias
ChartedSpace.secondCountable_of_sigma_compact := ChartedSpace.secondCountable_of_sigmaCompact
/-- If a topological space admits an atlas with locally compact charts, then the space itself
is locally compact. -/
theorem ChartedSpace.locallyCompactSpace [LocallyCompactSpace H] : LocallyCompactSpace M := by
have : ∀ x : M, (𝓝 x).HasBasis
(fun s ↦ s ∈ 𝓝 (chartAt H x x) ∧ IsCompact s ∧ s ⊆ (chartAt H x).target)
fun s ↦ (chartAt H x).symm '' s := fun x ↦ by
rw [← (chartAt H x).symm_map_nhds_eq (mem_chart_source H x)]
exact ((compact_basis_nhds (chartAt H x x)).hasBasis_self_subset
(chart_target_mem_nhds H x)).map _
refine .of_hasBasis this ?_
rintro x s ⟨_, h₂, h₃⟩
exact h₂.image_of_continuousOn ((chartAt H x).continuousOn_symm.mono h₃)
/-- If a topological space admits an atlas with locally connected charts, then the space itself is
locally connected. -/
theorem ChartedSpace.locallyConnectedSpace [LocallyConnectedSpace H] : LocallyConnectedSpace M := by
let e : M → PartialHomeomorph M H := chartAt H
refine locallyConnectedSpace_of_connected_bases (fun x s ↦ (e x).symm '' s)
(fun x s ↦ (IsOpen s ∧ e x x ∈ s ∧ IsConnected s) ∧ s ⊆ (e x).target) ?_ ?_
· intro x
simpa only [e, PartialHomeomorph.symm_map_nhds_eq, mem_chart_source] using
((LocallyConnectedSpace.open_connected_basis (e x x)).restrict_subset
((e x).open_target.mem_nhds (mem_chart_target H x))).map (e x).symm
· rintro x s ⟨⟨-, -, hsconn⟩, hssubset⟩
exact hsconn.isPreconnected.image _ ((e x).continuousOn_symm.mono hssubset)
| /-- If a topological space `M` admits an atlas with locally path-connected charts,
then `M` itself is locally path-connected. -/
theorem ChartedSpace.locPathConnectedSpace [LocPathConnectedSpace H] : LocPathConnectedSpace M := by
refine ⟨fun x ↦ ⟨fun s ↦ ⟨fun hs ↦ ?_, fun ⟨u, hu⟩ ↦ Filter.mem_of_superset hu.1.1 hu.2⟩⟩⟩
let e := chartAt H x
let t := s ∩ e.source
have ht : t ∈ 𝓝 x := Filter.inter_mem hs (chart_source_mem_nhds _ _)
refine ⟨e.symm '' pathComponentIn (e x) (e '' t), ⟨?_, ?_⟩, (?_ : _ ⊆ t).trans inter_subset_left⟩
| Mathlib/Geometry/Manifold/ChartedSpace.lean | 679 | 686 |
/-
Copyright (c) 2019 Amelia Livingston. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Amelia Livingston
-/
import Mathlib.Algebra.Group.Submonoid.Operations
import Mathlib.Data.Setoid.Basic
import Mathlib.GroupTheory.Congruence.Hom
/-!
# Congruence relations
This file proves basic properties of the quotient of a type by a congruence relation.
The second half of the file concerns congruence relations on monoids, in which case the
quotient by the congruence relation is also a monoid. There are results about the universal
property of quotients of monoids, and the isomorphism theorems for monoids.
## Implementation notes
A congruence relation on a monoid `M` can be thought of as a submonoid of `M × M` for which
membership is an equivalence relation, but whilst this fact is established in the file, it is not
used, since this perspective adds more layers of definitional unfolding.
## Tags
congruence, congruence relation, quotient, quotient by congruence relation, monoid,
quotient monoid, isomorphism theorems
-/
variable (M : Type*) {N : Type*} {P : Type*}
open Function Setoid
variable {M}
namespace Con
section
variable [Mul M] [Mul N] [Mul P] (c : Con M)
variable {c}
/-- Given types with multiplications `M, N`, the product of two congruence relations `c` on `M` and
`d` on `N`: `(x₁, x₂), (y₁, y₂) ∈ M × N` are related by `c.prod d` iff `x₁` is related to `y₁`
by `c` and `x₂` is related to `y₂` by `d`. -/
@[to_additive prod "Given types with additions `M, N`, the product of two congruence relations
`c` on `M` and `d` on `N`: `(x₁, x₂), (y₁, y₂) ∈ M × N` are related by `c.prod d` iff `x₁`
is related to `y₁` by `c` and `x₂` is related to `y₂` by `d`."]
protected def prod (c : Con M) (d : Con N) : Con (M × N) :=
{ c.toSetoid.prod d.toSetoid with
mul' := fun h1 h2 => ⟨c.mul h1.1 h2.1, d.mul h1.2 h2.2⟩ }
/-- The product of an indexed collection of congruence relations. -/
@[to_additive "The product of an indexed collection of additive congruence relations."]
def pi {ι : Type*} {f : ι → Type*} [∀ i, Mul (f i)] (C : ∀ i, Con (f i)) : Con (∀ i, f i) :=
{ @piSetoid _ _ fun i => (C i).toSetoid with
mul' := fun h1 h2 i => (C i).mul (h1 i) (h2 i) }
/-- Makes an isomorphism of quotients by two congruence relations, given that the relations are
equal. -/
@[to_additive "Makes an additive isomorphism of quotients by two additive congruence relations,
given that the relations are equal."]
protected def congr {c d : Con M} (h : c = d) : c.Quotient ≃* d.Quotient :=
{ Quotient.congr (Equiv.refl M) <| by apply Con.ext_iff.mp h with
map_mul' := fun x y => by rcases x with ⟨⟩; rcases y with ⟨⟩; rfl }
@[to_additive (attr := simp)]
theorem congr_mk {c d : Con M} (h : c = d) (a : M) :
Con.congr h (a : c.Quotient) = (a : d.Quotient) := rfl
@[to_additive]
theorem le_comap_conGen {M N : Type*} [Mul M] [Mul N] (f : M → N)
(H : ∀ (x y : M), f (x * y) = f x * f y) (rel : N → N → Prop) :
conGen (fun x y ↦ rel (f x) (f y)) ≤ Con.comap f H (conGen rel) := by
intro x y h
simp only [Con.comap_rel]
exact .rec (fun x y h ↦ .of (f x) (f y) h) (fun x ↦ .refl (f x))
(fun _ h ↦ .symm h) (fun _ _ h1 h2 ↦ h1.trans h2) (fun {w x y z} _ _ h1 h2 ↦
(congrArg (fun a ↦ conGen rel a (f (x * z))) (H w y)).mpr
(((congrArg (fun a ↦ conGen rel (f w * f y) a) (H x z))).mpr
(.mul h1 h2))) h
@[to_additive]
theorem comap_conGen_equiv {M N : Type*} [Mul M] [Mul N] (f : MulEquiv M N) (rel : N → N → Prop) :
Con.comap f (map_mul f) (conGen rel) = conGen (fun x y ↦ rel (f x) (f y)) := by
apply le_antisymm _ (le_comap_conGen f (map_mul f) rel)
intro a b h
simp only [Con.comap_rel] at h
have H : ∀ n1 n2, (conGen rel) n1 n2 → ∀ a b, f a = n1 → f b = n2 →
(conGen fun x y ↦ rel (f x) (f y)) a b := by
intro n1 n2 h
induction h with
| of x y h =>
intro _ _ fa fb
apply ConGen.Rel.of
rwa [fa, fb]
| refl x =>
intro _ _ fc fd
rw [f.injective (fc.trans fd.symm)]
exact ConGen.Rel.refl _
| symm _ h => exact fun a b fs fb ↦ ConGen.Rel.symm (h b a fb fs)
| trans _ _ ih ih1 =>
exact fun a b fa fb ↦ Exists.casesOn (f.surjective _) fun c' hc' ↦
ConGen.Rel.trans (ih a c' fa hc') (ih1 c' b hc' fb)
| mul _ _ ih ih1 =>
rename_i w x y z _ _
intro a b fa fb
rw [← f.eq_symm_apply, map_mul] at fa fb
rw [fa, fb]
exact ConGen.Rel.mul (ih (f.symm w) (f.symm x) (by simp) (by simp))
(ih1 (f.symm y) (f.symm z) (by simp) (by simp))
exact H (f a) (f b) h a b (refl _) (refl _)
@[to_additive]
theorem comap_conGen_of_bijective {M N : Type*} [Mul M] [Mul N] (f : M → N)
(hf : Function.Bijective f) (H : ∀ (x y : M), f (x * y) = f x * f y) (rel : N → N → Prop) :
Con.comap f H (conGen rel) = conGen (fun x y ↦ rel (f x) (f y)) :=
comap_conGen_equiv (MulEquiv.ofBijective (MulHom.mk f H) hf) rel
end
section MulOneClass
variable [MulOneClass M] [MulOneClass N] [MulOneClass P] (c : Con M)
/-- The submonoid of `M × M` defined by a congruence relation on a monoid `M`. -/
@[to_additive (attr := coe) "The `AddSubmonoid` of `M × M` defined by an additive congruence
relation on an `AddMonoid` `M`."]
protected def submonoid : Submonoid (M × M) where
carrier := { x | c x.1 x.2 }
one_mem' := c.iseqv.1 1
mul_mem' := c.mul
variable {c}
/-- The congruence relation on a monoid `M` from a submonoid of `M × M` for which membership
is an equivalence relation. -/
@[to_additive "The additive congruence relation on an `AddMonoid` `M` from
an `AddSubmonoid` of `M × M` for which membership is an equivalence relation."]
def ofSubmonoid (N : Submonoid (M × M)) (H : Equivalence fun x y => (x, y) ∈ N) : Con M where
r x y := (x, y) ∈ N
iseqv := H
mul' := N.mul_mem
/-- Coercion from a congruence relation `c` on a monoid `M` to the submonoid of `M × M` whose
elements are `(x, y)` such that `x` is related to `y` by `c`. -/
@[to_additive "Coercion from a congruence relation `c` on an `AddMonoid` `M`
to the `AddSubmonoid` of `M × M` whose elements are `(x, y)` such that `x`
is related to `y` by `c`."]
instance toSubmonoid : Coe (Con M) (Submonoid (M × M)) :=
⟨fun c => c.submonoid⟩
@[to_additive]
theorem mem_coe {c : Con M} {x y} : (x, y) ∈ (↑c : Submonoid (M × M)) ↔ (x, y) ∈ c :=
Iff.rfl
@[to_additive]
theorem to_submonoid_inj (c d : Con M) (H : (c : Submonoid (M × M)) = d) : c = d :=
ext fun x y => show (x, y) ∈ c.submonoid ↔ (x, y) ∈ d from H ▸ Iff.rfl
@[to_additive]
theorem le_iff {c d : Con M} : c ≤ d ↔ (c : Submonoid (M × M)) ≤ d :=
⟨fun h _ H => h H, fun h x y hc => h <| show (x, y) ∈ c from hc⟩
variable (x y : M)
@[to_additive (attr := simp)]
-- Porting note: removed dot notation
theorem mrange_mk' : MonoidHom.mrange c.mk' = ⊤ :=
MonoidHom.mrange_eq_top.2 mk'_surjective
variable {f : M →* P}
/-- Given a congruence relation `c` on a monoid and a homomorphism `f` constant on `c`'s
equivalence classes, `f` has the same image as the homomorphism that `f` induces on the
quotient. -/
@[to_additive "Given an additive congruence relation `c` on an `AddMonoid` and a homomorphism `f`
constant on `c`'s equivalence classes, `f` has the same image as the homomorphism that `f` induces
on the quotient."]
theorem lift_range (H : c ≤ ker f) : MonoidHom.mrange (c.lift f H) = MonoidHom.mrange f :=
Submonoid.ext fun x => ⟨by rintro ⟨⟨y⟩, hy⟩; exact ⟨y, hy⟩, fun ⟨y, hy⟩ => ⟨↑y, hy⟩⟩
/-- Given a monoid homomorphism `f`, the induced homomorphism on the quotient by `f`'s kernel has
the same image as `f`. -/
@[to_additive (attr := simp) "Given an `AddMonoid` homomorphism `f`, the induced homomorphism
on the quotient by `f`'s kernel has the same image as `f`."]
theorem kerLift_range_eq : MonoidHom.mrange (kerLift f) = MonoidHom.mrange f :=
lift_range fun _ _ => id
variable (c)
/-- The **first isomorphism theorem for monoids**. -/
@[to_additive "The first isomorphism theorem for `AddMonoid`s."]
noncomputable def quotientKerEquivRange (f : M →* P) : (ker f).Quotient ≃* MonoidHom.mrange f :=
{ Equiv.ofBijective
((@MulEquiv.toMonoidHom (MonoidHom.mrange (kerLift f)) _ _ _ <|
MulEquiv.submonoidCongr kerLift_range_eq).comp
(kerLift f).mrangeRestrict) <|
((Equiv.bijective (@MulEquiv.toEquiv (MonoidHom.mrange (kerLift f)) _ _ _ <|
MulEquiv.submonoidCongr kerLift_range_eq)).comp
⟨fun x y h =>
kerLift_injective f <| by rcases x with ⟨⟩; rcases y with ⟨⟩; injections,
fun ⟨w, z, hz⟩ => ⟨z, by rcases hz with ⟨⟩; rfl⟩⟩) with
map_mul' := MonoidHom.map_mul _ }
/-- The first isomorphism theorem for monoids in the case of a homomorphism with right inverse. -/
@[to_additive (attr := simps)
"The first isomorphism theorem for `AddMonoid`s in the case of a homomorphism
with right inverse."]
def quotientKerEquivOfRightInverse (f : M →* P) (g : P → M) (hf : Function.RightInverse g f) :
(ker f).Quotient ≃* P :=
{ kerLift f with
toFun := kerLift f
invFun := (↑) ∘ g
left_inv := fun x => kerLift_injective _ (by rw [Function.comp_apply, kerLift_mk, hf])
right_inv := fun x => by (conv_rhs => rw [← hf x]); rfl }
/-- The first isomorphism theorem for Monoids in the case of a surjective homomorphism.
For a `computable` version, see `Con.quotientKerEquivOfRightInverse`.
-/
@[to_additive "The first isomorphism theorem for `AddMonoid`s in the case of a surjective
homomorphism.
For a `computable` version, see `AddCon.quotientKerEquivOfRightInverse`.
"]
noncomputable def quotientKerEquivOfSurjective (f : M →* P) (hf : Surjective f) :
(ker f).Quotient ≃* P :=
quotientKerEquivOfRightInverse _ _ hf.hasRightInverse.choose_spec
/-- If e : M →* N is surjective then (c.comap e).Quotient ≃* c.Quotient with c : Con N -/
@[to_additive "If e : M →* N is surjective then (c.comap e).Quotient ≃* c.Quotient with c :
AddCon N"]
noncomputable def comapQuotientEquivOfSurj (c : Con M) (f : N →* M) (hf : Function.Surjective f) :
(Con.comap f f.map_mul c).Quotient ≃* c.Quotient :=
(Con.congr Con.comap_eq).trans <| Con.quotientKerEquivOfSurjective (c.mk'.comp f) <|
Con.mk'_surjective.comp hf
@[to_additive (attr := simp)]
lemma comapQuotientEquivOfSurj_mk (c : Con M) {f : N →* M} (hf : Function.Surjective f) (x : N) :
comapQuotientEquivOfSurj c f hf x = f x := rfl
@[to_additive (attr := simp)]
lemma comapQuotientEquivOfSurj_symm_mk (c : Con M) {f : N →* M} (hf) (x : N) :
(comapQuotientEquivOfSurj c f hf).symm (f x) = x :=
(MulEquiv.symm_apply_eq (c.comapQuotientEquivOfSurj f hf)).mpr rfl
/-- This version infers the surjectivity of the function from a MulEquiv function -/
@[to_additive (attr := simp) "This version infers the surjectivity of the function from a
MulEquiv function"]
lemma comapQuotientEquivOfSurj_symm_mk' (c : Con M) (f : N ≃* M) (x : N) :
((@MulEquiv.symm (Con.Quotient (comap ⇑f _ c)) _ _ _
(comapQuotientEquivOfSurj c (f : N →* M) f.surjective)) ⟦f x⟧) = ↑x :=
(MulEquiv.symm_apply_eq (@comapQuotientEquivOfSurj M N _ _ c f _)).mpr rfl
/-- The **second isomorphism theorem for monoids**. -/
@[to_additive "The second isomorphism theorem for `AddMonoid`s."]
noncomputable def comapQuotientEquiv (f : N →* M) :
(comap f f.map_mul c).Quotient ≃* MonoidHom.mrange (c.mk'.comp f) :=
(Con.congr comap_eq).trans <| quotientKerEquivRange <| c.mk'.comp f
/-- The **third isomorphism theorem for monoids**. -/
@[to_additive "The third isomorphism theorem for `AddMonoid`s."]
def quotientQuotientEquivQuotient (c d : Con M) (h : c ≤ d) :
(ker (c.map d h)).Quotient ≃* d.Quotient :=
{ Setoid.quotientQuotientEquivQuotient c.toSetoid d.toSetoid h with
map_mul' := fun x y =>
Con.induction_on₂ x y fun w z =>
Con.induction_on₂ w z fun a b =>
show _ = d.mk' a * d.mk' b by rw [← d.mk'.map_mul]; rfl }
end MulOneClass
section Monoids
@[to_additive]
theorem smul {α M : Type*} [MulOneClass M] [SMul α M] [IsScalarTower α M M] (c : Con M) (a : α)
{w x : M} (h : c w x) : c (a • w) (a • x) := by
simpa only [smul_one_mul] using c.mul (c.refl' (a • (1 : M) : M)) h
end Monoids
section Actions
@[to_additive]
instance instSMul {α M : Type*} [MulOneClass M] [SMul α M] [IsScalarTower α M M] (c : Con M) :
SMul α c.Quotient where
smul a := (Quotient.map' (a • ·)) fun _ _ => c.smul a
@[to_additive]
theorem coe_smul {α M : Type*} [MulOneClass M] [SMul α M] [IsScalarTower α M M] (c : Con M)
(a : α) (x : M) : (↑(a • x) : c.Quotient) = a • (x : c.Quotient) :=
rfl
instance instSMulCommClass {α β M : Type*} [MulOneClass M] [SMul α M] [SMul β M]
[IsScalarTower α M M] [IsScalarTower β M M] [SMulCommClass α β M] (c : Con M) :
SMulCommClass α β c.Quotient where
smul_comm a b := Quotient.ind' fun m => congr_arg Quotient.mk'' <| smul_comm a b m
instance instIsScalarTower {α β M : Type*} [MulOneClass M] [SMul α β] [SMul α M] [SMul β M]
[IsScalarTower α M M] [IsScalarTower β M M] [IsScalarTower α β M] (c : Con M) :
IsScalarTower α β c.Quotient where
smul_assoc a b := Quotient.ind' fun m => congr_arg Quotient.mk'' <| smul_assoc a b m
instance instIsCentralScalar {α M : Type*} [MulOneClass M] [SMul α M] [SMul αᵐᵒᵖ M]
[IsScalarTower α M M] [IsScalarTower αᵐᵒᵖ M M] [IsCentralScalar α M] (c : Con M) :
IsCentralScalar α c.Quotient where
op_smul_eq_smul a := Quotient.ind' fun m => congr_arg Quotient.mk'' <| op_smul_eq_smul a m
@[to_additive]
instance mulAction {α M : Type*} [Monoid α] [MulOneClass M] [MulAction α M] [IsScalarTower α M M]
(c : Con M) : MulAction α c.Quotient where
one_smul := Quotient.ind' fun _ => congr_arg Quotient.mk'' <| one_smul _ _
mul_smul _ _ := Quotient.ind' fun _ => congr_arg Quotient.mk'' <| mul_smul _ _ _
instance mulDistribMulAction {α M : Type*} [Monoid α] [Monoid M] [MulDistribMulAction α M]
[IsScalarTower α M M] (c : Con M) : MulDistribMulAction α c.Quotient :=
{ smul_one := fun _ => congr_arg Quotient.mk'' <| smul_one _
smul_mul := fun _ => Quotient.ind₂' fun _ _ => congr_arg Quotient.mk'' <| smul_mul' _ _ _ }
end Actions
end Con
| Mathlib/GroupTheory/Congruence/Basic.lean | 648 | 650 | |
/-
Copyright (c) 2018 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sébastien Gouëzel, Johannes Hölzl, Rémy Degenne
-/
import Mathlib.Order.ConditionallyCompleteLattice.Indexed
import Mathlib.Order.Filter.IsBounded
import Mathlib.Order.Hom.CompleteLattice
/-!
# liminfs and limsups of functions and filters
Defines the liminf/limsup of a function taking values in a conditionally complete lattice, with
respect to an arbitrary filter.
We define `limsSup f` (`limsInf f`) where `f` is a filter taking values in a conditionally complete
lattice. `limsSup f` is the smallest element `a` such that, eventually, `u ≤ a` (and vice versa for
`limsInf f`). To work with the Limsup along a function `u` use `limsSup (map u f)`.
Usually, one defines the Limsup as `inf (sup s)` where the Inf is taken over all sets in the filter.
For instance, in ℕ along a function `u`, this is `inf_n (sup_{k ≥ n} u k)` (and the latter quantity
decreases with `n`, so this is in fact a limit.). There is however a difficulty: it is well possible
that `u` is not bounded on the whole space, only eventually (think of `limsup (fun x ↦ 1/x)` on ℝ.
Then there is no guarantee that the quantity above really decreases (the value of the `sup`
beforehand is not really well defined, as one can not use ∞), so that the Inf could be anything.
So one can not use this `inf sup ...` definition in conditionally complete lattices, and one has
to use a less tractable definition.
In conditionally complete lattices, the definition is only useful for filters which are eventually
bounded above (otherwise, the Limsup would morally be +∞, which does not belong to the space) and
which are frequently bounded below (otherwise, the Limsup would morally be -∞, which is not in the
space either). We start with definitions of these concepts for arbitrary filters, before turning to
the definitions of Limsup and Liminf.
In complete lattices, however, it coincides with the `Inf Sup` definition.
-/
open Filter Set Function
variable {α β γ ι ι' : Type*}
namespace Filter
section ConditionallyCompleteLattice
variable [ConditionallyCompleteLattice α] {s : Set α} {u : β → α}
/-- The `limsSup` of a filter `f` is the infimum of the `a` such that, eventually for `f`,
holds `x ≤ a`. -/
def limsSup (f : Filter α) : α :=
sInf { a | ∀ᶠ n in f, n ≤ a }
/-- The `limsInf` of a filter `f` is the supremum of the `a` such that, eventually for `f`,
holds `x ≥ a`. -/
def limsInf (f : Filter α) : α :=
sSup { a | ∀ᶠ n in f, a ≤ n }
/-- The `limsup` of a function `u` along a filter `f` is the infimum of the `a` such that,
eventually for `f`, holds `u x ≤ a`. -/
def limsup (u : β → α) (f : Filter β) : α :=
limsSup (map u f)
/-- The `liminf` of a function `u` along a filter `f` is the supremum of the `a` such that,
eventually for `f`, holds `u x ≥ a`. -/
def liminf (u : β → α) (f : Filter β) : α :=
limsInf (map u f)
/-- The `blimsup` of a function `u` along a filter `f`, bounded by a predicate `p`, is the infimum
of the `a` such that, eventually for `f`, `u x ≤ a` whenever `p x` holds. -/
def blimsup (u : β → α) (f : Filter β) (p : β → Prop) :=
sInf { a | ∀ᶠ x in f, p x → u x ≤ a }
/-- The `bliminf` of a function `u` along a filter `f`, bounded by a predicate `p`, is the supremum
of the `a` such that, eventually for `f`, `a ≤ u x` whenever `p x` holds. -/
def bliminf (u : β → α) (f : Filter β) (p : β → Prop) :=
sSup { a | ∀ᶠ x in f, p x → a ≤ u x }
section
variable {f : Filter β} {u : β → α} {p : β → Prop}
theorem limsup_eq : limsup u f = sInf { a | ∀ᶠ n in f, u n ≤ a } :=
rfl
theorem liminf_eq : liminf u f = sSup { a | ∀ᶠ n in f, a ≤ u n } :=
rfl
theorem blimsup_eq : blimsup u f p = sInf { a | ∀ᶠ x in f, p x → u x ≤ a } :=
rfl
theorem bliminf_eq : bliminf u f p = sSup { a | ∀ᶠ x in f, p x → a ≤ u x } :=
rfl
lemma liminf_comp (u : β → α) (v : γ → β) (f : Filter γ) :
liminf (u ∘ v) f = liminf u (map v f) := rfl
lemma limsup_comp (u : β → α) (v : γ → β) (f : Filter γ) :
limsup (u ∘ v) f = limsup u (map v f) := rfl
end
@[simp]
theorem blimsup_true (f : Filter β) (u : β → α) : (blimsup u f fun _ => True) = limsup u f := by
simp [blimsup_eq, limsup_eq]
@[simp]
theorem bliminf_true (f : Filter β) (u : β → α) : (bliminf u f fun _ => True) = liminf u f := by
simp [bliminf_eq, liminf_eq]
lemma blimsup_eq_limsup {f : Filter β} {u : β → α} {p : β → Prop} :
blimsup u f p = limsup u (f ⊓ 𝓟 {x | p x}) := by
simp only [blimsup_eq, limsup_eq, eventually_inf_principal, mem_setOf_eq]
lemma bliminf_eq_liminf {f : Filter β} {u : β → α} {p : β → Prop} :
bliminf u f p = liminf u (f ⊓ 𝓟 {x | p x}) :=
blimsup_eq_limsup (α := αᵒᵈ)
theorem blimsup_eq_limsup_subtype {f : Filter β} {u : β → α} {p : β → Prop} :
blimsup u f p = limsup (u ∘ ((↑) : { x | p x } → β)) (comap (↑) f) := by
rw [blimsup_eq_limsup, limsup, limsup, ← map_map, map_comap_setCoe_val]
theorem bliminf_eq_liminf_subtype {f : Filter β} {u : β → α} {p : β → Prop} :
bliminf u f p = liminf (u ∘ ((↑) : { x | p x } → β)) (comap (↑) f) :=
blimsup_eq_limsup_subtype (α := αᵒᵈ)
theorem limsSup_le_of_le {f : Filter α} {a}
(hf : f.IsCobounded (· ≤ ·) := by isBoundedDefault)
(h : ∀ᶠ n in f, n ≤ a) : limsSup f ≤ a :=
csInf_le hf h
theorem le_limsInf_of_le {f : Filter α} {a}
(hf : f.IsCobounded (· ≥ ·) := by isBoundedDefault)
(h : ∀ᶠ n in f, a ≤ n) : a ≤ limsInf f :=
le_csSup hf h
theorem limsup_le_of_le {f : Filter β} {u : β → α} {a}
(hf : f.IsCoboundedUnder (· ≤ ·) u := by isBoundedDefault)
(h : ∀ᶠ n in f, u n ≤ a) : limsup u f ≤ a :=
csInf_le hf h
theorem le_liminf_of_le {f : Filter β} {u : β → α} {a}
(hf : f.IsCoboundedUnder (· ≥ ·) u := by isBoundedDefault)
(h : ∀ᶠ n in f, a ≤ u n) : a ≤ liminf u f :=
le_csSup hf h
theorem le_limsSup_of_le {f : Filter α} {a}
(hf : f.IsBounded (· ≤ ·) := by isBoundedDefault)
(h : ∀ b, (∀ᶠ n in f, n ≤ b) → a ≤ b) : a ≤ limsSup f :=
le_csInf hf h
theorem limsInf_le_of_le {f : Filter α} {a}
(hf : f.IsBounded (· ≥ ·) := by isBoundedDefault)
(h : ∀ b, (∀ᶠ n in f, b ≤ n) → b ≤ a) : limsInf f ≤ a :=
csSup_le hf h
theorem le_limsup_of_le {f : Filter β} {u : β → α} {a}
(hf : f.IsBoundedUnder (· ≤ ·) u := by isBoundedDefault)
(h : ∀ b, (∀ᶠ n in f, u n ≤ b) → a ≤ b) : a ≤ limsup u f :=
le_csInf hf h
theorem liminf_le_of_le {f : Filter β} {u : β → α} {a}
(hf : f.IsBoundedUnder (· ≥ ·) u := by isBoundedDefault)
(h : ∀ b, (∀ᶠ n in f, b ≤ u n) → b ≤ a) : liminf u f ≤ a :=
csSup_le hf h
theorem limsInf_le_limsSup {f : Filter α} [NeBot f]
(h₁ : f.IsBounded (· ≤ ·) := by isBoundedDefault)
(h₂ : f.IsBounded (· ≥ ·) := by isBoundedDefault) :
limsInf f ≤ limsSup f :=
liminf_le_of_le h₂ fun a₀ ha₀ =>
le_limsup_of_le h₁ fun a₁ ha₁ =>
show a₀ ≤ a₁ from
let ⟨_, hb₀, hb₁⟩ := (ha₀.and ha₁).exists
le_trans hb₀ hb₁
theorem liminf_le_limsup {f : Filter β} [NeBot f] {u : β → α}
(h : f.IsBoundedUnder (· ≤ ·) u := by isBoundedDefault)
(h' : f.IsBoundedUnder (· ≥ ·) u := by isBoundedDefault) :
liminf u f ≤ limsup u f :=
limsInf_le_limsSup h h'
theorem limsSup_le_limsSup {f g : Filter α}
(hf : f.IsCobounded (· ≤ ·) := by isBoundedDefault)
(hg : g.IsBounded (· ≤ ·) := by isBoundedDefault)
(h : ∀ a, (∀ᶠ n in g, n ≤ a) → ∀ᶠ n in f, n ≤ a) : limsSup f ≤ limsSup g :=
csInf_le_csInf hf hg h
theorem limsInf_le_limsInf {f g : Filter α}
(hf : f.IsBounded (· ≥ ·) := by isBoundedDefault)
(hg : g.IsCobounded (· ≥ ·) := by isBoundedDefault)
(h : ∀ a, (∀ᶠ n in f, a ≤ n) → ∀ᶠ n in g, a ≤ n) : limsInf f ≤ limsInf g :=
csSup_le_csSup hg hf h
theorem limsup_le_limsup {α : Type*} [ConditionallyCompleteLattice β] {f : Filter α} {u v : α → β}
(h : u ≤ᶠ[f] v)
(hu : f.IsCoboundedUnder (· ≤ ·) u := by isBoundedDefault)
(hv : f.IsBoundedUnder (· ≤ ·) v := by isBoundedDefault) :
limsup u f ≤ limsup v f :=
limsSup_le_limsSup hu hv fun _ => h.trans
theorem liminf_le_liminf {α : Type*} [ConditionallyCompleteLattice β] {f : Filter α} {u v : α → β}
(h : ∀ᶠ a in f, u a ≤ v a)
(hu : f.IsBoundedUnder (· ≥ ·) u := by isBoundedDefault)
(hv : f.IsCoboundedUnder (· ≥ ·) v := by isBoundedDefault) :
liminf u f ≤ liminf v f :=
limsup_le_limsup (β := βᵒᵈ) h hv hu
theorem limsSup_le_limsSup_of_le {f g : Filter α} (h : f ≤ g)
(hf : f.IsCobounded (· ≤ ·) := by isBoundedDefault)
(hg : g.IsBounded (· ≤ ·) := by isBoundedDefault) :
limsSup f ≤ limsSup g :=
limsSup_le_limsSup hf hg fun _ ha => h ha
theorem limsInf_le_limsInf_of_le {f g : Filter α} (h : g ≤ f)
(hf : f.IsBounded (· ≥ ·) := by isBoundedDefault)
(hg : g.IsCobounded (· ≥ ·) := by isBoundedDefault) :
limsInf f ≤ limsInf g :=
limsInf_le_limsInf hf hg fun _ ha => h ha
theorem limsup_le_limsup_of_le {α β} [ConditionallyCompleteLattice β] {f g : Filter α} (h : f ≤ g)
{u : α → β}
(hf : f.IsCoboundedUnder (· ≤ ·) u := by isBoundedDefault)
(hg : g.IsBoundedUnder (· ≤ ·) u := by isBoundedDefault) :
limsup u f ≤ limsup u g :=
limsSup_le_limsSup_of_le (map_mono h) hf hg
theorem liminf_le_liminf_of_le {α β} [ConditionallyCompleteLattice β] {f g : Filter α} (h : g ≤ f)
{u : α → β}
(hf : f.IsBoundedUnder (· ≥ ·) u := by isBoundedDefault)
(hg : g.IsCoboundedUnder (· ≥ ·) u := by isBoundedDefault) :
liminf u f ≤ liminf u g :=
limsInf_le_limsInf_of_le (map_mono h) hf hg
lemma limsSup_principal_eq_csSup (h : BddAbove s) (hs : s.Nonempty) : limsSup (𝓟 s) = sSup s := by
simp only [limsSup, eventually_principal]; exact csInf_upperBounds_eq_csSup h hs
lemma limsInf_principal_eq_csSup (h : BddBelow s) (hs : s.Nonempty) : limsInf (𝓟 s) = sInf s :=
limsSup_principal_eq_csSup (α := αᵒᵈ) h hs
lemma limsup_top_eq_ciSup [Nonempty β] (hu : BddAbove (range u)) : limsup u ⊤ = ⨆ i, u i := by
rw [limsup, map_top, limsSup_principal_eq_csSup hu (range_nonempty _), sSup_range]
lemma liminf_top_eq_ciInf [Nonempty β] (hu : BddBelow (range u)) : liminf u ⊤ = ⨅ i, u i := by
rw [liminf, map_top, limsInf_principal_eq_csSup hu (range_nonempty _), sInf_range]
theorem limsup_congr {α : Type*} [ConditionallyCompleteLattice β] {f : Filter α} {u v : α → β}
(h : ∀ᶠ a in f, u a = v a) : limsup u f = limsup v f := by
rw [limsup_eq]
congr with b
exact eventually_congr (h.mono fun x hx => by simp [hx])
theorem blimsup_congr {f : Filter β} {u v : β → α} {p : β → Prop} (h : ∀ᶠ a in f, p a → u a = v a) :
blimsup u f p = blimsup v f p := by
simpa only [blimsup_eq_limsup] using limsup_congr <| eventually_inf_principal.2 h
theorem bliminf_congr {f : Filter β} {u v : β → α} {p : β → Prop} (h : ∀ᶠ a in f, p a → u a = v a) :
bliminf u f p = bliminf v f p :=
blimsup_congr (α := αᵒᵈ) h
theorem liminf_congr {α : Type*} [ConditionallyCompleteLattice β] {f : Filter α} {u v : α → β}
(h : ∀ᶠ a in f, u a = v a) : liminf u f = liminf v f :=
limsup_congr (β := βᵒᵈ) h
@[simp]
theorem limsup_const {α : Type*} [ConditionallyCompleteLattice β] {f : Filter α} [NeBot f]
(b : β) : limsup (fun _ => b) f = b := by
simpa only [limsup_eq, eventually_const] using csInf_Ici
@[simp]
theorem liminf_const {α : Type*} [ConditionallyCompleteLattice β] {f : Filter α} [NeBot f]
(b : β) : liminf (fun _ => b) f = b :=
limsup_const (β := βᵒᵈ) b
theorem HasBasis.liminf_eq_sSup_iUnion_iInter {ι ι' : Type*} {f : ι → α} {v : Filter ι}
{p : ι' → Prop} {s : ι' → Set ι} (hv : v.HasBasis p s) :
liminf f v = sSup (⋃ (j : Subtype p), ⋂ (i : s j), Iic (f i)) := by
simp_rw [liminf_eq, hv.eventually_iff]
congr
ext x
simp only [mem_setOf_eq, iInter_coe_set, mem_iUnion, mem_iInter, mem_Iic, Subtype.exists,
exists_prop]
theorem HasBasis.liminf_eq_sSup_univ_of_empty {f : ι → α} {v : Filter ι}
{p : ι' → Prop} {s : ι' → Set ι} (hv : v.HasBasis p s) (i : ι') (hi : p i) (h'i : s i = ∅) :
liminf f v = sSup univ := by
simp [hv.eq_bot_iff.2 ⟨i, hi, h'i⟩, liminf_eq]
theorem HasBasis.limsup_eq_sInf_iUnion_iInter {ι ι' : Type*} {f : ι → α} {v : Filter ι}
{p : ι' → Prop} {s : ι' → Set ι} (hv : v.HasBasis p s) :
limsup f v = sInf (⋃ (j : Subtype p), ⋂ (i : s j), Ici (f i)) :=
HasBasis.liminf_eq_sSup_iUnion_iInter (α := αᵒᵈ) hv
theorem HasBasis.limsup_eq_sInf_univ_of_empty {f : ι → α} {v : Filter ι}
{p : ι' → Prop} {s : ι' → Set ι} (hv : v.HasBasis p s) (i : ι') (hi : p i) (h'i : s i = ∅) :
limsup f v = sInf univ :=
HasBasis.liminf_eq_sSup_univ_of_empty (α := αᵒᵈ) hv i hi h'i
@[simp]
theorem liminf_nat_add (f : ℕ → α) (k : ℕ) :
liminf (fun i => f (i + k)) atTop = liminf f atTop := by
rw [← Function.comp_def, liminf, liminf, ← map_map, map_add_atTop_eq_nat]
@[simp]
theorem limsup_nat_add (f : ℕ → α) (k : ℕ) : limsup (fun i => f (i + k)) atTop = limsup f atTop :=
@liminf_nat_add αᵒᵈ _ f k
end ConditionallyCompleteLattice
section CompleteLattice
variable [CompleteLattice α]
@[simp]
theorem limsSup_bot : limsSup (⊥ : Filter α) = ⊥ :=
bot_unique <| sInf_le <| by simp
@[simp] theorem limsup_bot (f : β → α) : limsup f ⊥ = ⊥ := by simp [limsup]
@[simp]
theorem limsInf_bot : limsInf (⊥ : Filter α) = ⊤ :=
top_unique <| le_sSup <| by simp
@[simp] theorem liminf_bot (f : β → α) : liminf f ⊥ = ⊤ := by simp [liminf]
@[simp]
theorem limsSup_top : limsSup (⊤ : Filter α) = ⊤ :=
top_unique <| le_sInf <| by simpa [eq_univ_iff_forall] using fun b hb => top_unique <| hb _
@[simp]
theorem limsInf_top : limsInf (⊤ : Filter α) = ⊥ :=
bot_unique <| sSup_le <| by simpa [eq_univ_iff_forall] using fun b hb => bot_unique <| hb _
@[simp]
theorem blimsup_false {f : Filter β} {u : β → α} : (blimsup u f fun _ => False) = ⊥ := by
simp [blimsup_eq]
@[simp]
theorem bliminf_false {f : Filter β} {u : β → α} : (bliminf u f fun _ => False) = ⊤ := by
simp [bliminf_eq]
/-- Same as limsup_const applied to `⊥` but without the `NeBot f` assumption -/
@[simp]
theorem limsup_const_bot {f : Filter β} : limsup (fun _ : β => (⊥ : α)) f = (⊥ : α) := by
rw [limsup_eq, eq_bot_iff]
exact sInf_le (Eventually.of_forall fun _ => le_rfl)
/-- Same as limsup_const applied to `⊤` but without the `NeBot f` assumption -/
@[simp]
theorem liminf_const_top {f : Filter β} : liminf (fun _ : β => (⊤ : α)) f = (⊤ : α) :=
limsup_const_bot (α := αᵒᵈ)
theorem HasBasis.limsSup_eq_iInf_sSup {ι} {p : ι → Prop} {s} {f : Filter α} (h : f.HasBasis p s) :
limsSup f = ⨅ (i) (_ : p i), sSup (s i) :=
le_antisymm (le_iInf₂ fun i hi => sInf_le <| h.eventually_iff.2 ⟨i, hi, fun _ => le_sSup⟩)
(le_sInf fun _ ha =>
let ⟨_, hi, ha⟩ := h.eventually_iff.1 ha
iInf₂_le_of_le _ hi <| sSup_le ha)
theorem HasBasis.limsInf_eq_iSup_sInf {p : ι → Prop} {s : ι → Set α} {f : Filter α}
(h : f.HasBasis p s) : limsInf f = ⨆ (i) (_ : p i), sInf (s i) :=
HasBasis.limsSup_eq_iInf_sSup (α := αᵒᵈ) h
theorem limsSup_eq_iInf_sSup {f : Filter α} : limsSup f = ⨅ s ∈ f, sSup s :=
f.basis_sets.limsSup_eq_iInf_sSup
theorem limsInf_eq_iSup_sInf {f : Filter α} : limsInf f = ⨆ s ∈ f, sInf s :=
limsSup_eq_iInf_sSup (α := αᵒᵈ)
theorem limsup_le_iSup {f : Filter β} {u : β → α} : limsup u f ≤ ⨆ n, u n :=
limsup_le_of_le (by isBoundedDefault) (Eventually.of_forall (le_iSup u))
theorem iInf_le_liminf {f : Filter β} {u : β → α} : ⨅ n, u n ≤ liminf u f :=
le_liminf_of_le (by isBoundedDefault) (Eventually.of_forall (iInf_le u))
/-- In a complete lattice, the limsup of a function is the infimum over sets `s` in the filter
of the supremum of the function over `s` -/
theorem limsup_eq_iInf_iSup {f : Filter β} {u : β → α} : limsup u f = ⨅ s ∈ f, ⨆ a ∈ s, u a :=
(f.basis_sets.map u).limsSup_eq_iInf_sSup.trans <| by simp only [sSup_image, id]
theorem limsup_eq_iInf_iSup_of_nat {u : ℕ → α} : limsup u atTop = ⨅ n : ℕ, ⨆ i ≥ n, u i :=
(atTop_basis.map u).limsSup_eq_iInf_sSup.trans <| by simp only [sSup_image, iInf_const]; rfl
theorem limsup_eq_iInf_iSup_of_nat' {u : ℕ → α} : limsup u atTop = ⨅ n : ℕ, ⨆ i : ℕ, u (i + n) := by
simp only [limsup_eq_iInf_iSup_of_nat, iSup_ge_eq_iSup_nat_add]
theorem HasBasis.limsup_eq_iInf_iSup {p : ι → Prop} {s : ι → Set β} {f : Filter β} {u : β → α}
(h : f.HasBasis p s) : limsup u f = ⨅ (i) (_ : p i), ⨆ a ∈ s i, u a :=
(h.map u).limsSup_eq_iInf_sSup.trans <| by simp only [sSup_image, id]
lemma limsSup_principal_eq_sSup (s : Set α) : limsSup (𝓟 s) = sSup s := by
simpa only [limsSup, eventually_principal] using sInf_upperBounds_eq_csSup s
lemma limsInf_principal_eq_sInf (s : Set α) : limsInf (𝓟 s) = sInf s := by
simpa only [limsInf, eventually_principal] using sSup_lowerBounds_eq_sInf s
@[simp] lemma limsup_top_eq_iSup (u : β → α) : limsup u ⊤ = ⨆ i, u i := by
rw [limsup, map_top, limsSup_principal_eq_sSup, sSup_range]
@[simp] lemma liminf_top_eq_iInf (u : β → α) : liminf u ⊤ = ⨅ i, u i := by
rw [liminf, map_top, limsInf_principal_eq_sInf, sInf_range]
theorem blimsup_congr' {f : Filter β} {p q : β → Prop} {u : β → α}
(h : ∀ᶠ x in f, u x ≠ ⊥ → (p x ↔ q x)) : blimsup u f p = blimsup u f q := by
simp only [blimsup_eq]
congr with a
refine eventually_congr (h.mono fun b hb => ?_)
rcases eq_or_ne (u b) ⊥ with hu | hu; · simp [hu]
rw [hb hu]
theorem bliminf_congr' {f : Filter β} {p q : β → Prop} {u : β → α}
(h : ∀ᶠ x in f, u x ≠ ⊤ → (p x ↔ q x)) : bliminf u f p = bliminf u f q :=
blimsup_congr' (α := αᵒᵈ) h
lemma HasBasis.blimsup_eq_iInf_iSup {p : ι → Prop} {s : ι → Set β} {f : Filter β} {u : β → α}
(hf : f.HasBasis p s) {q : β → Prop} :
blimsup u f q = ⨅ (i) (_ : p i), ⨆ a ∈ s i, ⨆ (_ : q a), u a := by
simp only [blimsup_eq_limsup, (hf.inf_principal _).limsup_eq_iInf_iSup, mem_inter_iff, iSup_and,
mem_setOf_eq]
theorem blimsup_eq_iInf_biSup {f : Filter β} {p : β → Prop} {u : β → α} :
blimsup u f p = ⨅ s ∈ f, ⨆ (b) (_ : p b ∧ b ∈ s), u b := by
simp only [f.basis_sets.blimsup_eq_iInf_iSup, iSup_and', id, and_comm]
theorem blimsup_eq_iInf_biSup_of_nat {p : ℕ → Prop} {u : ℕ → α} :
blimsup u atTop p = ⨅ i, ⨆ (j) (_ : p j ∧ i ≤ j), u j := by
simp only [atTop_basis.blimsup_eq_iInf_iSup, @and_comm (p _), iSup_and, mem_Ici, iInf_true]
/-- In a complete lattice, the liminf of a function is the infimum over sets `s` in the filter
of the supremum of the function over `s` -/
theorem liminf_eq_iSup_iInf {f : Filter β} {u : β → α} : liminf u f = ⨆ s ∈ f, ⨅ a ∈ s, u a :=
limsup_eq_iInf_iSup (α := αᵒᵈ)
theorem liminf_eq_iSup_iInf_of_nat {u : ℕ → α} : liminf u atTop = ⨆ n : ℕ, ⨅ i ≥ n, u i :=
@limsup_eq_iInf_iSup_of_nat αᵒᵈ _ u
theorem liminf_eq_iSup_iInf_of_nat' {u : ℕ → α} : liminf u atTop = ⨆ n : ℕ, ⨅ i : ℕ, u (i + n) :=
@limsup_eq_iInf_iSup_of_nat' αᵒᵈ _ _
theorem HasBasis.liminf_eq_iSup_iInf {p : ι → Prop} {s : ι → Set β} {f : Filter β} {u : β → α}
(h : f.HasBasis p s) : liminf u f = ⨆ (i) (_ : p i), ⨅ a ∈ s i, u a :=
HasBasis.limsup_eq_iInf_iSup (α := αᵒᵈ) h
theorem bliminf_eq_iSup_biInf {f : Filter β} {p : β → Prop} {u : β → α} :
bliminf u f p = ⨆ s ∈ f, ⨅ (b) (_ : p b ∧ b ∈ s), u b :=
@blimsup_eq_iInf_biSup αᵒᵈ β _ f p u
theorem bliminf_eq_iSup_biInf_of_nat {p : ℕ → Prop} {u : ℕ → α} :
bliminf u atTop p = ⨆ i, ⨅ (j) (_ : p j ∧ i ≤ j), u j :=
@blimsup_eq_iInf_biSup_of_nat αᵒᵈ _ p u
theorem limsup_eq_sInf_sSup {ι R : Type*} (F : Filter ι) [CompleteLattice R] (a : ι → R) :
limsup a F = sInf ((fun I => sSup (a '' I)) '' F.sets) := by
apply le_antisymm
· rw [limsup_eq]
refine sInf_le_sInf fun x hx => ?_
rcases (mem_image _ F.sets x).mp hx with ⟨I, ⟨I_mem_F, hI⟩⟩
filter_upwards [I_mem_F] with i hi
exact hI ▸ le_sSup (mem_image_of_mem _ hi)
· refine le_sInf fun b hb => sInf_le_of_le (mem_image_of_mem _ hb) <| sSup_le ?_
rintro _ ⟨_, h, rfl⟩
exact h
theorem liminf_eq_sSup_sInf {ι R : Type*} (F : Filter ι) [CompleteLattice R] (a : ι → R) :
liminf a F = sSup ((fun I => sInf (a '' I)) '' F.sets) :=
@Filter.limsup_eq_sInf_sSup ι (OrderDual R) _ _ a
theorem liminf_le_of_frequently_le' {α β} [CompleteLattice β] {f : Filter α} {u : α → β} {x : β}
(h : ∃ᶠ a in f, u a ≤ x) : liminf u f ≤ x := by
rw [liminf_eq]
refine sSup_le fun b hb => ?_
have hbx : ∃ᶠ _ in f, b ≤ x := by
revert h
rw [← not_imp_not, not_frequently, not_frequently]
exact fun h => hb.mp (h.mono fun a hbx hba hax => hbx (hba.trans hax))
exact hbx.exists.choose_spec
theorem le_limsup_of_frequently_le' {α β} [CompleteLattice β] {f : Filter α} {u : α → β} {x : β}
(h : ∃ᶠ a in f, x ≤ u a) : x ≤ limsup u f :=
liminf_le_of_frequently_le' (β := βᵒᵈ) h
/-- If `f : α → α` is a morphism of complete lattices, then the limsup of its iterates of any
`a : α` is a fixed point. -/
@[simp]
theorem _root_.CompleteLatticeHom.apply_limsup_iterate (f : CompleteLatticeHom α α) (a : α) :
f (limsup (fun n => f^[n] a) atTop) = limsup (fun n => f^[n] a) atTop := by
rw [limsup_eq_iInf_iSup_of_nat', map_iInf]
simp_rw [_root_.map_iSup, ← Function.comp_apply (f := f), ← Function.iterate_succ' f,
← Nat.add_succ]
conv_rhs => rw [iInf_split _ (0 < ·)]
simp only [not_lt, Nat.le_zero, iInf_iInf_eq_left, add_zero, iInf_nat_gt_zero_eq, left_eq_inf]
refine (iInf_le (fun i => ⨆ j, f^[j + (i + 1)] a) 0).trans ?_
simp only [zero_add, Function.comp_apply, iSup_le_iff]
exact fun i => le_iSup (fun i => f^[i] a) (i + 1)
/-- If `f : α → α` is a morphism of complete lattices, then the liminf of its iterates of any
`a : α` is a fixed point. -/
theorem _root_.CompleteLatticeHom.apply_liminf_iterate (f : CompleteLatticeHom α α) (a : α) :
f (liminf (fun n => f^[n] a) atTop) = liminf (fun n => f^[n] a) atTop :=
(CompleteLatticeHom.dual f).apply_limsup_iterate _
variable {f g : Filter β} {p q : β → Prop} {u v : β → α}
theorem blimsup_mono (h : ∀ x, p x → q x) : blimsup u f p ≤ blimsup u f q :=
sInf_le_sInf fun a ha => ha.mono <| by tauto
theorem bliminf_antitone (h : ∀ x, p x → q x) : bliminf u f q ≤ bliminf u f p :=
sSup_le_sSup fun a ha => ha.mono <| by tauto
theorem mono_blimsup' (h : ∀ᶠ x in f, p x → u x ≤ v x) : blimsup u f p ≤ blimsup v f p :=
sInf_le_sInf fun _ ha => (ha.and h).mono fun _ hx hx' => (hx.2 hx').trans (hx.1 hx')
theorem mono_blimsup (h : ∀ x, p x → u x ≤ v x) : blimsup u f p ≤ blimsup v f p :=
mono_blimsup' <| Eventually.of_forall h
theorem mono_bliminf' (h : ∀ᶠ x in f, p x → u x ≤ v x) : bliminf u f p ≤ bliminf v f p :=
sSup_le_sSup fun _ ha => (ha.and h).mono fun _ hx hx' => (hx.1 hx').trans (hx.2 hx')
theorem mono_bliminf (h : ∀ x, p x → u x ≤ v x) : bliminf u f p ≤ bliminf v f p :=
mono_bliminf' <| Eventually.of_forall h
theorem bliminf_antitone_filter (h : f ≤ g) : bliminf u g p ≤ bliminf u f p :=
sSup_le_sSup fun _ ha => ha.filter_mono h
theorem blimsup_monotone_filter (h : f ≤ g) : blimsup u f p ≤ blimsup u g p :=
sInf_le_sInf fun _ ha => ha.filter_mono h
theorem blimsup_and_le_inf : (blimsup u f fun x => p x ∧ q x) ≤ blimsup u f p ⊓ blimsup u f q :=
le_inf (blimsup_mono <| by tauto) (blimsup_mono <| by tauto)
@[simp]
theorem bliminf_sup_le_inf_aux_left :
(blimsup u f fun x => p x ∧ q x) ≤ blimsup u f p :=
blimsup_and_le_inf.trans inf_le_left
@[simp]
theorem bliminf_sup_le_inf_aux_right :
(blimsup u f fun x => p x ∧ q x) ≤ blimsup u f q :=
blimsup_and_le_inf.trans inf_le_right
theorem bliminf_sup_le_and : bliminf u f p ⊔ bliminf u f q ≤ bliminf u f fun x => p x ∧ q x :=
blimsup_and_le_inf (α := αᵒᵈ)
@[simp]
theorem bliminf_sup_le_and_aux_left : bliminf u f p ≤ bliminf u f fun x => p x ∧ q x :=
le_sup_left.trans bliminf_sup_le_and
@[simp]
theorem bliminf_sup_le_and_aux_right : bliminf u f q ≤ bliminf u f fun x => p x ∧ q x :=
le_sup_right.trans bliminf_sup_le_and
/-- See also `Filter.blimsup_or_eq_sup`. -/
theorem blimsup_sup_le_or : blimsup u f p ⊔ blimsup u f q ≤ blimsup u f fun x => p x ∨ q x :=
sup_le (blimsup_mono <| by tauto) (blimsup_mono <| by tauto)
@[simp]
theorem bliminf_sup_le_or_aux_left : blimsup u f p ≤ blimsup u f fun x => p x ∨ q x :=
le_sup_left.trans blimsup_sup_le_or
@[simp]
theorem bliminf_sup_le_or_aux_right : blimsup u f q ≤ blimsup u f fun x => p x ∨ q x :=
le_sup_right.trans blimsup_sup_le_or
/-- See also `Filter.bliminf_or_eq_inf`. -/
theorem bliminf_or_le_inf : (bliminf u f fun x => p x ∨ q x) ≤ bliminf u f p ⊓ bliminf u f q :=
blimsup_sup_le_or (α := αᵒᵈ)
@[simp]
theorem bliminf_or_le_inf_aux_left : (bliminf u f fun x => p x ∨ q x) ≤ bliminf u f p :=
bliminf_or_le_inf.trans inf_le_left
@[simp]
theorem bliminf_or_le_inf_aux_right : (bliminf u f fun x => p x ∨ q x) ≤ bliminf u f q :=
bliminf_or_le_inf.trans inf_le_right
theorem _root_.OrderIso.apply_blimsup [CompleteLattice γ] (e : α ≃o γ) :
e (blimsup u f p) = blimsup (e ∘ u) f p := by
simp only [blimsup_eq, map_sInf, Function.comp_apply, e.image_eq_preimage,
Set.preimage_setOf_eq, e.le_symm_apply]
theorem _root_.OrderIso.apply_bliminf [CompleteLattice γ] (e : α ≃o γ) :
e (bliminf u f p) = bliminf (e ∘ u) f p :=
e.dual.apply_blimsup
theorem _root_.sSupHom.apply_blimsup_le [CompleteLattice γ] (g : sSupHom α γ) :
g (blimsup u f p) ≤ blimsup (g ∘ u) f p := by
simp only [blimsup_eq_iInf_biSup, Function.comp]
refine ((OrderHomClass.mono g).map_iInf₂_le _).trans ?_
simp only [_root_.map_iSup, le_refl]
theorem _root_.sInfHom.le_apply_bliminf [CompleteLattice γ] (g : sInfHom α γ) :
bliminf (g ∘ u) f p ≤ g (bliminf u f p) :=
(sInfHom.dual g).apply_blimsup_le
end CompleteLattice
section CompleteDistribLattice
variable [CompleteDistribLattice α] {f : Filter β} {p q : β → Prop} {u : β → α}
lemma limsup_sup_filter {g} : limsup u (f ⊔ g) = limsup u f ⊔ limsup u g := by
refine le_antisymm ?_
(sup_le (limsup_le_limsup_of_le le_sup_left) (limsup_le_limsup_of_le le_sup_right))
simp_rw [limsup_eq, sInf_sup_eq, sup_sInf_eq, mem_setOf_eq, le_iInf₂_iff]
intro a ha b hb
exact sInf_le ⟨ha.mono fun _ h ↦ h.trans le_sup_left, hb.mono fun _ h ↦ h.trans le_sup_right⟩
lemma liminf_sup_filter {g} : liminf u (f ⊔ g) = liminf u f ⊓ liminf u g :=
limsup_sup_filter (α := αᵒᵈ)
@[simp]
theorem blimsup_or_eq_sup : (blimsup u f fun x => p x ∨ q x) = blimsup u f p ⊔ blimsup u f q := by
simp only [blimsup_eq_limsup, ← limsup_sup_filter, ← inf_sup_left, sup_principal, setOf_or]
@[simp]
theorem bliminf_or_eq_inf : (bliminf u f fun x => p x ∨ q x) = bliminf u f p ⊓ bliminf u f q :=
blimsup_or_eq_sup (α := αᵒᵈ)
@[simp]
lemma blimsup_sup_not : blimsup u f p ⊔ blimsup u f (¬p ·) = limsup u f := by
simp_rw [← blimsup_or_eq_sup, or_not, blimsup_true]
@[simp]
lemma bliminf_inf_not : bliminf u f p ⊓ bliminf u f (¬p ·) = liminf u f :=
blimsup_sup_not (α := αᵒᵈ)
@[simp]
lemma blimsup_not_sup : blimsup u f (¬p ·) ⊔ blimsup u f p = limsup u f := by
simpa only [not_not] using blimsup_sup_not (p := (¬p ·))
@[simp]
lemma bliminf_not_inf : bliminf u f (¬p ·) ⊓ bliminf u f p = liminf u f :=
blimsup_not_sup (α := αᵒᵈ)
lemma limsup_piecewise {s : Set β} [DecidablePred (· ∈ s)] {v} :
limsup (s.piecewise u v) f = blimsup u f (· ∈ s) ⊔ blimsup v f (· ∉ s) := by
rw [← blimsup_sup_not (p := (· ∈ s))]
refine congr_arg₂ _ (blimsup_congr ?_) (blimsup_congr ?_) <;>
filter_upwards with _ h using by simp [h]
lemma liminf_piecewise {s : Set β} [DecidablePred (· ∈ s)] {v} :
liminf (s.piecewise u v) f = bliminf u f (· ∈ s) ⊓ bliminf v f (· ∉ s) :=
limsup_piecewise (α := αᵒᵈ)
theorem sup_limsup [NeBot f] (a : α) : a ⊔ limsup u f = limsup (fun x => a ⊔ u x) f := by
simp only [limsup_eq_iInf_iSup, iSup_sup_eq, sup_iInf₂_eq]
congr; ext s; congr; ext hs; congr
exact (biSup_const (nonempty_of_mem hs)).symm
theorem inf_liminf [NeBot f] (a : α) : a ⊓ liminf u f = liminf (fun x => a ⊓ u x) f :=
sup_limsup (α := αᵒᵈ) a
theorem sup_liminf (a : α) : a ⊔ liminf u f = liminf (fun x => a ⊔ u x) f := by
simp only [liminf_eq_iSup_iInf]
rw [sup_comm, biSup_sup (⟨univ, univ_mem⟩ : ∃ i : Set β, i ∈ f)]
simp_rw [iInf₂_sup_eq, sup_comm (a := a)]
theorem inf_limsup (a : α) : a ⊓ limsup u f = limsup (fun x => a ⊓ u x) f :=
sup_liminf (α := αᵒᵈ) a
end CompleteDistribLattice
section CompleteBooleanAlgebra
variable [CompleteBooleanAlgebra α] (f : Filter β) (u : β → α)
theorem limsup_compl : (limsup u f)ᶜ = liminf (compl ∘ u) f := by
simp only [limsup_eq_iInf_iSup, compl_iInf, compl_iSup, liminf_eq_iSup_iInf, Function.comp_apply]
theorem liminf_compl : (liminf u f)ᶜ = limsup (compl ∘ u) f := by
simp only [limsup_eq_iInf_iSup, compl_iInf, compl_iSup, liminf_eq_iSup_iInf, Function.comp_apply]
theorem limsup_sdiff (a : α) : limsup u f \ a = limsup (fun b => u b \ a) f := by
simp only [limsup_eq_iInf_iSup, sdiff_eq]
rw [biInf_inf (⟨univ, univ_mem⟩ : ∃ i : Set β, i ∈ f)]
simp_rw [inf_comm, inf_iSup₂_eq, inf_comm]
theorem liminf_sdiff [NeBot f] (a : α) : liminf u f \ a = liminf (fun b => u b \ a) f := by
simp only [sdiff_eq, inf_comm _ aᶜ, inf_liminf]
theorem sdiff_limsup [NeBot f] (a : α) : a \ limsup u f = liminf (fun b => a \ u b) f := by
rw [← compl_inj_iff]
simp only [sdiff_eq, liminf_compl, comp_def, compl_inf, compl_compl, sup_limsup]
theorem sdiff_liminf (a : α) : a \ liminf u f = limsup (fun b => a \ u b) f := by
rw [← compl_inj_iff]
simp only [sdiff_eq, limsup_compl, comp_def, compl_inf, compl_compl, sup_liminf]
end CompleteBooleanAlgebra
section SetLattice
variable {p : ι → Prop} {s : ι → Set α} {𝓕 : Filter ι} {a : α}
lemma mem_liminf_iff_eventually_mem : (a ∈ liminf s 𝓕) ↔ (∀ᶠ i in 𝓕, a ∈ s i) := by
simpa only [liminf_eq_iSup_iInf, iSup_eq_iUnion, iInf_eq_iInter, mem_iUnion, mem_iInter]
using ⟨fun ⟨S, hS, hS'⟩ ↦ mem_of_superset hS (by tauto), fun h ↦ ⟨{i | a ∈ s i}, h, by tauto⟩⟩
lemma mem_limsup_iff_frequently_mem : (a ∈ limsup s 𝓕) ↔ (∃ᶠ i in 𝓕, a ∈ s i) := by
simp only [Filter.Frequently, iff_not_comm, ← mem_compl_iff, limsup_compl, comp_apply,
mem_liminf_iff_eventually_mem]
theorem cofinite.blimsup_set_eq :
blimsup s cofinite p = { x | { n | p n ∧ x ∈ s n }.Infinite } := by
simp only [blimsup_eq, le_eq_subset, eventually_cofinite, not_forall, sInf_eq_sInter, exists_prop]
ext x
refine ⟨fun h => ?_, fun hx t h => ?_⟩ <;> contrapose! h
· simp only [mem_sInter, mem_setOf_eq, not_forall, exists_prop]
exact ⟨{x}ᶜ, by simpa using h, by simp⟩
· exact hx.mono fun i hi => ⟨hi.1, fun hit => h (hit hi.2)⟩
theorem cofinite.bliminf_set_eq : bliminf s cofinite p = { x | { n | p n ∧ x ∉ s n }.Finite } := by
rw [← compl_inj_iff]
simp only [bliminf_eq_iSup_biInf, compl_iInf, compl_iSup, ← blimsup_eq_iInf_biSup,
cofinite.blimsup_set_eq]
rfl
/-- In other words, `limsup cofinite s` is the set of elements lying inside the family `s`
infinitely often. -/
theorem cofinite.limsup_set_eq : limsup s cofinite = { x | { n | x ∈ s n }.Infinite } := by
simp only [← cofinite.blimsup_true s, cofinite.blimsup_set_eq, true_and]
/-- In other words, `liminf cofinite s` is the set of elements lying outside the family `s`
finitely often. -/
theorem cofinite.liminf_set_eq : liminf s cofinite = { x | { n | x ∉ s n }.Finite } := by
simp only [← cofinite.bliminf_true s, cofinite.bliminf_set_eq, true_and]
theorem exists_forall_mem_of_hasBasis_mem_blimsup {l : Filter β} {b : ι → Set β} {q : ι → Prop}
(hl : l.HasBasis q b) {u : β → Set α} {p : β → Prop} {x : α} (hx : x ∈ blimsup u l p) :
∃ f : { i | q i } → β, ∀ i, x ∈ u (f i) ∧ p (f i) ∧ f i ∈ b i := by
rw [blimsup_eq_iInf_biSup] at hx
simp only [iSup_eq_iUnion, iInf_eq_iInter, mem_iInter, mem_iUnion, exists_prop] at hx
choose g hg hg' using hx
refine ⟨fun i : { i | q i } => g (b i) (hl.mem_of_mem i.2), fun i => ⟨?_, ?_⟩⟩
· exact hg' (b i) (hl.mem_of_mem i.2)
· exact hg (b i) (hl.mem_of_mem i.2)
theorem exists_forall_mem_of_hasBasis_mem_blimsup' {l : Filter β} {b : ι → Set β}
(hl : l.HasBasis (fun _ => True) b) {u : β → Set α} {p : β → Prop} {x : α}
(hx : x ∈ blimsup u l p) : ∃ f : ι → β, ∀ i, x ∈ u (f i) ∧ p (f i) ∧ f i ∈ b i := by
obtain ⟨f, hf⟩ := exists_forall_mem_of_hasBasis_mem_blimsup hl hx
exact ⟨fun i => f ⟨i, trivial⟩, fun i => hf ⟨i, trivial⟩⟩
end SetLattice
section ConditionallyCompleteLinearOrder
theorem frequently_lt_of_lt_limsSup {f : Filter α} [ConditionallyCompleteLinearOrder α] {a : α}
(hf : f.IsCobounded (· ≤ ·) := by isBoundedDefault)
(h : a < limsSup f) : ∃ᶠ n in f, a < n := by
contrapose! h
simp only [not_frequently, not_lt] at h
exact limsSup_le_of_le hf h
theorem frequently_lt_of_limsInf_lt {f : Filter α} [ConditionallyCompleteLinearOrder α] {a : α}
(hf : f.IsCobounded (· ≥ ·) := by isBoundedDefault)
(h : limsInf f < a) : ∃ᶠ n in f, n < a :=
frequently_lt_of_lt_limsSup (α := OrderDual α) hf h
theorem eventually_lt_of_lt_liminf {f : Filter α} [ConditionallyCompleteLinearOrder β] {u : α → β}
{b : β} (h : b < liminf u f)
(hu : f.IsBoundedUnder (· ≥ ·) u := by isBoundedDefault) :
∀ᶠ a in f, b < u a := by
obtain ⟨c, hc, hbc⟩ : ∃ (c : β) (_ : c ∈ { c : β | ∀ᶠ n : α in f, c ≤ u n }), b < c := by
simp_rw [exists_prop]
exact exists_lt_of_lt_csSup hu h
exact hc.mono fun x hx => lt_of_lt_of_le hbc hx
theorem eventually_lt_of_limsup_lt {f : Filter α} [ConditionallyCompleteLinearOrder β] {u : α → β}
{b : β} (h : limsup u f < b)
(hu : f.IsBoundedUnder (· ≤ ·) u := by isBoundedDefault) :
∀ᶠ a in f, u a < b :=
eventually_lt_of_lt_liminf (β := βᵒᵈ) h hu
section ConditionallyCompleteLinearOrder
variable [ConditionallyCompleteLinearOrder α]
/-- If `Filter.limsup u atTop ≤ x`, then for all `ε > 0`, eventually we have `u b < x + ε`. -/
theorem eventually_lt_add_pos_of_limsup_le [Preorder β] [AddZeroClass α] [AddLeftStrictMono α]
{x ε : α} {u : β → α} (hu_bdd : IsBoundedUnder LE.le atTop u) (hu : Filter.limsup u atTop ≤ x)
(hε : 0 < ε) :
∀ᶠ b : β in atTop, u b < x + ε :=
eventually_lt_of_limsup_lt (lt_of_le_of_lt hu (lt_add_of_pos_right x hε)) hu_bdd
/-- If `x ≤ Filter.liminf u atTop`, then for all `ε < 0`, eventually we have `x + ε < u b`. -/
theorem eventually_add_neg_lt_of_le_liminf [Preorder β] [AddZeroClass α] [AddLeftStrictMono α]
{x ε : α} {u : β → α} (hu_bdd : IsBoundedUnder GE.ge atTop u) (hu : x ≤ Filter.liminf u atTop)
(hε : ε < 0) :
| ∀ᶠ b : β in atTop, x + ε < u b :=
eventually_lt_of_lt_liminf (lt_of_lt_of_le (add_lt_of_neg_right x hε) hu) hu_bdd
| Mathlib/Order/LiminfLimsup.lean | 789 | 791 |
/-
Copyright (c) 2019 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov
-/
import Mathlib.Algebra.Order.BigOperators.Ring.Finset
import Mathlib.Analysis.Convex.Hull
import Mathlib.LinearAlgebra.AffineSpace.Basis
/-!
# Convex combinations
This file defines convex combinations of points in a vector space.
## Main declarations
* `Finset.centerMass`: Center of mass of a finite family of points.
## Implementation notes
We divide by the sum of the weights in the definition of `Finset.centerMass` because of the way
mathematical arguments go: one doesn't change weights, but merely adds some. This also makes a few
lemmas unconditional on the sum of the weights being `1`.
-/
open Set Function Pointwise
universe u u'
section
variable {R R' E F ι ι' α : Type*} [Field R] [Field R'] [AddCommGroup E] [AddCommGroup F]
[AddCommGroup α] [LinearOrder α] [Module R E] [Module R F] [Module R α] {s : Set E}
/-- Center of mass of a finite collection of points with prescribed weights.
Note that we require neither `0 ≤ w i` nor `∑ w = 1`. -/
def Finset.centerMass (t : Finset ι) (w : ι → R) (z : ι → E) : E :=
(∑ i ∈ t, w i)⁻¹ • ∑ i ∈ t, w i • z i
variable (i j : ι) (c : R) (t : Finset ι) (w : ι → R) (z : ι → E)
open Finset
theorem Finset.centerMass_empty : (∅ : Finset ι).centerMass w z = 0 := by
simp only [centerMass, sum_empty, smul_zero]
theorem Finset.centerMass_pair [DecidableEq ι] (hne : i ≠ j) :
({i, j} : Finset ι).centerMass w z = (w i / (w i + w j)) • z i + (w j / (w i + w j)) • z j := by
simp only [centerMass, sum_pair hne]
module
variable {w}
theorem Finset.centerMass_insert [DecidableEq ι] (ha : i ∉ t) (hw : ∑ j ∈ t, w j ≠ 0) :
(insert i t).centerMass w z =
(w i / (w i + ∑ j ∈ t, w j)) • z i +
((∑ j ∈ t, w j) / (w i + ∑ j ∈ t, w j)) • t.centerMass w z := by
simp only [centerMass, sum_insert ha, smul_add, (mul_smul _ _ _).symm, ← div_eq_inv_mul]
congr 2
rw [div_mul_eq_mul_div, mul_inv_cancel₀ hw, one_div]
theorem Finset.centerMass_singleton (hw : w i ≠ 0) : ({i} : Finset ι).centerMass w z = z i := by
rw [centerMass, sum_singleton, sum_singleton]
match_scalars
field_simp
@[simp] lemma Finset.centerMass_neg_left : t.centerMass (-w) z = t.centerMass w z := by
simp [centerMass, inv_neg]
lemma Finset.centerMass_smul_left {c : R'} [Module R' R] [Module R' E] [SMulCommClass R' R R]
[IsScalarTower R' R R] [SMulCommClass R R' E] [IsScalarTower R' R E] (hc : c ≠ 0) :
t.centerMass (c • w) z = t.centerMass w z := by
simp [centerMass, -smul_assoc, smul_assoc c, ← smul_sum, smul_inv₀, smul_smul_smul_comm, hc]
theorem Finset.centerMass_eq_of_sum_1 (hw : ∑ i ∈ t, w i = 1) :
t.centerMass w z = ∑ i ∈ t, w i • z i := by
simp only [Finset.centerMass, hw, inv_one, one_smul]
theorem Finset.centerMass_smul : (t.centerMass w fun i => c • z i) = c • t.centerMass w z := by
simp only [Finset.centerMass, Finset.smul_sum, (mul_smul _ _ _).symm, mul_comm c, mul_assoc]
/-- A convex combination of two centers of mass is a center of mass as well. This version
deals with two different index types. -/
theorem Finset.centerMass_segment' (s : Finset ι) (t : Finset ι') (ws : ι → R) (zs : ι → E)
(wt : ι' → R) (zt : ι' → E) (hws : ∑ i ∈ s, ws i = 1) (hwt : ∑ i ∈ t, wt i = 1) (a b : R)
(hab : a + b = 1) : a • s.centerMass ws zs + b • t.centerMass wt zt = (s.disjSum t).centerMass
(Sum.elim (fun i => a * ws i) fun j => b * wt j) (Sum.elim zs zt) := by
rw [s.centerMass_eq_of_sum_1 _ hws, t.centerMass_eq_of_sum_1 _ hwt, smul_sum, smul_sum, ←
Finset.sum_sumElim, Finset.centerMass_eq_of_sum_1]
· congr with ⟨⟩ <;> simp only [Sum.elim_inl, Sum.elim_inr, mul_smul]
· rw [sum_sumElim, ← mul_sum, ← mul_sum, hws, hwt, mul_one, mul_one, hab]
/-- A convex combination of two centers of mass is a center of mass as well. This version
works if two centers of mass share the set of original points. -/
theorem Finset.centerMass_segment (s : Finset ι) (w₁ w₂ : ι → R) (z : ι → E)
(hw₁ : ∑ i ∈ s, w₁ i = 1) (hw₂ : ∑ i ∈ s, w₂ i = 1) (a b : R) (hab : a + b = 1) :
a • s.centerMass w₁ z + b • s.centerMass w₂ z =
s.centerMass (fun i => a * w₁ i + b * w₂ i) z := by
have hw : (∑ i ∈ s, (a * w₁ i + b * w₂ i)) = 1 := by
simp only [← mul_sum, sum_add_distrib, mul_one, *]
simp only [Finset.centerMass_eq_of_sum_1, Finset.centerMass_eq_of_sum_1 _ _ hw,
smul_sum, sum_add_distrib, add_smul, mul_smul, *]
theorem Finset.centerMass_ite_eq [DecidableEq ι] (hi : i ∈ t) :
t.centerMass (fun j => if i = j then (1 : R) else 0) z = z i := by
rw [Finset.centerMass_eq_of_sum_1]
· trans ∑ j ∈ t, if i = j then z i else 0
· congr with i
split_ifs with h
exacts [h ▸ one_smul _ _, zero_smul _ _]
· rw [sum_ite_eq, if_pos hi]
· rw [sum_ite_eq, if_pos hi]
variable {t}
theorem Finset.centerMass_subset {t' : Finset ι} (ht : t ⊆ t') (h : ∀ i ∈ t', i ∉ t → w i = 0) :
t.centerMass w z = t'.centerMass w z := by
rw [centerMass, sum_subset ht h, smul_sum, centerMass, smul_sum]
apply sum_subset ht
intro i hit' hit
rw [h i hit' hit, zero_smul, smul_zero]
theorem Finset.centerMass_filter_ne_zero [∀ i, Decidable (w i ≠ 0)] :
{i ∈ t | w i ≠ 0}.centerMass w z = t.centerMass w z :=
Finset.centerMass_subset z (filter_subset _ _) fun i hit hit' => by
simpa only [hit, mem_filter, true_and, Ne, Classical.not_not] using hit'
namespace Finset
variable [LinearOrder R] [IsStrictOrderedRing R] [IsOrderedAddMonoid α] [OrderedSMul R α]
theorem centerMass_le_sup {s : Finset ι} {f : ι → α} {w : ι → R} (hw₀ : ∀ i ∈ s, 0 ≤ w i)
(hw₁ : 0 < ∑ i ∈ s, w i) :
s.centerMass w f ≤ s.sup' (nonempty_of_ne_empty <| by rintro rfl; simp at hw₁) f := by
rw [centerMass, inv_smul_le_iff_of_pos hw₁, sum_smul]
exact sum_le_sum fun i hi => smul_le_smul_of_nonneg_left (le_sup' _ hi) <| hw₀ i hi
theorem inf_le_centerMass {s : Finset ι} {f : ι → α} {w : ι → R} (hw₀ : ∀ i ∈ s, 0 ≤ w i)
(hw₁ : 0 < ∑ i ∈ s, w i) :
s.inf' (nonempty_of_ne_empty <| by rintro rfl; simp at hw₁) f ≤ s.centerMass w f :=
centerMass_le_sup (α := αᵒᵈ) hw₀ hw₁
end Finset
variable {z}
lemma Finset.centerMass_of_sum_add_sum_eq_zero {s t : Finset ι}
(hw : ∑ i ∈ s, w i + ∑ i ∈ t, w i = 0) (hz : ∑ i ∈ s, w i • z i + ∑ i ∈ t, w i • z i = 0) :
s.centerMass w z = t.centerMass w z := by
simp [centerMass, eq_neg_of_add_eq_zero_right hw, eq_neg_of_add_eq_zero_left hz, ← neg_inv]
variable [LinearOrder R] [IsStrictOrderedRing R] [IsOrderedAddMonoid α] [OrderedSMul R α]
/-- The center of mass of a finite subset of a convex set belongs to the set
provided that all weights are non-negative, and the total weight is positive. -/
theorem Convex.centerMass_mem (hs : Convex R s) :
(∀ i ∈ t, 0 ≤ w i) → (0 < ∑ i ∈ t, w i) → (∀ i ∈ t, z i ∈ s) → t.centerMass w z ∈ s := by
classical
induction' t using Finset.induction with i t hi ht
· simp [lt_irrefl]
intro h₀ hpos hmem
have zi : z i ∈ s := hmem _ (mem_insert_self _ _)
have hs₀ : ∀ j ∈ t, 0 ≤ w j := fun j hj => h₀ j <| mem_insert_of_mem hj
rw [sum_insert hi] at hpos
by_cases hsum_t : ∑ j ∈ t, w j = 0
· have ws : ∀ j ∈ t, w j = 0 := (sum_eq_zero_iff_of_nonneg hs₀).1 hsum_t
have wz : ∑ j ∈ t, w j • z j = 0 := sum_eq_zero fun i hi => by simp [ws i hi]
simp only [centerMass, sum_insert hi, wz, hsum_t, add_zero]
simp only [hsum_t, add_zero] at hpos
rw [← mul_smul, inv_mul_cancel₀ (ne_of_gt hpos), one_smul]
exact zi
· rw [Finset.centerMass_insert _ _ _ hi hsum_t]
refine convex_iff_div.1 hs zi (ht hs₀ ?_ ?_) ?_ (sum_nonneg hs₀) hpos
· exact lt_of_le_of_ne (sum_nonneg hs₀) (Ne.symm hsum_t)
· intro j hj
exact hmem j (mem_insert_of_mem hj)
· exact h₀ _ (mem_insert_self _ _)
theorem Convex.sum_mem (hs : Convex R s) (h₀ : ∀ i ∈ t, 0 ≤ w i) (h₁ : ∑ i ∈ t, w i = 1)
(hz : ∀ i ∈ t, z i ∈ s) : (∑ i ∈ t, w i • z i) ∈ s := by
simpa only [h₁, centerMass, inv_one, one_smul] using
hs.centerMass_mem h₀ (h₁.symm ▸ zero_lt_one) hz
/-- A version of `Convex.sum_mem` for `finsum`s. If `s` is a convex set, `w : ι → R` is a family of
nonnegative weights with sum one and `z : ι → E` is a family of elements of a module over `R` such
that `z i ∈ s` whenever `w i ≠ 0`, then the sum `∑ᶠ i, w i • z i` belongs to `s`. See also
`PartitionOfUnity.finsum_smul_mem_convex`. -/
theorem Convex.finsum_mem {ι : Sort*} {w : ι → R} {z : ι → E} {s : Set E} (hs : Convex R s)
(h₀ : ∀ i, 0 ≤ w i) (h₁ : ∑ᶠ i, w i = 1) (hz : ∀ i, w i ≠ 0 → z i ∈ s) :
(∑ᶠ i, w i • z i) ∈ s := by
have hfin_w : (support (w ∘ PLift.down)).Finite := by
by_contra H
rw [finsum, dif_neg H] at h₁
exact zero_ne_one h₁
have hsub : support ((fun i => w i • z i) ∘ PLift.down) ⊆ hfin_w.toFinset :=
(support_smul_subset_left _ _).trans hfin_w.coe_toFinset.ge
rw [finsum_eq_sum_plift_of_support_subset hsub]
refine hs.sum_mem (fun _ _ => h₀ _) ?_ fun i hi => hz _ ?_
· rwa [finsum, dif_pos hfin_w] at h₁
· rwa [hfin_w.mem_toFinset] at hi
theorem convex_iff_sum_mem : Convex R s ↔ ∀ (t : Finset E) (w : E → R),
(∀ i ∈ t, 0 ≤ w i) → ∑ i ∈ t, w i = 1 → (∀ x ∈ t, x ∈ s) → (∑ x ∈ t, w x • x) ∈ s := by
classical
refine ⟨fun hs t w hw₀ hw₁ hts => hs.sum_mem hw₀ hw₁ hts, ?_⟩
intro h x hx y hy a b ha hb hab
by_cases h_cases : x = y
· rw [h_cases, ← add_smul, hab, one_smul]
exact hy
· convert h {x, y} (fun z => if z = y then b else a) _ _ _
· simp only [sum_pair h_cases, if_neg h_cases, if_pos trivial]
· intro i _
simp only
split_ifs <;> assumption
· simp only [sum_pair h_cases, if_neg h_cases, if_pos trivial, hab]
· intro i hi
simp only [Finset.mem_singleton, Finset.mem_insert] at hi
cases hi <;> subst i <;> assumption
theorem Finset.centerMass_mem_convexHull (t : Finset ι) {w : ι → R} (hw₀ : ∀ i ∈ t, 0 ≤ w i)
(hws : 0 < ∑ i ∈ t, w i) {z : ι → E} (hz : ∀ i ∈ t, z i ∈ s) :
t.centerMass w z ∈ convexHull R s :=
(convex_convexHull R s).centerMass_mem hw₀ hws fun i hi => subset_convexHull R s <| hz i hi
/-- A version of `Finset.centerMass_mem_convexHull` for when the weights are nonpositive. -/
lemma Finset.centerMass_mem_convexHull_of_nonpos (t : Finset ι) (hw₀ : ∀ i ∈ t, w i ≤ 0)
(hws : ∑ i ∈ t, w i < 0) (hz : ∀ i ∈ t, z i ∈ s) : t.centerMass w z ∈ convexHull R s := by
rw [← centerMass_neg_left]
exact Finset.centerMass_mem_convexHull _ (fun _i hi ↦ neg_nonneg.2 <| hw₀ _ hi) (by simpa) hz
/-- A refinement of `Finset.centerMass_mem_convexHull` when the indexed family is a `Finset` of
the space. -/
theorem Finset.centerMass_id_mem_convexHull (t : Finset E) {w : E → R} (hw₀ : ∀ i ∈ t, 0 ≤ w i)
(hws : 0 < ∑ i ∈ t, w i) : t.centerMass w id ∈ convexHull R (t : Set E) :=
t.centerMass_mem_convexHull hw₀ hws fun _ => mem_coe.2
/-- A version of `Finset.centerMass_mem_convexHull` for when the weights are nonpositive. -/
lemma Finset.centerMass_id_mem_convexHull_of_nonpos (t : Finset E) {w : E → R}
(hw₀ : ∀ i ∈ t, w i ≤ 0) (hws : ∑ i ∈ t, w i < 0) :
t.centerMass w id ∈ convexHull R (t : Set E) :=
t.centerMass_mem_convexHull_of_nonpos hw₀ hws fun _ ↦ mem_coe.2
omit [LinearOrder R] [IsStrictOrderedRing R] in
theorem affineCombination_eq_centerMass {ι : Type*} {t : Finset ι} {p : ι → E} {w : ι → R}
(hw₂ : ∑ i ∈ t, w i = 1) : t.affineCombination R p w = centerMass t w p := by
rw [affineCombination_eq_weightedVSubOfPoint_vadd_of_sum_eq_one _ w _ hw₂ (0 : E),
Finset.weightedVSubOfPoint_apply, vadd_eq_add, add_zero, t.centerMass_eq_of_sum_1 _ hw₂]
simp_rw [vsub_eq_sub, sub_zero]
theorem affineCombination_mem_convexHull {s : Finset ι} {v : ι → E} {w : ι → R}
(hw₀ : ∀ i ∈ s, 0 ≤ w i) (hw₁ : s.sum w = 1) :
s.affineCombination R v w ∈ convexHull R (range v) := by
rw [affineCombination_eq_centerMass hw₁]
apply s.centerMass_mem_convexHull hw₀
· simp [hw₁]
· simp
/-- The centroid can be regarded as a center of mass. -/
@[simp]
theorem Finset.centroid_eq_centerMass (s : Finset ι) (hs : s.Nonempty) (p : ι → E) :
s.centroid R p = s.centerMass (s.centroidWeights R) p :=
affineCombination_eq_centerMass (s.sum_centroidWeights_eq_one_of_nonempty R hs)
theorem Finset.centroid_mem_convexHull (s : Finset E) (hs : s.Nonempty) :
s.centroid R id ∈ convexHull R (s : Set E) := by
rw [s.centroid_eq_centerMass hs]
apply s.centerMass_id_mem_convexHull
· simp only [inv_nonneg, imp_true_iff, Nat.cast_nonneg, Finset.centroidWeights_apply]
· have hs_card : (#s : R) ≠ 0 := by simp [Finset.nonempty_iff_ne_empty.mp hs]
simp only [hs_card, Finset.sum_const, nsmul_eq_mul, mul_inv_cancel₀, Ne, not_false_iff,
Finset.centroidWeights_apply, zero_lt_one]
theorem convexHull_range_eq_exists_affineCombination (v : ι → E) : convexHull R (range v) =
{ x | ∃ (s : Finset ι) (w : ι → R), (∀ i ∈ s, 0 ≤ w i) ∧ s.sum w = 1 ∧
s.affineCombination R v w = x } := by
classical
refine Subset.antisymm (convexHull_min ?_ ?_) ?_
· intro x hx
obtain ⟨i, hi⟩ := Set.mem_range.mp hx
exact ⟨{i}, Function.const ι (1 : R), by simp, by simp, by simp [hi]⟩
· rintro x ⟨s, w, hw₀, hw₁, rfl⟩ y ⟨s', w', hw₀', hw₁', rfl⟩ a b ha hb hab
let W : ι → R := fun i => (if i ∈ s then a * w i else 0) + if i ∈ s' then b * w' i else 0
have hW₁ : (s ∪ s').sum W = 1 := by
rw [sum_add_distrib, ← sum_subset subset_union_left,
← sum_subset subset_union_right, sum_ite_of_true,
sum_ite_of_true, ← mul_sum, ← mul_sum, hw₁, hw₁', ← add_mul, hab,
mul_one] <;> intros <;> simp_all
refine ⟨s ∪ s', W, ?_, hW₁, ?_⟩
· rintro i -
by_cases hi : i ∈ s <;> by_cases hi' : i ∈ s' <;>
simp [W, hi, hi', add_nonneg, mul_nonneg ha (hw₀ i _), mul_nonneg hb (hw₀' i _)]
· simp_rw [W, affineCombination_eq_linear_combination (s ∪ s') v _ hW₁,
affineCombination_eq_linear_combination s v w hw₁,
affineCombination_eq_linear_combination s' v w' hw₁', add_smul, sum_add_distrib]
rw [← sum_subset subset_union_left, ← sum_subset subset_union_right]
· simp only [ite_smul, sum_ite_of_true fun _ hi => hi, mul_smul, ← smul_sum]
· intro i _ hi'
simp [hi']
· intro i _ hi'
simp [hi']
· rintro x ⟨s, w, hw₀, hw₁, rfl⟩
exact affineCombination_mem_convexHull hw₀ hw₁
/--
Convex hull of `s` is equal to the set of all centers of masses of `Finset`s `t`, `z '' t ⊆ s`.
For universe reasons, you shouldn't use this lemma to prove that a given center of mass belongs
to the convex hull. Use convexity of the convex hull instead.
-/
theorem convexHull_eq (s : Set E) : convexHull R s =
{ x : E | ∃ (ι : Type) (t : Finset ι) (w : ι → R) (z : ι → E), (∀ i ∈ t, 0 ≤ w i) ∧
∑ i ∈ t, w i = 1 ∧ (∀ i ∈ t, z i ∈ s) ∧ t.centerMass w z = x } := by
refine Subset.antisymm (convexHull_min ?_ ?_) ?_
· intro x hx
use PUnit, {PUnit.unit}, fun _ => 1, fun _ => x, fun _ _ => zero_le_one, sum_singleton _ _,
fun _ _ => hx
simp only [Finset.centerMass, Finset.sum_singleton, inv_one, one_smul]
· rintro x ⟨ι, sx, wx, zx, hwx₀, hwx₁, hzx, rfl⟩ y ⟨ι', sy, wy, zy, hwy₀, hwy₁, hzy, rfl⟩ a b ha
hb hab
rw [Finset.centerMass_segment' _ _ _ _ _ _ hwx₁ hwy₁ _ _ hab]
refine ⟨_, _, _, _, ?_, ?_, ?_, rfl⟩
· rintro i hi
rw [Finset.mem_disjSum] at hi
rcases hi with (⟨j, hj, rfl⟩ | ⟨j, hj, rfl⟩) <;> simp only [Sum.elim_inl, Sum.elim_inr] <;>
apply_rules [mul_nonneg, hwx₀, hwy₀]
· simp [Finset.sum_sumElim, ← mul_sum, *]
· intro i hi
rw [Finset.mem_disjSum] at hi
rcases hi with (⟨j, hj, rfl⟩ | ⟨j, hj, rfl⟩) <;> apply_rules [hzx, hzy]
· rintro _ ⟨ι, t, w, z, hw₀, hw₁, hz, rfl⟩
exact t.centerMass_mem_convexHull hw₀ (hw₁.symm ▸ zero_lt_one) hz
/-- Universe polymorphic version of the reverse implication of `mem_convexHull_iff_exists_fintype`.
-/
lemma mem_convexHull_of_exists_fintype {s : Set E} {x : E} [Fintype ι] (w : ι → R) (z : ι → E)
(hw₀ : ∀ i, 0 ≤ w i) (hw₁ : ∑ i, w i = 1) (hz : ∀ i, z i ∈ s) (hx : ∑ i, w i • z i = x) :
x ∈ convexHull R s := by
rw [← hx, ← centerMass_eq_of_sum_1 _ _ hw₁]
exact centerMass_mem_convexHull _ (by simpa using hw₀) (by simp [hw₁]) (by simpa using hz)
/-- The convex hull of `s` is equal to the set of centers of masses of finite families of points in
`s`.
For universe reasons, you shouldn't use this lemma to prove that a given center of mass belongs
to the convex hull. Use `mem_convexHull_of_exists_fintype` of the convex hull instead. -/
lemma mem_convexHull_iff_exists_fintype {s : Set E} {x : E} :
x ∈ convexHull R s ↔ ∃ (ι : Type) (_ : Fintype ι) (w : ι → R) (z : ι → E), (∀ i, 0 ≤ w i) ∧
∑ i, w i = 1 ∧ (∀ i, z i ∈ s) ∧ ∑ i, w i • z i = x := by
constructor
· simp only [convexHull_eq, mem_setOf_eq]
rintro ⟨ι, t, w, z, h⟩
refine ⟨t, inferInstance, w ∘ (↑), z ∘ (↑), ?_⟩
simpa [← sum_attach t, centerMass_eq_of_sum_1 _ _ h.2.1] using h
· rintro ⟨ι, _, w, z, hw₀, hw₁, hz, hx⟩
exact mem_convexHull_of_exists_fintype w z hw₀ hw₁ hz hx
theorem Finset.convexHull_eq (s : Finset E) : convexHull R ↑s =
{ x : E | ∃ w : E → R, (∀ y ∈ s, 0 ≤ w y) ∧ ∑ y ∈ s, w y = 1 ∧ s.centerMass w id = x } := by
classical
refine Set.Subset.antisymm (convexHull_min ?_ ?_) ?_
· intro x hx
rw [Finset.mem_coe] at hx
refine ⟨_, ?_, ?_, Finset.centerMass_ite_eq _ _ _ hx⟩
· intros
split_ifs
exacts [zero_le_one, le_refl 0]
· rw [Finset.sum_ite_eq, if_pos hx]
· rintro x ⟨wx, hwx₀, hwx₁, rfl⟩ y ⟨wy, hwy₀, hwy₁, rfl⟩ a b ha hb hab
rw [Finset.centerMass_segment _ _ _ _ hwx₁ hwy₁ _ _ hab]
refine ⟨_, ?_, ?_, rfl⟩
· rintro i hi
apply_rules [add_nonneg, mul_nonneg, hwx₀, hwy₀]
· simp only [Finset.sum_add_distrib, ← mul_sum, mul_one, *]
· rintro _ ⟨w, hw₀, hw₁, rfl⟩
exact
s.centerMass_mem_convexHull (fun x hx => hw₀ _ hx) (hw₁.symm ▸ zero_lt_one) fun x hx => hx
theorem Finset.mem_convexHull {s : Finset E} {x : E} : x ∈ convexHull R (s : Set E) ↔
∃ w : E → R, (∀ y ∈ s, 0 ≤ w y) ∧ ∑ y ∈ s, w y = 1 ∧ s.centerMass w id = x := by
| rw [Finset.convexHull_eq, Set.mem_setOf_eq]
/-- This is a version of `Finset.mem_convexHull` stated without `Finset.centerMass`. -/
lemma Finset.mem_convexHull' {s : Finset E} {x : E} :
x ∈ convexHull R (s : Set E) ↔
∃ w : E → R, (∀ y ∈ s, 0 ≤ w y) ∧ ∑ y ∈ s, w y = 1 ∧ ∑ y ∈ s, w y • y = x := by
rw [mem_convexHull]
| Mathlib/Analysis/Convex/Combination.lean | 379 | 385 |
/-
Copyright (c) 2024 Oliver Nash. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Oliver Nash
-/
import Mathlib.Algebra.DirectSum.LinearMap
import Mathlib.Algebra.Lie.Weights.Cartan
import Mathlib.Data.Int.Interval
import Mathlib.LinearAlgebra.Trace
import Mathlib.RingTheory.Finiteness.Nilpotent
/-!
# Chains of roots and weights
Given roots `α` and `β` of a Lie algebra, together with elements `x` in the `α`-root space and
`y` in the `β`-root space, it follows from the Leibniz identity that `⁅x, y⁆` is either zero or
belongs to the `α + β`-root space. Iterating this operation leads to the study of families of
roots of the form `k • α + β`. Such a family is known as the `α`-chain through `β` (or sometimes,
the `α`-string through `β`) and the study of the sum of the corresponding root spaces is an
important technique.
More generally if `α` is a root and `χ` is a weight of a representation, it is useful to study the
`α`-chain through `χ`.
We provide basic definitions and results to support `α`-chain techniques in this file.
## Main definitions / results
* `LieModule.exists₂_genWeightSpace_smul_add_eq_bot`: given weights `χ₁`, `χ₂` if `χ₁ ≠ 0`, we can
find `p < 0` and `q > 0` such that the weight spaces `p • χ₁ + χ₂` and `q • χ₁ + χ₂` are both
trivial.
* `LieModule.genWeightSpaceChain`: given weights `χ₁`, `χ₂` together with integers `p` and `q`,
this is the sum of the weight spaces `k • χ₁ + χ₂` for `p < k < q`.
* `LieModule.trace_toEnd_genWeightSpaceChain_eq_zero`: given a root `α` relative to a Cartan
subalgebra `H`, there is a natural ideal `corootSpace α` in `H`. This lemma
states that this ideal acts by trace-zero endomorphisms on the sum of root spaces of any
`α`-chain, provided the weight spaces at the endpoints are both trivial.
* `LieModule.exists_forall_mem_corootSpace_smul_add_eq_zero`: given a (potential) root
`α` relative to a Cartan subalgebra `H`, if we restrict to the ideal
`corootSpace α` of `H`, we may find an integral linear combination between
`α` and any weight `χ` of a representation.
## TODO
It should be possible to unify some of the definitions here such as `LieModule.chainBotCoeff`,
`LieModule.chainTopCoeff` with corresponding definitions such as `RootPairing.chainBotCoeff`,
`RootPairing.chainTopCoeff`. This is not quite trivial since:
* The definitions here allow for chains in representations of Lie algebras.
* The proof that the roots of a Lie algebra are a root system currently depends on these results.
(This can be resolved by proving the root reflection formula using the approach outlined in
Bourbaki Ch. VIII §2.2 Lemma 1 (page 80 of English translation, 88 of English PDF).)
-/
open Module Function Set
variable {R L : Type*} [CommRing R] [LieRing L] [LieAlgebra R L]
(M : Type*) [AddCommGroup M] [Module R M] [LieRingModule L M] [LieModule R L M]
namespace LieModule
section IsNilpotent
variable [LieRing.IsNilpotent L] (χ₁ χ₂ : L → R) (p q : ℤ)
section
variable [NoZeroSMulDivisors ℤ R] [NoZeroSMulDivisors R M] [IsNoetherian R M] (hχ₁ : χ₁ ≠ 0)
include hχ₁
lemma eventually_genWeightSpace_smul_add_eq_bot :
∀ᶠ (k : ℕ) in Filter.atTop, genWeightSpace M (k • χ₁ + χ₂) = ⊥ := by
let f : ℕ → L → R := fun k ↦ k • χ₁ + χ₂
suffices Injective f by
rw [← Nat.cofinite_eq_atTop, Filter.eventually_cofinite, ← finite_image_iff this.injOn]
apply (finite_genWeightSpace_ne_bot R L M).subset
simp [f]
intro k l hkl
replace hkl : (k : ℤ) • χ₁ = (l : ℤ) • χ₁ := by
simpa only [f, add_left_inj, natCast_zsmul] using hkl
exact Nat.cast_inj.mp <| smul_left_injective ℤ hχ₁ hkl
lemma exists_genWeightSpace_smul_add_eq_bot :
∃ k > 0, genWeightSpace M (k • χ₁ + χ₂) = ⊥ :=
(Nat.eventually_pos.and <| eventually_genWeightSpace_smul_add_eq_bot M χ₁ χ₂ hχ₁).exists
lemma exists₂_genWeightSpace_smul_add_eq_bot :
∃ᵉ (p < (0 : ℤ)) (q > (0 : ℤ)),
genWeightSpace M (p • χ₁ + χ₂) = ⊥ ∧
genWeightSpace M (q • χ₁ + χ₂) = ⊥ := by
obtain ⟨q, hq₀, hq⟩ := exists_genWeightSpace_smul_add_eq_bot M χ₁ χ₂ hχ₁
obtain ⟨p, hp₀, hp⟩ := exists_genWeightSpace_smul_add_eq_bot M (-χ₁) χ₂ (neg_ne_zero.mpr hχ₁)
refine ⟨-(p : ℤ), by simpa, q, by simpa, ?_, ?_⟩
· rw [neg_smul, ← smul_neg, natCast_zsmul]
exact hp
· rw [natCast_zsmul]
exact hq
end
/-- Given two (potential) weights `χ₁` and `χ₂` together with integers `p` and `q`, it is often
useful to study the sum of weight spaces associated to the family of weights `k • χ₁ + χ₂` for
`p < k < q`. -/
def genWeightSpaceChain : LieSubmodule R L M :=
⨆ k ∈ Ioo p q, genWeightSpace M (k • χ₁ + χ₂)
lemma genWeightSpaceChain_def :
genWeightSpaceChain M χ₁ χ₂ p q = ⨆ k ∈ Ioo p q, genWeightSpace M (k • χ₁ + χ₂) :=
rfl
lemma genWeightSpaceChain_def' :
genWeightSpaceChain M χ₁ χ₂ p q = ⨆ k ∈ Finset.Ioo p q, genWeightSpace M (k • χ₁ + χ₂) := by
have : ∀ (k : ℤ), k ∈ Ioo p q ↔ k ∈ Finset.Ioo p q := by simp
simp_rw [genWeightSpaceChain_def, this]
@[simp]
lemma genWeightSpaceChain_neg :
genWeightSpaceChain M (-χ₁) χ₂ (-q) (-p) = genWeightSpaceChain M χ₁ χ₂ p q := by
let e : ℤ ≃ ℤ := neg_involutive.toPerm
simp_rw [genWeightSpaceChain, ← e.biSup_comp (Ioo p q)]
simp [e, -mem_Ioo, neg_mem_Ioo_iff]
lemma genWeightSpace_le_genWeightSpaceChain {k : ℤ} (hk : k ∈ Ioo p q) :
genWeightSpace M (k • χ₁ + χ₂) ≤ genWeightSpaceChain M χ₁ χ₂ p q :=
le_biSup (fun i ↦ genWeightSpace M (i • χ₁ + χ₂)) hk
end IsNilpotent
section LieSubalgebra
open LieAlgebra
variable {H : LieSubalgebra R L} (α χ : H → R) (p q : ℤ)
lemma lie_mem_genWeightSpaceChain_of_genWeightSpace_eq_bot_right [LieRing.IsNilpotent H]
(hq : genWeightSpace M (q • α + χ) = ⊥)
{x : L} (hx : x ∈ rootSpace H α)
{y : M} (hy : y ∈ genWeightSpaceChain M α χ p q) :
⁅x, y⁆ ∈ genWeightSpaceChain M α χ p q := by
rw [genWeightSpaceChain, iSup_subtype'] at hy
induction hy using LieSubmodule.iSup_induction' with
| mem k z hz =>
obtain ⟨k, hk⟩ := k
suffices genWeightSpace M ((k + 1) • α + χ) ≤ genWeightSpaceChain M α χ p q by
apply this
-- was `simpa using [...]` and very slow
-- (https://github.com/leanprover-community/mathlib4/issues/19751)
simpa only [zsmul_eq_mul, Int.cast_add, Pi.intCast_def, Int.cast_one] using
(rootSpaceWeightSpaceProduct R L H M α (k • α + χ) ((k + 1) • α + χ)
(by rw [add_smul]; abel) (⟨x, hx⟩ ⊗ₜ ⟨z, hz⟩)).property
rw [genWeightSpaceChain]
rcases eq_or_ne (k + 1) q with rfl | hk'; · simp only [hq, bot_le]
replace hk' : k + 1 ∈ Ioo p q := ⟨by linarith [hk.1], lt_of_le_of_ne hk.2 hk'⟩
exact le_biSup (fun k ↦ genWeightSpace M (k • α + χ)) hk'
| zero => simp
| add _ _ _ _ hz₁ hz₂ => rw [lie_add]; exact add_mem hz₁ hz₂
lemma lie_mem_genWeightSpaceChain_of_genWeightSpace_eq_bot_left [LieRing.IsNilpotent H]
(hp : genWeightSpace M (p • α + χ) = ⊥)
{x : L} (hx : x ∈ rootSpace H (-α))
{y : M} (hy : y ∈ genWeightSpaceChain M α χ p q) :
⁅x, y⁆ ∈ genWeightSpaceChain M α χ p q := by
replace hp : genWeightSpace M ((-p) • (-α) + χ) = ⊥ := by rwa [smul_neg, neg_smul, neg_neg]
rw [← genWeightSpaceChain_neg] at hy ⊢
exact lie_mem_genWeightSpaceChain_of_genWeightSpace_eq_bot_right M (-α) χ (-q) (-p) hp hx hy
section IsCartanSubalgebra
variable [H.IsCartanSubalgebra] [IsNoetherian R L]
lemma trace_toEnd_genWeightSpaceChain_eq_zero
(hp : genWeightSpace M (p • α + χ) = ⊥)
(hq : genWeightSpace M (q • α + χ) = ⊥)
{x : H} (hx : x ∈ corootSpace α) :
LinearMap.trace R _ (toEnd R H (genWeightSpaceChain M α χ p q) x) = 0 := by
rw [LieAlgebra.mem_corootSpace'] at hx
induction hx using Submodule.span_induction
· next u hu =>
obtain ⟨y, hy, z, hz, hyz⟩ := hu
let f : Module.End R (genWeightSpaceChain M α χ p q) :=
{ toFun := fun ⟨m, hm⟩ ↦ ⟨⁅(y : L), m⁆,
lie_mem_genWeightSpaceChain_of_genWeightSpace_eq_bot_right M α χ p q hq hy hm⟩
map_add' := fun _ _ ↦ by simp
map_smul' := fun t m ↦ by simp }
let g : Module.End R (genWeightSpaceChain M α χ p q) :=
{ toFun := fun ⟨m, hm⟩ ↦ ⟨⁅(z : L), m⁆,
lie_mem_genWeightSpaceChain_of_genWeightSpace_eq_bot_left M α χ p q hp hz hm⟩
map_add' := fun _ _ ↦ by simp
map_smul' := fun t m ↦ by simp }
have hfg : toEnd R H _ u = ⁅f, g⁆ := by
ext
rw [toEnd_apply_apply, LieSubmodule.coe_bracket, LieSubalgebra.coe_bracket_of_module, ← hyz]
simp only [lie_lie, LieHom.lie_apply, LinearMap.coe_mk, AddHom.coe_mk, Module.End.lie_apply,
AddSubgroupClass.coe_sub, f, g]
simp [hfg]
· simp
· simp_all
· simp_all
/-- Given a (potential) root `α` relative to a Cartan subalgebra `H`, if we restrict to the ideal
`I = corootSpace α` of `H` (informally, `I = ⁅H(α), H(-α)⁆`), we may find an
integral linear combination between `α` and any weight `χ` of a representation.
This is Proposition 4.4 from [carter2005] and is a key step in the proof that the roots of a
semisimple Lie algebra form a root system. It shows that the restriction of `α` to `I` vanishes iff
the restriction of every root to `I` vanishes (which cannot happen in a semisimple Lie algebra). -/
lemma exists_forall_mem_corootSpace_smul_add_eq_zero
[IsDomain R] [IsPrincipalIdealRing R] [CharZero R] [NoZeroSMulDivisors R M] [IsNoetherian R M]
(hα : α ≠ 0) (hχ : genWeightSpace M χ ≠ ⊥) :
∃ a b : ℤ, 0 < b ∧ ∀ x ∈ corootSpace α, (a • α + b • χ) x = 0 := by
obtain ⟨p, hp₀, q, hq₀, hp, hq⟩ := exists₂_genWeightSpace_smul_add_eq_bot M α χ hα
let a := ∑ i ∈ Finset.Ioo p q, finrank R (genWeightSpace M (i • α + χ)) • i
let b := ∑ i ∈ Finset.Ioo p q, finrank R (genWeightSpace M (i • α + χ))
have hb : 0 < b := by
replace hχ : Nontrivial (genWeightSpace M χ) := by rwa [LieSubmodule.nontrivial_iff_ne_bot]
refine Finset.sum_pos' (fun _ _ ↦ zero_le _) ⟨0, Finset.mem_Ioo.mpr ⟨hp₀, hq₀⟩, ?_⟩
rw [zero_smul, zero_add]
exact finrank_pos
refine ⟨a, b, Int.ofNat_pos.mpr hb, fun x hx ↦ ?_⟩
let N : ℤ → Submodule R M := fun k ↦ genWeightSpace M (k • α + χ)
have h₁ : iSupIndep fun (i : Finset.Ioo p q) ↦ N i := by
rw [LieSubmodule.iSupIndep_toSubmodule]
refine (iSupIndep_genWeightSpace R H M).comp fun i j hij ↦ ?_
exact SetCoe.ext <| smul_left_injective ℤ hα <| by rwa [add_left_inj] at hij
have h₂ : ∀ i, MapsTo (toEnd R H M x) ↑(N i) ↑(N i) := fun _ _ ↦ LieSubmodule.lie_mem _
have h₃ : genWeightSpaceChain M α χ p q = ⨆ i ∈ Finset.Ioo p q, N i := by
simp_rw [N, genWeightSpaceChain_def', LieSubmodule.iSup_toSubmodule]
rw [← trace_toEnd_genWeightSpaceChain_eq_zero M α χ p q hp hq hx,
← LieSubmodule.toEnd_restrict_eq_toEnd]
-- The lines below illustrate the cost of treating `LieSubmodule` as both a
-- `Submodule` and a `LieSubmodule` simultaneously.
erw [LinearMap.trace_eq_sum_trace_restrict_of_eq_biSup _ h₁ h₂ (genWeightSpaceChain M α χ p q) h₃]
simp_rw [N, LieSubmodule.toEnd_restrict_eq_toEnd]
dsimp [N]
convert_to _ =
∑ k ∈ Finset.Ioo p q, (LinearMap.trace R { x // x ∈ (genWeightSpace M (k • α + χ)) })
((toEnd R { x // x ∈ H } { x // x ∈ genWeightSpace M (k • α + χ) }) x)
simp_rw [a, b, trace_toEnd_genWeightSpace, Pi.add_apply, Pi.smul_apply, smul_add,
← smul_assoc, Finset.sum_add_distrib, ← Finset.sum_smul, natCast_zsmul]
end IsCartanSubalgebra
end LieSubalgebra
section
variable {M}
variable [LieRing.IsNilpotent L]
variable [NoZeroSMulDivisors ℤ R] [NoZeroSMulDivisors R M] [IsNoetherian R M]
variable (α : L → R) (β : Weight R L M)
/-- This is the largest `n : ℕ` such that `i • α + β` is a weight for all `0 ≤ i ≤ n`. -/
noncomputable
def chainTopCoeff : ℕ :=
letI := Classical.propDecidable
if hα : α = 0 then 0 else
Nat.pred <| Nat.find (show ∃ n, genWeightSpace M (n • α + β : L → R) = ⊥ from
(eventually_genWeightSpace_smul_add_eq_bot M α β hα).exists)
/-- This is the largest `n : ℕ` such that `-i • α + β` is a weight for all `0 ≤ i ≤ n`. -/
noncomputable
def chainBotCoeff : ℕ := chainTopCoeff (-α) β
@[simp] lemma chainTopCoeff_neg : chainTopCoeff (-α) β = chainBotCoeff α β := rfl
@[simp] lemma chainBotCoeff_neg : chainBotCoeff (-α) β = chainTopCoeff α β := by
rw [← chainTopCoeff_neg, neg_neg]
@[simp] lemma chainTopCoeff_zero : chainTopCoeff 0 β = 0 := dif_pos rfl
@[simp] lemma chainBotCoeff_zero : chainBotCoeff 0 β = 0 := dif_pos neg_zero
section
variable (hα : α ≠ 0)
include hα
lemma chainTopCoeff_add_one :
letI := Classical.propDecidable
chainTopCoeff α β + 1 =
Nat.find (eventually_genWeightSpace_smul_add_eq_bot M α β hα).exists := by
classical
rw [chainTopCoeff, dif_neg hα]
apply Nat.succ_pred_eq_of_pos
rw [zero_lt_iff]
intro e
have : genWeightSpace M (0 • α + β : L → R) = ⊥ := by
rw [← e]
exact Nat.find_spec (eventually_genWeightSpace_smul_add_eq_bot M α β hα).exists
exact β.genWeightSpace_ne_bot _ (by simpa only [zero_smul, zero_add] using this)
lemma genWeightSpace_chainTopCoeff_add_one_nsmul_add :
genWeightSpace M ((chainTopCoeff α β + 1) • α + β : L → R) = ⊥ := by
classical
rw [chainTopCoeff_add_one _ _ hα]
exact Nat.find_spec (eventually_genWeightSpace_smul_add_eq_bot M α β hα).exists
lemma genWeightSpace_chainTopCoeff_add_one_zsmul_add :
genWeightSpace M ((chainTopCoeff α β + 1 : ℤ) • α + β : L → R) = ⊥ := by
rw [← genWeightSpace_chainTopCoeff_add_one_nsmul_add α β hα, ← Nat.cast_smul_eq_nsmul ℤ,
Nat.cast_add, Nat.cast_one]
lemma genWeightSpace_chainBotCoeff_sub_one_zsmul_sub :
genWeightSpace M ((-chainBotCoeff α β - 1 : ℤ) • α + β : L → R) = ⊥ := by
rw [sub_eq_add_neg, ← neg_add, neg_smul, ← smul_neg, chainBotCoeff,
genWeightSpace_chainTopCoeff_add_one_zsmul_add _ _ (by simpa using hα)]
end
lemma genWeightSpace_nsmul_add_ne_bot_of_le {n} (hn : n ≤ chainTopCoeff α β) :
genWeightSpace M (n • α + β : L → R) ≠ ⊥ := by
by_cases hα : α = 0
| · rw [hα, smul_zero, zero_add]; exact β.genWeightSpace_ne_bot
classical
| Mathlib/Algebra/Lie/Weights/Chain.lean | 310 | 311 |
/-
Copyright (c) 2020 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov, Patrick Massot, Sébastien Gouëzel
-/
import Mathlib.MeasureTheory.Integral.IntervalIntegral.Basic
import Mathlib.MeasureTheory.Integral.IntervalIntegral.FundThmCalculus
import Mathlib.MeasureTheory.Integral.IntervalIntegral.IntegrationByParts
deprecated_module (since := "2025-04-13")
| Mathlib/MeasureTheory/Integral/IntervalIntegral.lean | 1,236 | 1,238 | |
/-
Copyright (c) 2022 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
-/
import Mathlib.Algebra.Field.Defs
import Mathlib.Algebra.GroupWithZero.Invertible
import Mathlib.Data.Sigma.Basic
import Mathlib.Algebra.Ring.Nat
import Mathlib.Data.Int.Cast.Basic
import Qq.MetaM
/-!
## The `Result` type for `norm_num`
We set up predicates `IsNat`, `IsInt`, and `IsRat`,
stating that an element of a ring is equal to the "normal form" of a natural number, integer,
or rational number coerced into that ring.
We then define `Result e`, which contains a proof that a typed expression `e : Q($α)`
is equal to the coercion of an explicit natural number, integer, or rational number,
or is either `true` or `false`.
-/
universe u
variable {α : Type u}
open Lean
open Lean.Meta Qq Lean.Elab Term
namespace Mathlib
namespace Meta.NormNum
variable {u : Level}
/-- A shortcut (non)instance for `AddMonoidWithOne ℕ` to shrink generated proofs. -/
def instAddMonoidWithOneNat : AddMonoidWithOne ℕ := inferInstance
/-- A shortcut (non)instance for `AddMonoidWithOne α` from `Ring α` to shrink generated proofs. -/
def instAddMonoidWithOne {α : Type u} [Ring α] : AddMonoidWithOne α := inferInstance
/-- Helper function to synthesize a typed `AddMonoidWithOne α` expression. -/
def inferAddMonoidWithOne (α : Q(Type u)) : MetaM Q(AddMonoidWithOne $α) :=
return ← synthInstanceQ q(AddMonoidWithOne $α) <|>
throwError "not an AddMonoidWithOne"
/-- Helper function to synthesize a typed `Semiring α` expression. -/
def inferSemiring (α : Q(Type u)) : MetaM Q(Semiring $α) :=
return ← synthInstanceQ q(Semiring $α) <|> throwError "not a semiring"
/-- Helper function to synthesize a typed `Ring α` expression. -/
def inferRing (α : Q(Type u)) : MetaM Q(Ring $α) :=
return ← synthInstanceQ q(Ring $α) <|> throwError "not a ring"
/--
Represent an integer as a "raw" typed expression.
This uses `.lit (.natVal n)` internally to represent a natural number,
rather than the preferred `OfNat.ofNat` form.
We use this internally to avoid unnecessary typeclass searches.
This function is the inverse of `Expr.intLit!`.
-/
def mkRawIntLit (n : ℤ) : Q(ℤ) :=
let lit : Q(ℕ) := mkRawNatLit n.natAbs
if 0 ≤ n then q(.ofNat $lit) else q(.negOfNat $lit)
/--
Represent an integer as a "raw" typed expression.
This `.lit (.natVal n)` internally to represent a natural number,
rather than the preferred `OfNat.ofNat` form.
We use this internally to avoid unnecessary typeclass searches.
-/
def mkRawRatLit (q : ℚ) : Q(ℚ) :=
let nlit : Q(ℤ) := mkRawIntLit q.num
let dlit : Q(ℕ) := mkRawNatLit q.den
q(mkRat $nlit $dlit)
/-- Extract the raw natlit representing the absolute value of a raw integer literal
(of the type produced by `Mathlib.Meta.NormNum.mkRawIntLit`) along with an equality proof. -/
def rawIntLitNatAbs (n : Q(ℤ)) : (m : Q(ℕ)) × Q(Int.natAbs $n = $m) :=
if n.isAppOfArity ``Int.ofNat 1 then
have m : Q(ℕ) := n.appArg!
⟨m, show Q(Int.natAbs (Int.ofNat $m) = $m) from q(Int.natAbs_natCast $m)⟩
else if n.isAppOfArity ``Int.negOfNat 1 then
have m : Q(ℕ) := n.appArg!
⟨m, show Q(Int.natAbs (Int.negOfNat $m) = $m) from q(Int.natAbs_neg $m)⟩
else
panic! "not a raw integer literal"
/--
Constructs an `ofNat` application `a'` with the canonical instance, together with a proof that
the instance is equal to the result of `Nat.cast` on the given `AddMonoidWithOne` instance.
This function is performance-critical, as many higher level tactics have to construct numerals.
So rather than using typeclass search we hardcode the (relatively small) set of solutions
to the typeclass problem.
-/
def mkOfNat (α : Q(Type u)) (_sα : Q(AddMonoidWithOne $α)) (lit : Q(ℕ)) :
MetaM ((a' : Q($α)) × Q($lit = $a')) := do
if α.isConstOf ``Nat then
let a' : Q(ℕ) := q(OfNat.ofNat $lit : ℕ)
pure ⟨a', (q(Eq.refl $a') : Expr)⟩
else if α.isConstOf ``Int then
let a' : Q(ℤ) := q(OfNat.ofNat $lit : ℤ)
pure ⟨a', (q(Eq.refl $a') : Expr)⟩
else if α.isConstOf ``Rat then
let a' : Q(ℚ) := q(OfNat.ofNat $lit : ℚ)
pure ⟨a', (q(Eq.refl $a') : Expr)⟩
else
let some n := lit.rawNatLit? | failure
match n with
| 0 => pure ⟨q(0 : $α), (q(Nat.cast_zero (R := $α)) : Expr)⟩
| 1 => pure ⟨q(1 : $α), (q(Nat.cast_one (R := $α)) : Expr)⟩
| k+2 =>
let k : Q(ℕ) := mkRawNatLit k
let _x : Q(Nat.AtLeastTwo $lit) :=
(q(instNatAtLeastTwo (n := $k)) : Expr)
let a' : Q($α) := q(OfNat.ofNat $lit)
pure ⟨a', (q(Eq.refl $a') : Expr)⟩
/-- Assert that an element of a semiring is equal to the coercion of some natural number. -/
structure IsNat {α : Type u} [AddMonoidWithOne α] (a : α) (n : ℕ) : Prop where
/-- The element is equal to the coercion of the natural number. -/
out : a = n
theorem IsNat.raw_refl (n : ℕ) : IsNat n n := ⟨rfl⟩
/--
A "raw nat cast" is an expression of the form `(Nat.rawCast lit : α)` where `lit` is a raw
natural number literal. These expressions are used by tactics like `ring` to decrease the number
of typeclass arguments required in each use of a number literal at type `α`.
-/
@[simp] def _root_.Nat.rawCast {α : Type u} [AddMonoidWithOne α] (n : ℕ) : α := n
theorem IsNat.to_eq {α : Type u} [AddMonoidWithOne α] {n} : {a a' : α} → IsNat a n → n = a' → a = a'
| _, _, ⟨rfl⟩, rfl => rfl
theorem IsNat.to_raw_eq {a : α} {n : ℕ} [AddMonoidWithOne α] : IsNat (a : α) n → a = n.rawCast
| ⟨e⟩ => e
theorem IsNat.of_raw (α) [AddMonoidWithOne α] (n : ℕ) : IsNat (n.rawCast : α) n := ⟨rfl⟩
@[elab_as_elim]
theorem isNat.natElim {p : ℕ → Prop} : {n : ℕ} → {n' : ℕ} → IsNat n n' → p n' → p n
| _, _, ⟨rfl⟩, h => h
/-- Assert that an element of a ring is equal to the coercion of some integer. -/
structure IsInt [Ring α] (a : α) (n : ℤ) : Prop where
/-- The element is equal to the coercion of the integer. -/
out : a = n
/--
A "raw int cast" is an expression of the form:
* `(Nat.rawCast lit : α)` where `lit` is a raw natural number literal
* `(Int.rawCast (Int.negOfNat lit) : α)` where `lit` is a nonzero raw natural number literal
(That is, we only actually use this function for negative integers.) This representation is used by
tactics like `ring` to decrease the number of typeclass arguments required in each use of a number
literal at type `α`.
-/
@[simp] def _root_.Int.rawCast [Ring α] (n : ℤ) : α := n
theorem IsInt.to_isNat {α} [Ring α] : ∀ {a : α} {n}, IsInt a (.ofNat n) → IsNat a n
| _, _, ⟨rfl⟩ => ⟨by simp⟩
theorem IsNat.to_isInt {α} [Ring α] : ∀ {a : α} {n}, IsNat a n → IsInt a (.ofNat n)
| _, _, ⟨rfl⟩ => ⟨by simp⟩
theorem IsInt.to_raw_eq {a : α} {n : ℤ} [Ring α] : IsInt (a : α) n → a = n.rawCast
| ⟨e⟩ => e
theorem IsInt.of_raw (α) [Ring α] (n : ℤ) : IsInt (n.rawCast : α) n := ⟨rfl⟩
theorem IsInt.neg_to_eq {α} [Ring α] {n} :
{a a' : α} → IsInt a (.negOfNat n) → n = a' → a = -a'
| _, _, ⟨rfl⟩, rfl => by simp [Int.negOfNat_eq, Int.cast_neg]
theorem IsInt.nonneg_to_eq {α} [Ring α] {n}
{a a' : α} (h : IsInt a (.ofNat n)) (e : n = a') : a = a' := h.to_isNat.to_eq e
/--
Assert that an element of a ring is equal to `num / denom`
(and `denom` is invertible so that this makes sense).
We will usually also have `num` and `denom` coprime,
although this is not part of the definition.
-/
inductive IsRat [Ring α] (a : α) (num : ℤ) (denom : ℕ) : Prop
| mk (inv : Invertible (denom : α)) (eq : a = num * ⅟(denom : α))
/--
A "raw rat cast" is an expression of the form:
* `(Nat.rawCast lit : α)` where `lit` is a raw natural number literal
* `(Int.rawCast (Int.negOfNat lit) : α)` where `lit` is a nonzero raw natural number literal
* `(Rat.rawCast n d : α)` where `n` is a raw int literal, `d` is a raw nat literal, and `d` is not
`1` or `0`.
(where a raw int literal is of the form `Int.ofNat lit` or `Int.negOfNat nzlit` where `lit` is a raw
nat literal)
This representation is used by tactics like `ring` to decrease the number of typeclass arguments
required in each use of a number literal at type `α`.
-/
@[simp]
def _root_.Rat.rawCast [DivisionRing α] (n : ℤ) (d : ℕ) : α := n / d
theorem IsRat.to_isNat {α} [Ring α] : ∀ {a : α} {n}, IsRat a (.ofNat n) (nat_lit 1) → IsNat a n
| _, _, ⟨inv, rfl⟩ => have := @invertibleOne α _; ⟨by simp⟩
theorem IsNat.to_isRat {α} [Ring α] : ∀ {a : α} {n}, IsNat a n → IsRat a (.ofNat n) (nat_lit 1)
| _, _, ⟨rfl⟩ => ⟨⟨1, by simp, by simp⟩, by simp⟩
theorem IsRat.to_isInt {α} [Ring α] : ∀ {a : α} {n}, IsRat a n (nat_lit 1) → IsInt a n
| _, _, ⟨inv, rfl⟩ => have := @invertibleOne α _; ⟨by simp⟩
theorem IsInt.to_isRat {α} [Ring α] : ∀ {a : α} {n}, IsInt a n → IsRat a n (nat_lit 1)
| _, _, ⟨rfl⟩ => ⟨⟨1, by simp, by simp⟩, by simp⟩
theorem IsRat.to_raw_eq {n : ℤ} {d : ℕ} [DivisionRing α] :
∀ {a}, IsRat (a : α) n d → a = Rat.rawCast n d
| _, ⟨inv, rfl⟩ => by simp [div_eq_mul_inv]
theorem IsRat.neg_to_eq {α} [DivisionRing α] {n d} :
{a n' d' : α} → IsRat a (.negOfNat n) d → n = n' → d = d' → a = -(n' / d')
| _, _, _, ⟨_, rfl⟩, rfl, rfl => by simp [div_eq_mul_inv]
theorem IsRat.nonneg_to_eq {α} [DivisionRing α] {n d} :
| {a n' d' : α} → IsRat a (.ofNat n) d → n = n' → d = d' → a = n' / d'
| _, _, _, ⟨_, rfl⟩, rfl, rfl => by simp [div_eq_mul_inv]
theorem IsRat.of_raw (α) [DivisionRing α] (n : ℤ) (d : ℕ)
| Mathlib/Tactic/NormNum/Result.lean | 232 | 235 |
/-
Copyright (c) 2019 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Sébastien Gouëzel, Yury Kudryashov
-/
import Mathlib.Analysis.Calculus.TangentCone
import Mathlib.Analysis.NormedSpace.OperatorNorm.Asymptotics
import Mathlib.Analysis.Asymptotics.TVS
import Mathlib.Analysis.Asymptotics.Lemmas
/-!
# The Fréchet derivative
Let `E` and `F` be normed spaces, `f : E → F`, and `f' : E →L[𝕜] F` a
continuous 𝕜-linear map, where `𝕜` is a non-discrete normed field. Then
`HasFDerivWithinAt f f' s x`
says that `f` has derivative `f'` at `x`, where the domain of interest
is restricted to `s`. We also have
`HasFDerivAt f f' x := HasFDerivWithinAt f f' x univ`
Finally,
`HasStrictFDerivAt f f' x`
means that `f : E → F` has derivative `f' : E →L[𝕜] F` in the sense of strict differentiability,
i.e., `f y - f z - f'(y - z) = o(y - z)` as `y, z → x`. This notion is used in the inverse
function theorem, and is defined here only to avoid proving theorems like
`IsBoundedBilinearMap.hasFDerivAt` twice: first for `HasFDerivAt`, then for
`HasStrictFDerivAt`.
## Main results
In addition to the definition and basic properties of the derivative,
the folder `Analysis/Calculus/FDeriv/` contains the usual formulas
(and existence assertions) for the derivative of
* constants
* the identity
* bounded linear maps (`Linear.lean`)
* bounded bilinear maps (`Bilinear.lean`)
* sum of two functions (`Add.lean`)
* sum of finitely many functions (`Add.lean`)
* multiplication of a function by a scalar constant (`Add.lean`)
* negative of a function (`Add.lean`)
* subtraction of two functions (`Add.lean`)
* multiplication of a function by a scalar function (`Mul.lean`)
* multiplication of two scalar functions (`Mul.lean`)
* composition of functions (the chain rule) (`Comp.lean`)
* inverse function (`Mul.lean`)
(assuming that it exists; the inverse function theorem is in `../Inverse.lean`)
For most binary operations we also define `const_op` and `op_const` theorems for the cases when
the first or second argument is a constant. This makes writing chains of `HasDerivAt`'s easier,
and they more frequently lead to the desired result.
One can also interpret the derivative of a function `f : 𝕜 → E` as an element of `E` (by identifying
a linear function from `𝕜` to `E` with its value at `1`). Results on the Fréchet derivative are
translated to this more elementary point of view on the derivative in the file `Deriv.lean`. The
derivative of polynomials is handled there, as it is naturally one-dimensional.
The simplifier is set up to prove automatically that some functions are differentiable, or
differentiable at a point (but not differentiable on a set or within a set at a point, as checking
automatically that the good domains are mapped one to the other when using composition is not
something the simplifier can easily do). This means that one can write
`example (x : ℝ) : Differentiable ℝ (fun x ↦ sin (exp (3 + x^2)) - 5 * cos x) := by simp`.
If there are divisions, one needs to supply to the simplifier proofs that the denominators do
not vanish, as in
```lean
example (x : ℝ) (h : 1 + sin x ≠ 0) : DifferentiableAt ℝ (fun x ↦ exp x / (1 + sin x)) x := by
simp [h]
```
Of course, these examples only work once `exp`, `cos` and `sin` have been shown to be
differentiable, in `Mathlib.Analysis.SpecialFunctions.Trigonometric.Deriv`.
The simplifier is not set up to compute the Fréchet derivative of maps (as these are in general
complicated multidimensional linear maps), but it will compute one-dimensional derivatives,
see `Deriv.lean`.
## Implementation details
The derivative is defined in terms of the `IsLittleOTVS` relation to ensure the definition does not
ingrain a choice of norm, and is then quickly translated to the more convenient `IsLittleO` in the
subsequent theorems.
It is also characterized in terms of the `Tendsto` relation.
We also introduce predicates `DifferentiableWithinAt 𝕜 f s x` (where `𝕜` is the base field,
`f` the function to be differentiated, `x` the point at which the derivative is asserted to exist,
and `s` the set along which the derivative is defined), as well as `DifferentiableAt 𝕜 f x`,
`DifferentiableOn 𝕜 f s` and `Differentiable 𝕜 f` to express the existence of a derivative.
To be able to compute with derivatives, we write `fderivWithin 𝕜 f s x` and `fderiv 𝕜 f x`
for some choice of a derivative if it exists, and the zero function otherwise. This choice only
behaves well along sets for which the derivative is unique, i.e., those for which the tangent
directions span a dense subset of the whole space. The predicates `UniqueDiffWithinAt s x` and
`UniqueDiffOn s`, defined in `TangentCone.lean` express this property. We prove that indeed
they imply the uniqueness of the derivative. This is satisfied for open subsets, and in particular
for `univ`. This uniqueness only holds when the field is non-discrete, which we request at the very
beginning: otherwise, a derivative can be defined, but it has no interesting properties whatsoever.
To make sure that the simplifier can prove automatically that functions are differentiable, we tag
many lemmas with the `simp` attribute, for instance those saying that the sum of differentiable
functions is differentiable, as well as their product, their cartesian product, and so on. A notable
exception is the chain rule: we do not mark as a simp lemma the fact that, if `f` and `g` are
differentiable, then their composition also is: `simp` would always be able to match this lemma,
by taking `f` or `g` to be the identity. Instead, for every reasonable function (say, `exp`),
we add a lemma that if `f` is differentiable then so is `(fun x ↦ exp (f x))`. This means adding
some boilerplate lemmas, but these can also be useful in their own right.
Tests for this ability of the simplifier (with more examples) are provided in
`Tests/Differentiable.lean`.
## TODO
Generalize more results to topological vector spaces.
## Tags
derivative, differentiable, Fréchet, calculus
-/
open Filter Asymptotics ContinuousLinearMap Set Metric Topology NNReal ENNReal
noncomputable section
section TVS
variable {𝕜 : Type*} [NontriviallyNormedField 𝕜]
variable {E : Type*} [AddCommGroup E] [Module 𝕜 E] [TopologicalSpace E]
variable {F : Type*} [AddCommGroup F] [Module 𝕜 F] [TopologicalSpace F]
/-- A function `f` has the continuous linear map `f'` as derivative along the filter `L` if
`f x' = f x + f' (x' - x) + o (x' - x)` when `x'` converges along the filter `L`. This definition
is designed to be specialized for `L = 𝓝 x` (in `HasFDerivAt`), giving rise to the usual notion
of Fréchet derivative, and for `L = 𝓝[s] x` (in `HasFDerivWithinAt`), giving rise to
the notion of Fréchet derivative along the set `s`. -/
@[mk_iff hasFDerivAtFilter_iff_isLittleOTVS]
structure HasFDerivAtFilter (f : E → F) (f' : E →L[𝕜] F) (x : E) (L : Filter E) : Prop where
of_isLittleOTVS ::
isLittleOTVS : (fun x' => f x' - f x - f' (x' - x)) =o[𝕜; L] (fun x' => x' - x)
/-- A function `f` has the continuous linear map `f'` as derivative at `x` within a set `s` if
`f x' = f x + f' (x' - x) + o (x' - x)` when `x'` tends to `x` inside `s`. -/
@[fun_prop]
def HasFDerivWithinAt (f : E → F) (f' : E →L[𝕜] F) (s : Set E) (x : E) :=
HasFDerivAtFilter f f' x (𝓝[s] x)
/-- A function `f` has the continuous linear map `f'` as derivative at `x` if
`f x' = f x + f' (x' - x) + o (x' - x)` when `x'` tends to `x`. -/
@[fun_prop]
def HasFDerivAt (f : E → F) (f' : E →L[𝕜] F) (x : E) :=
HasFDerivAtFilter f f' x (𝓝 x)
/-- A function `f` has derivative `f'` at `a` in the sense of *strict differentiability*
if `f x - f y - f' (x - y) = o(x - y)` as `x, y → a`. This form of differentiability is required,
e.g., by the inverse function theorem. Any `C^1` function on a vector space over `ℝ` is strictly
differentiable but this definition works, e.g., for vector spaces over `p`-adic numbers. -/
@[fun_prop, mk_iff hasStrictFDerivAt_iff_isLittleOTVS]
structure HasStrictFDerivAt (f : E → F) (f' : E →L[𝕜] F) (x : E) where
of_isLittleOTVS ::
isLittleOTVS :
(fun p : E × E => f p.1 - f p.2 - f' (p.1 - p.2))
=o[𝕜; 𝓝 (x, x)] (fun p : E × E => p.1 - p.2)
variable (𝕜)
/-- A function `f` is differentiable at a point `x` within a set `s` if it admits a derivative
there (possibly non-unique). -/
@[fun_prop]
def DifferentiableWithinAt (f : E → F) (s : Set E) (x : E) :=
∃ f' : E →L[𝕜] F, HasFDerivWithinAt f f' s x
/-- A function `f` is differentiable at a point `x` if it admits a derivative there (possibly
non-unique). -/
@[fun_prop]
def DifferentiableAt (f : E → F) (x : E) :=
∃ f' : E →L[𝕜] F, HasFDerivAt f f' x
open scoped Classical in
/-- If `f` has a derivative at `x` within `s`, then `fderivWithin 𝕜 f s x` is such a derivative.
Otherwise, it is set to `0`. We also set it to be zero, if zero is one of possible derivatives. -/
irreducible_def fderivWithin (f : E → F) (s : Set E) (x : E) : E →L[𝕜] F :=
if HasFDerivWithinAt f (0 : E →L[𝕜] F) s x
then 0
else if h : DifferentiableWithinAt 𝕜 f s x
then Classical.choose h
else 0
/-- If `f` has a derivative at `x`, then `fderiv 𝕜 f x` is such a derivative. Otherwise, it is
set to `0`. -/
irreducible_def fderiv (f : E → F) (x : E) : E →L[𝕜] F :=
fderivWithin 𝕜 f univ x
/-- `DifferentiableOn 𝕜 f s` means that `f` is differentiable within `s` at any point of `s`. -/
@[fun_prop]
def DifferentiableOn (f : E → F) (s : Set E) :=
∀ x ∈ s, DifferentiableWithinAt 𝕜 f s x
/-- `Differentiable 𝕜 f` means that `f` is differentiable at any point. -/
@[fun_prop]
def Differentiable (f : E → F) :=
∀ x, DifferentiableAt 𝕜 f x
variable {𝕜}
variable {f f₀ f₁ g : E → F}
variable {f' f₀' f₁' g' : E →L[𝕜] F}
variable {x : E}
variable {s t : Set E}
variable {L L₁ L₂ : Filter E}
theorem fderivWithin_zero_of_not_differentiableWithinAt (h : ¬DifferentiableWithinAt 𝕜 f s x) :
fderivWithin 𝕜 f s x = 0 := by
simp [fderivWithin, h]
@[simp]
theorem fderivWithin_univ : fderivWithin 𝕜 f univ = fderiv 𝕜 f := by
ext
rw [fderiv]
end TVS
section
variable {𝕜 : Type*} [NontriviallyNormedField 𝕜]
variable {E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E]
variable {F : Type*} [NormedAddCommGroup F] [NormedSpace 𝕜 F]
variable {f f₀ f₁ g : E → F}
variable {f' f₀' f₁' g' : E →L[𝕜] F}
variable {x : E}
variable {s t : Set E}
variable {L L₁ L₂ : Filter E}
theorem hasFDerivAtFilter_iff_isLittleO :
HasFDerivAtFilter f f' x L ↔ (fun x' => f x' - f x - f' (x' - x)) =o[L] fun x' => x' - x :=
(hasFDerivAtFilter_iff_isLittleOTVS ..).trans isLittleOTVS_iff_isLittleO
alias ⟨HasFDerivAtFilter.isLittleO, HasFDerivAtFilter.of_isLittleO⟩ :=
hasFDerivAtFilter_iff_isLittleO
theorem hasStrictFDerivAt_iff_isLittleO :
HasStrictFDerivAt f f' x ↔
(fun p : E × E => f p.1 - f p.2 - f' (p.1 - p.2)) =o[𝓝 (x, x)] fun p : E × E => p.1 - p.2 :=
(hasStrictFDerivAt_iff_isLittleOTVS ..).trans isLittleOTVS_iff_isLittleO
alias ⟨HasStrictFDerivAt.isLittleO, HasStrictFDerivAt.of_isLittleO⟩ :=
hasStrictFDerivAt_iff_isLittleO
section DerivativeUniqueness
/- In this section, we discuss the uniqueness of the derivative.
We prove that the definitions `UniqueDiffWithinAt` and `UniqueDiffOn` indeed imply the
uniqueness of the derivative. -/
/-- If a function f has a derivative f' at x, a rescaled version of f around x converges to f',
i.e., `n (f (x + (1/n) v) - f x)` converges to `f' v`. More generally, if `c n` tends to infinity
and `c n * d n` tends to `v`, then `c n * (f (x + d n) - f x)` tends to `f' v`. This lemma expresses
this fact, for functions having a derivative within a set. Its specific formulation is useful for
tangent cone related discussions. -/
theorem HasFDerivWithinAt.lim (h : HasFDerivWithinAt f f' s x) {α : Type*} (l : Filter α)
{c : α → 𝕜} {d : α → E} {v : E} (dtop : ∀ᶠ n in l, x + d n ∈ s)
(clim : Tendsto (fun n => ‖c n‖) l atTop) (cdlim : Tendsto (fun n => c n • d n) l (𝓝 v)) :
Tendsto (fun n => c n • (f (x + d n) - f x)) l (𝓝 (f' v)) := by
have tendsto_arg : Tendsto (fun n => x + d n) l (𝓝[s] x) := by
conv in 𝓝[s] x => rw [← add_zero x]
rw [nhdsWithin, tendsto_inf]
constructor
· apply tendsto_const_nhds.add (tangentConeAt.lim_zero l clim cdlim)
· rwa [tendsto_principal]
have : (fun y => f y - f x - f' (y - x)) =o[𝓝[s] x] fun y => y - x := h.isLittleO
have : (fun n => f (x + d n) - f x - f' (x + d n - x)) =o[l] fun n => x + d n - x :=
this.comp_tendsto tendsto_arg
have : (fun n => f (x + d n) - f x - f' (d n)) =o[l] d := by simpa only [add_sub_cancel_left]
have : (fun n => c n • (f (x + d n) - f x - f' (d n))) =o[l] fun n => c n • d n :=
(isBigO_refl c l).smul_isLittleO this
have : (fun n => c n • (f (x + d n) - f x - f' (d n))) =o[l] fun _ => (1 : ℝ) :=
this.trans_isBigO (cdlim.isBigO_one ℝ)
have L1 : Tendsto (fun n => c n • (f (x + d n) - f x - f' (d n))) l (𝓝 0) :=
(isLittleO_one_iff ℝ).1 this
have L2 : Tendsto (fun n => f' (c n • d n)) l (𝓝 (f' v)) :=
Tendsto.comp f'.cont.continuousAt cdlim
have L3 :
Tendsto (fun n => c n • (f (x + d n) - f x - f' (d n)) + f' (c n • d n)) l (𝓝 (0 + f' v)) :=
L1.add L2
have :
(fun n => c n • (f (x + d n) - f x - f' (d n)) + f' (c n • d n)) = fun n =>
c n • (f (x + d n) - f x) := by
ext n
simp [smul_add, smul_sub]
rwa [this, zero_add] at L3
/-- If `f'` and `f₁'` are two derivatives of `f` within `s` at `x`, then they are equal on the
tangent cone to `s` at `x` -/
theorem HasFDerivWithinAt.unique_on (hf : HasFDerivWithinAt f f' s x)
(hg : HasFDerivWithinAt f f₁' s x) : EqOn f' f₁' (tangentConeAt 𝕜 s x) :=
fun _ ⟨_, _, dtop, clim, cdlim⟩ =>
tendsto_nhds_unique (hf.lim atTop dtop clim cdlim) (hg.lim atTop dtop clim cdlim)
/-- `UniqueDiffWithinAt` achieves its goal: it implies the uniqueness of the derivative. -/
theorem UniqueDiffWithinAt.eq (H : UniqueDiffWithinAt 𝕜 s x) (hf : HasFDerivWithinAt f f' s x)
(hg : HasFDerivWithinAt f f₁' s x) : f' = f₁' :=
ContinuousLinearMap.ext_on H.1 (hf.unique_on hg)
theorem UniqueDiffOn.eq (H : UniqueDiffOn 𝕜 s) (hx : x ∈ s) (h : HasFDerivWithinAt f f' s x)
(h₁ : HasFDerivWithinAt f f₁' s x) : f' = f₁' :=
(H x hx).eq h h₁
end DerivativeUniqueness
section FDerivProperties
/-! ### Basic properties of the derivative -/
theorem hasFDerivAtFilter_iff_tendsto :
HasFDerivAtFilter f f' x L ↔
Tendsto (fun x' => ‖x' - x‖⁻¹ * ‖f x' - f x - f' (x' - x)‖) L (𝓝 0) := by
have h : ∀ x', ‖x' - x‖ = 0 → ‖f x' - f x - f' (x' - x)‖ = 0 := fun x' hx' => by
rw [sub_eq_zero.1 (norm_eq_zero.1 hx')]
simp
rw [hasFDerivAtFilter_iff_isLittleO, ← isLittleO_norm_left, ← isLittleO_norm_right,
isLittleO_iff_tendsto h]
exact tendsto_congr fun _ => div_eq_inv_mul _ _
theorem hasFDerivWithinAt_iff_tendsto :
HasFDerivWithinAt f f' s x ↔
Tendsto (fun x' => ‖x' - x‖⁻¹ * ‖f x' - f x - f' (x' - x)‖) (𝓝[s] x) (𝓝 0) :=
hasFDerivAtFilter_iff_tendsto
theorem hasFDerivAt_iff_tendsto :
HasFDerivAt f f' x ↔ Tendsto (fun x' => ‖x' - x‖⁻¹ * ‖f x' - f x - f' (x' - x)‖) (𝓝 x) (𝓝 0) :=
hasFDerivAtFilter_iff_tendsto
theorem hasFDerivAt_iff_isLittleO_nhds_zero :
HasFDerivAt f f' x ↔ (fun h : E => f (x + h) - f x - f' h) =o[𝓝 0] fun h => h := by
rw [HasFDerivAt, hasFDerivAtFilter_iff_isLittleO, ← map_add_left_nhds_zero x, isLittleO_map]
simp [Function.comp_def]
nonrec theorem HasFDerivAtFilter.mono (h : HasFDerivAtFilter f f' x L₂) (hst : L₁ ≤ L₂) :
HasFDerivAtFilter f f' x L₁ :=
.of_isLittleOTVS <| h.isLittleOTVS.mono hst
theorem HasFDerivWithinAt.mono_of_mem_nhdsWithin
(h : HasFDerivWithinAt f f' t x) (hst : t ∈ 𝓝[s] x) :
HasFDerivWithinAt f f' s x :=
h.mono <| nhdsWithin_le_iff.mpr hst
@[deprecated (since := "2024-10-31")]
alias HasFDerivWithinAt.mono_of_mem := HasFDerivWithinAt.mono_of_mem_nhdsWithin
nonrec theorem HasFDerivWithinAt.mono (h : HasFDerivWithinAt f f' t x) (hst : s ⊆ t) :
HasFDerivWithinAt f f' s x :=
h.mono <| nhdsWithin_mono _ hst
theorem HasFDerivAt.hasFDerivAtFilter (h : HasFDerivAt f f' x) (hL : L ≤ 𝓝 x) :
HasFDerivAtFilter f f' x L :=
h.mono hL
@[fun_prop]
theorem HasFDerivAt.hasFDerivWithinAt (h : HasFDerivAt f f' x) : HasFDerivWithinAt f f' s x :=
h.hasFDerivAtFilter inf_le_left
@[fun_prop]
theorem HasFDerivWithinAt.differentiableWithinAt (h : HasFDerivWithinAt f f' s x) :
DifferentiableWithinAt 𝕜 f s x :=
⟨f', h⟩
@[fun_prop]
theorem HasFDerivAt.differentiableAt (h : HasFDerivAt f f' x) : DifferentiableAt 𝕜 f x :=
⟨f', h⟩
@[simp]
theorem hasFDerivWithinAt_univ : HasFDerivWithinAt f f' univ x ↔ HasFDerivAt f f' x := by
simp only [HasFDerivWithinAt, nhdsWithin_univ, HasFDerivAt]
alias ⟨HasFDerivWithinAt.hasFDerivAt_of_univ, _⟩ := hasFDerivWithinAt_univ
theorem differentiableWithinAt_univ :
DifferentiableWithinAt 𝕜 f univ x ↔ DifferentiableAt 𝕜 f x := by
simp only [DifferentiableWithinAt, hasFDerivWithinAt_univ, DifferentiableAt]
theorem fderiv_zero_of_not_differentiableAt (h : ¬DifferentiableAt 𝕜 f x) : fderiv 𝕜 f x = 0 := by
rw [fderiv, fderivWithin_zero_of_not_differentiableWithinAt]
rwa [differentiableWithinAt_univ]
theorem hasFDerivWithinAt_of_mem_nhds (h : s ∈ 𝓝 x) :
HasFDerivWithinAt f f' s x ↔ HasFDerivAt f f' x := by
rw [HasFDerivAt, HasFDerivWithinAt, nhdsWithin_eq_nhds.mpr h]
lemma hasFDerivWithinAt_of_isOpen (h : IsOpen s) (hx : x ∈ s) :
HasFDerivWithinAt f f' s x ↔ HasFDerivAt f f' x :=
hasFDerivWithinAt_of_mem_nhds (h.mem_nhds hx)
@[simp]
theorem hasFDerivWithinAt_insert {y : E} :
HasFDerivWithinAt f f' (insert y s) x ↔ HasFDerivWithinAt f f' s x := by
rcases eq_or_ne x y with (rfl | h)
· simp_rw [HasFDerivWithinAt, hasFDerivAtFilter_iff_isLittleOTVS]
apply isLittleOTVS_insert
simp only [sub_self, map_zero]
refine ⟨fun h => h.mono <| subset_insert y s, fun hf => hf.mono_of_mem_nhdsWithin ?_⟩
simp_rw [nhdsWithin_insert_of_ne h, self_mem_nhdsWithin]
alias ⟨HasFDerivWithinAt.of_insert, HasFDerivWithinAt.insert'⟩ := hasFDerivWithinAt_insert
protected theorem HasFDerivWithinAt.insert (h : HasFDerivWithinAt g g' s x) :
HasFDerivWithinAt g g' (insert x s) x :=
h.insert'
@[simp]
theorem hasFDerivWithinAt_diff_singleton (y : E) :
HasFDerivWithinAt f f' (s \ {y}) x ↔ HasFDerivWithinAt f f' s x := by
rw [← hasFDerivWithinAt_insert, insert_diff_singleton, hasFDerivWithinAt_insert]
@[simp]
protected theorem HasFDerivWithinAt.empty : HasFDerivWithinAt f f' ∅ x := by
simp [HasFDerivWithinAt, hasFDerivAtFilter_iff_isLittleOTVS]
@[simp]
protected theorem DifferentiableWithinAt.empty : DifferentiableWithinAt 𝕜 f ∅ x :=
⟨0, .empty⟩
theorem HasFDerivWithinAt.of_finite (h : s.Finite) : HasFDerivWithinAt f f' s x := by
induction s, h using Set.Finite.induction_on with
| empty => exact .empty
| insert _ _ ih => exact ih.insert'
theorem DifferentiableWithinAt.of_finite (h : s.Finite) : DifferentiableWithinAt 𝕜 f s x :=
⟨0, .of_finite h⟩
@[simp]
protected theorem HasFDerivWithinAt.singleton {y} : HasFDerivWithinAt f f' {x} y :=
.of_finite <| finite_singleton _
@[simp]
protected theorem DifferentiableWithinAt.singleton {y} : DifferentiableWithinAt 𝕜 f {x} y :=
⟨0, .singleton⟩
theorem HasFDerivWithinAt.of_subsingleton (h : s.Subsingleton) : HasFDerivWithinAt f f' s x :=
.of_finite h.finite
theorem DifferentiableWithinAt.of_subsingleton (h : s.Subsingleton) :
DifferentiableWithinAt 𝕜 f s x :=
.of_finite h.finite
theorem HasStrictFDerivAt.isBigO_sub (hf : HasStrictFDerivAt f f' x) :
(fun p : E × E => f p.1 - f p.2) =O[𝓝 (x, x)] fun p : E × E => p.1 - p.2 :=
hf.isLittleO.isBigO.congr_of_sub.2 (f'.isBigO_comp _ _)
theorem HasFDerivAtFilter.isBigO_sub (h : HasFDerivAtFilter f f' x L) :
(fun x' => f x' - f x) =O[L] fun x' => x' - x :=
h.isLittleO.isBigO.congr_of_sub.2 (f'.isBigO_sub _ _)
@[fun_prop]
protected theorem HasStrictFDerivAt.hasFDerivAt (hf : HasStrictFDerivAt f f' x) :
HasFDerivAt f f' x :=
.of_isLittleOTVS <| by
simpa only using hf.isLittleOTVS.comp_tendsto (tendsto_id.prodMk_nhds tendsto_const_nhds)
protected theorem HasStrictFDerivAt.differentiableAt (hf : HasStrictFDerivAt f f' x) :
DifferentiableAt 𝕜 f x :=
hf.hasFDerivAt.differentiableAt
/-- If `f` is strictly differentiable at `x` with derivative `f'` and `K > ‖f'‖₊`, then `f` is
`K`-Lipschitz in a neighborhood of `x`. -/
theorem HasStrictFDerivAt.exists_lipschitzOnWith_of_nnnorm_lt (hf : HasStrictFDerivAt f f' x)
(K : ℝ≥0) (hK : ‖f'‖₊ < K) : ∃ s ∈ 𝓝 x, LipschitzOnWith K f s := by
have := hf.isLittleO.add_isBigOWith (f'.isBigOWith_comp _ _) hK
simp only [sub_add_cancel, IsBigOWith] at this
rcases exists_nhds_square this with ⟨U, Uo, xU, hU⟩
exact
⟨U, Uo.mem_nhds xU, lipschitzOnWith_iff_norm_sub_le.2 fun x hx y hy => hU (mk_mem_prod hx hy)⟩
/-- If `f` is strictly differentiable at `x` with derivative `f'`, then `f` is Lipschitz in a
neighborhood of `x`. See also `HasStrictFDerivAt.exists_lipschitzOnWith_of_nnnorm_lt` for a
more precise statement. -/
theorem HasStrictFDerivAt.exists_lipschitzOnWith (hf : HasStrictFDerivAt f f' x) :
∃ K, ∃ s ∈ 𝓝 x, LipschitzOnWith K f s :=
(exists_gt _).imp hf.exists_lipschitzOnWith_of_nnnorm_lt
/-- Directional derivative agrees with `HasFDeriv`. -/
theorem HasFDerivAt.lim (hf : HasFDerivAt f f' x) (v : E) {α : Type*} {c : α → 𝕜} {l : Filter α}
(hc : Tendsto (fun n => ‖c n‖) l atTop) :
Tendsto (fun n => c n • (f (x + (c n)⁻¹ • v) - f x)) l (𝓝 (f' v)) := by
refine (hasFDerivWithinAt_univ.2 hf).lim _ univ_mem hc ?_
intro U hU
refine (eventually_ne_of_tendsto_norm_atTop hc (0 : 𝕜)).mono fun y hy => ?_
convert mem_of_mem_nhds hU
dsimp only
rw [← mul_smul, mul_inv_cancel₀ hy, one_smul]
theorem HasFDerivAt.unique (h₀ : HasFDerivAt f f₀' x) (h₁ : HasFDerivAt f f₁' x) : f₀' = f₁' := by
rw [← hasFDerivWithinAt_univ] at h₀ h₁
exact uniqueDiffWithinAt_univ.eq h₀ h₁
theorem hasFDerivWithinAt_inter' (h : t ∈ 𝓝[s] x) :
HasFDerivWithinAt f f' (s ∩ t) x ↔ HasFDerivWithinAt f f' s x := by
simp [HasFDerivWithinAt, nhdsWithin_restrict'' s h]
theorem hasFDerivWithinAt_inter (h : t ∈ 𝓝 x) :
HasFDerivWithinAt f f' (s ∩ t) x ↔ HasFDerivWithinAt f f' s x := by
simp [HasFDerivWithinAt, nhdsWithin_restrict' s h]
theorem HasFDerivWithinAt.union (hs : HasFDerivWithinAt f f' s x)
(ht : HasFDerivWithinAt f f' t x) : HasFDerivWithinAt f f' (s ∪ t) x := by
simp only [HasFDerivWithinAt, nhdsWithin_union]
exact .of_isLittleOTVS <| hs.isLittleOTVS.sup ht.isLittleOTVS
theorem HasFDerivWithinAt.hasFDerivAt (h : HasFDerivWithinAt f f' s x) (hs : s ∈ 𝓝 x) :
HasFDerivAt f f' x := by
rwa [← univ_inter s, hasFDerivWithinAt_inter hs, hasFDerivWithinAt_univ] at h
theorem DifferentiableWithinAt.differentiableAt (h : DifferentiableWithinAt 𝕜 f s x)
(hs : s ∈ 𝓝 x) : DifferentiableAt 𝕜 f x :=
h.imp fun _ hf' => hf'.hasFDerivAt hs
/-- If `x` is isolated in `s`, then `f` has any derivative at `x` within `s`,
as this statement is empty. -/
theorem HasFDerivWithinAt.of_not_accPt (h : ¬AccPt x (𝓟 s)) : HasFDerivWithinAt f f' s x := by
rw [accPt_principal_iff_nhdsWithin, not_neBot] at h
rw [← hasFDerivWithinAt_diff_singleton x, HasFDerivWithinAt, h,
hasFDerivAtFilter_iff_isLittleOTVS]
exact .bot
/-- If `x` is isolated in `s`, then `f` has any derivative at `x` within `s`,
as this statement is empty. -/
@[deprecated HasFDerivWithinAt.of_not_accPt (since := "2025-04-20")]
theorem HasFDerivWithinAt.of_nhdsWithin_eq_bot (h : 𝓝[s \ {x}] x = ⊥) :
HasFDerivWithinAt f f' s x :=
.of_not_accPt <| by rwa [accPt_principal_iff_nhdsWithin, not_neBot]
/-- If `x` is not in the closure of `s`, then `f` has any derivative at `x` within `s`,
as this statement is empty. -/
theorem HasFDerivWithinAt.of_not_mem_closure (h : x ∉ closure s) : HasFDerivWithinAt f f' s x :=
.of_not_accPt (h ·.clusterPt.mem_closure)
@[deprecated (since := "2025-04-20")]
alias hasFDerivWithinAt_of_nmem_closure := HasFDerivWithinAt.of_not_mem_closure
theorem fderivWithin_zero_of_not_accPt (h : ¬AccPt x (𝓟 s)) : fderivWithin 𝕜 f s x = 0 := by
rw [fderivWithin, if_pos (.of_not_accPt h)]
set_option linter.deprecated false in
@[deprecated fderivWithin_zero_of_not_accPt (since := "2025-04-20")]
theorem fderivWithin_zero_of_isolated (h : 𝓝[s \ {x}] x = ⊥) : fderivWithin 𝕜 f s x = 0 := by
rw [fderivWithin, if_pos (.of_nhdsWithin_eq_bot h)]
theorem fderivWithin_zero_of_nmem_closure (h : x ∉ closure s) : fderivWithin 𝕜 f s x = 0 :=
fderivWithin_zero_of_not_accPt (h ·.clusterPt.mem_closure)
theorem DifferentiableWithinAt.hasFDerivWithinAt (h : DifferentiableWithinAt 𝕜 f s x) :
HasFDerivWithinAt f (fderivWithin 𝕜 f s x) s x := by
simp only [fderivWithin, dif_pos h]
split_ifs with h₀
exacts [h₀, Classical.choose_spec h]
theorem DifferentiableAt.hasFDerivAt (h : DifferentiableAt 𝕜 f x) :
HasFDerivAt f (fderiv 𝕜 f x) x := by
rw [fderiv, ← hasFDerivWithinAt_univ]
rw [← differentiableWithinAt_univ] at h
exact h.hasFDerivWithinAt
theorem DifferentiableOn.hasFDerivAt (h : DifferentiableOn 𝕜 f s) (hs : s ∈ 𝓝 x) :
HasFDerivAt f (fderiv 𝕜 f x) x :=
((h x (mem_of_mem_nhds hs)).differentiableAt hs).hasFDerivAt
theorem DifferentiableOn.differentiableAt (h : DifferentiableOn 𝕜 f s) (hs : s ∈ 𝓝 x) :
DifferentiableAt 𝕜 f x :=
(h.hasFDerivAt hs).differentiableAt
theorem DifferentiableOn.eventually_differentiableAt (h : DifferentiableOn 𝕜 f s) (hs : s ∈ 𝓝 x) :
∀ᶠ y in 𝓝 x, DifferentiableAt 𝕜 f y :=
(eventually_eventually_nhds.2 hs).mono fun _ => h.differentiableAt
protected theorem HasFDerivAt.fderiv (h : HasFDerivAt f f' x) : fderiv 𝕜 f x = f' := by
ext
rw [h.unique h.differentiableAt.hasFDerivAt]
theorem fderiv_eq {f' : E → E →L[𝕜] F} (h : ∀ x, HasFDerivAt f (f' x) x) : fderiv 𝕜 f = f' :=
funext fun x => (h x).fderiv
protected theorem HasFDerivWithinAt.fderivWithin (h : HasFDerivWithinAt f f' s x)
(hxs : UniqueDiffWithinAt 𝕜 s x) : fderivWithin 𝕜 f s x = f' :=
(hxs.eq h h.differentiableWithinAt.hasFDerivWithinAt).symm
theorem DifferentiableWithinAt.mono (h : DifferentiableWithinAt 𝕜 f t x) (st : s ⊆ t) :
DifferentiableWithinAt 𝕜 f s x := by
rcases h with ⟨f', hf'⟩
exact ⟨f', hf'.mono st⟩
theorem DifferentiableWithinAt.mono_of_mem_nhdsWithin
(h : DifferentiableWithinAt 𝕜 f s x) {t : Set E} (hst : s ∈ 𝓝[t] x) :
DifferentiableWithinAt 𝕜 f t x :=
(h.hasFDerivWithinAt.mono_of_mem_nhdsWithin hst).differentiableWithinAt
@[deprecated (since := "2024-10-31")]
alias DifferentiableWithinAt.mono_of_mem := DifferentiableWithinAt.mono_of_mem_nhdsWithin
theorem DifferentiableWithinAt.congr_nhds (h : DifferentiableWithinAt 𝕜 f s x) {t : Set E}
(hst : 𝓝[s] x = 𝓝[t] x) : DifferentiableWithinAt 𝕜 f t x :=
h.mono_of_mem_nhdsWithin <| hst ▸ self_mem_nhdsWithin
theorem differentiableWithinAt_congr_nhds {t : Set E} (hst : 𝓝[s] x = 𝓝[t] x) :
DifferentiableWithinAt 𝕜 f s x ↔ DifferentiableWithinAt 𝕜 f t x :=
⟨fun h => h.congr_nhds hst, fun h => h.congr_nhds hst.symm⟩
theorem differentiableWithinAt_inter (ht : t ∈ 𝓝 x) :
DifferentiableWithinAt 𝕜 f (s ∩ t) x ↔ DifferentiableWithinAt 𝕜 f s x := by
simp only [DifferentiableWithinAt, hasFDerivWithinAt_inter ht]
theorem differentiableWithinAt_inter' (ht : t ∈ 𝓝[s] x) :
DifferentiableWithinAt 𝕜 f (s ∩ t) x ↔ DifferentiableWithinAt 𝕜 f s x := by
simp only [DifferentiableWithinAt, hasFDerivWithinAt_inter' ht]
theorem differentiableWithinAt_insert_self :
DifferentiableWithinAt 𝕜 f (insert x s) x ↔ DifferentiableWithinAt 𝕜 f s x :=
⟨fun h ↦ h.mono (subset_insert x s), fun h ↦ h.hasFDerivWithinAt.insert.differentiableWithinAt⟩
theorem differentiableWithinAt_insert {y : E} :
DifferentiableWithinAt 𝕜 f (insert y s) x ↔ DifferentiableWithinAt 𝕜 f s x := by
rcases eq_or_ne x y with (rfl | h)
· exact differentiableWithinAt_insert_self
apply differentiableWithinAt_congr_nhds
exact nhdsWithin_insert_of_ne h
alias ⟨DifferentiableWithinAt.of_insert, DifferentiableWithinAt.insert'⟩ :=
differentiableWithinAt_insert
protected theorem DifferentiableWithinAt.insert (h : DifferentiableWithinAt 𝕜 f s x) :
DifferentiableWithinAt 𝕜 f (insert x s) x :=
h.insert'
theorem DifferentiableAt.differentiableWithinAt (h : DifferentiableAt 𝕜 f x) :
DifferentiableWithinAt 𝕜 f s x :=
(differentiableWithinAt_univ.2 h).mono (subset_univ _)
@[fun_prop]
theorem Differentiable.differentiableAt (h : Differentiable 𝕜 f) : DifferentiableAt 𝕜 f x :=
h x
protected theorem DifferentiableAt.fderivWithin (h : DifferentiableAt 𝕜 f x)
(hxs : UniqueDiffWithinAt 𝕜 s x) : fderivWithin 𝕜 f s x = fderiv 𝕜 f x :=
h.hasFDerivAt.hasFDerivWithinAt.fderivWithin hxs
theorem DifferentiableOn.mono (h : DifferentiableOn 𝕜 f t) (st : s ⊆ t) : DifferentiableOn 𝕜 f s :=
fun x hx => (h x (st hx)).mono st
theorem differentiableOn_univ : DifferentiableOn 𝕜 f univ ↔ Differentiable 𝕜 f := by
simp only [DifferentiableOn, Differentiable, differentiableWithinAt_univ, mem_univ,
forall_true_left]
@[fun_prop]
theorem Differentiable.differentiableOn (h : Differentiable 𝕜 f) : DifferentiableOn 𝕜 f s :=
(differentiableOn_univ.2 h).mono (subset_univ _)
theorem differentiableOn_of_locally_differentiableOn
(h : ∀ x ∈ s, ∃ u, IsOpen u ∧ x ∈ u ∧ DifferentiableOn 𝕜 f (s ∩ u)) :
DifferentiableOn 𝕜 f s := by
intro x xs
rcases h x xs with ⟨t, t_open, xt, ht⟩
exact (differentiableWithinAt_inter (IsOpen.mem_nhds t_open xt)).1 (ht x ⟨xs, xt⟩)
theorem fderivWithin_of_mem_nhdsWithin (st : t ∈ 𝓝[s] x) (ht : UniqueDiffWithinAt 𝕜 s x)
(h : DifferentiableWithinAt 𝕜 f t x) : fderivWithin 𝕜 f s x = fderivWithin 𝕜 f t x :=
((DifferentiableWithinAt.hasFDerivWithinAt h).mono_of_mem_nhdsWithin st).fderivWithin ht
@[deprecated (since := "2024-10-31")]
alias fderivWithin_of_mem := fderivWithin_of_mem_nhdsWithin
theorem fderivWithin_subset (st : s ⊆ t) (ht : UniqueDiffWithinAt 𝕜 s x)
(h : DifferentiableWithinAt 𝕜 f t x) : fderivWithin 𝕜 f s x = fderivWithin 𝕜 f t x :=
fderivWithin_of_mem_nhdsWithin (nhdsWithin_mono _ st self_mem_nhdsWithin) ht h
theorem fderivWithin_inter (ht : t ∈ 𝓝 x) : fderivWithin 𝕜 f (s ∩ t) x = fderivWithin 𝕜 f s x := by
classical
simp [fderivWithin, hasFDerivWithinAt_inter ht, DifferentiableWithinAt]
theorem fderivWithin_of_mem_nhds (h : s ∈ 𝓝 x) : fderivWithin 𝕜 f s x = fderiv 𝕜 f x := by
rw [← fderivWithin_univ, ← univ_inter s, fderivWithin_inter h]
theorem fderivWithin_of_isOpen (hs : IsOpen s) (hx : x ∈ s) : fderivWithin 𝕜 f s x = fderiv 𝕜 f x :=
fderivWithin_of_mem_nhds (hs.mem_nhds hx)
theorem fderivWithin_eq_fderiv (hs : UniqueDiffWithinAt 𝕜 s x) (h : DifferentiableAt 𝕜 f x) :
fderivWithin 𝕜 f s x = fderiv 𝕜 f x := by
rw [← fderivWithin_univ]
exact fderivWithin_subset (subset_univ _) hs h.differentiableWithinAt
theorem fderiv_mem_iff {f : E → F} {s : Set (E →L[𝕜] F)} {x : E} : fderiv 𝕜 f x ∈ s ↔
DifferentiableAt 𝕜 f x ∧ fderiv 𝕜 f x ∈ s ∨ ¬DifferentiableAt 𝕜 f x ∧ (0 : E →L[𝕜] F) ∈ s := by
by_cases hx : DifferentiableAt 𝕜 f x <;> simp [fderiv_zero_of_not_differentiableAt, *]
theorem fderivWithin_mem_iff {f : E → F} {t : Set E} {s : Set (E →L[𝕜] F)} {x : E} :
fderivWithin 𝕜 f t x ∈ s ↔
DifferentiableWithinAt 𝕜 f t x ∧ fderivWithin 𝕜 f t x ∈ s ∨
¬DifferentiableWithinAt 𝕜 f t x ∧ (0 : E →L[𝕜] F) ∈ s := by
by_cases hx : DifferentiableWithinAt 𝕜 f t x <;>
simp [fderivWithin_zero_of_not_differentiableWithinAt, *]
theorem Asymptotics.IsBigO.hasFDerivWithinAt {s : Set E} {x₀ : E} {n : ℕ}
(h : f =O[𝓝[s] x₀] fun x => ‖x - x₀‖ ^ n) (hx₀ : x₀ ∈ s) (hn : 1 < n) :
HasFDerivWithinAt f (0 : E →L[𝕜] F) s x₀ := by
simp_rw [HasFDerivWithinAt, hasFDerivAtFilter_iff_isLittleO,
h.eq_zero_of_norm_pow_within hx₀ hn.ne_bot, zero_apply, sub_zero,
h.trans_isLittleO ((isLittleO_pow_sub_sub x₀ hn).mono nhdsWithin_le_nhds)]
theorem Asymptotics.IsBigO.hasFDerivAt {x₀ : E} {n : ℕ} (h : f =O[𝓝 x₀] fun x => ‖x - x₀‖ ^ n)
(hn : 1 < n) : HasFDerivAt f (0 : E →L[𝕜] F) x₀ := by
rw [← nhdsWithin_univ] at h
exact (h.hasFDerivWithinAt (mem_univ _) hn).hasFDerivAt_of_univ
nonrec theorem HasFDerivWithinAt.isBigO_sub {f : E → F} {s : Set E} {x₀ : E} {f' : E →L[𝕜] F}
(h : HasFDerivWithinAt f f' s x₀) : (f · - f x₀) =O[𝓝[s] x₀] (· - x₀) :=
h.isBigO_sub
lemma DifferentiableWithinAt.isBigO_sub {f : E → F} {s : Set E} {x₀ : E}
(h : DifferentiableWithinAt 𝕜 f s x₀) : (f · - f x₀) =O[𝓝[s] x₀] (· - x₀) :=
h.hasFDerivWithinAt.isBigO_sub
nonrec theorem HasFDerivAt.isBigO_sub {f : E → F} {x₀ : E} {f' : E →L[𝕜] F}
(h : HasFDerivAt f f' x₀) : (f · - f x₀) =O[𝓝 x₀] (· - x₀) :=
h.isBigO_sub
nonrec theorem DifferentiableAt.isBigO_sub {f : E → F} {x₀ : E} (h : DifferentiableAt 𝕜 f x₀) :
(f · - f x₀) =O[𝓝 x₀] (· - x₀) :=
h.hasFDerivAt.isBigO_sub
end FDerivProperties
section Continuous
/-! ### Deducing continuity from differentiability -/
theorem HasFDerivAtFilter.tendsto_nhds (hL : L ≤ 𝓝 x) (h : HasFDerivAtFilter f f' x L) :
Tendsto f L (𝓝 (f x)) := by
have : Tendsto (fun x' => f x' - f x) L (𝓝 0) := by
refine h.isBigO_sub.trans_tendsto (Tendsto.mono_left ?_ hL)
rw [← sub_self x]
exact tendsto_id.sub tendsto_const_nhds
have := this.add (tendsto_const_nhds (x := f x))
rw [zero_add (f x)] at this
exact this.congr (by simp only [sub_add_cancel, eq_self_iff_true, forall_const])
theorem HasFDerivWithinAt.continuousWithinAt (h : HasFDerivWithinAt f f' s x) :
ContinuousWithinAt f s x :=
HasFDerivAtFilter.tendsto_nhds inf_le_left h
theorem HasFDerivAt.continuousAt (h : HasFDerivAt f f' x) : ContinuousAt f x :=
HasFDerivAtFilter.tendsto_nhds le_rfl h
@[fun_prop]
theorem DifferentiableWithinAt.continuousWithinAt (h : DifferentiableWithinAt 𝕜 f s x) :
ContinuousWithinAt f s x :=
let ⟨_, hf'⟩ := h
hf'.continuousWithinAt
@[fun_prop]
theorem DifferentiableAt.continuousAt (h : DifferentiableAt 𝕜 f x) : ContinuousAt f x :=
let ⟨_, hf'⟩ := h
hf'.continuousAt
@[fun_prop]
theorem DifferentiableOn.continuousOn (h : DifferentiableOn 𝕜 f s) : ContinuousOn f s := fun x hx =>
(h x hx).continuousWithinAt
@[fun_prop]
theorem Differentiable.continuous (h : Differentiable 𝕜 f) : Continuous f :=
continuous_iff_continuousAt.2 fun x => (h x).continuousAt
protected theorem HasStrictFDerivAt.continuousAt (hf : HasStrictFDerivAt f f' x) :
ContinuousAt f x :=
hf.hasFDerivAt.continuousAt
theorem HasStrictFDerivAt.isBigO_sub_rev {f' : E ≃L[𝕜] F}
(hf : HasStrictFDerivAt f (f' : E →L[𝕜] F) x) :
(fun p : E × E => p.1 - p.2) =O[𝓝 (x, x)] fun p : E × E => f p.1 - f p.2 :=
((f'.isBigO_comp_rev _ _).trans
(hf.isLittleO.trans_isBigO (f'.isBigO_comp_rev _ _)).right_isBigO_add).congr
(fun _ => rfl) fun _ => sub_add_cancel _ _
theorem HasFDerivAtFilter.isBigO_sub_rev (hf : HasFDerivAtFilter f f' x L) {C}
(hf' : AntilipschitzWith C f') : (fun x' => x' - x) =O[L] fun x' => f x' - f x :=
have : (fun x' => x' - x) =O[L] fun x' => f' (x' - x) :=
isBigO_iff.2 ⟨C, Eventually.of_forall fun _ => ZeroHomClass.bound_of_antilipschitz f' hf' _⟩
(this.trans (hf.isLittleO.trans_isBigO this).right_isBigO_add).congr (fun _ => rfl) fun _ =>
sub_add_cancel _ _
end Continuous
section congr
/-! ### congr properties of the derivative -/
theorem hasFDerivWithinAt_congr_set' (y : E) (h : s =ᶠ[𝓝[{y}ᶜ] x] t) :
HasFDerivWithinAt f f' s x ↔ HasFDerivWithinAt f f' t x :=
calc
HasFDerivWithinAt f f' s x ↔ HasFDerivWithinAt f f' (s \ {y}) x :=
(hasFDerivWithinAt_diff_singleton _).symm
_ ↔ HasFDerivWithinAt f f' (t \ {y}) x := by
suffices 𝓝[s \ {y}] x = 𝓝[t \ {y}] x by simp only [HasFDerivWithinAt, this]
simpa only [set_eventuallyEq_iff_inf_principal, ← nhdsWithin_inter', diff_eq,
inter_comm] using h
_ ↔ HasFDerivWithinAt f f' t x := hasFDerivWithinAt_diff_singleton _
theorem hasFDerivWithinAt_congr_set (h : s =ᶠ[𝓝 x] t) :
HasFDerivWithinAt f f' s x ↔ HasFDerivWithinAt f f' t x :=
hasFDerivWithinAt_congr_set' x <| h.filter_mono inf_le_left
theorem differentiableWithinAt_congr_set' (y : E) (h : s =ᶠ[𝓝[{y}ᶜ] x] t) :
DifferentiableWithinAt 𝕜 f s x ↔ DifferentiableWithinAt 𝕜 f t x :=
exists_congr fun _ => hasFDerivWithinAt_congr_set' _ h
theorem differentiableWithinAt_congr_set (h : s =ᶠ[𝓝 x] t) :
DifferentiableWithinAt 𝕜 f s x ↔ DifferentiableWithinAt 𝕜 f t x :=
exists_congr fun _ => hasFDerivWithinAt_congr_set h
theorem fderivWithin_congr_set' (y : E) (h : s =ᶠ[𝓝[{y}ᶜ] x] t) :
fderivWithin 𝕜 f s x = fderivWithin 𝕜 f t x := by
classical
simp only [fderivWithin, differentiableWithinAt_congr_set' _ h, hasFDerivWithinAt_congr_set' _ h]
theorem fderivWithin_congr_set (h : s =ᶠ[𝓝 x] t) : fderivWithin 𝕜 f s x = fderivWithin 𝕜 f t x :=
fderivWithin_congr_set' x <| h.filter_mono inf_le_left
theorem fderivWithin_eventually_congr_set' (y : E) (h : s =ᶠ[𝓝[{y}ᶜ] x] t) :
fderivWithin 𝕜 f s =ᶠ[𝓝 x] fderivWithin 𝕜 f t :=
(eventually_nhds_nhdsWithin.2 h).mono fun _ => fderivWithin_congr_set' y
theorem fderivWithin_eventually_congr_set (h : s =ᶠ[𝓝 x] t) :
fderivWithin 𝕜 f s =ᶠ[𝓝 x] fderivWithin 𝕜 f t :=
fderivWithin_eventually_congr_set' x <| h.filter_mono inf_le_left
theorem Filter.EventuallyEq.hasStrictFDerivAt_iff (h : f₀ =ᶠ[𝓝 x] f₁) (h' : ∀ y, f₀' y = f₁' y) :
HasStrictFDerivAt f₀ f₀' x ↔ HasStrictFDerivAt f₁ f₁' x := by
rw [hasStrictFDerivAt_iff_isLittleOTVS, hasStrictFDerivAt_iff_isLittleOTVS]
refine isLittleOTVS_congr ((h.prodMk_nhds h).mono ?_) .rfl
rintro p ⟨hp₁, hp₂⟩
simp only [*]
theorem HasStrictFDerivAt.congr_fderiv (h : HasStrictFDerivAt f f' x) (h' : f' = g') :
HasStrictFDerivAt f g' x :=
h' ▸ h
theorem HasFDerivAt.congr_fderiv (h : HasFDerivAt f f' x) (h' : f' = g') : HasFDerivAt f g' x :=
h' ▸ h
theorem HasFDerivWithinAt.congr_fderiv (h : HasFDerivWithinAt f f' s x) (h' : f' = g') :
HasFDerivWithinAt f g' s x :=
h' ▸ h
theorem HasStrictFDerivAt.congr_of_eventuallyEq (h : HasStrictFDerivAt f f' x)
(h₁ : f =ᶠ[𝓝 x] f₁) : HasStrictFDerivAt f₁ f' x :=
(h₁.hasStrictFDerivAt_iff fun _ => rfl).1 h
theorem Filter.EventuallyEq.hasFDerivAtFilter_iff (h₀ : f₀ =ᶠ[L] f₁) (hx : f₀ x = f₁ x)
(h₁ : ∀ x, f₀' x = f₁' x) : HasFDerivAtFilter f₀ f₀' x L ↔ HasFDerivAtFilter f₁ f₁' x L := by
simp only [hasFDerivAtFilter_iff_isLittleOTVS]
exact isLittleOTVS_congr (h₀.mono fun y hy => by simp only [hy, h₁, hx]) .rfl
theorem HasFDerivAtFilter.congr_of_eventuallyEq (h : HasFDerivAtFilter f f' x L) (hL : f₁ =ᶠ[L] f)
(hx : f₁ x = f x) : HasFDerivAtFilter f₁ f' x L :=
(hL.hasFDerivAtFilter_iff hx fun _ => rfl).2 h
theorem Filter.EventuallyEq.hasFDerivAt_iff (h : f₀ =ᶠ[𝓝 x] f₁) :
HasFDerivAt f₀ f' x ↔ HasFDerivAt f₁ f' x :=
h.hasFDerivAtFilter_iff h.eq_of_nhds fun _ => _root_.rfl
theorem Filter.EventuallyEq.differentiableAt_iff (h : f₀ =ᶠ[𝓝 x] f₁) :
DifferentiableAt 𝕜 f₀ x ↔ DifferentiableAt 𝕜 f₁ x :=
exists_congr fun _ => h.hasFDerivAt_iff
theorem Filter.EventuallyEq.hasFDerivWithinAt_iff (h : f₀ =ᶠ[𝓝[s] x] f₁) (hx : f₀ x = f₁ x) :
HasFDerivWithinAt f₀ f' s x ↔ HasFDerivWithinAt f₁ f' s x :=
h.hasFDerivAtFilter_iff hx fun _ => _root_.rfl
theorem Filter.EventuallyEq.hasFDerivWithinAt_iff_of_mem (h : f₀ =ᶠ[𝓝[s] x] f₁) (hx : x ∈ s) :
HasFDerivWithinAt f₀ f' s x ↔ HasFDerivWithinAt f₁ f' s x :=
h.hasFDerivWithinAt_iff (h.eq_of_nhdsWithin hx)
theorem Filter.EventuallyEq.differentiableWithinAt_iff (h : f₀ =ᶠ[𝓝[s] x] f₁) (hx : f₀ x = f₁ x) :
DifferentiableWithinAt 𝕜 f₀ s x ↔ DifferentiableWithinAt 𝕜 f₁ s x :=
exists_congr fun _ => h.hasFDerivWithinAt_iff hx
theorem Filter.EventuallyEq.differentiableWithinAt_iff_of_mem (h : f₀ =ᶠ[𝓝[s] x] f₁) (hx : x ∈ s) :
DifferentiableWithinAt 𝕜 f₀ s x ↔ DifferentiableWithinAt 𝕜 f₁ s x :=
h.differentiableWithinAt_iff (h.eq_of_nhdsWithin hx)
theorem HasFDerivWithinAt.congr_mono (h : HasFDerivWithinAt f f' s x) (ht : EqOn f₁ f t)
(hx : f₁ x = f x) (h₁ : t ⊆ s) : HasFDerivWithinAt f₁ f' t x :=
HasFDerivAtFilter.congr_of_eventuallyEq (h.mono h₁) (Filter.mem_inf_of_right ht) hx
theorem HasFDerivWithinAt.congr (h : HasFDerivWithinAt f f' s x) (hs : EqOn f₁ f s)
(hx : f₁ x = f x) : HasFDerivWithinAt f₁ f' s x :=
h.congr_mono hs hx (Subset.refl _)
theorem HasFDerivWithinAt.congr' (h : HasFDerivWithinAt f f' s x) (hs : EqOn f₁ f s) (hx : x ∈ s) :
HasFDerivWithinAt f₁ f' s x :=
h.congr hs (hs hx)
theorem HasFDerivWithinAt.congr_of_eventuallyEq (h : HasFDerivWithinAt f f' s x)
(h₁ : f₁ =ᶠ[𝓝[s] x] f) (hx : f₁ x = f x) : HasFDerivWithinAt f₁ f' s x :=
HasFDerivAtFilter.congr_of_eventuallyEq h h₁ hx
theorem HasFDerivAt.congr_of_eventuallyEq (h : HasFDerivAt f f' x) (h₁ : f₁ =ᶠ[𝓝 x] f) :
HasFDerivAt f₁ f' x :=
HasFDerivAtFilter.congr_of_eventuallyEq h h₁ (mem_of_mem_nhds h₁ :)
theorem DifferentiableWithinAt.congr_mono (h : DifferentiableWithinAt 𝕜 f s x) (ht : EqOn f₁ f t)
(hx : f₁ x = f x) (h₁ : t ⊆ s) : DifferentiableWithinAt 𝕜 f₁ t x :=
(HasFDerivWithinAt.congr_mono h.hasFDerivWithinAt ht hx h₁).differentiableWithinAt
theorem DifferentiableWithinAt.congr (h : DifferentiableWithinAt 𝕜 f s x) (ht : ∀ x ∈ s, f₁ x = f x)
(hx : f₁ x = f x) : DifferentiableWithinAt 𝕜 f₁ s x :=
DifferentiableWithinAt.congr_mono h ht hx (Subset.refl _)
theorem DifferentiableWithinAt.congr_of_eventuallyEq (h : DifferentiableWithinAt 𝕜 f s x)
(h₁ : f₁ =ᶠ[𝓝[s] x] f) (hx : f₁ x = f x) : DifferentiableWithinAt 𝕜 f₁ s x :=
(h.hasFDerivWithinAt.congr_of_eventuallyEq h₁ hx).differentiableWithinAt
theorem DifferentiableWithinAt.congr_of_eventuallyEq_of_mem (h : DifferentiableWithinAt 𝕜 f s x)
(h₁ : f₁ =ᶠ[𝓝[s] x] f) (hx : x ∈ s) : DifferentiableWithinAt 𝕜 f₁ s x :=
h.congr_of_eventuallyEq h₁ (mem_of_mem_nhdsWithin hx h₁ :)
theorem DifferentiableWithinAt.congr_of_eventuallyEq_insert (h : DifferentiableWithinAt 𝕜 f s x)
(h₁ : f₁ =ᶠ[𝓝[insert x s] x] f) : DifferentiableWithinAt 𝕜 f₁ s x :=
(h.insert.congr_of_eventuallyEq_of_mem h₁ (mem_insert _ _)).of_insert
theorem DifferentiableOn.congr_mono (h : DifferentiableOn 𝕜 f s) (h' : ∀ x ∈ t, f₁ x = f x)
(h₁ : t ⊆ s) : DifferentiableOn 𝕜 f₁ t := fun x hx => (h x (h₁ hx)).congr_mono h' (h' x hx) h₁
theorem DifferentiableOn.congr (h : DifferentiableOn 𝕜 f s) (h' : ∀ x ∈ s, f₁ x = f x) :
DifferentiableOn 𝕜 f₁ s := fun x hx => (h x hx).congr h' (h' x hx)
theorem differentiableOn_congr (h' : ∀ x ∈ s, f₁ x = f x) :
DifferentiableOn 𝕜 f₁ s ↔ DifferentiableOn 𝕜 f s :=
⟨fun h => DifferentiableOn.congr h fun y hy => (h' y hy).symm, fun h =>
DifferentiableOn.congr h h'⟩
theorem DifferentiableAt.congr_of_eventuallyEq (h : DifferentiableAt 𝕜 f x) (hL : f₁ =ᶠ[𝓝 x] f) :
DifferentiableAt 𝕜 f₁ x :=
hL.differentiableAt_iff.2 h
theorem DifferentiableWithinAt.fderivWithin_congr_mono (h : DifferentiableWithinAt 𝕜 f s x)
(hs : EqOn f₁ f t) (hx : f₁ x = f x) (hxt : UniqueDiffWithinAt 𝕜 t x) (h₁ : t ⊆ s) :
fderivWithin 𝕜 f₁ t x = fderivWithin 𝕜 f s x :=
(HasFDerivWithinAt.congr_mono h.hasFDerivWithinAt hs hx h₁).fderivWithin hxt
theorem Filter.EventuallyEq.fderivWithin_eq (hs : f₁ =ᶠ[𝓝[s] x] f) (hx : f₁ x = f x) :
fderivWithin 𝕜 f₁ s x = fderivWithin 𝕜 f s x := by
classical
simp only [fderivWithin, DifferentiableWithinAt, hs.hasFDerivWithinAt_iff hx]
theorem Filter.EventuallyEq.fderivWithin_eq_of_mem (hs : f₁ =ᶠ[𝓝[s] x] f) (hx : x ∈ s) :
fderivWithin 𝕜 f₁ s x = fderivWithin 𝕜 f s x :=
hs.fderivWithin_eq (mem_of_mem_nhdsWithin hx hs :)
theorem Filter.EventuallyEq.fderivWithin_eq_of_insert (hs : f₁ =ᶠ[𝓝[insert x s] x] f) :
fderivWithin 𝕜 f₁ s x = fderivWithin 𝕜 f s x := by
apply Filter.EventuallyEq.fderivWithin_eq (nhdsWithin_mono _ (subset_insert x s) hs)
exact (mem_of_mem_nhdsWithin (mem_insert x s) hs :)
theorem Filter.EventuallyEq.fderivWithin' (hs : f₁ =ᶠ[𝓝[s] x] f) (ht : t ⊆ s) :
fderivWithin 𝕜 f₁ t =ᶠ[𝓝[s] x] fderivWithin 𝕜 f t :=
(eventually_eventually_nhdsWithin.2 hs).mp <|
eventually_mem_nhdsWithin.mono fun _y hys hs =>
EventuallyEq.fderivWithin_eq (hs.filter_mono <| nhdsWithin_mono _ ht)
(hs.self_of_nhdsWithin hys)
protected theorem Filter.EventuallyEq.fderivWithin (hs : f₁ =ᶠ[𝓝[s] x] f) :
fderivWithin 𝕜 f₁ s =ᶠ[𝓝[s] x] fderivWithin 𝕜 f s :=
hs.fderivWithin' Subset.rfl
theorem Filter.EventuallyEq.fderivWithin_eq_nhds (h : f₁ =ᶠ[𝓝 x] f) :
fderivWithin 𝕜 f₁ s x = fderivWithin 𝕜 f s x :=
(h.filter_mono nhdsWithin_le_nhds).fderivWithin_eq h.self_of_nhds
theorem fderivWithin_congr (hs : EqOn f₁ f s) (hx : f₁ x = f x) :
fderivWithin 𝕜 f₁ s x = fderivWithin 𝕜 f s x :=
(hs.eventuallyEq.filter_mono inf_le_right).fderivWithin_eq hx
theorem fderivWithin_congr' (hs : EqOn f₁ f s) (hx : x ∈ s) :
fderivWithin 𝕜 f₁ s x = fderivWithin 𝕜 f s x :=
fderivWithin_congr hs (hs hx)
theorem Filter.EventuallyEq.fderiv_eq (h : f₁ =ᶠ[𝓝 x] f) : fderiv 𝕜 f₁ x = fderiv 𝕜 f x := by
rw [← fderivWithin_univ, ← fderivWithin_univ, h.fderivWithin_eq_nhds]
protected theorem Filter.EventuallyEq.fderiv (h : f₁ =ᶠ[𝓝 x] f) : fderiv 𝕜 f₁ =ᶠ[𝓝 x] fderiv 𝕜 f :=
h.eventuallyEq_nhds.mono fun _ h => h.fderiv_eq
end congr
section id
/-! ### Derivative of the identity -/
@[fun_prop]
theorem hasStrictFDerivAt_id (x : E) : HasStrictFDerivAt id (id 𝕜 E) x :=
.of_isLittleOTVS <| (IsLittleOTVS.zero _ _).congr_left <| by simp
theorem hasFDerivAtFilter_id (x : E) (L : Filter E) : HasFDerivAtFilter id (id 𝕜 E) x L :=
.of_isLittleOTVS <| (IsLittleOTVS.zero _ _).congr_left <| by simp
@[fun_prop]
theorem hasFDerivWithinAt_id (x : E) (s : Set E) : HasFDerivWithinAt id (id 𝕜 E) s x :=
hasFDerivAtFilter_id _ _
@[fun_prop]
theorem hasFDerivAt_id (x : E) : HasFDerivAt id (id 𝕜 E) x :=
hasFDerivAtFilter_id _ _
@[simp, fun_prop]
theorem differentiableAt_id : DifferentiableAt 𝕜 id x :=
(hasFDerivAt_id x).differentiableAt
/-- Variant with `fun x => x` rather than `id` -/
@[simp]
theorem differentiableAt_id' : DifferentiableAt 𝕜 (fun x => x) x :=
(hasFDerivAt_id x).differentiableAt
@[fun_prop]
theorem differentiableWithinAt_id : DifferentiableWithinAt 𝕜 id s x :=
differentiableAt_id.differentiableWithinAt
/-- Variant with `fun x => x` rather than `id` -/
@[fun_prop]
theorem differentiableWithinAt_id' : DifferentiableWithinAt 𝕜 (fun x => x) s x :=
differentiableWithinAt_id
@[simp, fun_prop]
theorem differentiable_id : Differentiable 𝕜 (id : E → E) := fun _ => differentiableAt_id
/-- Variant with `fun x => x` rather than `id` -/
@[simp]
theorem differentiable_id' : Differentiable 𝕜 fun x : E => x := fun _ => differentiableAt_id
@[fun_prop]
theorem differentiableOn_id : DifferentiableOn 𝕜 id s :=
differentiable_id.differentiableOn
@[simp]
theorem fderiv_id : fderiv 𝕜 id x = id 𝕜 E :=
HasFDerivAt.fderiv (hasFDerivAt_id x)
@[simp]
theorem fderiv_id' : fderiv 𝕜 (fun x : E => x) x = ContinuousLinearMap.id 𝕜 E :=
fderiv_id
theorem fderivWithin_id (hxs : UniqueDiffWithinAt 𝕜 s x) : fderivWithin 𝕜 id s x = id 𝕜 E := by
rw [DifferentiableAt.fderivWithin differentiableAt_id hxs]
exact fderiv_id
theorem fderivWithin_id' (hxs : UniqueDiffWithinAt 𝕜 s x) :
fderivWithin 𝕜 (fun x : E => x) s x = ContinuousLinearMap.id 𝕜 E :=
fderivWithin_id hxs
end id
section Const
/-! ### Derivative of constant functions
This include the constant functions `0`, `1`, `Nat.cast n`, `Int.cast z`, and other numerals.
-/
@[fun_prop]
theorem hasStrictFDerivAt_const (c : F) (x : E) :
HasStrictFDerivAt (fun _ => c) (0 : E →L[𝕜] F) x :=
.of_isLittleOTVS <| (IsLittleOTVS.zero _ _).congr_left fun _ => by
simp only [zero_apply, sub_self, Pi.zero_apply]
@[fun_prop]
theorem hasStrictFDerivAt_zero (x : E) :
HasStrictFDerivAt (0 : E → F) (0 : E →L[𝕜] F) x := hasStrictFDerivAt_const _ _
@[fun_prop]
theorem hasStrictFDerivAt_one [One F] (x : E) :
HasStrictFDerivAt (1 : E → F) (0 : E →L[𝕜] F) x := hasStrictFDerivAt_const _ _
@[fun_prop]
theorem hasStrictFDerivAt_natCast [NatCast F] (n : ℕ) (x : E) :
HasStrictFDerivAt (n : E → F) (0 : E →L[𝕜] F) x := hasStrictFDerivAt_const _ _
@[fun_prop]
theorem hasStrictFDerivAt_intCast [IntCast F] (z : ℤ) (x : E) :
HasStrictFDerivAt (z : E → F) (0 : E →L[𝕜] F) x := hasStrictFDerivAt_const _ _
@[fun_prop]
theorem hasStrictFDerivAt_ofNat (n : ℕ) [OfNat F n] (x : E) :
HasStrictFDerivAt (ofNat(n) : E → F) (0 : E →L[𝕜] F) x := hasStrictFDerivAt_const _ _
theorem hasFDerivAtFilter_const (c : F) (x : E) (L : Filter E) :
HasFDerivAtFilter (fun _ => c) (0 : E →L[𝕜] F) x L :=
.of_isLittleOTVS <| (IsLittleOTVS.zero _ _).congr_left fun _ => by
simp only [zero_apply, sub_self, Pi.zero_apply]
theorem hasFDerivAtFilter_zero (x : E) (L : Filter E) :
HasFDerivAtFilter (0 : E → F) (0 : E →L[𝕜] F) x L := hasFDerivAtFilter_const _ _ _
theorem hasFDerivAtFilter_one [One F] (x : E) (L : Filter E) :
HasFDerivAtFilter (1 : E → F) (0 : E →L[𝕜] F) x L := hasFDerivAtFilter_const _ _ _
theorem hasFDerivAtFilter_natCast [NatCast F] (n : ℕ) (x : E) (L : Filter E) :
HasFDerivAtFilter (n : E → F) (0 : E →L[𝕜] F) x L :=
hasFDerivAtFilter_const _ _ _
theorem hasFDerivAtFilter_intCast [IntCast F] (z : ℤ) (x : E) (L : Filter E) :
HasFDerivAtFilter (z : E → F) (0 : E →L[𝕜] F) x L :=
hasFDerivAtFilter_const _ _ _
theorem hasFDerivAtFilter_ofNat (n : ℕ) [OfNat F n] (x : E) (L : Filter E) :
HasFDerivAtFilter (ofNat(n) : E → F) (0 : E →L[𝕜] F) x L :=
hasFDerivAtFilter_const _ _ _
@[fun_prop]
theorem hasFDerivWithinAt_const (c : F) (x : E) (s : Set E) :
HasFDerivWithinAt (fun _ => c) (0 : E →L[𝕜] F) s x :=
hasFDerivAtFilter_const _ _ _
@[fun_prop]
theorem hasFDerivWithinAt_zero (x : E) (s : Set E) :
HasFDerivWithinAt (0 : E → F) (0 : E →L[𝕜] F) s x := hasFDerivWithinAt_const _ _ _
@[fun_prop]
theorem hasFDerivWithinAt_one [One F] (x : E) (s : Set E) :
HasFDerivWithinAt (1 : E → F) (0 : E →L[𝕜] F) s x := hasFDerivWithinAt_const _ _ _
@[fun_prop]
theorem hasFDerivWithinAt_natCast [NatCast F] (n : ℕ) (x : E) (s : Set E) :
HasFDerivWithinAt (n : E → F) (0 : E →L[𝕜] F) s x :=
hasFDerivWithinAt_const _ _ _
@[fun_prop]
theorem hasFDerivWithinAt_intCast [IntCast F] (z : ℤ) (x : E) (s : Set E) :
HasFDerivWithinAt (z : E → F) (0 : E →L[𝕜] F) s x :=
hasFDerivWithinAt_const _ _ _
@[fun_prop]
theorem hasFDerivWithinAt_ofNat (n : ℕ) [OfNat F n] (x : E) (s : Set E) :
HasFDerivWithinAt (ofNat(n) : E → F) (0 : E →L[𝕜] F) s x :=
hasFDerivWithinAt_const _ _ _
@[fun_prop]
theorem hasFDerivAt_const (c : F) (x : E) : HasFDerivAt (fun _ => c) (0 : E →L[𝕜] F) x :=
hasFDerivAtFilter_const _ _ _
@[fun_prop]
theorem hasFDerivAt_zero (x : E) :
HasFDerivAt (0 : E → F) (0 : E →L[𝕜] F) x := hasFDerivAt_const _ _
@[fun_prop]
theorem hasFDerivAt_one [One F] (x : E) :
HasFDerivAt (1 : E → F) (0 : E →L[𝕜] F) x := hasFDerivAt_const _ _
@[fun_prop]
theorem hasFDerivAt_natCast [NatCast F] (n : ℕ) (x : E) :
HasFDerivAt (n : E → F) (0 : E →L[𝕜] F) x := hasFDerivAt_const _ _
@[fun_prop]
theorem hasFDerivAt_intCast [IntCast F] (z : ℤ) (x : E) :
HasFDerivAt (z : E → F) (0 : E →L[𝕜] F) x := hasFDerivAt_const _ _
@[fun_prop]
theorem hasFDerivAt_ofNat (n : ℕ) [OfNat F n] (x : E) :
HasFDerivAt (ofNat(n) : E → F) (0 : E →L[𝕜] F) x := hasFDerivAt_const _ _
@[simp, fun_prop]
theorem differentiableAt_const (c : F) : DifferentiableAt 𝕜 (fun _ => c) x :=
⟨0, hasFDerivAt_const c x⟩
@[simp, fun_prop]
theorem differentiableAt_zero (x : E) :
DifferentiableAt 𝕜 (0 : E → F) x := differentiableAt_const _
@[simp, fun_prop]
theorem differentiableAt_one [One F] (x : E) :
DifferentiableAt 𝕜 (1 : E → F) x := differentiableAt_const _
@[simp, fun_prop]
theorem differentiableAt_natCast [NatCast F] (n : ℕ) (x : E) :
DifferentiableAt 𝕜 (n : E → F) x := differentiableAt_const _
@[simp, fun_prop]
theorem differentiableAt_intCast [IntCast F] (z : ℤ) (x : E) :
DifferentiableAt 𝕜 (z : E → F) x := differentiableAt_const _
|
@[simp low, fun_prop]
theorem differentiableAt_ofNat (n : ℕ) [OfNat F n] (x : E) :
DifferentiableAt 𝕜 (ofNat(n) : E → F) x := differentiableAt_const _
| Mathlib/Analysis/Calculus/FDeriv/Basic.lean | 1,186 | 1,189 |
/-
Copyright (c) 2018 Patrick Massot. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Massot, Johannes Hölzl, Yaël Dillies
-/
import Mathlib.Analysis.Normed.Group.Seminorm
import Mathlib.Data.NNReal.Basic
import Mathlib.Topology.Algebra.Support
import Mathlib.Topology.MetricSpace.Basic
import Mathlib.Topology.Order.Real
/-!
# Normed (semi)groups
In this file we define 10 classes:
* `Norm`, `NNNorm`: auxiliary classes endowing a type `α` with a function `norm : α → ℝ`
(notation: `‖x‖`) and `nnnorm : α → ℝ≥0` (notation: `‖x‖₊`), respectively;
* `Seminormed...Group`: A seminormed (additive) (commutative) group is an (additive) (commutative)
group with a norm and a compatible pseudometric space structure:
`∀ x y, dist x y = ‖x / y‖` or `∀ x y, dist x y = ‖x - y‖`, depending on the group operation.
* `Normed...Group`: A normed (additive) (commutative) group is an (additive) (commutative) group
with a norm and a compatible metric space structure.
We also prove basic properties of (semi)normed groups and provide some instances.
## Notes
The current convention `dist x y = ‖x - y‖` means that the distance is invariant under right
addition, but actions in mathlib are usually from the left. This means we might want to change it to
`dist x y = ‖-x + y‖`.
The normed group hierarchy would lend itself well to a mixin design (that is, having
`SeminormedGroup` and `SeminormedAddGroup` not extend `Group` and `AddGroup`), but we choose not
to for performance concerns.
## Tags
normed group
-/
variable {𝓕 α ι κ E F G : Type*}
open Filter Function Metric Bornology
open ENNReal Filter NNReal Uniformity Pointwise Topology
/-- Auxiliary class, endowing a type `E` with a function `norm : E → ℝ` with notation `‖x‖`. This
class is designed to be extended in more interesting classes specifying the properties of the norm.
-/
@[notation_class]
class Norm (E : Type*) where
/-- the `ℝ`-valued norm function. -/
norm : E → ℝ
/-- Auxiliary class, endowing a type `α` with a function `nnnorm : α → ℝ≥0` with notation `‖x‖₊`. -/
@[notation_class]
class NNNorm (E : Type*) where
/-- the `ℝ≥0`-valued norm function. -/
nnnorm : E → ℝ≥0
/-- Auxiliary class, endowing a type `α` with a function `enorm : α → ℝ≥0∞` with notation `‖x‖ₑ`. -/
@[notation_class]
class ENorm (E : Type*) where
/-- the `ℝ≥0∞`-valued norm function. -/
enorm : E → ℝ≥0∞
export Norm (norm)
export NNNorm (nnnorm)
export ENorm (enorm)
@[inherit_doc] notation "‖" e "‖" => norm e
@[inherit_doc] notation "‖" e "‖₊" => nnnorm e
@[inherit_doc] notation "‖" e "‖ₑ" => enorm e
section ENorm
variable {E : Type*} [NNNorm E] {x : E} {r : ℝ≥0}
instance NNNorm.toENorm : ENorm E where enorm := (‖·‖₊ : E → ℝ≥0∞)
lemma enorm_eq_nnnorm (x : E) : ‖x‖ₑ = ‖x‖₊ := rfl
@[simp] lemma toNNReal_enorm (x : E) : ‖x‖ₑ.toNNReal = ‖x‖₊ := rfl
@[simp, norm_cast] lemma coe_le_enorm : r ≤ ‖x‖ₑ ↔ r ≤ ‖x‖₊ := by simp [enorm]
@[simp, norm_cast] lemma enorm_le_coe : ‖x‖ₑ ≤ r ↔ ‖x‖₊ ≤ r := by simp [enorm]
@[simp, norm_cast] lemma coe_lt_enorm : r < ‖x‖ₑ ↔ r < ‖x‖₊ := by simp [enorm]
@[simp, norm_cast] lemma enorm_lt_coe : ‖x‖ₑ < r ↔ ‖x‖₊ < r := by simp [enorm]
@[simp] lemma enorm_ne_top : ‖x‖ₑ ≠ ∞ := by simp [enorm]
@[simp] lemma enorm_lt_top : ‖x‖ₑ < ∞ := by simp [enorm]
end ENorm
/-- A type `E` equipped with a continuous map `‖·‖ₑ : E → ℝ≥0∞`
NB. We do not demand that the topology is somehow defined by the enorm:
for ℝ≥0∞ (the motivating example behind this definition), this is not true. -/
class ContinuousENorm (E : Type*) [TopologicalSpace E] extends ENorm E where
continuous_enorm : Continuous enorm
/-- An enormed monoid is an additive monoid endowed with a continuous enorm. -/
class ENormedAddMonoid (E : Type*) [TopologicalSpace E] extends ContinuousENorm E, AddMonoid E where
enorm_eq_zero : ∀ x : E, ‖x‖ₑ = 0 ↔ x = 0
protected enorm_add_le : ∀ x y : E, ‖x + y‖ₑ ≤ ‖x‖ₑ + ‖y‖ₑ
/-- An enormed monoid is a monoid endowed with a continuous enorm. -/
@[to_additive]
class ENormedMonoid (E : Type*) [TopologicalSpace E] extends ContinuousENorm E, Monoid E where
enorm_eq_zero : ∀ x : E, ‖x‖ₑ = 0 ↔ x = 1
enorm_mul_le : ∀ x y : E, ‖x * y‖ₑ ≤ ‖x‖ₑ + ‖y‖ₑ
/-- An enormed commutative monoid is an additive commutative monoid
endowed with a continuous enorm.
We don't have `ENormedAddCommMonoid` extend `EMetricSpace`, since the canonical instance `ℝ≥0∞`
is not an `EMetricSpace`. This is because `ℝ≥0∞` carries the order topology, which is distinct from
the topology coming from `edist`. -/
class ENormedAddCommMonoid (E : Type*) [TopologicalSpace E]
extends ENormedAddMonoid E, AddCommMonoid E where
/-- An enormed commutative monoid is a commutative monoid endowed with a continuous enorm. -/
@[to_additive]
class ENormedCommMonoid (E : Type*) [TopologicalSpace E] extends ENormedMonoid E, CommMonoid E where
/-- A seminormed group is an additive group endowed with a norm for which `dist x y = ‖x - y‖`
defines a pseudometric space structure. -/
class SeminormedAddGroup (E : Type*) extends Norm E, AddGroup E, PseudoMetricSpace E where
dist := fun x y => ‖x - y‖
/-- The distance function is induced by the norm. -/
dist_eq : ∀ x y, dist x y = ‖x - y‖ := by aesop
/-- A seminormed group is a group endowed with a norm for which `dist x y = ‖x / y‖` defines a
pseudometric space structure. -/
@[to_additive]
class SeminormedGroup (E : Type*) extends Norm E, Group E, PseudoMetricSpace E where
dist := fun x y => ‖x / y‖
/-- The distance function is induced by the norm. -/
dist_eq : ∀ x y, dist x y = ‖x / y‖ := by aesop
/-- A normed group is an additive group endowed with a norm for which `dist x y = ‖x - y‖` defines a
metric space structure. -/
class NormedAddGroup (E : Type*) extends Norm E, AddGroup E, MetricSpace E where
dist := fun x y => ‖x - y‖
/-- The distance function is induced by the norm. -/
dist_eq : ∀ x y, dist x y = ‖x - y‖ := by aesop
/-- A normed group is a group endowed with a norm for which `dist x y = ‖x / y‖` defines a metric
space structure. -/
@[to_additive]
class NormedGroup (E : Type*) extends Norm E, Group E, MetricSpace E where
dist := fun x y => ‖x / y‖
/-- The distance function is induced by the norm. -/
dist_eq : ∀ x y, dist x y = ‖x / y‖ := by aesop
/-- A seminormed group is an additive group endowed with a norm for which `dist x y = ‖x - y‖`
defines a pseudometric space structure. -/
class SeminormedAddCommGroup (E : Type*) extends Norm E, AddCommGroup E,
PseudoMetricSpace E where
dist := fun x y => ‖x - y‖
/-- The distance function is induced by the norm. -/
dist_eq : ∀ x y, dist x y = ‖x - y‖ := by aesop
/-- A seminormed group is a group endowed with a norm for which `dist x y = ‖x / y‖`
defines a pseudometric space structure. -/
@[to_additive]
class SeminormedCommGroup (E : Type*) extends Norm E, CommGroup E, PseudoMetricSpace E where
dist := fun x y => ‖x / y‖
/-- The distance function is induced by the norm. -/
dist_eq : ∀ x y, dist x y = ‖x / y‖ := by aesop
/-- A normed group is an additive group endowed with a norm for which `dist x y = ‖x - y‖` defines a
metric space structure. -/
class NormedAddCommGroup (E : Type*) extends Norm E, AddCommGroup E, MetricSpace E where
dist := fun x y => ‖x - y‖
/-- The distance function is induced by the norm. -/
dist_eq : ∀ x y, dist x y = ‖x - y‖ := by aesop
/-- A normed group is a group endowed with a norm for which `dist x y = ‖x / y‖` defines a metric
space structure. -/
@[to_additive]
class NormedCommGroup (E : Type*) extends Norm E, CommGroup E, MetricSpace E where
dist := fun x y => ‖x / y‖
/-- The distance function is induced by the norm. -/
dist_eq : ∀ x y, dist x y = ‖x / y‖ := by aesop
-- See note [lower instance priority]
@[to_additive]
instance (priority := 100) NormedGroup.toSeminormedGroup [NormedGroup E] : SeminormedGroup E :=
{ ‹NormedGroup E› with }
-- See note [lower instance priority]
@[to_additive]
instance (priority := 100) NormedCommGroup.toSeminormedCommGroup [NormedCommGroup E] :
SeminormedCommGroup E :=
{ ‹NormedCommGroup E› with }
-- See note [lower instance priority]
@[to_additive]
instance (priority := 100) SeminormedCommGroup.toSeminormedGroup [SeminormedCommGroup E] :
SeminormedGroup E :=
{ ‹SeminormedCommGroup E› with }
-- See note [lower instance priority]
@[to_additive]
instance (priority := 100) NormedCommGroup.toNormedGroup [NormedCommGroup E] : NormedGroup E :=
{ ‹NormedCommGroup E› with }
-- See note [reducible non-instances]
/-- Construct a `NormedGroup` from a `SeminormedGroup` satisfying `∀ x, ‖x‖ = 0 → x = 1`. This
avoids having to go back to the `(Pseudo)MetricSpace` level when declaring a `NormedGroup`
instance as a special case of a more general `SeminormedGroup` instance. -/
@[to_additive "Construct a `NormedAddGroup` from a `SeminormedAddGroup`
satisfying `∀ x, ‖x‖ = 0 → x = 0`. This avoids having to go back to the `(Pseudo)MetricSpace`
level when declaring a `NormedAddGroup` instance as a special case of a more general
`SeminormedAddGroup` instance."]
abbrev NormedGroup.ofSeparation [SeminormedGroup E] (h : ∀ x : E, ‖x‖ = 0 → x = 1) :
NormedGroup E where
dist_eq := ‹SeminormedGroup E›.dist_eq
toMetricSpace :=
{ eq_of_dist_eq_zero := fun hxy =>
div_eq_one.1 <| h _ <| (‹SeminormedGroup E›.dist_eq _ _).symm.trans hxy }
-- See note [reducible non-instances]
/-- Construct a `NormedCommGroup` from a `SeminormedCommGroup` satisfying
`∀ x, ‖x‖ = 0 → x = 1`. This avoids having to go back to the `(Pseudo)MetricSpace` level when
declaring a `NormedCommGroup` instance as a special case of a more general `SeminormedCommGroup`
instance. -/
@[to_additive "Construct a `NormedAddCommGroup` from a
`SeminormedAddCommGroup` satisfying `∀ x, ‖x‖ = 0 → x = 0`. This avoids having to go back to the
`(Pseudo)MetricSpace` level when declaring a `NormedAddCommGroup` instance as a special case
of a more general `SeminormedAddCommGroup` instance."]
abbrev NormedCommGroup.ofSeparation [SeminormedCommGroup E] (h : ∀ x : E, ‖x‖ = 0 → x = 1) :
NormedCommGroup E :=
{ ‹SeminormedCommGroup E›, NormedGroup.ofSeparation h with }
-- See note [reducible non-instances]
/-- Construct a seminormed group from a multiplication-invariant distance. -/
@[to_additive
"Construct a seminormed group from a translation-invariant distance."]
abbrev SeminormedGroup.ofMulDist [Norm E] [Group E] [PseudoMetricSpace E]
(h₁ : ∀ x : E, ‖x‖ = dist x 1) (h₂ : ∀ x y z : E, dist x y ≤ dist (x * z) (y * z)) :
SeminormedGroup E where
dist_eq x y := by
rw [h₁]; apply le_antisymm
· simpa only [div_eq_mul_inv, ← mul_inv_cancel y] using h₂ _ _ _
· simpa only [div_mul_cancel, one_mul] using h₂ (x / y) 1 y
-- See note [reducible non-instances]
/-- Construct a seminormed group from a multiplication-invariant pseudodistance. -/
@[to_additive
"Construct a seminormed group from a translation-invariant pseudodistance."]
abbrev SeminormedGroup.ofMulDist' [Norm E] [Group E] [PseudoMetricSpace E]
(h₁ : ∀ x : E, ‖x‖ = dist x 1) (h₂ : ∀ x y z : E, dist (x * z) (y * z) ≤ dist x y) :
SeminormedGroup E where
dist_eq x y := by
rw [h₁]; apply le_antisymm
· simpa only [div_mul_cancel, one_mul] using h₂ (x / y) 1 y
· simpa only [div_eq_mul_inv, ← mul_inv_cancel y] using h₂ _ _ _
-- See note [reducible non-instances]
/-- Construct a seminormed group from a multiplication-invariant pseudodistance. -/
@[to_additive
"Construct a seminormed group from a translation-invariant pseudodistance."]
abbrev SeminormedCommGroup.ofMulDist [Norm E] [CommGroup E] [PseudoMetricSpace E]
(h₁ : ∀ x : E, ‖x‖ = dist x 1) (h₂ : ∀ x y z : E, dist x y ≤ dist (x * z) (y * z)) :
SeminormedCommGroup E :=
{ SeminormedGroup.ofMulDist h₁ h₂ with
mul_comm := mul_comm }
-- See note [reducible non-instances]
/-- Construct a seminormed group from a multiplication-invariant pseudodistance. -/
@[to_additive
"Construct a seminormed group from a translation-invariant pseudodistance."]
abbrev SeminormedCommGroup.ofMulDist' [Norm E] [CommGroup E] [PseudoMetricSpace E]
(h₁ : ∀ x : E, ‖x‖ = dist x 1) (h₂ : ∀ x y z : E, dist (x * z) (y * z) ≤ dist x y) :
SeminormedCommGroup E :=
{ SeminormedGroup.ofMulDist' h₁ h₂ with
mul_comm := mul_comm }
-- See note [reducible non-instances]
/-- Construct a normed group from a multiplication-invariant distance. -/
@[to_additive
"Construct a normed group from a translation-invariant distance."]
abbrev NormedGroup.ofMulDist [Norm E] [Group E] [MetricSpace E] (h₁ : ∀ x : E, ‖x‖ = dist x 1)
(h₂ : ∀ x y z : E, dist x y ≤ dist (x * z) (y * z)) : NormedGroup E :=
{ SeminormedGroup.ofMulDist h₁ h₂ with
eq_of_dist_eq_zero := eq_of_dist_eq_zero }
-- See note [reducible non-instances]
/-- Construct a normed group from a multiplication-invariant pseudodistance. -/
@[to_additive
"Construct a normed group from a translation-invariant pseudodistance."]
abbrev NormedGroup.ofMulDist' [Norm E] [Group E] [MetricSpace E] (h₁ : ∀ x : E, ‖x‖ = dist x 1)
(h₂ : ∀ x y z : E, dist (x * z) (y * z) ≤ dist x y) : NormedGroup E :=
{ SeminormedGroup.ofMulDist' h₁ h₂ with
eq_of_dist_eq_zero := eq_of_dist_eq_zero }
-- See note [reducible non-instances]
/-- Construct a normed group from a multiplication-invariant pseudodistance. -/
@[to_additive
"Construct a normed group from a translation-invariant pseudodistance."]
abbrev NormedCommGroup.ofMulDist [Norm E] [CommGroup E] [MetricSpace E]
(h₁ : ∀ x : E, ‖x‖ = dist x 1) (h₂ : ∀ x y z : E, dist x y ≤ dist (x * z) (y * z)) :
NormedCommGroup E :=
{ NormedGroup.ofMulDist h₁ h₂ with
mul_comm := mul_comm }
-- See note [reducible non-instances]
/-- Construct a normed group from a multiplication-invariant pseudodistance. -/
@[to_additive
"Construct a normed group from a translation-invariant pseudodistance."]
abbrev NormedCommGroup.ofMulDist' [Norm E] [CommGroup E] [MetricSpace E]
(h₁ : ∀ x : E, ‖x‖ = dist x 1) (h₂ : ∀ x y z : E, dist (x * z) (y * z) ≤ dist x y) :
NormedCommGroup E :=
{ NormedGroup.ofMulDist' h₁ h₂ with
mul_comm := mul_comm }
-- See note [reducible non-instances]
/-- Construct a seminormed group from a seminorm, i.e., registering the pseudodistance and the
pseudometric space structure from the seminorm properties. Note that in most cases this instance
creates bad definitional equalities (e.g., it does not take into account a possibly existing
`UniformSpace` instance on `E`). -/
@[to_additive
"Construct a seminormed group from a seminorm, i.e., registering the pseudodistance
and the pseudometric space structure from the seminorm properties. Note that in most cases this
instance creates bad definitional equalities (e.g., it does not take into account a possibly
existing `UniformSpace` instance on `E`)."]
abbrev GroupSeminorm.toSeminormedGroup [Group E] (f : GroupSeminorm E) : SeminormedGroup E where
dist x y := f (x / y)
norm := f
dist_eq _ _ := rfl
dist_self x := by simp only [div_self', map_one_eq_zero]
dist_triangle := le_map_div_add_map_div f
dist_comm := map_div_rev f
-- See note [reducible non-instances]
/-- Construct a seminormed group from a seminorm, i.e., registering the pseudodistance and the
pseudometric space structure from the seminorm properties. Note that in most cases this instance
creates bad definitional equalities (e.g., it does not take into account a possibly existing
`UniformSpace` instance on `E`). -/
@[to_additive
"Construct a seminormed group from a seminorm, i.e., registering the pseudodistance
and the pseudometric space structure from the seminorm properties. Note that in most cases this
instance creates bad definitional equalities (e.g., it does not take into account a possibly
existing `UniformSpace` instance on `E`)."]
abbrev GroupSeminorm.toSeminormedCommGroup [CommGroup E] (f : GroupSeminorm E) :
SeminormedCommGroup E :=
{ f.toSeminormedGroup with
mul_comm := mul_comm }
-- See note [reducible non-instances]
/-- Construct a normed group from a norm, i.e., registering the distance and the metric space
structure from the norm properties. Note that in most cases this instance creates bad definitional
equalities (e.g., it does not take into account a possibly existing `UniformSpace` instance on
`E`). -/
@[to_additive
"Construct a normed group from a norm, i.e., registering the distance and the metric
space structure from the norm properties. Note that in most cases this instance creates bad
definitional equalities (e.g., it does not take into account a possibly existing `UniformSpace`
instance on `E`)."]
abbrev GroupNorm.toNormedGroup [Group E] (f : GroupNorm E) : NormedGroup E :=
{ f.toGroupSeminorm.toSeminormedGroup with
eq_of_dist_eq_zero := fun h => div_eq_one.1 <| eq_one_of_map_eq_zero f h }
-- See note [reducible non-instances]
/-- Construct a normed group from a norm, i.e., registering the distance and the metric space
structure from the norm properties. Note that in most cases this instance creates bad definitional
equalities (e.g., it does not take into account a possibly existing `UniformSpace` instance on
`E`). -/
@[to_additive
"Construct a normed group from a norm, i.e., registering the distance and the metric
space structure from the norm properties. Note that in most cases this instance creates bad
definitional equalities (e.g., it does not take into account a possibly existing `UniformSpace`
instance on `E`)."]
abbrev GroupNorm.toNormedCommGroup [CommGroup E] (f : GroupNorm E) : NormedCommGroup E :=
{ f.toNormedGroup with
mul_comm := mul_comm }
section SeminormedGroup
variable [SeminormedGroup E] [SeminormedGroup F] [SeminormedGroup G] {s : Set E}
{a a₁ a₂ b c : E} {r r₁ r₂ : ℝ}
@[to_additive]
theorem dist_eq_norm_div (a b : E) : dist a b = ‖a / b‖ :=
SeminormedGroup.dist_eq _ _
@[to_additive]
theorem dist_eq_norm_div' (a b : E) : dist a b = ‖b / a‖ := by rw [dist_comm, dist_eq_norm_div]
alias dist_eq_norm := dist_eq_norm_sub
alias dist_eq_norm' := dist_eq_norm_sub'
@[to_additive of_forall_le_norm]
lemma DiscreteTopology.of_forall_le_norm' (hpos : 0 < r) (hr : ∀ x : E, x ≠ 1 → r ≤ ‖x‖) :
DiscreteTopology E :=
.of_forall_le_dist hpos fun x y hne ↦ by
simp only [dist_eq_norm_div]
exact hr _ (div_ne_one.2 hne)
@[to_additive (attr := simp)]
theorem dist_one_right (a : E) : dist a 1 = ‖a‖ := by rw [dist_eq_norm_div, div_one]
@[to_additive]
theorem inseparable_one_iff_norm {a : E} : Inseparable a 1 ↔ ‖a‖ = 0 := by
rw [Metric.inseparable_iff, dist_one_right]
@[to_additive]
lemma dist_one_left (a : E) : dist 1 a = ‖a‖ := by rw [dist_comm, dist_one_right]
@[to_additive (attr := simp)]
lemma dist_one : dist (1 : E) = norm := funext dist_one_left
@[to_additive]
theorem norm_div_rev (a b : E) : ‖a / b‖ = ‖b / a‖ := by
simpa only [dist_eq_norm_div] using dist_comm a b
@[to_additive (attr := simp) norm_neg]
theorem norm_inv' (a : E) : ‖a⁻¹‖ = ‖a‖ := by simpa using norm_div_rev 1 a
@[to_additive (attr := simp) norm_abs_zsmul]
theorem norm_zpow_abs (a : E) (n : ℤ) : ‖a ^ |n|‖ = ‖a ^ n‖ := by
rcases le_total 0 n with hn | hn <;> simp [hn, abs_of_nonneg, abs_of_nonpos]
@[to_additive (attr := simp) norm_natAbs_smul]
theorem norm_pow_natAbs (a : E) (n : ℤ) : ‖a ^ n.natAbs‖ = ‖a ^ n‖ := by
rw [← zpow_natCast, ← Int.abs_eq_natAbs, norm_zpow_abs]
@[to_additive norm_isUnit_zsmul]
theorem norm_zpow_isUnit (a : E) {n : ℤ} (hn : IsUnit n) : ‖a ^ n‖ = ‖a‖ := by
rw [← norm_pow_natAbs, Int.isUnit_iff_natAbs_eq.mp hn, pow_one]
@[simp]
theorem norm_units_zsmul {E : Type*} [SeminormedAddGroup E] (n : ℤˣ) (a : E) : ‖n • a‖ = ‖a‖ :=
norm_isUnit_zsmul a n.isUnit
open scoped symmDiff in
@[to_additive]
theorem dist_mulIndicator (s t : Set α) (f : α → E) (x : α) :
dist (s.mulIndicator f x) (t.mulIndicator f x) = ‖(s ∆ t).mulIndicator f x‖ := by
rw [dist_eq_norm_div, Set.apply_mulIndicator_symmDiff norm_inv']
/-- **Triangle inequality** for the norm. -/
@[to_additive norm_add_le "**Triangle inequality** for the norm."]
theorem norm_mul_le' (a b : E) : ‖a * b‖ ≤ ‖a‖ + ‖b‖ := by
simpa [dist_eq_norm_div] using dist_triangle a 1 b⁻¹
/-- **Triangle inequality** for the norm. -/
@[to_additive norm_add_le_of_le "**Triangle inequality** for the norm."]
theorem norm_mul_le_of_le' (h₁ : ‖a₁‖ ≤ r₁) (h₂ : ‖a₂‖ ≤ r₂) : ‖a₁ * a₂‖ ≤ r₁ + r₂ :=
(norm_mul_le' a₁ a₂).trans <| add_le_add h₁ h₂
/-- **Triangle inequality** for the norm. -/
@[to_additive norm_add₃_le "**Triangle inequality** for the norm."]
lemma norm_mul₃_le' : ‖a * b * c‖ ≤ ‖a‖ + ‖b‖ + ‖c‖ := norm_mul_le_of_le' (norm_mul_le' _ _) le_rfl
@[to_additive]
lemma norm_div_le_norm_div_add_norm_div (a b c : E) : ‖a / c‖ ≤ ‖a / b‖ + ‖b / c‖ := by
simpa only [dist_eq_norm_div] using dist_triangle a b c
@[to_additive (attr := simp) norm_nonneg]
theorem norm_nonneg' (a : E) : 0 ≤ ‖a‖ := by
rw [← dist_one_right]
exact dist_nonneg
attribute [bound] norm_nonneg
@[to_additive (attr := simp) abs_norm]
theorem abs_norm' (z : E) : |‖z‖| = ‖z‖ := abs_of_nonneg <| norm_nonneg' _
@[to_additive (attr := simp) norm_zero]
theorem norm_one' : ‖(1 : E)‖ = 0 := by rw [← dist_one_right, dist_self]
@[to_additive]
theorem ne_one_of_norm_ne_zero : ‖a‖ ≠ 0 → a ≠ 1 :=
mt <| by
rintro rfl
exact norm_one'
@[to_additive (attr := nontriviality) norm_of_subsingleton]
theorem norm_of_subsingleton' [Subsingleton E] (a : E) : ‖a‖ = 0 := by
rw [Subsingleton.elim a 1, norm_one']
@[to_additive zero_lt_one_add_norm_sq]
theorem zero_lt_one_add_norm_sq' (x : E) : 0 < 1 + ‖x‖ ^ 2 := by
positivity
@[to_additive]
theorem norm_div_le (a b : E) : ‖a / b‖ ≤ ‖a‖ + ‖b‖ := by
simpa [dist_eq_norm_div] using dist_triangle a 1 b
attribute [bound] norm_sub_le
@[to_additive]
theorem norm_div_le_of_le {r₁ r₂ : ℝ} (H₁ : ‖a₁‖ ≤ r₁) (H₂ : ‖a₂‖ ≤ r₂) : ‖a₁ / a₂‖ ≤ r₁ + r₂ :=
(norm_div_le a₁ a₂).trans <| add_le_add H₁ H₂
@[to_additive dist_le_norm_add_norm]
theorem dist_le_norm_add_norm' (a b : E) : dist a b ≤ ‖a‖ + ‖b‖ := by
rw [dist_eq_norm_div]
apply norm_div_le
@[to_additive abs_norm_sub_norm_le]
theorem abs_norm_sub_norm_le' (a b : E) : |‖a‖ - ‖b‖| ≤ ‖a / b‖ := by
simpa [dist_eq_norm_div] using abs_dist_sub_le a b 1
@[to_additive norm_sub_norm_le]
theorem norm_sub_norm_le' (a b : E) : ‖a‖ - ‖b‖ ≤ ‖a / b‖ :=
(le_abs_self _).trans (abs_norm_sub_norm_le' a b)
@[to_additive (attr := bound)]
theorem norm_sub_le_norm_mul (a b : E) : ‖a‖ - ‖b‖ ≤ ‖a * b‖ := by
simpa using norm_mul_le' (a * b) (b⁻¹)
@[to_additive dist_norm_norm_le]
theorem dist_norm_norm_le' (a b : E) : dist ‖a‖ ‖b‖ ≤ ‖a / b‖ :=
abs_norm_sub_norm_le' a b
@[to_additive]
theorem norm_le_norm_add_norm_div' (u v : E) : ‖u‖ ≤ ‖v‖ + ‖u / v‖ := by
rw [add_comm]
refine (norm_mul_le' _ _).trans_eq' ?_
rw [div_mul_cancel]
@[to_additive]
theorem norm_le_norm_add_norm_div (u v : E) : ‖v‖ ≤ ‖u‖ + ‖u / v‖ := by
rw [norm_div_rev]
exact norm_le_norm_add_norm_div' v u
alias norm_le_insert' := norm_le_norm_add_norm_sub'
alias norm_le_insert := norm_le_norm_add_norm_sub
@[to_additive]
theorem norm_le_mul_norm_add (u v : E) : ‖u‖ ≤ ‖u * v‖ + ‖v‖ :=
calc
‖u‖ = ‖u * v / v‖ := by rw [mul_div_cancel_right]
_ ≤ ‖u * v‖ + ‖v‖ := norm_div_le _ _
/-- An analogue of `norm_le_mul_norm_add` for the multiplication from the left. -/
@[to_additive "An analogue of `norm_le_add_norm_add` for the addition from the left."]
theorem norm_le_mul_norm_add' (u v : E) : ‖v‖ ≤ ‖u * v‖ + ‖u‖ :=
calc
‖v‖ = ‖u⁻¹ * (u * v)‖ := by rw [← mul_assoc, inv_mul_cancel, one_mul]
_ ≤ ‖u⁻¹‖ + ‖u * v‖ := norm_mul_le' u⁻¹ (u * v)
_ = ‖u * v‖ + ‖u‖ := by rw [norm_inv', add_comm]
@[to_additive]
lemma norm_mul_eq_norm_right {x : E} (y : E) (h : ‖x‖ = 0) : ‖x * y‖ = ‖y‖ := by
apply le_antisymm ?_ ?_
· simpa [h] using norm_mul_le' x y
· simpa [h] using norm_le_mul_norm_add' x y
@[to_additive]
lemma norm_mul_eq_norm_left (x : E) {y : E} (h : ‖y‖ = 0) : ‖x * y‖ = ‖x‖ := by
apply le_antisymm ?_ ?_
· simpa [h] using norm_mul_le' x y
· simpa [h] using norm_le_mul_norm_add x y
@[to_additive]
lemma norm_div_eq_norm_right {x : E} (y : E) (h : ‖x‖ = 0) : ‖x / y‖ = ‖y‖ := by
apply le_antisymm ?_ ?_
· simpa [h] using norm_div_le x y
· simpa [h, norm_div_rev x y] using norm_sub_norm_le' y x
@[to_additive]
lemma norm_div_eq_norm_left (x : E) {y : E} (h : ‖y‖ = 0) : ‖x / y‖ = ‖x‖ := by
apply le_antisymm ?_ ?_
· simpa [h] using norm_div_le x y
· simpa [h] using norm_sub_norm_le' x y
@[to_additive ball_eq]
theorem ball_eq' (y : E) (ε : ℝ) : ball y ε = { x | ‖x / y‖ < ε } :=
Set.ext fun a => by simp [dist_eq_norm_div]
@[to_additive]
theorem ball_one_eq (r : ℝ) : ball (1 : E) r = { x | ‖x‖ < r } :=
Set.ext fun a => by simp
@[to_additive mem_ball_iff_norm]
theorem mem_ball_iff_norm'' : b ∈ ball a r ↔ ‖b / a‖ < r := by rw [mem_ball, dist_eq_norm_div]
@[to_additive mem_ball_iff_norm']
theorem mem_ball_iff_norm''' : b ∈ ball a r ↔ ‖a / b‖ < r := by rw [mem_ball', dist_eq_norm_div]
@[to_additive]
theorem mem_ball_one_iff : a ∈ ball (1 : E) r ↔ ‖a‖ < r := by rw [mem_ball, dist_one_right]
@[to_additive mem_closedBall_iff_norm]
theorem mem_closedBall_iff_norm'' : b ∈ closedBall a r ↔ ‖b / a‖ ≤ r := by
rw [mem_closedBall, dist_eq_norm_div]
@[to_additive]
theorem mem_closedBall_one_iff : a ∈ closedBall (1 : E) r ↔ ‖a‖ ≤ r := by
rw [mem_closedBall, dist_one_right]
@[to_additive mem_closedBall_iff_norm']
theorem mem_closedBall_iff_norm''' : b ∈ closedBall a r ↔ ‖a / b‖ ≤ r := by
rw [mem_closedBall', dist_eq_norm_div]
@[to_additive norm_le_of_mem_closedBall]
theorem norm_le_of_mem_closedBall' (h : b ∈ closedBall a r) : ‖b‖ ≤ ‖a‖ + r :=
(norm_le_norm_add_norm_div' _ _).trans <| add_le_add_left (by rwa [← dist_eq_norm_div]) _
@[to_additive norm_le_norm_add_const_of_dist_le]
theorem norm_le_norm_add_const_of_dist_le' : dist a b ≤ r → ‖a‖ ≤ ‖b‖ + r :=
norm_le_of_mem_closedBall'
@[to_additive norm_lt_of_mem_ball]
theorem norm_lt_of_mem_ball' (h : b ∈ ball a r) : ‖b‖ < ‖a‖ + r :=
(norm_le_norm_add_norm_div' _ _).trans_lt <| add_lt_add_left (by rwa [← dist_eq_norm_div]) _
@[to_additive]
theorem norm_div_sub_norm_div_le_norm_div (u v w : E) : ‖u / w‖ - ‖v / w‖ ≤ ‖u / v‖ := by
simpa only [div_div_div_cancel_right] using norm_sub_norm_le' (u / w) (v / w)
@[to_additive (attr := simp 1001) mem_sphere_iff_norm]
-- Porting note: increase priority so the left-hand side doesn't reduce
theorem mem_sphere_iff_norm' : b ∈ sphere a r ↔ ‖b / a‖ = r := by simp [dist_eq_norm_div]
@[to_additive] -- `simp` can prove this
theorem mem_sphere_one_iff_norm : a ∈ sphere (1 : E) r ↔ ‖a‖ = r := by simp [dist_eq_norm_div]
@[to_additive (attr := simp) norm_eq_of_mem_sphere]
theorem norm_eq_of_mem_sphere' (x : sphere (1 : E) r) : ‖(x : E)‖ = r :=
mem_sphere_one_iff_norm.mp x.2
@[to_additive]
theorem ne_one_of_mem_sphere (hr : r ≠ 0) (x : sphere (1 : E) r) : (x : E) ≠ 1 :=
ne_one_of_norm_ne_zero <| by rwa [norm_eq_of_mem_sphere' x]
@[to_additive ne_zero_of_mem_unit_sphere]
theorem ne_one_of_mem_unit_sphere (x : sphere (1 : E) 1) : (x : E) ≠ 1 :=
ne_one_of_mem_sphere one_ne_zero _
variable (E)
/-- The norm of a seminormed group as a group seminorm. -/
@[to_additive "The norm of a seminormed group as an additive group seminorm."]
def normGroupSeminorm : GroupSeminorm E :=
⟨norm, norm_one', norm_mul_le', norm_inv'⟩
@[to_additive (attr := simp)]
theorem coe_normGroupSeminorm : ⇑(normGroupSeminorm E) = norm :=
rfl
variable {E}
@[to_additive]
theorem NormedCommGroup.tendsto_nhds_one {f : α → E} {l : Filter α} :
Tendsto f l (𝓝 1) ↔ ∀ ε > 0, ∀ᶠ x in l, ‖f x‖ < ε :=
Metric.tendsto_nhds.trans <| by simp only [dist_one_right]
@[to_additive]
theorem NormedCommGroup.tendsto_nhds_nhds {f : E → F} {x : E} {y : F} :
Tendsto f (𝓝 x) (𝓝 y) ↔ ∀ ε > 0, ∃ δ > 0, ∀ x', ‖x' / x‖ < δ → ‖f x' / y‖ < ε := by
simp_rw [Metric.tendsto_nhds_nhds, dist_eq_norm_div]
@[to_additive]
theorem NormedCommGroup.nhds_basis_norm_lt (x : E) :
(𝓝 x).HasBasis (fun ε : ℝ => 0 < ε) fun ε => { y | ‖y / x‖ < ε } := by
simp_rw [← ball_eq']
exact Metric.nhds_basis_ball
@[to_additive]
theorem NormedCommGroup.nhds_one_basis_norm_lt :
(𝓝 (1 : E)).HasBasis (fun ε : ℝ => 0 < ε) fun ε => { y | ‖y‖ < ε } := by
convert NormedCommGroup.nhds_basis_norm_lt (1 : E)
simp
@[to_additive]
theorem NormedCommGroup.uniformity_basis_dist :
(𝓤 E).HasBasis (fun ε : ℝ => 0 < ε) fun ε => { p : E × E | ‖p.fst / p.snd‖ < ε } := by
convert Metric.uniformity_basis_dist (α := E) using 1
simp [dist_eq_norm_div]
open Finset
variable [FunLike 𝓕 E F]
section NNNorm
-- See note [lower instance priority]
@[to_additive]
instance (priority := 100) SeminormedGroup.toNNNorm : NNNorm E :=
⟨fun a => ⟨‖a‖, norm_nonneg' a⟩⟩
@[to_additive (attr := simp, norm_cast) coe_nnnorm]
theorem coe_nnnorm' (a : E) : (‖a‖₊ : ℝ) = ‖a‖ := rfl
@[to_additive (attr := simp) coe_comp_nnnorm]
theorem coe_comp_nnnorm' : (toReal : ℝ≥0 → ℝ) ∘ (nnnorm : E → ℝ≥0) = norm :=
rfl
@[to_additive (attr := simp) norm_toNNReal]
theorem norm_toNNReal' : ‖a‖.toNNReal = ‖a‖₊ :=
@Real.toNNReal_coe ‖a‖₊
@[to_additive (attr := simp) toReal_enorm]
lemma toReal_enorm' (x : E) : ‖x‖ₑ.toReal = ‖x‖ := by simp [enorm]
@[to_additive (attr := simp) ofReal_norm]
lemma ofReal_norm' (x : E) : .ofReal ‖x‖ = ‖x‖ₑ := by
simp [enorm, ENNReal.ofReal, Real.toNNReal, nnnorm]
@[to_additive enorm_eq_iff_norm_eq]
theorem enorm'_eq_iff_norm_eq {x : E} {y : F} : ‖x‖ₑ = ‖y‖ₑ ↔ ‖x‖ = ‖y‖ := by
simp only [← ofReal_norm']
refine ⟨fun h ↦ ?_, fun h ↦ by congr⟩
exact (Real.toNNReal_eq_toNNReal_iff (norm_nonneg' _) (norm_nonneg' _)).mp (ENNReal.coe_inj.mp h)
@[to_additive enorm_le_iff_norm_le]
theorem enorm'_le_iff_norm_le {x : E} {y : F} : ‖x‖ₑ ≤ ‖y‖ₑ ↔ ‖x‖ ≤ ‖y‖ := by
simp only [← ofReal_norm']
refine ⟨fun h ↦ ?_, fun h ↦ by gcongr⟩
rw [ENNReal.ofReal_le_ofReal_iff (norm_nonneg' _)] at h
exact h
@[to_additive]
theorem nndist_eq_nnnorm_div (a b : E) : nndist a b = ‖a / b‖₊ :=
NNReal.eq <| dist_eq_norm_div _ _
alias nndist_eq_nnnorm := nndist_eq_nnnorm_sub
@[to_additive (attr := simp)]
theorem nndist_one_right (a : E) : nndist a 1 = ‖a‖₊ := by simp [nndist_eq_nnnorm_div]
@[to_additive (attr := simp)]
lemma edist_one_right (a : E) : edist a 1 = ‖a‖ₑ := by simp [edist_nndist, nndist_one_right, enorm]
@[to_additive (attr := simp) nnnorm_zero]
theorem nnnorm_one' : ‖(1 : E)‖₊ = 0 := NNReal.eq norm_one'
@[to_additive]
theorem ne_one_of_nnnorm_ne_zero {a : E} : ‖a‖₊ ≠ 0 → a ≠ 1 :=
mt <| by
rintro rfl
exact nnnorm_one'
@[to_additive nnnorm_add_le]
theorem nnnorm_mul_le' (a b : E) : ‖a * b‖₊ ≤ ‖a‖₊ + ‖b‖₊ :=
NNReal.coe_le_coe.1 <| norm_mul_le' a b
@[to_additive norm_nsmul_le]
lemma norm_pow_le_mul_norm : ∀ {n : ℕ}, ‖a ^ n‖ ≤ n * ‖a‖
| 0 => by simp
| n + 1 => by simpa [pow_succ, add_mul] using norm_mul_le_of_le' norm_pow_le_mul_norm le_rfl
@[to_additive nnnorm_nsmul_le]
lemma nnnorm_pow_le_mul_norm {n : ℕ} : ‖a ^ n‖₊ ≤ n * ‖a‖₊ := by
simpa only [← NNReal.coe_le_coe, NNReal.coe_mul, NNReal.coe_natCast] using norm_pow_le_mul_norm
@[to_additive (attr := simp) nnnorm_neg]
theorem nnnorm_inv' (a : E) : ‖a⁻¹‖₊ = ‖a‖₊ :=
NNReal.eq <| norm_inv' a
@[to_additive (attr := simp) nnnorm_abs_zsmul]
theorem nnnorm_zpow_abs (a : E) (n : ℤ) : ‖a ^ |n|‖₊ = ‖a ^ n‖₊ :=
NNReal.eq <| norm_zpow_abs a n
@[to_additive (attr := simp) nnnorm_natAbs_smul]
theorem nnnorm_pow_natAbs (a : E) (n : ℤ) : ‖a ^ n.natAbs‖₊ = ‖a ^ n‖₊ :=
NNReal.eq <| norm_pow_natAbs a n
@[to_additive nnnorm_isUnit_zsmul]
theorem nnnorm_zpow_isUnit (a : E) {n : ℤ} (hn : IsUnit n) : ‖a ^ n‖₊ = ‖a‖₊ :=
NNReal.eq <| norm_zpow_isUnit a hn
@[simp]
theorem nnnorm_units_zsmul {E : Type*} [SeminormedAddGroup E] (n : ℤˣ) (a : E) : ‖n • a‖₊ = ‖a‖₊ :=
NNReal.eq <| norm_isUnit_zsmul a n.isUnit
@[to_additive (attr := simp)]
theorem nndist_one_left (a : E) : nndist 1 a = ‖a‖₊ := by simp [nndist_eq_nnnorm_div]
@[to_additive (attr := simp)]
theorem edist_one_left (a : E) : edist 1 a = ‖a‖₊ := by
rw [edist_nndist, nndist_one_left]
open scoped symmDiff in
@[to_additive]
theorem nndist_mulIndicator (s t : Set α) (f : α → E) (x : α) :
nndist (s.mulIndicator f x) (t.mulIndicator f x) = ‖(s ∆ t).mulIndicator f x‖₊ :=
NNReal.eq <| dist_mulIndicator s t f x
@[to_additive]
theorem nnnorm_div_le (a b : E) : ‖a / b‖₊ ≤ ‖a‖₊ + ‖b‖₊ :=
NNReal.coe_le_coe.1 <| norm_div_le _ _
@[to_additive]
lemma enorm_div_le : ‖a / b‖ₑ ≤ ‖a‖ₑ + ‖b‖ₑ := by
simpa [enorm, ← ENNReal.coe_add] using nnnorm_div_le a b
@[to_additive nndist_nnnorm_nnnorm_le]
theorem nndist_nnnorm_nnnorm_le' (a b : E) : nndist ‖a‖₊ ‖b‖₊ ≤ ‖a / b‖₊ :=
NNReal.coe_le_coe.1 <| dist_norm_norm_le' a b
@[to_additive]
theorem nnnorm_le_nnnorm_add_nnnorm_div (a b : E) : ‖b‖₊ ≤ ‖a‖₊ + ‖a / b‖₊ :=
norm_le_norm_add_norm_div _ _
@[to_additive]
theorem nnnorm_le_nnnorm_add_nnnorm_div' (a b : E) : ‖a‖₊ ≤ ‖b‖₊ + ‖a / b‖₊ :=
norm_le_norm_add_norm_div' _ _
alias nnnorm_le_insert' := nnnorm_le_nnnorm_add_nnnorm_sub'
alias nnnorm_le_insert := nnnorm_le_nnnorm_add_nnnorm_sub
@[to_additive]
theorem nnnorm_le_mul_nnnorm_add (a b : E) : ‖a‖₊ ≤ ‖a * b‖₊ + ‖b‖₊ :=
norm_le_mul_norm_add _ _
/-- An analogue of `nnnorm_le_mul_nnnorm_add` for the multiplication from the left. -/
@[to_additive "An analogue of `nnnorm_le_add_nnnorm_add` for the addition from the left."]
theorem nnnorm_le_mul_nnnorm_add' (a b : E) : ‖b‖₊ ≤ ‖a * b‖₊ + ‖a‖₊ :=
norm_le_mul_norm_add' _ _
@[to_additive]
lemma nnnorm_mul_eq_nnnorm_right {x : E} (y : E) (h : ‖x‖₊ = 0) : ‖x * y‖₊ = ‖y‖₊ :=
NNReal.eq <| norm_mul_eq_norm_right _ <| congr_arg NNReal.toReal h
@[to_additive]
lemma nnnorm_mul_eq_nnnorm_left (x : E) {y : E} (h : ‖y‖₊ = 0) : ‖x * y‖₊ = ‖x‖₊ :=
NNReal.eq <| norm_mul_eq_norm_left _ <| congr_arg NNReal.toReal h
@[to_additive]
lemma nnnorm_div_eq_nnnorm_right {x : E} (y : E) (h : ‖x‖₊ = 0) : ‖x / y‖₊ = ‖y‖₊ :=
NNReal.eq <| norm_div_eq_norm_right _ <| congr_arg NNReal.toReal h
@[to_additive]
lemma nnnorm_div_eq_nnnorm_left (x : E) {y : E} (h : ‖y‖₊ = 0) : ‖x / y‖₊ = ‖x‖₊ :=
NNReal.eq <| norm_div_eq_norm_left _ <| congr_arg NNReal.toReal h
/-- The non negative norm seen as an `ENNReal` and then as a `Real` is equal to the norm. -/
@[to_additive toReal_coe_nnnorm "The non negative norm seen as an `ENNReal` and
then as a `Real` is equal to the norm."]
theorem toReal_coe_nnnorm' (a : E) : (‖a‖₊ : ℝ≥0∞).toReal = ‖a‖ := rfl
open scoped symmDiff in
@[to_additive]
theorem edist_mulIndicator (s t : Set α) (f : α → E) (x : α) :
edist (s.mulIndicator f x) (t.mulIndicator f x) = ‖(s ∆ t).mulIndicator f x‖₊ := by
rw [edist_nndist, nndist_mulIndicator]
end NNNorm
section ENorm
@[to_additive (attr := simp) enorm_zero]
lemma enorm_one' {E : Type*} [TopologicalSpace E] [ENormedMonoid E] : ‖(1 : E)‖ₑ = 0 := by
rw [ENormedMonoid.enorm_eq_zero]
@[to_additive exists_enorm_lt]
lemma exists_enorm_lt' (E : Type*) [TopologicalSpace E] [ENormedMonoid E]
[hbot : NeBot (𝓝[≠] (1 : E))] {c : ℝ≥0∞} (hc : c ≠ 0) : ∃ x ≠ (1 : E), ‖x‖ₑ < c :=
frequently_iff_neBot.mpr hbot |>.and_eventually
(ContinuousENorm.continuous_enorm.tendsto' 1 0 (by simp) |>.eventually_lt_const hc.bot_lt)
|>.exists
@[to_additive (attr := simp) enorm_neg]
lemma enorm_inv' (a : E) : ‖a⁻¹‖ₑ = ‖a‖ₑ := by simp [enorm]
@[to_additive ofReal_norm_eq_enorm]
lemma ofReal_norm_eq_enorm' (a : E) : .ofReal ‖a‖ = ‖a‖ₑ := ENNReal.ofReal_eq_coe_nnreal _
@[deprecated (since := "2025-01-17")] alias ofReal_norm_eq_coe_nnnorm := ofReal_norm_eq_enorm
@[deprecated (since := "2025-01-17")] alias ofReal_norm_eq_coe_nnnorm' := ofReal_norm_eq_enorm'
| instance : ENorm ℝ≥0∞ where
enorm x := x
| Mathlib/Analysis/Normed/Group/Basic.lean | 871 | 872 |
/-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Johannes Hölzl, Kim Morrison, Jens Wagemaker
-/
import Mathlib.Algebra.Group.Submonoid.Operations
import Mathlib.Algebra.MonoidAlgebra.Defs
import Mathlib.Algebra.Order.Monoid.Unbundled.WithTop
import Mathlib.Algebra.Ring.Action.Rat
import Mathlib.Data.Finset.Sort
import Mathlib.Tactic.FastInstance
/-!
# Theory of univariate polynomials
This file defines `Polynomial R`, the type of univariate polynomials over the semiring `R`, builds
a semiring structure on it, and gives basic definitions that are expanded in other files in this
directory.
## Main definitions
* `monomial n a` is the polynomial `a X^n`. Note that `monomial n` is defined as an `R`-linear map.
* `C a` is the constant polynomial `a`. Note that `C` is defined as a ring homomorphism.
* `X` is the polynomial `X`, i.e., `monomial 1 1`.
* `p.sum f` is `∑ n ∈ p.support, f n (p.coeff n)`, i.e., one sums the values of functions applied
to coefficients of the polynomial `p`.
* `p.erase n` is the polynomial `p` in which one removes the `c X^n` term.
There are often two natural variants of lemmas involving sums, depending on whether one acts on the
polynomials, or on the function. The naming convention is that one adds `index` when acting on
the polynomials. For instance,
* `sum_add_index` states that `(p + q).sum f = p.sum f + q.sum f`;
* `sum_add` states that `p.sum (fun n x ↦ f n x + g n x) = p.sum f + p.sum g`.
* Notation to refer to `Polynomial R`, as `R[X]` or `R[t]`.
## Implementation
Polynomials are defined using `R[ℕ]`, where `R` is a semiring.
The variable `X` commutes with every polynomial `p`: lemma `X_mul` proves the identity
`X * p = p * X`. The relationship to `R[ℕ]` is through a structure
to make polynomials irreducible from the point of view of the kernel. Most operations
are irreducible since Lean can not compute anyway with `AddMonoidAlgebra`. There are two
exceptions that we make semireducible:
* The zero polynomial, so that its coefficients are definitionally equal to `0`.
* The scalar action, to permit typeclass search to unfold it to resolve potential instance
diamonds.
The raw implementation of the equivalence between `R[X]` and `R[ℕ]` is
done through `ofFinsupp` and `toFinsupp` (or, equivalently, `rcases p` when `p` is a polynomial
gives an element `q` of `R[ℕ]`, and conversely `⟨q⟩` gives back `p`). The
equivalence is also registered as a ring equiv in `Polynomial.toFinsuppIso`. These should
in general not be used once the basic API for polynomials is constructed.
-/
noncomputable section
/-- `Polynomial R` is the type of univariate polynomials over `R`,
denoted as `R[X]` within the `Polynomial` namespace.
Polynomials should be seen as (semi-)rings with the additional constructor `X`.
The embedding from `R` is called `C`. -/
structure Polynomial (R : Type*) [Semiring R] where ofFinsupp ::
toFinsupp : AddMonoidAlgebra R ℕ
@[inherit_doc] scoped[Polynomial] notation:9000 R "[X]" => Polynomial R
open AddMonoidAlgebra Finset
open Finsupp hiding single
open Function hiding Commute
namespace Polynomial
universe u
variable {R : Type u} {a b : R} {m n : ℕ}
section Semiring
variable [Semiring R] {p q : R[X]}
theorem forall_iff_forall_finsupp (P : R[X] → Prop) :
(∀ p, P p) ↔ ∀ q : R[ℕ], P ⟨q⟩ :=
⟨fun h q => h ⟨q⟩, fun h ⟨p⟩ => h p⟩
theorem exists_iff_exists_finsupp (P : R[X] → Prop) :
(∃ p, P p) ↔ ∃ q : R[ℕ], P ⟨q⟩ :=
⟨fun ⟨⟨p⟩, hp⟩ => ⟨p, hp⟩, fun ⟨q, hq⟩ => ⟨⟨q⟩, hq⟩⟩
@[simp]
theorem eta (f : R[X]) : Polynomial.ofFinsupp f.toFinsupp = f := by cases f; rfl
/-! ### Conversions to and from `AddMonoidAlgebra`
Since `R[X]` is not defeq to `R[ℕ]`, but instead is a structure wrapping
it, we have to copy across all the arithmetic operators manually, along with the lemmas about how
they unfold around `Polynomial.ofFinsupp` and `Polynomial.toFinsupp`.
-/
section AddMonoidAlgebra
private irreducible_def add : R[X] → R[X] → R[X]
| ⟨a⟩, ⟨b⟩ => ⟨a + b⟩
private irreducible_def neg {R : Type u} [Ring R] : R[X] → R[X]
| ⟨a⟩ => ⟨-a⟩
private irreducible_def mul : R[X] → R[X] → R[X]
| ⟨a⟩, ⟨b⟩ => ⟨a * b⟩
instance zero : Zero R[X] :=
⟨⟨0⟩⟩
instance one : One R[X] :=
⟨⟨1⟩⟩
instance add' : Add R[X] :=
⟨add⟩
instance neg' {R : Type u} [Ring R] : Neg R[X] :=
⟨neg⟩
instance sub {R : Type u} [Ring R] : Sub R[X] :=
⟨fun a b => a + -b⟩
instance mul' : Mul R[X] :=
⟨mul⟩
-- If the private definitions are accidentally exposed, simplify them away.
@[simp] theorem add_eq_add : add p q = p + q := rfl
@[simp] theorem mul_eq_mul : mul p q = p * q := rfl
instance instNSMul : SMul ℕ R[X] where
smul r p := ⟨r • p.toFinsupp⟩
instance smulZeroClass {S : Type*} [SMulZeroClass S R] : SMulZeroClass S R[X] where
smul r p := ⟨r • p.toFinsupp⟩
smul_zero a := congr_arg ofFinsupp (smul_zero a)
instance {S : Type*} [Zero S] [SMulZeroClass S R] [NoZeroSMulDivisors S R] :
NoZeroSMulDivisors S R[X] where
eq_zero_or_eq_zero_of_smul_eq_zero eq :=
(eq_zero_or_eq_zero_of_smul_eq_zero <| congr_arg toFinsupp eq).imp id (congr_arg ofFinsupp)
-- to avoid a bug in the `ring` tactic
instance (priority := 1) pow : Pow R[X] ℕ where pow p n := npowRec n p
@[simp]
theorem ofFinsupp_zero : (⟨0⟩ : R[X]) = 0 :=
rfl
@[simp]
theorem ofFinsupp_one : (⟨1⟩ : R[X]) = 1 :=
rfl
@[simp]
theorem ofFinsupp_add {a b} : (⟨a + b⟩ : R[X]) = ⟨a⟩ + ⟨b⟩ :=
show _ = add _ _ by rw [add_def]
@[simp]
theorem ofFinsupp_neg {R : Type u} [Ring R] {a} : (⟨-a⟩ : R[X]) = -⟨a⟩ :=
show _ = neg _ by rw [neg_def]
@[simp]
theorem ofFinsupp_sub {R : Type u} [Ring R] {a b} : (⟨a - b⟩ : R[X]) = ⟨a⟩ - ⟨b⟩ := by
rw [sub_eq_add_neg, ofFinsupp_add, ofFinsupp_neg]
rfl
@[simp]
theorem ofFinsupp_mul (a b) : (⟨a * b⟩ : R[X]) = ⟨a⟩ * ⟨b⟩ :=
show _ = mul _ _ by rw [mul_def]
@[simp]
theorem ofFinsupp_nsmul (a : ℕ) (b) :
(⟨a • b⟩ : R[X]) = (a • ⟨b⟩ : R[X]) :=
rfl
@[simp]
theorem ofFinsupp_smul {S : Type*} [SMulZeroClass S R] (a : S) (b) :
(⟨a • b⟩ : R[X]) = (a • ⟨b⟩ : R[X]) :=
rfl
@[simp]
theorem ofFinsupp_pow (a) (n : ℕ) : (⟨a ^ n⟩ : R[X]) = ⟨a⟩ ^ n := by
change _ = npowRec n _
induction n with
| zero => simp [npowRec]
| succ n n_ih => simp [npowRec, n_ih, pow_succ]
@[simp]
theorem toFinsupp_zero : (0 : R[X]).toFinsupp = 0 :=
rfl
@[simp]
theorem toFinsupp_one : (1 : R[X]).toFinsupp = 1 :=
rfl
@[simp]
theorem toFinsupp_add (a b : R[X]) : (a + b).toFinsupp = a.toFinsupp + b.toFinsupp := by
cases a
cases b
rw [← ofFinsupp_add]
@[simp]
theorem toFinsupp_neg {R : Type u} [Ring R] (a : R[X]) : (-a).toFinsupp = -a.toFinsupp := by
cases a
rw [← ofFinsupp_neg]
@[simp]
theorem toFinsupp_sub {R : Type u} [Ring R] (a b : R[X]) :
(a - b).toFinsupp = a.toFinsupp - b.toFinsupp := by
rw [sub_eq_add_neg, ← toFinsupp_neg, ← toFinsupp_add]
rfl
@[simp]
theorem toFinsupp_mul (a b : R[X]) : (a * b).toFinsupp = a.toFinsupp * b.toFinsupp := by
cases a
cases b
rw [← ofFinsupp_mul]
@[simp]
theorem toFinsupp_nsmul (a : ℕ) (b : R[X]) :
(a • b).toFinsupp = a • b.toFinsupp :=
rfl
@[simp]
theorem toFinsupp_smul {S : Type*} [SMulZeroClass S R] (a : S) (b : R[X]) :
(a • b).toFinsupp = a • b.toFinsupp :=
rfl
@[simp]
theorem toFinsupp_pow (a : R[X]) (n : ℕ) : (a ^ n).toFinsupp = a.toFinsupp ^ n := by
cases a
rw [← ofFinsupp_pow]
theorem _root_.IsSMulRegular.polynomial {S : Type*} [SMulZeroClass S R] {a : S}
(ha : IsSMulRegular R a) : IsSMulRegular R[X] a
| ⟨_x⟩, ⟨_y⟩, h => congr_arg _ <| ha.finsupp (Polynomial.ofFinsupp.inj h)
theorem toFinsupp_injective : Function.Injective (toFinsupp : R[X] → AddMonoidAlgebra _ _) :=
fun ⟨_x⟩ ⟨_y⟩ => congr_arg _
@[simp]
theorem toFinsupp_inj {a b : R[X]} : a.toFinsupp = b.toFinsupp ↔ a = b :=
toFinsupp_injective.eq_iff
@[simp]
theorem toFinsupp_eq_zero {a : R[X]} : a.toFinsupp = 0 ↔ a = 0 := by
rw [← toFinsupp_zero, toFinsupp_inj]
@[simp]
theorem toFinsupp_eq_one {a : R[X]} : a.toFinsupp = 1 ↔ a = 1 := by
rw [← toFinsupp_one, toFinsupp_inj]
/-- A more convenient spelling of `Polynomial.ofFinsupp.injEq` in terms of `Iff`. -/
theorem ofFinsupp_inj {a b} : (⟨a⟩ : R[X]) = ⟨b⟩ ↔ a = b :=
iff_of_eq (ofFinsupp.injEq _ _)
@[simp]
theorem ofFinsupp_eq_zero {a} : (⟨a⟩ : R[X]) = 0 ↔ a = 0 := by
rw [← ofFinsupp_zero, ofFinsupp_inj]
@[simp]
theorem ofFinsupp_eq_one {a} : (⟨a⟩ : R[X]) = 1 ↔ a = 1 := by rw [← ofFinsupp_one, ofFinsupp_inj]
instance inhabited : Inhabited R[X] :=
⟨0⟩
instance instNatCast : NatCast R[X] where natCast n := ofFinsupp n
@[simp]
theorem ofFinsupp_natCast (n : ℕ) : (⟨n⟩ : R[X]) = n := rfl
@[simp]
theorem toFinsupp_natCast (n : ℕ) : (n : R[X]).toFinsupp = n := rfl
@[simp]
theorem ofFinsupp_ofNat (n : ℕ) [n.AtLeastTwo] : (⟨ofNat(n)⟩ : R[X]) = ofNat(n) := rfl
@[simp]
theorem toFinsupp_ofNat (n : ℕ) [n.AtLeastTwo] : (ofNat(n) : R[X]).toFinsupp = ofNat(n) := rfl
instance semiring : Semiring R[X] :=
fast_instance% Function.Injective.semiring toFinsupp toFinsupp_injective toFinsupp_zero
toFinsupp_one toFinsupp_add toFinsupp_mul (fun _ _ => toFinsupp_nsmul _ _) toFinsupp_pow
fun _ => rfl
instance distribSMul {S} [DistribSMul S R] : DistribSMul S R[X] :=
fast_instance% Function.Injective.distribSMul ⟨⟨toFinsupp, toFinsupp_zero⟩, toFinsupp_add⟩
toFinsupp_injective toFinsupp_smul
instance distribMulAction {S} [Monoid S] [DistribMulAction S R] : DistribMulAction S R[X] :=
fast_instance% Function.Injective.distribMulAction
⟨⟨toFinsupp, toFinsupp_zero (R := R)⟩, toFinsupp_add⟩ toFinsupp_injective toFinsupp_smul
instance faithfulSMul {S} [SMulZeroClass S R] [FaithfulSMul S R] : FaithfulSMul S R[X] where
eq_of_smul_eq_smul {_s₁ _s₂} h :=
eq_of_smul_eq_smul fun a : ℕ →₀ R => congr_arg toFinsupp (h ⟨a⟩)
instance module {S} [Semiring S] [Module S R] : Module S R[X] :=
fast_instance% Function.Injective.module _ ⟨⟨toFinsupp, toFinsupp_zero⟩, toFinsupp_add⟩
toFinsupp_injective toFinsupp_smul
instance smulCommClass {S₁ S₂} [SMulZeroClass S₁ R] [SMulZeroClass S₂ R] [SMulCommClass S₁ S₂ R] :
SMulCommClass S₁ S₂ R[X] :=
⟨by
rintro m n ⟨f⟩
simp_rw [← ofFinsupp_smul, smul_comm m n f]⟩
instance isScalarTower {S₁ S₂} [SMul S₁ S₂] [SMulZeroClass S₁ R] [SMulZeroClass S₂ R]
[IsScalarTower S₁ S₂ R] : IsScalarTower S₁ S₂ R[X] :=
⟨by
rintro _ _ ⟨⟩
simp_rw [← ofFinsupp_smul, smul_assoc]⟩
instance isScalarTower_right {α K : Type*} [Semiring K] [DistribSMul α K] [IsScalarTower α K K] :
IsScalarTower α K[X] K[X] :=
⟨by
rintro _ ⟨⟩ ⟨⟩
simp_rw [smul_eq_mul, ← ofFinsupp_smul, ← ofFinsupp_mul, ← ofFinsupp_smul, smul_mul_assoc]⟩
instance isCentralScalar {S} [SMulZeroClass S R] [SMulZeroClass Sᵐᵒᵖ R] [IsCentralScalar S R] :
IsCentralScalar S R[X] :=
⟨by
rintro _ ⟨⟩
simp_rw [← ofFinsupp_smul, op_smul_eq_smul]⟩
instance unique [Subsingleton R] : Unique R[X] :=
{ Polynomial.inhabited with
uniq := by
rintro ⟨x⟩
apply congr_arg ofFinsupp
simp [eq_iff_true_of_subsingleton] }
variable (R)
/-- Ring isomorphism between `R[X]` and `R[ℕ]`. This is just an
implementation detail, but it can be useful to transfer results from `Finsupp` to polynomials. -/
@[simps apply symm_apply]
def toFinsuppIso : R[X] ≃+* R[ℕ] where
toFun := toFinsupp
invFun := ofFinsupp
left_inv := fun ⟨_p⟩ => rfl
right_inv _p := rfl
map_mul' := toFinsupp_mul
map_add' := toFinsupp_add
instance [DecidableEq R] : DecidableEq R[X] :=
@Equiv.decidableEq R[X] _ (toFinsuppIso R).toEquiv (Finsupp.instDecidableEq)
/-- Linear isomorphism between `R[X]` and `R[ℕ]`. This is just an
implementation detail, but it can be useful to transfer results from `Finsupp` to polynomials. -/
@[simps!]
def toFinsuppIsoLinear : R[X] ≃ₗ[R] R[ℕ] where
__ := toFinsuppIso R
map_smul' _ _ := rfl
end AddMonoidAlgebra
theorem ofFinsupp_sum {ι : Type*} (s : Finset ι) (f : ι → R[ℕ]) :
(⟨∑ i ∈ s, f i⟩ : R[X]) = ∑ i ∈ s, ⟨f i⟩ :=
map_sum (toFinsuppIso R).symm f s
theorem toFinsupp_sum {ι : Type*} (s : Finset ι) (f : ι → R[X]) :
(∑ i ∈ s, f i : R[X]).toFinsupp = ∑ i ∈ s, (f i).toFinsupp :=
map_sum (toFinsuppIso R) f s
/-- The set of all `n` such that `X^n` has a non-zero coefficient. -/
def support : R[X] → Finset ℕ
| ⟨p⟩ => p.support
@[simp]
theorem support_ofFinsupp (p) : support (⟨p⟩ : R[X]) = p.support := by rw [support]
theorem support_toFinsupp (p : R[X]) : p.toFinsupp.support = p.support := by rw [support]
@[simp]
theorem support_zero : (0 : R[X]).support = ∅ :=
rfl
@[simp]
theorem support_eq_empty : p.support = ∅ ↔ p = 0 := by
rcases p with ⟨⟩
simp [support]
@[simp] lemma support_nonempty : p.support.Nonempty ↔ p ≠ 0 :=
Finset.nonempty_iff_ne_empty.trans support_eq_empty.not
theorem card_support_eq_zero : #p.support = 0 ↔ p = 0 := by simp
/-- `monomial s a` is the monomial `a * X^s` -/
def monomial (n : ℕ) : R →ₗ[R] R[X] where
toFun t := ⟨Finsupp.single n t⟩
-- Porting note (https://github.com/leanprover-community/mathlib4/issues/10745): was `simp`.
map_add' x y := by simp; rw [ofFinsupp_add]
-- Porting note (https://github.com/leanprover-community/mathlib4/issues/10745): was `simp [← ofFinsupp_smul]`.
map_smul' r x := by simp; rw [← ofFinsupp_smul, smul_single']
@[simp]
theorem toFinsupp_monomial (n : ℕ) (r : R) : (monomial n r).toFinsupp = Finsupp.single n r := by
simp [monomial]
@[simp]
theorem ofFinsupp_single (n : ℕ) (r : R) : (⟨Finsupp.single n r⟩ : R[X]) = monomial n r := by
simp [monomial]
@[simp]
theorem monomial_zero_right (n : ℕ) : monomial n (0 : R) = 0 :=
(monomial n).map_zero
-- This is not a `simp` lemma as `monomial_zero_left` is more general.
theorem monomial_zero_one : monomial 0 (1 : R) = 1 :=
rfl
-- TODO: can't we just delete this one?
theorem monomial_add (n : ℕ) (r s : R) : monomial n (r + s) = monomial n r + monomial n s :=
(monomial n).map_add _ _
theorem monomial_mul_monomial (n m : ℕ) (r s : R) :
monomial n r * monomial m s = monomial (n + m) (r * s) :=
toFinsupp_injective <| by
simp only [toFinsupp_monomial, toFinsupp_mul, AddMonoidAlgebra.single_mul_single]
@[simp]
theorem monomial_pow (n : ℕ) (r : R) (k : ℕ) : monomial n r ^ k = monomial (n * k) (r ^ k) := by
induction k with
| zero => simp [pow_zero, monomial_zero_one]
| succ k ih => simp [pow_succ, ih, monomial_mul_monomial, mul_add, add_comm]
theorem smul_monomial {S} [SMulZeroClass S R] (a : S) (n : ℕ) (b : R) :
a • monomial n b = monomial n (a • b) :=
toFinsupp_injective <| AddMonoidAlgebra.smul_single _ _ _
theorem monomial_injective (n : ℕ) : Function.Injective (monomial n : R → R[X]) :=
(toFinsuppIso R).symm.injective.comp (single_injective n)
@[simp]
theorem monomial_eq_zero_iff (t : R) (n : ℕ) : monomial n t = 0 ↔ t = 0 :=
LinearMap.map_eq_zero_iff _ (Polynomial.monomial_injective n)
theorem monomial_eq_monomial_iff {m n : ℕ} {a b : R} :
monomial m a = monomial n b ↔ m = n ∧ a = b ∨ a = 0 ∧ b = 0 := by
rw [← toFinsupp_inj, toFinsupp_monomial, toFinsupp_monomial, Finsupp.single_eq_single_iff]
theorem support_add : (p + q).support ⊆ p.support ∪ q.support := by
simpa [support] using Finsupp.support_add
/-- `C a` is the constant polynomial `a`.
`C` is provided as a ring homomorphism.
-/
def C : R →+* R[X] :=
{ monomial 0 with
map_one' := by simp [monomial_zero_one]
map_mul' := by simp [monomial_mul_monomial]
map_zero' := by simp }
@[simp]
theorem monomial_zero_left (a : R) : monomial 0 a = C a :=
rfl
@[simp]
theorem toFinsupp_C (a : R) : (C a).toFinsupp = single 0 a :=
rfl
theorem C_0 : C (0 : R) = 0 := by simp
theorem C_1 : C (1 : R) = 1 :=
rfl
theorem C_mul : C (a * b) = C a * C b :=
C.map_mul a b
theorem C_add : C (a + b) = C a + C b :=
C.map_add a b
@[simp]
theorem smul_C {S} [SMulZeroClass S R] (s : S) (r : R) : s • C r = C (s • r) :=
smul_monomial _ _ r
theorem C_pow : C (a ^ n) = C a ^ n :=
C.map_pow a n
theorem C_eq_natCast (n : ℕ) : C (n : R) = (n : R[X]) :=
map_natCast C n
@[simp]
theorem C_mul_monomial : C a * monomial n b = monomial n (a * b) := by
simp only [← monomial_zero_left, monomial_mul_monomial, zero_add]
@[simp]
theorem monomial_mul_C : monomial n a * C b = monomial n (a * b) := by
simp only [← monomial_zero_left, monomial_mul_monomial, add_zero]
/-- `X` is the polynomial variable (aka indeterminate). -/
def X : R[X] :=
monomial 1 1
theorem monomial_one_one_eq_X : monomial 1 (1 : R) = X :=
rfl
theorem monomial_one_right_eq_X_pow (n : ℕ) : monomial n (1 : R) = X ^ n := by
induction n with
| zero => simp [monomial_zero_one]
| succ n ih => rw [pow_succ, ← ih, ← monomial_one_one_eq_X, monomial_mul_monomial, mul_one]
@[simp]
theorem toFinsupp_X : X.toFinsupp = Finsupp.single 1 (1 : R) :=
rfl
theorem X_ne_C [Nontrivial R] (a : R) : X ≠ C a := by
intro he
simpa using monomial_eq_monomial_iff.1 he
/-- `X` commutes with everything, even when the coefficients are noncommutative. -/
theorem X_mul : X * p = p * X := by
rcases p with ⟨⟩
simp only [X, ← ofFinsupp_single, ← ofFinsupp_mul, LinearMap.coe_mk, ofFinsupp.injEq]
ext
simp [AddMonoidAlgebra.mul_apply, AddMonoidAlgebra.sum_single_index, add_comm]
theorem X_pow_mul {n : ℕ} : X ^ n * p = p * X ^ n := by
induction n with
| zero => simp
| succ n ih =>
conv_lhs => rw [pow_succ]
rw [mul_assoc, X_mul, ← mul_assoc, ih, mul_assoc, ← pow_succ]
/-- Prefer putting constants to the left of `X`.
This lemma is the loop-avoiding `simp` version of `Polynomial.X_mul`. -/
@[simp]
theorem X_mul_C (r : R) : X * C r = C r * X :=
X_mul
/-- Prefer putting constants to the left of `X ^ n`.
This lemma is the loop-avoiding `simp` version of `X_pow_mul`. -/
@[simp]
theorem X_pow_mul_C (r : R) (n : ℕ) : X ^ n * C r = C r * X ^ n :=
X_pow_mul
theorem X_pow_mul_assoc {n : ℕ} : p * X ^ n * q = p * q * X ^ n := by
rw [mul_assoc, X_pow_mul, ← mul_assoc]
/-- Prefer putting constants to the left of `X ^ n`.
This lemma is the loop-avoiding `simp` version of `X_pow_mul_assoc`. -/
@[simp]
theorem X_pow_mul_assoc_C {n : ℕ} (r : R) : p * X ^ n * C r = p * C r * X ^ n :=
X_pow_mul_assoc
theorem commute_X (p : R[X]) : Commute X p :=
X_mul
theorem commute_X_pow (p : R[X]) (n : ℕ) : Commute (X ^ n) p :=
X_pow_mul
@[simp]
theorem monomial_mul_X (n : ℕ) (r : R) : monomial n r * X = monomial (n + 1) r := by
rw [X, monomial_mul_monomial, mul_one]
@[simp]
theorem monomial_mul_X_pow (n : ℕ) (r : R) (k : ℕ) :
monomial n r * X ^ k = monomial (n + k) r := by
induction k with
| zero => simp
| succ k ih => simp [ih, pow_succ, ← mul_assoc, add_assoc]
@[simp]
theorem X_mul_monomial (n : ℕ) (r : R) : X * monomial n r = monomial (n + 1) r := by
rw [X_mul, monomial_mul_X]
@[simp]
theorem X_pow_mul_monomial (k n : ℕ) (r : R) : X ^ k * monomial n r = monomial (n + k) r := by
rw [X_pow_mul, monomial_mul_X_pow]
/-- `coeff p n` (often denoted `p.coeff n`) is the coefficient of `X^n` in `p`. -/
def coeff : R[X] → ℕ → R
| ⟨p⟩ => p
@[simp]
theorem coeff_ofFinsupp (p) : coeff (⟨p⟩ : R[X]) = p := by rw [coeff]
theorem coeff_injective : Injective (coeff : R[X] → ℕ → R) := by
rintro ⟨p⟩ ⟨q⟩
simp only [coeff, DFunLike.coe_fn_eq, imp_self, ofFinsupp.injEq]
@[simp]
theorem coeff_inj : p.coeff = q.coeff ↔ p = q :=
coeff_injective.eq_iff
theorem toFinsupp_apply (f : R[X]) (i) : f.toFinsupp i = f.coeff i := by cases f; rfl
theorem coeff_monomial : coeff (monomial n a) m = if n = m then a else 0 := by
simp [coeff, Finsupp.single_apply]
@[simp]
theorem coeff_monomial_same (n : ℕ) (c : R) : (monomial n c).coeff n = c :=
Finsupp.single_eq_same
theorem coeff_monomial_of_ne {m n : ℕ} (c : R) (h : n ≠ m) : (monomial n c).coeff m = 0 :=
Finsupp.single_eq_of_ne h
@[simp]
theorem coeff_zero (n : ℕ) : coeff (0 : R[X]) n = 0 :=
rfl
theorem coeff_one {n : ℕ} : coeff (1 : R[X]) n = if n = 0 then 1 else 0 := by
simp_rw [eq_comm (a := n) (b := 0)]
exact coeff_monomial
@[simp]
theorem coeff_one_zero : coeff (1 : R[X]) 0 = 1 := by
simp [coeff_one]
@[simp]
theorem coeff_X_one : coeff (X : R[X]) 1 = 1 :=
coeff_monomial
@[simp]
theorem coeff_X_zero : coeff (X : R[X]) 0 = 0 :=
coeff_monomial
@[simp]
theorem coeff_monomial_succ : coeff (monomial (n + 1) a) 0 = 0 := by simp [coeff_monomial]
theorem coeff_X : coeff (X : R[X]) n = if 1 = n then 1 else 0 :=
coeff_monomial
theorem coeff_X_of_ne_one {n : ℕ} (hn : n ≠ 1) : coeff (X : R[X]) n = 0 := by
rw [coeff_X, if_neg hn.symm]
@[simp]
theorem mem_support_iff : n ∈ p.support ↔ p.coeff n ≠ 0 := by
rcases p with ⟨⟩
simp
theorem not_mem_support_iff : n ∉ p.support ↔ p.coeff n = 0 := by simp
theorem coeff_C : coeff (C a) n = ite (n = 0) a 0 := by
convert coeff_monomial (a := a) (m := n) (n := 0) using 2
simp [eq_comm]
@[simp]
theorem coeff_C_zero : coeff (C a) 0 = a :=
coeff_monomial
theorem coeff_C_ne_zero (h : n ≠ 0) : (C a).coeff n = 0 := by rw [coeff_C, if_neg h]
@[simp]
lemma coeff_C_succ {r : R} {n : ℕ} : coeff (C r) (n + 1) = 0 := by simp [coeff_C]
@[simp]
theorem coeff_natCast_ite : (Nat.cast m : R[X]).coeff n = ite (n = 0) m 0 := by
simp only [← C_eq_natCast, coeff_C, Nat.cast_ite, Nat.cast_zero]
@[simp]
theorem coeff_ofNat_zero (a : ℕ) [a.AtLeastTwo] :
coeff (ofNat(a) : R[X]) 0 = ofNat(a) :=
coeff_monomial
@[simp]
theorem coeff_ofNat_succ (a n : ℕ) [h : a.AtLeastTwo] :
coeff (ofNat(a) : R[X]) (n + 1) = 0 := by
rw [← Nat.cast_ofNat]
simp [-Nat.cast_ofNat]
theorem C_mul_X_pow_eq_monomial : ∀ {n : ℕ}, C a * X ^ n = monomial n a
| 0 => mul_one _
| n + 1 => by
rw [pow_succ, ← mul_assoc, C_mul_X_pow_eq_monomial, X, monomial_mul_monomial, mul_one]
@[simp high]
theorem toFinsupp_C_mul_X_pow (a : R) (n : ℕ) :
Polynomial.toFinsupp (C a * X ^ n) = Finsupp.single n a := by
rw [C_mul_X_pow_eq_monomial, toFinsupp_monomial]
theorem C_mul_X_eq_monomial : C a * X = monomial 1 a := by rw [← C_mul_X_pow_eq_monomial, pow_one]
@[simp high]
theorem toFinsupp_C_mul_X (a : R) : Polynomial.toFinsupp (C a * X) = Finsupp.single 1 a := by
rw [C_mul_X_eq_monomial, toFinsupp_monomial]
theorem C_injective : Injective (C : R → R[X]) :=
monomial_injective 0
@[simp]
theorem C_inj : C a = C b ↔ a = b :=
C_injective.eq_iff
@[simp]
theorem C_eq_zero : C a = 0 ↔ a = 0 :=
C_injective.eq_iff' (map_zero C)
theorem C_ne_zero : C a ≠ 0 ↔ a ≠ 0 :=
C_eq_zero.not
theorem subsingleton_iff_subsingleton : Subsingleton R[X] ↔ Subsingleton R :=
⟨@Injective.subsingleton _ _ _ C_injective, by
intro
infer_instance⟩
theorem Nontrivial.of_polynomial_ne (h : p ≠ q) : Nontrivial R :=
(subsingleton_or_nontrivial R).resolve_left fun _hI => h <| Subsingleton.elim _ _
theorem forall_eq_iff_forall_eq : (∀ f g : R[X], f = g) ↔ ∀ a b : R, a = b := by
simpa only [← subsingleton_iff] using subsingleton_iff_subsingleton
theorem ext_iff {p q : R[X]} : p = q ↔ ∀ n, coeff p n = coeff q n := by
rcases p with ⟨f : ℕ →₀ R⟩
rcases q with ⟨g : ℕ →₀ R⟩
simpa [coeff] using DFunLike.ext_iff (f := f) (g := g)
@[ext]
theorem ext {p q : R[X]} : (∀ n, coeff p n = coeff q n) → p = q :=
ext_iff.2
/-- Monomials generate the additive monoid of polynomials. -/
theorem addSubmonoid_closure_setOf_eq_monomial :
AddSubmonoid.closure { p : R[X] | ∃ n a, p = monomial n a } = ⊤ := by
apply top_unique
rw [← AddSubmonoid.map_equiv_top (toFinsuppIso R).symm.toAddEquiv, ←
Finsupp.add_closure_setOf_eq_single, AddMonoidHom.map_mclosure]
refine AddSubmonoid.closure_mono (Set.image_subset_iff.2 ?_)
rintro _ ⟨n, a, rfl⟩
exact ⟨n, a, Polynomial.ofFinsupp_single _ _⟩
theorem addHom_ext {M : Type*} [AddZeroClass M] {f g : R[X] →+ M}
(h : ∀ n a, f (monomial n a) = g (monomial n a)) : f = g :=
AddMonoidHom.eq_of_eqOn_denseM addSubmonoid_closure_setOf_eq_monomial <| by
rintro p ⟨n, a, rfl⟩
exact h n a
@[ext high]
theorem addHom_ext' {M : Type*} [AddZeroClass M] {f g : R[X] →+ M}
(h : ∀ n, f.comp (monomial n).toAddMonoidHom = g.comp (monomial n).toAddMonoidHom) : f = g :=
addHom_ext fun n => DFunLike.congr_fun (h n)
@[ext high]
theorem lhom_ext' {M : Type*} [AddCommMonoid M] [Module R M] {f g : R[X] →ₗ[R] M}
(h : ∀ n, f.comp (monomial n) = g.comp (monomial n)) : f = g :=
LinearMap.toAddMonoidHom_injective <| addHom_ext fun n => LinearMap.congr_fun (h n)
-- this has the same content as the subsingleton
theorem eq_zero_of_eq_zero (h : (0 : R) = (1 : R)) (p : R[X]) : p = 0 := by
rw [← one_smul R p, ← h, zero_smul]
section Fewnomials
theorem support_monomial (n) {a : R} (H : a ≠ 0) : (monomial n a).support = singleton n := by
rw [← ofFinsupp_single, support]; exact Finsupp.support_single_ne_zero _ H
theorem support_monomial' (n) (a : R) : (monomial n a).support ⊆ singleton n := by
rw [← ofFinsupp_single, support]
exact Finsupp.support_single_subset
theorem support_C {a : R} (h : a ≠ 0) : (C a).support = singleton 0 :=
support_monomial 0 h
theorem support_C_subset (a : R) : (C a).support ⊆ singleton 0 :=
support_monomial' 0 a
theorem support_C_mul_X {c : R} (h : c ≠ 0) : Polynomial.support (C c * X) = singleton 1 := by
rw [C_mul_X_eq_monomial, support_monomial 1 h]
theorem support_C_mul_X' (c : R) : Polynomial.support (C c * X) ⊆ singleton 1 := by
simpa only [C_mul_X_eq_monomial] using support_monomial' 1 c
theorem support_C_mul_X_pow (n : ℕ) {c : R} (h : c ≠ 0) :
Polynomial.support (C c * X ^ n) = singleton n := by
rw [C_mul_X_pow_eq_monomial, support_monomial n h]
theorem support_C_mul_X_pow' (n : ℕ) (c : R) : Polynomial.support (C c * X ^ n) ⊆ singleton n := by
simpa only [C_mul_X_pow_eq_monomial] using support_monomial' n c
open Finset
|
theorem support_binomial' (k m : ℕ) (x y : R) :
Polynomial.support (C x * X ^ k + C y * X ^ m) ⊆ {k, m} :=
| Mathlib/Algebra/Polynomial/Basic.lean | 777 | 779 |
/-
Copyright (c) 2018 Kenny Lau. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kenny Lau, Chris Hughes, Anne Baanen
-/
import Mathlib.Data.Matrix.Basic
import Mathlib.Data.Matrix.Block
import Mathlib.Data.Matrix.Notation
import Mathlib.Data.Matrix.RowCol
import Mathlib.GroupTheory.GroupAction.Ring
import Mathlib.GroupTheory.Perm.Fin
import Mathlib.LinearAlgebra.Alternating.Basic
import Mathlib.LinearAlgebra.Matrix.SemiringInverse
/-!
# Determinant of a matrix
This file defines the determinant of a matrix, `Matrix.det`, and its essential properties.
## Main definitions
- `Matrix.det`: the determinant of a square matrix, as a sum over permutations
- `Matrix.detRowAlternating`: the determinant, as an `AlternatingMap` in the rows of the matrix
## Main results
- `det_mul`: the determinant of `A * B` is the product of determinants
- `det_zero_of_row_eq`: the determinant is zero if there is a repeated row
- `det_block_diagonal`: the determinant of a block diagonal matrix is a product
of the blocks' determinants
## Implementation notes
It is possible to configure `simp` to compute determinants. See the file
`MathlibTest/matrix.lean` for some examples.
-/
universe u v w z
open Equiv Equiv.Perm Finset Function
namespace Matrix
variable {m n : Type*} [DecidableEq n] [Fintype n] [DecidableEq m] [Fintype m]
variable {R : Type v} [CommRing R]
local notation "ε " σ:arg => ((sign σ : ℤ) : R)
/-- `det` is an `AlternatingMap` in the rows of the matrix. -/
def detRowAlternating : (n → R) [⋀^n]→ₗ[R] R :=
MultilinearMap.alternatization ((MultilinearMap.mkPiAlgebra R n R).compLinearMap LinearMap.proj)
/-- The determinant of a matrix given by the Leibniz formula. -/
abbrev det (M : Matrix n n R) : R :=
detRowAlternating M
theorem det_apply (M : Matrix n n R) : M.det = ∑ σ : Perm n, Equiv.Perm.sign σ • ∏ i, M (σ i) i :=
MultilinearMap.alternatization_apply _ M
-- This is what the old definition was. We use it to avoid having to change the old proofs below
theorem det_apply' (M : Matrix n n R) : M.det = ∑ σ : Perm n, ε σ * ∏ i, M (σ i) i := by
simp [det_apply, Units.smul_def]
theorem det_eq_detp_sub_detp (M : Matrix n n R) : M.det = M.detp 1 - M.detp (-1) := by
rw [det_apply, ← Equiv.sum_comp (Equiv.inv (Perm n)), ← ofSign_disjUnion, sum_disjUnion]
simp_rw [inv_apply, sign_inv, sub_eq_add_neg, detp, ← sum_neg_distrib]
refine congr_arg₂ (· + ·) (sum_congr rfl fun σ hσ ↦ ?_) (sum_congr rfl fun σ hσ ↦ ?_) <;>
rw [mem_ofSign.mp hσ, ← Equiv.prod_comp σ] <;> simp
@[simp]
theorem det_diagonal {d : n → R} : det (diagonal d) = ∏ i, d i := by
rw [det_apply']
refine (Finset.sum_eq_single 1 ?_ ?_).trans ?_
· rintro σ - h2
obtain ⟨x, h3⟩ := not_forall.1 (mt Equiv.ext h2)
convert mul_zero (ε σ)
apply Finset.prod_eq_zero (mem_univ x)
exact if_neg h3
· simp
· simp
theorem det_zero (_ : Nonempty n) : det (0 : Matrix n n R) = 0 :=
(detRowAlternating : (n → R) [⋀^n]→ₗ[R] R).map_zero
@[simp]
theorem det_one : det (1 : Matrix n n R) = 1 := by rw [← diagonal_one]; simp [-diagonal_one]
theorem det_isEmpty [IsEmpty n] {A : Matrix n n R} : det A = 1 := by simp [det_apply]
@[simp]
theorem coe_det_isEmpty [IsEmpty n] : (det : Matrix n n R → R) = Function.const _ 1 := by
ext
exact det_isEmpty
theorem det_eq_one_of_card_eq_zero {A : Matrix n n R} (h : Fintype.card n = 0) : det A = 1 :=
haveI : IsEmpty n := Fintype.card_eq_zero_iff.mp h
det_isEmpty
/-- If `n` has only one element, the determinant of an `n` by `n` matrix is just that element.
Although `Unique` implies `DecidableEq` and `Fintype`, the instances might
not be syntactically equal. Thus, we need to fill in the args explicitly. -/
@[simp]
theorem det_unique {n : Type*} [Unique n] [DecidableEq n] [Fintype n] (A : Matrix n n R) :
det A = A default default := by simp [det_apply, univ_unique]
theorem det_eq_elem_of_subsingleton [Subsingleton n] (A : Matrix n n R) (k : n) :
det A = A k k := by
have := uniqueOfSubsingleton k
convert det_unique A
theorem det_eq_elem_of_card_eq_one {A : Matrix n n R} (h : Fintype.card n = 1) (k : n) :
det A = A k k :=
haveI : Subsingleton n := Fintype.card_le_one_iff_subsingleton.mp h.le
det_eq_elem_of_subsingleton _ _
theorem det_mul_aux {M N : Matrix n n R} {p : n → n} (H : ¬Bijective p) :
(∑ σ : Perm n, ε σ * ∏ x, M (σ x) (p x) * N (p x) x) = 0 := by
obtain ⟨i, j, hpij, hij⟩ : ∃ i j, p i = p j ∧ i ≠ j := by
rw [← Finite.injective_iff_bijective, Injective] at H
push_neg at H
exact H
exact
sum_involution (fun σ _ => σ * Equiv.swap i j)
(fun σ _ => by
have : (∏ x, M (σ x) (p x)) = ∏ x, M ((σ * Equiv.swap i j) x) (p x) :=
| Fintype.prod_equiv (swap i j) _ _ (by simp [apply_swap_eq_self hpij])
simp [this, sign_swap hij, -sign_swap', prod_mul_distrib])
(fun σ _ _ => (not_congr mul_swap_eq_iff).mpr hij) (fun _ _ => mem_univ _) fun σ _ =>
mul_swap_involutive i j σ
@[simp]
theorem det_mul (M N : Matrix n n R) : det (M * N) = det M * det N :=
calc
det (M * N) = ∑ p : n → n, ∑ σ : Perm n, ε σ * ∏ i, M (σ i) (p i) * N (p i) i := by
simp only [det_apply', mul_apply, prod_univ_sum, mul_sum, Fintype.piFinset_univ]
rw [Finset.sum_comm]
_ = ∑ p : n → n with Bijective p, ∑ σ : Perm n, ε σ * ∏ i, M (σ i) (p i) * N (p i) i := by
refine (sum_subset (filter_subset _ _) fun f _ hbij ↦ det_mul_aux ?_).symm
simpa only [true_and, mem_filter, mem_univ] using hbij
| Mathlib/LinearAlgebra/Matrix/Determinant/Basic.lean | 128 | 141 |
/-
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
| Mathlib/Data/Fintype/Card.lean | 139 | 140 |
/-
Copyright (c) 2023 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov
-/
import Mathlib.Data.Real.Cardinality
import Mathlib.Topology.TietzeExtension
/-!
# Not normal topological spaces
In this file we prove (see `IsClosed.not_normal_of_continuum_le_mk`) that a separable space with a
discrete subspace of cardinality continuum is not a normal topological space.
-/
open Set Function Cardinal Topology TopologicalSpace
universe u
variable {X : Type u} [TopologicalSpace X] [SeparableSpace X]
/-- Let `s` be a closed set in a separable normal space. If the induced topology on `s` is discrete,
then `s` has cardinality less than continuum.
The proof follows
https://en.wikipedia.org/wiki/Moore_plane#Proof_that_the_Moore_plane_is_not_normal -/
theorem IsClosed.mk_lt_continuum [NormalSpace X] {s : Set X} (hs : IsClosed s)
| [DiscreteTopology s] : #s < 𝔠 := by
-- Proof by contradiction: assume `𝔠 ≤ #s`
by_contra! h
-- Choose a countable dense set `t : Set X`
rcases exists_countable_dense X with ⟨t, htc, htd⟩
haveI := htc.to_subtype
-- To obtain a contradiction, we will prove `2 ^ 𝔠 ≤ 𝔠`.
refine (Cardinal.cantor 𝔠).not_le ?_
calc
-- Any function `s → ℝ` is continuous, hence `2 ^ 𝔠 ≤ #C(s, ℝ)`
2 ^ 𝔠 ≤ #C(s, ℝ) := by
rw [(ContinuousMap.equivFnOfDiscrete _ _).cardinal_eq, mk_arrow, mk_real, lift_continuum,
lift_uzero]
exact (power_le_power_left two_ne_zero h).trans (power_le_power_right (nat_lt_continuum 2).le)
-- By the Tietze Extension Theorem, any function `f : C(s, ℝ)` can be extended to `C(X, ℝ)`,
-- hence `#C(s, ℝ) ≤ #C(X, ℝ)`
_ ≤ #C(X, ℝ) := by
choose f hf using ContinuousMap.exists_restrict_eq (Y := ℝ) hs
have hfi : Injective f := LeftInverse.injective hf
exact mk_le_of_injective hfi
-- Since `t` is dense, restriction `C(X, ℝ) → C(t, ℝ)` is injective, hence `#C(X, ℝ) ≤ #C(t, ℝ)`
_ ≤ #C(t, ℝ) := mk_le_of_injective <| ContinuousMap.injective_restrict htd
_ ≤ #(t → ℝ) := mk_le_of_injective DFunLike.coe_injective
-- Since `t` is countable, we have `#(t → ℝ) ≤ 𝔠`
_ ≤ 𝔠 := by
rw [mk_arrow, mk_real, lift_uzero, lift_continuum, continuum, ← power_mul]
exact power_le_power_left two_ne_zero mk_le_aleph0
| Mathlib/Topology/Separation/NotNormal.lean | 26 | 53 |
/-
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.Analysis.Convex.Between
import Mathlib.Analysis.Normed.Group.AddTorsor
import Mathlib.Analysis.Normed.Module.Convex
/-!
# Sides of affine subspaces
This file defines notions of two points being on the same or opposite sides of an affine subspace.
## Main definitions
* `s.WSameSide x y`: The points `x` and `y` are weakly on the same side of the affine
subspace `s`.
* `s.SSameSide x y`: The points `x` and `y` are strictly on the same side of the affine
subspace `s`.
* `s.WOppSide x y`: The points `x` and `y` are weakly on opposite sides of the affine
subspace `s`.
* `s.SOppSide x y`: The points `x` and `y` are strictly on opposite sides of the affine
subspace `s`.
-/
variable {R V V' P P' : Type*}
open AffineEquiv AffineMap
namespace AffineSubspace
section StrictOrderedCommRing
variable [CommRing R] [PartialOrder R] [IsStrictOrderedRing R]
[AddCommGroup V] [Module R V] [AddTorsor V P]
variable [AddCommGroup V'] [Module R V'] [AddTorsor V' P']
/-- The points `x` and `y` are weakly on the same side of `s`. -/
def WSameSide (s : AffineSubspace R P) (x y : P) : Prop :=
∃ᵉ (p₁ ∈ s) (p₂ ∈ s), SameRay R (x -ᵥ p₁) (y -ᵥ p₂)
/-- The points `x` and `y` are strictly on the same side of `s`. -/
def SSameSide (s : AffineSubspace R P) (x y : P) : Prop :=
s.WSameSide x y ∧ x ∉ s ∧ y ∉ s
/-- The points `x` and `y` are weakly on opposite sides of `s`. -/
def WOppSide (s : AffineSubspace R P) (x y : P) : Prop :=
∃ᵉ (p₁ ∈ s) (p₂ ∈ s), SameRay R (x -ᵥ p₁) (p₂ -ᵥ y)
/-- The points `x` and `y` are strictly on opposite sides of `s`. -/
def SOppSide (s : AffineSubspace R P) (x y : P) : Prop :=
s.WOppSide x y ∧ x ∉ s ∧ y ∉ s
theorem WSameSide.map {s : AffineSubspace R P} {x y : P} (h : s.WSameSide x y) (f : P →ᵃ[R] P') :
(s.map f).WSameSide (f x) (f y) := by
rcases h with ⟨p₁, hp₁, p₂, hp₂, h⟩
refine ⟨f p₁, mem_map_of_mem f hp₁, f p₂, mem_map_of_mem f hp₂, ?_⟩
simp_rw [← linearMap_vsub]
exact h.map f.linear
theorem _root_.Function.Injective.wSameSide_map_iff {s : AffineSubspace R P} {x y : P}
{f : P →ᵃ[R] P'} (hf : Function.Injective f) :
(s.map f).WSameSide (f x) (f y) ↔ s.WSameSide x y := by
refine ⟨fun h => ?_, fun h => h.map _⟩
rcases h with ⟨fp₁, hfp₁, fp₂, hfp₂, h⟩
rw [mem_map] at hfp₁ hfp₂
rcases hfp₁ with ⟨p₁, hp₁, rfl⟩
rcases hfp₂ with ⟨p₂, hp₂, rfl⟩
refine ⟨p₁, hp₁, p₂, hp₂, ?_⟩
simp_rw [← linearMap_vsub, (f.linear_injective_iff.2 hf).sameRay_map_iff] at h
exact h
theorem _root_.Function.Injective.sSameSide_map_iff {s : AffineSubspace R P} {x y : P}
{f : P →ᵃ[R] P'} (hf : Function.Injective f) :
(s.map f).SSameSide (f x) (f y) ↔ s.SSameSide x y := by
simp_rw [SSameSide, hf.wSameSide_map_iff, mem_map_iff_mem_of_injective hf]
@[simp]
theorem _root_.AffineEquiv.wSameSide_map_iff {s : AffineSubspace R P} {x y : P} (f : P ≃ᵃ[R] P') :
(s.map ↑f).WSameSide (f x) (f y) ↔ s.WSameSide x y :=
(show Function.Injective f.toAffineMap from f.injective).wSameSide_map_iff
@[simp]
theorem _root_.AffineEquiv.sSameSide_map_iff {s : AffineSubspace R P} {x y : P} (f : P ≃ᵃ[R] P') :
(s.map ↑f).SSameSide (f x) (f y) ↔ s.SSameSide x y :=
(show Function.Injective f.toAffineMap from f.injective).sSameSide_map_iff
theorem WOppSide.map {s : AffineSubspace R P} {x y : P} (h : s.WOppSide x y) (f : P →ᵃ[R] P') :
(s.map f).WOppSide (f x) (f y) := by
rcases h with ⟨p₁, hp₁, p₂, hp₂, h⟩
refine ⟨f p₁, mem_map_of_mem f hp₁, f p₂, mem_map_of_mem f hp₂, ?_⟩
simp_rw [← linearMap_vsub]
exact h.map f.linear
theorem _root_.Function.Injective.wOppSide_map_iff {s : AffineSubspace R P} {x y : P}
{f : P →ᵃ[R] P'} (hf : Function.Injective f) :
(s.map f).WOppSide (f x) (f y) ↔ s.WOppSide x y := by
refine ⟨fun h => ?_, fun h => h.map _⟩
rcases h with ⟨fp₁, hfp₁, fp₂, hfp₂, h⟩
rw [mem_map] at hfp₁ hfp₂
rcases hfp₁ with ⟨p₁, hp₁, rfl⟩
rcases hfp₂ with ⟨p₂, hp₂, rfl⟩
refine ⟨p₁, hp₁, p₂, hp₂, ?_⟩
simp_rw [← linearMap_vsub, (f.linear_injective_iff.2 hf).sameRay_map_iff] at h
exact h
theorem _root_.Function.Injective.sOppSide_map_iff {s : AffineSubspace R P} {x y : P}
{f : P →ᵃ[R] P'} (hf : Function.Injective f) :
(s.map f).SOppSide (f x) (f y) ↔ s.SOppSide x y := by
simp_rw [SOppSide, hf.wOppSide_map_iff, mem_map_iff_mem_of_injective hf]
@[simp]
theorem _root_.AffineEquiv.wOppSide_map_iff {s : AffineSubspace R P} {x y : P} (f : P ≃ᵃ[R] P') :
(s.map ↑f).WOppSide (f x) (f y) ↔ s.WOppSide x y :=
(show Function.Injective f.toAffineMap from f.injective).wOppSide_map_iff
@[simp]
theorem _root_.AffineEquiv.sOppSide_map_iff {s : AffineSubspace R P} {x y : P} (f : P ≃ᵃ[R] P') :
(s.map ↑f).SOppSide (f x) (f y) ↔ s.SOppSide x y :=
(show Function.Injective f.toAffineMap from f.injective).sOppSide_map_iff
theorem WSameSide.nonempty {s : AffineSubspace R P} {x y : P} (h : s.WSameSide x y) :
(s : Set P).Nonempty :=
⟨h.choose, h.choose_spec.left⟩
theorem SSameSide.nonempty {s : AffineSubspace R P} {x y : P} (h : s.SSameSide x y) :
(s : Set P).Nonempty :=
⟨h.1.choose, h.1.choose_spec.left⟩
theorem WOppSide.nonempty {s : AffineSubspace R P} {x y : P} (h : s.WOppSide x y) :
(s : Set P).Nonempty :=
⟨h.choose, h.choose_spec.left⟩
theorem SOppSide.nonempty {s : AffineSubspace R P} {x y : P} (h : s.SOppSide x y) :
(s : Set P).Nonempty :=
⟨h.1.choose, h.1.choose_spec.left⟩
theorem SSameSide.wSameSide {s : AffineSubspace R P} {x y : P} (h : s.SSameSide x y) :
s.WSameSide x y :=
h.1
theorem SSameSide.left_not_mem {s : AffineSubspace R P} {x y : P} (h : s.SSameSide x y) : x ∉ s :=
h.2.1
theorem SSameSide.right_not_mem {s : AffineSubspace R P} {x y : P} (h : s.SSameSide x y) : y ∉ s :=
h.2.2
theorem SOppSide.wOppSide {s : AffineSubspace R P} {x y : P} (h : s.SOppSide x y) :
s.WOppSide x y :=
h.1
theorem SOppSide.left_not_mem {s : AffineSubspace R P} {x y : P} (h : s.SOppSide x y) : x ∉ s :=
h.2.1
theorem SOppSide.right_not_mem {s : AffineSubspace R P} {x y : P} (h : s.SOppSide x y) : y ∉ s :=
h.2.2
theorem wSameSide_comm {s : AffineSubspace R P} {x y : P} : s.WSameSide x y ↔ s.WSameSide y x :=
⟨fun ⟨p₁, hp₁, p₂, hp₂, h⟩ => ⟨p₂, hp₂, p₁, hp₁, h.symm⟩,
fun ⟨p₁, hp₁, p₂, hp₂, h⟩ => ⟨p₂, hp₂, p₁, hp₁, h.symm⟩⟩
alias ⟨WSameSide.symm, _⟩ := wSameSide_comm
theorem sSameSide_comm {s : AffineSubspace R P} {x y : P} : s.SSameSide x y ↔ s.SSameSide y x := by
rw [SSameSide, SSameSide, wSameSide_comm, and_comm (b := x ∉ s)]
alias ⟨SSameSide.symm, _⟩ := sSameSide_comm
theorem wOppSide_comm {s : AffineSubspace R P} {x y : P} : s.WOppSide x y ↔ s.WOppSide y x := by
constructor
· rintro ⟨p₁, hp₁, p₂, hp₂, h⟩
refine ⟨p₂, hp₂, p₁, hp₁, ?_⟩
rwa [SameRay.sameRay_comm, ← sameRay_neg_iff, neg_vsub_eq_vsub_rev, neg_vsub_eq_vsub_rev]
· rintro ⟨p₁, hp₁, p₂, hp₂, h⟩
refine ⟨p₂, hp₂, p₁, hp₁, ?_⟩
rwa [SameRay.sameRay_comm, ← sameRay_neg_iff, neg_vsub_eq_vsub_rev, neg_vsub_eq_vsub_rev]
alias ⟨WOppSide.symm, _⟩ := wOppSide_comm
theorem sOppSide_comm {s : AffineSubspace R P} {x y : P} : s.SOppSide x y ↔ s.SOppSide y x := by
rw [SOppSide, SOppSide, wOppSide_comm, and_comm (b := x ∉ s)]
alias ⟨SOppSide.symm, _⟩ := sOppSide_comm
theorem not_wSameSide_bot (x y : P) : ¬(⊥ : AffineSubspace R P).WSameSide x y :=
fun ⟨_, h, _⟩ => h.elim
theorem not_sSameSide_bot (x y : P) : ¬(⊥ : AffineSubspace R P).SSameSide x y :=
fun h => not_wSameSide_bot x y h.wSameSide
| theorem not_wOppSide_bot (x y : P) : ¬(⊥ : AffineSubspace R P).WOppSide x y :=
fun ⟨_, h, _⟩ => h.elim
| Mathlib/Analysis/Convex/Side.lean | 194 | 195 |
/-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Floris van Doorn, Violeta Hernández Palacios
-/
import Mathlib.Algebra.GroupWithZero.Divisibility
import Mathlib.Data.Nat.SuccPred
import Mathlib.Order.SuccPred.InitialSeg
import Mathlib.SetTheory.Ordinal.Basic
/-!
# Ordinal arithmetic
Ordinals have an addition (corresponding to disjoint union) that turns them into an additive
monoid, and a multiplication (corresponding to the lexicographic order on the product) that turns
them into a monoid. One can also define correspondingly a subtraction, a division, a successor
function, a power function and a logarithm function.
We also define limit ordinals and prove the basic induction principle on ordinals separating
successor ordinals and limit ordinals, in `limitRecOn`.
## Main definitions and results
* `o₁ + o₂` is the order on the disjoint union of `o₁` and `o₂` obtained by declaring that
every element of `o₁` is smaller than every element of `o₂`.
* `o₁ - o₂` is the unique ordinal `o` such that `o₂ + o = o₁`, when `o₂ ≤ o₁`.
* `o₁ * o₂` is the lexicographic order on `o₂ × o₁`.
* `o₁ / o₂` is the ordinal `o` such that `o₁ = o₂ * o + o'` with `o' < o₂`. We also define the
divisibility predicate, and a modulo operation.
* `Order.succ o = o + 1` is the successor of `o`.
* `pred o` if the predecessor of `o`. If `o` is not a successor, we set `pred o = o`.
We discuss the properties of casts of natural numbers of and of `ω` with respect to these
operations.
Some properties of the operations are also used to discuss general tools on ordinals:
* `IsLimit o`: an ordinal is a limit ordinal if it is neither `0` nor a successor.
* `limitRecOn` is the main induction principle of ordinals: if one can prove a property by
induction at successor ordinals and at limit ordinals, then it holds for all ordinals.
* `IsNormal`: a function `f : Ordinal → Ordinal` satisfies `IsNormal` if it is strictly increasing
and order-continuous, i.e., the image `f o` of a limit ordinal `o` is the sup of `f a` for
`a < o`.
Various other basic arithmetic results are given in `Principal.lean` instead.
-/
assert_not_exists Field Module
noncomputable section
open Function Cardinal Set Equiv Order
open scoped Ordinal
universe u v w
namespace Ordinal
variable {α β γ : Type*} {r : α → α → Prop} {s : β → β → Prop} {t : γ → γ → Prop}
/-! ### Further properties of addition on ordinals -/
@[simp]
theorem lift_add (a b : Ordinal.{v}) : lift.{u} (a + b) = lift.{u} a + lift.{u} b :=
Quotient.inductionOn₂ a b fun ⟨_α, _r, _⟩ ⟨_β, _s, _⟩ =>
Quotient.sound
⟨(RelIso.preimage Equiv.ulift _).trans
(RelIso.sumLexCongr (RelIso.preimage Equiv.ulift _) (RelIso.preimage Equiv.ulift _)).symm⟩
@[simp]
theorem lift_succ (a : Ordinal.{v}) : lift.{u} (succ a) = succ (lift.{u} a) := by
rw [← add_one_eq_succ, lift_add, lift_one]
rfl
instance instAddLeftReflectLE :
AddLeftReflectLE Ordinal.{u} where
elim c a b := by
refine inductionOn₃ a b c fun α r _ β s _ γ t _ ⟨f⟩ ↦ ?_
have H₁ a : f (Sum.inl a) = Sum.inl a := by
simpa using ((InitialSeg.leAdd t r).trans f).eq (InitialSeg.leAdd t s) a
have H₂ a : ∃ b, f (Sum.inr a) = Sum.inr b := by
generalize hx : f (Sum.inr a) = x
obtain x | x := x
· rw [← H₁, f.inj] at hx
contradiction
· exact ⟨x, rfl⟩
choose g hg using H₂
refine (RelEmbedding.ofMonotone g fun _ _ h ↦ ?_).ordinal_type_le
rwa [← @Sum.lex_inr_inr _ t _ s, ← hg, ← hg, f.map_rel_iff, Sum.lex_inr_inr]
instance : IsLeftCancelAdd Ordinal where
add_left_cancel a b c h := by simpa only [le_antisymm_iff, add_le_add_iff_left] using h
@[deprecated add_left_cancel_iff (since := "2024-12-11")]
protected theorem add_left_cancel (a) {b c : Ordinal} : a + b = a + c ↔ b = c :=
add_left_cancel_iff
private theorem add_lt_add_iff_left' (a) {b c : Ordinal} : a + b < a + c ↔ b < c := by
rw [← not_le, ← not_le, add_le_add_iff_left]
instance instAddLeftStrictMono : AddLeftStrictMono Ordinal.{u} :=
⟨fun a _b _c ↦ (add_lt_add_iff_left' a).2⟩
instance instAddLeftReflectLT : AddLeftReflectLT Ordinal.{u} :=
⟨fun a _b _c ↦ (add_lt_add_iff_left' a).1⟩
instance instAddRightReflectLT : AddRightReflectLT Ordinal.{u} :=
⟨fun _a _b _c ↦ lt_imp_lt_of_le_imp_le fun h => add_le_add_right h _⟩
theorem add_le_add_iff_right {a b : Ordinal} : ∀ n : ℕ, a + n ≤ b + n ↔ a ≤ b
| 0 => by simp
| n + 1 => by
simp only [natCast_succ, add_succ, add_succ, succ_le_succ_iff, add_le_add_iff_right]
theorem add_right_cancel {a b : Ordinal} (n : ℕ) : a + n = b + n ↔ a = b := by
simp only [le_antisymm_iff, add_le_add_iff_right]
theorem add_eq_zero_iff {a b : Ordinal} : a + b = 0 ↔ a = 0 ∧ b = 0 :=
inductionOn₂ a b fun α r _ β s _ => by
simp_rw [← type_sum_lex, type_eq_zero_iff_isEmpty]
exact isEmpty_sum
theorem left_eq_zero_of_add_eq_zero {a b : Ordinal} (h : a + b = 0) : a = 0 :=
(add_eq_zero_iff.1 h).1
theorem right_eq_zero_of_add_eq_zero {a b : Ordinal} (h : a + b = 0) : b = 0 :=
(add_eq_zero_iff.1 h).2
/-! ### The predecessor of an ordinal -/
open Classical in
/-- The ordinal predecessor of `o` is `o'` if `o = succ o'`,
and `o` otherwise. -/
def pred (o : Ordinal) : Ordinal :=
if h : ∃ a, o = succ a then Classical.choose h else o
@[simp]
theorem pred_succ (o) : pred (succ o) = o := by
have h : ∃ a, succ o = succ a := ⟨_, rfl⟩
simpa only [pred, dif_pos h] using (succ_injective <| Classical.choose_spec h).symm
theorem pred_le_self (o) : pred o ≤ o := by
classical
exact if h : ∃ a, o = succ a then by
let ⟨a, e⟩ := h
rw [e, pred_succ]; exact le_succ a
else by rw [pred, dif_neg h]
theorem pred_eq_iff_not_succ {o} : pred o = o ↔ ¬∃ a, o = succ a :=
⟨fun e ⟨a, e'⟩ => by rw [e', pred_succ] at e; exact (lt_succ a).ne e, fun h => dif_neg h⟩
theorem pred_eq_iff_not_succ' {o} : pred o = o ↔ ∀ a, o ≠ succ a := by
simpa using pred_eq_iff_not_succ
theorem pred_lt_iff_is_succ {o} : pred o < o ↔ ∃ a, o = succ a :=
Iff.trans (by simp only [le_antisymm_iff, pred_le_self, true_and, not_le])
(iff_not_comm.1 pred_eq_iff_not_succ).symm
@[simp]
theorem pred_zero : pred 0 = 0 :=
pred_eq_iff_not_succ'.2 fun a => (succ_ne_zero a).symm
theorem succ_pred_iff_is_succ {o} : succ (pred o) = o ↔ ∃ a, o = succ a :=
⟨fun e => ⟨_, e.symm⟩, fun ⟨a, e⟩ => by simp only [e, pred_succ]⟩
theorem succ_lt_of_not_succ {o b : Ordinal} (h : ¬∃ a, o = succ a) : succ b < o ↔ b < o :=
⟨(lt_succ b).trans, fun l => lt_of_le_of_ne (succ_le_of_lt l) fun e => h ⟨_, e.symm⟩⟩
theorem lt_pred {a b} : a < pred b ↔ succ a < b := by
classical
exact if h : ∃ a, b = succ a then by
let ⟨c, e⟩ := h
rw [e, pred_succ, succ_lt_succ_iff]
else by simp only [pred, dif_neg h, succ_lt_of_not_succ h]
theorem pred_le {a b} : pred a ≤ b ↔ a ≤ succ b :=
le_iff_le_iff_lt_iff_lt.2 lt_pred
@[simp]
theorem lift_is_succ {o : Ordinal.{v}} : (∃ a, lift.{u} o = succ a) ↔ ∃ a, o = succ a :=
⟨fun ⟨a, h⟩ =>
let ⟨b, e⟩ := mem_range_lift_of_le <| show a ≤ lift.{u} o from le_of_lt <| h.symm ▸ lt_succ a
⟨b, (lift_inj.{u,v}).1 <| by rw [h, ← e, lift_succ]⟩,
fun ⟨a, h⟩ => ⟨lift.{u} a, by simp only [h, lift_succ]⟩⟩
@[simp]
theorem lift_pred (o : Ordinal.{v}) : lift.{u} (pred o) = pred (lift.{u} o) := by
classical
exact if h : ∃ a, o = succ a then by obtain ⟨a, e⟩ := h; simp only [e, pred_succ, lift_succ]
else by rw [pred_eq_iff_not_succ.2 h, pred_eq_iff_not_succ.2 (mt lift_is_succ.1 h)]
|
/-! ### Limit ordinals -/
| Mathlib/SetTheory/Ordinal/Arithmetic.lean | 191 | 192 |
/-
Copyright (c) 2021 Jakob von Raumer. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jakob von Raumer
-/
import Mathlib.Tactic.CategoryTheory.Monoidal.Basic
import Mathlib.CategoryTheory.Closed.Monoidal
import Mathlib.Tactic.ApplyFun
/-!
# Rigid (autonomous) monoidal categories
This file defines rigid (autonomous) monoidal categories and the necessary theory about
exact pairings and duals.
## Main definitions
* `ExactPairing` of two objects of a monoidal category
* Type classes `HasLeftDual` and `HasRightDual` that capture that a pairing exists
* The `rightAdjointMate f` as a morphism `fᘁ : Yᘁ ⟶ Xᘁ` for a morphism `f : X ⟶ Y`
* The classes of `RightRigidCategory`, `LeftRigidCategory` and `RigidCategory`
## Main statements
* `comp_rightAdjointMate`: The adjoint mates of the composition is the composition of
adjoint mates.
## Notations
* `η_` and `ε_` denote the coevaluation and evaluation morphism of an exact pairing.
* `Xᘁ` and `ᘁX` denote the right and left dual of an object, as well as the adjoint
mate of a morphism.
## Future work
* Show that `X ⊗ Y` and `Yᘁ ⊗ Xᘁ` form an exact pairing.
* Show that the left adjoint mate of the right adjoint mate of a morphism is the morphism itself.
* Simplify constructions in the case where a symmetry or braiding is present.
* Show that `ᘁ` gives an equivalence of categories `C ≅ (Cᵒᵖ)ᴹᵒᵖ`.
* Define pivotal categories (rigid categories equipped with a natural isomorphism `ᘁᘁ ≅ 𝟙 C`).
## Notes
Although we construct the adjunction `tensorLeft Y ⊣ tensorLeft X` from `ExactPairing X Y`,
this is not a bijective correspondence.
I think the correct statement is that `tensorLeft Y` and `tensorLeft X` are
module endofunctors of `C` as a right `C` module category,
and `ExactPairing X Y` is in bijection with adjunctions compatible with this right `C` action.
## References
* <https://ncatlab.org/nlab/show/rigid+monoidal+category>
## Tags
rigid category, monoidal category
-/
open CategoryTheory MonoidalCategory
universe v v₁ v₂ v₃ u u₁ u₂ u₃
noncomputable section
namespace CategoryTheory
variable {C : Type u₁} [Category.{v₁} C] [MonoidalCategory C]
/-- An exact pairing is a pair of objects `X Y : C` which admit
a coevaluation and evaluation morphism which fulfill two triangle equalities. -/
class ExactPairing (X Y : C) where
/-- Coevaluation of an exact pairing.
Do not use directly. Use `ExactPairing.coevaluation` instead. -/
coevaluation' : 𝟙_ C ⟶ X ⊗ Y
/-- Evaluation of an exact pairing.
Do not use directly. Use `ExactPairing.evaluation` instead. -/
evaluation' : Y ⊗ X ⟶ 𝟙_ C
coevaluation_evaluation' :
Y ◁ coevaluation' ≫ (α_ _ _ _).inv ≫ evaluation' ▷ Y = (ρ_ Y).hom ≫ (λ_ Y).inv := by
aesop_cat
evaluation_coevaluation' :
coevaluation' ▷ X ≫ (α_ _ _ _).hom ≫ X ◁ evaluation' = (λ_ X).hom ≫ (ρ_ X).inv := by
aesop_cat
namespace ExactPairing
-- Porting note: as there is no mechanism equivalent to `[]` in Lean 3 to make
-- arguments for class fields explicit,
-- we now repeat all the fields without primes.
-- See https://leanprover.zulipchat.com/#narrow/stream/287929-mathlib4/topic/Making.20variable.20in.20class.20field.20explicit
variable (X Y : C)
variable [ExactPairing X Y]
/-- Coevaluation of an exact pairing. -/
def coevaluation : 𝟙_ C ⟶ X ⊗ Y := @coevaluation' _ _ _ X Y _
/-- Evaluation of an exact pairing. -/
def evaluation : Y ⊗ X ⟶ 𝟙_ C := @evaluation' _ _ _ X Y _
@[inherit_doc] notation "η_" => ExactPairing.coevaluation
@[inherit_doc] notation "ε_" => ExactPairing.evaluation
lemma coevaluation_evaluation :
Y ◁ η_ _ _ ≫ (α_ _ _ _).inv ≫ ε_ X _ ▷ Y = (ρ_ Y).hom ≫ (λ_ Y).inv :=
coevaluation_evaluation'
lemma evaluation_coevaluation :
η_ _ _ ▷ X ≫ (α_ _ _ _).hom ≫ X ◁ ε_ _ Y = (λ_ X).hom ≫ (ρ_ X).inv :=
evaluation_coevaluation'
lemma coevaluation_evaluation'' :
Y ◁ η_ X Y ⊗≫ ε_ X Y ▷ Y = ⊗𝟙.hom := by
convert coevaluation_evaluation X Y <;> simp [monoidalComp]
lemma evaluation_coevaluation'' :
η_ X Y ▷ X ⊗≫ X ◁ ε_ X Y = ⊗𝟙.hom := by
convert evaluation_coevaluation X Y <;> simp [monoidalComp]
end ExactPairing
attribute [reassoc (attr := simp)] ExactPairing.coevaluation_evaluation
attribute [reassoc (attr := simp)] ExactPairing.evaluation_coevaluation
instance exactPairingUnit : ExactPairing (𝟙_ C) (𝟙_ C) where
coevaluation' := (ρ_ _).inv
evaluation' := (ρ_ _).hom
coevaluation_evaluation' := by monoidal_coherence
evaluation_coevaluation' := by monoidal_coherence
/-- A class of objects which have a right dual. -/
class HasRightDual (X : C) where
/-- The right dual of the object `X`. -/
rightDual : C
[exact : ExactPairing X rightDual]
/-- A class of objects which have a left dual. -/
class HasLeftDual (Y : C) where
/-- The left dual of the object `X`. -/
leftDual : C
[exact : ExactPairing leftDual Y]
attribute [instance] HasRightDual.exact
attribute [instance] HasLeftDual.exact
open ExactPairing HasRightDual HasLeftDual MonoidalCategory
#adaptation_note /-- https://github.com/leanprover/lean4/pull/4596
The overlapping notation for `leftDual` and `leftAdjointMate` become more problematic in
after https://github.com/leanprover/lean4/pull/4596, and we sometimes have to disambiguate with
e.g. `(ᘁX : C)` where previously just `ᘁX` was enough. -/
@[inherit_doc] prefix:1024 "ᘁ" => leftDual
@[inherit_doc] postfix:1024 "ᘁ" => rightDual
instance hasRightDualUnit : HasRightDual (𝟙_ C) where
rightDual := 𝟙_ C
instance hasLeftDualUnit : HasLeftDual (𝟙_ C) where
leftDual := 𝟙_ C
instance hasRightDualLeftDual {X : C} [HasLeftDual X] : HasRightDual ᘁX where
rightDual := X
instance hasLeftDualRightDual {X : C} [HasRightDual X] : HasLeftDual Xᘁ where
leftDual := X
@[simp]
theorem leftDual_rightDual {X : C} [HasRightDual X] : ᘁXᘁ = X :=
rfl
@[simp]
theorem rightDual_leftDual {X : C} [HasLeftDual X] : (ᘁX)ᘁ = X :=
rfl
/-- The right adjoint mate `fᘁ : Xᘁ ⟶ Yᘁ` of a morphism `f : X ⟶ Y`. -/
def rightAdjointMate {X Y : C} [HasRightDual X] [HasRightDual Y] (f : X ⟶ Y) : Yᘁ ⟶ Xᘁ :=
(ρ_ _).inv ≫ _ ◁ η_ _ _ ≫ _ ◁ f ▷ _ ≫ (α_ _ _ _).inv ≫ ε_ _ _ ▷ _ ≫ (λ_ _).hom
/-- The left adjoint mate `ᘁf : ᘁY ⟶ ᘁX` of a morphism `f : X ⟶ Y`. -/
def leftAdjointMate {X Y : C} [HasLeftDual X] [HasLeftDual Y] (f : X ⟶ Y) : ᘁY ⟶ ᘁX :=
(λ_ _).inv ≫ η_ (ᘁX) X ▷ _ ≫ (_ ◁ f) ▷ _ ≫ (α_ _ _ _).hom ≫ _ ◁ ε_ _ _ ≫ (ρ_ _).hom
@[inherit_doc] notation f "ᘁ" => rightAdjointMate f
@[inherit_doc] notation "ᘁ" f => leftAdjointMate f
@[simp]
theorem rightAdjointMate_id {X : C} [HasRightDual X] : (𝟙 X)ᘁ = 𝟙 (Xᘁ) := by
simp [rightAdjointMate]
@[simp]
theorem leftAdjointMate_id {X : C} [HasLeftDual X] : (ᘁ(𝟙 X)) = 𝟙 (ᘁX) := by
simp [leftAdjointMate]
theorem rightAdjointMate_comp {X Y Z : C} [HasRightDual X] [HasRightDual Y] {f : X ⟶ Y}
{g : Xᘁ ⟶ Z} :
fᘁ ≫ g =
(ρ_ (Yᘁ)).inv ≫
_ ◁ η_ X (Xᘁ) ≫ _ ◁ (f ⊗ g) ≫ (α_ (Yᘁ) Y Z).inv ≫ ε_ Y (Yᘁ) ▷ _ ≫ (λ_ Z).hom :=
calc
_ = 𝟙 _ ⊗≫ (Yᘁ : C) ◁ η_ X Xᘁ ≫ Yᘁ ◁ f ▷ Xᘁ ⊗≫ (ε_ Y Yᘁ ▷ Xᘁ ≫ 𝟙_ C ◁ g) ⊗≫ 𝟙 _ := by
dsimp only [rightAdjointMate]; monoidal
_ = _ := by
rw [← whisker_exchange, tensorHom_def]; monoidal
theorem leftAdjointMate_comp {X Y Z : C} [HasLeftDual X] [HasLeftDual Y] {f : X ⟶ Y}
{g : (ᘁX) ⟶ Z} :
(ᘁf) ≫ g =
(λ_ _).inv ≫
η_ (ᘁX : C) X ▷ _ ≫ (g ⊗ f) ▷ _ ≫ (α_ _ _ _).hom ≫ _ ◁ ε_ _ _ ≫ (ρ_ _).hom :=
calc
_ = 𝟙 _ ⊗≫ η_ (ᘁX : C) X ▷ (ᘁY) ⊗≫ (ᘁX) ◁ f ▷ (ᘁY) ⊗≫ ((ᘁX) ◁ ε_ (ᘁY) Y ≫ g ▷ 𝟙_ C) ⊗≫ 𝟙 _ := by
dsimp only [leftAdjointMate]; monoidal
_ = _ := by
rw [whisker_exchange, tensorHom_def']; monoidal
/-- The composition of right adjoint mates is the adjoint mate of the composition. -/
@[reassoc]
theorem comp_rightAdjointMate {X Y Z : C} [HasRightDual X] [HasRightDual Y] [HasRightDual Z]
{f : X ⟶ Y} {g : Y ⟶ Z} : (f ≫ g)ᘁ = gᘁ ≫ fᘁ := by
rw [rightAdjointMate_comp]
simp only [rightAdjointMate, comp_whiskerRight]
simp only [← Category.assoc]; congr 3; simp only [Category.assoc]
simp only [← MonoidalCategory.whiskerLeft_comp]; congr 2
symm
calc
_ = 𝟙 _ ⊗≫ (η_ Y Yᘁ ▷ 𝟙_ C ≫ (Y ⊗ Yᘁ) ◁ η_ X Xᘁ) ⊗≫ Y ◁ Yᘁ ◁ f ▷ Xᘁ ⊗≫
Y ◁ ε_ Y Yᘁ ▷ Xᘁ ⊗≫ g ▷ Xᘁ ⊗≫ 𝟙 _ := by
rw [tensorHom_def']; monoidal
_ = η_ X Xᘁ ⊗≫ (η_ Y Yᘁ ▷ (X ⊗ Xᘁ) ≫ (Y ⊗ Yᘁ) ◁ f ▷ Xᘁ) ⊗≫
Y ◁ ε_ Y Yᘁ ▷ Xᘁ ⊗≫ g ▷ Xᘁ ⊗≫ 𝟙 _ := by
rw [← whisker_exchange]; monoidal
_ = η_ X Xᘁ ⊗≫ f ▷ Xᘁ ⊗≫ (η_ Y Yᘁ ▷ Y ⊗≫ Y ◁ ε_ Y Yᘁ) ▷ Xᘁ ⊗≫ g ▷ Xᘁ ⊗≫ 𝟙 _ := by
rw [← whisker_exchange]; monoidal
_ = η_ X Xᘁ ≫ f ▷ Xᘁ ≫ g ▷ Xᘁ := by
rw [evaluation_coevaluation'']; monoidal
/-- The composition of left adjoint mates is the adjoint mate of the composition. -/
@[reassoc]
theorem comp_leftAdjointMate {X Y Z : C} [HasLeftDual X] [HasLeftDual Y] [HasLeftDual Z] {f : X ⟶ Y}
{g : Y ⟶ Z} : (ᘁf ≫ g) = (ᘁg) ≫ ᘁf := by
rw [leftAdjointMate_comp]
simp only [leftAdjointMate, MonoidalCategory.whiskerLeft_comp]
simp only [← Category.assoc]; congr 3; simp only [Category.assoc]
simp only [← comp_whiskerRight]; congr 2
symm
calc
_ = 𝟙 _ ⊗≫ ((𝟙_ C) ◁ η_ (ᘁY) Y ≫ η_ (ᘁX) X ▷ ((ᘁY) ⊗ Y)) ⊗≫ (ᘁX) ◁ f ▷ (ᘁY) ▷ Y ⊗≫
(ᘁX) ◁ ε_ (ᘁY) Y ▷ Y ⊗≫ (ᘁX) ◁ g := by
rw [tensorHom_def]; monoidal
_ = η_ (ᘁX) X ⊗≫ (((ᘁX) ⊗ X) ◁ η_ (ᘁY) Y ≫ ((ᘁX) ◁ f) ▷ ((ᘁY) ⊗ Y)) ⊗≫
(ᘁX) ◁ ε_ (ᘁY) Y ▷ Y ⊗≫ (ᘁX) ◁ g := by
rw [whisker_exchange]; monoidal
_ = η_ (ᘁX) X ⊗≫ ((ᘁX) ◁ f) ⊗≫ (ᘁX) ◁ (Y ◁ η_ (ᘁY) Y ⊗≫ ε_ (ᘁY) Y ▷ Y) ⊗≫ (ᘁX) ◁ g := by
rw [whisker_exchange]; monoidal
_ = η_ (ᘁX) X ≫ (ᘁX) ◁ f ≫ (ᘁX) ◁ g := by
rw [coevaluation_evaluation'']; monoidal
/-- Given an exact pairing on `Y Y'`,
we get a bijection on hom-sets `(Y' ⊗ X ⟶ Z) ≃ (X ⟶ Y ⊗ Z)`
by "pulling the string on the left" up or down.
This gives the adjunction `tensorLeftAdjunction Y Y' : tensorLeft Y' ⊣ tensorLeft Y`.
This adjunction is often referred to as "Frobenius reciprocity" in the
fusion categories / planar algebras / subfactors literature.
-/
def tensorLeftHomEquiv (X Y Y' Z : C) [ExactPairing Y Y'] : (Y' ⊗ X ⟶ Z) ≃ (X ⟶ Y ⊗ Z) where
toFun f := (λ_ _).inv ≫ η_ _ _ ▷ _ ≫ (α_ _ _ _).hom ≫ _ ◁ f
invFun f := Y' ◁ f ≫ (α_ _ _ _).inv ≫ ε_ _ _ ▷ _ ≫ (λ_ _).hom
left_inv f := by
calc
_ = 𝟙 _ ⊗≫ Y' ◁ η_ Y Y' ▷ X ⊗≫ ((Y' ⊗ Y) ◁ f ≫ ε_ Y Y' ▷ Z) ⊗≫ 𝟙 _ := by
monoidal
_ = 𝟙 _ ⊗≫ (Y' ◁ η_ Y Y' ⊗≫ ε_ Y Y' ▷ Y') ▷ X ⊗≫ f := by
rw [whisker_exchange]; monoidal
_ = f := by
rw [coevaluation_evaluation'']; monoidal
right_inv f := by
calc
_ = 𝟙 _ ⊗≫ (η_ Y Y' ▷ X ≫ (Y ⊗ Y') ◁ f) ⊗≫ Y ◁ ε_ Y Y' ▷ Z ⊗≫ 𝟙 _ := by
monoidal
_ = f ⊗≫ (η_ Y Y' ▷ Y ⊗≫ Y ◁ ε_ Y Y') ▷ Z ⊗≫ 𝟙 _ := by
rw [← whisker_exchange]; monoidal
_ = f := by
rw [evaluation_coevaluation'']; monoidal
/-- Given an exact pairing on `Y Y'`,
we get a bijection on hom-sets `(X ⊗ Y ⟶ Z) ≃ (X ⟶ Z ⊗ Y')`
by "pulling the string on the right" up or down.
-/
def tensorRightHomEquiv (X Y Y' Z : C) [ExactPairing Y Y'] : (X ⊗ Y ⟶ Z) ≃ (X ⟶ Z ⊗ Y') where
toFun f := (ρ_ _).inv ≫ _ ◁ η_ _ _ ≫ (α_ _ _ _).inv ≫ f ▷ _
invFun f := f ▷ _ ≫ (α_ _ _ _).hom ≫ _ ◁ ε_ _ _ ≫ (ρ_ _).hom
left_inv f := by
calc
_ = 𝟙 _ ⊗≫ X ◁ η_ Y Y' ▷ Y ⊗≫ (f ▷ (Y' ⊗ Y) ≫ Z ◁ ε_ Y Y') ⊗≫ 𝟙 _ := by
monoidal
_ = 𝟙 _ ⊗≫ X ◁ (η_ Y Y' ▷ Y ⊗≫ Y ◁ ε_ Y Y') ⊗≫ f := by
rw [← whisker_exchange]; monoidal
_ = f := by
rw [evaluation_coevaluation'']; monoidal
right_inv f := by
calc
_ = 𝟙 _ ⊗≫ (X ◁ η_ Y Y' ≫ f ▷ (Y ⊗ Y')) ⊗≫ Z ◁ ε_ Y Y' ▷ Y' ⊗≫ 𝟙 _ := by
monoidal
_ = f ⊗≫ Z ◁ (Y' ◁ η_ Y Y' ⊗≫ ε_ Y Y' ▷ Y') ⊗≫ 𝟙 _ := by
rw [whisker_exchange]; monoidal
_ = f := by
rw [coevaluation_evaluation'']; monoidal
theorem tensorLeftHomEquiv_naturality {X Y Y' Z Z' : C} [ExactPairing Y Y'] (f : Y' ⊗ X ⟶ Z)
(g : Z ⟶ Z') :
(tensorLeftHomEquiv X Y Y' Z') (f ≫ g) = (tensorLeftHomEquiv X Y Y' Z) f ≫ Y ◁ g := by
simp [tensorLeftHomEquiv]
theorem tensorLeftHomEquiv_symm_naturality {X X' Y Y' Z : C} [ExactPairing Y Y'] (f : X ⟶ X')
(g : X' ⟶ Y ⊗ Z) :
(tensorLeftHomEquiv X Y Y' Z).symm (f ≫ g) =
_ ◁ f ≫ (tensorLeftHomEquiv X' Y Y' Z).symm g := by
simp [tensorLeftHomEquiv]
theorem tensorRightHomEquiv_naturality {X Y Y' Z Z' : C} [ExactPairing Y Y'] (f : X ⊗ Y ⟶ Z)
(g : Z ⟶ Z') :
(tensorRightHomEquiv X Y Y' Z') (f ≫ g) = (tensorRightHomEquiv X Y Y' Z) f ≫ g ▷ Y' := by
simp [tensorRightHomEquiv]
theorem tensorRightHomEquiv_symm_naturality {X X' Y Y' Z : C} [ExactPairing Y Y'] (f : X ⟶ X')
(g : X' ⟶ Z ⊗ Y') :
(tensorRightHomEquiv X Y Y' Z).symm (f ≫ g) =
f ▷ Y ≫ (tensorRightHomEquiv X' Y Y' Z).symm g := by
simp [tensorRightHomEquiv]
/-- If `Y Y'` have an exact pairing,
then the functor `tensorLeft Y'` is left adjoint to `tensorLeft Y`.
-/
def tensorLeftAdjunction (Y Y' : C) [ExactPairing Y Y'] : tensorLeft Y' ⊣ tensorLeft Y :=
Adjunction.mkOfHomEquiv
{ homEquiv := fun X Z => tensorLeftHomEquiv X Y Y' Z
homEquiv_naturality_left_symm := fun f g => tensorLeftHomEquiv_symm_naturality f g
homEquiv_naturality_right := fun f g => tensorLeftHomEquiv_naturality f g }
| /-- If `Y Y'` have an exact pairing,
then the functor `tensor_right Y` is left adjoint to `tensor_right Y'`.
-/
def tensorRightAdjunction (Y Y' : C) [ExactPairing Y Y'] : tensorRight Y ⊣ tensorRight Y' :=
| Mathlib/CategoryTheory/Monoidal/Rigid/Basic.lean | 346 | 349 |
/-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Johannes Hölzl, Kim Morrison, Jens Wagemaker
-/
import Mathlib.Algebra.MonoidAlgebra.Support
import Mathlib.Algebra.Polynomial.Basic
import Mathlib.Data.Nat.Choose.Sum
import Mathlib.Algebra.CharP.Defs
/-!
# Theory of univariate polynomials
The theorems include formulas for computing coefficients, such as
`coeff_add`, `coeff_sum`, `coeff_mul`
-/
noncomputable section
open Finsupp Finset AddMonoidAlgebra
open Polynomial
namespace Polynomial
universe u v
variable {R : Type u} {S : Type v} {a b : R} {n m : ℕ}
variable [Semiring R] {p q r : R[X]}
section Coeff
@[simp]
theorem coeff_add (p q : R[X]) (n : ℕ) : coeff (p + q) n = coeff p n + coeff q n := by
rcases p with ⟨⟩
rcases q with ⟨⟩
simp_rw [← ofFinsupp_add, coeff]
exact Finsupp.add_apply _ _ _
@[simp]
theorem coeff_smul [SMulZeroClass S R] (r : S) (p : R[X]) (n : ℕ) :
coeff (r • p) n = r • coeff p n := by
rcases p with ⟨⟩
simp_rw [← ofFinsupp_smul, coeff]
exact Finsupp.smul_apply _ _ _
| theorem support_smul [SMulZeroClass S R] (r : S) (p : R[X]) :
support (r • p) ⊆ support p := by
intro i hi
simp? [mem_support_iff] at hi ⊢ says simp only [mem_support_iff, coeff_smul, ne_eq] at hi ⊢
contrapose! hi
| Mathlib/Algebra/Polynomial/Coeff.lean | 50 | 54 |
/-
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.Algebra.Order.Ring.WithTop
import Mathlib.Algebra.Order.Sub.WithTop
import Mathlib.Data.NNReal.Defs
import Mathlib.Order.Interval.Set.WithBotTop
/-!
# Extended non-negative reals
We define `ENNReal = ℝ≥0∞ := WithTop ℝ≥0` to be the type of extended nonnegative real numbers,
i.e., the interval `[0, +∞]`. This type is used as the codomain of a `MeasureTheory.Measure`,
and of the extended distance `edist` in an `EMetricSpace`.
In this file we set up many of the instances on `ℝ≥0∞`, and provide relationships between `ℝ≥0∞` and
`ℝ≥0`, and between `ℝ≥0∞` and `ℝ`. In particular, we provide a coercion from `ℝ≥0` to `ℝ≥0∞` as well
as functions `ENNReal.toNNReal`, `ENNReal.ofReal` and `ENNReal.toReal`, all of which take the value
zero wherever they cannot be the identity. Also included is the relationship between `ℝ≥0∞` and `ℕ`.
The interaction of these functions, especially `ENNReal.ofReal` and `ENNReal.toReal`, with the
algebraic and lattice structure can be found in `Data.ENNReal.Real`.
This file proves many of the order properties of `ℝ≥0∞`, with the exception of the ways those relate
to the algebraic structure, which are included in `Data.ENNReal.Operations`.
This file also defines inversion and division: this includes `Inv` and `Div` instances on `ℝ≥0∞`
making it into a `DivInvOneMonoid`.
As a consequence of being a `DivInvOneMonoid`, `ℝ≥0∞` inherits a power operation with integer
exponent: this and other properties is shown in `Data.ENNReal.Inv`.
## Main definitions
* `ℝ≥0∞`: the extended nonnegative real numbers `[0, ∞]`; defined as `WithTop ℝ≥0`; it is
equipped with the following structures:
- coercion from `ℝ≥0` defined in the natural way;
- the natural structure of a complete dense linear order: `↑p ≤ ↑q ↔ p ≤ q` and `∀ a, a ≤ ∞`;
- `a + b` is defined so that `↑p + ↑q = ↑(p + q)` for `(p q : ℝ≥0)` and `a + ∞ = ∞ + a = ∞`;
- `a * b` is defined so that `↑p * ↑q = ↑(p * q)` for `(p q : ℝ≥0)`, `0 * ∞ = ∞ * 0 = 0`, and
`a * ∞ = ∞ * a = ∞` for `a ≠ 0`;
- `a - b` is defined as the minimal `d` such that `a ≤ d + b`; this way we have
`↑p - ↑q = ↑(p - q)`, `∞ - ↑p = ∞`, `↑p - ∞ = ∞ - ∞ = 0`; note that there is no negation, only
subtraction;
The addition and multiplication defined this way together with `0 = ↑0` and `1 = ↑1` turn
`ℝ≥0∞` into a canonically ordered commutative semiring of characteristic zero.
- `a⁻¹` is defined as `Inf {b | 1 ≤ a * b}`. This way we have `(↑p)⁻¹ = ↑(p⁻¹)` for
`p : ℝ≥0`, `p ≠ 0`, `0⁻¹ = ∞`, and `∞⁻¹ = 0`.
- `a / b` is defined as `a * b⁻¹`.
This inversion and division include `Inv` and `Div` instances on `ℝ≥0∞`,
making it into a `DivInvOneMonoid`. Further properties of these are shown in `Data.ENNReal.Inv`.
* Coercions to/from other types:
- coercion `ℝ≥0 → ℝ≥0∞` is defined as `Coe`, so one can use `(p : ℝ≥0)` in a context that
expects `a : ℝ≥0∞`, and Lean will apply `coe` automatically;
- `ENNReal.toNNReal` sends `↑p` to `p` and `∞` to `0`;
- `ENNReal.toReal := coe ∘ ENNReal.toNNReal` sends `↑p`, `p : ℝ≥0` to `(↑p : ℝ)` and `∞` to `0`;
- `ENNReal.ofReal := coe ∘ Real.toNNReal` sends `x : ℝ` to `↑⟨max x 0, _⟩`
- `ENNReal.neTopEquivNNReal` is an equivalence between `{a : ℝ≥0∞ // a ≠ 0}` and `ℝ≥0`.
## Implementation notes
We define a `CanLift ℝ≥0∞ ℝ≥0` instance, so one of the ways to prove theorems about an `ℝ≥0∞`
number `a` is to consider the cases `a = ∞` and `a ≠ ∞`, and use the tactic `lift a to ℝ≥0 using ha`
in the second case. This instance is even more useful if one already has `ha : a ≠ ∞` in the
context, or if we have `(f : α → ℝ≥0∞) (hf : ∀ x, f x ≠ ∞)`.
## Notations
* `ℝ≥0∞`: the type of the extended nonnegative real numbers;
* `ℝ≥0`: the type of nonnegative real numbers `[0, ∞)`; defined in `Data.Real.NNReal`;
* `∞`: a localized notation in `ENNReal` for `⊤ : ℝ≥0∞`.
-/
assert_not_exists Finset
open Function Set NNReal
variable {α : Type*}
/-- The extended nonnegative real numbers. This is usually denoted [0, ∞],
and is relevant as the codomain of a measure. -/
def ENNReal := WithTop ℝ≥0
deriving Zero, Top, AddCommMonoidWithOne, SemilatticeSup, DistribLattice, Nontrivial
@[inherit_doc]
scoped[ENNReal] notation "ℝ≥0∞" => ENNReal
/-- Notation for infinity as an `ENNReal` number. -/
scoped[ENNReal] notation "∞" => (⊤ : ENNReal)
namespace ENNReal
instance : OrderBot ℝ≥0∞ := inferInstanceAs (OrderBot (WithTop ℝ≥0))
instance : OrderTop ℝ≥0∞ := inferInstanceAs (OrderTop (WithTop ℝ≥0))
instance : BoundedOrder ℝ≥0∞ := inferInstanceAs (BoundedOrder (WithTop ℝ≥0))
instance : CharZero ℝ≥0∞ := inferInstanceAs (CharZero (WithTop ℝ≥0))
instance : Min ℝ≥0∞ := SemilatticeInf.toMin
instance : Max ℝ≥0∞ := SemilatticeSup.toMax
noncomputable instance : CommSemiring ℝ≥0∞ :=
inferInstanceAs (CommSemiring (WithTop ℝ≥0))
instance : PartialOrder ℝ≥0∞ :=
inferInstanceAs (PartialOrder (WithTop ℝ≥0))
instance : IsOrderedRing ℝ≥0∞ :=
inferInstanceAs (IsOrderedRing (WithTop ℝ≥0))
instance : CanonicallyOrderedAdd ℝ≥0∞ :=
inferInstanceAs (CanonicallyOrderedAdd (WithTop ℝ≥0))
instance : NoZeroDivisors ℝ≥0∞ :=
inferInstanceAs (NoZeroDivisors (WithTop ℝ≥0))
noncomputable instance : CompleteLinearOrder ℝ≥0∞ :=
inferInstanceAs (CompleteLinearOrder (WithTop ℝ≥0))
instance : DenselyOrdered ℝ≥0∞ := inferInstanceAs (DenselyOrdered (WithTop ℝ≥0))
instance : AddCommMonoid ℝ≥0∞ :=
inferInstanceAs (AddCommMonoid (WithTop ℝ≥0))
noncomputable instance : LinearOrder ℝ≥0∞ :=
inferInstanceAs (LinearOrder (WithTop ℝ≥0))
instance : IsOrderedAddMonoid ℝ≥0∞ :=
inferInstanceAs (IsOrderedAddMonoid (WithTop ℝ≥0))
instance instSub : Sub ℝ≥0∞ := inferInstanceAs (Sub (WithTop ℝ≥0))
instance : OrderedSub ℝ≥0∞ := inferInstanceAs (OrderedSub (WithTop ℝ≥0))
noncomputable instance : LinearOrderedAddCommMonoidWithTop ℝ≥0∞ :=
inferInstanceAs (LinearOrderedAddCommMonoidWithTop (WithTop ℝ≥0))
-- RFC: redefine using pattern matching?
noncomputable instance : Inv ℝ≥0∞ := ⟨fun a => sInf { b | 1 ≤ a * b }⟩
noncomputable instance : DivInvMonoid ℝ≥0∞ where
variable {a b c d : ℝ≥0∞} {r p q : ℝ≥0}
-- TODO: add a `WithTop` instance and use it here
noncomputable instance : LinearOrderedCommMonoidWithZero ℝ≥0∞ :=
{ inferInstanceAs (LinearOrderedAddCommMonoidWithTop ℝ≥0∞),
inferInstanceAs (CommSemiring ℝ≥0∞) with
bot_le _ := bot_le
mul_le_mul_left := fun _ _ => mul_le_mul_left'
zero_le_one := zero_le 1 }
instance : Unique (AddUnits ℝ≥0∞) where
default := 0
uniq a := AddUnits.ext <| le_zero_iff.1 <| by rw [← a.add_neg]; exact le_self_add
instance : Inhabited ℝ≥0∞ := ⟨0⟩
/-- Coercion from `ℝ≥0` to `ℝ≥0∞`. -/
@[coe, match_pattern] def ofNNReal : ℝ≥0 → ℝ≥0∞ := WithTop.some
instance : Coe ℝ≥0 ℝ≥0∞ := ⟨ofNNReal⟩
/-- A version of `WithTop.recTopCoe` that uses `ENNReal.ofNNReal`. -/
@[elab_as_elim, induction_eliminator, cases_eliminator]
def recTopCoe {C : ℝ≥0∞ → Sort*} (top : C ∞) (coe : ∀ x : ℝ≥0, C x) (x : ℝ≥0∞) : C x :=
WithTop.recTopCoe top coe x
instance canLift : CanLift ℝ≥0∞ ℝ≥0 ofNNReal (· ≠ ∞) := WithTop.canLift
@[simp] theorem none_eq_top : (none : ℝ≥0∞) = ∞ := rfl
@[simp] theorem some_eq_coe (a : ℝ≥0) : (Option.some a : ℝ≥0∞) = (↑a : ℝ≥0∞) := rfl
@[simp] theorem some_eq_coe' (a : ℝ≥0) : (WithTop.some a : ℝ≥0∞) = (↑a : ℝ≥0∞) := rfl
lemma coe_injective : Injective ((↑) : ℝ≥0 → ℝ≥0∞) := WithTop.coe_injective
@[simp, norm_cast] lemma coe_inj : (p : ℝ≥0∞) = q ↔ p = q := coe_injective.eq_iff
lemma coe_ne_coe : (p : ℝ≥0∞) ≠ q ↔ p ≠ q := coe_inj.not
theorem range_coe' : range ofNNReal = Iio ∞ := WithTop.range_coe
theorem range_coe : range ofNNReal = {∞}ᶜ := (isCompl_range_some_none ℝ≥0).symm.compl_eq.symm
instance : NNRatCast ℝ≥0∞ where
nnratCast r := ofNNReal r
@[norm_cast]
theorem coe_nnratCast (q : ℚ≥0) : ↑(q : ℝ≥0) = (q : ℝ≥0∞) := rfl
/-- `toNNReal x` returns `x` if it is real, otherwise 0. -/
protected def toNNReal : ℝ≥0∞ → ℝ≥0 := WithTop.untopD 0
/-- `toReal x` returns `x` if it is real, `0` otherwise. -/
protected def toReal (a : ℝ≥0∞) : Real := a.toNNReal
/-- `ofReal x` returns `x` if it is nonnegative, `0` otherwise. -/
protected def ofReal (r : Real) : ℝ≥0∞ := r.toNNReal
|
@[simp, norm_cast] lemma toNNReal_coe (r : ℝ≥0) : (r : ℝ≥0∞).toNNReal = r := rfl
| Mathlib/Data/ENNReal/Basic.lean | 212 | 213 |
/-
Copyright (c) 2021 Bhavik Mehta. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Bhavik Mehta, Alena Gusakov, Yaël Dillies
-/
import Mathlib.Data.Finset.Grade
import Mathlib.Data.Finset.Sups
import Mathlib.Logic.Function.Iterate
/-!
# Shadows
This file defines shadows of a set family. The shadow of a set family is the set family of sets we
get by removing any element from any set of the original family. If one pictures `Finset α` as a big
hypercube (each dimension being membership of a given element), then taking the shadow corresponds
to projecting each finset down once in all available directions.
## Main definitions
* `Finset.shadow`: The shadow of a set family. Everything we can get by removing a new element from
some set.
* `Finset.upShadow`: The upper shadow of a set family. Everything we can get by adding an element
to some set.
## Notation
We define notation in locale `FinsetFamily`:
* `∂ 𝒜`: Shadow of `𝒜`.
* `∂⁺ 𝒜`: Upper shadow of `𝒜`.
We also maintain the convention that `a, b : α` are elements of the ground type, `s, t : Finset α`
are finsets, and `𝒜, ℬ : Finset (Finset α)` are finset families.
## References
* https://github.com/b-mehta/maths-notes/blob/master/iii/mich/combinatorics.pdf
* http://discretemath.imp.fu-berlin.de/DMII-2015-16/kruskal.pdf
## Tags
shadow, set family
-/
open Finset Nat
variable {α : Type*}
namespace Finset
section Shadow
variable [DecidableEq α] {𝒜 ℬ : Finset (Finset α)} {s t : Finset α} {a : α} {k r : ℕ}
/-- The shadow of a set family `𝒜` is all sets we can get by removing one element from any set in
`𝒜`, and the (`k` times) iterated shadow (`shadow^[k]`) is all sets we can get by removing `k`
elements from any set in `𝒜`. -/
def shadow (𝒜 : Finset (Finset α)) : Finset (Finset α) :=
𝒜.sup fun s => s.image (erase s)
@[inherit_doc] scoped[FinsetFamily] notation:max "∂ " => Finset.shadow
open FinsetFamily
/-- The shadow of the empty set is empty. -/
@[simp]
theorem shadow_empty : ∂ (∅ : Finset (Finset α)) = ∅ :=
rfl
@[simp] lemma shadow_iterate_empty (k : ℕ) : ∂^[k] (∅ : Finset (Finset α)) = ∅ := by
induction k <;> simp [*, shadow_empty]
@[simp]
theorem shadow_singleton_empty : ∂ ({∅} : Finset (Finset α)) = ∅ :=
rfl
@[simp]
theorem shadow_singleton (a : α) : ∂ {{a}} = {∅} := by
simp [shadow]
/-- The shadow is monotone. -/
@[mono]
theorem shadow_monotone : Monotone (shadow : Finset (Finset α) → Finset (Finset α)) := fun _ _ =>
sup_mono
@[gcongr] lemma shadow_mono (h𝒜ℬ : 𝒜 ⊆ ℬ) : ∂ 𝒜 ⊆ ∂ ℬ := shadow_monotone h𝒜ℬ
/-- `t` is in the shadow of `𝒜` iff there is a `s ∈ 𝒜` from which we can remove one element to
get `t`. -/
lemma mem_shadow_iff : t ∈ ∂ 𝒜 ↔ ∃ s ∈ 𝒜, ∃ a ∈ s, erase s a = t := by
simp only [shadow, mem_sup, mem_image]
theorem erase_mem_shadow (hs : s ∈ 𝒜) (ha : a ∈ s) : erase s a ∈ ∂ 𝒜 :=
mem_shadow_iff.2 ⟨s, hs, a, ha, rfl⟩
/-- `t ∈ ∂𝒜` iff `t` is exactly one element less than something from `𝒜`.
See also `Finset.mem_shadow_iff_exists_mem_card_add_one`. -/
lemma mem_shadow_iff_exists_sdiff : t ∈ ∂ 𝒜 ↔ ∃ s ∈ 𝒜, t ⊆ s ∧ #(s \ t) = 1 := by
simp_rw [mem_shadow_iff, ← covBy_iff_card_sdiff_eq_one, covBy_iff_exists_erase]
/-- `t` is in the shadow of `𝒜` iff we can add an element to it so that the resulting finset is in
`𝒜`. -/
lemma mem_shadow_iff_insert_mem : t ∈ ∂ 𝒜 ↔ ∃ a ∉ t, insert a t ∈ 𝒜 := by
simp_rw [mem_shadow_iff_exists_sdiff, ← covBy_iff_card_sdiff_eq_one, covBy_iff_exists_insert]
aesop
/-- `s ∈ ∂ 𝒜` iff `s` is exactly one element less than something from `𝒜`.
See also `Finset.mem_shadow_iff_exists_sdiff`. -/
lemma mem_shadow_iff_exists_mem_card_add_one : t ∈ ∂ 𝒜 ↔ ∃ s ∈ 𝒜, t ⊆ s ∧ #s = #t + 1 := by
refine mem_shadow_iff_exists_sdiff.trans <| exists_congr fun t ↦ and_congr_right fun _ ↦
and_congr_right fun hst ↦ ?_
rw [card_sdiff hst, tsub_eq_iff_eq_add_of_le, add_comm]
exact card_mono hst
lemma mem_shadow_iterate_iff_exists_card :
t ∈ ∂^[k] 𝒜 ↔ ∃ u : Finset α, #u = k ∧ Disjoint t u ∧ t ∪ u ∈ 𝒜 := by
induction k generalizing t with
| zero => simp
| succ k ih =>
simp only [mem_shadow_iff_insert_mem, ih, Function.iterate_succ_apply', card_eq_succ]
aesop
/-- `t ∈ ∂^k 𝒜` iff `t` is exactly `k` elements less than something from `𝒜`.
See also `Finset.mem_shadow_iff_exists_mem_card_add`. -/
lemma mem_shadow_iterate_iff_exists_sdiff : t ∈ ∂^[k] 𝒜 ↔ ∃ s ∈ 𝒜, t ⊆ s ∧ #(s \ t) = k := by
rw [mem_shadow_iterate_iff_exists_card]
constructor
· rintro ⟨u, rfl, htu, hsuA⟩
exact ⟨_, hsuA, subset_union_left, by rw [union_sdiff_cancel_left htu]⟩
· rintro ⟨s, hs, hts, rfl⟩
refine ⟨s \ t, rfl, disjoint_sdiff, ?_⟩
rwa [union_sdiff_self_eq_union, union_eq_right.2 hts]
/-- `t ∈ ∂^k 𝒜` iff `t` is exactly `k` elements less than something in `𝒜`.
See also `Finset.mem_shadow_iterate_iff_exists_sdiff`. -/
lemma mem_shadow_iterate_iff_exists_mem_card_add :
t ∈ ∂^[k] 𝒜 ↔ ∃ s ∈ 𝒜, t ⊆ s ∧ #s = #t + k := by
refine mem_shadow_iterate_iff_exists_sdiff.trans <| exists_congr fun t ↦ and_congr_right fun _ ↦
and_congr_right fun hst ↦ ?_
rw [card_sdiff hst, tsub_eq_iff_eq_add_of_le, add_comm]
exact card_mono hst
/-- The shadow of a family of `r`-sets is a family of `r - 1`-sets. -/
protected theorem _root_.Set.Sized.shadow (h𝒜 : (𝒜 : Set (Finset α)).Sized r) :
(∂ 𝒜 : Set (Finset α)).Sized (r - 1) := by
intro A h
obtain ⟨A, hA, i, hi, rfl⟩ := mem_shadow_iff.1 h
rw [card_erase_of_mem hi, h𝒜 hA]
/-- The `k`-th shadow of a family of `r`-sets is a family of `r - k`-sets. -/
lemma _root_.Set.Sized.shadow_iterate (h𝒜 : (𝒜 : Set (Finset α)).Sized r) :
(∂^[k] 𝒜 : Set (Finset α)).Sized (r - k) := by
simp_rw [Set.Sized, mem_coe, mem_shadow_iterate_iff_exists_sdiff]
rintro t ⟨s, hs, hts, rfl⟩
rw [card_sdiff hts, ← h𝒜 hs, Nat.sub_sub_self (card_le_card hts)]
theorem sized_shadow_iff (h : ∅ ∉ 𝒜) :
(∂ 𝒜 : Set (Finset α)).Sized r ↔ (𝒜 : Set (Finset α)).Sized (r + 1) := by
refine ⟨fun h𝒜 s hs => ?_, Set.Sized.shadow⟩
obtain ⟨a, ha⟩ := nonempty_iff_ne_empty.2 (ne_of_mem_of_not_mem hs h)
rw [← h𝒜 (erase_mem_shadow hs ha), card_erase_add_one ha]
/-- Being in the shadow of `𝒜` means we have a superset in `𝒜`. -/
lemma exists_subset_of_mem_shadow (hs : t ∈ ∂ 𝒜) : ∃ s ∈ 𝒜, t ⊆ s :=
let ⟨t, ht, hst⟩ := mem_shadow_iff_exists_mem_card_add_one.1 hs
⟨t, ht, hst.1⟩
end Shadow
open FinsetFamily
section UpShadow
variable [DecidableEq α] [Fintype α] {𝒜 : Finset (Finset α)} {s t : Finset α} {a : α} {k r : ℕ}
/-- The upper shadow of a set family `𝒜` is all sets we can get by adding one element to any set in
`𝒜`, and the (`k` times) iterated upper shadow (`upShadow^[k]`) is all sets we can get by adding
`k` elements from any set in `𝒜`. -/
def upShadow (𝒜 : Finset (Finset α)) : Finset (Finset α) :=
𝒜.sup fun s => sᶜ.image fun a => insert a s
@[inherit_doc] scoped[FinsetFamily] notation:max "∂⁺ " => Finset.upShadow
/-- The upper shadow of the empty set is empty. -/
@[simp]
theorem upShadow_empty : ∂⁺ (∅ : Finset (Finset α)) = ∅ :=
rfl
/-- The upper shadow is monotone. -/
@[mono]
theorem upShadow_monotone : Monotone (upShadow : Finset (Finset α) → Finset (Finset α)) :=
fun _ _ => sup_mono
/-- `t` is in the upper shadow of `𝒜` iff there is a `s ∈ 𝒜` from which we can remove one element
to get `t`. -/
lemma mem_upShadow_iff : t ∈ ∂⁺ 𝒜 ↔ ∃ s ∈ 𝒜, ∃ a ∉ s, insert a s = t := by
simp_rw [upShadow, mem_sup, mem_image, mem_compl]
theorem insert_mem_upShadow (hs : s ∈ 𝒜) (ha : a ∉ s) : insert a s ∈ ∂⁺ 𝒜 :=
mem_upShadow_iff.2 ⟨s, hs, a, ha, rfl⟩
/-- `t` is in the upper shadow of `𝒜` iff `t` is exactly one element more than something from `𝒜`.
See also `Finset.mem_upShadow_iff_exists_mem_card_add_one`. -/
lemma mem_upShadow_iff_exists_sdiff : t ∈ ∂⁺ 𝒜 ↔ ∃ s ∈ 𝒜, s ⊆ t ∧ #(t \ s) = 1 := by
simp_rw [mem_upShadow_iff, ← covBy_iff_card_sdiff_eq_one, covBy_iff_exists_insert]
/-- `t` is in the upper shadow of `𝒜` iff we can remove an element from it so that the resulting
finset is in `𝒜`. -/
lemma mem_upShadow_iff_erase_mem : t ∈ ∂⁺ 𝒜 ↔ ∃ a, a ∈ t ∧ erase t a ∈ 𝒜 := by
simp_rw [mem_upShadow_iff_exists_sdiff, ← covBy_iff_card_sdiff_eq_one, covBy_iff_exists_erase]
aesop
/-- `t` is in the upper shadow of `𝒜` iff `t` is exactly one element less than something from `𝒜`.
See also `Finset.mem_upShadow_iff_exists_sdiff`. -/
lemma mem_upShadow_iff_exists_mem_card_add_one :
t ∈ ∂⁺ 𝒜 ↔ ∃ s ∈ 𝒜, s ⊆ t ∧ #t = #s + 1 := by
refine mem_upShadow_iff_exists_sdiff.trans <| exists_congr fun t ↦ and_congr_right fun _ ↦
and_congr_right fun hst ↦ ?_
rw [card_sdiff hst, tsub_eq_iff_eq_add_of_le, add_comm]
exact card_mono hst
lemma mem_upShadow_iterate_iff_exists_card :
t ∈ ∂⁺^[k] 𝒜 ↔ ∃ u : Finset α, #u = k ∧ u ⊆ t ∧ t \ u ∈ 𝒜 := by
induction k generalizing t with
| zero => simp
| succ k ih =>
simp only [mem_upShadow_iff_erase_mem, ih, Function.iterate_succ_apply', card_eq_succ,
subset_erase, erase_sdiff_comm, ← sdiff_insert]
constructor
· rintro ⟨a, hat, u, rfl, ⟨hut, hau⟩, htu⟩
exact ⟨_, ⟨_, _, hau, rfl, rfl⟩, insert_subset hat hut, htu⟩
· rintro ⟨_, ⟨a, u, hau, rfl, rfl⟩, hut, htu⟩
rw [insert_subset_iff] at hut
exact ⟨a, hut.1, _, rfl, ⟨hut.2, hau⟩, htu⟩
/-- `t` is in the upper shadow of `𝒜` iff `t` is exactly `k` elements less than something from `𝒜`.
See also `Finset.mem_upShadow_iff_exists_mem_card_add`. -/
lemma mem_upShadow_iterate_iff_exists_sdiff : t ∈ ∂⁺^[k] 𝒜 ↔ ∃ s ∈ 𝒜, s ⊆ t ∧ #(t \ s) = k := by
rw [mem_upShadow_iterate_iff_exists_card]
| constructor
· rintro ⟨u, rfl, hut, htu⟩
exact ⟨_, htu, sdiff_subset, by rw [sdiff_sdiff_eq_self hut]⟩
· rintro ⟨s, hs, hst, rfl⟩
exact ⟨_, rfl, sdiff_subset, by rwa [sdiff_sdiff_eq_self hst]⟩
/-- `t ∈ ∂⁺^k 𝒜` iff `t` is exactly `k` elements less than something in `𝒜`.
See also `Finset.mem_upShadow_iterate_iff_exists_sdiff`. -/
lemma mem_upShadow_iterate_iff_exists_mem_card_add :
t ∈ ∂⁺^[k] 𝒜 ↔ ∃ s ∈ 𝒜, s ⊆ t ∧ #t = #s + k := by
refine mem_upShadow_iterate_iff_exists_sdiff.trans <| exists_congr fun t ↦ and_congr_right fun _ ↦
| Mathlib/Combinatorics/SetFamily/Shadow.lean | 247 | 258 |
/-
Copyright (c) 2021 Rémy Degenne. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Zhouhang Zhou, Yury Kudryashov, Sébastien Gouëzel, Rémy Degenne
-/
import Mathlib.MeasureTheory.Integral.FinMeasAdditive
/-!
# Extension of a linear function from indicators to L1
Given `T : Set α → E →L[ℝ] F` with `DominatedFinMeasAdditive μ T C`, we construct an extension
of `T` to integrable simple functions, which are finite sums of indicators of measurable sets
with finite measure, then to integrable functions, which are limits of integrable simple functions.
The main result is a continuous linear map `(α →₁[μ] E) →L[ℝ] F`.
This extension process is used to define the Bochner integral
in the `Mathlib.MeasureTheory.Integral.Bochner.Basic` file
and the conditional expectation of an integrable function
in `Mathlib.MeasureTheory.Function.ConditionalExpectation.CondexpL1`.
## Main definitions
- `setToL1 (hT : DominatedFinMeasAdditive μ T C) : (α →₁[μ] E) →L[ℝ] F`: the extension of `T`
from indicators to L1.
- `setToFun μ T (hT : DominatedFinMeasAdditive μ T C) (f : α → E) : F`: a version of the
extension which applies to functions (with value 0 if the function is not integrable).
## Properties
For most properties of `setToFun`, we provide two lemmas. One version uses hypotheses valid on
all sets, like `T = T'`, and a second version which uses a primed name uses hypotheses on
measurable sets with finite measure, like `∀ s, MeasurableSet s → μ s < ∞ → T s = T' s`.
The lemmas listed here don't show all hypotheses. Refer to the actual lemmas for details.
Linearity:
- `setToFun_zero_left : setToFun μ 0 hT f = 0`
- `setToFun_add_left : setToFun μ (T + T') _ f = setToFun μ T hT f + setToFun μ T' hT' f`
- `setToFun_smul_left : setToFun μ (fun s ↦ c • (T s)) (hT.smul c) f = c • setToFun μ T hT f`
- `setToFun_zero : setToFun μ T hT (0 : α → E) = 0`
- `setToFun_neg : setToFun μ T hT (-f) = - setToFun μ T hT f`
If `f` and `g` are integrable:
- `setToFun_add : setToFun μ T hT (f + g) = setToFun μ T hT f + setToFun μ T hT g`
- `setToFun_sub : setToFun μ T hT (f - g) = setToFun μ T hT f - setToFun μ T hT g`
If `T` is verifies `∀ c : 𝕜, ∀ s x, T s (c • x) = c • T s x`:
- `setToFun_smul : setToFun μ T hT (c • f) = c • setToFun μ T hT f`
Other:
- `setToFun_congr_ae (h : f =ᵐ[μ] g) : setToFun μ T hT f = setToFun μ T hT g`
- `setToFun_measure_zero (h : μ = 0) : setToFun μ T hT f = 0`
If the space is also an ordered additive group with an order closed topology and `T` is such that
`0 ≤ T s x` for `0 ≤ x`, we also prove order-related properties:
- `setToFun_mono_left (h : ∀ s x, T s x ≤ T' s x) : setToFun μ T hT f ≤ setToFun μ T' hT' f`
- `setToFun_nonneg (hf : 0 ≤ᵐ[μ] f) : 0 ≤ setToFun μ T hT f`
- `setToFun_mono (hfg : f ≤ᵐ[μ] g) : setToFun μ T hT f ≤ setToFun μ T hT g`
-/
noncomputable section
open scoped Topology NNReal
open Set Filter TopologicalSpace ENNReal
namespace MeasureTheory
variable {α E F F' G 𝕜 : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E]
[NormedAddCommGroup F] [NormedSpace ℝ F] [NormedAddCommGroup F'] [NormedSpace ℝ F']
[NormedAddCommGroup G] {m : MeasurableSpace α} {μ : Measure α}
namespace L1
open AEEqFun Lp.simpleFunc Lp
namespace SimpleFunc
theorem norm_eq_sum_mul (f : α →₁ₛ[μ] G) :
‖f‖ = ∑ x ∈ (toSimpleFunc f).range, μ.real (toSimpleFunc f ⁻¹' {x}) * ‖x‖ := by
rw [norm_toSimpleFunc, eLpNorm_one_eq_lintegral_enorm]
have h_eq := SimpleFunc.map_apply (‖·‖ₑ) (toSimpleFunc f)
simp_rw [← h_eq, measureReal_def]
rw [SimpleFunc.lintegral_eq_lintegral, SimpleFunc.map_lintegral, ENNReal.toReal_sum]
· congr
ext1 x
rw [ENNReal.toReal_mul, mul_comm, ← ofReal_norm_eq_enorm,
ENNReal.toReal_ofReal (norm_nonneg _)]
· intro x _
by_cases hx0 : x = 0
· rw [hx0]; simp
· exact
ENNReal.mul_ne_top ENNReal.coe_ne_top
(SimpleFunc.measure_preimage_lt_top_of_integrable _ (SimpleFunc.integrable f) hx0).ne
section SetToL1S
variable [NormedField 𝕜] [NormedSpace 𝕜 E]
attribute [local instance] Lp.simpleFunc.module
attribute [local instance] Lp.simpleFunc.normedSpace
/-- Extend `Set α → (E →L[ℝ] F')` to `(α →₁ₛ[μ] E) → F'`. -/
def setToL1S (T : Set α → E →L[ℝ] F) (f : α →₁ₛ[μ] E) : F :=
(toSimpleFunc f).setToSimpleFunc T
theorem setToL1S_eq_setToSimpleFunc (T : Set α → E →L[ℝ] F) (f : α →₁ₛ[μ] E) :
setToL1S T f = (toSimpleFunc f).setToSimpleFunc T :=
rfl
@[simp]
theorem setToL1S_zero_left (f : α →₁ₛ[μ] E) : setToL1S (0 : Set α → E →L[ℝ] F) f = 0 :=
SimpleFunc.setToSimpleFunc_zero _
theorem setToL1S_zero_left' {T : Set α → E →L[ℝ] F}
(h_zero : ∀ s, MeasurableSet s → μ s < ∞ → T s = 0) (f : α →₁ₛ[μ] E) : setToL1S T f = 0 :=
SimpleFunc.setToSimpleFunc_zero' h_zero _ (SimpleFunc.integrable f)
theorem setToL1S_congr (T : Set α → E →L[ℝ] F) (h_zero : ∀ s, MeasurableSet s → μ s = 0 → T s = 0)
(h_add : FinMeasAdditive μ T) {f g : α →₁ₛ[μ] E} (h : toSimpleFunc f =ᵐ[μ] toSimpleFunc g) :
setToL1S T f = setToL1S T g :=
SimpleFunc.setToSimpleFunc_congr T h_zero h_add (SimpleFunc.integrable f) h
theorem setToL1S_congr_left (T T' : Set α → E →L[ℝ] F)
(h : ∀ s, MeasurableSet s → μ s < ∞ → T s = T' s) (f : α →₁ₛ[μ] E) :
setToL1S T f = setToL1S T' f :=
SimpleFunc.setToSimpleFunc_congr_left T T' h (simpleFunc.toSimpleFunc f) (SimpleFunc.integrable f)
/-- `setToL1S` does not change if we replace the measure `μ` by `μ'` with `μ ≪ μ'`. The statement
uses two functions `f` and `f'` because they have to belong to different types, but morally these
are the same function (we have `f =ᵐ[μ] f'`). -/
theorem setToL1S_congr_measure {μ' : Measure α} (T : Set α → E →L[ℝ] F)
(h_zero : ∀ s, MeasurableSet s → μ s = 0 → T s = 0) (h_add : FinMeasAdditive μ T) (hμ : μ ≪ μ')
(f : α →₁ₛ[μ] E) (f' : α →₁ₛ[μ'] E) (h : (f : α → E) =ᵐ[μ] f') :
setToL1S T f = setToL1S T f' := by
refine SimpleFunc.setToSimpleFunc_congr T h_zero h_add (SimpleFunc.integrable f) ?_
refine (toSimpleFunc_eq_toFun f).trans ?_
suffices (f' : α → E) =ᵐ[μ] simpleFunc.toSimpleFunc f' from h.trans this
have goal' : (f' : α → E) =ᵐ[μ'] simpleFunc.toSimpleFunc f' := (toSimpleFunc_eq_toFun f').symm
exact hμ.ae_eq goal'
theorem setToL1S_add_left (T T' : Set α → E →L[ℝ] F) (f : α →₁ₛ[μ] E) :
setToL1S (T + T') f = setToL1S T f + setToL1S T' f :=
SimpleFunc.setToSimpleFunc_add_left T T'
theorem setToL1S_add_left' (T T' T'' : Set α → E →L[ℝ] F)
(h_add : ∀ s, MeasurableSet s → μ s < ∞ → T'' s = T s + T' s) (f : α →₁ₛ[μ] E) :
setToL1S T'' f = setToL1S T f + setToL1S T' f :=
SimpleFunc.setToSimpleFunc_add_left' T T' T'' h_add (SimpleFunc.integrable f)
theorem setToL1S_smul_left (T : Set α → E →L[ℝ] F) (c : ℝ) (f : α →₁ₛ[μ] E) :
setToL1S (fun s => c • T s) f = c • setToL1S T f :=
SimpleFunc.setToSimpleFunc_smul_left T c _
theorem setToL1S_smul_left' (T T' : Set α → E →L[ℝ] F) (c : ℝ)
(h_smul : ∀ s, MeasurableSet s → μ s < ∞ → T' s = c • T s) (f : α →₁ₛ[μ] E) :
setToL1S T' f = c • setToL1S T f :=
SimpleFunc.setToSimpleFunc_smul_left' T T' c h_smul (SimpleFunc.integrable f)
theorem setToL1S_add (T : Set α → E →L[ℝ] F) (h_zero : ∀ s, MeasurableSet s → μ s = 0 → T s = 0)
(h_add : FinMeasAdditive μ T) (f g : α →₁ₛ[μ] E) :
setToL1S T (f + g) = setToL1S T f + setToL1S T g := by
simp_rw [setToL1S]
rw [← SimpleFunc.setToSimpleFunc_add T h_add (SimpleFunc.integrable f)
(SimpleFunc.integrable g)]
exact
SimpleFunc.setToSimpleFunc_congr T h_zero h_add (SimpleFunc.integrable _)
(add_toSimpleFunc f g)
theorem setToL1S_neg {T : Set α → E →L[ℝ] F} (h_zero : ∀ s, MeasurableSet s → μ s = 0 → T s = 0)
(h_add : FinMeasAdditive μ T) (f : α →₁ₛ[μ] E) : setToL1S T (-f) = -setToL1S T f := by
simp_rw [setToL1S]
have : simpleFunc.toSimpleFunc (-f) =ᵐ[μ] ⇑(-simpleFunc.toSimpleFunc f) :=
neg_toSimpleFunc f
rw [SimpleFunc.setToSimpleFunc_congr T h_zero h_add (SimpleFunc.integrable _) this]
exact SimpleFunc.setToSimpleFunc_neg T h_add (SimpleFunc.integrable f)
theorem setToL1S_sub {T : Set α → E →L[ℝ] F} (h_zero : ∀ s, MeasurableSet s → μ s = 0 → T s = 0)
(h_add : FinMeasAdditive μ T) (f g : α →₁ₛ[μ] E) :
setToL1S T (f - g) = setToL1S T f - setToL1S T g := by
rw [sub_eq_add_neg, setToL1S_add T h_zero h_add, setToL1S_neg h_zero h_add, sub_eq_add_neg]
theorem setToL1S_smul_real (T : Set α → E →L[ℝ] F)
(h_zero : ∀ s, MeasurableSet s → μ s = 0 → T s = 0) (h_add : FinMeasAdditive μ T) (c : ℝ)
(f : α →₁ₛ[μ] E) : setToL1S T (c • f) = c • setToL1S T f := by
simp_rw [setToL1S]
rw [← SimpleFunc.setToSimpleFunc_smul_real T h_add c (SimpleFunc.integrable f)]
refine SimpleFunc.setToSimpleFunc_congr T h_zero h_add (SimpleFunc.integrable _) ?_
exact smul_toSimpleFunc c f
theorem setToL1S_smul {E} [NormedAddCommGroup E] [NormedSpace ℝ E] [NormedSpace 𝕜 E]
[DistribSMul 𝕜 F] (T : Set α → E →L[ℝ] F) (h_zero : ∀ s, MeasurableSet s → μ s = 0 → T s = 0)
(h_add : FinMeasAdditive μ T) (h_smul : ∀ c : 𝕜, ∀ s x, T s (c • x) = c • T s x) (c : 𝕜)
(f : α →₁ₛ[μ] E) : setToL1S T (c • f) = c • setToL1S T f := by
simp_rw [setToL1S]
rw [← SimpleFunc.setToSimpleFunc_smul T h_add h_smul c (SimpleFunc.integrable f)]
refine SimpleFunc.setToSimpleFunc_congr T h_zero h_add (SimpleFunc.integrable _) ?_
exact smul_toSimpleFunc c f
theorem norm_setToL1S_le (T : Set α → E →L[ℝ] F) {C : ℝ}
(hT_norm : ∀ s, MeasurableSet s → μ s < ∞ → ‖T s‖ ≤ C * μ.real s) (f : α →₁ₛ[μ] E) :
‖setToL1S T f‖ ≤ C * ‖f‖ := by
rw [setToL1S, norm_eq_sum_mul f]
exact
SimpleFunc.norm_setToSimpleFunc_le_sum_mul_norm_of_integrable T hT_norm _
(SimpleFunc.integrable f)
theorem setToL1S_indicatorConst {T : Set α → E →L[ℝ] F} {s : Set α}
(h_zero : ∀ s, MeasurableSet s → μ s = 0 → T s = 0) (h_add : FinMeasAdditive μ T)
(hs : MeasurableSet s) (hμs : μ s < ∞) (x : E) :
setToL1S T (simpleFunc.indicatorConst 1 hs hμs.ne x) = T s x := by
have h_empty : T ∅ = 0 := h_zero _ MeasurableSet.empty measure_empty
rw [setToL1S_eq_setToSimpleFunc]
refine Eq.trans ?_ (SimpleFunc.setToSimpleFunc_indicator T h_empty hs x)
refine SimpleFunc.setToSimpleFunc_congr T h_zero h_add (SimpleFunc.integrable _) ?_
exact toSimpleFunc_indicatorConst hs hμs.ne x
theorem setToL1S_const [IsFiniteMeasure μ] {T : Set α → E →L[ℝ] F}
(h_zero : ∀ s, MeasurableSet s → μ s = 0 → T s = 0) (h_add : FinMeasAdditive μ T) (x : E) :
setToL1S T (simpleFunc.indicatorConst 1 MeasurableSet.univ (measure_ne_top μ _) x) = T univ x :=
setToL1S_indicatorConst h_zero h_add MeasurableSet.univ (measure_lt_top _ _) x
section Order
variable {G'' G' : Type*}
[NormedAddCommGroup G'] [PartialOrder G'] [IsOrderedAddMonoid G'] [NormedSpace ℝ G']
[NormedAddCommGroup G''] [PartialOrder G''] [IsOrderedAddMonoid G''] [NormedSpace ℝ G'']
{T : Set α → G'' →L[ℝ] G'}
theorem setToL1S_mono_left {T T' : Set α → E →L[ℝ] G''} (hTT' : ∀ s x, T s x ≤ T' s x)
(f : α →₁ₛ[μ] E) : setToL1S T f ≤ setToL1S T' f :=
SimpleFunc.setToSimpleFunc_mono_left T T' hTT' _
theorem setToL1S_mono_left' {T T' : Set α → E →L[ℝ] G''}
(hTT' : ∀ s, MeasurableSet s → μ s < ∞ → ∀ x, T s x ≤ T' s x) (f : α →₁ₛ[μ] E) :
setToL1S T f ≤ setToL1S T' f :=
SimpleFunc.setToSimpleFunc_mono_left' T T' hTT' _ (SimpleFunc.integrable f)
omit [IsOrderedAddMonoid G''] in
theorem setToL1S_nonneg (h_zero : ∀ s, MeasurableSet s → μ s = 0 → T s = 0)
(h_add : FinMeasAdditive μ T)
(hT_nonneg : ∀ s, MeasurableSet s → μ s < ∞ → ∀ x, 0 ≤ x → 0 ≤ T s x) {f : α →₁ₛ[μ] G''}
(hf : 0 ≤ f) : 0 ≤ setToL1S T f := by
simp_rw [setToL1S]
obtain ⟨f', hf', hff'⟩ := exists_simpleFunc_nonneg_ae_eq hf
replace hff' : simpleFunc.toSimpleFunc f =ᵐ[μ] f' :=
(Lp.simpleFunc.toSimpleFunc_eq_toFun f).trans hff'
rw [SimpleFunc.setToSimpleFunc_congr _ h_zero h_add (SimpleFunc.integrable _) hff']
exact
SimpleFunc.setToSimpleFunc_nonneg' T hT_nonneg _ hf' ((SimpleFunc.integrable f).congr hff')
theorem setToL1S_mono (h_zero : ∀ s, MeasurableSet s → μ s = 0 → T s = 0)
(h_add : FinMeasAdditive μ T)
(hT_nonneg : ∀ s, MeasurableSet s → μ s < ∞ → ∀ x, 0 ≤ x → 0 ≤ T s x) {f g : α →₁ₛ[μ] G''}
(hfg : f ≤ g) : setToL1S T f ≤ setToL1S T g := by
rw [← sub_nonneg] at hfg ⊢
rw [← setToL1S_sub h_zero h_add]
exact setToL1S_nonneg h_zero h_add hT_nonneg hfg
end Order
variable [NormedSpace 𝕜 F]
variable (α E μ 𝕜)
/-- Extend `Set α → E →L[ℝ] F` to `(α →₁ₛ[μ] E) →L[𝕜] F`. -/
def setToL1SCLM' {T : Set α → E →L[ℝ] F} {C : ℝ} (hT : DominatedFinMeasAdditive μ T C)
(h_smul : ∀ c : 𝕜, ∀ s x, T s (c • x) = c • T s x) : (α →₁ₛ[μ] E) →L[𝕜] F :=
LinearMap.mkContinuous
⟨⟨setToL1S T, setToL1S_add T (fun _ => hT.eq_zero_of_measure_zero) hT.1⟩,
setToL1S_smul T (fun _ => hT.eq_zero_of_measure_zero) hT.1 h_smul⟩
C fun f => norm_setToL1S_le T hT.2 f
/-- Extend `Set α → E →L[ℝ] F` to `(α →₁ₛ[μ] E) →L[ℝ] F`. -/
def setToL1SCLM {T : Set α → E →L[ℝ] F} {C : ℝ} (hT : DominatedFinMeasAdditive μ T C) :
(α →₁ₛ[μ] E) →L[ℝ] F :=
LinearMap.mkContinuous
⟨⟨setToL1S T, setToL1S_add T (fun _ => hT.eq_zero_of_measure_zero) hT.1⟩,
setToL1S_smul_real T (fun _ => hT.eq_zero_of_measure_zero) hT.1⟩
C fun f => norm_setToL1S_le T hT.2 f
variable {α E μ 𝕜}
variable {T T' T'' : Set α → E →L[ℝ] F} {C C' C'' : ℝ}
@[simp]
theorem setToL1SCLM_zero_left (hT : DominatedFinMeasAdditive μ (0 : Set α → E →L[ℝ] F) C)
(f : α →₁ₛ[μ] E) : setToL1SCLM α E μ hT f = 0 :=
setToL1S_zero_left _
theorem setToL1SCLM_zero_left' (hT : DominatedFinMeasAdditive μ T C)
(h_zero : ∀ s, MeasurableSet s → μ s < ∞ → T s = 0) (f : α →₁ₛ[μ] E) :
setToL1SCLM α E μ hT f = 0 :=
setToL1S_zero_left' h_zero f
theorem setToL1SCLM_congr_left (hT : DominatedFinMeasAdditive μ T C)
(hT' : DominatedFinMeasAdditive μ T' C') (h : T = T') (f : α →₁ₛ[μ] E) :
setToL1SCLM α E μ hT f = setToL1SCLM α E μ hT' f :=
setToL1S_congr_left T T' (fun _ _ _ => by rw [h]) f
theorem setToL1SCLM_congr_left' (hT : DominatedFinMeasAdditive μ T C)
(hT' : DominatedFinMeasAdditive μ T' C') (h : ∀ s, MeasurableSet s → μ s < ∞ → T s = T' s)
(f : α →₁ₛ[μ] E) : setToL1SCLM α E μ hT f = setToL1SCLM α E μ hT' f :=
setToL1S_congr_left T T' h f
theorem setToL1SCLM_congr_measure {μ' : Measure α} (hT : DominatedFinMeasAdditive μ T C)
(hT' : DominatedFinMeasAdditive μ' T C') (hμ : μ ≪ μ') (f : α →₁ₛ[μ] E) (f' : α →₁ₛ[μ'] E)
(h : (f : α → E) =ᵐ[μ] f') : setToL1SCLM α E μ hT f = setToL1SCLM α E μ' hT' f' :=
setToL1S_congr_measure T (fun _ => hT.eq_zero_of_measure_zero) hT.1 hμ _ _ h
theorem setToL1SCLM_add_left (hT : DominatedFinMeasAdditive μ T C)
(hT' : DominatedFinMeasAdditive μ T' C') (f : α →₁ₛ[μ] E) :
setToL1SCLM α E μ (hT.add hT') f = setToL1SCLM α E μ hT f + setToL1SCLM α E μ hT' f :=
setToL1S_add_left T T' f
theorem setToL1SCLM_add_left' (hT : DominatedFinMeasAdditive μ T C)
(hT' : DominatedFinMeasAdditive μ T' C') (hT'' : DominatedFinMeasAdditive μ T'' C'')
(h_add : ∀ s, MeasurableSet s → μ s < ∞ → T'' s = T s + T' s) (f : α →₁ₛ[μ] E) :
setToL1SCLM α E μ hT'' f = setToL1SCLM α E μ hT f + setToL1SCLM α E μ hT' f :=
setToL1S_add_left' T T' T'' h_add f
theorem setToL1SCLM_smul_left (c : ℝ) (hT : DominatedFinMeasAdditive μ T C) (f : α →₁ₛ[μ] E) :
setToL1SCLM α E μ (hT.smul c) f = c • setToL1SCLM α E μ hT f :=
setToL1S_smul_left T c f
theorem setToL1SCLM_smul_left' (c : ℝ) (hT : DominatedFinMeasAdditive μ T C)
(hT' : DominatedFinMeasAdditive μ T' C')
(h_smul : ∀ s, MeasurableSet s → μ s < ∞ → T' s = c • T s) (f : α →₁ₛ[μ] E) :
setToL1SCLM α E μ hT' f = c • setToL1SCLM α E μ hT f :=
setToL1S_smul_left' T T' c h_smul f
theorem norm_setToL1SCLM_le {T : Set α → E →L[ℝ] F} {C : ℝ} (hT : DominatedFinMeasAdditive μ T C)
(hC : 0 ≤ C) : ‖setToL1SCLM α E μ hT‖ ≤ C :=
LinearMap.mkContinuous_norm_le _ hC _
theorem norm_setToL1SCLM_le' {T : Set α → E →L[ℝ] F} {C : ℝ} (hT : DominatedFinMeasAdditive μ T C) :
‖setToL1SCLM α E μ hT‖ ≤ max C 0 :=
LinearMap.mkContinuous_norm_le' _ _
theorem setToL1SCLM_const [IsFiniteMeasure μ] {T : Set α → E →L[ℝ] F} {C : ℝ}
(hT : DominatedFinMeasAdditive μ T C) (x : E) :
setToL1SCLM α E μ hT (simpleFunc.indicatorConst 1 MeasurableSet.univ (measure_ne_top μ _) x) =
T univ x :=
setToL1S_const (fun _ => hT.eq_zero_of_measure_zero) hT.1 x
section Order
variable {G' G'' : Type*}
[NormedAddCommGroup G''] [PartialOrder G''] [IsOrderedAddMonoid G''] [NormedSpace ℝ G'']
[NormedAddCommGroup G'] [PartialOrder G'] [IsOrderedAddMonoid G'] [NormedSpace ℝ G']
theorem setToL1SCLM_mono_left {T T' : Set α → E →L[ℝ] G''} {C C' : ℝ}
(hT : DominatedFinMeasAdditive μ T C) (hT' : DominatedFinMeasAdditive μ T' C')
(hTT' : ∀ s x, T s x ≤ T' s x) (f : α →₁ₛ[μ] E) :
setToL1SCLM α E μ hT f ≤ setToL1SCLM α E μ hT' f :=
SimpleFunc.setToSimpleFunc_mono_left T T' hTT' _
theorem setToL1SCLM_mono_left' {T T' : Set α → E →L[ℝ] G''} {C C' : ℝ}
(hT : DominatedFinMeasAdditive μ T C) (hT' : DominatedFinMeasAdditive μ T' C')
(hTT' : ∀ s, MeasurableSet s → μ s < ∞ → ∀ x, T s x ≤ T' s x) (f : α →₁ₛ[μ] E) :
setToL1SCLM α E μ hT f ≤ setToL1SCLM α E μ hT' f :=
SimpleFunc.setToSimpleFunc_mono_left' T T' hTT' _ (SimpleFunc.integrable f)
omit [IsOrderedAddMonoid G'] in
theorem setToL1SCLM_nonneg {T : Set α → G' →L[ℝ] G''} {C : ℝ} (hT : DominatedFinMeasAdditive μ T C)
(hT_nonneg : ∀ s, MeasurableSet s → μ s < ∞ → ∀ x, 0 ≤ x → 0 ≤ T s x) {f : α →₁ₛ[μ] G'}
(hf : 0 ≤ f) : 0 ≤ setToL1SCLM α G' μ hT f :=
setToL1S_nonneg (fun _ => hT.eq_zero_of_measure_zero) hT.1 hT_nonneg hf
theorem setToL1SCLM_mono {T : Set α → G' →L[ℝ] G''} {C : ℝ} (hT : DominatedFinMeasAdditive μ T C)
(hT_nonneg : ∀ s, MeasurableSet s → μ s < ∞ → ∀ x, 0 ≤ x → 0 ≤ T s x) {f g : α →₁ₛ[μ] G'}
(hfg : f ≤ g) : setToL1SCLM α G' μ hT f ≤ setToL1SCLM α G' μ hT g :=
setToL1S_mono (fun _ => hT.eq_zero_of_measure_zero) hT.1 hT_nonneg hfg
end Order
end SetToL1S
end SimpleFunc
open SimpleFunc
section SetToL1
attribute [local instance] Lp.simpleFunc.module
attribute [local instance] Lp.simpleFunc.normedSpace
variable (𝕜) [NontriviallyNormedField 𝕜] [NormedSpace 𝕜 E] [NormedSpace 𝕜 F] [CompleteSpace F]
{T T' T'' : Set α → E →L[ℝ] F} {C C' C'' : ℝ}
/-- Extend `Set α → (E →L[ℝ] F)` to `(α →₁[μ] E) →L[𝕜] F`. -/
def setToL1' (hT : DominatedFinMeasAdditive μ T C)
(h_smul : ∀ c : 𝕜, ∀ s x, T s (c • x) = c • T s x) : (α →₁[μ] E) →L[𝕜] F :=
(setToL1SCLM' α E 𝕜 μ hT h_smul).extend (coeToLp α E 𝕜) (simpleFunc.denseRange one_ne_top)
simpleFunc.isUniformInducing
variable {𝕜}
/-- Extend `Set α → E →L[ℝ] F` to `(α →₁[μ] E) →L[ℝ] F`. -/
def setToL1 (hT : DominatedFinMeasAdditive μ T C) : (α →₁[μ] E) →L[ℝ] F :=
(setToL1SCLM α E μ hT).extend (coeToLp α E ℝ) (simpleFunc.denseRange one_ne_top)
simpleFunc.isUniformInducing
theorem setToL1_eq_setToL1SCLM (hT : DominatedFinMeasAdditive μ T C) (f : α →₁ₛ[μ] E) :
setToL1 hT f = setToL1SCLM α E μ hT f :=
uniformly_extend_of_ind simpleFunc.isUniformInducing (simpleFunc.denseRange one_ne_top)
(setToL1SCLM α E μ hT).uniformContinuous _
theorem setToL1_eq_setToL1' (hT : DominatedFinMeasAdditive μ T C)
(h_smul : ∀ c : 𝕜, ∀ s x, T s (c • x) = c • T s x) (f : α →₁[μ] E) :
setToL1 hT f = setToL1' 𝕜 hT h_smul f :=
rfl
@[simp]
theorem setToL1_zero_left (hT : DominatedFinMeasAdditive μ (0 : Set α → E →L[ℝ] F) C)
(f : α →₁[μ] E) : setToL1 hT f = 0 := by
suffices setToL1 hT = 0 by rw [this]; simp
refine ContinuousLinearMap.extend_unique (setToL1SCLM α E μ hT) _ _ _ _ ?_
ext1 f
rw [setToL1SCLM_zero_left hT f, ContinuousLinearMap.zero_comp, ContinuousLinearMap.zero_apply]
theorem setToL1_zero_left' (hT : DominatedFinMeasAdditive μ T C)
(h_zero : ∀ s, MeasurableSet s → μ s < ∞ → T s = 0) (f : α →₁[μ] E) : setToL1 hT f = 0 := by
suffices setToL1 hT = 0 by rw [this]; simp
refine ContinuousLinearMap.extend_unique (setToL1SCLM α E μ hT) _ _ _ _ ?_
ext1 f
rw [setToL1SCLM_zero_left' hT h_zero f, ContinuousLinearMap.zero_comp,
ContinuousLinearMap.zero_apply]
theorem setToL1_congr_left (T T' : Set α → E →L[ℝ] F) {C C' : ℝ}
(hT : DominatedFinMeasAdditive μ T C) (hT' : DominatedFinMeasAdditive μ T' C') (h : T = T')
(f : α →₁[μ] E) : setToL1 hT f = setToL1 hT' f := by
suffices setToL1 hT = setToL1 hT' by rw [this]
refine ContinuousLinearMap.extend_unique (setToL1SCLM α E μ hT) _ _ _ _ ?_
ext1 f
suffices setToL1 hT' f = setToL1SCLM α E μ hT f by rw [← this]; simp [coeToLp]
rw [setToL1_eq_setToL1SCLM]
exact setToL1SCLM_congr_left hT' hT h.symm f
theorem setToL1_congr_left' (T T' : Set α → E →L[ℝ] F) {C C' : ℝ}
(hT : DominatedFinMeasAdditive μ T C) (hT' : DominatedFinMeasAdditive μ T' C')
(h : ∀ s, MeasurableSet s → μ s < ∞ → T s = T' s) (f : α →₁[μ] E) :
setToL1 hT f = setToL1 hT' f := by
suffices setToL1 hT = setToL1 hT' by rw [this]
refine ContinuousLinearMap.extend_unique (setToL1SCLM α E μ hT) _ _ _ _ ?_
ext1 f
suffices setToL1 hT' f = setToL1SCLM α E μ hT f by rw [← this]; simp [coeToLp]
rw [setToL1_eq_setToL1SCLM]
exact (setToL1SCLM_congr_left' hT hT' h f).symm
theorem setToL1_add_left (hT : DominatedFinMeasAdditive μ T C)
(hT' : DominatedFinMeasAdditive μ T' C') (f : α →₁[μ] E) :
setToL1 (hT.add hT') f = setToL1 hT f + setToL1 hT' f := by
suffices setToL1 (hT.add hT') = setToL1 hT + setToL1 hT' by
rw [this, ContinuousLinearMap.add_apply]
refine ContinuousLinearMap.extend_unique (setToL1SCLM α E μ (hT.add hT')) _ _ _ _ ?_
ext1 f
suffices setToL1 hT f + setToL1 hT' f = setToL1SCLM α E μ (hT.add hT') f by
rw [← this]; simp [coeToLp]
rw [setToL1_eq_setToL1SCLM, setToL1_eq_setToL1SCLM, setToL1SCLM_add_left hT hT']
theorem setToL1_add_left' (hT : DominatedFinMeasAdditive μ T C)
(hT' : DominatedFinMeasAdditive μ T' C') (hT'' : DominatedFinMeasAdditive μ T'' C'')
(h_add : ∀ s, MeasurableSet s → μ s < ∞ → T'' s = T s + T' s) (f : α →₁[μ] E) :
setToL1 hT'' f = setToL1 hT f + setToL1 hT' f := by
suffices setToL1 hT'' = setToL1 hT + setToL1 hT' by rw [this, ContinuousLinearMap.add_apply]
refine ContinuousLinearMap.extend_unique (setToL1SCLM α E μ hT'') _ _ _ _ ?_
ext1 f
suffices setToL1 hT f + setToL1 hT' f = setToL1SCLM α E μ hT'' f by rw [← this]; simp [coeToLp]
rw [setToL1_eq_setToL1SCLM, setToL1_eq_setToL1SCLM,
setToL1SCLM_add_left' hT hT' hT'' h_add]
theorem setToL1_smul_left (hT : DominatedFinMeasAdditive μ T C) (c : ℝ) (f : α →₁[μ] E) :
setToL1 (hT.smul c) f = c • setToL1 hT f := by
suffices setToL1 (hT.smul c) = c • setToL1 hT by rw [this, ContinuousLinearMap.smul_apply]
refine ContinuousLinearMap.extend_unique (setToL1SCLM α E μ (hT.smul c)) _ _ _ _ ?_
ext1 f
suffices c • setToL1 hT f = setToL1SCLM α E μ (hT.smul c) f by rw [← this]; simp [coeToLp]
rw [setToL1_eq_setToL1SCLM, setToL1SCLM_smul_left c hT]
theorem setToL1_smul_left' (hT : DominatedFinMeasAdditive μ T C)
(hT' : DominatedFinMeasAdditive μ T' C') (c : ℝ)
(h_smul : ∀ s, MeasurableSet s → μ s < ∞ → T' s = c • T s) (f : α →₁[μ] E) :
setToL1 hT' f = c • setToL1 hT f := by
suffices setToL1 hT' = c • setToL1 hT by rw [this, ContinuousLinearMap.smul_apply]
refine ContinuousLinearMap.extend_unique (setToL1SCLM α E μ hT') _ _ _ _ ?_
ext1 f
suffices c • setToL1 hT f = setToL1SCLM α E μ hT' f by rw [← this]; simp [coeToLp]
rw [setToL1_eq_setToL1SCLM, setToL1SCLM_smul_left' c hT hT' h_smul]
theorem setToL1_smul (hT : DominatedFinMeasAdditive μ T C)
(h_smul : ∀ c : 𝕜, ∀ s x, T s (c • x) = c • T s x) (c : 𝕜) (f : α →₁[μ] E) :
setToL1 hT (c • f) = c • setToL1 hT f := by
rw [setToL1_eq_setToL1' hT h_smul, setToL1_eq_setToL1' hT h_smul]
exact ContinuousLinearMap.map_smul _ _ _
theorem setToL1_simpleFunc_indicatorConst (hT : DominatedFinMeasAdditive μ T C) {s : Set α}
(hs : MeasurableSet s) (hμs : μ s < ∞) (x : E) :
setToL1 hT (simpleFunc.indicatorConst 1 hs hμs.ne x) = T s x := by
rw [setToL1_eq_setToL1SCLM]
exact setToL1S_indicatorConst (fun s => hT.eq_zero_of_measure_zero) hT.1 hs hμs x
theorem setToL1_indicatorConstLp (hT : DominatedFinMeasAdditive μ T C) {s : Set α}
(hs : MeasurableSet s) (hμs : μ s ≠ ∞) (x : E) :
setToL1 hT (indicatorConstLp 1 hs hμs x) = T s x := by
rw [← Lp.simpleFunc.coe_indicatorConst hs hμs x]
exact setToL1_simpleFunc_indicatorConst hT hs hμs.lt_top x
theorem setToL1_const [IsFiniteMeasure μ] (hT : DominatedFinMeasAdditive μ T C) (x : E) :
setToL1 hT (indicatorConstLp 1 MeasurableSet.univ (measure_ne_top _ _) x) = T univ x :=
setToL1_indicatorConstLp hT MeasurableSet.univ (measure_ne_top _ _) x
section Order
variable {G' G'' : Type*}
[NormedAddCommGroup G''] [PartialOrder G''] [OrderClosedTopology G''] [IsOrderedAddMonoid G'']
[NormedSpace ℝ G''] [CompleteSpace G'']
[NormedAddCommGroup G'] [PartialOrder G'] [NormedSpace ℝ G']
theorem setToL1_mono_left' {T T' : Set α → E →L[ℝ] G''} {C C' : ℝ}
(hT : DominatedFinMeasAdditive μ T C) (hT' : DominatedFinMeasAdditive μ T' C')
(hTT' : ∀ s, MeasurableSet s → μ s < ∞ → ∀ x, T s x ≤ T' s x) (f : α →₁[μ] E) :
setToL1 hT f ≤ setToL1 hT' f := by
induction f using Lp.induction (hp_ne_top := one_ne_top) with
| @indicatorConst c s hs hμs =>
rw [setToL1_simpleFunc_indicatorConst hT hs hμs, setToL1_simpleFunc_indicatorConst hT' hs hμs]
exact hTT' s hs hμs c
| @add f g hf hg _ hf_le hg_le =>
rw [(setToL1 hT).map_add, (setToL1 hT').map_add]
exact add_le_add hf_le hg_le
| isClosed => exact isClosed_le (setToL1 hT).continuous (setToL1 hT').continuous
theorem setToL1_mono_left {T T' : Set α → E →L[ℝ] G''} {C C' : ℝ}
(hT : DominatedFinMeasAdditive μ T C) (hT' : DominatedFinMeasAdditive μ T' C')
(hTT' : ∀ s x, T s x ≤ T' s x) (f : α →₁[μ] E) : setToL1 hT f ≤ setToL1 hT' f :=
setToL1_mono_left' hT hT' (fun s _ _ x => hTT' s x) f
theorem setToL1_nonneg {T : Set α → G' →L[ℝ] G''} {C : ℝ} (hT : DominatedFinMeasAdditive μ T C)
(hT_nonneg : ∀ s, MeasurableSet s → μ s < ∞ → ∀ x, 0 ≤ x → 0 ≤ T s x) {f : α →₁[μ] G'}
(hf : 0 ≤ f) : 0 ≤ setToL1 hT f := by
suffices ∀ f : { g : α →₁[μ] G' // 0 ≤ g }, 0 ≤ setToL1 hT f from
this (⟨f, hf⟩ : { g : α →₁[μ] G' // 0 ≤ g })
refine fun g =>
@isClosed_property { g : α →₁ₛ[μ] G' // 0 ≤ g } { g : α →₁[μ] G' // 0 ≤ g } _ _
(fun g => 0 ≤ setToL1 hT g)
(denseRange_coeSimpleFuncNonnegToLpNonneg 1 μ G' one_ne_top) ?_ ?_ g
· exact isClosed_le continuous_zero ((setToL1 hT).continuous.comp continuous_induced_dom)
· intro g
have : (coeSimpleFuncNonnegToLpNonneg 1 μ G' g : α →₁[μ] G') = (g : α →₁ₛ[μ] G') := rfl
rw [this, setToL1_eq_setToL1SCLM]
exact setToL1S_nonneg (fun s => hT.eq_zero_of_measure_zero) hT.1 hT_nonneg g.2
theorem setToL1_mono [IsOrderedAddMonoid G']
{T : Set α → G' →L[ℝ] G''} {C : ℝ} (hT : DominatedFinMeasAdditive μ T C)
(hT_nonneg : ∀ s, MeasurableSet s → μ s < ∞ → ∀ x, 0 ≤ x → 0 ≤ T s x) {f g : α →₁[μ] G'}
(hfg : f ≤ g) : setToL1 hT f ≤ setToL1 hT g := by
rw [← sub_nonneg] at hfg ⊢
rw [← (setToL1 hT).map_sub]
exact setToL1_nonneg hT hT_nonneg hfg
end Order
theorem norm_setToL1_le_norm_setToL1SCLM (hT : DominatedFinMeasAdditive μ T C) :
‖setToL1 hT‖ ≤ ‖setToL1SCLM α E μ hT‖ :=
calc
‖setToL1 hT‖ ≤ (1 : ℝ≥0) * ‖setToL1SCLM α E μ hT‖ := by
refine
ContinuousLinearMap.opNorm_extend_le (setToL1SCLM α E μ hT) (coeToLp α E ℝ)
(simpleFunc.denseRange one_ne_top) fun x => le_of_eq ?_
rw [NNReal.coe_one, one_mul]
simp [coeToLp]
_ = ‖setToL1SCLM α E μ hT‖ := by rw [NNReal.coe_one, one_mul]
theorem norm_setToL1_le_mul_norm (hT : DominatedFinMeasAdditive μ T C) (hC : 0 ≤ C)
(f : α →₁[μ] E) : ‖setToL1 hT f‖ ≤ C * ‖f‖ :=
calc
‖setToL1 hT f‖ ≤ ‖setToL1SCLM α E μ hT‖ * ‖f‖ :=
ContinuousLinearMap.le_of_opNorm_le _ (norm_setToL1_le_norm_setToL1SCLM hT) _
_ ≤ C * ‖f‖ := mul_le_mul (norm_setToL1SCLM_le hT hC) le_rfl (norm_nonneg _) hC
theorem norm_setToL1_le_mul_norm' (hT : DominatedFinMeasAdditive μ T C) (f : α →₁[μ] E) :
‖setToL1 hT f‖ ≤ max C 0 * ‖f‖ :=
calc
‖setToL1 hT f‖ ≤ ‖setToL1SCLM α E μ hT‖ * ‖f‖ :=
ContinuousLinearMap.le_of_opNorm_le _ (norm_setToL1_le_norm_setToL1SCLM hT) _
_ ≤ max C 0 * ‖f‖ :=
mul_le_mul (norm_setToL1SCLM_le' hT) le_rfl (norm_nonneg _) (le_max_right _ _)
theorem norm_setToL1_le (hT : DominatedFinMeasAdditive μ T C) (hC : 0 ≤ C) : ‖setToL1 hT‖ ≤ C :=
ContinuousLinearMap.opNorm_le_bound _ hC (norm_setToL1_le_mul_norm hT hC)
theorem norm_setToL1_le' (hT : DominatedFinMeasAdditive μ T C) : ‖setToL1 hT‖ ≤ max C 0 :=
ContinuousLinearMap.opNorm_le_bound _ (le_max_right _ _) (norm_setToL1_le_mul_norm' hT)
theorem setToL1_lipschitz (hT : DominatedFinMeasAdditive μ T C) :
LipschitzWith (Real.toNNReal C) (setToL1 hT) :=
(setToL1 hT).lipschitz.weaken (norm_setToL1_le' hT)
/-- If `fs i → f` in `L1`, then `setToL1 hT (fs i) → setToL1 hT f`. -/
theorem tendsto_setToL1 (hT : DominatedFinMeasAdditive μ T C) (f : α →₁[μ] E) {ι}
(fs : ι → α →₁[μ] E) {l : Filter ι} (hfs : Tendsto fs l (𝓝 f)) :
Tendsto (fun i => setToL1 hT (fs i)) l (𝓝 <| setToL1 hT f) :=
((setToL1 hT).continuous.tendsto _).comp hfs
end SetToL1
end L1
section Function
variable [CompleteSpace F] {T T' T'' : Set α → E →L[ℝ] F} {C C' C'' : ℝ} {f g : α → E}
variable (μ T)
open Classical in
/-- Extend `T : Set α → E →L[ℝ] F` to `(α → E) → F` (for integrable functions `α → E`). We set it to
0 if the function is not integrable. -/
def setToFun (hT : DominatedFinMeasAdditive μ T C) (f : α → E) : F :=
if hf : Integrable f μ then L1.setToL1 hT (hf.toL1 f) else 0
variable {μ T}
theorem setToFun_eq (hT : DominatedFinMeasAdditive μ T C) (hf : Integrable f μ) :
setToFun μ T hT f = L1.setToL1 hT (hf.toL1 f) :=
dif_pos hf
theorem L1.setToFun_eq_setToL1 (hT : DominatedFinMeasAdditive μ T C) (f : α →₁[μ] E) :
setToFun μ T hT f = L1.setToL1 hT f := by
rw [setToFun_eq hT (L1.integrable_coeFn f), Integrable.toL1_coeFn]
theorem setToFun_undef (hT : DominatedFinMeasAdditive μ T C) (hf : ¬Integrable f μ) :
setToFun μ T hT f = 0 :=
dif_neg hf
theorem setToFun_non_aestronglyMeasurable (hT : DominatedFinMeasAdditive μ T C)
(hf : ¬AEStronglyMeasurable f μ) : setToFun μ T hT f = 0 :=
setToFun_undef hT (not_and_of_not_left _ hf)
@[deprecated (since := "2025-04-09")]
alias setToFun_non_aEStronglyMeasurable := setToFun_non_aestronglyMeasurable
theorem setToFun_congr_left (hT : DominatedFinMeasAdditive μ T C)
(hT' : DominatedFinMeasAdditive μ T' C') (h : T = T') (f : α → E) :
setToFun μ T hT f = setToFun μ T' hT' f := by
by_cases hf : Integrable f μ
· simp_rw [setToFun_eq _ hf, L1.setToL1_congr_left T T' hT hT' h]
· simp_rw [setToFun_undef _ hf]
theorem setToFun_congr_left' (hT : DominatedFinMeasAdditive μ T C)
(hT' : DominatedFinMeasAdditive μ T' C') (h : ∀ s, MeasurableSet s → μ s < ∞ → T s = T' s)
(f : α → E) : setToFun μ T hT f = setToFun μ T' hT' f := by
by_cases hf : Integrable f μ
· simp_rw [setToFun_eq _ hf, L1.setToL1_congr_left' T T' hT hT' h]
· simp_rw [setToFun_undef _ hf]
theorem setToFun_add_left (hT : DominatedFinMeasAdditive μ T C)
(hT' : DominatedFinMeasAdditive μ T' C') (f : α → E) :
setToFun μ (T + T') (hT.add hT') f = setToFun μ T hT f + setToFun μ T' hT' f := by
by_cases hf : Integrable f μ
· simp_rw [setToFun_eq _ hf, L1.setToL1_add_left hT hT']
· simp_rw [setToFun_undef _ hf, add_zero]
theorem setToFun_add_left' (hT : DominatedFinMeasAdditive μ T C)
(hT' : DominatedFinMeasAdditive μ T' C') (hT'' : DominatedFinMeasAdditive μ T'' C'')
(h_add : ∀ s, MeasurableSet s → μ s < ∞ → T'' s = T s + T' s) (f : α → E) :
setToFun μ T'' hT'' f = setToFun μ T hT f + setToFun μ T' hT' f := by
by_cases hf : Integrable f μ
· simp_rw [setToFun_eq _ hf, L1.setToL1_add_left' hT hT' hT'' h_add]
· simp_rw [setToFun_undef _ hf, add_zero]
theorem setToFun_smul_left (hT : DominatedFinMeasAdditive μ T C) (c : ℝ) (f : α → E) :
setToFun μ (fun s => c • T s) (hT.smul c) f = c • setToFun μ T hT f := by
by_cases hf : Integrable f μ
· simp_rw [setToFun_eq _ hf, L1.setToL1_smul_left hT c]
· simp_rw [setToFun_undef _ hf, smul_zero]
theorem setToFun_smul_left' (hT : DominatedFinMeasAdditive μ T C)
(hT' : DominatedFinMeasAdditive μ T' C') (c : ℝ)
(h_smul : ∀ s, MeasurableSet s → μ s < ∞ → T' s = c • T s) (f : α → E) :
setToFun μ T' hT' f = c • setToFun μ T hT f := by
by_cases hf : Integrable f μ
· simp_rw [setToFun_eq _ hf, L1.setToL1_smul_left' hT hT' c h_smul]
· simp_rw [setToFun_undef _ hf, smul_zero]
@[simp]
theorem setToFun_zero (hT : DominatedFinMeasAdditive μ T C) : setToFun μ T hT (0 : α → E) = 0 := by
rw [Pi.zero_def, setToFun_eq hT (integrable_zero _ _ _)]
simp only [← Pi.zero_def]
rw [Integrable.toL1_zero, ContinuousLinearMap.map_zero]
@[simp]
theorem setToFun_zero_left {hT : DominatedFinMeasAdditive μ (0 : Set α → E →L[ℝ] F) C} :
setToFun μ 0 hT f = 0 := by
by_cases hf : Integrable f μ
· rw [setToFun_eq hT hf]; exact L1.setToL1_zero_left hT _
· exact setToFun_undef hT hf
theorem setToFun_zero_left' (hT : DominatedFinMeasAdditive μ T C)
(h_zero : ∀ s, MeasurableSet s → μ s < ∞ → T s = 0) : setToFun μ T hT f = 0 := by
by_cases hf : Integrable f μ
· rw [setToFun_eq hT hf]; exact L1.setToL1_zero_left' hT h_zero _
· exact setToFun_undef hT hf
theorem setToFun_add (hT : DominatedFinMeasAdditive μ T C) (hf : Integrable f μ)
(hg : Integrable g μ) : setToFun μ T hT (f + g) = setToFun μ T hT f + setToFun μ T hT g := by
rw [setToFun_eq hT (hf.add hg), setToFun_eq hT hf, setToFun_eq hT hg, Integrable.toL1_add,
(L1.setToL1 hT).map_add]
theorem setToFun_finset_sum' (hT : DominatedFinMeasAdditive μ T C) {ι} (s : Finset ι)
{f : ι → α → E} (hf : ∀ i ∈ s, Integrable (f i) μ) :
setToFun μ T hT (∑ i ∈ s, f i) = ∑ i ∈ s, setToFun μ T hT (f i) := by
classical
revert hf
refine Finset.induction_on s ?_ ?_
· intro _
simp only [setToFun_zero, Finset.sum_empty]
· intro i s his ih hf
simp only [his, Finset.sum_insert, not_false_iff]
rw [setToFun_add hT (hf i (Finset.mem_insert_self i s)) _]
· rw [ih fun i hi => hf i (Finset.mem_insert_of_mem hi)]
· convert integrable_finset_sum s fun i hi => hf i (Finset.mem_insert_of_mem hi) with x
simp
theorem setToFun_finset_sum (hT : DominatedFinMeasAdditive μ T C) {ι} (s : Finset ι) {f : ι → α → E}
(hf : ∀ i ∈ s, Integrable (f i) μ) :
(setToFun μ T hT fun a => ∑ i ∈ s, f i a) = ∑ i ∈ s, setToFun μ T hT (f i) := by
convert setToFun_finset_sum' hT s hf with a; simp
theorem setToFun_neg (hT : DominatedFinMeasAdditive μ T C) (f : α → E) :
setToFun μ T hT (-f) = -setToFun μ T hT f := by
by_cases hf : Integrable f μ
· rw [setToFun_eq hT hf, setToFun_eq hT hf.neg, Integrable.toL1_neg,
(L1.setToL1 hT).map_neg]
· rw [setToFun_undef hT hf, setToFun_undef hT, neg_zero]
rwa [← integrable_neg_iff] at hf
theorem setToFun_sub (hT : DominatedFinMeasAdditive μ T C) (hf : Integrable f μ)
(hg : Integrable g μ) : setToFun μ T hT (f - g) = setToFun μ T hT f - setToFun μ T hT g := by
rw [sub_eq_add_neg, sub_eq_add_neg, setToFun_add hT hf hg.neg, setToFun_neg hT g]
theorem setToFun_smul [NontriviallyNormedField 𝕜] [NormedSpace 𝕜 E] [NormedSpace 𝕜 F]
(hT : DominatedFinMeasAdditive μ T C) (h_smul : ∀ c : 𝕜, ∀ s x, T s (c • x) = c • T s x) (c : 𝕜)
(f : α → E) : setToFun μ T hT (c • f) = c • setToFun μ T hT f := by
by_cases hf : Integrable f μ
· rw [setToFun_eq hT hf, setToFun_eq hT, Integrable.toL1_smul',
L1.setToL1_smul hT h_smul c _]
· by_cases hr : c = 0
· rw [hr]; simp
· have hf' : ¬Integrable (c • f) μ := by rwa [integrable_smul_iff hr f]
rw [setToFun_undef hT hf, setToFun_undef hT hf', smul_zero]
theorem setToFun_congr_ae (hT : DominatedFinMeasAdditive μ T C) (h : f =ᵐ[μ] g) :
setToFun μ T hT f = setToFun μ T hT g := by
by_cases hfi : Integrable f μ
· have hgi : Integrable g μ := hfi.congr h
rw [setToFun_eq hT hfi, setToFun_eq hT hgi, (Integrable.toL1_eq_toL1_iff f g hfi hgi).2 h]
· have hgi : ¬Integrable g μ := by rw [integrable_congr h] at hfi; exact hfi
rw [setToFun_undef hT hfi, setToFun_undef hT hgi]
theorem setToFun_measure_zero (hT : DominatedFinMeasAdditive μ T C) (h : μ = 0) :
setToFun μ T hT f = 0 := by
have : f =ᵐ[μ] 0 := by simp [h, EventuallyEq]
rw [setToFun_congr_ae hT this, setToFun_zero]
theorem setToFun_measure_zero' (hT : DominatedFinMeasAdditive μ T C)
(h : ∀ s, MeasurableSet s → μ s < ∞ → μ s = 0) : setToFun μ T hT f = 0 :=
setToFun_zero_left' hT fun s hs hμs => hT.eq_zero_of_measure_zero hs (h s hs hμs)
theorem setToFun_toL1 (hT : DominatedFinMeasAdditive μ T C) (hf : Integrable f μ) :
setToFun μ T hT (hf.toL1 f) = setToFun μ T hT f :=
setToFun_congr_ae hT hf.coeFn_toL1
theorem setToFun_indicator_const (hT : DominatedFinMeasAdditive μ T C) {s : Set α}
(hs : MeasurableSet s) (hμs : μ s ≠ ∞) (x : E) :
setToFun μ T hT (s.indicator fun _ => x) = T s x := by
rw [setToFun_congr_ae hT (@indicatorConstLp_coeFn _ _ _ 1 _ _ _ hs hμs x).symm]
rw [L1.setToFun_eq_setToL1 hT]
exact L1.setToL1_indicatorConstLp hT hs hμs x
theorem setToFun_const [IsFiniteMeasure μ] (hT : DominatedFinMeasAdditive μ T C) (x : E) :
(setToFun μ T hT fun _ => x) = T univ x := by
have : (fun _ : α => x) = Set.indicator univ fun _ => x := (indicator_univ _).symm
rw [this]
exact setToFun_indicator_const hT MeasurableSet.univ (measure_ne_top _ _) x
section Order
variable {G' G'' : Type*}
[NormedAddCommGroup G''] [PartialOrder G''] [OrderClosedTopology G''] [IsOrderedAddMonoid G'']
[NormedSpace ℝ G''] [CompleteSpace G'']
[NormedAddCommGroup G'] [PartialOrder G'] [NormedSpace ℝ G']
theorem setToFun_mono_left' {T T' : Set α → E →L[ℝ] G''} {C C' : ℝ}
(hT : DominatedFinMeasAdditive μ T C) (hT' : DominatedFinMeasAdditive μ T' C')
(hTT' : ∀ s, MeasurableSet s → μ s < ∞ → ∀ x, T s x ≤ T' s x) (f : α → E) :
setToFun μ T hT f ≤ setToFun μ T' hT' f := by
by_cases hf : Integrable f μ
· simp_rw [setToFun_eq _ hf]; exact L1.setToL1_mono_left' hT hT' hTT' _
· simp_rw [setToFun_undef _ hf, le_rfl]
theorem setToFun_mono_left {T T' : Set α → E →L[ℝ] G''} {C C' : ℝ}
(hT : DominatedFinMeasAdditive μ T C) (hT' : DominatedFinMeasAdditive μ T' C')
(hTT' : ∀ s x, T s x ≤ T' s x) (f : α →₁[μ] E) : setToFun μ T hT f ≤ setToFun μ T' hT' f :=
setToFun_mono_left' hT hT' (fun s _ _ x => hTT' s x) f
theorem setToFun_nonneg {T : Set α → G' →L[ℝ] G''} {C : ℝ} (hT : DominatedFinMeasAdditive μ T C)
(hT_nonneg : ∀ s, MeasurableSet s → μ s < ∞ → ∀ x, 0 ≤ x → 0 ≤ T s x) {f : α → G'}
(hf : 0 ≤ᵐ[μ] f) : 0 ≤ setToFun μ T hT f := by
by_cases hfi : Integrable f μ
· simp_rw [setToFun_eq _ hfi]
refine L1.setToL1_nonneg hT hT_nonneg ?_
rw [← Lp.coeFn_le]
have h0 := Lp.coeFn_zero G' 1 μ
have h := Integrable.coeFn_toL1 hfi
filter_upwards [h0, h, hf] with _ h0a ha hfa
rw [h0a, ha]
exact hfa
· simp_rw [setToFun_undef _ hfi, le_rfl]
theorem setToFun_mono [IsOrderedAddMonoid G']
{T : Set α → G' →L[ℝ] G''} {C : ℝ} (hT : DominatedFinMeasAdditive μ T C)
(hT_nonneg : ∀ s, MeasurableSet s → μ s < ∞ → ∀ x, 0 ≤ x → 0 ≤ T s x) {f g : α → G'}
(hf : Integrable f μ) (hg : Integrable g μ) (hfg : f ≤ᵐ[μ] g) :
setToFun μ T hT f ≤ setToFun μ T hT g := by
rw [← sub_nonneg, ← setToFun_sub hT hg hf]
refine setToFun_nonneg hT hT_nonneg (hfg.mono fun a ha => ?_)
rw [Pi.sub_apply, Pi.zero_apply, sub_nonneg]
exact ha
end Order
@[continuity]
theorem continuous_setToFun (hT : DominatedFinMeasAdditive μ T C) :
Continuous fun f : α →₁[μ] E => setToFun μ T hT f := by
simp_rw [L1.setToFun_eq_setToL1 hT]; exact ContinuousLinearMap.continuous _
/-- If `F i → f` in `L1`, then `setToFun μ T hT (F i) → setToFun μ T hT f`. -/
theorem tendsto_setToFun_of_L1 (hT : DominatedFinMeasAdditive μ T C) {ι} (f : α → E)
(hfi : Integrable f μ) {fs : ι → α → E} {l : Filter ι} (hfsi : ∀ᶠ i in l, Integrable (fs i) μ)
(hfs : Tendsto (fun i => ∫⁻ x, ‖fs i x - f x‖ₑ ∂μ) l (𝓝 0)) :
Tendsto (fun i => setToFun μ T hT (fs i)) l (𝓝 <| setToFun μ T hT f) := by
classical
let f_lp := hfi.toL1 f
let F_lp i := if hFi : Integrable (fs i) μ then hFi.toL1 (fs i) else 0
have tendsto_L1 : Tendsto F_lp l (𝓝 f_lp) := by
rw [Lp.tendsto_Lp_iff_tendsto_eLpNorm']
simp_rw [eLpNorm_one_eq_lintegral_enorm, Pi.sub_apply]
refine (tendsto_congr' ?_).mp hfs
filter_upwards [hfsi] with i hi
refine lintegral_congr_ae ?_
filter_upwards [hi.coeFn_toL1, hfi.coeFn_toL1] with x hxi hxf
simp_rw [F_lp, dif_pos hi, hxi, f_lp, hxf]
suffices Tendsto (fun i => setToFun μ T hT (F_lp i)) l (𝓝 (setToFun μ T hT f)) by
refine (tendsto_congr' ?_).mp this
filter_upwards [hfsi] with i hi
suffices h_ae_eq : F_lp i =ᵐ[μ] fs i from setToFun_congr_ae hT h_ae_eq
simp_rw [F_lp, dif_pos hi]
exact hi.coeFn_toL1
rw [setToFun_congr_ae hT hfi.coeFn_toL1.symm]
exact ((continuous_setToFun hT).tendsto f_lp).comp tendsto_L1
theorem tendsto_setToFun_approxOn_of_measurable (hT : DominatedFinMeasAdditive μ T C)
[MeasurableSpace E] [BorelSpace E] {f : α → E} {s : Set E} [SeparableSpace s]
(hfi : Integrable f μ) (hfm : Measurable f) (hs : ∀ᵐ x ∂μ, f x ∈ closure s) {y₀ : E}
(h₀ : y₀ ∈ s) (h₀i : Integrable (fun _ => y₀) μ) :
Tendsto (fun n => setToFun μ T hT (SimpleFunc.approxOn f hfm s y₀ h₀ n)) atTop
(𝓝 <| setToFun μ T hT f) :=
tendsto_setToFun_of_L1 hT _ hfi
(Eventually.of_forall (SimpleFunc.integrable_approxOn hfm hfi h₀ h₀i))
(SimpleFunc.tendsto_approxOn_L1_enorm hfm _ hs (hfi.sub h₀i).2)
theorem tendsto_setToFun_approxOn_of_measurable_of_range_subset
(hT : DominatedFinMeasAdditive μ T C) [MeasurableSpace E] [BorelSpace E] {f : α → E}
(fmeas : Measurable f) (hf : Integrable f μ) (s : Set E) [SeparableSpace s]
(hs : range f ∪ {0} ⊆ s) :
Tendsto (fun n => setToFun μ T hT (SimpleFunc.approxOn f fmeas s 0 (hs <| by simp) n)) atTop
(𝓝 <| setToFun μ T hT f) := by
refine tendsto_setToFun_approxOn_of_measurable hT hf fmeas ?_ _ (integrable_zero _ _ _)
exact Eventually.of_forall fun x => subset_closure (hs (Set.mem_union_left _ (mem_range_self _)))
/-- Auxiliary lemma for `setToFun_congr_measure`: the function sending `f : α →₁[μ] G` to
`f : α →₁[μ'] G` is continuous when `μ' ≤ c' • μ` for `c' ≠ ∞`. -/
theorem continuous_L1_toL1 {μ' : Measure α} (c' : ℝ≥0∞) (hc' : c' ≠ ∞) (hμ'_le : μ' ≤ c' • μ) :
Continuous fun f : α →₁[μ] G =>
(Integrable.of_measure_le_smul hc' hμ'_le (L1.integrable_coeFn f)).toL1 f := by
by_cases hc'0 : c' = 0
· have hμ'0 : μ' = 0 := by rw [← Measure.nonpos_iff_eq_zero']; refine hμ'_le.trans ?_; simp [hc'0]
have h_im_zero :
(fun f : α →₁[μ] G =>
(Integrable.of_measure_le_smul hc' hμ'_le (L1.integrable_coeFn f)).toL1 f) =
0 := by
ext1 f; ext1; simp_rw [hμ'0]; simp only [ae_zero, EventuallyEq, eventually_bot]
rw [h_im_zero]
exact continuous_zero
rw [Metric.continuous_iff]
intro f ε hε_pos
use ε / 2 / c'.toReal
refine ⟨div_pos (half_pos hε_pos) (toReal_pos hc'0 hc'), ?_⟩
intro g hfg
rw [Lp.dist_def] at hfg ⊢
let h_int := fun f' : α →₁[μ] G => (L1.integrable_coeFn f').of_measure_le_smul hc' hμ'_le
have :
eLpNorm (⇑(Integrable.toL1 g (h_int g)) - ⇑(Integrable.toL1 f (h_int f))) 1 μ' =
eLpNorm (⇑g - ⇑f) 1 μ' :=
eLpNorm_congr_ae ((Integrable.coeFn_toL1 _).sub (Integrable.coeFn_toL1 _))
rw [this]
have h_eLpNorm_ne_top : eLpNorm (⇑g - ⇑f) 1 μ ≠ ∞ := by
rw [← eLpNorm_congr_ae (Lp.coeFn_sub _ _)]; exact Lp.eLpNorm_ne_top _
calc
(eLpNorm (⇑g - ⇑f) 1 μ').toReal ≤ (c' * eLpNorm (⇑g - ⇑f) 1 μ).toReal := by
refine toReal_mono (ENNReal.mul_ne_top hc' h_eLpNorm_ne_top) ?_
refine (eLpNorm_mono_measure (⇑g - ⇑f) hμ'_le).trans_eq ?_
rw [eLpNorm_smul_measure_of_ne_zero hc'0, smul_eq_mul]
simp
_ = c'.toReal * (eLpNorm (⇑g - ⇑f) 1 μ).toReal := toReal_mul
_ ≤ c'.toReal * (ε / 2 / c'.toReal) := by gcongr
_ = ε / 2 := by
refine mul_div_cancel₀ (ε / 2) ?_; rw [Ne, toReal_eq_zero_iff]; simp [hc', hc'0]
_ < ε := half_lt_self hε_pos
theorem setToFun_congr_measure_of_integrable {μ' : Measure α} (c' : ℝ≥0∞) (hc' : c' ≠ ∞)
(hμ'_le : μ' ≤ c' • μ) (hT : DominatedFinMeasAdditive μ T C)
(hT' : DominatedFinMeasAdditive μ' T C') (f : α → E) (hfμ : Integrable f μ) :
setToFun μ T hT f = setToFun μ' T hT' f := by
-- integrability for `μ` implies integrability for `μ'`.
have h_int : ∀ g : α → E, Integrable g μ → Integrable g μ' := fun g hg =>
Integrable.of_measure_le_smul hc' hμ'_le hg
-- We use `Integrable.induction`
apply hfμ.induction (P := fun f => setToFun μ T hT f = setToFun μ' T hT' f)
· intro c s hs hμs
have hμ's : μ' s ≠ ∞ := by
refine ((hμ'_le s).trans_lt ?_).ne
rw [Measure.smul_apply, smul_eq_mul]
exact ENNReal.mul_lt_top hc'.lt_top hμs
rw [setToFun_indicator_const hT hs hμs.ne, setToFun_indicator_const hT' hs hμ's]
· intro f₂ g₂ _ hf₂ hg₂ h_eq_f h_eq_g
rw [setToFun_add hT hf₂ hg₂, setToFun_add hT' (h_int f₂ hf₂) (h_int g₂ hg₂), h_eq_f, h_eq_g]
· refine isClosed_eq (continuous_setToFun hT) ?_
have :
(fun f : α →₁[μ] E => setToFun μ' T hT' f) = fun f : α →₁[μ] E =>
setToFun μ' T hT' ((h_int f (L1.integrable_coeFn f)).toL1 f) := by
ext1 f; exact setToFun_congr_ae hT' (Integrable.coeFn_toL1 _).symm
rw [this]
exact (continuous_setToFun hT').comp (continuous_L1_toL1 c' hc' hμ'_le)
· intro f₂ g₂ hfg _ hf_eq
have hfg' : f₂ =ᵐ[μ'] g₂ := (Measure.absolutelyContinuous_of_le_smul hμ'_le).ae_eq hfg
rw [← setToFun_congr_ae hT hfg, hf_eq, setToFun_congr_ae hT' hfg']
theorem setToFun_congr_measure {μ' : Measure α} (c c' : ℝ≥0∞) (hc : c ≠ ∞) (hc' : c' ≠ ∞)
(hμ_le : μ ≤ c • μ') (hμ'_le : μ' ≤ c' • μ) (hT : DominatedFinMeasAdditive μ T C)
(hT' : DominatedFinMeasAdditive μ' T C') (f : α → E) :
setToFun μ T hT f = setToFun μ' T hT' f := by
by_cases hf : Integrable f μ
· exact setToFun_congr_measure_of_integrable c' hc' hμ'_le hT hT' f hf
· -- if `f` is not integrable, both `setToFun` are 0.
have h_int : ∀ g : α → E, ¬Integrable g μ → ¬Integrable g μ' := fun g =>
mt fun h => h.of_measure_le_smul hc hμ_le
simp_rw [setToFun_undef _ hf, setToFun_undef _ (h_int f hf)]
theorem setToFun_congr_measure_of_add_right {μ' : Measure α}
(hT_add : DominatedFinMeasAdditive (μ + μ') T C') (hT : DominatedFinMeasAdditive μ T C)
(f : α → E) (hf : Integrable f (μ + μ')) :
setToFun (μ + μ') T hT_add f = setToFun μ T hT f := by
refine setToFun_congr_measure_of_integrable 1 one_ne_top ?_ hT_add hT f hf
rw [one_smul]
nth_rw 1 [← add_zero μ]
exact add_le_add le_rfl bot_le
theorem setToFun_congr_measure_of_add_left {μ' : Measure α}
(hT_add : DominatedFinMeasAdditive (μ + μ') T C') (hT : DominatedFinMeasAdditive μ' T C)
(f : α → E) (hf : Integrable f (μ + μ')) :
setToFun (μ + μ') T hT_add f = setToFun μ' T hT f := by
refine setToFun_congr_measure_of_integrable 1 one_ne_top ?_ hT_add hT f hf
rw [one_smul]
nth_rw 1 [← zero_add μ']
exact add_le_add_right bot_le μ'
theorem setToFun_top_smul_measure (hT : DominatedFinMeasAdditive (∞ • μ) T C) (f : α → E) :
setToFun (∞ • μ) T hT f = 0 := by
refine setToFun_measure_zero' hT fun s _ hμs => ?_
rw [lt_top_iff_ne_top] at hμs
simp only [true_and, Measure.smul_apply, ENNReal.mul_eq_top, eq_self_iff_true,
top_ne_zero, Ne, not_false_iff, not_or, Classical.not_not, smul_eq_mul] at hμs
simp only [hμs.right, Measure.smul_apply, mul_zero, smul_eq_mul]
theorem setToFun_congr_smul_measure (c : ℝ≥0∞) (hc_ne_top : c ≠ ∞)
(hT : DominatedFinMeasAdditive μ T C) (hT_smul : DominatedFinMeasAdditive (c • μ) T C')
(f : α → E) : setToFun μ T hT f = setToFun (c • μ) T hT_smul f := by
by_cases hc0 : c = 0
· simp [hc0] at hT_smul
have h : ∀ s, MeasurableSet s → μ s < ∞ → T s = 0 := fun s hs _ => hT_smul.eq_zero hs
rw [setToFun_zero_left' _ h, setToFun_measure_zero]
simp [hc0]
refine setToFun_congr_measure c⁻¹ c ?_ hc_ne_top (le_of_eq ?_) le_rfl hT hT_smul f
· simp [hc0]
· rw [smul_smul, ENNReal.inv_mul_cancel hc0 hc_ne_top, one_smul]
theorem norm_setToFun_le_mul_norm (hT : DominatedFinMeasAdditive μ T C) (f : α →₁[μ] E)
(hC : 0 ≤ C) : ‖setToFun μ T hT f‖ ≤ C * ‖f‖ := by
rw [L1.setToFun_eq_setToL1]; exact L1.norm_setToL1_le_mul_norm hT hC f
theorem norm_setToFun_le_mul_norm' (hT : DominatedFinMeasAdditive μ T C) (f : α →₁[μ] E) :
‖setToFun μ T hT f‖ ≤ max C 0 * ‖f‖ := by
rw [L1.setToFun_eq_setToL1]; exact L1.norm_setToL1_le_mul_norm' hT f
theorem norm_setToFun_le (hT : DominatedFinMeasAdditive μ T C) (hf : Integrable f μ) (hC : 0 ≤ C) :
‖setToFun μ T hT f‖ ≤ C * ‖hf.toL1 f‖ := by
rw [setToFun_eq hT hf]; exact L1.norm_setToL1_le_mul_norm hT hC _
theorem norm_setToFun_le' (hT : DominatedFinMeasAdditive μ T C) (hf : Integrable f μ) :
‖setToFun μ T hT f‖ ≤ max C 0 * ‖hf.toL1 f‖ := by
rw [setToFun_eq hT hf]; exact L1.norm_setToL1_le_mul_norm' hT _
/-- Lebesgue dominated convergence theorem provides sufficient conditions under which almost
everywhere convergence of a sequence of functions implies the convergence of their image by
`setToFun`.
We could weaken the condition `bound_integrable` to require `HasFiniteIntegral bound μ` instead
(i.e. not requiring that `bound` is measurable), but in all applications proving integrability
is easier. -/
theorem tendsto_setToFun_of_dominated_convergence (hT : DominatedFinMeasAdditive μ T C)
{fs : ℕ → α → E} {f : α → E} (bound : α → ℝ)
(fs_measurable : ∀ n, AEStronglyMeasurable (fs n) μ) (bound_integrable : Integrable bound μ)
(h_bound : ∀ n, ∀ᵐ a ∂μ, ‖fs n a‖ ≤ bound a)
(h_lim : ∀ᵐ a ∂μ, Tendsto (fun n => fs n a) atTop (𝓝 (f a))) :
Tendsto (fun n => setToFun μ T hT (fs n)) atTop (𝓝 <| setToFun μ T hT f) := by
-- `f` is a.e.-measurable, since it is the a.e.-pointwise limit of a.e.-measurable functions.
have f_measurable : AEStronglyMeasurable f μ :=
aestronglyMeasurable_of_tendsto_ae _ fs_measurable h_lim
-- all functions we consider are integrable
have fs_int : ∀ n, Integrable (fs n) μ := fun n =>
bound_integrable.mono' (fs_measurable n) (h_bound _)
have f_int : Integrable f μ :=
⟨f_measurable,
hasFiniteIntegral_of_dominated_convergence bound_integrable.hasFiniteIntegral h_bound
h_lim⟩
-- it suffices to prove the result for the corresponding L1 functions
suffices
Tendsto (fun n => L1.setToL1 hT ((fs_int n).toL1 (fs n))) atTop
(𝓝 (L1.setToL1 hT (f_int.toL1 f))) by
convert this with n
· exact setToFun_eq hT (fs_int n)
· exact setToFun_eq hT f_int
-- the convergence of setToL1 follows from the convergence of the L1 functions
refine L1.tendsto_setToL1 hT _ _ ?_
-- up to some rewriting, what we need to prove is `h_lim`
rw [tendsto_iff_norm_sub_tendsto_zero]
have lintegral_norm_tendsto_zero :
Tendsto (fun n => ENNReal.toReal <| ∫⁻ a, ENNReal.ofReal ‖fs n a - f a‖ ∂μ) atTop (𝓝 0) :=
(tendsto_toReal zero_ne_top).comp
(tendsto_lintegral_norm_of_dominated_convergence fs_measurable
bound_integrable.hasFiniteIntegral h_bound h_lim)
convert lintegral_norm_tendsto_zero with n
rw [L1.norm_def]
congr 1
refine lintegral_congr_ae ?_
rw [← Integrable.toL1_sub]
refine ((fs_int n).sub f_int).coeFn_toL1.mono fun x hx => ?_
dsimp only
rw [hx, ofReal_norm_eq_enorm, Pi.sub_apply]
/-- Lebesgue dominated convergence theorem for filters with a countable basis -/
theorem tendsto_setToFun_filter_of_dominated_convergence (hT : DominatedFinMeasAdditive μ T C) {ι}
{l : Filter ι} [l.IsCountablyGenerated] {fs : ι → α → E} {f : α → E} (bound : α → ℝ)
(hfs_meas : ∀ᶠ n in l, AEStronglyMeasurable (fs n) μ)
(h_bound : ∀ᶠ n in l, ∀ᵐ a ∂μ, ‖fs n a‖ ≤ bound a) (bound_integrable : Integrable bound μ)
(h_lim : ∀ᵐ a ∂μ, Tendsto (fun n => fs n a) l (𝓝 (f a))) :
Tendsto (fun n => setToFun μ T hT (fs n)) l (𝓝 <| setToFun μ T hT f) := by
rw [tendsto_iff_seq_tendsto]
intro x xl
have hxl : ∀ s ∈ l, ∃ a, ∀ b ≥ a, x b ∈ s := by rwa [tendsto_atTop'] at xl
have h :
{ x : ι | (fun n => AEStronglyMeasurable (fs n) μ) x } ∩
{ x : ι | (fun n => ∀ᵐ a ∂μ, ‖fs n a‖ ≤ bound a) x } ∈ l :=
inter_mem hfs_meas h_bound
obtain ⟨k, h⟩ := hxl _ h
rw [← tendsto_add_atTop_iff_nat k]
refine tendsto_setToFun_of_dominated_convergence hT bound ?_ bound_integrable ?_ ?_
· exact fun n => (h _ (self_le_add_left _ _)).1
· exact fun n => (h _ (self_le_add_left _ _)).2
· filter_upwards [h_lim]
refine fun a h_lin => @Tendsto.comp _ _ _ (fun n => x (n + k)) (fun n => fs n a) _ _ _ h_lin ?_
rwa [tendsto_add_atTop_iff_nat]
variable {X : Type*} [TopologicalSpace X] [FirstCountableTopology X]
theorem continuousWithinAt_setToFun_of_dominated (hT : DominatedFinMeasAdditive μ T C)
{fs : X → α → E} {x₀ : X} {bound : α → ℝ} {s : Set X}
(hfs_meas : ∀ᶠ x in 𝓝[s] x₀, AEStronglyMeasurable (fs x) μ)
(h_bound : ∀ᶠ x in 𝓝[s] x₀, ∀ᵐ a ∂μ, ‖fs x a‖ ≤ bound a) (bound_integrable : Integrable bound μ)
(h_cont : ∀ᵐ a ∂μ, ContinuousWithinAt (fun x => fs x a) s x₀) :
| ContinuousWithinAt (fun x => setToFun μ T hT (fs x)) s x₀ :=
tendsto_setToFun_filter_of_dominated_convergence hT bound ‹_› ‹_› ‹_› ‹_›
theorem continuousAt_setToFun_of_dominated (hT : DominatedFinMeasAdditive μ T C) {fs : X → α → E}
{x₀ : X} {bound : α → ℝ} (hfs_meas : ∀ᶠ x in 𝓝 x₀, AEStronglyMeasurable (fs x) μ)
(h_bound : ∀ᶠ x in 𝓝 x₀, ∀ᵐ a ∂μ, ‖fs x a‖ ≤ bound a) (bound_integrable : Integrable bound μ)
(h_cont : ∀ᵐ a ∂μ, ContinuousAt (fun x => fs x a) x₀) :
ContinuousAt (fun x => setToFun μ T hT (fs x)) x₀ :=
tendsto_setToFun_filter_of_dominated_convergence hT bound ‹_› ‹_› ‹_› ‹_›
| Mathlib/MeasureTheory/Integral/SetToL1.lean | 1,089 | 1,098 |
/-
Copyright (c) 2022 Moritz Doll. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Moritz Doll
-/
import Mathlib.GroupTheory.GroupAction.Pointwise
import Mathlib.Analysis.LocallyConvex.Basic
import Mathlib.Analysis.LocallyConvex.BalancedCoreHull
import Mathlib.Analysis.Seminorm
import Mathlib.LinearAlgebra.Basis.VectorSpace
import Mathlib.Topology.Bornology.Basic
import Mathlib.Topology.Algebra.IsUniformGroup.Basic
import Mathlib.Topology.UniformSpace.Cauchy
/-!
# Von Neumann Boundedness
This file defines natural or von Neumann bounded sets and proves elementary properties.
## Main declarations
* `Bornology.IsVonNBounded`: A set `s` is von Neumann-bounded if every neighborhood of zero
absorbs `s`.
* `Bornology.vonNBornology`: The bornology made of the von Neumann-bounded sets.
## Main results
* `Bornology.IsVonNBounded.of_topologicalSpace_le`: A coarser topology admits more
von Neumann-bounded sets.
* `Bornology.IsVonNBounded.image`: A continuous linear image of a bounded set is bounded.
* `Bornology.isVonNBounded_iff_smul_tendsto_zero`: Given any sequence `ε` of scalars which tends
to `𝓝[≠] 0`, we have that a set `S` is bounded if and only if for any sequence `x : ℕ → S`,
`ε • x` tends to 0. This shows that bounded sets are completely determined by sequences, which is
the key fact for proving that sequential continuity implies continuity for linear maps defined on
a bornological space
## References
* [Bourbaki, *Topological Vector Spaces*][bourbaki1987]
-/
variable {𝕜 𝕜' E F ι : Type*}
open Set Filter Function
open scoped Topology Pointwise
namespace Bornology
section SeminormedRing
section Zero
variable (𝕜)
variable [SeminormedRing 𝕜] [SMul 𝕜 E] [Zero E]
variable [TopologicalSpace E]
/-- A set `s` is von Neumann bounded if every neighborhood of 0 absorbs `s`. -/
def IsVonNBounded (s : Set E) : Prop :=
∀ ⦃V⦄, V ∈ 𝓝 (0 : E) → Absorbs 𝕜 V s
variable (E)
@[simp]
theorem isVonNBounded_empty : IsVonNBounded 𝕜 (∅ : Set E) := fun _ _ => Absorbs.empty
variable {𝕜 E}
theorem isVonNBounded_iff (s : Set E) : IsVonNBounded 𝕜 s ↔ ∀ V ∈ 𝓝 (0 : E), Absorbs 𝕜 V s :=
Iff.rfl
theorem _root_.Filter.HasBasis.isVonNBounded_iff {q : ι → Prop} {s : ι → Set E} {A : Set E}
(h : (𝓝 (0 : E)).HasBasis q s) : IsVonNBounded 𝕜 A ↔ ∀ i, q i → Absorbs 𝕜 (s i) A := by
refine ⟨fun hA i hi => hA (h.mem_of_mem hi), fun hA V hV => ?_⟩
rcases h.mem_iff.mp hV with ⟨i, hi, hV⟩
exact (hA i hi).mono_left hV
/-- Subsets of bounded sets are bounded. -/
theorem IsVonNBounded.subset {s₁ s₂ : Set E} (h : s₁ ⊆ s₂) (hs₂ : IsVonNBounded 𝕜 s₂) :
IsVonNBounded 𝕜 s₁ := fun _ hV => (hs₂ hV).mono_right h
@[simp]
theorem isVonNBounded_union {s t : Set E} :
IsVonNBounded 𝕜 (s ∪ t) ↔ IsVonNBounded 𝕜 s ∧ IsVonNBounded 𝕜 t := by
simp only [IsVonNBounded, absorbs_union, forall_and]
/-- The union of two bounded sets is bounded. -/
theorem IsVonNBounded.union {s₁ s₂ : Set E} (hs₁ : IsVonNBounded 𝕜 s₁) (hs₂ : IsVonNBounded 𝕜 s₂) :
IsVonNBounded 𝕜 (s₁ ∪ s₂) := isVonNBounded_union.2 ⟨hs₁, hs₂⟩
@[nontriviality]
theorem IsVonNBounded.of_boundedSpace [BoundedSpace 𝕜] {s : Set E} : IsVonNBounded 𝕜 s := fun _ _ ↦
.of_boundedSpace
@[nontriviality]
theorem IsVonNBounded.of_subsingleton [Subsingleton E] {s : Set E} : IsVonNBounded 𝕜 s :=
fun U hU ↦ .of_forall fun c ↦ calc
s ⊆ univ := subset_univ s
_ = c • U := .symm <| Subsingleton.eq_univ_of_nonempty <| (Filter.nonempty_of_mem hU).image _
@[simp]
theorem isVonNBounded_iUnion {ι : Sort*} [Finite ι] {s : ι → Set E} :
IsVonNBounded 𝕜 (⋃ i, s i) ↔ ∀ i, IsVonNBounded 𝕜 (s i) := by
simp only [IsVonNBounded, absorbs_iUnion, @forall_swap ι]
theorem isVonNBounded_biUnion {ι : Type*} {I : Set ι} (hI : I.Finite) {s : ι → Set E} :
IsVonNBounded 𝕜 (⋃ i ∈ I, s i) ↔ ∀ i ∈ I, IsVonNBounded 𝕜 (s i) := by
have _ := hI.to_subtype
rw [biUnion_eq_iUnion, isVonNBounded_iUnion, Subtype.forall]
theorem isVonNBounded_sUnion {S : Set (Set E)} (hS : S.Finite) :
IsVonNBounded 𝕜 (⋃₀ S) ↔ ∀ s ∈ S, IsVonNBounded 𝕜 s := by
rw [sUnion_eq_biUnion, isVonNBounded_biUnion hS]
end Zero
section ContinuousAdd
variable [SeminormedRing 𝕜] [AddZeroClass E] [TopologicalSpace E] [ContinuousAdd E]
[DistribSMul 𝕜 E] {s t : Set E}
protected theorem IsVonNBounded.add (hs : IsVonNBounded 𝕜 s) (ht : IsVonNBounded 𝕜 t) :
IsVonNBounded 𝕜 (s + t) := fun U hU ↦ by
rcases exists_open_nhds_zero_add_subset hU with ⟨V, hVo, hV, hVU⟩
exact ((hs <| hVo.mem_nhds hV).add (ht <| hVo.mem_nhds hV)).mono_left hVU
end ContinuousAdd
section IsTopologicalAddGroup
variable [SeminormedRing 𝕜] [AddGroup E] [TopologicalSpace E] [IsTopologicalAddGroup E]
[DistribMulAction 𝕜 E] {s t : Set E}
protected theorem IsVonNBounded.neg (hs : IsVonNBounded 𝕜 s) : IsVonNBounded 𝕜 (-s) := fun U hU ↦ by
rw [← neg_neg U]
exact (hs <| neg_mem_nhds_zero _ hU).neg_neg
@[simp]
theorem isVonNBounded_neg : IsVonNBounded 𝕜 (-s) ↔ IsVonNBounded 𝕜 s :=
⟨fun h ↦ neg_neg s ▸ h.neg, fun h ↦ h.neg⟩
alias ⟨IsVonNBounded.of_neg, _⟩ := isVonNBounded_neg
protected theorem IsVonNBounded.sub (hs : IsVonNBounded 𝕜 s) (ht : IsVonNBounded 𝕜 t) :
IsVonNBounded 𝕜 (s - t) := by
rw [sub_eq_add_neg]
exact hs.add ht.neg
end IsTopologicalAddGroup
end SeminormedRing
section MultipleTopologies
variable [SeminormedRing 𝕜] [AddCommGroup E] [Module 𝕜 E]
/-- If a topology `t'` is coarser than `t`, then any set `s` that is bounded with respect to
`t` is bounded with respect to `t'`. -/
theorem IsVonNBounded.of_topologicalSpace_le {t t' : TopologicalSpace E} (h : t ≤ t') {s : Set E}
(hs : @IsVonNBounded 𝕜 E _ _ _ t s) : @IsVonNBounded 𝕜 E _ _ _ t' s := fun _ hV =>
hs <| (le_iff_nhds t t').mp h 0 hV
end MultipleTopologies
lemma isVonNBounded_iff_tendsto_smallSets_nhds {𝕜 E : Type*} [NormedDivisionRing 𝕜]
[AddCommGroup E] [Module 𝕜 E] [TopologicalSpace E] {S : Set E} :
IsVonNBounded 𝕜 S ↔ Tendsto (· • S : 𝕜 → Set E) (𝓝 0) (𝓝 0).smallSets := by
rw [tendsto_smallSets_iff]
refine forall₂_congr fun V hV ↦ ?_
simp only [absorbs_iff_eventually_nhds_zero (mem_of_mem_nhds hV), mapsTo', image_smul]
alias ⟨IsVonNBounded.tendsto_smallSets_nhds, _⟩ := isVonNBounded_iff_tendsto_smallSets_nhds
lemma isVonNBounded_iff_absorbing_le {𝕜 E : Type*} [NormedDivisionRing 𝕜]
[AddCommGroup E] [Module 𝕜 E] [TopologicalSpace E] {S : Set E} :
IsVonNBounded 𝕜 S ↔ Filter.absorbing 𝕜 S ≤ 𝓝 0 :=
.rfl
lemma isVonNBounded_pi_iff {𝕜 ι : Type*} {E : ι → Type*} [NormedDivisionRing 𝕜]
[∀ i, AddCommGroup (E i)] [∀ i, Module 𝕜 (E i)] [∀ i, TopologicalSpace (E i)]
{S : Set (∀ i, E i)} : IsVonNBounded 𝕜 S ↔ ∀ i, IsVonNBounded 𝕜 (eval i '' S) := by
simp_rw [isVonNBounded_iff_tendsto_smallSets_nhds, nhds_pi, Filter.pi, smallSets_iInf,
smallSets_comap_eq_comap_image, tendsto_iInf, tendsto_comap_iff, Function.comp_def,
← image_smul, image_image, eval, Pi.smul_apply, Pi.zero_apply]
section Image
variable {𝕜₁ 𝕜₂ : Type*} [NormedDivisionRing 𝕜₁] [NormedDivisionRing 𝕜₂] [AddCommGroup E]
[Module 𝕜₁ E] [AddCommGroup F] [Module 𝕜₂ F] [TopologicalSpace E] [TopologicalSpace F]
/-- A continuous linear image of a bounded set is bounded. -/
protected theorem IsVonNBounded.image {σ : 𝕜₁ →+* 𝕜₂} [RingHomSurjective σ] [RingHomIsometric σ]
{s : Set E} (hs : IsVonNBounded 𝕜₁ s) (f : E →SL[σ] F) : IsVonNBounded 𝕜₂ (f '' s) := by
have σ_iso : Isometry σ := AddMonoidHomClass.isometry_of_norm σ fun x => RingHomIsometric.is_iso
have : map σ (𝓝 0) = 𝓝 0 := by
rw [σ_iso.isEmbedding.map_nhds_eq, σ.surjective.range_eq, nhdsWithin_univ, map_zero]
have hf₀ : Tendsto f (𝓝 0) (𝓝 0) := f.continuous.tendsto' 0 0 (map_zero f)
simp only [isVonNBounded_iff_tendsto_smallSets_nhds, ← this, tendsto_map'_iff] at hs ⊢
simpa only [comp_def, image_smul_setₛₗ] using hf₀.image_smallSets.comp hs
end Image
section sequence
theorem IsVonNBounded.smul_tendsto_zero [NormedField 𝕜]
[AddCommGroup E] [Module 𝕜 E] [TopologicalSpace E]
{S : Set E} {ε : ι → 𝕜} {x : ι → E} {l : Filter ι}
(hS : IsVonNBounded 𝕜 S) (hxS : ∀ᶠ n in l, x n ∈ S) (hε : Tendsto ε l (𝓝 0)) :
Tendsto (ε • x) l (𝓝 0) :=
(hS.tendsto_smallSets_nhds.comp hε).of_smallSets <| hxS.mono fun _ ↦ smul_mem_smul_set
variable [NontriviallyNormedField 𝕜]
[AddCommGroup E] [Module 𝕜 E] [TopologicalSpace E] [ContinuousSMul 𝕜 E]
theorem isVonNBounded_of_smul_tendsto_zero {ε : ι → 𝕜} {l : Filter ι} [l.NeBot]
(hε : ∀ᶠ n in l, ε n ≠ 0) {S : Set E}
(H : ∀ x : ι → E, (∀ n, x n ∈ S) → Tendsto (ε • x) l (𝓝 0)) : IsVonNBounded 𝕜 S := by
rw [(nhds_basis_balanced 𝕜 E).isVonNBounded_iff]
by_contra! H'
rcases H' with ⟨V, ⟨hV, hVb⟩, hVS⟩
have : ∀ᶠ n in l, ∃ x : S, ε n • (x : E) ∉ V := by
filter_upwards [hε] with n hn
rw [absorbs_iff_norm] at hVS
push_neg at hVS
rcases hVS ‖(ε n)⁻¹‖ with ⟨a, haε, haS⟩
rcases Set.not_subset.mp haS with ⟨x, hxS, hx⟩
refine ⟨⟨x, hxS⟩, fun hnx => ?_⟩
rw [← Set.mem_inv_smul_set_iff₀ hn] at hnx
exact hx (hVb.smul_mono haε hnx)
rcases this.choice with ⟨x, hx⟩
refine Filter.frequently_false l (Filter.Eventually.frequently ?_)
filter_upwards [hx,
(H (_ ∘ x) fun n => (x n).2).eventually (eventually_mem_set.mpr hV)] using fun n => id
/-- Given any sequence `ε` of scalars which tends to `𝓝[≠] 0`, we have that a set `S` is bounded
if and only if for any sequence `x : ℕ → S`, `ε • x` tends to 0. This actually works for any
indexing type `ι`, but in the special case `ι = ℕ` we get the important fact that convergent
sequences fully characterize bounded sets. -/
theorem isVonNBounded_iff_smul_tendsto_zero {ε : ι → 𝕜} {l : Filter ι} [l.NeBot]
(hε : Tendsto ε l (𝓝[≠] 0)) {S : Set E} :
IsVonNBounded 𝕜 S ↔ ∀ x : ι → E, (∀ n, x n ∈ S) → Tendsto (ε • x) l (𝓝 0) :=
⟨fun hS _ hxS => hS.smul_tendsto_zero (Eventually.of_forall hxS) (le_trans hε nhdsWithin_le_nhds),
isVonNBounded_of_smul_tendsto_zero (by exact hε self_mem_nhdsWithin)⟩
end sequence
/-- If a set is von Neumann bounded with respect to a smaller field,
then it is also von Neumann bounded with respect to a larger field.
See also `Bornology.IsVonNBounded.restrict_scalars` below. -/
theorem IsVonNBounded.extend_scalars [NontriviallyNormedField 𝕜]
{E : Type*} [AddCommGroup E] [Module 𝕜 E]
(𝕝 : Type*) [NontriviallyNormedField 𝕝] [NormedAlgebra 𝕜 𝕝]
[Module 𝕝 E] [TopologicalSpace E] [ContinuousSMul 𝕝 E] [IsScalarTower 𝕜 𝕝 E]
{s : Set E} (h : IsVonNBounded 𝕜 s) : IsVonNBounded 𝕝 s := by
obtain ⟨ε, hε, hε₀⟩ : ∃ ε : ℕ → 𝕜, Tendsto ε atTop (𝓝 0) ∧ ∀ᶠ n in atTop, ε n ≠ 0 := by
simpa only [tendsto_nhdsWithin_iff] using exists_seq_tendsto (𝓝[≠] (0 : 𝕜))
refine isVonNBounded_of_smul_tendsto_zero (ε := (ε · • 1)) (by simpa) fun x hx ↦ ?_
have := h.smul_tendsto_zero (.of_forall hx) hε
simpa only [Pi.smul_def', smul_one_smul]
section NormedField
variable [NormedField 𝕜] [AddCommGroup E] [Module 𝕜 E]
variable [TopologicalSpace E] [ContinuousSMul 𝕜 E]
/-- Singletons are bounded. -/
theorem isVonNBounded_singleton (x : E) : IsVonNBounded 𝕜 ({x} : Set E) := fun _ hV =>
(absorbent_nhds_zero hV).absorbs
@[simp]
theorem isVonNBounded_insert (x : E) {s : Set E} :
IsVonNBounded 𝕜 (insert x s) ↔ IsVonNBounded 𝕜 s := by
simp only [← singleton_union, isVonNBounded_union, isVonNBounded_singleton, true_and]
protected alias ⟨_, IsVonNBounded.insert⟩ := isVonNBounded_insert
section ContinuousAdd
variable [ContinuousAdd E] {s t : Set E}
protected theorem IsVonNBounded.vadd (hs : IsVonNBounded 𝕜 s) (x : E) :
IsVonNBounded 𝕜 (x +ᵥ s) := by
rw [← singleton_vadd]
-- TODO: dot notation timeouts in the next line
exact IsVonNBounded.add (isVonNBounded_singleton x) hs
@[simp]
theorem isVonNBounded_vadd (x : E) : IsVonNBounded 𝕜 (x +ᵥ s) ↔ IsVonNBounded 𝕜 s :=
⟨fun h ↦ by simpa using h.vadd (-x), fun h ↦ h.vadd x⟩
theorem IsVonNBounded.of_add_right (hst : IsVonNBounded 𝕜 (s + t)) (hs : s.Nonempty) :
IsVonNBounded 𝕜 t :=
let ⟨x, hx⟩ := hs
(isVonNBounded_vadd x).mp <| hst.subset <| image_subset_image2_right hx
theorem IsVonNBounded.of_add_left (hst : IsVonNBounded 𝕜 (s + t)) (ht : t.Nonempty) :
IsVonNBounded 𝕜 s :=
((add_comm s t).subst hst).of_add_right ht
theorem isVonNBounded_add_of_nonempty (hs : s.Nonempty) (ht : t.Nonempty) :
| IsVonNBounded 𝕜 (s + t) ↔ IsVonNBounded 𝕜 s ∧ IsVonNBounded 𝕜 t :=
⟨fun h ↦ ⟨h.of_add_left ht, h.of_add_right hs⟩, and_imp.2 IsVonNBounded.add⟩
| Mathlib/Analysis/LocallyConvex/Bounded.lean | 303 | 304 |
/-
Copyright (c) 2019 Johannes Hölzl, Zhouhang Zhou. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Zhouhang Zhou
-/
import Mathlib.Dynamics.Ergodic.MeasurePreserving
import Mathlib.MeasureTheory.Function.StronglyMeasurable.AEStronglyMeasurable
import Mathlib.MeasureTheory.Integral.Lebesgue.Add
import Mathlib.Order.Filter.Germ.Basic
import Mathlib.Topology.ContinuousMap.Algebra
/-!
# Almost everywhere equal functions
We build a space of equivalence classes of functions, where two functions are treated as identical
if they are almost everywhere equal. We form the set of equivalence classes under the relation of
being almost everywhere equal, which is sometimes known as the `L⁰` space.
To use this space as a basis for the `L^p` spaces and for the Bochner integral, we consider
equivalence classes of strongly measurable functions (or, equivalently, of almost everywhere
strongly measurable functions.)
See `L1Space.lean` for `L¹` space.
## Notation
* `α →ₘ[μ] β` is the type of `L⁰` space, where `α` is a measurable space, `β` is a topological
space, and `μ` is a measure on `α`. `f : α →ₘ β` is a "function" in `L⁰`.
In comments, `[f]` is also used to denote an `L⁰` function.
`ₘ` can be typed as `\_m`. Sometimes it is shown as a box if font is missing.
## Main statements
* The linear structure of `L⁰` :
Addition and scalar multiplication are defined on `L⁰` in the natural way, i.e.,
`[f] + [g] := [f + g]`, `c • [f] := [c • f]`. So defined, `α →ₘ β` inherits the linear structure
of `β`. For example, if `β` is a module, then `α →ₘ β` is a module over the same ring.
See `mk_add_mk`, `neg_mk`, `mk_sub_mk`, `smul_mk`,
`add_toFun`, `neg_toFun`, `sub_toFun`, `smul_toFun`
* The order structure of `L⁰` :
`≤` can be defined in a similar way: `[f] ≤ [g]` if `f a ≤ g a` for almost all `a` in domain.
And `α →ₘ β` inherits the preorder and partial order of `β`.
TODO: Define `sup` and `inf` on `L⁰` so that it forms a lattice. It seems that `β` must be a
linear order, since otherwise `f ⊔ g` may not be a measurable function.
## Implementation notes
* `f.toFun` : To find a representative of `f : α →ₘ β`, use the coercion `(f : α → β)`, which
is implemented as `f.toFun`.
For each operation `op` in `L⁰`, there is a lemma called `coe_fn_op`,
characterizing, say, `(f op g : α → β)`.
* `ae_eq_fun.mk` : To constructs an `L⁰` function `α →ₘ β` from an almost everywhere strongly
measurable function `f : α → β`, use `ae_eq_fun.mk`
* `comp` : Use `comp g f` to get `[g ∘ f]` from `g : β → γ` and `[f] : α →ₘ γ` when `g` is
continuous. Use `comp_measurable` if `g` is only measurable (this requires the
target space to be second countable).
* `comp₂` : Use `comp₂ g f₁ f₂` to get `[fun a ↦ g (f₁ a) (f₂ a)]`.
For example, `[f + g]` is `comp₂ (+)`
## Tags
function space, almost everywhere equal, `L⁰`, ae_eq_fun
-/
-- Guard against import creep
assert_not_exists InnerProductSpace
noncomputable section
open Topology Set Filter TopologicalSpace ENNReal EMetric MeasureTheory Function
variable {α β γ δ : Type*} [MeasurableSpace α] {μ ν : Measure α}
namespace MeasureTheory
section MeasurableSpace
variable [TopologicalSpace β]
variable (β)
/-- The equivalence relation of being almost everywhere equal for almost everywhere strongly
measurable functions. -/
def Measure.aeEqSetoid (μ : Measure α) : Setoid { f : α → β // AEStronglyMeasurable f μ } :=
⟨fun f g => (f : α → β) =ᵐ[μ] g, fun {f} => ae_eq_refl f.val, fun {_ _} => ae_eq_symm,
fun {_ _ _} => ae_eq_trans⟩
variable (α)
/-- The space of equivalence classes of almost everywhere strongly measurable functions, where two
strongly measurable functions are equivalent if they agree almost everywhere, i.e.,
they differ on a set of measure `0`. -/
def AEEqFun (μ : Measure α) : Type _ :=
Quotient (μ.aeEqSetoid β)
variable {α β}
@[inherit_doc MeasureTheory.AEEqFun]
notation:25 α " →ₘ[" μ "] " β => AEEqFun α β μ
end MeasurableSpace
variable [TopologicalSpace δ]
namespace AEEqFun
section
variable [TopologicalSpace β]
/-- Construct the equivalence class `[f]` of an almost everywhere measurable function `f`, based
on the equivalence relation of being almost everywhere equal. -/
def mk {β : Type*} [TopologicalSpace β] (f : α → β) (hf : AEStronglyMeasurable f μ) : α →ₘ[μ] β :=
Quotient.mk'' ⟨f, hf⟩
open scoped Classical in
/-- Coercion from a space of equivalence classes of almost everywhere strongly measurable
functions to functions. We ensure that if `f` has a constant representative,
then we choose that one. -/
@[coe]
def cast (f : α →ₘ[μ] β) : α → β :=
if h : ∃ (b : β), f = mk (const α b) aestronglyMeasurable_const then
const α <| Classical.choose h else
AEStronglyMeasurable.mk _ (Quotient.out f : { f : α → β // AEStronglyMeasurable f μ }).2
/-- A measurable representative of an `AEEqFun` [f] -/
instance instCoeFun : CoeFun (α →ₘ[μ] β) fun _ => α → β := ⟨cast⟩
protected theorem stronglyMeasurable (f : α →ₘ[μ] β) : StronglyMeasurable f := by
simp only [cast]
split_ifs with h
· exact stronglyMeasurable_const
· apply AEStronglyMeasurable.stronglyMeasurable_mk
protected theorem aestronglyMeasurable (f : α →ₘ[μ] β) : AEStronglyMeasurable f μ :=
f.stronglyMeasurable.aestronglyMeasurable
protected theorem measurable [PseudoMetrizableSpace β] [MeasurableSpace β] [BorelSpace β]
(f : α →ₘ[μ] β) : Measurable f :=
f.stronglyMeasurable.measurable
protected theorem aemeasurable [PseudoMetrizableSpace β] [MeasurableSpace β] [BorelSpace β]
(f : α →ₘ[μ] β) : AEMeasurable f μ :=
f.measurable.aemeasurable
@[simp]
theorem quot_mk_eq_mk (f : α → β) (hf) :
(Quot.mk (@Setoid.r _ <| μ.aeEqSetoid β) ⟨f, hf⟩ : α →ₘ[μ] β) = mk f hf :=
rfl
@[simp]
theorem mk_eq_mk {f g : α → β} {hf hg} : (mk f hf : α →ₘ[μ] β) = mk g hg ↔ f =ᵐ[μ] g :=
Quotient.eq''
@[simp]
theorem mk_coeFn (f : α →ₘ[μ] β) : mk f f.aestronglyMeasurable = f := by
conv_lhs => simp only [cast]
split_ifs with h
· exact Classical.choose_spec h |>.symm
conv_rhs => rw [← Quotient.out_eq' f]
rw [← mk, mk_eq_mk]
exact (AEStronglyMeasurable.ae_eq_mk _).symm
@[ext]
theorem ext {f g : α →ₘ[μ] β} (h : f =ᵐ[μ] g) : f = g := by
rwa [← f.mk_coeFn, ← g.mk_coeFn, mk_eq_mk]
theorem coeFn_mk (f : α → β) (hf) : (mk f hf : α →ₘ[μ] β) =ᵐ[μ] f := by
rw [← mk_eq_mk, mk_coeFn]
@[elab_as_elim]
theorem induction_on (f : α →ₘ[μ] β) {p : (α →ₘ[μ] β) → Prop} (H : ∀ f hf, p (mk f hf)) : p f :=
Quotient.inductionOn' f <| Subtype.forall.2 H
@[elab_as_elim]
theorem induction_on₂ {α' β' : Type*} [MeasurableSpace α'] [TopologicalSpace β'] {μ' : Measure α'}
(f : α →ₘ[μ] β) (f' : α' →ₘ[μ'] β') {p : (α →ₘ[μ] β) → (α' →ₘ[μ'] β') → Prop}
(H : ∀ f hf f' hf', p (mk f hf) (mk f' hf')) : p f f' :=
induction_on f fun f hf => induction_on f' <| H f hf
@[elab_as_elim]
theorem induction_on₃ {α' β' : Type*} [MeasurableSpace α'] [TopologicalSpace β'] {μ' : Measure α'}
{α'' β'' : Type*} [MeasurableSpace α''] [TopologicalSpace β''] {μ'' : Measure α''}
(f : α →ₘ[μ] β) (f' : α' →ₘ[μ'] β') (f'' : α'' →ₘ[μ''] β'')
{p : (α →ₘ[μ] β) → (α' →ₘ[μ'] β') → (α'' →ₘ[μ''] β'') → Prop}
(H : ∀ f hf f' hf' f'' hf'', p (mk f hf) (mk f' hf') (mk f'' hf'')) : p f f' f'' :=
induction_on f fun f hf => induction_on₂ f' f'' <| H f hf
end
/-!
### Composition of an a.e. equal function with a (quasi) measure preserving function
-/
section compQuasiMeasurePreserving
variable [TopologicalSpace γ] [MeasurableSpace β] {ν : MeasureTheory.Measure β} {f : α → β}
open MeasureTheory.Measure (QuasiMeasurePreserving)
/-- Composition of an almost everywhere equal function and a quasi measure preserving function.
See also `AEEqFun.compMeasurePreserving`. -/
def compQuasiMeasurePreserving (g : β →ₘ[ν] γ) (f : α → β) (hf : QuasiMeasurePreserving f μ ν) :
α →ₘ[μ] γ :=
Quotient.liftOn' g (fun g ↦ mk (g ∘ f) <| g.2.comp_quasiMeasurePreserving hf) fun _ _ h ↦
mk_eq_mk.2 <| h.comp_tendsto hf.tendsto_ae
@[simp]
theorem compQuasiMeasurePreserving_mk {g : β → γ} (hg : AEStronglyMeasurable g ν)
(hf : QuasiMeasurePreserving f μ ν) :
(mk g hg).compQuasiMeasurePreserving f hf = mk (g ∘ f) (hg.comp_quasiMeasurePreserving hf) :=
rfl
theorem compQuasiMeasurePreserving_eq_mk (g : β →ₘ[ν] γ) (hf : QuasiMeasurePreserving f μ ν) :
g.compQuasiMeasurePreserving f hf =
mk (g ∘ f) (g.aestronglyMeasurable.comp_quasiMeasurePreserving hf) := by
rw [← compQuasiMeasurePreserving_mk g.aestronglyMeasurable hf, mk_coeFn]
theorem coeFn_compQuasiMeasurePreserving (g : β →ₘ[ν] γ) (hf : QuasiMeasurePreserving f μ ν) :
g.compQuasiMeasurePreserving f hf =ᵐ[μ] g ∘ f := by
rw [compQuasiMeasurePreserving_eq_mk]
apply coeFn_mk
|
end compQuasiMeasurePreserving
section compMeasurePreserving
| Mathlib/MeasureTheory/Function/AEEqFun.lean | 228 | 231 |
/-
Copyright (c) 2024 Brendan Murphy. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Brendan Murphy
-/
import Mathlib.RingTheory.Regular.IsSMulRegular
import Mathlib.RingTheory.Artinian.Module
import Mathlib.RingTheory.Nakayama
import Mathlib.Algebra.Equiv.TransferInstance
import Mathlib.RingTheory.LocalRing.MaximalIdeal.Basic
import Mathlib.RingTheory.Noetherian.Basic
/-!
# Regular sequences and weakly regular sequences
The notion of a regular sequence is fundamental in commutative algebra.
Properties of regular sequences encode information about singularities of a
ring and regularity of a sequence can be tested homologically.
However the notion of a regular sequence is only really sensible for Noetherian local rings.
TODO: Koszul regular sequences, H_1-regular sequences, quasi-regular sequences, depth.
## Tags
module, regular element, regular sequence, commutative algebra
-/
universe u v
open scoped Pointwise
variable {R S M M₂ M₃ M₄ : Type*}
namespace Ideal
variable [Semiring R] [Semiring S]
/-- The ideal generated by a list of elements. -/
abbrev ofList (rs : List R) := span { r | r ∈ rs }
@[simp] lemma ofList_nil : (ofList [] : Ideal R) = ⊥ :=
have : { r | r ∈ [] } = ∅ := Set.eq_empty_of_forall_not_mem (fun _ => List.not_mem_nil)
Eq.trans (congrArg span this) span_empty
@[simp] lemma ofList_append (rs₁ rs₂ : List R) :
ofList (rs₁ ++ rs₂) = ofList rs₁ ⊔ ofList rs₂ :=
have : { r | r ∈ rs₁ ++ rs₂ } = _ := Set.ext (fun _ => List.mem_append)
Eq.trans (congrArg span this) (span_union _ _)
lemma ofList_singleton (r : R) : ofList [r] = span {r} :=
congrArg span (Set.ext fun _ => List.mem_singleton)
@[simp] lemma ofList_cons (r : R) (rs : List R) :
ofList (r::rs) = span {r} ⊔ ofList rs :=
Eq.trans (ofList_append [r] rs) (congrArg (· ⊔ _) (ofList_singleton r))
@[simp] lemma map_ofList (f : R →+* S) (rs : List R) :
map f (ofList rs) = ofList (rs.map f) :=
Eq.trans (map_span f { r | r ∈ rs }) <| congrArg span <|
Set.ext (fun _ => List.mem_map.symm)
lemma ofList_cons_smul {R} [CommSemiring R] (r : R) (rs : List R) {M}
[AddCommMonoid M] [Module R M] (N : Submodule R M) :
ofList (r :: rs) • N = r • N ⊔ ofList rs • N := by
rw [ofList_cons, Submodule.sup_smul, Submodule.ideal_span_singleton_smul]
end Ideal
namespace Submodule
lemma smul_top_le_comap_smul_top [Semiring R] [AddCommMonoid M]
[AddCommMonoid M₂] [Module R M] [Module R M₂] (I : Ideal R)
(f : M →ₗ[R] M₂) : I • ⊤ ≤ comap f (I • ⊤) :=
map_le_iff_le_comap.mp <| le_of_eq_of_le (map_smul'' _ _ _) <|
smul_mono_right _ le_top
variable (M) [CommRing R] [AddCommGroup M] [AddCommGroup M₂]
[Module R M] [Module R M₂] (r : R) (rs : List R)
/-- The equivalence between M ⧸ (r₀, r₁, …, rₙ)M and (M ⧸ r₀M) ⧸ (r₁, …, rₙ) (M ⧸ r₀M). -/
def quotOfListConsSMulTopEquivQuotSMulTopInner :
(M ⧸ (Ideal.ofList (r :: rs) • ⊤ : Submodule R M)) ≃ₗ[R]
QuotSMulTop r M ⧸ (Ideal.ofList rs • ⊤ : Submodule R (QuotSMulTop r M)) :=
quotEquivOfEq _ _ (Ideal.ofList_cons_smul r rs ⊤) ≪≫ₗ
(quotientQuotientEquivQuotientSup (r • ⊤) (Ideal.ofList rs • ⊤)).symm ≪≫ₗ
quotEquivOfEq _ _ (by rw [map_smul'', map_top, range_mkQ])
/-- The equivalence between M ⧸ (r₀, r₁, …, rₙ)M and (M ⧸ (r₁, …, rₙ)) ⧸ r₀ (M ⧸ (r₁, …, rₙ)). -/
def quotOfListConsSMulTopEquivQuotSMulTopOuter :
(M ⧸ (Ideal.ofList (r :: rs) • ⊤ : Submodule R M)) ≃ₗ[R]
QuotSMulTop r (M ⧸ (Ideal.ofList rs • ⊤ : Submodule R M)) :=
quotEquivOfEq _ _ (Eq.trans (Ideal.ofList_cons_smul r rs ⊤) (sup_comm _ _)) ≪≫ₗ
(quotientQuotientEquivQuotientSup (Ideal.ofList rs • ⊤) (r • ⊤)).symm ≪≫ₗ
quotEquivOfEq _ _ (by rw [map_pointwise_smul, map_top, range_mkQ])
variable {M}
lemma quotOfListConsSMulTopEquivQuotSMulTopInner_naturality (f : M →ₗ[R] M₂) :
(quotOfListConsSMulTopEquivQuotSMulTopInner M₂ r rs).toLinearMap ∘ₗ
mapQ _ _ _ (smul_top_le_comap_smul_top (Ideal.ofList (r :: rs)) f) =
mapQ _ _ _ (smul_top_le_comap_smul_top _ (QuotSMulTop.map r f)) ∘ₗ
(quotOfListConsSMulTopEquivQuotSMulTopInner M r rs).toLinearMap :=
quot_hom_ext _ _ _ fun _ => rfl
lemma top_eq_ofList_cons_smul_iff :
(⊤ : Submodule R M) = Ideal.ofList (r :: rs) • ⊤ ↔
(⊤ : Submodule R (QuotSMulTop r M)) = Ideal.ofList rs • ⊤ := by
conv => congr <;> rw [eq_comm, ← subsingleton_quotient_iff_eq_top]
exact (quotOfListConsSMulTopEquivQuotSMulTopInner M r rs).toEquiv.subsingleton_congr
end Submodule
namespace RingTheory.Sequence
open scoped TensorProduct List
open Function Submodule QuotSMulTop
variable (S M)
section Definitions
/-
In theory, regularity of `rs : List α` on `M` makes sense as soon as
`[Monoid α]`, `[AddCommGroup M]`, and `[DistribMulAction α M]`.
Instead of `Ideal.ofList (rs.take i) • (⊤ : Submodule R M)` we use
`⨆ (j : Fin i), rs[j] • (⊤ : AddSubgroup M)`.
However it's not clear that this is a useful generalization.
If we add the assumption `[SMulCommClass α α M]` this is essentially the same
as focusing on the commutative ring case, by passing to the monoid ring
`ℤ[abelianization of α]`.
-/
variable [CommRing R] [AddCommGroup M] [Module R M]
open Ideal
/-- A sequence `[r₁, …, rₙ]` is weakly regular on `M` iff `rᵢ` is regular on
`M⧸(r₁, …, rᵢ₋₁)M` for all `1 ≤ i ≤ n`. -/
@[mk_iff]
structure IsWeaklyRegular (rs : List R) : Prop where
regular_mod_prev : ∀ i (h : i < rs.length),
IsSMulRegular (M ⧸ (ofList (rs.take i) • ⊤ : Submodule R M)) rs[i]
lemma isWeaklyRegular_iff_Fin (rs : List R) :
IsWeaklyRegular M rs ↔ ∀ (i : Fin rs.length),
IsSMulRegular (M ⧸ (ofList (rs.take i) • ⊤ : Submodule R M)) rs[i] :=
Iff.trans (isWeaklyRegular_iff M rs) (Iff.symm Fin.forall_iff)
/-- A weakly regular sequence `rs` on `M` is regular if also `M/rsM ≠ 0`. -/
@[mk_iff]
structure IsRegular (rs : List R) : Prop extends IsWeaklyRegular M rs where
top_ne_smul : (⊤ : Submodule R M) ≠ Ideal.ofList rs • ⊤
end Definitions
section Congr
variable {S M} [CommRing R] [CommRing S] [AddCommGroup M] [AddCommGroup M₂]
[Module R M] [Module S M₂]
{σ : R →+* S} {σ' : S →+* R} [RingHomInvPair σ σ'] [RingHomInvPair σ' σ]
open DistribMulAction AddSubgroup in
private lemma _root_.AddHom.map_smul_top_toAddSubgroup_of_surjective
{f : M →+ M₂} {as : List R} {bs : List S} (hf : Function.Surjective f)
(h : List.Forall₂ (fun r s => ∀ x, f (r • x) = s • f x) as bs) :
(Ideal.ofList as • ⊤ : Submodule R M).toAddSubgroup.map f =
(Ideal.ofList bs • ⊤ : Submodule S M₂).toAddSubgroup := by
induction h with
| nil =>
convert AddSubgroup.map_bot f using 1 <;>
rw [Ideal.ofList_nil, bot_smul, bot_toAddSubgroup]
| @cons r s _ _ h _ ih =>
conv => congr <;> rw [Ideal.ofList_cons, sup_smul, sup_toAddSubgroup,
ideal_span_singleton_smul, pointwise_smul_toAddSubgroup,
top_toAddSubgroup, pointwise_smul_def]
apply DFunLike.ext (f.comp (toAddMonoidEnd R M r))
((toAddMonoidEnd S M₂ s).comp f) at h
rw [AddSubgroup.map_sup, ih, map_map, h, ← map_map,
map_top_of_surjective f hf]
lemma _root_.AddEquiv.isWeaklyRegular_congr {e : M ≃+ M₂} {as bs}
(h : List.Forall₂ (fun (r : R) (s : S) => ∀ x, e (r • x) = s • e x) as bs) :
IsWeaklyRegular M as ↔ IsWeaklyRegular M₂ bs := by
conv => congr <;> rw [isWeaklyRegular_iff_Fin]
let e' i : (M ⧸ (Ideal.ofList (as.take i) • ⊤ : Submodule R M)) ≃+
M₂ ⧸ (Ideal.ofList (bs.take i) • ⊤ : Submodule S M₂) :=
QuotientAddGroup.congr _ _ e <|
AddHom.map_smul_top_toAddSubgroup_of_surjective e.surjective <|
List.forall₂_take i h
refine (finCongr h.length_eq).forall_congr @fun _ => (e' _).isSMulRegular_congr ?_
exact (mkQ_surjective _).forall.mpr fun _ => congrArg (mkQ _) (h.get _ _ _)
lemma _root_.LinearEquiv.isWeaklyRegular_congr' (e : M ≃ₛₗ[σ] M₂) (rs : List R) :
IsWeaklyRegular M rs ↔ IsWeaklyRegular M₂ (rs.map σ) :=
e.toAddEquiv.isWeaklyRegular_congr <| List.forall₂_map_right_iff.mpr <|
List.forall₂_same.mpr fun r _ x => e.map_smul' r x
lemma _root_.LinearEquiv.isWeaklyRegular_congr [Module R M₂] (e : M ≃ₗ[R] M₂) (rs : List R) :
IsWeaklyRegular M rs ↔ IsWeaklyRegular M₂ rs :=
Iff.trans (e.isWeaklyRegular_congr' rs) <| iff_of_eq <| congrArg _ rs.map_id
lemma _root_.AddEquiv.isRegular_congr {e : M ≃+ M₂} {as bs}
(h : List.Forall₂ (fun (r : R) (s : S) => ∀ x, e (r • x) = s • e x) as bs) :
IsRegular M as ↔ IsRegular M₂ bs := by
conv => congr <;> rw [isRegular_iff, ne_eq, eq_comm,
← subsingleton_quotient_iff_eq_top]
let e' := QuotientAddGroup.congr _ _ e <|
AddHom.map_smul_top_toAddSubgroup_of_surjective e.surjective h
exact and_congr (e.isWeaklyRegular_congr h) e'.subsingleton_congr.not
lemma _root_.LinearEquiv.isRegular_congr' (e : M ≃ₛₗ[σ] M₂) (rs : List R) :
IsRegular M rs ↔ IsRegular M₂ (rs.map σ) :=
e.toAddEquiv.isRegular_congr <| List.forall₂_map_right_iff.mpr <|
List.forall₂_same.mpr fun r _ x => e.map_smul' r x
lemma _root_.LinearEquiv.isRegular_congr [Module R M₂] (e : M ≃ₗ[R] M₂) (rs : List R) :
IsRegular M rs ↔ IsRegular M₂ rs :=
Iff.trans (e.isRegular_congr' rs) <| iff_of_eq <| congrArg _ rs.map_id
end Congr
lemma isWeaklyRegular_map_algebraMap_iff [CommRing R] [CommRing S]
[Algebra R S] [AddCommGroup M] [Module R M] [Module S M]
[IsScalarTower R S M] (rs : List R) :
IsWeaklyRegular M (rs.map (algebraMap R S)) ↔ IsWeaklyRegular M rs :=
(AddEquiv.refl M).isWeaklyRegular_congr <| List.forall₂_map_left_iff.mpr <|
List.forall₂_same.mpr fun r _ => algebraMap_smul S r
variable [CommRing R] [AddCommGroup M] [AddCommGroup M₂] [AddCommGroup M₃]
[AddCommGroup M₄] [Module R M] [Module R M₂] [Module R M₃] [Module R M₄]
@[simp]
lemma isWeaklyRegular_cons_iff (r : R) (rs : List R) :
IsWeaklyRegular M (r :: rs) ↔
IsSMulRegular M r ∧ IsWeaklyRegular (QuotSMulTop r M) rs :=
have := Eq.trans (congrArg (· • ⊤) Ideal.ofList_nil) (bot_smul ⊤)
let e i := quotOfListConsSMulTopEquivQuotSMulTopInner M r (rs.take i)
Iff.trans (isWeaklyRegular_iff_Fin _ _) <| Iff.trans Fin.forall_iff_succ <|
and_congr ((quotEquivOfEqBot _ this).isSMulRegular_congr r) <|
Iff.trans (forall_congr' fun i => (e i).isSMulRegular_congr (rs.get i))
(isWeaklyRegular_iff_Fin _ _).symm
lemma isWeaklyRegular_cons_iff' (r : R) (rs : List R) :
IsWeaklyRegular M (r :: rs) ↔
IsSMulRegular M r ∧
IsWeaklyRegular (QuotSMulTop r M)
(rs.map (Ideal.Quotient.mk (Ideal.span {r}))) :=
Iff.trans (isWeaklyRegular_cons_iff M r rs) <| and_congr_right' <|
Iff.symm <| isWeaklyRegular_map_algebraMap_iff (R ⧸ Ideal.span {r}) _ rs
@[simp]
lemma isRegular_cons_iff (r : R) (rs : List R) :
IsRegular M (r :: rs) ↔
IsSMulRegular M r ∧ IsRegular (QuotSMulTop r M) rs := by
rw [isRegular_iff, isRegular_iff, isWeaklyRegular_cons_iff M r rs,
ne_eq, top_eq_ofList_cons_smul_iff, and_assoc]
lemma isRegular_cons_iff' (r : R) (rs : List R) :
IsRegular M (r :: rs) ↔
IsSMulRegular M r ∧ IsRegular (QuotSMulTop r M)
(rs.map (Ideal.Quotient.mk (Ideal.span {r}))) := by
conv => congr <;> rw [isRegular_iff, ne_eq]
rw [isWeaklyRegular_cons_iff', ← restrictScalars_inj R (R ⧸ _),
← Ideal.map_ofList, ← Ideal.Quotient.algebraMap_eq, Ideal.smul_restrictScalars,
restrictScalars_top, top_eq_ofList_cons_smul_iff, and_assoc]
variable {M}
namespace IsWeaklyRegular
variable (R M) in
@[simp] lemma nil : IsWeaklyRegular M ([] : List R) :=
.mk (False.elim <| Nat.not_lt_zero · ·)
lemma cons {r : R} {rs : List R} (h1 : IsSMulRegular M r)
(h2 : IsWeaklyRegular (QuotSMulTop r M) rs) : IsWeaklyRegular M (r :: rs) :=
(isWeaklyRegular_cons_iff M r rs).mpr ⟨h1, h2⟩
lemma cons' {r : R} {rs : List R} (h1 : IsSMulRegular M r)
(h2 : IsWeaklyRegular (QuotSMulTop r M)
(rs.map (Ideal.Quotient.mk (Ideal.span {r})))) :
IsWeaklyRegular M (r :: rs) :=
(isWeaklyRegular_cons_iff' M r rs).mpr ⟨h1, h2⟩
/-- Weakly regular sequences can be inductively characterized by:
* The empty sequence is weakly regular on any module.
* If `r` is regular on `M` and `rs` is a weakly regular sequence on `M⧸rM` then
the sequence obtained from `rs` by prepending `r` is weakly regular on `M`.
This is the induction principle produced by the inductive definition above.
The motive will usually be valued in `Prop`, but `Sort*` works too. -/
@[induction_eliminator]
def recIterModByRegular
{motive : (M : Type v) → [AddCommGroup M] → [Module R M] → (rs : List R) →
IsWeaklyRegular M rs → Sort*}
(nil : (M : Type v) → [AddCommGroup M] → [Module R M] → motive M [] (nil R M))
(cons : {M : Type v} → [AddCommGroup M] → [Module R M] → (r : R) →
(rs : List R) → (h1 : IsSMulRegular M r) →
(h2 : IsWeaklyRegular (QuotSMulTop r M) rs) →
(ih : motive (QuotSMulTop r M) rs h2) → motive M (r :: rs) (cons h1 h2)) :
{M : Type v} → [AddCommGroup M] → [Module R M] → {rs : List R} →
(h : IsWeaklyRegular M rs) → motive M rs h
| M, _, _, [], _ => nil M
| M, _, _, r :: rs, h =>
let ⟨h1, h2⟩ := (isWeaklyRegular_cons_iff M r rs).mp h
cons r rs h1 h2 (recIterModByRegular nil cons h2)
/-- A simplified version of `IsWeaklyRegular.recIterModByRegular` where the
motive is not allowed to depend on the proof of `IsWeaklyRegular`. -/
def ndrecIterModByRegular
{motive : (M : Type v) → [AddCommGroup M] → [Module R M] → (rs : List R) → Sort*}
(nil : (M : Type v) → [AddCommGroup M] → [Module R M] → motive M [])
(cons : {M : Type v} → [AddCommGroup M] → [Module R M] → (r : R) →
(rs : List R) → IsSMulRegular M r → IsWeaklyRegular (QuotSMulTop r M) rs →
motive (QuotSMulTop r M) rs → motive M (r :: rs))
{M} [AddCommGroup M] [Module R M] {rs} :
IsWeaklyRegular M rs → motive M rs :=
recIterModByRegular (motive := fun M _ _ rs _ => motive M rs) nil cons
/-- An alternate induction principle from `IsWeaklyRegular.recIterModByRegular`
where we mod out by successive elements in both the module and the base ring.
This is useful for propagating certain properties of the initial `M`, e.g.
faithfulness or freeness, throughout the induction. -/
def recIterModByRegularWithRing
{motive : (R : Type u) → [CommRing R] → (M : Type v) → [AddCommGroup M] →
[Module R M] → (rs : List R) → IsWeaklyRegular M rs → Sort*}
(nil : (R : Type u) → [CommRing R] → (M : Type v) → [AddCommGroup M] →
[Module R M] → motive R M [] (nil R M))
(cons : {R : Type u} → [CommRing R] → {M : Type v} → [AddCommGroup M] →
[Module R M] → (r : R) → (rs : List R) → (h1 : IsSMulRegular M r) →
(h2 : IsWeaklyRegular (QuotSMulTop r M)
(rs.map (Ideal.Quotient.mk (Ideal.span {r})))) →
(ih : motive (R ⧸ Ideal.span {r}) (QuotSMulTop r M)
(rs.map (Ideal.Quotient.mk (Ideal.span {r}))) h2) →
motive R M (r :: rs) (cons' h1 h2)) :
{R : Type u} → [CommRing R] → {M : Type v} → [AddCommGroup M] →
[Module R M] → {rs : List R} → (h : IsWeaklyRegular M rs) → motive R M rs h
| R, _, M, _, _, [], _ => nil R M
| _, _, M, _, _, r :: rs, h =>
let ⟨h1, h2⟩ := (isWeaklyRegular_cons_iff' M r rs).mp h
cons r rs h1 h2 (recIterModByRegularWithRing nil cons h2)
termination_by _ _ _ _ _ rs => List.length rs
/-- A simplified version of `IsWeaklyRegular.recIterModByRegularWithRing` where
the motive is not allowed to depend on the proof of `IsWeaklyRegular`. -/
def ndrecWithRing
{motive : (R : Type u) → [CommRing R] → (M : Type v) →
[AddCommGroup M] → [Module R M] → (rs : List R) → Sort*}
(nil : (R : Type u) → [CommRing R] → (M : Type v) →
[AddCommGroup M] → [Module R M] → motive R M [])
(cons : {R : Type u} → [CommRing R] → {M : Type v} → [AddCommGroup M] →
[Module R M] → (r : R) → (rs : List R) → IsSMulRegular M r →
IsWeaklyRegular (QuotSMulTop r M)
(rs.map (Ideal.Quotient.mk (Ideal.span {r}))) →
motive (R ⧸ Ideal.span {r}) (QuotSMulTop r M)
(rs.map (Ideal.Quotient.mk (Ideal.span {r}))) → motive R M (r :: rs))
{R} [CommRing R] {M} [AddCommGroup M] [Module R M] {rs} :
IsWeaklyRegular M rs → motive R M rs :=
recIterModByRegularWithRing (motive := fun R _ M _ _ rs _ => motive R M rs)
nil cons
end IsWeaklyRegular
section
variable (M)
lemma isWeaklyRegular_singleton_iff (r : R) :
IsWeaklyRegular M [r] ↔ IsSMulRegular M r :=
| Iff.trans (isWeaklyRegular_cons_iff M r []) (and_iff_left (.nil R _))
lemma isWeaklyRegular_append_iff (rs₁ rs₂ : List R) :
IsWeaklyRegular M (rs₁ ++ rs₂) ↔
IsWeaklyRegular M rs₁ ∧
IsWeaklyRegular (M ⧸ (Ideal.ofList rs₁ • ⊤ : Submodule R M)) rs₂ := by
induction rs₁ generalizing M with
| nil =>
refine Iff.symm <| Iff.trans (and_iff_right (.nil R M)) ?_
refine (quotEquivOfEqBot _ ?_).isWeaklyRegular_congr rs₂
rw [Ideal.ofList_nil, bot_smul]
| cons r rs₁ ih =>
let e := quotOfListConsSMulTopEquivQuotSMulTopInner M r rs₁
| Mathlib/RingTheory/Regular/RegularSequence.lean | 369 | 381 |
/-
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, Mario Carneiro
-/
import Mathlib.Algebra.BigOperators.Ring.List
import Mathlib.Data.Nat.GCD.Basic
import Mathlib.Data.Nat.Prime.Basic
import Mathlib.Data.List.Prime
import Mathlib.Data.List.Sort
import Mathlib.Data.List.Perm.Subperm
/-!
# Prime numbers
This file deals with the factors of natural numbers.
## Important declarations
- `Nat.factors n`: the prime factorization of `n`
- `Nat.factors_unique`: uniqueness of the prime factorisation
-/
assert_not_exists Multiset
open Bool Subtype
open Nat
namespace Nat
/-- `primeFactorsList n` is the prime factorization of `n`, listed in increasing order. -/
def primeFactorsList : ℕ → List ℕ
| 0 => []
| 1 => []
| k + 2 =>
let m := minFac (k + 2)
m :: primeFactorsList ((k + 2) / m)
decreasing_by exact factors_lemma
@[simp]
theorem primeFactorsList_zero : primeFactorsList 0 = [] := by rw [primeFactorsList]
@[simp]
theorem primeFactorsList_one : primeFactorsList 1 = [] := by rw [primeFactorsList]
@[simp]
theorem primeFactorsList_two : primeFactorsList 2 = [2] := by simp [primeFactorsList]
theorem prime_of_mem_primeFactorsList {n : ℕ} : ∀ {p : ℕ}, p ∈ primeFactorsList n → Prime p := by
match n with
| 0 => simp
| 1 => simp
| k + 2 =>
intro p h
let m := minFac (k + 2)
have : (k + 2) / m < (k + 2) := factors_lemma
have h₁ : p = m ∨ p ∈ primeFactorsList ((k + 2) / m) :=
List.mem_cons.1 (by rwa [primeFactorsList] at h)
exact Or.casesOn h₁ (fun h₂ => h₂.symm ▸ minFac_prime (by simp)) prime_of_mem_primeFactorsList
theorem pos_of_mem_primeFactorsList {n p : ℕ} (h : p ∈ primeFactorsList n) : 0 < p :=
Prime.pos (prime_of_mem_primeFactorsList h)
theorem prod_primeFactorsList : ∀ {n}, n ≠ 0 → List.prod (primeFactorsList n) = n
| 0 => by simp
| 1 => by simp
| k + 2 => fun _ =>
let m := minFac (k + 2)
have : (k + 2) / m < (k + 2) := factors_lemma
show (primeFactorsList (k + 2)).prod = (k + 2) by
have h₁ : (k + 2) / m ≠ 0 := fun h => by
have : (k + 2) = 0 * m := (Nat.div_eq_iff_eq_mul_left (minFac_pos _) (minFac_dvd _)).1 h
rw [zero_mul] at this; exact (show k + 2 ≠ 0 by simp) this
rw [primeFactorsList, List.prod_cons, prod_primeFactorsList h₁,
Nat.mul_div_cancel' (minFac_dvd _)]
theorem primeFactorsList_prime {p : ℕ} (hp : Nat.Prime p) : p.primeFactorsList = [p] := by
have : p = p - 2 + 2 := Nat.eq_add_of_sub_eq hp.two_le rfl
rw [this, primeFactorsList]
simp only [Eq.symm this]
have : Nat.minFac p = p := (Nat.prime_def_minFac.mp hp).2
simp only [this, primeFactorsList, Nat.div_self (Nat.Prime.pos hp)]
theorem primeFactorsList_chain {n : ℕ} :
∀ {a}, (∀ p, Prime p → p ∣ n → a ≤ p) → List.Chain (· ≤ ·) a (primeFactorsList n) := by
match n with
| 0 => simp
| 1 => simp
| k + 2 =>
intro a h
let m := minFac (k + 2)
have : (k + 2) / m < (k + 2) := factors_lemma
rw [primeFactorsList]
refine List.Chain.cons ((le_minFac.2 h).resolve_left (by simp)) (primeFactorsList_chain ?_)
exact fun p pp d => minFac_le_of_dvd pp.two_le (d.trans <| div_dvd_of_dvd <| minFac_dvd _)
theorem primeFactorsList_chain_2 (n) : List.Chain (· ≤ ·) 2 (primeFactorsList n) :=
primeFactorsList_chain fun _ pp _ => pp.two_le
theorem primeFactorsList_chain' (n) : List.Chain' (· ≤ ·) (primeFactorsList n) :=
@List.Chain'.tail _ _ (_ :: _) (primeFactorsList_chain_2 _)
theorem primeFactorsList_sorted (n : ℕ) : List.Sorted (· ≤ ·) (primeFactorsList n) :=
List.chain'_iff_pairwise.1 (primeFactorsList_chain' _)
/-- `primeFactorsList` can be constructed inductively by extracting `minFac`, for sufficiently
large `n`. -/
theorem primeFactorsList_add_two (n : ℕ) :
primeFactorsList (n + 2) = minFac (n + 2) :: primeFactorsList ((n + 2) / minFac (n + 2)) := by
rw [primeFactorsList]
@[simp]
theorem primeFactorsList_eq_nil (n : ℕ) : n.primeFactorsList = [] ↔ n = 0 ∨ n = 1 := by
constructor <;> intro h
· rcases n with (_ | _ | n)
· exact Or.inl rfl
· exact Or.inr rfl
· rw [primeFactorsList] at h
injection h
· rcases h with (rfl | rfl)
· exact primeFactorsList_zero
· exact primeFactorsList_one
open scoped List in
theorem eq_of_perm_primeFactorsList {a b : ℕ} (ha : a ≠ 0) (hb : b ≠ 0)
(h : a.primeFactorsList ~ b.primeFactorsList) : a = b := by
simpa [prod_primeFactorsList ha, prod_primeFactorsList hb] using List.Perm.prod_eq h
section
open List
theorem mem_primeFactorsList_iff_dvd {n p : ℕ} (hn : n ≠ 0) (hp : Prime p) :
p ∈ primeFactorsList n ↔ p ∣ n where
mp h := prod_primeFactorsList hn ▸ List.dvd_prod h
mpr h := mem_list_primes_of_dvd_prod (prime_iff.mp hp)
(fun _ h ↦ prime_iff.mp (prime_of_mem_primeFactorsList h)) ((prod_primeFactorsList hn).symm ▸ h)
theorem dvd_of_mem_primeFactorsList {n p : ℕ} (h : p ∈ n.primeFactorsList) : p ∣ n := by
rcases n.eq_zero_or_pos with (rfl | hn)
· exact dvd_zero p
· rwa [← mem_primeFactorsList_iff_dvd hn.ne' (prime_of_mem_primeFactorsList h)]
theorem mem_primeFactorsList {n p} (hn : n ≠ 0) : p ∈ primeFactorsList n ↔ Prime p ∧ p ∣ n :=
⟨fun h => ⟨prime_of_mem_primeFactorsList h, dvd_of_mem_primeFactorsList h⟩, fun ⟨hprime, hdvd⟩ =>
(mem_primeFactorsList_iff_dvd hn hprime).mpr hdvd⟩
@[simp] lemma mem_primeFactorsList' {n p} : p ∈ n.primeFactorsList ↔ p.Prime ∧ p ∣ n ∧ n ≠ 0 := by
cases n <;> simp [mem_primeFactorsList, *]
theorem le_of_mem_primeFactorsList {n p : ℕ} (h : p ∈ n.primeFactorsList) : p ≤ n := by
rcases n.eq_zero_or_pos with (rfl | hn)
· rw [primeFactorsList_zero] at h
cases h
· exact le_of_dvd hn (dvd_of_mem_primeFactorsList h)
/-- **Fundamental theorem of arithmetic** -/
theorem primeFactorsList_unique {n : ℕ} {l : List ℕ} (h₁ : prod l = n) (h₂ : ∀ p ∈ l, Prime p) :
l ~ primeFactorsList n := by
refine perm_of_prod_eq_prod ?_ ?_ ?_
· rw [h₁]
refine (prod_primeFactorsList ?_).symm
rintro rfl
rw [prod_eq_zero_iff] at h₁
exact Prime.ne_zero (h₂ 0 h₁) rfl
· simp_rw [← prime_iff]
exact h₂
· simp_rw [← prime_iff]
exact fun p => prime_of_mem_primeFactorsList
theorem Prime.primeFactorsList_pow {p : ℕ} (hp : p.Prime) (n : ℕ) :
(p ^ n).primeFactorsList = List.replicate n p := by
symm
rw [← List.replicate_perm]
apply Nat.primeFactorsList_unique (List.prod_replicate n p)
intro q hq
rwa [eq_of_mem_replicate hq]
theorem eq_prime_pow_of_unique_prime_dvd {n p : ℕ} (hpos : n ≠ 0)
(h : ∀ {d}, Nat.Prime d → d ∣ n → d = p) : n = p ^ n.primeFactorsList.length := by
set k := n.primeFactorsList.length
rw [← prod_primeFactorsList hpos, ← prod_replicate k p, eq_replicate_of_mem fun d hd =>
h (prime_of_mem_primeFactorsList hd) (dvd_of_mem_primeFactorsList hd)]
/-- For positive `a` and `b`, the prime factors of `a * b` are the union of those of `a` and `b` -/
theorem perm_primeFactorsList_mul {a b : ℕ} (ha : a ≠ 0) (hb : b ≠ 0) :
(a * b).primeFactorsList ~ a.primeFactorsList ++ b.primeFactorsList := by
refine (primeFactorsList_unique ?_ ?_).symm
· rw [List.prod_append, prod_primeFactorsList ha, prod_primeFactorsList hb]
· intro p hp
rw [List.mem_append] at hp
rcases hp with hp' | hp' <;> exact prime_of_mem_primeFactorsList hp'
/-- For coprime `a` and `b`, the prime factors of `a * b` are the union of those of `a` and `b` -/
theorem perm_primeFactorsList_mul_of_coprime {a b : ℕ} (hab : Coprime a b) :
(a * b).primeFactorsList ~ a.primeFactorsList ++ b.primeFactorsList := by
rcases a.eq_zero_or_pos with (rfl | ha)
· simp [(coprime_zero_left _).mp hab]
rcases b.eq_zero_or_pos with (rfl | hb)
· simp [(coprime_zero_right _).mp hab]
exact perm_primeFactorsList_mul ha.ne' hb.ne'
theorem primeFactorsList_sublist_right {n k : ℕ} (h : k ≠ 0) :
n.primeFactorsList <+ (n * k).primeFactorsList := by
rcases n with - | hn
· simp [zero_mul]
apply sublist_of_subperm_of_sorted _ (primeFactorsList_sorted _) (primeFactorsList_sorted _)
simp only [(perm_primeFactorsList_mul (Nat.succ_ne_zero _) h).subperm_left]
exact (sublist_append_left _ _).subperm
theorem primeFactorsList_sublist_of_dvd {n k : ℕ} (h : n ∣ k) (h' : k ≠ 0) :
n.primeFactorsList <+ k.primeFactorsList := by
obtain ⟨a, rfl⟩ := h
exact primeFactorsList_sublist_right (right_ne_zero_of_mul h')
theorem primeFactorsList_subset_right {n k : ℕ} (h : k ≠ 0) :
n.primeFactorsList ⊆ (n * k).primeFactorsList :=
(primeFactorsList_sublist_right h).subset
theorem primeFactorsList_subset_of_dvd {n k : ℕ} (h : n ∣ k) (h' : k ≠ 0) :
n.primeFactorsList ⊆ k.primeFactorsList :=
(primeFactorsList_sublist_of_dvd h h').subset
theorem dvd_of_primeFactorsList_subperm {a b : ℕ} (ha : a ≠ 0)
(h : a.primeFactorsList <+~ b.primeFactorsList) : a ∣ b := by
rcases b.eq_zero_or_pos with (rfl | hb)
· exact dvd_zero _
rcases a with (_ | _ | a)
· exact (ha rfl).elim
· exact one_dvd _
use (b.primeFactorsList.diff a.succ.succ.primeFactorsList).prod
nth_rw 1 [← Nat.prod_primeFactorsList ha]
rw [← List.prod_append,
List.Perm.prod_eq <| List.subperm_append_diff_self_of_count_le <| List.subperm_ext_iff.mp h,
Nat.prod_primeFactorsList hb.ne']
theorem replicate_subperm_primeFactorsList_iff {a b n : ℕ} (ha : Prime a) (hb : b ≠ 0) :
replicate n a <+~ primeFactorsList b ↔ a ^ n ∣ b := by
induction n generalizing b with
| zero => simp
| succ n ih =>
constructor
| · rw [List.subperm_iff]
rintro ⟨u, hu1, hu2⟩
rw [← Nat.prod_primeFactorsList hb, ← hu1.prod_eq, ← prod_replicate]
exact hu2.prod_dvd_prod
· rintro ⟨c, rfl⟩
rw [Ne, pow_succ', mul_assoc, mul_eq_zero, _root_.not_or] at hb
rw [pow_succ', mul_assoc, replicate_succ,
(Nat.perm_primeFactorsList_mul hb.1 hb.2).subperm_left, primeFactorsList_prime ha,
singleton_append, subperm_cons, ih hb.2]
exact dvd_mul_right _ _
end
| Mathlib/Data/Nat/Factors.lean | 245 | 257 |
/-
Copyright (c) 2020 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Anatole Dedecker, Sébastien Gouëzel, Yury Kudryashov, Dylan MacKenzie, Patrick Massot
-/
import Mathlib.Algebra.BigOperators.Module
import Mathlib.Algebra.Order.Field.Power
import Mathlib.Algebra.Polynomial.Monic
import Mathlib.Analysis.Asymptotics.Lemmas
import Mathlib.Analysis.Normed.Ring.InfiniteSum
import Mathlib.Analysis.Normed.Module.Basic
import Mathlib.Analysis.SpecificLimits.Basic
import Mathlib.Data.List.TFAE
import Mathlib.Data.Nat.Choose.Bounds
import Mathlib.Order.Filter.AtTopBot.ModEq
import Mathlib.RingTheory.Polynomial.Pochhammer
import Mathlib.Tactic.NoncommRing
/-!
# A collection of specific limit computations
This file contains important specific limit computations in (semi-)normed groups/rings/spaces, as
well as such computations in `ℝ` when the natural proof passes through a fact about normed spaces.
-/
noncomputable section
open Set Function Filter Finset Metric Asymptotics Topology Nat NNReal ENNReal
variable {α : Type*}
/-! ### Powers -/
theorem isLittleO_pow_pow_of_lt_left {r₁ r₂ : ℝ} (h₁ : 0 ≤ r₁) (h₂ : r₁ < r₂) :
(fun n : ℕ ↦ r₁ ^ n) =o[atTop] fun n ↦ r₂ ^ n :=
have H : 0 < r₂ := h₁.trans_lt h₂
(isLittleO_of_tendsto fun _ hn ↦ False.elim <| H.ne' <| pow_eq_zero hn) <|
(tendsto_pow_atTop_nhds_zero_of_lt_one
(div_nonneg h₁ (h₁.trans h₂.le)) ((div_lt_one H).2 h₂)).congr fun _ ↦ div_pow _ _ _
theorem isBigO_pow_pow_of_le_left {r₁ r₂ : ℝ} (h₁ : 0 ≤ r₁) (h₂ : r₁ ≤ r₂) :
(fun n : ℕ ↦ r₁ ^ n) =O[atTop] fun n ↦ r₂ ^ n :=
h₂.eq_or_lt.elim (fun h ↦ h ▸ isBigO_refl _ _) fun h ↦ (isLittleO_pow_pow_of_lt_left h₁ h).isBigO
theorem isLittleO_pow_pow_of_abs_lt_left {r₁ r₂ : ℝ} (h : |r₁| < |r₂|) :
(fun n : ℕ ↦ r₁ ^ n) =o[atTop] fun n ↦ r₂ ^ n := by
refine (IsLittleO.of_norm_left ?_).of_norm_right
exact (isLittleO_pow_pow_of_lt_left (abs_nonneg r₁) h).congr (pow_abs r₁) (pow_abs r₂)
open List in
/-- Various statements equivalent to the fact that `f n` grows exponentially slower than `R ^ n`.
* 0: $f n = o(a ^ n)$ for some $-R < a < R$;
* 1: $f n = o(a ^ n)$ for some $0 < a < R$;
* 2: $f n = O(a ^ n)$ for some $-R < a < R$;
* 3: $f n = O(a ^ n)$ for some $0 < a < R$;
* 4: there exist `a < R` and `C` such that one of `C` and `R` is positive and $|f n| ≤ Ca^n$
for all `n`;
* 5: there exists `0 < a < R` and a positive `C` such that $|f n| ≤ Ca^n$ for all `n`;
* 6: there exists `a < R` such that $|f n| ≤ a ^ n$ for sufficiently large `n`;
* 7: there exists `0 < a < R` such that $|f n| ≤ a ^ n$ for sufficiently large `n`.
NB: For backwards compatibility, if you add more items to the list, please append them at the end of
the list. -/
theorem TFAE_exists_lt_isLittleO_pow (f : ℕ → ℝ) (R : ℝ) :
TFAE
[∃ a ∈ Ioo (-R) R, f =o[atTop] (a ^ ·), ∃ a ∈ Ioo 0 R, f =o[atTop] (a ^ ·),
∃ a ∈ Ioo (-R) R, f =O[atTop] (a ^ ·), ∃ a ∈ Ioo 0 R, f =O[atTop] (a ^ ·),
∃ a < R, ∃ C : ℝ, (0 < C ∨ 0 < R) ∧ ∀ n, |f n| ≤ C * a ^ n,
∃ a ∈ Ioo 0 R, ∃ C > 0, ∀ n, |f n| ≤ C * a ^ n, ∃ a < R, ∀ᶠ n in atTop, |f n| ≤ a ^ n,
∃ a ∈ Ioo 0 R, ∀ᶠ n in atTop, |f n| ≤ a ^ n] := by
have A : Ico 0 R ⊆ Ioo (-R) R :=
fun x hx ↦ ⟨(neg_lt_zero.2 (hx.1.trans_lt hx.2)).trans_le hx.1, hx.2⟩
have B : Ioo 0 R ⊆ Ioo (-R) R := Subset.trans Ioo_subset_Ico_self A
-- First we prove that 1-4 are equivalent using 2 → 3 → 4, 1 → 3, and 2 → 1
tfae_have 1 → 3 := fun ⟨a, ha, H⟩ ↦ ⟨a, ha, H.isBigO⟩
tfae_have 2 → 1 := fun ⟨a, ha, H⟩ ↦ ⟨a, B ha, H⟩
tfae_have 3 → 2
| ⟨a, ha, H⟩ => by
rcases exists_between (abs_lt.2 ha) with ⟨b, hab, hbR⟩
exact ⟨b, ⟨(abs_nonneg a).trans_lt hab, hbR⟩,
H.trans_isLittleO (isLittleO_pow_pow_of_abs_lt_left (hab.trans_le (le_abs_self b)))⟩
tfae_have 2 → 4 := fun ⟨a, ha, H⟩ ↦ ⟨a, ha, H.isBigO⟩
tfae_have 4 → 3 := fun ⟨a, ha, H⟩ ↦ ⟨a, B ha, H⟩
-- Add 5 and 6 using 4 → 6 → 5 → 3
tfae_have 4 → 6
| ⟨a, ha, H⟩ => by
rcases bound_of_isBigO_nat_atTop H with ⟨C, hC₀, hC⟩
refine ⟨a, ha, C, hC₀, fun n ↦ ?_⟩
simpa only [Real.norm_eq_abs, abs_pow, abs_of_nonneg ha.1.le] using hC (pow_ne_zero n ha.1.ne')
tfae_have 6 → 5 := fun ⟨a, ha, C, H₀, H⟩ ↦ ⟨a, ha.2, C, Or.inl H₀, H⟩
tfae_have 5 → 3
| ⟨a, ha, C, h₀, H⟩ => by
rcases sign_cases_of_C_mul_pow_nonneg fun n ↦ (abs_nonneg _).trans (H n) with (rfl | ⟨hC₀, ha₀⟩)
· obtain rfl : f = 0 := by
ext n
simpa using H n
simp only [lt_irrefl, false_or] at h₀
exact ⟨0, ⟨neg_lt_zero.2 h₀, h₀⟩, isBigO_zero _ _⟩
exact ⟨a, A ⟨ha₀, ha⟩,
isBigO_of_le' _ fun n ↦ (H n).trans <| mul_le_mul_of_nonneg_left (le_abs_self _) hC₀.le⟩
-- Add 7 and 8 using 2 → 8 → 7 → 3
tfae_have 2 → 8
| ⟨a, ha, H⟩ => by
refine ⟨a, ha, (H.def zero_lt_one).mono fun n hn ↦ ?_⟩
rwa [Real.norm_eq_abs, Real.norm_eq_abs, one_mul, abs_pow, abs_of_pos ha.1] at hn
tfae_have 8 → 7 := fun ⟨a, ha, H⟩ ↦ ⟨a, ha.2, H⟩
tfae_have 7 → 3
| ⟨a, ha, H⟩ => by
refine ⟨a, A ⟨?_, ha⟩, .of_norm_eventuallyLE H⟩
exact nonneg_of_eventually_pow_nonneg (H.mono fun n ↦ (abs_nonneg _).trans)
tfae_finish
/-- For any natural `k` and a real `r > 1` we have `n ^ k = o(r ^ n)` as `n → ∞`. -/
theorem isLittleO_pow_const_const_pow_of_one_lt {R : Type*} [NormedRing R] (k : ℕ) {r : ℝ}
(hr : 1 < r) : (fun n ↦ (n : R) ^ k : ℕ → R) =o[atTop] fun n ↦ r ^ n := by
have : Tendsto (fun x : ℝ ↦ x ^ k) (𝓝[>] 1) (𝓝 1) :=
((continuous_id.pow k).tendsto' (1 : ℝ) 1 (one_pow _)).mono_left inf_le_left
obtain ⟨r' : ℝ, hr' : r' ^ k < r, h1 : 1 < r'⟩ :=
((this.eventually (gt_mem_nhds hr)).and self_mem_nhdsWithin).exists
have h0 : 0 ≤ r' := zero_le_one.trans h1.le
suffices (fun n ↦ (n : R) ^ k : ℕ → R) =O[atTop] fun n : ℕ ↦ (r' ^ k) ^ n from
this.trans_isLittleO (isLittleO_pow_pow_of_lt_left (pow_nonneg h0 _) hr')
conv in (r' ^ _) ^ _ => rw [← pow_mul, mul_comm, pow_mul]
suffices ∀ n : ℕ, ‖(n : R)‖ ≤ (r' - 1)⁻¹ * ‖(1 : R)‖ * ‖r' ^ n‖ from
(isBigO_of_le' _ this).pow _
intro n
rw [mul_right_comm]
refine n.norm_cast_le.trans (mul_le_mul_of_nonneg_right ?_ (norm_nonneg _))
simpa [_root_.div_eq_inv_mul, Real.norm_eq_abs, abs_of_nonneg h0] using n.cast_le_pow_div_sub h1
/-- For a real `r > 1` we have `n = o(r ^ n)` as `n → ∞`. -/
theorem isLittleO_coe_const_pow_of_one_lt {R : Type*} [NormedRing R] {r : ℝ} (hr : 1 < r) :
((↑) : ℕ → R) =o[atTop] fun n ↦ r ^ n := by
simpa only [pow_one] using @isLittleO_pow_const_const_pow_of_one_lt R _ 1 _ hr
/-- If `‖r₁‖ < r₂`, then for any natural `k` we have `n ^ k r₁ ^ n = o (r₂ ^ n)` as `n → ∞`. -/
theorem isLittleO_pow_const_mul_const_pow_const_pow_of_norm_lt {R : Type*} [NormedRing R] (k : ℕ)
{r₁ : R} {r₂ : ℝ} (h : ‖r₁‖ < r₂) :
(fun n ↦ (n : R) ^ k * r₁ ^ n : ℕ → R) =o[atTop] fun n ↦ r₂ ^ n := by
by_cases h0 : r₁ = 0
· refine (isLittleO_zero _ _).congr' (mem_atTop_sets.2 <| ⟨1, fun n hn ↦ ?_⟩) EventuallyEq.rfl
simp [zero_pow (one_le_iff_ne_zero.1 hn), h0]
rw [← Ne, ← norm_pos_iff] at h0
have A : (fun n ↦ (n : R) ^ k : ℕ → R) =o[atTop] fun n ↦ (r₂ / ‖r₁‖) ^ n :=
isLittleO_pow_const_const_pow_of_one_lt k ((one_lt_div h0).2 h)
suffices (fun n ↦ r₁ ^ n) =O[atTop] fun n ↦ ‖r₁‖ ^ n by
simpa [div_mul_cancel₀ _ (pow_pos h0 _).ne', div_pow] using A.mul_isBigO this
exact .of_norm_eventuallyLE <| eventually_norm_pow_le r₁
theorem tendsto_pow_const_div_const_pow_of_one_lt (k : ℕ) {r : ℝ} (hr : 1 < r) :
Tendsto (fun n ↦ (n : ℝ) ^ k / r ^ n : ℕ → ℝ) atTop (𝓝 0) :=
(isLittleO_pow_const_const_pow_of_one_lt k hr).tendsto_div_nhds_zero
/-- If `|r| < 1`, then `n ^ k r ^ n` tends to zero for any natural `k`. -/
theorem tendsto_pow_const_mul_const_pow_of_abs_lt_one (k : ℕ) {r : ℝ} (hr : |r| < 1) :
Tendsto (fun n ↦ (n : ℝ) ^ k * r ^ n : ℕ → ℝ) atTop (𝓝 0) := by
by_cases h0 : r = 0
· exact tendsto_const_nhds.congr'
(mem_atTop_sets.2 ⟨1, fun n hn ↦ by simp [zero_lt_one.trans_le hn |>.ne', h0]⟩)
have hr' : 1 < |r|⁻¹ := (one_lt_inv₀ (abs_pos.2 h0)).2 hr
rw [tendsto_zero_iff_norm_tendsto_zero]
simpa [div_eq_mul_inv] using tendsto_pow_const_div_const_pow_of_one_lt k hr'
/-- For `k ≠ 0` and a constant `r` the function `r / n ^ k` tends to zero. -/
lemma tendsto_const_div_pow (r : ℝ) (k : ℕ) (hk : k ≠ 0) :
Tendsto (fun n : ℕ => r / n ^ k) atTop (𝓝 0) := by
simpa using Filter.Tendsto.const_div_atTop (tendsto_natCast_atTop_atTop (R := ℝ).comp
(tendsto_pow_atTop hk) ) r
/-- If `0 ≤ r < 1`, then `n ^ k r ^ n` tends to zero for any natural `k`.
This is a specialized version of `tendsto_pow_const_mul_const_pow_of_abs_lt_one`, singled out
for ease of application. -/
theorem tendsto_pow_const_mul_const_pow_of_lt_one (k : ℕ) {r : ℝ} (hr : 0 ≤ r) (h'r : r < 1) :
Tendsto (fun n ↦ (n : ℝ) ^ k * r ^ n : ℕ → ℝ) atTop (𝓝 0) :=
tendsto_pow_const_mul_const_pow_of_abs_lt_one k (abs_lt.2 ⟨neg_one_lt_zero.trans_le hr, h'r⟩)
/-- If `|r| < 1`, then `n * r ^ n` tends to zero. -/
theorem tendsto_self_mul_const_pow_of_abs_lt_one {r : ℝ} (hr : |r| < 1) :
Tendsto (fun n ↦ n * r ^ n : ℕ → ℝ) atTop (𝓝 0) := by
simpa only [pow_one] using tendsto_pow_const_mul_const_pow_of_abs_lt_one 1 hr
/-- If `0 ≤ r < 1`, then `n * r ^ n` tends to zero. This is a specialized version of
`tendsto_self_mul_const_pow_of_abs_lt_one`, singled out for ease of application. -/
theorem tendsto_self_mul_const_pow_of_lt_one {r : ℝ} (hr : 0 ≤ r) (h'r : r < 1) :
Tendsto (fun n ↦ n * r ^ n : ℕ → ℝ) atTop (𝓝 0) := by
simpa only [pow_one] using tendsto_pow_const_mul_const_pow_of_lt_one 1 hr h'r
/-- In a normed ring, the powers of an element x with `‖x‖ < 1` tend to zero. -/
theorem tendsto_pow_atTop_nhds_zero_of_norm_lt_one {R : Type*} [SeminormedRing R] {x : R}
(h : ‖x‖ < 1) :
Tendsto (fun n : ℕ ↦ x ^ n) atTop (𝓝 0) := by
apply squeeze_zero_norm' (eventually_norm_pow_le x)
exact tendsto_pow_atTop_nhds_zero_of_lt_one (norm_nonneg _) h
theorem tendsto_pow_atTop_nhds_zero_of_abs_lt_one {r : ℝ} (h : |r| < 1) :
Tendsto (fun n : ℕ ↦ r ^ n) atTop (𝓝 0) :=
tendsto_pow_atTop_nhds_zero_of_norm_lt_one h
lemma tendsto_pow_atTop_nhds_zero_iff_norm_lt_one {R : Type*} [SeminormedRing R] [NormMulClass R]
{x : R} : Tendsto (fun n : ℕ ↦ x ^ n) atTop (𝓝 0) ↔ ‖x‖ < 1 := by
-- this proof is slightly fiddly since `‖x ^ n‖ = ‖x‖ ^ n` might not hold for `n = 0`
refine ⟨?_, tendsto_pow_atTop_nhds_zero_of_norm_lt_one⟩
rw [← abs_of_nonneg (norm_nonneg _), ← tendsto_pow_atTop_nhds_zero_iff,
tendsto_zero_iff_norm_tendsto_zero]
apply Tendsto.congr'
filter_upwards [eventually_ge_atTop 1] with n hn
induction n, hn using Nat.le_induction with
| base => simp
| succ n hn IH => simp [norm_pow, pow_succ, IH]
/-! ### Geometric series -/
/-- A normed ring has summable geometric series if, for all `ξ` of norm `< 1`, the geometric series
`∑ ξ ^ n` converges. This holds both in complete normed rings and in normed fields, providing a
convenient abstraction of these two classes to avoid repeating the same proofs. -/
class HasSummableGeomSeries (K : Type*) [NormedRing K] : Prop where
summable_geometric_of_norm_lt_one : ∀ (ξ : K), ‖ξ‖ < 1 → Summable (fun n ↦ ξ ^ n)
lemma summable_geometric_of_norm_lt_one {K : Type*} [NormedRing K] [HasSummableGeomSeries K]
{x : K} (h : ‖x‖ < 1) : Summable (fun n ↦ x ^ n) :=
HasSummableGeomSeries.summable_geometric_of_norm_lt_one x h
instance {R : Type*} [NormedRing R] [CompleteSpace R] : HasSummableGeomSeries R := by
constructor
intro x hx
have h1 : Summable fun n : ℕ ↦ ‖x‖ ^ n := summable_geometric_of_lt_one (norm_nonneg _) hx
exact h1.of_norm_bounded_eventually_nat _ (eventually_norm_pow_le x)
section HasSummableGeometricSeries
variable {R : Type*} [NormedRing R]
open NormedSpace
/-- Bound for the sum of a geometric series in a normed ring. This formula does not assume that the
normed ring satisfies the axiom `‖1‖ = 1`. -/
theorem tsum_geometric_le_of_norm_lt_one (x : R) (h : ‖x‖ < 1) :
‖∑' n : ℕ, x ^ n‖ ≤ ‖(1 : R)‖ - 1 + (1 - ‖x‖)⁻¹ := by
by_cases hx : Summable (fun n ↦ x ^ n)
· rw [hx.tsum_eq_zero_add]
simp only [_root_.pow_zero]
refine le_trans (norm_add_le _ _) ?_
have : ‖∑' b : ℕ, (fun n ↦ x ^ (n + 1)) b‖ ≤ (1 - ‖x‖)⁻¹ - 1 := by
refine tsum_of_norm_bounded ?_ fun b ↦ norm_pow_le' _ (Nat.succ_pos b)
convert (hasSum_nat_add_iff' 1).mpr (hasSum_geometric_of_lt_one (norm_nonneg x) h)
simp
linarith
· simp [tsum_eq_zero_of_not_summable hx]
nontriviality R
have : 1 ≤ ‖(1 : R)‖ := one_le_norm_one R
have : 0 ≤ (1 - ‖x‖) ⁻¹ := inv_nonneg.2 (by linarith)
linarith
variable [HasSummableGeomSeries R]
theorem geom_series_mul_neg (x : R) (h : ‖x‖ < 1) : (∑' i : ℕ, x ^ i) * (1 - x) = 1 := by
have := (summable_geometric_of_norm_lt_one h).hasSum.mul_right (1 - x)
refine tendsto_nhds_unique this.tendsto_sum_nat ?_
have : Tendsto (fun n : ℕ ↦ 1 - x ^ n) atTop (𝓝 1) := by
simpa using tendsto_const_nhds.sub (tendsto_pow_atTop_nhds_zero_of_norm_lt_one h)
convert← this
rw [← geom_sum_mul_neg, Finset.sum_mul]
theorem mul_neg_geom_series (x : R) (h : ‖x‖ < 1) : (1 - x) * ∑' i : ℕ, x ^ i = 1 := by
have := (summable_geometric_of_norm_lt_one h).hasSum.mul_left (1 - x)
refine tendsto_nhds_unique this.tendsto_sum_nat ?_
have : Tendsto (fun n : ℕ ↦ 1 - x ^ n) atTop (𝓝 1) := by
simpa using tendsto_const_nhds.sub (tendsto_pow_atTop_nhds_zero_of_norm_lt_one h)
convert← this
rw [← mul_neg_geom_sum, Finset.mul_sum]
theorem geom_series_succ (x : R) (h : ‖x‖ < 1) : ∑' i : ℕ, x ^ (i + 1) = ∑' i : ℕ, x ^ i - 1 := by
rw [eq_sub_iff_add_eq, (summable_geometric_of_norm_lt_one h).tsum_eq_zero_add,
pow_zero, add_comm]
theorem geom_series_mul_shift (x : R) (h : ‖x‖ < 1) :
x * ∑' i : ℕ, x ^ i = ∑' i : ℕ, x ^ (i + 1) := by
simp_rw [← (summable_geometric_of_norm_lt_one h).tsum_mul_left, ← _root_.pow_succ']
theorem geom_series_mul_one_add (x : R) (h : ‖x‖ < 1) :
(1 + x) * ∑' i : ℕ, x ^ i = 2 * ∑' i : ℕ, x ^ i - 1 := by
rw [add_mul, one_mul, geom_series_mul_shift x h, geom_series_succ x h, two_mul, add_sub_assoc]
/-- In a normed ring with summable geometric series, a perturbation of `1` by an element `t`
of distance less than `1` from `1` is a unit. Here we construct its `Units` structure. -/
@[simps val]
def Units.oneSub (t : R) (h : ‖t‖ < 1) : Rˣ where
val := 1 - t
inv := ∑' n : ℕ, t ^ n
val_inv := mul_neg_geom_series t h
inv_val := geom_series_mul_neg t h
theorem geom_series_eq_inverse (x : R) (h : ‖x‖ < 1) :
∑' i, x ^ i = Ring.inverse (1 - x) := by
change (Units.oneSub x h) ⁻¹ = Ring.inverse (1 - x)
rw [← Ring.inverse_unit]
rfl
theorem hasSum_geom_series_inverse (x : R) (h : ‖x‖ < 1) :
HasSum (fun i ↦ x ^ i) (Ring.inverse (1 - x)) := by
convert (summable_geometric_of_norm_lt_one h).hasSum
exact (geom_series_eq_inverse x h).symm
lemma isUnit_one_sub_of_norm_lt_one {x : R} (h : ‖x‖ < 1) : IsUnit (1 - x) :=
⟨Units.oneSub x h, rfl⟩
end HasSummableGeometricSeries
section Geometric
variable {K : Type*} [NormedDivisionRing K] {ξ : K}
theorem hasSum_geometric_of_norm_lt_one (h : ‖ξ‖ < 1) : HasSum (fun n : ℕ ↦ ξ ^ n) (1 - ξ)⁻¹ := by
have xi_ne_one : ξ ≠ 1 := by
contrapose! h
simp [h]
have A : Tendsto (fun n ↦ (ξ ^ n - 1) * (ξ - 1)⁻¹) atTop (𝓝 ((0 - 1) * (ξ - 1)⁻¹)) :=
((tendsto_pow_atTop_nhds_zero_of_norm_lt_one h).sub tendsto_const_nhds).mul tendsto_const_nhds
rw [hasSum_iff_tendsto_nat_of_summable_norm]
· simpa [geom_sum_eq, xi_ne_one, neg_inv, div_eq_mul_inv] using A
· simp [norm_pow, summable_geometric_of_lt_one (norm_nonneg _) h]
instance : HasSummableGeomSeries K :=
⟨fun _ h ↦ (hasSum_geometric_of_norm_lt_one h).summable⟩
theorem tsum_geometric_of_norm_lt_one (h : ‖ξ‖ < 1) : ∑' n : ℕ, ξ ^ n = (1 - ξ)⁻¹ :=
(hasSum_geometric_of_norm_lt_one h).tsum_eq
theorem hasSum_geometric_of_abs_lt_one {r : ℝ} (h : |r| < 1) :
HasSum (fun n : ℕ ↦ r ^ n) (1 - r)⁻¹ :=
hasSum_geometric_of_norm_lt_one h
theorem summable_geometric_of_abs_lt_one {r : ℝ} (h : |r| < 1) : Summable fun n : ℕ ↦ r ^ n :=
summable_geometric_of_norm_lt_one h
theorem tsum_geometric_of_abs_lt_one {r : ℝ} (h : |r| < 1) : ∑' n : ℕ, r ^ n = (1 - r)⁻¹ :=
tsum_geometric_of_norm_lt_one h
/-- A geometric series in a normed field is summable iff the norm of the common ratio is less than
one. -/
@[simp]
theorem summable_geometric_iff_norm_lt_one : (Summable fun n : ℕ ↦ ξ ^ n) ↔ ‖ξ‖ < 1 := by
refine ⟨fun h ↦ ?_, summable_geometric_of_norm_lt_one⟩
obtain ⟨k : ℕ, hk : dist (ξ ^ k) 0 < 1⟩ :=
(h.tendsto_cofinite_zero.eventually (ball_mem_nhds _ zero_lt_one)).exists
simp only [norm_pow, dist_zero_right] at hk
rw [← one_pow k] at hk
exact lt_of_pow_lt_pow_left₀ _ zero_le_one hk
end Geometric
section MulGeometric
variable {R : Type*} [NormedRing R] {𝕜 : Type*} [NormedDivisionRing 𝕜]
theorem summable_norm_mul_geometric_of_norm_lt_one {k : ℕ} {r : R}
(hr : ‖r‖ < 1) {u : ℕ → ℕ} (hu : (fun n ↦ (u n : ℝ)) =O[atTop] (fun n ↦ (↑(n ^ k) : ℝ))) :
Summable fun n : ℕ ↦ ‖(u n * r ^ n : R)‖ := by
rcases exists_between hr with ⟨r', hrr', h⟩
rw [← norm_norm] at hrr'
apply summable_of_isBigO_nat (summable_geometric_of_lt_one ((norm_nonneg _).trans hrr'.le) h)
calc
fun n ↦ ‖↑(u n) * r ^ n‖
_ =O[atTop] fun n ↦ u n * ‖r‖ ^ n := by
apply (IsBigOWith.of_bound (c := ‖(1 : R)‖) ?_).isBigO
filter_upwards [eventually_norm_pow_le r] with n hn
simp only [norm_norm, norm_mul, Real.norm_eq_abs, abs_cast, norm_pow, abs_norm]
apply (norm_mul_le _ _).trans
have : ‖(u n : R)‖ * ‖r ^ n‖ ≤ (u n * ‖(1 : R)‖) * ‖r‖ ^ n := by
gcongr; exact norm_cast_le (u n)
exact this.trans (le_of_eq (by ring))
_ =O[atTop] fun n ↦ ↑(n ^ k) * ‖r‖ ^ n := hu.mul (isBigO_refl _ _)
_ =O[atTop] fun n ↦ r' ^ n := by
simp only [cast_pow]
exact (isLittleO_pow_const_mul_const_pow_const_pow_of_norm_lt k hrr').isBigO
theorem summable_norm_pow_mul_geometric_of_norm_lt_one (k : ℕ) {r : R}
(hr : ‖r‖ < 1) : Summable fun n : ℕ ↦ ‖((n : R) ^ k * r ^ n : R)‖ := by
simp only [← cast_pow]
exact summable_norm_mul_geometric_of_norm_lt_one (k := k) (u := fun n ↦ n ^ k) hr
(isBigO_refl _ _)
theorem summable_norm_geometric_of_norm_lt_one {r : R}
(hr : ‖r‖ < 1) : Summable fun n : ℕ ↦ ‖(r ^ n : R)‖ := by
simpa using summable_norm_pow_mul_geometric_of_norm_lt_one 0 hr
variable [HasSummableGeomSeries R]
lemma hasSum_choose_mul_geometric_of_norm_lt_one'
(k : ℕ) {r : R} (hr : ‖r‖ < 1) :
HasSum (fun n ↦ (n + k).choose k * r ^ n) (Ring.inverse (1 - r) ^ (k + 1)) := by
induction k with
| zero => simpa using hasSum_geom_series_inverse r hr
| succ k ih =>
have I1 : Summable (fun (n : ℕ) ↦ ‖(n + k).choose k * r ^ n‖) := by
apply summable_norm_mul_geometric_of_norm_lt_one (k := k) hr
apply isBigO_iff.2 ⟨2 ^ k, ?_⟩
filter_upwards [Ioi_mem_atTop k] with n (hn : k < n)
simp only [Real.norm_eq_abs, abs_cast, cast_pow, norm_pow]
norm_cast
calc (n + k).choose k
_ ≤ (2 * n).choose k := choose_le_choose k (by omega)
_ ≤ (2 * n) ^ k := Nat.choose_le_pow _ _
_ = 2 ^ k * n ^ k := Nat.mul_pow 2 n k
convert hasSum_sum_range_mul_of_summable_norm' I1 ih.summable
(summable_norm_geometric_of_norm_lt_one hr) (summable_geometric_of_norm_lt_one hr) with n
· have : ∑ i ∈ Finset.range (n + 1), ↑((i + k).choose k) * r ^ i * r ^ (n - i) =
∑ i ∈ Finset.range (n + 1), ↑((i + k).choose k) * r ^ n := by
apply Finset.sum_congr rfl (fun i hi ↦ ?_)
simp only [Finset.mem_range] at hi
rw [mul_assoc, ← pow_add, show i + (n - i) = n by omega]
simp [this, ← sum_mul, ← Nat.cast_sum, sum_range_add_choose n k, add_assoc]
· rw [ih.tsum_eq, (hasSum_geom_series_inverse r hr).tsum_eq, pow_succ]
lemma summable_choose_mul_geometric_of_norm_lt_one (k : ℕ) {r : R} (hr : ‖r‖ < 1) :
Summable (fun n ↦ (n + k).choose k * r ^ n) :=
(hasSum_choose_mul_geometric_of_norm_lt_one' k hr).summable
lemma tsum_choose_mul_geometric_of_norm_lt_one' (k : ℕ) {r : R} (hr : ‖r‖ < 1) :
∑' n, (n + k).choose k * r ^ n = (Ring.inverse (1 - r)) ^ (k + 1) :=
(hasSum_choose_mul_geometric_of_norm_lt_one' k hr).tsum_eq
lemma hasSum_choose_mul_geometric_of_norm_lt_one
(k : ℕ) {r : 𝕜} (hr : ‖r‖ < 1) :
HasSum (fun n ↦ (n + k).choose k * r ^ n) (1 / (1 - r) ^ (k + 1)) := by
convert hasSum_choose_mul_geometric_of_norm_lt_one' k hr
simp
lemma tsum_choose_mul_geometric_of_norm_lt_one (k : ℕ) {r : 𝕜} (hr : ‖r‖ < 1) :
∑' n, (n + k).choose k * r ^ n = 1/ (1 - r) ^ (k + 1) :=
(hasSum_choose_mul_geometric_of_norm_lt_one k hr).tsum_eq
lemma summable_descFactorial_mul_geometric_of_norm_lt_one (k : ℕ) {r : R} (hr : ‖r‖ < 1) :
Summable (fun n ↦ (n + k).descFactorial k * r ^ n) := by
convert (summable_choose_mul_geometric_of_norm_lt_one k hr).mul_left (k.factorial : R)
using 2 with n
simp [← mul_assoc, descFactorial_eq_factorial_mul_choose (n + k) k]
open Polynomial in
theorem summable_pow_mul_geometric_of_norm_lt_one (k : ℕ) {r : R} (hr : ‖r‖ < 1) :
Summable (fun n ↦ (n : R) ^ k * r ^ n : ℕ → R) := by
refine Nat.strong_induction_on k fun k hk => ?_
obtain ⟨a, ha⟩ : ∃ (a : ℕ → ℕ), ∀ n, (n + k).descFactorial k
= n ^ k + ∑ i ∈ range k, a i * n ^ i := by
let P : Polynomial ℕ := (ascPochhammer ℕ k).comp (Polynomial.X + C 1)
refine ⟨fun i ↦ P.coeff i, fun n ↦ ?_⟩
have mP : Monic P := Monic.comp_X_add_C (monic_ascPochhammer ℕ k) _
have dP : P.natDegree = k := by
simp only [P, natDegree_comp, ascPochhammer_natDegree, mul_one, natDegree_X_add_C]
have A : (n + k).descFactorial k = P.eval n := by
have : n + 1 + k - 1 = n + k := by omega
simp [P, ascPochhammer_nat_eq_descFactorial, this]
conv_lhs => rw [A, mP.as_sum, dP]
simp [eval_finset_sum]
have : Summable (fun n ↦ (n + k).descFactorial k * r ^ n
- ∑ i ∈ range k, a i * n ^ (i : ℕ) * r ^ n) := by
apply (summable_descFactorial_mul_geometric_of_norm_lt_one k hr).sub
apply summable_sum (fun i hi ↦ ?_)
simp_rw [mul_assoc]
simp only [Finset.mem_range] at hi
exact (hk _ hi).mul_left _
convert this using 1
ext n
simp [ha n, add_mul, sum_mul]
/-- If `‖r‖ < 1`, then `∑' n : ℕ, n * r ^ n = r / (1 - r) ^ 2`, `HasSum` version in a general ring
with summable geometric series. For a version in a field, using division instead of `Ring.inverse`,
see `hasSum_coe_mul_geometric_of_norm_lt_one`. -/
theorem hasSum_coe_mul_geometric_of_norm_lt_one'
{x : R} (h : ‖x‖ < 1) :
HasSum (fun n ↦ n * x ^ n : ℕ → R) (x * (Ring.inverse (1 - x)) ^ 2) := by
have A : HasSum (fun (n : ℕ) ↦ (n + 1) * x ^ n) (Ring.inverse (1 - x) ^ 2) := by
convert hasSum_choose_mul_geometric_of_norm_lt_one' 1 h with n
simp
have B : HasSum (fun (n : ℕ) ↦ x ^ n) (Ring.inverse (1 - x)) := hasSum_geom_series_inverse x h
convert A.sub B using 1
· ext n
simp [add_mul]
· symm
calc Ring.inverse (1 - x) ^ 2 - Ring.inverse (1 - x)
_ = Ring.inverse (1 - x) ^ 2 - ((1 - x) * Ring.inverse (1 - x)) * Ring.inverse (1 - x) := by
simp [Ring.mul_inverse_cancel (1 - x) (isUnit_one_sub_of_norm_lt_one h)]
_ = x * Ring.inverse (1 - x) ^ 2 := by noncomm_ring
/-- If `‖r‖ < 1`, then `∑' n : ℕ, n * r ^ n = r / (1 - r) ^ 2`, version in a general ring with
summable geometric series. For a version in a field, using division instead of `Ring.inverse`,
see `tsum_coe_mul_geometric_of_norm_lt_one`. -/
theorem tsum_coe_mul_geometric_of_norm_lt_one'
{r : 𝕜} (hr : ‖r‖ < 1) : (∑' n : ℕ, n * r ^ n : 𝕜) = r * Ring.inverse (1 - r) ^ 2 :=
(hasSum_coe_mul_geometric_of_norm_lt_one' hr).tsum_eq
/-- If `‖r‖ < 1`, then `∑' n : ℕ, n * r ^ n = r / (1 - r) ^ 2`, `HasSum` version. -/
theorem hasSum_coe_mul_geometric_of_norm_lt_one {r : 𝕜} (hr : ‖r‖ < 1) :
HasSum (fun n ↦ n * r ^ n : ℕ → 𝕜) (r / (1 - r) ^ 2) := by
convert hasSum_coe_mul_geometric_of_norm_lt_one' hr using 1
simp [div_eq_mul_inv]
/-- If `‖r‖ < 1`, then `∑' n : ℕ, n * r ^ n = r / (1 - r) ^ 2`. -/
theorem tsum_coe_mul_geometric_of_norm_lt_one {r : 𝕜} (hr : ‖r‖ < 1) :
(∑' n : ℕ, n * r ^ n : 𝕜) = r / (1 - r) ^ 2 :=
(hasSum_coe_mul_geometric_of_norm_lt_one hr).tsum_eq
end MulGeometric
section SummableLeGeometric
variable [SeminormedAddCommGroup α] {r C : ℝ} {f : ℕ → α}
nonrec theorem SeminormedAddCommGroup.cauchySeq_of_le_geometric {C : ℝ} {r : ℝ} (hr : r < 1)
{u : ℕ → α} (h : ∀ n, ‖u n - u (n + 1)‖ ≤ C * r ^ n) : CauchySeq u :=
cauchySeq_of_le_geometric r C hr (by simpa [dist_eq_norm] using h)
theorem dist_partial_sum_le_of_le_geometric (hf : ∀ n, ‖f n‖ ≤ C * r ^ n) (n : ℕ) :
dist (∑ i ∈ range n, f i) (∑ i ∈ range (n + 1), f i) ≤ C * r ^ n := by
rw [sum_range_succ, dist_eq_norm, ← norm_neg, neg_sub, add_sub_cancel_left]
exact hf n
/-- If `‖f n‖ ≤ C * r ^ n` for all `n : ℕ` and some `r < 1`, then the partial sums of `f` form a
Cauchy sequence. This lemma does not assume `0 ≤ r` or `0 ≤ C`. -/
theorem cauchySeq_finset_of_geometric_bound (hr : r < 1) (hf : ∀ n, ‖f n‖ ≤ C * r ^ n) :
CauchySeq fun s : Finset ℕ ↦ ∑ x ∈ s, f x :=
cauchySeq_finset_of_norm_bounded _
(aux_hasSum_of_le_geometric hr (dist_partial_sum_le_of_le_geometric hf)).summable hf
/-- If `‖f n‖ ≤ C * r ^ n` for all `n : ℕ` and some `r < 1`, then the partial sums of `f` are within
distance `C * r ^ n / (1 - r)` of the sum of the series. This lemma does not assume `0 ≤ r` or
`0 ≤ C`. -/
theorem norm_sub_le_of_geometric_bound_of_hasSum (hr : r < 1) (hf : ∀ n, ‖f n‖ ≤ C * r ^ n) {a : α}
(ha : HasSum f a) (n : ℕ) : ‖(∑ x ∈ Finset.range n, f x) - a‖ ≤ C * r ^ n / (1 - r) := by
rw [← dist_eq_norm]
apply dist_le_of_le_geometric_of_tendsto r C hr (dist_partial_sum_le_of_le_geometric hf)
exact ha.tendsto_sum_nat
@[simp]
theorem dist_partial_sum (u : ℕ → α) (n : ℕ) :
dist (∑ k ∈ range (n + 1), u k) (∑ k ∈ range n, u k) = ‖u n‖ := by
simp [dist_eq_norm, sum_range_succ]
@[simp]
theorem dist_partial_sum' (u : ℕ → α) (n : ℕ) :
dist (∑ k ∈ range n, u k) (∑ k ∈ range (n + 1), u k) = ‖u n‖ := by
simp [dist_eq_norm', sum_range_succ]
theorem cauchy_series_of_le_geometric {C : ℝ} {u : ℕ → α} {r : ℝ} (hr : r < 1)
(h : ∀ n, ‖u n‖ ≤ C * r ^ n) : CauchySeq fun n ↦ ∑ k ∈ range n, u k :=
cauchySeq_of_le_geometric r C hr (by simp [h])
theorem NormedAddCommGroup.cauchy_series_of_le_geometric' {C : ℝ} {u : ℕ → α} {r : ℝ} (hr : r < 1)
(h : ∀ n, ‖u n‖ ≤ C * r ^ n) : CauchySeq fun n ↦ ∑ k ∈ range (n + 1), u k :=
(cauchy_series_of_le_geometric hr h).comp_tendsto <| tendsto_add_atTop_nat 1
theorem NormedAddCommGroup.cauchy_series_of_le_geometric'' {C : ℝ} {u : ℕ → α} {N : ℕ} {r : ℝ}
(hr₀ : 0 < r) (hr₁ : r < 1) (h : ∀ n ≥ N, ‖u n‖ ≤ C * r ^ n) :
CauchySeq fun n ↦ ∑ k ∈ range (n + 1), u k := by
set v : ℕ → α := fun n ↦ if n < N then 0 else u n
have hC : 0 ≤ C :=
(mul_nonneg_iff_of_pos_right <| pow_pos hr₀ N).mp ((norm_nonneg _).trans <| h N <| le_refl N)
have : ∀ n ≥ N, u n = v n := by
intro n hn
simp [v, hn, if_neg (not_lt.mpr hn)]
| apply cauchySeq_sum_of_eventually_eq this
(NormedAddCommGroup.cauchy_series_of_le_geometric' hr₁ _)
· exact C
| Mathlib/Analysis/SpecificLimits/Normed.lean | 562 | 564 |
/-
Copyright (c) 2020 Oliver Nash. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Oliver Nash
-/
import Mathlib.Algebra.Lie.Matrix
import Mathlib.LinearAlgebra.Matrix.SesquilinearForm
import Mathlib.Tactic.NoncommRing
/-!
# Lie algebras of skew-adjoint endomorphisms of a bilinear form
When a module carries a bilinear form, the Lie algebra of endomorphisms of the module contains a
distinguished Lie subalgebra: the skew-adjoint endomorphisms. Such subalgebras are important
because they provide a simple, explicit construction of the so-called classical Lie algebras.
This file defines the Lie subalgebra of skew-adjoint endomorphisms cut out by a bilinear form on
a module and proves some basic related results. It also provides the corresponding definitions and
results for the Lie algebra of square matrices.
## Main definitions
* `skewAdjointLieSubalgebra`
* `skewAdjointLieSubalgebraEquiv`
* `skewAdjointMatricesLieSubalgebra`
* `skewAdjointMatricesLieSubalgebraEquiv`
## Tags
lie algebra, skew-adjoint, bilinear form
-/
universe u v w w₁
section SkewAdjointEndomorphisms
open LinearMap (BilinForm)
variable {R : Type u} {M : Type v} [CommRing R] [AddCommGroup M] [Module R M]
variable (B : BilinForm R M)
theorem LinearMap.BilinForm.isSkewAdjoint_bracket {f g : Module.End R M}
(hf : f ∈ B.skewAdjointSubmodule) (hg : g ∈ B.skewAdjointSubmodule) :
⁅f, g⁆ ∈ B.skewAdjointSubmodule := by
rw [mem_skewAdjointSubmodule] at *
have hfg : IsAdjointPair B B (f * g) (g * f) := by rw [← neg_mul_neg g f]; exact hg.comp hf
have hgf : IsAdjointPair B B (g * f) (f * g) := by rw [← neg_mul_neg f g]; exact hf.comp hg
change IsAdjointPair B B (f * g - g * f) (-(f * g - g * f)); rw [neg_sub]
exact hfg.sub hgf
/-- Given an `R`-module `M`, equipped with a bilinear form, the skew-adjoint endomorphisms form a
Lie subalgebra of the Lie algebra of endomorphisms. -/
def skewAdjointLieSubalgebra : LieSubalgebra R (Module.End R M) :=
{ B.skewAdjointSubmodule with
lie_mem' := B.isSkewAdjoint_bracket }
variable {N : Type w} [AddCommGroup N] [Module R N] (e : N ≃ₗ[R] M)
/-- An equivalence of modules with bilinear forms gives equivalence of Lie algebras of skew-adjoint
endomorphisms. -/
def skewAdjointLieSubalgebraEquiv :
skewAdjointLieSubalgebra (B.compl₁₂ (e : N →ₗ[R] M) e) ≃ₗ⁅R⁆ skewAdjointLieSubalgebra B := by
apply LieEquiv.ofSubalgebras _ _ e.lieConj
ext f
simp only [LieSubalgebra.mem_coe, Submodule.mem_map_equiv, LieSubalgebra.mem_map_submodule,
LinearEquiv.coe_coe]
exact (LinearMap.isPairSelfAdjoint_equiv (B := -B) (F := B) e f).symm
@[simp]
theorem skewAdjointLieSubalgebraEquiv_apply
(f : skewAdjointLieSubalgebra (B.compl₁₂ (Qₗ := N) (Qₗ' := N) ↑e ↑e)) :
↑(skewAdjointLieSubalgebraEquiv B e f) = e.lieConj f := by
simp [skewAdjointLieSubalgebraEquiv]
@[simp]
theorem skewAdjointLieSubalgebraEquiv_symm_apply (f : skewAdjointLieSubalgebra B) :
↑((skewAdjointLieSubalgebraEquiv B e).symm f) = e.symm.lieConj f := by
simp [skewAdjointLieSubalgebraEquiv]
end SkewAdjointEndomorphisms
section SkewAdjointMatrices
open scoped Matrix
variable {R : Type u} {n : Type w} [CommRing R] [DecidableEq n] [Fintype n]
variable (J : Matrix n n R)
theorem Matrix.lie_transpose (A B : Matrix n n R) : ⁅A, B⁆ᵀ = ⁅Bᵀ, Aᵀ⁆ :=
show (A * B - B * A)ᵀ = Bᵀ * Aᵀ - Aᵀ * Bᵀ by simp
theorem Matrix.isSkewAdjoint_bracket {A B : Matrix n n R} (hA : A ∈ skewAdjointMatricesSubmodule J)
(hB : B ∈ skewAdjointMatricesSubmodule J) : ⁅A, B⁆ ∈ skewAdjointMatricesSubmodule J := by
simp only [mem_skewAdjointMatricesSubmodule] at *
change ⁅A, B⁆ᵀ * J = J * (-⁅A, B⁆)
change Aᵀ * J = J * (-A) at hA
| change Bᵀ * J = J * (-B) at hB
rw [Matrix.lie_transpose, LieRing.of_associative_ring_bracket,
| Mathlib/Algebra/Lie/SkewAdjoint.lean | 98 | 99 |
/-
Copyright (c) 2022 Yakov Pechersky. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yakov Pechersky, Floris van Doorn
-/
import Mathlib.Data.Nat.Find
import Mathlib.Data.PNat.Basic
/-!
# Explicit least witnesses to existentials on positive natural numbers
Implemented via calling out to `Nat.find`.
-/
namespace PNat
variable {p q : ℕ+ → Prop} [DecidablePred p] [DecidablePred q] (h : ∃ n, p n)
instance decidablePredExistsNat : DecidablePred fun n' : ℕ => ∃ (n : ℕ+) (_ : n' = n), p n :=
fun n' =>
decidable_of_iff' (∃ h : 0 < n', p ⟨n', h⟩) <|
Subtype.exists.trans <| by
simp_rw [mk_coe, @exists_comm (_ < _) (_ = _), exists_prop, exists_eq_left']
/-- The `PNat` version of `Nat.findX` -/
protected def findX : { n // p n ∧ ∀ m : ℕ+, m < n → ¬p m } := by
have : ∃ (n' : ℕ) (n : ℕ+) (_ : n' = n), p n := Exists.elim h fun n hn => ⟨n, n, rfl, hn⟩
have n := Nat.findX this
refine ⟨⟨n, ?_⟩, ?_, fun m hm pm => ?_⟩
· obtain ⟨n', hn', -⟩ := n.prop.1
rw [hn']
exact n'.prop
· obtain ⟨n', hn', pn'⟩ := n.prop.1
simpa [hn', Subtype.coe_eta] using pn'
· exact n.prop.2 m hm ⟨m, rfl, pm⟩
/-- If `p` is a (decidable) predicate on `ℕ+` and `hp : ∃ (n : ℕ+), p n` is a proof that
there exists some positive natural number satisfying `p`, then `PNat.find hp` is the
smallest positive natural number satisfying `p`. Note that `PNat.find` is protected,
meaning that you can't just write `find`, even if the `PNat` namespace is open.
The API for `PNat.find` is:
* `PNat.find_spec` is the proof that `PNat.find hp` satisfies `p`.
* `PNat.find_min` is the proof that if `m < PNat.find hp` then `m` does not satisfy `p`.
* `PNat.find_min'` is the proof that if `m` does satisfy `p` then `PNat.find hp ≤ m`.
-/
protected def find : ℕ+ :=
PNat.findX h
protected theorem find_spec : p (PNat.find h) :=
(PNat.findX h).prop.left
protected theorem find_min : ∀ {m : ℕ+}, m < PNat.find h → ¬p m :=
@(PNat.findX h).prop.right
protected theorem find_min' {m : ℕ+} (hm : p m) : PNat.find h ≤ m :=
le_of_not_lt fun l => PNat.find_min h l hm
variable {n m : ℕ+}
theorem find_eq_iff : PNat.find h = m ↔ p m ∧ ∀ n < m, ¬p n := by
constructor
· rintro rfl
exact ⟨PNat.find_spec h, fun _ => PNat.find_min h⟩
· rintro ⟨hm, hlt⟩
exact le_antisymm (PNat.find_min' h hm) (not_lt.1 <| imp_not_comm.1 (hlt _) <| PNat.find_spec h)
| @[simp]
theorem find_lt_iff (n : ℕ+) : PNat.find h < n ↔ ∃ m < n, p m :=
⟨fun h2 => ⟨PNat.find h, h2, PNat.find_spec h⟩, fun ⟨_, hmn, hm⟩ =>
(PNat.find_min' h hm).trans_lt hmn⟩
@[simp]
| Mathlib/Data/PNat/Find.lean | 71 | 76 |
/-
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
| Mathlib/Algebra/Order/ToIntervalMod.lean | 552 | 554 |
/-
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.Algebra.BigOperators.Fin
import Mathlib.Algebra.Order.BigOperators.Group.Finset
import Mathlib.Data.Finset.Sort
/-!
# Compositions
A composition of a natural number `n` is a decomposition `n = i₀ + ... + i_{k-1}` of `n` into a sum
of positive integers. Combinatorially, it corresponds to a decomposition of `{0, ..., n-1}` into
non-empty blocks of consecutive integers, where the `iⱼ` are the lengths of the blocks.
This notion is closely related to that of a partition of `n`, but in a composition of `n` the
order of the `iⱼ`s matters.
We implement two different structures covering these two viewpoints on compositions. The first
one, made of a list of positive integers summing to `n`, is the main one and is called
`Composition n`. The second one is useful for combinatorial arguments (for instance to show that
the number of compositions of `n` is `2^(n-1)`). It is given by a subset of `{0, ..., n}`
containing `0` and `n`, where the elements of the subset (other than `n`) correspond to the leftmost
points of each block. The main API is built on `Composition n`, and we provide an equivalence
between the two types.
## Main functions
* `c : Composition n` is a structure, made of a list of integers which are all positive and
add up to `n`.
* `composition_card` states that the cardinality of `Composition n` is exactly
`2^(n-1)`, which is proved by constructing an equiv with `CompositionAsSet n` (see below), which
is itself in bijection with the subsets of `Fin (n-1)` (this holds even for `n = 0`, where `-` is
nat subtraction).
Let `c : Composition n` be a composition of `n`. Then
* `c.blocks` is the list of blocks in `c`.
* `c.length` is the number of blocks in the composition.
* `c.blocksFun : Fin c.length → ℕ` is the realization of `c.blocks` as a function on
`Fin c.length`. This is the main object when using compositions to understand the composition of
analytic functions.
* `c.sizeUpTo : ℕ → ℕ` is the sum of the size of the blocks up to `i`.;
* `c.embedding i : Fin (c.blocksFun i) → Fin n` is the increasing embedding of the `i`-th block in
`Fin n`;
* `c.index j`, for `j : Fin n`, is the index of the block containing `j`.
* `Composition.ones n` is the composition of `n` made of ones, i.e., `[1, ..., 1]`.
* `Composition.single n (hn : 0 < n)` is the composition of `n` made of a single block of size `n`.
Compositions can also be used to split lists. Let `l` be a list of length `n` and `c` a composition
of `n`.
* `l.splitWrtComposition c` is a list of lists, made of the slices of `l` corresponding to the
blocks of `c`.
* `join_splitWrtComposition` states that splitting a list and then joining it gives back the
original list.
* `splitWrtComposition_join` states that joining a list of lists, and then splitting it back
according to the right composition, gives back the original list of lists.
We turn to the second viewpoint on compositions, that we realize as a finset of `Fin (n+1)`.
`c : CompositionAsSet n` is a structure made of a finset of `Fin (n+1)` called `c.boundaries`
and proofs that it contains `0` and `n`. (Taking a finset of `Fin n` containing `0` would not
make sense in the edge case `n = 0`, while the previous description works in all cases).
The elements of this set (other than `n`) correspond to leftmost points of blocks.
Thus, there is an equiv between `Composition n` and `CompositionAsSet n`. We
only construct basic API on `CompositionAsSet` (notably `c.length` and `c.blocks`) to be able
to construct this equiv, called `compositionEquiv n`. Since there is a straightforward equiv
between `CompositionAsSet n` and finsets of `{1, ..., n-1}` (obtained by removing `0` and `n`
from a `CompositionAsSet` and called `compositionAsSetEquiv n`), we deduce that
`CompositionAsSet n` and `Composition n` are both fintypes of cardinality `2^(n - 1)`
(see `compositionAsSet_card` and `composition_card`).
## Implementation details
The main motivation for this structure and its API is in the construction of the composition of
formal multilinear series, and the proof that the composition of analytic functions is analytic.
The representation of a composition as a list is very handy as lists are very flexible and already
have a well-developed API.
## Tags
Composition, partition
## References
<https://en.wikipedia.org/wiki/Composition_(combinatorics)>
-/
assert_not_exists Field
open List
variable {n : ℕ}
/-- A composition of `n` is a list of positive integers summing to `n`. -/
@[ext]
structure Composition (n : ℕ) where
/-- List of positive integers summing to `n` -/
blocks : List ℕ
/-- Proof of positivity for `blocks` -/
blocks_pos : ∀ {i}, i ∈ blocks → 0 < i
/-- Proof that `blocks` sums to `n` -/
blocks_sum : blocks.sum = n
deriving DecidableEq
attribute [simp] Composition.blocks_sum
/-- Combinatorial viewpoint on a composition of `n`, by seeing it as non-empty blocks of
consecutive integers in `{0, ..., n-1}`. We register every block by its left end-point, yielding
a finset containing `0`. As this does not make sense for `n = 0`, we add `n` to this finset, and
get a finset of `{0, ..., n}` containing `0` and `n`. This is the data in the structure
`CompositionAsSet n`. -/
@[ext]
structure CompositionAsSet (n : ℕ) where
/-- Combinatorial viewpoint on a composition of `n` as consecutive integers `{0, ..., n-1}` -/
boundaries : Finset (Fin n.succ)
/-- Proof that `0` is a member of `boundaries` -/
zero_mem : (0 : Fin n.succ) ∈ boundaries
/-- Last element of the composition -/
getLast_mem : Fin.last n ∈ boundaries
deriving DecidableEq
instance {n : ℕ} : Inhabited (CompositionAsSet n) :=
⟨⟨Finset.univ, Finset.mem_univ _, Finset.mem_univ _⟩⟩
attribute [simp] CompositionAsSet.zero_mem CompositionAsSet.getLast_mem
/-!
### Compositions
A composition of an integer `n` is a decomposition `n = i₀ + ... + i_{k-1}` of `n` into a sum of
positive integers.
-/
namespace Composition
variable (c : Composition n)
instance (n : ℕ) : ToString (Composition n) :=
⟨fun c => toString c.blocks⟩
/-- The length of a composition, i.e., the number of blocks in the composition. -/
abbrev length : ℕ :=
c.blocks.length
theorem blocks_length : c.blocks.length = c.length :=
rfl
/-- The blocks of a composition, seen as a function on `Fin c.length`. When composing analytic
functions using compositions, this is the main player. -/
def blocksFun : Fin c.length → ℕ := c.blocks.get
@[simp]
theorem ofFn_blocksFun : ofFn c.blocksFun = c.blocks :=
ofFn_get _
@[simp]
theorem sum_blocksFun : ∑ i, c.blocksFun i = n := by
conv_rhs => rw [← c.blocks_sum, ← ofFn_blocksFun, sum_ofFn]
@[simp]
theorem blocksFun_mem_blocks (i : Fin c.length) : c.blocksFun i ∈ c.blocks :=
get_mem _ _
theorem one_le_blocks {i : ℕ} (h : i ∈ c.blocks) : 1 ≤ i :=
c.blocks_pos h
theorem blocks_le {i : ℕ} (h : i ∈ c.blocks) : i ≤ n := by
rw [← c.blocks_sum]
exact List.le_sum_of_mem h
@[simp]
theorem one_le_blocks' {i : ℕ} (h : i < c.length) : 1 ≤ c.blocks[i] :=
c.one_le_blocks (get_mem (blocks c) _)
@[simp]
theorem blocks_pos' (i : ℕ) (h : i < c.length) : 0 < c.blocks[i] :=
c.one_le_blocks' h
@[simp]
theorem one_le_blocksFun (i : Fin c.length) : 1 ≤ c.blocksFun i :=
c.one_le_blocks (c.blocksFun_mem_blocks i)
@[simp]
theorem blocksFun_le {n} (c : Composition n) (i : Fin c.length) :
c.blocksFun i ≤ n :=
c.blocks_le <| getElem_mem _
@[simp]
theorem length_le : c.length ≤ n := by
conv_rhs => rw [← c.blocks_sum]
exact length_le_sum_of_one_le _ fun i hi => c.one_le_blocks hi
@[simp]
theorem blocks_eq_nil : c.blocks = [] ↔ n = 0 := by
constructor
· intro h
simpa using congr(List.sum $h)
· rintro rfl
rw [← length_eq_zero_iff, ← nonpos_iff_eq_zero]
exact c.length_le
protected theorem length_eq_zero : c.length = 0 ↔ n = 0 := by
simp
@[simp]
theorem length_pos_iff : 0 < c.length ↔ 0 < n := by
simp [pos_iff_ne_zero]
alias ⟨_, length_pos_of_pos⟩ := length_pos_iff
/-- The sum of the sizes of the blocks in a composition up to `i`. -/
def sizeUpTo (i : ℕ) : ℕ :=
(c.blocks.take i).sum
@[simp]
theorem sizeUpTo_zero : c.sizeUpTo 0 = 0 := by simp [sizeUpTo]
theorem sizeUpTo_ofLength_le (i : ℕ) (h : c.length ≤ i) : c.sizeUpTo i = n := by
dsimp [sizeUpTo]
convert c.blocks_sum
exact take_of_length_le h
@[simp]
theorem sizeUpTo_length : c.sizeUpTo c.length = n :=
c.sizeUpTo_ofLength_le c.length le_rfl
theorem sizeUpTo_le (i : ℕ) : c.sizeUpTo i ≤ n := by
conv_rhs => rw [← c.blocks_sum, ← sum_take_add_sum_drop _ i]
exact Nat.le_add_right _ _
theorem sizeUpTo_succ {i : ℕ} (h : i < c.length) :
c.sizeUpTo (i + 1) = c.sizeUpTo i + c.blocks[i] := by
simp only [sizeUpTo]
rw [sum_take_succ _ _ h]
theorem sizeUpTo_succ' (i : Fin c.length) :
c.sizeUpTo ((i : ℕ) + 1) = c.sizeUpTo i + c.blocksFun i :=
c.sizeUpTo_succ i.2
theorem sizeUpTo_strict_mono {i : ℕ} (h : i < c.length) : c.sizeUpTo i < c.sizeUpTo (i + 1) := by
rw [c.sizeUpTo_succ h]
simp
theorem monotone_sizeUpTo : Monotone c.sizeUpTo :=
monotone_sum_take _
/-- The `i`-th boundary of a composition, i.e., the leftmost point of the `i`-th block. We include
a virtual point at the right of the last block, to make for a nice equiv with
`CompositionAsSet n`. -/
def boundary : Fin (c.length + 1) ↪o Fin (n + 1) :=
(OrderEmbedding.ofStrictMono fun i => ⟨c.sizeUpTo i, Nat.lt_succ_of_le (c.sizeUpTo_le i)⟩) <|
Fin.strictMono_iff_lt_succ.2 fun ⟨_, hi⟩ => c.sizeUpTo_strict_mono hi
@[simp]
theorem boundary_zero : c.boundary 0 = 0 := by simp [boundary, Fin.ext_iff]
@[simp]
theorem boundary_last : c.boundary (Fin.last c.length) = Fin.last n := by
simp [boundary, Fin.ext_iff]
/-- The boundaries of a composition, i.e., the leftmost point of all the blocks. We include
a virtual point at the right of the last block, to make for a nice equiv with
`CompositionAsSet n`. -/
def boundaries : Finset (Fin (n + 1)) :=
Finset.univ.map c.boundary.toEmbedding
theorem card_boundaries_eq_succ_length : c.boundaries.card = c.length + 1 := by simp [boundaries]
/-- To `c : Composition n`, one can associate a `CompositionAsSet n` by registering the leftmost
point of each block, and adding a virtual point at the right of the last block. -/
def toCompositionAsSet : CompositionAsSet n where
boundaries := c.boundaries
zero_mem := by
simp only [boundaries, Finset.mem_univ, exists_prop_of_true, Finset.mem_map]
exact ⟨0, And.intro True.intro rfl⟩
getLast_mem := by
simp only [boundaries, Finset.mem_univ, exists_prop_of_true, Finset.mem_map]
exact ⟨Fin.last c.length, And.intro True.intro c.boundary_last⟩
/-- The canonical increasing bijection between `Fin (c.length + 1)` and `c.boundaries` is
exactly `c.boundary`. -/
theorem orderEmbOfFin_boundaries :
c.boundaries.orderEmbOfFin c.card_boundaries_eq_succ_length = c.boundary := by
refine (Finset.orderEmbOfFin_unique' _ ?_).symm
exact fun i => (Finset.mem_map' _).2 (Finset.mem_univ _)
/-- Embedding the `i`-th block of a composition (identified with `Fin (c.blocksFun i)`) into
`Fin n` at the relevant position. -/
def embedding (i : Fin c.length) : Fin (c.blocksFun i) ↪o Fin n :=
(Fin.natAddOrderEmb <| c.sizeUpTo i).trans <| Fin.castLEOrderEmb <|
calc
c.sizeUpTo i + c.blocksFun i = c.sizeUpTo (i + 1) := (c.sizeUpTo_succ i.2).symm
_ ≤ c.sizeUpTo c.length := monotone_sum_take _ i.2
_ = n := c.sizeUpTo_length
@[simp]
theorem coe_embedding (i : Fin c.length) (j : Fin (c.blocksFun i)) :
(c.embedding i j : ℕ) = c.sizeUpTo i + j :=
rfl
/-- `index_exists` asserts there is some `i` with `j < c.sizeUpTo (i+1)`.
In the next definition `index` we use `Nat.find` to produce the minimal such index.
-/
theorem index_exists {j : ℕ} (h : j < n) : ∃ i : ℕ, j < c.sizeUpTo (i + 1) ∧ i < c.length := by
have n_pos : 0 < n := lt_of_le_of_lt (zero_le j) h
have : 0 < c.blocks.sum := by rwa [← c.blocks_sum] at n_pos
have length_pos : 0 < c.blocks.length := length_pos_of_sum_pos (blocks c) this
refine ⟨c.length - 1, ?_, Nat.pred_lt (ne_of_gt length_pos)⟩
have : c.length - 1 + 1 = c.length := Nat.succ_pred_eq_of_pos length_pos
simp [this, h]
/-- `c.index j` is the index of the block in the composition `c` containing `j`. -/
def index (j : Fin n) : Fin c.length :=
⟨Nat.find (c.index_exists j.2), (Nat.find_spec (c.index_exists j.2)).2⟩
theorem lt_sizeUpTo_index_succ (j : Fin n) : (j : ℕ) < c.sizeUpTo (c.index j).succ :=
(Nat.find_spec (c.index_exists j.2)).1
theorem sizeUpTo_index_le (j : Fin n) : c.sizeUpTo (c.index j) ≤ j := by
by_contra H
set i := c.index j
push_neg at H
have i_pos : (0 : ℕ) < i := by
by_contra! i_pos
revert H
simp [nonpos_iff_eq_zero.1 i_pos, c.sizeUpTo_zero]
let i₁ := (i : ℕ).pred
have i₁_lt_i : i₁ < i := Nat.pred_lt (ne_of_gt i_pos)
have i₁_succ : i₁ + 1 = i := Nat.succ_pred_eq_of_pos i_pos
have := Nat.find_min (c.index_exists j.2) i₁_lt_i
simp [lt_trans i₁_lt_i (c.index j).2, i₁_succ] at this
exact Nat.lt_le_asymm H this
/-- Mapping an element `j` of `Fin n` to the element in the block containing it, identified with
`Fin (c.blocksFun (c.index j))` through the canonical increasing bijection. -/
def invEmbedding (j : Fin n) : Fin (c.blocksFun (c.index j)) :=
⟨j - c.sizeUpTo (c.index j), by
rw [tsub_lt_iff_right, add_comm, ← sizeUpTo_succ']
· exact lt_sizeUpTo_index_succ _ _
· exact sizeUpTo_index_le _ _⟩
@[simp]
theorem coe_invEmbedding (j : Fin n) : (c.invEmbedding j : ℕ) = j - c.sizeUpTo (c.index j) :=
rfl
theorem embedding_comp_inv (j : Fin n) : c.embedding (c.index j) (c.invEmbedding j) = j := by
rw [Fin.ext_iff]
apply add_tsub_cancel_of_le (c.sizeUpTo_index_le j)
theorem mem_range_embedding_iff {j : Fin n} {i : Fin c.length} :
j ∈ Set.range (c.embedding i) ↔ c.sizeUpTo i ≤ j ∧ (j : ℕ) < c.sizeUpTo (i : ℕ).succ := by
constructor
· intro h
rcases Set.mem_range.2 h with ⟨k, hk⟩
rw [Fin.ext_iff] at hk
dsimp at hk
rw [← hk]
simp [sizeUpTo_succ', k.is_lt]
· intro h
apply Set.mem_range.2
refine ⟨⟨j - c.sizeUpTo i, ?_⟩, ?_⟩
· rw [tsub_lt_iff_left, ← sizeUpTo_succ']
· exact h.2
· exact h.1
· rw [Fin.ext_iff]
exact add_tsub_cancel_of_le h.1
/-- The embeddings of different blocks of a composition are disjoint. -/
theorem disjoint_range {i₁ i₂ : Fin c.length} (h : i₁ ≠ i₂) :
Disjoint (Set.range (c.embedding i₁)) (Set.range (c.embedding i₂)) := by
classical
wlog h' : i₁ < i₂
· exact (this c h.symm (h.lt_or_lt.resolve_left h')).symm
by_contra d
obtain ⟨x, hx₁, hx₂⟩ :
∃ x : Fin n, x ∈ Set.range (c.embedding i₁) ∧ x ∈ Set.range (c.embedding i₂) :=
Set.not_disjoint_iff.1 d
have A : (i₁ : ℕ).succ ≤ i₂ := Nat.succ_le_of_lt h'
apply lt_irrefl (x : ℕ)
calc
(x : ℕ) < c.sizeUpTo (i₁ : ℕ).succ := (c.mem_range_embedding_iff.1 hx₁).2
_ ≤ c.sizeUpTo (i₂ : ℕ) := monotone_sum_take _ A
_ ≤ x := (c.mem_range_embedding_iff.1 hx₂).1
theorem mem_range_embedding (j : Fin n) : j ∈ Set.range (c.embedding (c.index j)) := by
have : c.embedding (c.index j) (c.invEmbedding j) ∈ Set.range (c.embedding (c.index j)) :=
Set.mem_range_self _
rwa [c.embedding_comp_inv j] at this
theorem mem_range_embedding_iff' {j : Fin n} {i : Fin c.length} :
j ∈ Set.range (c.embedding i) ↔ i = c.index j := by
constructor
· rw [← not_imp_not]
intro h
exact Set.disjoint_right.1 (c.disjoint_range h) (c.mem_range_embedding j)
· intro h
rw [h]
exact c.mem_range_embedding j
theorem index_embedding (i : Fin c.length) (j : Fin (c.blocksFun i)) :
c.index (c.embedding i j) = i := by
symm
rw [← mem_range_embedding_iff']
apply Set.mem_range_self
theorem invEmbedding_comp (i : Fin c.length) (j : Fin (c.blocksFun i)) :
(c.invEmbedding (c.embedding i j) : ℕ) = j := by
simp_rw [coe_invEmbedding, index_embedding, coe_embedding, add_tsub_cancel_left]
/-- Equivalence between the disjoint union of the blocks (each of them seen as
`Fin (c.blocksFun i)`) with `Fin n`. -/
def blocksFinEquiv : (Σi : Fin c.length, Fin (c.blocksFun i)) ≃ Fin n where
toFun x := c.embedding x.1 x.2
invFun j := ⟨c.index j, c.invEmbedding j⟩
left_inv x := by
rcases x with ⟨i, y⟩
dsimp
congr; · exact c.index_embedding _ _
rw [Fin.heq_ext_iff]
· exact c.invEmbedding_comp _ _
· rw [c.index_embedding]
right_inv j := c.embedding_comp_inv j
theorem blocksFun_congr {n₁ n₂ : ℕ} (c₁ : Composition n₁) (c₂ : Composition n₂) (i₁ : Fin c₁.length)
(i₂ : Fin c₂.length) (hn : n₁ = n₂) (hc : c₁.blocks = c₂.blocks) (hi : (i₁ : ℕ) = i₂) :
c₁.blocksFun i₁ = c₂.blocksFun i₂ := by
cases hn
rw [← Composition.ext_iff] at hc
cases hc
congr
rwa [Fin.ext_iff]
/-- Two compositions (possibly of different integers) coincide if and only if they have the
same sequence of blocks. -/
theorem sigma_eq_iff_blocks_eq {c : Σ n, Composition n} {c' : Σ n, Composition n} :
c = c' ↔ c.2.blocks = c'.2.blocks := by
refine ⟨fun H => by rw [H], fun H => ?_⟩
rcases c with ⟨n, c⟩
rcases c' with ⟨n', c'⟩
have : n = n' := by rw [← c.blocks_sum, ← c'.blocks_sum, H]
induction this
congr
ext1
exact H
/-! ### The composition `Composition.ones` -/
/-- The composition made of blocks all of size `1`. -/
def ones (n : ℕ) : Composition n :=
⟨replicate n (1 : ℕ), fun {i} hi => by simp [List.eq_of_mem_replicate hi], by simp⟩
instance {n : ℕ} : Inhabited (Composition n) :=
⟨Composition.ones n⟩
@[simp]
theorem ones_length (n : ℕ) : (ones n).length = n :=
List.length_replicate
@[simp]
theorem ones_blocks (n : ℕ) : (ones n).blocks = replicate n (1 : ℕ) :=
rfl
@[simp]
theorem ones_blocksFun (n : ℕ) (i : Fin (ones n).length) : (ones n).blocksFun i = 1 := by
simp only [blocksFun, ones, get_eq_getElem, getElem_replicate]
@[simp]
theorem ones_sizeUpTo (n : ℕ) (i : ℕ) : (ones n).sizeUpTo i = min i n := by
simp [sizeUpTo, ones_blocks, take_replicate]
@[simp]
theorem ones_embedding (i : Fin (ones n).length) (h : 0 < (ones n).blocksFun i) :
(ones n).embedding i ⟨0, h⟩ = ⟨i, lt_of_lt_of_le i.2 (ones n).length_le⟩ := by
ext
simpa using i.2.le
theorem eq_ones_iff {c : Composition n} : c = ones n ↔ ∀ i ∈ c.blocks, i = 1 := by
constructor
· rintro rfl
exact fun i => eq_of_mem_replicate
· intro H
ext1
have A : c.blocks = replicate c.blocks.length 1 := eq_replicate_of_mem H
have : c.blocks.length = n := by
conv_rhs => rw [← c.blocks_sum, A]
simp
rw [A, this, ones_blocks]
theorem ne_ones_iff {c : Composition n} : c ≠ ones n ↔ ∃ i ∈ c.blocks, 1 < i := by
refine (not_congr eq_ones_iff).trans ?_
have : ∀ j ∈ c.blocks, j = 1 ↔ j ≤ 1 := fun j hj => by simp [le_antisymm_iff, c.one_le_blocks hj]
simp +contextual [this]
theorem eq_ones_iff_length {c : Composition n} : c = ones n ↔ c.length = n := by
constructor
· rintro rfl
exact ones_length n
· contrapose
intro H length_n
apply lt_irrefl n
calc
n = ∑ i : Fin c.length, 1 := by simp [length_n]
_ < ∑ i : Fin c.length, c.blocksFun i := by
{
obtain ⟨i, hi, i_blocks⟩ : ∃ i ∈ c.blocks, 1 < i := ne_ones_iff.1 H
rw [← ofFn_blocksFun, mem_ofFn' c.blocksFun, Set.mem_range] at hi
obtain ⟨j : Fin c.length, hj : c.blocksFun j = i⟩ := hi
rw [← hj] at i_blocks
exact Finset.sum_lt_sum (fun i _ => one_le_blocksFun c i) ⟨j, Finset.mem_univ _, i_blocks⟩
}
_ = n := c.sum_blocksFun
theorem eq_ones_iff_le_length {c : Composition n} : c = ones n ↔ n ≤ c.length := by
simp [eq_ones_iff_length, le_antisymm_iff, c.length_le]
/-! ### The composition `Composition.single` -/
/-- The composition made of a single block of size `n`. -/
def single (n : ℕ) (h : 0 < n) : Composition n :=
⟨[n], by simp [h], by simp⟩
@[simp]
theorem single_length {n : ℕ} (h : 0 < n) : (single n h).length = 1 :=
rfl
@[simp]
theorem single_blocks {n : ℕ} (h : 0 < n) : (single n h).blocks = [n] :=
rfl
@[simp]
theorem single_blocksFun {n : ℕ} (h : 0 < n) (i : Fin (single n h).length) :
(single n h).blocksFun i = n := by simp [blocksFun, single, blocks, i.2]
@[simp]
theorem single_embedding {n : ℕ} (h : 0 < n) (i : Fin n) :
((single n h).embedding (0 : Fin 1)) i = i := by
ext
simp
theorem eq_single_iff_length {n : ℕ} (h : 0 < n) {c : Composition n} :
c = single n h ↔ c.length = 1 := by
constructor
· intro H
rw [H]
exact single_length h
· intro H
ext1
have A : c.blocks.length = 1 := H ▸ c.blocks_length
have B : c.blocks.sum = n := c.blocks_sum
rw [eq_cons_of_length_one A] at B ⊢
simpa [single_blocks] using B
theorem ne_single_iff {n : ℕ} (hn : 0 < n) {c : Composition n} :
c ≠ single n hn ↔ ∀ i, c.blocksFun i < n := by
rw [← not_iff_not]
push_neg
constructor
· rintro rfl
exact ⟨⟨0, by simp⟩, by simp⟩
· rintro ⟨i, hi⟩
rw [eq_single_iff_length]
have : ∀ j : Fin c.length, j = i := by
intro j
by_contra ji
apply lt_irrefl (∑ k, c.blocksFun k)
calc
∑ k, c.blocksFun k ≤ c.blocksFun i := by simp only [c.sum_blocksFun, hi]
_ < ∑ k, c.blocksFun k :=
Finset.single_lt_sum ji (Finset.mem_univ _) (Finset.mem_univ _) (c.one_le_blocksFun j)
fun _ _ _ => zero_le _
simpa using Fintype.card_eq_one_of_forall_eq this
variable {m : ℕ}
/-- Change `n` in `(c : Composition n)` to a propositionally equal value. -/
@[simps]
protected def cast (c : Composition m) (hmn : m = n) : Composition n where
__ := c
blocks_sum := c.blocks_sum.trans hmn
@[simp]
theorem cast_rfl (c : Composition n) : c.cast rfl = c := rfl
theorem cast_heq (c : Composition m) (hmn : m = n) : HEq (c.cast hmn) c := by subst m; rfl
theorem cast_eq_cast (c : Composition m) (hmn : m = n) :
c.cast hmn = cast (hmn ▸ rfl) c := by
subst m
rfl
/-- Append two compositions to get a composition of the sum of numbers. -/
@[simps]
def append (c₁ : Composition m) (c₂ : Composition n) : Composition (m + n) where
blocks := c₁.blocks ++ c₂.blocks
blocks_pos := by
intro i hi
rw [mem_append] at hi
exact hi.elim c₁.blocks_pos c₂.blocks_pos
blocks_sum := by simp
/-- Reverse the order of blocks in a composition. -/
@[simps]
def reverse (c : Composition n) : Composition n where
blocks := c.blocks.reverse
blocks_pos hi := c.blocks_pos (mem_reverse.mp hi)
blocks_sum := by simp [List.sum_reverse]
@[simp]
lemma reverse_reverse (c : Composition n) : c.reverse.reverse = c :=
Composition.ext <| List.reverse_reverse _
lemma reverse_involutive : Function.Involutive (@reverse n) := reverse_reverse
lemma reverse_bijective : Function.Bijective (@reverse n) := reverse_involutive.bijective
lemma reverse_injective : Function.Injective (@reverse n) := reverse_involutive.injective
lemma reverse_surjective : Function.Surjective (@reverse n) := reverse_involutive.surjective
@[simp]
lemma reverse_inj {c₁ c₂ : Composition n} : c₁.reverse = c₂.reverse ↔ c₁ = c₂ :=
reverse_injective.eq_iff
@[simp]
lemma reverse_ones : (ones n).reverse = ones n := by ext1; simp
@[simp]
lemma reverse_single (hn : 0 < n) : (single n hn).reverse = single n hn := by ext1; simp
@[simp]
lemma reverse_eq_ones {c : Composition n} : c.reverse = ones n ↔ c = ones n :=
reverse_injective.eq_iff' reverse_ones
@[simp]
lemma reverse_eq_single {hn : 0 < n} {c : Composition n} :
c.reverse = single n hn ↔ c = single n hn :=
reverse_injective.eq_iff' <| reverse_single _
lemma reverse_append (c₁ : Composition m) (c₂ : Composition n) :
reverse (append c₁ c₂) = (append c₂.reverse c₁.reverse).cast (add_comm _ _) :=
Composition.ext <| by simp
/-- Induction (recursion) principle on `c : Composition _`
that corresponds to the usual induction on the list of blocks of `c`. -/
@[elab_as_elim]
def recOnSingleAppend {motive : ∀ n, Composition n → Sort*} {n : ℕ} (c : Composition n)
(zero : motive 0 (ones 0))
(single_append : ∀ k n c, motive n c →
motive (k + 1 + n) (append (single (k + 1) k.succ_pos) c)) :
motive n c :=
match n, c with
| _, ⟨blocks, blocks_pos, rfl⟩ =>
match blocks with
| [] => zero
| 0 :: _ => by simp at blocks_pos
| (k + 1) :: l =>
single_append k l.sum ⟨l, fun hi ↦ blocks_pos <| mem_cons_of_mem _ hi, rfl⟩ <|
recOnSingleAppend _ zero single_append
decreasing_by simp
/-- Induction (recursion) principle on `c : Composition _`
that corresponds to the reverse induction on the list of blocks of `c`. -/
@[elab_as_elim]
def recOnAppendSingle {motive : ∀ n, Composition n → Sort*} {n : ℕ} (c : Composition n)
(zero : motive 0 (ones 0))
(append_single : ∀ k n c, motive n c →
motive (n + (k + 1)) (append c (single (k + 1) k.succ_pos))) :
| motive n c :=
reverse_reverse c ▸ c.reverse.recOnSingleAppend zero fun k n c ih ↦ by
convert append_single k n c.reverse ih using 1
· apply add_comm
· rw [reverse_append, reverse_single]
apply cast_heq
end Composition
| Mathlib/Combinatorics/Enumerative/Composition.lean | 668 | 676 |
/-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl
-/
import Mathlib.Order.Filter.AtTopBot.Finset
import Mathlib.Topology.Algebra.InfiniteSum.Group
import Mathlib.Topology.Algebra.Star
/-!
# Topological sums and functorial constructions
Lemmas on the interaction of `tprod`, `tsum`, `HasProd`, `HasSum` etc with products, Sigma and Pi
types, `MulOpposite`, etc.
-/
noncomputable section
open Filter Finset Function
open scoped Topology
variable {α β γ : Type*}
/-! ## Product, Sigma and Pi types -/
section ProdDomain
variable [CommMonoid α] [TopologicalSpace α]
@[to_additive]
theorem hasProd_pi_single [DecidableEq β] (b : β) (a : α) : HasProd (Pi.mulSingle b a) a := by
convert hasProd_ite_eq b a
simp [Pi.mulSingle_apply]
@[to_additive (attr := simp)]
theorem tprod_pi_single [DecidableEq β] (b : β) (a : α) : ∏' b', Pi.mulSingle b a b' = a := by
rw [tprod_eq_mulSingle b]
· simp
· intro b' hb'; simp [hb']
@[to_additive tsum_setProd_singleton_left]
lemma tprod_setProd_singleton_left (b : β) (t : Set γ) (f : β × γ → α) :
(∏' x : {b} ×ˢ t, f x) = ∏' c : t, f (b, c) := by
rw [tprod_congr_set_coe _ Set.singleton_prod, tprod_image _ (Prod.mk_right_injective b).injOn]
@[to_additive tsum_setProd_singleton_right]
lemma tprod_setProd_singleton_right (s : Set β) (c : γ) (f : β × γ → α) :
(∏' x : s ×ˢ {c}, f x) = ∏' b : s, f (b, c) := by
rw [tprod_congr_set_coe _ Set.prod_singleton, tprod_image _ (Prod.mk_left_injective c).injOn]
@[to_additive Summable.prod_symm]
theorem Multipliable.prod_symm {f : β × γ → α} (hf : Multipliable f) :
Multipliable fun p : γ × β ↦ f p.swap :=
(Equiv.prodComm γ β).multipliable_iff.2 hf
end ProdDomain
section ProdCodomain
variable [CommMonoid α] [TopologicalSpace α] [CommMonoid γ] [TopologicalSpace γ]
@[to_additive HasSum.prodMk]
theorem HasProd.prodMk {f : β → α} {g : β → γ} {a : α} {b : γ} (hf : HasProd f a)
(hg : HasProd g b) : HasProd (fun x ↦ (⟨f x, g x⟩ : α × γ)) ⟨a, b⟩ := by
simp [HasProd, ← prod_mk_prod, Filter.Tendsto.prodMk_nhds hf hg]
@[deprecated (since := "2025-03-10")]
alias HasSum.prod_mk := HasSum.prodMk
@[to_additive existing HasSum.prodMk, deprecated (since := "2025-03-10")]
alias HasProd.prod_mk := HasProd.prodMk
end ProdCodomain
section ContinuousMul
variable [CommMonoid α] [TopologicalSpace α] [ContinuousMul α]
section Sum
| @[to_additive]
lemma HasProd.sum {α β M : Type*} [CommMonoid M] [TopologicalSpace M] [ContinuousMul M]
{f : α ⊕ β → M} {a b : M}
(h₁ : HasProd (f ∘ Sum.inl) a) (h₂ : HasProd (f ∘ Sum.inr) b) : HasProd f (a * b) := by
have : Tendsto ((∏ b ∈ ·, f b) ∘ sumEquiv.symm) (atTop.map sumEquiv) (nhds (a * b)) := by
rw [Finset.sumEquiv.map_atTop, ← prod_atTop_atTop_eq]
convert (tendsto_mul.comp (nhds_prod_eq (x := a) (y := b) ▸ Tendsto.prodMap h₁ h₂))
ext s
simp
simpa [Tendsto, ← Filter.map_map] using this
@[to_additive "For the statement that `tsum` commutes with `Finset.sum`,
see `Summable.tsum_finsetSum`."]
protected lemma Multipliable.tprod_sum {α β M : Type*} [CommMonoid M] [TopologicalSpace M]
[ContinuousMul M] [T2Space M] {f : α ⊕ β → M} (h₁ : Multipliable (f ∘ .inl))
(h₂ : Multipliable (f ∘ .inr)) : ∏' i, f i = (∏' i, f (.inl i)) * (∏' i, f (.inr i)) :=
(h₁.hasProd.sum h₂.hasProd).tprod_eq
| Mathlib/Topology/Algebra/InfiniteSum/Constructions.lean | 84 | 101 |
/-
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 | 2,038 | 2,046 | |
/-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Mario Carneiro
-/
import Mathlib.MeasureTheory.Measure.Comap
import Mathlib.MeasureTheory.Measure.QuasiMeasurePreserving
/-!
# Restricting a measure to a subset or a subtype
Given a measure `μ` on a type `α` and a subset `s` of `α`, we define a measure `μ.restrict s` as
the restriction of `μ` to `s` (still as a measure on `α`).
We investigate how this notion interacts with usual operations on measures (sum, pushforward,
pullback), and on sets (inclusion, union, Union).
We also study the relationship between the restriction of a measure to a subtype (given by the
pullback under `Subtype.val`) and the restriction to a set as above.
-/
open scoped ENNReal NNReal Topology
open Set MeasureTheory Measure Filter MeasurableSpace ENNReal Function
variable {R α β δ γ ι : Type*}
namespace MeasureTheory
variable {m0 : MeasurableSpace α} [MeasurableSpace β] [MeasurableSpace γ]
variable {μ μ₁ μ₂ μ₃ ν ν' ν₁ ν₂ : Measure α} {s s' t : Set α}
namespace Measure
/-! ### Restricting a measure -/
/-- Restrict a measure `μ` to a set `s` as an `ℝ≥0∞`-linear map. -/
noncomputable def restrictₗ {m0 : MeasurableSpace α} (s : Set α) : Measure α →ₗ[ℝ≥0∞] Measure α :=
liftLinear (OuterMeasure.restrict s) fun μ s' hs' t => by
suffices μ (s ∩ t) = μ (s ∩ t ∩ s') + μ ((s ∩ t) \ s') by
simpa [← Set.inter_assoc, Set.inter_comm _ s, ← inter_diff_assoc]
exact le_toOuterMeasure_caratheodory _ _ hs' _
/-- Restrict a measure `μ` to a set `s`. -/
noncomputable def restrict {_m0 : MeasurableSpace α} (μ : Measure α) (s : Set α) : Measure α :=
restrictₗ s μ
@[simp]
theorem restrictₗ_apply {_m0 : MeasurableSpace α} (s : Set α) (μ : Measure α) :
restrictₗ s μ = μ.restrict s :=
rfl
/-- This lemma shows that `restrict` and `toOuterMeasure` commute. Note that the LHS has a
restrict on measures and the RHS has a restrict on outer measures. -/
theorem restrict_toOuterMeasure_eq_toOuterMeasure_restrict (h : MeasurableSet s) :
(μ.restrict s).toOuterMeasure = OuterMeasure.restrict s μ.toOuterMeasure := by
simp_rw [restrict, restrictₗ, liftLinear, LinearMap.coe_mk, AddHom.coe_mk,
toMeasure_toOuterMeasure, OuterMeasure.restrict_trim h, μ.trimmed]
theorem restrict_apply₀ (ht : NullMeasurableSet t (μ.restrict s)) : μ.restrict s t = μ (t ∩ s) := by
rw [← restrictₗ_apply, restrictₗ, liftLinear_apply₀ _ ht, OuterMeasure.restrict_apply,
coe_toOuterMeasure]
/-- If `t` is a measurable set, then the measure of `t` with respect to the restriction of
the measure to `s` equals the outer measure of `t ∩ s`. An alternate version requiring that `s`
be measurable instead of `t` exists as `Measure.restrict_apply'`. -/
@[simp]
theorem restrict_apply (ht : MeasurableSet t) : μ.restrict s t = μ (t ∩ s) :=
restrict_apply₀ ht.nullMeasurableSet
/-- Restriction of a measure to a subset is monotone both in set and in measure. -/
theorem restrict_mono' {_m0 : MeasurableSpace α} ⦃s s' : Set α⦄ ⦃μ ν : Measure α⦄ (hs : s ≤ᵐ[μ] s')
(hμν : μ ≤ ν) : μ.restrict s ≤ ν.restrict s' :=
Measure.le_iff.2 fun t ht => calc
μ.restrict s t = μ (t ∩ s) := restrict_apply ht
_ ≤ μ (t ∩ s') := (measure_mono_ae <| hs.mono fun _x hx ⟨hxt, hxs⟩ => ⟨hxt, hx hxs⟩)
_ ≤ ν (t ∩ s') := le_iff'.1 hμν (t ∩ s')
_ = ν.restrict s' t := (restrict_apply ht).symm
/-- Restriction of a measure to a subset is monotone both in set and in measure. -/
@[mono, gcongr]
theorem restrict_mono {_m0 : MeasurableSpace α} ⦃s s' : Set α⦄ (hs : s ⊆ s') ⦃μ ν : Measure α⦄
(hμν : μ ≤ ν) : μ.restrict s ≤ ν.restrict s' :=
restrict_mono' (ae_of_all _ hs) hμν
@[gcongr]
theorem restrict_mono_measure {_ : MeasurableSpace α} {μ ν : Measure α} (h : μ ≤ ν) (s : Set α) :
μ.restrict s ≤ ν.restrict s :=
restrict_mono subset_rfl h
@[gcongr]
theorem restrict_mono_set {_ : MeasurableSpace α} (μ : Measure α) {s t : Set α} (h : s ⊆ t) :
μ.restrict s ≤ μ.restrict t :=
restrict_mono h le_rfl
theorem restrict_mono_ae (h : s ≤ᵐ[μ] t) : μ.restrict s ≤ μ.restrict t :=
restrict_mono' h (le_refl μ)
theorem restrict_congr_set (h : s =ᵐ[μ] t) : μ.restrict s = μ.restrict t :=
le_antisymm (restrict_mono_ae h.le) (restrict_mono_ae h.symm.le)
/-- If `s` is a measurable set, then the outer measure of `t` with respect to the restriction of
the measure to `s` equals the outer measure of `t ∩ s`. This is an alternate version of
`Measure.restrict_apply`, requiring that `s` is measurable instead of `t`. -/
@[simp]
theorem restrict_apply' (hs : MeasurableSet s) : μ.restrict s t = μ (t ∩ s) := by
rw [← toOuterMeasure_apply,
Measure.restrict_toOuterMeasure_eq_toOuterMeasure_restrict hs,
OuterMeasure.restrict_apply s t _, toOuterMeasure_apply]
theorem restrict_apply₀' (hs : NullMeasurableSet s μ) : μ.restrict s t = μ (t ∩ s) := by
rw [← restrict_congr_set hs.toMeasurable_ae_eq,
restrict_apply' (measurableSet_toMeasurable _ _),
measure_congr ((ae_eq_refl t).inter hs.toMeasurable_ae_eq)]
theorem restrict_le_self : μ.restrict s ≤ μ :=
Measure.le_iff.2 fun t ht => calc
μ.restrict s t = μ (t ∩ s) := restrict_apply ht
_ ≤ μ t := measure_mono inter_subset_left
variable (μ)
theorem restrict_eq_self (h : s ⊆ t) : μ.restrict t s = μ s :=
(le_iff'.1 restrict_le_self s).antisymm <|
calc
μ s ≤ μ (toMeasurable (μ.restrict t) s ∩ t) :=
measure_mono (subset_inter (subset_toMeasurable _ _) h)
_ = μ.restrict t s := by
rw [← restrict_apply (measurableSet_toMeasurable _ _), measure_toMeasurable]
@[simp]
theorem restrict_apply_self (s : Set α) : (μ.restrict s) s = μ s :=
restrict_eq_self μ Subset.rfl
variable {μ}
theorem restrict_apply_univ (s : Set α) : μ.restrict s univ = μ s := by
rw [restrict_apply MeasurableSet.univ, Set.univ_inter]
theorem le_restrict_apply (s t : Set α) : μ (t ∩ s) ≤ μ.restrict s t :=
calc
μ (t ∩ s) = μ.restrict s (t ∩ s) := (restrict_eq_self μ inter_subset_right).symm
_ ≤ μ.restrict s t := measure_mono inter_subset_left
theorem restrict_apply_le (s t : Set α) : μ.restrict s t ≤ μ t :=
Measure.le_iff'.1 restrict_le_self _
theorem restrict_apply_superset (h : s ⊆ t) : μ.restrict s t = μ s :=
((measure_mono (subset_univ _)).trans_eq <| restrict_apply_univ _).antisymm
((restrict_apply_self μ s).symm.trans_le <| measure_mono h)
@[simp]
theorem restrict_add {_m0 : MeasurableSpace α} (μ ν : Measure α) (s : Set α) :
(μ + ν).restrict s = μ.restrict s + ν.restrict s :=
(restrictₗ s).map_add μ ν
@[simp]
theorem restrict_zero {_m0 : MeasurableSpace α} (s : Set α) : (0 : Measure α).restrict s = 0 :=
(restrictₗ s).map_zero
@[simp]
theorem restrict_smul {_m0 : MeasurableSpace α} {R : Type*} [SMul R ℝ≥0∞]
[IsScalarTower R ℝ≥0∞ ℝ≥0∞] (c : R) (μ : Measure α) (s : Set α) :
(c • μ).restrict s = c • μ.restrict s := by
simpa only [smul_one_smul] using (restrictₗ s).map_smul (c • 1) μ
theorem restrict_restrict₀ (hs : NullMeasurableSet s (μ.restrict t)) :
(μ.restrict t).restrict s = μ.restrict (s ∩ t) :=
ext fun u hu => by
simp only [Set.inter_assoc, restrict_apply hu,
restrict_apply₀ (hu.nullMeasurableSet.inter hs)]
@[simp]
theorem restrict_restrict (hs : MeasurableSet s) : (μ.restrict t).restrict s = μ.restrict (s ∩ t) :=
restrict_restrict₀ hs.nullMeasurableSet
theorem restrict_restrict_of_subset (h : s ⊆ t) : (μ.restrict t).restrict s = μ.restrict s := by
ext1 u hu
rw [restrict_apply hu, restrict_apply hu, restrict_eq_self]
exact inter_subset_right.trans h
theorem restrict_restrict₀' (ht : NullMeasurableSet t μ) :
(μ.restrict t).restrict s = μ.restrict (s ∩ t) :=
ext fun u hu => by simp only [restrict_apply hu, restrict_apply₀' ht, inter_assoc]
theorem restrict_restrict' (ht : MeasurableSet t) :
(μ.restrict t).restrict s = μ.restrict (s ∩ t) :=
restrict_restrict₀' ht.nullMeasurableSet
theorem restrict_comm (hs : MeasurableSet s) :
(μ.restrict t).restrict s = (μ.restrict s).restrict t := by
rw [restrict_restrict hs, restrict_restrict' hs, inter_comm]
theorem restrict_apply_eq_zero (ht : MeasurableSet t) : μ.restrict s t = 0 ↔ μ (t ∩ s) = 0 := by
rw [restrict_apply ht]
theorem measure_inter_eq_zero_of_restrict (h : μ.restrict s t = 0) : μ (t ∩ s) = 0 :=
nonpos_iff_eq_zero.1 (h ▸ le_restrict_apply _ _)
theorem restrict_apply_eq_zero' (hs : MeasurableSet s) : μ.restrict s t = 0 ↔ μ (t ∩ s) = 0 := by
rw [restrict_apply' hs]
@[simp]
theorem restrict_eq_zero : μ.restrict s = 0 ↔ μ s = 0 := by
rw [← measure_univ_eq_zero, restrict_apply_univ]
/-- If `μ s ≠ 0`, then `μ.restrict s ≠ 0`, in terms of `NeZero` instances. -/
instance restrict.neZero [NeZero (μ s)] : NeZero (μ.restrict s) :=
⟨mt restrict_eq_zero.mp <| NeZero.ne _⟩
theorem restrict_zero_set {s : Set α} (h : μ s = 0) : μ.restrict s = 0 :=
restrict_eq_zero.2 h
@[simp]
theorem restrict_empty : μ.restrict ∅ = 0 :=
restrict_zero_set measure_empty
@[simp]
theorem restrict_univ : μ.restrict univ = μ :=
ext fun s hs => by simp [hs]
theorem restrict_inter_add_diff₀ (s : Set α) (ht : NullMeasurableSet t μ) :
μ.restrict (s ∩ t) + μ.restrict (s \ t) = μ.restrict s := by
ext1 u hu
simp only [add_apply, restrict_apply hu, ← inter_assoc, diff_eq]
exact measure_inter_add_diff₀ (u ∩ s) ht
theorem restrict_inter_add_diff (s : Set α) (ht : MeasurableSet t) :
μ.restrict (s ∩ t) + μ.restrict (s \ t) = μ.restrict s :=
restrict_inter_add_diff₀ s ht.nullMeasurableSet
theorem restrict_union_add_inter₀ (s : Set α) (ht : NullMeasurableSet t μ) :
μ.restrict (s ∪ t) + μ.restrict (s ∩ t) = μ.restrict s + μ.restrict t := by
rw [← restrict_inter_add_diff₀ (s ∪ t) ht, union_inter_cancel_right, union_diff_right, ←
restrict_inter_add_diff₀ s ht, add_comm, ← add_assoc, add_right_comm]
theorem restrict_union_add_inter (s : Set α) (ht : MeasurableSet t) :
μ.restrict (s ∪ t) + μ.restrict (s ∩ t) = μ.restrict s + μ.restrict t :=
restrict_union_add_inter₀ s ht.nullMeasurableSet
theorem restrict_union_add_inter' (hs : MeasurableSet s) (t : Set α) :
μ.restrict (s ∪ t) + μ.restrict (s ∩ t) = μ.restrict s + μ.restrict t := by
simpa only [union_comm, inter_comm, add_comm] using restrict_union_add_inter t hs
theorem restrict_union₀ (h : AEDisjoint μ s t) (ht : NullMeasurableSet t μ) :
μ.restrict (s ∪ t) = μ.restrict s + μ.restrict t := by
simp [← restrict_union_add_inter₀ s ht, restrict_zero_set h]
theorem restrict_union (h : Disjoint s t) (ht : MeasurableSet t) :
μ.restrict (s ∪ t) = μ.restrict s + μ.restrict t :=
restrict_union₀ h.aedisjoint ht.nullMeasurableSet
theorem restrict_union' (h : Disjoint s t) (hs : MeasurableSet s) :
μ.restrict (s ∪ t) = μ.restrict s + μ.restrict t := by
rw [union_comm, restrict_union h.symm hs, add_comm]
|
@[simp]
theorem restrict_add_restrict_compl (hs : MeasurableSet s) :
μ.restrict s + μ.restrict sᶜ = μ := by
| Mathlib/MeasureTheory/Measure/Restrict.lean | 255 | 258 |
/-
Copyright (c) 2020 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov, Patrick Massot, Sébastien Gouëzel
-/
import Mathlib.MeasureTheory.Integral.IntervalIntegral.Basic
import Mathlib.MeasureTheory.Integral.IntervalIntegral.FundThmCalculus
import Mathlib.MeasureTheory.Integral.IntervalIntegral.IntegrationByParts
deprecated_module (since := "2025-04-13")
| Mathlib/MeasureTheory/Integral/IntervalIntegral.lean | 605 | 609 | |
/-
Copyright (c) 2023 Kyle Miller. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kyle Miller
-/
import Mathlib.Data.Nat.Choose.Basic
import Mathlib.Data.Sym.Sym2
/-! # Unordered tuples of elements of a list
Defines `List.sym` and the specialized `List.sym2` for computing lists of all unordered n-tuples
from a given list. These are list versions of `Nat.multichoose`.
## Main declarations
* `List.sym`: `xs.sym n` is a list of all unordered n-tuples of elements from `xs`,
with multiplicity. The list's values are in `Sym α n`.
* `List.sym2`: `xs.sym2` is a list of all unordered pairs of elements from `xs`,
with multiplicity. The list's values are in `Sym2 α`.
## TODO
* Prove `protected theorem Perm.sym (n : ℕ) {xs ys : List α} (h : xs ~ ys) : xs.sym n ~ ys.sym n`
and lift the result to `Multiset` and `Finset`.
-/
namespace List
variable {α β : Type*}
section Sym2
/-- `xs.sym2` is a list of all unordered pairs of elements from `xs`.
If `xs` has no duplicates then neither does `xs.sym2`. -/
protected def sym2 : List α → List (Sym2 α)
| [] => []
| x :: xs => (x :: xs).map (fun y => s(x, y)) ++ xs.sym2
theorem sym2_map (f : α → β) (xs : List α) :
(xs.map f).sym2 = xs.sym2.map (Sym2.map f) := by
induction xs with
| nil => simp [List.sym2]
| cons x xs ih => simp [List.sym2, ih, Function.comp]
theorem mem_sym2_cons_iff {x : α} {xs : List α} {z : Sym2 α} :
z ∈ (x :: xs).sym2 ↔ z = s(x, x) ∨ (∃ y, y ∈ xs ∧ z = s(x, y)) ∨ z ∈ xs.sym2 := by
simp only [List.sym2, map_cons, cons_append, mem_cons, mem_append, mem_map]
simp only [eq_comm]
@[simp]
theorem sym2_eq_nil_iff {xs : List α} : xs.sym2 = [] ↔ xs = [] := by
cases xs <;> simp [List.sym2]
theorem left_mem_of_mk_mem_sym2 {xs : List α} {a b : α}
(h : s(a, b) ∈ xs.sym2) : a ∈ xs := by
induction xs with
| nil => exact (not_mem_nil h).elim
| cons x xs ih =>
rw [mem_cons]
rw [mem_sym2_cons_iff] at h
obtain (h | ⟨c, hc, h⟩ | h) := h
· rw [Sym2.eq_iff, ← and_or_left] at h
exact .inl h.1
· rw [Sym2.eq_iff] at h
obtain (⟨rfl, rfl⟩ | ⟨rfl, rfl⟩) := h <;> simp [hc]
· exact .inr <| ih h
theorem right_mem_of_mk_mem_sym2 {xs : List α} {a b : α}
(h : s(a, b) ∈ xs.sym2) : b ∈ xs := by
rw [Sym2.eq_swap] at h
exact left_mem_of_mk_mem_sym2 h
theorem mk_mem_sym2 {xs : List α} {a b : α} (ha : a ∈ xs) (hb : b ∈ xs) :
s(a, b) ∈ xs.sym2 := by
induction xs with
| nil => simp at ha
| cons x xs ih =>
rw [mem_sym2_cons_iff]
rw [mem_cons] at ha hb
obtain (rfl | ha) := ha <;> obtain (rfl | hb) := hb
· left; rfl
· right; left; use b
· right; left; rw [Sym2.eq_swap]; use a
· right; right; exact ih ha hb
theorem mk_mem_sym2_iff {xs : List α} {a b : α} :
s(a, b) ∈ xs.sym2 ↔ a ∈ xs ∧ b ∈ xs := by
constructor
· intro h
exact ⟨left_mem_of_mk_mem_sym2 h, right_mem_of_mk_mem_sym2 h⟩
· rintro ⟨ha, hb⟩
exact mk_mem_sym2 ha hb
theorem mem_sym2_iff {xs : List α} {z : Sym2 α} :
z ∈ xs.sym2 ↔ ∀ y ∈ z, y ∈ xs := by
refine z.ind (fun a b => ?_)
simp [mk_mem_sym2_iff]
protected theorem Nodup.sym2 {xs : List α} (h : xs.Nodup) : xs.sym2.Nodup := by
induction xs with
| nil => simp only [List.sym2, nodup_nil]
| cons x xs ih =>
rw [List.sym2]
specialize ih h.of_cons
rw [nodup_cons] at h
refine Nodup.append (Nodup.cons ?notmem (h.2.map ?inj)) ih ?disj
case disj =>
intro z hz hz'
simp only [mem_cons, mem_map] at hz
obtain ⟨_, (rfl | _), rfl⟩ := hz
<;> simp [left_mem_of_mk_mem_sym2 hz'] at h
case notmem =>
intro h'
simp only [h.1, mem_map, Sym2.eq_iff, true_and, or_self, exists_eq_right] at h'
case inj =>
intro a b
simp only [Sym2.eq_iff, true_and]
rintro (rfl | ⟨rfl, rfl⟩) <;> rfl
theorem map_mk_sublist_sym2 (x : α) (xs : List α) (h : x ∈ xs) :
map (fun y ↦ s(x, y)) xs <+ xs.sym2 := by
induction xs with
| nil => simp
| cons x' xs ih =>
simp only [map_cons, List.sym2, cons_append]
cases h with
| head =>
exact (sublist_append_left _ _).cons₂ _
| tail _ h =>
refine .cons _ ?_
rw [← singleton_append]
refine .append ?_ (ih h)
rw [singleton_sublist, mem_map]
exact ⟨_, h, Sym2.eq_swap⟩
theorem map_mk_disjoint_sym2 (x : α) (xs : List α) (h : x ∉ xs) :
(map (fun y ↦ s(x, y)) xs).Disjoint xs.sym2 := by
induction xs with
| nil => simp
| cons x' xs ih =>
| simp only [mem_cons, not_or] at h
rw [List.sym2, map_cons, map_cons, disjoint_cons_left, disjoint_append_right,
disjoint_cons_right]
| Mathlib/Data/List/Sym.lean | 142 | 144 |
/-
Copyright (c) 2023 Yaël Dillies, Chenyi Li. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chenyi Li, Ziyu Wang, Yaël Dillies
-/
import Mathlib.Analysis.Convex.Function
import Mathlib.Analysis.InnerProductSpace.Basic
/-!
# Uniformly and strongly convex functions
In this file, we define uniformly convex functions and strongly convex functions.
For a real normed space `E`, a uniformly convex function with modulus `φ : ℝ → ℝ` is a function
`f : E → ℝ` such that `f (t • x + (1 - t) • y) ≤ t • f x + (1 - t) • f y - t * (1 - t) * φ ‖x - y‖`
for all `t ∈ [0, 1]`.
A `m`-strongly convex function is a uniformly convex function with modulus `fun r ↦ m / 2 * r ^ 2`.
If `E` is an inner product space, this is equivalent to `x ↦ f x - m / 2 * ‖x‖ ^ 2` being convex.
## TODO
Prove derivative properties of strongly convex functions.
-/
open Real
variable {E : Type*} [NormedAddCommGroup E]
section NormedSpace
variable [NormedSpace ℝ E] {φ ψ : ℝ → ℝ} {s : Set E} {m : ℝ} {f g : E → ℝ}
/-- A function `f` from a real normed space is uniformly convex with modulus `φ` if
`f (t • x + (1 - t) • y) ≤ t • f x + (1 - t) • f y - t * (1 - t) * φ ‖x - y‖` for all `t ∈ [0, 1]`.
`φ` is usually taken to be a monotone function such that `φ r = 0 ↔ r = 0`. -/
def UniformConvexOn (s : Set E) (φ : ℝ → ℝ) (f : E → ℝ) : Prop :=
Convex ℝ s ∧ ∀ ⦃x⦄, x ∈ s → ∀ ⦃y⦄, y ∈ s → ∀ ⦃a b : ℝ⦄, 0 ≤ a → 0 ≤ b → a + b = 1 →
f (a • x + b • y) ≤ a • f x + b • f y - a * b * φ ‖x - y‖
/-- A function `f` from a real normed space is uniformly concave with modulus `φ` if
`t • f x + (1 - t) • f y + t * (1 - t) * φ ‖x - y‖ ≤ f (t • x + (1 - t) • y)` for all `t ∈ [0, 1]`.
`φ` is usually taken to be a monotone function such that `φ r = 0 ↔ r = 0`. -/
def UniformConcaveOn (s : Set E) (φ : ℝ → ℝ) (f : E → ℝ) : Prop :=
Convex ℝ s ∧ ∀ ⦃x⦄, x ∈ s → ∀ ⦃y⦄, y ∈ s → ∀ ⦃a b : ℝ⦄, 0 ≤ a → 0 ≤ b → a + b = 1 →
a • f x + b • f y + a * b * φ ‖x - y‖ ≤ f (a • x + b • y)
@[simp] lemma uniformConvexOn_zero : UniformConvexOn s 0 f ↔ ConvexOn ℝ s f := by
simp [UniformConvexOn, ConvexOn]
@[simp] lemma uniformConcaveOn_zero : UniformConcaveOn s 0 f ↔ ConcaveOn ℝ s f := by
simp [UniformConcaveOn, ConcaveOn]
protected alias ⟨_, ConvexOn.uniformConvexOn_zero⟩ := uniformConvexOn_zero
protected alias ⟨_, ConcaveOn.uniformConcaveOn_zero⟩ := uniformConcaveOn_zero
lemma UniformConvexOn.mono (hψφ : ψ ≤ φ) (hf : UniformConvexOn s φ f) : UniformConvexOn s ψ f :=
⟨hf.1, fun x hx y hy a b ha hb hab ↦ (hf.2 hx hy ha hb hab).trans <| by gcongr; apply hψφ⟩
lemma UniformConcaveOn.mono (hψφ : ψ ≤ φ) (hf : UniformConcaveOn s φ f) : UniformConcaveOn s ψ f :=
⟨hf.1, fun x hx y hy a b ha hb hab ↦ (hf.2 hx hy ha hb hab).trans' <| by gcongr; apply hψφ⟩
lemma UniformConvexOn.convexOn (hf : UniformConvexOn s φ f) (hφ : 0 ≤ φ) : ConvexOn ℝ s f := by
simpa using hf.mono hφ
lemma UniformConcaveOn.concaveOn (hf : UniformConcaveOn s φ f) (hφ : 0 ≤ φ) : ConcaveOn ℝ s f := by
simpa using hf.mono hφ
lemma UniformConvexOn.strictConvexOn (hf : UniformConvexOn s φ f) (hφ : ∀ r, r ≠ 0 → 0 < φ r) :
StrictConvexOn ℝ s f := by
refine ⟨hf.1, fun x hx y hy hxy a b ha hb hab ↦ (hf.2 hx hy ha.le hb.le hab).trans_lt <|
sub_lt_self _ ?_⟩
rw [← sub_ne_zero, ← norm_pos_iff] at hxy
have := hφ _ hxy.ne'
positivity
lemma UniformConcaveOn.strictConcaveOn (hf : UniformConcaveOn s φ f) (hφ : ∀ r, r ≠ 0 → 0 < φ r) :
StrictConcaveOn ℝ s f := by
refine ⟨hf.1, fun x hx y hy hxy a b ha hb hab ↦ (hf.2 hx hy ha.le hb.le hab).trans_lt' <|
lt_add_of_pos_right _ ?_⟩
rw [← sub_ne_zero, ← norm_pos_iff] at hxy
have := hφ _ hxy.ne'
positivity
lemma UniformConvexOn.add (hf : UniformConvexOn s φ f) (hg : UniformConvexOn s ψ g) :
UniformConvexOn s (φ + ψ) (f + g) := by
refine ⟨hf.1, fun x hx y hy a b ha hb hab ↦ ?_⟩
simpa [mul_add, add_add_add_comm, sub_add_sub_comm]
using add_le_add (hf.2 hx hy ha hb hab) (hg.2 hx hy ha hb hab)
lemma UniformConcaveOn.add (hf : UniformConcaveOn s φ f) (hg : UniformConcaveOn s ψ g) :
UniformConcaveOn s (φ + ψ) (f + g) := by
refine ⟨hf.1, fun x hx y hy a b ha hb hab ↦ ?_⟩
simpa [mul_add, add_add_add_comm] using add_le_add (hf.2 hx hy ha hb hab) (hg.2 hx hy ha hb hab)
lemma UniformConvexOn.neg (hf : UniformConvexOn s φ f) : UniformConcaveOn s φ (-f) := by
refine ⟨hf.1, fun x hx y hy a b ha hb hab ↦ le_of_neg_le_neg ?_⟩
simpa [add_comm, -neg_le_neg_iff, le_sub_iff_add_le'] using hf.2 hx hy ha hb hab
|
lemma UniformConcaveOn.neg (hf : UniformConcaveOn s φ f) : UniformConvexOn s φ (-f) := by
refine ⟨hf.1, fun x hx y hy a b ha hb hab ↦ le_of_neg_le_neg ?_⟩
simpa [add_comm, -neg_le_neg_iff, ← le_sub_iff_add_le', sub_eq_add_neg, neg_add]
| Mathlib/Analysis/Convex/Strong.lean | 100 | 103 |
/-
Copyright (c) 2019 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sébastien Gouëzel
-/
import Mathlib.Data.Bundle
import Mathlib.Data.Set.Image
import Mathlib.Topology.CompactOpen
import Mathlib.Topology.PartialHomeomorph
import Mathlib.Topology.Order.Basic
/-!
# Trivializations
## Main definitions
### Basic definitions
* `Trivialization F p` : structure extending partial homeomorphisms, defining a local
trivialization of a topological space `Z` with projection `p` and fiber `F`.
* `Pretrivialization F proj` : trivialization as a partial equivalence, mainly used when the
topology on the total space has not yet been defined.
### Operations on bundles
We provide the following operations on `Trivialization`s.
* `Trivialization.compHomeomorph`: given a local trivialization `e` of a fiber bundle
`p : Z → B` and a homeomorphism `h : Z' ≃ₜ Z`, returns a local trivialization of the fiber bundle
`p ∘ h`.
## Implementation notes
Previously, in mathlib, there was a structure `topological_vector_bundle.trivialization` which
extended another structure `topological_fiber_bundle.trivialization` by a linearity hypothesis. As
of PR https://github.com/leanprover-community/mathlib3/pull/17359, we have changed this to a single structure
`Trivialization` (no namespace), together with a mixin class `Trivialization.IsLinear`.
This permits all the *data* of a vector bundle to be held at the level of fiber bundles, so that the
same trivializations can underlie an object's structure as (say) a vector bundle over `ℂ` and as a
vector bundle over `ℝ`, as well as its structure simply as a fiber bundle.
This might be a little surprising, given the general trend of the library to ever-increased
bundling. But in this case the typical motivation for more bundling does not apply: there is no
algebraic or order structure on the whole type of linear (say) trivializations of a bundle.
Indeed, since trivializations only have meaning on their base sets (taking junk values outside), the
type of linear trivializations is not even particularly well-behaved.
-/
open TopologicalSpace Filter Set Bundle Function
open scoped Topology
variable {B : Type*} (F : Type*) {E : B → Type*}
variable {Z : Type*} [TopologicalSpace B] [TopologicalSpace F] {proj : Z → B}
/-- This structure contains the information left for a local trivialization (which is implemented
below as `Trivialization F proj`) if the total space has not been given a topology, but we
have a topology on both the fiber and the base space. Through the construction
`topological_fiber_prebundle F proj` it will be possible to promote a
`Pretrivialization F proj` to a `Trivialization F proj`. -/
structure Pretrivialization (proj : Z → B) extends PartialEquiv Z (B × F) where
open_target : IsOpen target
baseSet : Set B
open_baseSet : IsOpen baseSet
source_eq : source = proj ⁻¹' baseSet
target_eq : target = baseSet ×ˢ univ
proj_toFun : ∀ p ∈ source, (toFun p).1 = proj p
namespace Pretrivialization
variable {F}
variable (e : Pretrivialization F proj) {x : Z}
/-- Coercion of a pretrivialization to a function. We don't use `e.toFun` in the `CoeFun` instance
because it is actually `e.toPartialEquiv.toFun`, so `simp` will apply lemmas about
`toPartialEquiv`. While we may want to switch to this behavior later, doing it mid-port will break a
lot of proofs. -/
@[coe] def toFun' : Z → (B × F) := e.toFun
instance : CoeFun (Pretrivialization F proj) fun _ => Z → B × F := ⟨toFun'⟩
@[ext]
lemma ext' (e e' : Pretrivialization F proj) (h₁ : e.toPartialEquiv = e'.toPartialEquiv)
(h₂ : e.baseSet = e'.baseSet) : e = e' := by
cases e; cases e'; congr
-- TODO: move `ext` here?
lemma ext {e e' : Pretrivialization F proj} (h₁ : ∀ x, e x = e' x)
(h₂ : ∀ x, e.toPartialEquiv.symm x = e'.toPartialEquiv.symm x) (h₃ : e.baseSet = e'.baseSet) :
e = e' := by
ext1 <;> [ext1; exact h₃]
· apply h₁
· apply h₂
· rw [e.source_eq, e'.source_eq, h₃]
/-- If the fiber is nonempty, then the projection also is. -/
lemma toPartialEquiv_injective [Nonempty F] :
Injective (toPartialEquiv : Pretrivialization F proj → PartialEquiv Z (B × F)) := by
refine fun e e' h ↦ ext' _ _ h ?_
simpa only [fst_image_prod, univ_nonempty, target_eq]
using congr_arg (Prod.fst '' PartialEquiv.target ·) h
@[simp, mfld_simps]
theorem coe_coe : ⇑e.toPartialEquiv = e :=
rfl
@[simp, mfld_simps]
theorem coe_fst (ex : x ∈ e.source) : (e x).1 = proj x :=
e.proj_toFun x ex
theorem mem_source : x ∈ e.source ↔ proj x ∈ e.baseSet := by rw [e.source_eq, mem_preimage]
theorem coe_fst' (ex : proj x ∈ e.baseSet) : (e x).1 = proj x :=
e.coe_fst (e.mem_source.2 ex)
protected theorem eqOn : EqOn (Prod.fst ∘ e) proj e.source := fun _ hx => e.coe_fst hx
theorem mk_proj_snd (ex : x ∈ e.source) : (proj x, (e x).2) = e x :=
Prod.ext (e.coe_fst ex).symm rfl
theorem mk_proj_snd' (ex : proj x ∈ e.baseSet) : (proj x, (e x).2) = e x :=
Prod.ext (e.coe_fst' ex).symm rfl
/-- Composition of inverse and coercion from the subtype of the target. -/
def setSymm : e.target → Z :=
e.target.restrict e.toPartialEquiv.symm
theorem mem_target {x : B × F} : x ∈ e.target ↔ x.1 ∈ e.baseSet := by
rw [e.target_eq, prod_univ, mem_preimage]
theorem proj_symm_apply {x : B × F} (hx : x ∈ e.target) : proj (e.toPartialEquiv.symm x) = x.1 := by
have := (e.coe_fst (e.map_target hx)).symm
rwa [← e.coe_coe, e.right_inv hx] at this
theorem proj_symm_apply' {b : B} {x : F} (hx : b ∈ e.baseSet) :
proj (e.toPartialEquiv.symm (b, x)) = b :=
e.proj_symm_apply (e.mem_target.2 hx)
theorem proj_surjOn_baseSet [Nonempty F] : Set.SurjOn proj e.source e.baseSet := fun b hb =>
let ⟨y⟩ := ‹Nonempty F›
⟨e.toPartialEquiv.symm (b, y), e.toPartialEquiv.map_target <| e.mem_target.2 hb,
e.proj_symm_apply' hb⟩
theorem apply_symm_apply {x : B × F} (hx : x ∈ e.target) : e (e.toPartialEquiv.symm x) = x :=
e.toPartialEquiv.right_inv hx
theorem apply_symm_apply' {b : B} {x : F} (hx : b ∈ e.baseSet) :
e (e.toPartialEquiv.symm (b, x)) = (b, x) :=
e.apply_symm_apply (e.mem_target.2 hx)
theorem symm_apply_apply {x : Z} (hx : x ∈ e.source) : e.toPartialEquiv.symm (e x) = x :=
e.toPartialEquiv.left_inv hx
@[simp, mfld_simps]
theorem symm_apply_mk_proj {x : Z} (ex : x ∈ e.source) :
e.toPartialEquiv.symm (proj x, (e x).2) = x := by
rw [← e.coe_fst ex, ← e.coe_coe, e.left_inv ex]
@[simp, mfld_simps]
theorem preimage_symm_proj_baseSet :
e.toPartialEquiv.symm ⁻¹' (proj ⁻¹' e.baseSet) ∩ e.target = e.target := by
refine inter_eq_right.mpr fun x hx => ?_
simp only [mem_preimage, PartialEquiv.invFun_as_coe, e.proj_symm_apply hx]
exact e.mem_target.mp hx
@[simp, mfld_simps]
theorem preimage_symm_proj_inter (s : Set B) :
e.toPartialEquiv.symm ⁻¹' (proj ⁻¹' s) ∩ e.baseSet ×ˢ univ = (s ∩ e.baseSet) ×ˢ univ := by
ext ⟨x, y⟩
suffices x ∈ e.baseSet → (proj (e.toPartialEquiv.symm (x, y)) ∈ s ↔ x ∈ s) by
simpa only [prodMk_mem_set_prod_eq, mem_inter_iff, and_true, mem_univ, and_congr_left_iff]
intro h
rw [e.proj_symm_apply' h]
theorem target_inter_preimage_symm_source_eq (e f : Pretrivialization F proj) :
f.target ∩ f.toPartialEquiv.symm ⁻¹' e.source = (e.baseSet ∩ f.baseSet) ×ˢ univ := by
rw [inter_comm, f.target_eq, e.source_eq, f.preimage_symm_proj_inter]
theorem trans_source (e f : Pretrivialization F proj) :
(f.toPartialEquiv.symm.trans e.toPartialEquiv).source = (e.baseSet ∩ f.baseSet) ×ˢ univ := by
rw [PartialEquiv.trans_source, PartialEquiv.symm_source, e.target_inter_preimage_symm_source_eq]
theorem symm_trans_symm (e e' : Pretrivialization F proj) :
(e.toPartialEquiv.symm.trans e'.toPartialEquiv).symm
= e'.toPartialEquiv.symm.trans e.toPartialEquiv := by
rw [PartialEquiv.trans_symm_eq_symm_trans_symm, PartialEquiv.symm_symm]
theorem symm_trans_source_eq (e e' : Pretrivialization F proj) :
(e.toPartialEquiv.symm.trans e'.toPartialEquiv).source = (e.baseSet ∩ e'.baseSet) ×ˢ univ := by
rw [PartialEquiv.trans_source, e'.source_eq, PartialEquiv.symm_source, e.target_eq, inter_comm,
e.preimage_symm_proj_inter, inter_comm]
theorem symm_trans_target_eq (e e' : Pretrivialization F proj) :
(e.toPartialEquiv.symm.trans e'.toPartialEquiv).target = (e.baseSet ∩ e'.baseSet) ×ˢ univ := by
rw [← PartialEquiv.symm_source, symm_trans_symm, symm_trans_source_eq, inter_comm]
variable (e' : Pretrivialization F (π F E)) {b : B} {y : E b}
@[simp]
theorem coe_mem_source : ↑y ∈ e'.source ↔ b ∈ e'.baseSet :=
e'.mem_source
@[simp, mfld_simps]
theorem coe_coe_fst (hb : b ∈ e'.baseSet) : (e' y).1 = b :=
e'.coe_fst (e'.mem_source.2 hb)
theorem mk_mem_target {x : B} {y : F} : (x, y) ∈ e'.target ↔ x ∈ e'.baseSet :=
e'.mem_target
theorem symm_coe_proj {x : B} {y : F} (e' : Pretrivialization F (π F E)) (h : x ∈ e'.baseSet) :
(e'.toPartialEquiv.symm (x, y)).1 = x :=
e'.proj_symm_apply' h
section Zero
variable [∀ x, Zero (E x)]
open Classical in
/-- A fiberwise inverse to `e`. This is the function `F → E b` that induces a local inverse
`B × F → TotalSpace F E` of `e` on `e.baseSet`. It is defined to be `0` outside `e.baseSet`. -/
protected noncomputable def symm (e : Pretrivialization F (π F E)) (b : B) (y : F) : E b :=
if hb : b ∈ e.baseSet then
cast (congr_arg E (e.proj_symm_apply' hb)) (e.toPartialEquiv.symm (b, y)).2
else 0
theorem symm_apply (e : Pretrivialization F (π F E)) {b : B} (hb : b ∈ e.baseSet) (y : F) :
e.symm b y = cast (congr_arg E (e.symm_coe_proj hb)) (e.toPartialEquiv.symm (b, y)).2 :=
dif_pos hb
theorem symm_apply_of_not_mem (e : Pretrivialization F (π F E)) {b : B} (hb : b ∉ e.baseSet)
(y : F) : e.symm b y = 0 :=
dif_neg hb
theorem coe_symm_of_not_mem (e : Pretrivialization F (π F E)) {b : B} (hb : b ∉ e.baseSet) :
(e.symm b : F → E b) = 0 :=
funext fun _ => dif_neg hb
theorem mk_symm (e : Pretrivialization F (π F E)) {b : B} (hb : b ∈ e.baseSet) (y : F) :
TotalSpace.mk b (e.symm b y) = e.toPartialEquiv.symm (b, y) := by
simp only [e.symm_apply hb, TotalSpace.mk_cast (e.proj_symm_apply' hb), TotalSpace.eta]
theorem symm_proj_apply (e : Pretrivialization F (π F E)) (z : TotalSpace F E)
(hz : z.proj ∈ e.baseSet) : e.symm z.proj (e z).2 = z.2 := by
rw [e.symm_apply hz, cast_eq_iff_heq, e.mk_proj_snd' hz, e.symm_apply_apply (e.mem_source.mpr hz)]
theorem symm_apply_apply_mk (e : Pretrivialization F (π F E)) {b : B} (hb : b ∈ e.baseSet)
(y : E b) : e.symm b (e ⟨b, y⟩).2 = y :=
e.symm_proj_apply ⟨b, y⟩ hb
theorem apply_mk_symm (e : Pretrivialization F (π F E)) {b : B} (hb : b ∈ e.baseSet) (y : F) :
e ⟨b, e.symm b y⟩ = (b, y) := by
rw [e.mk_symm hb, e.apply_symm_apply (e.mk_mem_target.mpr hb)]
end Zero
end Pretrivialization
variable [TopologicalSpace Z] [TopologicalSpace (TotalSpace F E)]
/-- A structure extending partial homeomorphisms, defining a local trivialization of a projection
`proj : Z → B` with fiber `F`, as a partial homeomorphism between `Z` and `B × F` defined between
two sets of the form `proj ⁻¹' baseSet` and `baseSet × F`, acting trivially on the first coordinate.
-/
structure Trivialization (proj : Z → B) extends PartialHomeomorph Z (B × F) where
baseSet : Set B
open_baseSet : IsOpen baseSet
source_eq : source = proj ⁻¹' baseSet
target_eq : target = baseSet ×ˢ univ
proj_toFun : ∀ p ∈ source, (toPartialHomeomorph p).1 = proj p
namespace Trivialization
variable {F}
variable (e : Trivialization F proj) {x : Z}
@[ext]
lemma ext' (e e' : Trivialization F proj) (h₁ : e.toPartialHomeomorph = e'.toPartialHomeomorph)
(h₂ : e.baseSet = e'.baseSet) : e = e' := by
cases e; cases e'; congr
/-- Coercion of a trivialization to a function. We don't use `e.toFun` in the `CoeFun` instance
because it is actually `e.toPartialEquiv.toFun`, so `simp` will apply lemmas about
`toPartialEquiv`. While we may want to switch to this behavior later, doing it mid-port will break a
lot of proofs. -/
@[coe] def toFun' : Z → (B × F) := e.toFun
/-- Natural identification as a `Pretrivialization`. -/
def toPretrivialization : Pretrivialization F proj :=
{ e with }
instance : CoeFun (Trivialization F proj) fun _ => Z → B × F := ⟨toFun'⟩
instance : Coe (Trivialization F proj) (Pretrivialization F proj) :=
⟨toPretrivialization⟩
theorem toPretrivialization_injective :
Function.Injective fun e : Trivialization F proj => e.toPretrivialization := fun e e' h => by
ext1
exacts [PartialHomeomorph.toPartialEquiv_injective (congr_arg Pretrivialization.toPartialEquiv h),
congr_arg Pretrivialization.baseSet h]
@[simp, mfld_simps]
theorem coe_coe : ⇑e.toPartialHomeomorph = e :=
rfl
@[simp, mfld_simps]
theorem coe_fst (ex : x ∈ e.source) : (e x).1 = proj x :=
e.proj_toFun x ex
protected theorem eqOn : EqOn (Prod.fst ∘ e) proj e.source := fun _x hx => e.coe_fst hx
theorem mem_source : x ∈ e.source ↔ proj x ∈ e.baseSet := by rw [e.source_eq, mem_preimage]
theorem coe_fst' (ex : proj x ∈ e.baseSet) : (e x).1 = proj x :=
e.coe_fst (e.mem_source.2 ex)
theorem mk_proj_snd (ex : x ∈ e.source) : (proj x, (e x).2) = e x :=
Prod.ext (e.coe_fst ex).symm rfl
theorem mk_proj_snd' (ex : proj x ∈ e.baseSet) : (proj x, (e x).2) = e x :=
Prod.ext (e.coe_fst' ex).symm rfl
theorem source_inter_preimage_target_inter (s : Set (B × F)) :
e.source ∩ e ⁻¹' (e.target ∩ s) = e.source ∩ e ⁻¹' s :=
e.toPartialHomeomorph.source_inter_preimage_target_inter s
@[simp, mfld_simps]
theorem coe_mk (e : PartialHomeomorph Z (B × F)) (i j k l m) (x : Z) :
(Trivialization.mk e i j k l m : Trivialization F proj) x = e x :=
rfl
theorem mem_target {x : B × F} : x ∈ e.target ↔ x.1 ∈ e.baseSet :=
e.toPretrivialization.mem_target
theorem map_target {x : B × F} (hx : x ∈ e.target) : e.toPartialHomeomorph.symm x ∈ e.source :=
e.toPartialHomeomorph.map_target hx
theorem proj_symm_apply {x : B × F} (hx : x ∈ e.target) :
proj (e.toPartialHomeomorph.symm x) = x.1 :=
e.toPretrivialization.proj_symm_apply hx
theorem proj_symm_apply' {b : B} {x : F} (hx : b ∈ e.baseSet) :
proj (e.toPartialHomeomorph.symm (b, x)) = b :=
e.toPretrivialization.proj_symm_apply' hx
theorem proj_surjOn_baseSet [Nonempty F] : Set.SurjOn proj e.source e.baseSet :=
e.toPretrivialization.proj_surjOn_baseSet
theorem apply_symm_apply {x : B × F} (hx : x ∈ e.target) : e (e.toPartialHomeomorph.symm x) = x :=
e.toPartialHomeomorph.right_inv hx
theorem apply_symm_apply' {b : B} {x : F} (hx : b ∈ e.baseSet) :
e (e.toPartialHomeomorph.symm (b, x)) = (b, x) :=
e.toPretrivialization.apply_symm_apply' hx
@[simp, mfld_simps]
theorem symm_apply_mk_proj (ex : x ∈ e.source) : e.toPartialHomeomorph.symm (proj x, (e x).2) = x :=
e.toPretrivialization.symm_apply_mk_proj ex
theorem symm_trans_source_eq (e e' : Trivialization F proj) :
(e.toPartialEquiv.symm.trans e'.toPartialEquiv).source = (e.baseSet ∩ e'.baseSet) ×ˢ univ :=
Pretrivialization.symm_trans_source_eq e.toPretrivialization e'
theorem symm_trans_target_eq (e e' : Trivialization F proj) :
(e.toPartialEquiv.symm.trans e'.toPartialEquiv).target = (e.baseSet ∩ e'.baseSet) ×ˢ univ :=
Pretrivialization.symm_trans_target_eq e.toPretrivialization e'
theorem coe_fst_eventuallyEq_proj (ex : x ∈ e.source) : Prod.fst ∘ e =ᶠ[𝓝 x] proj :=
mem_nhds_iff.2 ⟨e.source, fun _y hy => e.coe_fst hy, e.open_source, ex⟩
theorem coe_fst_eventuallyEq_proj' (ex : proj x ∈ e.baseSet) : Prod.fst ∘ e =ᶠ[𝓝 x] proj :=
e.coe_fst_eventuallyEq_proj (e.mem_source.2 ex)
theorem map_proj_nhds (ex : x ∈ e.source) : map proj (𝓝 x) = 𝓝 (proj x) := by
rw [← e.coe_fst ex, ← map_congr (e.coe_fst_eventuallyEq_proj ex), ← map_map, ← e.coe_coe,
e.map_nhds_eq ex, map_fst_nhds]
theorem preimage_subset_source {s : Set B} (hb : s ⊆ e.baseSet) : proj ⁻¹' s ⊆ e.source :=
fun _p hp => e.mem_source.mpr (hb hp)
theorem image_preimage_eq_prod_univ {s : Set B} (hb : s ⊆ e.baseSet) :
e '' (proj ⁻¹' s) = s ×ˢ univ :=
Subset.antisymm
(image_subset_iff.mpr fun p hp =>
⟨(e.proj_toFun p (e.preimage_subset_source hb hp)).symm ▸ hp, trivial⟩)
fun p hp =>
let hp' : p ∈ e.target := e.mem_target.mpr (hb hp.1)
⟨e.invFun p, mem_preimage.mpr ((e.proj_symm_apply hp').symm ▸ hp.1), e.apply_symm_apply hp'⟩
theorem tendsto_nhds_iff {α : Type*} {l : Filter α} {f : α → Z} {z : Z} (hz : z ∈ e.source) :
Tendsto f l (𝓝 z) ↔
Tendsto (proj ∘ f) l (𝓝 (proj z)) ∧ Tendsto (fun x ↦ (e (f x)).2) l (𝓝 (e z).2) := by
rw [e.nhds_eq_comap_inf_principal hz, tendsto_inf, tendsto_comap_iff, Prod.tendsto_iff, coe_coe,
tendsto_principal, coe_fst _ hz]
by_cases hl : ∀ᶠ x in l, f x ∈ e.source
· simp only [hl, and_true]
refine (tendsto_congr' ?_).and Iff.rfl
exact hl.mono fun x ↦ e.coe_fst
· simp only [hl, and_false, false_iff, not_and]
rw [e.source_eq] at hl hz
exact fun h _ ↦ hl <| h <| e.open_baseSet.mem_nhds hz
theorem nhds_eq_inf_comap {z : Z} (hz : z ∈ e.source) :
𝓝 z = comap proj (𝓝 (proj z)) ⊓ comap (Prod.snd ∘ e) (𝓝 (e z).2) := by
refine eq_of_forall_le_iff fun l ↦ ?_
rw [le_inf_iff, ← tendsto_iff_comap, ← tendsto_iff_comap]
exact e.tendsto_nhds_iff hz
/-- The preimage of a subset of the base set is homeomorphic to the product with the fiber. -/
def preimageHomeomorph {s : Set B} (hb : s ⊆ e.baseSet) : proj ⁻¹' s ≃ₜ s × F :=
(e.toPartialHomeomorph.homeomorphOfImageSubsetSource (e.preimage_subset_source hb)
(e.image_preimage_eq_prod_univ hb)).trans
((Homeomorph.Set.prod s univ).trans ((Homeomorph.refl s).prodCongr (Homeomorph.Set.univ F)))
@[simp]
theorem preimageHomeomorph_apply {s : Set B} (hb : s ⊆ e.baseSet) (p : proj ⁻¹' s) :
e.preimageHomeomorph hb p = (⟨proj p, p.2⟩, (e p).2) :=
Prod.ext (Subtype.ext (e.proj_toFun p (e.mem_source.mpr (hb p.2)))) rfl
/-- Auxiliary definition to avoid looping in `dsimp`
with `Trivialization.preimageHomeomorph_symm_apply`. -/
protected def preimageHomeomorph_symm_apply.aux {s : Set B} (hb : s ⊆ e.baseSet) :=
(e.preimageHomeomorph hb).symm
@[simp]
theorem preimageHomeomorph_symm_apply {s : Set B} (hb : s ⊆ e.baseSet) (p : s × F) :
(e.preimageHomeomorph hb).symm p =
⟨e.symm (p.1, p.2), ((preimageHomeomorph_symm_apply.aux e hb) p).2⟩ :=
rfl
/-- The source is homeomorphic to the product of the base set with the fiber. -/
def sourceHomeomorphBaseSetProd : e.source ≃ₜ e.baseSet × F :=
(Homeomorph.setCongr e.source_eq).trans (e.preimageHomeomorph subset_rfl)
@[simp]
theorem sourceHomeomorphBaseSetProd_apply (p : e.source) :
e.sourceHomeomorphBaseSetProd p = (⟨proj p, e.mem_source.mp p.2⟩, (e p).2) :=
e.preimageHomeomorph_apply subset_rfl ⟨p, e.mem_source.mp p.2⟩
/-- Auxiliary definition to avoid looping in `dsimp`
with `Trivialization.sourceHomeomorphBaseSetProd_symm_apply`. -/
protected def sourceHomeomorphBaseSetProd_symm_apply.aux := e.sourceHomeomorphBaseSetProd.symm
@[simp]
theorem sourceHomeomorphBaseSetProd_symm_apply (p : e.baseSet × F) :
e.sourceHomeomorphBaseSetProd.symm p =
⟨e.symm (p.1, p.2), (sourceHomeomorphBaseSetProd_symm_apply.aux e p).2⟩ :=
rfl
/-- Each fiber of a trivialization is homeomorphic to the specified fiber. -/
def preimageSingletonHomeomorph {b : B} (hb : b ∈ e.baseSet) : proj ⁻¹' {b} ≃ₜ F :=
.trans (e.preimageHomeomorph (Set.singleton_subset_iff.mpr hb)) <|
.trans (.prodCongr (Homeomorph.homeomorphOfUnique ({b} : Set B) PUnit.{1}) (Homeomorph.refl F))
(Homeomorph.punitProd F)
@[simp]
theorem preimageSingletonHomeomorph_apply {b : B} (hb : b ∈ e.baseSet) (p : proj ⁻¹' {b}) :
e.preimageSingletonHomeomorph hb p = (e p).2 :=
rfl
@[simp]
theorem preimageSingletonHomeomorph_symm_apply {b : B} (hb : b ∈ e.baseSet) (p : F) :
(e.preimageSingletonHomeomorph hb).symm p =
⟨e.symm (b, p), by rw [mem_preimage, e.proj_symm_apply' hb, mem_singleton_iff]⟩ :=
rfl
/-- In the domain of a bundle trivialization, the projection is continuous -/
theorem continuousAt_proj (ex : x ∈ e.source) : ContinuousAt proj x :=
(e.map_proj_nhds ex).le
/-- Composition of a `Trivialization` and a `Homeomorph`. -/
protected def compHomeomorph {Z' : Type*} [TopologicalSpace Z'] (h : Z' ≃ₜ Z) :
Trivialization F (proj ∘ h) where
toPartialHomeomorph := h.toPartialHomeomorph.trans e.toPartialHomeomorph
baseSet := e.baseSet
open_baseSet := e.open_baseSet
source_eq := by simp [source_eq, preimage_preimage, Function.comp_def]
target_eq := by simp [target_eq]
proj_toFun p hp := by
have hp : h p ∈ e.source := by simpa using hp
simp [hp]
/-- Read off the continuity of a function `f : Z → X` at `z : Z` by transferring via a
trivialization of `Z` containing `z`. -/
theorem continuousAt_of_comp_right {X : Type*} [TopologicalSpace X] {f : Z → X} {z : Z}
(e : Trivialization F proj) (he : proj z ∈ e.baseSet)
(hf : ContinuousAt (f ∘ e.toPartialEquiv.symm) (e z)) : ContinuousAt f z := by
have hez : z ∈ e.toPartialEquiv.symm.target := by
rw [PartialEquiv.symm_target, e.mem_source]
exact he
rwa [e.toPartialHomeomorph.symm.continuousAt_iff_continuousAt_comp_right hez,
PartialHomeomorph.symm_symm]
/-- Read off the continuity of a function `f : X → Z` at `x : X` by transferring via a
trivialization of `Z` containing `f x`. -/
theorem continuousAt_of_comp_left {X : Type*} [TopologicalSpace X] {f : X → Z} {x : X}
(e : Trivialization F proj) (hf_proj : ContinuousAt (proj ∘ f) x) (he : proj (f x) ∈ e.baseSet)
(hf : ContinuousAt (e ∘ f) x) : ContinuousAt f x := by
rw [e.continuousAt_iff_continuousAt_comp_left]
· exact hf
rw [e.source_eq, ← preimage_comp]
exact hf_proj.preimage_mem_nhds (e.open_baseSet.mem_nhds he)
variable (e' : Trivialization F (π F E)) {b : B} {y : E b}
protected theorem continuousOn : ContinuousOn e' e'.source :=
e'.continuousOn_toFun
theorem coe_mem_source : ↑y ∈ e'.source ↔ b ∈ e'.baseSet :=
e'.mem_source
@[simp, mfld_simps]
theorem coe_coe_fst (hb : b ∈ e'.baseSet) : (e' y).1 = b :=
e'.coe_fst (e'.mem_source.2 hb)
theorem mk_mem_target {y : F} : (b, y) ∈ e'.target ↔ b ∈ e'.baseSet :=
e'.toPretrivialization.mem_target
theorem symm_apply_apply {x : TotalSpace F E} (hx : x ∈ e'.source) :
e'.toPartialHomeomorph.symm (e' x) = x :=
e'.toPartialEquiv.left_inv hx
@[simp, mfld_simps]
theorem symm_coe_proj {x : B} {y : F} (e : Trivialization F (π F E)) (h : x ∈ e.baseSet) :
(e.toPartialHomeomorph.symm (x, y)).1 = x :=
e.proj_symm_apply' h
section Zero
variable [∀ x, Zero (E x)]
/-- A fiberwise inverse to `e'`. The function `F → E x` that induces a local inverse
`B × F → TotalSpace F E` of `e'` on `e'.baseSet`. It is defined to be `0` outside `e'.baseSet`. -/
protected noncomputable def symm (e : Trivialization F (π F E)) (b : B) (y : F) : E b :=
e.toPretrivialization.symm b y
theorem symm_apply (e : Trivialization F (π F E)) {b : B} (hb : b ∈ e.baseSet) (y : F) :
e.symm b y = cast (congr_arg E (e.symm_coe_proj hb)) (e.toPartialHomeomorph.symm (b, y)).2 :=
dif_pos hb
theorem symm_apply_of_not_mem (e : Trivialization F (π F E)) {b : B} (hb : b ∉ e.baseSet) (y : F) :
e.symm b y = 0 :=
dif_neg hb
theorem mk_symm (e : Trivialization F (π F E)) {b : B} (hb : b ∈ e.baseSet) (y : F) :
TotalSpace.mk b (e.symm b y) = e.toPartialHomeomorph.symm (b, y) :=
e.toPretrivialization.mk_symm hb y
theorem symm_proj_apply (e : Trivialization F (π F E)) (z : TotalSpace F E)
(hz : z.proj ∈ e.baseSet) : e.symm z.proj (e z).2 = z.2 :=
e.toPretrivialization.symm_proj_apply z hz
theorem symm_apply_apply_mk (e : Trivialization F (π F E)) {b : B} (hb : b ∈ e.baseSet) (y : E b) :
e.symm b (e ⟨b, y⟩).2 = y :=
e.symm_proj_apply ⟨b, y⟩ hb
theorem apply_mk_symm (e : Trivialization F (π F E)) {b : B} (hb : b ∈ e.baseSet) (y : F) :
e ⟨b, e.symm b y⟩ = (b, y) :=
e.toPretrivialization.apply_mk_symm hb y
theorem continuousOn_symm (e : Trivialization F (π F E)) :
ContinuousOn (fun z : B × F => TotalSpace.mk' F z.1 (e.symm z.1 z.2)) (e.baseSet ×ˢ univ) := by
| have : ∀ z ∈ e.baseSet ×ˢ (univ : Set F),
TotalSpace.mk z.1 (e.symm z.1 z.2) = e.toPartialHomeomorph.symm z := by
rintro x ⟨hx : x.1 ∈ e.baseSet, _⟩
rw [e.mk_symm hx]
refine ContinuousOn.congr ?_ this
rw [← e.target_eq]
exact e.toPartialHomeomorph.continuousOn_symm
| Mathlib/Topology/FiberBundle/Trivialization.lean | 564 | 571 |
/-
Copyright (c) 2017 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
-/
import Mathlib.Data.Ordmap.Invariants
/-!
# Verification of `Ordnode`
This file uses the invariants defined in `Mathlib.Data.Ordmap.Invariants` to construct `Ordset α`,
a wrapper around `Ordnode α` which includes the correctness invariant of the type. It exposes
parallel operations like `insert` as functions on `Ordset` that do the same thing but bundle the
correctness proofs.
The advantage is that it is possible to, for example, prove that the result of `find` on `insert`
will actually find the element, while `Ordnode` cannot guarantee this if the input tree did not
satisfy the type invariants.
## Main definitions
* `Ordnode.Valid`: The validity predicate for an `Ordnode` subtree.
* `Ordset α`: A well formed set of values of type `α`.
## Implementation notes
Because the `Ordnode` file was ported from Haskell, the correctness invariants of some
of the functions have not been spelled out, and some theorems like
`Ordnode.Valid'.balanceL_aux` show very intricate assumptions on the sizes,
which may need to be revised if it turns out some operations violate these assumptions,
because there is a decent amount of slop in the actual data structure invariants, so the
theorem will go through with multiple choices of assumption.
-/
variable {α : Type*}
namespace Ordnode
section Valid
variable [Preorder α]
/-- The validity predicate for an `Ordnode` subtree. This asserts that the `size` fields are
correct, the tree is balanced, and the elements of the tree are organized according to the
ordering. This version of `Valid` also puts all elements in the tree in the interval `(lo, hi)`. -/
structure Valid' (lo : WithBot α) (t : Ordnode α) (hi : WithTop α) : Prop where
ord : t.Bounded lo hi
sz : t.Sized
bal : t.Balanced
/-- The validity predicate for an `Ordnode` subtree. This asserts that the `size` fields are
correct, the tree is balanced, and the elements of the tree are organized according to the
ordering. -/
def Valid (t : Ordnode α) : Prop :=
Valid' ⊥ t ⊤
theorem Valid'.mono_left {x y : α} (xy : x ≤ y) {t : Ordnode α} {o} (h : Valid' y t o) :
Valid' x t o :=
⟨h.1.mono_left xy, h.2, h.3⟩
theorem Valid'.mono_right {x y : α} (xy : x ≤ y) {t : Ordnode α} {o} (h : Valid' o t x) :
Valid' o t y :=
⟨h.1.mono_right xy, h.2, h.3⟩
theorem Valid'.trans_left {t₁ t₂ : Ordnode α} {x : α} {o₁ o₂} (h : Bounded t₁ o₁ x)
(H : Valid' x t₂ o₂) : Valid' o₁ t₂ o₂ :=
⟨h.trans_left H.1, H.2, H.3⟩
theorem Valid'.trans_right {t₁ t₂ : Ordnode α} {x : α} {o₁ o₂} (H : Valid' o₁ t₁ x)
(h : Bounded t₂ x o₂) : Valid' o₁ t₁ o₂ :=
⟨H.1.trans_right h, H.2, H.3⟩
theorem Valid'.of_lt {t : Ordnode α} {x : α} {o₁ o₂} (H : Valid' o₁ t o₂) (h₁ : Bounded nil o₁ x)
(h₂ : All (· < x) t) : Valid' o₁ t x :=
⟨H.1.of_lt h₁ h₂, H.2, H.3⟩
theorem Valid'.of_gt {t : Ordnode α} {x : α} {o₁ o₂} (H : Valid' o₁ t o₂) (h₁ : Bounded nil x o₂)
(h₂ : All (· > x) t) : Valid' x t o₂ :=
⟨H.1.of_gt h₁ h₂, H.2, H.3⟩
theorem Valid'.valid {t o₁ o₂} (h : @Valid' α _ o₁ t o₂) : Valid t :=
⟨h.1.weak, h.2, h.3⟩
theorem valid'_nil {o₁ o₂} (h : Bounded nil o₁ o₂) : Valid' o₁ (@nil α) o₂ :=
⟨h, ⟨⟩, ⟨⟩⟩
theorem valid_nil : Valid (@nil α) :=
valid'_nil ⟨⟩
theorem Valid'.node {s l} {x : α} {r o₁ o₂} (hl : Valid' o₁ l x) (hr : Valid' x r o₂)
(H : BalancedSz (size l) (size r)) (hs : s = size l + size r + 1) :
Valid' o₁ (@node α s l x r) o₂ :=
⟨⟨hl.1, hr.1⟩, ⟨hs, hl.2, hr.2⟩, ⟨H, hl.3, hr.3⟩⟩
theorem Valid'.dual : ∀ {t : Ordnode α} {o₁ o₂}, Valid' o₁ t o₂ → @Valid' αᵒᵈ _ o₂ (dual t) o₁
| .nil, _, _, h => valid'_nil h.1.dual
| .node _ l _ r, _, _, ⟨⟨ol, Or⟩, ⟨rfl, sl, sr⟩, ⟨b, bl, br⟩⟩ =>
let ⟨ol', sl', bl'⟩ := Valid'.dual ⟨ol, sl, bl⟩
let ⟨or', sr', br'⟩ := Valid'.dual ⟨Or, sr, br⟩
⟨⟨or', ol'⟩, ⟨by simp [size_dual, add_comm], sr', sl'⟩,
⟨by rw [size_dual, size_dual]; exact b.symm, br', bl'⟩⟩
theorem Valid'.dual_iff {t : Ordnode α} {o₁ o₂} : Valid' o₁ t o₂ ↔ @Valid' αᵒᵈ _ o₂ (.dual t) o₁ :=
⟨Valid'.dual, fun h => by
have := Valid'.dual h; rwa [dual_dual, OrderDual.Preorder.dual_dual] at this⟩
theorem Valid.dual {t : Ordnode α} : Valid t → @Valid αᵒᵈ _ (.dual t) :=
Valid'.dual
theorem Valid.dual_iff {t : Ordnode α} : Valid t ↔ @Valid αᵒᵈ _ (.dual t) :=
Valid'.dual_iff
theorem Valid'.left {s l x r o₁ o₂} (H : Valid' o₁ (@Ordnode.node α s l x r) o₂) : Valid' o₁ l x :=
⟨H.1.1, H.2.2.1, H.3.2.1⟩
theorem Valid'.right {s l x r o₁ o₂} (H : Valid' o₁ (@Ordnode.node α s l x r) o₂) : Valid' x r o₂ :=
⟨H.1.2, H.2.2.2, H.3.2.2⟩
nonrec theorem Valid.left {s l x r} (H : Valid (@node α s l x r)) : Valid l :=
H.left.valid
nonrec theorem Valid.right {s l x r} (H : Valid (@node α s l x r)) : Valid r :=
H.right.valid
theorem Valid.size_eq {s l x r} (H : Valid (@node α s l x r)) :
size (@node α s l x r) = size l + size r + 1 :=
H.2.1
theorem Valid'.node' {l} {x : α} {r o₁ o₂} (hl : Valid' o₁ l x) (hr : Valid' x r o₂)
(H : BalancedSz (size l) (size r)) : Valid' o₁ (@node' α l x r) o₂ :=
hl.node hr H rfl
theorem valid'_singleton {x : α} {o₁ o₂} (h₁ : Bounded nil o₁ x) (h₂ : Bounded nil x o₂) :
Valid' o₁ (singleton x : Ordnode α) o₂ :=
(valid'_nil h₁).node (valid'_nil h₂) (Or.inl zero_le_one) rfl
theorem valid_singleton {x : α} : Valid (singleton x : Ordnode α) :=
valid'_singleton ⟨⟩ ⟨⟩
theorem Valid'.node3L {l} {x : α} {m} {y : α} {r o₁ o₂} (hl : Valid' o₁ l x) (hm : Valid' x m y)
(hr : Valid' y r o₂) (H1 : BalancedSz (size l) (size m))
(H2 : BalancedSz (size l + size m + 1) (size r)) : Valid' o₁ (@node3L α l x m y r) o₂ :=
(hl.node' hm H1).node' hr H2
theorem Valid'.node3R {l} {x : α} {m} {y : α} {r o₁ o₂} (hl : Valid' o₁ l x) (hm : Valid' x m y)
(hr : Valid' y r o₂) (H1 : BalancedSz (size l) (size m + size r + 1))
(H2 : BalancedSz (size m) (size r)) : Valid' o₁ (@node3R α l x m y r) o₂ :=
hl.node' (hm.node' hr H2) H1
theorem Valid'.node4L_lemma₁ {a b c d : ℕ} (lr₂ : 3 * (b + c + 1 + d) ≤ 16 * a + 9)
(mr₂ : b + c + 1 ≤ 3 * d) (mm₁ : b ≤ 3 * c) : b < 3 * a + 1 := by omega
theorem Valid'.node4L_lemma₂ {b c d : ℕ} (mr₂ : b + c + 1 ≤ 3 * d) : c ≤ 3 * d := by omega
theorem Valid'.node4L_lemma₃ {b c d : ℕ} (mr₁ : 2 * d ≤ b + c + 1) (mm₁ : b ≤ 3 * c) :
d ≤ 3 * c := by omega
theorem Valid'.node4L_lemma₄ {a b c d : ℕ} (lr₁ : 3 * a ≤ b + c + 1 + d) (mr₂ : b + c + 1 ≤ 3 * d)
(mm₁ : b ≤ 3 * c) : a + b + 1 ≤ 3 * (c + d + 1) := by omega
theorem Valid'.node4L_lemma₅ {a b c d : ℕ} (lr₂ : 3 * (b + c + 1 + d) ≤ 16 * a + 9)
(mr₁ : 2 * d ≤ b + c + 1) (mm₂ : c ≤ 3 * b) : c + d + 1 ≤ 3 * (a + b + 1) := by omega
theorem Valid'.node4L {l} {x : α} {m} {y : α} {r o₁ o₂} (hl : Valid' o₁ l x) (hm : Valid' x m y)
(hr : Valid' (↑y) r o₂) (Hm : 0 < size m)
(H : size l = 0 ∧ size m = 1 ∧ size r ≤ 1 ∨
0 < size l ∧
ratio * size r ≤ size m ∧
delta * size l ≤ size m + size r ∧
3 * (size m + size r) ≤ 16 * size l + 9 ∧ size m ≤ delta * size r) :
Valid' o₁ (@node4L α l x m y r) o₂ := by
obtain - | ⟨s, ml, z, mr⟩ := m; · cases Hm
suffices
BalancedSz (size l) (size ml) ∧
BalancedSz (size mr) (size r) ∧ BalancedSz (size l + size ml + 1) (size mr + size r + 1) from
Valid'.node' (hl.node' hm.left this.1) (hm.right.node' hr this.2.1) this.2.2
rcases H with (⟨l0, m1, r0⟩ | ⟨l0, mr₁, lr₁, lr₂, mr₂⟩)
· rw [hm.2.size_eq, Nat.succ_inj, add_eq_zero] at m1
rw [l0, m1.1, m1.2]; revert r0; rcases size r with (_ | _ | _) <;>
[decide; decide; (intro r0; unfold BalancedSz delta; omega)]
· rcases Nat.eq_zero_or_pos (size r) with r0 | r0
· rw [r0] at mr₂; cases not_le_of_lt Hm mr₂
rw [hm.2.size_eq] at lr₁ lr₂ mr₁ mr₂
by_cases mm : size ml + size mr ≤ 1
· have r1 :=
le_antisymm
((mul_le_mul_left (by decide)).1 (le_trans mr₁ (Nat.succ_le_succ mm) : _ ≤ ratio * 1)) r0
rw [r1, add_assoc] at lr₁
have l1 :=
le_antisymm
((mul_le_mul_left (by decide)).1 (le_trans lr₁ (add_le_add_right mm 2) : _ ≤ delta * 1))
l0
rw [l1, r1]
revert mm; cases size ml <;> cases size mr <;> intro mm
· decide
· rw [zero_add] at mm; rcases mm with (_ | ⟨⟨⟩⟩)
decide
· rcases mm with (_ | ⟨⟨⟩⟩); decide
· rw [Nat.succ_add] at mm; rcases mm with (_ | ⟨⟨⟩⟩)
rcases hm.3.1.resolve_left mm with ⟨mm₁, mm₂⟩
rcases Nat.eq_zero_or_pos (size ml) with ml0 | ml0
· rw [ml0, mul_zero, Nat.le_zero] at mm₂
rw [ml0, mm₂] at mm; cases mm (by decide)
have : 2 * size l ≤ size ml + size mr + 1 := by
have := Nat.mul_le_mul_left ratio lr₁
rw [mul_left_comm, mul_add] at this
have := le_trans this (add_le_add_left mr₁ _)
rw [← Nat.succ_mul] at this
exact (mul_le_mul_left (by decide)).1 this
refine ⟨Or.inr ⟨?_, ?_⟩, Or.inr ⟨?_, ?_⟩, Or.inr ⟨?_, ?_⟩⟩
· refine (mul_le_mul_left (by decide)).1 (le_trans this ?_)
rw [two_mul, Nat.succ_le_iff]
refine add_lt_add_of_lt_of_le ?_ mm₂
simpa using (mul_lt_mul_right ml0).2 (by decide : 1 < 3)
· exact Nat.le_of_lt_succ (Valid'.node4L_lemma₁ lr₂ mr₂ mm₁)
· exact Valid'.node4L_lemma₂ mr₂
· exact Valid'.node4L_lemma₃ mr₁ mm₁
· exact Valid'.node4L_lemma₄ lr₁ mr₂ mm₁
· exact Valid'.node4L_lemma₅ lr₂ mr₁ mm₂
theorem Valid'.rotateL_lemma₁ {a b c : ℕ} (H2 : 3 * a ≤ b + c) (hb₂ : c ≤ 3 * b) : a ≤ 3 * b := by
omega
theorem Valid'.rotateL_lemma₂ {a b c : ℕ} (H3 : 2 * (b + c) ≤ 9 * a + 3) (h : b < 2 * c) :
b < 3 * a + 1 := by omega
theorem Valid'.rotateL_lemma₃ {a b c : ℕ} (H2 : 3 * a ≤ b + c) (h : b < 2 * c) : a + b < 3 * c := by
omega
theorem Valid'.rotateL_lemma₄ {a b : ℕ} (H3 : 2 * b ≤ 9 * a + 3) : 3 * b ≤ 16 * a + 9 := by
omega
theorem Valid'.rotateL {l} {x : α} {r o₁ o₂} (hl : Valid' o₁ l x) (hr : Valid' x r o₂)
(H1 : ¬size l + size r ≤ 1) (H2 : delta * size l < size r)
(H3 : 2 * size r ≤ 9 * size l + 5 ∨ size r ≤ 3) : Valid' o₁ (@rotateL α l x r) o₂ := by
obtain - | ⟨rs, rl, rx, rr⟩ := r; · cases H2
rw [hr.2.size_eq, Nat.lt_succ_iff] at H2
rw [hr.2.size_eq] at H3
replace H3 : 2 * (size rl + size rr) ≤ 9 * size l + 3 ∨ size rl + size rr ≤ 2 :=
H3.imp (@Nat.le_of_add_le_add_right _ 2 _) Nat.le_of_succ_le_succ
have H3_0 : size l = 0 → size rl + size rr ≤ 2 := by
intro l0; rw [l0] at H3
exact
(or_iff_right_of_imp fun h => (mul_le_mul_left (by decide)).1 (le_trans h (by decide))).1 H3
have H3p : size l > 0 → 2 * (size rl + size rr) ≤ 9 * size l + 3 := fun l0 : 1 ≤ size l =>
(or_iff_left_of_imp <| by omega).1 H3
have ablem : ∀ {a b : ℕ}, 1 ≤ a → a + b ≤ 2 → b ≤ 1 := by omega
have hlp : size l > 0 → ¬size rl + size rr ≤ 1 := fun l0 hb =>
absurd (le_trans (le_trans (Nat.mul_le_mul_left _ l0) H2) hb) (by decide)
rw [Ordnode.rotateL_node]; split_ifs with h
· have rr0 : size rr > 0 :=
(mul_lt_mul_left (by decide)).1 (lt_of_le_of_lt (Nat.zero_le _) h : ratio * 0 < _)
suffices BalancedSz (size l) (size rl) ∧ BalancedSz (size l + size rl + 1) (size rr) by
exact hl.node3L hr.left hr.right this.1 this.2
rcases Nat.eq_zero_or_pos (size l) with l0 | l0
· rw [l0]; replace H3 := H3_0 l0
have := hr.3.1
rcases Nat.eq_zero_or_pos (size rl) with rl0 | rl0
· rw [rl0] at this ⊢
rw [le_antisymm (balancedSz_zero.1 this.symm) rr0]
decide
have rr1 : size rr = 1 := le_antisymm (ablem rl0 H3) rr0
rw [add_comm] at H3
rw [rr1, show size rl = 1 from le_antisymm (ablem rr0 H3) rl0]
decide
replace H3 := H3p l0
rcases hr.3.1.resolve_left (hlp l0) with ⟨_, hb₂⟩
refine ⟨Or.inr ⟨?_, ?_⟩, Or.inr ⟨?_, ?_⟩⟩
· exact Valid'.rotateL_lemma₁ H2 hb₂
· exact Nat.le_of_lt_succ (Valid'.rotateL_lemma₂ H3 h)
· exact Valid'.rotateL_lemma₃ H2 h
· exact
le_trans hb₂
(Nat.mul_le_mul_left _ <| le_trans (Nat.le_add_left _ _) (Nat.le_add_right _ _))
· rcases Nat.eq_zero_or_pos (size rl) with rl0 | rl0
· rw [rl0, not_lt, Nat.le_zero, Nat.mul_eq_zero] at h
replace h := h.resolve_left (by decide)
rw [rl0, h, Nat.le_zero, Nat.mul_eq_zero] at H2
rw [hr.2.size_eq, rl0, h, H2.resolve_left (by decide)] at H1
cases H1 (by decide)
refine hl.node4L hr.left hr.right rl0 ?_
rcases Nat.eq_zero_or_pos (size l) with l0 | l0
· replace H3 := H3_0 l0
rcases Nat.eq_zero_or_pos (size rr) with rr0 | rr0
· have := hr.3.1
rw [rr0] at this
exact Or.inl ⟨l0, le_antisymm (balancedSz_zero.1 this) rl0, rr0.symm ▸ zero_le_one⟩
exact Or.inl ⟨l0, le_antisymm (ablem rr0 <| by rwa [add_comm]) rl0, ablem rl0 H3⟩
exact
Or.inr ⟨l0, not_lt.1 h, H2, Valid'.rotateL_lemma₄ (H3p l0), (hr.3.1.resolve_left (hlp l0)).1⟩
theorem Valid'.rotateR {l} {x : α} {r o₁ o₂} (hl : Valid' o₁ l x) (hr : Valid' x r o₂)
(H1 : ¬size l + size r ≤ 1) (H2 : delta * size r < size l)
(H3 : 2 * size l ≤ 9 * size r + 5 ∨ size l ≤ 3) : Valid' o₁ (@rotateR α l x r) o₂ := by
refine Valid'.dual_iff.2 ?_
rw [dual_rotateR]
refine hr.dual.rotateL hl.dual ?_ ?_ ?_
· rwa [size_dual, size_dual, add_comm]
· rwa [size_dual, size_dual]
· rwa [size_dual, size_dual]
theorem Valid'.balance'_aux {l} {x : α} {r o₁ o₂} (hl : Valid' o₁ l x) (hr : Valid' x r o₂)
(H₁ : 2 * @size α r ≤ 9 * size l + 5 ∨ size r ≤ 3)
(H₂ : 2 * @size α l ≤ 9 * size r + 5 ∨ size l ≤ 3) : Valid' o₁ (@balance' α l x r) o₂ := by
rw [balance']; split_ifs with h h_1 h_2
· exact hl.node' hr (Or.inl h)
· exact hl.rotateL hr h h_1 H₁
· exact hl.rotateR hr h h_2 H₂
· exact hl.node' hr (Or.inr ⟨not_lt.1 h_2, not_lt.1 h_1⟩)
theorem Valid'.balance'_lemma {α l l' r r'} (H1 : BalancedSz l' r')
(H2 : Nat.dist (@size α l) l' ≤ 1 ∧ size r = r' ∨ Nat.dist (size r) r' ≤ 1 ∧ size l = l') :
2 * @size α r ≤ 9 * size l + 5 ∨ size r ≤ 3 := by
suffices @size α r ≤ 3 * (size l + 1) by omega
rcases H2 with (⟨hl, rfl⟩ | ⟨hr, rfl⟩) <;> rcases H1 with (h | ⟨_, h₂⟩)
· exact le_trans (Nat.le_add_left _ _) (le_trans h (Nat.le_add_left _ _))
· exact
le_trans h₂
(Nat.mul_le_mul_left _ <| le_trans (Nat.dist_tri_right _ _) (Nat.add_le_add_left hl _))
· exact
le_trans (Nat.dist_tri_left' _ _)
(le_trans (add_le_add hr (le_trans (Nat.le_add_left _ _) h)) (by omega))
· rw [Nat.mul_succ]
exact le_trans (Nat.dist_tri_right' _ _) (add_le_add h₂ (le_trans hr (by decide)))
theorem Valid'.balance' {l} {x : α} {r o₁ o₂} (hl : Valid' o₁ l x) (hr : Valid' x r o₂)
(H : ∃ l' r', BalancedSz l' r' ∧
(Nat.dist (size l) l' ≤ 1 ∧ size r = r' ∨ Nat.dist (size r) r' ≤ 1 ∧ size l = l')) :
Valid' o₁ (@balance' α l x r) o₂ :=
let ⟨_, _, H1, H2⟩ := H
Valid'.balance'_aux hl hr (Valid'.balance'_lemma H1 H2) (Valid'.balance'_lemma H1.symm H2.symm)
theorem Valid'.balance {l} {x : α} {r o₁ o₂} (hl : Valid' o₁ l x) (hr : Valid' x r o₂)
(H : ∃ l' r', BalancedSz l' r' ∧
(Nat.dist (size l) l' ≤ 1 ∧ size r = r' ∨ Nat.dist (size r) r' ≤ 1 ∧ size l = l')) :
Valid' o₁ (@balance α l x r) o₂ := by
rw [balance_eq_balance' hl.3 hr.3 hl.2 hr.2]; exact hl.balance' hr H
theorem Valid'.balanceL_aux {l} {x : α} {r o₁ o₂} (hl : Valid' o₁ l x) (hr : Valid' x r o₂)
(H₁ : size l = 0 → size r ≤ 1) (H₂ : 1 ≤ size l → 1 ≤ size r → size r ≤ delta * size l)
(H₃ : 2 * @size α l ≤ 9 * size r + 5 ∨ size l ≤ 3) : Valid' o₁ (@balanceL α l x r) o₂ := by
rw [balanceL_eq_balance hl.2 hr.2 H₁ H₂, balance_eq_balance' hl.3 hr.3 hl.2 hr.2]
refine hl.balance'_aux hr (Or.inl ?_) H₃
rcases Nat.eq_zero_or_pos (size r) with r0 | r0
· rw [r0]; exact Nat.zero_le _
rcases Nat.eq_zero_or_pos (size l) with l0 | l0
· rw [l0]; exact le_trans (Nat.mul_le_mul_left _ (H₁ l0)) (by decide)
replace H₂ : _ ≤ 3 * _ := H₂ l0 r0; omega
theorem Valid'.balanceL {l} {x : α} {r o₁ o₂} (hl : Valid' o₁ l x) (hr : Valid' x r o₂)
(H : (∃ l', Raised l' (size l) ∧ BalancedSz l' (size r)) ∨
∃ r', Raised (size r) r' ∧ BalancedSz (size l) r') :
Valid' o₁ (@balanceL α l x r) o₂ := by
rw [balanceL_eq_balance' hl.3 hr.3 hl.2 hr.2 H]
refine hl.balance' hr ?_
rcases H with (⟨l', e, H⟩ | ⟨r', e, H⟩)
· exact ⟨_, _, H, Or.inl ⟨e.dist_le', rfl⟩⟩
· exact ⟨_, _, H, Or.inr ⟨e.dist_le, rfl⟩⟩
theorem Valid'.balanceR_aux {l} {x : α} {r o₁ o₂} (hl : Valid' o₁ l x) (hr : Valid' x r o₂)
(H₁ : size r = 0 → size l ≤ 1) (H₂ : 1 ≤ size r → 1 ≤ size l → size l ≤ delta * size r)
(H₃ : 2 * @size α r ≤ 9 * size l + 5 ∨ size r ≤ 3) : Valid' o₁ (@balanceR α l x r) o₂ := by
rw [Valid'.dual_iff, dual_balanceR]
have := hr.dual.balanceL_aux hl.dual
rw [size_dual, size_dual] at this
exact this H₁ H₂ H₃
theorem Valid'.balanceR {l} {x : α} {r o₁ o₂} (hl : Valid' o₁ l x) (hr : Valid' x r o₂)
(H : (∃ l', Raised (size l) l' ∧ BalancedSz l' (size r)) ∨
∃ r', Raised r' (size r) ∧ BalancedSz (size l) r') :
Valid' o₁ (@balanceR α l x r) o₂ := by
rw [Valid'.dual_iff, dual_balanceR]; exact hr.dual.balanceL hl.dual (balance_sz_dual H)
theorem Valid'.eraseMax_aux {s l x r o₁ o₂} (H : Valid' o₁ (.node s l x r) o₂) :
Valid' o₁ (@eraseMax α (.node' l x r)) ↑(findMax' x r) ∧
size (.node' l x r) = size (eraseMax (.node' l x r)) + 1 := by
have := H.2.eq_node'; rw [this] at H; clear this
induction r generalizing l x o₁ with
| nil => exact ⟨H.left, rfl⟩
| node rs rl rx rr _ IHrr =>
have := H.2.2.2.eq_node'; rw [this] at H ⊢
rcases IHrr H.right with ⟨h, e⟩
refine ⟨Valid'.balanceL H.left h (Or.inr ⟨_, Or.inr e, H.3.1⟩), ?_⟩
rw [eraseMax, size_balanceL H.3.2.1 h.3 H.2.2.1 h.2 (Or.inr ⟨_, Or.inr e, H.3.1⟩)]
rw [size_node, e]; rfl
theorem Valid'.eraseMin_aux {s l} {x : α} {r o₁ o₂} (H : Valid' o₁ (.node s l x r) o₂) :
Valid' ↑(findMin' l x) (@eraseMin α (.node' l x r)) o₂ ∧
size (.node' l x r) = size (eraseMin (.node' l x r)) + 1 := by
have := H.dual.eraseMax_aux
rwa [← dual_node', size_dual, ← dual_eraseMin, size_dual, ← Valid'.dual_iff, findMax'_dual]
at this
theorem eraseMin.valid : ∀ {t}, @Valid α _ t → Valid (eraseMin t)
| nil, _ => valid_nil
| node _ l x r, h => by rw [h.2.eq_node']; exact h.eraseMin_aux.1.valid
theorem eraseMax.valid {t} (h : @Valid α _ t) : Valid (eraseMax t) := by
rw [Valid.dual_iff, dual_eraseMax]; exact eraseMin.valid h.dual
theorem Valid'.glue_aux {l r o₁ o₂} (hl : Valid' o₁ l o₂) (hr : Valid' o₁ r o₂)
(sep : l.All fun x => r.All fun y => x < y) (bal : BalancedSz (size l) (size r)) :
Valid' o₁ (@glue α l r) o₂ ∧ size (glue l r) = size l + size r := by
obtain - | ⟨ls, ll, lx, lr⟩ := l; · exact ⟨hr, (zero_add _).symm⟩
obtain - | ⟨rs, rl, rx, rr⟩ := r; · exact ⟨hl, rfl⟩
dsimp [glue]; split_ifs
· rw [splitMax_eq]
· obtain ⟨v, e⟩ := Valid'.eraseMax_aux hl
suffices H : _ by
refine ⟨Valid'.balanceR v (hr.of_gt ?_ ?_) H, ?_⟩
· refine findMax'_all (P := fun a : α => Bounded nil (a : WithTop α) o₂)
lx lr hl.1.2.to_nil (sep.2.2.imp ?_)
exact fun x h => hr.1.2.to_nil.mono_left (le_of_lt h.2.1)
· exact @findMax'_all _ (fun a => All (· > a) (.node rs rl rx rr)) lx lr sep.2.1 sep.2.2
· rw [size_balanceR v.3 hr.3 v.2 hr.2 H, add_right_comm, ← e, hl.2.1]; rfl
refine Or.inl ⟨_, Or.inr e, ?_⟩
rwa [hl.2.eq_node'] at bal
· rw [splitMin_eq]
· obtain ⟨v, e⟩ := Valid'.eraseMin_aux hr
suffices H : _ by
refine ⟨Valid'.balanceL (hl.of_lt ?_ ?_) v H, ?_⟩
· refine @findMin'_all (P := fun a : α => Bounded nil o₁ (a : WithBot α))
_ rl rx (sep.2.1.1.imp ?_) hr.1.1.to_nil
exact fun y h => hl.1.1.to_nil.mono_right (le_of_lt h)
· exact
@findMin'_all _ (fun a => All (· < a) (.node ls ll lx lr)) rl rx
(all_iff_forall.2 fun x hx => sep.imp fun y hy => all_iff_forall.1 hy.1 _ hx)
(sep.imp fun y hy => hy.2.1)
· rw [size_balanceL hl.3 v.3 hl.2 v.2 H, add_assoc, ← e, hr.2.1]; rfl
refine Or.inr ⟨_, Or.inr e, ?_⟩
rwa [hr.2.eq_node'] at bal
theorem Valid'.glue {l} {x : α} {r o₁ o₂} (hl : Valid' o₁ l x) (hr : Valid' x r o₂) :
BalancedSz (size l) (size r) →
Valid' o₁ (@glue α l r) o₂ ∧ size (@glue α l r) = size l + size r :=
Valid'.glue_aux (hl.trans_right hr.1) (hr.trans_left hl.1) (hl.1.to_sep hr.1)
theorem Valid'.merge_lemma {a b c : ℕ} (h₁ : 3 * a < b + c + 1) (h₂ : b ≤ 3 * c) :
2 * (a + b) ≤ 9 * c + 5 := by omega
theorem Valid'.merge_aux₁ {o₁ o₂ ls ll lx lr rs rl rx rr t}
(hl : Valid' o₁ (@Ordnode.node α ls ll lx lr) o₂) (hr : Valid' o₁ (.node rs rl rx rr) o₂)
(h : delta * ls < rs) (v : Valid' o₁ t rx) (e : size t = ls + size rl) :
Valid' o₁ (.balanceL t rx rr) o₂ ∧ size (.balanceL t rx rr) = ls + rs := by
rw [hl.2.1] at e
rw [hl.2.1, hr.2.1, delta] at h
rcases hr.3.1 with (H | ⟨hr₁, hr₂⟩); · omega
suffices H₂ : _ by
suffices H₁ : _ by
refine ⟨Valid'.balanceL_aux v hr.right H₁ H₂ ?_, ?_⟩
· rw [e]; exact Or.inl (Valid'.merge_lemma h hr₁)
· rw [balanceL_eq_balance v.2 hr.2.2.2 H₁ H₂, balance_eq_balance' v.3 hr.3.2.2 v.2 hr.2.2.2,
size_balance' v.2 hr.2.2.2, e, hl.2.1, hr.2.1]
abel
· rw [e, add_right_comm]; rintro ⟨⟩
intro _ _; rw [e]; unfold delta at hr₂ ⊢; omega
theorem Valid'.merge_aux {l r o₁ o₂} (hl : Valid' o₁ l o₂) (hr : Valid' o₁ r o₂)
(sep : l.All fun x => r.All fun y => x < y) :
Valid' o₁ (@merge α l r) o₂ ∧ size (merge l r) = size l + size r := by
induction l generalizing o₁ o₂ r with
| nil => exact ⟨hr, (zero_add _).symm⟩
| node ls ll lx lr _ IHlr => ?_
induction r generalizing o₁ o₂ with
| nil => exact ⟨hl, rfl⟩
| node rs rl rx rr IHrl _ => ?_
rw [merge_node]; split_ifs with h h_1
· obtain ⟨v, e⟩ := IHrl (hl.of_lt hr.1.1.to_nil <| sep.imp fun x h => h.2.1) hr.left
(sep.imp fun x h => h.1)
exact Valid'.merge_aux₁ hl hr h v e
· obtain ⟨v, e⟩ := IHlr hl.right (hr.of_gt hl.1.2.to_nil sep.2.1) sep.2.2
have := Valid'.merge_aux₁ hr.dual hl.dual h_1 v.dual
rw [size_dual, add_comm, size_dual, ← dual_balanceR, ← Valid'.dual_iff, size_dual,
add_comm rs] at this
exact this e
· refine Valid'.glue_aux hl hr sep (Or.inr ⟨not_lt.1 h_1, not_lt.1 h⟩)
theorem Valid.merge {l r} (hl : Valid l) (hr : Valid r)
(sep : l.All fun x => r.All fun y => x < y) : Valid (@merge α l r) :=
(Valid'.merge_aux hl hr sep).1
theorem insertWith.valid_aux [IsTotal α (· ≤ ·)] [DecidableLE α] (f : α → α) (x : α)
(hf : ∀ y, x ≤ y ∧ y ≤ x → x ≤ f y ∧ f y ≤ x) :
∀ {t o₁ o₂},
Valid' o₁ t o₂ →
Bounded nil o₁ x →
Bounded nil x o₂ →
Valid' o₁ (insertWith f x t) o₂ ∧ Raised (size t) (size (insertWith f x t))
| nil, _, _, _, bl, br => ⟨valid'_singleton bl br, Or.inr rfl⟩
| node sz l y r, o₁, o₂, h, bl, br => by
rw [insertWith, cmpLE]
split_ifs with h_1 h_2 <;> dsimp only
· rcases h with ⟨⟨lx, xr⟩, hs, hb⟩
rcases hf _ ⟨h_1, h_2⟩ with ⟨xf, fx⟩
refine
⟨⟨⟨lx.mono_right (le_trans h_2 xf), xr.mono_left (le_trans fx h_1)⟩, hs, hb⟩, Or.inl rfl⟩
· rcases insertWith.valid_aux f x hf h.left bl (lt_of_le_not_le h_1 h_2) with ⟨vl, e⟩
suffices H : _ by
refine ⟨vl.balanceL h.right H, ?_⟩
rw [size_balanceL vl.3 h.3.2.2 vl.2 h.2.2.2 H, h.2.size_eq]
exact (e.add_right _).add_right _
exact Or.inl ⟨_, e, h.3.1⟩
· have : y < x := lt_of_le_not_le ((total_of (· ≤ ·) _ _).resolve_left h_1) h_1
rcases insertWith.valid_aux f x hf h.right this br with ⟨vr, e⟩
suffices H : _ by
refine ⟨h.left.balanceR vr H, ?_⟩
rw [size_balanceR h.3.2.1 vr.3 h.2.2.1 vr.2 H, h.2.size_eq]
exact (e.add_left _).add_right _
exact Or.inr ⟨_, e, h.3.1⟩
theorem insertWith.valid [IsTotal α (· ≤ ·)] [DecidableLE α] (f : α → α) (x : α)
(hf : ∀ y, x ≤ y ∧ y ≤ x → x ≤ f y ∧ f y ≤ x) {t} (h : Valid t) : Valid (insertWith f x t) :=
(insertWith.valid_aux _ _ hf h ⟨⟩ ⟨⟩).1
theorem insert_eq_insertWith [DecidableLE α] (x : α) :
∀ t, Ordnode.insert x t = insertWith (fun _ => x) x t
| nil => rfl
| node _ l y r => by
unfold Ordnode.insert insertWith; cases cmpLE x y <;> simp [insert_eq_insertWith]
theorem insert.valid [IsTotal α (· ≤ ·)] [DecidableLE α] (x : α) {t} (h : Valid t) :
Valid (Ordnode.insert x t) := by
rw [insert_eq_insertWith]; exact insertWith.valid _ _ (fun _ _ => ⟨le_rfl, le_rfl⟩) h
theorem insert'_eq_insertWith [DecidableLE α] (x : α) :
∀ t, insert' x t = insertWith id x t
| nil => rfl
| node _ l y r => by
unfold insert' insertWith; cases cmpLE x y <;> simp [insert'_eq_insertWith]
theorem insert'.valid [IsTotal α (· ≤ ·)] [DecidableLE α]
(x : α) {t} (h : Valid t) : Valid (insert' x t) := by
rw [insert'_eq_insertWith]; exact insertWith.valid _ _ (fun _ => id) h
theorem Valid'.map_aux {β} [Preorder β] {f : α → β} (f_strict_mono : StrictMono f) {t a₁ a₂}
(h : Valid' a₁ t a₂) :
Valid' (Option.map f a₁) (map f t) (Option.map f a₂) ∧ (map f t).size = t.size := by
induction t generalizing a₁ a₂ with
| nil =>
simp only [map, size_nil, and_true]; apply valid'_nil
cases a₁; · trivial
cases a₂; · trivial
simp only [Option.map, Bounded]
exact f_strict_mono h.ord
| node _ _ _ _ t_ih_l t_ih_r =>
have t_ih_l' := t_ih_l h.left
have t_ih_r' := t_ih_r h.right
clear t_ih_l t_ih_r
obtain ⟨t_l_valid, t_l_size⟩ := t_ih_l'
obtain ⟨t_r_valid, t_r_size⟩ := t_ih_r'
simp only [map, size_node, and_true]
constructor
· exact And.intro t_l_valid.ord t_r_valid.ord
· constructor
· rw [t_l_size, t_r_size]; exact h.sz.1
· constructor
· exact t_l_valid.sz
· exact t_r_valid.sz
· constructor
· rw [t_l_size, t_r_size]; exact h.bal.1
· constructor
· exact t_l_valid.bal
· exact t_r_valid.bal
theorem map.valid {β} [Preorder β] {f : α → β} (f_strict_mono : StrictMono f) {t} (h : Valid t) :
Valid (map f t) :=
(Valid'.map_aux f_strict_mono h).1
theorem Valid'.erase_aux [DecidableLE α] (x : α) {t a₁ a₂} (h : Valid' a₁ t a₂) :
Valid' a₁ (erase x t) a₂ ∧ Raised (erase x t).size t.size := by
induction t generalizing a₁ a₂ with
| nil =>
simpa [erase, Raised]
| node _ t_l t_x t_r t_ih_l t_ih_r =>
simp only [erase, size_node]
have t_ih_l' := t_ih_l h.left
have t_ih_r' := t_ih_r h.right
clear t_ih_l t_ih_r
obtain ⟨t_l_valid, t_l_size⟩ := t_ih_l'
obtain ⟨t_r_valid, t_r_size⟩ := t_ih_r'
cases cmpLE x t_x <;> rw [h.sz.1]
· suffices h_balanceable : _ by
constructor
· exact Valid'.balanceR t_l_valid h.right h_balanceable
· rw [size_balanceR t_l_valid.bal h.right.bal t_l_valid.sz h.right.sz h_balanceable]
repeat apply Raised.add_right
exact t_l_size
left; exists t_l.size; exact And.intro t_l_size h.bal.1
· have h_glue := Valid'.glue h.left h.right h.bal.1
obtain ⟨h_glue_valid, h_glue_sized⟩ := h_glue
constructor
· exact h_glue_valid
· right; rw [h_glue_sized]
· suffices h_balanceable : _ by
constructor
· exact Valid'.balanceL h.left t_r_valid h_balanceable
· rw [size_balanceL h.left.bal t_r_valid.bal h.left.sz t_r_valid.sz h_balanceable]
apply Raised.add_right
apply Raised.add_left
exact t_r_size
right; exists t_r.size; exact And.intro t_r_size h.bal.1
theorem erase.valid [DecidableLE α] (x : α) {t} (h : Valid t) : Valid (erase x t) :=
(Valid'.erase_aux x h).1
theorem size_erase_of_mem [DecidableLE α] {x : α} {t a₁ a₂} (h : Valid' a₁ t a₂)
(h_mem : x ∈ t) : size (erase x t) = size t - 1 := by
induction t generalizing a₁ a₂ with
| nil =>
contradiction
| node _ t_l t_x t_r t_ih_l t_ih_r =>
have t_ih_l' := t_ih_l h.left
have t_ih_r' := t_ih_r h.right
clear t_ih_l t_ih_r
dsimp only [Membership.mem, mem] at h_mem
unfold erase
revert h_mem; cases cmpLE x t_x <;> intro h_mem <;> dsimp only at h_mem ⊢
· have t_ih_l := t_ih_l' h_mem
clear t_ih_l' t_ih_r'
have t_l_h := Valid'.erase_aux x h.left
obtain ⟨t_l_valid, t_l_size⟩ := t_l_h
rw [size_balanceR t_l_valid.bal h.right.bal t_l_valid.sz h.right.sz
(Or.inl (Exists.intro t_l.size (And.intro t_l_size h.bal.1)))]
rw [t_ih_l, h.sz.1]
have h_pos_t_l_size := pos_size_of_mem h.left.sz h_mem
revert h_pos_t_l_size; rcases t_l.size with - | t_l_size <;> intro h_pos_t_l_size
· cases h_pos_t_l_size
· simp [Nat.add_right_comm]
· rw [(Valid'.glue h.left h.right h.bal.1).2, h.sz.1]; rfl
· have t_ih_r := t_ih_r' h_mem
clear t_ih_l' t_ih_r'
have t_r_h := Valid'.erase_aux x h.right
obtain ⟨t_r_valid, t_r_size⟩ := t_r_h
rw [size_balanceL h.left.bal t_r_valid.bal h.left.sz t_r_valid.sz
(Or.inr (Exists.intro t_r.size (And.intro t_r_size h.bal.1)))]
rw [t_ih_r, h.sz.1]
have h_pos_t_r_size := pos_size_of_mem h.right.sz h_mem
revert h_pos_t_r_size; rcases t_r.size with - | t_r_size <;> intro h_pos_t_r_size
· cases h_pos_t_r_size
· simp [Nat.add_assoc]
end Valid
end Ordnode
/-- An `Ordset α` is a finite set of values, represented as a tree. The operations on this type
maintain that the tree is balanced and correctly stores subtree sizes at each level. The
correctness property of the tree is baked into the type, so all operations on this type are correct
by construction. -/
def Ordset (α : Type*) [Preorder α] :=
{ t : Ordnode α // t.Valid }
namespace Ordset
open Ordnode
variable [Preorder α]
/-- O(1). The empty set. -/
nonrec def nil : Ordset α :=
⟨nil, ⟨⟩, ⟨⟩, ⟨⟩⟩
/-- O(1). Get the size of the set. -/
def size (s : Ordset α) : ℕ :=
s.1.size
/-- O(1). Construct a singleton set containing value `a`. -/
protected def singleton (a : α) : Ordset α :=
⟨singleton a, valid_singleton⟩
instance instEmptyCollection : EmptyCollection (Ordset α) :=
⟨nil⟩
instance instInhabited : Inhabited (Ordset α) :=
⟨nil⟩
instance instSingleton : Singleton α (Ordset α) :=
⟨Ordset.singleton⟩
/-- O(1). Is the set empty? -/
def Empty (s : Ordset α) : Prop :=
s = ∅
theorem empty_iff {s : Ordset α} : s = ∅ ↔ s.1.empty :=
⟨fun h => by cases h; exact rfl,
fun h => by cases s with | mk s_val _ => cases s_val <;> [rfl; cases h]⟩
instance Empty.instDecidablePred : DecidablePred (@Empty α _) :=
fun _ => decidable_of_iff' _ empty_iff
/-- O(log n). Insert an element into the set, preserving balance and the BST property.
If an equivalent element is already in the set, this replaces it. -/
protected def insert [IsTotal α (· ≤ ·)] [DecidableLE α] (x : α) (s : Ordset α) :
Ordset α :=
⟨Ordnode.insert x s.1, insert.valid _ s.2⟩
instance instInsert [IsTotal α (· ≤ ·)] [DecidableLE α] : Insert α (Ordset α) :=
⟨Ordset.insert⟩
/-- O(log n). Insert an element into the set, preserving balance and the BST property.
If an equivalent element is already in the set, the set is returned as is. -/
nonrec def insert' [IsTotal α (· ≤ ·)] [DecidableLE α] (x : α) (s : Ordset α) :
Ordset α :=
⟨insert' x s.1, insert'.valid _ s.2⟩
section
variable [DecidableLE α]
/-- O(log n). Does the set contain the element `x`? That is,
is there an element that is equivalent to `x` in the order? -/
def mem (x : α) (s : Ordset α) : Bool :=
x ∈ s.val
/-- O(log n). Retrieve an element in the set that is equivalent to `x` in the order,
if it exists. -/
def find (x : α) (s : Ordset α) : Option α :=
Ordnode.find x s.val
instance instMembership : Membership α (Ordset α) :=
⟨fun s x => mem x s⟩
instance mem.decidable (x : α) (s : Ordset α) : Decidable (x ∈ s) :=
instDecidableEqBool _ _
theorem pos_size_of_mem {x : α} {t : Ordset α} (h_mem : x ∈ t) : 0 < size t := by
simp? [Membership.mem, mem] at h_mem says
simp only [Membership.mem, mem, Bool.decide_eq_true] at h_mem
apply Ordnode.pos_size_of_mem t.property.sz h_mem
end
/-- O(log n). Remove an element from the set equivalent to `x`. Does nothing if there
is no such element. -/
def erase [DecidableLE α] (x : α) (s : Ordset α) : Ordset α :=
⟨Ordnode.erase x s.val, Ordnode.erase.valid x s.property⟩
/-- O(n). Map a function across a tree, without changing the structure. -/
def map {β} [Preorder β] (f : α → β) (f_strict_mono : StrictMono f) (s : Ordset α) : Ordset β :=
⟨Ordnode.map f s.val, Ordnode.map.valid f_strict_mono s.property⟩
end Ordset
| Mathlib/Data/Ordmap/Ordset.lean | 1,232 | 1,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
-/
import Mathlib.Analysis.Analytic.Within
import Mathlib.Analysis.Calculus.FDeriv.Analytic
import Mathlib.Analysis.Calculus.ContDiff.FTaylorSeries
/-!
# Higher differentiability
A function is `C^1` on a domain if it is differentiable there, and its derivative is continuous.
By induction, it is `C^n` if it is `C^{n-1}` and its (n-1)-th derivative is `C^1` there or,
equivalently, if it is `C^1` and its derivative is `C^{n-1}`.
It is `C^∞` if it is `C^n` for all n.
Finally, it is `C^ω` if it is analytic (as well as all its derivative, which is automatic if the
space is complete).
We formalize these notions with predicates `ContDiffWithinAt`, `ContDiffAt`, `ContDiffOn` and
`ContDiff` saying that the function is `C^n` within a set at a point, at a point, on a set
and on the whole space respectively.
To avoid the issue of choice when choosing a derivative in sets where the derivative is not
necessarily unique, `ContDiffOn` is not defined directly in terms of the
regularity of the specific choice `iteratedFDerivWithin 𝕜 n f s` inside `s`, but in terms of the
existence of a nice sequence of derivatives, expressed with a predicate
`HasFTaylorSeriesUpToOn` defined in the file `FTaylorSeries`.
We prove basic properties of these notions.
## Main definitions and results
Let `f : E → F` be a map between normed vector spaces over a nontrivially normed field `𝕜`.
* `ContDiff 𝕜 n f`: expresses that `f` is `C^n`, i.e., it admits a Taylor series up to
rank `n`.
* `ContDiffOn 𝕜 n f s`: expresses that `f` is `C^n` in `s`.
* `ContDiffAt 𝕜 n f x`: expresses that `f` is `C^n` around `x`.
* `ContDiffWithinAt 𝕜 n f s x`: expresses that `f` is `C^n` around `x` within the set `s`.
In sets of unique differentiability, `ContDiffOn 𝕜 n f s` can be expressed in terms of the
properties of `iteratedFDerivWithin 𝕜 m f s` for `m ≤ n`. In the whole space,
`ContDiff 𝕜 n f` can be expressed in terms of the properties of `iteratedFDeriv 𝕜 m f`
for `m ≤ n`.
## Implementation notes
The definitions in this file are designed to work on any field `𝕜`. They are sometimes slightly more
complicated than the naive definitions one would guess from the intuition over the real or complex
numbers, but they are designed to circumvent the lack of gluing properties and partitions of unity
in general. In the usual situations, they coincide with the usual definitions.
### Definition of `C^n` functions in domains
One could define `C^n` functions in a domain `s` by fixing an arbitrary choice of derivatives (this
is what we do with `iteratedFDerivWithin`) and requiring that all these derivatives up to `n` are
continuous. If the derivative is not unique, this could lead to strange behavior like two `C^n`
functions `f` and `g` on `s` whose sum is not `C^n`. A better definition is thus to say that a
function is `C^n` inside `s` if it admits a sequence of derivatives up to `n` inside `s`.
This definition still has the problem that a function which is locally `C^n` would not need to
be `C^n`, as different choices of sequences of derivatives around different points might possibly
not be glued together to give a globally defined sequence of derivatives. (Note that this issue
can not happen over reals, thanks to partition of unity, but the behavior over a general field is
not so clear, and we want a definition for general fields). Also, there are locality
problems for the order parameter: one could image a function which, for each `n`, has a nice
sequence of derivatives up to order `n`, but they do not coincide for varying `n` and can therefore
not be glued to give rise to an infinite sequence of derivatives. This would give a function
which is `C^n` for all `n`, but not `C^∞`. We solve this issue by putting locality conditions
in space and order in our definition of `ContDiffWithinAt` and `ContDiffOn`.
The resulting definition is slightly more complicated to work with (in fact not so much), but it
gives rise to completely satisfactory theorems.
For instance, with this definition, a real function which is `C^m` (but not better) on `(-1/m, 1/m)`
for each natural `m` is by definition `C^∞` at `0`.
There is another issue with the definition of `ContDiffWithinAt 𝕜 n f s x`. We can
require the existence and good behavior of derivatives up to order `n` on a neighborhood of `x`
within `s`. However, this does not imply continuity or differentiability within `s` of the function
at `x` when `x` does not belong to `s`. Therefore, we require such existence and good behavior on
a neighborhood of `x` within `s ∪ {x}` (which appears as `insert x s` in this file).
## Notations
We use the notation `E [×n]→L[𝕜] F` for the space of continuous multilinear maps on `E^n` with
values in `F`. This is the space in which the `n`-th derivative of a function from `E` to `F` lives.
In this file, we denote `(⊤ : ℕ∞) : WithTop ℕ∞` with `∞`, and `⊤ : WithTop ℕ∞` with `ω`. To
avoid ambiguities with the two tops, the theorems name use either `infty` or `omega`.
These notations are scoped in `ContDiff`.
## Tags
derivative, differentiability, higher derivative, `C^n`, multilinear, Taylor series, formal series
-/
noncomputable section
open Set Fin Filter Function
open scoped NNReal Topology ContDiff
universe u uE uF uG uX
variable {𝕜 : Type u} [NontriviallyNormedField 𝕜] {E : Type uE} [NormedAddCommGroup E]
[NormedSpace 𝕜 E] {F : Type uF} [NormedAddCommGroup F] [NormedSpace 𝕜 F] {G : Type uG}
[NormedAddCommGroup G] [NormedSpace 𝕜 G] {X : Type uX} [NormedAddCommGroup X] [NormedSpace 𝕜 X]
{s s₁ t u : Set E} {f f₁ : E → F} {g : F → G} {x x₀ : E} {c : F} {m n : WithTop ℕ∞}
{p : E → FormalMultilinearSeries 𝕜 E F}
/-! ### Smooth functions within a set around a point -/
variable (𝕜) in
/-- A function is continuously differentiable up to order `n` within a set `s` at a point `x` if
it admits continuous derivatives up to order `n` in a neighborhood of `x` in `s ∪ {x}`.
For `n = ∞`, we only require that this holds up to any finite order (where the neighborhood may
depend on the finite order we consider).
For `n = ω`, we require the function to be analytic within `s` at `x`. The precise definition we
give (all the derivatives should be analytic) is more involved to work around issues when the space
is not complete, but it is equivalent when the space is complete.
For instance, a real function which is `C^m` on `(-1/m, 1/m)` for each natural `m`, but not
better, is `C^∞` at `0` within `univ`.
-/
def ContDiffWithinAt (n : WithTop ℕ∞) (f : E → F) (s : Set E) (x : E) : Prop :=
match n with
| ω => ∃ u ∈ 𝓝[insert x s] x, ∃ p : E → FormalMultilinearSeries 𝕜 E F,
HasFTaylorSeriesUpToOn ω f p u ∧ ∀ i, AnalyticOn 𝕜 (fun x ↦ p x i) u
| (n : ℕ∞) => ∀ m : ℕ, m ≤ n → ∃ u ∈ 𝓝[insert x s] x,
∃ p : E → FormalMultilinearSeries 𝕜 E F, HasFTaylorSeriesUpToOn m f p u
lemma HasFTaylorSeriesUpToOn.analyticOn
(hf : HasFTaylorSeriesUpToOn ω f p s) (h : AnalyticOn 𝕜 (fun x ↦ p x 0) s) :
AnalyticOn 𝕜 f s := by
have : AnalyticOn 𝕜 (fun x ↦ (continuousMultilinearCurryFin0 𝕜 E F) (p x 0)) s :=
(LinearIsometryEquiv.analyticOnNhd _ _ ).comp_analyticOn
h (Set.mapsTo_univ _ _)
exact this.congr (fun y hy ↦ (hf.zero_eq _ hy).symm)
lemma ContDiffWithinAt.analyticOn (h : ContDiffWithinAt 𝕜 ω f s x) :
∃ u ∈ 𝓝[insert x s] x, AnalyticOn 𝕜 f u := by
obtain ⟨u, hu, p, hp, h'p⟩ := h
exact ⟨u, hu, hp.analyticOn (h'p 0)⟩
lemma ContDiffWithinAt.analyticWithinAt (h : ContDiffWithinAt 𝕜 ω f s x) :
AnalyticWithinAt 𝕜 f s x := by
obtain ⟨u, hu, hf⟩ := h.analyticOn
have xu : x ∈ u := mem_of_mem_nhdsWithin (by simp) hu
exact (hf x xu).mono_of_mem_nhdsWithin (nhdsWithin_mono _ (subset_insert _ _) hu)
theorem contDiffWithinAt_omega_iff_analyticWithinAt [CompleteSpace F] :
ContDiffWithinAt 𝕜 ω f s x ↔ AnalyticWithinAt 𝕜 f s x := by
refine ⟨fun h ↦ h.analyticWithinAt, fun h ↦ ?_⟩
obtain ⟨u, hu, p, hp, h'p⟩ := h.exists_hasFTaylorSeriesUpToOn ω
exact ⟨u, hu, p, hp.of_le le_top, fun i ↦ h'p i⟩
theorem contDiffWithinAt_nat {n : ℕ} :
ContDiffWithinAt 𝕜 n f s x ↔ ∃ u ∈ 𝓝[insert x s] x,
∃ p : E → FormalMultilinearSeries 𝕜 E F, HasFTaylorSeriesUpToOn n f p u :=
⟨fun H => H n le_rfl, fun ⟨u, hu, p, hp⟩ _m hm => ⟨u, hu, p, hp.of_le (mod_cast hm)⟩⟩
/-- When `n` is either a natural number or `ω`, one can characterize the property of being `C^n`
as the existence of a neighborhood on which there is a Taylor series up to order `n`,
requiring in addition that its terms are analytic in the `ω` case. -/
lemma contDiffWithinAt_iff_of_ne_infty (hn : n ≠ ∞) :
ContDiffWithinAt 𝕜 n f s x ↔ ∃ u ∈ 𝓝[insert x s] x,
∃ p : E → FormalMultilinearSeries 𝕜 E F, HasFTaylorSeriesUpToOn n f p u ∧
(n = ω → ∀ i, AnalyticOn 𝕜 (fun x ↦ p x i) u) := by
match n with
| ω => simp [ContDiffWithinAt]
| ∞ => simp at hn
| (n : ℕ) => simp [contDiffWithinAt_nat]
theorem ContDiffWithinAt.of_le (h : ContDiffWithinAt 𝕜 n f s x) (hmn : m ≤ n) :
ContDiffWithinAt 𝕜 m f s x := by
match n with
| ω => match m with
| ω => exact h
| (m : ℕ∞) =>
intro k _
obtain ⟨u, hu, p, hp, -⟩ := h
exact ⟨u, hu, p, hp.of_le le_top⟩
| (n : ℕ∞) => match m with
| ω => simp at hmn
| (m : ℕ∞) => exact fun k hk ↦ h k (le_trans hk (mod_cast hmn))
/-- In a complete space, a function which is analytic within a set at a point is also `C^ω` there.
Note that the same statement for `AnalyticOn` does not require completeness, see
`AnalyticOn.contDiffOn`. -/
theorem AnalyticWithinAt.contDiffWithinAt [CompleteSpace F] (h : AnalyticWithinAt 𝕜 f s x) :
ContDiffWithinAt 𝕜 n f s x :=
(contDiffWithinAt_omega_iff_analyticWithinAt.2 h).of_le le_top
theorem contDiffWithinAt_iff_forall_nat_le {n : ℕ∞} :
ContDiffWithinAt 𝕜 n f s x ↔ ∀ m : ℕ, ↑m ≤ n → ContDiffWithinAt 𝕜 m f s x :=
⟨fun H _ hm => H.of_le (mod_cast hm), fun H m hm => H m hm _ le_rfl⟩
theorem contDiffWithinAt_infty :
ContDiffWithinAt 𝕜 ∞ f s x ↔ ∀ n : ℕ, ContDiffWithinAt 𝕜 n f s x :=
contDiffWithinAt_iff_forall_nat_le.trans <| by simp only [forall_prop_of_true, le_top]
@[deprecated (since := "2024-11-25")] alias contDiffWithinAt_top := contDiffWithinAt_infty
theorem ContDiffWithinAt.continuousWithinAt (h : ContDiffWithinAt 𝕜 n f s x) :
ContinuousWithinAt f s x := by
have := h.of_le (zero_le _)
simp only [ContDiffWithinAt, nonpos_iff_eq_zero, Nat.cast_eq_zero,
mem_pure, forall_eq, CharP.cast_eq_zero] at this
rcases this with ⟨u, hu, p, H⟩
rw [mem_nhdsWithin_insert] at hu
exact (H.continuousOn.continuousWithinAt hu.1).mono_of_mem_nhdsWithin hu.2
theorem ContDiffWithinAt.congr_of_eventuallyEq (h : ContDiffWithinAt 𝕜 n f s x)
(h₁ : f₁ =ᶠ[𝓝[s] x] f) (hx : f₁ x = f x) : ContDiffWithinAt 𝕜 n f₁ s x := by
match n with
| ω =>
obtain ⟨u, hu, p, H, H'⟩ := h
exact ⟨{x ∈ u | f₁ x = f x}, Filter.inter_mem hu (mem_nhdsWithin_insert.2 ⟨hx, h₁⟩), p,
(H.mono (sep_subset _ _)).congr fun _ ↦ And.right,
fun i ↦ (H' i).mono (sep_subset _ _)⟩
| (n : ℕ∞) =>
intro m hm
let ⟨u, hu, p, H⟩ := h m hm
exact ⟨{ x ∈ u | f₁ x = f x }, Filter.inter_mem hu (mem_nhdsWithin_insert.2 ⟨hx, h₁⟩), p,
(H.mono (sep_subset _ _)).congr fun _ ↦ And.right⟩
theorem Filter.EventuallyEq.congr_contDiffWithinAt (h₁ : f₁ =ᶠ[𝓝[s] x] f) (hx : f₁ x = f x) :
ContDiffWithinAt 𝕜 n f₁ s x ↔ ContDiffWithinAt 𝕜 n f s x :=
⟨fun H ↦ H.congr_of_eventuallyEq h₁.symm hx.symm, fun H ↦ H.congr_of_eventuallyEq h₁ hx⟩
theorem ContDiffWithinAt.congr_of_eventuallyEq_insert (h : ContDiffWithinAt 𝕜 n f s x)
(h₁ : f₁ =ᶠ[𝓝[insert x s] x] f) : ContDiffWithinAt 𝕜 n f₁ s x :=
h.congr_of_eventuallyEq (nhdsWithin_mono x (subset_insert x s) h₁)
(mem_of_mem_nhdsWithin (mem_insert x s) h₁ :)
theorem Filter.EventuallyEq.congr_contDiffWithinAt_of_insert (h₁ : f₁ =ᶠ[𝓝[insert x s] x] f) :
ContDiffWithinAt 𝕜 n f₁ s x ↔ ContDiffWithinAt 𝕜 n f s x :=
⟨fun H ↦ H.congr_of_eventuallyEq_insert h₁.symm, fun H ↦ H.congr_of_eventuallyEq_insert h₁⟩
theorem ContDiffWithinAt.congr_of_eventuallyEq_of_mem (h : ContDiffWithinAt 𝕜 n f s x)
(h₁ : f₁ =ᶠ[𝓝[s] x] f) (hx : x ∈ s) : ContDiffWithinAt 𝕜 n f₁ s x :=
h.congr_of_eventuallyEq h₁ <| h₁.self_of_nhdsWithin hx
theorem Filter.EventuallyEq.congr_contDiffWithinAt_of_mem (h₁ : f₁ =ᶠ[𝓝[s] x] f) (hx : x ∈ s):
ContDiffWithinAt 𝕜 n f₁ s x ↔ ContDiffWithinAt 𝕜 n f s x :=
⟨fun H ↦ H.congr_of_eventuallyEq_of_mem h₁.symm hx, fun H ↦ H.congr_of_eventuallyEq_of_mem h₁ hx⟩
theorem ContDiffWithinAt.congr (h : ContDiffWithinAt 𝕜 n f s x) (h₁ : ∀ y ∈ s, f₁ y = f y)
(hx : f₁ x = f x) : ContDiffWithinAt 𝕜 n f₁ s x :=
h.congr_of_eventuallyEq (Filter.eventuallyEq_of_mem self_mem_nhdsWithin h₁) hx
theorem contDiffWithinAt_congr (h₁ : ∀ y ∈ s, f₁ y = f y) (hx : f₁ x = f x) :
ContDiffWithinAt 𝕜 n f₁ s x ↔ ContDiffWithinAt 𝕜 n f s x :=
⟨fun h' ↦ h'.congr (fun x hx ↦ (h₁ x hx).symm) hx.symm, fun h' ↦ h'.congr h₁ hx⟩
theorem ContDiffWithinAt.congr_of_mem (h : ContDiffWithinAt 𝕜 n f s x) (h₁ : ∀ y ∈ s, f₁ y = f y)
(hx : x ∈ s) : ContDiffWithinAt 𝕜 n f₁ s x :=
h.congr h₁ (h₁ _ hx)
theorem contDiffWithinAt_congr_of_mem (h₁ : ∀ y ∈ s, f₁ y = f y) (hx : x ∈ s) :
ContDiffWithinAt 𝕜 n f₁ s x ↔ ContDiffWithinAt 𝕜 n f s x :=
contDiffWithinAt_congr h₁ (h₁ x hx)
theorem ContDiffWithinAt.congr_of_insert (h : ContDiffWithinAt 𝕜 n f s x)
(h₁ : ∀ y ∈ insert x s, f₁ y = f y) : ContDiffWithinAt 𝕜 n f₁ s x :=
h.congr (fun y hy ↦ h₁ y (mem_insert_of_mem _ hy)) (h₁ x (mem_insert _ _))
theorem contDiffWithinAt_congr_of_insert (h₁ : ∀ y ∈ insert x s, f₁ y = f y) :
ContDiffWithinAt 𝕜 n f₁ s x ↔ ContDiffWithinAt 𝕜 n f s x :=
contDiffWithinAt_congr (fun y hy ↦ h₁ y (mem_insert_of_mem _ hy)) (h₁ x (mem_insert _ _))
theorem ContDiffWithinAt.mono_of_mem_nhdsWithin (h : ContDiffWithinAt 𝕜 n f s x) {t : Set E}
(hst : s ∈ 𝓝[t] x) : ContDiffWithinAt 𝕜 n f t x := by
match n with
| ω =>
obtain ⟨u, hu, p, H, H'⟩ := h
exact ⟨u, nhdsWithin_le_of_mem (insert_mem_nhdsWithin_insert hst) hu, p, H, H'⟩
| (n : ℕ∞) =>
intro m hm
rcases h m hm with ⟨u, hu, p, H⟩
exact ⟨u, nhdsWithin_le_of_mem (insert_mem_nhdsWithin_insert hst) hu, p, H⟩
@[deprecated (since := "2024-10-30")]
alias ContDiffWithinAt.mono_of_mem := ContDiffWithinAt.mono_of_mem_nhdsWithin
theorem ContDiffWithinAt.mono (h : ContDiffWithinAt 𝕜 n f s x) {t : Set E} (hst : t ⊆ s) :
ContDiffWithinAt 𝕜 n f t x :=
h.mono_of_mem_nhdsWithin <| Filter.mem_of_superset self_mem_nhdsWithin hst
theorem ContDiffWithinAt.congr_mono
(h : ContDiffWithinAt 𝕜 n f s x) (h' : EqOn f₁ f s₁) (h₁ : s₁ ⊆ s) (hx : f₁ x = f x) :
ContDiffWithinAt 𝕜 n f₁ s₁ x :=
(h.mono h₁).congr h' hx
theorem ContDiffWithinAt.congr_set (h : ContDiffWithinAt 𝕜 n f s x) {t : Set E}
(hst : s =ᶠ[𝓝 x] t) : ContDiffWithinAt 𝕜 n f t x := by
rw [← nhdsWithin_eq_iff_eventuallyEq] at hst
apply h.mono_of_mem_nhdsWithin <| hst ▸ self_mem_nhdsWithin
@[deprecated (since := "2024-10-23")]
alias ContDiffWithinAt.congr_nhds := ContDiffWithinAt.congr_set
theorem contDiffWithinAt_congr_set {t : Set E} (hst : s =ᶠ[𝓝 x] t) :
ContDiffWithinAt 𝕜 n f s x ↔ ContDiffWithinAt 𝕜 n f t x :=
⟨fun h => h.congr_set hst, fun h => h.congr_set hst.symm⟩
@[deprecated (since := "2024-10-23")]
alias contDiffWithinAt_congr_nhds := contDiffWithinAt_congr_set
theorem contDiffWithinAt_inter' (h : t ∈ 𝓝[s] x) :
ContDiffWithinAt 𝕜 n f (s ∩ t) x ↔ ContDiffWithinAt 𝕜 n f s x :=
contDiffWithinAt_congr_set (mem_nhdsWithin_iff_eventuallyEq.1 h).symm
theorem contDiffWithinAt_inter (h : t ∈ 𝓝 x) :
ContDiffWithinAt 𝕜 n f (s ∩ t) x ↔ ContDiffWithinAt 𝕜 n f s x :=
contDiffWithinAt_inter' (mem_nhdsWithin_of_mem_nhds h)
theorem contDiffWithinAt_insert_self :
ContDiffWithinAt 𝕜 n f (insert x s) x ↔ ContDiffWithinAt 𝕜 n f s x := by
match n with
| ω => simp [ContDiffWithinAt]
| (n : ℕ∞) => simp_rw [ContDiffWithinAt, insert_idem]
theorem contDiffWithinAt_insert {y : E} :
ContDiffWithinAt 𝕜 n f (insert y s) x ↔ ContDiffWithinAt 𝕜 n f s x := by
rcases eq_or_ne x y with (rfl | hx)
· exact contDiffWithinAt_insert_self
refine ⟨fun h ↦ h.mono (subset_insert _ _), fun h ↦ ?_⟩
apply h.mono_of_mem_nhdsWithin
simp [nhdsWithin_insert_of_ne hx, self_mem_nhdsWithin]
alias ⟨ContDiffWithinAt.of_insert, ContDiffWithinAt.insert'⟩ := contDiffWithinAt_insert
protected theorem ContDiffWithinAt.insert (h : ContDiffWithinAt 𝕜 n f s x) :
ContDiffWithinAt 𝕜 n f (insert x s) x :=
h.insert'
theorem contDiffWithinAt_diff_singleton {y : E} :
ContDiffWithinAt 𝕜 n f (s \ {y}) x ↔ ContDiffWithinAt 𝕜 n f s x := by
rw [← contDiffWithinAt_insert, insert_diff_singleton, contDiffWithinAt_insert]
/-- If a function is `C^n` within a set at a point, with `n ≥ 1`, then it is differentiable
within this set at this point. -/
theorem ContDiffWithinAt.differentiableWithinAt' (h : ContDiffWithinAt 𝕜 n f s x) (hn : 1 ≤ n) :
DifferentiableWithinAt 𝕜 f (insert x s) x := by
rcases contDiffWithinAt_nat.1 (h.of_le hn) with ⟨u, hu, p, H⟩
rcases mem_nhdsWithin.1 hu with ⟨t, t_open, xt, tu⟩
rw [inter_comm] at tu
exact (differentiableWithinAt_inter (IsOpen.mem_nhds t_open xt)).1 <|
((H.mono tu).differentiableOn le_rfl) x ⟨mem_insert x s, xt⟩
theorem ContDiffWithinAt.differentiableWithinAt (h : ContDiffWithinAt 𝕜 n f s x) (hn : 1 ≤ n) :
DifferentiableWithinAt 𝕜 f s x :=
(h.differentiableWithinAt' hn).mono (subset_insert x s)
/-- A function is `C^(n + 1)` on a domain iff locally, it has a derivative which is `C^n`
(and moreover the function is analytic when `n = ω`). -/
theorem contDiffWithinAt_succ_iff_hasFDerivWithinAt (hn : n ≠ ∞) :
ContDiffWithinAt 𝕜 (n + 1) f s x ↔ ∃ u ∈ 𝓝[insert x s] x, (n = ω → AnalyticOn 𝕜 f u) ∧
∃ f' : E → E →L[𝕜] F,
(∀ x ∈ u, HasFDerivWithinAt f (f' x) u x) ∧ ContDiffWithinAt 𝕜 n f' u x := by
have h'n : n + 1 ≠ ∞ := by simpa using hn
constructor
· intro h
rcases (contDiffWithinAt_iff_of_ne_infty h'n).1 h with ⟨u, hu, p, Hp, H'p⟩
refine ⟨u, hu, ?_, fun y => (continuousMultilinearCurryFin1 𝕜 E F) (p y 1),
fun y hy => Hp.hasFDerivWithinAt le_add_self hy, ?_⟩
· rintro rfl
exact Hp.analyticOn (H'p rfl 0)
apply (contDiffWithinAt_iff_of_ne_infty hn).2
refine ⟨u, ?_, fun y : E => (p y).shift, ?_⟩
· convert @self_mem_nhdsWithin _ _ x u
have : x ∈ insert x s := by simp
exact insert_eq_of_mem (mem_of_mem_nhdsWithin this hu)
· rw [hasFTaylorSeriesUpToOn_succ_iff_right] at Hp
refine ⟨Hp.2.2, ?_⟩
rintro rfl i
change AnalyticOn 𝕜
(fun x ↦ (continuousMultilinearCurryRightEquiv' 𝕜 i E F) (p x (i + 1))) u
apply (LinearIsometryEquiv.analyticOnNhd _ _).comp_analyticOn
?_ (Set.mapsTo_univ _ _)
exact H'p rfl _
· rintro ⟨u, hu, hf, f', f'_eq_deriv, Hf'⟩
rw [contDiffWithinAt_iff_of_ne_infty h'n]
rcases (contDiffWithinAt_iff_of_ne_infty hn).1 Hf' with ⟨v, hv, p', Hp', p'_an⟩
refine ⟨v ∩ u, ?_, fun x => (p' x).unshift (f x), ?_, ?_⟩
· apply Filter.inter_mem _ hu
apply nhdsWithin_le_of_mem hu
exact nhdsWithin_mono _ (subset_insert x u) hv
· rw [hasFTaylorSeriesUpToOn_succ_iff_right]
refine ⟨fun y _ => rfl, fun y hy => ?_, ?_⟩
· change
HasFDerivWithinAt (fun z => (continuousMultilinearCurryFin0 𝕜 E F).symm (f z))
(FormalMultilinearSeries.unshift (p' y) (f y) 1).curryLeft (v ∩ u) y
rw [← Function.comp_def _ f, LinearIsometryEquiv.comp_hasFDerivWithinAt_iff']
convert (f'_eq_deriv y hy.2).mono inter_subset_right
rw [← Hp'.zero_eq y hy.1]
ext z
change ((p' y 0) (init (@cons 0 (fun _ => E) z 0))) (@cons 0 (fun _ => E) z 0 (last 0)) =
((p' y 0) 0) z
congr
norm_num [eq_iff_true_of_subsingleton]
· convert (Hp'.mono inter_subset_left).congr fun x hx => Hp'.zero_eq x hx.1 using 1
· ext x y
change p' x 0 (init (@snoc 0 (fun _ : Fin 1 => E) 0 y)) y = p' x 0 0 y
rw [init_snoc]
· ext x k v y
change p' x k (init (@snoc k (fun _ : Fin k.succ => E) v y))
(@snoc k (fun _ : Fin k.succ => E) v y (last k)) = p' x k v y
rw [snoc_last, init_snoc]
· intro h i
simp only [WithTop.add_eq_top, WithTop.one_ne_top, or_false] at h
match i with
| 0 =>
simp only [FormalMultilinearSeries.unshift]
apply AnalyticOnNhd.comp_analyticOn _ ((hf h).mono inter_subset_right)
(Set.mapsTo_univ _ _)
exact LinearIsometryEquiv.analyticOnNhd _ _
| i + 1 =>
simp only [FormalMultilinearSeries.unshift, Nat.succ_eq_add_one]
apply AnalyticOnNhd.comp_analyticOn _ ((p'_an h i).mono inter_subset_left)
(Set.mapsTo_univ _ _)
exact LinearIsometryEquiv.analyticOnNhd _ _
/-- A version of `contDiffWithinAt_succ_iff_hasFDerivWithinAt` where all derivatives
are taken within the same set. -/
theorem contDiffWithinAt_succ_iff_hasFDerivWithinAt' (hn : n ≠ ∞) :
ContDiffWithinAt 𝕜 (n + 1) f s x ↔
∃ u ∈ 𝓝[insert x s] x, u ⊆ insert x s ∧ (n = ω → AnalyticOn 𝕜 f u) ∧
∃ f' : E → E →L[𝕜] F,
(∀ x ∈ u, HasFDerivWithinAt f (f' x) s x) ∧ ContDiffWithinAt 𝕜 n f' s x := by
refine ⟨fun hf => ?_, ?_⟩
· obtain ⟨u, hu, f_an, f', huf', hf'⟩ := (contDiffWithinAt_succ_iff_hasFDerivWithinAt hn).mp hf
obtain ⟨w, hw, hxw, hwu⟩ := mem_nhdsWithin.mp hu
rw [inter_comm] at hwu
refine ⟨insert x s ∩ w, inter_mem_nhdsWithin _ (hw.mem_nhds hxw), inter_subset_left, ?_, f',
fun y hy => ?_, ?_⟩
· intro h
apply (f_an h).mono hwu
· refine ((huf' y <| hwu hy).mono hwu).mono_of_mem_nhdsWithin ?_
refine mem_of_superset ?_ (inter_subset_inter_left _ (subset_insert _ _))
exact inter_mem_nhdsWithin _ (hw.mem_nhds hy.2)
· exact hf'.mono_of_mem_nhdsWithin (nhdsWithin_mono _ (subset_insert _ _) hu)
· rw [← contDiffWithinAt_insert, contDiffWithinAt_succ_iff_hasFDerivWithinAt hn,
insert_eq_of_mem (mem_insert _ _)]
rintro ⟨u, hu, hus, f_an, f', huf', hf'⟩
exact ⟨u, hu, f_an, f', fun y hy => (huf' y hy).insert'.mono hus, hf'.insert.mono hus⟩
/-! ### Smooth functions within a set -/
variable (𝕜) in
/-- A function is continuously differentiable up to `n` on `s` if, for any point `x` in `s`, it
admits continuous derivatives up to order `n` on a neighborhood of `x` in `s`.
For `n = ∞`, we only require that this holds up to any finite order (where the neighborhood may
depend on the finite order we consider).
-/
def ContDiffOn (n : WithTop ℕ∞) (f : E → F) (s : Set E) : Prop :=
∀ x ∈ s, ContDiffWithinAt 𝕜 n f s x
theorem HasFTaylorSeriesUpToOn.contDiffOn {n : ℕ∞} {f' : E → FormalMultilinearSeries 𝕜 E F}
(hf : HasFTaylorSeriesUpToOn n f f' s) : ContDiffOn 𝕜 n f s := by
intro x hx m hm
use s
simp only [Set.insert_eq_of_mem hx, self_mem_nhdsWithin, true_and]
exact ⟨f', hf.of_le (mod_cast hm)⟩
theorem ContDiffOn.contDiffWithinAt (h : ContDiffOn 𝕜 n f s) (hx : x ∈ s) :
ContDiffWithinAt 𝕜 n f s x :=
h x hx
theorem ContDiffOn.of_le (h : ContDiffOn 𝕜 n f s) (hmn : m ≤ n) : ContDiffOn 𝕜 m f s := fun x hx =>
(h x hx).of_le hmn
theorem ContDiffWithinAt.contDiffOn' (hm : m ≤ n) (h' : m = ∞ → n = ω)
(h : ContDiffWithinAt 𝕜 n f s x) :
∃ u, IsOpen u ∧ x ∈ u ∧ ContDiffOn 𝕜 m f (insert x s ∩ u) := by
rcases eq_or_ne n ω with rfl | hn
· obtain ⟨t, ht, p, hp, h'p⟩ := h
rcases mem_nhdsWithin.1 ht with ⟨u, huo, hxu, hut⟩
rw [inter_comm] at hut
refine ⟨u, huo, hxu, ?_⟩
suffices ContDiffOn 𝕜 ω f (insert x s ∩ u) from this.of_le le_top
intro y hy
refine ⟨insert x s ∩ u, ?_, p, hp.mono hut, fun i ↦ (h'p i).mono hut⟩
simp only [insert_eq_of_mem, hy, self_mem_nhdsWithin]
· match m with
| ω => simp [hn] at hm
| ∞ => exact (hn (h' rfl)).elim
| (m : ℕ) =>
rcases contDiffWithinAt_nat.1 (h.of_le hm) with ⟨t, ht, p, hp⟩
rcases mem_nhdsWithin.1 ht with ⟨u, huo, hxu, hut⟩
rw [inter_comm] at hut
exact ⟨u, huo, hxu, (hp.mono hut).contDiffOn⟩
theorem ContDiffWithinAt.contDiffOn (hm : m ≤ n) (h' : m = ∞ → n = ω)
(h : ContDiffWithinAt 𝕜 n f s x) :
∃ u ∈ 𝓝[insert x s] x, u ⊆ insert x s ∧ ContDiffOn 𝕜 m f u := by
obtain ⟨_u, uo, xu, h⟩ := h.contDiffOn' hm h'
exact ⟨_, inter_mem_nhdsWithin _ (uo.mem_nhds xu), inter_subset_left, h⟩
theorem ContDiffOn.analyticOn (h : ContDiffOn 𝕜 ω f s) : AnalyticOn 𝕜 f s :=
fun x hx ↦ (h x hx).analyticWithinAt
/-- A function is `C^n` within a set at a point, for `n : ℕ`, if and only if it is `C^n` on
a neighborhood of this point. -/
theorem contDiffWithinAt_iff_contDiffOn_nhds (hn : n ≠ ∞) :
ContDiffWithinAt 𝕜 n f s x ↔ ∃ u ∈ 𝓝[insert x s] x, ContDiffOn 𝕜 n f u := by
refine ⟨fun h ↦ ?_, fun h ↦ ?_⟩
· rcases h.contDiffOn le_rfl (by simp [hn]) with ⟨u, hu, h'u⟩
exact ⟨u, hu, h'u.2⟩
· rcases h with ⟨u, u_mem, hu⟩
have : x ∈ u := mem_of_mem_nhdsWithin (mem_insert x s) u_mem
exact (hu x this).mono_of_mem_nhdsWithin (nhdsWithin_mono _ (subset_insert x s) u_mem)
protected theorem ContDiffWithinAt.eventually (h : ContDiffWithinAt 𝕜 n f s x) (hn : n ≠ ∞) :
∀ᶠ y in 𝓝[insert x s] x, ContDiffWithinAt 𝕜 n f s y := by
rcases h.contDiffOn le_rfl (by simp [hn]) with ⟨u, hu, _, hd⟩
have : ∀ᶠ y : E in 𝓝[insert x s] x, u ∈ 𝓝[insert x s] y ∧ y ∈ u :=
(eventually_eventually_nhdsWithin.2 hu).and hu
refine this.mono fun y hy => (hd y hy.2).mono_of_mem_nhdsWithin ?_
exact nhdsWithin_mono y (subset_insert _ _) hy.1
theorem ContDiffOn.of_succ (h : ContDiffOn 𝕜 (n + 1) f s) : ContDiffOn 𝕜 n f s :=
h.of_le le_self_add
theorem ContDiffOn.one_of_succ (h : ContDiffOn 𝕜 (n + 1) f s) : ContDiffOn 𝕜 1 f s :=
h.of_le le_add_self
theorem contDiffOn_iff_forall_nat_le {n : ℕ∞} :
ContDiffOn 𝕜 n f s ↔ ∀ m : ℕ, ↑m ≤ n → ContDiffOn 𝕜 m f s :=
⟨fun H _ hm => H.of_le (mod_cast hm), fun H x hx m hm => H m hm x hx m le_rfl⟩
theorem contDiffOn_infty : ContDiffOn 𝕜 ∞ f s ↔ ∀ n : ℕ, ContDiffOn 𝕜 n f s :=
contDiffOn_iff_forall_nat_le.trans <| by simp only [le_top, forall_prop_of_true]
@[deprecated (since := "2024-11-27")] alias contDiffOn_top := contDiffOn_infty
@[deprecated (since := "2024-11-27")]
alias contDiffOn_infty_iff_contDiffOn_omega := contDiffOn_infty
theorem contDiffOn_all_iff_nat :
(∀ (n : ℕ∞), ContDiffOn 𝕜 n f s) ↔ ∀ n : ℕ, ContDiffOn 𝕜 n f s := by
refine ⟨fun H n => H n, ?_⟩
rintro H (_ | n)
exacts [contDiffOn_infty.2 H, H n]
theorem ContDiffOn.continuousOn (h : ContDiffOn 𝕜 n f s) : ContinuousOn f s := fun x hx =>
(h x hx).continuousWithinAt
theorem ContDiffOn.congr (h : ContDiffOn 𝕜 n f s) (h₁ : ∀ x ∈ s, f₁ x = f x) :
ContDiffOn 𝕜 n f₁ s := fun x hx => (h x hx).congr h₁ (h₁ x hx)
theorem contDiffOn_congr (h₁ : ∀ x ∈ s, f₁ x = f x) : ContDiffOn 𝕜 n f₁ s ↔ ContDiffOn 𝕜 n f s :=
⟨fun H => H.congr fun x hx => (h₁ x hx).symm, fun H => H.congr h₁⟩
theorem ContDiffOn.mono (h : ContDiffOn 𝕜 n f s) {t : Set E} (hst : t ⊆ s) : ContDiffOn 𝕜 n f t :=
fun x hx => (h x (hst hx)).mono hst
theorem ContDiffOn.congr_mono (hf : ContDiffOn 𝕜 n f s) (h₁ : ∀ x ∈ s₁, f₁ x = f x) (hs : s₁ ⊆ s) :
ContDiffOn 𝕜 n f₁ s₁ :=
(hf.mono hs).congr h₁
/-- If a function is `C^n` on a set with `n ≥ 1`, then it is differentiable there. -/
theorem ContDiffOn.differentiableOn (h : ContDiffOn 𝕜 n f s) (hn : 1 ≤ n) :
DifferentiableOn 𝕜 f s := fun x hx => (h x hx).differentiableWithinAt hn
/-- If a function is `C^n` around each point in a set, then it is `C^n` on the set. -/
theorem contDiffOn_of_locally_contDiffOn
(h : ∀ x ∈ s, ∃ u, IsOpen u ∧ x ∈ u ∧ ContDiffOn 𝕜 n f (s ∩ u)) : ContDiffOn 𝕜 n f s := by
intro x xs
rcases h x xs with ⟨u, u_open, xu, hu⟩
apply (contDiffWithinAt_inter _).1 (hu x ⟨xs, xu⟩)
exact IsOpen.mem_nhds u_open xu
/-- A function is `C^(n + 1)` on a domain iff locally, it has a derivative which is `C^n`. -/
theorem contDiffOn_succ_iff_hasFDerivWithinAt (hn : n ≠ ∞) :
ContDiffOn 𝕜 (n + 1) f s ↔
∀ x ∈ s, ∃ u ∈ 𝓝[insert x s] x, (n = ω → AnalyticOn 𝕜 f u) ∧ ∃ f' : E → E →L[𝕜] F,
(∀ x ∈ u, HasFDerivWithinAt f (f' x) u x) ∧ ContDiffOn 𝕜 n f' u := by
constructor
· intro h x hx
rcases (contDiffWithinAt_succ_iff_hasFDerivWithinAt hn).1 (h x hx) with
⟨u, hu, f_an, f', hf', Hf'⟩
rcases Hf'.contDiffOn le_rfl (by simp [hn]) with ⟨v, vu, v'u, hv⟩
rw [insert_eq_of_mem hx] at hu ⊢
have xu : x ∈ u := mem_of_mem_nhdsWithin hx hu
rw [insert_eq_of_mem xu] at vu v'u
exact ⟨v, nhdsWithin_le_of_mem hu vu, fun h ↦ (f_an h).mono v'u, f',
fun y hy ↦ (hf' y (v'u hy)).mono v'u, hv⟩
· intro h x hx
rw [contDiffWithinAt_succ_iff_hasFDerivWithinAt hn]
rcases h x hx with ⟨u, u_nhbd, f_an, f', hu, hf'⟩
have : x ∈ u := mem_of_mem_nhdsWithin (mem_insert _ _) u_nhbd
exact ⟨u, u_nhbd, f_an, f', hu, hf' x this⟩
/-! ### Iterated derivative within a set -/
@[simp]
theorem contDiffOn_zero : ContDiffOn 𝕜 0 f s ↔ ContinuousOn f s := by
refine ⟨fun H => H.continuousOn, fun H => fun x hx m hm ↦ ?_⟩
have : (m : WithTop ℕ∞) = 0 := le_antisymm (mod_cast hm) bot_le
rw [this]
refine ⟨insert x s, self_mem_nhdsWithin, ftaylorSeriesWithin 𝕜 f s, ?_⟩
rw [hasFTaylorSeriesUpToOn_zero_iff]
exact ⟨by rwa [insert_eq_of_mem hx], fun x _ => by simp [ftaylorSeriesWithin]⟩
theorem contDiffWithinAt_zero (hx : x ∈ s) :
ContDiffWithinAt 𝕜 0 f s x ↔ ∃ u ∈ 𝓝[s] x, ContinuousOn f (s ∩ u) := by
constructor
· intro h
obtain ⟨u, H, p, hp⟩ := h 0 le_rfl
refine ⟨u, ?_, ?_⟩
· simpa [hx] using H
· simp only [Nat.cast_zero, hasFTaylorSeriesUpToOn_zero_iff] at hp
exact hp.1.mono inter_subset_right
· rintro ⟨u, H, hu⟩
rw [← contDiffWithinAt_inter' H]
have h' : x ∈ s ∩ u := ⟨hx, mem_of_mem_nhdsWithin hx H⟩
exact (contDiffOn_zero.mpr hu).contDiffWithinAt h'
/-- When a function is `C^n` in a set `s` of unique differentiability, it admits
`ftaylorSeriesWithin 𝕜 f s` as a Taylor series up to order `n` in `s`. -/
protected theorem ContDiffOn.ftaylorSeriesWithin
(h : ContDiffOn 𝕜 n f s) (hs : UniqueDiffOn 𝕜 s) :
HasFTaylorSeriesUpToOn n f (ftaylorSeriesWithin 𝕜 f s) s := by
constructor
· intro x _
simp only [ftaylorSeriesWithin, ContinuousMultilinearMap.curry0_apply,
iteratedFDerivWithin_zero_apply]
· intro m hm x hx
have : (m + 1 : ℕ) ≤ n := ENat.add_one_natCast_le_withTop_of_lt hm
rcases (h x hx).of_le this _ le_rfl with ⟨u, hu, p, Hp⟩
rw [insert_eq_of_mem hx] at hu
rcases mem_nhdsWithin.1 hu with ⟨o, o_open, xo, ho⟩
rw [inter_comm] at ho
have : p x m.succ = ftaylorSeriesWithin 𝕜 f s x m.succ := by
change p x m.succ = iteratedFDerivWithin 𝕜 m.succ f s x
rw [← iteratedFDerivWithin_inter_open o_open xo]
exact (Hp.mono ho).eq_iteratedFDerivWithin_of_uniqueDiffOn le_rfl (hs.inter o_open) ⟨hx, xo⟩
rw [← this, ← hasFDerivWithinAt_inter (IsOpen.mem_nhds o_open xo)]
have A : ∀ y ∈ s ∩ o, p y m = ftaylorSeriesWithin 𝕜 f s y m := by
rintro y ⟨hy, yo⟩
change p y m = iteratedFDerivWithin 𝕜 m f s y
rw [← iteratedFDerivWithin_inter_open o_open yo]
exact
(Hp.mono ho).eq_iteratedFDerivWithin_of_uniqueDiffOn (mod_cast Nat.le_succ m)
(hs.inter o_open) ⟨hy, yo⟩
exact
((Hp.mono ho).fderivWithin m (mod_cast lt_add_one m) x ⟨hx, xo⟩).congr
(fun y hy => (A y hy).symm) (A x ⟨hx, xo⟩).symm
· intro m hm
apply continuousOn_of_locally_continuousOn
intro x hx
rcases (h x hx).of_le hm _ le_rfl with ⟨u, hu, p, Hp⟩
rcases mem_nhdsWithin.1 hu with ⟨o, o_open, xo, ho⟩
rw [insert_eq_of_mem hx] at ho
rw [inter_comm] at ho
refine ⟨o, o_open, xo, ?_⟩
have A : ∀ y ∈ s ∩ o, p y m = ftaylorSeriesWithin 𝕜 f s y m := by
rintro y ⟨hy, yo⟩
change p y m = iteratedFDerivWithin 𝕜 m f s y
rw [← iteratedFDerivWithin_inter_open o_open yo]
exact (Hp.mono ho).eq_iteratedFDerivWithin_of_uniqueDiffOn le_rfl (hs.inter o_open) ⟨hy, yo⟩
exact ((Hp.mono ho).cont m le_rfl).congr fun y hy => (A y hy).symm
theorem iteratedFDerivWithin_subset {n : ℕ} (st : s ⊆ t) (hs : UniqueDiffOn 𝕜 s)
(ht : UniqueDiffOn 𝕜 t) (h : ContDiffOn 𝕜 n f t) (hx : x ∈ s) :
iteratedFDerivWithin 𝕜 n f s x = iteratedFDerivWithin 𝕜 n f t x :=
(((h.ftaylorSeriesWithin ht).mono st).eq_iteratedFDerivWithin_of_uniqueDiffOn le_rfl hs hx).symm
theorem ContDiffWithinAt.eventually_hasFTaylorSeriesUpToOn {f : E → F} {s : Set E} {a : E}
(h : ContDiffWithinAt 𝕜 n f s a) (hs : UniqueDiffOn 𝕜 s) (ha : a ∈ s) {m : ℕ} (hm : m ≤ n) :
∀ᶠ t in (𝓝[s] a).smallSets, HasFTaylorSeriesUpToOn m f (ftaylorSeriesWithin 𝕜 f s) t := by
rcases h.contDiffOn' hm (by simp) with ⟨U, hUo, haU, hfU⟩
have : ∀ᶠ t in (𝓝[s] a).smallSets, t ⊆ s ∩ U := by
rw [eventually_smallSets_subset]
exact inter_mem_nhdsWithin _ <| hUo.mem_nhds haU
refine this.mono fun t ht ↦ .mono ?_ ht
rw [insert_eq_of_mem ha] at hfU
refine (hfU.ftaylorSeriesWithin (hs.inter hUo)).congr_series fun k hk x hx ↦ ?_
exact iteratedFDerivWithin_inter_open hUo hx.2
/-- On a set with unique differentiability, an analytic function is automatically `C^ω`, as its
successive derivatives are also analytic. This does not require completeness of the space. See
also `AnalyticOn.contDiffOn_of_completeSpace`. -/
theorem AnalyticOn.contDiffOn (h : AnalyticOn 𝕜 f s) (hs : UniqueDiffOn 𝕜 s) :
ContDiffOn 𝕜 n f s := by
suffices ContDiffOn 𝕜 ω f s from this.of_le le_top
rcases h.exists_hasFTaylorSeriesUpToOn hs with ⟨p, hp⟩
intro x hx
refine ⟨s, ?_, p, hp⟩
rw [insert_eq_of_mem hx]
exact self_mem_nhdsWithin
/-- On a set with unique differentiability, an analytic function is automatically `C^ω`, as its
successive derivatives are also analytic. This does not require completeness of the space. See
also `AnalyticOnNhd.contDiffOn_of_completeSpace`. -/
theorem AnalyticOnNhd.contDiffOn (h : AnalyticOnNhd 𝕜 f s) (hs : UniqueDiffOn 𝕜 s) :
ContDiffOn 𝕜 n f s := h.analyticOn.contDiffOn hs
/-- An analytic function is automatically `C^ω` in a complete space -/
theorem AnalyticOn.contDiffOn_of_completeSpace [CompleteSpace F] (h : AnalyticOn 𝕜 f s) :
ContDiffOn 𝕜 n f s :=
fun x hx ↦ (h x hx).contDiffWithinAt
/-- An analytic function is automatically `C^ω` in a complete space -/
theorem AnalyticOnNhd.contDiffOn_of_completeSpace [CompleteSpace F] (h : AnalyticOnNhd 𝕜 f s) :
ContDiffOn 𝕜 n f s :=
h.analyticOn.contDiffOn_of_completeSpace
theorem contDiffOn_of_continuousOn_differentiableOn {n : ℕ∞}
(Hcont : ∀ m : ℕ, m ≤ n → ContinuousOn (fun x => iteratedFDerivWithin 𝕜 m f s x) s)
(Hdiff : ∀ m : ℕ, m < n →
DifferentiableOn 𝕜 (fun x => iteratedFDerivWithin 𝕜 m f s x) s) :
ContDiffOn 𝕜 n f s := by
intro x hx m hm
rw [insert_eq_of_mem hx]
refine ⟨s, self_mem_nhdsWithin, ftaylorSeriesWithin 𝕜 f s, ?_⟩
constructor
· intro y _
simp only [ftaylorSeriesWithin, ContinuousMultilinearMap.curry0_apply,
iteratedFDerivWithin_zero_apply]
· intro k hk y hy
convert (Hdiff k (lt_of_lt_of_le (mod_cast hk) (mod_cast hm)) y hy).hasFDerivWithinAt
· intro k hk
exact Hcont k (le_trans (mod_cast hk) (mod_cast hm))
theorem contDiffOn_of_differentiableOn {n : ℕ∞}
(h : ∀ m : ℕ, m ≤ n → DifferentiableOn 𝕜 (iteratedFDerivWithin 𝕜 m f s) s) :
ContDiffOn 𝕜 n f s :=
contDiffOn_of_continuousOn_differentiableOn (fun m hm => (h m hm).continuousOn) fun m hm =>
h m (le_of_lt hm)
theorem contDiffOn_of_analyticOn_iteratedFDerivWithin
(h : ∀ m, AnalyticOn 𝕜 (iteratedFDerivWithin 𝕜 m f s) s) :
ContDiffOn 𝕜 n f s := by
suffices ContDiffOn 𝕜 ω f s from this.of_le le_top
intro x hx
refine ⟨insert x s, self_mem_nhdsWithin, ftaylorSeriesWithin 𝕜 f s, ?_, ?_⟩
· rw [insert_eq_of_mem hx]
constructor
· intro y _
simp only [ftaylorSeriesWithin, ContinuousMultilinearMap.curry0_apply,
iteratedFDerivWithin_zero_apply]
· intro k _ y hy
exact ((h k).differentiableOn y hy).hasFDerivWithinAt
· intro k _
exact (h k).continuousOn
· intro i
rw [insert_eq_of_mem hx]
exact h i
theorem contDiffOn_omega_iff_analyticOn (hs : UniqueDiffOn 𝕜 s) :
ContDiffOn 𝕜 ω f s ↔ AnalyticOn 𝕜 f s :=
⟨fun h m ↦ h.analyticOn m, fun h ↦ h.contDiffOn hs⟩
theorem ContDiffOn.continuousOn_iteratedFDerivWithin {m : ℕ} (h : ContDiffOn 𝕜 n f s)
(hmn : m ≤ n) (hs : UniqueDiffOn 𝕜 s) : ContinuousOn (iteratedFDerivWithin 𝕜 m f s) s :=
((h.of_le hmn).ftaylorSeriesWithin hs).cont m le_rfl
theorem ContDiffOn.differentiableOn_iteratedFDerivWithin {m : ℕ} (h : ContDiffOn 𝕜 n f s)
(hmn : m < n) (hs : UniqueDiffOn 𝕜 s) :
DifferentiableOn 𝕜 (iteratedFDerivWithin 𝕜 m f s) s := by
intro x hx
have : (m + 1 : ℕ) ≤ n := ENat.add_one_natCast_le_withTop_of_lt hmn
apply (((h.of_le this).ftaylorSeriesWithin hs).fderivWithin m ?_ x hx).differentiableWithinAt
exact_mod_cast lt_add_one m
theorem ContDiffWithinAt.differentiableWithinAt_iteratedFDerivWithin {m : ℕ}
(h : ContDiffWithinAt 𝕜 n f s x) (hmn : m < n) (hs : UniqueDiffOn 𝕜 (insert x s)) :
DifferentiableWithinAt 𝕜 (iteratedFDerivWithin 𝕜 m f s) s x := by
have : (m + 1 : WithTop ℕ∞) ≠ ∞ := Ne.symm (ne_of_beq_false rfl)
rcases h.contDiffOn' (ENat.add_one_natCast_le_withTop_of_lt hmn) (by simp [this])
with ⟨u, uo, xu, hu⟩
set t := insert x s ∩ u
have A : t =ᶠ[𝓝[≠] x] s := by
simp only [set_eventuallyEq_iff_inf_principal, ← nhdsWithin_inter']
rw [← inter_assoc, nhdsWithin_inter_of_mem', ← diff_eq_compl_inter, insert_diff_of_mem,
diff_eq_compl_inter]
exacts [rfl, mem_nhdsWithin_of_mem_nhds (uo.mem_nhds xu)]
have B : iteratedFDerivWithin 𝕜 m f s =ᶠ[𝓝 x] iteratedFDerivWithin 𝕜 m f t :=
iteratedFDerivWithin_eventually_congr_set' _ A.symm _
have C : DifferentiableWithinAt 𝕜 (iteratedFDerivWithin 𝕜 m f t) t x :=
hu.differentiableOn_iteratedFDerivWithin (Nat.cast_lt.2 m.lt_succ_self) (hs.inter uo) x
⟨mem_insert _ _, xu⟩
rw [differentiableWithinAt_congr_set' _ A] at C
exact C.congr_of_eventuallyEq (B.filter_mono inf_le_left) B.self_of_nhds
theorem contDiffOn_iff_continuousOn_differentiableOn {n : ℕ∞} (hs : UniqueDiffOn 𝕜 s) :
ContDiffOn 𝕜 n f s ↔
(∀ m : ℕ, m ≤ n → ContinuousOn (fun x => iteratedFDerivWithin 𝕜 m f s x) s) ∧
∀ m : ℕ, m < n → DifferentiableOn 𝕜 (fun x => iteratedFDerivWithin 𝕜 m f s x) s :=
⟨fun h => ⟨fun _m hm => h.continuousOn_iteratedFDerivWithin (mod_cast hm) hs,
fun _m hm => h.differentiableOn_iteratedFDerivWithin (mod_cast hm) hs⟩,
fun h => contDiffOn_of_continuousOn_differentiableOn h.1 h.2⟩
theorem contDiffOn_nat_iff_continuousOn_differentiableOn {n : ℕ} (hs : UniqueDiffOn 𝕜 s) :
ContDiffOn 𝕜 n f s ↔
(∀ m : ℕ, m ≤ n → ContinuousOn (fun x => iteratedFDerivWithin 𝕜 m f s x) s) ∧
∀ m : ℕ, m < n → DifferentiableOn 𝕜 (fun x => iteratedFDerivWithin 𝕜 m f s x) s := by
rw [← WithTop.coe_natCast, contDiffOn_iff_continuousOn_differentiableOn hs]
simp
theorem contDiffOn_succ_of_fderivWithin (hf : DifferentiableOn 𝕜 f s)
(h' : n = ω → AnalyticOn 𝕜 f s)
(h : ContDiffOn 𝕜 n (fun y => fderivWithin 𝕜 f s y) s) : ContDiffOn 𝕜 (n + 1) f s := by
rcases eq_or_ne n ∞ with rfl | hn
· rw [ENat.coe_top_add_one, contDiffOn_infty]
intro m x hx
apply ContDiffWithinAt.of_le _ (show (m : WithTop ℕ∞) ≤ m + 1 from le_self_add)
rw [contDiffWithinAt_succ_iff_hasFDerivWithinAt (by simp),
insert_eq_of_mem hx]
exact ⟨s, self_mem_nhdsWithin, (by simp), fderivWithin 𝕜 f s,
fun y hy => (hf y hy).hasFDerivWithinAt, (h x hx).of_le (mod_cast le_top)⟩
· intro x hx
rw [contDiffWithinAt_succ_iff_hasFDerivWithinAt hn,
insert_eq_of_mem hx]
exact ⟨s, self_mem_nhdsWithin, h', fderivWithin 𝕜 f s,
fun y hy => (hf y hy).hasFDerivWithinAt, h x hx⟩
theorem contDiffOn_of_analyticOn_of_fderivWithin (hf : AnalyticOn 𝕜 f s)
(h : ContDiffOn 𝕜 ω (fun y ↦ fderivWithin 𝕜 f s y) s) : ContDiffOn 𝕜 n f s := by
suffices ContDiffOn 𝕜 (ω + 1) f s from this.of_le le_top
exact contDiffOn_succ_of_fderivWithin hf.differentiableOn (fun _ ↦ hf) h
/-- A function is `C^(n + 1)` on a domain with unique derivatives if and only if it is
differentiable there, and its derivative (expressed with `fderivWithin`) is `C^n`. -/
theorem contDiffOn_succ_iff_fderivWithin (hs : UniqueDiffOn 𝕜 s) :
ContDiffOn 𝕜 (n + 1) f s ↔
DifferentiableOn 𝕜 f s ∧ (n = ω → AnalyticOn 𝕜 f s) ∧
ContDiffOn 𝕜 n (fderivWithin 𝕜 f s) s := by
refine ⟨fun H => ?_, fun h => contDiffOn_succ_of_fderivWithin h.1 h.2.1 h.2.2⟩
refine ⟨H.differentiableOn le_add_self, ?_, fun x hx => ?_⟩
· rintro rfl
exact H.analyticOn
have A (m : ℕ) (hm : m ≤ n) : ContDiffWithinAt 𝕜 m (fun y => fderivWithin 𝕜 f s y) s x := by
rcases (contDiffWithinAt_succ_iff_hasFDerivWithinAt (n := m) (ne_of_beq_false rfl)).1
(H.of_le (add_le_add_right hm 1) x hx) with ⟨u, hu, -, f', hff', hf'⟩
rcases mem_nhdsWithin.1 hu with ⟨o, o_open, xo, ho⟩
rw [inter_comm, insert_eq_of_mem hx] at ho
have := hf'.mono ho
rw [contDiffWithinAt_inter' (mem_nhdsWithin_of_mem_nhds (IsOpen.mem_nhds o_open xo))] at this
apply this.congr_of_eventuallyEq_of_mem _ hx
have : o ∩ s ∈ 𝓝[s] x := mem_nhdsWithin.2 ⟨o, o_open, xo, Subset.refl _⟩
rw [inter_comm] at this
refine Filter.eventuallyEq_of_mem this fun y hy => ?_
have A : fderivWithin 𝕜 f (s ∩ o) y = f' y :=
((hff' y (ho hy)).mono ho).fderivWithin (hs.inter o_open y hy)
rwa [fderivWithin_inter (o_open.mem_nhds hy.2)] at A
match n with
| ω => exact (H.analyticOn.fderivWithin hs).contDiffOn hs (n := ω) x hx
| ∞ => exact contDiffWithinAt_infty.2 (fun m ↦ A m (mod_cast le_top))
| (n : ℕ) => exact A n le_rfl
theorem contDiffOn_succ_iff_hasFDerivWithinAt_of_uniqueDiffOn (hs : UniqueDiffOn 𝕜 s) :
ContDiffOn 𝕜 (n + 1) f s ↔ (n = ω → AnalyticOn 𝕜 f s) ∧
∃ f' : E → E →L[𝕜] F, ContDiffOn 𝕜 n f' s ∧ ∀ x, x ∈ s → HasFDerivWithinAt f (f' x) s x := by
rw [contDiffOn_succ_iff_fderivWithin hs]
refine ⟨fun h => ⟨h.2.1, fderivWithin 𝕜 f s, h.2.2,
fun x hx => (h.1 x hx).hasFDerivWithinAt⟩, fun ⟨f_an, h⟩ => ?_⟩
rcases h with ⟨f', h1, h2⟩
refine ⟨fun x hx => (h2 x hx).differentiableWithinAt, f_an, fun x hx => ?_⟩
exact (h1 x hx).congr_of_mem (fun y hy => (h2 y hy).fderivWithin (hs y hy)) hx
@[deprecated (since := "2024-11-27")]
alias contDiffOn_succ_iff_hasFDerivWithin := contDiffOn_succ_iff_hasFDerivWithinAt_of_uniqueDiffOn
theorem contDiffOn_infty_iff_fderivWithin (hs : UniqueDiffOn 𝕜 s) :
ContDiffOn 𝕜 ∞ f s ↔ DifferentiableOn 𝕜 f s ∧ ContDiffOn 𝕜 ∞ (fderivWithin 𝕜 f s) s := by
rw [← ENat.coe_top_add_one, contDiffOn_succ_iff_fderivWithin hs]
simp
@[deprecated (since := "2024-11-27")]
alias contDiffOn_top_iff_fderivWithin := contDiffOn_infty_iff_fderivWithin
/-- A function is `C^(n + 1)` on an open domain if and only if it is
differentiable there, and its derivative (expressed with `fderiv`) is `C^n`. -/
theorem contDiffOn_succ_iff_fderiv_of_isOpen (hs : IsOpen s) :
ContDiffOn 𝕜 (n + 1) f s ↔
DifferentiableOn 𝕜 f s ∧ (n = ω → AnalyticOn 𝕜 f s) ∧
ContDiffOn 𝕜 n (fderiv 𝕜 f) s := by
rw [contDiffOn_succ_iff_fderivWithin hs.uniqueDiffOn,
contDiffOn_congr fun x hx ↦ fderivWithin_of_isOpen hs hx]
theorem contDiffOn_infty_iff_fderiv_of_isOpen (hs : IsOpen s) :
ContDiffOn 𝕜 ∞ f s ↔ DifferentiableOn 𝕜 f s ∧ ContDiffOn 𝕜 ∞ (fderiv 𝕜 f) s := by
rw [← ENat.coe_top_add_one, contDiffOn_succ_iff_fderiv_of_isOpen hs]
simp
@[deprecated (since := "2024-11-27")]
alias contDiffOn_top_iff_fderiv_of_isOpen := contDiffOn_infty_iff_fderiv_of_isOpen
protected theorem ContDiffOn.fderivWithin (hf : ContDiffOn 𝕜 n f s) (hs : UniqueDiffOn 𝕜 s)
(hmn : m + 1 ≤ n) : ContDiffOn 𝕜 m (fderivWithin 𝕜 f s) s :=
((contDiffOn_succ_iff_fderivWithin hs).1 (hf.of_le hmn)).2.2
theorem ContDiffOn.fderiv_of_isOpen (hf : ContDiffOn 𝕜 n f s) (hs : IsOpen s) (hmn : m + 1 ≤ n) :
ContDiffOn 𝕜 m (fderiv 𝕜 f) s :=
(hf.fderivWithin hs.uniqueDiffOn hmn).congr fun _ hx => (fderivWithin_of_isOpen hs hx).symm
theorem ContDiffOn.continuousOn_fderivWithin (h : ContDiffOn 𝕜 n f s) (hs : UniqueDiffOn 𝕜 s)
(hn : 1 ≤ n) : ContinuousOn (fderivWithin 𝕜 f s) s :=
((contDiffOn_succ_iff_fderivWithin hs).1
(h.of_le (show 0 + (1 : WithTop ℕ∞) ≤ n from hn))).2.2.continuousOn
theorem ContDiffOn.continuousOn_fderiv_of_isOpen (h : ContDiffOn 𝕜 n f s) (hs : IsOpen s)
(hn : 1 ≤ n) : ContinuousOn (fderiv 𝕜 f) s :=
((contDiffOn_succ_iff_fderiv_of_isOpen hs).1
(h.of_le (show 0 + (1 : WithTop ℕ∞) ≤ n from hn))).2.2.continuousOn
/-! ### Smooth functions at a point -/
variable (𝕜) in
/-- A function is continuously differentiable up to `n` at a point `x` if, for any integer `k ≤ n`,
there is a neighborhood of `x` where `f` admits derivatives up to order `n`, which are continuous.
-/
def ContDiffAt (n : WithTop ℕ∞) (f : E → F) (x : E) : Prop :=
ContDiffWithinAt 𝕜 n f univ x
theorem contDiffWithinAt_univ : ContDiffWithinAt 𝕜 n f univ x ↔ ContDiffAt 𝕜 n f x :=
Iff.rfl
theorem contDiffAt_infty : ContDiffAt 𝕜 ∞ f x ↔ ∀ n : ℕ, ContDiffAt 𝕜 n f x := by
simp [← contDiffWithinAt_univ, contDiffWithinAt_infty]
@[deprecated (since := "2024-11-27")] alias contDiffAt_top := contDiffAt_infty
theorem ContDiffAt.contDiffWithinAt (h : ContDiffAt 𝕜 n f x) : ContDiffWithinAt 𝕜 n f s x :=
h.mono (subset_univ _)
theorem ContDiffWithinAt.contDiffAt (h : ContDiffWithinAt 𝕜 n f s x) (hx : s ∈ 𝓝 x) :
ContDiffAt 𝕜 n f x := by rwa [ContDiffAt, ← contDiffWithinAt_inter hx, univ_inter]
theorem contDiffWithinAt_iff_contDiffAt (h : s ∈ 𝓝 x) :
ContDiffWithinAt 𝕜 n f s x ↔ ContDiffAt 𝕜 n f x := by
rw [← univ_inter s, contDiffWithinAt_inter h, contDiffWithinAt_univ]
theorem IsOpen.contDiffOn_iff (hs : IsOpen s) :
ContDiffOn 𝕜 n f s ↔ ∀ ⦃a⦄, a ∈ s → ContDiffAt 𝕜 n f a :=
forall₂_congr fun _ => contDiffWithinAt_iff_contDiffAt ∘ hs.mem_nhds
theorem ContDiffOn.contDiffAt (h : ContDiffOn 𝕜 n f s) (hx : s ∈ 𝓝 x) :
ContDiffAt 𝕜 n f x :=
(h _ (mem_of_mem_nhds hx)).contDiffAt hx
theorem ContDiffAt.congr_of_eventuallyEq (h : ContDiffAt 𝕜 n f x) (hg : f₁ =ᶠ[𝓝 x] f) :
ContDiffAt 𝕜 n f₁ x :=
h.congr_of_eventuallyEq_of_mem (by rwa [nhdsWithin_univ]) (mem_univ x)
theorem ContDiffAt.of_le (h : ContDiffAt 𝕜 n f x) (hmn : m ≤ n) : ContDiffAt 𝕜 m f x :=
ContDiffWithinAt.of_le h hmn
theorem ContDiffAt.continuousAt (h : ContDiffAt 𝕜 n f x) : ContinuousAt f x := by
| simpa [continuousWithinAt_univ] using h.continuousWithinAt
theorem ContDiffAt.analyticAt (h : ContDiffAt 𝕜 ω f x) : AnalyticAt 𝕜 f x := by
rw [← contDiffWithinAt_univ] at h
rw [← analyticWithinAt_univ]
exact h.analyticWithinAt
| Mathlib/Analysis/Calculus/ContDiff/Defs.lean | 955 | 961 |
/-
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, Yaël Dillies
-/
import Mathlib.Algebra.Order.Group.DenselyOrdered
import Mathlib.Data.Real.Archimedean
import Mathlib.Order.LiminfLimsup
import Mathlib.Topology.Order.Monotone
import Mathlib.Topology.Algebra.Group.Basic
/-!
# Lemmas about liminf and limsup in an order topology.
## Main declarations
* `BoundedLENhdsClass`: Typeclass stating that neighborhoods are eventually bounded above.
* `BoundedGENhdsClass`: Typeclass stating that neighborhoods are eventually bounded below.
## Implementation notes
The same lemmas are true in `ℝ`, `ℝ × ℝ`, `ι → ℝ`, `EuclideanSpace ι ℝ`. To avoid code
duplication, we provide an ad hoc axiomatisation of the properties we need.
-/
open Filter TopologicalSpace
open scoped Topology
universe u v
variable {ι α β R S : Type*} {π : ι → Type*}
/-- Ad hoc typeclass stating that neighborhoods are eventually bounded above. -/
class BoundedLENhdsClass (α : Type*) [Preorder α] [TopologicalSpace α] : Prop where
isBounded_le_nhds (a : α) : (𝓝 a).IsBounded (· ≤ ·)
/-- Ad hoc typeclass stating that neighborhoods are eventually bounded below. -/
class BoundedGENhdsClass (α : Type*) [Preorder α] [TopologicalSpace α] : Prop where
isBounded_ge_nhds (a : α) : (𝓝 a).IsBounded (· ≥ ·)
section Preorder
variable [Preorder α] [Preorder β] [TopologicalSpace α] [TopologicalSpace β]
section BoundedLENhdsClass
variable [BoundedLENhdsClass α] [BoundedLENhdsClass β] {f : Filter ι} {u : ι → α} {a : α}
theorem isBounded_le_nhds (a : α) : (𝓝 a).IsBounded (· ≤ ·) :=
BoundedLENhdsClass.isBounded_le_nhds _
theorem Filter.Tendsto.isBoundedUnder_le (h : Tendsto u f (𝓝 a)) : f.IsBoundedUnder (· ≤ ·) u :=
(isBounded_le_nhds a).mono h
theorem Filter.Tendsto.bddAbove_range_of_cofinite [IsDirected α (· ≤ ·)]
(h : Tendsto u cofinite (𝓝 a)) : BddAbove (Set.range u) :=
h.isBoundedUnder_le.bddAbove_range_of_cofinite
theorem Filter.Tendsto.bddAbove_range [IsDirected α (· ≤ ·)] {u : ℕ → α}
(h : Tendsto u atTop (𝓝 a)) : BddAbove (Set.range u) :=
h.isBoundedUnder_le.bddAbove_range
theorem isCobounded_ge_nhds (a : α) : (𝓝 a).IsCobounded (· ≥ ·) :=
(isBounded_le_nhds a).isCobounded_flip
theorem Filter.Tendsto.isCoboundedUnder_ge [NeBot f] (h : Tendsto u f (𝓝 a)) :
f.IsCoboundedUnder (· ≥ ·) u :=
h.isBoundedUnder_le.isCobounded_flip
instance : BoundedGENhdsClass αᵒᵈ := ⟨@isBounded_le_nhds α _ _ _⟩
instance Prod.instBoundedLENhdsClass : BoundedLENhdsClass (α × β) := by
refine ⟨fun x ↦ ?_⟩
obtain ⟨a, ha⟩ := isBounded_le_nhds x.1
obtain ⟨b, hb⟩ := isBounded_le_nhds x.2
rw [← @Prod.mk.eta _ _ x, nhds_prod_eq]
exact ⟨(a, b), ha.prod_mk hb⟩
instance Pi.instBoundedLENhdsClass [Finite ι] [∀ i, Preorder (π i)] [∀ i, TopologicalSpace (π i)]
[∀ i, BoundedLENhdsClass (π i)] : BoundedLENhdsClass (∀ i, π i) := by
refine ⟨fun x ↦ ?_⟩
rw [nhds_pi]
choose f hf using fun i ↦ isBounded_le_nhds (x i)
exact ⟨f, eventually_pi hf⟩
end BoundedLENhdsClass
section BoundedGENhdsClass
variable [BoundedGENhdsClass α] [BoundedGENhdsClass β] {f : Filter ι} {u : ι → α} {a : α}
theorem isBounded_ge_nhds (a : α) : (𝓝 a).IsBounded (· ≥ ·) :=
BoundedGENhdsClass.isBounded_ge_nhds _
theorem Filter.Tendsto.isBoundedUnder_ge (h : Tendsto u f (𝓝 a)) : f.IsBoundedUnder (· ≥ ·) u :=
(isBounded_ge_nhds a).mono h
theorem Filter.Tendsto.bddBelow_range_of_cofinite [IsDirected α (· ≥ ·)]
(h : Tendsto u cofinite (𝓝 a)) : BddBelow (Set.range u) :=
h.isBoundedUnder_ge.bddBelow_range_of_cofinite
theorem Filter.Tendsto.bddBelow_range [IsDirected α (· ≥ ·)] {u : ℕ → α}
(h : Tendsto u atTop (𝓝 a)) : BddBelow (Set.range u) :=
h.isBoundedUnder_ge.bddBelow_range
theorem isCobounded_le_nhds (a : α) : (𝓝 a).IsCobounded (· ≤ ·) :=
(isBounded_ge_nhds a).isCobounded_flip
theorem Filter.Tendsto.isCoboundedUnder_le [NeBot f] (h : Tendsto u f (𝓝 a)) :
f.IsCoboundedUnder (· ≤ ·) u :=
h.isBoundedUnder_ge.isCobounded_flip
instance : BoundedLENhdsClass αᵒᵈ := ⟨@isBounded_ge_nhds α _ _ _⟩
instance Prod.instBoundedGENhdsClass : BoundedGENhdsClass (α × β) :=
⟨(Prod.instBoundedLENhdsClass (α := αᵒᵈ) (β := βᵒᵈ)).isBounded_le_nhds⟩
instance Pi.instBoundedGENhdsClass [Finite ι] [∀ i, Preorder (π i)] [∀ i, TopologicalSpace (π i)]
[∀ i, BoundedGENhdsClass (π i)] : BoundedGENhdsClass (∀ i, π i) :=
⟨(Pi.instBoundedLENhdsClass (π := fun i ↦ (π i)ᵒᵈ)).isBounded_le_nhds⟩
end BoundedGENhdsClass
-- See note [lower instance priority]
instance (priority := 100) OrderTop.to_BoundedLENhdsClass [OrderTop α] : BoundedLENhdsClass α :=
⟨fun _a ↦ isBounded_le_of_top⟩
-- See note [lower instance priority]
instance (priority := 100) OrderBot.to_BoundedGENhdsClass [OrderBot α] : BoundedGENhdsClass α :=
⟨fun _a ↦ isBounded_ge_of_bot⟩
end Preorder
-- See note [lower instance priority]
instance (priority := 100) BoundedLENhdsClass.of_closedIciTopology [LinearOrder α]
[TopologicalSpace α] [ClosedIciTopology α] : BoundedLENhdsClass α :=
⟨fun a ↦ ((isTop_or_exists_gt a).elim fun h ↦ ⟨a, Eventually.of_forall h⟩) <|
Exists.imp fun _b ↦ eventually_le_nhds⟩
-- See note [lower instance priority]
instance (priority := 100) BoundedGENhdsClass.of_closedIicTopology [LinearOrder α]
[TopologicalSpace α] [ClosedIicTopology α] : BoundedGENhdsClass α :=
inferInstanceAs <| BoundedGENhdsClass αᵒᵈᵒᵈ
section LiminfLimsup
section ConditionallyCompleteLinearOrder
variable [ConditionallyCompleteLinearOrder α] [TopologicalSpace α] [OrderTopology α]
/-- If the liminf and the limsup of a filter coincide, then this filter converges to
their common value, at least if the filter is eventually bounded above and below. -/
theorem le_nhds_of_limsSup_eq_limsInf {f : Filter α} {a : α} (hl : f.IsBounded (· ≤ ·))
(hg : f.IsBounded (· ≥ ·)) (hs : f.limsSup = a) (hi : f.limsInf = a) : f ≤ 𝓝 a :=
tendsto_order.2 ⟨fun _ hb ↦ gt_mem_sets_of_limsInf_gt hg <| hi.symm ▸ hb,
fun _ hb ↦ lt_mem_sets_of_limsSup_lt hl <| hs.symm ▸ hb⟩
theorem limsSup_nhds (a : α) : limsSup (𝓝 a) = a :=
csInf_eq_of_forall_ge_of_forall_gt_exists_lt (isBounded_le_nhds a)
(fun a' (h : { n : α | n ≤ a' } ∈ 𝓝 a) ↦ show a ≤ a' from @mem_of_mem_nhds _ _ a _ h)
fun b (hba : a < b) ↦
show ∃ c, { n : α | n ≤ c } ∈ 𝓝 a ∧ c < b from
match dense_or_discrete a b with
| Or.inl ⟨c, hac, hcb⟩ => ⟨c, ge_mem_nhds hac, hcb⟩
| Or.inr ⟨_, h⟩ => ⟨a, (𝓝 a).sets_of_superset (gt_mem_nhds hba) h, hba⟩
theorem limsInf_nhds (a : α) : limsInf (𝓝 a) = a :=
limsSup_nhds (α := αᵒᵈ) a
/-- If a filter is converging, its limsup coincides with its limit. -/
theorem limsInf_eq_of_le_nhds {f : Filter α} {a : α} [NeBot f] (h : f ≤ 𝓝 a) : f.limsInf = a :=
have hb_ge : IsBounded (· ≥ ·) f := (isBounded_ge_nhds a).mono h
have hb_le : IsBounded (· ≤ ·) f := (isBounded_le_nhds a).mono h
le_antisymm
(calc
f.limsInf ≤ f.limsSup := limsInf_le_limsSup hb_le hb_ge
_ ≤ (𝓝 a).limsSup := limsSup_le_limsSup_of_le h hb_ge.isCobounded_flip (isBounded_le_nhds a)
_ = a := limsSup_nhds a)
(calc
a = (𝓝 a).limsInf := (limsInf_nhds a).symm
_ ≤ f.limsInf := limsInf_le_limsInf_of_le h (isBounded_ge_nhds a) hb_le.isCobounded_flip)
/-- If a filter is converging, its liminf coincides with its limit. -/
theorem limsSup_eq_of_le_nhds {f : Filter α} {a : α} [NeBot f] (h : f ≤ 𝓝 a) : f.limsSup = a :=
limsInf_eq_of_le_nhds (α := αᵒᵈ) h
/-- If a function has a limit, then its limsup coincides with its limit. -/
theorem Filter.Tendsto.limsup_eq {f : Filter β} {u : β → α} {a : α} [NeBot f]
(h : Tendsto u f (𝓝 a)) : limsup u f = a :=
limsSup_eq_of_le_nhds h
/-- If a function has a limit, then its liminf coincides with its limit. -/
theorem Filter.Tendsto.liminf_eq {f : Filter β} {u : β → α} {a : α} [NeBot f]
(h : Tendsto u f (𝓝 a)) : liminf u f = a :=
limsInf_eq_of_le_nhds h
/-- If the liminf and the limsup of a function coincide, then the limit of the function
exists and has the same value. -/
theorem tendsto_of_liminf_eq_limsup {f : Filter β} {u : β → α} {a : α} (hinf : liminf u f = a)
(hsup : limsup u f = a) (h : f.IsBoundedUnder (· ≤ ·) u := by isBoundedDefault)
(h' : f.IsBoundedUnder (· ≥ ·) u := by isBoundedDefault) : Tendsto u f (𝓝 a) :=
le_nhds_of_limsSup_eq_limsInf h h' hsup hinf
/-- If a number `a` is less than or equal to the `liminf` of a function `f` at some filter
and is greater than or equal to the `limsup` of `f`, then `f` tends to `a` along this filter. -/
theorem tendsto_of_le_liminf_of_limsup_le {f : Filter β} {u : β → α} {a : α} (hinf : a ≤ liminf u f)
(hsup : limsup u f ≤ a) (h : f.IsBoundedUnder (· ≤ ·) u := by isBoundedDefault)
(h' : f.IsBoundedUnder (· ≥ ·) u := by isBoundedDefault) : Tendsto u f (𝓝 a) := by
rcases f.eq_or_neBot with rfl | _
· exact tendsto_bot
· exact tendsto_of_liminf_eq_limsup (le_antisymm (le_trans (liminf_le_limsup h h') hsup) hinf)
(le_antisymm hsup (le_trans hinf (liminf_le_limsup h h'))) h h'
/-- Assume that, for any `a < b`, a sequence can not be infinitely many times below `a` and
above `b`. If it is also ultimately bounded above and below, then it has to converge. This even
works if `a` and `b` are restricted to a dense subset.
-/
theorem tendsto_of_no_upcrossings [DenselyOrdered α] {f : Filter β} {u : β → α} {s : Set α}
(hs : Dense s) (H : ∀ a ∈ s, ∀ b ∈ s, a < b → ¬((∃ᶠ n in f, u n < a) ∧ ∃ᶠ n in f, b < u n))
(h : f.IsBoundedUnder (· ≤ ·) u := by isBoundedDefault)
(h' : f.IsBoundedUnder (· ≥ ·) u := by isBoundedDefault) :
∃ c : α, Tendsto u f (𝓝 c) := by
rcases f.eq_or_neBot with rfl | hbot
· exact ⟨sInf ∅, tendsto_bot⟩
refine ⟨limsup u f, ?_⟩
apply tendsto_of_le_liminf_of_limsup_le _ le_rfl h h'
by_contra! hlt
obtain ⟨a, ⟨⟨la, au⟩, as⟩⟩ : ∃ a, (f.liminf u < a ∧ a < f.limsup u) ∧ a ∈ s :=
dense_iff_inter_open.1 hs (Set.Ioo (f.liminf u) (f.limsup u)) isOpen_Ioo
(Set.nonempty_Ioo.2 hlt)
obtain ⟨b, ⟨⟨ab, bu⟩, bs⟩⟩ : ∃ b, (a < b ∧ b < f.limsup u) ∧ b ∈ s :=
dense_iff_inter_open.1 hs (Set.Ioo a (f.limsup u)) isOpen_Ioo (Set.nonempty_Ioo.2 au)
have A : ∃ᶠ n in f, u n < a := frequently_lt_of_liminf_lt (IsBounded.isCobounded_ge h) la
have B : ∃ᶠ n in f, b < u n := frequently_lt_of_lt_limsup (IsBounded.isCobounded_le h') bu
exact H a as b bs ab ⟨A, B⟩
variable [FirstCountableTopology α] {f : Filter β} [CountableInterFilter f] {u : β → α}
theorem eventually_le_limsup (hf : IsBoundedUnder (· ≤ ·) f u := by isBoundedDefault) :
∀ᶠ b in f, u b ≤ f.limsup u := by
obtain ha | ha := isTop_or_exists_gt (f.limsup u)
· exact Eventually.of_forall fun _ => ha _
by_cases H : IsGLB (Set.Ioi (f.limsup u)) (f.limsup u)
· obtain ⟨u, -, -, hua, hu⟩ := H.exists_seq_antitone_tendsto ha
have := fun n => eventually_lt_of_limsup_lt (hu n) hf
exact
(eventually_countable_forall.2 this).mono fun b hb =>
ge_of_tendsto hua <| Eventually.of_forall fun n => (hb _).le
· obtain ⟨x, hx, xa⟩ : ∃ x, (∀ ⦃b⦄, f.limsup u < b → x ≤ b) ∧ f.limsup u < x := by
simp only [IsGLB, IsGreatest, lowerBounds, upperBounds, Set.mem_Ioi, Set.mem_setOf_eq,
not_and, not_forall, not_le, exists_prop] at H
exact H fun x => le_of_lt
filter_upwards [eventually_lt_of_limsup_lt xa hf] with y hy
contrapose! hy
exact hx hy
theorem eventually_liminf_le (hf : IsBoundedUnder (· ≥ ·) f u := by isBoundedDefault) :
∀ᶠ b in f, f.liminf u ≤ u b :=
eventually_le_limsup (α := αᵒᵈ) hf
end ConditionallyCompleteLinearOrder
section CompleteLinearOrder
variable [CompleteLinearOrder α] [TopologicalSpace α] [FirstCountableTopology α] [OrderTopology α]
{f : Filter β} [CountableInterFilter f] {u : β → α}
@[simp]
theorem limsup_eq_bot : f.limsup u = ⊥ ↔ u =ᶠ[f] ⊥ :=
⟨fun h =>
(EventuallyLE.trans eventually_le_limsup <| Eventually.of_forall fun _ => h.le).mono fun _ hx =>
le_antisymm hx bot_le,
fun h => by
rw [limsup_congr h]
exact limsup_const_bot⟩
@[simp]
theorem liminf_eq_top : f.liminf u = ⊤ ↔ u =ᶠ[f] ⊤ :=
limsup_eq_bot (α := αᵒᵈ)
end CompleteLinearOrder
end LiminfLimsup
section Monotone
variable {F : Filter ι} [NeBot F]
[ConditionallyCompleteLinearOrder R] [TopologicalSpace R] [OrderTopology R]
[ConditionallyCompleteLinearOrder S] [TopologicalSpace S] [OrderTopology S]
/-- An antitone function between (conditionally) complete linear ordered spaces sends a
`Filter.limsSup` to the `Filter.liminf` of the image if the function is continuous at the `limsSup`
(and the filter is bounded from above and frequently bounded from below). -/
theorem Antitone.map_limsSup_of_continuousAt {F : Filter R} [NeBot F] {f : R → S}
(f_decr : Antitone f) (f_cont : ContinuousAt f F.limsSup)
(bdd_above : F.IsBounded (· ≤ ·) := by isBoundedDefault)
(cobdd : F.IsCobounded (· ≤ ·) := by isBoundedDefault) :
f F.limsSup = F.liminf f := by
apply le_antisymm
· rw [limsSup, f_decr.map_csInf_of_continuousAt f_cont bdd_above cobdd]
apply le_of_forall_lt
intro c hc
simp only [liminf, limsInf, eventually_map] at hc ⊢
obtain ⟨d, hd, h'd⟩ :=
exists_lt_of_lt_csSup (bdd_above.recOn fun x hx ↦ ⟨f x, Set.mem_image_of_mem f hx⟩) hc
apply lt_csSup_of_lt ?_ ?_ h'd
· simpa only [BddAbove, upperBounds]
using Antitone.isCoboundedUnder_ge_of_isCobounded f_decr cobdd
· rcases hd with ⟨e, ⟨he, fe_eq_d⟩⟩
filter_upwards [he] with x hx using (fe_eq_d.symm ▸ f_decr hx)
· by_cases h' : ∃ c, c < F.limsSup ∧ Set.Ioo c F.limsSup = ∅
· rcases h' with ⟨c, c_lt, hc⟩
have B : ∃ᶠ n in F, F.limsSup ≤ n := by
apply (frequently_lt_of_lt_limsSup cobdd c_lt).mono
| intro x hx
by_contra!
have : (Set.Ioo c F.limsSup).Nonempty := ⟨x, ⟨hx, this⟩⟩
simp only [hc, Set.not_nonempty_empty] at this
apply liminf_le_of_frequently_le _ (bdd_above.isBoundedUnder f_decr)
exact B.mono fun x hx ↦ f_decr hx
push_neg at h'
| Mathlib/Topology/Algebra/Order/LiminfLimsup.lean | 312 | 318 |
/-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Andrew Zipperer, Haitao Zhang, Minchao Wu, Yury Kudryashov
-/
import Mathlib.Data.Set.Prod
import Mathlib.Data.Set.Restrict
/-!
# Functions over sets
This file contains basic results on the following predicates of functions and sets:
* `Set.EqOn f₁ f₂ s` : functions `f₁` and `f₂` are equal at every point of `s`;
* `Set.MapsTo f s t` : `f` sends every point of `s` to a point of `t`;
* `Set.InjOn f s` : restriction of `f` to `s` is injective;
* `Set.SurjOn f s t` : every point in `s` has a preimage in `s`;
* `Set.BijOn f s t` : `f` is a bijection between `s` and `t`;
* `Set.LeftInvOn f' f s` : for every `x ∈ s` we have `f' (f x) = x`;
* `Set.RightInvOn f' f t` : for every `y ∈ t` we have `f (f' y) = y`;
* `Set.InvOn f' f s t` : `f'` is a two-side inverse of `f` on `s` and `t`, i.e.
we have `Set.LeftInvOn f' f s` and `Set.RightInvOn f' f t`.
-/
variable {α β γ δ : Type*} {ι : Sort*} {π : α → Type*}
open Equiv Equiv.Perm Function
namespace Set
/-! ### Equality on a set -/
section equality
variable {s s₁ s₂ : Set α} {f₁ f₂ f₃ : α → β} {g : β → γ} {a : α}
/-- This lemma exists for use by `aesop` as a forward rule. -/
@[aesop safe forward]
lemma EqOn.eq_of_mem (h : s.EqOn f₁ f₂) (ha : a ∈ s) : f₁ a = f₂ a :=
h ha
@[simp]
theorem eqOn_empty (f₁ f₂ : α → β) : EqOn f₁ f₂ ∅ := fun _ => False.elim
@[simp]
theorem eqOn_singleton : Set.EqOn f₁ f₂ {a} ↔ f₁ a = f₂ a := by
simp [Set.EqOn]
@[simp]
theorem eqOn_univ (f₁ f₂ : α → β) : EqOn f₁ f₂ univ ↔ f₁ = f₂ := by
simp [EqOn, funext_iff]
@[symm]
theorem EqOn.symm (h : EqOn f₁ f₂ s) : EqOn f₂ f₁ s := fun _ hx => (h hx).symm
theorem eqOn_comm : EqOn f₁ f₂ s ↔ EqOn f₂ f₁ s :=
⟨EqOn.symm, EqOn.symm⟩
-- This can not be tagged as `@[refl]` with the current argument order.
-- See note below at `EqOn.trans`.
theorem eqOn_refl (f : α → β) (s : Set α) : EqOn f f s := fun _ _ => rfl
-- Note: this was formerly tagged with `@[trans]`, and although the `trans` attribute accepted it
-- the `trans` tactic could not use it.
-- An update to the trans tactic coming in https://github.com/leanprover-community/mathlib4/pull/7014 will reject this attribute.
-- It can be restored by changing the argument order from `EqOn f₁ f₂ s` to `EqOn s f₁ f₂`.
-- This change will be made separately: [zulip](https://leanprover.zulipchat.com/#narrow/stream/287929-mathlib4/topic/Reordering.20arguments.20of.20.60Set.2EEqOn.60/near/390467581).
theorem EqOn.trans (h₁ : EqOn f₁ f₂ s) (h₂ : EqOn f₂ f₃ s) : EqOn f₁ f₃ s := fun _ hx =>
(h₁ hx).trans (h₂ hx)
theorem EqOn.image_eq (heq : EqOn f₁ f₂ s) : f₁ '' s = f₂ '' s :=
image_congr heq
/-- Variant of `EqOn.image_eq`, for one function being the identity. -/
theorem EqOn.image_eq_self {f : α → α} (h : Set.EqOn f id s) : f '' s = s := by
rw [h.image_eq, image_id]
theorem EqOn.inter_preimage_eq (heq : EqOn f₁ f₂ s) (t : Set β) : s ∩ f₁ ⁻¹' t = s ∩ f₂ ⁻¹' t :=
ext fun x => and_congr_right_iff.2 fun hx => by rw [mem_preimage, mem_preimage, heq hx]
theorem EqOn.mono (hs : s₁ ⊆ s₂) (hf : EqOn f₁ f₂ s₂) : EqOn f₁ f₂ s₁ := fun _ hx => hf (hs hx)
@[simp]
theorem eqOn_union : EqOn f₁ f₂ (s₁ ∪ s₂) ↔ EqOn f₁ f₂ s₁ ∧ EqOn f₁ f₂ s₂ :=
forall₂_or_left
theorem EqOn.union (h₁ : EqOn f₁ f₂ s₁) (h₂ : EqOn f₁ f₂ s₂) : EqOn f₁ f₂ (s₁ ∪ s₂) :=
eqOn_union.2 ⟨h₁, h₂⟩
theorem EqOn.comp_left (h : s.EqOn f₁ f₂) : s.EqOn (g ∘ f₁) (g ∘ f₂) := fun _ ha =>
congr_arg _ <| h ha
@[simp]
theorem eqOn_range {ι : Sort*} {f : ι → α} {g₁ g₂ : α → β} :
EqOn g₁ g₂ (range f) ↔ g₁ ∘ f = g₂ ∘ f :=
forall_mem_range.trans <| funext_iff.symm
alias ⟨EqOn.comp_eq, _⟩ := eqOn_range
end equality
variable {s s₁ s₂ : Set α} {t t₁ t₂ : Set β} {p : Set γ} {f f₁ f₂ : α → β} {g g₁ g₂ : β → γ}
{f' f₁' f₂' : β → α} {g' : γ → β} {a : α} {b : β}
section MapsTo
theorem mapsTo' : MapsTo f s t ↔ f '' s ⊆ t :=
image_subset_iff.symm
theorem mapsTo_prodMap_diagonal : MapsTo (Prod.map f f) (diagonal α) (diagonal β) :=
diagonal_subset_iff.2 fun _ => rfl
@[deprecated (since := "2025-04-18")]
alias mapsTo_prod_map_diagonal := mapsTo_prodMap_diagonal
theorem MapsTo.subset_preimage (hf : MapsTo f s t) : s ⊆ f ⁻¹' t := hf
theorem mapsTo_iff_subset_preimage : MapsTo f s t ↔ s ⊆ f ⁻¹' t := Iff.rfl
@[simp]
theorem mapsTo_singleton {x : α} : MapsTo f {x} t ↔ f x ∈ t :=
singleton_subset_iff
theorem mapsTo_empty (f : α → β) (t : Set β) : MapsTo f ∅ t :=
empty_subset _
@[simp] theorem mapsTo_empty_iff : MapsTo f s ∅ ↔ s = ∅ := by
simp [mapsTo', subset_empty_iff]
/-- If `f` maps `s` to `t` and `s` is non-empty, `t` is non-empty. -/
theorem MapsTo.nonempty (h : MapsTo f s t) (hs : s.Nonempty) : t.Nonempty :=
(hs.image f).mono (mapsTo'.mp h)
theorem MapsTo.image_subset (h : MapsTo f s t) : f '' s ⊆ t :=
mapsTo'.1 h
theorem MapsTo.congr (h₁ : MapsTo f₁ s t) (h : EqOn f₁ f₂ s) : MapsTo f₂ s t := fun _ hx =>
h hx ▸ h₁ hx
theorem EqOn.comp_right (hg : t.EqOn g₁ g₂) (hf : s.MapsTo f t) : s.EqOn (g₁ ∘ f) (g₂ ∘ f) :=
fun _ ha => hg <| hf ha
theorem EqOn.mapsTo_iff (H : EqOn f₁ f₂ s) : MapsTo f₁ s t ↔ MapsTo f₂ s t :=
⟨fun h => h.congr H, fun h => h.congr H.symm⟩
theorem MapsTo.comp (h₁ : MapsTo g t p) (h₂ : MapsTo f s t) : MapsTo (g ∘ f) s p := fun _ h =>
h₁ (h₂ h)
theorem mapsTo_id (s : Set α) : MapsTo id s s := fun _ => id
theorem MapsTo.iterate {f : α → α} {s : Set α} (h : MapsTo f s s) : ∀ n, MapsTo f^[n] s s
| 0 => fun _ => id
| n + 1 => (MapsTo.iterate h n).comp h
theorem MapsTo.iterate_restrict {f : α → α} {s : Set α} (h : MapsTo f s s) (n : ℕ) :
(h.restrict f s s)^[n] = (h.iterate n).restrict _ _ _ := by
funext x
rw [Subtype.ext_iff, MapsTo.val_restrict_apply]
induction n generalizing x with
| zero => rfl
| succ n ihn => simp [Nat.iterate, ihn]
lemma mapsTo_of_subsingleton' [Subsingleton β] (f : α → β) (h : s.Nonempty → t.Nonempty) :
MapsTo f s t :=
fun a ha ↦ Subsingleton.mem_iff_nonempty.2 <| h ⟨a, ha⟩
lemma mapsTo_of_subsingleton [Subsingleton α] (f : α → α) (s : Set α) : MapsTo f s s :=
mapsTo_of_subsingleton' _ id
theorem MapsTo.mono (hf : MapsTo f s₁ t₁) (hs : s₂ ⊆ s₁) (ht : t₁ ⊆ t₂) : MapsTo f s₂ t₂ :=
fun _ hx => ht (hf <| hs hx)
theorem MapsTo.mono_left (hf : MapsTo f s₁ t) (hs : s₂ ⊆ s₁) : MapsTo f s₂ t := fun _ hx =>
hf (hs hx)
theorem MapsTo.mono_right (hf : MapsTo f s t₁) (ht : t₁ ⊆ t₂) : MapsTo f s t₂ := fun _ hx =>
ht (hf hx)
theorem MapsTo.union_union (h₁ : MapsTo f s₁ t₁) (h₂ : MapsTo f s₂ t₂) :
MapsTo f (s₁ ∪ s₂) (t₁ ∪ t₂) := fun _ hx =>
hx.elim (fun hx => Or.inl <| h₁ hx) fun hx => Or.inr <| h₂ hx
theorem MapsTo.union (h₁ : MapsTo f s₁ t) (h₂ : MapsTo f s₂ t) : MapsTo f (s₁ ∪ s₂) t :=
union_self t ▸ h₁.union_union h₂
@[simp]
theorem mapsTo_union : MapsTo f (s₁ ∪ s₂) t ↔ MapsTo f s₁ t ∧ MapsTo f s₂ t :=
⟨fun h =>
⟨h.mono subset_union_left (Subset.refl t),
h.mono subset_union_right (Subset.refl t)⟩,
fun h => h.1.union h.2⟩
theorem MapsTo.inter (h₁ : MapsTo f s t₁) (h₂ : MapsTo f s t₂) : MapsTo f s (t₁ ∩ t₂) := fun _ hx =>
⟨h₁ hx, h₂ hx⟩
lemma MapsTo.insert (h : MapsTo f s t) (x : α) : MapsTo f (insert x s) (insert (f x) t) := by
simpa [← singleton_union] using h.mono_right subset_union_right
theorem MapsTo.inter_inter (h₁ : MapsTo f s₁ t₁) (h₂ : MapsTo f s₂ t₂) :
MapsTo f (s₁ ∩ s₂) (t₁ ∩ t₂) := fun _ hx => ⟨h₁ hx.1, h₂ hx.2⟩
@[simp]
theorem mapsTo_inter : MapsTo f s (t₁ ∩ t₂) ↔ MapsTo f s t₁ ∧ MapsTo f s t₂ :=
⟨fun h =>
⟨h.mono (Subset.refl s) inter_subset_left,
h.mono (Subset.refl s) inter_subset_right⟩,
fun h => h.1.inter h.2⟩
theorem mapsTo_univ (f : α → β) (s : Set α) : MapsTo f s univ := fun _ _ => trivial
theorem mapsTo_range (f : α → β) (s : Set α) : MapsTo f s (range f) :=
(mapsTo_image f s).mono (Subset.refl s) (image_subset_range _ _)
@[simp]
theorem mapsTo_image_iff {f : α → β} {g : γ → α} {s : Set γ} {t : Set β} :
MapsTo f (g '' s) t ↔ MapsTo (f ∘ g) s t :=
⟨fun h c hc => h ⟨c, hc, rfl⟩, fun h _ ⟨_, hc⟩ => hc.2 ▸ h hc.1⟩
lemma MapsTo.comp_left (g : β → γ) (hf : MapsTo f s t) : MapsTo (g ∘ f) s (g '' t) :=
fun x hx ↦ ⟨f x, hf hx, rfl⟩
lemma MapsTo.comp_right {s : Set β} {t : Set γ} (hg : MapsTo g s t) (f : α → β) :
MapsTo (g ∘ f) (f ⁻¹' s) t := fun _ hx ↦ hg hx
@[simp]
lemma mapsTo_univ_iff : MapsTo f univ t ↔ ∀ x, f x ∈ t :=
⟨fun h _ => h (mem_univ _), fun h x _ => h x⟩
@[simp]
lemma mapsTo_range_iff {g : ι → α} : MapsTo f (range g) t ↔ ∀ i, f (g i) ∈ t :=
forall_mem_range
theorem MapsTo.mem_iff (h : MapsTo f s t) (hc : MapsTo f sᶜ tᶜ) {x} : f x ∈ t ↔ x ∈ s :=
⟨fun ht => by_contra fun hs => hc hs ht, fun hx => h hx⟩
end MapsTo
/-! ### Injectivity on a set -/
section injOn
theorem Subsingleton.injOn (hs : s.Subsingleton) (f : α → β) : InjOn f s := fun _ hx _ hy _ =>
hs hx hy
@[simp]
theorem injOn_empty (f : α → β) : InjOn f ∅ :=
subsingleton_empty.injOn f
@[simp]
theorem injOn_singleton (f : α → β) (a : α) : InjOn f {a} :=
subsingleton_singleton.injOn f
@[simp] lemma injOn_pair {b : α} : InjOn f {a, b} ↔ f a = f b → a = b := by unfold InjOn; aesop
theorem InjOn.eq_iff {x y} (h : InjOn f s) (hx : x ∈ s) (hy : y ∈ s) : f x = f y ↔ x = y :=
⟨h hx hy, fun h => h ▸ rfl⟩
theorem InjOn.ne_iff {x y} (h : InjOn f s) (hx : x ∈ s) (hy : y ∈ s) : f x ≠ f y ↔ x ≠ y :=
(h.eq_iff hx hy).not
alias ⟨_, InjOn.ne⟩ := InjOn.ne_iff
theorem InjOn.congr (h₁ : InjOn f₁ s) (h : EqOn f₁ f₂ s) : InjOn f₂ s := fun _ hx _ hy =>
h hx ▸ h hy ▸ h₁ hx hy
theorem EqOn.injOn_iff (H : EqOn f₁ f₂ s) : InjOn f₁ s ↔ InjOn f₂ s :=
⟨fun h => h.congr H, fun h => h.congr H.symm⟩
theorem InjOn.mono (h : s₁ ⊆ s₂) (ht : InjOn f s₂) : InjOn f s₁ := fun _ hx _ hy H =>
ht (h hx) (h hy) H
theorem injOn_union (h : Disjoint s₁ s₂) :
InjOn f (s₁ ∪ s₂) ↔ InjOn f s₁ ∧ InjOn f s₂ ∧ ∀ x ∈ s₁, ∀ y ∈ s₂, f x ≠ f y := by
refine ⟨fun H => ⟨H.mono subset_union_left, H.mono subset_union_right, ?_⟩, ?_⟩
· intro x hx y hy hxy
obtain rfl : x = y := H (Or.inl hx) (Or.inr hy) hxy
exact h.le_bot ⟨hx, hy⟩
· rintro ⟨h₁, h₂, h₁₂⟩
rintro x (hx | hx) y (hy | hy) hxy
exacts [h₁ hx hy hxy, (h₁₂ _ hx _ hy hxy).elim, (h₁₂ _ hy _ hx hxy.symm).elim, h₂ hx hy hxy]
theorem injOn_insert {f : α → β} {s : Set α} {a : α} (has : a ∉ s) :
Set.InjOn f (insert a s) ↔ Set.InjOn f s ∧ f a ∉ f '' s := by
rw [← union_singleton, injOn_union (disjoint_singleton_right.2 has)]
simp
theorem injective_iff_injOn_univ : Injective f ↔ InjOn f univ :=
⟨fun h _ _ _ _ hxy => h hxy, fun h _ _ heq => h trivial trivial heq⟩
theorem injOn_of_injective (h : Injective f) {s : Set α} : InjOn f s := fun _ _ _ _ hxy => h hxy
alias _root_.Function.Injective.injOn := injOn_of_injective
-- A specialization of `injOn_of_injective` for `Subtype.val`.
theorem injOn_subtype_val {s : Set { x // p x }} : Set.InjOn Subtype.val s :=
Subtype.coe_injective.injOn
lemma injOn_id (s : Set α) : InjOn id s := injective_id.injOn
theorem InjOn.comp (hg : InjOn g t) (hf : InjOn f s) (h : MapsTo f s t) : InjOn (g ∘ f) s :=
fun _ hx _ hy heq => hf hx hy <| hg (h hx) (h hy) heq
lemma InjOn.of_comp (h : InjOn (g ∘ f) s) : InjOn f s :=
fun _ hx _ hy heq ↦ h hx hy (by simp [heq])
lemma InjOn.image_of_comp (h : InjOn (g ∘ f) s) : InjOn g (f '' s) :=
forall_mem_image.2 fun _x hx ↦ forall_mem_image.2 fun _y hy heq ↦ congr_arg f <| h hx hy heq
lemma InjOn.comp_iff (hf : InjOn f s) : InjOn (g ∘ f) s ↔ InjOn g (f '' s) :=
⟨image_of_comp, fun h ↦ InjOn.comp h hf <| mapsTo_image f s⟩
lemma InjOn.iterate {f : α → α} {s : Set α} (h : InjOn f s) (hf : MapsTo f s s) :
∀ n, InjOn f^[n] s
| 0 => injOn_id _
| (n + 1) => (h.iterate hf n).comp h hf
lemma injOn_of_subsingleton [Subsingleton α] (f : α → β) (s : Set α) : InjOn f s :=
(injective_of_subsingleton _).injOn
theorem _root_.Function.Injective.injOn_range (h : Injective (g ∘ f)) : InjOn g (range f) := by
rintro _ ⟨x, rfl⟩ _ ⟨y, rfl⟩ H
exact congr_arg f (h H)
theorem _root_.Set.InjOn.injective_iff (s : Set β) (h : InjOn g s) (hs : range f ⊆ s) :
Injective (g ∘ f) ↔ Injective f :=
⟨(·.of_comp), fun h _ ↦ by aesop⟩
theorem exists_injOn_iff_injective [Nonempty β] :
(∃ f : α → β, InjOn f s) ↔ ∃ f : s → β, Injective f :=
⟨fun ⟨_, hf⟩ => ⟨_, hf.injective⟩,
fun ⟨f, hf⟩ => by
lift f to α → β using trivial
exact ⟨f, injOn_iff_injective.2 hf⟩⟩
theorem injOn_preimage {B : Set (Set β)} (hB : B ⊆ 𝒫 range f) : InjOn (preimage f) B :=
fun _ hs _ ht hst => (preimage_eq_preimage' (hB hs) (hB ht)).1 hst
theorem InjOn.mem_of_mem_image {x} (hf : InjOn f s) (hs : s₁ ⊆ s) (h : x ∈ s) (h₁ : f x ∈ f '' s₁) :
x ∈ s₁ :=
let ⟨_, h', Eq⟩ := h₁
hf (hs h') h Eq ▸ h'
theorem InjOn.mem_image_iff {x} (hf : InjOn f s) (hs : s₁ ⊆ s) (hx : x ∈ s) :
f x ∈ f '' s₁ ↔ x ∈ s₁ :=
⟨hf.mem_of_mem_image hs hx, mem_image_of_mem f⟩
theorem InjOn.preimage_image_inter (hf : InjOn f s) (hs : s₁ ⊆ s) : f ⁻¹' (f '' s₁) ∩ s = s₁ :=
ext fun _ => ⟨fun ⟨h₁, h₂⟩ => hf.mem_of_mem_image hs h₂ h₁, fun h => ⟨mem_image_of_mem _ h, hs h⟩⟩
theorem EqOn.cancel_left (h : s.EqOn (g ∘ f₁) (g ∘ f₂)) (hg : t.InjOn g) (hf₁ : s.MapsTo f₁ t)
(hf₂ : s.MapsTo f₂ t) : s.EqOn f₁ f₂ := fun _ ha => hg (hf₁ ha) (hf₂ ha) (h ha)
theorem InjOn.cancel_left (hg : t.InjOn g) (hf₁ : s.MapsTo f₁ t) (hf₂ : s.MapsTo f₂ t) :
s.EqOn (g ∘ f₁) (g ∘ f₂) ↔ s.EqOn f₁ f₂ :=
⟨fun h => h.cancel_left hg hf₁ hf₂, EqOn.comp_left⟩
lemma InjOn.image_inter {s t u : Set α} (hf : u.InjOn f) (hs : s ⊆ u) (ht : t ⊆ u) :
f '' (s ∩ t) = f '' s ∩ f '' t := by
apply Subset.antisymm (image_inter_subset _ _ _)
intro x ⟨⟨y, ys, hy⟩, ⟨z, zt, hz⟩⟩
have : y = z := by
apply hf (hs ys) (ht zt)
rwa [← hz] at hy
rw [← this] at zt
exact ⟨y, ⟨ys, zt⟩, hy⟩
lemma InjOn.image (h : s.InjOn f) : s.powerset.InjOn (image f) :=
fun s₁ hs₁ s₂ hs₂ h' ↦ by rw [← h.preimage_image_inter hs₁, h', h.preimage_image_inter hs₂]
theorem InjOn.image_eq_image_iff (h : s.InjOn f) (h₁ : s₁ ⊆ s) (h₂ : s₂ ⊆ s) :
f '' s₁ = f '' s₂ ↔ s₁ = s₂ :=
h.image.eq_iff h₁ h₂
lemma InjOn.image_subset_image_iff (h : s.InjOn f) (h₁ : s₁ ⊆ s) (h₂ : s₂ ⊆ s) :
f '' s₁ ⊆ f '' s₂ ↔ s₁ ⊆ s₂ := by
refine ⟨fun h' ↦ ?_, image_subset _⟩
rw [← h.preimage_image_inter h₁, ← h.preimage_image_inter h₂]
exact inter_subset_inter_left _ (preimage_mono h')
lemma InjOn.image_ssubset_image_iff (h : s.InjOn f) (h₁ : s₁ ⊆ s) (h₂ : s₂ ⊆ s) :
f '' s₁ ⊂ f '' s₂ ↔ s₁ ⊂ s₂ := by
simp_rw [ssubset_def, h.image_subset_image_iff h₁ h₂, h.image_subset_image_iff h₂ h₁]
-- TODO: can this move to a better place?
theorem _root_.Disjoint.image {s t u : Set α} {f : α → β} (h : Disjoint s t) (hf : u.InjOn f)
(hs : s ⊆ u) (ht : t ⊆ u) : Disjoint (f '' s) (f '' t) := by
rw [disjoint_iff_inter_eq_empty] at h ⊢
rw [← hf.image_inter hs ht, h, image_empty]
lemma InjOn.image_diff {t : Set α} (h : s.InjOn f) : f '' (s \ t) = f '' s \ f '' (s ∩ t) := by
refine subset_antisymm (subset_diff.2 ⟨image_subset f diff_subset, ?_⟩)
(diff_subset_iff.2 (by rw [← image_union, inter_union_diff]))
exact Disjoint.image disjoint_sdiff_inter h diff_subset inter_subset_left
lemma InjOn.image_diff_subset {f : α → β} {t : Set α} (h : InjOn f s) (hst : t ⊆ s) :
f '' (s \ t) = f '' s \ f '' t := by
rw [h.image_diff, inter_eq_self_of_subset_right hst]
alias image_diff_of_injOn := InjOn.image_diff_subset
theorem InjOn.imageFactorization_injective (h : InjOn f s) :
Injective (s.imageFactorization f) :=
fun ⟨x, hx⟩ ⟨y, hy⟩ h' ↦ by simpa [imageFactorization, h.eq_iff hx hy] using h'
@[simp] theorem imageFactorization_injective_iff : Injective (s.imageFactorization f) ↔ InjOn f s :=
⟨fun h x hx y hy _ ↦ by simpa using @h ⟨x, hx⟩ ⟨y, hy⟩ (by simpa [imageFactorization]),
InjOn.imageFactorization_injective⟩
end injOn
section graphOn
variable {x : α × β}
lemma graphOn_univ_inj {g : α → β} : univ.graphOn f = univ.graphOn g ↔ f = g := by simp
lemma graphOn_univ_injective : Injective (univ.graphOn : (α → β) → Set (α × β)) :=
fun _f _g ↦ graphOn_univ_inj.1
lemma exists_eq_graphOn_image_fst [Nonempty β] {s : Set (α × β)} :
(∃ f : α → β, s = graphOn f (Prod.fst '' s)) ↔ InjOn Prod.fst s := by
refine ⟨?_, fun h ↦ ?_⟩
· rintro ⟨f, hf⟩
rw [hf]
exact InjOn.image_of_comp <| injOn_id _
· have : ∀ x ∈ Prod.fst '' s, ∃ y, (x, y) ∈ s := forall_mem_image.2 fun (x, y) h ↦ ⟨y, h⟩
choose! f hf using this
rw [forall_mem_image] at hf
use f
rw [graphOn, image_image, EqOn.image_eq_self]
exact fun x hx ↦ h (hf hx) hx rfl
lemma exists_eq_graphOn [Nonempty β] {s : Set (α × β)} :
(∃ f t, s = graphOn f t) ↔ InjOn Prod.fst s :=
.trans ⟨fun ⟨f, t, hs⟩ ↦ ⟨f, by rw [hs, image_fst_graphOn]⟩, fun ⟨f, hf⟩ ↦ ⟨f, _, hf⟩⟩
exists_eq_graphOn_image_fst
end graphOn
/-! ### Surjectivity on a set -/
section surjOn
theorem SurjOn.subset_range (h : SurjOn f s t) : t ⊆ range f :=
Subset.trans h <| image_subset_range f s
theorem surjOn_iff_exists_map_subtype :
SurjOn f s t ↔ ∃ (t' : Set β) (g : s → t'), t ⊆ t' ∧ Surjective g ∧ ∀ x : s, f x = g x :=
⟨fun h =>
⟨_, (mapsTo_image f s).restrict f s _, h, surjective_mapsTo_image_restrict _ _, fun _ => rfl⟩,
fun ⟨t', g, htt', hg, hfg⟩ y hy =>
let ⟨x, hx⟩ := hg ⟨y, htt' hy⟩
⟨x, x.2, by rw [hfg, hx, Subtype.coe_mk]⟩⟩
theorem surjOn_empty (f : α → β) (s : Set α) : SurjOn f s ∅ :=
empty_subset _
@[simp] theorem surjOn_empty_iff : SurjOn f ∅ t ↔ t = ∅ := by
simp [SurjOn, subset_empty_iff]
@[simp] lemma surjOn_singleton : SurjOn f s {b} ↔ b ∈ f '' s := singleton_subset_iff
theorem surjOn_image (f : α → β) (s : Set α) : SurjOn f s (f '' s) :=
Subset.rfl
theorem SurjOn.comap_nonempty (h : SurjOn f s t) (ht : t.Nonempty) : s.Nonempty :=
(ht.mono h).of_image
theorem SurjOn.congr (h : SurjOn f₁ s t) (H : EqOn f₁ f₂ s) : SurjOn f₂ s t := by
rwa [SurjOn, ← H.image_eq]
theorem EqOn.surjOn_iff (h : EqOn f₁ f₂ s) : SurjOn f₁ s t ↔ SurjOn f₂ s t :=
⟨fun H => H.congr h, fun H => H.congr h.symm⟩
theorem SurjOn.mono (hs : s₁ ⊆ s₂) (ht : t₁ ⊆ t₂) (hf : SurjOn f s₁ t₂) : SurjOn f s₂ t₁ :=
Subset.trans ht <| Subset.trans hf <| image_subset _ hs
theorem SurjOn.union (h₁ : SurjOn f s t₁) (h₂ : SurjOn f s t₂) : SurjOn f s (t₁ ∪ t₂) := fun _ hx =>
hx.elim (fun hx => h₁ hx) fun hx => h₂ hx
theorem SurjOn.union_union (h₁ : SurjOn f s₁ t₁) (h₂ : SurjOn f s₂ t₂) :
SurjOn f (s₁ ∪ s₂) (t₁ ∪ t₂) :=
(h₁.mono subset_union_left (Subset.refl _)).union
(h₂.mono subset_union_right (Subset.refl _))
theorem SurjOn.inter_inter (h₁ : SurjOn f s₁ t₁) (h₂ : SurjOn f s₂ t₂) (h : InjOn f (s₁ ∪ s₂)) :
SurjOn f (s₁ ∩ s₂) (t₁ ∩ t₂) := by
intro y hy
rcases h₁ hy.1 with ⟨x₁, hx₁, rfl⟩
rcases h₂ hy.2 with ⟨x₂, hx₂, heq⟩
obtain rfl : x₁ = x₂ := h (Or.inl hx₁) (Or.inr hx₂) heq.symm
exact mem_image_of_mem f ⟨hx₁, hx₂⟩
theorem SurjOn.inter (h₁ : SurjOn f s₁ t) (h₂ : SurjOn f s₂ t) (h : InjOn f (s₁ ∪ s₂)) :
SurjOn f (s₁ ∩ s₂) t :=
inter_self t ▸ h₁.inter_inter h₂ h
lemma surjOn_id (s : Set α) : SurjOn id s s := by simp [SurjOn]
theorem SurjOn.comp (hg : SurjOn g t p) (hf : SurjOn f s t) : SurjOn (g ∘ f) s p :=
Subset.trans hg <| Subset.trans (image_subset g hf) <| image_comp g f s ▸ Subset.refl _
lemma SurjOn.of_comp (h : SurjOn (g ∘ f) s p) (hr : MapsTo f s t) : SurjOn g t p := by
intro z hz
obtain ⟨x, hx, rfl⟩ := h hz
exact ⟨f x, hr hx, rfl⟩
lemma surjOn_comp_iff : SurjOn (g ∘ f) s p ↔ SurjOn g (f '' s) p :=
⟨fun h ↦ h.of_comp <| mapsTo_image f s, fun h ↦ h.comp <| surjOn_image _ _⟩
lemma SurjOn.iterate {f : α → α} {s : Set α} (h : SurjOn f s s) : ∀ n, SurjOn f^[n] s s
| 0 => surjOn_id _
| (n + 1) => (h.iterate n).comp h
lemma SurjOn.comp_left (hf : SurjOn f s t) (g : β → γ) : SurjOn (g ∘ f) s (g '' t) := by
rw [SurjOn, image_comp g f]; exact image_subset _ hf
lemma SurjOn.comp_right {s : Set β} {t : Set γ} (hf : Surjective f) (hg : SurjOn g s t) :
SurjOn (g ∘ f) (f ⁻¹' s) t := by
rwa [SurjOn, image_comp g f, image_preimage_eq _ hf]
lemma surjOn_of_subsingleton' [Subsingleton β] (f : α → β) (h : t.Nonempty → s.Nonempty) :
SurjOn f s t :=
fun _ ha ↦ Subsingleton.mem_iff_nonempty.2 <| (h ⟨_, ha⟩).image _
lemma surjOn_of_subsingleton [Subsingleton α] (f : α → α) (s : Set α) : SurjOn f s s :=
surjOn_of_subsingleton' _ id
theorem surjective_iff_surjOn_univ : Surjective f ↔ SurjOn f univ univ := by
simp [Surjective, SurjOn, subset_def]
theorem SurjOn.image_eq_of_mapsTo (h₁ : SurjOn f s t) (h₂ : MapsTo f s t) : f '' s = t :=
eq_of_subset_of_subset h₂.image_subset h₁
theorem image_eq_iff_surjOn_mapsTo : f '' s = t ↔ s.SurjOn f t ∧ s.MapsTo f t := by
refine ⟨?_, fun h => h.1.image_eq_of_mapsTo h.2⟩
rintro rfl
exact ⟨s.surjOn_image f, s.mapsTo_image f⟩
lemma SurjOn.image_preimage (h : Set.SurjOn f s t) (ht : t₁ ⊆ t) : f '' (f ⁻¹' t₁) = t₁ :=
image_preimage_eq_iff.2 fun _ hx ↦ mem_range_of_mem_image f s <| h <| ht hx
theorem SurjOn.mapsTo_compl (h : SurjOn f s t) (h' : Injective f) : MapsTo f sᶜ tᶜ :=
fun _ hs ht =>
let ⟨_, hx', HEq⟩ := h ht
hs <| h' HEq ▸ hx'
theorem MapsTo.surjOn_compl (h : MapsTo f s t) (h' : Surjective f) : SurjOn f sᶜ tᶜ :=
h'.forall.2 fun _ ht => (mem_image_of_mem _) fun hs => ht (h hs)
theorem EqOn.cancel_right (hf : s.EqOn (g₁ ∘ f) (g₂ ∘ f)) (hf' : s.SurjOn f t) : t.EqOn g₁ g₂ := by
intro b hb
obtain ⟨a, ha, rfl⟩ := hf' hb
exact hf ha
theorem SurjOn.cancel_right (hf : s.SurjOn f t) (hf' : s.MapsTo f t) :
s.EqOn (g₁ ∘ f) (g₂ ∘ f) ↔ t.EqOn g₁ g₂ :=
⟨fun h => h.cancel_right hf, fun h => h.comp_right hf'⟩
theorem eqOn_comp_right_iff : s.EqOn (g₁ ∘ f) (g₂ ∘ f) ↔ (f '' s).EqOn g₁ g₂ :=
(s.surjOn_image f).cancel_right <| s.mapsTo_image f
theorem SurjOn.forall {p : β → Prop} (hf : s.SurjOn f t) (hf' : s.MapsTo f t) :
(∀ y ∈ t, p y) ↔ (∀ x ∈ s, p (f x)) :=
⟨fun H x hx ↦ H (f x) (hf' hx), fun H _y hy ↦ let ⟨x, hx, hxy⟩ := hf hy; hxy ▸ H x hx⟩
end surjOn
/-! ### Bijectivity -/
section bijOn
theorem BijOn.mapsTo (h : BijOn f s t) : MapsTo f s t :=
h.left
theorem BijOn.injOn (h : BijOn f s t) : InjOn f s :=
h.right.left
theorem BijOn.surjOn (h : BijOn f s t) : SurjOn f s t :=
h.right.right
theorem BijOn.mk (h₁ : MapsTo f s t) (h₂ : InjOn f s) (h₃ : SurjOn f s t) : BijOn f s t :=
⟨h₁, h₂, h₃⟩
theorem bijOn_empty (f : α → β) : BijOn f ∅ ∅ :=
⟨mapsTo_empty f ∅, injOn_empty f, surjOn_empty f ∅⟩
@[simp] theorem bijOn_empty_iff_left : BijOn f s ∅ ↔ s = ∅ :=
⟨fun h ↦ by simpa using h.mapsTo, by rintro rfl; exact bijOn_empty f⟩
@[simp] theorem bijOn_empty_iff_right : BijOn f ∅ t ↔ t = ∅ :=
⟨fun h ↦ by simpa using h.surjOn, by rintro rfl; exact bijOn_empty f⟩
@[simp] lemma bijOn_singleton : BijOn f {a} {b} ↔ f a = b := by simp [BijOn, eq_comm]
theorem BijOn.inter_mapsTo (h₁ : BijOn f s₁ t₁) (h₂ : MapsTo f s₂ t₂) (h₃ : s₁ ∩ f ⁻¹' t₂ ⊆ s₂) :
BijOn f (s₁ ∩ s₂) (t₁ ∩ t₂) :=
⟨h₁.mapsTo.inter_inter h₂, h₁.injOn.mono inter_subset_left, fun _ hy =>
let ⟨x, hx, hxy⟩ := h₁.surjOn hy.1
⟨x, ⟨hx, h₃ ⟨hx, hxy.symm.subst hy.2⟩⟩, hxy⟩⟩
theorem MapsTo.inter_bijOn (h₁ : MapsTo f s₁ t₁) (h₂ : BijOn f s₂ t₂) (h₃ : s₂ ∩ f ⁻¹' t₁ ⊆ s₁) :
BijOn f (s₁ ∩ s₂) (t₁ ∩ t₂) :=
inter_comm s₂ s₁ ▸ inter_comm t₂ t₁ ▸ h₂.inter_mapsTo h₁ h₃
theorem BijOn.inter (h₁ : BijOn f s₁ t₁) (h₂ : BijOn f s₂ t₂) (h : InjOn f (s₁ ∪ s₂)) :
BijOn f (s₁ ∩ s₂) (t₁ ∩ t₂) :=
⟨h₁.mapsTo.inter_inter h₂.mapsTo, h₁.injOn.mono inter_subset_left,
h₁.surjOn.inter_inter h₂.surjOn h⟩
theorem BijOn.union (h₁ : BijOn f s₁ t₁) (h₂ : BijOn f s₂ t₂) (h : InjOn f (s₁ ∪ s₂)) :
BijOn f (s₁ ∪ s₂) (t₁ ∪ t₂) :=
⟨h₁.mapsTo.union_union h₂.mapsTo, h, h₁.surjOn.union_union h₂.surjOn⟩
theorem BijOn.subset_range (h : BijOn f s t) : t ⊆ range f :=
h.surjOn.subset_range
theorem InjOn.bijOn_image (h : InjOn f s) : BijOn f s (f '' s) :=
BijOn.mk (mapsTo_image f s) h (Subset.refl _)
theorem BijOn.congr (h₁ : BijOn f₁ s t) (h : EqOn f₁ f₂ s) : BijOn f₂ s t :=
BijOn.mk (h₁.mapsTo.congr h) (h₁.injOn.congr h) (h₁.surjOn.congr h)
theorem EqOn.bijOn_iff (H : EqOn f₁ f₂ s) : BijOn f₁ s t ↔ BijOn f₂ s t :=
⟨fun h => h.congr H, fun h => h.congr H.symm⟩
theorem BijOn.image_eq (h : BijOn f s t) : f '' s = t :=
h.surjOn.image_eq_of_mapsTo h.mapsTo
lemma BijOn.forall {p : β → Prop} (hf : BijOn f s t) : (∀ b ∈ t, p b) ↔ ∀ a ∈ s, p (f a) where
mp h _ ha := h _ <| hf.mapsTo ha
mpr h b hb := by obtain ⟨a, ha, rfl⟩ := hf.surjOn hb; exact h _ ha
lemma BijOn.exists {p : β → Prop} (hf : BijOn f s t) : (∃ b ∈ t, p b) ↔ ∃ a ∈ s, p (f a) where
mp := by rintro ⟨b, hb, h⟩; obtain ⟨a, ha, rfl⟩ := hf.surjOn hb; exact ⟨a, ha, h⟩
mpr := by rintro ⟨a, ha, h⟩; exact ⟨f a, hf.mapsTo ha, h⟩
lemma _root_.Equiv.image_eq_iff_bijOn (e : α ≃ β) : e '' s = t ↔ BijOn e s t :=
⟨fun h ↦ ⟨(mapsTo_image e s).mono_right h.subset, e.injective.injOn, h ▸ surjOn_image e s⟩,
BijOn.image_eq⟩
lemma bijOn_id (s : Set α) : BijOn id s s := ⟨s.mapsTo_id, s.injOn_id, s.surjOn_id⟩
theorem BijOn.comp (hg : BijOn g t p) (hf : BijOn f s t) : BijOn (g ∘ f) s p :=
BijOn.mk (hg.mapsTo.comp hf.mapsTo) (hg.injOn.comp hf.injOn hf.mapsTo) (hg.surjOn.comp hf.surjOn)
/-- If `f : α → β` and `g : β → γ` and if `f` is injective on `s`, then `f ∘ g` is a bijection
on `s` iff `g` is a bijection on `f '' s`. -/
theorem bijOn_comp_iff (hf : InjOn f s) : BijOn (g ∘ f) s p ↔ BijOn g (f '' s) p := by
simp only [BijOn, InjOn.comp_iff, surjOn_comp_iff, mapsTo_image_iff, hf]
/--
If we have a commutative square
```
α --f--> β
| |
p₁ p₂
| |
\/ \/
γ --g--> δ
```
and `f` induces a bijection from `s : Set α` to `t : Set β`, then `g`
induces a bijection from the image of `s` to the image of `t`, as long as `g` is
is injective on the image of `s`.
-/
theorem bijOn_image_image {p₁ : α → γ} {p₂ : β → δ} {g : γ → δ} (comm : ∀ a, p₂ (f a) = g (p₁ a))
(hbij : BijOn f s t) (hinj: InjOn g (p₁ '' s)) : BijOn g (p₁ '' s) (p₂ '' t) := by
obtain ⟨h1, h2, h3⟩ := hbij
refine ⟨?_, hinj, ?_⟩
· rintro _ ⟨a, ha, rfl⟩
exact ⟨f a, h1 ha, by rw [comm a]⟩
· rintro _ ⟨b, hb, rfl⟩
obtain ⟨a, ha, rfl⟩ := h3 hb
rw [← image_comp, comm]
exact ⟨a, ha, rfl⟩
lemma BijOn.iterate {f : α → α} {s : Set α} (h : BijOn f s s) : ∀ n, BijOn f^[n] s s
| 0 => s.bijOn_id
| (n + 1) => (h.iterate n).comp h
lemma bijOn_of_subsingleton' [Subsingleton α] [Subsingleton β] (f : α → β)
(h : s.Nonempty ↔ t.Nonempty) : BijOn f s t :=
⟨mapsTo_of_subsingleton' _ h.1, injOn_of_subsingleton _ _, surjOn_of_subsingleton' _ h.2⟩
lemma bijOn_of_subsingleton [Subsingleton α] (f : α → α) (s : Set α) : BijOn f s s :=
bijOn_of_subsingleton' _ Iff.rfl
theorem BijOn.bijective (h : BijOn f s t) : Bijective (h.mapsTo.restrict f s t) :=
⟨fun x y h' => Subtype.ext <| h.injOn x.2 y.2 <| Subtype.ext_iff.1 h', fun ⟨_, hy⟩ =>
let ⟨x, hx, hxy⟩ := h.surjOn hy
⟨⟨x, hx⟩, Subtype.eq hxy⟩⟩
theorem bijective_iff_bijOn_univ : Bijective f ↔ BijOn f univ univ :=
Iff.intro
(fun h =>
let ⟨inj, surj⟩ := h
⟨mapsTo_univ f _, inj.injOn, Iff.mp surjective_iff_surjOn_univ surj⟩)
fun h =>
let ⟨_map, inj, surj⟩ := h
⟨Iff.mpr injective_iff_injOn_univ inj, Iff.mpr surjective_iff_surjOn_univ surj⟩
alias ⟨_root_.Function.Bijective.bijOn_univ, _⟩ := bijective_iff_bijOn_univ
theorem BijOn.compl (hst : BijOn f s t) (hf : Bijective f) : BijOn f sᶜ tᶜ :=
⟨hst.surjOn.mapsTo_compl hf.1, hf.1.injOn, hst.mapsTo.surjOn_compl hf.2⟩
theorem BijOn.subset_right {r : Set β} (hf : BijOn f s t) (hrt : r ⊆ t) :
BijOn f (s ∩ f ⁻¹' r) r := by
refine ⟨inter_subset_right, hf.injOn.mono inter_subset_left, fun x hx ↦ ?_⟩
obtain ⟨y, hy, rfl⟩ := hf.surjOn (hrt hx)
exact ⟨y, ⟨hy, hx⟩, rfl⟩
theorem BijOn.subset_left {r : Set α} (hf : BijOn f s t) (hrs : r ⊆ s) :
BijOn f r (f '' r) :=
(hf.injOn.mono hrs).bijOn_image
theorem BijOn.insert_iff (ha : a ∉ s) (hfa : f a ∉ t) :
BijOn f (insert a s) (insert (f a) t) ↔ BijOn f s t where
mp h := by
have := congrArg (· \ {f a}) (image_insert_eq ▸ h.image_eq)
simp only [mem_singleton_iff, insert_diff_of_mem] at this
rw [diff_singleton_eq_self hfa, diff_singleton_eq_self] at this
· exact ⟨by simp [← this, mapsTo'], h.injOn.mono (subset_insert ..),
by simp [← this, surjOn_image]⟩
simp only [mem_image, not_exists, not_and]
intro x hx
rw [h.injOn.eq_iff (by simp [hx]) (by simp)]
exact ha ∘ (· ▸ hx)
mpr h := by
repeat rw [insert_eq]
refine (bijOn_singleton.mpr rfl).union h ?_
simp only [singleton_union, injOn_insert fun x ↦ (hfa (h.mapsTo x)), h.injOn, mem_image,
not_exists, not_and, true_and]
exact fun _ hx h₂ ↦ hfa (h₂ ▸ h.mapsTo hx)
theorem BijOn.insert (h₁ : BijOn f s t) (h₂ : f a ∉ t) :
BijOn f (insert a s) (insert (f a) t) :=
(insert_iff (h₂ <| h₁.mapsTo ·) h₂).mpr h₁
theorem BijOn.sdiff_singleton (h₁ : BijOn f s t) (h₂ : a ∈ s) :
BijOn f (s \ {a}) (t \ {f a}) := by
convert h₁.subset_left diff_subset
simp [h₁.injOn.image_diff, h₁.image_eq, h₂, inter_eq_self_of_subset_right]
end bijOn
/-! ### left inverse -/
namespace LeftInvOn
theorem eqOn (h : LeftInvOn f' f s) : EqOn (f' ∘ f) id s :=
h
theorem eq (h : LeftInvOn f' f s) {x} (hx : x ∈ s) : f' (f x) = x :=
h hx
theorem congr_left (h₁ : LeftInvOn f₁' f s) {t : Set β} (h₁' : MapsTo f s t)
(heq : EqOn f₁' f₂' t) : LeftInvOn f₂' f s := fun _ hx => heq (h₁' hx) ▸ h₁ hx
theorem congr_right (h₁ : LeftInvOn f₁' f₁ s) (heq : EqOn f₁ f₂ s) : LeftInvOn f₁' f₂ s :=
fun _ hx => heq hx ▸ h₁ hx
theorem injOn (h : LeftInvOn f₁' f s) : InjOn f s := fun x₁ h₁ x₂ h₂ heq =>
calc
x₁ = f₁' (f x₁) := Eq.symm <| h h₁
_ = f₁' (f x₂) := congr_arg f₁' heq
_ = x₂ := h h₂
theorem surjOn (h : LeftInvOn f' f s) (hf : MapsTo f s t) : SurjOn f' t s := fun x hx =>
⟨f x, hf hx, h hx⟩
theorem mapsTo (h : LeftInvOn f' f s) (hf : SurjOn f s t) :
MapsTo f' t s := fun y hy => by
let ⟨x, hs, hx⟩ := hf hy
rwa [← hx, h hs]
lemma _root_.Set.leftInvOn_id (s : Set α) : LeftInvOn id id s := fun _ _ ↦ rfl
theorem comp (hf' : LeftInvOn f' f s) (hg' : LeftInvOn g' g t) (hf : MapsTo f s t) :
LeftInvOn (f' ∘ g') (g ∘ f) s := fun x h =>
calc
(f' ∘ g') ((g ∘ f) x) = f' (f x) := congr_arg f' (hg' (hf h))
_ = x := hf' h
theorem mono (hf : LeftInvOn f' f s) (ht : s₁ ⊆ s) : LeftInvOn f' f s₁ := fun _ hx =>
hf (ht hx)
theorem image_inter' (hf : LeftInvOn f' f s) : f '' (s₁ ∩ s) = f' ⁻¹' s₁ ∩ f '' s := by
apply Subset.antisymm
· rintro _ ⟨x, ⟨h₁, h⟩, rfl⟩
exact ⟨by rwa [mem_preimage, hf h], mem_image_of_mem _ h⟩
· rintro _ ⟨h₁, ⟨x, h, rfl⟩⟩
exact mem_image_of_mem _ ⟨by rwa [← hf h], h⟩
theorem image_inter (hf : LeftInvOn f' f s) :
f '' (s₁ ∩ s) = f' ⁻¹' (s₁ ∩ s) ∩ f '' s := by
rw [hf.image_inter']
refine Subset.antisymm ?_ (inter_subset_inter_left _ (preimage_mono inter_subset_left))
rintro _ ⟨h₁, x, hx, rfl⟩; exact ⟨⟨h₁, by rwa [hf hx]⟩, mem_image_of_mem _ hx⟩
theorem image_image (hf : LeftInvOn f' f s) : f' '' (f '' s) = s := by
rw [Set.image_image, image_congr hf, image_id']
theorem image_image' (hf : LeftInvOn f' f s) (hs : s₁ ⊆ s) : f' '' (f '' s₁) = s₁ :=
(hf.mono hs).image_image
end LeftInvOn
/-! ### Right inverse -/
section RightInvOn
namespace RightInvOn
theorem eqOn (h : RightInvOn f' f t) : EqOn (f ∘ f') id t :=
h
theorem eq (h : RightInvOn f' f t) {y} (hy : y ∈ t) : f (f' y) = y :=
h hy
theorem _root_.Set.LeftInvOn.rightInvOn_image (h : LeftInvOn f' f s) : RightInvOn f' f (f '' s) :=
fun _y ⟨_x, hx, heq⟩ => heq ▸ (congr_arg f <| h.eq hx)
theorem congr_left (h₁ : RightInvOn f₁' f t) (heq : EqOn f₁' f₂' t) :
RightInvOn f₂' f t :=
h₁.congr_right heq
theorem congr_right (h₁ : RightInvOn f' f₁ t) (hg : MapsTo f' t s) (heq : EqOn f₁ f₂ s) :
RightInvOn f' f₂ t :=
LeftInvOn.congr_left h₁ hg heq
theorem surjOn (hf : RightInvOn f' f t) (hf' : MapsTo f' t s) : SurjOn f s t :=
LeftInvOn.surjOn hf hf'
theorem mapsTo (h : RightInvOn f' f t) (hf : SurjOn f' t s) : MapsTo f s t :=
LeftInvOn.mapsTo h hf
lemma _root_.Set.rightInvOn_id (s : Set α) : RightInvOn id id s := fun _ _ ↦ rfl
theorem comp (hf : RightInvOn f' f t) (hg : RightInvOn g' g p) (g'pt : MapsTo g' p t) :
RightInvOn (f' ∘ g') (g ∘ f) p :=
LeftInvOn.comp hg hf g'pt
theorem mono (hf : RightInvOn f' f t) (ht : t₁ ⊆ t) : RightInvOn f' f t₁ :=
LeftInvOn.mono hf ht
end RightInvOn
theorem InjOn.rightInvOn_of_leftInvOn (hf : InjOn f s) (hf' : LeftInvOn f f' t)
(h₁ : MapsTo f s t) (h₂ : MapsTo f' t s) : RightInvOn f f' s := fun _ h =>
hf (h₂ <| h₁ h) h (hf' (h₁ h))
theorem eqOn_of_leftInvOn_of_rightInvOn (h₁ : LeftInvOn f₁' f s) (h₂ : RightInvOn f₂' f t)
(h : MapsTo f₂' t s) : EqOn f₁' f₂' t := fun y hy =>
calc
f₁' y = (f₁' ∘ f ∘ f₂') y := congr_arg f₁' (h₂ hy).symm
_ = f₂' y := h₁ (h hy)
theorem SurjOn.leftInvOn_of_rightInvOn (hf : SurjOn f s t) (hf' : RightInvOn f f' s) :
LeftInvOn f f' t := fun y hy => by
let ⟨x, hx, heq⟩ := hf hy
rw [← heq, hf' hx]
end RightInvOn
/-! ### Two-side inverses -/
namespace InvOn
lemma _root_.Set.invOn_id (s : Set α) : InvOn id id s s := ⟨s.leftInvOn_id, s.rightInvOn_id⟩
lemma comp (hf : InvOn f' f s t) (hg : InvOn g' g t p) (fst : MapsTo f s t)
(g'pt : MapsTo g' p t) :
InvOn (f' ∘ g') (g ∘ f) s p :=
⟨hf.1.comp hg.1 fst, hf.2.comp hg.2 g'pt⟩
@[symm]
theorem symm (h : InvOn f' f s t) : InvOn f f' t s :=
⟨h.right, h.left⟩
theorem mono (h : InvOn f' f s t) (hs : s₁ ⊆ s) (ht : t₁ ⊆ t) : InvOn f' f s₁ t₁ :=
⟨h.1.mono hs, h.2.mono ht⟩
/-- If functions `f'` and `f` are inverse on `s` and `t`, `f` maps `s` into `t`, and `f'` maps `t`
into `s`, then `f` is a bijection between `s` and `t`. The `mapsTo` arguments can be deduced from
`surjOn` statements using `LeftInvOn.mapsTo` and `RightInvOn.mapsTo`. -/
theorem bijOn (h : InvOn f' f s t) (hf : MapsTo f s t) (hf' : MapsTo f' t s) : BijOn f s t :=
⟨hf, h.left.injOn, h.right.surjOn hf'⟩
end InvOn
end Set
/-! ### `invFunOn` is a left/right inverse -/
namespace Function
variable {s : Set α} {f : α → β} {a : α} {b : β}
/-- Construct the inverse for a function `f` on domain `s`. This function is a right inverse of `f`
on `f '' s`. For a computable version, see `Function.Embedding.invOfMemRange`. -/
noncomputable def invFunOn [Nonempty α] (f : α → β) (s : Set α) (b : β) : α :=
open scoped Classical in
if h : ∃ a, a ∈ s ∧ f a = b then Classical.choose h else Classical.choice ‹Nonempty α›
variable [Nonempty α]
theorem invFunOn_pos (h : ∃ a ∈ s, f a = b) : invFunOn f s b ∈ s ∧ f (invFunOn f s b) = b := by
rw [invFunOn, dif_pos h]
exact Classical.choose_spec h
theorem invFunOn_mem (h : ∃ a ∈ s, f a = b) : invFunOn f s b ∈ s :=
(invFunOn_pos h).left
theorem invFunOn_eq (h : ∃ a ∈ s, f a = b) : f (invFunOn f s b) = b :=
(invFunOn_pos h).right
theorem invFunOn_neg (h : ¬∃ a ∈ s, f a = b) : invFunOn f s b = Classical.choice ‹Nonempty α› := by
rw [invFunOn, dif_neg h]
@[simp]
theorem invFunOn_apply_mem (h : a ∈ s) : invFunOn f s (f a) ∈ s :=
invFunOn_mem ⟨a, h, rfl⟩
theorem invFunOn_apply_eq (h : a ∈ s) : f (invFunOn f s (f a)) = f a :=
invFunOn_eq ⟨a, h, rfl⟩
end Function
open Function
namespace Set
variable {s s₁ s₂ : Set α} {t : Set β} {f : α → β}
theorem InjOn.leftInvOn_invFunOn [Nonempty α] (h : InjOn f s) : LeftInvOn (invFunOn f s) f s :=
fun _a ha => h (invFunOn_apply_mem ha) ha (invFunOn_apply_eq ha)
theorem InjOn.invFunOn_image [Nonempty α] (h : InjOn f s₂) (ht : s₁ ⊆ s₂) :
invFunOn f s₂ '' (f '' s₁) = s₁ :=
h.leftInvOn_invFunOn.image_image' ht
theorem _root_.Function.leftInvOn_invFunOn_of_subset_image_image [Nonempty α]
(h : s ⊆ (invFunOn f s) '' (f '' s)) : LeftInvOn (invFunOn f s) f s :=
fun x hx ↦ by
obtain ⟨-, ⟨x, hx', rfl⟩, rfl⟩ := h hx
rw [invFunOn_apply_eq (f := f) hx']
theorem injOn_iff_invFunOn_image_image_eq_self [Nonempty α] :
InjOn f s ↔ (invFunOn f s) '' (f '' s) = s :=
⟨fun h ↦ h.invFunOn_image Subset.rfl, fun h ↦
(Function.leftInvOn_invFunOn_of_subset_image_image h.symm.subset).injOn⟩
theorem _root_.Function.invFunOn_injOn_image [Nonempty α] (f : α → β) (s : Set α) :
Set.InjOn (invFunOn f s) (f '' s) := by
rintro _ ⟨x, hx, rfl⟩ _ ⟨x', hx', rfl⟩ he
rw [← invFunOn_apply_eq (f := f) hx, he, invFunOn_apply_eq (f := f) hx']
theorem _root_.Function.invFunOn_image_image_subset [Nonempty α] (f : α → β) (s : Set α) :
(invFunOn f s) '' (f '' s) ⊆ s := by
rintro _ ⟨_, ⟨x,hx,rfl⟩, rfl⟩; exact invFunOn_apply_mem hx
theorem SurjOn.rightInvOn_invFunOn [Nonempty α] (h : SurjOn f s t) :
RightInvOn (invFunOn f s) f t := fun _y hy => invFunOn_eq <| h hy
theorem BijOn.invOn_invFunOn [Nonempty α] (h : BijOn f s t) : InvOn (invFunOn f s) f s t :=
⟨h.injOn.leftInvOn_invFunOn, h.surjOn.rightInvOn_invFunOn⟩
theorem SurjOn.invOn_invFunOn [Nonempty α] (h : SurjOn f s t) :
InvOn (invFunOn f s) f (invFunOn f s '' t) t := by
refine ⟨?_, h.rightInvOn_invFunOn⟩
rintro _ ⟨y, hy, rfl⟩
rw [h.rightInvOn_invFunOn hy]
theorem SurjOn.mapsTo_invFunOn [Nonempty α] (h : SurjOn f s t) : MapsTo (invFunOn f s) t s :=
fun _y hy => mem_preimage.2 <| invFunOn_mem <| h hy
/-- This lemma is a special case of `rightInvOn_invFunOn.image_image'`; it may make more sense
to use the other lemma directly in an application. -/
theorem SurjOn.image_invFunOn_image_of_subset [Nonempty α] {r : Set β} (hf : SurjOn f s t)
(hrt : r ⊆ t) : f '' (f.invFunOn s '' r) = r :=
hf.rightInvOn_invFunOn.image_image' hrt
/-- This lemma is a special case of `rightInvOn_invFunOn.image_image`; it may make more sense
to use the other lemma directly in an application. -/
theorem SurjOn.image_invFunOn_image [Nonempty α] (hf : SurjOn f s t) :
f '' (f.invFunOn s '' t) = t :=
hf.rightInvOn_invFunOn.image_image
theorem SurjOn.bijOn_subset [Nonempty α] (h : SurjOn f s t) : BijOn f (invFunOn f s '' t) t := by
refine h.invOn_invFunOn.bijOn ?_ (mapsTo_image _ _)
rintro _ ⟨y, hy, rfl⟩
rwa [h.rightInvOn_invFunOn hy]
theorem surjOn_iff_exists_bijOn_subset : SurjOn f s t ↔ ∃ s' ⊆ s, BijOn f s' t := by
constructor
· rcases eq_empty_or_nonempty t with (rfl | ht)
· exact fun _ => ⟨∅, empty_subset _, bijOn_empty f⟩
· intro h
haveI : Nonempty α := ⟨Classical.choose (h.comap_nonempty ht)⟩
exact ⟨_, h.mapsTo_invFunOn.image_subset, h.bijOn_subset⟩
· rintro ⟨s', hs', hfs'⟩
exact hfs'.surjOn.mono hs' (Subset.refl _)
alias ⟨SurjOn.exists_bijOn_subset, _⟩ := Set.surjOn_iff_exists_bijOn_subset
variable (f s)
lemma exists_subset_bijOn : ∃ s' ⊆ s, BijOn f s' (f '' s) :=
surjOn_iff_exists_bijOn_subset.mp (surjOn_image f s)
lemma exists_image_eq_and_injOn : ∃ u, f '' u = f '' s ∧ InjOn f u :=
let ⟨u, _, hfu⟩ := exists_subset_bijOn s f
⟨u, hfu.image_eq, hfu.injOn⟩
variable {f s}
lemma exists_image_eq_injOn_of_subset_range (ht : t ⊆ range f) :
∃ s, f '' s = t ∧ InjOn f s :=
image_preimage_eq_of_subset ht ▸ exists_image_eq_and_injOn _ _
/-- If `f` maps `s` bijectively to `t` and a set `t'` is contained in the image of some `s₁ ⊇ s`,
then `s₁` has a subset containing `s` that `f` maps bijectively to `t'`. -/
theorem BijOn.exists_extend_of_subset {t' : Set β} (h : BijOn f s t) (hss₁ : s ⊆ s₁) (htt' : t ⊆ t')
(ht' : SurjOn f s₁ t') : ∃ s', s ⊆ s' ∧ s' ⊆ s₁ ∧ Set.BijOn f s' t' := by
obtain ⟨r, hrss, hbij⟩ := exists_subset_bijOn ((s₁ ∩ f ⁻¹' t') \ f ⁻¹' t) f
rw [image_diff_preimage, image_inter_preimage] at hbij
refine ⟨s ∪ r, subset_union_left, ?_, ?_, ?_, fun y hyt' ↦ ?_⟩
· exact union_subset hss₁ <| hrss.trans <| diff_subset.trans inter_subset_left
· rw [mapsTo', image_union, hbij.image_eq, h.image_eq, union_subset_iff]
exact ⟨htt', diff_subset.trans inter_subset_right⟩
· rw [injOn_union, and_iff_right h.injOn, and_iff_right hbij.injOn]
· refine fun x hxs y hyr hxy ↦ (hrss hyr).2 ?_
rw [← h.image_eq]
exact ⟨x, hxs, hxy⟩
exact (subset_diff.1 hrss).2.symm.mono_left h.mapsTo
rw [image_union, h.image_eq, hbij.image_eq, union_diff_self]
exact .inr ⟨ht' hyt', hyt'⟩
/-- If `f` maps `s` bijectively to `t`, and `t'` is a superset of `t` contained in the range of `f`,
then `f` maps some superset of `s` bijectively to `t'`. -/
theorem BijOn.exists_extend {t' : Set β} (h : BijOn f s t) (htt' : t ⊆ t') (ht' : t' ⊆ range f) :
∃ s', s ⊆ s' ∧ BijOn f s' t' := by
simpa using h.exists_extend_of_subset (subset_univ s) htt' (by simpa [SurjOn])
theorem InjOn.exists_subset_injOn_subset_range_eq {r : Set α} (hinj : InjOn f r) (hrs : r ⊆ s) :
∃ u : Set α, r ⊆ u ∧ u ⊆ s ∧ f '' u = f '' s ∧ InjOn f u := by
obtain ⟨u, hru, hus, h⟩ := hinj.bijOn_image.exists_extend_of_subset hrs
(image_subset f hrs) Subset.rfl
exact ⟨u, hru, hus, h.image_eq, h.injOn⟩
theorem preimage_invFun_of_mem [n : Nonempty α] {f : α → β} (hf : Injective f) {s : Set α}
(h : Classical.choice n ∈ s) : invFun f ⁻¹' s = f '' s ∪ (range f)ᶜ := by
ext x
rcases em (x ∈ range f) with (⟨a, rfl⟩ | hx)
· simp only [mem_preimage, mem_union, mem_compl_iff, mem_range_self, not_true, or_false,
leftInverse_invFun hf _, hf.mem_set_image]
· simp only [mem_preimage, invFun_neg hx, h, hx, mem_union, mem_compl_iff, not_false_iff, or_true]
theorem preimage_invFun_of_not_mem [n : Nonempty α] {f : α → β} (hf : Injective f) {s : Set α}
(h : Classical.choice n ∉ s) : invFun f ⁻¹' s = f '' s := by
ext x
rcases em (x ∈ range f) with (⟨a, rfl⟩ | hx)
· rw [mem_preimage, leftInverse_invFun hf, hf.mem_set_image]
· have : x ∉ f '' s := fun h' => hx (image_subset_range _ _ h')
simp only [mem_preimage, invFun_neg hx, h, this]
lemma BijOn.symm {g : β → α} (h : InvOn f g t s) (hf : BijOn f s t) : BijOn g t s :=
⟨h.2.mapsTo hf.surjOn, h.1.injOn, h.2.surjOn hf.mapsTo⟩
lemma bijOn_comm {g : β → α} (h : InvOn f g t s) : BijOn f s t ↔ BijOn g t s :=
⟨BijOn.symm h, BijOn.symm h.symm⟩
end Set
namespace Function
open Set
variable {fa : α → α} {fb : β → β} {f : α → β} {g : β → γ} {s t : Set α}
theorem Injective.comp_injOn (hg : Injective g) (hf : s.InjOn f) : s.InjOn (g ∘ f) :=
hg.injOn.comp hf (mapsTo_univ _ _)
theorem Surjective.surjOn (hf : Surjective f) (s : Set β) : SurjOn f univ s :=
(surjective_iff_surjOn_univ.1 hf).mono (Subset.refl _) (subset_univ _)
theorem LeftInverse.leftInvOn {g : β → α} (h : LeftInverse f g) (s : Set β) : LeftInvOn f g s :=
fun x _ => h x
theorem RightInverse.rightInvOn {g : β → α} (h : RightInverse f g) (s : Set α) :
RightInvOn f g s := fun x _ => h x
theorem LeftInverse.rightInvOn_range {g : β → α} (h : LeftInverse f g) :
RightInvOn f g (range g) :=
forall_mem_range.2 fun i => congr_arg g (h i)
namespace Semiconj
theorem mapsTo_image (h : Semiconj f fa fb) (ha : MapsTo fa s t) : MapsTo fb (f '' s) (f '' t) :=
fun _y ⟨x, hx, hy⟩ => hy ▸ ⟨fa x, ha hx, h x⟩
theorem mapsTo_image_right {t : Set β} (h : Semiconj f fa fb) (hst : MapsTo f s t) :
MapsTo f (fa '' s) (fb '' t) :=
mapsTo_image_iff.2 fun x hx ↦ ⟨f x, hst hx, (h x).symm⟩
theorem mapsTo_range (h : Semiconj f fa fb) : MapsTo fb (range f) (range f) := fun _y ⟨x, hy⟩ =>
hy ▸ ⟨fa x, h x⟩
theorem surjOn_image (h : Semiconj f fa fb) (ha : SurjOn fa s t) : SurjOn fb (f '' s) (f '' t) := by
rintro y ⟨x, hxt, rfl⟩
rcases ha hxt with ⟨x, hxs, rfl⟩
rw [h x]
exact mem_image_of_mem _ (mem_image_of_mem _ hxs)
theorem surjOn_range (h : Semiconj f fa fb) (ha : Surjective fa) :
SurjOn fb (range f) (range f) := by
rw [← image_univ]
exact h.surjOn_image (ha.surjOn univ)
theorem injOn_image (h : Semiconj f fa fb) (ha : InjOn fa s) (hf : InjOn f (fa '' s)) :
InjOn fb (f '' s) := by
rintro _ ⟨x, hx, rfl⟩ _ ⟨y, hy, rfl⟩ H
simp only [← h.eq] at H
exact congr_arg f (ha hx hy <| hf (mem_image_of_mem fa hx) (mem_image_of_mem fa hy) H)
theorem injOn_range (h : Semiconj f fa fb) (ha : Injective fa) (hf : InjOn f (range fa)) :
InjOn fb (range f) := by
rw [← image_univ] at *
exact h.injOn_image ha.injOn hf
theorem bijOn_image (h : Semiconj f fa fb) (ha : BijOn fa s t) (hf : InjOn f t) :
BijOn fb (f '' s) (f '' t) :=
⟨h.mapsTo_image ha.mapsTo, h.injOn_image ha.injOn (ha.image_eq.symm ▸ hf),
h.surjOn_image ha.surjOn⟩
theorem bijOn_range (h : Semiconj f fa fb) (ha : Bijective fa) (hf : Injective f) :
BijOn fb (range f) (range f) := by
rw [← image_univ]
exact h.bijOn_image (bijective_iff_bijOn_univ.1 ha) hf.injOn
theorem mapsTo_preimage (h : Semiconj f fa fb) {s t : Set β} (hb : MapsTo fb s t) :
MapsTo fa (f ⁻¹' s) (f ⁻¹' t) := fun x hx => by simp only [mem_preimage, h x, hb hx]
theorem injOn_preimage (h : Semiconj f fa fb) {s : Set β} (hb : InjOn fb s)
(hf : InjOn f (f ⁻¹' s)) : InjOn fa (f ⁻¹' s) := by
intro x hx y hy H
have := congr_arg f H
rw [h.eq, h.eq] at this
exact hf hx hy (hb hx hy this)
end Semiconj
theorem update_comp_eq_of_not_mem_range' {α : Sort*} {β : Type*} {γ : β → Sort*} [DecidableEq β]
(g : ∀ b, γ b) {f : α → β} {i : β} (a : γ i) (h : i ∉ Set.range f) :
(fun j => update g i a (f j)) = fun j => g (f j) :=
(update_comp_eq_of_forall_ne' _ _) fun x hx => h ⟨x, hx⟩
/-- Non-dependent version of `Function.update_comp_eq_of_not_mem_range'` -/
theorem update_comp_eq_of_not_mem_range {α : Sort*} {β : Type*} {γ : Sort*} [DecidableEq β]
(g : β → γ) {f : α → β} {i : β} (a : γ) (h : i ∉ Set.range f) : update g i a ∘ f = g ∘ f :=
update_comp_eq_of_not_mem_range' g a h
theorem insert_injOn (s : Set α) : sᶜ.InjOn fun a => insert a s := fun _a ha _ _ =>
(insert_inj ha).1
lemma apply_eq_of_range_eq_singleton {f : α → β} {b : β} (h : range f = {b}) (a : α) :
f a = b := by
simpa only [h, mem_singleton_iff] using mem_range_self (f := f) a
end Function
/-! ### Equivalences, permutations -/
namespace Set
variable {p : β → Prop} [DecidablePred p] {f : α ≃ Subtype p} {g g₁ g₂ : Perm α} {s t : Set α}
protected lemma MapsTo.extendDomain (h : MapsTo g s t) :
MapsTo (g.extendDomain f) ((↑) ∘ f '' s) ((↑) ∘ f '' t) := by
rintro _ ⟨a, ha, rfl⟩; exact ⟨_, h ha, by simp_rw [Function.comp_apply, extendDomain_apply_image]⟩
protected lemma SurjOn.extendDomain (h : SurjOn g s t) :
SurjOn (g.extendDomain f) ((↑) ∘ f '' s) ((↑) ∘ f '' t) := by
rintro _ ⟨a, ha, rfl⟩
obtain ⟨b, hb, rfl⟩ := h ha
exact ⟨_, ⟨_, hb, rfl⟩, by simp_rw [Function.comp_apply, extendDomain_apply_image]⟩
protected lemma BijOn.extendDomain (h : BijOn g s t) :
BijOn (g.extendDomain f) ((↑) ∘ f '' s) ((↑) ∘ f '' t) :=
⟨h.mapsTo.extendDomain, (g.extendDomain f).injective.injOn, h.surjOn.extendDomain⟩
protected lemma LeftInvOn.extendDomain (h : LeftInvOn g₁ g₂ s) :
LeftInvOn (g₁.extendDomain f) (g₂.extendDomain f) ((↑) ∘ f '' s) := by
rintro _ ⟨a, ha, rfl⟩; simp_rw [Function.comp_apply, extendDomain_apply_image, h ha]
protected lemma RightInvOn.extendDomain (h : RightInvOn g₁ g₂ t) :
RightInvOn (g₁.extendDomain f) (g₂.extendDomain f) ((↑) ∘ f '' t) := by
rintro _ ⟨a, ha, rfl⟩; simp_rw [Function.comp_apply, extendDomain_apply_image, h ha]
protected lemma InvOn.extendDomain (h : InvOn g₁ g₂ s t) :
InvOn (g₁.extendDomain f) (g₂.extendDomain f) ((↑) ∘ f '' s) ((↑) ∘ f '' t) :=
⟨h.1.extendDomain, h.2.extendDomain⟩
end Set
namespace Set
variable {α₁ α₂ β₁ β₂ : Type*} {s₁ : Set α₁} {s₂ : Set α₂} {t₁ : Set β₁} {t₂ : Set β₂}
{f₁ : α₁ → β₁} {f₂ : α₂ → β₂} {g₁ : β₁ → α₁} {g₂ : β₂ → α₂}
lemma InjOn.prodMap (h₁ : s₁.InjOn f₁) (h₂ : s₂.InjOn f₂) :
(s₁ ×ˢ s₂).InjOn fun x ↦ (f₁ x.1, f₂ x.2) :=
fun x hx y hy ↦ by simp_rw [Prod.ext_iff]; exact And.imp (h₁ hx.1 hy.1) (h₂ hx.2 hy.2)
lemma SurjOn.prodMap (h₁ : SurjOn f₁ s₁ t₁) (h₂ : SurjOn f₂ s₂ t₂) :
SurjOn (fun x ↦ (f₁ x.1, f₂ x.2)) (s₁ ×ˢ s₂) (t₁ ×ˢ t₂) := by
rintro x hx
obtain ⟨a₁, ha₁, hx₁⟩ := h₁ hx.1
obtain ⟨a₂, ha₂, hx₂⟩ := h₂ hx.2
exact ⟨(a₁, a₂), ⟨ha₁, ha₂⟩, Prod.ext hx₁ hx₂⟩
lemma MapsTo.prodMap (h₁ : MapsTo f₁ s₁ t₁) (h₂ : MapsTo f₂ s₂ t₂) :
MapsTo (fun x ↦ (f₁ x.1, f₂ x.2)) (s₁ ×ˢ s₂) (t₁ ×ˢ t₂) :=
fun _x hx ↦ ⟨h₁ hx.1, h₂ hx.2⟩
lemma BijOn.prodMap (h₁ : BijOn f₁ s₁ t₁) (h₂ : BijOn f₂ s₂ t₂) :
BijOn (fun x ↦ (f₁ x.1, f₂ x.2)) (s₁ ×ˢ s₂) (t₁ ×ˢ t₂) :=
⟨h₁.mapsTo.prodMap h₂.mapsTo, h₁.injOn.prodMap h₂.injOn, h₁.surjOn.prodMap h₂.surjOn⟩
lemma LeftInvOn.prodMap (h₁ : LeftInvOn g₁ f₁ s₁) (h₂ : LeftInvOn g₂ f₂ s₂) :
LeftInvOn (fun x ↦ (g₁ x.1, g₂ x.2)) (fun x ↦ (f₁ x.1, f₂ x.2)) (s₁ ×ˢ s₂) :=
fun _x hx ↦ Prod.ext (h₁ hx.1) (h₂ hx.2)
lemma RightInvOn.prodMap (h₁ : RightInvOn g₁ f₁ t₁) (h₂ : RightInvOn g₂ f₂ t₂) :
RightInvOn (fun x ↦ (g₁ x.1, g₂ x.2)) (fun x ↦ (f₁ x.1, f₂ x.2)) (t₁ ×ˢ t₂) :=
fun _x hx ↦ Prod.ext (h₁ hx.1) (h₂ hx.2)
lemma InvOn.prodMap (h₁ : InvOn g₁ f₁ s₁ t₁) (h₂ : InvOn g₂ f₂ s₂ t₂) :
InvOn (fun x ↦ (g₁ x.1, g₂ x.2)) (fun x ↦ (f₁ x.1, f₂ x.2)) (s₁ ×ˢ s₂) (t₁ ×ˢ t₂) :=
⟨h₁.1.prodMap h₂.1, h₁.2.prodMap h₂.2⟩
end Set
namespace Equiv
open Set
variable (e : α ≃ β) {s : Set α} {t : Set β}
lemma bijOn' (h₁ : MapsTo e s t) (h₂ : MapsTo e.symm t s) : BijOn e s t :=
⟨h₁, e.injective.injOn, fun b hb ↦ ⟨e.symm b, h₂ hb, apply_symm_apply _ _⟩⟩
protected lemma bijOn (h : ∀ a, e a ∈ t ↔ a ∈ s) : BijOn e s t :=
e.bijOn' (fun _ ↦ (h _).2) fun b hb ↦ (h _).1 <| by rwa [apply_symm_apply]
lemma invOn : InvOn e e.symm t s :=
⟨e.rightInverse_symm.leftInvOn _, e.leftInverse_symm.leftInvOn _⟩
lemma bijOn_image : BijOn e s (e '' s) := e.injective.injOn.bijOn_image
lemma bijOn_symm_image : BijOn e.symm (e '' s) s := e.bijOn_image.symm e.invOn
variable {e}
@[simp] lemma bijOn_symm : BijOn e.symm t s ↔ BijOn e s t := bijOn_comm e.symm.invOn
alias ⟨_root_.Set.BijOn.of_equiv_symm, _root_.Set.BijOn.equiv_symm⟩ := bijOn_symm
variable [DecidableEq α] {a b : α}
lemma bijOn_swap (ha : a ∈ s) (hb : b ∈ s) : BijOn (swap a b) s s :=
(swap a b).bijOn fun x ↦ by
obtain rfl | hxa := eq_or_ne x a <;>
obtain rfl | hxb := eq_or_ne x b <;>
simp [*, swap_apply_of_ne_of_ne]
end Equiv
| Mathlib/Data/Set/Function.lean | 1,953 | 1,955 | |
/-
Copyright (c) 2018 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Kevin Kappelmann
-/
import Mathlib.Algebra.Order.Floor.Defs
import Mathlib.Algebra.Order.Floor.Ring
import Mathlib.Algebra.Order.Floor.Semiring
deprecated_module (since := "2025-04-13")
| Mathlib/Algebra/Order/Floor.lean | 296 | 297 | |
/-
Copyright (c) 2017 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Floris van Doorn, Violeta Hernández Palacios
-/
import Mathlib.SetTheory.Cardinal.Arithmetic
import Mathlib.SetTheory.Ordinal.FixedPoint
/-!
# Cofinality
This file contains the definition of cofinality of an order and an ordinal number.
## Main Definitions
* `Order.cof r` is the cofinality of a reflexive order. This is the smallest cardinality of a subset
`s` that is *cofinal*, i.e. `∀ x, ∃ y ∈ s, r x y`.
* `Ordinal.cof o` is the cofinality of the ordinal `o` when viewed as a linear order.
## Main Statements
* `Cardinal.lt_power_cof`: A consequence of König's theorem stating that `c < c ^ c.ord.cof` for
`c ≥ ℵ₀`.
## Implementation Notes
* The cofinality is defined for ordinals.
If `c` is a cardinal number, its cofinality is `c.ord.cof`.
-/
noncomputable section
open Function Cardinal Set Order
open scoped Ordinal
universe u v w
variable {α : Type u} {β : Type v} {r : α → α → Prop} {s : β → β → Prop}
/-! ### Cofinality of orders -/
attribute [local instance] IsRefl.swap
namespace Order
/-- Cofinality of a reflexive order `≼`. This is the smallest cardinality
of a subset `S : Set α` such that `∀ a, ∃ b ∈ S, a ≼ b`. -/
def cof (r : α → α → Prop) : Cardinal :=
sInf { c | ∃ S : Set α, (∀ a, ∃ b ∈ S, r a b) ∧ #S = c }
/-- The set in the definition of `Order.cof` is nonempty. -/
private theorem cof_nonempty (r : α → α → Prop) [IsRefl α r] :
{ c | ∃ S : Set α, (∀ a, ∃ b ∈ S, r a b) ∧ #S = c }.Nonempty :=
⟨_, Set.univ, fun a => ⟨a, ⟨⟩, refl _⟩, rfl⟩
theorem cof_le (r : α → α → Prop) {S : Set α} (h : ∀ a, ∃ b ∈ S, r a b) : cof r ≤ #S :=
csInf_le' ⟨S, h, rfl⟩
theorem le_cof [IsRefl α r] (c : Cardinal) :
c ≤ cof r ↔ ∀ {S : Set α}, (∀ a, ∃ b ∈ S, r a b) → c ≤ #S := by
rw [cof, le_csInf_iff'' (cof_nonempty r)]
use fun H S h => H _ ⟨S, h, rfl⟩
rintro H d ⟨S, h, rfl⟩
exact H h
end Order
namespace RelIso
private theorem cof_le_lift [IsRefl β s] (f : r ≃r s) :
Cardinal.lift.{v} (Order.cof r) ≤ Cardinal.lift.{u} (Order.cof s) := by
rw [Order.cof, Order.cof, lift_sInf, lift_sInf, le_csInf_iff'' ((Order.cof_nonempty s).image _)]
rintro - ⟨-, ⟨u, H, rfl⟩, rfl⟩
apply csInf_le'
refine ⟨_, ⟨f.symm '' u, fun a => ?_, rfl⟩, lift_mk_eq'.2 ⟨(f.symm.toEquiv.image u).symm⟩⟩
rcases H (f a) with ⟨b, hb, hb'⟩
refine ⟨f.symm b, mem_image_of_mem _ hb, f.map_rel_iff.1 ?_⟩
rwa [RelIso.apply_symm_apply]
theorem cof_eq_lift [IsRefl β s] (f : r ≃r s) :
Cardinal.lift.{v} (Order.cof r) = Cardinal.lift.{u} (Order.cof s) :=
have := f.toRelEmbedding.isRefl
(f.cof_le_lift).antisymm (f.symm.cof_le_lift)
theorem cof_eq {α β : Type u} {r : α → α → Prop} {s} [IsRefl β s] (f : r ≃r s) :
Order.cof r = Order.cof s :=
lift_inj.1 (f.cof_eq_lift)
end RelIso
/-! ### Cofinality of ordinals -/
namespace Ordinal
/-- Cofinality of an ordinal. This is the smallest cardinal of a subset `S` of the ordinal which is
unbounded, in the sense `∀ a, ∃ b ∈ S, a ≤ b`.
In particular, `cof 0 = 0` and `cof (succ o) = 1`. -/
def cof (o : Ordinal.{u}) : Cardinal.{u} :=
o.liftOn (fun a ↦ Order.cof (swap a.rᶜ)) fun _ _ ⟨f⟩ ↦ f.compl.swap.cof_eq
theorem cof_type (r : α → α → Prop) [IsWellOrder α r] : (type r).cof = Order.cof (swap rᶜ) :=
rfl
theorem cof_type_lt [LinearOrder α] [IsWellOrder α (· < ·)] :
(@type α (· < ·) _).cof = @Order.cof α (· ≤ ·) := by
rw [cof_type, compl_lt, swap_ge]
theorem cof_eq_cof_toType (o : Ordinal) : o.cof = @Order.cof o.toType (· ≤ ·) := by
conv_lhs => rw [← type_toType o, cof_type_lt]
theorem le_cof_type [IsWellOrder α r] {c} : c ≤ cof (type r) ↔ ∀ S, Unbounded r S → c ≤ #S :=
(le_csInf_iff'' (Order.cof_nonempty _)).trans
⟨fun H S h => H _ ⟨S, h, rfl⟩, by
rintro H d ⟨S, h, rfl⟩
exact H _ h⟩
theorem cof_type_le [IsWellOrder α r] {S : Set α} (h : Unbounded r S) : cof (type r) ≤ #S :=
le_cof_type.1 le_rfl S h
theorem lt_cof_type [IsWellOrder α r] {S : Set α} : #S < cof (type r) → Bounded r S := by
simpa using not_imp_not.2 cof_type_le
theorem cof_eq (r : α → α → Prop) [IsWellOrder α r] : ∃ S, Unbounded r S ∧ #S = cof (type r) :=
csInf_mem (Order.cof_nonempty (swap rᶜ))
theorem ord_cof_eq (r : α → α → Prop) [IsWellOrder α r] :
∃ S, Unbounded r S ∧ type (Subrel r (· ∈ S)) = (cof (type r)).ord := by
let ⟨S, hS, e⟩ := cof_eq r
let ⟨s, _, e'⟩ := Cardinal.ord_eq S
let T : Set α := { a | ∃ aS : a ∈ S, ∀ b : S, s b ⟨_, aS⟩ → r b a }
suffices Unbounded r T by
refine ⟨T, this, le_antisymm ?_ (Cardinal.ord_le.2 <| cof_type_le this)⟩
rw [← e, e']
refine
(RelEmbedding.ofMonotone
(fun a : T =>
(⟨a,
let ⟨aS, _⟩ := a.2
aS⟩ :
S))
fun a b h => ?_).ordinal_type_le
rcases a with ⟨a, aS, ha⟩
rcases b with ⟨b, bS, hb⟩
change s ⟨a, _⟩ ⟨b, _⟩
refine ((trichotomous_of s _ _).resolve_left fun hn => ?_).resolve_left ?_
· exact asymm h (ha _ hn)
· intro e
injection e with e
subst b
exact irrefl _ h
intro a
have : { b : S | ¬r b a }.Nonempty :=
let ⟨b, bS, ba⟩ := hS a
⟨⟨b, bS⟩, ba⟩
let b := (IsWellFounded.wf : WellFounded s).min _ this
have ba : ¬r b a := IsWellFounded.wf.min_mem _ this
refine ⟨b, ⟨b.2, fun c => not_imp_not.1 fun h => ?_⟩, ba⟩
rw [show ∀ b : S, (⟨b, b.2⟩ : S) = b by intro b; cases b; rfl]
exact IsWellFounded.wf.not_lt_min _ this (IsOrderConnected.neg_trans h ba)
/-! ### Cofinality of suprema and least strict upper bounds -/
private theorem card_mem_cof {o} : ∃ (ι : _) (f : ι → Ordinal), lsub.{u, u} f = o ∧ #ι = o.card :=
⟨_, _, lsub_typein o, mk_toType o⟩
/-- The set in the `lsub` characterization of `cof` is nonempty. -/
theorem cof_lsub_def_nonempty (o) :
{ a : Cardinal | ∃ (ι : _) (f : ι → Ordinal), lsub.{u, u} f = o ∧ #ι = a }.Nonempty :=
⟨_, card_mem_cof⟩
theorem cof_eq_sInf_lsub (o : Ordinal.{u}) : cof o =
sInf { a : Cardinal | ∃ (ι : Type u) (f : ι → Ordinal), lsub.{u, u} f = o ∧ #ι = a } := by
refine le_antisymm (le_csInf (cof_lsub_def_nonempty o) ?_) (csInf_le' ?_)
· rintro a ⟨ι, f, hf, rfl⟩
rw [← type_toType o]
refine
(cof_type_le fun a => ?_).trans
(@mk_le_of_injective _ _
(fun s : typein ((· < ·) : o.toType → o.toType → Prop) ⁻¹' Set.range f =>
Classical.choose s.prop)
fun s t hst => by
let H := congr_arg f hst
rwa [Classical.choose_spec s.prop, Classical.choose_spec t.prop, typein_inj,
Subtype.coe_inj] at H)
have := typein_lt_self a
simp_rw [← hf, lt_lsub_iff] at this
obtain ⟨i, hi⟩ := this
refine ⟨enum (α := o.toType) (· < ·) ⟨f i, ?_⟩, ?_, ?_⟩
· rw [type_toType, ← hf]
apply lt_lsub
· rw [mem_preimage, typein_enum]
exact mem_range_self i
· rwa [← typein_le_typein, typein_enum]
· rcases cof_eq (α := o.toType) (· < ·) with ⟨S, hS, hS'⟩
let f : S → Ordinal := fun s => typein LT.lt s.val
refine ⟨S, f, le_antisymm (lsub_le fun i => typein_lt_self (o := o) i)
(le_of_forall_lt fun a ha => ?_), by rwa [type_toType o] at hS'⟩
rw [← type_toType o] at ha
rcases hS (enum (· < ·) ⟨a, ha⟩) with ⟨b, hb, hb'⟩
rw [← typein_le_typein, typein_enum] at hb'
exact hb'.trans_lt (lt_lsub.{u, u} f ⟨b, hb⟩)
@[simp]
theorem lift_cof (o) : Cardinal.lift.{u, v} (cof o) = cof (Ordinal.lift.{u, v} o) := by
refine inductionOn o fun α r _ ↦ ?_
rw [← type_uLift, cof_type, cof_type, ← Cardinal.lift_id'.{v, u} (Order.cof _),
← Cardinal.lift_umax]
apply RelIso.cof_eq_lift ⟨Equiv.ulift.symm, _⟩
simp [swap]
theorem cof_le_card (o) : cof o ≤ card o := by
rw [cof_eq_sInf_lsub]
exact csInf_le' card_mem_cof
theorem cof_ord_le (c : Cardinal) : c.ord.cof ≤ c := by simpa using cof_le_card c.ord
theorem ord_cof_le (o : Ordinal.{u}) : o.cof.ord ≤ o :=
(ord_le_ord.2 (cof_le_card o)).trans (ord_card_le o)
theorem exists_lsub_cof (o : Ordinal) :
∃ (ι : _) (f : ι → Ordinal), lsub.{u, u} f = o ∧ #ι = cof o := by
rw [cof_eq_sInf_lsub]
exact csInf_mem (cof_lsub_def_nonempty o)
theorem cof_lsub_le {ι} (f : ι → Ordinal) : cof (lsub.{u, u} f) ≤ #ι := by
rw [cof_eq_sInf_lsub]
exact csInf_le' ⟨ι, f, rfl, rfl⟩
theorem cof_lsub_le_lift {ι} (f : ι → Ordinal) :
cof (lsub.{u, v} f) ≤ Cardinal.lift.{v, u} #ι := by
rw [← mk_uLift.{u, v}]
convert cof_lsub_le.{max u v} fun i : ULift.{v, u} ι => f i.down
exact
lsub_eq_of_range_eq.{u, max u v, max u v}
(Set.ext fun x => ⟨fun ⟨i, hi⟩ => ⟨ULift.up.{v, u} i, hi⟩, fun ⟨i, hi⟩ => ⟨_, hi⟩⟩)
theorem le_cof_iff_lsub {o : Ordinal} {a : Cardinal} :
a ≤ cof o ↔ ∀ {ι} (f : ι → Ordinal), lsub.{u, u} f = o → a ≤ #ι := by
rw [cof_eq_sInf_lsub]
exact
(le_csInf_iff'' (cof_lsub_def_nonempty o)).trans
⟨fun H ι f hf => H _ ⟨ι, f, hf, rfl⟩, fun H b ⟨ι, f, hf, hb⟩ => by
rw [← hb]
exact H _ hf⟩
theorem lsub_lt_ord_lift {ι} {f : ι → Ordinal} {c : Ordinal}
(hι : Cardinal.lift.{v, u} #ι < c.cof)
(hf : ∀ i, f i < c) : lsub.{u, v} f < c :=
lt_of_le_of_ne (lsub_le hf) fun h => by
subst h
exact (cof_lsub_le_lift.{u, v} f).not_lt hι
theorem lsub_lt_ord {ι} {f : ι → Ordinal} {c : Ordinal} (hι : #ι < c.cof) :
(∀ i, f i < c) → lsub.{u, u} f < c :=
lsub_lt_ord_lift (by rwa [(#ι).lift_id])
theorem cof_iSup_le_lift {ι} {f : ι → Ordinal} (H : ∀ i, f i < iSup f) :
cof (iSup f) ≤ Cardinal.lift.{v, u} #ι := by
rw [← Ordinal.sup] at *
rw [← sup_eq_lsub_iff_lt_sup.{u, v}] at H
rw [H]
exact cof_lsub_le_lift f
theorem cof_iSup_le {ι} {f : ι → Ordinal} (H : ∀ i, f i < iSup f) :
cof (iSup f) ≤ #ι := by
rw [← (#ι).lift_id]
exact cof_iSup_le_lift H
theorem iSup_lt_ord_lift {ι} {f : ι → Ordinal} {c : Ordinal} (hι : Cardinal.lift.{v, u} #ι < c.cof)
(hf : ∀ i, f i < c) : iSup f < c :=
(sup_le_lsub.{u, v} f).trans_lt (lsub_lt_ord_lift hι hf)
theorem iSup_lt_ord {ι} {f : ι → Ordinal} {c : Ordinal} (hι : #ι < c.cof) :
(∀ i, f i < c) → iSup f < c :=
iSup_lt_ord_lift (by rwa [(#ι).lift_id])
theorem iSup_lt_lift {ι} {f : ι → Cardinal} {c : Cardinal}
(hι : Cardinal.lift.{v, u} #ι < c.ord.cof)
(hf : ∀ i, f i < c) : iSup f < c := by
rw [← ord_lt_ord, iSup_ord (Cardinal.bddAbove_range _)]
refine iSup_lt_ord_lift hι fun i => ?_
rw [ord_lt_ord]
apply hf
theorem iSup_lt {ι} {f : ι → Cardinal} {c : Cardinal} (hι : #ι < c.ord.cof) :
(∀ i, f i < c) → iSup f < c :=
iSup_lt_lift (by rwa [(#ι).lift_id])
theorem nfpFamily_lt_ord_lift {ι} {f : ι → Ordinal → Ordinal} {c} (hc : ℵ₀ < cof c)
(hc' : Cardinal.lift.{v, u} #ι < cof c) (hf : ∀ (i), ∀ b < c, f i b < c) {a} (ha : a < c) :
nfpFamily f a < c := by
refine iSup_lt_ord_lift ((Cardinal.lift_le.2 (mk_list_le_max ι)).trans_lt ?_) fun l => ?_
· rw [lift_max]
apply max_lt _ hc'
rwa [Cardinal.lift_aleph0]
· induction' l with i l H
· exact ha
· exact hf _ _ H
theorem nfpFamily_lt_ord {ι} {f : ι → Ordinal → Ordinal} {c} (hc : ℵ₀ < cof c) (hc' : #ι < cof c)
(hf : ∀ (i), ∀ b < c, f i b < c) {a} : a < c → nfpFamily.{u, u} f a < c :=
nfpFamily_lt_ord_lift hc (by rwa [(#ι).lift_id]) hf
theorem nfp_lt_ord {f : Ordinal → Ordinal} {c} (hc : ℵ₀ < cof c) (hf : ∀ i < c, f i < c) {a} :
a < c → nfp f a < c :=
nfpFamily_lt_ord_lift hc (by simpa using Cardinal.one_lt_aleph0.trans hc) fun _ => hf
theorem exists_blsub_cof (o : Ordinal) :
∃ f : ∀ a < (cof o).ord, Ordinal, blsub.{u, u} _ f = o := by
rcases exists_lsub_cof o with ⟨ι, f, hf, hι⟩
rcases Cardinal.ord_eq ι with ⟨r, hr, hι'⟩
rw [← @blsub_eq_lsub' ι r hr] at hf
rw [← hι, hι']
exact ⟨_, hf⟩
theorem le_cof_iff_blsub {b : Ordinal} {a : Cardinal} :
a ≤ cof b ↔ ∀ {o} (f : ∀ a < o, Ordinal), blsub.{u, u} o f = b → a ≤ o.card :=
le_cof_iff_lsub.trans
⟨fun H o f hf => by simpa using H _ hf, fun H ι f hf => by
rcases Cardinal.ord_eq ι with ⟨r, hr, hι'⟩
rw [← @blsub_eq_lsub' ι r hr] at hf
simpa using H _ hf⟩
theorem cof_blsub_le_lift {o} (f : ∀ a < o, Ordinal) :
cof (blsub.{u, v} o f) ≤ Cardinal.lift.{v, u} o.card := by
rw [← mk_toType o]
exact cof_lsub_le_lift _
theorem cof_blsub_le {o} (f : ∀ a < o, Ordinal) : cof (blsub.{u, u} o f) ≤ o.card := by
rw [← o.card.lift_id]
exact cof_blsub_le_lift f
theorem blsub_lt_ord_lift {o : Ordinal.{u}} {f : ∀ a < o, Ordinal} {c : Ordinal}
(ho : Cardinal.lift.{v, u} o.card < c.cof) (hf : ∀ i hi, f i hi < c) : blsub.{u, v} o f < c :=
lt_of_le_of_ne (blsub_le hf) fun h =>
ho.not_le (by simpa [← iSup_ord, hf, h] using cof_blsub_le_lift.{u, v} f)
theorem blsub_lt_ord {o : Ordinal} {f : ∀ a < o, Ordinal} {c : Ordinal} (ho : o.card < c.cof)
(hf : ∀ i hi, f i hi < c) : blsub.{u, u} o f < c :=
blsub_lt_ord_lift (by rwa [o.card.lift_id]) hf
theorem cof_bsup_le_lift {o : Ordinal} {f : ∀ a < o, Ordinal} (H : ∀ i h, f i h < bsup.{u, v} o f) :
cof (bsup.{u, v} o f) ≤ Cardinal.lift.{v, u} o.card := by
rw [← bsup_eq_blsub_iff_lt_bsup.{u, v}] at H
rw [H]
exact cof_blsub_le_lift.{u, v} f
theorem cof_bsup_le {o : Ordinal} {f : ∀ a < o, Ordinal} :
(∀ i h, f i h < bsup.{u, u} o f) → cof (bsup.{u, u} o f) ≤ o.card := by
rw [← o.card.lift_id]
exact cof_bsup_le_lift
theorem bsup_lt_ord_lift {o : Ordinal} {f : ∀ a < o, Ordinal} {c : Ordinal}
(ho : Cardinal.lift.{v, u} o.card < c.cof) (hf : ∀ i hi, f i hi < c) : bsup.{u, v} o f < c :=
(bsup_le_blsub f).trans_lt (blsub_lt_ord_lift ho hf)
theorem bsup_lt_ord {o : Ordinal} {f : ∀ a < o, Ordinal} {c : Ordinal} (ho : o.card < c.cof) :
(∀ i hi, f i hi < c) → bsup.{u, u} o f < c :=
bsup_lt_ord_lift (by rwa [o.card.lift_id])
/-! ### Basic results -/
@[simp]
theorem cof_zero : cof 0 = 0 := by
refine LE.le.antisymm ?_ (Cardinal.zero_le _)
rw [← card_zero]
exact cof_le_card 0
@[simp]
theorem cof_eq_zero {o} : cof o = 0 ↔ o = 0 :=
⟨inductionOn o fun _ r _ z =>
let ⟨_, hl, e⟩ := cof_eq r
type_eq_zero_iff_isEmpty.2 <|
⟨fun a =>
let ⟨_, h, _⟩ := hl a
(mk_eq_zero_iff.1 (e.trans z)).elim' ⟨_, h⟩⟩,
fun e => by simp [e]⟩
theorem cof_ne_zero {o} : cof o ≠ 0 ↔ o ≠ 0 :=
cof_eq_zero.not
@[simp]
theorem cof_succ (o) : cof (succ o) = 1 := by
apply le_antisymm
· refine inductionOn o fun α r _ => ?_
change cof (type _) ≤ _
rw [← (_ : #_ = 1)]
· apply cof_type_le
refine fun a => ⟨Sum.inr PUnit.unit, Set.mem_singleton _, ?_⟩
rcases a with (a | ⟨⟨⟨⟩⟩⟩) <;> simp [EmptyRelation]
· rw [Cardinal.mk_fintype, Set.card_singleton]
simp
· rw [← Cardinal.succ_zero, succ_le_iff]
simpa [lt_iff_le_and_ne, Cardinal.zero_le] using fun h =>
succ_ne_zero o (cof_eq_zero.1 (Eq.symm h))
@[simp]
theorem cof_eq_one_iff_is_succ {o} : cof.{u} o = 1 ↔ ∃ a, o = succ a :=
⟨inductionOn o fun α r _ z => by
rcases cof_eq r with ⟨S, hl, e⟩; rw [z] at e
obtain ⟨a⟩ := mk_ne_zero_iff.1 (by rw [e]; exact one_ne_zero)
refine
⟨typein r a,
Eq.symm <|
Quotient.sound
⟨RelIso.ofSurjective (RelEmbedding.ofMonotone ?_ fun x y => ?_) fun x => ?_⟩⟩
· apply Sum.rec <;> [exact Subtype.val; exact fun _ => a]
· rcases x with (x | ⟨⟨⟨⟩⟩⟩) <;> rcases y with (y | ⟨⟨⟨⟩⟩⟩) <;>
simp [Subrel, Order.Preimage, EmptyRelation]
exact x.2
· suffices r x a ∨ ∃ _ : PUnit.{u}, ↑a = x by
convert this
dsimp [RelEmbedding.ofMonotone]; simp
rcases trichotomous_of r x a with (h | h | h)
· exact Or.inl h
· exact Or.inr ⟨PUnit.unit, h.symm⟩
· rcases hl x with ⟨a', aS, hn⟩
refine absurd h ?_
convert hn
change (a : α) = ↑(⟨a', aS⟩ : S)
have := le_one_iff_subsingleton.1 (le_of_eq e)
congr!,
fun ⟨a, e⟩ => by simp [e]⟩
/-! ### Fundamental sequences -/
-- TODO: move stuff about fundamental sequences to their own file.
/-- A fundamental sequence for `a` is an increasing sequence of length `o = cof a` that converges at
`a`. We provide `o` explicitly in order to avoid type rewrites. -/
def IsFundamentalSequence (a o : Ordinal.{u}) (f : ∀ b < o, Ordinal.{u}) : Prop :=
o ≤ a.cof.ord ∧ (∀ {i j} (hi hj), i < j → f i hi < f j hj) ∧ blsub.{u, u} o f = a
namespace IsFundamentalSequence
variable {a o : Ordinal.{u}} {f : ∀ b < o, Ordinal.{u}}
protected theorem cof_eq (hf : IsFundamentalSequence a o f) : a.cof.ord = o :=
hf.1.antisymm' <| by
rw [← hf.2.2]
exact (ord_le_ord.2 (cof_blsub_le f)).trans (ord_card_le o)
protected theorem strict_mono (hf : IsFundamentalSequence a o f) {i j} :
∀ hi hj, i < j → f i hi < f j hj :=
hf.2.1
theorem blsub_eq (hf : IsFundamentalSequence a o f) : blsub.{u, u} o f = a :=
hf.2.2
theorem ord_cof (hf : IsFundamentalSequence a o f) :
IsFundamentalSequence a a.cof.ord fun i hi => f i (hi.trans_le (by rw [hf.cof_eq])) := by
have H := hf.cof_eq
subst H
exact hf
theorem id_of_le_cof (h : o ≤ o.cof.ord) : IsFundamentalSequence o o fun a _ => a :=
⟨h, @fun _ _ _ _ => id, blsub_id o⟩
protected theorem zero {f : ∀ b < (0 : Ordinal), Ordinal} : IsFundamentalSequence 0 0 f :=
⟨by rw [cof_zero, ord_zero], @fun i _ hi => (Ordinal.not_lt_zero i hi).elim, blsub_zero f⟩
protected theorem succ : IsFundamentalSequence (succ o) 1 fun _ _ => o := by
refine ⟨?_, @fun i j hi hj h => ?_, blsub_const Ordinal.one_ne_zero o⟩
· rw [cof_succ, ord_one]
· rw [lt_one_iff_zero] at hi hj
rw [hi, hj] at h
exact h.false.elim
protected theorem monotone (hf : IsFundamentalSequence a o f) {i j : Ordinal} (hi : i < o)
(hj : j < o) (hij : i ≤ j) : f i hi ≤ f j hj := by
rcases lt_or_eq_of_le hij with (hij | rfl)
· exact (hf.2.1 hi hj hij).le
· rfl
theorem trans {a o o' : Ordinal.{u}} {f : ∀ b < o, Ordinal.{u}} (hf : IsFundamentalSequence a o f)
{g : ∀ b < o', Ordinal.{u}} (hg : IsFundamentalSequence o o' g) :
IsFundamentalSequence a o' fun i hi =>
f (g i hi) (by rw [← hg.2.2]; apply lt_blsub) := by
refine ⟨?_, @fun i j _ _ h => hf.2.1 _ _ (hg.2.1 _ _ h), ?_⟩
· rw [hf.cof_eq]
exact hg.1.trans (ord_cof_le o)
· rw [@blsub_comp.{u, u, u} o _ f (@IsFundamentalSequence.monotone _ _ f hf)]
· exact hf.2.2
· exact hg.2.2
protected theorem lt {a o : Ordinal} {s : Π p < o, Ordinal}
(h : IsFundamentalSequence a o s) {p : Ordinal} (hp : p < o) : s p hp < a :=
h.blsub_eq ▸ lt_blsub s p hp
end IsFundamentalSequence
/-- Every ordinal has a fundamental sequence. -/
theorem exists_fundamental_sequence (a : Ordinal.{u}) :
∃ f, IsFundamentalSequence a a.cof.ord f := by
suffices h : ∃ o f, IsFundamentalSequence a o f by
rcases h with ⟨o, f, hf⟩
exact ⟨_, hf.ord_cof⟩
rcases exists_lsub_cof a with ⟨ι, f, hf, hι⟩
rcases ord_eq ι with ⟨r, wo, hr⟩
haveI := wo
let r' := Subrel r fun i ↦ ∀ j, r j i → f j < f i
let hrr' : r' ↪r r := Subrel.relEmbedding _ _
haveI := hrr'.isWellOrder
refine
⟨_, _, hrr'.ordinal_type_le.trans ?_, @fun i j _ h _ => (enum r' ⟨j, h⟩).prop _ ?_,
le_antisymm (blsub_le fun i hi => lsub_le_iff.1 hf.le _) ?_⟩
· rw [← hι, hr]
· change r (hrr'.1 _) (hrr'.1 _)
rwa [hrr'.2, @enum_lt_enum _ r']
· rw [← hf, lsub_le_iff]
intro i
suffices h : ∃ i' hi', f i ≤ bfamilyOfFamily' r' (fun i => f i) i' hi' by
rcases h with ⟨i', hi', hfg⟩
exact hfg.trans_lt (lt_blsub _ _ _)
| by_cases h : ∀ j, r j i → f j < f i
· refine ⟨typein r' ⟨i, h⟩, typein_lt_type _ _, ?_⟩
rw [bfamilyOfFamily'_typein]
· push_neg at h
obtain ⟨hji, hij⟩ := wo.wf.min_mem _ h
refine ⟨typein r' ⟨_, fun k hkj => lt_of_lt_of_le ?_ hij⟩, typein_lt_type _ _, ?_⟩
· by_contra! H
exact (wo.wf.not_lt_min _ h ⟨IsTrans.trans _ _ _ hkj hji, H⟩) hkj
· rwa [bfamilyOfFamily'_typein]
@[simp]
theorem cof_cof (a : Ordinal.{u}) : cof (cof a).ord = cof a := by
obtain ⟨f, hf⟩ := exists_fundamental_sequence a
obtain ⟨g, hg⟩ := exists_fundamental_sequence a.cof.ord
exact ord_injective (hf.trans hg).cof_eq.symm
protected theorem IsNormal.isFundamentalSequence {f : Ordinal.{u} → Ordinal.{u}} (hf : IsNormal f)
{a o} (ha : IsLimit a) {g} (hg : IsFundamentalSequence a o g) :
IsFundamentalSequence (f a) o fun b hb => f (g b hb) := by
refine ⟨?_, @fun i j _ _ h => hf.strictMono (hg.2.1 _ _ h), ?_⟩
· rcases exists_lsub_cof (f a) with ⟨ι, f', hf', hι⟩
rw [← hg.cof_eq, ord_le_ord, ← hι]
suffices (lsub.{u, u} fun i => sInf { b : Ordinal | f' i ≤ f b }) = a by
rw [← this]
apply cof_lsub_le
have H : ∀ i, ∃ b < a, f' i ≤ f b := fun i => by
| Mathlib/SetTheory/Cardinal/Cofinality.lean | 516 | 541 |
/-
Copyright (c) 2019 Floris van Doorn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Floris van Doorn
-/
import Mathlib.Algebra.Order.Group.Pointwise.Interval
import Mathlib.Analysis.SpecificLimits.Basic
import Mathlib.Data.Rat.Cardinal
import Mathlib.SetTheory.Cardinal.Continuum
/-!
# The cardinality of the reals
This file shows that the real numbers have cardinality continuum, i.e. `#ℝ = 𝔠`.
We show that `#ℝ ≤ 𝔠` by noting that every real number is determined by a Cauchy-sequence of the
form `ℕ → ℚ`, which has cardinality `𝔠`. To show that `#ℝ ≥ 𝔠` we define an injection from
`{0, 1} ^ ℕ` to `ℝ` with `f ↦ Σ n, f n * (1 / 3) ^ n`.
We conclude that all intervals with distinct endpoints have cardinality continuum.
## Main definitions
* `Cardinal.cantorFunction` is the function that sends `f` in `{0, 1} ^ ℕ` to `ℝ` by
`f ↦ Σ' n, f n * (1 / 3) ^ n`
## Main statements
* `Cardinal.mk_real : #ℝ = 𝔠`: the reals have cardinality continuum.
* `Cardinal.not_countable_real`: the universal set of real numbers is not countable.
We can use this same proof to show that all the other sets in this file are not countable.
* 8 lemmas of the form `mk_Ixy_real` for `x,y ∈ {i,o,c}` state that intervals on the reals
have cardinality continuum.
## Notation
* `𝔠` : notation for `Cardinal.continuum` in locale `Cardinal`, defined in `SetTheory.Continuum`.
## Tags
continuum, cardinality, reals, cardinality of the reals
-/
open Nat Set
open Cardinal
noncomputable section
namespace Cardinal
variable {c : ℝ} {f g : ℕ → Bool} {n : ℕ}
/-- The body of the sum in `cantorFunction`.
`cantorFunctionAux c f n = c ^ n` if `f n = true`;
`cantorFunctionAux c f n = 0` if `f n = false`. -/
def cantorFunctionAux (c : ℝ) (f : ℕ → Bool) (n : ℕ) : ℝ :=
cond (f n) (c ^ n) 0
@[simp]
theorem cantorFunctionAux_true (h : f n = true) : cantorFunctionAux c f n = c ^ n := by
simp [cantorFunctionAux, h]
| @[simp]
theorem cantorFunctionAux_false (h : f n = false) : cantorFunctionAux c f n = 0 := by
| Mathlib/Data/Real/Cardinality.lean | 64 | 65 |
/-
Copyright (c) 2019 Kim Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kim Morrison
-/
import Mathlib.Algebra.Group.Pi.Basic
import Mathlib.CategoryTheory.Limits.Shapes.Products
import Mathlib.CategoryTheory.Limits.Shapes.Images
import Mathlib.CategoryTheory.IsomorphismClasses
import Mathlib.CategoryTheory.Limits.Shapes.ZeroObjects
/-!
# Zero morphisms and zero objects
A category "has zero morphisms" if there is a designated "zero morphism" in each morphism space,
and compositions of zero morphisms with anything give the zero morphism. (Notice this is extra
structure, not merely a property.)
A category "has a zero object" if it has an object which is both initial and terminal. Having a
zero object provides zero morphisms, as the unique morphisms factoring through the zero object.
## References
* https://en.wikipedia.org/wiki/Zero_morphism
* [F. Borceux, *Handbook of Categorical Algebra 2*][borceux-vol2]
-/
noncomputable section
universe w v v' u u'
open CategoryTheory
open CategoryTheory.Category
namespace CategoryTheory.Limits
variable (C : Type u) [Category.{v} C]
variable (D : Type u') [Category.{v'} D]
/-- A category "has zero morphisms" if there is a designated "zero morphism" in each morphism space,
and compositions of zero morphisms with anything give the zero morphism. -/
class HasZeroMorphisms where
/-- Every morphism space has zero -/
[zero : ∀ X Y : C, Zero (X ⟶ Y)]
/-- `f` composed with `0` is `0` -/
comp_zero : ∀ {X Y : C} (f : X ⟶ Y) (Z : C), f ≫ (0 : Y ⟶ Z) = (0 : X ⟶ Z) := by aesop_cat
/-- `0` composed with `f` is `0` -/
zero_comp : ∀ (X : C) {Y Z : C} (f : Y ⟶ Z), (0 : X ⟶ Y) ≫ f = (0 : X ⟶ Z) := by aesop_cat
attribute [instance] HasZeroMorphisms.zero
variable {C}
@[simp]
theorem comp_zero [HasZeroMorphisms C] {X Y : C} {f : X ⟶ Y} {Z : C} :
f ≫ (0 : Y ⟶ Z) = (0 : X ⟶ Z) :=
HasZeroMorphisms.comp_zero f Z
@[simp]
theorem zero_comp [HasZeroMorphisms C] {X : C} {Y Z : C} {f : Y ⟶ Z} :
(0 : X ⟶ Y) ≫ f = (0 : X ⟶ Z) :=
HasZeroMorphisms.zero_comp X f
instance hasZeroMorphismsPEmpty : HasZeroMorphisms (Discrete PEmpty) where
zero := by aesop_cat
instance hasZeroMorphismsPUnit : HasZeroMorphisms (Discrete PUnit) where
zero X Y := by repeat (constructor)
namespace HasZeroMorphisms
/-- This lemma will be immediately superseded by `ext`, below. -/
private theorem ext_aux (I J : HasZeroMorphisms C)
(w : ∀ X Y : C, (I.zero X Y).zero = (J.zero X Y).zero) : I = J := by
have : I.zero = J.zero := by
funext X Y
specialize w X Y
apply congrArg Zero.mk w
cases I; cases J
congr
· apply proof_irrel_heq
· apply proof_irrel_heq
/-- If you're tempted to use this lemma "in the wild", you should probably
carefully consider whether you've made a mistake in allowing two
instances of `HasZeroMorphisms` to exist at all.
See, particularly, the note on `zeroMorphismsOfZeroObject` below.
-/
theorem ext (I J : HasZeroMorphisms C) : I = J := by
apply ext_aux
intro X Y
have : (I.zero X Y).zero ≫ (J.zero Y Y).zero = (I.zero X Y).zero := by
apply I.zero_comp X (J.zero Y Y).zero
have that : (I.zero X Y).zero ≫ (J.zero Y Y).zero = (J.zero X Y).zero := by
apply J.comp_zero (I.zero X Y).zero Y
rw [← this, ← that]
instance : Subsingleton (HasZeroMorphisms C) :=
⟨ext⟩
end HasZeroMorphisms
open Opposite HasZeroMorphisms
instance hasZeroMorphismsOpposite [HasZeroMorphisms C] : HasZeroMorphisms Cᵒᵖ where
zero X Y := ⟨(0 : unop Y ⟶ unop X).op⟩
comp_zero f Z := congr_arg Quiver.Hom.op (HasZeroMorphisms.zero_comp (unop Z) f.unop)
zero_comp X {Y Z} (f : Y ⟶ Z) :=
congrArg Quiver.Hom.op (HasZeroMorphisms.comp_zero f.unop (unop X))
section
variable [HasZeroMorphisms C]
@[simp] lemma op_zero (X Y : C) : (0 : X ⟶ Y).op = 0 := rfl
@[simp] lemma unop_zero (X Y : Cᵒᵖ) : (0 : X ⟶ Y).unop = 0 := rfl
theorem zero_of_comp_mono {X Y Z : C} {f : X ⟶ Y} (g : Y ⟶ Z) [Mono g] (h : f ≫ g = 0) : f = 0 := by
rw [← zero_comp, cancel_mono] at h
exact h
theorem zero_of_epi_comp {X Y Z : C} (f : X ⟶ Y) {g : Y ⟶ Z} [Epi f] (h : f ≫ g = 0) : g = 0 := by
rw [← comp_zero, cancel_epi] at h
exact h
theorem eq_zero_of_image_eq_zero {X Y : C} {f : X ⟶ Y} [HasImage f] (w : image.ι f = 0) :
f = 0 := by rw [← image.fac f, w, HasZeroMorphisms.comp_zero]
theorem nonzero_image_of_nonzero {X Y : C} {f : X ⟶ Y} [HasImage f] (w : f ≠ 0) : image.ι f ≠ 0 :=
fun h => w (eq_zero_of_image_eq_zero h)
end
section
variable [HasZeroMorphisms D]
instance : HasZeroMorphisms (C ⥤ D) where
zero F G := ⟨{ app := fun _ => 0 }⟩
comp_zero := fun η H => by
ext X; dsimp; apply comp_zero
zero_comp := fun F {G H} η => by
ext X; dsimp; apply zero_comp
@[simp]
theorem zero_app (F G : C ⥤ D) (j : C) : (0 : F ⟶ G).app j = 0 := rfl
end
namespace IsZero
variable [HasZeroMorphisms C]
theorem eq_zero_of_src {X Y : C} (o : IsZero X) (f : X ⟶ Y) : f = 0 :=
o.eq_of_src _ _
theorem eq_zero_of_tgt {X Y : C} (o : IsZero Y) (f : X ⟶ Y) : f = 0 :=
o.eq_of_tgt _ _
theorem iff_id_eq_zero (X : C) : IsZero X ↔ 𝟙 X = 0 :=
⟨fun h => h.eq_of_src _ _, fun h =>
⟨fun Y => ⟨⟨⟨0⟩, fun f => by
rw [← id_comp f, ← id_comp (0 : X ⟶ Y), h, zero_comp, zero_comp]; simp only⟩⟩,
fun Y => ⟨⟨⟨0⟩, fun f => by
rw [← comp_id f, ← comp_id (0 : Y ⟶ X), h, comp_zero, comp_zero]; simp only ⟩⟩⟩⟩
theorem of_mono_zero (X Y : C) [Mono (0 : X ⟶ Y)] : IsZero X :=
(iff_id_eq_zero X).mpr ((cancel_mono (0 : X ⟶ Y)).1 (by simp))
theorem of_epi_zero (X Y : C) [Epi (0 : X ⟶ Y)] : IsZero Y :=
(iff_id_eq_zero Y).mpr ((cancel_epi (0 : X ⟶ Y)).1 (by simp))
theorem of_mono_eq_zero {X Y : C} (f : X ⟶ Y) [Mono f] (h : f = 0) : IsZero X := by
subst h
apply of_mono_zero X Y
theorem of_epi_eq_zero {X Y : C} (f : X ⟶ Y) [Epi f] (h : f = 0) : IsZero Y := by
subst h
apply of_epi_zero X Y
theorem iff_isSplitMono_eq_zero {X Y : C} (f : X ⟶ Y) [IsSplitMono f] : IsZero X ↔ f = 0 := by
rw [iff_id_eq_zero]
constructor
· intro h
rw [← Category.id_comp f, h, zero_comp]
· intro h
rw [← IsSplitMono.id f]
simp only [h, zero_comp]
theorem iff_isSplitEpi_eq_zero {X Y : C} (f : X ⟶ Y) [IsSplitEpi f] : IsZero Y ↔ f = 0 := by
rw [iff_id_eq_zero]
constructor
· intro h
rw [← Category.comp_id f, h, comp_zero]
· intro h
rw [← IsSplitEpi.id f]
simp [h]
theorem of_mono {X Y : C} (f : X ⟶ Y) [Mono f] (i : IsZero Y) : IsZero X := by
have hf := i.eq_zero_of_tgt f
subst hf
exact IsZero.of_mono_zero X Y
theorem of_epi {X Y : C} (f : X ⟶ Y) [Epi f] (i : IsZero X) : IsZero Y := by
have hf := i.eq_zero_of_src f
| subst hf
exact IsZero.of_epi_zero X Y
| Mathlib/CategoryTheory/Limits/Shapes/ZeroMorphisms.lean | 210 | 212 |
/-
Copyright (c) 2019 Kenny Lau. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kenny Lau
-/
import Mathlib.Algebra.Algebra.Subalgebra.Prod
import Mathlib.Algebra.Algebra.Subalgebra.Tower
import Mathlib.LinearAlgebra.Basis.Basic
import Mathlib.LinearAlgebra.Prod
/-!
# Adjoining elements to form subalgebras
This file contains basic results on `Algebra.adjoin`.
## Tags
adjoin, algebra
-/
assert_not_exists Polynomial
universe uR uS uA uB
open Pointwise
open Submodule Subsemiring
variable {R : Type uR} {S : Type uS} {A : Type uA} {B : Type uB}
namespace Algebra
section Semiring
variable [CommSemiring R] [CommSemiring S] [Semiring A] [Semiring B]
variable [Algebra R S] [Algebra R A] [Algebra S A] [Algebra R B] [IsScalarTower R S A]
variable {s t : Set A}
variable (R A)
variable {A} (s)
theorem adjoin_prod_le (s : Set A) (t : Set B) :
adjoin R (s ×ˢ t) ≤ (adjoin R s).prod (adjoin R t) :=
adjoin_le <| Set.prod_mono subset_adjoin subset_adjoin
theorem adjoin_inl_union_inr_eq_prod (s) (t) :
adjoin R (LinearMap.inl R A B '' (s ∪ {1}) ∪ LinearMap.inr R A B '' (t ∪ {1})) =
(adjoin R s).prod (adjoin R t) := by
apply le_antisymm
· simp only [adjoin_le_iff, Set.insert_subset_iff, Subalgebra.zero_mem, Subalgebra.one_mem,
subset_adjoin,-- the rest comes from `squeeze_simp`
Set.union_subset_iff,
LinearMap.coe_inl, Set.mk_preimage_prod_right, Set.image_subset_iff, SetLike.mem_coe,
Set.mk_preimage_prod_left, LinearMap.coe_inr, and_self_iff, Set.union_singleton,
Subalgebra.coe_prod]
· rintro ⟨a, b⟩ ⟨ha, hb⟩
let P := adjoin R (LinearMap.inl R A B '' (s ∪ {1}) ∪ LinearMap.inr R A B '' (t ∪ {1}))
have Ha : (a, (0 : B)) ∈ adjoin R (LinearMap.inl R A B '' (s ∪ {1})) :=
mem_adjoin_of_map_mul R LinearMap.inl_map_mul ha
have Hb : ((0 : A), b) ∈ adjoin R (LinearMap.inr R A B '' (t ∪ {1})) :=
mem_adjoin_of_map_mul R LinearMap.inr_map_mul hb
replace Ha : (a, (0 : B)) ∈ P := adjoin_mono Set.subset_union_left Ha
replace Hb : ((0 : A), b) ∈ P := adjoin_mono Set.subset_union_right Hb
simpa [P] using Subalgebra.add_mem _ Ha Hb
variable (A) in
theorem adjoin_algebraMap (s : Set S) :
adjoin R (algebraMap S A '' s) = (adjoin R s).map (IsScalarTower.toAlgHom R S A) :=
adjoin_image R (IsScalarTower.toAlgHom R S A) s
theorem adjoin_algebraMap_image_union_eq_adjoin_adjoin (s : Set S) (t : Set A) :
adjoin R (algebraMap S A '' s ∪ t) = (adjoin (adjoin R s) t).restrictScalars R :=
le_antisymm
(closure_mono <|
Set.union_subset (Set.range_subset_iff.2 fun r => Or.inl ⟨algebraMap R (adjoin R s) r,
(IsScalarTower.algebraMap_apply _ _ _ _).symm⟩)
(Set.union_subset_union_left _ fun _ ⟨_x, hx, hxs⟩ => hxs ▸ ⟨⟨_, subset_adjoin hx⟩, rfl⟩))
(closure_le.2 <|
Set.union_subset (Set.range_subset_iff.2 fun x => adjoin_mono Set.subset_union_left <|
Algebra.adjoin_algebraMap R A s ▸ ⟨x, x.prop, rfl⟩)
(Set.Subset.trans Set.subset_union_right subset_adjoin))
theorem adjoin_adjoin_of_tower (s : Set A) : adjoin S (adjoin R s : Set A) = adjoin S s := by
apply le_antisymm (adjoin_le _)
· exact adjoin_mono subset_adjoin
· change adjoin R s ≤ (adjoin S s).restrictScalars R
refine adjoin_le ?_
-- Porting note: unclear why this was broken
have : (Subalgebra.restrictScalars R (adjoin S s) : Set A) = adjoin S s := rfl
rw [this]
exact subset_adjoin
theorem Subalgebra.restrictScalars_adjoin {s : Set A} :
(adjoin S s).restrictScalars R = (IsScalarTower.toAlgHom R S A).range ⊔ adjoin R s := by
refine le_antisymm (fun _ hx ↦ adjoin_induction
(fun x hx ↦ le_sup_right (α := Subalgebra R A) (subset_adjoin hx))
(fun x ↦ le_sup_left (α := Subalgebra R A) ⟨x, rfl⟩)
(fun _ _ _ _ ↦ add_mem) (fun _ _ _ _ ↦ mul_mem) <|
(Subalgebra.mem_restrictScalars _).mp hx) (sup_le ?_ <| adjoin_le subset_adjoin)
rintro _ ⟨x, rfl⟩; exact algebraMap_mem (adjoin S s) x
@[simp]
theorem adjoin_top {A} [Semiring A] [Algebra S A] (t : Set A) :
adjoin (⊤ : Subalgebra R S) t = (adjoin S t).restrictScalars (⊤ : Subalgebra R S) :=
let equivTop : Subalgebra (⊤ : Subalgebra R S) A ≃o Subalgebra S A :=
{ toFun := fun s => { s with algebraMap_mem' := fun r => s.algebraMap_mem ⟨r, trivial⟩ }
invFun := fun s => s.restrictScalars _
left_inv := fun _ => SetLike.coe_injective rfl
right_inv := fun _ => SetLike.coe_injective rfl
map_rel_iff' := @fun _ _ => Iff.rfl }
le_antisymm
(adjoin_le <| show t ⊆ adjoin S t from subset_adjoin)
(equivTop.symm_apply_le.mpr <|
adjoin_le <| show t ⊆ adjoin (⊤ : Subalgebra R S) t from subset_adjoin)
end Semiring
section CommSemiring
variable [CommSemiring R] [CommSemiring A]
variable [Algebra R A] {s t : Set A}
variable (R s t)
theorem adjoin_union_eq_adjoin_adjoin :
adjoin R (s ∪ t) = (adjoin (adjoin R s) t).restrictScalars R := by
simpa using adjoin_algebraMap_image_union_eq_adjoin_adjoin R s t
variable {R}
theorem pow_smul_mem_of_smul_subset_of_mem_adjoin [CommSemiring B] [Algebra R B] [Algebra A B]
[IsScalarTower R A B] (r : A) (s : Set B) (B' : Subalgebra R B) (hs : r • s ⊆ B') {x : B}
(hx : x ∈ adjoin R s) (hr : algebraMap A B r ∈ B') : ∃ n₀ : ℕ, ∀ n ≥ n₀, r ^ n • x ∈ B' := by
change x ∈ Subalgebra.toSubmodule (adjoin R s) at hx
rw [adjoin_eq_span, Finsupp.mem_span_iff_linearCombination] at hx
rcases hx with ⟨l, rfl : (l.sum fun (i : Submonoid.closure s) (c : R) => c • (i : B)) = x⟩
choose n₁ n₂ using fun x : Submonoid.closure s => Submonoid.pow_smul_mem_closure_smul r s x.prop
use l.support.sup n₁
intro n hn
rw [Finsupp.smul_sum]
refine B'.toSubmodule.sum_mem ?_
intro a ha
have : n ≥ n₁ a := le_trans (Finset.le_sup ha) hn
dsimp only
rw [← tsub_add_cancel_of_le this, pow_add, ← smul_smul, ←
IsScalarTower.algebraMap_smul A (l a) (a : B), smul_smul (r ^ n₁ a), mul_comm, ← smul_smul,
smul_def, map_pow, IsScalarTower.algebraMap_smul]
apply Subalgebra.mul_mem _ (Subalgebra.pow_mem _ hr _) _
refine Subalgebra.smul_mem _ ?_ _
change _ ∈ B'.toSubmonoid
rw [← Submonoid.closure_eq B'.toSubmonoid]
apply Submonoid.closure_mono hs (n₂ a)
theorem pow_smul_mem_adjoin_smul (r : R) (s : Set A) {x : A} (hx : x ∈ adjoin R s) :
∃ n₀ : ℕ, ∀ n ≥ n₀, r ^ n • x ∈ adjoin R (r • s) :=
pow_smul_mem_of_smul_subset_of_mem_adjoin r s _ subset_adjoin hx (Subalgebra.algebraMap_mem _ _)
lemma adjoin_nonUnitalSubalgebra_eq_span (s : NonUnitalSubalgebra R A) :
Subalgebra.toSubmodule (adjoin R (s : Set A)) = span R {1} ⊔ s.toSubmodule := by
rw [adjoin_eq_span, Submonoid.closure_eq_one_union, span_union, ← NonUnitalAlgebra.adjoin_eq_span,
NonUnitalAlgebra.adjoin_eq]
end CommSemiring
end Algebra
open Algebra Subalgebra
section
variable (F E : Type*) {K : Type*} [CommSemiring E] [Semiring K] [SMul F E] [Algebra E K]
variable [CommSemiring F] [Algebra F K] [IsScalarTower F E K] (L : Subalgebra F K) {F}
/-- If `K / E / F` is a ring extension tower, `L` is a subalgebra of `K / F`,
then `E[L]` is generated by any basis of `L / F` as an `E`-module. -/
theorem Subalgebra.adjoin_eq_span_basis {ι : Type*} (bL : Basis ι F L) :
toSubmodule (adjoin E (L : Set K)) = span E (Set.range fun i : ι ↦ (bL i).1) :=
L.adjoin_eq_span_of_eq_span E <| by
simpa only [← L.range_val, Submodule.map_span, Submodule.map_top, ← Set.range_comp]
using congr_arg (Submodule.map L.val) bL.span_eq.symm
theorem Algebra.restrictScalars_adjoin (F : Type*) [CommSemiring F] {E : Type*} [CommSemiring E]
[Algebra F E] (K : Subalgebra F E) (S : Set E) :
(Algebra.adjoin K S).restrictScalars F = Algebra.adjoin F (K ∪ S) := by
conv_lhs => rw [← Algebra.adjoin_eq K, ← Algebra.adjoin_union_eq_adjoin_adjoin]
/-- If `E / L / F` and `E / L' / F` are two ring extension towers, `L ≃ₐ[F] L'` is an isomorphism
compatible with `E / L` and `E / L'`, then for any subset `S` of `E`, `L[S]` and `L'[S]` are
equal as subalgebras of `E / F`. -/
theorem Algebra.restrictScalars_adjoin_of_algEquiv
{F E L L' : Type*} [CommSemiring F] [CommSemiring L] [CommSemiring L'] [Semiring E]
[Algebra F L] [Algebra L E] [Algebra F L'] [Algebra L' E] [Algebra F E]
[IsScalarTower F L E] [IsScalarTower F L' E] (i : L ≃ₐ[F] L')
(hi : algebraMap L E = (algebraMap L' E) ∘ i) (S : Set E) :
(Algebra.adjoin L S).restrictScalars F = (Algebra.adjoin L' S).restrictScalars F := by
apply_fun Subalgebra.toSubsemiring using fun K K' h ↦ by rwa [SetLike.ext'_iff] at h ⊢
change Subsemiring.closure _ = Subsemiring.closure _
rw [hi, Set.range_comp, EquivLike.range_eq_univ, Set.image_univ]
end
| Mathlib/RingTheory/Adjoin/Basic.lean | 376 | 378 | |
/-
Copyright (c) 2021 Aaron Anderson, Yaël Dillies. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Aaron Anderson, Kevin Buzzard, Yaël Dillies, Eric Wieser
-/
import Mathlib.Data.Finset.Lattice.Union
import Mathlib.Data.Finset.Pairwise
import Mathlib.Data.Finset.Prod
import Mathlib.Data.Finset.Sigma
import Mathlib.Data.Fintype.Basic
import Mathlib.Order.CompleteLatticeIntervals
/-!
# Supremum independence
In this file, we define supremum independence of indexed sets. An indexed family `f : ι → α` is
sup-independent if, for all `a`, `f a` and the supremum of the rest are disjoint.
## Main definitions
* `Finset.SupIndep s f`: a family of elements `f` are supremum independent on the finite set `s`.
* `sSupIndep s`: a set of elements are supremum independent.
* `iSupIndep f`: a family of elements are supremum independent.
## Main statements
* In a distributive lattice, supremum independence is equivalent to pairwise disjointness:
* `Finset.supIndep_iff_pairwiseDisjoint`
* `CompleteLattice.sSupIndep_iff_pairwiseDisjoint`
* `CompleteLattice.iSupIndep_iff_pairwiseDisjoint`
* Otherwise, supremum independence is stronger than pairwise disjointness:
* `Finset.SupIndep.pairwiseDisjoint`
* `sSupIndep.pairwiseDisjoint`
* `iSupIndep.pairwiseDisjoint`
## Implementation notes
For the finite version, we avoid the "obvious" definition
`∀ i ∈ s, Disjoint (f i) ((s.erase i).sup f)` because `erase` would require decidable equality on
`ι`.
-/
variable {α β ι ι' : Type*}
/-! ### On lattices with a bottom element, via `Finset.sup` -/
namespace Finset
section Lattice
variable [Lattice α] [OrderBot α]
/-- Supremum independence of finite sets. We avoid the "obvious" definition using `s.erase i`
because `erase` would require decidable equality on `ι`. -/
def SupIndep (s : Finset ι) (f : ι → α) : Prop :=
∀ ⦃t⦄, t ⊆ s → ∀ ⦃i⦄, i ∈ s → i ∉ t → Disjoint (f i) (t.sup f)
variable {s t : Finset ι} {f : ι → α} {i : ι}
/-- The RHS looks like the definition of `iSupIndep`. -/
theorem supIndep_iff_disjoint_erase [DecidableEq ι] :
s.SupIndep f ↔ ∀ i ∈ s, Disjoint (f i) ((s.erase i).sup f) :=
⟨fun hs _ hi => hs (erase_subset _ _) hi (not_mem_erase _ _), fun hs _ ht i hi hit =>
(hs i hi).mono_right (sup_mono fun _ hj => mem_erase.2 ⟨ne_of_mem_of_not_mem hj hit, ht hj⟩)⟩
/-- If both the index type and the lattice have decidable equality,
then the `SupIndep` predicate is decidable.
TODO: speedup the definition and drop the `[DecidableEq ι]` assumption
by iterating over the pairs `(a, t)` such that `s = Finset.cons a t _`
using something like `List.eraseIdx`
or by generating both `f i` and `(s.erase i).sup f` in one loop over `s`.
Yet another possible optimization is to precompute partial suprema of `f`
over the inits and tails of the list representing `s`,
store them in 2 `Array`s,
then compute each `sup` in 1 operation. -/
instance [DecidableEq ι] [DecidableEq α] : Decidable (SupIndep s f) :=
have : ∀ i, Decidable (Disjoint (f i) ((s.erase i).sup f)) := fun _ ↦
decidable_of_iff _ disjoint_iff.symm
decidable_of_iff _ supIndep_iff_disjoint_erase.symm
theorem SupIndep.subset (ht : t.SupIndep f) (h : s ⊆ t) : s.SupIndep f := fun _ hu _ hi =>
ht (hu.trans h) (h hi)
@[simp]
theorem supIndep_empty (f : ι → α) : (∅ : Finset ι).SupIndep f := fun _ _ a ha =>
(not_mem_empty a ha).elim
@[simp]
theorem supIndep_singleton (i : ι) (f : ι → α) : ({i} : Finset ι).SupIndep f :=
fun s hs j hji hj => by
rw [eq_empty_of_ssubset_singleton ⟨hs, fun h => hj (h hji)⟩, sup_empty]
exact disjoint_bot_right
theorem SupIndep.pairwiseDisjoint (hs : s.SupIndep f) : (s : Set ι).PairwiseDisjoint f :=
fun _ ha _ hb hab =>
sup_singleton.subst <| hs (singleton_subset_iff.2 hb) ha <| not_mem_singleton.2 hab
@[deprecated (since := "2025-01-17")] alias sup_indep.pairwise_disjoint := SupIndep.pairwiseDisjoint
theorem SupIndep.le_sup_iff (hs : s.SupIndep f) (hts : t ⊆ s) (hi : i ∈ s) (hf : ∀ i, f i ≠ ⊥) :
f i ≤ t.sup f ↔ i ∈ t := by
refine ⟨fun h => ?_, le_sup⟩
by_contra hit
exact hf i (disjoint_self.1 <| (hs hts hi hit).mono_right h)
theorem SupIndep.antitone_fun {g : ι → α} (hle : ∀ x ∈ s, f x ≤ g x) (h : s.SupIndep g) :
s.SupIndep f := fun _t hts i his hit ↦
(h hts his hit).mono (hle i his) <| Finset.sup_mono_fun fun x hx ↦ hle x <| hts hx
@[deprecated (since := "2025-01-17")]
alias supIndep_antimono_fun := SupIndep.antitone_fun
protected theorem SupIndep.image [DecidableEq ι] {s : Finset ι'} {g : ι' → ι}
(hs : s.SupIndep (f ∘ g)) : (s.image g).SupIndep f := by
intro t ht i hi hit
rcases subset_image_iff.mp ht with ⟨t, hts, rfl⟩
rcases mem_image.mp hi with ⟨i, his, rfl⟩
rw [sup_image]
exact hs hts his (hit <| mem_image_of_mem _ ·)
theorem supIndep_map {s : Finset ι'} {g : ι' ↪ ι} : (s.map g).SupIndep f ↔ s.SupIndep (f ∘ g) := by
refine ⟨fun hs t ht i hi hit => ?_, fun hs => ?_⟩
· rw [← sup_map]
exact hs (map_subset_map.2 ht) ((mem_map' _).2 hi) (by rwa [mem_map'])
· classical
rw [map_eq_image]
exact hs.image
@[simp]
theorem supIndep_pair [DecidableEq ι] {i j : ι} (hij : i ≠ j) :
({i, j} : Finset ι).SupIndep f ↔ Disjoint (f i) (f j) := by
suffices Disjoint (f i) (f j) → Disjoint (f j) ((Finset.erase {i, j} j).sup f) by
simpa [supIndep_iff_disjoint_erase, hij]
rw [pair_comm]
simp [hij.symm, disjoint_comm]
theorem supIndep_univ_bool (f : Bool → α) :
(Finset.univ : Finset Bool).SupIndep f ↔ Disjoint (f false) (f true) :=
haveI : true ≠ false := by simp only [Ne, not_false_iff, reduceCtorEq]
(supIndep_pair this).trans disjoint_comm
@[simp]
theorem supIndep_univ_fin_two (f : Fin 2 → α) :
(Finset.univ : Finset (Fin 2)).SupIndep f ↔ Disjoint (f 0) (f 1) :=
have : (0 : Fin 2) ≠ 1 := by simp
supIndep_pair this
@[simp]
theorem supIndep_attach : (s.attach.SupIndep fun a => f a) ↔ s.SupIndep f := by
simpa [Finset.attach_map_val] using (supIndep_map (s := s.attach) (g := .subtype _)).symm
alias ⟨_, SupIndep.attach⟩ := supIndep_attach
end Lattice
section DistribLattice
variable [DistribLattice α] [OrderBot α] {s : Finset ι} {f : ι → α}
theorem supIndep_iff_pairwiseDisjoint : s.SupIndep f ↔ (s : Set ι).PairwiseDisjoint f :=
⟨SupIndep.pairwiseDisjoint, fun hs _ ht _ hi hit =>
Finset.disjoint_sup_right.2 fun _ hj => hs hi (ht hj) (ne_of_mem_of_not_mem hj hit).symm⟩
alias ⟨_, _root_.Set.PairwiseDisjoint.supIndep⟩ := supIndep_iff_pairwiseDisjoint
/-- Bind operation for `SupIndep`. -/
protected theorem SupIndep.sup [DecidableEq ι] {s : Finset ι'} {g : ι' → Finset ι} {f : ι → α}
(hs : s.SupIndep fun i => (g i).sup f) (hg : ∀ i' ∈ s, (g i').SupIndep f) :
(s.sup g).SupIndep f := by
simp_rw [supIndep_iff_pairwiseDisjoint] at hs hg ⊢
rw [sup_eq_biUnion, coe_biUnion]
exact hs.biUnion_finset hg
/-- Bind operation for `SupIndep`. -/
protected theorem SupIndep.biUnion [DecidableEq ι] {s : Finset ι'} {g : ι' → Finset ι} {f : ι → α}
(hs : s.SupIndep fun i => (g i).sup f) (hg : ∀ i' ∈ s, (g i').SupIndep f) :
(s.biUnion g).SupIndep f := by
rw [← sup_eq_biUnion]
exact hs.sup hg
/-- Bind operation for `SupIndep`. -/
protected theorem SupIndep.sigma {β : ι → Type*} {s : Finset ι} {g : ∀ i, Finset (β i)}
{f : Sigma β → α} (hs : s.SupIndep fun i => (g i).sup fun b => f ⟨i, b⟩)
(hg : ∀ i ∈ s, (g i).SupIndep fun b => f ⟨i, b⟩) : (s.sigma g).SupIndep f := by
rintro t ht ⟨i, b⟩ hi hit
rw [Finset.disjoint_sup_right]
rintro ⟨j, c⟩ hj
have hbc := (ne_of_mem_of_not_mem hj hit).symm
replace hj := ht hj
rw [mem_sigma] at hi hj
obtain rfl | hij := eq_or_ne i j
· exact (hg _ hj.1).pairwiseDisjoint hi.2 hj.2 (sigma_mk_injective.ne_iff.1 hbc)
· refine (hs.pairwiseDisjoint hi.1 hj.1 hij).mono ?_ ?_
· convert le_sup (α := α) hi.2; simp
· convert le_sup (α := α) hj.2; simp
protected theorem SupIndep.product {s : Finset ι} {t : Finset ι'} {f : ι × ι' → α}
(hs : s.SupIndep fun i => t.sup fun i' => f (i, i'))
(ht : t.SupIndep fun i' => s.sup fun i => f (i, i')) : (s ×ˢ t).SupIndep f := by
rintro u hu ⟨i, i'⟩ hi hiu
rw [Finset.disjoint_sup_right]
rintro ⟨j, j'⟩ hj
have hij := (ne_of_mem_of_not_mem hj hiu).symm
replace hj := hu hj
rw [mem_product] at hi hj
obtain rfl | hij := eq_or_ne i j
· refine (ht.pairwiseDisjoint hi.2 hj.2 <| (Prod.mk_right_injective _).ne_iff.1 hij).mono ?_ ?_
· convert le_sup (α := α) hi.1; simp
· convert le_sup (α := α) hj.1; simp
· refine (hs.pairwiseDisjoint hi.1 hj.1 hij).mono ?_ ?_
· convert le_sup (α := α) hi.2; simp
· convert le_sup (α := α) hj.2; simp
theorem supIndep_product_iff {s : Finset ι} {t : Finset ι'} {f : ι × ι' → α} :
(s.product t).SupIndep f ↔ (s.SupIndep fun i => t.sup fun i' => f (i, i'))
∧ t.SupIndep fun i' => s.sup fun i => f (i, i') := by
refine ⟨?_, fun h => h.1.product h.2⟩
simp_rw [supIndep_iff_pairwiseDisjoint]
refine fun h => ⟨fun i hi j hj hij => ?_, fun i hi j hj hij => ?_⟩ <;>
simp_rw [Finset.disjoint_sup_left, Finset.disjoint_sup_right] <;>
intro i' hi' j' hj'
· exact h (mk_mem_product hi hi') (mk_mem_product hj hj') (ne_of_apply_ne Prod.fst hij)
· exact h (mk_mem_product hi' hi) (mk_mem_product hj' hj) (ne_of_apply_ne Prod.snd hij)
end DistribLattice
end Finset
/-! ### On complete lattices via `sSup` -/
section CompleteLattice
variable [CompleteLattice α]
open Set Function
/-- An independent set of elements in a complete lattice is one in which every element is disjoint
from the `Sup` of the rest. -/
def sSupIndep (s : Set α) : Prop :=
∀ ⦃a⦄, a ∈ s → Disjoint a (sSup (s \ {a}))
@[deprecated (since := "2024-11-24")] alias CompleteLattice.SetIndependent := sSupIndep
variable {s : Set α} (hs : sSupIndep s)
@[simp]
theorem sSupIndep_empty : sSupIndep (∅ : Set α) := fun x hx =>
(Set.not_mem_empty x hx).elim
@[deprecated (since := "2024-11-24")] alias CompleteLattice.setIndependent_empty := sSupIndep_empty
include hs in
theorem sSupIndep.mono {t : Set α} (hst : t ⊆ s) : sSupIndep t := fun _ ha =>
(hs (hst ha)).mono_right (sSup_le_sSup (diff_subset_diff_left hst))
@[deprecated (since := "2024-11-24")] alias CompleteLattice.SetIndependent.mono := sSupIndep.mono
include hs in
/-- If the elements of a set are independent, then any pair within that set is disjoint. -/
theorem sSupIndep.pairwiseDisjoint : s.PairwiseDisjoint id := fun _ hx y hy h =>
disjoint_sSup_right (hs hx) ((mem_diff y).mpr ⟨hy, h.symm⟩)
|
@[deprecated (since := "2024-11-24")]
alias CompleteLattice.SetIndependent.pairwiseDisjoint := sSupIndep.pairwiseDisjoint
theorem sSupIndep_singleton (a : α) : sSupIndep ({a} : Set α) := fun i hi ↦ by
simp_all
@[deprecated (since := "2024-11-24")]
alias CompleteLattice.setIndependent_singleton := sSupIndep_singleton
| Mathlib/Order/SupIndep.lean | 264 | 273 |
/-
Copyright (c) 2023 Xavier Roblot. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Xavier Roblot
-/
import Mathlib.MeasureTheory.Constructions.Pi
import Mathlib.MeasureTheory.Integral.Prod
/-!
# Integration with respect to a finite product of measures
On a finite product of measure spaces, we show that a product of integrable functions each
depending on a single coordinate is integrable, in `MeasureTheory.integrable_fintype_prod`, and
that its integral is the product of the individual integrals,
in `MeasureTheory.integral_fintype_prod_eq_prod`.
-/
open Fintype MeasureTheory MeasureTheory.Measure
namespace MeasureTheory
namespace Integrable
variable {𝕜 : Type*} [NormedCommRing 𝕜]
/-- On a finite product space in `n` variables, for a natural number `n`, a product of integrable
functions depending on each coordinate is integrable. -/
theorem fin_nat_prod {n : ℕ} {E : Fin n → Type*}
[∀ i, MeasureSpace (E i)] [∀ i, SigmaFinite (volume : Measure (E i))]
{f : (i : Fin n) → E i → 𝕜} (hf : ∀ i, Integrable (f i)) :
Integrable (fun (x : (i : Fin n) → E i) ↦ ∏ i, f i (x i)) := by
induction n with
| zero => simp only [Finset.univ_eq_empty, Finset.prod_empty, volume_pi, isFiniteMeasure_iff,
integrable_const_iff, one_ne_zero, pi_empty_univ, ENNReal.one_lt_top, or_true]
| succ n n_ih =>
have := ((measurePreserving_piFinSuccAbove (fun i => (volume : Measure (E i))) 0).symm)
rw [volume_pi, ← this.integrable_comp_emb (MeasurableEquiv.measurableEmbedding _)]
simp_rw [MeasurableEquiv.piFinSuccAbove_symm_apply, Fin.insertNthEquiv,
Fin.prod_univ_succ, Fin.insertNth_zero]
simp only [Fin.zero_succAbove, cast_eq, Function.comp_def, Fin.cons_zero, Fin.cons_succ]
have : Integrable (fun (x : (j : Fin n) → E (Fin.succ j)) ↦ ∏ j, f (Fin.succ j) (x j)) :=
n_ih (fun i ↦ hf _)
exact Integrable.mul_prod (hf 0) this
/-- On a finite product space, a product of integrable functions depending on each coordinate is
integrable. Version with dependent target. -/
theorem fintype_prod_dep {ι : Type*} [Fintype ι] {E : ι → Type*}
{f : (i : ι) → E i → 𝕜} [∀ i, MeasureSpace (E i)] [∀ i, SigmaFinite (volume : Measure (E i))]
(hf : ∀ i, Integrable (f i)) :
Integrable (fun (x : (i : ι) → E i) ↦ ∏ i, f i (x i)) := by
let e := (equivFin ι).symm
simp_rw [← (volume_measurePreserving_piCongrLeft _ e).integrable_comp_emb
(MeasurableEquiv.measurableEmbedding _),
← e.prod_comp, MeasurableEquiv.coe_piCongrLeft, Function.comp_def,
Equiv.piCongrLeft_apply_apply]
exact .fin_nat_prod (fun i ↦ hf _)
/-- On a finite product space, a product of integrable functions depending on each coordinate is
integrable. -/
theorem fintype_prod {ι : Type*} [Fintype ι] {E : Type*}
{f : ι → E → 𝕜} [MeasureSpace E] [SigmaFinite (volume : Measure E)]
(hf : ∀ i, Integrable (f i)) :
Integrable (fun (x : ι → E) ↦ ∏ i, f i (x i)) :=
Integrable.fintype_prod_dep hf
|
end Integrable
variable {𝕜 : Type*} [RCLike 𝕜]
/-- A version of **Fubini's theorem** in `n` variables, for a natural number `n`. -/
theorem integral_fin_nat_prod_eq_prod {n : ℕ} {E : Fin n → Type*}
[∀ i, MeasureSpace (E i)] [∀ i, SigmaFinite (volume : Measure (E i))]
(f : (i : Fin n) → E i → 𝕜) :
∫ x : (i : Fin n) → E i, ∏ i, f i (x i) = ∏ i, ∫ x, f i x := by
induction n with
| zero =>
simp [volume_pi, measureReal_def]
| succ n n_ih =>
calc
_ = ∫ x : E 0 × ((i : Fin n) → E (Fin.succ i)),
f 0 x.1 * ∏ i : Fin n, f (Fin.succ i) (x.2 i) := by
rw [volume_pi, ← ((measurePreserving_piFinSuccAbove
(fun i => (volume : Measure (E i))) 0).symm).integral_comp']
simp_rw [MeasurableEquiv.piFinSuccAbove_symm_apply, Fin.insertNthEquiv,
| Mathlib/MeasureTheory/Integral/Pi.lean | 65 | 84 |
/-
Copyright (c) 2018 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
-/
import Mathlib.Data.Sigma.Basic
import Mathlib.Algebra.Order.Ring.Nat
/-!
# A computable model of ZFA without infinity
In this file we define finite hereditary lists. This is useful for calculations in naive set theory.
We distinguish two kinds of ZFA lists:
* Atoms. Directly correspond to an element of the original type.
* Proper ZFA lists. Can be thought of (but aren't implemented) as a list of ZFA lists (not
necessarily proper).
For example, `Lists ℕ` contains stuff like `23`, `[]`, `[37]`, `[1, [[2], 3], 4]`.
## Implementation note
As we want to be able to append both atoms and proper ZFA lists to proper ZFA lists, it's handy that
atoms and proper ZFA lists belong to the same type, even though atoms of `α` could be modelled as
`α` directly. But we don't want to be able to append anything to atoms.
This calls for a two-steps definition of ZFA lists:
* First, define ZFA prelists as atoms and proper ZFA prelists. Those proper ZFA prelists are defined
by inductive appending of (not necessarily proper) ZFA lists.
* Second, define ZFA lists by rubbing out the distinction between atoms and proper lists.
## Main declarations
* `Lists' α false`: Atoms as ZFA prelists. Basically a copy of `α`.
* `Lists' α true`: Proper ZFA prelists. Defined inductively from the empty ZFA prelist
(`Lists'.nil`) and from appending a ZFA prelist to a proper ZFA prelist (`Lists'.cons a l`).
* `Lists α`: ZFA lists. Sum of the atoms and proper ZFA prelists.
* `Finsets α`: ZFA sets. Defined as `Lists` quotiented by `Lists.Equiv`, the extensional
equivalence.
-/
variable {α : Type*}
/-- Prelists, helper type to define `Lists`. `Lists' α false` are the "atoms", a copy of `α`.
`Lists' α true` are the "proper" ZFA prelists, inductively defined from the empty ZFA prelist and
from appending a ZFA prelist to a proper ZFA prelist. It is made so that you can't append anything
to an atom while having only one appending function for appending both atoms and proper ZFC prelists
to a proper ZFA prelist. -/
inductive Lists'.{u} (α : Type u) : Bool → Type u
| atom : α → Lists' α false
| nil : Lists' α true
| cons' {b} : Lists' α b → Lists' α true → Lists' α true
deriving DecidableEq
compile_inductive% Lists'
/-- Hereditarily finite list, aka ZFA list. A ZFA list is either an "atom" (`b = false`),
corresponding to an element of `α`, or a "proper" ZFA list, inductively defined from the empty ZFA
list and from appending a ZFA list to a proper ZFA list. -/
def Lists (α : Type*) :=
Σb, Lists' α b
namespace Lists'
instance [Inhabited α] : ∀ b, Inhabited (Lists' α b)
| true => ⟨nil⟩
| false => ⟨atom default⟩
/-- Appending a ZFA list to a proper ZFA prelist. -/
def cons : Lists α → Lists' α true → Lists' α true
| ⟨_, a⟩, l => cons' a l
/-- Converts a ZFA prelist to a `List` of ZFA lists. Atoms are sent to `[]`. -/
@[simp]
def toList : ∀ {b}, Lists' α b → List (Lists α)
| _, atom _ => []
| _, nil => []
| _, cons' a l => ⟨_, a⟩ :: l.toList
@[simp]
theorem toList_cons (a : Lists α) (l) : toList (cons a l) = a :: l.toList := rfl
/-- Converts a `List` of ZFA lists to a proper ZFA prelist. -/
@[simp]
def ofList : List (Lists α) → Lists' α true
| [] => nil
| a :: l => cons a (ofList l)
@[simp]
theorem to_ofList (l : List (Lists α)) : toList (ofList l) = l := by induction l <;> simp [*]
@[simp]
theorem of_toList : ∀ l : Lists' α true, ofList (toList l) = l :=
suffices
∀ (b) (h : true = b) (l : Lists' α b),
let l' : Lists' α true := by rw [h]; exact l
ofList (toList l') = l'
from this _ rfl
fun b h l => by
induction l with
| atom => cases h
| nil => simp
| cons' b a _ IH => simpa [cons] using IH rfl
end Lists'
mutual
/-- Equivalence of ZFA lists. Defined inductively. -/
inductive Lists.Equiv : Lists α → Lists α → Prop
| refl (l) : Lists.Equiv l l
| antisymm {l₁ l₂ : Lists' α true} :
Lists'.Subset l₁ l₂ → Lists'.Subset l₂ l₁ → Lists.Equiv ⟨_, l₁⟩ ⟨_, l₂⟩
/-- Subset relation for ZFA lists. Defined inductively. -/
inductive Lists'.Subset : Lists' α true → Lists' α true → Prop
| nil {l} : Lists'.Subset Lists'.nil l
| cons {a a' l l'} :
Lists.Equiv a a' →
a' ∈ Lists'.toList l' → Lists'.Subset l l' → Lists'.Subset (Lists'.cons a l) l'
end
local infixl:50 " ~ " => Lists.Equiv
namespace Lists'
instance : HasSubset (Lists' α true) :=
⟨Lists'.Subset⟩
/-- ZFA prelist membership. A ZFA list is in a ZFA prelist if some element of this ZFA prelist is
equivalent as a ZFA list to this ZFA list. -/
instance {b} : Membership (Lists α) (Lists' α b) :=
⟨fun l a => ∃ a' ∈ l.toList, a ~ a'⟩
theorem mem_def {b a} {l : Lists' α b} : a ∈ l ↔ ∃ a' ∈ l.toList, a ~ a' :=
Iff.rfl
@[simp]
theorem mem_cons {a y l} : a ∈ @cons α y l ↔ a ~ y ∨ a ∈ l := by
simp [mem_def, or_and_right, exists_or]
theorem cons_subset {a} {l₁ l₂ : Lists' α true} : Lists'.cons a l₁ ⊆ l₂ ↔ a ∈ l₂ ∧ l₁ ⊆ l₂ := by
refine ⟨fun h => ?_, fun ⟨⟨a', m, e⟩, s⟩ => Subset.cons e m s⟩
generalize h' : Lists'.cons a l₁ = l₁' at h
obtain - | @⟨a', _, _, _, e, m, s⟩ := h
· cases a
cases h'
cases a; cases a'; cases h'; exact ⟨⟨_, m, e⟩, s⟩
theorem ofList_subset {l₁ l₂ : List (Lists α)} (h : l₁ ⊆ l₂) :
Lists'.ofList l₁ ⊆ Lists'.ofList l₂ := by
induction l₁ with
| nil => exact Subset.nil
| cons _ _ l₁_ih =>
refine Subset.cons (Lists.Equiv.refl _) ?_ (l₁_ih (List.subset_of_cons_subset h))
simp only [List.cons_subset] at h; simp [h]
@[refl]
theorem Subset.refl {l : Lists' α true} : l ⊆ l := by
rw [← Lists'.of_toList l]; exact ofList_subset (List.Subset.refl _)
theorem subset_nil {l : Lists' α true} : l ⊆ Lists'.nil → l = Lists'.nil := by
rw [← of_toList l]
induction toList l <;> intro h
· rfl
· rcases cons_subset.1 h with ⟨⟨_, ⟨⟩, _⟩, _⟩
theorem mem_of_subset' {a} : ∀ {l₁ l₂ : Lists' α true} (_ : l₁ ⊆ l₂) (_ : a ∈ l₁.toList), a ∈ l₂
| nil, _, Lists'.Subset.nil, h => by cases h
| cons' a0 l0, l₂, s, h => by
obtain - | ⟨e, m, s⟩ := s
simp only [toList, Sigma.eta, List.find?, List.mem_cons] at h
rcases h with (rfl | h)
· exact ⟨_, m, e⟩
· exact mem_of_subset' s h
theorem subset_def {l₁ l₂ : Lists' α true} : l₁ ⊆ l₂ ↔ ∀ a ∈ l₁.toList, a ∈ l₂ :=
⟨fun H _ => mem_of_subset' H, fun H => by
rw [← of_toList l₁]
revert H; induction' toList l₁ with h t t_ih <;> intro H
| · exact Subset.nil
· simp only [ofList, List.find?, List.mem_cons, forall_eq_or_imp] at *
| Mathlib/SetTheory/Lists.lean | 180 | 181 |
/-
Copyright (c) 2024 Riccardo Brasca. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Riccardo Brasca, Sanyam Gupta, Omar Haddad, David Lowry-Duda,
Lorenzo Luccioli, Pietro Monticone, Alexis Saurin, Florent Schaffhauser
-/
import Mathlib.NumberTheory.FLT.Basic
import Mathlib.NumberTheory.Cyclotomic.PID
import Mathlib.NumberTheory.Cyclotomic.Three
import Mathlib.Algebra.Ring.Divisibility.Lemmas
/-!
# Fermat Last Theorem in the case `n = 3`
The goal of this file is to prove Fermat's Last Theorem in the case `n = 3`.
## Main results
* `fermatLastTheoremThree`: Fermat's Last Theorem for `n = 3`: if `a b c : ℕ` are all non-zero then
`a ^ 3 + b ^ 3 ≠ c ^ 3`.
## Implementation details
We follow the proof in <https://webusers.imj-prg.fr/~marc.hindry/Cours-arith.pdf>, page 43.
The strategy is the following:
* The so called "Case 1", when `3 ∣ a * b * c` is completely elementary and is proved using
congruences modulo `9`.
* To prove case 2, we consider the generalized equation `a ^ 3 + b ^ 3 = u * c ^ 3`, where `a`, `b`,
and `c` are in the cyclotomic ring `ℤ[ζ₃]` (where `ζ₃` is a primitive cube root of unity) and `u`
is a unit of `ℤ[ζ₃]`. `FermatLastTheoremForThree_of_FermatLastTheoremThreeGen` (whose proof is
rather elementary on paper) says that to prove Fermat's last theorem for exponent `3`, it is
enough to prove that this equation has no solutions such that `c ≠ 0`, `¬ λ ∣ a`, `¬ λ ∣ b`,
`λ ∣ c` and `IsCoprime a b` (where we set `λ := ζ₃ - 1`). We call such a tuple a `Solution'`.
A `Solution` is the same as a `Solution'` with the additional assumption that `λ ^ 2 ∣ a + b`.
We then prove that, given `S' : Solution'`, there is `S : Solution` such that the multiplicity of
`λ = ζ₃ - 1` in `c` is the same in `S'` and `S` (see `exists_Solution_of_Solution'`).
In particular it is enough to prove that no `Solution` exists. The key point is a descent argument
on the multiplicity of `λ` in `c`: starting with `S : Solution` we can find `S₁ : Solution` with
multiplicity strictly smaller (see `exists_Solution_multiplicity_lt`) and this finishes the proof.
To construct `S₁` we go through a `Solution'` and then back to a `Solution`. More importantly, we
cannot control the unit `u`, and this is the reason why we need to consider the generalized
equation `a ^ 3 + b ^ 3 = u * c ^ 3`. The construction is completely explicit, but it depends
crucially on `IsCyclotomicExtension.Rat.Three.eq_one_or_neg_one_of_unit_of_congruent`, a special
case of Kummer's lemma.
* Note that we don't prove Case 1 for the generalized equation (in particular we don't prove that
the generalized equation has no nontrivial solutions). This is because the proof, even if
elementary on paper, would be quite annoying to formalize: indeed it involves a lot of explicit
computations in `ℤ[ζ₃] / (λ)`: this ring is isomorphic to `ℤ / 9ℤ`, but of course, even if we
construct such an isomorphism, tactics like `decide` would not work.
-/
section case1
open ZMod
private lemma cube_of_castHom_ne_zero {n : ZMod 9} :
castHom (show 3 ∣ 9 by norm_num) (ZMod 3) n ≠ 0 → n ^ 3 = 1 ∨ n ^ 3 = 8 := by
revert n; decide
private lemma cube_of_not_dvd {n : ℤ} (h : ¬ 3 ∣ n) :
(n : ZMod 9) ^ 3 = 1 ∨ (n : ZMod 9) ^ 3 = 8 := by
apply cube_of_castHom_ne_zero
rwa [map_intCast, Ne, ZMod.intCast_zmod_eq_zero_iff_dvd]
/-- If `a b c : ℤ` are such that `¬ 3 ∣ a * b * c`, then `a ^ 3 + b ^ 3 ≠ c ^ 3`. -/
theorem fermatLastTheoremThree_case_1 {a b c : ℤ} (hdvd : ¬ 3 ∣ a * b * c) :
a ^ 3 + b ^ 3 ≠ c ^ 3 := by
simp_rw [Int.prime_three.dvd_mul, not_or] at hdvd
apply mt (congrArg (Int.cast : ℤ → ZMod 9))
simp_rw [Int.cast_add, Int.cast_pow]
rcases cube_of_not_dvd hdvd.1.1 with ha | ha <;>
rcases cube_of_not_dvd hdvd.1.2 with hb | hb <;>
rcases cube_of_not_dvd hdvd.2 with hc | hc <;>
rw [ha, hb, hc] <;> decide
end case1
section case2
private lemma three_dvd_b_of_dvd_a_of_gcd_eq_one_of_case2 {a b c : ℤ} (ha : a ≠ 0)
(Hgcd : Finset.gcd {a, b, c} id = 1) (h3a : 3 ∣ a) (HF : a ^ 3 + b ^ 3 + c ^ 3 = 0)
(H : ∀ a b c : ℤ, c ≠ 0 → ¬ 3 ∣ a → ¬ 3 ∣ b → 3 ∣ c → IsCoprime a b → a ^ 3 + b ^ 3 ≠ c ^ 3) :
3 ∣ b := by
have hbc : IsCoprime (-b) (-c) := by
refine IsCoprime.neg_neg ?_
rw [add_comm (a ^ 3), add_assoc, add_comm (a ^ 3), ← add_assoc] at HF
refine isCoprime_of_gcd_eq_one_of_FLT ?_ HF
convert Hgcd using 2
rw [Finset.pair_comm, Finset.insert_comm]
by_contra! h3b
by_cases h3c : 3 ∣ c
· apply h3b
rw [add_assoc, add_comm (b ^ 3), ← add_assoc] at HF
exact dvd_c_of_prime_of_dvd_a_of_dvd_b_of_FLT Int.prime_three h3a h3c HF
· refine H (-b) (-c) a ha (by simp [h3b]) (by simp [h3c]) h3a hbc ?_
rw [add_eq_zero_iff_eq_neg, ← (show Odd 3 by decide).neg_pow] at HF
rw [← HF]
ring
open Finset in
private lemma fermatLastTheoremThree_of_dvd_a_of_gcd_eq_one_of_case2 {a b c : ℤ} (ha : a ≠ 0)
(h3a : 3 ∣ a) (Hgcd : Finset.gcd {a, b, c} id = 1)
(H : ∀ a b c : ℤ, c ≠ 0 → ¬ 3 ∣ a → ¬ 3 ∣ b → 3 ∣ c → IsCoprime a b → a ^ 3 + b ^ 3 ≠ c ^ 3) :
a ^ 3 + b ^ 3 + c ^ 3 ≠ 0 := by
intro HF
apply (show ¬(3 ∣ (1 : ℤ)) by decide)
rw [← Hgcd]
refine dvd_gcd (fun x hx ↦ ?_)
simp only [mem_insert, mem_singleton] at hx
have h3b : 3 ∣ b := by
refine three_dvd_b_of_dvd_a_of_gcd_eq_one_of_case2 ha ?_ h3a HF H
simp only [← Hgcd, gcd_insert, gcd_singleton, id_eq, ← Int.abs_eq_normalize, abs_neg]
rcases hx with hx | hx | hx
· exact hx ▸ h3a
· exact hx ▸ h3b
· simpa [hx] using dvd_c_of_prime_of_dvd_a_of_dvd_b_of_FLT Int.prime_three h3a h3b HF
open Finset Int in
/--
To prove Fermat's Last Theorem for `n = 3`, it is enough to show that for all `a`, `b`, `c`
in `ℤ` such that `c ≠ 0`, `¬ 3 ∣ a`, `¬ 3 ∣ b`, `a` and `b` are coprime and `3 ∣ c`, we have
`a ^ 3 + b ^ 3 ≠ c ^ 3`.
-/
theorem fermatLastTheoremThree_of_three_dvd_only_c
(H : ∀ a b c : ℤ, c ≠ 0 → ¬ 3 ∣ a → ¬ 3 ∣ b → 3 ∣ c → IsCoprime a b → a ^ 3 + b ^ 3 ≠ c ^ 3) :
FermatLastTheoremFor 3 := by
rw [fermatLastTheoremFor_iff_int]
refine fermatLastTheoremWith_of_fermatLastTheoremWith_coprime (fun a b c ha hb hc Hgcd hF ↦?_)
by_cases h1 : 3 ∣ a * b * c
swap
· exact fermatLastTheoremThree_case_1 h1 hF
rw [(prime_three).dvd_mul, (prime_three).dvd_mul] at h1
rw [← sub_eq_zero, sub_eq_add_neg, ← (show Odd 3 by decide).neg_pow] at hF
rcases h1 with (h3a | h3b) | h3c
· refine fermatLastTheoremThree_of_dvd_a_of_gcd_eq_one_of_case2 ha h3a ?_ H hF
simp only [← Hgcd, insert_comm, gcd_insert, gcd_singleton, id_eq, ← abs_eq_normalize, abs_neg]
· rw [add_comm (a ^ 3)] at hF
refine fermatLastTheoremThree_of_dvd_a_of_gcd_eq_one_of_case2 hb h3b ?_ H hF
simp only [← Hgcd, insert_comm, gcd_insert, gcd_singleton, id_eq, ← abs_eq_normalize, abs_neg]
· rw [add_comm _ ((-c) ^ 3), ← add_assoc] at hF
refine fermatLastTheoremThree_of_dvd_a_of_gcd_eq_one_of_case2 (neg_ne_zero.2 hc) (by simp [h3c])
?_ H hF
rw [Finset.insert_comm (-c), Finset.pair_comm (-c) b]
simp only [← Hgcd, insert_comm, gcd_insert, gcd_singleton, id_eq, ← abs_eq_normalize, abs_neg]
section eisenstein
open NumberField IsCyclotomicExtension.Rat.Three
variable {K : Type*} [Field K]
variable {ζ : K} (hζ : IsPrimitiveRoot ζ (3 : ℕ+))
local notation3 "η" => (IsPrimitiveRoot.isUnit (hζ.toInteger_isPrimitiveRoot) (by decide)).unit
local notation3 "λ" => hζ.toInteger - 1
/-- `FermatLastTheoremForThreeGen` is the statement that `a ^ 3 + b ^ 3 = u * c ^ 3` has no
nontrivial solutions in `𝓞 K` for all `u : (𝓞 K)ˣ` such that `¬ λ ∣ a`, `¬ λ ∣ b` and `λ ∣ c`.
The reason to consider `FermatLastTheoremForThreeGen` is to make a descent argument working. -/
def FermatLastTheoremForThreeGen : Prop :=
∀ a b c : 𝓞 K, ∀ u : (𝓞 K)ˣ, c ≠ 0 → ¬ λ ∣ a → ¬ λ ∣ b → λ ∣ c → IsCoprime a b →
a ^ 3 + b ^ 3 ≠ u * c ^ 3
/-- To prove `FermatLastTheoremFor 3`, it is enough to prove `FermatLastTheoremForThreeGen`. -/
lemma FermatLastTheoremForThree_of_FermatLastTheoremThreeGen
[NumberField K] [IsCyclotomicExtension {3} ℚ K] :
FermatLastTheoremForThreeGen hζ → FermatLastTheoremFor 3 := by
intro H
refine fermatLastTheoremThree_of_three_dvd_only_c (fun a b c hc ha hb ⟨x, hx⟩ hcoprime h ↦ ?_)
refine H a b c 1 (by simp [hc]) (fun hdvd ↦ ha ?_) (fun hdvd ↦ hb ?_) ?_ ?_ ?_
· rwa [← Ideal.norm_dvd_iff (hζ.prime_norm_toInteger_sub_one_of_prime_ne_two' (by decide)),
hζ.norm_toInteger_sub_one_of_prime_ne_two' (by decide)] at hdvd
· rwa [← Ideal.norm_dvd_iff (hζ.prime_norm_toInteger_sub_one_of_prime_ne_two' (by decide)),
hζ.norm_toInteger_sub_one_of_prime_ne_two' (by decide)] at hdvd
· exact dvd_trans hζ.toInteger_sub_one_dvd_prime' ⟨x, by simp [hx]⟩
· rw [show a = algebraMap _ (𝓞 K) a by simp, show b = algebraMap _ (𝓞 K) b by simp]
exact hcoprime.map _
· simp only [Units.val_one, one_mul]
exact_mod_cast h
namespace FermatLastTheoremForThreeGen
/-- `Solution'` is a tuple given by a solution to `a ^ 3 + b ^ 3 = u * c ^ 3`,
where `a`, `b`, `c` and `u` are as in `FermatLastTheoremForThreeGen`.
See `Solution` for the actual structure on which we will do the descent. -/
structure Solution' where
a : 𝓞 K
b : 𝓞 K
c : 𝓞 K
u : (𝓞 K)ˣ
ha : ¬ λ ∣ a
hb : ¬ λ ∣ b
hc : c ≠ 0
coprime : IsCoprime a b
hcdvd : λ ∣ c
H : a ^ 3 + b ^ 3 = u * c ^ 3
attribute [nolint docBlame] Solution'.a
attribute [nolint docBlame] Solution'.b
attribute [nolint docBlame] Solution'.c
attribute [nolint docBlame] Solution'.u
/-- `Solution` is the same as `Solution'` with the additional assumption that `λ ^ 2 ∣ a + b`. -/
structure Solution extends Solution' hζ where
hab : λ ^ 2 ∣ a + b
variable {hζ}
variable (S : Solution hζ) (S' : Solution' hζ)
section IsCyclotomicExtension
variable [NumberField K] [IsCyclotomicExtension {3} ℚ K]
/-- For any `S' : Solution'`, the multiplicity of `λ` in `S'.c` is finite. -/
lemma Solution'.multiplicity_lambda_c_finite :
FiniteMultiplicity (hζ.toInteger - 1) S'.c :=
.of_not_isUnit hζ.zeta_sub_one_prime'.not_unit S'.hc
/-- Given `S' : Solution'`, `S'.multiplicity` is the multiplicity of `λ` in `S'.c`, as a natural
number. -/
noncomputable def Solution'.multiplicity :=
_root_.multiplicity (hζ.toInteger - 1) S'.c
/-- Given `S : Solution`, `S.multiplicity` is the multiplicity of `λ` in `S.c`, as a natural
number. -/
noncomputable def Solution.multiplicity := S.toSolution'.multiplicity
/-- We say that `S : Solution` is minimal if for all `S₁ : Solution`, the multiplicity of `λ` in
`S.c` is less or equal than the multiplicity in `S₁.c`. -/
def Solution.isMinimal : Prop := ∀ (S₁ : Solution hζ), S.multiplicity ≤ S₁.multiplicity
omit [NumberField K] [IsCyclotomicExtension {3} ℚ K] in
include S in
/-- If there is a solution then there is a minimal one. -/
lemma Solution.exists_minimal : ∃ (S₁ : Solution hζ), S₁.isMinimal := by
classical
let T := {n | ∃ (S' : Solution hζ), S'.multiplicity = n}
rcases Nat.find_spec (⟨S.multiplicity, ⟨S, rfl⟩⟩ : T.Nonempty) with ⟨S₁, hS₁⟩
exact ⟨S₁, fun S'' ↦ hS₁ ▸ Nat.find_min' _ ⟨S'', rfl⟩⟩
/-- Given `S' : Solution'`, then `S'.a` and `S'.b` are both congruent to `1` modulo `λ ^ 4` or are
both congruent to `-1`. -/
lemma a_cube_b_cube_congr_one_or_neg_one :
λ ^ 4 ∣ S'.a ^ 3 - 1 ∧ λ ^ 4 ∣ S'.b ^ 3 + 1 ∨ λ ^ 4 ∣ S'.a ^ 3 + 1 ∧ λ ^ 4 ∣ S'.b ^ 3 - 1 := by
obtain ⟨z, hz⟩ := S'.hcdvd
rcases lambda_pow_four_dvd_cube_sub_one_or_add_one_of_lambda_not_dvd hζ S'.ha with
⟨x, hx⟩ | ⟨x, hx⟩ <;>
rcases lambda_pow_four_dvd_cube_sub_one_or_add_one_of_lambda_not_dvd hζ S'.hb with
⟨y, hy⟩ | ⟨y, hy⟩
· exfalso
replace hζ : IsPrimitiveRoot ζ ((3 : ℕ+) ^ 1) := by rwa [pow_one]
refine hζ.toInteger_sub_one_not_dvd_two (by decide) ⟨S'.u * λ ^ 2 * z ^ 3 - λ ^ 3 * (x + y), ?_⟩
symm
calc _ = S'.u * (λ * z) ^ 3 - λ ^ 4 * x - λ ^ 4 * y := by ring
_ = (S'.a ^ 3 + S'.b ^ 3) - (S'.a ^ 3 - 1) - (S'.b ^ 3 - 1) := by rw [← hx, ← hy, ← hz, ← S'.H]
_ = 2 := by ring
· left
exact ⟨⟨x, hx⟩, ⟨y, hy⟩⟩
· right
exact ⟨⟨x, hx⟩, ⟨y, hy⟩⟩
· exfalso
replace hζ : IsPrimitiveRoot ζ ((3 : ℕ+) ^ 1) := by rwa [pow_one]
refine hζ.toInteger_sub_one_not_dvd_two (by decide) ⟨λ ^ 3 * (x + y) - S'.u * λ ^ 2 * z ^ 3, ?_⟩
symm
calc _ = λ ^ 4 * x + λ ^ 4 * y - S'.u * (λ * z) ^ 3 := by ring
_ = (S'.a ^ 3 + 1) + (S'.b ^ 3 + 1) - (S'.a ^ 3 + S'.b ^ 3) := by rw [← hx, ← hy, ← hz, ← S'.H]
_ = 2 := by ring
/-- Given `S' : Solution'`, we have that `λ ^ 4` divides `S'.c ^ 3`. -/
lemma lambda_pow_four_dvd_c_cube : λ ^ 4 ∣ S'.c ^ 3 := by
rcases a_cube_b_cube_congr_one_or_neg_one S' with
⟨⟨x, hx⟩, ⟨y, hy⟩⟩ | ⟨⟨x, hx⟩, ⟨y, hy⟩⟩ <;>
· refine ⟨S'.u⁻¹ * (x + y), ?_⟩
symm
calc _ = S'.u⁻¹ * (λ ^ 4 * x + λ ^ 4 * y) := by ring
_ = S'.u⁻¹ * (S'.a ^ 3 + S'.b ^ 3) := by rw [← hx, ← hy]; ring
_ = S'.u⁻¹ * (S'.u * S'.c ^ 3) := by rw [S'.H]
_ = S'.c ^ 3 := by simp
/-- Given `S' : Solution'`, we have that `λ ^ 2` divides `S'.c`. -/
lemma lambda_sq_dvd_c : λ ^ 2 ∣ S'.c := by
| have hm := S'.multiplicity_lambda_c_finite
suffices 2 ≤ multiplicity (hζ.toInteger - 1) S'.c by
obtain ⟨x, hx⟩ := pow_multiplicity_dvd (hζ.toInteger - 1) S'.c
refine ⟨λ ^ (multiplicity (hζ.toInteger - 1) S'.c - 2) * x, ?_⟩
rw [← mul_assoc, ← pow_add]
convert hx using 3
simp [this]
have := lambda_pow_four_dvd_c_cube S'
rw [pow_dvd_iff_le_emultiplicity, emultiplicity_pow hζ.zeta_sub_one_prime',
hm.emultiplicity_eq_multiplicity] at this
norm_cast at this
omega
/-- Given `S' : Solution'`, we have that `2 ≤ S'.multiplicity`. -/
lemma Solution'.two_le_multiplicity : 2 ≤ S'.multiplicity := by
simpa [Solution'.multiplicity] using
S'.multiplicity_lambda_c_finite.le_multiplicity_of_pow_dvd (lambda_sq_dvd_c S')
/-- Given `S : Solution`, we have that `2 ≤ S.multiplicity`. -/
lemma Solution.two_le_multiplicity : 2 ≤ S.multiplicity :=
S.toSolution'.two_le_multiplicity
end IsCyclotomicExtension
/-- Given `S' : Solution'`, the key factorization of `S'.a ^ 3 + S'.b ^ 3`. -/
lemma a_cube_add_b_cube_eq_mul :
S'.a ^ 3 + S'.b ^ 3 = (S'.a + S'.b) * (S'.a + η * S'.b) * (S'.a + η ^ 2 * S'.b) := by
symm
calc _ = S'.a^3+S'.a^2*S'.b*(η^2+η+1)+S'.a*S'.b^2*(η^2+η+η^3)+η^3*S'.b^3 := by ring
| Mathlib/NumberTheory/FLT/Three.lean | 279 | 307 |
/-
Copyright (c) 2018 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Jens Wagemaker
-/
import Mathlib.Algebra.Ring.Associated
import Mathlib.Algebra.Ring.Regular
/-!
# Monoids with normalization functions, `gcd`, and `lcm`
This file defines extra structures on `CancelCommMonoidWithZero`s, including `IsDomain`s.
## Main Definitions
* `NormalizationMonoid`
* `GCDMonoid`
* `NormalizedGCDMonoid`
* `gcdMonoidOfGCD`, `gcdMonoidOfExistsGCD`, `normalizedGCDMonoidOfGCD`,
`normalizedGCDMonoidOfExistsGCD`
* `gcdMonoidOfLCM`, `gcdMonoidOfExistsLCM`, `normalizedGCDMonoidOfLCM`,
`normalizedGCDMonoidOfExistsLCM`
For the `NormalizedGCDMonoid` instances on `ℕ` and `ℤ`, see `Mathlib.Algebra.GCDMonoid.Nat`.
## Implementation Notes
* `NormalizationMonoid` is defined by assigning to each element a `normUnit` such that multiplying
by that unit normalizes the monoid, and `normalize` is an idempotent monoid homomorphism. This
definition as currently implemented does casework on `0`.
* `GCDMonoid` contains the definitions of `gcd` and `lcm` with the usual properties. They are
both determined up to a unit.
* `NormalizedGCDMonoid` extends `NormalizationMonoid`, so the `gcd` and `lcm` are always
normalized. This makes `gcd`s of polynomials easier to work with, but excludes Euclidean domains,
and monoids without zero.
* `gcdMonoidOfGCD` and `normalizedGCDMonoidOfGCD` noncomputably construct a `GCDMonoid`
(resp. `NormalizedGCDMonoid`) structure just from the `gcd` and its properties.
* `gcdMonoidOfExistsGCD` and `normalizedGCDMonoidOfExistsGCD` noncomputably construct a
`GCDMonoid` (resp. `NormalizedGCDMonoid`) structure just from a proof that any two elements
have a (not necessarily normalized) `gcd`.
* `gcdMonoidOfLCM` and `normalizedGCDMonoidOfLCM` noncomputably construct a `GCDMonoid`
(resp. `NormalizedGCDMonoid`) structure just from the `lcm` and its properties.
* `gcdMonoidOfExistsLCM` and `normalizedGCDMonoidOfExistsLCM` noncomputably construct a
`GCDMonoid` (resp. `NormalizedGCDMonoid`) structure just from a proof that any two elements
have a (not necessarily normalized) `lcm`.
## TODO
* Port GCD facts about nats, definition of coprime
* Generalize normalization monoids to commutative (cancellative) monoids with or without zero
## Tags
divisibility, gcd, lcm, normalize
-/
variable {α : Type*}
/-- Normalization monoid: multiplying with `normUnit` gives a normal form for associated
elements. -/
class NormalizationMonoid (α : Type*) [CancelCommMonoidWithZero α] where
/-- `normUnit` assigns to each element of the monoid a unit of the monoid. -/
normUnit : α → αˣ
/-- The proposition that `normUnit` maps `0` to the identity. -/
normUnit_zero : normUnit 0 = 1
/-- The proposition that `normUnit` respects multiplication of non-zero elements. -/
normUnit_mul : ∀ {a b}, a ≠ 0 → b ≠ 0 → normUnit (a * b) = normUnit a * normUnit b
/-- The proposition that `normUnit` maps units to their inverses. -/
normUnit_coe_units : ∀ u : αˣ, normUnit u = u⁻¹
export NormalizationMonoid (normUnit normUnit_zero normUnit_mul normUnit_coe_units)
attribute [simp] normUnit_coe_units normUnit_zero normUnit_mul
section NormalizationMonoid
variable [CancelCommMonoidWithZero α] [NormalizationMonoid α]
@[simp]
theorem normUnit_one : normUnit (1 : α) = 1 :=
normUnit_coe_units 1
/-- Chooses an element of each associate class, by multiplying by `normUnit` -/
def normalize : α →*₀ α where
toFun x := x * normUnit x
map_zero' := by
simp only [normUnit_zero]
exact mul_one (0 : α)
map_one' := by rw [normUnit_one, one_mul]; rfl
map_mul' x y :=
(by_cases fun hx : x = 0 => by rw [hx, zero_mul, zero_mul, zero_mul]) fun hx =>
(by_cases fun hy : y = 0 => by rw [hy, mul_zero, zero_mul, mul_zero]) fun hy => by
simp only [normUnit_mul hx hy, Units.val_mul]; simp only [mul_assoc, mul_left_comm y]
theorem associated_normalize (x : α) : Associated x (normalize x) :=
⟨_, rfl⟩
theorem normalize_associated (x : α) : Associated (normalize x) x :=
(associated_normalize _).symm
theorem associated_normalize_iff {x y : α} : Associated x (normalize y) ↔ Associated x y :=
⟨fun h => h.trans (normalize_associated y), fun h => h.trans (associated_normalize y)⟩
theorem normalize_associated_iff {x y : α} : Associated (normalize x) y ↔ Associated x y :=
⟨fun h => (associated_normalize _).trans h, fun h => (normalize_associated _).trans h⟩
theorem Associates.mk_normalize (x : α) : Associates.mk (normalize x) = Associates.mk x :=
Associates.mk_eq_mk_iff_associated.2 (normalize_associated _)
theorem normalize_apply (x : α) : normalize x = x * normUnit x :=
rfl
theorem normalize_zero : normalize (0 : α) = 0 :=
normalize.map_zero
theorem normalize_one : normalize (1 : α) = 1 :=
normalize.map_one
theorem normalize_coe_units (u : αˣ) : normalize (u : α) = 1 := by simp [normalize_apply]
theorem normalize_eq_zero {x : α} : normalize x = 0 ↔ x = 0 :=
⟨fun hx => (associated_zero_iff_eq_zero x).1 <| hx ▸ associated_normalize _, by
rintro rfl; exact normalize_zero⟩
theorem normalize_eq_one {x : α} : normalize x = 1 ↔ IsUnit x :=
⟨fun hx => isUnit_iff_exists_inv.2 ⟨_, hx⟩, fun ⟨u, hu⟩ => hu ▸ normalize_coe_units u⟩
@[simp]
theorem normUnit_mul_normUnit (a : α) : normUnit (a * normUnit a) = 1 := by
nontriviality α using Subsingleton.elim a 0
obtain rfl | h := eq_or_ne a 0
· rw [normUnit_zero, zero_mul, normUnit_zero]
· rw [normUnit_mul h (Units.ne_zero _), normUnit_coe_units, mul_inv_eq_one]
@[simp]
theorem normalize_idem (x : α) : normalize (normalize x) = normalize x := by simp [normalize_apply]
theorem normalize_eq_normalize {a b : α} (hab : a ∣ b) (hba : b ∣ a) :
normalize a = normalize b := by
nontriviality α
rcases associated_of_dvd_dvd hab hba with ⟨u, rfl⟩
refine by_cases (by rintro rfl; simp only [zero_mul]) fun ha : a ≠ 0 => ?_
suffices a * ↑(normUnit a) = a * ↑u * ↑(normUnit a) * ↑u⁻¹ by
simpa only [normalize_apply, mul_assoc, normUnit_mul ha u.ne_zero, normUnit_coe_units]
calc
a * ↑(normUnit a) = a * ↑(normUnit a) * ↑u * ↑u⁻¹ := (Units.mul_inv_cancel_right _ _).symm
_ = a * ↑u * ↑(normUnit a) * ↑u⁻¹ := by rw [mul_right_comm a]
theorem normalize_eq_normalize_iff {x y : α} : normalize x = normalize y ↔ x ∣ y ∧ y ∣ x :=
⟨fun h => ⟨Units.dvd_mul_right.1 ⟨_, h.symm⟩, Units.dvd_mul_right.1 ⟨_, h⟩⟩, fun ⟨hxy, hyx⟩ =>
normalize_eq_normalize hxy hyx⟩
theorem dvd_antisymm_of_normalize_eq {a b : α} (ha : normalize a = a) (hb : normalize b = b)
(hab : a ∣ b) (hba : b ∣ a) : a = b :=
ha ▸ hb ▸ normalize_eq_normalize hab hba
theorem Associated.eq_of_normalized
{a b : α} (h : Associated a b) (ha : normalize a = a) (hb : normalize b = b) :
a = b :=
dvd_antisymm_of_normalize_eq ha hb h.dvd h.dvd'
@[simp]
theorem dvd_normalize_iff {a b : α} : a ∣ normalize b ↔ a ∣ b :=
Units.dvd_mul_right
@[simp]
theorem normalize_dvd_iff {a b : α} : normalize a ∣ b ↔ a ∣ b :=
Units.mul_right_dvd
end NormalizationMonoid
namespace Associates
variable [CancelCommMonoidWithZero α] [NormalizationMonoid α]
/-- Maps an element of `Associates` back to the normalized element of its associate class -/
protected def out : Associates α → α :=
(Quotient.lift (normalize : α → α)) fun a _ ⟨_, hu⟩ =>
hu ▸ normalize_eq_normalize ⟨_, rfl⟩ (Units.mul_right_dvd.2 <| dvd_refl a)
@[simp]
theorem out_mk (a : α) : (Associates.mk a).out = normalize a :=
rfl
@[simp]
theorem out_one : (1 : Associates α).out = 1 :=
normalize_one
theorem out_mul (a b : Associates α) : (a * b).out = a.out * b.out :=
Quotient.inductionOn₂ a b fun _ _ => by
simp only [Associates.quotient_mk_eq_mk, out_mk, mk_mul_mk, normalize.map_mul]
theorem dvd_out_iff (a : α) (b : Associates α) : a ∣ b.out ↔ Associates.mk a ≤ b :=
Quotient.inductionOn b <| by
simp [Associates.out_mk, Associates.quotient_mk_eq_mk, mk_le_mk_iff_dvd]
theorem out_dvd_iff (a : α) (b : Associates α) : b.out ∣ a ↔ b ≤ Associates.mk a :=
Quotient.inductionOn b <| by
simp [Associates.out_mk, Associates.quotient_mk_eq_mk, mk_le_mk_iff_dvd]
@[simp]
theorem out_top : (⊤ : Associates α).out = 0 :=
normalize_zero
@[simp]
theorem normalize_out (a : Associates α) : normalize a.out = a.out :=
Quotient.inductionOn a normalize_idem
@[simp]
theorem mk_out (a : Associates α) : Associates.mk a.out = a :=
Quotient.inductionOn a mk_normalize
theorem out_injective : Function.Injective (Associates.out : _ → α) :=
Function.LeftInverse.injective mk_out
end Associates
/-- GCD monoid: a `CancelCommMonoidWithZero` with `gcd` (greatest common divisor) and
`lcm` (least common multiple) operations, determined up to a unit. The type class focuses on `gcd`
and we derive the corresponding `lcm` facts from `gcd`.
-/
class GCDMonoid (α : Type*) [CancelCommMonoidWithZero α] where
/-- The greatest common divisor between two elements. -/
gcd : α → α → α
/-- The least common multiple between two elements. -/
lcm : α → α → α
/-- The GCD is a divisor of the first element. -/
gcd_dvd_left : ∀ a b, gcd a b ∣ a
/-- The GCD is a divisor of the second element. -/
gcd_dvd_right : ∀ a b, gcd a b ∣ b
/-- Any common divisor of both elements is a divisor of the GCD. -/
dvd_gcd : ∀ {a b c}, a ∣ c → a ∣ b → a ∣ gcd c b
/-- The product of two elements is `Associated` with the product of their GCD and LCM. -/
gcd_mul_lcm : ∀ a b, Associated (gcd a b * lcm a b) (a * b)
/-- `0` is left-absorbing. -/
lcm_zero_left : ∀ a, lcm 0 a = 0
/-- `0` is right-absorbing. -/
lcm_zero_right : ∀ a, lcm a 0 = 0
/-- Normalized GCD monoid: a `CancelCommMonoidWithZero` with normalization and `gcd`
(greatest common divisor) and `lcm` (least common multiple) operations. In this setting `gcd` and
`lcm` form a bounded lattice on the associated elements where `gcd` is the infimum, `lcm` is the
supremum, `1` is bottom, and `0` is top. The type class focuses on `gcd` and we derive the
corresponding `lcm` facts from `gcd`.
-/
class NormalizedGCDMonoid (α : Type*) [CancelCommMonoidWithZero α] extends NormalizationMonoid α,
GCDMonoid α where
/-- The GCD is normalized to itself. -/
normalize_gcd : ∀ a b, normalize (gcd a b) = gcd a b
/-- The LCM is normalized to itself. -/
normalize_lcm : ∀ a b, normalize (lcm a b) = lcm a b
export GCDMonoid (gcd lcm gcd_dvd_left gcd_dvd_right dvd_gcd lcm_zero_left lcm_zero_right)
attribute [simp] lcm_zero_left lcm_zero_right
section GCDMonoid
variable [CancelCommMonoidWithZero α]
instance [NormalizationMonoid α] : Nonempty (NormalizationMonoid α) := ⟨‹_›⟩
instance [GCDMonoid α] : Nonempty (GCDMonoid α) := ⟨‹_›⟩
instance [NormalizedGCDMonoid α] : Nonempty (NormalizedGCDMonoid α) := ⟨‹_›⟩
instance [h : Nonempty (NormalizedGCDMonoid α)] : Nonempty (NormalizationMonoid α) :=
h.elim fun _ ↦ inferInstance
instance [h : Nonempty (NormalizedGCDMonoid α)] : Nonempty (GCDMonoid α) :=
h.elim fun _ ↦ inferInstance
theorem gcd_isUnit_iff_isRelPrime [GCDMonoid α] {a b : α} :
IsUnit (gcd a b) ↔ IsRelPrime a b :=
⟨fun h _ ha hb ↦ isUnit_of_dvd_unit (dvd_gcd ha hb) h, (· (gcd_dvd_left a b) (gcd_dvd_right a b))⟩
@[simp]
theorem normalize_gcd [NormalizedGCDMonoid α] : ∀ a b : α, normalize (gcd a b) = gcd a b :=
NormalizedGCDMonoid.normalize_gcd
theorem gcd_mul_lcm [GCDMonoid α] : ∀ a b : α, Associated (gcd a b * lcm a b) (a * b) :=
GCDMonoid.gcd_mul_lcm
section GCD
theorem dvd_gcd_iff [GCDMonoid α] (a b c : α) : a ∣ gcd b c ↔ a ∣ b ∧ a ∣ c :=
Iff.intro (fun h => ⟨h.trans (gcd_dvd_left _ _), h.trans (gcd_dvd_right _ _)⟩) fun ⟨hab, hac⟩ =>
dvd_gcd hab hac
theorem gcd_comm [NormalizedGCDMonoid α] (a b : α) : gcd a b = gcd b a :=
dvd_antisymm_of_normalize_eq (normalize_gcd _ _) (normalize_gcd _ _)
(dvd_gcd (gcd_dvd_right _ _) (gcd_dvd_left _ _))
(dvd_gcd (gcd_dvd_right _ _) (gcd_dvd_left _ _))
theorem gcd_comm' [GCDMonoid α] (a b : α) : Associated (gcd a b) (gcd b a) :=
associated_of_dvd_dvd (dvd_gcd (gcd_dvd_right _ _) (gcd_dvd_left _ _))
(dvd_gcd (gcd_dvd_right _ _) (gcd_dvd_left _ _))
theorem gcd_assoc [NormalizedGCDMonoid α] (m n k : α) : gcd (gcd m n) k = gcd m (gcd n k) :=
dvd_antisymm_of_normalize_eq (normalize_gcd _ _) (normalize_gcd _ _)
(dvd_gcd ((gcd_dvd_left (gcd m n) k).trans (gcd_dvd_left m n))
(dvd_gcd ((gcd_dvd_left (gcd m n) k).trans (gcd_dvd_right m n)) (gcd_dvd_right (gcd m n) k)))
(dvd_gcd
(dvd_gcd (gcd_dvd_left m (gcd n k)) ((gcd_dvd_right m (gcd n k)).trans (gcd_dvd_left n k)))
((gcd_dvd_right m (gcd n k)).trans (gcd_dvd_right n k)))
theorem gcd_assoc' [GCDMonoid α] (m n k : α) : Associated (gcd (gcd m n) k) (gcd m (gcd n k)) :=
associated_of_dvd_dvd
(dvd_gcd ((gcd_dvd_left (gcd m n) k).trans (gcd_dvd_left m n))
(dvd_gcd ((gcd_dvd_left (gcd m n) k).trans (gcd_dvd_right m n)) (gcd_dvd_right (gcd m n) k)))
(dvd_gcd
(dvd_gcd (gcd_dvd_left m (gcd n k)) ((gcd_dvd_right m (gcd n k)).trans (gcd_dvd_left n k)))
((gcd_dvd_right m (gcd n k)).trans (gcd_dvd_right n k)))
instance [NormalizedGCDMonoid α] : Std.Commutative (α := α) gcd where
comm := gcd_comm
instance [NormalizedGCDMonoid α] : Std.Associative (α := α) gcd where
assoc := gcd_assoc
theorem gcd_eq_normalize [NormalizedGCDMonoid α] {a b c : α} (habc : gcd a b ∣ c)
(hcab : c ∣ gcd a b) : gcd a b = normalize c :=
normalize_gcd a b ▸ normalize_eq_normalize habc hcab
@[simp]
theorem gcd_zero_left [NormalizedGCDMonoid α] (a : α) : gcd 0 a = normalize a :=
gcd_eq_normalize (gcd_dvd_right 0 a) (dvd_gcd (dvd_zero _) (dvd_refl a))
theorem gcd_zero_left' [GCDMonoid α] (a : α) : Associated (gcd 0 a) a :=
associated_of_dvd_dvd (gcd_dvd_right 0 a) (dvd_gcd (dvd_zero _) (dvd_refl a))
@[simp]
theorem gcd_zero_right [NormalizedGCDMonoid α] (a : α) : gcd a 0 = normalize a :=
gcd_eq_normalize (gcd_dvd_left a 0) (dvd_gcd (dvd_refl a) (dvd_zero _))
theorem gcd_zero_right' [GCDMonoid α] (a : α) : Associated (gcd a 0) a :=
associated_of_dvd_dvd (gcd_dvd_left a 0) (dvd_gcd (dvd_refl a) (dvd_zero _))
@[simp]
theorem gcd_eq_zero_iff [GCDMonoid α] (a b : α) : gcd a b = 0 ↔ a = 0 ∧ b = 0 :=
Iff.intro
(fun h => by
let ⟨ca, ha⟩ := gcd_dvd_left a b
let ⟨cb, hb⟩ := gcd_dvd_right a b
rw [h, zero_mul] at ha hb
exact ⟨ha, hb⟩)
fun ⟨ha, hb⟩ => by
rw [ha, hb, ← zero_dvd_iff]
apply dvd_gcd <;> rfl
theorem gcd_ne_zero_of_left [GCDMonoid α] {a b : α} (ha : a ≠ 0) : gcd a b ≠ 0 := by
simp_all
theorem gcd_ne_zero_of_right [GCDMonoid α] {a b : α} (hb : b ≠ 0) : gcd a b ≠ 0 := by
simp_all
@[simp]
theorem gcd_one_left [NormalizedGCDMonoid α] (a : α) : gcd 1 a = 1 :=
dvd_antisymm_of_normalize_eq (normalize_gcd _ _) normalize_one (gcd_dvd_left _ _) (one_dvd _)
@[simp]
theorem isUnit_gcd_one_left [GCDMonoid α] (a : α) : IsUnit (gcd 1 a) :=
isUnit_of_dvd_one (gcd_dvd_left _ _)
theorem gcd_one_left' [GCDMonoid α] (a : α) : Associated (gcd 1 a) 1 := by simp
@[simp]
theorem gcd_one_right [NormalizedGCDMonoid α] (a : α) : gcd a 1 = 1 :=
dvd_antisymm_of_normalize_eq (normalize_gcd _ _) normalize_one (gcd_dvd_right _ _) (one_dvd _)
@[simp]
theorem isUnit_gcd_one_right [GCDMonoid α] (a : α) : IsUnit (gcd a 1) :=
isUnit_of_dvd_one (gcd_dvd_right _ _)
theorem gcd_one_right' [GCDMonoid α] (a : α) : Associated (gcd a 1) 1 := by simp
theorem gcd_dvd_gcd [GCDMonoid α] {a b c d : α} (hab : a ∣ b) (hcd : c ∣ d) : gcd a c ∣ gcd b d :=
dvd_gcd ((gcd_dvd_left _ _).trans hab) ((gcd_dvd_right _ _).trans hcd)
protected theorem Associated.gcd [GCDMonoid α]
{a₁ a₂ b₁ b₂ : α} (ha : Associated a₁ a₂) (hb : Associated b₁ b₂) :
Associated (gcd a₁ b₁) (gcd a₂ b₂) :=
associated_of_dvd_dvd (gcd_dvd_gcd ha.dvd hb.dvd) (gcd_dvd_gcd ha.dvd' hb.dvd')
@[simp]
theorem gcd_same [NormalizedGCDMonoid α] (a : α) : gcd a a = normalize a :=
gcd_eq_normalize (gcd_dvd_left _ _) (dvd_gcd (dvd_refl a) (dvd_refl a))
@[simp]
theorem gcd_mul_left [NormalizedGCDMonoid α] (a b c : α) :
gcd (a * b) (a * c) = normalize a * gcd b c :=
(by_cases (by rintro rfl; simp only [zero_mul, gcd_zero_left, normalize_zero]))
fun ha : a ≠ 0 =>
suffices gcd (a * b) (a * c) = normalize (a * gcd b c) by simpa
let ⟨d, eq⟩ := dvd_gcd (dvd_mul_right a b) (dvd_mul_right a c)
gcd_eq_normalize
(eq.symm ▸ mul_dvd_mul_left a
(show d ∣ gcd b c from
dvd_gcd ((mul_dvd_mul_iff_left ha).1 <| eq ▸ gcd_dvd_left _ _)
((mul_dvd_mul_iff_left ha).1 <| eq ▸ gcd_dvd_right _ _)))
(dvd_gcd (mul_dvd_mul_left a <| gcd_dvd_left _ _) (mul_dvd_mul_left a <| gcd_dvd_right _ _))
theorem gcd_mul_left' [GCDMonoid α] (a b c : α) :
Associated (gcd (a * b) (a * c)) (a * gcd b c) := by
obtain rfl | ha := eq_or_ne a 0
· simp only [zero_mul, gcd_zero_left']
obtain ⟨d, eq⟩ := dvd_gcd (dvd_mul_right a b) (dvd_mul_right a c)
apply associated_of_dvd_dvd
· rw [eq]
apply mul_dvd_mul_left
exact
dvd_gcd ((mul_dvd_mul_iff_left ha).1 <| eq ▸ gcd_dvd_left _ _)
((mul_dvd_mul_iff_left ha).1 <| eq ▸ gcd_dvd_right _ _)
· exact dvd_gcd (mul_dvd_mul_left a <| gcd_dvd_left _ _) (mul_dvd_mul_left a <| gcd_dvd_right _ _)
@[simp]
theorem gcd_mul_right [NormalizedGCDMonoid α] (a b c : α) :
gcd (b * a) (c * a) = gcd b c * normalize a := by simp only [mul_comm, gcd_mul_left]
@[simp]
theorem gcd_mul_right' [GCDMonoid α] (a b c : α) :
Associated (gcd (b * a) (c * a)) (gcd b c * a) := by
simp only [mul_comm, gcd_mul_left']
theorem gcd_eq_left_iff [NormalizedGCDMonoid α] (a b : α) (h : normalize a = a) :
gcd a b = a ↔ a ∣ b :=
(Iff.intro fun eq => eq ▸ gcd_dvd_right _ _) fun hab =>
dvd_antisymm_of_normalize_eq (normalize_gcd _ _) h (gcd_dvd_left _ _) (dvd_gcd (dvd_refl a) hab)
theorem gcd_eq_right_iff [NormalizedGCDMonoid α] (a b : α) (h : normalize b = b) :
gcd a b = b ↔ b ∣ a := by simpa only [gcd_comm a b] using gcd_eq_left_iff b a h
theorem gcd_dvd_gcd_mul_left [GCDMonoid α] (m n k : α) : gcd m n ∣ gcd (k * m) n :=
gcd_dvd_gcd (dvd_mul_left _ _) dvd_rfl
theorem gcd_dvd_gcd_mul_right [GCDMonoid α] (m n k : α) : gcd m n ∣ gcd (m * k) n :=
gcd_dvd_gcd (dvd_mul_right _ _) dvd_rfl
theorem gcd_dvd_gcd_mul_left_right [GCDMonoid α] (m n k : α) : gcd m n ∣ gcd m (k * n) :=
gcd_dvd_gcd dvd_rfl (dvd_mul_left _ _)
theorem gcd_dvd_gcd_mul_right_right [GCDMonoid α] (m n k : α) : gcd m n ∣ gcd m (n * k) :=
gcd_dvd_gcd dvd_rfl (dvd_mul_right _ _)
theorem Associated.gcd_eq_left [NormalizedGCDMonoid α] {m n : α} (h : Associated m n) (k : α) :
gcd m k = gcd n k :=
dvd_antisymm_of_normalize_eq (normalize_gcd _ _) (normalize_gcd _ _) (gcd_dvd_gcd h.dvd dvd_rfl)
(gcd_dvd_gcd h.symm.dvd dvd_rfl)
theorem Associated.gcd_eq_right [NormalizedGCDMonoid α] {m n : α} (h : Associated m n) (k : α) :
gcd k m = gcd k n :=
dvd_antisymm_of_normalize_eq (normalize_gcd _ _) (normalize_gcd _ _) (gcd_dvd_gcd dvd_rfl h.dvd)
(gcd_dvd_gcd dvd_rfl h.symm.dvd)
theorem dvd_gcd_mul_of_dvd_mul [GCDMonoid α] {m n k : α} (H : k ∣ m * n) : k ∣ gcd k m * n :=
(dvd_gcd (dvd_mul_right _ n) H).trans (gcd_mul_right' n k m).dvd
theorem dvd_gcd_mul_iff_dvd_mul [GCDMonoid α] {m n k : α} : k ∣ gcd k m * n ↔ k ∣ m * n :=
⟨fun h => h.trans (mul_dvd_mul (gcd_dvd_right k m) dvd_rfl), dvd_gcd_mul_of_dvd_mul⟩
theorem dvd_mul_gcd_of_dvd_mul [GCDMonoid α] {m n k : α} (H : k ∣ m * n) : k ∣ m * gcd k n := by
rw [mul_comm] at H ⊢
exact dvd_gcd_mul_of_dvd_mul H
theorem dvd_mul_gcd_iff_dvd_mul [GCDMonoid α] {m n k : α} : k ∣ m * gcd k n ↔ k ∣ m * n :=
⟨fun h => h.trans (mul_dvd_mul dvd_rfl (gcd_dvd_right k n)), dvd_mul_gcd_of_dvd_mul⟩
/-- Represent a divisor of `m * n` as a product of a divisor of `m` and a divisor of `n`.
Note: In general, this representation is highly non-unique.
See `Nat.dvdProdDvdOfDvdProd` for a constructive version on `ℕ`. -/
instance [h : Nonempty (GCDMonoid α)] : DecompositionMonoid α where
primal k m n H := by
cases h
by_cases h0 : gcd k m = 0
· rw [gcd_eq_zero_iff] at h0
rcases h0 with ⟨rfl, rfl⟩
exact ⟨0, n, dvd_refl 0, dvd_refl n, by simp⟩
· obtain ⟨a, ha⟩ := gcd_dvd_left k m
refine ⟨gcd k m, a, gcd_dvd_right _ _, ?_, ha⟩
rw [← mul_dvd_mul_iff_left h0, ← ha]
exact dvd_gcd_mul_of_dvd_mul H
theorem gcd_mul_dvd_mul_gcd [GCDMonoid α] (k m n : α) : gcd k (m * n) ∣ gcd k m * gcd k n := by
obtain ⟨m', n', hm', hn', h⟩ := exists_dvd_and_dvd_of_dvd_mul (gcd_dvd_right k (m * n))
replace h : gcd k (m * n) = m' * n' := h
rw [h]
have hm'n' : m' * n' ∣ k := h ▸ gcd_dvd_left _ _
apply mul_dvd_mul
· have hm'k : m' ∣ k := (dvd_mul_right m' n').trans hm'n'
exact dvd_gcd hm'k hm'
· have hn'k : n' ∣ k := (dvd_mul_left n' m').trans hm'n'
exact dvd_gcd hn'k hn'
theorem gcd_pow_right_dvd_pow_gcd [GCDMonoid α] {a b : α} {k : ℕ} :
gcd a (b ^ k) ∣ gcd a b ^ k := by
by_cases hg : gcd a b = 0
· rw [gcd_eq_zero_iff] at hg
rcases hg with ⟨rfl, rfl⟩
exact
(gcd_zero_left' (0 ^ k : α)).dvd.trans
(pow_dvd_pow_of_dvd (gcd_zero_left' (0 : α)).symm.dvd _)
· induction k with
| zero => rw [pow_zero, pow_zero]; exact (gcd_one_right' a).dvd
| succ k hk =>
rw [pow_succ', pow_succ']
trans gcd a b * gcd a (b ^ k)
· exact gcd_mul_dvd_mul_gcd a b (b ^ k)
· exact (mul_dvd_mul_iff_left hg).mpr hk
theorem gcd_pow_left_dvd_pow_gcd [GCDMonoid α] {a b : α} {k : ℕ} : gcd (a ^ k) b ∣ gcd a b ^ k :=
calc
gcd (a ^ k) b ∣ gcd b (a ^ k) := (gcd_comm' _ _).dvd
_ ∣ gcd b a ^ k := gcd_pow_right_dvd_pow_gcd
_ ∣ gcd a b ^ k := pow_dvd_pow_of_dvd (gcd_comm' _ _).dvd _
theorem pow_dvd_of_mul_eq_pow [GCDMonoid α] {a b c d₁ d₂ : α} (ha : a ≠ 0) (hab : IsUnit (gcd a b))
{k : ℕ} (h : a * b = c ^ k) (hc : c = d₁ * d₂) (hd₁ : d₁ ∣ a) : d₁ ^ k ≠ 0 ∧ d₁ ^ k ∣ a := by
have h1 : IsUnit (gcd (d₁ ^ k) b) := by
apply isUnit_of_dvd_one
trans gcd d₁ b ^ k
· exact gcd_pow_left_dvd_pow_gcd
· apply IsUnit.dvd
apply IsUnit.pow
apply isUnit_of_dvd_one
apply dvd_trans _ hab.dvd
apply gcd_dvd_gcd hd₁ (dvd_refl b)
have h2 : d₁ ^ k ∣ a * b := by
use d₂ ^ k
rw [h, hc]
exact mul_pow d₁ d₂ k
rw [mul_comm] at h2
have h3 : d₁ ^ k ∣ a := by
| apply (dvd_gcd_mul_of_dvd_mul h2).trans
rw [h1.mul_left_dvd]
have h4 : d₁ ^ k ≠ 0 := by
| Mathlib/Algebra/GCDMonoid/Basic.lean | 538 | 540 |
/-
Copyright (c) 2018 Patrick Massot. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Massot, Kevin Buzzard, Kim Morrison, Johan Commelin, Chris Hughes,
Johannes Hölzl, Yury Kudryashov
-/
import Mathlib.Algebra.Group.Defs
import Mathlib.Algebra.Notation.Pi
import Mathlib.Data.FunLike.Basic
import Mathlib.Logic.Function.Iterate
/-!
# Monoid and group homomorphisms
This file defines the bundled structures for monoid and group homomorphisms. Namely, we define
`MonoidHom` (resp., `AddMonoidHom`) to be bundled homomorphisms between multiplicative (resp.,
additive) monoids or groups.
We also define coercion to a function, and usual operations: composition, identity homomorphism,
pointwise multiplication and pointwise inversion.
This file also defines the lesser-used (and notation-less) homomorphism types which are used as
building blocks for other homomorphisms:
* `ZeroHom`
* `OneHom`
* `AddHom`
* `MulHom`
## Notations
* `→+`: Bundled `AddMonoid` homs. Also use for `AddGroup` homs.
* `→*`: Bundled `Monoid` homs. Also use for `Group` homs.
* `→ₙ+`: Bundled `AddSemigroup` homs.
* `→ₙ*`: Bundled `Semigroup` homs.
## Implementation notes
There's a coercion from bundled homs to fun, and the canonical
notation is to use the bundled hom as a function via this coercion.
There is no `GroupHom` -- the idea is that `MonoidHom` is used.
The constructor for `MonoidHom` needs a proof of `map_one` as well
as `map_mul`; a separate constructor `MonoidHom.mk'` will construct
group homs (i.e. monoid homs between groups) given only a proof
that multiplication is preserved,
Implicit `{}` brackets are often used instead of type class `[]` brackets. This is done when the
instances can be inferred because they are implicit arguments to the type `MonoidHom`. When they
can be inferred from the type it is faster to use this method than to use type class inference.
Historically this file also included definitions of unbundled homomorphism classes; they were
deprecated and moved to `Deprecated/Group`.
## Tags
MonoidHom, AddMonoidHom
-/
open Function
variable {ι α β M N P : Type*}
-- monoids
variable {G : Type*} {H : Type*}
-- groups
variable {F : Type*}
-- homs
section Zero
/-- `ZeroHom M N` is the type of functions `M → N` that preserve zero.
When possible, instead of parametrizing results over `(f : ZeroHom M N)`,
you should parametrize over `(F : Type*) [ZeroHomClass F M N] (f : F)`.
When you extend this structure, make sure to also extend `ZeroHomClass`.
-/
structure ZeroHom (M : Type*) (N : Type*) [Zero M] [Zero N] where
/-- The underlying function -/
protected toFun : M → N
/-- The proposition that the function preserves 0 -/
protected map_zero' : toFun 0 = 0
/-- `ZeroHomClass F M N` states that `F` is a type of zero-preserving homomorphisms.
You should extend this typeclass when you extend `ZeroHom`.
-/
class ZeroHomClass (F : Type*) (M N : outParam Type*) [Zero M] [Zero N] [FunLike F M N] :
Prop where
/-- The proposition that the function preserves 0 -/
map_zero : ∀ f : F, f 0 = 0
-- Instances and lemmas are defined below through `@[to_additive]`.
end Zero
section Add
/-- `M →ₙ+ N` is the type of functions `M → N` that preserve addition. The `ₙ` in the notation
stands for "non-unital" because it is intended to match the notation for `NonUnitalAlgHom` and
`NonUnitalRingHom`, so a `AddHom` is a non-unital additive monoid hom.
When possible, instead of parametrizing results over `(f : AddHom M N)`,
you should parametrize over `(F : Type*) [AddHomClass F M N] (f : F)`.
When you extend this structure, make sure to extend `AddHomClass`.
-/
structure AddHom (M : Type*) (N : Type*) [Add M] [Add N] where
/-- The underlying function -/
protected toFun : M → N
/-- The proposition that the function preserves addition -/
protected map_add' : ∀ x y, toFun (x + y) = toFun x + toFun y
/-- `M →ₙ+ N` denotes the type of addition-preserving maps from `M` to `N`. -/
infixr:25 " →ₙ+ " => AddHom
/-- `AddHomClass F M N` states that `F` is a type of addition-preserving homomorphisms.
You should declare an instance of this typeclass when you extend `AddHom`.
-/
class AddHomClass (F : Type*) (M N : outParam Type*) [Add M] [Add N] [FunLike F M N] : Prop where
/-- The proposition that the function preserves addition -/
map_add : ∀ (f : F) (x y : M), f (x + y) = f x + f y
-- Instances and lemmas are defined below through `@[to_additive]`.
end Add
section add_zero
/-- `M →+ N` is the type of functions `M → N` that preserve the `AddZeroClass` structure.
`AddMonoidHom` is also used for group homomorphisms.
When possible, instead of parametrizing results over `(f : M →+ N)`,
you should parametrize over `(F : Type*) [AddMonoidHomClass F M N] (f : F)`.
When you extend this structure, make sure to extend `AddMonoidHomClass`.
-/
structure AddMonoidHom (M : Type*) (N : Type*) [AddZeroClass M] [AddZeroClass N] extends
ZeroHom M N, AddHom M N
attribute [nolint docBlame] AddMonoidHom.toAddHom
attribute [nolint docBlame] AddMonoidHom.toZeroHom
/-- `M →+ N` denotes the type of additive monoid homomorphisms from `M` to `N`. -/
infixr:25 " →+ " => AddMonoidHom
/-- `AddMonoidHomClass F M N` states that `F` is a type of `AddZeroClass`-preserving
homomorphisms.
You should also extend this typeclass when you extend `AddMonoidHom`.
-/
class AddMonoidHomClass (F : Type*) (M N : outParam Type*)
[AddZeroClass M] [AddZeroClass N] [FunLike F M N] : Prop
extends AddHomClass F M N, ZeroHomClass F M N
-- Instances and lemmas are defined below through `@[to_additive]`.
end add_zero
section One
variable [One M] [One N]
/-- `OneHom M N` is the type of functions `M → N` that preserve one.
When possible, instead of parametrizing results over `(f : OneHom M N)`,
you should parametrize over `(F : Type*) [OneHomClass F M N] (f : F)`.
When you extend this structure, make sure to also extend `OneHomClass`.
-/
@[to_additive]
structure OneHom (M : Type*) (N : Type*) [One M] [One N] where
/-- The underlying function -/
protected toFun : M → N
/-- The proposition that the function preserves 1 -/
protected map_one' : toFun 1 = 1
/-- `OneHomClass F M N` states that `F` is a type of one-preserving homomorphisms.
You should extend this typeclass when you extend `OneHom`.
-/
@[to_additive]
class OneHomClass (F : Type*) (M N : outParam Type*) [One M] [One N] [FunLike F M N] : Prop where
/-- The proposition that the function preserves 1 -/
map_one : ∀ f : F, f 1 = 1
@[to_additive]
instance OneHom.funLike : FunLike (OneHom M N) M N where
coe := OneHom.toFun
coe_injective' f g h := by cases f; cases g; congr
@[to_additive]
instance OneHom.oneHomClass : OneHomClass (OneHom M N) M N where
map_one := OneHom.map_one'
library_note "low priority simp lemmas"
/--
The hom class hierarchy allows for a single lemma, such as `map_one`, to apply to a large variety
of morphism types, so long as they have an instance of `OneHomClass`. For example, this applies to
to `MonoidHom`, `RingHom`, `AlgHom`, `StarAlgHom`, as well as their `Equiv` variants, etc. However,
precisely because these lemmas are so widely applicable, they keys in the `simp` discrimination tree
are necessarily highly non-specific. For example, the key for `map_one` is
`@DFunLike.coe _ _ _ _ _ 1`.
Consequently, whenever lean sees `⇑f 1`, for some `f : F`, it will attempt to synthesize a
`OneHomClass F ?A ?B` instance. If no such instance exists, then Lean will need to traverse (almost)
the entirety of the `FunLike` hierarchy in order to determine this because so many classes have a
`OneHomClass` instance (in fact, this problem is likely worse for `ZeroHomClass`). This can lead to
a significant performance hit when `map_one` fails to apply.
To avoid this problem, we mark these widely applicable simp lemmas with key discimination tree keys
with `low` priority in order to ensure that they are not tried first.
-/
variable [FunLike F M N]
/-- See note [low priority simp lemmas] -/
@[to_additive (attr := simp low)]
theorem map_one [OneHomClass F M N] (f : F) : f 1 = 1 :=
OneHomClass.map_one f
@[to_additive] lemma map_comp_one [OneHomClass F M N] (f : F) : f ∘ (1 : ι → M) = 1 := by simp
/-- In principle this could be an instance, but in practice it causes performance issues. -/
@[to_additive]
theorem Subsingleton.of_oneHomClass [Subsingleton M] [OneHomClass F M N] :
Subsingleton F where
allEq f g := DFunLike.ext _ _ fun x ↦ by simp [Subsingleton.elim x 1]
@[to_additive] instance [Subsingleton M] : Subsingleton (OneHom M N) := .of_oneHomClass
@[to_additive]
theorem map_eq_one_iff [OneHomClass F M N] (f : F) (hf : Function.Injective f)
{x : M} :
f x = 1 ↔ x = 1 := hf.eq_iff' (map_one f)
@[to_additive]
theorem map_ne_one_iff {R S F : Type*} [One R] [One S] [FunLike F R S] [OneHomClass F R S] (f : F)
(hf : Function.Injective f) {x : R} : f x ≠ 1 ↔ x ≠ 1 := (map_eq_one_iff f hf).not
@[to_additive]
theorem ne_one_of_map {R S F : Type*} [One R] [One S] [FunLike F R S] [OneHomClass F R S]
{f : F} {x : R} (hx : f x ≠ 1) : x ≠ 1 := ne_of_apply_ne f <| (by rwa [(map_one f)])
/-- Turn an element of a type `F` satisfying `OneHomClass F M N` into an actual
`OneHom`. This is declared as the default coercion from `F` to `OneHom M N`. -/
@[to_additive (attr := coe)
"Turn an element of a type `F` satisfying `ZeroHomClass F M N` into an actual
`ZeroHom`. This is declared as the default coercion from `F` to `ZeroHom M N`."]
def OneHomClass.toOneHom [OneHomClass F M N] (f : F) : OneHom M N where
toFun := f
map_one' := map_one f
/-- Any type satisfying `OneHomClass` can be cast into `OneHom` via `OneHomClass.toOneHom`. -/
@[to_additive "Any type satisfying `ZeroHomClass` can be cast into `ZeroHom` via
`ZeroHomClass.toZeroHom`. "]
instance [OneHomClass F M N] : CoeTC F (OneHom M N) :=
⟨OneHomClass.toOneHom⟩
@[to_additive (attr := simp)]
theorem OneHom.coe_coe [OneHomClass F M N] (f : F) :
((f : OneHom M N) : M → N) = f := rfl
end One
section Mul
variable [Mul M] [Mul N]
/-- `M →ₙ* N` is the type of functions `M → N` that preserve multiplication. The `ₙ` in the notation
stands for "non-unital" because it is intended to match the notation for `NonUnitalAlgHom` and
`NonUnitalRingHom`, so a `MulHom` is a non-unital monoid hom.
When possible, instead of parametrizing results over `(f : M →ₙ* N)`,
you should parametrize over `(F : Type*) [MulHomClass F M N] (f : F)`.
When you extend this structure, make sure to extend `MulHomClass`.
-/
@[to_additive]
structure MulHom (M : Type*) (N : Type*) [Mul M] [Mul N] where
/-- The underlying function -/
protected toFun : M → N
/-- The proposition that the function preserves multiplication -/
protected map_mul' : ∀ x y, toFun (x * y) = toFun x * toFun y
/-- `M →ₙ* N` denotes the type of multiplication-preserving maps from `M` to `N`. -/
infixr:25 " →ₙ* " => MulHom
/-- `MulHomClass F M N` states that `F` is a type of multiplication-preserving homomorphisms.
You should declare an instance of this typeclass when you extend `MulHom`.
-/
@[to_additive]
class MulHomClass (F : Type*) (M N : outParam Type*) [Mul M] [Mul N] [FunLike F M N] : Prop where
/-- The proposition that the function preserves multiplication -/
map_mul : ∀ (f : F) (x y : M), f (x * y) = f x * f y
@[to_additive]
instance MulHom.funLike : FunLike (M →ₙ* N) M N where
coe := MulHom.toFun
coe_injective' f g h := by cases f; cases g; congr
/-- `MulHom` is a type of multiplication-preserving homomorphisms -/
@[to_additive "`AddHom` is a type of addition-preserving homomorphisms"]
instance MulHom.mulHomClass : MulHomClass (M →ₙ* N) M N where
map_mul := MulHom.map_mul'
variable [FunLike F M N]
/-- See note [low priority simp lemmas] -/
@[to_additive (attr := simp low)]
theorem map_mul [MulHomClass F M N] (f : F) (x y : M) : f (x * y) = f x * f y :=
MulHomClass.map_mul f x y
@[to_additive (attr := simp)]
lemma map_comp_mul [MulHomClass F M N] (f : F) (g h : ι → M) : f ∘ (g * h) = f ∘ g * f ∘ h := by
ext; simp
/-- Turn an element of a type `F` satisfying `MulHomClass F M N` into an actual
`MulHom`. This is declared as the default coercion from `F` to `M →ₙ* N`. -/
@[to_additive (attr := coe)
"Turn an element of a type `F` satisfying `AddHomClass F M N` into an actual
`AddHom`. This is declared as the default coercion from `F` to `M →ₙ+ N`."]
def MulHomClass.toMulHom [MulHomClass F M N] (f : F) : M →ₙ* N where
toFun := f
map_mul' := map_mul f
/-- Any type satisfying `MulHomClass` can be cast into `MulHom` via `MulHomClass.toMulHom`. -/
@[to_additive "Any type satisfying `AddHomClass` can be cast into `AddHom` via
`AddHomClass.toAddHom`."]
instance [MulHomClass F M N] : CoeTC F (M →ₙ* N) :=
⟨MulHomClass.toMulHom⟩
@[to_additive (attr := simp)]
theorem MulHom.coe_coe [MulHomClass F M N] (f : F) : ((f : MulHom M N) : M → N) = f := rfl
end Mul
section mul_one
variable [MulOneClass M] [MulOneClass N]
/-- `M →* N` is the type of functions `M → N` that preserve the `Monoid` structure.
`MonoidHom` is also used for group homomorphisms.
When possible, instead of parametrizing results over `(f : M →* N)`,
you should parametrize over `(F : Type*) [MonoidHomClass F M N] (f : F)`.
When you extend this structure, make sure to extend `MonoidHomClass`.
-/
@[to_additive]
structure MonoidHom (M : Type*) (N : Type*) [MulOneClass M] [MulOneClass N] extends
OneHom M N, M →ₙ* N
attribute [nolint docBlame] MonoidHom.toMulHom
attribute [nolint docBlame] MonoidHom.toOneHom
/-- `M →* N` denotes the type of monoid homomorphisms from `M` to `N`. -/
infixr:25 " →* " => MonoidHom
/-- `MonoidHomClass F M N` states that `F` is a type of `Monoid`-preserving homomorphisms.
You should also extend this typeclass when you extend `MonoidHom`. -/
@[to_additive]
class MonoidHomClass (F : Type*) (M N : outParam Type*) [MulOneClass M] [MulOneClass N]
[FunLike F M N] : Prop
extends MulHomClass F M N, OneHomClass F M N
@[to_additive]
instance MonoidHom.instFunLike : FunLike (M →* N) M N where
coe f := f.toFun
coe_injective' f g h := by
cases f
cases g
congr
apply DFunLike.coe_injective'
exact h
@[to_additive]
instance MonoidHom.instMonoidHomClass : MonoidHomClass (M →* N) M N where
map_mul := MonoidHom.map_mul'
map_one f := f.toOneHom.map_one'
@[to_additive] instance [Subsingleton M] : Subsingleton (M →* N) := .of_oneHomClass
variable [FunLike F M N]
/-- Turn an element of a type `F` satisfying `MonoidHomClass F M N` into an actual
`MonoidHom`. This is declared as the default coercion from `F` to `M →* N`. -/
@[to_additive (attr := coe)
"Turn an element of a type `F` satisfying `AddMonoidHomClass F M N` into an
actual `MonoidHom`. This is declared as the default coercion from `F` to `M →+ N`."]
def MonoidHomClass.toMonoidHom [MonoidHomClass F M N] (f : F) : M →* N :=
{ (f : M →ₙ* N), (f : OneHom M N) with }
/-- Any type satisfying `MonoidHomClass` can be cast into `MonoidHom` via
`MonoidHomClass.toMonoidHom`. -/
@[to_additive "Any type satisfying `AddMonoidHomClass` can be cast into `AddMonoidHom` via
`AddMonoidHomClass.toAddMonoidHom`."]
instance [MonoidHomClass F M N] : CoeTC F (M →* N) :=
⟨MonoidHomClass.toMonoidHom⟩
@[to_additive (attr := simp)]
theorem MonoidHom.coe_coe [MonoidHomClass F M N] (f : F) : ((f : M →* N) : M → N) = f := rfl
@[to_additive]
theorem map_mul_eq_one [MonoidHomClass F M N] (f : F) {a b : M} (h : a * b = 1) :
f a * f b = 1 := by
rw [← map_mul, h, map_one]
variable [FunLike F G H]
@[to_additive]
theorem map_div' [DivInvMonoid G] [DivInvMonoid H] [MulHomClass F G H]
(f : F) (hf : ∀ a, f a⁻¹ = (f a)⁻¹) (a b : G) : f (a / b) = f a / f b := by
rw [div_eq_mul_inv, div_eq_mul_inv, map_mul, hf]
@[to_additive]
lemma map_comp_div' [DivInvMonoid G] [DivInvMonoid H] [MulHomClass F G H] (f : F)
(hf : ∀ a, f a⁻¹ = (f a)⁻¹) (g h : ι → G) : f ∘ (g / h) = f ∘ g / f ∘ h := by
ext; simp [map_div' f hf]
/-- Group homomorphisms preserve inverse.
See note [low priority simp lemmas] -/
@[to_additive (attr := simp low) "Additive group homomorphisms preserve negation."]
theorem map_inv [Group G] [DivisionMonoid H] [MonoidHomClass F G H]
(f : F) (a : G) : f a⁻¹ = (f a)⁻¹ :=
eq_inv_of_mul_eq_one_left <| map_mul_eq_one f <| inv_mul_cancel _
@[to_additive (attr := simp)]
lemma map_comp_inv [Group G] [DivisionMonoid H] [MonoidHomClass F G H] (f : F) (g : ι → G) :
f ∘ g⁻¹ = (f ∘ g)⁻¹ := by ext; simp
/-- Group homomorphisms preserve division. -/
@[to_additive "Additive group homomorphisms preserve subtraction."]
theorem map_mul_inv [Group G] [DivisionMonoid H] [MonoidHomClass F G H] (f : F) (a b : G) :
f (a * b⁻¹) = f a * (f b)⁻¹ := by rw [map_mul, map_inv]
@[to_additive]
lemma map_comp_mul_inv [Group G] [DivisionMonoid H] [MonoidHomClass F G H] (f : F) (g h : ι → G) :
f ∘ (g * h⁻¹) = f ∘ g * (f ∘ h)⁻¹ := by simp
/-- Group homomorphisms preserve division.
See note [low priority simp lemmas] -/
@[to_additive (attr := simp low) "Additive group homomorphisms preserve subtraction."]
theorem map_div [Group G] [DivisionMonoid H] [MonoidHomClass F G H] (f : F) :
∀ a b, f (a / b) = f a / f b := map_div' _ <| map_inv f
@[to_additive (attr := simp)]
lemma map_comp_div [Group G] [DivisionMonoid H] [MonoidHomClass F G H] (f : F) (g h : ι → G) :
f ∘ (g / h) = f ∘ g / f ∘ h := by ext; simp
/-- See note [low priority simp lemmas] -/
@[to_additive (attr := simp low) (reorder := 9 10)]
theorem map_pow [Monoid G] [Monoid H] [MonoidHomClass F G H] (f : F) (a : G) :
∀ n : ℕ, f (a ^ n) = f a ^ n
| 0 => by rw [pow_zero, pow_zero, map_one]
| n + 1 => by rw [pow_succ, pow_succ, map_mul, map_pow f a n]
@[to_additive (attr := simp)]
lemma map_comp_pow [Monoid G] [Monoid H] [MonoidHomClass F G H] (f : F) (g : ι → G) (n : ℕ) :
f ∘ (g ^ n) = f ∘ g ^ n := by ext; simp
@[to_additive]
theorem map_zpow' [DivInvMonoid G] [DivInvMonoid H] [MonoidHomClass F G H]
(f : F) (hf : ∀ x : G, f x⁻¹ = (f x)⁻¹) (a : G) : ∀ n : ℤ, f (a ^ n) = f a ^ n
| (n : ℕ) => by rw [zpow_natCast, map_pow, zpow_natCast]
| Int.negSucc n => by rw [zpow_negSucc, hf, map_pow, ← zpow_negSucc]
@[to_additive (attr := simp)]
lemma map_comp_zpow' [DivInvMonoid G] [DivInvMonoid H] [MonoidHomClass F G H] (f : F)
(hf : ∀ x : G, f x⁻¹ = (f x)⁻¹) (g : ι → G) (n : ℤ) : f ∘ (g ^ n) = f ∘ g ^ n := by
ext; simp [map_zpow' f hf]
/-- Group homomorphisms preserve integer power.
See note [low priority simp lemmas] -/
@[to_additive (attr := simp low) (reorder := 9 10)
"Additive group homomorphisms preserve integer scaling."]
theorem map_zpow [Group G] [DivisionMonoid H] [MonoidHomClass F G H]
(f : F) (g : G) (n : ℤ) : f (g ^ n) = f g ^ n := map_zpow' f (map_inv f) g n
@[to_additive]
lemma map_comp_zpow [Group G] [DivisionMonoid H] [MonoidHomClass F G H] (f : F) (g : ι → G)
| (n : ℤ) : f ∘ (g ^ n) = f ∘ g ^ n := by simp
end mul_one
| Mathlib/Algebra/Group/Hom/Defs.lean | 485 | 488 |
/-
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.Nat.Find
import Mathlib.Data.Stream.Init
import Mathlib.Tactic.Common
/-!
# Coinductive formalization of unbounded computations.
This file provides a `Computation` type where `Computation α` is the type of
unbounded computations returning `α`.
-/
open Function
universe u v w
/-
coinductive Computation (α : Type u) : Type u
| pure : α → Computation α
| think : Computation α → Computation α
-/
/-- `Computation α` is the type of unbounded computations returning `α`.
An element of `Computation α` is an infinite sequence of `Option α` such
that if `f n = some a` for some `n` then it is constantly `some a` after that. -/
def Computation (α : Type u) : Type u :=
{ f : Stream' (Option α) // ∀ ⦃n a⦄, f n = some a → f (n + 1) = some a }
namespace Computation
variable {α : Type u} {β : Type v} {γ : Type w}
-- constructors
/-- `pure a` is the computation that immediately terminates with result `a`. -/
def pure (a : α) : Computation α :=
⟨Stream'.const (some a), fun _ _ => id⟩
instance : CoeTC α (Computation α) :=
⟨pure⟩
-- note [use has_coe_t]
/-- `think c` is the computation that delays for one "tick" and then performs
computation `c`. -/
def think (c : Computation α) : Computation α :=
⟨Stream'.cons none c.1, fun n a h => by
rcases n with - | n
· contradiction
· exact c.2 h⟩
/-- `thinkN c n` is the computation that delays for `n` ticks and then performs
computation `c`. -/
def thinkN (c : Computation α) : ℕ → Computation α
| 0 => c
| n + 1 => think (thinkN c n)
-- check for immediate result
/-- `head c` is the first step of computation, either `some a` if `c = pure a`
or `none` if `c = think c'`. -/
def head (c : Computation α) : Option α :=
c.1.head
-- one step of computation
/-- `tail c` is the remainder of computation, either `c` if `c = pure a`
or `c'` if `c = think c'`. -/
def tail (c : Computation α) : Computation α :=
⟨c.1.tail, fun _ _ h => c.2 h⟩
/-- `empty α` is the computation that never returns, an infinite sequence of
`think`s. -/
def empty (α) : Computation α :=
⟨Stream'.const none, fun _ _ => id⟩
instance : Inhabited (Computation α) :=
⟨empty _⟩
/-- `runFor c n` evaluates `c` for `n` steps and returns the result, or `none`
if it did not terminate after `n` steps. -/
def runFor : Computation α → ℕ → Option α :=
Subtype.val
/-- `destruct c` is the destructor for `Computation α` as a coinductive type.
It returns `inl a` if `c = pure a` and `inr c'` if `c = think c'`. -/
def destruct (c : Computation α) : α ⊕ (Computation α) :=
match c.1 0 with
| none => Sum.inr (tail c)
| some a => Sum.inl a
/-- `run c` is an unsound meta function that runs `c` to completion, possibly
resulting in an infinite loop in the VM. -/
unsafe def run : Computation α → α
| c =>
match destruct c with
| Sum.inl a => a
| Sum.inr ca => run ca
theorem destruct_eq_pure {s : Computation α} {a : α} : destruct s = Sum.inl a → s = pure a := by
dsimp [destruct]
induction' f0 : s.1 0 with _ <;> intro h
· contradiction
· apply Subtype.eq
funext n
induction' n with n IH
· injection h with h'
rwa [h'] at f0
· exact s.2 IH
theorem destruct_eq_think {s : Computation α} {s'} : destruct s = Sum.inr s' → s = think s' := by
dsimp [destruct]
induction' f0 : s.1 0 with a' <;> intro h
· injection h with h'
rw [← h']
obtain ⟨f, al⟩ := s
apply Subtype.eq
dsimp [think, tail]
rw [← f0]
exact (Stream'.eta f).symm
· contradiction
@[simp]
theorem destruct_pure (a : α) : destruct (pure a) = Sum.inl a :=
rfl
@[simp]
theorem destruct_think : ∀ s : Computation α, destruct (think s) = Sum.inr s
| ⟨_, _⟩ => rfl
@[simp]
theorem destruct_empty : destruct (empty α) = Sum.inr (empty α) :=
rfl
@[simp]
theorem head_pure (a : α) : head (pure a) = some a :=
rfl
@[simp]
theorem head_think (s : Computation α) : head (think s) = none :=
rfl
@[simp]
theorem head_empty : head (empty α) = none :=
rfl
@[simp]
theorem tail_pure (a : α) : tail (pure a) = pure a :=
rfl
@[simp]
theorem tail_think (s : Computation α) : tail (think s) = s := by
obtain ⟨f, al⟩ := s; apply Subtype.eq; dsimp [tail, think]
@[simp]
theorem tail_empty : tail (empty α) = empty α :=
rfl
theorem think_empty : empty α = think (empty α) :=
destruct_eq_think destruct_empty
/-- Recursion principle for computations, compare with `List.recOn`. -/
def recOn {C : Computation α → Sort v} (s : Computation α) (h1 : ∀ a, C (pure a))
(h2 : ∀ s, C (think s)) : C s :=
match H : destruct s with
| Sum.inl v => by
rw [destruct_eq_pure H]
apply h1
| Sum.inr v => match v with
| ⟨a, s'⟩ => by
rw [destruct_eq_think H]
apply h2
/-- Corecursor constructor for `corec` -/
def Corec.f (f : β → α ⊕ β) : α ⊕ β → Option α × (α ⊕ β)
| Sum.inl a => (some a, Sum.inl a)
| Sum.inr b =>
(match f b with
| Sum.inl a => some a
| Sum.inr _ => none,
f b)
/-- `corec f b` is the corecursor for `Computation α` as a coinductive type.
If `f b = inl a` then `corec f b = pure a`, and if `f b = inl b'` then
`corec f b = think (corec f b')`. -/
def corec (f : β → α ⊕ β) (b : β) : Computation α := by
refine ⟨Stream'.corec' (Corec.f f) (Sum.inr b), fun n a' h => ?_⟩
rw [Stream'.corec'_eq]
change Stream'.corec' (Corec.f f) (Corec.f f (Sum.inr b)).2 n = some a'
revert h; generalize Sum.inr b = o; revert o
induction' n with n IH <;> intro o
· change (Corec.f f o).1 = some a' → (Corec.f f (Corec.f f o).2).1 = some a'
rcases o with _ | b <;> intro h
· exact h
unfold Corec.f at *; split <;> simp_all
· rw [Stream'.corec'_eq (Corec.f f) (Corec.f f o).2, Stream'.corec'_eq (Corec.f f) o]
exact IH (Corec.f f o).2
/-- left map of `⊕` -/
def lmap (f : α → β) : α ⊕ γ → β ⊕ γ
| Sum.inl a => Sum.inl (f a)
| Sum.inr b => Sum.inr b
/-- right map of `⊕` -/
def rmap (f : β → γ) : α ⊕ β → α ⊕ γ
| Sum.inl a => Sum.inl a
| Sum.inr b => Sum.inr (f b)
attribute [simp] lmap rmap
@[simp]
theorem corec_eq (f : β → α ⊕ β) (b : β) : destruct (corec f b) = rmap (corec f) (f b) := by
dsimp [corec, destruct]
rw [show Stream'.corec' (Corec.f f) (Sum.inr b) 0 =
Sum.rec Option.some (fun _ ↦ none) (f b) by
dsimp [Corec.f, Stream'.corec', Stream'.corec, Stream'.map, Stream'.get, Stream'.iterate]
match (f b) with
| Sum.inl x => rfl
| Sum.inr x => rfl
]
induction' h : f b with a b'; · rfl
dsimp [Corec.f, destruct]
apply congr_arg; apply Subtype.eq
dsimp [corec, tail]
rw [Stream'.corec'_eq, Stream'.tail_cons]
dsimp [Corec.f]; rw [h]
section Bisim
variable (R : Computation α → Computation α → Prop)
/-- bisimilarity relation -/
local infixl:50 " ~ " => R
/-- Bisimilarity over a sum of `Computation`s -/
def BisimO : α ⊕ (Computation α) → α ⊕ (Computation α) → Prop
| Sum.inl a, Sum.inl a' => a = a'
| Sum.inr s, Sum.inr s' => R s s'
| _, _ => False
attribute [simp] BisimO
attribute [nolint simpNF] BisimO.eq_3
/-- Attribute expressing bisimilarity over two `Computation`s -/
def IsBisimulation :=
∀ ⦃s₁ s₂⦄, s₁ ~ s₂ → BisimO R (destruct s₁) (destruct s₂)
-- If two computations are bisimilar, then they are equal
theorem eq_of_bisim (bisim : IsBisimulation R) {s₁ s₂} (r : s₁ ~ s₂) : s₁ = s₂ := by
apply Subtype.eq
apply Stream'.eq_of_bisim fun x y => ∃ s s' : Computation α, s.1 = x ∧ s'.1 = y ∧ R s s'
· dsimp [Stream'.IsBisimulation]
intro t₁ t₂ e
match t₁, t₂, e with
| _, _, ⟨s, s', rfl, rfl, r⟩ =>
suffices head s = head s' ∧ R (tail s) (tail s') from
And.imp id (fun r => ⟨tail s, tail s', by cases s; rfl, by cases s'; rfl, r⟩) this
have h := bisim r; revert r h
apply recOn s _ _ <;> intro r' <;> apply recOn s' _ _ <;> intro a' r h
· constructor <;> dsimp at h
· rw [h]
· rw [h] at r
rw [tail_pure, tail_pure,h]
assumption
· rw [destruct_pure, destruct_think] at h
exact False.elim h
· rw [destruct_pure, destruct_think] at h
exact False.elim h
· simp_all
· exact ⟨s₁, s₂, rfl, rfl, r⟩
end Bisim
-- It's more of a stretch to use ∈ for this relation, but it
-- asserts that the computation limits to the given value.
/-- Assertion that a `Computation` limits to a given value -/
protected def Mem (s : Computation α) (a : α) :=
some a ∈ s.1
instance : Membership α (Computation α) :=
⟨Computation.Mem⟩
theorem le_stable (s : Computation α) {a m n} (h : m ≤ n) : s.1 m = some a → s.1 n = some a := by
obtain ⟨f, al⟩ := s
induction' h with n _ IH
exacts [id, fun h2 => al (IH h2)]
theorem mem_unique {s : Computation α} {a b : α} : a ∈ s → b ∈ s → a = b
| ⟨m, ha⟩, ⟨n, hb⟩ => by
injection
(le_stable s (le_max_left m n) ha.symm).symm.trans (le_stable s (le_max_right m n) hb.symm)
theorem Mem.left_unique : Relator.LeftUnique ((· ∈ ·) : α → Computation α → Prop) := fun _ _ _ =>
mem_unique
/-- `Terminates s` asserts that the computation `s` eventually terminates with some value. -/
class Terminates (s : Computation α) : Prop where
/-- assertion that there is some term `a` such that the `Computation` terminates -/
term : ∃ a, a ∈ s
theorem terminates_iff (s : Computation α) : Terminates s ↔ ∃ a, a ∈ s :=
⟨fun h => h.1, Terminates.mk⟩
theorem terminates_of_mem {s : Computation α} {a : α} (h : a ∈ s) : Terminates s :=
⟨⟨a, h⟩⟩
theorem terminates_def (s : Computation α) : Terminates s ↔ ∃ n, (s.1 n).isSome :=
⟨fun ⟨⟨a, n, h⟩⟩ =>
⟨n, by
dsimp [Stream'.get] at h
rw [← h]
exact rfl⟩,
fun ⟨n, h⟩ => ⟨⟨Option.get _ h, n, (Option.eq_some_of_isSome h).symm⟩⟩⟩
theorem ret_mem (a : α) : a ∈ pure a :=
Exists.intro 0 rfl
theorem eq_of_pure_mem {a a' : α} (h : a' ∈ pure a) : a' = a :=
mem_unique h (ret_mem _)
@[simp]
theorem mem_pure_iff (a b : α) : a ∈ pure b ↔ a = b :=
⟨eq_of_pure_mem, fun h => h ▸ ret_mem _⟩
instance ret_terminates (a : α) : Terminates (pure a) :=
terminates_of_mem (ret_mem _)
theorem think_mem {s : Computation α} {a} : a ∈ s → a ∈ think s
| ⟨n, h⟩ => ⟨n + 1, h⟩
instance think_terminates (s : Computation α) : ∀ [Terminates s], Terminates (think s)
| ⟨⟨a, n, h⟩⟩ => ⟨⟨a, n + 1, h⟩⟩
theorem of_think_mem {s : Computation α} {a} : a ∈ think s → a ∈ s
| ⟨n, h⟩ => by
rcases n with - | n'
· contradiction
· exact ⟨n', h⟩
theorem of_think_terminates {s : Computation α} : Terminates (think s) → Terminates s
| ⟨⟨a, h⟩⟩ => ⟨⟨a, of_think_mem h⟩⟩
theorem not_mem_empty (a : α) : a ∉ empty α := fun ⟨n, h⟩ => by contradiction
theorem not_terminates_empty : ¬Terminates (empty α) := fun ⟨⟨a, h⟩⟩ => not_mem_empty a h
theorem eq_empty_of_not_terminates {s} (H : ¬Terminates s) : s = empty α := by
apply Subtype.eq; funext n
induction' h : s.val n with _; · rfl
refine absurd ?_ H; exact ⟨⟨_, _, h.symm⟩⟩
theorem thinkN_mem {s : Computation α} {a} : ∀ n, a ∈ thinkN s n ↔ a ∈ s
| 0 => Iff.rfl
| n + 1 => Iff.trans ⟨of_think_mem, think_mem⟩ (thinkN_mem n)
instance thinkN_terminates (s : Computation α) : ∀ [Terminates s] (n), Terminates (thinkN s n)
| ⟨⟨a, h⟩⟩, n => ⟨⟨a, (thinkN_mem n).2 h⟩⟩
theorem of_thinkN_terminates (s : Computation α) (n) : Terminates (thinkN s n) → Terminates s
| ⟨⟨a, h⟩⟩ => ⟨⟨a, (thinkN_mem _).1 h⟩⟩
/-- `Promises s a`, or `s ~> a`, asserts that although the computation `s`
may not terminate, if it does, then the result is `a`. -/
def Promises (s : Computation α) (a : α) : Prop :=
∀ ⦃a'⦄, a' ∈ s → a = a'
/-- `Promises s a`, or `s ~> a`, asserts that although the computation `s`
may not terminate, if it does, then the result is `a`. -/
scoped infixl:50 " ~> " => Promises
theorem mem_promises {s : Computation α} {a : α} : a ∈ s → s ~> a := fun h _ => mem_unique h
theorem empty_promises (a : α) : empty α ~> a := fun _ h => absurd h (not_mem_empty _)
section get
variable (s : Computation α) [h : Terminates s]
/-- `length s` gets the number of steps of a terminating computation -/
def length : ℕ :=
Nat.find ((terminates_def _).1 h)
/-- `get s` returns the result of a terminating computation -/
def get : α :=
Option.get _ (Nat.find_spec <| (terminates_def _).1 h)
theorem get_mem : get s ∈ s :=
Exists.intro (length s) (Option.eq_some_of_isSome _).symm
theorem get_eq_of_mem {a} : a ∈ s → get s = a :=
mem_unique (get_mem _)
theorem mem_of_get_eq {a} : get s = a → a ∈ s := by intro h; rw [← h]; apply get_mem
@[simp]
theorem get_think : get (think s) = get s :=
get_eq_of_mem _ <|
let ⟨n, h⟩ := get_mem s
⟨n + 1, h⟩
@[simp]
theorem get_thinkN (n) : get (thinkN s n) = get s :=
get_eq_of_mem _ <| (thinkN_mem _).2 (get_mem _)
theorem get_promises : s ~> get s := fun _ => get_eq_of_mem _
theorem mem_of_promises {a} (p : s ~> a) : a ∈ s := by
obtain ⟨h⟩ := h
obtain ⟨a', h⟩ := h
rw [p h]
exact h
theorem get_eq_of_promises {a} : s ~> a → get s = a :=
get_eq_of_mem _ ∘ mem_of_promises _
end get
/-- `Results s a n` completely characterizes a terminating computation:
it asserts that `s` terminates after exactly `n` steps, with result `a`. -/
def Results (s : Computation α) (a : α) (n : ℕ) :=
∃ h : a ∈ s, @length _ s (terminates_of_mem h) = n
theorem results_of_terminates (s : Computation α) [_T : Terminates s] :
Results s (get s) (length s) :=
⟨get_mem _, rfl⟩
theorem results_of_terminates' (s : Computation α) [T : Terminates s] {a} (h : a ∈ s) :
Results s a (length s) := by rw [← get_eq_of_mem _ h]; apply results_of_terminates
theorem Results.mem {s : Computation α} {a n} : Results s a n → a ∈ s
| ⟨m, _⟩ => m
theorem Results.terminates {s : Computation α} {a n} (h : Results s a n) : Terminates s :=
terminates_of_mem h.mem
theorem Results.length {s : Computation α} {a n} [_T : Terminates s] : Results s a n → length s = n
| ⟨_, h⟩ => h
theorem Results.val_unique {s : Computation α} {a b m n} (h1 : Results s a m) (h2 : Results s b n) :
a = b :=
mem_unique h1.mem h2.mem
theorem Results.len_unique {s : Computation α} {a b m n} (h1 : Results s a m) (h2 : Results s b n) :
m = n := by haveI := h1.terminates; haveI := h2.terminates; rw [← h1.length, h2.length]
theorem exists_results_of_mem {s : Computation α} {a} (h : a ∈ s) : ∃ n, Results s a n :=
haveI := terminates_of_mem h
⟨_, results_of_terminates' s h⟩
@[simp]
theorem get_pure (a : α) : get (pure a) = a :=
get_eq_of_mem _ ⟨0, rfl⟩
@[simp]
theorem length_pure (a : α) : length (pure a) = 0 :=
let h := Computation.ret_terminates a
Nat.eq_zero_of_le_zero <| Nat.find_min' ((terminates_def (pure a)).1 h) rfl
theorem results_pure (a : α) : Results (pure a) a 0 :=
⟨ret_mem a, length_pure _⟩
@[simp]
theorem length_think (s : Computation α) [h : Terminates s] : length (think s) = length s + 1 := by
apply le_antisymm
· exact Nat.find_min' _ (Nat.find_spec ((terminates_def _).1 h))
· have : (Option.isSome ((think s).val (length (think s))) : Prop) :=
Nat.find_spec ((terminates_def _).1 s.think_terminates)
revert this; rcases length (think s) with - | n <;> intro this
· simp [think, Stream'.cons] at this
· apply Nat.succ_le_succ
apply Nat.find_min'
apply this
theorem results_think {s : Computation α} {a n} (h : Results s a n) : Results (think s) a (n + 1) :=
haveI := h.terminates
⟨think_mem h.mem, by rw [length_think, h.length]⟩
theorem of_results_think {s : Computation α} {a n} (h : Results (think s) a n) :
∃ m, Results s a m ∧ n = m + 1 := by
haveI := of_think_terminates h.terminates
have := results_of_terminates' _ (of_think_mem h.mem)
exact ⟨_, this, Results.len_unique h (results_think this)⟩
@[simp]
theorem results_think_iff {s : Computation α} {a n} : Results (think s) a (n + 1) ↔ Results s a n :=
⟨fun h => by
let ⟨n', r, e⟩ := of_results_think h
injection e with h'; rwa [h'], results_think⟩
theorem results_thinkN {s : Computation α} {a m} :
∀ n, Results s a m → Results (thinkN s n) a (m + n)
| 0, h => h
| n + 1, h => results_think (results_thinkN n h)
theorem results_thinkN_pure (a : α) (n) : Results (thinkN (pure a) n) a n := by
have := results_thinkN n (results_pure a); rwa [Nat.zero_add] at this
@[simp]
theorem length_thinkN (s : Computation α) [_h : Terminates s] (n) :
length (thinkN s n) = length s + n :=
(results_thinkN n (results_of_terminates _)).length
theorem eq_thinkN {s : Computation α} {a n} (h : Results s a n) : s = thinkN (pure a) n := by
revert s
induction n with | zero => _ | succ n IH => _ <;>
(intro s; apply recOn s (fun a' => _) fun s => _) <;> intro a h
· rw [← eq_of_pure_mem h.mem]
rfl
· obtain ⟨n, h⟩ := of_results_think h
cases h
contradiction
· have := h.len_unique (results_pure _)
contradiction
· rw [IH (results_think_iff.1 h)]
rfl
theorem eq_thinkN' (s : Computation α) [_h : Terminates s] :
s = thinkN (pure (get s)) (length s) :=
eq_thinkN (results_of_terminates _)
/-- Recursor based on membership -/
def memRecOn {C : Computation α → Sort v} {a s} (M : a ∈ s) (h1 : C (pure a))
(h2 : ∀ s, C s → C (think s)) : C s := by
haveI T := terminates_of_mem M
rw [eq_thinkN' s, get_eq_of_mem s M]
generalize length s = n
induction' n with n IH; exacts [h1, h2 _ IH]
/-- Recursor based on assertion of `Terminates` -/
def terminatesRecOn
{C : Computation α → Sort v}
(s) [Terminates s]
(h1 : ∀ a, C (pure a))
(h2 : ∀ s, C s → C (think s)) : C s :=
memRecOn (get_mem s) (h1 _) h2
/-- Map a function on the result of a computation. -/
def map (f : α → β) : Computation α → Computation β
| ⟨s, al⟩ =>
⟨s.map fun o => Option.casesOn o none (some ∘ f), fun n b => by
dsimp [Stream'.map, Stream'.get]
induction' e : s n with a <;> intro h
· contradiction
· rw [al e]; exact h⟩
/-- bind over a `Sum` of `Computation` -/
def Bind.g : β ⊕ Computation β → β ⊕ (Computation α ⊕ Computation β)
| Sum.inl b => Sum.inl b
| Sum.inr cb' => Sum.inr <| Sum.inr cb'
/-- bind over a function mapping `α` to a `Computation` -/
def Bind.f (f : α → Computation β) :
Computation α ⊕ Computation β → β ⊕ (Computation α ⊕ Computation β)
| Sum.inl ca =>
match destruct ca with
| Sum.inl a => Bind.g <| destruct (f a)
| Sum.inr ca' => Sum.inr <| Sum.inl ca'
| Sum.inr cb => Bind.g <| destruct cb
/-- Compose two computations into a monadic `bind` operation. -/
def bind (c : Computation α) (f : α → Computation β) : Computation β :=
corec (Bind.f f) (Sum.inl c)
instance : Bind Computation :=
⟨@bind⟩
theorem has_bind_eq_bind {β} (c : Computation α) (f : α → Computation β) : c >>= f = bind c f :=
rfl
/-- Flatten a computation of computations into a single computation. -/
def join (c : Computation (Computation α)) : Computation α :=
c >>= id
@[simp]
theorem map_pure (f : α → β) (a) : map f (pure a) = pure (f a) :=
rfl
@[simp]
theorem map_think (f : α → β) : ∀ s, map f (think s) = think (map f s)
| ⟨s, al⟩ => by apply Subtype.eq; dsimp [think, map]; rw [Stream'.map_cons]
@[simp]
theorem destruct_map (f : α → β) (s) : destruct (map f s) = lmap f (rmap (map f) (destruct s)) := by
apply s.recOn <;> intro <;> simp
@[simp]
theorem map_id : ∀ s : Computation α, map id s = s
| ⟨f, al⟩ => by
apply Subtype.eq; simp only [map, comp_apply, id_eq]
have e : @Option.rec α (fun _ => Option α) none some = id := by ext ⟨⟩ <;> rfl
have h : ((fun x : Option α => x) = id) := rfl
simp [e, h, Stream'.map_id]
theorem map_comp (f : α → β) (g : β → γ) : ∀ s : Computation α, map (g ∘ f) s = map g (map f s)
| ⟨s, al⟩ => by
apply Subtype.eq; dsimp [map]
apply congr_arg fun f : _ → Option γ => Stream'.map f s
ext ⟨⟩ <;> rfl
@[simp]
theorem ret_bind (a) (f : α → Computation β) : bind (pure a) f = f a := by
apply
eq_of_bisim fun c₁ c₂ => c₁ = bind (pure a) f ∧ c₂ = f a ∨ c₁ = corec (Bind.f f) (Sum.inr c₂)
· intro c₁ c₂ h
match c₁, c₂, h with
| _, _, Or.inl ⟨rfl, rfl⟩ =>
simp only [BisimO, bind, Bind.f, corec_eq, rmap, destruct_pure]
rcases destruct (f a) with b | cb <;> simp [Bind.g]
| _, c, Or.inr rfl =>
simp only [BisimO, Bind.f, corec_eq, rmap]
rcases destruct c with b | cb <;> simp [Bind.g]
· simp
@[simp]
theorem think_bind (c) (f : α → Computation β) : bind (think c) f = think (bind c f) :=
destruct_eq_think <| by simp [bind, Bind.f]
@[simp]
theorem bind_pure (f : α → β) (s) : bind s (pure ∘ f) = map f s := by
apply eq_of_bisim fun c₁ c₂ => c₁ = c₂ ∨ ∃ s, c₁ = bind s (pure ∘ f) ∧ c₂ = map f s
· intro c₁ c₂ h
match c₁, c₂, h with
| _, c₂, Or.inl (Eq.refl _) => rcases destruct c₂ with b | cb <;> simp
| _, _, Or.inr ⟨s, rfl, rfl⟩ =>
apply recOn s <;> intro s
· simp
· simpa using Or.inr ⟨s, rfl, rfl⟩
· exact Or.inr ⟨s, rfl, rfl⟩
@[simp]
theorem bind_pure' (s : Computation α) : bind s pure = s := by
simpa using bind_pure id s
@[simp]
theorem bind_assoc (s : Computation α) (f : α → Computation β) (g : β → Computation γ) :
bind (bind s f) g = bind s fun x : α => bind (f x) g := by
apply
eq_of_bisim fun c₁ c₂ =>
c₁ = c₂ ∨ ∃ s, c₁ = bind (bind s f) g ∧ c₂ = bind s fun x : α => bind (f x) g
· intro c₁ c₂ h
match c₁, c₂, h with
| _, c₂, Or.inl (Eq.refl _) => rcases destruct c₂ with b | cb <;> simp
| _, _, Or.inr ⟨s, rfl, rfl⟩ =>
apply recOn s <;> intro s
· simp only [BisimO, ret_bind]; generalize f s = fs
apply recOn fs <;> intro t <;> simp
· rcases destruct (g t) with b | cb <;> simp
· simpa [BisimO] using Or.inr ⟨s, rfl, rfl⟩
· exact Or.inr ⟨s, rfl, rfl⟩
theorem results_bind {s : Computation α} {f : α → Computation β} {a b m n} (h1 : Results s a m)
(h2 : Results (f a) b n) : Results (bind s f) b (n + m) := by
have := h1.mem; revert m
apply memRecOn this _ fun s IH => _
· intro _ h1
rw [ret_bind]
rw [h1.len_unique (results_pure _)]
exact h2
· intro _ h3 _ h1
rw [think_bind]
obtain ⟨m', h⟩ := of_results_think h1
obtain ⟨h1, e⟩ := h
rw [e]
exact results_think (h3 h1)
theorem mem_bind {s : Computation α} {f : α → Computation β} {a b} (h1 : a ∈ s) (h2 : b ∈ f a) :
b ∈ bind s f :=
let ⟨_, h1⟩ := exists_results_of_mem h1
let ⟨_, h2⟩ := exists_results_of_mem h2
(results_bind h1 h2).mem
instance terminates_bind (s : Computation α) (f : α → Computation β) [Terminates s]
[Terminates (f (get s))] : Terminates (bind s f) :=
terminates_of_mem (mem_bind (get_mem s) (get_mem (f (get s))))
@[simp]
theorem get_bind (s : Computation α) (f : α → Computation β) [Terminates s]
[Terminates (f (get s))] : get (bind s f) = get (f (get s)) :=
get_eq_of_mem _ (mem_bind (get_mem s) (get_mem (f (get s))))
@[simp]
theorem length_bind (s : Computation α) (f : α → Computation β) [_T1 : Terminates s]
[_T2 : Terminates (f (get s))] : length (bind s f) = length (f (get s)) + length s :=
(results_of_terminates _).len_unique <|
results_bind (results_of_terminates _) (results_of_terminates _)
theorem of_results_bind {s : Computation α} {f : α → Computation β} {b k} :
Results (bind s f) b k → ∃ a m n, Results s a m ∧ Results (f a) b n ∧ k = n + m := by
induction k generalizing s with | zero => _ | succ n IH => _
| <;> apply recOn s (fun a => _) fun s' => _ <;> intro e h
· simp only [ret_bind] at h
| Mathlib/Data/Seq/Computation.lean | 689 | 690 |
/-
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,331 | 1,337 | |
/-
Copyright (c) 2022 Yaël Dillies. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies, Peter Nelson
-/
import Mathlib.Order.Antichain
/-!
# Minimality and Maximality
This file proves basic facts about minimality and maximality
of an element with respect to a predicate `P` on an ordered type `α`.
## Implementation Details
This file underwent a refactor from a version where minimality and maximality were defined using
sets rather than predicates, and with an unbundled order relation rather than a `LE` instance.
A side effect is that it has become less straightforward to state that something is minimal
with respect to a relation that is *not* defeq to the default `LE`.
One possible way would be with a type synonym,
and another would be with an ad hoc `LE` instance and `@` notation.
This was not an issue in practice anywhere in mathlib at the time of the refactor,
but it may be worth re-examining this to make it easier in the future; see the TODO below.
## TODO
* In the linearly ordered case, versions of lemmas like `minimal_mem_image` will hold with
`MonotoneOn`/`AntitoneOn` assumptions rather than the stronger `x ≤ y ↔ f x ≤ f y` assumptions.
* `Set.maximal_iff_forall_insert` and `Set.minimal_iff_forall_diff_singleton` will generalize to
lemmas about covering in the case of an `IsStronglyAtomic`/`IsStronglyCoatomic` order.
* `Finset` versions of the lemmas about sets.
* API to allow for easily expressing min/maximality with respect to an arbitrary non-`LE` relation.
* API for `MinimalFor`/`MaximalFor`
-/
assert_not_exists CompleteLattice
open Set OrderDual
variable {α : Type*} {P Q : α → Prop} {a x y : α}
section LE
variable [LE α]
@[simp] theorem minimal_toDual : Minimal (fun x ↦ P (ofDual x)) (toDual x) ↔ Maximal P x :=
Iff.rfl
alias ⟨Minimal.of_dual, Minimal.dual⟩ := minimal_toDual
@[simp] theorem maximal_toDual : Maximal (fun x ↦ P (ofDual x)) (toDual x) ↔ Minimal P x :=
Iff.rfl
alias ⟨Maximal.of_dual, Maximal.dual⟩ := maximal_toDual
@[simp] theorem minimal_false : ¬ Minimal (fun _ ↦ False) x := by
simp [Minimal]
@[simp] theorem maximal_false : ¬ Maximal (fun _ ↦ False) x := by
simp [Maximal]
@[simp] theorem minimal_true : Minimal (fun _ ↦ True) x ↔ IsMin x := by
simp [IsMin, Minimal]
@[simp] theorem maximal_true : Maximal (fun _ ↦ True) x ↔ IsMax x :=
minimal_true (α := αᵒᵈ)
@[simp] theorem minimal_subtype {x : Subtype Q} :
Minimal (fun x ↦ P x.1) x ↔ Minimal (P ⊓ Q) x := by
obtain ⟨x, hx⟩ := x
simp only [Minimal, Subtype.forall, Subtype.mk_le_mk, Pi.inf_apply, inf_Prop_eq]
tauto
@[simp] theorem maximal_subtype {x : Subtype Q} :
Maximal (fun x ↦ P x.1) x ↔ Maximal (P ⊓ Q) x :=
minimal_subtype (α := αᵒᵈ)
theorem maximal_true_subtype {x : Subtype P} : Maximal (fun _ ↦ True) x ↔ Maximal P x := by
obtain ⟨x, hx⟩ := x
simp [Maximal, hx]
theorem minimal_true_subtype {x : Subtype P} : Minimal (fun _ ↦ True) x ↔ Minimal P x := by
obtain ⟨x, hx⟩ := x
simp [Minimal, hx]
@[simp] theorem minimal_minimal : Minimal (Minimal P) x ↔ Minimal P x :=
⟨fun h ↦ h.prop, fun h ↦ ⟨h, fun _ hy hyx ↦ h.le_of_le hy.prop hyx⟩⟩
@[simp] theorem maximal_maximal : Maximal (Maximal P) x ↔ Maximal P x :=
minimal_minimal (α := αᵒᵈ)
/-- If `P` is down-closed, then minimal elements satisfying `P` are exactly the globally minimal
elements satisfying `P`. -/
theorem minimal_iff_isMin (hP : ∀ ⦃x y⦄, P y → x ≤ y → P x) : Minimal P x ↔ P x ∧ IsMin x :=
⟨fun h ↦ ⟨h.prop, fun _ h' ↦ h.le_of_le (hP h.prop h') h'⟩, fun h ↦ ⟨h.1, fun _ _ h' ↦ h.2 h'⟩⟩
/-- If `P` is up-closed, then maximal elements satisfying `P` are exactly the globally maximal
elements satisfying `P`. -/
theorem maximal_iff_isMax (hP : ∀ ⦃x y⦄, P y → y ≤ x → P x) : Maximal P x ↔ P x ∧ IsMax x :=
⟨fun h ↦ ⟨h.prop, fun _ h' ↦ h.le_of_ge (hP h.prop h') h'⟩, fun h ↦ ⟨h.1, fun _ _ h' ↦ h.2 h'⟩⟩
theorem Minimal.mono (h : Minimal P x) (hle : Q ≤ P) (hQ : Q x) : Minimal Q x :=
⟨hQ, fun y hQy ↦ h.le_of_le (hle y hQy)⟩
theorem Maximal.mono (h : Maximal P x) (hle : Q ≤ P) (hQ : Q x) : Maximal Q x :=
⟨hQ, fun y hQy ↦ h.le_of_ge (hle y hQy)⟩
theorem Minimal.and_right (h : Minimal P x) (hQ : Q x) : Minimal (fun x ↦ P x ∧ Q x) x :=
h.mono (fun _ ↦ And.left) ⟨h.prop, hQ⟩
theorem Minimal.and_left (h : Minimal P x) (hQ : Q x) : Minimal (fun x ↦ (Q x ∧ P x)) x :=
h.mono (fun _ ↦ And.right) ⟨hQ, h.prop⟩
theorem Maximal.and_right (h : Maximal P x) (hQ : Q x) : Maximal (fun x ↦ (P x ∧ Q x)) x :=
h.mono (fun _ ↦ And.left) ⟨h.prop, hQ⟩
theorem Maximal.and_left (h : Maximal P x) (hQ : Q x) : Maximal (fun x ↦ (Q x ∧ P x)) x :=
h.mono (fun _ ↦ And.right) ⟨hQ, h.prop⟩
@[simp] theorem minimal_eq_iff : Minimal (· = y) x ↔ x = y := by
simp +contextual [Minimal]
@[simp] theorem maximal_eq_iff : Maximal (· = y) x ↔ x = y := by
simp +contextual [Maximal]
theorem not_minimal_iff (hx : P x) : ¬ Minimal P x ↔ ∃ y, P y ∧ y ≤ x ∧ ¬ (x ≤ y) := by
simp [Minimal, hx]
theorem not_maximal_iff (hx : P x) : ¬ Maximal P x ↔ ∃ y, P y ∧ x ≤ y ∧ ¬ (y ≤ x) :=
not_minimal_iff (α := αᵒᵈ) hx
theorem Minimal.or (h : Minimal (fun x ↦ P x ∨ Q x) x) : Minimal P x ∨ Minimal Q x := by
obtain ⟨h | h, hmin⟩ := h
· exact .inl ⟨h, fun y hy hyx ↦ hmin (Or.inl hy) hyx⟩
exact .inr ⟨h, fun y hy hyx ↦ hmin (Or.inr hy) hyx⟩
theorem Maximal.or (h : Maximal (fun x ↦ P x ∨ Q x) x) : Maximal P x ∨ Maximal Q x :=
Minimal.or (α := αᵒᵈ) h
theorem minimal_and_iff_right_of_imp (hPQ : ∀ ⦃x⦄, P x → Q x) :
Minimal (fun x ↦ P x ∧ Q x) x ↔ (Minimal P x) ∧ Q x := by
simp_rw [and_iff_left_of_imp (fun x ↦ hPQ x), iff_self_and]
exact fun h ↦ hPQ h.prop
theorem minimal_and_iff_left_of_imp (hPQ : ∀ ⦃x⦄, P x → Q x) :
Minimal (fun x ↦ Q x ∧ P x) x ↔ Q x ∧ (Minimal P x) := by
simp_rw [iff_comm, and_comm, minimal_and_iff_right_of_imp hPQ, and_comm]
theorem maximal_and_iff_right_of_imp (hPQ : ∀ ⦃x⦄, P x → Q x) :
Maximal (fun x ↦ P x ∧ Q x) x ↔ (Maximal P x) ∧ Q x :=
minimal_and_iff_right_of_imp (α := αᵒᵈ) hPQ
theorem maximal_and_iff_left_of_imp (hPQ : ∀ ⦃x⦄, P x → Q x) :
Maximal (fun x ↦ Q x ∧ P x) x ↔ Q x ∧ (Maximal P x) :=
minimal_and_iff_left_of_imp (α := αᵒᵈ) hPQ
end LE
section Preorder
variable [Preorder α]
theorem minimal_iff_forall_lt : Minimal P x ↔ P x ∧ ∀ ⦃y⦄, y < x → ¬ P y := by
simp [Minimal, lt_iff_le_not_le, not_imp_not, imp.swap]
theorem maximal_iff_forall_gt : Maximal P x ↔ P x ∧ ∀ ⦃y⦄, x < y → ¬ P y :=
minimal_iff_forall_lt (α := αᵒᵈ)
theorem Minimal.not_prop_of_lt (h : Minimal P x) (hlt : y < x) : ¬ P y :=
(minimal_iff_forall_lt.1 h).2 hlt
theorem Maximal.not_prop_of_gt (h : Maximal P x) (hlt : x < y) : ¬ P y :=
(maximal_iff_forall_gt.1 h).2 hlt
theorem Minimal.not_lt (h : Minimal P x) (hy : P y) : ¬ (y < x) :=
fun hlt ↦ h.not_prop_of_lt hlt hy
theorem Maximal.not_gt (h : Maximal P x) (hy : P y) : ¬ (x < y) :=
fun hlt ↦ h.not_prop_of_gt hlt hy
@[simp] theorem minimal_le_iff : Minimal (· ≤ y) x ↔ x ≤ y ∧ IsMin x :=
minimal_iff_isMin (fun _ _ h h' ↦ h'.trans h)
@[simp] theorem maximal_ge_iff : Maximal (y ≤ ·) x ↔ y ≤ x ∧ IsMax x :=
minimal_le_iff (α := αᵒᵈ)
@[simp] theorem minimal_lt_iff : Minimal (· < y) x ↔ x < y ∧ IsMin x :=
minimal_iff_isMin (fun _ _ h h' ↦ h'.trans_lt h)
@[simp] theorem maximal_gt_iff : Maximal (y < ·) x ↔ y < x ∧ IsMax x :=
minimal_lt_iff (α := αᵒᵈ)
theorem not_minimal_iff_exists_lt (hx : P x) : ¬ Minimal P x ↔ ∃ y, y < x ∧ P y := by
simp_rw [not_minimal_iff hx, lt_iff_le_not_le, and_comm]
alias ⟨exists_lt_of_not_minimal, _⟩ := not_minimal_iff_exists_lt
theorem not_maximal_iff_exists_gt (hx : P x) : ¬ Maximal P x ↔ ∃ y, x < y ∧ P y :=
not_minimal_iff_exists_lt (α := αᵒᵈ) hx
alias ⟨exists_gt_of_not_maximal, _⟩ := not_maximal_iff_exists_gt
end Preorder
section PartialOrder
variable [PartialOrder α]
theorem Minimal.eq_of_ge (hx : Minimal P x) (hy : P y) (hge : y ≤ x) : x = y :=
(hx.2 hy hge).antisymm hge
theorem Minimal.eq_of_le (hx : Minimal P x) (hy : P y) (hle : y ≤ x) : y = x :=
(hx.eq_of_ge hy hle).symm
theorem Maximal.eq_of_le (hx : Maximal P x) (hy : P y) (hle : x ≤ y) : x = y :=
hle.antisymm <| hx.2 hy hle
theorem Maximal.eq_of_ge (hx : Maximal P x) (hy : P y) (hge : x ≤ y) : y = x :=
(hx.eq_of_le hy hge).symm
theorem minimal_iff : Minimal P x ↔ P x ∧ ∀ ⦃y⦄, P y → y ≤ x → x = y :=
⟨fun h ↦ ⟨h.1, fun _ ↦ h.eq_of_ge⟩, fun h ↦ ⟨h.1, fun _ hy hle ↦ (h.2 hy hle).le⟩⟩
theorem maximal_iff : Maximal P x ↔ P x ∧ ∀ ⦃y⦄, P y → x ≤ y → x = y :=
minimal_iff (α := αᵒᵈ)
theorem minimal_mem_iff {s : Set α} : Minimal (· ∈ s) x ↔ x ∈ s ∧ ∀ ⦃y⦄, y ∈ s → y ≤ x → x = y :=
minimal_iff
theorem maximal_mem_iff {s : Set α} : Maximal (· ∈ s) x ↔ x ∈ s ∧ ∀ ⦃y⦄, y ∈ s → x ≤ y → x = y :=
maximal_iff
/-- If `P y` holds, and everything satisfying `P` is above `y`, then `y` is the unique minimal
element satisfying `P`. -/
theorem minimal_iff_eq (hy : P y) (hP : ∀ ⦃x⦄, P x → y ≤ x) : Minimal P x ↔ x = y :=
⟨fun h ↦ h.eq_of_ge hy (hP h.prop), by rintro rfl; exact ⟨hy, fun z hz _ ↦ hP hz⟩⟩
/-- If `P y` holds, and everything satisfying `P` is below `y`, then `y` is the unique maximal
element satisfying `P`. -/
theorem maximal_iff_eq (hy : P y) (hP : ∀ ⦃x⦄, P x → x ≤ y) : Maximal P x ↔ x = y :=
minimal_iff_eq (α := αᵒᵈ) hy hP
@[simp] theorem minimal_ge_iff : Minimal (y ≤ ·) x ↔ x = y :=
minimal_iff_eq rfl.le fun _ ↦ id
@[simp] theorem maximal_le_iff : Maximal (· ≤ y) x ↔ x = y :=
maximal_iff_eq rfl.le fun _ ↦ id
theorem minimal_iff_minimal_of_imp_of_forall (hPQ : ∀ ⦃x⦄, Q x → P x)
(h : ∀ ⦃x⦄, P x → ∃ y, y ≤ x ∧ Q y) : Minimal P x ↔ Minimal Q x := by
refine ⟨fun h' ↦ ⟨?_, fun y hy hyx ↦ h'.le_of_le (hPQ hy) hyx⟩,
fun h' ↦ ⟨hPQ h'.prop, fun y hy hyx ↦ ?_⟩⟩
· obtain ⟨y, hyx, hy⟩ := h h'.prop
rwa [((h'.le_of_le (hPQ hy)) hyx).antisymm hyx]
obtain ⟨z, hzy, hz⟩ := h hy
exact (h'.le_of_le hz (hzy.trans hyx)).trans hzy
theorem maximal_iff_maximal_of_imp_of_forall (hPQ : ∀ ⦃x⦄, Q x → P x)
(h : ∀ ⦃x⦄, P x → ∃ y, x ≤ y ∧ Q y) : Maximal P x ↔ Maximal Q x :=
minimal_iff_minimal_of_imp_of_forall (α := αᵒᵈ) hPQ h
end PartialOrder
section Subset
variable {P : Set α → Prop} {s t : Set α}
theorem Minimal.eq_of_superset (h : Minimal P s) (ht : P t) (hts : t ⊆ s) : s = t :=
h.eq_of_ge ht hts
theorem Maximal.eq_of_subset (h : Maximal P s) (ht : P t) (hst : s ⊆ t) : s = t :=
h.eq_of_le ht hst
theorem Minimal.eq_of_subset (h : Minimal P s) (ht : P t) (hts : t ⊆ s) : t = s :=
h.eq_of_le ht hts
theorem Maximal.eq_of_superset (h : Maximal P s) (ht : P t) (hst : s ⊆ t) : t = s :=
h.eq_of_ge ht hst
theorem minimal_subset_iff : Minimal P s ↔ P s ∧ ∀ ⦃t⦄, P t → t ⊆ s → s = t :=
_root_.minimal_iff
theorem maximal_subset_iff : Maximal P s ↔ P s ∧ ∀ ⦃t⦄, P t → s ⊆ t → s = t :=
_root_.maximal_iff
theorem minimal_subset_iff' : Minimal P s ↔ P s ∧ ∀ ⦃t⦄, P t → t ⊆ s → s ⊆ t :=
Iff.rfl
theorem maximal_subset_iff' : Maximal P s ↔ P s ∧ ∀ ⦃t⦄, P t → s ⊆ t → t ⊆ s :=
Iff.rfl
theorem not_minimal_subset_iff (hs : P s) : ¬ Minimal P s ↔ ∃ t, t ⊂ s ∧ P t :=
not_minimal_iff_exists_lt hs
theorem not_maximal_subset_iff (hs : P s) : ¬ Maximal P s ↔ ∃ t, s ⊂ t ∧ P t :=
not_maximal_iff_exists_gt hs
theorem Set.minimal_iff_forall_ssubset : Minimal P s ↔ P s ∧ ∀ ⦃t⦄, t ⊂ s → ¬ P t :=
minimal_iff_forall_lt
theorem Minimal.not_prop_of_ssubset (h : Minimal P s) (ht : t ⊂ s) : ¬ P t :=
(minimal_iff_forall_lt.1 h).2 ht
theorem Minimal.not_ssubset (h : Minimal P s) (ht : P t) : ¬ t ⊂ s :=
h.not_lt ht
theorem Maximal.mem_of_prop_insert (h : Maximal P s) (hx : P (insert x s)) : x ∈ s :=
h.eq_of_subset hx (subset_insert _ _) ▸ mem_insert ..
theorem Minimal.not_mem_of_prop_diff_singleton (h : Minimal P s) (hx : P (s \ {x})) : x ∉ s :=
fun hxs ↦ ((h.eq_of_superset hx diff_subset).subset hxs).2 rfl
theorem Set.minimal_iff_forall_diff_singleton (hP : ∀ ⦃s t⦄, P t → t ⊆ s → P s) :
Minimal P s ↔ P s ∧ ∀ x ∈ s, ¬ P (s \ {x}) :=
⟨fun h ↦ ⟨h.1, fun _ hx hP ↦ h.not_mem_of_prop_diff_singleton hP hx⟩,
fun h ↦ ⟨h.1, fun _ ht hts x hxs ↦ by_contra fun hxt ↦
h.2 x hxs (hP ht <| subset_diff_singleton hts hxt)⟩⟩
theorem Set.exists_diff_singleton_of_not_minimal (hP : ∀ ⦃s t⦄, P t → t ⊆ s → P s) (hs : P s)
(h : ¬ Minimal P s) : ∃ x ∈ s, P (s \ {x}) := by
simpa [Set.minimal_iff_forall_diff_singleton hP, hs] using h
theorem Set.maximal_iff_forall_ssuperset : Maximal P s ↔ P s ∧ ∀ ⦃t⦄, s ⊂ t → ¬ P t :=
maximal_iff_forall_gt
theorem Maximal.not_prop_of_ssuperset (h : Maximal P s) (ht : s ⊂ t) : ¬ P t :=
(maximal_iff_forall_gt.1 h).2 ht
theorem Maximal.not_ssuperset (h : Maximal P s) (ht : P t) : ¬ s ⊂ t :=
h.not_gt ht
theorem Set.maximal_iff_forall_insert (hP : ∀ ⦃s t⦄, P t → s ⊆ t → P s) :
Maximal P s ↔ P s ∧ ∀ x ∉ s, ¬ P (insert x s) := by
simp only [not_imp_not]
exact ⟨fun h ↦ ⟨h.1, fun x ↦ h.mem_of_prop_insert⟩,
fun h ↦ ⟨h.1, fun t ht hst x hxt ↦ h.2 x (hP ht <| insert_subset hxt hst)⟩⟩
theorem Set.exists_insert_of_not_maximal (hP : ∀ ⦃s t⦄, P t → s ⊆ t → P s) (hs : P s)
(h : ¬ Maximal P s) : ∃ x ∉ s, P (insert x s) := by
simpa [Set.maximal_iff_forall_insert hP, hs] using h
/- TODO : generalize `minimal_iff_forall_diff_singleton` and `maximal_iff_forall_insert`
to `IsStronglyCoatomic`/`IsStronglyAtomic` orders. -/
end Subset
section Set
variable {s t : Set α}
section Preorder
variable [Preorder α]
theorem setOf_minimal_subset (s : Set α) : {x | Minimal (· ∈ s) x} ⊆ s :=
sep_subset ..
theorem setOf_maximal_subset (s : Set α) : {x | Maximal (· ∈ s) x} ⊆ s :=
sep_subset ..
theorem Set.Subsingleton.maximal_mem_iff (h : s.Subsingleton) : Maximal (· ∈ s) x ↔ x ∈ s := by
obtain (rfl | ⟨x, rfl⟩) := h.eq_empty_or_singleton <;> simp
theorem Set.Subsingleton.minimal_mem_iff (h : s.Subsingleton) : Minimal (· ∈ s) x ↔ x ∈ s := by
obtain (rfl | ⟨x, rfl⟩) := h.eq_empty_or_singleton <;> simp
theorem IsLeast.minimal (h : IsLeast s x) : Minimal (· ∈ s) x :=
⟨h.1, fun _b hb _ ↦ h.2 hb⟩
theorem IsGreatest.maximal (h : IsGreatest s x) : Maximal (· ∈ s) x :=
⟨h.1, fun _b hb _ ↦ h.2 hb⟩
theorem IsAntichain.minimal_mem_iff (hs : IsAntichain (· ≤ ·) s) : Minimal (· ∈ s) x ↔ x ∈ s :=
⟨fun h ↦ h.prop, fun h ↦ ⟨h, fun _ hys hyx ↦ (hs.eq hys h hyx).symm.le⟩⟩
theorem IsAntichain.maximal_mem_iff (hs : IsAntichain (· ≤ ·) s) : Maximal (· ∈ s) x ↔ x ∈ s :=
hs.to_dual.minimal_mem_iff
/-- If `t` is an antichain shadowing and including the set of maximal elements of `s`,
then `t` *is* the set of maximal elements of `s`. -/
theorem IsAntichain.eq_setOf_maximal (ht : IsAntichain (· ≤ ·) t)
(h : ∀ x, Maximal (· ∈ s) x → x ∈ t) (hs : ∀ a ∈ t, ∃ b, b ≤ a ∧ Maximal (· ∈ s) b) :
{x | Maximal (· ∈ s) x} = t := by
refine Set.ext fun x ↦ ⟨h _, fun hx ↦ ?_⟩
obtain ⟨y, hyx, hy⟩ := hs x hx
rwa [← ht.eq (h y hy) hx hyx]
/-- If `t` is an antichain shadowed by and including the set of minimal elements of `s`,
then `t` *is* the set of minimal elements of `s`. -/
theorem IsAntichain.eq_setOf_minimal (ht : IsAntichain (· ≤ ·) t)
(h : ∀ x, Minimal (· ∈ s) x → x ∈ t) (hs : ∀ a ∈ t, ∃ b, a ≤ b ∧ Minimal (· ∈ s) b) :
{x | Minimal (· ∈ s) x} = t :=
ht.to_dual.eq_setOf_maximal h hs
end Preorder
section PartialOrder
variable [PartialOrder α]
theorem setOf_maximal_antichain (P : α → Prop) : IsAntichain (· ≤ ·) {x | Maximal P x} :=
fun _ hx _ ⟨hy, _⟩ hne hle ↦ hne (hle.antisymm <| hx.2 hy hle)
theorem setOf_minimal_antichain (P : α → Prop) : IsAntichain (· ≤ ·) {x | Minimal P x} :=
(setOf_maximal_antichain (α := αᵒᵈ) P).swap
theorem IsLeast.minimal_iff (h : IsLeast s a) : Minimal (· ∈ s) x ↔ x = a :=
⟨fun h' ↦ h'.eq_of_ge h.1 (h.2 h'.prop), fun h' ↦ h' ▸ h.minimal⟩
theorem IsGreatest.maximal_iff (h : IsGreatest s a) : Maximal (· ∈ s) x ↔ x = a :=
⟨fun h' ↦ h'.eq_of_le h.1 (h.2 h'.prop), fun h' ↦ h' ▸ h.maximal⟩
end PartialOrder
end Set
section Image
variable [Preorder α] {β : Type*} [Preorder β] {s : Set α} {t : Set β}
section Function
variable {f : α → β}
theorem minimal_mem_image_monotone (hf : ∀ ⦃x y⦄, x ∈ s → y ∈ s → (f x ≤ f y ↔ x ≤ y))
(hx : Minimal (· ∈ s) x) : Minimal (· ∈ f '' s) (f x) := by
refine ⟨mem_image_of_mem f hx.prop, ?_⟩
rintro _ ⟨y, hy, rfl⟩
rw [hf hx.prop hy, hf hy hx.prop]
exact hx.le_of_le hy
theorem maximal_mem_image_monotone (hf : ∀ ⦃x y⦄, x ∈ s → y ∈ s → (f x ≤ f y ↔ x ≤ y))
(hx : Maximal (· ∈ s) x) : Maximal (· ∈ f '' s) (f x) :=
minimal_mem_image_monotone (α := αᵒᵈ) (β := βᵒᵈ) (s := s) (fun _ _ hx hy ↦ hf hy hx) hx
theorem minimal_mem_image_monotone_iff (ha : a ∈ s)
(hf : ∀ ⦃x y⦄, x ∈ s → y ∈ s → (f x ≤ f y ↔ x ≤ y)) :
| Minimal (· ∈ f '' s) (f a) ↔ Minimal (· ∈ s) a := by
refine ⟨fun h ↦ ⟨ha, fun y hys ↦ ?_⟩, minimal_mem_image_monotone hf⟩
rw [← hf ha hys, ← hf hys ha]
exact h.le_of_le (mem_image_of_mem f hys)
| Mathlib/Order/Minimal.lean | 440 | 444 |
/-
Copyright (c) 2020 Jalex Stark. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jalex Stark, Kim Morrison, Eric Wieser, Oliver Nash, Wen Yang
-/
import Mathlib.Data.Matrix.Basic
/-!
# Matrices with a single non-zero element.
This file provides `Matrix.stdBasisMatrix`. The matrix `Matrix.stdBasisMatrix i j c` has `c`
at position `(i, j)`, and zeroes elsewhere.
-/
assert_not_exists Matrix.trace
variable {l m n o : Type*}
variable {R α β : Type*}
namespace Matrix
variable [DecidableEq l] [DecidableEq m] [DecidableEq n] [DecidableEq o]
section Zero
variable [Zero α]
/-- `stdBasisMatrix i j a` is the matrix with `a` in the `i`-th row, `j`-th column,
and zeroes elsewhere.
-/
def stdBasisMatrix (i : m) (j : n) (a : α) : Matrix m n α :=
of <| fun i' j' => if i = i' ∧ j = j' then a else 0
theorem stdBasisMatrix_eq_of_single_single (i : m) (j : n) (a : α) :
stdBasisMatrix i j a = Matrix.of (Pi.single i (Pi.single j a)) := by
ext a b
unfold stdBasisMatrix
by_cases hi : i = a <;> by_cases hj : j = b <;> simp [*]
@[simp]
theorem of_symm_stdBasisMatrix (i : m) (j : n) (a : α) :
of.symm (stdBasisMatrix i j a) = Pi.single i (Pi.single j a) :=
congr_arg of.symm <| stdBasisMatrix_eq_of_single_single i j a
@[simp]
theorem smul_stdBasisMatrix [SMulZeroClass R α] (r : R) (i : m) (j : n) (a : α) :
r • stdBasisMatrix i j a = stdBasisMatrix i j (r • a) := by
unfold stdBasisMatrix
ext
simp [smul_ite]
@[simp]
theorem stdBasisMatrix_zero (i : m) (j : n) : stdBasisMatrix i j (0 : α) = 0 := by
unfold stdBasisMatrix
ext
simp
@[simp]
lemma transpose_stdBasisMatrix (i : m) (j : n) (a : α) :
(stdBasisMatrix i j a)ᵀ = stdBasisMatrix j i a := by
aesop (add unsafe unfold stdBasisMatrix)
@[simp]
lemma map_stdBasisMatrix (i : m) (j : n) (a : α) {β : Type*} [Zero β]
{F : Type*} [FunLike F α β] [ZeroHomClass F α β] (f : F) :
(stdBasisMatrix i j a).map f = stdBasisMatrix i j (f a) := by
aesop (add unsafe unfold stdBasisMatrix)
end Zero
theorem stdBasisMatrix_add [AddZeroClass α] (i : m) (j : n) (a b : α) :
stdBasisMatrix i j (a + b) = stdBasisMatrix i j a + stdBasisMatrix i j b := by
ext
simp only [stdBasisMatrix, of_apply]
split_ifs with h <;> simp [h]
theorem mulVec_stdBasisMatrix [NonUnitalNonAssocSemiring α] [Fintype m]
(i : n) (j : m) (c : α) (x : m → α) :
mulVec (stdBasisMatrix i j c) x = Function.update (0 : n → α) i (c * x j) := by
ext i'
simp [stdBasisMatrix, mulVec, dotProduct]
rcases eq_or_ne i i' with rfl|h
· simp
simp [h, h.symm]
theorem matrix_eq_sum_stdBasisMatrix [AddCommMonoid α] [Fintype m] [Fintype n] (x : Matrix m n α) :
x = ∑ i : m, ∑ j : n, stdBasisMatrix i j (x i j) := by
ext i j
rw [← Fintype.sum_prod_type']
simp [stdBasisMatrix, Matrix.sum_apply, Matrix.of_apply, ← Prod.mk_inj]
theorem stdBasisMatrix_eq_single_vecMulVec_single [MulZeroOneClass α] (i : m) (j : n) :
stdBasisMatrix i j (1 : α) = vecMulVec (Pi.single i 1) (Pi.single j 1) := by
ext i' j'
simp [-mul_ite, stdBasisMatrix, vecMulVec, ite_and, Pi.single_apply, eq_comm]
-- todo: the old proof used fintypes, I don't know `Finsupp` but this feels generalizable
@[elab_as_elim]
protected theorem induction_on'
[AddCommMonoid α] [Finite m] [Finite n] {P : Matrix m n α → Prop} (M : Matrix m n α)
(h_zero : P 0) (h_add : ∀ p q, P p → P q → P (p + q))
(h_std_basis : ∀ (i : m) (j : n) (x : α), P (stdBasisMatrix i j x)) : P M := by
cases nonempty_fintype m; cases nonempty_fintype n
rw [matrix_eq_sum_stdBasisMatrix M, ← Finset.sum_product']
apply Finset.sum_induction _ _ h_add h_zero
· intros
apply h_std_basis
@[elab_as_elim]
protected theorem induction_on
[AddCommMonoid α] [Finite m] [Finite n] [Nonempty m] [Nonempty n]
{P : Matrix m n α → Prop} (M : Matrix m n α) (h_add : ∀ p q, P p → P q → P (p + q))
(h_std_basis : ∀ i j x, P (stdBasisMatrix i j x)) : P M :=
Matrix.induction_on' M
(by
inhabit m
inhabit n
simpa using h_std_basis default default 0)
h_add h_std_basis
/-- `Matrix.stdBasisMatrix` as a bundled additive map. -/
@[simps]
def stdBasisMatrixAddMonoidHom [AddCommMonoid α] (i : m) (j : n) : α →+ Matrix m n α where
toFun := stdBasisMatrix i j
map_zero' := stdBasisMatrix_zero _ _
map_add' _ _ := stdBasisMatrix_add _ _ _ _
variable (R)
/-- `Matrix.stdBasisMatrix` as a bundled linear map. -/
@[simps!]
def stdBasisMatrixLinearMap [Semiring R] [AddCommMonoid α] [Module R α] (i : m) (j : n) :
α →ₗ[R] Matrix m n α where
__ := stdBasisMatrixAddMonoidHom i j
map_smul' _ _:= smul_stdBasisMatrix _ _ _ _ |>.symm
section ext
/-- Additive maps from finite matrices are equal if they agree on the standard basis.
See note [partially-applied ext lemmas]. -/
@[local ext]
theorem ext_addMonoidHom
[Finite m] [Finite n] [AddCommMonoid α] [AddCommMonoid β] ⦃f g : Matrix m n α →+ β⦄
(h : ∀ i j, f.comp (stdBasisMatrixAddMonoidHom i j) = g.comp (stdBasisMatrixAddMonoidHom i j)) :
f = g := by
cases nonempty_fintype m
cases nonempty_fintype n
ext x
rw [matrix_eq_sum_stdBasisMatrix x]
simp_rw [map_sum]
congr! 2
exact DFunLike.congr_fun (h _ _) _
/-- Linear maps from finite matrices are equal if they agree on the standard basis.
See note [partially-applied ext lemmas]. -/
@[local ext]
theorem ext_linearMap
[Finite m] [Finite n] [Semiring R] [AddCommMonoid α] [AddCommMonoid β] [Module R α] [Module R β]
⦃f g : Matrix m n α →ₗ[R] β⦄
| (h : ∀ i j, f ∘ₗ stdBasisMatrixLinearMap R i j = g ∘ₗ stdBasisMatrixLinearMap R i j) :
f = g :=
LinearMap.toAddMonoidHom_injective <| ext_addMonoidHom fun i j =>
| Mathlib/Data/Matrix/Basis.lean | 160 | 162 |
/-
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.Algebra.Polynomial.Eval.Defs
import Mathlib.LinearAlgebra.Dimension.Constructions
/-!
# Linear recurrence
Informally, a "linear recurrence" is an assertion of the form
`∀ n : ℕ, u (n + d) = a 0 * u n + a 1 * u (n+1) + ... + a (d-1) * u (n+d-1)`,
where `u` is a sequence, `d` is the *order* of the recurrence and the `a i`
are its *coefficients*.
In this file, we define the structure `LinearRecurrence` so that
`LinearRecurrence.mk d a` represents the above relation, and we call
a sequence `u` which verifies it a *solution* of the linear recurrence.
We prove a few basic lemmas about this concept, such as :
* the space of solutions is a submodule of `(ℕ → α)` (i.e a vector space if `α`
is a field)
* the function that maps a solution `u` to its first `d` terms builds a `LinearEquiv`
between the solution space and `Fin d → α`, aka `α ^ d`. As a consequence, two
solutions are equal if and only if their first `d` terms are equals.
* a geometric sequence `q ^ n` is solution iff `q` is a root of a particular polynomial,
which we call the *characteristic polynomial* of the recurrence
Of course, although we can inductively generate solutions (cf `mkSol`), the
interesting part would be to determinate closed-forms for the solutions.
This is currently *not implemented*, as we are waiting for definition and
properties of eigenvalues and eigenvectors.
-/
noncomputable section
open Finset
open Polynomial
/-- A "linear recurrence relation" over a commutative semiring is given by its
order `n` and `n` coefficients. -/
structure LinearRecurrence (R : Type*) [CommSemiring R] where
/-- Order of the linear recurrence -/
order : ℕ
/-- Coefficients of the linear recurrence -/
coeffs : Fin order → R
instance (R : Type*) [CommSemiring R] : Inhabited (LinearRecurrence R) :=
⟨⟨0, default⟩⟩
namespace LinearRecurrence
section CommSemiring
variable {R : Type*} [CommSemiring R] (E : LinearRecurrence R)
/-- We say that a sequence `u` is solution of `LinearRecurrence order coeffs` when we have
`u (n + order) = ∑ i : Fin order, coeffs i * u (n + i)` for any `n`. -/
def IsSolution (u : ℕ → R) :=
∀ n, u (n + E.order) = ∑ i, E.coeffs i * u (n + i)
/-- A solution of a `LinearRecurrence` which satisfies certain initial conditions.
We will prove this is the only such solution. -/
def mkSol (init : Fin E.order → R) : ℕ → R
| n =>
if h : n < E.order then init ⟨n, h⟩
else
∑ k : Fin E.order,
have _ : n - E.order + k < n := by omega
E.coeffs k * mkSol init (n - E.order + k)
/-- `E.mkSol` indeed gives solutions to `E`. -/
theorem is_sol_mkSol (init : Fin E.order → R) : E.IsSolution (E.mkSol init) := by
intro n
rw [mkSol]
simp
/-- `E.mkSol init`'s first `E.order` terms are `init`. -/
theorem mkSol_eq_init (init : Fin E.order → R) : ∀ n : Fin E.order, E.mkSol init n = init n := by
intro n
rw [mkSol]
simp only [n.is_lt, dif_pos, Fin.mk_val, Fin.eta]
/-- If `u` is a solution to `E` and `init` designates its first `E.order` values,
then `∀ n, u n = E.mkSol init n`. -/
theorem eq_mk_of_is_sol_of_eq_init {u : ℕ → R} {init : Fin E.order → R} (h : E.IsSolution u)
| (heq : ∀ n : Fin E.order, u n = init n) : ∀ n, u n = E.mkSol init n := by
intro n
rw [mkSol]
split_ifs with h'
| Mathlib/Algebra/LinearRecurrence.lean | 92 | 95 |
/-
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.Group.Nat.Defs
import Mathlib.CategoryTheory.Category.Preorder
import Mathlib.CategoryTheory.EqToHom
import Mathlib.CategoryTheory.Functor.Const
import Mathlib.Order.Fin.Basic
import Mathlib.Tactic.FinCases
import Mathlib.Tactic.SuppressCompilation
/-!
# Composable arrows
If `C` is a category, the type of `n`-simplices in the nerve of `C` identifies
to the type of functors `Fin (n + 1) ⥤ C`, which can be thought as families of `n` composable
arrows in `C`. In this file, we introduce and study this category `ComposableArrows C n`
of `n` composable arrows in `C`.
If `F : ComposableArrows C n`, we define `F.left` as the leftmost object, `F.right` as the
rightmost object, and `F.hom : F.left ⟶ F.right` is the canonical map.
The most significant definition in this file is the constructor
`F.precomp f : ComposableArrows C (n + 1)` for `F : ComposableArrows C n` and `f : X ⟶ F.left`:
"it shifts `F` towards the right and inserts `f` on the left". This `precomp` has
good definitional properties.
In the namespace `CategoryTheory.ComposableArrows`, we provide constructors
like `mk₁ f`, `mk₂ f g`, `mk₃ f g h` for `ComposableArrows C n` for small `n`.
TODO (@joelriou):
* redefine `Arrow C` as `ComposableArrow C 1`?
* construct some elements in `ComposableArrows m (Fin (n + 1))` for small `n`
the precomposition with which shall induce functors
`ComposableArrows C n ⥤ ComposableArrows C m` which correspond to simplicial operations
(specifically faces) with good definitional properties (this might be necessary for
up to `n = 7` in order to formalize spectral sequences following Verdier)
-/
/-!
New `simprocs` that run even in `dsimp` have caused breakages in this file.
(e.g. `dsimp` can now simplify `2 + 3` to `5`)
For now, we just turn off simprocs in this file.
We'll soon provide finer grained options here, e.g. to turn off simprocs only in `dsimp`, etc.
*However*, hopefully it is possible to refactor the material here so that no backwards compatibility
`set_option`s are required at all
-/
set_option simprocs false
namespace CategoryTheory
open Category
variable (C : Type*) [Category C]
/-- `ComposableArrows C n` is the type of functors `Fin (n + 1) ⥤ C`. -/
abbrev ComposableArrows (n : ℕ) := Fin (n + 1) ⥤ C
namespace ComposableArrows
variable {C} {n m : ℕ}
variable (F G : ComposableArrows C n)
/-- A wrapper for `omega` which prefaces it with some quick and useful attempts -/
macro "valid" : tactic =>
`(tactic| first | assumption | apply zero_le | apply le_rfl | transitivity <;> assumption | omega)
/-- The `i`th object (with `i : ℕ` such that `i ≤ n`) of `F : ComposableArrows C n`. -/
@[simp]
abbrev obj' (i : ℕ) (hi : i ≤ n := by valid) : C := F.obj ⟨i, by omega⟩
/-- The map `F.obj' i ⟶ F.obj' j` when `F : ComposableArrows C n`, and `i` and `j`
are natural numbers such that `i ≤ j ≤ n`. -/
@[simp]
abbrev map' (i j : ℕ) (hij : i ≤ j := by valid) (hjn : j ≤ n := by valid) :
F.obj ⟨i, by omega⟩ ⟶ F.obj ⟨j, by omega⟩ := F.map (homOfLE (by
simp only [Fin.mk_le_mk]
valid))
lemma map'_self (i : ℕ) (hi : i ≤ n := by valid) :
F.map' i i = 𝟙 _ := F.map_id _
lemma map'_comp (i j k : ℕ) (hij : i ≤ j := by valid)
(hjk : j ≤ k := by valid) (hk : k ≤ n := by valid) :
F.map' i k = F.map' i j ≫ F.map' j k :=
F.map_comp _ _
/-- The leftmost object of `F : ComposableArrows C n`. -/
abbrev left := obj' F 0
/-- The rightmost object of `F : ComposableArrows C n`. -/
abbrev right := obj' F n
/-- The canonical map `F.left ⟶ F.right` for `F : ComposableArrows C n`. -/
abbrev hom : F.left ⟶ F.right := map' F 0 n
variable {F G}
/-- The map `F.obj' i ⟶ G.obj' i` induced on `i`th objects by a morphism `F ⟶ G`
in `ComposableArrows C n` when `i` is a natural number such that `i ≤ n`. -/
@[simp]
abbrev app' (φ : F ⟶ G) (i : ℕ) (hi : i ≤ n := by valid) :
F.obj' i ⟶ G.obj' i := φ.app _
@[reassoc]
lemma naturality' (φ : F ⟶ G) (i j : ℕ) (hij : i ≤ j := by valid)
(hj : j ≤ n := by valid) :
F.map' i j ≫ app' φ j = app' φ i ≫ G.map' i j :=
φ.naturality _
/-- Constructor for `ComposableArrows C 0`. -/
@[simps!]
def mk₀ (X : C) : ComposableArrows C 0 := (Functor.const (Fin 1)).obj X
namespace Mk₁
variable (X₀ X₁ : C)
/-- The map which sends `0 : Fin 2` to `X₀` and `1` to `X₁`. -/
@[simp]
def obj : Fin 2 → C
| ⟨0, _⟩ => X₀
| ⟨1, _⟩ => X₁
variable {X₀ X₁}
variable (f : X₀ ⟶ X₁)
/-- The obvious map `obj X₀ X₁ i ⟶ obj X₀ X₁ j` whenever `i j : Fin 2` satisfy `i ≤ j`. -/
@[simp]
def map : ∀ (i j : Fin 2) (_ : i ≤ j), obj X₀ X₁ i ⟶ obj X₀ X₁ j
| ⟨0, _⟩, ⟨0, _⟩, _ => 𝟙 _
| ⟨0, _⟩, ⟨1, _⟩, _ => f
| ⟨1, _⟩, ⟨1, _⟩, _ => 𝟙 _
lemma map_id (i : Fin 2) : map f i i (by simp) = 𝟙 _ :=
match i with
| 0 => rfl
| 1 => rfl
lemma map_comp {i j k : Fin 2} (hij : i ≤ j) (hjk : j ≤ k) :
map f i k (hij.trans hjk) = map f i j hij ≫ map f j k hjk := by
obtain rfl | rfl : i = j ∨ j = k := by omega
· rw [map_id, id_comp]
· rw [map_id, comp_id]
end Mk₁
/-- Constructor for `ComposableArrows C 1`. -/
@[simps]
def mk₁ {X₀ X₁ : C} (f : X₀ ⟶ X₁) : ComposableArrows C 1 where
obj := Mk₁.obj X₀ X₁
map g := Mk₁.map f _ _ (leOfHom g)
map_id := Mk₁.map_id f
map_comp g g' := Mk₁.map_comp f (leOfHom g) (leOfHom g')
/-- Constructor for morphisms `F ⟶ G` in `ComposableArrows C n` which takes as inputs
a family of morphisms `F.obj i ⟶ G.obj i` and the naturality condition only for the
maps in `Fin (n + 1)` given by inequalities of the form `i ≤ i + 1`. -/
@[simps]
def homMk {F G : ComposableArrows C n} (app : ∀ i, F.obj i ⟶ G.obj i)
(w : ∀ (i : ℕ) (hi : i < n), F.map' i (i + 1) ≫ app _ = app _ ≫ G.map' i (i + 1)) :
F ⟶ G where
app := app
naturality := by
suffices ∀ (k i j : ℕ) (hj : i + k = j) (hj' : j ≤ n),
F.map' i j ≫ app _ = app _ ≫ G.map' i j by
rintro ⟨i, hi⟩ ⟨j, hj⟩ hij
have hij' := leOfHom hij
simp only [Fin.mk_le_mk] at hij'
obtain ⟨k, hk⟩ := Nat.le.dest hij'
exact this k i j hk (by valid)
intro k
induction' k with k hk
· intro i j hj hj'
simp only [add_zero] at hj
obtain rfl := hj
rw [F.map'_self i, G.map'_self i, id_comp, comp_id]
· intro i j hj hj'
rw [← add_assoc] at hj
subst hj
rw [F.map'_comp i (i + k) (i + k + 1), G.map'_comp i (i + k) (i + k + 1), assoc,
w (i + k) (by valid), reassoc_of% (hk i (i + k) rfl (by valid))]
/-- Constructor for isomorphisms `F ≅ G` in `ComposableArrows C n` which takes as inputs
a family of isomorphisms `F.obj i ≅ G.obj i` and the naturality condition only for the
maps in `Fin (n + 1)` given by inequalities of the form `i ≤ i + 1`. -/
@[simps]
def isoMk {F G : ComposableArrows C n} (app : ∀ i, F.obj i ≅ G.obj i)
(w : ∀ (i : ℕ) (hi : i < n),
F.map' i (i + 1) ≫ (app _).hom = (app _).hom ≫ G.map' i (i + 1)) :
F ≅ G where
hom := homMk (fun i => (app i).hom) w
inv := homMk (fun i => (app i).inv) (fun i hi => by
dsimp only
rw [← cancel_epi ((app _).hom), ← reassoc_of% (w i hi), Iso.hom_inv_id, comp_id,
Iso.hom_inv_id_assoc])
lemma ext {F G : ComposableArrows C n} (h : ∀ i, F.obj i = G.obj i)
(w : ∀ (i : ℕ) (hi : i < n), F.map' i (i + 1) =
eqToHom (h _) ≫ G.map' i (i + 1) ≫ eqToHom (h _).symm) : F = G :=
Functor.ext_of_iso
(isoMk (fun i => eqToIso (h i)) (fun i hi => by simp [w i hi])) h (fun _ => rfl)
/-- Constructor for morphisms in `ComposableArrows C 0`. -/
@[simps!]
def homMk₀ {F G : ComposableArrows C 0} (f : F.obj' 0 ⟶ G.obj' 0) : F ⟶ G :=
homMk (fun i => match i with
| ⟨0, _⟩ => f) (fun i hi => by simp at hi)
@[ext]
lemma hom_ext₀ {F G : ComposableArrows C 0} {φ φ' : F ⟶ G}
(h : app' φ 0 = app' φ' 0) :
φ = φ' := by
ext i
fin_cases i
exact h
/-- Constructor for isomorphisms in `ComposableArrows C 0`. -/
@[simps!]
def isoMk₀ {F G : ComposableArrows C 0} (e : F.obj' 0 ≅ G.obj' 0) : F ≅ G where
hom := homMk₀ e.hom
inv := homMk₀ e.inv
lemma ext₀ {F G : ComposableArrows C 0} (h : F.obj' 0 = G.obj 0) : F = G :=
ext (fun i => match i with
| ⟨0, _⟩ => h) (fun i hi => by simp at hi)
lemma mk₀_surjective (F : ComposableArrows C 0) : ∃ (X : C), F = mk₀ X :=
⟨F.obj' 0, ext₀ rfl⟩
/-- Constructor for morphisms in `ComposableArrows C 1`. -/
@[simps!]
def homMk₁ {F G : ComposableArrows C 1}
(left : F.obj' 0 ⟶ G.obj' 0) (right : F.obj' 1 ⟶ G.obj' 1)
(w : F.map' 0 1 ≫ right = left ≫ G.map' 0 1 := by aesop_cat) :
F ⟶ G :=
homMk (fun i => match i with
| ⟨0, _⟩ => left
| ⟨1, _⟩ => right) (by
intro i hi
obtain rfl : i = 0 := by simpa using hi
exact w)
@[ext]
lemma hom_ext₁ {F G : ComposableArrows C 1} {φ φ' : F ⟶ G}
(h₀ : app' φ 0 = app' φ' 0) (h₁ : app' φ 1 = app' φ' 1) :
φ = φ' := by
ext i
match i with
| 0 => exact h₀
| 1 => exact h₁
/-- Constructor for isomorphisms in `ComposableArrows C 1`. -/
@[simps!]
def isoMk₁ {F G : ComposableArrows C 1}
(left : F.obj' 0 ≅ G.obj' 0) (right : F.obj' 1 ≅ G.obj' 1)
(w : F.map' 0 1 ≫ right.hom = left.hom ≫ G.map' 0 1 := by aesop_cat) :
F ≅ G where
hom := homMk₁ left.hom right.hom w
inv := homMk₁ left.inv right.inv (by
rw [← cancel_mono right.hom, assoc, assoc, w, right.inv_hom_id, left.inv_hom_id_assoc]
apply comp_id)
lemma map'_eq_hom₁ (F : ComposableArrows C 1) : F.map' 0 1 = F.hom := rfl
lemma ext₁ {F G : ComposableArrows C 1}
(left : F.left = G.left) (right : F.right = G.right)
(w : F.hom = eqToHom left ≫ G.hom ≫ eqToHom right.symm) : F = G :=
Functor.ext_of_iso (isoMk₁ (eqToIso left) (eqToIso right) (by simp [map'_eq_hom₁, w]))
(fun i => by fin_cases i <;> assumption)
(fun i => by fin_cases i <;> rfl)
lemma mk₁_surjective (X : ComposableArrows C 1) : ∃ (X₀ X₁ : C) (f : X₀ ⟶ X₁), X = mk₁ f :=
⟨_, _, X.map' 0 1, ext₁ rfl rfl (by simp)⟩
variable (F)
namespace Precomp
variable (X : C)
/-- The map `Fin (n + 1 + 1) → C` which "shifts" `F.obj'` to the right and inserts `X` in
the zeroth position. -/
def obj : Fin (n + 1 + 1) → C
| ⟨0, _⟩ => X
| ⟨i + 1, hi⟩ => F.obj' i
@[simp]
lemma obj_zero : obj F X 0 = X := rfl
@[simp]
lemma obj_one : obj F X 1 = F.obj' 0 := rfl
@[simp]
lemma obj_succ (i : ℕ) (hi : i + 1 < n + 1 + 1) : obj F X ⟨i + 1, hi⟩ = F.obj' i := rfl
variable {X} (f : X ⟶ F.left)
/-- Auxiliary definition for the action on maps of the functor `F.precomp f`.
It sends `0 ≤ 1` to `f` and `i + 1 ≤ j + 1` to `F.map' i j`. -/
def map : ∀ (i j : Fin (n + 1 + 1)) (_ : i ≤ j), obj F X i ⟶ obj F X j
| ⟨0, _⟩, ⟨0, _⟩, _ => 𝟙 X
| ⟨0, _⟩, ⟨1, _⟩, _ => f
| ⟨0, _⟩, ⟨j + 2, hj⟩, _ => f ≫ F.map' 0 (j + 1)
| ⟨i + 1, hi⟩, ⟨j + 1, hj⟩, hij => F.map' i j (by simpa using hij)
@[simp]
lemma map_zero_zero : map F f 0 0 (by simp) = 𝟙 X := rfl
@[simp]
lemma map_one_one : map F f 1 1 (by simp) = F.map (𝟙 _) := rfl
@[simp]
lemma map_zero_one : map F f 0 1 (by simp) = f := rfl
@[simp]
lemma map_zero_one' : map F f 0 ⟨0 + 1, by simp⟩ (by simp) = f := rfl
|
@[simp]
| Mathlib/CategoryTheory/ComposableArrows.lean | 324 | 325 |
/-
Copyright (c) 2024 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin
-/
import Mathlib.Algebra.Lie.CartanSubalgebra
import Mathlib.Algebra.Lie.Rank
/-!
# Existence of Cartan subalgebras
In this file we prove existence of Cartan subalgebras in finite-dimensional Lie algebras,
following [barnes1967].
## Main results
* `exists_isCartanSubalgebra_of_finrank_le_card`:
A Lie algebra `L` over a field `K` has a Cartan subalgebra,
provided that the dimension of `L` over `K` is less than or equal to the cardinality of `K`.
* `exists_isCartanSubalgebra`:
A finite-dimensional Lie algebra `L` over an infinite field `K` has a Cartan subalgebra.
## References
* [barnes1967]: "On Cartan subalgebras of Lie algebras" by D.W. Barnes.
-/
namespace LieAlgebra
section CommRing
variable {K R L M : Type*}
variable [Field K] [CommRing R]
variable [LieRing L] [LieAlgebra K L] [LieAlgebra R L]
variable [AddCommGroup M] [Module R M] [LieRingModule L M] [LieModule R L M]
variable [Module.Finite K L]
variable [Module.Finite R L] [Module.Free R L]
variable [Module.Finite R M] [Module.Free R M]
open Module LieSubalgebra Module.Free Polynomial
variable (K)
namespace engel_isBot_of_isMin
/-!
## Implementation details for the proof of `LieAlgebra.engel_isBot_of_isMin`
In this section we provide some auxiliary definitions and lemmas
that are used in the proof of `LieAlgebra.engel_isBot_of_isMin`,
which is the following statement:
Let `L` be a Lie algebra of dimension `n` over a field `K` with at least `n` elements.
Given a Lie subalgebra `U` of `L`, and an element `x ∈ U` such that `U ≤ engel K x`.
Suppose that `engel K x` is minimal amongst the Engel subalgebras `engel K y` for `y ∈ U`.
Then `engel K x ≤ engel K y` for all `y ∈ U`.
We follow the proof strategy of Lemma 2 in [barnes1967].
-/
variable (R M)
variable (x y : L)
open LieModule LinearMap
local notation "φ" => LieModule.toEnd R L M
/-- Let `x` and `y` be elements of a Lie `R`-algebra `L`, and `M` a Lie module over `M`.
Then the characteristic polynomials of the family of endomorphisms `⁅r • y + x, _⁆` of `M`
have coefficients that are polynomial in `r : R`.
In other words, we obtain a polynomial over `R[X]`
that specializes to the characteristic polynomial of `⁅r • y + x, _⁆` under the map `X ↦ r`.
This polynomial is captured in `lieCharpoly R M x y`. -/
private noncomputable
def lieCharpoly : Polynomial R[X] :=
letI bL := chooseBasis R L
(polyCharpoly (LieHom.toLinearMap φ) bL).map <| RingHomClass.toRingHom <|
MvPolynomial.aeval fun i ↦ C (bL.repr y i) * X + C (bL.repr x i)
lemma lieCharpoly_monic : (lieCharpoly R M x y).Monic :=
(polyCharpoly_monic _ _).map _
lemma lieCharpoly_natDegree [Nontrivial R] : (lieCharpoly R M x y).natDegree = finrank R M := by
rw [lieCharpoly, (polyCharpoly_monic _ _).natDegree_map, polyCharpoly_natDegree]
variable {R} in
lemma lieCharpoly_map_eval (r : R) :
(lieCharpoly R M x y).map (evalRingHom r) = (φ (r • y + x)).charpoly := by
rw [lieCharpoly, map_map]
set b := chooseBasis R L
have aux : (fun i ↦ (b.repr y) i * r + (b.repr x) i) = b.repr (r • y + x) := by
ext i; simp [mul_comm r]
simp_rw [← coe_aeval_eq_evalRingHom, ← AlgHom.comp_toRingHom, MvPolynomial.comp_aeval,
map_add, map_mul, aeval_C, Algebra.id.map_eq_id, RingHom.id_apply, aeval_X, aux,
MvPolynomial.coe_aeval_eq_eval, polyCharpoly_map_eq_charpoly, LieHom.coe_toLinearMap]
lemma lieCharpoly_coeff_natDegree [Nontrivial R] (i j : ℕ) (hij : i + j = finrank R M) :
((lieCharpoly R M x y).coeff i).natDegree ≤ j := by
classical
rw [← mul_one j, lieCharpoly, coeff_map]
apply MvPolynomial.aeval_natDegree_le
· apply (polyCharpoly_coeff_isHomogeneous φ (chooseBasis R L) _ _ hij).totalDegree_le
intro k
apply Polynomial.natDegree_add_le_of_degree_le
· apply (Polynomial.natDegree_C_mul_le _ _).trans
simp only [natDegree_X, le_rfl]
· simp only [natDegree_C, zero_le]
end engel_isBot_of_isMin
end CommRing
section Field
variable {K L : Type*} [Field K] [LieRing L] [LieAlgebra K L] [Module.Finite K L]
open Module LieSubalgebra LieSubmodule Polynomial Cardinal LieModule engel_isBot_of_isMin
/-- Let `L` be a Lie algebra of dimension `n` over a field `K` with at least `n` elements.
Given a Lie subalgebra `U` of `L`, and an element `x ∈ U` such that `U ≤ engel K x`.
| Suppose that `engel K x` is minimal amongst the Engel subalgebras `engel K y` for `y ∈ U`.
Then `engel K x ≤ engel K y` for all `y ∈ U`.
Lemma 2 in [barnes1967]. -/
lemma engel_isBot_of_isMin (hLK : finrank K L ≤ #K) (U : LieSubalgebra K L)
(E : {engel K x | x ∈ U}) (hUle : U ≤ E) (hmin : IsMin E) :
IsBot E := by
rcases E with ⟨_, x, hxU, rfl⟩
rintro ⟨_, y, hyU, rfl⟩
-- It will be useful to repackage the Engel subalgebras
set Ex : {engel K x | x ∈ U} := ⟨engel K x, x, hxU, rfl⟩
set Ey : {engel K y | y ∈ U} := ⟨engel K y, y, hyU, rfl⟩
replace hUle : U ≤ Ex := hUle
replace hmin : ∀ E, E ≤ Ex → Ex ≤ E := @hmin
-- We also repackage the Engel subalgebra `engel K x`
-- as Lie submodule `E` of `L` over the Lie algebra `U`.
let E : LieSubmodule K U L :=
{ engel K x with
lie_mem := by rintro ⟨u, hu⟩ y hy; exact (engel K x).lie_mem (hUle hu) hy }
-- We may and do assume that `x ≠ 0`, since otherwise the statement is trivial.
obtain rfl|hx₀ := eq_or_ne x 0
· simpa [Ex, Ey] using hmin Ey
-- We denote by `Q` the quotient `L / E`, and by `r` the dimension of `E`.
let Q := L ⧸ E
let r := finrank K E
-- If `r = finrank K L`, then `E = L`, and the statement is trivial.
obtain hr|hr : r = finrank K L ∨ r < finrank K L := (Submodule.finrank_le _).eq_or_lt
· suffices engel K y ≤ engel K x from hmin Ey this
suffices engel K x = ⊤ by simp_rw [this, le_top]
apply LieSubalgebra.toSubmodule_injective
apply Submodule.eq_top_of_finrank_eq hr
-- So from now on, we assume that `r < finrank K L`.
-- We denote by `x'` and `y'` the elements `x` and `y` viewed as terms of `U`.
set x' : U := ⟨x, hxU⟩
set y' : U := ⟨y, hyU⟩
-- Let `u : U` denote `y - x`.
let u : U := y' - x'
-- We denote by `χ r` the characteristic polynomial of `⁅r • u + x, _⁆`
-- viewed as endomorphism of `E`. Note that `χ` is polynomial in its argument `r`.
-- Similarly: `ψ r` is the characteristic polynomial of `⁅r • u + x, _⁆`
-- viewed as endomorphism of `Q`. Note that `ψ` is polynomial in its argument `r`.
let χ : Polynomial (K[X]) := lieCharpoly K E x' u
let ψ : Polynomial (K[X]) := lieCharpoly K Q x' u
-- It suffices to show that `χ` is the monomial `X ^ r`.
suffices χ = X ^ r by
-- Indeed, by evaluating the coefficients at `1`
apply_fun (fun p ↦ p.map (evalRingHom 1)) at this
-- we find that the characteristic polynomial `χ 1` of `⁅y, _⁆` is equal to `X ^ r`
simp_rw [Polynomial.map_pow, map_X, χ, lieCharpoly_map_eval, one_smul, u, sub_add_cancel,
-- and therefore the endomorphism `⁅y, _⁆` acts nilpotently on `E`.
r, LinearMap.charpoly_eq_X_pow_iff,
Subtype.ext_iff, coe_toEnd_pow _ _ _ E, ZeroMemClass.coe_zero] at this
-- We ultimately want to show `engel K x ≤ engel K y`
intro z hz
-- which holds by definition of Engel subalgebra and the nilpotency that we just established.
rw [mem_engel_iff]
exact this ⟨z, hz⟩
-- To show that `χ = X ^ r`, it suffices to show that all coefficients in degrees `< r` are `0`.
suffices ∀ i < r, χ.coeff i = 0 by
simp_rw [r, ← lieCharpoly_natDegree K E x' u] at this ⊢
rw [(lieCharpoly_monic K E x' u).eq_X_pow_iff_natDegree_le_natTrailingDegree]
exact le_natTrailingDegree (lieCharpoly_monic K E x' u).ne_zero this
-- Let us consider the `i`-th coefficient of `χ`, for `i < r`.
intro i hi
-- We separately consider the case `i = 0`.
obtain rfl|hi0 := eq_or_ne i 0
· -- `The polynomial `coeff χ 0` is zero if it evaluates to zero on all elements of `K`,
-- provided that its degree is stictly less than `#K`.
apply eq_zero_of_forall_eval_zero_of_natDegree_lt_card _ _ ?deg
case deg =>
-- We need to show `(natDegree (coeff χ 0)) < #K` and know that `finrank K L ≤ #K`
apply lt_of_lt_of_le _ hLK
rw [Nat.cast_lt]
-- So we are left with showing `natDegree (coeff χ 0) < finrank K L`
apply lt_of_le_of_lt _ hr
apply lieCharpoly_coeff_natDegree _ _ _ _ 0 r (zero_add r)
-- Fix an element of `K`.
intro α
-- We want to show that `α` is a root of `coeff χ 0`.
-- So we need to show that there is a `z ≠ 0` in `E` satisfying `⁅α • u + x, z⁆ = 0`.
rw [← coe_evalRingHom, ← coeff_map, lieCharpoly_map_eval,
← constantCoeff_apply, LinearMap.charpoly_constantCoeff_eq_zero_iff]
-- We consider `z = α • u + x`, and split into the cases `z = 0` and `z ≠ 0`.
let z := α • u + x'
obtain hz₀|hz₀ := eq_or_ne z 0
· -- If `z = 0`, then `⁅α • u + x, x⁆` vanishes and we use our assumption `x ≠ 0`.
refine ⟨⟨x, self_mem_engel K x⟩, ?_, ?_⟩
· exact Subtype.coe_ne_coe.mp hx₀
· dsimp only [z] at hz₀
simp only [coe_bracket_of_module, hz₀, LieHom.map_zero, LinearMap.zero_apply]
-- If `z ≠ 0`, then `⁅α • u + x, z⁆` vanishes per axiom of Lie algebras
refine ⟨⟨z, hUle z.2⟩, ?_, ?_⟩
· simpa only [coe_bracket_of_module, ne_eq, Submodule.mk_eq_zero, Subtype.ext_iff] using hz₀
· show ⁅z, _⁆ = (0 : E)
ext
exact lie_self z.1
-- We are left with the case `i ≠ 0`, and want to show `coeff χ i = 0`.
-- We will do this once again by showing that `coeff χ i` vanishes
-- on a sufficiently large subset `s` of `K`.
-- But we first need to get our hands on that subset `s`.
-- We start by observing that `ψ` has non-trivial constant coefficient.
have hψ : constantCoeff ψ ≠ 0 := by
-- Suppose that `ψ` in fact has trivial constant coefficient.
intro H
-- Then there exists a `z ≠ 0` in `Q` such that `⁅x, z⁆ = 0`.
obtain ⟨z, hz0, hxz⟩ : ∃ z : Q, z ≠ 0 ∧ ⁅x', z⁆ = 0 := by
-- Indeed, if the constant coefficient of `ψ` is trivial,
-- then `0` is a root of the characteristic polynomial of `⁅0 • u + x, _⁆` acting on `Q`,
-- and hence we find an eigenvector `z` as desired.
apply_fun (evalRingHom 0) at H
rw [constantCoeff_apply, ← coeff_map, lieCharpoly_map_eval,
← constantCoeff_apply, map_zero, LinearMap.charpoly_constantCoeff_eq_zero_iff] at H
simpa only [coe_bracket_of_module, ne_eq, zero_smul, zero_add, toEnd_apply_apply]
using H
-- It suffices to show `z = 0` (in `Q`) to obtain a contradiction.
apply hz0
-- We replace `z : Q` by a representative in `L`.
obtain ⟨z, rfl⟩ := LieSubmodule.Quotient.surjective_mk' E z
-- The assumption `⁅x, z⁆ = 0` is equivalent to `⁅x, z⁆ ∈ E`.
have : ⁅x, z⁆ ∈ E := by rwa [← LieSubmodule.Quotient.mk_eq_zero']
-- From this we deduce that there exists an `n` such that `⁅x, _⁆ ^ n` vanishes on `⁅x, z⁆`.
-- On the other hand, our goal is to show `z = 0` in `Q`,
-- which is equivalent to showing that `⁅x, _⁆ ^ n` vanishes on `z`, for some `n`.
simp only [coe_bracket_of_module, LieSubmodule.mem_mk_iff', LieSubalgebra.mem_toSubmodule,
mem_engel_iff, LieSubmodule.Quotient.mk'_apply, LieSubmodule.Quotient.mk_eq_zero', E, Q]
at this ⊢
-- Hence we win.
obtain ⟨n, hn⟩ := this
use n+1
rwa [pow_succ]
-- Now we find a subset `s` of `K` of size `≥ r`
-- such that `constantCoeff ψ` takes non-zero values on all of `s`.
-- This turns out to be the subset that we alluded to earlier.
obtain ⟨s, hs, hsψ⟩ : ∃ s : Finset K, r ≤ s.card ∧ ∀ α ∈ s, (constantCoeff ψ).eval α ≠ 0 := by
classical
-- Let `t` denote the set of roots of `constantCoeff ψ`.
let t := (constantCoeff ψ).roots.toFinset
-- We show that `t` has cardinality at most `finrank K L - r`.
have ht : t.card ≤ finrank K L - r := by
refine (Multiset.toFinset_card_le _).trans ?_
refine (card_roots' _).trans ?_
rw [constantCoeff_apply]
-- Indeed, `constantCoeff ψ` has degree at most `finrank K Q = finrank K L - r`.
apply lieCharpoly_coeff_natDegree
suffices finrank K Q + r = finrank K L by rw [← this, zero_add, Nat.add_sub_cancel]
apply Submodule.finrank_quotient_add_finrank
-- Hence there exists a subset of size `≥ r` in the complement of `t`,
-- and `constantCoeff ψ` takes non-zero values on all of this subset.
obtain ⟨s, hs⟩ := exists_finset_le_card K _ hLK
use s \ t
refine ⟨?_, ?_⟩
· refine le_trans ?_ (Finset.le_card_sdiff _ _)
omega
· intro α hα
simp only [Finset.mem_sdiff, Multiset.mem_toFinset, mem_roots', IsRoot.def, not_and, t] at hα
exact hα.2 hψ
-- So finally we can continue our proof strategy by showing that `coeff χ i` vanishes on `s`.
apply eq_zero_of_natDegree_lt_card_of_eval_eq_zero' _ s _ ?hcard
case hcard =>
-- We need to show that `natDegree (coeff χ i) < s.card`
-- Which follows from our assumptions `i < r` and `r ≤ s.card`
-- and the fact that the degree of `coeff χ i` is less than or equal to `r - i`.
apply lt_of_le_of_lt (lieCharpoly_coeff_natDegree _ _ _ _ i (r - i) _)
· omega
· dsimp only [r] at hi ⊢
rw [Nat.add_sub_cancel' hi.le]
-- We need to show that for all `α ∈ s`, the polynomial `coeff χ i` evaluates to zero at `α`.
intro α hα
-- Once again, we are left with showing that `⁅y, _⁆` acts nilpotently on `E`.
rw [← coe_evalRingHom, ← coeff_map, lieCharpoly_map_eval,
(LinearMap.charpoly_eq_X_pow_iff _).mpr, coeff_X_pow, if_neg hi.ne]
-- To do so, it suffices to show that the Engel subalgebra of `v = a • u + x` is contained in `E`.
let v := α • u + x'
suffices engel K (v : L) ≤ engel K x by
-- Indeed, in that case the minimality assumption on `E` implies
-- that `E` is contained in the Engel subalgebra of `v`.
replace this : engel K x ≤ engel K (v : L) := (hmin ⟨_, v, v.2, rfl⟩ this).ge
intro z
-- And so we are done, by the definition of Engel subalgebra.
simpa only [mem_engel_iff, Subtype.ext_iff, coe_toEnd_pow _ _ _ E] using this z.2
-- Now we are in good shape.
-- Fix an element `z` in the Engel subalgebra of `y`.
intro z hz
-- We need to show that `z` is in `E`, or alternatively that `z = 0` in `Q`.
show z ∈ E
rw [← LieSubmodule.Quotient.mk_eq_zero]
-- We denote the image of `z` in `Q` by `z'`.
set z' : Q := LieSubmodule.Quotient.mk' E z
-- First we observe that `z'` is killed by a power of `⁅v, _⁆`.
have hz' : ∃ n : ℕ, (toEnd K U Q v ^ n) z' = 0 := by
rw [mem_engel_iff] at hz
obtain ⟨n, hn⟩ := hz
use n
apply_fun LieSubmodule.Quotient.mk' E at hn
rw [LieModuleHom.map_zero] at hn
rw [← hn]
clear hn
induction n with
| zero => simp only [z', pow_zero, Module.End.one_apply]
| succ n ih => rw [pow_succ', pow_succ', Module.End.mul_apply, ih]; rfl
classical
-- Now let `n` be the smallest power such that `⁅v, _⁆ ^ n` kills `z'`.
set n := Nat.find hz' with _hn
have hn : (toEnd K U Q v ^ n) z' = 0 := Nat.find_spec hz'
-- If `n = 0`, then we are done.
obtain hn₀|⟨k, hk⟩ : n = 0 ∨ ∃ k, n = k + 1 := by cases n <;> simp
· simpa only [hn₀, pow_zero, Module.End.one_apply] using hn
-- If `n = k + 1`, then we can write `⁅v, _⁆ ^ n = ⁅v, _⁆ ∘ ⁅v, _⁆ ^ k`.
-- Recall that `constantCoeff ψ` is non-zero on `α`, and `v = α • u + x`.
specialize hsψ α hα
-- Hence `⁅v, _⁆` acts injectively on `Q`.
rw [← coe_evalRingHom, constantCoeff_apply, ← coeff_map, lieCharpoly_map_eval,
← constantCoeff_apply, ne_eq, LinearMap.charpoly_constantCoeff_eq_zero_iff] at hsψ
-- We deduce from this that `z' = 0`, arguing by contraposition.
contrapose! hsψ
-- Indeed `⁅v, _⁆` kills `⁅v, _⁆ ^ k` applied to `z'`.
use (toEnd K U Q v ^ k) z'
refine ⟨?_, ?_⟩
· -- And `⁅v, _⁆ ^ k` applied to `z'` is non-zero by definition of `n`.
apply Nat.find_min hz'; omega
· rw [← hn, hk, pow_succ', Module.End.mul_apply]
| Mathlib/Algebra/Lie/CartanExists.lean | 124 | 345 |
/-
Copyright (c) 2023 Geoffrey Irving. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Loeffler, Geoffrey Irving, Stefan Kebekus
-/
import Mathlib.Analysis.Analytic.Composition
import Mathlib.Analysis.Analytic.Linear
import Mathlib.Analysis.NormedSpace.OperatorNorm.Mul
import Mathlib.Analysis.Normed.Ring.Units
import Mathlib.Analysis.Analytic.OfScalars
/-!
# Various ways to combine analytic functions
We show that the following are analytic:
1. Cartesian products of analytic functions
2. Arithmetic on analytic functions: `mul`, `smul`, `inv`, `div`
3. Finite sums and products: `Finset.sum`, `Finset.prod`
-/
noncomputable section
open scoped Topology
open Filter Asymptotics ENNReal NNReal
variable {α : Type*}
variable {𝕜 : Type*} [NontriviallyNormedField 𝕜]
variable {E F G H : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E] [NormedAddCommGroup F]
[NormedSpace 𝕜 F] [NormedAddCommGroup G] [NormedSpace 𝕜 G] [NormedAddCommGroup H]
[NormedSpace 𝕜 H]
variable {𝕝 : Type*} [NontriviallyNormedField 𝕝] [NormedAlgebra 𝕜 𝕝]
variable {A : Type*} [NormedRing A] [NormedAlgebra 𝕜 A]
/-!
### Constants are analytic
-/
theorem hasFPowerSeriesOnBall_const {c : F} {e : E} :
HasFPowerSeriesOnBall (fun _ => c) (constFormalMultilinearSeries 𝕜 E c) e ⊤ := by
refine ⟨by simp, WithTop.top_pos, fun _ => hasSum_single 0 fun n hn => ?_⟩
simp [constFormalMultilinearSeries_apply hn]
theorem hasFPowerSeriesAt_const {c : F} {e : E} :
HasFPowerSeriesAt (fun _ => c) (constFormalMultilinearSeries 𝕜 E c) e :=
⟨⊤, hasFPowerSeriesOnBall_const⟩
@[fun_prop]
theorem analyticAt_const {v : F} {x : E} : AnalyticAt 𝕜 (fun _ => v) x :=
⟨constFormalMultilinearSeries 𝕜 E v, hasFPowerSeriesAt_const⟩
theorem analyticOnNhd_const {v : F} {s : Set E} : AnalyticOnNhd 𝕜 (fun _ => v) s :=
fun _ _ => analyticAt_const
theorem analyticWithinAt_const {v : F} {s : Set E} {x : E} : AnalyticWithinAt 𝕜 (fun _ => v) s x :=
analyticAt_const.analyticWithinAt
theorem analyticOn_const {v : F} {s : Set E} : AnalyticOn 𝕜 (fun _ => v) s :=
analyticOnNhd_const.analyticOn
/-!
### Addition, negation, subtraction, scalar multiplication
-/
section
variable {f g : E → F} {pf pg : FormalMultilinearSeries 𝕜 E F} {s : Set E} {x : E} {r : ℝ≥0∞}
{c : 𝕜}
theorem HasFPowerSeriesWithinOnBall.add (hf : HasFPowerSeriesWithinOnBall f pf s x r)
(hg : HasFPowerSeriesWithinOnBall g pg s x r) :
HasFPowerSeriesWithinOnBall (f + g) (pf + pg) s x r :=
{ r_le := le_trans (le_min_iff.2 ⟨hf.r_le, hg.r_le⟩) (pf.min_radius_le_radius_add pg)
r_pos := hf.r_pos
hasSum := fun hy h'y => (hf.hasSum hy h'y).add (hg.hasSum hy h'y) }
theorem HasFPowerSeriesOnBall.add (hf : HasFPowerSeriesOnBall f pf x r)
(hg : HasFPowerSeriesOnBall g pg x r) : HasFPowerSeriesOnBall (f + g) (pf + pg) x r :=
{ r_le := le_trans (le_min_iff.2 ⟨hf.r_le, hg.r_le⟩) (pf.min_radius_le_radius_add pg)
r_pos := hf.r_pos
hasSum := fun hy => (hf.hasSum hy).add (hg.hasSum hy) }
theorem HasFPowerSeriesWithinAt.add
(hf : HasFPowerSeriesWithinAt f pf s x) (hg : HasFPowerSeriesWithinAt g pg s x) :
HasFPowerSeriesWithinAt (f + g) (pf + pg) s x := by
rcases (hf.eventually.and hg.eventually).exists with ⟨r, hr⟩
exact ⟨r, hr.1.add hr.2⟩
theorem HasFPowerSeriesAt.add (hf : HasFPowerSeriesAt f pf x) (hg : HasFPowerSeriesAt g pg x) :
HasFPowerSeriesAt (f + g) (pf + pg) x := by
rcases (hf.eventually.and hg.eventually).exists with ⟨r, hr⟩
exact ⟨r, hr.1.add hr.2⟩
theorem AnalyticWithinAt.add (hf : AnalyticWithinAt 𝕜 f s x) (hg : AnalyticWithinAt 𝕜 g s x) :
AnalyticWithinAt 𝕜 (f + g) s x :=
let ⟨_, hpf⟩ := hf
let ⟨_, hqf⟩ := hg
(hpf.add hqf).analyticWithinAt
@[fun_prop]
theorem AnalyticAt.fun_add (hf : AnalyticAt 𝕜 f x) (hg : AnalyticAt 𝕜 g x) :
AnalyticAt 𝕜 (fun z ↦ f z + g z) x :=
let ⟨_, hpf⟩ := hf
let ⟨_, hqf⟩ := hg
(hpf.add hqf).analyticAt
@[deprecated (since := "2025-03-11")] alias AnalyticAt.add' := AnalyticAt.fun_add
@[fun_prop]
theorem AnalyticAt.add (hf : AnalyticAt 𝕜 f x) (hg : AnalyticAt 𝕜 g x) : AnalyticAt 𝕜 (f + g) x :=
hf.fun_add hg
theorem HasFPowerSeriesWithinOnBall.neg (hf : HasFPowerSeriesWithinOnBall f pf s x r) :
HasFPowerSeriesWithinOnBall (-f) (-pf) s x r :=
{ r_le := by
rw [pf.radius_neg]
exact hf.r_le
r_pos := hf.r_pos
hasSum := fun hy h'y => (hf.hasSum hy h'y).neg }
theorem HasFPowerSeriesOnBall.neg (hf : HasFPowerSeriesOnBall f pf x r) :
HasFPowerSeriesOnBall (-f) (-pf) x r :=
{ r_le := by
rw [pf.radius_neg]
exact hf.r_le
r_pos := hf.r_pos
hasSum := fun hy => (hf.hasSum hy).neg }
theorem HasFPowerSeriesWithinAt.neg (hf : HasFPowerSeriesWithinAt f pf s x) :
HasFPowerSeriesWithinAt (-f) (-pf) s x :=
let ⟨_, hrf⟩ := hf
hrf.neg.hasFPowerSeriesWithinAt
theorem HasFPowerSeriesAt.neg (hf : HasFPowerSeriesAt f pf x) : HasFPowerSeriesAt (-f) (-pf) x :=
let ⟨_, hrf⟩ := hf
hrf.neg.hasFPowerSeriesAt
theorem AnalyticWithinAt.neg (hf : AnalyticWithinAt 𝕜 f s x) : AnalyticWithinAt 𝕜 (-f) s x :=
let ⟨_, hpf⟩ := hf
hpf.neg.analyticWithinAt
@[fun_prop]
theorem AnalyticAt.fun_neg (hf : AnalyticAt 𝕜 f x) : AnalyticAt 𝕜 (fun z ↦ -f z) x :=
let ⟨_, hpf⟩ := hf
hpf.neg.analyticAt
@[fun_prop]
theorem AnalyticAt.neg (hf : AnalyticAt 𝕜 f x) : AnalyticAt 𝕜 (-f) x :=
hf.fun_neg
@[deprecated (since := "2025-03-11")] alias AnalyticAt.neg' := AnalyticAt.fun_neg
theorem HasFPowerSeriesWithinOnBall.sub (hf : HasFPowerSeriesWithinOnBall f pf s x r)
(hg : HasFPowerSeriesWithinOnBall g pg s x r) :
HasFPowerSeriesWithinOnBall (f - g) (pf - pg) s x r := by
simpa only [sub_eq_add_neg] using hf.add hg.neg
theorem HasFPowerSeriesOnBall.sub (hf : HasFPowerSeriesOnBall f pf x r)
(hg : HasFPowerSeriesOnBall g pg x r) : HasFPowerSeriesOnBall (f - g) (pf - pg) x r := by
simpa only [sub_eq_add_neg] using hf.add hg.neg
theorem HasFPowerSeriesWithinAt.sub
(hf : HasFPowerSeriesWithinAt f pf s x) (hg : HasFPowerSeriesWithinAt g pg s x) :
HasFPowerSeriesWithinAt (f - g) (pf - pg) s x := by
simpa only [sub_eq_add_neg] using hf.add hg.neg
theorem HasFPowerSeriesAt.sub (hf : HasFPowerSeriesAt f pf x) (hg : HasFPowerSeriesAt g pg x) :
HasFPowerSeriesAt (f - g) (pf - pg) x := by
simpa only [sub_eq_add_neg] using hf.add hg.neg
theorem AnalyticWithinAt.sub (hf : AnalyticWithinAt 𝕜 f s x) (hg : AnalyticWithinAt 𝕜 g s x) :
AnalyticWithinAt 𝕜 (f - g) s x := by
simpa only [sub_eq_add_neg] using hf.add hg.neg
@[fun_prop]
theorem AnalyticAt.fun_sub (hf : AnalyticAt 𝕜 f x) (hg : AnalyticAt 𝕜 g x) :
AnalyticAt 𝕜 (fun z ↦ f z - g z) x := by
simpa only [sub_eq_add_neg] using hf.add hg.neg
@[fun_prop]
theorem AnalyticAt.sub (hf : AnalyticAt 𝕜 f x) (hg : AnalyticAt 𝕜 g x) :
AnalyticAt 𝕜 (f - g) x :=
hf.fun_sub hg
@[deprecated (since := "2025-03-11")] alias AnalyticAt.sub' := AnalyticAt.fun_sub
theorem HasFPowerSeriesWithinOnBall.const_smul (hf : HasFPowerSeriesWithinOnBall f pf s x r) :
HasFPowerSeriesWithinOnBall (c • f) (c • pf) s x r where
r_le := le_trans hf.r_le pf.radius_le_smul
r_pos := hf.r_pos
hasSum := fun hy h'y => (hf.hasSum hy h'y).const_smul _
theorem HasFPowerSeriesOnBall.const_smul (hf : HasFPowerSeriesOnBall f pf x r) :
HasFPowerSeriesOnBall (c • f) (c • pf) x r where
r_le := le_trans hf.r_le pf.radius_le_smul
r_pos := hf.r_pos
hasSum := fun hy => (hf.hasSum hy).const_smul _
theorem HasFPowerSeriesWithinAt.const_smul (hf : HasFPowerSeriesWithinAt f pf s x) :
HasFPowerSeriesWithinAt (c • f) (c • pf) s x :=
let ⟨_, hrf⟩ := hf
hrf.const_smul.hasFPowerSeriesWithinAt
theorem HasFPowerSeriesAt.const_smul (hf : HasFPowerSeriesAt f pf x) :
HasFPowerSeriesAt (c • f) (c • pf) x :=
let ⟨_, hrf⟩ := hf
hrf.const_smul.hasFPowerSeriesAt
theorem AnalyticWithinAt.const_smul (hf : AnalyticWithinAt 𝕜 f s x) :
AnalyticWithinAt 𝕜 (c • f) s x :=
let ⟨_, hpf⟩ := hf
hpf.const_smul.analyticWithinAt
@[fun_prop]
theorem AnalyticAt.fun_const_smul (hf : AnalyticAt 𝕜 f x) : AnalyticAt 𝕜 (fun z ↦ c • f z) x :=
let ⟨_, hpf⟩ := hf
hpf.const_smul.analyticAt
@[fun_prop]
theorem AnalyticAt.const_smul (hf : AnalyticAt 𝕜 f x) : AnalyticAt 𝕜 (c • f) x :=
hf.fun_const_smul
@[deprecated (since := "2025-03-11")] alias AnalyticAt.const_smul' := AnalyticAt.fun_const_smul
theorem AnalyticOn.add (hf : AnalyticOn 𝕜 f s) (hg : AnalyticOn 𝕜 g s) :
AnalyticOn 𝕜 (f + g) s :=
fun z hz => (hf z hz).add (hg z hz)
theorem AnalyticOnNhd.add (hf : AnalyticOnNhd 𝕜 f s) (hg : AnalyticOnNhd 𝕜 g s) :
AnalyticOnNhd 𝕜 (f + g) s :=
fun z hz => (hf z hz).add (hg z hz)
theorem AnalyticOn.neg (hf : AnalyticOn 𝕜 f s) : AnalyticOn 𝕜 (-f) s :=
fun z hz ↦ (hf z hz).neg
theorem AnalyticOnNhd.neg (hf : AnalyticOnNhd 𝕜 f s) : AnalyticOnNhd 𝕜 (-f) s :=
| fun z hz ↦ (hf z hz).neg
theorem AnalyticOn.sub (hf : AnalyticOn 𝕜 f s) (hg : AnalyticOn 𝕜 g s) :
AnalyticOn 𝕜 (f - g) s :=
fun z hz => (hf z hz).sub (hg z hz)
theorem AnalyticOnNhd.sub (hf : AnalyticOnNhd 𝕜 f s) (hg : AnalyticOnNhd 𝕜 g s) :
AnalyticOnNhd 𝕜 (f - g) s :=
fun z hz => (hf z hz).sub (hg z hz)
end
/-!
### Cartesian products are analytic
| Mathlib/Analysis/Analytic/Constructions.lean | 238 | 251 |
/-
Copyright (c) 2021 Henry Swanson. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Henry Swanson
-/
import Mathlib.Algebra.BigOperators.Ring.Finset
import Mathlib.Combinatorics.Derangements.Basic
import Mathlib.Data.Fintype.BigOperators
import Mathlib.Tactic.Ring
/-!
# Derangements on fintypes
This file contains lemmas that describe the cardinality of `derangements α` when `α` is a fintype.
# Main definitions
* `card_derangements_invariant`: A lemma stating that the number of derangements on a type `α`
depends only on the cardinality of `α`.
* `numDerangements n`: The number of derangements on an n-element set, defined in a computation-
friendly way.
* `card_derangements_eq_numDerangements`: Proof that `numDerangements` really does compute the
number of derangements.
* `numDerangements_sum`: A lemma giving an expression for `numDerangements n` in terms of
factorials.
-/
open derangements Equiv Fintype
variable {α : Type*} [DecidableEq α] [Fintype α]
instance : DecidablePred (derangements α) := fun _ => Fintype.decidableForallFintype
-- Porting note: used to use the tactic delta_instance
instance : Fintype (derangements α) := Subtype.fintype (fun (_ : Perm α) => ∀ (x_1 : α), ¬_ = x_1)
theorem card_derangements_invariant {α β : Type*} [Fintype α] [DecidableEq α] [Fintype β]
[DecidableEq β] (h : card α = card β) : card (derangements α) = card (derangements β) :=
Fintype.card_congr (Equiv.derangementsCongr <| equivOfCardEq h)
theorem card_derangements_fin_add_two (n : ℕ) :
card (derangements (Fin (n + 2))) =
(n + 1) * card (derangements (Fin n)) + (n + 1) * card (derangements (Fin (n + 1))) := by
-- get some basic results about the size of Fin (n+1) plus or minus an element
have h1 : ∀ a : Fin (n + 1), card ({a}ᶜ : Set (Fin (n + 1))) = card (Fin n) := by
intro a
simp only
[card_ofFinset (s := Finset.filter (fun x => x ∈ ({a}ᶜ : Set (Fin (n + 1)))) Finset.univ),
Set.mem_compl_singleton_iff, Finset.filter_ne' _ a,
Finset.card_erase_of_mem (Finset.mem_univ a), Finset.card_fin, add_tsub_cancel_right,
card_fin]
have h2 : card (Fin (n + 2)) = card (Option (Fin (n + 1))) := by simp only [card_fin, card_option]
-- rewrite the LHS and substitute in our fintype-level equivalence
simp only [card_derangements_invariant h2,
card_congr
(@derangementsRecursionEquiv (Fin (n + 1))
_),-- push the cardinality through the Σ and ⊕ so that we can use `card_n`
card_sigma,
card_sum, card_derangements_invariant (h1 _), Finset.sum_const, nsmul_eq_mul, Finset.card_fin,
mul_add, Nat.cast_id]
/-- The number of derangements of an `n`-element set. -/
def numDerangements : ℕ → ℕ
| 0 => 1
| 1 => 0
| n + 2 => (n + 1) * (numDerangements n + numDerangements (n + 1))
@[simp]
theorem numDerangements_zero : numDerangements 0 = 1 :=
rfl
@[simp]
theorem numDerangements_one : numDerangements 1 = 0 :=
rfl
theorem numDerangements_add_two (n : ℕ) :
numDerangements (n + 2) = (n + 1) * (numDerangements n + numDerangements (n + 1)) :=
rfl
theorem numDerangements_succ (n : ℕ) :
(numDerangements (n + 1) : ℤ) = (n + 1) * (numDerangements n : ℤ) - (-1) ^ n := by
induction n with
| zero => rfl
| succ n hn =>
simp only [numDerangements_add_two, hn, pow_succ, Int.natCast_mul, Int.natCast_add]
| ring
theorem card_derangements_fin_eq_numDerangements {n : ℕ} :
card (derangements (Fin n)) = numDerangements n := by
induction n using Nat.strongRecOn with | ind n hyp => _
rcases n with _ | _ | n
| Mathlib/Combinatorics/Derangements/Finite.lean | 87 | 92 |
/-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Abhimanyu Pallavi Sudhir
-/
import Mathlib.Algebra.CharP.Defs
import Mathlib.Algebra.Order.CauSeq.BigOperators
import Mathlib.Algebra.Order.Star.Basic
import Mathlib.Data.Complex.BigOperators
import Mathlib.Data.Complex.Norm
import Mathlib.Data.Nat.Choose.Sum
/-!
# Exponential Function
This file contains the definitions of the real and complex exponential function.
## Main definitions
* `Complex.exp`: The complex exponential function, defined via its Taylor series
* `Real.exp`: The real exponential function, defined as the real part of the complex exponential
-/
open CauSeq Finset IsAbsoluteValue
open scoped ComplexConjugate
namespace Complex
theorem isCauSeq_norm_exp (z : ℂ) :
IsCauSeq abs fun n => ∑ m ∈ range n, ‖z ^ m / m.factorial‖ :=
let ⟨n, hn⟩ := exists_nat_gt ‖z‖
have hn0 : (0 : ℝ) < n := lt_of_le_of_lt (norm_nonneg _) hn
IsCauSeq.series_ratio_test n (‖z‖ / n) (div_nonneg (norm_nonneg _) (le_of_lt hn0))
(by rwa [div_lt_iff₀ hn0, one_mul]) fun m hm => by
rw [abs_norm, abs_norm, Nat.factorial_succ, pow_succ', mul_comm m.succ, Nat.cast_mul,
← div_div, mul_div_assoc, mul_div_right_comm, Complex.norm_mul, Complex.norm_div,
norm_natCast]
gcongr
exact le_trans hm (Nat.le_succ _)
@[deprecated (since := "2025-02-16")] alias isCauSeq_abs_exp := isCauSeq_norm_exp
noncomputable section
theorem isCauSeq_exp (z : ℂ) : IsCauSeq (‖·‖) fun n => ∑ m ∈ range n, z ^ m / m.factorial :=
(isCauSeq_norm_exp z).of_abv
/-- The Cauchy sequence consisting of partial sums of the Taylor series of
the complex exponential function -/
@[pp_nodot]
def exp' (z : ℂ) : CauSeq ℂ (‖·‖) :=
⟨fun n => ∑ m ∈ range n, z ^ m / m.factorial, isCauSeq_exp z⟩
/-- The complex exponential function, defined via its Taylor series -/
@[pp_nodot]
def exp (z : ℂ) : ℂ :=
CauSeq.lim (exp' z)
/-- scoped notation for the complex exponential function -/
scoped notation "cexp" => Complex.exp
end
end Complex
namespace Real
open Complex
noncomputable section
/-- The real exponential function, defined as the real part of the complex exponential -/
@[pp_nodot]
nonrec def exp (x : ℝ) : ℝ :=
(exp x).re
/-- scoped notation for the real exponential function -/
scoped notation "rexp" => Real.exp
end
end Real
namespace Complex
variable (x y : ℂ)
@[simp]
theorem exp_zero : exp 0 = 1 := by
rw [exp]
refine lim_eq_of_equiv_const fun ε ε0 => ⟨1, fun j hj => ?_⟩
convert (config := .unfoldSameFun) ε0 -- ε0 : ε > 0 but goal is _ < ε
rcases j with - | j
· exact absurd hj (not_le_of_gt zero_lt_one)
· dsimp [exp']
induction' j with j ih
· dsimp [exp']; simp [show Nat.succ 0 = 1 from rfl]
· rw [← ih (by simp [Nat.succ_le_succ])]
simp only [sum_range_succ, pow_succ]
simp
theorem exp_add : exp (x + y) = exp x * exp y := by
have hj : ∀ j : ℕ, (∑ m ∈ range j, (x + y) ^ m / m.factorial) =
∑ i ∈ range j, ∑ k ∈ range (i + 1), x ^ k / k.factorial *
(y ^ (i - k) / (i - k).factorial) := by
intro j
refine Finset.sum_congr rfl fun m _ => ?_
rw [add_pow, div_eq_mul_inv, sum_mul]
refine Finset.sum_congr rfl fun I hi => ?_
have h₁ : (m.choose I : ℂ) ≠ 0 :=
Nat.cast_ne_zero.2 (pos_iff_ne_zero.1 (Nat.choose_pos (Nat.le_of_lt_succ (mem_range.1 hi))))
have h₂ := Nat.choose_mul_factorial_mul_factorial (Nat.le_of_lt_succ <| Finset.mem_range.1 hi)
rw [← h₂, Nat.cast_mul, Nat.cast_mul, mul_inv, mul_inv]
simp only [mul_left_comm (m.choose I : ℂ), mul_assoc, mul_left_comm (m.choose I : ℂ)⁻¹,
mul_comm (m.choose I : ℂ)]
rw [inv_mul_cancel₀ h₁]
simp [div_eq_mul_inv, mul_comm, mul_assoc, mul_left_comm]
simp_rw [exp, exp', lim_mul_lim]
apply (lim_eq_lim_of_equiv _).symm
simp only [hj]
exact cauchy_product (isCauSeq_norm_exp x) (isCauSeq_exp y)
/-- the exponential function as a monoid hom from `Multiplicative ℂ` to `ℂ` -/
@[simps]
noncomputable def expMonoidHom : MonoidHom (Multiplicative ℂ) ℂ :=
{ toFun := fun z => exp z.toAdd,
map_one' := by simp,
map_mul' := by simp [exp_add] }
theorem exp_list_sum (l : List ℂ) : exp l.sum = (l.map exp).prod :=
map_list_prod (M := Multiplicative ℂ) expMonoidHom l
theorem exp_multiset_sum (s : Multiset ℂ) : exp s.sum = (s.map exp).prod :=
@MonoidHom.map_multiset_prod (Multiplicative ℂ) ℂ _ _ expMonoidHom s
theorem exp_sum {α : Type*} (s : Finset α) (f : α → ℂ) :
exp (∑ x ∈ s, f x) = ∏ x ∈ s, exp (f x) :=
map_prod (β := Multiplicative ℂ) expMonoidHom f s
lemma exp_nsmul (x : ℂ) (n : ℕ) : exp (n • x) = exp x ^ n :=
@MonoidHom.map_pow (Multiplicative ℂ) ℂ _ _ expMonoidHom _ _
theorem exp_nat_mul (x : ℂ) : ∀ n : ℕ, exp (n * x) = exp x ^ n
| 0 => by rw [Nat.cast_zero, zero_mul, exp_zero, pow_zero]
| Nat.succ n => by rw [pow_succ, Nat.cast_add_one, add_mul, exp_add, ← exp_nat_mul _ n, one_mul]
@[simp]
theorem exp_ne_zero : exp x ≠ 0 := fun h =>
zero_ne_one (α := ℂ) <| by rw [← exp_zero, ← add_neg_cancel x, exp_add, h]; simp
theorem exp_neg : exp (-x) = (exp x)⁻¹ := by
rw [← mul_right_inj' (exp_ne_zero x), ← exp_add]; simp [mul_inv_cancel₀ (exp_ne_zero x)]
theorem exp_sub : exp (x - y) = exp x / exp y := by
simp [sub_eq_add_neg, exp_add, exp_neg, div_eq_mul_inv]
theorem exp_int_mul (z : ℂ) (n : ℤ) : Complex.exp (n * z) = Complex.exp z ^ n := by
cases n
· simp [exp_nat_mul]
· simp [exp_add, add_mul, pow_add, exp_neg, exp_nat_mul]
@[simp]
theorem exp_conj : exp (conj x) = conj (exp x) := by
dsimp [exp]
rw [← lim_conj]
refine congr_arg CauSeq.lim (CauSeq.ext fun _ => ?_)
dsimp [exp', Function.comp_def, cauSeqConj]
rw [map_sum (starRingEnd _)]
refine sum_congr rfl fun n _ => ?_
rw [map_div₀, map_pow, ← ofReal_natCast, conj_ofReal]
@[simp]
theorem ofReal_exp_ofReal_re (x : ℝ) : ((exp x).re : ℂ) = exp x :=
conj_eq_iff_re.1 <| by rw [← exp_conj, conj_ofReal]
@[simp, norm_cast]
theorem ofReal_exp (x : ℝ) : (Real.exp x : ℂ) = exp x :=
ofReal_exp_ofReal_re _
@[simp]
theorem exp_ofReal_im (x : ℝ) : (exp x).im = 0 := by rw [← ofReal_exp_ofReal_re, ofReal_im]
theorem exp_ofReal_re (x : ℝ) : (exp x).re = Real.exp x :=
rfl
end Complex
namespace Real
open Complex
variable (x y : ℝ)
@[simp]
theorem exp_zero : exp 0 = 1 := by simp [Real.exp]
nonrec theorem exp_add : exp (x + y) = exp x * exp y := by simp [exp_add, exp]
/-- the exponential function as a monoid hom from `Multiplicative ℝ` to `ℝ` -/
@[simps]
noncomputable def expMonoidHom : MonoidHom (Multiplicative ℝ) ℝ :=
{ toFun := fun x => exp x.toAdd,
map_one' := by simp,
map_mul' := by simp [exp_add] }
theorem exp_list_sum (l : List ℝ) : exp l.sum = (l.map exp).prod :=
map_list_prod (M := Multiplicative ℝ) expMonoidHom l
theorem exp_multiset_sum (s : Multiset ℝ) : exp s.sum = (s.map exp).prod :=
@MonoidHom.map_multiset_prod (Multiplicative ℝ) ℝ _ _ expMonoidHom s
theorem exp_sum {α : Type*} (s : Finset α) (f : α → ℝ) :
exp (∑ x ∈ s, f x) = ∏ x ∈ s, exp (f x) :=
map_prod (β := Multiplicative ℝ) expMonoidHom f s
lemma exp_nsmul (x : ℝ) (n : ℕ) : exp (n • x) = exp x ^ n :=
@MonoidHom.map_pow (Multiplicative ℝ) ℝ _ _ expMonoidHom _ _
nonrec theorem exp_nat_mul (x : ℝ) (n : ℕ) : exp (n * x) = exp x ^ n :=
ofReal_injective (by simp [exp_nat_mul])
@[simp]
nonrec theorem exp_ne_zero : exp x ≠ 0 := fun h =>
exp_ne_zero x <| by rw [exp, ← ofReal_inj] at h; simp_all
nonrec theorem exp_neg : exp (-x) = (exp x)⁻¹ :=
ofReal_injective <| by simp [exp_neg]
theorem exp_sub : exp (x - y) = exp x / exp y := by
simp [sub_eq_add_neg, exp_add, exp_neg, div_eq_mul_inv]
open IsAbsoluteValue Nat
theorem sum_le_exp_of_nonneg {x : ℝ} (hx : 0 ≤ x) (n : ℕ) : ∑ i ∈ range n, x ^ i / i ! ≤ exp x :=
calc
∑ i ∈ range n, x ^ i / i ! ≤ lim (⟨_, isCauSeq_re (exp' x)⟩ : CauSeq ℝ abs) := by
refine le_lim (CauSeq.le_of_exists ⟨n, fun j hj => ?_⟩)
simp only [exp', const_apply, re_sum]
norm_cast
refine sum_le_sum_of_subset_of_nonneg (range_mono hj) fun _ _ _ ↦ ?_
positivity
_ = exp x := by rw [exp, Complex.exp, ← cauSeqRe, lim_re]
lemma pow_div_factorial_le_exp (hx : 0 ≤ x) (n : ℕ) : x ^ n / n ! ≤ exp x :=
calc
x ^ n / n ! ≤ ∑ k ∈ range (n + 1), x ^ k / k ! :=
single_le_sum (f := fun k ↦ x ^ k / k !) (fun k _ ↦ by positivity) (self_mem_range_succ n)
_ ≤ exp x := sum_le_exp_of_nonneg hx _
theorem quadratic_le_exp_of_nonneg {x : ℝ} (hx : 0 ≤ x) : 1 + x + x ^ 2 / 2 ≤ exp x :=
calc
1 + x + x ^ 2 / 2 = ∑ i ∈ range 3, x ^ i / i ! := by
simp only [sum_range_succ, range_one, sum_singleton, _root_.pow_zero, factorial, cast_one,
ne_eq, one_ne_zero, not_false_eq_true, div_self, pow_one, mul_one, div_one, Nat.mul_one,
cast_succ, add_right_inj]
ring_nf
_ ≤ exp x := sum_le_exp_of_nonneg hx 3
private theorem add_one_lt_exp_of_pos {x : ℝ} (hx : 0 < x) : x + 1 < exp x :=
(by nlinarith : x + 1 < 1 + x + x ^ 2 / 2).trans_le (quadratic_le_exp_of_nonneg hx.le)
private theorem add_one_le_exp_of_nonneg {x : ℝ} (hx : 0 ≤ x) : x + 1 ≤ exp x := by
rcases eq_or_lt_of_le hx with (rfl | h)
· simp
exact (add_one_lt_exp_of_pos h).le
theorem one_le_exp {x : ℝ} (hx : 0 ≤ x) : 1 ≤ exp x := by linarith [add_one_le_exp_of_nonneg hx]
@[bound]
theorem exp_pos (x : ℝ) : 0 < exp x :=
(le_total 0 x).elim (lt_of_lt_of_le zero_lt_one ∘ one_le_exp) fun h => by
rw [← neg_neg x, Real.exp_neg]
exact inv_pos.2 (lt_of_lt_of_le zero_lt_one (one_le_exp (neg_nonneg.2 h)))
@[bound]
lemma exp_nonneg (x : ℝ) : 0 ≤ exp x := x.exp_pos.le
@[simp]
theorem abs_exp (x : ℝ) : |exp x| = exp x :=
abs_of_pos (exp_pos _)
lemma exp_abs_le (x : ℝ) : exp |x| ≤ exp x + exp (-x) := by
cases le_total x 0 <;> simp [abs_of_nonpos, abs_of_nonneg, exp_nonneg, *]
@[mono]
theorem exp_strictMono : StrictMono exp := fun x y h => by
rw [← sub_add_cancel y x, Real.exp_add]
exact (lt_mul_iff_one_lt_left (exp_pos _)).2
(lt_of_lt_of_le (by linarith) (add_one_le_exp_of_nonneg (by linarith)))
@[gcongr]
theorem exp_lt_exp_of_lt {x y : ℝ} (h : x < y) : exp x < exp y := exp_strictMono h
@[mono]
theorem exp_monotone : Monotone exp :=
exp_strictMono.monotone
@[gcongr, bound]
theorem exp_le_exp_of_le {x y : ℝ} (h : x ≤ y) : exp x ≤ exp y := exp_monotone h
@[simp]
theorem exp_lt_exp {x y : ℝ} : exp x < exp y ↔ x < y :=
exp_strictMono.lt_iff_lt
@[simp]
theorem exp_le_exp {x y : ℝ} : exp x ≤ exp y ↔ x ≤ y :=
exp_strictMono.le_iff_le
theorem exp_injective : Function.Injective exp :=
exp_strictMono.injective
@[simp]
theorem exp_eq_exp {x y : ℝ} : exp x = exp y ↔ x = y :=
exp_injective.eq_iff
@[simp]
theorem exp_eq_one_iff : exp x = 1 ↔ x = 0 :=
exp_injective.eq_iff' exp_zero
@[simp]
theorem one_lt_exp_iff {x : ℝ} : 1 < exp x ↔ 0 < x := by rw [← exp_zero, exp_lt_exp]
@[bound] private alias ⟨_, Bound.one_lt_exp_of_pos⟩ := one_lt_exp_iff
@[simp]
theorem exp_lt_one_iff {x : ℝ} : exp x < 1 ↔ x < 0 := by rw [← exp_zero, exp_lt_exp]
@[simp]
theorem exp_le_one_iff {x : ℝ} : exp x ≤ 1 ↔ x ≤ 0 :=
exp_zero ▸ exp_le_exp
@[simp]
theorem one_le_exp_iff {x : ℝ} : 1 ≤ exp x ↔ 0 ≤ x :=
exp_zero ▸ exp_le_exp
end Real
namespace Complex
theorem sum_div_factorial_le {α : Type*} [Field α] [LinearOrder α] [IsStrictOrderedRing α]
(n j : ℕ) (hn : 0 < n) :
(∑ m ∈ range j with n ≤ m, (1 / m.factorial : α)) ≤ n.succ / (n.factorial * n) :=
calc
(∑ m ∈ range j with n ≤ m, (1 / m.factorial : α)) =
∑ m ∈ range (j - n), (1 / ((m + n).factorial : α)) := by
refine sum_nbij' (· - n) (· + n) ?_ ?_ ?_ ?_ ?_ <;>
simp +contextual [lt_tsub_iff_right, tsub_add_cancel_of_le]
_ ≤ ∑ m ∈ range (j - n), ((n.factorial : α) * (n.succ : α) ^ m)⁻¹ := by
simp_rw [one_div]
gcongr
rw [← Nat.cast_pow, ← Nat.cast_mul, Nat.cast_le, add_comm]
exact Nat.factorial_mul_pow_le_factorial
_ = (n.factorial : α)⁻¹ * ∑ m ∈ range (j - n), (n.succ : α)⁻¹ ^ m := by
simp [mul_inv, ← mul_sum, ← sum_mul, mul_comm, inv_pow]
_ = ((n.succ : α) - n.succ * (n.succ : α)⁻¹ ^ (j - n)) / (n.factorial * n) := by
have h₁ : (n.succ : α) ≠ 1 :=
@Nat.cast_one α _ ▸ mt Nat.cast_inj.1 (mt Nat.succ.inj (pos_iff_ne_zero.1 hn))
have h₂ : (n.succ : α) ≠ 0 := by positivity
have h₃ : (n.factorial * n : α) ≠ 0 := by positivity
have h₄ : (n.succ - 1 : α) = n := by simp
rw [geom_sum_inv h₁ h₂, eq_div_iff_mul_eq h₃, mul_comm _ (n.factorial * n : α),
← mul_assoc (n.factorial⁻¹ : α), ← mul_inv_rev, h₄, ← mul_assoc (n.factorial * n : α),
mul_comm (n : α) n.factorial, mul_inv_cancel₀ h₃, one_mul, mul_comm]
_ ≤ n.succ / (n.factorial * n : α) := by gcongr; apply sub_le_self; positivity
theorem exp_bound {x : ℂ} (hx : ‖x‖ ≤ 1) {n : ℕ} (hn : 0 < n) :
‖exp x - ∑ m ∈ range n, x ^ m / m.factorial‖ ≤
‖x‖ ^ n * ((n.succ : ℝ) * (n.factorial * n : ℝ)⁻¹) := by
rw [← lim_const (abv := norm) (∑ m ∈ range n, _), exp, sub_eq_add_neg,
← lim_neg, lim_add, ← lim_norm]
refine lim_le (CauSeq.le_of_exists ⟨n, fun j hj => ?_⟩)
simp_rw [← sub_eq_add_neg]
show
‖(∑ m ∈ range j, x ^ m / m.factorial) - ∑ m ∈ range n, x ^ m / m.factorial‖ ≤
‖x‖ ^ n * ((n.succ : ℝ) * (n.factorial * n : ℝ)⁻¹)
rw [sum_range_sub_sum_range hj]
calc
‖∑ m ∈ range j with n ≤ m, (x ^ m / m.factorial : ℂ)‖
= ‖∑ m ∈ range j with n ≤ m, (x ^ n * (x ^ (m - n) / m.factorial) : ℂ)‖ := by
refine congr_arg norm (sum_congr rfl fun m hm => ?_)
rw [mem_filter, mem_range] at hm
rw [← mul_div_assoc, ← pow_add, add_tsub_cancel_of_le hm.2]
_ ≤ ∑ m ∈ range j with n ≤ m, ‖x ^ n * (x ^ (m - n) / m.factorial)‖ :=
IsAbsoluteValue.abv_sum norm ..
_ ≤ ∑ m ∈ range j with n ≤ m, ‖x‖ ^ n * (1 / m.factorial) := by
simp_rw [Complex.norm_mul, Complex.norm_pow, Complex.norm_div, norm_natCast]
gcongr
rw [Complex.norm_pow]
exact pow_le_one₀ (norm_nonneg _) hx
_ = ‖x‖ ^ n * ∑ m ∈ range j with n ≤ m, (1 / m.factorial : ℝ) := by
simp [abs_mul, abv_pow abs, abs_div, ← mul_sum]
_ ≤ ‖x‖ ^ n * (n.succ * (n.factorial * n : ℝ)⁻¹) := by
gcongr
exact sum_div_factorial_le _ _ hn
theorem exp_bound' {x : ℂ} {n : ℕ} (hx : ‖x‖ / n.succ ≤ 1 / 2) :
‖exp x - ∑ m ∈ range n, x ^ m / m.factorial‖ ≤ ‖x‖ ^ n / n.factorial * 2 := by
rw [← lim_const (abv := norm) (∑ m ∈ range n, _),
exp, sub_eq_add_neg, ← lim_neg, lim_add, ← lim_norm]
refine lim_le (CauSeq.le_of_exists ⟨n, fun j hj => ?_⟩)
simp_rw [← sub_eq_add_neg]
show ‖(∑ m ∈ range j, x ^ m / m.factorial) - ∑ m ∈ range n, x ^ m / m.factorial‖ ≤
‖x‖ ^ n / n.factorial * 2
let k := j - n
have hj : j = n + k := (add_tsub_cancel_of_le hj).symm
rw [hj, sum_range_add_sub_sum_range]
calc
‖∑ i ∈ range k, x ^ (n + i) / ((n + i).factorial : ℂ)‖ ≤
∑ i ∈ range k, ‖x ^ (n + i) / ((n + i).factorial : ℂ)‖ :=
IsAbsoluteValue.abv_sum _ _ _
_ ≤ ∑ i ∈ range k, ‖x‖ ^ (n + i) / (n + i).factorial := by
simp [norm_natCast, Complex.norm_pow]
_ ≤ ∑ i ∈ range k, ‖x‖ ^ (n + i) / ((n.factorial : ℝ) * (n.succ : ℝ) ^ i) := ?_
_ = ∑ i ∈ range k, ‖x‖ ^ n / n.factorial * (‖x‖ ^ i / (n.succ : ℝ) ^ i) := ?_
_ ≤ ‖x‖ ^ n / ↑n.factorial * 2 := ?_
· gcongr
exact mod_cast Nat.factorial_mul_pow_le_factorial
· refine Finset.sum_congr rfl fun _ _ => ?_
simp only [pow_add, div_eq_inv_mul, mul_inv, mul_left_comm, mul_assoc]
· rw [← mul_sum]
gcongr
simp_rw [← div_pow]
rw [geom_sum_eq, div_le_iff_of_neg]
· trans (-1 : ℝ)
· linarith
· simp only [neg_le_sub_iff_le_add, div_pow, Nat.cast_succ, le_add_iff_nonneg_left]
positivity
· linarith
· linarith
theorem norm_exp_sub_one_le {x : ℂ} (hx : ‖x‖ ≤ 1) : ‖exp x - 1‖ ≤ 2 * ‖x‖ :=
calc
‖exp x - 1‖ = ‖exp x - ∑ m ∈ range 1, x ^ m / m.factorial‖ := by simp [sum_range_succ]
_ ≤ ‖x‖ ^ 1 * ((Nat.succ 1 : ℝ) * ((Nat.factorial 1) * (1 : ℕ) : ℝ)⁻¹) :=
(exp_bound hx (by decide))
_ = 2 * ‖x‖ := by simp [two_mul, mul_two, mul_add, mul_comm, add_mul, Nat.factorial]
theorem norm_exp_sub_one_sub_id_le {x : ℂ} (hx : ‖x‖ ≤ 1) : ‖exp x - 1 - x‖ ≤ ‖x‖ ^ 2 :=
calc
‖exp x - 1 - x‖ = ‖exp x - ∑ m ∈ range 2, x ^ m / m.factorial‖ := by
simp [sub_eq_add_neg, sum_range_succ_comm, add_assoc, Nat.factorial]
_ ≤ ‖x‖ ^ 2 * ((Nat.succ 2 : ℝ) * (Nat.factorial 2 * (2 : ℕ) : ℝ)⁻¹) :=
(exp_bound hx (by decide))
_ ≤ ‖x‖ ^ 2 * 1 := by gcongr; norm_num [Nat.factorial]
_ = ‖x‖ ^ 2 := by rw [mul_one]
lemma norm_exp_sub_sum_le_exp_norm_sub_sum (x : ℂ) (n : ℕ) :
‖exp x - ∑ m ∈ range n, x ^ m / m.factorial‖
≤ Real.exp ‖x‖ - ∑ m ∈ range n, ‖x‖ ^ m / m.factorial := by
rw [← CauSeq.lim_const (abv := norm) (∑ m ∈ range n, _), Complex.exp, sub_eq_add_neg,
← CauSeq.lim_neg, CauSeq.lim_add, ← lim_norm]
refine CauSeq.lim_le (CauSeq.le_of_exists ⟨n, fun j hj => ?_⟩)
simp_rw [← sub_eq_add_neg]
calc ‖(∑ m ∈ range j, x ^ m / m.factorial) - ∑ m ∈ range n, x ^ m / m.factorial‖
_ ≤ (∑ m ∈ range j, ‖x‖ ^ m / m.factorial) - ∑ m ∈ range n, ‖x‖ ^ m / m.factorial := by
rw [sum_range_sub_sum_range hj, sum_range_sub_sum_range hj]
refine (IsAbsoluteValue.abv_sum norm ..).trans_eq ?_
congr with i
simp [Complex.norm_pow]
_ ≤ Real.exp ‖x‖ - ∑ m ∈ range n, ‖x‖ ^ m / m.factorial := by
gcongr
exact Real.sum_le_exp_of_nonneg (norm_nonneg _) _
lemma norm_exp_le_exp_norm (x : ℂ) : ‖exp x‖ ≤ Real.exp ‖x‖ := by
convert norm_exp_sub_sum_le_exp_norm_sub_sum x 0 using 1 <;> simp
lemma norm_exp_sub_sum_le_norm_mul_exp (x : ℂ) (n : ℕ) :
‖exp x - ∑ m ∈ range n, x ^ m / m.factorial‖ ≤ ‖x‖ ^ n * Real.exp ‖x‖ := by
rw [← CauSeq.lim_const (abv := norm) (∑ m ∈ range n, _), Complex.exp, sub_eq_add_neg,
← CauSeq.lim_neg, CauSeq.lim_add, ← lim_norm]
refine CauSeq.lim_le (CauSeq.le_of_exists ⟨n, fun j hj => ?_⟩)
simp_rw [← sub_eq_add_neg]
show ‖(∑ m ∈ range j, x ^ m / m.factorial) - ∑ m ∈ range n, x ^ m / m.factorial‖ ≤ _
rw [sum_range_sub_sum_range hj]
calc
‖∑ m ∈ range j with n ≤ m, (x ^ m / m.factorial : ℂ)‖
= ‖∑ m ∈ range j with n ≤ m, (x ^ n * (x ^ (m - n) / m.factorial) : ℂ)‖ := by
refine congr_arg norm (sum_congr rfl fun m hm => ?_)
rw [mem_filter, mem_range] at hm
rw [← mul_div_assoc, ← pow_add, add_tsub_cancel_of_le hm.2]
_ ≤ ∑ m ∈ range j with n ≤ m, ‖x ^ n * (x ^ (m - n) / m.factorial)‖ :=
IsAbsoluteValue.abv_sum norm ..
_ ≤ ∑ m ∈ range j with n ≤ m, ‖x‖ ^ n * (‖x‖ ^ (m - n) / (m - n).factorial) := by
simp_rw [Complex.norm_mul, Complex.norm_pow, Complex.norm_div, norm_natCast]
gcongr with i hi
· rw [Complex.norm_pow]
· simp
_ = ‖x‖ ^ n * ∑ m ∈ range j with n ≤ m, (‖x‖ ^ (m - n) / (m - n).factorial) := by
rw [← mul_sum]
_ = ‖x‖ ^ n * ∑ m ∈ range (j - n), (‖x‖ ^ m / m.factorial) := by
congr 1
refine (sum_bij (fun m hm ↦ m + n) ?_ ?_ ?_ ?_).symm
· intro a ha
simp only [mem_filter, mem_range, le_add_iff_nonneg_left, zero_le, and_true]
simp only [mem_range] at ha
rwa [← lt_tsub_iff_right]
· intro a ha b hb hab
simpa using hab
· intro b hb
simp only [mem_range, exists_prop]
simp only [mem_filter, mem_range] at hb
refine ⟨b - n, ?_, ?_⟩
· rw [tsub_lt_tsub_iff_right hb.2]
exact hb.1
· rw [tsub_add_cancel_of_le hb.2]
· simp
_ ≤ ‖x‖ ^ n * Real.exp ‖x‖ := by
gcongr
refine Real.sum_le_exp_of_nonneg ?_ _
exact norm_nonneg _
@[deprecated (since := "2025-02-16")] alias abs_exp_sub_one_le := norm_exp_sub_one_le
@[deprecated (since := "2025-02-16")] alias abs_exp_sub_one_sub_id_le := norm_exp_sub_one_sub_id_le
@[deprecated (since := "2025-02-16")] alias abs_exp_sub_sum_le_exp_abs_sub_sum :=
norm_exp_sub_sum_le_exp_norm_sub_sum
@[deprecated (since := "2025-02-16")] alias abs_exp_le_exp_abs := norm_exp_le_exp_norm
@[deprecated (since := "2025-02-16")] alias abs_exp_sub_sum_le_abs_mul_exp :=
norm_exp_sub_sum_le_norm_mul_exp
end Complex
namespace Real
open Complex Finset
nonrec theorem exp_bound {x : ℝ} (hx : |x| ≤ 1) {n : ℕ} (hn : 0 < n) :
|exp x - ∑ m ∈ range n, x ^ m / m.factorial| ≤ |x| ^ n * (n.succ / (n.factorial * n)) := by
have hxc : ‖(x : ℂ)‖ ≤ 1 := mod_cast hx
convert exp_bound hxc hn using 2 <;>
norm_cast
theorem exp_bound' {x : ℝ} (h1 : 0 ≤ x) (h2 : x ≤ 1) {n : ℕ} (hn : 0 < n) :
Real.exp x ≤ (∑ m ∈ Finset.range n, x ^ m / m.factorial) +
x ^ n * (n + 1) / (n.factorial * n) := by
have h3 : |x| = x := by simpa
have h4 : |x| ≤ 1 := by rwa [h3]
have h' := Real.exp_bound h4 hn
rw [h3] at h'
have h'' := (abs_sub_le_iff.1 h').1
have t := sub_le_iff_le_add'.1 h''
simpa [mul_div_assoc] using t
theorem abs_exp_sub_one_le {x : ℝ} (hx : |x| ≤ 1) : |exp x - 1| ≤ 2 * |x| := by
have : ‖(x : ℂ)‖ ≤ 1 := mod_cast hx
exact_mod_cast Complex.norm_exp_sub_one_le (x := x) this
theorem abs_exp_sub_one_sub_id_le {x : ℝ} (hx : |x| ≤ 1) : |exp x - 1 - x| ≤ x ^ 2 := by
rw [← sq_abs]
have : ‖(x : ℂ)‖ ≤ 1 := mod_cast hx
exact_mod_cast Complex.norm_exp_sub_one_sub_id_le this
/-- A finite initial segment of the exponential series, followed by an arbitrary tail.
For fixed `n` this is just a linear map wrt `r`, and each map is a simple linear function
of the previous (see `expNear_succ`), with `expNear n x r ⟶ exp x` as `n ⟶ ∞`,
for any `r`. -/
noncomputable def expNear (n : ℕ) (x r : ℝ) : ℝ :=
(∑ m ∈ range n, x ^ m / m.factorial) + x ^ n / n.factorial * r
@[simp]
theorem expNear_zero (x r) : expNear 0 x r = r := by simp [expNear]
@[simp]
theorem expNear_succ (n x r) : expNear (n + 1) x r = expNear n x (1 + x / (n + 1) * r) := by
simp [expNear, range_succ, mul_add, add_left_comm, add_assoc, pow_succ, div_eq_mul_inv,
mul_inv, Nat.factorial]
ac_rfl
theorem expNear_sub (n x r₁ r₂) : expNear n x r₁ -
expNear n x r₂ = x ^ n / n.factorial * (r₁ - r₂) := by
simp [expNear, mul_sub]
theorem exp_approx_end (n m : ℕ) (x : ℝ) (e₁ : n + 1 = m) (h : |x| ≤ 1) :
|exp x - expNear m x 0| ≤ |x| ^ m / m.factorial * ((m + 1) / m) := by
simp only [expNear, mul_zero, add_zero]
convert exp_bound (n := m) h ?_ using 1
· field_simp [mul_comm]
· omega
theorem exp_approx_succ {n} {x a₁ b₁ : ℝ} (m : ℕ) (e₁ : n + 1 = m) (a₂ b₂ : ℝ)
(e : |1 + x / m * a₂ - a₁| ≤ b₁ - |x| / m * b₂)
(h : |exp x - expNear m x a₂| ≤ |x| ^ m / m.factorial * b₂) :
|exp x - expNear n x a₁| ≤ |x| ^ n / n.factorial * b₁ := by
refine (abs_sub_le _ _ _).trans ((add_le_add_right h _).trans ?_)
subst e₁; rw [expNear_succ, expNear_sub, abs_mul]
convert mul_le_mul_of_nonneg_left (a := |x| ^ n / ↑(Nat.factorial n))
(le_sub_iff_add_le'.1 e) ?_ using 1
· simp [mul_add, pow_succ', div_eq_mul_inv, abs_mul, abs_inv, ← pow_abs, mul_inv, Nat.factorial]
ac_rfl
· simp [div_nonneg, abs_nonneg]
theorem exp_approx_end' {n} {x a b : ℝ} (m : ℕ) (e₁ : n + 1 = m) (rm : ℝ) (er : ↑m = rm)
(h : |x| ≤ 1) (e : |1 - a| ≤ b - |x| / rm * ((rm + 1) / rm)) :
|exp x - expNear n x a| ≤ |x| ^ n / n.factorial * b := by
subst er
exact exp_approx_succ _ e₁ _ _ (by simpa using e) (exp_approx_end _ _ _ e₁ h)
theorem exp_1_approx_succ_eq {n} {a₁ b₁ : ℝ} {m : ℕ} (en : n + 1 = m) {rm : ℝ} (er : ↑m = rm)
(h : |exp 1 - expNear m 1 ((a₁ - 1) * rm)| ≤ |1| ^ m / m.factorial * (b₁ * rm)) :
|exp 1 - expNear n 1 a₁| ≤ |1| ^ n / n.factorial * b₁ := by
subst er
refine exp_approx_succ _ en _ _ ?_ h
field_simp [show (m : ℝ) ≠ 0 by norm_cast; omega]
theorem exp_approx_start (x a b : ℝ) (h : |exp x - expNear 0 x a| ≤ |x| ^ 0 / Nat.factorial 0 * b) :
|exp x - a| ≤ b := by simpa using h
theorem exp_bound_div_one_sub_of_interval' {x : ℝ} (h1 : 0 < x) (h2 : x < 1) :
Real.exp x < 1 / (1 - x) := by
have H : 0 < 1 - (1 + x + x ^ 2) * (1 - x) := calc
0 < x ^ 3 := by positivity
_ = 1 - (1 + x + x ^ 2) * (1 - x) := by ring
calc
exp x ≤ _ := exp_bound' h1.le h2.le zero_lt_three
_ ≤ 1 + x + x ^ 2 := by
-- Porting note: was `norm_num [Finset.sum] <;> nlinarith`
-- This proof should be restored after the norm_num plugin for big operators is ported.
-- (It may also need the positivity extensions in https://github.com/leanprover-community/mathlib4/pull/3907.)
rw [show 3 = 1 + 1 + 1 from rfl]
repeat rw [Finset.sum_range_succ]
norm_num [Nat.factorial]
nlinarith
_ < 1 / (1 - x) := by rw [lt_div_iff₀] <;> nlinarith
theorem exp_bound_div_one_sub_of_interval {x : ℝ} (h1 : 0 ≤ x) (h2 : x < 1) :
Real.exp x ≤ 1 / (1 - x) := by
rcases eq_or_lt_of_le h1 with (rfl | h1)
· simp
· exact (exp_bound_div_one_sub_of_interval' h1 h2).le
theorem add_one_lt_exp {x : ℝ} (hx : x ≠ 0) : x + 1 < Real.exp x := by
obtain hx | hx := hx.symm.lt_or_lt
· exact add_one_lt_exp_of_pos hx
obtain h' | h' := le_or_lt 1 (-x)
· linarith [x.exp_pos]
have hx' : 0 < x + 1 := by linarith
simpa [add_comm, exp_neg, inv_lt_inv₀ (exp_pos _) hx']
using exp_bound_div_one_sub_of_interval' (neg_pos.2 hx) h'
theorem add_one_le_exp (x : ℝ) : x + 1 ≤ Real.exp x := by
obtain rfl | hx := eq_or_ne x 0
· simp
· exact (add_one_lt_exp hx).le
lemma one_sub_lt_exp_neg {x : ℝ} (hx : x ≠ 0) : 1 - x < exp (-x) :=
(sub_eq_neg_add _ _).trans_lt <| add_one_lt_exp <| neg_ne_zero.2 hx
lemma one_sub_le_exp_neg (x : ℝ) : 1 - x ≤ exp (-x) :=
(sub_eq_neg_add _ _).trans_le <| add_one_le_exp _
theorem one_sub_div_pow_le_exp_neg {n : ℕ} {t : ℝ} (ht' : t ≤ n) : (1 - t / n) ^ n ≤ exp (-t) := by
rcases eq_or_ne n 0 with (rfl | hn)
· simp
rwa [Nat.cast_zero] at ht'
calc
(1 - t / n) ^ n ≤ rexp (-(t / n)) ^ n := by
gcongr
· exact sub_nonneg.2 <| div_le_one_of_le₀ ht' n.cast_nonneg
· exact one_sub_le_exp_neg _
_ = rexp (-t) := by rw [← Real.exp_nat_mul, mul_neg, mul_comm, div_mul_cancel₀]; positivity
lemma le_inv_mul_exp (x : ℝ) {c : ℝ} (hc : 0 < c) : x ≤ c⁻¹ * exp (c * x) := by
rw [le_inv_mul_iff₀ hc]
calc c * x
_ ≤ c * x + 1 := le_add_of_nonneg_right zero_le_one
_ ≤ _ := Real.add_one_le_exp (c * x)
end Real
namespace Mathlib.Meta.Positivity
open Lean.Meta Qq
/-- Extension for the `positivity` tactic: `Real.exp` is always positive. -/
@[positivity Real.exp _]
def evalExp : PositivityExt where eval {u α} _ _ e := do
match u, α, e with
| 0, ~q(ℝ), ~q(Real.exp $a) =>
assertInstancesCommute
pure (.positive q(Real.exp_pos $a))
| _, _, _ => throwError "not Real.exp"
end Mathlib.Meta.Positivity
namespace Complex
@[simp]
theorem norm_exp_ofReal (x : ℝ) : ‖exp x‖ = Real.exp x := by
rw [← ofReal_exp]
exact Complex.norm_of_nonneg (le_of_lt (Real.exp_pos _))
@[deprecated (since := "2025-02-16")] alias abs_exp_ofReal := norm_exp_ofReal
| end Complex
| Mathlib/Data/Complex/Exponential.lean | 694 | 694 |
/-
Copyright (c) 2021 Julian Kuelshammer. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Julian Kuelshammer
-/
import Mathlib.GroupTheory.OrderOfElement
import Mathlib.Algebra.GCDMonoid.Finset
import Mathlib.Algebra.GCDMonoid.Nat
import Mathlib.Data.Nat.Factorization.Basic
import Mathlib.Tactic.Peel
import Mathlib.Algebra.Order.BigOperators.Ring.Finset
/-!
# Exponent of a group
This file defines the exponent of a group, or more generally a monoid. For a group `G` it is defined
to be the minimal `n≥1` such that `g ^ n = 1` for all `g ∈ G`. For a finite group `G`,
it is equal to the lowest common multiple of the order of all elements of the group `G`.
## Main definitions
* `Monoid.ExponentExists` is a predicate on a monoid `G` saying that there is some positive `n`
such that `g ^ n = 1` for all `g ∈ G`.
* `Monoid.exponent` defines the exponent of a monoid `G` as the minimal positive `n` such that
`g ^ n = 1` for all `g ∈ G`, by convention it is `0` if no such `n` exists.
* `AddMonoid.ExponentExists` the additive version of `Monoid.ExponentExists`.
* `AddMonoid.exponent` the additive version of `Monoid.exponent`.
## Main results
* `Monoid.lcm_order_eq_exponent`: For a finite left cancel monoid `G`, the exponent is equal to the
`Finset.lcm` of the order of its elements.
* `Monoid.exponent_eq_iSup_orderOf(')`: For a commutative cancel monoid, the exponent is
equal to `⨆ g : G, orderOf g` (or zero if it has any order-zero elements).
* `Monoid.exponent_pi` and `Monoid.exponent_prod`: The exponent of a finite product of monoids is
the least common multiple (`Finset.lcm` and `lcm`, respectively) of the exponents of the
constituent monoids.
* `MonoidHom.exponent_dvd`: If `f : M₁ →⋆ M₂` is surjective, then the exponent of `M₂` divides the
exponent of `M₁`.
## TODO
* Refactor the characteristic of a ring to be the exponent of its underlying additive group.
-/
universe u
variable {G : Type u}
namespace Monoid
section Monoid
variable (G) [Monoid G]
/-- A predicate on a monoid saying that there is a positive integer `n` such that `g ^ n = 1`
for all `g`. -/
@[to_additive
"A predicate on an additive monoid saying that there is a positive integer `n` such\n
that `n • g = 0` for all `g`."]
def ExponentExists :=
∃ n, 0 < n ∧ ∀ g : G, g ^ n = 1
open scoped Classical in
/-- The exponent of a group is the smallest positive integer `n` such that `g ^ n = 1` for all
`g ∈ G` if it exists, otherwise it is zero by convention. -/
@[to_additive
"The exponent of an additive group is the smallest positive integer `n` such that\n
`n • g = 0` for all `g ∈ G` if it exists, otherwise it is zero by convention."]
noncomputable def exponent :=
if h : ExponentExists G then Nat.find h else 0
variable {G}
@[simp]
theorem _root_.AddMonoid.exponent_additive :
AddMonoid.exponent (Additive G) = exponent G := rfl
@[simp]
theorem exponent_multiplicative {G : Type*} [AddMonoid G] :
exponent (Multiplicative G) = AddMonoid.exponent G := rfl
open MulOpposite in
@[to_additive (attr := simp)]
theorem _root_.MulOpposite.exponent : exponent (MulOpposite G) = exponent G := by
simp only [Monoid.exponent, ExponentExists]
congr!
all_goals exact ⟨(op_injective <| · <| op ·), (unop_injective <| · <| unop ·)⟩
@[to_additive]
theorem ExponentExists.isOfFinOrder (h : ExponentExists G) {g : G} : IsOfFinOrder g :=
isOfFinOrder_iff_pow_eq_one.mpr <| by peel 2 h; exact this g
@[to_additive]
theorem ExponentExists.orderOf_pos (h : ExponentExists G) (g : G) : 0 < orderOf g :=
h.isOfFinOrder.orderOf_pos
@[to_additive]
theorem exponent_ne_zero : exponent G ≠ 0 ↔ ExponentExists G := by
rw [exponent]
split_ifs with h
· simp [h, @not_lt_zero' ℕ]
--if this isn't done this way, `to_additive` freaks
· tauto
| @[to_additive]
protected alias ⟨_, ExponentExists.exponent_ne_zero⟩ := exponent_ne_zero
@[to_additive]
theorem exponent_pos : 0 < exponent G ↔ ExponentExists G :=
pos_iff_ne_zero.trans exponent_ne_zero
| Mathlib/GroupTheory/Exponent.lean | 106 | 111 |
/-
Copyright (c) 2023 Kim Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kim Morrison, Joël Riou
-/
import Mathlib.Algebra.Category.ModuleCat.ChangeOfRings
import Mathlib.Algebra.Category.Ring.Basic
/-!
# Presheaves of modules over a presheaf of rings.
Given a presheaf of rings `R : Cᵒᵖ ⥤ RingCat`, we define the category `PresheafOfModules R`.
An object `M : PresheafOfModules R` consists of a family of modules
`M.obj X : ModuleCat (R.obj X)` for all `X : Cᵒᵖ`, together with the data, for all `f : X ⟶ Y`,
of a functorial linear map `M.map f` from `M.obj X` to the restriction
of scalars of `M.obj Y` via `R.map f`.
## Future work
* Compare this to the definition as a presheaf of pairs `(R, M)` with specified first part.
* Compare this to the definition as a module object of the presheaf of rings
thought of as a monoid object.
* Presheaves of modules over a presheaf of commutative rings form a monoidal category.
* Pushforward and pullback.
-/
universe v v₁ u₁ u
open CategoryTheory LinearMap Opposite
variable {C : Type u₁} [Category.{v₁} C] {R : Cᵒᵖ ⥤ RingCat.{u}}
variable (R) in
/-- A presheaf of modules over `R : Cᵒᵖ ⥤ RingCat` consists of family of
objects `obj X : ModuleCat (R.obj X)` for all `X : Cᵒᵖ` together with
functorial maps `obj X ⟶ (ModuleCat.restrictScalars (R.map f)).obj (obj Y)`
for all `f : X ⟶ Y` in `Cᵒᵖ`. -/
structure PresheafOfModules where
/-- a family of modules over `R.obj X` for all `X` -/
obj (X : Cᵒᵖ) : ModuleCat.{v} (R.obj X)
/-- the restriction maps of a presheaf of modules -/
map {X Y : Cᵒᵖ} (f : X ⟶ Y) : obj X ⟶ (ModuleCat.restrictScalars (R.map f).hom).obj (obj Y)
map_id (X : Cᵒᵖ) :
map (𝟙 X) = (ModuleCat.restrictScalarsId' (R.map (𝟙 X)).hom
(congrArg RingCat.Hom.hom (R.map_id X))).inv.app _ := by
aesop_cat
map_comp {X Y Z : Cᵒᵖ} (f : X ⟶ Y) (g : Y ⟶ Z) :
map (f ≫ g) = map f ≫ (ModuleCat.restrictScalars _).map (map g) ≫
(ModuleCat.restrictScalarsComp' (R.map f).hom (R.map g).hom (R.map (f ≫ g)).hom
(congrArg RingCat.Hom.hom <| R.map_comp f g)).inv.app _ := by aesop_cat
namespace PresheafOfModules
attribute [simp] map_id map_comp
attribute [reassoc] map_comp
variable (M M₁ M₂ : PresheafOfModules.{v} R)
protected lemma map_smul {X Y : Cᵒᵖ} (f : X ⟶ Y) (r : R.obj X) (m : M.obj X) :
M.map f (r • m) = R.map f r • M.map f m := by simp
lemma congr_map_apply {X Y : Cᵒᵖ} {f g : X ⟶ Y} (h : f = g) (m : M.obj X) :
M.map f m = M.map g m := by rw [h]
/-- A morphism of presheaves of modules consists of a family of linear maps which
satisfy the naturality condition. -/
@[ext]
structure Hom where
/-- a family of linear maps `M₁.obj X ⟶ M₂.obj X` for all `X`. -/
app (X : Cᵒᵖ) : M₁.obj X ⟶ M₂.obj X
naturality {X Y : Cᵒᵖ} (f : X ⟶ Y) :
M₁.map f ≫ (ModuleCat.restrictScalars (R.map f).hom).map (app Y) =
app X ≫ M₂.map f := by aesop_cat
attribute [reassoc (attr := simp)] Hom.naturality
instance : Category (PresheafOfModules.{v} R) where
Hom := Hom
id _ := { app := fun _ ↦ 𝟙 _ }
comp f g := { app := fun _ ↦ f.app _ ≫ g.app _ }
variable {M₁ M₂}
| @[ext]
lemma hom_ext {f g : M₁ ⟶ M₂} (h : ∀ (X : Cᵒᵖ), f.app X = g.app X) :
f = g := Hom.ext (by ext1; apply h)
| Mathlib/Algebra/Category/ModuleCat/Presheaf.lean | 85 | 88 |
/-
Copyright (c) 2021 Rémy Degenne. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Rémy Degenne
-/
import Mathlib.MeasureTheory.Function.ConditionalExpectation.CondexpL2
import Mathlib.MeasureTheory.Measure.Real
/-! # Conditional expectation in L1
This file contains two more steps of the construction of the conditional expectation, which is
completed in `MeasureTheory.Function.ConditionalExpectation.Basic`. See that file for a
description of the full process.
The conditional expectation of an `L²` function is defined in
`MeasureTheory.Function.ConditionalExpectation.CondexpL2`. In this file, we perform two steps.
* Show that the conditional expectation of the indicator of a measurable set with finite measure
is integrable and define a map `Set α → (E →L[ℝ] (α →₁[μ] E))` which to a set associates a linear
map. That linear map sends `x ∈ E` to the conditional expectation of the indicator of the set
with value `x`.
* Extend that map to `condExpL1CLM : (α →₁[μ] E) →L[ℝ] (α →₁[μ] E)`. This is done using the same
construction as the Bochner integral (see the file `MeasureTheory/Integral/SetToL1`).
## Main definitions
* `condExpL1`: Conditional expectation of a function as a linear map from `L1` to itself.
-/
noncomputable section
open TopologicalSpace MeasureTheory.Lp Filter ContinuousLinearMap
open scoped NNReal ENNReal Topology MeasureTheory
namespace MeasureTheory
variable {α F F' G G' 𝕜 : Type*} [RCLike 𝕜]
-- 𝕜 for ℝ or ℂ
-- F for a Lp submodule
[NormedAddCommGroup F]
[NormedSpace 𝕜 F]
-- F' for integrals on a Lp submodule
[NormedAddCommGroup F']
[NormedSpace 𝕜 F'] [NormedSpace ℝ F'] [CompleteSpace F']
-- G for a Lp add_subgroup
[NormedAddCommGroup G]
-- G' for integrals on a Lp add_subgroup
[NormedAddCommGroup G']
[NormedSpace ℝ G'] [CompleteSpace G']
section CondexpInd
/-! ## Conditional expectation of an indicator as a continuous linear map.
The goal of this section is to build
`condExpInd (hm : m ≤ m0) (μ : Measure α) (s : Set s) : G →L[ℝ] α →₁[μ] G`, which
takes `x : G` to the conditional expectation of the indicator of the set `s` with value `x`,
seen as an element of `α →₁[μ] G`.
-/
variable {m m0 : MeasurableSpace α} {μ : Measure α} {s t : Set α} [NormedSpace ℝ G]
section CondexpIndL1Fin
/-- Conditional expectation of the indicator of a measurable set with finite measure,
as a function in L1. -/
def condExpIndL1Fin (hm : m ≤ m0) [SigmaFinite (μ.trim hm)] (hs : MeasurableSet s) (hμs : μ s ≠ ∞)
(x : G) : α →₁[μ] G :=
(integrable_condExpIndSMul hm hs hμs x).toL1 _
@[deprecated (since := "2025-01-21")] noncomputable alias condexpIndL1Fin := condExpIndL1Fin
theorem condExpIndL1Fin_ae_eq_condExpIndSMul (hm : m ≤ m0) [SigmaFinite (μ.trim hm)]
(hs : MeasurableSet s) (hμs : μ s ≠ ∞) (x : G) :
condExpIndL1Fin hm hs hμs x =ᵐ[μ] condExpIndSMul hm hs hμs x :=
(integrable_condExpIndSMul hm hs hμs x).coeFn_toL1
@[deprecated (since := "2025-01-21")]
alias condexpIndL1Fin_ae_eq_condexpIndSMul := condExpIndL1Fin_ae_eq_condExpIndSMul
variable {hm : m ≤ m0} [SigmaFinite (μ.trim hm)]
-- Porting note: this lemma fills the hole in `refine' (MemLp.coeFn_toLp _) ...`
-- which is not automatically filled in Lean 4
private theorem q {hs : MeasurableSet s} {hμs : μ s ≠ ∞} {x : G} :
MemLp (condExpIndSMul hm hs hμs x) 1 μ := by
rw [memLp_one_iff_integrable]; apply integrable_condExpIndSMul
theorem condExpIndL1Fin_add (hs : MeasurableSet s) (hμs : μ s ≠ ∞) (x y : G) :
condExpIndL1Fin hm hs hμs (x + y) =
condExpIndL1Fin hm hs hμs x + condExpIndL1Fin hm hs hμs y := by
ext1
refine (MemLp.coeFn_toLp q).trans ?_
refine EventuallyEq.trans ?_ (Lp.coeFn_add _ _).symm
refine EventuallyEq.trans ?_
(EventuallyEq.add (MemLp.coeFn_toLp q).symm (MemLp.coeFn_toLp q).symm)
rw [condExpIndSMul_add]
refine (Lp.coeFn_add _ _).trans (Eventually.of_forall fun a => ?_)
rfl
@[deprecated (since := "2025-01-21")] alias condexpIndL1Fin_add := condExpIndL1Fin_add
theorem condExpIndL1Fin_smul (hs : MeasurableSet s) (hμs : μ s ≠ ∞) (c : ℝ) (x : G) :
condExpIndL1Fin hm hs hμs (c • x) = c • condExpIndL1Fin hm hs hμs x := by
ext1
refine (MemLp.coeFn_toLp q).trans ?_
refine EventuallyEq.trans ?_ (Lp.coeFn_smul _ _).symm
rw [condExpIndSMul_smul hs hμs c x]
refine (Lp.coeFn_smul _ _).trans ?_
refine (condExpIndL1Fin_ae_eq_condExpIndSMul hm hs hμs x).mono fun y hy => ?_
simp only [Pi.smul_apply, hy]
@[deprecated (since := "2025-01-21")] alias condexpIndL1Fin_smul := condExpIndL1Fin_smul
theorem condExpIndL1Fin_smul' [NormedSpace ℝ F] [SMulCommClass ℝ 𝕜 F] (hs : MeasurableSet s)
(hμs : μ s ≠ ∞) (c : 𝕜) (x : F) :
condExpIndL1Fin hm hs hμs (c • x) = c • condExpIndL1Fin hm hs hμs x := by
ext1
refine (MemLp.coeFn_toLp q).trans ?_
refine EventuallyEq.trans ?_ (Lp.coeFn_smul _ _).symm
rw [condExpIndSMul_smul' hs hμs c x]
refine (Lp.coeFn_smul _ _).trans ?_
refine (condExpIndL1Fin_ae_eq_condExpIndSMul hm hs hμs x).mono fun y hy => ?_
simp only [Pi.smul_apply, hy]
@[deprecated (since := "2025-01-21")] alias condexpIndL1Fin_smul' := condExpIndL1Fin_smul'
theorem norm_condExpIndL1Fin_le (hs : MeasurableSet s) (hμs : μ s ≠ ∞) (x : G) :
‖condExpIndL1Fin hm hs hμs x‖ ≤ μ.real s * ‖x‖ := by
rw [L1.norm_eq_integral_norm, ← ENNReal.toReal_ofReal (norm_nonneg x), measureReal_def,
← ENNReal.toReal_mul,
← ENNReal.ofReal_le_iff_le_toReal (ENNReal.mul_ne_top hμs ENNReal.ofReal_ne_top),
ofReal_integral_norm_eq_lintegral_enorm]
swap; · rw [← memLp_one_iff_integrable]; exact Lp.memLp _
have h_eq :
∫⁻ a, ‖condExpIndL1Fin hm hs hμs x a‖ₑ ∂μ = ∫⁻ a, ‖condExpIndSMul hm hs hμs x a‖ₑ ∂μ := by
refine lintegral_congr_ae ?_
refine (condExpIndL1Fin_ae_eq_condExpIndSMul hm hs hμs x).mono fun z hz => ?_
dsimp only
rw [hz]
rw [h_eq, ofReal_norm_eq_enorm]
exact lintegral_nnnorm_condExpIndSMul_le hm hs hμs x
@[deprecated (since := "2025-01-21")] alias norm_condexpIndL1Fin_le := norm_condExpIndL1Fin_le
theorem condExpIndL1Fin_disjoint_union (hs : MeasurableSet s) (ht : MeasurableSet t) (hμs : μ s ≠ ∞)
(hμt : μ t ≠ ∞) (hst : Disjoint s t) (x : G) :
condExpIndL1Fin hm (hs.union ht) ((measure_union_le s t).trans_lt
(lt_top_iff_ne_top.mpr (ENNReal.add_ne_top.mpr ⟨hμs, hμt⟩))).ne x =
condExpIndL1Fin hm hs hμs x + condExpIndL1Fin hm ht hμt x := by
ext1
have hμst := measure_union_ne_top hμs hμt
refine (condExpIndL1Fin_ae_eq_condExpIndSMul hm (hs.union ht) hμst x).trans ?_
refine EventuallyEq.trans ?_ (Lp.coeFn_add _ _).symm
have hs_eq := condExpIndL1Fin_ae_eq_condExpIndSMul hm hs hμs x
have ht_eq := condExpIndL1Fin_ae_eq_condExpIndSMul hm ht hμt x
refine EventuallyEq.trans ?_ (EventuallyEq.add hs_eq.symm ht_eq.symm)
rw [condExpIndSMul]
rw [indicatorConstLp_disjoint_union hs ht hμs hμt hst (1 : ℝ)]
rw [(condExpL2 ℝ ℝ hm).map_add]
push_cast
rw [((toSpanSingleton ℝ x).compLpL 2 μ).map_add]
refine (Lp.coeFn_add _ _).trans ?_
filter_upwards with y using rfl
@[deprecated (since := "2025-01-21")]
alias condexpIndL1Fin_disjoint_union := condExpIndL1Fin_disjoint_union
end CondexpIndL1Fin
section CondexpIndL1
open scoped Classical in
/-- Conditional expectation of the indicator of a set, as a function in L1. Its value for sets
which are not both measurable and of finite measure is not used: we set it to 0. -/
def condExpIndL1 {m m0 : MeasurableSpace α} (hm : m ≤ m0) (μ : Measure α) (s : Set α)
[SigmaFinite (μ.trim hm)] (x : G) : α →₁[μ] G :=
if hs : MeasurableSet s ∧ μ s ≠ ∞ then condExpIndL1Fin hm hs.1 hs.2 x else 0
@[deprecated (since := "2025-01-21")] noncomputable alias condexpIndL1 := condExpIndL1
variable {hm : m ≤ m0} [SigmaFinite (μ.trim hm)]
theorem condExpIndL1_of_measurableSet_of_measure_ne_top (hs : MeasurableSet s) (hμs : μ s ≠ ∞)
(x : G) : condExpIndL1 hm μ s x = condExpIndL1Fin hm hs hμs x := by
simp only [condExpIndL1, And.intro hs hμs, dif_pos, Ne, not_false_iff, and_self_iff]
@[deprecated (since := "2025-01-21")]
alias condexpIndL1_of_measurableSet_of_measure_ne_top :=
condExpIndL1_of_measurableSet_of_measure_ne_top
theorem condExpIndL1_of_measure_eq_top (hμs : μ s = ∞) (x : G) : condExpIndL1 hm μ s x = 0 := by
simp only [condExpIndL1, hμs, eq_self_iff_true, not_true, Ne, dif_neg, not_false_iff,
and_false]
@[deprecated (since := "2025-01-21")]
alias condexpIndL1_of_measure_eq_top := condExpIndL1_of_measure_eq_top
theorem condExpIndL1_of_not_measurableSet (hs : ¬MeasurableSet s) (x : G) :
condExpIndL1 hm μ s x = 0 := by
simp only [condExpIndL1, hs, dif_neg, not_false_iff, false_and]
@[deprecated (since := "2025-01-21")]
alias condexpIndL1_of_not_measurableSet := condExpIndL1_of_not_measurableSet
theorem condExpIndL1_add (x y : G) :
condExpIndL1 hm μ s (x + y) = condExpIndL1 hm μ s x + condExpIndL1 hm μ s y := by
by_cases hs : MeasurableSet s
swap; · simp_rw [condExpIndL1_of_not_measurableSet hs]; rw [zero_add]
by_cases hμs : μ s = ∞
· simp_rw [condExpIndL1_of_measure_eq_top hμs]; rw [zero_add]
· simp_rw [condExpIndL1_of_measurableSet_of_measure_ne_top hs hμs]
exact condExpIndL1Fin_add hs hμs x y
@[deprecated (since := "2025-01-21")] alias condexpIndL1_add := condExpIndL1_add
theorem condExpIndL1_smul (c : ℝ) (x : G) :
condExpIndL1 hm μ s (c • x) = c • condExpIndL1 hm μ s x := by
by_cases hs : MeasurableSet s
swap; · simp_rw [condExpIndL1_of_not_measurableSet hs]; rw [smul_zero]
by_cases hμs : μ s = ∞
· simp_rw [condExpIndL1_of_measure_eq_top hμs]; rw [smul_zero]
· simp_rw [condExpIndL1_of_measurableSet_of_measure_ne_top hs hμs]
exact condExpIndL1Fin_smul hs hμs c x
@[deprecated (since := "2025-01-21")] alias condexpIndL1_smul := condExpIndL1_smul
theorem condExpIndL1_smul' [NormedSpace ℝ F] [SMulCommClass ℝ 𝕜 F] (c : 𝕜) (x : F) :
condExpIndL1 hm μ s (c • x) = c • condExpIndL1 hm μ s x := by
by_cases hs : MeasurableSet s
swap; · simp_rw [condExpIndL1_of_not_measurableSet hs]; rw [smul_zero]
by_cases hμs : μ s = ∞
· simp_rw [condExpIndL1_of_measure_eq_top hμs]; rw [smul_zero]
· simp_rw [condExpIndL1_of_measurableSet_of_measure_ne_top hs hμs]
exact condExpIndL1Fin_smul' hs hμs c x
@[deprecated (since := "2025-01-21")] alias condexpIndL1_smul' := condExpIndL1_smul'
theorem norm_condExpIndL1_le (x : G) : ‖condExpIndL1 hm μ s x‖ ≤ μ.real s * ‖x‖ := by
by_cases hs : MeasurableSet s
swap
· simp_rw [condExpIndL1_of_not_measurableSet hs]; rw [Lp.norm_zero]
exact mul_nonneg ENNReal.toReal_nonneg (norm_nonneg _)
by_cases hμs : μ s = ∞
· rw [condExpIndL1_of_measure_eq_top hμs x, Lp.norm_zero]
exact mul_nonneg ENNReal.toReal_nonneg (norm_nonneg _)
· rw [condExpIndL1_of_measurableSet_of_measure_ne_top hs hμs x]
exact norm_condExpIndL1Fin_le hs hμs x
@[deprecated (since := "2025-01-21")] alias norm_condexpIndL1_le := norm_condExpIndL1_le
theorem continuous_condExpIndL1 : Continuous fun x : G => condExpIndL1 hm μ s x :=
continuous_of_linear_of_bound condExpIndL1_add condExpIndL1_smul norm_condExpIndL1_le
@[deprecated (since := "2025-01-21")] alias continuous_condexpIndL1 := continuous_condExpIndL1
theorem condExpIndL1_disjoint_union (hs : MeasurableSet s) (ht : MeasurableSet t) (hμs : μ s ≠ ∞)
(hμt : μ t ≠ ∞) (hst : Disjoint s t) (x : G) :
condExpIndL1 hm μ (s ∪ t) x = condExpIndL1 hm μ s x + condExpIndL1 hm μ t x := by
have hμst : μ (s ∪ t) ≠ ∞ :=
((measure_union_le s t).trans_lt (lt_top_iff_ne_top.mpr (ENNReal.add_ne_top.mpr ⟨hμs, hμt⟩))).ne
rw [condExpIndL1_of_measurableSet_of_measure_ne_top hs hμs x,
condExpIndL1_of_measurableSet_of_measure_ne_top ht hμt x,
condExpIndL1_of_measurableSet_of_measure_ne_top (hs.union ht) hμst x]
exact condExpIndL1Fin_disjoint_union hs ht hμs hμt hst x
@[deprecated (since := "2025-01-21")]
alias condexpIndL1_disjoint_union := condExpIndL1_disjoint_union
end CondexpIndL1
variable (G)
/-- Conditional expectation of the indicator of a set, as a linear map from `G` to L1. -/
def condExpInd {m m0 : MeasurableSpace α} (hm : m ≤ m0) (μ : Measure α) [SigmaFinite (μ.trim hm)]
(s : Set α) : G →L[ℝ] α →₁[μ] G where
toFun := condExpIndL1 hm μ s
map_add' := condExpIndL1_add
map_smul' := condExpIndL1_smul
cont := continuous_condExpIndL1
@[deprecated (since := "2025-01-21")] noncomputable alias condexpInd := condExpInd
variable {G}
theorem condExpInd_ae_eq_condExpIndSMul (hm : m ≤ m0) [SigmaFinite (μ.trim hm)]
(hs : MeasurableSet s) (hμs : μ s ≠ ∞) (x : G) :
condExpInd G hm μ s x =ᵐ[μ] condExpIndSMul hm hs hμs x := by
refine EventuallyEq.trans ?_ (condExpIndL1Fin_ae_eq_condExpIndSMul hm hs hμs x)
simp [condExpInd, condExpIndL1, hs, hμs]
@[deprecated (since := "2025-01-21")]
alias condexpInd_ae_eq_condexpIndSMul := condExpInd_ae_eq_condExpIndSMul
variable {hm : m ≤ m0} [SigmaFinite (μ.trim hm)]
theorem aestronglyMeasurable_condExpInd (hs : MeasurableSet s) (hμs : μ s ≠ ∞) (x : G) :
AEStronglyMeasurable[m] (condExpInd G hm μ s x) μ :=
(aestronglyMeasurable_condExpIndSMul hm hs hμs x).congr
(condExpInd_ae_eq_condExpIndSMul hm hs hμs x).symm
@[deprecated (since := "2025-01-24")]
alias aestronglyMeasurable'_condExpInd := aestronglyMeasurable_condExpInd
@[deprecated (since := "2025-01-21")]
alias aestronglyMeasurable'_condexpInd := aestronglyMeasurable_condExpInd
@[simp]
theorem condExpInd_empty : condExpInd G hm μ ∅ = (0 : G →L[ℝ] α →₁[μ] G) := by
ext1 x
ext1
refine (condExpInd_ae_eq_condExpIndSMul hm MeasurableSet.empty (by simp) x).trans ?_
rw [condExpIndSMul_empty]
refine (Lp.coeFn_zero G 2 μ).trans ?_
refine EventuallyEq.trans ?_ (Lp.coeFn_zero G 1 μ).symm
rfl
@[deprecated (since := "2025-01-21")] alias condexpInd_empty := condExpInd_empty
theorem condExpInd_smul' [NormedSpace ℝ F] [SMulCommClass ℝ 𝕜 F] (c : 𝕜) (x : F) :
condExpInd F hm μ s (c • x) = c • condExpInd F hm μ s x :=
condExpIndL1_smul' c x
@[deprecated (since := "2025-01-21")] alias condexpInd_smul' := condExpInd_smul'
theorem norm_condExpInd_apply_le (x : G) : ‖condExpInd G hm μ s x‖ ≤ μ.real s * ‖x‖ :=
norm_condExpIndL1_le x
@[deprecated (since := "2025-01-21")] alias norm_condexpInd_apply_le := norm_condExpInd_apply_le
theorem norm_condExpInd_le : ‖(condExpInd G hm μ s : G →L[ℝ] α →₁[μ] G)‖ ≤ μ.real s :=
ContinuousLinearMap.opNorm_le_bound _ ENNReal.toReal_nonneg norm_condExpInd_apply_le
@[deprecated (since := "2025-01-21")] alias norm_condexpInd_le := norm_condExpInd_le
theorem condExpInd_disjoint_union_apply (hs : MeasurableSet s) (ht : MeasurableSet t)
(hμs : μ s ≠ ∞) (hμt : μ t ≠ ∞) (hst : Disjoint s t) (x : G) :
condExpInd G hm μ (s ∪ t) x = condExpInd G hm μ s x + condExpInd G hm μ t x :=
condExpIndL1_disjoint_union hs ht hμs hμt hst x
@[deprecated (since := "2025-01-21")]
alias condexpInd_disjoint_union_apply := condExpInd_disjoint_union_apply
theorem condExpInd_disjoint_union (hs : MeasurableSet s) (ht : MeasurableSet t) (hμs : μ s ≠ ∞)
(hμt : μ t ≠ ∞) (hst : Disjoint s t) : (condExpInd G hm μ (s ∪ t) : G →L[ℝ] α →₁[μ] G) =
condExpInd G hm μ s + condExpInd G hm μ t := by
ext1 x; push_cast; exact condExpInd_disjoint_union_apply hs ht hμs hμt hst x
@[deprecated (since := "2025-01-21")] alias condexpInd_disjoint_union := condExpInd_disjoint_union
variable (G)
theorem dominatedFinMeasAdditive_condExpInd (hm : m ≤ m0) (μ : Measure α)
[SigmaFinite (μ.trim hm)] :
DominatedFinMeasAdditive μ (condExpInd G hm μ : Set α → G →L[ℝ] α →₁[μ] G) 1 :=
⟨fun _ _ => condExpInd_disjoint_union, fun _ _ _ => norm_condExpInd_le.trans (one_mul _).symm.le⟩
@[deprecated (since := "2025-01-21")]
alias dominatedFinMeasAdditive_condexpInd := dominatedFinMeasAdditive_condExpInd
variable {G}
theorem setIntegral_condExpInd (hs : MeasurableSet[m] s) (ht : MeasurableSet t) (hμs : μ s ≠ ∞)
(hμt : μ t ≠ ∞) (x : G') : ∫ a in s, condExpInd G' hm μ t x a ∂μ = μ.real (t ∩ s) • x :=
calc
∫ a in s, condExpInd G' hm μ t x a ∂μ = ∫ a in s, condExpIndSMul hm ht hμt x a ∂μ :=
setIntegral_congr_ae (hm s hs)
((condExpInd_ae_eq_condExpIndSMul hm ht hμt x).mono fun _ hx _ => hx)
_ = μ.real (t ∩ s) • x := setIntegral_condExpIndSMul hs ht hμs hμt x
@[deprecated (since := "2025-01-21")] alias setIntegral_condexpInd := setIntegral_condExpInd
theorem condExpInd_of_measurable (hs : MeasurableSet[m] s) (hμs : μ s ≠ ∞) (c : G) :
condExpInd G hm μ s c = indicatorConstLp 1 (hm s hs) hμs c := by
ext1
refine EventuallyEq.trans ?_ indicatorConstLp_coeFn.symm
refine (condExpInd_ae_eq_condExpIndSMul hm (hm s hs) hμs c).trans ?_
refine (condExpIndSMul_ae_eq_smul hm (hm s hs) hμs c).trans ?_
rw [condExpL2_indicator_of_measurable hm hs hμs (1 : ℝ)]
refine (@indicatorConstLp_coeFn α _ _ 2 μ _ s (hm s hs) hμs (1 : ℝ)).mono fun x hx => ?_
dsimp only
rw [hx]
by_cases hx_mem : x ∈ s <;> simp [hx_mem]
@[deprecated (since := "2025-01-21")] alias condexpInd_of_measurable := condExpInd_of_measurable
theorem condExpInd_nonneg {E} [NormedAddCommGroup E] [PartialOrder E] [NormedSpace ℝ E]
[OrderedSMul ℝ E] (hs : MeasurableSet s) (hμs : μ s ≠ ∞) (x : E) (hx : 0 ≤ x) :
0 ≤ condExpInd E hm μ s x := by
rw [← coeFn_le]
refine EventuallyLE.trans_eq ?_ (condExpInd_ae_eq_condExpIndSMul hm hs hμs x).symm
exact (coeFn_zero E 1 μ).trans_le (condExpIndSMul_nonneg hs hμs x hx)
@[deprecated (since := "2025-01-21")] alias condexpInd_nonneg := condExpInd_nonneg
end CondexpInd
section CondexpL1
variable {m m0 : MeasurableSpace α} {μ : Measure α} {hm : m ≤ m0} [SigmaFinite (μ.trim hm)]
{f g : α → F'} {s : Set α}
variable (F')
/-- Conditional expectation of a function as a linear map from `α →₁[μ] F'` to itself. -/
def condExpL1CLM (hm : m ≤ m0) (μ : Measure α) [SigmaFinite (μ.trim hm)] :
(α →₁[μ] F') →L[ℝ] α →₁[μ] F' :=
L1.setToL1 (dominatedFinMeasAdditive_condExpInd F' hm μ)
@[deprecated (since := "2025-01-21")] noncomputable alias condexpL1CLM := condExpL1CLM
variable {F'}
theorem condExpL1CLM_smul (c : 𝕜) (f : α →₁[μ] F') :
condExpL1CLM F' hm μ (c • f) = c • condExpL1CLM F' hm μ f := by
refine L1.setToL1_smul (dominatedFinMeasAdditive_condExpInd F' hm μ) ?_ c f
exact fun c s x => condExpInd_smul' c x
@[deprecated (since := "2025-01-21")] alias condexpL1CLM_smul := condExpL1CLM_smul
theorem condExpL1CLM_indicatorConstLp (hs : MeasurableSet s) (hμs : μ s ≠ ∞) (x : F') :
(condExpL1CLM F' hm μ) (indicatorConstLp 1 hs hμs x) = condExpInd F' hm μ s x :=
L1.setToL1_indicatorConstLp (dominatedFinMeasAdditive_condExpInd F' hm μ) hs hμs x
@[deprecated (since := "2025-01-21")]
alias condexpL1CLM_indicatorConstLp := condExpL1CLM_indicatorConstLp
theorem condExpL1CLM_indicatorConst (hs : MeasurableSet s) (hμs : μ s ≠ ∞) (x : F') :
(condExpL1CLM F' hm μ) ↑(simpleFunc.indicatorConst 1 hs hμs x) = condExpInd F' hm μ s x := by
rw [Lp.simpleFunc.coe_indicatorConst]; exact condExpL1CLM_indicatorConstLp hs hμs x
@[deprecated (since := "2025-01-21")]
alias condexpL1CLM_indicatorConst := condExpL1CLM_indicatorConst
/-- Auxiliary lemma used in the proof of `setIntegral_condExpL1CLM`. -/
theorem setIntegral_condExpL1CLM_of_measure_ne_top (f : α →₁[μ] F') (hs : MeasurableSet[m] s)
(hμs : μ s ≠ ∞) : ∫ x in s, condExpL1CLM F' hm μ f x ∂μ = ∫ x in s, f x ∂μ := by
refine @Lp.induction _ _ _ _ _ _ _ ENNReal.one_ne_top
(fun f : α →₁[μ] F' => ∫ x in s, condExpL1CLM F' hm μ f x ∂μ = ∫ x in s, f x ∂μ) ?_ ?_
(isClosed_eq ?_ ?_) f
· intro x t ht hμt
simp_rw [condExpL1CLM_indicatorConst ht hμt.ne x]
rw [Lp.simpleFunc.coe_indicatorConst, setIntegral_indicatorConstLp (hm _ hs)]
exact setIntegral_condExpInd hs ht hμs hμt.ne x
· intro f g hf_Lp hg_Lp _ hf hg
simp_rw [(condExpL1CLM F' hm μ).map_add]
rw [setIntegral_congr_ae (hm s hs) ((Lp.coeFn_add (condExpL1CLM F' hm μ (hf_Lp.toLp f))
(condExpL1CLM F' hm μ (hg_Lp.toLp g))).mono fun x hx _ => hx)]
rw [setIntegral_congr_ae (hm s hs)
((Lp.coeFn_add (hf_Lp.toLp f) (hg_Lp.toLp g)).mono fun x hx _ => hx)]
simp_rw [Pi.add_apply]
rw [integral_add (L1.integrable_coeFn _).integrableOn (L1.integrable_coeFn _).integrableOn,
integral_add (L1.integrable_coeFn _).integrableOn (L1.integrable_coeFn _).integrableOn, hf,
hg]
· exact (continuous_setIntegral s).comp (condExpL1CLM F' hm μ).continuous
· exact continuous_setIntegral s
@[deprecated (since := "2025-01-21")]
alias setIntegral_condexpL1CLM_of_measure_ne_top := setIntegral_condExpL1CLM_of_measure_ne_top
/-- The integral of the conditional expectation `condExpL1CLM` over an `m`-measurable set is equal
to the integral of `f` on that set. See also `setIntegral_condExp`, the similar statement for
`condExp`. -/
theorem setIntegral_condExpL1CLM (f : α →₁[μ] F') (hs : MeasurableSet[m] s) :
∫ x in s, condExpL1CLM F' hm μ f x ∂μ = ∫ x in s, f x ∂μ := by
let S := spanningSets (μ.trim hm)
| have hS_meas : ∀ i, MeasurableSet[m] (S i) := measurableSet_spanningSets (μ.trim hm)
have hS_meas0 : ∀ i, MeasurableSet (S i) := fun i => hm _ (hS_meas i)
have hs_eq : s = ⋃ i, S i ∩ s := by
simp_rw [Set.inter_comm]
rw [← Set.inter_iUnion, iUnion_spanningSets (μ.trim hm), Set.inter_univ]
have hS_finite : ∀ i, μ (S i ∩ s) < ∞ := by
refine fun i => (measure_mono Set.inter_subset_left).trans_lt ?_
have hS_finite_trim := measure_spanningSets_lt_top (μ.trim hm) i
rwa [trim_measurableSet_eq hm (hS_meas i)] at hS_finite_trim
have h_mono : Monotone fun i => S i ∩ s := by
intro i j hij x
simp_rw [Set.mem_inter_iff]
exact fun h => ⟨monotone_spanningSets (μ.trim hm) hij h.1, h.2⟩
have h_eq_forall :
(fun i => ∫ x in S i ∩ s, condExpL1CLM F' hm μ f x ∂μ) = fun i => ∫ x in S i ∩ s, f x ∂μ :=
funext fun i =>
| Mathlib/MeasureTheory/Function/ConditionalExpectation/CondexpL1.lean | 473 | 488 |
/-
Copyright (c) 2017 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
-/
import Mathlib.Data.Option.NAry
import Mathlib.Data.Seq.Computation
import Mathlib.Tactic.ApplyFun
import Mathlib.Data.List.Basic
/-!
# Possibly infinite lists
This file provides a `Seq α` type representing possibly infinite lists (referred here as sequences).
It is encoded as an infinite stream of options such that if `f n = none`, then
`f m = none` for all `m ≥ n`.
-/
namespace Stream'
universe u v w
/-
coinductive seq (α : Type u) : Type u
| nil : seq α
| cons : α → seq α → seq α
-/
/-- A stream `s : Option α` is a sequence if `s.get n = none` implies `s.get (n + 1) = none`.
-/
def IsSeq {α : Type u} (s : Stream' (Option α)) : Prop :=
∀ {n : ℕ}, s n = none → s (n + 1) = none
/-- `Seq α` is the type of possibly infinite lists (referred here as sequences).
It is encoded as an infinite stream of options such that if `f n = none`, then
`f m = none` for all `m ≥ n`. -/
def Seq (α : Type u) : Type u :=
{ f : Stream' (Option α) // f.IsSeq }
/-- `Seq1 α` is the type of nonempty sequences. -/
def Seq1 (α) :=
α × Seq α
namespace Seq
variable {α : Type u} {β : Type v} {γ : Type w}
/-- The empty sequence -/
def nil : Seq α :=
⟨Stream'.const none, fun {_} _ => rfl⟩
instance : Inhabited (Seq α) :=
⟨nil⟩
/-- Prepend an element to a sequence -/
def cons (a : α) (s : Seq α) : Seq α :=
⟨some a::s.1, by
rintro (n | _) h
· contradiction
· exact s.2 h⟩
@[simp]
theorem val_cons (s : Seq α) (x : α) : (cons x s).val = some x::s.val :=
rfl
/-- Get the nth element of a sequence (if it exists) -/
def get? : Seq α → ℕ → Option α :=
Subtype.val
@[simp]
theorem val_eq_get (s : Seq α) (n : ℕ) : s.val n = s.get? n := by
rfl
@[simp]
theorem get?_mk (f hf) : @get? α ⟨f, hf⟩ = f :=
rfl
@[simp]
theorem get?_nil (n : ℕ) : (@nil α).get? n = none :=
rfl
@[simp]
theorem get?_cons_zero (a : α) (s : Seq α) : (cons a s).get? 0 = some a :=
rfl
@[simp]
theorem get?_cons_succ (a : α) (s : Seq α) (n : ℕ) : (cons a s).get? (n + 1) = s.get? n :=
rfl
@[ext]
protected theorem ext {s t : Seq α} (h : ∀ n : ℕ, s.get? n = t.get? n) : s = t :=
Subtype.eq <| funext h
theorem cons_injective2 : Function.Injective2 (cons : α → Seq α → Seq α) := fun x y s t h =>
⟨by rw [← Option.some_inj, ← get?_cons_zero, h, get?_cons_zero],
Seq.ext fun n => by simp_rw [← get?_cons_succ x s n, h, get?_cons_succ]⟩
theorem cons_left_injective (s : Seq α) : Function.Injective fun x => cons x s :=
cons_injective2.left _
theorem cons_right_injective (x : α) : Function.Injective (cons x) :=
cons_injective2.right _
/-- A sequence has terminated at position `n` if the value at position `n` equals `none`. -/
def TerminatedAt (s : Seq α) (n : ℕ) : Prop :=
s.get? n = none
/-- It is decidable whether a sequence terminates at a given position. -/
instance terminatedAtDecidable (s : Seq α) (n : ℕ) : Decidable (s.TerminatedAt n) :=
decidable_of_iff' (s.get? n).isNone <| by unfold TerminatedAt; cases s.get? n <;> simp
/-- A sequence terminates if there is some position `n` at which it has terminated. -/
def Terminates (s : Seq α) : Prop :=
∃ n : ℕ, s.TerminatedAt n
theorem not_terminates_iff {s : Seq α} : ¬s.Terminates ↔ ∀ n, (s.get? n).isSome := by
simp only [Terminates, TerminatedAt, ← Ne.eq_def, Option.ne_none_iff_isSome, not_exists, iff_self]
/-- Functorial action of the functor `Option (α × _)` -/
@[simp]
def omap (f : β → γ) : Option (α × β) → Option (α × γ)
| none => none
| some (a, b) => some (a, f b)
/-- Get the first element of a sequence -/
def head (s : Seq α) : Option α :=
get? s 0
/-- Get the tail of a sequence (or `nil` if the sequence is `nil`) -/
def tail (s : Seq α) : Seq α :=
⟨s.1.tail, fun n' => by
obtain ⟨f, al⟩ := s
exact al n'⟩
/-- member definition for `Seq` -/
protected def Mem (s : Seq α) (a : α) :=
some a ∈ s.1
instance : Membership α (Seq α) :=
⟨Seq.Mem⟩
theorem le_stable (s : Seq α) {m n} (h : m ≤ n) : s.get? m = none → s.get? n = none := by
obtain ⟨f, al⟩ := s
induction' h with n _ IH
exacts [id, fun h2 => al (IH h2)]
/-- If a sequence terminated at position `n`, it also terminated at `m ≥ n`. -/
theorem terminated_stable : ∀ (s : Seq α) {m n : ℕ}, m ≤ n → s.TerminatedAt m → s.TerminatedAt n :=
le_stable
/-- If `s.get? n = some aₙ` for some value `aₙ`, then there is also some value `aₘ` such
that `s.get? = some aₘ` for `m ≤ n`.
-/
theorem ge_stable (s : Seq α) {aₙ : α} {n m : ℕ} (m_le_n : m ≤ n)
(s_nth_eq_some : s.get? n = some aₙ) : ∃ aₘ : α, s.get? m = some aₘ :=
have : s.get? n ≠ none := by simp [s_nth_eq_some]
have : s.get? m ≠ none := mt (s.le_stable m_le_n) this
Option.ne_none_iff_exists'.mp this
theorem not_mem_nil (a : α) : a ∉ @nil α := fun ⟨_, (h : some a = none)⟩ => by injection h
theorem mem_cons (a : α) : ∀ s : Seq α, a ∈ cons a s
| ⟨_, _⟩ => Stream'.mem_cons (some a) _
theorem mem_cons_of_mem (y : α) {a : α} : ∀ {s : Seq α}, a ∈ s → a ∈ cons y s
| ⟨_, _⟩ => Stream'.mem_cons_of_mem (some y)
theorem eq_or_mem_of_mem_cons {a b : α} : ∀ {s : Seq α}, a ∈ cons b s → a = b ∨ a ∈ s
| ⟨_, _⟩, h => (Stream'.eq_or_mem_of_mem_cons h).imp_left fun h => by injection h
@[simp]
theorem mem_cons_iff {a b : α} {s : Seq α} : a ∈ cons b s ↔ a = b ∨ a ∈ s :=
⟨eq_or_mem_of_mem_cons, by rintro (rfl | m) <;> [apply mem_cons; exact mem_cons_of_mem _ m]⟩
@[simp]
theorem get?_mem {s : Seq α} {n : ℕ} {x : α} (h : s.get? n = .some x) : x ∈ s := ⟨n, h.symm⟩
/-- Destructor for a sequence, resulting in either `none` (for `nil`) or
`some (a, s)` (for `cons a s`). -/
def destruct (s : Seq α) : Option (Seq1 α) :=
(fun a' => (a', s.tail)) <$> get? s 0
theorem destruct_eq_none {s : Seq α} : destruct s = none → s = nil := by
dsimp [destruct]
induction' f0 : get? s 0 <;> intro h
· apply Subtype.eq
funext n
induction' n with n IH
exacts [f0, s.2 IH]
· contradiction
theorem destruct_eq_cons {s : Seq α} {a s'} : destruct s = some (a, s') → s = cons a s' := by
dsimp [destruct]
induction' f0 : get? s 0 with a' <;> intro h
· contradiction
· obtain ⟨f, al⟩ := s
injections _ h1 h2
rw [← h2]
apply Subtype.eq
dsimp [tail, cons]
rw [h1] at f0
rw [← f0]
exact (Stream'.eta f).symm
@[simp]
theorem destruct_nil : destruct (nil : Seq α) = none :=
rfl
@[simp]
theorem destruct_cons (a : α) : ∀ s, destruct (cons a s) = some (a, s)
| ⟨f, al⟩ => by
unfold cons destruct Functor.map
apply congr_arg fun s => some (a, s)
apply Subtype.eq; dsimp [tail]
-- Porting note: needed universe annotation to avoid universe issues
theorem head_eq_destruct (s : Seq α) : head.{u} s = Prod.fst.{u} <$> destruct.{u} s := by
unfold destruct head; cases get? s 0 <;> rfl
@[simp]
theorem head_nil : head (nil : Seq α) = none :=
rfl
@[simp]
theorem head_cons (a : α) (s) : head (cons a s) = some a := by
rw [head_eq_destruct, destruct_cons, Option.map_eq_map, Option.map_some']
@[simp]
theorem tail_nil : tail (nil : Seq α) = nil :=
rfl
@[simp]
theorem tail_cons (a : α) (s) : tail (cons a s) = s := by
obtain ⟨f, al⟩ := s
apply Subtype.eq
dsimp [tail, cons]
@[simp]
theorem get?_tail (s : Seq α) (n) : get? (tail s) n = get? s (n + 1) :=
rfl
/-- Recursion principle for sequences, compare with `List.recOn`. -/
@[cases_eliminator]
def recOn {motive : Seq α → Sort v} (s : Seq α) (nil : motive nil)
(cons : ∀ x s, motive (cons x s)) :
motive s := by
rcases H : destruct s with - | v
· rw [destruct_eq_none H]
apply nil
· obtain ⟨a, s'⟩ := v
rw [destruct_eq_cons H]
apply cons
@[simp]
theorem cons_ne_nil {x : α} {s : Seq α} : (cons x s) ≠ .nil := by
intro h
apply_fun head at h
simp at h
@[simp]
theorem nil_ne_cons {x : α} {s : Seq α} : .nil ≠ (cons x s) := cons_ne_nil.symm
theorem cons_eq_cons {x x' : α} {s s' : Seq α} :
(cons x s = cons x' s') ↔ (x = x' ∧ s = s') := by
constructor
· intro h
constructor
· apply_fun head at h
simpa using h
· apply_fun tail at h
simpa using h
· intro ⟨_, _⟩
congr
theorem head_eq_some {s : Seq α} {x : α} (h : s.head = some x) :
s = cons x s.tail := by
cases s <;> simp at h
simpa [cons_eq_cons]
theorem head_eq_none {s : Seq α} (h : s.head = none) : s = nil := by
cases s
· rfl
· simp at h
@[simp]
theorem head_eq_none_iff {s : Seq α} : s.head = none ↔ s = nil := by
constructor
· apply head_eq_none
· intro h
simp [h]
theorem mem_rec_on {C : Seq α → Prop} {a s} (M : a ∈ s)
(h1 : ∀ b s', a = b ∨ C s' → C (cons b s')) : C s := by
obtain ⟨k, e⟩ := M; unfold Stream'.get at e
induction' k with k IH generalizing s
· have TH : s = cons a (tail s) := by
apply destruct_eq_cons
unfold destruct get? Functor.map
rw [← e]
rfl
rw [TH]
apply h1 _ _ (Or.inl rfl)
cases s with
| nil => injection e
| cons b s' =>
have h_eq : (cons b s').val (Nat.succ k) = s'.val k := by cases s' using Subtype.recOn; rfl
rw [h_eq] at e
apply h1 _ _ (Or.inr (IH e))
/-- Corecursor over pairs of `Option` values -/
def Corec.f (f : β → Option (α × β)) : Option β → Option α × Option β
| none => (none, none)
| some b =>
match f b with
| none => (none, none)
| some (a, b') => (some a, some b')
/-- Corecursor for `Seq α` as a coinductive type. Iterates `f` to produce new elements
of the sequence until `none` is obtained. -/
def corec (f : β → Option (α × β)) (b : β) : Seq α := by
refine ⟨Stream'.corec' (Corec.f f) (some b), fun {n} h => ?_⟩
rw [Stream'.corec'_eq]
change Stream'.corec' (Corec.f f) (Corec.f f (some b)).2 n = none
revert h; generalize some b = o; revert o
induction' n with n IH <;> intro o
· change (Corec.f f o).1 = none → (Corec.f f (Corec.f f o).2).1 = none
rcases o with - | b <;> intro h
· rfl
dsimp [Corec.f] at h
dsimp [Corec.f]
revert h; rcases h₁ : f b with - | s <;> intro h
· rfl
· obtain ⟨a, b'⟩ := s
contradiction
· rw [Stream'.corec'_eq (Corec.f f) (Corec.f f o).2, Stream'.corec'_eq (Corec.f f) o]
exact IH (Corec.f f o).2
@[simp]
theorem corec_eq (f : β → Option (α × β)) (b : β) :
destruct (corec f b) = omap (corec f) (f b) := by
dsimp [corec, destruct, get]
rw [show Stream'.corec' (Corec.f f) (some b) 0 = (Corec.f f (some b)).1 from rfl]
dsimp [Corec.f]
induction' h : f b with s; · rfl
obtain ⟨a, b'⟩ := s; dsimp [Corec.f]
apply congr_arg fun b' => some (a, b')
apply Subtype.eq
dsimp [corec, tail]
rw [Stream'.corec'_eq, Stream'.tail_cons]
dsimp [Corec.f]; rw [h]
theorem corec_nil (f : β → Option (α × β)) (b : β)
(h : f b = .none) : corec f b = nil := by
apply destruct_eq_none
simp [h]
theorem corec_cons {f : β → Option (α × β)} {b : β} {x : α} {s : β}
(h : f b = .some (x, s)) : corec f b = cons x (corec f s) := by
apply destruct_eq_cons
simp [h]
section Bisim
variable (R : Seq α → Seq α → Prop)
local infixl:50 " ~ " => R
/-- Bisimilarity relation over `Option` of `Seq1 α` -/
def BisimO : Option (Seq1 α) → Option (Seq1 α) → Prop
| none, none => True
| some (a, s), some (a', s') => a = a' ∧ R s s'
| _, _ => False
attribute [simp] BisimO
attribute [nolint simpNF] BisimO.eq_3
/-- a relation is bisimilar if it meets the `BisimO` test -/
def IsBisimulation :=
∀ ⦃s₁ s₂⦄, s₁ ~ s₂ → BisimO R (destruct s₁) (destruct s₂)
-- If two streams are bisimilar, then they are equal
theorem eq_of_bisim (bisim : IsBisimulation R) {s₁ s₂} (r : s₁ ~ s₂) : s₁ = s₂ := by
apply Subtype.eq
apply Stream'.eq_of_bisim fun x y => ∃ s s' : Seq α, s.1 = x ∧ s'.1 = y ∧ R s s'
· dsimp [Stream'.IsBisimulation]
intro t₁ t₂ e
exact
match t₁, t₂, e with
| _, _, ⟨s, s', rfl, rfl, r⟩ => by
suffices head s = head s' ∧ R (tail s) (tail s') from
And.imp id (fun r => ⟨tail s, tail s', by cases s using Subtype.recOn; rfl,
by cases s' using Subtype.recOn; rfl, r⟩) this
have := bisim r; revert r this
cases s <;> cases s'
· intro r _
constructor
· rfl
· assumption
· intro _ this
rw [destruct_nil, destruct_cons] at this
exact False.elim this
· intro _ this
rw [destruct_nil, destruct_cons] at this
exact False.elim this
· intro _ this
rw [destruct_cons, destruct_cons] at this
rw [head_cons, head_cons, tail_cons, tail_cons]
obtain ⟨h1, h2⟩ := this
constructor
· rw [h1]
· exact h2
· exact ⟨s₁, s₂, rfl, rfl, r⟩
end Bisim
theorem coinduction :
∀ {s₁ s₂ : Seq α},
head s₁ = head s₂ →
(∀ (β : Type u) (fr : Seq α → β), fr s₁ = fr s₂ → fr (tail s₁) = fr (tail s₂)) → s₁ = s₂
| _, _, hh, ht =>
Subtype.eq (Stream'.coinduction hh fun β fr => ht β fun s => fr s.1)
theorem coinduction2 (s) (f g : Seq α → Seq β)
(H :
∀ s,
BisimO (fun s1 s2 : Seq β => ∃ s : Seq α, s1 = f s ∧ s2 = g s) (destruct (f s))
(destruct (g s))) :
f s = g s := by
refine eq_of_bisim (fun s1 s2 => ∃ s, s1 = f s ∧ s2 = g s) ?_ ⟨s, rfl, rfl⟩
intro s1 s2 h; rcases h with ⟨s, h1, h2⟩
rw [h1, h2]; apply H
/-- Embed a list as a sequence -/
@[coe]
def ofList (l : List α) : Seq α :=
⟨(l[·]?), fun {n} h => by
rw [List.getElem?_eq_none_iff] at h ⊢
exact h.trans (Nat.le_succ n)⟩
instance coeList : Coe (List α) (Seq α) :=
⟨ofList⟩
@[simp]
theorem ofList_nil : ofList [] = (nil : Seq α) :=
rfl
@[simp]
theorem ofList_get? (l : List α) (n : ℕ) : (ofList l).get? n = l[n]? :=
rfl
@[deprecated (since := "2025-02-21")]
alias ofList_get := ofList_get?
@[simp]
theorem ofList_cons (a : α) (l : List α) : ofList (a::l) = cons a (ofList l) := by
ext1 (_ | n) <;> simp
theorem ofList_injective : Function.Injective (ofList : List α → _) :=
fun _ _ h => List.ext_getElem? fun _ => congr_fun (Subtype.ext_iff.1 h) _
/-- Embed an infinite stream as a sequence -/
@[coe]
def ofStream (s : Stream' α) : Seq α :=
⟨s.map some, fun {n} h => by contradiction⟩
instance coeStream : Coe (Stream' α) (Seq α) :=
⟨ofStream⟩
section MLList
/-- Embed a `MLList α` as a sequence. Note that even though this
is non-meta, it will produce infinite sequences if used with
cyclic `MLList`s created by meta constructions. -/
def ofMLList : MLList Id α → Seq α :=
corec fun l =>
match l.uncons with
| .none => none
| .some (a, l') => some (a, l')
instance coeMLList : Coe (MLList Id α) (Seq α) :=
⟨ofMLList⟩
/-- Translate a sequence into a `MLList`. -/
unsafe def toMLList : Seq α → MLList Id α
| s =>
match destruct s with
| none => .nil
| some (a, s') => .cons a (toMLList s')
end MLList
/-- Translate a sequence to a list. This function will run forever if
run on an infinite sequence. -/
unsafe def forceToList (s : Seq α) : List α :=
(toMLList s).force
/-- The sequence of natural numbers some 0, some 1, ... -/
def nats : Seq ℕ :=
Stream'.nats
@[simp]
theorem nats_get? (n : ℕ) : nats.get? n = some n :=
rfl
/-- Append two sequences. If `s₁` is infinite, then `s₁ ++ s₂ = s₁`,
otherwise it puts `s₂` at the location of the `nil` in `s₁`. -/
def append (s₁ s₂ : Seq α) : Seq α :=
@corec α (Seq α × Seq α)
(fun ⟨s₁, s₂⟩ =>
match destruct s₁ with
| none => omap (fun s₂ => (nil, s₂)) (destruct s₂)
| some (a, s₁') => some (a, s₁', s₂))
(s₁, s₂)
/-- Map a function over a sequence. -/
def map (f : α → β) : Seq α → Seq β
| ⟨s, al⟩ =>
⟨s.map (Option.map f), fun {n} => by
dsimp [Stream'.map, Stream'.get]
induction' e : s n with e <;> intro
· rw [al e]
assumption
· contradiction⟩
/-- Flatten a sequence of sequences. (It is required that the
sequences be nonempty to ensure productivity; in the case
of an infinite sequence of `nil`, the first element is never
generated.) -/
def join : Seq (Seq1 α) → Seq α :=
corec fun S =>
match destruct S with
| none => none
| some ((a, s), S') =>
some
(a,
match destruct s with
| none => S'
| some s' => cons s' S')
/-- Remove the first `n` elements from the sequence. -/
def drop (s : Seq α) : ℕ → Seq α
| 0 => s
| n + 1 => tail (drop s n)
/-- Take the first `n` elements of the sequence (producing a list) -/
def take : ℕ → Seq α → List α
| 0, _ => []
| n + 1, s =>
match destruct s with
| none => []
| some (x, r) => List.cons x (take n r)
/-- Split a sequence at `n`, producing a finite initial segment
and an infinite tail. -/
def splitAt : ℕ → Seq α → List α × Seq α
| 0, s => ([], s)
| n + 1, s =>
match destruct s with
| none => ([], nil)
| some (x, s') =>
let (l, r) := splitAt n s'
(List.cons x l, r)
/-- Folds a sequence using `f`, producing a sequence of intermediate values, i.e.
`[init, f init s.head, f (f init s.head) s.tail.head, ...]`. -/
def fold (s : Seq α) (init : β) (f : β → α → β) : Seq β :=
let f : β × Seq α → Option (β × (β × Seq α)) := fun (acc, x) =>
match destruct x with
| none => .none
| some (x, s) => .some (f acc x, f acc x, s)
cons init <| corec f (init, s)
section ZipWith
/-- Combine two sequences with a function -/
def zipWith (f : α → β → γ) (s₁ : Seq α) (s₂ : Seq β) : Seq γ :=
⟨fun n => Option.map₂ f (s₁.get? n) (s₂.get? n), fun {_} hn =>
Option.map₂_eq_none_iff.2 <| (Option.map₂_eq_none_iff.1 hn).imp s₁.2 s₂.2⟩
@[simp]
theorem get?_zipWith (f : α → β → γ) (s s' n) :
(zipWith f s s').get? n = Option.map₂ f (s.get? n) (s'.get? n) :=
rfl
end ZipWith
/-- Pair two sequences into a sequence of pairs -/
def zip : Seq α → Seq β → Seq (α × β) :=
zipWith Prod.mk
@[simp]
theorem get?_zip (s : Seq α) (t : Seq β) (n : ℕ) :
get? (zip s t) n = Option.map₂ Prod.mk (get? s n) (get? t n) :=
get?_zipWith _ _ _ _
/-- Separate a sequence of pairs into two sequences -/
def unzip (s : Seq (α × β)) : Seq α × Seq β :=
(map Prod.fst s, map Prod.snd s)
/-- Enumerate a sequence by tagging each element with its index. -/
def enum (s : Seq α) : Seq (ℕ × α) :=
Seq.zip nats s
@[simp]
theorem get?_enum (s : Seq α) (n : ℕ) : get? (enum s) n = Option.map (Prod.mk n) (get? s n) :=
get?_zip _ _ _
@[simp]
theorem enum_nil : enum (nil : Seq α) = nil :=
rfl
/-- The length of a terminating sequence. -/
def length (s : Seq α) (h : s.Terminates) : ℕ :=
Nat.find h
/-- Convert a sequence which is known to terminate into a list -/
def toList (s : Seq α) (h : s.Terminates) : List α :=
take (length s h) s
/-- Convert a sequence which is known not to terminate into a stream -/
def toStream (s : Seq α) (h : ¬s.Terminates) : Stream' α := fun n =>
Option.get _ <| not_terminates_iff.1 h n
/-- Convert a sequence into either a list or a stream depending on whether
it is finite or infinite. (Without decidability of the infiniteness predicate,
this is not constructively possible.) -/
def toListOrStream (s : Seq α) [Decidable s.Terminates] : List α ⊕ Stream' α :=
if h : s.Terminates then Sum.inl (toList s h) else Sum.inr (toStream s h)
@[simp]
theorem nil_append (s : Seq α) : append nil s = s := by
apply coinduction2; intro s
dsimp [append]; rw [corec_eq]
dsimp [append]
cases s
· trivial
· rw [destruct_cons]
dsimp
exact ⟨rfl, _, rfl, rfl⟩
@[simp]
theorem take_nil {n : ℕ} : (nil (α := α)).take n = List.nil := by
cases n <;> rfl
@[simp]
theorem take_zero {s : Seq α} : s.take 0 = [] := by
cases s <;> rfl
@[simp]
theorem take_succ_cons {n : ℕ} {x : α} {s : Seq α} :
(cons x s).take (n + 1) = x :: s.take n := by
rfl
@[simp]
theorem getElem?_take : ∀ (n k : ℕ) (s : Seq α),
(s.take k)[n]? = if n < k then s.get? n else none
| n, 0, s => by simp [take]
| n, k+1, s => by
rw [take]
cases h : destruct s with
| none =>
simp [destruct_eq_none h]
| some a =>
match a with
| (x, r) =>
rw [destruct_eq_cons h]
match n with
| 0 => simp
| n+1 =>
simp [List.getElem?_cons_succ, Nat.add_lt_add_iff_right, getElem?_take]
theorem get?_mem_take {s : Seq α} {m n : ℕ} (h_mn : m < n) {x : α}
(h_get : s.get? m = .some x) : x ∈ s.take n := by
induction m generalizing n s with
| zero =>
obtain ⟨l, hl⟩ := Nat.exists_add_one_eq.mpr h_mn
rw [← hl, take, head_eq_some h_get]
simp
| succ k ih =>
obtain ⟨l, hl⟩ := Nat.exists_eq_add_of_lt h_mn
subst hl
have : ∃ y, s.get? 0 = .some y := by
apply ge_stable _ _ h_get
simp
obtain ⟨y, hy⟩ := this
rw [take, head_eq_some hy]
simp
right
apply ih (by omega)
rwa [get?_tail]
theorem terminatedAt_ofList (l : List α) :
(ofList l).TerminatedAt l.length := by
simp [ofList, TerminatedAt]
theorem terminates_ofList (l : List α) : (ofList l).Terminates :=
⟨_, terminatedAt_ofList l⟩
@[simp]
theorem terminatedAt_nil {n : ℕ} : TerminatedAt (nil : Seq α) n := rfl
@[simp]
theorem cons_not_terminatedAt_zero {x : α} {s : Seq α} :
¬(cons x s).TerminatedAt 0 := by
simp [TerminatedAt]
@[simp]
theorem cons_terminatedAt_succ_iff {x : α} {s : Seq α} {n : ℕ} :
(cons x s).TerminatedAt (n + 1) ↔ s.TerminatedAt n := by
simp [TerminatedAt]
@[simp]
theorem terminates_nil : Terminates (nil : Seq α) := ⟨0, rfl⟩
@[simp]
theorem terminates_cons_iff {x : α} {s : Seq α} :
(cons x s).Terminates ↔ s.Terminates := by
constructor <;> intro ⟨n, h⟩
· exact ⟨n, cons_terminatedAt_succ_iff.mp (terminated_stable _ (Nat.le_succ _) h)⟩
· exact ⟨n + 1, cons_terminatedAt_succ_iff.mpr h⟩
@[simp]
theorem length_nil : length (nil : Seq α) terminates_nil = 0 := rfl
@[simp]
theorem get?_zero_eq_none {s : Seq α} : s.get? 0 = none ↔ s = nil := by
refine ⟨fun h => ?_, fun h => h ▸ rfl⟩
ext1 n
exact le_stable s (Nat.zero_le _) h
@[simp] theorem length_eq_zero {s : Seq α} {h : s.Terminates} :
s.length h = 0 ↔ s = nil := by
simp [length, TerminatedAt]
theorem terminatedAt_zero_iff {s : Seq α} : s.TerminatedAt 0 ↔ s = nil := by
refine ⟨?_, ?_⟩
· intro h
ext n
rw [le_stable _ (Nat.zero_le _) h]
simp
· rintro rfl
simp [TerminatedAt]
/-- The statement of `length_le_iff'` does not assume that the sequence terminates. For a
simpler statement of the theorem where the sequence is known to terminate see `length_le_iff` -/
theorem length_le_iff' {s : Seq α} {n : ℕ} :
(∃ h, s.length h ≤ n) ↔ s.TerminatedAt n := by
simp only [length, Nat.find_le_iff, TerminatedAt, Terminates, exists_prop]
refine ⟨?_, ?_⟩
· rintro ⟨_, k, hkn, hk⟩
exact le_stable s hkn hk
· intro hn
exact ⟨⟨n, hn⟩, ⟨n, le_rfl, hn⟩⟩
/-- The statement of `length_le_iff` assumes that the sequence terminates. For a
statement of the where the sequence is not known to terminate see `length_le_iff'` -/
theorem length_le_iff {s : Seq α} {n : ℕ} {h : s.Terminates} :
s.length h ≤ n ↔ s.TerminatedAt n := by
rw [← length_le_iff']; simp [h]
/-- The statement of `lt_length_iff'` does not assume that the sequence terminates. For a
simpler statement of the theorem where the sequence is known to terminate see `lt_length_iff` -/
theorem lt_length_iff' {s : Seq α} {n : ℕ} :
(∀ h : s.Terminates, n < s.length h) ↔ ∃ a, a ∈ s.get? n := by
simp only [Terminates, TerminatedAt, length, Nat.lt_find_iff, forall_exists_index, Option.mem_def,
← Option.ne_none_iff_exists', ne_eq]
refine ⟨?_, ?_⟩
· intro h hn
exact h n hn n le_rfl hn
· intro hn _ _ k hkn hk
exact hn <| le_stable s hkn hk
/-- The statement of `length_le_iff` assumes that the sequence terminates. For a
statement of the where the sequence is not known to terminate see `length_le_iff'` -/
theorem lt_length_iff {s : Seq α} {n : ℕ} {h : s.Terminates} :
n < s.length h ↔ ∃ a, a ∈ s.get? n := by
rw [← lt_length_iff']; simp [h]
theorem length_take_le {s : Seq α} {n : ℕ} : (s.take n).length ≤ n := by
induction n generalizing s with
| zero => simp
| succ m ih =>
rw [take]
cases s.destruct with
| none => simp
| some v =>
obtain ⟨x, r⟩ := v
simpa using ih
theorem length_take_of_le_length {s : Seq α} {n : ℕ}
(hle : ∀ h : s.Terminates, n ≤ s.length h) : (s.take n).length = n := by
induction n generalizing s with
| zero => simp [take]
| succ n ih =>
rw [take, destruct]
let ⟨a, ha⟩ := lt_length_iff'.1 (fun ht => lt_of_lt_of_le (Nat.succ_pos _) (hle ht))
simp [Option.mem_def.1 ha]
rw [ih]
intro h
simp only [length, tail, Nat.le_find_iff, TerminatedAt, get?_mk, Stream'.tail]
intro m hmn hs
have := lt_length_iff'.1 (fun ht => (Nat.lt_of_succ_le (hle ht)))
rw [le_stable s (Nat.succ_le_of_lt hmn) hs] at this
simp at this
@[simp]
theorem length_toList (s : Seq α) (h : s.Terminates) : (toList s h).length = length s h := by
rw [toList, length_take_of_le_length]
intro _
exact le_rfl
@[simp]
theorem getElem?_toList (s : Seq α) (h : s.Terminates) (n : ℕ) : (toList s h)[n]? = s.get? n := by
ext k
simp only [ofList, toList, get?_mk, Option.mem_def, getElem?_take, Nat.lt_find_iff, length,
Option.ite_none_right_eq_some, and_iff_right_iff_imp, TerminatedAt]
intro h m hmn
let ⟨a, ha⟩ := ge_stable s hmn h
simp [ha]
@[simp]
theorem ofList_toList (s : Seq α) (h : s.Terminates) :
ofList (toList s h) = s := by
ext n; simp [ofList]
@[simp]
theorem toList_ofList (l : List α) : toList (ofList l) (terminates_ofList l) = l :=
ofList_injective (by simp)
@[simp]
theorem toList_nil : toList (nil : Seq α) ⟨0, terminatedAt_zero_iff.2 rfl⟩ = [] := by
ext; simp [nil, toList, const]
theorem getLast?_toList (s : Seq α) (h : s.Terminates) :
(toList s h).getLast? = s.get? (s.length h - 1) := by
rw [List.getLast?_eq_getElem?, getElem?_toList, length_toList]
@[simp]
theorem cons_append (a : α) (s t) : append (cons a s) t = cons a (append s t) :=
destruct_eq_cons <| by
dsimp [append]; rw [corec_eq]
dsimp [append]; rw [destruct_cons]
@[simp]
theorem append_nil (s : Seq α) : append s nil = s := by
apply coinduction2 s; intro s
cases s
· trivial
· rw [cons_append, destruct_cons, destruct_cons]
dsimp
exact ⟨rfl, _, rfl, rfl⟩
@[simp]
theorem append_assoc (s t u : Seq α) : append (append s t) u = append s (append t u) := by
apply eq_of_bisim fun s1 s2 => ∃ s t u, s1 = append (append s t) u ∧ s2 = append s (append t u)
· intro s1 s2 h
exact
match s1, s2, h with
| _, _, ⟨s, t, u, rfl, rfl⟩ => by
cases s <;> simp
case nil =>
cases t <;> simp
case nil =>
cases u <;> simp
case cons _ u => refine ⟨nil, nil, u, ?_, ?_⟩ <;> simp
case cons _ t => refine ⟨nil, t, u, ?_, ?_⟩ <;> simp
case cons _ s => exact ⟨s, t, u, rfl, rfl⟩
· exact ⟨s, t, u, rfl, rfl⟩
@[simp]
theorem map_nil (f : α → β) : map f nil = nil :=
rfl
@[simp]
theorem map_cons (f : α → β) (a) : ∀ s, map f (cons a s) = cons (f a) (map f s)
| ⟨s, al⟩ => by apply Subtype.eq; dsimp [cons, map]; rw [Stream'.map_cons]; rfl
@[simp]
theorem map_id : ∀ s : Seq α, map id s = s
| ⟨s, al⟩ => by
apply Subtype.eq; dsimp [map]
rw [Option.map_id, Stream'.map_id]
@[simp]
theorem map_tail (f : α → β) : ∀ s, map f (tail s) = tail (map f s)
| ⟨s, al⟩ => by apply Subtype.eq; dsimp [tail, map]
theorem map_comp (f : α → β) (g : β → γ) : ∀ s : Seq α, map (g ∘ f) s = map g (map f s)
| ⟨s, al⟩ => by
apply Subtype.eq; dsimp [map]
apply congr_arg fun f : _ → Option γ => Stream'.map f s
ext ⟨⟩ <;> rfl
@[simp]
theorem map_append (f : α → β) (s t) : map f (append s t) = append (map f s) (map f t) := by
apply
eq_of_bisim (fun s1 s2 => ∃ s t, s1 = map f (append s t) ∧ s2 = append (map f s) (map f t)) _
⟨s, t, rfl, rfl⟩
intro s1 s2 h
exact
match s1, s2, h with
| _, _, ⟨s, t, rfl, rfl⟩ => by
cases s <;> simp
case nil =>
cases t <;> simp
case cons _ t => refine ⟨nil, t, ?_, ?_⟩ <;> simp
case cons _ s => exact ⟨s, t, rfl, rfl⟩
@[simp]
theorem map_get? (f : α → β) : ∀ s n, get? (map f s) n = (get? s n).map f
| ⟨_, _⟩, _ => rfl
@[simp]
theorem terminatedAt_map_iff {f : α → β} {s : Seq α} {n : ℕ} :
(map f s).TerminatedAt n ↔ s.TerminatedAt n := by
simp [TerminatedAt]
@[simp]
theorem terminates_map_iff {f : α → β} {s : Seq α} :
(map f s).Terminates ↔ s.Terminates := by
simp [Terminates]
@[simp]
theorem length_map {s : Seq α} {f : α → β} (h : (s.map f).Terminates) :
(s.map f).length h = s.length (terminates_map_iff.1 h) := by
rw [length]
congr
ext
simp
instance : Functor Seq where map := @map
instance : LawfulFunctor Seq where
id_map := @map_id
comp_map := @map_comp
map_const := rfl
@[simp]
theorem join_nil : join nil = (nil : Seq α) :=
destruct_eq_none rfl
-- Not a simp lemmas as `join_cons` is more general
theorem join_cons_nil (a : α) (S) : join (cons (a, nil) S) = cons a (join S) :=
destruct_eq_cons <| by simp [join]
-- Not a simp lemmas as `join_cons` is more general
theorem join_cons_cons (a b : α) (s S) :
join (cons (a, cons b s) S) = cons a (join (cons (b, s) S)) :=
destruct_eq_cons <| by simp [join]
@[simp]
theorem join_cons (a : α) (s S) : join (cons (a, s) S) = cons a (append s (join S)) := by
apply
eq_of_bisim
(fun s1 s2 => s1 = s2 ∨ ∃ a s S, s1 = join (cons (a, s) S) ∧ s2 = cons a (append s (join S)))
_ (Or.inr ⟨a, s, S, rfl, rfl⟩)
intro s1 s2 h
exact
match s1, s2, h with
| s, _, Or.inl <| Eq.refl s => by
cases s; · trivial
· rw [destruct_cons]
exact ⟨rfl, Or.inl rfl⟩
| _, _, Or.inr ⟨a, s, S, rfl, rfl⟩ => by
| cases s
· simp [join_cons_cons, join_cons_nil]
· simpa [join_cons_cons, join_cons_nil] using Or.inr ⟨_, _, S, rfl, rfl⟩
@[simp]
theorem join_append (S T : Seq (Seq1 α)) : join (append S T) = append (join S) (join T) := by
| Mathlib/Data/Seq/Seq.lean | 964 | 969 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.