Context stringlengths 285 157k | file_name stringlengths 21 79 | start int64 14 3.67k | end int64 18 3.69k | theorem stringlengths 25 2.71k | proof stringlengths 5 10.6k |
|---|---|---|---|---|---|
/-
Copyright (c) 2020 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.CategoryTheory.Monoidal.Free.Coherence
import Mathlib.CategoryTheory.Monoidal.Discrete
import Mathlib.CategoryTheory.Monoidal.NaturalTransformation
import Mathlib.CategoryTheory.Monoidal.Opposite
import Mathlib.Tactic.CategoryTheory.Coherence
import Mathlib.CategoryTheory.CommSq
#align_import category_theory.monoidal.braided from "leanprover-community/mathlib"@"2efd2423f8d25fa57cf7a179f5d8652ab4d0df44"
/-!
# Braided and symmetric monoidal categories
The basic definitions of braided monoidal categories, and symmetric monoidal categories,
as well as braided functors.
## Implementation note
We make `BraidedCategory` another typeclass, but then have `SymmetricCategory` extend this.
The rationale is that we are not carrying any additional data, just requiring a property.
## Future work
* Construct the Drinfeld center of a monoidal category as a braided monoidal category.
* Say something about pseudo-natural transformations.
## References
* [Pavel Etingof, Shlomo Gelaki, Dmitri Nikshych, Victor Ostrik, *Tensor categories*][egno15]
-/
open CategoryTheory MonoidalCategory
universe v v₁ v₂ v₃ u u₁ u₂ u₃
namespace CategoryTheory
/-- A braided monoidal category is a monoidal category equipped with a braiding isomorphism
`β_ X Y : X ⊗ Y ≅ Y ⊗ X`
which is natural in both arguments,
and also satisfies the two hexagon identities.
-/
class BraidedCategory (C : Type u) [Category.{v} C] [MonoidalCategory.{v} C] where
/-- The braiding natural isomorphism. -/
braiding : ∀ X Y : C, X ⊗ Y ≅ Y ⊗ X
braiding_naturality_right :
∀ (X : C) {Y Z : C} (f : Y ⟶ Z),
X ◁ f ≫ (braiding X Z).hom = (braiding X Y).hom ≫ f ▷ X := by
aesop_cat
braiding_naturality_left :
∀ {X Y : C} (f : X ⟶ Y) (Z : C),
f ▷ Z ≫ (braiding Y Z).hom = (braiding X Z).hom ≫ Z ◁ f := by
aesop_cat
/-- The first hexagon identity. -/
hexagon_forward :
∀ X Y Z : C,
(α_ X Y Z).hom ≫ (braiding X (Y ⊗ Z)).hom ≫ (α_ Y Z X).hom =
((braiding X Y).hom ▷ Z) ≫ (α_ Y X Z).hom ≫ (Y ◁ (braiding X Z).hom) := by
aesop_cat
/-- The second hexagon identity. -/
hexagon_reverse :
∀ X Y Z : C,
(α_ X Y Z).inv ≫ (braiding (X ⊗ Y) Z).hom ≫ (α_ Z X Y).inv =
(X ◁ (braiding Y Z).hom) ≫ (α_ X Z Y).inv ≫ ((braiding X Z).hom ▷ Y) := by
aesop_cat
#align category_theory.braided_category CategoryTheory.BraidedCategory
attribute [reassoc (attr := simp)]
BraidedCategory.braiding_naturality_left
BraidedCategory.braiding_naturality_right
attribute [reassoc] BraidedCategory.hexagon_forward BraidedCategory.hexagon_reverse
open Category
open MonoidalCategory
open BraidedCategory
@[inherit_doc]
notation "β_" => BraidedCategory.braiding
namespace BraidedCategory
variable {C : Type u} [Category.{v} C] [MonoidalCategory.{v} C] [BraidedCategory.{v} C]
@[simp, reassoc]
theorem braiding_tensor_left (X Y Z : C) :
(β_ (X ⊗ Y) Z).hom =
(α_ X Y Z).hom ≫ X ◁ (β_ Y Z).hom ≫ (α_ X Z Y).inv ≫
(β_ X Z).hom ▷ Y ≫ (α_ Z X Y).hom := by
apply (cancel_epi (α_ X Y Z).inv).1
apply (cancel_mono (α_ Z X Y).inv).1
simp [hexagon_reverse]
@[simp, reassoc]
theorem braiding_tensor_right (X Y Z : C) :
(β_ X (Y ⊗ Z)).hom =
(α_ X Y Z).inv ≫ (β_ X Y).hom ▷ Z ≫ (α_ Y X Z).hom ≫
Y ◁ (β_ X Z).hom ≫ (α_ Y Z X).inv := by
apply (cancel_epi (α_ X Y Z).hom).1
apply (cancel_mono (α_ Y Z X).hom).1
simp [hexagon_forward]
@[simp, reassoc]
theorem braiding_inv_tensor_left (X Y Z : C) :
(β_ (X ⊗ Y) Z).inv =
(α_ Z X Y).inv ≫ (β_ X Z).inv ▷ Y ≫ (α_ X Z Y).hom ≫
X ◁ (β_ Y Z).inv ≫ (α_ X Y Z).inv :=
eq_of_inv_eq_inv (by simp)
@[simp, reassoc]
theorem braiding_inv_tensor_right (X Y Z : C) :
(β_ X (Y ⊗ Z)).inv =
(α_ Y Z X).hom ≫ Y ◁ (β_ X Z).inv ≫ (α_ Y X Z).inv ≫
(β_ X Y).inv ▷ Z ≫ (α_ X Y Z).hom :=
eq_of_inv_eq_inv (by simp)
@[reassoc (attr := simp)]
| Mathlib/CategoryTheory/Monoidal/Braided/Basic.lean | 125 | 128 | theorem braiding_naturality {X X' Y Y' : C} (f : X ⟶ Y) (g : X' ⟶ Y') :
(f ⊗ g) ≫ (braiding Y Y').hom = (braiding X X').hom ≫ (g ⊗ f) := by |
rw [tensorHom_def' f g, tensorHom_def g f]
simp_rw [Category.assoc, braiding_naturality_left, braiding_naturality_right_assoc]
|
/-
Copyright (c) 2022 Rémy Degenne. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Rémy Degenne
-/
import Mathlib.Data.Countable.Basic
import Mathlib.Logic.Encodable.Basic
import Mathlib.Order.SuccPred.Basic
import Mathlib.Order.Interval.Finset.Defs
#align_import order.succ_pred.linear_locally_finite from "leanprover-community/mathlib"@"2705404e701abc6b3127da906f40bae062a169c9"
/-!
# Linear locally finite orders
We prove that a `LinearOrder` which is a `LocallyFiniteOrder` also verifies
* `SuccOrder`
* `PredOrder`
* `IsSuccArchimedean`
* `IsPredArchimedean`
* `Countable`
Furthermore, we show that there is an `OrderIso` between such an order and a subset of `ℤ`.
## Main definitions
* `toZ i0 i`: in a linear order on which we can define predecessors and successors and which is
succ-archimedean, we can assign a unique integer `toZ i0 i` to each element `i : ι` while
respecting the order, starting from `toZ i0 i0 = 0`.
## Main results
Instances about linear locally finite orders:
* `LinearLocallyFiniteOrder.SuccOrder`: a linear locally finite order has a successor function.
* `LinearLocallyFiniteOrder.PredOrder`: a linear locally finite order has a predecessor
function.
* `LinearLocallyFiniteOrder.isSuccArchimedean`: a linear locally finite order is
succ-archimedean.
* `LinearOrder.pred_archimedean_of_succ_archimedean`: a succ-archimedean linear order is also
pred-archimedean.
* `countable_of_linear_succ_pred_arch` : a succ-archimedean linear order is countable.
About `toZ`:
* `orderIsoRangeToZOfLinearSuccPredArch`: `toZ` defines an `OrderIso` between `ι` and its
range.
* `orderIsoNatOfLinearSuccPredArch`: if the order has a bot but no top, `toZ` defines an
`OrderIso` between `ι` and `ℕ`.
* `orderIsoIntOfLinearSuccPredArch`: if the order has neither bot nor top, `toZ` defines an
`OrderIso` between `ι` and `ℤ`.
* `orderIsoRangeOfLinearSuccPredArch`: if the order has both a bot and a top, `toZ` gives an
`OrderIso` between `ι` and `Finset.range ((toZ ⊥ ⊤).toNat + 1)`.
-/
open Order
variable {ι : Type*} [LinearOrder ι]
namespace LinearLocallyFiniteOrder
/-- Successor in a linear order. This defines a true successor only when `i` is isolated from above,
i.e. when `i` is not the greatest lower bound of `(i, ∞)`. -/
noncomputable def succFn (i : ι) : ι :=
(exists_glb_Ioi i).choose
#align linear_locally_finite_order.succ_fn LinearLocallyFiniteOrder.succFn
theorem succFn_spec (i : ι) : IsGLB (Set.Ioi i) (succFn i) :=
(exists_glb_Ioi i).choose_spec
#align linear_locally_finite_order.succ_fn_spec LinearLocallyFiniteOrder.succFn_spec
theorem le_succFn (i : ι) : i ≤ succFn i := by
rw [le_isGLB_iff (succFn_spec i), mem_lowerBounds]
exact fun x hx ↦ le_of_lt hx
#align linear_locally_finite_order.le_succ_fn LinearLocallyFiniteOrder.le_succFn
theorem isGLB_Ioc_of_isGLB_Ioi {i j k : ι} (hij_lt : i < j) (h : IsGLB (Set.Ioi i) k) :
IsGLB (Set.Ioc i j) k := by
simp_rw [IsGLB, IsGreatest, mem_upperBounds, mem_lowerBounds] at h ⊢
refine ⟨fun x hx ↦ h.1 x hx.1, fun x hx ↦ h.2 x ?_⟩
intro y hy
rcases le_or_lt y j with h_le | h_lt
· exact hx y ⟨hy, h_le⟩
· exact le_trans (hx j ⟨hij_lt, le_rfl⟩) h_lt.le
#align linear_locally_finite_order.is_glb_Ioc_of_is_glb_Ioi LinearLocallyFiniteOrder.isGLB_Ioc_of_isGLB_Ioi
theorem isMax_of_succFn_le [LocallyFiniteOrder ι] (i : ι) (hi : succFn i ≤ i) : IsMax i := by
refine fun j _ ↦ not_lt.mp fun hij_lt ↦ ?_
have h_succFn_eq : succFn i = i := le_antisymm hi (le_succFn i)
have h_glb : IsGLB (Finset.Ioc i j : Set ι) i := by
rw [Finset.coe_Ioc]
have h := succFn_spec i
rw [h_succFn_eq] at h
exact isGLB_Ioc_of_isGLB_Ioi hij_lt h
have hi_mem : i ∈ Finset.Ioc i j := by
refine Finset.isGLB_mem _ h_glb ?_
exact ⟨_, Finset.mem_Ioc.mpr ⟨hij_lt, le_rfl⟩⟩
rw [Finset.mem_Ioc] at hi_mem
exact lt_irrefl i hi_mem.1
#align linear_locally_finite_order.is_max_of_succ_fn_le LinearLocallyFiniteOrder.isMax_of_succFn_le
theorem succFn_le_of_lt (i j : ι) (hij : i < j) : succFn i ≤ j := by
have h := succFn_spec i
rw [IsGLB, IsGreatest, mem_lowerBounds] at h
exact h.1 j hij
#align linear_locally_finite_order.succ_fn_le_of_lt LinearLocallyFiniteOrder.succFn_le_of_lt
theorem le_of_lt_succFn (j i : ι) (hij : j < succFn i) : j ≤ i := by
rw [lt_isGLB_iff (succFn_spec i)] at hij
obtain ⟨k, hk_lb, hk⟩ := hij
rw [mem_lowerBounds] at hk_lb
exact not_lt.mp fun hi_lt_j ↦ not_le.mpr hk (hk_lb j hi_lt_j)
#align linear_locally_finite_order.le_of_lt_succ_fn LinearLocallyFiniteOrder.le_of_lt_succFn
noncomputable instance (priority := 100) [LocallyFiniteOrder ι] : SuccOrder ι where
succ := succFn
le_succ := le_succFn
max_of_succ_le h := isMax_of_succFn_le _ h
succ_le_of_lt h := succFn_le_of_lt _ _ h
le_of_lt_succ h := le_of_lt_succFn _ _ h
noncomputable instance (priority := 100) [LocallyFiniteOrder ι] : PredOrder ι :=
(inferInstance : PredOrder (OrderDual ιᵒᵈ))
end LinearLocallyFiniteOrder
instance (priority := 100) LinearLocallyFiniteOrder.isSuccArchimedean [LocallyFiniteOrder ι] :
IsSuccArchimedean ι where
exists_succ_iterate_of_le := by
intro i j hij
rw [le_iff_lt_or_eq] at hij
cases' hij with hij hij
swap
· refine ⟨0, ?_⟩
simpa only [Function.iterate_zero, id] using hij
by_contra! h
have h_lt : ∀ n, succ^[n] i < j := by
intro n
induction' n with n hn
· simpa only [Function.iterate_zero, id] using hij
· refine lt_of_le_of_ne ?_ (h _)
rw [Function.iterate_succ', Function.comp_apply]
exact succ_le_of_lt hn
have h_mem : ∀ n, succ^[n] i ∈ Finset.Icc i j :=
fun n ↦ Finset.mem_Icc.mpr ⟨le_succ_iterate n i, (h_lt n).le⟩
obtain ⟨n, m, hnm, h_eq⟩ : ∃ n m, n < m ∧ succ^[n] i = succ^[m] i := by
let f : ℕ → Finset.Icc i j := fun n ↦ ⟨succ^[n] i, h_mem n⟩
obtain ⟨n, m, hnm_ne, hfnm⟩ : ∃ n m, n ≠ m ∧ f n = f m :=
Finite.exists_ne_map_eq_of_infinite f
have hnm_eq : succ^[n] i = succ^[m] i := by simpa only [f, Subtype.mk_eq_mk] using hfnm
rcases le_total n m with h_le | h_le
· exact ⟨n, m, lt_of_le_of_ne h_le hnm_ne, hnm_eq⟩
· exact ⟨m, n, lt_of_le_of_ne h_le hnm_ne.symm, hnm_eq.symm⟩
have h_max : IsMax (succ^[n] i) := isMax_iterate_succ_of_eq_of_ne h_eq hnm.ne
exact not_le.mpr (h_lt n) (h_max (h_lt n).le)
#align linear_locally_finite_order.is_succ_archimedean LinearLocallyFiniteOrder.isSuccArchimedean
instance (priority := 100) LinearOrder.isPredArchimedean_of_isSuccArchimedean [SuccOrder ι]
[PredOrder ι] [IsSuccArchimedean ι] : IsPredArchimedean ι where
exists_pred_iterate_of_le := by
intro i j hij
have h_exists := exists_succ_iterate_of_le hij
obtain ⟨n, hn_eq, hn_lt_ne⟩ : ∃ n, succ^[n] i = j ∧ ∀ m < n, succ^[m] i ≠ j :=
⟨Nat.find h_exists, Nat.find_spec h_exists, fun m hmn ↦ Nat.find_min h_exists hmn⟩
refine ⟨n, ?_⟩
rw [← hn_eq]
induction' n with n
· simp only [Nat.zero_eq, Function.iterate_zero, id]
· rw [pred_succ_iterate_of_not_isMax]
rw [Nat.succ_sub_succ_eq_sub, tsub_zero]
suffices succ^[n] i < succ^[n.succ] i from not_isMax_of_lt this
refine lt_of_le_of_ne ?_ ?_
· rw [Function.iterate_succ']
exact le_succ _
· rw [hn_eq]
exact hn_lt_ne _ (Nat.lt_succ_self n)
#align linear_order.pred_archimedean_of_succ_archimedean LinearOrder.isPredArchimedean_of_isSuccArchimedean
section toZ
variable [SuccOrder ι] [IsSuccArchimedean ι] [PredOrder ι] {i0 i : ι}
-- For "to_Z"
set_option linter.uppercaseLean3 false
/-- `toZ` numbers elements of `ι` according to their order, starting from `i0`. We prove in
`orderIsoRangeToZOfLinearSuccPredArch` that this defines an `OrderIso` between `ι` and
the range of `toZ`. -/
def toZ (i0 i : ι) : ℤ :=
dite (i0 ≤ i) (fun hi ↦ Nat.find (exists_succ_iterate_of_le hi)) fun hi ↦
-Nat.find (exists_pred_iterate_of_le (not_le.mp hi).le)
#align to_Z toZ
theorem toZ_of_ge (hi : i0 ≤ i) : toZ i0 i = Nat.find (exists_succ_iterate_of_le hi) :=
dif_pos hi
#align to_Z_of_ge toZ_of_ge
theorem toZ_of_lt (hi : i < i0) : toZ i0 i = -Nat.find (exists_pred_iterate_of_le hi.le) :=
dif_neg (not_le.mpr hi)
#align to_Z_of_lt toZ_of_lt
@[simp]
theorem toZ_of_eq : toZ i0 i0 = 0 := by
rw [toZ_of_ge le_rfl]
norm_cast
refine le_antisymm (Nat.find_le ?_) (zero_le _)
rw [Function.iterate_zero, id]
#align to_Z_of_eq toZ_of_eq
theorem iterate_succ_toZ (i : ι) (hi : i0 ≤ i) : succ^[(toZ i0 i).toNat] i0 = i := by
rw [toZ_of_ge hi, Int.toNat_natCast]
exact Nat.find_spec (exists_succ_iterate_of_le hi)
#align iterate_succ_to_Z iterate_succ_toZ
theorem iterate_pred_toZ (i : ι) (hi : i < i0) : pred^[(-toZ i0 i).toNat] i0 = i := by
rw [toZ_of_lt hi, neg_neg, Int.toNat_natCast]
exact Nat.find_spec (exists_pred_iterate_of_le hi.le)
#align iterate_pred_to_Z iterate_pred_toZ
lemma toZ_nonneg (hi : i0 ≤ i) : 0 ≤ toZ i0 i := by rw [toZ_of_ge hi]; exact Int.natCast_nonneg _
#align to_Z_nonneg toZ_nonneg
theorem toZ_neg (hi : i < i0) : toZ i0 i < 0 := by
refine lt_of_le_of_ne ?_ ?_
· rw [toZ_of_lt hi]
omega
· by_contra h
have h_eq := iterate_pred_toZ i hi
rw [← h_eq, h] at hi
simp only [neg_zero, Int.toNat_zero, Function.iterate_zero, id, lt_self_iff_false] at hi
#align to_Z_neg toZ_neg
theorem toZ_iterate_succ_le (n : ℕ) : toZ i0 (succ^[n] i0) ≤ n := by
rw [toZ_of_ge (le_succ_iterate _ _)]
norm_cast
exact Nat.find_min' _ rfl
#align to_Z_iterate_succ_le toZ_iterate_succ_le
theorem toZ_iterate_pred_ge (n : ℕ) : -(n : ℤ) ≤ toZ i0 (pred^[n] i0) := by
rcases le_or_lt i0 (pred^[n] i0) with h | h
· have h_eq : pred^[n] i0 = i0 := le_antisymm (pred_iterate_le _ _) h
rw [h_eq, toZ_of_eq]
omega
· rw [toZ_of_lt h]
refine Int.neg_le_neg ?_
norm_cast
exact Nat.find_min' _ rfl
#align to_Z_iterate_pred_ge toZ_iterate_pred_ge
| Mathlib/Order/SuccPred/LinearLocallyFinite.lean | 250 | 259 | theorem toZ_iterate_succ_of_not_isMax (n : ℕ) (hn : ¬IsMax (succ^[n] i0)) :
toZ i0 (succ^[n] i0) = n := by |
let m := (toZ i0 (succ^[n] i0)).toNat
have h_eq : succ^[m] i0 = succ^[n] i0 := iterate_succ_toZ _ (le_succ_iterate _ _)
by_cases hmn : m = n
· nth_rw 2 [← hmn]
rw [Int.toNat_eq_max, toZ_of_ge (le_succ_iterate _ _), max_eq_left]
exact Int.natCast_nonneg _
suffices IsMax (succ^[n] i0) from absurd this hn
exact isMax_iterate_succ_of_eq_of_ne h_eq.symm (Ne.symm hmn)
|
/-
Copyright (c) 2021 Kyle Miller. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kyle Miller
-/
import Mathlib.Combinatorics.SimpleGraph.Subgraph
import Mathlib.Data.List.Rotate
#align_import combinatorics.simple_graph.connectivity from "leanprover-community/mathlib"@"b99e2d58a5e6861833fa8de11e51a81144258db4"
/-!
# Graph connectivity
In a simple graph,
* A *walk* is a finite sequence of adjacent vertices, and can be
thought of equally well as a sequence of directed edges.
* A *trail* is a walk whose edges each appear no more than once.
* A *path* is a trail whose vertices appear no more than once.
* A *cycle* is a nonempty trail whose first and last vertices are the
same and whose vertices except for the first appear no more than once.
**Warning:** graph theorists mean something different by "path" than
do homotopy theorists. A "walk" in graph theory is a "path" in
homotopy theory. Another warning: some graph theorists use "path" and
"simple path" for "walk" and "path."
Some definitions and theorems have inspiration from multigraph
counterparts in [Chou1994].
## Main definitions
* `SimpleGraph.Walk` (with accompanying pattern definitions
`SimpleGraph.Walk.nil'` and `SimpleGraph.Walk.cons'`)
* `SimpleGraph.Walk.IsTrail`, `SimpleGraph.Walk.IsPath`, and `SimpleGraph.Walk.IsCycle`.
* `SimpleGraph.Path`
* `SimpleGraph.Walk.map` and `SimpleGraph.Path.map` for the induced map on walks,
given an (injective) graph homomorphism.
* `SimpleGraph.Reachable` for the relation of whether there exists
a walk between a given pair of vertices
* `SimpleGraph.Preconnected` and `SimpleGraph.Connected` are predicates
on simple graphs for whether every vertex can be reached from every other,
and in the latter case, whether the vertex type is nonempty.
* `SimpleGraph.ConnectedComponent` is the type of connected components of
a given graph.
* `SimpleGraph.IsBridge` for whether an edge is a bridge edge
## Main statements
* `SimpleGraph.isBridge_iff_mem_and_forall_cycle_not_mem` characterizes bridge edges in terms of
there being no cycle containing them.
## Tags
walks, trails, paths, circuits, cycles, bridge edges
-/
open Function
universe u v w
namespace SimpleGraph
variable {V : Type u} {V' : Type v} {V'' : Type w}
variable (G : SimpleGraph V) (G' : SimpleGraph V') (G'' : SimpleGraph V'')
/-- A walk is a sequence of adjacent vertices. For vertices `u v : V`,
the type `walk u v` consists of all walks starting at `u` and ending at `v`.
We say that a walk *visits* the vertices it contains. The set of vertices a
walk visits is `SimpleGraph.Walk.support`.
See `SimpleGraph.Walk.nil'` and `SimpleGraph.Walk.cons'` for patterns that
can be useful in definitions since they make the vertices explicit. -/
inductive Walk : V → V → Type u
| nil {u : V} : Walk u u
| cons {u v w : V} (h : G.Adj u v) (p : Walk v w) : Walk u w
deriving DecidableEq
#align simple_graph.walk SimpleGraph.Walk
attribute [refl] Walk.nil
@[simps]
instance Walk.instInhabited (v : V) : Inhabited (G.Walk v v) := ⟨Walk.nil⟩
#align simple_graph.walk.inhabited SimpleGraph.Walk.instInhabited
/-- The one-edge walk associated to a pair of adjacent vertices. -/
@[match_pattern, reducible]
def Adj.toWalk {G : SimpleGraph V} {u v : V} (h : G.Adj u v) : G.Walk u v :=
Walk.cons h Walk.nil
#align simple_graph.adj.to_walk SimpleGraph.Adj.toWalk
namespace Walk
variable {G}
/-- Pattern to get `Walk.nil` with the vertex as an explicit argument. -/
@[match_pattern]
abbrev nil' (u : V) : G.Walk u u := Walk.nil
#align simple_graph.walk.nil' SimpleGraph.Walk.nil'
/-- Pattern to get `Walk.cons` with the vertices as explicit arguments. -/
@[match_pattern]
abbrev cons' (u v w : V) (h : G.Adj u v) (p : G.Walk v w) : G.Walk u w := Walk.cons h p
#align simple_graph.walk.cons' SimpleGraph.Walk.cons'
/-- Change the endpoints of a walk using equalities. This is helpful for relaxing
definitional equality constraints and to be able to state otherwise difficult-to-state
lemmas. While this is a simple wrapper around `Eq.rec`, it gives a canonical way to write it.
The simp-normal form is for the `copy` to be pushed outward. That way calculations can
occur within the "copy context." -/
protected def copy {u v u' v'} (p : G.Walk u v) (hu : u = u') (hv : v = v') : G.Walk u' v' :=
hu ▸ hv ▸ p
#align simple_graph.walk.copy SimpleGraph.Walk.copy
@[simp]
theorem copy_rfl_rfl {u v} (p : G.Walk u v) : p.copy rfl rfl = p := rfl
#align simple_graph.walk.copy_rfl_rfl SimpleGraph.Walk.copy_rfl_rfl
@[simp]
theorem copy_copy {u v u' v' u'' v''} (p : G.Walk u v)
(hu : u = u') (hv : v = v') (hu' : u' = u'') (hv' : v' = v'') :
(p.copy hu hv).copy hu' hv' = p.copy (hu.trans hu') (hv.trans hv') := by
subst_vars
rfl
#align simple_graph.walk.copy_copy SimpleGraph.Walk.copy_copy
@[simp]
theorem copy_nil {u u'} (hu : u = u') : (Walk.nil : G.Walk u u).copy hu hu = Walk.nil := by
subst_vars
rfl
#align simple_graph.walk.copy_nil SimpleGraph.Walk.copy_nil
theorem copy_cons {u v w u' w'} (h : G.Adj u v) (p : G.Walk v w) (hu : u = u') (hw : w = w') :
(Walk.cons h p).copy hu hw = Walk.cons (hu ▸ h) (p.copy rfl hw) := by
subst_vars
rfl
#align simple_graph.walk.copy_cons SimpleGraph.Walk.copy_cons
@[simp]
theorem cons_copy {u v w v' w'} (h : G.Adj u v) (p : G.Walk v' w') (hv : v' = v) (hw : w' = w) :
Walk.cons h (p.copy hv hw) = (Walk.cons (hv ▸ h) p).copy rfl hw := by
subst_vars
rfl
#align simple_graph.walk.cons_copy SimpleGraph.Walk.cons_copy
theorem exists_eq_cons_of_ne {u v : V} (hne : u ≠ v) :
∀ (p : G.Walk u v), ∃ (w : V) (h : G.Adj u w) (p' : G.Walk w v), p = cons h p'
| nil => (hne rfl).elim
| cons h p' => ⟨_, h, p', rfl⟩
#align simple_graph.walk.exists_eq_cons_of_ne SimpleGraph.Walk.exists_eq_cons_of_ne
/-- The length of a walk is the number of edges/darts along it. -/
def length {u v : V} : G.Walk u v → ℕ
| nil => 0
| cons _ q => q.length.succ
#align simple_graph.walk.length SimpleGraph.Walk.length
/-- The concatenation of two compatible walks. -/
@[trans]
def append {u v w : V} : G.Walk u v → G.Walk v w → G.Walk u w
| nil, q => q
| cons h p, q => cons h (p.append q)
#align simple_graph.walk.append SimpleGraph.Walk.append
/-- The reversed version of `SimpleGraph.Walk.cons`, concatenating an edge to
the end of a walk. -/
def concat {u v w : V} (p : G.Walk u v) (h : G.Adj v w) : G.Walk u w := p.append (cons h nil)
#align simple_graph.walk.concat SimpleGraph.Walk.concat
theorem concat_eq_append {u v w : V} (p : G.Walk u v) (h : G.Adj v w) :
p.concat h = p.append (cons h nil) := rfl
#align simple_graph.walk.concat_eq_append SimpleGraph.Walk.concat_eq_append
/-- The concatenation of the reverse of the first walk with the second walk. -/
protected def reverseAux {u v w : V} : G.Walk u v → G.Walk u w → G.Walk v w
| nil, q => q
| cons h p, q => Walk.reverseAux p (cons (G.symm h) q)
#align simple_graph.walk.reverse_aux SimpleGraph.Walk.reverseAux
/-- The walk in reverse. -/
@[symm]
def reverse {u v : V} (w : G.Walk u v) : G.Walk v u := w.reverseAux nil
#align simple_graph.walk.reverse SimpleGraph.Walk.reverse
/-- Get the `n`th vertex from a walk, where `n` is generally expected to be
between `0` and `p.length`, inclusive.
If `n` is greater than or equal to `p.length`, the result is the path's endpoint. -/
def getVert {u v : V} : G.Walk u v → ℕ → V
| nil, _ => u
| cons _ _, 0 => u
| cons _ q, n + 1 => q.getVert n
#align simple_graph.walk.get_vert SimpleGraph.Walk.getVert
@[simp]
theorem getVert_zero {u v} (w : G.Walk u v) : w.getVert 0 = u := by cases w <;> rfl
#align simple_graph.walk.get_vert_zero SimpleGraph.Walk.getVert_zero
theorem getVert_of_length_le {u v} (w : G.Walk u v) {i : ℕ} (hi : w.length ≤ i) :
w.getVert i = v := by
induction w generalizing i with
| nil => rfl
| cons _ _ ih =>
cases i
· cases hi
· exact ih (Nat.succ_le_succ_iff.1 hi)
#align simple_graph.walk.get_vert_of_length_le SimpleGraph.Walk.getVert_of_length_le
@[simp]
theorem getVert_length {u v} (w : G.Walk u v) : w.getVert w.length = v :=
w.getVert_of_length_le rfl.le
#align simple_graph.walk.get_vert_length SimpleGraph.Walk.getVert_length
theorem adj_getVert_succ {u v} (w : G.Walk u v) {i : ℕ} (hi : i < w.length) :
G.Adj (w.getVert i) (w.getVert (i + 1)) := by
induction w generalizing i with
| nil => cases hi
| cons hxy _ ih =>
cases i
· simp [getVert, hxy]
· exact ih (Nat.succ_lt_succ_iff.1 hi)
#align simple_graph.walk.adj_get_vert_succ SimpleGraph.Walk.adj_getVert_succ
@[simp]
theorem cons_append {u v w x : V} (h : G.Adj u v) (p : G.Walk v w) (q : G.Walk w x) :
(cons h p).append q = cons h (p.append q) := rfl
#align simple_graph.walk.cons_append SimpleGraph.Walk.cons_append
@[simp]
theorem cons_nil_append {u v w : V} (h : G.Adj u v) (p : G.Walk v w) :
(cons h nil).append p = cons h p := rfl
#align simple_graph.walk.cons_nil_append SimpleGraph.Walk.cons_nil_append
@[simp]
theorem append_nil {u v : V} (p : G.Walk u v) : p.append nil = p := by
induction p with
| nil => rfl
| cons _ _ ih => rw [cons_append, ih]
#align simple_graph.walk.append_nil SimpleGraph.Walk.append_nil
@[simp]
theorem nil_append {u v : V} (p : G.Walk u v) : nil.append p = p :=
rfl
#align simple_graph.walk.nil_append SimpleGraph.Walk.nil_append
theorem append_assoc {u v w x : V} (p : G.Walk u v) (q : G.Walk v w) (r : G.Walk w x) :
p.append (q.append r) = (p.append q).append r := by
induction p with
| nil => rfl
| cons h p' ih =>
dsimp only [append]
rw [ih]
#align simple_graph.walk.append_assoc SimpleGraph.Walk.append_assoc
@[simp]
theorem append_copy_copy {u v w u' v' w'} (p : G.Walk u v) (q : G.Walk v w)
(hu : u = u') (hv : v = v') (hw : w = w') :
(p.copy hu hv).append (q.copy hv hw) = (p.append q).copy hu hw := by
subst_vars
rfl
#align simple_graph.walk.append_copy_copy SimpleGraph.Walk.append_copy_copy
theorem concat_nil {u v : V} (h : G.Adj u v) : nil.concat h = cons h nil := rfl
#align simple_graph.walk.concat_nil SimpleGraph.Walk.concat_nil
@[simp]
theorem concat_cons {u v w x : V} (h : G.Adj u v) (p : G.Walk v w) (h' : G.Adj w x) :
(cons h p).concat h' = cons h (p.concat h') := rfl
#align simple_graph.walk.concat_cons SimpleGraph.Walk.concat_cons
theorem append_concat {u v w x : V} (p : G.Walk u v) (q : G.Walk v w) (h : G.Adj w x) :
p.append (q.concat h) = (p.append q).concat h := append_assoc _ _ _
#align simple_graph.walk.append_concat SimpleGraph.Walk.append_concat
theorem concat_append {u v w x : V} (p : G.Walk u v) (h : G.Adj v w) (q : G.Walk w x) :
(p.concat h).append q = p.append (cons h q) := by
rw [concat_eq_append, ← append_assoc, cons_nil_append]
#align simple_graph.walk.concat_append SimpleGraph.Walk.concat_append
/-- A non-trivial `cons` walk is representable as a `concat` walk. -/
theorem exists_cons_eq_concat {u v w : V} (h : G.Adj u v) (p : G.Walk v w) :
∃ (x : V) (q : G.Walk u x) (h' : G.Adj x w), cons h p = q.concat h' := by
induction p generalizing u with
| nil => exact ⟨_, nil, h, rfl⟩
| cons h' p ih =>
obtain ⟨y, q, h'', hc⟩ := ih h'
refine ⟨y, cons h q, h'', ?_⟩
rw [concat_cons, hc]
#align simple_graph.walk.exists_cons_eq_concat SimpleGraph.Walk.exists_cons_eq_concat
/-- A non-trivial `concat` walk is representable as a `cons` walk. -/
theorem exists_concat_eq_cons {u v w : V} :
∀ (p : G.Walk u v) (h : G.Adj v w),
∃ (x : V) (h' : G.Adj u x) (q : G.Walk x w), p.concat h = cons h' q
| nil, h => ⟨_, h, nil, rfl⟩
| cons h' p, h => ⟨_, h', Walk.concat p h, concat_cons _ _ _⟩
#align simple_graph.walk.exists_concat_eq_cons SimpleGraph.Walk.exists_concat_eq_cons
@[simp]
theorem reverse_nil {u : V} : (nil : G.Walk u u).reverse = nil := rfl
#align simple_graph.walk.reverse_nil SimpleGraph.Walk.reverse_nil
theorem reverse_singleton {u v : V} (h : G.Adj u v) : (cons h nil).reverse = cons (G.symm h) nil :=
rfl
#align simple_graph.walk.reverse_singleton SimpleGraph.Walk.reverse_singleton
@[simp]
theorem cons_reverseAux {u v w x : V} (p : G.Walk u v) (q : G.Walk w x) (h : G.Adj w u) :
(cons h p).reverseAux q = p.reverseAux (cons (G.symm h) q) := rfl
#align simple_graph.walk.cons_reverse_aux SimpleGraph.Walk.cons_reverseAux
@[simp]
protected theorem append_reverseAux {u v w x : V}
(p : G.Walk u v) (q : G.Walk v w) (r : G.Walk u x) :
(p.append q).reverseAux r = q.reverseAux (p.reverseAux r) := by
induction p with
| nil => rfl
| cons h _ ih => exact ih q (cons (G.symm h) r)
#align simple_graph.walk.append_reverse_aux SimpleGraph.Walk.append_reverseAux
@[simp]
protected theorem reverseAux_append {u v w x : V}
(p : G.Walk u v) (q : G.Walk u w) (r : G.Walk w x) :
(p.reverseAux q).append r = p.reverseAux (q.append r) := by
induction p with
| nil => rfl
| cons h _ ih => simp [ih (cons (G.symm h) q)]
#align simple_graph.walk.reverse_aux_append SimpleGraph.Walk.reverseAux_append
protected theorem reverseAux_eq_reverse_append {u v w : V} (p : G.Walk u v) (q : G.Walk u w) :
p.reverseAux q = p.reverse.append q := by simp [reverse]
#align simple_graph.walk.reverse_aux_eq_reverse_append SimpleGraph.Walk.reverseAux_eq_reverse_append
@[simp]
theorem reverse_cons {u v w : V} (h : G.Adj u v) (p : G.Walk v w) :
(cons h p).reverse = p.reverse.append (cons (G.symm h) nil) := by simp [reverse]
#align simple_graph.walk.reverse_cons SimpleGraph.Walk.reverse_cons
@[simp]
theorem reverse_copy {u v u' v'} (p : G.Walk u v) (hu : u = u') (hv : v = v') :
(p.copy hu hv).reverse = p.reverse.copy hv hu := by
subst_vars
rfl
#align simple_graph.walk.reverse_copy SimpleGraph.Walk.reverse_copy
@[simp]
theorem reverse_append {u v w : V} (p : G.Walk u v) (q : G.Walk v w) :
(p.append q).reverse = q.reverse.append p.reverse := by simp [reverse]
#align simple_graph.walk.reverse_append SimpleGraph.Walk.reverse_append
@[simp]
theorem reverse_concat {u v w : V} (p : G.Walk u v) (h : G.Adj v w) :
(p.concat h).reverse = cons (G.symm h) p.reverse := by simp [concat_eq_append]
#align simple_graph.walk.reverse_concat SimpleGraph.Walk.reverse_concat
@[simp]
theorem reverse_reverse {u v : V} (p : G.Walk u v) : p.reverse.reverse = p := by
induction p with
| nil => rfl
| cons _ _ ih => simp [ih]
#align simple_graph.walk.reverse_reverse SimpleGraph.Walk.reverse_reverse
@[simp]
theorem length_nil {u : V} : (nil : G.Walk u u).length = 0 := rfl
#align simple_graph.walk.length_nil SimpleGraph.Walk.length_nil
@[simp]
theorem length_cons {u v w : V} (h : G.Adj u v) (p : G.Walk v w) :
(cons h p).length = p.length + 1 := rfl
#align simple_graph.walk.length_cons SimpleGraph.Walk.length_cons
@[simp]
theorem length_copy {u v u' v'} (p : G.Walk u v) (hu : u = u') (hv : v = v') :
(p.copy hu hv).length = p.length := by
subst_vars
rfl
#align simple_graph.walk.length_copy SimpleGraph.Walk.length_copy
@[simp]
theorem length_append {u v w : V} (p : G.Walk u v) (q : G.Walk v w) :
(p.append q).length = p.length + q.length := by
induction p with
| nil => simp
| cons _ _ ih => simp [ih, add_comm, add_left_comm, add_assoc]
#align simple_graph.walk.length_append SimpleGraph.Walk.length_append
@[simp]
theorem length_concat {u v w : V} (p : G.Walk u v) (h : G.Adj v w) :
(p.concat h).length = p.length + 1 := length_append _ _
#align simple_graph.walk.length_concat SimpleGraph.Walk.length_concat
@[simp]
protected theorem length_reverseAux {u v w : V} (p : G.Walk u v) (q : G.Walk u w) :
(p.reverseAux q).length = p.length + q.length := by
induction p with
| nil => simp!
| cons _ _ ih => simp [ih, Nat.succ_add, Nat.add_assoc]
#align simple_graph.walk.length_reverse_aux SimpleGraph.Walk.length_reverseAux
@[simp]
theorem length_reverse {u v : V} (p : G.Walk u v) : p.reverse.length = p.length := by simp [reverse]
#align simple_graph.walk.length_reverse SimpleGraph.Walk.length_reverse
theorem eq_of_length_eq_zero {u v : V} : ∀ {p : G.Walk u v}, p.length = 0 → u = v
| nil, _ => rfl
#align simple_graph.walk.eq_of_length_eq_zero SimpleGraph.Walk.eq_of_length_eq_zero
theorem adj_of_length_eq_one {u v : V} : ∀ {p : G.Walk u v}, p.length = 1 → G.Adj u v
| cons h nil, _ => h
@[simp]
theorem exists_length_eq_zero_iff {u v : V} : (∃ p : G.Walk u v, p.length = 0) ↔ u = v := by
constructor
· rintro ⟨p, hp⟩
exact eq_of_length_eq_zero hp
· rintro rfl
exact ⟨nil, rfl⟩
#align simple_graph.walk.exists_length_eq_zero_iff SimpleGraph.Walk.exists_length_eq_zero_iff
@[simp]
theorem length_eq_zero_iff {u : V} {p : G.Walk u u} : p.length = 0 ↔ p = nil := by cases p <;> simp
#align simple_graph.walk.length_eq_zero_iff SimpleGraph.Walk.length_eq_zero_iff
theorem getVert_append {u v w : V} (p : G.Walk u v) (q : G.Walk v w) (i : ℕ) :
(p.append q).getVert i = if i < p.length then p.getVert i else q.getVert (i - p.length) := by
induction p generalizing i with
| nil => simp
| cons h p ih => cases i <;> simp [getVert, ih, Nat.succ_lt_succ_iff]
theorem getVert_reverse {u v : V} (p : G.Walk u v) (i : ℕ) :
p.reverse.getVert i = p.getVert (p.length - i) := by
induction p with
| nil => rfl
| cons h p ih =>
simp only [reverse_cons, getVert_append, length_reverse, ih, length_cons]
split_ifs
next hi =>
rw [Nat.succ_sub hi.le]
simp [getVert]
next hi =>
obtain rfl | hi' := Nat.eq_or_lt_of_not_lt hi
· simp [getVert]
· rw [Nat.eq_add_of_sub_eq (Nat.sub_pos_of_lt hi') rfl, Nat.sub_eq_zero_of_le hi']
simp [getVert]
section ConcatRec
variable {motive : ∀ u v : V, G.Walk u v → Sort*} (Hnil : ∀ {u : V}, motive u u nil)
(Hconcat : ∀ {u v w : V} (p : G.Walk u v) (h : G.Adj v w), motive u v p → motive u w (p.concat h))
/-- Auxiliary definition for `SimpleGraph.Walk.concatRec` -/
def concatRecAux {u v : V} : (p : G.Walk u v) → motive v u p.reverse
| nil => Hnil
| cons h p => reverse_cons h p ▸ Hconcat p.reverse h.symm (concatRecAux p)
#align simple_graph.walk.concat_rec_aux SimpleGraph.Walk.concatRecAux
/-- Recursor on walks by inducting on `SimpleGraph.Walk.concat`.
This is inducting from the opposite end of the walk compared
to `SimpleGraph.Walk.rec`, which inducts on `SimpleGraph.Walk.cons`. -/
@[elab_as_elim]
def concatRec {u v : V} (p : G.Walk u v) : motive u v p :=
reverse_reverse p ▸ concatRecAux @Hnil @Hconcat p.reverse
#align simple_graph.walk.concat_rec SimpleGraph.Walk.concatRec
@[simp]
theorem concatRec_nil (u : V) :
@concatRec _ _ motive @Hnil @Hconcat _ _ (nil : G.Walk u u) = Hnil := rfl
#align simple_graph.walk.concat_rec_nil SimpleGraph.Walk.concatRec_nil
@[simp]
theorem concatRec_concat {u v w : V} (p : G.Walk u v) (h : G.Adj v w) :
@concatRec _ _ motive @Hnil @Hconcat _ _ (p.concat h) =
Hconcat p h (concatRec @Hnil @Hconcat p) := by
simp only [concatRec]
apply eq_of_heq
apply rec_heq_of_heq
trans concatRecAux @Hnil @Hconcat (cons h.symm p.reverse)
· congr
simp
· rw [concatRecAux, rec_heq_iff_heq]
congr <;> simp [heq_rec_iff_heq]
#align simple_graph.walk.concat_rec_concat SimpleGraph.Walk.concatRec_concat
end ConcatRec
| Mathlib/Combinatorics/SimpleGraph/Connectivity.lean | 499 | 500 | theorem concat_ne_nil {u v : V} (p : G.Walk u v) (h : G.Adj v u) : p.concat h ≠ nil := by |
cases p <;> simp [concat]
|
/-
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, Scott Morrison, Jens Wagemaker
-/
import Mathlib.Algebra.Algebra.Pi
import Mathlib.Algebra.Polynomial.Eval
import Mathlib.RingTheory.Adjoin.Basic
#align_import data.polynomial.algebra_map from "leanprover-community/mathlib"@"e064a7bf82ad94c3c17b5128bbd860d1ec34874e"
/-!
# Theory of univariate polynomials
We show that `A[X]` is an R-algebra when `A` is an R-algebra.
We promote `eval₂` to an algebra hom in `aeval`.
-/
noncomputable section
open Finset
open Polynomial
namespace Polynomial
universe u v w z
variable {R : Type u} {S : Type v} {T : Type w} {A : Type z} {A' B : Type*} {a b : R} {n : ℕ}
section CommSemiring
variable [CommSemiring R] [Semiring A] [Semiring B] [Algebra R A] [Algebra R B]
variable {p q r : R[X]}
/-- Note that this instance also provides `Algebra R R[X]`. -/
instance algebraOfAlgebra : Algebra R A[X] where
smul_def' r p :=
toFinsupp_injective <| by
dsimp only [RingHom.toFun_eq_coe, RingHom.comp_apply]
rw [toFinsupp_smul, toFinsupp_mul, toFinsupp_C]
exact Algebra.smul_def' _ _
commutes' r p :=
toFinsupp_injective <| by
dsimp only [RingHom.toFun_eq_coe, RingHom.comp_apply]
simp_rw [toFinsupp_mul, toFinsupp_C]
convert Algebra.commutes' r p.toFinsupp
toRingHom := C.comp (algebraMap R A)
#align polynomial.algebra_of_algebra Polynomial.algebraOfAlgebra
@[simp]
theorem algebraMap_apply (r : R) : algebraMap R A[X] r = C (algebraMap R A r) :=
rfl
#align polynomial.algebra_map_apply Polynomial.algebraMap_apply
@[simp]
theorem toFinsupp_algebraMap (r : R) : (algebraMap R A[X] r).toFinsupp = algebraMap R _ r :=
show toFinsupp (C (algebraMap _ _ r)) = _ by
rw [toFinsupp_C]
rfl
#align polynomial.to_finsupp_algebra_map Polynomial.toFinsupp_algebraMap
theorem ofFinsupp_algebraMap (r : R) : (⟨algebraMap R _ r⟩ : A[X]) = algebraMap R A[X] r :=
toFinsupp_injective (toFinsupp_algebraMap _).symm
#align polynomial.of_finsupp_algebra_map Polynomial.ofFinsupp_algebraMap
/-- When we have `[CommSemiring R]`, the function `C` is the same as `algebraMap R R[X]`.
(But note that `C` is defined when `R` is not necessarily commutative, in which case
`algebraMap` is not available.)
-/
theorem C_eq_algebraMap (r : R) : C r = algebraMap R R[X] r :=
rfl
set_option linter.uppercaseLean3 false in
#align polynomial.C_eq_algebra_map Polynomial.C_eq_algebraMap
@[simp]
theorem algebraMap_eq : algebraMap R R[X] = C :=
rfl
/-- `Polynomial.C` as an `AlgHom`. -/
@[simps! apply]
def CAlgHom : A →ₐ[R] A[X] where
toRingHom := C
commutes' _ := rfl
/-- Extensionality lemma for algebra maps out of `A'[X]` over a smaller base ring than `A'`
-/
@[ext 1100]
theorem algHom_ext' {f g : A[X] →ₐ[R] B}
(hC : f.comp CAlgHom = g.comp CAlgHom)
(hX : f X = g X) : f = g :=
AlgHom.coe_ringHom_injective (ringHom_ext' (congr_arg AlgHom.toRingHom hC) hX)
#align polynomial.alg_hom_ext' Polynomial.algHom_ext'
variable (R)
open AddMonoidAlgebra in
/-- Algebra 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 toFinsuppIsoAlg : R[X] ≃ₐ[R] R[ℕ] :=
{ toFinsuppIso R with
commutes' := fun r => by
dsimp }
#align polynomial.to_finsupp_iso_alg Polynomial.toFinsuppIsoAlg
variable {R}
instance subalgebraNontrivial [Nontrivial A] : Nontrivial (Subalgebra R A[X]) :=
⟨⟨⊥, ⊤, by
rw [Ne, SetLike.ext_iff, not_forall]
refine ⟨X, ?_⟩
simp only [Algebra.mem_bot, not_exists, Set.mem_range, iff_true_iff, Algebra.mem_top,
algebraMap_apply, not_forall]
intro x
rw [ext_iff, not_forall]
refine ⟨1, ?_⟩
simp [coeff_C]⟩⟩
@[simp]
theorem algHom_eval₂_algebraMap {R A B : Type*} [CommSemiring R] [Semiring A] [Semiring B]
[Algebra R A] [Algebra R B] (p : R[X]) (f : A →ₐ[R] B) (a : A) :
f (eval₂ (algebraMap R A) a p) = eval₂ (algebraMap R B) (f a) p := by
simp only [eval₂_eq_sum, sum_def]
simp only [f.map_sum, f.map_mul, f.map_pow, eq_intCast, map_intCast, AlgHom.commutes]
#align polynomial.alg_hom_eval₂_algebra_map Polynomial.algHom_eval₂_algebraMap
@[simp]
| Mathlib/Algebra/Polynomial/AlgebraMap.lean | 131 | 136 | theorem eval₂_algebraMap_X {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A] (p : R[X])
(f : R[X] →ₐ[R] A) : eval₂ (algebraMap R A) (f X) p = f p := by |
conv_rhs => rw [← Polynomial.sum_C_mul_X_pow_eq p]
simp only [eval₂_eq_sum, sum_def]
simp only [f.map_sum, f.map_mul, f.map_pow, eq_intCast, map_intCast]
simp [Polynomial.C_eq_algebraMap]
|
/-
Copyright (c) 2022 Andrew Yang. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Andrew Yang
-/
import Mathlib.AlgebraicGeometry.Gluing
import Mathlib.CategoryTheory.Limits.Opposites
import Mathlib.AlgebraicGeometry.AffineScheme
import Mathlib.CategoryTheory.Limits.Shapes.Diagonal
#align_import algebraic_geometry.pullbacks from "leanprover-community/mathlib"@"7316286ff2942aa14e540add9058c6b0aa1c8070"
/-!
# Fibred products of schemes
In this file we construct the fibred product of schemes via gluing.
We roughly follow [har77] Theorem 3.3.
In particular, the main construction is to show that for an open cover `{ Uᵢ }` of `X`, if there
exist fibred products `Uᵢ ×[Z] Y` for each `i`, then there exists a fibred product `X ×[Z] Y`.
Then, for constructing the fibred product for arbitrary schemes `X, Y, Z`, we can use the
construction to reduce to the case where `X, Y, Z` are all affine, where fibred products are
constructed via tensor products.
-/
set_option linter.uppercaseLean3 false
universe v u
noncomputable section
open CategoryTheory CategoryTheory.Limits AlgebraicGeometry
namespace AlgebraicGeometry.Scheme
namespace Pullback
variable {C : Type u} [Category.{v} C]
variable {X Y Z : Scheme.{u}} (𝒰 : OpenCover.{u} X) (f : X ⟶ Z) (g : Y ⟶ Z)
variable [∀ i, HasPullback (𝒰.map i ≫ f) g]
/-- The intersection of `Uᵢ ×[Z] Y` and `Uⱼ ×[Z] Y` is given by (Uᵢ ×[Z] Y) ×[X] Uⱼ -/
def v (i j : 𝒰.J) : Scheme :=
pullback ((pullback.fst : pullback (𝒰.map i ≫ f) g ⟶ _) ≫ 𝒰.map i) (𝒰.map j)
#align algebraic_geometry.Scheme.pullback.V AlgebraicGeometry.Scheme.Pullback.v
/-- The canonical transition map `(Uᵢ ×[Z] Y) ×[X] Uⱼ ⟶ (Uⱼ ×[Z] Y) ×[X] Uᵢ` given by the fact
that pullbacks are associative and symmetric. -/
def t (i j : 𝒰.J) : v 𝒰 f g i j ⟶ v 𝒰 f g j i := by
have : HasPullback (pullback.snd ≫ 𝒰.map i ≫ f) g :=
hasPullback_assoc_symm (𝒰.map j) (𝒰.map i) (𝒰.map i ≫ f) g
have : HasPullback (pullback.snd ≫ 𝒰.map j ≫ f) g :=
hasPullback_assoc_symm (𝒰.map i) (𝒰.map j) (𝒰.map j ≫ f) g
refine (pullbackSymmetry ..).hom ≫ (pullbackAssoc ..).inv ≫ ?_
refine ?_ ≫ (pullbackAssoc ..).hom ≫ (pullbackSymmetry ..).hom
refine pullback.map _ _ _ _ (pullbackSymmetry _ _).hom (𝟙 _) (𝟙 _) ?_ ?_
· rw [pullbackSymmetry_hom_comp_snd_assoc, pullback.condition_assoc, Category.comp_id]
· rw [Category.comp_id, Category.id_comp]
#align algebraic_geometry.Scheme.pullback.t AlgebraicGeometry.Scheme.Pullback.t
@[simp, reassoc]
theorem t_fst_fst (i j : 𝒰.J) : t 𝒰 f g i j ≫ pullback.fst ≫ pullback.fst = pullback.snd := by
simp only [t, Category.assoc, pullbackSymmetry_hom_comp_fst_assoc, pullbackAssoc_hom_snd_fst,
pullback.lift_fst_assoc, pullbackSymmetry_hom_comp_snd, pullbackAssoc_inv_fst_fst,
pullbackSymmetry_hom_comp_fst]
#align algebraic_geometry.Scheme.pullback.t_fst_fst AlgebraicGeometry.Scheme.Pullback.t_fst_fst
@[simp, reassoc]
theorem t_fst_snd (i j : 𝒰.J) :
t 𝒰 f g i j ≫ pullback.fst ≫ pullback.snd = pullback.fst ≫ pullback.snd := by
simp only [t, Category.assoc, pullbackSymmetry_hom_comp_fst_assoc, pullbackAssoc_hom_snd_snd,
pullback.lift_snd, Category.comp_id, pullbackAssoc_inv_snd, pullbackSymmetry_hom_comp_snd_assoc]
#align algebraic_geometry.Scheme.pullback.t_fst_snd AlgebraicGeometry.Scheme.Pullback.t_fst_snd
@[simp, reassoc]
theorem t_snd (i j : 𝒰.J) : t 𝒰 f g i j ≫ pullback.snd = pullback.fst ≫ pullback.fst := by
simp only [t, Category.assoc, pullbackSymmetry_hom_comp_snd, pullbackAssoc_hom_fst,
pullback.lift_fst_assoc, pullbackSymmetry_hom_comp_fst, pullbackAssoc_inv_fst_snd,
pullbackSymmetry_hom_comp_snd_assoc]
#align algebraic_geometry.Scheme.pullback.t_snd AlgebraicGeometry.Scheme.Pullback.t_snd
theorem t_id (i : 𝒰.J) : t 𝒰 f g i i = 𝟙 _ := by
apply pullback.hom_ext <;> rw [Category.id_comp]
· apply pullback.hom_ext
· rw [← cancel_mono (𝒰.map i)]; simp only [pullback.condition, Category.assoc, t_fst_fst]
· simp only [Category.assoc, t_fst_snd]
· rw [← cancel_mono (𝒰.map i)]; simp only [pullback.condition, t_snd, Category.assoc]
#align algebraic_geometry.Scheme.pullback.t_id AlgebraicGeometry.Scheme.Pullback.t_id
/-- The inclusion map of `V i j = (Uᵢ ×[Z] Y) ×[X] Uⱼ ⟶ Uᵢ ×[Z] Y`-/
abbrev fV (i j : 𝒰.J) : v 𝒰 f g i j ⟶ pullback (𝒰.map i ≫ f) g :=
pullback.fst
#align algebraic_geometry.Scheme.pullback.fV AlgebraicGeometry.Scheme.Pullback.fV
/-- The map `((Xᵢ ×[Z] Y) ×[X] Xⱼ) ×[Xᵢ ×[Z] Y] ((Xᵢ ×[Z] Y) ×[X] Xₖ)` ⟶
`((Xⱼ ×[Z] Y) ×[X] Xₖ) ×[Xⱼ ×[Z] Y] ((Xⱼ ×[Z] Y) ×[X] Xᵢ)` needed for gluing -/
def t' (i j k : 𝒰.J) :
pullback (fV 𝒰 f g i j) (fV 𝒰 f g i k) ⟶ pullback (fV 𝒰 f g j k) (fV 𝒰 f g j i) := by
refine (pullbackRightPullbackFstIso ..).hom ≫ ?_
refine ?_ ≫ (pullbackSymmetry _ _).hom
refine ?_ ≫ (pullbackRightPullbackFstIso ..).inv
refine pullback.map _ _ _ _ (t 𝒰 f g i j) (𝟙 _) (𝟙 _) ?_ ?_
· simp_rw [Category.comp_id, t_fst_fst_assoc, ← pullback.condition]
· rw [Category.comp_id, Category.id_comp]
#align algebraic_geometry.Scheme.pullback.t' AlgebraicGeometry.Scheme.Pullback.t'
@[simp, reassoc]
theorem t'_fst_fst_fst (i j k : 𝒰.J) :
t' 𝒰 f g i j k ≫ pullback.fst ≫ pullback.fst ≫ pullback.fst = pullback.fst ≫ pullback.snd := by
simp only [t', Category.assoc, pullbackSymmetry_hom_comp_fst_assoc,
pullbackRightPullbackFstIso_inv_snd_fst_assoc, pullback.lift_fst_assoc, t_fst_fst,
pullbackRightPullbackFstIso_hom_fst_assoc]
#align algebraic_geometry.Scheme.pullback.t'_fst_fst_fst AlgebraicGeometry.Scheme.Pullback.t'_fst_fst_fst
@[simp, reassoc]
theorem t'_fst_fst_snd (i j k : 𝒰.J) :
t' 𝒰 f g i j k ≫ pullback.fst ≫ pullback.fst ≫ pullback.snd =
pullback.fst ≫ pullback.fst ≫ pullback.snd := by
simp only [t', Category.assoc, pullbackSymmetry_hom_comp_fst_assoc,
pullbackRightPullbackFstIso_inv_snd_fst_assoc, pullback.lift_fst_assoc, t_fst_snd,
pullbackRightPullbackFstIso_hom_fst_assoc]
#align algebraic_geometry.Scheme.pullback.t'_fst_fst_snd AlgebraicGeometry.Scheme.Pullback.t'_fst_fst_snd
@[simp, reassoc]
theorem t'_fst_snd (i j k : 𝒰.J) :
t' 𝒰 f g i j k ≫ pullback.fst ≫ pullback.snd = pullback.snd ≫ pullback.snd := by
simp only [t', Category.assoc, pullbackSymmetry_hom_comp_fst_assoc,
pullbackRightPullbackFstIso_inv_snd_snd, pullback.lift_snd, Category.comp_id,
pullbackRightPullbackFstIso_hom_snd]
#align algebraic_geometry.Scheme.pullback.t'_fst_snd AlgebraicGeometry.Scheme.Pullback.t'_fst_snd
@[simp, reassoc]
theorem t'_snd_fst_fst (i j k : 𝒰.J) :
t' 𝒰 f g i j k ≫ pullback.snd ≫ pullback.fst ≫ pullback.fst = pullback.fst ≫ pullback.snd := by
simp only [t', Category.assoc, pullbackSymmetry_hom_comp_snd_assoc,
pullbackRightPullbackFstIso_inv_fst_assoc, pullback.lift_fst_assoc, t_fst_fst,
pullbackRightPullbackFstIso_hom_fst_assoc]
#align algebraic_geometry.Scheme.pullback.t'_snd_fst_fst AlgebraicGeometry.Scheme.Pullback.t'_snd_fst_fst
@[simp, reassoc]
theorem t'_snd_fst_snd (i j k : 𝒰.J) :
t' 𝒰 f g i j k ≫ pullback.snd ≫ pullback.fst ≫ pullback.snd =
pullback.fst ≫ pullback.fst ≫ pullback.snd := by
simp only [t', Category.assoc, pullbackSymmetry_hom_comp_snd_assoc,
pullbackRightPullbackFstIso_inv_fst_assoc, pullback.lift_fst_assoc, t_fst_snd,
pullbackRightPullbackFstIso_hom_fst_assoc]
#align algebraic_geometry.Scheme.pullback.t'_snd_fst_snd AlgebraicGeometry.Scheme.Pullback.t'_snd_fst_snd
@[simp, reassoc]
theorem t'_snd_snd (i j k : 𝒰.J) :
t' 𝒰 f g i j k ≫ pullback.snd ≫ pullback.snd = pullback.fst ≫ pullback.fst ≫ pullback.fst := by
simp only [t', Category.assoc, pullbackSymmetry_hom_comp_snd_assoc,
pullbackRightPullbackFstIso_inv_fst_assoc, pullback.lift_fst_assoc, t_snd,
pullbackRightPullbackFstIso_hom_fst_assoc]
#align algebraic_geometry.Scheme.pullback.t'_snd_snd AlgebraicGeometry.Scheme.Pullback.t'_snd_snd
theorem cocycle_fst_fst_fst (i j k : 𝒰.J) :
t' 𝒰 f g i j k ≫ t' 𝒰 f g j k i ≫ t' 𝒰 f g k i j ≫ pullback.fst ≫ pullback.fst ≫ pullback.fst =
pullback.fst ≫ pullback.fst ≫ pullback.fst := by
simp only [t'_fst_fst_fst, t'_fst_snd, t'_snd_snd]
#align algebraic_geometry.Scheme.pullback.cocycle_fst_fst_fst AlgebraicGeometry.Scheme.Pullback.cocycle_fst_fst_fst
theorem cocycle_fst_fst_snd (i j k : 𝒰.J) :
t' 𝒰 f g i j k ≫ t' 𝒰 f g j k i ≫ t' 𝒰 f g k i j ≫ pullback.fst ≫ pullback.fst ≫ pullback.snd =
pullback.fst ≫ pullback.fst ≫ pullback.snd := by
simp only [t'_fst_fst_snd]
#align algebraic_geometry.Scheme.pullback.cocycle_fst_fst_snd AlgebraicGeometry.Scheme.Pullback.cocycle_fst_fst_snd
theorem cocycle_fst_snd (i j k : 𝒰.J) :
t' 𝒰 f g i j k ≫ t' 𝒰 f g j k i ≫ t' 𝒰 f g k i j ≫ pullback.fst ≫ pullback.snd =
pullback.fst ≫ pullback.snd := by
simp only [t'_fst_snd, t'_snd_snd, t'_fst_fst_fst]
#align algebraic_geometry.Scheme.pullback.cocycle_fst_snd AlgebraicGeometry.Scheme.Pullback.cocycle_fst_snd
theorem cocycle_snd_fst_fst (i j k : 𝒰.J) :
t' 𝒰 f g i j k ≫ t' 𝒰 f g j k i ≫ t' 𝒰 f g k i j ≫ pullback.snd ≫ pullback.fst ≫ pullback.fst =
pullback.snd ≫ pullback.fst ≫ pullback.fst := by
rw [← cancel_mono (𝒰.map i)]
simp only [pullback.condition_assoc, t'_snd_fst_fst, t'_fst_snd, t'_snd_snd]
#align algebraic_geometry.Scheme.pullback.cocycle_snd_fst_fst AlgebraicGeometry.Scheme.Pullback.cocycle_snd_fst_fst
| Mathlib/AlgebraicGeometry/Pullbacks.lean | 184 | 187 | theorem cocycle_snd_fst_snd (i j k : 𝒰.J) :
t' 𝒰 f g i j k ≫ t' 𝒰 f g j k i ≫ t' 𝒰 f g k i j ≫ pullback.snd ≫ pullback.fst ≫ pullback.snd =
pullback.snd ≫ pullback.fst ≫ pullback.snd := by |
simp only [pullback.condition_assoc, t'_snd_fst_snd]
|
/-
Copyright (c) 2021 Aaron Anderson, Jesse Michael Han, Floris van Doorn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Aaron Anderson, Jesse Michael Han, Floris van Doorn
-/
import Mathlib.Data.Finset.Basic
import Mathlib.ModelTheory.Syntax
import Mathlib.Data.List.ProdSigma
#align_import model_theory.semantics from "leanprover-community/mathlib"@"d565b3df44619c1498326936be16f1a935df0728"
/-!
# Basics on First-Order Semantics
This file defines the interpretations of first-order terms, formulas, sentences, and theories
in a style inspired by the [Flypitch project](https://flypitch.github.io/).
## Main Definitions
* `FirstOrder.Language.Term.realize` is defined so that `t.realize v` is the term `t` evaluated at
variables `v`.
* `FirstOrder.Language.BoundedFormula.Realize` is defined so that `φ.Realize v xs` is the bounded
formula `φ` evaluated at tuples of variables `v` and `xs`.
* `FirstOrder.Language.Formula.Realize` is defined so that `φ.Realize v` is the formula `φ`
evaluated at variables `v`.
* `FirstOrder.Language.Sentence.Realize` is defined so that `φ.Realize M` is the sentence `φ`
evaluated in the structure `M`. Also denoted `M ⊨ φ`.
* `FirstOrder.Language.Theory.Model` is defined so that `T.Model M` is true if and only if every
sentence of `T` is realized in `M`. Also denoted `T ⊨ φ`.
## Main Results
* `FirstOrder.Language.BoundedFormula.realize_toPrenex` shows that the prenex normal form of a
formula has the same realization as the original formula.
* Several results in this file show that syntactic constructions such as `relabel`, `castLE`,
`liftAt`, `subst`, and the actions of language maps commute with realization of terms, formulas,
sentences, and theories.
## Implementation Notes
* Formulas use a modified version of de Bruijn variables. Specifically, a `L.BoundedFormula α n`
is a formula with some variables indexed by a type `α`, which cannot be quantified over, and some
indexed by `Fin n`, which can. For any `φ : L.BoundedFormula α (n + 1)`, we define the formula
`∀' φ : L.BoundedFormula α n` by universally quantifying over the variable indexed by
`n : Fin (n + 1)`.
## References
For the Flypitch project:
- [J. Han, F. van Doorn, *A formal proof of the independence of the continuum hypothesis*]
[flypitch_cpp]
- [J. Han, F. van Doorn, *A formalization of forcing and the unprovability of
the continuum hypothesis*][flypitch_itp]
-/
universe u v w u' v'
namespace FirstOrder
namespace Language
variable {L : Language.{u, v}} {L' : Language}
variable {M : Type w} {N P : Type*} [L.Structure M] [L.Structure N] [L.Structure P]
variable {α : Type u'} {β : Type v'} {γ : Type*}
open FirstOrder Cardinal
open Structure Cardinal Fin
namespace Term
-- Porting note: universes in different order
/-- A term `t` with variables indexed by `α` can be evaluated by giving a value to each variable. -/
def realize (v : α → M) : ∀ _t : L.Term α, M
| var k => v k
| func f ts => funMap f fun i => (ts i).realize v
#align first_order.language.term.realize FirstOrder.Language.Term.realize
/- Porting note: The equation lemma of `realize` is too strong; it simplifies terms like the LHS of
`realize_functions_apply₁`. Even `eqns` can't fix this. We removed `simp` attr from `realize` and
prepare new simp lemmas for `realize`. -/
@[simp]
theorem realize_var (v : α → M) (k) : realize v (var k : L.Term α) = v k := rfl
@[simp]
theorem realize_func (v : α → M) {n} (f : L.Functions n) (ts) :
realize v (func f ts : L.Term α) = funMap f fun i => (ts i).realize v := rfl
@[simp]
theorem realize_relabel {t : L.Term α} {g : α → β} {v : β → M} :
(t.relabel g).realize v = t.realize (v ∘ g) := by
induction' t with _ n f ts ih
· rfl
· simp [ih]
#align first_order.language.term.realize_relabel FirstOrder.Language.Term.realize_relabel
@[simp]
theorem realize_liftAt {n n' m : ℕ} {t : L.Term (Sum α (Fin n))} {v : Sum α (Fin (n + n')) → M} :
(t.liftAt n' m).realize v =
t.realize (v ∘ Sum.map id fun i : Fin _ =>
if ↑i < m then Fin.castAdd n' i else Fin.addNat i n') :=
realize_relabel
#align first_order.language.term.realize_lift_at FirstOrder.Language.Term.realize_liftAt
@[simp]
theorem realize_constants {c : L.Constants} {v : α → M} : c.term.realize v = c :=
funMap_eq_coe_constants
#align first_order.language.term.realize_constants FirstOrder.Language.Term.realize_constants
@[simp]
theorem realize_functions_apply₁ {f : L.Functions 1} {t : L.Term α} {v : α → M} :
(f.apply₁ t).realize v = funMap f ![t.realize v] := by
rw [Functions.apply₁, Term.realize]
refine congr rfl (funext fun i => ?_)
simp only [Matrix.cons_val_fin_one]
#align first_order.language.term.realize_functions_apply₁ FirstOrder.Language.Term.realize_functions_apply₁
@[simp]
theorem realize_functions_apply₂ {f : L.Functions 2} {t₁ t₂ : L.Term α} {v : α → M} :
(f.apply₂ t₁ t₂).realize v = funMap f ![t₁.realize v, t₂.realize v] := by
rw [Functions.apply₂, Term.realize]
refine congr rfl (funext (Fin.cases ?_ ?_))
· simp only [Matrix.cons_val_zero]
· simp only [Matrix.cons_val_succ, Matrix.cons_val_fin_one, forall_const]
#align first_order.language.term.realize_functions_apply₂ FirstOrder.Language.Term.realize_functions_apply₂
theorem realize_con {A : Set M} {a : A} {v : α → M} : (L.con a).term.realize v = a :=
rfl
#align first_order.language.term.realize_con FirstOrder.Language.Term.realize_con
@[simp]
theorem realize_subst {t : L.Term α} {tf : α → L.Term β} {v : β → M} :
(t.subst tf).realize v = t.realize fun a => (tf a).realize v := by
induction' t with _ _ _ _ ih
· rfl
· simp [ih]
#align first_order.language.term.realize_subst FirstOrder.Language.Term.realize_subst
@[simp]
theorem realize_restrictVar [DecidableEq α] {t : L.Term α} {s : Set α} (h : ↑t.varFinset ⊆ s)
{v : α → M} : (t.restrictVar (Set.inclusion h)).realize (v ∘ (↑)) = t.realize v := by
induction' t with _ _ _ _ ih
· rfl
· simp_rw [varFinset, Finset.coe_biUnion, Set.iUnion_subset_iff] at h
exact congr rfl (funext fun i => ih i (h i (Finset.mem_univ i)))
#align first_order.language.term.realize_restrict_var FirstOrder.Language.Term.realize_restrictVar
@[simp]
theorem realize_restrictVarLeft [DecidableEq α] {γ : Type*} {t : L.Term (Sum α γ)} {s : Set α}
(h : ↑t.varFinsetLeft ⊆ s) {v : α → M} {xs : γ → M} :
(t.restrictVarLeft (Set.inclusion h)).realize (Sum.elim (v ∘ (↑)) xs) =
t.realize (Sum.elim v xs) := by
induction' t with a _ _ _ ih
· cases a <;> rfl
· simp_rw [varFinsetLeft, Finset.coe_biUnion, Set.iUnion_subset_iff] at h
exact congr rfl (funext fun i => ih i (h i (Finset.mem_univ i)))
#align first_order.language.term.realize_restrict_var_left FirstOrder.Language.Term.realize_restrictVarLeft
@[simp]
theorem realize_constantsToVars [L[[α]].Structure M] [(lhomWithConstants L α).IsExpansionOn M]
{t : L[[α]].Term β} {v : β → M} :
t.constantsToVars.realize (Sum.elim (fun a => ↑(L.con a)) v) = t.realize v := by
induction' t with _ n f ts ih
· simp
· cases n
· cases f
· simp only [realize, ih, Nat.zero_eq, constantsOn, mk₂_Functions]
-- Porting note: below lemma does not work with simp for some reason
rw [withConstants_funMap_sum_inl]
· simp only [realize, constantsToVars, Sum.elim_inl, funMap_eq_coe_constants]
rfl
· cases' f with _ f
· simp only [realize, ih, constantsOn, mk₂_Functions]
-- Porting note: below lemma does not work with simp for some reason
rw [withConstants_funMap_sum_inl]
· exact isEmptyElim f
#align first_order.language.term.realize_constants_to_vars FirstOrder.Language.Term.realize_constantsToVars
@[simp]
theorem realize_varsToConstants [L[[α]].Structure M] [(lhomWithConstants L α).IsExpansionOn M]
{t : L.Term (Sum α β)} {v : β → M} :
t.varsToConstants.realize v = t.realize (Sum.elim (fun a => ↑(L.con a)) v) := by
induction' t with ab n f ts ih
· cases' ab with a b
-- Porting note: both cases were `simp [Language.con]`
· simp [Language.con, realize, funMap_eq_coe_constants]
· simp [realize, constantMap]
· simp only [realize, constantsOn, mk₂_Functions, ih]
-- Porting note: below lemma does not work with simp for some reason
rw [withConstants_funMap_sum_inl]
#align first_order.language.term.realize_vars_to_constants FirstOrder.Language.Term.realize_varsToConstants
theorem realize_constantsVarsEquivLeft [L[[α]].Structure M]
[(lhomWithConstants L α).IsExpansionOn M] {n} {t : L[[α]].Term (Sum β (Fin n))} {v : β → M}
{xs : Fin n → M} :
(constantsVarsEquivLeft t).realize (Sum.elim (Sum.elim (fun a => ↑(L.con a)) v) xs) =
t.realize (Sum.elim v xs) := by
simp only [constantsVarsEquivLeft, realize_relabel, Equiv.coe_trans, Function.comp_apply,
constantsVarsEquiv_apply, relabelEquiv_symm_apply]
refine _root_.trans ?_ realize_constantsToVars
rcongr x
rcases x with (a | (b | i)) <;> simp
#align first_order.language.term.realize_constants_vars_equiv_left FirstOrder.Language.Term.realize_constantsVarsEquivLeft
end Term
namespace LHom
@[simp]
theorem realize_onTerm [L'.Structure M] (φ : L →ᴸ L') [φ.IsExpansionOn M] (t : L.Term α)
(v : α → M) : (φ.onTerm t).realize v = t.realize v := by
induction' t with _ n f ts ih
· rfl
· simp only [Term.realize, LHom.onTerm, LHom.map_onFunction, ih]
set_option linter.uppercaseLean3 false in
#align first_order.language.Lhom.realize_on_term FirstOrder.Language.LHom.realize_onTerm
end LHom
@[simp]
theorem Hom.realize_term (g : M →[L] N) {t : L.Term α} {v : α → M} :
t.realize (g ∘ v) = g (t.realize v) := by
induction t
· rfl
· rw [Term.realize, Term.realize, g.map_fun]
refine congr rfl ?_
ext x
simp [*]
#align first_order.language.hom.realize_term FirstOrder.Language.Hom.realize_term
@[simp]
theorem Embedding.realize_term {v : α → M} (t : L.Term α) (g : M ↪[L] N) :
t.realize (g ∘ v) = g (t.realize v) :=
g.toHom.realize_term
#align first_order.language.embedding.realize_term FirstOrder.Language.Embedding.realize_term
@[simp]
theorem Equiv.realize_term {v : α → M} (t : L.Term α) (g : M ≃[L] N) :
t.realize (g ∘ v) = g (t.realize v) :=
g.toHom.realize_term
#align first_order.language.equiv.realize_term FirstOrder.Language.Equiv.realize_term
variable {n : ℕ}
namespace BoundedFormula
open Term
-- Porting note: universes in different order
/-- A bounded formula can be evaluated as true or false by giving values to each free variable. -/
def Realize : ∀ {l} (_f : L.BoundedFormula α l) (_v : α → M) (_xs : Fin l → M), Prop
| _, falsum, _v, _xs => False
| _, equal t₁ t₂, v, xs => t₁.realize (Sum.elim v xs) = t₂.realize (Sum.elim v xs)
| _, rel R ts, v, xs => RelMap R fun i => (ts i).realize (Sum.elim v xs)
| _, imp f₁ f₂, v, xs => Realize f₁ v xs → Realize f₂ v xs
| _, all f, v, xs => ∀ x : M, Realize f v (snoc xs x)
#align first_order.language.bounded_formula.realize FirstOrder.Language.BoundedFormula.Realize
variable {l : ℕ} {φ ψ : L.BoundedFormula α l} {θ : L.BoundedFormula α l.succ}
variable {v : α → M} {xs : Fin l → M}
@[simp]
theorem realize_bot : (⊥ : L.BoundedFormula α l).Realize v xs ↔ False :=
Iff.rfl
#align first_order.language.bounded_formula.realize_bot FirstOrder.Language.BoundedFormula.realize_bot
@[simp]
theorem realize_not : φ.not.Realize v xs ↔ ¬φ.Realize v xs :=
Iff.rfl
#align first_order.language.bounded_formula.realize_not FirstOrder.Language.BoundedFormula.realize_not
@[simp]
theorem realize_bdEqual (t₁ t₂ : L.Term (Sum α (Fin l))) :
(t₁.bdEqual t₂).Realize v xs ↔ t₁.realize (Sum.elim v xs) = t₂.realize (Sum.elim v xs) :=
Iff.rfl
#align first_order.language.bounded_formula.realize_bd_equal FirstOrder.Language.BoundedFormula.realize_bdEqual
@[simp]
theorem realize_top : (⊤ : L.BoundedFormula α l).Realize v xs ↔ True := by simp [Top.top]
#align first_order.language.bounded_formula.realize_top FirstOrder.Language.BoundedFormula.realize_top
@[simp]
theorem realize_inf : (φ ⊓ ψ).Realize v xs ↔ φ.Realize v xs ∧ ψ.Realize v xs := by
simp [Inf.inf, Realize]
#align first_order.language.bounded_formula.realize_inf FirstOrder.Language.BoundedFormula.realize_inf
@[simp]
theorem realize_foldr_inf (l : List (L.BoundedFormula α n)) (v : α → M) (xs : Fin n → M) :
(l.foldr (· ⊓ ·) ⊤).Realize v xs ↔ ∀ φ ∈ l, BoundedFormula.Realize φ v xs := by
induction' l with φ l ih
· simp
· simp [ih]
#align first_order.language.bounded_formula.realize_foldr_inf FirstOrder.Language.BoundedFormula.realize_foldr_inf
@[simp]
theorem realize_imp : (φ.imp ψ).Realize v xs ↔ φ.Realize v xs → ψ.Realize v xs := by
simp only [Realize]
#align first_order.language.bounded_formula.realize_imp FirstOrder.Language.BoundedFormula.realize_imp
@[simp]
theorem realize_rel {k : ℕ} {R : L.Relations k} {ts : Fin k → L.Term _} :
(R.boundedFormula ts).Realize v xs ↔ RelMap R fun i => (ts i).realize (Sum.elim v xs) :=
Iff.rfl
#align first_order.language.bounded_formula.realize_rel FirstOrder.Language.BoundedFormula.realize_rel
@[simp]
theorem realize_rel₁ {R : L.Relations 1} {t : L.Term _} :
(R.boundedFormula₁ t).Realize v xs ↔ RelMap R ![t.realize (Sum.elim v xs)] := by
rw [Relations.boundedFormula₁, realize_rel, iff_eq_eq]
refine congr rfl (funext fun _ => ?_)
simp only [Matrix.cons_val_fin_one]
#align first_order.language.bounded_formula.realize_rel₁ FirstOrder.Language.BoundedFormula.realize_rel₁
@[simp]
theorem realize_rel₂ {R : L.Relations 2} {t₁ t₂ : L.Term _} :
(R.boundedFormula₂ t₁ t₂).Realize v xs ↔
RelMap R ![t₁.realize (Sum.elim v xs), t₂.realize (Sum.elim v xs)] := by
rw [Relations.boundedFormula₂, realize_rel, iff_eq_eq]
refine congr rfl (funext (Fin.cases ?_ ?_))
· simp only [Matrix.cons_val_zero]
· simp only [Matrix.cons_val_succ, Matrix.cons_val_fin_one, forall_const]
#align first_order.language.bounded_formula.realize_rel₂ FirstOrder.Language.BoundedFormula.realize_rel₂
@[simp]
theorem realize_sup : (φ ⊔ ψ).Realize v xs ↔ φ.Realize v xs ∨ ψ.Realize v xs := by
simp only [realize, Sup.sup, realize_not, eq_iff_iff]
tauto
#align first_order.language.bounded_formula.realize_sup FirstOrder.Language.BoundedFormula.realize_sup
@[simp]
theorem realize_foldr_sup (l : List (L.BoundedFormula α n)) (v : α → M) (xs : Fin n → M) :
(l.foldr (· ⊔ ·) ⊥).Realize v xs ↔ ∃ φ ∈ l, BoundedFormula.Realize φ v xs := by
induction' l with φ l ih
· simp
· simp_rw [List.foldr_cons, realize_sup, ih, List.mem_cons, or_and_right, exists_or,
exists_eq_left]
#align first_order.language.bounded_formula.realize_foldr_sup FirstOrder.Language.BoundedFormula.realize_foldr_sup
@[simp]
theorem realize_all : (all θ).Realize v xs ↔ ∀ a : M, θ.Realize v (Fin.snoc xs a) :=
Iff.rfl
#align first_order.language.bounded_formula.realize_all FirstOrder.Language.BoundedFormula.realize_all
@[simp]
theorem realize_ex : θ.ex.Realize v xs ↔ ∃ a : M, θ.Realize v (Fin.snoc xs a) := by
rw [BoundedFormula.ex, realize_not, realize_all, not_forall]
simp_rw [realize_not, Classical.not_not]
#align first_order.language.bounded_formula.realize_ex FirstOrder.Language.BoundedFormula.realize_ex
@[simp]
theorem realize_iff : (φ.iff ψ).Realize v xs ↔ (φ.Realize v xs ↔ ψ.Realize v xs) := by
simp only [BoundedFormula.iff, realize_inf, realize_imp, and_imp, ← iff_def]
#align first_order.language.bounded_formula.realize_iff FirstOrder.Language.BoundedFormula.realize_iff
theorem realize_castLE_of_eq {m n : ℕ} (h : m = n) {h' : m ≤ n} {φ : L.BoundedFormula α m}
{v : α → M} {xs : Fin n → M} : (φ.castLE h').Realize v xs ↔ φ.Realize v (xs ∘ cast h) := by
subst h
simp only [castLE_rfl, cast_refl, OrderIso.coe_refl, Function.comp_id]
#align first_order.language.bounded_formula.realize_cast_le_of_eq FirstOrder.Language.BoundedFormula.realize_castLE_of_eq
theorem realize_mapTermRel_id [L'.Structure M]
{ft : ∀ n, L.Term (Sum α (Fin n)) → L'.Term (Sum β (Fin n))}
{fr : ∀ n, L.Relations n → L'.Relations n} {n} {φ : L.BoundedFormula α n} {v : α → M}
{v' : β → M} {xs : Fin n → M}
(h1 :
∀ (n) (t : L.Term (Sum α (Fin n))) (xs : Fin n → M),
(ft n t).realize (Sum.elim v' xs) = t.realize (Sum.elim v xs))
(h2 : ∀ (n) (R : L.Relations n) (x : Fin n → M), RelMap (fr n R) x = RelMap R x) :
(φ.mapTermRel ft fr fun _ => id).Realize v' xs ↔ φ.Realize v xs := by
induction' φ with _ _ _ _ _ _ _ _ _ _ _ ih1 ih2 _ _ ih
· rfl
· simp [mapTermRel, Realize, h1]
· simp [mapTermRel, Realize, h1, h2]
· simp [mapTermRel, Realize, ih1, ih2]
· simp only [mapTermRel, Realize, ih, id]
#align first_order.language.bounded_formula.realize_map_term_rel_id FirstOrder.Language.BoundedFormula.realize_mapTermRel_id
theorem realize_mapTermRel_add_castLe [L'.Structure M] {k : ℕ}
{ft : ∀ n, L.Term (Sum α (Fin n)) → L'.Term (Sum β (Fin (k + n)))}
{fr : ∀ n, L.Relations n → L'.Relations n} {n} {φ : L.BoundedFormula α n}
(v : ∀ {n}, (Fin (k + n) → M) → α → M) {v' : β → M} (xs : Fin (k + n) → M)
(h1 :
∀ (n) (t : L.Term (Sum α (Fin n))) (xs' : Fin (k + n) → M),
(ft n t).realize (Sum.elim v' xs') = t.realize (Sum.elim (v xs') (xs' ∘ Fin.natAdd _)))
(h2 : ∀ (n) (R : L.Relations n) (x : Fin n → M), RelMap (fr n R) x = RelMap R x)
(hv : ∀ (n) (xs : Fin (k + n) → M) (x : M), @v (n + 1) (snoc xs x : Fin _ → M) = v xs) :
(φ.mapTermRel ft fr fun n => castLE (add_assoc _ _ _).symm.le).Realize v' xs ↔
φ.Realize (v xs) (xs ∘ Fin.natAdd _) := by
induction' φ with _ _ _ _ _ _ _ _ _ _ _ ih1 ih2 _ _ ih
· rfl
· simp [mapTermRel, Realize, h1]
· simp [mapTermRel, Realize, h1, h2]
· simp [mapTermRel, Realize, ih1, ih2]
· simp [mapTermRel, Realize, ih, hv]
#align first_order.language.bounded_formula.realize_map_term_rel_add_cast_le FirstOrder.Language.BoundedFormula.realize_mapTermRel_add_castLe
@[simp]
theorem realize_relabel {m n : ℕ} {φ : L.BoundedFormula α n} {g : α → Sum β (Fin m)} {v : β → M}
{xs : Fin (m + n) → M} :
(φ.relabel g).Realize v xs ↔
φ.Realize (Sum.elim v (xs ∘ Fin.castAdd n) ∘ g) (xs ∘ Fin.natAdd m) := by
rw [relabel, realize_mapTermRel_add_castLe] <;> intros <;> simp
#align first_order.language.bounded_formula.realize_relabel FirstOrder.Language.BoundedFormula.realize_relabel
theorem realize_liftAt {n n' m : ℕ} {φ : L.BoundedFormula α n} {v : α → M} {xs : Fin (n + n') → M}
(hmn : m + n' ≤ n + 1) :
(φ.liftAt n' m).Realize v xs ↔
φ.Realize v (xs ∘ fun i => if ↑i < m then Fin.castAdd n' i else Fin.addNat i n') := by
rw [liftAt]
induction' φ with _ _ _ _ _ _ _ _ _ _ _ ih1 ih2 k _ ih3
· simp [mapTermRel, Realize]
· simp [mapTermRel, Realize, realize_rel, realize_liftAt, Sum.elim_comp_map]
· simp [mapTermRel, Realize, realize_rel, realize_liftAt, Sum.elim_comp_map]
· simp only [mapTermRel, Realize, ih1 hmn, ih2 hmn]
· have h : k + 1 + n' = k + n' + 1 := by rw [add_assoc, add_comm 1 n', ← add_assoc]
simp only [mapTermRel, Realize, realize_castLE_of_eq h, ih3 (hmn.trans k.succ.le_succ)]
refine forall_congr' fun x => iff_eq_eq.mpr (congr rfl (funext (Fin.lastCases ?_ fun i => ?_)))
· simp only [Function.comp_apply, val_last, snoc_last]
by_cases h : k < m
· rw [if_pos h]
refine (congr rfl (ext ?_)).trans (snoc_last _ _)
simp only [coe_cast, coe_castAdd, val_last, self_eq_add_right]
refine le_antisymm
(le_of_add_le_add_left ((hmn.trans (Nat.succ_le_of_lt h)).trans ?_)) n'.zero_le
rw [add_zero]
· rw [if_neg h]
refine (congr rfl (ext ?_)).trans (snoc_last _ _)
simp
· simp only [Function.comp_apply, Fin.snoc_castSucc]
refine (congr rfl (ext ?_)).trans (snoc_castSucc _ _ _)
simp only [coe_castSucc, coe_cast]
split_ifs <;> simp
#align first_order.language.bounded_formula.realize_lift_at FirstOrder.Language.BoundedFormula.realize_liftAt
theorem realize_liftAt_one {n m : ℕ} {φ : L.BoundedFormula α n} {v : α → M} {xs : Fin (n + 1) → M}
(hmn : m ≤ n) :
(φ.liftAt 1 m).Realize v xs ↔
φ.Realize v (xs ∘ fun i => if ↑i < m then castSucc i else i.succ) := by
simp [realize_liftAt (add_le_add_right hmn 1), castSucc]
#align first_order.language.bounded_formula.realize_lift_at_one FirstOrder.Language.BoundedFormula.realize_liftAt_one
@[simp]
theorem realize_liftAt_one_self {n : ℕ} {φ : L.BoundedFormula α n} {v : α → M}
{xs : Fin (n + 1) → M} : (φ.liftAt 1 n).Realize v xs ↔ φ.Realize v (xs ∘ castSucc) := by
rw [realize_liftAt_one (refl n), iff_eq_eq]
refine congr rfl (congr rfl (funext fun i => ?_))
rw [if_pos i.is_lt]
#align first_order.language.bounded_formula.realize_lift_at_one_self FirstOrder.Language.BoundedFormula.realize_liftAt_one_self
@[simp]
theorem realize_subst {φ : L.BoundedFormula α n} {tf : α → L.Term β} {v : β → M} {xs : Fin n → M} :
(φ.subst tf).Realize v xs ↔ φ.Realize (fun a => (tf a).realize v) xs :=
realize_mapTermRel_id
(fun n t x => by
rw [Term.realize_subst]
rcongr a
cases a
· simp only [Sum.elim_inl, Function.comp_apply, Term.realize_relabel, Sum.elim_comp_inl]
· rfl)
(by simp)
#align first_order.language.bounded_formula.realize_subst FirstOrder.Language.BoundedFormula.realize_subst
@[simp]
theorem realize_restrictFreeVar [DecidableEq α] {n : ℕ} {φ : L.BoundedFormula α n} {s : Set α}
(h : ↑φ.freeVarFinset ⊆ s) {v : α → M} {xs : Fin n → M} :
(φ.restrictFreeVar (Set.inclusion h)).Realize (v ∘ (↑)) xs ↔ φ.Realize v xs := by
induction' φ with _ _ _ _ _ _ _ _ _ _ _ ih1 ih2 _ _ ih3
· rfl
· simp [restrictFreeVar, Realize]
· simp [restrictFreeVar, Realize]
· simp [restrictFreeVar, Realize, ih1, ih2]
· simp [restrictFreeVar, Realize, ih3]
#align first_order.language.bounded_formula.realize_restrict_free_var FirstOrder.Language.BoundedFormula.realize_restrictFreeVar
theorem realize_constantsVarsEquiv [L[[α]].Structure M] [(lhomWithConstants L α).IsExpansionOn M]
{n} {φ : L[[α]].BoundedFormula β n} {v : β → M} {xs : Fin n → M} :
(constantsVarsEquiv φ).Realize (Sum.elim (fun a => ↑(L.con a)) v) xs ↔ φ.Realize v xs := by
refine realize_mapTermRel_id (fun n t xs => realize_constantsVarsEquivLeft) fun n R xs => ?_
-- This used to be `rw`, but we need `erw` after leanprover/lean4#2644
erw [← (lhomWithConstants L α).map_onRelation
(Equiv.sumEmpty (L.Relations n) ((constantsOn α).Relations n) R) xs]
rcongr
cases' R with R R
· simp
· exact isEmptyElim R
#align first_order.language.bounded_formula.realize_constants_vars_equiv FirstOrder.Language.BoundedFormula.realize_constantsVarsEquiv
@[simp]
theorem realize_relabelEquiv {g : α ≃ β} {k} {φ : L.BoundedFormula α k} {v : β → M}
{xs : Fin k → M} : (relabelEquiv g φ).Realize v xs ↔ φ.Realize (v ∘ g) xs := by
simp only [relabelEquiv, mapTermRelEquiv_apply, Equiv.coe_refl]
refine realize_mapTermRel_id (fun n t xs => ?_) fun _ _ _ => rfl
simp only [relabelEquiv_apply, Term.realize_relabel]
refine congr (congr rfl ?_) rfl
ext (i | i) <;> rfl
#align first_order.language.bounded_formula.realize_relabel_equiv FirstOrder.Language.BoundedFormula.realize_relabelEquiv
variable [Nonempty M]
theorem realize_all_liftAt_one_self {n : ℕ} {φ : L.BoundedFormula α n} {v : α → M}
{xs : Fin n → M} : (φ.liftAt 1 n).all.Realize v xs ↔ φ.Realize v xs := by
inhabit M
simp only [realize_all, realize_liftAt_one_self]
refine ⟨fun h => ?_, fun h a => ?_⟩
· refine (congr rfl (funext fun i => ?_)).mp (h default)
simp
· refine (congr rfl (funext fun i => ?_)).mp h
simp
#align first_order.language.bounded_formula.realize_all_lift_at_one_self FirstOrder.Language.BoundedFormula.realize_all_liftAt_one_self
theorem realize_toPrenexImpRight {φ ψ : L.BoundedFormula α n} (hφ : IsQF φ) (hψ : IsPrenex ψ)
{v : α → M} {xs : Fin n → M} :
(φ.toPrenexImpRight ψ).Realize v xs ↔ (φ.imp ψ).Realize v xs := by
induction' hψ with _ _ hψ _ _ _hψ ih _ _ _hψ ih
· rw [hψ.toPrenexImpRight]
· refine _root_.trans (forall_congr' fun _ => ih hφ.liftAt) ?_
simp only [realize_imp, realize_liftAt_one_self, snoc_comp_castSucc, realize_all]
exact ⟨fun h1 a h2 => h1 h2 a, fun h1 h2 a => h1 a h2⟩
· unfold toPrenexImpRight
rw [realize_ex]
refine _root_.trans (exists_congr fun _ => ih hφ.liftAt) ?_
simp only [realize_imp, realize_liftAt_one_self, snoc_comp_castSucc, realize_ex]
refine ⟨?_, fun h' => ?_⟩
· rintro ⟨a, ha⟩ h
exact ⟨a, ha h⟩
· by_cases h : φ.Realize v xs
· obtain ⟨a, ha⟩ := h' h
exact ⟨a, fun _ => ha⟩
· inhabit M
exact ⟨default, fun h'' => (h h'').elim⟩
#align first_order.language.bounded_formula.realize_to_prenex_imp_right FirstOrder.Language.BoundedFormula.realize_toPrenexImpRight
theorem realize_toPrenexImp {φ ψ : L.BoundedFormula α n} (hφ : IsPrenex φ) (hψ : IsPrenex ψ)
{v : α → M} {xs : Fin n → M} : (φ.toPrenexImp ψ).Realize v xs ↔ (φ.imp ψ).Realize v xs := by
revert ψ
induction' hφ with _ _ hφ _ _ _hφ ih _ _ _hφ ih <;> intro ψ hψ
· rw [hφ.toPrenexImp]
exact realize_toPrenexImpRight hφ hψ
· unfold toPrenexImp
rw [realize_ex]
refine _root_.trans (exists_congr fun _ => ih hψ.liftAt) ?_
simp only [realize_imp, realize_liftAt_one_self, snoc_comp_castSucc, realize_all]
refine ⟨?_, fun h' => ?_⟩
· rintro ⟨a, ha⟩ h
exact ha (h a)
· by_cases h : ψ.Realize v xs
· inhabit M
exact ⟨default, fun _h'' => h⟩
· obtain ⟨a, ha⟩ := not_forall.1 (h ∘ h')
exact ⟨a, fun h => (ha h).elim⟩
· refine _root_.trans (forall_congr' fun _ => ih hψ.liftAt) ?_
simp
#align first_order.language.bounded_formula.realize_to_prenex_imp FirstOrder.Language.BoundedFormula.realize_toPrenexImp
@[simp]
theorem realize_toPrenex (φ : L.BoundedFormula α n) {v : α → M} :
∀ {xs : Fin n → M}, φ.toPrenex.Realize v xs ↔ φ.Realize v xs := by
induction' φ with _ _ _ _ _ _ _ _ _ f1 f2 h1 h2 _ _ h
· exact Iff.rfl
· exact Iff.rfl
· exact Iff.rfl
· intros
rw [toPrenex, realize_toPrenexImp f1.toPrenex_isPrenex f2.toPrenex_isPrenex, realize_imp,
realize_imp, h1, h2]
· intros
rw [realize_all, toPrenex, realize_all]
exact forall_congr' fun a => h
#align first_order.language.bounded_formula.realize_to_prenex FirstOrder.Language.BoundedFormula.realize_toPrenex
end BoundedFormula
-- Porting note: no `protected` attribute in Lean4
-- attribute [protected] bounded_formula.falsum bounded_formula.equal bounded_formula.rel
-- attribute [protected] bounded_formula.imp bounded_formula.all
namespace LHom
open BoundedFormula
@[simp]
theorem realize_onBoundedFormula [L'.Structure M] (φ : L →ᴸ L') [φ.IsExpansionOn M] {n : ℕ}
(ψ : L.BoundedFormula α n) {v : α → M} {xs : Fin n → M} :
(φ.onBoundedFormula ψ).Realize v xs ↔ ψ.Realize v xs := by
induction' ψ with _ _ _ _ _ _ _ _ _ _ _ ih1 ih2 _ _ ih3
· rfl
· simp only [onBoundedFormula, realize_bdEqual, realize_onTerm]
rfl
· simp only [onBoundedFormula, realize_rel, LHom.map_onRelation,
Function.comp_apply, realize_onTerm]
rfl
· simp only [onBoundedFormula, ih1, ih2, realize_imp]
· simp only [onBoundedFormula, ih3, realize_all]
set_option linter.uppercaseLean3 false in
#align first_order.language.Lhom.realize_on_bounded_formula FirstOrder.Language.LHom.realize_onBoundedFormula
end LHom
-- Porting note: no `protected` attribute in Lean4
-- attribute [protected] bounded_formula.falsum bounded_formula.equal bounded_formula.rel
-- attribute [protected] bounded_formula.imp bounded_formula.all
namespace Formula
/-- A formula can be evaluated as true or false by giving values to each free variable. -/
nonrec def Realize (φ : L.Formula α) (v : α → M) : Prop :=
φ.Realize v default
#align first_order.language.formula.realize FirstOrder.Language.Formula.Realize
variable {φ ψ : L.Formula α} {v : α → M}
@[simp]
theorem realize_not : φ.not.Realize v ↔ ¬φ.Realize v :=
Iff.rfl
#align first_order.language.formula.realize_not FirstOrder.Language.Formula.realize_not
@[simp]
theorem realize_bot : (⊥ : L.Formula α).Realize v ↔ False :=
Iff.rfl
#align first_order.language.formula.realize_bot FirstOrder.Language.Formula.realize_bot
@[simp]
theorem realize_top : (⊤ : L.Formula α).Realize v ↔ True :=
BoundedFormula.realize_top
#align first_order.language.formula.realize_top FirstOrder.Language.Formula.realize_top
@[simp]
theorem realize_inf : (φ ⊓ ψ).Realize v ↔ φ.Realize v ∧ ψ.Realize v :=
BoundedFormula.realize_inf
#align first_order.language.formula.realize_inf FirstOrder.Language.Formula.realize_inf
@[simp]
theorem realize_imp : (φ.imp ψ).Realize v ↔ φ.Realize v → ψ.Realize v :=
BoundedFormula.realize_imp
#align first_order.language.formula.realize_imp FirstOrder.Language.Formula.realize_imp
@[simp]
theorem realize_rel {k : ℕ} {R : L.Relations k} {ts : Fin k → L.Term α} :
(R.formula ts).Realize v ↔ RelMap R fun i => (ts i).realize v :=
BoundedFormula.realize_rel.trans (by simp)
#align first_order.language.formula.realize_rel FirstOrder.Language.Formula.realize_rel
@[simp]
theorem realize_rel₁ {R : L.Relations 1} {t : L.Term _} :
(R.formula₁ t).Realize v ↔ RelMap R ![t.realize v] := by
rw [Relations.formula₁, realize_rel, iff_eq_eq]
refine congr rfl (funext fun _ => ?_)
simp only [Matrix.cons_val_fin_one]
#align first_order.language.formula.realize_rel₁ FirstOrder.Language.Formula.realize_rel₁
@[simp]
theorem realize_rel₂ {R : L.Relations 2} {t₁ t₂ : L.Term _} :
(R.formula₂ t₁ t₂).Realize v ↔ RelMap R ![t₁.realize v, t₂.realize v] := by
rw [Relations.formula₂, realize_rel, iff_eq_eq]
refine congr rfl (funext (Fin.cases ?_ ?_))
· simp only [Matrix.cons_val_zero]
· simp only [Matrix.cons_val_succ, Matrix.cons_val_fin_one, forall_const]
#align first_order.language.formula.realize_rel₂ FirstOrder.Language.Formula.realize_rel₂
@[simp]
theorem realize_sup : (φ ⊔ ψ).Realize v ↔ φ.Realize v ∨ ψ.Realize v :=
BoundedFormula.realize_sup
#align first_order.language.formula.realize_sup FirstOrder.Language.Formula.realize_sup
@[simp]
theorem realize_iff : (φ.iff ψ).Realize v ↔ (φ.Realize v ↔ ψ.Realize v) :=
BoundedFormula.realize_iff
#align first_order.language.formula.realize_iff FirstOrder.Language.Formula.realize_iff
@[simp]
theorem realize_relabel {φ : L.Formula α} {g : α → β} {v : β → M} :
(φ.relabel g).Realize v ↔ φ.Realize (v ∘ g) := by
rw [Realize, Realize, relabel, BoundedFormula.realize_relabel, iff_eq_eq, Fin.castAdd_zero]
exact congr rfl (funext finZeroElim)
#align first_order.language.formula.realize_relabel FirstOrder.Language.Formula.realize_relabel
theorem realize_relabel_sum_inr (φ : L.Formula (Fin n)) {v : Empty → M} {x : Fin n → M} :
(BoundedFormula.relabel Sum.inr φ).Realize v x ↔ φ.Realize x := by
rw [BoundedFormula.realize_relabel, Formula.Realize, Sum.elim_comp_inr, Fin.castAdd_zero,
cast_refl, Function.comp_id,
Subsingleton.elim (x ∘ (natAdd n : Fin 0 → Fin n)) default]
#align first_order.language.formula.realize_relabel_sum_inr FirstOrder.Language.Formula.realize_relabel_sum_inr
@[simp]
theorem realize_equal {t₁ t₂ : L.Term α} {x : α → M} :
(t₁.equal t₂).Realize x ↔ t₁.realize x = t₂.realize x := by simp [Term.equal, Realize]
#align first_order.language.formula.realize_equal FirstOrder.Language.Formula.realize_equal
@[simp]
theorem realize_graph {f : L.Functions n} {x : Fin n → M} {y : M} :
(Formula.graph f).Realize (Fin.cons y x : _ → M) ↔ funMap f x = y := by
simp only [Formula.graph, Term.realize, realize_equal, Fin.cons_zero, Fin.cons_succ]
rw [eq_comm]
#align first_order.language.formula.realize_graph FirstOrder.Language.Formula.realize_graph
end Formula
@[simp]
theorem LHom.realize_onFormula [L'.Structure M] (φ : L →ᴸ L') [φ.IsExpansionOn M] (ψ : L.Formula α)
{v : α → M} : (φ.onFormula ψ).Realize v ↔ ψ.Realize v :=
φ.realize_onBoundedFormula ψ
set_option linter.uppercaseLean3 false in
#align first_order.language.Lhom.realize_on_formula FirstOrder.Language.LHom.realize_onFormula
@[simp]
theorem LHom.setOf_realize_onFormula [L'.Structure M] (φ : L →ᴸ L') [φ.IsExpansionOn M]
(ψ : L.Formula α) : (setOf (φ.onFormula ψ).Realize : Set (α → M)) = setOf ψ.Realize := by
ext
simp
set_option linter.uppercaseLean3 false in
#align first_order.language.Lhom.set_of_realize_on_formula FirstOrder.Language.LHom.setOf_realize_onFormula
variable (M)
/-- A sentence can be evaluated as true or false in a structure. -/
nonrec def Sentence.Realize (φ : L.Sentence) : Prop :=
φ.Realize (default : _ → M)
#align first_order.language.sentence.realize FirstOrder.Language.Sentence.Realize
-- input using \|= or \vDash, but not using \models
@[inherit_doc Sentence.Realize]
infixl:51 " ⊨ " => Sentence.Realize
@[simp]
theorem Sentence.realize_not {φ : L.Sentence} : M ⊨ φ.not ↔ ¬M ⊨ φ :=
Iff.rfl
#align first_order.language.sentence.realize_not FirstOrder.Language.Sentence.realize_not
namespace Formula
@[simp]
theorem realize_equivSentence_symm_con [L[[α]].Structure M]
[(L.lhomWithConstants α).IsExpansionOn M] (φ : L[[α]].Sentence) :
((equivSentence.symm φ).Realize fun a => (L.con a : M)) ↔ φ.Realize M := by
simp only [equivSentence, _root_.Equiv.symm_symm, Equiv.coe_trans, Realize,
BoundedFormula.realize_relabelEquiv, Function.comp]
refine _root_.trans ?_ BoundedFormula.realize_constantsVarsEquiv
rw [iff_iff_eq]
congr with (_ | a)
· simp
· cases a
#align first_order.language.formula.realize_equiv_sentence_symm_con FirstOrder.Language.Formula.realize_equivSentence_symm_con
@[simp]
theorem realize_equivSentence [L[[α]].Structure M] [(L.lhomWithConstants α).IsExpansionOn M]
(φ : L.Formula α) : (equivSentence φ).Realize M ↔ φ.Realize fun a => (L.con a : M) := by
rw [← realize_equivSentence_symm_con M (equivSentence φ), _root_.Equiv.symm_apply_apply]
#align first_order.language.formula.realize_equiv_sentence FirstOrder.Language.Formula.realize_equivSentence
theorem realize_equivSentence_symm (φ : L[[α]].Sentence) (v : α → M) :
(equivSentence.symm φ).Realize v ↔
@Sentence.Realize _ M (@Language.withConstantsStructure L M _ α (constantsOn.structure v))
φ :=
letI := constantsOn.structure v
realize_equivSentence_symm_con M φ
#align first_order.language.formula.realize_equiv_sentence_symm FirstOrder.Language.Formula.realize_equivSentence_symm
end Formula
@[simp]
theorem LHom.realize_onSentence [L'.Structure M] (φ : L →ᴸ L') [φ.IsExpansionOn M]
(ψ : L.Sentence) : M ⊨ φ.onSentence ψ ↔ M ⊨ ψ :=
φ.realize_onFormula ψ
set_option linter.uppercaseLean3 false in
#align first_order.language.Lhom.realize_on_sentence FirstOrder.Language.LHom.realize_onSentence
variable (L)
/-- The complete theory of a structure `M` is the set of all sentences `M` satisfies. -/
def completeTheory : L.Theory :=
{ φ | M ⊨ φ }
#align first_order.language.complete_theory FirstOrder.Language.completeTheory
variable (N)
/-- Two structures are elementarily equivalent when they satisfy the same sentences. -/
def ElementarilyEquivalent : Prop :=
L.completeTheory M = L.completeTheory N
#align first_order.language.elementarily_equivalent FirstOrder.Language.ElementarilyEquivalent
@[inherit_doc FirstOrder.Language.ElementarilyEquivalent]
scoped[FirstOrder]
notation:25 A " ≅[" L "] " B:50 => FirstOrder.Language.ElementarilyEquivalent L A B
variable {L} {M} {N}
@[simp]
theorem mem_completeTheory {φ : Sentence L} : φ ∈ L.completeTheory M ↔ M ⊨ φ :=
Iff.rfl
#align first_order.language.mem_complete_theory FirstOrder.Language.mem_completeTheory
theorem elementarilyEquivalent_iff : M ≅[L] N ↔ ∀ φ : L.Sentence, M ⊨ φ ↔ N ⊨ φ := by
simp only [ElementarilyEquivalent, Set.ext_iff, completeTheory, Set.mem_setOf_eq]
#align first_order.language.elementarily_equivalent_iff FirstOrder.Language.elementarilyEquivalent_iff
variable (M)
/-- A model of a theory is a structure in which every sentence is realized as true. -/
class Theory.Model (T : L.Theory) : Prop where
realize_of_mem : ∀ φ ∈ T, M ⊨ φ
set_option linter.uppercaseLean3 false in
#align first_order.language.Theory.model FirstOrder.Language.Theory.Model
-- input using \|= or \vDash, but not using \models
@[inherit_doc Theory.Model]
infixl:51 " ⊨ " => Theory.Model
variable {M} (T : L.Theory)
@[simp default-10]
theorem Theory.model_iff : M ⊨ T ↔ ∀ φ ∈ T, M ⊨ φ :=
⟨fun h => h.realize_of_mem, fun h => ⟨h⟩⟩
set_option linter.uppercaseLean3 false in
#align first_order.language.Theory.model_iff FirstOrder.Language.Theory.model_iff
theorem Theory.realize_sentence_of_mem [M ⊨ T] {φ : L.Sentence} (h : φ ∈ T) : M ⊨ φ :=
Theory.Model.realize_of_mem φ h
set_option linter.uppercaseLean3 false in
#align first_order.language.Theory.realize_sentence_of_mem FirstOrder.Language.Theory.realize_sentence_of_mem
@[simp]
theorem LHom.onTheory_model [L'.Structure M] (φ : L →ᴸ L') [φ.IsExpansionOn M] (T : L.Theory) :
M ⊨ φ.onTheory T ↔ M ⊨ T := by simp [Theory.model_iff, LHom.onTheory]
set_option linter.uppercaseLean3 false in
#align first_order.language.Lhom.on_Theory_model FirstOrder.Language.LHom.onTheory_model
variable {T}
instance model_empty : M ⊨ (∅ : L.Theory) :=
⟨fun φ hφ => (Set.not_mem_empty φ hφ).elim⟩
#align first_order.language.model_empty FirstOrder.Language.model_empty
namespace Theory
theorem Model.mono {T' : L.Theory} (_h : M ⊨ T') (hs : T ⊆ T') : M ⊨ T :=
⟨fun _φ hφ => T'.realize_sentence_of_mem (hs hφ)⟩
set_option linter.uppercaseLean3 false in
#align first_order.language.Theory.model.mono FirstOrder.Language.Theory.Model.mono
theorem Model.union {T' : L.Theory} (h : M ⊨ T) (h' : M ⊨ T') : M ⊨ T ∪ T' := by
simp only [model_iff, Set.mem_union] at *
exact fun φ hφ => hφ.elim (h _) (h' _)
set_option linter.uppercaseLean3 false in
#align first_order.language.Theory.model.union FirstOrder.Language.Theory.Model.union
@[simp]
theorem model_union_iff {T' : L.Theory} : M ⊨ T ∪ T' ↔ M ⊨ T ∧ M ⊨ T' :=
⟨fun h => ⟨h.mono Set.subset_union_left, h.mono Set.subset_union_right⟩, fun h =>
h.1.union h.2⟩
set_option linter.uppercaseLean3 false in
#align first_order.language.Theory.model_union_iff FirstOrder.Language.Theory.model_union_iff
| Mathlib/ModelTheory/Semantics.lean | 853 | 853 | theorem model_singleton_iff {φ : L.Sentence} : M ⊨ ({φ} : L.Theory) ↔ M ⊨ φ := by | simp
|
/-
Copyright (c) 2022 Michael Stoll. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Michael Stoll
-/
import Mathlib.Data.Fin.Tuple.Sort
import Mathlib.Order.WellFounded
#align_import data.fin.tuple.bubble_sort_induction from "leanprover-community/mathlib"@"bf2428c9486c407ca38b5b3fb10b87dad0bc99fa"
/-!
# "Bubble sort" induction
We implement the following induction principle `Tuple.bubble_sort_induction`
on tuples with values in a linear order `α`.
Let `f : Fin n → α` and let `P` be a predicate on `Fin n → α`. Then we can show that
`f ∘ sort f` satisfies `P` if `f` satisfies `P`, and whenever some `g : Fin n → α`
satisfies `P` and `g i > g j` for some `i < j`, then `g ∘ swap i j` also satisfies `P`.
We deduce it from a stronger variant `Tuple.bubble_sort_induction'`, which
requires the assumption only for `g` that are permutations of `f`.
The latter is proved by well-founded induction via `WellFounded.induction_bot'`
with respect to the lexicographic ordering on the finite set of all permutations of `f`.
-/
namespace Tuple
/-- *Bubble sort induction*: Prove that the sorted version of `f` has some property `P`
if `f` satisfies `P` and `P` is preserved on permutations of `f` when swapping two
antitone values. -/
| Mathlib/Data/Fin/Tuple/BubbleSortInduction.lean | 34 | 44 | theorem bubble_sort_induction' {n : ℕ} {α : Type*} [LinearOrder α] {f : Fin n → α}
{P : (Fin n → α) → Prop} (hf : P f)
(h : ∀ (σ : Equiv.Perm (Fin n)) (i j : Fin n),
i < j → (f ∘ σ) j < (f ∘ σ) i → P (f ∘ σ) → P (f ∘ σ ∘ Equiv.swap i j)) :
P (f ∘ sort f) := by |
letI := @Preorder.lift _ (Lex (Fin n → α)) _ fun σ : Equiv.Perm (Fin n) => toLex (f ∘ σ)
refine
@WellFounded.induction_bot' _ _ _ (IsWellFounded.wf : WellFounded (· < ·))
(Equiv.refl _) (sort f) P (fun σ => f ∘ σ) (fun σ hσ hfσ => ?_) hf
obtain ⟨i, j, hij₁, hij₂⟩ := antitone_pair_of_not_sorted' hσ
exact ⟨σ * Equiv.swap i j, Pi.lex_desc hij₁.le hij₂, h σ i j hij₁ hij₂ hfσ⟩
|
/-
Copyright (c) 2020 Anne Baanen. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Anne Baanen, Filippo A. E. Nuccio
-/
import Mathlib.RingTheory.Localization.Integer
import Mathlib.RingTheory.Localization.Submodule
#align_import ring_theory.fractional_ideal from "leanprover-community/mathlib"@"ed90a7d327c3a5caf65a6faf7e8a0d63c4605df7"
/-!
# Fractional ideals
This file defines fractional ideals of an integral domain and proves basic facts about them.
## Main definitions
Let `S` be a submonoid of an integral domain `R` and `P` the localization of `R` at `S`.
* `IsFractional` defines which `R`-submodules of `P` are fractional ideals
* `FractionalIdeal S P` is the type of fractional ideals in `P`
* a coercion `coeIdeal : Ideal R → FractionalIdeal S P`
* `CommSemiring (FractionalIdeal S P)` instance:
the typical ideal operations generalized to fractional ideals
* `Lattice (FractionalIdeal S P)` instance
## Main statements
* `mul_left_mono` and `mul_right_mono` state that ideal multiplication is monotone
* `mul_div_self_cancel_iff` states that `1 / I` is the inverse of `I` if one exists
## Implementation notes
Fractional ideals are considered equal when they contain the same elements,
independent of the denominator `a : R` such that `a I ⊆ R`.
Thus, we define `FractionalIdeal` to be the subtype of the predicate `IsFractional`,
instead of having `FractionalIdeal` be a structure of which `a` is a field.
Most definitions in this file specialize operations from submodules to fractional ideals,
proving that the result of this operation is fractional if the input is fractional.
Exceptions to this rule are defining `(+) := (⊔)` and `⊥ := 0`,
in order to re-use their respective proof terms.
We can still use `simp` to show `↑I + ↑J = ↑(I + J)` and `↑⊥ = ↑0`.
Many results in fact do not need that `P` is a localization, only that `P` is an
`R`-algebra. We omit the `IsLocalization` parameter whenever this is practical.
Similarly, we don't assume that the localization is a field until we need it to
define ideal quotients. When this assumption is needed, we replace `S` with `R⁰`,
making the localization a field.
## References
* https://en.wikipedia.org/wiki/Fractional_ideal
## Tags
fractional ideal, fractional ideals, invertible ideal
-/
open IsLocalization Pointwise nonZeroDivisors
section Defs
variable {R : Type*} [CommRing R] {S : Submonoid R} {P : Type*} [CommRing P]
variable [Algebra R P]
variable (S)
/-- A submodule `I` is a fractional ideal if `a I ⊆ R` for some `a ≠ 0`. -/
def IsFractional (I : Submodule R P) :=
∃ a ∈ S, ∀ b ∈ I, IsInteger R (a • b)
#align is_fractional IsFractional
variable (P)
/-- The fractional ideals of a domain `R` are ideals of `R` divided by some `a ∈ R`.
More precisely, let `P` be a localization of `R` at some submonoid `S`,
then a fractional ideal `I ⊆ P` is an `R`-submodule of `P`,
such that there is a nonzero `a : R` with `a I ⊆ R`.
-/
def FractionalIdeal :=
{ I : Submodule R P // IsFractional S I }
#align fractional_ideal FractionalIdeal
end Defs
namespace FractionalIdeal
open Set Submodule
variable {R : Type*} [CommRing R] {S : Submonoid R} {P : Type*} [CommRing P]
variable [Algebra R P] [loc : IsLocalization S P]
/-- Map a fractional ideal `I` to a submodule by forgetting that `∃ a, a I ⊆ R`.
This implements the coercion `FractionalIdeal S P → Submodule R P`.
-/
@[coe]
def coeToSubmodule (I : FractionalIdeal S P) : Submodule R P :=
I.val
/-- Map a fractional ideal `I` to a submodule by forgetting that `∃ a, a I ⊆ R`.
This coercion is typically called `coeToSubmodule` in lemma names
(or `coe` when the coercion is clear from the context),
not to be confused with `IsLocalization.coeSubmodule : Ideal R → Submodule R P`
(which we use to define `coe : Ideal R → FractionalIdeal S P`).
-/
instance : CoeOut (FractionalIdeal S P) (Submodule R P) :=
⟨coeToSubmodule⟩
protected theorem isFractional (I : FractionalIdeal S P) : IsFractional S (I : Submodule R P) :=
I.prop
#align fractional_ideal.is_fractional FractionalIdeal.isFractional
/-- An element of `S` such that `I.den • I = I.num`, see `FractionalIdeal.num` and
`FractionalIdeal.den_mul_self_eq_num`. -/
noncomputable def den (I : FractionalIdeal S P) : S :=
⟨I.2.choose, I.2.choose_spec.1⟩
/-- An ideal of `R` such that `I.den • I = I.num`, see `FractionalIdeal.den` and
`FractionalIdeal.den_mul_self_eq_num`. -/
noncomputable def num (I : FractionalIdeal S P) : Ideal R :=
(I.den • (I : Submodule R P)).comap (Algebra.linearMap R P)
theorem den_mul_self_eq_num (I : FractionalIdeal S P) :
I.den • (I : Submodule R P) = Submodule.map (Algebra.linearMap R P) I.num := by
rw [den, num, Submodule.map_comap_eq]
refine (inf_of_le_right ?_).symm
rintro _ ⟨a, ha, rfl⟩
exact I.2.choose_spec.2 a ha
/-- The linear equivalence between the fractional ideal `I` and the integral ideal `I.num`
defined by mapping `x` to `den I • x`. -/
noncomputable def equivNum [Nontrivial P] [NoZeroSMulDivisors R P]
{I : FractionalIdeal S P} (h_nz : (I.den : R) ≠ 0) : I ≃ₗ[R] I.num := by
refine LinearEquiv.trans
(LinearEquiv.ofBijective ((DistribMulAction.toLinearMap R P I.den).restrict fun _ hx ↦ ?_)
⟨fun _ _ hxy ↦ ?_, fun ⟨y, hy⟩ ↦ ?_⟩)
(Submodule.equivMapOfInjective (Algebra.linearMap R P)
(NoZeroSMulDivisors.algebraMap_injective R P) (num I)).symm
· rw [← den_mul_self_eq_num]
exact Submodule.smul_mem_pointwise_smul _ _ _ hx
· simp_rw [LinearMap.restrict_apply, DistribMulAction.toLinearMap_apply, Subtype.mk.injEq] at hxy
rwa [Submonoid.smul_def, Submonoid.smul_def, smul_right_inj h_nz, SetCoe.ext_iff] at hxy
· rw [← den_mul_self_eq_num] at hy
obtain ⟨x, hx, hxy⟩ := hy
exact ⟨⟨x, hx⟩, by simp_rw [LinearMap.restrict_apply, Subtype.ext_iff, ← hxy]; rfl⟩
section SetLike
instance : SetLike (FractionalIdeal S P) P where
coe I := ↑(I : Submodule R P)
coe_injective' := SetLike.coe_injective.comp Subtype.coe_injective
@[simp]
theorem mem_coe {I : FractionalIdeal S P} {x : P} : x ∈ (I : Submodule R P) ↔ x ∈ I :=
Iff.rfl
#align fractional_ideal.mem_coe FractionalIdeal.mem_coe
@[ext]
theorem ext {I J : FractionalIdeal S P} : (∀ x, x ∈ I ↔ x ∈ J) → I = J :=
SetLike.ext
#align fractional_ideal.ext FractionalIdeal.ext
@[simp]
theorem equivNum_apply [Nontrivial P] [NoZeroSMulDivisors R P] {I : FractionalIdeal S P}
(h_nz : (I.den : R) ≠ 0) (x : I) :
algebraMap R P (equivNum h_nz x) = I.den • x := by
change Algebra.linearMap R P _ = _
rw [equivNum, LinearEquiv.trans_apply, LinearEquiv.ofBijective_apply, LinearMap.restrict_apply,
Submodule.map_equivMapOfInjective_symm_apply, Subtype.coe_mk,
DistribMulAction.toLinearMap_apply]
/-- Copy of a `FractionalIdeal` with a new underlying set equal to the old one.
Useful to fix definitional equalities. -/
protected def copy (p : FractionalIdeal S P) (s : Set P) (hs : s = ↑p) : FractionalIdeal S P :=
⟨Submodule.copy p s hs, by
convert p.isFractional
ext
simp only [hs]
rfl⟩
#align fractional_ideal.copy FractionalIdeal.copy
@[simp]
theorem coe_copy (p : FractionalIdeal S P) (s : Set P) (hs : s = ↑p) : ↑(p.copy s hs) = s :=
rfl
#align fractional_ideal.coe_copy FractionalIdeal.coe_copy
theorem coe_eq (p : FractionalIdeal S P) (s : Set P) (hs : s = ↑p) : p.copy s hs = p :=
SetLike.coe_injective hs
#align fractional_ideal.coe_eq FractionalIdeal.coe_eq
end SetLike
-- Porting note: this seems to be needed a lot more than in Lean 3
@[simp]
theorem val_eq_coe (I : FractionalIdeal S P) : I.val = I :=
rfl
#align fractional_ideal.val_eq_coe FractionalIdeal.val_eq_coe
-- Porting note: had to rephrase this to make it clear to `simp` what was going on.
@[simp, norm_cast]
theorem coe_mk (I : Submodule R P) (hI : IsFractional S I) :
coeToSubmodule ⟨I, hI⟩ = I :=
rfl
#align fractional_ideal.coe_mk FractionalIdeal.coe_mk
-- Porting note (#10756): added lemma because Lean can't see through the composition of coercions.
theorem coeToSet_coeToSubmodule (I : FractionalIdeal S P) :
((I : Submodule R P) : Set P) = I :=
rfl
/-! Transfer instances from `Submodule R P` to `FractionalIdeal S P`. -/
instance (I : FractionalIdeal S P) : Module R I :=
Submodule.module (I : Submodule R P)
theorem coeToSubmodule_injective :
Function.Injective (fun (I : FractionalIdeal S P) ↦ (I : Submodule R P)) :=
Subtype.coe_injective
#align fractional_ideal.coe_to_submodule_injective FractionalIdeal.coeToSubmodule_injective
theorem coeToSubmodule_inj {I J : FractionalIdeal S P} : (I : Submodule R P) = J ↔ I = J :=
coeToSubmodule_injective.eq_iff
#align fractional_ideal.coe_to_submodule_inj FractionalIdeal.coeToSubmodule_inj
theorem isFractional_of_le_one (I : Submodule R P) (h : I ≤ 1) : IsFractional S I := by
use 1, S.one_mem
intro b hb
rw [one_smul]
obtain ⟨b', b'_mem, rfl⟩ := h hb
exact Set.mem_range_self b'
#align fractional_ideal.is_fractional_of_le_one FractionalIdeal.isFractional_of_le_one
theorem isFractional_of_le {I : Submodule R P} {J : FractionalIdeal S P} (hIJ : I ≤ J) :
IsFractional S I := by
obtain ⟨a, a_mem, ha⟩ := J.isFractional
use a, a_mem
intro b b_mem
exact ha b (hIJ b_mem)
#align fractional_ideal.is_fractional_of_le FractionalIdeal.isFractional_of_le
/-- Map an ideal `I` to a fractional ideal by forgetting `I` is integral.
This is the function that implements the coercion `Ideal R → FractionalIdeal S P`. -/
@[coe]
def coeIdeal (I : Ideal R) : FractionalIdeal S P :=
⟨coeSubmodule P I,
isFractional_of_le_one _ <| by simpa using coeSubmodule_mono P (le_top : I ≤ ⊤)⟩
-- Is a `CoeTC` rather than `Coe` to speed up failing inference, see library note [use has_coe_t]
/-- Map an ideal `I` to a fractional ideal by forgetting `I` is integral.
This is a bundled version of `IsLocalization.coeSubmodule : Ideal R → Submodule R P`,
which is not to be confused with the `coe : FractionalIdeal S P → Submodule R P`,
also called `coeToSubmodule` in theorem names.
This map is available as a ring hom, called `FractionalIdeal.coeIdealHom`.
-/
instance : CoeTC (Ideal R) (FractionalIdeal S P) :=
⟨fun I => coeIdeal I⟩
@[simp, norm_cast]
theorem coe_coeIdeal (I : Ideal R) :
((I : FractionalIdeal S P) : Submodule R P) = coeSubmodule P I :=
rfl
#align fractional_ideal.coe_coe_ideal FractionalIdeal.coe_coeIdeal
variable (S)
@[simp]
theorem mem_coeIdeal {x : P} {I : Ideal R} :
x ∈ (I : FractionalIdeal S P) ↔ ∃ x', x' ∈ I ∧ algebraMap R P x' = x :=
mem_coeSubmodule _ _
#align fractional_ideal.mem_coe_ideal FractionalIdeal.mem_coeIdeal
theorem mem_coeIdeal_of_mem {x : R} {I : Ideal R} (hx : x ∈ I) :
algebraMap R P x ∈ (I : FractionalIdeal S P) :=
(mem_coeIdeal S).mpr ⟨x, hx, rfl⟩
#align fractional_ideal.mem_coe_ideal_of_mem FractionalIdeal.mem_coeIdeal_of_mem
theorem coeIdeal_le_coeIdeal' [IsLocalization S P] (h : S ≤ nonZeroDivisors R) {I J : Ideal R} :
(I : FractionalIdeal S P) ≤ J ↔ I ≤ J :=
coeSubmodule_le_coeSubmodule h
#align fractional_ideal.coe_ideal_le_coe_ideal' FractionalIdeal.coeIdeal_le_coeIdeal'
@[simp]
theorem coeIdeal_le_coeIdeal (K : Type*) [CommRing K] [Algebra R K] [IsFractionRing R K]
{I J : Ideal R} : (I : FractionalIdeal R⁰ K) ≤ J ↔ I ≤ J :=
IsFractionRing.coeSubmodule_le_coeSubmodule
#align fractional_ideal.coe_ideal_le_coe_ideal FractionalIdeal.coeIdeal_le_coeIdeal
instance : Zero (FractionalIdeal S P) :=
⟨(0 : Ideal R)⟩
@[simp]
theorem mem_zero_iff {x : P} : x ∈ (0 : FractionalIdeal S P) ↔ x = 0 :=
⟨fun ⟨x', x'_mem_zero, x'_eq_x⟩ => by
have x'_eq_zero : x' = 0 := x'_mem_zero
simp [x'_eq_x.symm, x'_eq_zero], fun hx => ⟨0, rfl, by simp [hx]⟩⟩
#align fractional_ideal.mem_zero_iff FractionalIdeal.mem_zero_iff
variable {S}
@[simp, norm_cast]
theorem coe_zero : ↑(0 : FractionalIdeal S P) = (⊥ : Submodule R P) :=
Submodule.ext fun _ => mem_zero_iff S
#align fractional_ideal.coe_zero FractionalIdeal.coe_zero
@[simp, norm_cast]
theorem coeIdeal_bot : ((⊥ : Ideal R) : FractionalIdeal S P) = 0 :=
rfl
#align fractional_ideal.coe_ideal_bot FractionalIdeal.coeIdeal_bot
variable (P)
@[simp]
theorem exists_mem_algebraMap_eq {x : R} {I : Ideal R} (h : S ≤ nonZeroDivisors R) :
(∃ x', x' ∈ I ∧ algebraMap R P x' = algebraMap R P x) ↔ x ∈ I :=
⟨fun ⟨_, hx', Eq⟩ => IsLocalization.injective _ h Eq ▸ hx', fun h => ⟨x, h, rfl⟩⟩
#align fractional_ideal.exists_mem_to_map_eq FractionalIdeal.exists_mem_algebraMap_eq
variable {P}
theorem coeIdeal_injective' (h : S ≤ nonZeroDivisors R) :
Function.Injective (fun (I : Ideal R) ↦ (I : FractionalIdeal S P)) := fun _ _ h' =>
((coeIdeal_le_coeIdeal' S h).mp h'.le).antisymm ((coeIdeal_le_coeIdeal' S h).mp
h'.ge)
#align fractional_ideal.coe_ideal_injective' FractionalIdeal.coeIdeal_injective'
theorem coeIdeal_inj' (h : S ≤ nonZeroDivisors R) {I J : Ideal R} :
(I : FractionalIdeal S P) = J ↔ I = J :=
(coeIdeal_injective' h).eq_iff
#align fractional_ideal.coe_ideal_inj' FractionalIdeal.coeIdeal_inj'
-- Porting note: doesn't need to be @[simp] because it can be proved by coeIdeal_eq_zero
theorem coeIdeal_eq_zero' {I : Ideal R} (h : S ≤ nonZeroDivisors R) :
(I : FractionalIdeal S P) = 0 ↔ I = (⊥ : Ideal R) :=
coeIdeal_inj' h
#align fractional_ideal.coe_ideal_eq_zero' FractionalIdeal.coeIdeal_eq_zero'
theorem coeIdeal_ne_zero' {I : Ideal R} (h : S ≤ nonZeroDivisors R) :
(I : FractionalIdeal S P) ≠ 0 ↔ I ≠ (⊥ : Ideal R) :=
not_iff_not.mpr <| coeIdeal_eq_zero' h
#align fractional_ideal.coe_ideal_ne_zero' FractionalIdeal.coeIdeal_ne_zero'
theorem coeToSubmodule_eq_bot {I : FractionalIdeal S P} : (I : Submodule R P) = ⊥ ↔ I = 0 :=
⟨fun h => coeToSubmodule_injective (by simp [h]), fun h => by simp [h]⟩
#align fractional_ideal.coe_to_submodule_eq_bot FractionalIdeal.coeToSubmodule_eq_bot
theorem coeToSubmodule_ne_bot {I : FractionalIdeal S P} : ↑I ≠ (⊥ : Submodule R P) ↔ I ≠ 0 :=
not_iff_not.mpr coeToSubmodule_eq_bot
#align fractional_ideal.coe_to_submodule_ne_bot FractionalIdeal.coeToSubmodule_ne_bot
instance : Inhabited (FractionalIdeal S P) :=
⟨0⟩
instance : One (FractionalIdeal S P) :=
⟨(⊤ : Ideal R)⟩
theorem zero_of_num_eq_bot [NoZeroSMulDivisors R P] (hS : 0 ∉ S) {I : FractionalIdeal S P}
(hI : I.num = ⊥) : I = 0 := by
rw [← coeToSubmodule_eq_bot, eq_bot_iff]
intro x hx
suffices (den I : R) • x = 0 from
(smul_eq_zero.mp this).resolve_left (ne_of_mem_of_not_mem (SetLike.coe_mem _) hS)
have h_eq : I.den • (I : Submodule R P) = ⊥ := by rw [den_mul_self_eq_num, hI, Submodule.map_bot]
exact (Submodule.eq_bot_iff _).mp h_eq (den I • x) ⟨x, hx, rfl⟩
theorem num_zero_eq (h_inj : Function.Injective (algebraMap R P)) :
num (0 : FractionalIdeal S P) = 0 := by
simpa [num, LinearMap.ker_eq_bot] using h_inj
variable (S)
@[simp, norm_cast]
theorem coeIdeal_top : ((⊤ : Ideal R) : FractionalIdeal S P) = 1 :=
rfl
#align fractional_ideal.coe_ideal_top FractionalIdeal.coeIdeal_top
theorem mem_one_iff {x : P} : x ∈ (1 : FractionalIdeal S P) ↔ ∃ x' : R, algebraMap R P x' = x :=
Iff.intro (fun ⟨x', _, h⟩ => ⟨x', h⟩) fun ⟨x', h⟩ => ⟨x', ⟨⟩, h⟩
#align fractional_ideal.mem_one_iff FractionalIdeal.mem_one_iff
theorem coe_mem_one (x : R) : algebraMap R P x ∈ (1 : FractionalIdeal S P) :=
(mem_one_iff S).mpr ⟨x, rfl⟩
#align fractional_ideal.coe_mem_one FractionalIdeal.coe_mem_one
theorem one_mem_one : (1 : P) ∈ (1 : FractionalIdeal S P) :=
(mem_one_iff S).mpr ⟨1, RingHom.map_one _⟩
#align fractional_ideal.one_mem_one FractionalIdeal.one_mem_one
variable {S}
/-- `(1 : FractionalIdeal S P)` is defined as the R-submodule `f(R) ≤ P`.
However, this is not definitionally equal to `1 : Submodule R P`,
which is proved in the actual `simp` lemma `coe_one`. -/
theorem coe_one_eq_coeSubmodule_top : ↑(1 : FractionalIdeal S P) = coeSubmodule P (⊤ : Ideal R) :=
rfl
#align fractional_ideal.coe_one_eq_coe_submodule_top FractionalIdeal.coe_one_eq_coeSubmodule_top
@[simp, norm_cast]
| Mathlib/RingTheory/FractionalIdeal/Basic.lean | 404 | 405 | theorem coe_one : (↑(1 : FractionalIdeal S P) : Submodule R P) = 1 := by |
rw [coe_one_eq_coeSubmodule_top, coeSubmodule_top]
|
/-
Copyright (c) 2020 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison, Shing Tak Lam, Mario Carneiro
-/
import Mathlib.Algebra.BigOperators.Intervals
import Mathlib.Algebra.BigOperators.Ring.List
import Mathlib.Data.Int.ModEq
import Mathlib.Data.Nat.Bits
import Mathlib.Data.Nat.Log
import Mathlib.Data.List.Indexes
import Mathlib.Data.List.Palindrome
import Mathlib.Tactic.IntervalCases
import Mathlib.Tactic.Linarith
import Mathlib.Tactic.Ring
#align_import data.nat.digits from "leanprover-community/mathlib"@"369525b73f229ccd76a6ec0e0e0bf2be57599768"
/-!
# Digits of a natural number
This provides a basic API for extracting the digits of a natural number in a given base,
and reconstructing numbers from their digits.
We also prove some divisibility tests based on digits, in particular completing
Theorem #85 from https://www.cs.ru.nl/~freek/100/.
Also included is a bound on the length of `Nat.toDigits` from core.
## TODO
A basic `norm_digits` tactic for proving goals of the form `Nat.digits a b = l` where `a` and `b`
are numerals is not yet ported.
-/
namespace Nat
variable {n : ℕ}
/-- (Impl.) An auxiliary definition for `digits`, to help get the desired definitional unfolding. -/
def digitsAux0 : ℕ → List ℕ
| 0 => []
| n + 1 => [n + 1]
#align nat.digits_aux_0 Nat.digitsAux0
/-- (Impl.) An auxiliary definition for `digits`, to help get the desired definitional unfolding. -/
def digitsAux1 (n : ℕ) : List ℕ :=
List.replicate n 1
#align nat.digits_aux_1 Nat.digitsAux1
/-- (Impl.) An auxiliary definition for `digits`, to help get the desired definitional unfolding. -/
def digitsAux (b : ℕ) (h : 2 ≤ b) : ℕ → List ℕ
| 0 => []
| n + 1 =>
((n + 1) % b) :: digitsAux b h ((n + 1) / b)
decreasing_by exact Nat.div_lt_self (Nat.succ_pos _) h
#align nat.digits_aux Nat.digitsAux
@[simp]
theorem digitsAux_zero (b : ℕ) (h : 2 ≤ b) : digitsAux b h 0 = [] := by rw [digitsAux]
#align nat.digits_aux_zero Nat.digitsAux_zero
theorem digitsAux_def (b : ℕ) (h : 2 ≤ b) (n : ℕ) (w : 0 < n) :
digitsAux b h n = (n % b) :: digitsAux b h (n / b) := by
cases n
· cases w
· rw [digitsAux]
#align nat.digits_aux_def Nat.digitsAux_def
/-- `digits b n` gives the digits, in little-endian order,
of a natural number `n` in a specified base `b`.
In any base, we have `ofDigits b L = L.foldr (fun x y ↦ x + b * y) 0`.
* For any `2 ≤ b`, we have `l < b` for any `l ∈ digits b n`,
and the last digit is not zero.
This uniquely specifies the behaviour of `digits b`.
* For `b = 1`, we define `digits 1 n = List.replicate n 1`.
* For `b = 0`, we define `digits 0 n = [n]`, except `digits 0 0 = []`.
Note this differs from the existing `Nat.toDigits` in core, which is used for printing numerals.
In particular, `Nat.toDigits b 0 = ['0']`, while `digits b 0 = []`.
-/
def digits : ℕ → ℕ → List ℕ
| 0 => digitsAux0
| 1 => digitsAux1
| b + 2 => digitsAux (b + 2) (by norm_num)
#align nat.digits Nat.digits
@[simp]
theorem digits_zero (b : ℕ) : digits b 0 = [] := by
rcases b with (_ | ⟨_ | ⟨_⟩⟩) <;> simp [digits, digitsAux0, digitsAux1]
#align nat.digits_zero Nat.digits_zero
-- @[simp] -- Porting note (#10618): simp can prove this
theorem digits_zero_zero : digits 0 0 = [] :=
rfl
#align nat.digits_zero_zero Nat.digits_zero_zero
@[simp]
theorem digits_zero_succ (n : ℕ) : digits 0 n.succ = [n + 1] :=
rfl
#align nat.digits_zero_succ Nat.digits_zero_succ
theorem digits_zero_succ' : ∀ {n : ℕ}, n ≠ 0 → digits 0 n = [n]
| 0, h => (h rfl).elim
| _ + 1, _ => rfl
#align nat.digits_zero_succ' Nat.digits_zero_succ'
@[simp]
theorem digits_one (n : ℕ) : digits 1 n = List.replicate n 1 :=
rfl
#align nat.digits_one Nat.digits_one
-- @[simp] -- Porting note (#10685): dsimp can prove this
theorem digits_one_succ (n : ℕ) : digits 1 (n + 1) = 1 :: digits 1 n :=
rfl
#align nat.digits_one_succ Nat.digits_one_succ
theorem digits_add_two_add_one (b n : ℕ) :
digits (b + 2) (n + 1) = ((n + 1) % (b + 2)) :: digits (b + 2) ((n + 1) / (b + 2)) := by
simp [digits, digitsAux_def]
#align nat.digits_add_two_add_one Nat.digits_add_two_add_one
@[simp]
lemma digits_of_two_le_of_pos {b : ℕ} (hb : 2 ≤ b) (hn : 0 < n) :
Nat.digits b n = n % b :: Nat.digits b (n / b) := by
rw [Nat.eq_add_of_sub_eq hb rfl, Nat.eq_add_of_sub_eq hn rfl, Nat.digits_add_two_add_one]
theorem digits_def' :
∀ {b : ℕ} (_ : 1 < b) {n : ℕ} (_ : 0 < n), digits b n = (n % b) :: digits b (n / b)
| 0, h => absurd h (by decide)
| 1, h => absurd h (by decide)
| b + 2, _ => digitsAux_def _ (by simp) _
#align nat.digits_def' Nat.digits_def'
@[simp]
theorem digits_of_lt (b x : ℕ) (hx : x ≠ 0) (hxb : x < b) : digits b x = [x] := by
rcases exists_eq_succ_of_ne_zero hx with ⟨x, rfl⟩
rcases Nat.exists_eq_add_of_le' ((Nat.le_add_left 1 x).trans_lt hxb) with ⟨b, rfl⟩
rw [digits_add_two_add_one, div_eq_of_lt hxb, digits_zero, mod_eq_of_lt hxb]
#align nat.digits_of_lt Nat.digits_of_lt
theorem digits_add (b : ℕ) (h : 1 < b) (x y : ℕ) (hxb : x < b) (hxy : x ≠ 0 ∨ y ≠ 0) :
digits b (x + b * y) = x :: digits b y := by
rcases Nat.exists_eq_add_of_le' h with ⟨b, rfl : _ = _ + 2⟩
cases y
· simp [hxb, hxy.resolve_right (absurd rfl)]
dsimp [digits]
rw [digitsAux_def]
· congr
· simp [Nat.add_mod, mod_eq_of_lt hxb]
· simp [add_mul_div_left, div_eq_of_lt hxb]
· apply Nat.succ_pos
#align nat.digits_add Nat.digits_add
-- If we had a function converting a list into a polynomial,
-- and appropriate lemmas about that function,
-- we could rewrite this in terms of that.
/-- `ofDigits b L` takes a list `L` of natural numbers, and interprets them
as a number in semiring, as the little-endian digits in base `b`.
-/
def ofDigits {α : Type*} [Semiring α] (b : α) : List ℕ → α
| [] => 0
| h :: t => h + b * ofDigits b t
#align nat.of_digits Nat.ofDigits
theorem ofDigits_eq_foldr {α : Type*} [Semiring α] (b : α) (L : List ℕ) :
ofDigits b L = List.foldr (fun x y => ↑x + b * y) 0 L := by
induction' L with d L ih
· rfl
· dsimp [ofDigits]
rw [ih]
#align nat.of_digits_eq_foldr Nat.ofDigits_eq_foldr
theorem ofDigits_eq_sum_map_with_index_aux (b : ℕ) (l : List ℕ) :
((List.range l.length).zipWith ((fun i a : ℕ => a * b ^ (i + 1))) l).sum =
b * ((List.range l.length).zipWith (fun i a => a * b ^ i) l).sum := by
suffices
(List.range l.length).zipWith (fun i a : ℕ => a * b ^ (i + 1)) l =
(List.range l.length).zipWith (fun i a => b * (a * b ^ i)) l
by simp [this]
congr; ext; simp [pow_succ]; ring
#align nat.of_digits_eq_sum_map_with_index_aux Nat.ofDigits_eq_sum_map_with_index_aux
theorem ofDigits_eq_sum_mapIdx (b : ℕ) (L : List ℕ) :
ofDigits b L = (L.mapIdx fun i a => a * b ^ i).sum := by
rw [List.mapIdx_eq_enum_map, List.enum_eq_zip_range, List.map_uncurry_zip_eq_zipWith,
ofDigits_eq_foldr]
induction' L with hd tl hl
· simp
· simpa [List.range_succ_eq_map, List.zipWith_map_left, ofDigits_eq_sum_map_with_index_aux] using
Or.inl hl
#align nat.of_digits_eq_sum_map_with_index Nat.ofDigits_eq_sum_mapIdx
@[simp]
theorem ofDigits_nil {b : ℕ} : ofDigits b [] = 0 := rfl
@[simp]
theorem ofDigits_singleton {b n : ℕ} : ofDigits b [n] = n := by simp [ofDigits]
#align nat.of_digits_singleton Nat.ofDigits_singleton
@[simp]
theorem ofDigits_one_cons {α : Type*} [Semiring α] (h : ℕ) (L : List ℕ) :
ofDigits (1 : α) (h :: L) = h + ofDigits 1 L := by simp [ofDigits]
#align nat.of_digits_one_cons Nat.ofDigits_one_cons
theorem ofDigits_cons {b hd} {tl : List ℕ} :
ofDigits b (hd :: tl) = hd + b * ofDigits b tl := rfl
theorem ofDigits_append {b : ℕ} {l1 l2 : List ℕ} :
ofDigits b (l1 ++ l2) = ofDigits b l1 + b ^ l1.length * ofDigits b l2 := by
induction' l1 with hd tl IH
· simp [ofDigits]
· rw [ofDigits, List.cons_append, ofDigits, IH, List.length_cons, pow_succ']
ring
#align nat.of_digits_append Nat.ofDigits_append
@[norm_cast]
theorem coe_ofDigits (α : Type*) [Semiring α] (b : ℕ) (L : List ℕ) :
((ofDigits b L : ℕ) : α) = ofDigits (b : α) L := by
induction' L with d L ih
· simp [ofDigits]
· dsimp [ofDigits]; push_cast; rw [ih]
#align nat.coe_of_digits Nat.coe_ofDigits
@[norm_cast]
theorem coe_int_ofDigits (b : ℕ) (L : List ℕ) : ((ofDigits b L : ℕ) : ℤ) = ofDigits (b : ℤ) L := by
induction' L with d L _
· rfl
· dsimp [ofDigits]; push_cast; simp only
#align nat.coe_int_of_digits Nat.coe_int_ofDigits
theorem digits_zero_of_eq_zero {b : ℕ} (h : b ≠ 0) :
∀ {L : List ℕ} (_ : ofDigits b L = 0), ∀ l ∈ L, l = 0
| _ :: _, h0, _, List.Mem.head .. => Nat.eq_zero_of_add_eq_zero_right h0
| _ :: _, h0, _, List.Mem.tail _ hL =>
digits_zero_of_eq_zero h (mul_right_injective₀ h (Nat.eq_zero_of_add_eq_zero_left h0)) _ hL
#align nat.digits_zero_of_eq_zero Nat.digits_zero_of_eq_zero
theorem digits_ofDigits (b : ℕ) (h : 1 < b) (L : List ℕ) (w₁ : ∀ l ∈ L, l < b)
(w₂ : ∀ h : L ≠ [], L.getLast h ≠ 0) : digits b (ofDigits b L) = L := by
induction' L with d L ih
· dsimp [ofDigits]
simp
· dsimp [ofDigits]
replace w₂ := w₂ (by simp)
rw [digits_add b h]
· rw [ih]
· intro l m
apply w₁
exact List.mem_cons_of_mem _ m
· intro h
rw [List.getLast_cons h] at w₂
convert w₂
· exact w₁ d (List.mem_cons_self _ _)
· by_cases h' : L = []
· rcases h' with rfl
left
simpa using w₂
· right
contrapose! w₂
refine digits_zero_of_eq_zero h.ne_bot w₂ _ ?_
rw [List.getLast_cons h']
exact List.getLast_mem h'
#align nat.digits_of_digits Nat.digits_ofDigits
theorem ofDigits_digits (b n : ℕ) : ofDigits b (digits b n) = n := by
cases' b with b
· cases' n with n
· rfl
· change ofDigits 0 [n + 1] = n + 1
dsimp [ofDigits]
· cases' b with b
· induction' n with n ih
· rfl
· rw [Nat.zero_add] at ih ⊢
simp only [ih, add_comm 1, ofDigits_one_cons, Nat.cast_id, digits_one_succ]
· apply Nat.strongInductionOn n _
clear n
intro n h
cases n
· rw [digits_zero]
rfl
· simp only [Nat.succ_eq_add_one, digits_add_two_add_one]
dsimp [ofDigits]
rw [h _ (Nat.div_lt_self' _ b)]
rw [Nat.mod_add_div]
#align nat.of_digits_digits Nat.ofDigits_digits
| Mathlib/Data/Nat/Digits.lean | 290 | 293 | theorem ofDigits_one (L : List ℕ) : ofDigits 1 L = L.sum := by |
induction' L with _ _ ih
· rfl
· simp [ofDigits, List.sum_cons, ih]
|
/-
Copyright (c) 2018 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
-/
import Mathlib.Data.Finset.Sort
import Mathlib.Data.Vector.Basic
import Mathlib.Logic.Denumerable
#align_import logic.equiv.list from "leanprover-community/mathlib"@"d11893b411025250c8e61ff2f12ccbd7ee35ab15"
/-!
# Equivalences involving `List`-like types
This file defines some additional constructive equivalences using `Encodable` and the pairing
function on `ℕ`.
-/
open Nat List
namespace Encodable
variable {α : Type*}
section List
variable [Encodable α]
/-- Explicit encoding function for `List α` -/
def encodeList : List α → ℕ
| [] => 0
| a :: l => succ (pair (encode a) (encodeList l))
#align encodable.encode_list Encodable.encodeList
/-- Explicit decoding function for `List α` -/
def decodeList : ℕ → Option (List α)
| 0 => some []
| succ v =>
match unpair v, unpair_right_le v with
| (v₁, v₂), h =>
have : v₂ < succ v := lt_succ_of_le h
(· :: ·) <$> decode (α := α) v₁ <*> decodeList v₂
#align encodable.decode_list Encodable.decodeList
/-- If `α` is encodable, then so is `List α`. This uses the `pair` and `unpair` functions from
`Data.Nat.Pairing`. -/
instance _root_.List.encodable : Encodable (List α) :=
⟨encodeList, decodeList, fun l => by
induction' l with a l IH <;> simp [encodeList, decodeList, unpair_pair, encodek, *]⟩
#align list.encodable List.encodable
instance _root_.List.countable {α : Type*} [Countable α] : Countable (List α) := by
haveI := Encodable.ofCountable α
infer_instance
#align list.countable List.countable
@[simp]
theorem encode_list_nil : encode (@nil α) = 0 :=
rfl
#align encodable.encode_list_nil Encodable.encode_list_nil
@[simp]
theorem encode_list_cons (a : α) (l : List α) :
encode (a :: l) = succ (pair (encode a) (encode l)) :=
rfl
#align encodable.encode_list_cons Encodable.encode_list_cons
@[simp]
theorem decode_list_zero : decode (α := List α) 0 = some [] :=
show decodeList 0 = some [] by rw [decodeList]
#align encodable.decode_list_zero Encodable.decode_list_zero
@[simp, nolint unusedHavesSuffices] -- Porting note: false positive
theorem decode_list_succ (v : ℕ) :
decode (α := List α) (succ v) =
(· :: ·) <$> decode (α := α) v.unpair.1 <*> decode (α := List α) v.unpair.2 :=
show decodeList (succ v) = _ by
cases' e : unpair v with v₁ v₂
simp [decodeList, e]; rfl
#align encodable.decode_list_succ Encodable.decode_list_succ
theorem length_le_encode : ∀ l : List α, length l ≤ encode l
| [] => Nat.zero_le _
| _ :: l => succ_le_succ <| (length_le_encode l).trans (right_le_pair _ _)
#align encodable.length_le_encode Encodable.length_le_encode
end List
section Finset
variable [Encodable α]
private def enle : α → α → Prop :=
encode ⁻¹'o (· ≤ ·)
private theorem enle.isLinearOrder : IsLinearOrder α enle :=
(RelEmbedding.preimage ⟨encode, encode_injective⟩ (· ≤ ·)).isLinearOrder
private def decidable_enle (a b : α) : Decidable (enle a b) := by
unfold enle Order.Preimage
infer_instance
attribute [local instance] enle.isLinearOrder decidable_enle
/-- Explicit encoding function for `Multiset α` -/
def encodeMultiset (s : Multiset α) : ℕ :=
encode (s.sort enle)
#align encodable.encode_multiset Encodable.encodeMultiset
/-- Explicit decoding function for `Multiset α` -/
def decodeMultiset (n : ℕ) : Option (Multiset α) :=
((↑) : List α → Multiset α) <$> decode (α := List α) n
#align encodable.decode_multiset Encodable.decodeMultiset
/-- If `α` is encodable, then so is `Multiset α`. -/
instance _root_.Multiset.encodable : Encodable (Multiset α) :=
⟨encodeMultiset, decodeMultiset, fun s => by simp [encodeMultiset, decodeMultiset, encodek]⟩
#align multiset.encodable Multiset.encodable
/-- If `α` is countable, then so is `Multiset α`. -/
instance _root_.Multiset.countable {α : Type*} [Countable α] : Countable (Multiset α) :=
Quotient.countable
#align multiset.countable Multiset.countable
end Finset
/-- A listable type with decidable equality is encodable. -/
def encodableOfList [DecidableEq α] (l : List α) (H : ∀ x, x ∈ l) : Encodable α :=
⟨fun a => indexOf a l, l.get?, fun _ => indexOf_get? (H _)⟩
#align encodable.encodable_of_list Encodable.encodableOfList
/-- A finite type is encodable. Because the encoding is not unique, we wrap it in `Trunc` to
preserve computability. -/
def _root_.Fintype.truncEncodable (α : Type*) [DecidableEq α] [Fintype α] : Trunc (Encodable α) :=
@Quot.recOnSubsingleton' _ _ (fun s : Multiset α => (∀ x : α, x ∈ s) → Trunc (Encodable α)) _
Finset.univ.1 (fun l H => Trunc.mk <| encodableOfList l H) Finset.mem_univ
#align fintype.trunc_encodable Fintype.truncEncodable
/-- A noncomputable way to arbitrarily choose an ordering on a finite type.
It is not made into a global instance, since it involves an arbitrary choice.
This can be locally made into an instance with `attribute [local instance] Fintype.toEncodable`. -/
noncomputable def _root_.Fintype.toEncodable (α : Type*) [Fintype α] : Encodable α := by
classical exact (Fintype.truncEncodable α).out
#align fintype.to_encodable Fintype.toEncodable
/-- If `α` is encodable, then so is `Vector α n`. -/
instance _root_.Vector.encodable [Encodable α] {n} : Encodable (Vector α n) :=
Subtype.encodable
#align vector.encodable Vector.encodable
/-- If `α` is countable, then so is `Vector α n`. -/
instance _root_.Vector.countable [Countable α] {n} : Countable (Vector α n) :=
Subtype.countable
#align vector.countable Vector.countable
/-- If `α` is encodable, then so is `Fin n → α`. -/
instance finArrow [Encodable α] {n} : Encodable (Fin n → α) :=
ofEquiv _ (Equiv.vectorEquivFin _ _).symm
#align encodable.fin_arrow Encodable.finArrow
instance finPi (n) (π : Fin n → Type*) [∀ i, Encodable (π i)] : Encodable (∀ i, π i) :=
ofEquiv _ (Equiv.piEquivSubtypeSigma (Fin n) π)
#align encodable.fin_pi Encodable.finPi
/-- If `α` is encodable, then so is `Finset α`. -/
instance _root_.Finset.encodable [Encodable α] : Encodable (Finset α) :=
haveI := decidableEqOfEncodable α
ofEquiv { s : Multiset α // s.Nodup }
⟨fun ⟨a, b⟩ => ⟨a, b⟩, fun ⟨a, b⟩ => ⟨a, b⟩, fun ⟨_, _⟩ => rfl, fun ⟨_, _⟩ => rfl⟩
#align finset.encodable Finset.encodable
/-- If `α` is countable, then so is `Finset α`. -/
instance _root_.Finset.countable [Countable α] : Countable (Finset α) :=
Finset.val_injective.countable
#align finset.countable Finset.countable
-- TODO: Unify with `fintypePi` and find a better name
/-- When `α` is finite and `β` is encodable, `α → β` is encodable too. Because the encoding is not
unique, we wrap it in `Trunc` to preserve computability. -/
def fintypeArrow (α : Type*) (β : Type*) [DecidableEq α] [Fintype α] [Encodable β] :
Trunc (Encodable (α → β)) :=
(Fintype.truncEquivFin α).map fun f =>
Encodable.ofEquiv (Fin (Fintype.card α) → β) <| Equiv.arrowCongr f (Equiv.refl _)
#align encodable.fintype_arrow Encodable.fintypeArrow
/-- When `α` is finite and all `π a` are encodable, `Π a, π a` is encodable too. Because the
encoding is not unique, we wrap it in `Trunc` to preserve computability. -/
def fintypePi (α : Type*) (π : α → Type*) [DecidableEq α] [Fintype α] [∀ a, Encodable (π a)] :
Trunc (Encodable (∀ a, π a)) :=
(Fintype.truncEncodable α).bind fun a =>
(@fintypeArrow α (Σa, π a) _ _ (@Sigma.encodable _ _ a _)).bind fun f =>
Trunc.mk <|
@Encodable.ofEquiv _ _ (@Subtype.encodable _ _ f _)
(Equiv.piEquivSubtypeSigma α π)
#align encodable.fintype_pi Encodable.fintypePi
/-- The elements of a `Fintype` as a sorted list. -/
def sortedUniv (α) [Fintype α] [Encodable α] : List α :=
Finset.univ.sort (Encodable.encode' α ⁻¹'o (· ≤ ·))
#align encodable.sorted_univ Encodable.sortedUniv
@[simp]
theorem mem_sortedUniv {α} [Fintype α] [Encodable α] (x : α) : x ∈ sortedUniv α :=
(Finset.mem_sort _).2 (Finset.mem_univ _)
#align encodable.mem_sorted_univ Encodable.mem_sortedUniv
@[simp]
theorem length_sortedUniv (α) [Fintype α] [Encodable α] : (sortedUniv α).length = Fintype.card α :=
Finset.length_sort _
#align encodable.length_sorted_univ Encodable.length_sortedUniv
@[simp]
theorem sortedUniv_nodup (α) [Fintype α] [Encodable α] : (sortedUniv α).Nodup :=
Finset.sort_nodup _ _
#align encodable.sorted_univ_nodup Encodable.sortedUniv_nodup
@[simp]
theorem sortedUniv_toFinset (α) [Fintype α] [Encodable α] [DecidableEq α] :
(sortedUniv α).toFinset = Finset.univ :=
Finset.sort_toFinset _ _
#align encodable.sorted_univ_to_finset Encodable.sortedUniv_toFinset
/-- An encodable `Fintype` is equivalent to the same size `Fin`. -/
def fintypeEquivFin {α} [Fintype α] [Encodable α] : α ≃ Fin (Fintype.card α) :=
haveI : DecidableEq α := Encodable.decidableEqOfEncodable _
-- Porting note: used the `trans` tactic
((sortedUniv_nodup α).getEquivOfForallMemList _ mem_sortedUniv).symm.trans <|
Equiv.cast (congr_arg _ (length_sortedUniv α))
#align encodable.fintype_equiv_fin Encodable.fintypeEquivFin
/-- If `α` and `β` are encodable and `α` is a fintype, then `α → β` is encodable as well. -/
instance fintypeArrowOfEncodable {α β : Type*} [Encodable α] [Fintype α] [Encodable β] :
Encodable (α → β) :=
ofEquiv (Fin (Fintype.card α) → β) <| Equiv.arrowCongr fintypeEquivFin (Equiv.refl _)
#align encodable.fintype_arrow_of_encodable Encodable.fintypeArrowOfEncodable
end Encodable
namespace Denumerable
variable {α : Type*} {β : Type*} [Denumerable α] [Denumerable β]
open Encodable
section List
@[nolint unusedHavesSuffices] -- Porting note: false positive
theorem denumerable_list_aux : ∀ n : ℕ, ∃ a ∈ @decodeList α _ n, encodeList a = n
| 0 => by rw [decodeList]; exact ⟨_, rfl, rfl⟩
| succ v => by
cases' e : unpair v with v₁ v₂
have h := unpair_right_le v
rw [e] at h
rcases have : v₂ < succ v := lt_succ_of_le h
denumerable_list_aux v₂ with
⟨a, h₁, h₂⟩
rw [Option.mem_def] at h₁
use ofNat α v₁ :: a
simp [decodeList, e, h₂, h₁, encodeList, pair_unpair' e]
#align denumerable.denumerable_list_aux Denumerable.denumerable_list_aux
/-- If `α` is denumerable, then so is `List α`. -/
instance denumerableList : Denumerable (List α) :=
⟨denumerable_list_aux⟩
#align denumerable.denumerable_list Denumerable.denumerableList
@[simp]
| Mathlib/Logic/Equiv/List.lean | 269 | 269 | theorem list_ofNat_zero : ofNat (List α) 0 = [] := by | rw [← @encode_list_nil α, ofNat_encode]
|
/-
Copyright (c) 2022 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sébastien Gouëzel
-/
import Mathlib.Probability.IdentDistrib
import Mathlib.MeasureTheory.Integral.DominatedConvergence
import Mathlib.Analysis.SpecificLimits.FloorPow
import Mathlib.Analysis.PSeries
import Mathlib.Analysis.Asymptotics.SpecificAsymptotics
#align_import probability.strong_law from "leanprover-community/mathlib"@"f2ce6086713c78a7f880485f7917ea547a215982"
/-!
# The strong law of large numbers
We prove the strong law of large numbers, in `ProbabilityTheory.strong_law_ae`:
If `X n` is a sequence of independent identically distributed integrable random
variables, then `∑ i ∈ range n, X i / n` converges almost surely to `𝔼[X 0]`.
We give here the strong version, due to Etemadi, that only requires pairwise independence.
This file also contains the Lᵖ version of the strong law of large numbers provided by
`ProbabilityTheory.strong_law_Lp` which shows `∑ i ∈ range n, X i / n` converges in Lᵖ to
`𝔼[X 0]` provided `X n` is independent identically distributed and is Lᵖ.
## Implementation
The main point is to prove the result for real-valued random variables, as the general case
of Banach-space valued random variables follows from this case and approximation by simple
functions. The real version is given in `ProbabilityTheory.strong_law_ae_real`.
We follow the proof by Etemadi
[Etemadi, *An elementary proof of the strong law of large numbers*][etemadi_strong_law],
which goes as follows.
It suffices to prove the result for nonnegative `X`, as one can prove the general result by
splitting a general `X` into its positive part and negative part.
Consider `Xₙ` a sequence of nonnegative integrable identically distributed pairwise independent
random variables. Let `Yₙ` be the truncation of `Xₙ` up to `n`. We claim that
* Almost surely, `Xₙ = Yₙ` for all but finitely many indices. Indeed, `∑ ℙ (Xₙ ≠ Yₙ)` is bounded by
`1 + 𝔼[X]` (see `sum_prob_mem_Ioc_le` and `tsum_prob_mem_Ioi_lt_top`).
* Let `c > 1`. Along the sequence `n = c ^ k`, then `(∑_{i=0}^{n-1} Yᵢ - 𝔼[Yᵢ])/n` converges almost
surely to `0`. This follows from a variance control, as
```
∑_k ℙ (|∑_{i=0}^{c^k - 1} Yᵢ - 𝔼[Yᵢ]| > c^k ε)
≤ ∑_k (c^k ε)^{-2} ∑_{i=0}^{c^k - 1} Var[Yᵢ] (by Markov inequality)
≤ ∑_i (C/i^2) Var[Yᵢ] (as ∑_{c^k > i} 1/(c^k)^2 ≤ C/i^2)
≤ ∑_i (C/i^2) 𝔼[Yᵢ^2]
≤ 2C 𝔼[X^2] (see `sum_variance_truncation_le`)
```
* As `𝔼[Yᵢ]` converges to `𝔼[X]`, it follows from the two previous items and Cesàro that, along
the sequence `n = c^k`, one has `(∑_{i=0}^{n-1} Xᵢ) / n → 𝔼[X]` almost surely.
* To generalize it to all indices, we use the fact that `∑_{i=0}^{n-1} Xᵢ` is nondecreasing and
that, if `c` is close enough to `1`, the gap between `c^k` and `c^(k+1)` is small.
-/
noncomputable section
open MeasureTheory Filter Finset Asymptotics
open Set (indicator)
open scoped Topology MeasureTheory ProbabilityTheory ENNReal NNReal
namespace ProbabilityTheory
/-! ### Prerequisites on truncations -/
section Truncation
variable {α : Type*}
/-- Truncating a real-valued function to the interval `(-A, A]`. -/
def truncation (f : α → ℝ) (A : ℝ) :=
indicator (Set.Ioc (-A) A) id ∘ f
#align probability_theory.truncation ProbabilityTheory.truncation
variable {m : MeasurableSpace α} {μ : Measure α} {f : α → ℝ}
theorem _root_.MeasureTheory.AEStronglyMeasurable.truncation (hf : AEStronglyMeasurable f μ)
{A : ℝ} : AEStronglyMeasurable (truncation f A) μ := by
apply AEStronglyMeasurable.comp_aemeasurable _ hf.aemeasurable
exact (stronglyMeasurable_id.indicator measurableSet_Ioc).aestronglyMeasurable
#align measure_theory.ae_strongly_measurable.truncation MeasureTheory.AEStronglyMeasurable.truncation
theorem abs_truncation_le_bound (f : α → ℝ) (A : ℝ) (x : α) : |truncation f A x| ≤ |A| := by
simp only [truncation, Set.indicator, Set.mem_Icc, id, Function.comp_apply]
split_ifs with h
· exact abs_le_abs h.2 (neg_le.2 h.1.le)
· simp [abs_nonneg]
#align probability_theory.abs_truncation_le_bound ProbabilityTheory.abs_truncation_le_bound
@[simp]
theorem truncation_zero (f : α → ℝ) : truncation f 0 = 0 := by simp [truncation]; rfl
#align probability_theory.truncation_zero ProbabilityTheory.truncation_zero
theorem abs_truncation_le_abs_self (f : α → ℝ) (A : ℝ) (x : α) : |truncation f A x| ≤ |f x| := by
simp only [truncation, indicator, Set.mem_Icc, id, Function.comp_apply]
split_ifs
· exact le_rfl
· simp [abs_nonneg]
#align probability_theory.abs_truncation_le_abs_self ProbabilityTheory.abs_truncation_le_abs_self
theorem truncation_eq_self {f : α → ℝ} {A : ℝ} {x : α} (h : |f x| < A) :
truncation f A x = f x := by
simp only [truncation, indicator, Set.mem_Icc, id, Function.comp_apply, ite_eq_left_iff]
intro H
apply H.elim
simp [(abs_lt.1 h).1, (abs_lt.1 h).2.le]
#align probability_theory.truncation_eq_self ProbabilityTheory.truncation_eq_self
theorem truncation_eq_of_nonneg {f : α → ℝ} {A : ℝ} (h : ∀ x, 0 ≤ f x) :
truncation f A = indicator (Set.Ioc 0 A) id ∘ f := by
ext x
rcases (h x).lt_or_eq with (hx | hx)
· simp only [truncation, indicator, hx, Set.mem_Ioc, id, Function.comp_apply, true_and_iff]
by_cases h'x : f x ≤ A
· have : -A < f x := by linarith [h x]
simp only [this, true_and_iff]
· simp only [h'x, and_false_iff]
· simp only [truncation, indicator, hx, id, Function.comp_apply, ite_self]
#align probability_theory.truncation_eq_of_nonneg ProbabilityTheory.truncation_eq_of_nonneg
theorem truncation_nonneg {f : α → ℝ} (A : ℝ) {x : α} (h : 0 ≤ f x) : 0 ≤ truncation f A x :=
Set.indicator_apply_nonneg fun _ => h
#align probability_theory.truncation_nonneg ProbabilityTheory.truncation_nonneg
theorem _root_.MeasureTheory.AEStronglyMeasurable.memℒp_truncation [IsFiniteMeasure μ]
(hf : AEStronglyMeasurable f μ) {A : ℝ} {p : ℝ≥0∞} : Memℒp (truncation f A) p μ :=
Memℒp.of_bound hf.truncation |A| (eventually_of_forall fun _ => abs_truncation_le_bound _ _ _)
#align measure_theory.ae_strongly_measurable.mem_ℒp_truncation MeasureTheory.AEStronglyMeasurable.memℒp_truncation
theorem _root_.MeasureTheory.AEStronglyMeasurable.integrable_truncation [IsFiniteMeasure μ]
(hf : AEStronglyMeasurable f μ) {A : ℝ} : Integrable (truncation f A) μ := by
rw [← memℒp_one_iff_integrable]; exact hf.memℒp_truncation
#align measure_theory.ae_strongly_measurable.integrable_truncation MeasureTheory.AEStronglyMeasurable.integrable_truncation
theorem moment_truncation_eq_intervalIntegral (hf : AEStronglyMeasurable f μ) {A : ℝ} (hA : 0 ≤ A)
{n : ℕ} (hn : n ≠ 0) : ∫ x, truncation f A x ^ n ∂μ = ∫ y in -A..A, y ^ n ∂Measure.map f μ := by
have M : MeasurableSet (Set.Ioc (-A) A) := measurableSet_Ioc
change ∫ x, (fun z => indicator (Set.Ioc (-A) A) id z ^ n) (f x) ∂μ = _
rw [← integral_map (f := fun z => _ ^ n) hf.aemeasurable, intervalIntegral.integral_of_le,
← integral_indicator M]
· simp only [indicator, zero_pow hn, id, ite_pow]
· linarith
· exact ((measurable_id.indicator M).pow_const n).aestronglyMeasurable
#align probability_theory.moment_truncation_eq_interval_integral ProbabilityTheory.moment_truncation_eq_intervalIntegral
theorem moment_truncation_eq_intervalIntegral_of_nonneg (hf : AEStronglyMeasurable f μ) {A : ℝ}
{n : ℕ} (hn : n ≠ 0) (h'f : 0 ≤ f) :
∫ x, truncation f A x ^ n ∂μ = ∫ y in (0)..A, y ^ n ∂Measure.map f μ := by
have M : MeasurableSet (Set.Ioc 0 A) := measurableSet_Ioc
have M' : MeasurableSet (Set.Ioc A 0) := measurableSet_Ioc
rw [truncation_eq_of_nonneg h'f]
change ∫ x, (fun z => indicator (Set.Ioc 0 A) id z ^ n) (f x) ∂μ = _
rcases le_or_lt 0 A with (hA | hA)
· rw [← integral_map (f := fun z => _ ^ n) hf.aemeasurable, intervalIntegral.integral_of_le hA,
← integral_indicator M]
· simp only [indicator, zero_pow hn, id, ite_pow]
· exact ((measurable_id.indicator M).pow_const n).aestronglyMeasurable
· rw [← integral_map (f := fun z => _ ^ n) hf.aemeasurable, intervalIntegral.integral_of_ge hA.le,
← integral_indicator M']
· simp only [Set.Ioc_eq_empty_of_le hA.le, zero_pow hn, Set.indicator_empty, integral_zero,
zero_eq_neg]
apply integral_eq_zero_of_ae
have : ∀ᵐ x ∂Measure.map f μ, (0 : ℝ) ≤ x :=
(ae_map_iff hf.aemeasurable measurableSet_Ici).2 (eventually_of_forall h'f)
filter_upwards [this] with x hx
simp only [indicator, Set.mem_Ioc, Pi.zero_apply, ite_eq_right_iff, and_imp]
intro _ h''x
have : x = 0 := by linarith
simp [this, zero_pow hn]
· exact ((measurable_id.indicator M).pow_const n).aestronglyMeasurable
#align probability_theory.moment_truncation_eq_interval_integral_of_nonneg ProbabilityTheory.moment_truncation_eq_intervalIntegral_of_nonneg
theorem integral_truncation_eq_intervalIntegral (hf : AEStronglyMeasurable f μ) {A : ℝ}
(hA : 0 ≤ A) : ∫ x, truncation f A x ∂μ = ∫ y in -A..A, y ∂Measure.map f μ := by
simpa using moment_truncation_eq_intervalIntegral hf hA one_ne_zero
#align probability_theory.integral_truncation_eq_interval_integral ProbabilityTheory.integral_truncation_eq_intervalIntegral
theorem integral_truncation_eq_intervalIntegral_of_nonneg (hf : AEStronglyMeasurable f μ) {A : ℝ}
(h'f : 0 ≤ f) : ∫ x, truncation f A x ∂μ = ∫ y in (0)..A, y ∂Measure.map f μ := by
simpa using moment_truncation_eq_intervalIntegral_of_nonneg hf one_ne_zero h'f
#align probability_theory.integral_truncation_eq_interval_integral_of_nonneg ProbabilityTheory.integral_truncation_eq_intervalIntegral_of_nonneg
theorem integral_truncation_le_integral_of_nonneg (hf : Integrable f μ) (h'f : 0 ≤ f) {A : ℝ} :
∫ x, truncation f A x ∂μ ≤ ∫ x, f x ∂μ := by
apply integral_mono_of_nonneg
(eventually_of_forall fun x => ?_) hf (eventually_of_forall fun x => ?_)
· exact truncation_nonneg _ (h'f x)
· calc
truncation f A x ≤ |truncation f A x| := le_abs_self _
_ ≤ |f x| := abs_truncation_le_abs_self _ _ _
_ = f x := abs_of_nonneg (h'f x)
#align probability_theory.integral_truncation_le_integral_of_nonneg ProbabilityTheory.integral_truncation_le_integral_of_nonneg
/-- If a function is integrable, then the integral of its truncated versions converges to the
integral of the whole function. -/
theorem tendsto_integral_truncation {f : α → ℝ} (hf : Integrable f μ) :
Tendsto (fun A => ∫ x, truncation f A x ∂μ) atTop (𝓝 (∫ x, f x ∂μ)) := by
refine tendsto_integral_filter_of_dominated_convergence (fun x => abs (f x)) ?_ ?_ ?_ ?_
· exact eventually_of_forall fun A ↦ hf.aestronglyMeasurable.truncation
· filter_upwards with A
filter_upwards with x
rw [Real.norm_eq_abs]
exact abs_truncation_le_abs_self _ _ _
· exact hf.abs
· filter_upwards with x
apply tendsto_const_nhds.congr' _
filter_upwards [Ioi_mem_atTop (abs (f x))] with A hA
exact (truncation_eq_self hA).symm
#align probability_theory.tendsto_integral_truncation ProbabilityTheory.tendsto_integral_truncation
theorem IdentDistrib.truncation {β : Type*} [MeasurableSpace β] {ν : Measure β} {f : α → ℝ}
{g : β → ℝ} (h : IdentDistrib f g μ ν) {A : ℝ} :
IdentDistrib (truncation f A) (truncation g A) μ ν :=
h.comp (measurable_id.indicator measurableSet_Ioc)
#align probability_theory.ident_distrib.truncation ProbabilityTheory.IdentDistrib.truncation
end Truncation
section StrongLawAeReal
variable {Ω : Type*} [MeasureSpace Ω] [IsProbabilityMeasure (ℙ : Measure Ω)]
section MomentEstimates
theorem sum_prob_mem_Ioc_le {X : Ω → ℝ} (hint : Integrable X) (hnonneg : 0 ≤ X) {K : ℕ} {N : ℕ}
(hKN : K ≤ N) :
∑ j ∈ range K, ℙ {ω | X ω ∈ Set.Ioc (j : ℝ) N} ≤ ENNReal.ofReal (𝔼[X] + 1) := by
let ρ : Measure ℝ := Measure.map X ℙ
haveI : IsProbabilityMeasure ρ := isProbabilityMeasure_map hint.aemeasurable
have A : ∑ j ∈ range K, ∫ _ in j..N, (1 : ℝ) ∂ρ ≤ 𝔼[X] + 1 :=
calc
∑ j ∈ range K, ∫ _ in j..N, (1 : ℝ) ∂ρ =
∑ j ∈ range K, ∑ i ∈ Ico j N, ∫ _ in i..(i + 1 : ℕ), (1 : ℝ) ∂ρ := by
apply sum_congr rfl fun j hj => ?_
rw [intervalIntegral.sum_integral_adjacent_intervals_Ico ((mem_range.1 hj).le.trans hKN)]
intro k _
exact continuous_const.intervalIntegrable _ _
_ = ∑ i ∈ range N, ∑ j ∈ range (min (i + 1) K), ∫ _ in i..(i + 1 : ℕ), (1 : ℝ) ∂ρ := by
simp_rw [sum_sigma']
refine sum_nbij' (fun p ↦ ⟨p.2, p.1⟩) (fun p ↦ ⟨p.2, p.1⟩) ?_ ?_ ?_ ?_ ?_ <;>
aesop (add simp Nat.lt_succ_iff)
_ ≤ ∑ i ∈ range N, (i + 1) * ∫ _ in i..(i + 1 : ℕ), (1 : ℝ) ∂ρ := by
apply sum_le_sum fun i _ => ?_
simp only [Nat.cast_add, Nat.cast_one, sum_const, card_range, nsmul_eq_mul, Nat.cast_min]
refine mul_le_mul_of_nonneg_right (min_le_left _ _) ?_
apply intervalIntegral.integral_nonneg
· simp only [le_add_iff_nonneg_right, zero_le_one]
· simp only [zero_le_one, imp_true_iff]
_ ≤ ∑ i ∈ range N, ∫ x in i..(i + 1 : ℕ), x + 1 ∂ρ := by
apply sum_le_sum fun i _ => ?_
have I : (i : ℝ) ≤ (i + 1 : ℕ) := by
simp only [Nat.cast_add, Nat.cast_one, le_add_iff_nonneg_right, zero_le_one]
simp_rw [intervalIntegral.integral_of_le I, ← integral_mul_left]
apply setIntegral_mono_on
· exact continuous_const.integrableOn_Ioc
· exact (continuous_id.add continuous_const).integrableOn_Ioc
· exact measurableSet_Ioc
· intro x hx
simp only [Nat.cast_add, Nat.cast_one, Set.mem_Ioc] at hx
simp [hx.1.le]
_ = ∫ x in (0)..N, x + 1 ∂ρ := by
rw [intervalIntegral.sum_integral_adjacent_intervals fun k _ => ?_]
· norm_cast
· exact (continuous_id.add continuous_const).intervalIntegrable _ _
_ = ∫ x in (0)..N, x ∂ρ + ∫ x in (0)..N, 1 ∂ρ := by
rw [intervalIntegral.integral_add]
· exact continuous_id.intervalIntegrable _ _
· exact continuous_const.intervalIntegrable _ _
_ = 𝔼[truncation X N] + ∫ x in (0)..N, 1 ∂ρ := by
rw [integral_truncation_eq_intervalIntegral_of_nonneg hint.1 hnonneg]
_ ≤ 𝔼[X] + ∫ x in (0)..N, 1 ∂ρ :=
(add_le_add_right (integral_truncation_le_integral_of_nonneg hint hnonneg) _)
_ ≤ 𝔼[X] + 1 := by
refine add_le_add le_rfl ?_
rw [intervalIntegral.integral_of_le (Nat.cast_nonneg _)]
simp only [integral_const, Measure.restrict_apply', measurableSet_Ioc, Set.univ_inter,
Algebra.id.smul_eq_mul, mul_one]
rw [← ENNReal.one_toReal]
exact ENNReal.toReal_mono ENNReal.one_ne_top prob_le_one
have B : ∀ a b, ℙ {ω | X ω ∈ Set.Ioc a b} = ENNReal.ofReal (∫ _ in Set.Ioc a b, (1 : ℝ) ∂ρ) := by
intro a b
rw [ofReal_setIntegral_one ρ _,
Measure.map_apply_of_aemeasurable hint.aemeasurable measurableSet_Ioc]
rfl
calc
∑ j ∈ range K, ℙ {ω | X ω ∈ Set.Ioc (j : ℝ) N} =
∑ j ∈ range K, ENNReal.ofReal (∫ _ in Set.Ioc (j : ℝ) N, (1 : ℝ) ∂ρ) := by simp_rw [B]
_ = ENNReal.ofReal (∑ j ∈ range K, ∫ _ in Set.Ioc (j : ℝ) N, (1 : ℝ) ∂ρ) := by
rw [ENNReal.ofReal_sum_of_nonneg]
simp only [integral_const, Algebra.id.smul_eq_mul, mul_one, ENNReal.toReal_nonneg,
imp_true_iff]
_ = ENNReal.ofReal (∑ j ∈ range K, ∫ _ in (j : ℝ)..N, (1 : ℝ) ∂ρ) := by
congr 1
refine sum_congr rfl fun j hj => ?_
rw [intervalIntegral.integral_of_le (Nat.cast_le.2 ((mem_range.1 hj).le.trans hKN))]
_ ≤ ENNReal.ofReal (𝔼[X] + 1) := ENNReal.ofReal_le_ofReal A
#align probability_theory.sum_prob_mem_Ioc_le ProbabilityTheory.sum_prob_mem_Ioc_le
theorem tsum_prob_mem_Ioi_lt_top {X : Ω → ℝ} (hint : Integrable X) (hnonneg : 0 ≤ X) :
(∑' j : ℕ, ℙ {ω | X ω ∈ Set.Ioi (j : ℝ)}) < ∞ := by
suffices ∀ K : ℕ, ∑ j ∈ range K, ℙ {ω | X ω ∈ Set.Ioi (j : ℝ)} ≤ ENNReal.ofReal (𝔼[X] + 1) from
(le_of_tendsto_of_tendsto (ENNReal.tendsto_nat_tsum _) tendsto_const_nhds
(eventually_of_forall this)).trans_lt ENNReal.ofReal_lt_top
intro K
have A : Tendsto (fun N : ℕ => ∑ j ∈ range K, ℙ {ω | X ω ∈ Set.Ioc (j : ℝ) N}) atTop
(𝓝 (∑ j ∈ range K, ℙ {ω | X ω ∈ Set.Ioi (j : ℝ)})) := by
refine tendsto_finset_sum _ fun i _ => ?_
have : {ω | X ω ∈ Set.Ioi (i : ℝ)} = ⋃ N : ℕ, {ω | X ω ∈ Set.Ioc (i : ℝ) N} := by
apply Set.Subset.antisymm _ _
· intro ω hω
obtain ⟨N, hN⟩ : ∃ N : ℕ, X ω ≤ N := exists_nat_ge (X ω)
exact Set.mem_iUnion.2 ⟨N, hω, hN⟩
· simp (config := {contextual := true}) only [Set.mem_Ioc, Set.mem_Ioi,
Set.iUnion_subset_iff, Set.setOf_subset_setOf, imp_true_iff]
rw [this]
apply tendsto_measure_iUnion
intro m n hmn x hx
exact ⟨hx.1, hx.2.trans (Nat.cast_le.2 hmn)⟩
apply le_of_tendsto_of_tendsto A tendsto_const_nhds
filter_upwards [Ici_mem_atTop K] with N hN
exact sum_prob_mem_Ioc_le hint hnonneg hN
#align probability_theory.tsum_prob_mem_Ioi_lt_top ProbabilityTheory.tsum_prob_mem_Ioi_lt_top
theorem sum_variance_truncation_le {X : Ω → ℝ} (hint : Integrable X) (hnonneg : 0 ≤ X) (K : ℕ) :
∑ j ∈ range K, ((j : ℝ) ^ 2)⁻¹ * 𝔼[truncation X j ^ 2] ≤ 2 * 𝔼[X] := by
set Y := fun n : ℕ => truncation X n
let ρ : Measure ℝ := Measure.map X ℙ
have Y2 : ∀ n, 𝔼[Y n ^ 2] = ∫ x in (0)..n, x ^ 2 ∂ρ := by
intro n
change 𝔼[fun x => Y n x ^ 2] = _
rw [moment_truncation_eq_intervalIntegral_of_nonneg hint.1 two_ne_zero hnonneg]
calc
∑ j ∈ range K, ((j : ℝ) ^ 2)⁻¹ * 𝔼[Y j ^ 2] =
∑ j ∈ range K, ((j : ℝ) ^ 2)⁻¹ * ∫ x in (0)..j, x ^ 2 ∂ρ := by simp_rw [Y2]
_ = ∑ j ∈ range K, ((j : ℝ) ^ 2)⁻¹ * ∑ k ∈ range j, ∫ x in k..(k + 1 : ℕ), x ^ 2 ∂ρ := by
congr 1 with j
congr 1
rw [intervalIntegral.sum_integral_adjacent_intervals]
· norm_cast
intro k _
exact (continuous_id.pow _).intervalIntegrable _ _
_ = ∑ k ∈ range K, (∑ j ∈ Ioo k K, ((j : ℝ) ^ 2)⁻¹) * ∫ x in k..(k + 1 : ℕ), x ^ 2 ∂ρ := by
simp_rw [mul_sum, sum_mul, sum_sigma']
refine sum_nbij' (fun p ↦ ⟨p.2, p.1⟩) (fun p ↦ ⟨p.2, p.1⟩) ?_ ?_ ?_ ?_ ?_ <;>
aesop (add unsafe lt_trans)
_ ≤ ∑ k ∈ range K, 2 / (k + 1 : ℝ) * ∫ x in k..(k + 1 : ℕ), x ^ 2 ∂ρ := by
apply sum_le_sum fun k _ => ?_
refine mul_le_mul_of_nonneg_right (sum_Ioo_inv_sq_le _ _) ?_
refine intervalIntegral.integral_nonneg_of_forall ?_ fun u => sq_nonneg _
simp only [Nat.cast_add, Nat.cast_one, le_add_iff_nonneg_right, zero_le_one]
_ ≤ ∑ k ∈ range K, ∫ x in k..(k + 1 : ℕ), 2 * x ∂ρ := by
apply sum_le_sum fun k _ => ?_
have Ik : (k : ℝ) ≤ (k + 1 : ℕ) := by simp
rw [← intervalIntegral.integral_const_mul, intervalIntegral.integral_of_le Ik,
intervalIntegral.integral_of_le Ik]
refine setIntegral_mono_on ?_ ?_ measurableSet_Ioc fun x hx => ?_
· apply Continuous.integrableOn_Ioc
exact continuous_const.mul (continuous_pow 2)
· apply Continuous.integrableOn_Ioc
exact continuous_const.mul continuous_id'
· calc
↑2 / (↑k + ↑1) * x ^ 2 = x / (k + 1) * (2 * x) := by ring
_ ≤ 1 * (2 * x) :=
(mul_le_mul_of_nonneg_right (by
convert (div_le_one _).2 hx.2
· norm_cast
simp only [Nat.cast_add, Nat.cast_one]
linarith only [show (0 : ℝ) ≤ k from Nat.cast_nonneg k])
(mul_nonneg zero_le_two ((Nat.cast_nonneg k).trans hx.1.le)))
_ = 2 * x := by rw [one_mul]
_ = 2 * ∫ x in (0 : ℝ)..K, x ∂ρ := by
rw [intervalIntegral.sum_integral_adjacent_intervals fun k _ => ?_]
swap; · exact (continuous_const.mul continuous_id').intervalIntegrable _ _
rw [intervalIntegral.integral_const_mul]
norm_cast
_ ≤ 2 * 𝔼[X] := mul_le_mul_of_nonneg_left (by
rw [← integral_truncation_eq_intervalIntegral_of_nonneg hint.1 hnonneg]
exact integral_truncation_le_integral_of_nonneg hint hnonneg) zero_le_two
#align probability_theory.sum_variance_truncation_le ProbabilityTheory.sum_variance_truncation_le
end MomentEstimates
/-! Proof of the strong law of large numbers (almost sure version, assuming only
pairwise independence) for nonnegative random variables, following Etemadi's proof. -/
section StrongLawNonneg
variable (X : ℕ → Ω → ℝ) (hint : Integrable (X 0))
(hindep : Pairwise fun i j => IndepFun (X i) (X j)) (hident : ∀ i, IdentDistrib (X i) (X 0))
(hnonneg : ∀ i ω, 0 ≤ X i ω)
/-- The truncation of `Xᵢ` up to `i` satisfies the strong law of large numbers (with respect to
the truncated expectation) along the sequence `c^n`, for any `c > 1`, up to a given `ε > 0`.
This follows from a variance control. -/
theorem strong_law_aux1 {c : ℝ} (c_one : 1 < c) {ε : ℝ} (εpos : 0 < ε) : ∀ᵐ ω, ∀ᶠ n : ℕ in atTop,
|∑ i ∈ range ⌊c ^ n⌋₊, truncation (X i) i ω - 𝔼[∑ i ∈ range ⌊c ^ n⌋₊, truncation (X i) i]| <
ε * ⌊c ^ n⌋₊ := by
/- Let `S n = ∑ i ∈ range n, Y i` where `Y i = truncation (X i) i`. We should show that
`|S k - 𝔼[S k]| / k ≤ ε` along the sequence of powers of `c`. For this, we apply Borel-Cantelli:
it suffices to show that the converse probabilites are summable. From Chebyshev inequality, this
will follow from a variance control `∑' Var[S (c^i)] / (c^i)^2 < ∞`. This is checked in `I2`
using pairwise independence to expand the variance of the sum as the sum of the variances,
and then a straightforward but tedious computation (essentially boiling down to the fact that
the sum of `1/(c ^ i)^2` beyong a threshold `j` is comparable to `1/j^2`).
Note that we have written `c^i` in the above proof sketch, but rigorously one should put integer
parts everywhere, making things more painful. We write `u i = ⌊c^i⌋₊` for brevity. -/
have c_pos : 0 < c := zero_lt_one.trans c_one
have hX : ∀ i, AEStronglyMeasurable (X i) ℙ := fun i =>
(hident i).symm.aestronglyMeasurable_snd hint.1
have A : ∀ i, StronglyMeasurable (indicator (Set.Ioc (-i : ℝ) i) id) := fun i =>
stronglyMeasurable_id.indicator measurableSet_Ioc
set Y := fun n : ℕ => truncation (X n) n
set S := fun n => ∑ i ∈ range n, Y i with hS
let u : ℕ → ℕ := fun n => ⌊c ^ n⌋₊
have u_mono : Monotone u := fun i j hij => Nat.floor_mono (pow_le_pow_right c_one.le hij)
have I1 : ∀ K, ∑ j ∈ range K, ((j : ℝ) ^ 2)⁻¹ * Var[Y j] ≤ 2 * 𝔼[X 0] := by
intro K
calc
∑ j ∈ range K, ((j : ℝ) ^ 2)⁻¹ * Var[Y j] ≤
∑ j ∈ range K, ((j : ℝ) ^ 2)⁻¹ * 𝔼[truncation (X 0) j ^ 2] := by
apply sum_le_sum fun j _ => ?_
refine mul_le_mul_of_nonneg_left ?_ (inv_nonneg.2 (sq_nonneg _))
rw [(hident j).truncation.variance_eq]
exact variance_le_expectation_sq (hX 0).truncation
_ ≤ 2 * 𝔼[X 0] := sum_variance_truncation_le hint (hnonneg 0) K
let C := c ^ 5 * (c - 1)⁻¹ ^ 3 * (2 * 𝔼[X 0])
have I2 : ∀ N, ∑ i ∈ range N, ((u i : ℝ) ^ 2)⁻¹ * Var[S (u i)] ≤ C := by
intro N
calc
∑ i ∈ range N, ((u i : ℝ) ^ 2)⁻¹ * Var[S (u i)] =
∑ i ∈ range N, ((u i : ℝ) ^ 2)⁻¹ * ∑ j ∈ range (u i), Var[Y j] := by
congr 1 with i
congr 1
rw [hS, IndepFun.variance_sum]
· intro j _
exact (hident j).aestronglyMeasurable_fst.memℒp_truncation
· intro k _ l _ hkl
exact (hindep hkl).comp (A k).measurable (A l).measurable
_ = ∑ j ∈ range (u (N - 1)),
(∑ i ∈ (range N).filter fun i => j < u i, ((u i : ℝ) ^ 2)⁻¹) * Var[Y j] := by
simp_rw [mul_sum, sum_mul, sum_sigma']
refine sum_nbij' (fun p ↦ ⟨p.2, p.1⟩) (fun p ↦ ⟨p.2, p.1⟩) ?_ ?_ ?_ ?_ ?_
· simp only [mem_sigma, mem_range, filter_congr_decidable, mem_filter, and_imp,
Sigma.forall]
exact fun a b haN hb ↦ ⟨hb.trans_le <| u_mono <| Nat.le_pred_of_lt haN, haN, hb⟩
all_goals aesop
_ ≤ ∑ j ∈ range (u (N - 1)), c ^ 5 * (c - 1)⁻¹ ^ 3 / ↑j ^ 2 * Var[Y j] := by
apply sum_le_sum fun j hj => ?_
rcases @eq_zero_or_pos _ _ j with (rfl | hj)
· simp only [Nat.cast_zero, zero_pow, Ne, bit0_eq_zero, Nat.one_ne_zero,
not_false_iff, div_zero, zero_mul]
simp only [Y, Nat.cast_zero, truncation_zero, variance_zero, mul_zero, le_rfl]
apply mul_le_mul_of_nonneg_right _ (variance_nonneg _ _)
convert sum_div_nat_floor_pow_sq_le_div_sq N (Nat.cast_pos.2 hj) c_one using 2
· simp only [Nat.cast_lt]
· simp only [one_div]
_ = c ^ 5 * (c - 1)⁻¹ ^ 3 * ∑ j ∈ range (u (N - 1)), ((j : ℝ) ^ 2)⁻¹ * Var[Y j] := by
simp_rw [mul_sum, div_eq_mul_inv, mul_assoc]
_ ≤ c ^ 5 * (c - 1)⁻¹ ^ 3 * (2 * 𝔼[X 0]) := by
apply mul_le_mul_of_nonneg_left (I1 _)
apply mul_nonneg (pow_nonneg c_pos.le _)
exact pow_nonneg (inv_nonneg.2 (sub_nonneg.2 c_one.le)) _
have I3 : ∀ N, ∑ i ∈ range N, ℙ {ω | (u i * ε : ℝ) ≤ |S (u i) ω - 𝔼[S (u i)]|} ≤
ENNReal.ofReal (ε⁻¹ ^ 2 * C) := by
intro N
calc
∑ i ∈ range N, ℙ {ω | (u i * ε : ℝ) ≤ |S (u i) ω - 𝔼[S (u i)]|} ≤
∑ i ∈ range N, ENNReal.ofReal (Var[S (u i)] / (u i * ε) ^ 2) := by
refine sum_le_sum fun i _ => ?_
apply meas_ge_le_variance_div_sq
· exact memℒp_finset_sum' _ fun j _ => (hident j).aestronglyMeasurable_fst.memℒp_truncation
· apply mul_pos (Nat.cast_pos.2 _) εpos
refine zero_lt_one.trans_le ?_
apply Nat.le_floor
rw [Nat.cast_one]
apply one_le_pow_of_one_le c_one.le
_ = ENNReal.ofReal (∑ i ∈ range N, Var[S (u i)] / (u i * ε) ^ 2) := by
rw [ENNReal.ofReal_sum_of_nonneg fun i _ => ?_]
exact div_nonneg (variance_nonneg _ _) (sq_nonneg _)
_ ≤ ENNReal.ofReal (ε⁻¹ ^ 2 * C) := by
apply ENNReal.ofReal_le_ofReal
-- Porting note: do most of the rewrites under `conv` so as not to expand `variance`
conv_lhs =>
enter [2, i]
rw [div_eq_inv_mul, ← inv_pow, mul_inv, mul_comm _ ε⁻¹, mul_pow, mul_assoc]
rw [← mul_sum]
refine mul_le_mul_of_nonneg_left ?_ (sq_nonneg _)
conv_lhs => enter [2, i]; rw [inv_pow]
exact I2 N
have I4 : (∑' i, ℙ {ω | (u i * ε : ℝ) ≤ |S (u i) ω - 𝔼[S (u i)]|}) < ∞ :=
(le_of_tendsto_of_tendsto' (ENNReal.tendsto_nat_tsum _) tendsto_const_nhds I3).trans_lt
ENNReal.ofReal_lt_top
filter_upwards [ae_eventually_not_mem I4.ne] with ω hω
simp_rw [S, not_le, mul_comm, sum_apply] at hω
convert hω; simp only [sum_apply]
#align probability_theory.strong_law_aux1 ProbabilityTheory.strong_law_aux1
/- The truncation of `Xᵢ` up to `i` satisfies the strong law of large numbers
(with respect to the truncated expectation) along the sequence
`c^n`, for any `c > 1`. This follows from `strong_law_aux1` by varying `ε`. -/
theorem strong_law_aux2 {c : ℝ} (c_one : 1 < c) :
∀ᵐ ω, (fun n : ℕ => ∑ i ∈ range ⌊c ^ n⌋₊, truncation (X i) i ω -
𝔼[∑ i ∈ range ⌊c ^ n⌋₊, truncation (X i) i]) =o[atTop] fun n : ℕ => (⌊c ^ n⌋₊ : ℝ) := by
obtain ⟨v, -, v_pos, v_lim⟩ :
∃ v : ℕ → ℝ, StrictAnti v ∧ (∀ n : ℕ, 0 < v n) ∧ Tendsto v atTop (𝓝 0) :=
exists_seq_strictAnti_tendsto (0 : ℝ)
have := fun i => strong_law_aux1 X hint hindep hident hnonneg c_one (v_pos i)
filter_upwards [ae_all_iff.2 this] with ω hω
apply Asymptotics.isLittleO_iff.2 fun ε εpos => ?_
obtain ⟨i, hi⟩ : ∃ i, v i < ε := ((tendsto_order.1 v_lim).2 ε εpos).exists
filter_upwards [hω i] with n hn
simp only [Real.norm_eq_abs, abs_abs, Nat.abs_cast]
exact hn.le.trans (mul_le_mul_of_nonneg_right hi.le (Nat.cast_nonneg _))
#align probability_theory.strong_law_aux2 ProbabilityTheory.strong_law_aux2
/-- The expectation of the truncated version of `Xᵢ` behaves asymptotically like the whole
expectation. This follows from convergence and Cesàro averaging. -/
theorem strong_law_aux3 :
(fun n => 𝔼[∑ i ∈ range n, truncation (X i) i] - n * 𝔼[X 0]) =o[atTop] ((↑) : ℕ → ℝ) := by
have A : Tendsto (fun i => 𝔼[truncation (X i) i]) atTop (𝓝 𝔼[X 0]) := by
convert (tendsto_integral_truncation hint).comp tendsto_natCast_atTop_atTop using 1
ext i
exact (hident i).truncation.integral_eq
convert Asymptotics.isLittleO_sum_range_of_tendsto_zero (tendsto_sub_nhds_zero_iff.2 A) using 1
ext1 n
simp only [sum_sub_distrib, sum_const, card_range, nsmul_eq_mul, sum_apply, sub_left_inj]
rw [integral_finset_sum _ fun i _ => ?_]
exact ((hident i).symm.integrable_snd hint).1.integrable_truncation
#align probability_theory.strong_law_aux3 ProbabilityTheory.strong_law_aux3
/- The truncation of `Xᵢ` up to `i` satisfies the strong law of large numbers
(with respect to the original expectation) along the sequence
`c^n`, for any `c > 1`. This follows from the version from the truncated expectation, and the
fact that the truncated and the original expectations have the same asymptotic behavior. -/
theorem strong_law_aux4 {c : ℝ} (c_one : 1 < c) :
∀ᵐ ω, (fun n : ℕ => ∑ i ∈ range ⌊c ^ n⌋₊, truncation (X i) i ω - ⌊c ^ n⌋₊ * 𝔼[X 0]) =o[atTop]
fun n : ℕ => (⌊c ^ n⌋₊ : ℝ) := by
filter_upwards [strong_law_aux2 X hint hindep hident hnonneg c_one] with ω hω
have A : Tendsto (fun n : ℕ => ⌊c ^ n⌋₊) atTop atTop :=
tendsto_nat_floor_atTop.comp (tendsto_pow_atTop_atTop_of_one_lt c_one)
convert hω.add ((strong_law_aux3 X hint hident).comp_tendsto A) using 1
ext1 n
simp
#align probability_theory.strong_law_aux4 ProbabilityTheory.strong_law_aux4
/-- The truncated and non-truncated versions of `Xᵢ` have the same asymptotic behavior, as they
almost surely coincide at all but finitely many steps. This follows from a probability computation
and Borel-Cantelli. -/
| Mathlib/Probability/StrongLaw.lean | 553 | 575 | theorem strong_law_aux5 :
∀ᵐ ω, (fun n : ℕ => ∑ i ∈ range n, truncation (X i) i ω - ∑ i ∈ range n, X i ω) =o[atTop]
fun n : ℕ => (n : ℝ) := by |
have A : (∑' j : ℕ, ℙ {ω | X j ω ∈ Set.Ioi (j : ℝ)}) < ∞ := by
convert tsum_prob_mem_Ioi_lt_top hint (hnonneg 0) using 2
ext1 j
exact (hident j).measure_mem_eq measurableSet_Ioi
have B : ∀ᵐ ω, Tendsto (fun n : ℕ => truncation (X n) n ω - X n ω) atTop (𝓝 0) := by
filter_upwards [ae_eventually_not_mem A.ne] with ω hω
apply tendsto_const_nhds.congr' _
filter_upwards [hω, Ioi_mem_atTop 0] with n hn npos
simp only [truncation, indicator, Set.mem_Ioc, id, Function.comp_apply]
split_ifs with h
· exact (sub_self _).symm
· have : -(n : ℝ) < X n ω := by
apply lt_of_lt_of_le _ (hnonneg n ω)
simpa only [Right.neg_neg_iff, Nat.cast_pos] using npos
simp only [this, true_and_iff, not_le] at h
exact (hn h).elim
filter_upwards [B] with ω hω
convert isLittleO_sum_range_of_tendsto_zero hω using 1
ext n
rw [sum_sub_distrib]
|
/-
Copyright (c) 2020 Kexing Ying. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kexing Ying
-/
import Mathlib.Algebra.Group.Conj
import Mathlib.Algebra.Group.Pi.Lemmas
import Mathlib.Algebra.Group.Subsemigroup.Operations
import Mathlib.Algebra.Group.Submonoid.Operations
import Mathlib.Algebra.Order.Group.Abs
import Mathlib.Data.Set.Image
import Mathlib.Order.Atoms
import Mathlib.Tactic.ApplyFun
#align_import group_theory.subgroup.basic from "leanprover-community/mathlib"@"4be589053caf347b899a494da75410deb55fb3ef"
/-!
# Subgroups
This file defines multiplicative and additive subgroups as an extension of submonoids, in a bundled
form (unbundled subgroups are in `Deprecated/Subgroups.lean`).
We prove subgroups of a group form a complete lattice, and results about images and preimages of
subgroups under group homomorphisms. The bundled subgroups use bundled monoid homomorphisms.
There are also theorems about the subgroups generated by an element or a subset of a group,
defined both inductively and as the infimum of the set of subgroups containing a given
element/subset.
Special thanks goes to Amelia Livingston and Yury Kudryashov for their help and inspiration.
## Main definitions
Notation used here:
- `G N` are `Group`s
- `A` is an `AddGroup`
- `H K` are `Subgroup`s of `G` or `AddSubgroup`s of `A`
- `x` is an element of type `G` or type `A`
- `f g : N →* G` are group homomorphisms
- `s k` are sets of elements of type `G`
Definitions in the file:
* `Subgroup G` : the type of subgroups of a group `G`
* `AddSubgroup A` : the type of subgroups of an additive group `A`
* `CompleteLattice (Subgroup G)` : the subgroups of `G` form a complete lattice
* `Subgroup.closure k` : the minimal subgroup that includes the set `k`
* `Subgroup.subtype` : the natural group homomorphism from a subgroup of group `G` to `G`
* `Subgroup.gi` : `closure` forms a Galois insertion with the coercion to set
* `Subgroup.comap H f` : the preimage of a subgroup `H` along the group homomorphism `f` is also a
subgroup
* `Subgroup.map f H` : the image of a subgroup `H` along the group homomorphism `f` is also a
subgroup
* `Subgroup.prod H K` : the product of subgroups `H`, `K` of groups `G`, `N` respectively, `H × K`
is a subgroup of `G × N`
* `MonoidHom.range f` : the range of the group homomorphism `f` is a subgroup
* `MonoidHom.ker f` : the kernel of a group homomorphism `f` is the subgroup of elements `x : G`
such that `f x = 1`
* `MonoidHom.eq_locus f g` : given group homomorphisms `f`, `g`, the elements of `G` such that
`f x = g x` form a subgroup of `G`
## Implementation notes
Subgroup inclusion is denoted `≤` rather than `⊆`, although `∈` is defined as
membership of a subgroup's underlying set.
## Tags
subgroup, subgroups
-/
open Function
open Int
variable {G G' G'' : Type*} [Group G] [Group G'] [Group G'']
variable {A : Type*} [AddGroup A]
section SubgroupClass
/-- `InvMemClass S G` states `S` is a type of subsets `s ⊆ G` closed under inverses. -/
class InvMemClass (S G : Type*) [Inv G] [SetLike S G] : Prop where
/-- `s` is closed under inverses -/
inv_mem : ∀ {s : S} {x}, x ∈ s → x⁻¹ ∈ s
#align inv_mem_class InvMemClass
export InvMemClass (inv_mem)
/-- `NegMemClass S G` states `S` is a type of subsets `s ⊆ G` closed under negation. -/
class NegMemClass (S G : Type*) [Neg G] [SetLike S G] : Prop where
/-- `s` is closed under negation -/
neg_mem : ∀ {s : S} {x}, x ∈ s → -x ∈ s
#align neg_mem_class NegMemClass
export NegMemClass (neg_mem)
/-- `SubgroupClass S G` states `S` is a type of subsets `s ⊆ G` that are subgroups of `G`. -/
class SubgroupClass (S G : Type*) [DivInvMonoid G] [SetLike S G] extends SubmonoidClass S G,
InvMemClass S G : Prop
#align subgroup_class SubgroupClass
/-- `AddSubgroupClass S G` states `S` is a type of subsets `s ⊆ G` that are
additive subgroups of `G`. -/
class AddSubgroupClass (S G : Type*) [SubNegMonoid G] [SetLike S G] extends AddSubmonoidClass S G,
NegMemClass S G : Prop
#align add_subgroup_class AddSubgroupClass
attribute [to_additive] InvMemClass SubgroupClass
attribute [aesop safe apply (rule_sets := [SetLike])] inv_mem neg_mem
@[to_additive (attr := simp)]
theorem inv_mem_iff {S G} [InvolutiveInv G] {_ : SetLike S G} [InvMemClass S G] {H : S}
{x : G} : x⁻¹ ∈ H ↔ x ∈ H :=
⟨fun h => inv_inv x ▸ inv_mem h, inv_mem⟩
#align inv_mem_iff inv_mem_iff
#align neg_mem_iff neg_mem_iff
@[simp] theorem abs_mem_iff {S G} [AddGroup G] [LinearOrder G] {_ : SetLike S G}
[NegMemClass S G] {H : S} {x : G} : |x| ∈ H ↔ x ∈ H := by
cases abs_choice x <;> simp [*]
variable {M S : Type*} [DivInvMonoid M] [SetLike S M] [hSM : SubgroupClass S M] {H K : S}
/-- A subgroup is closed under division. -/
@[to_additive (attr := aesop safe apply (rule_sets := [SetLike]))
"An additive subgroup is closed under subtraction."]
theorem div_mem {x y : M} (hx : x ∈ H) (hy : y ∈ H) : x / y ∈ H := by
rw [div_eq_mul_inv]; exact mul_mem hx (inv_mem hy)
#align div_mem div_mem
#align sub_mem sub_mem
@[to_additive (attr := aesop safe apply (rule_sets := [SetLike]))]
theorem zpow_mem {x : M} (hx : x ∈ K) : ∀ n : ℤ, x ^ n ∈ K
| (n : ℕ) => by
rw [zpow_natCast]
exact pow_mem hx n
| -[n+1] => by
rw [zpow_negSucc]
exact inv_mem (pow_mem hx n.succ)
#align zpow_mem zpow_mem
#align zsmul_mem zsmul_mem
variable [SetLike S G] [SubgroupClass S G]
@[to_additive]
theorem div_mem_comm_iff {a b : G} : a / b ∈ H ↔ b / a ∈ H :=
inv_div b a ▸ inv_mem_iff
#align div_mem_comm_iff div_mem_comm_iff
#align sub_mem_comm_iff sub_mem_comm_iff
@[to_additive /-(attr := simp)-/] -- Porting note: `simp` cannot simplify LHS
theorem exists_inv_mem_iff_exists_mem {P : G → Prop} :
(∃ x : G, x ∈ H ∧ P x⁻¹) ↔ ∃ x ∈ H, P x := by
constructor <;>
· rintro ⟨x, x_in, hx⟩
exact ⟨x⁻¹, inv_mem x_in, by simp [hx]⟩
#align exists_inv_mem_iff_exists_mem exists_inv_mem_iff_exists_mem
#align exists_neg_mem_iff_exists_mem exists_neg_mem_iff_exists_mem
@[to_additive]
theorem mul_mem_cancel_right {x y : G} (h : x ∈ H) : y * x ∈ H ↔ y ∈ H :=
⟨fun hba => by simpa using mul_mem hba (inv_mem h), fun hb => mul_mem hb h⟩
#align mul_mem_cancel_right mul_mem_cancel_right
#align add_mem_cancel_right add_mem_cancel_right
@[to_additive]
theorem mul_mem_cancel_left {x y : G} (h : x ∈ H) : x * y ∈ H ↔ y ∈ H :=
⟨fun hab => by simpa using mul_mem (inv_mem h) hab, mul_mem h⟩
#align mul_mem_cancel_left mul_mem_cancel_left
#align add_mem_cancel_left add_mem_cancel_left
namespace InvMemClass
/-- A subgroup of a group inherits an inverse. -/
@[to_additive "An additive subgroup of an `AddGroup` inherits an inverse."]
instance inv {G : Type u_1} {S : Type u_2} [Inv G] [SetLike S G]
[InvMemClass S G] {H : S} : Inv H :=
⟨fun a => ⟨a⁻¹, inv_mem a.2⟩⟩
#align subgroup_class.has_inv InvMemClass.inv
#align add_subgroup_class.has_neg NegMemClass.neg
@[to_additive (attr := simp, norm_cast)]
theorem coe_inv (x : H) : (x⁻¹).1 = x.1⁻¹ :=
rfl
#align subgroup_class.coe_inv InvMemClass.coe_inv
#align add_subgroup_class.coe_neg NegMemClass.coe_neg
end InvMemClass
namespace SubgroupClass
@[to_additive (attr := deprecated (since := "2024-01-15"))] alias coe_inv := InvMemClass.coe_inv
-- Here we assume H, K, and L are subgroups, but in fact any one of them
-- could be allowed to be a subsemigroup.
-- Counterexample where K and L are submonoids: H = ℤ, K = ℕ, L = -ℕ
-- Counterexample where H and K are submonoids: H = {n | n = 0 ∨ 3 ≤ n}, K = 3ℕ + 4ℕ, L = 5ℤ
@[to_additive]
| Mathlib/Algebra/Group/Subgroup/Basic.lean | 216 | 221 | theorem subset_union {H K L : S} : (H : Set G) ⊆ K ∪ L ↔ H ≤ K ∨ H ≤ L := by |
refine ⟨fun h ↦ ?_, fun h x xH ↦ h.imp (· xH) (· xH)⟩
rw [or_iff_not_imp_left, SetLike.not_le_iff_exists]
exact fun ⟨x, xH, xK⟩ y yH ↦ (h <| mul_mem xH yH).elim
((h yH).resolve_left fun yK ↦ xK <| (mul_mem_cancel_right yK).mp ·)
(mul_mem_cancel_left <| (h xH).resolve_left xK).mp
|
/-
Copyright (c) 2020 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin
-/
import Mathlib.Algebra.MvPolynomial.Expand
import Mathlib.FieldTheory.Finite.Basic
import Mathlib.RingTheory.MvPolynomial.Basic
#align_import field_theory.finite.polynomial from "leanprover-community/mathlib"@"5aa3c1de9f3c642eac76e11071c852766f220fd0"
/-!
## Polynomials over finite fields
-/
namespace MvPolynomial
variable {σ : Type*}
/-- A polynomial over the integers is divisible by `n : ℕ`
if and only if it is zero over `ZMod n`. -/
theorem C_dvd_iff_zmod (n : ℕ) (φ : MvPolynomial σ ℤ) :
C (n : ℤ) ∣ φ ↔ map (Int.castRingHom (ZMod n)) φ = 0 :=
C_dvd_iff_map_hom_eq_zero _ _ (CharP.intCast_eq_zero_iff (ZMod n) n) _
set_option linter.uppercaseLean3 false in
#align mv_polynomial.C_dvd_iff_zmod MvPolynomial.C_dvd_iff_zmod
section frobenius
variable {p : ℕ} [Fact p.Prime]
theorem frobenius_zmod (f : MvPolynomial σ (ZMod p)) : frobenius _ p f = expand p f := by
apply induction_on f
· intro a; rw [expand_C, frobenius_def, ← C_pow, ZMod.pow_card]
· simp only [AlgHom.map_add, RingHom.map_add]; intro _ _ hf hg; rw [hf, hg]
· simp only [expand_X, RingHom.map_mul, AlgHom.map_mul]
intro _ _ hf; rw [hf, frobenius_def]
#align mv_polynomial.frobenius_zmod MvPolynomial.frobenius_zmod
theorem expand_zmod (f : MvPolynomial σ (ZMod p)) : expand p f = f ^ p :=
(frobenius_zmod _).symm
#align mv_polynomial.expand_zmod MvPolynomial.expand_zmod
end frobenius
end MvPolynomial
namespace MvPolynomial
noncomputable section
open scoped Classical
open Set LinearMap Submodule
variable {K : Type*} {σ : Type*}
section Indicator
variable [Fintype K] [Fintype σ]
/-- Over a field, this is the indicator function as an `MvPolynomial`. -/
def indicator [CommRing K] (a : σ → K) : MvPolynomial σ K :=
∏ n, (1 - (X n - C (a n)) ^ (Fintype.card K - 1))
#align mv_polynomial.indicator MvPolynomial.indicator
section CommRing
variable [CommRing K]
theorem eval_indicator_apply_eq_one (a : σ → K) : eval a (indicator a) = 1 := by
nontriviality
have : 0 < Fintype.card K - 1 := tsub_pos_of_lt Fintype.one_lt_card
simp only [indicator, map_prod, map_sub, map_one, map_pow, eval_X, eval_C, sub_self,
zero_pow this.ne', sub_zero, Finset.prod_const_one]
#align mv_polynomial.eval_indicator_apply_eq_one MvPolynomial.eval_indicator_apply_eq_one
theorem degrees_indicator (c : σ → K) :
degrees (indicator c) ≤ ∑ s : σ, (Fintype.card K - 1) • {s} := by
rw [indicator]
refine le_trans (degrees_prod _ _) (Finset.sum_le_sum fun s _ => ?_)
refine le_trans (degrees_sub _ _) ?_
rw [degrees_one, ← bot_eq_zero, bot_sup_eq]
refine le_trans (degrees_pow _ _) (nsmul_le_nsmul_right ?_ _)
refine le_trans (degrees_sub _ _) ?_
rw [degrees_C, ← bot_eq_zero, sup_bot_eq]
exact degrees_X' _
#align mv_polynomial.degrees_indicator MvPolynomial.degrees_indicator
theorem indicator_mem_restrictDegree (c : σ → K) :
indicator c ∈ restrictDegree σ K (Fintype.card K - 1) := by
rw [mem_restrictDegree_iff_sup, indicator]
intro n
refine le_trans (Multiset.count_le_of_le _ <| degrees_indicator _) (le_of_eq ?_)
simp_rw [← Multiset.coe_countAddMonoidHom, map_sum,
AddMonoidHom.map_nsmul, Multiset.coe_countAddMonoidHom, nsmul_eq_mul, Nat.cast_id]
trans
· refine Finset.sum_eq_single n ?_ ?_
· intro b _ ne
simp [Multiset.count_singleton, ne, if_neg (Ne.symm _)]
· intro h; exact (h <| Finset.mem_univ _).elim
· rw [Multiset.count_singleton_self, mul_one]
#align mv_polynomial.indicator_mem_restrict_degree MvPolynomial.indicator_mem_restrictDegree
end CommRing
variable [Field K]
theorem eval_indicator_apply_eq_zero (a b : σ → K) (h : a ≠ b) : eval a (indicator b) = 0 := by
obtain ⟨i, hi⟩ : ∃ i, a i ≠ b i := by rwa [Ne, Function.funext_iff, not_forall] at h
simp only [indicator, map_prod, map_sub, map_one, map_pow, eval_X, eval_C, sub_self,
Finset.prod_eq_zero_iff]
refine ⟨i, Finset.mem_univ _, ?_⟩
rw [FiniteField.pow_card_sub_one_eq_one, sub_self]
rwa [Ne, sub_eq_zero]
#align mv_polynomial.eval_indicator_apply_eq_zero MvPolynomial.eval_indicator_apply_eq_zero
end Indicator
section
variable (K σ)
/-- `MvPolynomial.eval` as a `K`-linear map. -/
@[simps]
def evalₗ [CommSemiring K] : MvPolynomial σ K →ₗ[K] (σ → K) → K where
toFun p e := eval e p
map_add' p q := by ext x; simp
map_smul' a p := by ext e; simp
#align mv_polynomial.evalₗ MvPolynomial.evalₗ
variable [Field K] [Fintype K] [Finite σ]
-- Porting note: `K` and `σ` were implicit in mathlib3, even if they were declared via
-- `variable (K σ)` (I don't understand why). They are now explicit, as expected.
| Mathlib/FieldTheory/Finite/Polynomial.lean | 137 | 150 | theorem map_restrict_dom_evalₗ : (restrictDegree σ K (Fintype.card K - 1)).map (evalₗ K σ) = ⊤ := by |
cases nonempty_fintype σ
refine top_unique (SetLike.le_def.2 fun e _ => mem_map.2 ?_)
refine ⟨∑ n : σ → K, e n • indicator n, ?_, ?_⟩
· exact sum_mem fun c _ => smul_mem _ _ (indicator_mem_restrictDegree _)
· ext n
simp only [_root_.map_sum, @Finset.sum_apply (σ → K) (fun _ => K) _ _ _ _ _, Pi.smul_apply,
map_smul]
simp only [evalₗ_apply]
trans
· refine Finset.sum_eq_single n (fun b _ h => ?_) ?_
· rw [eval_indicator_apply_eq_zero _ _ h.symm, smul_zero]
· exact fun h => (h <| Finset.mem_univ n).elim
· rw [eval_indicator_apply_eq_one, smul_eq_mul, mul_one]
|
/-
Copyright (c) 2022 Andrew Yang. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Andrew Yang
-/
import Mathlib.Topology.Sets.Closeds
#align_import topology.noetherian_space from "leanprover-community/mathlib"@"dc6c365e751e34d100e80fe6e314c3c3e0fd2988"
/-!
# Noetherian space
A Noetherian space is a topological space that satisfies any of the following equivalent conditions:
- `WellFounded ((· > ·) : TopologicalSpace.Opens α → TopologicalSpace.Opens α → Prop)`
- `WellFounded ((· < ·) : TopologicalSpace.Closeds α → TopologicalSpace.Closeds α → Prop)`
- `∀ s : Set α, IsCompact s`
- `∀ s : TopologicalSpace.Opens α, IsCompact s`
The first is chosen as the definition, and the equivalence is shown in
`TopologicalSpace.noetherianSpace_TFAE`.
Many examples of noetherian spaces come from algebraic topology. For example, the underlying space
of a noetherian scheme (e.g., the spectrum of a noetherian ring) is noetherian.
## Main Results
- `TopologicalSpace.NoetherianSpace.set`: Every subspace of a noetherian space is noetherian.
- `TopologicalSpace.NoetherianSpace.isCompact`: Every set in a noetherian space is a compact set.
- `TopologicalSpace.noetherianSpace_TFAE`: Describes the equivalent definitions of noetherian
spaces.
- `TopologicalSpace.NoetherianSpace.range`: The image of a noetherian space under a continuous map
is noetherian.
- `TopologicalSpace.NoetherianSpace.iUnion`: The finite union of noetherian spaces is noetherian.
- `TopologicalSpace.NoetherianSpace.discrete`: A noetherian and Hausdorff space is discrete.
- `TopologicalSpace.NoetherianSpace.exists_finset_irreducible`: Every closed subset of a noetherian
space is a finite union of irreducible closed subsets.
- `TopologicalSpace.NoetherianSpace.finite_irreducibleComponents`: The number of irreducible
components of a noetherian space is finite.
-/
variable (α β : Type*) [TopologicalSpace α] [TopologicalSpace β]
namespace TopologicalSpace
/-- Type class for noetherian spaces. It is defined to be spaces whose open sets satisfies ACC. -/
@[mk_iff]
class NoetherianSpace : Prop where
wellFounded_opens : WellFounded ((· > ·) : Opens α → Opens α → Prop)
#align topological_space.noetherian_space TopologicalSpace.NoetherianSpace
theorem noetherianSpace_iff_opens : NoetherianSpace α ↔ ∀ s : Opens α, IsCompact (s : Set α) := by
rw [noetherianSpace_iff, CompleteLattice.wellFounded_iff_isSupFiniteCompact,
CompleteLattice.isSupFiniteCompact_iff_all_elements_compact]
exact forall_congr' Opens.isCompactElement_iff
#align topological_space.noetherian_space_iff_opens TopologicalSpace.noetherianSpace_iff_opens
instance (priority := 100) NoetherianSpace.compactSpace [h : NoetherianSpace α] : CompactSpace α :=
⟨(noetherianSpace_iff_opens α).mp h ⊤⟩
#align topological_space.noetherian_space.compact_space TopologicalSpace.NoetherianSpace.compactSpace
variable {α β}
/-- In a Noetherian space, all sets are compact. -/
protected theorem NoetherianSpace.isCompact [NoetherianSpace α] (s : Set α) : IsCompact s := by
refine isCompact_iff_finite_subcover.2 fun U hUo hs => ?_
rcases ((noetherianSpace_iff_opens α).mp ‹_› ⟨⋃ i, U i, isOpen_iUnion hUo⟩).elim_finite_subcover U
hUo Set.Subset.rfl with ⟨t, ht⟩
exact ⟨t, hs.trans ht⟩
#align topological_space.noetherian_space.is_compact TopologicalSpace.NoetherianSpace.isCompact
-- Porting note: fixed NS
protected theorem _root_.Inducing.noetherianSpace [NoetherianSpace α] {i : β → α}
(hi : Inducing i) : NoetherianSpace β :=
(noetherianSpace_iff_opens _).2 fun _ => hi.isCompact_iff.2 (NoetherianSpace.isCompact _)
#align topological_space.inducing.noetherian_space Inducing.noetherianSpace
/-- [Stacks: Lemma 0052 (1)](https://stacks.math.columbia.edu/tag/0052)-/
instance NoetherianSpace.set [NoetherianSpace α] (s : Set α) : NoetherianSpace s :=
inducing_subtype_val.noetherianSpace
#align topological_space.noetherian_space.set TopologicalSpace.NoetherianSpace.set
variable (α)
open List in
theorem noetherianSpace_TFAE :
TFAE [NoetherianSpace α,
WellFounded fun s t : Closeds α => s < t,
∀ s : Set α, IsCompact s,
∀ s : Opens α, IsCompact (s : Set α)] := by
tfae_have 1 ↔ 2
· refine (noetherianSpace_iff α).trans (Opens.compl_bijective.2.wellFounded_iff ?_)
exact (@OrderIso.compl (Set α)).lt_iff_lt.symm
tfae_have 1 ↔ 4
· exact noetherianSpace_iff_opens α
tfae_have 1 → 3
· exact @NoetherianSpace.isCompact α _
tfae_have 3 → 4
· exact fun h s => h s
tfae_finish
#align topological_space.noetherian_space_tfae TopologicalSpace.noetherianSpace_TFAE
variable {α}
theorem noetherianSpace_iff_isCompact : NoetherianSpace α ↔ ∀ s : Set α, IsCompact s :=
(noetherianSpace_TFAE α).out 0 2
theorem NoetherianSpace.wellFounded_closeds [NoetherianSpace α] :
WellFounded fun s t : Closeds α => s < t :=
Iff.mp ((noetherianSpace_TFAE α).out 0 1) ‹_›
instance {α} : NoetherianSpace (CofiniteTopology α) := by
simp only [noetherianSpace_iff_isCompact, isCompact_iff_ultrafilter_le_nhds,
CofiniteTopology.nhds_eq, Ultrafilter.le_sup_iff, Filter.le_principal_iff]
intro s f hs
rcases f.le_cofinite_or_eq_pure with (hf | ⟨a, rfl⟩)
· rcases Filter.nonempty_of_mem hs with ⟨a, ha⟩
exact ⟨a, ha, Or.inr hf⟩
· exact ⟨a, hs, Or.inl le_rfl⟩
theorem noetherianSpace_of_surjective [NoetherianSpace α] (f : α → β) (hf : Continuous f)
(hf' : Function.Surjective f) : NoetherianSpace β :=
noetherianSpace_iff_isCompact.2 <| (Set.image_surjective.mpr hf').forall.2 fun s =>
(NoetherianSpace.isCompact s).image hf
#align topological_space.noetherian_space_of_surjective TopologicalSpace.noetherianSpace_of_surjective
theorem noetherianSpace_iff_of_homeomorph (f : α ≃ₜ β) : NoetherianSpace α ↔ NoetherianSpace β :=
⟨fun _ => noetherianSpace_of_surjective f f.continuous f.surjective,
fun _ => noetherianSpace_of_surjective f.symm f.symm.continuous f.symm.surjective⟩
#align topological_space.noetherian_space_iff_of_homeomorph TopologicalSpace.noetherianSpace_iff_of_homeomorph
theorem NoetherianSpace.range [NoetherianSpace α] (f : α → β) (hf : Continuous f) :
NoetherianSpace (Set.range f) :=
noetherianSpace_of_surjective (Set.rangeFactorization f) (hf.subtype_mk _)
Set.surjective_onto_range
#align topological_space.noetherian_space.range TopologicalSpace.NoetherianSpace.range
| Mathlib/Topology/NoetherianSpace.lean | 139 | 142 | theorem noetherianSpace_set_iff (s : Set α) :
NoetherianSpace s ↔ ∀ t, t ⊆ s → IsCompact t := by |
simp only [noetherianSpace_iff_isCompact, embedding_subtype_val.isCompact_iff,
Subtype.forall_set_subtype]
|
/-
Copyright (c) 2022 Yaël Dillies. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies
-/
import Mathlib.Order.PropInstances
#align_import order.heyting.basic from "leanprover-community/mathlib"@"9ac7c0c8c4d7a535ec3e5b34b8859aab9233b2f4"
/-!
# Heyting algebras
This file defines Heyting, co-Heyting and bi-Heyting algebras.
A Heyting algebra is a bounded distributive lattice with an implication operation `⇨` such that
`a ≤ b ⇨ c ↔ a ⊓ b ≤ c`. It also comes with a pseudo-complement `ᶜ`, such that `aᶜ = a ⇨ ⊥`.
Co-Heyting algebras are dual to Heyting algebras. They have a difference `\` and a negation `¬`
such that `a \ b ≤ c ↔ a ≤ b ⊔ c` and `¬a = ⊤ \ a`.
Bi-Heyting algebras are Heyting algebras that are also co-Heyting algebras.
From a logic standpoint, Heyting algebras precisely model intuitionistic logic, whereas boolean
algebras model classical logic.
Heyting algebras are the order theoretic equivalent of cartesian-closed categories.
## Main declarations
* `GeneralizedHeytingAlgebra`: Heyting algebra without a top element (nor negation).
* `GeneralizedCoheytingAlgebra`: Co-Heyting algebra without a bottom element (nor complement).
* `HeytingAlgebra`: Heyting algebra.
* `CoheytingAlgebra`: Co-Heyting algebra.
* `BiheytingAlgebra`: bi-Heyting algebra.
## References
* [Francis Borceux, *Handbook of Categorical Algebra III*][borceux-vol3]
## Tags
Heyting, Brouwer, algebra, implication, negation, intuitionistic
-/
open Function OrderDual
universe u
variable {ι α β : Type*}
/-! ### Notation -/
section
variable (α β)
instance Prod.instHImp [HImp α] [HImp β] : HImp (α × β) :=
⟨fun a b => (a.1 ⇨ b.1, a.2 ⇨ b.2)⟩
instance Prod.instHNot [HNot α] [HNot β] : HNot (α × β) :=
⟨fun a => (¬a.1, ¬a.2)⟩
instance Prod.instSDiff [SDiff α] [SDiff β] : SDiff (α × β) :=
⟨fun a b => (a.1 \ b.1, a.2 \ b.2)⟩
instance Prod.instHasCompl [HasCompl α] [HasCompl β] : HasCompl (α × β) :=
⟨fun a => (a.1ᶜ, a.2ᶜ)⟩
end
@[simp]
theorem fst_himp [HImp α] [HImp β] (a b : α × β) : (a ⇨ b).1 = a.1 ⇨ b.1 :=
rfl
#align fst_himp fst_himp
@[simp]
theorem snd_himp [HImp α] [HImp β] (a b : α × β) : (a ⇨ b).2 = a.2 ⇨ b.2 :=
rfl
#align snd_himp snd_himp
@[simp]
theorem fst_hnot [HNot α] [HNot β] (a : α × β) : (¬a).1 = ¬a.1 :=
rfl
#align fst_hnot fst_hnot
@[simp]
theorem snd_hnot [HNot α] [HNot β] (a : α × β) : (¬a).2 = ¬a.2 :=
rfl
#align snd_hnot snd_hnot
@[simp]
theorem fst_sdiff [SDiff α] [SDiff β] (a b : α × β) : (a \ b).1 = a.1 \ b.1 :=
rfl
#align fst_sdiff fst_sdiff
@[simp]
theorem snd_sdiff [SDiff α] [SDiff β] (a b : α × β) : (a \ b).2 = a.2 \ b.2 :=
rfl
#align snd_sdiff snd_sdiff
@[simp]
theorem fst_compl [HasCompl α] [HasCompl β] (a : α × β) : aᶜ.1 = a.1ᶜ :=
rfl
#align fst_compl fst_compl
@[simp]
theorem snd_compl [HasCompl α] [HasCompl β] (a : α × β) : aᶜ.2 = a.2ᶜ :=
rfl
#align snd_compl snd_compl
namespace Pi
variable {π : ι → Type*}
instance [∀ i, HImp (π i)] : HImp (∀ i, π i) :=
⟨fun a b i => a i ⇨ b i⟩
instance [∀ i, HNot (π i)] : HNot (∀ i, π i) :=
⟨fun a i => ¬a i⟩
theorem himp_def [∀ i, HImp (π i)] (a b : ∀ i, π i) : a ⇨ b = fun i => a i ⇨ b i :=
rfl
#align pi.himp_def Pi.himp_def
theorem hnot_def [∀ i, HNot (π i)] (a : ∀ i, π i) : ¬a = fun i => ¬a i :=
rfl
#align pi.hnot_def Pi.hnot_def
@[simp]
theorem himp_apply [∀ i, HImp (π i)] (a b : ∀ i, π i) (i : ι) : (a ⇨ b) i = a i ⇨ b i :=
rfl
#align pi.himp_apply Pi.himp_apply
@[simp]
theorem hnot_apply [∀ i, HNot (π i)] (a : ∀ i, π i) (i : ι) : (¬a) i = ¬a i :=
rfl
#align pi.hnot_apply Pi.hnot_apply
end Pi
/-- A generalized Heyting algebra is a lattice with an additional binary operation `⇨` called
Heyting implication such that `a ⇨` is right adjoint to `a ⊓`.
This generalizes `HeytingAlgebra` by not requiring a bottom element. -/
class GeneralizedHeytingAlgebra (α : Type*) extends Lattice α, OrderTop α, HImp α where
/-- `a ⇨` is right adjoint to `a ⊓` -/
le_himp_iff (a b c : α) : a ≤ b ⇨ c ↔ a ⊓ b ≤ c
#align generalized_heyting_algebra GeneralizedHeytingAlgebra
#align generalized_heyting_algebra.to_order_top GeneralizedHeytingAlgebra.toOrderTop
/-- A generalized co-Heyting algebra is a lattice with an additional binary
difference operation `\` such that `\ a` is right adjoint to `⊔ a`.
This generalizes `CoheytingAlgebra` by not requiring a top element. -/
class GeneralizedCoheytingAlgebra (α : Type*) extends Lattice α, OrderBot α, SDiff α where
/-- `\ a` is right adjoint to `⊔ a` -/
sdiff_le_iff (a b c : α) : a \ b ≤ c ↔ a ≤ b ⊔ c
#align generalized_coheyting_algebra GeneralizedCoheytingAlgebra
#align generalized_coheyting_algebra.to_order_bot GeneralizedCoheytingAlgebra.toOrderBot
/-- A Heyting algebra is a bounded lattice with an additional binary operation `⇨` called Heyting
implication such that `a ⇨` is right adjoint to `a ⊓`. -/
class HeytingAlgebra (α : Type*) extends GeneralizedHeytingAlgebra α, OrderBot α, HasCompl α where
/-- `a ⇨` is right adjoint to `a ⊓` -/
himp_bot (a : α) : a ⇨ ⊥ = aᶜ
#align heyting_algebra HeytingAlgebra
/-- A co-Heyting algebra is a bounded lattice with an additional binary difference operation `\`
such that `\ a` is right adjoint to `⊔ a`. -/
class CoheytingAlgebra (α : Type*) extends GeneralizedCoheytingAlgebra α, OrderTop α, HNot α where
/-- `⊤ \ a` is `¬a` -/
top_sdiff (a : α) : ⊤ \ a = ¬a
#align coheyting_algebra CoheytingAlgebra
/-- A bi-Heyting algebra is a Heyting algebra that is also a co-Heyting algebra. -/
class BiheytingAlgebra (α : Type*) extends HeytingAlgebra α, SDiff α, HNot α where
/-- `\ a` is right adjoint to `⊔ a` -/
sdiff_le_iff (a b c : α) : a \ b ≤ c ↔ a ≤ b ⊔ c
/-- `⊤ \ a` is `¬a` -/
top_sdiff (a : α) : ⊤ \ a = ¬a
#align biheyting_algebra BiheytingAlgebra
-- See note [lower instance priority]
attribute [instance 100] GeneralizedHeytingAlgebra.toOrderTop
attribute [instance 100] GeneralizedCoheytingAlgebra.toOrderBot
-- See note [lower instance priority]
instance (priority := 100) HeytingAlgebra.toBoundedOrder [HeytingAlgebra α] : BoundedOrder α :=
{ bot_le := ‹HeytingAlgebra α›.bot_le }
--#align heyting_algebra.to_bounded_order HeytingAlgebra.toBoundedOrder
-- See note [lower instance priority]
instance (priority := 100) CoheytingAlgebra.toBoundedOrder [CoheytingAlgebra α] : BoundedOrder α :=
{ ‹CoheytingAlgebra α› with }
#align coheyting_algebra.to_bounded_order CoheytingAlgebra.toBoundedOrder
-- See note [lower instance priority]
instance (priority := 100) BiheytingAlgebra.toCoheytingAlgebra [BiheytingAlgebra α] :
CoheytingAlgebra α :=
{ ‹BiheytingAlgebra α› with }
#align biheyting_algebra.to_coheyting_algebra BiheytingAlgebra.toCoheytingAlgebra
-- See note [reducible non-instances]
/-- Construct a Heyting algebra from the lattice structure and Heyting implication alone. -/
abbrev HeytingAlgebra.ofHImp [DistribLattice α] [BoundedOrder α] (himp : α → α → α)
(le_himp_iff : ∀ a b c, a ≤ himp b c ↔ a ⊓ b ≤ c) : HeytingAlgebra α :=
{ ‹DistribLattice α›, ‹BoundedOrder α› with
himp,
compl := fun a => himp a ⊥,
le_himp_iff,
himp_bot := fun a => rfl }
#align heyting_algebra.of_himp HeytingAlgebra.ofHImp
-- See note [reducible non-instances]
/-- Construct a Heyting algebra from the lattice structure and complement operator alone. -/
abbrev HeytingAlgebra.ofCompl [DistribLattice α] [BoundedOrder α] (compl : α → α)
(le_himp_iff : ∀ a b c, a ≤ compl b ⊔ c ↔ a ⊓ b ≤ c) : HeytingAlgebra α where
himp := (compl · ⊔ ·)
compl := compl
le_himp_iff := le_himp_iff
himp_bot _ := sup_bot_eq _
#align heyting_algebra.of_compl HeytingAlgebra.ofCompl
-- See note [reducible non-instances]
/-- Construct a co-Heyting algebra from the lattice structure and the difference alone. -/
abbrev CoheytingAlgebra.ofSDiff [DistribLattice α] [BoundedOrder α] (sdiff : α → α → α)
(sdiff_le_iff : ∀ a b c, sdiff a b ≤ c ↔ a ≤ b ⊔ c) : CoheytingAlgebra α :=
{ ‹DistribLattice α›, ‹BoundedOrder α› with
sdiff,
hnot := fun a => sdiff ⊤ a,
sdiff_le_iff,
top_sdiff := fun a => rfl }
#align coheyting_algebra.of_sdiff CoheytingAlgebra.ofSDiff
-- See note [reducible non-instances]
/-- Construct a co-Heyting algebra from the difference and Heyting negation alone. -/
abbrev CoheytingAlgebra.ofHNot [DistribLattice α] [BoundedOrder α] (hnot : α → α)
(sdiff_le_iff : ∀ a b c, a ⊓ hnot b ≤ c ↔ a ≤ b ⊔ c) : CoheytingAlgebra α where
sdiff a b := a ⊓ hnot b
hnot := hnot
sdiff_le_iff := sdiff_le_iff
top_sdiff _ := top_inf_eq _
#align coheyting_algebra.of_hnot CoheytingAlgebra.ofHNot
/-! In this section, we'll give interpretations of these results in the Heyting algebra model of
intuitionistic logic,- where `≤` can be interpreted as "validates", `⇨` as "implies", `⊓` as "and",
`⊔` as "or", `⊥` as "false" and `⊤` as "true". Note that we confuse `→` and `⊢` because those are
the same in this logic.
See also `Prop.heytingAlgebra`. -/
section GeneralizedHeytingAlgebra
variable [GeneralizedHeytingAlgebra α] {a b c d : α}
/-- `p → q → r ↔ p ∧ q → r` -/
@[simp]
theorem le_himp_iff : a ≤ b ⇨ c ↔ a ⊓ b ≤ c :=
GeneralizedHeytingAlgebra.le_himp_iff _ _ _
#align le_himp_iff le_himp_iff
/-- `p → q → r ↔ q ∧ p → r` -/
theorem le_himp_iff' : a ≤ b ⇨ c ↔ b ⊓ a ≤ c := by rw [le_himp_iff, inf_comm]
#align le_himp_iff' le_himp_iff'
/-- `p → q → r ↔ q → p → r` -/
theorem le_himp_comm : a ≤ b ⇨ c ↔ b ≤ a ⇨ c := by rw [le_himp_iff, le_himp_iff']
#align le_himp_comm le_himp_comm
/-- `p → q → p` -/
theorem le_himp : a ≤ b ⇨ a :=
le_himp_iff.2 inf_le_left
#align le_himp le_himp
/-- `p → p → q ↔ p → q` -/
theorem le_himp_iff_left : a ≤ a ⇨ b ↔ a ≤ b := by rw [le_himp_iff, inf_idem]
#align le_himp_iff_left le_himp_iff_left
/-- `p → p` -/
@[simp]
theorem himp_self : a ⇨ a = ⊤ :=
top_le_iff.1 <| le_himp_iff.2 inf_le_right
#align himp_self himp_self
/-- `(p → q) ∧ p → q` -/
theorem himp_inf_le : (a ⇨ b) ⊓ a ≤ b :=
le_himp_iff.1 le_rfl
#align himp_inf_le himp_inf_le
/-- `p ∧ (p → q) → q` -/
theorem inf_himp_le : a ⊓ (a ⇨ b) ≤ b := by rw [inf_comm, ← le_himp_iff]
#align inf_himp_le inf_himp_le
/-- `p ∧ (p → q) ↔ p ∧ q` -/
@[simp]
theorem inf_himp (a b : α) : a ⊓ (a ⇨ b) = a ⊓ b :=
le_antisymm (le_inf inf_le_left <| by rw [inf_comm, ← le_himp_iff]) <| inf_le_inf_left _ le_himp
#align inf_himp inf_himp
/-- `(p → q) ∧ p ↔ q ∧ p` -/
@[simp]
theorem himp_inf_self (a b : α) : (a ⇨ b) ⊓ a = b ⊓ a := by rw [inf_comm, inf_himp, inf_comm]
#align himp_inf_self himp_inf_self
/-- The **deduction theorem** in the Heyting algebra model of intuitionistic logic:
an implication holds iff the conclusion follows from the hypothesis. -/
@[simp]
theorem himp_eq_top_iff : a ⇨ b = ⊤ ↔ a ≤ b := by rw [← top_le_iff, le_himp_iff, top_inf_eq]
#align himp_eq_top_iff himp_eq_top_iff
/-- `p → true`, `true → p ↔ p` -/
@[simp]
theorem himp_top : a ⇨ ⊤ = ⊤ :=
himp_eq_top_iff.2 le_top
#align himp_top himp_top
@[simp]
theorem top_himp : ⊤ ⇨ a = a :=
eq_of_forall_le_iff fun b => by rw [le_himp_iff, inf_top_eq]
#align top_himp top_himp
/-- `p → q → r ↔ p ∧ q → r` -/
theorem himp_himp (a b c : α) : a ⇨ b ⇨ c = a ⊓ b ⇨ c :=
eq_of_forall_le_iff fun d => by simp_rw [le_himp_iff, inf_assoc]
#align himp_himp himp_himp
/-- `(q → r) → (p → q) → q → r` -/
theorem himp_le_himp_himp_himp : b ⇨ c ≤ (a ⇨ b) ⇨ a ⇨ c := by
rw [le_himp_iff, le_himp_iff, inf_assoc, himp_inf_self, ← inf_assoc, himp_inf_self, inf_assoc]
exact inf_le_left
#align himp_le_himp_himp_himp himp_le_himp_himp_himp
@[simp]
| Mathlib/Order/Heyting/Basic.lean | 332 | 333 | theorem himp_inf_himp_inf_le : (b ⇨ c) ⊓ (a ⇨ b) ⊓ a ≤ c := by |
simpa using @himp_le_himp_himp_himp
|
/-
Copyright (c) 2017 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
-/
import Mathlib.Algebra.Order.Ring.Defs
import Mathlib.Algebra.Group.Int
import Mathlib.Data.Nat.Dist
import Mathlib.Data.Ordmap.Ordnode
import Mathlib.Tactic.Abel
import Mathlib.Tactic.Linarith
#align_import data.ordmap.ordset from "leanprover-community/mathlib"@"47b51515e69f59bca5cf34ef456e6000fe205a69"
/-!
# Verification of the `Ordnode α` datatype
This file proves the correctness of the operations in `Data.Ordmap.Ordnode`.
The public facing version is the type `Ordset α`, which is a wrapper around
`Ordnode α` which includes the correctness invariant of the type, and 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
* `Ordset α`: A well formed set of values of type `α`
## Implementation notes
The majority of this file is actually in the `Ordnode` namespace, because we first
have to prove the correctness of all the operations (and defining what correctness
means here is actually somewhat subtle). So all the actual `Ordset` operations are
at the very end, once we have all the theorems.
An `Ordnode α` is an inductive type which describes a tree which stores the `size` at
internal nodes. The correctness invariant of an `Ordnode α` is:
* `Ordnode.Sized t`: All internal `size` fields must match the actual measured
size of the tree. (This is not hard to satisfy.)
* `Ordnode.Balanced t`: Unless the tree has the form `()` or `((a) b)` or `(a (b))`
(that is, nil or a single singleton subtree), the two subtrees must satisfy
`size l ≤ δ * size r` and `size r ≤ δ * size l`, where `δ := 3` is a global
parameter of the data structure (and this property must hold recursively at subtrees).
This is why we say this is a "size balanced tree" data structure.
* `Ordnode.Bounded lo hi t`: The members of the tree must be in strictly increasing order,
meaning that if `a` is in the left subtree and `b` is the root, then `a ≤ b` and
`¬ (b ≤ a)`. We enforce this using `Ordnode.Bounded` which includes also a global
upper and lower bound.
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.
**Note:** This file is incomplete, in the sense that the intent is to have verified
versions and lemmas about all the definitions in `Ordnode.lean`, but at the moment only
a few operations are verified (the hard part should be out of the way, but still).
Contributors are encouraged to pick this up and finish the job, if it appeals to you.
## Tags
ordered map, ordered set, data structure, verified programming
-/
variable {α : Type*}
namespace Ordnode
/-! ### delta and ratio -/
theorem not_le_delta {s} (H : 1 ≤ s) : ¬s ≤ delta * 0 :=
not_le_of_gt H
#align ordnode.not_le_delta Ordnode.not_le_delta
theorem delta_lt_false {a b : ℕ} (h₁ : delta * a < b) (h₂ : delta * b < a) : False :=
not_le_of_lt (lt_trans ((mul_lt_mul_left (by decide)).2 h₁) h₂) <| by
simpa [mul_assoc] using Nat.mul_le_mul_right a (by decide : 1 ≤ delta * delta)
#align ordnode.delta_lt_false Ordnode.delta_lt_false
/-! ### `singleton` -/
/-! ### `size` and `empty` -/
/-- O(n). Computes the actual number of elements in the set, ignoring the cached `size` field. -/
def realSize : Ordnode α → ℕ
| nil => 0
| node _ l _ r => realSize l + realSize r + 1
#align ordnode.real_size Ordnode.realSize
/-! ### `Sized` -/
/-- The `Sized` property asserts that all the `size` fields in nodes match the actual size of the
respective subtrees. -/
def Sized : Ordnode α → Prop
| nil => True
| node s l _ r => s = size l + size r + 1 ∧ Sized l ∧ Sized r
#align ordnode.sized Ordnode.Sized
theorem Sized.node' {l x r} (hl : @Sized α l) (hr : Sized r) : Sized (node' l x r) :=
⟨rfl, hl, hr⟩
#align ordnode.sized.node' Ordnode.Sized.node'
theorem Sized.eq_node' {s l x r} (h : @Sized α (node s l x r)) : node s l x r = .node' l x r := by
rw [h.1]
#align ordnode.sized.eq_node' Ordnode.Sized.eq_node'
theorem Sized.size_eq {s l x r} (H : Sized (@node α s l x r)) :
size (@node α s l x r) = size l + size r + 1 :=
H.1
#align ordnode.sized.size_eq Ordnode.Sized.size_eq
@[elab_as_elim]
theorem Sized.induction {t} (hl : @Sized α t) {C : Ordnode α → Prop} (H0 : C nil)
(H1 : ∀ l x r, C l → C r → C (.node' l x r)) : C t := by
induction t with
| nil => exact H0
| node _ _ _ _ t_ih_l t_ih_r =>
rw [hl.eq_node']
exact H1 _ _ _ (t_ih_l hl.2.1) (t_ih_r hl.2.2)
#align ordnode.sized.induction Ordnode.Sized.induction
theorem size_eq_realSize : ∀ {t : Ordnode α}, Sized t → size t = realSize t
| nil, _ => rfl
| node s l x r, ⟨h₁, h₂, h₃⟩ => by
rw [size, h₁, size_eq_realSize h₂, size_eq_realSize h₃]; rfl
#align ordnode.size_eq_real_size Ordnode.size_eq_realSize
@[simp]
theorem Sized.size_eq_zero {t : Ordnode α} (ht : Sized t) : size t = 0 ↔ t = nil := by
cases t <;> [simp;simp [ht.1]]
#align ordnode.sized.size_eq_zero Ordnode.Sized.size_eq_zero
theorem Sized.pos {s l x r} (h : Sized (@node α s l x r)) : 0 < s := by
rw [h.1]; apply Nat.le_add_left
#align ordnode.sized.pos Ordnode.Sized.pos
/-! `dual` -/
theorem dual_dual : ∀ t : Ordnode α, dual (dual t) = t
| nil => rfl
| node s l x r => by rw [dual, dual, dual_dual l, dual_dual r]
#align ordnode.dual_dual Ordnode.dual_dual
@[simp]
theorem size_dual (t : Ordnode α) : size (dual t) = size t := by cases t <;> rfl
#align ordnode.size_dual Ordnode.size_dual
/-! `Balanced` -/
/-- The `BalancedSz l r` asserts that a hypothetical tree with children of sizes `l` and `r` is
balanced: either `l ≤ δ * r` and `r ≤ δ * r`, or the tree is trivial with a singleton on one side
and nothing on the other. -/
def BalancedSz (l r : ℕ) : Prop :=
l + r ≤ 1 ∨ l ≤ delta * r ∧ r ≤ delta * l
#align ordnode.balanced_sz Ordnode.BalancedSz
instance BalancedSz.dec : DecidableRel BalancedSz := fun _ _ => Or.decidable
#align ordnode.balanced_sz.dec Ordnode.BalancedSz.dec
/-- The `Balanced t` asserts that the tree `t` satisfies the balance invariants
(at every level). -/
def Balanced : Ordnode α → Prop
| nil => True
| node _ l _ r => BalancedSz (size l) (size r) ∧ Balanced l ∧ Balanced r
#align ordnode.balanced Ordnode.Balanced
instance Balanced.dec : DecidablePred (@Balanced α)
| nil => by
unfold Balanced
infer_instance
| node _ l _ r => by
unfold Balanced
haveI := Balanced.dec l
haveI := Balanced.dec r
infer_instance
#align ordnode.balanced.dec Ordnode.Balanced.dec
@[symm]
theorem BalancedSz.symm {l r : ℕ} : BalancedSz l r → BalancedSz r l :=
Or.imp (by rw [add_comm]; exact id) And.symm
#align ordnode.balanced_sz.symm Ordnode.BalancedSz.symm
theorem balancedSz_zero {l : ℕ} : BalancedSz l 0 ↔ l ≤ 1 := by
simp (config := { contextual := true }) [BalancedSz]
#align ordnode.balanced_sz_zero Ordnode.balancedSz_zero
theorem balancedSz_up {l r₁ r₂ : ℕ} (h₁ : r₁ ≤ r₂) (h₂ : l + r₂ ≤ 1 ∨ r₂ ≤ delta * l)
(H : BalancedSz l r₁) : BalancedSz l r₂ := by
refine or_iff_not_imp_left.2 fun h => ?_
refine ⟨?_, h₂.resolve_left h⟩
cases H with
| inl H =>
cases r₂
· cases h (le_trans (Nat.add_le_add_left (Nat.zero_le _) _) H)
· exact le_trans (le_trans (Nat.le_add_right _ _) H) (Nat.le_add_left 1 _)
| inr H =>
exact le_trans H.1 (Nat.mul_le_mul_left _ h₁)
#align ordnode.balanced_sz_up Ordnode.balancedSz_up
theorem balancedSz_down {l r₁ r₂ : ℕ} (h₁ : r₁ ≤ r₂) (h₂ : l + r₂ ≤ 1 ∨ l ≤ delta * r₁)
(H : BalancedSz l r₂) : BalancedSz l r₁ :=
have : l + r₂ ≤ 1 → BalancedSz l r₁ := fun H => Or.inl (le_trans (Nat.add_le_add_left h₁ _) H)
Or.casesOn H this fun H => Or.casesOn h₂ this fun h₂ => Or.inr ⟨h₂, le_trans h₁ H.2⟩
#align ordnode.balanced_sz_down Ordnode.balancedSz_down
theorem Balanced.dual : ∀ {t : Ordnode α}, Balanced t → Balanced (dual t)
| nil, _ => ⟨⟩
| node _ l _ r, ⟨b, bl, br⟩ => ⟨by rw [size_dual, size_dual]; exact b.symm, br.dual, bl.dual⟩
#align ordnode.balanced.dual Ordnode.Balanced.dual
/-! ### `rotate` and `balance` -/
/-- Build a tree from three nodes, left associated (ignores the invariants). -/
def node3L (l : Ordnode α) (x : α) (m : Ordnode α) (y : α) (r : Ordnode α) : Ordnode α :=
node' (node' l x m) y r
#align ordnode.node3_l Ordnode.node3L
/-- Build a tree from three nodes, right associated (ignores the invariants). -/
def node3R (l : Ordnode α) (x : α) (m : Ordnode α) (y : α) (r : Ordnode α) : Ordnode α :=
node' l x (node' m y r)
#align ordnode.node3_r Ordnode.node3R
/-- Build a tree from three nodes, with `a () b -> (a ()) b` and `a (b c) d -> ((a b) (c d))`. -/
def node4L : Ordnode α → α → Ordnode α → α → Ordnode α → Ordnode α
| l, x, node _ ml y mr, z, r => node' (node' l x ml) y (node' mr z r)
| l, x, nil, z, r => node3L l x nil z r
#align ordnode.node4_l Ordnode.node4L
-- should not happen
/-- Build a tree from three nodes, with `a () b -> a (() b)` and `a (b c) d -> ((a b) (c d))`. -/
def node4R : Ordnode α → α → Ordnode α → α → Ordnode α → Ordnode α
| l, x, node _ ml y mr, z, r => node' (node' l x ml) y (node' mr z r)
| l, x, nil, z, r => node3R l x nil z r
#align ordnode.node4_r Ordnode.node4R
-- should not happen
/-- Concatenate two nodes, performing a left rotation `x (y z) -> ((x y) z)`
if balance is upset. -/
def rotateL : Ordnode α → α → Ordnode α → Ordnode α
| l, x, node _ m y r => if size m < ratio * size r then node3L l x m y r else node4L l x m y r
| l, x, nil => node' l x nil
#align ordnode.rotate_l Ordnode.rotateL
-- Porting note (#11467): during the port we marked these lemmas with `@[eqns]`
-- to emulate the old Lean 3 behaviour.
theorem rotateL_node (l : Ordnode α) (x : α) (sz : ℕ) (m : Ordnode α) (y : α) (r : Ordnode α) :
rotateL l x (node sz m y r) =
if size m < ratio * size r then node3L l x m y r else node4L l x m y r :=
rfl
theorem rotateL_nil (l : Ordnode α) (x : α) : rotateL l x nil = node' l x nil :=
rfl
-- should not happen
/-- Concatenate two nodes, performing a right rotation `(x y) z -> (x (y z))`
if balance is upset. -/
def rotateR : Ordnode α → α → Ordnode α → Ordnode α
| node _ l x m, y, r => if size m < ratio * size l then node3R l x m y r else node4R l x m y r
| nil, y, r => node' nil y r
#align ordnode.rotate_r Ordnode.rotateR
-- Porting note (#11467): during the port we marked these lemmas with `@[eqns]`
-- to emulate the old Lean 3 behaviour.
theorem rotateR_node (sz : ℕ) (l : Ordnode α) (x : α) (m : Ordnode α) (y : α) (r : Ordnode α) :
rotateR (node sz l x m) y r =
if size m < ratio * size l then node3R l x m y r else node4R l x m y r :=
rfl
theorem rotateR_nil (y : α) (r : Ordnode α) : rotateR nil y r = node' nil y r :=
rfl
-- should not happen
/-- A left balance operation. This will rebalance a concatenation, assuming the original nodes are
not too far from balanced. -/
def balanceL' (l : Ordnode α) (x : α) (r : Ordnode α) : Ordnode α :=
if size l + size r ≤ 1 then node' l x r
else if size l > delta * size r then rotateR l x r else node' l x r
#align ordnode.balance_l' Ordnode.balanceL'
/-- A right balance operation. This will rebalance a concatenation, assuming the original nodes are
not too far from balanced. -/
def balanceR' (l : Ordnode α) (x : α) (r : Ordnode α) : Ordnode α :=
if size l + size r ≤ 1 then node' l x r
else if size r > delta * size l then rotateL l x r else node' l x r
#align ordnode.balance_r' Ordnode.balanceR'
/-- The full balance operation. This is the same as `balance`, but with less manual inlining.
It is somewhat easier to work with this version in proofs. -/
def balance' (l : Ordnode α) (x : α) (r : Ordnode α) : Ordnode α :=
if size l + size r ≤ 1 then node' l x r
else
if size r > delta * size l then rotateL l x r
else if size l > delta * size r then rotateR l x r else node' l x r
#align ordnode.balance' Ordnode.balance'
theorem dual_node' (l : Ordnode α) (x : α) (r : Ordnode α) :
dual (node' l x r) = node' (dual r) x (dual l) := by simp [node', add_comm]
#align ordnode.dual_node' Ordnode.dual_node'
theorem dual_node3L (l : Ordnode α) (x : α) (m : Ordnode α) (y : α) (r : Ordnode α) :
dual (node3L l x m y r) = node3R (dual r) y (dual m) x (dual l) := by
simp [node3L, node3R, dual_node', add_comm]
#align ordnode.dual_node3_l Ordnode.dual_node3L
theorem dual_node3R (l : Ordnode α) (x : α) (m : Ordnode α) (y : α) (r : Ordnode α) :
dual (node3R l x m y r) = node3L (dual r) y (dual m) x (dual l) := by
simp [node3L, node3R, dual_node', add_comm]
#align ordnode.dual_node3_r Ordnode.dual_node3R
theorem dual_node4L (l : Ordnode α) (x : α) (m : Ordnode α) (y : α) (r : Ordnode α) :
dual (node4L l x m y r) = node4R (dual r) y (dual m) x (dual l) := by
cases m <;> simp [node4L, node4R, node3R, dual_node3L, dual_node', add_comm]
#align ordnode.dual_node4_l Ordnode.dual_node4L
theorem dual_node4R (l : Ordnode α) (x : α) (m : Ordnode α) (y : α) (r : Ordnode α) :
dual (node4R l x m y r) = node4L (dual r) y (dual m) x (dual l) := by
cases m <;> simp [node4L, node4R, node3L, dual_node3R, dual_node', add_comm]
#align ordnode.dual_node4_r Ordnode.dual_node4R
theorem dual_rotateL (l : Ordnode α) (x : α) (r : Ordnode α) :
dual (rotateL l x r) = rotateR (dual r) x (dual l) := by
cases r <;> simp [rotateL, rotateR, dual_node']; split_ifs <;>
simp [dual_node3L, dual_node4L, node3R, add_comm]
#align ordnode.dual_rotate_l Ordnode.dual_rotateL
theorem dual_rotateR (l : Ordnode α) (x : α) (r : Ordnode α) :
dual (rotateR l x r) = rotateL (dual r) x (dual l) := by
rw [← dual_dual (rotateL _ _ _), dual_rotateL, dual_dual, dual_dual]
#align ordnode.dual_rotate_r Ordnode.dual_rotateR
theorem dual_balance' (l : Ordnode α) (x : α) (r : Ordnode α) :
dual (balance' l x r) = balance' (dual r) x (dual l) := by
simp [balance', add_comm]; split_ifs with h h_1 h_2 <;>
simp [dual_node', dual_rotateL, dual_rotateR, add_comm]
cases delta_lt_false h_1 h_2
#align ordnode.dual_balance' Ordnode.dual_balance'
theorem dual_balanceL (l : Ordnode α) (x : α) (r : Ordnode α) :
dual (balanceL l x r) = balanceR (dual r) x (dual l) := by
unfold balanceL balanceR
cases' r with rs rl rx rr
· cases' l with ls ll lx lr; · rfl
cases' ll with lls lll llx llr <;> cases' lr with lrs lrl lrx lrr <;> dsimp only [dual, id] <;>
try rfl
split_ifs with h <;> repeat simp [h, add_comm]
· cases' l with ls ll lx lr; · rfl
dsimp only [dual, id]
split_ifs; swap; · simp [add_comm]
cases' ll with lls lll llx llr <;> cases' lr with lrs lrl lrx lrr <;> try rfl
dsimp only [dual, id]
split_ifs with h <;> simp [h, add_comm]
#align ordnode.dual_balance_l Ordnode.dual_balanceL
theorem dual_balanceR (l : Ordnode α) (x : α) (r : Ordnode α) :
dual (balanceR l x r) = balanceL (dual r) x (dual l) := by
rw [← dual_dual (balanceL _ _ _), dual_balanceL, dual_dual, dual_dual]
#align ordnode.dual_balance_r Ordnode.dual_balanceR
theorem Sized.node3L {l x m y r} (hl : @Sized α l) (hm : Sized m) (hr : Sized r) :
Sized (node3L l x m y r) :=
(hl.node' hm).node' hr
#align ordnode.sized.node3_l Ordnode.Sized.node3L
theorem Sized.node3R {l x m y r} (hl : @Sized α l) (hm : Sized m) (hr : Sized r) :
Sized (node3R l x m y r) :=
hl.node' (hm.node' hr)
#align ordnode.sized.node3_r Ordnode.Sized.node3R
theorem Sized.node4L {l x m y r} (hl : @Sized α l) (hm : Sized m) (hr : Sized r) :
Sized (node4L l x m y r) := by
cases m <;> [exact (hl.node' hm).node' hr; exact (hl.node' hm.2.1).node' (hm.2.2.node' hr)]
#align ordnode.sized.node4_l Ordnode.Sized.node4L
theorem node3L_size {l x m y r} : size (@node3L α l x m y r) = size l + size m + size r + 2 := by
dsimp [node3L, node', size]; rw [add_right_comm _ 1]
#align ordnode.node3_l_size Ordnode.node3L_size
theorem node3R_size {l x m y r} : size (@node3R α l x m y r) = size l + size m + size r + 2 := by
dsimp [node3R, node', size]; rw [← add_assoc, ← add_assoc]
#align ordnode.node3_r_size Ordnode.node3R_size
theorem node4L_size {l x m y r} (hm : Sized m) :
size (@node4L α l x m y r) = size l + size m + size r + 2 := by
cases m <;> simp [node4L, node3L, node'] <;> [abel; (simp [size, hm.1]; abel)]
#align ordnode.node4_l_size Ordnode.node4L_size
theorem Sized.dual : ∀ {t : Ordnode α}, Sized t → Sized (dual t)
| nil, _ => ⟨⟩
| node _ l _ r, ⟨rfl, sl, sr⟩ => ⟨by simp [size_dual, add_comm], Sized.dual sr, Sized.dual sl⟩
#align ordnode.sized.dual Ordnode.Sized.dual
theorem Sized.dual_iff {t : Ordnode α} : Sized (.dual t) ↔ Sized t :=
⟨fun h => by rw [← dual_dual t]; exact h.dual, Sized.dual⟩
#align ordnode.sized.dual_iff Ordnode.Sized.dual_iff
theorem Sized.rotateL {l x r} (hl : @Sized α l) (hr : Sized r) : Sized (rotateL l x r) := by
cases r; · exact hl.node' hr
rw [Ordnode.rotateL_node]; split_ifs
· exact hl.node3L hr.2.1 hr.2.2
· exact hl.node4L hr.2.1 hr.2.2
#align ordnode.sized.rotate_l Ordnode.Sized.rotateL
theorem Sized.rotateR {l x r} (hl : @Sized α l) (hr : Sized r) : Sized (rotateR l x r) :=
Sized.dual_iff.1 <| by rw [dual_rotateR]; exact hr.dual.rotateL hl.dual
#align ordnode.sized.rotate_r Ordnode.Sized.rotateR
theorem Sized.rotateL_size {l x r} (hm : Sized r) :
size (@Ordnode.rotateL α l x r) = size l + size r + 1 := by
cases r <;> simp [Ordnode.rotateL]
simp only [hm.1]
split_ifs <;> simp [node3L_size, node4L_size hm.2.1] <;> abel
#align ordnode.sized.rotate_l_size Ordnode.Sized.rotateL_size
theorem Sized.rotateR_size {l x r} (hl : Sized l) :
size (@Ordnode.rotateR α l x r) = size l + size r + 1 := by
rw [← size_dual, dual_rotateR, hl.dual.rotateL_size, size_dual, size_dual, add_comm (size l)]
#align ordnode.sized.rotate_r_size Ordnode.Sized.rotateR_size
theorem Sized.balance' {l x r} (hl : @Sized α l) (hr : Sized r) : Sized (balance' l x r) := by
unfold balance'; split_ifs
· exact hl.node' hr
· exact hl.rotateL hr
· exact hl.rotateR hr
· exact hl.node' hr
#align ordnode.sized.balance' Ordnode.Sized.balance'
theorem size_balance' {l x r} (hl : @Sized α l) (hr : Sized r) :
size (@balance' α l x r) = size l + size r + 1 := by
unfold balance'; split_ifs
· rfl
· exact hr.rotateL_size
· exact hl.rotateR_size
· rfl
#align ordnode.size_balance' Ordnode.size_balance'
/-! ## `All`, `Any`, `Emem`, `Amem` -/
theorem All.imp {P Q : α → Prop} (H : ∀ a, P a → Q a) : ∀ {t}, All P t → All Q t
| nil, _ => ⟨⟩
| node _ _ _ _, ⟨h₁, h₂, h₃⟩ => ⟨h₁.imp H, H _ h₂, h₃.imp H⟩
#align ordnode.all.imp Ordnode.All.imp
theorem Any.imp {P Q : α → Prop} (H : ∀ a, P a → Q a) : ∀ {t}, Any P t → Any Q t
| nil => id
| node _ _ _ _ => Or.imp (Any.imp H) <| Or.imp (H _) (Any.imp H)
#align ordnode.any.imp Ordnode.Any.imp
theorem all_singleton {P : α → Prop} {x : α} : All P (singleton x) ↔ P x :=
⟨fun h => h.2.1, fun h => ⟨⟨⟩, h, ⟨⟩⟩⟩
#align ordnode.all_singleton Ordnode.all_singleton
theorem any_singleton {P : α → Prop} {x : α} : Any P (singleton x) ↔ P x :=
⟨by rintro (⟨⟨⟩⟩ | h | ⟨⟨⟩⟩); exact h, fun h => Or.inr (Or.inl h)⟩
#align ordnode.any_singleton Ordnode.any_singleton
theorem all_dual {P : α → Prop} : ∀ {t : Ordnode α}, All P (dual t) ↔ All P t
| nil => Iff.rfl
| node _ _l _x _r =>
⟨fun ⟨hr, hx, hl⟩ => ⟨all_dual.1 hl, hx, all_dual.1 hr⟩, fun ⟨hl, hx, hr⟩ =>
⟨all_dual.2 hr, hx, all_dual.2 hl⟩⟩
#align ordnode.all_dual Ordnode.all_dual
theorem all_iff_forall {P : α → Prop} : ∀ {t}, All P t ↔ ∀ x, Emem x t → P x
| nil => (iff_true_intro <| by rintro _ ⟨⟩).symm
| node _ l x r => by simp [All, Emem, all_iff_forall, Any, or_imp, forall_and]
#align ordnode.all_iff_forall Ordnode.all_iff_forall
theorem any_iff_exists {P : α → Prop} : ∀ {t}, Any P t ↔ ∃ x, Emem x t ∧ P x
| nil => ⟨by rintro ⟨⟩, by rintro ⟨_, ⟨⟩, _⟩⟩
| node _ l x r => by simp only [Emem]; simp [Any, any_iff_exists, or_and_right, exists_or]
#align ordnode.any_iff_exists Ordnode.any_iff_exists
theorem emem_iff_all {x : α} {t} : Emem x t ↔ ∀ P, All P t → P x :=
⟨fun h _ al => all_iff_forall.1 al _ h, fun H => H _ <| all_iff_forall.2 fun _ => id⟩
#align ordnode.emem_iff_all Ordnode.emem_iff_all
theorem all_node' {P l x r} : @All α P (node' l x r) ↔ All P l ∧ P x ∧ All P r :=
Iff.rfl
#align ordnode.all_node' Ordnode.all_node'
theorem all_node3L {P l x m y r} :
@All α P (node3L l x m y r) ↔ All P l ∧ P x ∧ All P m ∧ P y ∧ All P r := by
simp [node3L, all_node', and_assoc]
#align ordnode.all_node3_l Ordnode.all_node3L
theorem all_node3R {P l x m y r} :
@All α P (node3R l x m y r) ↔ All P l ∧ P x ∧ All P m ∧ P y ∧ All P r :=
Iff.rfl
#align ordnode.all_node3_r Ordnode.all_node3R
theorem all_node4L {P l x m y r} :
@All α P (node4L l x m y r) ↔ All P l ∧ P x ∧ All P m ∧ P y ∧ All P r := by
cases m <;> simp [node4L, all_node', All, all_node3L, and_assoc]
#align ordnode.all_node4_l Ordnode.all_node4L
theorem all_node4R {P l x m y r} :
@All α P (node4R l x m y r) ↔ All P l ∧ P x ∧ All P m ∧ P y ∧ All P r := by
cases m <;> simp [node4R, all_node', All, all_node3R, and_assoc]
#align ordnode.all_node4_r Ordnode.all_node4R
theorem all_rotateL {P l x r} : @All α P (rotateL l x r) ↔ All P l ∧ P x ∧ All P r := by
cases r <;> simp [rotateL, all_node']; split_ifs <;>
simp [all_node3L, all_node4L, All, and_assoc]
#align ordnode.all_rotate_l Ordnode.all_rotateL
theorem all_rotateR {P l x r} : @All α P (rotateR l x r) ↔ All P l ∧ P x ∧ All P r := by
rw [← all_dual, dual_rotateR, all_rotateL]; simp [all_dual, and_comm, and_left_comm, and_assoc]
#align ordnode.all_rotate_r Ordnode.all_rotateR
theorem all_balance' {P l x r} : @All α P (balance' l x r) ↔ All P l ∧ P x ∧ All P r := by
rw [balance']; split_ifs <;> simp [all_node', all_rotateL, all_rotateR]
#align ordnode.all_balance' Ordnode.all_balance'
/-! ### `toList` -/
theorem foldr_cons_eq_toList : ∀ (t : Ordnode α) (r : List α), t.foldr List.cons r = toList t ++ r
| nil, r => rfl
| node _ l x r, r' => by
rw [foldr, foldr_cons_eq_toList l, foldr_cons_eq_toList r, ← List.cons_append,
← List.append_assoc, ← foldr_cons_eq_toList l]; rfl
#align ordnode.foldr_cons_eq_to_list Ordnode.foldr_cons_eq_toList
@[simp]
theorem toList_nil : toList (@nil α) = [] :=
rfl
#align ordnode.to_list_nil Ordnode.toList_nil
@[simp]
theorem toList_node (s l x r) : toList (@node α s l x r) = toList l ++ x :: toList r := by
rw [toList, foldr, foldr_cons_eq_toList]; rfl
#align ordnode.to_list_node Ordnode.toList_node
theorem emem_iff_mem_toList {x : α} {t} : Emem x t ↔ x ∈ toList t := by
unfold Emem; induction t <;> simp [Any, *, or_assoc]
#align ordnode.emem_iff_mem_to_list Ordnode.emem_iff_mem_toList
theorem length_toList' : ∀ t : Ordnode α, (toList t).length = t.realSize
| nil => rfl
| node _ l _ r => by
rw [toList_node, List.length_append, List.length_cons, length_toList' l,
length_toList' r]; rfl
#align ordnode.length_to_list' Ordnode.length_toList'
theorem length_toList {t : Ordnode α} (h : Sized t) : (toList t).length = t.size := by
rw [length_toList', size_eq_realSize h]
#align ordnode.length_to_list Ordnode.length_toList
theorem equiv_iff {t₁ t₂ : Ordnode α} (h₁ : Sized t₁) (h₂ : Sized t₂) :
Equiv t₁ t₂ ↔ toList t₁ = toList t₂ :=
and_iff_right_of_imp fun h => by rw [← length_toList h₁, h, length_toList h₂]
#align ordnode.equiv_iff Ordnode.equiv_iff
/-! ### `mem` -/
theorem pos_size_of_mem [LE α] [@DecidableRel α (· ≤ ·)] {x : α} {t : Ordnode α} (h : Sized t)
(h_mem : x ∈ t) : 0 < size t := by cases t; · { contradiction }; · { simp [h.1] }
#align ordnode.pos_size_of_mem Ordnode.pos_size_of_mem
/-! ### `(find/erase/split)(Min/Max)` -/
theorem findMin'_dual : ∀ (t) (x : α), findMin' (dual t) x = findMax' x t
| nil, _ => rfl
| node _ _ x r, _ => findMin'_dual r x
#align ordnode.find_min'_dual Ordnode.findMin'_dual
theorem findMax'_dual (t) (x : α) : findMax' x (dual t) = findMin' t x := by
rw [← findMin'_dual, dual_dual]
#align ordnode.find_max'_dual Ordnode.findMax'_dual
theorem findMin_dual : ∀ t : Ordnode α, findMin (dual t) = findMax t
| nil => rfl
| node _ _ _ _ => congr_arg some <| findMin'_dual _ _
#align ordnode.find_min_dual Ordnode.findMin_dual
theorem findMax_dual (t : Ordnode α) : findMax (dual t) = findMin t := by
rw [← findMin_dual, dual_dual]
#align ordnode.find_max_dual Ordnode.findMax_dual
theorem dual_eraseMin : ∀ t : Ordnode α, dual (eraseMin t) = eraseMax (dual t)
| nil => rfl
| node _ nil x r => rfl
| node _ (node sz l' y r') x r => by
rw [eraseMin, dual_balanceR, dual_eraseMin (node sz l' y r'), dual, dual, dual, eraseMax]
#align ordnode.dual_erase_min Ordnode.dual_eraseMin
theorem dual_eraseMax (t : Ordnode α) : dual (eraseMax t) = eraseMin (dual t) := by
rw [← dual_dual (eraseMin _), dual_eraseMin, dual_dual]
#align ordnode.dual_erase_max Ordnode.dual_eraseMax
theorem splitMin_eq :
∀ (s l) (x : α) (r), splitMin' l x r = (findMin' l x, eraseMin (node s l x r))
| _, nil, x, r => rfl
| _, node ls ll lx lr, x, r => by rw [splitMin', splitMin_eq ls ll lx lr, findMin', eraseMin]
#align ordnode.split_min_eq Ordnode.splitMin_eq
theorem splitMax_eq :
∀ (s l) (x : α) (r), splitMax' l x r = (eraseMax (node s l x r), findMax' x r)
| _, l, x, nil => rfl
| _, l, x, node ls ll lx lr => by rw [splitMax', splitMax_eq ls ll lx lr, findMax', eraseMax]
#align ordnode.split_max_eq Ordnode.splitMax_eq
-- @[elab_as_elim] -- Porting note: unexpected eliminator resulting type
theorem findMin'_all {P : α → Prop} : ∀ (t) (x : α), All P t → P x → P (findMin' t x)
| nil, _x, _, hx => hx
| node _ ll lx _, _, ⟨h₁, h₂, _⟩, _ => findMin'_all ll lx h₁ h₂
#align ordnode.find_min'_all Ordnode.findMin'_all
-- @[elab_as_elim] -- Porting note: unexpected eliminator resulting type
theorem findMax'_all {P : α → Prop} : ∀ (x : α) (t), P x → All P t → P (findMax' x t)
| _x, nil, hx, _ => hx
| _, node _ _ lx lr, _, ⟨_, h₂, h₃⟩ => findMax'_all lx lr h₂ h₃
#align ordnode.find_max'_all Ordnode.findMax'_all
/-! ### `glue` -/
/-! ### `merge` -/
@[simp]
theorem merge_nil_left (t : Ordnode α) : merge t nil = t := by cases t <;> rfl
#align ordnode.merge_nil_left Ordnode.merge_nil_left
@[simp]
theorem merge_nil_right (t : Ordnode α) : merge nil t = t :=
rfl
#align ordnode.merge_nil_right Ordnode.merge_nil_right
@[simp]
theorem merge_node {ls ll lx lr rs rl rx rr} :
merge (@node α ls ll lx lr) (node rs rl rx rr) =
if delta * ls < rs then balanceL (merge (node ls ll lx lr) rl) rx rr
else if delta * rs < ls then balanceR ll lx (merge lr (node rs rl rx rr))
else glue (node ls ll lx lr) (node rs rl rx rr) :=
rfl
#align ordnode.merge_node Ordnode.merge_node
/-! ### `insert` -/
theorem dual_insert [Preorder α] [IsTotal α (· ≤ ·)] [@DecidableRel α (· ≤ ·)] (x : α) :
∀ t : Ordnode α, dual (Ordnode.insert x t) = @Ordnode.insert αᵒᵈ _ _ x (dual t)
| nil => rfl
| node _ l y r => by
have : @cmpLE αᵒᵈ _ _ x y = cmpLE y x := rfl
rw [Ordnode.insert, dual, Ordnode.insert, this, ← cmpLE_swap x y]
cases cmpLE x y <;>
simp [Ordering.swap, Ordnode.insert, dual_balanceL, dual_balanceR, dual_insert]
#align ordnode.dual_insert Ordnode.dual_insert
/-! ### `balance` properties -/
theorem balance_eq_balance' {l x r} (hl : Balanced l) (hr : Balanced r) (sl : Sized l)
(sr : Sized r) : @balance α l x r = balance' l x r := by
cases' l with ls ll lx lr
· cases' r with rs rl rx rr
· rfl
· rw [sr.eq_node'] at hr ⊢
cases' rl with rls rll rlx rlr <;> cases' rr with rrs rrl rrx rrr <;>
dsimp [balance, balance']
· rfl
· have : size rrl = 0 ∧ size rrr = 0 := by
have := balancedSz_zero.1 hr.1.symm
rwa [size, sr.2.2.1, Nat.succ_le_succ_iff, Nat.le_zero, add_eq_zero_iff] at this
cases sr.2.2.2.1.size_eq_zero.1 this.1
cases sr.2.2.2.2.size_eq_zero.1 this.2
obtain rfl : rrs = 1 := sr.2.2.1
rw [if_neg, if_pos, rotateL_node, if_pos]; · rfl
all_goals dsimp only [size]; decide
· have : size rll = 0 ∧ size rlr = 0 := by
have := balancedSz_zero.1 hr.1
rwa [size, sr.2.1.1, Nat.succ_le_succ_iff, Nat.le_zero, add_eq_zero_iff] at this
cases sr.2.1.2.1.size_eq_zero.1 this.1
cases sr.2.1.2.2.size_eq_zero.1 this.2
obtain rfl : rls = 1 := sr.2.1.1
rw [if_neg, if_pos, rotateL_node, if_neg]; · rfl
all_goals dsimp only [size]; decide
· symm; rw [zero_add, if_neg, if_pos, rotateL]
· dsimp only [size_node]; split_ifs
· simp [node3L, node']; abel
· simp [node4L, node', sr.2.1.1]; abel
· apply Nat.zero_lt_succ
· exact not_le_of_gt (Nat.succ_lt_succ (add_pos sr.2.1.pos sr.2.2.pos))
· cases' r with rs rl rx rr
· rw [sl.eq_node'] at hl ⊢
cases' ll with lls lll llx llr <;> cases' lr with lrs lrl lrx lrr <;>
dsimp [balance, balance']
· rfl
· have : size lrl = 0 ∧ size lrr = 0 := by
have := balancedSz_zero.1 hl.1.symm
rwa [size, sl.2.2.1, Nat.succ_le_succ_iff, Nat.le_zero, add_eq_zero_iff] at this
cases sl.2.2.2.1.size_eq_zero.1 this.1
cases sl.2.2.2.2.size_eq_zero.1 this.2
obtain rfl : lrs = 1 := sl.2.2.1
rw [if_neg, if_neg, if_pos, rotateR_node, if_neg]; · rfl
all_goals dsimp only [size]; decide
· have : size lll = 0 ∧ size llr = 0 := by
have := balancedSz_zero.1 hl.1
rwa [size, sl.2.1.1, Nat.succ_le_succ_iff, Nat.le_zero, add_eq_zero_iff] at this
cases sl.2.1.2.1.size_eq_zero.1 this.1
cases sl.2.1.2.2.size_eq_zero.1 this.2
obtain rfl : lls = 1 := sl.2.1.1
rw [if_neg, if_neg, if_pos, rotateR_node, if_pos]; · rfl
all_goals dsimp only [size]; decide
· symm; rw [if_neg, if_neg, if_pos, rotateR]
· dsimp only [size_node]; split_ifs
· simp [node3R, node']; abel
· simp [node4R, node', sl.2.2.1]; abel
· apply Nat.zero_lt_succ
· apply Nat.not_lt_zero
· exact not_le_of_gt (Nat.succ_lt_succ (add_pos sl.2.1.pos sl.2.2.pos))
· simp [balance, balance']
symm; rw [if_neg]
· split_ifs with h h_1
· have rd : delta ≤ size rl + size rr := by
have := lt_of_le_of_lt (Nat.mul_le_mul_left _ sl.pos) h
rwa [sr.1, Nat.lt_succ_iff] at this
cases' rl with rls rll rlx rlr
· rw [size, zero_add] at rd
exact absurd (le_trans rd (balancedSz_zero.1 hr.1.symm)) (by decide)
cases' rr with rrs rrl rrx rrr
· exact absurd (le_trans rd (balancedSz_zero.1 hr.1)) (by decide)
dsimp [rotateL]; split_ifs
· simp [node3L, node', sr.1]; abel
· simp [node4L, node', sr.1, sr.2.1.1]; abel
· have ld : delta ≤ size ll + size lr := by
have := lt_of_le_of_lt (Nat.mul_le_mul_left _ sr.pos) h_1
rwa [sl.1, Nat.lt_succ_iff] at this
cases' ll with lls lll llx llr
· rw [size, zero_add] at ld
exact absurd (le_trans ld (balancedSz_zero.1 hl.1.symm)) (by decide)
cases' lr with lrs lrl lrx lrr
· exact absurd (le_trans ld (balancedSz_zero.1 hl.1)) (by decide)
dsimp [rotateR]; split_ifs
· simp [node3R, node', sl.1]; abel
· simp [node4R, node', sl.1, sl.2.2.1]; abel
· simp [node']
· exact not_le_of_gt (add_le_add (Nat.succ_le_of_lt sl.pos) (Nat.succ_le_of_lt sr.pos))
#align ordnode.balance_eq_balance' Ordnode.balance_eq_balance'
theorem balanceL_eq_balance {l x r} (sl : Sized l) (sr : Sized r) (H1 : size l = 0 → size r ≤ 1)
(H2 : 1 ≤ size l → 1 ≤ size r → size r ≤ delta * size l) :
@balanceL α l x r = balance l x r := by
cases' r with rs rl rx rr
· rfl
· cases' l with ls ll lx lr
· have : size rl = 0 ∧ size rr = 0 := by
have := H1 rfl
rwa [size, sr.1, Nat.succ_le_succ_iff, Nat.le_zero, add_eq_zero_iff] at this
cases sr.2.1.size_eq_zero.1 this.1
cases sr.2.2.size_eq_zero.1 this.2
rw [sr.eq_node']; rfl
· replace H2 : ¬rs > delta * ls := not_lt_of_le (H2 sl.pos sr.pos)
simp [balanceL, balance, H2]; split_ifs <;> simp [add_comm]
#align ordnode.balance_l_eq_balance Ordnode.balanceL_eq_balance
/-- `Raised n m` means `m` is either equal or one up from `n`. -/
def Raised (n m : ℕ) : Prop :=
m = n ∨ m = n + 1
#align ordnode.raised Ordnode.Raised
theorem raised_iff {n m} : Raised n m ↔ n ≤ m ∧ m ≤ n + 1 := by
constructor
· rintro (rfl | rfl)
· exact ⟨le_rfl, Nat.le_succ _⟩
· exact ⟨Nat.le_succ _, le_rfl⟩
· rintro ⟨h₁, h₂⟩
rcases eq_or_lt_of_le h₁ with (rfl | h₁)
· exact Or.inl rfl
· exact Or.inr (le_antisymm h₂ h₁)
#align ordnode.raised_iff Ordnode.raised_iff
theorem Raised.dist_le {n m} (H : Raised n m) : Nat.dist n m ≤ 1 := by
cases' raised_iff.1 H with H1 H2; rwa [Nat.dist_eq_sub_of_le H1, tsub_le_iff_left]
#align ordnode.raised.dist_le Ordnode.Raised.dist_le
theorem Raised.dist_le' {n m} (H : Raised n m) : Nat.dist m n ≤ 1 := by
rw [Nat.dist_comm]; exact H.dist_le
#align ordnode.raised.dist_le' Ordnode.Raised.dist_le'
theorem Raised.add_left (k) {n m} (H : Raised n m) : Raised (k + n) (k + m) := by
rcases H with (rfl | rfl)
· exact Or.inl rfl
· exact Or.inr rfl
#align ordnode.raised.add_left Ordnode.Raised.add_left
theorem Raised.add_right (k) {n m} (H : Raised n m) : Raised (n + k) (m + k) := by
rw [add_comm, add_comm m]; exact H.add_left _
#align ordnode.raised.add_right Ordnode.Raised.add_right
theorem Raised.right {l x₁ x₂ r₁ r₂} (H : Raised (size r₁) (size r₂)) :
Raised (size (@node' α l x₁ r₁)) (size (@node' α l x₂ r₂)) := by
rw [node', size_node, size_node]; generalize size r₂ = m at H ⊢
rcases H with (rfl | rfl)
· exact Or.inl rfl
· exact Or.inr rfl
#align ordnode.raised.right Ordnode.Raised.right
theorem balanceL_eq_balance' {l x r} (hl : Balanced l) (hr : Balanced r) (sl : Sized l)
(sr : Sized r)
(H :
(∃ l', Raised l' (size l) ∧ BalancedSz l' (size r)) ∨
∃ r', Raised (size r) r' ∧ BalancedSz (size l) r') :
@balanceL α l x r = balance' l x r := by
rw [← balance_eq_balance' hl hr sl sr, balanceL_eq_balance sl sr]
· intro l0; rw [l0] at H
rcases H with (⟨_, ⟨⟨⟩⟩ | ⟨⟨⟩⟩, H⟩ | ⟨r', e, H⟩)
· exact balancedSz_zero.1 H.symm
exact le_trans (raised_iff.1 e).1 (balancedSz_zero.1 H.symm)
· intro l1 _
rcases H with (⟨l', e, H | ⟨_, H₂⟩⟩ | ⟨r', e, H | ⟨_, H₂⟩⟩)
· exact le_trans (le_trans (Nat.le_add_left _ _) H) (mul_pos (by decide) l1 : (0 : ℕ) < _)
· exact le_trans H₂ (Nat.mul_le_mul_left _ (raised_iff.1 e).1)
· cases raised_iff.1 e; unfold delta; omega
· exact le_trans (raised_iff.1 e).1 H₂
#align ordnode.balance_l_eq_balance' Ordnode.balanceL_eq_balance'
theorem balance_sz_dual {l r}
(H : (∃ l', Raised (@size α l) l' ∧ BalancedSz l' (@size α r)) ∨
∃ r', Raised r' (size r) ∧ BalancedSz (size l) r') :
(∃ l', Raised l' (size (dual r)) ∧ BalancedSz l' (size (dual l))) ∨
∃ r', Raised (size (dual l)) r' ∧ BalancedSz (size (dual r)) r' := by
rw [size_dual, size_dual]
exact
H.symm.imp (Exists.imp fun _ => And.imp_right BalancedSz.symm)
(Exists.imp fun _ => And.imp_right BalancedSz.symm)
#align ordnode.balance_sz_dual Ordnode.balance_sz_dual
theorem size_balanceL {l x r} (hl : Balanced l) (hr : Balanced r) (sl : Sized l) (sr : Sized r)
(H : (∃ l', Raised l' (size l) ∧ BalancedSz l' (size r)) ∨
∃ r', Raised (size r) r' ∧ BalancedSz (size l) r') :
size (@balanceL α l x r) = size l + size r + 1 := by
rw [balanceL_eq_balance' hl hr sl sr H, size_balance' sl sr]
#align ordnode.size_balance_l Ordnode.size_balanceL
theorem all_balanceL {P l x r} (hl : Balanced l) (hr : Balanced r) (sl : Sized l) (sr : Sized r)
(H :
(∃ l', Raised l' (size l) ∧ BalancedSz l' (size r)) ∨
∃ r', Raised (size r) r' ∧ BalancedSz (size l) r') :
All P (@balanceL α l x r) ↔ All P l ∧ P x ∧ All P r := by
rw [balanceL_eq_balance' hl hr sl sr H, all_balance']
#align ordnode.all_balance_l Ordnode.all_balanceL
theorem balanceR_eq_balance' {l x r} (hl : Balanced l) (hr : Balanced r) (sl : Sized l)
(sr : Sized r)
(H : (∃ l', Raised (size l) l' ∧ BalancedSz l' (size r)) ∨
∃ r', Raised r' (size r) ∧ BalancedSz (size l) r') :
@balanceR α l x r = balance' l x r := by
rw [← dual_dual (balanceR l x r), dual_balanceR,
balanceL_eq_balance' hr.dual hl.dual sr.dual sl.dual (balance_sz_dual H), ← dual_balance',
dual_dual]
#align ordnode.balance_r_eq_balance' Ordnode.balanceR_eq_balance'
theorem size_balanceR {l x r} (hl : Balanced l) (hr : Balanced r) (sl : Sized l) (sr : Sized r)
(H : (∃ l', Raised (size l) l' ∧ BalancedSz l' (size r)) ∨
∃ r', Raised r' (size r) ∧ BalancedSz (size l) r') :
size (@balanceR α l x r) = size l + size r + 1 := by
rw [balanceR_eq_balance' hl hr sl sr H, size_balance' sl sr]
#align ordnode.size_balance_r Ordnode.size_balanceR
theorem all_balanceR {P l x r} (hl : Balanced l) (hr : Balanced r) (sl : Sized l) (sr : Sized r)
(H :
(∃ l', Raised (size l) l' ∧ BalancedSz l' (size r)) ∨
∃ r', Raised r' (size r) ∧ BalancedSz (size l) r') :
All P (@balanceR α l x r) ↔ All P l ∧ P x ∧ All P r := by
rw [balanceR_eq_balance' hl hr sl sr H, all_balance']
#align ordnode.all_balance_r Ordnode.all_balanceR
/-! ### `bounded` -/
section
variable [Preorder α]
/-- `Bounded t lo hi` says that every element `x ∈ t` is in the range `lo < x < hi`, and also this
property holds recursively in subtrees, making the full tree a BST. The bounds can be set to
`lo = ⊥` and `hi = ⊤` if we care only about the internal ordering constraints. -/
def Bounded : Ordnode α → WithBot α → WithTop α → Prop
| nil, some a, some b => a < b
| nil, _, _ => True
| node _ l x r, o₁, o₂ => Bounded l o₁ x ∧ Bounded r (↑x) o₂
#align ordnode.bounded Ordnode.Bounded
theorem Bounded.dual :
∀ {t : Ordnode α} {o₁ o₂}, Bounded t o₁ o₂ → @Bounded αᵒᵈ _ (dual t) o₂ o₁
| nil, o₁, o₂, h => by cases o₁ <;> cases o₂ <;> trivial
| node _ l x r, _, _, ⟨ol, Or⟩ => ⟨Or.dual, ol.dual⟩
#align ordnode.bounded.dual Ordnode.Bounded.dual
theorem Bounded.dual_iff {t : Ordnode α} {o₁ o₂} :
Bounded t o₁ o₂ ↔ @Bounded αᵒᵈ _ (.dual t) o₂ o₁ :=
⟨Bounded.dual, fun h => by
have := Bounded.dual h; rwa [dual_dual, OrderDual.Preorder.dual_dual] at this⟩
#align ordnode.bounded.dual_iff Ordnode.Bounded.dual_iff
theorem Bounded.weak_left : ∀ {t : Ordnode α} {o₁ o₂}, Bounded t o₁ o₂ → Bounded t ⊥ o₂
| nil, o₁, o₂, h => by cases o₂ <;> trivial
| node _ l x r, _, _, ⟨ol, Or⟩ => ⟨ol.weak_left, Or⟩
#align ordnode.bounded.weak_left Ordnode.Bounded.weak_left
theorem Bounded.weak_right : ∀ {t : Ordnode α} {o₁ o₂}, Bounded t o₁ o₂ → Bounded t o₁ ⊤
| nil, o₁, o₂, h => by cases o₁ <;> trivial
| node _ l x r, _, _, ⟨ol, Or⟩ => ⟨ol, Or.weak_right⟩
#align ordnode.bounded.weak_right Ordnode.Bounded.weak_right
theorem Bounded.weak {t : Ordnode α} {o₁ o₂} (h : Bounded t o₁ o₂) : Bounded t ⊥ ⊤ :=
h.weak_left.weak_right
#align ordnode.bounded.weak Ordnode.Bounded.weak
theorem Bounded.mono_left {x y : α} (xy : x ≤ y) :
∀ {t : Ordnode α} {o}, Bounded t y o → Bounded t x o
| nil, none, _ => ⟨⟩
| nil, some _, h => lt_of_le_of_lt xy h
| node _ _ _ _, _o, ⟨ol, or⟩ => ⟨ol.mono_left xy, or⟩
#align ordnode.bounded.mono_left Ordnode.Bounded.mono_left
theorem Bounded.mono_right {x y : α} (xy : x ≤ y) :
∀ {t : Ordnode α} {o}, Bounded t o x → Bounded t o y
| nil, none, _ => ⟨⟩
| nil, some _, h => lt_of_lt_of_le h xy
| node _ _ _ _, _o, ⟨ol, or⟩ => ⟨ol, or.mono_right xy⟩
#align ordnode.bounded.mono_right Ordnode.Bounded.mono_right
theorem Bounded.to_lt : ∀ {t : Ordnode α} {x y : α}, Bounded t x y → x < y
| nil, _, _, h => h
| node _ _ _ _, _, _, ⟨h₁, h₂⟩ => lt_trans h₁.to_lt h₂.to_lt
#align ordnode.bounded.to_lt Ordnode.Bounded.to_lt
theorem Bounded.to_nil {t : Ordnode α} : ∀ {o₁ o₂}, Bounded t o₁ o₂ → Bounded nil o₁ o₂
| none, _, _ => ⟨⟩
| some _, none, _ => ⟨⟩
| some _, some _, h => h.to_lt
#align ordnode.bounded.to_nil Ordnode.Bounded.to_nil
theorem Bounded.trans_left {t₁ t₂ : Ordnode α} {x : α} :
∀ {o₁ o₂}, Bounded t₁ o₁ x → Bounded t₂ x o₂ → Bounded t₂ o₁ o₂
| none, _, _, h₂ => h₂.weak_left
| some _, _, h₁, h₂ => h₂.mono_left (le_of_lt h₁.to_lt)
#align ordnode.bounded.trans_left Ordnode.Bounded.trans_left
theorem Bounded.trans_right {t₁ t₂ : Ordnode α} {x : α} :
∀ {o₁ o₂}, Bounded t₁ o₁ x → Bounded t₂ x o₂ → Bounded t₁ o₁ o₂
| _, none, h₁, _ => h₁.weak_right
| _, some _, h₁, h₂ => h₁.mono_right (le_of_lt h₂.to_lt)
#align ordnode.bounded.trans_right Ordnode.Bounded.trans_right
theorem Bounded.mem_lt : ∀ {t o} {x : α}, Bounded t o x → All (· < x) t
| nil, _, _, _ => ⟨⟩
| node _ _ _ _, _, _, ⟨h₁, h₂⟩ =>
⟨h₁.mem_lt.imp fun _ h => lt_trans h h₂.to_lt, h₂.to_lt, h₂.mem_lt⟩
#align ordnode.bounded.mem_lt Ordnode.Bounded.mem_lt
theorem Bounded.mem_gt : ∀ {t o} {x : α}, Bounded t x o → All (· > x) t
| nil, _, _, _ => ⟨⟩
| node _ _ _ _, _, _, ⟨h₁, h₂⟩ => ⟨h₁.mem_gt, h₁.to_lt, h₂.mem_gt.imp fun _ => lt_trans h₁.to_lt⟩
#align ordnode.bounded.mem_gt Ordnode.Bounded.mem_gt
theorem Bounded.of_lt :
∀ {t o₁ o₂} {x : α}, Bounded t o₁ o₂ → Bounded nil o₁ x → All (· < x) t → Bounded t o₁ x
| nil, _, _, _, _, hn, _ => hn
| node _ _ _ _, _, _, _, ⟨h₁, h₂⟩, _, ⟨_, al₂, al₃⟩ => ⟨h₁, h₂.of_lt al₂ al₃⟩
#align ordnode.bounded.of_lt Ordnode.Bounded.of_lt
theorem Bounded.of_gt :
∀ {t o₁ o₂} {x : α}, Bounded t o₁ o₂ → Bounded nil x o₂ → All (· > x) t → Bounded t x o₂
| nil, _, _, _, _, hn, _ => hn
| node _ _ _ _, _, _, _, ⟨h₁, h₂⟩, _, ⟨al₁, al₂, _⟩ => ⟨h₁.of_gt al₂ al₁, h₂⟩
#align ordnode.bounded.of_gt Ordnode.Bounded.of_gt
theorem Bounded.to_sep {t₁ t₂ o₁ o₂} {x : α}
(h₁ : Bounded t₁ o₁ (x : WithTop α)) (h₂ : Bounded t₂ (x : WithBot α) o₂) :
t₁.All fun y => t₂.All fun z : α => y < z := by
refine h₁.mem_lt.imp fun y yx => ?_
exact h₂.mem_gt.imp fun z xz => lt_trans yx xz
#align ordnode.bounded.to_sep Ordnode.Bounded.to_sep
end
/-! ### `Valid` -/
section
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
#align ordnode.valid' Ordnode.Valid'
#align ordnode.valid'.ord Ordnode.Valid'.ord
#align ordnode.valid'.sz Ordnode.Valid'.sz
#align ordnode.valid'.bal Ordnode.Valid'.bal
/-- 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 ⊤
#align ordnode.valid Ordnode.Valid
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⟩
#align ordnode.valid'.mono_left Ordnode.Valid'.mono_left
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⟩
#align ordnode.valid'.mono_right Ordnode.Valid'.mono_right
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⟩
#align ordnode.valid'.trans_left Ordnode.Valid'.trans_left
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⟩
#align ordnode.valid'.trans_right Ordnode.Valid'.trans_right
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⟩
#align ordnode.valid'.of_lt Ordnode.Valid'.of_lt
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⟩
#align ordnode.valid'.of_gt Ordnode.Valid'.of_gt
theorem Valid'.valid {t o₁ o₂} (h : @Valid' α _ o₁ t o₂) : Valid t :=
⟨h.1.weak, h.2, h.3⟩
#align ordnode.valid'.valid Ordnode.Valid'.valid
theorem valid'_nil {o₁ o₂} (h : Bounded nil o₁ o₂) : Valid' o₁ (@nil α) o₂ :=
⟨h, ⟨⟩, ⟨⟩⟩
#align ordnode.valid'_nil Ordnode.valid'_nil
theorem valid_nil : Valid (@nil α) :=
valid'_nil ⟨⟩
#align ordnode.valid_nil Ordnode.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⟩⟩
#align ordnode.valid'.node Ordnode.Valid'.node
theorem Valid'.dual : ∀ {t : Ordnode α} {o₁ o₂}, Valid' o₁ t o₂ → @Valid' αᵒᵈ _ o₂ (dual t) o₁
| .nil, o₁, o₂, h => valid'_nil h.1.dual
| .node _ l x r, o₁, o₂, ⟨⟨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'⟩⟩
#align ordnode.valid'.dual Ordnode.Valid'.dual
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⟩
#align ordnode.valid'.dual_iff Ordnode.Valid'.dual_iff
theorem Valid.dual {t : Ordnode α} : Valid t → @Valid αᵒᵈ _ (.dual t) :=
Valid'.dual
#align ordnode.valid.dual Ordnode.Valid.dual
theorem Valid.dual_iff {t : Ordnode α} : Valid t ↔ @Valid αᵒᵈ _ (.dual t) :=
Valid'.dual_iff
#align ordnode.valid.dual_iff Ordnode.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⟩
#align ordnode.valid'.left Ordnode.Valid'.left
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⟩
#align ordnode.valid'.right Ordnode.Valid'.right
nonrec theorem Valid.left {s l x r} (H : Valid (@node α s l x r)) : Valid l :=
H.left.valid
#align ordnode.valid.left Ordnode.Valid.left
nonrec theorem Valid.right {s l x r} (H : Valid (@node α s l x r)) : Valid r :=
H.right.valid
#align ordnode.valid.right Ordnode.Valid.right
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
#align ordnode.valid.size_eq Ordnode.Valid.size_eq
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
#align ordnode.valid'.node' Ordnode.Valid'.node'
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
#align ordnode.valid'_singleton Ordnode.valid'_singleton
theorem valid_singleton {x : α} : Valid (singleton x : Ordnode α) :=
valid'_singleton ⟨⟩ ⟨⟩
#align ordnode.valid_singleton 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
#align ordnode.valid'.node3_l Ordnode.Valid'.node3L
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
#align ordnode.valid'.node3_r Ordnode.Valid'.node3R
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
#align ordnode.valid'.node4_l_lemma₁ Ordnode.Valid'.node4L_lemma₁
theorem Valid'.node4L_lemma₂ {b c d : ℕ} (mr₂ : b + c + 1 ≤ 3 * d) : c ≤ 3 * d := by omega
#align ordnode.valid'.node4_l_lemma₂ Ordnode.Valid'.node4L_lemma₂
theorem Valid'.node4L_lemma₃ {b c d : ℕ} (mr₁ : 2 * d ≤ b + c + 1) (mm₁ : b ≤ 3 * c) :
d ≤ 3 * c := by omega
#align ordnode.valid'.node4_l_lemma₃ Ordnode.Valid'.node4L_lemma₃
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
#align ordnode.valid'.node4_l_lemma₄ Ordnode.Valid'.node4L_lemma₄
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
#align ordnode.valid'.node4_l_lemma₅ Ordnode.Valid'.node4L_lemma₅
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
cases' m with s ml z mr; · 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_iff] 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₂
#align ordnode.valid'.node4_l Ordnode.Valid'.node4L
theorem Valid'.rotateL_lemma₁ {a b c : ℕ} (H2 : 3 * a ≤ b + c) (hb₂ : c ≤ 3 * b) : a ≤ 3 * b := by
omega
#align ordnode.valid'.rotate_l_lemma₁ Ordnode.Valid'.rotateL_lemma₁
theorem Valid'.rotateL_lemma₂ {a b c : ℕ} (H3 : 2 * (b + c) ≤ 9 * a + 3) (h : b < 2 * c) :
b < 3 * a + 1 := by omega
#align ordnode.valid'.rotate_l_lemma₂ Ordnode.Valid'.rotateL_lemma₂
theorem Valid'.rotateL_lemma₃ {a b c : ℕ} (H2 : 3 * a ≤ b + c) (h : b < 2 * c) : a + b < 3 * c := by
omega
#align ordnode.valid'.rotate_l_lemma₃ Ordnode.Valid'.rotateL_lemma₃
theorem Valid'.rotateL_lemma₄ {a b : ℕ} (H3 : 2 * b ≤ 9 * a + 3) : 3 * b ≤ 16 * a + 9 := by
omega
#align ordnode.valid'.rotate_l_lemma₄ Ordnode.Valid'.rotateL_lemma₄
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
cases' r with rs rl rx rr; · 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)
erw [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⟩
#align ordnode.valid'.rotate_l Ordnode.Valid'.rotateL
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]
#align ordnode.valid'.rotate_r Ordnode.Valid'.rotateR
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⟩)
#align ordnode.valid'.balance'_aux Ordnode.Valid'.balance'_aux
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
rcases Nat.eq_zero_or_pos (size l) with l0 | l0
· apply Or.inr; rwa [l0] at this
change 1 ≤ _ at l0; apply Or.inl; 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)))
#align ordnode.valid'.balance'_lemma Ordnode.Valid'.balance'_lemma
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)
#align ordnode.valid'.balance' Ordnode.Valid'.balance'
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
#align ordnode.valid'.balance Ordnode.Valid'.balance
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
#align ordnode.valid'.balance_l_aux Ordnode.Valid'.balanceL_aux
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⟩⟩
#align ordnode.valid'.balance_l Ordnode.Valid'.balanceL
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₃
#align ordnode.valid'.balance_r_aux Ordnode.Valid'.balanceR_aux
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)
#align ordnode.valid'.balance_r Ordnode.Valid'.balanceR
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 with rs rl rx rr _ IHrr generalizing l x o₁
· exact ⟨H.left, rfl⟩
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
#align ordnode.valid'.erase_max_aux Ordnode.Valid'.eraseMax_aux
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
#align ordnode.valid'.erase_min_aux Ordnode.Valid'.eraseMin_aux
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
#align ordnode.erase_min.valid Ordnode.eraseMin.valid
theorem eraseMax.valid {t} (h : @Valid α _ t) : Valid (eraseMax t) := by
rw [Valid.dual_iff, dual_eraseMax]; exact eraseMin.valid h.dual
#align ordnode.erase_max.valid Ordnode.eraseMax.valid
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
cases' l with ls ll lx lr; · exact ⟨hr, (zero_add _).symm⟩
cases' r with rs rl rx rr; · exact ⟨hl, rfl⟩
dsimp [glue]; split_ifs
· rw [splitMax_eq]
· cases' Valid'.eraseMax_aux hl with v e
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]
· cases' Valid'.eraseMin_aux hr with v e
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
#align ordnode.valid'.glue_aux Ordnode.Valid'.glue_aux
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)
#align ordnode.valid'.glue Ordnode.Valid'.glue
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
#align ordnode.valid'.merge_lemma Ordnode.Valid'.merge_lemma
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
#align ordnode.valid'.merge_aux₁ Ordnode.Valid'.merge_aux₁
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 with ls ll lx lr _ IHlr generalizing o₁ o₂ r
· exact ⟨hr, (zero_add _).symm⟩
induction' r with rs rl rx rr IHrl _ generalizing o₁ o₂
· exact ⟨hl, rfl⟩
rw [merge_node]; split_ifs with h h_1
· cases'
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) with
v e
exact Valid'.merge_aux₁ hl hr h v e
· cases' IHlr hl.right (hr.of_gt hl.1.2.to_nil sep.2.1) sep.2.2 with v e
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⟩)
#align ordnode.valid'.merge_aux Ordnode.Valid'.merge_aux
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
#align ordnode.valid.merge Ordnode.Valid.merge
theorem insertWith.valid_aux [IsTotal α (· ≤ ·)] [@DecidableRel α (· ≤ ·)] (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, o₁, o₂, _, 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⟩
#align ordnode.insert_with.valid_aux Ordnode.insertWith.valid_aux
theorem insertWith.valid [IsTotal α (· ≤ ·)] [@DecidableRel α (· ≤ ·)] (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
#align ordnode.insert_with.valid Ordnode.insertWith.valid
theorem insert_eq_insertWith [@DecidableRel α (· ≤ ·)] (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]
#align ordnode.insert_eq_insert_with Ordnode.insert_eq_insertWith
| Mathlib/Data/Ordmap/Ordset.lean | 1,550 | 1,552 | theorem insert.valid [IsTotal α (· ≤ ·)] [@DecidableRel α (· ≤ ·)] (x : α) {t} (h : Valid t) :
Valid (Ordnode.insert x t) := by |
rw [insert_eq_insertWith]; exact insertWith.valid _ _ (fun _ _ => ⟨le_rfl, le_rfl⟩) h
|
/-
Copyright (c) 2023 Jz Pan. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jz Pan
-/
import Mathlib.FieldTheory.SplittingField.Construction
import Mathlib.FieldTheory.IsAlgClosed.AlgebraicClosure
import Mathlib.FieldTheory.Separable
import Mathlib.FieldTheory.NormalClosure
import Mathlib.RingTheory.Polynomial.SeparableDegree
/-!
# Separable degree
This file contains basics about the separable degree of a field extension.
## Main definitions
- `Field.Emb F E`: the type of `F`-algebra homomorphisms from `E` to the algebraic closure of `E`
(the algebraic closure of `F` is usually used in the literature, but our definition has the
advantage that `Field.Emb F E` lies in the same universe as `E` rather than the maximum over `F`
and `E`). Usually denoted by $\operatorname{Emb}_F(E)$ in textbooks.
**Remark:** if `E / F` is not algebraic, then this definition makes no mathematical sense,
and if it is infinite, then its cardinality doesn't behave as expected (namely, not equal to the
field extension degree of `separableClosure F E / F`). For example, if $F = \mathbb{Q}$ and
$E = \mathbb{Q}( \mu_{p^\infty} )$, then $\operatorname{Emb}_F (E)$ is in bijection with
$\operatorname{Gal}(E/F)$, which is isomorphic to
$\mathbb{Z}_p^\times$, which is uncountable, while $[E:F]$ is countable.
**TODO:** prove or disprove that if `E / F` is algebraic and `Emb F E` is infinite, then
`Field.Emb F E` has cardinality `2 ^ Module.rank F (separableClosure F E)`.
- `Field.finSepDegree F E`: the (finite) separable degree $[E:F]_s$ of an algebraic extension
`E / F` of fields, defined to be the number of `F`-algebra homomorphisms from `E` to the algebraic
closure of `E`, as a natural number. It is zero if `Field.Emb F E` is not finite.
Note that if `E / F` is not algebraic, then this definition makes no mathematical sense.
**Remark:** the `Cardinal`-valued, potentially infinite separable degree `Field.sepDegree F E`
for a general algebraic extension `E / F` is defined to be the degree of `L / F`, where `L` is
the (relative) separable closure `separableClosure F E` of `F` in `E`, which is not defined in
this file yet. Later we will show that (`Field.finSepDegree_eq`), if `Field.Emb F E` is finite,
then these two definitions coincide.
- `Polynomial.natSepDegree`: the separable degree of a polynomial is a natural number,
defined to be the number of distinct roots of it over its splitting field.
## Main results
- `Field.embEquivOfEquiv`, `Field.finSepDegree_eq_of_equiv`:
a random bijection between `Field.Emb F E` and `Field.Emb F K` when `E` and `K` are isomorphic
as `F`-algebras. In particular, they have the same cardinality (so their
`Field.finSepDegree` are equal).
- `Field.embEquivOfAdjoinSplits`,
`Field.finSepDegree_eq_of_adjoin_splits`: a random bijection between `Field.Emb F E` and
`E →ₐ[F] K` if `E = F(S)` such that every element `s` of `S` is integral (= algebraic) over `F`
and whose minimal polynomial splits in `K`. In particular, they have the same cardinality.
- `Field.embEquivOfIsAlgClosed`,
`Field.finSepDegree_eq_of_isAlgClosed`: a random bijection between `Field.Emb F E` and
`E →ₐ[F] K` when `E / F` is algebraic and `K / F` is algebraically closed.
In particular, they have the same cardinality.
- `Field.embProdEmbOfIsAlgebraic`, `Field.finSepDegree_mul_finSepDegree_of_isAlgebraic`:
if `K / E / F` is a field extension tower, such that `K / E` is algebraic,
then there is a non-canonical bijection `Field.Emb F E × Field.Emb E K ≃ Field.Emb F K`.
In particular, the separable degrees satisfy the tower law: $[E:F]_s [K:E]_s = [K:F]_s$
(see also `FiniteDimensional.finrank_mul_finrank`).
- `Polynomial.natSepDegree_le_natDegree`: the separable degree of a polynomial is smaller than
its degree.
- `Polynomial.natSepDegree_eq_natDegree_iff`: the separable degree of a non-zero polynomial is
equal to its degree if and only if it is separable.
- `Polynomial.natSepDegree_eq_of_splits`: if a polynomial splits over `E`, then its separable degree
is equal to the number of distinct roots of it over `E`.
- `Polynomial.natSepDegree_eq_of_isAlgClosed`: the separable degree of a polynomial is equal to
the number of distinct roots of it over any algebraically closed field.
- `Polynomial.natSepDegree_expand`: if a field `F` is of exponential characteristic
`q`, then `Polynomial.expand F (q ^ n) f` and `f` have the same separable degree.
- `Polynomial.HasSeparableContraction.natSepDegree_eq`: if a polynomial has separable
contraction, then its separable degree is equal to its separable contraction degree.
- `Irreducible.natSepDegree_dvd_natDegree`: the separable degree of an irreducible
polynomial divides its degree.
- `IntermediateField.finSepDegree_adjoin_simple_eq_natSepDegree`: the separable degree of
`F⟮α⟯ / F` is equal to the separable degree of the minimal polynomial of `α` over `F`.
- `IntermediateField.finSepDegree_adjoin_simple_eq_finrank_iff`: if `α` is algebraic over `F`, then
the separable degree of `F⟮α⟯ / F` is equal to the degree of `F⟮α⟯ / F` if and only if `α` is a
separable element.
- `Field.finSepDegree_dvd_finrank`: the separable degree of any field extension `E / F` divides
the degree of `E / F`.
- `Field.finSepDegree_le_finrank`: the separable degree of a finite extension `E / F` is smaller
than the degree of `E / F`.
- `Field.finSepDegree_eq_finrank_iff`: if `E / F` is a finite extension, then its separable degree
is equal to its degree if and only if it is a separable extension.
- `IntermediateField.isSeparable_adjoin_simple_iff_separable`: `F⟮x⟯ / F` is a separable extension
if and only if `x` is a separable element.
- `IsSeparable.trans`: if `E / F` and `K / E` are both separable, then `K / F` is also separable.
## Tags
separable degree, degree, polynomial
-/
open scoped Classical Polynomial
open FiniteDimensional Polynomial IntermediateField Field
noncomputable section
universe u v w
variable (F : Type u) (E : Type v) [Field F] [Field E] [Algebra F E]
variable (K : Type w) [Field K] [Algebra F K]
namespace Field
/-- `Field.Emb F E` is the type of `F`-algebra homomorphisms from `E` to the algebraic closure
of `E`. -/
def Emb := E →ₐ[F] AlgebraicClosure E
/-- If `E / F` is an algebraic extension, then the (finite) separable degree of `E / F`
is the number of `F`-algebra homomorphisms from `E` to the algebraic closure of `E`,
as a natural number. It is defined to be zero if there are infinitely many of them.
Note that if `E / F` is not algebraic, then this definition makes no mathematical sense. -/
def finSepDegree : ℕ := Nat.card (Emb F E)
instance instInhabitedEmb : Inhabited (Emb F E) := ⟨IsScalarTower.toAlgHom F E _⟩
instance instNeZeroFinSepDegree [FiniteDimensional F E] : NeZero (finSepDegree F E) :=
⟨Nat.card_ne_zero.2 ⟨inferInstance, Fintype.finite <| minpoly.AlgHom.fintype _ _ _⟩⟩
/-- A random bijection between `Field.Emb F E` and `Field.Emb F K` when `E` and `K` are isomorphic
as `F`-algebras. -/
def embEquivOfEquiv (i : E ≃ₐ[F] K) :
Emb F E ≃ Emb F K := AlgEquiv.arrowCongr i <| AlgEquiv.symm <| by
let _ : Algebra E K := i.toAlgHom.toRingHom.toAlgebra
have : Algebra.IsAlgebraic E K := by
constructor
intro x
have h := isAlgebraic_algebraMap (R := E) (A := K) (i.symm.toAlgHom x)
rw [show ∀ y : E, (algebraMap E K) y = i.toAlgHom y from fun y ↦ rfl] at h
simpa only [AlgEquiv.toAlgHom_eq_coe, AlgHom.coe_coe, AlgEquiv.apply_symm_apply] using h
apply AlgEquiv.restrictScalars (R := F) (S := E)
exact IsAlgClosure.equivOfAlgebraic E K (AlgebraicClosure K) (AlgebraicClosure E)
/-- If `E` and `K` are isomorphic as `F`-algebras, then they have the same `Field.finSepDegree`
over `F`. -/
theorem finSepDegree_eq_of_equiv (i : E ≃ₐ[F] K) :
finSepDegree F E = finSepDegree F K := Nat.card_congr (embEquivOfEquiv F E K i)
@[simp]
theorem finSepDegree_self : finSepDegree F F = 1 := by
have : Cardinal.mk (Emb F F) = 1 := le_antisymm
(Cardinal.le_one_iff_subsingleton.2 AlgHom.subsingleton)
(Cardinal.one_le_iff_ne_zero.2 <| Cardinal.mk_ne_zero _)
rw [finSepDegree, Nat.card, this, Cardinal.one_toNat]
end Field
namespace IntermediateField
@[simp]
theorem finSepDegree_bot : finSepDegree F (⊥ : IntermediateField F E) = 1 := by
rw [finSepDegree_eq_of_equiv _ _ _ (botEquiv F E), finSepDegree_self]
section Tower
variable {F}
variable [Algebra E K] [IsScalarTower F E K]
@[simp]
theorem finSepDegree_bot' : finSepDegree F (⊥ : IntermediateField E K) = finSepDegree F E :=
finSepDegree_eq_of_equiv _ _ _ ((botEquiv E K).restrictScalars F)
@[simp]
theorem finSepDegree_top : finSepDegree F (⊤ : IntermediateField E K) = finSepDegree F K :=
finSepDegree_eq_of_equiv _ _ _ ((topEquiv (F := E) (E := K)).restrictScalars F)
end Tower
end IntermediateField
namespace Field
/-- A random bijection between `Field.Emb F E` and `E →ₐ[F] K` if `E = F(S)` such that every
element `s` of `S` is integral (= algebraic) over `F` and whose minimal polynomial splits in `K`.
Combined with `Field.instInhabitedEmb`, it can be viewed as a stronger version of
`IntermediateField.nonempty_algHom_of_adjoin_splits`. -/
def embEquivOfAdjoinSplits {S : Set E} (hS : adjoin F S = ⊤)
(hK : ∀ s ∈ S, IsIntegral F s ∧ Splits (algebraMap F K) (minpoly F s)) :
Emb F E ≃ (E →ₐ[F] K) :=
have : Algebra.IsAlgebraic F (⊤ : IntermediateField F E) :=
(hS ▸ isAlgebraic_adjoin (S := S) fun x hx ↦ (hK x hx).1)
have halg := (topEquiv (F := F) (E := E)).isAlgebraic
Classical.choice <| Function.Embedding.antisymm
(halg.algHomEmbeddingOfSplits (fun _ ↦ splits_of_mem_adjoin F (S := S) hK (hS ▸ mem_top)) _)
(halg.algHomEmbeddingOfSplits (fun _ ↦ IsAlgClosed.splits_codomain _) _)
/-- The `Field.finSepDegree F E` is equal to the cardinality of `E →ₐ[F] K`
if `E = F(S)` such that every element
`s` of `S` is integral (= algebraic) over `F` and whose minimal polynomial splits in `K`. -/
theorem finSepDegree_eq_of_adjoin_splits {S : Set E} (hS : adjoin F S = ⊤)
(hK : ∀ s ∈ S, IsIntegral F s ∧ Splits (algebraMap F K) (minpoly F s)) :
finSepDegree F E = Nat.card (E →ₐ[F] K) := Nat.card_congr (embEquivOfAdjoinSplits F E K hS hK)
/-- A random bijection between `Field.Emb F E` and `E →ₐ[F] K` when `E / F` is algebraic
and `K / F` is algebraically closed. -/
def embEquivOfIsAlgClosed [Algebra.IsAlgebraic F E] [IsAlgClosed K] :
Emb F E ≃ (E →ₐ[F] K) :=
embEquivOfAdjoinSplits F E K (adjoin_univ F E) fun s _ ↦
⟨Algebra.IsIntegral.isIntegral s, IsAlgClosed.splits_codomain _⟩
/-- The `Field.finSepDegree F E` is equal to the cardinality of `E →ₐ[F] K` as a natural number,
when `E / F` is algebraic and `K / F` is algebraically closed. -/
theorem finSepDegree_eq_of_isAlgClosed [Algebra.IsAlgebraic F E] [IsAlgClosed K] :
finSepDegree F E = Nat.card (E →ₐ[F] K) := Nat.card_congr (embEquivOfIsAlgClosed F E K)
/-- If `K / E / F` is a field extension tower, such that `K / E` is algebraic,
then there is a non-canonical bijection
`Field.Emb F E × Field.Emb E K ≃ Field.Emb F K`. A corollary of `algHomEquivSigma`. -/
def embProdEmbOfIsAlgebraic [Algebra E K] [IsScalarTower F E K] [Algebra.IsAlgebraic E K] :
Emb F E × Emb E K ≃ Emb F K :=
let e : ∀ f : E →ₐ[F] AlgebraicClosure K,
@AlgHom E K _ _ _ _ _ f.toRingHom.toAlgebra ≃ Emb E K := fun f ↦
(@embEquivOfIsAlgClosed E K _ _ _ _ _ f.toRingHom.toAlgebra).symm
(algHomEquivSigma (A := F) (B := E) (C := K) (D := AlgebraicClosure K) |>.trans
(Equiv.sigmaEquivProdOfEquiv e) |>.trans <| Equiv.prodCongrLeft <|
fun _ : Emb E K ↦ AlgEquiv.arrowCongr (@AlgEquiv.refl F E _ _ _) <|
(IsAlgClosure.equivOfAlgebraic E K (AlgebraicClosure K)
(AlgebraicClosure E)).restrictScalars F).symm
/-- If `K / E / F` is a field extension tower, such that `K / E` is algebraic, then their
separable degrees satisfy the tower law
$[E:F]_s [K:E]_s = [K:F]_s$. See also `FiniteDimensional.finrank_mul_finrank`. -/
theorem finSepDegree_mul_finSepDegree_of_isAlgebraic
[Algebra E K] [IsScalarTower F E K] [Algebra.IsAlgebraic E K] :
finSepDegree F E * finSepDegree E K = finSepDegree F K := by
simpa only [Nat.card_prod] using Nat.card_congr (embProdEmbOfIsAlgebraic F E K)
end Field
namespace Polynomial
variable {F E}
variable (f : F[X])
/-- The separable degree `Polynomial.natSepDegree` of a polynomial is a natural number,
defined to be the number of distinct roots of it over its splitting field.
This is similar to `Polynomial.natDegree` but not to `Polynomial.degree`, namely, the separable
degree of `0` is `0`, not negative infinity. -/
def natSepDegree : ℕ := (f.aroots f.SplittingField).toFinset.card
/-- The separable degree of a polynomial is smaller than its degree. -/
theorem natSepDegree_le_natDegree : f.natSepDegree ≤ f.natDegree := by
have := f.map (algebraMap F f.SplittingField) |>.card_roots'
rw [← aroots_def, natDegree_map] at this
exact (f.aroots f.SplittingField).toFinset_card_le.trans this
@[simp]
theorem natSepDegree_X_sub_C (x : F) : (X - C x).natSepDegree = 1 := by
simp only [natSepDegree, aroots_X_sub_C, Multiset.toFinset_singleton, Finset.card_singleton]
@[simp]
theorem natSepDegree_X : (X : F[X]).natSepDegree = 1 := by
simp only [natSepDegree, aroots_X, Multiset.toFinset_singleton, Finset.card_singleton]
/-- A constant polynomial has zero separable degree. -/
theorem natSepDegree_eq_zero (h : f.natDegree = 0) : f.natSepDegree = 0 := by
linarith only [natSepDegree_le_natDegree f, h]
@[simp]
theorem natSepDegree_C (x : F) : (C x).natSepDegree = 0 := natSepDegree_eq_zero _ (natDegree_C _)
@[simp]
theorem natSepDegree_zero : (0 : F[X]).natSepDegree = 0 := by
rw [← C_0, natSepDegree_C]
@[simp]
theorem natSepDegree_one : (1 : F[X]).natSepDegree = 0 := by
rw [← C_1, natSepDegree_C]
/-- A non-constant polynomial has non-zero separable degree. -/
theorem natSepDegree_ne_zero (h : f.natDegree ≠ 0) : f.natSepDegree ≠ 0 := by
rw [natSepDegree, ne_eq, Finset.card_eq_zero, ← ne_eq, ← Finset.nonempty_iff_ne_empty]
use rootOfSplits _ (SplittingField.splits f) (ne_of_apply_ne _ h)
rw [Multiset.mem_toFinset, mem_aroots]
exact ⟨ne_of_apply_ne _ h, map_rootOfSplits _ (SplittingField.splits f) (ne_of_apply_ne _ h)⟩
/-- A polynomial has zero separable degree if and only if it is constant. -/
theorem natSepDegree_eq_zero_iff : f.natSepDegree = 0 ↔ f.natDegree = 0 :=
⟨(natSepDegree_ne_zero f).mtr, natSepDegree_eq_zero f⟩
/-- A polynomial has non-zero separable degree if and only if it is non-constant. -/
theorem natSepDegree_ne_zero_iff : f.natSepDegree ≠ 0 ↔ f.natDegree ≠ 0 :=
Iff.not <| natSepDegree_eq_zero_iff f
/-- The separable degree of a non-zero polynomial is equal to its degree if and only if
it is separable. -/
theorem natSepDegree_eq_natDegree_iff (hf : f ≠ 0) :
f.natSepDegree = f.natDegree ↔ f.Separable := by
simp_rw [← card_rootSet_eq_natDegree_iff_of_splits hf (SplittingField.splits f),
rootSet_def, Finset.coe_sort_coe, Fintype.card_coe]
rfl
/-- If a polynomial is separable, then its separable degree is equal to its degree. -/
theorem natSepDegree_eq_natDegree_of_separable (h : f.Separable) :
f.natSepDegree = f.natDegree := (natSepDegree_eq_natDegree_iff f h.ne_zero).2 h
variable {f} in
/-- Same as `Polynomial.natSepDegree_eq_natDegree_of_separable`, but enables the use of
dot notation. -/
theorem Separable.natSepDegree_eq_natDegree (h : f.Separable) :
f.natSepDegree = f.natDegree := natSepDegree_eq_natDegree_of_separable f h
/-- If a polynomial splits over `E`, then its separable degree is equal to
the number of distinct roots of it over `E`. -/
| Mathlib/FieldTheory/SeparableDegree.lean | 333 | 337 | theorem natSepDegree_eq_of_splits (h : f.Splits (algebraMap F E)) :
f.natSepDegree = (f.aroots E).toFinset.card := by |
rw [aroots, ← (SplittingField.lift f h).comp_algebraMap, ← map_map,
roots_map _ ((splits_id_iff_splits _).mpr <| SplittingField.splits f),
Multiset.toFinset_map, Finset.card_image_of_injective _ (RingHom.injective _), natSepDegree]
|
/-
Copyright (c) 2020 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov, Moritz Doll
-/
import Mathlib.LinearAlgebra.Prod
#align_import linear_algebra.linear_pmap from "leanprover-community/mathlib"@"8b981918a93bc45a8600de608cde7944a80d92b9"
/-!
# Partially defined linear maps
A `LinearPMap R E F` or `E →ₗ.[R] F` is a linear map from a submodule of `E` to `F`.
We define a `SemilatticeInf` with `OrderBot` instance on this, and define three operations:
* `mkSpanSingleton` defines a partial linear map defined on the span of a singleton.
* `sup` takes two partial linear maps `f`, `g` that agree on the intersection of their
domains, and returns the unique partial linear map on `f.domain ⊔ g.domain` that
extends both `f` and `g`.
* `sSup` takes a `DirectedOn (· ≤ ·)` set of partial linear maps, and returns the unique
partial linear map on the `sSup` of their domains that extends all these maps.
Moreover, we define
* `LinearPMap.graph` is the graph of the partial linear map viewed as a submodule of `E × F`.
Partially defined maps are currently used in `Mathlib` to prove Hahn-Banach theorem
and its variations. Namely, `LinearPMap.sSup` implies that every chain of `LinearPMap`s
is bounded above.
They are also the basis for the theory of unbounded operators.
-/
universe u v w
/-- A `LinearPMap R E F` or `E →ₗ.[R] F` is a linear map from a submodule of `E` to `F`. -/
structure LinearPMap (R : Type u) [Ring R] (E : Type v) [AddCommGroup E] [Module R E] (F : Type w)
[AddCommGroup F] [Module R F] where
domain : Submodule R E
toFun : domain →ₗ[R] F
#align linear_pmap LinearPMap
@[inherit_doc] notation:25 E " →ₗ.[" R:25 "] " F:0 => LinearPMap R E F
variable {R : Type*} [Ring R] {E : Type*} [AddCommGroup E] [Module R E] {F : Type*}
[AddCommGroup F] [Module R F] {G : Type*} [AddCommGroup G] [Module R G]
namespace LinearPMap
open Submodule
-- Porting note: A new definition underlying a coercion `↑`.
@[coe]
def toFun' (f : E →ₗ.[R] F) : f.domain → F := f.toFun
instance : CoeFun (E →ₗ.[R] F) fun f : E →ₗ.[R] F => f.domain → F :=
⟨toFun'⟩
@[simp]
theorem toFun_eq_coe (f : E →ₗ.[R] F) (x : f.domain) : f.toFun x = f x :=
rfl
#align linear_pmap.to_fun_eq_coe LinearPMap.toFun_eq_coe
@[ext]
theorem ext {f g : E →ₗ.[R] F} (h : f.domain = g.domain)
(h' : ∀ ⦃x : f.domain⦄ ⦃y : g.domain⦄ (_h : (x : E) = y), f x = g y) : f = g := by
rcases f with ⟨f_dom, f⟩
rcases g with ⟨g_dom, g⟩
obtain rfl : f_dom = g_dom := h
obtain rfl : f = g := LinearMap.ext fun x => h' rfl
rfl
#align linear_pmap.ext LinearPMap.ext
@[simp]
theorem map_zero (f : E →ₗ.[R] F) : f 0 = 0 :=
f.toFun.map_zero
#align linear_pmap.map_zero LinearPMap.map_zero
theorem ext_iff {f g : E →ₗ.[R] F} :
f = g ↔
∃ _domain_eq : f.domain = g.domain,
∀ ⦃x : f.domain⦄ ⦃y : g.domain⦄ (_h : (x : E) = y), f x = g y :=
⟨fun EQ =>
EQ ▸
⟨rfl, fun x y h => by
congr
exact mod_cast h⟩,
fun ⟨deq, feq⟩ => ext deq feq⟩
#align linear_pmap.ext_iff LinearPMap.ext_iff
theorem ext' {s : Submodule R E} {f g : s →ₗ[R] F} (h : f = g) : mk s f = mk s g :=
h ▸ rfl
#align linear_pmap.ext' LinearPMap.ext'
theorem map_add (f : E →ₗ.[R] F) (x y : f.domain) : f (x + y) = f x + f y :=
f.toFun.map_add x y
#align linear_pmap.map_add LinearPMap.map_add
theorem map_neg (f : E →ₗ.[R] F) (x : f.domain) : f (-x) = -f x :=
f.toFun.map_neg x
#align linear_pmap.map_neg LinearPMap.map_neg
theorem map_sub (f : E →ₗ.[R] F) (x y : f.domain) : f (x - y) = f x - f y :=
f.toFun.map_sub x y
#align linear_pmap.map_sub LinearPMap.map_sub
theorem map_smul (f : E →ₗ.[R] F) (c : R) (x : f.domain) : f (c • x) = c • f x :=
f.toFun.map_smul c x
#align linear_pmap.map_smul LinearPMap.map_smul
@[simp]
theorem mk_apply (p : Submodule R E) (f : p →ₗ[R] F) (x : p) : mk p f x = f x :=
rfl
#align linear_pmap.mk_apply LinearPMap.mk_apply
/-- The unique `LinearPMap` on `R ∙ x` that sends `x` to `y`. This version works for modules
over rings, and requires a proof of `∀ c, c • x = 0 → c • y = 0`. -/
noncomputable def mkSpanSingleton' (x : E) (y : F) (H : ∀ c : R, c • x = 0 → c • y = 0) :
E →ₗ.[R] F where
domain := R ∙ x
toFun :=
have H : ∀ c₁ c₂ : R, c₁ • x = c₂ • x → c₁ • y = c₂ • y := by
intro c₁ c₂ h
rw [← sub_eq_zero, ← sub_smul] at h ⊢
exact H _ h
{ toFun := fun z => Classical.choose (mem_span_singleton.1 z.prop) • y
-- Porting note(#12129): additional beta reduction needed
-- Porting note: Were `Classical.choose_spec (mem_span_singleton.1 _)`.
map_add' := fun y z => by
beta_reduce
rw [← add_smul]
apply H
simp only [add_smul, sub_smul,
fun w : R ∙ x => Classical.choose_spec (mem_span_singleton.1 w.prop)]
apply coe_add
map_smul' := fun c z => by
beta_reduce
rw [smul_smul]
apply H
simp only [mul_smul,
fun w : R ∙ x => Classical.choose_spec (mem_span_singleton.1 w.prop)]
apply coe_smul }
#align linear_pmap.mk_span_singleton' LinearPMap.mkSpanSingleton'
@[simp]
theorem domain_mkSpanSingleton (x : E) (y : F) (H : ∀ c : R, c • x = 0 → c • y = 0) :
(mkSpanSingleton' x y H).domain = R ∙ x :=
rfl
#align linear_pmap.domain_mk_span_singleton LinearPMap.domain_mkSpanSingleton
@[simp]
theorem mkSpanSingleton'_apply (x : E) (y : F) (H : ∀ c : R, c • x = 0 → c • y = 0) (c : R) (h) :
mkSpanSingleton' x y H ⟨c • x, h⟩ = c • y := by
dsimp [mkSpanSingleton']
rw [← sub_eq_zero, ← sub_smul]
apply H
simp only [sub_smul, one_smul, sub_eq_zero]
apply Classical.choose_spec (mem_span_singleton.1 h)
#align linear_pmap.mk_span_singleton'_apply LinearPMap.mkSpanSingleton'_apply
@[simp]
theorem mkSpanSingleton'_apply_self (x : E) (y : F) (H : ∀ c : R, c • x = 0 → c • y = 0) (h) :
mkSpanSingleton' x y H ⟨x, h⟩ = y := by
-- Porting note: A placeholder should be specified before `convert`.
have := by refine mkSpanSingleton'_apply x y H 1 ?_; rwa [one_smul]
convert this <;> rw [one_smul]
#align linear_pmap.mk_span_singleton'_apply_self LinearPMap.mkSpanSingleton'_apply_self
/-- The unique `LinearPMap` on `span R {x}` that sends a non-zero vector `x` to `y`.
This version works for modules over division rings. -/
noncomputable abbrev mkSpanSingleton {K E F : Type*} [DivisionRing K] [AddCommGroup E] [Module K E]
[AddCommGroup F] [Module K F] (x : E) (y : F) (hx : x ≠ 0) : E →ₗ.[K] F :=
mkSpanSingleton' x y fun c hc =>
(smul_eq_zero.1 hc).elim (fun hc => by rw [hc, zero_smul]) fun hx' => absurd hx' hx
#align linear_pmap.mk_span_singleton LinearPMap.mkSpanSingleton
theorem mkSpanSingleton_apply (K : Type*) {E F : Type*} [DivisionRing K] [AddCommGroup E]
[Module K E] [AddCommGroup F] [Module K F] {x : E} (hx : x ≠ 0) (y : F) :
mkSpanSingleton x y hx ⟨x, (Submodule.mem_span_singleton_self x : x ∈ Submodule.span K {x})⟩ =
y :=
LinearPMap.mkSpanSingleton'_apply_self _ _ _ _
#align linear_pmap.mk_span_singleton_apply LinearPMap.mkSpanSingleton_apply
/-- Projection to the first coordinate as a `LinearPMap` -/
protected def fst (p : Submodule R E) (p' : Submodule R F) : E × F →ₗ.[R] E where
domain := p.prod p'
toFun := (LinearMap.fst R E F).comp (p.prod p').subtype
#align linear_pmap.fst LinearPMap.fst
@[simp]
theorem fst_apply (p : Submodule R E) (p' : Submodule R F) (x : p.prod p') :
LinearPMap.fst p p' x = (x : E × F).1 :=
rfl
#align linear_pmap.fst_apply LinearPMap.fst_apply
/-- Projection to the second coordinate as a `LinearPMap` -/
protected def snd (p : Submodule R E) (p' : Submodule R F) : E × F →ₗ.[R] F where
domain := p.prod p'
toFun := (LinearMap.snd R E F).comp (p.prod p').subtype
#align linear_pmap.snd LinearPMap.snd
@[simp]
theorem snd_apply (p : Submodule R E) (p' : Submodule R F) (x : p.prod p') :
LinearPMap.snd p p' x = (x : E × F).2 :=
rfl
#align linear_pmap.snd_apply LinearPMap.snd_apply
instance le : LE (E →ₗ.[R] F) :=
⟨fun f g => f.domain ≤ g.domain ∧ ∀ ⦃x : f.domain⦄ ⦃y : g.domain⦄ (_h : (x : E) = y), f x = g y⟩
#align linear_pmap.has_le LinearPMap.le
theorem apply_comp_inclusion {T S : E →ₗ.[R] F} (h : T ≤ S) (x : T.domain) :
T x = S (Submodule.inclusion h.1 x) :=
h.2 rfl
#align linear_pmap.apply_comp_of_le LinearPMap.apply_comp_inclusion
theorem exists_of_le {T S : E →ₗ.[R] F} (h : T ≤ S) (x : T.domain) :
∃ y : S.domain, (x : E) = y ∧ T x = S y :=
⟨⟨x.1, h.1 x.2⟩, ⟨rfl, h.2 rfl⟩⟩
#align linear_pmap.exists_of_le LinearPMap.exists_of_le
theorem eq_of_le_of_domain_eq {f g : E →ₗ.[R] F} (hle : f ≤ g) (heq : f.domain = g.domain) :
f = g :=
ext heq hle.2
#align linear_pmap.eq_of_le_of_domain_eq LinearPMap.eq_of_le_of_domain_eq
/-- Given two partial linear maps `f`, `g`, the set of points `x` such that
both `f` and `g` are defined at `x` and `f x = g x` form a submodule. -/
def eqLocus (f g : E →ₗ.[R] F) : Submodule R E where
carrier := { x | ∃ (hf : x ∈ f.domain) (hg : x ∈ g.domain), f ⟨x, hf⟩ = g ⟨x, hg⟩ }
zero_mem' := ⟨zero_mem _, zero_mem _, f.map_zero.trans g.map_zero.symm⟩
add_mem' := fun {x y} ⟨hfx, hgx, hx⟩ ⟨hfy, hgy, hy⟩ =>
⟨add_mem hfx hfy, add_mem hgx hgy, by
erw [f.map_add ⟨x, hfx⟩ ⟨y, hfy⟩, g.map_add ⟨x, hgx⟩ ⟨y, hgy⟩, hx, hy]⟩
-- Porting note: `by rintro` is required, or error of a free variable happens.
smul_mem' := by
rintro c x ⟨hfx, hgx, hx⟩
exact
⟨smul_mem _ c hfx, smul_mem _ c hgx,
by erw [f.map_smul c ⟨x, hfx⟩, g.map_smul c ⟨x, hgx⟩, hx]⟩
#align linear_pmap.eq_locus LinearPMap.eqLocus
instance inf : Inf (E →ₗ.[R] F) :=
⟨fun f g => ⟨f.eqLocus g, f.toFun.comp <| inclusion fun _x hx => hx.fst⟩⟩
#align linear_pmap.has_inf LinearPMap.inf
instance bot : Bot (E →ₗ.[R] F) :=
⟨⟨⊥, 0⟩⟩
#align linear_pmap.has_bot LinearPMap.bot
instance inhabited : Inhabited (E →ₗ.[R] F) :=
⟨⊥⟩
#align linear_pmap.inhabited LinearPMap.inhabited
instance semilatticeInf : SemilatticeInf (E →ₗ.[R] F) where
le := (· ≤ ·)
le_refl f := ⟨le_refl f.domain, fun x y h => Subtype.eq h ▸ rfl⟩
le_trans := fun f g h ⟨fg_le, fg_eq⟩ ⟨gh_le, gh_eq⟩ =>
⟨le_trans fg_le gh_le, fun x z hxz =>
have hxy : (x : E) = inclusion fg_le x := rfl
(fg_eq hxy).trans (gh_eq <| hxy.symm.trans hxz)⟩
le_antisymm f g fg gf := eq_of_le_of_domain_eq fg (le_antisymm fg.1 gf.1)
inf := (· ⊓ ·)
-- Porting note: `by rintro` is required, or error of a metavariable happens.
le_inf := by
rintro f g h ⟨fg_le, fg_eq⟩ ⟨fh_le, fh_eq⟩
exact ⟨fun x hx =>
⟨fg_le hx, fh_le hx, by
-- Porting note: `[exact ⟨x, hx⟩, rfl, rfl]` → `[skip, exact ⟨x, hx⟩, skip] <;> rfl`
convert (fg_eq _).symm.trans (fh_eq _) <;> [skip; exact ⟨x, hx⟩; skip] <;> rfl⟩,
fun x ⟨y, yg, hy⟩ h => by
apply fg_eq
exact h⟩
inf_le_left f g := ⟨fun x hx => hx.fst, fun x y h => congr_arg f <| Subtype.eq <| h⟩
inf_le_right f g :=
⟨fun x hx => hx.snd.fst, fun ⟨x, xf, xg, hx⟩ y h => hx.trans <| congr_arg g <| Subtype.eq <| h⟩
#align linear_pmap.semilattice_inf LinearPMap.semilatticeInf
instance orderBot : OrderBot (E →ₗ.[R] F) where
bot := ⊥
bot_le f :=
⟨bot_le, fun x y h => by
have hx : x = 0 := Subtype.eq ((mem_bot R).1 x.2)
have hy : y = 0 := Subtype.eq (h.symm.trans (congr_arg _ hx))
rw [hx, hy, map_zero, map_zero]⟩
#align linear_pmap.order_bot LinearPMap.orderBot
theorem le_of_eqLocus_ge {f g : E →ₗ.[R] F} (H : f.domain ≤ f.eqLocus g) : f ≤ g :=
suffices f ≤ f ⊓ g from le_trans this inf_le_right
⟨H, fun _x _y hxy => ((inf_le_left : f ⊓ g ≤ f).2 hxy.symm).symm⟩
#align linear_pmap.le_of_eq_locus_ge LinearPMap.le_of_eqLocus_ge
theorem domain_mono : StrictMono (@domain R _ E _ _ F _ _) := fun _f _g hlt =>
lt_of_le_of_ne hlt.1.1 fun heq => ne_of_lt hlt <| eq_of_le_of_domain_eq (le_of_lt hlt) heq
#align linear_pmap.domain_mono LinearPMap.domain_mono
private theorem sup_aux (f g : E →ₗ.[R] F)
(h : ∀ (x : f.domain) (y : g.domain), (x : E) = y → f x = g y) :
∃ fg : ↥(f.domain ⊔ g.domain) →ₗ[R] F,
∀ (x : f.domain) (y : g.domain) (z : ↥(f.domain ⊔ g.domain)),
(x : E) + y = ↑z → fg z = f x + g y := by
choose x hx y hy hxy using fun z : ↥(f.domain ⊔ g.domain) => mem_sup.1 z.prop
set fg := fun z => f ⟨x z, hx z⟩ + g ⟨y z, hy z⟩
have fg_eq : ∀ (x' : f.domain) (y' : g.domain) (z' : ↥(f.domain ⊔ g.domain))
(_H : (x' : E) + y' = z'), fg z' = f x' + g y' := by
intro x' y' z' H
dsimp [fg]
rw [add_comm, ← sub_eq_sub_iff_add_eq_add, eq_comm, ← map_sub, ← map_sub]
apply h
simp only [← eq_sub_iff_add_eq] at hxy
simp only [AddSubgroupClass.coe_sub, coe_mk, coe_mk, hxy, ← sub_add, ← sub_sub, sub_self,
zero_sub, ← H]
apply neg_add_eq_sub
use { toFun := fg, map_add' := ?_, map_smul' := ?_ }, fg_eq
· rintro ⟨z₁, hz₁⟩ ⟨z₂, hz₂⟩
rw [← add_assoc, add_right_comm (f _), ← map_add, add_assoc, ← map_add]
apply fg_eq
simp only [coe_add, coe_mk, ← add_assoc]
rw [add_right_comm (x _), hxy, add_assoc, hxy, coe_mk, coe_mk]
· intro c z
rw [smul_add, ← map_smul, ← map_smul]
apply fg_eq
simp only [coe_smul, coe_mk, ← smul_add, hxy, RingHom.id_apply]
/-- Given two partial linear maps that agree on the intersection of their domains,
`f.sup g h` is the unique partial linear map on `f.domain ⊔ g.domain` that agrees
with `f` and `g`. -/
protected noncomputable def sup (f g : E →ₗ.[R] F)
(h : ∀ (x : f.domain) (y : g.domain), (x : E) = y → f x = g y) : E →ₗ.[R] F :=
⟨_, Classical.choose (sup_aux f g h)⟩
#align linear_pmap.sup LinearPMap.sup
@[simp]
theorem domain_sup (f g : E →ₗ.[R] F)
(h : ∀ (x : f.domain) (y : g.domain), (x : E) = y → f x = g y) :
(f.sup g h).domain = f.domain ⊔ g.domain :=
rfl
#align linear_pmap.domain_sup LinearPMap.domain_sup
theorem sup_apply {f g : E →ₗ.[R] F} (H : ∀ (x : f.domain) (y : g.domain), (x : E) = y → f x = g y)
(x : f.domain) (y : g.domain) (z : ↥(f.domain ⊔ g.domain)) (hz : (↑x : E) + ↑y = ↑z) :
f.sup g H z = f x + g y :=
Classical.choose_spec (sup_aux f g H) x y z hz
#align linear_pmap.sup_apply LinearPMap.sup_apply
protected theorem left_le_sup (f g : E →ₗ.[R] F)
(h : ∀ (x : f.domain) (y : g.domain), (x : E) = y → f x = g y) : f ≤ f.sup g h := by
refine ⟨le_sup_left, fun z₁ z₂ hz => ?_⟩
rw [← add_zero (f _), ← g.map_zero]
refine (sup_apply h _ _ _ ?_).symm
simpa
#align linear_pmap.left_le_sup LinearPMap.left_le_sup
protected theorem right_le_sup (f g : E →ₗ.[R] F)
(h : ∀ (x : f.domain) (y : g.domain), (x : E) = y → f x = g y) : g ≤ f.sup g h := by
refine ⟨le_sup_right, fun z₁ z₂ hz => ?_⟩
rw [← zero_add (g _), ← f.map_zero]
refine (sup_apply h _ _ _ ?_).symm
simpa
#align linear_pmap.right_le_sup LinearPMap.right_le_sup
protected theorem sup_le {f g h : E →ₗ.[R] F}
(H : ∀ (x : f.domain) (y : g.domain), (x : E) = y → f x = g y) (fh : f ≤ h) (gh : g ≤ h) :
f.sup g H ≤ h :=
have Hf : f ≤ f.sup g H ⊓ h := le_inf (f.left_le_sup g H) fh
have Hg : g ≤ f.sup g H ⊓ h := le_inf (f.right_le_sup g H) gh
le_of_eqLocus_ge <| sup_le Hf.1 Hg.1
#align linear_pmap.sup_le LinearPMap.sup_le
/-- Hypothesis for `LinearPMap.sup` holds, if `f.domain` is disjoint with `g.domain`. -/
theorem sup_h_of_disjoint (f g : E →ₗ.[R] F) (h : Disjoint f.domain g.domain) (x : f.domain)
(y : g.domain) (hxy : (x : E) = y) : f x = g y := by
rw [disjoint_def] at h
have hy : y = 0 := Subtype.eq (h y (hxy ▸ x.2) y.2)
have hx : x = 0 := Subtype.eq (hxy.trans <| congr_arg _ hy)
simp [*]
#align linear_pmap.sup_h_of_disjoint LinearPMap.sup_h_of_disjoint
/-! ### Algebraic operations -/
section Zero
instance instZero : Zero (E →ₗ.[R] F) := ⟨⊤, 0⟩
@[simp]
theorem zero_domain : (0 : E →ₗ.[R] F).domain = ⊤ := rfl
@[simp]
theorem zero_apply (x : (⊤ : Submodule R E)) : (0 : E →ₗ.[R] F) x = 0 := rfl
end Zero
section SMul
variable {M N : Type*} [Monoid M] [DistribMulAction M F] [SMulCommClass R M F]
variable [Monoid N] [DistribMulAction N F] [SMulCommClass R N F]
instance instSMul : SMul M (E →ₗ.[R] F) :=
⟨fun a f =>
{ domain := f.domain
toFun := a • f.toFun }⟩
#align linear_pmap.has_smul LinearPMap.instSMul
@[simp]
theorem smul_domain (a : M) (f : E →ₗ.[R] F) : (a • f).domain = f.domain :=
rfl
#align linear_pmap.smul_domain LinearPMap.smul_domain
theorem smul_apply (a : M) (f : E →ₗ.[R] F) (x : (a • f).domain) : (a • f) x = a • f x :=
rfl
#align linear_pmap.smul_apply LinearPMap.smul_apply
@[simp]
theorem coe_smul (a : M) (f : E →ₗ.[R] F) : ⇑(a • f) = a • ⇑f :=
rfl
#align linear_pmap.coe_smul LinearPMap.coe_smul
instance instSMulCommClass [SMulCommClass M N F] : SMulCommClass M N (E →ₗ.[R] F) :=
⟨fun a b f => ext' <| smul_comm a b f.toFun⟩
#align linear_pmap.smul_comm_class LinearPMap.instSMulCommClass
instance instIsScalarTower [SMul M N] [IsScalarTower M N F] : IsScalarTower M N (E →ₗ.[R] F) :=
⟨fun a b f => ext' <| smul_assoc a b f.toFun⟩
#align linear_pmap.is_scalar_tower LinearPMap.instIsScalarTower
instance instMulAction : MulAction M (E →ₗ.[R] F) where
smul := (· • ·)
one_smul := fun ⟨_s, f⟩ => ext' <| one_smul M f
mul_smul a b f := ext' <| mul_smul a b f.toFun
#align linear_pmap.mul_action LinearPMap.instMulAction
end SMul
instance instNeg : Neg (E →ₗ.[R] F) :=
⟨fun f => ⟨f.domain, -f.toFun⟩⟩
#align linear_pmap.has_neg LinearPMap.instNeg
@[simp]
theorem neg_domain (f : E →ₗ.[R] F) : (-f).domain = f.domain := rfl
@[simp]
theorem neg_apply (f : E →ₗ.[R] F) (x) : (-f) x = -f x :=
rfl
#align linear_pmap.neg_apply LinearPMap.neg_apply
instance instInvolutiveNeg : InvolutiveNeg (E →ₗ.[R] F) :=
⟨fun f => by
ext x y hxy
· rfl
· simp only [neg_apply, neg_neg]
cases x
congr⟩
section Add
instance instAdd : Add (E →ₗ.[R] F) :=
⟨fun f g =>
{ domain := f.domain ⊓ g.domain
toFun := f.toFun.comp (inclusion (inf_le_left : f.domain ⊓ g.domain ≤ _))
+ g.toFun.comp (inclusion (inf_le_right : f.domain ⊓ g.domain ≤ _)) }⟩
theorem add_domain (f g : E →ₗ.[R] F) : (f + g).domain = f.domain ⊓ g.domain := rfl
theorem add_apply (f g : E →ₗ.[R] F) (x : (f.domain ⊓ g.domain : Submodule R E)) :
(f + g) x = f ⟨x, x.prop.1⟩ + g ⟨x, x.prop.2⟩ := rfl
instance instAddSemigroup : AddSemigroup (E →ₗ.[R] F) :=
⟨fun f g h => by
ext x y hxy
· simp only [add_domain, inf_assoc]
· simp only [add_apply, hxy, add_assoc]⟩
instance instAddZeroClass : AddZeroClass (E →ₗ.[R] F) :=
⟨fun f => by
ext x y hxy
· simp [add_domain]
· simp only [add_apply, hxy, zero_apply, zero_add],
fun f => by
ext x y hxy
· simp [add_domain]
· simp only [add_apply, hxy, zero_apply, add_zero]⟩
instance instAddMonoid : AddMonoid (E →ₗ.[R] F) where
zero_add f := by
simp
add_zero := by
simp
nsmul := nsmulRec
instance instAddCommMonoid : AddCommMonoid (E →ₗ.[R] F) :=
⟨fun f g => by
ext x y hxy
· simp only [add_domain, inf_comm]
· simp only [add_apply, hxy, add_comm]⟩
end Add
section VAdd
instance instVAdd : VAdd (E →ₗ[R] F) (E →ₗ.[R] F) :=
⟨fun f g =>
{ domain := g.domain
toFun := f.comp g.domain.subtype + g.toFun }⟩
#align linear_pmap.has_vadd LinearPMap.instVAdd
@[simp]
theorem vadd_domain (f : E →ₗ[R] F) (g : E →ₗ.[R] F) : (f +ᵥ g).domain = g.domain :=
rfl
#align linear_pmap.vadd_domain LinearPMap.vadd_domain
theorem vadd_apply (f : E →ₗ[R] F) (g : E →ₗ.[R] F) (x : (f +ᵥ g).domain) :
(f +ᵥ g) x = f x + g x :=
rfl
#align linear_pmap.vadd_apply LinearPMap.vadd_apply
@[simp]
theorem coe_vadd (f : E →ₗ[R] F) (g : E →ₗ.[R] F) : ⇑(f +ᵥ g) = ⇑(f.comp g.domain.subtype) + ⇑g :=
rfl
#align linear_pmap.coe_vadd LinearPMap.coe_vadd
instance instAddAction : AddAction (E →ₗ[R] F) (E →ₗ.[R] F) where
vadd := (· +ᵥ ·)
zero_vadd := fun ⟨_s, _f⟩ => ext' <| zero_add _
add_vadd := fun _f₁ _f₂ ⟨_s, _g⟩ => ext' <| LinearMap.ext fun _x => add_assoc _ _ _
#align linear_pmap.add_action LinearPMap.instAddAction
end VAdd
section Sub
instance instSub : Sub (E →ₗ.[R] F) :=
⟨fun f g =>
{ domain := f.domain ⊓ g.domain
toFun := f.toFun.comp (inclusion (inf_le_left : f.domain ⊓ g.domain ≤ _))
- g.toFun.comp (inclusion (inf_le_right : f.domain ⊓ g.domain ≤ _)) }⟩
theorem sub_domain (f g : E →ₗ.[R] F) : (f - g).domain = f.domain ⊓ g.domain := rfl
theorem sub_apply (f g : E →ₗ.[R] F) (x : (f.domain ⊓ g.domain : Submodule R E)) :
(f - g) x = f ⟨x, x.prop.1⟩ - g ⟨x, x.prop.2⟩ := rfl
instance instSubtractionCommMonoid : SubtractionCommMonoid (E →ₗ.[R] F) where
add_comm := add_comm
sub_eq_add_neg f g := by
ext x y h
· rfl
simp [sub_apply, add_apply, neg_apply, ← sub_eq_add_neg, h]
neg_neg := neg_neg
neg_add_rev f g := by
ext x y h
· simp [add_domain, sub_domain, neg_domain, And.comm]
simp [sub_apply, add_apply, neg_apply, ← sub_eq_add_neg, h]
neg_eq_of_add f g h' := by
ext x y h
· have : (0 : E →ₗ.[R] F).domain = ⊤ := zero_domain
simp only [← h', add_domain, ge_iff_le, inf_eq_top_iff] at this
rw [neg_domain, this.1, this.2]
simp only [inf_coe, neg_domain, Eq.ndrec, Int.ofNat_eq_coe, neg_apply]
rw [ext_iff] at h'
rcases h' with ⟨hdom, h'⟩
rw [zero_domain] at hdom
simp only [inf_coe, neg_domain, Eq.ndrec, Int.ofNat_eq_coe, zero_domain, top_coe, zero_apply,
Subtype.forall, mem_top, forall_true_left, forall_eq'] at h'
specialize h' x.1 (by simp [hdom])
simp only [inf_coe, neg_domain, Eq.ndrec, Int.ofNat_eq_coe, add_apply, Subtype.coe_eta,
← neg_eq_iff_add_eq_zero] at h'
rw [h', h]
zsmul := zsmulRec
end Sub
section
variable {K : Type*} [DivisionRing K] [Module K E] [Module K F]
/-- Extend a `LinearPMap` to `f.domain ⊔ K ∙ x`. -/
noncomputable def supSpanSingleton (f : E →ₗ.[K] F) (x : E) (y : F) (hx : x ∉ f.domain) :
E →ₗ.[K] F :=
-- Porting note: `simpa [..]` → `simp [..]; exact ..`
f.sup (mkSpanSingleton x y fun h₀ => hx <| h₀.symm ▸ f.domain.zero_mem) <|
sup_h_of_disjoint _ _ <| by simp [disjoint_span_singleton]; exact fun h => False.elim <| hx h
#align linear_pmap.sup_span_singleton LinearPMap.supSpanSingleton
@[simp]
theorem domain_supSpanSingleton (f : E →ₗ.[K] F) (x : E) (y : F) (hx : x ∉ f.domain) :
(f.supSpanSingleton x y hx).domain = f.domain ⊔ K ∙ x :=
rfl
#align linear_pmap.domain_sup_span_singleton LinearPMap.domain_supSpanSingleton
@[simp, nolint simpNF] -- Porting note: Left-hand side does not simplify.
theorem supSpanSingleton_apply_mk (f : E →ₗ.[K] F) (x : E) (y : F) (hx : x ∉ f.domain) (x' : E)
(hx' : x' ∈ f.domain) (c : K) :
f.supSpanSingleton x y hx
⟨x' + c • x, mem_sup.2 ⟨x', hx', _, mem_span_singleton.2 ⟨c, rfl⟩, rfl⟩⟩ =
f ⟨x', hx'⟩ + c • y := by
-- Porting note: `erw [..]; rfl; exact ..` → `erw [..]; exact ..; rfl`
-- That is, the order of the side goals generated by `erw` changed.
erw [sup_apply _ ⟨x', hx'⟩ ⟨c • x, _⟩, mkSpanSingleton'_apply]
· exact mem_span_singleton.2 ⟨c, rfl⟩
· rfl
#align linear_pmap.sup_span_singleton_apply_mk LinearPMap.supSpanSingleton_apply_mk
end
private theorem sSup_aux (c : Set (E →ₗ.[R] F)) (hc : DirectedOn (· ≤ ·) c) :
∃ f : ↥(sSup (domain '' c)) →ₗ[R] F, (⟨_, f⟩ : E →ₗ.[R] F) ∈ upperBounds c := by
rcases c.eq_empty_or_nonempty with ceq | cne
· subst c
simp
have hdir : DirectedOn (· ≤ ·) (domain '' c) :=
directedOn_image.2 (hc.mono @(domain_mono.monotone))
have P : ∀ x : ↥(sSup (domain '' c)), { p : c // (x : E) ∈ p.val.domain } := by
rintro x
apply Classical.indefiniteDescription
have := (mem_sSup_of_directed (cne.image _) hdir).1 x.2
-- Porting note: + `← bex_def`
rwa [Set.exists_mem_image, ← bex_def, SetCoe.exists'] at this
set f : ↥(sSup (domain '' c)) → F := fun x => (P x).val.val ⟨x, (P x).property⟩
have f_eq : ∀ (p : c) (x : ↥(sSup (domain '' c))) (y : p.1.1) (_hxy : (x : E) = y),
f x = p.1 y := by
intro p x y hxy
rcases hc (P x).1.1 (P x).1.2 p.1 p.2 with ⟨q, _hqc, hxq, hpq⟩
-- Porting note: `refine' ..; exacts [inclusion hpq.1 y, hxy, rfl]`
-- → `refine' .. <;> [skip; exact inclusion hpq.1 y; rfl]; exact hxy`
convert (hxq.2 _).trans (hpq.2 _).symm <;> [skip; exact inclusion hpq.1 y; rfl]; exact hxy
use { toFun := f, map_add' := ?_, map_smul' := ?_ }, ?_
· intro x y
rcases hc (P x).1.1 (P x).1.2 (P y).1.1 (P y).1.2 with ⟨p, hpc, hpx, hpy⟩
set x' := inclusion hpx.1 ⟨x, (P x).2⟩
set y' := inclusion hpy.1 ⟨y, (P y).2⟩
rw [f_eq ⟨p, hpc⟩ x x' rfl, f_eq ⟨p, hpc⟩ y y' rfl, f_eq ⟨p, hpc⟩ (x + y) (x' + y') rfl,
map_add]
· intro c x
simp only [RingHom.id_apply]
rw [f_eq (P x).1 (c • x) (c • ⟨x, (P x).2⟩) rfl, ← map_smul]
· intro p hpc
refine ⟨le_sSup <| Set.mem_image_of_mem domain hpc, fun x y hxy => Eq.symm ?_⟩
exact f_eq ⟨p, hpc⟩ _ _ hxy.symm
protected noncomputable def sSup (c : Set (E →ₗ.[R] F)) (hc : DirectedOn (· ≤ ·) c) : E →ₗ.[R] F :=
⟨_, Classical.choose <| sSup_aux c hc⟩
#align linear_pmap.Sup LinearPMap.sSup
protected theorem le_sSup {c : Set (E →ₗ.[R] F)} (hc : DirectedOn (· ≤ ·) c) {f : E →ₗ.[R] F}
(hf : f ∈ c) : f ≤ LinearPMap.sSup c hc :=
Classical.choose_spec (sSup_aux c hc) hf
#align linear_pmap.le_Sup LinearPMap.le_sSup
protected theorem sSup_le {c : Set (E →ₗ.[R] F)} (hc : DirectedOn (· ≤ ·) c) {g : E →ₗ.[R] F}
(hg : ∀ f ∈ c, f ≤ g) : LinearPMap.sSup c hc ≤ g :=
le_of_eqLocus_ge <|
sSup_le fun _ ⟨f, hf, Eq⟩ =>
Eq ▸
have : f ≤ LinearPMap.sSup c hc ⊓ g := le_inf (LinearPMap.le_sSup _ hf) (hg f hf)
this.1
#align linear_pmap.Sup_le LinearPMap.sSup_le
protected theorem sSup_apply {c : Set (E →ₗ.[R] F)} (hc : DirectedOn (· ≤ ·) c) {l : E →ₗ.[R] F}
(hl : l ∈ c) (x : l.domain) :
(LinearPMap.sSup c hc) ⟨x, (LinearPMap.le_sSup hc hl).1 x.2⟩ = l x := by
symm
apply (Classical.choose_spec (sSup_aux c hc) hl).2
rfl
#align linear_pmap.Sup_apply LinearPMap.sSup_apply
end LinearPMap
namespace LinearMap
/-- Restrict a linear map to a submodule, reinterpreting the result as a `LinearPMap`. -/
def toPMap (f : E →ₗ[R] F) (p : Submodule R E) : E →ₗ.[R] F :=
⟨p, f.comp p.subtype⟩
#align linear_map.to_pmap LinearMap.toPMap
@[simp]
theorem toPMap_apply (f : E →ₗ[R] F) (p : Submodule R E) (x : p) : f.toPMap p x = f x :=
rfl
#align linear_map.to_pmap_apply LinearMap.toPMap_apply
@[simp]
theorem toPMap_domain (f : E →ₗ[R] F) (p : Submodule R E) : (f.toPMap p).domain = p :=
rfl
#align linear_map.to_pmap_domain LinearMap.toPMap_domain
/-- Compose a linear map with a `LinearPMap` -/
def compPMap (g : F →ₗ[R] G) (f : E →ₗ.[R] F) : E →ₗ.[R] G where
domain := f.domain
toFun := g.comp f.toFun
#align linear_map.comp_pmap LinearMap.compPMap
@[simp]
theorem compPMap_apply (g : F →ₗ[R] G) (f : E →ₗ.[R] F) (x) : g.compPMap f x = g (f x) :=
rfl
#align linear_map.comp_pmap_apply LinearMap.compPMap_apply
end LinearMap
namespace LinearPMap
/-- Restrict codomain of a `LinearPMap` -/
def codRestrict (f : E →ₗ.[R] F) (p : Submodule R F) (H : ∀ x, f x ∈ p) : E →ₗ.[R] p where
domain := f.domain
toFun := f.toFun.codRestrict p H
#align linear_pmap.cod_restrict LinearPMap.codRestrict
/-- Compose two `LinearPMap`s -/
def comp (g : F →ₗ.[R] G) (f : E →ₗ.[R] F) (H : ∀ x : f.domain, f x ∈ g.domain) : E →ₗ.[R] G :=
g.toFun.compPMap <| f.codRestrict _ H
#align linear_pmap.comp LinearPMap.comp
/-- `f.coprod g` is the partially defined linear map defined on `f.domain × g.domain`,
and sending `p` to `f p.1 + g p.2`. -/
def coprod (f : E →ₗ.[R] G) (g : F →ₗ.[R] G) : E × F →ₗ.[R] G where
domain := f.domain.prod g.domain
toFun :=
-- Porting note: This is just
-- `(f.comp (LinearPMap.fst f.domain g.domain) fun x => x.2.1).toFun +`
-- ` (g.comp (LinearPMap.snd f.domain g.domain) fun x => x.2.2).toFun`,
HAdd.hAdd
(α := f.domain.prod g.domain →ₗ[R] G)
(β := f.domain.prod g.domain →ₗ[R] G)
(f.comp (LinearPMap.fst f.domain g.domain) fun x => x.2.1).toFun
(g.comp (LinearPMap.snd f.domain g.domain) fun x => x.2.2).toFun
#align linear_pmap.coprod LinearPMap.coprod
@[simp]
theorem coprod_apply (f : E →ₗ.[R] G) (g : F →ₗ.[R] G) (x) :
f.coprod g x = f ⟨(x : E × F).1, x.2.1⟩ + g ⟨(x : E × F).2, x.2.2⟩ :=
rfl
#align linear_pmap.coprod_apply LinearPMap.coprod_apply
/-- Restrict a partially defined linear map to a submodule of `E` contained in `f.domain`. -/
def domRestrict (f : E →ₗ.[R] F) (S : Submodule R E) : E →ₗ.[R] F :=
⟨S ⊓ f.domain, f.toFun.comp (Submodule.inclusion (by simp))⟩
#align linear_pmap.dom_restrict LinearPMap.domRestrict
@[simp]
theorem domRestrict_domain (f : E →ₗ.[R] F) {S : Submodule R E} :
(f.domRestrict S).domain = S ⊓ f.domain :=
rfl
#align linear_pmap.dom_restrict_domain LinearPMap.domRestrict_domain
theorem domRestrict_apply {f : E →ₗ.[R] F} {S : Submodule R E} ⦃x : ↥(S ⊓ f.domain)⦄ ⦃y : f.domain⦄
(h : (x : E) = y) : f.domRestrict S x = f y := by
have : Submodule.inclusion (by simp) x = y := by
ext
simp [h]
rw [← this]
exact LinearPMap.mk_apply _ _ _
#align linear_pmap.dom_restrict_apply LinearPMap.domRestrict_apply
theorem domRestrict_le {f : E →ₗ.[R] F} {S : Submodule R E} : f.domRestrict S ≤ f :=
⟨by simp, fun x y hxy => domRestrict_apply hxy⟩
#align linear_pmap.dom_restrict_le LinearPMap.domRestrict_le
/-! ### Graph -/
section Graph
/-- The graph of a `LinearPMap` viewed as a submodule on `E × F`. -/
def graph (f : E →ₗ.[R] F) : Submodule R (E × F) :=
f.toFun.graph.map (f.domain.subtype.prodMap (LinearMap.id : F →ₗ[R] F))
#align linear_pmap.graph LinearPMap.graph
theorem mem_graph_iff' (f : E →ₗ.[R] F) {x : E × F} :
x ∈ f.graph ↔ ∃ y : f.domain, (↑y, f y) = x := by simp [graph]
#align linear_pmap.mem_graph_iff' LinearPMap.mem_graph_iff'
@[simp]
| Mathlib/LinearAlgebra/LinearPMap.lean | 771 | 774 | theorem mem_graph_iff (f : E →ₗ.[R] F) {x : E × F} :
x ∈ f.graph ↔ ∃ y : f.domain, (↑y : E) = x.1 ∧ f y = x.2 := by |
cases x
simp_rw [mem_graph_iff', Prod.mk.inj_iff]
|
/-
Copyright (c) 2019 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov, Sébastien Gouëzel, Rémy Degenne
-/
import Mathlib.Analysis.Convex.Jensen
import Mathlib.Analysis.Convex.SpecificFunctions.Basic
import Mathlib.Analysis.SpecialFunctions.Pow.NNReal
import Mathlib.Data.Real.ConjExponents
#align_import analysis.mean_inequalities from "leanprover-community/mathlib"@"8f9fea08977f7e450770933ee6abb20733b47c92"
/-!
# Mean value inequalities
In this file we prove several inequalities for finite sums, including AM-GM inequality,
Young's inequality, Hölder inequality, and Minkowski inequality. Versions for integrals of some of
these inequalities are available in `MeasureTheory.MeanInequalities`.
## Main theorems
### AM-GM inequality:
The inequality says that the geometric mean of a tuple of non-negative numbers is less than or equal
to their arithmetic mean. We prove the weighted version of this inequality: if $w$ and $z$
are two non-negative vectors and $\sum_{i\in s} w_i=1$, then
$$
\prod_{i\in s} z_i^{w_i} ≤ \sum_{i\in s} w_iz_i.
$$
The classical version is a special case of this inequality for $w_i=\frac{1}{n}$.
We prove a few versions of this inequality. Each of the following lemmas comes in two versions:
a version for real-valued non-negative functions is in the `Real` namespace, and a version for
`NNReal`-valued functions is in the `NNReal` namespace.
- `geom_mean_le_arith_mean_weighted` : weighted version for functions on `Finset`s;
- `geom_mean_le_arith_mean2_weighted` : weighted version for two numbers;
- `geom_mean_le_arith_mean3_weighted` : weighted version for three numbers;
- `geom_mean_le_arith_mean4_weighted` : weighted version for four numbers.
### Young's inequality
Young's inequality says that for non-negative numbers `a`, `b`, `p`, `q` such that
$\frac{1}{p}+\frac{1}{q}=1$ we have
$$
ab ≤ \frac{a^p}{p} + \frac{b^q}{q}.
$$
This inequality is a special case of the AM-GM inequality. It is then used to prove Hölder's
inequality (see below).
### Hölder's inequality
The inequality says that for two conjugate exponents `p` and `q` (i.e., for two positive numbers
such that $\frac{1}{p}+\frac{1}{q}=1$) and any two non-negative vectors their inner product is
less than or equal to the product of the $L_p$ norm of the first vector and the $L_q$ norm of the
second vector:
$$
\sum_{i\in s} a_ib_i ≤ \sqrt[p]{\sum_{i\in s} a_i^p}\sqrt[q]{\sum_{i\in s} b_i^q}.
$$
We give versions of this result in `ℝ`, `ℝ≥0` and `ℝ≥0∞`.
There are at least two short proofs of this inequality. In our proof we prenormalize both vectors,
then apply Young's inequality to each $a_ib_i$. Another possible proof would be to deduce this
inequality from the generalized mean inequality for well-chosen vectors and weights.
### Minkowski's inequality
The inequality says that for `p ≥ 1` the function
$$
\|a\|_p=\sqrt[p]{\sum_{i\in s} a_i^p}
$$
satisfies the triangle inequality $\|a+b\|_p\le \|a\|_p+\|b\|_p$.
We give versions of this result in `Real`, `ℝ≥0` and `ℝ≥0∞`.
We deduce this inequality from Hölder's inequality. Namely, Hölder inequality implies that $\|a\|_p$
is the maximum of the inner product $\sum_{i\in s}a_ib_i$ over `b` such that $\|b\|_q\le 1$. Now
Minkowski's inequality follows from the fact that the maximum value of the sum of two functions is
less than or equal to the sum of the maximum values of the summands.
## TODO
- each inequality `A ≤ B` should come with a theorem `A = B ↔ _`; one of the ways to prove them
is to define `StrictConvexOn` functions.
- generalized mean inequality with any `p ≤ q`, including negative numbers;
- prove that the power mean tends to the geometric mean as the exponent tends to zero.
-/
universe u v
open scoped Classical
open Finset NNReal ENNReal
set_option linter.uppercaseLean3 false
noncomputable section
variable {ι : Type u} (s : Finset ι)
section GeomMeanLEArithMean
/-! ### AM-GM inequality -/
namespace Real
/-- **AM-GM inequality**: The geometric mean is less than or equal to the arithmetic mean, weighted
version for real-valued nonnegative functions. -/
theorem geom_mean_le_arith_mean_weighted (w z : ι → ℝ) (hw : ∀ i ∈ s, 0 ≤ w i)
(hw' : ∑ i ∈ s, w i = 1) (hz : ∀ i ∈ s, 0 ≤ z i) :
∏ i ∈ s, z i ^ w i ≤ ∑ i ∈ s, w i * z i := by
-- If some number `z i` equals zero and has non-zero weight, then LHS is 0 and RHS is nonnegative.
by_cases A : ∃ i ∈ s, z i = 0 ∧ w i ≠ 0
· rcases A with ⟨i, his, hzi, hwi⟩
rw [prod_eq_zero his]
· exact sum_nonneg fun j hj => mul_nonneg (hw j hj) (hz j hj)
· rw [hzi]
exact zero_rpow hwi
-- If all numbers `z i` with non-zero weight are positive, then we apply Jensen's inequality
-- for `exp` and numbers `log (z i)` with weights `w i`.
· simp only [not_exists, not_and, Ne, Classical.not_not] at A
have := convexOn_exp.map_sum_le hw hw' fun i _ => Set.mem_univ <| log (z i)
simp only [exp_sum, (· ∘ ·), smul_eq_mul, mul_comm (w _) (log _)] at this
convert this using 1 <;> [apply prod_congr rfl;apply sum_congr rfl] <;> intro i hi
· cases' eq_or_lt_of_le (hz i hi) with hz hz
· simp [A i hi hz.symm]
· exact rpow_def_of_pos hz _
· cases' eq_or_lt_of_le (hz i hi) with hz hz
· simp [A i hi hz.symm]
· rw [exp_log hz]
#align real.geom_mean_le_arith_mean_weighted Real.geom_mean_le_arith_mean_weighted
/-- **AM-GM inequality**: The **geometric mean is less than or equal to the arithmetic mean. --/
theorem geom_mean_le_arith_mean {ι : Type*} (s : Finset ι) (w : ι → ℝ) (z : ι → ℝ)
(hw : ∀ i ∈ s, 0 ≤ w i) (hw' : 0 < ∑ i ∈ s, w i) (hz : ∀ i ∈ s, 0 ≤ z i) :
(∏ i ∈ s, z i ^ w i) ^ (∑ i ∈ s, w i)⁻¹ ≤ (∑ i ∈ s, w i * z i) / (∑ i ∈ s, w i) := by
convert geom_mean_le_arith_mean_weighted s (fun i => (w i) / ∑ i ∈ s, w i) z ?_ ?_ hz using 2
· rw [← finset_prod_rpow _ _ (fun i hi => rpow_nonneg (hz _ hi) _) _]
refine Finset.prod_congr rfl (fun _ ih => ?_)
rw [div_eq_mul_inv, rpow_mul (hz _ ih)]
· simp_rw [div_eq_mul_inv, mul_assoc, mul_comm, ← mul_assoc, ← Finset.sum_mul, mul_comm]
· exact fun _ hi => div_nonneg (hw _ hi) (le_of_lt hw')
· simp_rw [div_eq_mul_inv, ← Finset.sum_mul]
exact mul_inv_cancel (by linarith)
theorem geom_mean_weighted_of_constant (w z : ι → ℝ) (x : ℝ) (hw : ∀ i ∈ s, 0 ≤ w i)
(hw' : ∑ i ∈ s, w i = 1) (hz : ∀ i ∈ s, 0 ≤ z i) (hx : ∀ i ∈ s, w i ≠ 0 → z i = x) :
∏ i ∈ s, z i ^ w i = x :=
calc
∏ i ∈ s, z i ^ w i = ∏ i ∈ s, x ^ w i := by
refine prod_congr rfl fun i hi => ?_
rcases eq_or_ne (w i) 0 with h₀ | h₀
· rw [h₀, rpow_zero, rpow_zero]
· rw [hx i hi h₀]
_ = x := by
rw [← rpow_sum_of_nonneg _ hw, hw', rpow_one]
have : (∑ i ∈ s, w i) ≠ 0 := by
rw [hw']
exact one_ne_zero
obtain ⟨i, his, hi⟩ := exists_ne_zero_of_sum_ne_zero this
rw [← hx i his hi]
exact hz i his
#align real.geom_mean_weighted_of_constant Real.geom_mean_weighted_of_constant
theorem arith_mean_weighted_of_constant (w z : ι → ℝ) (x : ℝ) (hw' : ∑ i ∈ s, w i = 1)
(hx : ∀ i ∈ s, w i ≠ 0 → z i = x) : ∑ i ∈ s, w i * z i = x :=
calc
∑ i ∈ s, w i * z i = ∑ i ∈ s, w i * x := by
refine sum_congr rfl fun i hi => ?_
rcases eq_or_ne (w i) 0 with hwi | hwi
· rw [hwi, zero_mul, zero_mul]
· rw [hx i hi hwi]
_ = x := by rw [← sum_mul, hw', one_mul]
#align real.arith_mean_weighted_of_constant Real.arith_mean_weighted_of_constant
theorem geom_mean_eq_arith_mean_weighted_of_constant (w z : ι → ℝ) (x : ℝ) (hw : ∀ i ∈ s, 0 ≤ w i)
(hw' : ∑ i ∈ s, w i = 1) (hz : ∀ i ∈ s, 0 ≤ z i) (hx : ∀ i ∈ s, w i ≠ 0 → z i = x) :
∏ i ∈ s, z i ^ w i = ∑ i ∈ s, w i * z i := by
rw [geom_mean_weighted_of_constant, arith_mean_weighted_of_constant] <;> assumption
#align real.geom_mean_eq_arith_mean_weighted_of_constant Real.geom_mean_eq_arith_mean_weighted_of_constant
end Real
namespace NNReal
/-- **AM-GM inequality**: The geometric mean is less than or equal to the arithmetic mean, weighted
version for `NNReal`-valued functions. -/
theorem geom_mean_le_arith_mean_weighted (w z : ι → ℝ≥0) (hw' : ∑ i ∈ s, w i = 1) :
(∏ i ∈ s, z i ^ (w i : ℝ)) ≤ ∑ i ∈ s, w i * z i :=
mod_cast
Real.geom_mean_le_arith_mean_weighted _ _ _ (fun i _ => (w i).coe_nonneg)
(by assumption_mod_cast) fun i _ => (z i).coe_nonneg
#align nnreal.geom_mean_le_arith_mean_weighted NNReal.geom_mean_le_arith_mean_weighted
/-- **AM-GM inequality**: The geometric mean is less than or equal to the arithmetic mean, weighted
version for two `NNReal` numbers. -/
theorem geom_mean_le_arith_mean2_weighted (w₁ w₂ p₁ p₂ : ℝ≥0) :
w₁ + w₂ = 1 → p₁ ^ (w₁ : ℝ) * p₂ ^ (w₂ : ℝ) ≤ w₁ * p₁ + w₂ * p₂ := by
simpa only [Fin.prod_univ_succ, Fin.sum_univ_succ, Finset.prod_empty, Finset.sum_empty,
Finset.univ_eq_empty, Fin.cons_succ, Fin.cons_zero, add_zero, mul_one] using
geom_mean_le_arith_mean_weighted univ ![w₁, w₂] ![p₁, p₂]
#align nnreal.geom_mean_le_arith_mean2_weighted NNReal.geom_mean_le_arith_mean2_weighted
theorem geom_mean_le_arith_mean3_weighted (w₁ w₂ w₃ p₁ p₂ p₃ : ℝ≥0) :
w₁ + w₂ + w₃ = 1 →
p₁ ^ (w₁ : ℝ) * p₂ ^ (w₂ : ℝ) * p₃ ^ (w₃ : ℝ) ≤ w₁ * p₁ + w₂ * p₂ + w₃ * p₃ := by
simpa only [Fin.prod_univ_succ, Fin.sum_univ_succ, Finset.prod_empty, Finset.sum_empty,
Finset.univ_eq_empty, Fin.cons_succ, Fin.cons_zero, add_zero, mul_one, ← add_assoc,
mul_assoc] using geom_mean_le_arith_mean_weighted univ ![w₁, w₂, w₃] ![p₁, p₂, p₃]
#align nnreal.geom_mean_le_arith_mean3_weighted NNReal.geom_mean_le_arith_mean3_weighted
theorem geom_mean_le_arith_mean4_weighted (w₁ w₂ w₃ w₄ p₁ p₂ p₃ p₄ : ℝ≥0) :
w₁ + w₂ + w₃ + w₄ = 1 →
p₁ ^ (w₁ : ℝ) * p₂ ^ (w₂ : ℝ) * p₃ ^ (w₃ : ℝ) * p₄ ^ (w₄ : ℝ) ≤
w₁ * p₁ + w₂ * p₂ + w₃ * p₃ + w₄ * p₄ := by
simpa only [Fin.prod_univ_succ, Fin.sum_univ_succ, Finset.prod_empty, Finset.sum_empty,
Finset.univ_eq_empty, Fin.cons_succ, Fin.cons_zero, add_zero, mul_one, ← add_assoc,
mul_assoc] using geom_mean_le_arith_mean_weighted univ ![w₁, w₂, w₃, w₄] ![p₁, p₂, p₃, p₄]
#align nnreal.geom_mean_le_arith_mean4_weighted NNReal.geom_mean_le_arith_mean4_weighted
end NNReal
namespace Real
theorem geom_mean_le_arith_mean2_weighted {w₁ w₂ p₁ p₂ : ℝ} (hw₁ : 0 ≤ w₁) (hw₂ : 0 ≤ w₂)
(hp₁ : 0 ≤ p₁) (hp₂ : 0 ≤ p₂) (hw : w₁ + w₂ = 1) : p₁ ^ w₁ * p₂ ^ w₂ ≤ w₁ * p₁ + w₂ * p₂ :=
NNReal.geom_mean_le_arith_mean2_weighted ⟨w₁, hw₁⟩ ⟨w₂, hw₂⟩ ⟨p₁, hp₁⟩ ⟨p₂, hp₂⟩ <|
NNReal.coe_inj.1 <| by assumption
#align real.geom_mean_le_arith_mean2_weighted Real.geom_mean_le_arith_mean2_weighted
theorem geom_mean_le_arith_mean3_weighted {w₁ w₂ w₃ p₁ p₂ p₃ : ℝ} (hw₁ : 0 ≤ w₁) (hw₂ : 0 ≤ w₂)
(hw₃ : 0 ≤ w₃) (hp₁ : 0 ≤ p₁) (hp₂ : 0 ≤ p₂) (hp₃ : 0 ≤ p₃) (hw : w₁ + w₂ + w₃ = 1) :
p₁ ^ w₁ * p₂ ^ w₂ * p₃ ^ w₃ ≤ w₁ * p₁ + w₂ * p₂ + w₃ * p₃ :=
NNReal.geom_mean_le_arith_mean3_weighted ⟨w₁, hw₁⟩ ⟨w₂, hw₂⟩ ⟨w₃, hw₃⟩ ⟨p₁, hp₁⟩ ⟨p₂, hp₂⟩
⟨p₃, hp₃⟩ <|
NNReal.coe_inj.1 hw
#align real.geom_mean_le_arith_mean3_weighted Real.geom_mean_le_arith_mean3_weighted
theorem geom_mean_le_arith_mean4_weighted {w₁ w₂ w₃ w₄ p₁ p₂ p₃ p₄ : ℝ} (hw₁ : 0 ≤ w₁)
(hw₂ : 0 ≤ w₂) (hw₃ : 0 ≤ w₃) (hw₄ : 0 ≤ w₄) (hp₁ : 0 ≤ p₁) (hp₂ : 0 ≤ p₂) (hp₃ : 0 ≤ p₃)
(hp₄ : 0 ≤ p₄) (hw : w₁ + w₂ + w₃ + w₄ = 1) :
p₁ ^ w₁ * p₂ ^ w₂ * p₃ ^ w₃ * p₄ ^ w₄ ≤ w₁ * p₁ + w₂ * p₂ + w₃ * p₃ + w₄ * p₄ :=
NNReal.geom_mean_le_arith_mean4_weighted ⟨w₁, hw₁⟩ ⟨w₂, hw₂⟩ ⟨w₃, hw₃⟩ ⟨w₄, hw₄⟩ ⟨p₁, hp₁⟩
⟨p₂, hp₂⟩ ⟨p₃, hp₃⟩ ⟨p₄, hp₄⟩ <|
NNReal.coe_inj.1 <| by assumption
#align real.geom_mean_le_arith_mean4_weighted Real.geom_mean_le_arith_mean4_weighted
end Real
end GeomMeanLEArithMean
section Young
/-! ### Young's inequality -/
namespace Real
/-- **Young's inequality**, a version for nonnegative real numbers. -/
theorem young_inequality_of_nonneg {a b p q : ℝ} (ha : 0 ≤ a) (hb : 0 ≤ b)
(hpq : p.IsConjExponent q) : a * b ≤ a ^ p / p + b ^ q / q := by
simpa [← rpow_mul, ha, hb, hpq.ne_zero, hpq.symm.ne_zero, _root_.div_eq_inv_mul] using
geom_mean_le_arith_mean2_weighted hpq.inv_nonneg hpq.symm.inv_nonneg
(rpow_nonneg ha p) (rpow_nonneg hb q) hpq.inv_add_inv_conj
#align real.young_inequality_of_nonneg Real.young_inequality_of_nonneg
/-- **Young's inequality**, a version for arbitrary real numbers. -/
theorem young_inequality (a b : ℝ) {p q : ℝ} (hpq : p.IsConjExponent q) :
a * b ≤ |a| ^ p / p + |b| ^ q / q :=
calc
a * b ≤ |a * b| := le_abs_self (a * b)
_ = |a| * |b| := abs_mul a b
_ ≤ |a| ^ p / p + |b| ^ q / q :=
Real.young_inequality_of_nonneg (abs_nonneg a) (abs_nonneg b) hpq
#align real.young_inequality Real.young_inequality
end Real
namespace NNReal
/-- **Young's inequality**, `ℝ≥0` version. We use `{p q : ℝ≥0}` in order to avoid constructing
witnesses of `0 ≤ p` and `0 ≤ q` for the denominators. -/
theorem young_inequality (a b : ℝ≥0) {p q : ℝ≥0} (hpq : p.IsConjExponent q) :
a * b ≤ a ^ (p : ℝ) / p + b ^ (q : ℝ) / q :=
Real.young_inequality_of_nonneg a.coe_nonneg b.coe_nonneg hpq.coe
#align nnreal.young_inequality NNReal.young_inequality
/-- **Young's inequality**, `ℝ≥0` version with real conjugate exponents. -/
theorem young_inequality_real (a b : ℝ≥0) {p q : ℝ} (hpq : p.IsConjExponent q) :
a * b ≤ a ^ p / Real.toNNReal p + b ^ q / Real.toNNReal q := by
simpa [Real.coe_toNNReal, hpq.nonneg, hpq.symm.nonneg] using young_inequality a b hpq.toNNReal
#align nnreal.young_inequality_real NNReal.young_inequality_real
end NNReal
namespace ENNReal
/-- **Young's inequality**, `ℝ≥0∞` version with real conjugate exponents. -/
theorem young_inequality (a b : ℝ≥0∞) {p q : ℝ} (hpq : p.IsConjExponent q) :
a * b ≤ a ^ p / ENNReal.ofReal p + b ^ q / ENNReal.ofReal q := by
by_cases h : a = ⊤ ∨ b = ⊤
· refine le_trans le_top (le_of_eq ?_)
repeat rw [div_eq_mul_inv]
cases' h with h h <;> rw [h] <;> simp [h, hpq.pos, hpq.symm.pos]
push_neg at h
-- if a ≠ ⊤ and b ≠ ⊤, use the nnreal version: nnreal.young_inequality_real
rw [← coe_toNNReal h.left, ← coe_toNNReal h.right, ← coe_mul, coe_rpow_of_nonneg _ hpq.nonneg,
coe_rpow_of_nonneg _ hpq.symm.nonneg, ENNReal.ofReal, ENNReal.ofReal, ←
@coe_div (Real.toNNReal p) _ (by simp [hpq.pos]), ←
@coe_div (Real.toNNReal q) _ (by simp [hpq.symm.pos]), ← coe_add, coe_le_coe]
exact NNReal.young_inequality_real a.toNNReal b.toNNReal hpq
#align ennreal.young_inequality ENNReal.young_inequality
end ENNReal
end Young
section HoelderMinkowski
/-! ### Hölder's and Minkowski's inequalities -/
namespace NNReal
private theorem inner_le_Lp_mul_Lp_of_norm_le_one (f g : ι → ℝ≥0) {p q : ℝ}
(hpq : p.IsConjExponent q) (hf : ∑ i ∈ s, f i ^ p ≤ 1) (hg : ∑ i ∈ s, g i ^ q ≤ 1) :
∑ i ∈ s, f i * g i ≤ 1 := by
have hp_ne_zero : Real.toNNReal p ≠ 0 := (zero_lt_one.trans hpq.toNNReal.one_lt).ne.symm
have hq_ne_zero : Real.toNNReal q ≠ 0 := (zero_lt_one.trans hpq.toNNReal.symm.one_lt).ne.symm
calc
∑ i ∈ s, f i * g i ≤ ∑ i ∈ s, (f i ^ p / Real.toNNReal p + g i ^ q / Real.toNNReal q) :=
Finset.sum_le_sum fun i _ => young_inequality_real (f i) (g i) hpq
_ = (∑ i ∈ s, f i ^ p) / Real.toNNReal p + (∑ i ∈ s, g i ^ q) / Real.toNNReal q := by
rw [sum_add_distrib, sum_div, sum_div]
_ ≤ 1 / Real.toNNReal p + 1 / Real.toNNReal q := by
refine add_le_add ?_ ?_
· rwa [div_le_iff hp_ne_zero, div_mul_cancel₀ _ hp_ne_zero]
· rwa [div_le_iff hq_ne_zero, div_mul_cancel₀ _ hq_ne_zero]
_ = 1 := by simp_rw [one_div, hpq.toNNReal.inv_add_inv_conj]
private theorem inner_le_Lp_mul_Lp_of_norm_eq_zero (f g : ι → ℝ≥0) {p q : ℝ}
(hpq : p.IsConjExponent q) (hf : ∑ i ∈ s, f i ^ p = 0) :
∑ i ∈ s, f i * g i ≤ (∑ i ∈ s, f i ^ p) ^ (1 / p) * (∑ i ∈ s, g i ^ q) ^ (1 / q) := by
simp only [hf, hpq.ne_zero, one_div, sum_eq_zero_iff, zero_rpow, zero_mul,
inv_eq_zero, Ne, not_false_iff, le_zero_iff, mul_eq_zero]
intro i his
left
rw [sum_eq_zero_iff] at hf
exact (rpow_eq_zero_iff.mp (hf i his)).left
/-- **Hölder inequality**: The scalar product of two functions is bounded by the product of their
`L^p` and `L^q` norms when `p` and `q` are conjugate exponents. Version for sums over finite sets,
with `ℝ≥0`-valued functions. -/
theorem inner_le_Lp_mul_Lq (f g : ι → ℝ≥0) {p q : ℝ} (hpq : p.IsConjExponent q) :
∑ i ∈ s, f i * g i ≤ (∑ i ∈ s, f i ^ p) ^ (1 / p) * (∑ i ∈ s, g i ^ q) ^ (1 / q) := by
by_cases hF_zero : ∑ i ∈ s, f i ^ p = 0
· exact inner_le_Lp_mul_Lp_of_norm_eq_zero s f g hpq hF_zero
by_cases hG_zero : ∑ i ∈ s, g i ^ q = 0
· calc
∑ i ∈ s, f i * g i = ∑ i ∈ s, g i * f i := by
congr with i
rw [mul_comm]
_ ≤ (∑ i ∈ s, g i ^ q) ^ (1 / q) * (∑ i ∈ s, f i ^ p) ^ (1 / p) :=
(inner_le_Lp_mul_Lp_of_norm_eq_zero s g f hpq.symm hG_zero)
_ = (∑ i ∈ s, f i ^ p) ^ (1 / p) * (∑ i ∈ s, g i ^ q) ^ (1 / q) := mul_comm _ _
let f' i := f i / (∑ i ∈ s, f i ^ p) ^ (1 / p)
let g' i := g i / (∑ i ∈ s, g i ^ q) ^ (1 / q)
suffices (∑ i ∈ s, f' i * g' i) ≤ 1 by
simp_rw [f', g', div_mul_div_comm, ← sum_div] at this
rwa [div_le_iff, one_mul] at this
refine mul_ne_zero ?_ ?_
· rw [Ne, rpow_eq_zero_iff, not_and_or]
exact Or.inl hF_zero
· rw [Ne, rpow_eq_zero_iff, not_and_or]
exact Or.inl hG_zero
refine inner_le_Lp_mul_Lp_of_norm_le_one s f' g' hpq (le_of_eq ?_) (le_of_eq ?_)
· simp_rw [f', div_rpow, ← sum_div, ← rpow_mul, one_div, inv_mul_cancel hpq.ne_zero, rpow_one,
div_self hF_zero]
· simp_rw [g', div_rpow, ← sum_div, ← rpow_mul, one_div, inv_mul_cancel hpq.symm.ne_zero,
rpow_one, div_self hG_zero]
#align nnreal.inner_le_Lp_mul_Lq NNReal.inner_le_Lp_mul_Lq
/-- **Weighted Hölder inequality**. -/
lemma inner_le_weight_mul_Lp (s : Finset ι) {p : ℝ} (hp : 1 ≤ p) (w f : ι → ℝ≥0) :
∑ i ∈ s, w i * f i ≤ (∑ i ∈ s, w i) ^ (1 - p⁻¹) * (∑ i ∈ s, w i * f i ^ p) ^ p⁻¹ := by
obtain rfl | hp := hp.eq_or_lt
· simp
calc
_ = ∑ i ∈ s, w i ^ (1 - p⁻¹) * (w i ^ p⁻¹ * f i) := ?_
_ ≤ (∑ i ∈ s, (w i ^ (1 - p⁻¹)) ^ (1 - p⁻¹)⁻¹) ^ (1 / (1 - p⁻¹)⁻¹) *
(∑ i ∈ s, (w i ^ p⁻¹ * f i) ^ p) ^ (1 / p) :=
inner_le_Lp_mul_Lq _ _ _ (.symm ⟨hp, by simp⟩)
_ = _ := ?_
· congr with i
rw [← mul_assoc, ← rpow_of_add_eq _ one_ne_zero, rpow_one]
simp
· have hp₀ : p ≠ 0 := by positivity
have hp₁ : 1 - p⁻¹ ≠ 0 := by simp [sub_eq_zero, hp.ne']
simp [mul_rpow, div_inv_eq_mul, one_mul, one_div, hp₀, hp₁]
/-- **Hölder inequality**: the scalar product of two functions is bounded by the product of their
`L^p` and `L^q` norms when `p` and `q` are conjugate exponents. A version for `NNReal`-valued
functions. For an alternative version, convenient if the infinite sums are already expressed as
`p`-th powers, see `inner_le_Lp_mul_Lq_hasSum`. -/
theorem inner_le_Lp_mul_Lq_tsum {f g : ι → ℝ≥0} {p q : ℝ} (hpq : p.IsConjExponent q)
(hf : Summable fun i => f i ^ p) (hg : Summable fun i => g i ^ q) :
(Summable fun i => f i * g i) ∧
∑' i, f i * g i ≤ (∑' i, f i ^ p) ^ (1 / p) * (∑' i, g i ^ q) ^ (1 / q) := by
have H₁ : ∀ s : Finset ι,
∑ i ∈ s, f i * g i ≤ (∑' i, f i ^ p) ^ (1 / p) * (∑' i, g i ^ q) ^ (1 / q) := by
intro s
refine le_trans (inner_le_Lp_mul_Lq s f g hpq) (mul_le_mul ?_ ?_ bot_le bot_le)
· rw [NNReal.rpow_le_rpow_iff (one_div_pos.mpr hpq.pos)]
exact sum_le_tsum _ (fun _ _ => zero_le _) hf
· rw [NNReal.rpow_le_rpow_iff (one_div_pos.mpr hpq.symm.pos)]
exact sum_le_tsum _ (fun _ _ => zero_le _) hg
have bdd : BddAbove (Set.range fun s => ∑ i ∈ s, f i * g i) := by
refine ⟨(∑' i, f i ^ p) ^ (1 / p) * (∑' i, g i ^ q) ^ (1 / q), ?_⟩
rintro a ⟨s, rfl⟩
exact H₁ s
have H₂ : Summable _ := (hasSum_of_isLUB _ (isLUB_ciSup bdd)).summable
exact ⟨H₂, tsum_le_of_sum_le H₂ H₁⟩
#align nnreal.inner_le_Lp_mul_Lq_tsum NNReal.inner_le_Lp_mul_Lq_tsum
theorem summable_mul_of_Lp_Lq {f g : ι → ℝ≥0} {p q : ℝ} (hpq : p.IsConjExponent q)
(hf : Summable fun i => f i ^ p) (hg : Summable fun i => g i ^ q) :
Summable fun i => f i * g i :=
(inner_le_Lp_mul_Lq_tsum hpq hf hg).1
#align nnreal.summable_mul_of_Lp_Lq NNReal.summable_mul_of_Lp_Lq
theorem inner_le_Lp_mul_Lq_tsum' {f g : ι → ℝ≥0} {p q : ℝ} (hpq : p.IsConjExponent q)
(hf : Summable fun i => f i ^ p) (hg : Summable fun i => g i ^ q) :
∑' i, f i * g i ≤ (∑' i, f i ^ p) ^ (1 / p) * (∑' i, g i ^ q) ^ (1 / q) :=
(inner_le_Lp_mul_Lq_tsum hpq hf hg).2
#align nnreal.inner_le_Lp_mul_Lq_tsum' NNReal.inner_le_Lp_mul_Lq_tsum'
/-- **Hölder inequality**: the scalar product of two functions is bounded by the product of their
`L^p` and `L^q` norms when `p` and `q` are conjugate exponents. A version for `NNReal`-valued
functions. For an alternative version, convenient if the infinite sums are not already expressed as
`p`-th powers, see `inner_le_Lp_mul_Lq_tsum`. -/
theorem inner_le_Lp_mul_Lq_hasSum {f g : ι → ℝ≥0} {A B : ℝ≥0} {p q : ℝ}
(hpq : p.IsConjExponent q) (hf : HasSum (fun i => f i ^ p) (A ^ p))
(hg : HasSum (fun i => g i ^ q) (B ^ q)) : ∃ C, C ≤ A * B ∧ HasSum (fun i => f i * g i) C := by
obtain ⟨H₁, H₂⟩ := inner_le_Lp_mul_Lq_tsum hpq hf.summable hg.summable
have hA : A = (∑' i : ι, f i ^ p) ^ (1 / p) := by rw [hf.tsum_eq, rpow_inv_rpow_self hpq.ne_zero]
have hB : B = (∑' i : ι, g i ^ q) ^ (1 / q) := by
rw [hg.tsum_eq, rpow_inv_rpow_self hpq.symm.ne_zero]
refine ⟨∑' i, f i * g i, ?_, ?_⟩
· simpa [hA, hB] using H₂
· simpa only [rpow_self_rpow_inv hpq.ne_zero] using H₁.hasSum
#align nnreal.inner_le_Lp_mul_Lq_has_sum NNReal.inner_le_Lp_mul_Lq_hasSum
/-- For `1 ≤ p`, the `p`-th power of the sum of `f i` is bounded above by a constant times the
sum of the `p`-th powers of `f i`. Version for sums over finite sets, with `ℝ≥0`-valued functions.
-/
theorem rpow_sum_le_const_mul_sum_rpow (f : ι → ℝ≥0) {p : ℝ} (hp : 1 ≤ p) :
(∑ i ∈ s, f i) ^ p ≤ (card s : ℝ≥0) ^ (p - 1) * ∑ i ∈ s, f i ^ p := by
cases' eq_or_lt_of_le hp with hp hp
· simp [← hp]
let q : ℝ := p / (p - 1)
have hpq : p.IsConjExponent q := .conjExponent hp
have hp₁ : 1 / p * p = 1 := one_div_mul_cancel hpq.ne_zero
have hq : 1 / q * p = p - 1 := by
rw [← hpq.div_conj_eq_sub_one]
ring
simpa only [NNReal.mul_rpow, ← NNReal.rpow_mul, hp₁, hq, one_mul, one_rpow, rpow_one,
Pi.one_apply, sum_const, Nat.smul_one_eq_cast] using
NNReal.rpow_le_rpow (inner_le_Lp_mul_Lq s 1 f hpq.symm) hpq.nonneg
#align nnreal.rpow_sum_le_const_mul_sum_rpow NNReal.rpow_sum_le_const_mul_sum_rpow
/-- The `L_p` seminorm of a vector `f` is the greatest value of the inner product
`∑ i ∈ s, f i * g i` over functions `g` of `L_q` seminorm less than or equal to one. -/
theorem isGreatest_Lp (f : ι → ℝ≥0) {p q : ℝ} (hpq : p.IsConjExponent q) :
IsGreatest ((fun g : ι → ℝ≥0 => ∑ i ∈ s, f i * g i) '' { g | ∑ i ∈ s, g i ^ q ≤ 1 })
((∑ i ∈ s, f i ^ p) ^ (1 / p)) := by
constructor
· use fun i => f i ^ p / f i / (∑ i ∈ s, f i ^ p) ^ (1 / q)
by_cases hf : ∑ i ∈ s, f i ^ p = 0
· simp [hf, hpq.ne_zero, hpq.symm.ne_zero]
· have A : p + q - q ≠ 0 := by simp [hpq.ne_zero]
have B : ∀ y : ℝ≥0, y * y ^ p / y = y ^ p := by
refine fun y => mul_div_cancel_left_of_imp fun h => ?_
simp [h, hpq.ne_zero]
simp only [Set.mem_setOf_eq, div_rpow, ← sum_div, ← rpow_mul,
div_mul_cancel₀ _ hpq.symm.ne_zero, rpow_one, div_le_iff hf, one_mul, hpq.mul_eq_add, ←
rpow_sub' _ A, add_sub_cancel_right, le_refl, true_and_iff, ← mul_div_assoc, B]
rw [div_eq_iff, ← rpow_add hf, one_div, one_div, hpq.inv_add_inv_conj, rpow_one]
simpa [hpq.symm.ne_zero] using hf
· rintro _ ⟨g, hg, rfl⟩
apply le_trans (inner_le_Lp_mul_Lq s f g hpq)
simpa only [mul_one] using
mul_le_mul_left' (NNReal.rpow_le_one hg (le_of_lt hpq.symm.one_div_pos)) _
#align nnreal.is_greatest_Lp NNReal.isGreatest_Lp
/-- **Minkowski inequality**: the `L_p` seminorm of the sum of two vectors is less than or equal
to the sum of the `L_p`-seminorms of the summands. A version for `NNReal`-valued functions. -/
theorem Lp_add_le (f g : ι → ℝ≥0) {p : ℝ} (hp : 1 ≤ p) :
(∑ i ∈ s, (f i + g i) ^ p) ^ (1 / p) ≤
(∑ i ∈ s, f i ^ p) ^ (1 / p) + (∑ i ∈ s, g i ^ p) ^ (1 / p) := by
-- The result is trivial when `p = 1`, so we can assume `1 < p`.
rcases eq_or_lt_of_le hp with (rfl | hp);
· simp [Finset.sum_add_distrib]
have hpq := Real.IsConjExponent.conjExponent hp
have := isGreatest_Lp s (f + g) hpq
simp only [Pi.add_apply, add_mul, sum_add_distrib] at this
rcases this.1 with ⟨φ, hφ, H⟩
rw [← H]
exact
add_le_add ((isGreatest_Lp s f hpq).2 ⟨φ, hφ, rfl⟩) ((isGreatest_Lp s g hpq).2 ⟨φ, hφ, rfl⟩)
#align nnreal.Lp_add_le NNReal.Lp_add_le
/-- **Minkowski inequality**: the `L_p` seminorm of the infinite sum of two vectors is less than or
equal to the infinite sum of the `L_p`-seminorms of the summands, if these infinite sums both
exist. A version for `NNReal`-valued functions. For an alternative version, convenient if the
infinite sums are already expressed as `p`-th powers, see `Lp_add_le_hasSum_of_nonneg`. -/
theorem Lp_add_le_tsum {f g : ι → ℝ≥0} {p : ℝ} (hp : 1 ≤ p) (hf : Summable fun i => f i ^ p)
(hg : Summable fun i => g i ^ p) :
(Summable fun i => (f i + g i) ^ p) ∧
(∑' i, (f i + g i) ^ p) ^ (1 / p) ≤
(∑' i, f i ^ p) ^ (1 / p) + (∑' i, g i ^ p) ^ (1 / p) := by
have pos : 0 < p := lt_of_lt_of_le zero_lt_one hp
have H₁ : ∀ s : Finset ι,
(∑ i ∈ s, (f i + g i) ^ p) ≤
((∑' i, f i ^ p) ^ (1 / p) + (∑' i, g i ^ p) ^ (1 / p)) ^ p := by
intro s
rw [← NNReal.rpow_one_div_le_iff pos]
refine le_trans (Lp_add_le s f g hp) (add_le_add ?_ ?_) <;>
rw [NNReal.rpow_le_rpow_iff (one_div_pos.mpr pos)] <;>
refine sum_le_tsum _ (fun _ _ => zero_le _) ?_
exacts [hf, hg]
have bdd : BddAbove (Set.range fun s => ∑ i ∈ s, (f i + g i) ^ p) := by
refine ⟨((∑' i, f i ^ p) ^ (1 / p) + (∑' i, g i ^ p) ^ (1 / p)) ^ p, ?_⟩
rintro a ⟨s, rfl⟩
exact H₁ s
have H₂ : Summable _ := (hasSum_of_isLUB _ (isLUB_ciSup bdd)).summable
refine ⟨H₂, ?_⟩
rw [NNReal.rpow_one_div_le_iff pos]
exact tsum_le_of_sum_le H₂ H₁
#align nnreal.Lp_add_le_tsum NNReal.Lp_add_le_tsum
theorem summable_Lp_add {f g : ι → ℝ≥0} {p : ℝ} (hp : 1 ≤ p) (hf : Summable fun i => f i ^ p)
(hg : Summable fun i => g i ^ p) : Summable fun i => (f i + g i) ^ p :=
(Lp_add_le_tsum hp hf hg).1
#align nnreal.summable_Lp_add NNReal.summable_Lp_add
theorem Lp_add_le_tsum' {f g : ι → ℝ≥0} {p : ℝ} (hp : 1 ≤ p) (hf : Summable fun i => f i ^ p)
(hg : Summable fun i => g i ^ p) :
(∑' i, (f i + g i) ^ p) ^ (1 / p) ≤ (∑' i, f i ^ p) ^ (1 / p) + (∑' i, g i ^ p) ^ (1 / p) :=
(Lp_add_le_tsum hp hf hg).2
#align nnreal.Lp_add_le_tsum' NNReal.Lp_add_le_tsum'
/-- **Minkowski inequality**: the `L_p` seminorm of the infinite sum of two vectors is less than or
equal to the infinite sum of the `L_p`-seminorms of the summands, if these infinite sums both
exist. A version for `NNReal`-valued functions. For an alternative version, convenient if the
infinite sums are not already expressed as `p`-th powers, see `Lp_add_le_tsum_of_nonneg`. -/
| Mathlib/Analysis/MeanInequalities.lean | 560 | 569 | theorem Lp_add_le_hasSum {f g : ι → ℝ≥0} {A B : ℝ≥0} {p : ℝ} (hp : 1 ≤ p)
(hf : HasSum (fun i => f i ^ p) (A ^ p)) (hg : HasSum (fun i => g i ^ p) (B ^ p)) :
∃ C, C ≤ A + B ∧ HasSum (fun i => (f i + g i) ^ p) (C ^ p) := by |
have hp' : p ≠ 0 := (lt_of_lt_of_le zero_lt_one hp).ne'
obtain ⟨H₁, H₂⟩ := Lp_add_le_tsum hp hf.summable hg.summable
have hA : A = (∑' i : ι, f i ^ p) ^ (1 / p) := by rw [hf.tsum_eq, rpow_inv_rpow_self hp']
have hB : B = (∑' i : ι, g i ^ p) ^ (1 / p) := by rw [hg.tsum_eq, rpow_inv_rpow_self hp']
refine ⟨(∑' i, (f i + g i) ^ p) ^ (1 / p), ?_, ?_⟩
· simpa [hA, hB] using H₂
· simpa only [rpow_self_rpow_inv hp'] using H₁.hasSum
|
/-
Copyright (c) 2017 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
-/
import Mathlib.Algebra.BigOperators.Group.Multiset
import Mathlib.Data.Multiset.Dedup
#align_import data.multiset.bind from "leanprover-community/mathlib"@"f694c7dead66f5d4c80f446c796a5aad14707f0e"
/-!
# Bind operation for multisets
This file defines a few basic operations on `Multiset`, notably the monadic bind.
## Main declarations
* `Multiset.join`: The join, aka union or sum, of multisets.
* `Multiset.bind`: The bind of a multiset-indexed family of multisets.
* `Multiset.product`: Cartesian product of two multisets.
* `Multiset.sigma`: Disjoint sum of multisets in a sigma type.
-/
assert_not_exists MonoidWithZero
assert_not_exists MulAction
universe v
variable {α : Type*} {β : Type v} {γ δ : Type*}
namespace Multiset
/-! ### Join -/
/-- `join S`, where `S` is a multiset of multisets, is the lift of the list join
operation, that is, the union of all the sets.
join {{1, 2}, {1, 2}, {0, 1}} = {0, 1, 1, 1, 2, 2} -/
def join : Multiset (Multiset α) → Multiset α :=
sum
#align multiset.join Multiset.join
theorem coe_join :
∀ L : List (List α), join (L.map ((↑) : List α → Multiset α) : Multiset (Multiset α)) = L.join
| [] => rfl
| l :: L => by
exact congr_arg (fun s : Multiset α => ↑l + s) (coe_join L)
#align multiset.coe_join Multiset.coe_join
@[simp]
theorem join_zero : @join α 0 = 0 :=
rfl
#align multiset.join_zero Multiset.join_zero
@[simp]
theorem join_cons (s S) : @join α (s ::ₘ S) = s + join S :=
sum_cons _ _
#align multiset.join_cons Multiset.join_cons
@[simp]
theorem join_add (S T) : @join α (S + T) = join S + join T :=
sum_add _ _
#align multiset.join_add Multiset.join_add
@[simp]
theorem singleton_join (a) : join ({a} : Multiset (Multiset α)) = a :=
sum_singleton _
#align multiset.singleton_join Multiset.singleton_join
@[simp]
theorem mem_join {a S} : a ∈ @join α S ↔ ∃ s ∈ S, a ∈ s :=
Multiset.induction_on S (by simp) <| by
simp (config := { contextual := true }) [or_and_right, exists_or]
#align multiset.mem_join Multiset.mem_join
@[simp]
theorem card_join (S) : card (@join α S) = sum (map card S) :=
Multiset.induction_on S (by simp) (by simp)
#align multiset.card_join Multiset.card_join
@[simp]
theorem map_join (f : α → β) (S : Multiset (Multiset α)) :
map f (join S) = join (map (map f) S) := by
induction S using Multiset.induction with
| empty => simp
| cons _ _ ih => simp [ih]
@[to_additive (attr := simp)]
theorem prod_join [CommMonoid α] {S : Multiset (Multiset α)} :
prod (join S) = prod (map prod S) := by
induction S using Multiset.induction with
| empty => simp
| cons _ _ ih => simp [ih]
theorem rel_join {r : α → β → Prop} {s t} (h : Rel (Rel r) s t) : Rel r s.join t.join := by
induction h with
| zero => simp
| cons hab hst ih => simpa using hab.add ih
#align multiset.rel_join Multiset.rel_join
/-! ### Bind -/
section Bind
variable (a : α) (s t : Multiset α) (f g : α → Multiset β)
/-- `s.bind f` is the monad bind operation, defined as `(s.map f).join`. It is the union of `f a` as
`a` ranges over `s`. -/
def bind (s : Multiset α) (f : α → Multiset β) : Multiset β :=
(s.map f).join
#align multiset.bind Multiset.bind
@[simp]
theorem coe_bind (l : List α) (f : α → List β) : (@bind α β l fun a => f a) = l.bind f := by
rw [List.bind, ← coe_join, List.map_map]
rfl
#align multiset.coe_bind Multiset.coe_bind
@[simp]
theorem zero_bind : bind 0 f = 0 :=
rfl
#align multiset.zero_bind Multiset.zero_bind
@[simp]
theorem cons_bind : (a ::ₘ s).bind f = f a + s.bind f := by simp [bind]
#align multiset.cons_bind Multiset.cons_bind
@[simp]
theorem singleton_bind : bind {a} f = f a := by simp [bind]
#align multiset.singleton_bind Multiset.singleton_bind
@[simp]
theorem add_bind : (s + t).bind f = s.bind f + t.bind f := by simp [bind]
#align multiset.add_bind Multiset.add_bind
@[simp]
theorem bind_zero : s.bind (fun _ => 0 : α → Multiset β) = 0 := by simp [bind, join, nsmul_zero]
#align multiset.bind_zero Multiset.bind_zero
@[simp]
theorem bind_add : (s.bind fun a => f a + g a) = s.bind f + s.bind g := by simp [bind, join]
#align multiset.bind_add Multiset.bind_add
@[simp]
theorem bind_cons (f : α → β) (g : α → Multiset β) :
(s.bind fun a => f a ::ₘ g a) = map f s + s.bind g :=
Multiset.induction_on s (by simp)
(by simp (config := { contextual := true }) [add_comm, add_left_comm, add_assoc])
#align multiset.bind_cons Multiset.bind_cons
@[simp]
theorem bind_singleton (f : α → β) : (s.bind fun x => ({f x} : Multiset β)) = map f s :=
Multiset.induction_on s (by rw [zero_bind, map_zero]) (by simp [singleton_add])
#align multiset.bind_singleton Multiset.bind_singleton
@[simp]
theorem mem_bind {b s} {f : α → Multiset β} : b ∈ bind s f ↔ ∃ a ∈ s, b ∈ f a := by
simp [bind]
#align multiset.mem_bind Multiset.mem_bind
@[simp]
theorem card_bind : card (s.bind f) = (s.map (card ∘ f)).sum := by simp [bind]
#align multiset.card_bind Multiset.card_bind
theorem bind_congr {f g : α → Multiset β} {m : Multiset α} :
(∀ a ∈ m, f a = g a) → bind m f = bind m g := by simp (config := { contextual := true }) [bind]
#align multiset.bind_congr Multiset.bind_congr
theorem bind_hcongr {β' : Type v} {m : Multiset α} {f : α → Multiset β} {f' : α → Multiset β'}
(h : β = β') (hf : ∀ a ∈ m, HEq (f a) (f' a)) : HEq (bind m f) (bind m f') := by
subst h
simp only [heq_eq_eq] at hf
simp [bind_congr hf]
#align multiset.bind_hcongr Multiset.bind_hcongr
theorem map_bind (m : Multiset α) (n : α → Multiset β) (f : β → γ) :
map f (bind m n) = bind m fun a => map f (n a) := by simp [bind]
#align multiset.map_bind Multiset.map_bind
theorem bind_map (m : Multiset α) (n : β → Multiset γ) (f : α → β) :
bind (map f m) n = bind m fun a => n (f a) :=
Multiset.induction_on m (by simp) (by simp (config := { contextual := true }))
#align multiset.bind_map Multiset.bind_map
theorem bind_assoc {s : Multiset α} {f : α → Multiset β} {g : β → Multiset γ} :
(s.bind f).bind g = s.bind fun a => (f a).bind g :=
Multiset.induction_on s (by simp) (by simp (config := { contextual := true }))
#align multiset.bind_assoc Multiset.bind_assoc
theorem bind_bind (m : Multiset α) (n : Multiset β) {f : α → β → Multiset γ} :
((bind m) fun a => (bind n) fun b => f a b) = (bind n) fun b => (bind m) fun a => f a b :=
Multiset.induction_on m (by simp) (by simp (config := { contextual := true }))
#align multiset.bind_bind Multiset.bind_bind
theorem bind_map_comm (m : Multiset α) (n : Multiset β) {f : α → β → γ} :
((bind m) fun a => n.map fun b => f a b) = (bind n) fun b => m.map fun a => f a b :=
Multiset.induction_on m (by simp) (by simp (config := { contextual := true }))
#align multiset.bind_map_comm Multiset.bind_map_comm
@[to_additive (attr := simp)]
theorem prod_bind [CommMonoid β] (s : Multiset α) (t : α → Multiset β) :
(s.bind t).prod = (s.map fun a => (t a).prod).prod := by simp [bind]
#align multiset.prod_bind Multiset.prod_bind
#align multiset.sum_bind Multiset.sum_bind
theorem rel_bind {r : α → β → Prop} {p : γ → δ → Prop} {s t} {f : α → Multiset γ}
{g : β → Multiset δ} (h : (r ⇒ Rel p) f g) (hst : Rel r s t) :
Rel p (s.bind f) (t.bind g) := by
apply rel_join
rw [rel_map]
exact hst.mono fun a _ b _ hr => h hr
#align multiset.rel_bind Multiset.rel_bind
theorem count_sum [DecidableEq α] {m : Multiset β} {f : β → Multiset α} {a : α} :
count a (map f m).sum = sum (m.map fun b => count a <| f b) :=
Multiset.induction_on m (by simp) (by simp)
#align multiset.count_sum Multiset.count_sum
theorem count_bind [DecidableEq α] {m : Multiset β} {f : β → Multiset α} {a : α} :
count a (bind m f) = sum (m.map fun b => count a <| f b) :=
count_sum
#align multiset.count_bind Multiset.count_bind
theorem le_bind {α β : Type*} {f : α → Multiset β} (S : Multiset α) {x : α} (hx : x ∈ S) :
f x ≤ S.bind f := by
classical
refine le_iff_count.2 fun a ↦ ?_
obtain ⟨m', hm'⟩ := exists_cons_of_mem $ mem_map_of_mem (fun b ↦ count a (f b)) hx
rw [count_bind, hm', sum_cons]
exact Nat.le_add_right _ _
#align multiset.le_bind Multiset.le_bind
-- Porting note (#11119): @[simp] removed because not in normal form
theorem attach_bind_coe (s : Multiset α) (f : α → Multiset β) :
(s.attach.bind fun i => f i) = s.bind f :=
congr_arg join <| attach_map_val' _ _
#align multiset.attach_bind_coe Multiset.attach_bind_coe
variable {f s t}
@[simp] lemma nodup_bind :
Nodup (bind s f) ↔ (∀ a ∈ s, Nodup (f a)) ∧ s.Pairwise fun a b => Disjoint (f a) (f b) := by
have : ∀ a, ∃ l : List β, f a = l := fun a => Quot.induction_on (f a) fun l => ⟨l, rfl⟩
choose f' h' using this
have : f = fun a ↦ ofList (f' a) := funext h'
have hd : Symmetric fun a b ↦ List.Disjoint (f' a) (f' b) := fun a b h ↦ h.symm
exact Quot.induction_on s <| by simp [this, List.nodup_bind, pairwise_coe_iff_pairwise hd]
#align multiset.nodup_bind Multiset.nodup_bind
@[simp]
lemma dedup_bind_dedup [DecidableEq α] [DecidableEq β] (s : Multiset α) (f : α → Multiset β) :
(s.dedup.bind f).dedup = (s.bind f).dedup := by
ext x
-- Porting note: was `simp_rw [count_dedup, mem_bind, mem_dedup]`
simp_rw [count_dedup]
refine if_congr ?_ rfl rfl
simp
#align multiset.dedup_bind_dedup Multiset.dedup_bind_dedup
end Bind
/-! ### Product of two multisets -/
section Product
variable (a : α) (b : β) (s : Multiset α) (t : Multiset β)
/-- The multiplicity of `(a, b)` in `s ×ˢ t` is
the product of the multiplicity of `a` in `s` and `b` in `t`. -/
def product (s : Multiset α) (t : Multiset β) : Multiset (α × β) :=
s.bind fun a => t.map <| Prod.mk a
#align multiset.product Multiset.product
instance instSProd : SProd (Multiset α) (Multiset β) (Multiset (α × β)) where
sprod := Multiset.product
@[simp]
theorem coe_product (l₁ : List α) (l₂ : List β) :
(l₁ : Multiset α) ×ˢ (l₂ : Multiset β) = (l₁ ×ˢ l₂) := by
dsimp only [SProd.sprod]
rw [product, List.product, ← coe_bind]
simp
#align multiset.coe_product Multiset.coe_product
@[simp]
theorem zero_product : (0 : Multiset α) ×ˢ t = 0 :=
rfl
#align multiset.zero_product Multiset.zero_product
@[simp]
theorem cons_product : (a ::ₘ s) ×ˢ t = map (Prod.mk a) t + s ×ˢ t := by simp [SProd.sprod, product]
#align multiset.cons_product Multiset.cons_product
@[simp]
theorem product_zero : s ×ˢ (0 : Multiset β) = 0 := by simp [SProd.sprod, product]
#align multiset.product_zero Multiset.product_zero
@[simp]
theorem product_cons : s ×ˢ (b ::ₘ t) = (s.map fun a => (a, b)) + s ×ˢ t := by
simp [SProd.sprod, product]
#align multiset.product_cons Multiset.product_cons
@[simp]
theorem product_singleton : ({a} : Multiset α) ×ˢ ({b} : Multiset β) = {(a, b)} := by
simp only [SProd.sprod, product, bind_singleton, map_singleton]
#align multiset.product_singleton Multiset.product_singleton
@[simp]
theorem add_product (s t : Multiset α) (u : Multiset β) : (s + t) ×ˢ u = s ×ˢ u + t ×ˢ u := by
simp [SProd.sprod, product]
#align multiset.add_product Multiset.add_product
@[simp]
theorem product_add (s : Multiset α) : ∀ t u : Multiset β, s ×ˢ (t + u) = s ×ˢ t + s ×ˢ u :=
Multiset.induction_on s (fun t u => rfl) fun a s IH t u => by
rw [cons_product, IH]
simp [add_comm, add_left_comm, add_assoc]
#align multiset.product_add Multiset.product_add
@[simp]
theorem card_product : card (s ×ˢ t) = card s * card t := by simp [SProd.sprod, product]
#align multiset.card_product Multiset.card_product
variable {s t}
@[simp] lemma mem_product : ∀ {p : α × β}, p ∈ @product α β s t ↔ p.1 ∈ s ∧ p.2 ∈ t
| (a, b) => by simp [product, and_left_comm]
#align multiset.mem_product Multiset.mem_product
protected theorem Nodup.product : Nodup s → Nodup t → Nodup (s ×ˢ t) :=
Quotient.inductionOn₂ s t fun l₁ l₂ d₁ d₂ => by simp [List.Nodup.product d₁ d₂]
#align multiset.nodup.product Multiset.Nodup.product
end Product
/-! ### Disjoint sum of multisets -/
section Sigma
variable {σ : α → Type*} (a : α) (s : Multiset α) (t : ∀ a, Multiset (σ a))
/-- `Multiset.sigma s t` is the dependent version of `Multiset.product`. It is the sum of
`(a, b)` as `a` ranges over `s` and `b` ranges over `t a`. -/
protected def sigma (s : Multiset α) (t : ∀ a, Multiset (σ a)) : Multiset (Σa, σ a) :=
s.bind fun a => (t a).map <| Sigma.mk a
#align multiset.sigma Multiset.sigma
@[simp]
| Mathlib/Data/Multiset/Bind.lean | 352 | 355 | theorem coe_sigma (l₁ : List α) (l₂ : ∀ a, List (σ a)) :
(@Multiset.sigma α σ l₁ fun a => l₂ a) = l₁.sigma l₂ := by |
rw [Multiset.sigma, List.sigma, ← coe_bind]
simp
|
/-
Copyright (c) 2020 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sébastien Gouëzel, Yury Kudryashov
-/
import Mathlib.Analysis.Calculus.FormalMultilinearSeries
import Mathlib.Analysis.SpecificLimits.Normed
import Mathlib.Logic.Equiv.Fin
import Mathlib.Topology.Algebra.InfiniteSum.Module
#align_import analysis.analytic.basic from "leanprover-community/mathlib"@"32253a1a1071173b33dc7d6a218cf722c6feb514"
/-!
# Analytic functions
A function is analytic in one dimension around `0` if it can be written as a converging power series
`Σ pₙ zⁿ`. This definition can be extended to any dimension (even in infinite dimension) by
requiring that `pₙ` is a continuous `n`-multilinear map. In general, `pₙ` is not unique (in two
dimensions, taking `p₂ (x, y) (x', y') = x y'` or `y x'` gives the same map when applied to a
vector `(x, y) (x, y)`). A way to guarantee uniqueness is to take a symmetric `pₙ`, but this is not
always possible in nonzero characteristic (in characteristic 2, the previous example has no
symmetric representative). Therefore, we do not insist on symmetry or uniqueness in the definition,
and we only require the existence of a converging series.
The general framework is important to say that the exponential map on bounded operators on a Banach
space is analytic, as well as the inverse on invertible operators.
## Main definitions
Let `p` be a formal multilinear series from `E` to `F`, i.e., `p n` is a multilinear map on `E^n`
for `n : ℕ`.
* `p.radius`: the largest `r : ℝ≥0∞` such that `‖p n‖ * r^n` grows subexponentially.
* `p.le_radius_of_bound`, `p.le_radius_of_bound_nnreal`, `p.le_radius_of_isBigO`: if `‖p n‖ * r ^ n`
is bounded above, then `r ≤ p.radius`;
* `p.isLittleO_of_lt_radius`, `p.norm_mul_pow_le_mul_pow_of_lt_radius`,
`p.isLittleO_one_of_lt_radius`,
`p.norm_mul_pow_le_of_lt_radius`, `p.nnnorm_mul_pow_le_of_lt_radius`: if `r < p.radius`, then
`‖p n‖ * r ^ n` tends to zero exponentially;
* `p.lt_radius_of_isBigO`: if `r ≠ 0` and `‖p n‖ * r ^ n = O(a ^ n)` for some `-1 < a < 1`, then
`r < p.radius`;
* `p.partialSum n x`: the sum `∑_{i = 0}^{n-1} pᵢ xⁱ`.
* `p.sum x`: the sum `∑'_{i = 0}^{∞} pᵢ xⁱ`.
Additionally, let `f` be a function from `E` to `F`.
* `HasFPowerSeriesOnBall f p x r`: on the ball of center `x` with radius `r`,
`f (x + y) = ∑'_n pₙ yⁿ`.
* `HasFPowerSeriesAt f p x`: on some ball of center `x` with positive radius, holds
`HasFPowerSeriesOnBall f p x r`.
* `AnalyticAt 𝕜 f x`: there exists a power series `p` such that holds `HasFPowerSeriesAt f p x`.
* `AnalyticOn 𝕜 f s`: the function `f` is analytic at every point of `s`.
We develop the basic properties of these notions, notably:
* If a function admits a power series, it is continuous (see
`HasFPowerSeriesOnBall.continuousOn` and `HasFPowerSeriesAt.continuousAt` and
`AnalyticAt.continuousAt`).
* In a complete space, the sum of a formal power series with positive radius is well defined on the
disk of convergence, see `FormalMultilinearSeries.hasFPowerSeriesOnBall`.
* If a function admits a power series in a ball, then it is analytic at any point `y` of this ball,
and the power series there can be expressed in terms of the initial power series `p` as
`p.changeOrigin y`. See `HasFPowerSeriesOnBall.changeOrigin`. It follows in particular that
the set of points at which a given function is analytic is open, see `isOpen_analyticAt`.
## Implementation details
We only introduce the radius of convergence of a power series, as `p.radius`.
For a power series in finitely many dimensions, there is a finer (directional, coordinate-dependent)
notion, describing the polydisk of convergence. This notion is more specific, and not necessary to
build the general theory. We do not define it here.
-/
noncomputable section
variable {𝕜 E F G : Type*}
open scoped Classical
open Topology NNReal Filter ENNReal
open Set Filter Asymptotics
namespace FormalMultilinearSeries
variable [Ring 𝕜] [AddCommGroup E] [AddCommGroup F] [Module 𝕜 E] [Module 𝕜 F]
variable [TopologicalSpace E] [TopologicalSpace F]
variable [TopologicalAddGroup E] [TopologicalAddGroup F]
variable [ContinuousConstSMul 𝕜 E] [ContinuousConstSMul 𝕜 F]
/-- Given a formal multilinear series `p` and a vector `x`, then `p.sum x` is the sum `Σ pₙ xⁿ`. A
priori, it only behaves well when `‖x‖ < p.radius`. -/
protected def sum (p : FormalMultilinearSeries 𝕜 E F) (x : E) : F :=
∑' n : ℕ, p n fun _ => x
#align formal_multilinear_series.sum FormalMultilinearSeries.sum
/-- Given a formal multilinear series `p` and a vector `x`, then `p.partialSum n x` is the sum
`Σ pₖ xᵏ` for `k ∈ {0,..., n-1}`. -/
def partialSum (p : FormalMultilinearSeries 𝕜 E F) (n : ℕ) (x : E) : F :=
∑ k ∈ Finset.range n, p k fun _ : Fin k => x
#align formal_multilinear_series.partial_sum FormalMultilinearSeries.partialSum
/-- The partial sums of a formal multilinear series are continuous. -/
theorem partialSum_continuous (p : FormalMultilinearSeries 𝕜 E F) (n : ℕ) :
Continuous (p.partialSum n) := by
unfold partialSum -- Porting note: added
continuity
#align formal_multilinear_series.partial_sum_continuous FormalMultilinearSeries.partialSum_continuous
end FormalMultilinearSeries
/-! ### The radius of a formal multilinear series -/
variable [NontriviallyNormedField 𝕜] [NormedAddCommGroup E] [NormedSpace 𝕜 E] [NormedAddCommGroup F]
[NormedSpace 𝕜 F] [NormedAddCommGroup G] [NormedSpace 𝕜 G]
namespace FormalMultilinearSeries
variable (p : FormalMultilinearSeries 𝕜 E F) {r : ℝ≥0}
/-- The radius of a formal multilinear series is the largest `r` such that the sum `Σ ‖pₙ‖ ‖y‖ⁿ`
converges for all `‖y‖ < r`. This implies that `Σ pₙ yⁿ` converges for all `‖y‖ < r`, but these
definitions are *not* equivalent in general. -/
def radius (p : FormalMultilinearSeries 𝕜 E F) : ℝ≥0∞ :=
⨆ (r : ℝ≥0) (C : ℝ) (_ : ∀ n, ‖p n‖ * (r : ℝ) ^ n ≤ C), (r : ℝ≥0∞)
#align formal_multilinear_series.radius FormalMultilinearSeries.radius
/-- If `‖pₙ‖ rⁿ` is bounded in `n`, then the radius of `p` is at least `r`. -/
theorem le_radius_of_bound (C : ℝ) {r : ℝ≥0} (h : ∀ n : ℕ, ‖p n‖ * (r : ℝ) ^ n ≤ C) :
(r : ℝ≥0∞) ≤ p.radius :=
le_iSup_of_le r <| le_iSup_of_le C <| le_iSup (fun _ => (r : ℝ≥0∞)) h
#align formal_multilinear_series.le_radius_of_bound FormalMultilinearSeries.le_radius_of_bound
/-- If `‖pₙ‖ rⁿ` is bounded in `n`, then the radius of `p` is at least `r`. -/
theorem le_radius_of_bound_nnreal (C : ℝ≥0) {r : ℝ≥0} (h : ∀ n : ℕ, ‖p n‖₊ * r ^ n ≤ C) :
(r : ℝ≥0∞) ≤ p.radius :=
p.le_radius_of_bound C fun n => mod_cast h n
#align formal_multilinear_series.le_radius_of_bound_nnreal FormalMultilinearSeries.le_radius_of_bound_nnreal
/-- If `‖pₙ‖ rⁿ = O(1)`, as `n → ∞`, then the radius of `p` is at least `r`. -/
theorem le_radius_of_isBigO (h : (fun n => ‖p n‖ * (r : ℝ) ^ n) =O[atTop] fun _ => (1 : ℝ)) :
↑r ≤ p.radius :=
Exists.elim (isBigO_one_nat_atTop_iff.1 h) fun C hC =>
p.le_radius_of_bound C fun n => (le_abs_self _).trans (hC n)
set_option linter.uppercaseLean3 false in
#align formal_multilinear_series.le_radius_of_is_O FormalMultilinearSeries.le_radius_of_isBigO
theorem le_radius_of_eventually_le (C) (h : ∀ᶠ n in atTop, ‖p n‖ * (r : ℝ) ^ n ≤ C) :
↑r ≤ p.radius :=
p.le_radius_of_isBigO <| IsBigO.of_bound C <| h.mono fun n hn => by simpa
#align formal_multilinear_series.le_radius_of_eventually_le FormalMultilinearSeries.le_radius_of_eventually_le
theorem le_radius_of_summable_nnnorm (h : Summable fun n => ‖p n‖₊ * r ^ n) : ↑r ≤ p.radius :=
p.le_radius_of_bound_nnreal (∑' n, ‖p n‖₊ * r ^ n) fun _ => le_tsum' h _
#align formal_multilinear_series.le_radius_of_summable_nnnorm FormalMultilinearSeries.le_radius_of_summable_nnnorm
theorem le_radius_of_summable (h : Summable fun n => ‖p n‖ * (r : ℝ) ^ n) : ↑r ≤ p.radius :=
p.le_radius_of_summable_nnnorm <| by
simp only [← coe_nnnorm] at h
exact mod_cast h
#align formal_multilinear_series.le_radius_of_summable FormalMultilinearSeries.le_radius_of_summable
theorem radius_eq_top_of_forall_nnreal_isBigO
(h : ∀ r : ℝ≥0, (fun n => ‖p n‖ * (r : ℝ) ^ n) =O[atTop] fun _ => (1 : ℝ)) : p.radius = ∞ :=
ENNReal.eq_top_of_forall_nnreal_le fun r => p.le_radius_of_isBigO (h r)
set_option linter.uppercaseLean3 false in
#align formal_multilinear_series.radius_eq_top_of_forall_nnreal_is_O FormalMultilinearSeries.radius_eq_top_of_forall_nnreal_isBigO
theorem radius_eq_top_of_eventually_eq_zero (h : ∀ᶠ n in atTop, p n = 0) : p.radius = ∞ :=
p.radius_eq_top_of_forall_nnreal_isBigO fun r =>
(isBigO_zero _ _).congr' (h.mono fun n hn => by simp [hn]) EventuallyEq.rfl
#align formal_multilinear_series.radius_eq_top_of_eventually_eq_zero FormalMultilinearSeries.radius_eq_top_of_eventually_eq_zero
theorem radius_eq_top_of_forall_image_add_eq_zero (n : ℕ) (hn : ∀ m, p (m + n) = 0) :
p.radius = ∞ :=
p.radius_eq_top_of_eventually_eq_zero <|
mem_atTop_sets.2 ⟨n, fun _ hk => tsub_add_cancel_of_le hk ▸ hn _⟩
#align formal_multilinear_series.radius_eq_top_of_forall_image_add_eq_zero FormalMultilinearSeries.radius_eq_top_of_forall_image_add_eq_zero
@[simp]
theorem constFormalMultilinearSeries_radius {v : F} :
(constFormalMultilinearSeries 𝕜 E v).radius = ⊤ :=
(constFormalMultilinearSeries 𝕜 E v).radius_eq_top_of_forall_image_add_eq_zero 1
(by simp [constFormalMultilinearSeries])
#align formal_multilinear_series.const_formal_multilinear_series_radius FormalMultilinearSeries.constFormalMultilinearSeries_radius
/-- For `r` strictly smaller than the radius of `p`, then `‖pₙ‖ rⁿ` tends to zero exponentially:
for some `0 < a < 1`, `‖p n‖ rⁿ = o(aⁿ)`. -/
theorem isLittleO_of_lt_radius (h : ↑r < p.radius) :
∃ a ∈ Ioo (0 : ℝ) 1, (fun n => ‖p n‖ * (r : ℝ) ^ n) =o[atTop] (a ^ ·) := by
have := (TFAE_exists_lt_isLittleO_pow (fun n => ‖p n‖ * (r : ℝ) ^ n) 1).out 1 4
rw [this]
-- Porting note: was
-- rw [(TFAE_exists_lt_isLittleO_pow (fun n => ‖p n‖ * (r : ℝ) ^ n) 1).out 1 4]
simp only [radius, lt_iSup_iff] at h
rcases h with ⟨t, C, hC, rt⟩
rw [ENNReal.coe_lt_coe, ← NNReal.coe_lt_coe] at rt
have : 0 < (t : ℝ) := r.coe_nonneg.trans_lt rt
rw [← div_lt_one this] at rt
refine ⟨_, rt, C, Or.inr zero_lt_one, fun n => ?_⟩
calc
|‖p n‖ * (r : ℝ) ^ n| = ‖p n‖ * (t : ℝ) ^ n * (r / t : ℝ) ^ n := by
field_simp [mul_right_comm, abs_mul]
_ ≤ C * (r / t : ℝ) ^ n := by gcongr; apply hC
#align formal_multilinear_series.is_o_of_lt_radius FormalMultilinearSeries.isLittleO_of_lt_radius
/-- For `r` strictly smaller than the radius of `p`, then `‖pₙ‖ rⁿ = o(1)`. -/
theorem isLittleO_one_of_lt_radius (h : ↑r < p.radius) :
(fun n => ‖p n‖ * (r : ℝ) ^ n) =o[atTop] (fun _ => 1 : ℕ → ℝ) :=
let ⟨_, ha, hp⟩ := p.isLittleO_of_lt_radius h
hp.trans <| (isLittleO_pow_pow_of_lt_left ha.1.le ha.2).congr (fun _ => rfl) one_pow
#align formal_multilinear_series.is_o_one_of_lt_radius FormalMultilinearSeries.isLittleO_one_of_lt_radius
/-- For `r` strictly smaller than the radius of `p`, then `‖pₙ‖ rⁿ` tends to zero exponentially:
for some `0 < a < 1` and `C > 0`, `‖p n‖ * r ^ n ≤ C * a ^ n`. -/
theorem norm_mul_pow_le_mul_pow_of_lt_radius (h : ↑r < p.radius) :
∃ a ∈ Ioo (0 : ℝ) 1, ∃ C > 0, ∀ n, ‖p n‖ * (r : ℝ) ^ n ≤ C * a ^ n := by
-- Porting note: moved out of `rcases`
have := ((TFAE_exists_lt_isLittleO_pow (fun n => ‖p n‖ * (r : ℝ) ^ n) 1).out 1 5).mp
(p.isLittleO_of_lt_radius h)
rcases this with ⟨a, ha, C, hC, H⟩
exact ⟨a, ha, C, hC, fun n => (le_abs_self _).trans (H n)⟩
#align formal_multilinear_series.norm_mul_pow_le_mul_pow_of_lt_radius FormalMultilinearSeries.norm_mul_pow_le_mul_pow_of_lt_radius
/-- If `r ≠ 0` and `‖pₙ‖ rⁿ = O(aⁿ)` for some `-1 < a < 1`, then `r < p.radius`. -/
theorem lt_radius_of_isBigO (h₀ : r ≠ 0) {a : ℝ} (ha : a ∈ Ioo (-1 : ℝ) 1)
(hp : (fun n => ‖p n‖ * (r : ℝ) ^ n) =O[atTop] (a ^ ·)) : ↑r < p.radius := by
-- Porting note: moved out of `rcases`
have := ((TFAE_exists_lt_isLittleO_pow (fun n => ‖p n‖ * (r : ℝ) ^ n) 1).out 2 5)
rcases this.mp ⟨a, ha, hp⟩ with ⟨a, ha, C, hC, hp⟩
rw [← pos_iff_ne_zero, ← NNReal.coe_pos] at h₀
lift a to ℝ≥0 using ha.1.le
have : (r : ℝ) < r / a := by
simpa only [div_one] using (div_lt_div_left h₀ zero_lt_one ha.1).2 ha.2
norm_cast at this
rw [← ENNReal.coe_lt_coe] at this
refine this.trans_le (p.le_radius_of_bound C fun n => ?_)
rw [NNReal.coe_div, div_pow, ← mul_div_assoc, div_le_iff (pow_pos ha.1 n)]
exact (le_abs_self _).trans (hp n)
set_option linter.uppercaseLean3 false in
#align formal_multilinear_series.lt_radius_of_is_O FormalMultilinearSeries.lt_radius_of_isBigO
/-- For `r` strictly smaller than the radius of `p`, then `‖pₙ‖ rⁿ` is bounded. -/
theorem norm_mul_pow_le_of_lt_radius (p : FormalMultilinearSeries 𝕜 E F) {r : ℝ≥0}
(h : (r : ℝ≥0∞) < p.radius) : ∃ C > 0, ∀ n, ‖p n‖ * (r : ℝ) ^ n ≤ C :=
let ⟨_, ha, C, hC, h⟩ := p.norm_mul_pow_le_mul_pow_of_lt_radius h
⟨C, hC, fun n => (h n).trans <| mul_le_of_le_one_right hC.lt.le (pow_le_one _ ha.1.le ha.2.le)⟩
#align formal_multilinear_series.norm_mul_pow_le_of_lt_radius FormalMultilinearSeries.norm_mul_pow_le_of_lt_radius
/-- For `r` strictly smaller than the radius of `p`, then `‖pₙ‖ rⁿ` is bounded. -/
theorem norm_le_div_pow_of_pos_of_lt_radius (p : FormalMultilinearSeries 𝕜 E F) {r : ℝ≥0}
(h0 : 0 < r) (h : (r : ℝ≥0∞) < p.radius) : ∃ C > 0, ∀ n, ‖p n‖ ≤ C / (r : ℝ) ^ n :=
let ⟨C, hC, hp⟩ := p.norm_mul_pow_le_of_lt_radius h
⟨C, hC, fun n => Iff.mpr (le_div_iff (pow_pos h0 _)) (hp n)⟩
#align formal_multilinear_series.norm_le_div_pow_of_pos_of_lt_radius FormalMultilinearSeries.norm_le_div_pow_of_pos_of_lt_radius
/-- For `r` strictly smaller than the radius of `p`, then `‖pₙ‖ rⁿ` is bounded. -/
theorem nnnorm_mul_pow_le_of_lt_radius (p : FormalMultilinearSeries 𝕜 E F) {r : ℝ≥0}
(h : (r : ℝ≥0∞) < p.radius) : ∃ C > 0, ∀ n, ‖p n‖₊ * r ^ n ≤ C :=
let ⟨C, hC, hp⟩ := p.norm_mul_pow_le_of_lt_radius h
⟨⟨C, hC.lt.le⟩, hC, mod_cast hp⟩
#align formal_multilinear_series.nnnorm_mul_pow_le_of_lt_radius FormalMultilinearSeries.nnnorm_mul_pow_le_of_lt_radius
theorem le_radius_of_tendsto (p : FormalMultilinearSeries 𝕜 E F) {l : ℝ}
(h : Tendsto (fun n => ‖p n‖ * (r : ℝ) ^ n) atTop (𝓝 l)) : ↑r ≤ p.radius :=
p.le_radius_of_isBigO (h.isBigO_one _)
#align formal_multilinear_series.le_radius_of_tendsto FormalMultilinearSeries.le_radius_of_tendsto
theorem le_radius_of_summable_norm (p : FormalMultilinearSeries 𝕜 E F)
(hs : Summable fun n => ‖p n‖ * (r : ℝ) ^ n) : ↑r ≤ p.radius :=
p.le_radius_of_tendsto hs.tendsto_atTop_zero
#align formal_multilinear_series.le_radius_of_summable_norm FormalMultilinearSeries.le_radius_of_summable_norm
theorem not_summable_norm_of_radius_lt_nnnorm (p : FormalMultilinearSeries 𝕜 E F) {x : E}
(h : p.radius < ‖x‖₊) : ¬Summable fun n => ‖p n‖ * ‖x‖ ^ n :=
fun hs => not_le_of_lt h (p.le_radius_of_summable_norm hs)
#align formal_multilinear_series.not_summable_norm_of_radius_lt_nnnorm FormalMultilinearSeries.not_summable_norm_of_radius_lt_nnnorm
theorem summable_norm_mul_pow (p : FormalMultilinearSeries 𝕜 E F) {r : ℝ≥0} (h : ↑r < p.radius) :
Summable fun n : ℕ => ‖p n‖ * (r : ℝ) ^ n := by
obtain ⟨a, ha : a ∈ Ioo (0 : ℝ) 1, C, - : 0 < C, hp⟩ := p.norm_mul_pow_le_mul_pow_of_lt_radius h
exact .of_nonneg_of_le (fun n => mul_nonneg (norm_nonneg _) (pow_nonneg r.coe_nonneg _))
hp ((summable_geometric_of_lt_one ha.1.le ha.2).mul_left _)
#align formal_multilinear_series.summable_norm_mul_pow FormalMultilinearSeries.summable_norm_mul_pow
theorem summable_norm_apply (p : FormalMultilinearSeries 𝕜 E F) {x : E}
(hx : x ∈ EMetric.ball (0 : E) p.radius) : Summable fun n : ℕ => ‖p n fun _ => x‖ := by
rw [mem_emetric_ball_zero_iff] at hx
refine .of_nonneg_of_le
(fun _ ↦ norm_nonneg _) (fun n ↦ ((p n).le_opNorm _).trans_eq ?_) (p.summable_norm_mul_pow hx)
simp
#align formal_multilinear_series.summable_norm_apply FormalMultilinearSeries.summable_norm_apply
theorem summable_nnnorm_mul_pow (p : FormalMultilinearSeries 𝕜 E F) {r : ℝ≥0} (h : ↑r < p.radius) :
Summable fun n : ℕ => ‖p n‖₊ * r ^ n := by
rw [← NNReal.summable_coe]
push_cast
exact p.summable_norm_mul_pow h
#align formal_multilinear_series.summable_nnnorm_mul_pow FormalMultilinearSeries.summable_nnnorm_mul_pow
protected theorem summable [CompleteSpace F] (p : FormalMultilinearSeries 𝕜 E F) {x : E}
(hx : x ∈ EMetric.ball (0 : E) p.radius) : Summable fun n : ℕ => p n fun _ => x :=
(p.summable_norm_apply hx).of_norm
#align formal_multilinear_series.summable FormalMultilinearSeries.summable
theorem radius_eq_top_of_summable_norm (p : FormalMultilinearSeries 𝕜 E F)
(hs : ∀ r : ℝ≥0, Summable fun n => ‖p n‖ * (r : ℝ) ^ n) : p.radius = ∞ :=
ENNReal.eq_top_of_forall_nnreal_le fun r => p.le_radius_of_summable_norm (hs r)
#align formal_multilinear_series.radius_eq_top_of_summable_norm FormalMultilinearSeries.radius_eq_top_of_summable_norm
theorem radius_eq_top_iff_summable_norm (p : FormalMultilinearSeries 𝕜 E F) :
p.radius = ∞ ↔ ∀ r : ℝ≥0, Summable fun n => ‖p n‖ * (r : ℝ) ^ n := by
constructor
· intro h r
obtain ⟨a, ha : a ∈ Ioo (0 : ℝ) 1, C, - : 0 < C, hp⟩ := p.norm_mul_pow_le_mul_pow_of_lt_radius
(show (r : ℝ≥0∞) < p.radius from h.symm ▸ ENNReal.coe_lt_top)
refine .of_norm_bounded
(fun n ↦ (C : ℝ) * a ^ n) ((summable_geometric_of_lt_one ha.1.le ha.2).mul_left _) fun n ↦ ?_
specialize hp n
rwa [Real.norm_of_nonneg (mul_nonneg (norm_nonneg _) (pow_nonneg r.coe_nonneg n))]
· exact p.radius_eq_top_of_summable_norm
#align formal_multilinear_series.radius_eq_top_iff_summable_norm FormalMultilinearSeries.radius_eq_top_iff_summable_norm
/-- If the radius of `p` is positive, then `‖pₙ‖` grows at most geometrically. -/
theorem le_mul_pow_of_radius_pos (p : FormalMultilinearSeries 𝕜 E F) (h : 0 < p.radius) :
∃ (C r : _) (hC : 0 < C) (_ : 0 < r), ∀ n, ‖p n‖ ≤ C * r ^ n := by
rcases ENNReal.lt_iff_exists_nnreal_btwn.1 h with ⟨r, r0, rlt⟩
have rpos : 0 < (r : ℝ) := by simp [ENNReal.coe_pos.1 r0]
rcases norm_le_div_pow_of_pos_of_lt_radius p rpos rlt with ⟨C, Cpos, hCp⟩
refine ⟨C, r⁻¹, Cpos, by simp only [inv_pos, rpos], fun n => ?_⟩
-- Porting note: was `convert`
rw [inv_pow, ← div_eq_mul_inv]
exact hCp n
#align formal_multilinear_series.le_mul_pow_of_radius_pos FormalMultilinearSeries.le_mul_pow_of_radius_pos
/-- The radius of the sum of two formal series is at least the minimum of their two radii. -/
theorem min_radius_le_radius_add (p q : FormalMultilinearSeries 𝕜 E F) :
min p.radius q.radius ≤ (p + q).radius := by
refine ENNReal.le_of_forall_nnreal_lt fun r hr => ?_
rw [lt_min_iff] at hr
have := ((p.isLittleO_one_of_lt_radius hr.1).add (q.isLittleO_one_of_lt_radius hr.2)).isBigO
refine (p + q).le_radius_of_isBigO ((isBigO_of_le _ fun n => ?_).trans this)
rw [← add_mul, norm_mul, norm_mul, norm_norm]
exact mul_le_mul_of_nonneg_right ((norm_add_le _ _).trans (le_abs_self _)) (norm_nonneg _)
#align formal_multilinear_series.min_radius_le_radius_add FormalMultilinearSeries.min_radius_le_radius_add
@[simp]
theorem radius_neg (p : FormalMultilinearSeries 𝕜 E F) : (-p).radius = p.radius := by
simp only [radius, neg_apply, norm_neg]
#align formal_multilinear_series.radius_neg FormalMultilinearSeries.radius_neg
protected theorem hasSum [CompleteSpace F] (p : FormalMultilinearSeries 𝕜 E F) {x : E}
(hx : x ∈ EMetric.ball (0 : E) p.radius) : HasSum (fun n : ℕ => p n fun _ => x) (p.sum x) :=
(p.summable hx).hasSum
#align formal_multilinear_series.has_sum FormalMultilinearSeries.hasSum
theorem radius_le_radius_continuousLinearMap_comp (p : FormalMultilinearSeries 𝕜 E F)
(f : F →L[𝕜] G) : p.radius ≤ (f.compFormalMultilinearSeries p).radius := by
refine ENNReal.le_of_forall_nnreal_lt fun r hr => ?_
apply le_radius_of_isBigO
apply (IsBigO.trans_isLittleO _ (p.isLittleO_one_of_lt_radius hr)).isBigO
refine IsBigO.mul (@IsBigOWith.isBigO _ _ _ _ _ ‖f‖ _ _ _ ?_) (isBigO_refl _ _)
refine IsBigOWith.of_bound (eventually_of_forall fun n => ?_)
simpa only [norm_norm] using f.norm_compContinuousMultilinearMap_le (p n)
#align formal_multilinear_series.radius_le_radius_continuous_linear_map_comp FormalMultilinearSeries.radius_le_radius_continuousLinearMap_comp
end FormalMultilinearSeries
/-! ### Expanding a function as a power series -/
section
variable {f g : E → F} {p pf pg : FormalMultilinearSeries 𝕜 E F} {x : E} {r r' : ℝ≥0∞}
/-- Given a function `f : E → F` and a formal multilinear series `p`, we say that `f` has `p` as
a power series on the ball of radius `r > 0` around `x` if `f (x + y) = ∑' pₙ yⁿ` for all `‖y‖ < r`.
-/
structure HasFPowerSeriesOnBall (f : E → F) (p : FormalMultilinearSeries 𝕜 E F) (x : E) (r : ℝ≥0∞) :
Prop where
r_le : r ≤ p.radius
r_pos : 0 < r
hasSum :
∀ {y}, y ∈ EMetric.ball (0 : E) r → HasSum (fun n : ℕ => p n fun _ : Fin n => y) (f (x + y))
#align has_fpower_series_on_ball HasFPowerSeriesOnBall
/-- Given a function `f : E → F` and a formal multilinear series `p`, we say that `f` has `p` as
a power series around `x` if `f (x + y) = ∑' pₙ yⁿ` for all `y` in a neighborhood of `0`. -/
def HasFPowerSeriesAt (f : E → F) (p : FormalMultilinearSeries 𝕜 E F) (x : E) :=
∃ r, HasFPowerSeriesOnBall f p x r
#align has_fpower_series_at HasFPowerSeriesAt
variable (𝕜)
/-- Given a function `f : E → F`, we say that `f` is analytic at `x` if it admits a convergent power
series expansion around `x`. -/
def AnalyticAt (f : E → F) (x : E) :=
∃ p : FormalMultilinearSeries 𝕜 E F, HasFPowerSeriesAt f p x
#align analytic_at AnalyticAt
/-- Given a function `f : E → F`, we say that `f` is analytic on a set `s` if it is analytic around
every point of `s`. -/
def AnalyticOn (f : E → F) (s : Set E) :=
∀ x, x ∈ s → AnalyticAt 𝕜 f x
#align analytic_on AnalyticOn
variable {𝕜}
theorem HasFPowerSeriesOnBall.hasFPowerSeriesAt (hf : HasFPowerSeriesOnBall f p x r) :
HasFPowerSeriesAt f p x :=
⟨r, hf⟩
#align has_fpower_series_on_ball.has_fpower_series_at HasFPowerSeriesOnBall.hasFPowerSeriesAt
theorem HasFPowerSeriesAt.analyticAt (hf : HasFPowerSeriesAt f p x) : AnalyticAt 𝕜 f x :=
⟨p, hf⟩
#align has_fpower_series_at.analytic_at HasFPowerSeriesAt.analyticAt
theorem HasFPowerSeriesOnBall.analyticAt (hf : HasFPowerSeriesOnBall f p x r) : AnalyticAt 𝕜 f x :=
hf.hasFPowerSeriesAt.analyticAt
#align has_fpower_series_on_ball.analytic_at HasFPowerSeriesOnBall.analyticAt
theorem HasFPowerSeriesOnBall.congr (hf : HasFPowerSeriesOnBall f p x r)
(hg : EqOn f g (EMetric.ball x r)) : HasFPowerSeriesOnBall g p x r :=
{ r_le := hf.r_le
r_pos := hf.r_pos
hasSum := fun {y} hy => by
convert hf.hasSum hy using 1
apply hg.symm
simpa [edist_eq_coe_nnnorm_sub] using hy }
#align has_fpower_series_on_ball.congr HasFPowerSeriesOnBall.congr
/-- If a function `f` has a power series `p` around `x`, then the function `z ↦ f (z - y)` has the
same power series around `x + y`. -/
theorem HasFPowerSeriesOnBall.comp_sub (hf : HasFPowerSeriesOnBall f p x r) (y : E) :
HasFPowerSeriesOnBall (fun z => f (z - y)) p (x + y) r :=
{ r_le := hf.r_le
r_pos := hf.r_pos
hasSum := fun {z} hz => by
convert hf.hasSum hz using 2
abel }
#align has_fpower_series_on_ball.comp_sub HasFPowerSeriesOnBall.comp_sub
theorem HasFPowerSeriesOnBall.hasSum_sub (hf : HasFPowerSeriesOnBall f p x r) {y : E}
(hy : y ∈ EMetric.ball x r) : HasSum (fun n : ℕ => p n fun _ => y - x) (f y) := by
have : y - x ∈ EMetric.ball (0 : E) r := by simpa [edist_eq_coe_nnnorm_sub] using hy
simpa only [add_sub_cancel] using hf.hasSum this
#align has_fpower_series_on_ball.has_sum_sub HasFPowerSeriesOnBall.hasSum_sub
theorem HasFPowerSeriesOnBall.radius_pos (hf : HasFPowerSeriesOnBall f p x r) : 0 < p.radius :=
lt_of_lt_of_le hf.r_pos hf.r_le
#align has_fpower_series_on_ball.radius_pos HasFPowerSeriesOnBall.radius_pos
theorem HasFPowerSeriesAt.radius_pos (hf : HasFPowerSeriesAt f p x) : 0 < p.radius :=
let ⟨_, hr⟩ := hf
hr.radius_pos
#align has_fpower_series_at.radius_pos HasFPowerSeriesAt.radius_pos
theorem HasFPowerSeriesOnBall.mono (hf : HasFPowerSeriesOnBall f p x r) (r'_pos : 0 < r')
(hr : r' ≤ r) : HasFPowerSeriesOnBall f p x r' :=
⟨le_trans hr hf.1, r'_pos, fun hy => hf.hasSum (EMetric.ball_subset_ball hr hy)⟩
#align has_fpower_series_on_ball.mono HasFPowerSeriesOnBall.mono
theorem HasFPowerSeriesAt.congr (hf : HasFPowerSeriesAt f p x) (hg : f =ᶠ[𝓝 x] g) :
HasFPowerSeriesAt g p x := by
rcases hf with ⟨r₁, h₁⟩
rcases EMetric.mem_nhds_iff.mp hg with ⟨r₂, h₂pos, h₂⟩
exact ⟨min r₁ r₂,
(h₁.mono (lt_min h₁.r_pos h₂pos) inf_le_left).congr
fun y hy => h₂ (EMetric.ball_subset_ball inf_le_right hy)⟩
#align has_fpower_series_at.congr HasFPowerSeriesAt.congr
protected theorem HasFPowerSeriesAt.eventually (hf : HasFPowerSeriesAt f p x) :
∀ᶠ r : ℝ≥0∞ in 𝓝[>] 0, HasFPowerSeriesOnBall f p x r :=
let ⟨_, hr⟩ := hf
mem_of_superset (Ioo_mem_nhdsWithin_Ioi (left_mem_Ico.2 hr.r_pos)) fun _ hr' =>
hr.mono hr'.1 hr'.2.le
#align has_fpower_series_at.eventually HasFPowerSeriesAt.eventually
theorem HasFPowerSeriesOnBall.eventually_hasSum (hf : HasFPowerSeriesOnBall f p x r) :
∀ᶠ y in 𝓝 0, HasSum (fun n : ℕ => p n fun _ : Fin n => y) (f (x + y)) := by
filter_upwards [EMetric.ball_mem_nhds (0 : E) hf.r_pos] using fun _ => hf.hasSum
#align has_fpower_series_on_ball.eventually_has_sum HasFPowerSeriesOnBall.eventually_hasSum
theorem HasFPowerSeriesAt.eventually_hasSum (hf : HasFPowerSeriesAt f p x) :
∀ᶠ y in 𝓝 0, HasSum (fun n : ℕ => p n fun _ : Fin n => y) (f (x + y)) :=
let ⟨_, hr⟩ := hf
hr.eventually_hasSum
#align has_fpower_series_at.eventually_has_sum HasFPowerSeriesAt.eventually_hasSum
theorem HasFPowerSeriesOnBall.eventually_hasSum_sub (hf : HasFPowerSeriesOnBall f p x r) :
∀ᶠ y in 𝓝 x, HasSum (fun n : ℕ => p n fun _ : Fin n => y - x) (f y) := by
filter_upwards [EMetric.ball_mem_nhds x hf.r_pos] with y using hf.hasSum_sub
#align has_fpower_series_on_ball.eventually_has_sum_sub HasFPowerSeriesOnBall.eventually_hasSum_sub
theorem HasFPowerSeriesAt.eventually_hasSum_sub (hf : HasFPowerSeriesAt f p x) :
∀ᶠ y in 𝓝 x, HasSum (fun n : ℕ => p n fun _ : Fin n => y - x) (f y) :=
let ⟨_, hr⟩ := hf
hr.eventually_hasSum_sub
#align has_fpower_series_at.eventually_has_sum_sub HasFPowerSeriesAt.eventually_hasSum_sub
theorem HasFPowerSeriesOnBall.eventually_eq_zero
(hf : HasFPowerSeriesOnBall f (0 : FormalMultilinearSeries 𝕜 E F) x r) :
∀ᶠ z in 𝓝 x, f z = 0 := by
filter_upwards [hf.eventually_hasSum_sub] with z hz using hz.unique hasSum_zero
#align has_fpower_series_on_ball.eventually_eq_zero HasFPowerSeriesOnBall.eventually_eq_zero
theorem HasFPowerSeriesAt.eventually_eq_zero
(hf : HasFPowerSeriesAt f (0 : FormalMultilinearSeries 𝕜 E F) x) : ∀ᶠ z in 𝓝 x, f z = 0 :=
let ⟨_, hr⟩ := hf
hr.eventually_eq_zero
#align has_fpower_series_at.eventually_eq_zero HasFPowerSeriesAt.eventually_eq_zero
theorem hasFPowerSeriesOnBall_const {c : F} {e : E} :
HasFPowerSeriesOnBall (fun _ => c) (constFormalMultilinearSeries 𝕜 E c) e ⊤ := by
refine ⟨by simp, WithTop.zero_lt_top, fun _ => hasSum_single 0 fun n hn => ?_⟩
simp [constFormalMultilinearSeries_apply hn]
#align has_fpower_series_on_ball_const hasFPowerSeriesOnBall_const
theorem hasFPowerSeriesAt_const {c : F} {e : E} :
HasFPowerSeriesAt (fun _ => c) (constFormalMultilinearSeries 𝕜 E c) e :=
⟨⊤, hasFPowerSeriesOnBall_const⟩
#align has_fpower_series_at_const hasFPowerSeriesAt_const
theorem analyticAt_const {v : F} : AnalyticAt 𝕜 (fun _ => v) x :=
⟨constFormalMultilinearSeries 𝕜 E v, hasFPowerSeriesAt_const⟩
#align analytic_at_const analyticAt_const
theorem analyticOn_const {v : F} {s : Set E} : AnalyticOn 𝕜 (fun _ => v) s :=
fun _ _ => analyticAt_const
#align analytic_on_const analyticOn_const
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) }
#align has_fpower_series_on_ball.add HasFPowerSeriesOnBall.add
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⟩
#align has_fpower_series_at.add HasFPowerSeriesAt.add
theorem AnalyticAt.congr (hf : AnalyticAt 𝕜 f x) (hg : f =ᶠ[𝓝 x] g) : AnalyticAt 𝕜 g x :=
let ⟨_, hpf⟩ := hf
(hpf.congr hg).analyticAt
theorem analyticAt_congr (h : f =ᶠ[𝓝 x] g) : AnalyticAt 𝕜 f x ↔ AnalyticAt 𝕜 g x :=
⟨fun hf ↦ hf.congr h, fun hg ↦ hg.congr h.symm⟩
theorem AnalyticAt.add (hf : AnalyticAt 𝕜 f x) (hg : AnalyticAt 𝕜 g x) : AnalyticAt 𝕜 (f + g) x :=
let ⟨_, hpf⟩ := hf
let ⟨_, hqf⟩ := hg
(hpf.add hqf).analyticAt
#align analytic_at.add AnalyticAt.add
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 }
#align has_fpower_series_on_ball.neg HasFPowerSeriesOnBall.neg
theorem HasFPowerSeriesAt.neg (hf : HasFPowerSeriesAt f pf x) : HasFPowerSeriesAt (-f) (-pf) x :=
let ⟨_, hrf⟩ := hf
hrf.neg.hasFPowerSeriesAt
#align has_fpower_series_at.neg HasFPowerSeriesAt.neg
theorem AnalyticAt.neg (hf : AnalyticAt 𝕜 f x) : AnalyticAt 𝕜 (-f) x :=
let ⟨_, hpf⟩ := hf
hpf.neg.analyticAt
#align analytic_at.neg AnalyticAt.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
#align has_fpower_series_on_ball.sub HasFPowerSeriesOnBall.sub
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
#align has_fpower_series_at.sub HasFPowerSeriesAt.sub
theorem AnalyticAt.sub (hf : AnalyticAt 𝕜 f x) (hg : AnalyticAt 𝕜 g x) :
AnalyticAt 𝕜 (f - g) x := by
simpa only [sub_eq_add_neg] using hf.add hg.neg
#align analytic_at.sub AnalyticAt.sub
theorem AnalyticOn.mono {s t : Set E} (hf : AnalyticOn 𝕜 f t) (hst : s ⊆ t) : AnalyticOn 𝕜 f s :=
fun z hz => hf z (hst hz)
#align analytic_on.mono AnalyticOn.mono
theorem AnalyticOn.congr' {s : Set E} (hf : AnalyticOn 𝕜 f s) (hg : f =ᶠ[𝓝ˢ s] g) :
AnalyticOn 𝕜 g s :=
fun z hz => (hf z hz).congr (mem_nhdsSet_iff_forall.mp hg z hz)
theorem analyticOn_congr' {s : Set E} (h : f =ᶠ[𝓝ˢ s] g) : AnalyticOn 𝕜 f s ↔ AnalyticOn 𝕜 g s :=
⟨fun hf => hf.congr' h, fun hg => hg.congr' h.symm⟩
theorem AnalyticOn.congr {s : Set E} (hs : IsOpen s) (hf : AnalyticOn 𝕜 f s) (hg : s.EqOn f g) :
AnalyticOn 𝕜 g s :=
hf.congr' <| mem_nhdsSet_iff_forall.mpr
(fun _ hz => eventuallyEq_iff_exists_mem.mpr ⟨s, hs.mem_nhds hz, hg⟩)
theorem analyticOn_congr {s : Set E} (hs : IsOpen s) (h : s.EqOn f g) : AnalyticOn 𝕜 f s ↔
AnalyticOn 𝕜 g s := ⟨fun hf => hf.congr hs h, fun hg => hg.congr hs h.symm⟩
theorem AnalyticOn.add {s : Set E} (hf : AnalyticOn 𝕜 f s) (hg : AnalyticOn 𝕜 g s) :
AnalyticOn 𝕜 (f + g) s :=
fun z hz => (hf z hz).add (hg z hz)
#align analytic_on.add AnalyticOn.add
theorem AnalyticOn.sub {s : Set E} (hf : AnalyticOn 𝕜 f s) (hg : AnalyticOn 𝕜 g s) :
AnalyticOn 𝕜 (f - g) s :=
fun z hz => (hf z hz).sub (hg z hz)
#align analytic_on.sub AnalyticOn.sub
theorem HasFPowerSeriesOnBall.coeff_zero (hf : HasFPowerSeriesOnBall f pf x r) (v : Fin 0 → E) :
pf 0 v = f x := by
have v_eq : v = fun i => 0 := Subsingleton.elim _ _
have zero_mem : (0 : E) ∈ EMetric.ball (0 : E) r := by simp [hf.r_pos]
have : ∀ i, i ≠ 0 → (pf i fun j => 0) = 0 := by
intro i hi
have : 0 < i := pos_iff_ne_zero.2 hi
exact ContinuousMultilinearMap.map_coord_zero _ (⟨0, this⟩ : Fin i) rfl
have A := (hf.hasSum zero_mem).unique (hasSum_single _ this)
simpa [v_eq] using A.symm
#align has_fpower_series_on_ball.coeff_zero HasFPowerSeriesOnBall.coeff_zero
theorem HasFPowerSeriesAt.coeff_zero (hf : HasFPowerSeriesAt f pf x) (v : Fin 0 → E) :
pf 0 v = f x :=
let ⟨_, hrf⟩ := hf
hrf.coeff_zero v
#align has_fpower_series_at.coeff_zero HasFPowerSeriesAt.coeff_zero
/-- If a function `f` has a power series `p` on a ball and `g` is linear, then `g ∘ f` has the
power series `g ∘ p` on the same ball. -/
theorem ContinuousLinearMap.comp_hasFPowerSeriesOnBall (g : F →L[𝕜] G)
(h : HasFPowerSeriesOnBall f p x r) :
HasFPowerSeriesOnBall (g ∘ f) (g.compFormalMultilinearSeries p) x r :=
{ r_le := h.r_le.trans (p.radius_le_radius_continuousLinearMap_comp _)
r_pos := h.r_pos
hasSum := fun hy => by
simpa only [ContinuousLinearMap.compFormalMultilinearSeries_apply,
ContinuousLinearMap.compContinuousMultilinearMap_coe, Function.comp_apply] using
g.hasSum (h.hasSum hy) }
#align continuous_linear_map.comp_has_fpower_series_on_ball ContinuousLinearMap.comp_hasFPowerSeriesOnBall
/-- If a function `f` is analytic on a set `s` and `g` is linear, then `g ∘ f` is analytic
on `s`. -/
theorem ContinuousLinearMap.comp_analyticOn {s : Set E} (g : F →L[𝕜] G) (h : AnalyticOn 𝕜 f s) :
AnalyticOn 𝕜 (g ∘ f) s := by
rintro x hx
rcases h x hx with ⟨p, r, hp⟩
exact ⟨g.compFormalMultilinearSeries p, r, g.comp_hasFPowerSeriesOnBall hp⟩
#align continuous_linear_map.comp_analytic_on ContinuousLinearMap.comp_analyticOn
/-- If a function admits a power series expansion, then it is exponentially close to the partial
sums of this power series on strict subdisks of the disk of convergence.
This version provides an upper estimate that decreases both in `‖y‖` and `n`. See also
`HasFPowerSeriesOnBall.uniform_geometric_approx` for a weaker version. -/
theorem HasFPowerSeriesOnBall.uniform_geometric_approx' {r' : ℝ≥0}
(hf : HasFPowerSeriesOnBall f p x r) (h : (r' : ℝ≥0∞) < r) :
∃ a ∈ Ioo (0 : ℝ) 1, ∃ C > 0, ∀ y ∈ Metric.ball (0 : E) r', ∀ n,
‖f (x + y) - p.partialSum n y‖ ≤ C * (a * (‖y‖ / r')) ^ n := by
obtain ⟨a, ha, C, hC, hp⟩ : ∃ a ∈ Ioo (0 : ℝ) 1, ∃ C > 0, ∀ n, ‖p n‖ * (r' : ℝ) ^ n ≤ C * a ^ n :=
p.norm_mul_pow_le_mul_pow_of_lt_radius (h.trans_le hf.r_le)
refine ⟨a, ha, C / (1 - a), div_pos hC (sub_pos.2 ha.2), fun y hy n => ?_⟩
have yr' : ‖y‖ < r' := by
rw [ball_zero_eq] at hy
exact hy
have hr'0 : 0 < (r' : ℝ) := (norm_nonneg _).trans_lt yr'
have : y ∈ EMetric.ball (0 : E) r := by
refine mem_emetric_ball_zero_iff.2 (lt_trans ?_ h)
exact mod_cast yr'
rw [norm_sub_rev, ← mul_div_right_comm]
have ya : a * (‖y‖ / ↑r') ≤ a :=
mul_le_of_le_one_right ha.1.le (div_le_one_of_le yr'.le r'.coe_nonneg)
suffices ‖p.partialSum n y - f (x + y)‖ ≤ C * (a * (‖y‖ / r')) ^ n / (1 - a * (‖y‖ / r')) by
refine this.trans ?_
have : 0 < a := ha.1
gcongr
apply_rules [sub_pos.2, ha.2]
apply norm_sub_le_of_geometric_bound_of_hasSum (ya.trans_lt ha.2) _ (hf.hasSum this)
intro n
calc
‖(p n) fun _ : Fin n => y‖
_ ≤ ‖p n‖ * ∏ _i : Fin n, ‖y‖ := ContinuousMultilinearMap.le_opNorm _ _
_ = ‖p n‖ * (r' : ℝ) ^ n * (‖y‖ / r') ^ n := by field_simp [mul_right_comm]
_ ≤ C * a ^ n * (‖y‖ / r') ^ n := by gcongr ?_ * _; apply hp
_ ≤ C * (a * (‖y‖ / r')) ^ n := by rw [mul_pow, mul_assoc]
#align has_fpower_series_on_ball.uniform_geometric_approx' HasFPowerSeriesOnBall.uniform_geometric_approx'
/-- If a function admits a power series expansion, then it is exponentially close to the partial
sums of this power series on strict subdisks of the disk of convergence. -/
theorem HasFPowerSeriesOnBall.uniform_geometric_approx {r' : ℝ≥0}
(hf : HasFPowerSeriesOnBall f p x r) (h : (r' : ℝ≥0∞) < r) :
∃ a ∈ Ioo (0 : ℝ) 1,
∃ C > 0, ∀ y ∈ Metric.ball (0 : E) r', ∀ n, ‖f (x + y) - p.partialSum n y‖ ≤ C * a ^ n := by
obtain ⟨a, ha, C, hC, hp⟩ : ∃ a ∈ Ioo (0 : ℝ) 1, ∃ C > 0, ∀ y ∈ Metric.ball (0 : E) r', ∀ n,
‖f (x + y) - p.partialSum n y‖ ≤ C * (a * (‖y‖ / r')) ^ n :=
hf.uniform_geometric_approx' h
refine ⟨a, ha, C, hC, fun y hy n => (hp y hy n).trans ?_⟩
have yr' : ‖y‖ < r' := by rwa [ball_zero_eq] at hy
have := ha.1.le -- needed to discharge a side goal on the next line
gcongr
exact mul_le_of_le_one_right ha.1.le (div_le_one_of_le yr'.le r'.coe_nonneg)
#align has_fpower_series_on_ball.uniform_geometric_approx HasFPowerSeriesOnBall.uniform_geometric_approx
/-- Taylor formula for an analytic function, `IsBigO` version. -/
theorem HasFPowerSeriesAt.isBigO_sub_partialSum_pow (hf : HasFPowerSeriesAt f p x) (n : ℕ) :
(fun y : E => f (x + y) - p.partialSum n y) =O[𝓝 0] fun y => ‖y‖ ^ n := by
rcases hf with ⟨r, hf⟩
rcases ENNReal.lt_iff_exists_nnreal_btwn.1 hf.r_pos with ⟨r', r'0, h⟩
obtain ⟨a, -, C, -, hp⟩ : ∃ a ∈ Ioo (0 : ℝ) 1, ∃ C > 0, ∀ y ∈ Metric.ball (0 : E) r', ∀ n,
‖f (x + y) - p.partialSum n y‖ ≤ C * (a * (‖y‖ / r')) ^ n :=
hf.uniform_geometric_approx' h
refine isBigO_iff.2 ⟨C * (a / r') ^ n, ?_⟩
replace r'0 : 0 < (r' : ℝ) := mod_cast r'0
filter_upwards [Metric.ball_mem_nhds (0 : E) r'0] with y hy
simpa [mul_pow, mul_div_assoc, mul_assoc, div_mul_eq_mul_div] using hp y hy n
set_option linter.uppercaseLean3 false in
#align has_fpower_series_at.is_O_sub_partial_sum_pow HasFPowerSeriesAt.isBigO_sub_partialSum_pow
/-- If `f` has formal power series `∑ n, pₙ` on a ball of radius `r`, then for `y, z` in any smaller
ball, the norm of the difference `f y - f z - p 1 (fun _ ↦ y - z)` is bounded above by
`C * (max ‖y - x‖ ‖z - x‖) * ‖y - z‖`. This lemma formulates this property using `IsBigO` and
`Filter.principal` on `E × E`. -/
theorem HasFPowerSeriesOnBall.isBigO_image_sub_image_sub_deriv_principal
(hf : HasFPowerSeriesOnBall f p x r) (hr : r' < r) :
(fun y : E × E => f y.1 - f y.2 - p 1 fun _ => y.1 - y.2) =O[𝓟 (EMetric.ball (x, x) r')]
fun y => ‖y - (x, x)‖ * ‖y.1 - y.2‖ := by
lift r' to ℝ≥0 using ne_top_of_lt hr
rcases (zero_le r').eq_or_lt with (rfl | hr'0)
· simp only [isBigO_bot, EMetric.ball_zero, principal_empty, ENNReal.coe_zero]
obtain ⟨a, ha, C, hC : 0 < C, hp⟩ :
∃ a ∈ Ioo (0 : ℝ) 1, ∃ C > 0, ∀ n : ℕ, ‖p n‖ * (r' : ℝ) ^ n ≤ C * a ^ n :=
p.norm_mul_pow_le_mul_pow_of_lt_radius (hr.trans_le hf.r_le)
simp only [← le_div_iff (pow_pos (NNReal.coe_pos.2 hr'0) _)] at hp
set L : E × E → ℝ := fun y =>
C * (a / r') ^ 2 * (‖y - (x, x)‖ * ‖y.1 - y.2‖) * (a / (1 - a) ^ 2 + 2 / (1 - a))
have hL : ∀ y ∈ EMetric.ball (x, x) r', ‖f y.1 - f y.2 - p 1 fun _ => y.1 - y.2‖ ≤ L y := by
intro y hy'
have hy : y ∈ EMetric.ball x r ×ˢ EMetric.ball x r := by
rw [EMetric.ball_prod_same]
exact EMetric.ball_subset_ball hr.le hy'
set A : ℕ → F := fun n => (p n fun _ => y.1 - x) - p n fun _ => y.2 - x
have hA : HasSum (fun n => A (n + 2)) (f y.1 - f y.2 - p 1 fun _ => y.1 - y.2) := by
convert (hasSum_nat_add_iff' 2).2 ((hf.hasSum_sub hy.1).sub (hf.hasSum_sub hy.2)) using 1
rw [Finset.sum_range_succ, Finset.sum_range_one, hf.coeff_zero, hf.coeff_zero, sub_self,
zero_add, ← Subsingleton.pi_single_eq (0 : Fin 1) (y.1 - x), Pi.single,
← Subsingleton.pi_single_eq (0 : Fin 1) (y.2 - x), Pi.single, ← (p 1).map_sub, ← Pi.single,
Subsingleton.pi_single_eq, sub_sub_sub_cancel_right]
rw [EMetric.mem_ball, edist_eq_coe_nnnorm_sub, ENNReal.coe_lt_coe] at hy'
set B : ℕ → ℝ := fun n => C * (a / r') ^ 2 * (‖y - (x, x)‖ * ‖y.1 - y.2‖) * ((n + 2) * a ^ n)
have hAB : ∀ n, ‖A (n + 2)‖ ≤ B n := fun n =>
calc
‖A (n + 2)‖ ≤ ‖p (n + 2)‖ * ↑(n + 2) * ‖y - (x, x)‖ ^ (n + 1) * ‖y.1 - y.2‖ := by
-- Porting note: `pi_norm_const` was `pi_norm_const (_ : E)`
simpa only [Fintype.card_fin, pi_norm_const, Prod.norm_def, Pi.sub_def,
Prod.fst_sub, Prod.snd_sub, sub_sub_sub_cancel_right] using
(p <| n + 2).norm_image_sub_le (fun _ => y.1 - x) fun _ => y.2 - x
_ = ‖p (n + 2)‖ * ‖y - (x, x)‖ ^ n * (↑(n + 2) * ‖y - (x, x)‖ * ‖y.1 - y.2‖) := by
rw [pow_succ ‖y - (x, x)‖]
ring
-- Porting note: the two `↑` in `↑r'` are new, without them, Lean fails to synthesize
-- instances `HDiv ℝ ℝ≥0 ?m` or `HMul ℝ ℝ≥0 ?m`
_ ≤ C * a ^ (n + 2) / ↑r' ^ (n + 2)
* ↑r' ^ n * (↑(n + 2) * ‖y - (x, x)‖ * ‖y.1 - y.2‖) := by
have : 0 < a := ha.1
gcongr
· apply hp
· apply hy'.le
_ = B n := by
field_simp [B, pow_succ]
simp only [mul_assoc, mul_comm, mul_left_comm]
have hBL : HasSum B (L y) := by
apply HasSum.mul_left
simp only [add_mul]
have : ‖a‖ < 1 := by simp only [Real.norm_eq_abs, abs_of_pos ha.1, ha.2]
rw [div_eq_mul_inv, div_eq_mul_inv]
exact (hasSum_coe_mul_geometric_of_norm_lt_one this).add -- Porting note: was `convert`!
((hasSum_geometric_of_norm_lt_one this).mul_left 2)
exact hA.norm_le_of_bounded hBL hAB
suffices L =O[𝓟 (EMetric.ball (x, x) r')] fun y => ‖y - (x, x)‖ * ‖y.1 - y.2‖ by
refine (IsBigO.of_bound 1 (eventually_principal.2 fun y hy => ?_)).trans this
rw [one_mul]
exact (hL y hy).trans (le_abs_self _)
simp_rw [L, mul_right_comm _ (_ * _)]
exact (isBigO_refl _ _).const_mul_left _
set_option linter.uppercaseLean3 false in
#align has_fpower_series_on_ball.is_O_image_sub_image_sub_deriv_principal HasFPowerSeriesOnBall.isBigO_image_sub_image_sub_deriv_principal
/-- If `f` has formal power series `∑ n, pₙ` on a ball of radius `r`, then for `y, z` in any smaller
ball, the norm of the difference `f y - f z - p 1 (fun _ ↦ y - z)` is bounded above by
`C * (max ‖y - x‖ ‖z - x‖) * ‖y - z‖`. -/
theorem HasFPowerSeriesOnBall.image_sub_sub_deriv_le (hf : HasFPowerSeriesOnBall f p x r)
(hr : r' < r) :
∃ C, ∀ᵉ (y ∈ EMetric.ball x r') (z ∈ EMetric.ball x r'),
‖f y - f z - p 1 fun _ => y - z‖ ≤ C * max ‖y - x‖ ‖z - x‖ * ‖y - z‖ := by
simpa only [isBigO_principal, mul_assoc, norm_mul, norm_norm, Prod.forall, EMetric.mem_ball,
Prod.edist_eq, max_lt_iff, and_imp, @forall_swap (_ < _) E] using
hf.isBigO_image_sub_image_sub_deriv_principal hr
#align has_fpower_series_on_ball.image_sub_sub_deriv_le HasFPowerSeriesOnBall.image_sub_sub_deriv_le
/-- If `f` has formal power series `∑ n, pₙ` at `x`, then
`f y - f z - p 1 (fun _ ↦ y - z) = O(‖(y, z) - (x, x)‖ * ‖y - z‖)` as `(y, z) → (x, x)`.
In particular, `f` is strictly differentiable at `x`. -/
theorem HasFPowerSeriesAt.isBigO_image_sub_norm_mul_norm_sub (hf : HasFPowerSeriesAt f p x) :
(fun y : E × E => f y.1 - f y.2 - p 1 fun _ => y.1 - y.2) =O[𝓝 (x, x)] fun y =>
‖y - (x, x)‖ * ‖y.1 - y.2‖ := by
rcases hf with ⟨r, hf⟩
rcases ENNReal.lt_iff_exists_nnreal_btwn.1 hf.r_pos with ⟨r', r'0, h⟩
refine (hf.isBigO_image_sub_image_sub_deriv_principal h).mono ?_
exact le_principal_iff.2 (EMetric.ball_mem_nhds _ r'0)
set_option linter.uppercaseLean3 false in
#align has_fpower_series_at.is_O_image_sub_norm_mul_norm_sub HasFPowerSeriesAt.isBigO_image_sub_norm_mul_norm_sub
/-- If a function admits a power series expansion at `x`, then it is the uniform limit of the
partial sums of this power series on strict subdisks of the disk of convergence, i.e., `f (x + y)`
is the uniform limit of `p.partialSum n y` there. -/
theorem HasFPowerSeriesOnBall.tendstoUniformlyOn {r' : ℝ≥0} (hf : HasFPowerSeriesOnBall f p x r)
(h : (r' : ℝ≥0∞) < r) :
TendstoUniformlyOn (fun n y => p.partialSum n y) (fun y => f (x + y)) atTop
(Metric.ball (0 : E) r') := by
obtain ⟨a, ha, C, -, hp⟩ : ∃ a ∈ Ioo (0 : ℝ) 1, ∃ C > 0, ∀ y ∈ Metric.ball (0 : E) r', ∀ n,
‖f (x + y) - p.partialSum n y‖ ≤ C * a ^ n := hf.uniform_geometric_approx h
refine Metric.tendstoUniformlyOn_iff.2 fun ε εpos => ?_
have L : Tendsto (fun n => (C : ℝ) * a ^ n) atTop (𝓝 ((C : ℝ) * 0)) :=
tendsto_const_nhds.mul (tendsto_pow_atTop_nhds_zero_of_lt_one ha.1.le ha.2)
rw [mul_zero] at L
refine (L.eventually (gt_mem_nhds εpos)).mono fun n hn y hy => ?_
rw [dist_eq_norm]
exact (hp y hy n).trans_lt hn
#align has_fpower_series_on_ball.tendsto_uniformly_on HasFPowerSeriesOnBall.tendstoUniformlyOn
/-- If a function admits a power series expansion at `x`, then it is the locally uniform limit of
the partial sums of this power series on the disk of convergence, i.e., `f (x + y)`
is the locally uniform limit of `p.partialSum n y` there. -/
theorem HasFPowerSeriesOnBall.tendstoLocallyUniformlyOn (hf : HasFPowerSeriesOnBall f p x r) :
TendstoLocallyUniformlyOn (fun n y => p.partialSum n y) (fun y => f (x + y)) atTop
(EMetric.ball (0 : E) r) := by
intro u hu x hx
rcases ENNReal.lt_iff_exists_nnreal_btwn.1 hx with ⟨r', xr', hr'⟩
have : EMetric.ball (0 : E) r' ∈ 𝓝 x := IsOpen.mem_nhds EMetric.isOpen_ball xr'
refine ⟨EMetric.ball (0 : E) r', mem_nhdsWithin_of_mem_nhds this, ?_⟩
simpa [Metric.emetric_ball_nnreal] using hf.tendstoUniformlyOn hr' u hu
#align has_fpower_series_on_ball.tendsto_locally_uniformly_on HasFPowerSeriesOnBall.tendstoLocallyUniformlyOn
/-- If a function admits a power series expansion at `x`, then it is the uniform limit of the
partial sums of this power series on strict subdisks of the disk of convergence, i.e., `f y`
is the uniform limit of `p.partialSum n (y - x)` there. -/
theorem HasFPowerSeriesOnBall.tendstoUniformlyOn' {r' : ℝ≥0} (hf : HasFPowerSeriesOnBall f p x r)
(h : (r' : ℝ≥0∞) < r) :
TendstoUniformlyOn (fun n y => p.partialSum n (y - x)) f atTop (Metric.ball (x : E) r') := by
convert (hf.tendstoUniformlyOn h).comp fun y => y - x using 1
· simp [(· ∘ ·)]
· ext z
simp [dist_eq_norm]
#align has_fpower_series_on_ball.tendsto_uniformly_on' HasFPowerSeriesOnBall.tendstoUniformlyOn'
/-- If a function admits a power series expansion at `x`, then it is the locally uniform limit of
the partial sums of this power series on the disk of convergence, i.e., `f y`
is the locally uniform limit of `p.partialSum n (y - x)` there. -/
theorem HasFPowerSeriesOnBall.tendstoLocallyUniformlyOn' (hf : HasFPowerSeriesOnBall f p x r) :
TendstoLocallyUniformlyOn (fun n y => p.partialSum n (y - x)) f atTop
(EMetric.ball (x : E) r) := by
have A : ContinuousOn (fun y : E => y - x) (EMetric.ball (x : E) r) :=
(continuous_id.sub continuous_const).continuousOn
convert hf.tendstoLocallyUniformlyOn.comp (fun y : E => y - x) _ A using 1
· ext z
simp
· intro z
simp [edist_eq_coe_nnnorm, edist_eq_coe_nnnorm_sub]
#align has_fpower_series_on_ball.tendsto_locally_uniformly_on' HasFPowerSeriesOnBall.tendstoLocallyUniformlyOn'
/-- If a function admits a power series expansion on a disk, then it is continuous there. -/
protected theorem HasFPowerSeriesOnBall.continuousOn (hf : HasFPowerSeriesOnBall f p x r) :
ContinuousOn f (EMetric.ball x r) :=
hf.tendstoLocallyUniformlyOn'.continuousOn <|
eventually_of_forall fun n =>
((p.partialSum_continuous n).comp (continuous_id.sub continuous_const)).continuousOn
#align has_fpower_series_on_ball.continuous_on HasFPowerSeriesOnBall.continuousOn
protected theorem HasFPowerSeriesAt.continuousAt (hf : HasFPowerSeriesAt f p x) :
ContinuousAt f x :=
let ⟨_, hr⟩ := hf
hr.continuousOn.continuousAt (EMetric.ball_mem_nhds x hr.r_pos)
#align has_fpower_series_at.continuous_at HasFPowerSeriesAt.continuousAt
protected theorem AnalyticAt.continuousAt (hf : AnalyticAt 𝕜 f x) : ContinuousAt f x :=
let ⟨_, hp⟩ := hf
hp.continuousAt
#align analytic_at.continuous_at AnalyticAt.continuousAt
protected theorem AnalyticOn.continuousOn {s : Set E} (hf : AnalyticOn 𝕜 f s) : ContinuousOn f s :=
fun x hx => (hf x hx).continuousAt.continuousWithinAt
#align analytic_on.continuous_on AnalyticOn.continuousOn
/-- Analytic everywhere implies continuous -/
theorem AnalyticOn.continuous {f : E → F} (fa : AnalyticOn 𝕜 f univ) : Continuous f := by
rw [continuous_iff_continuousOn_univ]; exact fa.continuousOn
/-- In a complete space, the sum of a converging power series `p` admits `p` as a power series.
This is not totally obvious as we need to check the convergence of the series. -/
protected theorem FormalMultilinearSeries.hasFPowerSeriesOnBall [CompleteSpace F]
(p : FormalMultilinearSeries 𝕜 E F) (h : 0 < p.radius) :
HasFPowerSeriesOnBall p.sum p 0 p.radius :=
{ r_le := le_rfl
r_pos := h
hasSum := fun hy => by
rw [zero_add]
exact p.hasSum hy }
#align formal_multilinear_series.has_fpower_series_on_ball FormalMultilinearSeries.hasFPowerSeriesOnBall
theorem HasFPowerSeriesOnBall.sum (h : HasFPowerSeriesOnBall f p x r) {y : E}
(hy : y ∈ EMetric.ball (0 : E) r) : f (x + y) = p.sum y :=
(h.hasSum hy).tsum_eq.symm
#align has_fpower_series_on_ball.sum HasFPowerSeriesOnBall.sum
/-- The sum of a converging power series is continuous in its disk of convergence. -/
protected theorem FormalMultilinearSeries.continuousOn [CompleteSpace F] :
ContinuousOn p.sum (EMetric.ball 0 p.radius) := by
rcases (zero_le p.radius).eq_or_lt with h | h
· simp [← h, continuousOn_empty]
· exact (p.hasFPowerSeriesOnBall h).continuousOn
#align formal_multilinear_series.continuous_on FormalMultilinearSeries.continuousOn
end
/-!
### Uniqueness of power series
If a function `f : E → F` has two representations as power series at a point `x : E`, corresponding
to formal multilinear series `p₁` and `p₂`, then these representations agree term-by-term. That is,
for any `n : ℕ` and `y : E`, `p₁ n (fun i ↦ y) = p₂ n (fun i ↦ y)`. In the one-dimensional case,
when `f : 𝕜 → E`, the continuous multilinear maps `p₁ n` and `p₂ n` are given by
`ContinuousMultilinearMap.mkPiRing`, and hence are determined completely by the value of
`p₁ n (fun i ↦ 1)`, so `p₁ = p₂`. Consequently, the radius of convergence for one series can be
transferred to the other.
-/
section Uniqueness
open ContinuousMultilinearMap
theorem Asymptotics.IsBigO.continuousMultilinearMap_apply_eq_zero {n : ℕ} {p : E[×n]→L[𝕜] F}
(h : (fun y => p fun _ => y) =O[𝓝 0] fun y => ‖y‖ ^ (n + 1)) (y : E) : (p fun _ => y) = 0 := by
obtain ⟨c, c_pos, hc⟩ := h.exists_pos
obtain ⟨t, ht, t_open, z_mem⟩ := eventually_nhds_iff.mp (isBigOWith_iff.mp hc)
obtain ⟨δ, δ_pos, δε⟩ := (Metric.isOpen_iff.mp t_open) 0 z_mem
clear h hc z_mem
cases' n with n
· exact norm_eq_zero.mp (by
-- Porting note: the symmetric difference of the `simpa only` sets:
-- added `Nat.zero_eq, zero_add, pow_one`
-- removed `zero_pow, Ne.def, Nat.one_ne_zero, not_false_iff`
simpa only [Nat.zero_eq, fin0_apply_norm, norm_eq_zero, norm_zero, zero_add, pow_one,
mul_zero, norm_le_zero_iff] using ht 0 (δε (Metric.mem_ball_self δ_pos)))
· refine Or.elim (Classical.em (y = 0))
(fun hy => by simpa only [hy] using p.map_zero) fun hy => ?_
replace hy := norm_pos_iff.mpr hy
refine norm_eq_zero.mp (le_antisymm (le_of_forall_pos_le_add fun ε ε_pos => ?_) (norm_nonneg _))
have h₀ := _root_.mul_pos c_pos (pow_pos hy (n.succ + 1))
obtain ⟨k, k_pos, k_norm⟩ := NormedField.exists_norm_lt 𝕜
(lt_min (mul_pos δ_pos (inv_pos.mpr hy)) (mul_pos ε_pos (inv_pos.mpr h₀)))
have h₁ : ‖k • y‖ < δ := by
rw [norm_smul]
exact inv_mul_cancel_right₀ hy.ne.symm δ ▸
mul_lt_mul_of_pos_right (lt_of_lt_of_le k_norm (min_le_left _ _)) hy
have h₂ :=
calc
‖p fun _ => k • y‖ ≤ c * ‖k • y‖ ^ (n.succ + 1) := by
-- Porting note: now Lean wants `_root_.`
simpa only [norm_pow, _root_.norm_norm] using ht (k • y) (δε (mem_ball_zero_iff.mpr h₁))
--simpa only [norm_pow, norm_norm] using ht (k • y) (δε (mem_ball_zero_iff.mpr h₁))
_ = ‖k‖ ^ n.succ * (‖k‖ * (c * ‖y‖ ^ (n.succ + 1))) := by
-- Porting note: added `Nat.succ_eq_add_one` since otherwise `ring` does not conclude.
simp only [norm_smul, mul_pow, Nat.succ_eq_add_one]
-- Porting note: removed `rw [pow_succ]`, since it now becomes superfluous.
ring
have h₃ : ‖k‖ * (c * ‖y‖ ^ (n.succ + 1)) < ε :=
inv_mul_cancel_right₀ h₀.ne.symm ε ▸
mul_lt_mul_of_pos_right (lt_of_lt_of_le k_norm (min_le_right _ _)) h₀
calc
‖p fun _ => y‖ = ‖k⁻¹ ^ n.succ‖ * ‖p fun _ => k • y‖ := by
simpa only [inv_smul_smul₀ (norm_pos_iff.mp k_pos), norm_smul, Finset.prod_const,
Finset.card_fin] using
congr_arg norm (p.map_smul_univ (fun _ : Fin n.succ => k⁻¹) fun _ : Fin n.succ => k • y)
_ ≤ ‖k⁻¹ ^ n.succ‖ * (‖k‖ ^ n.succ * (‖k‖ * (c * ‖y‖ ^ (n.succ + 1)))) := by gcongr
_ = ‖(k⁻¹ * k) ^ n.succ‖ * (‖k‖ * (c * ‖y‖ ^ (n.succ + 1))) := by
rw [← mul_assoc]
simp [norm_mul, mul_pow]
_ ≤ 0 + ε := by
rw [inv_mul_cancel (norm_pos_iff.mp k_pos)]
simpa using h₃.le
set_option linter.uppercaseLean3 false in
#align asymptotics.is_O.continuous_multilinear_map_apply_eq_zero Asymptotics.IsBigO.continuousMultilinearMap_apply_eq_zero
/-- If a formal multilinear series `p` represents the zero function at `x : E`, then the
terms `p n (fun i ↦ y)` appearing in the sum are zero for any `n : ℕ`, `y : E`. -/
theorem HasFPowerSeriesAt.apply_eq_zero {p : FormalMultilinearSeries 𝕜 E F} {x : E}
(h : HasFPowerSeriesAt 0 p x) (n : ℕ) : ∀ y : E, (p n fun _ => y) = 0 := by
refine Nat.strong_induction_on n fun k hk => ?_
have psum_eq : p.partialSum (k + 1) = fun y => p k fun _ => y := by
funext z
refine Finset.sum_eq_single _ (fun b hb hnb => ?_) fun hn => ?_
· have := Finset.mem_range_succ_iff.mp hb
simp only [hk b (this.lt_of_ne hnb), Pi.zero_apply]
· exact False.elim (hn (Finset.mem_range.mpr (lt_add_one k)))
replace h := h.isBigO_sub_partialSum_pow k.succ
simp only [psum_eq, zero_sub, Pi.zero_apply, Asymptotics.isBigO_neg_left] at h
exact h.continuousMultilinearMap_apply_eq_zero
#align has_fpower_series_at.apply_eq_zero HasFPowerSeriesAt.apply_eq_zero
/-- A one-dimensional formal multilinear series representing the zero function is zero. -/
theorem HasFPowerSeriesAt.eq_zero {p : FormalMultilinearSeries 𝕜 𝕜 E} {x : 𝕜}
(h : HasFPowerSeriesAt 0 p x) : p = 0 := by
-- Porting note: `funext; ext` was `ext (n x)`
funext n
ext x
rw [← mkPiRing_apply_one_eq_self (p n)]
simp [h.apply_eq_zero n 1]
#align has_fpower_series_at.eq_zero HasFPowerSeriesAt.eq_zero
/-- One-dimensional formal multilinear series representing the same function are equal. -/
theorem HasFPowerSeriesAt.eq_formalMultilinearSeries {p₁ p₂ : FormalMultilinearSeries 𝕜 𝕜 E}
{f : 𝕜 → E} {x : 𝕜} (h₁ : HasFPowerSeriesAt f p₁ x) (h₂ : HasFPowerSeriesAt f p₂ x) : p₁ = p₂ :=
sub_eq_zero.mp (HasFPowerSeriesAt.eq_zero (by simpa only [sub_self] using h₁.sub h₂))
#align has_fpower_series_at.eq_formal_multilinear_series HasFPowerSeriesAt.eq_formalMultilinearSeries
theorem HasFPowerSeriesAt.eq_formalMultilinearSeries_of_eventually
{p q : FormalMultilinearSeries 𝕜 𝕜 E} {f g : 𝕜 → E} {x : 𝕜} (hp : HasFPowerSeriesAt f p x)
(hq : HasFPowerSeriesAt g q x) (heq : ∀ᶠ z in 𝓝 x, f z = g z) : p = q :=
(hp.congr heq).eq_formalMultilinearSeries hq
#align has_fpower_series_at.eq_formal_multilinear_series_of_eventually HasFPowerSeriesAt.eq_formalMultilinearSeries_of_eventually
/-- A one-dimensional formal multilinear series representing a locally zero function is zero. -/
theorem HasFPowerSeriesAt.eq_zero_of_eventually {p : FormalMultilinearSeries 𝕜 𝕜 E} {f : 𝕜 → E}
{x : 𝕜} (hp : HasFPowerSeriesAt f p x) (hf : f =ᶠ[𝓝 x] 0) : p = 0 :=
(hp.congr hf).eq_zero
#align has_fpower_series_at.eq_zero_of_eventually HasFPowerSeriesAt.eq_zero_of_eventually
/-- If a function `f : 𝕜 → E` has two power series representations at `x`, then the given radii in
which convergence is guaranteed may be interchanged. This can be useful when the formal multilinear
series in one representation has a particularly nice form, but the other has a larger radius. -/
theorem HasFPowerSeriesOnBall.exchange_radius {p₁ p₂ : FormalMultilinearSeries 𝕜 𝕜 E} {f : 𝕜 → E}
{r₁ r₂ : ℝ≥0∞} {x : 𝕜} (h₁ : HasFPowerSeriesOnBall f p₁ x r₁)
(h₂ : HasFPowerSeriesOnBall f p₂ x r₂) : HasFPowerSeriesOnBall f p₁ x r₂ :=
h₂.hasFPowerSeriesAt.eq_formalMultilinearSeries h₁.hasFPowerSeriesAt ▸ h₂
#align has_fpower_series_on_ball.exchange_radius HasFPowerSeriesOnBall.exchange_radius
/-- If a function `f : 𝕜 → E` has power series representation `p` on a ball of some radius and for
each positive radius it has some power series representation, then `p` converges to `f` on the whole
`𝕜`. -/
theorem HasFPowerSeriesOnBall.r_eq_top_of_exists {f : 𝕜 → E} {r : ℝ≥0∞} {x : 𝕜}
{p : FormalMultilinearSeries 𝕜 𝕜 E} (h : HasFPowerSeriesOnBall f p x r)
(h' : ∀ (r' : ℝ≥0) (_ : 0 < r'), ∃ p' : FormalMultilinearSeries 𝕜 𝕜 E,
HasFPowerSeriesOnBall f p' x r') :
HasFPowerSeriesOnBall f p x ∞ :=
{ r_le := ENNReal.le_of_forall_pos_nnreal_lt fun r hr _ =>
let ⟨_, hp'⟩ := h' r hr
(h.exchange_radius hp').r_le
r_pos := ENNReal.coe_lt_top
hasSum := fun {y} _ =>
let ⟨r', hr'⟩ := exists_gt ‖y‖₊
let ⟨_, hp'⟩ := h' r' hr'.ne_bot.bot_lt
(h.exchange_radius hp').hasSum <| mem_emetric_ball_zero_iff.mpr (ENNReal.coe_lt_coe.2 hr') }
#align has_fpower_series_on_ball.r_eq_top_of_exists HasFPowerSeriesOnBall.r_eq_top_of_exists
end Uniqueness
/-!
### Changing origin in a power series
If a function is analytic in a disk `D(x, R)`, then it is analytic in any disk contained in that
one. Indeed, one can write
$$
f (x + y + z) = \sum_{n} p_n (y + z)^n = \sum_{n, k} \binom{n}{k} p_n y^{n-k} z^k
= \sum_{k} \Bigl(\sum_{n} \binom{n}{k} p_n y^{n-k}\Bigr) z^k.
$$
The corresponding power series has thus a `k`-th coefficient equal to
$\sum_{n} \binom{n}{k} p_n y^{n-k}$. In the general case where `pₙ` is a multilinear map, this has
to be interpreted suitably: instead of having a binomial coefficient, one should sum over all
possible subsets `s` of `Fin n` of cardinality `k`, and attribute `z` to the indices in `s` and
`y` to the indices outside of `s`.
In this paragraph, we implement this. The new power series is called `p.changeOrigin y`. Then, we
check its convergence and the fact that its sum coincides with the original sum. The outcome of this
discussion is that the set of points where a function is analytic is open.
-/
namespace FormalMultilinearSeries
section
variable (p : FormalMultilinearSeries 𝕜 E F) {x y : E} {r R : ℝ≥0}
/-- A term of `FormalMultilinearSeries.changeOriginSeries`.
Given a formal multilinear series `p` and a point `x` in its ball of convergence,
`p.changeOrigin x` is a formal multilinear series such that
`p.sum (x+y) = (p.changeOrigin x).sum y` when this makes sense. Each term of `p.changeOrigin x`
is itself an analytic function of `x` given by the series `p.changeOriginSeries`. Each term in
`changeOriginSeries` is the sum of `changeOriginSeriesTerm`'s over all `s` of cardinality `l`.
The definition is such that `p.changeOriginSeriesTerm k l s hs (fun _ ↦ x) (fun _ ↦ y) =
p (k + l) (s.piecewise (fun _ ↦ x) (fun _ ↦ y))`
-/
def changeOriginSeriesTerm (k l : ℕ) (s : Finset (Fin (k + l))) (hs : s.card = l) :
E[×l]→L[𝕜] E[×k]→L[𝕜] F := by
let a := ContinuousMultilinearMap.curryFinFinset 𝕜 E F hs
(by erw [Finset.card_compl, Fintype.card_fin, hs, add_tsub_cancel_right])
exact a (p (k + l))
#align formal_multilinear_series.change_origin_series_term FormalMultilinearSeries.changeOriginSeriesTerm
theorem changeOriginSeriesTerm_apply (k l : ℕ) (s : Finset (Fin (k + l))) (hs : s.card = l)
(x y : E) :
(p.changeOriginSeriesTerm k l s hs (fun _ => x) fun _ => y) =
p (k + l) (s.piecewise (fun _ => x) fun _ => y) :=
ContinuousMultilinearMap.curryFinFinset_apply_const _ _ _ _ _
#align formal_multilinear_series.change_origin_series_term_apply FormalMultilinearSeries.changeOriginSeriesTerm_apply
@[simp]
theorem norm_changeOriginSeriesTerm (k l : ℕ) (s : Finset (Fin (k + l))) (hs : s.card = l) :
‖p.changeOriginSeriesTerm k l s hs‖ = ‖p (k + l)‖ := by
simp only [changeOriginSeriesTerm, LinearIsometryEquiv.norm_map]
#align formal_multilinear_series.norm_change_origin_series_term FormalMultilinearSeries.norm_changeOriginSeriesTerm
@[simp]
theorem nnnorm_changeOriginSeriesTerm (k l : ℕ) (s : Finset (Fin (k + l))) (hs : s.card = l) :
‖p.changeOriginSeriesTerm k l s hs‖₊ = ‖p (k + l)‖₊ := by
simp only [changeOriginSeriesTerm, LinearIsometryEquiv.nnnorm_map]
#align formal_multilinear_series.nnnorm_change_origin_series_term FormalMultilinearSeries.nnnorm_changeOriginSeriesTerm
theorem nnnorm_changeOriginSeriesTerm_apply_le (k l : ℕ) (s : Finset (Fin (k + l)))
(hs : s.card = l) (x y : E) :
‖p.changeOriginSeriesTerm k l s hs (fun _ => x) fun _ => y‖₊ ≤
‖p (k + l)‖₊ * ‖x‖₊ ^ l * ‖y‖₊ ^ k := by
rw [← p.nnnorm_changeOriginSeriesTerm k l s hs, ← Fin.prod_const, ← Fin.prod_const]
apply ContinuousMultilinearMap.le_of_opNNNorm_le
apply ContinuousMultilinearMap.le_opNNNorm
#align formal_multilinear_series.nnnorm_change_origin_series_term_apply_le FormalMultilinearSeries.nnnorm_changeOriginSeriesTerm_apply_le
/-- The power series for `f.changeOrigin k`.
Given a formal multilinear series `p` and a point `x` in its ball of convergence,
`p.changeOrigin x` is a formal multilinear series such that
`p.sum (x+y) = (p.changeOrigin x).sum y` when this makes sense. Its `k`-th term is the sum of
the series `p.changeOriginSeries k`. -/
def changeOriginSeries (k : ℕ) : FormalMultilinearSeries 𝕜 E (E[×k]→L[𝕜] F) := fun l =>
∑ s : { s : Finset (Fin (k + l)) // Finset.card s = l }, p.changeOriginSeriesTerm k l s s.2
#align formal_multilinear_series.change_origin_series FormalMultilinearSeries.changeOriginSeries
theorem nnnorm_changeOriginSeries_le_tsum (k l : ℕ) :
‖p.changeOriginSeries k l‖₊ ≤
∑' _ : { s : Finset (Fin (k + l)) // s.card = l }, ‖p (k + l)‖₊ :=
(nnnorm_sum_le _ (fun t => changeOriginSeriesTerm p k l (Subtype.val t) t.prop)).trans_eq <| by
simp_rw [tsum_fintype, nnnorm_changeOriginSeriesTerm (p := p) (k := k) (l := l)]
#align formal_multilinear_series.nnnorm_change_origin_series_le_tsum FormalMultilinearSeries.nnnorm_changeOriginSeries_le_tsum
theorem nnnorm_changeOriginSeries_apply_le_tsum (k l : ℕ) (x : E) :
‖p.changeOriginSeries k l fun _ => x‖₊ ≤
∑' _ : { s : Finset (Fin (k + l)) // s.card = l }, ‖p (k + l)‖₊ * ‖x‖₊ ^ l := by
rw [NNReal.tsum_mul_right, ← Fin.prod_const]
exact (p.changeOriginSeries k l).le_of_opNNNorm_le _ (p.nnnorm_changeOriginSeries_le_tsum _ _)
#align formal_multilinear_series.nnnorm_change_origin_series_apply_le_tsum FormalMultilinearSeries.nnnorm_changeOriginSeries_apply_le_tsum
/-- Changing the origin of a formal multilinear series `p`, so that
`p.sum (x+y) = (p.changeOrigin x).sum y` when this makes sense.
-/
def changeOrigin (x : E) : FormalMultilinearSeries 𝕜 E F :=
fun k => (p.changeOriginSeries k).sum x
#align formal_multilinear_series.change_origin FormalMultilinearSeries.changeOrigin
/-- An auxiliary equivalence useful in the proofs about
`FormalMultilinearSeries.changeOriginSeries`: the set of triples `(k, l, s)`, where `s` is a
`Finset (Fin (k + l))` of cardinality `l` is equivalent to the set of pairs `(n, s)`, where `s` is a
`Finset (Fin n)`.
The forward map sends `(k, l, s)` to `(k + l, s)` and the inverse map sends `(n, s)` to
`(n - Finset.card s, Finset.card s, s)`. The actual definition is less readable because of problems
with non-definitional equalities. -/
@[simps]
def changeOriginIndexEquiv :
(Σ k l : ℕ, { s : Finset (Fin (k + l)) // s.card = l }) ≃ Σ n : ℕ, Finset (Fin n) where
toFun s := ⟨s.1 + s.2.1, s.2.2⟩
invFun s :=
⟨s.1 - s.2.card, s.2.card,
⟨s.2.map
(finCongr <| (tsub_add_cancel_of_le <| card_finset_fin_le s.2).symm).toEmbedding,
Finset.card_map _⟩⟩
left_inv := by
rintro ⟨k, l, ⟨s : Finset (Fin <| k + l), hs : s.card = l⟩⟩
dsimp only [Subtype.coe_mk]
-- Lean can't automatically generalize `k' = k + l - s.card`, `l' = s.card`, so we explicitly
-- formulate the generalized goal
suffices ∀ k' l', k' = k → l' = l → ∀ (hkl : k + l = k' + l') (hs'),
(⟨k', l', ⟨s.map (finCongr hkl).toEmbedding, hs'⟩⟩ :
Σk l : ℕ, { s : Finset (Fin (k + l)) // s.card = l }) = ⟨k, l, ⟨s, hs⟩⟩ by
apply this <;> simp only [hs, add_tsub_cancel_right]
rintro _ _ rfl rfl hkl hs'
simp only [Equiv.refl_toEmbedding, finCongr_refl, Finset.map_refl, eq_self_iff_true,
OrderIso.refl_toEquiv, and_self_iff, heq_iff_eq]
right_inv := by
rintro ⟨n, s⟩
simp [tsub_add_cancel_of_le (card_finset_fin_le s), finCongr_eq_equivCast]
#align formal_multilinear_series.change_origin_index_equiv FormalMultilinearSeries.changeOriginIndexEquiv
lemma changeOriginSeriesTerm_changeOriginIndexEquiv_symm (n t) :
let s := changeOriginIndexEquiv.symm ⟨n, t⟩
p.changeOriginSeriesTerm s.1 s.2.1 s.2.2 s.2.2.2 (fun _ ↦ x) (fun _ ↦ y) =
p n (t.piecewise (fun _ ↦ x) fun _ ↦ y) := by
have : ∀ (m) (hm : n = m), p n (t.piecewise (fun _ ↦ x) fun _ ↦ y) =
p m ((t.map (finCongr hm).toEmbedding).piecewise (fun _ ↦ x) fun _ ↦ y) := by
rintro m rfl
simp (config := { unfoldPartialApp := true }) [Finset.piecewise]
simp_rw [changeOriginSeriesTerm_apply, eq_comm]; apply this
theorem changeOriginSeries_summable_aux₁ {r r' : ℝ≥0} (hr : (r + r' : ℝ≥0∞) < p.radius) :
Summable fun s : Σk l : ℕ, { s : Finset (Fin (k + l)) // s.card = l } =>
‖p (s.1 + s.2.1)‖₊ * r ^ s.2.1 * r' ^ s.1 := by
rw [← changeOriginIndexEquiv.symm.summable_iff]
dsimp only [Function.comp_def, changeOriginIndexEquiv_symm_apply_fst,
changeOriginIndexEquiv_symm_apply_snd_fst]
have : ∀ n : ℕ,
HasSum (fun s : Finset (Fin n) => ‖p (n - s.card + s.card)‖₊ * r ^ s.card * r' ^ (n - s.card))
(‖p n‖₊ * (r + r') ^ n) := by
intro n
-- TODO: why `simp only [tsub_add_cancel_of_le (card_finset_fin_le _)]` fails?
convert_to HasSum (fun s : Finset (Fin n) => ‖p n‖₊ * (r ^ s.card * r' ^ (n - s.card))) _
· ext1 s
rw [tsub_add_cancel_of_le (card_finset_fin_le _), mul_assoc]
rw [← Fin.sum_pow_mul_eq_add_pow]
exact (hasSum_fintype _).mul_left _
refine NNReal.summable_sigma.2 ⟨fun n => (this n).summable, ?_⟩
simp only [(this _).tsum_eq]
exact p.summable_nnnorm_mul_pow hr
#align formal_multilinear_series.change_origin_series_summable_aux₁ FormalMultilinearSeries.changeOriginSeries_summable_aux₁
theorem changeOriginSeries_summable_aux₂ (hr : (r : ℝ≥0∞) < p.radius) (k : ℕ) :
Summable fun s : Σl : ℕ, { s : Finset (Fin (k + l)) // s.card = l } =>
‖p (k + s.1)‖₊ * r ^ s.1 := by
rcases ENNReal.lt_iff_exists_add_pos_lt.1 hr with ⟨r', h0, hr'⟩
simpa only [mul_inv_cancel_right₀ (pow_pos h0 _).ne'] using
((NNReal.summable_sigma.1 (p.changeOriginSeries_summable_aux₁ hr')).1 k).mul_right (r' ^ k)⁻¹
#align formal_multilinear_series.change_origin_series_summable_aux₂ FormalMultilinearSeries.changeOriginSeries_summable_aux₂
| Mathlib/Analysis/Analytic/Basic.lean | 1,251 | 1,256 | theorem changeOriginSeries_summable_aux₃ {r : ℝ≥0} (hr : ↑r < p.radius) (k : ℕ) :
Summable fun l : ℕ => ‖p.changeOriginSeries k l‖₊ * r ^ l := by |
refine NNReal.summable_of_le
(fun n => ?_) (NNReal.summable_sigma.1 <| p.changeOriginSeries_summable_aux₂ hr k).2
simp only [NNReal.tsum_mul_right]
exact mul_le_mul' (p.nnnorm_changeOriginSeries_le_tsum _ _) le_rfl
|
/-
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, Sébastien Gouëzel, Yury Kudryashov
-/
import Mathlib.Dynamics.Ergodic.MeasurePreserving
import Mathlib.LinearAlgebra.Determinant
import Mathlib.LinearAlgebra.Matrix.Diagonal
import Mathlib.LinearAlgebra.Matrix.Transvection
import Mathlib.MeasureTheory.Group.LIntegral
import Mathlib.MeasureTheory.Integral.Marginal
import Mathlib.MeasureTheory.Measure.Stieltjes
import Mathlib.MeasureTheory.Measure.Haar.OfBasis
#align_import measure_theory.measure.lebesgue.basic from "leanprover-community/mathlib"@"fd5edc43dc4f10b85abfe544b88f82cf13c5f844"
/-!
# Lebesgue measure on the real line and on `ℝⁿ`
We show that the Lebesgue measure on the real line (constructed as a particular case of additive
Haar measure on inner product spaces) coincides with the Stieltjes measure associated
to the function `x ↦ x`. We deduce properties of this measure on `ℝ`, and then of the product
Lebesgue measure on `ℝⁿ`. In particular, we prove that they are translation invariant.
We show that, on `ℝⁿ`, a linear map acts on Lebesgue measure by rescaling it through the absolute
value of its determinant, in `Real.map_linearMap_volume_pi_eq_smul_volume_pi`.
More properties of the Lebesgue measure are deduced from this in
`Mathlib/MeasureTheory/Measure/Lebesgue/EqHaar.lean`, where they are proved more generally for any
additive Haar measure on a finite-dimensional real vector space.
-/
assert_not_exists MeasureTheory.integral
noncomputable section
open scoped Classical
open Set Filter MeasureTheory MeasureTheory.Measure TopologicalSpace
open ENNReal (ofReal)
open scoped ENNReal NNReal Topology
/-!
### Definition of the Lebesgue measure and lengths of intervals
-/
namespace Real
variable {ι : Type*} [Fintype ι]
/-- The volume on the real line (as a particular case of the volume on a finite-dimensional
inner product space) coincides with the Stieltjes measure coming from the identity function. -/
theorem volume_eq_stieltjes_id : (volume : Measure ℝ) = StieltjesFunction.id.measure := by
haveI : IsAddLeftInvariant StieltjesFunction.id.measure :=
⟨fun a =>
Eq.symm <|
Real.measure_ext_Ioo_rat fun p q => by
simp only [Measure.map_apply (measurable_const_add a) measurableSet_Ioo,
sub_sub_sub_cancel_right, StieltjesFunction.measure_Ioo, StieltjesFunction.id_leftLim,
StieltjesFunction.id_apply, id, preimage_const_add_Ioo]⟩
have A : StieltjesFunction.id.measure (stdOrthonormalBasis ℝ ℝ).toBasis.parallelepiped = 1 := by
change StieltjesFunction.id.measure (parallelepiped (stdOrthonormalBasis ℝ ℝ)) = 1
rcases parallelepiped_orthonormalBasis_one_dim (stdOrthonormalBasis ℝ ℝ) with (H | H) <;>
simp only [H, StieltjesFunction.measure_Icc, StieltjesFunction.id_apply, id, tsub_zero,
StieltjesFunction.id_leftLim, sub_neg_eq_add, zero_add, ENNReal.ofReal_one]
conv_rhs =>
rw [addHaarMeasure_unique StieltjesFunction.id.measure
(stdOrthonormalBasis ℝ ℝ).toBasis.parallelepiped, A]
simp only [volume, Basis.addHaar, one_smul]
#align real.volume_eq_stieltjes_id Real.volume_eq_stieltjes_id
| Mathlib/MeasureTheory/Measure/Lebesgue/Basic.lean | 75 | 76 | theorem volume_val (s) : volume s = StieltjesFunction.id.measure s := by |
simp [volume_eq_stieltjes_id]
|
/-
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, Mario Carneiro
-/
import Mathlib.Algebra.GroupWithZero.Divisibility
import Mathlib.Algebra.Order.Group.Int
import Mathlib.Algebra.Order.Ring.Nat
import Mathlib.Algebra.Ring.Rat
import Mathlib.Data.PNat.Defs
#align_import data.rat.lemmas from "leanprover-community/mathlib"@"550b58538991c8977703fdeb7c9d51a5aa27df11"
/-!
# Further lemmas for the Rational Numbers
-/
namespace Rat
open Rat
theorem num_dvd (a) {b : ℤ} (b0 : b ≠ 0) : (a /. b).num ∣ a := by
cases' e : a /. b with n d h c
rw [Rat.mk'_eq_divInt, divInt_eq_iff b0 (mod_cast h)] at e
refine Int.natAbs_dvd.1 <| Int.dvd_natAbs.1 <| Int.natCast_dvd_natCast.2 <|
c.dvd_of_dvd_mul_right ?_
have := congr_arg Int.natAbs e
simp only [Int.natAbs_mul, Int.natAbs_ofNat] at this; simp [this]
#align rat.num_dvd Rat.num_dvd
theorem den_dvd (a b : ℤ) : ((a /. b).den : ℤ) ∣ b := by
by_cases b0 : b = 0; · simp [b0]
cases' e : a /. b with n d h c
rw [mk'_eq_divInt, divInt_eq_iff b0 (ne_of_gt (Int.natCast_pos.2 (Nat.pos_of_ne_zero h)))] at e
refine Int.dvd_natAbs.1 <| Int.natCast_dvd_natCast.2 <| c.symm.dvd_of_dvd_mul_left ?_
rw [← Int.natAbs_mul, ← Int.natCast_dvd_natCast, Int.dvd_natAbs, ← e]; simp
#align rat.denom_dvd Rat.den_dvd
theorem num_den_mk {q : ℚ} {n d : ℤ} (hd : d ≠ 0) (qdf : q = n /. d) :
∃ c : ℤ, n = c * q.num ∧ d = c * q.den := by
obtain rfl | hn := eq_or_ne n 0
· simp [qdf]
have : q.num * d = n * ↑q.den := by
refine (divInt_eq_iff ?_ hd).mp ?_
· exact Int.natCast_ne_zero.mpr (Rat.den_nz _)
· rwa [num_divInt_den]
have hqdn : q.num ∣ n := by
rw [qdf]
exact Rat.num_dvd _ hd
refine ⟨n / q.num, ?_, ?_⟩
· rw [Int.ediv_mul_cancel hqdn]
· refine Int.eq_mul_div_of_mul_eq_mul_of_dvd_left ?_ hqdn this
rw [qdf]
exact Rat.num_ne_zero.2 ((divInt_ne_zero hd).mpr hn)
#align rat.num_denom_mk Rat.num_den_mk
#noalign rat.mk_pnat_num
#noalign rat.mk_pnat_denom
theorem num_mk (n d : ℤ) : (n /. d).num = d.sign * n / n.gcd d := by
have (m : ℕ) : Int.natAbs (m + 1) = m + 1 := by
rw [← Nat.cast_one, ← Nat.cast_add, Int.natAbs_cast]
rcases d with ((_ | _) | _) <;>
rw [← Int.div_eq_ediv_of_dvd] <;>
simp [divInt, mkRat, Rat.normalize, Nat.succPNat, Int.sign, Int.gcd,
Int.zero_ediv, Int.ofNat_dvd_left, Nat.gcd_dvd_left, this]
#align rat.num_mk Rat.num_mk
theorem den_mk (n d : ℤ) : (n /. d).den = if d = 0 then 1 else d.natAbs / n.gcd d := by
have (m : ℕ) : Int.natAbs (m + 1) = m + 1 := by
rw [← Nat.cast_one, ← Nat.cast_add, Int.natAbs_cast]
rcases d with ((_ | _) | _) <;>
simp [divInt, mkRat, Rat.normalize, Nat.succPNat, Int.sign, Int.gcd,
if_neg (Nat.cast_add_one_ne_zero _), this]
#align rat.denom_mk Rat.den_mk
#noalign rat.mk_pnat_denom_dvd
theorem add_den_dvd (q₁ q₂ : ℚ) : (q₁ + q₂).den ∣ q₁.den * q₂.den := by
rw [add_def, normalize_eq]
apply Nat.div_dvd_of_dvd
apply Nat.gcd_dvd_right
#align rat.add_denom_dvd Rat.add_den_dvd
theorem mul_den_dvd (q₁ q₂ : ℚ) : (q₁ * q₂).den ∣ q₁.den * q₂.den := by
rw [mul_def, normalize_eq]
apply Nat.div_dvd_of_dvd
apply Nat.gcd_dvd_right
#align rat.mul_denom_dvd Rat.mul_den_dvd
theorem mul_num (q₁ q₂ : ℚ) :
(q₁ * q₂).num = q₁.num * q₂.num / Nat.gcd (q₁.num * q₂.num).natAbs (q₁.den * q₂.den) := by
rw [mul_def, normalize_eq]
#align rat.mul_num Rat.mul_num
theorem mul_den (q₁ q₂ : ℚ) :
(q₁ * q₂).den =
q₁.den * q₂.den / Nat.gcd (q₁.num * q₂.num).natAbs (q₁.den * q₂.den) := by
rw [mul_def, normalize_eq]
#align rat.mul_denom Rat.mul_den
theorem mul_self_num (q : ℚ) : (q * q).num = q.num * q.num := by
rw [mul_num, Int.natAbs_mul, Nat.Coprime.gcd_eq_one, Int.ofNat_one, Int.ediv_one]
exact (q.reduced.mul_right q.reduced).mul (q.reduced.mul_right q.reduced)
#align rat.mul_self_num Rat.mul_self_num
theorem mul_self_den (q : ℚ) : (q * q).den = q.den * q.den := by
rw [Rat.mul_den, Int.natAbs_mul, Nat.Coprime.gcd_eq_one, Nat.div_one]
exact (q.reduced.mul_right q.reduced).mul (q.reduced.mul_right q.reduced)
#align rat.mul_self_denom Rat.mul_self_den
theorem add_num_den (q r : ℚ) :
q + r = (q.num * r.den + q.den * r.num : ℤ) /. (↑q.den * ↑r.den : ℤ) := by
have hqd : (q.den : ℤ) ≠ 0 := Int.natCast_ne_zero_iff_pos.2 q.den_pos
have hrd : (r.den : ℤ) ≠ 0 := Int.natCast_ne_zero_iff_pos.2 r.den_pos
conv_lhs => rw [← num_divInt_den q, ← num_divInt_den r, divInt_add_divInt _ _ hqd hrd]
rw [mul_comm r.num q.den]
#align rat.add_num_denom Rat.add_num_den
section Casts
theorem exists_eq_mul_div_num_and_eq_mul_div_den (n : ℤ) {d : ℤ} (d_ne_zero : d ≠ 0) :
∃ c : ℤ, n = c * ((n : ℚ) / d).num ∧ (d : ℤ) = c * ((n : ℚ) / d).den :=
haveI : (n : ℚ) / d = Rat.divInt n d := by rw [← Rat.divInt_eq_div]
Rat.num_den_mk d_ne_zero this
#align rat.exists_eq_mul_div_num_and_eq_mul_div_denom Rat.exists_eq_mul_div_num_and_eq_mul_div_den
theorem mul_num_den' (q r : ℚ) :
(q * r).num * q.den * r.den = q.num * r.num * (q * r).den := by
let s := q.num * r.num /. (q.den * r.den : ℤ)
have hs : (q.den * r.den : ℤ) ≠ 0 := Int.natCast_ne_zero_iff_pos.mpr (mul_pos q.pos r.pos)
obtain ⟨c, ⟨c_mul_num, c_mul_den⟩⟩ :=
exists_eq_mul_div_num_and_eq_mul_div_den (q.num * r.num) hs
rw [c_mul_num, mul_assoc, mul_comm]
nth_rw 1 [c_mul_den]
rw [Int.mul_assoc, Int.mul_assoc, mul_eq_mul_left_iff, or_iff_not_imp_right]
intro
have h : _ = s := divInt_mul_divInt q.num r.num (mod_cast q.den_ne_zero) (mod_cast r.den_ne_zero)
rw [num_divInt_den, num_divInt_den] at h
rw [h, mul_comm, ← Rat.eq_iff_mul_eq_mul, ← divInt_eq_div]
#align rat.mul_num_denom' Rat.mul_num_den'
theorem add_num_den' (q r : ℚ) :
(q + r).num * q.den * r.den = (q.num * r.den + r.num * q.den) * (q + r).den := by
let s := divInt (q.num * r.den + r.num * q.den) (q.den * r.den : ℤ)
have hs : (q.den * r.den : ℤ) ≠ 0 := Int.natCast_ne_zero_iff_pos.mpr (mul_pos q.pos r.pos)
obtain ⟨c, ⟨c_mul_num, c_mul_den⟩⟩ :=
exists_eq_mul_div_num_and_eq_mul_div_den (q.num * r.den + r.num * q.den) hs
rw [c_mul_num, mul_assoc, mul_comm]
nth_rw 1 [c_mul_den]
repeat rw [Int.mul_assoc]
apply mul_eq_mul_left_iff.2
rw [or_iff_not_imp_right]
intro
have h : _ = s := divInt_add_divInt q.num r.num (mod_cast q.den_ne_zero) (mod_cast r.den_ne_zero)
rw [num_divInt_den, num_divInt_den] at h
rw [h]
rw [mul_comm]
apply Rat.eq_iff_mul_eq_mul.mp
rw [← divInt_eq_div]
#align rat.add_num_denom' Rat.add_num_den'
theorem substr_num_den' (q r : ℚ) :
(q - r).num * q.den * r.den = (q.num * r.den - r.num * q.den) * (q - r).den := by
rw [sub_eq_add_neg, sub_eq_add_neg, ← neg_mul, ← num_neg_eq_neg_num, ← den_neg_eq_den r,
add_num_den' q (-r)]
#align rat.substr_num_denom' Rat.substr_num_den'
end Casts
protected theorem inv_neg (q : ℚ) : (-q)⁻¹ = -q⁻¹ := by
rw [← num_divInt_den q]
simp only [Rat.neg_divInt, Rat.inv_divInt', eq_self_iff_true, Rat.divInt_neg]
#align rat.inv_neg Rat.inv_neg
theorem num_div_eq_of_coprime {a b : ℤ} (hb0 : 0 < b) (h : Nat.Coprime a.natAbs b.natAbs) :
(a / b : ℚ).num = a := by
-- Porting note: was `lift b to ℕ using le_of_lt hb0`
rw [← Int.natAbs_of_nonneg hb0.le, ← Rat.divInt_eq_div,
← mk_eq_divInt _ _ (Int.natAbs_ne_zero.mpr hb0.ne') h]
#align rat.num_div_eq_of_coprime Rat.num_div_eq_of_coprime
theorem den_div_eq_of_coprime {a b : ℤ} (hb0 : 0 < b) (h : Nat.Coprime a.natAbs b.natAbs) :
((a / b : ℚ).den : ℤ) = b := by
-- Porting note: was `lift b to ℕ using le_of_lt hb0`
rw [← Int.natAbs_of_nonneg hb0.le, ← Rat.divInt_eq_div,
← mk_eq_divInt _ _ (Int.natAbs_ne_zero.mpr hb0.ne') h]
#align rat.denom_div_eq_of_coprime Rat.den_div_eq_of_coprime
theorem div_int_inj {a b c d : ℤ} (hb0 : 0 < b) (hd0 : 0 < d) (h1 : Nat.Coprime a.natAbs b.natAbs)
(h2 : Nat.Coprime c.natAbs d.natAbs) (h : (a : ℚ) / b = (c : ℚ) / d) : a = c ∧ b = d := by
apply And.intro
· rw [← num_div_eq_of_coprime hb0 h1, h, num_div_eq_of_coprime hd0 h2]
· rw [← den_div_eq_of_coprime hb0 h1, h, den_div_eq_of_coprime hd0 h2]
#align rat.div_int_inj Rat.div_int_inj
@[norm_cast]
theorem intCast_div_self (n : ℤ) : ((n / n : ℤ) : ℚ) = n / n := by
by_cases hn : n = 0
· subst hn
simp only [Int.cast_zero, Int.zero_div, zero_div, Int.ediv_zero]
· have : (n : ℚ) ≠ 0 := by rwa [← coe_int_inj] at hn
simp only [Int.ediv_self hn, Int.cast_one, Ne, not_false_iff, div_self this]
#align rat.coe_int_div_self Rat.intCast_div_self
@[norm_cast]
theorem natCast_div_self (n : ℕ) : ((n / n : ℕ) : ℚ) = n / n :=
intCast_div_self n
#align rat.coe_nat_div_self Rat.natCast_div_self
| Mathlib/Data/Rat/Lemmas.lean | 213 | 216 | theorem intCast_div (a b : ℤ) (h : b ∣ a) : ((a / b : ℤ) : ℚ) = a / b := by |
rcases h with ⟨c, rfl⟩
rw [mul_comm b, Int.mul_ediv_assoc c (dvd_refl b), Int.cast_mul,
intCast_div_self, Int.cast_mul, mul_div_assoc]
|
/-
Copyright (c) 2015, 2017 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Robert Y. Lewis, Johannes Hölzl, Mario Carneiro, Sébastien Gouëzel
-/
import Mathlib.Topology.EMetricSpace.Basic
import Mathlib.Topology.Bornology.Constructions
import Mathlib.Data.Set.Pointwise.Interval
import Mathlib.Topology.Order.DenselyOrdered
/-!
## Pseudo-metric spaces
This file defines pseudo-metric spaces: these differ from metric spaces by not imposing the
condition `dist x y = 0 → x = y`.
Many definitions and theorems expected on (pseudo-)metric spaces are already introduced on uniform
spaces and topological spaces. For example: open and closed sets, compactness, completeness,
continuity and uniform continuity.
## Main definitions
* `Dist α`: Endows a space `α` with a function `dist a b`.
* `PseudoMetricSpace α`: A space endowed with a distance function, which can
be zero even if the two elements are non-equal.
* `Metric.ball x ε`: The set of all points `y` with `dist y x < ε`.
* `Metric.Bounded s`: Whether a subset of a `PseudoMetricSpace` is bounded.
* `MetricSpace α`: A `PseudoMetricSpace` with the guarantee `dist x y = 0 → x = y`.
Additional useful definitions:
* `nndist a b`: `dist` as a function to the non-negative reals.
* `Metric.closedBall x ε`: The set of all points `y` with `dist y x ≤ ε`.
* `Metric.sphere x ε`: The set of all points `y` with `dist y x = ε`.
TODO (anyone): Add "Main results" section.
## Tags
pseudo_metric, dist
-/
open Set Filter TopologicalSpace Bornology
open scoped ENNReal NNReal Uniformity Topology
universe u v w
variable {α : Type u} {β : Type v} {X ι : Type*}
theorem UniformSpace.ofDist_aux (ε : ℝ) (hε : 0 < ε) : ∃ δ > (0 : ℝ), ∀ x < δ, ∀ y < δ, x + y < ε :=
⟨ε / 2, half_pos hε, fun _x hx _y hy => add_halves ε ▸ add_lt_add hx hy⟩
/-- Construct a uniform structure from a distance function and metric space axioms -/
def UniformSpace.ofDist (dist : α → α → ℝ) (dist_self : ∀ x : α, dist x x = 0)
(dist_comm : ∀ x y : α, dist x y = dist y x)
(dist_triangle : ∀ x y z : α, dist x z ≤ dist x y + dist y z) : UniformSpace α :=
.ofFun dist dist_self dist_comm dist_triangle ofDist_aux
#align uniform_space_of_dist UniformSpace.ofDist
-- Porting note: dropped the `dist_self` argument
/-- Construct a bornology from a distance function and metric space axioms. -/
abbrev Bornology.ofDist {α : Type*} (dist : α → α → ℝ) (dist_comm : ∀ x y, dist x y = dist y x)
(dist_triangle : ∀ x y z, dist x z ≤ dist x y + dist y z) : Bornology α :=
Bornology.ofBounded { s : Set α | ∃ C, ∀ ⦃x⦄, x ∈ s → ∀ ⦃y⦄, y ∈ s → dist x y ≤ C }
⟨0, fun x hx y => hx.elim⟩ (fun s ⟨c, hc⟩ t h => ⟨c, fun x hx y hy => hc (h hx) (h hy)⟩)
(fun s hs t ht => by
rcases s.eq_empty_or_nonempty with rfl | ⟨x, hx⟩
· rwa [empty_union]
rcases t.eq_empty_or_nonempty with rfl | ⟨y, hy⟩
· rwa [union_empty]
rsuffices ⟨C, hC⟩ : ∃ C, ∀ z ∈ s ∪ t, dist x z ≤ C
· refine ⟨C + C, fun a ha b hb => (dist_triangle a x b).trans ?_⟩
simpa only [dist_comm] using add_le_add (hC _ ha) (hC _ hb)
rcases hs with ⟨Cs, hs⟩; rcases ht with ⟨Ct, ht⟩
refine ⟨max Cs (dist x y + Ct), fun z hz => hz.elim
(fun hz => (hs hx hz).trans (le_max_left _ _))
(fun hz => (dist_triangle x y z).trans <|
(add_le_add le_rfl (ht hy hz)).trans (le_max_right _ _))⟩)
fun z => ⟨dist z z, forall_eq.2 <| forall_eq.2 le_rfl⟩
#align bornology.of_dist Bornology.ofDistₓ
/-- The distance function (given an ambient metric space on `α`), which returns
a nonnegative real number `dist x y` given `x y : α`. -/
@[ext]
class Dist (α : Type*) where
dist : α → α → ℝ
#align has_dist Dist
export Dist (dist)
-- the uniform structure and the emetric space structure are embedded in the metric space structure
-- to avoid instance diamond issues. See Note [forgetful inheritance].
/-- This is an internal lemma used inside the default of `PseudoMetricSpace.edist`. -/
private theorem dist_nonneg' {α} {x y : α} (dist : α → α → ℝ)
(dist_self : ∀ x : α, dist x x = 0) (dist_comm : ∀ x y : α, dist x y = dist y x)
(dist_triangle : ∀ x y z : α, dist x z ≤ dist x y + dist y z) : 0 ≤ dist x y :=
have : 0 ≤ 2 * dist x y :=
calc 0 = dist x x := (dist_self _).symm
_ ≤ dist x y + dist y x := dist_triangle _ _ _
_ = 2 * dist x y := by rw [two_mul, dist_comm]
nonneg_of_mul_nonneg_right this two_pos
#noalign pseudo_metric_space.edist_dist_tac -- Porting note (#11215): TODO: restore
/-- Pseudo metric and Metric spaces
A pseudo metric space is endowed with a distance for which the requirement `d(x,y)=0 → x = y` might
not hold. A metric space is a pseudo metric space such that `d(x,y)=0 → x = y`.
Each pseudo metric space induces a canonical `UniformSpace` and hence a canonical
`TopologicalSpace` This is enforced in the type class definition, by extending the `UniformSpace`
structure. When instantiating a `PseudoMetricSpace` structure, the uniformity fields are not
necessary, they will be filled in by default. In the same way, each (pseudo) metric space induces a
(pseudo) emetric space structure. It is included in the structure, but filled in by default.
-/
class PseudoMetricSpace (α : Type u) extends Dist α : Type u where
dist_self : ∀ x : α, dist x x = 0
dist_comm : ∀ x y : α, dist x y = dist y x
dist_triangle : ∀ x y z : α, dist x z ≤ dist x y + dist y z
edist : α → α → ℝ≥0∞ := fun x y => ENNReal.ofNNReal ⟨dist x y, dist_nonneg' _ ‹_› ‹_› ‹_›⟩
edist_dist : ∀ x y : α, edist x y = ENNReal.ofReal (dist x y)
-- Porting note (#11215): TODO: add := by _
toUniformSpace : UniformSpace α := .ofDist dist dist_self dist_comm dist_triangle
uniformity_dist : 𝓤 α = ⨅ ε > 0, 𝓟 { p : α × α | dist p.1 p.2 < ε } := by intros; rfl
toBornology : Bornology α := Bornology.ofDist dist dist_comm dist_triangle
cobounded_sets : (Bornology.cobounded α).sets =
{ s | ∃ C : ℝ, ∀ x ∈ sᶜ, ∀ y ∈ sᶜ, dist x y ≤ C } := by intros; rfl
#align pseudo_metric_space PseudoMetricSpace
/-- Two pseudo metric space structures with the same distance function coincide. -/
@[ext]
theorem PseudoMetricSpace.ext {α : Type*} {m m' : PseudoMetricSpace α}
(h : m.toDist = m'.toDist) : m = m' := by
cases' m with d _ _ _ ed hed U hU B hB
cases' m' with d' _ _ _ ed' hed' U' hU' B' hB'
obtain rfl : d = d' := h
congr
· ext x y : 2
rw [hed, hed']
· exact UniformSpace.ext (hU.trans hU'.symm)
· ext : 2
rw [← Filter.mem_sets, ← Filter.mem_sets, hB, hB']
#align pseudo_metric_space.ext PseudoMetricSpace.ext
variable [PseudoMetricSpace α]
attribute [instance] PseudoMetricSpace.toUniformSpace PseudoMetricSpace.toBornology
-- see Note [lower instance priority]
instance (priority := 200) PseudoMetricSpace.toEDist : EDist α :=
⟨PseudoMetricSpace.edist⟩
#align pseudo_metric_space.to_has_edist PseudoMetricSpace.toEDist
/-- Construct a pseudo-metric space structure whose underlying topological space structure
(definitionally) agrees which a pre-existing topology which is compatible with a given distance
function. -/
def PseudoMetricSpace.ofDistTopology {α : Type u} [TopologicalSpace α] (dist : α → α → ℝ)
(dist_self : ∀ x : α, dist x x = 0) (dist_comm : ∀ x y : α, dist x y = dist y x)
(dist_triangle : ∀ x y z : α, dist x z ≤ dist x y + dist y z)
(H : ∀ s : Set α, IsOpen s ↔ ∀ x ∈ s, ∃ ε > 0, ∀ y, dist x y < ε → y ∈ s) :
PseudoMetricSpace α :=
{ dist := dist
dist_self := dist_self
dist_comm := dist_comm
dist_triangle := dist_triangle
edist_dist := fun x y => by exact ENNReal.coe_nnreal_eq _
toUniformSpace :=
(UniformSpace.ofDist dist dist_self dist_comm dist_triangle).replaceTopology <|
TopologicalSpace.ext_iff.2 fun s ↦ (H s).trans <| forall₂_congr fun x _ ↦
((UniformSpace.hasBasis_ofFun (exists_gt (0 : ℝ)) dist dist_self dist_comm dist_triangle
UniformSpace.ofDist_aux).comap (Prod.mk x)).mem_iff.symm
uniformity_dist := rfl
toBornology := Bornology.ofDist dist dist_comm dist_triangle
cobounded_sets := rfl }
#align pseudo_metric_space.of_dist_topology PseudoMetricSpace.ofDistTopology
@[simp]
theorem dist_self (x : α) : dist x x = 0 :=
PseudoMetricSpace.dist_self x
#align dist_self dist_self
theorem dist_comm (x y : α) : dist x y = dist y x :=
PseudoMetricSpace.dist_comm x y
#align dist_comm dist_comm
theorem edist_dist (x y : α) : edist x y = ENNReal.ofReal (dist x y) :=
PseudoMetricSpace.edist_dist x y
#align edist_dist edist_dist
theorem dist_triangle (x y z : α) : dist x z ≤ dist x y + dist y z :=
PseudoMetricSpace.dist_triangle x y z
#align dist_triangle dist_triangle
theorem dist_triangle_left (x y z : α) : dist x y ≤ dist z x + dist z y := by
rw [dist_comm z]; apply dist_triangle
#align dist_triangle_left dist_triangle_left
theorem dist_triangle_right (x y z : α) : dist x y ≤ dist x z + dist y z := by
rw [dist_comm y]; apply dist_triangle
#align dist_triangle_right dist_triangle_right
theorem dist_triangle4 (x y z w : α) : dist x w ≤ dist x y + dist y z + dist z w :=
calc
dist x w ≤ dist x z + dist z w := dist_triangle x z w
_ ≤ dist x y + dist y z + dist z w := add_le_add_right (dist_triangle x y z) _
#align dist_triangle4 dist_triangle4
theorem dist_triangle4_left (x₁ y₁ x₂ y₂ : α) :
dist x₂ y₂ ≤ dist x₁ y₁ + (dist x₁ x₂ + dist y₁ y₂) := by
rw [add_left_comm, dist_comm x₁, ← add_assoc]
apply dist_triangle4
#align dist_triangle4_left dist_triangle4_left
theorem dist_triangle4_right (x₁ y₁ x₂ y₂ : α) :
dist x₁ y₁ ≤ dist x₁ x₂ + dist y₁ y₂ + dist x₂ y₂ := by
rw [add_right_comm, dist_comm y₁]
apply dist_triangle4
#align dist_triangle4_right dist_triangle4_right
/-- The triangle (polygon) inequality for sequences of points; `Finset.Ico` version. -/
theorem dist_le_Ico_sum_dist (f : ℕ → α) {m n} (h : m ≤ n) :
dist (f m) (f n) ≤ ∑ i ∈ Finset.Ico m n, dist (f i) (f (i + 1)) := by
induction n, h using Nat.le_induction with
| base => rw [Finset.Ico_self, Finset.sum_empty, dist_self]
| succ n hle ihn =>
calc
dist (f m) (f (n + 1)) ≤ dist (f m) (f n) + dist (f n) (f (n + 1)) := dist_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 }
#align dist_le_Ico_sum_dist dist_le_Ico_sum_dist
/-- The triangle (polygon) inequality for sequences of points; `Finset.range` version. -/
theorem dist_le_range_sum_dist (f : ℕ → α) (n : ℕ) :
dist (f 0) (f n) ≤ ∑ i ∈ Finset.range n, dist (f i) (f (i + 1)) :=
Nat.Ico_zero_eq_range ▸ dist_le_Ico_sum_dist f (Nat.zero_le n)
#align dist_le_range_sum_dist dist_le_range_sum_dist
/-- A version of `dist_le_Ico_sum_dist` with each intermediate distance replaced
with an upper estimate. -/
theorem dist_le_Ico_sum_of_dist_le {f : ℕ → α} {m n} (hmn : m ≤ n) {d : ℕ → ℝ}
(hd : ∀ {k}, m ≤ k → k < n → dist (f k) (f (k + 1)) ≤ d k) :
dist (f m) (f n) ≤ ∑ i ∈ Finset.Ico m n, d i :=
le_trans (dist_le_Ico_sum_dist f hmn) <|
Finset.sum_le_sum fun _k hk => hd (Finset.mem_Ico.1 hk).1 (Finset.mem_Ico.1 hk).2
#align dist_le_Ico_sum_of_dist_le dist_le_Ico_sum_of_dist_le
/-- A version of `dist_le_range_sum_dist` with each intermediate distance replaced
with an upper estimate. -/
theorem dist_le_range_sum_of_dist_le {f : ℕ → α} (n : ℕ) {d : ℕ → ℝ}
(hd : ∀ {k}, k < n → dist (f k) (f (k + 1)) ≤ d k) :
dist (f 0) (f n) ≤ ∑ i ∈ Finset.range n, d i :=
Nat.Ico_zero_eq_range ▸ dist_le_Ico_sum_of_dist_le (zero_le n) fun _ => hd
#align dist_le_range_sum_of_dist_le dist_le_range_sum_of_dist_le
theorem swap_dist : Function.swap (@dist α _) = dist := by funext x y; exact dist_comm _ _
#align swap_dist swap_dist
theorem abs_dist_sub_le (x y z : α) : |dist x z - dist y z| ≤ dist x y :=
abs_sub_le_iff.2
⟨sub_le_iff_le_add.2 (dist_triangle _ _ _), sub_le_iff_le_add.2 (dist_triangle_left _ _ _)⟩
#align abs_dist_sub_le abs_dist_sub_le
theorem dist_nonneg {x y : α} : 0 ≤ dist x y :=
dist_nonneg' dist dist_self dist_comm dist_triangle
#align dist_nonneg dist_nonneg
namespace Mathlib.Meta.Positivity
open Lean Meta Qq Function
/-- Extension for the `positivity` tactic: distances are nonnegative. -/
@[positivity Dist.dist _ _]
def evalDist : PositivityExt where eval {u α} _zα _pα e := do
match u, α, e with
| 0, ~q(ℝ), ~q(@Dist.dist $β $inst $a $b) =>
let _inst ← synthInstanceQ q(PseudoMetricSpace $β)
assertInstancesCommute
pure (.nonnegative q(dist_nonneg))
| _, _, _ => throwError "not dist"
end Mathlib.Meta.Positivity
example {x y : α} : 0 ≤ dist x y := by positivity
@[simp] theorem abs_dist {a b : α} : |dist a b| = dist a b := abs_of_nonneg dist_nonneg
#align abs_dist abs_dist
/-- A version of `Dist` that takes value in `ℝ≥0`. -/
class NNDist (α : Type*) where
nndist : α → α → ℝ≥0
#align has_nndist NNDist
export NNDist (nndist)
-- see Note [lower instance priority]
/-- Distance as a nonnegative real number. -/
instance (priority := 100) PseudoMetricSpace.toNNDist : NNDist α :=
⟨fun a b => ⟨dist a b, dist_nonneg⟩⟩
#align pseudo_metric_space.to_has_nndist PseudoMetricSpace.toNNDist
/-- Express `dist` in terms of `nndist`-/
theorem dist_nndist (x y : α) : dist x y = nndist x y := rfl
#align dist_nndist dist_nndist
@[simp, norm_cast]
theorem coe_nndist (x y : α) : ↑(nndist x y) = dist x y := rfl
#align coe_nndist coe_nndist
/-- Express `edist` in terms of `nndist`-/
theorem edist_nndist (x y : α) : edist x y = nndist x y := by
rw [edist_dist, dist_nndist, ENNReal.ofReal_coe_nnreal]
#align edist_nndist edist_nndist
/-- Express `nndist` in terms of `edist`-/
theorem nndist_edist (x y : α) : nndist x y = (edist x y).toNNReal := by
simp [edist_nndist]
#align nndist_edist nndist_edist
@[simp, norm_cast]
theorem coe_nnreal_ennreal_nndist (x y : α) : ↑(nndist x y) = edist x y :=
(edist_nndist x y).symm
#align coe_nnreal_ennreal_nndist coe_nnreal_ennreal_nndist
@[simp, norm_cast]
theorem edist_lt_coe {x y : α} {c : ℝ≥0} : edist x y < c ↔ nndist x y < c := by
rw [edist_nndist, ENNReal.coe_lt_coe]
#align edist_lt_coe edist_lt_coe
@[simp, norm_cast]
theorem edist_le_coe {x y : α} {c : ℝ≥0} : edist x y ≤ c ↔ nndist x y ≤ c := by
rw [edist_nndist, ENNReal.coe_le_coe]
#align edist_le_coe edist_le_coe
/-- In a pseudometric space, the extended distance is always finite-/
theorem edist_lt_top {α : Type*} [PseudoMetricSpace α] (x y : α) : edist x y < ⊤ :=
(edist_dist x y).symm ▸ ENNReal.ofReal_lt_top
#align edist_lt_top edist_lt_top
/-- In a pseudometric space, the extended distance is always finite-/
theorem edist_ne_top (x y : α) : edist x y ≠ ⊤ :=
(edist_lt_top x y).ne
#align edist_ne_top edist_ne_top
/-- `nndist x x` vanishes-/
@[simp] theorem nndist_self (a : α) : nndist a a = 0 := NNReal.coe_eq_zero.1 (dist_self a)
#align nndist_self nndist_self
-- Porting note: `dist_nndist` and `coe_nndist` moved up
@[simp, norm_cast]
theorem dist_lt_coe {x y : α} {c : ℝ≥0} : dist x y < c ↔ nndist x y < c :=
Iff.rfl
#align dist_lt_coe dist_lt_coe
@[simp, norm_cast]
theorem dist_le_coe {x y : α} {c : ℝ≥0} : dist x y ≤ c ↔ nndist x y ≤ c :=
Iff.rfl
#align dist_le_coe dist_le_coe
@[simp]
theorem edist_lt_ofReal {x y : α} {r : ℝ} : edist x y < ENNReal.ofReal r ↔ dist x y < r := by
rw [edist_dist, ENNReal.ofReal_lt_ofReal_iff_of_nonneg dist_nonneg]
#align edist_lt_of_real edist_lt_ofReal
@[simp]
theorem edist_le_ofReal {x y : α} {r : ℝ} (hr : 0 ≤ r) :
edist x y ≤ ENNReal.ofReal r ↔ dist x y ≤ r := by
rw [edist_dist, ENNReal.ofReal_le_ofReal_iff hr]
#align edist_le_of_real edist_le_ofReal
/-- Express `nndist` in terms of `dist`-/
theorem nndist_dist (x y : α) : nndist x y = Real.toNNReal (dist x y) := by
rw [dist_nndist, Real.toNNReal_coe]
#align nndist_dist nndist_dist
theorem nndist_comm (x y : α) : nndist x y = nndist y x := NNReal.eq <| dist_comm x y
#align nndist_comm nndist_comm
/-- Triangle inequality for the nonnegative distance-/
theorem nndist_triangle (x y z : α) : nndist x z ≤ nndist x y + nndist y z :=
dist_triangle _ _ _
#align nndist_triangle nndist_triangle
theorem nndist_triangle_left (x y z : α) : nndist x y ≤ nndist z x + nndist z y :=
dist_triangle_left _ _ _
#align nndist_triangle_left nndist_triangle_left
theorem nndist_triangle_right (x y z : α) : nndist x y ≤ nndist x z + nndist y z :=
dist_triangle_right _ _ _
#align nndist_triangle_right nndist_triangle_right
/-- Express `dist` in terms of `edist`-/
theorem dist_edist (x y : α) : dist x y = (edist x y).toReal := by
rw [edist_dist, ENNReal.toReal_ofReal dist_nonneg]
#align dist_edist dist_edist
namespace Metric
-- instantiate pseudometric space as a topology
variable {x y z : α} {δ ε ε₁ ε₂ : ℝ} {s : Set α}
/-- `ball x ε` is the set of all points `y` with `dist y x < ε` -/
def ball (x : α) (ε : ℝ) : Set α :=
{ y | dist y x < ε }
#align metric.ball Metric.ball
@[simp]
theorem mem_ball : y ∈ ball x ε ↔ dist y x < ε :=
Iff.rfl
#align metric.mem_ball Metric.mem_ball
theorem mem_ball' : y ∈ ball x ε ↔ dist x y < ε := by rw [dist_comm, mem_ball]
#align metric.mem_ball' Metric.mem_ball'
theorem pos_of_mem_ball (hy : y ∈ ball x ε) : 0 < ε :=
dist_nonneg.trans_lt hy
#align metric.pos_of_mem_ball Metric.pos_of_mem_ball
theorem mem_ball_self (h : 0 < ε) : x ∈ ball x ε := by
rwa [mem_ball, dist_self]
#align metric.mem_ball_self Metric.mem_ball_self
@[simp]
theorem nonempty_ball : (ball x ε).Nonempty ↔ 0 < ε :=
⟨fun ⟨_x, hx⟩ => pos_of_mem_ball hx, fun h => ⟨x, mem_ball_self h⟩⟩
#align metric.nonempty_ball Metric.nonempty_ball
@[simp]
theorem ball_eq_empty : ball x ε = ∅ ↔ ε ≤ 0 := by
rw [← not_nonempty_iff_eq_empty, nonempty_ball, not_lt]
#align metric.ball_eq_empty Metric.ball_eq_empty
@[simp]
theorem ball_zero : ball x 0 = ∅ := by rw [ball_eq_empty]
#align metric.ball_zero Metric.ball_zero
/-- If a point belongs to an open ball, then there is a strictly smaller radius whose ball also
contains it.
See also `exists_lt_subset_ball`. -/
theorem exists_lt_mem_ball_of_mem_ball (h : x ∈ ball y ε) : ∃ ε' < ε, x ∈ ball y ε' := by
simp only [mem_ball] at h ⊢
exact ⟨(dist x y + ε) / 2, by linarith, by linarith⟩
#align metric.exists_lt_mem_ball_of_mem_ball Metric.exists_lt_mem_ball_of_mem_ball
theorem ball_eq_ball (ε : ℝ) (x : α) :
UniformSpace.ball x { p | dist p.2 p.1 < ε } = Metric.ball x ε :=
rfl
#align metric.ball_eq_ball Metric.ball_eq_ball
theorem ball_eq_ball' (ε : ℝ) (x : α) :
UniformSpace.ball x { p | dist p.1 p.2 < ε } = Metric.ball x ε := by
ext
simp [dist_comm, UniformSpace.ball]
#align metric.ball_eq_ball' Metric.ball_eq_ball'
@[simp]
theorem iUnion_ball_nat (x : α) : ⋃ n : ℕ, ball x n = univ :=
iUnion_eq_univ_iff.2 fun y => exists_nat_gt (dist y x)
#align metric.Union_ball_nat Metric.iUnion_ball_nat
@[simp]
theorem iUnion_ball_nat_succ (x : α) : ⋃ n : ℕ, ball x (n + 1) = univ :=
iUnion_eq_univ_iff.2 fun y => (exists_nat_gt (dist y x)).imp fun _ h => h.trans (lt_add_one _)
#align metric.Union_ball_nat_succ Metric.iUnion_ball_nat_succ
/-- `closedBall x ε` is the set of all points `y` with `dist y x ≤ ε` -/
def closedBall (x : α) (ε : ℝ) :=
{ y | dist y x ≤ ε }
#align metric.closed_ball Metric.closedBall
@[simp] theorem mem_closedBall : y ∈ closedBall x ε ↔ dist y x ≤ ε := Iff.rfl
#align metric.mem_closed_ball Metric.mem_closedBall
theorem mem_closedBall' : y ∈ closedBall x ε ↔ dist x y ≤ ε := by rw [dist_comm, mem_closedBall]
#align metric.mem_closed_ball' Metric.mem_closedBall'
/-- `sphere x ε` is the set of all points `y` with `dist y x = ε` -/
def sphere (x : α) (ε : ℝ) := { y | dist y x = ε }
#align metric.sphere Metric.sphere
@[simp] theorem mem_sphere : y ∈ sphere x ε ↔ dist y x = ε := Iff.rfl
#align metric.mem_sphere Metric.mem_sphere
theorem mem_sphere' : y ∈ sphere x ε ↔ dist x y = ε := by rw [dist_comm, mem_sphere]
#align metric.mem_sphere' Metric.mem_sphere'
theorem ne_of_mem_sphere (h : y ∈ sphere x ε) (hε : ε ≠ 0) : y ≠ x :=
ne_of_mem_of_not_mem h <| by simpa using hε.symm
#align metric.ne_of_mem_sphere Metric.ne_of_mem_sphere
theorem nonneg_of_mem_sphere (hy : y ∈ sphere x ε) : 0 ≤ ε :=
dist_nonneg.trans_eq hy
#align metric.nonneg_of_mem_sphere Metric.nonneg_of_mem_sphere
@[simp]
theorem sphere_eq_empty_of_neg (hε : ε < 0) : sphere x ε = ∅ :=
Set.eq_empty_iff_forall_not_mem.mpr fun _y hy => (nonneg_of_mem_sphere hy).not_lt hε
#align metric.sphere_eq_empty_of_neg Metric.sphere_eq_empty_of_neg
theorem sphere_eq_empty_of_subsingleton [Subsingleton α] (hε : ε ≠ 0) : sphere x ε = ∅ :=
Set.eq_empty_iff_forall_not_mem.mpr fun _ h => ne_of_mem_sphere h hε (Subsingleton.elim _ _)
#align metric.sphere_eq_empty_of_subsingleton Metric.sphere_eq_empty_of_subsingleton
instance sphere_isEmpty_of_subsingleton [Subsingleton α] [NeZero ε] : IsEmpty (sphere x ε) := by
rw [sphere_eq_empty_of_subsingleton (NeZero.ne ε)]; infer_instance
#align metric.sphere_is_empty_of_subsingleton Metric.sphere_isEmpty_of_subsingleton
theorem mem_closedBall_self (h : 0 ≤ ε) : x ∈ closedBall x ε := by
rwa [mem_closedBall, dist_self]
#align metric.mem_closed_ball_self Metric.mem_closedBall_self
@[simp]
theorem nonempty_closedBall : (closedBall x ε).Nonempty ↔ 0 ≤ ε :=
⟨fun ⟨_x, hx⟩ => dist_nonneg.trans hx, fun h => ⟨x, mem_closedBall_self h⟩⟩
#align metric.nonempty_closed_ball Metric.nonempty_closedBall
@[simp]
theorem closedBall_eq_empty : closedBall x ε = ∅ ↔ ε < 0 := by
rw [← not_nonempty_iff_eq_empty, nonempty_closedBall, not_le]
#align metric.closed_ball_eq_empty Metric.closedBall_eq_empty
/-- Closed balls and spheres coincide when the radius is non-positive -/
theorem closedBall_eq_sphere_of_nonpos (hε : ε ≤ 0) : closedBall x ε = sphere x ε :=
Set.ext fun _ => (hε.trans dist_nonneg).le_iff_eq
#align metric.closed_ball_eq_sphere_of_nonpos Metric.closedBall_eq_sphere_of_nonpos
theorem ball_subset_closedBall : ball x ε ⊆ closedBall x ε := fun _y hy =>
mem_closedBall.2 (le_of_lt hy)
#align metric.ball_subset_closed_ball Metric.ball_subset_closedBall
theorem sphere_subset_closedBall : sphere x ε ⊆ closedBall x ε := fun _ => le_of_eq
#align metric.sphere_subset_closed_ball Metric.sphere_subset_closedBall
lemma sphere_subset_ball {r R : ℝ} (h : r < R) : sphere x r ⊆ ball x R := fun _x hx ↦
(mem_sphere.1 hx).trans_lt h
theorem closedBall_disjoint_ball (h : δ + ε ≤ dist x y) : Disjoint (closedBall x δ) (ball y ε) :=
Set.disjoint_left.mpr fun _a ha1 ha2 =>
(h.trans <| dist_triangle_left _ _ _).not_lt <| add_lt_add_of_le_of_lt ha1 ha2
#align metric.closed_ball_disjoint_ball Metric.closedBall_disjoint_ball
theorem ball_disjoint_closedBall (h : δ + ε ≤ dist x y) : Disjoint (ball x δ) (closedBall y ε) :=
(closedBall_disjoint_ball <| by rwa [add_comm, dist_comm]).symm
#align metric.ball_disjoint_closed_ball Metric.ball_disjoint_closedBall
theorem ball_disjoint_ball (h : δ + ε ≤ dist x y) : Disjoint (ball x δ) (ball y ε) :=
(closedBall_disjoint_ball h).mono_left ball_subset_closedBall
#align metric.ball_disjoint_ball Metric.ball_disjoint_ball
theorem closedBall_disjoint_closedBall (h : δ + ε < dist x y) :
Disjoint (closedBall x δ) (closedBall y ε) :=
Set.disjoint_left.mpr fun _a ha1 ha2 =>
h.not_le <| (dist_triangle_left _ _ _).trans <| add_le_add ha1 ha2
#align metric.closed_ball_disjoint_closed_ball Metric.closedBall_disjoint_closedBall
theorem sphere_disjoint_ball : Disjoint (sphere x ε) (ball x ε) :=
Set.disjoint_left.mpr fun _y hy₁ hy₂ => absurd hy₁ <| ne_of_lt hy₂
#align metric.sphere_disjoint_ball Metric.sphere_disjoint_ball
@[simp]
theorem ball_union_sphere : ball x ε ∪ sphere x ε = closedBall x ε :=
Set.ext fun _y => (@le_iff_lt_or_eq ℝ _ _ _).symm
#align metric.ball_union_sphere Metric.ball_union_sphere
@[simp]
theorem sphere_union_ball : sphere x ε ∪ ball x ε = closedBall x ε := by
rw [union_comm, ball_union_sphere]
#align metric.sphere_union_ball Metric.sphere_union_ball
@[simp]
theorem closedBall_diff_sphere : closedBall x ε \ sphere x ε = ball x ε := by
rw [← ball_union_sphere, Set.union_diff_cancel_right sphere_disjoint_ball.symm.le_bot]
#align metric.closed_ball_diff_sphere Metric.closedBall_diff_sphere
@[simp]
theorem closedBall_diff_ball : closedBall x ε \ ball x ε = sphere x ε := by
rw [← ball_union_sphere, Set.union_diff_cancel_left sphere_disjoint_ball.symm.le_bot]
#align metric.closed_ball_diff_ball Metric.closedBall_diff_ball
theorem mem_ball_comm : x ∈ ball y ε ↔ y ∈ ball x ε := by rw [mem_ball', mem_ball]
#align metric.mem_ball_comm Metric.mem_ball_comm
theorem mem_closedBall_comm : x ∈ closedBall y ε ↔ y ∈ closedBall x ε := by
rw [mem_closedBall', mem_closedBall]
#align metric.mem_closed_ball_comm Metric.mem_closedBall_comm
theorem mem_sphere_comm : x ∈ sphere y ε ↔ y ∈ sphere x ε := by rw [mem_sphere', mem_sphere]
#align metric.mem_sphere_comm Metric.mem_sphere_comm
@[gcongr]
theorem ball_subset_ball (h : ε₁ ≤ ε₂) : ball x ε₁ ⊆ ball x ε₂ := fun _y yx =>
lt_of_lt_of_le (mem_ball.1 yx) h
#align metric.ball_subset_ball Metric.ball_subset_ball
theorem closedBall_eq_bInter_ball : closedBall x ε = ⋂ δ > ε, ball x δ := by
ext y; rw [mem_closedBall, ← forall_lt_iff_le', mem_iInter₂]; rfl
#align metric.closed_ball_eq_bInter_ball Metric.closedBall_eq_bInter_ball
theorem ball_subset_ball' (h : ε₁ + dist x y ≤ ε₂) : ball x ε₁ ⊆ ball y ε₂ := fun z hz =>
calc
dist z y ≤ dist z x + dist x y := dist_triangle _ _ _
_ < ε₁ + dist x y := add_lt_add_right (mem_ball.1 hz) _
_ ≤ ε₂ := h
#align metric.ball_subset_ball' Metric.ball_subset_ball'
@[gcongr]
theorem closedBall_subset_closedBall (h : ε₁ ≤ ε₂) : closedBall x ε₁ ⊆ closedBall x ε₂ :=
fun _y (yx : _ ≤ ε₁) => le_trans yx h
#align metric.closed_ball_subset_closed_ball Metric.closedBall_subset_closedBall
theorem closedBall_subset_closedBall' (h : ε₁ + dist x y ≤ ε₂) :
closedBall x ε₁ ⊆ closedBall y ε₂ := fun z hz =>
calc
dist z y ≤ dist z x + dist x y := dist_triangle _ _ _
_ ≤ ε₁ + dist x y := add_le_add_right (mem_closedBall.1 hz) _
_ ≤ ε₂ := h
#align metric.closed_ball_subset_closed_ball' Metric.closedBall_subset_closedBall'
theorem closedBall_subset_ball (h : ε₁ < ε₂) : closedBall x ε₁ ⊆ ball x ε₂ :=
fun y (yh : dist y x ≤ ε₁) => lt_of_le_of_lt yh h
#align metric.closed_ball_subset_ball Metric.closedBall_subset_ball
theorem closedBall_subset_ball' (h : ε₁ + dist x y < ε₂) :
closedBall x ε₁ ⊆ ball y ε₂ := fun z hz =>
calc
dist z y ≤ dist z x + dist x y := dist_triangle _ _ _
_ ≤ ε₁ + dist x y := add_le_add_right (mem_closedBall.1 hz) _
_ < ε₂ := h
#align metric.closed_ball_subset_ball' Metric.closedBall_subset_ball'
theorem dist_le_add_of_nonempty_closedBall_inter_closedBall
(h : (closedBall x ε₁ ∩ closedBall y ε₂).Nonempty) : dist x y ≤ ε₁ + ε₂ :=
let ⟨z, hz⟩ := h
calc
dist x y ≤ dist z x + dist z y := dist_triangle_left _ _ _
_ ≤ ε₁ + ε₂ := add_le_add hz.1 hz.2
#align metric.dist_le_add_of_nonempty_closed_ball_inter_closed_ball Metric.dist_le_add_of_nonempty_closedBall_inter_closedBall
theorem dist_lt_add_of_nonempty_closedBall_inter_ball (h : (closedBall x ε₁ ∩ ball y ε₂).Nonempty) :
dist x y < ε₁ + ε₂ :=
let ⟨z, hz⟩ := h
calc
dist x y ≤ dist z x + dist z y := dist_triangle_left _ _ _
_ < ε₁ + ε₂ := add_lt_add_of_le_of_lt hz.1 hz.2
#align metric.dist_lt_add_of_nonempty_closed_ball_inter_ball Metric.dist_lt_add_of_nonempty_closedBall_inter_ball
theorem dist_lt_add_of_nonempty_ball_inter_closedBall (h : (ball x ε₁ ∩ closedBall y ε₂).Nonempty) :
dist x y < ε₁ + ε₂ := by
rw [inter_comm] at h
rw [add_comm, dist_comm]
exact dist_lt_add_of_nonempty_closedBall_inter_ball h
#align metric.dist_lt_add_of_nonempty_ball_inter_closed_ball Metric.dist_lt_add_of_nonempty_ball_inter_closedBall
theorem dist_lt_add_of_nonempty_ball_inter_ball (h : (ball x ε₁ ∩ ball y ε₂).Nonempty) :
dist x y < ε₁ + ε₂ :=
dist_lt_add_of_nonempty_closedBall_inter_ball <|
h.mono (inter_subset_inter ball_subset_closedBall Subset.rfl)
#align metric.dist_lt_add_of_nonempty_ball_inter_ball Metric.dist_lt_add_of_nonempty_ball_inter_ball
@[simp]
theorem iUnion_closedBall_nat (x : α) : ⋃ n : ℕ, closedBall x n = univ :=
iUnion_eq_univ_iff.2 fun y => exists_nat_ge (dist y x)
#align metric.Union_closed_ball_nat Metric.iUnion_closedBall_nat
| Mathlib/Topology/MetricSpace/PseudoMetric.lean | 665 | 666 | theorem iUnion_inter_closedBall_nat (s : Set α) (x : α) : ⋃ n : ℕ, s ∩ closedBall x n = s := by |
rw [← inter_iUnion, iUnion_closedBall_nat, inter_univ]
|
/-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Mario Carneiro
-/
import Mathlib.Init.Order.LinearOrder
import Mathlib.Data.Prod.Basic
import Mathlib.Data.Subtype
import Mathlib.Tactic.Spread
import Mathlib.Tactic.Convert
import Mathlib.Tactic.SimpRw
import Mathlib.Tactic.Cases
import Mathlib.Order.Notation
#align_import order.basic from "leanprover-community/mathlib"@"90df25ded755a2cf9651ea850d1abe429b1e4eb1"
/-!
# Basic definitions about `≤` and `<`
This file proves basic results about orders, provides extensive dot notation, defines useful order
classes and allows to transfer order instances.
## Type synonyms
* `OrderDual α` : A type synonym reversing the meaning of all inequalities, with notation `αᵒᵈ`.
* `AsLinearOrder α`: A type synonym to promote `PartialOrder α` to `LinearOrder α` using
`IsTotal α (≤)`.
### Transferring orders
- `Order.Preimage`, `Preorder.lift`: Transfers a (pre)order on `β` to an order on `α`
using a function `f : α → β`.
- `PartialOrder.lift`, `LinearOrder.lift`: Transfers a partial (resp., linear) order on `β` to a
partial (resp., linear) order on `α` using an injective function `f`.
### Extra class
* `DenselyOrdered`: An order with no gap, i.e. for any two elements `a < b` there exists `c` such
that `a < c < b`.
## Notes
`≤` and `<` are highly favored over `≥` and `>` in mathlib. The reason is that we can formulate all
lemmas using `≤`/`<`, and `rw` has trouble unifying `≤` and `≥`. Hence choosing one direction spares
us useless duplication. This is enforced by a linter. See Note [nolint_ge] for more infos.
Dot notation is particularly useful on `≤` (`LE.le`) and `<` (`LT.lt`). To that end, we
provide many aliases to dot notation-less lemmas. For example, `le_trans` is aliased with
`LE.le.trans` and can be used to construct `hab.trans hbc : a ≤ c` when `hab : a ≤ b`,
`hbc : b ≤ c`, `lt_of_le_of_lt` is aliased as `LE.le.trans_lt` and can be used to construct
`hab.trans hbc : a < c` when `hab : a ≤ b`, `hbc : b < c`.
## TODO
- expand module docs
- automatic construction of dual definitions / theorems
## Tags
preorder, order, partial order, poset, linear order, chain
-/
open Function
variable {ι α β : Type*} {π : ι → Type*}
section Preorder
variable [Preorder α] {a b c : α}
theorem le_trans' : b ≤ c → a ≤ b → a ≤ c :=
flip le_trans
#align le_trans' le_trans'
theorem lt_trans' : b < c → a < b → a < c :=
flip lt_trans
#align lt_trans' lt_trans'
theorem lt_of_le_of_lt' : b ≤ c → a < b → a < c :=
flip lt_of_lt_of_le
#align lt_of_le_of_lt' lt_of_le_of_lt'
theorem lt_of_lt_of_le' : b < c → a ≤ b → a < c :=
flip lt_of_le_of_lt
#align lt_of_lt_of_le' lt_of_lt_of_le'
end Preorder
section PartialOrder
variable [PartialOrder α] {a b : α}
theorem ge_antisymm : a ≤ b → b ≤ a → b = a :=
flip le_antisymm
#align ge_antisymm ge_antisymm
theorem lt_of_le_of_ne' : a ≤ b → b ≠ a → a < b := fun h₁ h₂ ↦ lt_of_le_of_ne h₁ h₂.symm
#align lt_of_le_of_ne' lt_of_le_of_ne'
theorem Ne.lt_of_le : a ≠ b → a ≤ b → a < b :=
flip lt_of_le_of_ne
#align ne.lt_of_le Ne.lt_of_le
theorem Ne.lt_of_le' : b ≠ a → a ≤ b → a < b :=
flip lt_of_le_of_ne'
#align ne.lt_of_le' Ne.lt_of_le'
end PartialOrder
attribute [simp] le_refl
attribute [ext] LE
alias LE.le.trans := le_trans
alias LE.le.trans' := le_trans'
alias LE.le.trans_lt := lt_of_le_of_lt
alias LE.le.trans_lt' := lt_of_le_of_lt'
alias LE.le.antisymm := le_antisymm
alias LE.le.antisymm' := ge_antisymm
alias LE.le.lt_of_ne := lt_of_le_of_ne
alias LE.le.lt_of_ne' := lt_of_le_of_ne'
alias LE.le.lt_of_not_le := lt_of_le_not_le
alias LE.le.lt_or_eq := lt_or_eq_of_le
alias LE.le.lt_or_eq_dec := Decidable.lt_or_eq_of_le
alias LT.lt.le := le_of_lt
alias LT.lt.trans := lt_trans
alias LT.lt.trans' := lt_trans'
alias LT.lt.trans_le := lt_of_lt_of_le
alias LT.lt.trans_le' := lt_of_lt_of_le'
alias LT.lt.ne := ne_of_lt
#align has_lt.lt.ne LT.lt.ne
alias LT.lt.asymm := lt_asymm
alias LT.lt.not_lt := lt_asymm
alias Eq.le := le_of_eq
#align eq.le Eq.le
-- Porting note: no `decidable_classical` linter
-- attribute [nolint decidable_classical] LE.le.lt_or_eq_dec
section
variable [Preorder α] {a b c : α}
@[simp]
theorem lt_self_iff_false (x : α) : x < x ↔ False :=
⟨lt_irrefl x, False.elim⟩
#align lt_self_iff_false lt_self_iff_false
#align le_of_le_of_eq le_of_le_of_eq
#align le_of_eq_of_le le_of_eq_of_le
#align lt_of_lt_of_eq lt_of_lt_of_eq
#align lt_of_eq_of_lt lt_of_eq_of_lt
theorem le_of_le_of_eq' : b ≤ c → a = b → a ≤ c :=
flip le_of_eq_of_le
#align le_of_le_of_eq' le_of_le_of_eq'
theorem le_of_eq_of_le' : b = c → a ≤ b → a ≤ c :=
flip le_of_le_of_eq
#align le_of_eq_of_le' le_of_eq_of_le'
theorem lt_of_lt_of_eq' : b < c → a = b → a < c :=
flip lt_of_eq_of_lt
#align lt_of_lt_of_eq' lt_of_lt_of_eq'
theorem lt_of_eq_of_lt' : b = c → a < b → a < c :=
flip lt_of_lt_of_eq
#align lt_of_eq_of_lt' lt_of_eq_of_lt'
alias LE.le.trans_eq := le_of_le_of_eq
alias LE.le.trans_eq' := le_of_le_of_eq'
alias LT.lt.trans_eq := lt_of_lt_of_eq
alias LT.lt.trans_eq' := lt_of_lt_of_eq'
alias Eq.trans_le := le_of_eq_of_le
#align eq.trans_le Eq.trans_le
alias Eq.trans_ge := le_of_eq_of_le'
#align eq.trans_ge Eq.trans_ge
alias Eq.trans_lt := lt_of_eq_of_lt
#align eq.trans_lt Eq.trans_lt
alias Eq.trans_gt := lt_of_eq_of_lt'
#align eq.trans_gt Eq.trans_gt
end
namespace Eq
variable [Preorder α] {x y z : α}
/-- If `x = y` then `y ≤ x`. Note: this lemma uses `y ≤ x` instead of `x ≥ y`, because `le` is used
almost exclusively in mathlib. -/
protected theorem ge (h : x = y) : y ≤ x :=
h.symm.le
#align eq.ge Eq.ge
theorem not_lt (h : x = y) : ¬x < y := fun h' ↦ h'.ne h
#align eq.not_lt Eq.not_lt
theorem not_gt (h : x = y) : ¬y < x :=
h.symm.not_lt
#align eq.not_gt Eq.not_gt
end Eq
section
variable [Preorder α] {a b : α}
@[simp] lemma le_of_subsingleton [Subsingleton α] : a ≤ b := (Subsingleton.elim a b).le
-- Making this a @[simp] lemma causes confluences problems downstream.
lemma not_lt_of_subsingleton [Subsingleton α] : ¬a < b := (Subsingleton.elim a b).not_lt
end
namespace LE.le
-- see Note [nolint_ge]
-- Porting note: linter not found @[nolint ge_or_gt]
protected theorem ge [LE α] {x y : α} (h : x ≤ y) : y ≥ x :=
h
#align has_le.le.ge LE.le.ge
section PartialOrder
variable [PartialOrder α] {a b : α}
theorem lt_iff_ne (h : a ≤ b) : a < b ↔ a ≠ b :=
⟨fun h ↦ h.ne, h.lt_of_ne⟩
#align has_le.le.lt_iff_ne LE.le.lt_iff_ne
theorem gt_iff_ne (h : a ≤ b) : a < b ↔ b ≠ a :=
⟨fun h ↦ h.ne.symm, h.lt_of_ne'⟩
#align has_le.le.gt_iff_ne LE.le.gt_iff_ne
theorem not_lt_iff_eq (h : a ≤ b) : ¬a < b ↔ a = b :=
h.lt_iff_ne.not_left
#align has_le.le.not_lt_iff_eq LE.le.not_lt_iff_eq
theorem not_gt_iff_eq (h : a ≤ b) : ¬a < b ↔ b = a :=
h.gt_iff_ne.not_left
#align has_le.le.not_gt_iff_eq LE.le.not_gt_iff_eq
theorem le_iff_eq (h : a ≤ b) : b ≤ a ↔ b = a :=
⟨fun h' ↦ h'.antisymm h, Eq.le⟩
#align has_le.le.le_iff_eq LE.le.le_iff_eq
theorem ge_iff_eq (h : a ≤ b) : b ≤ a ↔ a = b :=
⟨h.antisymm, Eq.ge⟩
#align has_le.le.ge_iff_eq LE.le.ge_iff_eq
end PartialOrder
theorem lt_or_le [LinearOrder α] {a b : α} (h : a ≤ b) (c : α) : a < c ∨ c ≤ b :=
((lt_or_ge a c).imp id) fun hc ↦ le_trans hc h
#align has_le.le.lt_or_le LE.le.lt_or_le
theorem le_or_lt [LinearOrder α] {a b : α} (h : a ≤ b) (c : α) : a ≤ c ∨ c < b :=
((le_or_gt a c).imp id) fun hc ↦ lt_of_lt_of_le hc h
#align has_le.le.le_or_lt LE.le.le_or_lt
theorem le_or_le [LinearOrder α] {a b : α} (h : a ≤ b) (c : α) : a ≤ c ∨ c ≤ b :=
(h.le_or_lt c).elim Or.inl fun h ↦ Or.inr <| le_of_lt h
#align has_le.le.le_or_le LE.le.le_or_le
end LE.le
namespace LT.lt
-- see Note [nolint_ge]
-- Porting note: linter not found @[nolint ge_or_gt]
protected theorem gt [LT α] {x y : α} (h : x < y) : y > x :=
h
#align has_lt.lt.gt LT.lt.gt
protected theorem false [Preorder α] {x : α} : x < x → False :=
lt_irrefl x
#align has_lt.lt.false LT.lt.false
theorem ne' [Preorder α] {x y : α} (h : x < y) : y ≠ x :=
h.ne.symm
#align has_lt.lt.ne' LT.lt.ne'
theorem lt_or_lt [LinearOrder α] {x y : α} (h : x < y) (z : α) : x < z ∨ z < y :=
(lt_or_ge z y).elim Or.inr fun hz ↦ Or.inl <| h.trans_le hz
#align has_lt.lt.lt_or_lt LT.lt.lt_or_lt
end LT.lt
-- see Note [nolint_ge]
-- Porting note: linter not found @[nolint ge_or_gt]
protected theorem GE.ge.le [LE α] {x y : α} (h : x ≥ y) : y ≤ x :=
h
#align ge.le GE.ge.le
-- see Note [nolint_ge]
-- Porting note: linter not found @[nolint ge_or_gt]
protected theorem GT.gt.lt [LT α] {x y : α} (h : x > y) : y < x :=
h
#align gt.lt GT.gt.lt
-- see Note [nolint_ge]
-- Porting note: linter not found @[nolint ge_or_gt]
theorem ge_of_eq [Preorder α] {a b : α} (h : a = b) : a ≥ b :=
h.ge
#align ge_of_eq ge_of_eq
#align ge_iff_le ge_iff_le
#align gt_iff_lt gt_iff_lt
theorem not_le_of_lt [Preorder α] {a b : α} (h : a < b) : ¬b ≤ a :=
(le_not_le_of_lt h).right
#align not_le_of_lt not_le_of_lt
alias LT.lt.not_le := not_le_of_lt
theorem not_lt_of_le [Preorder α] {a b : α} (h : a ≤ b) : ¬b < a := fun hba ↦ hba.not_le h
#align not_lt_of_le not_lt_of_le
alias LE.le.not_lt := not_lt_of_le
theorem ne_of_not_le [Preorder α] {a b : α} (h : ¬a ≤ b) : a ≠ b := fun hab ↦ h (le_of_eq hab)
#align ne_of_not_le ne_of_not_le
-- See Note [decidable namespace]
protected theorem Decidable.le_iff_eq_or_lt [PartialOrder α] [@DecidableRel α (· ≤ ·)] {a b : α} :
a ≤ b ↔ a = b ∨ a < b :=
Decidable.le_iff_lt_or_eq.trans or_comm
#align decidable.le_iff_eq_or_lt Decidable.le_iff_eq_or_lt
theorem le_iff_eq_or_lt [PartialOrder α] {a b : α} : a ≤ b ↔ a = b ∨ a < b :=
le_iff_lt_or_eq.trans or_comm
#align le_iff_eq_or_lt le_iff_eq_or_lt
theorem lt_iff_le_and_ne [PartialOrder α] {a b : α} : a < b ↔ a ≤ b ∧ a ≠ b :=
⟨fun h ↦ ⟨le_of_lt h, ne_of_lt h⟩, fun ⟨h1, h2⟩ ↦ h1.lt_of_ne h2⟩
#align lt_iff_le_and_ne lt_iff_le_and_ne
theorem eq_iff_not_lt_of_le [PartialOrder α] {x y : α} : x ≤ y → y = x ↔ ¬x < y := by
rw [lt_iff_le_and_ne, not_and, Classical.not_not, eq_comm]
#align eq_iff_not_lt_of_le eq_iff_not_lt_of_le
-- See Note [decidable namespace]
protected theorem Decidable.eq_iff_le_not_lt [PartialOrder α] [@DecidableRel α (· ≤ ·)] {a b : α} :
a = b ↔ a ≤ b ∧ ¬a < b :=
⟨fun h ↦ ⟨h.le, h ▸ lt_irrefl _⟩, fun ⟨h₁, h₂⟩ ↦
h₁.antisymm <| Decidable.by_contradiction fun h₃ ↦ h₂ (h₁.lt_of_not_le h₃)⟩
#align decidable.eq_iff_le_not_lt Decidable.eq_iff_le_not_lt
theorem eq_iff_le_not_lt [PartialOrder α] {a b : α} : a = b ↔ a ≤ b ∧ ¬a < b :=
haveI := Classical.dec
Decidable.eq_iff_le_not_lt
#align eq_iff_le_not_lt eq_iff_le_not_lt
theorem eq_or_lt_of_le [PartialOrder α] {a b : α} (h : a ≤ b) : a = b ∨ a < b :=
h.lt_or_eq.symm
#align eq_or_lt_of_le eq_or_lt_of_le
theorem eq_or_gt_of_le [PartialOrder α] {a b : α} (h : a ≤ b) : b = a ∨ a < b :=
h.lt_or_eq.symm.imp Eq.symm id
#align eq_or_gt_of_le eq_or_gt_of_le
theorem gt_or_eq_of_le [PartialOrder α] {a b : α} (h : a ≤ b) : a < b ∨ b = a :=
(eq_or_gt_of_le h).symm
#align gt_or_eq_of_le gt_or_eq_of_le
alias LE.le.eq_or_lt_dec := Decidable.eq_or_lt_of_le
alias LE.le.eq_or_lt := eq_or_lt_of_le
alias LE.le.eq_or_gt := eq_or_gt_of_le
alias LE.le.gt_or_eq := gt_or_eq_of_le
-- Porting note: no `decidable_classical` linter
-- attribute [nolint decidable_classical] LE.le.eq_or_lt_dec
theorem eq_of_le_of_not_lt [PartialOrder α] {a b : α} (hab : a ≤ b) (hba : ¬a < b) : a = b :=
hab.eq_or_lt.resolve_right hba
#align eq_of_le_of_not_lt eq_of_le_of_not_lt
theorem eq_of_ge_of_not_gt [PartialOrder α] {a b : α} (hab : a ≤ b) (hba : ¬a < b) : b = a :=
(hab.eq_or_lt.resolve_right hba).symm
#align eq_of_ge_of_not_gt eq_of_ge_of_not_gt
alias LE.le.eq_of_not_lt := eq_of_le_of_not_lt
alias LE.le.eq_of_not_gt := eq_of_ge_of_not_gt
theorem Ne.le_iff_lt [PartialOrder α] {a b : α} (h : a ≠ b) : a ≤ b ↔ a < b :=
⟨fun h' ↦ lt_of_le_of_ne h' h, fun h ↦ h.le⟩
#align ne.le_iff_lt Ne.le_iff_lt
theorem Ne.not_le_or_not_le [PartialOrder α] {a b : α} (h : a ≠ b) : ¬a ≤ b ∨ ¬b ≤ a :=
not_and_or.1 <| le_antisymm_iff.not.1 h
#align ne.not_le_or_not_le Ne.not_le_or_not_le
-- See Note [decidable namespace]
protected theorem Decidable.ne_iff_lt_iff_le [PartialOrder α] [DecidableEq α] {a b : α} :
(a ≠ b ↔ a < b) ↔ a ≤ b :=
⟨fun h ↦ Decidable.byCases le_of_eq (le_of_lt ∘ h.mp), fun h ↦ ⟨lt_of_le_of_ne h, ne_of_lt⟩⟩
#align decidable.ne_iff_lt_iff_le Decidable.ne_iff_lt_iff_le
@[simp]
theorem ne_iff_lt_iff_le [PartialOrder α] {a b : α} : (a ≠ b ↔ a < b) ↔ a ≤ b :=
haveI := Classical.dec
Decidable.ne_iff_lt_iff_le
#align ne_iff_lt_iff_le ne_iff_lt_iff_le
-- Variant of `min_def` with the branches reversed.
theorem min_def' [LinearOrder α] (a b : α) : min a b = if b ≤ a then b else a := by
rw [min_def]
rcases lt_trichotomy a b with (lt | eq | gt)
· rw [if_pos lt.le, if_neg (not_le.mpr lt)]
· rw [if_pos eq.le, if_pos eq.ge, eq]
· rw [if_neg (not_le.mpr gt.gt), if_pos gt.le]
#align min_def' min_def'
-- Variant of `min_def` with the branches reversed.
-- This is sometimes useful as it used to be the default.
theorem max_def' [LinearOrder α] (a b : α) : max a b = if b ≤ a then a else b := by
rw [max_def]
rcases lt_trichotomy a b with (lt | eq | gt)
· rw [if_pos lt.le, if_neg (not_le.mpr lt)]
· rw [if_pos eq.le, if_pos eq.ge, eq]
· rw [if_neg (not_le.mpr gt.gt), if_pos gt.le]
#align max_def' max_def'
theorem lt_of_not_le [LinearOrder α] {a b : α} (h : ¬b ≤ a) : a < b :=
((le_total _ _).resolve_right h).lt_of_not_le h
#align lt_of_not_le lt_of_not_le
theorem lt_iff_not_le [LinearOrder α] {x y : α} : x < y ↔ ¬y ≤ x :=
⟨not_le_of_lt, lt_of_not_le⟩
#align lt_iff_not_le lt_iff_not_le
theorem Ne.lt_or_lt [LinearOrder α] {x y : α} (h : x ≠ y) : x < y ∨ y < x :=
lt_or_gt_of_ne h
#align ne.lt_or_lt Ne.lt_or_lt
/-- A version of `ne_iff_lt_or_gt` with LHS and RHS reversed. -/
@[simp]
theorem lt_or_lt_iff_ne [LinearOrder α] {x y : α} : x < y ∨ y < x ↔ x ≠ y :=
ne_iff_lt_or_gt.symm
#align lt_or_lt_iff_ne lt_or_lt_iff_ne
theorem not_lt_iff_eq_or_lt [LinearOrder α] {a b : α} : ¬a < b ↔ a = b ∨ b < a :=
not_lt.trans <| Decidable.le_iff_eq_or_lt.trans <| or_congr eq_comm Iff.rfl
#align not_lt_iff_eq_or_lt not_lt_iff_eq_or_lt
theorem exists_ge_of_linear [LinearOrder α] (a b : α) : ∃ c, a ≤ c ∧ b ≤ c :=
match le_total a b with
| Or.inl h => ⟨_, h, le_rfl⟩
| Or.inr h => ⟨_, le_rfl, h⟩
#align exists_ge_of_linear exists_ge_of_linear
lemma exists_forall_ge_and [LinearOrder α] {p q : α → Prop} :
(∃ i, ∀ j ≥ i, p j) → (∃ i, ∀ j ≥ i, q j) → ∃ i, ∀ j ≥ i, p j ∧ q j
| ⟨a, ha⟩, ⟨b, hb⟩ =>
let ⟨c, hac, hbc⟩ := exists_ge_of_linear a b
⟨c, fun _d hcd ↦ ⟨ha _ $ hac.trans hcd, hb _ $ hbc.trans hcd⟩⟩
#align exists_forall_ge_and exists_forall_ge_and
theorem lt_imp_lt_of_le_imp_le {β} [LinearOrder α] [Preorder β] {a b : α} {c d : β}
(H : a ≤ b → c ≤ d) (h : d < c) : b < a :=
lt_of_not_le fun h' ↦ (H h').not_lt h
#align lt_imp_lt_of_le_imp_le lt_imp_lt_of_le_imp_le
theorem le_imp_le_iff_lt_imp_lt {β} [LinearOrder α] [LinearOrder β] {a b : α} {c d : β} :
a ≤ b → c ≤ d ↔ d < c → b < a :=
⟨lt_imp_lt_of_le_imp_le, le_imp_le_of_lt_imp_lt⟩
#align le_imp_le_iff_lt_imp_lt le_imp_le_iff_lt_imp_lt
theorem lt_iff_lt_of_le_iff_le' {β} [Preorder α] [Preorder β] {a b : α} {c d : β}
(H : a ≤ b ↔ c ≤ d) (H' : b ≤ a ↔ d ≤ c) : b < a ↔ d < c :=
lt_iff_le_not_le.trans <| (and_congr H' (not_congr H)).trans lt_iff_le_not_le.symm
#align lt_iff_lt_of_le_iff_le' lt_iff_lt_of_le_iff_le'
theorem lt_iff_lt_of_le_iff_le {β} [LinearOrder α] [LinearOrder β] {a b : α} {c d : β}
(H : a ≤ b ↔ c ≤ d) : b < a ↔ d < c :=
not_le.symm.trans <| (not_congr H).trans <| not_le
#align lt_iff_lt_of_le_iff_le lt_iff_lt_of_le_iff_le
theorem le_iff_le_iff_lt_iff_lt {β} [LinearOrder α] [LinearOrder β] {a b : α} {c d : β} :
(a ≤ b ↔ c ≤ d) ↔ (b < a ↔ d < c) :=
⟨lt_iff_lt_of_le_iff_le, fun H ↦ not_lt.symm.trans <| (not_congr H).trans <| not_lt⟩
#align le_iff_le_iff_lt_iff_lt le_iff_le_iff_lt_iff_lt
theorem eq_of_forall_le_iff [PartialOrder α] {a b : α} (H : ∀ c, c ≤ a ↔ c ≤ b) : a = b :=
((H _).1 le_rfl).antisymm ((H _).2 le_rfl)
#align eq_of_forall_le_iff eq_of_forall_le_iff
theorem le_of_forall_le [Preorder α] {a b : α} (H : ∀ c, c ≤ a → c ≤ b) : a ≤ b :=
H _ le_rfl
#align le_of_forall_le le_of_forall_le
theorem le_of_forall_le' [Preorder α] {a b : α} (H : ∀ c, a ≤ c → b ≤ c) : b ≤ a :=
H _ le_rfl
#align le_of_forall_le' le_of_forall_le'
theorem le_of_forall_lt [LinearOrder α] {a b : α} (H : ∀ c, c < a → c < b) : a ≤ b :=
le_of_not_lt fun h ↦ lt_irrefl _ (H _ h)
#align le_of_forall_lt le_of_forall_lt
theorem forall_lt_iff_le [LinearOrder α] {a b : α} : (∀ ⦃c⦄, c < a → c < b) ↔ a ≤ b :=
⟨le_of_forall_lt, fun h _ hca ↦ lt_of_lt_of_le hca h⟩
#align forall_lt_iff_le forall_lt_iff_le
theorem le_of_forall_lt' [LinearOrder α] {a b : α} (H : ∀ c, a < c → b < c) : b ≤ a :=
le_of_not_lt fun h ↦ lt_irrefl _ (H _ h)
#align le_of_forall_lt' le_of_forall_lt'
theorem forall_lt_iff_le' [LinearOrder α] {a b : α} : (∀ ⦃c⦄, a < c → b < c) ↔ b ≤ a :=
⟨le_of_forall_lt', fun h _ hac ↦ lt_of_le_of_lt h hac⟩
#align forall_lt_iff_le' forall_lt_iff_le'
theorem eq_of_forall_ge_iff [PartialOrder α] {a b : α} (H : ∀ c, a ≤ c ↔ b ≤ c) : a = b :=
((H _).2 le_rfl).antisymm ((H _).1 le_rfl)
#align eq_of_forall_ge_iff eq_of_forall_ge_iff
theorem eq_of_forall_lt_iff [LinearOrder α] {a b : α} (h : ∀ c, c < a ↔ c < b) : a = b :=
(le_of_forall_lt fun _ ↦ (h _).1).antisymm <| le_of_forall_lt fun _ ↦ (h _).2
#align eq_of_forall_lt_iff eq_of_forall_lt_iff
theorem eq_of_forall_gt_iff [LinearOrder α] {a b : α} (h : ∀ c, a < c ↔ b < c) : a = b :=
(le_of_forall_lt' fun _ ↦ (h _).2).antisymm <| le_of_forall_lt' fun _ ↦ (h _).1
#align eq_of_forall_gt_iff eq_of_forall_gt_iff
/-- A symmetric relation implies two values are equal, when it implies they're less-equal. -/
theorem rel_imp_eq_of_rel_imp_le [PartialOrder β] (r : α → α → Prop) [IsSymm α r] {f : α → β}
(h : ∀ a b, r a b → f a ≤ f b) {a b : α} : r a b → f a = f b := fun hab ↦
le_antisymm (h a b hab) (h b a <| symm hab)
#align rel_imp_eq_of_rel_imp_le rel_imp_eq_of_rel_imp_le
/-- monotonicity of `≤` with respect to `→` -/
theorem le_implies_le_of_le_of_le {a b c d : α} [Preorder α] (hca : c ≤ a) (hbd : b ≤ d) :
a ≤ b → c ≤ d :=
fun hab ↦ (hca.trans hab).trans hbd
#align le_implies_le_of_le_of_le le_implies_le_of_le_of_le
section PartialOrder
variable [PartialOrder α]
/-- To prove commutativity of a binary operation `○`, we only to check `a ○ b ≤ b ○ a` for all `a`,
`b`. -/
theorem commutative_of_le {f : β → β → α} (comm : ∀ a b, f a b ≤ f b a) : ∀ a b, f a b = f b a :=
fun _ _ ↦ (comm _ _).antisymm <| comm _ _
#align commutative_of_le commutative_of_le
/-- To prove associativity of a commutative binary operation `○`, we only to check
`(a ○ b) ○ c ≤ a ○ (b ○ c)` for all `a`, `b`, `c`. -/
theorem associative_of_commutative_of_le {f : α → α → α} (comm : Commutative f)
(assoc : ∀ a b c, f (f a b) c ≤ f a (f b c)) : Associative f := fun a b c ↦
le_antisymm (assoc _ _ _) <| by
rw [comm, comm b, comm _ c, comm a]
exact assoc _ _ _
#align associative_of_commutative_of_le associative_of_commutative_of_le
end PartialOrder
@[ext]
theorem Preorder.toLE_injective : Function.Injective (@Preorder.toLE α) :=
fun A B h ↦ match A, B with
| { lt := A_lt, lt_iff_le_not_le := A_iff, .. },
{ lt := B_lt, lt_iff_le_not_le := B_iff, .. } => by
cases h
have : A_lt = B_lt := by
funext a b
show (LT.mk A_lt).lt a b = (LT.mk B_lt).lt a b
rw [A_iff, B_iff]
cases this
congr
#align preorder.to_has_le_injective Preorder.toLE_injective
@[ext]
theorem PartialOrder.toPreorder_injective :
Function.Injective (@PartialOrder.toPreorder α) := fun A B h ↦ by
cases A
cases B
cases h
congr
#align partial_order.to_preorder_injective PartialOrder.toPreorder_injective
@[ext]
theorem LinearOrder.toPartialOrder_injective :
Function.Injective (@LinearOrder.toPartialOrder α) :=
fun A B h ↦ match A, B with
| { le := A_le, lt := A_lt,
decidableLE := A_decidableLE, decidableEq := A_decidableEq, decidableLT := A_decidableLT
min := A_min, max := A_max, min_def := A_min_def, max_def := A_max_def,
compare := A_compare, compare_eq_compareOfLessAndEq := A_compare_canonical, .. },
{ le := B_le, lt := B_lt,
decidableLE := B_decidableLE, decidableEq := B_decidableEq, decidableLT := B_decidableLT
min := B_min, max := B_max, min_def := B_min_def, max_def := B_max_def,
compare := B_compare, compare_eq_compareOfLessAndEq := B_compare_canonical, .. } => by
cases h
obtain rfl : A_decidableLE = B_decidableLE := Subsingleton.elim _ _
obtain rfl : A_decidableEq = B_decidableEq := Subsingleton.elim _ _
obtain rfl : A_decidableLT = B_decidableLT := Subsingleton.elim _ _
have : A_min = B_min := by
funext a b
exact (A_min_def _ _).trans (B_min_def _ _).symm
cases this
have : A_max = B_max := by
funext a b
exact (A_max_def _ _).trans (B_max_def _ _).symm
cases this
have : A_compare = B_compare := by
funext a b
exact (A_compare_canonical _ _).trans (B_compare_canonical _ _).symm
congr
#align linear_order.to_partial_order_injective LinearOrder.toPartialOrder_injective
theorem Preorder.ext {A B : Preorder α}
(H : ∀ x y : α, (haveI := A; x ≤ y) ↔ x ≤ y) : A = B := by
ext x y
exact H x y
#align preorder.ext Preorder.ext
theorem PartialOrder.ext {A B : PartialOrder α}
(H : ∀ x y : α, (haveI := A; x ≤ y) ↔ x ≤ y) : A = B := by
ext x y
exact H x y
#align partial_order.ext PartialOrder.ext
theorem LinearOrder.ext {A B : LinearOrder α}
(H : ∀ x y : α, (haveI := A; x ≤ y) ↔ x ≤ y) : A = B := by
ext x y
exact H x y
#align linear_order.ext LinearOrder.ext
/-- Given a relation `R` on `β` and a function `f : α → β`, the preimage relation on `α` is defined
by `x ≤ y ↔ f x ≤ f y`. It is the unique relation on `α` making `f` a `RelEmbedding` (assuming `f`
is injective). -/
@[simp]
def Order.Preimage (f : α → β) (s : β → β → Prop) (x y : α) : Prop :=
s (f x) (f y)
#align order.preimage Order.Preimage
@[inherit_doc]
infixl:80 " ⁻¹'o " => Order.Preimage
/-- The preimage of a decidable order is decidable. -/
instance Order.Preimage.decidable (f : α → β) (s : β → β → Prop) [H : DecidableRel s] :
DecidableRel (f ⁻¹'o s) := fun _ _ ↦ H _ _
#align order.preimage.decidable Order.Preimage.decidable
section ltByCases
variable [LinearOrder α] {P : Sort*} {x y : α}
@[simp]
lemma ltByCases_lt (h : x < y) {h₁ : x < y → P} {h₂ : x = y → P} {h₃ : y < x → P} :
ltByCases x y h₁ h₂ h₃ = h₁ h := dif_pos h
@[simp]
lemma ltByCases_gt (h : y < x) {h₁ : x < y → P} {h₂ : x = y → P} {h₃ : y < x → P} :
ltByCases x y h₁ h₂ h₃ = h₃ h := (dif_neg h.not_lt).trans (dif_pos h)
@[simp]
lemma ltByCases_eq (h : x = y) {h₁ : x < y → P} {h₂ : x = y → P} {h₃ : y < x → P} :
ltByCases x y h₁ h₂ h₃ = h₂ h := (dif_neg h.not_lt).trans (dif_neg h.not_gt)
lemma ltByCases_not_lt (h : ¬ x < y) {h₁ : x < y → P} {h₂ : x = y → P} {h₃ : y < x → P}
(p : ¬ y < x → x = y := fun h' => (le_antisymm (le_of_not_gt h') (le_of_not_gt h))) :
ltByCases x y h₁ h₂ h₃ = if h' : y < x then h₃ h' else h₂ (p h') := dif_neg h
lemma ltByCases_not_gt (h : ¬ y < x) {h₁ : x < y → P} {h₂ : x = y → P} {h₃ : y < x → P}
(p : ¬ x < y → x = y := fun h' => (le_antisymm (le_of_not_gt h) (le_of_not_gt h'))) :
ltByCases x y h₁ h₂ h₃ = if h' : x < y then h₁ h' else h₂ (p h') :=
dite_congr rfl (fun _ => rfl) (fun _ => dif_neg h)
lemma ltByCases_ne (h : x ≠ y) {h₁ : x < y → P} {h₂ : x = y → P} {h₃ : y < x → P}
(p : ¬ x < y → y < x := fun h' => h.lt_or_lt.resolve_left h') :
ltByCases x y h₁ h₂ h₃ = if h' : x < y then h₁ h' else h₃ (p h') :=
dite_congr rfl (fun _ => rfl) (fun _ => dif_pos _)
lemma ltByCases_comm {h₁ : x < y → P} {h₂ : x = y → P} {h₃ : y < x → P}
(p : y = x → x = y := fun h' => h'.symm) :
ltByCases x y h₁ h₂ h₃ = ltByCases y x h₃ (h₂ ∘ p) h₁ := by
refine ltByCases x y (fun h => ?_) (fun h => ?_) (fun h => ?_)
· rw [ltByCases_lt h, ltByCases_gt h]
· rw [ltByCases_eq h, ltByCases_eq h.symm, comp_apply]
· rw [ltByCases_lt h, ltByCases_gt h]
lemma eq_iff_eq_of_lt_iff_lt_of_gt_iff_gt {x' y' : α}
(ltc : (x < y) ↔ (x' < y')) (gtc : (y < x) ↔ (y' < x')) :
x = y ↔ x' = y' := by simp_rw [eq_iff_le_not_lt, ← not_lt, ltc, gtc]
lemma ltByCases_rec {h₁ : x < y → P} {h₂ : x = y → P} {h₃ : y < x → P} (p : P)
(hlt : (h : x < y) → h₁ h = p) (heq : (h : x = y) → h₂ h = p)
(hgt : (h : y < x) → h₃ h = p) :
ltByCases x y h₁ h₂ h₃ = p :=
ltByCases x y
(fun h => ltByCases_lt h ▸ hlt h)
(fun h => ltByCases_eq h ▸ heq h)
(fun h => ltByCases_gt h ▸ hgt h)
lemma ltByCases_eq_iff {h₁ : x < y → P} {h₂ : x = y → P} {h₃ : y < x → P} {p : P} :
ltByCases x y h₁ h₂ h₃ = p ↔ (∃ h, h₁ h = p) ∨ (∃ h, h₂ h = p) ∨ (∃ h, h₃ h = p) := by
refine ltByCases x y (fun h => ?_) (fun h => ?_) (fun h => ?_)
· simp only [ltByCases_lt, exists_prop_of_true, h, h.not_lt, not_false_eq_true,
exists_prop_of_false, or_false, h.ne]
· simp only [h, lt_self_iff_false, ltByCases_eq, not_false_eq_true,
exists_prop_of_false, exists_prop_of_true, or_false, false_or]
· simp only [ltByCases_gt, exists_prop_of_true, h, h.not_lt, not_false_eq_true,
exists_prop_of_false, false_or, h.ne']
lemma ltByCases_congr {x' y' : α} {h₁ : x < y → P} {h₂ : x = y → P} {h₃ : y < x → P}
{h₁' : x' < y' → P} {h₂' : x' = y' → P} {h₃' : y' < x' → P} (ltc : (x < y) ↔ (x' < y'))
(gtc : (y < x) ↔ (y' < x')) (hh'₁ : ∀ (h : x' < y'), h₁ (ltc.mpr h) = h₁' h)
(hh'₂ : ∀ (h : x' = y'), h₂ ((eq_iff_eq_of_lt_iff_lt_of_gt_iff_gt ltc gtc).mpr h) = h₂' h)
(hh'₃ : ∀ (h : y' < x'), h₃ (gtc.mpr h) = h₃' h) :
ltByCases x y h₁ h₂ h₃ = ltByCases x' y' h₁' h₂' h₃' := by
refine ltByCases_rec _ (fun h => ?_) (fun h => ?_) (fun h => ?_)
· rw [ltByCases_lt (ltc.mp h), hh'₁]
· rw [eq_iff_eq_of_lt_iff_lt_of_gt_iff_gt ltc gtc] at h
rw [ltByCases_eq h, hh'₂]
· rw [ltByCases_gt (gtc.mp h), hh'₃]
/-- Perform a case-split on the ordering of `x` and `y` in a decidable linear order,
non-dependently. -/
abbrev ltTrichotomy (x y : α) (p q r : P) := ltByCases x y (fun _ => p) (fun _ => q) (fun _ => r)
variable {p q r s : P}
@[simp]
lemma ltTrichotomy_lt (h : x < y) : ltTrichotomy x y p q r = p := ltByCases_lt h
@[simp]
lemma ltTrichotomy_gt (h : y < x) : ltTrichotomy x y p q r = r := ltByCases_gt h
@[simp]
lemma ltTrichotomy_eq (h : x = y) : ltTrichotomy x y p q r = q := ltByCases_eq h
lemma ltTrichotomy_not_lt (h : ¬ x < y) :
ltTrichotomy x y p q r = if y < x then r else q := ltByCases_not_lt h
lemma ltTrichotomy_not_gt (h : ¬ y < x) :
ltTrichotomy x y p q r = if x < y then p else q := ltByCases_not_gt h
lemma ltTrichotomy_ne (h : x ≠ y) :
ltTrichotomy x y p q r = if x < y then p else r := ltByCases_ne h
lemma ltTrichotomy_comm : ltTrichotomy x y p q r = ltTrichotomy y x r q p := ltByCases_comm
lemma ltTrichotomy_self {p : P} : ltTrichotomy x y p p p = p :=
ltByCases_rec p (fun _ => rfl) (fun _ => rfl) (fun _ => rfl)
lemma ltTrichotomy_eq_iff : ltTrichotomy x y p q r = s ↔
(x < y ∧ p = s) ∨ (x = y ∧ q = s) ∨ (y < x ∧ r = s) := by
refine ltByCases x y (fun h => ?_) (fun h => ?_) (fun h => ?_)
· simp only [ltTrichotomy_lt, false_and, true_and, or_false, h, h.not_lt, h.ne]
· simp only [ltTrichotomy_eq, false_and, true_and, or_false, false_or, h, lt_irrefl]
· simp only [ltTrichotomy_gt, false_and, true_and, false_or, h, h.not_lt, h.ne']
lemma ltTrichotomy_congr {x' y' : α} {p' q' r' : P} (ltc : (x < y) ↔ (x' < y'))
(gtc : (y < x) ↔ (y' < x')) (hh'₁ : x' < y' → p = p')
(hh'₂ : x' = y' → q = q') (hh'₃ : y' < x' → r = r') :
ltTrichotomy x y p q r = ltTrichotomy x' y' p' q' r' :=
ltByCases_congr ltc gtc hh'₁ hh'₂ hh'₃
end ltByCases
/-! ### Order dual -/
/-- Type synonym to equip a type with the dual order: `≤` means `≥` and `<` means `>`. `αᵒᵈ` is
notation for `OrderDual α`. -/
def OrderDual (α : Type*) : Type _ :=
α
#align order_dual OrderDual
@[inherit_doc]
notation:max α "ᵒᵈ" => OrderDual α
namespace OrderDual
instance (α : Type*) [h : Nonempty α] : Nonempty αᵒᵈ :=
h
instance (α : Type*) [h : Subsingleton α] : Subsingleton αᵒᵈ :=
h
instance (α : Type*) [LE α] : LE αᵒᵈ :=
⟨fun x y : α ↦ y ≤ x⟩
instance (α : Type*) [LT α] : LT αᵒᵈ :=
⟨fun x y : α ↦ y < x⟩
instance instPreorder (α : Type*) [Preorder α] : Preorder αᵒᵈ where
le_refl := fun _ ↦ le_refl _
le_trans := fun _ _ _ hab hbc ↦ hbc.trans hab
lt_iff_le_not_le := fun _ _ ↦ lt_iff_le_not_le
instance instPartialOrder (α : Type*) [PartialOrder α] : PartialOrder αᵒᵈ where
__ := inferInstanceAs (Preorder αᵒᵈ)
le_antisymm := fun a b hab hba ↦ @le_antisymm α _ a b hba hab
instance instLinearOrder (α : Type*) [LinearOrder α] : LinearOrder αᵒᵈ where
__ := inferInstanceAs (PartialOrder αᵒᵈ)
le_total := fun a b : α ↦ le_total b a
max := fun a b ↦ (min a b : α)
min := fun a b ↦ (max a b : α)
min_def := fun a b ↦ show (max .. : α) = _ by rw [max_comm, max_def]; rfl
max_def := fun a b ↦ show (min .. : α) = _ by rw [min_comm, min_def]; rfl
decidableLE := (inferInstance : DecidableRel (fun a b : α ↦ b ≤ a))
decidableLT := (inferInstance : DecidableRel (fun a b : α ↦ b < a))
#align order_dual.linear_order OrderDual.instLinearOrder
instance : ∀ [Inhabited α], Inhabited αᵒᵈ := fun [x : Inhabited α] => x
theorem Preorder.dual_dual (α : Type*) [H : Preorder α] : OrderDual.instPreorder αᵒᵈ = H :=
Preorder.ext fun _ _ ↦ Iff.rfl
#align order_dual.preorder.dual_dual OrderDual.Preorder.dual_dual
theorem instPartialOrder.dual_dual (α : Type*) [H : PartialOrder α] :
OrderDual.instPartialOrder αᵒᵈ = H :=
PartialOrder.ext fun _ _ ↦ Iff.rfl
#align order_dual.partial_order.dual_dual OrderDual.instPartialOrder.dual_dual
theorem instLinearOrder.dual_dual (α : Type*) [H : LinearOrder α] :
OrderDual.instLinearOrder αᵒᵈ = H :=
LinearOrder.ext fun _ _ ↦ Iff.rfl
#align order_dual.linear_order.dual_dual OrderDual.instLinearOrder.dual_dual
end OrderDual
/-! ### `HasCompl` -/
instance Prop.hasCompl : HasCompl Prop :=
⟨Not⟩
#align Prop.has_compl Prop.hasCompl
instance Pi.hasCompl [∀ i, HasCompl (π i)] : HasCompl (∀ i, π i) :=
⟨fun x i ↦ (x i)ᶜ⟩
#align pi.has_compl Pi.hasCompl
theorem Pi.compl_def [∀ i, HasCompl (π i)] (x : ∀ i, π i) :
xᶜ = fun i ↦ (x i)ᶜ :=
rfl
#align pi.compl_def Pi.compl_def
@[simp]
theorem Pi.compl_apply [∀ i, HasCompl (π i)] (x : ∀ i, π i) (i : ι) :
xᶜ i = (x i)ᶜ :=
rfl
#align pi.compl_apply Pi.compl_apply
instance IsIrrefl.compl (r) [IsIrrefl α r] : IsRefl α rᶜ :=
⟨@irrefl α r _⟩
#align is_irrefl.compl IsIrrefl.compl
instance IsRefl.compl (r) [IsRefl α r] : IsIrrefl α rᶜ :=
⟨fun a ↦ not_not_intro (refl a)⟩
#align is_refl.compl IsRefl.compl
/-! ### Order instances on the function space -/
instance Pi.hasLe [∀ i, LE (π i)] :
LE (∀ i, π i) where le x y := ∀ i, x i ≤ y i
#align pi.has_le Pi.hasLe
theorem Pi.le_def [∀ i, LE (π i)] {x y : ∀ i, π i} :
x ≤ y ↔ ∀ i, x i ≤ y i :=
Iff.rfl
#align pi.le_def Pi.le_def
instance Pi.preorder [∀ i, Preorder (π i)] : Preorder (∀ i, π i) where
__ := inferInstanceAs (LE (∀ i, π i))
le_refl := fun a i ↦ le_refl (a i)
le_trans := fun a b c h₁ h₂ i ↦ le_trans (h₁ i) (h₂ i)
#align pi.preorder Pi.preorder
theorem Pi.lt_def [∀ i, Preorder (π i)] {x y : ∀ i, π i} :
x < y ↔ x ≤ y ∧ ∃ i, x i < y i := by
simp (config := { contextual := true }) [lt_iff_le_not_le, Pi.le_def]
#align pi.lt_def Pi.lt_def
instance Pi.partialOrder [∀ i, PartialOrder (π i)] : PartialOrder (∀ i, π i) where
__ := Pi.preorder
le_antisymm := fun _ _ h1 h2 ↦ funext fun b ↦ (h1 b).antisymm (h2 b)
#align pi.partial_order Pi.partialOrder
namespace Sum
variable {α₁ α₂ : Type*} [LE β]
@[simp]
lemma elim_le_elim_iff {u₁ v₁ : α₁ → β} {u₂ v₂ : α₂ → β} :
Sum.elim u₁ u₂ ≤ Sum.elim v₁ v₂ ↔ u₁ ≤ v₁ ∧ u₂ ≤ v₂ :=
Sum.forall
lemma const_le_elim_iff {b : β} {v₁ : α₁ → β} {v₂ : α₂ → β} :
Function.const _ b ≤ Sum.elim v₁ v₂ ↔ Function.const _ b ≤ v₁ ∧ Function.const _ b ≤ v₂ :=
elim_const_const b ▸ elim_le_elim_iff ..
lemma elim_le_const_iff {b : β} {u₁ : α₁ → β} {u₂ : α₂ → β} :
Sum.elim u₁ u₂ ≤ Function.const _ b ↔ u₁ ≤ Function.const _ b ∧ u₂ ≤ Function.const _ b :=
elim_const_const b ▸ elim_le_elim_iff ..
end Sum
section Pi
/-- A function `a` is strongly less than a function `b` if `a i < b i` for all `i`. -/
def StrongLT [∀ i, LT (π i)] (a b : ∀ i, π i) : Prop :=
∀ i, a i < b i
#align strong_lt StrongLT
@[inherit_doc]
local infixl:50 " ≺ " => StrongLT
variable [∀ i, Preorder (π i)] {a b c : ∀ i, π i}
theorem le_of_strongLT (h : a ≺ b) : a ≤ b := fun _ ↦ (h _).le
#align le_of_strong_lt le_of_strongLT
theorem lt_of_strongLT [Nonempty ι] (h : a ≺ b) : a < b := by
inhabit ι
exact Pi.lt_def.2 ⟨le_of_strongLT h, default, h _⟩
#align lt_of_strong_lt lt_of_strongLT
theorem strongLT_of_strongLT_of_le (hab : a ≺ b) (hbc : b ≤ c) : a ≺ c := fun _ ↦
(hab _).trans_le <| hbc _
#align strong_lt_of_strong_lt_of_le strongLT_of_strongLT_of_le
theorem strongLT_of_le_of_strongLT (hab : a ≤ b) (hbc : b ≺ c) : a ≺ c := fun _ ↦
(hab _).trans_lt <| hbc _
#align strong_lt_of_le_of_strong_lt strongLT_of_le_of_strongLT
alias StrongLT.le := le_of_strongLT
#align strong_lt.le StrongLT.le
alias StrongLT.lt := lt_of_strongLT
#align strong_lt.lt StrongLT.lt
alias StrongLT.trans_le := strongLT_of_strongLT_of_le
#align strong_lt.trans_le StrongLT.trans_le
alias LE.le.trans_strongLT := strongLT_of_le_of_strongLT
end Pi
section Function
variable [DecidableEq ι] [∀ i, Preorder (π i)] {x y : ∀ i, π i} {i : ι} {a b : π i}
theorem le_update_iff : x ≤ Function.update y i a ↔ x i ≤ a ∧ ∀ (j) (_ : j ≠ i), x j ≤ y j :=
Function.forall_update_iff _ fun j z ↦ x j ≤ z
#align le_update_iff le_update_iff
theorem update_le_iff : Function.update x i a ≤ y ↔ a ≤ y i ∧ ∀ (j) (_ : j ≠ i), x j ≤ y j :=
Function.forall_update_iff _ fun j z ↦ z ≤ y j
#align update_le_iff update_le_iff
theorem update_le_update_iff :
Function.update x i a ≤ Function.update y i b ↔ a ≤ b ∧ ∀ (j) (_ : j ≠ i), x j ≤ y j := by
simp (config := { contextual := true }) [update_le_iff]
#align update_le_update_iff update_le_update_iff
@[simp]
theorem update_le_update_iff' : update x i a ≤ update x i b ↔ a ≤ b := by
simp [update_le_update_iff]
#align update_le_update_iff' update_le_update_iff'
@[simp]
theorem update_lt_update_iff : update x i a < update x i b ↔ a < b :=
lt_iff_lt_of_le_iff_le' update_le_update_iff' update_le_update_iff'
#align update_lt_update_iff update_lt_update_iff
@[simp]
theorem le_update_self_iff : x ≤ update x i a ↔ x i ≤ a := by simp [le_update_iff]
#align le_update_self_iff le_update_self_iff
@[simp]
theorem update_le_self_iff : update x i a ≤ x ↔ a ≤ x i := by simp [update_le_iff]
#align update_le_self_iff update_le_self_iff
@[simp]
theorem lt_update_self_iff : x < update x i a ↔ x i < a := by simp [lt_iff_le_not_le]
#align lt_update_self_iff lt_update_self_iff
@[simp]
theorem update_lt_self_iff : update x i a < x ↔ a < x i := by simp [lt_iff_le_not_le]
#align update_lt_self_iff update_lt_self_iff
end Function
instance Pi.sdiff [∀ i, SDiff (π i)] : SDiff (∀ i, π i) :=
⟨fun x y i ↦ x i \ y i⟩
#align pi.has_sdiff Pi.sdiff
theorem Pi.sdiff_def [∀ i, SDiff (π i)] (x y : ∀ i, π i) :
x \ y = fun i ↦ x i \ y i :=
rfl
#align pi.sdiff_def Pi.sdiff_def
@[simp]
theorem Pi.sdiff_apply [∀ i, SDiff (π i)] (x y : ∀ i, π i) (i : ι) :
(x \ y) i = x i \ y i :=
rfl
#align pi.sdiff_apply Pi.sdiff_apply
namespace Function
variable [Preorder α] [Nonempty β] {a b : α}
@[simp]
theorem const_le_const : const β a ≤ const β b ↔ a ≤ b := by simp [Pi.le_def]
#align function.const_le_const Function.const_le_const
@[simp]
theorem const_lt_const : const β a < const β b ↔ a < b := by simpa [Pi.lt_def] using le_of_lt
#align function.const_lt_const Function.const_lt_const
end Function
/-! ### `min`/`max` recursors -/
section MinMaxRec
variable [LinearOrder α] {p : α → Prop} {x y : α}
theorem min_rec (hx : x ≤ y → p x) (hy : y ≤ x → p y) : p (min x y) :=
(le_total x y).rec (fun h ↦ (min_eq_left h).symm.subst (hx h)) fun h ↦
(min_eq_right h).symm.subst (hy h)
#align min_rec min_rec
theorem max_rec (hx : y ≤ x → p x) (hy : x ≤ y → p y) : p (max x y) :=
@min_rec αᵒᵈ _ _ _ _ hx hy
#align max_rec max_rec
theorem min_rec' (p : α → Prop) (hx : p x) (hy : p y) : p (min x y) :=
min_rec (fun _ ↦ hx) fun _ ↦ hy
#align min_rec' min_rec'
theorem max_rec' (p : α → Prop) (hx : p x) (hy : p y) : p (max x y) :=
max_rec (fun _ ↦ hx) fun _ ↦ hy
#align max_rec' max_rec'
theorem min_def_lt (x y : α) : min x y = if x < y then x else y := by
rw [min_comm, min_def, ← ite_not]
simp only [not_le]
#align min_def_lt min_def_lt
theorem max_def_lt (x y : α) : max x y = if x < y then y else x := by
rw [max_comm, max_def, ← ite_not]
simp only [not_le]
#align max_def_lt max_def_lt
end MinMaxRec
/-! ### Lifts of order instances -/
/-- Transfer a `Preorder` on `β` to a `Preorder` on `α` using a function `f : α → β`.
See note [reducible non-instances]. -/
abbrev Preorder.lift [Preorder β] (f : α → β) : Preorder α where
le x y := f x ≤ f y
le_refl _ := le_rfl
le_trans _ _ _ := _root_.le_trans
lt x y := f x < f y
lt_iff_le_not_le _ _ := _root_.lt_iff_le_not_le
#align preorder.lift Preorder.lift
/-- Transfer a `PartialOrder` on `β` to a `PartialOrder` on `α` using an injective
function `f : α → β`. See note [reducible non-instances]. -/
abbrev PartialOrder.lift [PartialOrder β] (f : α → β) (inj : Injective f) : PartialOrder α :=
{ Preorder.lift f with le_antisymm := fun _ _ h₁ h₂ ↦ inj (h₁.antisymm h₂) }
#align partial_order.lift PartialOrder.lift
theorem compare_of_injective_eq_compareOfLessAndEq (a b : α) [LinearOrder β]
[DecidableEq α] (f : α → β) (inj : Injective f)
[Decidable (LT.lt (self := PartialOrder.lift f inj |>.toLT) a b)] :
compare (f a) (f b) =
@compareOfLessAndEq _ a b (PartialOrder.lift f inj |>.toLT) _ _ := by
have h := LinearOrder.compare_eq_compareOfLessAndEq (f a) (f b)
simp only [h, compareOfLessAndEq]
split_ifs <;> try (first | rfl | contradiction)
· have : ¬ f a = f b := by rename_i h; exact inj.ne h
contradiction
· have : f a = f b := by rename_i h; exact congrArg f h
contradiction
/-- Transfer a `LinearOrder` on `β` to a `LinearOrder` on `α` using an injective
function `f : α → β`. This version takes `[Sup α]` and `[Inf α]` as arguments, then uses
them for `max` and `min` fields. See `LinearOrder.lift'` for a version that autogenerates `min` and
`max` fields, and `LinearOrder.liftWithOrd` for one that does not auto-generate `compare`
fields. See note [reducible non-instances]. -/
abbrev LinearOrder.lift [LinearOrder β] [Sup α] [Inf α] (f : α → β) (inj : Injective f)
(hsup : ∀ x y, f (x ⊔ y) = max (f x) (f y)) (hinf : ∀ x y, f (x ⊓ y) = min (f x) (f y)) :
LinearOrder α :=
letI instOrdα : Ord α := ⟨fun a b ↦ compare (f a) (f b)⟩
letI decidableLE := fun x y ↦ (inferInstance : Decidable (f x ≤ f y))
letI decidableLT := fun x y ↦ (inferInstance : Decidable (f x < f y))
letI decidableEq := fun x y ↦ decidable_of_iff (f x = f y) inj.eq_iff
{ PartialOrder.lift f inj, instOrdα with
le_total := fun x y ↦ le_total (f x) (f y)
decidableLE := decidableLE
decidableLT := decidableLT
decidableEq := decidableEq
min := (· ⊓ ·)
max := (· ⊔ ·)
min_def := by
intros x y
apply inj
rw [apply_ite f]
exact (hinf _ _).trans (min_def _ _)
max_def := by
intros x y
apply inj
rw [apply_ite f]
exact (hsup _ _).trans (max_def _ _)
compare_eq_compareOfLessAndEq := fun a b ↦
compare_of_injective_eq_compareOfLessAndEq a b f inj }
/-- Transfer a `LinearOrder` on `β` to a `LinearOrder` on `α` using an injective
function `f : α → β`. This version autogenerates `min` and `max` fields. See `LinearOrder.lift`
for a version that takes `[Sup α]` and `[Inf α]`, then uses them as `max` and `min`. See
`LinearOrder.liftWithOrd'` for a version which does not auto-generate `compare` fields.
See note [reducible non-instances]. -/
abbrev LinearOrder.lift' [LinearOrder β] (f : α → β) (inj : Injective f) : LinearOrder α :=
@LinearOrder.lift α β _ ⟨fun x y ↦ if f x ≤ f y then y else x⟩
⟨fun x y ↦ if f x ≤ f y then x else y⟩ f inj
(fun _ _ ↦ (apply_ite f _ _ _).trans (max_def _ _).symm) fun _ _ ↦
(apply_ite f _ _ _).trans (min_def _ _).symm
#align linear_order.lift' LinearOrder.lift'
/-- Transfer a `LinearOrder` on `β` to a `LinearOrder` on `α` using an injective
function `f : α → β`. This version takes `[Sup α]` and `[Inf α]` as arguments, then uses
them for `max` and `min` fields. It also takes `[Ord α]` as an argument and uses them for `compare`
fields. See `LinearOrder.lift` for a version that autogenerates `compare` fields, and
`LinearOrder.liftWithOrd'` for one that auto-generates `min` and `max` fields.
fields. See note [reducible non-instances]. -/
abbrev LinearOrder.liftWithOrd [LinearOrder β] [Sup α] [Inf α] [Ord α] (f : α → β)
(inj : Injective f) (hsup : ∀ x y, f (x ⊔ y) = max (f x) (f y))
(hinf : ∀ x y, f (x ⊓ y) = min (f x) (f y))
(compare_f : ∀ a b : α, compare a b = compare (f a) (f b)) : LinearOrder α :=
letI decidableLE := fun x y ↦ (inferInstance : Decidable (f x ≤ f y))
letI decidableLT := fun x y ↦ (inferInstance : Decidable (f x < f y))
letI decidableEq := fun x y ↦ decidable_of_iff (f x = f y) inj.eq_iff
{ PartialOrder.lift f inj with
le_total := fun x y ↦ le_total (f x) (f y)
decidableLE := decidableLE
decidableLT := decidableLT
decidableEq := decidableEq
min := (· ⊓ ·)
max := (· ⊔ ·)
min_def := by
intros x y
apply inj
rw [apply_ite f]
exact (hinf _ _).trans (min_def _ _)
max_def := by
intros x y
apply inj
rw [apply_ite f]
exact (hsup _ _).trans (max_def _ _)
compare_eq_compareOfLessAndEq := fun a b ↦
(compare_f a b).trans <| compare_of_injective_eq_compareOfLessAndEq a b f inj }
/-- Transfer a `LinearOrder` on `β` to a `LinearOrder` on `α` using an injective
function `f : α → β`. This version auto-generates `min` and `max` fields. It also takes `[Ord α]`
as an argument and uses them for `compare` fields. See `LinearOrder.lift` for a version that
autogenerates `compare` fields, and `LinearOrder.liftWithOrd` for one that doesn't auto-generate
`min` and `max` fields. fields. See note [reducible non-instances]. -/
abbrev LinearOrder.liftWithOrd' [LinearOrder β] [Ord α] (f : α → β)
(inj : Injective f)
(compare_f : ∀ a b : α, compare a b = compare (f a) (f b)) : LinearOrder α :=
@LinearOrder.liftWithOrd α β _ ⟨fun x y ↦ if f x ≤ f y then y else x⟩
⟨fun x y ↦ if f x ≤ f y then x else y⟩ _ f inj
(fun _ _ ↦ (apply_ite f _ _ _).trans (max_def _ _).symm)
(fun _ _ ↦ (apply_ite f _ _ _).trans (min_def _ _).symm)
compare_f
/-! ### Subtype of an order -/
namespace Subtype
instance le [LE α] {p : α → Prop} : LE (Subtype p) :=
⟨fun x y ↦ (x : α) ≤ y⟩
instance lt [LT α] {p : α → Prop} : LT (Subtype p) :=
⟨fun x y ↦ (x : α) < y⟩
@[simp]
theorem mk_le_mk [LE α] {p : α → Prop} {x y : α} {hx : p x} {hy : p y} :
(⟨x, hx⟩ : Subtype p) ≤ ⟨y, hy⟩ ↔ x ≤ y :=
Iff.rfl
#align subtype.mk_le_mk Subtype.mk_le_mk
@[simp]
theorem mk_lt_mk [LT α] {p : α → Prop} {x y : α} {hx : p x} {hy : p y} :
(⟨x, hx⟩ : Subtype p) < ⟨y, hy⟩ ↔ x < y :=
Iff.rfl
#align subtype.mk_lt_mk Subtype.mk_lt_mk
@[simp, norm_cast]
theorem coe_le_coe [LE α] {p : α → Prop} {x y : Subtype p} : (x : α) ≤ y ↔ x ≤ y :=
Iff.rfl
#align subtype.coe_le_coe Subtype.coe_le_coe
@[simp, norm_cast]
theorem coe_lt_coe [LT α] {p : α → Prop} {x y : Subtype p} : (x : α) < y ↔ x < y :=
Iff.rfl
#align subtype.coe_lt_coe Subtype.coe_lt_coe
instance preorder [Preorder α] (p : α → Prop) : Preorder (Subtype p) :=
Preorder.lift (fun (a : Subtype p) ↦ (a : α))
instance partialOrder [PartialOrder α] (p : α → Prop) : PartialOrder (Subtype p) :=
PartialOrder.lift (fun (a : Subtype p) ↦ (a : α)) Subtype.coe_injective
#align subtype.partial_order Subtype.partialOrder
instance decidableLE [Preorder α] [h : @DecidableRel α (· ≤ ·)] {p : α → Prop} :
@DecidableRel (Subtype p) (· ≤ ·) := fun a b ↦ h a b
#align subtype.decidable_le Subtype.decidableLE
instance decidableLT [Preorder α] [h : @DecidableRel α (· < ·)] {p : α → Prop} :
@DecidableRel (Subtype p) (· < ·) := fun a b ↦ h a b
#align subtype.decidable_lt Subtype.decidableLT
/-- A subtype of a linear order is a linear order. We explicitly give the proofs of decidable
equality and decidable order in order to ensure the decidability instances are all definitionally
equal. -/
instance instLinearOrder [LinearOrder α] (p : α → Prop) : LinearOrder (Subtype p) :=
@LinearOrder.lift (Subtype p) _ _ ⟨fun x y ↦ ⟨max x y, max_rec' _ x.2 y.2⟩⟩
⟨fun x y ↦ ⟨min x y, min_rec' _ x.2 y.2⟩⟩ (fun (a : Subtype p) ↦ (a : α))
Subtype.coe_injective (fun _ _ ↦ rfl) fun _ _ ↦
rfl
end Subtype
/-!
### Pointwise order on `α × β`
The lexicographic order is defined in `Data.Prod.Lex`, and the instances are available via the
type synonym `α ×ₗ β = α × β`.
-/
namespace Prod
instance (α β : Type*) [LE α] [LE β] : LE (α × β) :=
⟨fun p q ↦ p.1 ≤ q.1 ∧ p.2 ≤ q.2⟩
-- Porting note (#10754): new instance
instance instDecidableLE (α β : Type*) [LE α] [LE β] (x y : α × β)
[Decidable (x.1 ≤ y.1)] [Decidable (x.2 ≤ y.2)] : Decidable (x ≤ y) := And.decidable
theorem le_def [LE α] [LE β] {x y : α × β} : x ≤ y ↔ x.1 ≤ y.1 ∧ x.2 ≤ y.2 :=
Iff.rfl
#align prod.le_def Prod.le_def
@[simp]
theorem mk_le_mk [LE α] [LE β] {x₁ x₂ : α} {y₁ y₂ : β} : (x₁, y₁) ≤ (x₂, y₂) ↔ x₁ ≤ x₂ ∧ y₁ ≤ y₂ :=
Iff.rfl
#align prod.mk_le_mk Prod.mk_le_mk
@[simp]
theorem swap_le_swap [LE α] [LE β] {x y : α × β} : x.swap ≤ y.swap ↔ x ≤ y :=
and_comm
#align prod.swap_le_swap Prod.swap_le_swap
section Preorder
variable [Preorder α] [Preorder β] {a a₁ a₂ : α} {b b₁ b₂ : β} {x y : α × β}
instance (α β : Type*) [Preorder α] [Preorder β] : Preorder (α × β) where
__ := inferInstanceAs (LE (α × β))
le_refl := fun ⟨a, b⟩ ↦ ⟨le_refl a, le_refl b⟩
le_trans := fun ⟨a, b⟩ ⟨c, d⟩ ⟨e, f⟩ ⟨hac, hbd⟩ ⟨hce, hdf⟩ ↦ ⟨le_trans hac hce, le_trans hbd hdf⟩
@[simp]
theorem swap_lt_swap : x.swap < y.swap ↔ x < y :=
and_congr swap_le_swap (not_congr swap_le_swap)
#align prod.swap_lt_swap Prod.swap_lt_swap
theorem mk_le_mk_iff_left : (a₁, b) ≤ (a₂, b) ↔ a₁ ≤ a₂ :=
and_iff_left le_rfl
#align prod.mk_le_mk_iff_left Prod.mk_le_mk_iff_left
theorem mk_le_mk_iff_right : (a, b₁) ≤ (a, b₂) ↔ b₁ ≤ b₂ :=
and_iff_right le_rfl
#align prod.mk_le_mk_iff_right Prod.mk_le_mk_iff_right
theorem mk_lt_mk_iff_left : (a₁, b) < (a₂, b) ↔ a₁ < a₂ :=
lt_iff_lt_of_le_iff_le' mk_le_mk_iff_left mk_le_mk_iff_left
#align prod.mk_lt_mk_iff_left Prod.mk_lt_mk_iff_left
theorem mk_lt_mk_iff_right : (a, b₁) < (a, b₂) ↔ b₁ < b₂ :=
lt_iff_lt_of_le_iff_le' mk_le_mk_iff_right mk_le_mk_iff_right
#align prod.mk_lt_mk_iff_right Prod.mk_lt_mk_iff_right
| Mathlib/Order/Basic.lean | 1,325 | 1,332 | theorem lt_iff : x < y ↔ x.1 < y.1 ∧ x.2 ≤ y.2 ∨ x.1 ≤ y.1 ∧ x.2 < y.2 := by |
refine ⟨fun h ↦ ?_, ?_⟩
· by_cases h₁ : y.1 ≤ x.1
· exact Or.inr ⟨h.1.1, LE.le.lt_of_not_le h.1.2 fun h₂ ↦ h.2 ⟨h₁, h₂⟩⟩
· exact Or.inl ⟨LE.le.lt_of_not_le h.1.1 h₁, h.1.2⟩
· rintro (⟨h₁, h₂⟩ | ⟨h₁, h₂⟩)
· exact ⟨⟨h₁.le, h₂⟩, fun h ↦ h₁.not_le h.1⟩
· exact ⟨⟨h₁, h₂.le⟩, fun h ↦ h₂.not_le h.2⟩
|
/-
Copyright (c) 2015, 2017 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Robert Y. Lewis, Johannes Hölzl, Mario Carneiro, Sébastien Gouëzel
-/
import Mathlib.Topology.EMetricSpace.Basic
import Mathlib.Topology.Bornology.Constructions
import Mathlib.Data.Set.Pointwise.Interval
import Mathlib.Topology.Order.DenselyOrdered
/-!
## Pseudo-metric spaces
This file defines pseudo-metric spaces: these differ from metric spaces by not imposing the
condition `dist x y = 0 → x = y`.
Many definitions and theorems expected on (pseudo-)metric spaces are already introduced on uniform
spaces and topological spaces. For example: open and closed sets, compactness, completeness,
continuity and uniform continuity.
## Main definitions
* `Dist α`: Endows a space `α` with a function `dist a b`.
* `PseudoMetricSpace α`: A space endowed with a distance function, which can
be zero even if the two elements are non-equal.
* `Metric.ball x ε`: The set of all points `y` with `dist y x < ε`.
* `Metric.Bounded s`: Whether a subset of a `PseudoMetricSpace` is bounded.
* `MetricSpace α`: A `PseudoMetricSpace` with the guarantee `dist x y = 0 → x = y`.
Additional useful definitions:
* `nndist a b`: `dist` as a function to the non-negative reals.
* `Metric.closedBall x ε`: The set of all points `y` with `dist y x ≤ ε`.
* `Metric.sphere x ε`: The set of all points `y` with `dist y x = ε`.
TODO (anyone): Add "Main results" section.
## Tags
pseudo_metric, dist
-/
open Set Filter TopologicalSpace Bornology
open scoped ENNReal NNReal Uniformity Topology
universe u v w
variable {α : Type u} {β : Type v} {X ι : Type*}
theorem UniformSpace.ofDist_aux (ε : ℝ) (hε : 0 < ε) : ∃ δ > (0 : ℝ), ∀ x < δ, ∀ y < δ, x + y < ε :=
⟨ε / 2, half_pos hε, fun _x hx _y hy => add_halves ε ▸ add_lt_add hx hy⟩
/-- Construct a uniform structure from a distance function and metric space axioms -/
def UniformSpace.ofDist (dist : α → α → ℝ) (dist_self : ∀ x : α, dist x x = 0)
(dist_comm : ∀ x y : α, dist x y = dist y x)
(dist_triangle : ∀ x y z : α, dist x z ≤ dist x y + dist y z) : UniformSpace α :=
.ofFun dist dist_self dist_comm dist_triangle ofDist_aux
#align uniform_space_of_dist UniformSpace.ofDist
-- Porting note: dropped the `dist_self` argument
/-- Construct a bornology from a distance function and metric space axioms. -/
abbrev Bornology.ofDist {α : Type*} (dist : α → α → ℝ) (dist_comm : ∀ x y, dist x y = dist y x)
(dist_triangle : ∀ x y z, dist x z ≤ dist x y + dist y z) : Bornology α :=
Bornology.ofBounded { s : Set α | ∃ C, ∀ ⦃x⦄, x ∈ s → ∀ ⦃y⦄, y ∈ s → dist x y ≤ C }
⟨0, fun x hx y => hx.elim⟩ (fun s ⟨c, hc⟩ t h => ⟨c, fun x hx y hy => hc (h hx) (h hy)⟩)
(fun s hs t ht => by
rcases s.eq_empty_or_nonempty with rfl | ⟨x, hx⟩
· rwa [empty_union]
rcases t.eq_empty_or_nonempty with rfl | ⟨y, hy⟩
· rwa [union_empty]
rsuffices ⟨C, hC⟩ : ∃ C, ∀ z ∈ s ∪ t, dist x z ≤ C
· refine ⟨C + C, fun a ha b hb => (dist_triangle a x b).trans ?_⟩
simpa only [dist_comm] using add_le_add (hC _ ha) (hC _ hb)
rcases hs with ⟨Cs, hs⟩; rcases ht with ⟨Ct, ht⟩
refine ⟨max Cs (dist x y + Ct), fun z hz => hz.elim
(fun hz => (hs hx hz).trans (le_max_left _ _))
(fun hz => (dist_triangle x y z).trans <|
(add_le_add le_rfl (ht hy hz)).trans (le_max_right _ _))⟩)
fun z => ⟨dist z z, forall_eq.2 <| forall_eq.2 le_rfl⟩
#align bornology.of_dist Bornology.ofDistₓ
/-- The distance function (given an ambient metric space on `α`), which returns
a nonnegative real number `dist x y` given `x y : α`. -/
@[ext]
class Dist (α : Type*) where
dist : α → α → ℝ
#align has_dist Dist
export Dist (dist)
-- the uniform structure and the emetric space structure are embedded in the metric space structure
-- to avoid instance diamond issues. See Note [forgetful inheritance].
/-- This is an internal lemma used inside the default of `PseudoMetricSpace.edist`. -/
private theorem dist_nonneg' {α} {x y : α} (dist : α → α → ℝ)
(dist_self : ∀ x : α, dist x x = 0) (dist_comm : ∀ x y : α, dist x y = dist y x)
(dist_triangle : ∀ x y z : α, dist x z ≤ dist x y + dist y z) : 0 ≤ dist x y :=
have : 0 ≤ 2 * dist x y :=
calc 0 = dist x x := (dist_self _).symm
_ ≤ dist x y + dist y x := dist_triangle _ _ _
_ = 2 * dist x y := by rw [two_mul, dist_comm]
nonneg_of_mul_nonneg_right this two_pos
#noalign pseudo_metric_space.edist_dist_tac -- Porting note (#11215): TODO: restore
/-- Pseudo metric and Metric spaces
A pseudo metric space is endowed with a distance for which the requirement `d(x,y)=0 → x = y` might
not hold. A metric space is a pseudo metric space such that `d(x,y)=0 → x = y`.
Each pseudo metric space induces a canonical `UniformSpace` and hence a canonical
`TopologicalSpace` This is enforced in the type class definition, by extending the `UniformSpace`
structure. When instantiating a `PseudoMetricSpace` structure, the uniformity fields are not
necessary, they will be filled in by default. In the same way, each (pseudo) metric space induces a
(pseudo) emetric space structure. It is included in the structure, but filled in by default.
-/
class PseudoMetricSpace (α : Type u) extends Dist α : Type u where
dist_self : ∀ x : α, dist x x = 0
dist_comm : ∀ x y : α, dist x y = dist y x
dist_triangle : ∀ x y z : α, dist x z ≤ dist x y + dist y z
edist : α → α → ℝ≥0∞ := fun x y => ENNReal.ofNNReal ⟨dist x y, dist_nonneg' _ ‹_› ‹_› ‹_›⟩
edist_dist : ∀ x y : α, edist x y = ENNReal.ofReal (dist x y)
-- Porting note (#11215): TODO: add := by _
toUniformSpace : UniformSpace α := .ofDist dist dist_self dist_comm dist_triangle
uniformity_dist : 𝓤 α = ⨅ ε > 0, 𝓟 { p : α × α | dist p.1 p.2 < ε } := by intros; rfl
toBornology : Bornology α := Bornology.ofDist dist dist_comm dist_triangle
cobounded_sets : (Bornology.cobounded α).sets =
{ s | ∃ C : ℝ, ∀ x ∈ sᶜ, ∀ y ∈ sᶜ, dist x y ≤ C } := by intros; rfl
#align pseudo_metric_space PseudoMetricSpace
/-- Two pseudo metric space structures with the same distance function coincide. -/
@[ext]
theorem PseudoMetricSpace.ext {α : Type*} {m m' : PseudoMetricSpace α}
(h : m.toDist = m'.toDist) : m = m' := by
cases' m with d _ _ _ ed hed U hU B hB
cases' m' with d' _ _ _ ed' hed' U' hU' B' hB'
obtain rfl : d = d' := h
congr
· ext x y : 2
rw [hed, hed']
· exact UniformSpace.ext (hU.trans hU'.symm)
· ext : 2
rw [← Filter.mem_sets, ← Filter.mem_sets, hB, hB']
#align pseudo_metric_space.ext PseudoMetricSpace.ext
variable [PseudoMetricSpace α]
attribute [instance] PseudoMetricSpace.toUniformSpace PseudoMetricSpace.toBornology
-- see Note [lower instance priority]
instance (priority := 200) PseudoMetricSpace.toEDist : EDist α :=
⟨PseudoMetricSpace.edist⟩
#align pseudo_metric_space.to_has_edist PseudoMetricSpace.toEDist
/-- Construct a pseudo-metric space structure whose underlying topological space structure
(definitionally) agrees which a pre-existing topology which is compatible with a given distance
function. -/
def PseudoMetricSpace.ofDistTopology {α : Type u} [TopologicalSpace α] (dist : α → α → ℝ)
(dist_self : ∀ x : α, dist x x = 0) (dist_comm : ∀ x y : α, dist x y = dist y x)
(dist_triangle : ∀ x y z : α, dist x z ≤ dist x y + dist y z)
(H : ∀ s : Set α, IsOpen s ↔ ∀ x ∈ s, ∃ ε > 0, ∀ y, dist x y < ε → y ∈ s) :
PseudoMetricSpace α :=
{ dist := dist
dist_self := dist_self
dist_comm := dist_comm
dist_triangle := dist_triangle
edist_dist := fun x y => by exact ENNReal.coe_nnreal_eq _
toUniformSpace :=
(UniformSpace.ofDist dist dist_self dist_comm dist_triangle).replaceTopology <|
TopologicalSpace.ext_iff.2 fun s ↦ (H s).trans <| forall₂_congr fun x _ ↦
((UniformSpace.hasBasis_ofFun (exists_gt (0 : ℝ)) dist dist_self dist_comm dist_triangle
UniformSpace.ofDist_aux).comap (Prod.mk x)).mem_iff.symm
uniformity_dist := rfl
toBornology := Bornology.ofDist dist dist_comm dist_triangle
cobounded_sets := rfl }
#align pseudo_metric_space.of_dist_topology PseudoMetricSpace.ofDistTopology
@[simp]
theorem dist_self (x : α) : dist x x = 0 :=
PseudoMetricSpace.dist_self x
#align dist_self dist_self
theorem dist_comm (x y : α) : dist x y = dist y x :=
PseudoMetricSpace.dist_comm x y
#align dist_comm dist_comm
theorem edist_dist (x y : α) : edist x y = ENNReal.ofReal (dist x y) :=
PseudoMetricSpace.edist_dist x y
#align edist_dist edist_dist
theorem dist_triangle (x y z : α) : dist x z ≤ dist x y + dist y z :=
PseudoMetricSpace.dist_triangle x y z
#align dist_triangle dist_triangle
| Mathlib/Topology/MetricSpace/PseudoMetric.lean | 192 | 193 | theorem dist_triangle_left (x y z : α) : dist x y ≤ dist z x + dist z y := by |
rw [dist_comm z]; apply dist_triangle
|
/-
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.SetTheory.Ordinal.Basic
import Mathlib.Data.Nat.SuccPred
#align_import set_theory.ordinal.arithmetic from "leanprover-community/mathlib"@"31b269b60935483943542d547a6dd83a66b37dc7"
/-!
# 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`.
* `enumOrd`: enumerates an unbounded set of ordinals by the ordinals themselves.
* `sup`, `lsub`: the supremum / least strict upper bound of an indexed family of ordinals in
`Type u`, as an ordinal in `Type u`.
* `bsup`, `blsub`: the supremum / least strict upper bound of a set of ordinals indexed by ordinals
less than a given ordinal `o`.
Various other basic arithmetic results are given in `Principal.lean` instead.
-/
assert_not_exists Field
assert_not_exists Module
noncomputable section
open Function Cardinal Set Equiv Order
open scoped Classical
open Cardinal Ordinal
universe u v w
namespace Ordinal
variable {α : Type*} {β : Type*} {γ : 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⟩
#align ordinal.lift_add Ordinal.lift_add
@[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
#align ordinal.lift_succ Ordinal.lift_succ
instance add_contravariantClass_le : ContravariantClass Ordinal.{u} Ordinal.{u} (· + ·) (· ≤ ·) :=
⟨fun a b c =>
inductionOn a fun α r hr =>
inductionOn b fun β₁ s₁ hs₁ =>
inductionOn c fun β₂ s₂ hs₂ ⟨f⟩ =>
⟨have fl : ∀ a, f (Sum.inl a) = Sum.inl a := fun a => by
simpa only [InitialSeg.trans_apply, InitialSeg.leAdd_apply] using
@InitialSeg.eq _ _ _ _ _
((InitialSeg.leAdd r s₁).trans f) (InitialSeg.leAdd r s₂) a
have : ∀ b, { b' // f (Sum.inr b) = Sum.inr b' } := by
intro b; cases e : f (Sum.inr b)
· rw [← fl] at e
have := f.inj' e
contradiction
· exact ⟨_, rfl⟩
let g (b) := (this b).1
have fr : ∀ b, f (Sum.inr b) = Sum.inr (g b) := fun b => (this b).2
⟨⟨⟨g, fun x y h => by
injection f.inj' (by rw [fr, fr, h] : f (Sum.inr x) = f (Sum.inr y))⟩,
@fun a b => by
-- Porting note:
-- `relEmbedding.coe_fn_to_embedding` & `initial_seg.coe_fn_to_rel_embedding`
-- → `InitialSeg.coe_coe_fn`
simpa only [Sum.lex_inr_inr, fr, InitialSeg.coe_coe_fn, Embedding.coeFn_mk] using
@RelEmbedding.map_rel_iff _ _ _ _ f.toRelEmbedding (Sum.inr a) (Sum.inr b)⟩,
fun a b H => by
rcases f.init (by rw [fr] <;> exact Sum.lex_inr_inr.2 H) with ⟨a' | a', h⟩
· rw [fl] at h
cases h
· rw [fr] at h
exact ⟨a', Sum.inr.inj h⟩⟩⟩⟩
#align ordinal.add_contravariant_class_le Ordinal.add_contravariantClass_le
theorem add_left_cancel (a) {b c : Ordinal} : a + b = a + c ↔ b = c := by
simp only [le_antisymm_iff, add_le_add_iff_left]
#align ordinal.add_left_cancel Ordinal.add_left_cancel
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 add_covariantClass_lt : CovariantClass Ordinal.{u} Ordinal.{u} (· + ·) (· < ·) :=
⟨fun a _b _c => (add_lt_add_iff_left' a).2⟩
#align ordinal.add_covariant_class_lt Ordinal.add_covariantClass_lt
instance add_contravariantClass_lt : ContravariantClass Ordinal.{u} Ordinal.{u} (· + ·) (· < ·) :=
⟨fun a _b _c => (add_lt_add_iff_left' a).1⟩
#align ordinal.add_contravariant_class_lt Ordinal.add_contravariantClass_lt
instance add_swap_contravariantClass_lt :
ContravariantClass Ordinal.{u} Ordinal.{u} (swap (· + ·)) (· < ·) :=
⟨fun _a _b _c => lt_imp_lt_of_le_imp_le fun h => add_le_add_right h _⟩
#align ordinal.add_swap_contravariant_class_lt Ordinal.add_swap_contravariantClass_lt
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]
#align ordinal.add_le_add_iff_right Ordinal.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]
#align ordinal.add_right_cancel Ordinal.add_right_cancel
theorem add_eq_zero_iff {a b : Ordinal} : a + b = 0 ↔ a = 0 ∧ b = 0 :=
inductionOn a fun α r _ =>
inductionOn b fun β s _ => by
simp_rw [← type_sum_lex, type_eq_zero_iff_isEmpty]
exact isEmpty_sum
#align ordinal.add_eq_zero_iff Ordinal.add_eq_zero_iff
theorem left_eq_zero_of_add_eq_zero {a b : Ordinal} (h : a + b = 0) : a = 0 :=
(add_eq_zero_iff.1 h).1
#align ordinal.left_eq_zero_of_add_eq_zero Ordinal.left_eq_zero_of_add_eq_zero
theorem right_eq_zero_of_add_eq_zero {a b : Ordinal} (h : a + b = 0) : b = 0 :=
(add_eq_zero_iff.1 h).2
#align ordinal.right_eq_zero_of_add_eq_zero Ordinal.right_eq_zero_of_add_eq_zero
/-! ### The predecessor of an ordinal -/
/-- 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
#align ordinal.pred Ordinal.pred
@[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
#align ordinal.pred_succ Ordinal.pred_succ
theorem pred_le_self (o) : pred o ≤ o :=
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]
#align ordinal.pred_le_self Ordinal.pred_le_self
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⟩
#align ordinal.pred_eq_iff_not_succ Ordinal.pred_eq_iff_not_succ
theorem pred_eq_iff_not_succ' {o} : pred o = o ↔ ∀ a, o ≠ succ a := by
simpa using pred_eq_iff_not_succ
#align ordinal.pred_eq_iff_not_succ' Ordinal.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_iff, not_le])
(iff_not_comm.1 pred_eq_iff_not_succ).symm
#align ordinal.pred_lt_iff_is_succ Ordinal.pred_lt_iff_is_succ
@[simp]
theorem pred_zero : pred 0 = 0 :=
pred_eq_iff_not_succ'.2 fun a => (succ_ne_zero a).symm
#align ordinal.pred_zero Ordinal.pred_zero
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]⟩
#align ordinal.succ_pred_iff_is_succ Ordinal.succ_pred_iff_is_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⟩⟩
#align ordinal.succ_lt_of_not_succ Ordinal.succ_lt_of_not_succ
theorem lt_pred {a b} : a < pred b ↔ succ a < b :=
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]
#align ordinal.lt_pred Ordinal.lt_pred
theorem pred_le {a b} : pred a ≤ b ↔ a ≤ succ b :=
le_iff_le_iff_lt_iff_lt.2 lt_pred
#align ordinal.pred_le Ordinal.pred_le
@[simp]
theorem lift_is_succ {o : Ordinal.{v}} : (∃ a, lift.{u} o = succ a) ↔ ∃ a, o = succ a :=
⟨fun ⟨a, h⟩ =>
let ⟨b, e⟩ := lift_down <| show a ≤ lift.{u} o from le_of_lt <| h.symm ▸ lt_succ a
⟨b, lift_inj.1 <| by rw [h, ← e, lift_succ]⟩,
fun ⟨a, h⟩ => ⟨lift.{u} a, by simp only [h, lift_succ]⟩⟩
#align ordinal.lift_is_succ Ordinal.lift_is_succ
@[simp]
theorem lift_pred (o : Ordinal.{v}) : lift.{u} (pred o) = pred (lift.{u} o) :=
if h : ∃ a, o = succ a then by cases' h with a e; 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)]
#align ordinal.lift_pred Ordinal.lift_pred
/-! ### Limit ordinals -/
/-- A limit ordinal is an ordinal which is not zero and not a successor. -/
def IsLimit (o : Ordinal) : Prop :=
o ≠ 0 ∧ ∀ a < o, succ a < o
#align ordinal.is_limit Ordinal.IsLimit
theorem IsLimit.isSuccLimit {o} (h : IsLimit o) : IsSuccLimit o := isSuccLimit_iff_succ_lt.mpr h.2
theorem IsLimit.succ_lt {o a : Ordinal} (h : IsLimit o) : a < o → succ a < o :=
h.2 a
#align ordinal.is_limit.succ_lt Ordinal.IsLimit.succ_lt
theorem isSuccLimit_zero : IsSuccLimit (0 : Ordinal) := isSuccLimit_bot
theorem not_zero_isLimit : ¬IsLimit 0
| ⟨h, _⟩ => h rfl
#align ordinal.not_zero_is_limit Ordinal.not_zero_isLimit
theorem not_succ_isLimit (o) : ¬IsLimit (succ o)
| ⟨_, h⟩ => lt_irrefl _ (h _ (lt_succ o))
#align ordinal.not_succ_is_limit Ordinal.not_succ_isLimit
theorem not_succ_of_isLimit {o} (h : IsLimit o) : ¬∃ a, o = succ a
| ⟨a, e⟩ => not_succ_isLimit a (e ▸ h)
#align ordinal.not_succ_of_is_limit Ordinal.not_succ_of_isLimit
theorem succ_lt_of_isLimit {o a : Ordinal} (h : IsLimit o) : succ a < o ↔ a < o :=
⟨(lt_succ a).trans, h.2 _⟩
#align ordinal.succ_lt_of_is_limit Ordinal.succ_lt_of_isLimit
theorem le_succ_of_isLimit {o} (h : IsLimit o) {a} : o ≤ succ a ↔ o ≤ a :=
le_iff_le_iff_lt_iff_lt.2 <| succ_lt_of_isLimit h
#align ordinal.le_succ_of_is_limit Ordinal.le_succ_of_isLimit
theorem limit_le {o} (h : IsLimit o) {a} : o ≤ a ↔ ∀ x < o, x ≤ a :=
⟨fun h _x l => l.le.trans h, fun H =>
(le_succ_of_isLimit h).1 <| le_of_not_lt fun hn => not_lt_of_le (H _ hn) (lt_succ a)⟩
#align ordinal.limit_le Ordinal.limit_le
theorem lt_limit {o} (h : IsLimit o) {a} : a < o ↔ ∃ x < o, a < x := by
-- Porting note: `bex_def` is required.
simpa only [not_forall₂, not_le, bex_def] using not_congr (@limit_le _ h a)
#align ordinal.lt_limit Ordinal.lt_limit
@[simp]
theorem lift_isLimit (o) : IsLimit (lift o) ↔ IsLimit o :=
and_congr (not_congr <| by simpa only [lift_zero] using @lift_inj o 0)
⟨fun H a h => lift_lt.1 <| by simpa only [lift_succ] using H _ (lift_lt.2 h), fun H a h => by
obtain ⟨a', rfl⟩ := lift_down h.le
rw [← lift_succ, lift_lt]
exact H a' (lift_lt.1 h)⟩
#align ordinal.lift_is_limit Ordinal.lift_isLimit
theorem IsLimit.pos {o : Ordinal} (h : IsLimit o) : 0 < o :=
lt_of_le_of_ne (Ordinal.zero_le _) h.1.symm
#align ordinal.is_limit.pos Ordinal.IsLimit.pos
theorem IsLimit.one_lt {o : Ordinal} (h : IsLimit o) : 1 < o := by
simpa only [succ_zero] using h.2 _ h.pos
#align ordinal.is_limit.one_lt Ordinal.IsLimit.one_lt
theorem IsLimit.nat_lt {o : Ordinal} (h : IsLimit o) : ∀ n : ℕ, (n : Ordinal) < o
| 0 => h.pos
| n + 1 => h.2 _ (IsLimit.nat_lt h n)
#align ordinal.is_limit.nat_lt Ordinal.IsLimit.nat_lt
theorem zero_or_succ_or_limit (o : Ordinal) : o = 0 ∨ (∃ a, o = succ a) ∨ IsLimit o :=
if o0 : o = 0 then Or.inl o0
else
if h : ∃ a, o = succ a then Or.inr (Or.inl h)
else Or.inr <| Or.inr ⟨o0, fun _a => (succ_lt_of_not_succ h).2⟩
#align ordinal.zero_or_succ_or_limit Ordinal.zero_or_succ_or_limit
/-- Main induction principle of ordinals: if one can prove a property by
induction at successor ordinals and at limit ordinals, then it holds for all ordinals. -/
@[elab_as_elim]
def limitRecOn {C : Ordinal → Sort*} (o : Ordinal) (H₁ : C 0) (H₂ : ∀ o, C o → C (succ o))
(H₃ : ∀ o, IsLimit o → (∀ o' < o, C o') → C o) : C o :=
SuccOrder.limitRecOn o (fun o _ ↦ H₂ o) fun o hl ↦
if h : o = 0 then fun _ ↦ h ▸ H₁ else H₃ o ⟨h, fun _ ↦ hl.succ_lt⟩
#align ordinal.limit_rec_on Ordinal.limitRecOn
@[simp]
theorem limitRecOn_zero {C} (H₁ H₂ H₃) : @limitRecOn C 0 H₁ H₂ H₃ = H₁ := by
rw [limitRecOn, SuccOrder.limitRecOn_limit _ _ isSuccLimit_zero, dif_pos rfl]
#align ordinal.limit_rec_on_zero Ordinal.limitRecOn_zero
@[simp]
theorem limitRecOn_succ {C} (o H₁ H₂ H₃) :
@limitRecOn C (succ o) H₁ H₂ H₃ = H₂ o (@limitRecOn C o H₁ H₂ H₃) := by
simp_rw [limitRecOn, SuccOrder.limitRecOn_succ _ _ (not_isMax _)]
#align ordinal.limit_rec_on_succ Ordinal.limitRecOn_succ
@[simp]
theorem limitRecOn_limit {C} (o H₁ H₂ H₃ h) :
@limitRecOn C o H₁ H₂ H₃ = H₃ o h fun x _h => @limitRecOn C x H₁ H₂ H₃ := by
simp_rw [limitRecOn, SuccOrder.limitRecOn_limit _ _ h.isSuccLimit, dif_neg h.1]
#align ordinal.limit_rec_on_limit Ordinal.limitRecOn_limit
instance orderTopOutSucc (o : Ordinal) : OrderTop (succ o).out.α :=
@OrderTop.mk _ _ (Top.mk _) le_enum_succ
#align ordinal.order_top_out_succ Ordinal.orderTopOutSucc
theorem enum_succ_eq_top {o : Ordinal} :
enum (· < ·) o
(by
rw [type_lt]
exact lt_succ o) =
(⊤ : (succ o).out.α) :=
rfl
#align ordinal.enum_succ_eq_top Ordinal.enum_succ_eq_top
theorem has_succ_of_type_succ_lt {α} {r : α → α → Prop} [wo : IsWellOrder α r]
(h : ∀ a < type r, succ a < type r) (x : α) : ∃ y, r x y := by
use enum r (succ (typein r x)) (h _ (typein_lt_type r x))
convert (enum_lt_enum (typein_lt_type r x)
(h _ (typein_lt_type r x))).mpr (lt_succ _); rw [enum_typein]
#align ordinal.has_succ_of_type_succ_lt Ordinal.has_succ_of_type_succ_lt
theorem out_no_max_of_succ_lt {o : Ordinal} (ho : ∀ a < o, succ a < o) : NoMaxOrder o.out.α :=
⟨has_succ_of_type_succ_lt (by rwa [type_lt])⟩
#align ordinal.out_no_max_of_succ_lt Ordinal.out_no_max_of_succ_lt
theorem bounded_singleton {r : α → α → Prop} [IsWellOrder α r] (hr : (type r).IsLimit) (x) :
Bounded r {x} := by
refine ⟨enum r (succ (typein r x)) (hr.2 _ (typein_lt_type r x)), ?_⟩
intro b hb
rw [mem_singleton_iff.1 hb]
nth_rw 1 [← enum_typein r x]
rw [@enum_lt_enum _ r]
apply lt_succ
#align ordinal.bounded_singleton Ordinal.bounded_singleton
-- Porting note: `· < ·` requires a type ascription for an `IsWellOrder` instance.
theorem type_subrel_lt (o : Ordinal.{u}) :
type (Subrel ((· < ·) : Ordinal → Ordinal → Prop) { o' : Ordinal | o' < o })
= Ordinal.lift.{u + 1} o := by
refine Quotient.inductionOn o ?_
rintro ⟨α, r, wo⟩; apply Quotient.sound
-- Porting note: `symm; refine' [term]` → `refine' [term].symm`
constructor; refine ((RelIso.preimage Equiv.ulift r).trans (enumIso r).symm).symm
#align ordinal.type_subrel_lt Ordinal.type_subrel_lt
theorem mk_initialSeg (o : Ordinal.{u}) :
#{ o' : Ordinal | o' < o } = Cardinal.lift.{u + 1} o.card := by
rw [lift_card, ← type_subrel_lt, card_type]
#align ordinal.mk_initial_seg Ordinal.mk_initialSeg
/-! ### Normal ordinal functions -/
/-- A normal ordinal function is a strictly increasing function which is
order-continuous, i.e., the image `f o` of a limit ordinal `o` is the sup of `f a` for
`a < o`. -/
def IsNormal (f : Ordinal → Ordinal) : Prop :=
(∀ o, f o < f (succ o)) ∧ ∀ o, IsLimit o → ∀ a, f o ≤ a ↔ ∀ b < o, f b ≤ a
#align ordinal.is_normal Ordinal.IsNormal
theorem IsNormal.limit_le {f} (H : IsNormal f) :
∀ {o}, IsLimit o → ∀ {a}, f o ≤ a ↔ ∀ b < o, f b ≤ a :=
@H.2
#align ordinal.is_normal.limit_le Ordinal.IsNormal.limit_le
theorem IsNormal.limit_lt {f} (H : IsNormal f) {o} (h : IsLimit o) {a} :
a < f o ↔ ∃ b < o, a < f b :=
not_iff_not.1 <| by simpa only [exists_prop, not_exists, not_and, not_lt] using H.2 _ h a
#align ordinal.is_normal.limit_lt Ordinal.IsNormal.limit_lt
theorem IsNormal.strictMono {f} (H : IsNormal f) : StrictMono f := fun a b =>
limitRecOn b (Not.elim (not_lt_of_le <| Ordinal.zero_le _))
(fun _b IH h =>
(lt_or_eq_of_le (le_of_lt_succ h)).elim (fun h => (IH h).trans (H.1 _)) fun e => e ▸ H.1 _)
fun _b l _IH h => lt_of_lt_of_le (H.1 a) ((H.2 _ l _).1 le_rfl _ (l.2 _ h))
#align ordinal.is_normal.strict_mono Ordinal.IsNormal.strictMono
theorem IsNormal.monotone {f} (H : IsNormal f) : Monotone f :=
H.strictMono.monotone
#align ordinal.is_normal.monotone Ordinal.IsNormal.monotone
theorem isNormal_iff_strictMono_limit (f : Ordinal → Ordinal) :
IsNormal f ↔ StrictMono f ∧ ∀ o, IsLimit o → ∀ a, (∀ b < o, f b ≤ a) → f o ≤ a :=
⟨fun hf => ⟨hf.strictMono, fun a ha c => (hf.2 a ha c).2⟩, fun ⟨hs, hl⟩ =>
⟨fun a => hs (lt_succ a), fun a ha c =>
⟨fun hac _b hba => ((hs hba).trans_le hac).le, hl a ha c⟩⟩⟩
#align ordinal.is_normal_iff_strict_mono_limit Ordinal.isNormal_iff_strictMono_limit
theorem IsNormal.lt_iff {f} (H : IsNormal f) {a b} : f a < f b ↔ a < b :=
StrictMono.lt_iff_lt <| H.strictMono
#align ordinal.is_normal.lt_iff Ordinal.IsNormal.lt_iff
theorem IsNormal.le_iff {f} (H : IsNormal f) {a b} : f a ≤ f b ↔ a ≤ b :=
le_iff_le_iff_lt_iff_lt.2 H.lt_iff
#align ordinal.is_normal.le_iff Ordinal.IsNormal.le_iff
theorem IsNormal.inj {f} (H : IsNormal f) {a b} : f a = f b ↔ a = b := by
simp only [le_antisymm_iff, H.le_iff]
#align ordinal.is_normal.inj Ordinal.IsNormal.inj
theorem IsNormal.self_le {f} (H : IsNormal f) (a) : a ≤ f a :=
lt_wf.self_le_of_strictMono H.strictMono a
#align ordinal.is_normal.self_le Ordinal.IsNormal.self_le
theorem IsNormal.le_set {f o} (H : IsNormal f) (p : Set Ordinal) (p0 : p.Nonempty) (b)
(H₂ : ∀ o, b ≤ o ↔ ∀ a ∈ p, a ≤ o) : f b ≤ o ↔ ∀ a ∈ p, f a ≤ o :=
⟨fun h a pa => (H.le_iff.2 ((H₂ _).1 le_rfl _ pa)).trans h, fun h => by
-- Porting note: `refine'` didn't work well so `induction` is used
induction b using limitRecOn with
| H₁ =>
cases' p0 with x px
have := Ordinal.le_zero.1 ((H₂ _).1 (Ordinal.zero_le _) _ px)
rw [this] at px
exact h _ px
| H₂ S _ =>
rcases not_forall₂.1 (mt (H₂ S).2 <| (lt_succ S).not_le) with ⟨a, h₁, h₂⟩
exact (H.le_iff.2 <| succ_le_of_lt <| not_le.1 h₂).trans (h _ h₁)
| H₃ S L _ =>
refine (H.2 _ L _).2 fun a h' => ?_
rcases not_forall₂.1 (mt (H₂ a).2 h'.not_le) with ⟨b, h₁, h₂⟩
exact (H.le_iff.2 <| (not_le.1 h₂).le).trans (h _ h₁)⟩
#align ordinal.is_normal.le_set Ordinal.IsNormal.le_set
theorem IsNormal.le_set' {f o} (H : IsNormal f) (p : Set α) (p0 : p.Nonempty) (g : α → Ordinal) (b)
(H₂ : ∀ o, b ≤ o ↔ ∀ a ∈ p, g a ≤ o) : f b ≤ o ↔ ∀ a ∈ p, f (g a) ≤ o := by
simpa [H₂] using H.le_set (g '' p) (p0.image g) b
#align ordinal.is_normal.le_set' Ordinal.IsNormal.le_set'
theorem IsNormal.refl : IsNormal id :=
⟨lt_succ, fun _o l _a => Ordinal.limit_le l⟩
#align ordinal.is_normal.refl Ordinal.IsNormal.refl
theorem IsNormal.trans {f g} (H₁ : IsNormal f) (H₂ : IsNormal g) : IsNormal (f ∘ g) :=
⟨fun _x => H₁.lt_iff.2 (H₂.1 _), fun o l _a =>
H₁.le_set' (· < o) ⟨0, l.pos⟩ g _ fun _c => H₂.2 _ l _⟩
#align ordinal.is_normal.trans Ordinal.IsNormal.trans
theorem IsNormal.isLimit {f} (H : IsNormal f) {o} (l : IsLimit o) : IsLimit (f o) :=
⟨ne_of_gt <| (Ordinal.zero_le _).trans_lt <| H.lt_iff.2 l.pos, fun _ h =>
let ⟨_b, h₁, h₂⟩ := (H.limit_lt l).1 h
(succ_le_of_lt h₂).trans_lt (H.lt_iff.2 h₁)⟩
#align ordinal.is_normal.is_limit Ordinal.IsNormal.isLimit
theorem IsNormal.le_iff_eq {f} (H : IsNormal f) {a} : f a ≤ a ↔ f a = a :=
(H.self_le a).le_iff_eq
#align ordinal.is_normal.le_iff_eq Ordinal.IsNormal.le_iff_eq
theorem add_le_of_limit {a b c : Ordinal} (h : IsLimit b) : a + b ≤ c ↔ ∀ b' < b, a + b' ≤ c :=
⟨fun h b' l => (add_le_add_left l.le _).trans h, fun H =>
le_of_not_lt <| by
-- Porting note: `induction` tactics are required because of the parser bug.
induction a using inductionOn with
| H α r =>
induction b using inductionOn with
| H β s =>
intro l
suffices ∀ x : β, Sum.Lex r s (Sum.inr x) (enum _ _ l) by
-- Porting note: `revert` & `intro` is required because `cases'` doesn't replace
-- `enum _ _ l` in `this`.
revert this; cases' enum _ _ l with x x <;> intro this
· cases this (enum s 0 h.pos)
· exact irrefl _ (this _)
intro x
rw [← typein_lt_typein (Sum.Lex r s), typein_enum]
have := H _ (h.2 _ (typein_lt_type s x))
rw [add_succ, succ_le_iff] at this
refine
(RelEmbedding.ofMonotone (fun a => ?_) fun a b => ?_).ordinal_type_le.trans_lt this
· rcases a with ⟨a | b, h⟩
· exact Sum.inl a
· exact Sum.inr ⟨b, by cases h; assumption⟩
· rcases a with ⟨a | a, h₁⟩ <;> rcases b with ⟨b | b, h₂⟩ <;> cases h₁ <;> cases h₂ <;>
rintro ⟨⟩ <;> constructor <;> assumption⟩
#align ordinal.add_le_of_limit Ordinal.add_le_of_limit
theorem add_isNormal (a : Ordinal) : IsNormal (a + ·) :=
⟨fun b => (add_lt_add_iff_left a).2 (lt_succ b), fun _b l _c => add_le_of_limit l⟩
#align ordinal.add_is_normal Ordinal.add_isNormal
theorem add_isLimit (a) {b} : IsLimit b → IsLimit (a + b) :=
(add_isNormal a).isLimit
#align ordinal.add_is_limit Ordinal.add_isLimit
alias IsLimit.add := add_isLimit
#align ordinal.is_limit.add Ordinal.IsLimit.add
/-! ### Subtraction on ordinals-/
/-- The set in the definition of subtraction is nonempty. -/
theorem sub_nonempty {a b : Ordinal} : { o | a ≤ b + o }.Nonempty :=
⟨a, le_add_left _ _⟩
#align ordinal.sub_nonempty Ordinal.sub_nonempty
/-- `a - b` is the unique ordinal satisfying `b + (a - b) = a` when `b ≤ a`. -/
instance sub : Sub Ordinal :=
⟨fun a b => sInf { o | a ≤ b + o }⟩
theorem le_add_sub (a b : Ordinal) : a ≤ b + (a - b) :=
csInf_mem sub_nonempty
#align ordinal.le_add_sub Ordinal.le_add_sub
theorem sub_le {a b c : Ordinal} : a - b ≤ c ↔ a ≤ b + c :=
⟨fun h => (le_add_sub a b).trans (add_le_add_left h _), fun h => csInf_le' h⟩
#align ordinal.sub_le Ordinal.sub_le
theorem lt_sub {a b c : Ordinal} : a < b - c ↔ c + a < b :=
lt_iff_lt_of_le_iff_le sub_le
#align ordinal.lt_sub Ordinal.lt_sub
theorem add_sub_cancel (a b : Ordinal) : a + b - a = b :=
le_antisymm (sub_le.2 <| le_rfl) ((add_le_add_iff_left a).1 <| le_add_sub _ _)
#align ordinal.add_sub_cancel Ordinal.add_sub_cancel
theorem sub_eq_of_add_eq {a b c : Ordinal} (h : a + b = c) : c - a = b :=
h ▸ add_sub_cancel _ _
#align ordinal.sub_eq_of_add_eq Ordinal.sub_eq_of_add_eq
theorem sub_le_self (a b : Ordinal) : a - b ≤ a :=
sub_le.2 <| le_add_left _ _
#align ordinal.sub_le_self Ordinal.sub_le_self
protected theorem add_sub_cancel_of_le {a b : Ordinal} (h : b ≤ a) : b + (a - b) = a :=
(le_add_sub a b).antisymm'
(by
rcases zero_or_succ_or_limit (a - b) with (e | ⟨c, e⟩ | l)
· simp only [e, add_zero, h]
· rw [e, add_succ, succ_le_iff, ← lt_sub, e]
exact lt_succ c
· exact (add_le_of_limit l).2 fun c l => (lt_sub.1 l).le)
#align ordinal.add_sub_cancel_of_le Ordinal.add_sub_cancel_of_le
theorem le_sub_of_le {a b c : Ordinal} (h : b ≤ a) : c ≤ a - b ↔ b + c ≤ a := by
rw [← add_le_add_iff_left b, Ordinal.add_sub_cancel_of_le h]
#align ordinal.le_sub_of_le Ordinal.le_sub_of_le
theorem sub_lt_of_le {a b c : Ordinal} (h : b ≤ a) : a - b < c ↔ a < b + c :=
lt_iff_lt_of_le_iff_le (le_sub_of_le h)
#align ordinal.sub_lt_of_le Ordinal.sub_lt_of_le
instance existsAddOfLE : ExistsAddOfLE Ordinal :=
⟨fun h => ⟨_, (Ordinal.add_sub_cancel_of_le h).symm⟩⟩
@[simp]
theorem sub_zero (a : Ordinal) : a - 0 = a := by simpa only [zero_add] using add_sub_cancel 0 a
#align ordinal.sub_zero Ordinal.sub_zero
@[simp]
theorem zero_sub (a : Ordinal) : 0 - a = 0 := by rw [← Ordinal.le_zero]; apply sub_le_self
#align ordinal.zero_sub Ordinal.zero_sub
@[simp]
theorem sub_self (a : Ordinal) : a - a = 0 := by simpa only [add_zero] using add_sub_cancel a 0
#align ordinal.sub_self Ordinal.sub_self
protected theorem sub_eq_zero_iff_le {a b : Ordinal} : a - b = 0 ↔ a ≤ b :=
⟨fun h => by simpa only [h, add_zero] using le_add_sub a b, fun h => by
rwa [← Ordinal.le_zero, sub_le, add_zero]⟩
#align ordinal.sub_eq_zero_iff_le Ordinal.sub_eq_zero_iff_le
theorem sub_sub (a b c : Ordinal) : a - b - c = a - (b + c) :=
eq_of_forall_ge_iff fun d => by rw [sub_le, sub_le, sub_le, add_assoc]
#align ordinal.sub_sub Ordinal.sub_sub
@[simp]
theorem add_sub_add_cancel (a b c : Ordinal) : a + b - (a + c) = b - c := by
rw [← sub_sub, add_sub_cancel]
#align ordinal.add_sub_add_cancel Ordinal.add_sub_add_cancel
theorem sub_isLimit {a b} (l : IsLimit a) (h : b < a) : IsLimit (a - b) :=
⟨ne_of_gt <| lt_sub.2 <| by rwa [add_zero], fun c h => by
rw [lt_sub, add_succ]; exact l.2 _ (lt_sub.1 h)⟩
#align ordinal.sub_is_limit Ordinal.sub_isLimit
-- @[simp] -- Porting note (#10618): simp can prove this
theorem one_add_omega : 1 + ω = ω := by
refine le_antisymm ?_ (le_add_left _ _)
rw [omega, ← lift_one.{_, 0}, ← lift_add, lift_le, ← type_unit, ← type_sum_lex]
refine ⟨RelEmbedding.collapse (RelEmbedding.ofMonotone ?_ ?_)⟩
· apply Sum.rec
· exact fun _ => 0
· exact Nat.succ
· intro a b
cases a <;> cases b <;> intro H <;> cases' H with _ _ H _ _ H <;>
[exact H.elim; exact Nat.succ_pos _; exact Nat.succ_lt_succ H]
#align ordinal.one_add_omega Ordinal.one_add_omega
@[simp]
theorem one_add_of_omega_le {o} (h : ω ≤ o) : 1 + o = o := by
rw [← Ordinal.add_sub_cancel_of_le h, ← add_assoc, one_add_omega]
#align ordinal.one_add_of_omega_le Ordinal.one_add_of_omega_le
/-! ### Multiplication of ordinals-/
/-- The multiplication of ordinals `o₁` and `o₂` is the (well founded) lexicographic order on
`o₂ × o₁`. -/
instance monoid : Monoid Ordinal.{u} where
mul a b :=
Quotient.liftOn₂ a b
(fun ⟨α, r, wo⟩ ⟨β, s, wo'⟩ => ⟦⟨β × α, Prod.Lex s r, inferInstance⟩⟧ :
WellOrder → WellOrder → Ordinal)
fun ⟨α₁, r₁, o₁⟩ ⟨α₂, r₂, o₂⟩ ⟨β₁, s₁, p₁⟩ ⟨β₂, s₂, p₂⟩ ⟨f⟩ ⟨g⟩ =>
Quot.sound ⟨RelIso.prodLexCongr g f⟩
one := 1
mul_assoc a b c :=
Quotient.inductionOn₃ a b c fun ⟨α, r, _⟩ ⟨β, s, _⟩ ⟨γ, t, _⟩ =>
Eq.symm <|
Quotient.sound
⟨⟨prodAssoc _ _ _, @fun a b => by
rcases a with ⟨⟨a₁, a₂⟩, a₃⟩
rcases b with ⟨⟨b₁, b₂⟩, b₃⟩
simp [Prod.lex_def, and_or_left, or_assoc, and_assoc]⟩⟩
mul_one a :=
inductionOn a fun α r _ =>
Quotient.sound
⟨⟨punitProd _, @fun a b => by
rcases a with ⟨⟨⟨⟩⟩, a⟩; rcases b with ⟨⟨⟨⟩⟩, b⟩
simp only [Prod.lex_def, EmptyRelation, false_or_iff]
simp only [eq_self_iff_true, true_and_iff]
rfl⟩⟩
one_mul a :=
inductionOn a fun α r _ =>
Quotient.sound
⟨⟨prodPUnit _, @fun a b => by
rcases a with ⟨a, ⟨⟨⟩⟩⟩; rcases b with ⟨b, ⟨⟨⟩⟩⟩
simp only [Prod.lex_def, EmptyRelation, and_false_iff, or_false_iff]
rfl⟩⟩
@[simp]
theorem type_prod_lex {α β : Type u} (r : α → α → Prop) (s : β → β → Prop) [IsWellOrder α r]
[IsWellOrder β s] : type (Prod.Lex s r) = type r * type s :=
rfl
#align ordinal.type_prod_lex Ordinal.type_prod_lex
private theorem mul_eq_zero' {a b : Ordinal} : a * b = 0 ↔ a = 0 ∨ b = 0 :=
inductionOn a fun α _ _ =>
inductionOn b fun β _ _ => by
simp_rw [← type_prod_lex, type_eq_zero_iff_isEmpty]
rw [or_comm]
exact isEmpty_prod
instance monoidWithZero : MonoidWithZero Ordinal :=
{ Ordinal.monoid with
zero := 0
mul_zero := fun _a => mul_eq_zero'.2 <| Or.inr rfl
zero_mul := fun _a => mul_eq_zero'.2 <| Or.inl rfl }
instance noZeroDivisors : NoZeroDivisors Ordinal :=
⟨fun {_ _} => mul_eq_zero'.1⟩
@[simp]
theorem lift_mul (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.prodLexCongr (RelIso.preimage Equiv.ulift _)
(RelIso.preimage Equiv.ulift _)).symm⟩
#align ordinal.lift_mul Ordinal.lift_mul
@[simp]
theorem card_mul (a b) : card (a * b) = card a * card b :=
Quotient.inductionOn₂ a b fun ⟨α, _r, _⟩ ⟨β, _s, _⟩ => mul_comm #β #α
#align ordinal.card_mul Ordinal.card_mul
instance leftDistribClass : LeftDistribClass Ordinal.{u} :=
⟨fun a b c =>
Quotient.inductionOn₃ a b c fun ⟨α, r, _⟩ ⟨β, s, _⟩ ⟨γ, t, _⟩ =>
Quotient.sound
⟨⟨sumProdDistrib _ _ _, by
rintro ⟨a₁ | a₁, a₂⟩ ⟨b₁ | b₁, b₂⟩ <;>
simp only [Prod.lex_def, Sum.lex_inl_inl, Sum.Lex.sep, Sum.lex_inr_inl,
Sum.lex_inr_inr, sumProdDistrib_apply_left, sumProdDistrib_apply_right] <;>
-- Porting note: `Sum.inr.inj_iff` is required.
simp only [Sum.inl.inj_iff, Sum.inr.inj_iff,
true_or_iff, false_and_iff, false_or_iff]⟩⟩⟩
theorem mul_succ (a b : Ordinal) : a * succ b = a * b + a :=
mul_add_one a b
#align ordinal.mul_succ Ordinal.mul_succ
instance mul_covariantClass_le : CovariantClass Ordinal.{u} Ordinal.{u} (· * ·) (· ≤ ·) :=
⟨fun c a b =>
Quotient.inductionOn₃ a b c fun ⟨α, r, _⟩ ⟨β, s, _⟩ ⟨γ, t, _⟩ ⟨f⟩ => by
refine
(RelEmbedding.ofMonotone (fun a : α × γ => (f a.1, a.2)) fun a b h => ?_).ordinal_type_le
cases' h with a₁ b₁ a₂ b₂ h' a b₁ b₂ h'
· exact Prod.Lex.left _ _ (f.toRelEmbedding.map_rel_iff.2 h')
· exact Prod.Lex.right _ h'⟩
#align ordinal.mul_covariant_class_le Ordinal.mul_covariantClass_le
instance mul_swap_covariantClass_le :
CovariantClass Ordinal.{u} Ordinal.{u} (swap (· * ·)) (· ≤ ·) :=
⟨fun c a b =>
Quotient.inductionOn₃ a b c fun ⟨α, r, _⟩ ⟨β, s, _⟩ ⟨γ, t, _⟩ ⟨f⟩ => by
refine
(RelEmbedding.ofMonotone (fun a : γ × α => (a.1, f a.2)) fun a b h => ?_).ordinal_type_le
cases' h with a₁ b₁ a₂ b₂ h' a b₁ b₂ h'
· exact Prod.Lex.left _ _ h'
· exact Prod.Lex.right _ (f.toRelEmbedding.map_rel_iff.2 h')⟩
#align ordinal.mul_swap_covariant_class_le Ordinal.mul_swap_covariantClass_le
theorem le_mul_left (a : Ordinal) {b : Ordinal} (hb : 0 < b) : a ≤ a * b := by
convert mul_le_mul_left' (one_le_iff_pos.2 hb) a
rw [mul_one a]
#align ordinal.le_mul_left Ordinal.le_mul_left
theorem le_mul_right (a : Ordinal) {b : Ordinal} (hb : 0 < b) : a ≤ b * a := by
convert mul_le_mul_right' (one_le_iff_pos.2 hb) a
rw [one_mul a]
#align ordinal.le_mul_right Ordinal.le_mul_right
private theorem mul_le_of_limit_aux {α β r s} [IsWellOrder α r] [IsWellOrder β s] {c}
(h : IsLimit (type s)) (H : ∀ b' < type s, type r * b' ≤ c) (l : c < type r * type s) :
False := by
suffices ∀ a b, Prod.Lex s r (b, a) (enum _ _ l) by
cases' enum _ _ l with b a
exact irrefl _ (this _ _)
intro a b
rw [← typein_lt_typein (Prod.Lex s r), typein_enum]
have := H _ (h.2 _ (typein_lt_type s b))
rw [mul_succ] at this
have := ((add_lt_add_iff_left _).2 (typein_lt_type _ a)).trans_le this
refine (RelEmbedding.ofMonotone (fun a => ?_) fun a b => ?_).ordinal_type_le.trans_lt this
· rcases a with ⟨⟨b', a'⟩, h⟩
by_cases e : b = b'
· refine Sum.inr ⟨a', ?_⟩
subst e
cases' h with _ _ _ _ h _ _ _ h
· exact (irrefl _ h).elim
· exact h
· refine Sum.inl (⟨b', ?_⟩, a')
cases' h with _ _ _ _ h _ _ _ h
· exact h
· exact (e rfl).elim
· rcases a with ⟨⟨b₁, a₁⟩, h₁⟩
rcases b with ⟨⟨b₂, a₂⟩, h₂⟩
intro h
by_cases e₁ : b = b₁ <;> by_cases e₂ : b = b₂
· substs b₁ b₂
simpa only [subrel_val, Prod.lex_def, @irrefl _ s _ b, true_and_iff, false_or_iff,
eq_self_iff_true, dif_pos, Sum.lex_inr_inr] using h
· subst b₁
simp only [subrel_val, Prod.lex_def, e₂, Prod.lex_def, dif_pos, subrel_val, eq_self_iff_true,
or_false_iff, dif_neg, not_false_iff, Sum.lex_inr_inl, false_and_iff] at h ⊢
cases' h₂ with _ _ _ _ h₂_h h₂_h <;> [exact asymm h h₂_h; exact e₂ rfl]
-- Porting note: `cc` hadn't ported yet.
· simp [e₂, dif_neg e₁, show b₂ ≠ b₁ from e₂ ▸ e₁]
· simpa only [dif_neg e₁, dif_neg e₂, Prod.lex_def, subrel_val, Subtype.mk_eq_mk,
Sum.lex_inl_inl] using h
theorem mul_le_of_limit {a b c : Ordinal} (h : IsLimit b) : a * b ≤ c ↔ ∀ b' < b, a * b' ≤ c :=
⟨fun h b' l => (mul_le_mul_left' l.le _).trans h, fun H =>
-- Porting note: `induction` tactics are required because of the parser bug.
le_of_not_lt <| by
induction a using inductionOn with
| H α r =>
induction b using inductionOn with
| H β s =>
exact mul_le_of_limit_aux h H⟩
#align ordinal.mul_le_of_limit Ordinal.mul_le_of_limit
theorem mul_isNormal {a : Ordinal} (h : 0 < a) : IsNormal (a * ·) :=
-- Porting note(#12129): additional beta reduction needed
⟨fun b => by
beta_reduce
rw [mul_succ]
simpa only [add_zero] using (add_lt_add_iff_left (a * b)).2 h,
fun b l c => mul_le_of_limit l⟩
#align ordinal.mul_is_normal Ordinal.mul_isNormal
theorem lt_mul_of_limit {a b c : Ordinal} (h : IsLimit c) : a < b * c ↔ ∃ c' < c, a < b * c' := by
-- Porting note: `bex_def` is required.
simpa only [not_forall₂, not_le, bex_def] using not_congr (@mul_le_of_limit b c a h)
#align ordinal.lt_mul_of_limit Ordinal.lt_mul_of_limit
theorem mul_lt_mul_iff_left {a b c : Ordinal} (a0 : 0 < a) : a * b < a * c ↔ b < c :=
(mul_isNormal a0).lt_iff
#align ordinal.mul_lt_mul_iff_left Ordinal.mul_lt_mul_iff_left
theorem mul_le_mul_iff_left {a b c : Ordinal} (a0 : 0 < a) : a * b ≤ a * c ↔ b ≤ c :=
(mul_isNormal a0).le_iff
#align ordinal.mul_le_mul_iff_left Ordinal.mul_le_mul_iff_left
theorem mul_lt_mul_of_pos_left {a b c : Ordinal} (h : a < b) (c0 : 0 < c) : c * a < c * b :=
(mul_lt_mul_iff_left c0).2 h
#align ordinal.mul_lt_mul_of_pos_left Ordinal.mul_lt_mul_of_pos_left
theorem mul_pos {a b : Ordinal} (h₁ : 0 < a) (h₂ : 0 < b) : 0 < a * b := by
simpa only [mul_zero] using mul_lt_mul_of_pos_left h₂ h₁
#align ordinal.mul_pos Ordinal.mul_pos
theorem mul_ne_zero {a b : Ordinal} : a ≠ 0 → b ≠ 0 → a * b ≠ 0 := by
simpa only [Ordinal.pos_iff_ne_zero] using mul_pos
#align ordinal.mul_ne_zero Ordinal.mul_ne_zero
theorem le_of_mul_le_mul_left {a b c : Ordinal} (h : c * a ≤ c * b) (h0 : 0 < c) : a ≤ b :=
le_imp_le_of_lt_imp_lt (fun h' => mul_lt_mul_of_pos_left h' h0) h
#align ordinal.le_of_mul_le_mul_left Ordinal.le_of_mul_le_mul_left
theorem mul_right_inj {a b c : Ordinal} (a0 : 0 < a) : a * b = a * c ↔ b = c :=
(mul_isNormal a0).inj
#align ordinal.mul_right_inj Ordinal.mul_right_inj
theorem mul_isLimit {a b : Ordinal} (a0 : 0 < a) : IsLimit b → IsLimit (a * b) :=
(mul_isNormal a0).isLimit
#align ordinal.mul_is_limit Ordinal.mul_isLimit
theorem mul_isLimit_left {a b : Ordinal} (l : IsLimit a) (b0 : 0 < b) : IsLimit (a * b) := by
rcases zero_or_succ_or_limit b with (rfl | ⟨b, rfl⟩ | lb)
· exact b0.false.elim
· rw [mul_succ]
exact add_isLimit _ l
· exact mul_isLimit l.pos lb
#align ordinal.mul_is_limit_left Ordinal.mul_isLimit_left
theorem smul_eq_mul : ∀ (n : ℕ) (a : Ordinal), n • a = a * n
| 0, a => by rw [zero_nsmul, Nat.cast_zero, mul_zero]
| n + 1, a => by rw [succ_nsmul, Nat.cast_add, mul_add, Nat.cast_one, mul_one, smul_eq_mul n]
#align ordinal.smul_eq_mul Ordinal.smul_eq_mul
/-! ### Division on ordinals -/
/-- The set in the definition of division is nonempty. -/
theorem div_nonempty {a b : Ordinal} (h : b ≠ 0) : { o | a < b * succ o }.Nonempty :=
⟨a, (succ_le_iff (a := a) (b := b * succ a)).1 <| by
simpa only [succ_zero, one_mul] using
mul_le_mul_right' (succ_le_of_lt (Ordinal.pos_iff_ne_zero.2 h)) (succ a)⟩
#align ordinal.div_nonempty Ordinal.div_nonempty
/-- `a / b` is the unique ordinal `o` satisfying `a = b * o + o'` with `o' < b`. -/
instance div : Div Ordinal :=
⟨fun a b => if _h : b = 0 then 0 else sInf { o | a < b * succ o }⟩
@[simp]
theorem div_zero (a : Ordinal) : a / 0 = 0 :=
dif_pos rfl
#align ordinal.div_zero Ordinal.div_zero
theorem div_def (a) {b : Ordinal} (h : b ≠ 0) : a / b = sInf { o | a < b * succ o } :=
dif_neg h
#align ordinal.div_def Ordinal.div_def
theorem lt_mul_succ_div (a) {b : Ordinal} (h : b ≠ 0) : a < b * succ (a / b) := by
rw [div_def a h]; exact csInf_mem (div_nonempty h)
#align ordinal.lt_mul_succ_div Ordinal.lt_mul_succ_div
theorem lt_mul_div_add (a) {b : Ordinal} (h : b ≠ 0) : a < b * (a / b) + b := by
simpa only [mul_succ] using lt_mul_succ_div a h
#align ordinal.lt_mul_div_add Ordinal.lt_mul_div_add
theorem div_le {a b c : Ordinal} (b0 : b ≠ 0) : a / b ≤ c ↔ a < b * succ c :=
⟨fun h => (lt_mul_succ_div a b0).trans_le (mul_le_mul_left' (succ_le_succ_iff.2 h) _), fun h => by
rw [div_def a b0]; exact csInf_le' h⟩
#align ordinal.div_le Ordinal.div_le
theorem lt_div {a b c : Ordinal} (h : c ≠ 0) : a < b / c ↔ c * succ a ≤ b := by
rw [← not_le, div_le h, not_lt]
#align ordinal.lt_div Ordinal.lt_div
theorem div_pos {b c : Ordinal} (h : c ≠ 0) : 0 < b / c ↔ c ≤ b := by simp [lt_div h]
#align ordinal.div_pos Ordinal.div_pos
theorem le_div {a b c : Ordinal} (c0 : c ≠ 0) : a ≤ b / c ↔ c * a ≤ b := by
induction a using limitRecOn with
| H₁ => simp only [mul_zero, Ordinal.zero_le]
| H₂ _ _ => rw [succ_le_iff, lt_div c0]
| H₃ _ h₁ h₂ =>
revert h₁ h₂
simp (config := { contextual := true }) only [mul_le_of_limit, limit_le, iff_self_iff,
forall_true_iff]
#align ordinal.le_div Ordinal.le_div
theorem div_lt {a b c : Ordinal} (b0 : b ≠ 0) : a / b < c ↔ a < b * c :=
lt_iff_lt_of_le_iff_le <| le_div b0
#align ordinal.div_lt Ordinal.div_lt
theorem div_le_of_le_mul {a b c : Ordinal} (h : a ≤ b * c) : a / b ≤ c :=
if b0 : b = 0 then by simp only [b0, div_zero, Ordinal.zero_le]
else
(div_le b0).2 <| h.trans_lt <| mul_lt_mul_of_pos_left (lt_succ c) (Ordinal.pos_iff_ne_zero.2 b0)
#align ordinal.div_le_of_le_mul Ordinal.div_le_of_le_mul
theorem mul_lt_of_lt_div {a b c : Ordinal} : a < b / c → c * a < b :=
lt_imp_lt_of_le_imp_le div_le_of_le_mul
#align ordinal.mul_lt_of_lt_div Ordinal.mul_lt_of_lt_div
@[simp]
theorem zero_div (a : Ordinal) : 0 / a = 0 :=
Ordinal.le_zero.1 <| div_le_of_le_mul <| Ordinal.zero_le _
#align ordinal.zero_div Ordinal.zero_div
theorem mul_div_le (a b : Ordinal) : b * (a / b) ≤ a :=
if b0 : b = 0 then by simp only [b0, zero_mul, Ordinal.zero_le] else (le_div b0).1 le_rfl
#align ordinal.mul_div_le Ordinal.mul_div_le
theorem mul_add_div (a) {b : Ordinal} (b0 : b ≠ 0) (c) : (b * a + c) / b = a + c / b := by
apply le_antisymm
· apply (div_le b0).2
rw [mul_succ, mul_add, add_assoc, add_lt_add_iff_left]
apply lt_mul_div_add _ b0
· rw [le_div b0, mul_add, add_le_add_iff_left]
apply mul_div_le
#align ordinal.mul_add_div Ordinal.mul_add_div
theorem div_eq_zero_of_lt {a b : Ordinal} (h : a < b) : a / b = 0 := by
rw [← Ordinal.le_zero, div_le <| Ordinal.pos_iff_ne_zero.1 <| (Ordinal.zero_le _).trans_lt h]
simpa only [succ_zero, mul_one] using h
#align ordinal.div_eq_zero_of_lt Ordinal.div_eq_zero_of_lt
@[simp]
theorem mul_div_cancel (a) {b : Ordinal} (b0 : b ≠ 0) : b * a / b = a := by
simpa only [add_zero, zero_div] using mul_add_div a b0 0
#align ordinal.mul_div_cancel Ordinal.mul_div_cancel
@[simp]
theorem div_one (a : Ordinal) : a / 1 = a := by
simpa only [one_mul] using mul_div_cancel a Ordinal.one_ne_zero
#align ordinal.div_one Ordinal.div_one
@[simp]
theorem div_self {a : Ordinal} (h : a ≠ 0) : a / a = 1 := by
simpa only [mul_one] using mul_div_cancel 1 h
#align ordinal.div_self Ordinal.div_self
theorem mul_sub (a b c : Ordinal) : a * (b - c) = a * b - a * c :=
if a0 : a = 0 then by simp only [a0, zero_mul, sub_self]
else
eq_of_forall_ge_iff fun d => by rw [sub_le, ← le_div a0, sub_le, ← le_div a0, mul_add_div _ a0]
#align ordinal.mul_sub Ordinal.mul_sub
| Mathlib/SetTheory/Ordinal/Arithmetic.lean | 969 | 982 | theorem isLimit_add_iff {a b} : IsLimit (a + b) ↔ IsLimit b ∨ b = 0 ∧ IsLimit a := by |
constructor <;> intro h
· by_cases h' : b = 0
· rw [h', add_zero] at h
right
exact ⟨h', h⟩
left
rw [← add_sub_cancel a b]
apply sub_isLimit h
suffices a + 0 < a + b by simpa only [add_zero] using this
rwa [add_lt_add_iff_left, Ordinal.pos_iff_ne_zero]
rcases h with (h | ⟨rfl, h⟩)
· exact add_isLimit a h
· simpa only [add_zero]
|
/-
Copyright (c) 2022 Joël Riou. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Joël Riou
-/
import Mathlib.CategoryTheory.MorphismProperty.Composition
import Mathlib.CategoryTheory.MorphismProperty.IsInvertedBy
import Mathlib.CategoryTheory.Category.Quiv
#align_import category_theory.localization.construction from "leanprover-community/mathlib"@"1a5e56f2166e4e9d0964c71f4273b1d39227678d"
/-!
# Construction of the localized category
This file constructs the localized category, obtained by formally inverting
a class of maps `W : MorphismProperty C` in a category `C`.
We first construct a quiver `LocQuiver W` whose objects are the same as those
of `C` and whose maps are the maps in `C` and placeholders for the formal
inverses of the maps in `W`.
The localized category `W.Localization` is obtained by taking the quotient
of the path category of `LocQuiver W` by the congruence generated by four
types of relations.
The obvious functor `Q W : C ⥤ W.Localization` satisfies the universal property
of the localization. Indeed, if `G : C ⥤ D` sends morphisms in `W` to isomorphisms
in `D` (i.e. we have `hG : W.IsInvertedBy G`), then there exists a unique functor
`G' : W.Localization ⥤ D` such that `Q W ≫ G' = G`. This `G'` is `lift G hG`.
The expected property of `lift G hG` if expressed by the lemma `fac` and the
uniqueness is expressed by `uniq`.
## References
* [P. Gabriel, M. Zisman, *Calculus of fractions and homotopy theory*][gabriel-zisman-1967]
-/
noncomputable section
open CategoryTheory.Category
namespace CategoryTheory
-- category universes first for convenience
universe uC' uD' uC uD
variable {C : Type uC} [Category.{uC'} C] (W : MorphismProperty C) {D : Type uD} [Category.{uD'} D]
namespace Localization
namespace Construction
-- porting note (#5171): removed @[nolint has_nonempty_instance]
/-- If `W : MorphismProperty C`, `LocQuiver W` is a quiver with the same objects
as `C`, and whose morphisms are those in `C` and placeholders for formal
inverses of the morphisms in `W`. -/
structure LocQuiver (W : MorphismProperty C) where
/-- underlying object -/
obj : C
#align category_theory.localization.construction.loc_quiver CategoryTheory.Localization.Construction.LocQuiver
instance : Quiver (LocQuiver W) where Hom A B := Sum (A.obj ⟶ B.obj) { f : B.obj ⟶ A.obj // W f }
/-- The object in the path category of `LocQuiver W` attached to an object in
the category `C` -/
def ιPaths (X : C) : Paths (LocQuiver W) :=
⟨X⟩
#align category_theory.localization.construction.ι_paths CategoryTheory.Localization.Construction.ιPaths
/-- The morphism in the path category associated to a morphism in the original category. -/
@[simp]
def ψ₁ {X Y : C} (f : X ⟶ Y) : ιPaths W X ⟶ ιPaths W Y :=
Paths.of.map (Sum.inl f)
#align category_theory.localization.construction.ψ₁ CategoryTheory.Localization.Construction.ψ₁
/-- The morphism in the path category corresponding to a formal inverse. -/
@[simp]
def ψ₂ {X Y : C} (w : X ⟶ Y) (hw : W w) : ιPaths W Y ⟶ ιPaths W X :=
Paths.of.map (Sum.inr ⟨w, hw⟩)
#align category_theory.localization.construction.ψ₂ CategoryTheory.Localization.Construction.ψ₂
/-- The relations by which we take the quotient in order to get the localized category. -/
inductive relations : HomRel (Paths (LocQuiver W))
| id (X : C) : relations (ψ₁ W (𝟙 X)) (𝟙 _)
| comp {X Y Z : C} (f : X ⟶ Y) (g : Y ⟶ Z) : relations (ψ₁ W (f ≫ g)) (ψ₁ W f ≫ ψ₁ W g)
| Winv₁ {X Y : C} (w : X ⟶ Y) (hw : W w) : relations (ψ₁ W w ≫ ψ₂ W w hw) (𝟙 _)
| Winv₂ {X Y : C} (w : X ⟶ Y) (hw : W w) : relations (ψ₂ W w hw ≫ ψ₁ W w) (𝟙 _)
#align category_theory.localization.construction.relations CategoryTheory.Localization.Construction.relations
end Construction
end Localization
namespace MorphismProperty
open Localization.Construction
-- porting note (#5171): removed @[nolint has_nonempty_instance]
/-- The localized category obtained by formally inverting the morphisms
in `W : MorphismProperty C` -/
def Localization :=
CategoryTheory.Quotient (Localization.Construction.relations W)
#align category_theory.morphism_property.localization CategoryTheory.MorphismProperty.Localization
instance : Category (Localization W) := by
dsimp only [Localization]
infer_instance
/-- The obvious functor `C ⥤ W.Localization` -/
def Q : C ⥤ W.Localization where
obj X := (Quotient.functor _).obj (Paths.of.obj ⟨X⟩)
map f := (Quotient.functor _).map (ψ₁ W f)
map_id X := Quotient.sound _ (relations.id X)
map_comp f g := Quotient.sound _ (relations.comp f g)
set_option linter.uppercaseLean3 false in
#align category_theory.morphism_property.Q CategoryTheory.MorphismProperty.Q
end MorphismProperty
namespace Localization
namespace Construction
variable {W}
/-- The isomorphism in `W.Localization` associated to a morphism `w` in W -/
def wIso {X Y : C} (w : X ⟶ Y) (hw : W w) : Iso (W.Q.obj X) (W.Q.obj Y) where
hom := W.Q.map w
inv := (Quotient.functor _).map (by dsimp; exact Paths.of.map (Sum.inr ⟨w, hw⟩))
hom_inv_id := Quotient.sound _ (relations.Winv₁ w hw)
inv_hom_id := Quotient.sound _ (relations.Winv₂ w hw)
set_option linter.uppercaseLean3 false in
#align category_theory.localization.construction.Wiso CategoryTheory.Localization.Construction.wIso
/-- The formal inverse in `W.Localization` of a morphism `w` in `W`. -/
abbrev winv {X Y : C} (w : X ⟶ Y) (hw : W w) :=
(wIso w hw).inv
set_option linter.uppercaseLean3 false in
#align category_theory.localization.construction.Winv CategoryTheory.Localization.Construction.winv
variable (W)
theorem _root_.CategoryTheory.MorphismProperty.Q_inverts : W.IsInvertedBy W.Q := fun _ _ w hw =>
(Localization.Construction.wIso w hw).isIso_hom
set_option linter.uppercaseLean3 false in
#align category_theory.morphism_property.Q_inverts CategoryTheory.MorphismProperty.Q_inverts
variable {W} (G : C ⥤ D) (hG : W.IsInvertedBy G)
/-- The lifting of a functor to the path category of `LocQuiver W` -/
@[simps!]
def liftToPathCategory : Paths (LocQuiver W) ⥤ D :=
Quiv.lift
{ obj := fun X => G.obj X.obj
map := by
intros X Y
rintro (f | ⟨g, hg⟩)
· exact G.map f
· haveI := hG g hg
exact inv (G.map g) }
#align category_theory.localization.construction.lift_to_path_category CategoryTheory.Localization.Construction.liftToPathCategory
/-- The lifting of a functor `C ⥤ D` inverting `W` as a functor `W.Localization ⥤ D` -/
@[simps!]
def lift : W.Localization ⥤ D :=
Quotient.lift (relations W) (liftToPathCategory G hG)
(by
rintro ⟨X⟩ ⟨Y⟩ f₁ f₂ r
-- Porting note: rest of proof was `rcases r with ⟨⟩; tidy`
rcases r with (_|_|⟨f,hf⟩|⟨f,hf⟩)
· aesop_cat
· aesop_cat
all_goals
dsimp
haveI := hG f hf
simp
rfl)
#align category_theory.localization.construction.lift CategoryTheory.Localization.Construction.lift
@[simp]
theorem fac : W.Q ⋙ lift G hG = G :=
Functor.ext (fun X => rfl)
(by
intro X Y f
simp only [Functor.comp_map, eqToHom_refl, comp_id, id_comp]
dsimp [MorphismProperty.Q, Quot.liftOn, Quotient.functor]
rw [composePath_toPath])
#align category_theory.localization.construction.fac CategoryTheory.Localization.Construction.fac
theorem uniq (G₁ G₂ : W.Localization ⥤ D) (h : W.Q ⋙ G₁ = W.Q ⋙ G₂) : G₁ = G₂ := by
suffices h' : Quotient.functor _ ⋙ G₁ = Quotient.functor _ ⋙ G₂ by
refine Functor.ext ?_ ?_
· rintro ⟨⟨X⟩⟩
apply Functor.congr_obj h
· rintro ⟨⟨X⟩⟩ ⟨⟨Y⟩⟩ ⟨f⟩
apply Functor.congr_hom h'
refine Paths.ext_functor ?_ ?_
· ext X
cases X
apply Functor.congr_obj h
· rintro ⟨X⟩ ⟨Y⟩ (f | ⟨w, hw⟩)
· simpa only using Functor.congr_hom h f
· have hw : W.Q.map w = (wIso w hw).hom := rfl
have hw' := Functor.congr_hom h w
simp only [Functor.comp_map, hw] at hw'
refine Functor.congr_inv_of_congr_hom _ _ _ ?_ ?_ hw'
all_goals apply Functor.congr_obj h
#align category_theory.localization.construction.uniq CategoryTheory.Localization.Construction.uniq
variable (W)
/-- The canonical bijection between objects in a category and its
localization with respect to a morphism_property `W` -/
@[simps]
def objEquiv : C ≃ W.Localization where
toFun := W.Q.obj
invFun X := X.as.obj
left_inv X := rfl
right_inv := by
rintro ⟨⟨X⟩⟩
rfl
#align category_theory.localization.construction.obj_equiv CategoryTheory.Localization.Construction.objEquiv
variable {W}
/-- A `MorphismProperty` in `W.Localization` is satisfied by all
morphisms in the localized category if it contains the image of the
morphisms in the original category, the inverses of the morphisms
in `W` and if it is stable under composition -/
theorem morphismProperty_is_top (P : MorphismProperty W.Localization)
[P.IsStableUnderComposition] (hP₁ : ∀ ⦃X Y : C⦄ (f : X ⟶ Y), P (W.Q.map f))
(hP₂ : ∀ ⦃X Y : C⦄ (w : X ⟶ Y) (hw : W w), P (winv w hw)) :
P = ⊤ := by
funext X Y f
ext
constructor
· intro
apply MorphismProperty.top_apply
· intro
let G : _ ⥤ W.Localization := Quotient.functor _
haveI : G.Full := Quotient.full_functor _
suffices ∀ (X₁ X₂ : Paths (LocQuiver W)) (f : X₁ ⟶ X₂), P (G.map f) by
rcases X with ⟨⟨X⟩⟩
rcases Y with ⟨⟨Y⟩⟩
simpa only [Functor.map_preimage] using this _ _ (G.preimage f)
intros X₁ X₂ p
induction' p with X₂ X₃ p g hp
· simpa only [Functor.map_id] using hP₁ (𝟙 X₁.obj)
· let p' : X₁ ⟶X₂ := p
rw [show p'.cons g = p' ≫ Quiver.Hom.toPath g by rfl, G.map_comp]
refine P.comp_mem _ _ hp ?_
rcases g with (g | ⟨g, hg⟩)
· apply hP₁
· apply hP₂
#align category_theory.localization.construction.morphism_property_is_top CategoryTheory.Localization.Construction.morphismProperty_is_top
/-- A `MorphismProperty` in `W.Localization` is satisfied by all
morphisms in the localized category if it contains the image of the
morphisms in the original category, if is stable under composition
and if the property is stable by passing to inverses. -/
theorem morphismProperty_is_top' (P : MorphismProperty W.Localization)
[P.IsStableUnderComposition] (hP₁ : ∀ ⦃X Y : C⦄ (f : X ⟶ Y), P (W.Q.map f))
(hP₂ : ∀ ⦃X Y : W.Localization⦄ (e : X ≅ Y) (_ : P e.hom), P e.inv) : P = ⊤ :=
morphismProperty_is_top P hP₁ (fun _ _ w _ => hP₂ _ (hP₁ w))
#align category_theory.localization.construction.morphism_property_is_top' CategoryTheory.Localization.Construction.morphismProperty_is_top'
namespace NatTransExtension
variable {F₁ F₂ : W.Localization ⥤ D} (τ : W.Q ⋙ F₁ ⟶ W.Q ⋙ F₂)
/-- If `F₁` and `F₂` are functors `W.Localization ⥤ D` and if we have
`τ : W.Q ⋙ F₁ ⟶ W.Q ⋙ F₂`, we shall define a natural transformation `F₁ ⟶ F₂`.
This is the `app` field of this natural transformation. -/
def app (X : W.Localization) : F₁.obj X ⟶ F₂.obj X :=
eqToHom (congr_arg F₁.obj ((objEquiv W).right_inv X).symm) ≫
τ.app ((objEquiv W).invFun X) ≫ eqToHom (congr_arg F₂.obj ((objEquiv W).right_inv X))
#align category_theory.localization.construction.nat_trans_extension.app CategoryTheory.Localization.Construction.NatTransExtension.app
@[simp]
theorem app_eq (X : C) : (app τ) (W.Q.obj X) = τ.app X := by
simp only [app, eqToHom_refl, comp_id, id_comp]
rfl
#align category_theory.localization.construction.nat_trans_extension.app_eq CategoryTheory.Localization.Construction.NatTransExtension.app_eq
end NatTransExtension
/-- If `F₁` and `F₂` are functors `W.Localization ⥤ D`, a natural transformation `F₁ ⟶ F₂`
can be obtained from a natural transformation `W.Q ⋙ F₁ ⟶ W.Q ⋙ F₂`. -/
@[simps]
def natTransExtension {F₁ F₂ : W.Localization ⥤ D} (τ : W.Q ⋙ F₁ ⟶ W.Q ⋙ F₂) : F₁ ⟶ F₂ where
app := NatTransExtension.app τ
naturality := by
suffices MorphismProperty.naturalityProperty (NatTransExtension.app τ) = ⊤ by
intro X Y f
simpa only [← this] using MorphismProperty.top_apply f
refine morphismProperty_is_top'
(MorphismProperty.naturalityProperty (NatTransExtension.app τ))
?_ (MorphismProperty.naturalityProperty.stableUnderInverse _)
intros X Y f
dsimp
simpa only [NatTransExtension.app_eq] using τ.naturality f
#align category_theory.localization.construction.nat_trans_extension CategoryTheory.Localization.Construction.natTransExtension
@[simp]
| Mathlib/CategoryTheory/Localization/Construction.lean | 306 | 307 | theorem natTransExtension_hcomp {F G : W.Localization ⥤ D} (τ : W.Q ⋙ F ⟶ W.Q ⋙ G) :
𝟙 W.Q ◫ natTransExtension τ = τ := by | aesop_cat
|
/-
Copyright (c) 2022 Yaël Dillies. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies
-/
import Mathlib.Order.PropInstances
#align_import order.heyting.basic from "leanprover-community/mathlib"@"9ac7c0c8c4d7a535ec3e5b34b8859aab9233b2f4"
/-!
# Heyting algebras
This file defines Heyting, co-Heyting and bi-Heyting algebras.
A Heyting algebra is a bounded distributive lattice with an implication operation `⇨` such that
`a ≤ b ⇨ c ↔ a ⊓ b ≤ c`. It also comes with a pseudo-complement `ᶜ`, such that `aᶜ = a ⇨ ⊥`.
Co-Heyting algebras are dual to Heyting algebras. They have a difference `\` and a negation `¬`
such that `a \ b ≤ c ↔ a ≤ b ⊔ c` and `¬a = ⊤ \ a`.
Bi-Heyting algebras are Heyting algebras that are also co-Heyting algebras.
From a logic standpoint, Heyting algebras precisely model intuitionistic logic, whereas boolean
algebras model classical logic.
Heyting algebras are the order theoretic equivalent of cartesian-closed categories.
## Main declarations
* `GeneralizedHeytingAlgebra`: Heyting algebra without a top element (nor negation).
* `GeneralizedCoheytingAlgebra`: Co-Heyting algebra without a bottom element (nor complement).
* `HeytingAlgebra`: Heyting algebra.
* `CoheytingAlgebra`: Co-Heyting algebra.
* `BiheytingAlgebra`: bi-Heyting algebra.
## References
* [Francis Borceux, *Handbook of Categorical Algebra III*][borceux-vol3]
## Tags
Heyting, Brouwer, algebra, implication, negation, intuitionistic
-/
open Function OrderDual
universe u
variable {ι α β : Type*}
/-! ### Notation -/
section
variable (α β)
instance Prod.instHImp [HImp α] [HImp β] : HImp (α × β) :=
⟨fun a b => (a.1 ⇨ b.1, a.2 ⇨ b.2)⟩
instance Prod.instHNot [HNot α] [HNot β] : HNot (α × β) :=
⟨fun a => (¬a.1, ¬a.2)⟩
instance Prod.instSDiff [SDiff α] [SDiff β] : SDiff (α × β) :=
⟨fun a b => (a.1 \ b.1, a.2 \ b.2)⟩
instance Prod.instHasCompl [HasCompl α] [HasCompl β] : HasCompl (α × β) :=
⟨fun a => (a.1ᶜ, a.2ᶜ)⟩
end
@[simp]
theorem fst_himp [HImp α] [HImp β] (a b : α × β) : (a ⇨ b).1 = a.1 ⇨ b.1 :=
rfl
#align fst_himp fst_himp
@[simp]
theorem snd_himp [HImp α] [HImp β] (a b : α × β) : (a ⇨ b).2 = a.2 ⇨ b.2 :=
rfl
#align snd_himp snd_himp
@[simp]
theorem fst_hnot [HNot α] [HNot β] (a : α × β) : (¬a).1 = ¬a.1 :=
rfl
#align fst_hnot fst_hnot
@[simp]
theorem snd_hnot [HNot α] [HNot β] (a : α × β) : (¬a).2 = ¬a.2 :=
rfl
#align snd_hnot snd_hnot
@[simp]
theorem fst_sdiff [SDiff α] [SDiff β] (a b : α × β) : (a \ b).1 = a.1 \ b.1 :=
rfl
#align fst_sdiff fst_sdiff
@[simp]
theorem snd_sdiff [SDiff α] [SDiff β] (a b : α × β) : (a \ b).2 = a.2 \ b.2 :=
rfl
#align snd_sdiff snd_sdiff
@[simp]
theorem fst_compl [HasCompl α] [HasCompl β] (a : α × β) : aᶜ.1 = a.1ᶜ :=
rfl
#align fst_compl fst_compl
@[simp]
theorem snd_compl [HasCompl α] [HasCompl β] (a : α × β) : aᶜ.2 = a.2ᶜ :=
rfl
#align snd_compl snd_compl
namespace Pi
variable {π : ι → Type*}
instance [∀ i, HImp (π i)] : HImp (∀ i, π i) :=
⟨fun a b i => a i ⇨ b i⟩
instance [∀ i, HNot (π i)] : HNot (∀ i, π i) :=
⟨fun a i => ¬a i⟩
theorem himp_def [∀ i, HImp (π i)] (a b : ∀ i, π i) : a ⇨ b = fun i => a i ⇨ b i :=
rfl
#align pi.himp_def Pi.himp_def
theorem hnot_def [∀ i, HNot (π i)] (a : ∀ i, π i) : ¬a = fun i => ¬a i :=
rfl
#align pi.hnot_def Pi.hnot_def
@[simp]
theorem himp_apply [∀ i, HImp (π i)] (a b : ∀ i, π i) (i : ι) : (a ⇨ b) i = a i ⇨ b i :=
rfl
#align pi.himp_apply Pi.himp_apply
@[simp]
theorem hnot_apply [∀ i, HNot (π i)] (a : ∀ i, π i) (i : ι) : (¬a) i = ¬a i :=
rfl
#align pi.hnot_apply Pi.hnot_apply
end Pi
/-- A generalized Heyting algebra is a lattice with an additional binary operation `⇨` called
Heyting implication such that `a ⇨` is right adjoint to `a ⊓`.
This generalizes `HeytingAlgebra` by not requiring a bottom element. -/
class GeneralizedHeytingAlgebra (α : Type*) extends Lattice α, OrderTop α, HImp α where
/-- `a ⇨` is right adjoint to `a ⊓` -/
le_himp_iff (a b c : α) : a ≤ b ⇨ c ↔ a ⊓ b ≤ c
#align generalized_heyting_algebra GeneralizedHeytingAlgebra
#align generalized_heyting_algebra.to_order_top GeneralizedHeytingAlgebra.toOrderTop
/-- A generalized co-Heyting algebra is a lattice with an additional binary
difference operation `\` such that `\ a` is right adjoint to `⊔ a`.
This generalizes `CoheytingAlgebra` by not requiring a top element. -/
class GeneralizedCoheytingAlgebra (α : Type*) extends Lattice α, OrderBot α, SDiff α where
/-- `\ a` is right adjoint to `⊔ a` -/
sdiff_le_iff (a b c : α) : a \ b ≤ c ↔ a ≤ b ⊔ c
#align generalized_coheyting_algebra GeneralizedCoheytingAlgebra
#align generalized_coheyting_algebra.to_order_bot GeneralizedCoheytingAlgebra.toOrderBot
/-- A Heyting algebra is a bounded lattice with an additional binary operation `⇨` called Heyting
implication such that `a ⇨` is right adjoint to `a ⊓`. -/
class HeytingAlgebra (α : Type*) extends GeneralizedHeytingAlgebra α, OrderBot α, HasCompl α where
/-- `a ⇨` is right adjoint to `a ⊓` -/
himp_bot (a : α) : a ⇨ ⊥ = aᶜ
#align heyting_algebra HeytingAlgebra
/-- A co-Heyting algebra is a bounded lattice with an additional binary difference operation `\`
such that `\ a` is right adjoint to `⊔ a`. -/
class CoheytingAlgebra (α : Type*) extends GeneralizedCoheytingAlgebra α, OrderTop α, HNot α where
/-- `⊤ \ a` is `¬a` -/
top_sdiff (a : α) : ⊤ \ a = ¬a
#align coheyting_algebra CoheytingAlgebra
/-- A bi-Heyting algebra is a Heyting algebra that is also a co-Heyting algebra. -/
class BiheytingAlgebra (α : Type*) extends HeytingAlgebra α, SDiff α, HNot α where
/-- `\ a` is right adjoint to `⊔ a` -/
sdiff_le_iff (a b c : α) : a \ b ≤ c ↔ a ≤ b ⊔ c
/-- `⊤ \ a` is `¬a` -/
top_sdiff (a : α) : ⊤ \ a = ¬a
#align biheyting_algebra BiheytingAlgebra
-- See note [lower instance priority]
attribute [instance 100] GeneralizedHeytingAlgebra.toOrderTop
attribute [instance 100] GeneralizedCoheytingAlgebra.toOrderBot
-- See note [lower instance priority]
instance (priority := 100) HeytingAlgebra.toBoundedOrder [HeytingAlgebra α] : BoundedOrder α :=
{ bot_le := ‹HeytingAlgebra α›.bot_le }
--#align heyting_algebra.to_bounded_order HeytingAlgebra.toBoundedOrder
-- See note [lower instance priority]
instance (priority := 100) CoheytingAlgebra.toBoundedOrder [CoheytingAlgebra α] : BoundedOrder α :=
{ ‹CoheytingAlgebra α› with }
#align coheyting_algebra.to_bounded_order CoheytingAlgebra.toBoundedOrder
-- See note [lower instance priority]
instance (priority := 100) BiheytingAlgebra.toCoheytingAlgebra [BiheytingAlgebra α] :
CoheytingAlgebra α :=
{ ‹BiheytingAlgebra α› with }
#align biheyting_algebra.to_coheyting_algebra BiheytingAlgebra.toCoheytingAlgebra
-- See note [reducible non-instances]
/-- Construct a Heyting algebra from the lattice structure and Heyting implication alone. -/
abbrev HeytingAlgebra.ofHImp [DistribLattice α] [BoundedOrder α] (himp : α → α → α)
(le_himp_iff : ∀ a b c, a ≤ himp b c ↔ a ⊓ b ≤ c) : HeytingAlgebra α :=
{ ‹DistribLattice α›, ‹BoundedOrder α› with
himp,
compl := fun a => himp a ⊥,
le_himp_iff,
himp_bot := fun a => rfl }
#align heyting_algebra.of_himp HeytingAlgebra.ofHImp
-- See note [reducible non-instances]
/-- Construct a Heyting algebra from the lattice structure and complement operator alone. -/
abbrev HeytingAlgebra.ofCompl [DistribLattice α] [BoundedOrder α] (compl : α → α)
(le_himp_iff : ∀ a b c, a ≤ compl b ⊔ c ↔ a ⊓ b ≤ c) : HeytingAlgebra α where
himp := (compl · ⊔ ·)
compl := compl
le_himp_iff := le_himp_iff
himp_bot _ := sup_bot_eq _
#align heyting_algebra.of_compl HeytingAlgebra.ofCompl
-- See note [reducible non-instances]
/-- Construct a co-Heyting algebra from the lattice structure and the difference alone. -/
abbrev CoheytingAlgebra.ofSDiff [DistribLattice α] [BoundedOrder α] (sdiff : α → α → α)
(sdiff_le_iff : ∀ a b c, sdiff a b ≤ c ↔ a ≤ b ⊔ c) : CoheytingAlgebra α :=
{ ‹DistribLattice α›, ‹BoundedOrder α› with
sdiff,
hnot := fun a => sdiff ⊤ a,
sdiff_le_iff,
top_sdiff := fun a => rfl }
#align coheyting_algebra.of_sdiff CoheytingAlgebra.ofSDiff
-- See note [reducible non-instances]
/-- Construct a co-Heyting algebra from the difference and Heyting negation alone. -/
abbrev CoheytingAlgebra.ofHNot [DistribLattice α] [BoundedOrder α] (hnot : α → α)
(sdiff_le_iff : ∀ a b c, a ⊓ hnot b ≤ c ↔ a ≤ b ⊔ c) : CoheytingAlgebra α where
sdiff a b := a ⊓ hnot b
hnot := hnot
sdiff_le_iff := sdiff_le_iff
top_sdiff _ := top_inf_eq _
#align coheyting_algebra.of_hnot CoheytingAlgebra.ofHNot
/-! In this section, we'll give interpretations of these results in the Heyting algebra model of
intuitionistic logic,- where `≤` can be interpreted as "validates", `⇨` as "implies", `⊓` as "and",
`⊔` as "or", `⊥` as "false" and `⊤` as "true". Note that we confuse `→` and `⊢` because those are
the same in this logic.
See also `Prop.heytingAlgebra`. -/
section GeneralizedHeytingAlgebra
variable [GeneralizedHeytingAlgebra α] {a b c d : α}
/-- `p → q → r ↔ p ∧ q → r` -/
@[simp]
theorem le_himp_iff : a ≤ b ⇨ c ↔ a ⊓ b ≤ c :=
GeneralizedHeytingAlgebra.le_himp_iff _ _ _
#align le_himp_iff le_himp_iff
/-- `p → q → r ↔ q ∧ p → r` -/
theorem le_himp_iff' : a ≤ b ⇨ c ↔ b ⊓ a ≤ c := by rw [le_himp_iff, inf_comm]
#align le_himp_iff' le_himp_iff'
/-- `p → q → r ↔ q → p → r` -/
theorem le_himp_comm : a ≤ b ⇨ c ↔ b ≤ a ⇨ c := by rw [le_himp_iff, le_himp_iff']
#align le_himp_comm le_himp_comm
/-- `p → q → p` -/
theorem le_himp : a ≤ b ⇨ a :=
le_himp_iff.2 inf_le_left
#align le_himp le_himp
/-- `p → p → q ↔ p → q` -/
theorem le_himp_iff_left : a ≤ a ⇨ b ↔ a ≤ b := by rw [le_himp_iff, inf_idem]
#align le_himp_iff_left le_himp_iff_left
/-- `p → p` -/
@[simp]
theorem himp_self : a ⇨ a = ⊤ :=
top_le_iff.1 <| le_himp_iff.2 inf_le_right
#align himp_self himp_self
/-- `(p → q) ∧ p → q` -/
theorem himp_inf_le : (a ⇨ b) ⊓ a ≤ b :=
le_himp_iff.1 le_rfl
#align himp_inf_le himp_inf_le
/-- `p ∧ (p → q) → q` -/
theorem inf_himp_le : a ⊓ (a ⇨ b) ≤ b := by rw [inf_comm, ← le_himp_iff]
#align inf_himp_le inf_himp_le
/-- `p ∧ (p → q) ↔ p ∧ q` -/
@[simp]
theorem inf_himp (a b : α) : a ⊓ (a ⇨ b) = a ⊓ b :=
le_antisymm (le_inf inf_le_left <| by rw [inf_comm, ← le_himp_iff]) <| inf_le_inf_left _ le_himp
#align inf_himp inf_himp
/-- `(p → q) ∧ p ↔ q ∧ p` -/
@[simp]
| Mathlib/Order/Heyting/Basic.lean | 300 | 300 | theorem himp_inf_self (a b : α) : (a ⇨ b) ⊓ a = b ⊓ a := by | rw [inf_comm, inf_himp, inf_comm]
|
/-
Copyright (c) 2020 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison, Johan Commelin
-/
import Mathlib.LinearAlgebra.FiniteDimensional
import Mathlib.LinearAlgebra.TensorProduct.Tower
import Mathlib.RingTheory.Adjoin.Basic
import Mathlib.LinearAlgebra.DirectSum.Finsupp
#align_import ring_theory.tensor_product from "leanprover-community/mathlib"@"88fcdc3da43943f5b01925deddaa5bf0c0e85e4e"
/-!
# The tensor product of R-algebras
This file provides results about the multiplicative structure on `A ⊗[R] B` when `R` is a
commutative (semi)ring and `A` and `B` are both `R`-algebras. On these tensor products,
multiplication is characterized by `(a₁ ⊗ₜ b₁) * (a₂ ⊗ₜ b₂) = (a₁ * a₂) ⊗ₜ (b₁ * b₂)`.
## Main declarations
- `LinearMap.baseChange A f` is the `A`-linear map `A ⊗ f`, for an `R`-linear map `f`.
- `Algebra.TensorProduct.semiring`: the ring structure on `A ⊗[R] B` for two `R`-algebras `A`, `B`.
- `Algebra.TensorProduct.leftAlgebra`: the `S`-algebra structure on `A ⊗[R] B`, for when `A` is
additionally an `S` algebra.
- the structure isomorphisms
* `Algebra.TensorProduct.lid : R ⊗[R] A ≃ₐ[R] A`
* `Algebra.TensorProduct.rid : A ⊗[R] R ≃ₐ[S] A` (usually used with `S = R` or `S = A`)
* `Algebra.TensorProduct.comm : A ⊗[R] B ≃ₐ[R] B ⊗[R] A`
* `Algebra.TensorProduct.assoc : ((A ⊗[R] B) ⊗[R] C) ≃ₐ[R] (A ⊗[R] (B ⊗[R] C))`
- `Algebra.TensorProduct.liftEquiv`: a universal property for the tensor product of algebras.
## References
* [C. Kassel, *Quantum Groups* (§II.4)][Kassel1995]
-/
suppress_compilation
open scoped TensorProduct
open TensorProduct
namespace LinearMap
open TensorProduct
/-!
### The base-change of a linear map of `R`-modules to a linear map of `A`-modules
-/
section Semiring
variable {R A B M N P : Type*} [CommSemiring R]
variable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]
variable [AddCommMonoid M] [AddCommMonoid N] [AddCommMonoid P]
variable [Module R M] [Module R N] [Module R P]
variable (r : R) (f g : M →ₗ[R] N)
variable (A)
/-- `baseChange A f` for `f : M →ₗ[R] N` is the `A`-linear map `A ⊗[R] M →ₗ[A] A ⊗[R] N`.
This "base change" operation is also known as "extension of scalars". -/
def baseChange (f : M →ₗ[R] N) : A ⊗[R] M →ₗ[A] A ⊗[R] N :=
AlgebraTensorModule.map (LinearMap.id : A →ₗ[A] A) f
#align linear_map.base_change LinearMap.baseChange
variable {A}
@[simp]
theorem baseChange_tmul (a : A) (x : M) : f.baseChange A (a ⊗ₜ x) = a ⊗ₜ f x :=
rfl
#align linear_map.base_change_tmul LinearMap.baseChange_tmul
theorem baseChange_eq_ltensor : (f.baseChange A : A ⊗ M → A ⊗ N) = f.lTensor A :=
rfl
#align linear_map.base_change_eq_ltensor LinearMap.baseChange_eq_ltensor
@[simp]
theorem baseChange_add : (f + g).baseChange A = f.baseChange A + g.baseChange A := by
ext
-- Porting note: added `-baseChange_tmul`
simp [baseChange_eq_ltensor, -baseChange_tmul]
#align linear_map.base_change_add LinearMap.baseChange_add
@[simp]
| Mathlib/RingTheory/TensorProduct/Basic.lean | 90 | 92 | theorem baseChange_zero : baseChange A (0 : M →ₗ[R] N) = 0 := by |
ext
simp [baseChange_eq_ltensor]
|
/-
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.Init.Core
import Mathlib.RingTheory.Polynomial.Cyclotomic.Roots
import Mathlib.NumberTheory.NumberField.Basic
import Mathlib.FieldTheory.Galois
#align_import number_theory.cyclotomic.basic from "leanprover-community/mathlib"@"4b05d3f4f0601dca8abf99c4ec99187682ed0bba"
/-!
# Cyclotomic extensions
Let `A` and `B` be commutative rings with `Algebra A B`. For `S : Set ℕ+`, we define a class
`IsCyclotomicExtension S A B` expressing the fact that `B` is obtained from `A` by adding `n`-th
primitive roots of unity, for all `n ∈ S`.
## Main definitions
* `IsCyclotomicExtension S A B` : means that `B` is obtained from `A` by adding `n`-th primitive
roots of unity, for all `n ∈ S`.
* `CyclotomicField`: given `n : ℕ+` and a field `K`, we define `CyclotomicField n K` as the
splitting field of `cyclotomic n K`. If `n` is nonzero in `K`, it has the instance
`IsCyclotomicExtension {n} K (CyclotomicField n K)`.
* `CyclotomicRing` : if `A` is a domain with fraction field `K` and `n : ℕ+`, we define
`CyclotomicRing n A K` as the `A`-subalgebra of `CyclotomicField n K` generated by the roots of
`X ^ n - 1`. If `n` is nonzero in `A`, it has the instance
`IsCyclotomicExtension {n} A (CyclotomicRing n A K)`.
## Main results
* `IsCyclotomicExtension.trans` : if `IsCyclotomicExtension S A B` and
`IsCyclotomicExtension T B C`, then `IsCyclotomicExtension (S ∪ T) A C` if
`Function.Injective (algebraMap B C)`.
* `IsCyclotomicExtension.union_right` : given `IsCyclotomicExtension (S ∪ T) A B`, then
`IsCyclotomicExtension T (adjoin A { b : B | ∃ a : ℕ+, a ∈ S ∧ b ^ (a : ℕ) = 1 }) B`.
* `IsCyclotomicExtension.union_left` : given `IsCyclotomicExtension T A B` and `S ⊆ T`, then
`IsCyclotomicExtension S A (adjoin A { b : B | ∃ a : ℕ+, a ∈ S ∧ b ^ (a : ℕ) = 1 })`.
* `IsCyclotomicExtension.finite` : if `S` is finite and `IsCyclotomicExtension S A B`, then
`B` is a finite `A`-algebra.
* `IsCyclotomicExtension.numberField` : a finite cyclotomic extension of a number field is a
number field.
* `IsCyclotomicExtension.isSplittingField_X_pow_sub_one` : if `IsCyclotomicExtension {n} K L`,
then `L` is the splitting field of `X ^ n - 1`.
* `IsCyclotomicExtension.splitting_field_cyclotomic` : if `IsCyclotomicExtension {n} K L`,
then `L` is the splitting field of `cyclotomic n K`.
## Implementation details
Our definition of `IsCyclotomicExtension` is very general, to allow rings of any characteristic
and infinite extensions, but it will mainly be used in the case `S = {n}` and for integral domains.
All results are in the `IsCyclotomicExtension` namespace.
Note that some results, for example `IsCyclotomicExtension.trans`,
`IsCyclotomicExtension.finite`, `IsCyclotomicExtension.numberField`,
`IsCyclotomicExtension.finiteDimensional`, `IsCyclotomicExtension.isGalois` and
`CyclotomicField.algebraBase` are lemmas, but they can be made local instances. Some of them are
included in the `Cyclotomic` locale.
-/
open Polynomial Algebra FiniteDimensional Set
universe u v w z
variable (n : ℕ+) (S T : Set ℕ+) (A : Type u) (B : Type v) (K : Type w) (L : Type z)
variable [CommRing A] [CommRing B] [Algebra A B]
variable [Field K] [Field L] [Algebra K L]
noncomputable section
/-- Given an `A`-algebra `B` and `S : Set ℕ+`, we define `IsCyclotomicExtension S A B` requiring
that there is an `n`-th primitive root of unity in `B` for all `n ∈ S` and that `B` is generated
over `A` by the roots of `X ^ n - 1`. -/
@[mk_iff]
class IsCyclotomicExtension : Prop where
/-- For all `n ∈ S`, there exists a primitive `n`-th root of unity in `B`. -/
exists_prim_root {n : ℕ+} (ha : n ∈ S) : ∃ r : B, IsPrimitiveRoot r n
/-- The `n`-th roots of unity, for `n ∈ S`, generate `B` as an `A`-algebra. -/
adjoin_roots : ∀ x : B, x ∈ adjoin A {b : B | ∃ n : ℕ+, n ∈ S ∧ b ^ (n : ℕ) = 1}
#align is_cyclotomic_extension IsCyclotomicExtension
namespace IsCyclotomicExtension
section Basic
/-- A reformulation of `IsCyclotomicExtension` that uses `⊤`. -/
theorem iff_adjoin_eq_top :
IsCyclotomicExtension S A B ↔
(∀ n : ℕ+, n ∈ S → ∃ r : B, IsPrimitiveRoot r n) ∧
adjoin A {b : B | ∃ n : ℕ+, n ∈ S ∧ b ^ (n : ℕ) = 1} = ⊤ :=
⟨fun h => ⟨fun _ => h.exists_prim_root, Algebra.eq_top_iff.2 h.adjoin_roots⟩, fun h =>
⟨h.1 _, Algebra.eq_top_iff.1 h.2⟩⟩
#align is_cyclotomic_extension.iff_adjoin_eq_top IsCyclotomicExtension.iff_adjoin_eq_top
/-- A reformulation of `IsCyclotomicExtension` in the case `S` is a singleton. -/
theorem iff_singleton :
IsCyclotomicExtension {n} A B ↔
(∃ r : B, IsPrimitiveRoot r n) ∧ ∀ x, x ∈ adjoin A {b : B | b ^ (n : ℕ) = 1} := by
simp [isCyclotomicExtension_iff]
#align is_cyclotomic_extension.iff_singleton IsCyclotomicExtension.iff_singleton
/-- If `IsCyclotomicExtension ∅ A B`, then the image of `A` in `B` equals `B`. -/
theorem empty [h : IsCyclotomicExtension ∅ A B] : (⊥ : Subalgebra A B) = ⊤ := by
simpa [Algebra.eq_top_iff, isCyclotomicExtension_iff] using h
#align is_cyclotomic_extension.empty IsCyclotomicExtension.empty
/-- If `IsCyclotomicExtension {1} A B`, then the image of `A` in `B` equals `B`. -/
theorem singleton_one [h : IsCyclotomicExtension {1} A B] : (⊥ : Subalgebra A B) = ⊤ :=
Algebra.eq_top_iff.2 fun x => by
simpa [adjoin_singleton_one] using ((isCyclotomicExtension_iff _ _ _).1 h).2 x
#align is_cyclotomic_extension.singleton_one IsCyclotomicExtension.singleton_one
variable {A B}
/-- If `(⊥ : SubAlgebra A B) = ⊤`, then `IsCyclotomicExtension ∅ A B`. -/
theorem singleton_zero_of_bot_eq_top (h : (⊥ : Subalgebra A B) = ⊤) :
IsCyclotomicExtension ∅ A B := by
-- Porting note: Lean3 is able to infer `A`.
refine (iff_adjoin_eq_top _ A _).2
⟨fun s hs => by simp at hs, _root_.eq_top_iff.2 fun x hx => ?_⟩
rw [← h] at hx
simpa using hx
#align is_cyclotomic_extension.singleton_zero_of_bot_eq_top IsCyclotomicExtension.singleton_zero_of_bot_eq_top
variable (A B)
/-- Transitivity of cyclotomic extensions. -/
theorem trans (C : Type w) [CommRing C] [Algebra A C] [Algebra B C] [IsScalarTower A B C]
[hS : IsCyclotomicExtension S A B] [hT : IsCyclotomicExtension T B C]
(h : Function.Injective (algebraMap B C)) : IsCyclotomicExtension (S ∪ T) A C := by
refine ⟨fun hn => ?_, fun x => ?_⟩
· cases' hn with hn hn
· obtain ⟨b, hb⟩ := ((isCyclotomicExtension_iff _ _ _).1 hS).1 hn
refine ⟨algebraMap B C b, ?_⟩
exact hb.map_of_injective h
· exact ((isCyclotomicExtension_iff _ _ _).1 hT).1 hn
· refine adjoin_induction (((isCyclotomicExtension_iff T B _).1 hT).2 x)
(fun c ⟨n, hn⟩ => subset_adjoin ⟨n, Or.inr hn.1, hn.2⟩) (fun b => ?_)
(fun x y hx hy => Subalgebra.add_mem _ hx hy) fun x y hx hy => Subalgebra.mul_mem _ hx hy
let f := IsScalarTower.toAlgHom A B C
have hb : f b ∈ (adjoin A {b : B | ∃ a : ℕ+, a ∈ S ∧ b ^ (a : ℕ) = 1}).map f :=
⟨b, ((isCyclotomicExtension_iff _ _ _).1 hS).2 b, rfl⟩
rw [IsScalarTower.toAlgHom_apply, ← adjoin_image] at hb
refine adjoin_mono (fun y hy => ?_) hb
obtain ⟨b₁, ⟨⟨n, hn⟩, h₁⟩⟩ := hy
exact ⟨n, ⟨mem_union_left T hn.1, by rw [← h₁, ← AlgHom.map_pow, hn.2, AlgHom.map_one]⟩⟩
#align is_cyclotomic_extension.trans IsCyclotomicExtension.trans
@[nontriviality]
theorem subsingleton_iff [Subsingleton B] : IsCyclotomicExtension S A B ↔ S = { } ∨ S = {1} := by
have : Subsingleton (Subalgebra A B) := inferInstance
constructor
· rintro ⟨hprim, -⟩
rw [← subset_singleton_iff_eq]
intro t ht
obtain ⟨ζ, hζ⟩ := hprim ht
rw [mem_singleton_iff, ← PNat.coe_eq_one_iff]
exact mod_cast hζ.unique (IsPrimitiveRoot.of_subsingleton ζ)
· rintro (rfl | rfl)
-- Porting note: `R := A` was not needed.
· exact ⟨fun h => h.elim, fun x => by convert (mem_top (R := A) : x ∈ ⊤)⟩
· rw [iff_singleton]
exact ⟨⟨0, IsPrimitiveRoot.of_subsingleton 0⟩,
fun x => by convert (mem_top (R := A) : x ∈ ⊤)⟩
#align is_cyclotomic_extension.subsingleton_iff IsCyclotomicExtension.subsingleton_iff
/-- If `B` is a cyclotomic extension of `A` given by roots of unity of order in `S ∪ T`, then `B`
is a cyclotomic extension of `adjoin A { b : B | ∃ a : ℕ+, a ∈ S ∧ b ^ (a : ℕ) = 1 }` given by
roots of unity of order in `T`. -/
theorem union_right [h : IsCyclotomicExtension (S ∪ T) A B] :
IsCyclotomicExtension T (adjoin A {b : B | ∃ a : ℕ+, a ∈ S ∧ b ^ (a : ℕ) = 1}) B := by
have : {b : B | ∃ n : ℕ+, n ∈ S ∪ T ∧ b ^ (n : ℕ) = 1} =
{b : B | ∃ n : ℕ+, n ∈ S ∧ b ^ (n : ℕ) = 1} ∪
{b : B | ∃ n : ℕ+, n ∈ T ∧ b ^ (n : ℕ) = 1} := by
refine le_antisymm ?_ ?_
· rintro x ⟨n, hn₁ | hn₂, hnpow⟩
· left; exact ⟨n, hn₁, hnpow⟩
· right; exact ⟨n, hn₂, hnpow⟩
· rintro x (⟨n, hn⟩ | ⟨n, hn⟩)
· exact ⟨n, Or.inl hn.1, hn.2⟩
· exact ⟨n, Or.inr hn.1, hn.2⟩
refine ⟨fun hn => ((isCyclotomicExtension_iff _ A _).1 h).1 (mem_union_right S hn), fun b => ?_⟩
replace h := ((isCyclotomicExtension_iff _ _ _).1 h).2 b
rwa [this, adjoin_union_eq_adjoin_adjoin, Subalgebra.mem_restrictScalars] at h
#align is_cyclotomic_extension.union_right IsCyclotomicExtension.union_right
/-- If `B` is a cyclotomic extension of `A` given by roots of unity of order in `T` and `S ⊆ T`,
then `adjoin A { b : B | ∃ a : ℕ+, a ∈ S ∧ b ^ (a : ℕ) = 1 }` is a cyclotomic extension of `B`
given by roots of unity of order in `S`. -/
theorem union_left [h : IsCyclotomicExtension T A B] (hS : S ⊆ T) :
IsCyclotomicExtension S A (adjoin A {b : B | ∃ a : ℕ+, a ∈ S ∧ b ^ (a : ℕ) = 1}) := by
refine ⟨@fun n hn => ?_, fun b => ?_⟩
· obtain ⟨b, hb⟩ := ((isCyclotomicExtension_iff _ _ _).1 h).1 (hS hn)
refine ⟨⟨b, subset_adjoin ⟨n, hn, hb.pow_eq_one⟩⟩, ?_⟩
rwa [← IsPrimitiveRoot.coe_submonoidClass_iff, Subtype.coe_mk]
· convert mem_top (R := A) (x := b)
rw [← adjoin_adjoin_coe_preimage, preimage_setOf_eq]
norm_cast
#align is_cyclotomic_extension.union_left IsCyclotomicExtension.union_left
variable {n S}
/-- If `∀ s ∈ S, n ∣ s` and `S` is not empty, then `IsCyclotomicExtension S A B` implies
`IsCyclotomicExtension (S ∪ {n}) A B`. -/
theorem of_union_of_dvd (h : ∀ s ∈ S, n ∣ s) (hS : S.Nonempty) [H : IsCyclotomicExtension S A B] :
IsCyclotomicExtension (S ∪ {n}) A B := by
refine (iff_adjoin_eq_top _ A _).2 ⟨fun s hs => ?_, ?_⟩
· rw [mem_union, mem_singleton_iff] at hs
obtain hs | rfl := hs
· exact H.exists_prim_root hs
· obtain ⟨m, hm⟩ := hS
obtain ⟨x, rfl⟩ := h m hm
obtain ⟨ζ, hζ⟩ := H.exists_prim_root hm
refine ⟨ζ ^ (x : ℕ), ?_⟩
convert hζ.pow_of_dvd x.ne_zero (dvd_mul_left (x : ℕ) s)
simp only [PNat.mul_coe, Nat.mul_div_left, PNat.pos]
· refine _root_.eq_top_iff.2 ?_
rw [← ((iff_adjoin_eq_top S A B).1 H).2]
refine adjoin_mono fun x hx => ?_
simp only [union_singleton, mem_insert_iff, mem_setOf_eq] at hx ⊢
obtain ⟨m, hm⟩ := hx
exact ⟨m, ⟨Or.inr hm.1, hm.2⟩⟩
#align is_cyclotomic_extension.of_union_of_dvd IsCyclotomicExtension.of_union_of_dvd
/-- If `∀ s ∈ S, n ∣ s` and `S` is not empty, then `IsCyclotomicExtension S A B` if and only if
`IsCyclotomicExtension (S ∪ {n}) A B`. -/
theorem iff_union_of_dvd (h : ∀ s ∈ S, n ∣ s) (hS : S.Nonempty) :
IsCyclotomicExtension S A B ↔ IsCyclotomicExtension (S ∪ {n}) A B := by
refine
⟨fun H => of_union_of_dvd A B h hS, fun H => (iff_adjoin_eq_top _ A _).2 ⟨fun s hs => ?_, ?_⟩⟩
· exact H.exists_prim_root (subset_union_left hs)
· rw [_root_.eq_top_iff, ← ((iff_adjoin_eq_top _ A B).1 H).2]
refine adjoin_mono fun x hx => ?_
simp only [union_singleton, mem_insert_iff, mem_setOf_eq] at hx ⊢
obtain ⟨m, rfl | hm, hxpow⟩ := hx
· obtain ⟨y, hy⟩ := hS
refine ⟨y, ⟨hy, ?_⟩⟩
obtain ⟨z, rfl⟩ := h y hy
simp only [PNat.mul_coe, pow_mul, hxpow, one_pow]
· exact ⟨m, ⟨hm, hxpow⟩⟩
#align is_cyclotomic_extension.iff_union_of_dvd IsCyclotomicExtension.iff_union_of_dvd
variable (n S)
/-- `IsCyclotomicExtension S A B` is equivalent to `IsCyclotomicExtension (S ∪ {1}) A B`. -/
theorem iff_union_singleton_one :
IsCyclotomicExtension S A B ↔ IsCyclotomicExtension (S ∪ {1}) A B := by
obtain hS | rfl := S.eq_empty_or_nonempty.symm
· exact iff_union_of_dvd _ _ (fun s _ => one_dvd _) hS
rw [empty_union]
refine ⟨fun H => ?_, fun H => ?_⟩
· refine (iff_adjoin_eq_top _ A _).2 ⟨fun s hs => ⟨1, by simp [mem_singleton_iff.1 hs]⟩, ?_⟩
simp [adjoin_singleton_one, empty]
· refine (iff_adjoin_eq_top _ A _).2 ⟨fun s hs => (not_mem_empty s hs).elim, ?_⟩
simp [@singleton_one A B _ _ _ H]
#align is_cyclotomic_extension.iff_union_singleton_one IsCyclotomicExtension.iff_union_singleton_one
variable {A B}
/-- If `(⊥ : SubAlgebra A B) = ⊤`, then `IsCyclotomicExtension {1} A B`. -/
theorem singleton_one_of_bot_eq_top (h : (⊥ : Subalgebra A B) = ⊤) :
IsCyclotomicExtension {1} A B := by
convert (iff_union_singleton_one _ A _).1 (singleton_zero_of_bot_eq_top h)
simp
#align is_cyclotomic_extension.singleton_one_of_bot_eq_top IsCyclotomicExtension.singleton_one_of_bot_eq_top
/-- If `Function.Surjective (algebraMap A B)`, then `IsCyclotomicExtension {1} A B`. -/
theorem singleton_one_of_algebraMap_bijective (h : Function.Surjective (algebraMap A B)) :
IsCyclotomicExtension {1} A B :=
singleton_one_of_bot_eq_top (surjective_algebraMap_iff.1 h).symm
#align is_cyclotomic_extension.singleton_one_of_algebra_map_bijective IsCyclotomicExtension.singleton_one_of_algebraMap_bijective
variable (A B)
/-- Given `(f : B ≃ₐ[A] C)`, if `IsCyclotomicExtension S A B` then
`IsCyclotomicExtension S A C`. -/
protected
| Mathlib/NumberTheory/Cyclotomic/Basic.lean | 282 | 287 | theorem equiv {C : Type*} [CommRing C] [Algebra A C] [h : IsCyclotomicExtension S A B]
(f : B ≃ₐ[A] C) : IsCyclotomicExtension S A C := by |
letI : Algebra B C := f.toAlgHom.toRingHom.toAlgebra
haveI : IsCyclotomicExtension {1} B C := singleton_one_of_algebraMap_bijective f.surjective
haveI : IsScalarTower A B C := IsScalarTower.of_algHom f.toAlgHom
exact (iff_union_singleton_one _ _ _).2 (trans S {1} A B C f.injective)
|
/-
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.Topology.Algebra.InfiniteSum.Group
import Mathlib.Logic.Encodable.Lattice
/-!
# Infinite sums and products over `ℕ` and `ℤ`
This file contains lemmas about `HasSum`, `Summable`, `tsum`, `HasProd`, `Multipliable`, and `tprod`
applied to the important special cases where the domain is `ℕ` or `ℤ`. For instance, we prove the
formula `∑ i ∈ range k, f i + ∑' i, f (i + k) = ∑' i, f i`, ∈ `sum_add_tsum_nat_add`, as well as
several results relating sums and products on `ℕ` to sums and products on `ℤ`.
-/
noncomputable section
open Filter Finset Function Encodable
open scoped Topology
variable {M : Type*} [CommMonoid M] [TopologicalSpace M] {m m' : M}
variable {G : Type*} [CommGroup G] {g g' : G}
-- don't declare [TopologicalAddGroup G] here as some results require [UniformAddGroup G] instead
/-!
## Sums over `ℕ`
-/
section Nat
section Monoid
namespace HasProd
/-- If `f : ℕ → M` has product `m`, then the partial products `∏ i ∈ range n, f i` converge
to `m`. -/
@[to_additive "If `f : ℕ → M` has sum `m`, then the partial sums `∑ i ∈ range n, f i` converge
to `m`."]
theorem tendsto_prod_nat {f : ℕ → M} (h : HasProd f m) :
Tendsto (fun n ↦ ∏ i ∈ range n, f i) atTop (𝓝 m) :=
h.comp tendsto_finset_range
#align has_sum.tendsto_sum_nat HasSum.tendsto_sum_nat
/-- If `f : ℕ → M` is multipliable, then the partial products `∏ i ∈ range n, f i` converge
to `∏' i, f i`. -/
@[to_additive "If `f : ℕ → M` is summable, then the partial sums `∑ i ∈ range n, f i` converge
to `∑' i, f i`."]
theorem Multipliable.tendsto_prod_tprod_nat {f : ℕ → M} (h : Multipliable f) :
Tendsto (fun n ↦ ∏ i ∈ range n, f i) atTop (𝓝 (∏' i, f i)) :=
tendsto_prod_nat h.hasProd
section ContinuousMul
variable [ContinuousMul M]
@[to_additive]
theorem prod_range_mul {f : ℕ → M} {k : ℕ} (h : HasProd (fun n ↦ f (n + k)) m) :
HasProd f ((∏ i ∈ range k, f i) * m) := by
refine ((range k).hasProd f).mul_compl ?_
rwa [← (notMemRangeEquiv k).symm.hasProd_iff]
@[to_additive]
theorem zero_mul {f : ℕ → M} (h : HasProd (fun n ↦ f (n + 1)) m) :
HasProd f (f 0 * m) := by
simpa only [prod_range_one] using h.prod_range_mul
@[to_additive]
theorem even_mul_odd {f : ℕ → M} (he : HasProd (fun k ↦ f (2 * k)) m)
(ho : HasProd (fun k ↦ f (2 * k + 1)) m') : HasProd f (m * m') := by
have := mul_right_injective₀ (two_ne_zero' ℕ)
replace ho := ((add_left_injective 1).comp this).hasProd_range_iff.2 ho
refine (this.hasProd_range_iff.2 he).mul_isCompl ?_ ho
simpa [(· ∘ ·)] using Nat.isCompl_even_odd
#align has_sum.even_add_odd HasSum.even_add_odd
end ContinuousMul
end HasProd
namespace Multipliable
@[to_additive]
theorem hasProd_iff_tendsto_nat [T2Space M] {f : ℕ → M} (hf : Multipliable f) :
HasProd f m ↔ Tendsto (fun n : ℕ ↦ ∏ i ∈ range n, f i) atTop (𝓝 m) := by
refine ⟨fun h ↦ h.tendsto_prod_nat, fun h ↦ ?_⟩
rw [tendsto_nhds_unique h hf.hasProd.tendsto_prod_nat]
exact hf.hasProd
#align summable.has_sum_iff_tendsto_nat Summable.hasSum_iff_tendsto_nat
section ContinuousMul
variable [ContinuousMul M]
@[to_additive]
theorem comp_nat_add {f : ℕ → M} {k : ℕ} (h : Multipliable fun n ↦ f (n + k)) : Multipliable f :=
h.hasProd.prod_range_mul.multipliable
@[to_additive]
theorem even_mul_odd {f : ℕ → M} (he : Multipliable fun k ↦ f (2 * k))
(ho : Multipliable fun k ↦ f (2 * k + 1)) : Multipliable f :=
(he.hasProd.even_mul_odd ho.hasProd).multipliable
end ContinuousMul
end Multipliable
section tprod
variable [T2Space M] {α β γ : Type*}
section Encodable
variable [Encodable β]
/-- You can compute a product over an encodable type by multiplying over the natural numbers and
taking a supremum. -/
@[to_additive "You can compute a sum over an encodable type by summing over the natural numbers and
taking a supremum. This is useful for outer measures."]
| Mathlib/Topology/Algebra/InfiniteSum/NatInt.lean | 124 | 132 | theorem tprod_iSup_decode₂ [CompleteLattice α] (m : α → M) (m0 : m ⊥ = 1) (s : β → α) :
∏' i : ℕ, m (⨆ b ∈ decode₂ β i, s b) = ∏' b : β, m (s b) := by |
rw [← tprod_extend_one (@encode_injective β _)]
refine tprod_congr fun n ↦ ?_
rcases em (n ∈ Set.range (encode : β → ℕ)) with ⟨a, rfl⟩ | hn
· simp [encode_injective.extend_apply]
· rw [extend_apply' _ _ _ hn]
rw [← decode₂_ne_none_iff, ne_eq, not_not] at hn
simp [hn, m0]
|
/-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Morenikeji Neri
-/
import Mathlib.Algebra.EuclideanDomain.Instances
import Mathlib.RingTheory.Ideal.Colon
import Mathlib.RingTheory.UniqueFactorizationDomain
#align_import ring_theory.principal_ideal_domain from "leanprover-community/mathlib"@"6010cf523816335f7bae7f8584cb2edaace73940"
/-!
# Principal ideal rings, principal ideal domains, and Bézout rings
A principal ideal ring (PIR) is a ring in which all left ideals are principal. A
principal ideal domain (PID) is an integral domain which is a principal ideal ring.
# Main definitions
Note that for principal ideal domains, one should use
`[IsDomain R] [IsPrincipalIdealRing R]`. There is no explicit definition of a PID.
Theorems about PID's are in the `principal_ideal_ring` namespace.
- `IsPrincipalIdealRing`: a predicate on rings, saying that every left ideal is principal.
- `IsBezout`: the predicate saying that every finitely generated left ideal is principal.
- `generator`: a generator of a principal ideal (or more generally submodule)
- `to_unique_factorization_monoid`: a PID is a unique factorization domain
# Main results
- `to_maximal_ideal`: a non-zero prime ideal in a PID is maximal.
- `EuclideanDomain.to_principal_ideal_domain` : a Euclidean domain is a PID.
- `IsBezout.nonemptyGCDMonoid`: Every Bézout domain is a GCD domain.
-/
universe u v
variable {R : Type u} {M : Type v}
open Set Function
open Submodule
section
variable [Ring R] [AddCommGroup M] [Module R M]
instance bot_isPrincipal : (⊥ : Submodule R M).IsPrincipal :=
⟨⟨0, by simp⟩⟩
#align bot_is_principal bot_isPrincipal
instance top_isPrincipal : (⊤ : Submodule R R).IsPrincipal :=
⟨⟨1, Ideal.span_singleton_one.symm⟩⟩
#align top_is_principal top_isPrincipal
variable (R)
/-- A Bézout ring is a ring whose finitely generated ideals are principal. -/
class IsBezout : Prop where
/-- Any finitely generated ideal is principal. -/
isPrincipal_of_FG : ∀ I : Ideal R, I.FG → I.IsPrincipal
#align is_bezout IsBezout
instance (priority := 100) IsBezout.of_isPrincipalIdealRing [IsPrincipalIdealRing R] : IsBezout R :=
⟨fun I _ => IsPrincipalIdealRing.principal I⟩
#align is_bezout.of_is_principal_ideal_ring IsBezout.of_isPrincipalIdealRing
instance (priority := 100) DivisionRing.isPrincipalIdealRing (K : Type u) [DivisionRing K] :
IsPrincipalIdealRing K where
principal S := by
rcases Ideal.eq_bot_or_top S with (rfl | rfl)
· apply bot_isPrincipal
· apply top_isPrincipal
#align division_ring.is_principal_ideal_ring DivisionRing.isPrincipalIdealRing
end
namespace Submodule.IsPrincipal
variable [AddCommGroup M]
section Ring
variable [Ring R] [Module R M]
/-- `generator I`, if `I` is a principal submodule, is an `x ∈ M` such that `span R {x} = I` -/
noncomputable def generator (S : Submodule R M) [S.IsPrincipal] : M :=
Classical.choose (principal S)
#align submodule.is_principal.generator Submodule.IsPrincipal.generator
theorem span_singleton_generator (S : Submodule R M) [S.IsPrincipal] : span R {generator S} = S :=
Eq.symm (Classical.choose_spec (principal S))
#align submodule.is_principal.span_singleton_generator Submodule.IsPrincipal.span_singleton_generator
@[simp]
theorem _root_.Ideal.span_singleton_generator (I : Ideal R) [I.IsPrincipal] :
Ideal.span ({generator I} : Set R) = I :=
Eq.symm (Classical.choose_spec (principal I))
#align ideal.span_singleton_generator Ideal.span_singleton_generator
@[simp]
theorem generator_mem (S : Submodule R M) [S.IsPrincipal] : generator S ∈ S := by
conv_rhs => rw [← span_singleton_generator S]
exact subset_span (mem_singleton _)
#align submodule.is_principal.generator_mem Submodule.IsPrincipal.generator_mem
theorem mem_iff_eq_smul_generator (S : Submodule R M) [S.IsPrincipal] {x : M} :
x ∈ S ↔ ∃ s : R, x = s • generator S := by
simp_rw [@eq_comm _ x, ← mem_span_singleton, span_singleton_generator]
#align submodule.is_principal.mem_iff_eq_smul_generator Submodule.IsPrincipal.mem_iff_eq_smul_generator
theorem eq_bot_iff_generator_eq_zero (S : Submodule R M) [S.IsPrincipal] :
S = ⊥ ↔ generator S = 0 := by rw [← @span_singleton_eq_bot R M, span_singleton_generator]
#align submodule.is_principal.eq_bot_iff_generator_eq_zero Submodule.IsPrincipal.eq_bot_iff_generator_eq_zero
end Ring
section CommRing
variable [CommRing R] [Module R M]
theorem associated_generator_span_self [IsPrincipalIdealRing R] [IsDomain R] (r : R) :
Associated (generator <| Ideal.span {r}) r := by
rw [← Ideal.span_singleton_eq_span_singleton]
exact Ideal.span_singleton_generator _
theorem mem_iff_generator_dvd (S : Ideal R) [S.IsPrincipal] {x : R} : x ∈ S ↔ generator S ∣ x :=
(mem_iff_eq_smul_generator S).trans (exists_congr fun a => by simp only [mul_comm, smul_eq_mul])
#align submodule.is_principal.mem_iff_generator_dvd Submodule.IsPrincipal.mem_iff_generator_dvd
theorem prime_generator_of_isPrime (S : Ideal R) [S.IsPrincipal] [is_prime : S.IsPrime]
(ne_bot : S ≠ ⊥) : Prime (generator S) :=
⟨fun h => ne_bot ((eq_bot_iff_generator_eq_zero S).2 h), fun h =>
is_prime.ne_top (S.eq_top_of_isUnit_mem (generator_mem S) h), fun _ _ => by
simpa only [← mem_iff_generator_dvd S] using is_prime.2⟩
#align submodule.is_principal.prime_generator_of_is_prime Submodule.IsPrincipal.prime_generator_of_isPrime
-- Note that the converse may not hold if `ϕ` is not injective.
theorem generator_map_dvd_of_mem {N : Submodule R M} (ϕ : M →ₗ[R] R) [(N.map ϕ).IsPrincipal] {x : M}
(hx : x ∈ N) : generator (N.map ϕ) ∣ ϕ x := by
rw [← mem_iff_generator_dvd, Submodule.mem_map]
exact ⟨x, hx, rfl⟩
#align submodule.is_principal.generator_map_dvd_of_mem Submodule.IsPrincipal.generator_map_dvd_of_mem
-- Note that the converse may not hold if `ϕ` is not injective.
theorem generator_submoduleImage_dvd_of_mem {N O : Submodule R M} (hNO : N ≤ O) (ϕ : O →ₗ[R] R)
[(ϕ.submoduleImage N).IsPrincipal] {x : M} (hx : x ∈ N) :
generator (ϕ.submoduleImage N) ∣ ϕ ⟨x, hNO hx⟩ := by
rw [← mem_iff_generator_dvd, LinearMap.mem_submoduleImage_of_le hNO]
exact ⟨x, hx, rfl⟩
#align submodule.is_principal.generator_submodule_image_dvd_of_mem Submodule.IsPrincipal.generator_submoduleImage_dvd_of_mem
end CommRing
end Submodule.IsPrincipal
namespace IsBezout
section
variable [Ring R]
instance span_pair_isPrincipal [IsBezout R] (x y : R) : (Ideal.span {x, y}).IsPrincipal := by
classical exact isPrincipal_of_FG (Ideal.span {x, y}) ⟨{x, y}, by simp⟩
#align is_bezout.span_pair_is_principal IsBezout.span_pair_isPrincipal
variable (x y : R) [(Ideal.span {x, y}).IsPrincipal]
/-- A choice of gcd of two elements in a Bézout domain.
Note that the choice is usually not unique. -/
noncomputable def gcd : R := Submodule.IsPrincipal.generator (Ideal.span {x, y})
#align is_bezout.gcd IsBezout.gcd
theorem span_gcd : Ideal.span {gcd x y} = Ideal.span {x, y} :=
Ideal.span_singleton_generator _
#align is_bezout.span_gcd IsBezout.span_gcd
end
variable [CommRing R] (x y z : R) [(Ideal.span {x, y}).IsPrincipal]
theorem gcd_dvd_left : gcd x y ∣ x :=
(Submodule.IsPrincipal.mem_iff_generator_dvd _).mp (Ideal.subset_span (by simp))
#align is_bezout.gcd_dvd_left IsBezout.gcd_dvd_left
theorem gcd_dvd_right : gcd x y ∣ y :=
(Submodule.IsPrincipal.mem_iff_generator_dvd _).mp (Ideal.subset_span (by simp))
#align is_bezout.gcd_dvd_right IsBezout.gcd_dvd_right
variable {x y z} in
theorem dvd_gcd (hx : z ∣ x) (hy : z ∣ y) : z ∣ gcd x y := by
rw [← Ideal.span_singleton_le_span_singleton] at hx hy ⊢
rw [span_gcd, Ideal.span_insert, sup_le_iff]
exact ⟨hx, hy⟩
#align is_bezout.dvd_gcd IsBezout.dvd_gcd
theorem gcd_eq_sum : ∃ a b : R, a * x + b * y = gcd x y :=
Ideal.mem_span_pair.mp (by rw [← span_gcd]; apply Ideal.subset_span; simp)
#align is_bezout.gcd_eq_sum IsBezout.gcd_eq_sum
variable {x y}
theorem _root_.IsRelPrime.isCoprime (h : IsRelPrime x y) : IsCoprime x y := by
rw [← Ideal.isCoprime_span_singleton_iff, Ideal.isCoprime_iff_sup_eq, ← Ideal.span_union,
Set.singleton_union, ← span_gcd, Ideal.span_singleton_eq_top]
exact h (gcd_dvd_left x y) (gcd_dvd_right x y)
theorem _root_.isRelPrime_iff_isCoprime : IsRelPrime x y ↔ IsCoprime x y :=
⟨IsRelPrime.isCoprime, IsCoprime.isRelPrime⟩
variable (R)
/-- Any Bézout domain is a GCD domain. This is not an instance since `GCDMonoid` contains data,
and this might not be how we would like to construct it. -/
noncomputable def toGCDDomain [IsBezout R] [IsDomain R] [DecidableEq R] : GCDMonoid R :=
gcdMonoidOfGCD (gcd · ·) (gcd_dvd_left · ·) (gcd_dvd_right · ·) dvd_gcd
#align is_bezout.to_gcd_domain IsBezout.toGCDDomain
instance nonemptyGCDMonoid [IsBezout R] [IsDomain R] : Nonempty (GCDMonoid R) := by
classical exact ⟨toGCDDomain R⟩
theorem associated_gcd_gcd [IsDomain R] [GCDMonoid R] :
Associated (IsBezout.gcd x y) (GCDMonoid.gcd x y) :=
gcd_greatest_associated (gcd_dvd_left _ _ ) (gcd_dvd_right _ _) (fun _ => dvd_gcd)
end IsBezout
namespace IsPrime
open Submodule.IsPrincipal Ideal
-- TODO -- for a non-ID one could perhaps prove that if p < q are prime then q maximal;
-- 0 isn't prime in a non-ID PIR but the Krull dimension is still <= 1.
-- The below result follows from this, but we could also use the below result to
-- prove this (quotient out by p).
theorem to_maximal_ideal [CommRing R] [IsDomain R] [IsPrincipalIdealRing R] {S : Ideal R}
[hpi : IsPrime S] (hS : S ≠ ⊥) : IsMaximal S :=
isMaximal_iff.2
⟨(ne_top_iff_one S).1 hpi.1, by
intro T x hST hxS hxT
cases' (mem_iff_generator_dvd _).1 (hST <| generator_mem S) with z hz
cases hpi.mem_or_mem (show generator T * z ∈ S from hz ▸ generator_mem S) with
| inl h =>
have hTS : T ≤ S := by
rwa [← T.span_singleton_generator, Ideal.span_le, singleton_subset_iff]
exact (hxS <| hTS hxT).elim
| inr h =>
cases' (mem_iff_generator_dvd _).1 h with y hy
have : generator S ≠ 0 := mt (eq_bot_iff_generator_eq_zero _).2 hS
rw [← mul_one (generator S), hy, mul_left_comm, mul_right_inj' this] at hz
exact hz.symm ▸ T.mul_mem_right _ (generator_mem T)⟩
#align is_prime.to_maximal_ideal IsPrime.to_maximal_ideal
end IsPrime
section
open EuclideanDomain
variable [EuclideanDomain R]
theorem mod_mem_iff {S : Ideal R} {x y : R} (hy : y ∈ S) : x % y ∈ S ↔ x ∈ S :=
⟨fun hxy => div_add_mod x y ▸ S.add_mem (S.mul_mem_right _ hy) hxy, fun hx =>
(mod_eq_sub_mul_div x y).symm ▸ S.sub_mem hx (S.mul_mem_right _ hy)⟩
#align mod_mem_iff mod_mem_iff
-- see Note [lower instance priority]
instance (priority := 100) EuclideanDomain.to_principal_ideal_domain : IsPrincipalIdealRing R where
principal S := by classical exact
⟨if h : { x : R | x ∈ S ∧ x ≠ 0 }.Nonempty then
have wf : WellFounded (EuclideanDomain.r : R → R → Prop) := EuclideanDomain.r_wellFounded
have hmin : WellFounded.min wf { x : R | x ∈ S ∧ x ≠ 0 } h ∈ S ∧
WellFounded.min wf { x : R | x ∈ S ∧ x ≠ 0 } h ≠ 0 :=
WellFounded.min_mem wf { x : R | x ∈ S ∧ x ≠ 0 } h
⟨WellFounded.min wf { x : R | x ∈ S ∧ x ≠ 0 } h,
Submodule.ext fun x => ⟨fun hx =>
div_add_mod x (WellFounded.min wf { x : R | x ∈ S ∧ x ≠ 0 } h) ▸
(Ideal.mem_span_singleton.2 <| dvd_add (dvd_mul_right _ _) <| by
have : x % WellFounded.min wf { x : R | x ∈ S ∧ x ≠ 0 } h ∉
{ x : R | x ∈ S ∧ x ≠ 0 } :=
fun h₁ => WellFounded.not_lt_min wf _ h h₁ (mod_lt x hmin.2)
have : x % WellFounded.min wf { x : R | x ∈ S ∧ x ≠ 0 } h = 0 := by
simp only [not_and_or, Set.mem_setOf_eq, not_ne_iff] at this
exact this.neg_resolve_left <| (mod_mem_iff hmin.1).2 hx
simp [*]),
fun hx =>
let ⟨y, hy⟩ := Ideal.mem_span_singleton.1 hx
hy.symm ▸ S.mul_mem_right _ hmin.1⟩⟩
else ⟨0, Submodule.ext fun a => by
rw [← @Submodule.bot_coe R R _ _ _, span_eq, Submodule.mem_bot]
exact ⟨fun haS => by_contra fun ha0 => h ⟨a, ⟨haS, ha0⟩⟩,
fun h₁ => h₁.symm ▸ S.zero_mem⟩⟩⟩
#align euclidean_domain.to_principal_ideal_domain EuclideanDomain.to_principal_ideal_domain
end
theorem IsField.isPrincipalIdealRing {R : Type*} [CommRing R] (h : IsField R) :
IsPrincipalIdealRing R :=
@EuclideanDomain.to_principal_ideal_domain R (@Field.toEuclideanDomain R h.toField)
#align is_field.is_principal_ideal_ring IsField.isPrincipalIdealRing
namespace PrincipalIdealRing
open IsPrincipalIdealRing
-- see Note [lower instance priority]
instance (priority := 100) isNoetherianRing [Ring R] [IsPrincipalIdealRing R] :
IsNoetherianRing R :=
isNoetherianRing_iff.2
⟨fun s : Ideal R => by
rcases (IsPrincipalIdealRing.principal s).principal with ⟨a, rfl⟩
rw [← Finset.coe_singleton]
exact ⟨{a}, SetLike.coe_injective rfl⟩⟩
#align principal_ideal_ring.is_noetherian_ring PrincipalIdealRing.isNoetherianRing
theorem isMaximal_of_irreducible [CommRing R] [IsPrincipalIdealRing R] {p : R}
(hp : Irreducible p) : Ideal.IsMaximal (span R ({p} : Set R)) :=
⟨⟨mt Ideal.span_singleton_eq_top.1 hp.1, fun I hI => by
rcases principal I with ⟨a, rfl⟩
erw [Ideal.span_singleton_eq_top]
rcases Ideal.span_singleton_le_span_singleton.1 (le_of_lt hI) with ⟨b, rfl⟩
refine (of_irreducible_mul hp).resolve_right (mt (fun hb => ?_) (not_le_of_lt hI))
erw [Ideal.span_singleton_le_span_singleton, IsUnit.mul_right_dvd hb]⟩⟩
#align principal_ideal_ring.is_maximal_of_irreducible PrincipalIdealRing.isMaximal_of_irreducible
@[deprecated] protected alias irreducible_iff_prime := irreducible_iff_prime
#align principal_ideal_ring.irreducible_iff_prime irreducible_iff_prime
@[deprecated] protected alias associates_irreducible_iff_prime := associates_irreducible_iff_prime
#align principal_ideal_ring.associates_irreducible_iff_prime associates_irreducible_iff_prime
variable [CommRing R] [IsDomain R] [IsPrincipalIdealRing R]
section
open scoped Classical
/-- `factors a` is a multiset of irreducible elements whose product is `a`, up to units -/
noncomputable def factors (a : R) : Multiset R :=
if h : a = 0 then ∅ else Classical.choose (WfDvdMonoid.exists_factors a h)
#align principal_ideal_ring.factors PrincipalIdealRing.factors
theorem factors_spec (a : R) (h : a ≠ 0) :
(∀ b ∈ factors a, Irreducible b) ∧ Associated (factors a).prod a := by
unfold factors; rw [dif_neg h]
exact Classical.choose_spec (WfDvdMonoid.exists_factors a h)
#align principal_ideal_ring.factors_spec PrincipalIdealRing.factors_spec
theorem ne_zero_of_mem_factors {R : Type v} [CommRing R] [IsDomain R] [IsPrincipalIdealRing R]
{a b : R} (ha : a ≠ 0) (hb : b ∈ factors a) : b ≠ 0 :=
Irreducible.ne_zero ((factors_spec a ha).1 b hb)
#align principal_ideal_ring.ne_zero_of_mem_factors PrincipalIdealRing.ne_zero_of_mem_factors
theorem mem_submonoid_of_factors_subset_of_units_subset (s : Submonoid R) {a : R} (ha : a ≠ 0)
(hfac : ∀ b ∈ factors a, b ∈ s) (hunit : ∀ c : Rˣ, (c : R) ∈ s) : a ∈ s := by
rcases (factors_spec a ha).2 with ⟨c, hc⟩
rw [← hc]
exact mul_mem (multiset_prod_mem _ hfac) (hunit _)
#align principal_ideal_ring.mem_submonoid_of_factors_subset_of_units_subset PrincipalIdealRing.mem_submonoid_of_factors_subset_of_units_subset
/-- If a `RingHom` maps all units and all factors of an element `a` into a submonoid `s`, then it
also maps `a` into that submonoid. -/
theorem ringHom_mem_submonoid_of_factors_subset_of_units_subset {R S : Type*} [CommRing R]
[IsDomain R] [IsPrincipalIdealRing R] [Semiring S] (f : R →+* S) (s : Submonoid S) (a : R)
(ha : a ≠ 0) (h : ∀ b ∈ factors a, f b ∈ s) (hf : ∀ c : Rˣ, f c ∈ s) : f a ∈ s :=
mem_submonoid_of_factors_subset_of_units_subset (s.comap f.toMonoidHom) ha h hf
#align principal_ideal_ring.ring_hom_mem_submonoid_of_factors_subset_of_units_subset PrincipalIdealRing.ringHom_mem_submonoid_of_factors_subset_of_units_subset
-- see Note [lower instance priority]
/-- A principal ideal domain has unique factorization -/
instance (priority := 100) to_uniqueFactorizationMonoid : UniqueFactorizationMonoid R :=
{ (IsNoetherianRing.wfDvdMonoid : WfDvdMonoid R) with
irreducible_iff_prime := irreducible_iff_prime }
#align principal_ideal_ring.to_unique_factorization_monoid PrincipalIdealRing.to_uniqueFactorizationMonoid
end
end PrincipalIdealRing
section Surjective
open Submodule
variable {S N : Type*} [Ring R] [AddCommGroup M] [AddCommGroup N] [Ring S]
variable [Module R M] [Module R N]
theorem Submodule.IsPrincipal.of_comap (f : M →ₗ[R] N) (hf : Function.Surjective f)
(S : Submodule R N) [hI : IsPrincipal (S.comap f)] : IsPrincipal S :=
⟨⟨f (IsPrincipal.generator (S.comap f)), by
rw [← Set.image_singleton, ← Submodule.map_span, IsPrincipal.span_singleton_generator,
Submodule.map_comap_eq_of_surjective hf]⟩⟩
#align submodule.is_principal.of_comap Submodule.IsPrincipal.of_comap
theorem Ideal.IsPrincipal.of_comap (f : R →+* S) (hf : Function.Surjective f) (I : Ideal S)
[hI : IsPrincipal (I.comap f)] : IsPrincipal I :=
⟨⟨f (IsPrincipal.generator (I.comap f)), by
rw [Ideal.submodule_span_eq, ← Set.image_singleton, ← Ideal.map_span,
Ideal.span_singleton_generator, Ideal.map_comap_of_surjective f hf]⟩⟩
#align ideal.is_principal.of_comap Ideal.IsPrincipal.of_comap
/-- The surjective image of a principal ideal ring is again a principal ideal ring. -/
theorem IsPrincipalIdealRing.of_surjective [IsPrincipalIdealRing R] (f : R →+* S)
(hf : Function.Surjective f) : IsPrincipalIdealRing S :=
⟨fun I => Ideal.IsPrincipal.of_comap f hf I⟩
#align is_principal_ideal_ring.of_surjective IsPrincipalIdealRing.of_surjective
end Surjective
section
open Ideal
variable [CommRing R] [IsDomain R]
section Bezout
variable [IsBezout R]
section GCD
variable [GCDMonoid R]
theorem IsBezout.span_gcd_eq_span_gcd (x y : R) :
span {GCDMonoid.gcd x y} = span {IsBezout.gcd x y} := by
rw [Ideal.span_singleton_eq_span_singleton]
exact associated_of_dvd_dvd
(IsBezout.dvd_gcd (GCDMonoid.gcd_dvd_left _ _) <| GCDMonoid.gcd_dvd_right _ _)
(GCDMonoid.dvd_gcd (IsBezout.gcd_dvd_left _ _) <| IsBezout.gcd_dvd_right _ _)
theorem span_gcd (x y : R) : span {gcd x y} = span {x, y} := by
rw [← IsBezout.span_gcd, IsBezout.span_gcd_eq_span_gcd]
#align span_gcd span_gcd
theorem gcd_dvd_iff_exists (a b : R) {z} : gcd a b ∣ z ↔ ∃ x y, z = a * x + b * y := by
simp_rw [mul_comm a, mul_comm b, @eq_comm _ z, ← Ideal.mem_span_pair, ← span_gcd,
Ideal.mem_span_singleton]
#align gcd_dvd_iff_exists gcd_dvd_iff_exists
/-- **Bézout's lemma** -/
theorem exists_gcd_eq_mul_add_mul (a b : R) : ∃ x y, gcd a b = a * x + b * y := by
rw [← gcd_dvd_iff_exists]
#align exists_gcd_eq_mul_add_mul exists_gcd_eq_mul_add_mul
theorem gcd_isUnit_iff (x y : R) : IsUnit (gcd x y) ↔ IsCoprime x y := by
rw [IsCoprime, ← Ideal.mem_span_pair, ← span_gcd, ← span_singleton_eq_top, eq_top_iff_one]
#align gcd_is_unit_iff gcd_isUnit_iff
end GCD
theorem isCoprime_of_dvd (x y : R) (nonzero : ¬(x = 0 ∧ y = 0))
(H : ∀ z ∈ nonunits R, z ≠ 0 → z ∣ x → ¬z ∣ y) : IsCoprime x y :=
(isRelPrime_of_no_nonunits_factors nonzero H).isCoprime
#align is_coprime_of_dvd isCoprime_of_dvd
theorem dvd_or_coprime (x y : R) (h : Irreducible x) : x ∣ y ∨ IsCoprime x y :=
h.dvd_or_isRelPrime.imp_right IsRelPrime.isCoprime
#align dvd_or_coprime dvd_or_coprime
/-- See also `Irreducible.isRelPrime_iff_not_dvd`. -/
theorem Irreducible.coprime_iff_not_dvd {p n : R} (hp : Irreducible p) :
IsCoprime p n ↔ ¬p ∣ n := by rw [← isRelPrime_iff_isCoprime, hp.isRelPrime_iff_not_dvd]
#align irreducible.coprime_iff_not_dvd Irreducible.coprime_iff_not_dvd
theorem Prime.coprime_iff_not_dvd {p n : R} (hp : Prime p) : IsCoprime p n ↔ ¬p ∣ n :=
hp.irreducible.coprime_iff_not_dvd
#align prime.coprime_iff_not_dvd Prime.coprime_iff_not_dvd
/-- See also `Irreducible.coprime_iff_not_dvd'`. -/
theorem Irreducible.dvd_iff_not_coprime {p n : R} (hp : Irreducible p) : p ∣ n ↔ ¬IsCoprime p n :=
iff_not_comm.2 hp.coprime_iff_not_dvd
#align irreducible.dvd_iff_not_coprime Irreducible.dvd_iff_not_coprime
theorem Irreducible.coprime_pow_of_not_dvd {p a : R} (m : ℕ) (hp : Irreducible p) (h : ¬p ∣ a) :
IsCoprime a (p ^ m) :=
(hp.coprime_iff_not_dvd.2 h).symm.pow_right
#align irreducible.coprime_pow_of_not_dvd Irreducible.coprime_pow_of_not_dvd
theorem Irreducible.coprime_or_dvd {p : R} (hp : Irreducible p) (i : R) : IsCoprime p i ∨ p ∣ i :=
(_root_.em _).imp_right hp.dvd_iff_not_coprime.2
#align irreducible.coprime_or_dvd Irreducible.coprime_or_dvd
| Mathlib/RingTheory/PrincipalIdealDomain.lean | 482 | 486 | theorem exists_associated_pow_of_mul_eq_pow' {a b c : R} (hab : IsCoprime a b) {k : ℕ}
(h : a * b = c ^ k) : ∃ d : R, Associated (d ^ k) a := by |
classical
letI := IsBezout.toGCDDomain R
exact exists_associated_pow_of_mul_eq_pow ((gcd_isUnit_iff _ _).mpr hab) h
|
/-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Mario Carneiro, Yury Kudryashov
-/
import Mathlib.Topology.Order.LeftRightNhds
/-!
# Properties of LUB and GLB in an order topology
-/
open Set Filter TopologicalSpace Topology Function
open OrderDual (toDual ofDual)
variable {α β γ : Type*}
section OrderTopology
variable [TopologicalSpace α] [TopologicalSpace β] [LinearOrder α] [LinearOrder β] [OrderTopology α]
[OrderTopology β]
theorem IsLUB.frequently_mem {a : α} {s : Set α} (ha : IsLUB s a) (hs : s.Nonempty) :
∃ᶠ x in 𝓝[≤] a, x ∈ s := by
rcases hs with ⟨a', ha'⟩
intro h
rcases (ha.1 ha').eq_or_lt with (rfl | ha'a)
· exact h.self_of_nhdsWithin le_rfl ha'
· rcases (mem_nhdsWithin_Iic_iff_exists_Ioc_subset' ha'a).1 h with ⟨b, hba, hb⟩
rcases ha.exists_between hba with ⟨b', hb's, hb'⟩
exact hb hb' hb's
#align is_lub.frequently_mem IsLUB.frequently_mem
theorem IsLUB.frequently_nhds_mem {a : α} {s : Set α} (ha : IsLUB s a) (hs : s.Nonempty) :
∃ᶠ x in 𝓝 a, x ∈ s :=
(ha.frequently_mem hs).filter_mono inf_le_left
#align is_lub.frequently_nhds_mem IsLUB.frequently_nhds_mem
theorem IsGLB.frequently_mem {a : α} {s : Set α} (ha : IsGLB s a) (hs : s.Nonempty) :
∃ᶠ x in 𝓝[≥] a, x ∈ s :=
IsLUB.frequently_mem (α := αᵒᵈ) ha hs
#align is_glb.frequently_mem IsGLB.frequently_mem
theorem IsGLB.frequently_nhds_mem {a : α} {s : Set α} (ha : IsGLB s a) (hs : s.Nonempty) :
∃ᶠ x in 𝓝 a, x ∈ s :=
(ha.frequently_mem hs).filter_mono inf_le_left
#align is_glb.frequently_nhds_mem IsGLB.frequently_nhds_mem
theorem IsLUB.mem_closure {a : α} {s : Set α} (ha : IsLUB s a) (hs : s.Nonempty) : a ∈ closure s :=
(ha.frequently_nhds_mem hs).mem_closure
#align is_lub.mem_closure IsLUB.mem_closure
theorem IsGLB.mem_closure {a : α} {s : Set α} (ha : IsGLB s a) (hs : s.Nonempty) : a ∈ closure s :=
(ha.frequently_nhds_mem hs).mem_closure
#align is_glb.mem_closure IsGLB.mem_closure
theorem IsLUB.nhdsWithin_neBot {a : α} {s : Set α} (ha : IsLUB s a) (hs : s.Nonempty) :
NeBot (𝓝[s] a) :=
mem_closure_iff_nhdsWithin_neBot.1 (ha.mem_closure hs)
#align is_lub.nhds_within_ne_bot IsLUB.nhdsWithin_neBot
theorem IsGLB.nhdsWithin_neBot : ∀ {a : α} {s : Set α}, IsGLB s a → s.Nonempty → NeBot (𝓝[s] a) :=
IsLUB.nhdsWithin_neBot (α := αᵒᵈ)
#align is_glb.nhds_within_ne_bot IsGLB.nhdsWithin_neBot
theorem isLUB_of_mem_nhds {s : Set α} {a : α} {f : Filter α} (hsa : a ∈ upperBounds s) (hsf : s ∈ f)
[NeBot (f ⊓ 𝓝 a)] : IsLUB s a :=
⟨hsa, fun b hb =>
not_lt.1 fun hba =>
have : s ∩ { a | b < a } ∈ f ⊓ 𝓝 a := inter_mem_inf hsf (IsOpen.mem_nhds (isOpen_lt' _) hba)
let ⟨_x, ⟨hxs, hxb⟩⟩ := Filter.nonempty_of_mem this
have : b < b := lt_of_lt_of_le hxb <| hb hxs
lt_irrefl b this⟩
#align is_lub_of_mem_nhds isLUB_of_mem_nhds
theorem isLUB_of_mem_closure {s : Set α} {a : α} (hsa : a ∈ upperBounds s) (hsf : a ∈ closure s) :
IsLUB s a := by
rw [mem_closure_iff_clusterPt, ClusterPt, inf_comm] at hsf
exact isLUB_of_mem_nhds hsa (mem_principal_self s)
#align is_lub_of_mem_closure isLUB_of_mem_closure
theorem isGLB_of_mem_nhds :
∀ {s : Set α} {a : α} {f : Filter α}, a ∈ lowerBounds s → s ∈ f → NeBot (f ⊓ 𝓝 a) → IsGLB s a :=
isLUB_of_mem_nhds (α := αᵒᵈ)
#align is_glb_of_mem_nhds isGLB_of_mem_nhds
theorem isGLB_of_mem_closure {s : Set α} {a : α} (hsa : a ∈ lowerBounds s) (hsf : a ∈ closure s) :
IsGLB s a :=
isLUB_of_mem_closure (α := αᵒᵈ) hsa hsf
#align is_glb_of_mem_closure isGLB_of_mem_closure
theorem IsLUB.mem_upperBounds_of_tendsto [Preorder γ] [TopologicalSpace γ] [OrderClosedTopology γ]
{f : α → γ} {s : Set α} {a : α} {b : γ} (hf : MonotoneOn f s) (ha : IsLUB s a)
(hb : Tendsto f (𝓝[s] a) (𝓝 b)) : b ∈ upperBounds (f '' s) := by
rintro _ ⟨x, hx, rfl⟩
replace ha := ha.inter_Ici_of_mem hx
haveI := ha.nhdsWithin_neBot ⟨x, hx, le_rfl⟩
refine ge_of_tendsto (hb.mono_left (nhdsWithin_mono a (inter_subset_left (t := Ici x)))) ?_
exact mem_of_superset self_mem_nhdsWithin fun y hy => hf hx hy.1 hy.2
#align is_lub.mem_upper_bounds_of_tendsto IsLUB.mem_upperBounds_of_tendsto
-- For a version of this theorem in which the convergence considered on the domain `α` is as `x : α`
-- tends to infinity, rather than tending to a point `x` in `α`, see `isLUB_of_tendsto_atTop`
theorem IsLUB.isLUB_of_tendsto [Preorder γ] [TopologicalSpace γ] [OrderClosedTopology γ] {f : α → γ}
{s : Set α} {a : α} {b : γ} (hf : MonotoneOn f s) (ha : IsLUB s a) (hs : s.Nonempty)
(hb : Tendsto f (𝓝[s] a) (𝓝 b)) : IsLUB (f '' s) b :=
haveI := ha.nhdsWithin_neBot hs
⟨ha.mem_upperBounds_of_tendsto hf hb, fun _b' hb' =>
le_of_tendsto hb (mem_of_superset self_mem_nhdsWithin fun _ hx => hb' <| mem_image_of_mem _ hx)⟩
#align is_lub.is_lub_of_tendsto IsLUB.isLUB_of_tendsto
theorem IsGLB.mem_lowerBounds_of_tendsto [Preorder γ] [TopologicalSpace γ] [OrderClosedTopology γ]
{f : α → γ} {s : Set α} {a : α} {b : γ} (hf : MonotoneOn f s) (ha : IsGLB s a)
(hb : Tendsto f (𝓝[s] a) (𝓝 b)) : b ∈ lowerBounds (f '' s) :=
IsLUB.mem_upperBounds_of_tendsto (α := αᵒᵈ) (γ := γᵒᵈ) hf.dual ha hb
#align is_glb.mem_lower_bounds_of_tendsto IsGLB.mem_lowerBounds_of_tendsto
-- For a version of this theorem in which the convergence considered on the domain `α` is as
-- `x : α` tends to negative infinity, rather than tending to a point `x` in `α`, see
-- `isGLB_of_tendsto_atBot`
theorem IsGLB.isGLB_of_tendsto [Preorder γ] [TopologicalSpace γ] [OrderClosedTopology γ] {f : α → γ}
{s : Set α} {a : α} {b : γ} (hf : MonotoneOn f s) :
IsGLB s a → s.Nonempty → Tendsto f (𝓝[s] a) (𝓝 b) → IsGLB (f '' s) b :=
IsLUB.isLUB_of_tendsto (α := αᵒᵈ) (γ := γᵒᵈ) hf.dual
#align is_glb.is_glb_of_tendsto IsGLB.isGLB_of_tendsto
theorem IsLUB.mem_lowerBounds_of_tendsto [Preorder γ] [TopologicalSpace γ] [OrderClosedTopology γ]
{f : α → γ} {s : Set α} {a : α} {b : γ} (hf : AntitoneOn f s) (ha : IsLUB s a)
(hb : Tendsto f (𝓝[s] a) (𝓝 b)) : b ∈ lowerBounds (f '' s) :=
IsLUB.mem_upperBounds_of_tendsto (γ := γᵒᵈ) hf ha hb
#align is_lub.mem_lower_bounds_of_tendsto IsLUB.mem_lowerBounds_of_tendsto
theorem IsLUB.isGLB_of_tendsto [Preorder γ] [TopologicalSpace γ] [OrderClosedTopology γ] :
∀ {f : α → γ} {s : Set α} {a : α} {b : γ},
AntitoneOn f s → IsLUB s a → s.Nonempty → Tendsto f (𝓝[s] a) (𝓝 b) → IsGLB (f '' s) b :=
IsLUB.isLUB_of_tendsto (γ := γᵒᵈ)
#align is_lub.is_glb_of_tendsto IsLUB.isGLB_of_tendsto
theorem IsGLB.mem_upperBounds_of_tendsto [Preorder γ] [TopologicalSpace γ] [OrderClosedTopology γ]
{f : α → γ} {s : Set α} {a : α} {b : γ} (hf : AntitoneOn f s) (ha : IsGLB s a)
(hb : Tendsto f (𝓝[s] a) (𝓝 b)) : b ∈ upperBounds (f '' s) :=
IsGLB.mem_lowerBounds_of_tendsto (γ := γᵒᵈ) hf ha hb
#align is_glb.mem_upper_bounds_of_tendsto IsGLB.mem_upperBounds_of_tendsto
theorem IsGLB.isLUB_of_tendsto [Preorder γ] [TopologicalSpace γ] [OrderClosedTopology γ] :
∀ {f : α → γ} {s : Set α} {a : α} {b : γ},
AntitoneOn f s → IsGLB s a → s.Nonempty → Tendsto f (𝓝[s] a) (𝓝 b) → IsLUB (f '' s) b :=
IsGLB.isGLB_of_tendsto (γ := γᵒᵈ)
#align is_glb.is_lub_of_tendsto IsGLB.isLUB_of_tendsto
theorem IsLUB.mem_of_isClosed {a : α} {s : Set α} (ha : IsLUB s a) (hs : s.Nonempty)
(sc : IsClosed s) : a ∈ s :=
sc.closure_subset <| ha.mem_closure hs
#align is_lub.mem_of_is_closed IsLUB.mem_of_isClosed
alias IsClosed.isLUB_mem := IsLUB.mem_of_isClosed
#align is_closed.is_lub_mem IsClosed.isLUB_mem
theorem IsGLB.mem_of_isClosed {a : α} {s : Set α} (ha : IsGLB s a) (hs : s.Nonempty)
(sc : IsClosed s) : a ∈ s :=
sc.closure_subset <| ha.mem_closure hs
#align is_glb.mem_of_is_closed IsGLB.mem_of_isClosed
alias IsClosed.isGLB_mem := IsGLB.mem_of_isClosed
#align is_closed.is_glb_mem IsClosed.isGLB_mem
/-!
### Existence of sequences tending to `sInf` or `sSup` of a given set
-/
theorem IsLUB.exists_seq_strictMono_tendsto_of_not_mem {t : Set α} {x : α}
[IsCountablyGenerated (𝓝 x)] (htx : IsLUB t x) (not_mem : x ∉ t) (ht : t.Nonempty) :
∃ u : ℕ → α, StrictMono u ∧ (∀ n, u n < x) ∧ Tendsto u atTop (𝓝 x) ∧ ∀ n, u n ∈ t := by
obtain ⟨v, hvx, hvt⟩ := exists_seq_forall_of_frequently (htx.frequently_mem ht)
replace hvx := hvx.mono_right nhdsWithin_le_nhds
have hvx' : ∀ {n}, v n < x := (htx.1 (hvt _)).lt_of_ne (ne_of_mem_of_not_mem (hvt _) not_mem)
have : ∀ k, ∀ᶠ l in atTop, v k < v l := fun k => hvx.eventually (lt_mem_nhds hvx')
choose N hN hvN using fun k => ((eventually_gt_atTop k).and (this k)).exists
refine ⟨fun k => v (N^[k] 0), strictMono_nat_of_lt_succ fun _ => ?_, fun _ => hvx',
hvx.comp (strictMono_nat_of_lt_succ fun _ => ?_).tendsto_atTop, fun _ => hvt _⟩
· rw [iterate_succ_apply']; exact hvN _
· rw [iterate_succ_apply']; exact hN _
#align is_lub.exists_seq_strict_mono_tendsto_of_not_mem IsLUB.exists_seq_strictMono_tendsto_of_not_mem
| Mathlib/Topology/Order/IsLUB.lean | 186 | 192 | theorem IsLUB.exists_seq_monotone_tendsto {t : Set α} {x : α} [IsCountablyGenerated (𝓝 x)]
(htx : IsLUB t x) (ht : t.Nonempty) :
∃ u : ℕ → α, Monotone u ∧ (∀ n, u n ≤ x) ∧ Tendsto u atTop (𝓝 x) ∧ ∀ n, u n ∈ t := by |
by_cases h : x ∈ t
· exact ⟨fun _ => x, monotone_const, fun n => le_rfl, tendsto_const_nhds, fun _ => h⟩
· rcases htx.exists_seq_strictMono_tendsto_of_not_mem h ht with ⟨u, hu⟩
exact ⟨u, hu.1.monotone, fun n => (hu.2.1 n).le, hu.2.2⟩
|
/-
Copyright (c) 2023 Ali Ramsey. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Ali Ramsey, Eric Wieser
-/
import Mathlib.LinearAlgebra.Finsupp
import Mathlib.LinearAlgebra.Prod
import Mathlib.LinearAlgebra.TensorProduct.Basic
/-!
# Coalgebras
In this file we define `Coalgebra`, and provide instances for:
* Commutative semirings: `CommSemiring.toCoalgebra`
* Binary products: `Prod.instCoalgebra`
* Finitely supported functions: `Finsupp.instCoalgebra`
## References
* <https://en.wikipedia.org/wiki/Coalgebra>
-/
suppress_compilation
universe u v w
open scoped TensorProduct
/-- Data fields for `Coalgebra`, to allow API to be constructed before proving `Coalgebra.coassoc`.
See `Coalgebra` for documentation. -/
class CoalgebraStruct (R : Type u) (A : Type v)
[CommSemiring R] [AddCommMonoid A] [Module R A] where
/-- The comultiplication of the coalgebra -/
comul : A →ₗ[R] A ⊗[R] A
/-- The counit of the coalgebra -/
counit : A →ₗ[R] R
namespace Coalgebra
export CoalgebraStruct (comul counit)
end Coalgebra
/-- A coalgebra over a commutative (semi)ring `R` is an `R`-module equipped with a coassociative
comultiplication `Δ` and a counit `ε` obeying the left and right counitality laws. -/
class Coalgebra (R : Type u) (A : Type v)
[CommSemiring R] [AddCommMonoid A] [Module R A] extends CoalgebraStruct R A where
/-- The comultiplication is coassociative -/
coassoc : TensorProduct.assoc R A A A ∘ₗ comul.rTensor A ∘ₗ comul = comul.lTensor A ∘ₗ comul
/-- The counit satisfies the left counitality law -/
rTensor_counit_comp_comul : counit.rTensor A ∘ₗ comul = TensorProduct.mk R _ _ 1
/-- The counit satisfies the right counitality law -/
lTensor_counit_comp_comul : counit.lTensor A ∘ₗ comul = (TensorProduct.mk R _ _).flip 1
namespace Coalgebra
variable {R : Type u} {A : Type v}
variable [CommSemiring R] [AddCommMonoid A] [Module R A] [Coalgebra R A]
@[simp]
theorem coassoc_apply (a : A) :
TensorProduct.assoc R A A A (comul.rTensor A (comul a)) = comul.lTensor A (comul a) :=
LinearMap.congr_fun coassoc a
@[simp]
theorem coassoc_symm_apply (a : A) :
(TensorProduct.assoc R A A A).symm (comul.lTensor A (comul a)) = comul.rTensor A (comul a) := by
rw [(TensorProduct.assoc R A A A).symm_apply_eq, coassoc_apply a]
@[simp]
theorem coassoc_symm :
(TensorProduct.assoc R A A A).symm ∘ₗ comul.lTensor A ∘ₗ comul =
comul.rTensor A ∘ₗ (comul (R := R)) :=
LinearMap.ext coassoc_symm_apply
@[simp]
theorem rTensor_counit_comul (a : A) : counit.rTensor A (comul a) = 1 ⊗ₜ[R] a :=
LinearMap.congr_fun rTensor_counit_comp_comul a
@[simp]
theorem lTensor_counit_comul (a : A) : counit.lTensor A (comul a) = a ⊗ₜ[R] 1 :=
LinearMap.congr_fun lTensor_counit_comp_comul a
end Coalgebra
section CommSemiring
open Coalgebra
namespace CommSemiring
variable (R : Type u) [CommSemiring R]
/-- Every commutative (semi)ring is a coalgebra over itself, with `Δ r = 1 ⊗ₜ r`. -/
instance toCoalgebra : Coalgebra R R where
comul := (TensorProduct.mk R R R) 1
counit := .id
coassoc := rfl
rTensor_counit_comp_comul := by ext; rfl
lTensor_counit_comp_comul := by ext; rfl
@[simp]
theorem comul_apply (r : R) : comul r = 1 ⊗ₜ[R] r := rfl
@[simp]
theorem counit_apply (r : R) : counit r = r := rfl
end CommSemiring
namespace Prod
variable (R : Type u) (A : Type v) (B : Type w)
variable [CommSemiring R] [AddCommMonoid A] [AddCommMonoid B] [Module R A] [Module R B]
variable [Coalgebra R A] [Coalgebra R B]
open LinearMap
instance instCoalgebraStruct : CoalgebraStruct R (A × B) where
comul := .coprod
(TensorProduct.map (.inl R A B) (.inl R A B) ∘ₗ comul)
(TensorProduct.map (.inr R A B) (.inr R A B) ∘ₗ comul)
counit := .coprod counit counit
@[simp]
theorem comul_apply (r : A × B) :
comul r =
TensorProduct.map (.inl R A B) (.inl R A B) (comul r.1) +
TensorProduct.map (.inr R A B) (.inr R A B) (comul r.2) := rfl
@[simp]
theorem counit_apply (r : A × B) : (counit r : R) = counit r.1 + counit r.2 := rfl
theorem comul_comp_inl :
comul ∘ₗ inl R A B = TensorProduct.map (.inl R A B) (.inl R A B) ∘ₗ comul := by
ext; simp
theorem comul_comp_inr :
comul ∘ₗ inr R A B = TensorProduct.map (.inr R A B) (.inr R A B) ∘ₗ comul := by
ext; simp
theorem comul_comp_fst :
comul ∘ₗ .fst R A B = TensorProduct.map (.fst R A B) (.fst R A B) ∘ₗ comul := by
ext : 1
· rw [comp_assoc, fst_comp_inl, comp_id, comp_assoc, comul_comp_inl, ← comp_assoc,
← TensorProduct.map_comp, fst_comp_inl, TensorProduct.map_id, id_comp]
· rw [comp_assoc, fst_comp_inr, comp_zero, comp_assoc, comul_comp_inr, ← comp_assoc,
← TensorProduct.map_comp, fst_comp_inr, TensorProduct.map_zero_left, zero_comp]
| Mathlib/RingTheory/Coalgebra/Basic.lean | 145 | 151 | theorem comul_comp_snd :
comul ∘ₗ .snd R A B = TensorProduct.map (.snd R A B) (.snd R A B) ∘ₗ comul := by |
ext : 1
· rw [comp_assoc, snd_comp_inl, comp_zero, comp_assoc, comul_comp_inl, ← comp_assoc,
← TensorProduct.map_comp, snd_comp_inl, TensorProduct.map_zero_left, zero_comp]
· rw [comp_assoc, snd_comp_inr, comp_id, comp_assoc, comul_comp_inr, ← comp_assoc,
← TensorProduct.map_comp, snd_comp_inr, TensorProduct.map_id, id_comp]
|
/-
Copyright (c) 2022 Alexander Bentkamp. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Alexander Bentkamp, Eric Wieser, Jeremy Avigad, Johan Commelin
-/
import Mathlib.Data.Matrix.Invertible
import Mathlib.LinearAlgebra.Matrix.NonsingularInverse
import Mathlib.LinearAlgebra.Matrix.PosDef
#align_import linear_algebra.matrix.schur_complement from "leanprover-community/mathlib"@"a176cb1219e300e85793d44583dede42377b51af"
/-! # 2×2 block matrices and the Schur complement
This file proves properties of 2×2 block matrices `[A B; C D]` that relate to the Schur complement
`D - C*A⁻¹*B`.
Some of the results here generalize to 2×2 matrices in a category, rather than just a ring. A few
results in this direction can be found in the file `CateogryTheory.Preadditive.Biproducts`,
especially the declarations `CategoryTheory.Biprod.gaussian` and `CategoryTheory.Biprod.isoElim`.
Compare with `Matrix.invertibleOfFromBlocks₁₁Invertible`.
## Main results
* `Matrix.det_fromBlocks₁₁`, `Matrix.det_fromBlocks₂₂`: determinant of a block matrix in terms of
the Schur complement.
* `Matrix.invOf_fromBlocks_zero₂₁_eq`, `Matrix.invOf_fromBlocks_zero₁₂_eq`: the inverse of a
block triangular matrix.
* `Matrix.isUnit_fromBlocks_zero₂₁`, `Matrix.isUnit_fromBlocks_zero₁₂`: invertibility of a
block triangular matrix.
* `Matrix.det_one_add_mul_comm`: the **Weinstein–Aronszajn identity**.
* `Matrix.PosSemidef.fromBlocks₁₁` and `Matrix.PosSemidef.fromBlocks₂₂`: If a matrix `A` is
positive definite, then `[A B; Bᴴ D]` is postive semidefinite if and only if `D - Bᴴ A⁻¹ B` is
postive semidefinite.
-/
variable {l m n α : Type*}
namespace Matrix
open scoped Matrix
section CommRing
variable [Fintype l] [Fintype m] [Fintype n]
variable [DecidableEq l] [DecidableEq m] [DecidableEq n]
variable [CommRing α]
/-- LDU decomposition of a block matrix with an invertible top-left corner, using the
Schur complement. -/
theorem fromBlocks_eq_of_invertible₁₁ (A : Matrix m m α) (B : Matrix m n α) (C : Matrix l m α)
(D : Matrix l n α) [Invertible A] :
fromBlocks A B C D =
fromBlocks 1 0 (C * ⅟ A) 1 * fromBlocks A 0 0 (D - C * ⅟ A * B) *
fromBlocks 1 (⅟ A * B) 0 1 := by
simp only [fromBlocks_multiply, Matrix.mul_zero, Matrix.zero_mul, add_zero, zero_add,
Matrix.one_mul, Matrix.mul_one, invOf_mul_self, Matrix.mul_invOf_self_assoc,
Matrix.mul_invOf_mul_self_cancel, Matrix.mul_assoc, add_sub_cancel]
#align matrix.from_blocks_eq_of_invertible₁₁ Matrix.fromBlocks_eq_of_invertible₁₁
/-- LDU decomposition of a block matrix with an invertible bottom-right corner, using the
Schur complement. -/
theorem fromBlocks_eq_of_invertible₂₂ (A : Matrix l m α) (B : Matrix l n α) (C : Matrix n m α)
(D : Matrix n n α) [Invertible D] :
fromBlocks A B C D =
fromBlocks 1 (B * ⅟ D) 0 1 * fromBlocks (A - B * ⅟ D * C) 0 0 D *
fromBlocks 1 0 (⅟ D * C) 1 :=
(Matrix.reindex (Equiv.sumComm _ _) (Equiv.sumComm _ _)).injective <| by
simpa [reindex_apply, Equiv.sumComm_symm, ← submatrix_mul_equiv _ _ _ (Equiv.sumComm n m), ←
submatrix_mul_equiv _ _ _ (Equiv.sumComm n l), Equiv.sumComm_apply,
fromBlocks_submatrix_sum_swap_sum_swap] using fromBlocks_eq_of_invertible₁₁ D C B A
#align matrix.from_blocks_eq_of_invertible₂₂ Matrix.fromBlocks_eq_of_invertible₂₂
section Triangular
/-! #### Block triangular matrices -/
/-- An upper-block-triangular matrix is invertible if its diagonal is. -/
def fromBlocksZero₂₁Invertible (A : Matrix m m α) (B : Matrix m n α) (D : Matrix n n α)
[Invertible A] [Invertible D] : Invertible (fromBlocks A B 0 D) :=
invertibleOfLeftInverse _ (fromBlocks (⅟ A) (-(⅟ A * B * ⅟ D)) 0 (⅟ D)) <| by
simp_rw [fromBlocks_multiply, Matrix.mul_zero, Matrix.zero_mul, zero_add, add_zero,
Matrix.neg_mul, invOf_mul_self, Matrix.mul_invOf_mul_self_cancel, add_right_neg,
fromBlocks_one]
#align matrix.from_blocks_zero₂₁_invertible Matrix.fromBlocksZero₂₁Invertible
/-- A lower-block-triangular matrix is invertible if its diagonal is. -/
def fromBlocksZero₁₂Invertible (A : Matrix m m α) (C : Matrix n m α) (D : Matrix n n α)
[Invertible A] [Invertible D] : Invertible (fromBlocks A 0 C D) :=
invertibleOfLeftInverse _
(fromBlocks (⅟ A) 0 (-(⅟ D * C * ⅟ A))
(⅟ D)) <| by -- a symmetry argument is more work than just copying the proof
simp_rw [fromBlocks_multiply, Matrix.mul_zero, Matrix.zero_mul, zero_add, add_zero,
Matrix.neg_mul, invOf_mul_self, Matrix.mul_invOf_mul_self_cancel, add_left_neg,
fromBlocks_one]
#align matrix.from_blocks_zero₁₂_invertible Matrix.fromBlocksZero₁₂Invertible
theorem invOf_fromBlocks_zero₂₁_eq (A : Matrix m m α) (B : Matrix m n α) (D : Matrix n n α)
[Invertible A] [Invertible D] [Invertible (fromBlocks A B 0 D)] :
⅟ (fromBlocks A B 0 D) = fromBlocks (⅟ A) (-(⅟ A * B * ⅟ D)) 0 (⅟ D) := by
letI := fromBlocksZero₂₁Invertible A B D
convert (rfl : ⅟ (fromBlocks A B 0 D) = _)
#align matrix.inv_of_from_blocks_zero₂₁_eq Matrix.invOf_fromBlocks_zero₂₁_eq
theorem invOf_fromBlocks_zero₁₂_eq (A : Matrix m m α) (C : Matrix n m α) (D : Matrix n n α)
[Invertible A] [Invertible D] [Invertible (fromBlocks A 0 C D)] :
⅟ (fromBlocks A 0 C D) = fromBlocks (⅟ A) 0 (-(⅟ D * C * ⅟ A)) (⅟ D) := by
letI := fromBlocksZero₁₂Invertible A C D
convert (rfl : ⅟ (fromBlocks A 0 C D) = _)
#align matrix.inv_of_from_blocks_zero₁₂_eq Matrix.invOf_fromBlocks_zero₁₂_eq
/-- Both diagonal entries of an invertible upper-block-triangular matrix are invertible (by reading
off the diagonal entries of the inverse). -/
def invertibleOfFromBlocksZero₂₁Invertible (A : Matrix m m α) (B : Matrix m n α) (D : Matrix n n α)
[Invertible (fromBlocks A B 0 D)] : Invertible A × Invertible D where
fst :=
invertibleOfLeftInverse _ (⅟ (fromBlocks A B 0 D)).toBlocks₁₁ <| by
have := invOf_mul_self (fromBlocks A B 0 D)
rw [← fromBlocks_toBlocks (⅟ (fromBlocks A B 0 D)), fromBlocks_multiply] at this
replace := congr_arg Matrix.toBlocks₁₁ this
simpa only [Matrix.toBlocks_fromBlocks₁₁, Matrix.mul_zero, add_zero, ← fromBlocks_one] using
this
snd :=
invertibleOfRightInverse _ (⅟ (fromBlocks A B 0 D)).toBlocks₂₂ <| by
have := mul_invOf_self (fromBlocks A B 0 D)
rw [← fromBlocks_toBlocks (⅟ (fromBlocks A B 0 D)), fromBlocks_multiply] at this
replace := congr_arg Matrix.toBlocks₂₂ this
simpa only [Matrix.toBlocks_fromBlocks₂₂, Matrix.zero_mul, zero_add, ← fromBlocks_one] using
this
#align matrix.invertible_of_from_blocks_zero₂₁_invertible Matrix.invertibleOfFromBlocksZero₂₁Invertible
/-- Both diagonal entries of an invertible lower-block-triangular matrix are invertible (by reading
off the diagonal entries of the inverse). -/
def invertibleOfFromBlocksZero₁₂Invertible (A : Matrix m m α) (C : Matrix n m α) (D : Matrix n n α)
[Invertible (fromBlocks A 0 C D)] : Invertible A × Invertible D where
fst :=
invertibleOfRightInverse _ (⅟ (fromBlocks A 0 C D)).toBlocks₁₁ <| by
have := mul_invOf_self (fromBlocks A 0 C D)
rw [← fromBlocks_toBlocks (⅟ (fromBlocks A 0 C D)), fromBlocks_multiply] at this
replace := congr_arg Matrix.toBlocks₁₁ this
simpa only [Matrix.toBlocks_fromBlocks₁₁, Matrix.zero_mul, add_zero, ← fromBlocks_one] using
this
snd :=
invertibleOfLeftInverse _ (⅟ (fromBlocks A 0 C D)).toBlocks₂₂ <| by
have := invOf_mul_self (fromBlocks A 0 C D)
rw [← fromBlocks_toBlocks (⅟ (fromBlocks A 0 C D)), fromBlocks_multiply] at this
replace := congr_arg Matrix.toBlocks₂₂ this
simpa only [Matrix.toBlocks_fromBlocks₂₂, Matrix.mul_zero, zero_add, ← fromBlocks_one] using
this
#align matrix.invertible_of_from_blocks_zero₁₂_invertible Matrix.invertibleOfFromBlocksZero₁₂Invertible
/-- `invertibleOfFromBlocksZero₂₁Invertible` and `Matrix.fromBlocksZero₂₁Invertible` form
an equivalence. -/
def fromBlocksZero₂₁InvertibleEquiv (A : Matrix m m α) (B : Matrix m n α) (D : Matrix n n α) :
Invertible (fromBlocks A B 0 D) ≃ Invertible A × Invertible D where
toFun _ := invertibleOfFromBlocksZero₂₁Invertible A B D
invFun i := by
letI := i.1
letI := i.2
exact fromBlocksZero₂₁Invertible A B D
left_inv _ := Subsingleton.elim _ _
right_inv _ := Subsingleton.elim _ _
#align matrix.from_blocks_zero₂₁_invertible_equiv Matrix.fromBlocksZero₂₁InvertibleEquiv
/-- `invertibleOfFromBlocksZero₁₂Invertible` and `Matrix.fromBlocksZero₁₂Invertible` form
an equivalence. -/
def fromBlocksZero₁₂InvertibleEquiv (A : Matrix m m α) (C : Matrix n m α) (D : Matrix n n α) :
Invertible (fromBlocks A 0 C D) ≃ Invertible A × Invertible D where
toFun _ := invertibleOfFromBlocksZero₁₂Invertible A C D
invFun i := by
letI := i.1
letI := i.2
exact fromBlocksZero₁₂Invertible A C D
left_inv _ := Subsingleton.elim _ _
right_inv _ := Subsingleton.elim _ _
#align matrix.from_blocks_zero₁₂_invertible_equiv Matrix.fromBlocksZero₁₂InvertibleEquiv
/-- An upper block-triangular matrix is invertible iff both elements of its diagonal are.
This is a propositional form of `Matrix.fromBlocksZero₂₁InvertibleEquiv`. -/
@[simp]
theorem isUnit_fromBlocks_zero₂₁ {A : Matrix m m α} {B : Matrix m n α} {D : Matrix n n α} :
IsUnit (fromBlocks A B 0 D) ↔ IsUnit A ∧ IsUnit D := by
simp only [← nonempty_invertible_iff_isUnit, ← nonempty_prod,
(fromBlocksZero₂₁InvertibleEquiv _ _ _).nonempty_congr]
#align matrix.is_unit_from_blocks_zero₂₁ Matrix.isUnit_fromBlocks_zero₂₁
/-- A lower block-triangular matrix is invertible iff both elements of its diagonal are.
This is a propositional form of `Matrix.fromBlocksZero₁₂InvertibleEquiv` forms an `iff`. -/
@[simp]
theorem isUnit_fromBlocks_zero₁₂ {A : Matrix m m α} {C : Matrix n m α} {D : Matrix n n α} :
IsUnit (fromBlocks A 0 C D) ↔ IsUnit A ∧ IsUnit D := by
simp only [← nonempty_invertible_iff_isUnit, ← nonempty_prod,
(fromBlocksZero₁₂InvertibleEquiv _ _ _).nonempty_congr]
#align matrix.is_unit_from_blocks_zero₁₂ Matrix.isUnit_fromBlocks_zero₁₂
/-- An expression for the inverse of an upper block-triangular matrix, when either both elements of
diagonal are invertible, or both are not. -/
theorem inv_fromBlocks_zero₂₁_of_isUnit_iff (A : Matrix m m α) (B : Matrix m n α) (D : Matrix n n α)
(hAD : IsUnit A ↔ IsUnit D) :
(fromBlocks A B 0 D)⁻¹ = fromBlocks A⁻¹ (-(A⁻¹ * B * D⁻¹)) 0 D⁻¹ := by
by_cases hA : IsUnit A
· have hD := hAD.mp hA
cases hA.nonempty_invertible
cases hD.nonempty_invertible
letI := fromBlocksZero₂₁Invertible A B D
simp_rw [← invOf_eq_nonsing_inv, invOf_fromBlocks_zero₂₁_eq]
· have hD := hAD.not.mp hA
have : ¬IsUnit (fromBlocks A B 0 D) :=
isUnit_fromBlocks_zero₂₁.not.mpr (not_and'.mpr fun _ => hA)
simp_rw [nonsing_inv_eq_ring_inverse, Ring.inverse_non_unit _ hA, Ring.inverse_non_unit _ hD,
Ring.inverse_non_unit _ this, Matrix.zero_mul, neg_zero, fromBlocks_zero]
#align matrix.inv_from_blocks_zero₂₁_of_is_unit_iff Matrix.inv_fromBlocks_zero₂₁_of_isUnit_iff
/-- An expression for the inverse of a lower block-triangular matrix, when either both elements of
diagonal are invertible, or both are not. -/
theorem inv_fromBlocks_zero₁₂_of_isUnit_iff (A : Matrix m m α) (C : Matrix n m α) (D : Matrix n n α)
(hAD : IsUnit A ↔ IsUnit D) :
(fromBlocks A 0 C D)⁻¹ = fromBlocks A⁻¹ 0 (-(D⁻¹ * C * A⁻¹)) D⁻¹ := by
by_cases hA : IsUnit A
· have hD := hAD.mp hA
cases hA.nonempty_invertible
cases hD.nonempty_invertible
letI := fromBlocksZero₁₂Invertible A C D
simp_rw [← invOf_eq_nonsing_inv, invOf_fromBlocks_zero₁₂_eq]
· have hD := hAD.not.mp hA
have : ¬IsUnit (fromBlocks A 0 C D) :=
isUnit_fromBlocks_zero₁₂.not.mpr (not_and'.mpr fun _ => hA)
simp_rw [nonsing_inv_eq_ring_inverse, Ring.inverse_non_unit _ hA, Ring.inverse_non_unit _ hD,
Ring.inverse_non_unit _ this, Matrix.zero_mul, neg_zero, fromBlocks_zero]
#align matrix.inv_from_blocks_zero₁₂_of_is_unit_iff Matrix.inv_fromBlocks_zero₁₂_of_isUnit_iff
end Triangular
/-! ### 2×2 block matrices -/
section Block
/-! #### General 2×2 block matrices-/
/-- A block matrix is invertible if the bottom right corner and the corresponding schur complement
is. -/
def fromBlocks₂₂Invertible (A : Matrix m m α) (B : Matrix m n α) (C : Matrix n m α)
(D : Matrix n n α) [Invertible D] [Invertible (A - B * ⅟ D * C)] :
Invertible (fromBlocks A B C D) := by
-- factor `fromBlocks` via `fromBlocks_eq_of_invertible₂₂`, and state the inverse we expect
convert Invertible.copy' _ _ (fromBlocks (⅟ (A - B * ⅟ D * C)) (-(⅟ (A - B * ⅟ D * C) * B * ⅟ D))
(-(⅟ D * C * ⅟ (A - B * ⅟ D * C))) (⅟ D + ⅟ D * C * ⅟ (A - B * ⅟ D * C) * B * ⅟ D))
(fromBlocks_eq_of_invertible₂₂ _ _ _ _) _
· -- the product is invertible because all the factors are
letI : Invertible (1 : Matrix n n α) := invertibleOne
letI : Invertible (1 : Matrix m m α) := invertibleOne
refine Invertible.mul ?_ (fromBlocksZero₁₂Invertible _ _ _)
exact
Invertible.mul (fromBlocksZero₂₁Invertible _ _ _)
(fromBlocksZero₂₁Invertible _ _ _)
· -- unfold the `Invertible` instances to get the raw factors
show
_ =
fromBlocks 1 0 (-(1 * (⅟ D * C) * 1)) 1 *
(fromBlocks (⅟ (A - B * ⅟ D * C)) (-(⅟ (A - B * ⅟ D * C) * 0 * ⅟ D)) 0 (⅟ D) *
fromBlocks 1 (-(1 * (B * ⅟ D) * 1)) 0 1)
-- combine into a single block matrix
simp only [fromBlocks_multiply, invOf_one, Matrix.one_mul, Matrix.mul_one, Matrix.zero_mul,
Matrix.mul_zero, add_zero, zero_add, neg_zero, Matrix.mul_neg, Matrix.neg_mul, neg_neg, ←
Matrix.mul_assoc, add_comm (⅟D)]
#align matrix.from_blocks₂₂_invertible Matrix.fromBlocks₂₂Invertible
/-- A block matrix is invertible if the top left corner and the corresponding schur complement
is. -/
def fromBlocks₁₁Invertible (A : Matrix m m α) (B : Matrix m n α) (C : Matrix n m α)
(D : Matrix n n α) [Invertible A] [Invertible (D - C * ⅟ A * B)] :
Invertible (fromBlocks A B C D) := by
-- we argue by symmetry
letI := fromBlocks₂₂Invertible D C B A
letI iDCBA :=
submatrixEquivInvertible (fromBlocks D C B A) (Equiv.sumComm _ _) (Equiv.sumComm _ _)
exact
iDCBA.copy' _
(fromBlocks (⅟ A + ⅟ A * B * ⅟ (D - C * ⅟ A * B) * C * ⅟ A) (-(⅟ A * B * ⅟ (D - C * ⅟ A * B)))
(-(⅟ (D - C * ⅟ A * B) * C * ⅟ A)) (⅟ (D - C * ⅟ A * B)))
(fromBlocks_submatrix_sum_swap_sum_swap _ _ _ _).symm
(fromBlocks_submatrix_sum_swap_sum_swap _ _ _ _).symm
#align matrix.from_blocks₁₁_invertible Matrix.fromBlocks₁₁Invertible
theorem invOf_fromBlocks₂₂_eq (A : Matrix m m α) (B : Matrix m n α) (C : Matrix n m α)
(D : Matrix n n α) [Invertible D] [Invertible (A - B * ⅟ D * C)]
[Invertible (fromBlocks A B C D)] :
⅟ (fromBlocks A B C D) =
fromBlocks (⅟ (A - B * ⅟ D * C)) (-(⅟ (A - B * ⅟ D * C) * B * ⅟ D))
(-(⅟ D * C * ⅟ (A - B * ⅟ D * C))) (⅟ D + ⅟ D * C * ⅟ (A - B * ⅟ D * C) * B * ⅟ D) := by
letI := fromBlocks₂₂Invertible A B C D
convert (rfl : ⅟ (fromBlocks A B C D) = _)
#align matrix.inv_of_from_blocks₂₂_eq Matrix.invOf_fromBlocks₂₂_eq
theorem invOf_fromBlocks₁₁_eq (A : Matrix m m α) (B : Matrix m n α) (C : Matrix n m α)
(D : Matrix n n α) [Invertible A] [Invertible (D - C * ⅟ A * B)]
[Invertible (fromBlocks A B C D)] :
⅟ (fromBlocks A B C D) =
fromBlocks (⅟ A + ⅟ A * B * ⅟ (D - C * ⅟ A * B) * C * ⅟ A) (-(⅟ A * B * ⅟ (D - C * ⅟ A * B)))
(-(⅟ (D - C * ⅟ A * B) * C * ⅟ A)) (⅟ (D - C * ⅟ A * B)) := by
letI := fromBlocks₁₁Invertible A B C D
convert (rfl : ⅟ (fromBlocks A B C D) = _)
#align matrix.inv_of_from_blocks₁₁_eq Matrix.invOf_fromBlocks₁₁_eq
/-- If a block matrix is invertible and so is its bottom left element, then so is the corresponding
Schur complement. -/
def invertibleOfFromBlocks₂₂Invertible (A : Matrix m m α) (B : Matrix m n α) (C : Matrix n m α)
(D : Matrix n n α) [Invertible D] [Invertible (fromBlocks A B C D)] :
Invertible (A - B * ⅟ D * C) := by
suffices Invertible (fromBlocks (A - B * ⅟ D * C) 0 0 D) by
exact (invertibleOfFromBlocksZero₁₂Invertible (A - B * ⅟ D * C) 0 D).1
letI : Invertible (1 : Matrix n n α) := invertibleOne
letI : Invertible (1 : Matrix m m α) := invertibleOne
letI iDC : Invertible (fromBlocks 1 0 (⅟ D * C) 1 : Matrix (Sum m n) (Sum m n) α) :=
fromBlocksZero₁₂Invertible _ _ _
letI iBD : Invertible (fromBlocks 1 (B * ⅟ D) 0 1 : Matrix (Sum m n) (Sum m n) α) :=
fromBlocksZero₂₁Invertible _ _ _
letI iBDC := Invertible.copy ‹_› _ (fromBlocks_eq_of_invertible₂₂ A B C D).symm
refine (iBD.mulLeft _).symm ?_
exact (iDC.mulRight _).symm iBDC
#align matrix.invertible_of_from_blocks₂₂_invertible Matrix.invertibleOfFromBlocks₂₂Invertible
/-- If a block matrix is invertible and so is its bottom left element, then so is the corresponding
Schur complement. -/
def invertibleOfFromBlocks₁₁Invertible (A : Matrix m m α) (B : Matrix m n α) (C : Matrix n m α)
(D : Matrix n n α) [Invertible A] [Invertible (fromBlocks A B C D)] :
Invertible (D - C * ⅟ A * B) := by
-- another symmetry argument
letI iABCD' :=
submatrixEquivInvertible (fromBlocks A B C D) (Equiv.sumComm _ _) (Equiv.sumComm _ _)
letI iDCBA := iABCD'.copy _ (fromBlocks_submatrix_sum_swap_sum_swap _ _ _ _).symm
exact invertibleOfFromBlocks₂₂Invertible D C B A
#align matrix.invertible_of_from_blocks₁₁_invertible Matrix.invertibleOfFromBlocks₁₁Invertible
/-- `Matrix.invertibleOfFromBlocks₂₂Invertible` and `Matrix.fromBlocks₂₂Invertible` as an
equivalence. -/
def invertibleEquivFromBlocks₂₂Invertible (A : Matrix m m α) (B : Matrix m n α) (C : Matrix n m α)
(D : Matrix n n α) [Invertible D] :
Invertible (fromBlocks A B C D) ≃ Invertible (A - B * ⅟ D * C) where
toFun _iABCD := invertibleOfFromBlocks₂₂Invertible _ _ _ _
invFun _i_schur := fromBlocks₂₂Invertible _ _ _ _
left_inv _iABCD := Subsingleton.elim _ _
right_inv _i_schur := Subsingleton.elim _ _
#align matrix.invertible_equiv_from_blocks₂₂_invertible Matrix.invertibleEquivFromBlocks₂₂Invertible
/-- `Matrix.invertibleOfFromBlocks₁₁Invertible` and `Matrix.fromBlocks₁₁Invertible` as an
equivalence. -/
def invertibleEquivFromBlocks₁₁Invertible (A : Matrix m m α) (B : Matrix m n α) (C : Matrix n m α)
(D : Matrix n n α) [Invertible A] :
Invertible (fromBlocks A B C D) ≃ Invertible (D - C * ⅟ A * B) where
toFun _iABCD := invertibleOfFromBlocks₁₁Invertible _ _ _ _
invFun _i_schur := fromBlocks₁₁Invertible _ _ _ _
left_inv _iABCD := Subsingleton.elim _ _
right_inv _i_schur := Subsingleton.elim _ _
#align matrix.invertible_equiv_from_blocks₁₁_invertible Matrix.invertibleEquivFromBlocks₁₁Invertible
/-- If the bottom-left element of a block matrix is invertible, then the whole matrix is invertible
iff the corresponding schur complement is. -/
theorem isUnit_fromBlocks_iff_of_invertible₂₂ {A : Matrix m m α} {B : Matrix m n α}
{C : Matrix n m α} {D : Matrix n n α} [Invertible D] :
IsUnit (fromBlocks A B C D) ↔ IsUnit (A - B * ⅟ D * C) := by
simp only [← nonempty_invertible_iff_isUnit,
(invertibleEquivFromBlocks₂₂Invertible A B C D).nonempty_congr]
#align matrix.is_unit_from_blocks_iff_of_invertible₂₂ Matrix.isUnit_fromBlocks_iff_of_invertible₂₂
/-- If the top-right element of a block matrix is invertible, then the whole matrix is invertible
iff the corresponding schur complement is. -/
theorem isUnit_fromBlocks_iff_of_invertible₁₁ {A : Matrix m m α} {B : Matrix m n α}
{C : Matrix n m α} {D : Matrix n n α} [Invertible A] :
IsUnit (fromBlocks A B C D) ↔ IsUnit (D - C * ⅟ A * B) := by
simp only [← nonempty_invertible_iff_isUnit,
(invertibleEquivFromBlocks₁₁Invertible A B C D).nonempty_congr]
#align matrix.is_unit_from_blocks_iff_of_invertible₁₁ Matrix.isUnit_fromBlocks_iff_of_invertible₁₁
end Block
/-! ### Lemmas about `Matrix.det` -/
section Det
/-- Determinant of a 2×2 block matrix, expanded around an invertible top left element in terms of
the Schur complement. -/
theorem det_fromBlocks₁₁ (A : Matrix m m α) (B : Matrix m n α) (C : Matrix n m α)
(D : Matrix n n α) [Invertible A] :
(Matrix.fromBlocks A B C D).det = det A * det (D - C * ⅟ A * B) := by
rw [fromBlocks_eq_of_invertible₁₁ (A := A), det_mul, det_mul, det_fromBlocks_zero₂₁,
det_fromBlocks_zero₂₁, det_fromBlocks_zero₁₂, det_one, det_one, one_mul, one_mul, mul_one]
#align matrix.det_from_blocks₁₁ Matrix.det_fromBlocks₁₁
@[simp]
theorem det_fromBlocks_one₁₁ (B : Matrix m n α) (C : Matrix n m α) (D : Matrix n n α) :
(Matrix.fromBlocks 1 B C D).det = det (D - C * B) := by
haveI : Invertible (1 : Matrix m m α) := invertibleOne
rw [det_fromBlocks₁₁, invOf_one, Matrix.mul_one, det_one, one_mul]
#align matrix.det_from_blocks_one₁₁ Matrix.det_fromBlocks_one₁₁
/-- Determinant of a 2×2 block matrix, expanded around an invertible bottom right element in terms
of the Schur complement. -/
| Mathlib/LinearAlgebra/Matrix/SchurComplement.lean | 406 | 413 | theorem det_fromBlocks₂₂ (A : Matrix m m α) (B : Matrix m n α) (C : Matrix n m α)
(D : Matrix n n α) [Invertible D] :
(Matrix.fromBlocks A B C D).det = det D * det (A - B * ⅟ D * C) := by |
have : fromBlocks A B C D =
(fromBlocks D C B A).submatrix (Equiv.sumComm _ _) (Equiv.sumComm _ _) := by
ext (i j)
cases i <;> cases j <;> rfl
rw [this, det_submatrix_equiv_self, det_fromBlocks₁₁]
|
/-
Copyright (c) 2015 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura, Mario Carneiro
-/
import Mathlib.Data.FunLike.Equiv
import Mathlib.Data.Quot
import Mathlib.Init.Data.Bool.Lemmas
import Mathlib.Logic.Unique
import Mathlib.Tactic.Substs
import Mathlib.Tactic.Conv
#align_import logic.equiv.defs from "leanprover-community/mathlib"@"48fb5b5280e7c81672afc9524185ae994553ebf4"
/-!
# Equivalence between types
In this file we define two types:
* `Equiv α β` a.k.a. `α ≃ β`: a bijective map `α → β` bundled with its inverse map; we use this (and
not equality!) to express that various `Type`s or `Sort`s are equivalent.
* `Equiv.Perm α`: the group of permutations `α ≃ α`. More lemmas about `Equiv.Perm` can be found in
`GroupTheory.Perm`.
Then we define
* canonical isomorphisms between various types: e.g.,
- `Equiv.refl α` is the identity map interpreted as `α ≃ α`;
* operations on equivalences: e.g.,
- `Equiv.symm e : β ≃ α` is the inverse of `e : α ≃ β`;
- `Equiv.trans e₁ e₂ : α ≃ γ` is the composition of `e₁ : α ≃ β` and `e₂ : β ≃ γ` (note the order
of the arguments!);
* definitions that transfer some instances along an equivalence. By convention, we transfer
instances from right to left.
- `Equiv.inhabited` takes `e : α ≃ β` and `[Inhabited β]` and returns `Inhabited α`;
- `Equiv.unique` takes `e : α ≃ β` and `[Unique β]` and returns `Unique α`;
- `Equiv.decidableEq` takes `e : α ≃ β` and `[DecidableEq β]` and returns `DecidableEq α`.
More definitions of this kind can be found in other files. E.g., `Data.Equiv.TransferInstance`
does it for many algebraic type classes like `Group`, `Module`, etc.
Many more such isomorphisms and operations are defined in `Logic.Equiv.Basic`.
## Tags
equivalence, congruence, bijective map
-/
open Function
universe u v w z
variable {α : Sort u} {β : Sort v} {γ : Sort w}
/-- `α ≃ β` is the type of functions from `α → β` with a two-sided inverse. -/
structure Equiv (α : Sort*) (β : Sort _) where
protected toFun : α → β
protected invFun : β → α
protected left_inv : LeftInverse invFun toFun
protected right_inv : RightInverse invFun toFun
#align equiv Equiv
@[inherit_doc]
infixl:25 " ≃ " => Equiv
/-- Turn an element of a type `F` satisfying `EquivLike F α β` into an actual
`Equiv`. This is declared as the default coercion from `F` to `α ≃ β`. -/
@[coe]
def EquivLike.toEquiv {F} [EquivLike F α β] (f : F) : α ≃ β where
toFun := f
invFun := EquivLike.inv f
left_inv := EquivLike.left_inv f
right_inv := EquivLike.right_inv f
/-- Any type satisfying `EquivLike` can be cast into `Equiv` via `EquivLike.toEquiv`. -/
instance {F} [EquivLike F α β] : CoeTC F (α ≃ β) :=
⟨EquivLike.toEquiv⟩
/-- `Perm α` is the type of bijections from `α` to itself. -/
abbrev Equiv.Perm (α : Sort*) :=
Equiv α α
#align equiv.perm Equiv.Perm
namespace Equiv
instance : EquivLike (α ≃ β) α β where
coe := Equiv.toFun
inv := Equiv.invFun
left_inv := Equiv.left_inv
right_inv := Equiv.right_inv
coe_injective' e₁ e₂ h₁ h₂ := by cases e₁; cases e₂; congr
/-- Helper instance when inference gets stuck on following the normal chain
`EquivLike → FunLike`.
TODO: this instance doesn't appear to be necessary: remove it (after benchmarking?)
-/
instance : FunLike (α ≃ β) α β where
coe := Equiv.toFun
coe_injective' := DFunLike.coe_injective
@[simp, norm_cast]
lemma _root_.EquivLike.coe_coe {F} [EquivLike F α β] (e : F) :
((e : α ≃ β) : α → β) = e := rfl
@[simp] theorem coe_fn_mk (f : α → β) (g l r) : (Equiv.mk f g l r : α → β) = f :=
rfl
#align equiv.coe_fn_mk Equiv.coe_fn_mk
/-- The map `(r ≃ s) → (r → s)` is injective. -/
theorem coe_fn_injective : @Function.Injective (α ≃ β) (α → β) (fun e => e) :=
DFunLike.coe_injective'
#align equiv.coe_fn_injective Equiv.coe_fn_injective
protected theorem coe_inj {e₁ e₂ : α ≃ β} : (e₁ : α → β) = e₂ ↔ e₁ = e₂ :=
@DFunLike.coe_fn_eq _ _ _ _ e₁ e₂
#align equiv.coe_inj Equiv.coe_inj
@[ext] theorem ext {f g : Equiv α β} (H : ∀ x, f x = g x) : f = g := DFunLike.ext f g H
#align equiv.ext Equiv.ext
protected theorem congr_arg {f : Equiv α β} {x x' : α} : x = x' → f x = f x' :=
DFunLike.congr_arg f
#align equiv.congr_arg Equiv.congr_arg
protected theorem congr_fun {f g : Equiv α β} (h : f = g) (x : α) : f x = g x :=
DFunLike.congr_fun h x
#align equiv.congr_fun Equiv.congr_fun
theorem ext_iff {f g : Equiv α β} : f = g ↔ ∀ x, f x = g x := DFunLike.ext_iff
#align equiv.ext_iff Equiv.ext_iff
@[ext] theorem Perm.ext {σ τ : Equiv.Perm α} (H : ∀ x, σ x = τ x) : σ = τ := Equiv.ext H
#align equiv.perm.ext Equiv.Perm.ext
protected theorem Perm.congr_arg {f : Equiv.Perm α} {x x' : α} : x = x' → f x = f x' :=
Equiv.congr_arg
#align equiv.perm.congr_arg Equiv.Perm.congr_arg
protected theorem Perm.congr_fun {f g : Equiv.Perm α} (h : f = g) (x : α) : f x = g x :=
Equiv.congr_fun h x
#align equiv.perm.congr_fun Equiv.Perm.congr_fun
theorem Perm.ext_iff {σ τ : Equiv.Perm α} : σ = τ ↔ ∀ x, σ x = τ x := Equiv.ext_iff
#align equiv.perm.ext_iff Equiv.Perm.ext_iff
/-- Any type is equivalent to itself. -/
@[refl] protected def refl (α : Sort*) : α ≃ α := ⟨id, id, fun _ => rfl, fun _ => rfl⟩
#align equiv.refl Equiv.refl
instance inhabited' : Inhabited (α ≃ α) := ⟨Equiv.refl α⟩
/-- Inverse of an equivalence `e : α ≃ β`. -/
@[symm]
protected def symm (e : α ≃ β) : β ≃ α := ⟨e.invFun, e.toFun, e.right_inv, e.left_inv⟩
#align equiv.symm Equiv.symm
/-- See Note [custom simps projection] -/
def Simps.symm_apply (e : α ≃ β) : β → α := e.symm
#align equiv.simps.symm_apply Equiv.Simps.symm_apply
initialize_simps_projections Equiv (toFun → apply, invFun → symm_apply)
-- Porting note:
-- Added these lemmas as restatements of `left_inv` and `right_inv`,
-- which use the coercions.
-- We might even consider switching the names, and having these as a public API.
theorem left_inv' (e : α ≃ β) : Function.LeftInverse e.symm e := e.left_inv
theorem right_inv' (e : α ≃ β) : Function.RightInverse e.symm e := e.right_inv
/-- Composition of equivalences `e₁ : α ≃ β` and `e₂ : β ≃ γ`. -/
@[trans]
protected def trans (e₁ : α ≃ β) (e₂ : β ≃ γ) : α ≃ γ :=
⟨e₂ ∘ e₁, e₁.symm ∘ e₂.symm, e₂.left_inv.comp e₁.left_inv, e₂.right_inv.comp e₁.right_inv⟩
#align equiv.trans Equiv.trans
@[simps]
instance : Trans Equiv Equiv Equiv where
trans := Equiv.trans
-- Porting note: this is not a syntactic tautology any more because
-- the coercion from `e` to a function is now `DFunLike.coe` not `e.toFun`
@[simp, mfld_simps] theorem toFun_as_coe (e : α ≃ β) : e.toFun = e := rfl
#align equiv.to_fun_as_coe Equiv.toFun_as_coe
@[simp, mfld_simps] theorem invFun_as_coe (e : α ≃ β) : e.invFun = e.symm := rfl
#align equiv.inv_fun_as_coe Equiv.invFun_as_coe
protected theorem injective (e : α ≃ β) : Injective e := EquivLike.injective e
#align equiv.injective Equiv.injective
protected theorem surjective (e : α ≃ β) : Surjective e := EquivLike.surjective e
#align equiv.surjective Equiv.surjective
protected theorem bijective (e : α ≃ β) : Bijective e := EquivLike.bijective e
#align equiv.bijective Equiv.bijective
protected theorem subsingleton (e : α ≃ β) [Subsingleton β] : Subsingleton α :=
e.injective.subsingleton
#align equiv.subsingleton Equiv.subsingleton
protected theorem subsingleton.symm (e : α ≃ β) [Subsingleton α] : Subsingleton β :=
e.symm.injective.subsingleton
#align equiv.subsingleton.symm Equiv.subsingleton.symm
theorem subsingleton_congr (e : α ≃ β) : Subsingleton α ↔ Subsingleton β :=
⟨fun _ => e.symm.subsingleton, fun _ => e.subsingleton⟩
#align equiv.subsingleton_congr Equiv.subsingleton_congr
instance equiv_subsingleton_cod [Subsingleton β] : Subsingleton (α ≃ β) :=
⟨fun _ _ => Equiv.ext fun _ => Subsingleton.elim _ _⟩
instance equiv_subsingleton_dom [Subsingleton α] : Subsingleton (α ≃ β) :=
⟨fun f _ => Equiv.ext fun _ => @Subsingleton.elim _ (Equiv.subsingleton.symm f) _ _⟩
instance permUnique [Subsingleton α] : Unique (Perm α) :=
uniqueOfSubsingleton (Equiv.refl α)
theorem Perm.subsingleton_eq_refl [Subsingleton α] (e : Perm α) : e = Equiv.refl α :=
Subsingleton.elim _ _
#align equiv.perm.subsingleton_eq_refl Equiv.Perm.subsingleton_eq_refl
/-- Transfer `DecidableEq` across an equivalence. -/
protected def decidableEq (e : α ≃ β) [DecidableEq β] : DecidableEq α :=
e.injective.decidableEq
#align equiv.decidable_eq Equiv.decidableEq
theorem nonempty_congr (e : α ≃ β) : Nonempty α ↔ Nonempty β := Nonempty.congr e e.symm
#align equiv.nonempty_congr Equiv.nonempty_congr
protected theorem nonempty (e : α ≃ β) [Nonempty β] : Nonempty α := e.nonempty_congr.mpr ‹_›
#align equiv.nonempty Equiv.nonempty
/-- If `α ≃ β` and `β` is inhabited, then so is `α`. -/
protected def inhabited [Inhabited β] (e : α ≃ β) : Inhabited α := ⟨e.symm default⟩
#align equiv.inhabited Equiv.inhabited
/-- If `α ≃ β` and `β` is a singleton type, then so is `α`. -/
protected def unique [Unique β] (e : α ≃ β) : Unique α := e.symm.surjective.unique
#align equiv.unique Equiv.unique
/-- Equivalence between equal types. -/
protected def cast {α β : Sort _} (h : α = β) : α ≃ β :=
⟨cast h, cast h.symm, fun _ => by cases h; rfl, fun _ => by cases h; rfl⟩
#align equiv.cast Equiv.cast
@[simp] theorem coe_fn_symm_mk (f : α → β) (g l r) : ((Equiv.mk f g l r).symm : β → α) = g := rfl
#align equiv.coe_fn_symm_mk Equiv.coe_fn_symm_mk
@[simp] theorem coe_refl : (Equiv.refl α : α → α) = id := rfl
#align equiv.coe_refl Equiv.coe_refl
/-- This cannot be a `simp` lemmas as it incorrectly matches against `e : α ≃ synonym α`, when
`synonym α` is semireducible. This makes a mess of `Multiplicative.ofAdd` etc. -/
theorem Perm.coe_subsingleton {α : Type*} [Subsingleton α] (e : Perm α) : (e : α → α) = id := by
rw [Perm.subsingleton_eq_refl e, coe_refl]
#align equiv.perm.coe_subsingleton Equiv.Perm.coe_subsingleton
-- Porting note: marking this as `@[simp]` because `simp` doesn't fire on `coe_refl`
-- in an expression such as `Equiv.refl a x`
@[simp] theorem refl_apply (x : α) : Equiv.refl α x = x := rfl
#align equiv.refl_apply Equiv.refl_apply
@[simp] theorem coe_trans (f : α ≃ β) (g : β ≃ γ) : (f.trans g : α → γ) = g ∘ f := rfl
#align equiv.coe_trans Equiv.coe_trans
-- Porting note: marking this as `@[simp]` because `simp` doesn't fire on `coe_trans`
-- in an expression such as `Equiv.trans f g x`
@[simp] theorem trans_apply (f : α ≃ β) (g : β ≃ γ) (a : α) : (f.trans g) a = g (f a) := rfl
#align equiv.trans_apply Equiv.trans_apply
@[simp] theorem apply_symm_apply (e : α ≃ β) (x : β) : e (e.symm x) = x := e.right_inv x
#align equiv.apply_symm_apply Equiv.apply_symm_apply
@[simp] theorem symm_apply_apply (e : α ≃ β) (x : α) : e.symm (e x) = x := e.left_inv x
#align equiv.symm_apply_apply Equiv.symm_apply_apply
@[simp] theorem symm_comp_self (e : α ≃ β) : e.symm ∘ e = id := funext e.symm_apply_apply
#align equiv.symm_comp_self Equiv.symm_comp_self
@[simp] theorem self_comp_symm (e : α ≃ β) : e ∘ e.symm = id := funext e.apply_symm_apply
#align equiv.self_comp_symm Equiv.self_comp_symm
@[simp] lemma _root_.EquivLike.apply_coe_symm_apply {F} [EquivLike F α β] (e : F) (x : β) :
e ((e : α ≃ β).symm x) = x :=
(e : α ≃ β).apply_symm_apply x
@[simp] lemma _root_.EquivLike.coe_symm_apply_apply {F} [EquivLike F α β] (e : F) (x : α) :
(e : α ≃ β).symm (e x) = x :=
(e : α ≃ β).symm_apply_apply x
@[simp] lemma _root_.EquivLike.coe_symm_comp_self {F} [EquivLike F α β] (e : F) :
(e : α ≃ β).symm ∘ e = id :=
(e : α ≃ β).symm_comp_self
@[simp] lemma _root_.EquivLike.self_comp_coe_symm {F} [EquivLike F α β] (e : F) :
e ∘ (e : α ≃ β).symm = id :=
(e : α ≃ β).self_comp_symm
@[simp] theorem symm_trans_apply (f : α ≃ β) (g : β ≃ γ) (a : γ) :
(f.trans g).symm a = f.symm (g.symm a) := rfl
#align equiv.symm_trans_apply Equiv.symm_trans_apply
-- The `simp` attribute is needed to make this a `dsimp` lemma.
-- `simp` will always rewrite with `Equiv.symm_symm` before this has a chance to fire.
@[simp, nolint simpNF] theorem symm_symm_apply (f : α ≃ β) (b : α) : f.symm.symm b = f b := rfl
#align equiv.symm_symm_apply Equiv.symm_symm_apply
theorem apply_eq_iff_eq (f : α ≃ β) {x y : α} : f x = f y ↔ x = y := EquivLike.apply_eq_iff_eq f
#align equiv.apply_eq_iff_eq Equiv.apply_eq_iff_eq
theorem apply_eq_iff_eq_symm_apply {x : α} {y : β} (f : α ≃ β) : f x = y ↔ x = f.symm y := by
conv_lhs => rw [← apply_symm_apply f y]
rw [apply_eq_iff_eq]
#align equiv.apply_eq_iff_eq_symm_apply Equiv.apply_eq_iff_eq_symm_apply
@[simp] theorem cast_apply {α β} (h : α = β) (x : α) : Equiv.cast h x = cast h x := rfl
#align equiv.cast_apply Equiv.cast_apply
@[simp] theorem cast_symm {α β} (h : α = β) : (Equiv.cast h).symm = Equiv.cast h.symm := rfl
#align equiv.cast_symm Equiv.cast_symm
@[simp] theorem cast_refl {α} (h : α = α := rfl) : Equiv.cast h = Equiv.refl α := rfl
#align equiv.cast_refl Equiv.cast_refl
@[simp] theorem cast_trans {α β γ} (h : α = β) (h2 : β = γ) :
(Equiv.cast h).trans (Equiv.cast h2) = Equiv.cast (h.trans h2) :=
ext fun x => by substs h h2; rfl
#align equiv.cast_trans Equiv.cast_trans
| Mathlib/Logic/Equiv/Defs.lean | 338 | 339 | theorem cast_eq_iff_heq {α β} (h : α = β) {a : α} {b : β} : Equiv.cast h a = b ↔ HEq a b := by |
subst h; simp [coe_refl]
|
/-
Copyright (c) 2019 Zhouhang Zhou. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Zhouhang Zhou, Yury Kudryashov, Sébastien Gouëzel, Rémy Degenne
-/
import Mathlib.MeasureTheory.Integral.SetToL1
#align_import measure_theory.integral.bochner from "leanprover-community/mathlib"@"48fb5b5280e7c81672afc9524185ae994553ebf4"
/-!
# Bochner integral
The Bochner integral extends the definition of the Lebesgue integral to functions that map from a
measure space into a Banach space (complete normed vector space). It is constructed here by
extending the integral on simple functions.
## Main definitions
The Bochner integral is defined through the extension process described in the file `SetToL1`,
which follows these steps:
1. Define the integral of the indicator of a set. This is `weightedSMul μ s x = (μ s).toReal * x`.
`weightedSMul μ` is shown to be linear in the value `x` and `DominatedFinMeasAdditive`
(defined in the file `SetToL1`) with respect to the set `s`.
2. Define the integral on simple functions of the type `SimpleFunc α E` (notation : `α →ₛ E`)
where `E` is a real normed space. (See `SimpleFunc.integral` for details.)
3. Transfer this definition to define the integral on `L1.simpleFunc α E` (notation :
`α →₁ₛ[μ] E`), see `L1.simpleFunc.integral`. Show that this integral is a continuous linear
map from `α →₁ₛ[μ] E` to `E`.
4. Define the Bochner integral on L1 functions by extending the integral on integrable simple
functions `α →₁ₛ[μ] E` using `ContinuousLinearMap.extend` and the fact that the embedding of
`α →₁ₛ[μ] E` into `α →₁[μ] E` is dense.
5. Define the Bochner integral on functions as the Bochner integral of its equivalence class in L1
space, if it is in L1, and 0 otherwise.
The result of that construction is `∫ a, f a ∂μ`, which is definitionally equal to
`setToFun (dominatedFinMeasAdditive_weightedSMul μ) f`. Some basic properties of the integral
(like linearity) are particular cases of the properties of `setToFun` (which are described in the
file `SetToL1`).
## Main statements
1. Basic properties of the Bochner integral on functions of type `α → E`, where `α` is a measure
space and `E` is a real normed space.
* `integral_zero` : `∫ 0 ∂μ = 0`
* `integral_add` : `∫ x, f x + g x ∂μ = ∫ x, f ∂μ + ∫ x, g x ∂μ`
* `integral_neg` : `∫ x, - f x ∂μ = - ∫ x, f x ∂μ`
* `integral_sub` : `∫ x, f x - g x ∂μ = ∫ x, f x ∂μ - ∫ x, g x ∂μ`
* `integral_smul` : `∫ x, r • f x ∂μ = r • ∫ x, f x ∂μ`
* `integral_congr_ae` : `f =ᵐ[μ] g → ∫ x, f x ∂μ = ∫ x, g x ∂μ`
* `norm_integral_le_integral_norm` : `‖∫ x, f x ∂μ‖ ≤ ∫ x, ‖f x‖ ∂μ`
2. Basic properties of the Bochner integral on functions of type `α → ℝ`, where `α` is a measure
space.
* `integral_nonneg_of_ae` : `0 ≤ᵐ[μ] f → 0 ≤ ∫ x, f x ∂μ`
* `integral_nonpos_of_ae` : `f ≤ᵐ[μ] 0 → ∫ x, f x ∂μ ≤ 0`
* `integral_mono_ae` : `f ≤ᵐ[μ] g → ∫ x, f x ∂μ ≤ ∫ x, g x ∂μ`
* `integral_nonneg` : `0 ≤ f → 0 ≤ ∫ x, f x ∂μ`
* `integral_nonpos` : `f ≤ 0 → ∫ x, f x ∂μ ≤ 0`
* `integral_mono` : `f ≤ᵐ[μ] g → ∫ x, f x ∂μ ≤ ∫ x, g x ∂μ`
3. Propositions connecting the Bochner integral with the integral on `ℝ≥0∞`-valued functions,
which is called `lintegral` and has the notation `∫⁻`.
* `integral_eq_lintegral_pos_part_sub_lintegral_neg_part` :
`∫ x, f x ∂μ = ∫⁻ x, f⁺ x ∂μ - ∫⁻ x, f⁻ x ∂μ`,
where `f⁺` is the positive part of `f` and `f⁻` is the negative part of `f`.
* `integral_eq_lintegral_of_nonneg_ae` : `0 ≤ᵐ[μ] f → ∫ x, f x ∂μ = ∫⁻ x, f x ∂μ`
4. (In the file `DominatedConvergence`)
`tendsto_integral_of_dominated_convergence` : the Lebesgue dominated convergence theorem
5. (In the file `SetIntegral`) integration commutes with continuous linear maps.
* `ContinuousLinearMap.integral_comp_comm`
* `LinearIsometry.integral_comp_comm`
## Notes
Some tips on how to prove a proposition if the API for the Bochner integral is not enough so that
you need to unfold the definition of the Bochner integral and go back to simple functions.
One method is to use the theorem `Integrable.induction` in the file `SimpleFuncDenseLp` (or one
of the related results, like `Lp.induction` for functions in `Lp`), which allows you to prove
something for an arbitrary integrable function.
Another method is using the following steps.
See `integral_eq_lintegral_pos_part_sub_lintegral_neg_part` for a complicated example, which proves
that `∫ f = ∫⁻ f⁺ - ∫⁻ f⁻`, with the first integral sign being the Bochner integral of a real-valued
function `f : α → ℝ`, and second and third integral sign being the integral on `ℝ≥0∞`-valued
functions (called `lintegral`). The proof of `integral_eq_lintegral_pos_part_sub_lintegral_neg_part`
is scattered in sections with the name `posPart`.
Here are the usual steps of proving that a property `p`, say `∫ f = ∫⁻ f⁺ - ∫⁻ f⁻`, holds for all
functions :
1. First go to the `L¹` space.
For example, if you see `ENNReal.toReal (∫⁻ a, ENNReal.ofReal <| ‖f a‖)`, that is the norm of
`f` in `L¹` space. Rewrite using `L1.norm_of_fun_eq_lintegral_norm`.
2. Show that the set `{f ∈ L¹ | ∫ f = ∫⁻ f⁺ - ∫⁻ f⁻}` is closed in `L¹` using `isClosed_eq`.
3. Show that the property holds for all simple functions `s` in `L¹` space.
Typically, you need to convert various notions to their `SimpleFunc` counterpart, using lemmas
like `L1.integral_coe_eq_integral`.
4. Since simple functions are dense in `L¹`,
```
univ = closure {s simple}
= closure {s simple | ∫ s = ∫⁻ s⁺ - ∫⁻ s⁻} : the property holds for all simple functions
⊆ closure {f | ∫ f = ∫⁻ f⁺ - ∫⁻ f⁻}
= {f | ∫ f = ∫⁻ f⁺ - ∫⁻ f⁻} : closure of a closed set is itself
```
Use `isClosed_property` or `DenseRange.induction_on` for this argument.
## Notations
* `α →ₛ E` : simple functions (defined in `MeasureTheory/Integration`)
* `α →₁[μ] E` : functions in L1 space, i.e., equivalence classes of integrable functions (defined in
`MeasureTheory/LpSpace`)
* `α →₁ₛ[μ] E` : simple functions in L1 space, i.e., equivalence classes of integrable simple
functions (defined in `MeasureTheory/SimpleFuncDense`)
* `∫ a, f a ∂μ` : integral of `f` with respect to a measure `μ`
* `∫ a, f a` : integral of `f` with respect to `volume`, the default measure on the ambient type
We also define notations for integral on a set, which are described in the file
`MeasureTheory/SetIntegral`.
Note : `ₛ` is typed using `\_s`. Sometimes it shows as a box if the font is missing.
## Tags
Bochner integral, simple function, function space, Lebesgue dominated convergence theorem
-/
assert_not_exists Differentiable
noncomputable section
open scoped Topology NNReal ENNReal MeasureTheory
open Set Filter TopologicalSpace ENNReal EMetric
namespace MeasureTheory
variable {α E F 𝕜 : Type*}
section WeightedSMul
open ContinuousLinearMap
variable [NormedAddCommGroup F] [NormedSpace ℝ F] {m : MeasurableSpace α} {μ : Measure α}
/-- Given a set `s`, return the continuous linear map `fun x => (μ s).toReal • x`. The extension
of that set function through `setToL1` gives the Bochner integral of L1 functions. -/
def weightedSMul {_ : MeasurableSpace α} (μ : Measure α) (s : Set α) : F →L[ℝ] F :=
(μ s).toReal • ContinuousLinearMap.id ℝ F
#align measure_theory.weighted_smul MeasureTheory.weightedSMul
theorem weightedSMul_apply {m : MeasurableSpace α} (μ : Measure α) (s : Set α) (x : F) :
weightedSMul μ s x = (μ s).toReal • x := by simp [weightedSMul]
#align measure_theory.weighted_smul_apply MeasureTheory.weightedSMul_apply
@[simp]
theorem weightedSMul_zero_measure {m : MeasurableSpace α} :
weightedSMul (0 : Measure α) = (0 : Set α → F →L[ℝ] F) := by ext1; simp [weightedSMul]
#align measure_theory.weighted_smul_zero_measure MeasureTheory.weightedSMul_zero_measure
@[simp]
theorem weightedSMul_empty {m : MeasurableSpace α} (μ : Measure α) :
weightedSMul μ ∅ = (0 : F →L[ℝ] F) := by ext1 x; rw [weightedSMul_apply]; simp
#align measure_theory.weighted_smul_empty MeasureTheory.weightedSMul_empty
theorem weightedSMul_add_measure {m : MeasurableSpace α} (μ ν : Measure α) {s : Set α}
(hμs : μ s ≠ ∞) (hνs : ν s ≠ ∞) :
(weightedSMul (μ + ν) s : F →L[ℝ] F) = weightedSMul μ s + weightedSMul ν s := by
ext1 x
push_cast
simp_rw [Pi.add_apply, weightedSMul_apply]
push_cast
rw [Pi.add_apply, ENNReal.toReal_add hμs hνs, add_smul]
#align measure_theory.weighted_smul_add_measure MeasureTheory.weightedSMul_add_measure
theorem weightedSMul_smul_measure {m : MeasurableSpace α} (μ : Measure α) (c : ℝ≥0∞) {s : Set α} :
(weightedSMul (c • μ) s : F →L[ℝ] F) = c.toReal • weightedSMul μ s := by
ext1 x
push_cast
simp_rw [Pi.smul_apply, weightedSMul_apply]
push_cast
simp_rw [Pi.smul_apply, smul_eq_mul, toReal_mul, smul_smul]
#align measure_theory.weighted_smul_smul_measure MeasureTheory.weightedSMul_smul_measure
theorem weightedSMul_congr (s t : Set α) (hst : μ s = μ t) :
(weightedSMul μ s : F →L[ℝ] F) = weightedSMul μ t := by
ext1 x; simp_rw [weightedSMul_apply]; congr 2
#align measure_theory.weighted_smul_congr MeasureTheory.weightedSMul_congr
theorem weightedSMul_null {s : Set α} (h_zero : μ s = 0) : (weightedSMul μ s : F →L[ℝ] F) = 0 := by
ext1 x; rw [weightedSMul_apply, h_zero]; simp
#align measure_theory.weighted_smul_null MeasureTheory.weightedSMul_null
theorem weightedSMul_union' (s t : Set α) (ht : MeasurableSet t) (hs_finite : μ s ≠ ∞)
(ht_finite : μ t ≠ ∞) (h_inter : s ∩ t = ∅) :
(weightedSMul μ (s ∪ t) : F →L[ℝ] F) = weightedSMul μ s + weightedSMul μ t := by
ext1 x
simp_rw [add_apply, weightedSMul_apply,
measure_union (Set.disjoint_iff_inter_eq_empty.mpr h_inter) ht,
ENNReal.toReal_add hs_finite ht_finite, add_smul]
#align measure_theory.weighted_smul_union' MeasureTheory.weightedSMul_union'
@[nolint unusedArguments]
theorem weightedSMul_union (s t : Set α) (_hs : MeasurableSet s) (ht : MeasurableSet t)
(hs_finite : μ s ≠ ∞) (ht_finite : μ t ≠ ∞) (h_inter : s ∩ t = ∅) :
(weightedSMul μ (s ∪ t) : F →L[ℝ] F) = weightedSMul μ s + weightedSMul μ t :=
weightedSMul_union' s t ht hs_finite ht_finite h_inter
#align measure_theory.weighted_smul_union MeasureTheory.weightedSMul_union
theorem weightedSMul_smul [NormedField 𝕜] [NormedSpace 𝕜 F] [SMulCommClass ℝ 𝕜 F] (c : 𝕜)
(s : Set α) (x : F) : weightedSMul μ s (c • x) = c • weightedSMul μ s x := by
simp_rw [weightedSMul_apply, smul_comm]
#align measure_theory.weighted_smul_smul MeasureTheory.weightedSMul_smul
theorem norm_weightedSMul_le (s : Set α) : ‖(weightedSMul μ s : F →L[ℝ] F)‖ ≤ (μ s).toReal :=
calc
‖(weightedSMul μ s : F →L[ℝ] F)‖ = ‖(μ s).toReal‖ * ‖ContinuousLinearMap.id ℝ F‖ :=
norm_smul (μ s).toReal (ContinuousLinearMap.id ℝ F)
_ ≤ ‖(μ s).toReal‖ :=
((mul_le_mul_of_nonneg_left norm_id_le (norm_nonneg _)).trans (mul_one _).le)
_ = abs (μ s).toReal := Real.norm_eq_abs _
_ = (μ s).toReal := abs_eq_self.mpr ENNReal.toReal_nonneg
#align measure_theory.norm_weighted_smul_le MeasureTheory.norm_weightedSMul_le
theorem dominatedFinMeasAdditive_weightedSMul {_ : MeasurableSpace α} (μ : Measure α) :
DominatedFinMeasAdditive μ (weightedSMul μ : Set α → F →L[ℝ] F) 1 :=
⟨weightedSMul_union, fun s _ _ => (norm_weightedSMul_le s).trans (one_mul _).symm.le⟩
#align measure_theory.dominated_fin_meas_additive_weighted_smul MeasureTheory.dominatedFinMeasAdditive_weightedSMul
theorem weightedSMul_nonneg (s : Set α) (x : ℝ) (hx : 0 ≤ x) : 0 ≤ weightedSMul μ s x := by
simp only [weightedSMul, Algebra.id.smul_eq_mul, coe_smul', _root_.id, coe_id', Pi.smul_apply]
exact mul_nonneg toReal_nonneg hx
#align measure_theory.weighted_smul_nonneg MeasureTheory.weightedSMul_nonneg
end WeightedSMul
local infixr:25 " →ₛ " => SimpleFunc
namespace SimpleFunc
section PosPart
variable [LinearOrder E] [Zero E] [MeasurableSpace α]
/-- Positive part of a simple function. -/
def posPart (f : α →ₛ E) : α →ₛ E :=
f.map fun b => max b 0
#align measure_theory.simple_func.pos_part MeasureTheory.SimpleFunc.posPart
/-- Negative part of a simple function. -/
def negPart [Neg E] (f : α →ₛ E) : α →ₛ E :=
posPart (-f)
#align measure_theory.simple_func.neg_part MeasureTheory.SimpleFunc.negPart
theorem posPart_map_norm (f : α →ₛ ℝ) : (posPart f).map norm = posPart f := by
ext; rw [map_apply, Real.norm_eq_abs, abs_of_nonneg]; exact le_max_right _ _
#align measure_theory.simple_func.pos_part_map_norm MeasureTheory.SimpleFunc.posPart_map_norm
theorem negPart_map_norm (f : α →ₛ ℝ) : (negPart f).map norm = negPart f := by
rw [negPart]; exact posPart_map_norm _
#align measure_theory.simple_func.neg_part_map_norm MeasureTheory.SimpleFunc.negPart_map_norm
theorem posPart_sub_negPart (f : α →ₛ ℝ) : f.posPart - f.negPart = f := by
simp only [posPart, negPart]
ext a
rw [coe_sub]
exact max_zero_sub_eq_self (f a)
#align measure_theory.simple_func.pos_part_sub_neg_part MeasureTheory.SimpleFunc.posPart_sub_negPart
end PosPart
section Integral
/-!
### The Bochner integral of simple functions
Define the Bochner integral of simple functions of the type `α →ₛ β` where `β` is a normed group,
and prove basic property of this integral.
-/
open Finset
variable [NormedAddCommGroup E] [NormedAddCommGroup F] [NormedSpace ℝ F] {p : ℝ≥0∞} {G F' : Type*}
[NormedAddCommGroup G] [NormedAddCommGroup F'] [NormedSpace ℝ F'] {m : MeasurableSpace α}
{μ : Measure α}
/-- Bochner integral of simple functions whose codomain is a real `NormedSpace`.
This is equal to `∑ x ∈ f.range, (μ (f ⁻¹' {x})).toReal • x` (see `integral_eq`). -/
def integral {_ : MeasurableSpace α} (μ : Measure α) (f : α →ₛ F) : F :=
f.setToSimpleFunc (weightedSMul μ)
#align measure_theory.simple_func.integral MeasureTheory.SimpleFunc.integral
theorem integral_def {_ : MeasurableSpace α} (μ : Measure α) (f : α →ₛ F) :
f.integral μ = f.setToSimpleFunc (weightedSMul μ) := rfl
#align measure_theory.simple_func.integral_def MeasureTheory.SimpleFunc.integral_def
theorem integral_eq {m : MeasurableSpace α} (μ : Measure α) (f : α →ₛ F) :
f.integral μ = ∑ x ∈ f.range, (μ (f ⁻¹' {x})).toReal • x := by
simp [integral, setToSimpleFunc, weightedSMul_apply]
#align measure_theory.simple_func.integral_eq MeasureTheory.SimpleFunc.integral_eq
theorem integral_eq_sum_filter [DecidablePred fun x : F => x ≠ 0] {m : MeasurableSpace α}
(f : α →ₛ F) (μ : Measure α) :
f.integral μ = ∑ x ∈ f.range.filter fun x => x ≠ 0, (μ (f ⁻¹' {x})).toReal • x := by
rw [integral_def, setToSimpleFunc_eq_sum_filter]; simp_rw [weightedSMul_apply]; congr
#align measure_theory.simple_func.integral_eq_sum_filter MeasureTheory.SimpleFunc.integral_eq_sum_filter
/-- The Bochner integral is equal to a sum over any set that includes `f.range` (except `0`). -/
theorem integral_eq_sum_of_subset [DecidablePred fun x : F => x ≠ 0] {f : α →ₛ F} {s : Finset F}
(hs : (f.range.filter fun x => x ≠ 0) ⊆ s) :
f.integral μ = ∑ x ∈ s, (μ (f ⁻¹' {x})).toReal • x := by
rw [SimpleFunc.integral_eq_sum_filter, Finset.sum_subset hs]
rintro x - hx; rw [Finset.mem_filter, not_and_or, Ne, Classical.not_not] at hx
-- Porting note: reordered for clarity
rcases hx.symm with (rfl | hx)
· simp
rw [SimpleFunc.mem_range] at hx
-- Porting note: added
simp only [Set.mem_range, not_exists] at hx
rw [preimage_eq_empty] <;> simp [Set.disjoint_singleton_left, hx]
#align measure_theory.simple_func.integral_eq_sum_of_subset MeasureTheory.SimpleFunc.integral_eq_sum_of_subset
@[simp]
theorem integral_const {m : MeasurableSpace α} (μ : Measure α) (y : F) :
(const α y).integral μ = (μ univ).toReal • y := by
classical
calc
(const α y).integral μ = ∑ z ∈ {y}, (μ (const α y ⁻¹' {z})).toReal • z :=
integral_eq_sum_of_subset <| (filter_subset _ _).trans (range_const_subset _ _)
_ = (μ univ).toReal • y := by simp [Set.preimage] -- Porting note: added `Set.preimage`
#align measure_theory.simple_func.integral_const MeasureTheory.SimpleFunc.integral_const
@[simp]
theorem integral_piecewise_zero {m : MeasurableSpace α} (f : α →ₛ F) (μ : Measure α) {s : Set α}
(hs : MeasurableSet s) : (piecewise s hs f 0).integral μ = f.integral (μ.restrict s) := by
classical
refine (integral_eq_sum_of_subset ?_).trans
((sum_congr rfl fun y hy => ?_).trans (integral_eq_sum_filter _ _).symm)
· intro y hy
simp only [mem_filter, mem_range, coe_piecewise, coe_zero, piecewise_eq_indicator,
mem_range_indicator] at *
rcases hy with ⟨⟨rfl, -⟩ | ⟨x, -, rfl⟩, h₀⟩
exacts [(h₀ rfl).elim, ⟨Set.mem_range_self _, h₀⟩]
· dsimp
rw [Set.piecewise_eq_indicator, indicator_preimage_of_not_mem,
Measure.restrict_apply (f.measurableSet_preimage _)]
exact fun h₀ => (mem_filter.1 hy).2 (Eq.symm h₀)
#align measure_theory.simple_func.integral_piecewise_zero MeasureTheory.SimpleFunc.integral_piecewise_zero
/-- Calculate the integral of `g ∘ f : α →ₛ F`, where `f` is an integrable function from `α` to `E`
and `g` is a function from `E` to `F`. We require `g 0 = 0` so that `g ∘ f` is integrable. -/
theorem map_integral (f : α →ₛ E) (g : E → F) (hf : Integrable f μ) (hg : g 0 = 0) :
(f.map g).integral μ = ∑ x ∈ f.range, ENNReal.toReal (μ (f ⁻¹' {x})) • g x :=
map_setToSimpleFunc _ weightedSMul_union hf hg
#align measure_theory.simple_func.map_integral MeasureTheory.SimpleFunc.map_integral
/-- `SimpleFunc.integral` and `SimpleFunc.lintegral` agree when the integrand has type
`α →ₛ ℝ≥0∞`. But since `ℝ≥0∞` is not a `NormedSpace`, we need some form of coercion.
See `integral_eq_lintegral` for a simpler version. -/
theorem integral_eq_lintegral' {f : α →ₛ E} {g : E → ℝ≥0∞} (hf : Integrable f μ) (hg0 : g 0 = 0)
(ht : ∀ b, g b ≠ ∞) :
(f.map (ENNReal.toReal ∘ g)).integral μ = ENNReal.toReal (∫⁻ a, g (f a) ∂μ) := by
have hf' : f.FinMeasSupp μ := integrable_iff_finMeasSupp.1 hf
simp only [← map_apply g f, lintegral_eq_lintegral]
rw [map_integral f _ hf, map_lintegral, ENNReal.toReal_sum]
· refine Finset.sum_congr rfl fun b _ => ?_
-- Porting note: added `Function.comp_apply`
rw [smul_eq_mul, toReal_mul, mul_comm, Function.comp_apply]
· rintro a -
by_cases a0 : a = 0
· rw [a0, hg0, zero_mul]; exact WithTop.zero_ne_top
· apply mul_ne_top (ht a) (hf'.meas_preimage_singleton_ne_zero a0).ne
· simp [hg0]
#align measure_theory.simple_func.integral_eq_lintegral' MeasureTheory.SimpleFunc.integral_eq_lintegral'
variable [NormedField 𝕜] [NormedSpace 𝕜 E] [NormedSpace ℝ E] [SMulCommClass ℝ 𝕜 E]
theorem integral_congr {f g : α →ₛ E} (hf : Integrable f μ) (h : f =ᵐ[μ] g) :
f.integral μ = g.integral μ :=
setToSimpleFunc_congr (weightedSMul μ) (fun _ _ => weightedSMul_null) weightedSMul_union hf h
#align measure_theory.simple_func.integral_congr MeasureTheory.SimpleFunc.integral_congr
/-- `SimpleFunc.bintegral` and `SimpleFunc.integral` agree when the integrand has type
`α →ₛ ℝ≥0∞`. But since `ℝ≥0∞` is not a `NormedSpace`, we need some form of coercion. -/
theorem integral_eq_lintegral {f : α →ₛ ℝ} (hf : Integrable f μ) (h_pos : 0 ≤ᵐ[μ] f) :
f.integral μ = ENNReal.toReal (∫⁻ a, ENNReal.ofReal (f a) ∂μ) := by
have : f =ᵐ[μ] f.map (ENNReal.toReal ∘ ENNReal.ofReal) :=
h_pos.mono fun a h => (ENNReal.toReal_ofReal h).symm
rw [← integral_eq_lintegral' hf]
exacts [integral_congr hf this, ENNReal.ofReal_zero, fun b => ENNReal.ofReal_ne_top]
#align measure_theory.simple_func.integral_eq_lintegral MeasureTheory.SimpleFunc.integral_eq_lintegral
theorem integral_add {f g : α →ₛ E} (hf : Integrable f μ) (hg : Integrable g μ) :
integral μ (f + g) = integral μ f + integral μ g :=
setToSimpleFunc_add _ weightedSMul_union hf hg
#align measure_theory.simple_func.integral_add MeasureTheory.SimpleFunc.integral_add
theorem integral_neg {f : α →ₛ E} (hf : Integrable f μ) : integral μ (-f) = -integral μ f :=
setToSimpleFunc_neg _ weightedSMul_union hf
#align measure_theory.simple_func.integral_neg MeasureTheory.SimpleFunc.integral_neg
theorem integral_sub {f g : α →ₛ E} (hf : Integrable f μ) (hg : Integrable g μ) :
integral μ (f - g) = integral μ f - integral μ g :=
setToSimpleFunc_sub _ weightedSMul_union hf hg
#align measure_theory.simple_func.integral_sub MeasureTheory.SimpleFunc.integral_sub
theorem integral_smul (c : 𝕜) {f : α →ₛ E} (hf : Integrable f μ) :
integral μ (c • f) = c • integral μ f :=
setToSimpleFunc_smul _ weightedSMul_union weightedSMul_smul c hf
#align measure_theory.simple_func.integral_smul MeasureTheory.SimpleFunc.integral_smul
theorem norm_setToSimpleFunc_le_integral_norm (T : Set α → E →L[ℝ] F) {C : ℝ}
(hT_norm : ∀ s, MeasurableSet s → μ s < ∞ → ‖T s‖ ≤ C * (μ s).toReal) {f : α →ₛ E}
(hf : Integrable f μ) : ‖f.setToSimpleFunc T‖ ≤ C * (f.map norm).integral μ :=
calc
‖f.setToSimpleFunc T‖ ≤ C * ∑ x ∈ f.range, ENNReal.toReal (μ (f ⁻¹' {x})) * ‖x‖ :=
norm_setToSimpleFunc_le_sum_mul_norm_of_integrable T hT_norm f hf
_ = C * (f.map norm).integral μ := by
rw [map_integral f norm hf norm_zero]; simp_rw [smul_eq_mul]
#align measure_theory.simple_func.norm_set_to_simple_func_le_integral_norm MeasureTheory.SimpleFunc.norm_setToSimpleFunc_le_integral_norm
theorem norm_integral_le_integral_norm (f : α →ₛ E) (hf : Integrable f μ) :
‖f.integral μ‖ ≤ (f.map norm).integral μ := by
refine (norm_setToSimpleFunc_le_integral_norm _ (fun s _ _ => ?_) hf).trans (one_mul _).le
exact (norm_weightedSMul_le s).trans (one_mul _).symm.le
#align measure_theory.simple_func.norm_integral_le_integral_norm MeasureTheory.SimpleFunc.norm_integral_le_integral_norm
theorem integral_add_measure {ν} (f : α →ₛ E) (hf : Integrable f (μ + ν)) :
f.integral (μ + ν) = f.integral μ + f.integral ν := by
simp_rw [integral_def]
refine setToSimpleFunc_add_left'
(weightedSMul μ) (weightedSMul ν) (weightedSMul (μ + ν)) (fun s _ hμνs => ?_) hf
rw [lt_top_iff_ne_top, Measure.coe_add, Pi.add_apply, ENNReal.add_ne_top] at hμνs
rw [weightedSMul_add_measure _ _ hμνs.1 hμνs.2]
#align measure_theory.simple_func.integral_add_measure MeasureTheory.SimpleFunc.integral_add_measure
end Integral
end SimpleFunc
namespace L1
set_option linter.uppercaseLean3 false -- `L1`
open AEEqFun Lp.simpleFunc Lp
variable [NormedAddCommGroup E] [NormedAddCommGroup F] {m : MeasurableSpace α} {μ : Measure α}
namespace SimpleFunc
theorem norm_eq_integral (f : α →₁ₛ[μ] E) : ‖f‖ = ((toSimpleFunc f).map norm).integral μ := by
rw [norm_eq_sum_mul f, (toSimpleFunc f).map_integral norm (SimpleFunc.integrable f) norm_zero]
simp_rw [smul_eq_mul]
#align measure_theory.L1.simple_func.norm_eq_integral MeasureTheory.L1.SimpleFunc.norm_eq_integral
section PosPart
/-- Positive part of a simple function in L1 space. -/
nonrec def posPart (f : α →₁ₛ[μ] ℝ) : α →₁ₛ[μ] ℝ :=
⟨Lp.posPart (f : α →₁[μ] ℝ), by
rcases f with ⟨f, s, hsf⟩
use s.posPart
simp only [Subtype.coe_mk, Lp.coe_posPart, ← hsf, AEEqFun.posPart_mk,
SimpleFunc.coe_map, mk_eq_mk]
-- Porting note: added
simp [SimpleFunc.posPart, Function.comp, EventuallyEq.rfl] ⟩
#align measure_theory.L1.simple_func.pos_part MeasureTheory.L1.SimpleFunc.posPart
/-- Negative part of a simple function in L1 space. -/
def negPart (f : α →₁ₛ[μ] ℝ) : α →₁ₛ[μ] ℝ :=
posPart (-f)
#align measure_theory.L1.simple_func.neg_part MeasureTheory.L1.SimpleFunc.negPart
@[norm_cast]
theorem coe_posPart (f : α →₁ₛ[μ] ℝ) : (posPart f : α →₁[μ] ℝ) = Lp.posPart (f : α →₁[μ] ℝ) := rfl
#align measure_theory.L1.simple_func.coe_pos_part MeasureTheory.L1.SimpleFunc.coe_posPart
@[norm_cast]
theorem coe_negPart (f : α →₁ₛ[μ] ℝ) : (negPart f : α →₁[μ] ℝ) = Lp.negPart (f : α →₁[μ] ℝ) := rfl
#align measure_theory.L1.simple_func.coe_neg_part MeasureTheory.L1.SimpleFunc.coe_negPart
end PosPart
section SimpleFuncIntegral
/-!
### The Bochner integral of `L1`
Define the Bochner integral on `α →₁ₛ[μ] E` by extension from the simple functions `α →₁ₛ[μ] E`,
and prove basic properties of this integral. -/
variable [NormedField 𝕜] [NormedSpace 𝕜 E] [NormedSpace ℝ E] [SMulCommClass ℝ 𝕜 E] {F' : Type*}
[NormedAddCommGroup F'] [NormedSpace ℝ F']
attribute [local instance] simpleFunc.normedSpace
/-- The Bochner integral over simple functions in L1 space. -/
def integral (f : α →₁ₛ[μ] E) : E :=
(toSimpleFunc f).integral μ
#align measure_theory.L1.simple_func.integral MeasureTheory.L1.SimpleFunc.integral
theorem integral_eq_integral (f : α →₁ₛ[μ] E) : integral f = (toSimpleFunc f).integral μ := rfl
#align measure_theory.L1.simple_func.integral_eq_integral MeasureTheory.L1.SimpleFunc.integral_eq_integral
nonrec theorem integral_eq_lintegral {f : α →₁ₛ[μ] ℝ} (h_pos : 0 ≤ᵐ[μ] toSimpleFunc f) :
integral f = ENNReal.toReal (∫⁻ a, ENNReal.ofReal ((toSimpleFunc f) a) ∂μ) := by
rw [integral, SimpleFunc.integral_eq_lintegral (SimpleFunc.integrable f) h_pos]
#align measure_theory.L1.simple_func.integral_eq_lintegral MeasureTheory.L1.SimpleFunc.integral_eq_lintegral
theorem integral_eq_setToL1S (f : α →₁ₛ[μ] E) : integral f = setToL1S (weightedSMul μ) f := rfl
#align measure_theory.L1.simple_func.integral_eq_set_to_L1s MeasureTheory.L1.SimpleFunc.integral_eq_setToL1S
nonrec theorem integral_congr {f g : α →₁ₛ[μ] E} (h : toSimpleFunc f =ᵐ[μ] toSimpleFunc g) :
integral f = integral g :=
SimpleFunc.integral_congr (SimpleFunc.integrable f) h
#align measure_theory.L1.simple_func.integral_congr MeasureTheory.L1.SimpleFunc.integral_congr
theorem integral_add (f g : α →₁ₛ[μ] E) : integral (f + g) = integral f + integral g :=
setToL1S_add _ (fun _ _ => weightedSMul_null) weightedSMul_union _ _
#align measure_theory.L1.simple_func.integral_add MeasureTheory.L1.SimpleFunc.integral_add
theorem integral_smul (c : 𝕜) (f : α →₁ₛ[μ] E) : integral (c • f) = c • integral f :=
setToL1S_smul _ (fun _ _ => weightedSMul_null) weightedSMul_union weightedSMul_smul c f
#align measure_theory.L1.simple_func.integral_smul MeasureTheory.L1.SimpleFunc.integral_smul
theorem norm_integral_le_norm (f : α →₁ₛ[μ] E) : ‖integral f‖ ≤ ‖f‖ := by
rw [integral, norm_eq_integral]
exact (toSimpleFunc f).norm_integral_le_integral_norm (SimpleFunc.integrable f)
#align measure_theory.L1.simple_func.norm_integral_le_norm MeasureTheory.L1.SimpleFunc.norm_integral_le_norm
variable {E' : Type*} [NormedAddCommGroup E'] [NormedSpace ℝ E'] [NormedSpace 𝕜 E']
variable (α E μ 𝕜)
/-- The Bochner integral over simple functions in L1 space as a continuous linear map. -/
def integralCLM' : (α →₁ₛ[μ] E) →L[𝕜] E :=
LinearMap.mkContinuous ⟨⟨integral, integral_add⟩, integral_smul⟩ 1 fun f =>
le_trans (norm_integral_le_norm _) <| by rw [one_mul]
#align measure_theory.L1.simple_func.integral_clm' MeasureTheory.L1.SimpleFunc.integralCLM'
/-- The Bochner integral over simple functions in L1 space as a continuous linear map over ℝ. -/
def integralCLM : (α →₁ₛ[μ] E) →L[ℝ] E :=
integralCLM' α E ℝ μ
#align measure_theory.L1.simple_func.integral_clm MeasureTheory.L1.SimpleFunc.integralCLM
variable {α E μ 𝕜}
local notation "Integral" => integralCLM α E μ
open ContinuousLinearMap
theorem norm_Integral_le_one : ‖Integral‖ ≤ 1 :=
-- Porting note: Old proof was `LinearMap.mkContinuous_norm_le _ zero_le_one _`
LinearMap.mkContinuous_norm_le _ zero_le_one (fun f => by
rw [one_mul]
exact norm_integral_le_norm f)
#align measure_theory.L1.simple_func.norm_Integral_le_one MeasureTheory.L1.SimpleFunc.norm_Integral_le_one
section PosPart
theorem posPart_toSimpleFunc (f : α →₁ₛ[μ] ℝ) :
toSimpleFunc (posPart f) =ᵐ[μ] (toSimpleFunc f).posPart := by
have eq : ∀ a, (toSimpleFunc f).posPart a = max ((toSimpleFunc f) a) 0 := fun a => rfl
have ae_eq : ∀ᵐ a ∂μ, toSimpleFunc (posPart f) a = max ((toSimpleFunc f) a) 0 := by
filter_upwards [toSimpleFunc_eq_toFun (posPart f), Lp.coeFn_posPart (f : α →₁[μ] ℝ),
toSimpleFunc_eq_toFun f] with _ _ h₂ h₃
convert h₂ using 1
-- Porting note: added
rw [h₃]
refine ae_eq.mono fun a h => ?_
rw [h, eq]
#align measure_theory.L1.simple_func.pos_part_to_simple_func MeasureTheory.L1.SimpleFunc.posPart_toSimpleFunc
theorem negPart_toSimpleFunc (f : α →₁ₛ[μ] ℝ) :
toSimpleFunc (negPart f) =ᵐ[μ] (toSimpleFunc f).negPart := by
rw [SimpleFunc.negPart, MeasureTheory.SimpleFunc.negPart]
filter_upwards [posPart_toSimpleFunc (-f), neg_toSimpleFunc f]
intro a h₁ h₂
rw [h₁]
show max _ _ = max _ _
rw [h₂]
rfl
#align measure_theory.L1.simple_func.neg_part_to_simple_func MeasureTheory.L1.SimpleFunc.negPart_toSimpleFunc
theorem integral_eq_norm_posPart_sub (f : α →₁ₛ[μ] ℝ) : integral f = ‖posPart f‖ - ‖negPart f‖ := by
-- Convert things in `L¹` to their `SimpleFunc` counterpart
have ae_eq₁ : (toSimpleFunc f).posPart =ᵐ[μ] (toSimpleFunc (posPart f)).map norm := by
filter_upwards [posPart_toSimpleFunc f] with _ h
rw [SimpleFunc.map_apply, h]
conv_lhs => rw [← SimpleFunc.posPart_map_norm, SimpleFunc.map_apply]
-- Convert things in `L¹` to their `SimpleFunc` counterpart
have ae_eq₂ : (toSimpleFunc f).negPart =ᵐ[μ] (toSimpleFunc (negPart f)).map norm := by
filter_upwards [negPart_toSimpleFunc f] with _ h
rw [SimpleFunc.map_apply, h]
conv_lhs => rw [← SimpleFunc.negPart_map_norm, SimpleFunc.map_apply]
rw [integral, norm_eq_integral, norm_eq_integral, ← SimpleFunc.integral_sub]
· show (toSimpleFunc f).integral μ =
((toSimpleFunc (posPart f)).map norm - (toSimpleFunc (negPart f)).map norm).integral μ
apply MeasureTheory.SimpleFunc.integral_congr (SimpleFunc.integrable f)
filter_upwards [ae_eq₁, ae_eq₂] with _ h₁ h₂
show _ = _ - _
rw [← h₁, ← h₂]
have := (toSimpleFunc f).posPart_sub_negPart
conv_lhs => rw [← this]
rfl
· exact (SimpleFunc.integrable f).pos_part.congr ae_eq₁
· exact (SimpleFunc.integrable f).neg_part.congr ae_eq₂
#align measure_theory.L1.simple_func.integral_eq_norm_pos_part_sub MeasureTheory.L1.SimpleFunc.integral_eq_norm_posPart_sub
end PosPart
end SimpleFuncIntegral
end SimpleFunc
open SimpleFunc
local notation "Integral" => @integralCLM α E _ _ _ _ _ μ _
variable [NormedSpace ℝ E] [NontriviallyNormedField 𝕜] [NormedSpace 𝕜 E] [SMulCommClass ℝ 𝕜 E]
[NormedSpace ℝ F] [CompleteSpace E]
section IntegrationInL1
attribute [local instance] simpleFunc.normedSpace
open ContinuousLinearMap
variable (𝕜)
/-- The Bochner integral in L1 space as a continuous linear map. -/
nonrec def integralCLM' : (α →₁[μ] E) →L[𝕜] E :=
(integralCLM' α E 𝕜 μ).extend (coeToLp α E 𝕜) (simpleFunc.denseRange one_ne_top)
simpleFunc.uniformInducing
#align measure_theory.L1.integral_clm' MeasureTheory.L1.integralCLM'
variable {𝕜}
/-- The Bochner integral in L1 space as a continuous linear map over ℝ. -/
def integralCLM : (α →₁[μ] E) →L[ℝ] E :=
integralCLM' ℝ
#align measure_theory.L1.integral_clm MeasureTheory.L1.integralCLM
-- Porting note: added `(E := E)` in several places below.
/-- The Bochner integral in L1 space -/
irreducible_def integral (f : α →₁[μ] E) : E :=
integralCLM (E := E) f
#align measure_theory.L1.integral MeasureTheory.L1.integral
theorem integral_eq (f : α →₁[μ] E) : integral f = integralCLM (E := E) f := by
simp only [integral]
#align measure_theory.L1.integral_eq MeasureTheory.L1.integral_eq
theorem integral_eq_setToL1 (f : α →₁[μ] E) :
integral f = setToL1 (E := E) (dominatedFinMeasAdditive_weightedSMul μ) f := by
simp only [integral]; rfl
#align measure_theory.L1.integral_eq_set_to_L1 MeasureTheory.L1.integral_eq_setToL1
@[norm_cast]
theorem SimpleFunc.integral_L1_eq_integral (f : α →₁ₛ[μ] E) :
L1.integral (f : α →₁[μ] E) = SimpleFunc.integral f := by
simp only [integral, L1.integral]
exact setToL1_eq_setToL1SCLM (dominatedFinMeasAdditive_weightedSMul μ) f
#align measure_theory.L1.simple_func.integral_L1_eq_integral MeasureTheory.L1.SimpleFunc.integral_L1_eq_integral
variable (α E)
@[simp]
theorem integral_zero : integral (0 : α →₁[μ] E) = 0 := by
simp only [integral]
exact map_zero integralCLM
#align measure_theory.L1.integral_zero MeasureTheory.L1.integral_zero
variable {α E}
@[integral_simps]
theorem integral_add (f g : α →₁[μ] E) : integral (f + g) = integral f + integral g := by
simp only [integral]
exact map_add integralCLM f g
#align measure_theory.L1.integral_add MeasureTheory.L1.integral_add
@[integral_simps]
theorem integral_neg (f : α →₁[μ] E) : integral (-f) = -integral f := by
simp only [integral]
exact map_neg integralCLM f
#align measure_theory.L1.integral_neg MeasureTheory.L1.integral_neg
@[integral_simps]
theorem integral_sub (f g : α →₁[μ] E) : integral (f - g) = integral f - integral g := by
simp only [integral]
exact map_sub integralCLM f g
#align measure_theory.L1.integral_sub MeasureTheory.L1.integral_sub
@[integral_simps]
theorem integral_smul (c : 𝕜) (f : α →₁[μ] E) : integral (c • f) = c • integral f := by
simp only [integral]
show (integralCLM' (E := E) 𝕜) (c • f) = c • (integralCLM' (E := E) 𝕜) f
exact map_smul (integralCLM' (E := E) 𝕜) c f
#align measure_theory.L1.integral_smul MeasureTheory.L1.integral_smul
local notation "Integral" => @integralCLM α E _ _ μ _ _
local notation "sIntegral" => @SimpleFunc.integralCLM α E _ _ μ _
theorem norm_Integral_le_one : ‖integralCLM (α := α) (E := E) (μ := μ)‖ ≤ 1 :=
norm_setToL1_le (dominatedFinMeasAdditive_weightedSMul μ) zero_le_one
#align measure_theory.L1.norm_Integral_le_one MeasureTheory.L1.norm_Integral_le_one
theorem nnnorm_Integral_le_one : ‖integralCLM (α := α) (E := E) (μ := μ)‖₊ ≤ 1 :=
norm_Integral_le_one
theorem norm_integral_le (f : α →₁[μ] E) : ‖integral f‖ ≤ ‖f‖ :=
calc
‖integral f‖ = ‖integralCLM (E := E) f‖ := by simp only [integral]
_ ≤ ‖integralCLM (α := α) (E := E) (μ := μ)‖ * ‖f‖ := le_opNorm _ _
_ ≤ 1 * ‖f‖ := mul_le_mul_of_nonneg_right norm_Integral_le_one <| norm_nonneg _
_ = ‖f‖ := one_mul _
#align measure_theory.L1.norm_integral_le MeasureTheory.L1.norm_integral_le
theorem nnnorm_integral_le (f : α →₁[μ] E) : ‖integral f‖₊ ≤ ‖f‖₊ :=
norm_integral_le f
@[continuity]
theorem continuous_integral : Continuous fun f : α →₁[μ] E => integral f := by
simp only [integral]
exact L1.integralCLM.continuous
#align measure_theory.L1.continuous_integral MeasureTheory.L1.continuous_integral
section PosPart
theorem integral_eq_norm_posPart_sub (f : α →₁[μ] ℝ) :
integral f = ‖Lp.posPart f‖ - ‖Lp.negPart f‖ := by
-- Use `isClosed_property` and `isClosed_eq`
refine @isClosed_property _ _ _ ((↑) : (α →₁ₛ[μ] ℝ) → α →₁[μ] ℝ)
(fun f : α →₁[μ] ℝ => integral f = ‖Lp.posPart f‖ - ‖Lp.negPart f‖)
(simpleFunc.denseRange one_ne_top) (isClosed_eq ?_ ?_) ?_ f
· simp only [integral]
exact cont _
· refine Continuous.sub (continuous_norm.comp Lp.continuous_posPart)
(continuous_norm.comp Lp.continuous_negPart)
-- Show that the property holds for all simple functions in the `L¹` space.
· intro s
norm_cast
exact SimpleFunc.integral_eq_norm_posPart_sub _
#align measure_theory.L1.integral_eq_norm_pos_part_sub MeasureTheory.L1.integral_eq_norm_posPart_sub
end PosPart
end IntegrationInL1
end L1
/-!
## The Bochner integral on functions
Define the Bochner integral on functions generally to be the `L1` Bochner integral, for integrable
functions, and 0 otherwise; prove its basic properties.
-/
variable [NormedAddCommGroup E] [NormedSpace ℝ E] [hE : CompleteSpace E] [NontriviallyNormedField 𝕜]
[NormedSpace 𝕜 E] [SMulCommClass ℝ 𝕜 E] [NormedAddCommGroup F] [NormedSpace ℝ F] [CompleteSpace F]
{G : Type*} [NormedAddCommGroup G] [NormedSpace ℝ G]
section
open scoped Classical
/-- The Bochner integral -/
irreducible_def integral {_ : MeasurableSpace α} (μ : Measure α) (f : α → G) : G :=
if _ : CompleteSpace G then
if hf : Integrable f μ then L1.integral (hf.toL1 f) else 0
else 0
#align measure_theory.integral MeasureTheory.integral
end
/-! In the notation for integrals, an expression like `∫ x, g ‖x‖ ∂μ` will not be parsed correctly,
and needs parentheses. We do not set the binding power of `r` to `0`, because then
`∫ x, f x = 0` will be parsed incorrectly. -/
@[inherit_doc MeasureTheory.integral]
notation3 "∫ "(...)", "r:60:(scoped f => f)" ∂"μ:70 => integral μ r
@[inherit_doc MeasureTheory.integral]
notation3 "∫ "(...)", "r:60:(scoped f => integral volume f) => r
@[inherit_doc MeasureTheory.integral]
notation3 "∫ "(...)" in "s", "r:60:(scoped f => f)" ∂"μ:70 => integral (Measure.restrict μ s) r
@[inherit_doc MeasureTheory.integral]
notation3 "∫ "(...)" in "s", "r:60:(scoped f => integral (Measure.restrict volume s) f) => r
section Properties
open ContinuousLinearMap MeasureTheory.SimpleFunc
variable {f g : α → E} {m : MeasurableSpace α} {μ : Measure α}
theorem integral_eq (f : α → E) (hf : Integrable f μ) : ∫ a, f a ∂μ = L1.integral (hf.toL1 f) := by
simp [integral, hE, hf]
#align measure_theory.integral_eq MeasureTheory.integral_eq
theorem integral_eq_setToFun (f : α → E) :
∫ a, f a ∂μ = setToFun μ (weightedSMul μ) (dominatedFinMeasAdditive_weightedSMul μ) f := by
simp only [integral, hE, L1.integral]; rfl
#align measure_theory.integral_eq_set_to_fun MeasureTheory.integral_eq_setToFun
theorem L1.integral_eq_integral (f : α →₁[μ] E) : L1.integral f = ∫ a, f a ∂μ := by
simp only [integral, L1.integral, integral_eq_setToFun]
exact (L1.setToFun_eq_setToL1 (dominatedFinMeasAdditive_weightedSMul μ) f).symm
set_option linter.uppercaseLean3 false in
#align measure_theory.L1.integral_eq_integral MeasureTheory.L1.integral_eq_integral
theorem integral_undef {f : α → G} (h : ¬Integrable f μ) : ∫ a, f a ∂μ = 0 := by
by_cases hG : CompleteSpace G
· simp [integral, hG, h]
· simp [integral, hG]
#align measure_theory.integral_undef MeasureTheory.integral_undef
theorem Integrable.of_integral_ne_zero {f : α → G} (h : ∫ a, f a ∂μ ≠ 0) : Integrable f μ :=
Not.imp_symm integral_undef h
theorem integral_non_aestronglyMeasurable {f : α → G} (h : ¬AEStronglyMeasurable f μ) :
∫ a, f a ∂μ = 0 :=
integral_undef <| not_and_of_not_left _ h
#align measure_theory.integral_non_ae_strongly_measurable MeasureTheory.integral_non_aestronglyMeasurable
variable (α G)
@[simp]
theorem integral_zero : ∫ _ : α, (0 : G) ∂μ = 0 := by
by_cases hG : CompleteSpace G
· simp only [integral, hG, L1.integral]
exact setToFun_zero (dominatedFinMeasAdditive_weightedSMul μ)
· simp [integral, hG]
#align measure_theory.integral_zero MeasureTheory.integral_zero
@[simp]
theorem integral_zero' : integral μ (0 : α → G) = 0 :=
integral_zero α G
#align measure_theory.integral_zero' MeasureTheory.integral_zero'
variable {α G}
theorem integrable_of_integral_eq_one {f : α → ℝ} (h : ∫ x, f x ∂μ = 1) : Integrable f μ :=
.of_integral_ne_zero <| h ▸ one_ne_zero
#align measure_theory.integrable_of_integral_eq_one MeasureTheory.integrable_of_integral_eq_one
theorem integral_add {f g : α → G} (hf : Integrable f μ) (hg : Integrable g μ) :
∫ a, f a + g a ∂μ = ∫ a, f a ∂μ + ∫ a, g a ∂μ := by
by_cases hG : CompleteSpace G
· simp only [integral, hG, L1.integral]
exact setToFun_add (dominatedFinMeasAdditive_weightedSMul μ) hf hg
· simp [integral, hG]
#align measure_theory.integral_add MeasureTheory.integral_add
theorem integral_add' {f g : α → G} (hf : Integrable f μ) (hg : Integrable g μ) :
∫ a, (f + g) a ∂μ = ∫ a, f a ∂μ + ∫ a, g a ∂μ :=
integral_add hf hg
#align measure_theory.integral_add' MeasureTheory.integral_add'
theorem integral_finset_sum {ι} (s : Finset ι) {f : ι → α → G} (hf : ∀ i ∈ s, Integrable (f i) μ) :
∫ a, ∑ i ∈ s, f i a ∂μ = ∑ i ∈ s, ∫ a, f i a ∂μ := by
by_cases hG : CompleteSpace G
· simp only [integral, hG, L1.integral]
exact setToFun_finset_sum (dominatedFinMeasAdditive_weightedSMul _) s hf
· simp [integral, hG]
#align measure_theory.integral_finset_sum MeasureTheory.integral_finset_sum
@[integral_simps]
theorem integral_neg (f : α → G) : ∫ a, -f a ∂μ = -∫ a, f a ∂μ := by
by_cases hG : CompleteSpace G
· simp only [integral, hG, L1.integral]
exact setToFun_neg (dominatedFinMeasAdditive_weightedSMul μ) f
· simp [integral, hG]
#align measure_theory.integral_neg MeasureTheory.integral_neg
theorem integral_neg' (f : α → G) : ∫ a, (-f) a ∂μ = -∫ a, f a ∂μ :=
integral_neg f
#align measure_theory.integral_neg' MeasureTheory.integral_neg'
theorem integral_sub {f g : α → G} (hf : Integrable f μ) (hg : Integrable g μ) :
∫ a, f a - g a ∂μ = ∫ a, f a ∂μ - ∫ a, g a ∂μ := by
by_cases hG : CompleteSpace G
· simp only [integral, hG, L1.integral]
exact setToFun_sub (dominatedFinMeasAdditive_weightedSMul μ) hf hg
· simp [integral, hG]
#align measure_theory.integral_sub MeasureTheory.integral_sub
theorem integral_sub' {f g : α → G} (hf : Integrable f μ) (hg : Integrable g μ) :
∫ a, (f - g) a ∂μ = ∫ a, f a ∂μ - ∫ a, g a ∂μ :=
integral_sub hf hg
#align measure_theory.integral_sub' MeasureTheory.integral_sub'
@[integral_simps]
theorem integral_smul [NormedSpace 𝕜 G] [SMulCommClass ℝ 𝕜 G] (c : 𝕜) (f : α → G) :
∫ a, c • f a ∂μ = c • ∫ a, f a ∂μ := by
by_cases hG : CompleteSpace G
· simp only [integral, hG, L1.integral]
exact setToFun_smul (dominatedFinMeasAdditive_weightedSMul μ) weightedSMul_smul c f
· simp [integral, hG]
#align measure_theory.integral_smul MeasureTheory.integral_smul
theorem integral_mul_left {L : Type*} [RCLike L] (r : L) (f : α → L) :
∫ a, r * f a ∂μ = r * ∫ a, f a ∂μ :=
integral_smul r f
#align measure_theory.integral_mul_left MeasureTheory.integral_mul_left
theorem integral_mul_right {L : Type*} [RCLike L] (r : L) (f : α → L) :
∫ a, f a * r ∂μ = (∫ a, f a ∂μ) * r := by
simp only [mul_comm]; exact integral_mul_left r f
#align measure_theory.integral_mul_right MeasureTheory.integral_mul_right
theorem integral_div {L : Type*} [RCLike L] (r : L) (f : α → L) :
∫ a, f a / r ∂μ = (∫ a, f a ∂μ) / r := by
simpa only [← div_eq_mul_inv] using integral_mul_right r⁻¹ f
#align measure_theory.integral_div MeasureTheory.integral_div
theorem integral_congr_ae {f g : α → G} (h : f =ᵐ[μ] g) : ∫ a, f a ∂μ = ∫ a, g a ∂μ := by
by_cases hG : CompleteSpace G
· simp only [integral, hG, L1.integral]
exact setToFun_congr_ae (dominatedFinMeasAdditive_weightedSMul μ) h
· simp [integral, hG]
#align measure_theory.integral_congr_ae MeasureTheory.integral_congr_ae
-- Porting note: `nolint simpNF` added because simplify fails on left-hand side
@[simp, nolint simpNF]
| Mathlib/MeasureTheory/Integral/Bochner.lean | 947 | 952 | theorem L1.integral_of_fun_eq_integral {f : α → G} (hf : Integrable f μ) :
∫ a, (hf.toL1 f) a ∂μ = ∫ a, f a ∂μ := by |
by_cases hG : CompleteSpace G
· simp only [MeasureTheory.integral, hG, L1.integral]
exact setToFun_toL1 (dominatedFinMeasAdditive_weightedSMul μ) hf
· simp [MeasureTheory.integral, hG]
|
/-
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
#align_import analysis.calculus.fderiv.basic from "leanprover-community/mathlib"@"41bef4ae1254365bc190aee63b947674d2977f01"
/-!
# 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 `Analysis.SpecialFunctions.Trigonometric`.
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 `isLittleO` relation, but 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`.
## Tags
derivative, differentiable, Fréchet, calculus
-/
open Filter Asymptotics ContinuousLinearMap Set Metric
open scoped Classical
open Topology NNReal Filter Asymptotics ENNReal
noncomputable section
section
variable {𝕜 : Type*} [NontriviallyNormedField 𝕜]
variable {E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E]
variable {F : Type*} [NormedAddCommGroup F] [NormedSpace 𝕜 F]
variable {G : Type*} [NormedAddCommGroup G] [NormedSpace 𝕜 G]
variable {G' : Type*} [NormedAddCommGroup G'] [NormedSpace 𝕜 G']
/-- 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_isLittleO]
structure HasFDerivAtFilter (f : E → F) (f' : E →L[𝕜] F) (x : E) (L : Filter E) : Prop where
of_isLittleO :: isLittleO : (fun x' => f x' - f x - f' (x' - x)) =o[L] fun x' => x' - x
#align has_fderiv_at_filter HasFDerivAtFilter
/-- 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)
#align has_fderiv_within_at HasFDerivWithinAt
/-- 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)
#align has_fderiv_at HasFDerivAt
/-- 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]
def HasStrictFDerivAt (f : E → F) (f' : E →L[𝕜] F) (x : E) :=
(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
#align has_strict_fderiv_at HasStrictFDerivAt
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
#align differentiable_within_at DifferentiableWithinAt
/-- 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
#align differentiable_at DifferentiableAt
/-- If `f` has a derivative at `x` within `s`, then `fderivWithin 𝕜 f s x` is such a derivative.
Otherwise, it is set to `0`. If `x` is isolated in `s`, we take the derivative within `s` to
be zero for convenience. -/
irreducible_def fderivWithin (f : E → F) (s : Set E) (x : E) : E →L[𝕜] F :=
if 𝓝[s \ {x}] x = ⊥ then 0 else
if h : ∃ f', HasFDerivWithinAt f f' s x then Classical.choose h else 0
#align fderiv_within fderivWithin
/-- 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 :=
if h : ∃ f', HasFDerivAt f f' x then Classical.choose h else 0
#align fderiv fderiv
/-- `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
#align differentiable_on DifferentiableOn
/-- `Differentiable 𝕜 f` means that `f` is differentiable at any point. -/
@[fun_prop]
def Differentiable (f : E → F) :=
∀ x, DifferentiableAt 𝕜 f x
#align differentiable Differentiable
variable {𝕜}
variable {f f₀ f₁ g : E → F}
variable {f' f₀' f₁' g' : E →L[𝕜] F}
variable (e : E →L[𝕜] F)
variable {x : E}
variable {s t : Set E}
variable {L L₁ L₂ : Filter E}
theorem fderivWithin_zero_of_isolated (h : 𝓝[s \ {x}] x = ⊥) : fderivWithin 𝕜 f s x = 0 := by
rw [fderivWithin, if_pos h]
theorem fderivWithin_zero_of_nmem_closure (h : x ∉ closure s) : fderivWithin 𝕜 f s x = 0 := by
apply fderivWithin_zero_of_isolated
simp only [mem_closure_iff_nhdsWithin_neBot, neBot_iff, Ne, Classical.not_not] at h
rw [eq_bot_iff, ← h]
exact nhdsWithin_mono _ diff_subset
theorem fderivWithin_zero_of_not_differentiableWithinAt (h : ¬DifferentiableWithinAt 𝕜 f s x) :
fderivWithin 𝕜 f s x = 0 := by
have : ¬∃ f', HasFDerivWithinAt f f' s x := h
simp [fderivWithin, this]
#align fderiv_within_zero_of_not_differentiable_within_at fderivWithin_zero_of_not_differentiableWithinAt
theorem fderiv_zero_of_not_differentiableAt (h : ¬DifferentiableAt 𝕜 f x) : fderiv 𝕜 f x = 0 := by
have : ¬∃ f', HasFDerivAt f f' x := h
simp [fderiv, this]
#align fderiv_zero_of_not_differentiable_at fderiv_zero_of_not_differentiableAt
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
#align has_fderiv_within_at.lim HasFDerivWithinAt.lim
/-- 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)
#align has_fderiv_within_at.unique_on HasFDerivWithinAt.unique_on
/-- `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)
#align unique_diff_within_at.eq UniqueDiffWithinAt.eq
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₁
#align unique_diff_on.eq UniqueDiffOn.eq
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 _ _
#align has_fderiv_at_filter_iff_tendsto hasFDerivAtFilter_iff_tendsto
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
#align has_fderiv_within_at_iff_tendsto hasFDerivWithinAt_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
#align has_fderiv_at_iff_tendsto hasFDerivAt_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 [(· ∘ ·)]
#align has_fderiv_at_iff_is_o_nhds_zero hasFDerivAt_iff_isLittleO_nhds_zero
/-- Converse to the mean value inequality: if `f` is differentiable at `x₀` and `C`-lipschitz
on a neighborhood of `x₀` then its derivative at `x₀` has norm bounded by `C`. This version
only assumes that `‖f x - f x₀‖ ≤ C * ‖x - x₀‖` in a neighborhood of `x`. -/
theorem HasFDerivAt.le_of_lip' {f : E → F} {f' : E →L[𝕜] F} {x₀ : E} (hf : HasFDerivAt f f' x₀)
{C : ℝ} (hC₀ : 0 ≤ C) (hlip : ∀ᶠ x in 𝓝 x₀, ‖f x - f x₀‖ ≤ C * ‖x - x₀‖) : ‖f'‖ ≤ C := by
refine le_of_forall_pos_le_add fun ε ε0 => opNorm_le_of_nhds_zero ?_ ?_
· exact add_nonneg hC₀ ε0.le
rw [← map_add_left_nhds_zero x₀, eventually_map] at hlip
filter_upwards [isLittleO_iff.1 (hasFDerivAt_iff_isLittleO_nhds_zero.1 hf) ε0, hlip] with y hy hyC
rw [add_sub_cancel_left] at hyC
calc
‖f' y‖ ≤ ‖f (x₀ + y) - f x₀‖ + ‖f (x₀ + y) - f x₀ - f' y‖ := norm_le_insert _ _
_ ≤ C * ‖y‖ + ε * ‖y‖ := add_le_add hyC hy
_ = (C + ε) * ‖y‖ := (add_mul _ _ _).symm
#align has_fderiv_at.le_of_lip' HasFDerivAt.le_of_lip'
/-- Converse to the mean value inequality: if `f` is differentiable at `x₀` and `C`-lipschitz
on a neighborhood of `x₀` then its derivative at `x₀` has norm bounded by `C`. -/
theorem HasFDerivAt.le_of_lipschitzOn
{f : E → F} {f' : E →L[𝕜] F} {x₀ : E} (hf : HasFDerivAt f f' x₀)
{s : Set E} (hs : s ∈ 𝓝 x₀) {C : ℝ≥0} (hlip : LipschitzOnWith C f s) : ‖f'‖ ≤ C := by
refine hf.le_of_lip' C.coe_nonneg ?_
filter_upwards [hs] with x hx using hlip.norm_sub_le hx (mem_of_mem_nhds hs)
#align has_fderiv_at.le_of_lip HasFDerivAt.le_of_lipschitzOn
/-- Converse to the mean value inequality: if `f` is differentiable at `x₀` and `C`-lipschitz
then its derivative at `x₀` has norm bounded by `C`. -/
theorem HasFDerivAt.le_of_lipschitz {f : E → F} {f' : E →L[𝕜] F} {x₀ : E} (hf : HasFDerivAt f f' x₀)
{C : ℝ≥0} (hlip : LipschitzWith C f) : ‖f'‖ ≤ C :=
hf.le_of_lipschitzOn univ_mem (lipschitzOn_univ.2 hlip)
nonrec theorem HasFDerivAtFilter.mono (h : HasFDerivAtFilter f f' x L₂) (hst : L₁ ≤ L₂) :
HasFDerivAtFilter f f' x L₁ :=
.of_isLittleO <| h.isLittleO.mono hst
#align has_fderiv_at_filter.mono HasFDerivAtFilter.mono
theorem HasFDerivWithinAt.mono_of_mem (h : HasFDerivWithinAt f f' t x) (hst : t ∈ 𝓝[s] x) :
HasFDerivWithinAt f f' s x :=
h.mono <| nhdsWithin_le_iff.mpr hst
#align has_fderiv_within_at.mono_of_mem HasFDerivWithinAt.mono_of_mem
#align has_fderiv_within_at.nhds_within HasFDerivWithinAt.mono_of_mem
nonrec theorem HasFDerivWithinAt.mono (h : HasFDerivWithinAt f f' t x) (hst : s ⊆ t) :
HasFDerivWithinAt f f' s x :=
h.mono <| nhdsWithin_mono _ hst
#align has_fderiv_within_at.mono HasFDerivWithinAt.mono
theorem HasFDerivAt.hasFDerivAtFilter (h : HasFDerivAt f f' x) (hL : L ≤ 𝓝 x) :
HasFDerivAtFilter f f' x L :=
h.mono hL
#align has_fderiv_at.has_fderiv_at_filter HasFDerivAt.hasFDerivAtFilter
@[fun_prop]
theorem HasFDerivAt.hasFDerivWithinAt (h : HasFDerivAt f f' x) : HasFDerivWithinAt f f' s x :=
h.hasFDerivAtFilter inf_le_left
#align has_fderiv_at.has_fderiv_within_at HasFDerivAt.hasFDerivWithinAt
@[fun_prop]
theorem HasFDerivWithinAt.differentiableWithinAt (h : HasFDerivWithinAt f f' s x) :
DifferentiableWithinAt 𝕜 f s x :=
⟨f', h⟩
#align has_fderiv_within_at.differentiable_within_at HasFDerivWithinAt.differentiableWithinAt
@[fun_prop]
theorem HasFDerivAt.differentiableAt (h : HasFDerivAt f f' x) : DifferentiableAt 𝕜 f x :=
⟨f', h⟩
#align has_fderiv_at.differentiable_at HasFDerivAt.differentiableAt
@[simp]
theorem hasFDerivWithinAt_univ : HasFDerivWithinAt f f' univ x ↔ HasFDerivAt f f' x := by
simp only [HasFDerivWithinAt, nhdsWithin_univ]
rfl
#align has_fderiv_within_at_univ hasFDerivWithinAt_univ
alias ⟨HasFDerivWithinAt.hasFDerivAt_of_univ, _⟩ := hasFDerivWithinAt_univ
#align has_fderiv_within_at.has_fderiv_at_of_univ HasFDerivWithinAt.hasFDerivAt_of_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)
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_isLittleO]
apply Asymptotics.isLittleO_insert
simp only [sub_self, map_zero]
refine ⟨fun h => h.mono <| subset_insert y s, fun hf => hf.mono_of_mem ?_⟩
simp_rw [nhdsWithin_insert_of_ne h, self_mem_nhdsWithin]
#align has_fderiv_within_at_insert hasFDerivWithinAt_insert
alias ⟨HasFDerivWithinAt.of_insert, HasFDerivWithinAt.insert'⟩ := hasFDerivWithinAt_insert
#align has_fderiv_within_at.of_insert HasFDerivWithinAt.of_insert
#align has_fderiv_within_at.insert' HasFDerivWithinAt.insert'
protected theorem HasFDerivWithinAt.insert (h : HasFDerivWithinAt g g' s x) :
HasFDerivWithinAt g g' (insert x s) x :=
h.insert'
#align has_fderiv_within_at.insert HasFDerivWithinAt.insert
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]
#align has_fderiv_within_at_diff_singleton hasFDerivWithinAt_diff_singleton
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.isBigO.congr_of_sub.2 (f'.isBigO_comp _ _)
set_option linter.uppercaseLean3 false in
#align has_strict_fderiv_at.is_O_sub HasStrictFDerivAt.isBigO_sub
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 _ _)
set_option linter.uppercaseLean3 false in
#align has_fderiv_at_filter.is_O_sub HasFDerivAtFilter.isBigO_sub
@[fun_prop]
protected theorem HasStrictFDerivAt.hasFDerivAt (hf : HasStrictFDerivAt f f' x) :
HasFDerivAt f f' x := by
rw [HasFDerivAt, hasFDerivAtFilter_iff_isLittleO, isLittleO_iff]
exact fun c hc => tendsto_id.prod_mk_nhds tendsto_const_nhds (isLittleO_iff.1 hf hc)
#align has_strict_fderiv_at.has_fderiv_at HasStrictFDerivAt.hasFDerivAt
protected theorem HasStrictFDerivAt.differentiableAt (hf : HasStrictFDerivAt f f' x) :
DifferentiableAt 𝕜 f x :=
hf.hasFDerivAt.differentiableAt
#align has_strict_fderiv_at.differentiable_at HasStrictFDerivAt.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.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)⟩
#align has_strict_fderiv_at.exists_lipschitz_on_with_of_nnnorm_lt HasStrictFDerivAt.exists_lipschitzOnWith_of_nnnorm_lt
/-- 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
#align has_strict_fderiv_at.exists_lipschitz_on_with HasStrictFDerivAt.exists_lipschitzOnWith
/-- 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]
#align has_fderiv_at.lim HasFDerivAt.lim
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₁
#align has_fderiv_at.unique HasFDerivAt.unique
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]
#align has_fderiv_within_at_inter' hasFDerivWithinAt_inter'
theorem hasFDerivWithinAt_inter (h : t ∈ 𝓝 x) :
HasFDerivWithinAt f f' (s ∩ t) x ↔ HasFDerivWithinAt f f' s x := by
simp [HasFDerivWithinAt, nhdsWithin_restrict' s h]
#align has_fderiv_within_at_inter hasFDerivWithinAt_inter
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_isLittleO <| hs.isLittleO.sup ht.isLittleO
#align has_fderiv_within_at.union HasFDerivWithinAt.union
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
#align has_fderiv_within_at.has_fderiv_at HasFDerivWithinAt.hasFDerivAt
theorem DifferentiableWithinAt.differentiableAt (h : DifferentiableWithinAt 𝕜 f s x)
(hs : s ∈ 𝓝 x) : DifferentiableAt 𝕜 f x :=
h.imp fun _ hf' => hf'.hasFDerivAt hs
#align differentiable_within_at.differentiable_at DifferentiableWithinAt.differentiableAt
/-- If `x` is isolated in `s`, then `f` has any derivative at `x` within `s`,
as this statement is empty. -/
theorem HasFDerivWithinAt.of_nhdsWithin_eq_bot (h : 𝓝[s\{x}] x = ⊥) :
HasFDerivWithinAt f f' s x := by
rw [← hasFDerivWithinAt_diff_singleton x, HasFDerivWithinAt, h, hasFDerivAtFilter_iff_isLittleO]
apply isLittleO_bot
/-- 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_nmem_closure (h : x ∉ closure s) : HasFDerivWithinAt f f' s x :=
.of_nhdsWithin_eq_bot <| eq_bot_mono (nhdsWithin_mono _ diff_subset) <| by
rwa [mem_closure_iff_nhdsWithin_neBot, not_neBot] at h
#align has_fderiv_within_at_of_not_mem_closure hasFDerivWithinAt_of_nmem_closure
theorem DifferentiableWithinAt.hasFDerivWithinAt (h : DifferentiableWithinAt 𝕜 f s x) :
HasFDerivWithinAt f (fderivWithin 𝕜 f s x) s x := by
by_cases H : 𝓝[s \ {x}] x = ⊥
· exact .of_nhdsWithin_eq_bot H
· unfold DifferentiableWithinAt at h
rw [fderivWithin, if_neg H, dif_pos h]
exact Classical.choose_spec h
#align differentiable_within_at.has_fderiv_within_at DifferentiableWithinAt.hasFDerivWithinAt
theorem DifferentiableAt.hasFDerivAt (h : DifferentiableAt 𝕜 f x) :
HasFDerivAt f (fderiv 𝕜 f x) x := by
dsimp only [DifferentiableAt] at h
rw [fderiv, dif_pos h]
exact Classical.choose_spec h
#align differentiable_at.has_fderiv_at DifferentiableAt.hasFDerivAt
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
#align differentiable_on.has_fderiv_at DifferentiableOn.hasFDerivAt
theorem DifferentiableOn.differentiableAt (h : DifferentiableOn 𝕜 f s) (hs : s ∈ 𝓝 x) :
DifferentiableAt 𝕜 f x :=
(h.hasFDerivAt hs).differentiableAt
#align differentiable_on.differentiable_at DifferentiableOn.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
#align differentiable_on.eventually_differentiable_at DifferentiableOn.eventually_differentiableAt
protected theorem HasFDerivAt.fderiv (h : HasFDerivAt f f' x) : fderiv 𝕜 f x = f' := by
ext
rw [h.unique h.differentiableAt.hasFDerivAt]
#align has_fderiv_at.fderiv HasFDerivAt.fderiv
theorem fderiv_eq {f' : E → E →L[𝕜] F} (h : ∀ x, HasFDerivAt f (f' x) x) : fderiv 𝕜 f = f' :=
funext fun x => (h x).fderiv
#align fderiv_eq fderiv_eq
variable (𝕜)
/-- Converse to the mean value inequality: if `f` is `C`-lipschitz
on a neighborhood of `x₀` then its derivative at `x₀` has norm bounded by `C`. This version
only assumes that `‖f x - f x₀‖ ≤ C * ‖x - x₀‖` in a neighborhood of `x`. -/
theorem norm_fderiv_le_of_lip' {f : E → F} {x₀ : E}
{C : ℝ} (hC₀ : 0 ≤ C) (hlip : ∀ᶠ x in 𝓝 x₀, ‖f x - f x₀‖ ≤ C * ‖x - x₀‖) :
‖fderiv 𝕜 f x₀‖ ≤ C := by
by_cases hf : DifferentiableAt 𝕜 f x₀
· exact hf.hasFDerivAt.le_of_lip' hC₀ hlip
· rw [fderiv_zero_of_not_differentiableAt hf]
simp [hC₀]
/-- Converse to the mean value inequality: if `f` is `C`-lipschitz
on a neighborhood of `x₀` then its derivative at `x₀` has norm bounded by `C`.
Version using `fderiv`. -/
-- Porting note: renamed so that dot-notation makes sense
theorem norm_fderiv_le_of_lipschitzOn {f : E → F} {x₀ : E} {s : Set E} (hs : s ∈ 𝓝 x₀)
{C : ℝ≥0} (hlip : LipschitzOnWith C f s) : ‖fderiv 𝕜 f x₀‖ ≤ C := by
refine norm_fderiv_le_of_lip' 𝕜 C.coe_nonneg ?_
filter_upwards [hs] with x hx using hlip.norm_sub_le hx (mem_of_mem_nhds hs)
#align fderiv_at.le_of_lip norm_fderiv_le_of_lipschitzOn
/-- Converse to the mean value inequality: if `f` is `C`-lipschitz then
its derivative at `x₀` has norm bounded by `C`.
Version using `fderiv`. -/
theorem norm_fderiv_le_of_lipschitz {f : E → F} {x₀ : E}
{C : ℝ≥0} (hlip : LipschitzWith C f) : ‖fderiv 𝕜 f x₀‖ ≤ C :=
norm_fderiv_le_of_lipschitzOn 𝕜 univ_mem (lipschitzOn_univ.2 hlip)
variable {𝕜}
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
#align has_fderiv_within_at.fderiv_within HasFDerivWithinAt.fderivWithin
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⟩
#align differentiable_within_at.mono DifferentiableWithinAt.mono
theorem DifferentiableWithinAt.mono_of_mem (h : DifferentiableWithinAt 𝕜 f s x) {t : Set E}
(hst : s ∈ 𝓝[t] x) : DifferentiableWithinAt 𝕜 f t x :=
(h.hasFDerivWithinAt.mono_of_mem hst).differentiableWithinAt
#align differentiable_within_at.mono_of_mem DifferentiableWithinAt.mono_of_mem
theorem differentiableWithinAt_univ :
DifferentiableWithinAt 𝕜 f univ x ↔ DifferentiableAt 𝕜 f x := by
simp only [DifferentiableWithinAt, hasFDerivWithinAt_univ, DifferentiableAt]
#align differentiable_within_at_univ differentiableWithinAt_univ
theorem differentiableWithinAt_inter (ht : t ∈ 𝓝 x) :
DifferentiableWithinAt 𝕜 f (s ∩ t) x ↔ DifferentiableWithinAt 𝕜 f s x := by
simp only [DifferentiableWithinAt, hasFDerivWithinAt_inter ht]
#align differentiable_within_at_inter differentiableWithinAt_inter
theorem differentiableWithinAt_inter' (ht : t ∈ 𝓝[s] x) :
DifferentiableWithinAt 𝕜 f (s ∩ t) x ↔ DifferentiableWithinAt 𝕜 f s x := by
simp only [DifferentiableWithinAt, hasFDerivWithinAt_inter' ht]
#align differentiable_within_at_inter' differentiableWithinAt_inter'
theorem DifferentiableAt.differentiableWithinAt (h : DifferentiableAt 𝕜 f x) :
DifferentiableWithinAt 𝕜 f s x :=
(differentiableWithinAt_univ.2 h).mono (subset_univ _)
#align differentiable_at.differentiable_within_at DifferentiableAt.differentiableWithinAt
@[fun_prop]
theorem Differentiable.differentiableAt (h : Differentiable 𝕜 f) : DifferentiableAt 𝕜 f x :=
h x
#align differentiable.differentiable_at Differentiable.differentiableAt
protected theorem DifferentiableAt.fderivWithin (h : DifferentiableAt 𝕜 f x)
(hxs : UniqueDiffWithinAt 𝕜 s x) : fderivWithin 𝕜 f s x = fderiv 𝕜 f x :=
h.hasFDerivAt.hasFDerivWithinAt.fderivWithin hxs
#align differentiable_at.fderiv_within DifferentiableAt.fderivWithin
theorem DifferentiableOn.mono (h : DifferentiableOn 𝕜 f t) (st : s ⊆ t) : DifferentiableOn 𝕜 f s :=
fun x hx => (h x (st hx)).mono st
#align differentiable_on.mono DifferentiableOn.mono
theorem differentiableOn_univ : DifferentiableOn 𝕜 f univ ↔ Differentiable 𝕜 f := by
simp only [DifferentiableOn, Differentiable, differentiableWithinAt_univ, mem_univ,
forall_true_left]
#align differentiable_on_univ differentiableOn_univ
@[fun_prop]
theorem Differentiable.differentiableOn (h : Differentiable 𝕜 f) : DifferentiableOn 𝕜 f s :=
(differentiableOn_univ.2 h).mono (subset_univ _)
#align differentiable.differentiable_on Differentiable.differentiableOn
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⟩)
#align differentiable_on_of_locally_differentiable_on differentiableOn_of_locally_differentiableOn
theorem fderivWithin_of_mem (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 st).fderivWithin ht
#align fderiv_within_of_mem fderivWithin_of_mem
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_mono _ st self_mem_nhdsWithin) ht h
#align fderiv_within_subset fderivWithin_subset
theorem fderivWithin_inter (ht : t ∈ 𝓝 x) : fderivWithin 𝕜 f (s ∩ t) x = fderivWithin 𝕜 f s x := by
have A : 𝓝[(s ∩ t) \ {x}] x = 𝓝[s \ {x}] x := by
have : (s ∩ t) \ {x} = (s \ {x}) ∩ t := by rw [inter_comm, inter_diff_assoc, inter_comm]
rw [this, ← nhdsWithin_restrict' _ ht]
simp [fderivWithin, A, hasFDerivWithinAt_inter ht]
#align fderiv_within_inter fderivWithin_inter
@[simp]
theorem fderivWithin_univ : fderivWithin 𝕜 f univ = fderiv 𝕜 f := by
ext1 x
nontriviality E
have H : 𝓝[univ \ {x}] x ≠ ⊥ := by
rw [← compl_eq_univ_diff, ← neBot_iff]
exact Module.punctured_nhds_neBot 𝕜 E x
simp [fderivWithin, fderiv, H]
#align fderiv_within_univ fderivWithin_univ
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]
#align fderiv_within_of_mem_nhds fderivWithin_of_mem_nhds
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)
#align fderiv_within_of_open fderivWithin_of_isOpen
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
#align fderiv_within_eq_fderiv fderivWithin_eq_fderiv
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, *]
#align fderiv_mem_iff fderiv_mem_iff
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, *]
#align fderiv_within_mem_iff fderivWithin_mem_iff
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)]
set_option linter.uppercaseLean3 false in
#align asymptotics.is_O.has_fderiv_within_at Asymptotics.IsBigO.hasFDerivWithinAt
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
set_option linter.uppercaseLean3 false in
#align asymptotics.is_O.has_fderiv_at Asymptotics.IsBigO.hasFDerivAt
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
set_option linter.uppercaseLean3 false in
#align has_fderiv_within_at.is_O HasFDerivWithinAt.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
set_option linter.uppercaseLean3 false in
#align has_fderiv_at.is_O HasFDerivAt.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])
#align has_fderiv_at_filter.tendsto_nhds HasFDerivAtFilter.tendsto_nhds
theorem HasFDerivWithinAt.continuousWithinAt (h : HasFDerivWithinAt f f' s x) :
ContinuousWithinAt f s x :=
HasFDerivAtFilter.tendsto_nhds inf_le_left h
#align has_fderiv_within_at.continuous_within_at HasFDerivWithinAt.continuousWithinAt
theorem HasFDerivAt.continuousAt (h : HasFDerivAt f f' x) : ContinuousAt f x :=
HasFDerivAtFilter.tendsto_nhds le_rfl h
#align has_fderiv_at.continuous_at HasFDerivAt.continuousAt
@[fun_prop]
theorem DifferentiableWithinAt.continuousWithinAt (h : DifferentiableWithinAt 𝕜 f s x) :
ContinuousWithinAt f s x :=
let ⟨_, hf'⟩ := h
hf'.continuousWithinAt
#align differentiable_within_at.continuous_within_at DifferentiableWithinAt.continuousWithinAt
@[fun_prop]
theorem DifferentiableAt.continuousAt (h : DifferentiableAt 𝕜 f x) : ContinuousAt f x :=
let ⟨_, hf'⟩ := h
hf'.continuousAt
#align differentiable_at.continuous_at DifferentiableAt.continuousAt
@[fun_prop]
theorem DifferentiableOn.continuousOn (h : DifferentiableOn 𝕜 f s) : ContinuousOn f s := fun x hx =>
(h x hx).continuousWithinAt
#align differentiable_on.continuous_on DifferentiableOn.continuousOn
@[fun_prop]
theorem Differentiable.continuous (h : Differentiable 𝕜 f) : Continuous f :=
continuous_iff_continuousAt.2 fun x => (h x).continuousAt
#align differentiable.continuous Differentiable.continuous
protected theorem HasStrictFDerivAt.continuousAt (hf : HasStrictFDerivAt f f' x) :
ContinuousAt f x :=
hf.hasFDerivAt.continuousAt
#align has_strict_fderiv_at.continuous_at HasStrictFDerivAt.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.trans_isBigO (f'.isBigO_comp_rev _ _)).right_isBigO_add).congr
(fun _ => rfl) fun _ => sub_add_cancel _ _
set_option linter.uppercaseLean3 false in
#align has_strict_fderiv_at.is_O_sub_rev HasStrictFDerivAt.isBigO_sub_rev
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 _ _
set_option linter.uppercaseLean3 false in
#align has_fderiv_at_filter.is_O_sub_rev HasFDerivAtFilter.isBigO_sub_rev
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 _
#align has_fderiv_within_at_congr_set' hasFDerivWithinAt_congr_set'
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
#align has_fderiv_within_at_congr_set hasFDerivWithinAt_congr_set
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
#align differentiable_within_at_congr_set' differentiableWithinAt_congr_set'
theorem differentiableWithinAt_congr_set (h : s =ᶠ[𝓝 x] t) :
DifferentiableWithinAt 𝕜 f s x ↔ DifferentiableWithinAt 𝕜 f t x :=
exists_congr fun _ => hasFDerivWithinAt_congr_set h
#align differentiable_within_at_congr_set differentiableWithinAt_congr_set
theorem fderivWithin_congr_set' (y : E) (h : s =ᶠ[𝓝[{y}ᶜ] x] t) :
fderivWithin 𝕜 f s x = fderivWithin 𝕜 f t x := by
have : s =ᶠ[𝓝[{x}ᶜ] x] t := nhdsWithin_compl_singleton_le x y h
have : 𝓝[s \ {x}] x = 𝓝[t \ {x}] x := by
simpa only [set_eventuallyEq_iff_inf_principal, ← nhdsWithin_inter', diff_eq,
inter_comm] using this
simp only [fderivWithin, hasFDerivWithinAt_congr_set' y h, this]
#align fderiv_within_congr_set' fderivWithin_congr_set'
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
#align fderiv_within_congr_set fderivWithin_congr_set
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
#align fderiv_within_eventually_congr_set' fderivWithin_eventually_congr_set'
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
#align fderiv_within_eventually_congr_set fderivWithin_eventually_congr_set
theorem Filter.EventuallyEq.hasStrictFDerivAt_iff (h : f₀ =ᶠ[𝓝 x] f₁) (h' : ∀ y, f₀' y = f₁' y) :
HasStrictFDerivAt f₀ f₀' x ↔ HasStrictFDerivAt f₁ f₁' x := by
refine isLittleO_congr ((h.prod_mk_nhds h).mono ?_) .rfl
rintro p ⟨hp₁, hp₂⟩
simp only [*]
#align filter.eventually_eq.has_strict_fderiv_at_iff Filter.EventuallyEq.hasStrictFDerivAt_iff
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
#align has_strict_fderiv_at.congr_of_eventually_eq HasStrictFDerivAt.congr_of_eventuallyEq
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_isLittleO]
exact isLittleO_congr (h₀.mono fun y hy => by simp only [hy, h₁, hx]) .rfl
#align filter.eventually_eq.has_fderiv_at_filter_iff Filter.EventuallyEq.hasFDerivAtFilter_iff
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
#align has_fderiv_at_filter.congr_of_eventually_eq HasFDerivAtFilter.congr_of_eventuallyEq
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
#align filter.eventually_eq.has_fderiv_at_iff Filter.EventuallyEq.hasFDerivAt_iff
theorem Filter.EventuallyEq.differentiableAt_iff (h : f₀ =ᶠ[𝓝 x] f₁) :
DifferentiableAt 𝕜 f₀ x ↔ DifferentiableAt 𝕜 f₁ x :=
exists_congr fun _ => h.hasFDerivAt_iff
#align filter.eventually_eq.differentiable_at_iff Filter.EventuallyEq.differentiableAt_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
#align filter.eventually_eq.has_fderiv_within_at_iff Filter.EventuallyEq.hasFDerivWithinAt_iff
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)
#align filter.eventually_eq.has_fderiv_within_at_iff_of_mem Filter.EventuallyEq.hasFDerivWithinAt_iff_of_mem
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
#align filter.eventually_eq.differentiable_within_at_iff Filter.EventuallyEq.differentiableWithinAt_iff
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)
#align filter.eventually_eq.differentiable_within_at_iff_of_mem Filter.EventuallyEq.differentiableWithinAt_iff_of_mem
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
#align has_fderiv_within_at.congr_mono HasFDerivWithinAt.congr_mono
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 _)
#align has_fderiv_within_at.congr HasFDerivWithinAt.congr
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)
#align has_fderiv_within_at.congr' HasFDerivWithinAt.congr'
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
#align has_fderiv_within_at.congr_of_eventually_eq HasFDerivWithinAt.congr_of_eventuallyEq
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₁ : _)
#align has_fderiv_at.congr_of_eventually_eq HasFDerivAt.congr_of_eventuallyEq
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
#align differentiable_within_at.congr_mono DifferentiableWithinAt.congr_mono
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 _)
#align differentiable_within_at.congr DifferentiableWithinAt.congr
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
#align differentiable_within_at.congr_of_eventually_eq DifferentiableWithinAt.congr_of_eventuallyEq
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₁
#align differentiable_on.congr_mono DifferentiableOn.congr_mono
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)
#align differentiable_on.congr DifferentiableOn.congr
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'⟩
#align differentiable_on_congr differentiableOn_congr
theorem DifferentiableAt.congr_of_eventuallyEq (h : DifferentiableAt 𝕜 f x) (hL : f₁ =ᶠ[𝓝 x] f) :
DifferentiableAt 𝕜 f₁ x :=
hL.differentiableAt_iff.2 h
#align differentiable_at.congr_of_eventually_eq DifferentiableAt.congr_of_eventuallyEq
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
#align differentiable_within_at.fderiv_within_congr_mono DifferentiableWithinAt.fderivWithin_congr_mono
| Mathlib/Analysis/Calculus/FDeriv/Basic.lean | 1,029 | 1,031 | theorem Filter.EventuallyEq.fderivWithin_eq (hs : f₁ =ᶠ[𝓝[s] x] f) (hx : f₁ x = f x) :
fderivWithin 𝕜 f₁ s x = fderivWithin 𝕜 f s x := by |
simp only [fderivWithin, hs.hasFDerivWithinAt_iff hx]
|
/-
Copyright (c) 2015 Nathaniel Thomas. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Nathaniel Thomas, Jeremy Avigad, Johannes Hölzl, Mario Carneiro
-/
import Mathlib.Algebra.Group.Hom.End
import Mathlib.Algebra.Ring.Invertible
import Mathlib.Algebra.SMulWithZero
import Mathlib.Data.Int.Cast.Lemmas
import Mathlib.GroupTheory.GroupAction.Units
#align_import algebra.module.basic from "leanprover-community/mathlib"@"30413fc89f202a090a54d78e540963ed3de0056e"
/-!
# Modules over a ring
In this file we define
* `Module R M` : an additive commutative monoid `M` is a `Module` over a
`Semiring R` if for `r : R` and `x : M` their "scalar multiplication" `r • x : M` is defined, and
the operation `•` satisfies some natural associativity and distributivity axioms similar to those
on a ring.
## Implementation notes
In typical mathematical usage, our definition of `Module` corresponds to "semimodule", and the
word "module" is reserved for `Module R M` where `R` is a `Ring` and `M` an `AddCommGroup`.
If `R` is a `Field` and `M` an `AddCommGroup`, `M` would be called an `R`-vector space.
Since those assumptions can be made by changing the typeclasses applied to `R` and `M`,
without changing the axioms in `Module`, mathlib calls everything a `Module`.
In older versions of mathlib3, we had separate abbreviations for semimodules and vector spaces.
This caused inference issues in some cases, while not providing any real advantages, so we decided
to use a canonical `Module` typeclass throughout.
## Tags
semimodule, module, vector space
-/
assert_not_exists Multiset
assert_not_exists Set.indicator
assert_not_exists Pi.single_smul₀
open Function Set
universe u v
variable {α R k S M M₂ M₃ ι : Type*}
/-- A module is a generalization of vector spaces to a scalar semiring.
It consists of a scalar semiring `R` and an additive monoid of "vectors" `M`,
connected by a "scalar multiplication" operation `r • x : M`
(where `r : R` and `x : M`) with some natural associativity and
distributivity axioms similar to those on a ring. -/
@[ext]
class Module (R : Type u) (M : Type v) [Semiring R] [AddCommMonoid M] extends
DistribMulAction R M where
/-- Scalar multiplication distributes over addition from the right. -/
protected add_smul : ∀ (r s : R) (x : M), (r + s) • x = r • x + s • x
/-- Scalar multiplication by zero gives zero. -/
protected zero_smul : ∀ x : M, (0 : R) • x = 0
#align module Module
#align module.ext Module.ext
#align module.ext_iff Module.ext_iff
section AddCommMonoid
variable [Semiring R] [AddCommMonoid M] [Module R M] (r s : R) (x y : M)
-- see Note [lower instance priority]
/-- A module over a semiring automatically inherits a `MulActionWithZero` structure. -/
instance (priority := 100) Module.toMulActionWithZero : MulActionWithZero R M :=
{ (inferInstance : MulAction R M) with
smul_zero := smul_zero
zero_smul := Module.zero_smul }
#align module.to_mul_action_with_zero Module.toMulActionWithZero
instance AddCommMonoid.natModule : Module ℕ M where
one_smul := one_nsmul
mul_smul m n a := mul_nsmul' a m n
smul_add n a b := nsmul_add a b n
smul_zero := nsmul_zero
zero_smul := zero_nsmul
add_smul r s x := add_nsmul x r s
#align add_comm_monoid.nat_module AddCommMonoid.natModule
theorem AddMonoid.End.natCast_def (n : ℕ) :
(↑n : AddMonoid.End M) = DistribMulAction.toAddMonoidEnd ℕ M n :=
rfl
#align add_monoid.End.nat_cast_def AddMonoid.End.natCast_def
theorem add_smul : (r + s) • x = r • x + s • x :=
Module.add_smul r s x
#align add_smul add_smul
theorem Convex.combo_self {a b : R} (h : a + b = 1) (x : M) : a • x + b • x = x := by
rw [← add_smul, h, one_smul]
#align convex.combo_self Convex.combo_self
variable (R)
-- Porting note: this is the letter of the mathlib3 version, but not really the spirit
theorem two_smul : (2 : R) • x = x + x := by rw [← one_add_one_eq_two, add_smul, one_smul]
#align two_smul two_smul
set_option linter.deprecated false in
@[deprecated]
theorem two_smul' : (2 : R) • x = bit0 x :=
two_smul R x
#align two_smul' two_smul'
@[simp]
theorem invOf_two_smul_add_invOf_two_smul [Invertible (2 : R)] (x : M) :
(⅟ 2 : R) • x + (⅟ 2 : R) • x = x :=
Convex.combo_self invOf_two_add_invOf_two _
#align inv_of_two_smul_add_inv_of_two_smul invOf_two_smul_add_invOf_two_smul
/-- Pullback a `Module` structure along an injective additive monoid homomorphism.
See note [reducible non-instances]. -/
protected abbrev Function.Injective.module [AddCommMonoid M₂] [SMul R M₂] (f : M₂ →+ M)
(hf : Injective f) (smul : ∀ (c : R) (x), f (c • x) = c • f x) : Module R M₂ :=
{ hf.distribMulAction f smul with
add_smul := fun c₁ c₂ x => hf <| by simp only [smul, f.map_add, add_smul]
zero_smul := fun x => hf <| by simp only [smul, zero_smul, f.map_zero] }
#align function.injective.module Function.Injective.module
/-- Pushforward a `Module` structure along a surjective additive monoid homomorphism.
See note [reducible non-instances]. -/
protected abbrev Function.Surjective.module [AddCommMonoid M₂] [SMul R M₂] (f : M →+ M₂)
(hf : Surjective f) (smul : ∀ (c : R) (x), f (c • x) = c • f x) : Module R M₂ :=
{ toDistribMulAction := hf.distribMulAction f smul
add_smul := fun c₁ c₂ x => by
rcases hf x with ⟨x, rfl⟩
simp only [add_smul, ← smul, ← f.map_add]
zero_smul := fun x => by
rcases hf x with ⟨x, rfl⟩
rw [← f.map_zero, ← smul, zero_smul] }
#align function.surjective.module Function.Surjective.module
/-- Push forward the action of `R` on `M` along a compatible surjective map `f : R →+* S`.
See also `Function.Surjective.mulActionLeft` and `Function.Surjective.distribMulActionLeft`.
-/
abbrev Function.Surjective.moduleLeft {R S M : Type*} [Semiring R] [AddCommMonoid M] [Module R M]
[Semiring S] [SMul S M] (f : R →+* S) (hf : Function.Surjective f)
(hsmul : ∀ (c) (x : M), f c • x = c • x) : Module S M :=
{ hf.distribMulActionLeft f.toMonoidHom hsmul with
zero_smul := fun x => by rw [← f.map_zero, hsmul, zero_smul]
add_smul := hf.forall₂.mpr fun a b x => by simp only [← f.map_add, hsmul, add_smul] }
#align function.surjective.module_left Function.Surjective.moduleLeft
variable {R} (M)
/-- Compose a `Module` with a `RingHom`, with action `f s • m`.
See note [reducible non-instances]. -/
abbrev Module.compHom [Semiring S] (f : S →+* R) : Module S M :=
{ MulActionWithZero.compHom M f.toMonoidWithZeroHom, DistribMulAction.compHom M (f : S →* R) with
-- Porting note: the `show f (r + s) • x = f r • x + f s • x` wasn't needed in mathlib3.
-- Somehow, now that `SMul` is heterogeneous, it can't unfold earlier fields of a definition for
-- use in later fields. See
-- https://leanprover.zulipchat.com/#narrow/stream/287929-mathlib4/topic/Heterogeneous.20scalar.20multiplication
add_smul := fun r s x => show f (r + s) • x = f r • x + f s • x by simp [add_smul] }
#align module.comp_hom Module.compHom
variable (R)
/-- `(•)` as an `AddMonoidHom`.
This is a stronger version of `DistribMulAction.toAddMonoidEnd` -/
@[simps! apply_apply]
def Module.toAddMonoidEnd : R →+* AddMonoid.End M :=
{ DistribMulAction.toAddMonoidEnd R M with
-- Porting note: the two `show`s weren't needed in mathlib3.
-- Somehow, now that `SMul` is heterogeneous, it can't unfold earlier fields of a definition for
-- use in later fields. See
-- https://leanprover.zulipchat.com/#narrow/stream/287929-mathlib4/topic/Heterogeneous.20scalar.20multiplication
map_zero' := AddMonoidHom.ext fun r => show (0:R) • r = 0 by simp
map_add' := fun x y =>
AddMonoidHom.ext fun r => show (x + y) • r = x • r + y • r by simp [add_smul] }
#align module.to_add_monoid_End Module.toAddMonoidEnd
#align module.to_add_monoid_End_apply_apply Module.toAddMonoidEnd_apply_apply
/-- A convenience alias for `Module.toAddMonoidEnd` as an `AddMonoidHom`, usually to allow the
use of `AddMonoidHom.flip`. -/
def smulAddHom : R →+ M →+ M :=
(Module.toAddMonoidEnd R M).toAddMonoidHom
#align smul_add_hom smulAddHom
variable {R M}
@[simp]
theorem smulAddHom_apply (r : R) (x : M) : smulAddHom R M r x = r • x :=
rfl
#align smul_add_hom_apply smulAddHom_apply
theorem Module.eq_zero_of_zero_eq_one (zero_eq_one : (0 : R) = 1) : x = 0 := by
rw [← one_smul R x, ← zero_eq_one, zero_smul]
#align module.eq_zero_of_zero_eq_one Module.eq_zero_of_zero_eq_one
@[simp]
theorem smul_add_one_sub_smul {R : Type*} [Ring R] [Module R M] {r : R} {m : M} :
r • m + (1 - r) • m = m := by rw [← add_smul, add_sub_cancel, one_smul]
#align smul_add_one_sub_smul smul_add_one_sub_smul
end AddCommMonoid
section AddCommGroup
variable (R M) [Semiring R] [AddCommGroup M]
instance AddCommGroup.intModule : Module ℤ M where
one_smul := one_zsmul
mul_smul m n a := mul_zsmul a m n
smul_add n a b := zsmul_add a b n
smul_zero := zsmul_zero
zero_smul := zero_zsmul
add_smul r s x := add_zsmul x r s
#align add_comm_group.int_module AddCommGroup.intModule
theorem AddMonoid.End.intCast_def (z : ℤ) :
(↑z : AddMonoid.End M) = DistribMulAction.toAddMonoidEnd ℤ M z :=
rfl
#align add_monoid.End.int_cast_def AddMonoid.End.intCast_def
variable {R M}
theorem Convex.combo_eq_smul_sub_add [Module R M] {x y : M} {a b : R} (h : a + b = 1) :
a • x + b • y = b • (y - x) + x :=
calc
a • x + b • y = b • y - b • x + (a • x + b • x) := by rw [sub_add_add_cancel, add_comm]
_ = b • (y - x) + x := by rw [smul_sub, Convex.combo_self h]
#align convex.combo_eq_smul_sub_add Convex.combo_eq_smul_sub_add
end AddCommGroup
-- We'll later use this to show `Module ℕ M` and `Module ℤ M` are subsingletons.
/-- A variant of `Module.ext` that's convenient for term-mode. -/
theorem Module.ext' {R : Type*} [Semiring R] {M : Type*} [AddCommMonoid M] (P Q : Module R M)
(w : ∀ (r : R) (m : M), (haveI := P; r • m) = (haveI := Q; r • m)) :
P = Q := by
ext
exact w _ _
#align module.ext' Module.ext'
section Module
variable [Ring R] [AddCommGroup M] [Module R M] (r s : R) (x y : M)
@[simp]
theorem neg_smul : -r • x = -(r • x) :=
eq_neg_of_add_eq_zero_left <| by rw [← add_smul, add_left_neg, zero_smul]
#align neg_smul neg_smul
-- Porting note (#10618): simp can prove this
--@[simp]
theorem neg_smul_neg : -r • -x = r • x := by rw [neg_smul, smul_neg, neg_neg]
#align neg_smul_neg neg_smul_neg
@[simp]
theorem Units.neg_smul (u : Rˣ) (x : M) : -u • x = -(u • x) := by
rw [Units.smul_def, Units.val_neg, _root_.neg_smul, Units.smul_def]
#align units.neg_smul Units.neg_smul
variable (R)
theorem neg_one_smul (x : M) : (-1 : R) • x = -x := by simp
#align neg_one_smul neg_one_smul
variable {R}
theorem sub_smul (r s : R) (y : M) : (r - s) • y = r • y - s • y := by
simp [add_smul, sub_eq_add_neg]
#align sub_smul sub_smul
end Module
variable (R)
/-- An `AddCommMonoid` that is a `Module` over a `Ring` carries a natural `AddCommGroup`
structure.
See note [reducible non-instances]. -/
abbrev Module.addCommMonoidToAddCommGroup
[Ring R] [AddCommMonoid M] [Module R M] : AddCommGroup M :=
{ (inferInstance : AddCommMonoid M) with
neg := fun a => (-1 : R) • a
add_left_neg := fun a =>
show (-1 : R) • a + a = 0 by
nth_rw 2 [← one_smul R a]
rw [← add_smul, add_left_neg, zero_smul]
zsmul := fun z a => (z : R) • a
zsmul_zero' := fun a => by simpa only [Int.cast_zero] using zero_smul R a
zsmul_succ' := fun z a => by simp [add_comm, add_smul]
zsmul_neg' := fun z a => by simp [← smul_assoc, neg_one_smul] }
#align module.add_comm_monoid_to_add_comm_group Module.addCommMonoidToAddCommGroup
variable {R}
/-- A module over a `Subsingleton` semiring is a `Subsingleton`. We cannot register this
as an instance because Lean has no way to guess `R`. -/
protected theorem Module.subsingleton (R M : Type*) [Semiring R] [Subsingleton R] [AddCommMonoid M]
[Module R M] : Subsingleton M :=
MulActionWithZero.subsingleton R M
#align module.subsingleton Module.subsingleton
/-- A semiring is `Nontrivial` provided that there exists a nontrivial module over this semiring. -/
protected theorem Module.nontrivial (R M : Type*) [Semiring R] [Nontrivial M] [AddCommMonoid M]
[Module R M] : Nontrivial R :=
MulActionWithZero.nontrivial R M
#align module.nontrivial Module.nontrivial
-- see Note [lower instance priority]
instance (priority := 910) Semiring.toModule [Semiring R] : Module R R where
smul_add := mul_add
add_smul := add_mul
zero_smul := zero_mul
smul_zero := mul_zero
#align semiring.to_module Semiring.toModule
-- see Note [lower instance priority]
/-- Like `Semiring.toModule`, but multiplies on the right. -/
instance (priority := 910) Semiring.toOppositeModule [Semiring R] : Module Rᵐᵒᵖ R :=
{ MonoidWithZero.toOppositeMulActionWithZero R with
smul_add := fun _ _ _ => add_mul _ _ _
add_smul := fun _ _ _ => mul_add _ _ _ }
#align semiring.to_opposite_module Semiring.toOppositeModule
/-- A ring homomorphism `f : R →+* M` defines a module structure by `r • x = f r * x`. -/
def RingHom.toModule [Semiring R] [Semiring S] (f : R →+* S) : Module R S :=
Module.compHom S f
#align ring_hom.to_module RingHom.toModule
/-- If the module action of `R` on `S` is compatible with multiplication on `S`, then
`fun x ↦ x • 1` is a ring homomorphism from `R` to `S`.
This is the `RingHom` version of `MonoidHom.smulOneHom`.
When `R` is commutative, usually `algebraMap` should be preferred. -/
@[simps!] def RingHom.smulOneHom
[Semiring R] [NonAssocSemiring S] [Module R S] [IsScalarTower R S S] : R →+* S where
__ := MonoidHom.smulOneHom
map_zero' := zero_smul R 1
map_add' := (add_smul · · 1)
/-- A homomorphism between semirings R and S can be equivalently specified by a R-module
structure on S such that S/S/R is a scalar tower. -/
def ringHomEquivModuleIsScalarTower [Semiring R] [Semiring S] :
(R →+* S) ≃ {_inst : Module R S // IsScalarTower R S S} where
toFun f := ⟨Module.compHom S f, SMul.comp.isScalarTower _⟩
invFun := fun ⟨_, _⟩ ↦ RingHom.smulOneHom
left_inv f := RingHom.ext fun r ↦ mul_one (f r)
right_inv := fun ⟨_, _⟩ ↦ Subtype.ext <| Module.ext _ _ <| funext₂ <| smul_one_smul S
section AddCommMonoid
variable [Semiring R] [AddCommMonoid M] [Module R M]
section
variable (R)
/-- `nsmul` is equal to any other module structure via a cast. -/
theorem nsmul_eq_smul_cast (n : ℕ) (b : M) : n • b = (n : R) • b := by
induction' n with n ih
· rw [Nat.cast_zero, zero_smul, zero_smul]
· rw [Nat.cast_succ, add_smul, add_smul, one_smul, ih, one_smul]
#align nsmul_eq_smul_cast nsmul_eq_smul_cast
end
/-- Convert back any exotic `ℕ`-smul to the canonical instance. This should not be needed since in
mathlib all `AddCommMonoid`s should normally have exactly one `ℕ`-module structure by design.
-/
theorem nat_smul_eq_nsmul (h : Module ℕ M) (n : ℕ) (x : M) :
@SMul.smul ℕ M h.toSMul n x = n • x := by rw [nsmul_eq_smul_cast ℕ n x, Nat.cast_id]; rfl
#align nat_smul_eq_nsmul nat_smul_eq_nsmul
/-- All `ℕ`-module structures are equal. Not an instance since in mathlib all `AddCommMonoid`
should normally have exactly one `ℕ`-module structure by design. -/
def AddCommMonoid.natModule.unique : Unique (Module ℕ M) where
default := by infer_instance
uniq P := (Module.ext' P _) fun n => by convert nat_smul_eq_nsmul P n
#align add_comm_monoid.nat_module.unique AddCommMonoid.natModule.unique
instance AddCommMonoid.nat_isScalarTower : IsScalarTower ℕ R M where
smul_assoc n x y :=
Nat.recOn n (by simp only [Nat.zero_eq, zero_smul])
fun n ih => by simp only [Nat.succ_eq_add_one, add_smul, one_smul, ih]
#align add_comm_monoid.nat_is_scalar_tower AddCommMonoid.nat_isScalarTower
end AddCommMonoid
section AddCommGroup
variable [Semiring S] [Ring R] [AddCommGroup M] [Module S M] [Module R M]
section
variable (R)
/-- `zsmul` is equal to any other module structure via a cast. -/
theorem zsmul_eq_smul_cast (n : ℤ) (b : M) : n • b = (n : R) • b :=
have : (smulAddHom ℤ M).flip b = ((smulAddHom R M).flip b).comp (Int.castAddHom R) := by
apply AddMonoidHom.ext_int
simp
DFunLike.congr_fun this n
#align zsmul_eq_smul_cast zsmul_eq_smul_cast
end
/-- Convert back any exotic `ℤ`-smul to the canonical instance. This should not be needed since in
mathlib all `AddCommGroup`s should normally have exactly one `ℤ`-module structure by design. -/
theorem int_smul_eq_zsmul (h : Module ℤ M) (n : ℤ) (x : M) :
@SMul.smul ℤ M h.toSMul n x = n • x := by rw [zsmul_eq_smul_cast ℤ n x, Int.cast_id]; rfl
#align int_smul_eq_zsmul int_smul_eq_zsmul
/-- All `ℤ`-module structures are equal. Not an instance since in mathlib all `AddCommGroup`
should normally have exactly one `ℤ`-module structure by design. -/
def AddCommGroup.intModule.unique : Unique (Module ℤ M) where
default := by infer_instance
uniq P := (Module.ext' P _) fun n => by convert int_smul_eq_zsmul P n
#align add_comm_group.int_module.unique AddCommGroup.intModule.unique
end AddCommGroup
theorem map_intCast_smul [AddCommGroup M] [AddCommGroup M₂] {F : Type*} [FunLike F M M₂]
[AddMonoidHomClass F M M₂] (f : F) (R S : Type*) [Ring R] [Ring S] [Module R M] [Module S M₂]
(x : ℤ) (a : M) :
f ((x : R) • a) = (x : S) • f a := by simp only [← zsmul_eq_smul_cast, map_zsmul]
#align map_int_cast_smul map_intCast_smul
theorem map_natCast_smul [AddCommMonoid M] [AddCommMonoid M₂] {F : Type*} [FunLike F M M₂]
[AddMonoidHomClass F M M₂] (f : F) (R S : Type*) [Semiring R] [Semiring S] [Module R M]
[Module S M₂] (x : ℕ) (a : M) : f ((x : R) • a) = (x : S) • f a := by
simp only [← nsmul_eq_smul_cast, AddMonoidHom.map_nsmul, map_nsmul]
#align map_nat_cast_smul map_natCast_smul
instance AddCommGroup.intIsScalarTower {R : Type u} {M : Type v} [Ring R] [AddCommGroup M]
[Module R M] : IsScalarTower ℤ R M where
smul_assoc n x y := ((smulAddHom R M).flip y).map_zsmul x n
#align add_comm_group.int_is_scalar_tower AddCommGroup.intIsScalarTower
section NoZeroSMulDivisors
/-! ### `NoZeroSMulDivisors`
This section defines the `NoZeroSMulDivisors` class, and includes some tests
for the vanishing of elements (especially in modules over division rings).
-/
/-- `NoZeroSMulDivisors R M` states that a scalar multiple is `0` only if either argument is `0`.
This is a version of saying that `M` is torsion free, without assuming `R` is zero-divisor free.
The main application of `NoZeroSMulDivisors R M`, when `M` is a module,
is the result `smul_eq_zero`: a scalar multiple is `0` iff either argument is `0`.
It is a generalization of the `NoZeroDivisors` class to heterogeneous multiplication.
-/
@[mk_iff]
class NoZeroSMulDivisors (R M : Type*) [Zero R] [Zero M] [SMul R M] : Prop where
/-- If scalar multiplication yields zero, either the scalar or the vector was zero. -/
eq_zero_or_eq_zero_of_smul_eq_zero : ∀ {c : R} {x : M}, c • x = 0 → c = 0 ∨ x = 0
#align no_zero_smul_divisors NoZeroSMulDivisors
export NoZeroSMulDivisors (eq_zero_or_eq_zero_of_smul_eq_zero)
/-- Pullback a `NoZeroSMulDivisors` instance along an injective function. -/
theorem Function.Injective.noZeroSMulDivisors {R M N : Type*} [Zero R] [Zero M] [Zero N]
[SMul R M] [SMul R N] [NoZeroSMulDivisors R N] (f : M → N) (hf : Function.Injective f)
(h0 : f 0 = 0) (hs : ∀ (c : R) (x : M), f (c • x) = c • f x) : NoZeroSMulDivisors R M :=
⟨fun {_ _} h =>
Or.imp_right (@hf _ _) <| h0.symm ▸ eq_zero_or_eq_zero_of_smul_eq_zero (by rw [← hs, h, h0])⟩
#align function.injective.no_zero_smul_divisors Function.Injective.noZeroSMulDivisors
-- See note [lower instance priority]
instance (priority := 100) NoZeroDivisors.toNoZeroSMulDivisors [Zero R] [Mul R]
[NoZeroDivisors R] : NoZeroSMulDivisors R R :=
⟨fun {_ _} => eq_zero_or_eq_zero_of_mul_eq_zero⟩
#align no_zero_divisors.to_no_zero_smul_divisors NoZeroDivisors.toNoZeroSMulDivisors
theorem smul_ne_zero [Zero R] [Zero M] [SMul R M] [NoZeroSMulDivisors R M] {c : R} {x : M}
(hc : c ≠ 0) (hx : x ≠ 0) : c • x ≠ 0 := fun h =>
(eq_zero_or_eq_zero_of_smul_eq_zero h).elim hc hx
#align smul_ne_zero smul_ne_zero
section SMulWithZero
variable [Zero R] [Zero M] [SMulWithZero R M] [NoZeroSMulDivisors R M] {c : R} {x : M}
@[simp]
theorem smul_eq_zero : c • x = 0 ↔ c = 0 ∨ x = 0 :=
⟨eq_zero_or_eq_zero_of_smul_eq_zero, fun h =>
h.elim (fun h => h.symm ▸ zero_smul R x) fun h => h.symm ▸ smul_zero c⟩
#align smul_eq_zero smul_eq_zero
| Mathlib/Algebra/Module/Defs.lean | 499 | 499 | theorem smul_ne_zero_iff : c • x ≠ 0 ↔ c ≠ 0 ∧ x ≠ 0 := by | rw [Ne, smul_eq_zero, not_or]
|
/-
Copyright (c) 2021 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin
-/
import Mathlib.Analysis.Normed.Group.Basic
#align_import analysis.normed.group.hom from "leanprover-community/mathlib"@"3c4225288b55380a90df078ebae0991080b12393"
/-!
# Normed groups homomorphisms
This file gathers definitions and elementary constructions about bounded group homomorphisms
between normed (abelian) groups (abbreviated to "normed group homs").
The main lemmas relate the boundedness condition to continuity and Lipschitzness.
The main construction is to endow the type of normed group homs between two given normed groups
with a group structure and a norm, giving rise to a normed group structure. We provide several
simple constructions for normed group homs, like kernel, range and equalizer.
Some easy other constructions are related to subgroups of normed groups.
Since a lot of elementary properties don't require `‖x‖ = 0 → x = 0` we start setting up the
theory of `SeminormedAddGroupHom` and we specialize to `NormedAddGroupHom` when needed.
-/
noncomputable section
open NNReal
-- TODO: migrate to the new morphism / morphism_class style
/-- A morphism of seminormed abelian groups is a bounded group homomorphism. -/
structure NormedAddGroupHom (V W : Type*) [SeminormedAddCommGroup V]
[SeminormedAddCommGroup W] where
/-- The function underlying a `NormedAddGroupHom` -/
toFun : V → W
/-- A `NormedAddGroupHom` is additive. -/
map_add' : ∀ v₁ v₂, toFun (v₁ + v₂) = toFun v₁ + toFun v₂
/-- A `NormedAddGroupHom` is bounded. -/
bound' : ∃ C, ∀ v, ‖toFun v‖ ≤ C * ‖v‖
#align normed_add_group_hom NormedAddGroupHom
namespace AddMonoidHom
variable {V W : Type*} [SeminormedAddCommGroup V] [SeminormedAddCommGroup W]
{f g : NormedAddGroupHom V W}
/-- Associate to a group homomorphism a bounded group homomorphism under a norm control condition.
See `AddMonoidHom.mkNormedAddGroupHom'` for a version that uses `ℝ≥0` for the bound. -/
def mkNormedAddGroupHom (f : V →+ W) (C : ℝ) (h : ∀ v, ‖f v‖ ≤ C * ‖v‖) : NormedAddGroupHom V W :=
{ f with bound' := ⟨C, h⟩ }
#align add_monoid_hom.mk_normed_add_group_hom AddMonoidHom.mkNormedAddGroupHom
/-- Associate to a group homomorphism a bounded group homomorphism under a norm control condition.
See `AddMonoidHom.mkNormedAddGroupHom` for a version that uses `ℝ` for the bound. -/
def mkNormedAddGroupHom' (f : V →+ W) (C : ℝ≥0) (hC : ∀ x, ‖f x‖₊ ≤ C * ‖x‖₊) :
NormedAddGroupHom V W :=
{ f with bound' := ⟨C, hC⟩ }
#align add_monoid_hom.mk_normed_add_group_hom' AddMonoidHom.mkNormedAddGroupHom'
end AddMonoidHom
theorem exists_pos_bound_of_bound {V W : Type*} [SeminormedAddCommGroup V]
[SeminormedAddCommGroup W] {f : V → W} (M : ℝ) (h : ∀ x, ‖f x‖ ≤ M * ‖x‖) :
∃ N, 0 < N ∧ ∀ x, ‖f x‖ ≤ N * ‖x‖ :=
⟨max M 1, lt_of_lt_of_le zero_lt_one (le_max_right _ _), fun x =>
calc
‖f x‖ ≤ M * ‖x‖ := h x
_ ≤ max M 1 * ‖x‖ := by gcongr; apply le_max_left
⟩
#align exists_pos_bound_of_bound exists_pos_bound_of_bound
namespace NormedAddGroupHom
variable {V V₁ V₂ V₃ : Type*} [SeminormedAddCommGroup V] [SeminormedAddCommGroup V₁]
[SeminormedAddCommGroup V₂] [SeminormedAddCommGroup V₃]
variable {f g : NormedAddGroupHom V₁ V₂}
/-- A Lipschitz continuous additive homomorphism is a normed additive group homomorphism. -/
def ofLipschitz (f : V₁ →+ V₂) {K : ℝ≥0} (h : LipschitzWith K f) : NormedAddGroupHom V₁ V₂ :=
f.mkNormedAddGroupHom K fun x ↦ by simpa only [map_zero, dist_zero_right] using h.dist_le_mul x 0
instance funLike : FunLike (NormedAddGroupHom V₁ V₂) V₁ V₂ where
coe := toFun
coe_injective' := fun f g h => by cases f; cases g; congr
-- Porting note: moved this declaration up so we could get a `FunLike` instance sooner.
instance toAddMonoidHomClass : AddMonoidHomClass (NormedAddGroupHom V₁ V₂) V₁ V₂ where
map_add f := f.map_add'
map_zero f := (AddMonoidHom.mk' f.toFun f.map_add').map_zero
initialize_simps_projections NormedAddGroupHom (toFun → apply)
theorem coe_inj (H : (f : V₁ → V₂) = g) : f = g := by
cases f; cases g; congr
#align normed_add_group_hom.coe_inj NormedAddGroupHom.coe_inj
theorem coe_injective : @Function.Injective (NormedAddGroupHom V₁ V₂) (V₁ → V₂) toFun := by
apply coe_inj
#align normed_add_group_hom.coe_injective NormedAddGroupHom.coe_injective
theorem coe_inj_iff : f = g ↔ (f : V₁ → V₂) = g :=
⟨congr_arg _, coe_inj⟩
#align normed_add_group_hom.coe_inj_iff NormedAddGroupHom.coe_inj_iff
@[ext]
theorem ext (H : ∀ x, f x = g x) : f = g :=
coe_inj <| funext H
#align normed_add_group_hom.ext NormedAddGroupHom.ext
theorem ext_iff : f = g ↔ ∀ x, f x = g x :=
⟨by rintro rfl x; rfl, ext⟩
#align normed_add_group_hom.ext_iff NormedAddGroupHom.ext_iff
variable (f g)
@[simp]
theorem toFun_eq_coe : f.toFun = f :=
rfl
#align normed_add_group_hom.to_fun_eq_coe NormedAddGroupHom.toFun_eq_coe
-- Porting note: removed `simp` because `simpNF` complains the LHS doesn't simplify.
theorem coe_mk (f) (h₁) (h₂) (h₃) : ⇑(⟨f, h₁, h₂, h₃⟩ : NormedAddGroupHom V₁ V₂) = f :=
rfl
#align normed_add_group_hom.coe_mk NormedAddGroupHom.coe_mk
@[simp]
theorem coe_mkNormedAddGroupHom (f : V₁ →+ V₂) (C) (hC) : ⇑(f.mkNormedAddGroupHom C hC) = f :=
rfl
#align normed_add_group_hom.coe_mk_normed_add_group_hom NormedAddGroupHom.coe_mkNormedAddGroupHom
@[simp]
theorem coe_mkNormedAddGroupHom' (f : V₁ →+ V₂) (C) (hC) : ⇑(f.mkNormedAddGroupHom' C hC) = f :=
rfl
#align normed_add_group_hom.coe_mk_normed_add_group_hom' NormedAddGroupHom.coe_mkNormedAddGroupHom'
/-- The group homomorphism underlying a bounded group homomorphism. -/
def toAddMonoidHom (f : NormedAddGroupHom V₁ V₂) : V₁ →+ V₂ :=
AddMonoidHom.mk' f f.map_add'
#align normed_add_group_hom.to_add_monoid_hom NormedAddGroupHom.toAddMonoidHom
@[simp]
theorem coe_toAddMonoidHom : ⇑f.toAddMonoidHom = f :=
rfl
#align normed_add_group_hom.coe_to_add_monoid_hom NormedAddGroupHom.coe_toAddMonoidHom
theorem toAddMonoidHom_injective :
Function.Injective (@NormedAddGroupHom.toAddMonoidHom V₁ V₂ _ _) := fun f g h =>
coe_inj <| by rw [← coe_toAddMonoidHom f, ← coe_toAddMonoidHom g, h]
#align normed_add_group_hom.to_add_monoid_hom_injective NormedAddGroupHom.toAddMonoidHom_injective
@[simp]
theorem mk_toAddMonoidHom (f) (h₁) (h₂) :
(⟨f, h₁, h₂⟩ : NormedAddGroupHom V₁ V₂).toAddMonoidHom = AddMonoidHom.mk' f h₁ :=
rfl
#align normed_add_group_hom.mk_to_add_monoid_hom NormedAddGroupHom.mk_toAddMonoidHom
theorem bound : ∃ C, 0 < C ∧ ∀ x, ‖f x‖ ≤ C * ‖x‖ :=
let ⟨_C, hC⟩ := f.bound'
exists_pos_bound_of_bound _ hC
#align normed_add_group_hom.bound NormedAddGroupHom.bound
theorem antilipschitz_of_norm_ge {K : ℝ≥0} (h : ∀ x, ‖x‖ ≤ K * ‖f x‖) : AntilipschitzWith K f :=
AntilipschitzWith.of_le_mul_dist fun x y => by simpa only [dist_eq_norm, map_sub] using h (x - y)
#align normed_add_group_hom.antilipschitz_of_norm_ge NormedAddGroupHom.antilipschitz_of_norm_ge
/-- A normed group hom is surjective on the subgroup `K` with constant `C` if every element
`x` of `K` has a preimage whose norm is bounded above by `C*‖x‖`. This is a more
abstract version of `f` having a right inverse defined on `K` with operator norm
at most `C`. -/
def SurjectiveOnWith (f : NormedAddGroupHom V₁ V₂) (K : AddSubgroup V₂) (C : ℝ) : Prop :=
∀ h ∈ K, ∃ g, f g = h ∧ ‖g‖ ≤ C * ‖h‖
#align normed_add_group_hom.surjective_on_with NormedAddGroupHom.SurjectiveOnWith
theorem SurjectiveOnWith.mono {f : NormedAddGroupHom V₁ V₂} {K : AddSubgroup V₂} {C C' : ℝ}
(h : f.SurjectiveOnWith K C) (H : C ≤ C') : f.SurjectiveOnWith K C' := by
intro k k_in
rcases h k k_in with ⟨g, rfl, hg⟩
use g, rfl
by_cases Hg : ‖f g‖ = 0
· simpa [Hg] using hg
· exact hg.trans (by gcongr)
#align normed_add_group_hom.surjective_on_with.mono NormedAddGroupHom.SurjectiveOnWith.mono
theorem SurjectiveOnWith.exists_pos {f : NormedAddGroupHom V₁ V₂} {K : AddSubgroup V₂} {C : ℝ}
(h : f.SurjectiveOnWith K C) : ∃ C' > 0, f.SurjectiveOnWith K C' := by
refine ⟨|C| + 1, ?_, ?_⟩
· linarith [abs_nonneg C]
· apply h.mono
linarith [le_abs_self C]
#align normed_add_group_hom.surjective_on_with.exists_pos NormedAddGroupHom.SurjectiveOnWith.exists_pos
theorem SurjectiveOnWith.surjOn {f : NormedAddGroupHom V₁ V₂} {K : AddSubgroup V₂} {C : ℝ}
(h : f.SurjectiveOnWith K C) : Set.SurjOn f Set.univ K := fun x hx =>
(h x hx).imp fun _a ⟨ha, _⟩ => ⟨Set.mem_univ _, ha⟩
#align normed_add_group_hom.surjective_on_with.surj_on NormedAddGroupHom.SurjectiveOnWith.surjOn
/-! ### The operator norm -/
/-- The operator norm of a seminormed group homomorphism is the inf of all its bounds. -/
def opNorm (f : NormedAddGroupHom V₁ V₂) :=
sInf { c | 0 ≤ c ∧ ∀ x, ‖f x‖ ≤ c * ‖x‖ }
#align normed_add_group_hom.op_norm NormedAddGroupHom.opNorm
instance hasOpNorm : Norm (NormedAddGroupHom V₁ V₂) :=
⟨opNorm⟩
#align normed_add_group_hom.has_op_norm NormedAddGroupHom.hasOpNorm
theorem norm_def : ‖f‖ = sInf { c | 0 ≤ c ∧ ∀ x, ‖f x‖ ≤ c * ‖x‖ } :=
rfl
#align normed_add_group_hom.norm_def NormedAddGroupHom.norm_def
-- So that invocations of `le_csInf` make sense: we show that the set of
-- bounds is nonempty and bounded below.
theorem bounds_nonempty {f : NormedAddGroupHom V₁ V₂} :
∃ c, c ∈ { c | 0 ≤ c ∧ ∀ x, ‖f x‖ ≤ c * ‖x‖ } :=
let ⟨M, hMp, hMb⟩ := f.bound
⟨M, le_of_lt hMp, hMb⟩
#align normed_add_group_hom.bounds_nonempty NormedAddGroupHom.bounds_nonempty
theorem bounds_bddBelow {f : NormedAddGroupHom V₁ V₂} :
BddBelow { c | 0 ≤ c ∧ ∀ x, ‖f x‖ ≤ c * ‖x‖ } :=
⟨0, fun _ ⟨hn, _⟩ => hn⟩
#align normed_add_group_hom.bounds_bdd_below NormedAddGroupHom.bounds_bddBelow
theorem opNorm_nonneg : 0 ≤ ‖f‖ :=
le_csInf bounds_nonempty fun _ ⟨hx, _⟩ => hx
#align normed_add_group_hom.op_norm_nonneg NormedAddGroupHom.opNorm_nonneg
/-- The fundamental property of the operator norm: `‖f x‖ ≤ ‖f‖ * ‖x‖`. -/
theorem le_opNorm (x : V₁) : ‖f x‖ ≤ ‖f‖ * ‖x‖ := by
obtain ⟨C, _Cpos, hC⟩ := f.bound
replace hC := hC x
by_cases h : ‖x‖ = 0
· rwa [h, mul_zero] at hC ⊢
have hlt : 0 < ‖x‖ := lt_of_le_of_ne (norm_nonneg x) (Ne.symm h)
exact
(div_le_iff hlt).mp
(le_csInf bounds_nonempty fun c ⟨_, hc⟩ => (div_le_iff hlt).mpr <| by apply hc)
#align normed_add_group_hom.le_op_norm NormedAddGroupHom.le_opNorm
theorem le_opNorm_of_le {c : ℝ} {x} (h : ‖x‖ ≤ c) : ‖f x‖ ≤ ‖f‖ * c :=
le_trans (f.le_opNorm x) (by gcongr; exact f.opNorm_nonneg)
#align normed_add_group_hom.le_op_norm_of_le NormedAddGroupHom.le_opNorm_of_le
theorem le_of_opNorm_le {c : ℝ} (h : ‖f‖ ≤ c) (x : V₁) : ‖f x‖ ≤ c * ‖x‖ :=
(f.le_opNorm x).trans (by gcongr)
#align normed_add_group_hom.le_of_op_norm_le NormedAddGroupHom.le_of_opNorm_le
/-- continuous linear maps are Lipschitz continuous. -/
theorem lipschitz : LipschitzWith ⟨‖f‖, opNorm_nonneg f⟩ f :=
LipschitzWith.of_dist_le_mul fun x y => by
rw [dist_eq_norm, dist_eq_norm, ← map_sub]
apply le_opNorm
#align normed_add_group_hom.lipschitz NormedAddGroupHom.lipschitz
protected theorem uniformContinuous (f : NormedAddGroupHom V₁ V₂) : UniformContinuous f :=
f.lipschitz.uniformContinuous
#align normed_add_group_hom.uniform_continuous NormedAddGroupHom.uniformContinuous
@[continuity]
protected theorem continuous (f : NormedAddGroupHom V₁ V₂) : Continuous f :=
f.uniformContinuous.continuous
#align normed_add_group_hom.continuous NormedAddGroupHom.continuous
theorem ratio_le_opNorm (x : V₁) : ‖f x‖ / ‖x‖ ≤ ‖f‖ :=
div_le_of_nonneg_of_le_mul (norm_nonneg _) f.opNorm_nonneg (le_opNorm _ _)
#align normed_add_group_hom.ratio_le_op_norm NormedAddGroupHom.ratio_le_opNorm
/-- If one controls the norm of every `f x`, then one controls the norm of `f`. -/
theorem opNorm_le_bound {M : ℝ} (hMp : 0 ≤ M) (hM : ∀ x, ‖f x‖ ≤ M * ‖x‖) : ‖f‖ ≤ M :=
csInf_le bounds_bddBelow ⟨hMp, hM⟩
#align normed_add_group_hom.op_norm_le_bound NormedAddGroupHom.opNorm_le_bound
theorem opNorm_eq_of_bounds {M : ℝ} (M_nonneg : 0 ≤ M) (h_above : ∀ x, ‖f x‖ ≤ M * ‖x‖)
(h_below : ∀ N ≥ 0, (∀ x, ‖f x‖ ≤ N * ‖x‖) → M ≤ N) : ‖f‖ = M :=
le_antisymm (f.opNorm_le_bound M_nonneg h_above)
((le_csInf_iff NormedAddGroupHom.bounds_bddBelow ⟨M, M_nonneg, h_above⟩).mpr
fun N ⟨N_nonneg, hN⟩ => h_below N N_nonneg hN)
#align normed_add_group_hom.op_norm_eq_of_bounds NormedAddGroupHom.opNorm_eq_of_bounds
theorem opNorm_le_of_lipschitz {f : NormedAddGroupHom V₁ V₂} {K : ℝ≥0} (hf : LipschitzWith K f) :
‖f‖ ≤ K :=
f.opNorm_le_bound K.2 fun x => by simpa only [dist_zero_right, map_zero] using hf.dist_le_mul x 0
#align normed_add_group_hom.op_norm_le_of_lipschitz NormedAddGroupHom.opNorm_le_of_lipschitz
/-- If a bounded group homomorphism map is constructed from a group homomorphism via the constructor
`AddMonoidHom.mkNormedAddGroupHom`, then its norm is bounded by the bound given to the constructor
if it is nonnegative. -/
theorem mkNormedAddGroupHom_norm_le (f : V₁ →+ V₂) {C : ℝ} (hC : 0 ≤ C) (h : ∀ x, ‖f x‖ ≤ C * ‖x‖) :
‖f.mkNormedAddGroupHom C h‖ ≤ C :=
opNorm_le_bound _ hC h
#align normed_add_group_hom.mk_normed_add_group_hom_norm_le NormedAddGroupHom.mkNormedAddGroupHom_norm_le
/-- If a bounded group homomorphism map is constructed from a group homomorphism via the constructor
`NormedAddGroupHom.ofLipschitz`, then its norm is bounded by the bound given to the constructor. -/
theorem ofLipschitz_norm_le (f : V₁ →+ V₂) {K : ℝ≥0} (h : LipschitzWith K f) :
‖ofLipschitz f h‖ ≤ K :=
mkNormedAddGroupHom_norm_le f K.coe_nonneg _
/-- If a bounded group homomorphism map is constructed from a group homomorphism
via the constructor `AddMonoidHom.mkNormedAddGroupHom`, then its norm is bounded by the bound
given to the constructor or zero if this bound is negative. -/
theorem mkNormedAddGroupHom_norm_le' (f : V₁ →+ V₂) {C : ℝ} (h : ∀ x, ‖f x‖ ≤ C * ‖x‖) :
‖f.mkNormedAddGroupHom C h‖ ≤ max C 0 :=
opNorm_le_bound _ (le_max_right _ _) fun x =>
(h x).trans <| by gcongr; apply le_max_left
#align normed_add_group_hom.mk_normed_add_group_hom_norm_le' NormedAddGroupHom.mkNormedAddGroupHom_norm_le'
alias _root_.AddMonoidHom.mkNormedAddGroupHom_norm_le := mkNormedAddGroupHom_norm_le
#align add_monoid_hom.mk_normed_add_group_hom_norm_le AddMonoidHom.mkNormedAddGroupHom_norm_le
alias _root_.AddMonoidHom.mkNormedAddGroupHom_norm_le' := mkNormedAddGroupHom_norm_le'
#align add_monoid_hom.mk_normed_add_group_hom_norm_le' AddMonoidHom.mkNormedAddGroupHom_norm_le'
/-! ### Addition of normed group homs -/
/-- Addition of normed group homs. -/
instance add : Add (NormedAddGroupHom V₁ V₂) :=
⟨fun f g =>
(f.toAddMonoidHom + g.toAddMonoidHom).mkNormedAddGroupHom (‖f‖ + ‖g‖) fun v =>
calc
‖f v + g v‖ ≤ ‖f v‖ + ‖g v‖ := norm_add_le _ _
_ ≤ ‖f‖ * ‖v‖ + ‖g‖ * ‖v‖ := by gcongr <;> apply le_opNorm
_ = (‖f‖ + ‖g‖) * ‖v‖ := by rw [add_mul]
⟩
/-- The operator norm satisfies the triangle inequality. -/
theorem opNorm_add_le : ‖f + g‖ ≤ ‖f‖ + ‖g‖ :=
mkNormedAddGroupHom_norm_le _ (add_nonneg (opNorm_nonneg _) (opNorm_nonneg _)) _
#align normed_add_group_hom.op_norm_add_le NormedAddGroupHom.opNorm_add_le
-- Porting note: this library note doesn't seem to apply anymore
/-
library_note "addition on function coercions"/--
Terms containing `@has_add.add (has_coe_to_fun.F ...) pi.has_add`
seem to cause leanchecker to [crash due to an out-of-memory
condition](https://github.com/leanprover-community/lean/issues/543).
As a workaround, we add a type annotation: `(f + g : V₁ → V₂)`
-/
-/
@[simp]
theorem coe_add (f g : NormedAddGroupHom V₁ V₂) : ⇑(f + g) = f + g :=
rfl
#align normed_add_group_hom.coe_add NormedAddGroupHom.coe_add
@[simp]
theorem add_apply (f g : NormedAddGroupHom V₁ V₂) (v : V₁) :
(f + g) v = f v + g v :=
rfl
#align normed_add_group_hom.add_apply NormedAddGroupHom.add_apply
/-! ### The zero normed group hom -/
instance zero : Zero (NormedAddGroupHom V₁ V₂) :=
⟨(0 : V₁ →+ V₂).mkNormedAddGroupHom 0 (by simp)⟩
instance inhabited : Inhabited (NormedAddGroupHom V₁ V₂) :=
⟨0⟩
/-- The norm of the `0` operator is `0`. -/
theorem opNorm_zero : ‖(0 : NormedAddGroupHom V₁ V₂)‖ = 0 :=
le_antisymm
(csInf_le bounds_bddBelow
⟨ge_of_eq rfl, fun _ =>
le_of_eq
(by
rw [zero_mul]
exact norm_zero)⟩)
(opNorm_nonneg _)
#align normed_add_group_hom.op_norm_zero NormedAddGroupHom.opNorm_zero
/-- For normed groups, an operator is zero iff its norm vanishes. -/
theorem opNorm_zero_iff {V₁ V₂ : Type*} [NormedAddCommGroup V₁] [NormedAddCommGroup V₂]
{f : NormedAddGroupHom V₁ V₂} : ‖f‖ = 0 ↔ f = 0 :=
Iff.intro
(fun hn =>
ext fun x =>
norm_le_zero_iff.1
(calc
_ ≤ ‖f‖ * ‖x‖ := le_opNorm _ _
_ = _ := by rw [hn, zero_mul]
))
fun hf => by rw [hf, opNorm_zero]
#align normed_add_group_hom.op_norm_zero_iff NormedAddGroupHom.opNorm_zero_iff
@[simp]
theorem coe_zero : ⇑(0 : NormedAddGroupHom V₁ V₂) = 0 :=
rfl
#align normed_add_group_hom.coe_zero NormedAddGroupHom.coe_zero
@[simp]
theorem zero_apply (v : V₁) : (0 : NormedAddGroupHom V₁ V₂) v = 0 :=
rfl
#align normed_add_group_hom.zero_apply NormedAddGroupHom.zero_apply
variable {f g}
/-! ### The identity normed group hom -/
variable (V)
/-- The identity as a continuous normed group hom. -/
@[simps!]
def id : NormedAddGroupHom V V :=
(AddMonoidHom.id V).mkNormedAddGroupHom 1 (by simp [le_refl])
#align normed_add_group_hom.id NormedAddGroupHom.id
/-- The norm of the identity is at most `1`. It is in fact `1`, except when the norm of every
element vanishes, where it is `0`. (Since we are working with seminorms this can happen even if the
space is non-trivial.) It means that one can not do better than an inequality in general. -/
theorem norm_id_le : ‖(id V : NormedAddGroupHom V V)‖ ≤ 1 :=
opNorm_le_bound _ zero_le_one fun x => by simp
#align normed_add_group_hom.norm_id_le NormedAddGroupHom.norm_id_le
/-- If there is an element with norm different from `0`, then the norm of the identity equals `1`.
(Since we are working with seminorms supposing that the space is non-trivial is not enough.) -/
theorem norm_id_of_nontrivial_seminorm (h : ∃ x : V, ‖x‖ ≠ 0) : ‖id V‖ = 1 :=
le_antisymm (norm_id_le V) <| by
let ⟨x, hx⟩ := h
have := (id V).ratio_le_opNorm x
rwa [id_apply, div_self hx] at this
#align normed_add_group_hom.norm_id_of_nontrivial_seminorm NormedAddGroupHom.norm_id_of_nontrivial_seminorm
/-- If a normed space is non-trivial, then the norm of the identity equals `1`. -/
theorem norm_id {V : Type*} [NormedAddCommGroup V] [Nontrivial V] : ‖id V‖ = 1 := by
refine norm_id_of_nontrivial_seminorm V ?_
obtain ⟨x, hx⟩ := exists_ne (0 : V)
exact ⟨x, ne_of_gt (norm_pos_iff.2 hx)⟩
#align normed_add_group_hom.norm_id NormedAddGroupHom.norm_id
theorem coe_id : (NormedAddGroupHom.id V : V → V) = _root_.id :=
rfl
#align normed_add_group_hom.coe_id NormedAddGroupHom.coe_id
/-! ### The negation of a normed group hom -/
/-- Opposite of a normed group hom. -/
instance neg : Neg (NormedAddGroupHom V₁ V₂) :=
⟨fun f => (-f.toAddMonoidHom).mkNormedAddGroupHom ‖f‖ fun v => by simp [le_opNorm f v]⟩
@[simp]
theorem coe_neg (f : NormedAddGroupHom V₁ V₂) : ⇑(-f) = -f :=
rfl
#align normed_add_group_hom.coe_neg NormedAddGroupHom.coe_neg
@[simp]
theorem neg_apply (f : NormedAddGroupHom V₁ V₂) (v : V₁) :
(-f : NormedAddGroupHom V₁ V₂) v = -f v :=
rfl
#align normed_add_group_hom.neg_apply NormedAddGroupHom.neg_apply
theorem opNorm_neg (f : NormedAddGroupHom V₁ V₂) : ‖-f‖ = ‖f‖ := by
simp only [norm_def, coe_neg, norm_neg, Pi.neg_apply]
#align normed_add_group_hom.op_norm_neg NormedAddGroupHom.opNorm_neg
/-! ### Subtraction of normed group homs -/
/-- Subtraction of normed group homs. -/
instance sub : Sub (NormedAddGroupHom V₁ V₂) :=
⟨fun f g =>
{ f.toAddMonoidHom - g.toAddMonoidHom with
bound' := by
simp only [AddMonoidHom.sub_apply, AddMonoidHom.toFun_eq_coe, sub_eq_add_neg]
exact (f + -g).bound' }⟩
@[simp]
theorem coe_sub (f g : NormedAddGroupHom V₁ V₂) : ⇑(f - g) = f - g :=
rfl
#align normed_add_group_hom.coe_sub NormedAddGroupHom.coe_sub
@[simp]
theorem sub_apply (f g : NormedAddGroupHom V₁ V₂) (v : V₁) :
(f - g : NormedAddGroupHom V₁ V₂) v = f v - g v :=
rfl
#align normed_add_group_hom.sub_apply NormedAddGroupHom.sub_apply
/-! ### Scalar actions on normed group homs -/
section SMul
variable {R R' : Type*} [MonoidWithZero R] [DistribMulAction R V₂] [PseudoMetricSpace R]
[BoundedSMul R V₂] [MonoidWithZero R'] [DistribMulAction R' V₂] [PseudoMetricSpace R']
[BoundedSMul R' V₂]
instance smul : SMul R (NormedAddGroupHom V₁ V₂) where
smul r f :=
{ toFun := r • ⇑f
map_add' := (r • f.toAddMonoidHom).map_add'
bound' :=
let ⟨b, hb⟩ := f.bound'
⟨dist r 0 * b, fun x => by
have := dist_smul_pair r (f x) (f 0)
rw [map_zero, smul_zero, dist_zero_right, dist_zero_right] at this
rw [mul_assoc]
refine this.trans ?_
gcongr
exact hb x⟩ }
@[simp]
theorem coe_smul (r : R) (f : NormedAddGroupHom V₁ V₂) : ⇑(r • f) = r • ⇑f :=
rfl
#align normed_add_group_hom.coe_smul NormedAddGroupHom.coe_smul
@[simp]
theorem smul_apply (r : R) (f : NormedAddGroupHom V₁ V₂) (v : V₁) : (r • f) v = r • f v :=
rfl
#align normed_add_group_hom.smul_apply NormedAddGroupHom.smul_apply
instance smulCommClass [SMulCommClass R R' V₂] :
SMulCommClass R R' (NormedAddGroupHom V₁ V₂) where
smul_comm _ _ _ := ext fun _ => smul_comm _ _ _
instance isScalarTower [SMul R R'] [IsScalarTower R R' V₂] :
IsScalarTower R R' (NormedAddGroupHom V₁ V₂) where
smul_assoc _ _ _ := ext fun _ => smul_assoc _ _ _
instance isCentralScalar [DistribMulAction Rᵐᵒᵖ V₂] [IsCentralScalar R V₂] :
IsCentralScalar R (NormedAddGroupHom V₁ V₂) where
op_smul_eq_smul _ _ := ext fun _ => op_smul_eq_smul _ _
end SMul
instance nsmul : SMul ℕ (NormedAddGroupHom V₁ V₂) where
smul n f :=
{ toFun := n • ⇑f
map_add' := (n • f.toAddMonoidHom).map_add'
bound' :=
let ⟨b, hb⟩ := f.bound'
⟨n • b, fun v => by
rw [Pi.smul_apply, nsmul_eq_mul, mul_assoc]
exact (norm_nsmul_le _ _).trans (by gcongr; apply hb)⟩ }
#align normed_add_group_hom.has_nat_scalar NormedAddGroupHom.nsmul
@[simp]
theorem coe_nsmul (r : ℕ) (f : NormedAddGroupHom V₁ V₂) : ⇑(r • f) = r • ⇑f :=
rfl
#align normed_add_group_hom.coe_nsmul NormedAddGroupHom.coe_nsmul
@[simp]
theorem nsmul_apply (r : ℕ) (f : NormedAddGroupHom V₁ V₂) (v : V₁) : (r • f) v = r • f v :=
rfl
#align normed_add_group_hom.nsmul_apply NormedAddGroupHom.nsmul_apply
instance zsmul : SMul ℤ (NormedAddGroupHom V₁ V₂) where
smul z f :=
{ toFun := z • ⇑f
map_add' := (z • f.toAddMonoidHom).map_add'
bound' :=
let ⟨b, hb⟩ := f.bound'
⟨‖z‖ • b, fun v => by
rw [Pi.smul_apply, smul_eq_mul, mul_assoc]
exact (norm_zsmul_le _ _).trans (by gcongr; apply hb)⟩ }
#align normed_add_group_hom.has_int_scalar NormedAddGroupHom.zsmul
@[simp]
theorem coe_zsmul (r : ℤ) (f : NormedAddGroupHom V₁ V₂) : ⇑(r • f) = r • ⇑f :=
rfl
#align normed_add_group_hom.coe_zsmul NormedAddGroupHom.coe_zsmul
@[simp]
theorem zsmul_apply (r : ℤ) (f : NormedAddGroupHom V₁ V₂) (v : V₁) : (r • f) v = r • f v :=
rfl
#align normed_add_group_hom.zsmul_apply NormedAddGroupHom.zsmul_apply
/-! ### Normed group structure on normed group homs -/
/-- Homs between two given normed groups form a commutative additive group. -/
instance toAddCommGroup : AddCommGroup (NormedAddGroupHom V₁ V₂) :=
coe_injective.addCommGroup _ rfl (fun _ _ => rfl) (fun _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl)
fun _ _ => rfl
/-- Normed group homomorphisms themselves form a seminormed group with respect to
the operator norm. -/
instance toSeminormedAddCommGroup : SeminormedAddCommGroup (NormedAddGroupHom V₁ V₂) :=
AddGroupSeminorm.toSeminormedAddCommGroup
{ toFun := opNorm
map_zero' := opNorm_zero
neg' := opNorm_neg
add_le' := opNorm_add_le }
#align normed_add_group_hom.to_seminormed_add_comm_group NormedAddGroupHom.toSeminormedAddCommGroup
/-- Normed group homomorphisms themselves form a normed group with respect to
the operator norm. -/
instance toNormedAddCommGroup {V₁ V₂ : Type*} [NormedAddCommGroup V₁] [NormedAddCommGroup V₂] :
NormedAddCommGroup (NormedAddGroupHom V₁ V₂) :=
AddGroupNorm.toNormedAddCommGroup
{ toFun := opNorm
map_zero' := opNorm_zero
neg' := opNorm_neg
add_le' := opNorm_add_le
eq_zero_of_map_eq_zero' := fun _f => opNorm_zero_iff.1 }
#align normed_add_group_hom.to_normed_add_comm_group NormedAddGroupHom.toNormedAddCommGroup
/-- Coercion of a `NormedAddGroupHom` is an `AddMonoidHom`. Similar to `AddMonoidHom.coeFn`. -/
@[simps]
def coeAddHom : NormedAddGroupHom V₁ V₂ →+ V₁ → V₂ where
toFun := DFunLike.coe
map_zero' := coe_zero
map_add' := coe_add
#align normed_add_group_hom.coe_fn_add_hom NormedAddGroupHom.coeAddHom
@[simp]
theorem coe_sum {ι : Type*} (s : Finset ι) (f : ι → NormedAddGroupHom V₁ V₂) :
⇑(∑ i ∈ s, f i) = ∑ i ∈ s, (f i : V₁ → V₂) :=
map_sum coeAddHom f s
#align normed_add_group_hom.coe_sum NormedAddGroupHom.coe_sum
theorem sum_apply {ι : Type*} (s : Finset ι) (f : ι → NormedAddGroupHom V₁ V₂) (v : V₁) :
(∑ i ∈ s, f i) v = ∑ i ∈ s, f i v := by simp only [coe_sum, Finset.sum_apply]
#align normed_add_group_hom.sum_apply NormedAddGroupHom.sum_apply
/-! ### Module structure on normed group homs -/
instance distribMulAction {R : Type*} [MonoidWithZero R] [DistribMulAction R V₂]
[PseudoMetricSpace R] [BoundedSMul R V₂] : DistribMulAction R (NormedAddGroupHom V₁ V₂) :=
Function.Injective.distribMulAction coeAddHom coe_injective coe_smul
instance module {R : Type*} [Semiring R] [Module R V₂] [PseudoMetricSpace R] [BoundedSMul R V₂] :
Module R (NormedAddGroupHom V₁ V₂) :=
Function.Injective.module _ coeAddHom coe_injective coe_smul
/-! ### Composition of normed group homs -/
/-- The composition of continuous normed group homs. -/
@[simps!]
protected def comp (g : NormedAddGroupHom V₂ V₃) (f : NormedAddGroupHom V₁ V₂) :
NormedAddGroupHom V₁ V₃ :=
(g.toAddMonoidHom.comp f.toAddMonoidHom).mkNormedAddGroupHom (‖g‖ * ‖f‖) fun v =>
calc
‖g (f v)‖ ≤ ‖g‖ * ‖f v‖ := le_opNorm _ _
_ ≤ ‖g‖ * (‖f‖ * ‖v‖) := by gcongr; apply le_opNorm
_ = ‖g‖ * ‖f‖ * ‖v‖ := by rw [mul_assoc]
#align normed_add_group_hom.comp NormedAddGroupHom.comp
theorem norm_comp_le (g : NormedAddGroupHom V₂ V₃) (f : NormedAddGroupHom V₁ V₂) :
‖g.comp f‖ ≤ ‖g‖ * ‖f‖ :=
mkNormedAddGroupHom_norm_le _ (mul_nonneg (opNorm_nonneg _) (opNorm_nonneg _)) _
#align normed_add_group_hom.norm_comp_le NormedAddGroupHom.norm_comp_le
theorem norm_comp_le_of_le {g : NormedAddGroupHom V₂ V₃} {C₁ C₂ : ℝ} (hg : ‖g‖ ≤ C₂)
(hf : ‖f‖ ≤ C₁) : ‖g.comp f‖ ≤ C₂ * C₁ :=
le_trans (norm_comp_le g f) <| by gcongr; exact le_trans (norm_nonneg _) hg
#align normed_add_group_hom.norm_comp_le_of_le NormedAddGroupHom.norm_comp_le_of_le
theorem norm_comp_le_of_le' {g : NormedAddGroupHom V₂ V₃} (C₁ C₂ C₃ : ℝ) (h : C₃ = C₂ * C₁)
(hg : ‖g‖ ≤ C₂) (hf : ‖f‖ ≤ C₁) : ‖g.comp f‖ ≤ C₃ := by
rw [h]
exact norm_comp_le_of_le hg hf
#align normed_add_group_hom.norm_comp_le_of_le' NormedAddGroupHom.norm_comp_le_of_le'
/-- Composition of normed groups hom as an additive group morphism. -/
def compHom : NormedAddGroupHom V₂ V₃ →+ NormedAddGroupHom V₁ V₂ →+ NormedAddGroupHom V₁ V₃ :=
AddMonoidHom.mk'
(fun g =>
AddMonoidHom.mk' (fun f => g.comp f)
(by
intros
ext
exact map_add g _ _))
(by
intros
ext
simp only [comp_apply, Pi.add_apply, Function.comp_apply, AddMonoidHom.add_apply,
AddMonoidHom.mk'_apply, coe_add])
#align normed_add_group_hom.comp_hom NormedAddGroupHom.compHom
@[simp]
| Mathlib/Analysis/Normed/Group/Hom.lean | 685 | 687 | theorem comp_zero (f : NormedAddGroupHom V₂ V₃) : f.comp (0 : NormedAddGroupHom V₁ V₂) = 0 := by |
ext
exact map_zero f
|
/-
Copyright (c) 2018 Kenny Lau. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kenny Lau, Mario Carneiro, Johan Commelin, Amelia Livingston, Anne Baanen
-/
import Mathlib.Algebra.Algebra.Tower
import Mathlib.Algebra.GroupWithZero.NonZeroDivisors
import Mathlib.GroupTheory.MonoidLocalization
import Mathlib.RingTheory.Ideal.Basic
import Mathlib.GroupTheory.GroupAction.Ring
#align_import ring_theory.localization.basic from "leanprover-community/mathlib"@"b69c9a770ecf37eb21f7b8cf4fa00de3b62694ec"
/-!
# Localizations of commutative rings
We characterize the localization of a commutative ring `R` at a submonoid `M` up to
isomorphism; that is, a commutative ring `S` is the localization of `R` at `M` iff we can find a
ring homomorphism `f : R →+* S` satisfying 3 properties:
1. For all `y ∈ M`, `f y` is a unit;
2. For all `z : S`, there exists `(x, y) : R × M` such that `z * f y = f x`;
3. For all `x, y : R` such that `f x = f y`, there exists `c ∈ M` such that `x * c = y * c`.
(The converse is a consequence of 1.)
In the following, let `R, P` be commutative rings, `S, Q` be `R`- and `P`-algebras
and `M, T` be submonoids of `R` and `P` respectively, e.g.:
```
variable (R S P Q : Type*) [CommRing R] [CommRing S] [CommRing P] [CommRing Q]
variable [Algebra R S] [Algebra P Q] (M : Submonoid R) (T : Submonoid P)
```
## Main definitions
* `IsLocalization (M : Submonoid R) (S : Type*)` is a typeclass expressing that `S` is a
localization of `R` at `M`, i.e. the canonical map `algebraMap R S : R →+* S` is a
localization map (satisfying the above properties).
* `IsLocalization.mk' S` is a surjection sending `(x, y) : R × M` to `f x * (f y)⁻¹`
* `IsLocalization.lift` is the ring homomorphism from `S` induced by a homomorphism from `R`
which maps elements of `M` to invertible elements of the codomain.
* `IsLocalization.map S Q` is the ring homomorphism from `S` to `Q` which maps elements
of `M` to elements of `T`
* `IsLocalization.ringEquivOfRingEquiv`: if `R` and `P` are isomorphic by an isomorphism
sending `M` to `T`, then `S` and `Q` are isomorphic
* `IsLocalization.algEquiv`: if `Q` is another localization of `R` at `M`, then `S` and `Q`
are isomorphic as `R`-algebras
## Main results
* `Localization M S`, a construction of the localization as a quotient type, defined in
`GroupTheory.MonoidLocalization`, has `CommRing`, `Algebra R` and `IsLocalization M`
instances if `R` is a ring. `Localization.Away`, `Localization.AtPrime` and `FractionRing`
are abbreviations for `Localization`s and have their corresponding `IsLocalization` instances
## Implementation notes
In maths it is natural to reason up to isomorphism, but in Lean we cannot naturally `rewrite` one
structure with an isomorphic one; one way around this is to isolate a predicate characterizing
a structure up to isomorphism, and reason about things that satisfy the predicate.
A previous version of this file used a fully bundled type of ring localization maps,
then used a type synonym `f.codomain` for `f : LocalizationMap M S` to instantiate the
`R`-algebra structure on `S`. This results in defining ad-hoc copies for everything already
defined on `S`. By making `IsLocalization` a predicate on the `algebraMap R S`,
we can ensure the localization map commutes nicely with other `algebraMap`s.
To prove most lemmas about a localization map `algebraMap R S` in this file we invoke the
corresponding proof for the underlying `CommMonoid` localization map
`IsLocalization.toLocalizationMap M S`, which can be found in `GroupTheory.MonoidLocalization`
and the namespace `Submonoid.LocalizationMap`.
To reason about the localization as a quotient type, use `mk_eq_of_mk'` and associated lemmas.
These show the quotient map `mk : R → M → Localization M` equals the surjection
`LocalizationMap.mk'` induced by the map `algebraMap : R →+* Localization M`.
The lemma `mk_eq_of_mk'` hence gives you access to the results in the rest of the file,
which are about the `LocalizationMap.mk'` induced by any localization map.
The proof that "a `CommRing` `K` which is the localization of an integral domain `R` at `R \ {0}`
is a field" is a `def` rather than an `instance`, so if you want to reason about a field of
fractions `K`, assume `[Field K]` instead of just `[CommRing K]`.
## Tags
localization, ring localization, commutative ring localization, characteristic predicate,
commutative ring, field of fractions
-/
open Function
section CommSemiring
variable {R : Type*} [CommSemiring R] (M : Submonoid R) (S : Type*) [CommSemiring S]
variable [Algebra R S] {P : Type*} [CommSemiring P]
/-- The typeclass `IsLocalization (M : Submonoid R) S` where `S` is an `R`-algebra
expresses that `S` is isomorphic to the localization of `R` at `M`. -/
@[mk_iff] class IsLocalization : Prop where
-- Porting note: add ' to fields, and made new versions of these with either `S` or `M` explicit.
/-- Everything in the image of `algebraMap` is a unit -/
map_units' : ∀ y : M, IsUnit (algebraMap R S y)
/-- The `algebraMap` is surjective -/
surj' : ∀ z : S, ∃ x : R × M, z * algebraMap R S x.2 = algebraMap R S x.1
/-- The kernel of `algebraMap` is contained in the annihilator of `M`;
it is then equal to the annihilator by `map_units'` -/
exists_of_eq : ∀ {x y}, algebraMap R S x = algebraMap R S y → ∃ c : M, ↑c * x = ↑c * y
#align is_localization IsLocalization
variable {M}
namespace IsLocalization
section IsLocalization
variable [IsLocalization M S]
section
@[inherit_doc IsLocalization.map_units']
theorem map_units : ∀ y : M, IsUnit (algebraMap R S y) :=
IsLocalization.map_units'
variable (M) {S}
@[inherit_doc IsLocalization.surj']
theorem surj : ∀ z : S, ∃ x : R × M, z * algebraMap R S x.2 = algebraMap R S x.1 :=
IsLocalization.surj'
variable (S)
@[inherit_doc IsLocalization.exists_of_eq]
theorem eq_iff_exists {x y} : algebraMap R S x = algebraMap R S y ↔ ∃ c : M, ↑c * x = ↑c * y :=
Iff.intro IsLocalization.exists_of_eq fun ⟨c, h⟩ ↦ by
apply_fun algebraMap R S at h
rw [map_mul, map_mul] at h
exact (IsLocalization.map_units S c).mul_right_inj.mp h
variable {S}
theorem of_le (N : Submonoid R) (h₁ : M ≤ N) (h₂ : ∀ r ∈ N, IsUnit (algebraMap R S r)) :
IsLocalization N S where
map_units' r := h₂ r r.2
surj' s :=
have ⟨⟨x, y, hy⟩, H⟩ := IsLocalization.surj M s
⟨⟨x, y, h₁ hy⟩, H⟩
exists_of_eq {x y} := by
rw [IsLocalization.eq_iff_exists M]
rintro ⟨c, hc⟩
exact ⟨⟨c, h₁ c.2⟩, hc⟩
#align is_localization.of_le IsLocalization.of_le
variable (S)
/-- `IsLocalization.toLocalizationWithZeroMap M S` shows `S` is the monoid localization of
`R` at `M`. -/
@[simps]
def toLocalizationWithZeroMap : Submonoid.LocalizationWithZeroMap M S where
__ := algebraMap R S
toFun := algebraMap R S
map_units' := IsLocalization.map_units _
surj' := IsLocalization.surj _
exists_of_eq _ _ := IsLocalization.exists_of_eq
#align is_localization.to_localization_with_zero_map IsLocalization.toLocalizationWithZeroMap
/-- `IsLocalization.toLocalizationMap M S` shows `S` is the monoid localization of `R` at `M`. -/
abbrev toLocalizationMap : Submonoid.LocalizationMap M S :=
(toLocalizationWithZeroMap M S).toLocalizationMap
#align is_localization.to_localization_map IsLocalization.toLocalizationMap
@[simp]
theorem toLocalizationMap_toMap : (toLocalizationMap M S).toMap = (algebraMap R S : R →*₀ S) :=
rfl
#align is_localization.to_localization_map_to_map IsLocalization.toLocalizationMap_toMap
theorem toLocalizationMap_toMap_apply (x) : (toLocalizationMap M S).toMap x = algebraMap R S x :=
rfl
#align is_localization.to_localization_map_to_map_apply IsLocalization.toLocalizationMap_toMap_apply
theorem surj₂ : ∀ z w : S, ∃ z' w' : R, ∃ d : M,
(z * algebraMap R S d = algebraMap R S z') ∧ (w * algebraMap R S d = algebraMap R S w') :=
(toLocalizationMap M S).surj₂
end
variable (M) {S}
/-- Given a localization map `f : M →* N`, a section function sending `z : N` to some
`(x, y) : M × S` such that `f x * (f y)⁻¹ = z`. -/
noncomputable def sec (z : S) : R × M :=
Classical.choose <| IsLocalization.surj _ z
#align is_localization.sec IsLocalization.sec
@[simp]
theorem toLocalizationMap_sec : (toLocalizationMap M S).sec = sec M :=
rfl
#align is_localization.to_localization_map_sec IsLocalization.toLocalizationMap_sec
/-- Given `z : S`, `IsLocalization.sec M z` is defined to be a pair `(x, y) : R × M` such
that `z * f y = f x` (so this lemma is true by definition). -/
theorem sec_spec (z : S) :
z * algebraMap R S (IsLocalization.sec M z).2 = algebraMap R S (IsLocalization.sec M z).1 :=
Classical.choose_spec <| IsLocalization.surj _ z
#align is_localization.sec_spec IsLocalization.sec_spec
/-- Given `z : S`, `IsLocalization.sec M z` is defined to be a pair `(x, y) : R × M` such
that `z * f y = f x`, so this lemma is just an application of `S`'s commutativity. -/
theorem sec_spec' (z : S) :
algebraMap R S (IsLocalization.sec M z).1 = algebraMap R S (IsLocalization.sec M z).2 * z := by
rw [mul_comm, sec_spec]
#align is_localization.sec_spec' IsLocalization.sec_spec'
variable {M}
/-- If `M` contains `0` then the localization at `M` is trivial. -/
theorem subsingleton (h : 0 ∈ M) : Subsingleton S := (toLocalizationMap M S).subsingleton h
theorem map_right_cancel {x y} {c : M} (h : algebraMap R S (c * x) = algebraMap R S (c * y)) :
algebraMap R S x = algebraMap R S y :=
(toLocalizationMap M S).map_right_cancel h
#align is_localization.map_right_cancel IsLocalization.map_right_cancel
theorem map_left_cancel {x y} {c : M} (h : algebraMap R S (x * c) = algebraMap R S (y * c)) :
algebraMap R S x = algebraMap R S y :=
(toLocalizationMap M S).map_left_cancel h
#align is_localization.map_left_cancel IsLocalization.map_left_cancel
theorem eq_zero_of_fst_eq_zero {z x} {y : M} (h : z * algebraMap R S y = algebraMap R S x)
(hx : x = 0) : z = 0 := by
rw [hx, (algebraMap R S).map_zero] at h
exact (IsUnit.mul_left_eq_zero (IsLocalization.map_units S y)).1 h
#align is_localization.eq_zero_of_fst_eq_zero IsLocalization.eq_zero_of_fst_eq_zero
variable (M S)
theorem map_eq_zero_iff (r : R) : algebraMap R S r = 0 ↔ ∃ m : M, ↑m * r = 0 := by
constructor
· intro h
obtain ⟨m, hm⟩ := (IsLocalization.eq_iff_exists M S).mp ((algebraMap R S).map_zero.trans h.symm)
exact ⟨m, by simpa using hm.symm⟩
· rintro ⟨m, hm⟩
rw [← (IsLocalization.map_units S m).mul_right_inj, mul_zero, ← RingHom.map_mul, hm,
RingHom.map_zero]
#align is_localization.map_eq_zero_iff IsLocalization.map_eq_zero_iff
variable {M}
/-- `IsLocalization.mk' S` is the surjection sending `(x, y) : R × M` to
`f x * (f y)⁻¹`. -/
noncomputable def mk' (x : R) (y : M) : S :=
(toLocalizationMap M S).mk' x y
#align is_localization.mk' IsLocalization.mk'
@[simp]
theorem mk'_sec (z : S) : mk' S (IsLocalization.sec M z).1 (IsLocalization.sec M z).2 = z :=
(toLocalizationMap M S).mk'_sec _
#align is_localization.mk'_sec IsLocalization.mk'_sec
theorem mk'_mul (x₁ x₂ : R) (y₁ y₂ : M) : mk' S (x₁ * x₂) (y₁ * y₂) = mk' S x₁ y₁ * mk' S x₂ y₂ :=
(toLocalizationMap M S).mk'_mul _ _ _ _
#align is_localization.mk'_mul IsLocalization.mk'_mul
theorem mk'_one (x) : mk' S x (1 : M) = algebraMap R S x :=
(toLocalizationMap M S).mk'_one _
#align is_localization.mk'_one IsLocalization.mk'_one
@[simp]
theorem mk'_spec (x) (y : M) : mk' S x y * algebraMap R S y = algebraMap R S x :=
(toLocalizationMap M S).mk'_spec _ _
#align is_localization.mk'_spec IsLocalization.mk'_spec
@[simp]
theorem mk'_spec' (x) (y : M) : algebraMap R S y * mk' S x y = algebraMap R S x :=
(toLocalizationMap M S).mk'_spec' _ _
#align is_localization.mk'_spec' IsLocalization.mk'_spec'
@[simp]
theorem mk'_spec_mk (x) (y : R) (hy : y ∈ M) :
mk' S x ⟨y, hy⟩ * algebraMap R S y = algebraMap R S x :=
mk'_spec S x ⟨y, hy⟩
#align is_localization.mk'_spec_mk IsLocalization.mk'_spec_mk
@[simp]
theorem mk'_spec'_mk (x) (y : R) (hy : y ∈ M) :
algebraMap R S y * mk' S x ⟨y, hy⟩ = algebraMap R S x :=
mk'_spec' S x ⟨y, hy⟩
#align is_localization.mk'_spec'_mk IsLocalization.mk'_spec'_mk
variable {S}
theorem eq_mk'_iff_mul_eq {x} {y : M} {z} :
z = mk' S x y ↔ z * algebraMap R S y = algebraMap R S x :=
(toLocalizationMap M S).eq_mk'_iff_mul_eq
#align is_localization.eq_mk'_iff_mul_eq IsLocalization.eq_mk'_iff_mul_eq
theorem mk'_eq_iff_eq_mul {x} {y : M} {z} :
mk' S x y = z ↔ algebraMap R S x = z * algebraMap R S y :=
(toLocalizationMap M S).mk'_eq_iff_eq_mul
#align is_localization.mk'_eq_iff_eq_mul IsLocalization.mk'_eq_iff_eq_mul
theorem mk'_add_eq_iff_add_mul_eq_mul {x} {y : M} {z₁ z₂} :
mk' S x y + z₁ = z₂ ↔ algebraMap R S x + z₁ * algebraMap R S y = z₂ * algebraMap R S y := by
rw [← mk'_spec S x y, ← IsUnit.mul_left_inj (IsLocalization.map_units S y), right_distrib]
#align is_localization.mk'_add_eq_iff_add_mul_eq_mul IsLocalization.mk'_add_eq_iff_add_mul_eq_mul
variable (M)
theorem mk'_surjective (z : S) : ∃ (x : _) (y : M), mk' S x y = z :=
let ⟨r, hr⟩ := IsLocalization.surj _ z
⟨r.1, r.2, (eq_mk'_iff_mul_eq.2 hr).symm⟩
#align is_localization.mk'_surjective IsLocalization.mk'_surjective
variable (S)
/-- The localization of a `Fintype` is a `Fintype`. Cannot be an instance. -/
noncomputable def fintype' [Fintype R] : Fintype S :=
have := Classical.propDecidable
Fintype.ofSurjective (Function.uncurry <| IsLocalization.mk' S) fun a =>
Prod.exists'.mpr <| IsLocalization.mk'_surjective M a
#align is_localization.fintype' IsLocalization.fintype'
variable {M S}
/-- Localizing at a submonoid with 0 inside it leads to the trivial ring. -/
def uniqueOfZeroMem (h : (0 : R) ∈ M) : Unique S :=
uniqueOfZeroEqOne <| by simpa using IsLocalization.map_units S ⟨0, h⟩
#align is_localization.unique_of_zero_mem IsLocalization.uniqueOfZeroMem
theorem mk'_eq_iff_eq {x₁ x₂} {y₁ y₂ : M} :
mk' S x₁ y₁ = mk' S x₂ y₂ ↔ algebraMap R S (y₂ * x₁) = algebraMap R S (y₁ * x₂) :=
(toLocalizationMap M S).mk'_eq_iff_eq
#align is_localization.mk'_eq_iff_eq IsLocalization.mk'_eq_iff_eq
theorem mk'_eq_iff_eq' {x₁ x₂} {y₁ y₂ : M} :
mk' S x₁ y₁ = mk' S x₂ y₂ ↔ algebraMap R S (x₁ * y₂) = algebraMap R S (x₂ * y₁) :=
(toLocalizationMap M S).mk'_eq_iff_eq'
#align is_localization.mk'_eq_iff_eq' IsLocalization.mk'_eq_iff_eq'
theorem mk'_mem_iff {x} {y : M} {I : Ideal S} : mk' S x y ∈ I ↔ algebraMap R S x ∈ I := by
constructor <;> intro h
· rw [← mk'_spec S x y, mul_comm]
exact I.mul_mem_left ((algebraMap R S) y) h
· rw [← mk'_spec S x y] at h
obtain ⟨b, hb⟩ := isUnit_iff_exists_inv.1 (map_units S y)
have := I.mul_mem_left b h
rwa [mul_comm, mul_assoc, hb, mul_one] at this
#align is_localization.mk'_mem_iff IsLocalization.mk'_mem_iff
protected theorem eq {a₁ b₁} {a₂ b₂ : M} :
mk' S a₁ a₂ = mk' S b₁ b₂ ↔ ∃ c : M, ↑c * (↑b₂ * a₁) = c * (a₂ * b₁) :=
(toLocalizationMap M S).eq
#align is_localization.eq IsLocalization.eq
theorem mk'_eq_zero_iff (x : R) (s : M) : mk' S x s = 0 ↔ ∃ m : M, ↑m * x = 0 := by
rw [← (map_units S s).mul_left_inj, mk'_spec, zero_mul, map_eq_zero_iff M]
#align is_localization.mk'_eq_zero_iff IsLocalization.mk'_eq_zero_iff
@[simp]
theorem mk'_zero (s : M) : IsLocalization.mk' S 0 s = 0 := by
rw [eq_comm, IsLocalization.eq_mk'_iff_mul_eq, zero_mul, map_zero]
#align is_localization.mk'_zero IsLocalization.mk'_zero
theorem ne_zero_of_mk'_ne_zero {x : R} {y : M} (hxy : IsLocalization.mk' S x y ≠ 0) : x ≠ 0 := by
rintro rfl
exact hxy (IsLocalization.mk'_zero _)
#align is_localization.ne_zero_of_mk'_ne_zero IsLocalization.ne_zero_of_mk'_ne_zero
section Ext
variable [Algebra R P] [IsLocalization M P]
theorem eq_iff_eq {x y} :
algebraMap R S x = algebraMap R S y ↔ algebraMap R P x = algebraMap R P y :=
(toLocalizationMap M S).eq_iff_eq (toLocalizationMap M P)
#align is_localization.eq_iff_eq IsLocalization.eq_iff_eq
theorem mk'_eq_iff_mk'_eq {x₁ x₂} {y₁ y₂ : M} :
mk' S x₁ y₁ = mk' S x₂ y₂ ↔ mk' P x₁ y₁ = mk' P x₂ y₂ :=
(toLocalizationMap M S).mk'_eq_iff_mk'_eq (toLocalizationMap M P)
#align is_localization.mk'_eq_iff_mk'_eq IsLocalization.mk'_eq_iff_mk'_eq
theorem mk'_eq_of_eq {a₁ b₁ : R} {a₂ b₂ : M} (H : ↑a₂ * b₁ = ↑b₂ * a₁) :
mk' S a₁ a₂ = mk' S b₁ b₂ :=
(toLocalizationMap M S).mk'_eq_of_eq H
#align is_localization.mk'_eq_of_eq IsLocalization.mk'_eq_of_eq
theorem mk'_eq_of_eq' {a₁ b₁ : R} {a₂ b₂ : M} (H : b₁ * ↑a₂ = a₁ * ↑b₂) :
mk' S a₁ a₂ = mk' S b₁ b₂ :=
(toLocalizationMap M S).mk'_eq_of_eq' H
#align is_localization.mk'_eq_of_eq' IsLocalization.mk'_eq_of_eq'
theorem mk'_cancel (a : R) (b c : M) :
mk' S (a * c) (b * c) = mk' S a b := (toLocalizationMap M S).mk'_cancel _ _ _
variable (S)
@[simp]
theorem mk'_self {x : R} (hx : x ∈ M) : mk' S x ⟨x, hx⟩ = 1 :=
(toLocalizationMap M S).mk'_self _ hx
#align is_localization.mk'_self IsLocalization.mk'_self
@[simp]
theorem mk'_self' {x : M} : mk' S (x : R) x = 1 :=
(toLocalizationMap M S).mk'_self' _
#align is_localization.mk'_self' IsLocalization.mk'_self'
theorem mk'_self'' {x : M} : mk' S x.1 x = 1 :=
mk'_self' _
#align is_localization.mk'_self'' IsLocalization.mk'_self''
end Ext
theorem mul_mk'_eq_mk'_of_mul (x y : R) (z : M) :
(algebraMap R S) x * mk' S y z = mk' S (x * y) z :=
(toLocalizationMap M S).mul_mk'_eq_mk'_of_mul _ _ _
#align is_localization.mul_mk'_eq_mk'_of_mul IsLocalization.mul_mk'_eq_mk'_of_mul
theorem mk'_eq_mul_mk'_one (x : R) (y : M) : mk' S x y = (algebraMap R S) x * mk' S 1 y :=
((toLocalizationMap M S).mul_mk'_one_eq_mk' _ _).symm
#align is_localization.mk'_eq_mul_mk'_one IsLocalization.mk'_eq_mul_mk'_one
@[simp]
theorem mk'_mul_cancel_left (x : R) (y : M) : mk' S (y * x : R) y = (algebraMap R S) x :=
(toLocalizationMap M S).mk'_mul_cancel_left _ _
#align is_localization.mk'_mul_cancel_left IsLocalization.mk'_mul_cancel_left
theorem mk'_mul_cancel_right (x : R) (y : M) : mk' S (x * y) y = (algebraMap R S) x :=
(toLocalizationMap M S).mk'_mul_cancel_right _ _
#align is_localization.mk'_mul_cancel_right IsLocalization.mk'_mul_cancel_right
@[simp]
theorem mk'_mul_mk'_eq_one (x y : M) : mk' S (x : R) y * mk' S (y : R) x = 1 := by
rw [← mk'_mul, mul_comm]; exact mk'_self _ _
#align is_localization.mk'_mul_mk'_eq_one IsLocalization.mk'_mul_mk'_eq_one
theorem mk'_mul_mk'_eq_one' (x : R) (y : M) (h : x ∈ M) : mk' S x y * mk' S (y : R) ⟨x, h⟩ = 1 :=
mk'_mul_mk'_eq_one ⟨x, h⟩ _
#align is_localization.mk'_mul_mk'_eq_one' IsLocalization.mk'_mul_mk'_eq_one'
theorem smul_mk' (x y : R) (m : M) : x • mk' S y m = mk' S (x * y) m := by
nth_rw 2 [← one_mul m]
rw [mk'_mul, mk'_one, Algebra.smul_def]
@[simp] theorem smul_mk'_one (x : R) (m : M) : x • mk' S 1 m = mk' S x m := by
rw [smul_mk', mul_one]
@[simp] lemma smul_mk'_self {m : M} {r : R} :
(m : R) • mk' S r m = algebraMap R S r := by
rw [smul_mk', mk'_mul_cancel_left]
@[simps]
instance invertible_mk'_one (s : M) : Invertible (IsLocalization.mk' S (1 : R) s) where
invOf := algebraMap R S s
invOf_mul_self := by simp
mul_invOf_self := by simp
section
variable (M)
theorem isUnit_comp (j : S →+* P) (y : M) : IsUnit (j.comp (algebraMap R S) y) :=
(toLocalizationMap M S).isUnit_comp j.toMonoidHom _
#align is_localization.is_unit_comp IsLocalization.isUnit_comp
end
/-- Given a localization map `f : R →+* S` for a submonoid `M ⊆ R` and a map of `CommSemiring`s
`g : R →+* P` such that `g(M) ⊆ Units P`, `f x = f y → g x = g y` for all `x y : R`. -/
theorem eq_of_eq {g : R →+* P} (hg : ∀ y : M, IsUnit (g y)) {x y}
(h : (algebraMap R S) x = (algebraMap R S) y) : g x = g y :=
Submonoid.LocalizationMap.eq_of_eq (toLocalizationMap M S) (g := g.toMonoidHom) hg h
#align is_localization.eq_of_eq IsLocalization.eq_of_eq
theorem mk'_add (x₁ x₂ : R) (y₁ y₂ : M) :
mk' S (x₁ * y₂ + x₂ * y₁) (y₁ * y₂) = mk' S x₁ y₁ + mk' S x₂ y₂ :=
mk'_eq_iff_eq_mul.2 <|
Eq.symm
(by
rw [mul_comm (_ + _), mul_add, mul_mk'_eq_mk'_of_mul, mk'_add_eq_iff_add_mul_eq_mul,
mul_comm (_ * _), ← mul_assoc, add_comm, ← map_mul, mul_mk'_eq_mk'_of_mul,
mk'_add_eq_iff_add_mul_eq_mul]
simp only [map_add, Submonoid.coe_mul, map_mul]
ring)
#align is_localization.mk'_add IsLocalization.mk'_add
theorem mul_add_inv_left {g : R →+* P} (h : ∀ y : M, IsUnit (g y)) (y : M) (w z₁ z₂ : P) :
w * ↑(IsUnit.liftRight (g.toMonoidHom.restrict M) h y)⁻¹ + z₁ =
z₂ ↔ w + g y * z₁ = g y * z₂ := by
rw [mul_comm, ← one_mul z₁, ← Units.inv_mul (IsUnit.liftRight (g.toMonoidHom.restrict M) h y),
mul_assoc, ← mul_add, Units.inv_mul_eq_iff_eq_mul, Units.inv_mul_cancel_left,
IsUnit.coe_liftRight]
simp [RingHom.toMonoidHom_eq_coe, MonoidHom.restrict_apply]
#align is_localization.mul_add_inv_left IsLocalization.mul_add_inv_left
theorem lift_spec_mul_add {g : R →+* P} (hg : ∀ y : M, IsUnit (g y)) (z w w' v) :
((toLocalizationWithZeroMap M S).lift g.toMonoidWithZeroHom hg) z * w + w' = v ↔
g ((toLocalizationMap M S).sec z).1 * w + g ((toLocalizationMap M S).sec z).2 * w' =
g ((toLocalizationMap M S).sec z).2 * v := by
erw [mul_comm, ← mul_assoc, mul_add_inv_left hg, mul_comm]
rfl
#align is_localization.lift_spec_mul_add IsLocalization.lift_spec_mul_add
/-- Given a localization map `f : R →+* S` for a submonoid `M ⊆ R` and a map of `CommSemiring`s
`g : R →+* P` such that `g y` is invertible for all `y : M`, the homomorphism induced from
`S` to `P` sending `z : S` to `g x * (g y)⁻¹`, where `(x, y) : R × M` are such that
`z = f x * (f y)⁻¹`. -/
noncomputable def lift {g : R →+* P} (hg : ∀ y : M, IsUnit (g y)) : S →+* P :=
{ Submonoid.LocalizationWithZeroMap.lift (toLocalizationWithZeroMap M S)
g.toMonoidWithZeroHom hg with
map_add' := by
intro x y
erw [(toLocalizationMap M S).lift_spec, mul_add, mul_comm, eq_comm, lift_spec_mul_add,
add_comm, mul_comm, mul_assoc, mul_comm, mul_assoc, lift_spec_mul_add]
simp_rw [← mul_assoc]
show g _ * g _ * g _ + g _ * g _ * g _ = g _ * g _ * g _
simp_rw [← map_mul g, ← map_add g]
apply eq_of_eq (S := S) hg
simp only [sec_spec', toLocalizationMap_sec, map_add, map_mul]
ring }
#align is_localization.lift IsLocalization.lift
variable {g : R →+* P} (hg : ∀ y : M, IsUnit (g y))
/-- Given a localization map `f : R →+* S` for a submonoid `M ⊆ R` and a map of `CommSemiring`s
`g : R →* P` such that `g y` is invertible for all `y : M`, the homomorphism induced from
`S` to `P` maps `f x * (f y)⁻¹` to `g x * (g y)⁻¹` for all `x : R, y ∈ M`. -/
theorem lift_mk' (x y) :
lift hg (mk' S x y) = g x * ↑(IsUnit.liftRight (g.toMonoidHom.restrict M) hg y)⁻¹ :=
(toLocalizationMap M S).lift_mk' _ _ _
#align is_localization.lift_mk' IsLocalization.lift_mk'
theorem lift_mk'_spec (x v) (y : M) : lift hg (mk' S x y) = v ↔ g x = g y * v :=
(toLocalizationMap M S).lift_mk'_spec _ _ _ _
#align is_localization.lift_mk'_spec IsLocalization.lift_mk'_spec
@[simp]
theorem lift_eq (x : R) : lift hg ((algebraMap R S) x) = g x :=
(toLocalizationMap M S).lift_eq _ _
#align is_localization.lift_eq IsLocalization.lift_eq
theorem lift_eq_iff {x y : R × M} :
lift hg (mk' S x.1 x.2) = lift hg (mk' S y.1 y.2) ↔ g (x.1 * y.2) = g (y.1 * x.2) :=
(toLocalizationMap M S).lift_eq_iff _
#align is_localization.lift_eq_iff IsLocalization.lift_eq_iff
@[simp]
theorem lift_comp : (lift hg).comp (algebraMap R S) = g :=
RingHom.ext <| (DFunLike.ext_iff (F := MonoidHom _ _)).1 <| (toLocalizationMap M S).lift_comp _
#align is_localization.lift_comp IsLocalization.lift_comp
@[simp]
theorem lift_of_comp (j : S →+* P) : lift (isUnit_comp M j) = j :=
RingHom.ext <| (DFunLike.ext_iff (F := MonoidHom _ _)).1 <|
(toLocalizationMap M S).lift_of_comp j.toMonoidHom
#align is_localization.lift_of_comp IsLocalization.lift_of_comp
variable (M)
/-- See note [partially-applied ext lemmas] -/
theorem monoidHom_ext ⦃j k : S →* P⦄
(h : j.comp (algebraMap R S : R →* S) = k.comp (algebraMap R S)) : j = k :=
Submonoid.LocalizationMap.epic_of_localizationMap (toLocalizationMap M S) <| DFunLike.congr_fun h
#align is_localization.monoid_hom_ext IsLocalization.monoidHom_ext
/-- See note [partially-applied ext lemmas] -/
theorem ringHom_ext ⦃j k : S →+* P⦄ (h : j.comp (algebraMap R S) = k.comp (algebraMap R S)) :
j = k :=
RingHom.coe_monoidHom_injective <| monoidHom_ext M <| MonoidHom.ext <| RingHom.congr_fun h
#align is_localization.ring_hom_ext IsLocalization.ringHom_ext
/- This is not an instance because the submonoid `M` would become a metavariable
in typeclass search. -/
theorem algHom_subsingleton [Algebra R P] : Subsingleton (S →ₐ[R] P) :=
⟨fun f g =>
AlgHom.coe_ringHom_injective <|
IsLocalization.ringHom_ext M <| by rw [f.comp_algebraMap, g.comp_algebraMap]⟩
#align is_localization.alg_hom_subsingleton IsLocalization.algHom_subsingleton
/-- To show `j` and `k` agree on the whole localization, it suffices to show they agree
on the image of the base ring, if they preserve `1` and `*`. -/
protected theorem ext (j k : S → P) (hj1 : j 1 = 1) (hk1 : k 1 = 1)
(hjm : ∀ a b, j (a * b) = j a * j b) (hkm : ∀ a b, k (a * b) = k a * k b)
(h : ∀ a, j (algebraMap R S a) = k (algebraMap R S a)) : j = k :=
let j' : MonoidHom S P :=
{ toFun := j, map_one' := hj1, map_mul' := hjm }
let k' : MonoidHom S P :=
{ toFun := k, map_one' := hk1, map_mul' := hkm }
have : j' = k' := monoidHom_ext M (MonoidHom.ext h)
show j'.toFun = k'.toFun by rw [this]
#align is_localization.ext IsLocalization.ext
variable {M}
theorem lift_unique {j : S →+* P} (hj : ∀ x, j ((algebraMap R S) x) = g x) : lift hg = j :=
RingHom.ext <|
(DFunLike.ext_iff (F := MonoidHom _ _)).1 <|
Submonoid.LocalizationMap.lift_unique (toLocalizationMap M S) (g := g.toMonoidHom) hg
(j := j.toMonoidHom) hj
#align is_localization.lift_unique IsLocalization.lift_unique
@[simp]
theorem lift_id (x) : lift (map_units S : ∀ _ : M, IsUnit _) x = x :=
(toLocalizationMap M S).lift_id _
#align is_localization.lift_id IsLocalization.lift_id
theorem lift_surjective_iff :
Surjective (lift hg : S → P) ↔ ∀ v : P, ∃ x : R × M, v * g x.2 = g x.1 :=
(toLocalizationMap M S).lift_surjective_iff hg
#align is_localization.lift_surjective_iff IsLocalization.lift_surjective_iff
theorem lift_injective_iff :
Injective (lift hg : S → P) ↔ ∀ x y, algebraMap R S x = algebraMap R S y ↔ g x = g y :=
(toLocalizationMap M S).lift_injective_iff hg
#align is_localization.lift_injective_iff IsLocalization.lift_injective_iff
section Map
variable {T : Submonoid P} {Q : Type*} [CommSemiring Q] (hy : M ≤ T.comap g)
variable [Algebra P Q] [IsLocalization T Q]
section
variable (Q)
/-- Map a homomorphism `g : R →+* P` to `S →+* Q`, where `S` and `Q` are
localizations of `R` and `P` at `M` and `T` respectively,
such that `g(M) ⊆ T`.
We send `z : S` to `algebraMap P Q (g x) * (algebraMap P Q (g y))⁻¹`, where
`(x, y) : R × M` are such that `z = f x * (f y)⁻¹`. -/
noncomputable def map (g : R →+* P) (hy : M ≤ T.comap g) : S →+* Q :=
lift (M := M) (g := (algebraMap P Q).comp g) fun y => map_units _ ⟨g y, hy y.2⟩
#align is_localization.map IsLocalization.map
end
-- Porting note: added `simp` attribute, since it proves very similar lemmas marked `simp`
@[simp]
theorem map_eq (x) : map Q g hy ((algebraMap R S) x) = algebraMap P Q (g x) :=
lift_eq (fun y => map_units _ ⟨g y, hy y.2⟩) x
#align is_localization.map_eq IsLocalization.map_eq
@[simp]
theorem map_comp : (map Q g hy).comp (algebraMap R S) = (algebraMap P Q).comp g :=
lift_comp fun y => map_units _ ⟨g y, hy y.2⟩
#align is_localization.map_comp IsLocalization.map_comp
theorem map_mk' (x) (y : M) : map Q g hy (mk' S x y) = mk' Q (g x) ⟨g y, hy y.2⟩ :=
Submonoid.LocalizationMap.map_mk' (toLocalizationMap M S) (g := g.toMonoidHom)
(fun y => hy y.2) (k := toLocalizationMap T Q) ..
#align is_localization.map_mk' IsLocalization.map_mk'
-- Porting note (#10756): new theorem
@[simp]
theorem map_id_mk' {Q : Type*} [CommSemiring Q] [Algebra R Q] [IsLocalization M Q] (x) (y : M) :
map Q (RingHom.id R) (le_refl M) (mk' S x y) = mk' Q x y :=
map_mk' ..
@[simp]
theorem map_id (z : S) (h : M ≤ M.comap (RingHom.id R) := le_refl M) :
map S (RingHom.id _) h z = z :=
lift_id _
#align is_localization.map_id IsLocalization.map_id
theorem map_unique (j : S →+* Q) (hj : ∀ x : R, j (algebraMap R S x) = algebraMap P Q (g x)) :
map Q g hy = j :=
lift_unique (fun y => map_units _ ⟨g y, hy y.2⟩) hj
#align is_localization.map_unique IsLocalization.map_unique
/-- If `CommSemiring` homs `g : R →+* P, l : P →+* A` induce maps of localizations, the composition
of the induced maps equals the map of localizations induced by `l ∘ g`. -/
theorem map_comp_map {A : Type*} [CommSemiring A] {U : Submonoid A} {W} [CommSemiring W]
[Algebra A W] [IsLocalization U W] {l : P →+* A} (hl : T ≤ U.comap l) :
(map W l hl).comp (map Q g hy : S →+* _) = map W (l.comp g) fun _ hx => hl (hy hx) :=
RingHom.ext fun x =>
Submonoid.LocalizationMap.map_map (P := P) (toLocalizationMap M S) (fun y => hy y.2)
(toLocalizationMap U W) (fun w => hl w.2) x
#align is_localization.map_comp_map IsLocalization.map_comp_map
/-- If `CommSemiring` homs `g : R →+* P, l : P →+* A` induce maps of localizations, the composition
of the induced maps equals the map of localizations induced by `l ∘ g`. -/
| Mathlib/RingTheory/Localization/Basic.lean | 676 | 679 | theorem map_map {A : Type*} [CommSemiring A] {U : Submonoid A} {W} [CommSemiring W] [Algebra A W]
[IsLocalization U W] {l : P →+* A} (hl : T ≤ U.comap l) (x : S) :
map W l hl (map Q g hy x) = map W (l.comp g) (fun x hx => hl (hy hx)) x := by |
rw [← map_comp_map (Q := Q) hy hl]; rfl
|
/-
Copyright (c) 2020 Riccardo Brasca. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Riccardo Brasca, Johan Commelin
-/
import Mathlib.RingTheory.RootsOfUnity.Basic
import Mathlib.FieldTheory.Minpoly.IsIntegrallyClosed
import Mathlib.Algebra.GCDMonoid.IntegrallyClosed
import Mathlib.FieldTheory.Finite.Basic
#align_import ring_theory.roots_of_unity.minpoly from "leanprover-community/mathlib"@"7fdeecc0d03cd40f7a165e6cf00a4d2286db599f"
/-!
# Minimal polynomial of roots of unity
We gather several results about minimal polynomial of root of unity.
## Main results
* `IsPrimitiveRoot.totient_le_degree_minpoly`: The degree of the minimal polynomial of an `n`-th
primitive root of unity is at least `totient n`.
-/
open minpoly Polynomial
open scoped Polynomial
namespace IsPrimitiveRoot
section CommRing
variable {n : ℕ} {K : Type*} [CommRing K] {μ : K} (h : IsPrimitiveRoot μ n)
/-- `μ` is integral over `ℤ`. -/
-- Porting note: `hpos` was in the `variable` line, with an `omit` in mathlib3 just after this
-- declaration. For some reason, in Lean4, `hpos` gets included also in the declarations below,
-- even if it is not used in the proof.
theorem isIntegral (hpos : 0 < n) : IsIntegral ℤ μ := by
use X ^ n - 1
constructor
· exact monic_X_pow_sub_C 1 (ne_of_lt hpos).symm
· simp only [((IsPrimitiveRoot.iff_def μ n).mp h).left, eval₂_one, eval₂_X_pow, eval₂_sub,
sub_self]
#align is_primitive_root.is_integral IsPrimitiveRoot.isIntegral
section IsDomain
variable [IsDomain K] [CharZero K]
/-- The minimal polynomial of a root of unity `μ` divides `X ^ n - 1`. -/
theorem minpoly_dvd_x_pow_sub_one : minpoly ℤ μ ∣ X ^ n - 1 := by
rcases n.eq_zero_or_pos with (rfl | h0)
· simp
apply minpoly.isIntegrallyClosed_dvd (isIntegral h h0)
simp only [((IsPrimitiveRoot.iff_def μ n).mp h).left, aeval_X_pow, eq_intCast, Int.cast_one,
aeval_one, AlgHom.map_sub, sub_self]
set_option linter.uppercaseLean3 false in
#align is_primitive_root.minpoly_dvd_X_pow_sub_one IsPrimitiveRoot.minpoly_dvd_x_pow_sub_one
/-- The reduction modulo `p` of the minimal polynomial of a root of unity `μ` is separable. -/
theorem separable_minpoly_mod {p : ℕ} [Fact p.Prime] (hdiv : ¬p ∣ n) :
Separable (map (Int.castRingHom (ZMod p)) (minpoly ℤ μ)) := by
have hdvd : map (Int.castRingHom (ZMod p)) (minpoly ℤ μ) ∣ X ^ n - 1 := by
convert RingHom.map_dvd (mapRingHom (Int.castRingHom (ZMod p)))
(minpoly_dvd_x_pow_sub_one h)
simp only [map_sub, map_pow, coe_mapRingHom, map_X, map_one]
refine Separable.of_dvd (separable_X_pow_sub_C 1 ?_ one_ne_zero) hdvd
by_contra hzero
exact hdiv ((ZMod.natCast_zmod_eq_zero_iff_dvd n p).1 hzero)
#align is_primitive_root.separable_minpoly_mod IsPrimitiveRoot.separable_minpoly_mod
/-- The reduction modulo `p` of the minimal polynomial of a root of unity `μ` is squarefree. -/
theorem squarefree_minpoly_mod {p : ℕ} [Fact p.Prime] (hdiv : ¬p ∣ n) :
Squarefree (map (Int.castRingHom (ZMod p)) (minpoly ℤ μ)) :=
(separable_minpoly_mod h hdiv).squarefree
#align is_primitive_root.squarefree_minpoly_mod IsPrimitiveRoot.squarefree_minpoly_mod
/-- Let `P` be the minimal polynomial of a root of unity `μ` and `Q` be the minimal polynomial of
`μ ^ p`, where `p` is a natural number that does not divide `n`. Then `P` divides `expand ℤ p Q`. -/
theorem minpoly_dvd_expand {p : ℕ} (hdiv : ¬p ∣ n) :
minpoly ℤ μ ∣ expand ℤ p (minpoly ℤ (μ ^ p)) := by
rcases n.eq_zero_or_pos with (rfl | hpos)
· simp_all
letI : IsIntegrallyClosed ℤ := GCDMonoid.toIsIntegrallyClosed
refine minpoly.isIntegrallyClosed_dvd (h.isIntegral hpos) ?_
rw [aeval_def, coe_expand, ← comp, eval₂_eq_eval_map, map_comp, Polynomial.map_pow, map_X,
eval_comp, eval_pow, eval_X, ← eval₂_eq_eval_map, ← aeval_def]
exact minpoly.aeval _ _
#align is_primitive_root.minpoly_dvd_expand IsPrimitiveRoot.minpoly_dvd_expand
/-- Let `P` be the minimal polynomial of a root of unity `μ` and `Q` be the minimal polynomial of
`μ ^ p`, where `p` is a prime that does not divide `n`. Then `P` divides `Q ^ p` modulo `p`. -/
theorem minpoly_dvd_pow_mod {p : ℕ} [hprime : Fact p.Prime] (hdiv : ¬p ∣ n) :
map (Int.castRingHom (ZMod p)) (minpoly ℤ μ) ∣
map (Int.castRingHom (ZMod p)) (minpoly ℤ (μ ^ p)) ^ p := by
set Q := minpoly ℤ (μ ^ p)
have hfrob :
map (Int.castRingHom (ZMod p)) Q ^ p = map (Int.castRingHom (ZMod p)) (expand ℤ p Q) := by
rw [← ZMod.expand_card, map_expand]
rw [hfrob]
apply RingHom.map_dvd (mapRingHom (Int.castRingHom (ZMod p)))
exact minpoly_dvd_expand h hdiv
#align is_primitive_root.minpoly_dvd_pow_mod IsPrimitiveRoot.minpoly_dvd_pow_mod
/-- Let `P` be the minimal polynomial of a root of unity `μ` and `Q` be the minimal polynomial of
`μ ^ p`, where `p` is a prime that does not divide `n`. Then `P` divides `Q` modulo `p`. -/
theorem minpoly_dvd_mod_p {p : ℕ} [Fact p.Prime] (hdiv : ¬p ∣ n) :
map (Int.castRingHom (ZMod p)) (minpoly ℤ μ) ∣
map (Int.castRingHom (ZMod p)) (minpoly ℤ (μ ^ p)) :=
(squarefree_minpoly_mod h hdiv).isRadical _ _ (minpoly_dvd_pow_mod h hdiv)
#align is_primitive_root.minpoly_dvd_mod_p IsPrimitiveRoot.minpoly_dvd_mod_p
/-- If `p` is a prime that does not divide `n`,
then the minimal polynomials of a primitive `n`-th root of unity `μ`
and of `μ ^ p` are the same. -/
theorem minpoly_eq_pow {p : ℕ} [hprime : Fact p.Prime] (hdiv : ¬p ∣ n) :
minpoly ℤ μ = minpoly ℤ (μ ^ p) := by
classical
by_cases hn : n = 0
· simp_all
have hpos := Nat.pos_of_ne_zero hn
by_contra hdiff
set P := minpoly ℤ μ
set Q := minpoly ℤ (μ ^ p)
have Pmonic : P.Monic := minpoly.monic (h.isIntegral hpos)
have Qmonic : Q.Monic := minpoly.monic ((h.pow_of_prime hprime.1 hdiv).isIntegral hpos)
have Pirr : Irreducible P := minpoly.irreducible (h.isIntegral hpos)
have Qirr : Irreducible Q := minpoly.irreducible ((h.pow_of_prime hprime.1 hdiv).isIntegral hpos)
have PQprim : IsPrimitive (P * Q) := Pmonic.isPrimitive.mul Qmonic.isPrimitive
have prod : P * Q ∣ X ^ n - 1 := by
rw [IsPrimitive.Int.dvd_iff_map_cast_dvd_map_cast (P * Q) (X ^ n - 1) PQprim
(monic_X_pow_sub_C (1 : ℤ) (ne_of_gt hpos)).isPrimitive,
Polynomial.map_mul]
refine IsCoprime.mul_dvd ?_ ?_ ?_
· have aux := IsPrimitive.Int.irreducible_iff_irreducible_map_cast Pmonic.isPrimitive
refine (dvd_or_coprime _ _ (aux.1 Pirr)).resolve_left ?_
rw [map_dvd_map (Int.castRingHom ℚ) Int.cast_injective Pmonic]
intro hdiv
refine hdiff (eq_of_monic_of_associated Pmonic Qmonic ?_)
exact associated_of_dvd_dvd hdiv (Pirr.dvd_symm Qirr hdiv)
· apply (map_dvd_map (Int.castRingHom ℚ) Int.cast_injective Pmonic).2
exact minpoly_dvd_x_pow_sub_one h
· apply (map_dvd_map (Int.castRingHom ℚ) Int.cast_injective Qmonic).2
exact minpoly_dvd_x_pow_sub_one (pow_of_prime h hprime.1 hdiv)
replace prod := RingHom.map_dvd (mapRingHom (Int.castRingHom (ZMod p))) prod
rw [coe_mapRingHom, Polynomial.map_mul, Polynomial.map_sub, Polynomial.map_one,
Polynomial.map_pow, map_X] at prod
obtain ⟨R, hR⟩ := minpoly_dvd_mod_p h hdiv
rw [hR, ← mul_assoc, ← Polynomial.map_mul, ← sq, Polynomial.map_pow] at prod
have habs : map (Int.castRingHom (ZMod p)) P ^ 2 ∣ map (Int.castRingHom (ZMod p)) P ^ 2 * R := by
use R
replace habs :=
lt_of_lt_of_le (PartENat.coe_lt_coe.2 one_lt_two)
(multiplicity.le_multiplicity_of_pow_dvd (dvd_trans habs prod))
have hfree : Squarefree (X ^ n - 1 : (ZMod p)[X]) :=
(separable_X_pow_sub_C 1 (fun h => hdiv <| (ZMod.natCast_zmod_eq_zero_iff_dvd n p).1 h)
one_ne_zero).squarefree
cases'
(multiplicity.squarefree_iff_multiplicity_le_one (X ^ n - 1)).1 hfree
(map (Int.castRingHom (ZMod p)) P) with
hle hunit
· rw [Nat.cast_one] at habs; exact hle.not_lt habs
· replace hunit := degree_eq_zero_of_isUnit hunit
rw [degree_map_eq_of_leadingCoeff_ne_zero (Int.castRingHom (ZMod p)) _] at hunit
· exact (minpoly.degree_pos (isIntegral h hpos)).ne' hunit
simp only [Pmonic, eq_intCast, Monic.leadingCoeff, Int.cast_one, Ne, not_false_iff,
one_ne_zero]
#align is_primitive_root.minpoly_eq_pow IsPrimitiveRoot.minpoly_eq_pow
/-- If `m : ℕ` is coprime with `n`,
then the minimal polynomials of a primitive `n`-th root of unity `μ`
and of `μ ^ m` are the same. -/
| Mathlib/RingTheory/RootsOfUnity/Minpoly.lean | 175 | 193 | theorem minpoly_eq_pow_coprime {m : ℕ} (hcop : Nat.Coprime m n) :
minpoly ℤ μ = minpoly ℤ (μ ^ m) := by |
revert n hcop
refine UniqueFactorizationMonoid.induction_on_prime m ?_ ?_ ?_
· intro h hn
congr
simpa [(Nat.coprime_zero_left _).mp hn] using h
· intro u hunit _ _
congr
simp [Nat.isUnit_iff.mp hunit]
· intro a p _ hprime
intro hind h hcop
rw [hind h (Nat.Coprime.coprime_mul_left hcop)]; clear hind
replace hprime := hprime.nat_prime
have hdiv := (Nat.Prime.coprime_iff_not_dvd hprime).1 (Nat.Coprime.coprime_mul_right hcop)
haveI := Fact.mk hprime
rw [minpoly_eq_pow (h.pow_of_coprime a (Nat.Coprime.coprime_mul_left hcop)) hdiv]
congr 1
ring
|
/-
Copyright (c) 2022 María Inés de Frutos-Fernández. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: María Inés de Frutos-Fernández
-/
import Mathlib.RingTheory.DedekindDomain.Ideal
#align_import ring_theory.dedekind_domain.factorization from "leanprover-community/mathlib"@"2f588be38bb5bec02f218ba14f82fc82eb663f87"
/-!
# Factorization of ideals and fractional ideals of Dedekind domains
Every nonzero ideal `I` of a Dedekind domain `R` can be factored as a product `∏_v v^{n_v}` over the
maximal ideals of `R`, where the exponents `n_v` are natural numbers.
Similarly, every nonzero fractional ideal `I` of a Dedekind domain `R` can be factored as a product
`∏_v v^{n_v}` over the maximal ideals of `R`, where the exponents `n_v` are integers. We define
`FractionalIdeal.count K v I` (abbreviated as `val_v(I)` in the documentation) to be `n_v`, and we
prove some of its properties. If `I = 0`, we define `val_v(I) = 0`.
## Main definitions
- `FractionalIdeal.count` : If `I` is a nonzero fractional ideal, `a ∈ R`, and `J` is an ideal of
`R` such that `I = a⁻¹J`, then we define `val_v(I)` as `(val_v(J) - val_v(a))`. If `I = 0`, we
set `val_v(I) = 0`.
## Main results
- `Ideal.finite_factors` : Only finitely many maximal ideals of `R` divide a given nonzero ideal.
- `Ideal.finprod_heightOneSpectrum_factorization` : The ideal `I` equals the finprod
`∏_v v^(val_v(I))`, where `val_v(I)` denotes the multiplicity of `v` in the factorization of `I`
and `v` runs over the maximal ideals of `R`.
- `FractionalIdeal.finprod_heightOneSpectrum_factorization` : If `I` is a nonzero fractional ideal,
`a ∈ R`, and `J` is an ideal of `R` such that `I = a⁻¹J`, then `I` is equal to the product
`∏_v v^(val_v(J) - val_v(a))`.
- `FractionalIdeal.finprod_heightOneSpectrum_factorization'` : If `I` is a nonzero fractional
ideal, then `I` is equal to the product `∏_v v^(val_v(I))`.
- `FractionalIdeal.finprod_heightOneSpectrum_factorization_principal` : For a nonzero `k = r/s ∈ K`,
the fractional ideal `(k)` is equal to the product `∏_v v^(val_v(r) - val_v(s))`.
- `FractionalIdeal.finite_factors` : If `I ≠ 0`, then `val_v(I) = 0` for all but finitely many
maximal ideals of `R`.
## Implementation notes
Since we are only interested in the factorization of nonzero fractional ideals, we define
`val_v(0) = 0` so that every `val_v` is in `ℤ` and we can avoid having to use `WithTop ℤ`.
## Tags
dedekind domain, fractional ideal, ideal, factorization
-/
noncomputable section
open scoped Classical nonZeroDivisors
open Set Function UniqueFactorizationMonoid IsDedekindDomain IsDedekindDomain.HeightOneSpectrum
Classical
variable {R : Type*} [CommRing R] {K : Type*} [Field K] [Algebra R K] [IsFractionRing R K]
/-! ### Factorization of ideals of Dedekind domains -/
variable [IsDedekindDomain R] (v : HeightOneSpectrum R)
/-- Given a maximal ideal `v` and an ideal `I` of `R`, `maxPowDividing` returns the maximal
power of `v` dividing `I`. -/
def IsDedekindDomain.HeightOneSpectrum.maxPowDividing (I : Ideal R) : Ideal R :=
v.asIdeal ^ (Associates.mk v.asIdeal).count (Associates.mk I).factors
#align is_dedekind_domain.height_one_spectrum.max_pow_dividing IsDedekindDomain.HeightOneSpectrum.maxPowDividing
/-- Only finitely many maximal ideals of `R` divide a given nonzero ideal. -/
theorem Ideal.finite_factors {I : Ideal R} (hI : I ≠ 0) :
{v : HeightOneSpectrum R | v.asIdeal ∣ I}.Finite := by
rw [← Set.finite_coe_iff, Set.coe_setOf]
haveI h_fin := fintypeSubtypeDvd I hI
refine
Finite.of_injective (fun v => (⟨(v : HeightOneSpectrum R).asIdeal, v.2⟩ : { x // x ∣ I })) ?_
intro v w hvw
simp? at hvw says simp only [Subtype.mk.injEq] at hvw
exact Subtype.coe_injective ((HeightOneSpectrum.ext_iff (R := R) ↑v ↑w).mpr hvw)
#align ideal.finite_factors Ideal.finite_factors
/-- For every nonzero ideal `I` of `v`, there are finitely many maximal ideals `v` such that the
multiplicity of `v` in the factorization of `I`, denoted `val_v(I)`, is nonzero. -/
theorem Associates.finite_factors {I : Ideal R} (hI : I ≠ 0) :
∀ᶠ v : HeightOneSpectrum R in Filter.cofinite,
((Associates.mk v.asIdeal).count (Associates.mk I).factors : ℤ) = 0 := by
have h_supp : {v : HeightOneSpectrum R | ¬((Associates.mk v.asIdeal).count
(Associates.mk I).factors : ℤ) = 0} = {v : HeightOneSpectrum R | v.asIdeal ∣ I} := by
ext v
simp_rw [Int.natCast_eq_zero]
exact Associates.count_ne_zero_iff_dvd hI v.irreducible
rw [Filter.eventually_cofinite, h_supp]
exact Ideal.finite_factors hI
#align associates.finite_factors Associates.finite_factors
namespace Ideal
/-- For every nonzero ideal `I` of `v`, there are finitely many maximal ideals `v` such that
`v^(val_v(I))` is not the unit ideal. -/
theorem finite_mulSupport {I : Ideal R} (hI : I ≠ 0) :
(mulSupport fun v : HeightOneSpectrum R => v.maxPowDividing I).Finite :=
haveI h_subset : {v : HeightOneSpectrum R | v.maxPowDividing I ≠ 1} ⊆
{v : HeightOneSpectrum R |
((Associates.mk v.asIdeal).count (Associates.mk I).factors : ℤ) ≠ 0} := by
intro v hv h_zero
have hv' : v.maxPowDividing I = 1 := by
rw [IsDedekindDomain.HeightOneSpectrum.maxPowDividing, Int.natCast_eq_zero.mp h_zero,
pow_zero _]
exact hv hv'
Finite.subset (Filter.eventually_cofinite.mp (Associates.finite_factors hI)) h_subset
#align ideal.finite_mul_support Ideal.finite_mulSupport
/-- For every nonzero ideal `I` of `v`, there are finitely many maximal ideals `v` such that
`v^(val_v(I))`, regarded as a fractional ideal, is not `(1)`. -/
theorem finite_mulSupport_coe {I : Ideal R} (hI : I ≠ 0) :
(mulSupport fun v : HeightOneSpectrum R => (v.asIdeal : FractionalIdeal R⁰ K) ^
((Associates.mk v.asIdeal).count (Associates.mk I).factors : ℤ)).Finite := by
rw [mulSupport]
simp_rw [Ne, zpow_natCast, ← FractionalIdeal.coeIdeal_pow, FractionalIdeal.coeIdeal_eq_one]
exact finite_mulSupport hI
#align ideal.finite_mul_support_coe Ideal.finite_mulSupport_coe
/-- For every nonzero ideal `I` of `v`, there are finitely many maximal ideals `v` such that
`v^-(val_v(I))` is not the unit ideal. -/
theorem finite_mulSupport_inv {I : Ideal R} (hI : I ≠ 0) :
(mulSupport fun v : HeightOneSpectrum R => (v.asIdeal : FractionalIdeal R⁰ K) ^
(-((Associates.mk v.asIdeal).count (Associates.mk I).factors : ℤ))).Finite := by
rw [mulSupport]
simp_rw [zpow_neg, Ne, inv_eq_one]
exact finite_mulSupport_coe hI
#align ideal.finite_mul_support_inv Ideal.finite_mulSupport_inv
/-- For every nonzero ideal `I` of `v`, `v^(val_v(I) + 1)` does not divide `∏_v v^(val_v(I))`. -/
theorem finprod_not_dvd (I : Ideal R) (hI : I ≠ 0) :
¬v.asIdeal ^ ((Associates.mk v.asIdeal).count (Associates.mk I).factors + 1) ∣
∏ᶠ v : HeightOneSpectrum R, v.maxPowDividing I := by
have hf := finite_mulSupport hI
have h_ne_zero : v.maxPowDividing I ≠ 0 := pow_ne_zero _ v.ne_bot
rw [← mul_finprod_cond_ne v hf, pow_add, pow_one, finprod_cond_ne _ _ hf]
intro h_contr
have hv_prime : Prime v.asIdeal := Ideal.prime_of_isPrime v.ne_bot v.isPrime
obtain ⟨w, hw, hvw'⟩ :=
Prime.exists_mem_finset_dvd hv_prime ((mul_dvd_mul_iff_left h_ne_zero).mp h_contr)
have hw_prime : Prime w.asIdeal := Ideal.prime_of_isPrime w.ne_bot w.isPrime
have hvw := Prime.dvd_of_dvd_pow hv_prime hvw'
rw [Prime.dvd_prime_iff_associated hv_prime hw_prime, associated_iff_eq] at hvw
exact (Finset.mem_erase.mp hw).1 (HeightOneSpectrum.ext w v (Eq.symm hvw))
#align ideal.finprod_not_dvd Ideal.finprod_not_dvd
end Ideal
theorem Associates.finprod_ne_zero (I : Ideal R) :
Associates.mk (∏ᶠ v : HeightOneSpectrum R, v.maxPowDividing I) ≠ 0 := by
rw [Associates.mk_ne_zero, finprod_def]
split_ifs
· rw [Finset.prod_ne_zero_iff]
intro v _
apply pow_ne_zero _ v.ne_bot
· exact one_ne_zero
#align associates.finprod_ne_zero Associates.finprod_ne_zero
namespace Ideal
/-- The multiplicity of `v` in `∏_v v^(val_v(I))` equals `val_v(I)`. -/
theorem finprod_count (I : Ideal R) (hI : I ≠ 0) : (Associates.mk v.asIdeal).count
(Associates.mk (∏ᶠ v : HeightOneSpectrum R, v.maxPowDividing I)).factors =
(Associates.mk v.asIdeal).count (Associates.mk I).factors := by
have h_ne_zero := Associates.finprod_ne_zero I
have hv : Irreducible (Associates.mk v.asIdeal) := v.associates_irreducible
have h_dvd := finprod_mem_dvd v (Ideal.finite_mulSupport hI)
have h_not_dvd := Ideal.finprod_not_dvd v I hI
simp only [IsDedekindDomain.HeightOneSpectrum.maxPowDividing] at h_dvd h_ne_zero h_not_dvd
rw [← Associates.mk_dvd_mk] at h_dvd h_not_dvd
simp only [Associates.dvd_eq_le] at h_dvd h_not_dvd
rw [Associates.mk_pow, Associates.prime_pow_dvd_iff_le h_ne_zero hv] at h_dvd h_not_dvd
rw [not_le] at h_not_dvd
apply Nat.eq_of_le_of_lt_succ h_dvd h_not_dvd
#align ideal.finprod_count Ideal.finprod_count
/-- The ideal `I` equals the finprod `∏_v v^(val_v(I))`. -/
theorem finprod_heightOneSpectrum_factorization {I : Ideal R} (hI : I ≠ 0) :
∏ᶠ v : HeightOneSpectrum R, v.maxPowDividing I = I := by
rw [← associated_iff_eq, ← Associates.mk_eq_mk_iff_associated]
apply Associates.eq_of_eq_counts
· apply Associates.finprod_ne_zero I
· apply Associates.mk_ne_zero.mpr hI
intro v hv
obtain ⟨J, hJv⟩ := Associates.exists_rep v
rw [← hJv, Associates.irreducible_mk] at hv
rw [← hJv]
apply Ideal.finprod_count
⟨J, Ideal.isPrime_of_prime (irreducible_iff_prime.mp hv), Irreducible.ne_zero hv⟩ I hI
#align ideal.finprod_height_one_spectrum_factorization Ideal.finprod_heightOneSpectrum_factorization
variable (K)
/-- The ideal `I` equals the finprod `∏_v v^(val_v(I))`, when both sides are regarded as fractional
ideals of `R`. -/
theorem finprod_heightOneSpectrum_factorization_coe {I : Ideal R} (hI : I ≠ 0) :
(∏ᶠ v : HeightOneSpectrum R, (v.asIdeal : FractionalIdeal R⁰ K) ^
((Associates.mk v.asIdeal).count (Associates.mk I).factors : ℤ)) = I := by
conv_rhs => rw [← Ideal.finprod_heightOneSpectrum_factorization hI]
rw [FractionalIdeal.coeIdeal_finprod R⁰ K (le_refl _)]
simp_rw [IsDedekindDomain.HeightOneSpectrum.maxPowDividing, FractionalIdeal.coeIdeal_pow,
zpow_natCast]
#align ideal.finprod_height_one_spectrum_factorization_coe Ideal.finprod_heightOneSpectrum_factorization_coe
end Ideal
/-! ### Factorization of fractional ideals of Dedekind domains -/
namespace FractionalIdeal
open Int IsLocalization
/-- If `I` is a nonzero fractional ideal, `a ∈ R`, and `J` is an ideal of `R` such that
`I = a⁻¹J`, then `I` is equal to the product `∏_v v^(val_v(J) - val_v(a))`. -/
theorem finprod_heightOneSpectrum_factorization {I : FractionalIdeal R⁰ K} (hI : I ≠ 0) {a : R}
{J : Ideal R} (haJ : I = spanSingleton R⁰ ((algebraMap R K) a)⁻¹ * ↑J) :
∏ᶠ v : HeightOneSpectrum R, (v.asIdeal : FractionalIdeal R⁰ K) ^
((Associates.mk v.asIdeal).count (Associates.mk J).factors -
(Associates.mk v.asIdeal).count (Associates.mk (Ideal.span {a})).factors : ℤ) = I := by
have hJ_ne_zero : J ≠ 0 := ideal_factor_ne_zero hI haJ
have hJ := Ideal.finprod_heightOneSpectrum_factorization_coe K hJ_ne_zero
have ha_ne_zero : Ideal.span {a} ≠ 0 := constant_factor_ne_zero hI haJ
have ha := Ideal.finprod_heightOneSpectrum_factorization_coe K ha_ne_zero
rw [haJ, ← div_spanSingleton, div_eq_mul_inv, ← coeIdeal_span_singleton, ← hJ, ← ha,
← finprod_inv_distrib]
simp_rw [← zpow_neg]
rw [← finprod_mul_distrib (Ideal.finite_mulSupport_coe hJ_ne_zero)
(Ideal.finite_mulSupport_inv ha_ne_zero)]
apply finprod_congr
intro v
rw [← zpow_add₀ ((@coeIdeal_ne_zero R _ K _ _ _ _).mpr v.ne_bot), sub_eq_add_neg]
/-- For a nonzero `k = r/s ∈ K`, the fractional ideal `(k)` is equal to the product
`∏_v v^(val_v(r) - val_v(s))`. -/
theorem finprod_heightOneSpectrum_factorization_principal_fraction {n : R} (hn : n ≠ 0) (d : ↥R⁰) :
∏ᶠ v : HeightOneSpectrum R, (v.asIdeal : FractionalIdeal R⁰ K) ^
((Associates.mk v.asIdeal).count (Associates.mk (Ideal.span {n} : Ideal R)).factors -
(Associates.mk v.asIdeal).count (Associates.mk ((Ideal.span {(↑d : R)}) :
Ideal R)).factors : ℤ) = spanSingleton R⁰ (mk' K n d) := by
have hd_ne_zero : (algebraMap R K) (d : R) ≠ 0 :=
map_ne_zero_of_mem_nonZeroDivisors _ (IsFractionRing.injective R K) d.property
have h0 : spanSingleton R⁰ (mk' K n d) ≠ 0 := by
rw [spanSingleton_ne_zero_iff, IsFractionRing.mk'_eq_div, ne_eq, div_eq_zero_iff, not_or]
exact ⟨(map_ne_zero_iff (algebraMap R K) (IsFractionRing.injective R K)).mpr hn, hd_ne_zero⟩
have hI : spanSingleton R⁰ (mk' K n d) =
spanSingleton R⁰ ((algebraMap R K) d)⁻¹ * ↑(Ideal.span {n} : Ideal R) := by
rw [coeIdeal_span_singleton, spanSingleton_mul_spanSingleton]
apply congr_arg
rw [IsFractionRing.mk'_eq_div, div_eq_mul_inv, mul_comm]
exact finprod_heightOneSpectrum_factorization h0 hI
/-- For a nonzero `k = r/s ∈ K`, the fractional ideal `(k)` is equal to the product
`∏_v v^(val_v(r) - val_v(s))`. -/
theorem finprod_heightOneSpectrum_factorization_principal {I : FractionalIdeal R⁰ K} (hI : I ≠ 0)
(k : K) (hk : I = spanSingleton R⁰ k) :
∏ᶠ v : HeightOneSpectrum R, (v.asIdeal : FractionalIdeal R⁰ K) ^
((Associates.mk v.asIdeal).count (Associates.mk (Ideal.span {choose
(mk'_surjective R⁰ k)} : Ideal R)).factors -
(Associates.mk v.asIdeal).count (Associates.mk ((Ideal.span {(↑(choose
(choose_spec (mk'_surjective R⁰ k)) : ↥R⁰) : R)}) : Ideal R)).factors : ℤ) = I := by
set n : R := choose (mk'_surjective R⁰ k)
set d : ↥R⁰ := choose (choose_spec (mk'_surjective R⁰ k))
have hnd : mk' K n d = k := choose_spec (choose_spec (mk'_surjective R⁰ k))
have hn0 : n ≠ 0 := by
by_contra h
rw [← hnd, h, IsFractionRing.mk'_eq_div, _root_.map_zero,
zero_div, spanSingleton_zero] at hk
exact hI hk
rw [finprod_heightOneSpectrum_factorization_principal_fraction hn0 d, hk, hnd]
variable (K)
/-- If `I` is a nonzero fractional ideal, `a ∈ R`, and `J` is an ideal of `R` such that `I = a⁻¹J`,
then we define `val_v(I)` as `(val_v(J) - val_v(a))`. If `I = 0`, we set `val_v(I) = 0`. -/
def count (I : FractionalIdeal R⁰ K) : ℤ :=
dite (I = 0) (fun _ : I = 0 => 0) fun _ : ¬I = 0 =>
let a := choose (exists_eq_spanSingleton_mul I)
let J := choose (choose_spec (exists_eq_spanSingleton_mul I))
((Associates.mk v.asIdeal).count (Associates.mk J).factors -
(Associates.mk v.asIdeal).count (Associates.mk (Ideal.span {a})).factors : ℤ)
/-- val_v(0) = 0. -/
lemma count_zero : count K v (0 : FractionalIdeal R⁰ K) = 0 := by simp only [count, dif_pos]
lemma count_ne_zero {I : FractionalIdeal R⁰ K} (hI : I ≠ 0) :
count K v I = ((Associates.mk v.asIdeal).count (Associates.mk
(choose (choose_spec (exists_eq_spanSingleton_mul I)))).factors -
(Associates.mk v.asIdeal).count
(Associates.mk (Ideal.span {choose (exists_eq_spanSingleton_mul I)})).factors : ℤ) := by
simp only [count, dif_neg hI]
/-- `val_v(I)` does not depend on the choice of `a` and `J` used to represent `I`. -/
theorem count_well_defined {I : FractionalIdeal R⁰ K} (hI : I ≠ 0) {a : R}
{J : Ideal R} (h_aJ : I = spanSingleton R⁰ ((algebraMap R K) a)⁻¹ * ↑J) :
count K v I = ((Associates.mk v.asIdeal).count (Associates.mk J).factors -
(Associates.mk v.asIdeal).count (Associates.mk (Ideal.span {a})).factors : ℤ) := by
set a₁ := choose (exists_eq_spanSingleton_mul I)
set J₁ := choose (choose_spec (exists_eq_spanSingleton_mul I))
have h_a₁J₁ : I = spanSingleton R⁰ ((algebraMap R K) a₁)⁻¹ * ↑J₁ :=
(choose_spec (choose_spec (exists_eq_spanSingleton_mul I))).2
have h_a₁_ne_zero : a₁ ≠ 0 := (choose_spec (choose_spec (exists_eq_spanSingleton_mul I))).1
have h_J₁_ne_zero : J₁ ≠ 0 := ideal_factor_ne_zero hI h_a₁J₁
have h_a_ne_zero : Ideal.span {a} ≠ 0 := constant_factor_ne_zero hI h_aJ
have h_J_ne_zero : J ≠ 0 := ideal_factor_ne_zero hI h_aJ
have h_a₁' : spanSingleton R⁰ ((algebraMap R K) a₁) ≠ 0 := by
rw [ne_eq, spanSingleton_eq_zero_iff, ← (algebraMap R K).map_zero,
Injective.eq_iff (IsLocalization.injective K (le_refl R⁰))]
exact h_a₁_ne_zero
have h_a' : spanSingleton R⁰ ((algebraMap R K) a) ≠ 0 := by
rw [ne_eq, spanSingleton_eq_zero_iff, ← (algebraMap R K).map_zero,
Injective.eq_iff (IsLocalization.injective K (le_refl R⁰))]
rw [ne_eq, Ideal.zero_eq_bot, Ideal.span_singleton_eq_bot] at h_a_ne_zero
exact h_a_ne_zero
have hv : Irreducible (Associates.mk v.asIdeal) := by
exact Associates.irreducible_mk.mpr v.irreducible
rw [h_a₁J₁, ← div_spanSingleton, ← div_spanSingleton, div_eq_div_iff h_a₁' h_a',
← coeIdeal_span_singleton, ← coeIdeal_span_singleton, ← coeIdeal_mul, ← coeIdeal_mul] at h_aJ
rw [count, dif_neg hI, sub_eq_sub_iff_add_eq_add, ← ofNat_add, ← ofNat_add, natCast_inj,
← Associates.count_mul _ _ hv, ← Associates.count_mul _ _ hv, Associates.mk_mul_mk,
Associates.mk_mul_mk, coeIdeal_injective h_aJ]
· rw [ne_eq, Associates.mk_eq_zero]; exact h_J_ne_zero
· rw [ne_eq, Associates.mk_eq_zero, Ideal.zero_eq_bot, Ideal.span_singleton_eq_bot]
exact h_a₁_ne_zero
· rw [ne_eq, Associates.mk_eq_zero]; exact h_J₁_ne_zero
· rw [ne_eq, Associates.mk_eq_zero]; exact h_a_ne_zero
/-- For nonzero `I, I'`, `val_v(I*I') = val_v(I) + val_v(I')`. -/
theorem count_mul {I I' : FractionalIdeal R⁰ K} (hI : I ≠ 0) (hI' : I' ≠ 0) :
count K v (I * I') = count K v I + count K v I' := by
have hv : Irreducible (Associates.mk v.asIdeal) := by apply v.associates_irreducible
obtain ⟨a, J, ha, haJ⟩ := exists_eq_spanSingleton_mul I
have ha_ne_zero : Associates.mk (Ideal.span {a} : Ideal R) ≠ 0 := by
rw [ne_eq, Associates.mk_eq_zero, Ideal.zero_eq_bot, Ideal.span_singleton_eq_bot]; exact ha
have hJ_ne_zero : Associates.mk J ≠ 0 := Associates.mk_ne_zero.mpr (ideal_factor_ne_zero hI haJ)
obtain ⟨a', J', ha', haJ'⟩ := exists_eq_spanSingleton_mul I'
have ha'_ne_zero : Associates.mk (Ideal.span {a'} : Ideal R) ≠ 0 := by
rw [ne_eq, Associates.mk_eq_zero, Ideal.zero_eq_bot, Ideal.span_singleton_eq_bot]; exact ha'
have hJ'_ne_zero : Associates.mk J' ≠ 0 :=
Associates.mk_ne_zero.mpr (ideal_factor_ne_zero hI' haJ')
have h_prod : I * I' = spanSingleton R⁰ ((algebraMap R K) (a * a'))⁻¹ * ↑(J * J') := by
rw [haJ, haJ', mul_assoc, mul_comm (J : FractionalIdeal R⁰ K), mul_assoc, ← mul_assoc,
spanSingleton_mul_spanSingleton, coeIdeal_mul, RingHom.map_mul, mul_inv,
mul_comm (J : FractionalIdeal R⁰ K)]
rw [count_well_defined K v hI haJ, count_well_defined K v hI' haJ',
count_well_defined K v (mul_ne_zero hI hI') h_prod, ← Associates.mk_mul_mk,
Associates.count_mul hJ_ne_zero hJ'_ne_zero hv, ← Ideal.span_singleton_mul_span_singleton,
← Associates.mk_mul_mk, Associates.count_mul ha_ne_zero ha'_ne_zero hv]
push_cast
ring
/-- For nonzero `I, I'`, `val_v(I*I') = val_v(I) + val_v(I')`. If `I` or `I'` is zero, then
`val_v(I*I') = 0`. -/
theorem count_mul' (I I' : FractionalIdeal R⁰ K) :
count K v (I * I') = if I ≠ 0 ∧ I' ≠ 0 then count K v I + count K v I' else 0 := by
split_ifs with h
· exact count_mul K v h.1 h.2
· push_neg at h
by_cases hI : I = 0
· rw [hI, MulZeroClass.zero_mul, count, dif_pos (Eq.refl _)]
· rw [h hI, MulZeroClass.mul_zero, count, dif_pos (Eq.refl _)]
/-- val_v(1) = 0. -/
theorem count_one : count K v (1 : FractionalIdeal R⁰ K) = 0 := by
have h1 : (1 : FractionalIdeal R⁰ K) =
spanSingleton R⁰ ((algebraMap R K) 1)⁻¹ * ↑(1 : Ideal R) := by
rw [(algebraMap R K).map_one, Ideal.one_eq_top, coeIdeal_top, mul_one, inv_one,
spanSingleton_one]
rw [count_well_defined K v one_ne_zero h1, Ideal.span_singleton_one, Ideal.one_eq_top, sub_self]
theorem count_prod {ι} (s : Finset ι) (I : ι → FractionalIdeal R⁰ K) (hS : ∀ i ∈ s, I i ≠ 0) :
count K v (∏ i ∈ s, I i) = ∑ i ∈ s, count K v (I i) := by
induction' s using Finset.induction with i s hi hrec
· rw [Finset.prod_empty, Finset.sum_empty, count_one]
· have hS' : ∀ i ∈ s, I i ≠ 0 := fun j hj => hS j (Finset.mem_insert_of_mem hj)
have hS0 : ∏ i ∈ s, I i ≠ 0 := Finset.prod_ne_zero_iff.mpr hS'
have hi0 : I i ≠ 0 := hS i (Finset.mem_insert_self i s)
rw [Finset.prod_insert hi, Finset.sum_insert hi, count_mul K v hi0 hS0, hrec hS']
/-- For every `n ∈ ℕ` and every ideal `I`, `val_v(I^n) = n*val_v(I)`. -/
theorem count_pow (n : ℕ) (I : FractionalIdeal R⁰ K) :
count K v (I ^ n) = n * count K v I := by
induction' n with n h
· rw [pow_zero, ofNat_zero, MulZeroClass.zero_mul, count_one]
· rw [pow_succ, count_mul']
by_cases hI : I = 0
· have h_neg : ¬(I ^ n ≠ 0 ∧ I ≠ 0) := by
rw [not_and', not_not, ne_eq]
intro h
exact absurd hI h
rw [if_neg h_neg, hI, count_zero, MulZeroClass.mul_zero]
· rw [if_pos (And.intro (pow_ne_zero n hI) hI), h, Nat.cast_add,
Nat.cast_one]
ring
/-- `val_v(v) = 1`, when `v` is regarded as a fractional ideal. -/
theorem count_self : count K v (v.asIdeal : FractionalIdeal R⁰ K) = 1 := by
have hv : (v.asIdeal : FractionalIdeal R⁰ K) ≠ 0 := coeIdeal_ne_zero.mpr v.ne_bot
have h_self : (v.asIdeal : FractionalIdeal R⁰ K) =
spanSingleton R⁰ ((algebraMap R K) 1)⁻¹ * ↑v.asIdeal := by
rw [(algebraMap R K).map_one, inv_one, spanSingleton_one, one_mul]
have hv_irred : Irreducible (Associates.mk v.asIdeal) := by apply v.associates_irreducible
rw [count_well_defined K v hv h_self, Associates.count_self hv_irred, Ideal.span_singleton_one,
← Ideal.one_eq_top, Associates.mk_one, Associates.factors_one, Associates.count_zero hv_irred,
ofNat_zero, sub_zero, ofNat_one]
/-- `val_v(v^n) = n` for every `n ∈ ℕ`. -/
theorem count_pow_self (n : ℕ) :
count K v ((v.asIdeal : FractionalIdeal R⁰ K) ^ n) = n := by
rw [count_pow, count_self, mul_one]
/-- `val_v(I⁻ⁿ) = -val_v(Iⁿ)` for every `n ∈ ℤ`. -/
theorem count_neg_zpow (n : ℤ) (I : FractionalIdeal R⁰ K) :
count K v (I ^ (-n)) = - count K v (I ^ n) := by
by_cases hI : I = 0
· by_cases hn : n = 0
· rw [hn, neg_zero, zpow_zero, count_one, neg_zero]
· rw [hI, zero_zpow n hn, zero_zpow (-n) (neg_ne_zero.mpr hn), count_zero, neg_zero]
· rw [eq_neg_iff_add_eq_zero, ← count_mul K v (zpow_ne_zero _ hI) (zpow_ne_zero _ hI),
← zpow_add₀ hI, neg_add_self, zpow_zero]
exact count_one K v
theorem count_inv (I : FractionalIdeal R⁰ K) :
count K v (I⁻¹) = - count K v I := by
rw [← zpow_neg_one, count_neg_zpow K v (1 : ℤ) I, zpow_one]
/-- `val_v(Iⁿ) = n*val_v(I)` for every `n ∈ ℤ`. -/
theorem count_zpow (n : ℤ) (I : FractionalIdeal R⁰ K) :
count K v (I ^ n) = n * count K v I := by
cases' n with n
· rw [ofNat_eq_coe, zpow_natCast]
exact count_pow K v n I
· rw [negSucc_coe, count_neg_zpow, zpow_natCast, count_pow]
ring
/-- `val_v(v^n) = n` for every `n ∈ ℤ`. -/
theorem count_zpow_self (n : ℤ) :
count K v ((v.asIdeal : FractionalIdeal R⁰ K) ^ n) = n := by
rw [count_zpow, count_self, mul_one]
/-- If `v ≠ w` are two maximal ideals of `R`, then `val_v(w) = 0`. -/
theorem count_maximal_coprime {w : HeightOneSpectrum R} (hw : w ≠ v) :
count K v (w.asIdeal : FractionalIdeal R⁰ K) = 0 := by
have hw_fact : (w.asIdeal : FractionalIdeal R⁰ K) =
spanSingleton R⁰ ((algebraMap R K) 1)⁻¹ * ↑w.asIdeal := by
rw [(algebraMap R K).map_one, inv_one, spanSingleton_one, one_mul]
have hw_ne_zero : (w.asIdeal : FractionalIdeal R⁰ K) ≠ 0 :=
coeIdeal_ne_zero.mpr w.ne_bot
have hv : Irreducible (Associates.mk v.asIdeal) := by apply v.associates_irreducible
have hw' : Irreducible (Associates.mk w.asIdeal) := by apply w.associates_irreducible
rw [count_well_defined K v hw_ne_zero hw_fact, Ideal.span_singleton_one, ← Ideal.one_eq_top,
Associates.mk_one, Associates.factors_one, Associates.count_zero hv, ofNat_zero, sub_zero,
natCast_eq_zero, ← pow_one (Associates.mk w.asIdeal), Associates.factors_prime_pow hw',
Associates.count_some hv, Multiset.replicate_one, Multiset.count_eq_zero,
Multiset.mem_singleton]
simp only [Subtype.mk.injEq]
rw [Associates.mk_eq_mk_iff_associated, associated_iff_eq, ← HeightOneSpectrum.ext_iff]
exact Ne.symm hw
theorem count_maximal (w : HeightOneSpectrum R) :
count K v (w.asIdeal : FractionalIdeal R⁰ K) = if w = v then 1 else 0 := by
split_ifs with h
· rw [h, count_self]
· exact count_maximal_coprime K v h
/-- `val_v(∏_{w ≠ v} w^{exps w}) = 0`. -/
theorem count_finprod_coprime (exps : HeightOneSpectrum R → ℤ) :
count K v (∏ᶠ (w : HeightOneSpectrum R) (_ : w ≠ v),
(w.asIdeal : (FractionalIdeal R⁰ K)) ^ exps w) = 0 := by
apply finprod_mem_induction fun I => count K v I = 0
· exact count_one K v
· intro I I' hI hI'
by_cases h : I ≠ 0 ∧ I' ≠ 0
· rw [count_mul' K v, if_pos h, hI, hI', add_zero]
· rw [count_mul' K v, if_neg h]
· intro w hw
rw [count_zpow, count_maximal_coprime K v hw, MulZeroClass.mul_zero]
theorem count_finsupp_prod (exps : HeightOneSpectrum R →₀ ℤ) :
count K v (exps.prod (HeightOneSpectrum.asIdeal · ^ ·)) = exps v := by
rw [Finsupp.prod, count_prod]
· simp only [count_zpow, count_maximal, mul_ite, mul_one, mul_zero, Finset.sum_ite_eq',
exps.mem_support_iff, ne_eq, ite_not, ite_eq_right_iff, @eq_comm ℤ 0, imp_self]
· exact fun v hv ↦ zpow_ne_zero _ (coeIdeal_ne_zero.mpr v.ne_bot)
/-- If `exps` is finitely supported, then `val_v(∏_w w^{exps w}) = exps v`. -/
theorem count_finprod (exps : HeightOneSpectrum R → ℤ)
(h_exps : ∀ᶠ v : HeightOneSpectrum R in Filter.cofinite, exps v = 0) :
count K v (∏ᶠ v : HeightOneSpectrum R,
(v.asIdeal : FractionalIdeal R⁰ K) ^ exps v) = exps v := by
convert count_finsupp_prod K v (Finsupp.mk h_exps.toFinset exps (fun _ ↦ h_exps.mem_toFinset))
rw [finprod_eq_finset_prod_of_mulSupport_subset (s := h_exps.toFinset), Finsupp.prod]
· rfl
· rw [Finite.coe_toFinset]
intro v hv h
rw [mem_mulSupport, h, zpow_zero] at hv
exact hv (Eq.refl 1)
theorem count_coe {J : Ideal R} (hJ : J ≠ 0) :
count K v J = (Associates.mk v.asIdeal).count (Associates.mk J).factors := by
rw [count_well_defined K (J := J) (a := 1), Ideal.span_singleton_one, sub_eq_self,
Nat.cast_eq_zero, ← Ideal.one_eq_top, Associates.mk_one, Associates.factors_one,
Associates.count_zero v.associates_irreducible]
· simpa only [ne_eq, coeIdeal_eq_zero]
· simp only [_root_.map_one, inv_one, spanSingleton_one, one_mul]
theorem count_coe_nonneg (J : Ideal R) : 0 ≤ count K v J := by
by_cases hJ : J = 0
· simp only [hJ, Submodule.zero_eq_bot, coeIdeal_bot, count_zero, le_refl]
· simp only [count_coe K v hJ, Nat.cast_nonneg]
| Mathlib/RingTheory/DedekindDomain/Factorization.lean | 511 | 519 | theorem count_mono {I J} (hI : I ≠ 0) (h : I ≤ J) : count K v J ≤ count K v I := by |
by_cases hJ : J = 0
· exact (hI (FractionalIdeal.le_zero_iff.mp (h.trans hJ.le))).elim
have := FractionalIdeal.mul_le_mul_left h J⁻¹
rw [inv_mul_cancel hJ, FractionalIdeal.le_one_iff_exists_coeIdeal] at this
obtain ⟨J', hJ'⟩ := this
rw [← mul_inv_cancel_left₀ hJ I, ← hJ', count_mul K v hJ, le_add_iff_nonneg_right]
· exact count_coe_nonneg K v J'
· exact hJ' ▸ mul_ne_zero (inv_ne_zero hJ) hI
|
/-
Copyright (c) 2018 Louis Carlin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Louis Carlin, Mario Carneiro
-/
import Mathlib.Algebra.Divisibility.Basic
import Mathlib.Algebra.Group.Basic
import Mathlib.Algebra.Ring.Defs
#align_import algebra.euclidean_domain.defs from "leanprover-community/mathlib"@"ee7b9f9a9ac2a8d9f04ea39bbfe6b1a3be053b38"
/-!
# Euclidean domains
This file introduces Euclidean domains and provides the extended Euclidean algorithm. To be precise,
a slightly more general version is provided which is sometimes called a transfinite Euclidean domain
and differs in the fact that the degree function need not take values in `ℕ` but can take values in
any well-ordered set. Transfinite Euclidean domains were introduced by Motzkin and examples which
don't satisfy the classical notion were provided independently by Hiblot and Nagata.
## Main definitions
* `EuclideanDomain`: Defines Euclidean domain with functions `quotient` and `remainder`. Instances
of `Div` and `Mod` are provided, so that one can write `a = b * (a / b) + a % b`.
* `gcd`: defines the greatest common divisors of two elements of a Euclidean domain.
* `xgcd`: given two elements `a b : R`, `xgcd a b` defines the pair `(x, y)` such that
`x * a + y * b = gcd a b`.
* `lcm`: defines the lowest common multiple of two elements `a` and `b` of a Euclidean domain as
`a * b / (gcd a b)`
## Main statements
See `Algebra.EuclideanDomain.Basic` for most of the theorems about Euclidean domains,
including Bézout's lemma.
See `Algebra.EuclideanDomain.Instances` for the fact that `ℤ` is a Euclidean domain,
as is any field.
## Notation
`≺` denotes the well founded relation on the Euclidean domain, e.g. in the example of the polynomial
ring over a field, `p ≺ q` for polynomials `p` and `q` if and only if the degree of `p` is less than
the degree of `q`.
## Implementation details
Instead of working with a valuation, `EuclideanDomain` is implemented with the existence of a well
founded relation `r` on the integral domain `R`, which in the example of `ℤ` would correspond to
setting `i ≺ j` for integers `i` and `j` if the absolute value of `i` is smaller than the absolute
value of `j`.
## References
* [Th. Motzkin, *The Euclidean algorithm*][MR32592]
* [J.-J. Hiblot, *Des anneaux euclidiens dont le plus petit algorithme n'est pas à valeurs finies*]
[MR399081]
* [M. Nagata, *On Euclid algorithm*][MR541021]
## Tags
Euclidean domain, transfinite Euclidean domain, Bézout's lemma
-/
universe u
/-- A `EuclideanDomain` is a non-trivial commutative ring with a division and a remainder,
satisfying `b * (a / b) + a % b = a`.
The definition of a Euclidean domain usually includes a valuation function `R → ℕ`.
This definition is slightly generalised to include a well founded relation
`r` with the property that `r (a % b) b`, instead of a valuation. -/
class EuclideanDomain (R : Type u) extends CommRing R, Nontrivial R where
/-- A division function (denoted `/`) on `R`.
This satisfies the property `b * (a / b) + a % b = a`, where `%` denotes `remainder`. -/
protected quotient : R → R → R
/-- Division by zero should always give zero by convention. -/
protected quotient_zero : ∀ a, quotient a 0 = 0
/-- A remainder function (denoted `%`) on `R`.
This satisfies the property `b * (a / b) + a % b = a`, where `/` denotes `quotient`. -/
protected remainder : R → R → R
/-- The property that links the quotient and remainder functions.
This allows us to compute GCDs and LCMs. -/
protected quotient_mul_add_remainder_eq : ∀ a b, b * quotient a b + remainder a b = a
/-- A well-founded relation on `R`, satisfying `r (a % b) b`.
This ensures that the GCD algorithm always terminates. -/
protected r : R → R → Prop
/-- The relation `r` must be well-founded.
This ensures that the GCD algorithm always terminates. -/
r_wellFounded : WellFounded r
/-- The relation `r` satisfies `r (a % b) b`. -/
protected remainder_lt : ∀ (a) {b}, b ≠ 0 → r (remainder a b) b
/-- An additional constraint on `r`. -/
mul_left_not_lt : ∀ (a) {b}, b ≠ 0 → ¬r (a * b) a
#align euclidean_domain EuclideanDomain
#align euclidean_domain.quotient EuclideanDomain.quotient
#align euclidean_domain.quotient_zero EuclideanDomain.quotient_zero
#align euclidean_domain.remainder EuclideanDomain.remainder
#align euclidean_domain.quotient_mul_add_remainder_eq EuclideanDomain.quotient_mul_add_remainder_eq
#align euclidean_domain.r EuclideanDomain.r
#align euclidean_domain.r_well_founded EuclideanDomain.r_wellFounded
#align euclidean_domain.remainder_lt EuclideanDomain.remainder_lt
#align euclidean_domain.mul_left_not_lt EuclideanDomain.mul_left_not_lt
namespace EuclideanDomain
variable {R : Type u} [EuclideanDomain R]
/-- Abbreviated notation for the well-founded relation `r` in a Euclidean domain. -/
local infixl:50 " ≺ " => EuclideanDomain.r
local instance wellFoundedRelation : WellFoundedRelation R where
wf := r_wellFounded
-- see Note [lower instance priority]
instance (priority := 70) : Div R :=
⟨EuclideanDomain.quotient⟩
-- see Note [lower instance priority]
instance (priority := 70) : Mod R :=
⟨EuclideanDomain.remainder⟩
theorem div_add_mod (a b : R) : b * (a / b) + a % b = a :=
EuclideanDomain.quotient_mul_add_remainder_eq _ _
#align euclidean_domain.div_add_mod EuclideanDomain.div_add_mod
theorem mod_add_div (a b : R) : a % b + b * (a / b) = a :=
(add_comm _ _).trans (div_add_mod _ _)
#align euclidean_domain.mod_add_div EuclideanDomain.mod_add_div
theorem mod_add_div' (m k : R) : m % k + m / k * k = m := by
rw [mul_comm]
exact mod_add_div _ _
#align euclidean_domain.mod_add_div' EuclideanDomain.mod_add_div'
theorem div_add_mod' (m k : R) : m / k * k + m % k = m := by
rw [mul_comm]
exact div_add_mod _ _
#align euclidean_domain.div_add_mod' EuclideanDomain.div_add_mod'
theorem mod_eq_sub_mul_div {R : Type*} [EuclideanDomain R] (a b : R) : a % b = a - b * (a / b) :=
calc
a % b = b * (a / b) + a % b - b * (a / b) := (add_sub_cancel_left _ _).symm
_ = a - b * (a / b) := by rw [div_add_mod]
#align euclidean_domain.mod_eq_sub_mul_div EuclideanDomain.mod_eq_sub_mul_div
theorem mod_lt : ∀ (a) {b : R}, b ≠ 0 → a % b ≺ b :=
EuclideanDomain.remainder_lt
#align euclidean_domain.mod_lt EuclideanDomain.mod_lt
theorem mul_right_not_lt {a : R} (b) (h : a ≠ 0) : ¬a * b ≺ b := by
rw [mul_comm]
exact mul_left_not_lt b h
#align euclidean_domain.mul_right_not_lt EuclideanDomain.mul_right_not_lt
@[simp]
theorem mod_zero (a : R) : a % 0 = a := by simpa only [zero_mul, zero_add] using div_add_mod a 0
#align euclidean_domain.mod_zero EuclideanDomain.mod_zero
theorem lt_one (a : R) : a ≺ (1 : R) → a = 0 :=
haveI := Classical.dec
not_imp_not.1 fun h => by simpa only [one_mul] using mul_left_not_lt 1 h
#align euclidean_domain.lt_one EuclideanDomain.lt_one
theorem val_dvd_le : ∀ a b : R, b ∣ a → a ≠ 0 → ¬a ≺ b
| _, b, ⟨d, rfl⟩, ha => mul_left_not_lt b (mt (by rintro rfl; exact mul_zero _) ha)
#align euclidean_domain.val_dvd_le EuclideanDomain.val_dvd_le
@[simp]
theorem div_zero (a : R) : a / 0 = 0 :=
EuclideanDomain.quotient_zero a
#align euclidean_domain.div_zero EuclideanDomain.div_zero
section
open scoped Classical
@[elab_as_elim]
theorem GCD.induction {P : R → R → Prop} (a b : R) (H0 : ∀ x, P 0 x)
(H1 : ∀ a b, a ≠ 0 → P (b % a) a → P a b) : P a b :=
if a0 : a = 0 then by
-- Porting note: required for hygiene, the equation compiler introduces a dummy variable `x`
-- See https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/unnecessarily.20tombstoned.20argument/near/314573315
change P a b
exact a0.symm ▸ H0 b
else
have _ := mod_lt b a0
H1 _ _ a0 (GCD.induction (b % a) a H0 H1)
termination_by a
#align euclidean_domain.gcd.induction EuclideanDomain.GCD.induction
end
section GCD
variable [DecidableEq R]
/-- `gcd a b` is a (non-unique) element such that `gcd a b ∣ a` `gcd a b ∣ b`, and for
any element `c` such that `c ∣ a` and `c ∣ b`, then `c ∣ gcd a b` -/
def gcd (a b : R) : R :=
if a0 : a = 0 then b
else
have _ := mod_lt b a0
gcd (b % a) a
termination_by a
#align euclidean_domain.gcd EuclideanDomain.gcd
@[simp]
| Mathlib/Algebra/EuclideanDomain/Defs.lean | 209 | 211 | theorem gcd_zero_left (a : R) : gcd 0 a = a := by |
rw [gcd]
exact if_pos rfl
|
/-
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.RingTheory.IntegrallyClosed
import Mathlib.RingTheory.Trace
import Mathlib.RingTheory.Norm
#align_import ring_theory.discriminant from "leanprover-community/mathlib"@"3e068ece210655b7b9a9477c3aff38a492400aa1"
/-!
# Discriminant of a family of vectors
Given an `A`-algebra `B` and `b`, an `ι`-indexed family of elements of `B`, we define the
*discriminant* of `b` as the determinant of the matrix whose `(i j)`-th element is the trace of
`b i * b j`.
## Main definition
* `Algebra.discr A b` : the discriminant of `b : ι → B`.
## Main results
* `Algebra.discr_zero_of_not_linearIndependent` : if `b` is not linear independent, then
`Algebra.discr A b = 0`.
* `Algebra.discr_of_matrix_vecMul` and `Algebra.discr_of_matrix_mulVec` : formulas relating
`Algebra.discr A ι b` with `Algebra.discr A (b ᵥ* P.map (algebraMap A B))` and
`Algebra.discr A (P.map (algebraMap A B) *ᵥ b)`.
* `Algebra.discr_not_zero_of_basis` : over a field, if `b` is a basis, then
`Algebra.discr K b ≠ 0`.
* `Algebra.discr_eq_det_embeddingsMatrixReindex_pow_two` : if `L/K` is a field extension and
`b : ι → L`, then `discr K b` is the square of the determinant of the matrix whose `(i, j)`
coefficient is `σⱼ (b i)`, where `σⱼ : L →ₐ[K] E` is the embedding in an algebraically closed
field `E` corresponding to `j : ι` via a bijection `e : ι ≃ (L →ₐ[K] E)`.
* `Algebra.discr_powerBasis_eq_prod` : the discriminant of a power basis.
* `Algebra.discr_isIntegral` : if `K` and `L` are fields and `IsScalarTower R K L`, if
`b : ι → L` satisfies `∀ i, IsIntegral R (b i)`, then `IsIntegral R (discr K b)`.
* `Algebra.discr_mul_isIntegral_mem_adjoin` : let `K` be the fraction field of an integrally
closed domain `R` and let `L` be a finite separable extension of `K`. Let `B : PowerBasis K L`
be such that `IsIntegral R B.gen`. Then for all, `z : L` we have
`(discr K B.basis) • z ∈ adjoin R ({B.gen} : Set L)`.
## Implementation details
Our definition works for any `A`-algebra `B`, but note that if `B` is not free as an `A`-module,
then `trace A B = 0` by definition, so `discr A b = 0` for any `b`.
-/
universe u v w z
open scoped Matrix
open Matrix FiniteDimensional Fintype Polynomial Finset IntermediateField
namespace Algebra
variable (A : Type u) {B : Type v} (C : Type z) {ι : Type w} [DecidableEq ι]
variable [CommRing A] [CommRing B] [Algebra A B] [CommRing C] [Algebra A C]
section Discr
/-- Given an `A`-algebra `B` and `b`, an `ι`-indexed family of elements of `B`, we define
`discr A ι b` as the determinant of `traceMatrix A ι b`. -/
-- Porting note: using `[DecidableEq ι]` instead of `by classical...` did not work in
-- mathlib3.
noncomputable def discr (A : Type u) {B : Type v} [CommRing A] [CommRing B] [Algebra A B]
[Fintype ι] (b : ι → B) := (traceMatrix A b).det
#align algebra.discr Algebra.discr
theorem discr_def [Fintype ι] (b : ι → B) : discr A b = (traceMatrix A b).det := rfl
variable {A C} in
/-- Mapping a family of vectors along an `AlgEquiv` preserves the discriminant. -/
theorem discr_eq_discr_of_algEquiv [Fintype ι] (b : ι → B) (f : B ≃ₐ[A] C) :
Algebra.discr A b = Algebra.discr A (f ∘ b) := by
rw [discr_def]; congr; ext
simp_rw [traceMatrix_apply, traceForm_apply, Function.comp, ← map_mul f, trace_eq_of_algEquiv]
#align algebra.discr_def Algebra.discr_def
variable {ι' : Type*} [Fintype ι'] [Fintype ι] [DecidableEq ι']
section Basic
@[simp]
theorem discr_reindex (b : Basis ι A B) (f : ι ≃ ι') : discr A (b ∘ ⇑f.symm) = discr A b := by
classical rw [← Basis.coe_reindex, discr_def, traceMatrix_reindex, det_reindex_self, ← discr_def]
#align algebra.discr_reindex Algebra.discr_reindex
/-- If `b` is not linear independent, then `Algebra.discr A b = 0`. -/
theorem discr_zero_of_not_linearIndependent [IsDomain A] {b : ι → B}
(hli : ¬LinearIndependent A b) : discr A b = 0 := by
classical
obtain ⟨g, hg, i, hi⟩ := Fintype.not_linearIndependent_iff.1 hli
have : (traceMatrix A b) *ᵥ g = 0 := by
ext i
have : ∀ j, (trace A B) (b i * b j) * g j = (trace A B) (g j • b j * b i) := by
intro j;
simp [mul_comm]
simp only [mulVec, dotProduct, traceMatrix_apply, Pi.zero_apply, traceForm_apply, fun j =>
this j, ← map_sum, ← sum_mul, hg, zero_mul, LinearMap.map_zero]
by_contra h
rw [discr_def] at h
simp [Matrix.eq_zero_of_mulVec_eq_zero h this] at hi
#align algebra.discr_zero_of_not_linear_independent Algebra.discr_zero_of_not_linearIndependent
variable {A}
/-- Relation between `Algebra.discr A ι b` and
`Algebra.discr A (b ᵥ* P.map (algebraMap A B))`. -/
theorem discr_of_matrix_vecMul (b : ι → B) (P : Matrix ι ι A) :
discr A (b ᵥ* P.map (algebraMap A B)) = P.det ^ 2 * discr A b := by
rw [discr_def, traceMatrix_of_matrix_vecMul, det_mul, det_mul, det_transpose, mul_comm, ←
mul_assoc, discr_def, pow_two]
#align algebra.discr_of_matrix_vec_mul Algebra.discr_of_matrix_vecMul
/-- Relation between `Algebra.discr A ι b` and
`Algebra.discr A ((P.map (algebraMap A B)) *ᵥ b)`. -/
theorem discr_of_matrix_mulVec (b : ι → B) (P : Matrix ι ι A) :
discr A (P.map (algebraMap A B) *ᵥ b) = P.det ^ 2 * discr A b := by
rw [discr_def, traceMatrix_of_matrix_mulVec, det_mul, det_mul, det_transpose, mul_comm, ←
mul_assoc, discr_def, pow_two]
#align algebra.discr_of_matrix_mul_vec Algebra.discr_of_matrix_mulVec
end Basic
section Field
variable (K : Type u) {L : Type v} (E : Type z) [Field K] [Field L] [Field E]
variable [Algebra K L] [Algebra K E]
variable [Module.Finite K L] [IsAlgClosed E]
/-- If `b` is a basis of a finite separable field extension `L/K`, then `Algebra.discr K b ≠ 0`. -/
| Mathlib/RingTheory/Discriminant.lean | 136 | 139 | theorem discr_not_zero_of_basis [IsSeparable K L] (b : Basis ι K L) :
discr K b ≠ 0 := by |
rw [discr_def, traceMatrix_of_basis, ← LinearMap.BilinForm.nondegenerate_iff_det_ne_zero]
exact traceForm_nondegenerate _ _
|
/-
Copyright (c) 2018 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Kenny Lau, Scott Morrison, Alex Keizer
-/
import Mathlib.Data.List.OfFn
import Mathlib.Data.List.Range
#align_import data.list.fin_range from "leanprover-community/mathlib"@"9003f28797c0664a49e4179487267c494477d853"
/-!
# Lists of elements of `Fin n`
This file develops some results on `finRange n`.
-/
universe u
namespace List
variable {α : Type u}
@[simp]
theorem map_coe_finRange (n : ℕ) : ((finRange n) : List (Fin n)).map (Fin.val) = List.range n := by
simp_rw [finRange, map_pmap, pmap_eq_map]
exact List.map_id _
#align list.map_coe_fin_range List.map_coe_finRange
theorem finRange_succ_eq_map (n : ℕ) : finRange n.succ = 0 :: (finRange n).map Fin.succ := by
apply map_injective_iff.mpr Fin.val_injective
rw [map_cons, map_coe_finRange, range_succ_eq_map, Fin.val_zero, ← map_coe_finRange, map_map,
map_map]
simp only [Function.comp, Fin.val_succ]
#align list.fin_range_succ_eq_map List.finRange_succ_eq_map
theorem finRange_succ (n : ℕ) :
finRange n.succ = (finRange n |>.map Fin.castSucc |>.concat (.last _)) := by
apply map_injective_iff.mpr Fin.val_injective
simp [range_succ, Function.comp_def]
-- Porting note: `map_nth_le` moved to `List.finRange_map_get` in Data.List.Range
theorem ofFn_eq_pmap {n} {f : Fin n → α} :
ofFn f = pmap (fun i hi => f ⟨i, hi⟩) (range n) fun _ => mem_range.1 := by
rw [pmap_eq_map_attach]
exact ext_get (by simp) fun i hi1 hi2 => by simp [get_ofFn f ⟨i, hi1⟩]
#align list.of_fn_eq_pmap List.ofFn_eq_pmap
theorem ofFn_id (n) : ofFn id = finRange n :=
ofFn_eq_pmap
#align list.of_fn_id List.ofFn_id
| Mathlib/Data/List/FinRange.lean | 54 | 55 | theorem ofFn_eq_map {n} {f : Fin n → α} : ofFn f = (finRange n).map f := by |
rw [← ofFn_id, map_ofFn, Function.comp_id]
|
/-
Copyright (c) 2020 Thomas Browning, Patrick Lutz. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Thomas Browning, Patrick Lutz
-/
import Mathlib.Algebra.Algebra.Subalgebra.Directed
import Mathlib.FieldTheory.IntermediateField
import Mathlib.FieldTheory.Separable
import Mathlib.FieldTheory.SplittingField.IsSplittingField
import Mathlib.RingTheory.TensorProduct.Basic
#align_import field_theory.adjoin from "leanprover-community/mathlib"@"df76f43357840485b9d04ed5dee5ab115d420e87"
/-!
# Adjoining Elements to Fields
In this file we introduce the notion of adjoining elements to fields.
This isn't quite the same as adjoining elements to rings.
For example, `Algebra.adjoin K {x}` might not include `x⁻¹`.
## Main results
- `adjoin_adjoin_left`: adjoining S and then T is the same as adjoining `S ∪ T`.
- `bot_eq_top_of_rank_adjoin_eq_one`: if `F⟮x⟯` has dimension `1` over `F` for every `x`
in `E` then `F = E`
## Notation
- `F⟮α⟯`: adjoin a single element `α` to `F` (in scope `IntermediateField`).
-/
set_option autoImplicit true
open FiniteDimensional Polynomial
open scoped Classical Polynomial
namespace IntermediateField
section AdjoinDef
variable (F : Type*) [Field F] {E : Type*} [Field E] [Algebra F E] (S : Set E)
-- Porting note: not adding `neg_mem'` causes an error.
/-- `adjoin F S` extends a field `F` by adjoining a set `S ⊆ E`. -/
def adjoin : IntermediateField F E :=
{ Subfield.closure (Set.range (algebraMap F E) ∪ S) with
algebraMap_mem' := fun x => Subfield.subset_closure (Or.inl (Set.mem_range_self x)) }
#align intermediate_field.adjoin IntermediateField.adjoin
variable {S}
theorem mem_adjoin_iff (x : E) :
x ∈ adjoin F S ↔ ∃ r s : MvPolynomial S F,
x = MvPolynomial.aeval Subtype.val r / MvPolynomial.aeval Subtype.val s := by
simp only [adjoin, mem_mk, Subring.mem_toSubsemiring, Subfield.mem_toSubring,
Subfield.mem_closure_iff, ← Algebra.adjoin_eq_ring_closure, Subalgebra.mem_toSubring,
Algebra.adjoin_eq_range, AlgHom.mem_range, exists_exists_eq_and]
tauto
theorem mem_adjoin_simple_iff {α : E} (x : E) :
x ∈ adjoin F {α} ↔ ∃ r s : F[X], x = aeval α r / aeval α s := by
simp only [adjoin, mem_mk, Subring.mem_toSubsemiring, Subfield.mem_toSubring,
Subfield.mem_closure_iff, ← Algebra.adjoin_eq_ring_closure, Subalgebra.mem_toSubring,
Algebra.adjoin_singleton_eq_range_aeval, AlgHom.mem_range, exists_exists_eq_and]
tauto
end AdjoinDef
section Lattice
variable {F : Type*} [Field F] {E : Type*} [Field E] [Algebra F E]
@[simp]
theorem adjoin_le_iff {S : Set E} {T : IntermediateField F E} : adjoin F S ≤ T ↔ S ≤ T :=
⟨fun H => le_trans (le_trans Set.subset_union_right Subfield.subset_closure) H, fun H =>
(@Subfield.closure_le E _ (Set.range (algebraMap F E) ∪ S) T.toSubfield).mpr
(Set.union_subset (IntermediateField.set_range_subset T) H)⟩
#align intermediate_field.adjoin_le_iff IntermediateField.adjoin_le_iff
theorem gc : GaloisConnection (adjoin F : Set E → IntermediateField F E)
(fun (x : IntermediateField F E) => (x : Set E)) := fun _ _ =>
adjoin_le_iff
#align intermediate_field.gc IntermediateField.gc
/-- Galois insertion between `adjoin` and `coe`. -/
def gi : GaloisInsertion (adjoin F : Set E → IntermediateField F E)
(fun (x : IntermediateField F E) => (x : Set E)) where
choice s hs := (adjoin F s).copy s <| le_antisymm (gc.le_u_l s) hs
gc := IntermediateField.gc
le_l_u S := (IntermediateField.gc (S : Set E) (adjoin F S)).1 <| le_rfl
choice_eq _ _ := copy_eq _ _ _
#align intermediate_field.gi IntermediateField.gi
instance : CompleteLattice (IntermediateField F E) where
__ := GaloisInsertion.liftCompleteLattice IntermediateField.gi
bot :=
{ toSubalgebra := ⊥
inv_mem' := by rintro x ⟨r, rfl⟩; exact ⟨r⁻¹, map_inv₀ _ _⟩ }
bot_le x := (bot_le : ⊥ ≤ x.toSubalgebra)
instance : Inhabited (IntermediateField F E) :=
⟨⊤⟩
instance : Unique (IntermediateField F F) :=
{ inferInstanceAs (Inhabited (IntermediateField F F)) with
uniq := fun _ ↦ toSubalgebra_injective <| Subsingleton.elim _ _ }
theorem coe_bot : ↑(⊥ : IntermediateField F E) = Set.range (algebraMap F E) := rfl
#align intermediate_field.coe_bot IntermediateField.coe_bot
theorem mem_bot {x : E} : x ∈ (⊥ : IntermediateField F E) ↔ x ∈ Set.range (algebraMap F E) :=
Iff.rfl
#align intermediate_field.mem_bot IntermediateField.mem_bot
@[simp]
theorem bot_toSubalgebra : (⊥ : IntermediateField F E).toSubalgebra = ⊥ := rfl
#align intermediate_field.bot_to_subalgebra IntermediateField.bot_toSubalgebra
@[simp]
theorem coe_top : ↑(⊤ : IntermediateField F E) = (Set.univ : Set E) :=
rfl
#align intermediate_field.coe_top IntermediateField.coe_top
@[simp]
theorem mem_top {x : E} : x ∈ (⊤ : IntermediateField F E) :=
trivial
#align intermediate_field.mem_top IntermediateField.mem_top
@[simp]
theorem top_toSubalgebra : (⊤ : IntermediateField F E).toSubalgebra = ⊤ :=
rfl
#align intermediate_field.top_to_subalgebra IntermediateField.top_toSubalgebra
@[simp]
theorem top_toSubfield : (⊤ : IntermediateField F E).toSubfield = ⊤ :=
rfl
#align intermediate_field.top_to_subfield IntermediateField.top_toSubfield
@[simp, norm_cast]
theorem coe_inf (S T : IntermediateField F E) : (↑(S ⊓ T) : Set E) = (S : Set E) ∩ T :=
rfl
#align intermediate_field.coe_inf IntermediateField.coe_inf
@[simp]
theorem mem_inf {S T : IntermediateField F E} {x : E} : x ∈ S ⊓ T ↔ x ∈ S ∧ x ∈ T :=
Iff.rfl
#align intermediate_field.mem_inf IntermediateField.mem_inf
@[simp]
theorem inf_toSubalgebra (S T : IntermediateField F E) :
(S ⊓ T).toSubalgebra = S.toSubalgebra ⊓ T.toSubalgebra :=
rfl
#align intermediate_field.inf_to_subalgebra IntermediateField.inf_toSubalgebra
@[simp]
theorem inf_toSubfield (S T : IntermediateField F E) :
(S ⊓ T).toSubfield = S.toSubfield ⊓ T.toSubfield :=
rfl
#align intermediate_field.inf_to_subfield IntermediateField.inf_toSubfield
@[simp, norm_cast]
theorem coe_sInf (S : Set (IntermediateField F E)) : (↑(sInf S) : Set E) =
sInf ((fun (x : IntermediateField F E) => (x : Set E)) '' S) :=
rfl
#align intermediate_field.coe_Inf IntermediateField.coe_sInf
@[simp]
theorem sInf_toSubalgebra (S : Set (IntermediateField F E)) :
(sInf S).toSubalgebra = sInf (toSubalgebra '' S) :=
SetLike.coe_injective <| by simp [Set.sUnion_image]
#align intermediate_field.Inf_to_subalgebra IntermediateField.sInf_toSubalgebra
@[simp]
theorem sInf_toSubfield (S : Set (IntermediateField F E)) :
(sInf S).toSubfield = sInf (toSubfield '' S) :=
SetLike.coe_injective <| by simp [Set.sUnion_image]
#align intermediate_field.Inf_to_subfield IntermediateField.sInf_toSubfield
@[simp, norm_cast]
theorem coe_iInf {ι : Sort*} (S : ι → IntermediateField F E) : (↑(iInf S) : Set E) = ⋂ i, S i := by
simp [iInf]
#align intermediate_field.coe_infi IntermediateField.coe_iInf
@[simp]
theorem iInf_toSubalgebra {ι : Sort*} (S : ι → IntermediateField F E) :
(iInf S).toSubalgebra = ⨅ i, (S i).toSubalgebra :=
SetLike.coe_injective <| by simp [iInf]
#align intermediate_field.infi_to_subalgebra IntermediateField.iInf_toSubalgebra
@[simp]
theorem iInf_toSubfield {ι : Sort*} (S : ι → IntermediateField F E) :
(iInf S).toSubfield = ⨅ i, (S i).toSubfield :=
SetLike.coe_injective <| by simp [iInf]
#align intermediate_field.infi_to_subfield IntermediateField.iInf_toSubfield
/-- Construct an algebra isomorphism from an equality of intermediate fields -/
@[simps! apply]
def equivOfEq {S T : IntermediateField F E} (h : S = T) : S ≃ₐ[F] T :=
Subalgebra.equivOfEq _ _ (congr_arg toSubalgebra h)
#align intermediate_field.equiv_of_eq IntermediateField.equivOfEq
@[simp]
theorem equivOfEq_symm {S T : IntermediateField F E} (h : S = T) :
(equivOfEq h).symm = equivOfEq h.symm :=
rfl
#align intermediate_field.equiv_of_eq_symm IntermediateField.equivOfEq_symm
@[simp]
theorem equivOfEq_rfl (S : IntermediateField F E) : equivOfEq (rfl : S = S) = AlgEquiv.refl := by
ext; rfl
#align intermediate_field.equiv_of_eq_rfl IntermediateField.equivOfEq_rfl
@[simp]
theorem equivOfEq_trans {S T U : IntermediateField F E} (hST : S = T) (hTU : T = U) :
(equivOfEq hST).trans (equivOfEq hTU) = equivOfEq (hST.trans hTU) :=
rfl
#align intermediate_field.equiv_of_eq_trans IntermediateField.equivOfEq_trans
variable (F E)
/-- The bottom intermediate_field is isomorphic to the field. -/
noncomputable def botEquiv : (⊥ : IntermediateField F E) ≃ₐ[F] F :=
(Subalgebra.equivOfEq _ _ bot_toSubalgebra).trans (Algebra.botEquiv F E)
#align intermediate_field.bot_equiv IntermediateField.botEquiv
variable {F E}
-- Porting note: this was tagged `simp`.
theorem botEquiv_def (x : F) : botEquiv F E (algebraMap F (⊥ : IntermediateField F E) x) = x := by
simp
#align intermediate_field.bot_equiv_def IntermediateField.botEquiv_def
@[simp]
theorem botEquiv_symm (x : F) : (botEquiv F E).symm x = algebraMap F _ x :=
rfl
#align intermediate_field.bot_equiv_symm IntermediateField.botEquiv_symm
noncomputable instance algebraOverBot : Algebra (⊥ : IntermediateField F E) F :=
(IntermediateField.botEquiv F E).toAlgHom.toRingHom.toAlgebra
#align intermediate_field.algebra_over_bot IntermediateField.algebraOverBot
theorem coe_algebraMap_over_bot :
(algebraMap (⊥ : IntermediateField F E) F : (⊥ : IntermediateField F E) → F) =
IntermediateField.botEquiv F E :=
rfl
#align intermediate_field.coe_algebra_map_over_bot IntermediateField.coe_algebraMap_over_bot
instance isScalarTower_over_bot : IsScalarTower (⊥ : IntermediateField F E) F E :=
IsScalarTower.of_algebraMap_eq
(by
intro x
obtain ⟨y, rfl⟩ := (botEquiv F E).symm.surjective x
rw [coe_algebraMap_over_bot, (botEquiv F E).apply_symm_apply, botEquiv_symm,
IsScalarTower.algebraMap_apply F (⊥ : IntermediateField F E) E])
#align intermediate_field.is_scalar_tower_over_bot IntermediateField.isScalarTower_over_bot
/-- The top `IntermediateField` is isomorphic to the field.
This is the intermediate field version of `Subalgebra.topEquiv`. -/
@[simps!]
def topEquiv : (⊤ : IntermediateField F E) ≃ₐ[F] E :=
(Subalgebra.equivOfEq _ _ top_toSubalgebra).trans Subalgebra.topEquiv
#align intermediate_field.top_equiv IntermediateField.topEquiv
-- Porting note: this theorem is now generated by the `@[simps!]` above.
#align intermediate_field.top_equiv_symm_apply_coe IntermediateField.topEquiv_symm_apply_coe
@[simp]
theorem restrictScalars_bot_eq_self (K : IntermediateField F E) :
(⊥ : IntermediateField K E).restrictScalars _ = K :=
SetLike.coe_injective Subtype.range_coe
#align intermediate_field.restrict_scalars_bot_eq_self IntermediateField.restrictScalars_bot_eq_self
@[simp]
theorem restrictScalars_top {K : Type*} [Field K] [Algebra K E] [Algebra K F]
[IsScalarTower K F E] : (⊤ : IntermediateField F E).restrictScalars K = ⊤ :=
rfl
#align intermediate_field.restrict_scalars_top IntermediateField.restrictScalars_top
variable {K : Type*} [Field K] [Algebra F K]
@[simp]
theorem map_bot (f : E →ₐ[F] K) :
IntermediateField.map f ⊥ = ⊥ :=
toSubalgebra_injective <| Algebra.map_bot _
theorem map_sup (s t : IntermediateField F E) (f : E →ₐ[F] K) : (s ⊔ t).map f = s.map f ⊔ t.map f :=
(gc_map_comap f).l_sup
theorem map_iSup {ι : Sort*} (f : E →ₐ[F] K) (s : ι → IntermediateField F E) :
(iSup s).map f = ⨆ i, (s i).map f :=
(gc_map_comap f).l_iSup
theorem _root_.AlgHom.fieldRange_eq_map (f : E →ₐ[F] K) :
f.fieldRange = IntermediateField.map f ⊤ :=
SetLike.ext' Set.image_univ.symm
#align alg_hom.field_range_eq_map AlgHom.fieldRange_eq_map
theorem _root_.AlgHom.map_fieldRange {L : Type*} [Field L] [Algebra F L]
(f : E →ₐ[F] K) (g : K →ₐ[F] L) : f.fieldRange.map g = (g.comp f).fieldRange :=
SetLike.ext' (Set.range_comp g f).symm
#align alg_hom.map_field_range AlgHom.map_fieldRange
theorem _root_.AlgHom.fieldRange_eq_top {f : E →ₐ[F] K} :
f.fieldRange = ⊤ ↔ Function.Surjective f :=
SetLike.ext'_iff.trans Set.range_iff_surjective
#align alg_hom.field_range_eq_top AlgHom.fieldRange_eq_top
@[simp]
theorem _root_.AlgEquiv.fieldRange_eq_top (f : E ≃ₐ[F] K) :
(f : E →ₐ[F] K).fieldRange = ⊤ :=
AlgHom.fieldRange_eq_top.mpr f.surjective
#align alg_equiv.field_range_eq_top AlgEquiv.fieldRange_eq_top
end Lattice
section equivMap
variable {F : Type*} [Field F] {E : Type*} [Field E] [Algebra F E]
{K : Type*} [Field K] [Algebra F K] (L : IntermediateField F E) (f : E →ₐ[F] K)
theorem fieldRange_comp_val : (f.comp L.val).fieldRange = L.map f := toSubalgebra_injective <| by
rw [toSubalgebra_map, AlgHom.fieldRange_toSubalgebra, AlgHom.range_comp, range_val]
/-- An intermediate field is isomorphic to its image under an `AlgHom`
(which is automatically injective) -/
noncomputable def equivMap : L ≃ₐ[F] L.map f :=
(AlgEquiv.ofInjective _ (f.comp L.val).injective).trans (equivOfEq (fieldRange_comp_val L f))
@[simp]
theorem coe_equivMap_apply (x : L) : ↑(equivMap L f x) = f x := rfl
end equivMap
section AdjoinDef
variable (F : Type*) [Field F] {E : Type*} [Field E] [Algebra F E] (S : Set E)
theorem adjoin_eq_range_algebraMap_adjoin :
(adjoin F S : Set E) = Set.range (algebraMap (adjoin F S) E) :=
Subtype.range_coe.symm
#align intermediate_field.adjoin_eq_range_algebra_map_adjoin IntermediateField.adjoin_eq_range_algebraMap_adjoin
theorem adjoin.algebraMap_mem (x : F) : algebraMap F E x ∈ adjoin F S :=
IntermediateField.algebraMap_mem (adjoin F S) x
#align intermediate_field.adjoin.algebra_map_mem IntermediateField.adjoin.algebraMap_mem
theorem adjoin.range_algebraMap_subset : Set.range (algebraMap F E) ⊆ adjoin F S := by
intro x hx
cases' hx with f hf
rw [← hf]
exact adjoin.algebraMap_mem F S f
#align intermediate_field.adjoin.range_algebra_map_subset IntermediateField.adjoin.range_algebraMap_subset
instance adjoin.fieldCoe : CoeTC F (adjoin F S) where
coe x := ⟨algebraMap F E x, adjoin.algebraMap_mem F S x⟩
#align intermediate_field.adjoin.field_coe IntermediateField.adjoin.fieldCoe
theorem subset_adjoin : S ⊆ adjoin F S := fun _ hx => Subfield.subset_closure (Or.inr hx)
#align intermediate_field.subset_adjoin IntermediateField.subset_adjoin
instance adjoin.setCoe : CoeTC S (adjoin F S) where coe x := ⟨x, subset_adjoin F S (Subtype.mem x)⟩
#align intermediate_field.adjoin.set_coe IntermediateField.adjoin.setCoe
@[mono]
theorem adjoin.mono (T : Set E) (h : S ⊆ T) : adjoin F S ≤ adjoin F T :=
GaloisConnection.monotone_l gc h
#align intermediate_field.adjoin.mono IntermediateField.adjoin.mono
theorem adjoin_contains_field_as_subfield (F : Subfield E) : (F : Set E) ⊆ adjoin F S := fun x hx =>
adjoin.algebraMap_mem F S ⟨x, hx⟩
#align intermediate_field.adjoin_contains_field_as_subfield IntermediateField.adjoin_contains_field_as_subfield
theorem subset_adjoin_of_subset_left {F : Subfield E} {T : Set E} (HT : T ⊆ F) : T ⊆ adjoin F S :=
fun x hx => (adjoin F S).algebraMap_mem ⟨x, HT hx⟩
#align intermediate_field.subset_adjoin_of_subset_left IntermediateField.subset_adjoin_of_subset_left
theorem subset_adjoin_of_subset_right {T : Set E} (H : T ⊆ S) : T ⊆ adjoin F S := fun _ hx =>
subset_adjoin F S (H hx)
#align intermediate_field.subset_adjoin_of_subset_right IntermediateField.subset_adjoin_of_subset_right
@[simp]
theorem adjoin_empty (F E : Type*) [Field F] [Field E] [Algebra F E] : adjoin F (∅ : Set E) = ⊥ :=
eq_bot_iff.mpr (adjoin_le_iff.mpr (Set.empty_subset _))
#align intermediate_field.adjoin_empty IntermediateField.adjoin_empty
@[simp]
theorem adjoin_univ (F E : Type*) [Field F] [Field E] [Algebra F E] :
adjoin F (Set.univ : Set E) = ⊤ :=
eq_top_iff.mpr <| subset_adjoin _ _
#align intermediate_field.adjoin_univ IntermediateField.adjoin_univ
/-- If `K` is a field with `F ⊆ K` and `S ⊆ K` then `adjoin F S ≤ K`. -/
theorem adjoin_le_subfield {K : Subfield E} (HF : Set.range (algebraMap F E) ⊆ K) (HS : S ⊆ K) :
(adjoin F S).toSubfield ≤ K := by
apply Subfield.closure_le.mpr
rw [Set.union_subset_iff]
exact ⟨HF, HS⟩
#align intermediate_field.adjoin_le_subfield IntermediateField.adjoin_le_subfield
theorem adjoin_subset_adjoin_iff {F' : Type*} [Field F'] [Algebra F' E] {S S' : Set E} :
(adjoin F S : Set E) ⊆ adjoin F' S' ↔
Set.range (algebraMap F E) ⊆ adjoin F' S' ∧ S ⊆ adjoin F' S' :=
⟨fun h => ⟨(adjoin.range_algebraMap_subset _ _).trans h,
(subset_adjoin _ _).trans h⟩, fun ⟨hF, hS⟩ =>
(Subfield.closure_le (t := (adjoin F' S').toSubfield)).mpr (Set.union_subset hF hS)⟩
#align intermediate_field.adjoin_subset_adjoin_iff IntermediateField.adjoin_subset_adjoin_iff
/-- `F[S][T] = F[S ∪ T]` -/
theorem adjoin_adjoin_left (T : Set E) :
(adjoin (adjoin F S) T).restrictScalars _ = adjoin F (S ∪ T) := by
rw [SetLike.ext'_iff]
change (↑(adjoin (adjoin F S) T) : Set E) = _
apply Set.eq_of_subset_of_subset <;> rw [adjoin_subset_adjoin_iff] <;> constructor
· rintro _ ⟨⟨x, hx⟩, rfl⟩; exact adjoin.mono _ _ _ Set.subset_union_left hx
· exact subset_adjoin_of_subset_right _ _ Set.subset_union_right
-- Porting note: orginal proof times out
· rintro x ⟨f, rfl⟩
refine Subfield.subset_closure ?_
left
exact ⟨f, rfl⟩
-- Porting note: orginal proof times out
· refine Set.union_subset (fun x hx => Subfield.subset_closure ?_)
(fun x hx => Subfield.subset_closure ?_)
· left
refine ⟨⟨x, Subfield.subset_closure ?_⟩, rfl⟩
right
exact hx
· right
exact hx
#align intermediate_field.adjoin_adjoin_left IntermediateField.adjoin_adjoin_left
@[simp]
theorem adjoin_insert_adjoin (x : E) :
adjoin F (insert x (adjoin F S : Set E)) = adjoin F (insert x S) :=
le_antisymm
(adjoin_le_iff.mpr
(Set.insert_subset_iff.mpr
⟨subset_adjoin _ _ (Set.mem_insert _ _),
adjoin_le_iff.mpr (subset_adjoin_of_subset_right _ _ (Set.subset_insert _ _))⟩))
(adjoin.mono _ _ _ (Set.insert_subset_insert (subset_adjoin _ _)))
#align intermediate_field.adjoin_insert_adjoin IntermediateField.adjoin_insert_adjoin
/-- `F[S][T] = F[T][S]` -/
theorem adjoin_adjoin_comm (T : Set E) :
(adjoin (adjoin F S) T).restrictScalars F = (adjoin (adjoin F T) S).restrictScalars F := by
rw [adjoin_adjoin_left, adjoin_adjoin_left, Set.union_comm]
#align intermediate_field.adjoin_adjoin_comm IntermediateField.adjoin_adjoin_comm
theorem adjoin_map {E' : Type*} [Field E'] [Algebra F E'] (f : E →ₐ[F] E') :
(adjoin F S).map f = adjoin F (f '' S) := by
ext x
show
x ∈ (Subfield.closure (Set.range (algebraMap F E) ∪ S)).map (f : E →+* E') ↔
x ∈ Subfield.closure (Set.range (algebraMap F E') ∪ f '' S)
rw [RingHom.map_field_closure, Set.image_union, ← Set.range_comp, ← RingHom.coe_comp,
f.comp_algebraMap]
rfl
#align intermediate_field.adjoin_map IntermediateField.adjoin_map
@[simp]
theorem lift_adjoin (K : IntermediateField F E) (S : Set K) :
lift (adjoin F S) = adjoin F (Subtype.val '' S) :=
adjoin_map _ _ _
theorem lift_adjoin_simple (K : IntermediateField F E) (α : K) :
lift (adjoin F {α}) = adjoin F {α.1} := by
simp only [lift_adjoin, Set.image_singleton]
@[simp]
theorem lift_bot (K : IntermediateField F E) :
lift (F := K) ⊥ = ⊥ := map_bot _
@[simp]
theorem lift_top (K : IntermediateField F E) :
lift (F := K) ⊤ = K := by rw [lift, ← AlgHom.fieldRange_eq_map, fieldRange_val]
@[simp]
theorem adjoin_self (K : IntermediateField F E) :
adjoin F K = K := le_antisymm (adjoin_le_iff.2 fun _ ↦ id) (subset_adjoin F _)
theorem restrictScalars_adjoin (K : IntermediateField F E) (S : Set E) :
restrictScalars F (adjoin K S) = adjoin F (K ∪ S) := by
rw [← adjoin_self _ K, adjoin_adjoin_left, adjoin_self _ K]
variable {F} in
theorem extendScalars_adjoin {K : IntermediateField F E} {S : Set E} (h : K ≤ adjoin F S) :
extendScalars h = adjoin K S := restrictScalars_injective F <| by
rw [extendScalars_restrictScalars, restrictScalars_adjoin]
exact le_antisymm (adjoin.mono F S _ Set.subset_union_right) <| adjoin_le_iff.2 <|
Set.union_subset h (subset_adjoin F S)
variable {F} in
/-- If `E / L / F` and `E / L' / F` are two field 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 intermediate fields of `E / F`. -/
theorem restrictScalars_adjoin_of_algEquiv
{L L' : Type*} [Field L] [Field L']
[Algebra F L] [Algebra L E] [Algebra F L'] [Algebra L' E]
[IsScalarTower F L E] [IsScalarTower F L' E] (i : L ≃ₐ[F] L')
(hi : algebraMap L E = (algebraMap L' E) ∘ i) (S : Set E) :
(adjoin L S).restrictScalars F = (adjoin L' S).restrictScalars F := by
apply_fun toSubfield using (fun K K' h ↦ by
ext x; change x ∈ K.toSubfield ↔ x ∈ K'.toSubfield; rw [h])
change Subfield.closure _ = Subfield.closure _
congr
ext x
exact ⟨fun ⟨y, h⟩ ↦ ⟨i y, by rw [← h, hi]; rfl⟩,
fun ⟨y, h⟩ ↦ ⟨i.symm y, by rw [← h, hi, Function.comp_apply, AlgEquiv.apply_symm_apply]⟩⟩
theorem algebra_adjoin_le_adjoin : Algebra.adjoin F S ≤ (adjoin F S).toSubalgebra :=
Algebra.adjoin_le (subset_adjoin _ _)
#align intermediate_field.algebra_adjoin_le_adjoin IntermediateField.algebra_adjoin_le_adjoin
theorem adjoin_eq_algebra_adjoin (inv_mem : ∀ x ∈ Algebra.adjoin F S, x⁻¹ ∈ Algebra.adjoin F S) :
(adjoin F S).toSubalgebra = Algebra.adjoin F S :=
le_antisymm
(show adjoin F S ≤
{ Algebra.adjoin F S with
inv_mem' := inv_mem }
from adjoin_le_iff.mpr Algebra.subset_adjoin)
(algebra_adjoin_le_adjoin _ _)
#align intermediate_field.adjoin_eq_algebra_adjoin IntermediateField.adjoin_eq_algebra_adjoin
theorem eq_adjoin_of_eq_algebra_adjoin (K : IntermediateField F E)
(h : K.toSubalgebra = Algebra.adjoin F S) : K = adjoin F S := by
apply toSubalgebra_injective
rw [h]
refine (adjoin_eq_algebra_adjoin F _ ?_).symm
intro x
convert K.inv_mem (x := x) <;> rw [← h] <;> rfl
#align intermediate_field.eq_adjoin_of_eq_algebra_adjoin IntermediateField.eq_adjoin_of_eq_algebra_adjoin
theorem adjoin_eq_top_of_algebra (hS : Algebra.adjoin F S = ⊤) : adjoin F S = ⊤ :=
top_le_iff.mp (hS.symm.trans_le <| algebra_adjoin_le_adjoin F S)
@[elab_as_elim]
theorem adjoin_induction {s : Set E} {p : E → Prop} {x} (h : x ∈ adjoin F s) (mem : ∀ x ∈ s, p x)
(algebraMap : ∀ x, p (algebraMap F E x)) (add : ∀ x y, p x → p y → p (x + y))
(neg : ∀ x, p x → p (-x)) (inv : ∀ x, p x → p x⁻¹) (mul : ∀ x y, p x → p y → p (x * y)) :
p x :=
Subfield.closure_induction h
(fun x hx => Or.casesOn hx (fun ⟨x, hx⟩ => hx ▸ algebraMap x) (mem x))
((_root_.algebraMap F E).map_one ▸ algebraMap 1) add neg inv mul
#align intermediate_field.adjoin_induction IntermediateField.adjoin_induction
/- Porting note (kmill): this notation is replacing the typeclass-based one I had previously
written, and it gives true `{x₁, x₂, ..., xₙ}` sets in the `adjoin` term. -/
open Lean in
/-- Supporting function for the `F⟮x₁,x₂,...,xₙ⟯` adjunction notation. -/
private partial def mkInsertTerm [Monad m] [MonadQuotation m] (xs : TSyntaxArray `term) : m Term :=
run 0
where
run (i : Nat) : m Term := do
if i + 1 == xs.size then
``(singleton $(xs[i]!))
else if i < xs.size then
``(insert $(xs[i]!) $(← run (i + 1)))
else
``(EmptyCollection.emptyCollection)
/-- If `x₁ x₂ ... xₙ : E` then `F⟮x₁,x₂,...,xₙ⟯` is the `IntermediateField F E`
generated by these elements. -/
scoped macro:max K:term "⟮" xs:term,* "⟯" : term => do ``(adjoin $K $(← mkInsertTerm xs.getElems))
open Lean PrettyPrinter.Delaborator SubExpr in
@[delab app.IntermediateField.adjoin]
partial def delabAdjoinNotation : Delab := whenPPOption getPPNotation do
let e ← getExpr
guard <| e.isAppOfArity ``adjoin 6
let F ← withNaryArg 0 delab
let xs ← withNaryArg 5 delabInsertArray
`($F⟮$(xs.toArray),*⟯)
where
delabInsertArray : DelabM (List Term) := do
let e ← getExpr
if e.isAppOfArity ``EmptyCollection.emptyCollection 2 then
return []
else if e.isAppOfArity ``singleton 4 then
let x ← withNaryArg 3 delab
return [x]
else if e.isAppOfArity ``insert 5 then
let x ← withNaryArg 3 delab
let xs ← withNaryArg 4 delabInsertArray
return x :: xs
else failure
section AdjoinSimple
variable (α : E)
-- Porting note: in all the theorems below, mathport translated `F⟮α⟯` into `F⟮⟯`.
theorem mem_adjoin_simple_self : α ∈ F⟮α⟯ :=
subset_adjoin F {α} (Set.mem_singleton α)
#align intermediate_field.mem_adjoin_simple_self IntermediateField.mem_adjoin_simple_self
/-- generator of `F⟮α⟯` -/
def AdjoinSimple.gen : F⟮α⟯ :=
⟨α, mem_adjoin_simple_self F α⟩
#align intermediate_field.adjoin_simple.gen IntermediateField.AdjoinSimple.gen
@[simp]
theorem AdjoinSimple.coe_gen : (AdjoinSimple.gen F α : E) = α :=
rfl
theorem AdjoinSimple.algebraMap_gen : algebraMap F⟮α⟯ E (AdjoinSimple.gen F α) = α :=
rfl
#align intermediate_field.adjoin_simple.algebra_map_gen IntermediateField.AdjoinSimple.algebraMap_gen
@[simp]
theorem AdjoinSimple.isIntegral_gen : IsIntegral F (AdjoinSimple.gen F α) ↔ IsIntegral F α := by
conv_rhs => rw [← AdjoinSimple.algebraMap_gen F α]
rw [isIntegral_algebraMap_iff (algebraMap F⟮α⟯ E).injective]
#align intermediate_field.adjoin_simple.is_integral_gen IntermediateField.AdjoinSimple.isIntegral_gen
theorem adjoin_simple_adjoin_simple (β : E) : F⟮α⟯⟮β⟯.restrictScalars F = F⟮α, β⟯ :=
adjoin_adjoin_left _ _ _
#align intermediate_field.adjoin_simple_adjoin_simple IntermediateField.adjoin_simple_adjoin_simple
theorem adjoin_simple_comm (β : E) : F⟮α⟯⟮β⟯.restrictScalars F = F⟮β⟯⟮α⟯.restrictScalars F :=
adjoin_adjoin_comm _ _ _
#align intermediate_field.adjoin_simple_comm IntermediateField.adjoin_simple_comm
variable {F} {α}
theorem adjoin_algebraic_toSubalgebra {S : Set E} (hS : ∀ x ∈ S, IsAlgebraic F x) :
(IntermediateField.adjoin F S).toSubalgebra = Algebra.adjoin F S := by
simp only [isAlgebraic_iff_isIntegral] at hS
have : Algebra.IsIntegral F (Algebra.adjoin F S) := by
rwa [← le_integralClosure_iff_isIntegral, Algebra.adjoin_le_iff]
have : IsField (Algebra.adjoin F S) := isField_of_isIntegral_of_isField' (Field.toIsField F)
rw [← ((Algebra.adjoin F S).toIntermediateField' this).eq_adjoin_of_eq_algebra_adjoin F S] <;> rfl
#align intermediate_field.adjoin_algebraic_to_subalgebra IntermediateField.adjoin_algebraic_toSubalgebra
theorem adjoin_simple_toSubalgebra_of_integral (hα : IsIntegral F α) :
F⟮α⟯.toSubalgebra = Algebra.adjoin F {α} := by
apply adjoin_algebraic_toSubalgebra
rintro x (rfl : x = α)
rwa [isAlgebraic_iff_isIntegral]
#align intermediate_field.adjoin_simple_to_subalgebra_of_integral IntermediateField.adjoin_simple_toSubalgebra_of_integral
/-- Characterize `IsSplittingField` with `IntermediateField.adjoin` instead of `Algebra.adjoin`. -/
theorem _root_.isSplittingField_iff_intermediateField {p : F[X]} :
p.IsSplittingField F E ↔ p.Splits (algebraMap F E) ∧ adjoin F (p.rootSet E) = ⊤ := by
rw [← toSubalgebra_injective.eq_iff,
adjoin_algebraic_toSubalgebra fun _ ↦ isAlgebraic_of_mem_rootSet]
exact ⟨fun ⟨spl, adj⟩ ↦ ⟨spl, adj⟩, fun ⟨spl, adj⟩ ↦ ⟨spl, adj⟩⟩
-- Note: p.Splits (algebraMap F E) also works
theorem isSplittingField_iff {p : F[X]} {K : IntermediateField F E} :
p.IsSplittingField F K ↔ p.Splits (algebraMap F K) ∧ K = adjoin F (p.rootSet E) := by
suffices _ → (Algebra.adjoin F (p.rootSet K) = ⊤ ↔ K = adjoin F (p.rootSet E)) by
exact ⟨fun h ↦ ⟨h.1, (this h.1).mp h.2⟩, fun h ↦ ⟨h.1, (this h.1).mpr h.2⟩⟩
rw [← toSubalgebra_injective.eq_iff,
adjoin_algebraic_toSubalgebra fun x ↦ isAlgebraic_of_mem_rootSet]
refine fun hp ↦ (adjoin_rootSet_eq_range hp K.val).symm.trans ?_
rw [← K.range_val, eq_comm]
#align intermediate_field.is_splitting_field_iff IntermediateField.isSplittingField_iff
theorem adjoin_rootSet_isSplittingField {p : F[X]} (hp : p.Splits (algebraMap F E)) :
p.IsSplittingField F (adjoin F (p.rootSet E)) :=
isSplittingField_iff.mpr ⟨splits_of_splits hp fun _ hx ↦ subset_adjoin F (p.rootSet E) hx, rfl⟩
#align intermediate_field.adjoin_root_set_is_splitting_field IntermediateField.adjoin_rootSet_isSplittingField
section Supremum
variable {K L : Type*} [Field K] [Field L] [Algebra K L] (E1 E2 : IntermediateField K L)
theorem le_sup_toSubalgebra : E1.toSubalgebra ⊔ E2.toSubalgebra ≤ (E1 ⊔ E2).toSubalgebra :=
sup_le (show E1 ≤ E1 ⊔ E2 from le_sup_left) (show E2 ≤ E1 ⊔ E2 from le_sup_right)
#align intermediate_field.le_sup_to_subalgebra IntermediateField.le_sup_toSubalgebra
theorem sup_toSubalgebra_of_isAlgebraic_right [Algebra.IsAlgebraic K E2] :
(E1 ⊔ E2).toSubalgebra = E1.toSubalgebra ⊔ E2.toSubalgebra := by
have : (adjoin E1 (E2 : Set L)).toSubalgebra = _ := adjoin_algebraic_toSubalgebra fun x h ↦
IsAlgebraic.tower_top E1 (isAlgebraic_iff.1
(Algebra.IsAlgebraic.isAlgebraic (⟨x, h⟩ : E2)))
apply_fun Subalgebra.restrictScalars K at this
erw [← restrictScalars_toSubalgebra, restrictScalars_adjoin,
Algebra.restrictScalars_adjoin] at this
exact this
theorem sup_toSubalgebra_of_isAlgebraic_left [Algebra.IsAlgebraic K E1] :
(E1 ⊔ E2).toSubalgebra = E1.toSubalgebra ⊔ E2.toSubalgebra := by
have := sup_toSubalgebra_of_isAlgebraic_right E2 E1
rwa [sup_comm (a := E1), sup_comm (a := E1.toSubalgebra)]
/-- The compositum of two intermediate fields is equal to the compositum of them
as subalgebras, if one of them is algebraic over the base field. -/
theorem sup_toSubalgebra_of_isAlgebraic
(halg : Algebra.IsAlgebraic K E1 ∨ Algebra.IsAlgebraic K E2) :
(E1 ⊔ E2).toSubalgebra = E1.toSubalgebra ⊔ E2.toSubalgebra :=
halg.elim (fun _ ↦ sup_toSubalgebra_of_isAlgebraic_left E1 E2)
(fun _ ↦ sup_toSubalgebra_of_isAlgebraic_right E1 E2)
theorem sup_toSubalgebra_of_left [FiniteDimensional K E1] :
(E1 ⊔ E2).toSubalgebra = E1.toSubalgebra ⊔ E2.toSubalgebra :=
sup_toSubalgebra_of_isAlgebraic_left E1 E2
#align intermediate_field.sup_to_subalgebra IntermediateField.sup_toSubalgebra_of_left
@[deprecated (since := "2024-01-19")] alias sup_toSubalgebra := sup_toSubalgebra_of_left
theorem sup_toSubalgebra_of_right [FiniteDimensional K E2] :
(E1 ⊔ E2).toSubalgebra = E1.toSubalgebra ⊔ E2.toSubalgebra :=
sup_toSubalgebra_of_isAlgebraic_right E1 E2
instance finiteDimensional_sup [FiniteDimensional K E1] [FiniteDimensional K E2] :
FiniteDimensional K (E1 ⊔ E2 : IntermediateField K L) := by
let g := Algebra.TensorProduct.productMap E1.val E2.val
suffices g.range = (E1 ⊔ E2).toSubalgebra by
have h : FiniteDimensional K (Subalgebra.toSubmodule g.range) :=
g.toLinearMap.finiteDimensional_range
rwa [this] at h
rw [Algebra.TensorProduct.productMap_range, E1.range_val, E2.range_val, sup_toSubalgebra_of_left]
#align intermediate_field.finite_dimensional_sup IntermediateField.finiteDimensional_sup
variable {ι : Type*} {t : ι → IntermediateField K L}
theorem coe_iSup_of_directed [Nonempty ι] (dir : Directed (· ≤ ·) t) :
↑(iSup t) = ⋃ i, (t i : Set L) :=
let M : IntermediateField K L :=
{ __ := Subalgebra.copy _ _ (Subalgebra.coe_iSup_of_directed dir).symm
inv_mem' := fun _ hx ↦ have ⟨i, hi⟩ := Set.mem_iUnion.mp hx
Set.mem_iUnion.mpr ⟨i, (t i).inv_mem hi⟩ }
have : iSup t = M := le_antisymm
(iSup_le fun i ↦ le_iSup (fun i ↦ (t i : Set L)) i) (Set.iUnion_subset fun _ ↦ le_iSup t _)
this.symm ▸ rfl
| Mathlib/FieldTheory/Adjoin.lean | 732 | 736 | theorem toSubalgebra_iSup_of_directed (dir : Directed (· ≤ ·) t) :
(iSup t).toSubalgebra = ⨆ i, (t i).toSubalgebra := by |
cases isEmpty_or_nonempty ι
· simp_rw [iSup_of_empty, bot_toSubalgebra]
· exact SetLike.ext' ((coe_iSup_of_directed dir).trans (Subalgebra.coe_iSup_of_directed dir).symm)
|
/-
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, Scott Morrison, Jens Wagemaker
-/
import Mathlib.Algebra.MonoidAlgebra.Support
import Mathlib.Algebra.Polynomial.Basic
import Mathlib.Algebra.Regular.Basic
import Mathlib.Data.Nat.Choose.Sum
#align_import data.polynomial.coeff from "leanprover-community/mathlib"@"2651125b48fc5c170ab1111afd0817c903b1fc6c"
/-!
# Theory of univariate polynomials
The theorems include formulas for computing coefficients, such as
`coeff_add`, `coeff_sum`, `coeff_mul`
-/
set_option linter.uppercaseLean3 false
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 _ _ _
#align polynomial.coeff_add Polynomial.coeff_add
set_option linter.deprecated false in
@[simp]
theorem coeff_bit0 (p : R[X]) (n : ℕ) : coeff (bit0 p) n = bit0 (coeff p n) := by simp [bit0]
#align polynomial.coeff_bit0 Polynomial.coeff_bit0
@[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 _ _ _
#align polynomial.coeff_smul Polynomial.coeff_smul
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
simp [hi]
#align polynomial.support_smul Polynomial.support_smul
open scoped Pointwise in
theorem card_support_mul_le : (p * q).support.card ≤ p.support.card * q.support.card := by
calc (p * q).support.card
_ = (p.toFinsupp * q.toFinsupp).support.card := by rw [← support_toFinsupp, toFinsupp_mul]
_ ≤ (p.toFinsupp.support + q.toFinsupp.support).card :=
Finset.card_le_card (AddMonoidAlgebra.support_mul p.toFinsupp q.toFinsupp)
_ ≤ p.support.card * q.support.card := Finset.card_image₂_le ..
/-- `Polynomial.sum` as a linear map. -/
@[simps]
def lsum {R A M : Type*} [Semiring R] [Semiring A] [AddCommMonoid M] [Module R A] [Module R M]
(f : ℕ → A →ₗ[R] M) : A[X] →ₗ[R] M where
toFun p := p.sum (f · ·)
map_add' p q := sum_add_index p q _ (fun n => (f n).map_zero) fun n _ _ => (f n).map_add _ _
map_smul' c p := by
-- Porting note: added `dsimp only`; `beta_reduce` alone is not sufficient
dsimp only
rw [sum_eq_of_subset (f · ·) (fun n => (f n).map_zero) (support_smul c p)]
simp only [sum_def, Finset.smul_sum, coeff_smul, LinearMap.map_smul, RingHom.id_apply]
#align polynomial.lsum Polynomial.lsum
#align polynomial.lsum_apply Polynomial.lsum_apply
variable (R)
/-- The nth coefficient, as a linear map. -/
def lcoeff (n : ℕ) : R[X] →ₗ[R] R where
toFun p := coeff p n
map_add' p q := coeff_add p q n
map_smul' r p := coeff_smul r p n
#align polynomial.lcoeff Polynomial.lcoeff
variable {R}
@[simp]
theorem lcoeff_apply (n : ℕ) (f : R[X]) : lcoeff R n f = coeff f n :=
rfl
#align polynomial.lcoeff_apply Polynomial.lcoeff_apply
@[simp]
theorem finset_sum_coeff {ι : Type*} (s : Finset ι) (f : ι → R[X]) (n : ℕ) :
coeff (∑ b ∈ s, f b) n = ∑ b ∈ s, coeff (f b) n :=
map_sum (lcoeff R n) _ _
#align polynomial.finset_sum_coeff Polynomial.finset_sum_coeff
lemma coeff_list_sum (l : List R[X]) (n : ℕ) :
l.sum.coeff n = (l.map (lcoeff R n)).sum :=
map_list_sum (lcoeff R n) _
lemma coeff_list_sum_map {ι : Type*} (l : List ι) (f : ι → R[X]) (n : ℕ) :
(l.map f).sum.coeff n = (l.map (fun a => (f a).coeff n)).sum := by
simp_rw [coeff_list_sum, List.map_map, Function.comp, lcoeff_apply]
theorem coeff_sum [Semiring S] (n : ℕ) (f : ℕ → R → S[X]) :
coeff (p.sum f) n = p.sum fun a b => coeff (f a b) n := by
rcases p with ⟨⟩
-- porting note (#10745): was `simp [Polynomial.sum, support, coeff]`.
simp [Polynomial.sum, support_ofFinsupp, coeff_ofFinsupp]
#align polynomial.coeff_sum Polynomial.coeff_sum
/-- Decomposes the coefficient of the product `p * q` as a sum
over `antidiagonal`. A version which sums over `range (n + 1)` can be obtained
by using `Finset.Nat.sum_antidiagonal_eq_sum_range_succ`. -/
theorem coeff_mul (p q : R[X]) (n : ℕ) :
coeff (p * q) n = ∑ x ∈ antidiagonal n, coeff p x.1 * coeff q x.2 := by
rcases p with ⟨p⟩; rcases q with ⟨q⟩
simp_rw [← ofFinsupp_mul, coeff]
exact AddMonoidAlgebra.mul_apply_antidiagonal p q n _ Finset.mem_antidiagonal
#align polynomial.coeff_mul Polynomial.coeff_mul
@[simp]
theorem mul_coeff_zero (p q : R[X]) : coeff (p * q) 0 = coeff p 0 * coeff q 0 := by simp [coeff_mul]
#align polynomial.mul_coeff_zero Polynomial.mul_coeff_zero
/-- `constantCoeff p` returns the constant term of the polynomial `p`,
defined as `coeff p 0`. This is a ring homomorphism. -/
@[simps]
def constantCoeff : R[X] →+* R where
toFun p := coeff p 0
map_one' := coeff_one_zero
map_mul' := mul_coeff_zero
map_zero' := coeff_zero 0
map_add' p q := coeff_add p q 0
#align polynomial.constant_coeff Polynomial.constantCoeff
#align polynomial.constant_coeff_apply Polynomial.constantCoeff_apply
theorem isUnit_C {x : R} : IsUnit (C x) ↔ IsUnit x :=
⟨fun h => (congr_arg IsUnit coeff_C_zero).mp (h.map <| @constantCoeff R _), fun h => h.map C⟩
#align polynomial.is_unit_C Polynomial.isUnit_C
theorem coeff_mul_X_zero (p : R[X]) : coeff (p * X) 0 = 0 := by simp
#align polynomial.coeff_mul_X_zero Polynomial.coeff_mul_X_zero
theorem coeff_X_mul_zero (p : R[X]) : coeff (X * p) 0 = 0 := by simp
#align polynomial.coeff_X_mul_zero Polynomial.coeff_X_mul_zero
theorem coeff_C_mul_X_pow (x : R) (k n : ℕ) :
coeff (C x * X ^ k : R[X]) n = if n = k then x else 0 := by
rw [C_mul_X_pow_eq_monomial, coeff_monomial]
congr 1
simp [eq_comm]
#align polynomial.coeff_C_mul_X_pow Polynomial.coeff_C_mul_X_pow
theorem coeff_C_mul_X (x : R) (n : ℕ) : coeff (C x * X : R[X]) n = if n = 1 then x else 0 := by
rw [← pow_one X, coeff_C_mul_X_pow]
#align polynomial.coeff_C_mul_X Polynomial.coeff_C_mul_X
@[simp]
theorem coeff_C_mul (p : R[X]) : coeff (C a * p) n = a * coeff p n := by
rcases p with ⟨p⟩
simp_rw [← monomial_zero_left, ← ofFinsupp_single, ← ofFinsupp_mul, coeff]
exact AddMonoidAlgebra.single_zero_mul_apply p a n
#align polynomial.coeff_C_mul Polynomial.coeff_C_mul
theorem C_mul' (a : R) (f : R[X]) : C a * f = a • f := by
ext
rw [coeff_C_mul, coeff_smul, smul_eq_mul]
#align polynomial.C_mul' Polynomial.C_mul'
@[simp]
theorem coeff_mul_C (p : R[X]) (n : ℕ) (a : R) : coeff (p * C a) n = coeff p n * a := by
rcases p with ⟨p⟩
simp_rw [← monomial_zero_left, ← ofFinsupp_single, ← ofFinsupp_mul, coeff]
exact AddMonoidAlgebra.mul_single_zero_apply p a n
#align polynomial.coeff_mul_C Polynomial.coeff_mul_C
@[simp] lemma coeff_mul_natCast {a k : ℕ} :
coeff (p * (a : R[X])) k = coeff p k * (↑a : R) := coeff_mul_C _ _ _
@[simp] lemma coeff_natCast_mul {a k : ℕ} :
coeff ((a : R[X]) * p) k = a * coeff p k := coeff_C_mul _
-- See note [no_index around OfNat.ofNat]
@[simp] lemma coeff_mul_ofNat {a k : ℕ} [Nat.AtLeastTwo a] :
coeff (p * (no_index (OfNat.ofNat a) : R[X])) k = coeff p k * OfNat.ofNat a := coeff_mul_C _ _ _
-- See note [no_index around OfNat.ofNat]
@[simp] lemma coeff_ofNat_mul {a k : ℕ} [Nat.AtLeastTwo a] :
coeff ((no_index (OfNat.ofNat a) : R[X]) * p) k = OfNat.ofNat a * coeff p k := coeff_C_mul _
@[simp] lemma coeff_mul_intCast [Ring S] {p : S[X]} {a : ℤ} {k : ℕ} :
coeff (p * (a : S[X])) k = coeff p k * (↑a : S) := coeff_mul_C _ _ _
@[simp] lemma coeff_intCast_mul [Ring S] {p : S[X]} {a : ℤ} {k : ℕ} :
coeff ((a : S[X]) * p) k = a * coeff p k := coeff_C_mul _
@[simp]
theorem coeff_X_pow (k n : ℕ) : coeff (X ^ k : R[X]) n = if n = k then 1 else 0 := by
simp only [one_mul, RingHom.map_one, ← coeff_C_mul_X_pow]
#align polynomial.coeff_X_pow Polynomial.coeff_X_pow
theorem coeff_X_pow_self (n : ℕ) : coeff (X ^ n : R[X]) n = 1 := by simp
#align polynomial.coeff_X_pow_self Polynomial.coeff_X_pow_self
section Fewnomials
open Finset
theorem support_binomial {k m : ℕ} (hkm : k ≠ m) {x y : R} (hx : x ≠ 0) (hy : y ≠ 0) :
support (C x * X ^ k + C y * X ^ m) = {k, m} := by
apply subset_antisymm (support_binomial' k m x y)
simp_rw [insert_subset_iff, singleton_subset_iff, mem_support_iff, coeff_add, coeff_C_mul,
coeff_X_pow_self, mul_one, coeff_X_pow, if_neg hkm, if_neg hkm.symm, mul_zero, zero_add,
add_zero, Ne, hx, hy, not_false_eq_true, and_true]
#align polynomial.support_binomial Polynomial.support_binomial
theorem support_trinomial {k m n : ℕ} (hkm : k < m) (hmn : m < n) {x y z : R} (hx : x ≠ 0)
(hy : y ≠ 0) (hz : z ≠ 0) :
support (C x * X ^ k + C y * X ^ m + C z * X ^ n) = {k, m, n} := by
apply subset_antisymm (support_trinomial' k m n x y z)
simp_rw [insert_subset_iff, singleton_subset_iff, mem_support_iff, coeff_add, coeff_C_mul,
coeff_X_pow_self, mul_one, coeff_X_pow, if_neg hkm.ne, if_neg hkm.ne', if_neg hmn.ne,
if_neg hmn.ne', if_neg (hkm.trans hmn).ne, if_neg (hkm.trans hmn).ne', mul_zero, add_zero,
zero_add, Ne, hx, hy, hz, not_false_eq_true, and_true]
#align polynomial.support_trinomial Polynomial.support_trinomial
| Mathlib/Algebra/Polynomial/Coeff.lean | 243 | 245 | theorem card_support_binomial {k m : ℕ} (h : k ≠ m) {x y : R} (hx : x ≠ 0) (hy : y ≠ 0) :
card (support (C x * X ^ k + C y * X ^ m)) = 2 := by |
rw [support_binomial h hx hy, card_insert_of_not_mem (mt mem_singleton.mp h), card_singleton]
|
/-
Copyright (c) 2021 Aaron Anderson. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Aaron Anderson
-/
import Mathlib.Algebra.Group.Support
import Mathlib.Order.WellFoundedSet
#align_import ring_theory.hahn_series from "leanprover-community/mathlib"@"a484a7d0eade4e1268f4fb402859b6686037f965"
/-!
# Hahn Series
If `Γ` is ordered and `R` has zero, then `HahnSeries Γ R` consists of formal series over `Γ` with
coefficients in `R`, whose supports are partially well-ordered. With further structure on `R` and
`Γ`, we can add further structure on `HahnSeries Γ R`, with the most studied case being when `Γ` is
a linearly ordered abelian group and `R` is a field, in which case `HahnSeries Γ R` is a
valued field, with value group `Γ`.
These generalize Laurent series (with value group `ℤ`), and Laurent series are implemented that way
in the file `RingTheory/LaurentSeries`.
## Main Definitions
* If `Γ` is ordered and `R` has zero, then `HahnSeries Γ R` consists of
formal series over `Γ` with coefficients in `R`, whose supports are partially well-ordered.
* `support x` is the subset of `Γ` whose coefficients are nonzero.
* `single a r` is the Hahn series which has coefficient `r` at `a` and zero otherwise.
* `orderTop x` is a minimal element of `WithTop Γ` where `x` has a nonzero
coefficient if `x ≠ 0`, and is `⊤` when `x = 0`.
* `order x` is a minimal element of `Γ` where `x` has a nonzero coefficient if `x ≠ 0`, and is zero
when `x = 0`.
## References
- [J. van der Hoeven, *Operators on Generalized Power Series*][van_der_hoeven]
-/
set_option linter.uppercaseLean3 false
open Finset Function
open scoped Classical
noncomputable section
/-- If `Γ` is linearly ordered and `R` has zero, then `HahnSeries Γ R` consists of
formal series over `Γ` with coefficients in `R`, whose supports are well-founded. -/
@[ext]
structure HahnSeries (Γ : Type*) (R : Type*) [PartialOrder Γ] [Zero R] where
/-- The coefficient function of a Hahn Series. -/
coeff : Γ → R
isPWO_support' : (Function.support coeff).IsPWO
#align hahn_series HahnSeries
variable {Γ : Type*} {R : Type*}
namespace HahnSeries
section Zero
variable [PartialOrder Γ] [Zero R]
theorem coeff_injective : Injective (coeff : HahnSeries Γ R → Γ → R) :=
HahnSeries.ext
#align hahn_series.coeff_injective HahnSeries.coeff_injective
@[simp]
theorem coeff_inj {x y : HahnSeries Γ R} : x.coeff = y.coeff ↔ x = y :=
coeff_injective.eq_iff
#align hahn_series.coeff_inj HahnSeries.coeff_inj
/-- The support of a Hahn series is just the set of indices whose coefficients are nonzero.
Notably, it is well-founded. -/
nonrec def support (x : HahnSeries Γ R) : Set Γ :=
support x.coeff
#align hahn_series.support HahnSeries.support
@[simp]
theorem isPWO_support (x : HahnSeries Γ R) : x.support.IsPWO :=
x.isPWO_support'
#align hahn_series.is_pwo_support HahnSeries.isPWO_support
@[simp]
theorem isWF_support (x : HahnSeries Γ R) : x.support.IsWF :=
x.isPWO_support.isWF
#align hahn_series.is_wf_support HahnSeries.isWF_support
@[simp]
theorem mem_support (x : HahnSeries Γ R) (a : Γ) : a ∈ x.support ↔ x.coeff a ≠ 0 :=
Iff.refl _
#align hahn_series.mem_support HahnSeries.mem_support
instance : Zero (HahnSeries Γ R) :=
⟨{ coeff := 0
isPWO_support' := by simp }⟩
instance : Inhabited (HahnSeries Γ R) :=
⟨0⟩
instance [Subsingleton R] : Subsingleton (HahnSeries Γ R) :=
⟨fun a b => a.ext b (Subsingleton.elim _ _)⟩
@[simp]
theorem zero_coeff {a : Γ} : (0 : HahnSeries Γ R).coeff a = 0 :=
rfl
#align hahn_series.zero_coeff HahnSeries.zero_coeff
@[simp]
theorem coeff_fun_eq_zero_iff {x : HahnSeries Γ R} : x.coeff = 0 ↔ x = 0 :=
coeff_injective.eq_iff' rfl
#align hahn_series.coeff_fun_eq_zero_iff HahnSeries.coeff_fun_eq_zero_iff
theorem ne_zero_of_coeff_ne_zero {x : HahnSeries Γ R} {g : Γ} (h : x.coeff g ≠ 0) : x ≠ 0 :=
mt (fun x0 => (x0.symm ▸ zero_coeff : x.coeff g = 0)) h
#align hahn_series.ne_zero_of_coeff_ne_zero HahnSeries.ne_zero_of_coeff_ne_zero
@[simp]
theorem support_zero : support (0 : HahnSeries Γ R) = ∅ :=
Function.support_zero
#align hahn_series.support_zero HahnSeries.support_zero
@[simp]
nonrec theorem support_nonempty_iff {x : HahnSeries Γ R} : x.support.Nonempty ↔ x ≠ 0 := by
rw [support, support_nonempty_iff, Ne, coeff_fun_eq_zero_iff]
#align hahn_series.support_nonempty_iff HahnSeries.support_nonempty_iff
@[simp]
theorem support_eq_empty_iff {x : HahnSeries Γ R} : x.support = ∅ ↔ x = 0 :=
support_eq_empty_iff.trans coeff_fun_eq_zero_iff
#align hahn_series.support_eq_empty_iff HahnSeries.support_eq_empty_iff
/-- Change a HahnSeries with coefficients in HahnSeries to a HahnSeries on the Lex product. -/
def ofIterate {Γ' : Type*} [PartialOrder Γ'] (x : HahnSeries Γ (HahnSeries Γ' R)) :
HahnSeries (Γ ×ₗ Γ') R where
coeff := fun g => coeff (coeff x g.1) g.2
isPWO_support' := by
refine Set.PartiallyWellOrderedOn.subsetProdLex ?_ ?_
· refine Set.IsPWO.mono x.isPWO_support' ?_
simp_rw [Set.image_subset_iff, support_subset_iff, Set.mem_preimage, Function.mem_support]
exact fun _ ↦ ne_zero_of_coeff_ne_zero
· exact fun a => by simpa [Function.mem_support, ne_eq] using (x.coeff a).isPWO_support'
@[simp]
lemma mk_eq_zero (f : Γ → R) (h) : HahnSeries.mk f h = 0 ↔ f = 0 := by
rw [HahnSeries.ext_iff]
rfl
/-- Change a Hahn series on a lex product to a Hahn series with coefficients in a Hahn series. -/
def toIterate {Γ' : Type*} [PartialOrder Γ'] (x : HahnSeries (Γ ×ₗ Γ') R) :
HahnSeries Γ (HahnSeries Γ' R) where
coeff := fun g => {
coeff := fun g' => coeff x (g, g')
isPWO_support' := Set.PartiallyWellOrderedOn.fiberProdLex x.isPWO_support' g
}
isPWO_support' := by
have h₁ : (Function.support fun g => HahnSeries.mk (fun g' => x.coeff (g, g'))
(Set.PartiallyWellOrderedOn.fiberProdLex x.isPWO_support' g)) = Function.support
fun g => fun g' => x.coeff (g, g') := by
simp only [Function.support, ne_eq, mk_eq_zero]
rw [h₁, Function.support_curry' x.coeff]
exact Set.PartiallyWellOrderedOn.imageProdLex x.isPWO_support'
/-- The equivalence between iterated Hahn series and Hahn series on the lex product. -/
@[simps]
def iterateEquiv {Γ' : Type*} [PartialOrder Γ'] :
HahnSeries Γ (HahnSeries Γ' R) ≃ HahnSeries (Γ ×ₗ Γ') R where
toFun := ofIterate
invFun := toIterate
left_inv := congrFun rfl
right_inv := congrFun rfl
/-- `single a r` is the Hahn series which has coefficient `r` at `a` and zero otherwise. -/
def single (a : Γ) : ZeroHom R (HahnSeries Γ R) where
toFun r :=
{ coeff := Pi.single a r
isPWO_support' := (Set.isPWO_singleton a).mono Pi.support_single_subset }
map_zero' := HahnSeries.ext _ _ (Pi.single_zero _)
#align hahn_series.single HahnSeries.single
variable {a b : Γ} {r : R}
@[simp]
theorem single_coeff_same (a : Γ) (r : R) : (single a r).coeff a = r :=
Pi.single_eq_same (f := fun _ => R) a r
#align hahn_series.single_coeff_same HahnSeries.single_coeff_same
@[simp]
theorem single_coeff_of_ne (h : b ≠ a) : (single a r).coeff b = 0 :=
Pi.single_eq_of_ne (f := fun _ => R) h r
#align hahn_series.single_coeff_of_ne HahnSeries.single_coeff_of_ne
theorem single_coeff : (single a r).coeff b = if b = a then r else 0 := by
split_ifs with h <;> simp [h]
#align hahn_series.single_coeff HahnSeries.single_coeff
@[simp]
theorem support_single_of_ne (h : r ≠ 0) : support (single a r) = {a} :=
Pi.support_single_of_ne h
#align hahn_series.support_single_of_ne HahnSeries.support_single_of_ne
theorem support_single_subset : support (single a r) ⊆ {a} :=
Pi.support_single_subset
#align hahn_series.support_single_subset HahnSeries.support_single_subset
theorem eq_of_mem_support_single {b : Γ} (h : b ∈ support (single a r)) : b = a :=
support_single_subset h
#align hahn_series.eq_of_mem_support_single HahnSeries.eq_of_mem_support_single
--@[simp] Porting note (#10618): simp can prove it
theorem single_eq_zero : single a (0 : R) = 0 :=
(single a).map_zero
#align hahn_series.single_eq_zero HahnSeries.single_eq_zero
theorem single_injective (a : Γ) : Function.Injective (single a : R → HahnSeries Γ R) :=
fun r s rs => by rw [← single_coeff_same a r, ← single_coeff_same a s, rs]
#align hahn_series.single_injective HahnSeries.single_injective
theorem single_ne_zero (h : r ≠ 0) : single a r ≠ 0 := fun con =>
h (single_injective a (con.trans single_eq_zero.symm))
#align hahn_series.single_ne_zero HahnSeries.single_ne_zero
@[simp]
theorem single_eq_zero_iff {a : Γ} {r : R} : single a r = 0 ↔ r = 0 :=
map_eq_zero_iff _ <| single_injective a
#align hahn_series.single_eq_zero_iff HahnSeries.single_eq_zero_iff
instance [Nonempty Γ] [Nontrivial R] : Nontrivial (HahnSeries Γ R) :=
⟨by
obtain ⟨r, s, rs⟩ := exists_pair_ne R
inhabit Γ
refine ⟨single default r, single default s, fun con => rs ?_⟩
rw [← single_coeff_same (default : Γ) r, con, single_coeff_same]⟩
section Order
/-- The orderTop of a Hahn series `x` is a minimal element of `WithTop Γ` where `x` has a nonzero
coefficient if `x ≠ 0`, and is `⊤` when `x = 0`. -/
def orderTop (x : HahnSeries Γ R) : WithTop Γ :=
if h : x = 0 then ⊤ else x.isWF_support.min (support_nonempty_iff.2 h)
@[simp]
theorem orderTop_zero : orderTop (0 : HahnSeries Γ R) = ⊤ :=
dif_pos rfl
theorem orderTop_of_ne {x : HahnSeries Γ R} (hx : x ≠ 0) :
orderTop x = x.isWF_support.min (support_nonempty_iff.2 hx) :=
dif_neg hx
@[simp]
theorem ne_zero_iff_orderTop {x : HahnSeries Γ R} : x ≠ 0 ↔ orderTop x ≠ ⊤ := by
constructor
· exact fun hx => Eq.mpr (congrArg (fun h ↦ h ≠ ⊤) (orderTop_of_ne hx)) WithTop.coe_ne_top
· contrapose!
simp_all only [orderTop_zero, implies_true]
| Mathlib/RingTheory/HahnSeries/Basic.lean | 252 | 256 | theorem orderTop_eq_top_iff {x : HahnSeries Γ R} : orderTop x = ⊤ ↔ x = 0 := by |
constructor
· contrapose!
exact ne_zero_iff_orderTop.mp
· simp_all only [orderTop_zero, implies_true]
|
/-
Copyright (c) 2020 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin
-/
import Mathlib.LinearAlgebra.Finsupp
import Mathlib.RingTheory.Ideal.Over
import Mathlib.RingTheory.Ideal.Prod
import Mathlib.RingTheory.Ideal.MinimalPrime
import Mathlib.RingTheory.Localization.Away.Basic
import Mathlib.RingTheory.Nilpotent.Lemmas
import Mathlib.Topology.Sets.Closeds
import Mathlib.Topology.Sober
#align_import algebraic_geometry.prime_spectrum.basic from "leanprover-community/mathlib"@"a7c017d750512a352b623b1824d75da5998457d0"
/-!
# Prime spectrum of a commutative (semi)ring
The prime spectrum of a commutative (semi)ring is the type of all prime ideals.
It is naturally endowed with a topology: the Zariski topology.
(It is also naturally endowed with a sheaf of rings,
which is constructed in `AlgebraicGeometry.StructureSheaf`.)
## Main definitions
* `PrimeSpectrum R`: The prime spectrum of a commutative (semi)ring `R`,
i.e., the set of all prime ideals of `R`.
* `zeroLocus s`: The zero locus of a subset `s` of `R`
is the subset of `PrimeSpectrum R` consisting of all prime ideals that contain `s`.
* `vanishingIdeal t`: The vanishing ideal of a subset `t` of `PrimeSpectrum R`
is the intersection of points in `t` (viewed as prime ideals).
## Conventions
We denote subsets of (semi)rings with `s`, `s'`, etc...
whereas we denote subsets of prime spectra with `t`, `t'`, etc...
## Inspiration/contributors
The contents of this file draw inspiration from <https://github.com/ramonfmir/lean-scheme>
which has contributions from Ramon Fernandez Mir, Kevin Buzzard, Kenny Lau,
and Chris Hughes (on an earlier repository).
-/
noncomputable section
open scoped Classical
universe u v
variable (R : Type u) (S : Type v)
/-- The prime spectrum of a commutative (semi)ring `R` is the type of all prime ideals of `R`.
It is naturally endowed with a topology (the Zariski topology),
and a sheaf of commutative rings (see `AlgebraicGeometry.StructureSheaf`).
It is a fundamental building block in algebraic geometry. -/
@[ext]
structure PrimeSpectrum [CommSemiring R] where
asIdeal : Ideal R
IsPrime : asIdeal.IsPrime
#align prime_spectrum PrimeSpectrum
attribute [instance] PrimeSpectrum.IsPrime
namespace PrimeSpectrum
section CommSemiRing
variable [CommSemiring R] [CommSemiring S]
variable {R S}
instance [Nontrivial R] : Nonempty <| PrimeSpectrum R :=
let ⟨I, hI⟩ := Ideal.exists_maximal R
⟨⟨I, hI.isPrime⟩⟩
/-- The prime spectrum of the zero ring is empty. -/
instance [Subsingleton R] : IsEmpty (PrimeSpectrum R) :=
⟨fun x ↦ x.IsPrime.ne_top <| SetLike.ext' <| Subsingleton.eq_univ_of_nonempty x.asIdeal.nonempty⟩
#noalign prime_spectrum.punit
variable (R S)
/-- The map from the direct sum of prime spectra to the prime spectrum of a direct product. -/
@[simp]
def primeSpectrumProdOfSum : Sum (PrimeSpectrum R) (PrimeSpectrum S) → PrimeSpectrum (R × S)
| Sum.inl ⟨I, _⟩ => ⟨Ideal.prod I ⊤, Ideal.isPrime_ideal_prod_top⟩
| Sum.inr ⟨J, _⟩ => ⟨Ideal.prod ⊤ J, Ideal.isPrime_ideal_prod_top'⟩
#align prime_spectrum.prime_spectrum_prod_of_sum PrimeSpectrum.primeSpectrumProdOfSum
/-- The prime spectrum of `R × S` is in bijection with the disjoint unions of the prime spectrum of
`R` and the prime spectrum of `S`. -/
noncomputable def primeSpectrumProd :
PrimeSpectrum (R × S) ≃ Sum (PrimeSpectrum R) (PrimeSpectrum S) :=
Equiv.symm <|
Equiv.ofBijective (primeSpectrumProdOfSum R S) (by
constructor
· rintro (⟨I, hI⟩ | ⟨J, hJ⟩) (⟨I', hI'⟩ | ⟨J', hJ'⟩) h <;>
simp only [mk.injEq, Ideal.prod.ext_iff, primeSpectrumProdOfSum] at h
· simp only [h]
· exact False.elim (hI.ne_top h.left)
· exact False.elim (hJ.ne_top h.right)
· simp only [h]
· rintro ⟨I, hI⟩
rcases (Ideal.ideal_prod_prime I).mp hI with (⟨p, ⟨hp, rfl⟩⟩ | ⟨p, ⟨hp, rfl⟩⟩)
· exact ⟨Sum.inl ⟨p, hp⟩, rfl⟩
· exact ⟨Sum.inr ⟨p, hp⟩, rfl⟩)
#align prime_spectrum.prime_spectrum_prod PrimeSpectrum.primeSpectrumProd
variable {R S}
@[simp]
| Mathlib/AlgebraicGeometry/PrimeSpectrum/Basic.lean | 116 | 119 | theorem primeSpectrumProd_symm_inl_asIdeal (x : PrimeSpectrum R) :
((primeSpectrumProd R S).symm <| Sum.inl x).asIdeal = Ideal.prod x.asIdeal ⊤ := by |
cases x
rfl
|
/-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Mario Carneiro, Yury Kudryashov
-/
import Mathlib.Data.Set.Image
import Mathlib.Order.SuccPred.Relation
import Mathlib.Topology.Clopen
import Mathlib.Topology.Irreducible
#align_import topology.connected from "leanprover-community/mathlib"@"d101e93197bb5f6ea89bd7ba386b7f7dff1f3903"
/-!
# Connected subsets of topological spaces
In this file we define connected subsets of a topological spaces and various other properties and
classes related to connectivity.
## Main definitions
We define the following properties for sets in a topological space:
* `IsConnected`: a nonempty set that has no non-trivial open partition.
See also the section below in the module doc.
* `connectedComponent` is the connected component of an element in the space.
We also have a class stating that the whole space satisfies that property: `ConnectedSpace`
## On the definition of connected sets/spaces
In informal mathematics, connected spaces are assumed to be nonempty.
We formalise the predicate without that assumption as `IsPreconnected`.
In other words, the only difference is whether the empty space counts as connected.
There are good reasons to consider the empty space to be “too simple to be simple”
See also https://ncatlab.org/nlab/show/too+simple+to+be+simple,
and in particular
https://ncatlab.org/nlab/show/too+simple+to+be+simple#relationship_to_biased_definitions.
-/
open Set Function Topology TopologicalSpace Relation
open scoped Classical
universe u v
variable {α : Type u} {β : Type v} {ι : Type*} {π : ι → Type*} [TopologicalSpace α]
{s t u v : Set α}
section Preconnected
/-- A preconnected set is one where there is no non-trivial open partition. -/
def IsPreconnected (s : Set α) : Prop :=
∀ u v : Set α, IsOpen u → IsOpen v → s ⊆ u ∪ v → (s ∩ u).Nonempty → (s ∩ v).Nonempty →
(s ∩ (u ∩ v)).Nonempty
#align is_preconnected IsPreconnected
/-- A connected set is one that is nonempty and where there is no non-trivial open partition. -/
def IsConnected (s : Set α) : Prop :=
s.Nonempty ∧ IsPreconnected s
#align is_connected IsConnected
theorem IsConnected.nonempty {s : Set α} (h : IsConnected s) : s.Nonempty :=
h.1
#align is_connected.nonempty IsConnected.nonempty
theorem IsConnected.isPreconnected {s : Set α} (h : IsConnected s) : IsPreconnected s :=
h.2
#align is_connected.is_preconnected IsConnected.isPreconnected
theorem IsPreirreducible.isPreconnected {s : Set α} (H : IsPreirreducible s) : IsPreconnected s :=
fun _ _ hu hv _ => H _ _ hu hv
#align is_preirreducible.is_preconnected IsPreirreducible.isPreconnected
theorem IsIrreducible.isConnected {s : Set α} (H : IsIrreducible s) : IsConnected s :=
⟨H.nonempty, H.isPreirreducible.isPreconnected⟩
#align is_irreducible.is_connected IsIrreducible.isConnected
theorem isPreconnected_empty : IsPreconnected (∅ : Set α) :=
isPreirreducible_empty.isPreconnected
#align is_preconnected_empty isPreconnected_empty
theorem isConnected_singleton {x} : IsConnected ({x} : Set α) :=
isIrreducible_singleton.isConnected
#align is_connected_singleton isConnected_singleton
theorem isPreconnected_singleton {x} : IsPreconnected ({x} : Set α) :=
isConnected_singleton.isPreconnected
#align is_preconnected_singleton isPreconnected_singleton
theorem Set.Subsingleton.isPreconnected {s : Set α} (hs : s.Subsingleton) : IsPreconnected s :=
hs.induction_on isPreconnected_empty fun _ => isPreconnected_singleton
#align set.subsingleton.is_preconnected Set.Subsingleton.isPreconnected
/-- If any point of a set is joined to a fixed point by a preconnected subset,
then the original set is preconnected as well. -/
theorem isPreconnected_of_forall {s : Set α} (x : α)
(H : ∀ y ∈ s, ∃ t, t ⊆ s ∧ x ∈ t ∧ y ∈ t ∧ IsPreconnected t) : IsPreconnected s := by
rintro u v hu hv hs ⟨z, zs, zu⟩ ⟨y, ys, yv⟩
have xs : x ∈ s := by
rcases H y ys with ⟨t, ts, xt, -, -⟩
exact ts xt
-- Porting note (#11215): TODO: use `wlog xu : x ∈ u := hs xs using u v y z, v u z y`
cases hs xs with
| inl xu =>
rcases H y ys with ⟨t, ts, xt, yt, ht⟩
have := ht u v hu hv (ts.trans hs) ⟨x, xt, xu⟩ ⟨y, yt, yv⟩
exact this.imp fun z hz => ⟨ts hz.1, hz.2⟩
| inr xv =>
rcases H z zs with ⟨t, ts, xt, zt, ht⟩
have := ht v u hv hu (ts.trans <| by rwa [union_comm]) ⟨x, xt, xv⟩ ⟨z, zt, zu⟩
exact this.imp fun _ h => ⟨ts h.1, h.2.2, h.2.1⟩
#align is_preconnected_of_forall isPreconnected_of_forall
/-- If any two points of a set are contained in a preconnected subset,
then the original set is preconnected as well. -/
theorem isPreconnected_of_forall_pair {s : Set α}
(H : ∀ x ∈ s, ∀ y ∈ s, ∃ t, t ⊆ s ∧ x ∈ t ∧ y ∈ t ∧ IsPreconnected t) :
IsPreconnected s := by
rcases eq_empty_or_nonempty s with (rfl | ⟨x, hx⟩)
exacts [isPreconnected_empty, isPreconnected_of_forall x fun y => H x hx y]
#align is_preconnected_of_forall_pair isPreconnected_of_forall_pair
/-- A union of a family of preconnected sets with a common point is preconnected as well. -/
theorem isPreconnected_sUnion (x : α) (c : Set (Set α)) (H1 : ∀ s ∈ c, x ∈ s)
(H2 : ∀ s ∈ c, IsPreconnected s) : IsPreconnected (⋃₀ c) := by
apply isPreconnected_of_forall x
rintro y ⟨s, sc, ys⟩
exact ⟨s, subset_sUnion_of_mem sc, H1 s sc, ys, H2 s sc⟩
#align is_preconnected_sUnion isPreconnected_sUnion
theorem isPreconnected_iUnion {ι : Sort*} {s : ι → Set α} (h₁ : (⋂ i, s i).Nonempty)
(h₂ : ∀ i, IsPreconnected (s i)) : IsPreconnected (⋃ i, s i) :=
Exists.elim h₁ fun f hf => isPreconnected_sUnion f _ hf (forall_mem_range.2 h₂)
#align is_preconnected_Union isPreconnected_iUnion
theorem IsPreconnected.union (x : α) {s t : Set α} (H1 : x ∈ s) (H2 : x ∈ t) (H3 : IsPreconnected s)
(H4 : IsPreconnected t) : IsPreconnected (s ∪ t) :=
sUnion_pair s t ▸ isPreconnected_sUnion x {s, t} (by rintro r (rfl | rfl | h) <;> assumption)
(by rintro r (rfl | rfl | h) <;> assumption)
#align is_preconnected.union IsPreconnected.union
| Mathlib/Topology/Connected/Basic.lean | 142 | 145 | theorem IsPreconnected.union' {s t : Set α} (H : (s ∩ t).Nonempty) (hs : IsPreconnected s)
(ht : IsPreconnected t) : IsPreconnected (s ∪ t) := by |
rcases H with ⟨x, hxs, hxt⟩
exact hs.union x hxs hxt ht
|
/-
Copyright (c) 2020 Rémy Degenne. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Rémy Degenne, Sébastien Gouëzel
-/
import Mathlib.Analysis.Normed.Group.Hom
import Mathlib.Analysis.SpecialFunctions.Pow.Continuity
import Mathlib.Data.Set.Image
import Mathlib.MeasureTheory.Function.LpSeminorm.ChebyshevMarkov
import Mathlib.MeasureTheory.Function.LpSeminorm.CompareExp
import Mathlib.MeasureTheory.Function.LpSeminorm.TriangleInequality
import Mathlib.MeasureTheory.Measure.OpenPos
import Mathlib.Topology.ContinuousFunction.Compact
import Mathlib.Order.Filter.IndicatorFunction
#align_import measure_theory.function.lp_space from "leanprover-community/mathlib"@"c4015acc0a223449d44061e27ddac1835a3852b9"
/-!
# Lp space
This file provides the space `Lp E p μ` as the subtype of elements of `α →ₘ[μ] E` (see ae_eq_fun)
such that `snorm f p μ` is finite. For `1 ≤ p`, `snorm` defines a norm and `Lp` is a complete metric
space.
## Main definitions
* `Lp E p μ` : elements of `α →ₘ[μ] E` (see ae_eq_fun) such that `snorm f p μ` is finite. Defined
as an `AddSubgroup` of `α →ₘ[μ] E`.
Lipschitz functions vanishing at zero act by composition on `Lp`. We define this action, and prove
that it is continuous. In particular,
* `ContinuousLinearMap.compLp` defines the action on `Lp` of a continuous linear map.
* `Lp.posPart` is the positive part of an `Lp` function.
* `Lp.negPart` is the negative part of an `Lp` function.
When `α` is a topological space equipped with a finite Borel measure, there is a bounded linear map
from the normed space of bounded continuous functions (`α →ᵇ E`) to `Lp E p μ`. We construct this
as `BoundedContinuousFunction.toLp`.
## Notations
* `α →₁[μ] E` : the type `Lp E 1 μ`.
* `α →₂[μ] E` : the type `Lp E 2 μ`.
## Implementation
Since `Lp` is defined as an `AddSubgroup`, dot notation does not work. Use `Lp.Measurable f` to
say that the coercion of `f` to a genuine function is measurable, instead of the non-working
`f.Measurable`.
To prove that two `Lp` elements are equal, it suffices to show that their coercions to functions
coincide almost everywhere (this is registered as an `ext` rule). This can often be done using
`filter_upwards`. For instance, a proof from first principles that `f + (g + h) = (f + g) + h`
could read (in the `Lp` namespace)
```
example (f g h : Lp E p μ) : (f + g) + h = f + (g + h) := by
ext1
filter_upwards [coeFn_add (f + g) h, coeFn_add f g, coeFn_add f (g + h), coeFn_add g h]
with _ ha1 ha2 ha3 ha4
simp only [ha1, ha2, ha3, ha4, add_assoc]
```
The lemma `coeFn_add` states that the coercion of `f + g` coincides almost everywhere with the sum
of the coercions of `f` and `g`. All such lemmas use `coeFn` in their name, to distinguish the
function coercion from the coercion to almost everywhere defined functions.
-/
noncomputable section
set_option linter.uppercaseLean3 false
open TopologicalSpace MeasureTheory Filter
open scoped NNReal ENNReal Topology MeasureTheory Uniformity
variable {α E F G : Type*} {m m0 : MeasurableSpace α} {p : ℝ≥0∞} {q : ℝ} {μ ν : Measure α}
[NormedAddCommGroup E] [NormedAddCommGroup F] [NormedAddCommGroup G]
namespace MeasureTheory
/-!
### Lp space
The space of equivalence classes of measurable functions for which `snorm f p μ < ∞`.
-/
@[simp]
theorem snorm_aeeqFun {α E : Type*} [MeasurableSpace α] {μ : Measure α} [NormedAddCommGroup E]
{p : ℝ≥0∞} {f : α → E} (hf : AEStronglyMeasurable f μ) :
snorm (AEEqFun.mk f hf) p μ = snorm f p μ :=
snorm_congr_ae (AEEqFun.coeFn_mk _ _)
#align measure_theory.snorm_ae_eq_fun MeasureTheory.snorm_aeeqFun
theorem Memℒp.snorm_mk_lt_top {α E : Type*} [MeasurableSpace α] {μ : Measure α}
[NormedAddCommGroup E] {p : ℝ≥0∞} {f : α → E} (hfp : Memℒp f p μ) :
snorm (AEEqFun.mk f hfp.1) p μ < ∞ := by simp [hfp.2]
#align measure_theory.mem_ℒp.snorm_mk_lt_top MeasureTheory.Memℒp.snorm_mk_lt_top
/-- Lp space -/
def Lp {α} (E : Type*) {m : MeasurableSpace α} [NormedAddCommGroup E] (p : ℝ≥0∞)
(μ : Measure α := by volume_tac) : AddSubgroup (α →ₘ[μ] E) where
carrier := { f | snorm f p μ < ∞ }
zero_mem' := by simp [snorm_congr_ae AEEqFun.coeFn_zero, snorm_zero]
add_mem' {f g} hf hg := by
simp [snorm_congr_ae (AEEqFun.coeFn_add f g),
snorm_add_lt_top ⟨f.aestronglyMeasurable, hf⟩ ⟨g.aestronglyMeasurable, hg⟩]
neg_mem' {f} hf := by rwa [Set.mem_setOf_eq, snorm_congr_ae (AEEqFun.coeFn_neg f), snorm_neg]
#align measure_theory.Lp MeasureTheory.Lp
-- Porting note: calling the first argument `α` breaks the `(α := ·)` notation
scoped notation:25 α' " →₁[" μ "] " E => MeasureTheory.Lp (α := α') E 1 μ
scoped notation:25 α' " →₂[" μ "] " E => MeasureTheory.Lp (α := α') E 2 μ
namespace Memℒp
/-- make an element of Lp from a function verifying `Memℒp` -/
def toLp (f : α → E) (h_mem_ℒp : Memℒp f p μ) : Lp E p μ :=
⟨AEEqFun.mk f h_mem_ℒp.1, h_mem_ℒp.snorm_mk_lt_top⟩
#align measure_theory.mem_ℒp.to_Lp MeasureTheory.Memℒp.toLp
theorem coeFn_toLp {f : α → E} (hf : Memℒp f p μ) : hf.toLp f =ᵐ[μ] f :=
AEEqFun.coeFn_mk _ _
#align measure_theory.mem_ℒp.coe_fn_to_Lp MeasureTheory.Memℒp.coeFn_toLp
theorem toLp_congr {f g : α → E} (hf : Memℒp f p μ) (hg : Memℒp g p μ) (hfg : f =ᵐ[μ] g) :
hf.toLp f = hg.toLp g := by simp [toLp, hfg]
#align measure_theory.mem_ℒp.to_Lp_congr MeasureTheory.Memℒp.toLp_congr
@[simp]
theorem toLp_eq_toLp_iff {f g : α → E} (hf : Memℒp f p μ) (hg : Memℒp g p μ) :
hf.toLp f = hg.toLp g ↔ f =ᵐ[μ] g := by simp [toLp]
#align measure_theory.mem_ℒp.to_Lp_eq_to_Lp_iff MeasureTheory.Memℒp.toLp_eq_toLp_iff
@[simp]
theorem toLp_zero (h : Memℒp (0 : α → E) p μ) : h.toLp 0 = 0 :=
rfl
#align measure_theory.mem_ℒp.to_Lp_zero MeasureTheory.Memℒp.toLp_zero
theorem toLp_add {f g : α → E} (hf : Memℒp f p μ) (hg : Memℒp g p μ) :
(hf.add hg).toLp (f + g) = hf.toLp f + hg.toLp g :=
rfl
#align measure_theory.mem_ℒp.to_Lp_add MeasureTheory.Memℒp.toLp_add
theorem toLp_neg {f : α → E} (hf : Memℒp f p μ) : hf.neg.toLp (-f) = -hf.toLp f :=
rfl
#align measure_theory.mem_ℒp.to_Lp_neg MeasureTheory.Memℒp.toLp_neg
theorem toLp_sub {f g : α → E} (hf : Memℒp f p μ) (hg : Memℒp g p μ) :
(hf.sub hg).toLp (f - g) = hf.toLp f - hg.toLp g :=
rfl
#align measure_theory.mem_ℒp.to_Lp_sub MeasureTheory.Memℒp.toLp_sub
end Memℒp
namespace Lp
instance instCoeFun : CoeFun (Lp E p μ) (fun _ => α → E) :=
⟨fun f => ((f : α →ₘ[μ] E) : α → E)⟩
#align measure_theory.Lp.has_coe_to_fun MeasureTheory.Lp.instCoeFun
@[ext high]
theorem ext {f g : Lp E p μ} (h : f =ᵐ[μ] g) : f = g := by
cases f
cases g
simp only [Subtype.mk_eq_mk]
exact AEEqFun.ext h
#align measure_theory.Lp.ext MeasureTheory.Lp.ext
theorem ext_iff {f g : Lp E p μ} : f = g ↔ f =ᵐ[μ] g :=
⟨fun h => by rw [h], fun h => ext h⟩
#align measure_theory.Lp.ext_iff MeasureTheory.Lp.ext_iff
theorem mem_Lp_iff_snorm_lt_top {f : α →ₘ[μ] E} : f ∈ Lp E p μ ↔ snorm f p μ < ∞ := Iff.rfl
#align measure_theory.Lp.mem_Lp_iff_snorm_lt_top MeasureTheory.Lp.mem_Lp_iff_snorm_lt_top
theorem mem_Lp_iff_memℒp {f : α →ₘ[μ] E} : f ∈ Lp E p μ ↔ Memℒp f p μ := by
simp [mem_Lp_iff_snorm_lt_top, Memℒp, f.stronglyMeasurable.aestronglyMeasurable]
#align measure_theory.Lp.mem_Lp_iff_mem_ℒp MeasureTheory.Lp.mem_Lp_iff_memℒp
protected theorem antitone [IsFiniteMeasure μ] {p q : ℝ≥0∞} (hpq : p ≤ q) : Lp E q μ ≤ Lp E p μ :=
fun f hf => (Memℒp.memℒp_of_exponent_le ⟨f.aestronglyMeasurable, hf⟩ hpq).2
#align measure_theory.Lp.antitone MeasureTheory.Lp.antitone
@[simp]
theorem coeFn_mk {f : α →ₘ[μ] E} (hf : snorm f p μ < ∞) : ((⟨f, hf⟩ : Lp E p μ) : α → E) = f :=
rfl
#align measure_theory.Lp.coe_fn_mk MeasureTheory.Lp.coeFn_mk
-- @[simp] -- Porting note (#10685): dsimp can prove this
theorem coe_mk {f : α →ₘ[μ] E} (hf : snorm f p μ < ∞) : ((⟨f, hf⟩ : Lp E p μ) : α →ₘ[μ] E) = f :=
rfl
#align measure_theory.Lp.coe_mk MeasureTheory.Lp.coe_mk
@[simp]
theorem toLp_coeFn (f : Lp E p μ) (hf : Memℒp f p μ) : hf.toLp f = f := by
cases f
simp [Memℒp.toLp]
#align measure_theory.Lp.to_Lp_coe_fn MeasureTheory.Lp.toLp_coeFn
theorem snorm_lt_top (f : Lp E p μ) : snorm f p μ < ∞ :=
f.prop
#align measure_theory.Lp.snorm_lt_top MeasureTheory.Lp.snorm_lt_top
theorem snorm_ne_top (f : Lp E p μ) : snorm f p μ ≠ ∞ :=
(snorm_lt_top f).ne
#align measure_theory.Lp.snorm_ne_top MeasureTheory.Lp.snorm_ne_top
@[measurability]
protected theorem stronglyMeasurable (f : Lp E p μ) : StronglyMeasurable f :=
f.val.stronglyMeasurable
#align measure_theory.Lp.strongly_measurable MeasureTheory.Lp.stronglyMeasurable
@[measurability]
protected theorem aestronglyMeasurable (f : Lp E p μ) : AEStronglyMeasurable f μ :=
f.val.aestronglyMeasurable
#align measure_theory.Lp.ae_strongly_measurable MeasureTheory.Lp.aestronglyMeasurable
protected theorem memℒp (f : Lp E p μ) : Memℒp f p μ :=
⟨Lp.aestronglyMeasurable f, f.prop⟩
#align measure_theory.Lp.mem_ℒp MeasureTheory.Lp.memℒp
variable (E p μ)
theorem coeFn_zero : ⇑(0 : Lp E p μ) =ᵐ[μ] 0 :=
AEEqFun.coeFn_zero
#align measure_theory.Lp.coe_fn_zero MeasureTheory.Lp.coeFn_zero
variable {E p μ}
theorem coeFn_neg (f : Lp E p μ) : ⇑(-f) =ᵐ[μ] -f :=
AEEqFun.coeFn_neg _
#align measure_theory.Lp.coe_fn_neg MeasureTheory.Lp.coeFn_neg
theorem coeFn_add (f g : Lp E p μ) : ⇑(f + g) =ᵐ[μ] f + g :=
AEEqFun.coeFn_add _ _
#align measure_theory.Lp.coe_fn_add MeasureTheory.Lp.coeFn_add
theorem coeFn_sub (f g : Lp E p μ) : ⇑(f - g) =ᵐ[μ] f - g :=
AEEqFun.coeFn_sub _ _
#align measure_theory.Lp.coe_fn_sub MeasureTheory.Lp.coeFn_sub
theorem const_mem_Lp (α) {_ : MeasurableSpace α} (μ : Measure α) (c : E) [IsFiniteMeasure μ] :
@AEEqFun.const α _ _ μ _ c ∈ Lp E p μ :=
(memℒp_const c).snorm_mk_lt_top
#align measure_theory.Lp.mem_Lp_const MeasureTheory.Lp.const_mem_Lp
instance instNorm : Norm (Lp E p μ) where norm f := ENNReal.toReal (snorm f p μ)
#align measure_theory.Lp.has_norm MeasureTheory.Lp.instNorm
-- note: we need this to be defeq to the instance from `SeminormedAddGroup.toNNNorm`, so
-- can't use `ENNReal.toNNReal (snorm f p μ)`
instance instNNNorm : NNNorm (Lp E p μ) where nnnorm f := ⟨‖f‖, ENNReal.toReal_nonneg⟩
#align measure_theory.Lp.has_nnnorm MeasureTheory.Lp.instNNNorm
instance instDist : Dist (Lp E p μ) where dist f g := ‖f - g‖
#align measure_theory.Lp.has_dist MeasureTheory.Lp.instDist
instance instEDist : EDist (Lp E p μ) where edist f g := snorm (⇑f - ⇑g) p μ
#align measure_theory.Lp.has_edist MeasureTheory.Lp.instEDist
theorem norm_def (f : Lp E p μ) : ‖f‖ = ENNReal.toReal (snorm f p μ) :=
rfl
#align measure_theory.Lp.norm_def MeasureTheory.Lp.norm_def
theorem nnnorm_def (f : Lp E p μ) : ‖f‖₊ = ENNReal.toNNReal (snorm f p μ) :=
rfl
#align measure_theory.Lp.nnnorm_def MeasureTheory.Lp.nnnorm_def
@[simp, norm_cast]
protected theorem coe_nnnorm (f : Lp E p μ) : (‖f‖₊ : ℝ) = ‖f‖ :=
rfl
#align measure_theory.Lp.coe_nnnorm MeasureTheory.Lp.coe_nnnorm
@[simp, norm_cast]
theorem nnnorm_coe_ennreal (f : Lp E p μ) : (‖f‖₊ : ℝ≥0∞) = snorm f p μ :=
ENNReal.coe_toNNReal <| Lp.snorm_ne_top f
@[simp]
theorem norm_toLp (f : α → E) (hf : Memℒp f p μ) : ‖hf.toLp f‖ = ENNReal.toReal (snorm f p μ) := by
erw [norm_def, snorm_congr_ae (Memℒp.coeFn_toLp hf)]
#align measure_theory.Lp.norm_to_Lp MeasureTheory.Lp.norm_toLp
@[simp]
theorem nnnorm_toLp (f : α → E) (hf : Memℒp f p μ) :
‖hf.toLp f‖₊ = ENNReal.toNNReal (snorm f p μ) :=
NNReal.eq <| norm_toLp f hf
#align measure_theory.Lp.nnnorm_to_Lp MeasureTheory.Lp.nnnorm_toLp
theorem coe_nnnorm_toLp {f : α → E} (hf : Memℒp f p μ) : (‖hf.toLp f‖₊ : ℝ≥0∞) = snorm f p μ := by
rw [nnnorm_toLp f hf, ENNReal.coe_toNNReal hf.2.ne]
theorem dist_def (f g : Lp E p μ) : dist f g = (snorm (⇑f - ⇑g) p μ).toReal := by
simp_rw [dist, norm_def]
refine congr_arg _ ?_
apply snorm_congr_ae (coeFn_sub _ _)
#align measure_theory.Lp.dist_def MeasureTheory.Lp.dist_def
theorem edist_def (f g : Lp E p μ) : edist f g = snorm (⇑f - ⇑g) p μ :=
rfl
#align measure_theory.Lp.edist_def MeasureTheory.Lp.edist_def
protected theorem edist_dist (f g : Lp E p μ) : edist f g = .ofReal (dist f g) := by
rw [edist_def, dist_def, ← snorm_congr_ae (coeFn_sub _ _),
ENNReal.ofReal_toReal (snorm_ne_top (f - g))]
protected theorem dist_edist (f g : Lp E p μ) : dist f g = (edist f g).toReal :=
MeasureTheory.Lp.dist_def ..
theorem dist_eq_norm (f g : Lp E p μ) : dist f g = ‖f - g‖ := rfl
@[simp]
theorem edist_toLp_toLp (f g : α → E) (hf : Memℒp f p μ) (hg : Memℒp g p μ) :
edist (hf.toLp f) (hg.toLp g) = snorm (f - g) p μ := by
rw [edist_def]
exact snorm_congr_ae (hf.coeFn_toLp.sub hg.coeFn_toLp)
#align measure_theory.Lp.edist_to_Lp_to_Lp MeasureTheory.Lp.edist_toLp_toLp
@[simp]
theorem edist_toLp_zero (f : α → E) (hf : Memℒp f p μ) : edist (hf.toLp f) 0 = snorm f p μ := by
convert edist_toLp_toLp f 0 hf zero_memℒp
simp
#align measure_theory.Lp.edist_to_Lp_zero MeasureTheory.Lp.edist_toLp_zero
@[simp]
theorem nnnorm_zero : ‖(0 : Lp E p μ)‖₊ = 0 := by
rw [nnnorm_def]
change (snorm (⇑(0 : α →ₘ[μ] E)) p μ).toNNReal = 0
simp [snorm_congr_ae AEEqFun.coeFn_zero, snorm_zero]
#align measure_theory.Lp.nnnorm_zero MeasureTheory.Lp.nnnorm_zero
@[simp]
theorem norm_zero : ‖(0 : Lp E p μ)‖ = 0 :=
congr_arg ((↑) : ℝ≥0 → ℝ) nnnorm_zero
#align measure_theory.Lp.norm_zero MeasureTheory.Lp.norm_zero
@[simp]
theorem norm_measure_zero (f : Lp E p (0 : MeasureTheory.Measure α)) : ‖f‖ = 0 := by
simp [norm_def]
@[simp] theorem norm_exponent_zero (f : Lp E 0 μ) : ‖f‖ = 0 := by simp [norm_def]
theorem nnnorm_eq_zero_iff {f : Lp E p μ} (hp : 0 < p) : ‖f‖₊ = 0 ↔ f = 0 := by
refine ⟨fun hf => ?_, fun hf => by simp [hf]⟩
rw [nnnorm_def, ENNReal.toNNReal_eq_zero_iff] at hf
cases hf with
| inl hf =>
rw [snorm_eq_zero_iff (Lp.aestronglyMeasurable f) hp.ne.symm] at hf
exact Subtype.eq (AEEqFun.ext (hf.trans AEEqFun.coeFn_zero.symm))
| inr hf =>
exact absurd hf (snorm_ne_top f)
#align measure_theory.Lp.nnnorm_eq_zero_iff MeasureTheory.Lp.nnnorm_eq_zero_iff
theorem norm_eq_zero_iff {f : Lp E p μ} (hp : 0 < p) : ‖f‖ = 0 ↔ f = 0 :=
NNReal.coe_eq_zero.trans (nnnorm_eq_zero_iff hp)
#align measure_theory.Lp.norm_eq_zero_iff MeasureTheory.Lp.norm_eq_zero_iff
theorem eq_zero_iff_ae_eq_zero {f : Lp E p μ} : f = 0 ↔ f =ᵐ[μ] 0 := by
rw [← (Lp.memℒp f).toLp_eq_toLp_iff zero_memℒp, Memℒp.toLp_zero, toLp_coeFn]
#align measure_theory.Lp.eq_zero_iff_ae_eq_zero MeasureTheory.Lp.eq_zero_iff_ae_eq_zero
@[simp]
theorem nnnorm_neg (f : Lp E p μ) : ‖-f‖₊ = ‖f‖₊ := by
rw [nnnorm_def, nnnorm_def, snorm_congr_ae (coeFn_neg _), snorm_neg]
#align measure_theory.Lp.nnnorm_neg MeasureTheory.Lp.nnnorm_neg
@[simp]
theorem norm_neg (f : Lp E p μ) : ‖-f‖ = ‖f‖ :=
congr_arg ((↑) : ℝ≥0 → ℝ) (nnnorm_neg f)
#align measure_theory.Lp.norm_neg MeasureTheory.Lp.norm_neg
theorem nnnorm_le_mul_nnnorm_of_ae_le_mul {c : ℝ≥0} {f : Lp E p μ} {g : Lp F p μ}
(h : ∀ᵐ x ∂μ, ‖f x‖₊ ≤ c * ‖g x‖₊) : ‖f‖₊ ≤ c * ‖g‖₊ := by
simp only [nnnorm_def]
have := snorm_le_nnreal_smul_snorm_of_ae_le_mul h p
rwa [← ENNReal.toNNReal_le_toNNReal, ENNReal.smul_def, smul_eq_mul, ENNReal.toNNReal_mul,
ENNReal.toNNReal_coe] at this
· exact (Lp.memℒp _).snorm_ne_top
· exact ENNReal.mul_ne_top ENNReal.coe_ne_top (Lp.memℒp _).snorm_ne_top
#align measure_theory.Lp.nnnorm_le_mul_nnnorm_of_ae_le_mul MeasureTheory.Lp.nnnorm_le_mul_nnnorm_of_ae_le_mul
theorem norm_le_mul_norm_of_ae_le_mul {c : ℝ} {f : Lp E p μ} {g : Lp F p μ}
(h : ∀ᵐ x ∂μ, ‖f x‖ ≤ c * ‖g x‖) : ‖f‖ ≤ c * ‖g‖ := by
rcases le_or_lt 0 c with hc | hc
· lift c to ℝ≥0 using hc
exact NNReal.coe_le_coe.mpr (nnnorm_le_mul_nnnorm_of_ae_le_mul h)
· simp only [norm_def]
have := snorm_eq_zero_and_zero_of_ae_le_mul_neg h hc p
simp [this]
#align measure_theory.Lp.norm_le_mul_norm_of_ae_le_mul MeasureTheory.Lp.norm_le_mul_norm_of_ae_le_mul
theorem norm_le_norm_of_ae_le {f : Lp E p μ} {g : Lp F p μ} (h : ∀ᵐ x ∂μ, ‖f x‖ ≤ ‖g x‖) :
‖f‖ ≤ ‖g‖ := by
rw [norm_def, norm_def, ENNReal.toReal_le_toReal (snorm_ne_top _) (snorm_ne_top _)]
exact snorm_mono_ae h
#align measure_theory.Lp.norm_le_norm_of_ae_le MeasureTheory.Lp.norm_le_norm_of_ae_le
theorem mem_Lp_of_nnnorm_ae_le_mul {c : ℝ≥0} {f : α →ₘ[μ] E} {g : Lp F p μ}
(h : ∀ᵐ x ∂μ, ‖f x‖₊ ≤ c * ‖g x‖₊) : f ∈ Lp E p μ :=
mem_Lp_iff_memℒp.2 <| Memℒp.of_nnnorm_le_mul (Lp.memℒp g) f.aestronglyMeasurable h
#align measure_theory.Lp.mem_Lp_of_nnnorm_ae_le_mul MeasureTheory.Lp.mem_Lp_of_nnnorm_ae_le_mul
theorem mem_Lp_of_ae_le_mul {c : ℝ} {f : α →ₘ[μ] E} {g : Lp F p μ}
(h : ∀ᵐ x ∂μ, ‖f x‖ ≤ c * ‖g x‖) : f ∈ Lp E p μ :=
mem_Lp_iff_memℒp.2 <| Memℒp.of_le_mul (Lp.memℒp g) f.aestronglyMeasurable h
#align measure_theory.Lp.mem_Lp_of_ae_le_mul MeasureTheory.Lp.mem_Lp_of_ae_le_mul
theorem mem_Lp_of_nnnorm_ae_le {f : α →ₘ[μ] E} {g : Lp F p μ} (h : ∀ᵐ x ∂μ, ‖f x‖₊ ≤ ‖g x‖₊) :
f ∈ Lp E p μ :=
mem_Lp_iff_memℒp.2 <| Memℒp.of_le (Lp.memℒp g) f.aestronglyMeasurable h
#align measure_theory.Lp.mem_Lp_of_nnnorm_ae_le MeasureTheory.Lp.mem_Lp_of_nnnorm_ae_le
theorem mem_Lp_of_ae_le {f : α →ₘ[μ] E} {g : Lp F p μ} (h : ∀ᵐ x ∂μ, ‖f x‖ ≤ ‖g x‖) :
f ∈ Lp E p μ :=
mem_Lp_of_nnnorm_ae_le h
#align measure_theory.Lp.mem_Lp_of_ae_le MeasureTheory.Lp.mem_Lp_of_ae_le
theorem mem_Lp_of_ae_nnnorm_bound [IsFiniteMeasure μ] {f : α →ₘ[μ] E} (C : ℝ≥0)
(hfC : ∀ᵐ x ∂μ, ‖f x‖₊ ≤ C) : f ∈ Lp E p μ :=
mem_Lp_iff_memℒp.2 <| Memℒp.of_bound f.aestronglyMeasurable _ hfC
#align measure_theory.Lp.mem_Lp_of_ae_nnnorm_bound MeasureTheory.Lp.mem_Lp_of_ae_nnnorm_bound
theorem mem_Lp_of_ae_bound [IsFiniteMeasure μ] {f : α →ₘ[μ] E} (C : ℝ) (hfC : ∀ᵐ x ∂μ, ‖f x‖ ≤ C) :
f ∈ Lp E p μ :=
mem_Lp_iff_memℒp.2 <| Memℒp.of_bound f.aestronglyMeasurable _ hfC
#align measure_theory.Lp.mem_Lp_of_ae_bound MeasureTheory.Lp.mem_Lp_of_ae_bound
theorem nnnorm_le_of_ae_bound [IsFiniteMeasure μ] {f : Lp E p μ} {C : ℝ≥0}
(hfC : ∀ᵐ x ∂μ, ‖f x‖₊ ≤ C) : ‖f‖₊ ≤ measureUnivNNReal μ ^ p.toReal⁻¹ * C := by
by_cases hμ : μ = 0
· by_cases hp : p.toReal⁻¹ = 0
· simp [hp, hμ, nnnorm_def]
· simp [hμ, nnnorm_def, Real.zero_rpow hp]
rw [← ENNReal.coe_le_coe, nnnorm_def, ENNReal.coe_toNNReal (snorm_ne_top _)]
refine (snorm_le_of_ae_nnnorm_bound hfC).trans_eq ?_
rw [← coe_measureUnivNNReal μ, ENNReal.coe_rpow_of_ne_zero (measureUnivNNReal_pos hμ).ne',
ENNReal.coe_mul, mul_comm, ENNReal.smul_def, smul_eq_mul]
#align measure_theory.Lp.nnnorm_le_of_ae_bound MeasureTheory.Lp.nnnorm_le_of_ae_bound
| Mathlib/MeasureTheory/Function/LpSpace.lean | 440 | 444 | theorem norm_le_of_ae_bound [IsFiniteMeasure μ] {f : Lp E p μ} {C : ℝ} (hC : 0 ≤ C)
(hfC : ∀ᵐ x ∂μ, ‖f x‖ ≤ C) : ‖f‖ ≤ measureUnivNNReal μ ^ p.toReal⁻¹ * C := by |
lift C to ℝ≥0 using hC
have := nnnorm_le_of_ae_bound hfC
rwa [← NNReal.coe_le_coe, NNReal.coe_mul, NNReal.coe_rpow] at this
|
/-
Copyright (c) 2017 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
-/
import Mathlib.Algebra.Order.Ring.Defs
import Mathlib.Algebra.Group.Int
import Mathlib.Data.Nat.Dist
import Mathlib.Data.Ordmap.Ordnode
import Mathlib.Tactic.Abel
import Mathlib.Tactic.Linarith
#align_import data.ordmap.ordset from "leanprover-community/mathlib"@"47b51515e69f59bca5cf34ef456e6000fe205a69"
/-!
# Verification of the `Ordnode α` datatype
This file proves the correctness of the operations in `Data.Ordmap.Ordnode`.
The public facing version is the type `Ordset α`, which is a wrapper around
`Ordnode α` which includes the correctness invariant of the type, and 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
* `Ordset α`: A well formed set of values of type `α`
## Implementation notes
The majority of this file is actually in the `Ordnode` namespace, because we first
have to prove the correctness of all the operations (and defining what correctness
means here is actually somewhat subtle). So all the actual `Ordset` operations are
at the very end, once we have all the theorems.
An `Ordnode α` is an inductive type which describes a tree which stores the `size` at
internal nodes. The correctness invariant of an `Ordnode α` is:
* `Ordnode.Sized t`: All internal `size` fields must match the actual measured
size of the tree. (This is not hard to satisfy.)
* `Ordnode.Balanced t`: Unless the tree has the form `()` or `((a) b)` or `(a (b))`
(that is, nil or a single singleton subtree), the two subtrees must satisfy
`size l ≤ δ * size r` and `size r ≤ δ * size l`, where `δ := 3` is a global
parameter of the data structure (and this property must hold recursively at subtrees).
This is why we say this is a "size balanced tree" data structure.
* `Ordnode.Bounded lo hi t`: The members of the tree must be in strictly increasing order,
meaning that if `a` is in the left subtree and `b` is the root, then `a ≤ b` and
`¬ (b ≤ a)`. We enforce this using `Ordnode.Bounded` which includes also a global
upper and lower bound.
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.
**Note:** This file is incomplete, in the sense that the intent is to have verified
versions and lemmas about all the definitions in `Ordnode.lean`, but at the moment only
a few operations are verified (the hard part should be out of the way, but still).
Contributors are encouraged to pick this up and finish the job, if it appeals to you.
## Tags
ordered map, ordered set, data structure, verified programming
-/
variable {α : Type*}
namespace Ordnode
/-! ### delta and ratio -/
theorem not_le_delta {s} (H : 1 ≤ s) : ¬s ≤ delta * 0 :=
not_le_of_gt H
#align ordnode.not_le_delta Ordnode.not_le_delta
theorem delta_lt_false {a b : ℕ} (h₁ : delta * a < b) (h₂ : delta * b < a) : False :=
not_le_of_lt (lt_trans ((mul_lt_mul_left (by decide)).2 h₁) h₂) <| by
simpa [mul_assoc] using Nat.mul_le_mul_right a (by decide : 1 ≤ delta * delta)
#align ordnode.delta_lt_false Ordnode.delta_lt_false
/-! ### `singleton` -/
/-! ### `size` and `empty` -/
/-- O(n). Computes the actual number of elements in the set, ignoring the cached `size` field. -/
def realSize : Ordnode α → ℕ
| nil => 0
| node _ l _ r => realSize l + realSize r + 1
#align ordnode.real_size Ordnode.realSize
/-! ### `Sized` -/
/-- The `Sized` property asserts that all the `size` fields in nodes match the actual size of the
respective subtrees. -/
def Sized : Ordnode α → Prop
| nil => True
| node s l _ r => s = size l + size r + 1 ∧ Sized l ∧ Sized r
#align ordnode.sized Ordnode.Sized
theorem Sized.node' {l x r} (hl : @Sized α l) (hr : Sized r) : Sized (node' l x r) :=
⟨rfl, hl, hr⟩
#align ordnode.sized.node' Ordnode.Sized.node'
theorem Sized.eq_node' {s l x r} (h : @Sized α (node s l x r)) : node s l x r = .node' l x r := by
rw [h.1]
#align ordnode.sized.eq_node' Ordnode.Sized.eq_node'
theorem Sized.size_eq {s l x r} (H : Sized (@node α s l x r)) :
size (@node α s l x r) = size l + size r + 1 :=
H.1
#align ordnode.sized.size_eq Ordnode.Sized.size_eq
@[elab_as_elim]
theorem Sized.induction {t} (hl : @Sized α t) {C : Ordnode α → Prop} (H0 : C nil)
(H1 : ∀ l x r, C l → C r → C (.node' l x r)) : C t := by
induction t with
| nil => exact H0
| node _ _ _ _ t_ih_l t_ih_r =>
rw [hl.eq_node']
exact H1 _ _ _ (t_ih_l hl.2.1) (t_ih_r hl.2.2)
#align ordnode.sized.induction Ordnode.Sized.induction
theorem size_eq_realSize : ∀ {t : Ordnode α}, Sized t → size t = realSize t
| nil, _ => rfl
| node s l x r, ⟨h₁, h₂, h₃⟩ => by
rw [size, h₁, size_eq_realSize h₂, size_eq_realSize h₃]; rfl
#align ordnode.size_eq_real_size Ordnode.size_eq_realSize
@[simp]
theorem Sized.size_eq_zero {t : Ordnode α} (ht : Sized t) : size t = 0 ↔ t = nil := by
cases t <;> [simp;simp [ht.1]]
#align ordnode.sized.size_eq_zero Ordnode.Sized.size_eq_zero
theorem Sized.pos {s l x r} (h : Sized (@node α s l x r)) : 0 < s := by
rw [h.1]; apply Nat.le_add_left
#align ordnode.sized.pos Ordnode.Sized.pos
/-! `dual` -/
theorem dual_dual : ∀ t : Ordnode α, dual (dual t) = t
| nil => rfl
| node s l x r => by rw [dual, dual, dual_dual l, dual_dual r]
#align ordnode.dual_dual Ordnode.dual_dual
@[simp]
theorem size_dual (t : Ordnode α) : size (dual t) = size t := by cases t <;> rfl
#align ordnode.size_dual Ordnode.size_dual
/-! `Balanced` -/
/-- The `BalancedSz l r` asserts that a hypothetical tree with children of sizes `l` and `r` is
balanced: either `l ≤ δ * r` and `r ≤ δ * r`, or the tree is trivial with a singleton on one side
and nothing on the other. -/
def BalancedSz (l r : ℕ) : Prop :=
l + r ≤ 1 ∨ l ≤ delta * r ∧ r ≤ delta * l
#align ordnode.balanced_sz Ordnode.BalancedSz
instance BalancedSz.dec : DecidableRel BalancedSz := fun _ _ => Or.decidable
#align ordnode.balanced_sz.dec Ordnode.BalancedSz.dec
/-- The `Balanced t` asserts that the tree `t` satisfies the balance invariants
(at every level). -/
def Balanced : Ordnode α → Prop
| nil => True
| node _ l _ r => BalancedSz (size l) (size r) ∧ Balanced l ∧ Balanced r
#align ordnode.balanced Ordnode.Balanced
instance Balanced.dec : DecidablePred (@Balanced α)
| nil => by
unfold Balanced
infer_instance
| node _ l _ r => by
unfold Balanced
haveI := Balanced.dec l
haveI := Balanced.dec r
infer_instance
#align ordnode.balanced.dec Ordnode.Balanced.dec
@[symm]
theorem BalancedSz.symm {l r : ℕ} : BalancedSz l r → BalancedSz r l :=
Or.imp (by rw [add_comm]; exact id) And.symm
#align ordnode.balanced_sz.symm Ordnode.BalancedSz.symm
theorem balancedSz_zero {l : ℕ} : BalancedSz l 0 ↔ l ≤ 1 := by
simp (config := { contextual := true }) [BalancedSz]
#align ordnode.balanced_sz_zero Ordnode.balancedSz_zero
theorem balancedSz_up {l r₁ r₂ : ℕ} (h₁ : r₁ ≤ r₂) (h₂ : l + r₂ ≤ 1 ∨ r₂ ≤ delta * l)
(H : BalancedSz l r₁) : BalancedSz l r₂ := by
refine or_iff_not_imp_left.2 fun h => ?_
refine ⟨?_, h₂.resolve_left h⟩
cases H with
| inl H =>
cases r₂
· cases h (le_trans (Nat.add_le_add_left (Nat.zero_le _) _) H)
· exact le_trans (le_trans (Nat.le_add_right _ _) H) (Nat.le_add_left 1 _)
| inr H =>
exact le_trans H.1 (Nat.mul_le_mul_left _ h₁)
#align ordnode.balanced_sz_up Ordnode.balancedSz_up
theorem balancedSz_down {l r₁ r₂ : ℕ} (h₁ : r₁ ≤ r₂) (h₂ : l + r₂ ≤ 1 ∨ l ≤ delta * r₁)
(H : BalancedSz l r₂) : BalancedSz l r₁ :=
have : l + r₂ ≤ 1 → BalancedSz l r₁ := fun H => Or.inl (le_trans (Nat.add_le_add_left h₁ _) H)
Or.casesOn H this fun H => Or.casesOn h₂ this fun h₂ => Or.inr ⟨h₂, le_trans h₁ H.2⟩
#align ordnode.balanced_sz_down Ordnode.balancedSz_down
theorem Balanced.dual : ∀ {t : Ordnode α}, Balanced t → Balanced (dual t)
| nil, _ => ⟨⟩
| node _ l _ r, ⟨b, bl, br⟩ => ⟨by rw [size_dual, size_dual]; exact b.symm, br.dual, bl.dual⟩
#align ordnode.balanced.dual Ordnode.Balanced.dual
/-! ### `rotate` and `balance` -/
/-- Build a tree from three nodes, left associated (ignores the invariants). -/
def node3L (l : Ordnode α) (x : α) (m : Ordnode α) (y : α) (r : Ordnode α) : Ordnode α :=
node' (node' l x m) y r
#align ordnode.node3_l Ordnode.node3L
/-- Build a tree from three nodes, right associated (ignores the invariants). -/
def node3R (l : Ordnode α) (x : α) (m : Ordnode α) (y : α) (r : Ordnode α) : Ordnode α :=
node' l x (node' m y r)
#align ordnode.node3_r Ordnode.node3R
/-- Build a tree from three nodes, with `a () b -> (a ()) b` and `a (b c) d -> ((a b) (c d))`. -/
def node4L : Ordnode α → α → Ordnode α → α → Ordnode α → Ordnode α
| l, x, node _ ml y mr, z, r => node' (node' l x ml) y (node' mr z r)
| l, x, nil, z, r => node3L l x nil z r
#align ordnode.node4_l Ordnode.node4L
-- should not happen
/-- Build a tree from three nodes, with `a () b -> a (() b)` and `a (b c) d -> ((a b) (c d))`. -/
def node4R : Ordnode α → α → Ordnode α → α → Ordnode α → Ordnode α
| l, x, node _ ml y mr, z, r => node' (node' l x ml) y (node' mr z r)
| l, x, nil, z, r => node3R l x nil z r
#align ordnode.node4_r Ordnode.node4R
-- should not happen
/-- Concatenate two nodes, performing a left rotation `x (y z) -> ((x y) z)`
if balance is upset. -/
def rotateL : Ordnode α → α → Ordnode α → Ordnode α
| l, x, node _ m y r => if size m < ratio * size r then node3L l x m y r else node4L l x m y r
| l, x, nil => node' l x nil
#align ordnode.rotate_l Ordnode.rotateL
-- Porting note (#11467): during the port we marked these lemmas with `@[eqns]`
-- to emulate the old Lean 3 behaviour.
theorem rotateL_node (l : Ordnode α) (x : α) (sz : ℕ) (m : Ordnode α) (y : α) (r : Ordnode α) :
rotateL l x (node sz m y r) =
if size m < ratio * size r then node3L l x m y r else node4L l x m y r :=
rfl
theorem rotateL_nil (l : Ordnode α) (x : α) : rotateL l x nil = node' l x nil :=
rfl
-- should not happen
/-- Concatenate two nodes, performing a right rotation `(x y) z -> (x (y z))`
if balance is upset. -/
def rotateR : Ordnode α → α → Ordnode α → Ordnode α
| node _ l x m, y, r => if size m < ratio * size l then node3R l x m y r else node4R l x m y r
| nil, y, r => node' nil y r
#align ordnode.rotate_r Ordnode.rotateR
-- Porting note (#11467): during the port we marked these lemmas with `@[eqns]`
-- to emulate the old Lean 3 behaviour.
theorem rotateR_node (sz : ℕ) (l : Ordnode α) (x : α) (m : Ordnode α) (y : α) (r : Ordnode α) :
rotateR (node sz l x m) y r =
if size m < ratio * size l then node3R l x m y r else node4R l x m y r :=
rfl
theorem rotateR_nil (y : α) (r : Ordnode α) : rotateR nil y r = node' nil y r :=
rfl
-- should not happen
/-- A left balance operation. This will rebalance a concatenation, assuming the original nodes are
not too far from balanced. -/
def balanceL' (l : Ordnode α) (x : α) (r : Ordnode α) : Ordnode α :=
if size l + size r ≤ 1 then node' l x r
else if size l > delta * size r then rotateR l x r else node' l x r
#align ordnode.balance_l' Ordnode.balanceL'
/-- A right balance operation. This will rebalance a concatenation, assuming the original nodes are
not too far from balanced. -/
def balanceR' (l : Ordnode α) (x : α) (r : Ordnode α) : Ordnode α :=
if size l + size r ≤ 1 then node' l x r
else if size r > delta * size l then rotateL l x r else node' l x r
#align ordnode.balance_r' Ordnode.balanceR'
/-- The full balance operation. This is the same as `balance`, but with less manual inlining.
It is somewhat easier to work with this version in proofs. -/
def balance' (l : Ordnode α) (x : α) (r : Ordnode α) : Ordnode α :=
if size l + size r ≤ 1 then node' l x r
else
if size r > delta * size l then rotateL l x r
else if size l > delta * size r then rotateR l x r else node' l x r
#align ordnode.balance' Ordnode.balance'
theorem dual_node' (l : Ordnode α) (x : α) (r : Ordnode α) :
dual (node' l x r) = node' (dual r) x (dual l) := by simp [node', add_comm]
#align ordnode.dual_node' Ordnode.dual_node'
theorem dual_node3L (l : Ordnode α) (x : α) (m : Ordnode α) (y : α) (r : Ordnode α) :
dual (node3L l x m y r) = node3R (dual r) y (dual m) x (dual l) := by
simp [node3L, node3R, dual_node', add_comm]
#align ordnode.dual_node3_l Ordnode.dual_node3L
theorem dual_node3R (l : Ordnode α) (x : α) (m : Ordnode α) (y : α) (r : Ordnode α) :
dual (node3R l x m y r) = node3L (dual r) y (dual m) x (dual l) := by
simp [node3L, node3R, dual_node', add_comm]
#align ordnode.dual_node3_r Ordnode.dual_node3R
theorem dual_node4L (l : Ordnode α) (x : α) (m : Ordnode α) (y : α) (r : Ordnode α) :
dual (node4L l x m y r) = node4R (dual r) y (dual m) x (dual l) := by
cases m <;> simp [node4L, node4R, node3R, dual_node3L, dual_node', add_comm]
#align ordnode.dual_node4_l Ordnode.dual_node4L
theorem dual_node4R (l : Ordnode α) (x : α) (m : Ordnode α) (y : α) (r : Ordnode α) :
dual (node4R l x m y r) = node4L (dual r) y (dual m) x (dual l) := by
cases m <;> simp [node4L, node4R, node3L, dual_node3R, dual_node', add_comm]
#align ordnode.dual_node4_r Ordnode.dual_node4R
theorem dual_rotateL (l : Ordnode α) (x : α) (r : Ordnode α) :
dual (rotateL l x r) = rotateR (dual r) x (dual l) := by
cases r <;> simp [rotateL, rotateR, dual_node']; split_ifs <;>
simp [dual_node3L, dual_node4L, node3R, add_comm]
#align ordnode.dual_rotate_l Ordnode.dual_rotateL
theorem dual_rotateR (l : Ordnode α) (x : α) (r : Ordnode α) :
dual (rotateR l x r) = rotateL (dual r) x (dual l) := by
rw [← dual_dual (rotateL _ _ _), dual_rotateL, dual_dual, dual_dual]
#align ordnode.dual_rotate_r Ordnode.dual_rotateR
theorem dual_balance' (l : Ordnode α) (x : α) (r : Ordnode α) :
dual (balance' l x r) = balance' (dual r) x (dual l) := by
simp [balance', add_comm]; split_ifs with h h_1 h_2 <;>
simp [dual_node', dual_rotateL, dual_rotateR, add_comm]
cases delta_lt_false h_1 h_2
#align ordnode.dual_balance' Ordnode.dual_balance'
theorem dual_balanceL (l : Ordnode α) (x : α) (r : Ordnode α) :
dual (balanceL l x r) = balanceR (dual r) x (dual l) := by
unfold balanceL balanceR
cases' r with rs rl rx rr
· cases' l with ls ll lx lr; · rfl
cases' ll with lls lll llx llr <;> cases' lr with lrs lrl lrx lrr <;> dsimp only [dual, id] <;>
try rfl
split_ifs with h <;> repeat simp [h, add_comm]
· cases' l with ls ll lx lr; · rfl
dsimp only [dual, id]
split_ifs; swap; · simp [add_comm]
cases' ll with lls lll llx llr <;> cases' lr with lrs lrl lrx lrr <;> try rfl
dsimp only [dual, id]
split_ifs with h <;> simp [h, add_comm]
#align ordnode.dual_balance_l Ordnode.dual_balanceL
theorem dual_balanceR (l : Ordnode α) (x : α) (r : Ordnode α) :
dual (balanceR l x r) = balanceL (dual r) x (dual l) := by
rw [← dual_dual (balanceL _ _ _), dual_balanceL, dual_dual, dual_dual]
#align ordnode.dual_balance_r Ordnode.dual_balanceR
theorem Sized.node3L {l x m y r} (hl : @Sized α l) (hm : Sized m) (hr : Sized r) :
Sized (node3L l x m y r) :=
(hl.node' hm).node' hr
#align ordnode.sized.node3_l Ordnode.Sized.node3L
theorem Sized.node3R {l x m y r} (hl : @Sized α l) (hm : Sized m) (hr : Sized r) :
Sized (node3R l x m y r) :=
hl.node' (hm.node' hr)
#align ordnode.sized.node3_r Ordnode.Sized.node3R
theorem Sized.node4L {l x m y r} (hl : @Sized α l) (hm : Sized m) (hr : Sized r) :
Sized (node4L l x m y r) := by
cases m <;> [exact (hl.node' hm).node' hr; exact (hl.node' hm.2.1).node' (hm.2.2.node' hr)]
#align ordnode.sized.node4_l Ordnode.Sized.node4L
theorem node3L_size {l x m y r} : size (@node3L α l x m y r) = size l + size m + size r + 2 := by
dsimp [node3L, node', size]; rw [add_right_comm _ 1]
#align ordnode.node3_l_size Ordnode.node3L_size
theorem node3R_size {l x m y r} : size (@node3R α l x m y r) = size l + size m + size r + 2 := by
dsimp [node3R, node', size]; rw [← add_assoc, ← add_assoc]
#align ordnode.node3_r_size Ordnode.node3R_size
theorem node4L_size {l x m y r} (hm : Sized m) :
size (@node4L α l x m y r) = size l + size m + size r + 2 := by
cases m <;> simp [node4L, node3L, node'] <;> [abel; (simp [size, hm.1]; abel)]
#align ordnode.node4_l_size Ordnode.node4L_size
theorem Sized.dual : ∀ {t : Ordnode α}, Sized t → Sized (dual t)
| nil, _ => ⟨⟩
| node _ l _ r, ⟨rfl, sl, sr⟩ => ⟨by simp [size_dual, add_comm], Sized.dual sr, Sized.dual sl⟩
#align ordnode.sized.dual Ordnode.Sized.dual
theorem Sized.dual_iff {t : Ordnode α} : Sized (.dual t) ↔ Sized t :=
⟨fun h => by rw [← dual_dual t]; exact h.dual, Sized.dual⟩
#align ordnode.sized.dual_iff Ordnode.Sized.dual_iff
theorem Sized.rotateL {l x r} (hl : @Sized α l) (hr : Sized r) : Sized (rotateL l x r) := by
cases r; · exact hl.node' hr
rw [Ordnode.rotateL_node]; split_ifs
· exact hl.node3L hr.2.1 hr.2.2
· exact hl.node4L hr.2.1 hr.2.2
#align ordnode.sized.rotate_l Ordnode.Sized.rotateL
theorem Sized.rotateR {l x r} (hl : @Sized α l) (hr : Sized r) : Sized (rotateR l x r) :=
Sized.dual_iff.1 <| by rw [dual_rotateR]; exact hr.dual.rotateL hl.dual
#align ordnode.sized.rotate_r Ordnode.Sized.rotateR
theorem Sized.rotateL_size {l x r} (hm : Sized r) :
size (@Ordnode.rotateL α l x r) = size l + size r + 1 := by
cases r <;> simp [Ordnode.rotateL]
simp only [hm.1]
split_ifs <;> simp [node3L_size, node4L_size hm.2.1] <;> abel
#align ordnode.sized.rotate_l_size Ordnode.Sized.rotateL_size
theorem Sized.rotateR_size {l x r} (hl : Sized l) :
size (@Ordnode.rotateR α l x r) = size l + size r + 1 := by
rw [← size_dual, dual_rotateR, hl.dual.rotateL_size, size_dual, size_dual, add_comm (size l)]
#align ordnode.sized.rotate_r_size Ordnode.Sized.rotateR_size
theorem Sized.balance' {l x r} (hl : @Sized α l) (hr : Sized r) : Sized (balance' l x r) := by
unfold balance'; split_ifs
· exact hl.node' hr
· exact hl.rotateL hr
· exact hl.rotateR hr
· exact hl.node' hr
#align ordnode.sized.balance' Ordnode.Sized.balance'
theorem size_balance' {l x r} (hl : @Sized α l) (hr : Sized r) :
size (@balance' α l x r) = size l + size r + 1 := by
unfold balance'; split_ifs
· rfl
· exact hr.rotateL_size
· exact hl.rotateR_size
· rfl
#align ordnode.size_balance' Ordnode.size_balance'
/-! ## `All`, `Any`, `Emem`, `Amem` -/
theorem All.imp {P Q : α → Prop} (H : ∀ a, P a → Q a) : ∀ {t}, All P t → All Q t
| nil, _ => ⟨⟩
| node _ _ _ _, ⟨h₁, h₂, h₃⟩ => ⟨h₁.imp H, H _ h₂, h₃.imp H⟩
#align ordnode.all.imp Ordnode.All.imp
theorem Any.imp {P Q : α → Prop} (H : ∀ a, P a → Q a) : ∀ {t}, Any P t → Any Q t
| nil => id
| node _ _ _ _ => Or.imp (Any.imp H) <| Or.imp (H _) (Any.imp H)
#align ordnode.any.imp Ordnode.Any.imp
theorem all_singleton {P : α → Prop} {x : α} : All P (singleton x) ↔ P x :=
⟨fun h => h.2.1, fun h => ⟨⟨⟩, h, ⟨⟩⟩⟩
#align ordnode.all_singleton Ordnode.all_singleton
theorem any_singleton {P : α → Prop} {x : α} : Any P (singleton x) ↔ P x :=
⟨by rintro (⟨⟨⟩⟩ | h | ⟨⟨⟩⟩); exact h, fun h => Or.inr (Or.inl h)⟩
#align ordnode.any_singleton Ordnode.any_singleton
theorem all_dual {P : α → Prop} : ∀ {t : Ordnode α}, All P (dual t) ↔ All P t
| nil => Iff.rfl
| node _ _l _x _r =>
⟨fun ⟨hr, hx, hl⟩ => ⟨all_dual.1 hl, hx, all_dual.1 hr⟩, fun ⟨hl, hx, hr⟩ =>
⟨all_dual.2 hr, hx, all_dual.2 hl⟩⟩
#align ordnode.all_dual Ordnode.all_dual
theorem all_iff_forall {P : α → Prop} : ∀ {t}, All P t ↔ ∀ x, Emem x t → P x
| nil => (iff_true_intro <| by rintro _ ⟨⟩).symm
| node _ l x r => by simp [All, Emem, all_iff_forall, Any, or_imp, forall_and]
#align ordnode.all_iff_forall Ordnode.all_iff_forall
theorem any_iff_exists {P : α → Prop} : ∀ {t}, Any P t ↔ ∃ x, Emem x t ∧ P x
| nil => ⟨by rintro ⟨⟩, by rintro ⟨_, ⟨⟩, _⟩⟩
| node _ l x r => by simp only [Emem]; simp [Any, any_iff_exists, or_and_right, exists_or]
#align ordnode.any_iff_exists Ordnode.any_iff_exists
theorem emem_iff_all {x : α} {t} : Emem x t ↔ ∀ P, All P t → P x :=
⟨fun h _ al => all_iff_forall.1 al _ h, fun H => H _ <| all_iff_forall.2 fun _ => id⟩
#align ordnode.emem_iff_all Ordnode.emem_iff_all
theorem all_node' {P l x r} : @All α P (node' l x r) ↔ All P l ∧ P x ∧ All P r :=
Iff.rfl
#align ordnode.all_node' Ordnode.all_node'
theorem all_node3L {P l x m y r} :
@All α P (node3L l x m y r) ↔ All P l ∧ P x ∧ All P m ∧ P y ∧ All P r := by
simp [node3L, all_node', and_assoc]
#align ordnode.all_node3_l Ordnode.all_node3L
theorem all_node3R {P l x m y r} :
@All α P (node3R l x m y r) ↔ All P l ∧ P x ∧ All P m ∧ P y ∧ All P r :=
Iff.rfl
#align ordnode.all_node3_r Ordnode.all_node3R
theorem all_node4L {P l x m y r} :
@All α P (node4L l x m y r) ↔ All P l ∧ P x ∧ All P m ∧ P y ∧ All P r := by
cases m <;> simp [node4L, all_node', All, all_node3L, and_assoc]
#align ordnode.all_node4_l Ordnode.all_node4L
theorem all_node4R {P l x m y r} :
@All α P (node4R l x m y r) ↔ All P l ∧ P x ∧ All P m ∧ P y ∧ All P r := by
cases m <;> simp [node4R, all_node', All, all_node3R, and_assoc]
#align ordnode.all_node4_r Ordnode.all_node4R
theorem all_rotateL {P l x r} : @All α P (rotateL l x r) ↔ All P l ∧ P x ∧ All P r := by
cases r <;> simp [rotateL, all_node']; split_ifs <;>
simp [all_node3L, all_node4L, All, and_assoc]
#align ordnode.all_rotate_l Ordnode.all_rotateL
theorem all_rotateR {P l x r} : @All α P (rotateR l x r) ↔ All P l ∧ P x ∧ All P r := by
rw [← all_dual, dual_rotateR, all_rotateL]; simp [all_dual, and_comm, and_left_comm, and_assoc]
#align ordnode.all_rotate_r Ordnode.all_rotateR
theorem all_balance' {P l x r} : @All α P (balance' l x r) ↔ All P l ∧ P x ∧ All P r := by
rw [balance']; split_ifs <;> simp [all_node', all_rotateL, all_rotateR]
#align ordnode.all_balance' Ordnode.all_balance'
/-! ### `toList` -/
theorem foldr_cons_eq_toList : ∀ (t : Ordnode α) (r : List α), t.foldr List.cons r = toList t ++ r
| nil, r => rfl
| node _ l x r, r' => by
rw [foldr, foldr_cons_eq_toList l, foldr_cons_eq_toList r, ← List.cons_append,
← List.append_assoc, ← foldr_cons_eq_toList l]; rfl
#align ordnode.foldr_cons_eq_to_list Ordnode.foldr_cons_eq_toList
@[simp]
theorem toList_nil : toList (@nil α) = [] :=
rfl
#align ordnode.to_list_nil Ordnode.toList_nil
@[simp]
theorem toList_node (s l x r) : toList (@node α s l x r) = toList l ++ x :: toList r := by
rw [toList, foldr, foldr_cons_eq_toList]; rfl
#align ordnode.to_list_node Ordnode.toList_node
theorem emem_iff_mem_toList {x : α} {t} : Emem x t ↔ x ∈ toList t := by
unfold Emem; induction t <;> simp [Any, *, or_assoc]
#align ordnode.emem_iff_mem_to_list Ordnode.emem_iff_mem_toList
theorem length_toList' : ∀ t : Ordnode α, (toList t).length = t.realSize
| nil => rfl
| node _ l _ r => by
rw [toList_node, List.length_append, List.length_cons, length_toList' l,
length_toList' r]; rfl
#align ordnode.length_to_list' Ordnode.length_toList'
theorem length_toList {t : Ordnode α} (h : Sized t) : (toList t).length = t.size := by
rw [length_toList', size_eq_realSize h]
#align ordnode.length_to_list Ordnode.length_toList
theorem equiv_iff {t₁ t₂ : Ordnode α} (h₁ : Sized t₁) (h₂ : Sized t₂) :
Equiv t₁ t₂ ↔ toList t₁ = toList t₂ :=
and_iff_right_of_imp fun h => by rw [← length_toList h₁, h, length_toList h₂]
#align ordnode.equiv_iff Ordnode.equiv_iff
/-! ### `mem` -/
theorem pos_size_of_mem [LE α] [@DecidableRel α (· ≤ ·)] {x : α} {t : Ordnode α} (h : Sized t)
(h_mem : x ∈ t) : 0 < size t := by cases t; · { contradiction }; · { simp [h.1] }
#align ordnode.pos_size_of_mem Ordnode.pos_size_of_mem
/-! ### `(find/erase/split)(Min/Max)` -/
theorem findMin'_dual : ∀ (t) (x : α), findMin' (dual t) x = findMax' x t
| nil, _ => rfl
| node _ _ x r, _ => findMin'_dual r x
#align ordnode.find_min'_dual Ordnode.findMin'_dual
theorem findMax'_dual (t) (x : α) : findMax' x (dual t) = findMin' t x := by
rw [← findMin'_dual, dual_dual]
#align ordnode.find_max'_dual Ordnode.findMax'_dual
theorem findMin_dual : ∀ t : Ordnode α, findMin (dual t) = findMax t
| nil => rfl
| node _ _ _ _ => congr_arg some <| findMin'_dual _ _
#align ordnode.find_min_dual Ordnode.findMin_dual
theorem findMax_dual (t : Ordnode α) : findMax (dual t) = findMin t := by
rw [← findMin_dual, dual_dual]
#align ordnode.find_max_dual Ordnode.findMax_dual
theorem dual_eraseMin : ∀ t : Ordnode α, dual (eraseMin t) = eraseMax (dual t)
| nil => rfl
| node _ nil x r => rfl
| node _ (node sz l' y r') x r => by
rw [eraseMin, dual_balanceR, dual_eraseMin (node sz l' y r'), dual, dual, dual, eraseMax]
#align ordnode.dual_erase_min Ordnode.dual_eraseMin
theorem dual_eraseMax (t : Ordnode α) : dual (eraseMax t) = eraseMin (dual t) := by
rw [← dual_dual (eraseMin _), dual_eraseMin, dual_dual]
#align ordnode.dual_erase_max Ordnode.dual_eraseMax
theorem splitMin_eq :
∀ (s l) (x : α) (r), splitMin' l x r = (findMin' l x, eraseMin (node s l x r))
| _, nil, x, r => rfl
| _, node ls ll lx lr, x, r => by rw [splitMin', splitMin_eq ls ll lx lr, findMin', eraseMin]
#align ordnode.split_min_eq Ordnode.splitMin_eq
theorem splitMax_eq :
∀ (s l) (x : α) (r), splitMax' l x r = (eraseMax (node s l x r), findMax' x r)
| _, l, x, nil => rfl
| _, l, x, node ls ll lx lr => by rw [splitMax', splitMax_eq ls ll lx lr, findMax', eraseMax]
#align ordnode.split_max_eq Ordnode.splitMax_eq
-- @[elab_as_elim] -- Porting note: unexpected eliminator resulting type
theorem findMin'_all {P : α → Prop} : ∀ (t) (x : α), All P t → P x → P (findMin' t x)
| nil, _x, _, hx => hx
| node _ ll lx _, _, ⟨h₁, h₂, _⟩, _ => findMin'_all ll lx h₁ h₂
#align ordnode.find_min'_all Ordnode.findMin'_all
-- @[elab_as_elim] -- Porting note: unexpected eliminator resulting type
theorem findMax'_all {P : α → Prop} : ∀ (x : α) (t), P x → All P t → P (findMax' x t)
| _x, nil, hx, _ => hx
| _, node _ _ lx lr, _, ⟨_, h₂, h₃⟩ => findMax'_all lx lr h₂ h₃
#align ordnode.find_max'_all Ordnode.findMax'_all
/-! ### `glue` -/
/-! ### `merge` -/
@[simp]
theorem merge_nil_left (t : Ordnode α) : merge t nil = t := by cases t <;> rfl
#align ordnode.merge_nil_left Ordnode.merge_nil_left
@[simp]
theorem merge_nil_right (t : Ordnode α) : merge nil t = t :=
rfl
#align ordnode.merge_nil_right Ordnode.merge_nil_right
@[simp]
theorem merge_node {ls ll lx lr rs rl rx rr} :
merge (@node α ls ll lx lr) (node rs rl rx rr) =
if delta * ls < rs then balanceL (merge (node ls ll lx lr) rl) rx rr
else if delta * rs < ls then balanceR ll lx (merge lr (node rs rl rx rr))
else glue (node ls ll lx lr) (node rs rl rx rr) :=
rfl
#align ordnode.merge_node Ordnode.merge_node
/-! ### `insert` -/
theorem dual_insert [Preorder α] [IsTotal α (· ≤ ·)] [@DecidableRel α (· ≤ ·)] (x : α) :
∀ t : Ordnode α, dual (Ordnode.insert x t) = @Ordnode.insert αᵒᵈ _ _ x (dual t)
| nil => rfl
| node _ l y r => by
have : @cmpLE αᵒᵈ _ _ x y = cmpLE y x := rfl
rw [Ordnode.insert, dual, Ordnode.insert, this, ← cmpLE_swap x y]
cases cmpLE x y <;>
simp [Ordering.swap, Ordnode.insert, dual_balanceL, dual_balanceR, dual_insert]
#align ordnode.dual_insert Ordnode.dual_insert
/-! ### `balance` properties -/
theorem balance_eq_balance' {l x r} (hl : Balanced l) (hr : Balanced r) (sl : Sized l)
(sr : Sized r) : @balance α l x r = balance' l x r := by
cases' l with ls ll lx lr
· cases' r with rs rl rx rr
· rfl
· rw [sr.eq_node'] at hr ⊢
cases' rl with rls rll rlx rlr <;> cases' rr with rrs rrl rrx rrr <;>
dsimp [balance, balance']
· rfl
· have : size rrl = 0 ∧ size rrr = 0 := by
have := balancedSz_zero.1 hr.1.symm
rwa [size, sr.2.2.1, Nat.succ_le_succ_iff, Nat.le_zero, add_eq_zero_iff] at this
cases sr.2.2.2.1.size_eq_zero.1 this.1
cases sr.2.2.2.2.size_eq_zero.1 this.2
obtain rfl : rrs = 1 := sr.2.2.1
rw [if_neg, if_pos, rotateL_node, if_pos]; · rfl
all_goals dsimp only [size]; decide
· have : size rll = 0 ∧ size rlr = 0 := by
have := balancedSz_zero.1 hr.1
rwa [size, sr.2.1.1, Nat.succ_le_succ_iff, Nat.le_zero, add_eq_zero_iff] at this
cases sr.2.1.2.1.size_eq_zero.1 this.1
cases sr.2.1.2.2.size_eq_zero.1 this.2
obtain rfl : rls = 1 := sr.2.1.1
rw [if_neg, if_pos, rotateL_node, if_neg]; · rfl
all_goals dsimp only [size]; decide
· symm; rw [zero_add, if_neg, if_pos, rotateL]
· dsimp only [size_node]; split_ifs
· simp [node3L, node']; abel
· simp [node4L, node', sr.2.1.1]; abel
· apply Nat.zero_lt_succ
· exact not_le_of_gt (Nat.succ_lt_succ (add_pos sr.2.1.pos sr.2.2.pos))
· cases' r with rs rl rx rr
· rw [sl.eq_node'] at hl ⊢
cases' ll with lls lll llx llr <;> cases' lr with lrs lrl lrx lrr <;>
dsimp [balance, balance']
· rfl
· have : size lrl = 0 ∧ size lrr = 0 := by
have := balancedSz_zero.1 hl.1.symm
rwa [size, sl.2.2.1, Nat.succ_le_succ_iff, Nat.le_zero, add_eq_zero_iff] at this
cases sl.2.2.2.1.size_eq_zero.1 this.1
cases sl.2.2.2.2.size_eq_zero.1 this.2
obtain rfl : lrs = 1 := sl.2.2.1
rw [if_neg, if_neg, if_pos, rotateR_node, if_neg]; · rfl
all_goals dsimp only [size]; decide
· have : size lll = 0 ∧ size llr = 0 := by
have := balancedSz_zero.1 hl.1
rwa [size, sl.2.1.1, Nat.succ_le_succ_iff, Nat.le_zero, add_eq_zero_iff] at this
cases sl.2.1.2.1.size_eq_zero.1 this.1
cases sl.2.1.2.2.size_eq_zero.1 this.2
obtain rfl : lls = 1 := sl.2.1.1
rw [if_neg, if_neg, if_pos, rotateR_node, if_pos]; · rfl
all_goals dsimp only [size]; decide
· symm; rw [if_neg, if_neg, if_pos, rotateR]
· dsimp only [size_node]; split_ifs
· simp [node3R, node']; abel
· simp [node4R, node', sl.2.2.1]; abel
· apply Nat.zero_lt_succ
· apply Nat.not_lt_zero
· exact not_le_of_gt (Nat.succ_lt_succ (add_pos sl.2.1.pos sl.2.2.pos))
· simp [balance, balance']
symm; rw [if_neg]
· split_ifs with h h_1
· have rd : delta ≤ size rl + size rr := by
have := lt_of_le_of_lt (Nat.mul_le_mul_left _ sl.pos) h
rwa [sr.1, Nat.lt_succ_iff] at this
cases' rl with rls rll rlx rlr
· rw [size, zero_add] at rd
exact absurd (le_trans rd (balancedSz_zero.1 hr.1.symm)) (by decide)
cases' rr with rrs rrl rrx rrr
· exact absurd (le_trans rd (balancedSz_zero.1 hr.1)) (by decide)
dsimp [rotateL]; split_ifs
· simp [node3L, node', sr.1]; abel
· simp [node4L, node', sr.1, sr.2.1.1]; abel
· have ld : delta ≤ size ll + size lr := by
have := lt_of_le_of_lt (Nat.mul_le_mul_left _ sr.pos) h_1
rwa [sl.1, Nat.lt_succ_iff] at this
cases' ll with lls lll llx llr
· rw [size, zero_add] at ld
exact absurd (le_trans ld (balancedSz_zero.1 hl.1.symm)) (by decide)
cases' lr with lrs lrl lrx lrr
· exact absurd (le_trans ld (balancedSz_zero.1 hl.1)) (by decide)
dsimp [rotateR]; split_ifs
· simp [node3R, node', sl.1]; abel
· simp [node4R, node', sl.1, sl.2.2.1]; abel
· simp [node']
· exact not_le_of_gt (add_le_add (Nat.succ_le_of_lt sl.pos) (Nat.succ_le_of_lt sr.pos))
#align ordnode.balance_eq_balance' Ordnode.balance_eq_balance'
theorem balanceL_eq_balance {l x r} (sl : Sized l) (sr : Sized r) (H1 : size l = 0 → size r ≤ 1)
(H2 : 1 ≤ size l → 1 ≤ size r → size r ≤ delta * size l) :
@balanceL α l x r = balance l x r := by
cases' r with rs rl rx rr
· rfl
· cases' l with ls ll lx lr
· have : size rl = 0 ∧ size rr = 0 := by
have := H1 rfl
rwa [size, sr.1, Nat.succ_le_succ_iff, Nat.le_zero, add_eq_zero_iff] at this
cases sr.2.1.size_eq_zero.1 this.1
cases sr.2.2.size_eq_zero.1 this.2
rw [sr.eq_node']; rfl
· replace H2 : ¬rs > delta * ls := not_lt_of_le (H2 sl.pos sr.pos)
simp [balanceL, balance, H2]; split_ifs <;> simp [add_comm]
#align ordnode.balance_l_eq_balance Ordnode.balanceL_eq_balance
/-- `Raised n m` means `m` is either equal or one up from `n`. -/
def Raised (n m : ℕ) : Prop :=
m = n ∨ m = n + 1
#align ordnode.raised Ordnode.Raised
theorem raised_iff {n m} : Raised n m ↔ n ≤ m ∧ m ≤ n + 1 := by
constructor
· rintro (rfl | rfl)
· exact ⟨le_rfl, Nat.le_succ _⟩
· exact ⟨Nat.le_succ _, le_rfl⟩
· rintro ⟨h₁, h₂⟩
rcases eq_or_lt_of_le h₁ with (rfl | h₁)
· exact Or.inl rfl
· exact Or.inr (le_antisymm h₂ h₁)
#align ordnode.raised_iff Ordnode.raised_iff
theorem Raised.dist_le {n m} (H : Raised n m) : Nat.dist n m ≤ 1 := by
cases' raised_iff.1 H with H1 H2; rwa [Nat.dist_eq_sub_of_le H1, tsub_le_iff_left]
#align ordnode.raised.dist_le Ordnode.Raised.dist_le
theorem Raised.dist_le' {n m} (H : Raised n m) : Nat.dist m n ≤ 1 := by
rw [Nat.dist_comm]; exact H.dist_le
#align ordnode.raised.dist_le' Ordnode.Raised.dist_le'
| Mathlib/Data/Ordmap/Ordset.lean | 802 | 805 | theorem Raised.add_left (k) {n m} (H : Raised n m) : Raised (k + n) (k + m) := by |
rcases H with (rfl | rfl)
· exact Or.inl rfl
· exact Or.inr rfl
|
/-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Joey van Langen, Casper Putz
-/
import Mathlib.FieldTheory.Separable
import Mathlib.RingTheory.IntegralDomain
import Mathlib.Algebra.CharP.Reduced
import Mathlib.Tactic.ApplyFun
#align_import field_theory.finite.basic from "leanprover-community/mathlib"@"12a85fac627bea918960da036049d611b1a3ee43"
/-!
# Finite fields
This file contains basic results about finite fields.
Throughout most of this file, `K` denotes a finite field
and `q` is notation for the cardinality of `K`.
See `RingTheory.IntegralDomain` for the fact that the unit group of a finite field is a
cyclic group, as well as the fact that every finite integral domain is a field
(`Fintype.fieldOfDomain`).
## Main results
1. `Fintype.card_units`: The unit group of a finite field has cardinality `q - 1`.
2. `sum_pow_units`: The sum of `x^i`, where `x` ranges over the units of `K`, is
- `q-1` if `q-1 ∣ i`
- `0` otherwise
3. `FiniteField.card`: The cardinality `q` is a power of the characteristic of `K`.
See `FiniteField.card'` for a variant.
## Notation
Throughout most of this file, `K` denotes a finite field
and `q` is notation for the cardinality of `K`.
## Implementation notes
While `Fintype Kˣ` can be inferred from `Fintype K` in the presence of `DecidableEq K`,
in this file we take the `Fintype Kˣ` argument directly to reduce the chance of typeclass
diamonds, as `Fintype` carries data.
-/
variable {K : Type*} {R : Type*}
local notation "q" => Fintype.card K
open Finset
open scoped Polynomial
namespace FiniteField
section Polynomial
variable [CommRing R] [IsDomain R]
open Polynomial
/-- The cardinality of a field is at most `n` times the cardinality of the image of a degree `n`
polynomial -/
theorem card_image_polynomial_eval [DecidableEq R] [Fintype R] {p : R[X]} (hp : 0 < p.degree) :
Fintype.card R ≤ natDegree p * (univ.image fun x => eval x p).card :=
Finset.card_le_mul_card_image _ _ (fun a _ =>
calc
_ = (p - C a).roots.toFinset.card :=
congr_arg card (by simp [Finset.ext_iff, ← mem_roots_sub_C hp])
_ ≤ Multiset.card (p - C a).roots := Multiset.toFinset_card_le _
_ ≤ _ := card_roots_sub_C' hp)
#align finite_field.card_image_polynomial_eval FiniteField.card_image_polynomial_eval
/-- If `f` and `g` are quadratic polynomials, then the `f.eval a + g.eval b = 0` has a solution. -/
theorem exists_root_sum_quadratic [Fintype R] {f g : R[X]} (hf2 : degree f = 2) (hg2 : degree g = 2)
(hR : Fintype.card R % 2 = 1) : ∃ a b, f.eval a + g.eval b = 0 :=
letI := Classical.decEq R
suffices ¬Disjoint (univ.image fun x : R => eval x f)
(univ.image fun x : R => eval x (-g)) by
simp only [disjoint_left, mem_image] at this
push_neg at this
rcases this with ⟨x, ⟨a, _, ha⟩, ⟨b, _, hb⟩⟩
exact ⟨a, b, by rw [ha, ← hb, eval_neg, neg_add_self]⟩
fun hd : Disjoint _ _ =>
lt_irrefl (2 * ((univ.image fun x : R => eval x f) ∪ univ.image fun x : R => eval x (-g)).card) <|
calc 2 * ((univ.image fun x : R => eval x f) ∪ univ.image fun x : R => eval x (-g)).card
≤ 2 * Fintype.card R := Nat.mul_le_mul_left _ (Finset.card_le_univ _)
_ = Fintype.card R + Fintype.card R := two_mul _
_ < natDegree f * (univ.image fun x : R => eval x f).card +
natDegree (-g) * (univ.image fun x : R => eval x (-g)).card :=
(add_lt_add_of_lt_of_le
(lt_of_le_of_ne (card_image_polynomial_eval (by rw [hf2]; decide))
(mt (congr_arg (· % 2)) (by simp [natDegree_eq_of_degree_eq_some hf2, hR])))
(card_image_polynomial_eval (by rw [degree_neg, hg2]; decide)))
_ = 2 * ((univ.image fun x : R => eval x f) ∪ univ.image fun x : R => eval x (-g)).card := by
rw [card_union_of_disjoint hd];
simp [natDegree_eq_of_degree_eq_some hf2, natDegree_eq_of_degree_eq_some hg2, mul_add]
#align finite_field.exists_root_sum_quadratic FiniteField.exists_root_sum_quadratic
end Polynomial
theorem prod_univ_units_id_eq_neg_one [CommRing K] [IsDomain K] [Fintype Kˣ] :
∏ x : Kˣ, x = (-1 : Kˣ) := by
classical
have : (∏ x ∈ (@univ Kˣ _).erase (-1), x) = 1 :=
prod_involution (fun x _ => x⁻¹) (by simp)
(fun a => by simp (config := { contextual := true }) [Units.inv_eq_self_iff])
(fun a => by simp [@inv_eq_iff_eq_inv _ _ a]) (by simp)
rw [← insert_erase (mem_univ (-1 : Kˣ)), prod_insert (not_mem_erase _ _), this, mul_one]
#align finite_field.prod_univ_units_id_eq_neg_one FiniteField.prod_univ_units_id_eq_neg_one
set_option backward.synthInstance.canonInstances false in -- See https://github.com/leanprover-community/mathlib4/issues/12532
theorem card_cast_subgroup_card_ne_zero [Ring K] [NoZeroDivisors K] [Nontrivial K]
(G : Subgroup Kˣ) [Fintype G] : (Fintype.card G : K) ≠ 0 := by
let n := Fintype.card G
intro nzero
have ⟨p, char_p⟩ := CharP.exists K
have hd : p ∣ n := (CharP.cast_eq_zero_iff K p n).mp nzero
cases CharP.char_is_prime_or_zero K p with
| inr pzero =>
exact (Fintype.card_pos).ne' <| Nat.eq_zero_of_zero_dvd <| pzero ▸ hd
| inl pprime =>
have fact_pprime := Fact.mk pprime
-- G has an element x of order p by Cauchy's theorem
have ⟨x, hx⟩ := exists_prime_orderOf_dvd_card p hd
-- F has an element u (= ↑↑x) of order p
let u := ((x : Kˣ) : K)
have hu : orderOf u = p := by rwa [orderOf_units, Subgroup.orderOf_coe]
-- u ^ p = 1 implies (u - 1) ^ p = 0 and hence u = 1 ...
have h : u = 1 := by
rw [← sub_left_inj, sub_self 1]
apply pow_eq_zero (n := p)
rw [sub_pow_char_of_commute, one_pow, ← hu, pow_orderOf_eq_one, sub_self]
exact Commute.one_right u
-- ... meaning x didn't have order p after all, contradiction
apply pprime.one_lt.ne
rw [← hu, h, orderOf_one]
/-- The sum of a nontrivial subgroup of the units of a field is zero. -/
theorem sum_subgroup_units_eq_zero [Ring K] [NoZeroDivisors K]
{G : Subgroup Kˣ} [Fintype G] (hg : G ≠ ⊥) :
∑ x : G, (x.val : K) = 0 := by
rw [Subgroup.ne_bot_iff_exists_ne_one] at hg
rcases hg with ⟨a, ha⟩
-- The action of a on G as an embedding
let a_mul_emb : G ↪ G := mulLeftEmbedding a
-- ... and leaves G unchanged
have h_unchanged : Finset.univ.map a_mul_emb = Finset.univ := by simp
-- Therefore the sum of x over a G is the sum of a x over G
have h_sum_map := Finset.univ.sum_map a_mul_emb fun x => ((x : Kˣ) : K)
-- ... and the former is the sum of x over G.
-- By algebraic manipulation, we have Σ G, x = ∑ G, a x = a ∑ G, x
simp only [a_mul_emb, h_unchanged, Function.Embedding.coeFn_mk, Function.Embedding.toFun_eq_coe,
mulLeftEmbedding_apply, Submonoid.coe_mul, Subgroup.coe_toSubmonoid, Units.val_mul,
← Finset.mul_sum] at h_sum_map
-- thus one of (a - 1) or ∑ G, x is zero
have hzero : (((a : Kˣ) : K) - 1) = 0 ∨ ∑ x : ↥G, ((x : Kˣ) : K) = 0 := by
rw [← mul_eq_zero, sub_mul, ← h_sum_map, one_mul, sub_self]
apply Or.resolve_left hzero
contrapose! ha
ext
rwa [← sub_eq_zero]
/-- The sum of a subgroup of the units of a field is 1 if the subgroup is trivial and 1 otherwise -/
@[simp]
theorem sum_subgroup_units [Ring K] [NoZeroDivisors K]
{G : Subgroup Kˣ} [Fintype G] [Decidable (G = ⊥)] :
∑ x : G, (x.val : K) = if G = ⊥ then 1 else 0 := by
by_cases G_bot : G = ⊥
· subst G_bot
simp only [ite_true, Subgroup.mem_bot, Fintype.card_ofSubsingleton, Nat.cast_ite, Nat.cast_one,
Nat.cast_zero, univ_unique, Set.default_coe_singleton, sum_singleton, Units.val_one]
· simp only [G_bot, ite_false]
exact sum_subgroup_units_eq_zero G_bot
@[simp]
theorem sum_subgroup_pow_eq_zero [CommRing K] [NoZeroDivisors K]
{G : Subgroup Kˣ} [Fintype G] {k : ℕ} (k_pos : k ≠ 0) (k_lt_card_G : k < Fintype.card G) :
∑ x : G, ((x : Kˣ) : K) ^ k = 0 := by
nontriviality K
have := NoZeroDivisors.to_isDomain K
rcases (exists_pow_ne_one_of_isCyclic k_pos k_lt_card_G) with ⟨a, ha⟩
rw [Finset.sum_eq_multiset_sum]
have h_multiset_map :
Finset.univ.val.map (fun x : G => ((x : Kˣ) : K) ^ k) =
Finset.univ.val.map (fun x : G => ((x : Kˣ) : K) ^ k * ((a : Kˣ) : K) ^ k) := by
simp_rw [← mul_pow]
have as_comp :
(fun x : ↥G => (((x : Kˣ) : K) * ((a : Kˣ) : K)) ^ k)
= (fun x : ↥G => ((x : Kˣ) : K) ^ k) ∘ fun x : ↥G => x * a := by
funext x
simp only [Function.comp_apply, Submonoid.coe_mul, Subgroup.coe_toSubmonoid, Units.val_mul]
rw [as_comp, ← Multiset.map_map]
congr
rw [eq_comm]
exact Multiset.map_univ_val_equiv (Equiv.mulRight a)
have h_multiset_map_sum : (Multiset.map (fun x : G => ((x : Kˣ) : K) ^ k) Finset.univ.val).sum =
(Multiset.map (fun x : G => ((x : Kˣ) : K) ^ k * ((a : Kˣ) : K) ^ k) Finset.univ.val).sum := by
rw [h_multiset_map]
rw [Multiset.sum_map_mul_right] at h_multiset_map_sum
have hzero : (((a : Kˣ) : K) ^ k - 1 : K)
* (Multiset.map (fun i : G => (i.val : K) ^ k) Finset.univ.val).sum = 0 := by
rw [sub_mul, mul_comm, ← h_multiset_map_sum, one_mul, sub_self]
rw [mul_eq_zero] at hzero
refine hzero.resolve_left fun h => ha ?_
ext
rw [← sub_eq_zero]
simp_rw [SubmonoidClass.coe_pow, Units.val_pow_eq_pow_val, OneMemClass.coe_one, Units.val_one, h]
section
variable [GroupWithZero K] [Fintype K]
theorem pow_card_sub_one_eq_one (a : K) (ha : a ≠ 0) : a ^ (q - 1) = 1 := by
calc
a ^ (Fintype.card K - 1) = (Units.mk0 a ha ^ (Fintype.card K - 1) : Kˣ).1 := by
rw [Units.val_pow_eq_pow_val, Units.val_mk0]
_ = 1 := by
classical
rw [← Fintype.card_units, pow_card_eq_one]
rfl
#align finite_field.pow_card_sub_one_eq_one FiniteField.pow_card_sub_one_eq_one
theorem pow_card (a : K) : a ^ q = a := by
by_cases h : a = 0; · rw [h]; apply zero_pow Fintype.card_ne_zero
rw [← Nat.succ_pred_eq_of_pos Fintype.card_pos, pow_succ, Nat.pred_eq_sub_one,
pow_card_sub_one_eq_one a h, one_mul]
#align finite_field.pow_card FiniteField.pow_card
theorem pow_card_pow (n : ℕ) (a : K) : a ^ q ^ n = a := by
induction' n with n ih
· simp
· simp [pow_succ, pow_mul, ih, pow_card]
#align finite_field.pow_card_pow FiniteField.pow_card_pow
end
variable (K) [Field K] [Fintype K]
theorem card (p : ℕ) [CharP K p] : ∃ n : ℕ+, Nat.Prime p ∧ q = p ^ (n : ℕ) := by
haveI hp : Fact p.Prime := ⟨CharP.char_is_prime K p⟩
letI : Module (ZMod p) K := { (ZMod.castHom dvd_rfl K : ZMod p →+* _).toModule with }
obtain ⟨n, h⟩ := VectorSpace.card_fintype (ZMod p) K
rw [ZMod.card] at h
refine ⟨⟨n, ?_⟩, hp.1, h⟩
apply Or.resolve_left (Nat.eq_zero_or_pos n)
rintro rfl
rw [pow_zero] at h
have : (0 : K) = 1 := by apply Fintype.card_le_one_iff.mp (le_of_eq h)
exact absurd this zero_ne_one
#align finite_field.card FiniteField.card
-- this statement doesn't use `q` because we want `K` to be an explicit parameter
theorem card' : ∃ (p : ℕ) (n : ℕ+), Nat.Prime p ∧ Fintype.card K = p ^ (n : ℕ) :=
let ⟨p, hc⟩ := CharP.exists K
⟨p, @FiniteField.card K _ _ p hc⟩
#align finite_field.card' FiniteField.card'
-- Porting note: this was a `simp` lemma with a 5 lines proof.
theorem cast_card_eq_zero : (q : K) = 0 := by
simp
#align finite_field.cast_card_eq_zero FiniteField.cast_card_eq_zero
theorem forall_pow_eq_one_iff (i : ℕ) : (∀ x : Kˣ, x ^ i = 1) ↔ q - 1 ∣ i := by
classical
obtain ⟨x, hx⟩ := IsCyclic.exists_generator (α := Kˣ)
rw [← Fintype.card_units, ← orderOf_eq_card_of_forall_mem_zpowers hx,
orderOf_dvd_iff_pow_eq_one]
constructor
· intro h; apply h
· intro h y
simp_rw [← mem_powers_iff_mem_zpowers] at hx
rcases hx y with ⟨j, rfl⟩
rw [← pow_mul, mul_comm, pow_mul, h, one_pow]
#align finite_field.forall_pow_eq_one_iff FiniteField.forall_pow_eq_one_iff
/-- The sum of `x ^ i` as `x` ranges over the units of a finite field of cardinality `q`
is equal to `0` unless `(q - 1) ∣ i`, in which case the sum is `q - 1`. -/
theorem sum_pow_units [DecidableEq K] (i : ℕ) :
(∑ x : Kˣ, (x ^ i : K)) = if q - 1 ∣ i then -1 else 0 := by
let φ : Kˣ →* K :=
{ toFun := fun x => x ^ i
map_one' := by simp
map_mul' := by intros; simp [mul_pow] }
have : Decidable (φ = 1) := by classical infer_instance
calc (∑ x : Kˣ, φ x) = if φ = 1 then Fintype.card Kˣ else 0 := sum_hom_units φ
_ = if q - 1 ∣ i then -1 else 0 := by
suffices q - 1 ∣ i ↔ φ = 1 by
simp only [this]
split_ifs; swap
· exact Nat.cast_zero
· rw [Fintype.card_units, Nat.cast_sub,
cast_card_eq_zero, Nat.cast_one, zero_sub]
show 1 ≤ q; exact Fintype.card_pos_iff.mpr ⟨0⟩
rw [← forall_pow_eq_one_iff, DFunLike.ext_iff]
apply forall_congr'; intro x; simp [φ, Units.ext_iff]
#align finite_field.sum_pow_units FiniteField.sum_pow_units
/-- The sum of `x ^ i` as `x` ranges over a finite field of cardinality `q`
is equal to `0` if `i < q - 1`. -/
theorem sum_pow_lt_card_sub_one (i : ℕ) (h : i < q - 1) : ∑ x : K, x ^ i = 0 := by
by_cases hi : i = 0
· simp only [hi, nsmul_one, sum_const, pow_zero, card_univ, cast_card_eq_zero]
classical
have hiq : ¬q - 1 ∣ i := by contrapose! h; exact Nat.le_of_dvd (Nat.pos_of_ne_zero hi) h
let φ : Kˣ ↪ K := ⟨fun x ↦ x, Units.ext⟩
have : univ.map φ = univ \ {0} := by
ext x
simpa only [mem_map, mem_univ, Function.Embedding.coeFn_mk, true_and_iff, mem_sdiff,
mem_singleton, φ] using isUnit_iff_ne_zero
calc
∑ x : K, x ^ i = ∑ x ∈ univ \ {(0 : K)}, x ^ i := by
rw [← sum_sdiff ({0} : Finset K).subset_univ, sum_singleton, zero_pow hi, add_zero]
_ = ∑ x : Kˣ, (x ^ i : K) := by simp [φ, ← this, univ.sum_map φ]
_ = 0 := by rw [sum_pow_units K i, if_neg]; exact hiq
#align finite_field.sum_pow_lt_card_sub_one FiniteField.sum_pow_lt_card_sub_one
open Polynomial
section
variable (K' : Type*) [Field K'] {p n : ℕ}
theorem X_pow_card_sub_X_natDegree_eq (hp : 1 < p) : (X ^ p - X : K'[X]).natDegree = p := by
have h1 : (X : K'[X]).degree < (X ^ p : K'[X]).degree := by
rw [degree_X_pow, degree_X]
exact mod_cast hp
rw [natDegree_eq_of_degree_eq (degree_sub_eq_left_of_degree_lt h1), natDegree_X_pow]
set_option linter.uppercaseLean3 false in
#align finite_field.X_pow_card_sub_X_nat_degree_eq FiniteField.X_pow_card_sub_X_natDegree_eq
theorem X_pow_card_pow_sub_X_natDegree_eq (hn : n ≠ 0) (hp : 1 < p) :
(X ^ p ^ n - X : K'[X]).natDegree = p ^ n :=
X_pow_card_sub_X_natDegree_eq K' <| Nat.one_lt_pow hn hp
set_option linter.uppercaseLean3 false in
#align finite_field.X_pow_card_pow_sub_X_nat_degree_eq FiniteField.X_pow_card_pow_sub_X_natDegree_eq
theorem X_pow_card_sub_X_ne_zero (hp : 1 < p) : (X ^ p - X : K'[X]) ≠ 0 :=
ne_zero_of_natDegree_gt <|
calc
1 < _ := hp
_ = _ := (X_pow_card_sub_X_natDegree_eq K' hp).symm
set_option linter.uppercaseLean3 false in
#align finite_field.X_pow_card_sub_X_ne_zero FiniteField.X_pow_card_sub_X_ne_zero
theorem X_pow_card_pow_sub_X_ne_zero (hn : n ≠ 0) (hp : 1 < p) : (X ^ p ^ n - X : K'[X]) ≠ 0 :=
X_pow_card_sub_X_ne_zero K' <| Nat.one_lt_pow hn hp
set_option linter.uppercaseLean3 false in
#align finite_field.X_pow_card_pow_sub_X_ne_zero FiniteField.X_pow_card_pow_sub_X_ne_zero
end
variable (p : ℕ) [Fact p.Prime] [Algebra (ZMod p) K]
| Mathlib/FieldTheory/Finite/Basic.lean | 357 | 370 | theorem roots_X_pow_card_sub_X : roots (X ^ q - X : K[X]) = Finset.univ.val := by |
classical
have aux : (X ^ q - X : K[X]) ≠ 0 := X_pow_card_sub_X_ne_zero K Fintype.one_lt_card
have : (roots (X ^ q - X : K[X])).toFinset = Finset.univ := by
rw [eq_univ_iff_forall]
intro x
rw [Multiset.mem_toFinset, mem_roots aux, IsRoot.def, eval_sub, eval_pow, eval_X,
sub_eq_zero, pow_card]
rw [← this, Multiset.toFinset_val, eq_comm, Multiset.dedup_eq_self]
apply nodup_roots
rw [separable_def]
convert isCoprime_one_right.neg_right (R := K[X]) using 1
rw [derivative_sub, derivative_X, derivative_X_pow, Nat.cast_card_eq_zero K, C_0,
zero_mul, zero_sub]
|
/-
Copyright (c) 2021 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.CategoryTheory.Preadditive.AdditiveFunctor
import Mathlib.CategoryTheory.Monoidal.Functor
#align_import category_theory.monoidal.preadditive from "leanprover-community/mathlib"@"986c4d5761f938b2e1c43c01f001b6d9d88c2055"
/-!
# Preadditive monoidal categories
A monoidal category is `MonoidalPreadditive` if it is preadditive and tensor product of morphisms
is linear in both factors.
-/
noncomputable section
open scoped Classical
namespace CategoryTheory
open CategoryTheory.Limits
open CategoryTheory.MonoidalCategory
variable (C : Type*) [Category C] [Preadditive C] [MonoidalCategory C]
/-- A category is `MonoidalPreadditive` if tensoring is additive in both factors.
Note we don't `extend Preadditive C` here, as `Abelian C` already extends it,
and we'll need to have both typeclasses sometimes.
-/
class MonoidalPreadditive : Prop where
whiskerLeft_zero : ∀ {X Y Z : C}, X ◁ (0 : Y ⟶ Z) = 0 := by aesop_cat
zero_whiskerRight : ∀ {X Y Z : C}, (0 : Y ⟶ Z) ▷ X = 0 := by aesop_cat
whiskerLeft_add : ∀ {X Y Z : C} (f g : Y ⟶ Z), X ◁ (f + g) = X ◁ f + X ◁ g := by aesop_cat
add_whiskerRight : ∀ {X Y Z : C} (f g : Y ⟶ Z), (f + g) ▷ X = f ▷ X + g ▷ X := by aesop_cat
#align category_theory.monoidal_preadditive CategoryTheory.MonoidalPreadditive
attribute [simp] MonoidalPreadditive.whiskerLeft_zero MonoidalPreadditive.zero_whiskerRight
attribute [simp] MonoidalPreadditive.whiskerLeft_add MonoidalPreadditive.add_whiskerRight
variable {C}
variable [MonoidalPreadditive C]
namespace MonoidalPreadditive
-- The priority setting will not be needed when we replace `𝟙 X ⊗ f` by `X ◁ f`.
@[simp (low)]
theorem tensor_zero {W X Y Z : C} (f : W ⟶ X) : f ⊗ (0 : Y ⟶ Z) = 0 := by
simp [tensorHom_def]
-- The priority setting will not be needed when we replace `f ⊗ 𝟙 X` by `f ▷ X`.
@[simp (low)]
theorem zero_tensor {W X Y Z : C} (f : Y ⟶ Z) : (0 : W ⟶ X) ⊗ f = 0 := by
simp [tensorHom_def]
theorem tensor_add {W X Y Z : C} (f : W ⟶ X) (g h : Y ⟶ Z) : f ⊗ (g + h) = f ⊗ g + f ⊗ h := by
simp [tensorHom_def]
theorem add_tensor {W X Y Z : C} (f g : W ⟶ X) (h : Y ⟶ Z) : (f + g) ⊗ h = f ⊗ h + g ⊗ h := by
simp [tensorHom_def]
end MonoidalPreadditive
instance tensorLeft_additive (X : C) : (tensorLeft X).Additive where
#align category_theory.tensor_left_additive CategoryTheory.tensorLeft_additive
instance tensorRight_additive (X : C) : (tensorRight X).Additive where
#align category_theory.tensor_right_additive CategoryTheory.tensorRight_additive
instance tensoringLeft_additive (X : C) : ((tensoringLeft C).obj X).Additive where
#align category_theory.tensoring_left_additive CategoryTheory.tensoringLeft_additive
instance tensoringRight_additive (X : C) : ((tensoringRight C).obj X).Additive where
#align category_theory.tensoring_right_additive CategoryTheory.tensoringRight_additive
/-- A faithful additive monoidal functor to a monoidal preadditive category
ensures that the domain is monoidal preadditive. -/
theorem monoidalPreadditive_of_faithful {D} [Category D] [Preadditive D] [MonoidalCategory D]
(F : MonoidalFunctor D C) [F.Faithful] [F.Additive] :
MonoidalPreadditive D :=
{ whiskerLeft_zero := by
intros
apply F.toFunctor.map_injective
simp [F.map_whiskerLeft]
zero_whiskerRight := by
intros
apply F.toFunctor.map_injective
simp [F.map_whiskerRight]
whiskerLeft_add := by
intros
apply F.toFunctor.map_injective
simp only [F.map_whiskerLeft, Functor.map_add, Preadditive.comp_add, Preadditive.add_comp,
MonoidalPreadditive.whiskerLeft_add]
add_whiskerRight := by
intros
apply F.toFunctor.map_injective
simp only [F.map_whiskerRight, Functor.map_add, Preadditive.comp_add, Preadditive.add_comp,
MonoidalPreadditive.add_whiskerRight] }
#align category_theory.monoidal_preadditive_of_faithful CategoryTheory.monoidalPreadditive_of_faithful
theorem whiskerLeft_sum (P : C) {Q R : C} {J : Type*} (s : Finset J) (g : J → (Q ⟶ R)) :
P ◁ ∑ j ∈ s, g j = ∑ j ∈ s, P ◁ g j :=
map_sum ((tensoringLeft C).obj P).mapAddHom g s
theorem sum_whiskerRight {Q R : C} {J : Type*} (s : Finset J) (g : J → (Q ⟶ R)) (P : C) :
(∑ j ∈ s, g j) ▷ P = ∑ j ∈ s, g j ▷ P :=
map_sum ((tensoringRight C).obj P).mapAddHom g s
theorem tensor_sum {P Q R S : C} {J : Type*} (s : Finset J) (f : P ⟶ Q) (g : J → (R ⟶ S)) :
(f ⊗ ∑ j ∈ s, g j) = ∑ j ∈ s, f ⊗ g j := by
simp only [tensorHom_def, whiskerLeft_sum, Preadditive.comp_sum]
#align category_theory.tensor_sum CategoryTheory.tensor_sum
theorem sum_tensor {P Q R S : C} {J : Type*} (s : Finset J) (f : P ⟶ Q) (g : J → (R ⟶ S)) :
(∑ j ∈ s, g j) ⊗ f = ∑ j ∈ s, g j ⊗ f := by
simp only [tensorHom_def, sum_whiskerRight, Preadditive.sum_comp]
#align category_theory.sum_tensor CategoryTheory.sum_tensor
-- In a closed monoidal category, this would hold because
-- `tensorLeft X` is a left adjoint and hence preserves all colimits.
-- In any case it is true in any preadditive category.
instance (X : C) : PreservesFiniteBiproducts (tensorLeft X) where
preserves {J} :=
{ preserves := fun {f} =>
{ preserves := fun {b} i => isBilimitOfTotal _ (by
dsimp
simp_rw [← id_tensorHom]
simp only [← tensor_comp, Category.comp_id, ← tensor_sum, ← tensor_id,
IsBilimit.total i]) } }
instance (X : C) : PreservesFiniteBiproducts (tensorRight X) where
preserves {J} :=
{ preserves := fun {f} =>
{ preserves := fun {b} i => isBilimitOfTotal _ (by
dsimp
simp_rw [← tensorHom_id]
simp only [← tensor_comp, Category.comp_id, ← sum_tensor, ← tensor_id,
IsBilimit.total i]) } }
variable [HasFiniteBiproducts C]
/-- The isomorphism showing how tensor product on the left distributes over direct sums. -/
def leftDistributor {J : Type} [Fintype J] (X : C) (f : J → C) : X ⊗ ⨁ f ≅ ⨁ fun j => X ⊗ f j :=
(tensorLeft X).mapBiproduct f
#align category_theory.left_distributor CategoryTheory.leftDistributor
theorem leftDistributor_hom {J : Type} [Fintype J] (X : C) (f : J → C) :
(leftDistributor X f).hom =
∑ j : J, (X ◁ biproduct.π f j) ≫ biproduct.ι (fun j => X ⊗ f j) j := by
ext
dsimp [leftDistributor, Functor.mapBiproduct, Functor.mapBicone]
erw [biproduct.lift_π]
simp only [Preadditive.sum_comp, Category.assoc, biproduct.ι_π, comp_dite, comp_zero,
Finset.sum_dite_eq', Finset.mem_univ, ite_true, eqToHom_refl, Category.comp_id]
#align category_theory.left_distributor_hom CategoryTheory.leftDistributor_hom
theorem leftDistributor_inv {J : Type} [Fintype J] (X : C) (f : J → C) :
(leftDistributor X f).inv = ∑ j : J, biproduct.π _ j ≫ (X ◁ biproduct.ι f j) := by
ext
dsimp [leftDistributor, Functor.mapBiproduct, Functor.mapBicone]
simp only [Preadditive.comp_sum, biproduct.ι_π_assoc, dite_comp, zero_comp,
Finset.sum_dite_eq, Finset.mem_univ, ite_true, eqToHom_refl, Category.id_comp,
biproduct.ι_desc]
#align category_theory.left_distributor_inv CategoryTheory.leftDistributor_inv
@[reassoc (attr := simp)]
theorem leftDistributor_hom_comp_biproduct_π {J : Type} [Fintype J] (X : C) (f : J → C) (j : J) :
(leftDistributor X f).hom ≫ biproduct.π _ j = X ◁ biproduct.π _ j := by
simp [leftDistributor_hom, Preadditive.sum_comp, biproduct.ι_π, comp_dite]
@[reassoc (attr := simp)]
theorem biproduct_ι_comp_leftDistributor_hom {J : Type} [Fintype J] (X : C) (f : J → C) (j : J) :
(X ◁ biproduct.ι _ j) ≫ (leftDistributor X f).hom = biproduct.ι (fun j => X ⊗ f j) j := by
simp [leftDistributor_hom, Preadditive.comp_sum, ← MonoidalCategory.whiskerLeft_comp_assoc,
biproduct.ι_π, whiskerLeft_dite, dite_comp]
@[reassoc (attr := simp)]
theorem leftDistributor_inv_comp_biproduct_π {J : Type} [Fintype J] (X : C) (f : J → C) (j : J) :
(leftDistributor X f).inv ≫ (X ◁ biproduct.π _ j) = biproduct.π _ j := by
simp [leftDistributor_inv, Preadditive.sum_comp, ← MonoidalCategory.whiskerLeft_comp,
biproduct.ι_π, whiskerLeft_dite, comp_dite]
@[reassoc (attr := simp)]
theorem biproduct_ι_comp_leftDistributor_inv {J : Type} [Fintype J] (X : C) (f : J → C) (j : J) :
biproduct.ι _ j ≫ (leftDistributor X f).inv = X ◁ biproduct.ι _ j := by
simp [leftDistributor_inv, Preadditive.comp_sum, ← id_tensor_comp, biproduct.ι_π_assoc, dite_comp]
theorem leftDistributor_assoc {J : Type} [Fintype J] (X Y : C) (f : J → C) :
(asIso (𝟙 X) ⊗ leftDistributor Y f) ≪≫ leftDistributor X _ =
(α_ X Y (⨁ f)).symm ≪≫ leftDistributor (X ⊗ Y) f ≪≫ biproduct.mapIso fun j => α_ X Y _ := by
ext
simp only [Category.comp_id, Category.assoc, eqToHom_refl, Iso.trans_hom, Iso.symm_hom,
asIso_hom, comp_zero, comp_dite, Preadditive.sum_comp, Preadditive.comp_sum, tensor_sum,
id_tensor_comp, tensorIso_hom, leftDistributor_hom, biproduct.mapIso_hom, biproduct.ι_map,
biproduct.ι_π, Finset.sum_dite_irrel, Finset.sum_dite_eq', Finset.sum_const_zero]
simp_rw [← id_tensorHom]
simp only [← id_tensor_comp, biproduct.ι_π]
simp only [id_tensor_comp, tensor_dite, comp_dite]
simp
#align category_theory.left_distributor_assoc CategoryTheory.leftDistributor_assoc
/-- The isomorphism showing how tensor product on the right distributes over direct sums. -/
def rightDistributor {J : Type} [Fintype J] (f : J → C) (X : C) : (⨁ f) ⊗ X ≅ ⨁ fun j => f j ⊗ X :=
(tensorRight X).mapBiproduct f
#align category_theory.right_distributor CategoryTheory.rightDistributor
theorem rightDistributor_hom {J : Type} [Fintype J] (f : J → C) (X : C) :
(rightDistributor f X).hom =
∑ j : J, (biproduct.π f j ▷ X) ≫ biproduct.ι (fun j => f j ⊗ X) j := by
ext
dsimp [rightDistributor, Functor.mapBiproduct, Functor.mapBicone]
erw [biproduct.lift_π]
simp only [Preadditive.sum_comp, Category.assoc, biproduct.ι_π, comp_dite, comp_zero,
Finset.sum_dite_eq', Finset.mem_univ, eqToHom_refl, Category.comp_id, ite_true]
#align category_theory.right_distributor_hom CategoryTheory.rightDistributor_hom
theorem rightDistributor_inv {J : Type} [Fintype J] (f : J → C) (X : C) :
(rightDistributor f X).inv = ∑ j : J, biproduct.π _ j ≫ (biproduct.ι f j ▷ X) := by
ext
dsimp [rightDistributor, Functor.mapBiproduct, Functor.mapBicone]
simp only [biproduct.ι_desc, Preadditive.comp_sum, ne_eq, biproduct.ι_π_assoc, dite_comp,
zero_comp, Finset.sum_dite_eq, Finset.mem_univ, eqToHom_refl, Category.id_comp, ite_true]
#align category_theory.right_distributor_inv CategoryTheory.rightDistributor_inv
@[reassoc (attr := simp)]
theorem rightDistributor_hom_comp_biproduct_π {J : Type} [Fintype J] (f : J → C) (X : C) (j : J) :
(rightDistributor f X).hom ≫ biproduct.π _ j = biproduct.π _ j ▷ X := by
simp [rightDistributor_hom, Preadditive.sum_comp, biproduct.ι_π, comp_dite]
@[reassoc (attr := simp)]
theorem biproduct_ι_comp_rightDistributor_hom {J : Type} [Fintype J] (f : J → C) (X : C) (j : J) :
(biproduct.ι _ j ▷ X) ≫ (rightDistributor f X).hom = biproduct.ι (fun j => f j ⊗ X) j := by
simp [rightDistributor_hom, Preadditive.comp_sum, ← comp_whiskerRight_assoc, biproduct.ι_π,
dite_whiskerRight, dite_comp]
@[reassoc (attr := simp)]
theorem rightDistributor_inv_comp_biproduct_π {J : Type} [Fintype J] (f : J → C) (X : C) (j : J) :
(rightDistributor f X).inv ≫ (biproduct.π _ j ▷ X) = biproduct.π _ j := by
simp [rightDistributor_inv, Preadditive.sum_comp, ← MonoidalCategory.comp_whiskerRight,
biproduct.ι_π, dite_whiskerRight, comp_dite]
@[reassoc (attr := simp)]
theorem biproduct_ι_comp_rightDistributor_inv {J : Type} [Fintype J] (f : J → C) (X : C) (j : J) :
biproduct.ι _ j ≫ (rightDistributor f X).inv = biproduct.ι _ j ▷ X := by
simp [rightDistributor_inv, Preadditive.comp_sum, ← id_tensor_comp, biproduct.ι_π_assoc,
dite_comp]
theorem rightDistributor_assoc {J : Type} [Fintype J] (f : J → C) (X Y : C) :
(rightDistributor f X ⊗ asIso (𝟙 Y)) ≪≫ rightDistributor _ Y =
α_ (⨁ f) X Y ≪≫ rightDistributor f (X ⊗ Y) ≪≫ biproduct.mapIso fun j => (α_ _ X Y).symm := by
ext
simp only [Category.comp_id, Category.assoc, eqToHom_refl, Iso.symm_hom, Iso.trans_hom,
asIso_hom, comp_zero, comp_dite, Preadditive.sum_comp, Preadditive.comp_sum, sum_tensor,
comp_tensor_id, tensorIso_hom, rightDistributor_hom, biproduct.mapIso_hom, biproduct.ι_map,
biproduct.ι_π, Finset.sum_dite_irrel, Finset.sum_dite_eq', Finset.sum_const_zero,
Finset.mem_univ, if_true]
simp_rw [← tensorHom_id]
simp only [← comp_tensor_id, biproduct.ι_π, dite_tensor, comp_dite]
simp
#align category_theory.right_distributor_assoc CategoryTheory.rightDistributor_assoc
theorem leftDistributor_rightDistributor_assoc {J : Type _} [Fintype J]
(X : C) (f : J → C) (Y : C) :
(leftDistributor X f ⊗ asIso (𝟙 Y)) ≪≫ rightDistributor _ Y =
α_ X (⨁ f) Y ≪≫
(asIso (𝟙 X) ⊗ rightDistributor _ Y) ≪≫
leftDistributor X _ ≪≫ biproduct.mapIso fun j => (α_ _ _ _).symm := by
ext
simp only [Category.comp_id, Category.assoc, eqToHom_refl, Iso.symm_hom, Iso.trans_hom,
asIso_hom, comp_zero, comp_dite, Preadditive.sum_comp, Preadditive.comp_sum, sum_tensor,
tensor_sum, comp_tensor_id, tensorIso_hom, leftDistributor_hom, rightDistributor_hom,
biproduct.mapIso_hom, biproduct.ι_map, biproduct.ι_π, Finset.sum_dite_irrel,
Finset.sum_dite_eq', Finset.sum_const_zero, Finset.mem_univ, if_true]
simp_rw [← tensorHom_id, ← id_tensorHom]
simp only [← comp_tensor_id, ← id_tensor_comp_assoc, Category.assoc, biproduct.ι_π, comp_dite,
dite_comp, tensor_dite, dite_tensor]
simp
#align category_theory.left_distributor_right_distributor_assoc CategoryTheory.leftDistributor_rightDistributor_assoc
@[ext]
theorem leftDistributor_ext_left {J : Type} [Fintype J] {X Y : C} {f : J → C} {g h : X ⊗ ⨁ f ⟶ Y}
(w : ∀ j, (X ◁ biproduct.ι f j) ≫ g = (X ◁ biproduct.ι f j) ≫ h) : g = h := by
apply (cancel_epi (leftDistributor X f).inv).mp
ext
simp? [leftDistributor_inv, Preadditive.comp_sum_assoc, biproduct.ι_π_assoc, dite_comp] says
simp only [leftDistributor_inv, Preadditive.comp_sum_assoc, biproduct.ι_π_assoc, dite_comp,
zero_comp, Finset.sum_dite_eq, Finset.mem_univ, ↓reduceIte, eqToHom_refl, Category.id_comp]
apply w
@[ext]
theorem leftDistributor_ext_right {J : Type} [Fintype J] {X Y : C} {f : J → C} {g h : X ⟶ Y ⊗ ⨁ f}
(w : ∀ j, g ≫ (Y ◁ biproduct.π f j) = h ≫ (Y ◁ biproduct.π f j)) : g = h := by
apply (cancel_mono (leftDistributor Y f).hom).mp
ext
simp? [leftDistributor_hom, Preadditive.sum_comp, Preadditive.comp_sum_assoc, biproduct.ι_π,
comp_dite] says
simp only [leftDistributor_hom, Category.assoc, Preadditive.sum_comp, biproduct.ι_π, comp_dite,
comp_zero, Finset.sum_dite_eq', Finset.mem_univ, ↓reduceIte, eqToHom_refl, Category.comp_id]
apply w
-- One might wonder how many iterated tensor products we need simp lemmas for.
-- The answer is two: this lemma is needed to verify the pentagon identity.
@[ext]
| Mathlib/CategoryTheory/Monoidal/Preadditive.lean | 309 | 315 | theorem leftDistributor_ext₂_left {J : Type} [Fintype J]
{X Y Z : C} {f : J → C} {g h : X ⊗ (Y ⊗ ⨁ f) ⟶ Z}
(w : ∀ j, (X ◁ (Y ◁ biproduct.ι f j)) ≫ g = (X ◁ (Y ◁ biproduct.ι f j)) ≫ h) :
g = h := by |
apply (cancel_epi (α_ _ _ _).hom).mp
ext
simp [w]
|
/-
Copyright (c) 2020 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin
-/
import Mathlib.Algebra.Group.Defs
import Mathlib.Logic.Function.Basic
import Mathlib.Logic.Nontrivial.Defs
import Mathlib.Tactic.SplitIfs
#align_import algebra.group_with_zero.defs from "leanprover-community/mathlib"@"2f3994e1b117b1e1da49bcfb67334f33460c3ce4"
/-!
# Typeclasses for groups with an adjoined zero element
This file provides just the typeclass definitions, and the projection lemmas that expose their
members.
## Main definitions
* `GroupWithZero`
* `CommGroupWithZero`
-/
assert_not_exists DenselyOrdered
universe u
-- We have to fix the universe of `G₀` here, since the default argument to
-- `GroupWithZero.div'` cannot contain a universe metavariable.
variable {G₀ : Type u} {M₀ M₀' G₀' : Type*}
/-- Typeclass for expressing that a type `M₀` with multiplication and a zero satisfies
`0 * a = 0` and `a * 0 = 0` for all `a : M₀`. -/
class MulZeroClass (M₀ : Type u) extends Mul M₀, Zero M₀ where
/-- Zero is a left absorbing element for multiplication -/
zero_mul : ∀ a : M₀, 0 * a = 0
/-- Zero is a right absorbing element for multiplication -/
mul_zero : ∀ a : M₀, a * 0 = 0
#align mul_zero_class MulZeroClass
/-- A mixin for left cancellative multiplication by nonzero elements. -/
class IsLeftCancelMulZero (M₀ : Type u) [Mul M₀] [Zero M₀] : Prop where
/-- Multiplication by a nonzero element is left cancellative. -/
protected mul_left_cancel_of_ne_zero : ∀ {a b c : M₀}, a ≠ 0 → a * b = a * c → b = c
#align is_left_cancel_mul_zero IsLeftCancelMulZero
section IsLeftCancelMulZero
variable [Mul M₀] [Zero M₀] [IsLeftCancelMulZero M₀] {a b c : M₀}
theorem mul_left_cancel₀ (ha : a ≠ 0) (h : a * b = a * c) : b = c :=
IsLeftCancelMulZero.mul_left_cancel_of_ne_zero ha h
#align mul_left_cancel₀ mul_left_cancel₀
theorem mul_right_injective₀ (ha : a ≠ 0) : Function.Injective (a * ·) :=
fun _ _ => mul_left_cancel₀ ha
#align mul_right_injective₀ mul_right_injective₀
end IsLeftCancelMulZero
/-- A mixin for right cancellative multiplication by nonzero elements. -/
class IsRightCancelMulZero (M₀ : Type u) [Mul M₀] [Zero M₀] : Prop where
/-- Multiplicatin by a nonzero element is right cancellative. -/
protected mul_right_cancel_of_ne_zero : ∀ {a b c : M₀}, b ≠ 0 → a * b = c * b → a = c
#align is_right_cancel_mul_zero IsRightCancelMulZero
section IsRightCancelMulZero
variable [Mul M₀] [Zero M₀] [IsRightCancelMulZero M₀] {a b c : M₀}
theorem mul_right_cancel₀ (hb : b ≠ 0) (h : a * b = c * b) : a = c :=
IsRightCancelMulZero.mul_right_cancel_of_ne_zero hb h
#align mul_right_cancel₀ mul_right_cancel₀
theorem mul_left_injective₀ (hb : b ≠ 0) : Function.Injective fun a => a * b :=
fun _ _ => mul_right_cancel₀ hb
#align mul_left_injective₀ mul_left_injective₀
end IsRightCancelMulZero
/-- A mixin for cancellative multiplication by nonzero elements. -/
class IsCancelMulZero (M₀ : Type u) [Mul M₀] [Zero M₀]
extends IsLeftCancelMulZero M₀, IsRightCancelMulZero M₀ : Prop
#align is_cancel_mul_zero IsCancelMulZero
export MulZeroClass (zero_mul mul_zero)
attribute [simp] zero_mul mul_zero
#align zero_mul MulZeroClass.zero_mul
#align mul_zero MulZeroClass.mul_zero
/-- Predicate typeclass for expressing that `a * b = 0` implies `a = 0` or `b = 0`
for all `a` and `b` of type `G₀`. -/
class NoZeroDivisors (M₀ : Type*) [Mul M₀] [Zero M₀] : Prop where
/-- For all `a` and `b` of `G₀`, `a * b = 0` implies `a = 0` or `b = 0`. -/
eq_zero_or_eq_zero_of_mul_eq_zero : ∀ {a b : M₀}, a * b = 0 → a = 0 ∨ b = 0
#align no_zero_divisors NoZeroDivisors
export NoZeroDivisors (eq_zero_or_eq_zero_of_mul_eq_zero)
/-- A type `S₀` is a "semigroup with zero” if it is a semigroup with zero element, and `0` is left
and right absorbing. -/
class SemigroupWithZero (S₀ : Type u) extends Semigroup S₀, MulZeroClass S₀
#align semigroup_with_zero SemigroupWithZero
/-- A typeclass for non-associative monoids with zero elements. -/
class MulZeroOneClass (M₀ : Type u) extends MulOneClass M₀, MulZeroClass M₀
#align mul_zero_one_class MulZeroOneClass
/-- A type `M₀` is a “monoid with zero” if it is a monoid with zero element, and `0` is left
and right absorbing. -/
class MonoidWithZero (M₀ : Type u) extends Monoid M₀, MulZeroOneClass M₀, SemigroupWithZero M₀
#align monoid_with_zero MonoidWithZero
/-- A type `M` is a `CancelMonoidWithZero` if it is a monoid with zero element, `0` is left
and right absorbing, and left/right multiplication by a non-zero element is injective. -/
class CancelMonoidWithZero (M₀ : Type*) extends MonoidWithZero M₀, IsCancelMulZero M₀
#align cancel_monoid_with_zero CancelMonoidWithZero
/-- A type `M` is a commutative “monoid with zero” if it is a commutative monoid with zero
element, and `0` is left and right absorbing. -/
class CommMonoidWithZero (M₀ : Type*) extends CommMonoid M₀, MonoidWithZero M₀
#align comm_monoid_with_zero CommMonoidWithZero
section CancelMonoidWithZero
variable [CancelMonoidWithZero M₀] {a b c : M₀}
theorem mul_left_inj' (hc : c ≠ 0) : a * c = b * c ↔ a = b :=
(mul_left_injective₀ hc).eq_iff
#align mul_left_inj' mul_left_inj'
theorem mul_right_inj' (ha : a ≠ 0) : a * b = a * c ↔ b = c :=
(mul_right_injective₀ ha).eq_iff
#align mul_right_inj' mul_right_inj'
end CancelMonoidWithZero
section CommSemigroup
variable [CommSemigroup M₀] [Zero M₀]
lemma IsLeftCancelMulZero.to_isRightCancelMulZero [IsLeftCancelMulZero M₀] :
IsRightCancelMulZero M₀ :=
{ mul_right_cancel_of_ne_zero :=
fun hb h => mul_left_cancel₀ hb <| (mul_comm _ _).trans (h.trans (mul_comm _ _)) }
#align is_left_cancel_mul_zero.to_is_right_cancel_mul_zero IsLeftCancelMulZero.to_isRightCancelMulZero
lemma IsRightCancelMulZero.to_isLeftCancelMulZero [IsRightCancelMulZero M₀] :
IsLeftCancelMulZero M₀ :=
{ mul_left_cancel_of_ne_zero :=
fun hb h => mul_right_cancel₀ hb <| (mul_comm _ _).trans (h.trans (mul_comm _ _)) }
#align is_right_cancel_mul_zero.to_is_left_cancel_mul_zero IsRightCancelMulZero.to_isLeftCancelMulZero
lemma IsLeftCancelMulZero.to_isCancelMulZero [IsLeftCancelMulZero M₀] :
IsCancelMulZero M₀ :=
{ IsLeftCancelMulZero.to_isRightCancelMulZero with }
#align is_left_cancel_mul_zero.to_is_cancel_mul_zero IsLeftCancelMulZero.to_isCancelMulZero
lemma IsRightCancelMulZero.to_isCancelMulZero [IsRightCancelMulZero M₀] :
IsCancelMulZero M₀ :=
{ IsRightCancelMulZero.to_isLeftCancelMulZero with }
#align is_right_cancel_mul_zero.to_is_cancel_mul_zero IsRightCancelMulZero.to_isCancelMulZero
end CommSemigroup
/-- A type `M` is a `CancelCommMonoidWithZero` if it is a commutative monoid with zero element,
`0` is left and right absorbing,
and left/right multiplication by a non-zero element is injective. -/
class CancelCommMonoidWithZero (M₀ : Type*) extends CommMonoidWithZero M₀, IsLeftCancelMulZero M₀
#align cancel_comm_monoid_with_zero CancelCommMonoidWithZero
-- See note [lower cancel priority]
attribute [instance 75] CancelCommMonoidWithZero.toCommMonoidWithZero
instance (priority := 100) CancelCommMonoidWithZero.toCancelMonoidWithZero
[CancelCommMonoidWithZero M₀] : CancelMonoidWithZero M₀ :=
{ IsLeftCancelMulZero.to_isCancelMulZero (M₀ := M₀) with }
/-- Prop-valued mixin for a monoid with zero to be equipped with a cancelling division.
The obvious use case is groups with zero, but this condition is also satisfied by `ℕ`, `ℤ` and, more
generally, any euclidean domain. -/
class MulDivCancelClass (M₀ : Type*) [MonoidWithZero M₀] [Div M₀] : Prop where
protected mul_div_cancel (a b : M₀) : b ≠ 0 → a * b / b = a
section MulDivCancelClass
variable [MonoidWithZero M₀] [Div M₀] [MulDivCancelClass M₀] {a b : M₀}
@[simp] lemma mul_div_cancel_right₀ (a : M₀) (hb : b ≠ 0) : a * b / b = a :=
MulDivCancelClass.mul_div_cancel _ _ hb
#align mul_div_cancel mul_div_cancel_right₀
end MulDivCancelClass
section MulDivCancelClass
variable [CommMonoidWithZero M₀] [Div M₀] [MulDivCancelClass M₀] {a b : M₀}
@[simp] lemma mul_div_cancel_left₀ (b : M₀) (ha : a ≠ 0) : a * b / a = b := by
rw [mul_comm, mul_div_cancel_right₀ _ ha]
#align mul_div_cancel_left mul_div_cancel_left₀
end MulDivCancelClass
/-- A type `G₀` is a “group with zero” if it is a monoid with zero element (distinct from `1`)
such that every nonzero element is invertible.
The type is required to come with an “inverse” function, and the inverse of `0` must be `0`.
Examples include division rings and the ordered monoids that are the
target of valuations in general valuation theory. -/
class GroupWithZero (G₀ : Type u) extends MonoidWithZero G₀, DivInvMonoid G₀, Nontrivial G₀ where
/-- The inverse of `0` in a group with zero is `0`. -/
inv_zero : (0 : G₀)⁻¹ = 0
/-- Every nonzero element of a group with zero is invertible. -/
protected mul_inv_cancel (a : G₀) : a ≠ 0 → a * a⁻¹ = 1
#align group_with_zero GroupWithZero
export GroupWithZero (inv_zero)
attribute [simp] inv_zero
section GroupWithZero
variable [GroupWithZero G₀] {a : G₀}
@[simp] lemma mul_inv_cancel (h : a ≠ 0) : a * a⁻¹ = 1 := GroupWithZero.mul_inv_cancel a h
#align mul_inv_cancel mul_inv_cancel
-- See note [lower instance priority]
instance (priority := 100) GroupWithZero.toMulDivCancelClass : MulDivCancelClass G₀ where
mul_div_cancel a b hb := by rw [div_eq_mul_inv, mul_assoc, mul_inv_cancel hb, mul_one]
end GroupWithZero
/-- A type `G₀` is a commutative “group with zero”
if it is a commutative monoid with zero element (distinct from `1`)
such that every nonzero element is invertible.
The type is required to come with an “inverse” function, and the inverse of `0` must be `0`. -/
class CommGroupWithZero (G₀ : Type*) extends CommMonoidWithZero G₀, GroupWithZero G₀
#align comm_group_with_zero CommGroupWithZero
section
variable [CancelMonoidWithZero M₀] {x : M₀}
lemma eq_zero_or_one_of_sq_eq_self (hx : x ^ 2 = x) : x = 0 ∨ x = 1 :=
or_iff_not_imp_left.mpr (mul_left_injective₀ · <| by simpa [sq] using hx)
end
section GroupWithZero
variable [GroupWithZero G₀] {a b c g h x : G₀}
@[simp]
theorem mul_inv_cancel_right₀ (h : b ≠ 0) (a : G₀) : a * b * b⁻¹ = a :=
calc
a * b * b⁻¹ = a * (b * b⁻¹) := mul_assoc _ _ _
_ = a := by simp [h]
#align mul_inv_cancel_right₀ mul_inv_cancel_right₀
@[simp]
theorem mul_inv_cancel_left₀ (h : a ≠ 0) (b : G₀) : a * (a⁻¹ * b) = b :=
calc
a * (a⁻¹ * b) = a * a⁻¹ * b := (mul_assoc _ _ _).symm
_ = b := by simp [h]
#align mul_inv_cancel_left₀ mul_inv_cancel_left₀
end GroupWithZero
section MulZeroClass
variable [MulZeroClass M₀]
theorem mul_eq_zero_of_left {a : M₀} (h : a = 0) (b : M₀) : a * b = 0 := h.symm ▸ zero_mul b
#align mul_eq_zero_of_left mul_eq_zero_of_left
theorem mul_eq_zero_of_right (a : M₀) {b : M₀} (h : b = 0) : a * b = 0 := h.symm ▸ mul_zero a
#align mul_eq_zero_of_right mul_eq_zero_of_right
variable [NoZeroDivisors M₀] {a b : M₀}
/-- If `α` has no zero divisors, then the product of two elements equals zero iff one of them
equals zero. -/
@[simp]
theorem mul_eq_zero : a * b = 0 ↔ a = 0 ∨ b = 0 :=
⟨eq_zero_or_eq_zero_of_mul_eq_zero,
fun o => o.elim (fun h => mul_eq_zero_of_left h b) (mul_eq_zero_of_right a)⟩
#align mul_eq_zero mul_eq_zero
/-- If `α` has no zero divisors, then the product of two elements equals zero iff one of them
equals zero. -/
@[simp]
| Mathlib/Algebra/GroupWithZero/Defs.lean | 290 | 290 | theorem zero_eq_mul : 0 = a * b ↔ a = 0 ∨ b = 0 := by | rw [eq_comm, mul_eq_zero]
|
/-
Copyright (c) 2022 Joseph Myers. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Joseph Myers
-/
import Mathlib.Geometry.Euclidean.Angle.Oriented.Affine
import Mathlib.Geometry.Euclidean.Angle.Unoriented.RightAngle
#align_import geometry.euclidean.angle.oriented.right_angle from "leanprover-community/mathlib"@"46b633fd842bef9469441c0209906f6dddd2b4f5"
/-!
# Oriented angles in right-angled triangles.
This file proves basic geometrical results about distances and oriented angles in (possibly
degenerate) right-angled triangles in real inner product spaces and Euclidean affine spaces.
-/
noncomputable section
open scoped EuclideanGeometry
open scoped Real
open scoped RealInnerProductSpace
namespace Orientation
open FiniteDimensional
variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℝ V]
variable [hd2 : Fact (finrank ℝ V = 2)] (o : Orientation ℝ V (Fin 2))
/-- An angle in a right-angled triangle expressed using `arccos`. -/
theorem oangle_add_right_eq_arccos_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) :
o.oangle x (x + y) = Real.arccos (‖x‖ / ‖x + y‖) := by
have hs : (o.oangle x (x + y)).sign = 1 := by
rw [oangle_sign_add_right, h, Real.Angle.sign_coe_pi_div_two]
rw [o.oangle_eq_angle_of_sign_eq_one hs,
InnerProductGeometry.angle_add_eq_arccos_of_inner_eq_zero
(o.inner_eq_zero_of_oangle_eq_pi_div_two h)]
#align orientation.oangle_add_right_eq_arccos_of_oangle_eq_pi_div_two Orientation.oangle_add_right_eq_arccos_of_oangle_eq_pi_div_two
/-- An angle in a right-angled triangle expressed using `arccos`. -/
theorem oangle_add_left_eq_arccos_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) :
o.oangle (x + y) y = Real.arccos (‖y‖ / ‖x + y‖) := by
rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢
rw [add_comm]
exact (-o).oangle_add_right_eq_arccos_of_oangle_eq_pi_div_two h
#align orientation.oangle_add_left_eq_arccos_of_oangle_eq_pi_div_two Orientation.oangle_add_left_eq_arccos_of_oangle_eq_pi_div_two
/-- An angle in a right-angled triangle expressed using `arcsin`. -/
theorem oangle_add_right_eq_arcsin_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) :
o.oangle x (x + y) = Real.arcsin (‖y‖ / ‖x + y‖) := by
have hs : (o.oangle x (x + y)).sign = 1 := by
rw [oangle_sign_add_right, h, Real.Angle.sign_coe_pi_div_two]
rw [o.oangle_eq_angle_of_sign_eq_one hs,
InnerProductGeometry.angle_add_eq_arcsin_of_inner_eq_zero
(o.inner_eq_zero_of_oangle_eq_pi_div_two h)
(Or.inl (o.left_ne_zero_of_oangle_eq_pi_div_two h))]
#align orientation.oangle_add_right_eq_arcsin_of_oangle_eq_pi_div_two Orientation.oangle_add_right_eq_arcsin_of_oangle_eq_pi_div_two
/-- An angle in a right-angled triangle expressed using `arcsin`. -/
theorem oangle_add_left_eq_arcsin_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) :
o.oangle (x + y) y = Real.arcsin (‖x‖ / ‖x + y‖) := by
rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢
rw [add_comm]
exact (-o).oangle_add_right_eq_arcsin_of_oangle_eq_pi_div_two h
#align orientation.oangle_add_left_eq_arcsin_of_oangle_eq_pi_div_two Orientation.oangle_add_left_eq_arcsin_of_oangle_eq_pi_div_two
/-- An angle in a right-angled triangle expressed using `arctan`. -/
theorem oangle_add_right_eq_arctan_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) :
o.oangle x (x + y) = Real.arctan (‖y‖ / ‖x‖) := by
have hs : (o.oangle x (x + y)).sign = 1 := by
rw [oangle_sign_add_right, h, Real.Angle.sign_coe_pi_div_two]
rw [o.oangle_eq_angle_of_sign_eq_one hs,
InnerProductGeometry.angle_add_eq_arctan_of_inner_eq_zero
(o.inner_eq_zero_of_oangle_eq_pi_div_two h) (o.left_ne_zero_of_oangle_eq_pi_div_two h)]
#align orientation.oangle_add_right_eq_arctan_of_oangle_eq_pi_div_two Orientation.oangle_add_right_eq_arctan_of_oangle_eq_pi_div_two
/-- An angle in a right-angled triangle expressed using `arctan`. -/
theorem oangle_add_left_eq_arctan_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) :
o.oangle (x + y) y = Real.arctan (‖x‖ / ‖y‖) := by
rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢
rw [add_comm]
exact (-o).oangle_add_right_eq_arctan_of_oangle_eq_pi_div_two h
#align orientation.oangle_add_left_eq_arctan_of_oangle_eq_pi_div_two Orientation.oangle_add_left_eq_arctan_of_oangle_eq_pi_div_two
/-- The cosine of an angle in a right-angled triangle as a ratio of sides. -/
theorem cos_oangle_add_right_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) :
Real.Angle.cos (o.oangle x (x + y)) = ‖x‖ / ‖x + y‖ := by
have hs : (o.oangle x (x + y)).sign = 1 := by
rw [oangle_sign_add_right, h, Real.Angle.sign_coe_pi_div_two]
rw [o.oangle_eq_angle_of_sign_eq_one hs, Real.Angle.cos_coe,
InnerProductGeometry.cos_angle_add_of_inner_eq_zero (o.inner_eq_zero_of_oangle_eq_pi_div_two h)]
#align orientation.cos_oangle_add_right_of_oangle_eq_pi_div_two Orientation.cos_oangle_add_right_of_oangle_eq_pi_div_two
/-- The cosine of an angle in a right-angled triangle as a ratio of sides. -/
theorem cos_oangle_add_left_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) :
Real.Angle.cos (o.oangle (x + y) y) = ‖y‖ / ‖x + y‖ := by
rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢
rw [add_comm]
exact (-o).cos_oangle_add_right_of_oangle_eq_pi_div_two h
#align orientation.cos_oangle_add_left_of_oangle_eq_pi_div_two Orientation.cos_oangle_add_left_of_oangle_eq_pi_div_two
/-- The sine of an angle in a right-angled triangle as a ratio of sides. -/
theorem sin_oangle_add_right_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) :
Real.Angle.sin (o.oangle x (x + y)) = ‖y‖ / ‖x + y‖ := by
have hs : (o.oangle x (x + y)).sign = 1 := by
rw [oangle_sign_add_right, h, Real.Angle.sign_coe_pi_div_two]
rw [o.oangle_eq_angle_of_sign_eq_one hs, Real.Angle.sin_coe,
InnerProductGeometry.sin_angle_add_of_inner_eq_zero (o.inner_eq_zero_of_oangle_eq_pi_div_two h)
(Or.inl (o.left_ne_zero_of_oangle_eq_pi_div_two h))]
#align orientation.sin_oangle_add_right_of_oangle_eq_pi_div_two Orientation.sin_oangle_add_right_of_oangle_eq_pi_div_two
/-- The sine of an angle in a right-angled triangle as a ratio of sides. -/
theorem sin_oangle_add_left_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) :
Real.Angle.sin (o.oangle (x + y) y) = ‖x‖ / ‖x + y‖ := by
rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢
rw [add_comm]
exact (-o).sin_oangle_add_right_of_oangle_eq_pi_div_two h
#align orientation.sin_oangle_add_left_of_oangle_eq_pi_div_two Orientation.sin_oangle_add_left_of_oangle_eq_pi_div_two
/-- The tangent of an angle in a right-angled triangle as a ratio of sides. -/
theorem tan_oangle_add_right_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) :
Real.Angle.tan (o.oangle x (x + y)) = ‖y‖ / ‖x‖ := by
have hs : (o.oangle x (x + y)).sign = 1 := by
rw [oangle_sign_add_right, h, Real.Angle.sign_coe_pi_div_two]
rw [o.oangle_eq_angle_of_sign_eq_one hs, Real.Angle.tan_coe,
InnerProductGeometry.tan_angle_add_of_inner_eq_zero (o.inner_eq_zero_of_oangle_eq_pi_div_two h)]
#align orientation.tan_oangle_add_right_of_oangle_eq_pi_div_two Orientation.tan_oangle_add_right_of_oangle_eq_pi_div_two
/-- The tangent of an angle in a right-angled triangle as a ratio of sides. -/
theorem tan_oangle_add_left_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) :
Real.Angle.tan (o.oangle (x + y) y) = ‖x‖ / ‖y‖ := by
rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢
rw [add_comm]
exact (-o).tan_oangle_add_right_of_oangle_eq_pi_div_two h
#align orientation.tan_oangle_add_left_of_oangle_eq_pi_div_two Orientation.tan_oangle_add_left_of_oangle_eq_pi_div_two
/-- The cosine of an angle in a right-angled triangle multiplied by the hypotenuse equals the
adjacent side. -/
theorem cos_oangle_add_right_mul_norm_of_oangle_eq_pi_div_two {x y : V}
(h : o.oangle x y = ↑(π / 2)) : Real.Angle.cos (o.oangle x (x + y)) * ‖x + y‖ = ‖x‖ := by
have hs : (o.oangle x (x + y)).sign = 1 := by
rw [oangle_sign_add_right, h, Real.Angle.sign_coe_pi_div_two]
rw [o.oangle_eq_angle_of_sign_eq_one hs, Real.Angle.cos_coe,
InnerProductGeometry.cos_angle_add_mul_norm_of_inner_eq_zero
(o.inner_eq_zero_of_oangle_eq_pi_div_two h)]
#align orientation.cos_oangle_add_right_mul_norm_of_oangle_eq_pi_div_two Orientation.cos_oangle_add_right_mul_norm_of_oangle_eq_pi_div_two
/-- The cosine of an angle in a right-angled triangle multiplied by the hypotenuse equals the
adjacent side. -/
theorem cos_oangle_add_left_mul_norm_of_oangle_eq_pi_div_two {x y : V}
(h : o.oangle x y = ↑(π / 2)) : Real.Angle.cos (o.oangle (x + y) y) * ‖x + y‖ = ‖y‖ := by
rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢
rw [add_comm]
exact (-o).cos_oangle_add_right_mul_norm_of_oangle_eq_pi_div_two h
#align orientation.cos_oangle_add_left_mul_norm_of_oangle_eq_pi_div_two Orientation.cos_oangle_add_left_mul_norm_of_oangle_eq_pi_div_two
/-- The sine of an angle in a right-angled triangle multiplied by the hypotenuse equals the
opposite side. -/
theorem sin_oangle_add_right_mul_norm_of_oangle_eq_pi_div_two {x y : V}
(h : o.oangle x y = ↑(π / 2)) : Real.Angle.sin (o.oangle x (x + y)) * ‖x + y‖ = ‖y‖ := by
have hs : (o.oangle x (x + y)).sign = 1 := by
rw [oangle_sign_add_right, h, Real.Angle.sign_coe_pi_div_two]
rw [o.oangle_eq_angle_of_sign_eq_one hs, Real.Angle.sin_coe,
InnerProductGeometry.sin_angle_add_mul_norm_of_inner_eq_zero
(o.inner_eq_zero_of_oangle_eq_pi_div_two h)]
#align orientation.sin_oangle_add_right_mul_norm_of_oangle_eq_pi_div_two Orientation.sin_oangle_add_right_mul_norm_of_oangle_eq_pi_div_two
/-- The sine of an angle in a right-angled triangle multiplied by the hypotenuse equals the
opposite side. -/
theorem sin_oangle_add_left_mul_norm_of_oangle_eq_pi_div_two {x y : V}
(h : o.oangle x y = ↑(π / 2)) : Real.Angle.sin (o.oangle (x + y) y) * ‖x + y‖ = ‖x‖ := by
rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢
rw [add_comm]
exact (-o).sin_oangle_add_right_mul_norm_of_oangle_eq_pi_div_two h
#align orientation.sin_oangle_add_left_mul_norm_of_oangle_eq_pi_div_two Orientation.sin_oangle_add_left_mul_norm_of_oangle_eq_pi_div_two
/-- The tangent of an angle in a right-angled triangle multiplied by the adjacent side equals
the opposite side. -/
theorem tan_oangle_add_right_mul_norm_of_oangle_eq_pi_div_two {x y : V}
(h : o.oangle x y = ↑(π / 2)) : Real.Angle.tan (o.oangle x (x + y)) * ‖x‖ = ‖y‖ := by
have hs : (o.oangle x (x + y)).sign = 1 := by
rw [oangle_sign_add_right, h, Real.Angle.sign_coe_pi_div_two]
rw [o.oangle_eq_angle_of_sign_eq_one hs, Real.Angle.tan_coe,
InnerProductGeometry.tan_angle_add_mul_norm_of_inner_eq_zero
(o.inner_eq_zero_of_oangle_eq_pi_div_two h)
(Or.inl (o.left_ne_zero_of_oangle_eq_pi_div_two h))]
#align orientation.tan_oangle_add_right_mul_norm_of_oangle_eq_pi_div_two Orientation.tan_oangle_add_right_mul_norm_of_oangle_eq_pi_div_two
/-- The tangent of an angle in a right-angled triangle multiplied by the adjacent side equals
the opposite side. -/
theorem tan_oangle_add_left_mul_norm_of_oangle_eq_pi_div_two {x y : V}
(h : o.oangle x y = ↑(π / 2)) : Real.Angle.tan (o.oangle (x + y) y) * ‖y‖ = ‖x‖ := by
rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢
rw [add_comm]
exact (-o).tan_oangle_add_right_mul_norm_of_oangle_eq_pi_div_two h
#align orientation.tan_oangle_add_left_mul_norm_of_oangle_eq_pi_div_two Orientation.tan_oangle_add_left_mul_norm_of_oangle_eq_pi_div_two
/-- A side of a right-angled triangle divided by the cosine of the adjacent angle equals the
hypotenuse. -/
theorem norm_div_cos_oangle_add_right_of_oangle_eq_pi_div_two {x y : V}
(h : o.oangle x y = ↑(π / 2)) : ‖x‖ / Real.Angle.cos (o.oangle x (x + y)) = ‖x + y‖ := by
have hs : (o.oangle x (x + y)).sign = 1 := by
rw [oangle_sign_add_right, h, Real.Angle.sign_coe_pi_div_two]
rw [o.oangle_eq_angle_of_sign_eq_one hs, Real.Angle.cos_coe,
InnerProductGeometry.norm_div_cos_angle_add_of_inner_eq_zero
(o.inner_eq_zero_of_oangle_eq_pi_div_two h)
(Or.inl (o.left_ne_zero_of_oangle_eq_pi_div_two h))]
#align orientation.norm_div_cos_oangle_add_right_of_oangle_eq_pi_div_two Orientation.norm_div_cos_oangle_add_right_of_oangle_eq_pi_div_two
/-- A side of a right-angled triangle divided by the cosine of the adjacent angle equals the
hypotenuse. -/
theorem norm_div_cos_oangle_add_left_of_oangle_eq_pi_div_two {x y : V}
(h : o.oangle x y = ↑(π / 2)) : ‖y‖ / Real.Angle.cos (o.oangle (x + y) y) = ‖x + y‖ := by
rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢
rw [add_comm]
exact (-o).norm_div_cos_oangle_add_right_of_oangle_eq_pi_div_two h
#align orientation.norm_div_cos_oangle_add_left_of_oangle_eq_pi_div_two Orientation.norm_div_cos_oangle_add_left_of_oangle_eq_pi_div_two
/-- A side of a right-angled triangle divided by the sine of the opposite angle equals the
hypotenuse. -/
theorem norm_div_sin_oangle_add_right_of_oangle_eq_pi_div_two {x y : V}
(h : o.oangle x y = ↑(π / 2)) : ‖y‖ / Real.Angle.sin (o.oangle x (x + y)) = ‖x + y‖ := by
have hs : (o.oangle x (x + y)).sign = 1 := by
rw [oangle_sign_add_right, h, Real.Angle.sign_coe_pi_div_two]
rw [o.oangle_eq_angle_of_sign_eq_one hs, Real.Angle.sin_coe,
InnerProductGeometry.norm_div_sin_angle_add_of_inner_eq_zero
(o.inner_eq_zero_of_oangle_eq_pi_div_two h)
(Or.inr (o.right_ne_zero_of_oangle_eq_pi_div_two h))]
#align orientation.norm_div_sin_oangle_add_right_of_oangle_eq_pi_div_two Orientation.norm_div_sin_oangle_add_right_of_oangle_eq_pi_div_two
/-- A side of a right-angled triangle divided by the sine of the opposite angle equals the
hypotenuse. -/
| Mathlib/Geometry/Euclidean/Angle/Oriented/RightAngle.lean | 238 | 242 | theorem norm_div_sin_oangle_add_left_of_oangle_eq_pi_div_two {x y : V}
(h : o.oangle x y = ↑(π / 2)) : ‖x‖ / Real.Angle.sin (o.oangle (x + y) y) = ‖x + y‖ := by |
rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢
rw [add_comm]
exact (-o).norm_div_sin_oangle_add_right_of_oangle_eq_pi_div_two h
|
/-
Copyright (c) 2020 Yury G. Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury G. Kudryashov
-/
import Mathlib.Algebra.Group.Pi.Lemmas
import Mathlib.Topology.Algebra.Monoid
import Mathlib.Topology.Homeomorph
#align_import topology.algebra.group_with_zero from "leanprover-community/mathlib"@"c10e724be91096453ee3db13862b9fb9a992fef2"
/-!
# Topological group with zero
In this file we define `HasContinuousInv₀` to be a mixin typeclass a type with `Inv` and
`Zero` (e.g., a `GroupWithZero`) such that `fun x ↦ x⁻¹` is continuous at all nonzero points. Any
normed (semi)field has this property. Currently the only example of `HasContinuousInv₀` in
`mathlib` which is not a normed field is the type `NNReal` (a.k.a. `ℝ≥0`) of nonnegative real
numbers.
Then we prove lemmas about continuity of `x ↦ x⁻¹` and `f / g` providing dot-style `*.inv₀` and
`*.div` operations on `Filter.Tendsto`, `ContinuousAt`, `ContinuousWithinAt`, `ContinuousOn`,
and `Continuous`. As a special case, we provide `*.div_const` operations that require only
`DivInvMonoid` and `ContinuousMul` instances.
All lemmas about `(⁻¹)` use `inv₀` in their names because lemmas without `₀` are used for
`TopologicalGroup`s. We also use `'` in the typeclass name `HasContinuousInv₀` for the sake of
consistency of notation.
On a `GroupWithZero` with continuous multiplication, we also define left and right multiplication
as homeomorphisms.
-/
open Topology Filter Function
/-!
### A `DivInvMonoid` with continuous multiplication
If `G₀` is a `DivInvMonoid` with continuous `(*)`, then `(/y)` is continuous for any `y`. In this
section we prove lemmas that immediately follow from this fact providing `*.div_const` dot-style
operations on `Filter.Tendsto`, `ContinuousAt`, `ContinuousWithinAt`, `ContinuousOn`, and
`Continuous`.
-/
variable {α β G₀ : Type*}
section DivConst
variable [DivInvMonoid G₀] [TopologicalSpace G₀] [ContinuousMul G₀] {f : α → G₀} {s : Set α}
{l : Filter α}
theorem Filter.Tendsto.div_const {x : G₀} (hf : Tendsto f l (𝓝 x)) (y : G₀) :
Tendsto (fun a => f a / y) l (𝓝 (x / y)) := by
simpa only [div_eq_mul_inv] using hf.mul tendsto_const_nhds
#align filter.tendsto.div_const Filter.Tendsto.div_const
variable [TopologicalSpace α]
nonrec theorem ContinuousAt.div_const {a : α} (hf : ContinuousAt f a) (y : G₀) :
ContinuousAt (fun x => f x / y) a :=
hf.div_const y
#align continuous_at.div_const ContinuousAt.div_const
nonrec theorem ContinuousWithinAt.div_const {a} (hf : ContinuousWithinAt f s a) (y : G₀) :
ContinuousWithinAt (fun x => f x / y) s a :=
hf.div_const _
#align continuous_within_at.div_const ContinuousWithinAt.div_const
theorem ContinuousOn.div_const (hf : ContinuousOn f s) (y : G₀) :
ContinuousOn (fun x => f x / y) s := by
simpa only [div_eq_mul_inv] using hf.mul continuousOn_const
#align continuous_on.div_const ContinuousOn.div_const
@[continuity]
theorem Continuous.div_const (hf : Continuous f) (y : G₀) : Continuous fun x => f x / y := by
simpa only [div_eq_mul_inv] using hf.mul continuous_const
#align continuous.div_const Continuous.div_const
end DivConst
/-- A type with `0` and `Inv` such that `fun x ↦ x⁻¹` is continuous at all nonzero points. Any
normed (semi)field has this property. -/
class HasContinuousInv₀ (G₀ : Type*) [Zero G₀] [Inv G₀] [TopologicalSpace G₀] : Prop where
/-- The map `fun x ↦ x⁻¹` is continuous at all nonzero points. -/
continuousAt_inv₀ : ∀ ⦃x : G₀⦄, x ≠ 0 → ContinuousAt Inv.inv x
#align has_continuous_inv₀ HasContinuousInv₀
export HasContinuousInv₀ (continuousAt_inv₀)
section Inv₀
variable [Zero G₀] [Inv G₀] [TopologicalSpace G₀] [HasContinuousInv₀ G₀] {l : Filter α} {f : α → G₀}
{s : Set α} {a : α}
/-!
### Continuity of `fun x ↦ x⁻¹` at a non-zero point
We define `HasContinuousInv₀` to be a `GroupWithZero` such that the operation `x ↦ x⁻¹`
is continuous at all nonzero points. In this section we prove dot-style `*.inv₀` lemmas for
`Filter.Tendsto`, `ContinuousAt`, `ContinuousWithinAt`, `ContinuousOn`, and `Continuous`.
-/
theorem tendsto_inv₀ {x : G₀} (hx : x ≠ 0) : Tendsto Inv.inv (𝓝 x) (𝓝 x⁻¹) :=
continuousAt_inv₀ hx
#align tendsto_inv₀ tendsto_inv₀
theorem continuousOn_inv₀ : ContinuousOn (Inv.inv : G₀ → G₀) {0}ᶜ := fun _x hx =>
(continuousAt_inv₀ hx).continuousWithinAt
#align continuous_on_inv₀ continuousOn_inv₀
/-- If a function converges to a nonzero value, its inverse converges to the inverse of this value.
We use the name `Filter.Tendsto.inv₀` as `Filter.Tendsto.inv` is already used in multiplicative
topological groups. -/
theorem Filter.Tendsto.inv₀ {a : G₀} (hf : Tendsto f l (𝓝 a)) (ha : a ≠ 0) :
Tendsto (fun x => (f x)⁻¹) l (𝓝 a⁻¹) :=
(tendsto_inv₀ ha).comp hf
#align filter.tendsto.inv₀ Filter.Tendsto.inv₀
variable [TopologicalSpace α]
nonrec theorem ContinuousWithinAt.inv₀ (hf : ContinuousWithinAt f s a) (ha : f a ≠ 0) :
ContinuousWithinAt (fun x => (f x)⁻¹) s a :=
hf.inv₀ ha
#align continuous_within_at.inv₀ ContinuousWithinAt.inv₀
@[fun_prop]
nonrec theorem ContinuousAt.inv₀ (hf : ContinuousAt f a) (ha : f a ≠ 0) :
ContinuousAt (fun x => (f x)⁻¹) a :=
hf.inv₀ ha
#align continuous_at.inv₀ ContinuousAt.inv₀
@[continuity, fun_prop]
theorem Continuous.inv₀ (hf : Continuous f) (h0 : ∀ x, f x ≠ 0) : Continuous fun x => (f x)⁻¹ :=
continuous_iff_continuousAt.2 fun x => (hf.tendsto x).inv₀ (h0 x)
#align continuous.inv₀ Continuous.inv₀
@[fun_prop]
theorem ContinuousOn.inv₀ (hf : ContinuousOn f s) (h0 : ∀ x ∈ s, f x ≠ 0) :
ContinuousOn (fun x => (f x)⁻¹) s := fun x hx => (hf x hx).inv₀ (h0 x hx)
#align continuous_on.inv₀ ContinuousOn.inv₀
end Inv₀
/-- If `G₀` is a group with zero with topology such that `x ↦ x⁻¹` is continuous at all nonzero
points. Then the coercion `G₀ˣ → G₀` is a topological embedding. -/
theorem Units.embedding_val₀ [GroupWithZero G₀] [TopologicalSpace G₀] [HasContinuousInv₀ G₀] :
Embedding (val : G₀ˣ → G₀) :=
embedding_val_mk <| (continuousOn_inv₀ (G₀ := G₀)).mono fun _ ↦ IsUnit.ne_zero
#align units.embedding_coe₀ Units.embedding_val₀
section NhdsInv
variable [GroupWithZero G₀] [TopologicalSpace G₀] [HasContinuousInv₀ G₀] {x : G₀}
lemma nhds_inv₀ (hx : x ≠ 0) : 𝓝 x⁻¹ = (𝓝 x)⁻¹ := by
refine le_antisymm (inv_le_iff_le_inv.1 ?_) (tendsto_inv₀ hx)
simpa only [inv_inv] using tendsto_inv₀ (inv_ne_zero hx)
lemma tendsto_inv_iff₀ {l : Filter α} {f : α → G₀} (hx : x ≠ 0) :
Tendsto (fun x ↦ (f x)⁻¹) l (𝓝 x⁻¹) ↔ Tendsto f l (𝓝 x) := by
simp only [nhds_inv₀ hx, ← Filter.comap_inv, tendsto_comap_iff, (· ∘ ·), inv_inv]
end NhdsInv
/-!
### Continuity of division
If `G₀` is a `GroupWithZero` with `x ↦ x⁻¹` continuous at all nonzero points and `(*)`, then
division `(/)` is continuous at any point where the denominator is continuous.
-/
section Div
variable [GroupWithZero G₀] [TopologicalSpace G₀] [HasContinuousInv₀ G₀] [ContinuousMul G₀]
{f g : α → G₀}
theorem Filter.Tendsto.div {l : Filter α} {a b : G₀} (hf : Tendsto f l (𝓝 a))
(hg : Tendsto g l (𝓝 b)) (hy : b ≠ 0) : Tendsto (f / g) l (𝓝 (a / b)) := by
simpa only [div_eq_mul_inv] using hf.mul (hg.inv₀ hy)
#align filter.tendsto.div Filter.Tendsto.div
theorem Filter.tendsto_mul_iff_of_ne_zero [T1Space G₀] {f g : α → G₀} {l : Filter α} {x y : G₀}
(hg : Tendsto g l (𝓝 y)) (hy : y ≠ 0) :
Tendsto (fun n => f n * g n) l (𝓝 <| x * y) ↔ Tendsto f l (𝓝 x) := by
refine ⟨fun hfg => ?_, fun hf => hf.mul hg⟩
rw [← mul_div_cancel_right₀ x hy]
refine Tendsto.congr' ?_ (hfg.div hg hy)
exact (hg.eventually_ne hy).mono fun n hn => mul_div_cancel_right₀ _ hn
#align filter.tendsto_mul_iff_of_ne_zero Filter.tendsto_mul_iff_of_ne_zero
variable [TopologicalSpace α] [TopologicalSpace β] {s : Set α} {a : α}
nonrec theorem ContinuousWithinAt.div (hf : ContinuousWithinAt f s a)
(hg : ContinuousWithinAt g s a) (h₀ : g a ≠ 0) : ContinuousWithinAt (f / g) s a :=
hf.div hg h₀
#align continuous_within_at.div ContinuousWithinAt.div
theorem ContinuousOn.div (hf : ContinuousOn f s) (hg : ContinuousOn g s) (h₀ : ∀ x ∈ s, g x ≠ 0) :
ContinuousOn (f / g) s := fun x hx => (hf x hx).div (hg x hx) (h₀ x hx)
#align continuous_on.div ContinuousOn.div
/-- Continuity at a point of the result of dividing two functions continuous at that point, where
the denominator is nonzero. -/
nonrec theorem ContinuousAt.div (hf : ContinuousAt f a) (hg : ContinuousAt g a) (h₀ : g a ≠ 0) :
ContinuousAt (f / g) a :=
hf.div hg h₀
#align continuous_at.div ContinuousAt.div
@[continuity]
theorem Continuous.div (hf : Continuous f) (hg : Continuous g) (h₀ : ∀ x, g x ≠ 0) :
Continuous (f / g) := by simpa only [div_eq_mul_inv] using hf.mul (hg.inv₀ h₀)
#align continuous.div Continuous.div
theorem continuousOn_div : ContinuousOn (fun p : G₀ × G₀ => p.1 / p.2) { p | p.2 ≠ 0 } :=
continuousOn_fst.div continuousOn_snd fun _ => id
#align continuous_on_div continuousOn_div
@[fun_prop]
theorem Continuous.div₀ (hf : Continuous f) (hg : Continuous g) (h₀ : ∀ x, g x ≠ 0) :
Continuous (fun x => f x / g x) := by
simpa only [div_eq_mul_inv] using hf.mul (hg.inv₀ h₀)
@[fun_prop]
theorem ContinuousAt.div₀ (hf : ContinuousAt f a) (hg : ContinuousAt g a) (h₀ : g a ≠ 0) :
ContinuousAt (fun x => f x / g x) a := ContinuousAt.div hf hg h₀
@[fun_prop]
theorem ContinuousOn.div₀ (hf : ContinuousOn f s) (hg : ContinuousOn g s) (h₀ : ∀ x ∈ s, g x ≠ 0) :
ContinuousOn (fun x => f x / g x) s := ContinuousOn.div hf hg h₀
/-- The function `f x / g x` is discontinuous when `g x = 0`. However, under appropriate
conditions, `h x (f x / g x)` is still continuous. The condition is that if `g a = 0` then `h x y`
must tend to `h a 0` when `x` tends to `a`, with no information about `y`. This is represented by
the `⊤` filter. Note: `tendsto_prod_top_iff` characterizes this convergence in uniform spaces. See
also `Filter.prod_top` and `Filter.mem_prod_top`. -/
theorem ContinuousAt.comp_div_cases {f g : α → G₀} (h : α → G₀ → β) (hf : ContinuousAt f a)
(hg : ContinuousAt g a) (hh : g a ≠ 0 → ContinuousAt (↿h) (a, f a / g a))
(h2h : g a = 0 → Tendsto (↿h) (𝓝 a ×ˢ ⊤) (𝓝 (h a 0))) :
ContinuousAt (fun x => h x (f x / g x)) a := by
show ContinuousAt (↿h ∘ fun x => (x, f x / g x)) a
by_cases hga : g a = 0
· rw [ContinuousAt]
simp_rw [comp_apply, hga, div_zero]
exact (h2h hga).comp (continuousAt_id.prod_mk tendsto_top)
· exact ContinuousAt.comp (hh hga) (continuousAt_id.prod (hf.div hg hga))
#align continuous_at.comp_div_cases ContinuousAt.comp_div_cases
/-- `h x (f x / g x)` is continuous under certain conditions, even if the denominator is sometimes
`0`. See docstring of `ContinuousAt.comp_div_cases`. -/
theorem Continuous.comp_div_cases {f g : α → G₀} (h : α → G₀ → β) (hf : Continuous f)
(hg : Continuous g) (hh : ∀ a, g a ≠ 0 → ContinuousAt (↿h) (a, f a / g a))
(h2h : ∀ a, g a = 0 → Tendsto (↿h) (𝓝 a ×ˢ ⊤) (𝓝 (h a 0))) :
Continuous fun x => h x (f x / g x) :=
continuous_iff_continuousAt.mpr fun a =>
hf.continuousAt.comp_div_cases _ hg.continuousAt (hh a) (h2h a)
#align continuous.comp_div_cases Continuous.comp_div_cases
end Div
/-! ### Left and right multiplication as homeomorphisms -/
namespace Homeomorph
variable [TopologicalSpace α] [GroupWithZero α] [ContinuousMul α]
/-- Left multiplication by a nonzero element in a `GroupWithZero` with continuous multiplication
is a homeomorphism of the underlying type. -/
protected def mulLeft₀ (c : α) (hc : c ≠ 0) : α ≃ₜ α :=
{ Equiv.mulLeft₀ c hc with
continuous_toFun := continuous_mul_left _
continuous_invFun := continuous_mul_left _ }
#align homeomorph.mul_left₀ Homeomorph.mulLeft₀
/-- Right multiplication by a nonzero element in a `GroupWithZero` with continuous multiplication
is a homeomorphism of the underlying type. -/
protected def mulRight₀ (c : α) (hc : c ≠ 0) : α ≃ₜ α :=
{ Equiv.mulRight₀ c hc with
continuous_toFun := continuous_mul_right _
continuous_invFun := continuous_mul_right _ }
#align homeomorph.mul_right₀ Homeomorph.mulRight₀
@[simp]
theorem coe_mulLeft₀ (c : α) (hc : c ≠ 0) : ⇑(Homeomorph.mulLeft₀ c hc) = (c * ·) :=
rfl
#align homeomorph.coe_mul_left₀ Homeomorph.coe_mulLeft₀
@[simp]
theorem mulLeft₀_symm_apply (c : α) (hc : c ≠ 0) :
((Homeomorph.mulLeft₀ c hc).symm : α → α) = (c⁻¹ * ·) :=
rfl
#align homeomorph.mul_left₀_symm_apply Homeomorph.mulLeft₀_symm_apply
@[simp]
theorem coe_mulRight₀ (c : α) (hc : c ≠ 0) : ⇑(Homeomorph.mulRight₀ c hc) = (· * c) :=
rfl
#align homeomorph.coe_mul_right₀ Homeomorph.coe_mulRight₀
@[simp]
theorem mulRight₀_symm_apply (c : α) (hc : c ≠ 0) :
((Homeomorph.mulRight₀ c hc).symm : α → α) = (· * c⁻¹) :=
rfl
#align homeomorph.mul_right₀_symm_apply Homeomorph.mulRight₀_symm_apply
end Homeomorph
section map_comap
variable [TopologicalSpace G₀] [GroupWithZero G₀] [ContinuousMul G₀] {a : G₀}
theorem map_mul_left_nhds₀ (ha : a ≠ 0) (b : G₀) : map (a * ·) (𝓝 b) = 𝓝 (a * b) :=
(Homeomorph.mulLeft₀ a ha).map_nhds_eq b
theorem map_mul_left_nhds_one₀ (ha : a ≠ 0) : map (a * ·) (𝓝 1) = 𝓝 (a) := by
rw [map_mul_left_nhds₀ ha, mul_one]
theorem map_mul_right_nhds₀ (ha : a ≠ 0) (b : G₀) : map (· * a) (𝓝 b) = 𝓝 (b * a) :=
(Homeomorph.mulRight₀ a ha).map_nhds_eq b
theorem map_mul_right_nhds_one₀ (ha : a ≠ 0) : map (· * a) (𝓝 1) = 𝓝 (a) := by
rw [map_mul_right_nhds₀ ha, one_mul]
theorem nhds_translation_mul_inv₀ (ha : a ≠ 0) : comap (· * a⁻¹) (𝓝 1) = 𝓝 a :=
((Homeomorph.mulRight₀ a ha).symm.comap_nhds_eq 1).trans <| by simp
/-- If a group with zero has continuous multiplication and `fun x ↦ x⁻¹` is continuous at one,
then it is continuous at any unit. -/
theorem HasContinuousInv₀.of_nhds_one (h : Tendsto Inv.inv (𝓝 (1 : G₀)) (𝓝 1)) :
HasContinuousInv₀ G₀ where
continuousAt_inv₀ x hx := by
have hx' := inv_ne_zero hx
rw [ContinuousAt, ← map_mul_left_nhds_one₀ hx, ← nhds_translation_mul_inv₀ hx',
tendsto_map'_iff, tendsto_comap_iff]
simpa only [(· ∘ ·), mul_inv_rev, mul_inv_cancel_right₀ hx']
end map_comap
section ZPow
variable [GroupWithZero G₀] [TopologicalSpace G₀] [HasContinuousInv₀ G₀] [ContinuousMul G₀]
| Mathlib/Topology/Algebra/GroupWithZero.lean | 342 | 348 | theorem continuousAt_zpow₀ (x : G₀) (m : ℤ) (h : x ≠ 0 ∨ 0 ≤ m) :
ContinuousAt (fun x => x ^ m) x := by |
cases' m with m m
· simpa only [Int.ofNat_eq_coe, zpow_natCast] using continuousAt_pow x m
· simp only [zpow_negSucc]
have hx : x ≠ 0 := h.resolve_right (Int.negSucc_lt_zero m).not_le
exact (continuousAt_pow x (m + 1)).inv₀ (pow_ne_zero _ hx)
|
/-
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, Scott Morrison, Jens Wagemaker
-/
import Mathlib.Algebra.GroupPower.IterateHom
import Mathlib.Algebra.Polynomial.Eval
import Mathlib.GroupTheory.GroupAction.Ring
#align_import data.polynomial.derivative from "leanprover-community/mathlib"@"bbeb185db4ccee8ed07dc48449414ebfa39cb821"
/-!
# The derivative map on polynomials
## Main definitions
* `Polynomial.derivative`: The formal derivative of polynomials, expressed as a linear map.
-/
noncomputable section
open Finset
open Polynomial
namespace Polynomial
universe u v w y z
variable {R : Type u} {S : Type v} {T : Type w} {ι : Type y} {A : Type z} {a b : R} {n : ℕ}
section Derivative
section Semiring
variable [Semiring R]
/-- `derivative p` is the formal derivative of the polynomial `p` -/
def derivative : R[X] →ₗ[R] R[X] where
toFun p := p.sum fun n a => C (a * n) * X ^ (n - 1)
map_add' p q := by
dsimp only
rw [sum_add_index] <;>
simp only [add_mul, forall_const, RingHom.map_add, eq_self_iff_true, zero_mul,
RingHom.map_zero]
map_smul' a p := by
dsimp; rw [sum_smul_index] <;>
simp only [mul_sum, ← C_mul', mul_assoc, coeff_C_mul, RingHom.map_mul, forall_const, zero_mul,
RingHom.map_zero, sum]
#align polynomial.derivative Polynomial.derivative
theorem derivative_apply (p : R[X]) : derivative p = p.sum fun n a => C (a * n) * X ^ (n - 1) :=
rfl
#align polynomial.derivative_apply Polynomial.derivative_apply
theorem coeff_derivative (p : R[X]) (n : ℕ) :
coeff (derivative p) n = coeff p (n + 1) * (n + 1) := by
rw [derivative_apply]
simp only [coeff_X_pow, coeff_sum, coeff_C_mul]
rw [sum, Finset.sum_eq_single (n + 1)]
· simp only [Nat.add_succ_sub_one, add_zero, mul_one, if_true, eq_self_iff_true]; norm_cast
· intro b
cases b
· intros
rw [Nat.cast_zero, mul_zero, zero_mul]
· intro _ H
rw [Nat.add_one_sub_one, if_neg (mt (congr_arg Nat.succ) H.symm), mul_zero]
· rw [if_pos (add_tsub_cancel_right n 1).symm, mul_one, Nat.cast_add, Nat.cast_one,
mem_support_iff]
intro h
push_neg at h
simp [h]
#align polynomial.coeff_derivative Polynomial.coeff_derivative
-- Porting note (#10618): removed `simp`: `simp` can prove it.
theorem derivative_zero : derivative (0 : R[X]) = 0 :=
derivative.map_zero
#align polynomial.derivative_zero Polynomial.derivative_zero
theorem iterate_derivative_zero {k : ℕ} : derivative^[k] (0 : R[X]) = 0 :=
iterate_map_zero derivative k
#align polynomial.iterate_derivative_zero Polynomial.iterate_derivative_zero
@[simp]
theorem derivative_monomial (a : R) (n : ℕ) :
derivative (monomial n a) = monomial (n - 1) (a * n) := by
rw [derivative_apply, sum_monomial_index, C_mul_X_pow_eq_monomial]
simp
#align polynomial.derivative_monomial Polynomial.derivative_monomial
theorem derivative_C_mul_X (a : R) : derivative (C a * X) = C a := by
simp [C_mul_X_eq_monomial, derivative_monomial, Nat.cast_one, mul_one]
set_option linter.uppercaseLean3 false in
#align polynomial.derivative_C_mul_X Polynomial.derivative_C_mul_X
theorem derivative_C_mul_X_pow (a : R) (n : ℕ) :
derivative (C a * X ^ n) = C (a * n) * X ^ (n - 1) := by
rw [C_mul_X_pow_eq_monomial, C_mul_X_pow_eq_monomial, derivative_monomial]
set_option linter.uppercaseLean3 false in
#align polynomial.derivative_C_mul_X_pow Polynomial.derivative_C_mul_X_pow
theorem derivative_C_mul_X_sq (a : R) : derivative (C a * X ^ 2) = C (a * 2) * X := by
rw [derivative_C_mul_X_pow, Nat.cast_two, pow_one]
set_option linter.uppercaseLean3 false in
#align polynomial.derivative_C_mul_X_sq Polynomial.derivative_C_mul_X_sq
@[simp]
theorem derivative_X_pow (n : ℕ) : derivative (X ^ n : R[X]) = C (n : R) * X ^ (n - 1) := by
convert derivative_C_mul_X_pow (1 : R) n <;> simp
set_option linter.uppercaseLean3 false in
#align polynomial.derivative_X_pow Polynomial.derivative_X_pow
-- Porting note (#10618): removed `simp`: `simp` can prove it.
theorem derivative_X_sq : derivative (X ^ 2 : R[X]) = C 2 * X := by
rw [derivative_X_pow, Nat.cast_two, pow_one]
set_option linter.uppercaseLean3 false in
#align polynomial.derivative_X_sq Polynomial.derivative_X_sq
@[simp]
theorem derivative_C {a : R} : derivative (C a) = 0 := by simp [derivative_apply]
set_option linter.uppercaseLean3 false in
#align polynomial.derivative_C Polynomial.derivative_C
theorem derivative_of_natDegree_zero {p : R[X]} (hp : p.natDegree = 0) : derivative p = 0 := by
rw [eq_C_of_natDegree_eq_zero hp, derivative_C]
#align polynomial.derivative_of_nat_degree_zero Polynomial.derivative_of_natDegree_zero
@[simp]
theorem derivative_X : derivative (X : R[X]) = 1 :=
(derivative_monomial _ _).trans <| by simp
set_option linter.uppercaseLean3 false in
#align polynomial.derivative_X Polynomial.derivative_X
@[simp]
theorem derivative_one : derivative (1 : R[X]) = 0 :=
derivative_C
#align polynomial.derivative_one Polynomial.derivative_one
#noalign polynomial.derivative_bit0
#noalign polynomial.derivative_bit1
-- Porting note (#10618): removed `simp`: `simp` can prove it.
theorem derivative_add {f g : R[X]} : derivative (f + g) = derivative f + derivative g :=
derivative.map_add f g
#align polynomial.derivative_add Polynomial.derivative_add
-- Porting note (#10618): removed `simp`: `simp` can prove it.
theorem derivative_X_add_C (c : R) : derivative (X + C c) = 1 := by
rw [derivative_add, derivative_X, derivative_C, add_zero]
set_option linter.uppercaseLean3 false in
#align polynomial.derivative_X_add_C Polynomial.derivative_X_add_C
-- Porting note (#10618): removed `simp`: `simp` can prove it.
theorem derivative_sum {s : Finset ι} {f : ι → R[X]} :
derivative (∑ b ∈ s, f b) = ∑ b ∈ s, derivative (f b) :=
map_sum ..
#align polynomial.derivative_sum Polynomial.derivative_sum
-- Porting note (#10618): removed `simp`: `simp` can prove it.
theorem derivative_smul {S : Type*} [Monoid S] [DistribMulAction S R] [IsScalarTower S R R] (s : S)
(p : R[X]) : derivative (s • p) = s • derivative p :=
derivative.map_smul_of_tower s p
#align polynomial.derivative_smul Polynomial.derivative_smul
@[simp]
theorem iterate_derivative_smul {S : Type*} [Monoid S] [DistribMulAction S R] [IsScalarTower S R R]
(s : S) (p : R[X]) (k : ℕ) : derivative^[k] (s • p) = s • derivative^[k] p := by
induction' k with k ih generalizing p
· simp
· simp [ih]
#align polynomial.iterate_derivative_smul Polynomial.iterate_derivative_smul
@[simp]
theorem iterate_derivative_C_mul (a : R) (p : R[X]) (k : ℕ) :
derivative^[k] (C a * p) = C a * derivative^[k] p := by
simp_rw [← smul_eq_C_mul, iterate_derivative_smul]
set_option linter.uppercaseLean3 false in
#align polynomial.iterate_derivative_C_mul Polynomial.iterate_derivative_C_mul
theorem of_mem_support_derivative {p : R[X]} {n : ℕ} (h : n ∈ p.derivative.support) :
n + 1 ∈ p.support :=
mem_support_iff.2 fun h1 : p.coeff (n + 1) = 0 =>
mem_support_iff.1 h <| show p.derivative.coeff n = 0 by rw [coeff_derivative, h1, zero_mul]
#align polynomial.of_mem_support_derivative Polynomial.of_mem_support_derivative
theorem degree_derivative_lt {p : R[X]} (hp : p ≠ 0) : p.derivative.degree < p.degree :=
(Finset.sup_lt_iff <| bot_lt_iff_ne_bot.2 <| mt degree_eq_bot.1 hp).2 fun n hp =>
lt_of_lt_of_le (WithBot.coe_lt_coe.2 n.lt_succ_self) <|
Finset.le_sup <| of_mem_support_derivative hp
#align polynomial.degree_derivative_lt Polynomial.degree_derivative_lt
theorem degree_derivative_le {p : R[X]} : p.derivative.degree ≤ p.degree :=
letI := Classical.decEq R
if H : p = 0 then le_of_eq <| by rw [H, derivative_zero] else (degree_derivative_lt H).le
#align polynomial.degree_derivative_le Polynomial.degree_derivative_le
| Mathlib/Algebra/Polynomial/Derivative.lean | 198 | 204 | theorem natDegree_derivative_lt {p : R[X]} (hp : p.natDegree ≠ 0) :
p.derivative.natDegree < p.natDegree := by |
rcases eq_or_ne (derivative p) 0 with hp' | hp'
· rw [hp', Polynomial.natDegree_zero]
exact hp.bot_lt
· rw [natDegree_lt_natDegree_iff hp']
exact degree_derivative_lt fun h => hp (h.symm ▸ natDegree_zero)
|
/-
Copyright (c) 2021 Frédéric Dupuis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Frédéric Dupuis
-/
import Mathlib.Algebra.Group.Subgroup.Basic
import Mathlib.Algebra.Module.Defs
import Mathlib.Algebra.Star.Pi
#align_import algebra.star.self_adjoint from "leanprover-community/mathlib"@"a6ece35404f60597c651689c1b46ead86de5ac1b"
/-!
# Self-adjoint, skew-adjoint and normal elements of a star additive group
This file defines `selfAdjoint R` (resp. `skewAdjoint R`), where `R` is a star additive group,
as the additive subgroup containing the elements that satisfy `star x = x` (resp. `star x = -x`).
This includes, for instance, (skew-)Hermitian operators on Hilbert spaces.
We also define `IsStarNormal R`, a `Prop` that states that an element `x` satisfies
`star x * x = x * star x`.
## Implementation notes
* When `R` is a `StarModule R₂ R`, then `selfAdjoint R` has a natural
`Module (selfAdjoint R₂) (selfAdjoint R)` structure. However, doing this literally would be
undesirable since in the main case of interest (`R₂ = ℂ`) we want `Module ℝ (selfAdjoint R)`
and not `Module (selfAdjoint ℂ) (selfAdjoint R)`. We solve this issue by adding the typeclass
`[TrivialStar R₃]`, of which `ℝ` is an instance (registered in `Data/Real/Basic`), and then
add a `[Module R₃ (selfAdjoint R)]` instance whenever we have
`[Module R₃ R] [TrivialStar R₃]`. (Another approach would have been to define
`[StarInvariantScalars R₃ R]` to express the fact that `star (x • v) = x • star v`, but
this typeclass would have the disadvantage of taking two type arguments.)
## TODO
* Define `IsSkewAdjoint` to match `IsSelfAdjoint`.
* Define `fun z x => z * x * star z` (i.e. conjugation by `z`) as a monoid action of `R` on `R`
(similar to the existing `ConjAct` for groups), and then state the fact that `selfAdjoint R` is
invariant under it.
-/
open Function
variable {R A : Type*}
/-- An element is self-adjoint if it is equal to its star. -/
def IsSelfAdjoint [Star R] (x : R) : Prop :=
star x = x
#align is_self_adjoint IsSelfAdjoint
/-- An element of a star monoid is normal if it commutes with its adjoint. -/
@[mk_iff]
class IsStarNormal [Mul R] [Star R] (x : R) : Prop where
/-- A normal element of a star monoid commutes with its adjoint. -/
star_comm_self : Commute (star x) x
#align is_star_normal IsStarNormal
export IsStarNormal (star_comm_self)
theorem star_comm_self' [Mul R] [Star R] (x : R) [IsStarNormal x] : star x * x = x * star x :=
IsStarNormal.star_comm_self
#align star_comm_self' star_comm_self'
namespace IsSelfAdjoint
-- named to match `Commute.allₓ`
/-- All elements are self-adjoint when `star` is trivial. -/
theorem all [Star R] [TrivialStar R] (r : R) : IsSelfAdjoint r :=
star_trivial _
#align is_self_adjoint.all IsSelfAdjoint.all
theorem star_eq [Star R] {x : R} (hx : IsSelfAdjoint x) : star x = x :=
hx
#align is_self_adjoint.star_eq IsSelfAdjoint.star_eq
theorem _root_.isSelfAdjoint_iff [Star R] {x : R} : IsSelfAdjoint x ↔ star x = x :=
Iff.rfl
#align is_self_adjoint_iff isSelfAdjoint_iff
@[simp]
theorem star_iff [InvolutiveStar R] {x : R} : IsSelfAdjoint (star x) ↔ IsSelfAdjoint x := by
simpa only [IsSelfAdjoint, star_star] using eq_comm
#align is_self_adjoint.star_iff IsSelfAdjoint.star_iff
@[simp]
theorem star_mul_self [Mul R] [StarMul R] (x : R) : IsSelfAdjoint (star x * x) := by
simp only [IsSelfAdjoint, star_mul, star_star]
#align is_self_adjoint.star_mul_self IsSelfAdjoint.star_mul_self
@[simp]
theorem mul_star_self [Mul R] [StarMul R] (x : R) : IsSelfAdjoint (x * star x) := by
simpa only [star_star] using star_mul_self (star x)
#align is_self_adjoint.mul_star_self IsSelfAdjoint.mul_star_self
/-- Self-adjoint elements commute if and only if their product is self-adjoint. -/
lemma commute_iff {R : Type*} [Mul R] [StarMul R] {x y : R}
(hx : IsSelfAdjoint x) (hy : IsSelfAdjoint y) : Commute x y ↔ IsSelfAdjoint (x * y) := by
refine ⟨fun h ↦ ?_, fun h ↦ ?_⟩
· rw [isSelfAdjoint_iff, star_mul, hx.star_eq, hy.star_eq, h.eq]
· simpa only [star_mul, hx.star_eq, hy.star_eq] using h.symm
/-- Functions in a `StarHomClass` preserve self-adjoint elements. -/
theorem starHom_apply {F R S : Type*} [Star R] [Star S] [FunLike F R S] [StarHomClass F R S]
{x : R} (hx : IsSelfAdjoint x) (f : F) : IsSelfAdjoint (f x) :=
show star (f x) = f x from map_star f x ▸ congr_arg f hx
#align is_self_adjoint.star_hom_apply IsSelfAdjoint.starHom_apply
/- note: this lemma is *not* marked as `simp` so that Lean doesn't look for a `[TrivialStar R]`
instance every time it sees `⊢ IsSelfAdjoint (f x)`, which will likely occur relatively often. -/
theorem _root_.isSelfAdjoint_starHom_apply {F R S : Type*} [Star R] [Star S] [FunLike F R S]
[StarHomClass F R S] [TrivialStar R] (f : F) (x : R) : IsSelfAdjoint (f x) :=
(IsSelfAdjoint.all x).starHom_apply f
section AddMonoid
variable [AddMonoid R] [StarAddMonoid R]
variable (R)
@[simp] theorem _root_.isSelfAdjoint_zero : IsSelfAdjoint (0 : R) := star_zero R
#align is_self_adjoint_zero isSelfAdjoint_zero
variable {R}
theorem add {x y : R} (hx : IsSelfAdjoint x) (hy : IsSelfAdjoint y) : IsSelfAdjoint (x + y) := by
simp only [isSelfAdjoint_iff, star_add, hx.star_eq, hy.star_eq]
#align is_self_adjoint.add IsSelfAdjoint.add
#noalign is_self_adjoint.bit0
end AddMonoid
section AddGroup
variable [AddGroup R] [StarAddMonoid R]
theorem neg {x : R} (hx : IsSelfAdjoint x) : IsSelfAdjoint (-x) := by
simp only [isSelfAdjoint_iff, star_neg, hx.star_eq]
#align is_self_adjoint.neg IsSelfAdjoint.neg
theorem sub {x y : R} (hx : IsSelfAdjoint x) (hy : IsSelfAdjoint y) : IsSelfAdjoint (x - y) := by
simp only [isSelfAdjoint_iff, star_sub, hx.star_eq, hy.star_eq]
#align is_self_adjoint.sub IsSelfAdjoint.sub
end AddGroup
section AddCommMonoid
variable [AddCommMonoid R] [StarAddMonoid R]
theorem _root_.isSelfAdjoint_add_star_self (x : R) : IsSelfAdjoint (x + star x) := by
simp only [isSelfAdjoint_iff, add_comm, star_add, star_star]
#align is_self_adjoint_add_star_self isSelfAdjoint_add_star_self
theorem _root_.isSelfAdjoint_star_add_self (x : R) : IsSelfAdjoint (star x + x) := by
simp only [isSelfAdjoint_iff, add_comm, star_add, star_star]
#align is_self_adjoint_star_add_self isSelfAdjoint_star_add_self
end AddCommMonoid
section Semigroup
variable [Semigroup R] [StarMul R]
| Mathlib/Algebra/Star/SelfAdjoint.lean | 165 | 166 | theorem conjugate {x : R} (hx : IsSelfAdjoint x) (z : R) : IsSelfAdjoint (z * x * star z) := by |
simp only [isSelfAdjoint_iff, star_mul, star_star, mul_assoc, hx.star_eq]
|
/-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Johan Commelin, Mario Carneiro
-/
import Mathlib.Algebra.Algebra.Tower
import Mathlib.Algebra.GroupWithZero.Divisibility
import Mathlib.Algebra.Regular.Pow
import Mathlib.Algebra.MonoidAlgebra.Support
import Mathlib.Data.Finsupp.Antidiagonal
import Mathlib.Order.SymmDiff
import Mathlib.RingTheory.Adjoin.Basic
#align_import data.mv_polynomial.basic from "leanprover-community/mathlib"@"c8734e8953e4b439147bd6f75c2163f6d27cdce6"
/-!
# Multivariate polynomials
This file defines polynomial rings over a base ring (or even semiring),
with variables from a general type `σ` (which could be infinite).
## Important definitions
Let `R` be a commutative ring (or a semiring) and let `σ` be an arbitrary
type. This file creates the type `MvPolynomial σ R`, which mathematicians
might denote $R[X_i : i \in σ]$. It is the type of multivariate
(a.k.a. multivariable) polynomials, with variables
corresponding to the terms in `σ`, and coefficients in `R`.
### Notation
In the definitions below, we use the following notation:
+ `σ : Type*` (indexing the variables)
+ `R : Type*` `[CommSemiring R]` (the coefficients)
+ `s : σ →₀ ℕ`, a function from `σ` to `ℕ` which is zero away from a finite set.
This will give rise to a monomial in `MvPolynomial σ R` which mathematicians might call `X^s`
+ `a : R`
+ `i : σ`, with corresponding monomial `X i`, often denoted `X_i` by mathematicians
+ `p : MvPolynomial σ R`
### Definitions
* `MvPolynomial σ R` : the type of polynomials with variables of type `σ` and coefficients
in the commutative semiring `R`
* `monomial s a` : the monomial which mathematically would be denoted `a * X^s`
* `C a` : the constant polynomial with value `a`
* `X i` : the degree one monomial corresponding to i; mathematically this might be denoted `Xᵢ`.
* `coeff s p` : the coefficient of `s` in `p`.
* `eval₂ (f : R → S₁) (g : σ → S₁) p` : given a semiring homomorphism from `R` to another
semiring `S₁`, and a map `σ → S₁`, evaluates `p` at this valuation, returning a term of type `S₁`.
Note that `eval₂` can be made using `eval` and `map` (see below), and it has been suggested
that sticking to `eval` and `map` might make the code less brittle.
* `eval (g : σ → R) p` : given a map `σ → R`, evaluates `p` at this valuation,
returning a term of type `R`
* `map (f : R → S₁) p` : returns the multivariate polynomial obtained from `p` by the change of
coefficient semiring corresponding to `f`
## Implementation notes
Recall that if `Y` has a zero, then `X →₀ Y` is the type of functions from `X` to `Y` with finite
support, i.e. such that only finitely many elements of `X` get sent to non-zero terms in `Y`.
The definition of `MvPolynomial σ R` is `(σ →₀ ℕ) →₀ R`; here `σ →₀ ℕ` denotes the space of all
monomials in the variables, and the function to `R` sends a monomial to its coefficient in
the polynomial being represented.
## Tags
polynomial, multivariate polynomial, multivariable polynomial
-/
noncomputable section
open Set Function Finsupp AddMonoidAlgebra
open scoped Pointwise
universe u v w x
variable {R : Type u} {S₁ : Type v} {S₂ : Type w} {S₃ : Type x}
/-- Multivariate polynomial, where `σ` is the index set of the variables and
`R` is the coefficient ring -/
def MvPolynomial (σ : Type*) (R : Type*) [CommSemiring R] :=
AddMonoidAlgebra R (σ →₀ ℕ)
#align mv_polynomial MvPolynomial
namespace MvPolynomial
-- Porting note: because of `MvPolynomial.C` and `MvPolynomial.X` this linter throws
-- tons of warnings in this file, and it's easier to just disable them globally in the file
set_option linter.uppercaseLean3 false
variable {σ : Type*} {a a' a₁ a₂ : R} {e : ℕ} {n m : σ} {s : σ →₀ ℕ}
section CommSemiring
section Instances
instance decidableEqMvPolynomial [CommSemiring R] [DecidableEq σ] [DecidableEq R] :
DecidableEq (MvPolynomial σ R) :=
Finsupp.instDecidableEq
#align mv_polynomial.decidable_eq_mv_polynomial MvPolynomial.decidableEqMvPolynomial
instance commSemiring [CommSemiring R] : CommSemiring (MvPolynomial σ R) :=
AddMonoidAlgebra.commSemiring
instance inhabited [CommSemiring R] : Inhabited (MvPolynomial σ R) :=
⟨0⟩
instance distribuMulAction [Monoid R] [CommSemiring S₁] [DistribMulAction R S₁] :
DistribMulAction R (MvPolynomial σ S₁) :=
AddMonoidAlgebra.distribMulAction
instance smulZeroClass [CommSemiring S₁] [SMulZeroClass R S₁] :
SMulZeroClass R (MvPolynomial σ S₁) :=
AddMonoidAlgebra.smulZeroClass
instance faithfulSMul [CommSemiring S₁] [SMulZeroClass R S₁] [FaithfulSMul R S₁] :
FaithfulSMul R (MvPolynomial σ S₁) :=
AddMonoidAlgebra.faithfulSMul
instance module [Semiring R] [CommSemiring S₁] [Module R S₁] : Module R (MvPolynomial σ S₁) :=
AddMonoidAlgebra.module
instance isScalarTower [CommSemiring S₂] [SMul R S₁] [SMulZeroClass R S₂] [SMulZeroClass S₁ S₂]
[IsScalarTower R S₁ S₂] : IsScalarTower R S₁ (MvPolynomial σ S₂) :=
AddMonoidAlgebra.isScalarTower
instance smulCommClass [CommSemiring S₂] [SMulZeroClass R S₂] [SMulZeroClass S₁ S₂]
[SMulCommClass R S₁ S₂] : SMulCommClass R S₁ (MvPolynomial σ S₂) :=
AddMonoidAlgebra.smulCommClass
instance isCentralScalar [CommSemiring S₁] [SMulZeroClass R S₁] [SMulZeroClass Rᵐᵒᵖ S₁]
[IsCentralScalar R S₁] : IsCentralScalar R (MvPolynomial σ S₁) :=
AddMonoidAlgebra.isCentralScalar
instance algebra [CommSemiring R] [CommSemiring S₁] [Algebra R S₁] :
Algebra R (MvPolynomial σ S₁) :=
AddMonoidAlgebra.algebra
instance isScalarTower_right [CommSemiring S₁] [DistribSMul R S₁] [IsScalarTower R S₁ S₁] :
IsScalarTower R (MvPolynomial σ S₁) (MvPolynomial σ S₁) :=
AddMonoidAlgebra.isScalarTower_self _
#align mv_polynomial.is_scalar_tower_right MvPolynomial.isScalarTower_right
instance smulCommClass_right [CommSemiring S₁] [DistribSMul R S₁] [SMulCommClass R S₁ S₁] :
SMulCommClass R (MvPolynomial σ S₁) (MvPolynomial σ S₁) :=
AddMonoidAlgebra.smulCommClass_self _
#align mv_polynomial.smul_comm_class_right MvPolynomial.smulCommClass_right
/-- If `R` is a subsingleton, then `MvPolynomial σ R` has a unique element -/
instance unique [CommSemiring R] [Subsingleton R] : Unique (MvPolynomial σ R) :=
AddMonoidAlgebra.unique
#align mv_polynomial.unique MvPolynomial.unique
end Instances
variable [CommSemiring R] [CommSemiring S₁] {p q : MvPolynomial σ R}
/-- `monomial s a` is the monomial with coefficient `a` and exponents given by `s` -/
def monomial (s : σ →₀ ℕ) : R →ₗ[R] MvPolynomial σ R :=
lsingle s
#align mv_polynomial.monomial MvPolynomial.monomial
theorem single_eq_monomial (s : σ →₀ ℕ) (a : R) : Finsupp.single s a = monomial s a :=
rfl
#align mv_polynomial.single_eq_monomial MvPolynomial.single_eq_monomial
theorem mul_def : p * q = p.sum fun m a => q.sum fun n b => monomial (m + n) (a * b) :=
AddMonoidAlgebra.mul_def
#align mv_polynomial.mul_def MvPolynomial.mul_def
/-- `C a` is the constant polynomial with value `a` -/
def C : R →+* MvPolynomial σ R :=
{ singleZeroRingHom with toFun := monomial 0 }
#align mv_polynomial.C MvPolynomial.C
variable (R σ)
@[simp]
theorem algebraMap_eq : algebraMap R (MvPolynomial σ R) = C :=
rfl
#align mv_polynomial.algebra_map_eq MvPolynomial.algebraMap_eq
variable {R σ}
/-- `X n` is the degree `1` monomial $X_n$. -/
def X (n : σ) : MvPolynomial σ R :=
monomial (Finsupp.single n 1) 1
#align mv_polynomial.X MvPolynomial.X
theorem monomial_left_injective {r : R} (hr : r ≠ 0) :
Function.Injective fun s : σ →₀ ℕ => monomial s r :=
Finsupp.single_left_injective hr
#align mv_polynomial.monomial_left_injective MvPolynomial.monomial_left_injective
@[simp]
theorem monomial_left_inj {s t : σ →₀ ℕ} {r : R} (hr : r ≠ 0) :
monomial s r = monomial t r ↔ s = t :=
Finsupp.single_left_inj hr
#align mv_polynomial.monomial_left_inj MvPolynomial.monomial_left_inj
theorem C_apply : (C a : MvPolynomial σ R) = monomial 0 a :=
rfl
#align mv_polynomial.C_apply MvPolynomial.C_apply
-- Porting note (#10618): `simp` can prove this
theorem C_0 : C 0 = (0 : MvPolynomial σ R) := map_zero _
#align mv_polynomial.C_0 MvPolynomial.C_0
-- Porting note (#10618): `simp` can prove this
theorem C_1 : C 1 = (1 : MvPolynomial σ R) :=
rfl
#align mv_polynomial.C_1 MvPolynomial.C_1
theorem C_mul_monomial : C a * monomial s a' = monomial s (a * a') := by
-- Porting note: this `show` feels like defeq abuse, but I can't find the appropriate lemmas
show AddMonoidAlgebra.single _ _ * AddMonoidAlgebra.single _ _ = AddMonoidAlgebra.single _ _
simp [C_apply, single_mul_single]
#align mv_polynomial.C_mul_monomial MvPolynomial.C_mul_monomial
-- Porting note (#10618): `simp` can prove this
theorem C_add : (C (a + a') : MvPolynomial σ R) = C a + C a' :=
Finsupp.single_add _ _ _
#align mv_polynomial.C_add MvPolynomial.C_add
-- Porting note (#10618): `simp` can prove this
theorem C_mul : (C (a * a') : MvPolynomial σ R) = C a * C a' :=
C_mul_monomial.symm
#align mv_polynomial.C_mul MvPolynomial.C_mul
-- Porting note (#10618): `simp` can prove this
theorem C_pow (a : R) (n : ℕ) : (C (a ^ n) : MvPolynomial σ R) = C a ^ n :=
map_pow _ _ _
#align mv_polynomial.C_pow MvPolynomial.C_pow
theorem C_injective (σ : Type*) (R : Type*) [CommSemiring R] :
Function.Injective (C : R → MvPolynomial σ R) :=
Finsupp.single_injective _
#align mv_polynomial.C_injective MvPolynomial.C_injective
theorem C_surjective {R : Type*} [CommSemiring R] (σ : Type*) [IsEmpty σ] :
Function.Surjective (C : R → MvPolynomial σ R) := by
refine fun p => ⟨p.toFun 0, Finsupp.ext fun a => ?_⟩
simp only [C_apply, ← single_eq_monomial, (Finsupp.ext isEmptyElim (α := σ) : a = 0),
single_eq_same]
rfl
#align mv_polynomial.C_surjective MvPolynomial.C_surjective
@[simp]
theorem C_inj {σ : Type*} (R : Type*) [CommSemiring R] (r s : R) :
(C r : MvPolynomial σ R) = C s ↔ r = s :=
(C_injective σ R).eq_iff
#align mv_polynomial.C_inj MvPolynomial.C_inj
instance nontrivial_of_nontrivial (σ : Type*) (R : Type*) [CommSemiring R] [Nontrivial R] :
Nontrivial (MvPolynomial σ R) :=
inferInstanceAs (Nontrivial <| AddMonoidAlgebra R (σ →₀ ℕ))
instance infinite_of_infinite (σ : Type*) (R : Type*) [CommSemiring R] [Infinite R] :
Infinite (MvPolynomial σ R) :=
Infinite.of_injective C (C_injective _ _)
#align mv_polynomial.infinite_of_infinite MvPolynomial.infinite_of_infinite
instance infinite_of_nonempty (σ : Type*) (R : Type*) [Nonempty σ] [CommSemiring R]
[Nontrivial R] : Infinite (MvPolynomial σ R) :=
Infinite.of_injective ((fun s : σ →₀ ℕ => monomial s 1) ∘ Finsupp.single (Classical.arbitrary σ))
<| (monomial_left_injective one_ne_zero).comp (Finsupp.single_injective _)
#align mv_polynomial.infinite_of_nonempty MvPolynomial.infinite_of_nonempty
theorem C_eq_coe_nat (n : ℕ) : (C ↑n : MvPolynomial σ R) = n := by
induction n <;> simp [Nat.succ_eq_add_one, *]
#align mv_polynomial.C_eq_coe_nat MvPolynomial.C_eq_coe_nat
theorem C_mul' : MvPolynomial.C a * p = a • p :=
(Algebra.smul_def a p).symm
#align mv_polynomial.C_mul' MvPolynomial.C_mul'
theorem smul_eq_C_mul (p : MvPolynomial σ R) (a : R) : a • p = C a * p :=
C_mul'.symm
#align mv_polynomial.smul_eq_C_mul MvPolynomial.smul_eq_C_mul
theorem C_eq_smul_one : (C a : MvPolynomial σ R) = a • (1 : MvPolynomial σ R) := by
rw [← C_mul', mul_one]
#align mv_polynomial.C_eq_smul_one MvPolynomial.C_eq_smul_one
theorem smul_monomial {S₁ : Type*} [SMulZeroClass S₁ R] (r : S₁) :
r • monomial s a = monomial s (r • a) :=
Finsupp.smul_single _ _ _
#align mv_polynomial.smul_monomial MvPolynomial.smul_monomial
theorem X_injective [Nontrivial R] : Function.Injective (X : σ → MvPolynomial σ R) :=
(monomial_left_injective one_ne_zero).comp (Finsupp.single_left_injective one_ne_zero)
#align mv_polynomial.X_injective MvPolynomial.X_injective
@[simp]
theorem X_inj [Nontrivial R] (m n : σ) : X m = (X n : MvPolynomial σ R) ↔ m = n :=
X_injective.eq_iff
#align mv_polynomial.X_inj MvPolynomial.X_inj
theorem monomial_pow : monomial s a ^ e = monomial (e • s) (a ^ e) :=
AddMonoidAlgebra.single_pow e
#align mv_polynomial.monomial_pow MvPolynomial.monomial_pow
@[simp]
theorem monomial_mul {s s' : σ →₀ ℕ} {a b : R} :
monomial s a * monomial s' b = monomial (s + s') (a * b) :=
AddMonoidAlgebra.single_mul_single
#align mv_polynomial.monomial_mul MvPolynomial.monomial_mul
variable (σ R)
/-- `fun s ↦ monomial s 1` as a homomorphism. -/
def monomialOneHom : Multiplicative (σ →₀ ℕ) →* MvPolynomial σ R :=
AddMonoidAlgebra.of _ _
#align mv_polynomial.monomial_one_hom MvPolynomial.monomialOneHom
variable {σ R}
@[simp]
theorem monomialOneHom_apply : monomialOneHom R σ s = (monomial s 1 : MvPolynomial σ R) :=
rfl
#align mv_polynomial.monomial_one_hom_apply MvPolynomial.monomialOneHom_apply
theorem X_pow_eq_monomial : X n ^ e = monomial (Finsupp.single n e) (1 : R) := by
simp [X, monomial_pow]
#align mv_polynomial.X_pow_eq_monomial MvPolynomial.X_pow_eq_monomial
theorem monomial_add_single : monomial (s + Finsupp.single n e) a = monomial s a * X n ^ e := by
rw [X_pow_eq_monomial, monomial_mul, mul_one]
#align mv_polynomial.monomial_add_single MvPolynomial.monomial_add_single
theorem monomial_single_add : monomial (Finsupp.single n e + s) a = X n ^ e * monomial s a := by
rw [X_pow_eq_monomial, monomial_mul, one_mul]
#align mv_polynomial.monomial_single_add MvPolynomial.monomial_single_add
theorem C_mul_X_pow_eq_monomial {s : σ} {a : R} {n : ℕ} :
C a * X s ^ n = monomial (Finsupp.single s n) a := by
rw [← zero_add (Finsupp.single s n), monomial_add_single, C_apply]
#align mv_polynomial.C_mul_X_pow_eq_monomial MvPolynomial.C_mul_X_pow_eq_monomial
theorem C_mul_X_eq_monomial {s : σ} {a : R} : C a * X s = monomial (Finsupp.single s 1) a := by
rw [← C_mul_X_pow_eq_monomial, pow_one]
#align mv_polynomial.C_mul_X_eq_monomial MvPolynomial.C_mul_X_eq_monomial
-- Porting note (#10618): `simp` can prove this
theorem monomial_zero {s : σ →₀ ℕ} : monomial s (0 : R) = 0 :=
Finsupp.single_zero _
#align mv_polynomial.monomial_zero MvPolynomial.monomial_zero
@[simp]
theorem monomial_zero' : (monomial (0 : σ →₀ ℕ) : R → MvPolynomial σ R) = C :=
rfl
#align mv_polynomial.monomial_zero' MvPolynomial.monomial_zero'
@[simp]
theorem monomial_eq_zero {s : σ →₀ ℕ} {b : R} : monomial s b = 0 ↔ b = 0 :=
Finsupp.single_eq_zero
#align mv_polynomial.monomial_eq_zero MvPolynomial.monomial_eq_zero
@[simp]
theorem sum_monomial_eq {A : Type*} [AddCommMonoid A] {u : σ →₀ ℕ} {r : R} {b : (σ →₀ ℕ) → R → A}
(w : b u 0 = 0) : sum (monomial u r) b = b u r :=
Finsupp.sum_single_index w
#align mv_polynomial.sum_monomial_eq MvPolynomial.sum_monomial_eq
@[simp]
theorem sum_C {A : Type*} [AddCommMonoid A] {b : (σ →₀ ℕ) → R → A} (w : b 0 0 = 0) :
sum (C a) b = b 0 a :=
sum_monomial_eq w
#align mv_polynomial.sum_C MvPolynomial.sum_C
theorem monomial_sum_one {α : Type*} (s : Finset α) (f : α → σ →₀ ℕ) :
(monomial (∑ i ∈ s, f i) 1 : MvPolynomial σ R) = ∏ i ∈ s, monomial (f i) 1 :=
map_prod (monomialOneHom R σ) (fun i => Multiplicative.ofAdd (f i)) s
#align mv_polynomial.monomial_sum_one MvPolynomial.monomial_sum_one
theorem monomial_sum_index {α : Type*} (s : Finset α) (f : α → σ →₀ ℕ) (a : R) :
monomial (∑ i ∈ s, f i) a = C a * ∏ i ∈ s, monomial (f i) 1 := by
rw [← monomial_sum_one, C_mul', ← (monomial _).map_smul, smul_eq_mul, mul_one]
#align mv_polynomial.monomial_sum_index MvPolynomial.monomial_sum_index
theorem monomial_finsupp_sum_index {α β : Type*} [Zero β] (f : α →₀ β) (g : α → β → σ →₀ ℕ)
(a : R) : monomial (f.sum g) a = C a * f.prod fun a b => monomial (g a b) 1 :=
monomial_sum_index _ _ _
#align mv_polynomial.monomial_finsupp_sum_index MvPolynomial.monomial_finsupp_sum_index
theorem monomial_eq_monomial_iff {α : Type*} (a₁ a₂ : α →₀ ℕ) (b₁ b₂ : R) :
monomial a₁ b₁ = monomial a₂ b₂ ↔ a₁ = a₂ ∧ b₁ = b₂ ∨ b₁ = 0 ∧ b₂ = 0 :=
Finsupp.single_eq_single_iff _ _ _ _
#align mv_polynomial.monomial_eq_monomial_iff MvPolynomial.monomial_eq_monomial_iff
theorem monomial_eq : monomial s a = C a * (s.prod fun n e => X n ^ e : MvPolynomial σ R) := by
simp only [X_pow_eq_monomial, ← monomial_finsupp_sum_index, Finsupp.sum_single]
#align mv_polynomial.monomial_eq MvPolynomial.monomial_eq
@[simp]
lemma prod_X_pow_eq_monomial : ∏ x ∈ s.support, X x ^ s x = monomial s (1 : R) := by
simp only [monomial_eq, map_one, one_mul, Finsupp.prod]
theorem induction_on_monomial {M : MvPolynomial σ R → Prop} (h_C : ∀ a, M (C a))
(h_X : ∀ p n, M p → M (p * X n)) : ∀ s a, M (monomial s a) := by
intro s a
apply @Finsupp.induction σ ℕ _ _ s
· show M (monomial 0 a)
exact h_C a
· intro n e p _hpn _he ih
have : ∀ e : ℕ, M (monomial p a * X n ^ e) := by
intro e
induction e with
| zero => simp [ih]
| succ e e_ih => simp [ih, pow_succ, (mul_assoc _ _ _).symm, h_X, e_ih]
simp [add_comm, monomial_add_single, this]
#align mv_polynomial.induction_on_monomial MvPolynomial.induction_on_monomial
/-- Analog of `Polynomial.induction_on'`.
To prove something about mv_polynomials,
it suffices to show the condition is closed under taking sums,
and it holds for monomials. -/
@[elab_as_elim]
theorem induction_on' {P : MvPolynomial σ R → Prop} (p : MvPolynomial σ R)
(h1 : ∀ (u : σ →₀ ℕ) (a : R), P (monomial u a))
(h2 : ∀ p q : MvPolynomial σ R, P p → P q → P (p + q)) : P p :=
Finsupp.induction p
(suffices P (monomial 0 0) by rwa [monomial_zero] at this
show P (monomial 0 0) from h1 0 0)
fun a b f _ha _hb hPf => h2 _ _ (h1 _ _) hPf
#align mv_polynomial.induction_on' MvPolynomial.induction_on'
/-- Similar to `MvPolynomial.induction_on` but only a weak form of `h_add` is required. -/
theorem induction_on''' {M : MvPolynomial σ R → Prop} (p : MvPolynomial σ R) (h_C : ∀ a, M (C a))
(h_add_weak :
∀ (a : σ →₀ ℕ) (b : R) (f : (σ →₀ ℕ) →₀ R),
a ∉ f.support → b ≠ 0 → M f → M ((show (σ →₀ ℕ) →₀ R from monomial a b) + f)) :
M p :=
-- Porting note: I had to add the `show ... from ...` above, a type ascription was insufficient.
Finsupp.induction p (C_0.rec <| h_C 0) h_add_weak
#align mv_polynomial.induction_on''' MvPolynomial.induction_on'''
/-- Similar to `MvPolynomial.induction_on` but only a yet weaker form of `h_add` is required. -/
theorem induction_on'' {M : MvPolynomial σ R → Prop} (p : MvPolynomial σ R) (h_C : ∀ a, M (C a))
(h_add_weak :
∀ (a : σ →₀ ℕ) (b : R) (f : (σ →₀ ℕ) →₀ R),
a ∉ f.support → b ≠ 0 → M f → M (monomial a b) →
M ((show (σ →₀ ℕ) →₀ R from monomial a b) + f))
(h_X : ∀ (p : MvPolynomial σ R) (n : σ), M p → M (p * MvPolynomial.X n)) : M p :=
-- Porting note: I had to add the `show ... from ...` above, a type ascription was insufficient.
induction_on''' p h_C fun a b f ha hb hf =>
h_add_weak a b f ha hb hf <| induction_on_monomial h_C h_X a b
#align mv_polynomial.induction_on'' MvPolynomial.induction_on''
/-- Analog of `Polynomial.induction_on`. -/
@[recursor 5]
theorem induction_on {M : MvPolynomial σ R → Prop} (p : MvPolynomial σ R) (h_C : ∀ a, M (C a))
(h_add : ∀ p q, M p → M q → M (p + q)) (h_X : ∀ p n, M p → M (p * X n)) : M p :=
induction_on'' p h_C (fun a b f _ha _hb hf hm => h_add (monomial a b) f hm hf) h_X
#align mv_polynomial.induction_on MvPolynomial.induction_on
theorem ringHom_ext {A : Type*} [Semiring A] {f g : MvPolynomial σ R →+* A}
(hC : ∀ r, f (C r) = g (C r)) (hX : ∀ i, f (X i) = g (X i)) : f = g := by
refine AddMonoidAlgebra.ringHom_ext' ?_ ?_
-- Porting note: this has high priority, but Lean still chooses `RingHom.ext`, why?
-- probably because of the type synonym
· ext x
exact hC _
· apply Finsupp.mulHom_ext'; intros x
-- Porting note: `Finsupp.mulHom_ext'` needs to have increased priority
apply MonoidHom.ext_mnat
exact hX _
#align mv_polynomial.ring_hom_ext MvPolynomial.ringHom_ext
/-- See note [partially-applied ext lemmas]. -/
@[ext 1100]
theorem ringHom_ext' {A : Type*} [Semiring A] {f g : MvPolynomial σ R →+* A}
(hC : f.comp C = g.comp C) (hX : ∀ i, f (X i) = g (X i)) : f = g :=
ringHom_ext (RingHom.ext_iff.1 hC) hX
#align mv_polynomial.ring_hom_ext' MvPolynomial.ringHom_ext'
theorem hom_eq_hom [Semiring S₂] (f g : MvPolynomial σ R →+* S₂) (hC : f.comp C = g.comp C)
(hX : ∀ n : σ, f (X n) = g (X n)) (p : MvPolynomial σ R) : f p = g p :=
RingHom.congr_fun (ringHom_ext' hC hX) p
#align mv_polynomial.hom_eq_hom MvPolynomial.hom_eq_hom
theorem is_id (f : MvPolynomial σ R →+* MvPolynomial σ R) (hC : f.comp C = C)
(hX : ∀ n : σ, f (X n) = X n) (p : MvPolynomial σ R) : f p = p :=
hom_eq_hom f (RingHom.id _) hC hX p
#align mv_polynomial.is_id MvPolynomial.is_id
@[ext 1100]
theorem algHom_ext' {A B : Type*} [CommSemiring A] [CommSemiring B] [Algebra R A] [Algebra R B]
{f g : MvPolynomial σ A →ₐ[R] B}
(h₁ :
f.comp (IsScalarTower.toAlgHom R A (MvPolynomial σ A)) =
g.comp (IsScalarTower.toAlgHom R A (MvPolynomial σ A)))
(h₂ : ∀ i, f (X i) = g (X i)) : f = g :=
AlgHom.coe_ringHom_injective (MvPolynomial.ringHom_ext' (congr_arg AlgHom.toRingHom h₁) h₂)
#align mv_polynomial.alg_hom_ext' MvPolynomial.algHom_ext'
@[ext 1200]
theorem algHom_ext {A : Type*} [Semiring A] [Algebra R A] {f g : MvPolynomial σ R →ₐ[R] A}
(hf : ∀ i : σ, f (X i) = g (X i)) : f = g :=
AddMonoidAlgebra.algHom_ext' (mulHom_ext' fun X : σ => MonoidHom.ext_mnat (hf X))
#align mv_polynomial.alg_hom_ext MvPolynomial.algHom_ext
@[simp]
theorem algHom_C {τ : Type*} (f : MvPolynomial σ R →ₐ[R] MvPolynomial τ R) (r : R) :
f (C r) = C r :=
f.commutes r
#align mv_polynomial.alg_hom_C MvPolynomial.algHom_C
@[simp]
theorem adjoin_range_X : Algebra.adjoin R (range (X : σ → MvPolynomial σ R)) = ⊤ := by
set S := Algebra.adjoin R (range (X : σ → MvPolynomial σ R))
refine top_unique fun p hp => ?_; clear hp
induction p using MvPolynomial.induction_on with
| h_C => exact S.algebraMap_mem _
| h_add p q hp hq => exact S.add_mem hp hq
| h_X p i hp => exact S.mul_mem hp (Algebra.subset_adjoin <| mem_range_self _)
#align mv_polynomial.adjoin_range_X MvPolynomial.adjoin_range_X
@[ext]
theorem linearMap_ext {M : Type*} [AddCommMonoid M] [Module R M] {f g : MvPolynomial σ R →ₗ[R] M}
(h : ∀ s, f ∘ₗ monomial s = g ∘ₗ monomial s) : f = g :=
Finsupp.lhom_ext' h
#align mv_polynomial.linear_map_ext MvPolynomial.linearMap_ext
section Support
/-- The finite set of all `m : σ →₀ ℕ` such that `X^m` has a non-zero coefficient. -/
def support (p : MvPolynomial σ R) : Finset (σ →₀ ℕ) :=
Finsupp.support p
#align mv_polynomial.support MvPolynomial.support
theorem finsupp_support_eq_support (p : MvPolynomial σ R) : Finsupp.support p = p.support :=
rfl
#align mv_polynomial.finsupp_support_eq_support MvPolynomial.finsupp_support_eq_support
theorem support_monomial [h : Decidable (a = 0)] :
(monomial s a).support = if a = 0 then ∅ else {s} := by
rw [← Subsingleton.elim (Classical.decEq R a 0) h]
rfl
-- Porting note: the proof in Lean 3 wasn't fundamentally better and needed `by convert rfl`
-- the issue is the different decidability instances in the `ite` expressions
#align mv_polynomial.support_monomial MvPolynomial.support_monomial
theorem support_monomial_subset : (monomial s a).support ⊆ {s} :=
support_single_subset
#align mv_polynomial.support_monomial_subset MvPolynomial.support_monomial_subset
theorem support_add [DecidableEq σ] : (p + q).support ⊆ p.support ∪ q.support :=
Finsupp.support_add
#align mv_polynomial.support_add MvPolynomial.support_add
theorem support_X [Nontrivial R] : (X n : MvPolynomial σ R).support = {Finsupp.single n 1} := by
classical rw [X, support_monomial, if_neg]; exact one_ne_zero
#align mv_polynomial.support_X MvPolynomial.support_X
theorem support_X_pow [Nontrivial R] (s : σ) (n : ℕ) :
(X s ^ n : MvPolynomial σ R).support = {Finsupp.single s n} := by
classical
rw [X_pow_eq_monomial, support_monomial, if_neg (one_ne_zero' R)]
#align mv_polynomial.support_X_pow MvPolynomial.support_X_pow
@[simp]
theorem support_zero : (0 : MvPolynomial σ R).support = ∅ :=
rfl
#align mv_polynomial.support_zero MvPolynomial.support_zero
theorem support_smul {S₁ : Type*} [SMulZeroClass S₁ R] {a : S₁} {f : MvPolynomial σ R} :
(a • f).support ⊆ f.support :=
Finsupp.support_smul
#align mv_polynomial.support_smul MvPolynomial.support_smul
theorem support_sum {α : Type*} [DecidableEq σ] {s : Finset α} {f : α → MvPolynomial σ R} :
(∑ x ∈ s, f x).support ⊆ s.biUnion fun x => (f x).support :=
Finsupp.support_finset_sum
#align mv_polynomial.support_sum MvPolynomial.support_sum
end Support
section Coeff
/-- The coefficient of the monomial `m` in the multi-variable polynomial `p`. -/
def coeff (m : σ →₀ ℕ) (p : MvPolynomial σ R) : R :=
@DFunLike.coe ((σ →₀ ℕ) →₀ R) _ _ _ p m
-- Porting note: I changed this from `@CoeFun.coe _ _ (MonoidAlgebra.coeFun _ _) p m` because
-- I think it should work better syntactically. They are defeq.
#align mv_polynomial.coeff MvPolynomial.coeff
@[simp]
theorem mem_support_iff {p : MvPolynomial σ R} {m : σ →₀ ℕ} : m ∈ p.support ↔ p.coeff m ≠ 0 := by
simp [support, coeff]
#align mv_polynomial.mem_support_iff MvPolynomial.mem_support_iff
theorem not_mem_support_iff {p : MvPolynomial σ R} {m : σ →₀ ℕ} : m ∉ p.support ↔ p.coeff m = 0 :=
by simp
#align mv_polynomial.not_mem_support_iff MvPolynomial.not_mem_support_iff
theorem sum_def {A} [AddCommMonoid A] {p : MvPolynomial σ R} {b : (σ →₀ ℕ) → R → A} :
p.sum b = ∑ m ∈ p.support, b m (p.coeff m) := by simp [support, Finsupp.sum, coeff]
#align mv_polynomial.sum_def MvPolynomial.sum_def
theorem support_mul [DecidableEq σ] (p q : MvPolynomial σ R) :
(p * q).support ⊆ p.support + q.support :=
AddMonoidAlgebra.support_mul p q
#align mv_polynomial.support_mul MvPolynomial.support_mul
@[ext]
theorem ext (p q : MvPolynomial σ R) : (∀ m, coeff m p = coeff m q) → p = q :=
Finsupp.ext
#align mv_polynomial.ext MvPolynomial.ext
theorem ext_iff (p q : MvPolynomial σ R) : p = q ↔ ∀ m, coeff m p = coeff m q :=
⟨fun h m => by rw [h], ext p q⟩
#align mv_polynomial.ext_iff MvPolynomial.ext_iff
@[simp]
theorem coeff_add (m : σ →₀ ℕ) (p q : MvPolynomial σ R) : coeff m (p + q) = coeff m p + coeff m q :=
add_apply p q m
#align mv_polynomial.coeff_add MvPolynomial.coeff_add
@[simp]
theorem coeff_smul {S₁ : Type*} [SMulZeroClass S₁ R] (m : σ →₀ ℕ) (C : S₁) (p : MvPolynomial σ R) :
coeff m (C • p) = C • coeff m p :=
smul_apply C p m
#align mv_polynomial.coeff_smul MvPolynomial.coeff_smul
@[simp]
theorem coeff_zero (m : σ →₀ ℕ) : coeff m (0 : MvPolynomial σ R) = 0 :=
rfl
#align mv_polynomial.coeff_zero MvPolynomial.coeff_zero
@[simp]
theorem coeff_zero_X (i : σ) : coeff 0 (X i : MvPolynomial σ R) = 0 :=
single_eq_of_ne fun h => by cases Finsupp.single_eq_zero.1 h
#align mv_polynomial.coeff_zero_X MvPolynomial.coeff_zero_X
/-- `MvPolynomial.coeff m` but promoted to an `AddMonoidHom`. -/
@[simps]
def coeffAddMonoidHom (m : σ →₀ ℕ) : MvPolynomial σ R →+ R where
toFun := coeff m
map_zero' := coeff_zero m
map_add' := coeff_add m
#align mv_polynomial.coeff_add_monoid_hom MvPolynomial.coeffAddMonoidHom
variable (R) in
/-- `MvPolynomial.coeff m` but promoted to a `LinearMap`. -/
@[simps]
def lcoeff (m : σ →₀ ℕ) : MvPolynomial σ R →ₗ[R] R where
toFun := coeff m
map_add' := coeff_add m
map_smul' := coeff_smul m
theorem coeff_sum {X : Type*} (s : Finset X) (f : X → MvPolynomial σ R) (m : σ →₀ ℕ) :
coeff m (∑ x ∈ s, f x) = ∑ x ∈ s, coeff m (f x) :=
map_sum (@coeffAddMonoidHom R σ _ _) _ s
#align mv_polynomial.coeff_sum MvPolynomial.coeff_sum
theorem monic_monomial_eq (m) :
monomial m (1 : R) = (m.prod fun n e => X n ^ e : MvPolynomial σ R) := by simp [monomial_eq]
#align mv_polynomial.monic_monomial_eq MvPolynomial.monic_monomial_eq
@[simp]
theorem coeff_monomial [DecidableEq σ] (m n) (a) :
coeff m (monomial n a : MvPolynomial σ R) = if n = m then a else 0 :=
Finsupp.single_apply
#align mv_polynomial.coeff_monomial MvPolynomial.coeff_monomial
@[simp]
theorem coeff_C [DecidableEq σ] (m) (a) :
coeff m (C a : MvPolynomial σ R) = if 0 = m then a else 0 :=
Finsupp.single_apply
#align mv_polynomial.coeff_C MvPolynomial.coeff_C
lemma eq_C_of_isEmpty [IsEmpty σ] (p : MvPolynomial σ R) :
p = C (p.coeff 0) := by
obtain ⟨x, rfl⟩ := C_surjective σ p
simp
theorem coeff_one [DecidableEq σ] (m) : coeff m (1 : MvPolynomial σ R) = if 0 = m then 1 else 0 :=
coeff_C m 1
#align mv_polynomial.coeff_one MvPolynomial.coeff_one
@[simp]
theorem coeff_zero_C (a) : coeff 0 (C a : MvPolynomial σ R) = a :=
single_eq_same
#align mv_polynomial.coeff_zero_C MvPolynomial.coeff_zero_C
@[simp]
theorem coeff_zero_one : coeff 0 (1 : MvPolynomial σ R) = 1 :=
coeff_zero_C 1
#align mv_polynomial.coeff_zero_one MvPolynomial.coeff_zero_one
theorem coeff_X_pow [DecidableEq σ] (i : σ) (m) (k : ℕ) :
coeff m (X i ^ k : MvPolynomial σ R) = if Finsupp.single i k = m then 1 else 0 := by
have := coeff_monomial m (Finsupp.single i k) (1 : R)
rwa [@monomial_eq _ _ (1 : R) (Finsupp.single i k) _, C_1, one_mul, Finsupp.prod_single_index]
at this
exact pow_zero _
#align mv_polynomial.coeff_X_pow MvPolynomial.coeff_X_pow
theorem coeff_X' [DecidableEq σ] (i : σ) (m) :
coeff m (X i : MvPolynomial σ R) = if Finsupp.single i 1 = m then 1 else 0 := by
rw [← coeff_X_pow, pow_one]
#align mv_polynomial.coeff_X' MvPolynomial.coeff_X'
@[simp]
theorem coeff_X (i : σ) : coeff (Finsupp.single i 1) (X i : MvPolynomial σ R) = 1 := by
classical rw [coeff_X', if_pos rfl]
#align mv_polynomial.coeff_X MvPolynomial.coeff_X
@[simp]
theorem coeff_C_mul (m) (a : R) (p : MvPolynomial σ R) : coeff m (C a * p) = a * coeff m p := by
classical
rw [mul_def, sum_C]
· simp (config := { contextual := true }) [sum_def, coeff_sum]
simp
#align mv_polynomial.coeff_C_mul MvPolynomial.coeff_C_mul
theorem coeff_mul [DecidableEq σ] (p q : MvPolynomial σ R) (n : σ →₀ ℕ) :
coeff n (p * q) = ∑ x ∈ Finset.antidiagonal n, coeff x.1 p * coeff x.2 q :=
AddMonoidAlgebra.mul_apply_antidiagonal p q _ _ Finset.mem_antidiagonal
#align mv_polynomial.coeff_mul MvPolynomial.coeff_mul
@[simp]
theorem coeff_mul_monomial (m) (s : σ →₀ ℕ) (r : R) (p : MvPolynomial σ R) :
coeff (m + s) (p * monomial s r) = coeff m p * r :=
AddMonoidAlgebra.mul_single_apply_aux p _ _ _ _ fun _a => add_left_inj _
#align mv_polynomial.coeff_mul_monomial MvPolynomial.coeff_mul_monomial
@[simp]
theorem coeff_monomial_mul (m) (s : σ →₀ ℕ) (r : R) (p : MvPolynomial σ R) :
coeff (s + m) (monomial s r * p) = r * coeff m p :=
AddMonoidAlgebra.single_mul_apply_aux p _ _ _ _ fun _a => add_right_inj _
#align mv_polynomial.coeff_monomial_mul MvPolynomial.coeff_monomial_mul
@[simp]
theorem coeff_mul_X (m) (s : σ) (p : MvPolynomial σ R) :
coeff (m + Finsupp.single s 1) (p * X s) = coeff m p :=
(coeff_mul_monomial _ _ _ _).trans (mul_one _)
#align mv_polynomial.coeff_mul_X MvPolynomial.coeff_mul_X
@[simp]
theorem coeff_X_mul (m) (s : σ) (p : MvPolynomial σ R) :
coeff (Finsupp.single s 1 + m) (X s * p) = coeff m p :=
(coeff_monomial_mul _ _ _ _).trans (one_mul _)
#align mv_polynomial.coeff_X_mul MvPolynomial.coeff_X_mul
lemma coeff_single_X_pow [DecidableEq σ] (s s' : σ) (n n' : ℕ) :
(X (R := R) s ^ n).coeff (Finsupp.single s' n')
= if s = s' ∧ n = n' ∨ n = 0 ∧ n' = 0 then 1 else 0 := by
simp only [coeff_X_pow, single_eq_single_iff]
@[simp]
lemma coeff_single_X [DecidableEq σ] (s s' : σ) (n : ℕ) :
(X s).coeff (R := R) (Finsupp.single s' n) = if n = 1 ∧ s = s' then 1 else 0 := by
simpa [eq_comm, and_comm] using coeff_single_X_pow s s' 1 n
@[simp]
theorem support_mul_X (s : σ) (p : MvPolynomial σ R) :
(p * X s).support = p.support.map (addRightEmbedding (Finsupp.single s 1)) :=
AddMonoidAlgebra.support_mul_single p _ (by simp) _
#align mv_polynomial.support_mul_X MvPolynomial.support_mul_X
@[simp]
theorem support_X_mul (s : σ) (p : MvPolynomial σ R) :
(X s * p).support = p.support.map (addLeftEmbedding (Finsupp.single s 1)) :=
AddMonoidAlgebra.support_single_mul p _ (by simp) _
#align mv_polynomial.support_X_mul MvPolynomial.support_X_mul
@[simp]
theorem support_smul_eq {S₁ : Type*} [Semiring S₁] [Module S₁ R] [NoZeroSMulDivisors S₁ R] {a : S₁}
(h : a ≠ 0) (p : MvPolynomial σ R) : (a • p).support = p.support :=
Finsupp.support_smul_eq h
#align mv_polynomial.support_smul_eq MvPolynomial.support_smul_eq
theorem support_sdiff_support_subset_support_add [DecidableEq σ] (p q : MvPolynomial σ R) :
p.support \ q.support ⊆ (p + q).support := by
intro m hm
simp only [Classical.not_not, mem_support_iff, Finset.mem_sdiff, Ne] at hm
simp [hm.2, hm.1]
#align mv_polynomial.support_sdiff_support_subset_support_add MvPolynomial.support_sdiff_support_subset_support_add
open scoped symmDiff in
theorem support_symmDiff_support_subset_support_add [DecidableEq σ] (p q : MvPolynomial σ R) :
p.support ∆ q.support ⊆ (p + q).support := by
rw [symmDiff_def, Finset.sup_eq_union]
apply Finset.union_subset
· exact support_sdiff_support_subset_support_add p q
· rw [add_comm]
exact support_sdiff_support_subset_support_add q p
#align mv_polynomial.support_symm_diff_support_subset_support_add MvPolynomial.support_symmDiff_support_subset_support_add
| Mathlib/Algebra/MvPolynomial/Basic.lean | 795 | 807 | theorem coeff_mul_monomial' (m) (s : σ →₀ ℕ) (r : R) (p : MvPolynomial σ R) :
coeff m (p * monomial s r) = if s ≤ m then coeff (m - s) p * r else 0 := by |
classical
split_ifs with h
· conv_rhs => rw [← coeff_mul_monomial _ s]
congr with t
rw [tsub_add_cancel_of_le h]
· contrapose! h
rw [← mem_support_iff] at h
obtain ⟨j, -, rfl⟩ : ∃ j ∈ support p, j + s = m := by
simpa [Finset.add_singleton]
using Finset.add_subset_add_left support_monomial_subset <| support_mul _ _ h
exact le_add_left le_rfl
|
/-
Copyright (c) 2021 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin, Eric Wieser
-/
import Mathlib.LinearAlgebra.Matrix.DotProduct
import Mathlib.LinearAlgebra.Determinant
import Mathlib.LinearAlgebra.Matrix.Diagonal
#align_import data.matrix.rank from "leanprover-community/mathlib"@"17219820a8aa8abe85adf5dfde19af1dd1bd8ae7"
/-!
# Rank of matrices
The rank of a matrix `A` is defined to be the rank of range of the linear map corresponding to `A`.
This definition does not depend on the choice of basis, see `Matrix.rank_eq_finrank_range_toLin`.
## Main declarations
* `Matrix.rank`: the rank of a matrix
## TODO
* Do a better job of generalizing over `ℚ`, `ℝ`, and `ℂ` in `Matrix.rank_transpose` and
`Matrix.rank_conjTranspose`. See
[this Zulip thread](https://leanprover.zulipchat.com/#narrow/stream/116395-maths/topic/row.20rank.20equals.20column.20rank/near/350462992).
-/
open Matrix
namespace Matrix
open FiniteDimensional
variable {l m n o R : Type*} [Fintype n] [Fintype o]
section CommRing
variable [CommRing R]
/-- The rank of a matrix is the rank of its image. -/
noncomputable def rank (A : Matrix m n R) : ℕ :=
finrank R <| LinearMap.range A.mulVecLin
#align matrix.rank Matrix.rank
@[simp]
theorem rank_one [StrongRankCondition R] [DecidableEq n] :
rank (1 : Matrix n n R) = Fintype.card n := by
rw [rank, mulVecLin_one, LinearMap.range_id, finrank_top, finrank_pi]
#align matrix.rank_one Matrix.rank_one
@[simp]
theorem rank_zero [Nontrivial R] : rank (0 : Matrix m n R) = 0 := by
rw [rank, mulVecLin_zero, LinearMap.range_zero, finrank_bot]
#align matrix.rank_zero Matrix.rank_zero
theorem rank_le_card_width [StrongRankCondition R] (A : Matrix m n R) :
A.rank ≤ Fintype.card n := by
haveI : Module.Finite R (n → R) := Module.Finite.pi
haveI : Module.Free R (n → R) := Module.Free.pi _ _
exact A.mulVecLin.finrank_range_le.trans_eq (finrank_pi _)
#align matrix.rank_le_card_width Matrix.rank_le_card_width
theorem rank_le_width [StrongRankCondition R] {m n : ℕ} (A : Matrix (Fin m) (Fin n) R) :
A.rank ≤ n :=
A.rank_le_card_width.trans <| (Fintype.card_fin n).le
#align matrix.rank_le_width Matrix.rank_le_width
theorem rank_mul_le_left [StrongRankCondition R] (A : Matrix m n R) (B : Matrix n o R) :
(A * B).rank ≤ A.rank := by
rw [rank, rank, mulVecLin_mul]
exact Cardinal.toNat_le_toNat (LinearMap.rank_comp_le_left _ _) (rank_lt_aleph0 _ _)
#align matrix.rank_mul_le_left Matrix.rank_mul_le_left
theorem rank_mul_le_right [StrongRankCondition R] (A : Matrix m n R) (B : Matrix n o R) :
(A * B).rank ≤ B.rank := by
rw [rank, rank, mulVecLin_mul]
exact finrank_le_finrank_of_rank_le_rank (LinearMap.lift_rank_comp_le_right _ _)
(rank_lt_aleph0 _ _)
#align matrix.rank_mul_le_right Matrix.rank_mul_le_right
theorem rank_mul_le [StrongRankCondition R] (A : Matrix m n R) (B : Matrix n o R) :
(A * B).rank ≤ min A.rank B.rank :=
le_min (rank_mul_le_left _ _) (rank_mul_le_right _ _)
#align matrix.rank_mul_le Matrix.rank_mul_le
theorem rank_unit [StrongRankCondition R] [DecidableEq n] (A : (Matrix n n R)ˣ) :
(A : Matrix n n R).rank = Fintype.card n := by
apply le_antisymm (rank_le_card_width (A : Matrix n n R)) _
have := rank_mul_le_left (A : Matrix n n R) (↑A⁻¹ : Matrix n n R)
rwa [← Units.val_mul, mul_inv_self, Units.val_one, rank_one] at this
#align matrix.rank_unit Matrix.rank_unit
theorem rank_of_isUnit [StrongRankCondition R] [DecidableEq n] (A : Matrix n n R) (h : IsUnit A) :
A.rank = Fintype.card n := by
obtain ⟨A, rfl⟩ := h
exact rank_unit A
#align matrix.rank_of_is_unit Matrix.rank_of_isUnit
/-- Right multiplying by an invertible matrix does not change the rank -/
@[simp]
lemma rank_mul_eq_left_of_isUnit_det [DecidableEq n]
(A : Matrix n n R) (B : Matrix m n R) (hA : IsUnit A.det) :
(B * A).rank = B.rank := by
suffices Function.Surjective A.mulVecLin by
rw [rank, mulVecLin_mul, LinearMap.range_comp_of_range_eq_top _
(LinearMap.range_eq_top.mpr this), ← rank]
intro v
exact ⟨(A⁻¹).mulVecLin v, by simp [mul_nonsing_inv _ hA]⟩
/-- Left multiplying by an invertible matrix does not change the rank -/
@[simp]
lemma rank_mul_eq_right_of_isUnit_det [Fintype m] [DecidableEq m]
(A : Matrix m m R) (B : Matrix m n R) (hA : IsUnit A.det) :
(A * B).rank = B.rank := by
let b : Basis m R (m → R) := Pi.basisFun R m
replace hA : IsUnit (LinearMap.toMatrix b b A.mulVecLin).det := by
convert hA; rw [← LinearEquiv.eq_symm_apply]; rfl
have hAB : mulVecLin (A * B) = (LinearEquiv.ofIsUnitDet hA).comp (mulVecLin B) := by ext; simp
rw [rank, rank, hAB, LinearMap.range_comp, LinearEquiv.finrank_map_eq]
/-- Taking a subset of the rows and permuting the columns reduces the rank. -/
theorem rank_submatrix_le [StrongRankCondition R] [Fintype m] (f : n → m) (e : n ≃ m)
(A : Matrix m m R) : rank (A.submatrix f e) ≤ rank A := by
rw [rank, rank, mulVecLin_submatrix, LinearMap.range_comp, LinearMap.range_comp,
show LinearMap.funLeft R R e.symm = LinearEquiv.funCongrLeft R R e.symm from rfl,
LinearEquiv.range, Submodule.map_top]
exact Submodule.finrank_map_le _ _
#align matrix.rank_submatrix_le Matrix.rank_submatrix_le
theorem rank_reindex [Fintype m] (e₁ e₂ : m ≃ n) (A : Matrix m m R) :
rank (reindex e₁ e₂ A) = rank A := by
rw [rank, rank, mulVecLin_reindex, LinearMap.range_comp, LinearMap.range_comp,
LinearEquiv.range, Submodule.map_top, LinearEquiv.finrank_map_eq]
#align matrix.rank_reindex Matrix.rank_reindex
@[simp]
theorem rank_submatrix [Fintype m] (A : Matrix m m R) (e₁ e₂ : n ≃ m) :
rank (A.submatrix e₁ e₂) = rank A := by
simpa only [reindex_apply] using rank_reindex e₁.symm e₂.symm A
#align matrix.rank_submatrix Matrix.rank_submatrix
theorem rank_eq_finrank_range_toLin [Finite m] [DecidableEq n] {M₁ M₂ : Type*} [AddCommGroup M₁]
[AddCommGroup M₂] [Module R M₁] [Module R M₂] (A : Matrix m n R) (v₁ : Basis m R M₁)
(v₂ : Basis n R M₂) : A.rank = finrank R (LinearMap.range (toLin v₂ v₁ A)) := by
cases nonempty_fintype m
let e₁ := (Pi.basisFun R m).equiv v₁ (Equiv.refl _)
let e₂ := (Pi.basisFun R n).equiv v₂ (Equiv.refl _)
have range_e₂ : LinearMap.range e₂ = ⊤ := by
rw [LinearMap.range_eq_top]
exact e₂.surjective
refine LinearEquiv.finrank_eq (e₁.ofSubmodules _ _ ?_)
rw [← LinearMap.range_comp, ← LinearMap.range_comp_of_range_eq_top (toLin v₂ v₁ A) range_e₂]
congr 1
apply LinearMap.pi_ext'
rintro i
apply LinearMap.ext_ring
have aux₁ := toLin_self (Pi.basisFun R n) (Pi.basisFun R m) A i
have aux₂ := Basis.equiv_apply (Pi.basisFun R n) i v₂
rw [toLin_eq_toLin', toLin'_apply'] at aux₁
rw [Pi.basisFun_apply, LinearMap.coe_stdBasis] at aux₁ aux₂
simp only [e₁, e₁, LinearMap.comp_apply, LinearEquiv.coe_coe, Equiv.refl_apply, aux₁, aux₂,
LinearMap.coe_single, toLin_self, map_sum, LinearEquiv.map_smul, Basis.equiv_apply]
#align matrix.rank_eq_finrank_range_to_lin Matrix.rank_eq_finrank_range_toLin
theorem rank_le_card_height [Fintype m] [StrongRankCondition R] (A : Matrix m n R) :
A.rank ≤ Fintype.card m := by
haveI : Module.Finite R (m → R) := Module.Finite.pi
haveI : Module.Free R (m → R) := Module.Free.pi _ _
exact (Submodule.finrank_le _).trans (finrank_pi R).le
#align matrix.rank_le_card_height Matrix.rank_le_card_height
theorem rank_le_height [StrongRankCondition R] {m n : ℕ} (A : Matrix (Fin m) (Fin n) R) :
A.rank ≤ m :=
A.rank_le_card_height.trans <| (Fintype.card_fin m).le
#align matrix.rank_le_height Matrix.rank_le_height
/-- The rank of a matrix is the rank of the space spanned by its columns. -/
theorem rank_eq_finrank_span_cols (A : Matrix m n R) :
A.rank = finrank R (Submodule.span R (Set.range Aᵀ)) := by rw [rank, Matrix.range_mulVecLin]
#align matrix.rank_eq_finrank_span_cols Matrix.rank_eq_finrank_span_cols
end CommRing
section Field
variable [Field R]
/-- The rank of a diagnonal matrix is the count of non-zero elements on its main diagonal -/
theorem rank_diagonal [Fintype m] [DecidableEq m] [DecidableEq R] (w : m → R) :
(diagonal w).rank = Fintype.card {i // (w i) ≠ 0} := by
rw [Matrix.rank, ← Matrix.toLin'_apply', FiniteDimensional.finrank, ← LinearMap.rank,
LinearMap.rank_diagonal, Cardinal.toNat_natCast]
end Field
/-! ### Lemmas about transpose and conjugate transpose
This section contains lemmas about the rank of `Matrix.transpose` and `Matrix.conjTranspose`.
Unfortunately the proofs are essentially duplicated between the two; `ℚ` is a linearly-ordered ring
but can't be a star-ordered ring, while `ℂ` is star-ordered (with `open ComplexOrder`) but
not linearly ordered. For now we don't prove the transpose case for `ℂ`.
TODO: the lemmas `Matrix.rank_transpose` and `Matrix.rank_conjTranspose` current follow a short
proof that is a simple consequence of `Matrix.rank_transpose_mul_self` and
`Matrix.rank_conjTranspose_mul_self`. This proof pulls in unnecessary assumptions on `R`, and should
be replaced with a proof that uses Gaussian reduction or argues via linear combinations.
-/
section StarOrderedField
variable [Fintype m] [Field R] [PartialOrder R] [StarRing R] [StarOrderedRing R]
theorem ker_mulVecLin_conjTranspose_mul_self (A : Matrix m n R) :
LinearMap.ker (Aᴴ * A).mulVecLin = LinearMap.ker (mulVecLin A) := by
ext x
simp only [LinearMap.mem_ker, mulVecLin_apply, conjTranspose_mul_self_mulVec_eq_zero]
#align matrix.ker_mul_vec_lin_conj_transpose_mul_self Matrix.ker_mulVecLin_conjTranspose_mul_self
theorem rank_conjTranspose_mul_self (A : Matrix m n R) : (Aᴴ * A).rank = A.rank := by
dsimp only [rank]
refine add_left_injective (finrank R (LinearMap.ker (mulVecLin A))) ?_
dsimp only
trans finrank R { x // x ∈ LinearMap.range (mulVecLin (Aᴴ * A)) } +
finrank R { x // x ∈ LinearMap.ker (mulVecLin (Aᴴ * A)) }
· rw [ker_mulVecLin_conjTranspose_mul_self]
· simp only [LinearMap.finrank_range_add_finrank_ker]
#align matrix.rank_conj_transpose_mul_self Matrix.rank_conjTranspose_mul_self
-- this follows the proof here https://math.stackexchange.com/a/81903/1896
/-- TODO: prove this in greater generality. -/
@[simp]
theorem rank_conjTranspose (A : Matrix m n R) : Aᴴ.rank = A.rank :=
le_antisymm
(((rank_conjTranspose_mul_self _).symm.trans_le <| rank_mul_le_left _ _).trans_eq <|
congr_arg _ <| conjTranspose_conjTranspose _)
((rank_conjTranspose_mul_self _).symm.trans_le <| rank_mul_le_left _ _)
#align matrix.rank_conj_transpose Matrix.rank_conjTranspose
@[simp]
theorem rank_self_mul_conjTranspose (A : Matrix m n R) : (A * Aᴴ).rank = A.rank := by
simpa only [rank_conjTranspose, conjTranspose_conjTranspose] using
rank_conjTranspose_mul_self Aᴴ
#align matrix.rank_self_mul_conj_transpose Matrix.rank_self_mul_conjTranspose
end StarOrderedField
section LinearOrderedField
variable [Fintype m] [LinearOrderedField R]
theorem ker_mulVecLin_transpose_mul_self (A : Matrix m n R) :
LinearMap.ker (Aᵀ * A).mulVecLin = LinearMap.ker (mulVecLin A) := by
ext x
simp only [LinearMap.mem_ker, mulVecLin_apply, ← mulVec_mulVec]
constructor
· intro h
replace h := congr_arg (dotProduct x) h
rwa [dotProduct_mulVec, dotProduct_zero, vecMul_transpose, dotProduct_self_eq_zero] at h
· intro h
rw [h, mulVec_zero]
#align matrix.ker_mul_vec_lin_transpose_mul_self Matrix.ker_mulVecLin_transpose_mul_self
theorem rank_transpose_mul_self (A : Matrix m n R) : (Aᵀ * A).rank = A.rank := by
dsimp only [rank]
refine add_left_injective (finrank R <| LinearMap.ker A.mulVecLin) ?_
dsimp only
trans finrank R { x // x ∈ LinearMap.range (mulVecLin (Aᵀ * A)) } +
finrank R { x // x ∈ LinearMap.ker (mulVecLin (Aᵀ * A)) }
· rw [ker_mulVecLin_transpose_mul_self]
· simp only [LinearMap.finrank_range_add_finrank_ker]
#align matrix.rank_transpose_mul_self Matrix.rank_transpose_mul_self
/-- TODO: prove this in greater generality. -/
@[simp]
theorem rank_transpose (A : Matrix m n R) : Aᵀ.rank = A.rank :=
le_antisymm ((rank_transpose_mul_self _).symm.trans_le <| rank_mul_le_left _ _)
((rank_transpose_mul_self _).symm.trans_le <| rank_mul_le_left _ _)
#align matrix.rank_transpose Matrix.rank_transpose
@[simp]
theorem rank_self_mul_transpose (A : Matrix m n R) : (A * Aᵀ).rank = A.rank := by
simpa only [rank_transpose, transpose_transpose] using rank_transpose_mul_self Aᵀ
#align matrix.rank_self_mul_transpose Matrix.rank_self_mul_transpose
end LinearOrderedField
/-- The rank of a matrix is the rank of the space spanned by its rows.
TODO: prove this in a generality that works for `ℂ` too, not just `ℚ` and `ℝ`. -/
| Mathlib/Data/Matrix/Rank.lean | 294 | 297 | theorem rank_eq_finrank_span_row [LinearOrderedField R] [Finite m] (A : Matrix m n R) :
A.rank = finrank R (Submodule.span R (Set.range A)) := by |
cases nonempty_fintype m
rw [← rank_transpose, rank_eq_finrank_span_cols, transpose_transpose]
|
/-
Copyright (c) 2018 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Kenny Lau, Scott Morrison, Alex Keizer
-/
import Mathlib.Data.List.OfFn
import Mathlib.Data.List.Range
#align_import data.list.fin_range from "leanprover-community/mathlib"@"9003f28797c0664a49e4179487267c494477d853"
/-!
# Lists of elements of `Fin n`
This file develops some results on `finRange n`.
-/
universe u
namespace List
variable {α : Type u}
@[simp]
theorem map_coe_finRange (n : ℕ) : ((finRange n) : List (Fin n)).map (Fin.val) = List.range n := by
simp_rw [finRange, map_pmap, pmap_eq_map]
exact List.map_id _
#align list.map_coe_fin_range List.map_coe_finRange
| Mathlib/Data/List/FinRange.lean | 30 | 34 | theorem finRange_succ_eq_map (n : ℕ) : finRange n.succ = 0 :: (finRange n).map Fin.succ := by |
apply map_injective_iff.mpr Fin.val_injective
rw [map_cons, map_coe_finRange, range_succ_eq_map, Fin.val_zero, ← map_coe_finRange, map_map,
map_map]
simp only [Function.comp, Fin.val_succ]
|
/-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura, Johannes Hölzl, Mario Carneiro
-/
import Mathlib.Logic.Pairwise
import Mathlib.Order.CompleteBooleanAlgebra
import Mathlib.Order.Directed
import Mathlib.Order.GaloisConnection
#align_import data.set.lattice from "leanprover-community/mathlib"@"b86832321b586c6ac23ef8cdef6a7a27e42b13bd"
/-!
# The set lattice
This file provides usual set notation for unions and intersections, a `CompleteLattice` instance
for `Set α`, and some more set constructions.
## Main declarations
* `Set.iUnion`: **i**ndexed **union**. Union of an indexed family of sets.
* `Set.iInter`: **i**ndexed **inter**section. Intersection of an indexed family of sets.
* `Set.sInter`: **s**et **inter**section. Intersection of sets belonging to a set of sets.
* `Set.sUnion`: **s**et **union**. Union of sets belonging to a set of sets.
* `Set.sInter_eq_biInter`, `Set.sUnion_eq_biInter`: Shows that `⋂₀ s = ⋂ x ∈ s, x` and
`⋃₀ s = ⋃ x ∈ s, x`.
* `Set.completeAtomicBooleanAlgebra`: `Set α` is a `CompleteAtomicBooleanAlgebra` with `≤ = ⊆`,
`< = ⊂`, `⊓ = ∩`, `⊔ = ∪`, `⨅ = ⋂`, `⨆ = ⋃` and `\` as the set difference.
See `Set.BooleanAlgebra`.
* `Set.kernImage`: For a function `f : α → β`, `s.kernImage f` is the set of `y` such that
`f ⁻¹ y ⊆ s`.
* `Set.seq`: Union of the image of a set under a **seq**uence of functions. `seq s t` is the union
of `f '' t` over all `f ∈ s`, where `t : Set α` and `s : Set (α → β)`.
* `Set.unionEqSigmaOfDisjoint`: Equivalence between `⋃ i, t i` and `Σ i, t i`, where `t` is an
indexed family of disjoint sets.
## Naming convention
In lemma names,
* `⋃ i, s i` is called `iUnion`
* `⋂ i, s i` is called `iInter`
* `⋃ i j, s i j` is called `iUnion₂`. This is an `iUnion` inside an `iUnion`.
* `⋂ i j, s i j` is called `iInter₂`. This is an `iInter` inside an `iInter`.
* `⋃ i ∈ s, t i` is called `biUnion` for "bounded `iUnion`". This is the special case of `iUnion₂`
where `j : i ∈ s`.
* `⋂ i ∈ s, t i` is called `biInter` for "bounded `iInter`". This is the special case of `iInter₂`
where `j : i ∈ s`.
## Notation
* `⋃`: `Set.iUnion`
* `⋂`: `Set.iInter`
* `⋃₀`: `Set.sUnion`
* `⋂₀`: `Set.sInter`
-/
open Function Set
universe u
variable {α β γ : Type*} {ι ι' ι₂ : Sort*} {κ κ₁ κ₂ : ι → Sort*} {κ' : ι' → Sort*}
namespace Set
/-! ### Complete lattice and complete Boolean algebra instances -/
theorem mem_iUnion₂ {x : γ} {s : ∀ i, κ i → Set γ} : (x ∈ ⋃ (i) (j), s i j) ↔ ∃ i j, x ∈ s i j := by
simp_rw [mem_iUnion]
#align set.mem_Union₂ Set.mem_iUnion₂
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/
theorem mem_iInter₂ {x : γ} {s : ∀ i, κ i → Set γ} : (x ∈ ⋂ (i) (j), s i j) ↔ ∀ i j, x ∈ s i j := by
simp_rw [mem_iInter]
#align set.mem_Inter₂ Set.mem_iInter₂
theorem mem_iUnion_of_mem {s : ι → Set α} {a : α} (i : ι) (ha : a ∈ s i) : a ∈ ⋃ i, s i :=
mem_iUnion.2 ⟨i, ha⟩
#align set.mem_Union_of_mem Set.mem_iUnion_of_mem
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/
theorem mem_iUnion₂_of_mem {s : ∀ i, κ i → Set α} {a : α} {i : ι} (j : κ i) (ha : a ∈ s i j) :
a ∈ ⋃ (i) (j), s i j :=
mem_iUnion₂.2 ⟨i, j, ha⟩
#align set.mem_Union₂_of_mem Set.mem_iUnion₂_of_mem
theorem mem_iInter_of_mem {s : ι → Set α} {a : α} (h : ∀ i, a ∈ s i) : a ∈ ⋂ i, s i :=
mem_iInter.2 h
#align set.mem_Inter_of_mem Set.mem_iInter_of_mem
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/
theorem mem_iInter₂_of_mem {s : ∀ i, κ i → Set α} {a : α} (h : ∀ i j, a ∈ s i j) :
a ∈ ⋂ (i) (j), s i j :=
mem_iInter₂.2 h
#align set.mem_Inter₂_of_mem Set.mem_iInter₂_of_mem
instance completeAtomicBooleanAlgebra : CompleteAtomicBooleanAlgebra (Set α) :=
{ instBooleanAlgebraSet with
le_sSup := fun s t t_in a a_in => ⟨t, t_in, a_in⟩
sSup_le := fun s t h a ⟨t', ⟨t'_in, a_in⟩⟩ => h t' t'_in a_in
le_sInf := fun s t h a a_in t' t'_in => h t' t'_in a_in
sInf_le := fun s t t_in a h => h _ t_in
iInf_iSup_eq := by intros; ext; simp [Classical.skolem] }
section GaloisConnection
variable {f : α → β}
protected theorem image_preimage : GaloisConnection (image f) (preimage f) := fun _ _ =>
image_subset_iff
#align set.image_preimage Set.image_preimage
protected theorem preimage_kernImage : GaloisConnection (preimage f) (kernImage f) := fun _ _ =>
subset_kernImage_iff.symm
#align set.preimage_kern_image Set.preimage_kernImage
end GaloisConnection
section kernImage
variable {f : α → β}
lemma kernImage_mono : Monotone (kernImage f) :=
Set.preimage_kernImage.monotone_u
lemma kernImage_eq_compl {s : Set α} : kernImage f s = (f '' sᶜ)ᶜ :=
Set.preimage_kernImage.u_unique (Set.image_preimage.compl)
(fun t ↦ compl_compl (f ⁻¹' t) ▸ Set.preimage_compl)
lemma kernImage_compl {s : Set α} : kernImage f (sᶜ) = (f '' s)ᶜ := by
rw [kernImage_eq_compl, compl_compl]
lemma kernImage_empty : kernImage f ∅ = (range f)ᶜ := by
rw [kernImage_eq_compl, compl_empty, image_univ]
lemma kernImage_preimage_eq_iff {s : Set β} : kernImage f (f ⁻¹' s) = s ↔ (range f)ᶜ ⊆ s := by
rw [kernImage_eq_compl, ← preimage_compl, compl_eq_comm, eq_comm, image_preimage_eq_iff,
compl_subset_comm]
lemma compl_range_subset_kernImage {s : Set α} : (range f)ᶜ ⊆ kernImage f s := by
rw [← kernImage_empty]
exact kernImage_mono (empty_subset _)
lemma kernImage_union_preimage {s : Set α} {t : Set β} :
kernImage f (s ∪ f ⁻¹' t) = kernImage f s ∪ t := by
rw [kernImage_eq_compl, kernImage_eq_compl, compl_union, ← preimage_compl, image_inter_preimage,
compl_inter, compl_compl]
lemma kernImage_preimage_union {s : Set α} {t : Set β} :
kernImage f (f ⁻¹' t ∪ s) = t ∪ kernImage f s := by
rw [union_comm, kernImage_union_preimage, union_comm]
end kernImage
/-! ### Union and intersection over an indexed family of sets -/
instance : OrderTop (Set α) where
top := univ
le_top := by simp
@[congr]
theorem iUnion_congr_Prop {p q : Prop} {f₁ : p → Set α} {f₂ : q → Set α} (pq : p ↔ q)
(f : ∀ x, f₁ (pq.mpr x) = f₂ x) : iUnion f₁ = iUnion f₂ :=
iSup_congr_Prop pq f
#align set.Union_congr_Prop Set.iUnion_congr_Prop
@[congr]
theorem iInter_congr_Prop {p q : Prop} {f₁ : p → Set α} {f₂ : q → Set α} (pq : p ↔ q)
(f : ∀ x, f₁ (pq.mpr x) = f₂ x) : iInter f₁ = iInter f₂ :=
iInf_congr_Prop pq f
#align set.Inter_congr_Prop Set.iInter_congr_Prop
theorem iUnion_plift_up (f : PLift ι → Set α) : ⋃ i, f (PLift.up i) = ⋃ i, f i :=
iSup_plift_up _
#align set.Union_plift_up Set.iUnion_plift_up
theorem iUnion_plift_down (f : ι → Set α) : ⋃ i, f (PLift.down i) = ⋃ i, f i :=
iSup_plift_down _
#align set.Union_plift_down Set.iUnion_plift_down
theorem iInter_plift_up (f : PLift ι → Set α) : ⋂ i, f (PLift.up i) = ⋂ i, f i :=
iInf_plift_up _
#align set.Inter_plift_up Set.iInter_plift_up
theorem iInter_plift_down (f : ι → Set α) : ⋂ i, f (PLift.down i) = ⋂ i, f i :=
iInf_plift_down _
#align set.Inter_plift_down Set.iInter_plift_down
theorem iUnion_eq_if {p : Prop} [Decidable p] (s : Set α) : ⋃ _ : p, s = if p then s else ∅ :=
iSup_eq_if _
#align set.Union_eq_if Set.iUnion_eq_if
theorem iUnion_eq_dif {p : Prop} [Decidable p] (s : p → Set α) :
⋃ h : p, s h = if h : p then s h else ∅ :=
iSup_eq_dif _
#align set.Union_eq_dif Set.iUnion_eq_dif
theorem iInter_eq_if {p : Prop} [Decidable p] (s : Set α) : ⋂ _ : p, s = if p then s else univ :=
iInf_eq_if _
#align set.Inter_eq_if Set.iInter_eq_if
theorem iInf_eq_dif {p : Prop} [Decidable p] (s : p → Set α) :
⋂ h : p, s h = if h : p then s h else univ :=
_root_.iInf_eq_dif _
#align set.Infi_eq_dif Set.iInf_eq_dif
theorem exists_set_mem_of_union_eq_top {ι : Type*} (t : Set ι) (s : ι → Set β)
(w : ⋃ i ∈ t, s i = ⊤) (x : β) : ∃ i ∈ t, x ∈ s i := by
have p : x ∈ ⊤ := Set.mem_univ x
rw [← w, Set.mem_iUnion] at p
simpa using p
#align set.exists_set_mem_of_union_eq_top Set.exists_set_mem_of_union_eq_top
theorem nonempty_of_union_eq_top_of_nonempty {ι : Type*} (t : Set ι) (s : ι → Set α)
(H : Nonempty α) (w : ⋃ i ∈ t, s i = ⊤) : t.Nonempty := by
obtain ⟨x, m, -⟩ := exists_set_mem_of_union_eq_top t s w H.some
exact ⟨x, m⟩
#align set.nonempty_of_union_eq_top_of_nonempty Set.nonempty_of_union_eq_top_of_nonempty
theorem nonempty_of_nonempty_iUnion
{s : ι → Set α} (h_Union : (⋃ i, s i).Nonempty) : Nonempty ι := by
obtain ⟨x, hx⟩ := h_Union
exact ⟨Classical.choose <| mem_iUnion.mp hx⟩
theorem nonempty_of_nonempty_iUnion_eq_univ
{s : ι → Set α} [Nonempty α] (h_Union : ⋃ i, s i = univ) : Nonempty ι :=
nonempty_of_nonempty_iUnion (s := s) (by simpa only [h_Union] using univ_nonempty)
theorem setOf_exists (p : ι → β → Prop) : { x | ∃ i, p i x } = ⋃ i, { x | p i x } :=
ext fun _ => mem_iUnion.symm
#align set.set_of_exists Set.setOf_exists
theorem setOf_forall (p : ι → β → Prop) : { x | ∀ i, p i x } = ⋂ i, { x | p i x } :=
ext fun _ => mem_iInter.symm
#align set.set_of_forall Set.setOf_forall
theorem iUnion_subset {s : ι → Set α} {t : Set α} (h : ∀ i, s i ⊆ t) : ⋃ i, s i ⊆ t :=
iSup_le h
#align set.Union_subset Set.iUnion_subset
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/
theorem iUnion₂_subset {s : ∀ i, κ i → Set α} {t : Set α} (h : ∀ i j, s i j ⊆ t) :
⋃ (i) (j), s i j ⊆ t :=
iUnion_subset fun x => iUnion_subset (h x)
#align set.Union₂_subset Set.iUnion₂_subset
theorem subset_iInter {t : Set β} {s : ι → Set β} (h : ∀ i, t ⊆ s i) : t ⊆ ⋂ i, s i :=
le_iInf h
#align set.subset_Inter Set.subset_iInter
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/
theorem subset_iInter₂ {s : Set α} {t : ∀ i, κ i → Set α} (h : ∀ i j, s ⊆ t i j) :
s ⊆ ⋂ (i) (j), t i j :=
subset_iInter fun x => subset_iInter <| h x
#align set.subset_Inter₂ Set.subset_iInter₂
@[simp]
theorem iUnion_subset_iff {s : ι → Set α} {t : Set α} : ⋃ i, s i ⊆ t ↔ ∀ i, s i ⊆ t :=
⟨fun h _ => Subset.trans (le_iSup s _) h, iUnion_subset⟩
#align set.Union_subset_iff Set.iUnion_subset_iff
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/
theorem iUnion₂_subset_iff {s : ∀ i, κ i → Set α} {t : Set α} :
⋃ (i) (j), s i j ⊆ t ↔ ∀ i j, s i j ⊆ t := by simp_rw [iUnion_subset_iff]
#align set.Union₂_subset_iff Set.iUnion₂_subset_iff
@[simp]
theorem subset_iInter_iff {s : Set α} {t : ι → Set α} : (s ⊆ ⋂ i, t i) ↔ ∀ i, s ⊆ t i :=
le_iInf_iff
#align set.subset_Inter_iff Set.subset_iInter_iff
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/
-- Porting note (#10618): removing `simp`. `simp` can prove it
theorem subset_iInter₂_iff {s : Set α} {t : ∀ i, κ i → Set α} :
(s ⊆ ⋂ (i) (j), t i j) ↔ ∀ i j, s ⊆ t i j := by simp_rw [subset_iInter_iff]
#align set.subset_Inter₂_iff Set.subset_iInter₂_iff
theorem subset_iUnion : ∀ (s : ι → Set β) (i : ι), s i ⊆ ⋃ i, s i :=
le_iSup
#align set.subset_Union Set.subset_iUnion
theorem iInter_subset : ∀ (s : ι → Set β) (i : ι), ⋂ i, s i ⊆ s i :=
iInf_le
#align set.Inter_subset Set.iInter_subset
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/
theorem subset_iUnion₂ {s : ∀ i, κ i → Set α} (i : ι) (j : κ i) : s i j ⊆ ⋃ (i') (j'), s i' j' :=
le_iSup₂ i j
#align set.subset_Union₂ Set.subset_iUnion₂
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/
theorem iInter₂_subset {s : ∀ i, κ i → Set α} (i : ι) (j : κ i) : ⋂ (i) (j), s i j ⊆ s i j :=
iInf₂_le i j
#align set.Inter₂_subset Set.iInter₂_subset
/-- This rather trivial consequence of `subset_iUnion`is convenient with `apply`, and has `i`
explicit for this purpose. -/
theorem subset_iUnion_of_subset {s : Set α} {t : ι → Set α} (i : ι) (h : s ⊆ t i) : s ⊆ ⋃ i, t i :=
le_iSup_of_le i h
#align set.subset_Union_of_subset Set.subset_iUnion_of_subset
/-- This rather trivial consequence of `iInter_subset`is convenient with `apply`, and has `i`
explicit for this purpose. -/
theorem iInter_subset_of_subset {s : ι → Set α} {t : Set α} (i : ι) (h : s i ⊆ t) :
⋂ i, s i ⊆ t :=
iInf_le_of_le i h
#align set.Inter_subset_of_subset Set.iInter_subset_of_subset
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/
/-- This rather trivial consequence of `subset_iUnion₂` is convenient with `apply`, and has `i` and
`j` explicit for this purpose. -/
theorem subset_iUnion₂_of_subset {s : Set α} {t : ∀ i, κ i → Set α} (i : ι) (j : κ i)
(h : s ⊆ t i j) : s ⊆ ⋃ (i) (j), t i j :=
le_iSup₂_of_le i j h
#align set.subset_Union₂_of_subset Set.subset_iUnion₂_of_subset
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/
/-- This rather trivial consequence of `iInter₂_subset` is convenient with `apply`, and has `i` and
`j` explicit for this purpose. -/
theorem iInter₂_subset_of_subset {s : ∀ i, κ i → Set α} {t : Set α} (i : ι) (j : κ i)
(h : s i j ⊆ t) : ⋂ (i) (j), s i j ⊆ t :=
iInf₂_le_of_le i j h
#align set.Inter₂_subset_of_subset Set.iInter₂_subset_of_subset
theorem iUnion_mono {s t : ι → Set α} (h : ∀ i, s i ⊆ t i) : ⋃ i, s i ⊆ ⋃ i, t i :=
iSup_mono h
#align set.Union_mono Set.iUnion_mono
@[gcongr]
theorem iUnion_mono'' {s t : ι → Set α} (h : ∀ i, s i ⊆ t i) : iUnion s ⊆ iUnion t :=
iSup_mono h
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/
theorem iUnion₂_mono {s t : ∀ i, κ i → Set α} (h : ∀ i j, s i j ⊆ t i j) :
⋃ (i) (j), s i j ⊆ ⋃ (i) (j), t i j :=
iSup₂_mono h
#align set.Union₂_mono Set.iUnion₂_mono
theorem iInter_mono {s t : ι → Set α} (h : ∀ i, s i ⊆ t i) : ⋂ i, s i ⊆ ⋂ i, t i :=
iInf_mono h
#align set.Inter_mono Set.iInter_mono
@[gcongr]
theorem iInter_mono'' {s t : ι → Set α} (h : ∀ i, s i ⊆ t i) : iInter s ⊆ iInter t :=
iInf_mono h
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/
theorem iInter₂_mono {s t : ∀ i, κ i → Set α} (h : ∀ i j, s i j ⊆ t i j) :
⋂ (i) (j), s i j ⊆ ⋂ (i) (j), t i j :=
iInf₂_mono h
#align set.Inter₂_mono Set.iInter₂_mono
theorem iUnion_mono' {s : ι → Set α} {t : ι₂ → Set α} (h : ∀ i, ∃ j, s i ⊆ t j) :
⋃ i, s i ⊆ ⋃ i, t i :=
iSup_mono' h
#align set.Union_mono' Set.iUnion_mono'
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i' j') -/
theorem iUnion₂_mono' {s : ∀ i, κ i → Set α} {t : ∀ i', κ' i' → Set α}
(h : ∀ i j, ∃ i' j', s i j ⊆ t i' j') : ⋃ (i) (j), s i j ⊆ ⋃ (i') (j'), t i' j' :=
iSup₂_mono' h
#align set.Union₂_mono' Set.iUnion₂_mono'
theorem iInter_mono' {s : ι → Set α} {t : ι' → Set α} (h : ∀ j, ∃ i, s i ⊆ t j) :
⋂ i, s i ⊆ ⋂ j, t j :=
Set.subset_iInter fun j =>
let ⟨i, hi⟩ := h j
iInter_subset_of_subset i hi
#align set.Inter_mono' Set.iInter_mono'
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i' j') -/
theorem iInter₂_mono' {s : ∀ i, κ i → Set α} {t : ∀ i', κ' i' → Set α}
(h : ∀ i' j', ∃ i j, s i j ⊆ t i' j') : ⋂ (i) (j), s i j ⊆ ⋂ (i') (j'), t i' j' :=
subset_iInter₂_iff.2 fun i' j' =>
let ⟨_, _, hst⟩ := h i' j'
(iInter₂_subset _ _).trans hst
#align set.Inter₂_mono' Set.iInter₂_mono'
theorem iUnion₂_subset_iUnion (κ : ι → Sort*) (s : ι → Set α) :
⋃ (i) (_ : κ i), s i ⊆ ⋃ i, s i :=
iUnion_mono fun _ => iUnion_subset fun _ => Subset.rfl
#align set.Union₂_subset_Union Set.iUnion₂_subset_iUnion
theorem iInter_subset_iInter₂ (κ : ι → Sort*) (s : ι → Set α) :
⋂ i, s i ⊆ ⋂ (i) (_ : κ i), s i :=
iInter_mono fun _ => subset_iInter fun _ => Subset.rfl
#align set.Inter_subset_Inter₂ Set.iInter_subset_iInter₂
theorem iUnion_setOf (P : ι → α → Prop) : ⋃ i, { x : α | P i x } = { x : α | ∃ i, P i x } := by
ext
exact mem_iUnion
#align set.Union_set_of Set.iUnion_setOf
theorem iInter_setOf (P : ι → α → Prop) : ⋂ i, { x : α | P i x } = { x : α | ∀ i, P i x } := by
ext
exact mem_iInter
#align set.Inter_set_of Set.iInter_setOf
theorem iUnion_congr_of_surjective {f : ι → Set α} {g : ι₂ → Set α} (h : ι → ι₂) (h1 : Surjective h)
(h2 : ∀ x, g (h x) = f x) : ⋃ x, f x = ⋃ y, g y :=
h1.iSup_congr h h2
#align set.Union_congr_of_surjective Set.iUnion_congr_of_surjective
theorem iInter_congr_of_surjective {f : ι → Set α} {g : ι₂ → Set α} (h : ι → ι₂) (h1 : Surjective h)
(h2 : ∀ x, g (h x) = f x) : ⋂ x, f x = ⋂ y, g y :=
h1.iInf_congr h h2
#align set.Inter_congr_of_surjective Set.iInter_congr_of_surjective
lemma iUnion_congr {s t : ι → Set α} (h : ∀ i, s i = t i) : ⋃ i, s i = ⋃ i, t i := iSup_congr h
#align set.Union_congr Set.iUnion_congr
lemma iInter_congr {s t : ι → Set α} (h : ∀ i, s i = t i) : ⋂ i, s i = ⋂ i, t i := iInf_congr h
#align set.Inter_congr Set.iInter_congr
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/
lemma iUnion₂_congr {s t : ∀ i, κ i → Set α} (h : ∀ i j, s i j = t i j) :
⋃ (i) (j), s i j = ⋃ (i) (j), t i j :=
iUnion_congr fun i => iUnion_congr <| h i
#align set.Union₂_congr Set.iUnion₂_congr
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/
lemma iInter₂_congr {s t : ∀ i, κ i → Set α} (h : ∀ i j, s i j = t i j) :
⋂ (i) (j), s i j = ⋂ (i) (j), t i j :=
iInter_congr fun i => iInter_congr <| h i
#align set.Inter₂_congr Set.iInter₂_congr
section Nonempty
variable [Nonempty ι] {f : ι → Set α} {s : Set α}
lemma iUnion_const (s : Set β) : ⋃ _ : ι, s = s := iSup_const
#align set.Union_const Set.iUnion_const
lemma iInter_const (s : Set β) : ⋂ _ : ι, s = s := iInf_const
#align set.Inter_const Set.iInter_const
lemma iUnion_eq_const (hf : ∀ i, f i = s) : ⋃ i, f i = s :=
(iUnion_congr hf).trans <| iUnion_const _
#align set.Union_eq_const Set.iUnion_eq_const
lemma iInter_eq_const (hf : ∀ i, f i = s) : ⋂ i, f i = s :=
(iInter_congr hf).trans <| iInter_const _
#align set.Inter_eq_const Set.iInter_eq_const
end Nonempty
@[simp]
theorem compl_iUnion (s : ι → Set β) : (⋃ i, s i)ᶜ = ⋂ i, (s i)ᶜ :=
compl_iSup
#align set.compl_Union Set.compl_iUnion
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/
theorem compl_iUnion₂ (s : ∀ i, κ i → Set α) : (⋃ (i) (j), s i j)ᶜ = ⋂ (i) (j), (s i j)ᶜ := by
simp_rw [compl_iUnion]
#align set.compl_Union₂ Set.compl_iUnion₂
@[simp]
theorem compl_iInter (s : ι → Set β) : (⋂ i, s i)ᶜ = ⋃ i, (s i)ᶜ :=
compl_iInf
#align set.compl_Inter Set.compl_iInter
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/
theorem compl_iInter₂ (s : ∀ i, κ i → Set α) : (⋂ (i) (j), s i j)ᶜ = ⋃ (i) (j), (s i j)ᶜ := by
simp_rw [compl_iInter]
#align set.compl_Inter₂ Set.compl_iInter₂
-- classical -- complete_boolean_algebra
theorem iUnion_eq_compl_iInter_compl (s : ι → Set β) : ⋃ i, s i = (⋂ i, (s i)ᶜ)ᶜ := by
simp only [compl_iInter, compl_compl]
#align set.Union_eq_compl_Inter_compl Set.iUnion_eq_compl_iInter_compl
-- classical -- complete_boolean_algebra
theorem iInter_eq_compl_iUnion_compl (s : ι → Set β) : ⋂ i, s i = (⋃ i, (s i)ᶜ)ᶜ := by
simp only [compl_iUnion, compl_compl]
#align set.Inter_eq_compl_Union_compl Set.iInter_eq_compl_iUnion_compl
theorem inter_iUnion (s : Set β) (t : ι → Set β) : (s ∩ ⋃ i, t i) = ⋃ i, s ∩ t i :=
inf_iSup_eq _ _
#align set.inter_Union Set.inter_iUnion
theorem iUnion_inter (s : Set β) (t : ι → Set β) : (⋃ i, t i) ∩ s = ⋃ i, t i ∩ s :=
iSup_inf_eq _ _
#align set.Union_inter Set.iUnion_inter
theorem iUnion_union_distrib (s : ι → Set β) (t : ι → Set β) :
⋃ i, s i ∪ t i = (⋃ i, s i) ∪ ⋃ i, t i :=
iSup_sup_eq
#align set.Union_union_distrib Set.iUnion_union_distrib
theorem iInter_inter_distrib (s : ι → Set β) (t : ι → Set β) :
⋂ i, s i ∩ t i = (⋂ i, s i) ∩ ⋂ i, t i :=
iInf_inf_eq
#align set.Inter_inter_distrib Set.iInter_inter_distrib
theorem union_iUnion [Nonempty ι] (s : Set β) (t : ι → Set β) : (s ∪ ⋃ i, t i) = ⋃ i, s ∪ t i :=
sup_iSup
#align set.union_Union Set.union_iUnion
theorem iUnion_union [Nonempty ι] (s : Set β) (t : ι → Set β) : (⋃ i, t i) ∪ s = ⋃ i, t i ∪ s :=
iSup_sup
#align set.Union_union Set.iUnion_union
theorem inter_iInter [Nonempty ι] (s : Set β) (t : ι → Set β) : (s ∩ ⋂ i, t i) = ⋂ i, s ∩ t i :=
inf_iInf
#align set.inter_Inter Set.inter_iInter
theorem iInter_inter [Nonempty ι] (s : Set β) (t : ι → Set β) : (⋂ i, t i) ∩ s = ⋂ i, t i ∩ s :=
iInf_inf
#align set.Inter_inter Set.iInter_inter
-- classical
theorem union_iInter (s : Set β) (t : ι → Set β) : (s ∪ ⋂ i, t i) = ⋂ i, s ∪ t i :=
sup_iInf_eq _ _
#align set.union_Inter Set.union_iInter
theorem iInter_union (s : ι → Set β) (t : Set β) : (⋂ i, s i) ∪ t = ⋂ i, s i ∪ t :=
iInf_sup_eq _ _
#align set.Inter_union Set.iInter_union
theorem iUnion_diff (s : Set β) (t : ι → Set β) : (⋃ i, t i) \ s = ⋃ i, t i \ s :=
iUnion_inter _ _
#align set.Union_diff Set.iUnion_diff
theorem diff_iUnion [Nonempty ι] (s : Set β) (t : ι → Set β) : (s \ ⋃ i, t i) = ⋂ i, s \ t i := by
rw [diff_eq, compl_iUnion, inter_iInter]; rfl
#align set.diff_Union Set.diff_iUnion
theorem diff_iInter (s : Set β) (t : ι → Set β) : (s \ ⋂ i, t i) = ⋃ i, s \ t i := by
rw [diff_eq, compl_iInter, inter_iUnion]; rfl
#align set.diff_Inter Set.diff_iInter
theorem iUnion_inter_subset {ι α} {s t : ι → Set α} : ⋃ i, s i ∩ t i ⊆ (⋃ i, s i) ∩ ⋃ i, t i :=
le_iSup_inf_iSup s t
#align set.Union_inter_subset Set.iUnion_inter_subset
theorem iUnion_inter_of_monotone {ι α} [Preorder ι] [IsDirected ι (· ≤ ·)] {s t : ι → Set α}
(hs : Monotone s) (ht : Monotone t) : ⋃ i, s i ∩ t i = (⋃ i, s i) ∩ ⋃ i, t i :=
iSup_inf_of_monotone hs ht
#align set.Union_inter_of_monotone Set.iUnion_inter_of_monotone
theorem iUnion_inter_of_antitone {ι α} [Preorder ι] [IsDirected ι (swap (· ≤ ·))] {s t : ι → Set α}
(hs : Antitone s) (ht : Antitone t) : ⋃ i, s i ∩ t i = (⋃ i, s i) ∩ ⋃ i, t i :=
iSup_inf_of_antitone hs ht
#align set.Union_inter_of_antitone Set.iUnion_inter_of_antitone
theorem iInter_union_of_monotone {ι α} [Preorder ι] [IsDirected ι (swap (· ≤ ·))] {s t : ι → Set α}
(hs : Monotone s) (ht : Monotone t) : ⋂ i, s i ∪ t i = (⋂ i, s i) ∪ ⋂ i, t i :=
iInf_sup_of_monotone hs ht
#align set.Inter_union_of_monotone Set.iInter_union_of_monotone
theorem iInter_union_of_antitone {ι α} [Preorder ι] [IsDirected ι (· ≤ ·)] {s t : ι → Set α}
(hs : Antitone s) (ht : Antitone t) : ⋂ i, s i ∪ t i = (⋂ i, s i) ∪ ⋂ i, t i :=
iInf_sup_of_antitone hs ht
#align set.Inter_union_of_antitone Set.iInter_union_of_antitone
/-- An equality version of this lemma is `iUnion_iInter_of_monotone` in `Data.Set.Finite`. -/
theorem iUnion_iInter_subset {s : ι → ι' → Set α} : (⋃ j, ⋂ i, s i j) ⊆ ⋂ i, ⋃ j, s i j :=
iSup_iInf_le_iInf_iSup (flip s)
#align set.Union_Inter_subset Set.iUnion_iInter_subset
theorem iUnion_option {ι} (s : Option ι → Set α) : ⋃ o, s o = s none ∪ ⋃ i, s (some i) :=
iSup_option s
#align set.Union_option Set.iUnion_option
theorem iInter_option {ι} (s : Option ι → Set α) : ⋂ o, s o = s none ∩ ⋂ i, s (some i) :=
iInf_option s
#align set.Inter_option Set.iInter_option
section
variable (p : ι → Prop) [DecidablePred p]
theorem iUnion_dite (f : ∀ i, p i → Set α) (g : ∀ i, ¬p i → Set α) :
⋃ i, (if h : p i then f i h else g i h) = (⋃ (i) (h : p i), f i h) ∪ ⋃ (i) (h : ¬p i), g i h :=
iSup_dite _ _ _
#align set.Union_dite Set.iUnion_dite
theorem iUnion_ite (f g : ι → Set α) :
⋃ i, (if p i then f i else g i) = (⋃ (i) (_ : p i), f i) ∪ ⋃ (i) (_ : ¬p i), g i :=
iUnion_dite _ _ _
#align set.Union_ite Set.iUnion_ite
theorem iInter_dite (f : ∀ i, p i → Set α) (g : ∀ i, ¬p i → Set α) :
⋂ i, (if h : p i then f i h else g i h) = (⋂ (i) (h : p i), f i h) ∩ ⋂ (i) (h : ¬p i), g i h :=
iInf_dite _ _ _
#align set.Inter_dite Set.iInter_dite
theorem iInter_ite (f g : ι → Set α) :
⋂ i, (if p i then f i else g i) = (⋂ (i) (_ : p i), f i) ∩ ⋂ (i) (_ : ¬p i), g i :=
iInter_dite _ _ _
#align set.Inter_ite Set.iInter_ite
end
theorem image_projection_prod {ι : Type*} {α : ι → Type*} {v : ∀ i : ι, Set (α i)}
(hv : (pi univ v).Nonempty) (i : ι) :
((fun x : ∀ i : ι, α i => x i) '' ⋂ k, (fun x : ∀ j : ι, α j => x k) ⁻¹' v k) = v i := by
classical
apply Subset.antisymm
· simp [iInter_subset]
· intro y y_in
simp only [mem_image, mem_iInter, mem_preimage]
rcases hv with ⟨z, hz⟩
refine ⟨Function.update z i y, ?_, update_same i y z⟩
rw [@forall_update_iff ι α _ z i y fun i t => t ∈ v i]
exact ⟨y_in, fun j _ => by simpa using hz j⟩
#align set.image_projection_prod Set.image_projection_prod
/-! ### Unions and intersections indexed by `Prop` -/
theorem iInter_false {s : False → Set α} : iInter s = univ :=
iInf_false
#align set.Inter_false Set.iInter_false
theorem iUnion_false {s : False → Set α} : iUnion s = ∅ :=
iSup_false
#align set.Union_false Set.iUnion_false
@[simp]
theorem iInter_true {s : True → Set α} : iInter s = s trivial :=
iInf_true
#align set.Inter_true Set.iInter_true
@[simp]
theorem iUnion_true {s : True → Set α} : iUnion s = s trivial :=
iSup_true
#align set.Union_true Set.iUnion_true
@[simp]
theorem iInter_exists {p : ι → Prop} {f : Exists p → Set α} :
⋂ x, f x = ⋂ (i) (h : p i), f ⟨i, h⟩ :=
iInf_exists
#align set.Inter_exists Set.iInter_exists
@[simp]
theorem iUnion_exists {p : ι → Prop} {f : Exists p → Set α} :
⋃ x, f x = ⋃ (i) (h : p i), f ⟨i, h⟩ :=
iSup_exists
#align set.Union_exists Set.iUnion_exists
@[simp]
theorem iUnion_empty : (⋃ _ : ι, ∅ : Set α) = ∅ :=
iSup_bot
#align set.Union_empty Set.iUnion_empty
@[simp]
theorem iInter_univ : (⋂ _ : ι, univ : Set α) = univ :=
iInf_top
#align set.Inter_univ Set.iInter_univ
section
variable {s : ι → Set α}
@[simp]
theorem iUnion_eq_empty : ⋃ i, s i = ∅ ↔ ∀ i, s i = ∅ :=
iSup_eq_bot
#align set.Union_eq_empty Set.iUnion_eq_empty
@[simp]
theorem iInter_eq_univ : ⋂ i, s i = univ ↔ ∀ i, s i = univ :=
iInf_eq_top
#align set.Inter_eq_univ Set.iInter_eq_univ
@[simp]
theorem nonempty_iUnion : (⋃ i, s i).Nonempty ↔ ∃ i, (s i).Nonempty := by
simp [nonempty_iff_ne_empty]
#align set.nonempty_Union Set.nonempty_iUnion
-- Porting note (#10618): removing `simp`. `simp` can prove it
theorem nonempty_biUnion {t : Set α} {s : α → Set β} :
(⋃ i ∈ t, s i).Nonempty ↔ ∃ i ∈ t, (s i).Nonempty := by simp
#align set.nonempty_bUnion Set.nonempty_biUnion
theorem iUnion_nonempty_index (s : Set α) (t : s.Nonempty → Set β) :
⋃ h, t h = ⋃ x ∈ s, t ⟨x, ‹_›⟩ :=
iSup_exists
#align set.Union_nonempty_index Set.iUnion_nonempty_index
end
@[simp]
theorem iInter_iInter_eq_left {b : β} {s : ∀ x : β, x = b → Set α} :
⋂ (x) (h : x = b), s x h = s b rfl :=
iInf_iInf_eq_left
#align set.Inter_Inter_eq_left Set.iInter_iInter_eq_left
@[simp]
theorem iInter_iInter_eq_right {b : β} {s : ∀ x : β, b = x → Set α} :
⋂ (x) (h : b = x), s x h = s b rfl :=
iInf_iInf_eq_right
#align set.Inter_Inter_eq_right Set.iInter_iInter_eq_right
@[simp]
theorem iUnion_iUnion_eq_left {b : β} {s : ∀ x : β, x = b → Set α} :
⋃ (x) (h : x = b), s x h = s b rfl :=
iSup_iSup_eq_left
#align set.Union_Union_eq_left Set.iUnion_iUnion_eq_left
@[simp]
theorem iUnion_iUnion_eq_right {b : β} {s : ∀ x : β, b = x → Set α} :
⋃ (x) (h : b = x), s x h = s b rfl :=
iSup_iSup_eq_right
#align set.Union_Union_eq_right Set.iUnion_iUnion_eq_right
theorem iInter_or {p q : Prop} (s : p ∨ q → Set α) :
⋂ h, s h = (⋂ h : p, s (Or.inl h)) ∩ ⋂ h : q, s (Or.inr h) :=
iInf_or
#align set.Inter_or Set.iInter_or
theorem iUnion_or {p q : Prop} (s : p ∨ q → Set α) :
⋃ h, s h = (⋃ i, s (Or.inl i)) ∪ ⋃ j, s (Or.inr j) :=
iSup_or
#align set.Union_or Set.iUnion_or
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (hp hq) -/
theorem iUnion_and {p q : Prop} (s : p ∧ q → Set α) : ⋃ h, s h = ⋃ (hp) (hq), s ⟨hp, hq⟩ :=
iSup_and
#align set.Union_and Set.iUnion_and
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (hp hq) -/
theorem iInter_and {p q : Prop} (s : p ∧ q → Set α) : ⋂ h, s h = ⋂ (hp) (hq), s ⟨hp, hq⟩ :=
iInf_and
#align set.Inter_and Set.iInter_and
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i i') -/
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i' i) -/
theorem iUnion_comm (s : ι → ι' → Set α) : ⋃ (i) (i'), s i i' = ⋃ (i') (i), s i i' :=
iSup_comm
#align set.Union_comm Set.iUnion_comm
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i i') -/
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i' i) -/
theorem iInter_comm (s : ι → ι' → Set α) : ⋂ (i) (i'), s i i' = ⋂ (i') (i), s i i' :=
iInf_comm
#align set.Inter_comm Set.iInter_comm
theorem iUnion_sigma {γ : α → Type*} (s : Sigma γ → Set β) : ⋃ ia, s ia = ⋃ i, ⋃ a, s ⟨i, a⟩ :=
iSup_sigma
theorem iUnion_sigma' {γ : α → Type*} (s : ∀ i, γ i → Set β) :
⋃ i, ⋃ a, s i a = ⋃ ia : Sigma γ, s ia.1 ia.2 :=
iSup_sigma' _
theorem iInter_sigma {γ : α → Type*} (s : Sigma γ → Set β) : ⋂ ia, s ia = ⋂ i, ⋂ a, s ⟨i, a⟩ :=
iInf_sigma
theorem iInter_sigma' {γ : α → Type*} (s : ∀ i, γ i → Set β) :
⋂ i, ⋂ a, s i a = ⋂ ia : Sigma γ, s ia.1 ia.2 :=
iInf_sigma' _
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i₁ j₁ i₂ j₂) -/
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i₂ j₂ i₁ j₁) -/
theorem iUnion₂_comm (s : ∀ i₁, κ₁ i₁ → ∀ i₂, κ₂ i₂ → Set α) :
⋃ (i₁) (j₁) (i₂) (j₂), s i₁ j₁ i₂ j₂ = ⋃ (i₂) (j₂) (i₁) (j₁), s i₁ j₁ i₂ j₂ :=
iSup₂_comm _
#align set.Union₂_comm Set.iUnion₂_comm
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i₁ j₁ i₂ j₂) -/
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i₂ j₂ i₁ j₁) -/
theorem iInter₂_comm (s : ∀ i₁, κ₁ i₁ → ∀ i₂, κ₂ i₂ → Set α) :
⋂ (i₁) (j₁) (i₂) (j₂), s i₁ j₁ i₂ j₂ = ⋂ (i₂) (j₂) (i₁) (j₁), s i₁ j₁ i₂ j₂ :=
iInf₂_comm _
#align set.Inter₂_comm Set.iInter₂_comm
@[simp]
theorem biUnion_and (p : ι → Prop) (q : ι → ι' → Prop) (s : ∀ x y, p x ∧ q x y → Set α) :
⋃ (x : ι) (y : ι') (h : p x ∧ q x y), s x y h =
⋃ (x : ι) (hx : p x) (y : ι') (hy : q x y), s x y ⟨hx, hy⟩ := by
simp only [iUnion_and, @iUnion_comm _ ι']
#align set.bUnion_and Set.biUnion_and
@[simp]
theorem biUnion_and' (p : ι' → Prop) (q : ι → ι' → Prop) (s : ∀ x y, p y ∧ q x y → Set α) :
⋃ (x : ι) (y : ι') (h : p y ∧ q x y), s x y h =
⋃ (y : ι') (hy : p y) (x : ι) (hx : q x y), s x y ⟨hy, hx⟩ := by
simp only [iUnion_and, @iUnion_comm _ ι]
#align set.bUnion_and' Set.biUnion_and'
@[simp]
theorem biInter_and (p : ι → Prop) (q : ι → ι' → Prop) (s : ∀ x y, p x ∧ q x y → Set α) :
⋂ (x : ι) (y : ι') (h : p x ∧ q x y), s x y h =
⋂ (x : ι) (hx : p x) (y : ι') (hy : q x y), s x y ⟨hx, hy⟩ := by
simp only [iInter_and, @iInter_comm _ ι']
#align set.bInter_and Set.biInter_and
@[simp]
theorem biInter_and' (p : ι' → Prop) (q : ι → ι' → Prop) (s : ∀ x y, p y ∧ q x y → Set α) :
⋂ (x : ι) (y : ι') (h : p y ∧ q x y), s x y h =
⋂ (y : ι') (hy : p y) (x : ι) (hx : q x y), s x y ⟨hy, hx⟩ := by
simp only [iInter_and, @iInter_comm _ ι]
#align set.bInter_and' Set.biInter_and'
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (x h) -/
@[simp]
theorem iUnion_iUnion_eq_or_left {b : β} {p : β → Prop} {s : ∀ x : β, x = b ∨ p x → Set α} :
⋃ (x) (h), s x h = s b (Or.inl rfl) ∪ ⋃ (x) (h : p x), s x (Or.inr h) := by
simp only [iUnion_or, iUnion_union_distrib, iUnion_iUnion_eq_left]
#align set.Union_Union_eq_or_left Set.iUnion_iUnion_eq_or_left
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (x h) -/
@[simp]
theorem iInter_iInter_eq_or_left {b : β} {p : β → Prop} {s : ∀ x : β, x = b ∨ p x → Set α} :
⋂ (x) (h), s x h = s b (Or.inl rfl) ∩ ⋂ (x) (h : p x), s x (Or.inr h) := by
simp only [iInter_or, iInter_inter_distrib, iInter_iInter_eq_left]
#align set.Inter_Inter_eq_or_left Set.iInter_iInter_eq_or_left
/-! ### Bounded unions and intersections -/
/-- A specialization of `mem_iUnion₂`. -/
theorem mem_biUnion {s : Set α} {t : α → Set β} {x : α} {y : β} (xs : x ∈ s) (ytx : y ∈ t x) :
y ∈ ⋃ x ∈ s, t x :=
mem_iUnion₂_of_mem xs ytx
#align set.mem_bUnion Set.mem_biUnion
/-- A specialization of `mem_iInter₂`. -/
theorem mem_biInter {s : Set α} {t : α → Set β} {y : β} (h : ∀ x ∈ s, y ∈ t x) :
y ∈ ⋂ x ∈ s, t x :=
mem_iInter₂_of_mem h
#align set.mem_bInter Set.mem_biInter
/-- A specialization of `subset_iUnion₂`. -/
theorem subset_biUnion_of_mem {s : Set α} {u : α → Set β} {x : α} (xs : x ∈ s) :
u x ⊆ ⋃ x ∈ s, u x :=
-- Porting note: Why is this not just `subset_iUnion₂ x xs`?
@subset_iUnion₂ β α (· ∈ s) (fun i _ => u i) x xs
#align set.subset_bUnion_of_mem Set.subset_biUnion_of_mem
/-- A specialization of `iInter₂_subset`. -/
theorem biInter_subset_of_mem {s : Set α} {t : α → Set β} {x : α} (xs : x ∈ s) :
⋂ x ∈ s, t x ⊆ t x :=
iInter₂_subset x xs
#align set.bInter_subset_of_mem Set.biInter_subset_of_mem
theorem biUnion_subset_biUnion_left {s s' : Set α} {t : α → Set β} (h : s ⊆ s') :
⋃ x ∈ s, t x ⊆ ⋃ x ∈ s', t x :=
iUnion₂_subset fun _ hx => subset_biUnion_of_mem <| h hx
#align set.bUnion_subset_bUnion_left Set.biUnion_subset_biUnion_left
theorem biInter_subset_biInter_left {s s' : Set α} {t : α → Set β} (h : s' ⊆ s) :
⋂ x ∈ s, t x ⊆ ⋂ x ∈ s', t x :=
subset_iInter₂ fun _ hx => biInter_subset_of_mem <| h hx
#align set.bInter_subset_bInter_left Set.biInter_subset_biInter_left
theorem biUnion_mono {s s' : Set α} {t t' : α → Set β} (hs : s' ⊆ s) (h : ∀ x ∈ s, t x ⊆ t' x) :
⋃ x ∈ s', t x ⊆ ⋃ x ∈ s, t' x :=
(biUnion_subset_biUnion_left hs).trans <| iUnion₂_mono h
#align set.bUnion_mono Set.biUnion_mono
theorem biInter_mono {s s' : Set α} {t t' : α → Set β} (hs : s ⊆ s') (h : ∀ x ∈ s, t x ⊆ t' x) :
⋂ x ∈ s', t x ⊆ ⋂ x ∈ s, t' x :=
(biInter_subset_biInter_left hs).trans <| iInter₂_mono h
#align set.bInter_mono Set.biInter_mono
theorem biUnion_eq_iUnion (s : Set α) (t : ∀ x ∈ s, Set β) :
⋃ x ∈ s, t x ‹_› = ⋃ x : s, t x x.2 :=
iSup_subtype'
#align set.bUnion_eq_Union Set.biUnion_eq_iUnion
theorem biInter_eq_iInter (s : Set α) (t : ∀ x ∈ s, Set β) :
⋂ x ∈ s, t x ‹_› = ⋂ x : s, t x x.2 :=
iInf_subtype'
#align set.bInter_eq_Inter Set.biInter_eq_iInter
theorem iUnion_subtype (p : α → Prop) (s : { x // p x } → Set β) :
⋃ x : { x // p x }, s x = ⋃ (x) (hx : p x), s ⟨x, hx⟩ :=
iSup_subtype
#align set.Union_subtype Set.iUnion_subtype
theorem iInter_subtype (p : α → Prop) (s : { x // p x } → Set β) :
⋂ x : { x // p x }, s x = ⋂ (x) (hx : p x), s ⟨x, hx⟩ :=
iInf_subtype
#align set.Inter_subtype Set.iInter_subtype
theorem biInter_empty (u : α → Set β) : ⋂ x ∈ (∅ : Set α), u x = univ :=
iInf_emptyset
#align set.bInter_empty Set.biInter_empty
theorem biInter_univ (u : α → Set β) : ⋂ x ∈ @univ α, u x = ⋂ x, u x :=
iInf_univ
#align set.bInter_univ Set.biInter_univ
@[simp]
theorem biUnion_self (s : Set α) : ⋃ x ∈ s, s = s :=
Subset.antisymm (iUnion₂_subset fun _ _ => Subset.refl s) fun _ hx => mem_biUnion hx hx
#align set.bUnion_self Set.biUnion_self
@[simp]
theorem iUnion_nonempty_self (s : Set α) : ⋃ _ : s.Nonempty, s = s := by
rw [iUnion_nonempty_index, biUnion_self]
#align set.Union_nonempty_self Set.iUnion_nonempty_self
theorem biInter_singleton (a : α) (s : α → Set β) : ⋂ x ∈ ({a} : Set α), s x = s a :=
iInf_singleton
#align set.bInter_singleton Set.biInter_singleton
theorem biInter_union (s t : Set α) (u : α → Set β) :
⋂ x ∈ s ∪ t, u x = (⋂ x ∈ s, u x) ∩ ⋂ x ∈ t, u x :=
iInf_union
#align set.bInter_union Set.biInter_union
theorem biInter_insert (a : α) (s : Set α) (t : α → Set β) :
⋂ x ∈ insert a s, t x = t a ∩ ⋂ x ∈ s, t x := by simp
#align set.bInter_insert Set.biInter_insert
theorem biInter_pair (a b : α) (s : α → Set β) : ⋂ x ∈ ({a, b} : Set α), s x = s a ∩ s b := by
rw [biInter_insert, biInter_singleton]
#align set.bInter_pair Set.biInter_pair
theorem biInter_inter {ι α : Type*} {s : Set ι} (hs : s.Nonempty) (f : ι → Set α) (t : Set α) :
⋂ i ∈ s, f i ∩ t = (⋂ i ∈ s, f i) ∩ t := by
haveI : Nonempty s := hs.to_subtype
simp [biInter_eq_iInter, ← iInter_inter]
#align set.bInter_inter Set.biInter_inter
theorem inter_biInter {ι α : Type*} {s : Set ι} (hs : s.Nonempty) (f : ι → Set α) (t : Set α) :
⋂ i ∈ s, t ∩ f i = t ∩ ⋂ i ∈ s, f i := by
rw [inter_comm, ← biInter_inter hs]
simp [inter_comm]
#align set.inter_bInter Set.inter_biInter
theorem biUnion_empty (s : α → Set β) : ⋃ x ∈ (∅ : Set α), s x = ∅ :=
iSup_emptyset
#align set.bUnion_empty Set.biUnion_empty
theorem biUnion_univ (s : α → Set β) : ⋃ x ∈ @univ α, s x = ⋃ x, s x :=
iSup_univ
#align set.bUnion_univ Set.biUnion_univ
theorem biUnion_singleton (a : α) (s : α → Set β) : ⋃ x ∈ ({a} : Set α), s x = s a :=
iSup_singleton
#align set.bUnion_singleton Set.biUnion_singleton
@[simp]
theorem biUnion_of_singleton (s : Set α) : ⋃ x ∈ s, {x} = s :=
ext <| by simp
#align set.bUnion_of_singleton Set.biUnion_of_singleton
theorem biUnion_union (s t : Set α) (u : α → Set β) :
⋃ x ∈ s ∪ t, u x = (⋃ x ∈ s, u x) ∪ ⋃ x ∈ t, u x :=
iSup_union
#align set.bUnion_union Set.biUnion_union
@[simp]
theorem iUnion_coe_set {α β : Type*} (s : Set α) (f : s → Set β) :
⋃ i, f i = ⋃ i ∈ s, f ⟨i, ‹i ∈ s›⟩ :=
iUnion_subtype _ _
#align set.Union_coe_set Set.iUnion_coe_set
@[simp]
theorem iInter_coe_set {α β : Type*} (s : Set α) (f : s → Set β) :
⋂ i, f i = ⋂ i ∈ s, f ⟨i, ‹i ∈ s›⟩ :=
iInter_subtype _ _
#align set.Inter_coe_set Set.iInter_coe_set
theorem biUnion_insert (a : α) (s : Set α) (t : α → Set β) :
⋃ x ∈ insert a s, t x = t a ∪ ⋃ x ∈ s, t x := by simp
#align set.bUnion_insert Set.biUnion_insert
theorem biUnion_pair (a b : α) (s : α → Set β) : ⋃ x ∈ ({a, b} : Set α), s x = s a ∪ s b := by
simp
#align set.bUnion_pair Set.biUnion_pair
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/
theorem inter_iUnion₂ (s : Set α) (t : ∀ i, κ i → Set α) :
(s ∩ ⋃ (i) (j), t i j) = ⋃ (i) (j), s ∩ t i j := by simp only [inter_iUnion]
#align set.inter_Union₂ Set.inter_iUnion₂
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/
theorem iUnion₂_inter (s : ∀ i, κ i → Set α) (t : Set α) :
(⋃ (i) (j), s i j) ∩ t = ⋃ (i) (j), s i j ∩ t := by simp_rw [iUnion_inter]
#align set.Union₂_inter Set.iUnion₂_inter
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/
theorem union_iInter₂ (s : Set α) (t : ∀ i, κ i → Set α) :
(s ∪ ⋂ (i) (j), t i j) = ⋂ (i) (j), s ∪ t i j := by simp_rw [union_iInter]
#align set.union_Inter₂ Set.union_iInter₂
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/
theorem iInter₂_union (s : ∀ i, κ i → Set α) (t : Set α) :
(⋂ (i) (j), s i j) ∪ t = ⋂ (i) (j), s i j ∪ t := by simp_rw [iInter_union]
#align set.Inter₂_union Set.iInter₂_union
theorem mem_sUnion_of_mem {x : α} {t : Set α} {S : Set (Set α)} (hx : x ∈ t) (ht : t ∈ S) :
x ∈ ⋃₀S :=
⟨t, ht, hx⟩
#align set.mem_sUnion_of_mem Set.mem_sUnion_of_mem
-- is this theorem really necessary?
theorem not_mem_of_not_mem_sUnion {x : α} {t : Set α} {S : Set (Set α)} (hx : x ∉ ⋃₀S)
(ht : t ∈ S) : x ∉ t := fun h => hx ⟨t, ht, h⟩
#align set.not_mem_of_not_mem_sUnion Set.not_mem_of_not_mem_sUnion
theorem sInter_subset_of_mem {S : Set (Set α)} {t : Set α} (tS : t ∈ S) : ⋂₀ S ⊆ t :=
sInf_le tS
#align set.sInter_subset_of_mem Set.sInter_subset_of_mem
theorem subset_sUnion_of_mem {S : Set (Set α)} {t : Set α} (tS : t ∈ S) : t ⊆ ⋃₀S :=
le_sSup tS
#align set.subset_sUnion_of_mem Set.subset_sUnion_of_mem
theorem subset_sUnion_of_subset {s : Set α} (t : Set (Set α)) (u : Set α) (h₁ : s ⊆ u)
(h₂ : u ∈ t) : s ⊆ ⋃₀t :=
Subset.trans h₁ (subset_sUnion_of_mem h₂)
#align set.subset_sUnion_of_subset Set.subset_sUnion_of_subset
theorem sUnion_subset {S : Set (Set α)} {t : Set α} (h : ∀ t' ∈ S, t' ⊆ t) : ⋃₀S ⊆ t :=
sSup_le h
#align set.sUnion_subset Set.sUnion_subset
@[simp]
theorem sUnion_subset_iff {s : Set (Set α)} {t : Set α} : ⋃₀s ⊆ t ↔ ∀ t' ∈ s, t' ⊆ t :=
sSup_le_iff
#align set.sUnion_subset_iff Set.sUnion_subset_iff
/-- `sUnion` is monotone under taking a subset of each set. -/
lemma sUnion_mono_subsets {s : Set (Set α)} {f : Set α → Set α} (hf : ∀ t : Set α, t ⊆ f t) :
⋃₀ s ⊆ ⋃₀ (f '' s) :=
fun _ ⟨t, htx, hxt⟩ ↦ ⟨f t, mem_image_of_mem f htx, hf t hxt⟩
/-- `sUnion` is monotone under taking a superset of each set. -/
lemma sUnion_mono_supsets {s : Set (Set α)} {f : Set α → Set α} (hf : ∀ t : Set α, f t ⊆ t) :
⋃₀ (f '' s) ⊆ ⋃₀ s :=
-- If t ∈ f '' s is arbitrary; t = f u for some u : Set α.
fun _ ⟨_, ⟨u, hus, hut⟩, hxt⟩ ↦ ⟨u, hus, (hut ▸ hf u) hxt⟩
theorem subset_sInter {S : Set (Set α)} {t : Set α} (h : ∀ t' ∈ S, t ⊆ t') : t ⊆ ⋂₀ S :=
le_sInf h
#align set.subset_sInter Set.subset_sInter
@[simp]
theorem subset_sInter_iff {S : Set (Set α)} {t : Set α} : t ⊆ ⋂₀ S ↔ ∀ t' ∈ S, t ⊆ t' :=
le_sInf_iff
#align set.subset_sInter_iff Set.subset_sInter_iff
@[gcongr]
theorem sUnion_subset_sUnion {S T : Set (Set α)} (h : S ⊆ T) : ⋃₀S ⊆ ⋃₀T :=
sUnion_subset fun _ hs => subset_sUnion_of_mem (h hs)
#align set.sUnion_subset_sUnion Set.sUnion_subset_sUnion
@[gcongr]
theorem sInter_subset_sInter {S T : Set (Set α)} (h : S ⊆ T) : ⋂₀ T ⊆ ⋂₀ S :=
subset_sInter fun _ hs => sInter_subset_of_mem (h hs)
#align set.sInter_subset_sInter Set.sInter_subset_sInter
@[simp]
theorem sUnion_empty : ⋃₀∅ = (∅ : Set α) :=
sSup_empty
#align set.sUnion_empty Set.sUnion_empty
@[simp]
theorem sInter_empty : ⋂₀ ∅ = (univ : Set α) :=
sInf_empty
#align set.sInter_empty Set.sInter_empty
@[simp]
theorem sUnion_singleton (s : Set α) : ⋃₀{s} = s :=
sSup_singleton
#align set.sUnion_singleton Set.sUnion_singleton
@[simp]
theorem sInter_singleton (s : Set α) : ⋂₀ {s} = s :=
sInf_singleton
#align set.sInter_singleton Set.sInter_singleton
@[simp]
theorem sUnion_eq_empty {S : Set (Set α)} : ⋃₀S = ∅ ↔ ∀ s ∈ S, s = ∅ :=
sSup_eq_bot
#align set.sUnion_eq_empty Set.sUnion_eq_empty
@[simp]
theorem sInter_eq_univ {S : Set (Set α)} : ⋂₀ S = univ ↔ ∀ s ∈ S, s = univ :=
sInf_eq_top
#align set.sInter_eq_univ Set.sInter_eq_univ
theorem subset_powerset_iff {s : Set (Set α)} {t : Set α} : s ⊆ 𝒫 t ↔ ⋃₀ s ⊆ t :=
sUnion_subset_iff.symm
/-- `⋃₀` and `𝒫` form a Galois connection. -/
theorem sUnion_powerset_gc :
GaloisConnection (⋃₀ · : Set (Set α) → Set α) (𝒫 · : Set α → Set (Set α)) :=
gc_sSup_Iic
/-- `⋃₀` and `𝒫` form a Galois insertion. -/
def sUnion_powerset_gi :
GaloisInsertion (⋃₀ · : Set (Set α) → Set α) (𝒫 · : Set α → Set (Set α)) :=
gi_sSup_Iic
/-- If all sets in a collection are either `∅` or `Set.univ`, then so is their union. -/
theorem sUnion_mem_empty_univ {S : Set (Set α)} (h : S ⊆ {∅, univ}) :
⋃₀ S ∈ ({∅, univ} : Set (Set α)) := by
simp only [mem_insert_iff, mem_singleton_iff, or_iff_not_imp_left, sUnion_eq_empty, not_forall]
rintro ⟨s, hs, hne⟩
obtain rfl : s = univ := (h hs).resolve_left hne
exact univ_subset_iff.1 <| subset_sUnion_of_mem hs
@[simp]
theorem nonempty_sUnion {S : Set (Set α)} : (⋃₀S).Nonempty ↔ ∃ s ∈ S, Set.Nonempty s := by
simp [nonempty_iff_ne_empty]
#align set.nonempty_sUnion Set.nonempty_sUnion
theorem Nonempty.of_sUnion {s : Set (Set α)} (h : (⋃₀s).Nonempty) : s.Nonempty :=
let ⟨s, hs, _⟩ := nonempty_sUnion.1 h
⟨s, hs⟩
#align set.nonempty.of_sUnion Set.Nonempty.of_sUnion
theorem Nonempty.of_sUnion_eq_univ [Nonempty α] {s : Set (Set α)} (h : ⋃₀s = univ) : s.Nonempty :=
Nonempty.of_sUnion <| h.symm ▸ univ_nonempty
#align set.nonempty.of_sUnion_eq_univ Set.Nonempty.of_sUnion_eq_univ
theorem sUnion_union (S T : Set (Set α)) : ⋃₀(S ∪ T) = ⋃₀S ∪ ⋃₀T :=
sSup_union
#align set.sUnion_union Set.sUnion_union
theorem sInter_union (S T : Set (Set α)) : ⋂₀ (S ∪ T) = ⋂₀ S ∩ ⋂₀ T :=
sInf_union
#align set.sInter_union Set.sInter_union
@[simp]
theorem sUnion_insert (s : Set α) (T : Set (Set α)) : ⋃₀insert s T = s ∪ ⋃₀T :=
sSup_insert
#align set.sUnion_insert Set.sUnion_insert
@[simp]
theorem sInter_insert (s : Set α) (T : Set (Set α)) : ⋂₀ insert s T = s ∩ ⋂₀ T :=
sInf_insert
#align set.sInter_insert Set.sInter_insert
@[simp]
theorem sUnion_diff_singleton_empty (s : Set (Set α)) : ⋃₀(s \ {∅}) = ⋃₀s :=
sSup_diff_singleton_bot s
#align set.sUnion_diff_singleton_empty Set.sUnion_diff_singleton_empty
@[simp]
theorem sInter_diff_singleton_univ (s : Set (Set α)) : ⋂₀ (s \ {univ}) = ⋂₀ s :=
sInf_diff_singleton_top s
#align set.sInter_diff_singleton_univ Set.sInter_diff_singleton_univ
theorem sUnion_pair (s t : Set α) : ⋃₀{s, t} = s ∪ t :=
sSup_pair
#align set.sUnion_pair Set.sUnion_pair
theorem sInter_pair (s t : Set α) : ⋂₀ {s, t} = s ∩ t :=
sInf_pair
#align set.sInter_pair Set.sInter_pair
@[simp]
theorem sUnion_image (f : α → Set β) (s : Set α) : ⋃₀(f '' s) = ⋃ x ∈ s, f x :=
sSup_image
#align set.sUnion_image Set.sUnion_image
@[simp]
theorem sInter_image (f : α → Set β) (s : Set α) : ⋂₀ (f '' s) = ⋂ x ∈ s, f x :=
sInf_image
#align set.sInter_image Set.sInter_image
@[simp]
theorem sUnion_range (f : ι → Set β) : ⋃₀range f = ⋃ x, f x :=
rfl
#align set.sUnion_range Set.sUnion_range
@[simp]
theorem sInter_range (f : ι → Set β) : ⋂₀ range f = ⋂ x, f x :=
rfl
#align set.sInter_range Set.sInter_range
theorem iUnion_eq_univ_iff {f : ι → Set α} : ⋃ i, f i = univ ↔ ∀ x, ∃ i, x ∈ f i := by
simp only [eq_univ_iff_forall, mem_iUnion]
#align set.Union_eq_univ_iff Set.iUnion_eq_univ_iff
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/
theorem iUnion₂_eq_univ_iff {s : ∀ i, κ i → Set α} :
⋃ (i) (j), s i j = univ ↔ ∀ a, ∃ i j, a ∈ s i j := by
simp only [iUnion_eq_univ_iff, mem_iUnion]
#align set.Union₂_eq_univ_iff Set.iUnion₂_eq_univ_iff
theorem sUnion_eq_univ_iff {c : Set (Set α)} : ⋃₀c = univ ↔ ∀ a, ∃ b ∈ c, a ∈ b := by
simp only [eq_univ_iff_forall, mem_sUnion]
#align set.sUnion_eq_univ_iff Set.sUnion_eq_univ_iff
-- classical
theorem iInter_eq_empty_iff {f : ι → Set α} : ⋂ i, f i = ∅ ↔ ∀ x, ∃ i, x ∉ f i := by
simp [Set.eq_empty_iff_forall_not_mem]
#align set.Inter_eq_empty_iff Set.iInter_eq_empty_iff
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/
-- classical
theorem iInter₂_eq_empty_iff {s : ∀ i, κ i → Set α} :
⋂ (i) (j), s i j = ∅ ↔ ∀ a, ∃ i j, a ∉ s i j := by
simp only [eq_empty_iff_forall_not_mem, mem_iInter, not_forall]
#align set.Inter₂_eq_empty_iff Set.iInter₂_eq_empty_iff
-- classical
theorem sInter_eq_empty_iff {c : Set (Set α)} : ⋂₀ c = ∅ ↔ ∀ a, ∃ b ∈ c, a ∉ b := by
simp [Set.eq_empty_iff_forall_not_mem]
#align set.sInter_eq_empty_iff Set.sInter_eq_empty_iff
-- classical
@[simp]
theorem nonempty_iInter {f : ι → Set α} : (⋂ i, f i).Nonempty ↔ ∃ x, ∀ i, x ∈ f i := by
simp [nonempty_iff_ne_empty, iInter_eq_empty_iff]
#align set.nonempty_Inter Set.nonempty_iInter
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/
-- classical
-- Porting note (#10618): removing `simp`. `simp` can prove it
theorem nonempty_iInter₂ {s : ∀ i, κ i → Set α} :
(⋂ (i) (j), s i j).Nonempty ↔ ∃ a, ∀ i j, a ∈ s i j := by
simp
#align set.nonempty_Inter₂ Set.nonempty_iInter₂
-- classical
@[simp]
theorem nonempty_sInter {c : Set (Set α)} : (⋂₀ c).Nonempty ↔ ∃ a, ∀ b ∈ c, a ∈ b := by
simp [nonempty_iff_ne_empty, sInter_eq_empty_iff]
#align set.nonempty_sInter Set.nonempty_sInter
-- classical
theorem compl_sUnion (S : Set (Set α)) : (⋃₀S)ᶜ = ⋂₀ (compl '' S) :=
ext fun x => by simp
#align set.compl_sUnion Set.compl_sUnion
-- classical
theorem sUnion_eq_compl_sInter_compl (S : Set (Set α)) : ⋃₀S = (⋂₀ (compl '' S))ᶜ := by
rw [← compl_compl (⋃₀S), compl_sUnion]
#align set.sUnion_eq_compl_sInter_compl Set.sUnion_eq_compl_sInter_compl
-- classical
theorem compl_sInter (S : Set (Set α)) : (⋂₀ S)ᶜ = ⋃₀(compl '' S) := by
rw [sUnion_eq_compl_sInter_compl, compl_compl_image]
#align set.compl_sInter Set.compl_sInter
-- classical
theorem sInter_eq_compl_sUnion_compl (S : Set (Set α)) : ⋂₀ S = (⋃₀(compl '' S))ᶜ := by
rw [← compl_compl (⋂₀ S), compl_sInter]
#align set.sInter_eq_compl_sUnion_compl Set.sInter_eq_compl_sUnion_compl
theorem inter_empty_of_inter_sUnion_empty {s t : Set α} {S : Set (Set α)} (hs : t ∈ S)
(h : s ∩ ⋃₀S = ∅) : s ∩ t = ∅ :=
eq_empty_of_subset_empty <| by
rw [← h]; exact inter_subset_inter_right _ (subset_sUnion_of_mem hs)
#align set.inter_empty_of_inter_sUnion_empty Set.inter_empty_of_inter_sUnion_empty
theorem range_sigma_eq_iUnion_range {γ : α → Type*} (f : Sigma γ → β) :
range f = ⋃ a, range fun b => f ⟨a, b⟩ :=
Set.ext <| by simp
#align set.range_sigma_eq_Union_range Set.range_sigma_eq_iUnion_range
theorem iUnion_eq_range_sigma (s : α → Set β) : ⋃ i, s i = range fun a : Σi, s i => a.2 := by
simp [Set.ext_iff]
#align set.Union_eq_range_sigma Set.iUnion_eq_range_sigma
theorem iUnion_eq_range_psigma (s : ι → Set β) : ⋃ i, s i = range fun a : Σ'i, s i => a.2 := by
simp [Set.ext_iff]
#align set.Union_eq_range_psigma Set.iUnion_eq_range_psigma
theorem iUnion_image_preimage_sigma_mk_eq_self {ι : Type*} {σ : ι → Type*} (s : Set (Sigma σ)) :
⋃ i, Sigma.mk i '' (Sigma.mk i ⁻¹' s) = s := by
ext x
simp only [mem_iUnion, mem_image, mem_preimage]
constructor
· rintro ⟨i, a, h, rfl⟩
exact h
· intro h
cases' x with i a
exact ⟨i, a, h, rfl⟩
#align set.Union_image_preimage_sigma_mk_eq_self Set.iUnion_image_preimage_sigma_mk_eq_self
theorem Sigma.univ (X : α → Type*) : (Set.univ : Set (Σa, X a)) = ⋃ a, range (Sigma.mk a) :=
Set.ext fun x =>
iff_of_true trivial ⟨range (Sigma.mk x.1), Set.mem_range_self _, x.2, Sigma.eta x⟩
#align set.sigma.univ Set.Sigma.univ
alias sUnion_mono := sUnion_subset_sUnion
#align set.sUnion_mono Set.sUnion_mono
theorem iUnion_subset_iUnion_const {s : Set α} (h : ι → ι₂) : ⋃ _ : ι, s ⊆ ⋃ _ : ι₂, s :=
iSup_const_mono (α := Set α) h
#align set.Union_subset_Union_const Set.iUnion_subset_iUnion_const
@[simp]
theorem iUnion_singleton_eq_range {α β : Type*} (f : α → β) : ⋃ x : α, {f x} = range f := by
ext x
simp [@eq_comm _ x]
#align set.Union_singleton_eq_range Set.iUnion_singleton_eq_range
theorem iUnion_of_singleton (α : Type*) : (⋃ x, {x} : Set α) = univ := by simp [Set.ext_iff]
#align set.Union_of_singleton Set.iUnion_of_singleton
theorem iUnion_of_singleton_coe (s : Set α) : ⋃ i : s, ({(i : α)} : Set α) = s := by simp
#align set.Union_of_singleton_coe Set.iUnion_of_singleton_coe
theorem sUnion_eq_biUnion {s : Set (Set α)} : ⋃₀s = ⋃ (i : Set α) (_ : i ∈ s), i := by
rw [← sUnion_image, image_id']
#align set.sUnion_eq_bUnion Set.sUnion_eq_biUnion
theorem sInter_eq_biInter {s : Set (Set α)} : ⋂₀ s = ⋂ (i : Set α) (_ : i ∈ s), i := by
rw [← sInter_image, image_id']
#align set.sInter_eq_bInter Set.sInter_eq_biInter
theorem sUnion_eq_iUnion {s : Set (Set α)} : ⋃₀s = ⋃ i : s, i := by
simp only [← sUnion_range, Subtype.range_coe]
#align set.sUnion_eq_Union Set.sUnion_eq_iUnion
theorem sInter_eq_iInter {s : Set (Set α)} : ⋂₀ s = ⋂ i : s, i := by
simp only [← sInter_range, Subtype.range_coe]
#align set.sInter_eq_Inter Set.sInter_eq_iInter
@[simp]
theorem iUnion_of_empty [IsEmpty ι] (s : ι → Set α) : ⋃ i, s i = ∅ :=
iSup_of_empty _
#align set.Union_of_empty Set.iUnion_of_empty
@[simp]
theorem iInter_of_empty [IsEmpty ι] (s : ι → Set α) : ⋂ i, s i = univ :=
iInf_of_empty _
#align set.Inter_of_empty Set.iInter_of_empty
theorem union_eq_iUnion {s₁ s₂ : Set α} : s₁ ∪ s₂ = ⋃ b : Bool, cond b s₁ s₂ :=
sup_eq_iSup s₁ s₂
#align set.union_eq_Union Set.union_eq_iUnion
theorem inter_eq_iInter {s₁ s₂ : Set α} : s₁ ∩ s₂ = ⋂ b : Bool, cond b s₁ s₂ :=
inf_eq_iInf s₁ s₂
#align set.inter_eq_Inter Set.inter_eq_iInter
theorem sInter_union_sInter {S T : Set (Set α)} :
⋂₀ S ∪ ⋂₀ T = ⋂ p ∈ S ×ˢ T, (p : Set α × Set α).1 ∪ p.2 :=
sInf_sup_sInf
#align set.sInter_union_sInter Set.sInter_union_sInter
theorem sUnion_inter_sUnion {s t : Set (Set α)} :
⋃₀s ∩ ⋃₀t = ⋃ p ∈ s ×ˢ t, (p : Set α × Set α).1 ∩ p.2 :=
sSup_inf_sSup
#align set.sUnion_inter_sUnion Set.sUnion_inter_sUnion
theorem biUnion_iUnion (s : ι → Set α) (t : α → Set β) :
⋃ x ∈ ⋃ i, s i, t x = ⋃ (i) (x ∈ s i), t x := by simp [@iUnion_comm _ ι]
#align set.bUnion_Union Set.biUnion_iUnion
theorem biInter_iUnion (s : ι → Set α) (t : α → Set β) :
⋂ x ∈ ⋃ i, s i, t x = ⋂ (i) (x ∈ s i), t x := by simp [@iInter_comm _ ι]
#align set.bInter_Union Set.biInter_iUnion
theorem sUnion_iUnion (s : ι → Set (Set α)) : ⋃₀⋃ i, s i = ⋃ i, ⋃₀s i := by
simp only [sUnion_eq_biUnion, biUnion_iUnion]
#align set.sUnion_Union Set.sUnion_iUnion
theorem sInter_iUnion (s : ι → Set (Set α)) : ⋂₀ ⋃ i, s i = ⋂ i, ⋂₀ s i := by
simp only [sInter_eq_biInter, biInter_iUnion]
#align set.sInter_Union Set.sInter_iUnion
theorem iUnion_range_eq_sUnion {α β : Type*} (C : Set (Set α)) {f : ∀ s : C, β → (s : Type _)}
(hf : ∀ s : C, Surjective (f s)) : ⋃ y : β, range (fun s : C => (f s y).val) = ⋃₀C := by
ext x; constructor
· rintro ⟨s, ⟨y, rfl⟩, ⟨s, hs⟩, rfl⟩
refine ⟨_, hs, ?_⟩
exact (f ⟨s, hs⟩ y).2
· rintro ⟨s, hs, hx⟩
cases' hf ⟨s, hs⟩ ⟨x, hx⟩ with y hy
refine ⟨_, ⟨y, rfl⟩, ⟨s, hs⟩, ?_⟩
exact congr_arg Subtype.val hy
#align set.Union_range_eq_sUnion Set.iUnion_range_eq_sUnion
theorem iUnion_range_eq_iUnion (C : ι → Set α) {f : ∀ x : ι, β → C x}
(hf : ∀ x : ι, Surjective (f x)) : ⋃ y : β, range (fun x : ι => (f x y).val) = ⋃ x, C x := by
ext x; rw [mem_iUnion, mem_iUnion]; constructor
· rintro ⟨y, i, rfl⟩
exact ⟨i, (f i y).2⟩
· rintro ⟨i, hx⟩
cases' hf i ⟨x, hx⟩ with y hy
exact ⟨y, i, congr_arg Subtype.val hy⟩
#align set.Union_range_eq_Union Set.iUnion_range_eq_iUnion
theorem union_distrib_iInter_left (s : ι → Set α) (t : Set α) : (t ∪ ⋂ i, s i) = ⋂ i, t ∪ s i :=
sup_iInf_eq _ _
#align set.union_distrib_Inter_left Set.union_distrib_iInter_left
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/
theorem union_distrib_iInter₂_left (s : Set α) (t : ∀ i, κ i → Set α) :
(s ∪ ⋂ (i) (j), t i j) = ⋂ (i) (j), s ∪ t i j := by simp_rw [union_distrib_iInter_left]
#align set.union_distrib_Inter₂_left Set.union_distrib_iInter₂_left
theorem union_distrib_iInter_right (s : ι → Set α) (t : Set α) : (⋂ i, s i) ∪ t = ⋂ i, s i ∪ t :=
iInf_sup_eq _ _
#align set.union_distrib_Inter_right Set.union_distrib_iInter_right
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/
theorem union_distrib_iInter₂_right (s : ∀ i, κ i → Set α) (t : Set α) :
(⋂ (i) (j), s i j) ∪ t = ⋂ (i) (j), s i j ∪ t := by simp_rw [union_distrib_iInter_right]
#align set.union_distrib_Inter₂_right Set.union_distrib_iInter₂_right
section Function
/-! ### Lemmas about `Set.MapsTo`
Porting note: some lemmas in this section were upgraded from implications to `iff`s.
-/
@[simp]
theorem mapsTo_sUnion {S : Set (Set α)} {t : Set β} {f : α → β} :
MapsTo f (⋃₀ S) t ↔ ∀ s ∈ S, MapsTo f s t :=
sUnion_subset_iff
#align set.maps_to_sUnion Set.mapsTo_sUnion
@[simp]
theorem mapsTo_iUnion {s : ι → Set α} {t : Set β} {f : α → β} :
MapsTo f (⋃ i, s i) t ↔ ∀ i, MapsTo f (s i) t :=
iUnion_subset_iff
#align set.maps_to_Union Set.mapsTo_iUnion
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/
theorem mapsTo_iUnion₂ {s : ∀ i, κ i → Set α} {t : Set β} {f : α → β} :
MapsTo f (⋃ (i) (j), s i j) t ↔ ∀ i j, MapsTo f (s i j) t :=
iUnion₂_subset_iff
#align set.maps_to_Union₂ Set.mapsTo_iUnion₂
theorem mapsTo_iUnion_iUnion {s : ι → Set α} {t : ι → Set β} {f : α → β}
(H : ∀ i, MapsTo f (s i) (t i)) : MapsTo f (⋃ i, s i) (⋃ i, t i) :=
mapsTo_iUnion.2 fun i ↦ (H i).mono_right (subset_iUnion t i)
#align set.maps_to_Union_Union Set.mapsTo_iUnion_iUnion
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/
theorem mapsTo_iUnion₂_iUnion₂ {s : ∀ i, κ i → Set α} {t : ∀ i, κ i → Set β} {f : α → β}
(H : ∀ i j, MapsTo f (s i j) (t i j)) : MapsTo f (⋃ (i) (j), s i j) (⋃ (i) (j), t i j) :=
mapsTo_iUnion_iUnion fun i => mapsTo_iUnion_iUnion (H i)
#align set.maps_to_Union₂_Union₂ Set.mapsTo_iUnion₂_iUnion₂
@[simp]
theorem mapsTo_sInter {s : Set α} {T : Set (Set β)} {f : α → β} :
MapsTo f s (⋂₀ T) ↔ ∀ t ∈ T, MapsTo f s t :=
forall₂_swap
#align set.maps_to_sInter Set.mapsTo_sInter
@[simp]
theorem mapsTo_iInter {s : Set α} {t : ι → Set β} {f : α → β} :
MapsTo f s (⋂ i, t i) ↔ ∀ i, MapsTo f s (t i) :=
mapsTo_sInter.trans forall_mem_range
#align set.maps_to_Inter Set.mapsTo_iInter
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/
theorem mapsTo_iInter₂ {s : Set α} {t : ∀ i, κ i → Set β} {f : α → β} :
MapsTo f s (⋂ (i) (j), t i j) ↔ ∀ i j, MapsTo f s (t i j) := by
simp only [mapsTo_iInter]
#align set.maps_to_Inter₂ Set.mapsTo_iInter₂
theorem mapsTo_iInter_iInter {s : ι → Set α} {t : ι → Set β} {f : α → β}
(H : ∀ i, MapsTo f (s i) (t i)) : MapsTo f (⋂ i, s i) (⋂ i, t i) :=
mapsTo_iInter.2 fun i => (H i).mono_left (iInter_subset s i)
#align set.maps_to_Inter_Inter Set.mapsTo_iInter_iInter
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/
theorem mapsTo_iInter₂_iInter₂ {s : ∀ i, κ i → Set α} {t : ∀ i, κ i → Set β} {f : α → β}
(H : ∀ i j, MapsTo f (s i j) (t i j)) : MapsTo f (⋂ (i) (j), s i j) (⋂ (i) (j), t i j) :=
mapsTo_iInter_iInter fun i => mapsTo_iInter_iInter (H i)
#align set.maps_to_Inter₂_Inter₂ Set.mapsTo_iInter₂_iInter₂
theorem image_iInter_subset (s : ι → Set α) (f : α → β) : (f '' ⋂ i, s i) ⊆ ⋂ i, f '' s i :=
(mapsTo_iInter_iInter fun i => mapsTo_image f (s i)).image_subset
#align set.image_Inter_subset Set.image_iInter_subset
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/
theorem image_iInter₂_subset (s : ∀ i, κ i → Set α) (f : α → β) :
(f '' ⋂ (i) (j), s i j) ⊆ ⋂ (i) (j), f '' s i j :=
(mapsTo_iInter₂_iInter₂ fun i hi => mapsTo_image f (s i hi)).image_subset
#align set.image_Inter₂_subset Set.image_iInter₂_subset
theorem image_sInter_subset (S : Set (Set α)) (f : α → β) : f '' ⋂₀ S ⊆ ⋂ s ∈ S, f '' s := by
rw [sInter_eq_biInter]
apply image_iInter₂_subset
#align set.image_sInter_subset Set.image_sInter_subset
/-! ### `restrictPreimage` -/
section
open Function
variable (s : Set β) {f : α → β} {U : ι → Set β} (hU : iUnion U = univ)
theorem injective_iff_injective_of_iUnion_eq_univ :
Injective f ↔ ∀ i, Injective ((U i).restrictPreimage f) := by
refine ⟨fun H i => (U i).restrictPreimage_injective H, fun H x y e => ?_⟩
obtain ⟨i, hi⟩ := Set.mem_iUnion.mp
(show f x ∈ Set.iUnion U by rw [hU]; trivial)
injection @H i ⟨x, hi⟩ ⟨y, show f y ∈ U i from e ▸ hi⟩ (Subtype.ext e)
#align set.injective_iff_injective_of_Union_eq_univ Set.injective_iff_injective_of_iUnion_eq_univ
theorem surjective_iff_surjective_of_iUnion_eq_univ :
Surjective f ↔ ∀ i, Surjective ((U i).restrictPreimage f) := by
refine ⟨fun H i => (U i).restrictPreimage_surjective H, fun H x => ?_⟩
obtain ⟨i, hi⟩ :=
Set.mem_iUnion.mp
(show x ∈ Set.iUnion U by rw [hU]; trivial)
exact ⟨_, congr_arg Subtype.val (H i ⟨x, hi⟩).choose_spec⟩
#align set.surjective_iff_surjective_of_Union_eq_univ Set.surjective_iff_surjective_of_iUnion_eq_univ
| Mathlib/Data/Set/Lattice.lean | 1,515 | 1,519 | theorem bijective_iff_bijective_of_iUnion_eq_univ :
Bijective f ↔ ∀ i, Bijective ((U i).restrictPreimage f) := by |
rw [Bijective, injective_iff_injective_of_iUnion_eq_univ hU,
surjective_iff_surjective_of_iUnion_eq_univ hU]
simp [Bijective, forall_and]
|
/-
Copyright (c) 2019 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Yakov Pechersky
-/
import Mathlib.Data.List.Nodup
import Mathlib.Data.List.Zip
import Mathlib.Data.Nat.Defs
import Mathlib.Data.List.Infix
#align_import data.list.rotate from "leanprover-community/mathlib"@"f694c7dead66f5d4c80f446c796a5aad14707f0e"
/-!
# List rotation
This file proves basic results about `List.rotate`, the list rotation.
## Main declarations
* `List.IsRotated l₁ l₂`: States that `l₁` is a rotated version of `l₂`.
* `List.cyclicPermutations l`: The list of all cyclic permutants of `l`, up to the length of `l`.
## Tags
rotated, rotation, permutation, cycle
-/
universe u
variable {α : Type u}
open Nat Function
namespace List
theorem rotate_mod (l : List α) (n : ℕ) : l.rotate (n % l.length) = l.rotate n := by simp [rotate]
#align list.rotate_mod List.rotate_mod
@[simp]
theorem rotate_nil (n : ℕ) : ([] : List α).rotate n = [] := by simp [rotate]
#align list.rotate_nil List.rotate_nil
@[simp]
theorem rotate_zero (l : List α) : l.rotate 0 = l := by simp [rotate]
#align list.rotate_zero List.rotate_zero
-- Porting note: removing simp, simp can prove it
theorem rotate'_nil (n : ℕ) : ([] : List α).rotate' n = [] := by cases n <;> rfl
#align list.rotate'_nil List.rotate'_nil
@[simp]
| Mathlib/Data/List/Rotate.lean | 53 | 53 | theorem rotate'_zero (l : List α) : l.rotate' 0 = l := by | cases l <;> rfl
|
/-
Copyright (c) 2018 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin, Simon Hudon
-/
import Batteries.Data.List.Lemmas
import Batteries.Tactic.Classical
import Mathlib.Tactic.TypeStar
import Mathlib.Mathport.Rename
#align_import data.list.tfae from "leanprover-community/mathlib"@"5a3e819569b0f12cbec59d740a2613018e7b8eec"
/-!
# The Following Are Equivalent
This file allows to state that all propositions in a list are equivalent. It is used by
`Mathlib.Tactic.Tfae`.
`TFAE l` means `∀ x ∈ l, ∀ y ∈ l, x ↔ y`. This is equivalent to `Pairwise (↔) l`.
-/
namespace List
/-- TFAE: The Following (propositions) Are Equivalent.
The `tfae_have` and `tfae_finish` tactics can be useful in proofs with `TFAE` goals.
-/
def TFAE (l : List Prop) : Prop :=
∀ x ∈ l, ∀ y ∈ l, x ↔ y
#align list.tfae List.TFAE
theorem tfae_nil : TFAE [] :=
forall_mem_nil _
#align list.tfae_nil List.tfae_nil
@[simp]
theorem tfae_singleton (p) : TFAE [p] := by simp [TFAE, -eq_iff_iff]
#align list.tfae_singleton List.tfae_singleton
theorem tfae_cons_of_mem {a b} {l : List Prop} (h : b ∈ l) : TFAE (a :: l) ↔ (a ↔ b) ∧ TFAE l :=
⟨fun H => ⟨H a (by simp) b (Mem.tail a h),
fun p hp q hq => H _ (Mem.tail a hp) _ (Mem.tail a hq)⟩,
by
rintro ⟨ab, H⟩ p (_ | ⟨_, hp⟩) q (_ | ⟨_, hq⟩)
· rfl
· exact ab.trans (H _ h _ hq)
· exact (ab.trans (H _ h _ hp)).symm
· exact H _ hp _ hq⟩
#align list.tfae_cons_of_mem List.tfae_cons_of_mem
theorem tfae_cons_cons {a b} {l : List Prop} : TFAE (a :: b :: l) ↔ (a ↔ b) ∧ TFAE (b :: l) :=
tfae_cons_of_mem (Mem.head _)
#align list.tfae_cons_cons List.tfae_cons_cons
@[simp]
theorem tfae_cons_self {a} {l : List Prop} : TFAE (a :: a :: l) ↔ TFAE (a :: l) := by
simp [tfae_cons_cons]
theorem tfae_of_forall (b : Prop) (l : List Prop) (h : ∀ a ∈ l, a ↔ b) : TFAE l :=
fun _a₁ h₁ _a₂ h₂ => (h _ h₁).trans (h _ h₂).symm
#align list.tfae_of_forall List.tfae_of_forall
| Mathlib/Data/List/TFAE.lean | 63 | 71 | theorem tfae_of_cycle {a b} {l : List Prop} (h_chain : List.Chain (· → ·) a (b :: l))
(h_last : getLastD l b → a) : TFAE (a :: b :: l) := by |
induction l generalizing a b with
| nil => simp_all [tfae_cons_cons, iff_def]
| cons c l IH =>
simp only [tfae_cons_cons, getLastD_cons, tfae_singleton, and_true, chain_cons, Chain.nil] at *
rcases h_chain with ⟨ab, ⟨bc, ch⟩⟩
have := IH ⟨bc, ch⟩ (ab ∘ h_last)
exact ⟨⟨ab, h_last ∘ (this.2 c (.head _) _ (getLastD_mem_cons _ _)).1 ∘ bc⟩, this⟩
|
/-
Copyright (c) 2020 Anne Baanen. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Anne Baanen
-/
import Mathlib.RingTheory.IntegrallyClosed
import Mathlib.RingTheory.Localization.NumDen
import Mathlib.RingTheory.Polynomial.ScaleRoots
#align_import ring_theory.polynomial.rational_root from "leanprover-community/mathlib"@"62c0a4ef1441edb463095ea02a06e87f3dfe135c"
/-!
# Rational root theorem and integral root theorem
This file contains the rational root theorem and integral root theorem.
The rational root theorem for a unique factorization domain `A`
with localization `S`, states that the roots of `p : A[X]` in `A`'s
field of fractions are of the form `x / y` with `x y : A`, `x ∣ p.coeff 0` and
`y ∣ p.leadingCoeff`.
The corollary is the integral root theorem `isInteger_of_is_root_of_monic`:
if `p` is monic, its roots must be integers.
Finally, we use this to show unique factorization domains are integrally closed.
## References
* https://en.wikipedia.org/wiki/Rational_root_theorem
-/
open scoped Polynomial
section ScaleRoots
variable {A K R S : Type*} [CommRing A] [Field K] [CommRing R] [CommRing S]
variable {M : Submonoid A} [Algebra A S] [IsLocalization M S] [Algebra A K] [IsFractionRing A K]
open Finsupp IsFractionRing IsLocalization Polynomial
theorem scaleRoots_aeval_eq_zero_of_aeval_mk'_eq_zero {p : A[X]} {r : A} {s : M}
(hr : aeval (mk' S r s) p = 0) : aeval (algebraMap A S r) (scaleRoots p s) = 0 := by
convert scaleRoots_eval₂_eq_zero (algebraMap A S) hr
-- Porting note: added
funext
rw [aeval_def, mk'_spec' _ r s]
#align scale_roots_aeval_eq_zero_of_aeval_mk'_eq_zero scaleRoots_aeval_eq_zero_of_aeval_mk'_eq_zero
variable [IsDomain A]
| Mathlib/RingTheory/Polynomial/RationalRoot.lean | 49 | 54 | theorem num_isRoot_scaleRoots_of_aeval_eq_zero [UniqueFactorizationMonoid A] {p : A[X]} {x : K}
(hr : aeval x p = 0) : IsRoot (scaleRoots p (den A x)) (num A x) := by |
apply isRoot_of_eval₂_map_eq_zero (IsFractionRing.injective A K)
refine scaleRoots_aeval_eq_zero_of_aeval_mk'_eq_zero ?_
rw [mk'_num_den]
exact hr
|
/-
Copyright (c) 2021 Oliver Nash. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Oliver Nash
-/
import Mathlib.Algebra.Lie.Basic
import Mathlib.RingTheory.Noetherian
#align_import algebra.lie.subalgebra from "leanprover-community/mathlib"@"6d584f1709bedbed9175bd9350df46599bdd7213"
/-!
# Lie subalgebras
This file defines Lie subalgebras of a Lie algebra and provides basic related definitions and
results.
## Main definitions
* `LieSubalgebra`
* `LieSubalgebra.incl`
* `LieSubalgebra.map`
* `LieHom.range`
* `LieEquiv.ofInjective`
* `LieEquiv.ofEq`
* `LieEquiv.ofSubalgebras`
## Tags
lie algebra, lie subalgebra
-/
universe u v w w₁ w₂
section LieSubalgebra
variable (R : Type u) (L : Type v) [CommRing R] [LieRing L] [LieAlgebra R L]
/-- A Lie subalgebra of a Lie algebra is submodule that is closed under the Lie bracket.
This is a sufficient condition for the subset itself to form a Lie algebra. -/
structure LieSubalgebra extends Submodule R L where
/-- A Lie subalgebra is closed under Lie bracket. -/
lie_mem' : ∀ {x y}, x ∈ carrier → y ∈ carrier → ⁅x, y⁆ ∈ carrier
#align lie_subalgebra LieSubalgebra
/-- The zero algebra is a subalgebra of any Lie algebra. -/
instance : Zero (LieSubalgebra R L) :=
⟨⟨0, @fun x y hx _hy ↦ by
rw [(Submodule.mem_bot R).1 hx, zero_lie]
exact Submodule.zero_mem 0⟩⟩
instance : Inhabited (LieSubalgebra R L) :=
⟨0⟩
instance : Coe (LieSubalgebra R L) (Submodule R L) :=
⟨LieSubalgebra.toSubmodule⟩
namespace LieSubalgebra
instance : SetLike (LieSubalgebra R L) L where
coe L' := L'.carrier
coe_injective' L' L'' h := by
rcases L' with ⟨⟨⟩⟩
rcases L'' with ⟨⟨⟩⟩
congr
exact SetLike.coe_injective' h
instance : AddSubgroupClass (LieSubalgebra R L) L where
add_mem := Submodule.add_mem _
zero_mem L' := L'.zero_mem'
neg_mem {L'} x hx := show -x ∈ (L' : Submodule R L) from neg_mem hx
/-- A Lie subalgebra forms a new Lie ring. -/
instance lieRing (L' : LieSubalgebra R L) : LieRing L' where
bracket x y := ⟨⁅x.val, y.val⁆, L'.lie_mem' x.property y.property⟩
lie_add := by
intros
apply SetCoe.ext
apply lie_add
add_lie := by
intros
apply SetCoe.ext
apply add_lie
lie_self := by
intros
apply SetCoe.ext
apply lie_self
leibniz_lie := by
intros
apply SetCoe.ext
apply leibniz_lie
section
variable {R₁ : Type*} [Semiring R₁]
/-- A Lie subalgebra inherits module structures from `L`. -/
instance [SMul R₁ R] [Module R₁ L] [IsScalarTower R₁ R L] (L' : LieSubalgebra R L) : Module R₁ L' :=
L'.toSubmodule.module'
instance [SMul R₁ R] [SMul R₁ᵐᵒᵖ R] [Module R₁ L] [Module R₁ᵐᵒᵖ L] [IsScalarTower R₁ R L]
[IsScalarTower R₁ᵐᵒᵖ R L] [IsCentralScalar R₁ L] (L' : LieSubalgebra R L) :
IsCentralScalar R₁ L' :=
L'.toSubmodule.isCentralScalar
instance [SMul R₁ R] [Module R₁ L] [IsScalarTower R₁ R L] (L' : LieSubalgebra R L) :
IsScalarTower R₁ R L' :=
L'.toSubmodule.isScalarTower
instance (L' : LieSubalgebra R L) [IsNoetherian R L] : IsNoetherian R L' :=
isNoetherian_submodule' _
end
/-- A Lie subalgebra forms a new Lie algebra. -/
instance lieAlgebra (L' : LieSubalgebra R L) : LieAlgebra R L' where
lie_smul := by
{ intros
apply SetCoe.ext
apply lie_smul }
variable {R L}
variable (L' : LieSubalgebra R L)
@[simp]
protected theorem zero_mem : (0 : L) ∈ L' :=
zero_mem L'
#align lie_subalgebra.zero_mem LieSubalgebra.zero_mem
protected theorem add_mem {x y : L} : x ∈ L' → y ∈ L' → (x + y : L) ∈ L' :=
add_mem
#align lie_subalgebra.add_mem LieSubalgebra.add_mem
protected theorem sub_mem {x y : L} : x ∈ L' → y ∈ L' → (x - y : L) ∈ L' :=
sub_mem
#align lie_subalgebra.sub_mem LieSubalgebra.sub_mem
theorem smul_mem (t : R) {x : L} (h : x ∈ L') : t • x ∈ L' :=
(L' : Submodule R L).smul_mem t h
#align lie_subalgebra.smul_mem LieSubalgebra.smul_mem
theorem lie_mem {x y : L} (hx : x ∈ L') (hy : y ∈ L') : (⁅x, y⁆ : L) ∈ L' :=
L'.lie_mem' hx hy
#align lie_subalgebra.lie_mem LieSubalgebra.lie_mem
theorem mem_carrier {x : L} : x ∈ L'.carrier ↔ x ∈ (L' : Set L) :=
Iff.rfl
#align lie_subalgebra.mem_carrier LieSubalgebra.mem_carrier
@[simp]
theorem mem_mk_iff (S : Set L) (h₁ h₂ h₃ h₄) {x : L} :
x ∈ (⟨⟨⟨⟨S, h₁⟩, h₂⟩, h₃⟩, h₄⟩ : LieSubalgebra R L) ↔ x ∈ S :=
Iff.rfl
#align lie_subalgebra.mem_mk_iff LieSubalgebra.mem_mk_iff
@[simp]
theorem mem_coe_submodule {x : L} : x ∈ (L' : Submodule R L) ↔ x ∈ L' :=
Iff.rfl
#align lie_subalgebra.mem_coe_submodule LieSubalgebra.mem_coe_submodule
theorem mem_coe {x : L} : x ∈ (L' : Set L) ↔ x ∈ L' :=
Iff.rfl
#align lie_subalgebra.mem_coe LieSubalgebra.mem_coe
@[simp, norm_cast]
theorem coe_bracket (x y : L') : (↑⁅x, y⁆ : L) = ⁅(↑x : L), ↑y⁆ :=
rfl
#align lie_subalgebra.coe_bracket LieSubalgebra.coe_bracket
theorem ext_iff (x y : L') : x = y ↔ (x : L) = y :=
Subtype.ext_iff
#align lie_subalgebra.ext_iff LieSubalgebra.ext_iff
theorem coe_zero_iff_zero (x : L') : (x : L) = 0 ↔ x = 0 :=
(ext_iff L' x 0).symm
#align lie_subalgebra.coe_zero_iff_zero LieSubalgebra.coe_zero_iff_zero
@[ext]
theorem ext (L₁' L₂' : LieSubalgebra R L) (h : ∀ x, x ∈ L₁' ↔ x ∈ L₂') : L₁' = L₂' :=
SetLike.ext h
#align lie_subalgebra.ext LieSubalgebra.ext
theorem ext_iff' (L₁' L₂' : LieSubalgebra R L) : L₁' = L₂' ↔ ∀ x, x ∈ L₁' ↔ x ∈ L₂' :=
SetLike.ext_iff
#align lie_subalgebra.ext_iff' LieSubalgebra.ext_iff'
@[simp]
theorem mk_coe (S : Set L) (h₁ h₂ h₃ h₄) :
((⟨⟨⟨⟨S, h₁⟩, h₂⟩, h₃⟩, h₄⟩ : LieSubalgebra R L) : Set L) = S :=
rfl
#align lie_subalgebra.mk_coe LieSubalgebra.mk_coe
theorem coe_to_submodule_mk (p : Submodule R L) (h) :
(({ p with lie_mem' := h } : LieSubalgebra R L) : Submodule R L) = p := by
cases p
rfl
#align lie_subalgebra.coe_to_submodule_mk LieSubalgebra.coe_to_submodule_mk
theorem coe_injective : Function.Injective ((↑) : LieSubalgebra R L → Set L) :=
SetLike.coe_injective
#align lie_subalgebra.coe_injective LieSubalgebra.coe_injective
@[norm_cast]
theorem coe_set_eq (L₁' L₂' : LieSubalgebra R L) : (L₁' : Set L) = L₂' ↔ L₁' = L₂' :=
SetLike.coe_set_eq
#align lie_subalgebra.coe_set_eq LieSubalgebra.coe_set_eq
theorem to_submodule_injective : Function.Injective ((↑) : LieSubalgebra R L → Submodule R L) :=
fun L₁' L₂' h ↦ by
rw [SetLike.ext'_iff] at h
rw [← coe_set_eq]
exact h
#align lie_subalgebra.to_submodule_injective LieSubalgebra.to_submodule_injective
@[simp]
theorem coe_to_submodule_eq_iff (L₁' L₂' : LieSubalgebra R L) :
(L₁' : Submodule R L) = (L₂' : Submodule R L) ↔ L₁' = L₂' :=
to_submodule_injective.eq_iff
#align lie_subalgebra.coe_to_submodule_eq_iff LieSubalgebra.coe_to_submodule_eq_iff
theorem coe_to_submodule : ((L' : Submodule R L) : Set L) = L' :=
rfl
#align lie_subalgebra.coe_to_submodule LieSubalgebra.coe_to_submodule
section LieModule
variable {M : Type w} [AddCommGroup M] [LieRingModule L M]
variable {N : Type w₁} [AddCommGroup N] [LieRingModule L N] [Module R N] [LieModule R L N]
/-- Given a Lie algebra `L` containing a Lie subalgebra `L' ⊆ L`, together with a Lie ring module
`M` of `L`, we may regard `M` as a Lie ring module of `L'` by restriction. -/
instance lieRingModule : LieRingModule L' M where
bracket x m := ⁅(x : L), m⁆
add_lie x y m := add_lie (x : L) y m
lie_add x y m := lie_add (x : L) y m
leibniz_lie x y m := leibniz_lie (x : L) y m
@[simp]
theorem coe_bracket_of_module (x : L') (m : M) : ⁅x, m⁆ = ⁅(x : L), m⁆ :=
rfl
#align lie_subalgebra.coe_bracket_of_module LieSubalgebra.coe_bracket_of_module
variable [Module R M] [LieModule R L M]
/-- Given a Lie algebra `L` containing a Lie subalgebra `L' ⊆ L`, together with a Lie module `M` of
`L`, we may regard `M` as a Lie module of `L'` by restriction. -/
instance lieModule : LieModule R L' M where
smul_lie t x m := by simp only [coe_bracket_of_module, smul_lie, Submodule.coe_smul_of_tower]
lie_smul t x m := by simp only [coe_bracket_of_module, lie_smul]
/-- An `L`-equivariant map of Lie modules `M → N` is `L'`-equivariant for any Lie subalgebra
`L' ⊆ L`. -/
def _root_.LieModuleHom.restrictLie (f : M →ₗ⁅R,L⁆ N) (L' : LieSubalgebra R L) : M →ₗ⁅R,L'⁆ N :=
{ (f : M →ₗ[R] N) with map_lie' := @fun x m ↦ f.map_lie (↑x) m }
#align lie_module_hom.restrict_lie LieModuleHom.restrictLie
@[simp]
theorem _root_.LieModuleHom.coe_restrictLie (f : M →ₗ⁅R,L⁆ N) : ⇑(f.restrictLie L') = f :=
rfl
#align lie_module_hom.coe_restrict_lie LieModuleHom.coe_restrictLie
end LieModule
/-- The embedding of a Lie subalgebra into the ambient space as a morphism of Lie algebras. -/
def incl : L' →ₗ⁅R⁆ L :=
{ (L' : Submodule R L).subtype with
map_lie' := rfl }
#align lie_subalgebra.incl LieSubalgebra.incl
@[simp]
theorem coe_incl : ⇑L'.incl = ((↑) : L' → L) :=
rfl
#align lie_subalgebra.coe_incl LieSubalgebra.coe_incl
/-- The embedding of a Lie subalgebra into the ambient space as a morphism of Lie modules. -/
def incl' : L' →ₗ⁅R,L'⁆ L :=
{ (L' : Submodule R L).subtype with
map_lie' := rfl }
#align lie_subalgebra.incl' LieSubalgebra.incl'
@[simp]
theorem coe_incl' : ⇑L'.incl' = ((↑) : L' → L) :=
rfl
#align lie_subalgebra.coe_incl' LieSubalgebra.coe_incl'
end LieSubalgebra
variable {R L}
variable {L₂ : Type w} [LieRing L₂] [LieAlgebra R L₂]
variable (f : L →ₗ⁅R⁆ L₂)
namespace LieHom
/-- The range of a morphism of Lie algebras is a Lie subalgebra. -/
def range : LieSubalgebra R L₂ :=
{ LinearMap.range (f : L →ₗ[R] L₂) with
lie_mem' := by
rintro - - ⟨x, rfl⟩ ⟨y, rfl⟩
exact ⟨⁅x, y⁆, f.map_lie x y⟩ }
#align lie_hom.range LieHom.range
@[simp]
theorem range_coe : (f.range : Set L₂) = Set.range f :=
LinearMap.range_coe (f : L →ₗ[R] L₂)
#align lie_hom.range_coe LieHom.range_coe
@[simp]
theorem mem_range (x : L₂) : x ∈ f.range ↔ ∃ y : L, f y = x :=
LinearMap.mem_range
#align lie_hom.mem_range LieHom.mem_range
theorem mem_range_self (x : L) : f x ∈ f.range :=
LinearMap.mem_range_self (f : L →ₗ[R] L₂) x
#align lie_hom.mem_range_self LieHom.mem_range_self
/-- We can restrict a morphism to a (surjective) map to its range. -/
def rangeRestrict : L →ₗ⁅R⁆ f.range :=
{ (f : L →ₗ[R] L₂).rangeRestrict with
map_lie' := @fun x y ↦ by
apply Subtype.ext
exact f.map_lie x y }
#align lie_hom.range_restrict LieHom.rangeRestrict
@[simp]
theorem rangeRestrict_apply (x : L) : f.rangeRestrict x = ⟨f x, f.mem_range_self x⟩ :=
rfl
#align lie_hom.range_restrict_apply LieHom.rangeRestrict_apply
theorem surjective_rangeRestrict : Function.Surjective f.rangeRestrict := by
rintro ⟨y, hy⟩
erw [mem_range] at hy; obtain ⟨x, rfl⟩ := hy
use x
simp only [Subtype.mk_eq_mk, rangeRestrict_apply]
#align lie_hom.surjective_range_restrict LieHom.surjective_rangeRestrict
/-- A Lie algebra is equivalent to its range under an injective Lie algebra morphism. -/
noncomputable def equivRangeOfInjective (h : Function.Injective f) : L ≃ₗ⁅R⁆ f.range :=
LieEquiv.ofBijective f.rangeRestrict
⟨fun x y hxy ↦ by
simp only [Subtype.mk_eq_mk, rangeRestrict_apply] at hxy
exact h hxy, f.surjective_rangeRestrict⟩
#align lie_hom.equiv_range_of_injective LieHom.equivRangeOfInjective
@[simp]
theorem equivRangeOfInjective_apply (h : Function.Injective f) (x : L) :
f.equivRangeOfInjective h x = ⟨f x, mem_range_self f x⟩ :=
rfl
#align lie_hom.equiv_range_of_injective_apply LieHom.equivRangeOfInjective_apply
end LieHom
theorem Submodule.exists_lieSubalgebra_coe_eq_iff (p : Submodule R L) :
(∃ K : LieSubalgebra R L, ↑K = p) ↔ ∀ x y : L, x ∈ p → y ∈ p → ⁅x, y⁆ ∈ p := by
constructor
· rintro ⟨K, rfl⟩ _ _
exact K.lie_mem'
· intro h
use { p with lie_mem' := h _ _ }
#align submodule.exists_lie_subalgebra_coe_eq_iff Submodule.exists_lieSubalgebra_coe_eq_iff
namespace LieSubalgebra
variable (K K' : LieSubalgebra R L) (K₂ : LieSubalgebra R L₂)
@[simp]
theorem incl_range : K.incl.range = K := by
rw [← coe_to_submodule_eq_iff]
exact (K : Submodule R L).range_subtype
#align lie_subalgebra.incl_range LieSubalgebra.incl_range
/-- The image of a Lie subalgebra under a Lie algebra morphism is a Lie subalgebra of the
codomain. -/
def map : LieSubalgebra R L₂ :=
{ (K : Submodule R L).map (f : L →ₗ[R] L₂) with
lie_mem' := @fun x y hx hy ↦ by
erw [Submodule.mem_map] at hx
rcases hx with ⟨x', hx', hx⟩
rw [← hx]
erw [Submodule.mem_map] at hy
rcases hy with ⟨y', hy', hy⟩
rw [← hy]
erw [Submodule.mem_map]
exact ⟨⁅x', y'⁆, K.lie_mem hx' hy', f.map_lie x' y'⟩ }
#align lie_subalgebra.map LieSubalgebra.map
@[simp]
theorem mem_map (x : L₂) : x ∈ K.map f ↔ ∃ y : L, y ∈ K ∧ f y = x :=
Submodule.mem_map
#align lie_subalgebra.mem_map LieSubalgebra.mem_map
-- TODO Rename and state for homs instead of equivs.
theorem mem_map_submodule (e : L ≃ₗ⁅R⁆ L₂) (x : L₂) :
x ∈ K.map (e : L →ₗ⁅R⁆ L₂) ↔ x ∈ (K : Submodule R L).map (e : L →ₗ[R] L₂) :=
Iff.rfl
#align lie_subalgebra.mem_map_submodule LieSubalgebra.mem_map_submodule
/-- The preimage of a Lie subalgebra under a Lie algebra morphism is a Lie subalgebra of the
domain. -/
def comap : LieSubalgebra R L :=
{ (K₂ : Submodule R L₂).comap (f : L →ₗ[R] L₂) with
lie_mem' := @fun x y hx hy ↦ by
suffices ⁅f x, f y⁆ ∈ K₂ by simp [this]
exact K₂.lie_mem hx hy }
#align lie_subalgebra.comap LieSubalgebra.comap
section LatticeStructure
open Set
instance : PartialOrder (LieSubalgebra R L) :=
{ PartialOrder.lift ((↑) : LieSubalgebra R L → Set L) coe_injective with
le := fun N N' ↦ ∀ ⦃x⦄, x ∈ N → x ∈ N' }
theorem le_def : K ≤ K' ↔ (K : Set L) ⊆ K' :=
Iff.rfl
#align lie_subalgebra.le_def LieSubalgebra.le_def
@[simp]
theorem coe_submodule_le_coe_submodule : (K : Submodule R L) ≤ K' ↔ K ≤ K' :=
Iff.rfl
#align lie_subalgebra.coe_submodule_le_coe_submodule LieSubalgebra.coe_submodule_le_coe_submodule
instance : Bot (LieSubalgebra R L) :=
⟨0⟩
@[simp]
theorem bot_coe : ((⊥ : LieSubalgebra R L) : Set L) = {0} :=
rfl
#align lie_subalgebra.bot_coe LieSubalgebra.bot_coe
@[simp]
theorem bot_coe_submodule : ((⊥ : LieSubalgebra R L) : Submodule R L) = ⊥ :=
rfl
#align lie_subalgebra.bot_coe_submodule LieSubalgebra.bot_coe_submodule
@[simp]
theorem mem_bot (x : L) : x ∈ (⊥ : LieSubalgebra R L) ↔ x = 0 :=
mem_singleton_iff
#align lie_subalgebra.mem_bot LieSubalgebra.mem_bot
instance : Top (LieSubalgebra R L) :=
⟨{ (⊤ : Submodule R L) with lie_mem' := @fun x y _ _ ↦ mem_univ ⁅x, y⁆ }⟩
@[simp]
theorem top_coe : ((⊤ : LieSubalgebra R L) : Set L) = univ :=
rfl
#align lie_subalgebra.top_coe LieSubalgebra.top_coe
@[simp]
theorem top_coe_submodule : ((⊤ : LieSubalgebra R L) : Submodule R L) = ⊤ :=
rfl
#align lie_subalgebra.top_coe_submodule LieSubalgebra.top_coe_submodule
@[simp]
theorem mem_top (x : L) : x ∈ (⊤ : LieSubalgebra R L) :=
mem_univ x
#align lie_subalgebra.mem_top LieSubalgebra.mem_top
theorem _root_.LieHom.range_eq_map : f.range = map f ⊤ := by
ext
simp
#align lie_hom.range_eq_map LieHom.range_eq_map
instance : Inf (LieSubalgebra R L) :=
⟨fun K K' ↦
{ (K ⊓ K' : Submodule R L) with
lie_mem' := fun hx hy ↦ mem_inter (K.lie_mem hx.1 hy.1) (K'.lie_mem hx.2 hy.2) }⟩
instance : InfSet (LieSubalgebra R L) :=
⟨fun S ↦
{ sInf {(s : Submodule R L) | s ∈ S} with
lie_mem' := @fun x y hx hy ↦ by
simp only [Submodule.mem_carrier, mem_iInter, Submodule.sInf_coe, mem_setOf_eq,
forall_apply_eq_imp_iff₂, exists_imp, and_imp] at hx hy ⊢
intro K hK
exact K.lie_mem (hx K hK) (hy K hK) }⟩
@[simp]
theorem inf_coe : (↑(K ⊓ K') : Set L) = (K : Set L) ∩ (K' : Set L) :=
rfl
#align lie_subalgebra.inf_coe LieSubalgebra.inf_coe
@[simp]
theorem sInf_coe_to_submodule (S : Set (LieSubalgebra R L)) :
(↑(sInf S) : Submodule R L) = sInf {(s : Submodule R L) | s ∈ S} :=
rfl
#align lie_subalgebra.Inf_coe_to_submodule LieSubalgebra.sInf_coe_to_submodule
@[simp]
theorem sInf_coe (S : Set (LieSubalgebra R L)) : (↑(sInf S) : Set L) = ⋂ s ∈ S, (s : Set L) := by
rw [← coe_to_submodule, sInf_coe_to_submodule, Submodule.sInf_coe]
ext x
simp
#align lie_subalgebra.Inf_coe LieSubalgebra.sInf_coe
theorem sInf_glb (S : Set (LieSubalgebra R L)) : IsGLB S (sInf S) := by
have h : ∀ K K' : LieSubalgebra R L, (K : Set L) ≤ K' ↔ K ≤ K' := by
intros
exact Iff.rfl
apply IsGLB.of_image @h
simp only [sInf_coe]
exact isGLB_biInf
#align lie_subalgebra.Inf_glb LieSubalgebra.sInf_glb
/-- The set of Lie subalgebras of a Lie algebra form a complete lattice.
We provide explicit values for the fields `bot`, `top`, `inf` to get more convenient definitions
than we would otherwise obtain from `completeLatticeOfInf`. -/
instance completeLattice : CompleteLattice (LieSubalgebra R L) :=
{ completeLatticeOfInf _ sInf_glb with
bot := ⊥
bot_le := fun N _ h ↦ by
rw [mem_bot] at h
rw [h]
exact N.zero_mem'
top := ⊤
le_top := fun _ _ _ ↦ trivial
inf := (· ⊓ ·)
le_inf := fun N₁ N₂ N₃ h₁₂ h₁₃ m hm ↦ ⟨h₁₂ hm, h₁₃ hm⟩
inf_le_left := fun _ _ _ ↦ And.left
inf_le_right := fun _ _ _ ↦ And.right }
instance : Add (LieSubalgebra R L) where add := Sup.sup
instance : Zero (LieSubalgebra R L) where zero := ⊥
instance addCommMonoid : AddCommMonoid (LieSubalgebra R L) where
add_assoc := sup_assoc
zero_add := bot_sup_eq
add_zero := sup_bot_eq
add_comm := sup_comm
nsmul := nsmulRec
instance : CanonicallyOrderedAddCommMonoid (LieSubalgebra R L) :=
{ LieSubalgebra.addCommMonoid,
LieSubalgebra.completeLattice with
add_le_add_left := fun _a _b ↦ sup_le_sup_left
exists_add_of_le := @fun _a b h ↦ ⟨b, (sup_eq_right.2 h).symm⟩
le_self_add := fun _a _b ↦ le_sup_left }
@[simp]
theorem add_eq_sup : K + K' = K ⊔ K' :=
rfl
#align lie_subalgebra.add_eq_sup LieSubalgebra.add_eq_sup
@[simp]
theorem inf_coe_to_submodule :
(↑(K ⊓ K') : Submodule R L) = (K : Submodule R L) ⊓ (K' : Submodule R L) :=
rfl
#align lie_subalgebra.inf_coe_to_submodule LieSubalgebra.inf_coe_to_submodule
@[simp]
theorem mem_inf (x : L) : x ∈ K ⊓ K' ↔ x ∈ K ∧ x ∈ K' := by
rw [← mem_coe_submodule, ← mem_coe_submodule, ← mem_coe_submodule, inf_coe_to_submodule,
Submodule.mem_inf]
#align lie_subalgebra.mem_inf LieSubalgebra.mem_inf
theorem eq_bot_iff : K = ⊥ ↔ ∀ x : L, x ∈ K → x = 0 := by
rw [_root_.eq_bot_iff]
exact Iff.rfl
#align lie_subalgebra.eq_bot_iff LieSubalgebra.eq_bot_iff
instance subsingleton_of_bot : Subsingleton (LieSubalgebra R (⊥ : LieSubalgebra R L)) := by
apply subsingleton_of_bot_eq_top
ext ⟨x, hx⟩; change x ∈ ⊥ at hx; rw [LieSubalgebra.mem_bot] at hx; subst hx
simp only [true_iff_iff, eq_self_iff_true, Submodule.mk_eq_zero, mem_bot, mem_top]
#align lie_subalgebra.subsingleton_of_bot LieSubalgebra.subsingleton_of_bot
theorem subsingleton_bot : Subsingleton (⊥ : LieSubalgebra R L) :=
show Subsingleton ((⊥ : LieSubalgebra R L) : Set L) by simp
#align lie_subalgebra.subsingleton_bot LieSubalgebra.subsingleton_bot
variable (R L)
theorem wellFounded_of_noetherian [IsNoetherian R L] :
WellFounded ((· > ·) : LieSubalgebra R L → LieSubalgebra R L → Prop) :=
let f :
((· > ·) : LieSubalgebra R L → LieSubalgebra R L → Prop) →r
((· > ·) : Submodule R L → Submodule R L → Prop) :=
{ toFun := (↑)
map_rel' := @fun _ _ h ↦ h }
RelHomClass.wellFounded f (isNoetherian_iff_wellFounded.mp inferInstance)
#align lie_subalgebra.well_founded_of_noetherian LieSubalgebra.wellFounded_of_noetherian
variable {R L K K' f}
section NestedSubalgebras
variable (h : K ≤ K')
/-- Given two nested Lie subalgebras `K ⊆ K'`, the inclusion `K ↪ K'` is a morphism of Lie
algebras. -/
def inclusion : K →ₗ⁅R⁆ K' :=
{ Submodule.inclusion h with map_lie' := @fun _ _ ↦ rfl }
#align lie_subalgebra.hom_of_le LieSubalgebra.inclusion
@[simp]
theorem coe_inclusion (x : K) : (inclusion h x : L) = x :=
rfl
#align lie_subalgebra.coe_hom_of_le LieSubalgebra.coe_inclusion
theorem inclusion_apply (x : K) : inclusion h x = ⟨x.1, h x.2⟩ :=
rfl
#align lie_subalgebra.hom_of_le_apply LieSubalgebra.inclusion_apply
theorem inclusion_injective : Function.Injective (inclusion h) := fun x y ↦ by
simp only [inclusion_apply, imp_self, Subtype.mk_eq_mk, SetLike.coe_eq_coe]
#align lie_subalgebra.hom_of_le_injective LieSubalgebra.inclusion_injective
/-- Given two nested Lie subalgebras `K ⊆ K'`, we can view `K` as a Lie subalgebra of `K'`,
regarded as Lie algebra in its own right. -/
def ofLe : LieSubalgebra R K' :=
(inclusion h).range
#align lie_subalgebra.of_le LieSubalgebra.ofLe
@[simp]
theorem mem_ofLe (x : K') : x ∈ ofLe h ↔ (x : L) ∈ K := by
simp only [ofLe, inclusion_apply, LieHom.mem_range]
constructor
· rintro ⟨y, rfl⟩
exact y.property
· intro h
use ⟨(x : L), h⟩
#align lie_subalgebra.mem_of_le LieSubalgebra.mem_ofLe
theorem ofLe_eq_comap_incl : ofLe h = K.comap K'.incl := by
ext
rw [mem_ofLe]
rfl
#align lie_subalgebra.of_le_eq_comap_incl LieSubalgebra.ofLe_eq_comap_incl
@[simp]
theorem coe_ofLe : (ofLe h : Submodule R K') = LinearMap.range (Submodule.inclusion h) :=
rfl
#align lie_subalgebra.coe_of_le LieSubalgebra.coe_ofLe
/-- Given nested Lie subalgebras `K ⊆ K'`, there is a natural equivalence from `K` to its image in
`K'`. -/
noncomputable def equivOfLe : K ≃ₗ⁅R⁆ ofLe h :=
(inclusion h).equivRangeOfInjective (inclusion_injective h)
#align lie_subalgebra.equiv_of_le LieSubalgebra.equivOfLe
@[simp]
theorem equivOfLe_apply (x : K) : equivOfLe h x = ⟨inclusion h x, (inclusion h).mem_range_self x⟩ :=
rfl
#align lie_subalgebra.equiv_of_le_apply LieSubalgebra.equivOfLe_apply
end NestedSubalgebras
theorem map_le_iff_le_comap {K : LieSubalgebra R L} {K' : LieSubalgebra R L₂} :
map f K ≤ K' ↔ K ≤ comap f K' :=
Set.image_subset_iff
#align lie_subalgebra.map_le_iff_le_comap LieSubalgebra.map_le_iff_le_comap
theorem gc_map_comap : GaloisConnection (map f) (comap f) := fun _ _ ↦ map_le_iff_le_comap
#align lie_subalgebra.gc_map_comap LieSubalgebra.gc_map_comap
end LatticeStructure
section LieSpan
variable (R L) (s : Set L)
/-- The Lie subalgebra of a Lie algebra `L` generated by a subset `s ⊆ L`. -/
def lieSpan : LieSubalgebra R L :=
sInf { N | s ⊆ N }
#align lie_subalgebra.lie_span LieSubalgebra.lieSpan
variable {R L s}
theorem mem_lieSpan {x : L} : x ∈ lieSpan R L s ↔ ∀ K : LieSubalgebra R L, s ⊆ K → x ∈ K := by
change x ∈ (lieSpan R L s : Set L) ↔ _
erw [sInf_coe]
exact Set.mem_iInter₂
#align lie_subalgebra.mem_lie_span LieSubalgebra.mem_lieSpan
theorem subset_lieSpan : s ⊆ lieSpan R L s := by
intro m hm
erw [mem_lieSpan]
intro K hK
exact hK hm
#align lie_subalgebra.subset_lie_span LieSubalgebra.subset_lieSpan
theorem submodule_span_le_lieSpan : Submodule.span R s ≤ lieSpan R L s := by
rw [Submodule.span_le]
apply subset_lieSpan
#align lie_subalgebra.submodule_span_le_lie_span LieSubalgebra.submodule_span_le_lieSpan
| Mathlib/Algebra/Lie/Subalgebra.lean | 689 | 694 | theorem lieSpan_le {K} : lieSpan R L s ≤ K ↔ s ⊆ K := by |
constructor
· exact Set.Subset.trans subset_lieSpan
· intro hs m hm
rw [mem_lieSpan] at hm
exact hm _ hs
|
/-
Copyright (c) 2021 Bhavik Mehta. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies, Bhavik Mehta
-/
import Mathlib.Combinatorics.SetFamily.Shadow
#align_import combinatorics.set_family.compression.uv from "leanprover-community/mathlib"@"6f8ab7de1c4b78a68ab8cf7dd83d549eb78a68a1"
/-!
# UV-compressions
This file defines UV-compression. It is an operation on a set family that reduces its shadow.
UV-compressing `a : α` along `u v : α` means replacing `a` by `(a ⊔ u) \ v` if `a` and `u` are
disjoint and `v ≤ a`. In some sense, it's moving `a` from `v` to `u`.
UV-compressions are immensely useful to prove the Kruskal-Katona theorem. The idea is that
compressing a set family might decrease the size of its shadow, so iterated compressions hopefully
minimise the shadow.
## Main declarations
* `UV.compress`: `compress u v a` is `a` compressed along `u` and `v`.
* `UV.compression`: `compression u v s` is the compression of the set family `s` along `u` and `v`.
It is the compressions of the elements of `s` whose compression is not already in `s` along with
the element whose compression is already in `s`. This way of splitting into what moves and what
does not ensures the compression doesn't squash the set family, which is proved by
`UV.card_compression`.
* `UV.card_shadow_compression_le`: Compressing reduces the size of the shadow. This is a key fact in
the proof of Kruskal-Katona.
## Notation
`𝓒` (typed with `\MCC`) is notation for `UV.compression` in locale `FinsetFamily`.
## Notes
Even though our emphasis is on `Finset α`, we define UV-compressions more generally in a generalized
boolean algebra, so that one can use it for `Set α`.
## References
* https://github.com/b-mehta/maths-notes/blob/master/iii/mich/combinatorics.pdf
## Tags
compression, UV-compression, shadow
-/
open Finset
variable {α : Type*}
/-- UV-compression is injective on the elements it moves. See `UV.compress`. -/
theorem sup_sdiff_injOn [GeneralizedBooleanAlgebra α] (u v : α) :
{ x | Disjoint u x ∧ v ≤ x }.InjOn fun x => (x ⊔ u) \ v := by
rintro a ha b hb hab
have h : ((a ⊔ u) \ v) \ u ⊔ v = ((b ⊔ u) \ v) \ u ⊔ v := by
dsimp at hab
rw [hab]
rwa [sdiff_sdiff_comm, ha.1.symm.sup_sdiff_cancel_right, sdiff_sdiff_comm,
hb.1.symm.sup_sdiff_cancel_right, sdiff_sup_cancel ha.2, sdiff_sup_cancel hb.2] at h
#align sup_sdiff_inj_on sup_sdiff_injOn
-- The namespace is here to distinguish from other compressions.
namespace UV
/-! ### UV-compression in generalized boolean algebras -/
section GeneralizedBooleanAlgebra
variable [GeneralizedBooleanAlgebra α] [DecidableRel (@Disjoint α _ _)]
[DecidableRel ((· ≤ ·) : α → α → Prop)] {s : Finset α} {u v a b : α}
/-- UV-compressing `a` means removing `v` from it and adding `u` if `a` and `u` are disjoint and
`v ≤ a` (it replaces the `v` part of `a` by the `u` part). Else, UV-compressing `a` doesn't do
anything. This is most useful when `u` and `v` are disjoint finsets of the same size. -/
def compress (u v a : α) : α :=
if Disjoint u a ∧ v ≤ a then (a ⊔ u) \ v else a
#align uv.compress UV.compress
theorem compress_of_disjoint_of_le (hua : Disjoint u a) (hva : v ≤ a) :
compress u v a = (a ⊔ u) \ v :=
if_pos ⟨hua, hva⟩
#align uv.compress_of_disjoint_of_le UV.compress_of_disjoint_of_le
theorem compress_of_disjoint_of_le' (hva : Disjoint v a) (hua : u ≤ a) :
compress u v ((a ⊔ v) \ u) = a := by
rw [compress_of_disjoint_of_le disjoint_sdiff_self_right
(le_sdiff.2 ⟨(le_sup_right : v ≤ a ⊔ v), hva.mono_right hua⟩),
sdiff_sup_cancel (le_sup_of_le_left hua), hva.symm.sup_sdiff_cancel_right]
#align uv.compress_of_disjoint_of_le' UV.compress_of_disjoint_of_le'
@[simp]
theorem compress_self (u a : α) : compress u u a = a := by
unfold compress
split_ifs with h
· exact h.1.symm.sup_sdiff_cancel_right
· rfl
#align uv.compress_self UV.compress_self
/-- An element can be compressed to any other element by removing/adding the differences. -/
@[simp]
theorem compress_sdiff_sdiff (a b : α) : compress (a \ b) (b \ a) b = a := by
refine (compress_of_disjoint_of_le disjoint_sdiff_self_left sdiff_le).trans ?_
rw [sup_sdiff_self_right, sup_sdiff, disjoint_sdiff_self_right.sdiff_eq_left, sup_eq_right]
exact sdiff_sdiff_le
#align uv.compress_sdiff_sdiff UV.compress_sdiff_sdiff
/-- Compressing an element is idempotent. -/
@[simp]
theorem compress_idem (u v a : α) : compress u v (compress u v a) = compress u v a := by
unfold compress
split_ifs with h h'
· rw [le_sdiff_iff.1 h'.2, sdiff_bot, sdiff_bot, sup_assoc, sup_idem]
· rfl
· rfl
#align uv.compress_idem UV.compress_idem
variable [DecidableEq α]
/-- To UV-compress a set family, we compress each of its elements, except that we don't want to
reduce the cardinality, so we keep all elements whose compression is already present. -/
def compression (u v : α) (s : Finset α) :=
(s.filter (compress u v · ∈ s)) ∪ (s.image <| compress u v).filter (· ∉ s)
#align uv.compression UV.compression
@[inherit_doc]
scoped[FinsetFamily] notation "𝓒 " => UV.compression
open scoped FinsetFamily
/-- `IsCompressed u v s` expresses that `s` is UV-compressed. -/
def IsCompressed (u v : α) (s : Finset α) :=
𝓒 u v s = s
#align uv.is_compressed UV.IsCompressed
/-- UV-compression is injective on the sets that are not UV-compressed. -/
theorem compress_injOn : Set.InjOn (compress u v) ↑(s.filter (compress u v · ∉ s)) := by
intro a ha b hb hab
rw [mem_coe, mem_filter] at ha hb
rw [compress] at ha hab
split_ifs at ha hab with has
· rw [compress] at hb hab
split_ifs at hb hab with hbs
· exact sup_sdiff_injOn u v has hbs hab
· exact (hb.2 hb.1).elim
· exact (ha.2 ha.1).elim
#align uv.compress_inj_on UV.compress_injOn
/-- `a` is in the UV-compressed family iff it's in the original and its compression is in the
original, or it's not in the original but it's the compression of something in the original. -/
theorem mem_compression :
a ∈ 𝓒 u v s ↔ a ∈ s ∧ compress u v a ∈ s ∨ a ∉ s ∧ ∃ b ∈ s, compress u v b = a := by
simp_rw [compression, mem_union, mem_filter, mem_image, and_comm]
#align uv.mem_compression UV.mem_compression
protected theorem IsCompressed.eq (h : IsCompressed u v s) : 𝓒 u v s = s := h
#align uv.is_compressed.eq UV.IsCompressed.eq
@[simp]
| Mathlib/Combinatorics/SetFamily/Compression/UV.lean | 165 | 173 | theorem compression_self (u : α) (s : Finset α) : 𝓒 u u s = s := by |
unfold compression
convert union_empty s
· ext a
rw [mem_filter, compress_self, and_self_iff]
· refine eq_empty_of_forall_not_mem fun a ha ↦ ?_
simp_rw [mem_filter, mem_image, compress_self] at ha
obtain ⟨⟨b, hb, rfl⟩, hb'⟩ := ha
exact hb' hb
|
/-
Copyright (c) 2017 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Y. Lewis, Keeley Hoek
-/
import Mathlib.Algebra.NeZero
import Mathlib.Data.Nat.Defs
import Mathlib.Logic.Embedding.Basic
import Mathlib.Logic.Equiv.Set
import Mathlib.Tactic.Common
#align_import data.fin.basic from "leanprover-community/mathlib"@"3a2b5524a138b5d0b818b858b516d4ac8a484b03"
/-!
# The finite type with `n` elements
`Fin n` is the type whose elements are natural numbers smaller than `n`.
This file expands on the development in the core library.
## Main definitions
### Induction principles
* `finZeroElim` : Elimination principle for the empty set `Fin 0`, generalizes `Fin.elim0`.
* `Fin.succRec` : Define `C n i` by induction on `i : Fin n` interpreted
as `(0 : Fin (n - i)).succ.succ…`. This function has two arguments: `H0 n` defines
`0`-th element `C (n+1) 0` of an `(n+1)`-tuple, and `Hs n i` defines `(i+1)`-st element
of `(n+1)`-tuple based on `n`, `i`, and `i`-th element of `n`-tuple.
* `Fin.succRecOn` : same as `Fin.succRec` but `i : Fin n` is the first argument;
* `Fin.induction` : Define `C i` by induction on `i : Fin (n + 1)`, separating into the
`Nat`-like base cases of `C 0` and `C (i.succ)`.
* `Fin.inductionOn` : same as `Fin.induction` but with `i : Fin (n + 1)` as the first argument.
* `Fin.cases` : define `f : Π i : Fin n.succ, C i` by separately handling the cases `i = 0` and
`i = Fin.succ j`, `j : Fin n`, defined using `Fin.induction`.
* `Fin.reverseInduction`: reverse induction on `i : Fin (n + 1)`; given `C (Fin.last n)` and
`∀ i : Fin n, C (Fin.succ i) → C (Fin.castSucc i)`, constructs all values `C i` by going down;
* `Fin.lastCases`: define `f : Π i, Fin (n + 1), C i` by separately handling the cases
`i = Fin.last n` and `i = Fin.castSucc j`, a special case of `Fin.reverseInduction`;
* `Fin.addCases`: define a function on `Fin (m + n)` by separately handling the cases
`Fin.castAdd n i` and `Fin.natAdd m i`;
* `Fin.succAboveCases`: given `i : Fin (n + 1)`, define a function on `Fin (n + 1)` by separately
handling the cases `j = i` and `j = Fin.succAbove i k`, same as `Fin.insertNth` but marked
as eliminator and works for `Sort*`. -- Porting note: this is in another file
### Embeddings and isomorphisms
* `Fin.valEmbedding` : coercion to natural numbers as an `Embedding`;
* `Fin.succEmb` : `Fin.succ` as an `Embedding`;
* `Fin.castLEEmb h` : `Fin.castLE` as an `Embedding`, embed `Fin n` into `Fin m`, `h : n ≤ m`;
* `finCongr` : `Fin.cast` as an `Equiv`, equivalence between `Fin n` and `Fin m` when `n = m`;
* `Fin.castAddEmb m` : `Fin.castAdd` as an `Embedding`, embed `Fin n` into `Fin (n+m)`;
* `Fin.castSuccEmb` : `Fin.castSucc` as an `Embedding`, embed `Fin n` into `Fin (n+1)`;
* `Fin.addNatEmb m i` : `Fin.addNat` as an `Embedding`, add `m` on `i` on the right,
generalizes `Fin.succ`;
* `Fin.natAddEmb n i` : `Fin.natAdd` as an `Embedding`, adds `n` on `i` on the left;
### Other casts
* `Fin.ofNat'`: given a positive number `n` (deduced from `[NeZero n]`), `Fin.ofNat' i` is
`i % n` interpreted as an element of `Fin n`;
* `Fin.divNat i` : divides `i : Fin (m * n)` by `n`;
* `Fin.modNat i` : takes the mod of `i : Fin (m * n)` by `n`;
### Misc definitions
* `Fin.revPerm : Equiv.Perm (Fin n)` : `Fin.rev` as an `Equiv.Perm`, the antitone involution given
by `i ↦ n-(i+1)`
-/
assert_not_exists Monoid
universe u v
open Fin Nat Function
/-- Elimination principle for the empty set `Fin 0`, dependent version. -/
def finZeroElim {α : Fin 0 → Sort*} (x : Fin 0) : α x :=
x.elim0
#align fin_zero_elim finZeroElim
namespace Fin
instance {n : ℕ} : CanLift ℕ (Fin n) Fin.val (· < n) where
prf k hk := ⟨⟨k, hk⟩, rfl⟩
/-- A dependent variant of `Fin.elim0`. -/
def rec0 {α : Fin 0 → Sort*} (i : Fin 0) : α i := absurd i.2 (Nat.not_lt_zero _)
#align fin.elim0' Fin.elim0
variable {n m : ℕ}
--variable {a b : Fin n} -- this *really* breaks stuff
#align fin.fin_to_nat Fin.coeToNat
theorem val_injective : Function.Injective (@Fin.val n) :=
@Fin.eq_of_val_eq n
#align fin.val_injective Fin.val_injective
/-- If you actually have an element of `Fin n`, then the `n` is always positive -/
lemma size_positive : Fin n → 0 < n := Fin.pos
lemma size_positive' [Nonempty (Fin n)] : 0 < n :=
‹Nonempty (Fin n)›.elim Fin.pos
protected theorem prop (a : Fin n) : a.val < n :=
a.2
#align fin.prop Fin.prop
#align fin.is_lt Fin.is_lt
#align fin.pos Fin.pos
#align fin.pos_iff_nonempty Fin.pos_iff_nonempty
section Order
variable {a b c : Fin n}
protected lemma lt_of_le_of_lt : a ≤ b → b < c → a < c := Nat.lt_of_le_of_lt
protected lemma lt_of_lt_of_le : a < b → b ≤ c → a < c := Nat.lt_of_lt_of_le
protected lemma le_rfl : a ≤ a := Nat.le_refl _
protected lemma lt_iff_le_and_ne : a < b ↔ a ≤ b ∧ a ≠ b := by
rw [← val_ne_iff]; exact Nat.lt_iff_le_and_ne
protected lemma lt_or_lt_of_ne (h : a ≠ b) : a < b ∨ b < a := Nat.lt_or_lt_of_ne $ val_ne_iff.2 h
protected lemma lt_or_le (a b : Fin n) : a < b ∨ b ≤ a := Nat.lt_or_ge _ _
protected lemma le_or_lt (a b : Fin n) : a ≤ b ∨ b < a := (b.lt_or_le a).symm
protected lemma le_of_eq (hab : a = b) : a ≤ b := Nat.le_of_eq $ congr_arg val hab
protected lemma ge_of_eq (hab : a = b) : b ≤ a := Fin.le_of_eq hab.symm
protected lemma eq_or_lt_of_le : a ≤ b → a = b ∨ a < b := by rw [ext_iff]; exact Nat.eq_or_lt_of_le
protected lemma lt_or_eq_of_le : a ≤ b → a < b ∨ a = b := by rw [ext_iff]; exact Nat.lt_or_eq_of_le
end Order
lemma lt_last_iff_ne_last {a : Fin (n + 1)} : a < last n ↔ a ≠ last n := by
simp [Fin.lt_iff_le_and_ne, le_last]
lemma ne_zero_of_lt {a b : Fin (n + 1)} (hab : a < b) : b ≠ 0 :=
Fin.ne_of_gt $ Fin.lt_of_le_of_lt a.zero_le hab
lemma ne_last_of_lt {a b : Fin (n + 1)} (hab : a < b) : a ≠ last n :=
Fin.ne_of_lt $ Fin.lt_of_lt_of_le hab b.le_last
/-- Equivalence between `Fin n` and `{ i // i < n }`. -/
@[simps apply symm_apply]
def equivSubtype : Fin n ≃ { i // i < n } where
toFun a := ⟨a.1, a.2⟩
invFun a := ⟨a.1, a.2⟩
left_inv := fun ⟨_, _⟩ => rfl
right_inv := fun ⟨_, _⟩ => rfl
#align fin.equiv_subtype Fin.equivSubtype
#align fin.equiv_subtype_symm_apply Fin.equivSubtype_symm_apply
#align fin.equiv_subtype_apply Fin.equivSubtype_apply
section coe
/-!
### coercions and constructions
-/
#align fin.eta Fin.eta
#align fin.ext Fin.ext
#align fin.ext_iff Fin.ext_iff
#align fin.coe_injective Fin.val_injective
theorem val_eq_val (a b : Fin n) : (a : ℕ) = b ↔ a = b :=
ext_iff.symm
#align fin.coe_eq_coe Fin.val_eq_val
@[deprecated ext_iff (since := "2024-02-20")]
theorem eq_iff_veq (a b : Fin n) : a = b ↔ a.1 = b.1 :=
ext_iff
#align fin.eq_iff_veq Fin.eq_iff_veq
theorem ne_iff_vne (a b : Fin n) : a ≠ b ↔ a.1 ≠ b.1 :=
ext_iff.not
#align fin.ne_iff_vne Fin.ne_iff_vne
-- Porting note: I'm not sure if this comment still applies.
-- built-in reduction doesn't always work
@[simp, nolint simpNF]
theorem mk_eq_mk {a h a' h'} : @mk n a h = @mk n a' h' ↔ a = a' :=
ext_iff
#align fin.mk_eq_mk Fin.mk_eq_mk
#align fin.mk.inj_iff Fin.mk.inj_iff
#align fin.mk_val Fin.val_mk
#align fin.eq_mk_iff_coe_eq Fin.eq_mk_iff_val_eq
#align fin.coe_mk Fin.val_mk
#align fin.mk_coe Fin.mk_val
-- syntactic tautologies now
#noalign fin.coe_eq_val
#noalign fin.val_eq_coe
/-- Assume `k = l`. If two functions defined on `Fin k` and `Fin l` are equal on each element,
then they coincide (in the heq sense). -/
protected theorem heq_fun_iff {α : Sort*} {k l : ℕ} (h : k = l) {f : Fin k → α} {g : Fin l → α} :
HEq f g ↔ ∀ i : Fin k, f i = g ⟨(i : ℕ), h ▸ i.2⟩ := by
subst h
simp [Function.funext_iff]
#align fin.heq_fun_iff Fin.heq_fun_iff
/-- Assume `k = l` and `k' = l'`.
If two functions `Fin k → Fin k' → α` and `Fin l → Fin l' → α` are equal on each pair,
then they coincide (in the heq sense). -/
protected theorem heq_fun₂_iff {α : Sort*} {k l k' l' : ℕ} (h : k = l) (h' : k' = l')
{f : Fin k → Fin k' → α} {g : Fin l → Fin l' → α} :
HEq f g ↔ ∀ (i : Fin k) (j : Fin k'), f i j = g ⟨(i : ℕ), h ▸ i.2⟩ ⟨(j : ℕ), h' ▸ j.2⟩ := by
subst h
subst h'
simp [Function.funext_iff]
protected theorem heq_ext_iff {k l : ℕ} (h : k = l) {i : Fin k} {j : Fin l} :
HEq i j ↔ (i : ℕ) = (j : ℕ) := by
subst h
simp [val_eq_val]
#align fin.heq_ext_iff Fin.heq_ext_iff
#align fin.exists_iff Fin.exists_iff
#align fin.forall_iff Fin.forall_iff
end coe
section Order
/-!
### order
-/
#align fin.is_le Fin.is_le
#align fin.is_le' Fin.is_le'
#align fin.lt_iff_coe_lt_coe Fin.lt_iff_val_lt_val
theorem le_iff_val_le_val {a b : Fin n} : a ≤ b ↔ (a : ℕ) ≤ b :=
Iff.rfl
#align fin.le_iff_coe_le_coe Fin.le_iff_val_le_val
#align fin.mk_lt_of_lt_coe Fin.mk_lt_of_lt_val
#align fin.mk_le_of_le_coe Fin.mk_le_of_le_val
/-- `a < b` as natural numbers if and only if `a < b` in `Fin n`. -/
@[norm_cast, simp]
theorem val_fin_lt {n : ℕ} {a b : Fin n} : (a : ℕ) < (b : ℕ) ↔ a < b :=
Iff.rfl
#align fin.coe_fin_lt Fin.val_fin_lt
/-- `a ≤ b` as natural numbers if and only if `a ≤ b` in `Fin n`. -/
@[norm_cast, simp]
theorem val_fin_le {n : ℕ} {a b : Fin n} : (a : ℕ) ≤ (b : ℕ) ↔ a ≤ b :=
Iff.rfl
#align fin.coe_fin_le Fin.val_fin_le
#align fin.mk_le_mk Fin.mk_le_mk
#align fin.mk_lt_mk Fin.mk_lt_mk
-- @[simp] -- Porting note (#10618): simp can prove this
theorem min_val {a : Fin n} : min (a : ℕ) n = a := by simp
#align fin.min_coe Fin.min_val
-- @[simp] -- Porting note (#10618): simp can prove this
theorem max_val {a : Fin n} : max (a : ℕ) n = n := by simp
#align fin.max_coe Fin.max_val
/-- The inclusion map `Fin n → ℕ` is an embedding. -/
@[simps apply]
def valEmbedding : Fin n ↪ ℕ :=
⟨val, val_injective⟩
#align fin.coe_embedding Fin.valEmbedding
@[simp]
theorem equivSubtype_symm_trans_valEmbedding :
equivSubtype.symm.toEmbedding.trans valEmbedding = Embedding.subtype (· < n) :=
rfl
#align fin.equiv_subtype_symm_trans_val_embedding Fin.equivSubtype_symm_trans_valEmbedding
/-- Use the ordering on `Fin n` for checking recursive definitions.
For example, the following definition is not accepted by the termination checker,
unless we declare the `WellFoundedRelation` instance:
```lean
def factorial {n : ℕ} : Fin n → ℕ
| ⟨0, _⟩ := 1
| ⟨i + 1, hi⟩ := (i + 1) * factorial ⟨i, i.lt_succ_self.trans hi⟩
```
-/
instance {n : ℕ} : WellFoundedRelation (Fin n) :=
measure (val : Fin n → ℕ)
/-- Given a positive `n`, `Fin.ofNat' i` is `i % n` as an element of `Fin n`. -/
def ofNat'' [NeZero n] (i : ℕ) : Fin n :=
⟨i % n, mod_lt _ n.pos_of_neZero⟩
#align fin.of_nat' Fin.ofNat''ₓ
-- Porting note: `Fin.ofNat'` conflicts with something in core (there the hypothesis is `n > 0`),
-- so for now we make this double-prime `''`. This is also the reason for the dubious translation.
instance {n : ℕ} [NeZero n] : Zero (Fin n) := ⟨ofNat'' 0⟩
instance {n : ℕ} [NeZero n] : One (Fin n) := ⟨ofNat'' 1⟩
#align fin.coe_zero Fin.val_zero
/--
The `Fin.val_zero` in `Lean` only applies in `Fin (n+1)`.
This one instead uses a `NeZero n` typeclass hypothesis.
-/
@[simp]
theorem val_zero' (n : ℕ) [NeZero n] : ((0 : Fin n) : ℕ) = 0 :=
rfl
#align fin.val_zero' Fin.val_zero'
#align fin.mk_zero Fin.mk_zero
/--
The `Fin.zero_le` in `Lean` only applies in `Fin (n+1)`.
This one instead uses a `NeZero n` typeclass hypothesis.
-/
@[simp]
protected theorem zero_le' [NeZero n] (a : Fin n) : 0 ≤ a :=
Nat.zero_le a.val
#align fin.zero_le Fin.zero_le'
#align fin.zero_lt_one Fin.zero_lt_one
#align fin.not_lt_zero Fin.not_lt_zero
/--
The `Fin.pos_iff_ne_zero` in `Lean` only applies in `Fin (n+1)`.
This one instead uses a `NeZero n` typeclass hypothesis.
-/
theorem pos_iff_ne_zero' [NeZero n] (a : Fin n) : 0 < a ↔ a ≠ 0 := by
rw [← val_fin_lt, val_zero', Nat.pos_iff_ne_zero, Ne, Ne, ext_iff, val_zero']
#align fin.pos_iff_ne_zero Fin.pos_iff_ne_zero'
#align fin.eq_zero_or_eq_succ Fin.eq_zero_or_eq_succ
#align fin.eq_succ_of_ne_zero Fin.eq_succ_of_ne_zero
@[simp] lemma cast_eq_self (a : Fin n) : cast rfl a = a := rfl
theorem rev_involutive : Involutive (rev : Fin n → Fin n) := fun i =>
ext <| by
dsimp only [rev]
rw [← Nat.sub_sub, Nat.sub_sub_self (Nat.add_one_le_iff.2 i.is_lt), Nat.add_sub_cancel_right]
#align fin.rev_involutive Fin.rev_involutive
/-- `Fin.rev` as an `Equiv.Perm`, the antitone involution `Fin n → Fin n` given by
`i ↦ n-(i+1)`. -/
@[simps! apply symm_apply]
def revPerm : Equiv.Perm (Fin n) :=
Involutive.toPerm rev rev_involutive
#align fin.rev Fin.revPerm
#align fin.coe_rev Fin.val_revₓ
theorem rev_injective : Injective (@rev n) :=
rev_involutive.injective
#align fin.rev_injective Fin.rev_injective
theorem rev_surjective : Surjective (@rev n) :=
rev_involutive.surjective
#align fin.rev_surjective Fin.rev_surjective
theorem rev_bijective : Bijective (@rev n) :=
rev_involutive.bijective
#align fin.rev_bijective Fin.rev_bijective
#align fin.rev_inj Fin.rev_injₓ
#align fin.rev_rev Fin.rev_revₓ
@[simp]
theorem revPerm_symm : (@revPerm n).symm = revPerm :=
rfl
#align fin.rev_symm Fin.revPerm_symm
#align fin.rev_eq Fin.rev_eqₓ
#align fin.rev_le_rev Fin.rev_le_revₓ
#align fin.rev_lt_rev Fin.rev_lt_revₓ
theorem cast_rev (i : Fin n) (h : n = m) :
cast h i.rev = (i.cast h).rev := by
subst h; simp
theorem rev_eq_iff {i j : Fin n} : rev i = j ↔ i = rev j := by
rw [← rev_inj, rev_rev]
theorem rev_ne_iff {i j : Fin n} : rev i ≠ j ↔ i ≠ rev j := rev_eq_iff.not
theorem rev_lt_iff {i j : Fin n} : rev i < j ↔ rev j < i := by
rw [← rev_lt_rev, rev_rev]
theorem rev_le_iff {i j : Fin n} : rev i ≤ j ↔ rev j ≤ i := by
rw [← rev_le_rev, rev_rev]
theorem lt_rev_iff {i j : Fin n} : i < rev j ↔ j < rev i := by
rw [← rev_lt_rev, rev_rev]
theorem le_rev_iff {i j : Fin n} : i ≤ rev j ↔ j ≤ rev i := by
rw [← rev_le_rev, rev_rev]
#align fin.last Fin.last
#align fin.coe_last Fin.val_last
-- Porting note: this is now syntactically equal to `val_last`
#align fin.last_val Fin.val_last
#align fin.le_last Fin.le_last
#align fin.last_pos Fin.last_pos
#align fin.eq_last_of_not_lt Fin.eq_last_of_not_lt
theorem last_pos' [NeZero n] : 0 < last n := n.pos_of_neZero
theorem one_lt_last [NeZero n] : 1 < last (n + 1) := Nat.lt_add_left_iff_pos.2 n.pos_of_neZero
end Order
section Add
/-!
### addition, numerals, and coercion from Nat
-/
#align fin.val_one Fin.val_one
#align fin.coe_one Fin.val_one
@[simp]
theorem val_one' (n : ℕ) [NeZero n] : ((1 : Fin n) : ℕ) = 1 % n :=
rfl
#align fin.coe_one' Fin.val_one'
-- Porting note: Delete this lemma after porting
theorem val_one'' {n : ℕ} : ((1 : Fin (n + 1)) : ℕ) = 1 % (n + 1) :=
rfl
#align fin.one_val Fin.val_one''
#align fin.mk_one Fin.mk_one
instance nontrivial {n : ℕ} : Nontrivial (Fin (n + 2)) where
exists_pair_ne := ⟨0, 1, (ne_iff_vne 0 1).mpr (by simp [val_one, val_zero])⟩
theorem nontrivial_iff_two_le : Nontrivial (Fin n) ↔ 2 ≤ n := by
rcases n with (_ | _ | n) <;>
simp [← Nat.one_eq_succ_zero, Fin.nontrivial, not_nontrivial, Nat.succ_le_iff]
-- Porting note: here and in the next lemma, had to use `← Nat.one_eq_succ_zero`.
#align fin.nontrivial_iff_two_le Fin.nontrivial_iff_two_le
#align fin.subsingleton_iff_le_one Fin.subsingleton_iff_le_one
section Monoid
-- Porting note (#10618): removing `simp`, `simp` can prove it with AddCommMonoid instance
protected theorem add_zero [NeZero n] (k : Fin n) : k + 0 = k := by
simp only [add_def, val_zero', Nat.add_zero, mod_eq_of_lt (is_lt k)]
#align fin.add_zero Fin.add_zero
-- Porting note (#10618): removing `simp`, `simp` can prove it with AddCommMonoid instance
protected theorem zero_add [NeZero n] (k : Fin n) : 0 + k = k := by
simp [ext_iff, add_def, mod_eq_of_lt (is_lt k)]
#align fin.zero_add Fin.zero_add
instance {a : ℕ} [NeZero n] : OfNat (Fin n) a where
ofNat := Fin.ofNat' a n.pos_of_neZero
instance inhabited (n : ℕ) [NeZero n] : Inhabited (Fin n) :=
⟨0⟩
instance inhabitedFinOneAdd (n : ℕ) : Inhabited (Fin (1 + n)) :=
haveI : NeZero (1 + n) := by rw [Nat.add_comm]; infer_instance
inferInstance
@[simp]
theorem default_eq_zero (n : ℕ) [NeZero n] : (default : Fin n) = 0 :=
rfl
#align fin.default_eq_zero Fin.default_eq_zero
section from_ad_hoc
@[simp] lemma ofNat'_zero {h : 0 < n} [NeZero n] : (Fin.ofNat' 0 h : Fin n) = 0 := rfl
@[simp] lemma ofNat'_one {h : 0 < n} [NeZero n] : (Fin.ofNat' 1 h : Fin n) = 1 := rfl
end from_ad_hoc
instance instNatCast [NeZero n] : NatCast (Fin n) where
natCast n := Fin.ofNat'' n
lemma natCast_def [NeZero n] (a : ℕ) : (a : Fin n) = ⟨a % n, mod_lt _ n.pos_of_neZero⟩ := rfl
end Monoid
#align fin.val_add Fin.val_add
#align fin.coe_add Fin.val_add
theorem val_add_eq_ite {n : ℕ} (a b : Fin n) :
(↑(a + b) : ℕ) = if n ≤ a + b then a + b - n else a + b := by
rw [Fin.val_add, Nat.add_mod_eq_ite, Nat.mod_eq_of_lt (show ↑a < n from a.2),
Nat.mod_eq_of_lt (show ↑b < n from b.2)]
#align fin.coe_add_eq_ite Fin.val_add_eq_ite
section deprecated
set_option linter.deprecated false
@[deprecated]
theorem val_bit0 {n : ℕ} (k : Fin n) : ((bit0 k : Fin n) : ℕ) = bit0 (k : ℕ) % n := by
cases k
rfl
#align fin.coe_bit0 Fin.val_bit0
@[deprecated]
theorem val_bit1 {n : ℕ} [NeZero n] (k : Fin n) :
((bit1 k : Fin n) : ℕ) = bit1 (k : ℕ) % n := by
cases n;
· cases' k with k h
cases k
· show _ % _ = _
simp at h
cases' h with _ h
simp [bit1, Fin.val_bit0, Fin.val_add, Fin.val_one]
#align fin.coe_bit1 Fin.val_bit1
end deprecated
#align fin.coe_add_one_of_lt Fin.val_add_one_of_lt
#align fin.last_add_one Fin.last_add_one
#align fin.coe_add_one Fin.val_add_one
section Bit
set_option linter.deprecated false
@[simp, deprecated]
theorem mk_bit0 {m n : ℕ} (h : bit0 m < n) :
(⟨bit0 m, h⟩ : Fin n) = (bit0 ⟨m, (Nat.le_add_right m m).trans_lt h⟩ : Fin _) :=
eq_of_val_eq (Nat.mod_eq_of_lt h).symm
#align fin.mk_bit0 Fin.mk_bit0
@[simp, deprecated]
theorem mk_bit1 {m n : ℕ} [NeZero n] (h : bit1 m < n) :
(⟨bit1 m, h⟩ : Fin n) =
(bit1 ⟨m, (Nat.le_add_right m m).trans_lt ((m + m).lt_succ_self.trans h)⟩ : Fin _) := by
ext
simp only [bit1, bit0] at h
simp only [bit1, bit0, val_add, val_one', ← Nat.add_mod, Nat.mod_eq_of_lt h]
#align fin.mk_bit1 Fin.mk_bit1
end Bit
#align fin.val_two Fin.val_two
--- Porting note: syntactically the same as the above
#align fin.coe_two Fin.val_two
section OfNatCoe
@[simp]
theorem ofNat''_eq_cast (n : ℕ) [NeZero n] (a : ℕ) : (Fin.ofNat'' a : Fin n) = a :=
rfl
#align fin.of_nat_eq_coe Fin.ofNat''_eq_cast
@[simp] lemma val_natCast (a n : ℕ) [NeZero n] : (a : Fin n).val = a % n := rfl
@[deprecated (since := "2024-04-17")]
alias val_nat_cast := val_natCast
-- Porting note: is this the right name for things involving `Nat.cast`?
/-- Converting an in-range number to `Fin (n + 1)` produces a result
whose value is the original number. -/
theorem val_cast_of_lt {n : ℕ} [NeZero n] {a : ℕ} (h : a < n) : (a : Fin n).val = a :=
Nat.mod_eq_of_lt h
#align fin.coe_val_of_lt Fin.val_cast_of_lt
/-- If `n` is non-zero, converting the value of a `Fin n` to `Fin n` results
in the same value. -/
@[simp] theorem cast_val_eq_self {n : ℕ} [NeZero n] (a : Fin n) : (a.val : Fin n) = a :=
ext <| val_cast_of_lt a.isLt
#align fin.coe_val_eq_self Fin.cast_val_eq_self
-- Porting note: this is syntactically the same as `val_cast_of_lt`
#align fin.coe_coe_of_lt Fin.val_cast_of_lt
-- Porting note: this is syntactically the same as `cast_val_of_lt`
#align fin.coe_coe_eq_self Fin.cast_val_eq_self
@[simp] lemma natCast_self (n : ℕ) [NeZero n] : (n : Fin n) = 0 := by ext; simp
@[deprecated (since := "2024-04-17")]
alias nat_cast_self := natCast_self
@[simp] lemma natCast_eq_zero {a n : ℕ} [NeZero n] : (a : Fin n) = 0 ↔ n ∣ a := by
simp [ext_iff, Nat.dvd_iff_mod_eq_zero]
@[deprecated (since := "2024-04-17")]
alias nat_cast_eq_zero := natCast_eq_zero
@[simp]
theorem natCast_eq_last (n) : (n : Fin (n + 1)) = Fin.last n := by ext; simp
#align fin.coe_nat_eq_last Fin.natCast_eq_last
@[deprecated (since := "2024-05-04")] alias cast_nat_eq_last := natCast_eq_last
theorem le_val_last (i : Fin (n + 1)) : i ≤ n := by
rw [Fin.natCast_eq_last]
exact Fin.le_last i
#align fin.le_coe_last Fin.le_val_last
variable {a b : ℕ}
lemma natCast_le_natCast (han : a ≤ n) (hbn : b ≤ n) : (a : Fin (n + 1)) ≤ b ↔ a ≤ b := by
rw [← Nat.lt_succ_iff] at han hbn
simp [le_iff_val_le_val, -val_fin_le, Nat.mod_eq_of_lt, han, hbn]
lemma natCast_lt_natCast (han : a ≤ n) (hbn : b ≤ n) : (a : Fin (n + 1)) < b ↔ a < b := by
rw [← Nat.lt_succ_iff] at han hbn; simp [lt_iff_val_lt_val, Nat.mod_eq_of_lt, han, hbn]
lemma natCast_mono (hbn : b ≤ n) (hab : a ≤ b) : (a : Fin (n + 1)) ≤ b :=
(natCast_le_natCast (hab.trans hbn) hbn).2 hab
lemma natCast_strictMono (hbn : b ≤ n) (hab : a < b) : (a : Fin (n + 1)) < b :=
(natCast_lt_natCast (hab.le.trans hbn) hbn).2 hab
end OfNatCoe
#align fin.add_one_pos Fin.add_one_pos
#align fin.one_pos Fin.one_pos
#align fin.zero_ne_one Fin.zero_ne_one
@[simp]
theorem one_eq_zero_iff [NeZero n] : (1 : Fin n) = 0 ↔ n = 1 := by
obtain _ | _ | n := n <;> simp [Fin.ext_iff]
#align fin.one_eq_zero_iff Fin.one_eq_zero_iff
@[simp]
theorem zero_eq_one_iff [NeZero n] : (0 : Fin n) = 1 ↔ n = 1 := by rw [eq_comm, one_eq_zero_iff]
#align fin.zero_eq_one_iff Fin.zero_eq_one_iff
end Add
section Succ
/-!
### succ and casts into larger Fin types
-/
#align fin.coe_succ Fin.val_succ
#align fin.succ_pos Fin.succ_pos
lemma succ_injective (n : ℕ) : Injective (@Fin.succ n) := fun a b ↦ by simp [ext_iff]
#align fin.succ_injective Fin.succ_injective
/-- `Fin.succ` as an `Embedding` -/
def succEmb (n : ℕ) : Fin n ↪ Fin (n + 1) where
toFun := succ
inj' := succ_injective _
@[simp]
theorem val_succEmb : ⇑(succEmb n) = Fin.succ := rfl
#align fin.succ_le_succ_iff Fin.succ_le_succ_iff
#align fin.succ_lt_succ_iff Fin.succ_lt_succ_iff
@[simp]
theorem exists_succ_eq {x : Fin (n + 1)} : (∃ y, Fin.succ y = x) ↔ x ≠ 0 :=
⟨fun ⟨_, hy⟩ => hy ▸ succ_ne_zero _, x.cases (fun h => h.irrefl.elim) (fun _ _ => ⟨_, rfl⟩)⟩
#align fin.exists_succ_eq_iff Fin.exists_succ_eq
theorem exists_succ_eq_of_ne_zero {x : Fin (n + 1)} (h : x ≠ 0) :
∃ y, Fin.succ y = x := exists_succ_eq.mpr h
#align fin.succ_inj Fin.succ_inj
#align fin.succ_ne_zero Fin.succ_ne_zero
@[simp]
theorem succ_zero_eq_one' [NeZero n] : Fin.succ (0 : Fin n) = 1 := by
cases n
· exact (NeZero.ne 0 rfl).elim
· rfl
#align fin.succ_zero_eq_one Fin.succ_zero_eq_one'
theorem one_pos' [NeZero n] : (0 : Fin (n + 1)) < 1 := succ_zero_eq_one' (n := n) ▸ succ_pos _
theorem zero_ne_one' [NeZero n] : (0 : Fin (n + 1)) ≠ 1 := Fin.ne_of_lt one_pos'
#align fin.succ_zero_eq_one' Fin.succ_zero_eq_one
/--
The `Fin.succ_one_eq_two` in `Lean` only applies in `Fin (n+2)`.
This one instead uses a `NeZero n` typeclass hypothesis.
-/
@[simp]
theorem succ_one_eq_two' [NeZero n] : Fin.succ (1 : Fin (n + 1)) = 2 := by
cases n
· exact (NeZero.ne 0 rfl).elim
· rfl
#align fin.succ_one_eq_two Fin.succ_one_eq_two'
-- Version of `succ_one_eq_two` to be used by `dsimp`.
-- Note the `'` swapped around due to a move to std4.
#align fin.succ_one_eq_two' Fin.succ_one_eq_two
#align fin.succ_mk Fin.succ_mk
#align fin.mk_succ_pos Fin.mk_succ_pos
#align fin.one_lt_succ_succ Fin.one_lt_succ_succ
#align fin.add_one_lt_iff Fin.add_one_lt_iff
#align fin.add_one_le_iff Fin.add_one_le_iff
#align fin.last_le_iff Fin.last_le_iff
#align fin.lt_add_one_iff Fin.lt_add_one_iff
/--
The `Fin.le_zero_iff` in `Lean` only applies in `Fin (n+1)`.
This one instead uses a `NeZero n` typeclass hypothesis.
-/
@[simp]
theorem le_zero_iff' {n : ℕ} [NeZero n] {k : Fin n} : k ≤ 0 ↔ k = 0 :=
⟨fun h => Fin.ext <| by rw [Nat.eq_zero_of_le_zero h]; rfl, by rintro rfl; exact Nat.le_refl _⟩
#align fin.le_zero_iff Fin.le_zero_iff'
#align fin.succ_succ_ne_one Fin.succ_succ_ne_one
#align fin.cast_lt Fin.castLT
#align fin.coe_cast_lt Fin.coe_castLT
#align fin.cast_lt_mk Fin.castLT_mk
-- Move to Batteries?
@[simp] theorem cast_refl {n : Nat} (h : n = n) :
Fin.cast h = id := rfl
-- TODO: Move to Batteries
@[simp] lemma castLE_inj {hmn : m ≤ n} {a b : Fin m} : castLE hmn a = castLE hmn b ↔ a = b := by
simp [ext_iff]
@[simp] lemma castAdd_inj {a b : Fin m} : castAdd n a = castAdd n b ↔ a = b := by simp [ext_iff]
attribute [simp] castSucc_inj
lemma castLE_injective (hmn : m ≤ n) : Injective (castLE hmn) :=
fun a b hab ↦ ext (by have := congr_arg val hab; exact this)
lemma castAdd_injective (m n : ℕ) : Injective (@Fin.castAdd m n) := castLE_injective _
lemma castSucc_injective (n : ℕ) : Injective (@Fin.castSucc n) := castAdd_injective _ _
#align fin.cast_succ_injective Fin.castSucc_injective
/-- `Fin.castLE` as an `Embedding`, `castLEEmb h i` embeds `i` into a larger `Fin` type. -/
@[simps! apply]
def castLEEmb (h : n ≤ m) : Fin n ↪ Fin m where
toFun := castLE h
inj' := castLE_injective _
@[simp, norm_cast] lemma coe_castLEEmb {m n} (hmn : m ≤ n) : castLEEmb hmn = castLE hmn := rfl
#align fin.coe_cast_le Fin.coe_castLE
#align fin.cast_le_mk Fin.castLE_mk
#align fin.cast_le_zero Fin.castLE_zero
/- The next proof can be golfed a lot using `Fintype.card`.
It is written this way to define `ENat.card` and `Nat.card` without a `Fintype` dependency
(not done yet). -/
assert_not_exists Fintype
lemma nonempty_embedding_iff : Nonempty (Fin n ↪ Fin m) ↔ n ≤ m := by
refine ⟨fun h ↦ ?_, fun h ↦ ⟨castLEEmb h⟩⟩
induction n generalizing m with
| zero => exact m.zero_le
| succ n ihn =>
cases' h with e
rcases exists_eq_succ_of_ne_zero (pos_iff_nonempty.2 (Nonempty.map e inferInstance)).ne'
with ⟨m, rfl⟩
refine Nat.succ_le_succ <| ihn ⟨?_⟩
refine ⟨fun i ↦ (e.setValue 0 0 i.succ).pred (mt e.setValue_eq_iff.1 i.succ_ne_zero),
fun i j h ↦ ?_⟩
simpa only [pred_inj, EmbeddingLike.apply_eq_iff_eq, succ_inj] using h
lemma equiv_iff_eq : Nonempty (Fin m ≃ Fin n) ↔ m = n :=
⟨fun ⟨e⟩ ↦ le_antisymm (nonempty_embedding_iff.1 ⟨e⟩) (nonempty_embedding_iff.1 ⟨e.symm⟩),
fun h ↦ h ▸ ⟨.refl _⟩⟩
#align fin.equiv_iff_eq Fin.equiv_iff_eq
@[simp] lemma castLE_castSucc {n m} (i : Fin n) (h : n + 1 ≤ m) :
i.castSucc.castLE h = i.castLE (Nat.le_of_succ_le h) :=
rfl
@[simp] lemma castLE_comp_castSucc {n m} (h : n + 1 ≤ m) :
Fin.castLE h ∘ Fin.castSucc = Fin.castLE (Nat.le_of_succ_le h) :=
rfl
@[simp] lemma castLE_rfl (n : ℕ) : Fin.castLE (le_refl n) = id :=
rfl
@[simp]
theorem range_castLE {n k : ℕ} (h : n ≤ k) : Set.range (castLE h) = { i : Fin k | (i : ℕ) < n } :=
Set.ext fun x => ⟨fun ⟨y, hy⟩ => hy ▸ y.2, fun hx => ⟨⟨x, hx⟩, Fin.ext rfl⟩⟩
#align fin.range_cast_le Fin.range_castLE
@[simp]
theorem coe_of_injective_castLE_symm {n k : ℕ} (h : n ≤ k) (i : Fin k) (hi) :
((Equiv.ofInjective _ (castLE_injective h)).symm ⟨i, hi⟩ : ℕ) = i := by
rw [← coe_castLE h]
exact congr_arg Fin.val (Equiv.apply_ofInjective_symm _ _)
#align fin.coe_of_injective_cast_le_symm Fin.coe_of_injective_castLE_symm
#align fin.cast_le_succ Fin.castLE_succ
#align fin.cast_le_cast_le Fin.castLE_castLE
#align fin.cast_le_comp_cast_le Fin.castLE_comp_castLE
theorem leftInverse_cast (eq : n = m) : LeftInverse (cast eq.symm) (cast eq) :=
fun _ => rfl
theorem rightInverse_cast (eq : n = m) : RightInverse (cast eq.symm) (cast eq) :=
fun _ => rfl
theorem cast_le_cast (eq : n = m) {a b : Fin n} : cast eq a ≤ cast eq b ↔ a ≤ b :=
Iff.rfl
/-- The 'identity' equivalence between `Fin m` and `Fin n` when `m = n`. -/
@[simps]
def _root_.finCongr (eq : n = m) : Fin n ≃ Fin m where
toFun := cast eq
invFun := cast eq.symm
left_inv := leftInverse_cast eq
right_inv := rightInverse_cast eq
#align fin_congr finCongr
@[simp] lemma _root_.finCongr_apply_mk (h : m = n) (k : ℕ) (hk : k < m) :
finCongr h ⟨k, hk⟩ = ⟨k, h ▸ hk⟩ := rfl
#align fin_congr_apply_mk finCongr_apply_mk
@[simp]
lemma _root_.finCongr_refl (h : n = n := rfl) : finCongr h = Equiv.refl (Fin n) := by ext; simp
@[simp] lemma _root_.finCongr_symm (h : m = n) : (finCongr h).symm = finCongr h.symm := rfl
#align fin_congr_symm finCongr_symm
@[simp] lemma _root_.finCongr_apply_coe (h : m = n) (k : Fin m) : (finCongr h k : ℕ) = k := rfl
#align fin_congr_apply_coe finCongr_apply_coe
lemma _root_.finCongr_symm_apply_coe (h : m = n) (k : Fin n) : ((finCongr h).symm k : ℕ) = k := rfl
#align fin_congr_symm_apply_coe finCongr_symm_apply_coe
/-- While in many cases `finCongr` is better than `Equiv.cast`/`cast`, sometimes we want to apply
a generic theorem about `cast`. -/
lemma _root_.finCongr_eq_equivCast (h : n = m) : finCongr h = .cast (h ▸ rfl) := by subst h; simp
#align fin.coe_cast Fin.coe_castₓ
@[simp]
theorem cast_zero {n' : ℕ} [NeZero n] {h : n = n'} : cast h (0 : Fin n) =
by { haveI : NeZero n' := by {rw [← h]; infer_instance}; exact 0} :=
ext rfl
#align fin.cast_zero Fin.cast_zero
#align fin.cast_last Fin.cast_lastₓ
#align fin.cast_mk Fin.cast_mkₓ
#align fin.cast_trans Fin.cast_transₓ
#align fin.cast_le_of_eq Fin.castLE_of_eq
/-- While in many cases `Fin.cast` is better than `Equiv.cast`/`cast`, sometimes we want to apply
a generic theorem about `cast`. -/
theorem cast_eq_cast (h : n = m) : (cast h : Fin n → Fin m) = _root_.cast (h ▸ rfl) := by
subst h
ext
rfl
#align fin.cast_eq_cast Fin.cast_eq_cast
/-- `Fin.castAdd` as an `Embedding`, `castAddEmb m i` embeds `i : Fin n` in `Fin (n+m)`.
See also `Fin.natAddEmb` and `Fin.addNatEmb`. -/
@[simps! apply]
def castAddEmb (m) : Fin n ↪ Fin (n + m) := castLEEmb (le_add_right n m)
#align fin.coe_cast_add Fin.coe_castAdd
#align fin.cast_add_zero Fin.castAdd_zeroₓ
#align fin.cast_add_lt Fin.castAdd_lt
#align fin.cast_add_mk Fin.castAdd_mk
#align fin.cast_add_cast_lt Fin.castAdd_castLT
#align fin.cast_lt_cast_add Fin.castLT_castAdd
#align fin.cast_add_cast Fin.castAdd_castₓ
#align fin.cast_cast_add_left Fin.cast_castAdd_leftₓ
#align fin.cast_cast_add_right Fin.cast_castAdd_rightₓ
#align fin.cast_add_cast_add Fin.castAdd_castAdd
#align fin.cast_succ_eq Fin.cast_succ_eqₓ
#align fin.succ_cast_eq Fin.succ_cast_eqₓ
/-- `Fin.castSucc` as an `Embedding`, `castSuccEmb i` embeds `i : Fin n` in `Fin (n+1)`. -/
@[simps! apply]
def castSuccEmb : Fin n ↪ Fin (n + 1) := castAddEmb _
@[simp, norm_cast] lemma coe_castSuccEmb : (castSuccEmb : Fin n → Fin (n + 1)) = Fin.castSucc := rfl
#align fin.coe_cast_succ Fin.coe_castSucc
#align fin.cast_succ_mk Fin.castSucc_mk
#align fin.cast_cast_succ Fin.cast_castSuccₓ
#align fin.cast_succ_lt_succ Fin.castSucc_lt_succ
#align fin.le_cast_succ_iff Fin.le_castSucc_iff
#align fin.cast_succ_lt_iff_succ_le Fin.castSucc_lt_iff_succ_le
#align fin.succ_last Fin.succ_last
#align fin.succ_eq_last_succ Fin.succ_eq_last_succ
#align fin.cast_succ_cast_lt Fin.castSucc_castLT
#align fin.cast_lt_cast_succ Fin.castLT_castSucc
#align fin.cast_succ_lt_cast_succ_iff Fin.castSucc_lt_castSucc_iff
@[simp]
theorem castSucc_le_castSucc_iff {a b : Fin n} : castSucc a ≤ castSucc b ↔ a ≤ b := Iff.rfl
@[simp]
theorem succ_le_castSucc_iff {a b : Fin n} : succ a ≤ castSucc b ↔ a < b := by
rw [le_castSucc_iff, succ_lt_succ_iff]
@[simp]
theorem castSucc_lt_succ_iff {a b : Fin n} : castSucc a < succ b ↔ a ≤ b := by
rw [castSucc_lt_iff_succ_le, succ_le_succ_iff]
theorem le_of_castSucc_lt_of_succ_lt {a b : Fin (n + 1)} {i : Fin n}
(hl : castSucc i < a) (hu : b < succ i) : b < a := by
simp [Fin.lt_def, -val_fin_lt] at *; omega
theorem castSucc_lt_or_lt_succ (p : Fin (n + 1)) (i : Fin n) : castSucc i < p ∨ p < i.succ := by
simp [Fin.lt_def, -val_fin_lt]; omega
#align fin.succ_above_lt_gt Fin.castSucc_lt_or_lt_succ
@[deprecated] alias succAbove_lt_gt := castSucc_lt_or_lt_succ
theorem succ_le_or_le_castSucc (p : Fin (n + 1)) (i : Fin n) : succ i ≤ p ∨ p ≤ i.castSucc := by
rw [le_castSucc_iff, ← castSucc_lt_iff_succ_le]
exact p.castSucc_lt_or_lt_succ i
theorem exists_castSucc_eq_of_ne_last {x : Fin (n + 1)} (h : x ≠ (last _)) :
∃ y, Fin.castSucc y = x := exists_castSucc_eq.mpr h
#align fin.cast_succ_inj Fin.castSucc_inj
#align fin.cast_succ_lt_last Fin.castSucc_lt_last
theorem forall_fin_succ' {P : Fin (n + 1) → Prop} :
(∀ i, P i) ↔ (∀ i : Fin n, P i.castSucc) ∧ P (.last _) :=
⟨fun H => ⟨fun _ => H _, H _⟩, fun ⟨H0, H1⟩ i => Fin.lastCases H1 H0 i⟩
-- to match `Fin.eq_zero_or_eq_succ`
theorem eq_castSucc_or_eq_last {n : Nat} (i : Fin (n + 1)) :
(∃ j : Fin n, i = j.castSucc) ∨ i = last n := i.lastCases (Or.inr rfl) (Or.inl ⟨·, rfl⟩)
theorem exists_fin_succ' {P : Fin (n + 1) → Prop} :
(∃ i, P i) ↔ (∃ i : Fin n, P i.castSucc) ∨ P (.last _) :=
⟨fun ⟨i, h⟩ => Fin.lastCases Or.inr (fun i hi => Or.inl ⟨i, hi⟩) i h,
fun h => h.elim (fun ⟨i, hi⟩ => ⟨i.castSucc, hi⟩) (fun h => ⟨.last _, h⟩)⟩
/--
The `Fin.castSucc_zero` in `Lean` only applies in `Fin (n+1)`.
This one instead uses a `NeZero n` typeclass hypothesis.
-/
@[simp]
theorem castSucc_zero' [NeZero n] : castSucc (0 : Fin n) = 0 :=
ext rfl
#align fin.cast_succ_zero Fin.castSucc_zero'
#align fin.cast_succ_one Fin.castSucc_one
/-- `castSucc i` is positive when `i` is positive.
The `Fin.castSucc_pos` in `Lean` only applies in `Fin (n+1)`.
This one instead uses a `NeZero n` typeclass hypothesis. -/
theorem castSucc_pos' [NeZero n] {i : Fin n} (h : 0 < i) : 0 < castSucc i := by
simpa [lt_iff_val_lt_val] using h
#align fin.cast_succ_pos Fin.castSucc_pos'
/--
The `Fin.castSucc_eq_zero_iff` in `Lean` only applies in `Fin (n+1)`.
This one instead uses a `NeZero n` typeclass hypothesis.
-/
@[simp]
theorem castSucc_eq_zero_iff' [NeZero n] (a : Fin n) : castSucc a = 0 ↔ a = 0 :=
Fin.ext_iff.trans <| (Fin.ext_iff.trans <| by simp).symm
#align fin.cast_succ_eq_zero_iff Fin.castSucc_eq_zero_iff'
/--
The `Fin.castSucc_ne_zero_iff` in `Lean` only applies in `Fin (n+1)`.
This one instead uses a `NeZero n` typeclass hypothesis.
-/
theorem castSucc_ne_zero_iff' [NeZero n] (a : Fin n) : castSucc a ≠ 0 ↔ a ≠ 0 :=
not_iff_not.mpr <| castSucc_eq_zero_iff' a
#align fin.cast_succ_ne_zero_iff Fin.castSucc_ne_zero_iff
theorem castSucc_ne_zero_of_lt {p i : Fin n} (h : p < i) : castSucc i ≠ 0 := by
cases n
· exact i.elim0
· rw [castSucc_ne_zero_iff', Ne, ext_iff]
exact ((zero_le _).trans_lt h).ne'
theorem succ_ne_last_iff (a : Fin (n + 1)) : succ a ≠ last (n + 1) ↔ a ≠ last n :=
not_iff_not.mpr <| succ_eq_last_succ a
| Mathlib/Data/Fin/Basic.lean | 995 | 999 | theorem succ_ne_last_of_lt {p i : Fin n} (h : i < p) : succ i ≠ last n := by |
cases n
· exact i.elim0
· rw [succ_ne_last_iff, Ne, ext_iff]
exact ((le_last _).trans_lt' h).ne
|
/-
Copyright (c) 2021 Jujian Zhang. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jujian Zhang, Eric Wieser
-/
import Mathlib.RingTheory.Ideal.Basic
import Mathlib.RingTheory.Ideal.Maps
import Mathlib.LinearAlgebra.Finsupp
import Mathlib.RingTheory.GradedAlgebra.Basic
#align_import ring_theory.graded_algebra.homogeneous_ideal from "leanprover-community/mathlib"@"4e861f25ba5ceef42ba0712d8ffeb32f38ad6441"
/-!
# Homogeneous ideals of a graded algebra
This file defines homogeneous ideals of `GradedRing 𝒜` where `𝒜 : ι → Submodule R A` and
operations on them.
## Main definitions
For any `I : Ideal A`:
* `Ideal.IsHomogeneous 𝒜 I`: The property that an ideal is closed under `GradedRing.proj`.
* `HomogeneousIdeal 𝒜`: The structure extending ideals which satisfy `Ideal.IsHomogeneous`.
* `Ideal.homogeneousCore I 𝒜`: The largest homogeneous ideal smaller than `I`.
* `Ideal.homogeneousHull I 𝒜`: The smallest homogeneous ideal larger than `I`.
## Main statements
* `HomogeneousIdeal.completeLattice`: `Ideal.IsHomogeneous` is preserved by `⊥`, `⊤`, `⊔`, `⊓`,
`⨆`, `⨅`, and so the subtype of homogeneous ideals inherits a complete lattice structure.
* `Ideal.homogeneousCore.gi`: `Ideal.homogeneousCore` forms a galois insertion with coercion.
* `Ideal.homogeneousHull.gi`: `Ideal.homogeneousHull` forms a galois insertion with coercion.
## Implementation notes
We introduce `Ideal.homogeneousCore'` earlier than might be expected so that we can get access
to `Ideal.IsHomogeneous.iff_exists` as quickly as possible.
## Tags
graded algebra, homogeneous
-/
open SetLike DirectSum Set
open Pointwise DirectSum
variable {ι σ R A : Type*}
section HomogeneousDef
variable [Semiring A]
variable [SetLike σ A] [AddSubmonoidClass σ A] (𝒜 : ι → σ)
variable [DecidableEq ι] [AddMonoid ι] [GradedRing 𝒜]
variable (I : Ideal A)
/-- An `I : Ideal A` is homogeneous if for every `r ∈ I`, all homogeneous components
of `r` are in `I`. -/
def Ideal.IsHomogeneous : Prop :=
∀ (i : ι) ⦃r : A⦄, r ∈ I → (DirectSum.decompose 𝒜 r i : A) ∈ I
#align ideal.is_homogeneous Ideal.IsHomogeneous
theorem Ideal.IsHomogeneous.mem_iff {I} (hI : Ideal.IsHomogeneous 𝒜 I) {x} :
x ∈ I ↔ ∀ i, (decompose 𝒜 x i : A) ∈ I := by
classical
refine ⟨fun hx i ↦ hI i hx, fun hx ↦ ?_⟩
rw [← DirectSum.sum_support_decompose 𝒜 x]
exact Ideal.sum_mem _ (fun i _ ↦ hx i)
/-- For any `Semiring A`, we collect the homogeneous ideals of `A` into a type. -/
structure HomogeneousIdeal extends Submodule A A where
is_homogeneous' : Ideal.IsHomogeneous 𝒜 toSubmodule
#align homogeneous_ideal HomogeneousIdeal
variable {𝒜}
/-- Converting a homogeneous ideal to an ideal. -/
def HomogeneousIdeal.toIdeal (I : HomogeneousIdeal 𝒜) : Ideal A :=
I.toSubmodule
#align homogeneous_ideal.to_ideal HomogeneousIdeal.toIdeal
theorem HomogeneousIdeal.isHomogeneous (I : HomogeneousIdeal 𝒜) : I.toIdeal.IsHomogeneous 𝒜 :=
I.is_homogeneous'
#align homogeneous_ideal.is_homogeneous HomogeneousIdeal.isHomogeneous
theorem HomogeneousIdeal.toIdeal_injective :
Function.Injective (HomogeneousIdeal.toIdeal : HomogeneousIdeal 𝒜 → Ideal A) :=
fun ⟨x, hx⟩ ⟨y, hy⟩ => fun (h : x = y) => by simp [h]
#align homogeneous_ideal.to_ideal_injective HomogeneousIdeal.toIdeal_injective
instance HomogeneousIdeal.setLike : SetLike (HomogeneousIdeal 𝒜) A where
coe I := I.toIdeal
coe_injective' _ _ h := HomogeneousIdeal.toIdeal_injective <| SetLike.coe_injective h
#align homogeneous_ideal.set_like HomogeneousIdeal.setLike
@[ext]
theorem HomogeneousIdeal.ext {I J : HomogeneousIdeal 𝒜} (h : I.toIdeal = J.toIdeal) : I = J :=
HomogeneousIdeal.toIdeal_injective h
#align homogeneous_ideal.ext HomogeneousIdeal.ext
theorem HomogeneousIdeal.ext' {I J : HomogeneousIdeal 𝒜} (h : ∀ i, ∀ x ∈ 𝒜 i, x ∈ I ↔ x ∈ J) :
I = J := by
ext
rw [I.isHomogeneous.mem_iff, J.isHomogeneous.mem_iff]
apply forall_congr'
exact fun i ↦ h i _ (decompose 𝒜 _ i).2
@[simp]
theorem HomogeneousIdeal.mem_iff {I : HomogeneousIdeal 𝒜} {x : A} : x ∈ I.toIdeal ↔ x ∈ I :=
Iff.rfl
#align homogeneous_ideal.mem_iff HomogeneousIdeal.mem_iff
end HomogeneousDef
section HomogeneousCore
variable [Semiring A]
variable [SetLike σ A] (𝒜 : ι → σ)
variable (I : Ideal A)
/-- For any `I : Ideal A`, not necessarily homogeneous, `I.homogeneousCore' 𝒜`
is the largest homogeneous ideal of `A` contained in `I`, as an ideal. -/
def Ideal.homogeneousCore' (I : Ideal A) : Ideal A :=
Ideal.span ((↑) '' (((↑) : Subtype (Homogeneous 𝒜) → A) ⁻¹' I))
#align ideal.homogeneous_core' Ideal.homogeneousCore'
theorem Ideal.homogeneousCore'_mono : Monotone (Ideal.homogeneousCore' 𝒜) :=
fun _ _ I_le_J => Ideal.span_mono <| Set.image_subset _ fun _ => @I_le_J _
#align ideal.homogeneous_core'_mono Ideal.homogeneousCore'_mono
theorem Ideal.homogeneousCore'_le : I.homogeneousCore' 𝒜 ≤ I :=
Ideal.span_le.2 <| image_preimage_subset _ _
#align ideal.homogeneous_core'_le Ideal.homogeneousCore'_le
end HomogeneousCore
section IsHomogeneousIdealDefs
variable [Semiring A]
variable [SetLike σ A] [AddSubmonoidClass σ A] (𝒜 : ι → σ)
variable [DecidableEq ι] [AddMonoid ι] [GradedRing 𝒜]
variable (I : Ideal A)
theorem Ideal.isHomogeneous_iff_forall_subset :
I.IsHomogeneous 𝒜 ↔ ∀ i, (I : Set A) ⊆ GradedRing.proj 𝒜 i ⁻¹' I :=
Iff.rfl
#align ideal.is_homogeneous_iff_forall_subset Ideal.isHomogeneous_iff_forall_subset
theorem Ideal.isHomogeneous_iff_subset_iInter :
I.IsHomogeneous 𝒜 ↔ (I : Set A) ⊆ ⋂ i, GradedRing.proj 𝒜 i ⁻¹' ↑I :=
subset_iInter_iff.symm
#align ideal.is_homogeneous_iff_subset_Inter Ideal.isHomogeneous_iff_subset_iInter
theorem Ideal.mul_homogeneous_element_mem_of_mem {I : Ideal A} (r x : A) (hx₁ : Homogeneous 𝒜 x)
(hx₂ : x ∈ I) (j : ι) : GradedRing.proj 𝒜 j (r * x) ∈ I := by
classical
rw [← DirectSum.sum_support_decompose 𝒜 r, Finset.sum_mul, map_sum]
apply Ideal.sum_mem
intro k _
obtain ⟨i, hi⟩ := hx₁
have mem₁ : (DirectSum.decompose 𝒜 r k : A) * x ∈ 𝒜 (k + i) :=
GradedMul.mul_mem (SetLike.coe_mem _) hi
erw [GradedRing.proj_apply, DirectSum.decompose_of_mem 𝒜 mem₁, coe_of_apply]
split_ifs
· exact I.mul_mem_left _ hx₂
· exact I.zero_mem
#align ideal.mul_homogeneous_element_mem_of_mem Ideal.mul_homogeneous_element_mem_of_mem
theorem Ideal.homogeneous_span (s : Set A) (h : ∀ x ∈ s, Homogeneous 𝒜 x) :
(Ideal.span s).IsHomogeneous 𝒜 := by
rintro i r hr
rw [Ideal.span, Finsupp.span_eq_range_total] at hr
rw [LinearMap.mem_range] at hr
obtain ⟨s, rfl⟩ := hr
rw [Finsupp.total_apply, Finsupp.sum, decompose_sum, DFinsupp.finset_sum_apply,
AddSubmonoidClass.coe_finset_sum]
refine Ideal.sum_mem _ ?_
rintro z hz1
rw [smul_eq_mul]
refine Ideal.mul_homogeneous_element_mem_of_mem 𝒜 (s z) z ?_ ?_ i
· rcases z with ⟨z, hz2⟩
apply h _ hz2
· exact Ideal.subset_span z.2
#align ideal.is_homogeneous_span Ideal.homogeneous_span
/-- For any `I : Ideal A`, not necessarily homogeneous, `I.homogeneousCore' 𝒜`
is the largest homogeneous ideal of `A` contained in `I`. -/
def Ideal.homogeneousCore : HomogeneousIdeal 𝒜 :=
⟨Ideal.homogeneousCore' 𝒜 I,
Ideal.homogeneous_span _ _ fun _ h => by
have := Subtype.image_preimage_coe (setOf (Homogeneous 𝒜)) (I : Set A)
exact (cast congr(_ ∈ $this) h).1⟩
#align ideal.homogeneous_core Ideal.homogeneousCore
theorem Ideal.homogeneousCore_mono : Monotone (Ideal.homogeneousCore 𝒜) :=
Ideal.homogeneousCore'_mono 𝒜
#align ideal.homogeneous_core_mono Ideal.homogeneousCore_mono
theorem Ideal.toIdeal_homogeneousCore_le : (I.homogeneousCore 𝒜).toIdeal ≤ I :=
Ideal.homogeneousCore'_le 𝒜 I
#align ideal.to_ideal_homogeneous_core_le Ideal.toIdeal_homogeneousCore_le
variable {𝒜 I}
theorem Ideal.mem_homogeneousCore_of_homogeneous_of_mem {x : A} (h : SetLike.Homogeneous 𝒜 x)
(hmem : x ∈ I) : x ∈ I.homogeneousCore 𝒜 :=
Ideal.subset_span ⟨⟨x, h⟩, hmem, rfl⟩
#align ideal.mem_homogeneous_core_of_is_homogeneous_of_mem Ideal.mem_homogeneousCore_of_homogeneous_of_mem
theorem Ideal.IsHomogeneous.toIdeal_homogeneousCore_eq_self (h : I.IsHomogeneous 𝒜) :
(I.homogeneousCore 𝒜).toIdeal = I := by
apply le_antisymm (I.homogeneousCore'_le 𝒜) _
intro x hx
classical
rw [← DirectSum.sum_support_decompose 𝒜 x]
exact Ideal.sum_mem _ fun j _ => Ideal.subset_span ⟨⟨_, homogeneous_coe _⟩, h _ hx, rfl⟩
#align ideal.is_homogeneous.to_ideal_homogeneous_core_eq_self Ideal.IsHomogeneous.toIdeal_homogeneousCore_eq_self
@[simp]
theorem HomogeneousIdeal.toIdeal_homogeneousCore_eq_self (I : HomogeneousIdeal 𝒜) :
I.toIdeal.homogeneousCore 𝒜 = I := by
ext1
convert Ideal.IsHomogeneous.toIdeal_homogeneousCore_eq_self I.isHomogeneous
#align homogeneous_ideal.to_ideal_homogeneous_core_eq_self HomogeneousIdeal.toIdeal_homogeneousCore_eq_self
variable (𝒜 I)
theorem Ideal.IsHomogeneous.iff_eq : I.IsHomogeneous 𝒜 ↔ (I.homogeneousCore 𝒜).toIdeal = I :=
⟨fun hI => hI.toIdeal_homogeneousCore_eq_self, fun hI => hI ▸ (Ideal.homogeneousCore 𝒜 I).2⟩
#align ideal.is_homogeneous.iff_eq Ideal.IsHomogeneous.iff_eq
theorem Ideal.IsHomogeneous.iff_exists :
I.IsHomogeneous 𝒜 ↔ ∃ S : Set (homogeneousSubmonoid 𝒜), I = Ideal.span ((↑) '' S) := by
rw [Ideal.IsHomogeneous.iff_eq, eq_comm]
exact ((Set.image_preimage.compose (Submodule.gi _ _).gc).exists_eq_l _).symm
#align ideal.is_homogeneous.iff_exists Ideal.IsHomogeneous.iff_exists
end IsHomogeneousIdealDefs
/-! ### Operations
In this section, we show that `Ideal.IsHomogeneous` is preserved by various notations, then use
these results to provide these notation typeclasses for `HomogeneousIdeal`. -/
section Operations
section Semiring
variable [Semiring A] [DecidableEq ι] [AddMonoid ι]
variable [SetLike σ A] [AddSubmonoidClass σ A] (𝒜 : ι → σ) [GradedRing 𝒜]
namespace Ideal.IsHomogeneous
theorem bot : Ideal.IsHomogeneous 𝒜 ⊥ := fun i r hr => by
simp only [Ideal.mem_bot] at hr
rw [hr, decompose_zero, zero_apply]
apply Ideal.zero_mem
#align ideal.is_homogeneous.bot Ideal.IsHomogeneous.bot
theorem top : Ideal.IsHomogeneous 𝒜 ⊤ := fun i r _ => by simp only [Submodule.mem_top]
#align ideal.is_homogeneous.top Ideal.IsHomogeneous.top
variable {𝒜}
theorem inf {I J : Ideal A} (HI : I.IsHomogeneous 𝒜) (HJ : J.IsHomogeneous 𝒜) :
(I ⊓ J).IsHomogeneous 𝒜 :=
fun _ _ hr => ⟨HI _ hr.1, HJ _ hr.2⟩
#align ideal.is_homogeneous.inf Ideal.IsHomogeneous.inf
theorem sup {I J : Ideal A} (HI : I.IsHomogeneous 𝒜) (HJ : J.IsHomogeneous 𝒜) :
(I ⊔ J).IsHomogeneous 𝒜 := by
rw [iff_exists] at HI HJ ⊢
obtain ⟨⟨s₁, rfl⟩, ⟨s₂, rfl⟩⟩ := HI, HJ
refine ⟨s₁ ∪ s₂, ?_⟩
rw [Set.image_union]
exact (Submodule.span_union _ _).symm
#align ideal.is_homogeneous.sup Ideal.IsHomogeneous.sup
protected theorem iSup {κ : Sort*} {f : κ → Ideal A} (h : ∀ i, (f i).IsHomogeneous 𝒜) :
(⨆ i, f i).IsHomogeneous 𝒜 := by
simp_rw [iff_exists] at h ⊢
choose s hs using h
refine ⟨⋃ i, s i, ?_⟩
simp_rw [Set.image_iUnion, Ideal.span_iUnion]
congr
exact funext hs
#align ideal.is_homogeneous.supr Ideal.IsHomogeneous.iSup
protected theorem iInf {κ : Sort*} {f : κ → Ideal A} (h : ∀ i, (f i).IsHomogeneous 𝒜) :
(⨅ i, f i).IsHomogeneous 𝒜 := by
intro i x hx
simp only [Ideal.mem_iInf] at hx ⊢
exact fun j => h _ _ (hx j)
#align ideal.is_homogeneous.infi Ideal.IsHomogeneous.iInf
theorem iSup₂ {κ : Sort*} {κ' : κ → Sort*} {f : ∀ i, κ' i → Ideal A}
(h : ∀ i j, (f i j).IsHomogeneous 𝒜) : (⨆ (i) (j), f i j).IsHomogeneous 𝒜 :=
IsHomogeneous.iSup fun i => IsHomogeneous.iSup <| h i
#align ideal.is_homogeneous.supr₂ Ideal.IsHomogeneous.iSup₂
theorem iInf₂ {κ : Sort*} {κ' : κ → Sort*} {f : ∀ i, κ' i → Ideal A}
(h : ∀ i j, (f i j).IsHomogeneous 𝒜) : (⨅ (i) (j), f i j).IsHomogeneous 𝒜 :=
IsHomogeneous.iInf fun i => IsHomogeneous.iInf <| h i
#align ideal.is_homogeneous.infi₂ Ideal.IsHomogeneous.iInf₂
theorem sSup {ℐ : Set (Ideal A)} (h : ∀ I ∈ ℐ, Ideal.IsHomogeneous 𝒜 I) :
(sSup ℐ).IsHomogeneous 𝒜 := by
rw [sSup_eq_iSup]
exact iSup₂ h
#align ideal.is_homogeneous.Sup Ideal.IsHomogeneous.sSup
theorem sInf {ℐ : Set (Ideal A)} (h : ∀ I ∈ ℐ, Ideal.IsHomogeneous 𝒜 I) :
(sInf ℐ).IsHomogeneous 𝒜 := by
rw [sInf_eq_iInf]
exact iInf₂ h
#align ideal.is_homogeneous.Inf Ideal.IsHomogeneous.sInf
end Ideal.IsHomogeneous
variable {𝒜}
namespace HomogeneousIdeal
instance : PartialOrder (HomogeneousIdeal 𝒜) :=
SetLike.instPartialOrder
instance : Top (HomogeneousIdeal 𝒜) :=
⟨⟨⊤, Ideal.IsHomogeneous.top 𝒜⟩⟩
instance : Bot (HomogeneousIdeal 𝒜) :=
⟨⟨⊥, Ideal.IsHomogeneous.bot 𝒜⟩⟩
instance : Sup (HomogeneousIdeal 𝒜) :=
⟨fun I J => ⟨_, I.isHomogeneous.sup J.isHomogeneous⟩⟩
instance : Inf (HomogeneousIdeal 𝒜) :=
⟨fun I J => ⟨_, I.isHomogeneous.inf J.isHomogeneous⟩⟩
instance : SupSet (HomogeneousIdeal 𝒜) :=
⟨fun S => ⟨⨆ s ∈ S, toIdeal s, Ideal.IsHomogeneous.iSup₂ fun s _ => s.isHomogeneous⟩⟩
instance : InfSet (HomogeneousIdeal 𝒜) :=
⟨fun S => ⟨⨅ s ∈ S, toIdeal s, Ideal.IsHomogeneous.iInf₂ fun s _ => s.isHomogeneous⟩⟩
@[simp]
theorem coe_top : ((⊤ : HomogeneousIdeal 𝒜) : Set A) = univ :=
rfl
#align homogeneous_ideal.coe_top HomogeneousIdeal.coe_top
@[simp]
theorem coe_bot : ((⊥ : HomogeneousIdeal 𝒜) : Set A) = 0 :=
rfl
#align homogeneous_ideal.coe_bot HomogeneousIdeal.coe_bot
@[simp]
theorem coe_sup (I J : HomogeneousIdeal 𝒜) : ↑(I ⊔ J) = (I + J : Set A) :=
Submodule.coe_sup _ _
#align homogeneous_ideal.coe_sup HomogeneousIdeal.coe_sup
@[simp]
theorem coe_inf (I J : HomogeneousIdeal 𝒜) : (↑(I ⊓ J) : Set A) = ↑I ∩ ↑J :=
rfl
#align homogeneous_ideal.coe_inf HomogeneousIdeal.coe_inf
@[simp]
theorem toIdeal_top : (⊤ : HomogeneousIdeal 𝒜).toIdeal = (⊤ : Ideal A) :=
rfl
#align homogeneous_ideal.to_ideal_top HomogeneousIdeal.toIdeal_top
@[simp]
theorem toIdeal_bot : (⊥ : HomogeneousIdeal 𝒜).toIdeal = (⊥ : Ideal A) :=
rfl
#align homogeneous_ideal.to_ideal_bot HomogeneousIdeal.toIdeal_bot
@[simp]
theorem toIdeal_sup (I J : HomogeneousIdeal 𝒜) : (I ⊔ J).toIdeal = I.toIdeal ⊔ J.toIdeal :=
rfl
#align homogeneous_ideal.to_ideal_sup HomogeneousIdeal.toIdeal_sup
@[simp]
theorem toIdeal_inf (I J : HomogeneousIdeal 𝒜) : (I ⊓ J).toIdeal = I.toIdeal ⊓ J.toIdeal :=
rfl
#align homogeneous_ideal.to_ideal_inf HomogeneousIdeal.toIdeal_inf
@[simp]
theorem toIdeal_sSup (ℐ : Set (HomogeneousIdeal 𝒜)) : (sSup ℐ).toIdeal = ⨆ s ∈ ℐ, toIdeal s :=
rfl
#align homogeneous_ideal.to_ideal_Sup HomogeneousIdeal.toIdeal_sSup
@[simp]
theorem toIdeal_sInf (ℐ : Set (HomogeneousIdeal 𝒜)) : (sInf ℐ).toIdeal = ⨅ s ∈ ℐ, toIdeal s :=
rfl
#align homogeneous_ideal.to_ideal_Inf HomogeneousIdeal.toIdeal_sInf
@[simp]
theorem toIdeal_iSup {κ : Sort*} (s : κ → HomogeneousIdeal 𝒜) :
(⨆ i, s i).toIdeal = ⨆ i, (s i).toIdeal := by
rw [iSup, toIdeal_sSup, iSup_range]
#align homogeneous_ideal.to_ideal_supr HomogeneousIdeal.toIdeal_iSup
@[simp]
theorem toIdeal_iInf {κ : Sort*} (s : κ → HomogeneousIdeal 𝒜) :
(⨅ i, s i).toIdeal = ⨅ i, (s i).toIdeal := by
rw [iInf, toIdeal_sInf, iInf_range]
#align homogeneous_ideal.to_ideal_infi HomogeneousIdeal.toIdeal_iInf
-- @[simp] -- Porting note (#10618): simp can prove this
theorem toIdeal_iSup₂ {κ : Sort*} {κ' : κ → Sort*} (s : ∀ i, κ' i → HomogeneousIdeal 𝒜) :
(⨆ (i) (j), s i j).toIdeal = ⨆ (i) (j), (s i j).toIdeal := by
simp_rw [toIdeal_iSup]
#align homogeneous_ideal.to_ideal_supr₂ HomogeneousIdeal.toIdeal_iSup₂
-- @[simp] -- Porting note (#10618): simp can prove this
theorem toIdeal_iInf₂ {κ : Sort*} {κ' : κ → Sort*} (s : ∀ i, κ' i → HomogeneousIdeal 𝒜) :
(⨅ (i) (j), s i j).toIdeal = ⨅ (i) (j), (s i j).toIdeal := by
simp_rw [toIdeal_iInf]
#align homogeneous_ideal.to_ideal_infi₂ HomogeneousIdeal.toIdeal_iInf₂
@[simp]
theorem eq_top_iff (I : HomogeneousIdeal 𝒜) : I = ⊤ ↔ I.toIdeal = ⊤ :=
toIdeal_injective.eq_iff.symm
#align homogeneous_ideal.eq_top_iff HomogeneousIdeal.eq_top_iff
@[simp]
theorem eq_bot_iff (I : HomogeneousIdeal 𝒜) : I = ⊥ ↔ I.toIdeal = ⊥ :=
toIdeal_injective.eq_iff.symm
#align homogeneous_ideal.eq_bot_iff HomogeneousIdeal.eq_bot_iff
instance completeLattice : CompleteLattice (HomogeneousIdeal 𝒜) :=
toIdeal_injective.completeLattice _ toIdeal_sup toIdeal_inf toIdeal_sSup toIdeal_sInf toIdeal_top
toIdeal_bot
instance : Add (HomogeneousIdeal 𝒜) :=
⟨(· ⊔ ·)⟩
@[simp]
theorem toIdeal_add (I J : HomogeneousIdeal 𝒜) : (I + J).toIdeal = I.toIdeal + J.toIdeal :=
rfl
#align homogeneous_ideal.to_ideal_add HomogeneousIdeal.toIdeal_add
instance : Inhabited (HomogeneousIdeal 𝒜) where default := ⊥
end HomogeneousIdeal
end Semiring
section CommSemiring
variable [CommSemiring A]
variable [DecidableEq ι] [AddMonoid ι]
variable [SetLike σ A] [AddSubmonoidClass σ A] {𝒜 : ι → σ} [GradedRing 𝒜]
variable (I : Ideal A)
theorem Ideal.IsHomogeneous.mul {I J : Ideal A} (HI : I.IsHomogeneous 𝒜) (HJ : J.IsHomogeneous 𝒜) :
(I * J).IsHomogeneous 𝒜 := by
rw [Ideal.IsHomogeneous.iff_exists] at HI HJ ⊢
obtain ⟨⟨s₁, rfl⟩, ⟨s₂, rfl⟩⟩ := HI, HJ
rw [Ideal.span_mul_span']
exact ⟨s₁ * s₂, congr_arg _ <| (Set.image_mul (homogeneousSubmonoid 𝒜).subtype).symm⟩
#align ideal.is_homogeneous.mul Ideal.IsHomogeneous.mul
instance : Mul (HomogeneousIdeal 𝒜) where
mul I J := ⟨I.toIdeal * J.toIdeal, I.isHomogeneous.mul J.isHomogeneous⟩
@[simp]
theorem HomogeneousIdeal.toIdeal_mul (I J : HomogeneousIdeal 𝒜) :
(I * J).toIdeal = I.toIdeal * J.toIdeal :=
rfl
#align homogeneous_ideal.to_ideal_mul HomogeneousIdeal.toIdeal_mul
end CommSemiring
end Operations
/-! ### Homogeneous core
Note that many results about the homogeneous core came earlier in this file, as they are helpful
for building the lattice structure. -/
section homogeneousCore
open HomogeneousIdeal
variable [Semiring A] [DecidableEq ι] [AddMonoid ι]
variable [SetLike σ A] [AddSubmonoidClass σ A] (𝒜 : ι → σ) [GradedRing 𝒜]
variable (I : Ideal A)
theorem Ideal.homogeneousCore.gc : GaloisConnection toIdeal (Ideal.homogeneousCore 𝒜) := fun I _ =>
⟨fun H => I.toIdeal_homogeneousCore_eq_self ▸ Ideal.homogeneousCore_mono 𝒜 H,
fun H => le_trans H (Ideal.homogeneousCore'_le _ _)⟩
#align ideal.homogeneous_core.gc Ideal.homogeneousCore.gc
/-- `toIdeal : HomogeneousIdeal 𝒜 → Ideal A` and `Ideal.homogeneousCore 𝒜` forms a galois
coinsertion. -/
def Ideal.homogeneousCore.gi : GaloisCoinsertion toIdeal (Ideal.homogeneousCore 𝒜) where
choice I HI :=
⟨I, le_antisymm (I.toIdeal_homogeneousCore_le 𝒜) HI ▸ HomogeneousIdeal.isHomogeneous _⟩
gc := Ideal.homogeneousCore.gc 𝒜
u_l_le _ := Ideal.homogeneousCore'_le _ _
choice_eq I H := le_antisymm H (I.toIdeal_homogeneousCore_le _)
#align ideal.homogeneous_core.gi Ideal.homogeneousCore.gi
theorem Ideal.homogeneousCore_eq_sSup :
I.homogeneousCore 𝒜 = sSup { J : HomogeneousIdeal 𝒜 | J.toIdeal ≤ I } :=
Eq.symm <| IsLUB.sSup_eq <| (Ideal.homogeneousCore.gc 𝒜).isGreatest_u.isLUB
#align ideal.homogeneous_core_eq_Sup Ideal.homogeneousCore_eq_sSup
theorem Ideal.homogeneousCore'_eq_sSup :
I.homogeneousCore' 𝒜 = sSup { J : Ideal A | J.IsHomogeneous 𝒜 ∧ J ≤ I } := by
refine (IsLUB.sSup_eq ?_).symm
apply IsGreatest.isLUB
have coe_mono : Monotone (toIdeal : HomogeneousIdeal 𝒜 → Ideal A) := fun x y => id
convert coe_mono.map_isGreatest (Ideal.homogeneousCore.gc 𝒜).isGreatest_u using 1
ext x
rw [mem_image, mem_setOf_eq]
refine ⟨fun hI => ⟨⟨x, hI.1⟩, ⟨hI.2, rfl⟩⟩, ?_⟩
rintro ⟨x, ⟨hx, rfl⟩⟩
exact ⟨x.isHomogeneous, hx⟩
#align ideal.homogeneous_core'_eq_Sup Ideal.homogeneousCore'_eq_sSup
end homogeneousCore
/-! ### Homogeneous hulls -/
section HomogeneousHull
open HomogeneousIdeal
variable [Semiring A] [DecidableEq ι] [AddMonoid ι]
variable [SetLike σ A] [AddSubmonoidClass σ A] (𝒜 : ι → σ) [GradedRing 𝒜]
variable (I : Ideal A)
/-- For any `I : Ideal A`, not necessarily homogeneous, `I.homogeneousHull 𝒜` is
the smallest homogeneous ideal containing `I`. -/
def Ideal.homogeneousHull : HomogeneousIdeal 𝒜 :=
⟨Ideal.span { r : A | ∃ (i : ι) (x : I), (DirectSum.decompose 𝒜 (x : A) i : A) = r }, by
refine Ideal.homogeneous_span _ _ fun x hx => ?_
obtain ⟨i, x, rfl⟩ := hx
apply SetLike.homogeneous_coe⟩
#align ideal.homogeneous_hull Ideal.homogeneousHull
theorem Ideal.le_toIdeal_homogeneousHull : I ≤ (Ideal.homogeneousHull 𝒜 I).toIdeal := by
intro r hr
classical
rw [← DirectSum.sum_support_decompose 𝒜 r]
refine Ideal.sum_mem _ ?_
intro j _
apply Ideal.subset_span
use j
use ⟨r, hr⟩
#align ideal.le_to_ideal_homogeneous_hull Ideal.le_toIdeal_homogeneousHull
theorem Ideal.homogeneousHull_mono : Monotone (Ideal.homogeneousHull 𝒜) := fun I J I_le_J => by
apply Ideal.span_mono
rintro r ⟨hr1, ⟨x, hx⟩, rfl⟩
exact ⟨hr1, ⟨⟨x, I_le_J hx⟩, rfl⟩⟩
#align ideal.homogeneous_hull_mono Ideal.homogeneousHull_mono
variable {I 𝒜}
| Mathlib/RingTheory/GradedAlgebra/HomogeneousIdeal.lean | 565 | 570 | theorem Ideal.IsHomogeneous.toIdeal_homogeneousHull_eq_self (h : I.IsHomogeneous 𝒜) :
(Ideal.homogeneousHull 𝒜 I).toIdeal = I := by |
apply le_antisymm _ (Ideal.le_toIdeal_homogeneousHull _ _)
apply Ideal.span_le.2
rintro _ ⟨i, x, rfl⟩
exact h _ x.prop
|
/-
Copyright (c) 2021 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.Topology.ContinuousFunction.Bounded
import Mathlib.Topology.UniformSpace.Compact
import Mathlib.Topology.CompactOpen
import Mathlib.Topology.Sets.Compacts
import Mathlib.Analysis.Normed.Group.InfiniteSum
#align_import topology.continuous_function.compact from "leanprover-community/mathlib"@"d3af0609f6db8691dffdc3e1fb7feb7da72698f2"
/-!
# Continuous functions on a compact space
Continuous functions `C(α, β)` from a compact space `α` to a metric space `β`
are automatically bounded, and so acquire various structures inherited from `α →ᵇ β`.
This file transfers these structures, and restates some lemmas
characterising these structures.
If you need a lemma which is proved about `α →ᵇ β` but not for `C(α, β)` when `α` is compact,
you should restate it here. You can also use
`ContinuousMap.equivBoundedOfCompact` to move functions back and forth.
-/
noncomputable section
open scoped Classical
open Topology NNReal BoundedContinuousFunction
open Set Filter Metric
open BoundedContinuousFunction
namespace ContinuousMap
variable {α β E : Type*} [TopologicalSpace α] [CompactSpace α] [MetricSpace β]
[NormedAddCommGroup E]
section
variable (α β)
/-- When `α` is compact, the bounded continuous maps `α →ᵇ β` are
equivalent to `C(α, β)`.
-/
@[simps (config := .asFn)]
def equivBoundedOfCompact : C(α, β) ≃ (α →ᵇ β) :=
⟨mkOfCompact, BoundedContinuousFunction.toContinuousMap, fun f => by
ext
rfl, fun f => by
ext
rfl⟩
#align continuous_map.equiv_bounded_of_compact ContinuousMap.equivBoundedOfCompact
theorem uniformInducing_equivBoundedOfCompact : UniformInducing (equivBoundedOfCompact α β) :=
UniformInducing.mk'
(by
simp only [hasBasis_compactConvergenceUniformity.mem_iff, uniformity_basis_dist_le.mem_iff]
exact fun s =>
⟨fun ⟨⟨a, b⟩, ⟨_, ⟨ε, hε, hb⟩⟩, hs⟩ =>
⟨{ p | ∀ x, (p.1 x, p.2 x) ∈ b }, ⟨ε, hε, fun _ h x => hb ((dist_le hε.le).mp h x)⟩,
fun f g h => hs fun x _ => h x⟩,
fun ⟨_, ⟨ε, hε, ht⟩, hs⟩ =>
⟨⟨Set.univ, { p | dist p.1 p.2 ≤ ε }⟩, ⟨isCompact_univ, ⟨ε, hε, fun _ h => h⟩⟩,
fun ⟨f, g⟩ h => hs _ _ (ht ((dist_le hε.le).mpr fun x => h x (mem_univ x)))⟩⟩)
#align continuous_map.uniform_inducing_equiv_bounded_of_compact ContinuousMap.uniformInducing_equivBoundedOfCompact
theorem uniformEmbedding_equivBoundedOfCompact : UniformEmbedding (equivBoundedOfCompact α β) :=
{ uniformInducing_equivBoundedOfCompact α β with inj := (equivBoundedOfCompact α β).injective }
#align continuous_map.uniform_embedding_equiv_bounded_of_compact ContinuousMap.uniformEmbedding_equivBoundedOfCompact
/-- When `α` is compact, the bounded continuous maps `α →ᵇ 𝕜` are
additively equivalent to `C(α, 𝕜)`.
-/
-- Porting note: the following `simps` received a "maximum recursion depth" error
-- @[simps! (config := .asFn) apply symm_apply]
def addEquivBoundedOfCompact [AddMonoid β] [LipschitzAdd β] : C(α, β) ≃+ (α →ᵇ β) :=
({ toContinuousMapAddHom α β, (equivBoundedOfCompact α β).symm with } : (α →ᵇ β) ≃+ C(α, β)).symm
#align continuous_map.add_equiv_bounded_of_compact ContinuousMap.addEquivBoundedOfCompact
-- Porting note: added this `simp` lemma manually because of the `simps` error above
@[simp]
theorem addEquivBoundedOfCompact_symm_apply [AddMonoid β] [LipschitzAdd β] :
⇑((addEquivBoundedOfCompact α β).symm) = toContinuousMapAddHom α β :=
rfl
-- Porting note: added this `simp` lemma manually because of the `simps` error above
@[simp]
theorem addEquivBoundedOfCompact_apply [AddMonoid β] [LipschitzAdd β] :
⇑(addEquivBoundedOfCompact α β) = mkOfCompact :=
rfl
instance metricSpace : MetricSpace C(α, β) :=
(uniformEmbedding_equivBoundedOfCompact α β).comapMetricSpace _
#align continuous_map.metric_space ContinuousMap.metricSpace
/-- When `α` is compact, and `β` is a metric space, the bounded continuous maps `α →ᵇ β` are
isometric to `C(α, β)`.
-/
@[simps! (config := .asFn) toEquiv apply symm_apply]
def isometryEquivBoundedOfCompact : C(α, β) ≃ᵢ (α →ᵇ β) where
isometry_toFun _ _ := rfl
toEquiv := equivBoundedOfCompact α β
#align continuous_map.isometry_equiv_bounded_of_compact ContinuousMap.isometryEquivBoundedOfCompact
end
@[simp]
theorem _root_.BoundedContinuousFunction.dist_mkOfCompact (f g : C(α, β)) :
dist (mkOfCompact f) (mkOfCompact g) = dist f g :=
rfl
#align bounded_continuous_function.dist_mk_of_compact BoundedContinuousFunction.dist_mkOfCompact
@[simp]
theorem _root_.BoundedContinuousFunction.dist_toContinuousMap (f g : α →ᵇ β) :
dist f.toContinuousMap g.toContinuousMap = dist f g :=
rfl
#align bounded_continuous_function.dist_to_continuous_map BoundedContinuousFunction.dist_toContinuousMap
open BoundedContinuousFunction
section
variable {f g : C(α, β)} {C : ℝ}
/-- The pointwise distance is controlled by the distance between functions, by definition. -/
theorem dist_apply_le_dist (x : α) : dist (f x) (g x) ≤ dist f g := by
simp only [← dist_mkOfCompact, dist_coe_le_dist, ← mkOfCompact_apply]
#align continuous_map.dist_apply_le_dist ContinuousMap.dist_apply_le_dist
/-- The distance between two functions is controlled by the supremum of the pointwise distances. -/
theorem dist_le (C0 : (0 : ℝ) ≤ C) : dist f g ≤ C ↔ ∀ x : α, dist (f x) (g x) ≤ C := by
simp only [← dist_mkOfCompact, BoundedContinuousFunction.dist_le C0, mkOfCompact_apply]
#align continuous_map.dist_le ContinuousMap.dist_le
theorem dist_le_iff_of_nonempty [Nonempty α] : dist f g ≤ C ↔ ∀ x, dist (f x) (g x) ≤ C := by
simp only [← dist_mkOfCompact, BoundedContinuousFunction.dist_le_iff_of_nonempty,
mkOfCompact_apply]
#align continuous_map.dist_le_iff_of_nonempty ContinuousMap.dist_le_iff_of_nonempty
| Mathlib/Topology/ContinuousFunction/Compact.lean | 146 | 147 | theorem dist_lt_iff_of_nonempty [Nonempty α] : dist f g < C ↔ ∀ x : α, dist (f x) (g x) < C := by |
simp only [← dist_mkOfCompact, dist_lt_iff_of_nonempty_compact, mkOfCompact_apply]
|
/-
Copyright (c) 2019 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sébastien Gouëzel
-/
import Mathlib.Analysis.SpecificLimits.Basic
import Mathlib.Topology.MetricSpace.IsometricSMul
#align_import topology.metric_space.hausdorff_distance from "leanprover-community/mathlib"@"bc91ed7093bf098d253401e69df601fc33dde156"
/-!
# Hausdorff distance
The Hausdorff distance on subsets of a metric (or emetric) space.
Given two subsets `s` and `t` of a metric space, their Hausdorff distance is the smallest `d`
such that any point `s` is within `d` of a point in `t`, and conversely. This quantity
is often infinite (think of `s` bounded and `t` unbounded), and therefore better
expressed in the setting of emetric spaces.
## Main definitions
This files introduces:
* `EMetric.infEdist x s`, the infimum edistance of a point `x` to a set `s` in an emetric space
* `EMetric.hausdorffEdist s t`, the Hausdorff edistance of two sets in an emetric space
* Versions of these notions on metric spaces, called respectively `Metric.infDist`
and `Metric.hausdorffDist`
## Main results
* `infEdist_closure`: the edistance to a set and its closure coincide
* `EMetric.mem_closure_iff_infEdist_zero`: a point `x` belongs to the closure of `s` iff
`infEdist x s = 0`
* `IsCompact.exists_infEdist_eq_edist`: if `s` is compact and non-empty, there exists a point `y`
which attains this edistance
* `IsOpen.exists_iUnion_isClosed`: every open set `U` can be written as the increasing union
of countably many closed subsets of `U`
* `hausdorffEdist_closure`: replacing a set by its closure does not change the Hausdorff edistance
* `hausdorffEdist_zero_iff_closure_eq_closure`: two sets have Hausdorff edistance zero
iff their closures coincide
* the Hausdorff edistance is symmetric and satisfies the triangle inequality
* in particular, closed sets in an emetric space are an emetric space
(this is shown in `EMetricSpace.closeds.emetricspace`)
* versions of these notions on metric spaces
* `hausdorffEdist_ne_top_of_nonempty_of_bounded`: if two sets in a metric space
are nonempty and bounded in a metric space, they are at finite Hausdorff edistance.
## Tags
metric space, Hausdorff distance
-/
noncomputable section
open NNReal ENNReal Topology Set Filter Pointwise Bornology
universe u v w
variable {ι : Sort*} {α : Type u} {β : Type v}
namespace EMetric
section InfEdist
variable [PseudoEMetricSpace α] [PseudoEMetricSpace β] {x y : α} {s t : Set α} {Φ : α → β}
/-! ### Distance of a point to a set as a function into `ℝ≥0∞`. -/
/-- The minimal edistance of a point to a set -/
def infEdist (x : α) (s : Set α) : ℝ≥0∞ :=
⨅ y ∈ s, edist x y
#align emetric.inf_edist EMetric.infEdist
@[simp]
theorem infEdist_empty : infEdist x ∅ = ∞ :=
iInf_emptyset
#align emetric.inf_edist_empty EMetric.infEdist_empty
theorem le_infEdist {d} : d ≤ infEdist x s ↔ ∀ y ∈ s, d ≤ edist x y := by
simp only [infEdist, le_iInf_iff]
#align emetric.le_inf_edist EMetric.le_infEdist
/-- The edist to a union is the minimum of the edists -/
@[simp]
theorem infEdist_union : infEdist x (s ∪ t) = infEdist x s ⊓ infEdist x t :=
iInf_union
#align emetric.inf_edist_union EMetric.infEdist_union
@[simp]
theorem infEdist_iUnion (f : ι → Set α) (x : α) : infEdist x (⋃ i, f i) = ⨅ i, infEdist x (f i) :=
iInf_iUnion f _
#align emetric.inf_edist_Union EMetric.infEdist_iUnion
lemma infEdist_biUnion {ι : Type*} (f : ι → Set α) (I : Set ι) (x : α) :
infEdist x (⋃ i ∈ I, f i) = ⨅ i ∈ I, infEdist x (f i) := by simp only [infEdist_iUnion]
/-- The edist to a singleton is the edistance to the single point of this singleton -/
@[simp]
theorem infEdist_singleton : infEdist x {y} = edist x y :=
iInf_singleton
#align emetric.inf_edist_singleton EMetric.infEdist_singleton
/-- The edist to a set is bounded above by the edist to any of its points -/
theorem infEdist_le_edist_of_mem (h : y ∈ s) : infEdist x s ≤ edist x y :=
iInf₂_le y h
#align emetric.inf_edist_le_edist_of_mem EMetric.infEdist_le_edist_of_mem
/-- If a point `x` belongs to `s`, then its edist to `s` vanishes -/
theorem infEdist_zero_of_mem (h : x ∈ s) : infEdist x s = 0 :=
nonpos_iff_eq_zero.1 <| @edist_self _ _ x ▸ infEdist_le_edist_of_mem h
#align emetric.inf_edist_zero_of_mem EMetric.infEdist_zero_of_mem
/-- The edist is antitone with respect to inclusion. -/
theorem infEdist_anti (h : s ⊆ t) : infEdist x t ≤ infEdist x s :=
iInf_le_iInf_of_subset h
#align emetric.inf_edist_anti EMetric.infEdist_anti
/-- The edist to a set is `< r` iff there exists a point in the set at edistance `< r` -/
theorem infEdist_lt_iff {r : ℝ≥0∞} : infEdist x s < r ↔ ∃ y ∈ s, edist x y < r := by
simp_rw [infEdist, iInf_lt_iff, exists_prop]
#align emetric.inf_edist_lt_iff EMetric.infEdist_lt_iff
/-- The edist of `x` to `s` is bounded by the sum of the edist of `y` to `s` and
the edist from `x` to `y` -/
theorem infEdist_le_infEdist_add_edist : infEdist x s ≤ infEdist y s + edist x y :=
calc
⨅ z ∈ s, edist x z ≤ ⨅ z ∈ s, edist y z + edist x y :=
iInf₂_mono fun z _ => (edist_triangle _ _ _).trans_eq (add_comm _ _)
_ = (⨅ z ∈ s, edist y z) + edist x y := by simp only [ENNReal.iInf_add]
#align emetric.inf_edist_le_inf_edist_add_edist EMetric.infEdist_le_infEdist_add_edist
theorem infEdist_le_edist_add_infEdist : infEdist x s ≤ edist x y + infEdist y s := by
rw [add_comm]
exact infEdist_le_infEdist_add_edist
#align emetric.inf_edist_le_edist_add_inf_edist EMetric.infEdist_le_edist_add_infEdist
theorem edist_le_infEdist_add_ediam (hy : y ∈ s) : edist x y ≤ infEdist x s + diam s := by
simp_rw [infEdist, ENNReal.iInf_add]
refine le_iInf₂ fun i hi => ?_
calc
edist x y ≤ edist x i + edist i y := edist_triangle _ _ _
_ ≤ edist x i + diam s := add_le_add le_rfl (edist_le_diam_of_mem hi hy)
#align emetric.edist_le_inf_edist_add_ediam EMetric.edist_le_infEdist_add_ediam
/-- The edist to a set depends continuously on the point -/
@[continuity]
theorem continuous_infEdist : Continuous fun x => infEdist x s :=
continuous_of_le_add_edist 1 (by simp) <| by
simp only [one_mul, infEdist_le_infEdist_add_edist, forall₂_true_iff]
#align emetric.continuous_inf_edist EMetric.continuous_infEdist
/-- The edist to a set and to its closure coincide -/
theorem infEdist_closure : infEdist x (closure s) = infEdist x s := by
refine le_antisymm (infEdist_anti subset_closure) ?_
refine ENNReal.le_of_forall_pos_le_add fun ε εpos h => ?_
have ε0 : 0 < (ε / 2 : ℝ≥0∞) := by simpa [pos_iff_ne_zero] using εpos
have : infEdist x (closure s) < infEdist x (closure s) + ε / 2 :=
ENNReal.lt_add_right h.ne ε0.ne'
obtain ⟨y : α, ycs : y ∈ closure s, hy : edist x y < infEdist x (closure s) + ↑ε / 2⟩ :=
infEdist_lt_iff.mp this
obtain ⟨z : α, zs : z ∈ s, dyz : edist y z < ↑ε / 2⟩ := EMetric.mem_closure_iff.1 ycs (ε / 2) ε0
calc
infEdist x s ≤ edist x z := infEdist_le_edist_of_mem zs
_ ≤ edist x y + edist y z := edist_triangle _ _ _
_ ≤ infEdist x (closure s) + ε / 2 + ε / 2 := add_le_add (le_of_lt hy) (le_of_lt dyz)
_ = infEdist x (closure s) + ↑ε := by rw [add_assoc, ENNReal.add_halves]
#align emetric.inf_edist_closure EMetric.infEdist_closure
/-- A point belongs to the closure of `s` iff its infimum edistance to this set vanishes -/
theorem mem_closure_iff_infEdist_zero : x ∈ closure s ↔ infEdist x s = 0 :=
⟨fun h => by
rw [← infEdist_closure]
exact infEdist_zero_of_mem h,
fun h =>
EMetric.mem_closure_iff.2 fun ε εpos => infEdist_lt_iff.mp <| by rwa [h]⟩
#align emetric.mem_closure_iff_inf_edist_zero EMetric.mem_closure_iff_infEdist_zero
/-- Given a closed set `s`, a point belongs to `s` iff its infimum edistance to this set vanishes -/
theorem mem_iff_infEdist_zero_of_closed (h : IsClosed s) : x ∈ s ↔ infEdist x s = 0 := by
rw [← mem_closure_iff_infEdist_zero, h.closure_eq]
#align emetric.mem_iff_inf_edist_zero_of_closed EMetric.mem_iff_infEdist_zero_of_closed
/-- The infimum edistance of a point to a set is positive if and only if the point is not in the
closure of the set. -/
theorem infEdist_pos_iff_not_mem_closure {x : α} {E : Set α} :
0 < infEdist x E ↔ x ∉ closure E := by
rw [mem_closure_iff_infEdist_zero, pos_iff_ne_zero]
#align emetric.inf_edist_pos_iff_not_mem_closure EMetric.infEdist_pos_iff_not_mem_closure
theorem infEdist_closure_pos_iff_not_mem_closure {x : α} {E : Set α} :
0 < infEdist x (closure E) ↔ x ∉ closure E := by
rw [infEdist_closure, infEdist_pos_iff_not_mem_closure]
#align emetric.inf_edist_closure_pos_iff_not_mem_closure EMetric.infEdist_closure_pos_iff_not_mem_closure
theorem exists_real_pos_lt_infEdist_of_not_mem_closure {x : α} {E : Set α} (h : x ∉ closure E) :
∃ ε : ℝ, 0 < ε ∧ ENNReal.ofReal ε < infEdist x E := by
rw [← infEdist_pos_iff_not_mem_closure, ENNReal.lt_iff_exists_real_btwn] at h
rcases h with ⟨ε, ⟨_, ⟨ε_pos, ε_lt⟩⟩⟩
exact ⟨ε, ⟨ENNReal.ofReal_pos.mp ε_pos, ε_lt⟩⟩
#align emetric.exists_real_pos_lt_inf_edist_of_not_mem_closure EMetric.exists_real_pos_lt_infEdist_of_not_mem_closure
theorem disjoint_closedBall_of_lt_infEdist {r : ℝ≥0∞} (h : r < infEdist x s) :
Disjoint (closedBall x r) s := by
rw [disjoint_left]
intro y hy h'y
apply lt_irrefl (infEdist x s)
calc
infEdist x s ≤ edist x y := infEdist_le_edist_of_mem h'y
_ ≤ r := by rwa [mem_closedBall, edist_comm] at hy
_ < infEdist x s := h
#align emetric.disjoint_closed_ball_of_lt_inf_edist EMetric.disjoint_closedBall_of_lt_infEdist
/-- The infimum edistance is invariant under isometries -/
theorem infEdist_image (hΦ : Isometry Φ) : infEdist (Φ x) (Φ '' t) = infEdist x t := by
simp only [infEdist, iInf_image, hΦ.edist_eq]
#align emetric.inf_edist_image EMetric.infEdist_image
@[to_additive (attr := simp)]
theorem infEdist_smul {M} [SMul M α] [IsometricSMul M α] (c : M) (x : α) (s : Set α) :
infEdist (c • x) (c • s) = infEdist x s :=
infEdist_image (isometry_smul _ _)
#align emetric.inf_edist_smul EMetric.infEdist_smul
#align emetric.inf_edist_vadd EMetric.infEdist_vadd
theorem _root_.IsOpen.exists_iUnion_isClosed {U : Set α} (hU : IsOpen U) :
∃ F : ℕ → Set α, (∀ n, IsClosed (F n)) ∧ (∀ n, F n ⊆ U) ∧ ⋃ n, F n = U ∧ Monotone F := by
obtain ⟨a, a_pos, a_lt_one⟩ : ∃ a : ℝ≥0∞, 0 < a ∧ a < 1 := exists_between zero_lt_one
let F := fun n : ℕ => (fun x => infEdist x Uᶜ) ⁻¹' Ici (a ^ n)
have F_subset : ∀ n, F n ⊆ U := fun n x hx ↦ by
by_contra h
have : infEdist x Uᶜ ≠ 0 := ((ENNReal.pow_pos a_pos _).trans_le hx).ne'
exact this (infEdist_zero_of_mem h)
refine ⟨F, fun n => IsClosed.preimage continuous_infEdist isClosed_Ici, F_subset, ?_, ?_⟩
· show ⋃ n, F n = U
refine Subset.antisymm (by simp only [iUnion_subset_iff, F_subset, forall_const]) fun x hx => ?_
have : ¬x ∈ Uᶜ := by simpa using hx
rw [mem_iff_infEdist_zero_of_closed hU.isClosed_compl] at this
have B : 0 < infEdist x Uᶜ := by simpa [pos_iff_ne_zero] using this
have : Filter.Tendsto (fun n => a ^ n) atTop (𝓝 0) :=
ENNReal.tendsto_pow_atTop_nhds_zero_of_lt_one a_lt_one
rcases ((tendsto_order.1 this).2 _ B).exists with ⟨n, hn⟩
simp only [mem_iUnion, mem_Ici, mem_preimage]
exact ⟨n, hn.le⟩
show Monotone F
intro m n hmn x hx
simp only [F, mem_Ici, mem_preimage] at hx ⊢
apply le_trans (pow_le_pow_right_of_le_one' a_lt_one.le hmn) hx
#align is_open.exists_Union_is_closed IsOpen.exists_iUnion_isClosed
theorem _root_.IsCompact.exists_infEdist_eq_edist (hs : IsCompact s) (hne : s.Nonempty) (x : α) :
∃ y ∈ s, infEdist x s = edist x y := by
have A : Continuous fun y => edist x y := continuous_const.edist continuous_id
obtain ⟨y, ys, hy⟩ := hs.exists_isMinOn hne A.continuousOn
exact ⟨y, ys, le_antisymm (infEdist_le_edist_of_mem ys) (by rwa [le_infEdist])⟩
#align is_compact.exists_inf_edist_eq_edist IsCompact.exists_infEdist_eq_edist
theorem exists_pos_forall_lt_edist (hs : IsCompact s) (ht : IsClosed t) (hst : Disjoint s t) :
∃ r : ℝ≥0, 0 < r ∧ ∀ x ∈ s, ∀ y ∈ t, (r : ℝ≥0∞) < edist x y := by
rcases s.eq_empty_or_nonempty with (rfl | hne)
· use 1
simp
obtain ⟨x, hx, h⟩ := hs.exists_isMinOn hne continuous_infEdist.continuousOn
have : 0 < infEdist x t :=
pos_iff_ne_zero.2 fun H => hst.le_bot ⟨hx, (mem_iff_infEdist_zero_of_closed ht).mpr H⟩
rcases ENNReal.lt_iff_exists_nnreal_btwn.1 this with ⟨r, h₀, hr⟩
exact ⟨r, ENNReal.coe_pos.mp h₀, fun y hy z hz => hr.trans_le <| le_infEdist.1 (h hy) z hz⟩
#align emetric.exists_pos_forall_lt_edist EMetric.exists_pos_forall_lt_edist
end InfEdist
/-! ### The Hausdorff distance as a function into `ℝ≥0∞`. -/
/-- The Hausdorff edistance between two sets is the smallest `r` such that each set
is contained in the `r`-neighborhood of the other one -/
irreducible_def hausdorffEdist {α : Type u} [PseudoEMetricSpace α] (s t : Set α) : ℝ≥0∞ :=
(⨆ x ∈ s, infEdist x t) ⊔ ⨆ y ∈ t, infEdist y s
#align emetric.Hausdorff_edist EMetric.hausdorffEdist
#align emetric.Hausdorff_edist_def EMetric.hausdorffEdist_def
section HausdorffEdist
variable [PseudoEMetricSpace α] [PseudoEMetricSpace β] {x y : α} {s t u : Set α} {Φ : α → β}
/-- The Hausdorff edistance of a set to itself vanishes. -/
@[simp]
theorem hausdorffEdist_self : hausdorffEdist s s = 0 := by
simp only [hausdorffEdist_def, sup_idem, ENNReal.iSup_eq_zero]
exact fun x hx => infEdist_zero_of_mem hx
#align emetric.Hausdorff_edist_self EMetric.hausdorffEdist_self
/-- The Haudorff edistances of `s` to `t` and of `t` to `s` coincide. -/
theorem hausdorffEdist_comm : hausdorffEdist s t = hausdorffEdist t s := by
simp only [hausdorffEdist_def]; apply sup_comm
set_option linter.uppercaseLean3 false in
#align emetric.Hausdorff_edist_comm EMetric.hausdorffEdist_comm
/-- Bounding the Hausdorff edistance by bounding the edistance of any point
in each set to the other set -/
theorem hausdorffEdist_le_of_infEdist {r : ℝ≥0∞} (H1 : ∀ x ∈ s, infEdist x t ≤ r)
(H2 : ∀ x ∈ t, infEdist x s ≤ r) : hausdorffEdist s t ≤ r := by
simp only [hausdorffEdist_def, sup_le_iff, iSup_le_iff]
exact ⟨H1, H2⟩
#align emetric.Hausdorff_edist_le_of_inf_edist EMetric.hausdorffEdist_le_of_infEdist
/-- Bounding the Hausdorff edistance by exhibiting, for any point in each set,
another point in the other set at controlled distance -/
theorem hausdorffEdist_le_of_mem_edist {r : ℝ≥0∞} (H1 : ∀ x ∈ s, ∃ y ∈ t, edist x y ≤ r)
(H2 : ∀ x ∈ t, ∃ y ∈ s, edist x y ≤ r) : hausdorffEdist s t ≤ r := by
refine hausdorffEdist_le_of_infEdist (fun x xs ↦ ?_) (fun x xt ↦ ?_)
· rcases H1 x xs with ⟨y, yt, hy⟩
exact le_trans (infEdist_le_edist_of_mem yt) hy
· rcases H2 x xt with ⟨y, ys, hy⟩
exact le_trans (infEdist_le_edist_of_mem ys) hy
#align emetric.Hausdorff_edist_le_of_mem_edist EMetric.hausdorffEdist_le_of_mem_edist
/-- The distance to a set is controlled by the Hausdorff distance. -/
theorem infEdist_le_hausdorffEdist_of_mem (h : x ∈ s) : infEdist x t ≤ hausdorffEdist s t := by
rw [hausdorffEdist_def]
refine le_trans ?_ le_sup_left
exact le_iSup₂ (α := ℝ≥0∞) x h
#align emetric.inf_edist_le_Hausdorff_edist_of_mem EMetric.infEdist_le_hausdorffEdist_of_mem
/-- If the Hausdorff distance is `< r`, then any point in one of the sets has
a corresponding point at distance `< r` in the other set. -/
theorem exists_edist_lt_of_hausdorffEdist_lt {r : ℝ≥0∞} (h : x ∈ s) (H : hausdorffEdist s t < r) :
∃ y ∈ t, edist x y < r :=
infEdist_lt_iff.mp <|
calc
infEdist x t ≤ hausdorffEdist s t := infEdist_le_hausdorffEdist_of_mem h
_ < r := H
#align emetric.exists_edist_lt_of_Hausdorff_edist_lt EMetric.exists_edist_lt_of_hausdorffEdist_lt
/-- The distance from `x` to `s` or `t` is controlled in terms of the Hausdorff distance
between `s` and `t`. -/
theorem infEdist_le_infEdist_add_hausdorffEdist :
infEdist x t ≤ infEdist x s + hausdorffEdist s t :=
ENNReal.le_of_forall_pos_le_add fun ε εpos h => by
have ε0 : (ε / 2 : ℝ≥0∞) ≠ 0 := by simpa [pos_iff_ne_zero] using εpos
have : infEdist x s < infEdist x s + ε / 2 :=
ENNReal.lt_add_right (ENNReal.add_lt_top.1 h).1.ne ε0
obtain ⟨y : α, ys : y ∈ s, dxy : edist x y < infEdist x s + ↑ε / 2⟩ := infEdist_lt_iff.mp this
have : hausdorffEdist s t < hausdorffEdist s t + ε / 2 :=
ENNReal.lt_add_right (ENNReal.add_lt_top.1 h).2.ne ε0
obtain ⟨z : α, zt : z ∈ t, dyz : edist y z < hausdorffEdist s t + ↑ε / 2⟩ :=
exists_edist_lt_of_hausdorffEdist_lt ys this
calc
infEdist x t ≤ edist x z := infEdist_le_edist_of_mem zt
_ ≤ edist x y + edist y z := edist_triangle _ _ _
_ ≤ infEdist x s + ε / 2 + (hausdorffEdist s t + ε / 2) := add_le_add dxy.le dyz.le
_ = infEdist x s + hausdorffEdist s t + ε := by
simp [ENNReal.add_halves, add_comm, add_left_comm]
#align emetric.inf_edist_le_inf_edist_add_Hausdorff_edist EMetric.infEdist_le_infEdist_add_hausdorffEdist
/-- The Hausdorff edistance is invariant under isometries. -/
theorem hausdorffEdist_image (h : Isometry Φ) :
hausdorffEdist (Φ '' s) (Φ '' t) = hausdorffEdist s t := by
simp only [hausdorffEdist_def, iSup_image, infEdist_image h]
#align emetric.Hausdorff_edist_image EMetric.hausdorffEdist_image
/-- The Hausdorff distance is controlled by the diameter of the union. -/
theorem hausdorffEdist_le_ediam (hs : s.Nonempty) (ht : t.Nonempty) :
hausdorffEdist s t ≤ diam (s ∪ t) := by
rcases hs with ⟨x, xs⟩
rcases ht with ⟨y, yt⟩
refine hausdorffEdist_le_of_mem_edist ?_ ?_
· intro z hz
exact ⟨y, yt, edist_le_diam_of_mem (subset_union_left hz) (subset_union_right yt)⟩
· intro z hz
exact ⟨x, xs, edist_le_diam_of_mem (subset_union_right hz) (subset_union_left xs)⟩
#align emetric.Hausdorff_edist_le_ediam EMetric.hausdorffEdist_le_ediam
/-- The Hausdorff distance satisfies the triangle inequality. -/
theorem hausdorffEdist_triangle : hausdorffEdist s u ≤ hausdorffEdist s t + hausdorffEdist t u := by
rw [hausdorffEdist_def]
simp only [sup_le_iff, iSup_le_iff]
constructor
· show ∀ x ∈ s, infEdist x u ≤ hausdorffEdist s t + hausdorffEdist t u
exact fun x xs =>
calc
infEdist x u ≤ infEdist x t + hausdorffEdist t u :=
infEdist_le_infEdist_add_hausdorffEdist
_ ≤ hausdorffEdist s t + hausdorffEdist t u :=
add_le_add_right (infEdist_le_hausdorffEdist_of_mem xs) _
· show ∀ x ∈ u, infEdist x s ≤ hausdorffEdist s t + hausdorffEdist t u
exact fun x xu =>
calc
infEdist x s ≤ infEdist x t + hausdorffEdist t s :=
infEdist_le_infEdist_add_hausdorffEdist
_ ≤ hausdorffEdist u t + hausdorffEdist t s :=
add_le_add_right (infEdist_le_hausdorffEdist_of_mem xu) _
_ = hausdorffEdist s t + hausdorffEdist t u := by simp [hausdorffEdist_comm, add_comm]
#align emetric.Hausdorff_edist_triangle EMetric.hausdorffEdist_triangle
/-- Two sets are at zero Hausdorff edistance if and only if they have the same closure. -/
theorem hausdorffEdist_zero_iff_closure_eq_closure :
hausdorffEdist s t = 0 ↔ closure s = closure t := by
simp only [hausdorffEdist_def, ENNReal.sup_eq_zero, ENNReal.iSup_eq_zero, ← subset_def,
← mem_closure_iff_infEdist_zero, subset_antisymm_iff, isClosed_closure.closure_subset_iff]
#align emetric.Hausdorff_edist_zero_iff_closure_eq_closure EMetric.hausdorffEdist_zero_iff_closure_eq_closure
/-- The Hausdorff edistance between a set and its closure vanishes. -/
@[simp]
theorem hausdorffEdist_self_closure : hausdorffEdist s (closure s) = 0 := by
rw [hausdorffEdist_zero_iff_closure_eq_closure, closure_closure]
#align emetric.Hausdorff_edist_self_closure EMetric.hausdorffEdist_self_closure
/-- Replacing a set by its closure does not change the Hausdorff edistance. -/
@[simp]
theorem hausdorffEdist_closure₁ : hausdorffEdist (closure s) t = hausdorffEdist s t := by
refine le_antisymm ?_ ?_
· calc
_ ≤ hausdorffEdist (closure s) s + hausdorffEdist s t := hausdorffEdist_triangle
_ = hausdorffEdist s t := by simp [hausdorffEdist_comm]
· calc
_ ≤ hausdorffEdist s (closure s) + hausdorffEdist (closure s) t := hausdorffEdist_triangle
_ = hausdorffEdist (closure s) t := by simp
#align emetric.Hausdorff_edist_closure₁ EMetric.hausdorffEdist_closure₁
/-- Replacing a set by its closure does not change the Hausdorff edistance. -/
@[simp]
theorem hausdorffEdist_closure₂ : hausdorffEdist s (closure t) = hausdorffEdist s t := by
simp [@hausdorffEdist_comm _ _ s _]
#align emetric.Hausdorff_edist_closure₂ EMetric.hausdorffEdist_closure₂
/-- The Hausdorff edistance between sets or their closures is the same. -/
-- @[simp] -- Porting note (#10618): simp can prove this
theorem hausdorffEdist_closure : hausdorffEdist (closure s) (closure t) = hausdorffEdist s t := by
simp
#align emetric.Hausdorff_edist_closure EMetric.hausdorffEdist_closure
/-- Two closed sets are at zero Hausdorff edistance if and only if they coincide. -/
theorem hausdorffEdist_zero_iff_eq_of_closed (hs : IsClosed s) (ht : IsClosed t) :
hausdorffEdist s t = 0 ↔ s = t := by
rw [hausdorffEdist_zero_iff_closure_eq_closure, hs.closure_eq, ht.closure_eq]
#align emetric.Hausdorff_edist_zero_iff_eq_of_closed EMetric.hausdorffEdist_zero_iff_eq_of_closed
/-- The Haudorff edistance to the empty set is infinite. -/
theorem hausdorffEdist_empty (ne : s.Nonempty) : hausdorffEdist s ∅ = ∞ := by
rcases ne with ⟨x, xs⟩
have : infEdist x ∅ ≤ hausdorffEdist s ∅ := infEdist_le_hausdorffEdist_of_mem xs
simpa using this
#align emetric.Hausdorff_edist_empty EMetric.hausdorffEdist_empty
/-- If a set is at finite Hausdorff edistance of a nonempty set, it is nonempty. -/
theorem nonempty_of_hausdorffEdist_ne_top (hs : s.Nonempty) (fin : hausdorffEdist s t ≠ ⊤) :
t.Nonempty :=
t.eq_empty_or_nonempty.resolve_left fun ht ↦ fin (ht.symm ▸ hausdorffEdist_empty hs)
#align emetric.nonempty_of_Hausdorff_edist_ne_top EMetric.nonempty_of_hausdorffEdist_ne_top
theorem empty_or_nonempty_of_hausdorffEdist_ne_top (fin : hausdorffEdist s t ≠ ⊤) :
(s = ∅ ∧ t = ∅) ∨ (s.Nonempty ∧ t.Nonempty) := by
rcases s.eq_empty_or_nonempty with hs | hs
· rcases t.eq_empty_or_nonempty with ht | ht
· exact Or.inl ⟨hs, ht⟩
· rw [hausdorffEdist_comm] at fin
exact Or.inr ⟨nonempty_of_hausdorffEdist_ne_top ht fin, ht⟩
· exact Or.inr ⟨hs, nonempty_of_hausdorffEdist_ne_top hs fin⟩
#align emetric.empty_or_nonempty_of_Hausdorff_edist_ne_top EMetric.empty_or_nonempty_of_hausdorffEdist_ne_top
end HausdorffEdist
-- section
end EMetric
/-! Now, we turn to the same notions in metric spaces. To avoid the difficulties related to
`sInf` and `sSup` on `ℝ` (which is only conditionally complete), we use the notions in `ℝ≥0∞`
formulated in terms of the edistance, and coerce them to `ℝ`.
Then their properties follow readily from the corresponding properties in `ℝ≥0∞`,
modulo some tedious rewriting of inequalities from one to the other. -/
--namespace
namespace Metric
section
variable [PseudoMetricSpace α] [PseudoMetricSpace β] {s t u : Set α} {x y : α} {Φ : α → β}
open EMetric
/-! ### Distance of a point to a set as a function into `ℝ`. -/
/-- The minimal distance of a point to a set -/
def infDist (x : α) (s : Set α) : ℝ :=
ENNReal.toReal (infEdist x s)
#align metric.inf_dist Metric.infDist
theorem infDist_eq_iInf : infDist x s = ⨅ y : s, dist x y := by
rw [infDist, infEdist, iInf_subtype', ENNReal.toReal_iInf]
· simp only [dist_edist]
· exact fun _ ↦ edist_ne_top _ _
#align metric.inf_dist_eq_infi Metric.infDist_eq_iInf
/-- The minimal distance is always nonnegative -/
theorem infDist_nonneg : 0 ≤ infDist x s := toReal_nonneg
#align metric.inf_dist_nonneg Metric.infDist_nonneg
/-- The minimal distance to the empty set is 0 (if you want to have the more reasonable
value `∞` instead, use `EMetric.infEdist`, which takes values in `ℝ≥0∞`) -/
@[simp]
theorem infDist_empty : infDist x ∅ = 0 := by simp [infDist]
#align metric.inf_dist_empty Metric.infDist_empty
/-- In a metric space, the minimal edistance to a nonempty set is finite. -/
theorem infEdist_ne_top (h : s.Nonempty) : infEdist x s ≠ ⊤ := by
rcases h with ⟨y, hy⟩
exact ne_top_of_le_ne_top (edist_ne_top _ _) (infEdist_le_edist_of_mem hy)
#align metric.inf_edist_ne_top Metric.infEdist_ne_top
-- Porting note (#10756): new lemma;
-- Porting note (#11215): TODO: make it a `simp` lemma
theorem infEdist_eq_top_iff : infEdist x s = ∞ ↔ s = ∅ := by
rcases s.eq_empty_or_nonempty with rfl | hs <;> simp [*, Nonempty.ne_empty, infEdist_ne_top]
/-- The minimal distance of a point to a set containing it vanishes. -/
theorem infDist_zero_of_mem (h : x ∈ s) : infDist x s = 0 := by
simp [infEdist_zero_of_mem h, infDist]
#align metric.inf_dist_zero_of_mem Metric.infDist_zero_of_mem
/-- The minimal distance to a singleton is the distance to the unique point in this singleton. -/
@[simp]
theorem infDist_singleton : infDist x {y} = dist x y := by simp [infDist, dist_edist]
#align metric.inf_dist_singleton Metric.infDist_singleton
/-- The minimal distance to a set is bounded by the distance to any point in this set. -/
theorem infDist_le_dist_of_mem (h : y ∈ s) : infDist x s ≤ dist x y := by
rw [dist_edist, infDist]
exact ENNReal.toReal_mono (edist_ne_top _ _) (infEdist_le_edist_of_mem h)
#align metric.inf_dist_le_dist_of_mem Metric.infDist_le_dist_of_mem
/-- The minimal distance is monotone with respect to inclusion. -/
theorem infDist_le_infDist_of_subset (h : s ⊆ t) (hs : s.Nonempty) : infDist x t ≤ infDist x s :=
ENNReal.toReal_mono (infEdist_ne_top hs) (infEdist_anti h)
#align metric.inf_dist_le_inf_dist_of_subset Metric.infDist_le_infDist_of_subset
/-- The minimal distance to a set `s` is `< r` iff there exists a point in `s` at distance `< r`. -/
theorem infDist_lt_iff {r : ℝ} (hs : s.Nonempty) : infDist x s < r ↔ ∃ y ∈ s, dist x y < r := by
simp_rw [infDist, ← ENNReal.lt_ofReal_iff_toReal_lt (infEdist_ne_top hs), infEdist_lt_iff,
ENNReal.lt_ofReal_iff_toReal_lt (edist_ne_top _ _), ← dist_edist]
#align metric.inf_dist_lt_iff Metric.infDist_lt_iff
/-- The minimal distance from `x` to `s` is bounded by the distance from `y` to `s`, modulo
the distance between `x` and `y`. -/
theorem infDist_le_infDist_add_dist : infDist x s ≤ infDist y s + dist x y := by
rw [infDist, infDist, dist_edist]
refine ENNReal.toReal_le_add' infEdist_le_infEdist_add_edist ?_ (flip absurd (edist_ne_top _ _))
simp only [infEdist_eq_top_iff, imp_self]
#align metric.inf_dist_le_inf_dist_add_dist Metric.infDist_le_infDist_add_dist
theorem not_mem_of_dist_lt_infDist (h : dist x y < infDist x s) : y ∉ s := fun hy =>
h.not_le <| infDist_le_dist_of_mem hy
#align metric.not_mem_of_dist_lt_inf_dist Metric.not_mem_of_dist_lt_infDist
theorem disjoint_ball_infDist : Disjoint (ball x (infDist x s)) s :=
disjoint_left.2 fun _y hy => not_mem_of_dist_lt_infDist <| mem_ball'.1 hy
#align metric.disjoint_ball_inf_dist Metric.disjoint_ball_infDist
theorem ball_infDist_subset_compl : ball x (infDist x s) ⊆ sᶜ :=
(disjoint_ball_infDist (s := s)).subset_compl_right
#align metric.ball_inf_dist_subset_compl Metric.ball_infDist_subset_compl
theorem ball_infDist_compl_subset : ball x (infDist x sᶜ) ⊆ s :=
ball_infDist_subset_compl.trans_eq (compl_compl s)
#align metric.ball_inf_dist_compl_subset Metric.ball_infDist_compl_subset
theorem disjoint_closedBall_of_lt_infDist {r : ℝ} (h : r < infDist x s) :
Disjoint (closedBall x r) s :=
disjoint_ball_infDist.mono_left <| closedBall_subset_ball h
#align metric.disjoint_closed_ball_of_lt_inf_dist Metric.disjoint_closedBall_of_lt_infDist
theorem dist_le_infDist_add_diam (hs : IsBounded s) (hy : y ∈ s) :
dist x y ≤ infDist x s + diam s := by
rw [infDist, diam, dist_edist]
exact toReal_le_add (edist_le_infEdist_add_ediam hy) (infEdist_ne_top ⟨y, hy⟩) hs.ediam_ne_top
#align metric.dist_le_inf_dist_add_diam Metric.dist_le_infDist_add_diam
variable (s)
/-- The minimal distance to a set is Lipschitz in point with constant 1 -/
theorem lipschitz_infDist_pt : LipschitzWith 1 (infDist · s) :=
LipschitzWith.of_le_add fun _ _ => infDist_le_infDist_add_dist
#align metric.lipschitz_inf_dist_pt Metric.lipschitz_infDist_pt
/-- The minimal distance to a set is uniformly continuous in point -/
theorem uniformContinuous_infDist_pt : UniformContinuous (infDist · s) :=
(lipschitz_infDist_pt s).uniformContinuous
#align metric.uniform_continuous_inf_dist_pt Metric.uniformContinuous_infDist_pt
/-- The minimal distance to a set is continuous in point -/
@[continuity]
theorem continuous_infDist_pt : Continuous (infDist · s) :=
(uniformContinuous_infDist_pt s).continuous
#align metric.continuous_inf_dist_pt Metric.continuous_infDist_pt
variable {s}
/-- The minimal distances to a set and its closure coincide. -/
theorem infDist_closure : infDist x (closure s) = infDist x s := by
simp [infDist, infEdist_closure]
#align metric.inf_dist_eq_closure Metric.infDist_closure
/-- If a point belongs to the closure of `s`, then its infimum distance to `s` equals zero.
The converse is true provided that `s` is nonempty, see `Metric.mem_closure_iff_infDist_zero`. -/
| Mathlib/Topology/MetricSpace/HausdorffDistance.lean | 604 | 606 | theorem infDist_zero_of_mem_closure (hx : x ∈ closure s) : infDist x s = 0 := by |
rw [← infDist_closure]
exact infDist_zero_of_mem hx
|
/-
Copyright (c) 2023 Peter Nelson. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Peter Nelson
-/
import Mathlib.SetTheory.Cardinal.Finite
#align_import data.set.ncard from "leanprover-community/mathlib"@"74c2af38a828107941029b03839882c5c6f87a04"
/-!
# Noncomputable Set Cardinality
We define the cardinality of set `s` as a term `Set.encard s : ℕ∞` and a term `Set.ncard s : ℕ`.
The latter takes the junk value of zero if `s` is infinite. Both functions are noncomputable, and
are defined in terms of `PartENat.card` (which takes a type as its argument); this file can be seen
as an API for the same function in the special case where the type is a coercion of a `Set`,
allowing for smoother interactions with the `Set` API.
`Set.encard` never takes junk values, so is more mathematically natural than `Set.ncard`, even
though it takes values in a less convenient type. It is probably the right choice in settings where
one is concerned with the cardinalities of sets that may or may not be infinite.
`Set.ncard` has a nicer codomain, but when using it, `Set.Finite` hypotheses are normally needed to
make sure its values are meaningful. More generally, `Set.ncard` is intended to be used over the
obvious alternative `Finset.card` when finiteness is 'propositional' rather than 'structural'.
When working with sets that are finite by virtue of their definition, then `Finset.card` probably
makes more sense. One setting where `Set.ncard` works nicely is in a type `α` with `[Finite α]`,
where every set is automatically finite. In this setting, we use default arguments and a simple
tactic so that finiteness goals are discharged automatically in `Set.ncard` theorems.
## Main Definitions
* `Set.encard s` is the cardinality of the set `s` as an extended natural number, with value `⊤` if
`s` is infinite.
* `Set.ncard s` is the cardinality of the set `s` as a natural number, provided `s` is Finite.
If `s` is Infinite, then `Set.ncard s = 0`.
* `toFinite_tac` is a tactic that tries to synthesize a `Set.Finite s` argument with
`Set.toFinite`. This will work for `s : Set α` where there is a `Finite α` instance.
## Implementation Notes
The theorems in this file are very similar to those in `Data.Finset.Card`, but with `Set` operations
instead of `Finset`. We first prove all the theorems for `Set.encard`, and then derive most of the
`Set.ncard` results as a consequence. Things are done this way to avoid reliance on the `Finset` API
for theorems about infinite sets, and to allow for a refactor that removes or modifies `Set.ncard`
in the future.
Nearly all the theorems for `Set.ncard` require finiteness of one or more of their arguments. We
provide this assumption with a default argument of the form `(hs : s.Finite := by toFinite_tac)`,
where `toFinite_tac` will find an `s.Finite` term in the cases where `s` is a set in a `Finite`
type.
Often, where there are two set arguments `s` and `t`, the finiteness of one follows from the other
in the context of the theorem, in which case we only include the ones that are needed, and derive
the other inside the proof. A few of the theorems, such as `ncard_union_le` do not require
finiteness arguments; they are true by coincidence due to junk values.
-/
namespace Set
variable {α β : Type*} {s t : Set α}
/-- The cardinality of a set as a term in `ℕ∞` -/
noncomputable def encard (s : Set α) : ℕ∞ := PartENat.withTopEquiv (PartENat.card s)
@[simp] theorem encard_univ_coe (s : Set α) : encard (univ : Set s) = encard s := by
rw [encard, encard, PartENat.card_congr (Equiv.Set.univ ↑s)]
theorem encard_univ (α : Type*) :
encard (univ : Set α) = PartENat.withTopEquiv (PartENat.card α) := by
rw [encard, PartENat.card_congr (Equiv.Set.univ α)]
theorem Finite.encard_eq_coe_toFinset_card (h : s.Finite) : s.encard = h.toFinset.card := by
have := h.fintype
rw [encard, PartENat.card_eq_coe_fintype_card,
PartENat.withTopEquiv_natCast, toFinite_toFinset, toFinset_card]
theorem encard_eq_coe_toFinset_card (s : Set α) [Fintype s] : encard s = s.toFinset.card := by
have h := toFinite s
rw [h.encard_eq_coe_toFinset_card, toFinite_toFinset]
theorem encard_coe_eq_coe_finsetCard (s : Finset α) : encard (s : Set α) = s.card := by
rw [Finite.encard_eq_coe_toFinset_card (Finset.finite_toSet s)]; simp
theorem Infinite.encard_eq {s : Set α} (h : s.Infinite) : s.encard = ⊤ := by
have := h.to_subtype
rw [encard, ← PartENat.withTopEquiv.symm.injective.eq_iff, Equiv.symm_apply_apply,
PartENat.withTopEquiv_symm_top, PartENat.card_eq_top_of_infinite]
@[simp] theorem encard_eq_zero : s.encard = 0 ↔ s = ∅ := by
rw [encard, ← PartENat.withTopEquiv.symm.injective.eq_iff, Equiv.symm_apply_apply,
PartENat.withTopEquiv_symm_zero, PartENat.card_eq_zero_iff_empty, isEmpty_subtype,
eq_empty_iff_forall_not_mem]
@[simp] theorem encard_empty : (∅ : Set α).encard = 0 := by
rw [encard_eq_zero]
theorem nonempty_of_encard_ne_zero (h : s.encard ≠ 0) : s.Nonempty := by
rwa [nonempty_iff_ne_empty, Ne, ← encard_eq_zero]
theorem encard_ne_zero : s.encard ≠ 0 ↔ s.Nonempty := by
rw [ne_eq, encard_eq_zero, nonempty_iff_ne_empty]
@[simp] theorem encard_pos : 0 < s.encard ↔ s.Nonempty := by
rw [pos_iff_ne_zero, encard_ne_zero]
@[simp] theorem encard_singleton (e : α) : ({e} : Set α).encard = 1 := by
rw [encard, ← PartENat.withTopEquiv.symm.injective.eq_iff, Equiv.symm_apply_apply,
PartENat.card_eq_coe_fintype_card, Fintype.card_ofSubsingleton, Nat.cast_one]; rfl
theorem encard_union_eq (h : Disjoint s t) : (s ∪ t).encard = s.encard + t.encard := by
classical
have e := (Equiv.Set.union (by rwa [subset_empty_iff, ← disjoint_iff_inter_eq_empty])).symm
simp [encard, ← PartENat.card_congr e, PartENat.card_sum, PartENat.withTopEquiv]
theorem encard_insert_of_not_mem {a : α} (has : a ∉ s) : (insert a s).encard = s.encard + 1 := by
rw [← union_singleton, encard_union_eq (by simpa), encard_singleton]
theorem Finite.encard_lt_top (h : s.Finite) : s.encard < ⊤ := by
refine h.induction_on (by simp) ?_
rintro a t hat _ ht'
rw [encard_insert_of_not_mem hat]
exact lt_tsub_iff_right.1 ht'
theorem Finite.encard_eq_coe (h : s.Finite) : s.encard = ENat.toNat s.encard :=
(ENat.coe_toNat h.encard_lt_top.ne).symm
theorem Finite.exists_encard_eq_coe (h : s.Finite) : ∃ (n : ℕ), s.encard = n :=
⟨_, h.encard_eq_coe⟩
@[simp] theorem encard_lt_top_iff : s.encard < ⊤ ↔ s.Finite :=
⟨fun h ↦ by_contra fun h' ↦ h.ne (Infinite.encard_eq h'), Finite.encard_lt_top⟩
@[simp] theorem encard_eq_top_iff : s.encard = ⊤ ↔ s.Infinite := by
rw [← not_iff_not, ← Ne, ← lt_top_iff_ne_top, encard_lt_top_iff, not_infinite]
theorem encard_ne_top_iff : s.encard ≠ ⊤ ↔ s.Finite := by
simp
theorem finite_of_encard_le_coe {k : ℕ} (h : s.encard ≤ k) : s.Finite := by
rw [← encard_lt_top_iff]; exact h.trans_lt (WithTop.coe_lt_top _)
theorem finite_of_encard_eq_coe {k : ℕ} (h : s.encard = k) : s.Finite :=
finite_of_encard_le_coe h.le
theorem encard_le_coe_iff {k : ℕ} : s.encard ≤ k ↔ s.Finite ∧ ∃ (n₀ : ℕ), s.encard = n₀ ∧ n₀ ≤ k :=
⟨fun h ↦ ⟨finite_of_encard_le_coe h, by rwa [ENat.le_coe_iff] at h⟩,
fun ⟨_,⟨n₀,hs, hle⟩⟩ ↦ by rwa [hs, Nat.cast_le]⟩
section Lattice
theorem encard_le_card (h : s ⊆ t) : s.encard ≤ t.encard := by
rw [← union_diff_cancel h, encard_union_eq disjoint_sdiff_right]; exact le_self_add
theorem encard_mono {α : Type*} : Monotone (encard : Set α → ℕ∞) :=
fun _ _ ↦ encard_le_card
theorem encard_diff_add_encard_of_subset (h : s ⊆ t) : (t \ s).encard + s.encard = t.encard := by
rw [← encard_union_eq disjoint_sdiff_left, diff_union_self, union_eq_self_of_subset_right h]
@[simp] theorem one_le_encard_iff_nonempty : 1 ≤ s.encard ↔ s.Nonempty := by
rw [nonempty_iff_ne_empty, Ne, ← encard_eq_zero, ENat.one_le_iff_ne_zero]
theorem encard_diff_add_encard_inter (s t : Set α) :
(s \ t).encard + (s ∩ t).encard = s.encard := by
rw [← encard_union_eq (disjoint_of_subset_right inter_subset_right disjoint_sdiff_left),
diff_union_inter]
theorem encard_union_add_encard_inter (s t : Set α) :
(s ∪ t).encard + (s ∩ t).encard = s.encard + t.encard := by
rw [← diff_union_self, encard_union_eq disjoint_sdiff_left, add_right_comm,
encard_diff_add_encard_inter]
theorem encard_eq_encard_iff_encard_diff_eq_encard_diff (h : (s ∩ t).Finite) :
s.encard = t.encard ↔ (s \ t).encard = (t \ s).encard := by
rw [← encard_diff_add_encard_inter s t, ← encard_diff_add_encard_inter t s, inter_comm t s,
WithTop.add_right_cancel_iff h.encard_lt_top.ne]
theorem encard_le_encard_iff_encard_diff_le_encard_diff (h : (s ∩ t).Finite) :
s.encard ≤ t.encard ↔ (s \ t).encard ≤ (t \ s).encard := by
rw [← encard_diff_add_encard_inter s t, ← encard_diff_add_encard_inter t s, inter_comm t s,
WithTop.add_le_add_iff_right h.encard_lt_top.ne]
theorem encard_lt_encard_iff_encard_diff_lt_encard_diff (h : (s ∩ t).Finite) :
s.encard < t.encard ↔ (s \ t).encard < (t \ s).encard := by
rw [← encard_diff_add_encard_inter s t, ← encard_diff_add_encard_inter t s, inter_comm t s,
WithTop.add_lt_add_iff_right h.encard_lt_top.ne]
theorem encard_union_le (s t : Set α) : (s ∪ t).encard ≤ s.encard + t.encard := by
rw [← encard_union_add_encard_inter]; exact le_self_add
theorem finite_iff_finite_of_encard_eq_encard (h : s.encard = t.encard) : s.Finite ↔ t.Finite := by
rw [← encard_lt_top_iff, ← encard_lt_top_iff, h]
theorem infinite_iff_infinite_of_encard_eq_encard (h : s.encard = t.encard) :
s.Infinite ↔ t.Infinite := by rw [← encard_eq_top_iff, h, encard_eq_top_iff]
theorem Finite.finite_of_encard_le {s : Set α} {t : Set β} (hs : s.Finite)
(h : t.encard ≤ s.encard) : t.Finite :=
encard_lt_top_iff.1 (h.trans_lt hs.encard_lt_top)
theorem Finite.eq_of_subset_of_encard_le (ht : t.Finite) (hst : s ⊆ t) (hts : t.encard ≤ s.encard) :
s = t := by
rw [← zero_add (a := encard s), ← encard_diff_add_encard_of_subset hst] at hts
have hdiff := WithTop.le_of_add_le_add_right (ht.subset hst).encard_lt_top.ne hts
rw [nonpos_iff_eq_zero, encard_eq_zero, diff_eq_empty] at hdiff
exact hst.antisymm hdiff
theorem Finite.eq_of_subset_of_encard_le' (hs : s.Finite) (hst : s ⊆ t)
(hts : t.encard ≤ s.encard) : s = t :=
(hs.finite_of_encard_le hts).eq_of_subset_of_encard_le hst hts
theorem Finite.encard_lt_encard (ht : t.Finite) (h : s ⊂ t) : s.encard < t.encard :=
(encard_mono h.subset).lt_of_ne (fun he ↦ h.ne (ht.eq_of_subset_of_encard_le h.subset he.symm.le))
theorem encard_strictMono [Finite α] : StrictMono (encard : Set α → ℕ∞) :=
fun _ _ h ↦ (toFinite _).encard_lt_encard h
theorem encard_diff_add_encard (s t : Set α) : (s \ t).encard + t.encard = (s ∪ t).encard := by
rw [← encard_union_eq disjoint_sdiff_left, diff_union_self]
theorem encard_le_encard_diff_add_encard (s t : Set α) : s.encard ≤ (s \ t).encard + t.encard :=
(encard_mono subset_union_left).trans_eq (encard_diff_add_encard _ _).symm
theorem tsub_encard_le_encard_diff (s t : Set α) : s.encard - t.encard ≤ (s \ t).encard := by
rw [tsub_le_iff_left, add_comm]; apply encard_le_encard_diff_add_encard
theorem encard_add_encard_compl (s : Set α) : s.encard + sᶜ.encard = (univ : Set α).encard := by
rw [← encard_union_eq disjoint_compl_right, union_compl_self]
end Lattice
section InsertErase
variable {a b : α}
theorem encard_insert_le (s : Set α) (x : α) : (insert x s).encard ≤ s.encard + 1 := by
rw [← union_singleton, ← encard_singleton x]; apply encard_union_le
theorem encard_singleton_inter (s : Set α) (x : α) : ({x} ∩ s).encard ≤ 1 := by
rw [← encard_singleton x]; exact encard_le_card inter_subset_left
theorem encard_diff_singleton_add_one (h : a ∈ s) :
(s \ {a}).encard + 1 = s.encard := by
rw [← encard_insert_of_not_mem (fun h ↦ h.2 rfl), insert_diff_singleton, insert_eq_of_mem h]
theorem encard_diff_singleton_of_mem (h : a ∈ s) :
(s \ {a}).encard = s.encard - 1 := by
rw [← encard_diff_singleton_add_one h, ← WithTop.add_right_cancel_iff WithTop.one_ne_top,
tsub_add_cancel_of_le (self_le_add_left _ _)]
theorem encard_tsub_one_le_encard_diff_singleton (s : Set α) (x : α) :
s.encard - 1 ≤ (s \ {x}).encard := by
rw [← encard_singleton x]; apply tsub_encard_le_encard_diff
theorem encard_exchange (ha : a ∉ s) (hb : b ∈ s) : (insert a (s \ {b})).encard = s.encard := by
rw [encard_insert_of_not_mem, encard_diff_singleton_add_one hb]
simp_all only [not_true, mem_diff, mem_singleton_iff, false_and, not_false_eq_true]
theorem encard_exchange' (ha : a ∉ s) (hb : b ∈ s) : (insert a s \ {b}).encard = s.encard := by
rw [← insert_diff_singleton_comm (by rintro rfl; exact ha hb), encard_exchange ha hb]
theorem encard_eq_add_one_iff {k : ℕ∞} :
s.encard = k + 1 ↔ (∃ a t, ¬a ∈ t ∧ insert a t = s ∧ t.encard = k) := by
refine ⟨fun h ↦ ?_, ?_⟩
· obtain ⟨a, ha⟩ := nonempty_of_encard_ne_zero (s := s) (by simp [h])
refine ⟨a, s \ {a}, fun h ↦ h.2 rfl, by rwa [insert_diff_singleton, insert_eq_of_mem], ?_⟩
rw [← WithTop.add_right_cancel_iff WithTop.one_ne_top, ← h,
encard_diff_singleton_add_one ha]
rintro ⟨a, t, h, rfl, rfl⟩
rw [encard_insert_of_not_mem h]
/-- Every set is either empty, infinite, or can have its `encard` reduced by a removal. Intended
for well-founded induction on the value of `encard`. -/
theorem eq_empty_or_encard_eq_top_or_encard_diff_singleton_lt (s : Set α) :
s = ∅ ∨ s.encard = ⊤ ∨ ∃ a ∈ s, (s \ {a}).encard < s.encard := by
refine s.eq_empty_or_nonempty.elim Or.inl (Or.inr ∘ fun ⟨a,ha⟩ ↦
(s.finite_or_infinite.elim (fun hfin ↦ Or.inr ⟨a, ha, ?_⟩) (Or.inl ∘ Infinite.encard_eq)))
rw [← encard_diff_singleton_add_one ha]; nth_rw 1 [← add_zero (encard _)]
exact WithTop.add_lt_add_left (hfin.diff _).encard_lt_top.ne zero_lt_one
end InsertErase
section SmallSets
theorem encard_pair {x y : α} (hne : x ≠ y) : ({x, y} : Set α).encard = 2 := by
rw [encard_insert_of_not_mem (by simpa), ← one_add_one_eq_two,
WithTop.add_right_cancel_iff WithTop.one_ne_top, encard_singleton]
theorem encard_eq_one : s.encard = 1 ↔ ∃ x, s = {x} := by
refine ⟨fun h ↦ ?_, fun ⟨x, hx⟩ ↦ by rw [hx, encard_singleton]⟩
obtain ⟨x, hx⟩ := nonempty_of_encard_ne_zero (s := s) (by rw [h]; simp)
exact ⟨x, ((finite_singleton x).eq_of_subset_of_encard_le' (by simpa) (by simp [h])).symm⟩
theorem encard_le_one_iff_eq : s.encard ≤ 1 ↔ s = ∅ ∨ ∃ x, s = {x} := by
rw [le_iff_lt_or_eq, lt_iff_not_le, ENat.one_le_iff_ne_zero, not_not, encard_eq_zero,
encard_eq_one]
theorem encard_le_one_iff : s.encard ≤ 1 ↔ ∀ a b, a ∈ s → b ∈ s → a = b := by
rw [encard_le_one_iff_eq, or_iff_not_imp_left, ← Ne, ← nonempty_iff_ne_empty]
refine ⟨fun h a b has hbs ↦ ?_,
fun h ⟨x, hx⟩ ↦ ⟨x, ((singleton_subset_iff.2 hx).antisymm' (fun y hy ↦ h _ _ hy hx))⟩⟩
obtain ⟨x, rfl⟩ := h ⟨_, has⟩
rw [(has : a = x), (hbs : b = x)]
theorem one_lt_encard_iff : 1 < s.encard ↔ ∃ a b, a ∈ s ∧ b ∈ s ∧ a ≠ b := by
rw [← not_iff_not, not_exists, not_lt, encard_le_one_iff]; aesop
theorem exists_ne_of_one_lt_encard (h : 1 < s.encard) (a : α) : ∃ b ∈ s, b ≠ a := by
by_contra! h'
obtain ⟨b, b', hb, hb', hne⟩ := one_lt_encard_iff.1 h
apply hne
rw [h' b hb, h' b' hb']
theorem encard_eq_two : s.encard = 2 ↔ ∃ x y, x ≠ y ∧ s = {x, y} := by
refine ⟨fun h ↦ ?_, fun ⟨x, y, hne, hs⟩ ↦ by rw [hs, encard_pair hne]⟩
obtain ⟨x, hx⟩ := nonempty_of_encard_ne_zero (s := s) (by rw [h]; simp)
rw [← insert_eq_of_mem hx, ← insert_diff_singleton, encard_insert_of_not_mem (fun h ↦ h.2 rfl),
← one_add_one_eq_two, WithTop.add_right_cancel_iff (WithTop.one_ne_top), encard_eq_one] at h
obtain ⟨y, h⟩ := h
refine ⟨x, y, by rintro rfl; exact (h.symm.subset rfl).2 rfl, ?_⟩
rw [← h, insert_diff_singleton, insert_eq_of_mem hx]
theorem encard_eq_three {α : Type u_1} {s : Set α} :
encard s = 3 ↔ ∃ x y z, x ≠ y ∧ x ≠ z ∧ y ≠ z ∧ s = {x, y, z} := by
refine ⟨fun h ↦ ?_, fun ⟨x, y, z, hxy, hyz, hxz, hs⟩ ↦ ?_⟩
· obtain ⟨x, hx⟩ := nonempty_of_encard_ne_zero (s := s) (by rw [h]; simp)
rw [← insert_eq_of_mem hx, ← insert_diff_singleton,
encard_insert_of_not_mem (fun h ↦ h.2 rfl), (by exact rfl : (3 : ℕ∞) = 2 + 1),
WithTop.add_right_cancel_iff WithTop.one_ne_top, encard_eq_two] at h
obtain ⟨y, z, hne, hs⟩ := h
refine ⟨x, y, z, ?_, ?_, hne, ?_⟩
· rintro rfl; exact (hs.symm.subset (Or.inl rfl)).2 rfl
· rintro rfl; exact (hs.symm.subset (Or.inr rfl)).2 rfl
rw [← hs, insert_diff_singleton, insert_eq_of_mem hx]
rw [hs, encard_insert_of_not_mem, encard_insert_of_not_mem, encard_singleton] <;> aesop
theorem Nat.encard_range (k : ℕ) : {i | i < k}.encard = k := by
convert encard_coe_eq_coe_finsetCard (Finset.range k) using 1
· rw [Finset.coe_range, Iio_def]
rw [Finset.card_range]
end SmallSets
theorem Finite.eq_insert_of_subset_of_encard_eq_succ (hs : s.Finite) (h : s ⊆ t)
(hst : t.encard = s.encard + 1) : ∃ a, t = insert a s := by
rw [← encard_diff_add_encard_of_subset h, add_comm,
WithTop.add_left_cancel_iff hs.encard_lt_top.ne, encard_eq_one] at hst
obtain ⟨x, hx⟩ := hst; use x; rw [← diff_union_of_subset h, hx, singleton_union]
theorem exists_subset_encard_eq {k : ℕ∞} (hk : k ≤ s.encard) : ∃ t, t ⊆ s ∧ t.encard = k := by
revert hk
refine ENat.nat_induction k (fun _ ↦ ⟨∅, empty_subset _, by simp⟩) (fun n IH hle ↦ ?_) ?_
· obtain ⟨t₀, ht₀s, ht₀⟩ := IH (le_trans (by simp) hle)
simp only [Nat.cast_succ] at *
have hne : t₀ ≠ s := by
rintro rfl; rw [ht₀, ← Nat.cast_one, ← Nat.cast_add, Nat.cast_le] at hle; simp at hle
obtain ⟨x, hx⟩ := exists_of_ssubset (ht₀s.ssubset_of_ne hne)
exact ⟨insert x t₀, insert_subset hx.1 ht₀s, by rw [encard_insert_of_not_mem hx.2, ht₀]⟩
simp only [top_le_iff, encard_eq_top_iff]
exact fun _ hi ↦ ⟨s, Subset.rfl, hi⟩
theorem exists_superset_subset_encard_eq {k : ℕ∞}
(hst : s ⊆ t) (hsk : s.encard ≤ k) (hkt : k ≤ t.encard) :
∃ r, s ⊆ r ∧ r ⊆ t ∧ r.encard = k := by
obtain (hs | hs) := eq_or_ne s.encard ⊤
· rw [hs, top_le_iff] at hsk; subst hsk; exact ⟨s, Subset.rfl, hst, hs⟩
obtain ⟨k, rfl⟩ := exists_add_of_le hsk
obtain ⟨k', hk'⟩ := exists_add_of_le hkt
have hk : k ≤ encard (t \ s) := by
rw [← encard_diff_add_encard_of_subset hst, add_comm] at hkt
exact WithTop.le_of_add_le_add_right hs hkt
obtain ⟨r', hr', rfl⟩ := exists_subset_encard_eq hk
refine ⟨s ∪ r', subset_union_left, union_subset hst (hr'.trans diff_subset), ?_⟩
rw [encard_union_eq (disjoint_of_subset_right hr' disjoint_sdiff_right)]
section Function
variable {s : Set α} {t : Set β} {f : α → β}
theorem InjOn.encard_image (h : InjOn f s) : (f '' s).encard = s.encard := by
rw [encard, PartENat.card_image_of_injOn h, encard]
theorem encard_congr (e : s ≃ t) : s.encard = t.encard := by
rw [← encard_univ_coe, ← encard_univ_coe t, encard_univ, encard_univ, PartENat.card_congr e]
theorem _root_.Function.Injective.encard_image (hf : f.Injective) (s : Set α) :
(f '' s).encard = s.encard :=
hf.injOn.encard_image
theorem _root_.Function.Embedding.enccard_le (e : s ↪ t) : s.encard ≤ t.encard := by
rw [← encard_univ_coe, ← e.injective.encard_image, ← Subtype.coe_injective.encard_image]
exact encard_mono (by simp)
theorem encard_image_le (f : α → β) (s : Set α) : (f '' s).encard ≤ s.encard := by
obtain (h | h) := isEmpty_or_nonempty α
· rw [s.eq_empty_of_isEmpty]; simp
rw [← (f.invFunOn_injOn_image s).encard_image]
apply encard_le_card
exact f.invFunOn_image_image_subset s
theorem Finite.injOn_of_encard_image_eq (hs : s.Finite) (h : (f '' s).encard = s.encard) :
InjOn f s := by
obtain (h' | hne) := isEmpty_or_nonempty α
· rw [s.eq_empty_of_isEmpty]; simp
rw [← (f.invFunOn_injOn_image s).encard_image] at h
rw [injOn_iff_invFunOn_image_image_eq_self]
exact hs.eq_of_subset_of_encard_le (f.invFunOn_image_image_subset s) h.symm.le
theorem encard_preimage_of_injective_subset_range (hf : f.Injective) (ht : t ⊆ range f) :
(f ⁻¹' t).encard = t.encard := by
rw [← hf.encard_image, image_preimage_eq_inter_range, inter_eq_self_of_subset_left ht]
theorem encard_le_encard_of_injOn (hf : MapsTo f s t) (f_inj : InjOn f s) :
s.encard ≤ t.encard := by
rw [← f_inj.encard_image]; apply encard_le_card; rintro _ ⟨x, hx, rfl⟩; exact hf hx
theorem Finite.exists_injOn_of_encard_le [Nonempty β] {s : Set α} {t : Set β} (hs : s.Finite)
(hle : s.encard ≤ t.encard) : ∃ (f : α → β), s ⊆ f ⁻¹' t ∧ InjOn f s := by
classical
obtain (rfl | h | ⟨a, has, -⟩) := s.eq_empty_or_encard_eq_top_or_encard_diff_singleton_lt
· simp
· exact (encard_ne_top_iff.mpr hs h).elim
obtain ⟨b, hbt⟩ := encard_pos.1 ((encard_pos.2 ⟨_, has⟩).trans_le hle)
have hle' : (s \ {a}).encard ≤ (t \ {b}).encard := by
rwa [← WithTop.add_le_add_iff_right WithTop.one_ne_top,
encard_diff_singleton_add_one has, encard_diff_singleton_add_one hbt]
obtain ⟨f₀, hf₀s, hinj⟩ := exists_injOn_of_encard_le (hs.diff {a}) hle'
simp only [preimage_diff, subset_def, mem_diff, mem_singleton_iff, mem_preimage, and_imp] at hf₀s
use Function.update f₀ a b
rw [← insert_eq_of_mem has, ← insert_diff_singleton, injOn_insert (fun h ↦ h.2 rfl)]
simp only [mem_diff, mem_singleton_iff, not_true, and_false, insert_diff_singleton, subset_def,
mem_insert_iff, mem_preimage, ne_eq, Function.update_apply, forall_eq_or_imp, ite_true, and_imp,
mem_image, ite_eq_left_iff, not_exists, not_and, not_forall, exists_prop, and_iff_right hbt]
refine ⟨?_, ?_, fun x hxs hxa ↦ ⟨hxa, (hf₀s x hxs hxa).2⟩⟩
· rintro x hx; split_ifs with h
· assumption
· exact (hf₀s x hx h).1
exact InjOn.congr hinj (fun x ⟨_, hxa⟩ ↦ by rwa [Function.update_noteq])
termination_by encard s
theorem Finite.exists_bijOn_of_encard_eq [Nonempty β] (hs : s.Finite) (h : s.encard = t.encard) :
∃ (f : α → β), BijOn f s t := by
obtain ⟨f, hf, hinj⟩ := hs.exists_injOn_of_encard_le h.le; use f
convert hinj.bijOn_image
rw [(hs.image f).eq_of_subset_of_encard_le' (image_subset_iff.mpr hf)
(h.symm.trans hinj.encard_image.symm).le]
end Function
section ncard
open Nat
/-- A tactic (for use in default params) that applies `Set.toFinite` to synthesize a `Set.Finite`
term. -/
syntax "toFinite_tac" : tactic
macro_rules
| `(tactic| toFinite_tac) => `(tactic| apply Set.toFinite)
/-- A tactic useful for transferring proofs for `encard` to their corresponding `card` statements -/
syntax "to_encard_tac" : tactic
macro_rules
| `(tactic| to_encard_tac) => `(tactic|
simp only [← Nat.cast_le (α := ℕ∞), ← Nat.cast_inj (R := ℕ∞), Nat.cast_add, Nat.cast_one])
/-- The cardinality of `s : Set α` . Has the junk value `0` if `s` is infinite -/
noncomputable def ncard (s : Set α) : ℕ := ENat.toNat s.encard
#align set.ncard Set.ncard
theorem ncard_def (s : Set α) : s.ncard = ENat.toNat s.encard := rfl
theorem Finite.cast_ncard_eq (hs : s.Finite) : s.ncard = s.encard := by
rwa [ncard, ENat.coe_toNat_eq_self, ne_eq, encard_eq_top_iff, Set.Infinite, not_not]
theorem Nat.card_coe_set_eq (s : Set α) : Nat.card s = s.ncard := by
obtain (h | h) := s.finite_or_infinite
· have := h.fintype
rw [ncard, h.encard_eq_coe_toFinset_card, Nat.card_eq_fintype_card,
toFinite_toFinset, toFinset_card, ENat.toNat_coe]
have := infinite_coe_iff.2 h
rw [ncard, h.encard_eq, Nat.card_eq_zero_of_infinite, ENat.toNat_top]
#align set.nat.card_coe_set_eq Set.Nat.card_coe_set_eq
theorem ncard_eq_toFinset_card (s : Set α) (hs : s.Finite := by toFinite_tac) :
s.ncard = hs.toFinset.card := by
rw [← Nat.card_coe_set_eq, @Nat.card_eq_fintype_card _ hs.fintype,
@Finite.card_toFinset _ _ hs.fintype hs]
#align set.ncard_eq_to_finset_card Set.ncard_eq_toFinset_card
theorem ncard_eq_toFinset_card' (s : Set α) [Fintype s] :
s.ncard = s.toFinset.card := by
simp [← Nat.card_coe_set_eq, Nat.card_eq_fintype_card]
theorem encard_le_coe_iff_finite_ncard_le {k : ℕ} : s.encard ≤ k ↔ s.Finite ∧ s.ncard ≤ k := by
rw [encard_le_coe_iff, and_congr_right_iff]
exact fun hfin ↦ ⟨fun ⟨n₀, hn₀, hle⟩ ↦ by rwa [ncard_def, hn₀, ENat.toNat_coe],
fun h ↦ ⟨s.ncard, by rw [hfin.cast_ncard_eq], h⟩⟩
theorem Infinite.ncard (hs : s.Infinite) : s.ncard = 0 := by
rw [← Nat.card_coe_set_eq, @Nat.card_eq_zero_of_infinite _ hs.to_subtype]
#align set.infinite.ncard Set.Infinite.ncard
theorem ncard_le_ncard (hst : s ⊆ t) (ht : t.Finite := by toFinite_tac) :
s.ncard ≤ t.ncard := by
rw [← Nat.cast_le (α := ℕ∞), ht.cast_ncard_eq, (ht.subset hst).cast_ncard_eq]
exact encard_mono hst
#align set.ncard_le_of_subset Set.ncard_le_ncard
theorem ncard_mono [Finite α] : @Monotone (Set α) _ _ _ ncard := fun _ _ ↦ ncard_le_ncard
#align set.ncard_mono Set.ncard_mono
@[simp] theorem ncard_eq_zero (hs : s.Finite := by toFinite_tac) :
s.ncard = 0 ↔ s = ∅ := by
rw [← Nat.cast_inj (R := ℕ∞), hs.cast_ncard_eq, Nat.cast_zero, encard_eq_zero]
#align set.ncard_eq_zero Set.ncard_eq_zero
@[simp] theorem ncard_coe_Finset (s : Finset α) : (s : Set α).ncard = s.card := by
rw [ncard_eq_toFinset_card _, Finset.finite_toSet_toFinset]
#align set.ncard_coe_finset Set.ncard_coe_Finset
theorem ncard_univ (α : Type*) : (univ : Set α).ncard = Nat.card α := by
cases' finite_or_infinite α with h h
· have hft := Fintype.ofFinite α
rw [ncard_eq_toFinset_card, Finite.toFinset_univ, Finset.card_univ, Nat.card_eq_fintype_card]
rw [Nat.card_eq_zero_of_infinite, Infinite.ncard]
exact infinite_univ
#align set.ncard_univ Set.ncard_univ
@[simp] theorem ncard_empty (α : Type*) : (∅ : Set α).ncard = 0 := by
rw [ncard_eq_zero]
#align set.ncard_empty Set.ncard_empty
theorem ncard_pos (hs : s.Finite := by toFinite_tac) : 0 < s.ncard ↔ s.Nonempty := by
rw [pos_iff_ne_zero, Ne, ncard_eq_zero hs, nonempty_iff_ne_empty]
#align set.ncard_pos Set.ncard_pos
theorem ncard_ne_zero_of_mem {a : α} (h : a ∈ s) (hs : s.Finite := by toFinite_tac) : s.ncard ≠ 0 :=
((ncard_pos hs).mpr ⟨a, h⟩).ne.symm
#align set.ncard_ne_zero_of_mem Set.ncard_ne_zero_of_mem
theorem finite_of_ncard_ne_zero (hs : s.ncard ≠ 0) : s.Finite :=
s.finite_or_infinite.elim id fun h ↦ (hs h.ncard).elim
#align set.finite_of_ncard_ne_zero Set.finite_of_ncard_ne_zero
theorem finite_of_ncard_pos (hs : 0 < s.ncard) : s.Finite :=
finite_of_ncard_ne_zero hs.ne.symm
#align set.finite_of_ncard_pos Set.finite_of_ncard_pos
theorem nonempty_of_ncard_ne_zero (hs : s.ncard ≠ 0) : s.Nonempty := by
rw [nonempty_iff_ne_empty]; rintro rfl; simp at hs
#align set.nonempty_of_ncard_ne_zero Set.nonempty_of_ncard_ne_zero
@[simp] theorem ncard_singleton (a : α) : ({a} : Set α).ncard = 1 := by
simp [ncard, ncard_eq_toFinset_card]
#align set.ncard_singleton Set.ncard_singleton
theorem ncard_singleton_inter (a : α) (s : Set α) : ({a} ∩ s).ncard ≤ 1 := by
rw [← Nat.cast_le (α := ℕ∞), (toFinite _).cast_ncard_eq, Nat.cast_one]
apply encard_singleton_inter
#align set.ncard_singleton_inter Set.ncard_singleton_inter
section InsertErase
@[simp] theorem ncard_insert_of_not_mem {a : α} (h : a ∉ s) (hs : s.Finite := by toFinite_tac) :
(insert a s).ncard = s.ncard + 1 := by
rw [← Nat.cast_inj (R := ℕ∞), (hs.insert a).cast_ncard_eq, Nat.cast_add, Nat.cast_one,
hs.cast_ncard_eq, encard_insert_of_not_mem h]
#align set.ncard_insert_of_not_mem Set.ncard_insert_of_not_mem
theorem ncard_insert_of_mem {a : α} (h : a ∈ s) : ncard (insert a s) = s.ncard := by
rw [insert_eq_of_mem h]
#align set.ncard_insert_of_mem Set.ncard_insert_of_mem
theorem ncard_insert_le (a : α) (s : Set α) : (insert a s).ncard ≤ s.ncard + 1 := by
obtain hs | hs := s.finite_or_infinite
· to_encard_tac; rw [hs.cast_ncard_eq, (hs.insert _).cast_ncard_eq]; apply encard_insert_le
rw [(hs.mono (subset_insert a s)).ncard]
exact Nat.zero_le _
#align set.ncard_insert_le Set.ncard_insert_le
theorem ncard_insert_eq_ite {a : α} [Decidable (a ∈ s)] (hs : s.Finite := by toFinite_tac) :
ncard (insert a s) = if a ∈ s then s.ncard else s.ncard + 1 := by
by_cases h : a ∈ s
· rw [ncard_insert_of_mem h, if_pos h]
· rw [ncard_insert_of_not_mem h hs, if_neg h]
#align set.ncard_insert_eq_ite Set.ncard_insert_eq_ite
theorem ncard_le_ncard_insert (a : α) (s : Set α) : s.ncard ≤ (insert a s).ncard := by
classical
refine
s.finite_or_infinite.elim (fun h ↦ ?_) (fun h ↦ by (rw [h.ncard]; exact Nat.zero_le _))
rw [ncard_insert_eq_ite h]; split_ifs <;> simp
#align set.ncard_le_ncard_insert Set.ncard_le_ncard_insert
@[simp] theorem ncard_pair {a b : α} (h : a ≠ b) : ({a, b} : Set α).ncard = 2 := by
rw [ncard_insert_of_not_mem, ncard_singleton]; simpa
#align set.card_doubleton Set.ncard_pair
@[simp] theorem ncard_diff_singleton_add_one {a : α} (h : a ∈ s)
(hs : s.Finite := by toFinite_tac) : (s \ {a}).ncard + 1 = s.ncard := by
to_encard_tac; rw [hs.cast_ncard_eq, (hs.diff _).cast_ncard_eq,
encard_diff_singleton_add_one h]
#align set.ncard_diff_singleton_add_one Set.ncard_diff_singleton_add_one
@[simp] theorem ncard_diff_singleton_of_mem {a : α} (h : a ∈ s) (hs : s.Finite := by toFinite_tac) :
(s \ {a}).ncard = s.ncard - 1 :=
eq_tsub_of_add_eq (ncard_diff_singleton_add_one h hs)
#align set.ncard_diff_singleton_of_mem Set.ncard_diff_singleton_of_mem
theorem ncard_diff_singleton_lt_of_mem {a : α} (h : a ∈ s) (hs : s.Finite := by toFinite_tac) :
(s \ {a}).ncard < s.ncard := by
rw [← ncard_diff_singleton_add_one h hs]; apply lt_add_one
#align set.ncard_diff_singleton_lt_of_mem Set.ncard_diff_singleton_lt_of_mem
theorem ncard_diff_singleton_le (s : Set α) (a : α) : (s \ {a}).ncard ≤ s.ncard := by
obtain hs | hs := s.finite_or_infinite
· apply ncard_le_ncard diff_subset hs
convert @zero_le ℕ _ _
exact (hs.diff (by simp : Set.Finite {a})).ncard
#align set.ncard_diff_singleton_le Set.ncard_diff_singleton_le
theorem pred_ncard_le_ncard_diff_singleton (s : Set α) (a : α) : s.ncard - 1 ≤ (s \ {a}).ncard := by
cases' s.finite_or_infinite with hs hs
· by_cases h : a ∈ s
· rw [ncard_diff_singleton_of_mem h hs]
rw [diff_singleton_eq_self h]
apply Nat.pred_le
convert Nat.zero_le _
rw [hs.ncard]
#align set.pred_ncard_le_ncard_diff_singleton Set.pred_ncard_le_ncard_diff_singleton
theorem ncard_exchange {a b : α} (ha : a ∉ s) (hb : b ∈ s) : (insert a (s \ {b})).ncard = s.ncard :=
congr_arg ENat.toNat <| encard_exchange ha hb
#align set.ncard_exchange Set.ncard_exchange
theorem ncard_exchange' {a b : α} (ha : a ∉ s) (hb : b ∈ s) :
(insert a s \ {b}).ncard = s.ncard := by
rw [← ncard_exchange ha hb, ← singleton_union, ← singleton_union, union_diff_distrib,
@diff_singleton_eq_self _ b {a} fun h ↦ ha (by rwa [← mem_singleton_iff.mp h])]
#align set.ncard_exchange' Set.ncard_exchange'
end InsertErase
variable {f : α → β}
theorem ncard_image_le (hs : s.Finite := by toFinite_tac) : (f '' s).ncard ≤ s.ncard := by
to_encard_tac; rw [hs.cast_ncard_eq, (hs.image _).cast_ncard_eq]; apply encard_image_le
#align set.ncard_image_le Set.ncard_image_le
theorem ncard_image_of_injOn (H : Set.InjOn f s) : (f '' s).ncard = s.ncard :=
congr_arg ENat.toNat <| H.encard_image
#align set.ncard_image_of_inj_on Set.ncard_image_of_injOn
theorem injOn_of_ncard_image_eq (h : (f '' s).ncard = s.ncard) (hs : s.Finite := by toFinite_tac) :
Set.InjOn f s := by
rw [← Nat.cast_inj (R := ℕ∞), hs.cast_ncard_eq, (hs.image _).cast_ncard_eq] at h
exact hs.injOn_of_encard_image_eq h
#align set.inj_on_of_ncard_image_eq Set.injOn_of_ncard_image_eq
theorem ncard_image_iff (hs : s.Finite := by toFinite_tac) :
(f '' s).ncard = s.ncard ↔ Set.InjOn f s :=
⟨fun h ↦ injOn_of_ncard_image_eq h hs, ncard_image_of_injOn⟩
#align set.ncard_image_iff Set.ncard_image_iff
theorem ncard_image_of_injective (s : Set α) (H : f.Injective) : (f '' s).ncard = s.ncard :=
ncard_image_of_injOn fun _ _ _ _ h ↦ H h
#align set.ncard_image_of_injective Set.ncard_image_of_injective
theorem ncard_preimage_of_injective_subset_range {s : Set β} (H : f.Injective)
(hs : s ⊆ Set.range f) :
(f ⁻¹' s).ncard = s.ncard := by
rw [← ncard_image_of_injective _ H, image_preimage_eq_iff.mpr hs]
#align set.ncard_preimage_of_injective_subset_range Set.ncard_preimage_of_injective_subset_range
theorem fiber_ncard_ne_zero_iff_mem_image {y : β} (hs : s.Finite := by toFinite_tac) :
{ x ∈ s | f x = y }.ncard ≠ 0 ↔ y ∈ f '' s := by
refine ⟨nonempty_of_ncard_ne_zero, ?_⟩
rintro ⟨z, hz, rfl⟩
exact @ncard_ne_zero_of_mem _ ({ x ∈ s | f x = f z }) z (mem_sep hz rfl)
(hs.subset (sep_subset _ _))
#align set.fiber_ncard_ne_zero_iff_mem_image Set.fiber_ncard_ne_zero_iff_mem_image
@[simp] theorem ncard_map (f : α ↪ β) : (f '' s).ncard = s.ncard :=
ncard_image_of_injective _ f.inj'
#align set.ncard_map Set.ncard_map
@[simp] theorem ncard_subtype (P : α → Prop) (s : Set α) :
{ x : Subtype P | (x : α) ∈ s }.ncard = (s ∩ setOf P).ncard := by
convert (ncard_image_of_injective _ (@Subtype.coe_injective _ P)).symm
ext x
simp [← and_assoc, exists_eq_right]
#align set.ncard_subtype Set.ncard_subtype
theorem ncard_inter_le_ncard_left (s t : Set α) (hs : s.Finite := by toFinite_tac) :
(s ∩ t).ncard ≤ s.ncard :=
ncard_le_ncard inter_subset_left hs
#align set.ncard_inter_le_ncard_left Set.ncard_inter_le_ncard_left
theorem ncard_inter_le_ncard_right (s t : Set α) (ht : t.Finite := by toFinite_tac) :
(s ∩ t).ncard ≤ t.ncard :=
ncard_le_ncard inter_subset_right ht
#align set.ncard_inter_le_ncard_right Set.ncard_inter_le_ncard_right
theorem eq_of_subset_of_ncard_le (h : s ⊆ t) (h' : t.ncard ≤ s.ncard)
(ht : t.Finite := by toFinite_tac) : s = t :=
ht.eq_of_subset_of_encard_le h
(by rwa [← Nat.cast_le (α := ℕ∞), ht.cast_ncard_eq, (ht.subset h).cast_ncard_eq] at h')
#align set.eq_of_subset_of_ncard_le Set.eq_of_subset_of_ncard_le
theorem subset_iff_eq_of_ncard_le (h : t.ncard ≤ s.ncard) (ht : t.Finite := by toFinite_tac) :
s ⊆ t ↔ s = t :=
⟨fun hst ↦ eq_of_subset_of_ncard_le hst h ht, Eq.subset'⟩
#align set.subset_iff_eq_of_ncard_le Set.subset_iff_eq_of_ncard_le
theorem map_eq_of_subset {f : α ↪ α} (h : f '' s ⊆ s) (hs : s.Finite := by toFinite_tac) :
f '' s = s :=
eq_of_subset_of_ncard_le h (ncard_map _).ge hs
#align set.map_eq_of_subset Set.map_eq_of_subset
theorem sep_of_ncard_eq {a : α} {P : α → Prop} (h : { x ∈ s | P x }.ncard = s.ncard) (ha : a ∈ s)
(hs : s.Finite := by toFinite_tac) : P a :=
sep_eq_self_iff_mem_true.mp (eq_of_subset_of_ncard_le (by simp) h.symm.le hs) _ ha
#align set.sep_of_ncard_eq Set.sep_of_ncard_eq
theorem ncard_lt_ncard (h : s ⊂ t) (ht : t.Finite := by toFinite_tac) :
s.ncard < t.ncard := by
rw [← Nat.cast_lt (α := ℕ∞), ht.cast_ncard_eq, (ht.subset h.subset).cast_ncard_eq]
exact ht.encard_lt_encard h
#align set.ncard_lt_ncard Set.ncard_lt_ncard
theorem ncard_strictMono [Finite α] : @StrictMono (Set α) _ _ _ ncard :=
fun _ _ h ↦ ncard_lt_ncard h
#align set.ncard_strict_mono Set.ncard_strictMono
theorem ncard_eq_of_bijective {n : ℕ} (f : ∀ i, i < n → α)
(hf : ∀ a ∈ s, ∃ i, ∃ h : i < n, f i h = a) (hf' : ∀ (i) (h : i < n), f i h ∈ s)
(f_inj : ∀ (i j) (hi : i < n) (hj : j < n), f i hi = f j hj → i = j) : s.ncard = n := by
let f' : Fin n → α := fun i ↦ f i.val i.is_lt
suffices himage : s = f' '' Set.univ by
rw [← Fintype.card_fin n, ← Nat.card_eq_fintype_card, ← Set.ncard_univ, himage]
exact ncard_image_of_injOn <| fun i _hi j _hj h ↦ Fin.ext <| f_inj i.val j.val i.is_lt j.is_lt h
ext x
simp only [image_univ, mem_range]
refine ⟨fun hx ↦ ?_, fun ⟨⟨i, hi⟩, hx⟩ ↦ hx ▸ hf' i hi⟩
obtain ⟨i, hi, rfl⟩ := hf x hx
use ⟨i, hi⟩
#align set.ncard_eq_of_bijective Set.ncard_eq_of_bijective
theorem ncard_congr {t : Set β} (f : ∀ a ∈ s, β) (h₁ : ∀ a ha, f a ha ∈ t)
(h₂ : ∀ a b ha hb, f a ha = f b hb → a = b) (h₃ : ∀ b ∈ t, ∃ a ha, f a ha = b) :
s.ncard = t.ncard := by
set f' : s → t := fun x ↦ ⟨f x.1 x.2, h₁ _ _⟩
have hbij : f'.Bijective := by
constructor
· rintro ⟨x, hx⟩ ⟨y, hy⟩ hxy
simp only [f', Subtype.mk.injEq] at hxy ⊢
exact h₂ _ _ hx hy hxy
rintro ⟨y, hy⟩
obtain ⟨a, ha, rfl⟩ := h₃ y hy
simp only [Subtype.mk.injEq, Subtype.exists]
exact ⟨_, ha, rfl⟩
simp_rw [← Nat.card_coe_set_eq]
exact Nat.card_congr (Equiv.ofBijective f' hbij)
#align set.ncard_congr Set.ncard_congr
theorem ncard_le_ncard_of_injOn {t : Set β} (f : α → β) (hf : ∀ a ∈ s, f a ∈ t) (f_inj : InjOn f s)
(ht : t.Finite := by toFinite_tac) :
s.ncard ≤ t.ncard := by
have hle := encard_le_encard_of_injOn hf f_inj
to_encard_tac; rwa [ht.cast_ncard_eq, (ht.finite_of_encard_le hle).cast_ncard_eq]
#align set.ncard_le_ncard_of_inj_on Set.ncard_le_ncard_of_injOn
theorem exists_ne_map_eq_of_ncard_lt_of_maps_to {t : Set β} (hc : t.ncard < s.ncard) {f : α → β}
(hf : ∀ a ∈ s, f a ∈ t) (ht : t.Finite := by toFinite_tac) :
∃ x ∈ s, ∃ y ∈ s, x ≠ y ∧ f x = f y := by
by_contra h'
simp only [Ne, exists_prop, not_exists, not_and, not_imp_not] at h'
exact (ncard_le_ncard_of_injOn f hf h' ht).not_lt hc
#align set.exists_ne_map_eq_of_ncard_lt_of_maps_to Set.exists_ne_map_eq_of_ncard_lt_of_maps_to
theorem le_ncard_of_inj_on_range {n : ℕ} (f : ℕ → α) (hf : ∀ i < n, f i ∈ s)
(f_inj : ∀ i < n, ∀ j < n, f i = f j → i = j) (hs : s.Finite := by toFinite_tac) :
n ≤ s.ncard := by
rw [ncard_eq_toFinset_card _ hs]
apply Finset.le_card_of_inj_on_range <;> simpa
#align set.le_ncard_of_inj_on_range Set.le_ncard_of_inj_on_range
| Mathlib/Data/Set/Card.lean | 794 | 813 | theorem surj_on_of_inj_on_of_ncard_le {t : Set β} (f : ∀ a ∈ s, β) (hf : ∀ a ha, f a ha ∈ t)
(hinj : ∀ a₁ a₂ ha₁ ha₂, f a₁ ha₁ = f a₂ ha₂ → a₁ = a₂) (hst : t.ncard ≤ s.ncard)
(ht : t.Finite := by | toFinite_tac) :
∀ b ∈ t, ∃ a ha, b = f a ha := by
intro b hb
set f' : s → t := fun x ↦ ⟨f x.1 x.2, hf _ _⟩
have finj : f'.Injective := by
rintro ⟨x, hx⟩ ⟨y, hy⟩ hxy
simp only [f', Subtype.mk.injEq] at hxy ⊢
apply hinj _ _ hx hy hxy
have hft := ht.fintype
have hft' := Fintype.ofInjective f' finj
set f'' : ∀ a, a ∈ s.toFinset → β := fun a h ↦ f a (by simpa using h)
convert @Finset.surj_on_of_inj_on_of_card_le _ _ _ t.toFinset f'' _ _ _ _ (by simpa)
· simp
· simp [hf]
· intros a₁ a₂ ha₁ ha₂ h
rw [mem_toFinset] at ha₁ ha₂
exact hinj _ _ ha₁ ha₂ h
rwa [← ncard_eq_toFinset_card', ← ncard_eq_toFinset_card']
|
/-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Mario Carneiro, Yury Kudryashov
-/
import Mathlib.MeasureTheory.Measure.AEDisjoint
import Mathlib.MeasureTheory.Constructions.EventuallyMeasurable
#align_import measure_theory.measure.null_measurable from "leanprover-community/mathlib"@"e4edb23029fff178210b9945dcb77d293f001e1c"
/-!
# Null measurable sets and complete measures
## Main definitions
### Null measurable sets and functions
A set `s : Set α` is called *null measurable* (`MeasureTheory.NullMeasurableSet`) if it satisfies
any of the following equivalent conditions:
* there exists a measurable set `t` such that `s =ᵐ[μ] t` (this is used as a definition);
* `MeasureTheory.toMeasurable μ s =ᵐ[μ] s`;
* there exists a measurable subset `t ⊆ s` such that `t =ᵐ[μ] s` (in this case the latter equality
means that `μ (s \ t) = 0`);
* `s` can be represented as a union of a measurable set and a set of measure zero;
* `s` can be represented as a difference of a measurable set and a set of measure zero.
Null measurable sets form a σ-algebra that is registered as a `MeasurableSpace` instance on
`MeasureTheory.NullMeasurableSpace α μ`. We also say that `f : α → β` is
`MeasureTheory.NullMeasurable` if the preimage of a measurable set is a null measurable set.
In other words, `f : α → β` is null measurable if it is measurable as a function
`MeasureTheory.NullMeasurableSpace α μ → β`.
### Complete measures
We say that a measure `μ` is complete w.r.t. the `MeasurableSpace α` σ-algebra (or the σ-algebra is
complete w.r.t measure `μ`) if every set of measure zero is measurable. In this case all null
measurable sets and functions are measurable.
For each measure `μ`, we define `MeasureTheory.Measure.completion μ` to be the same measure
interpreted as a measure on `MeasureTheory.NullMeasurableSpace α μ` and prove that this is a
complete measure.
## Implementation notes
We define `MeasureTheory.NullMeasurableSet` as `@MeasurableSet (NullMeasurableSpace α μ) _` so
that theorems about `MeasurableSet`s like `MeasurableSet.union` can be applied to
`NullMeasurableSet`s. However, these lemmas output terms of the same form
`@MeasurableSet (NullMeasurableSpace α μ) _ _`. While this is definitionally equal to the
expected output `NullMeasurableSet s μ`, it looks different and may be misleading. So we copy all
standard lemmas about measurable sets to the `MeasureTheory.NullMeasurableSet` namespace and fix
the output type.
## Tags
measurable, measure, null measurable, completion
-/
open Filter Set Encodable
variable {ι α β γ : Type*}
namespace MeasureTheory
/-- A type tag for `α` with `MeasurableSet` given by `NullMeasurableSet`. -/
@[nolint unusedArguments]
def NullMeasurableSpace (α : Type*) [MeasurableSpace α]
(_μ : Measure α := by volume_tac) : Type _ :=
α
#align measure_theory.null_measurable_space MeasureTheory.NullMeasurableSpace
section
variable {m0 : MeasurableSpace α} {μ : Measure α} {s t : Set α}
instance NullMeasurableSpace.instInhabited [h : Inhabited α] :
Inhabited (NullMeasurableSpace α μ) :=
h
#align measure_theory.null_measurable_space.inhabited MeasureTheory.NullMeasurableSpace.instInhabited
instance NullMeasurableSpace.instSubsingleton [h : Subsingleton α] :
Subsingleton (NullMeasurableSpace α μ) :=
h
#align measure_theory.null_measurable_space.subsingleton MeasureTheory.NullMeasurableSpace.instSubsingleton
instance NullMeasurableSpace.instMeasurableSpace : MeasurableSpace (NullMeasurableSpace α μ) :=
@EventuallyMeasurableSpace α inferInstance (ae μ) _
/-- A set is called `NullMeasurableSet` if it can be approximated by a measurable set up to
a set of null measure. -/
def NullMeasurableSet [MeasurableSpace α] (s : Set α)
(μ : Measure α := by volume_tac) : Prop :=
@MeasurableSet (NullMeasurableSpace α μ) _ s
#align measure_theory.null_measurable_set MeasureTheory.NullMeasurableSet
@[simp]
theorem _root_.MeasurableSet.nullMeasurableSet (h : MeasurableSet s) : NullMeasurableSet s μ :=
h.eventuallyMeasurableSet
#align measurable_set.null_measurable_set MeasurableSet.nullMeasurableSet
-- @[simp] -- Porting note (#10618): simp can prove this
theorem nullMeasurableSet_empty : NullMeasurableSet ∅ μ :=
MeasurableSet.empty
#align measure_theory.null_measurable_set_empty MeasureTheory.nullMeasurableSet_empty
-- @[simp] -- Porting note (#10618): simp can prove this
theorem nullMeasurableSet_univ : NullMeasurableSet univ μ :=
MeasurableSet.univ
#align measure_theory.null_measurable_set_univ MeasureTheory.nullMeasurableSet_univ
namespace NullMeasurableSet
theorem of_null (h : μ s = 0) : NullMeasurableSet s μ :=
⟨∅, MeasurableSet.empty, ae_eq_empty.2 h⟩
#align measure_theory.null_measurable_set.of_null MeasureTheory.NullMeasurableSet.of_null
theorem compl (h : NullMeasurableSet s μ) : NullMeasurableSet sᶜ μ :=
MeasurableSet.compl h
#align measure_theory.null_measurable_set.compl MeasureTheory.NullMeasurableSet.compl
theorem of_compl (h : NullMeasurableSet sᶜ μ) : NullMeasurableSet s μ :=
MeasurableSet.of_compl h
#align measure_theory.null_measurable_set.of_compl MeasureTheory.NullMeasurableSet.of_compl
@[simp]
theorem compl_iff : NullMeasurableSet sᶜ μ ↔ NullMeasurableSet s μ :=
MeasurableSet.compl_iff
#align measure_theory.null_measurable_set.compl_iff MeasureTheory.NullMeasurableSet.compl_iff
@[nontriviality]
theorem of_subsingleton [Subsingleton α] : NullMeasurableSet s μ :=
Subsingleton.measurableSet
#align measure_theory.null_measurable_set.of_subsingleton MeasureTheory.NullMeasurableSet.of_subsingleton
protected theorem congr (hs : NullMeasurableSet s μ) (h : s =ᵐ[μ] t) : NullMeasurableSet t μ :=
EventuallyMeasurableSet.congr hs h.symm
#align measure_theory.null_measurable_set.congr MeasureTheory.NullMeasurableSet.congr
protected theorem iUnion {ι : Sort*} [Countable ι] {s : ι → Set α}
(h : ∀ i, NullMeasurableSet (s i) μ) : NullMeasurableSet (⋃ i, s i) μ :=
MeasurableSet.iUnion h
#align measure_theory.null_measurable_set.Union MeasureTheory.NullMeasurableSet.iUnion
@[deprecated iUnion (since := "2023-05-06")]
protected theorem biUnion_decode₂ [Encodable ι] ⦃f : ι → Set α⦄ (h : ∀ i, NullMeasurableSet (f i) μ)
(n : ℕ) : NullMeasurableSet (⋃ b ∈ Encodable.decode₂ ι n, f b) μ :=
.iUnion fun _ => .iUnion fun _ => h _
#align measure_theory.null_measurable_set.bUnion_decode₂ MeasureTheory.NullMeasurableSet.biUnion_decode₂
protected theorem biUnion {f : ι → Set α} {s : Set ι} (hs : s.Countable)
(h : ∀ b ∈ s, NullMeasurableSet (f b) μ) : NullMeasurableSet (⋃ b ∈ s, f b) μ :=
MeasurableSet.biUnion hs h
#align measure_theory.null_measurable_set.bUnion MeasureTheory.NullMeasurableSet.biUnion
protected theorem sUnion {s : Set (Set α)} (hs : s.Countable) (h : ∀ t ∈ s, NullMeasurableSet t μ) :
NullMeasurableSet (⋃₀ s) μ := by
rw [sUnion_eq_biUnion]
exact MeasurableSet.biUnion hs h
#align measure_theory.null_measurable_set.sUnion MeasureTheory.NullMeasurableSet.sUnion
protected theorem iInter {ι : Sort*} [Countable ι] {f : ι → Set α}
(h : ∀ i, NullMeasurableSet (f i) μ) : NullMeasurableSet (⋂ i, f i) μ :=
MeasurableSet.iInter h
#align measure_theory.null_measurable_set.Inter MeasureTheory.NullMeasurableSet.iInter
protected theorem biInter {f : β → Set α} {s : Set β} (hs : s.Countable)
(h : ∀ b ∈ s, NullMeasurableSet (f b) μ) : NullMeasurableSet (⋂ b ∈ s, f b) μ :=
MeasurableSet.biInter hs h
#align measure_theory.null_measurable_set.bInter MeasureTheory.NullMeasurableSet.biInter
protected theorem sInter {s : Set (Set α)} (hs : s.Countable) (h : ∀ t ∈ s, NullMeasurableSet t μ) :
NullMeasurableSet (⋂₀ s) μ :=
MeasurableSet.sInter hs h
#align measure_theory.null_measurable_set.sInter MeasureTheory.NullMeasurableSet.sInter
@[simp]
protected theorem union (hs : NullMeasurableSet s μ) (ht : NullMeasurableSet t μ) :
NullMeasurableSet (s ∪ t) μ :=
MeasurableSet.union hs ht
#align measure_theory.null_measurable_set.union MeasureTheory.NullMeasurableSet.union
protected theorem union_null (hs : NullMeasurableSet s μ) (ht : μ t = 0) :
NullMeasurableSet (s ∪ t) μ :=
hs.union (of_null ht)
#align measure_theory.null_measurable_set.union_null MeasureTheory.NullMeasurableSet.union_null
@[simp]
protected theorem inter (hs : NullMeasurableSet s μ) (ht : NullMeasurableSet t μ) :
NullMeasurableSet (s ∩ t) μ :=
MeasurableSet.inter hs ht
#align measure_theory.null_measurable_set.inter MeasureTheory.NullMeasurableSet.inter
@[simp]
protected theorem diff (hs : NullMeasurableSet s μ) (ht : NullMeasurableSet t μ) :
NullMeasurableSet (s \ t) μ :=
MeasurableSet.diff hs ht
#align measure_theory.null_measurable_set.diff MeasureTheory.NullMeasurableSet.diff
@[simp]
protected theorem disjointed {f : ℕ → Set α} (h : ∀ i, NullMeasurableSet (f i) μ) (n) :
NullMeasurableSet (disjointed f n) μ :=
MeasurableSet.disjointed h n
#align measure_theory.null_measurable_set.disjointed MeasureTheory.NullMeasurableSet.disjointed
-- @[simp] -- Porting note (#10618): simp can prove thisrove this
protected theorem const (p : Prop) : NullMeasurableSet { _a : α | p } μ :=
MeasurableSet.const p
#align measure_theory.null_measurable_set.const MeasureTheory.NullMeasurableSet.const
instance instMeasurableSingletonClass [MeasurableSingletonClass α] :
MeasurableSingletonClass (NullMeasurableSpace α μ) :=
EventuallyMeasurableSpace.measurableSingleton (m := m0)
#align measure_theory.null_measurable_set.measure_theory.null_measurable_space.measurable_singleton_class MeasureTheory.NullMeasurableSet.instMeasurableSingletonClass
protected theorem insert [MeasurableSingletonClass (NullMeasurableSpace α μ)]
(hs : NullMeasurableSet s μ) (a : α) : NullMeasurableSet (insert a s) μ :=
MeasurableSet.insert hs a
#align measure_theory.null_measurable_set.insert MeasureTheory.NullMeasurableSet.insert
theorem exists_measurable_superset_ae_eq (h : NullMeasurableSet s μ) :
∃ t ⊇ s, MeasurableSet t ∧ t =ᵐ[μ] s := by
rcases h with ⟨t, htm, hst⟩
refine ⟨t ∪ toMeasurable μ (s \ t), ?_, htm.union (measurableSet_toMeasurable _ _), ?_⟩
· exact diff_subset_iff.1 (subset_toMeasurable _ _)
· have : toMeasurable μ (s \ t) =ᵐ[μ] (∅ : Set α) := by simp [ae_le_set.1 hst.le]
simpa only [union_empty] using hst.symm.union this
#align measure_theory.null_measurable_set.exists_measurable_superset_ae_eq MeasureTheory.NullMeasurableSet.exists_measurable_superset_ae_eq
theorem toMeasurable_ae_eq (h : NullMeasurableSet s μ) : toMeasurable μ s =ᵐ[μ] s := by
rw [toMeasurable_def, dif_pos]
exact (exists_measurable_superset_ae_eq h).choose_spec.2.2
#align measure_theory.null_measurable_set.to_measurable_ae_eq MeasureTheory.NullMeasurableSet.toMeasurable_ae_eq
theorem compl_toMeasurable_compl_ae_eq (h : NullMeasurableSet s μ) : (toMeasurable μ sᶜ)ᶜ =ᵐ[μ] s :=
Iff.mpr ae_eq_set_compl <| toMeasurable_ae_eq h.compl
#align measure_theory.null_measurable_set.compl_to_measurable_compl_ae_eq MeasureTheory.NullMeasurableSet.compl_toMeasurable_compl_ae_eq
theorem exists_measurable_subset_ae_eq (h : NullMeasurableSet s μ) :
∃ t ⊆ s, MeasurableSet t ∧ t =ᵐ[μ] s :=
⟨(toMeasurable μ sᶜ)ᶜ, compl_subset_comm.2 <| subset_toMeasurable _ _,
(measurableSet_toMeasurable _ _).compl, compl_toMeasurable_compl_ae_eq h⟩
#align measure_theory.null_measurable_set.exists_measurable_subset_ae_eq MeasureTheory.NullMeasurableSet.exists_measurable_subset_ae_eq
end NullMeasurableSet
open NullMeasurableSet
/-- If `sᵢ` is a countable family of (null) measurable pairwise `μ`-a.e. disjoint sets, then there
exists a subordinate family `tᵢ ⊆ sᵢ` of measurable pairwise disjoint sets such that
`tᵢ =ᵐ[μ] sᵢ`. -/
theorem exists_subordinate_pairwise_disjoint [Countable ι] {s : ι → Set α}
(h : ∀ i, NullMeasurableSet (s i) μ) (hd : Pairwise (AEDisjoint μ on s)) :
∃ t : ι → Set α,
(∀ i, t i ⊆ s i) ∧
(∀ i, s i =ᵐ[μ] t i) ∧ (∀ i, MeasurableSet (t i)) ∧ Pairwise (Disjoint on t) := by
choose t ht_sub htm ht_eq using fun i => exists_measurable_subset_ae_eq (h i)
rcases exists_null_pairwise_disjoint_diff hd with ⟨u, hum, hu₀, hud⟩
exact
⟨fun i => t i \ u i, fun i => diff_subset.trans (ht_sub _), fun i =>
(ht_eq _).symm.trans (diff_null_ae_eq_self (hu₀ i)).symm, fun i => (htm i).diff (hum i),
hud.mono fun i j h =>
h.mono (diff_subset_diff_left (ht_sub i)) (diff_subset_diff_left (ht_sub j))⟩
#align measure_theory.exists_subordinate_pairwise_disjoint MeasureTheory.exists_subordinate_pairwise_disjoint
| Mathlib/MeasureTheory/Measure/NullMeasurable.lean | 266 | 273 | theorem measure_iUnion {m0 : MeasurableSpace α} {μ : Measure α} [Countable ι] {f : ι → Set α}
(hn : Pairwise (Disjoint on f)) (h : ∀ i, MeasurableSet (f i)) :
μ (⋃ i, f i) = ∑' i, μ (f i) := by |
rw [measure_eq_extend (MeasurableSet.iUnion h),
extend_iUnion MeasurableSet.empty _ MeasurableSet.iUnion _ hn h]
· simp [measure_eq_extend, h]
· exact μ.empty
· exact μ.m_iUnion
|
/-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura, Johannes Hölzl, Mario Carneiro
-/
import Mathlib.Logic.Pairwise
import Mathlib.Order.CompleteBooleanAlgebra
import Mathlib.Order.Directed
import Mathlib.Order.GaloisConnection
#align_import data.set.lattice from "leanprover-community/mathlib"@"b86832321b586c6ac23ef8cdef6a7a27e42b13bd"
/-!
# The set lattice
This file provides usual set notation for unions and intersections, a `CompleteLattice` instance
for `Set α`, and some more set constructions.
## Main declarations
* `Set.iUnion`: **i**ndexed **union**. Union of an indexed family of sets.
* `Set.iInter`: **i**ndexed **inter**section. Intersection of an indexed family of sets.
* `Set.sInter`: **s**et **inter**section. Intersection of sets belonging to a set of sets.
* `Set.sUnion`: **s**et **union**. Union of sets belonging to a set of sets.
* `Set.sInter_eq_biInter`, `Set.sUnion_eq_biInter`: Shows that `⋂₀ s = ⋂ x ∈ s, x` and
`⋃₀ s = ⋃ x ∈ s, x`.
* `Set.completeAtomicBooleanAlgebra`: `Set α` is a `CompleteAtomicBooleanAlgebra` with `≤ = ⊆`,
`< = ⊂`, `⊓ = ∩`, `⊔ = ∪`, `⨅ = ⋂`, `⨆ = ⋃` and `\` as the set difference.
See `Set.BooleanAlgebra`.
* `Set.kernImage`: For a function `f : α → β`, `s.kernImage f` is the set of `y` such that
`f ⁻¹ y ⊆ s`.
* `Set.seq`: Union of the image of a set under a **seq**uence of functions. `seq s t` is the union
of `f '' t` over all `f ∈ s`, where `t : Set α` and `s : Set (α → β)`.
* `Set.unionEqSigmaOfDisjoint`: Equivalence between `⋃ i, t i` and `Σ i, t i`, where `t` is an
indexed family of disjoint sets.
## Naming convention
In lemma names,
* `⋃ i, s i` is called `iUnion`
* `⋂ i, s i` is called `iInter`
* `⋃ i j, s i j` is called `iUnion₂`. This is an `iUnion` inside an `iUnion`.
* `⋂ i j, s i j` is called `iInter₂`. This is an `iInter` inside an `iInter`.
* `⋃ i ∈ s, t i` is called `biUnion` for "bounded `iUnion`". This is the special case of `iUnion₂`
where `j : i ∈ s`.
* `⋂ i ∈ s, t i` is called `biInter` for "bounded `iInter`". This is the special case of `iInter₂`
where `j : i ∈ s`.
## Notation
* `⋃`: `Set.iUnion`
* `⋂`: `Set.iInter`
* `⋃₀`: `Set.sUnion`
* `⋂₀`: `Set.sInter`
-/
open Function Set
universe u
variable {α β γ : Type*} {ι ι' ι₂ : Sort*} {κ κ₁ κ₂ : ι → Sort*} {κ' : ι' → Sort*}
namespace Set
/-! ### Complete lattice and complete Boolean algebra instances -/
theorem mem_iUnion₂ {x : γ} {s : ∀ i, κ i → Set γ} : (x ∈ ⋃ (i) (j), s i j) ↔ ∃ i j, x ∈ s i j := by
simp_rw [mem_iUnion]
#align set.mem_Union₂ Set.mem_iUnion₂
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/
theorem mem_iInter₂ {x : γ} {s : ∀ i, κ i → Set γ} : (x ∈ ⋂ (i) (j), s i j) ↔ ∀ i j, x ∈ s i j := by
simp_rw [mem_iInter]
#align set.mem_Inter₂ Set.mem_iInter₂
theorem mem_iUnion_of_mem {s : ι → Set α} {a : α} (i : ι) (ha : a ∈ s i) : a ∈ ⋃ i, s i :=
mem_iUnion.2 ⟨i, ha⟩
#align set.mem_Union_of_mem Set.mem_iUnion_of_mem
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/
theorem mem_iUnion₂_of_mem {s : ∀ i, κ i → Set α} {a : α} {i : ι} (j : κ i) (ha : a ∈ s i j) :
a ∈ ⋃ (i) (j), s i j :=
mem_iUnion₂.2 ⟨i, j, ha⟩
#align set.mem_Union₂_of_mem Set.mem_iUnion₂_of_mem
theorem mem_iInter_of_mem {s : ι → Set α} {a : α} (h : ∀ i, a ∈ s i) : a ∈ ⋂ i, s i :=
mem_iInter.2 h
#align set.mem_Inter_of_mem Set.mem_iInter_of_mem
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/
theorem mem_iInter₂_of_mem {s : ∀ i, κ i → Set α} {a : α} (h : ∀ i j, a ∈ s i j) :
a ∈ ⋂ (i) (j), s i j :=
mem_iInter₂.2 h
#align set.mem_Inter₂_of_mem Set.mem_iInter₂_of_mem
instance completeAtomicBooleanAlgebra : CompleteAtomicBooleanAlgebra (Set α) :=
{ instBooleanAlgebraSet with
le_sSup := fun s t t_in a a_in => ⟨t, t_in, a_in⟩
sSup_le := fun s t h a ⟨t', ⟨t'_in, a_in⟩⟩ => h t' t'_in a_in
le_sInf := fun s t h a a_in t' t'_in => h t' t'_in a_in
sInf_le := fun s t t_in a h => h _ t_in
iInf_iSup_eq := by intros; ext; simp [Classical.skolem] }
section GaloisConnection
variable {f : α → β}
protected theorem image_preimage : GaloisConnection (image f) (preimage f) := fun _ _ =>
image_subset_iff
#align set.image_preimage Set.image_preimage
protected theorem preimage_kernImage : GaloisConnection (preimage f) (kernImage f) := fun _ _ =>
subset_kernImage_iff.symm
#align set.preimage_kern_image Set.preimage_kernImage
end GaloisConnection
section kernImage
variable {f : α → β}
lemma kernImage_mono : Monotone (kernImage f) :=
Set.preimage_kernImage.monotone_u
lemma kernImage_eq_compl {s : Set α} : kernImage f s = (f '' sᶜ)ᶜ :=
Set.preimage_kernImage.u_unique (Set.image_preimage.compl)
(fun t ↦ compl_compl (f ⁻¹' t) ▸ Set.preimage_compl)
lemma kernImage_compl {s : Set α} : kernImage f (sᶜ) = (f '' s)ᶜ := by
rw [kernImage_eq_compl, compl_compl]
lemma kernImage_empty : kernImage f ∅ = (range f)ᶜ := by
rw [kernImage_eq_compl, compl_empty, image_univ]
lemma kernImage_preimage_eq_iff {s : Set β} : kernImage f (f ⁻¹' s) = s ↔ (range f)ᶜ ⊆ s := by
rw [kernImage_eq_compl, ← preimage_compl, compl_eq_comm, eq_comm, image_preimage_eq_iff,
compl_subset_comm]
lemma compl_range_subset_kernImage {s : Set α} : (range f)ᶜ ⊆ kernImage f s := by
rw [← kernImage_empty]
exact kernImage_mono (empty_subset _)
lemma kernImage_union_preimage {s : Set α} {t : Set β} :
kernImage f (s ∪ f ⁻¹' t) = kernImage f s ∪ t := by
rw [kernImage_eq_compl, kernImage_eq_compl, compl_union, ← preimage_compl, image_inter_preimage,
compl_inter, compl_compl]
lemma kernImage_preimage_union {s : Set α} {t : Set β} :
kernImage f (f ⁻¹' t ∪ s) = t ∪ kernImage f s := by
rw [union_comm, kernImage_union_preimage, union_comm]
end kernImage
/-! ### Union and intersection over an indexed family of sets -/
instance : OrderTop (Set α) where
top := univ
le_top := by simp
@[congr]
theorem iUnion_congr_Prop {p q : Prop} {f₁ : p → Set α} {f₂ : q → Set α} (pq : p ↔ q)
(f : ∀ x, f₁ (pq.mpr x) = f₂ x) : iUnion f₁ = iUnion f₂ :=
iSup_congr_Prop pq f
#align set.Union_congr_Prop Set.iUnion_congr_Prop
@[congr]
theorem iInter_congr_Prop {p q : Prop} {f₁ : p → Set α} {f₂ : q → Set α} (pq : p ↔ q)
(f : ∀ x, f₁ (pq.mpr x) = f₂ x) : iInter f₁ = iInter f₂ :=
iInf_congr_Prop pq f
#align set.Inter_congr_Prop Set.iInter_congr_Prop
theorem iUnion_plift_up (f : PLift ι → Set α) : ⋃ i, f (PLift.up i) = ⋃ i, f i :=
iSup_plift_up _
#align set.Union_plift_up Set.iUnion_plift_up
theorem iUnion_plift_down (f : ι → Set α) : ⋃ i, f (PLift.down i) = ⋃ i, f i :=
iSup_plift_down _
#align set.Union_plift_down Set.iUnion_plift_down
theorem iInter_plift_up (f : PLift ι → Set α) : ⋂ i, f (PLift.up i) = ⋂ i, f i :=
iInf_plift_up _
#align set.Inter_plift_up Set.iInter_plift_up
theorem iInter_plift_down (f : ι → Set α) : ⋂ i, f (PLift.down i) = ⋂ i, f i :=
iInf_plift_down _
#align set.Inter_plift_down Set.iInter_plift_down
theorem iUnion_eq_if {p : Prop} [Decidable p] (s : Set α) : ⋃ _ : p, s = if p then s else ∅ :=
iSup_eq_if _
#align set.Union_eq_if Set.iUnion_eq_if
theorem iUnion_eq_dif {p : Prop} [Decidable p] (s : p → Set α) :
⋃ h : p, s h = if h : p then s h else ∅ :=
iSup_eq_dif _
#align set.Union_eq_dif Set.iUnion_eq_dif
theorem iInter_eq_if {p : Prop} [Decidable p] (s : Set α) : ⋂ _ : p, s = if p then s else univ :=
iInf_eq_if _
#align set.Inter_eq_if Set.iInter_eq_if
theorem iInf_eq_dif {p : Prop} [Decidable p] (s : p → Set α) :
⋂ h : p, s h = if h : p then s h else univ :=
_root_.iInf_eq_dif _
#align set.Infi_eq_dif Set.iInf_eq_dif
theorem exists_set_mem_of_union_eq_top {ι : Type*} (t : Set ι) (s : ι → Set β)
(w : ⋃ i ∈ t, s i = ⊤) (x : β) : ∃ i ∈ t, x ∈ s i := by
have p : x ∈ ⊤ := Set.mem_univ x
rw [← w, Set.mem_iUnion] at p
simpa using p
#align set.exists_set_mem_of_union_eq_top Set.exists_set_mem_of_union_eq_top
theorem nonempty_of_union_eq_top_of_nonempty {ι : Type*} (t : Set ι) (s : ι → Set α)
(H : Nonempty α) (w : ⋃ i ∈ t, s i = ⊤) : t.Nonempty := by
obtain ⟨x, m, -⟩ := exists_set_mem_of_union_eq_top t s w H.some
exact ⟨x, m⟩
#align set.nonempty_of_union_eq_top_of_nonempty Set.nonempty_of_union_eq_top_of_nonempty
theorem nonempty_of_nonempty_iUnion
{s : ι → Set α} (h_Union : (⋃ i, s i).Nonempty) : Nonempty ι := by
obtain ⟨x, hx⟩ := h_Union
exact ⟨Classical.choose <| mem_iUnion.mp hx⟩
theorem nonempty_of_nonempty_iUnion_eq_univ
{s : ι → Set α} [Nonempty α] (h_Union : ⋃ i, s i = univ) : Nonempty ι :=
nonempty_of_nonempty_iUnion (s := s) (by simpa only [h_Union] using univ_nonempty)
theorem setOf_exists (p : ι → β → Prop) : { x | ∃ i, p i x } = ⋃ i, { x | p i x } :=
ext fun _ => mem_iUnion.symm
#align set.set_of_exists Set.setOf_exists
theorem setOf_forall (p : ι → β → Prop) : { x | ∀ i, p i x } = ⋂ i, { x | p i x } :=
ext fun _ => mem_iInter.symm
#align set.set_of_forall Set.setOf_forall
theorem iUnion_subset {s : ι → Set α} {t : Set α} (h : ∀ i, s i ⊆ t) : ⋃ i, s i ⊆ t :=
iSup_le h
#align set.Union_subset Set.iUnion_subset
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/
theorem iUnion₂_subset {s : ∀ i, κ i → Set α} {t : Set α} (h : ∀ i j, s i j ⊆ t) :
⋃ (i) (j), s i j ⊆ t :=
iUnion_subset fun x => iUnion_subset (h x)
#align set.Union₂_subset Set.iUnion₂_subset
theorem subset_iInter {t : Set β} {s : ι → Set β} (h : ∀ i, t ⊆ s i) : t ⊆ ⋂ i, s i :=
le_iInf h
#align set.subset_Inter Set.subset_iInter
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/
theorem subset_iInter₂ {s : Set α} {t : ∀ i, κ i → Set α} (h : ∀ i j, s ⊆ t i j) :
s ⊆ ⋂ (i) (j), t i j :=
subset_iInter fun x => subset_iInter <| h x
#align set.subset_Inter₂ Set.subset_iInter₂
@[simp]
theorem iUnion_subset_iff {s : ι → Set α} {t : Set α} : ⋃ i, s i ⊆ t ↔ ∀ i, s i ⊆ t :=
⟨fun h _ => Subset.trans (le_iSup s _) h, iUnion_subset⟩
#align set.Union_subset_iff Set.iUnion_subset_iff
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/
theorem iUnion₂_subset_iff {s : ∀ i, κ i → Set α} {t : Set α} :
⋃ (i) (j), s i j ⊆ t ↔ ∀ i j, s i j ⊆ t := by simp_rw [iUnion_subset_iff]
#align set.Union₂_subset_iff Set.iUnion₂_subset_iff
@[simp]
theorem subset_iInter_iff {s : Set α} {t : ι → Set α} : (s ⊆ ⋂ i, t i) ↔ ∀ i, s ⊆ t i :=
le_iInf_iff
#align set.subset_Inter_iff Set.subset_iInter_iff
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/
-- Porting note (#10618): removing `simp`. `simp` can prove it
theorem subset_iInter₂_iff {s : Set α} {t : ∀ i, κ i → Set α} :
(s ⊆ ⋂ (i) (j), t i j) ↔ ∀ i j, s ⊆ t i j := by simp_rw [subset_iInter_iff]
#align set.subset_Inter₂_iff Set.subset_iInter₂_iff
theorem subset_iUnion : ∀ (s : ι → Set β) (i : ι), s i ⊆ ⋃ i, s i :=
le_iSup
#align set.subset_Union Set.subset_iUnion
theorem iInter_subset : ∀ (s : ι → Set β) (i : ι), ⋂ i, s i ⊆ s i :=
iInf_le
#align set.Inter_subset Set.iInter_subset
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/
theorem subset_iUnion₂ {s : ∀ i, κ i → Set α} (i : ι) (j : κ i) : s i j ⊆ ⋃ (i') (j'), s i' j' :=
le_iSup₂ i j
#align set.subset_Union₂ Set.subset_iUnion₂
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/
theorem iInter₂_subset {s : ∀ i, κ i → Set α} (i : ι) (j : κ i) : ⋂ (i) (j), s i j ⊆ s i j :=
iInf₂_le i j
#align set.Inter₂_subset Set.iInter₂_subset
/-- This rather trivial consequence of `subset_iUnion`is convenient with `apply`, and has `i`
explicit for this purpose. -/
theorem subset_iUnion_of_subset {s : Set α} {t : ι → Set α} (i : ι) (h : s ⊆ t i) : s ⊆ ⋃ i, t i :=
le_iSup_of_le i h
#align set.subset_Union_of_subset Set.subset_iUnion_of_subset
/-- This rather trivial consequence of `iInter_subset`is convenient with `apply`, and has `i`
explicit for this purpose. -/
theorem iInter_subset_of_subset {s : ι → Set α} {t : Set α} (i : ι) (h : s i ⊆ t) :
⋂ i, s i ⊆ t :=
iInf_le_of_le i h
#align set.Inter_subset_of_subset Set.iInter_subset_of_subset
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/
/-- This rather trivial consequence of `subset_iUnion₂` is convenient with `apply`, and has `i` and
`j` explicit for this purpose. -/
theorem subset_iUnion₂_of_subset {s : Set α} {t : ∀ i, κ i → Set α} (i : ι) (j : κ i)
(h : s ⊆ t i j) : s ⊆ ⋃ (i) (j), t i j :=
le_iSup₂_of_le i j h
#align set.subset_Union₂_of_subset Set.subset_iUnion₂_of_subset
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/
/-- This rather trivial consequence of `iInter₂_subset` is convenient with `apply`, and has `i` and
`j` explicit for this purpose. -/
theorem iInter₂_subset_of_subset {s : ∀ i, κ i → Set α} {t : Set α} (i : ι) (j : κ i)
(h : s i j ⊆ t) : ⋂ (i) (j), s i j ⊆ t :=
iInf₂_le_of_le i j h
#align set.Inter₂_subset_of_subset Set.iInter₂_subset_of_subset
theorem iUnion_mono {s t : ι → Set α} (h : ∀ i, s i ⊆ t i) : ⋃ i, s i ⊆ ⋃ i, t i :=
iSup_mono h
#align set.Union_mono Set.iUnion_mono
@[gcongr]
theorem iUnion_mono'' {s t : ι → Set α} (h : ∀ i, s i ⊆ t i) : iUnion s ⊆ iUnion t :=
iSup_mono h
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/
theorem iUnion₂_mono {s t : ∀ i, κ i → Set α} (h : ∀ i j, s i j ⊆ t i j) :
⋃ (i) (j), s i j ⊆ ⋃ (i) (j), t i j :=
iSup₂_mono h
#align set.Union₂_mono Set.iUnion₂_mono
theorem iInter_mono {s t : ι → Set α} (h : ∀ i, s i ⊆ t i) : ⋂ i, s i ⊆ ⋂ i, t i :=
iInf_mono h
#align set.Inter_mono Set.iInter_mono
@[gcongr]
theorem iInter_mono'' {s t : ι → Set α} (h : ∀ i, s i ⊆ t i) : iInter s ⊆ iInter t :=
iInf_mono h
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/
theorem iInter₂_mono {s t : ∀ i, κ i → Set α} (h : ∀ i j, s i j ⊆ t i j) :
⋂ (i) (j), s i j ⊆ ⋂ (i) (j), t i j :=
iInf₂_mono h
#align set.Inter₂_mono Set.iInter₂_mono
theorem iUnion_mono' {s : ι → Set α} {t : ι₂ → Set α} (h : ∀ i, ∃ j, s i ⊆ t j) :
⋃ i, s i ⊆ ⋃ i, t i :=
iSup_mono' h
#align set.Union_mono' Set.iUnion_mono'
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i' j') -/
theorem iUnion₂_mono' {s : ∀ i, κ i → Set α} {t : ∀ i', κ' i' → Set α}
(h : ∀ i j, ∃ i' j', s i j ⊆ t i' j') : ⋃ (i) (j), s i j ⊆ ⋃ (i') (j'), t i' j' :=
iSup₂_mono' h
#align set.Union₂_mono' Set.iUnion₂_mono'
theorem iInter_mono' {s : ι → Set α} {t : ι' → Set α} (h : ∀ j, ∃ i, s i ⊆ t j) :
⋂ i, s i ⊆ ⋂ j, t j :=
Set.subset_iInter fun j =>
let ⟨i, hi⟩ := h j
iInter_subset_of_subset i hi
#align set.Inter_mono' Set.iInter_mono'
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i' j') -/
theorem iInter₂_mono' {s : ∀ i, κ i → Set α} {t : ∀ i', κ' i' → Set α}
(h : ∀ i' j', ∃ i j, s i j ⊆ t i' j') : ⋂ (i) (j), s i j ⊆ ⋂ (i') (j'), t i' j' :=
subset_iInter₂_iff.2 fun i' j' =>
let ⟨_, _, hst⟩ := h i' j'
(iInter₂_subset _ _).trans hst
#align set.Inter₂_mono' Set.iInter₂_mono'
theorem iUnion₂_subset_iUnion (κ : ι → Sort*) (s : ι → Set α) :
⋃ (i) (_ : κ i), s i ⊆ ⋃ i, s i :=
iUnion_mono fun _ => iUnion_subset fun _ => Subset.rfl
#align set.Union₂_subset_Union Set.iUnion₂_subset_iUnion
theorem iInter_subset_iInter₂ (κ : ι → Sort*) (s : ι → Set α) :
⋂ i, s i ⊆ ⋂ (i) (_ : κ i), s i :=
iInter_mono fun _ => subset_iInter fun _ => Subset.rfl
#align set.Inter_subset_Inter₂ Set.iInter_subset_iInter₂
theorem iUnion_setOf (P : ι → α → Prop) : ⋃ i, { x : α | P i x } = { x : α | ∃ i, P i x } := by
ext
exact mem_iUnion
#align set.Union_set_of Set.iUnion_setOf
theorem iInter_setOf (P : ι → α → Prop) : ⋂ i, { x : α | P i x } = { x : α | ∀ i, P i x } := by
ext
exact mem_iInter
#align set.Inter_set_of Set.iInter_setOf
theorem iUnion_congr_of_surjective {f : ι → Set α} {g : ι₂ → Set α} (h : ι → ι₂) (h1 : Surjective h)
(h2 : ∀ x, g (h x) = f x) : ⋃ x, f x = ⋃ y, g y :=
h1.iSup_congr h h2
#align set.Union_congr_of_surjective Set.iUnion_congr_of_surjective
theorem iInter_congr_of_surjective {f : ι → Set α} {g : ι₂ → Set α} (h : ι → ι₂) (h1 : Surjective h)
(h2 : ∀ x, g (h x) = f x) : ⋂ x, f x = ⋂ y, g y :=
h1.iInf_congr h h2
#align set.Inter_congr_of_surjective Set.iInter_congr_of_surjective
lemma iUnion_congr {s t : ι → Set α} (h : ∀ i, s i = t i) : ⋃ i, s i = ⋃ i, t i := iSup_congr h
#align set.Union_congr Set.iUnion_congr
lemma iInter_congr {s t : ι → Set α} (h : ∀ i, s i = t i) : ⋂ i, s i = ⋂ i, t i := iInf_congr h
#align set.Inter_congr Set.iInter_congr
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/
lemma iUnion₂_congr {s t : ∀ i, κ i → Set α} (h : ∀ i j, s i j = t i j) :
⋃ (i) (j), s i j = ⋃ (i) (j), t i j :=
iUnion_congr fun i => iUnion_congr <| h i
#align set.Union₂_congr Set.iUnion₂_congr
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/
lemma iInter₂_congr {s t : ∀ i, κ i → Set α} (h : ∀ i j, s i j = t i j) :
⋂ (i) (j), s i j = ⋂ (i) (j), t i j :=
iInter_congr fun i => iInter_congr <| h i
#align set.Inter₂_congr Set.iInter₂_congr
section Nonempty
variable [Nonempty ι] {f : ι → Set α} {s : Set α}
lemma iUnion_const (s : Set β) : ⋃ _ : ι, s = s := iSup_const
#align set.Union_const Set.iUnion_const
lemma iInter_const (s : Set β) : ⋂ _ : ι, s = s := iInf_const
#align set.Inter_const Set.iInter_const
lemma iUnion_eq_const (hf : ∀ i, f i = s) : ⋃ i, f i = s :=
(iUnion_congr hf).trans <| iUnion_const _
#align set.Union_eq_const Set.iUnion_eq_const
lemma iInter_eq_const (hf : ∀ i, f i = s) : ⋂ i, f i = s :=
(iInter_congr hf).trans <| iInter_const _
#align set.Inter_eq_const Set.iInter_eq_const
end Nonempty
@[simp]
theorem compl_iUnion (s : ι → Set β) : (⋃ i, s i)ᶜ = ⋂ i, (s i)ᶜ :=
compl_iSup
#align set.compl_Union Set.compl_iUnion
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/
theorem compl_iUnion₂ (s : ∀ i, κ i → Set α) : (⋃ (i) (j), s i j)ᶜ = ⋂ (i) (j), (s i j)ᶜ := by
simp_rw [compl_iUnion]
#align set.compl_Union₂ Set.compl_iUnion₂
@[simp]
theorem compl_iInter (s : ι → Set β) : (⋂ i, s i)ᶜ = ⋃ i, (s i)ᶜ :=
compl_iInf
#align set.compl_Inter Set.compl_iInter
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/
theorem compl_iInter₂ (s : ∀ i, κ i → Set α) : (⋂ (i) (j), s i j)ᶜ = ⋃ (i) (j), (s i j)ᶜ := by
simp_rw [compl_iInter]
#align set.compl_Inter₂ Set.compl_iInter₂
-- classical -- complete_boolean_algebra
theorem iUnion_eq_compl_iInter_compl (s : ι → Set β) : ⋃ i, s i = (⋂ i, (s i)ᶜ)ᶜ := by
simp only [compl_iInter, compl_compl]
#align set.Union_eq_compl_Inter_compl Set.iUnion_eq_compl_iInter_compl
-- classical -- complete_boolean_algebra
theorem iInter_eq_compl_iUnion_compl (s : ι → Set β) : ⋂ i, s i = (⋃ i, (s i)ᶜ)ᶜ := by
simp only [compl_iUnion, compl_compl]
#align set.Inter_eq_compl_Union_compl Set.iInter_eq_compl_iUnion_compl
theorem inter_iUnion (s : Set β) (t : ι → Set β) : (s ∩ ⋃ i, t i) = ⋃ i, s ∩ t i :=
inf_iSup_eq _ _
#align set.inter_Union Set.inter_iUnion
theorem iUnion_inter (s : Set β) (t : ι → Set β) : (⋃ i, t i) ∩ s = ⋃ i, t i ∩ s :=
iSup_inf_eq _ _
#align set.Union_inter Set.iUnion_inter
theorem iUnion_union_distrib (s : ι → Set β) (t : ι → Set β) :
⋃ i, s i ∪ t i = (⋃ i, s i) ∪ ⋃ i, t i :=
iSup_sup_eq
#align set.Union_union_distrib Set.iUnion_union_distrib
theorem iInter_inter_distrib (s : ι → Set β) (t : ι → Set β) :
⋂ i, s i ∩ t i = (⋂ i, s i) ∩ ⋂ i, t i :=
iInf_inf_eq
#align set.Inter_inter_distrib Set.iInter_inter_distrib
theorem union_iUnion [Nonempty ι] (s : Set β) (t : ι → Set β) : (s ∪ ⋃ i, t i) = ⋃ i, s ∪ t i :=
sup_iSup
#align set.union_Union Set.union_iUnion
theorem iUnion_union [Nonempty ι] (s : Set β) (t : ι → Set β) : (⋃ i, t i) ∪ s = ⋃ i, t i ∪ s :=
iSup_sup
#align set.Union_union Set.iUnion_union
theorem inter_iInter [Nonempty ι] (s : Set β) (t : ι → Set β) : (s ∩ ⋂ i, t i) = ⋂ i, s ∩ t i :=
inf_iInf
#align set.inter_Inter Set.inter_iInter
theorem iInter_inter [Nonempty ι] (s : Set β) (t : ι → Set β) : (⋂ i, t i) ∩ s = ⋂ i, t i ∩ s :=
iInf_inf
#align set.Inter_inter Set.iInter_inter
-- classical
theorem union_iInter (s : Set β) (t : ι → Set β) : (s ∪ ⋂ i, t i) = ⋂ i, s ∪ t i :=
sup_iInf_eq _ _
#align set.union_Inter Set.union_iInter
theorem iInter_union (s : ι → Set β) (t : Set β) : (⋂ i, s i) ∪ t = ⋂ i, s i ∪ t :=
iInf_sup_eq _ _
#align set.Inter_union Set.iInter_union
theorem iUnion_diff (s : Set β) (t : ι → Set β) : (⋃ i, t i) \ s = ⋃ i, t i \ s :=
iUnion_inter _ _
#align set.Union_diff Set.iUnion_diff
theorem diff_iUnion [Nonempty ι] (s : Set β) (t : ι → Set β) : (s \ ⋃ i, t i) = ⋂ i, s \ t i := by
rw [diff_eq, compl_iUnion, inter_iInter]; rfl
#align set.diff_Union Set.diff_iUnion
theorem diff_iInter (s : Set β) (t : ι → Set β) : (s \ ⋂ i, t i) = ⋃ i, s \ t i := by
rw [diff_eq, compl_iInter, inter_iUnion]; rfl
#align set.diff_Inter Set.diff_iInter
theorem iUnion_inter_subset {ι α} {s t : ι → Set α} : ⋃ i, s i ∩ t i ⊆ (⋃ i, s i) ∩ ⋃ i, t i :=
le_iSup_inf_iSup s t
#align set.Union_inter_subset Set.iUnion_inter_subset
theorem iUnion_inter_of_monotone {ι α} [Preorder ι] [IsDirected ι (· ≤ ·)] {s t : ι → Set α}
(hs : Monotone s) (ht : Monotone t) : ⋃ i, s i ∩ t i = (⋃ i, s i) ∩ ⋃ i, t i :=
iSup_inf_of_monotone hs ht
#align set.Union_inter_of_monotone Set.iUnion_inter_of_monotone
theorem iUnion_inter_of_antitone {ι α} [Preorder ι] [IsDirected ι (swap (· ≤ ·))] {s t : ι → Set α}
(hs : Antitone s) (ht : Antitone t) : ⋃ i, s i ∩ t i = (⋃ i, s i) ∩ ⋃ i, t i :=
iSup_inf_of_antitone hs ht
#align set.Union_inter_of_antitone Set.iUnion_inter_of_antitone
theorem iInter_union_of_monotone {ι α} [Preorder ι] [IsDirected ι (swap (· ≤ ·))] {s t : ι → Set α}
(hs : Monotone s) (ht : Monotone t) : ⋂ i, s i ∪ t i = (⋂ i, s i) ∪ ⋂ i, t i :=
iInf_sup_of_monotone hs ht
#align set.Inter_union_of_monotone Set.iInter_union_of_monotone
theorem iInter_union_of_antitone {ι α} [Preorder ι] [IsDirected ι (· ≤ ·)] {s t : ι → Set α}
(hs : Antitone s) (ht : Antitone t) : ⋂ i, s i ∪ t i = (⋂ i, s i) ∪ ⋂ i, t i :=
iInf_sup_of_antitone hs ht
#align set.Inter_union_of_antitone Set.iInter_union_of_antitone
/-- An equality version of this lemma is `iUnion_iInter_of_monotone` in `Data.Set.Finite`. -/
theorem iUnion_iInter_subset {s : ι → ι' → Set α} : (⋃ j, ⋂ i, s i j) ⊆ ⋂ i, ⋃ j, s i j :=
iSup_iInf_le_iInf_iSup (flip s)
#align set.Union_Inter_subset Set.iUnion_iInter_subset
theorem iUnion_option {ι} (s : Option ι → Set α) : ⋃ o, s o = s none ∪ ⋃ i, s (some i) :=
iSup_option s
#align set.Union_option Set.iUnion_option
theorem iInter_option {ι} (s : Option ι → Set α) : ⋂ o, s o = s none ∩ ⋂ i, s (some i) :=
iInf_option s
#align set.Inter_option Set.iInter_option
section
variable (p : ι → Prop) [DecidablePred p]
theorem iUnion_dite (f : ∀ i, p i → Set α) (g : ∀ i, ¬p i → Set α) :
⋃ i, (if h : p i then f i h else g i h) = (⋃ (i) (h : p i), f i h) ∪ ⋃ (i) (h : ¬p i), g i h :=
iSup_dite _ _ _
#align set.Union_dite Set.iUnion_dite
theorem iUnion_ite (f g : ι → Set α) :
⋃ i, (if p i then f i else g i) = (⋃ (i) (_ : p i), f i) ∪ ⋃ (i) (_ : ¬p i), g i :=
iUnion_dite _ _ _
#align set.Union_ite Set.iUnion_ite
theorem iInter_dite (f : ∀ i, p i → Set α) (g : ∀ i, ¬p i → Set α) :
⋂ i, (if h : p i then f i h else g i h) = (⋂ (i) (h : p i), f i h) ∩ ⋂ (i) (h : ¬p i), g i h :=
iInf_dite _ _ _
#align set.Inter_dite Set.iInter_dite
theorem iInter_ite (f g : ι → Set α) :
⋂ i, (if p i then f i else g i) = (⋂ (i) (_ : p i), f i) ∩ ⋂ (i) (_ : ¬p i), g i :=
iInter_dite _ _ _
#align set.Inter_ite Set.iInter_ite
end
theorem image_projection_prod {ι : Type*} {α : ι → Type*} {v : ∀ i : ι, Set (α i)}
(hv : (pi univ v).Nonempty) (i : ι) :
((fun x : ∀ i : ι, α i => x i) '' ⋂ k, (fun x : ∀ j : ι, α j => x k) ⁻¹' v k) = v i := by
classical
apply Subset.antisymm
· simp [iInter_subset]
· intro y y_in
simp only [mem_image, mem_iInter, mem_preimage]
rcases hv with ⟨z, hz⟩
refine ⟨Function.update z i y, ?_, update_same i y z⟩
rw [@forall_update_iff ι α _ z i y fun i t => t ∈ v i]
exact ⟨y_in, fun j _ => by simpa using hz j⟩
#align set.image_projection_prod Set.image_projection_prod
/-! ### Unions and intersections indexed by `Prop` -/
theorem iInter_false {s : False → Set α} : iInter s = univ :=
iInf_false
#align set.Inter_false Set.iInter_false
theorem iUnion_false {s : False → Set α} : iUnion s = ∅ :=
iSup_false
#align set.Union_false Set.iUnion_false
@[simp]
theorem iInter_true {s : True → Set α} : iInter s = s trivial :=
iInf_true
#align set.Inter_true Set.iInter_true
@[simp]
theorem iUnion_true {s : True → Set α} : iUnion s = s trivial :=
iSup_true
#align set.Union_true Set.iUnion_true
@[simp]
theorem iInter_exists {p : ι → Prop} {f : Exists p → Set α} :
⋂ x, f x = ⋂ (i) (h : p i), f ⟨i, h⟩ :=
iInf_exists
#align set.Inter_exists Set.iInter_exists
@[simp]
theorem iUnion_exists {p : ι → Prop} {f : Exists p → Set α} :
⋃ x, f x = ⋃ (i) (h : p i), f ⟨i, h⟩ :=
iSup_exists
#align set.Union_exists Set.iUnion_exists
@[simp]
theorem iUnion_empty : (⋃ _ : ι, ∅ : Set α) = ∅ :=
iSup_bot
#align set.Union_empty Set.iUnion_empty
@[simp]
theorem iInter_univ : (⋂ _ : ι, univ : Set α) = univ :=
iInf_top
#align set.Inter_univ Set.iInter_univ
section
variable {s : ι → Set α}
@[simp]
theorem iUnion_eq_empty : ⋃ i, s i = ∅ ↔ ∀ i, s i = ∅ :=
iSup_eq_bot
#align set.Union_eq_empty Set.iUnion_eq_empty
@[simp]
theorem iInter_eq_univ : ⋂ i, s i = univ ↔ ∀ i, s i = univ :=
iInf_eq_top
#align set.Inter_eq_univ Set.iInter_eq_univ
@[simp]
theorem nonempty_iUnion : (⋃ i, s i).Nonempty ↔ ∃ i, (s i).Nonempty := by
simp [nonempty_iff_ne_empty]
#align set.nonempty_Union Set.nonempty_iUnion
-- Porting note (#10618): removing `simp`. `simp` can prove it
theorem nonempty_biUnion {t : Set α} {s : α → Set β} :
(⋃ i ∈ t, s i).Nonempty ↔ ∃ i ∈ t, (s i).Nonempty := by simp
#align set.nonempty_bUnion Set.nonempty_biUnion
theorem iUnion_nonempty_index (s : Set α) (t : s.Nonempty → Set β) :
⋃ h, t h = ⋃ x ∈ s, t ⟨x, ‹_›⟩ :=
iSup_exists
#align set.Union_nonempty_index Set.iUnion_nonempty_index
end
@[simp]
theorem iInter_iInter_eq_left {b : β} {s : ∀ x : β, x = b → Set α} :
⋂ (x) (h : x = b), s x h = s b rfl :=
iInf_iInf_eq_left
#align set.Inter_Inter_eq_left Set.iInter_iInter_eq_left
@[simp]
theorem iInter_iInter_eq_right {b : β} {s : ∀ x : β, b = x → Set α} :
⋂ (x) (h : b = x), s x h = s b rfl :=
iInf_iInf_eq_right
#align set.Inter_Inter_eq_right Set.iInter_iInter_eq_right
@[simp]
theorem iUnion_iUnion_eq_left {b : β} {s : ∀ x : β, x = b → Set α} :
⋃ (x) (h : x = b), s x h = s b rfl :=
iSup_iSup_eq_left
#align set.Union_Union_eq_left Set.iUnion_iUnion_eq_left
@[simp]
theorem iUnion_iUnion_eq_right {b : β} {s : ∀ x : β, b = x → Set α} :
⋃ (x) (h : b = x), s x h = s b rfl :=
iSup_iSup_eq_right
#align set.Union_Union_eq_right Set.iUnion_iUnion_eq_right
theorem iInter_or {p q : Prop} (s : p ∨ q → Set α) :
⋂ h, s h = (⋂ h : p, s (Or.inl h)) ∩ ⋂ h : q, s (Or.inr h) :=
iInf_or
#align set.Inter_or Set.iInter_or
theorem iUnion_or {p q : Prop} (s : p ∨ q → Set α) :
⋃ h, s h = (⋃ i, s (Or.inl i)) ∪ ⋃ j, s (Or.inr j) :=
iSup_or
#align set.Union_or Set.iUnion_or
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (hp hq) -/
theorem iUnion_and {p q : Prop} (s : p ∧ q → Set α) : ⋃ h, s h = ⋃ (hp) (hq), s ⟨hp, hq⟩ :=
iSup_and
#align set.Union_and Set.iUnion_and
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (hp hq) -/
theorem iInter_and {p q : Prop} (s : p ∧ q → Set α) : ⋂ h, s h = ⋂ (hp) (hq), s ⟨hp, hq⟩ :=
iInf_and
#align set.Inter_and Set.iInter_and
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i i') -/
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i' i) -/
theorem iUnion_comm (s : ι → ι' → Set α) : ⋃ (i) (i'), s i i' = ⋃ (i') (i), s i i' :=
iSup_comm
#align set.Union_comm Set.iUnion_comm
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i i') -/
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i' i) -/
theorem iInter_comm (s : ι → ι' → Set α) : ⋂ (i) (i'), s i i' = ⋂ (i') (i), s i i' :=
iInf_comm
#align set.Inter_comm Set.iInter_comm
theorem iUnion_sigma {γ : α → Type*} (s : Sigma γ → Set β) : ⋃ ia, s ia = ⋃ i, ⋃ a, s ⟨i, a⟩ :=
iSup_sigma
theorem iUnion_sigma' {γ : α → Type*} (s : ∀ i, γ i → Set β) :
⋃ i, ⋃ a, s i a = ⋃ ia : Sigma γ, s ia.1 ia.2 :=
iSup_sigma' _
theorem iInter_sigma {γ : α → Type*} (s : Sigma γ → Set β) : ⋂ ia, s ia = ⋂ i, ⋂ a, s ⟨i, a⟩ :=
iInf_sigma
theorem iInter_sigma' {γ : α → Type*} (s : ∀ i, γ i → Set β) :
⋂ i, ⋂ a, s i a = ⋂ ia : Sigma γ, s ia.1 ia.2 :=
iInf_sigma' _
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i₁ j₁ i₂ j₂) -/
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i₂ j₂ i₁ j₁) -/
theorem iUnion₂_comm (s : ∀ i₁, κ₁ i₁ → ∀ i₂, κ₂ i₂ → Set α) :
⋃ (i₁) (j₁) (i₂) (j₂), s i₁ j₁ i₂ j₂ = ⋃ (i₂) (j₂) (i₁) (j₁), s i₁ j₁ i₂ j₂ :=
iSup₂_comm _
#align set.Union₂_comm Set.iUnion₂_comm
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i₁ j₁ i₂ j₂) -/
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i₂ j₂ i₁ j₁) -/
theorem iInter₂_comm (s : ∀ i₁, κ₁ i₁ → ∀ i₂, κ₂ i₂ → Set α) :
⋂ (i₁) (j₁) (i₂) (j₂), s i₁ j₁ i₂ j₂ = ⋂ (i₂) (j₂) (i₁) (j₁), s i₁ j₁ i₂ j₂ :=
iInf₂_comm _
#align set.Inter₂_comm Set.iInter₂_comm
@[simp]
theorem biUnion_and (p : ι → Prop) (q : ι → ι' → Prop) (s : ∀ x y, p x ∧ q x y → Set α) :
⋃ (x : ι) (y : ι') (h : p x ∧ q x y), s x y h =
⋃ (x : ι) (hx : p x) (y : ι') (hy : q x y), s x y ⟨hx, hy⟩ := by
simp only [iUnion_and, @iUnion_comm _ ι']
#align set.bUnion_and Set.biUnion_and
@[simp]
theorem biUnion_and' (p : ι' → Prop) (q : ι → ι' → Prop) (s : ∀ x y, p y ∧ q x y → Set α) :
⋃ (x : ι) (y : ι') (h : p y ∧ q x y), s x y h =
⋃ (y : ι') (hy : p y) (x : ι) (hx : q x y), s x y ⟨hy, hx⟩ := by
simp only [iUnion_and, @iUnion_comm _ ι]
#align set.bUnion_and' Set.biUnion_and'
@[simp]
theorem biInter_and (p : ι → Prop) (q : ι → ι' → Prop) (s : ∀ x y, p x ∧ q x y → Set α) :
⋂ (x : ι) (y : ι') (h : p x ∧ q x y), s x y h =
⋂ (x : ι) (hx : p x) (y : ι') (hy : q x y), s x y ⟨hx, hy⟩ := by
simp only [iInter_and, @iInter_comm _ ι']
#align set.bInter_and Set.biInter_and
@[simp]
theorem biInter_and' (p : ι' → Prop) (q : ι → ι' → Prop) (s : ∀ x y, p y ∧ q x y → Set α) :
⋂ (x : ι) (y : ι') (h : p y ∧ q x y), s x y h =
⋂ (y : ι') (hy : p y) (x : ι) (hx : q x y), s x y ⟨hy, hx⟩ := by
simp only [iInter_and, @iInter_comm _ ι]
#align set.bInter_and' Set.biInter_and'
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (x h) -/
@[simp]
theorem iUnion_iUnion_eq_or_left {b : β} {p : β → Prop} {s : ∀ x : β, x = b ∨ p x → Set α} :
⋃ (x) (h), s x h = s b (Or.inl rfl) ∪ ⋃ (x) (h : p x), s x (Or.inr h) := by
simp only [iUnion_or, iUnion_union_distrib, iUnion_iUnion_eq_left]
#align set.Union_Union_eq_or_left Set.iUnion_iUnion_eq_or_left
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (x h) -/
@[simp]
theorem iInter_iInter_eq_or_left {b : β} {p : β → Prop} {s : ∀ x : β, x = b ∨ p x → Set α} :
⋂ (x) (h), s x h = s b (Or.inl rfl) ∩ ⋂ (x) (h : p x), s x (Or.inr h) := by
simp only [iInter_or, iInter_inter_distrib, iInter_iInter_eq_left]
#align set.Inter_Inter_eq_or_left Set.iInter_iInter_eq_or_left
/-! ### Bounded unions and intersections -/
/-- A specialization of `mem_iUnion₂`. -/
theorem mem_biUnion {s : Set α} {t : α → Set β} {x : α} {y : β} (xs : x ∈ s) (ytx : y ∈ t x) :
y ∈ ⋃ x ∈ s, t x :=
mem_iUnion₂_of_mem xs ytx
#align set.mem_bUnion Set.mem_biUnion
/-- A specialization of `mem_iInter₂`. -/
theorem mem_biInter {s : Set α} {t : α → Set β} {y : β} (h : ∀ x ∈ s, y ∈ t x) :
y ∈ ⋂ x ∈ s, t x :=
mem_iInter₂_of_mem h
#align set.mem_bInter Set.mem_biInter
/-- A specialization of `subset_iUnion₂`. -/
theorem subset_biUnion_of_mem {s : Set α} {u : α → Set β} {x : α} (xs : x ∈ s) :
u x ⊆ ⋃ x ∈ s, u x :=
-- Porting note: Why is this not just `subset_iUnion₂ x xs`?
@subset_iUnion₂ β α (· ∈ s) (fun i _ => u i) x xs
#align set.subset_bUnion_of_mem Set.subset_biUnion_of_mem
/-- A specialization of `iInter₂_subset`. -/
theorem biInter_subset_of_mem {s : Set α} {t : α → Set β} {x : α} (xs : x ∈ s) :
⋂ x ∈ s, t x ⊆ t x :=
iInter₂_subset x xs
#align set.bInter_subset_of_mem Set.biInter_subset_of_mem
theorem biUnion_subset_biUnion_left {s s' : Set α} {t : α → Set β} (h : s ⊆ s') :
⋃ x ∈ s, t x ⊆ ⋃ x ∈ s', t x :=
iUnion₂_subset fun _ hx => subset_biUnion_of_mem <| h hx
#align set.bUnion_subset_bUnion_left Set.biUnion_subset_biUnion_left
theorem biInter_subset_biInter_left {s s' : Set α} {t : α → Set β} (h : s' ⊆ s) :
⋂ x ∈ s, t x ⊆ ⋂ x ∈ s', t x :=
subset_iInter₂ fun _ hx => biInter_subset_of_mem <| h hx
#align set.bInter_subset_bInter_left Set.biInter_subset_biInter_left
theorem biUnion_mono {s s' : Set α} {t t' : α → Set β} (hs : s' ⊆ s) (h : ∀ x ∈ s, t x ⊆ t' x) :
⋃ x ∈ s', t x ⊆ ⋃ x ∈ s, t' x :=
(biUnion_subset_biUnion_left hs).trans <| iUnion₂_mono h
#align set.bUnion_mono Set.biUnion_mono
theorem biInter_mono {s s' : Set α} {t t' : α → Set β} (hs : s ⊆ s') (h : ∀ x ∈ s, t x ⊆ t' x) :
⋂ x ∈ s', t x ⊆ ⋂ x ∈ s, t' x :=
(biInter_subset_biInter_left hs).trans <| iInter₂_mono h
#align set.bInter_mono Set.biInter_mono
theorem biUnion_eq_iUnion (s : Set α) (t : ∀ x ∈ s, Set β) :
⋃ x ∈ s, t x ‹_› = ⋃ x : s, t x x.2 :=
iSup_subtype'
#align set.bUnion_eq_Union Set.biUnion_eq_iUnion
theorem biInter_eq_iInter (s : Set α) (t : ∀ x ∈ s, Set β) :
⋂ x ∈ s, t x ‹_› = ⋂ x : s, t x x.2 :=
iInf_subtype'
#align set.bInter_eq_Inter Set.biInter_eq_iInter
theorem iUnion_subtype (p : α → Prop) (s : { x // p x } → Set β) :
⋃ x : { x // p x }, s x = ⋃ (x) (hx : p x), s ⟨x, hx⟩ :=
iSup_subtype
#align set.Union_subtype Set.iUnion_subtype
theorem iInter_subtype (p : α → Prop) (s : { x // p x } → Set β) :
⋂ x : { x // p x }, s x = ⋂ (x) (hx : p x), s ⟨x, hx⟩ :=
iInf_subtype
#align set.Inter_subtype Set.iInter_subtype
theorem biInter_empty (u : α → Set β) : ⋂ x ∈ (∅ : Set α), u x = univ :=
iInf_emptyset
#align set.bInter_empty Set.biInter_empty
theorem biInter_univ (u : α → Set β) : ⋂ x ∈ @univ α, u x = ⋂ x, u x :=
iInf_univ
#align set.bInter_univ Set.biInter_univ
@[simp]
theorem biUnion_self (s : Set α) : ⋃ x ∈ s, s = s :=
Subset.antisymm (iUnion₂_subset fun _ _ => Subset.refl s) fun _ hx => mem_biUnion hx hx
#align set.bUnion_self Set.biUnion_self
@[simp]
theorem iUnion_nonempty_self (s : Set α) : ⋃ _ : s.Nonempty, s = s := by
rw [iUnion_nonempty_index, biUnion_self]
#align set.Union_nonempty_self Set.iUnion_nonempty_self
theorem biInter_singleton (a : α) (s : α → Set β) : ⋂ x ∈ ({a} : Set α), s x = s a :=
iInf_singleton
#align set.bInter_singleton Set.biInter_singleton
theorem biInter_union (s t : Set α) (u : α → Set β) :
⋂ x ∈ s ∪ t, u x = (⋂ x ∈ s, u x) ∩ ⋂ x ∈ t, u x :=
iInf_union
#align set.bInter_union Set.biInter_union
theorem biInter_insert (a : α) (s : Set α) (t : α → Set β) :
⋂ x ∈ insert a s, t x = t a ∩ ⋂ x ∈ s, t x := by simp
#align set.bInter_insert Set.biInter_insert
theorem biInter_pair (a b : α) (s : α → Set β) : ⋂ x ∈ ({a, b} : Set α), s x = s a ∩ s b := by
rw [biInter_insert, biInter_singleton]
#align set.bInter_pair Set.biInter_pair
theorem biInter_inter {ι α : Type*} {s : Set ι} (hs : s.Nonempty) (f : ι → Set α) (t : Set α) :
⋂ i ∈ s, f i ∩ t = (⋂ i ∈ s, f i) ∩ t := by
haveI : Nonempty s := hs.to_subtype
simp [biInter_eq_iInter, ← iInter_inter]
#align set.bInter_inter Set.biInter_inter
theorem inter_biInter {ι α : Type*} {s : Set ι} (hs : s.Nonempty) (f : ι → Set α) (t : Set α) :
⋂ i ∈ s, t ∩ f i = t ∩ ⋂ i ∈ s, f i := by
rw [inter_comm, ← biInter_inter hs]
simp [inter_comm]
#align set.inter_bInter Set.inter_biInter
theorem biUnion_empty (s : α → Set β) : ⋃ x ∈ (∅ : Set α), s x = ∅ :=
iSup_emptyset
#align set.bUnion_empty Set.biUnion_empty
theorem biUnion_univ (s : α → Set β) : ⋃ x ∈ @univ α, s x = ⋃ x, s x :=
iSup_univ
#align set.bUnion_univ Set.biUnion_univ
theorem biUnion_singleton (a : α) (s : α → Set β) : ⋃ x ∈ ({a} : Set α), s x = s a :=
iSup_singleton
#align set.bUnion_singleton Set.biUnion_singleton
@[simp]
theorem biUnion_of_singleton (s : Set α) : ⋃ x ∈ s, {x} = s :=
ext <| by simp
#align set.bUnion_of_singleton Set.biUnion_of_singleton
theorem biUnion_union (s t : Set α) (u : α → Set β) :
⋃ x ∈ s ∪ t, u x = (⋃ x ∈ s, u x) ∪ ⋃ x ∈ t, u x :=
iSup_union
#align set.bUnion_union Set.biUnion_union
@[simp]
theorem iUnion_coe_set {α β : Type*} (s : Set α) (f : s → Set β) :
⋃ i, f i = ⋃ i ∈ s, f ⟨i, ‹i ∈ s›⟩ :=
iUnion_subtype _ _
#align set.Union_coe_set Set.iUnion_coe_set
@[simp]
theorem iInter_coe_set {α β : Type*} (s : Set α) (f : s → Set β) :
⋂ i, f i = ⋂ i ∈ s, f ⟨i, ‹i ∈ s›⟩ :=
iInter_subtype _ _
#align set.Inter_coe_set Set.iInter_coe_set
theorem biUnion_insert (a : α) (s : Set α) (t : α → Set β) :
⋃ x ∈ insert a s, t x = t a ∪ ⋃ x ∈ s, t x := by simp
#align set.bUnion_insert Set.biUnion_insert
theorem biUnion_pair (a b : α) (s : α → Set β) : ⋃ x ∈ ({a, b} : Set α), s x = s a ∪ s b := by
simp
#align set.bUnion_pair Set.biUnion_pair
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/
theorem inter_iUnion₂ (s : Set α) (t : ∀ i, κ i → Set α) :
(s ∩ ⋃ (i) (j), t i j) = ⋃ (i) (j), s ∩ t i j := by simp only [inter_iUnion]
#align set.inter_Union₂ Set.inter_iUnion₂
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/
theorem iUnion₂_inter (s : ∀ i, κ i → Set α) (t : Set α) :
(⋃ (i) (j), s i j) ∩ t = ⋃ (i) (j), s i j ∩ t := by simp_rw [iUnion_inter]
#align set.Union₂_inter Set.iUnion₂_inter
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/
theorem union_iInter₂ (s : Set α) (t : ∀ i, κ i → Set α) :
(s ∪ ⋂ (i) (j), t i j) = ⋂ (i) (j), s ∪ t i j := by simp_rw [union_iInter]
#align set.union_Inter₂ Set.union_iInter₂
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/
theorem iInter₂_union (s : ∀ i, κ i → Set α) (t : Set α) :
(⋂ (i) (j), s i j) ∪ t = ⋂ (i) (j), s i j ∪ t := by simp_rw [iInter_union]
#align set.Inter₂_union Set.iInter₂_union
theorem mem_sUnion_of_mem {x : α} {t : Set α} {S : Set (Set α)} (hx : x ∈ t) (ht : t ∈ S) :
x ∈ ⋃₀S :=
⟨t, ht, hx⟩
#align set.mem_sUnion_of_mem Set.mem_sUnion_of_mem
-- is this theorem really necessary?
theorem not_mem_of_not_mem_sUnion {x : α} {t : Set α} {S : Set (Set α)} (hx : x ∉ ⋃₀S)
(ht : t ∈ S) : x ∉ t := fun h => hx ⟨t, ht, h⟩
#align set.not_mem_of_not_mem_sUnion Set.not_mem_of_not_mem_sUnion
theorem sInter_subset_of_mem {S : Set (Set α)} {t : Set α} (tS : t ∈ S) : ⋂₀ S ⊆ t :=
sInf_le tS
#align set.sInter_subset_of_mem Set.sInter_subset_of_mem
theorem subset_sUnion_of_mem {S : Set (Set α)} {t : Set α} (tS : t ∈ S) : t ⊆ ⋃₀S :=
le_sSup tS
#align set.subset_sUnion_of_mem Set.subset_sUnion_of_mem
theorem subset_sUnion_of_subset {s : Set α} (t : Set (Set α)) (u : Set α) (h₁ : s ⊆ u)
(h₂ : u ∈ t) : s ⊆ ⋃₀t :=
Subset.trans h₁ (subset_sUnion_of_mem h₂)
#align set.subset_sUnion_of_subset Set.subset_sUnion_of_subset
theorem sUnion_subset {S : Set (Set α)} {t : Set α} (h : ∀ t' ∈ S, t' ⊆ t) : ⋃₀S ⊆ t :=
sSup_le h
#align set.sUnion_subset Set.sUnion_subset
@[simp]
theorem sUnion_subset_iff {s : Set (Set α)} {t : Set α} : ⋃₀s ⊆ t ↔ ∀ t' ∈ s, t' ⊆ t :=
sSup_le_iff
#align set.sUnion_subset_iff Set.sUnion_subset_iff
/-- `sUnion` is monotone under taking a subset of each set. -/
lemma sUnion_mono_subsets {s : Set (Set α)} {f : Set α → Set α} (hf : ∀ t : Set α, t ⊆ f t) :
⋃₀ s ⊆ ⋃₀ (f '' s) :=
fun _ ⟨t, htx, hxt⟩ ↦ ⟨f t, mem_image_of_mem f htx, hf t hxt⟩
/-- `sUnion` is monotone under taking a superset of each set. -/
lemma sUnion_mono_supsets {s : Set (Set α)} {f : Set α → Set α} (hf : ∀ t : Set α, f t ⊆ t) :
⋃₀ (f '' s) ⊆ ⋃₀ s :=
-- If t ∈ f '' s is arbitrary; t = f u for some u : Set α.
fun _ ⟨_, ⟨u, hus, hut⟩, hxt⟩ ↦ ⟨u, hus, (hut ▸ hf u) hxt⟩
theorem subset_sInter {S : Set (Set α)} {t : Set α} (h : ∀ t' ∈ S, t ⊆ t') : t ⊆ ⋂₀ S :=
le_sInf h
#align set.subset_sInter Set.subset_sInter
@[simp]
theorem subset_sInter_iff {S : Set (Set α)} {t : Set α} : t ⊆ ⋂₀ S ↔ ∀ t' ∈ S, t ⊆ t' :=
le_sInf_iff
#align set.subset_sInter_iff Set.subset_sInter_iff
@[gcongr]
theorem sUnion_subset_sUnion {S T : Set (Set α)} (h : S ⊆ T) : ⋃₀S ⊆ ⋃₀T :=
sUnion_subset fun _ hs => subset_sUnion_of_mem (h hs)
#align set.sUnion_subset_sUnion Set.sUnion_subset_sUnion
@[gcongr]
theorem sInter_subset_sInter {S T : Set (Set α)} (h : S ⊆ T) : ⋂₀ T ⊆ ⋂₀ S :=
subset_sInter fun _ hs => sInter_subset_of_mem (h hs)
#align set.sInter_subset_sInter Set.sInter_subset_sInter
@[simp]
theorem sUnion_empty : ⋃₀∅ = (∅ : Set α) :=
sSup_empty
#align set.sUnion_empty Set.sUnion_empty
@[simp]
theorem sInter_empty : ⋂₀ ∅ = (univ : Set α) :=
sInf_empty
#align set.sInter_empty Set.sInter_empty
@[simp]
theorem sUnion_singleton (s : Set α) : ⋃₀{s} = s :=
sSup_singleton
#align set.sUnion_singleton Set.sUnion_singleton
@[simp]
theorem sInter_singleton (s : Set α) : ⋂₀ {s} = s :=
sInf_singleton
#align set.sInter_singleton Set.sInter_singleton
@[simp]
theorem sUnion_eq_empty {S : Set (Set α)} : ⋃₀S = ∅ ↔ ∀ s ∈ S, s = ∅ :=
sSup_eq_bot
#align set.sUnion_eq_empty Set.sUnion_eq_empty
@[simp]
theorem sInter_eq_univ {S : Set (Set α)} : ⋂₀ S = univ ↔ ∀ s ∈ S, s = univ :=
sInf_eq_top
#align set.sInter_eq_univ Set.sInter_eq_univ
theorem subset_powerset_iff {s : Set (Set α)} {t : Set α} : s ⊆ 𝒫 t ↔ ⋃₀ s ⊆ t :=
sUnion_subset_iff.symm
/-- `⋃₀` and `𝒫` form a Galois connection. -/
theorem sUnion_powerset_gc :
GaloisConnection (⋃₀ · : Set (Set α) → Set α) (𝒫 · : Set α → Set (Set α)) :=
gc_sSup_Iic
/-- `⋃₀` and `𝒫` form a Galois insertion. -/
def sUnion_powerset_gi :
GaloisInsertion (⋃₀ · : Set (Set α) → Set α) (𝒫 · : Set α → Set (Set α)) :=
gi_sSup_Iic
/-- If all sets in a collection are either `∅` or `Set.univ`, then so is their union. -/
theorem sUnion_mem_empty_univ {S : Set (Set α)} (h : S ⊆ {∅, univ}) :
⋃₀ S ∈ ({∅, univ} : Set (Set α)) := by
simp only [mem_insert_iff, mem_singleton_iff, or_iff_not_imp_left, sUnion_eq_empty, not_forall]
rintro ⟨s, hs, hne⟩
obtain rfl : s = univ := (h hs).resolve_left hne
exact univ_subset_iff.1 <| subset_sUnion_of_mem hs
@[simp]
theorem nonempty_sUnion {S : Set (Set α)} : (⋃₀S).Nonempty ↔ ∃ s ∈ S, Set.Nonempty s := by
simp [nonempty_iff_ne_empty]
#align set.nonempty_sUnion Set.nonempty_sUnion
theorem Nonempty.of_sUnion {s : Set (Set α)} (h : (⋃₀s).Nonempty) : s.Nonempty :=
let ⟨s, hs, _⟩ := nonempty_sUnion.1 h
⟨s, hs⟩
#align set.nonempty.of_sUnion Set.Nonempty.of_sUnion
theorem Nonempty.of_sUnion_eq_univ [Nonempty α] {s : Set (Set α)} (h : ⋃₀s = univ) : s.Nonempty :=
Nonempty.of_sUnion <| h.symm ▸ univ_nonempty
#align set.nonempty.of_sUnion_eq_univ Set.Nonempty.of_sUnion_eq_univ
theorem sUnion_union (S T : Set (Set α)) : ⋃₀(S ∪ T) = ⋃₀S ∪ ⋃₀T :=
sSup_union
#align set.sUnion_union Set.sUnion_union
theorem sInter_union (S T : Set (Set α)) : ⋂₀ (S ∪ T) = ⋂₀ S ∩ ⋂₀ T :=
sInf_union
#align set.sInter_union Set.sInter_union
@[simp]
theorem sUnion_insert (s : Set α) (T : Set (Set α)) : ⋃₀insert s T = s ∪ ⋃₀T :=
sSup_insert
#align set.sUnion_insert Set.sUnion_insert
@[simp]
theorem sInter_insert (s : Set α) (T : Set (Set α)) : ⋂₀ insert s T = s ∩ ⋂₀ T :=
sInf_insert
#align set.sInter_insert Set.sInter_insert
@[simp]
theorem sUnion_diff_singleton_empty (s : Set (Set α)) : ⋃₀(s \ {∅}) = ⋃₀s :=
sSup_diff_singleton_bot s
#align set.sUnion_diff_singleton_empty Set.sUnion_diff_singleton_empty
@[simp]
theorem sInter_diff_singleton_univ (s : Set (Set α)) : ⋂₀ (s \ {univ}) = ⋂₀ s :=
sInf_diff_singleton_top s
#align set.sInter_diff_singleton_univ Set.sInter_diff_singleton_univ
theorem sUnion_pair (s t : Set α) : ⋃₀{s, t} = s ∪ t :=
sSup_pair
#align set.sUnion_pair Set.sUnion_pair
theorem sInter_pair (s t : Set α) : ⋂₀ {s, t} = s ∩ t :=
sInf_pair
#align set.sInter_pair Set.sInter_pair
@[simp]
theorem sUnion_image (f : α → Set β) (s : Set α) : ⋃₀(f '' s) = ⋃ x ∈ s, f x :=
sSup_image
#align set.sUnion_image Set.sUnion_image
@[simp]
theorem sInter_image (f : α → Set β) (s : Set α) : ⋂₀ (f '' s) = ⋂ x ∈ s, f x :=
sInf_image
#align set.sInter_image Set.sInter_image
@[simp]
theorem sUnion_range (f : ι → Set β) : ⋃₀range f = ⋃ x, f x :=
rfl
#align set.sUnion_range Set.sUnion_range
@[simp]
theorem sInter_range (f : ι → Set β) : ⋂₀ range f = ⋂ x, f x :=
rfl
#align set.sInter_range Set.sInter_range
theorem iUnion_eq_univ_iff {f : ι → Set α} : ⋃ i, f i = univ ↔ ∀ x, ∃ i, x ∈ f i := by
simp only [eq_univ_iff_forall, mem_iUnion]
#align set.Union_eq_univ_iff Set.iUnion_eq_univ_iff
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/
theorem iUnion₂_eq_univ_iff {s : ∀ i, κ i → Set α} :
⋃ (i) (j), s i j = univ ↔ ∀ a, ∃ i j, a ∈ s i j := by
simp only [iUnion_eq_univ_iff, mem_iUnion]
#align set.Union₂_eq_univ_iff Set.iUnion₂_eq_univ_iff
theorem sUnion_eq_univ_iff {c : Set (Set α)} : ⋃₀c = univ ↔ ∀ a, ∃ b ∈ c, a ∈ b := by
simp only [eq_univ_iff_forall, mem_sUnion]
#align set.sUnion_eq_univ_iff Set.sUnion_eq_univ_iff
-- classical
theorem iInter_eq_empty_iff {f : ι → Set α} : ⋂ i, f i = ∅ ↔ ∀ x, ∃ i, x ∉ f i := by
simp [Set.eq_empty_iff_forall_not_mem]
#align set.Inter_eq_empty_iff Set.iInter_eq_empty_iff
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/
-- classical
theorem iInter₂_eq_empty_iff {s : ∀ i, κ i → Set α} :
⋂ (i) (j), s i j = ∅ ↔ ∀ a, ∃ i j, a ∉ s i j := by
simp only [eq_empty_iff_forall_not_mem, mem_iInter, not_forall]
#align set.Inter₂_eq_empty_iff Set.iInter₂_eq_empty_iff
-- classical
theorem sInter_eq_empty_iff {c : Set (Set α)} : ⋂₀ c = ∅ ↔ ∀ a, ∃ b ∈ c, a ∉ b := by
simp [Set.eq_empty_iff_forall_not_mem]
#align set.sInter_eq_empty_iff Set.sInter_eq_empty_iff
-- classical
@[simp]
theorem nonempty_iInter {f : ι → Set α} : (⋂ i, f i).Nonempty ↔ ∃ x, ∀ i, x ∈ f i := by
simp [nonempty_iff_ne_empty, iInter_eq_empty_iff]
#align set.nonempty_Inter Set.nonempty_iInter
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/
-- classical
-- Porting note (#10618): removing `simp`. `simp` can prove it
theorem nonempty_iInter₂ {s : ∀ i, κ i → Set α} :
(⋂ (i) (j), s i j).Nonempty ↔ ∃ a, ∀ i j, a ∈ s i j := by
simp
#align set.nonempty_Inter₂ Set.nonempty_iInter₂
-- classical
@[simp]
theorem nonempty_sInter {c : Set (Set α)} : (⋂₀ c).Nonempty ↔ ∃ a, ∀ b ∈ c, a ∈ b := by
simp [nonempty_iff_ne_empty, sInter_eq_empty_iff]
#align set.nonempty_sInter Set.nonempty_sInter
-- classical
theorem compl_sUnion (S : Set (Set α)) : (⋃₀S)ᶜ = ⋂₀ (compl '' S) :=
ext fun x => by simp
#align set.compl_sUnion Set.compl_sUnion
-- classical
theorem sUnion_eq_compl_sInter_compl (S : Set (Set α)) : ⋃₀S = (⋂₀ (compl '' S))ᶜ := by
rw [← compl_compl (⋃₀S), compl_sUnion]
#align set.sUnion_eq_compl_sInter_compl Set.sUnion_eq_compl_sInter_compl
-- classical
theorem compl_sInter (S : Set (Set α)) : (⋂₀ S)ᶜ = ⋃₀(compl '' S) := by
rw [sUnion_eq_compl_sInter_compl, compl_compl_image]
#align set.compl_sInter Set.compl_sInter
-- classical
theorem sInter_eq_compl_sUnion_compl (S : Set (Set α)) : ⋂₀ S = (⋃₀(compl '' S))ᶜ := by
rw [← compl_compl (⋂₀ S), compl_sInter]
#align set.sInter_eq_compl_sUnion_compl Set.sInter_eq_compl_sUnion_compl
theorem inter_empty_of_inter_sUnion_empty {s t : Set α} {S : Set (Set α)} (hs : t ∈ S)
(h : s ∩ ⋃₀S = ∅) : s ∩ t = ∅ :=
eq_empty_of_subset_empty <| by
rw [← h]; exact inter_subset_inter_right _ (subset_sUnion_of_mem hs)
#align set.inter_empty_of_inter_sUnion_empty Set.inter_empty_of_inter_sUnion_empty
theorem range_sigma_eq_iUnion_range {γ : α → Type*} (f : Sigma γ → β) :
range f = ⋃ a, range fun b => f ⟨a, b⟩ :=
Set.ext <| by simp
#align set.range_sigma_eq_Union_range Set.range_sigma_eq_iUnion_range
theorem iUnion_eq_range_sigma (s : α → Set β) : ⋃ i, s i = range fun a : Σi, s i => a.2 := by
simp [Set.ext_iff]
#align set.Union_eq_range_sigma Set.iUnion_eq_range_sigma
theorem iUnion_eq_range_psigma (s : ι → Set β) : ⋃ i, s i = range fun a : Σ'i, s i => a.2 := by
simp [Set.ext_iff]
#align set.Union_eq_range_psigma Set.iUnion_eq_range_psigma
theorem iUnion_image_preimage_sigma_mk_eq_self {ι : Type*} {σ : ι → Type*} (s : Set (Sigma σ)) :
⋃ i, Sigma.mk i '' (Sigma.mk i ⁻¹' s) = s := by
ext x
simp only [mem_iUnion, mem_image, mem_preimage]
constructor
· rintro ⟨i, a, h, rfl⟩
exact h
· intro h
cases' x with i a
exact ⟨i, a, h, rfl⟩
#align set.Union_image_preimage_sigma_mk_eq_self Set.iUnion_image_preimage_sigma_mk_eq_self
theorem Sigma.univ (X : α → Type*) : (Set.univ : Set (Σa, X a)) = ⋃ a, range (Sigma.mk a) :=
Set.ext fun x =>
iff_of_true trivial ⟨range (Sigma.mk x.1), Set.mem_range_self _, x.2, Sigma.eta x⟩
#align set.sigma.univ Set.Sigma.univ
alias sUnion_mono := sUnion_subset_sUnion
#align set.sUnion_mono Set.sUnion_mono
theorem iUnion_subset_iUnion_const {s : Set α} (h : ι → ι₂) : ⋃ _ : ι, s ⊆ ⋃ _ : ι₂, s :=
iSup_const_mono (α := Set α) h
#align set.Union_subset_Union_const Set.iUnion_subset_iUnion_const
@[simp]
theorem iUnion_singleton_eq_range {α β : Type*} (f : α → β) : ⋃ x : α, {f x} = range f := by
ext x
simp [@eq_comm _ x]
#align set.Union_singleton_eq_range Set.iUnion_singleton_eq_range
theorem iUnion_of_singleton (α : Type*) : (⋃ x, {x} : Set α) = univ := by simp [Set.ext_iff]
#align set.Union_of_singleton Set.iUnion_of_singleton
theorem iUnion_of_singleton_coe (s : Set α) : ⋃ i : s, ({(i : α)} : Set α) = s := by simp
#align set.Union_of_singleton_coe Set.iUnion_of_singleton_coe
theorem sUnion_eq_biUnion {s : Set (Set α)} : ⋃₀s = ⋃ (i : Set α) (_ : i ∈ s), i := by
rw [← sUnion_image, image_id']
#align set.sUnion_eq_bUnion Set.sUnion_eq_biUnion
theorem sInter_eq_biInter {s : Set (Set α)} : ⋂₀ s = ⋂ (i : Set α) (_ : i ∈ s), i := by
rw [← sInter_image, image_id']
#align set.sInter_eq_bInter Set.sInter_eq_biInter
theorem sUnion_eq_iUnion {s : Set (Set α)} : ⋃₀s = ⋃ i : s, i := by
simp only [← sUnion_range, Subtype.range_coe]
#align set.sUnion_eq_Union Set.sUnion_eq_iUnion
theorem sInter_eq_iInter {s : Set (Set α)} : ⋂₀ s = ⋂ i : s, i := by
simp only [← sInter_range, Subtype.range_coe]
#align set.sInter_eq_Inter Set.sInter_eq_iInter
@[simp]
theorem iUnion_of_empty [IsEmpty ι] (s : ι → Set α) : ⋃ i, s i = ∅ :=
iSup_of_empty _
#align set.Union_of_empty Set.iUnion_of_empty
@[simp]
theorem iInter_of_empty [IsEmpty ι] (s : ι → Set α) : ⋂ i, s i = univ :=
iInf_of_empty _
#align set.Inter_of_empty Set.iInter_of_empty
theorem union_eq_iUnion {s₁ s₂ : Set α} : s₁ ∪ s₂ = ⋃ b : Bool, cond b s₁ s₂ :=
sup_eq_iSup s₁ s₂
#align set.union_eq_Union Set.union_eq_iUnion
theorem inter_eq_iInter {s₁ s₂ : Set α} : s₁ ∩ s₂ = ⋂ b : Bool, cond b s₁ s₂ :=
inf_eq_iInf s₁ s₂
#align set.inter_eq_Inter Set.inter_eq_iInter
theorem sInter_union_sInter {S T : Set (Set α)} :
⋂₀ S ∪ ⋂₀ T = ⋂ p ∈ S ×ˢ T, (p : Set α × Set α).1 ∪ p.2 :=
sInf_sup_sInf
#align set.sInter_union_sInter Set.sInter_union_sInter
theorem sUnion_inter_sUnion {s t : Set (Set α)} :
⋃₀s ∩ ⋃₀t = ⋃ p ∈ s ×ˢ t, (p : Set α × Set α).1 ∩ p.2 :=
sSup_inf_sSup
#align set.sUnion_inter_sUnion Set.sUnion_inter_sUnion
theorem biUnion_iUnion (s : ι → Set α) (t : α → Set β) :
⋃ x ∈ ⋃ i, s i, t x = ⋃ (i) (x ∈ s i), t x := by simp [@iUnion_comm _ ι]
#align set.bUnion_Union Set.biUnion_iUnion
theorem biInter_iUnion (s : ι → Set α) (t : α → Set β) :
⋂ x ∈ ⋃ i, s i, t x = ⋂ (i) (x ∈ s i), t x := by simp [@iInter_comm _ ι]
#align set.bInter_Union Set.biInter_iUnion
theorem sUnion_iUnion (s : ι → Set (Set α)) : ⋃₀⋃ i, s i = ⋃ i, ⋃₀s i := by
simp only [sUnion_eq_biUnion, biUnion_iUnion]
#align set.sUnion_Union Set.sUnion_iUnion
theorem sInter_iUnion (s : ι → Set (Set α)) : ⋂₀ ⋃ i, s i = ⋂ i, ⋂₀ s i := by
simp only [sInter_eq_biInter, biInter_iUnion]
#align set.sInter_Union Set.sInter_iUnion
theorem iUnion_range_eq_sUnion {α β : Type*} (C : Set (Set α)) {f : ∀ s : C, β → (s : Type _)}
(hf : ∀ s : C, Surjective (f s)) : ⋃ y : β, range (fun s : C => (f s y).val) = ⋃₀C := by
ext x; constructor
· rintro ⟨s, ⟨y, rfl⟩, ⟨s, hs⟩, rfl⟩
refine ⟨_, hs, ?_⟩
exact (f ⟨s, hs⟩ y).2
· rintro ⟨s, hs, hx⟩
cases' hf ⟨s, hs⟩ ⟨x, hx⟩ with y hy
refine ⟨_, ⟨y, rfl⟩, ⟨s, hs⟩, ?_⟩
exact congr_arg Subtype.val hy
#align set.Union_range_eq_sUnion Set.iUnion_range_eq_sUnion
theorem iUnion_range_eq_iUnion (C : ι → Set α) {f : ∀ x : ι, β → C x}
(hf : ∀ x : ι, Surjective (f x)) : ⋃ y : β, range (fun x : ι => (f x y).val) = ⋃ x, C x := by
ext x; rw [mem_iUnion, mem_iUnion]; constructor
· rintro ⟨y, i, rfl⟩
exact ⟨i, (f i y).2⟩
· rintro ⟨i, hx⟩
cases' hf i ⟨x, hx⟩ with y hy
exact ⟨y, i, congr_arg Subtype.val hy⟩
#align set.Union_range_eq_Union Set.iUnion_range_eq_iUnion
theorem union_distrib_iInter_left (s : ι → Set α) (t : Set α) : (t ∪ ⋂ i, s i) = ⋂ i, t ∪ s i :=
sup_iInf_eq _ _
#align set.union_distrib_Inter_left Set.union_distrib_iInter_left
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/
theorem union_distrib_iInter₂_left (s : Set α) (t : ∀ i, κ i → Set α) :
(s ∪ ⋂ (i) (j), t i j) = ⋂ (i) (j), s ∪ t i j := by simp_rw [union_distrib_iInter_left]
#align set.union_distrib_Inter₂_left Set.union_distrib_iInter₂_left
theorem union_distrib_iInter_right (s : ι → Set α) (t : Set α) : (⋂ i, s i) ∪ t = ⋂ i, s i ∪ t :=
iInf_sup_eq _ _
#align set.union_distrib_Inter_right Set.union_distrib_iInter_right
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/
theorem union_distrib_iInter₂_right (s : ∀ i, κ i → Set α) (t : Set α) :
(⋂ (i) (j), s i j) ∪ t = ⋂ (i) (j), s i j ∪ t := by simp_rw [union_distrib_iInter_right]
#align set.union_distrib_Inter₂_right Set.union_distrib_iInter₂_right
section Function
/-! ### Lemmas about `Set.MapsTo`
Porting note: some lemmas in this section were upgraded from implications to `iff`s.
-/
@[simp]
theorem mapsTo_sUnion {S : Set (Set α)} {t : Set β} {f : α → β} :
MapsTo f (⋃₀ S) t ↔ ∀ s ∈ S, MapsTo f s t :=
sUnion_subset_iff
#align set.maps_to_sUnion Set.mapsTo_sUnion
@[simp]
theorem mapsTo_iUnion {s : ι → Set α} {t : Set β} {f : α → β} :
MapsTo f (⋃ i, s i) t ↔ ∀ i, MapsTo f (s i) t :=
iUnion_subset_iff
#align set.maps_to_Union Set.mapsTo_iUnion
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/
theorem mapsTo_iUnion₂ {s : ∀ i, κ i → Set α} {t : Set β} {f : α → β} :
MapsTo f (⋃ (i) (j), s i j) t ↔ ∀ i j, MapsTo f (s i j) t :=
iUnion₂_subset_iff
#align set.maps_to_Union₂ Set.mapsTo_iUnion₂
theorem mapsTo_iUnion_iUnion {s : ι → Set α} {t : ι → Set β} {f : α → β}
(H : ∀ i, MapsTo f (s i) (t i)) : MapsTo f (⋃ i, s i) (⋃ i, t i) :=
mapsTo_iUnion.2 fun i ↦ (H i).mono_right (subset_iUnion t i)
#align set.maps_to_Union_Union Set.mapsTo_iUnion_iUnion
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/
theorem mapsTo_iUnion₂_iUnion₂ {s : ∀ i, κ i → Set α} {t : ∀ i, κ i → Set β} {f : α → β}
(H : ∀ i j, MapsTo f (s i j) (t i j)) : MapsTo f (⋃ (i) (j), s i j) (⋃ (i) (j), t i j) :=
mapsTo_iUnion_iUnion fun i => mapsTo_iUnion_iUnion (H i)
#align set.maps_to_Union₂_Union₂ Set.mapsTo_iUnion₂_iUnion₂
@[simp]
theorem mapsTo_sInter {s : Set α} {T : Set (Set β)} {f : α → β} :
MapsTo f s (⋂₀ T) ↔ ∀ t ∈ T, MapsTo f s t :=
forall₂_swap
#align set.maps_to_sInter Set.mapsTo_sInter
@[simp]
theorem mapsTo_iInter {s : Set α} {t : ι → Set β} {f : α → β} :
MapsTo f s (⋂ i, t i) ↔ ∀ i, MapsTo f s (t i) :=
mapsTo_sInter.trans forall_mem_range
#align set.maps_to_Inter Set.mapsTo_iInter
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/
theorem mapsTo_iInter₂ {s : Set α} {t : ∀ i, κ i → Set β} {f : α → β} :
MapsTo f s (⋂ (i) (j), t i j) ↔ ∀ i j, MapsTo f s (t i j) := by
simp only [mapsTo_iInter]
#align set.maps_to_Inter₂ Set.mapsTo_iInter₂
theorem mapsTo_iInter_iInter {s : ι → Set α} {t : ι → Set β} {f : α → β}
(H : ∀ i, MapsTo f (s i) (t i)) : MapsTo f (⋂ i, s i) (⋂ i, t i) :=
mapsTo_iInter.2 fun i => (H i).mono_left (iInter_subset s i)
#align set.maps_to_Inter_Inter Set.mapsTo_iInter_iInter
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/
theorem mapsTo_iInter₂_iInter₂ {s : ∀ i, κ i → Set α} {t : ∀ i, κ i → Set β} {f : α → β}
(H : ∀ i j, MapsTo f (s i j) (t i j)) : MapsTo f (⋂ (i) (j), s i j) (⋂ (i) (j), t i j) :=
mapsTo_iInter_iInter fun i => mapsTo_iInter_iInter (H i)
#align set.maps_to_Inter₂_Inter₂ Set.mapsTo_iInter₂_iInter₂
theorem image_iInter_subset (s : ι → Set α) (f : α → β) : (f '' ⋂ i, s i) ⊆ ⋂ i, f '' s i :=
(mapsTo_iInter_iInter fun i => mapsTo_image f (s i)).image_subset
#align set.image_Inter_subset Set.image_iInter_subset
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/
theorem image_iInter₂_subset (s : ∀ i, κ i → Set α) (f : α → β) :
(f '' ⋂ (i) (j), s i j) ⊆ ⋂ (i) (j), f '' s i j :=
(mapsTo_iInter₂_iInter₂ fun i hi => mapsTo_image f (s i hi)).image_subset
#align set.image_Inter₂_subset Set.image_iInter₂_subset
theorem image_sInter_subset (S : Set (Set α)) (f : α → β) : f '' ⋂₀ S ⊆ ⋂ s ∈ S, f '' s := by
rw [sInter_eq_biInter]
apply image_iInter₂_subset
#align set.image_sInter_subset Set.image_sInter_subset
/-! ### `restrictPreimage` -/
section
open Function
variable (s : Set β) {f : α → β} {U : ι → Set β} (hU : iUnion U = univ)
theorem injective_iff_injective_of_iUnion_eq_univ :
Injective f ↔ ∀ i, Injective ((U i).restrictPreimage f) := by
refine ⟨fun H i => (U i).restrictPreimage_injective H, fun H x y e => ?_⟩
obtain ⟨i, hi⟩ := Set.mem_iUnion.mp
(show f x ∈ Set.iUnion U by rw [hU]; trivial)
injection @H i ⟨x, hi⟩ ⟨y, show f y ∈ U i from e ▸ hi⟩ (Subtype.ext e)
#align set.injective_iff_injective_of_Union_eq_univ Set.injective_iff_injective_of_iUnion_eq_univ
theorem surjective_iff_surjective_of_iUnion_eq_univ :
Surjective f ↔ ∀ i, Surjective ((U i).restrictPreimage f) := by
refine ⟨fun H i => (U i).restrictPreimage_surjective H, fun H x => ?_⟩
obtain ⟨i, hi⟩ :=
Set.mem_iUnion.mp
(show x ∈ Set.iUnion U by rw [hU]; trivial)
exact ⟨_, congr_arg Subtype.val (H i ⟨x, hi⟩).choose_spec⟩
#align set.surjective_iff_surjective_of_Union_eq_univ Set.surjective_iff_surjective_of_iUnion_eq_univ
theorem bijective_iff_bijective_of_iUnion_eq_univ :
Bijective f ↔ ∀ i, Bijective ((U i).restrictPreimage f) := by
rw [Bijective, injective_iff_injective_of_iUnion_eq_univ hU,
surjective_iff_surjective_of_iUnion_eq_univ hU]
simp [Bijective, forall_and]
#align set.bijective_iff_bijective_of_Union_eq_univ Set.bijective_iff_bijective_of_iUnion_eq_univ
end
/-! ### `InjOn` -/
theorem InjOn.image_iInter_eq [Nonempty ι] {s : ι → Set α} {f : α → β} (h : InjOn f (⋃ i, s i)) :
(f '' ⋂ i, s i) = ⋂ i, f '' s i := by
inhabit ι
refine Subset.antisymm (image_iInter_subset s f) fun y hy => ?_
simp only [mem_iInter, mem_image] at hy
choose x hx hy using hy
refine ⟨x default, mem_iInter.2 fun i => ?_, hy _⟩
suffices x default = x i by
rw [this]
apply hx
replace hx : ∀ i, x i ∈ ⋃ j, s j := fun i => (subset_iUnion _ _) (hx i)
apply h (hx _) (hx _)
simp only [hy]
#align set.inj_on.image_Inter_eq Set.InjOn.image_iInter_eq
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i hi) -/
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i hi) -/
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i hi) -/
theorem InjOn.image_biInter_eq {p : ι → Prop} {s : ∀ i, p i → Set α} (hp : ∃ i, p i)
{f : α → β} (h : InjOn f (⋃ (i) (hi), s i hi)) :
(f '' ⋂ (i) (hi), s i hi) = ⋂ (i) (hi), f '' s i hi := by
simp only [iInter, iInf_subtype']
haveI : Nonempty { i // p i } := nonempty_subtype.2 hp
apply InjOn.image_iInter_eq
simpa only [iUnion, iSup_subtype'] using h
#align set.inj_on.image_bInter_eq Set.InjOn.image_biInter_eq
theorem image_iInter {f : α → β} (hf : Bijective f) (s : ι → Set α) :
(f '' ⋂ i, s i) = ⋂ i, f '' s i := by
cases isEmpty_or_nonempty ι
· simp_rw [iInter_of_empty, image_univ_of_surjective hf.surjective]
· exact hf.injective.injOn.image_iInter_eq
#align set.image_Inter Set.image_iInter
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/
theorem image_iInter₂ {f : α → β} (hf : Bijective f) (s : ∀ i, κ i → Set α) :
(f '' ⋂ (i) (j), s i j) = ⋂ (i) (j), f '' s i j := by simp_rw [image_iInter hf]
#align set.image_Inter₂ Set.image_iInter₂
theorem inj_on_iUnion_of_directed {s : ι → Set α} (hs : Directed (· ⊆ ·) s) {f : α → β}
(hf : ∀ i, InjOn f (s i)) : InjOn f (⋃ i, s i) := by
intro x hx y hy hxy
rcases mem_iUnion.1 hx with ⟨i, hx⟩
rcases mem_iUnion.1 hy with ⟨j, hy⟩
rcases hs i j with ⟨k, hi, hj⟩
exact hf k (hi hx) (hj hy) hxy
#align set.inj_on_Union_of_directed Set.inj_on_iUnion_of_directed
/-! ### `SurjOn` -/
theorem surjOn_sUnion {s : Set α} {T : Set (Set β)} {f : α → β} (H : ∀ t ∈ T, SurjOn f s t) :
SurjOn f s (⋃₀T) := fun _ ⟨t, ht, hx⟩ => H t ht hx
#align set.surj_on_sUnion Set.surjOn_sUnion
theorem surjOn_iUnion {s : Set α} {t : ι → Set β} {f : α → β} (H : ∀ i, SurjOn f s (t i)) :
SurjOn f s (⋃ i, t i) :=
surjOn_sUnion <| forall_mem_range.2 H
#align set.surj_on_Union Set.surjOn_iUnion
theorem surjOn_iUnion_iUnion {s : ι → Set α} {t : ι → Set β} {f : α → β}
(H : ∀ i, SurjOn f (s i) (t i)) : SurjOn f (⋃ i, s i) (⋃ i, t i) :=
surjOn_iUnion fun i => (H i).mono (subset_iUnion _ _) (Subset.refl _)
#align set.surj_on_Union_Union Set.surjOn_iUnion_iUnion
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/
theorem surjOn_iUnion₂ {s : Set α} {t : ∀ i, κ i → Set β} {f : α → β}
(H : ∀ i j, SurjOn f s (t i j)) : SurjOn f s (⋃ (i) (j), t i j) :=
surjOn_iUnion fun i => surjOn_iUnion (H i)
#align set.surj_on_Union₂ Set.surjOn_iUnion₂
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/
theorem surjOn_iUnion₂_iUnion₂ {s : ∀ i, κ i → Set α} {t : ∀ i, κ i → Set β} {f : α → β}
(H : ∀ i j, SurjOn f (s i j) (t i j)) : SurjOn f (⋃ (i) (j), s i j) (⋃ (i) (j), t i j) :=
surjOn_iUnion_iUnion fun i => surjOn_iUnion_iUnion (H i)
#align set.surj_on_Union₂_Union₂ Set.surjOn_iUnion₂_iUnion₂
theorem surjOn_iInter [Nonempty ι] {s : ι → Set α} {t : Set β} {f : α → β}
(H : ∀ i, SurjOn f (s i) t) (Hinj : InjOn f (⋃ i, s i)) : SurjOn f (⋂ i, s i) t := by
intro y hy
rw [Hinj.image_iInter_eq, mem_iInter]
exact fun i => H i hy
#align set.surj_on_Inter Set.surjOn_iInter
theorem surjOn_iInter_iInter [Nonempty ι] {s : ι → Set α} {t : ι → Set β} {f : α → β}
(H : ∀ i, SurjOn f (s i) (t i)) (Hinj : InjOn f (⋃ i, s i)) : SurjOn f (⋂ i, s i) (⋂ i, t i) :=
surjOn_iInter (fun i => (H i).mono (Subset.refl _) (iInter_subset _ _)) Hinj
#align set.surj_on_Inter_Inter Set.surjOn_iInter_iInter
/-! ### `BijOn` -/
theorem bijOn_iUnion {s : ι → Set α} {t : ι → Set β} {f : α → β} (H : ∀ i, BijOn f (s i) (t i))
(Hinj : InjOn f (⋃ i, s i)) : BijOn f (⋃ i, s i) (⋃ i, t i) :=
⟨mapsTo_iUnion_iUnion fun i => (H i).mapsTo, Hinj, surjOn_iUnion_iUnion fun i => (H i).surjOn⟩
#align set.bij_on_Union Set.bijOn_iUnion
theorem bijOn_iInter [hi : Nonempty ι] {s : ι → Set α} {t : ι → Set β} {f : α → β}
(H : ∀ i, BijOn f (s i) (t i)) (Hinj : InjOn f (⋃ i, s i)) : BijOn f (⋂ i, s i) (⋂ i, t i) :=
⟨mapsTo_iInter_iInter fun i => (H i).mapsTo,
hi.elim fun i => (H i).injOn.mono (iInter_subset _ _),
surjOn_iInter_iInter (fun i => (H i).surjOn) Hinj⟩
#align set.bij_on_Inter Set.bijOn_iInter
theorem bijOn_iUnion_of_directed {s : ι → Set α} (hs : Directed (· ⊆ ·) s) {t : ι → Set β}
{f : α → β} (H : ∀ i, BijOn f (s i) (t i)) : BijOn f (⋃ i, s i) (⋃ i, t i) :=
bijOn_iUnion H <| inj_on_iUnion_of_directed hs fun i => (H i).injOn
#align set.bij_on_Union_of_directed Set.bijOn_iUnion_of_directed
theorem bijOn_iInter_of_directed [Nonempty ι] {s : ι → Set α} (hs : Directed (· ⊆ ·) s)
{t : ι → Set β} {f : α → β} (H : ∀ i, BijOn f (s i) (t i)) : BijOn f (⋂ i, s i) (⋂ i, t i) :=
bijOn_iInter H <| inj_on_iUnion_of_directed hs fun i => (H i).injOn
#align set.bij_on_Inter_of_directed Set.bijOn_iInter_of_directed
end Function
/-! ### `image`, `preimage` -/
section Image
theorem image_iUnion {f : α → β} {s : ι → Set α} : (f '' ⋃ i, s i) = ⋃ i, f '' s i := by
ext1 x
simp only [mem_image, mem_iUnion, ← exists_and_right, ← exists_and_left]
-- Porting note: `exists_swap` causes a `simp` loop in Lean4 so we use `rw` instead.
rw [exists_swap]
#align set.image_Union Set.image_iUnion
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/
theorem image_iUnion₂ (f : α → β) (s : ∀ i, κ i → Set α) :
(f '' ⋃ (i) (j), s i j) = ⋃ (i) (j), f '' s i j := by simp_rw [image_iUnion]
#align set.image_Union₂ Set.image_iUnion₂
theorem univ_subtype {p : α → Prop} : (univ : Set (Subtype p)) = ⋃ (x) (h : p x), {⟨x, h⟩} :=
Set.ext fun ⟨x, h⟩ => by simp [h]
#align set.univ_subtype Set.univ_subtype
theorem range_eq_iUnion {ι} (f : ι → α) : range f = ⋃ i, {f i} :=
Set.ext fun a => by simp [@eq_comm α a]
#align set.range_eq_Union Set.range_eq_iUnion
theorem image_eq_iUnion (f : α → β) (s : Set α) : f '' s = ⋃ i ∈ s, {f i} :=
Set.ext fun b => by simp [@eq_comm β b]
#align set.image_eq_Union Set.image_eq_iUnion
theorem biUnion_range {f : ι → α} {g : α → Set β} : ⋃ x ∈ range f, g x = ⋃ y, g (f y) :=
iSup_range
#align set.bUnion_range Set.biUnion_range
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (x y) -/
@[simp]
theorem iUnion_iUnion_eq' {f : ι → α} {g : α → Set β} :
⋃ (x) (y) (_ : f y = x), g x = ⋃ y, g (f y) := by simpa using biUnion_range
#align set.Union_Union_eq' Set.iUnion_iUnion_eq'
theorem biInter_range {f : ι → α} {g : α → Set β} : ⋂ x ∈ range f, g x = ⋂ y, g (f y) :=
iInf_range
#align set.bInter_range Set.biInter_range
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (x y) -/
@[simp]
theorem iInter_iInter_eq' {f : ι → α} {g : α → Set β} :
⋂ (x) (y) (_ : f y = x), g x = ⋂ y, g (f y) := by simpa using biInter_range
#align set.Inter_Inter_eq' Set.iInter_iInter_eq'
variable {s : Set γ} {f : γ → α} {g : α → Set β}
theorem biUnion_image : ⋃ x ∈ f '' s, g x = ⋃ y ∈ s, g (f y) :=
iSup_image
#align set.bUnion_image Set.biUnion_image
theorem biInter_image : ⋂ x ∈ f '' s, g x = ⋂ y ∈ s, g (f y) :=
iInf_image
#align set.bInter_image Set.biInter_image
end Image
section Preimage
theorem monotone_preimage {f : α → β} : Monotone (preimage f) := fun _ _ h => preimage_mono h
#align set.monotone_preimage Set.monotone_preimage
@[simp]
theorem preimage_iUnion {f : α → β} {s : ι → Set β} : (f ⁻¹' ⋃ i, s i) = ⋃ i, f ⁻¹' s i :=
Set.ext <| by simp [preimage]
#align set.preimage_Union Set.preimage_iUnion
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/
theorem preimage_iUnion₂ {f : α → β} {s : ∀ i, κ i → Set β} :
(f ⁻¹' ⋃ (i) (j), s i j) = ⋃ (i) (j), f ⁻¹' s i j := by simp_rw [preimage_iUnion]
#align set.preimage_Union₂ Set.preimage_iUnion₂
theorem image_sUnion {f : α → β} {s : Set (Set α)} : (f '' ⋃₀ s) = ⋃₀ (image f '' s) := by
ext b
simp only [mem_image, mem_sUnion, exists_prop, sUnion_image, mem_iUnion]
constructor
· rintro ⟨a, ⟨t, ht₁, ht₂⟩, rfl⟩
exact ⟨t, ht₁, a, ht₂, rfl⟩
· rintro ⟨t, ht₁, a, ht₂, rfl⟩
exact ⟨a, ⟨t, ht₁, ht₂⟩, rfl⟩
@[simp]
theorem preimage_sUnion {f : α → β} {s : Set (Set β)} : f ⁻¹' ⋃₀s = ⋃ t ∈ s, f ⁻¹' t := by
rw [sUnion_eq_biUnion, preimage_iUnion₂]
#align set.preimage_sUnion Set.preimage_sUnion
theorem preimage_iInter {f : α → β} {s : ι → Set β} : (f ⁻¹' ⋂ i, s i) = ⋂ i, f ⁻¹' s i := by
ext; simp
#align set.preimage_Inter Set.preimage_iInter
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/
theorem preimage_iInter₂ {f : α → β} {s : ∀ i, κ i → Set β} :
(f ⁻¹' ⋂ (i) (j), s i j) = ⋂ (i) (j), f ⁻¹' s i j := by simp_rw [preimage_iInter]
#align set.preimage_Inter₂ Set.preimage_iInter₂
@[simp]
theorem preimage_sInter {f : α → β} {s : Set (Set β)} : f ⁻¹' ⋂₀ s = ⋂ t ∈ s, f ⁻¹' t := by
rw [sInter_eq_biInter, preimage_iInter₂]
#align set.preimage_sInter Set.preimage_sInter
@[simp]
theorem biUnion_preimage_singleton (f : α → β) (s : Set β) : ⋃ y ∈ s, f ⁻¹' {y} = f ⁻¹' s := by
rw [← preimage_iUnion₂, biUnion_of_singleton]
#align set.bUnion_preimage_singleton Set.biUnion_preimage_singleton
theorem biUnion_range_preimage_singleton (f : α → β) : ⋃ y ∈ range f, f ⁻¹' {y} = univ := by
rw [biUnion_preimage_singleton, preimage_range]
#align set.bUnion_range_preimage_singleton Set.biUnion_range_preimage_singleton
end Preimage
section Prod
theorem prod_iUnion {s : Set α} {t : ι → Set β} : (s ×ˢ ⋃ i, t i) = ⋃ i, s ×ˢ t i := by
ext
simp
#align set.prod_Union Set.prod_iUnion
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/
theorem prod_iUnion₂ {s : Set α} {t : ∀ i, κ i → Set β} :
(s ×ˢ ⋃ (i) (j), t i j) = ⋃ (i) (j), s ×ˢ t i j := by simp_rw [prod_iUnion]
#align set.prod_Union₂ Set.prod_iUnion₂
theorem prod_sUnion {s : Set α} {C : Set (Set β)} : s ×ˢ ⋃₀C = ⋃₀((fun t => s ×ˢ t) '' C) := by
simp_rw [sUnion_eq_biUnion, biUnion_image, prod_iUnion₂]
#align set.prod_sUnion Set.prod_sUnion
theorem iUnion_prod_const {s : ι → Set α} {t : Set β} : (⋃ i, s i) ×ˢ t = ⋃ i, s i ×ˢ t := by
ext
simp
#align set.Union_prod_const Set.iUnion_prod_const
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/
theorem iUnion₂_prod_const {s : ∀ i, κ i → Set α} {t : Set β} :
(⋃ (i) (j), s i j) ×ˢ t = ⋃ (i) (j), s i j ×ˢ t := by simp_rw [iUnion_prod_const]
#align set.Union₂_prod_const Set.iUnion₂_prod_const
theorem sUnion_prod_const {C : Set (Set α)} {t : Set β} :
⋃₀C ×ˢ t = ⋃₀((fun s : Set α => s ×ˢ t) '' C) := by
simp only [sUnion_eq_biUnion, iUnion₂_prod_const, biUnion_image]
#align set.sUnion_prod_const Set.sUnion_prod_const
theorem iUnion_prod {ι ι' α β} (s : ι → Set α) (t : ι' → Set β) :
⋃ x : ι × ι', s x.1 ×ˢ t x.2 = (⋃ i : ι, s i) ×ˢ ⋃ i : ι', t i := by
ext
simp
#align set.Union_prod Set.iUnion_prod
/-- Analogue of `iSup_prod` for sets. -/
lemma iUnion_prod' (f : β × γ → Set α) : ⋃ x : β × γ, f x = ⋃ (i : β) (j : γ), f (i, j) :=
iSup_prod
theorem iUnion_prod_of_monotone [SemilatticeSup α] {s : α → Set β} {t : α → Set γ} (hs : Monotone s)
(ht : Monotone t) : ⋃ x, s x ×ˢ t x = (⋃ x, s x) ×ˢ ⋃ x, t x := by
ext ⟨z, w⟩; simp only [mem_prod, mem_iUnion, exists_imp, and_imp, iff_def]; constructor
· intro x hz hw
exact ⟨⟨x, hz⟩, x, hw⟩
· intro x hz x' hw
exact ⟨x ⊔ x', hs le_sup_left hz, ht le_sup_right hw⟩
#align set.Union_prod_of_monotone Set.iUnion_prod_of_monotone
theorem sInter_prod_sInter_subset (S : Set (Set α)) (T : Set (Set β)) :
⋂₀ S ×ˢ ⋂₀ T ⊆ ⋂ r ∈ S ×ˢ T, r.1 ×ˢ r.2 :=
subset_iInter₂ fun x hx _ hy => ⟨hy.1 x.1 hx.1, hy.2 x.2 hx.2⟩
#align set.sInter_prod_sInter_subset Set.sInter_prod_sInter_subset
theorem sInter_prod_sInter {S : Set (Set α)} {T : Set (Set β)} (hS : S.Nonempty) (hT : T.Nonempty) :
⋂₀ S ×ˢ ⋂₀ T = ⋂ r ∈ S ×ˢ T, r.1 ×ˢ r.2 := by
obtain ⟨s₁, h₁⟩ := hS
obtain ⟨s₂, h₂⟩ := hT
refine Set.Subset.antisymm (sInter_prod_sInter_subset S T) fun x hx => ?_
rw [mem_iInter₂] at hx
exact ⟨fun s₀ h₀ => (hx (s₀, s₂) ⟨h₀, h₂⟩).1, fun s₀ h₀ => (hx (s₁, s₀) ⟨h₁, h₀⟩).2⟩
#align set.sInter_prod_sInter Set.sInter_prod_sInter
theorem sInter_prod {S : Set (Set α)} (hS : S.Nonempty) (t : Set β) :
⋂₀ S ×ˢ t = ⋂ s ∈ S, s ×ˢ t := by
rw [← sInter_singleton t, sInter_prod_sInter hS (singleton_nonempty t), sInter_singleton]
simp_rw [prod_singleton, mem_image, iInter_exists, biInter_and', iInter_iInter_eq_right]
#align set.sInter_prod Set.sInter_prod
| Mathlib/Data/Set/Lattice.lean | 1,835 | 1,838 | theorem prod_sInter {T : Set (Set β)} (hT : T.Nonempty) (s : Set α) :
s ×ˢ ⋂₀ T = ⋂ t ∈ T, s ×ˢ t := by |
rw [← sInter_singleton s, sInter_prod_sInter (singleton_nonempty s) hT, sInter_singleton]
simp_rw [singleton_prod, mem_image, iInter_exists, biInter_and', iInter_iInter_eq_right]
|
/-
Copyright (c) 2022 Anne Baanen. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Anne Baanen, Alex J. Best
-/
import Mathlib.Algebra.CharP.Quotient
import Mathlib.Algebra.GroupWithZero.NonZeroDivisors
import Mathlib.Data.Finsupp.Fintype
import Mathlib.Data.Int.AbsoluteValue
import Mathlib.Data.Int.Associated
import Mathlib.LinearAlgebra.FreeModule.Determinant
import Mathlib.LinearAlgebra.FreeModule.IdealQuotient
import Mathlib.RingTheory.DedekindDomain.PID
import Mathlib.RingTheory.Ideal.Basis
import Mathlib.RingTheory.LocalProperties
import Mathlib.RingTheory.Localization.NormTrace
#align_import ring_theory.ideal.norm from "leanprover-community/mathlib"@"f0c8bf9245297a541f468be517f1bde6195105e9"
/-!
# Ideal norms
This file defines the absolute ideal norm `Ideal.absNorm (I : Ideal R) : ℕ` as the cardinality of
the quotient `R ⧸ I` (setting it to 0 if the cardinality is infinite),
and the relative ideal norm `Ideal.spanNorm R (I : Ideal S) : Ideal S` as the ideal spanned by
the norms of elements in `I`.
## Main definitions
* `Submodule.cardQuot (S : Submodule R M)`: the cardinality of the quotient `M ⧸ S`, in `ℕ`.
This maps `⊥` to `0` and `⊤` to `1`.
* `Ideal.absNorm (I : Ideal R)`: the absolute ideal norm, defined as
the cardinality of the quotient `R ⧸ I`, as a bundled monoid-with-zero homomorphism.
* `Ideal.spanNorm R (I : Ideal S)`: the ideal spanned by the norms of elements in `I`.
This is used to define `Ideal.relNorm`.
* `Ideal.relNorm R (I : Ideal S)`: the relative ideal norm as a bundled monoid-with-zero morphism,
defined as the ideal spanned by the norms of elements in `I`.
## Main results
* `map_mul Ideal.absNorm`: multiplicativity of the ideal norm is bundled in
the definition of `Ideal.absNorm`
* `Ideal.natAbs_det_basis_change`: the ideal norm is given by the determinant
of the basis change matrix
* `Ideal.absNorm_span_singleton`: the ideal norm of a principal ideal is the
norm of its generator
* `map_mul Ideal.relNorm`: multiplicativity of the relative ideal norm
-/
open scoped nonZeroDivisors
section abs_norm
namespace Submodule
variable {R M : Type*} [Ring R] [AddCommGroup M] [Module R M]
section
/-- The cardinality of `(M ⧸ S)`, if `(M ⧸ S)` is finite, and `0` otherwise.
This is used to define the absolute ideal norm `Ideal.absNorm`.
-/
noncomputable def cardQuot (S : Submodule R M) : ℕ :=
AddSubgroup.index S.toAddSubgroup
#align submodule.card_quot Submodule.cardQuot
@[simp]
theorem cardQuot_apply (S : Submodule R M) [h : Fintype (M ⧸ S)] :
cardQuot S = Fintype.card (M ⧸ S) := by
-- Porting note: original proof was AddSubgroup.index_eq_card _
suffices Fintype (M ⧸ S.toAddSubgroup) by convert AddSubgroup.index_eq_card S.toAddSubgroup
convert h
#align submodule.card_quot_apply Submodule.cardQuot_apply
variable (R M)
@[simp]
theorem cardQuot_bot [Infinite M] : cardQuot (⊥ : Submodule R M) = 0 :=
AddSubgroup.index_bot.trans Nat.card_eq_zero_of_infinite
#align submodule.card_quot_bot Submodule.cardQuot_bot
-- @[simp] -- Porting note (#10618): simp can prove this
theorem cardQuot_top : cardQuot (⊤ : Submodule R M) = 1 :=
AddSubgroup.index_top
#align submodule.card_quot_top Submodule.cardQuot_top
variable {R M}
@[simp]
theorem cardQuot_eq_one_iff {P : Submodule R M} : cardQuot P = 1 ↔ P = ⊤ :=
AddSubgroup.index_eq_one.trans (by simp [SetLike.ext_iff])
#align submodule.card_quot_eq_one_iff Submodule.cardQuot_eq_one_iff
end
end Submodule
section RingOfIntegers
variable {S : Type*} [CommRing S] [IsDomain S]
open Submodule
/-- Multiplicity of the ideal norm, for coprime ideals.
This is essentially just a repackaging of the Chinese Remainder Theorem.
-/
theorem cardQuot_mul_of_coprime [Module.Free ℤ S] [Module.Finite ℤ S]
{I J : Ideal S} (coprime : IsCoprime I J) : cardQuot (I * J) = cardQuot I * cardQuot J := by
let b := Module.Free.chooseBasis ℤ S
cases isEmpty_or_nonempty (Module.Free.ChooseBasisIndex ℤ S)
· haveI : Subsingleton S := Function.Surjective.subsingleton b.repr.toEquiv.symm.surjective
nontriviality S
exfalso
exact not_nontrivial_iff_subsingleton.mpr ‹Subsingleton S› ‹Nontrivial S›
haveI : Infinite S := Infinite.of_surjective _ b.repr.toEquiv.surjective
by_cases hI : I = ⊥
· rw [hI, Submodule.bot_mul, cardQuot_bot, zero_mul]
by_cases hJ : J = ⊥
· rw [hJ, Submodule.mul_bot, cardQuot_bot, mul_zero]
have hIJ : I * J ≠ ⊥ := mt Ideal.mul_eq_bot.mp (not_or_of_not hI hJ)
letI := Classical.decEq (Module.Free.ChooseBasisIndex ℤ S)
letI := I.fintypeQuotientOfFreeOfNeBot hI
letI := J.fintypeQuotientOfFreeOfNeBot hJ
letI := (I * J).fintypeQuotientOfFreeOfNeBot hIJ
rw [cardQuot_apply, cardQuot_apply, cardQuot_apply,
Fintype.card_eq.mpr ⟨(Ideal.quotientMulEquivQuotientProd I J coprime).toEquiv⟩,
Fintype.card_prod]
#align card_quot_mul_of_coprime cardQuot_mul_of_coprime
/-- If the `d` from `Ideal.exists_mul_add_mem_pow_succ` is unique, up to `P`,
then so are the `c`s, up to `P ^ (i + 1)`.
Inspired by [Neukirch], proposition 6.1 -/
theorem Ideal.mul_add_mem_pow_succ_inj (P : Ideal S) {i : ℕ} (a d d' e e' : S) (a_mem : a ∈ P ^ i)
(e_mem : e ∈ P ^ (i + 1)) (e'_mem : e' ∈ P ^ (i + 1)) (h : d - d' ∈ P) :
a * d + e - (a * d' + e') ∈ P ^ (i + 1) := by
have : a * d - a * d' ∈ P ^ (i + 1) := by
simp only [← mul_sub]
exact Ideal.mul_mem_mul a_mem h
convert Ideal.add_mem _ this (Ideal.sub_mem _ e_mem e'_mem) using 1
ring
#align ideal.mul_add_mem_pow_succ_inj Ideal.mul_add_mem_pow_succ_inj
section PPrime
variable {P : Ideal S} [P_prime : P.IsPrime] (hP : P ≠ ⊥)
/-- If `a ∈ P^i \ P^(i+1)` and `c ∈ P^i`, then `a * d + e = c` for `e ∈ P^(i+1)`.
`Ideal.mul_add_mem_pow_succ_unique` shows the choice of `d` is unique, up to `P`.
Inspired by [Neukirch], proposition 6.1 -/
theorem Ideal.exists_mul_add_mem_pow_succ [IsDedekindDomain S] {i : ℕ} (a c : S) (a_mem : a ∈ P ^ i)
(a_not_mem : a ∉ P ^ (i + 1)) (c_mem : c ∈ P ^ i) :
∃ d : S, ∃ e ∈ P ^ (i + 1), a * d + e = c := by
suffices eq_b : P ^ i = Ideal.span {a} ⊔ P ^ (i + 1) by
rw [eq_b] at c_mem
simp only [mul_comm a]
exact Ideal.mem_span_singleton_sup.mp c_mem
refine (Ideal.eq_prime_pow_of_succ_lt_of_le hP (lt_of_le_of_ne le_sup_right ?_)
(sup_le (Ideal.span_le.mpr (Set.singleton_subset_iff.mpr a_mem))
(Ideal.pow_succ_lt_pow hP i).le)).symm
contrapose! a_not_mem with this
rw [this]
exact mem_sup.mpr ⟨a, mem_span_singleton_self a, 0, by simp, by simp⟩
#align ideal.exists_mul_add_mem_pow_succ Ideal.exists_mul_add_mem_pow_succ
theorem Ideal.mem_prime_of_mul_mem_pow [IsDedekindDomain S] {P : Ideal S} [P_prime : P.IsPrime]
(hP : P ≠ ⊥) {i : ℕ} {a b : S} (a_not_mem : a ∉ P ^ (i + 1)) (ab_mem : a * b ∈ P ^ (i + 1)) :
b ∈ P := by
simp only [← Ideal.span_singleton_le_iff_mem, ← Ideal.dvd_iff_le, pow_succ, ←
Ideal.span_singleton_mul_span_singleton] at a_not_mem ab_mem ⊢
exact (prime_pow_succ_dvd_mul (Ideal.prime_of_isPrime hP P_prime) ab_mem).resolve_left a_not_mem
#align ideal.mem_prime_of_mul_mem_pow Ideal.mem_prime_of_mul_mem_pow
/-- The choice of `d` in `Ideal.exists_mul_add_mem_pow_succ` is unique, up to `P`.
Inspired by [Neukirch], proposition 6.1 -/
theorem Ideal.mul_add_mem_pow_succ_unique [IsDedekindDomain S] {i : ℕ} (a d d' e e' : S)
(a_not_mem : a ∉ P ^ (i + 1)) (e_mem : e ∈ P ^ (i + 1)) (e'_mem : e' ∈ P ^ (i + 1))
(h : a * d + e - (a * d' + e') ∈ P ^ (i + 1)) : d - d' ∈ P := by
have h' : a * (d - d') ∈ P ^ (i + 1) := by
convert Ideal.add_mem _ h (Ideal.sub_mem _ e'_mem e_mem) using 1
ring
exact Ideal.mem_prime_of_mul_mem_pow hP a_not_mem h'
#align ideal.mul_add_mem_pow_succ_unique Ideal.mul_add_mem_pow_succ_unique
/-- Multiplicity of the ideal norm, for powers of prime ideals. -/
theorem cardQuot_pow_of_prime [IsDedekindDomain S] [Module.Finite ℤ S] [Module.Free ℤ S] {i : ℕ} :
cardQuot (P ^ i) = cardQuot P ^ i := by
let _ := Module.Free.chooseBasis ℤ S
classical
induction' i with i ih
· simp
letI := Ideal.fintypeQuotientOfFreeOfNeBot (P ^ i.succ) (pow_ne_zero _ hP)
letI := Ideal.fintypeQuotientOfFreeOfNeBot (P ^ i) (pow_ne_zero _ hP)
letI := Ideal.fintypeQuotientOfFreeOfNeBot P hP
have : P ^ (i + 1) < P ^ i := Ideal.pow_succ_lt_pow hP i
suffices hquot : map (P ^ i.succ).mkQ (P ^ i) ≃ S ⧸ P by
rw [pow_succ' (cardQuot P), ← ih, cardQuot_apply (P ^ i.succ), ←
card_quotient_mul_card_quotient (P ^ i) (P ^ i.succ) this.le, cardQuot_apply (P ^ i),
cardQuot_apply P]
congr 1
rw [Fintype.card_eq]
exact ⟨hquot⟩
choose a a_mem a_not_mem using SetLike.exists_of_lt this
choose f g hg hf using fun c (hc : c ∈ P ^ i) =>
Ideal.exists_mul_add_mem_pow_succ hP a c a_mem a_not_mem hc
choose k hk_mem hk_eq using fun c' (hc' : c' ∈ map (mkQ (P ^ i.succ)) (P ^ i)) =>
Submodule.mem_map.mp hc'
refine Equiv.ofBijective (fun c' => Quotient.mk'' (f (k c' c'.prop) (hk_mem c' c'.prop))) ⟨?_, ?_⟩
· rintro ⟨c₁', hc₁'⟩ ⟨c₂', hc₂'⟩ h
rw [Subtype.mk_eq_mk, ← hk_eq _ hc₁', ← hk_eq _ hc₂', mkQ_apply, mkQ_apply,
Submodule.Quotient.eq, ← hf _ (hk_mem _ hc₁'), ← hf _ (hk_mem _ hc₂')]
refine Ideal.mul_add_mem_pow_succ_inj _ _ _ _ _ _ a_mem (hg _ _) (hg _ _) ?_
simpa only [Submodule.Quotient.mk''_eq_mk, Submodule.Quotient.mk''_eq_mk,
Submodule.Quotient.eq] using h
· intro d'
refine Quotient.inductionOn' d' fun d => ?_
have hd' := (mem_map (f := mkQ (P ^ i.succ))).mpr ⟨a * d, Ideal.mul_mem_right d _ a_mem, rfl⟩
refine ⟨⟨_, hd'⟩, ?_⟩
simp only [Submodule.Quotient.mk''_eq_mk, Ideal.Quotient.mk_eq_mk, Ideal.Quotient.eq,
Subtype.coe_mk]
refine
Ideal.mul_add_mem_pow_succ_unique hP a _ _ _ _ a_not_mem (hg _ (hk_mem _ hd')) (zero_mem _) ?_
rw [hf, add_zero]
exact (Submodule.Quotient.eq _).mp (hk_eq _ hd')
#align card_quot_pow_of_prime cardQuot_pow_of_prime
end PPrime
/-- Multiplicativity of the ideal norm in number rings. -/
theorem cardQuot_mul [IsDedekindDomain S] [Module.Free ℤ S] [Module.Finite ℤ S] (I J : Ideal S) :
cardQuot (I * J) = cardQuot I * cardQuot J := by
let b := Module.Free.chooseBasis ℤ S
cases isEmpty_or_nonempty (Module.Free.ChooseBasisIndex ℤ S)
· haveI : Subsingleton S := Function.Surjective.subsingleton b.repr.toEquiv.symm.surjective
nontriviality S
exfalso
exact not_nontrivial_iff_subsingleton.mpr ‹Subsingleton S› ‹Nontrivial S›
haveI : Infinite S := Infinite.of_surjective _ b.repr.toEquiv.surjective
exact UniqueFactorizationMonoid.multiplicative_of_coprime cardQuot I J (cardQuot_bot _ _)
(fun {I J} hI => by simp [Ideal.isUnit_iff.mp hI, Ideal.mul_top])
(fun {I} i hI =>
have : Ideal.IsPrime I := Ideal.isPrime_of_prime hI
cardQuot_pow_of_prime hI.ne_zero)
fun {I J} hIJ => cardQuot_mul_of_coprime <| Ideal.isCoprime_iff_sup_eq.mpr
(Ideal.isUnit_iff.mp
(hIJ (Ideal.dvd_iff_le.mpr le_sup_left) (Ideal.dvd_iff_le.mpr le_sup_right)))
#align card_quot_mul cardQuot_mul
/-- The absolute norm of the ideal `I : Ideal R` is the cardinality of the quotient `R ⧸ I`. -/
noncomputable def Ideal.absNorm [Nontrivial S] [IsDedekindDomain S] [Module.Free ℤ S]
[Module.Finite ℤ S] : Ideal S →*₀ ℕ where
toFun := Submodule.cardQuot
map_mul' I J := by dsimp only; rw [cardQuot_mul]
map_one' := by dsimp only; rw [Ideal.one_eq_top, cardQuot_top]
map_zero' := by
have : Infinite S := Module.Free.infinite ℤ S
rw [Ideal.zero_eq_bot, cardQuot_bot]
#align ideal.abs_norm Ideal.absNorm
namespace Ideal
variable [Nontrivial S] [IsDedekindDomain S] [Module.Free ℤ S] [Module.Finite ℤ S]
theorem absNorm_apply (I : Ideal S) : absNorm I = cardQuot I := rfl
#align ideal.abs_norm_apply Ideal.absNorm_apply
@[simp]
theorem absNorm_bot : absNorm (⊥ : Ideal S) = 0 := by rw [← Ideal.zero_eq_bot, _root_.map_zero]
#align ideal.abs_norm_bot Ideal.absNorm_bot
@[simp]
theorem absNorm_top : absNorm (⊤ : Ideal S) = 1 := by rw [← Ideal.one_eq_top, _root_.map_one]
#align ideal.abs_norm_top Ideal.absNorm_top
@[simp]
theorem absNorm_eq_one_iff {I : Ideal S} : absNorm I = 1 ↔ I = ⊤ := by
rw [absNorm_apply, cardQuot_eq_one_iff]
#align ideal.abs_norm_eq_one_iff Ideal.absNorm_eq_one_iff
theorem absNorm_ne_zero_iff (I : Ideal S) : Ideal.absNorm I ≠ 0 ↔ Finite (S ⧸ I) :=
⟨fun h => Nat.finite_of_card_ne_zero h, fun h =>
(@AddSubgroup.finiteIndex_of_finite_quotient _ _ _ h).finiteIndex⟩
#align ideal.abs_norm_ne_zero_iff Ideal.absNorm_ne_zero_iff
/-- Let `e : S ≃ I` be an additive isomorphism (therefore a `ℤ`-linear equiv).
Then an alternative way to compute the norm of `I` is given by taking the determinant of `e`.
See `natAbs_det_basis_change` for a more familiar formulation of this result. -/
theorem natAbs_det_equiv (I : Ideal S) {E : Type*} [EquivLike E S I] [AddEquivClass E S I] (e : E) :
Int.natAbs
(LinearMap.det
((Submodule.subtype I).restrictScalars ℤ ∘ₗ AddMonoidHom.toIntLinearMap (e : S →+ I))) =
Ideal.absNorm I := by
-- `S ⧸ I` might be infinite if `I = ⊥`, but then `e` can't be an equiv.
by_cases hI : I = ⊥
· subst hI
have : (1 : S) ≠ 0 := one_ne_zero
have : (1 : S) = 0 := EquivLike.injective e (Subsingleton.elim _ _)
contradiction
let ι := Module.Free.ChooseBasisIndex ℤ S
let b := Module.Free.chooseBasis ℤ S
cases isEmpty_or_nonempty ι
· nontriviality S
exact (not_nontrivial_iff_subsingleton.mpr
(Function.Surjective.subsingleton b.repr.toEquiv.symm.surjective) (by infer_instance)).elim
-- Thus `(S ⧸ I)` is isomorphic to a product of `ZMod`s, so it is a fintype.
letI := Ideal.fintypeQuotientOfFreeOfNeBot I hI
-- Use the Smith normal form to choose a nice basis for `I`.
letI := Classical.decEq ι
let a := I.smithCoeffs b hI
let b' := I.ringBasis b hI
let ab := I.selfBasis b hI
have ab_eq := I.selfBasis_def b hI
let e' : S ≃ₗ[ℤ] I := b'.equiv ab (Equiv.refl _)
let f : S →ₗ[ℤ] S := (I.subtype.restrictScalars ℤ).comp (e' : S →ₗ[ℤ] I)
let f_apply : ∀ x, f x = b'.equiv ab (Equiv.refl _) x := fun x => rfl
suffices (LinearMap.det f).natAbs = Ideal.absNorm I by
calc
_ = (LinearMap.det ((Submodule.subtype I).restrictScalars ℤ ∘ₗ
(AddEquiv.toIntLinearEquiv e : S ≃ₗ[ℤ] I))).natAbs := rfl
_ = (LinearMap.det ((Submodule.subtype I).restrictScalars ℤ ∘ₗ _)).natAbs :=
Int.natAbs_eq_iff_associated.mpr (LinearMap.associated_det_comp_equiv _ _ _)
_ = absNorm I := this
have ha : ∀ i, f (b' i) = a i • b' i := by
intro i; rw [f_apply, b'.equiv_apply, Equiv.refl_apply, ab_eq]
-- `det f` is equal to `∏ i, a i`,
letI := Classical.decEq ι
calc
Int.natAbs (LinearMap.det f) = Int.natAbs (LinearMap.toMatrix b' b' f).det := by
rw [LinearMap.det_toMatrix]
_ = Int.natAbs (Matrix.diagonal a).det := ?_
_ = Int.natAbs (∏ i, a i) := by rw [Matrix.det_diagonal]
_ = ∏ i, Int.natAbs (a i) := map_prod Int.natAbsHom a Finset.univ
_ = Fintype.card (S ⧸ I) := ?_
_ = absNorm I := (Submodule.cardQuot_apply _).symm
-- since `LinearMap.toMatrix b' b' f` is the diagonal matrix with `a` along the diagonal.
· congr 2; ext i j
rw [LinearMap.toMatrix_apply, ha, LinearEquiv.map_smul, Basis.repr_self, Finsupp.smul_single,
smul_eq_mul, mul_one]
by_cases h : i = j
· rw [h, Matrix.diagonal_apply_eq, Finsupp.single_eq_same]
· rw [Matrix.diagonal_apply_ne _ h, Finsupp.single_eq_of_ne (Ne.symm h)]
-- Now we map everything through the linear equiv `S ≃ₗ (ι → ℤ)`,
-- which maps `(S ⧸ I)` to `Π i, ZMod (a i).nat_abs`.
haveI : ∀ i, NeZero (a i).natAbs := fun i =>
⟨Int.natAbs_ne_zero.mpr (Ideal.smithCoeffs_ne_zero b I hI i)⟩
simp_rw [Fintype.card_eq.mpr ⟨(Ideal.quotientEquivPiZMod I b hI).toEquiv⟩, Fintype.card_pi,
ZMod.card]
#align ideal.nat_abs_det_equiv Ideal.natAbs_det_equiv
/-- Let `b` be a basis for `S` over `ℤ` and `bI` a basis for `I` over `ℤ` of the same dimension.
Then an alternative way to compute the norm of `I` is given by taking the determinant of `bI`
over `b`. -/
theorem natAbs_det_basis_change {ι : Type*} [Fintype ι] [DecidableEq ι] (b : Basis ι ℤ S)
(I : Ideal S) (bI : Basis ι ℤ I) : (b.det ((↑) ∘ bI)).natAbs = Ideal.absNorm I := by
let e := b.equiv bI (Equiv.refl _)
calc
(b.det ((Submodule.subtype I).restrictScalars ℤ ∘ bI)).natAbs =
(LinearMap.det ((Submodule.subtype I).restrictScalars ℤ ∘ₗ (e : S →ₗ[ℤ] I))).natAbs := by
rw [Basis.det_comp_basis]
_ = _ := natAbs_det_equiv I e
#align ideal.nat_abs_det_basis_change Ideal.natAbs_det_basis_change
@[simp]
| Mathlib/RingTheory/Ideal/Norm.lean | 365 | 376 | theorem absNorm_span_singleton (r : S) :
absNorm (span ({r} : Set S)) = (Algebra.norm ℤ r).natAbs := by |
rw [Algebra.norm_apply]
by_cases hr : r = 0
· simp only [hr, Ideal.span_zero, Algebra.coe_lmul_eq_mul, eq_self_iff_true, Ideal.absNorm_bot,
LinearMap.det_zero'', Set.singleton_zero, _root_.map_zero, Int.natAbs_zero]
letI := Ideal.fintypeQuotientOfFreeOfNeBot (span {r}) (mt span_singleton_eq_bot.mp hr)
let b := Module.Free.chooseBasis ℤ S
rw [← natAbs_det_equiv _ (b.equiv (basisSpanSingleton b hr) (Equiv.refl _))]
congr
refine b.ext fun i => ?_
simp
|
/-
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.Asymptotics.AsymptoticEquivalent
import Mathlib.Analysis.Calculus.FDeriv.Linear
import Mathlib.Analysis.Calculus.FDeriv.Comp
#align_import analysis.calculus.fderiv.equiv from "leanprover-community/mathlib"@"e3fb84046afd187b710170887195d50bada934ee"
/-!
# The derivative of a linear equivalence
For detailed documentation of the Fréchet derivative,
see the module docstring of `Analysis/Calculus/FDeriv/Basic.lean`.
This file contains the usual formulas (and existence assertions) for the derivative of
continuous linear equivalences.
We also prove the usual formula for the derivative of the inverse function, assuming it exists.
The inverse function theorem is in `Mathlib/Analysis/Calculus/InverseFunctionTheorem/FDeriv.lean`.
-/
open Filter Asymptotics ContinuousLinearMap Set Metric
open scoped Classical
open Topology NNReal Filter Asymptotics ENNReal
noncomputable section
section
variable {𝕜 : Type*} [NontriviallyNormedField 𝕜]
variable {E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E]
variable {F : Type*} [NormedAddCommGroup F] [NormedSpace 𝕜 F]
variable {G : Type*} [NormedAddCommGroup G] [NormedSpace 𝕜 G]
variable {G' : Type*} [NormedAddCommGroup G'] [NormedSpace 𝕜 G']
variable {f f₀ f₁ g : E → F}
variable {f' f₀' f₁' g' : E →L[𝕜] F}
variable (e : E →L[𝕜] F)
variable {x : E}
variable {s t : Set E}
variable {L L₁ L₂ : Filter E}
namespace ContinuousLinearEquiv
/-! ### Differentiability of linear equivs, and invariance of differentiability -/
variable (iso : E ≃L[𝕜] F)
@[fun_prop]
protected theorem hasStrictFDerivAt : HasStrictFDerivAt iso (iso : E →L[𝕜] F) x :=
iso.toContinuousLinearMap.hasStrictFDerivAt
#align continuous_linear_equiv.has_strict_fderiv_at ContinuousLinearEquiv.hasStrictFDerivAt
@[fun_prop]
protected theorem hasFDerivWithinAt : HasFDerivWithinAt iso (iso : E →L[𝕜] F) s x :=
iso.toContinuousLinearMap.hasFDerivWithinAt
#align continuous_linear_equiv.has_fderiv_within_at ContinuousLinearEquiv.hasFDerivWithinAt
@[fun_prop]
protected theorem hasFDerivAt : HasFDerivAt iso (iso : E →L[𝕜] F) x :=
iso.toContinuousLinearMap.hasFDerivAtFilter
#align continuous_linear_equiv.has_fderiv_at ContinuousLinearEquiv.hasFDerivAt
@[fun_prop]
protected theorem differentiableAt : DifferentiableAt 𝕜 iso x :=
iso.hasFDerivAt.differentiableAt
#align continuous_linear_equiv.differentiable_at ContinuousLinearEquiv.differentiableAt
@[fun_prop]
protected theorem differentiableWithinAt : DifferentiableWithinAt 𝕜 iso s x :=
iso.differentiableAt.differentiableWithinAt
#align continuous_linear_equiv.differentiable_within_at ContinuousLinearEquiv.differentiableWithinAt
protected theorem fderiv : fderiv 𝕜 iso x = iso :=
iso.hasFDerivAt.fderiv
#align continuous_linear_equiv.fderiv ContinuousLinearEquiv.fderiv
protected theorem fderivWithin (hxs : UniqueDiffWithinAt 𝕜 s x) : fderivWithin 𝕜 iso s x = iso :=
iso.toContinuousLinearMap.fderivWithin hxs
#align continuous_linear_equiv.fderiv_within ContinuousLinearEquiv.fderivWithin
@[fun_prop]
protected theorem differentiable : Differentiable 𝕜 iso := fun _ => iso.differentiableAt
#align continuous_linear_equiv.differentiable ContinuousLinearEquiv.differentiable
@[fun_prop]
protected theorem differentiableOn : DifferentiableOn 𝕜 iso s :=
iso.differentiable.differentiableOn
#align continuous_linear_equiv.differentiable_on ContinuousLinearEquiv.differentiableOn
theorem comp_differentiableWithinAt_iff {f : G → E} {s : Set G} {x : G} :
DifferentiableWithinAt 𝕜 (iso ∘ f) s x ↔ DifferentiableWithinAt 𝕜 f s x := by
refine
⟨fun H => ?_, fun H => iso.differentiable.differentiableAt.comp_differentiableWithinAt x H⟩
have : DifferentiableWithinAt 𝕜 (iso.symm ∘ iso ∘ f) s x :=
iso.symm.differentiable.differentiableAt.comp_differentiableWithinAt x H
rwa [← Function.comp.assoc iso.symm iso f, iso.symm_comp_self] at this
#align continuous_linear_equiv.comp_differentiable_within_at_iff ContinuousLinearEquiv.comp_differentiableWithinAt_iff
theorem comp_differentiableAt_iff {f : G → E} {x : G} :
DifferentiableAt 𝕜 (iso ∘ f) x ↔ DifferentiableAt 𝕜 f x := by
rw [← differentiableWithinAt_univ, ← differentiableWithinAt_univ,
iso.comp_differentiableWithinAt_iff]
#align continuous_linear_equiv.comp_differentiable_at_iff ContinuousLinearEquiv.comp_differentiableAt_iff
theorem comp_differentiableOn_iff {f : G → E} {s : Set G} :
DifferentiableOn 𝕜 (iso ∘ f) s ↔ DifferentiableOn 𝕜 f s := by
rw [DifferentiableOn, DifferentiableOn]
simp only [iso.comp_differentiableWithinAt_iff]
#align continuous_linear_equiv.comp_differentiable_on_iff ContinuousLinearEquiv.comp_differentiableOn_iff
theorem comp_differentiable_iff {f : G → E} : Differentiable 𝕜 (iso ∘ f) ↔ Differentiable 𝕜 f := by
rw [← differentiableOn_univ, ← differentiableOn_univ]
exact iso.comp_differentiableOn_iff
#align continuous_linear_equiv.comp_differentiable_iff ContinuousLinearEquiv.comp_differentiable_iff
theorem comp_hasFDerivWithinAt_iff {f : G → E} {s : Set G} {x : G} {f' : G →L[𝕜] E} :
HasFDerivWithinAt (iso ∘ f) ((iso : E →L[𝕜] F).comp f') s x ↔ HasFDerivWithinAt f f' s x := by
refine ⟨fun H => ?_, fun H => iso.hasFDerivAt.comp_hasFDerivWithinAt x H⟩
have A : f = iso.symm ∘ iso ∘ f := by
rw [← Function.comp.assoc, iso.symm_comp_self]
rfl
have B : f' = (iso.symm : F →L[𝕜] E).comp ((iso : E →L[𝕜] F).comp f') := by
rw [← ContinuousLinearMap.comp_assoc, iso.coe_symm_comp_coe, ContinuousLinearMap.id_comp]
rw [A, B]
exact iso.symm.hasFDerivAt.comp_hasFDerivWithinAt x H
#align continuous_linear_equiv.comp_has_fderiv_within_at_iff ContinuousLinearEquiv.comp_hasFDerivWithinAt_iff
theorem comp_hasStrictFDerivAt_iff {f : G → E} {x : G} {f' : G →L[𝕜] E} :
HasStrictFDerivAt (iso ∘ f) ((iso : E →L[𝕜] F).comp f') x ↔ HasStrictFDerivAt f f' x := by
refine ⟨fun H => ?_, fun H => iso.hasStrictFDerivAt.comp x H⟩
convert iso.symm.hasStrictFDerivAt.comp x H using 1 <;>
ext z <;> apply (iso.symm_apply_apply _).symm
#align continuous_linear_equiv.comp_has_strict_fderiv_at_iff ContinuousLinearEquiv.comp_hasStrictFDerivAt_iff
theorem comp_hasFDerivAt_iff {f : G → E} {x : G} {f' : G →L[𝕜] E} :
HasFDerivAt (iso ∘ f) ((iso : E →L[𝕜] F).comp f') x ↔ HasFDerivAt f f' x := by
simp_rw [← hasFDerivWithinAt_univ, iso.comp_hasFDerivWithinAt_iff]
#align continuous_linear_equiv.comp_has_fderiv_at_iff ContinuousLinearEquiv.comp_hasFDerivAt_iff
theorem comp_hasFDerivWithinAt_iff' {f : G → E} {s : Set G} {x : G} {f' : G →L[𝕜] F} :
HasFDerivWithinAt (iso ∘ f) f' s x ↔
HasFDerivWithinAt f ((iso.symm : F →L[𝕜] E).comp f') s x := by
rw [← iso.comp_hasFDerivWithinAt_iff, ← ContinuousLinearMap.comp_assoc, iso.coe_comp_coe_symm,
ContinuousLinearMap.id_comp]
#align continuous_linear_equiv.comp_has_fderiv_within_at_iff' ContinuousLinearEquiv.comp_hasFDerivWithinAt_iff'
theorem comp_hasFDerivAt_iff' {f : G → E} {x : G} {f' : G →L[𝕜] F} :
HasFDerivAt (iso ∘ f) f' x ↔ HasFDerivAt f ((iso.symm : F →L[𝕜] E).comp f') x := by
simp_rw [← hasFDerivWithinAt_univ, iso.comp_hasFDerivWithinAt_iff']
#align continuous_linear_equiv.comp_has_fderiv_at_iff' ContinuousLinearEquiv.comp_hasFDerivAt_iff'
theorem comp_fderivWithin {f : G → E} {s : Set G} {x : G} (hxs : UniqueDiffWithinAt 𝕜 s x) :
fderivWithin 𝕜 (iso ∘ f) s x = (iso : E →L[𝕜] F).comp (fderivWithin 𝕜 f s x) := by
by_cases h : DifferentiableWithinAt 𝕜 f s x
· rw [fderiv.comp_fderivWithin x iso.differentiableAt h hxs, iso.fderiv]
· have : ¬DifferentiableWithinAt 𝕜 (iso ∘ f) s x := mt iso.comp_differentiableWithinAt_iff.1 h
rw [fderivWithin_zero_of_not_differentiableWithinAt h,
fderivWithin_zero_of_not_differentiableWithinAt this, ContinuousLinearMap.comp_zero]
#align continuous_linear_equiv.comp_fderiv_within ContinuousLinearEquiv.comp_fderivWithin
theorem comp_fderiv {f : G → E} {x : G} :
fderiv 𝕜 (iso ∘ f) x = (iso : E →L[𝕜] F).comp (fderiv 𝕜 f x) := by
rw [← fderivWithin_univ, ← fderivWithin_univ]
exact iso.comp_fderivWithin uniqueDiffWithinAt_univ
#align continuous_linear_equiv.comp_fderiv ContinuousLinearEquiv.comp_fderiv
lemma _root_.fderivWithin_continuousLinearEquiv_comp (L : G ≃L[𝕜] G') (f : E → (F →L[𝕜] G))
(hs : UniqueDiffWithinAt 𝕜 s x) :
fderivWithin 𝕜 (fun x ↦ (L : G →L[𝕜] G').comp (f x)) s x =
(((ContinuousLinearEquiv.refl 𝕜 F).arrowCongr L)) ∘L (fderivWithin 𝕜 f s x) := by
change fderivWithin 𝕜 (((ContinuousLinearEquiv.refl 𝕜 F).arrowCongr L) ∘ f) s x = _
rw [ContinuousLinearEquiv.comp_fderivWithin _ hs]
lemma _root_.fderiv_continuousLinearEquiv_comp (L : G ≃L[𝕜] G') (f : E → (F →L[𝕜] G)) (x : E) :
fderiv 𝕜 (fun x ↦ (L : G →L[𝕜] G').comp (f x)) x =
(((ContinuousLinearEquiv.refl 𝕜 F).arrowCongr L)) ∘L (fderiv 𝕜 f x) := by
change fderiv 𝕜 (((ContinuousLinearEquiv.refl 𝕜 F).arrowCongr L) ∘ f) x = _
rw [ContinuousLinearEquiv.comp_fderiv]
lemma _root_.fderiv_continuousLinearEquiv_comp' (L : G ≃L[𝕜] G') (f : E → (F →L[𝕜] G)) :
fderiv 𝕜 (fun x ↦ (L : G →L[𝕜] G').comp (f x)) =
fun x ↦ (((ContinuousLinearEquiv.refl 𝕜 F).arrowCongr L)) ∘L (fderiv 𝕜 f x) := by
ext x : 1
exact fderiv_continuousLinearEquiv_comp L f x
theorem comp_right_differentiableWithinAt_iff {f : F → G} {s : Set F} {x : E} :
DifferentiableWithinAt 𝕜 (f ∘ iso) (iso ⁻¹' s) x ↔ DifferentiableWithinAt 𝕜 f s (iso x) := by
refine ⟨fun H => ?_, fun H => H.comp x iso.differentiableWithinAt (mapsTo_preimage _ s)⟩
have : DifferentiableWithinAt 𝕜 ((f ∘ iso) ∘ iso.symm) s (iso x) := by
rw [← iso.symm_apply_apply x] at H
apply H.comp (iso x) iso.symm.differentiableWithinAt
intro y hy
simpa only [mem_preimage, apply_symm_apply] using hy
rwa [Function.comp.assoc, iso.self_comp_symm] at this
#align continuous_linear_equiv.comp_right_differentiable_within_at_iff ContinuousLinearEquiv.comp_right_differentiableWithinAt_iff
theorem comp_right_differentiableAt_iff {f : F → G} {x : E} :
DifferentiableAt 𝕜 (f ∘ iso) x ↔ DifferentiableAt 𝕜 f (iso x) := by
simp only [← differentiableWithinAt_univ, ← iso.comp_right_differentiableWithinAt_iff,
preimage_univ]
#align continuous_linear_equiv.comp_right_differentiable_at_iff ContinuousLinearEquiv.comp_right_differentiableAt_iff
theorem comp_right_differentiableOn_iff {f : F → G} {s : Set F} :
DifferentiableOn 𝕜 (f ∘ iso) (iso ⁻¹' s) ↔ DifferentiableOn 𝕜 f s := by
refine ⟨fun H y hy => ?_, fun H y hy => iso.comp_right_differentiableWithinAt_iff.2 (H _ hy)⟩
rw [← iso.apply_symm_apply y, ← comp_right_differentiableWithinAt_iff]
apply H
simpa only [mem_preimage, apply_symm_apply] using hy
#align continuous_linear_equiv.comp_right_differentiable_on_iff ContinuousLinearEquiv.comp_right_differentiableOn_iff
theorem comp_right_differentiable_iff {f : F → G} :
Differentiable 𝕜 (f ∘ iso) ↔ Differentiable 𝕜 f := by
simp only [← differentiableOn_univ, ← iso.comp_right_differentiableOn_iff, preimage_univ]
#align continuous_linear_equiv.comp_right_differentiable_iff ContinuousLinearEquiv.comp_right_differentiable_iff
theorem comp_right_hasFDerivWithinAt_iff {f : F → G} {s : Set F} {x : E} {f' : F →L[𝕜] G} :
HasFDerivWithinAt (f ∘ iso) (f'.comp (iso : E →L[𝕜] F)) (iso ⁻¹' s) x ↔
HasFDerivWithinAt f f' s (iso x) := by
refine ⟨fun H => ?_, fun H => H.comp x iso.hasFDerivWithinAt (mapsTo_preimage _ s)⟩
rw [← iso.symm_apply_apply x] at H
have A : f = (f ∘ iso) ∘ iso.symm := by
rw [Function.comp.assoc, iso.self_comp_symm]
rfl
have B : f' = (f'.comp (iso : E →L[𝕜] F)).comp (iso.symm : F →L[𝕜] E) := by
rw [ContinuousLinearMap.comp_assoc, iso.coe_comp_coe_symm, ContinuousLinearMap.comp_id]
rw [A, B]
apply H.comp (iso x) iso.symm.hasFDerivWithinAt
intro y hy
simpa only [mem_preimage, apply_symm_apply] using hy
#align continuous_linear_equiv.comp_right_has_fderiv_within_at_iff ContinuousLinearEquiv.comp_right_hasFDerivWithinAt_iff
theorem comp_right_hasFDerivAt_iff {f : F → G} {x : E} {f' : F →L[𝕜] G} :
HasFDerivAt (f ∘ iso) (f'.comp (iso : E →L[𝕜] F)) x ↔ HasFDerivAt f f' (iso x) := by
simp only [← hasFDerivWithinAt_univ, ← comp_right_hasFDerivWithinAt_iff, preimage_univ]
#align continuous_linear_equiv.comp_right_has_fderiv_at_iff ContinuousLinearEquiv.comp_right_hasFDerivAt_iff
theorem comp_right_hasFDerivWithinAt_iff' {f : F → G} {s : Set F} {x : E} {f' : E →L[𝕜] G} :
HasFDerivWithinAt (f ∘ iso) f' (iso ⁻¹' s) x ↔
HasFDerivWithinAt f (f'.comp (iso.symm : F →L[𝕜] E)) s (iso x) := by
rw [← iso.comp_right_hasFDerivWithinAt_iff, ContinuousLinearMap.comp_assoc,
iso.coe_symm_comp_coe, ContinuousLinearMap.comp_id]
#align continuous_linear_equiv.comp_right_has_fderiv_within_at_iff' ContinuousLinearEquiv.comp_right_hasFDerivWithinAt_iff'
theorem comp_right_hasFDerivAt_iff' {f : F → G} {x : E} {f' : E →L[𝕜] G} :
HasFDerivAt (f ∘ iso) f' x ↔ HasFDerivAt f (f'.comp (iso.symm : F →L[𝕜] E)) (iso x) := by
simp only [← hasFDerivWithinAt_univ, ← iso.comp_right_hasFDerivWithinAt_iff', preimage_univ]
#align continuous_linear_equiv.comp_right_has_fderiv_at_iff' ContinuousLinearEquiv.comp_right_hasFDerivAt_iff'
theorem comp_right_fderivWithin {f : F → G} {s : Set F} {x : E}
(hxs : UniqueDiffWithinAt 𝕜 (iso ⁻¹' s) x) :
fderivWithin 𝕜 (f ∘ iso) (iso ⁻¹' s) x =
(fderivWithin 𝕜 f s (iso x)).comp (iso : E →L[𝕜] F) := by
by_cases h : DifferentiableWithinAt 𝕜 f s (iso x)
· exact (iso.comp_right_hasFDerivWithinAt_iff.2 h.hasFDerivWithinAt).fderivWithin hxs
· have : ¬DifferentiableWithinAt 𝕜 (f ∘ iso) (iso ⁻¹' s) x := by
intro h'
exact h (iso.comp_right_differentiableWithinAt_iff.1 h')
rw [fderivWithin_zero_of_not_differentiableWithinAt h,
fderivWithin_zero_of_not_differentiableWithinAt this, ContinuousLinearMap.zero_comp]
#align continuous_linear_equiv.comp_right_fderiv_within ContinuousLinearEquiv.comp_right_fderivWithin
| Mathlib/Analysis/Calculus/FDeriv/Equiv.lean | 267 | 270 | theorem comp_right_fderiv {f : F → G} {x : E} :
fderiv 𝕜 (f ∘ iso) x = (fderiv 𝕜 f (iso x)).comp (iso : E →L[𝕜] F) := by |
rw [← fderivWithin_univ, ← fderivWithin_univ, ← iso.comp_right_fderivWithin, preimage_univ]
exact uniqueDiffWithinAt_univ
|
/-
Copyright (c) 2021 Yaël Dillies, Bhavik Mehta. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies, Bhavik Mehta
-/
import Mathlib.Analysis.Convex.Topology
import Mathlib.Analysis.NormedSpace.Pointwise
import Mathlib.Analysis.Seminorm
import Mathlib.Analysis.LocallyConvex.Bounded
import Mathlib.Analysis.RCLike.Basic
#align_import analysis.convex.gauge from "leanprover-community/mathlib"@"373b03b5b9d0486534edbe94747f23cb3712f93d"
/-!
# The Minkowski functional
This file defines the Minkowski functional, aka gauge.
The Minkowski functional of a set `s` is the function which associates each point to how much you
need to scale `s` for `x` to be inside it. When `s` is symmetric, convex and absorbent, its gauge is
a seminorm. Reciprocally, any seminorm arises as the gauge of some set, namely its unit ball. This
induces the equivalence of seminorms and locally convex topological vector spaces.
## Main declarations
For a real vector space,
* `gauge`: Aka Minkowski functional. `gauge s x` is the least (actually, an infimum) `r` such
that `x ∈ r • s`.
* `gaugeSeminorm`: The Minkowski functional as a seminorm, when `s` is symmetric, convex and
absorbent.
## References
* [H. H. Schaefer, *Topological Vector Spaces*][schaefer1966]
## Tags
Minkowski functional, gauge
-/
open NormedField Set
open scoped Pointwise Topology NNReal
noncomputable section
variable {𝕜 E F : Type*}
section AddCommGroup
variable [AddCommGroup E] [Module ℝ E]
/-- The Minkowski functional. Given a set `s` in a real vector space, `gauge s` is the functional
which sends `x : E` to the smallest `r : ℝ` such that `x` is in `s` scaled by `r`. -/
def gauge (s : Set E) (x : E) : ℝ :=
sInf { r : ℝ | 0 < r ∧ x ∈ r • s }
#align gauge gauge
variable {s t : Set E} {x : E} {a : ℝ}
theorem gauge_def : gauge s x = sInf ({ r ∈ Set.Ioi (0 : ℝ) | x ∈ r • s }) :=
rfl
#align gauge_def gauge_def
/-- An alternative definition of the gauge using scalar multiplication on the element rather than on
the set. -/
theorem gauge_def' : gauge s x = sInf {r ∈ Set.Ioi (0 : ℝ) | r⁻¹ • x ∈ s} := by
congrm sInf {r | ?_}
exact and_congr_right fun hr => mem_smul_set_iff_inv_smul_mem₀ hr.ne' _ _
#align gauge_def' gauge_def'
private theorem gauge_set_bddBelow : BddBelow { r : ℝ | 0 < r ∧ x ∈ r • s } :=
⟨0, fun _ hr => hr.1.le⟩
/-- If the given subset is `Absorbent` then the set we take an infimum over in `gauge` is nonempty,
which is useful for proving many properties about the gauge. -/
theorem Absorbent.gauge_set_nonempty (absorbs : Absorbent ℝ s) :
{ r : ℝ | 0 < r ∧ x ∈ r • s }.Nonempty :=
let ⟨r, hr₁, hr₂⟩ := (absorbs x).exists_pos
⟨r, hr₁, hr₂ r (Real.norm_of_nonneg hr₁.le).ge rfl⟩
#align absorbent.gauge_set_nonempty Absorbent.gauge_set_nonempty
theorem gauge_mono (hs : Absorbent ℝ s) (h : s ⊆ t) : gauge t ≤ gauge s := fun _ =>
csInf_le_csInf gauge_set_bddBelow hs.gauge_set_nonempty fun _ hr => ⟨hr.1, smul_set_mono h hr.2⟩
#align gauge_mono gauge_mono
theorem exists_lt_of_gauge_lt (absorbs : Absorbent ℝ s) (h : gauge s x < a) :
∃ b, 0 < b ∧ b < a ∧ x ∈ b • s := by
obtain ⟨b, ⟨hb, hx⟩, hba⟩ := exists_lt_of_csInf_lt absorbs.gauge_set_nonempty h
exact ⟨b, hb, hba, hx⟩
#align exists_lt_of_gauge_lt exists_lt_of_gauge_lt
/-- The gauge evaluated at `0` is always zero (mathematically this requires `0` to be in the set `s`
but, the real infimum of the empty set in Lean being defined as `0`, it holds unconditionally). -/
@[simp]
theorem gauge_zero : gauge s 0 = 0 := by
rw [gauge_def']
by_cases h : (0 : E) ∈ s
· simp only [smul_zero, sep_true, h, csInf_Ioi]
· simp only [smul_zero, sep_false, h, Real.sInf_empty]
#align gauge_zero gauge_zero
@[simp]
theorem gauge_zero' : gauge (0 : Set E) = 0 := by
ext x
rw [gauge_def']
obtain rfl | hx := eq_or_ne x 0
· simp only [csInf_Ioi, mem_zero, Pi.zero_apply, eq_self_iff_true, sep_true, smul_zero]
· simp only [mem_zero, Pi.zero_apply, inv_eq_zero, smul_eq_zero]
convert Real.sInf_empty
exact eq_empty_iff_forall_not_mem.2 fun r hr => hr.2.elim (ne_of_gt hr.1) hx
#align gauge_zero' gauge_zero'
@[simp]
theorem gauge_empty : gauge (∅ : Set E) = 0 := by
ext
simp only [gauge_def', Real.sInf_empty, mem_empty_iff_false, Pi.zero_apply, sep_false]
#align gauge_empty gauge_empty
theorem gauge_of_subset_zero (h : s ⊆ 0) : gauge s = 0 := by
obtain rfl | rfl := subset_singleton_iff_eq.1 h
exacts [gauge_empty, gauge_zero']
#align gauge_of_subset_zero gauge_of_subset_zero
/-- The gauge is always nonnegative. -/
theorem gauge_nonneg (x : E) : 0 ≤ gauge s x :=
Real.sInf_nonneg _ fun _ hx => hx.1.le
#align gauge_nonneg gauge_nonneg
theorem gauge_neg (symmetric : ∀ x ∈ s, -x ∈ s) (x : E) : gauge s (-x) = gauge s x := by
have : ∀ x, -x ∈ s ↔ x ∈ s := fun x => ⟨fun h => by simpa using symmetric _ h, symmetric x⟩
simp_rw [gauge_def', smul_neg, this]
#align gauge_neg gauge_neg
theorem gauge_neg_set_neg (x : E) : gauge (-s) (-x) = gauge s x := by
simp_rw [gauge_def', smul_neg, neg_mem_neg]
#align gauge_neg_set_neg gauge_neg_set_neg
theorem gauge_neg_set_eq_gauge_neg (x : E) : gauge (-s) x = gauge s (-x) := by
rw [← gauge_neg_set_neg, neg_neg]
#align gauge_neg_set_eq_gauge_neg gauge_neg_set_eq_gauge_neg
theorem gauge_le_of_mem (ha : 0 ≤ a) (hx : x ∈ a • s) : gauge s x ≤ a := by
obtain rfl | ha' := ha.eq_or_lt
· rw [mem_singleton_iff.1 (zero_smul_set_subset _ hx), gauge_zero]
· exact csInf_le gauge_set_bddBelow ⟨ha', hx⟩
#align gauge_le_of_mem gauge_le_of_mem
theorem gauge_le_eq (hs₁ : Convex ℝ s) (hs₀ : (0 : E) ∈ s) (hs₂ : Absorbent ℝ s) (ha : 0 ≤ a) :
{ x | gauge s x ≤ a } = ⋂ (r : ℝ) (_ : a < r), r • s := by
ext x
simp_rw [Set.mem_iInter, Set.mem_setOf_eq]
refine ⟨fun h r hr => ?_, fun h => le_of_forall_pos_lt_add fun ε hε => ?_⟩
· have hr' := ha.trans_lt hr
rw [mem_smul_set_iff_inv_smul_mem₀ hr'.ne']
obtain ⟨δ, δ_pos, hδr, hδ⟩ := exists_lt_of_gauge_lt hs₂ (h.trans_lt hr)
suffices (r⁻¹ * δ) • δ⁻¹ • x ∈ s by rwa [smul_smul, mul_inv_cancel_right₀ δ_pos.ne'] at this
rw [mem_smul_set_iff_inv_smul_mem₀ δ_pos.ne'] at hδ
refine hs₁.smul_mem_of_zero_mem hs₀ hδ ⟨by positivity, ?_⟩
rw [inv_mul_le_iff hr', mul_one]
exact hδr.le
· have hε' := (lt_add_iff_pos_right a).2 (half_pos hε)
exact
(gauge_le_of_mem (ha.trans hε'.le) <| h _ hε').trans_lt (add_lt_add_left (half_lt_self hε) _)
#align gauge_le_eq gauge_le_eq
theorem gauge_lt_eq' (absorbs : Absorbent ℝ s) (a : ℝ) :
{ x | gauge s x < a } = ⋃ (r : ℝ) (_ : 0 < r) (_ : r < a), r • s := by
ext
simp_rw [mem_setOf, mem_iUnion, exists_prop]
exact
⟨exists_lt_of_gauge_lt absorbs, fun ⟨r, hr₀, hr₁, hx⟩ =>
(gauge_le_of_mem hr₀.le hx).trans_lt hr₁⟩
#align gauge_lt_eq' gauge_lt_eq'
| Mathlib/Analysis/Convex/Gauge.lean | 175 | 181 | theorem gauge_lt_eq (absorbs : Absorbent ℝ s) (a : ℝ) :
{ x | gauge s x < a } = ⋃ r ∈ Set.Ioo 0 (a : ℝ), r • s := by |
ext
simp_rw [mem_setOf, mem_iUnion, exists_prop, mem_Ioo, and_assoc]
exact
⟨exists_lt_of_gauge_lt absorbs, fun ⟨r, hr₀, hr₁, hx⟩ =>
(gauge_le_of_mem hr₀.le hx).trans_lt hr₁⟩
|
/-
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.CharZero.Lemmas
import Mathlib.Algebra.Order.Interval.Set.Group
import Mathlib.Algebra.Group.Int
import Mathlib.Data.Int.Lemmas
import Mathlib.Data.Set.Subsingleton
import Mathlib.Init.Data.Nat.Lemmas
import Mathlib.Order.GaloisConnection
import Mathlib.Tactic.Abel
import Mathlib.Tactic.Linarith
import Mathlib.Tactic.Positivity
#align_import algebra.order.floor from "leanprover-community/mathlib"@"afdb43429311b885a7988ea15d0bac2aac80f69c"
/-!
# Floor and ceil
## Summary
We define the natural- and integer-valued floor and ceil functions on linearly ordered rings.
## Main Definitions
* `FloorSemiring`: An ordered semiring with natural-valued floor and ceil.
* `Nat.floor a`: Greatest natural `n` such that `n ≤ a`. Equal to `0` if `a < 0`.
* `Nat.ceil a`: Least natural `n` such that `a ≤ n`.
* `FloorRing`: A linearly ordered ring with integer-valued floor and ceil.
* `Int.floor a`: Greatest integer `z` such that `z ≤ a`.
* `Int.ceil a`: Least integer `z` such that `a ≤ z`.
* `Int.fract a`: Fractional part of `a`, defined as `a - floor a`.
* `round a`: Nearest integer to `a`. It rounds halves towards infinity.
## Notations
* `⌊a⌋₊` is `Nat.floor a`.
* `⌈a⌉₊` is `Nat.ceil a`.
* `⌊a⌋` is `Int.floor a`.
* `⌈a⌉` is `Int.ceil a`.
The index `₊` in the notations for `Nat.floor` and `Nat.ceil` is used in analogy to the notation
for `nnnorm`.
## TODO
`LinearOrderedRing`/`LinearOrderedSemiring` can be relaxed to `OrderedRing`/`OrderedSemiring` in
many lemmas.
## Tags
rounding, floor, ceil
-/
open Set
variable {F α β : Type*}
/-! ### Floor semiring -/
/-- A `FloorSemiring` is an ordered semiring over `α` with a function
`floor : α → ℕ` satisfying `∀ (n : ℕ) (x : α), n ≤ ⌊x⌋ ↔ (n : α) ≤ x)`.
Note that many lemmas require a `LinearOrder`. Please see the above `TODO`. -/
class FloorSemiring (α) [OrderedSemiring α] where
/-- `FloorSemiring.floor a` computes the greatest natural `n` such that `(n : α) ≤ a`. -/
floor : α → ℕ
/-- `FloorSemiring.ceil a` computes the least natural `n` such that `a ≤ (n : α)`. -/
ceil : α → ℕ
/-- `FloorSemiring.floor` of a negative element is zero. -/
floor_of_neg {a : α} (ha : a < 0) : floor a = 0
/-- A natural number `n` is smaller than `FloorSemiring.floor a` iff its coercion to `α` is
smaller than `a`. -/
gc_floor {a : α} {n : ℕ} (ha : 0 ≤ a) : n ≤ floor a ↔ (n : α) ≤ a
/-- `FloorSemiring.ceil` is the lower adjoint of the coercion `↑ : ℕ → α`. -/
gc_ceil : GaloisConnection ceil (↑)
#align floor_semiring FloorSemiring
instance : FloorSemiring ℕ where
floor := id
ceil := id
floor_of_neg ha := (Nat.not_lt_zero _ ha).elim
gc_floor _ := by
rw [Nat.cast_id]
rfl
gc_ceil n a := by
rw [Nat.cast_id]
rfl
namespace Nat
section OrderedSemiring
variable [OrderedSemiring α] [FloorSemiring α] {a : α} {n : ℕ}
/-- `⌊a⌋₊` is the greatest natural `n` such that `n ≤ a`. If `a` is negative, then `⌊a⌋₊ = 0`. -/
def floor : α → ℕ :=
FloorSemiring.floor
#align nat.floor Nat.floor
/-- `⌈a⌉₊` is the least natural `n` such that `a ≤ n` -/
def ceil : α → ℕ :=
FloorSemiring.ceil
#align nat.ceil Nat.ceil
@[simp]
theorem floor_nat : (Nat.floor : ℕ → ℕ) = id :=
rfl
#align nat.floor_nat Nat.floor_nat
@[simp]
theorem ceil_nat : (Nat.ceil : ℕ → ℕ) = id :=
rfl
#align nat.ceil_nat Nat.ceil_nat
@[inherit_doc]
notation "⌊" a "⌋₊" => Nat.floor a
@[inherit_doc]
notation "⌈" a "⌉₊" => Nat.ceil a
end OrderedSemiring
section LinearOrderedSemiring
variable [LinearOrderedSemiring α] [FloorSemiring α] {a : α} {n : ℕ}
theorem le_floor_iff (ha : 0 ≤ a) : n ≤ ⌊a⌋₊ ↔ (n : α) ≤ a :=
FloorSemiring.gc_floor ha
#align nat.le_floor_iff Nat.le_floor_iff
theorem le_floor (h : (n : α) ≤ a) : n ≤ ⌊a⌋₊ :=
(le_floor_iff <| n.cast_nonneg.trans h).2 h
#align nat.le_floor Nat.le_floor
theorem floor_lt (ha : 0 ≤ a) : ⌊a⌋₊ < n ↔ a < n :=
lt_iff_lt_of_le_iff_le <| le_floor_iff ha
#align nat.floor_lt Nat.floor_lt
theorem floor_lt_one (ha : 0 ≤ a) : ⌊a⌋₊ < 1 ↔ a < 1 :=
(floor_lt ha).trans <| by rw [Nat.cast_one]
#align nat.floor_lt_one Nat.floor_lt_one
theorem lt_of_floor_lt (h : ⌊a⌋₊ < n) : a < n :=
lt_of_not_le fun h' => (le_floor h').not_lt h
#align nat.lt_of_floor_lt Nat.lt_of_floor_lt
theorem lt_one_of_floor_lt_one (h : ⌊a⌋₊ < 1) : a < 1 := mod_cast lt_of_floor_lt h
#align nat.lt_one_of_floor_lt_one Nat.lt_one_of_floor_lt_one
theorem floor_le (ha : 0 ≤ a) : (⌊a⌋₊ : α) ≤ a :=
(le_floor_iff ha).1 le_rfl
#align nat.floor_le Nat.floor_le
theorem lt_succ_floor (a : α) : a < ⌊a⌋₊.succ :=
lt_of_floor_lt <| Nat.lt_succ_self _
#align nat.lt_succ_floor Nat.lt_succ_floor
theorem lt_floor_add_one (a : α) : a < ⌊a⌋₊ + 1 := by simpa using lt_succ_floor a
#align nat.lt_floor_add_one Nat.lt_floor_add_one
@[simp]
theorem floor_natCast (n : ℕ) : ⌊(n : α)⌋₊ = n :=
eq_of_forall_le_iff fun a => by
rw [le_floor_iff, Nat.cast_le]
exact n.cast_nonneg
#align nat.floor_coe Nat.floor_natCast
@[deprecated (since := "2024-06-08")] alias floor_coe := floor_natCast
@[simp]
theorem floor_zero : ⌊(0 : α)⌋₊ = 0 := by rw [← Nat.cast_zero, floor_natCast]
#align nat.floor_zero Nat.floor_zero
@[simp]
theorem floor_one : ⌊(1 : α)⌋₊ = 1 := by rw [← Nat.cast_one, floor_natCast]
#align nat.floor_one Nat.floor_one
-- See note [no_index around OfNat.ofNat]
@[simp]
theorem floor_ofNat (n : ℕ) [n.AtLeastTwo] : ⌊no_index (OfNat.ofNat n : α)⌋₊ = n :=
Nat.floor_natCast _
theorem floor_of_nonpos (ha : a ≤ 0) : ⌊a⌋₊ = 0 :=
ha.lt_or_eq.elim FloorSemiring.floor_of_neg <| by
rintro rfl
exact floor_zero
#align nat.floor_of_nonpos Nat.floor_of_nonpos
theorem floor_mono : Monotone (floor : α → ℕ) := fun a b h => by
obtain ha | ha := le_total a 0
· rw [floor_of_nonpos ha]
exact Nat.zero_le _
· exact le_floor ((floor_le ha).trans h)
#align nat.floor_mono Nat.floor_mono
@[gcongr]
theorem floor_le_floor : ∀ x y : α, x ≤ y → ⌊x⌋₊ ≤ ⌊y⌋₊ := floor_mono
theorem le_floor_iff' (hn : n ≠ 0) : n ≤ ⌊a⌋₊ ↔ (n : α) ≤ a := by
obtain ha | ha := le_total a 0
· rw [floor_of_nonpos ha]
exact
iff_of_false (Nat.pos_of_ne_zero hn).not_le
(not_le_of_lt <| ha.trans_lt <| cast_pos.2 <| Nat.pos_of_ne_zero hn)
· exact le_floor_iff ha
#align nat.le_floor_iff' Nat.le_floor_iff'
@[simp]
theorem one_le_floor_iff (x : α) : 1 ≤ ⌊x⌋₊ ↔ 1 ≤ x :=
mod_cast @le_floor_iff' α _ _ x 1 one_ne_zero
#align nat.one_le_floor_iff Nat.one_le_floor_iff
theorem floor_lt' (hn : n ≠ 0) : ⌊a⌋₊ < n ↔ a < n :=
lt_iff_lt_of_le_iff_le <| le_floor_iff' hn
#align nat.floor_lt' Nat.floor_lt'
theorem floor_pos : 0 < ⌊a⌋₊ ↔ 1 ≤ a := by
-- Porting note: broken `convert le_floor_iff' Nat.one_ne_zero`
rw [Nat.lt_iff_add_one_le, zero_add, le_floor_iff' Nat.one_ne_zero, cast_one]
#align nat.floor_pos Nat.floor_pos
theorem pos_of_floor_pos (h : 0 < ⌊a⌋₊) : 0 < a :=
(le_or_lt a 0).resolve_left fun ha => lt_irrefl 0 <| by rwa [floor_of_nonpos ha] at h
#align nat.pos_of_floor_pos Nat.pos_of_floor_pos
theorem lt_of_lt_floor (h : n < ⌊a⌋₊) : ↑n < a :=
(Nat.cast_lt.2 h).trans_le <| floor_le (pos_of_floor_pos <| (Nat.zero_le n).trans_lt h).le
#align nat.lt_of_lt_floor Nat.lt_of_lt_floor
theorem floor_le_of_le (h : a ≤ n) : ⌊a⌋₊ ≤ n :=
le_imp_le_iff_lt_imp_lt.2 lt_of_lt_floor h
#align nat.floor_le_of_le Nat.floor_le_of_le
theorem floor_le_one_of_le_one (h : a ≤ 1) : ⌊a⌋₊ ≤ 1 :=
floor_le_of_le <| h.trans_eq <| Nat.cast_one.symm
#align nat.floor_le_one_of_le_one Nat.floor_le_one_of_le_one
@[simp]
theorem floor_eq_zero : ⌊a⌋₊ = 0 ↔ a < 1 := by
rw [← lt_one_iff, ← @cast_one α]
exact floor_lt' Nat.one_ne_zero
#align nat.floor_eq_zero Nat.floor_eq_zero
theorem floor_eq_iff (ha : 0 ≤ a) : ⌊a⌋₊ = n ↔ ↑n ≤ a ∧ a < ↑n + 1 := by
rw [← le_floor_iff ha, ← Nat.cast_one, ← Nat.cast_add, ← floor_lt ha, Nat.lt_add_one_iff,
le_antisymm_iff, and_comm]
#align nat.floor_eq_iff Nat.floor_eq_iff
theorem floor_eq_iff' (hn : n ≠ 0) : ⌊a⌋₊ = n ↔ ↑n ≤ a ∧ a < ↑n + 1 := by
rw [← le_floor_iff' hn, ← Nat.cast_one, ← Nat.cast_add, ← floor_lt' (Nat.add_one_ne_zero n),
Nat.lt_add_one_iff, le_antisymm_iff, and_comm]
#align nat.floor_eq_iff' Nat.floor_eq_iff'
theorem floor_eq_on_Ico (n : ℕ) : ∀ a ∈ (Set.Ico n (n + 1) : Set α), ⌊a⌋₊ = n := fun _ ⟨h₀, h₁⟩ =>
(floor_eq_iff <| n.cast_nonneg.trans h₀).mpr ⟨h₀, h₁⟩
#align nat.floor_eq_on_Ico Nat.floor_eq_on_Ico
theorem floor_eq_on_Ico' (n : ℕ) :
∀ a ∈ (Set.Ico n (n + 1) : Set α), (⌊a⌋₊ : α) = n :=
fun x hx => mod_cast floor_eq_on_Ico n x hx
#align nat.floor_eq_on_Ico' Nat.floor_eq_on_Ico'
@[simp]
theorem preimage_floor_zero : (floor : α → ℕ) ⁻¹' {0} = Iio 1 :=
ext fun _ => floor_eq_zero
#align nat.preimage_floor_zero Nat.preimage_floor_zero
-- Porting note: in mathlib3 there was no need for the type annotation in `(n:α)`
theorem preimage_floor_of_ne_zero {n : ℕ} (hn : n ≠ 0) :
(floor : α → ℕ) ⁻¹' {n} = Ico (n:α) (n + 1) :=
ext fun _ => floor_eq_iff' hn
#align nat.preimage_floor_of_ne_zero Nat.preimage_floor_of_ne_zero
/-! #### Ceil -/
theorem gc_ceil_coe : GaloisConnection (ceil : α → ℕ) (↑) :=
FloorSemiring.gc_ceil
#align nat.gc_ceil_coe Nat.gc_ceil_coe
@[simp]
theorem ceil_le : ⌈a⌉₊ ≤ n ↔ a ≤ n :=
gc_ceil_coe _ _
#align nat.ceil_le Nat.ceil_le
theorem lt_ceil : n < ⌈a⌉₊ ↔ (n : α) < a :=
lt_iff_lt_of_le_iff_le ceil_le
#align nat.lt_ceil Nat.lt_ceil
-- porting note (#10618): simp can prove this
-- @[simp]
theorem add_one_le_ceil_iff : n + 1 ≤ ⌈a⌉₊ ↔ (n : α) < a := by
rw [← Nat.lt_ceil, Nat.add_one_le_iff]
#align nat.add_one_le_ceil_iff Nat.add_one_le_ceil_iff
@[simp]
theorem one_le_ceil_iff : 1 ≤ ⌈a⌉₊ ↔ 0 < a := by
rw [← zero_add 1, Nat.add_one_le_ceil_iff, Nat.cast_zero]
#align nat.one_le_ceil_iff Nat.one_le_ceil_iff
theorem ceil_le_floor_add_one (a : α) : ⌈a⌉₊ ≤ ⌊a⌋₊ + 1 := by
rw [ceil_le, Nat.cast_add, Nat.cast_one]
exact (lt_floor_add_one a).le
#align nat.ceil_le_floor_add_one Nat.ceil_le_floor_add_one
theorem le_ceil (a : α) : a ≤ ⌈a⌉₊ :=
ceil_le.1 le_rfl
#align nat.le_ceil Nat.le_ceil
@[simp]
theorem ceil_intCast {α : Type*} [LinearOrderedRing α] [FloorSemiring α] (z : ℤ) :
⌈(z : α)⌉₊ = z.toNat :=
eq_of_forall_ge_iff fun a => by
simp only [ceil_le, Int.toNat_le]
norm_cast
#align nat.ceil_int_cast Nat.ceil_intCast
@[simp]
theorem ceil_natCast (n : ℕ) : ⌈(n : α)⌉₊ = n :=
eq_of_forall_ge_iff fun a => by rw [ceil_le, cast_le]
#align nat.ceil_nat_cast Nat.ceil_natCast
theorem ceil_mono : Monotone (ceil : α → ℕ) :=
gc_ceil_coe.monotone_l
#align nat.ceil_mono Nat.ceil_mono
@[gcongr]
theorem ceil_le_ceil : ∀ x y : α, x ≤ y → ⌈x⌉₊ ≤ ⌈y⌉₊ := ceil_mono
@[simp]
theorem ceil_zero : ⌈(0 : α)⌉₊ = 0 := by rw [← Nat.cast_zero, ceil_natCast]
#align nat.ceil_zero Nat.ceil_zero
@[simp]
theorem ceil_one : ⌈(1 : α)⌉₊ = 1 := by rw [← Nat.cast_one, ceil_natCast]
#align nat.ceil_one Nat.ceil_one
-- See note [no_index around OfNat.ofNat]
@[simp]
theorem ceil_ofNat (n : ℕ) [n.AtLeastTwo] : ⌈no_index (OfNat.ofNat n : α)⌉₊ = n := ceil_natCast n
@[simp]
theorem ceil_eq_zero : ⌈a⌉₊ = 0 ↔ a ≤ 0 := by rw [← Nat.le_zero, ceil_le, Nat.cast_zero]
#align nat.ceil_eq_zero Nat.ceil_eq_zero
@[simp]
theorem ceil_pos : 0 < ⌈a⌉₊ ↔ 0 < a := by rw [lt_ceil, cast_zero]
#align nat.ceil_pos Nat.ceil_pos
theorem lt_of_ceil_lt (h : ⌈a⌉₊ < n) : a < n :=
(le_ceil a).trans_lt (Nat.cast_lt.2 h)
#align nat.lt_of_ceil_lt Nat.lt_of_ceil_lt
theorem le_of_ceil_le (h : ⌈a⌉₊ ≤ n) : a ≤ n :=
(le_ceil a).trans (Nat.cast_le.2 h)
#align nat.le_of_ceil_le Nat.le_of_ceil_le
theorem floor_le_ceil (a : α) : ⌊a⌋₊ ≤ ⌈a⌉₊ := by
obtain ha | ha := le_total a 0
· rw [floor_of_nonpos ha]
exact Nat.zero_le _
· exact cast_le.1 ((floor_le ha).trans <| le_ceil _)
#align nat.floor_le_ceil Nat.floor_le_ceil
theorem floor_lt_ceil_of_lt_of_pos {a b : α} (h : a < b) (h' : 0 < b) : ⌊a⌋₊ < ⌈b⌉₊ := by
rcases le_or_lt 0 a with (ha | ha)
· rw [floor_lt ha]
exact h.trans_le (le_ceil _)
· rwa [floor_of_nonpos ha.le, lt_ceil, Nat.cast_zero]
#align nat.floor_lt_ceil_of_lt_of_pos Nat.floor_lt_ceil_of_lt_of_pos
theorem ceil_eq_iff (hn : n ≠ 0) : ⌈a⌉₊ = n ↔ ↑(n - 1) < a ∧ a ≤ n := by
rw [← ceil_le, ← not_le, ← ceil_le, not_le,
tsub_lt_iff_right (Nat.add_one_le_iff.2 (pos_iff_ne_zero.2 hn)), Nat.lt_add_one_iff,
le_antisymm_iff, and_comm]
#align nat.ceil_eq_iff Nat.ceil_eq_iff
@[simp]
theorem preimage_ceil_zero : (Nat.ceil : α → ℕ) ⁻¹' {0} = Iic 0 :=
ext fun _ => ceil_eq_zero
#align nat.preimage_ceil_zero Nat.preimage_ceil_zero
-- Porting note: in mathlib3 there was no need for the type annotation in `(↑(n - 1))`
theorem preimage_ceil_of_ne_zero (hn : n ≠ 0) : (Nat.ceil : α → ℕ) ⁻¹' {n} = Ioc (↑(n - 1) : α) n :=
ext fun _ => ceil_eq_iff hn
#align nat.preimage_ceil_of_ne_zero Nat.preimage_ceil_of_ne_zero
/-! #### Intervals -/
-- Porting note: changed `(coe : ℕ → α)` to `(Nat.cast : ℕ → α)`
@[simp]
theorem preimage_Ioo {a b : α} (ha : 0 ≤ a) :
(Nat.cast : ℕ → α) ⁻¹' Set.Ioo a b = Set.Ioo ⌊a⌋₊ ⌈b⌉₊ := by
ext
simp [floor_lt, lt_ceil, ha]
#align nat.preimage_Ioo Nat.preimage_Ioo
-- Porting note: changed `(coe : ℕ → α)` to `(Nat.cast : ℕ → α)`
@[simp]
theorem preimage_Ico {a b : α} : (Nat.cast : ℕ → α) ⁻¹' Set.Ico a b = Set.Ico ⌈a⌉₊ ⌈b⌉₊ := by
ext
simp [ceil_le, lt_ceil]
#align nat.preimage_Ico Nat.preimage_Ico
-- Porting note: changed `(coe : ℕ → α)` to `(Nat.cast : ℕ → α)`
@[simp]
theorem preimage_Ioc {a b : α} (ha : 0 ≤ a) (hb : 0 ≤ b) :
(Nat.cast : ℕ → α) ⁻¹' Set.Ioc a b = Set.Ioc ⌊a⌋₊ ⌊b⌋₊ := by
ext
simp [floor_lt, le_floor_iff, hb, ha]
#align nat.preimage_Ioc Nat.preimage_Ioc
-- Porting note: changed `(coe : ℕ → α)` to `(Nat.cast : ℕ → α)`
@[simp]
theorem preimage_Icc {a b : α} (hb : 0 ≤ b) :
(Nat.cast : ℕ → α) ⁻¹' Set.Icc a b = Set.Icc ⌈a⌉₊ ⌊b⌋₊ := by
ext
simp [ceil_le, hb, le_floor_iff]
#align nat.preimage_Icc Nat.preimage_Icc
-- Porting note: changed `(coe : ℕ → α)` to `(Nat.cast : ℕ → α)`
@[simp]
theorem preimage_Ioi {a : α} (ha : 0 ≤ a) : (Nat.cast : ℕ → α) ⁻¹' Set.Ioi a = Set.Ioi ⌊a⌋₊ := by
ext
simp [floor_lt, ha]
#align nat.preimage_Ioi Nat.preimage_Ioi
-- Porting note: changed `(coe : ℕ → α)` to `(Nat.cast : ℕ → α)`
@[simp]
theorem preimage_Ici {a : α} : (Nat.cast : ℕ → α) ⁻¹' Set.Ici a = Set.Ici ⌈a⌉₊ := by
ext
simp [ceil_le]
#align nat.preimage_Ici Nat.preimage_Ici
-- Porting note: changed `(coe : ℕ → α)` to `(Nat.cast : ℕ → α)`
@[simp]
theorem preimage_Iio {a : α} : (Nat.cast : ℕ → α) ⁻¹' Set.Iio a = Set.Iio ⌈a⌉₊ := by
ext
simp [lt_ceil]
#align nat.preimage_Iio Nat.preimage_Iio
-- Porting note: changed `(coe : ℕ → α)` to `(Nat.cast : ℕ → α)`
@[simp]
theorem preimage_Iic {a : α} (ha : 0 ≤ a) : (Nat.cast : ℕ → α) ⁻¹' Set.Iic a = Set.Iic ⌊a⌋₊ := by
ext
simp [le_floor_iff, ha]
#align nat.preimage_Iic Nat.preimage_Iic
theorem floor_add_nat (ha : 0 ≤ a) (n : ℕ) : ⌊a + n⌋₊ = ⌊a⌋₊ + n :=
eq_of_forall_le_iff fun b => by
rw [le_floor_iff (add_nonneg ha n.cast_nonneg)]
obtain hb | hb := le_total n b
· obtain ⟨d, rfl⟩ := exists_add_of_le hb
rw [Nat.cast_add, add_comm n, add_comm (n : α), add_le_add_iff_right, add_le_add_iff_right,
le_floor_iff ha]
· obtain ⟨d, rfl⟩ := exists_add_of_le hb
rw [Nat.cast_add, add_left_comm _ b, add_left_comm _ (b : α)]
refine iff_of_true ?_ le_self_add
exact le_add_of_nonneg_right <| ha.trans <| le_add_of_nonneg_right d.cast_nonneg
#align nat.floor_add_nat Nat.floor_add_nat
theorem floor_add_one (ha : 0 ≤ a) : ⌊a + 1⌋₊ = ⌊a⌋₊ + 1 := by
-- Porting note: broken `convert floor_add_nat ha 1`
rw [← cast_one, floor_add_nat ha 1]
#align nat.floor_add_one Nat.floor_add_one
-- See note [no_index around OfNat.ofNat]
theorem floor_add_ofNat (ha : 0 ≤ a) (n : ℕ) [n.AtLeastTwo] :
⌊a + (no_index (OfNat.ofNat n))⌋₊ = ⌊a⌋₊ + OfNat.ofNat n :=
floor_add_nat ha n
@[simp]
theorem floor_sub_nat [Sub α] [OrderedSub α] [ExistsAddOfLE α] (a : α) (n : ℕ) :
⌊a - n⌋₊ = ⌊a⌋₊ - n := by
obtain ha | ha := le_total a 0
· rw [floor_of_nonpos ha, floor_of_nonpos (tsub_nonpos_of_le (ha.trans n.cast_nonneg)), zero_tsub]
rcases le_total a n with h | h
· rw [floor_of_nonpos (tsub_nonpos_of_le h), eq_comm, tsub_eq_zero_iff_le]
exact Nat.cast_le.1 ((Nat.floor_le ha).trans h)
· rw [eq_tsub_iff_add_eq_of_le (le_floor h), ← floor_add_nat _, tsub_add_cancel_of_le h]
exact le_tsub_of_add_le_left ((add_zero _).trans_le h)
#align nat.floor_sub_nat Nat.floor_sub_nat
@[simp]
theorem floor_sub_one [Sub α] [OrderedSub α] [ExistsAddOfLE α] (a : α) : ⌊a - 1⌋₊ = ⌊a⌋₊ - 1 :=
mod_cast floor_sub_nat a 1
-- See note [no_index around OfNat.ofNat]
@[simp]
theorem floor_sub_ofNat [Sub α] [OrderedSub α] [ExistsAddOfLE α] (a : α) (n : ℕ) [n.AtLeastTwo] :
⌊a - (no_index (OfNat.ofNat n))⌋₊ = ⌊a⌋₊ - OfNat.ofNat n :=
floor_sub_nat a n
theorem ceil_add_nat (ha : 0 ≤ a) (n : ℕ) : ⌈a + n⌉₊ = ⌈a⌉₊ + n :=
eq_of_forall_ge_iff fun b => by
rw [← not_lt, ← not_lt, not_iff_not, lt_ceil]
obtain hb | hb := le_or_lt n b
· obtain ⟨d, rfl⟩ := exists_add_of_le hb
rw [Nat.cast_add, add_comm n, add_comm (n : α), add_lt_add_iff_right, add_lt_add_iff_right,
lt_ceil]
· exact iff_of_true (lt_add_of_nonneg_of_lt ha <| cast_lt.2 hb) (Nat.lt_add_left _ hb)
#align nat.ceil_add_nat Nat.ceil_add_nat
theorem ceil_add_one (ha : 0 ≤ a) : ⌈a + 1⌉₊ = ⌈a⌉₊ + 1 := by
-- Porting note: broken `convert ceil_add_nat ha 1`
rw [cast_one.symm, ceil_add_nat ha 1]
#align nat.ceil_add_one Nat.ceil_add_one
-- See note [no_index around OfNat.ofNat]
theorem ceil_add_ofNat (ha : 0 ≤ a) (n : ℕ) [n.AtLeastTwo] :
⌈a + (no_index (OfNat.ofNat n))⌉₊ = ⌈a⌉₊ + OfNat.ofNat n :=
ceil_add_nat ha n
theorem ceil_lt_add_one (ha : 0 ≤ a) : (⌈a⌉₊ : α) < a + 1 :=
lt_ceil.1 <| (Nat.lt_succ_self _).trans_le (ceil_add_one ha).ge
#align nat.ceil_lt_add_one Nat.ceil_lt_add_one
theorem ceil_add_le (a b : α) : ⌈a + b⌉₊ ≤ ⌈a⌉₊ + ⌈b⌉₊ := by
rw [ceil_le, Nat.cast_add]
exact _root_.add_le_add (le_ceil _) (le_ceil _)
#align nat.ceil_add_le Nat.ceil_add_le
end LinearOrderedSemiring
section LinearOrderedRing
variable [LinearOrderedRing α] [FloorSemiring α]
theorem sub_one_lt_floor (a : α) : a - 1 < ⌊a⌋₊ :=
sub_lt_iff_lt_add.2 <| lt_floor_add_one a
#align nat.sub_one_lt_floor Nat.sub_one_lt_floor
end LinearOrderedRing
section LinearOrderedSemifield
variable [LinearOrderedSemifield α] [FloorSemiring α]
-- TODO: should these lemmas be `simp`? `norm_cast`?
theorem floor_div_nat (a : α) (n : ℕ) : ⌊a / n⌋₊ = ⌊a⌋₊ / n := by
rcases le_total a 0 with ha | ha
· rw [floor_of_nonpos, floor_of_nonpos ha]
· simp
apply div_nonpos_of_nonpos_of_nonneg ha n.cast_nonneg
obtain rfl | hn := n.eq_zero_or_pos
· rw [cast_zero, div_zero, Nat.div_zero, floor_zero]
refine (floor_eq_iff ?_).2 ?_
· exact div_nonneg ha n.cast_nonneg
constructor
· exact cast_div_le.trans (div_le_div_of_nonneg_right (floor_le ha) n.cast_nonneg)
rw [div_lt_iff, add_mul, one_mul, ← cast_mul, ← cast_add, ← floor_lt ha]
· exact lt_div_mul_add hn
· exact cast_pos.2 hn
#align nat.floor_div_nat Nat.floor_div_nat
-- See note [no_index around OfNat.ofNat]
theorem floor_div_ofNat (a : α) (n : ℕ) [n.AtLeastTwo] :
⌊a / (no_index (OfNat.ofNat n))⌋₊ = ⌊a⌋₊ / OfNat.ofNat n :=
floor_div_nat a n
/-- Natural division is the floor of field division. -/
theorem floor_div_eq_div (m n : ℕ) : ⌊(m : α) / n⌋₊ = m / n := by
convert floor_div_nat (m : α) n
rw [m.floor_natCast]
#align nat.floor_div_eq_div Nat.floor_div_eq_div
end LinearOrderedSemifield
end Nat
/-- There exists at most one `FloorSemiring` structure on a linear ordered semiring. -/
theorem subsingleton_floorSemiring {α} [LinearOrderedSemiring α] :
Subsingleton (FloorSemiring α) := by
refine ⟨fun H₁ H₂ => ?_⟩
have : H₁.ceil = H₂.ceil := funext fun a => (H₁.gc_ceil.l_unique H₂.gc_ceil) fun n => rfl
have : H₁.floor = H₂.floor := by
ext a
cases' lt_or_le a 0 with h h
· rw [H₁.floor_of_neg, H₂.floor_of_neg] <;> exact h
· refine eq_of_forall_le_iff fun n => ?_
rw [H₁.gc_floor, H₂.gc_floor] <;> exact h
cases H₁
cases H₂
congr
#align subsingleton_floor_semiring subsingleton_floorSemiring
/-! ### Floor rings -/
/-- A `FloorRing` is a linear ordered ring over `α` with a function
`floor : α → ℤ` satisfying `∀ (z : ℤ) (a : α), z ≤ floor a ↔ (z : α) ≤ a)`.
-/
class FloorRing (α) [LinearOrderedRing α] where
/-- `FloorRing.floor a` computes the greatest integer `z` such that `(z : α) ≤ a`. -/
floor : α → ℤ
/-- `FloorRing.ceil a` computes the least integer `z` such that `a ≤ (z : α)`. -/
ceil : α → ℤ
/-- `FloorRing.ceil` is the upper adjoint of the coercion `↑ : ℤ → α`. -/
gc_coe_floor : GaloisConnection (↑) floor
/-- `FloorRing.ceil` is the lower adjoint of the coercion `↑ : ℤ → α`. -/
gc_ceil_coe : GaloisConnection ceil (↑)
#align floor_ring FloorRing
instance : FloorRing ℤ where
floor := id
ceil := id
gc_coe_floor a b := by
rw [Int.cast_id]
rfl
gc_ceil_coe a b := by
rw [Int.cast_id]
rfl
/-- A `FloorRing` constructor from the `floor` function alone. -/
def FloorRing.ofFloor (α) [LinearOrderedRing α] (floor : α → ℤ)
(gc_coe_floor : GaloisConnection (↑) floor) : FloorRing α :=
{ floor
ceil := fun a => -floor (-a)
gc_coe_floor
gc_ceil_coe := fun a z => by rw [neg_le, ← gc_coe_floor, Int.cast_neg, neg_le_neg_iff] }
#align floor_ring.of_floor FloorRing.ofFloor
/-- A `FloorRing` constructor from the `ceil` function alone. -/
def FloorRing.ofCeil (α) [LinearOrderedRing α] (ceil : α → ℤ)
(gc_ceil_coe : GaloisConnection ceil (↑)) : FloorRing α :=
{ floor := fun a => -ceil (-a)
ceil
gc_coe_floor := fun a z => by rw [le_neg, gc_ceil_coe, Int.cast_neg, neg_le_neg_iff]
gc_ceil_coe }
#align floor_ring.of_ceil FloorRing.ofCeil
namespace Int
variable [LinearOrderedRing α] [FloorRing α] {z : ℤ} {a : α}
/-- `Int.floor a` is the greatest integer `z` such that `z ≤ a`. It is denoted with `⌊a⌋`. -/
def floor : α → ℤ :=
FloorRing.floor
#align int.floor Int.floor
/-- `Int.ceil a` is the smallest integer `z` such that `a ≤ z`. It is denoted with `⌈a⌉`. -/
def ceil : α → ℤ :=
FloorRing.ceil
#align int.ceil Int.ceil
/-- `Int.fract a`, the fractional part of `a`, is `a` minus its floor. -/
def fract (a : α) : α :=
a - floor a
#align int.fract Int.fract
@[simp]
theorem floor_int : (Int.floor : ℤ → ℤ) = id :=
rfl
#align int.floor_int Int.floor_int
@[simp]
theorem ceil_int : (Int.ceil : ℤ → ℤ) = id :=
rfl
#align int.ceil_int Int.ceil_int
@[simp]
theorem fract_int : (Int.fract : ℤ → ℤ) = 0 :=
funext fun x => by simp [fract]
#align int.fract_int Int.fract_int
@[inherit_doc]
notation "⌊" a "⌋" => Int.floor a
@[inherit_doc]
notation "⌈" a "⌉" => Int.ceil a
-- Mathematical notation for `fract a` is usually `{a}`. Let's not even go there.
@[simp]
theorem floorRing_floor_eq : @FloorRing.floor = @Int.floor :=
rfl
#align int.floor_ring_floor_eq Int.floorRing_floor_eq
@[simp]
theorem floorRing_ceil_eq : @FloorRing.ceil = @Int.ceil :=
rfl
#align int.floor_ring_ceil_eq Int.floorRing_ceil_eq
/-! #### Floor -/
theorem gc_coe_floor : GaloisConnection ((↑) : ℤ → α) floor :=
FloorRing.gc_coe_floor
#align int.gc_coe_floor Int.gc_coe_floor
theorem le_floor : z ≤ ⌊a⌋ ↔ (z : α) ≤ a :=
(gc_coe_floor z a).symm
#align int.le_floor Int.le_floor
theorem floor_lt : ⌊a⌋ < z ↔ a < z :=
lt_iff_lt_of_le_iff_le le_floor
#align int.floor_lt Int.floor_lt
theorem floor_le (a : α) : (⌊a⌋ : α) ≤ a :=
gc_coe_floor.l_u_le a
#align int.floor_le Int.floor_le
theorem floor_nonneg : 0 ≤ ⌊a⌋ ↔ 0 ≤ a := by rw [le_floor, Int.cast_zero]
#align int.floor_nonneg Int.floor_nonneg
@[simp]
theorem floor_le_sub_one_iff : ⌊a⌋ ≤ z - 1 ↔ a < z := by rw [← floor_lt, le_sub_one_iff]
#align int.floor_le_sub_one_iff Int.floor_le_sub_one_iff
@[simp]
theorem floor_le_neg_one_iff : ⌊a⌋ ≤ -1 ↔ a < 0 := by
rw [← zero_sub (1 : ℤ), floor_le_sub_one_iff, cast_zero]
#align int.floor_le_neg_one_iff Int.floor_le_neg_one_iff
theorem floor_nonpos (ha : a ≤ 0) : ⌊a⌋ ≤ 0 := by
rw [← @cast_le α, Int.cast_zero]
exact (floor_le a).trans ha
#align int.floor_nonpos Int.floor_nonpos
theorem lt_succ_floor (a : α) : a < ⌊a⌋.succ :=
floor_lt.1 <| Int.lt_succ_self _
#align int.lt_succ_floor Int.lt_succ_floor
@[simp]
theorem lt_floor_add_one (a : α) : a < ⌊a⌋ + 1 := by
simpa only [Int.succ, Int.cast_add, Int.cast_one] using lt_succ_floor a
#align int.lt_floor_add_one Int.lt_floor_add_one
@[simp]
theorem sub_one_lt_floor (a : α) : a - 1 < ⌊a⌋ :=
sub_lt_iff_lt_add.2 (lt_floor_add_one a)
#align int.sub_one_lt_floor Int.sub_one_lt_floor
@[simp]
theorem floor_intCast (z : ℤ) : ⌊(z : α)⌋ = z :=
eq_of_forall_le_iff fun a => by rw [le_floor, Int.cast_le]
#align int.floor_int_cast Int.floor_intCast
@[simp]
theorem floor_natCast (n : ℕ) : ⌊(n : α)⌋ = n :=
eq_of_forall_le_iff fun a => by rw [le_floor, ← cast_natCast, cast_le]
#align int.floor_nat_cast Int.floor_natCast
@[simp]
theorem floor_zero : ⌊(0 : α)⌋ = 0 := by rw [← cast_zero, floor_intCast]
#align int.floor_zero Int.floor_zero
@[simp]
theorem floor_one : ⌊(1 : α)⌋ = 1 := by rw [← cast_one, floor_intCast]
#align int.floor_one Int.floor_one
-- See note [no_index around OfNat.ofNat]
@[simp] theorem floor_ofNat (n : ℕ) [n.AtLeastTwo] : ⌊(no_index (OfNat.ofNat n : α))⌋ = n :=
floor_natCast n
@[mono]
theorem floor_mono : Monotone (floor : α → ℤ) :=
gc_coe_floor.monotone_u
#align int.floor_mono Int.floor_mono
@[gcongr]
theorem floor_le_floor : ∀ x y : α, x ≤ y → ⌊x⌋ ≤ ⌊y⌋ := floor_mono
theorem floor_pos : 0 < ⌊a⌋ ↔ 1 ≤ a := by
-- Porting note: broken `convert le_floor`
rw [Int.lt_iff_add_one_le, zero_add, le_floor, cast_one]
#align int.floor_pos Int.floor_pos
@[simp]
theorem floor_add_int (a : α) (z : ℤ) : ⌊a + z⌋ = ⌊a⌋ + z :=
eq_of_forall_le_iff fun a => by
rw [le_floor, ← sub_le_iff_le_add, ← sub_le_iff_le_add, le_floor, Int.cast_sub]
#align int.floor_add_int Int.floor_add_int
@[simp]
theorem floor_add_one (a : α) : ⌊a + 1⌋ = ⌊a⌋ + 1 := by
-- Porting note: broken `convert floor_add_int a 1`
rw [← cast_one, floor_add_int]
#align int.floor_add_one Int.floor_add_one
theorem le_floor_add (a b : α) : ⌊a⌋ + ⌊b⌋ ≤ ⌊a + b⌋ := by
rw [le_floor, Int.cast_add]
exact add_le_add (floor_le _) (floor_le _)
#align int.le_floor_add Int.le_floor_add
theorem le_floor_add_floor (a b : α) : ⌊a + b⌋ - 1 ≤ ⌊a⌋ + ⌊b⌋ := by
rw [← sub_le_iff_le_add, le_floor, Int.cast_sub, sub_le_comm, Int.cast_sub, Int.cast_one]
refine le_trans ?_ (sub_one_lt_floor _).le
rw [sub_le_iff_le_add', ← add_sub_assoc, sub_le_sub_iff_right]
exact floor_le _
#align int.le_floor_add_floor Int.le_floor_add_floor
@[simp]
theorem floor_int_add (z : ℤ) (a : α) : ⌊↑z + a⌋ = z + ⌊a⌋ := by
simpa only [add_comm] using floor_add_int a z
#align int.floor_int_add Int.floor_int_add
@[simp]
theorem floor_add_nat (a : α) (n : ℕ) : ⌊a + n⌋ = ⌊a⌋ + n := by
rw [← Int.cast_natCast, floor_add_int]
#align int.floor_add_nat Int.floor_add_nat
-- See note [no_index around OfNat.ofNat]
@[simp]
theorem floor_add_ofNat (a : α) (n : ℕ) [n.AtLeastTwo] :
⌊a + (no_index (OfNat.ofNat n))⌋ = ⌊a⌋ + OfNat.ofNat n :=
floor_add_nat a n
@[simp]
theorem floor_nat_add (n : ℕ) (a : α) : ⌊↑n + a⌋ = n + ⌊a⌋ := by
rw [← Int.cast_natCast, floor_int_add]
#align int.floor_nat_add Int.floor_nat_add
-- See note [no_index around OfNat.ofNat]
@[simp]
theorem floor_ofNat_add (n : ℕ) [n.AtLeastTwo] (a : α) :
⌊(no_index (OfNat.ofNat n)) + a⌋ = OfNat.ofNat n + ⌊a⌋ :=
floor_nat_add n a
@[simp]
theorem floor_sub_int (a : α) (z : ℤ) : ⌊a - z⌋ = ⌊a⌋ - z :=
Eq.trans (by rw [Int.cast_neg, sub_eq_add_neg]) (floor_add_int _ _)
#align int.floor_sub_int Int.floor_sub_int
@[simp]
theorem floor_sub_nat (a : α) (n : ℕ) : ⌊a - n⌋ = ⌊a⌋ - n := by
rw [← Int.cast_natCast, floor_sub_int]
#align int.floor_sub_nat Int.floor_sub_nat
@[simp] theorem floor_sub_one (a : α) : ⌊a - 1⌋ = ⌊a⌋ - 1 := mod_cast floor_sub_nat a 1
-- See note [no_index around OfNat.ofNat]
@[simp]
theorem floor_sub_ofNat (a : α) (n : ℕ) [n.AtLeastTwo] :
⌊a - (no_index (OfNat.ofNat n))⌋ = ⌊a⌋ - OfNat.ofNat n :=
floor_sub_nat a n
theorem abs_sub_lt_one_of_floor_eq_floor {α : Type*} [LinearOrderedCommRing α] [FloorRing α]
{a b : α} (h : ⌊a⌋ = ⌊b⌋) : |a - b| < 1 := by
have : a < ⌊a⌋ + 1 := lt_floor_add_one a
have : b < ⌊b⌋ + 1 := lt_floor_add_one b
have : (⌊a⌋ : α) = ⌊b⌋ := Int.cast_inj.2 h
have : (⌊a⌋ : α) ≤ a := floor_le a
have : (⌊b⌋ : α) ≤ b := floor_le b
exact abs_sub_lt_iff.2 ⟨by linarith, by linarith⟩
#align int.abs_sub_lt_one_of_floor_eq_floor Int.abs_sub_lt_one_of_floor_eq_floor
theorem floor_eq_iff : ⌊a⌋ = z ↔ ↑z ≤ a ∧ a < z + 1 := by
rw [le_antisymm_iff, le_floor, ← Int.lt_add_one_iff, floor_lt, Int.cast_add, Int.cast_one,
and_comm]
#align int.floor_eq_iff Int.floor_eq_iff
@[simp]
theorem floor_eq_zero_iff : ⌊a⌋ = 0 ↔ a ∈ Ico (0 : α) 1 := by simp [floor_eq_iff]
#align int.floor_eq_zero_iff Int.floor_eq_zero_iff
theorem floor_eq_on_Ico (n : ℤ) : ∀ a ∈ Set.Ico (n : α) (n + 1), ⌊a⌋ = n := fun _ ⟨h₀, h₁⟩ =>
floor_eq_iff.mpr ⟨h₀, h₁⟩
#align int.floor_eq_on_Ico Int.floor_eq_on_Ico
theorem floor_eq_on_Ico' (n : ℤ) : ∀ a ∈ Set.Ico (n : α) (n + 1), (⌊a⌋ : α) = n := fun a ha =>
congr_arg _ <| floor_eq_on_Ico n a ha
#align int.floor_eq_on_Ico' Int.floor_eq_on_Ico'
-- Porting note: in mathlib3 there was no need for the type annotation in `(m:α)`
@[simp]
theorem preimage_floor_singleton (m : ℤ) : (floor : α → ℤ) ⁻¹' {m} = Ico (m : α) (m + 1) :=
ext fun _ => floor_eq_iff
#align int.preimage_floor_singleton Int.preimage_floor_singleton
/-! #### Fractional part -/
@[simp]
theorem self_sub_floor (a : α) : a - ⌊a⌋ = fract a :=
rfl
#align int.self_sub_floor Int.self_sub_floor
@[simp]
theorem floor_add_fract (a : α) : (⌊a⌋ : α) + fract a = a :=
add_sub_cancel _ _
#align int.floor_add_fract Int.floor_add_fract
@[simp]
theorem fract_add_floor (a : α) : fract a + ⌊a⌋ = a :=
sub_add_cancel _ _
#align int.fract_add_floor Int.fract_add_floor
@[simp]
theorem fract_add_int (a : α) (m : ℤ) : fract (a + m) = fract a := by
rw [fract]
simp
#align int.fract_add_int Int.fract_add_int
@[simp]
theorem fract_add_nat (a : α) (m : ℕ) : fract (a + m) = fract a := by
rw [fract]
simp
#align int.fract_add_nat Int.fract_add_nat
@[simp]
theorem fract_add_one (a : α) : fract (a + 1) = fract a := mod_cast fract_add_nat a 1
-- See note [no_index around OfNat.ofNat]
@[simp]
theorem fract_add_ofNat (a : α) (n : ℕ) [n.AtLeastTwo] :
fract (a + (no_index (OfNat.ofNat n))) = fract a :=
fract_add_nat a n
@[simp]
theorem fract_int_add (m : ℤ) (a : α) : fract (↑m + a) = fract a := by rw [add_comm, fract_add_int]
#align int.fract_int_add Int.fract_int_add
@[simp]
theorem fract_nat_add (n : ℕ) (a : α) : fract (↑n + a) = fract a := by rw [add_comm, fract_add_nat]
@[simp]
theorem fract_one_add (a : α) : fract (1 + a) = fract a := mod_cast fract_nat_add 1 a
-- See note [no_index around OfNat.ofNat]
@[simp]
theorem fract_ofNat_add (n : ℕ) [n.AtLeastTwo] (a : α) :
fract ((no_index (OfNat.ofNat n)) + a) = fract a :=
fract_nat_add n a
@[simp]
theorem fract_sub_int (a : α) (m : ℤ) : fract (a - m) = fract a := by
rw [fract]
simp
#align int.fract_sub_int Int.fract_sub_int
@[simp]
theorem fract_sub_nat (a : α) (n : ℕ) : fract (a - n) = fract a := by
rw [fract]
simp
#align int.fract_sub_nat Int.fract_sub_nat
@[simp]
theorem fract_sub_one (a : α) : fract (a - 1) = fract a := mod_cast fract_sub_nat a 1
-- See note [no_index around OfNat.ofNat]
@[simp]
theorem fract_sub_ofNat (a : α) (n : ℕ) [n.AtLeastTwo] :
fract (a - (no_index (OfNat.ofNat n))) = fract a :=
fract_sub_nat a n
-- Was a duplicate lemma under a bad name
#align int.fract_int_nat Int.fract_int_add
theorem fract_add_le (a b : α) : fract (a + b) ≤ fract a + fract b := by
rw [fract, fract, fract, sub_add_sub_comm, sub_le_sub_iff_left, ← Int.cast_add, Int.cast_le]
exact le_floor_add _ _
#align int.fract_add_le Int.fract_add_le
theorem fract_add_fract_le (a b : α) : fract a + fract b ≤ fract (a + b) + 1 := by
rw [fract, fract, fract, sub_add_sub_comm, sub_add, sub_le_sub_iff_left]
exact mod_cast le_floor_add_floor a b
#align int.fract_add_fract_le Int.fract_add_fract_le
@[simp]
theorem self_sub_fract (a : α) : a - fract a = ⌊a⌋ :=
sub_sub_cancel _ _
#align int.self_sub_fract Int.self_sub_fract
@[simp]
theorem fract_sub_self (a : α) : fract a - a = -⌊a⌋ :=
sub_sub_cancel_left _ _
#align int.fract_sub_self Int.fract_sub_self
@[simp]
theorem fract_nonneg (a : α) : 0 ≤ fract a :=
sub_nonneg.2 <| floor_le _
#align int.fract_nonneg Int.fract_nonneg
/-- The fractional part of `a` is positive if and only if `a ≠ ⌊a⌋`. -/
lemma fract_pos : 0 < fract a ↔ a ≠ ⌊a⌋ :=
(fract_nonneg a).lt_iff_ne.trans <| ne_comm.trans sub_ne_zero
#align int.fract_pos Int.fract_pos
theorem fract_lt_one (a : α) : fract a < 1 :=
sub_lt_comm.1 <| sub_one_lt_floor _
#align int.fract_lt_one Int.fract_lt_one
@[simp]
theorem fract_zero : fract (0 : α) = 0 := by rw [fract, floor_zero, cast_zero, sub_self]
#align int.fract_zero Int.fract_zero
@[simp]
theorem fract_one : fract (1 : α) = 0 := by simp [fract]
#align int.fract_one Int.fract_one
theorem abs_fract : |fract a| = fract a :=
abs_eq_self.mpr <| fract_nonneg a
#align int.abs_fract Int.abs_fract
@[simp]
theorem abs_one_sub_fract : |1 - fract a| = 1 - fract a :=
abs_eq_self.mpr <| sub_nonneg.mpr (fract_lt_one a).le
#align int.abs_one_sub_fract Int.abs_one_sub_fract
@[simp]
theorem fract_intCast (z : ℤ) : fract (z : α) = 0 := by
unfold fract
rw [floor_intCast]
exact sub_self _
#align int.fract_int_cast Int.fract_intCast
@[simp]
theorem fract_natCast (n : ℕ) : fract (n : α) = 0 := by simp [fract]
#align int.fract_nat_cast Int.fract_natCast
-- See note [no_index around OfNat.ofNat]
@[simp]
theorem fract_ofNat (n : ℕ) [n.AtLeastTwo] :
fract ((no_index (OfNat.ofNat n)) : α) = 0 :=
fract_natCast n
-- porting note (#10618): simp can prove this
-- @[simp]
theorem fract_floor (a : α) : fract (⌊a⌋ : α) = 0 :=
fract_intCast _
#align int.fract_floor Int.fract_floor
@[simp]
theorem floor_fract (a : α) : ⌊fract a⌋ = 0 := by
rw [floor_eq_iff, Int.cast_zero, zero_add]; exact ⟨fract_nonneg _, fract_lt_one _⟩
#align int.floor_fract Int.floor_fract
theorem fract_eq_iff {a b : α} : fract a = b ↔ 0 ≤ b ∧ b < 1 ∧ ∃ z : ℤ, a - b = z :=
⟨fun h => by
rw [← h]
exact ⟨fract_nonneg _, fract_lt_one _, ⟨⌊a⌋, sub_sub_cancel _ _⟩⟩,
by
rintro ⟨h₀, h₁, z, hz⟩
rw [← self_sub_floor, eq_comm, eq_sub_iff_add_eq, add_comm, ← eq_sub_iff_add_eq, hz,
Int.cast_inj, floor_eq_iff, ← hz]
constructor <;> simpa [sub_eq_add_neg, add_assoc] ⟩
#align int.fract_eq_iff Int.fract_eq_iff
theorem fract_eq_fract {a b : α} : fract a = fract b ↔ ∃ z : ℤ, a - b = z :=
⟨fun h => ⟨⌊a⌋ - ⌊b⌋, by unfold fract at h; rw [Int.cast_sub, sub_eq_sub_iff_sub_eq_sub.1 h]⟩,
by
rintro ⟨z, hz⟩
refine fract_eq_iff.2 ⟨fract_nonneg _, fract_lt_one _, z + ⌊b⌋, ?_⟩
rw [eq_add_of_sub_eq hz, add_comm, Int.cast_add]
exact add_sub_sub_cancel _ _ _⟩
#align int.fract_eq_fract Int.fract_eq_fract
@[simp]
theorem fract_eq_self {a : α} : fract a = a ↔ 0 ≤ a ∧ a < 1 :=
fract_eq_iff.trans <| and_assoc.symm.trans <| and_iff_left ⟨0, by simp⟩
#align int.fract_eq_self Int.fract_eq_self
@[simp]
theorem fract_fract (a : α) : fract (fract a) = fract a :=
fract_eq_self.2 ⟨fract_nonneg _, fract_lt_one _⟩
#align int.fract_fract Int.fract_fract
theorem fract_add (a b : α) : ∃ z : ℤ, fract (a + b) - fract a - fract b = z :=
⟨⌊a⌋ + ⌊b⌋ - ⌊a + b⌋, by
unfold fract
simp only [sub_eq_add_neg, neg_add_rev, neg_neg, cast_add, cast_neg]
abel⟩
#align int.fract_add Int.fract_add
theorem fract_neg {x : α} (hx : fract x ≠ 0) : fract (-x) = 1 - fract x := by
rw [fract_eq_iff]
constructor
· rw [le_sub_iff_add_le, zero_add]
exact (fract_lt_one x).le
refine ⟨sub_lt_self _ (lt_of_le_of_ne' (fract_nonneg x) hx), -⌊x⌋ - 1, ?_⟩
simp only [sub_sub_eq_add_sub, cast_sub, cast_neg, cast_one, sub_left_inj]
conv in -x => rw [← floor_add_fract x]
simp [-floor_add_fract]
#align int.fract_neg Int.fract_neg
@[simp]
theorem fract_neg_eq_zero {x : α} : fract (-x) = 0 ↔ fract x = 0 := by
simp only [fract_eq_iff, le_refl, zero_lt_one, tsub_zero, true_and_iff]
constructor <;> rintro ⟨z, hz⟩ <;> use -z <;> simp [← hz]
#align int.fract_neg_eq_zero Int.fract_neg_eq_zero
theorem fract_mul_nat (a : α) (b : ℕ) : ∃ z : ℤ, fract a * b - fract (a * b) = z := by
induction' b with c hc
· use 0; simp
· rcases hc with ⟨z, hz⟩
rw [Nat.cast_add, mul_add, mul_add, Nat.cast_one, mul_one, mul_one]
rcases fract_add (a * c) a with ⟨y, hy⟩
use z - y
rw [Int.cast_sub, ← hz, ← hy]
abel
#align int.fract_mul_nat Int.fract_mul_nat
-- Porting note: in mathlib3 there was no need for the type annotation in `(m:α)`
theorem preimage_fract (s : Set α) :
fract ⁻¹' s = ⋃ m : ℤ, (fun x => x - (m:α)) ⁻¹' (s ∩ Ico (0 : α) 1) := by
ext x
simp only [mem_preimage, mem_iUnion, mem_inter_iff]
refine ⟨fun h => ⟨⌊x⌋, h, fract_nonneg x, fract_lt_one x⟩, ?_⟩
rintro ⟨m, hms, hm0, hm1⟩
obtain rfl : ⌊x⌋ = m := floor_eq_iff.2 ⟨sub_nonneg.1 hm0, sub_lt_iff_lt_add'.1 hm1⟩
exact hms
#align int.preimage_fract Int.preimage_fract
theorem image_fract (s : Set α) : fract '' s = ⋃ m : ℤ, (fun x : α => x - m) '' s ∩ Ico 0 1 := by
ext x
simp only [mem_image, mem_inter_iff, mem_iUnion]; constructor
· rintro ⟨y, hy, rfl⟩
exact ⟨⌊y⌋, ⟨y, hy, rfl⟩, fract_nonneg y, fract_lt_one y⟩
· rintro ⟨m, ⟨y, hys, rfl⟩, h0, h1⟩
obtain rfl : ⌊y⌋ = m := floor_eq_iff.2 ⟨sub_nonneg.1 h0, sub_lt_iff_lt_add'.1 h1⟩
exact ⟨y, hys, rfl⟩
#align int.image_fract Int.image_fract
section LinearOrderedField
variable {k : Type*} [LinearOrderedField k] [FloorRing k] {b : k}
theorem fract_div_mul_self_mem_Ico (a b : k) (ha : 0 < a) : fract (b / a) * a ∈ Ico 0 a :=
⟨(mul_nonneg_iff_of_pos_right ha).2 (fract_nonneg (b / a)),
(mul_lt_iff_lt_one_left ha).2 (fract_lt_one (b / a))⟩
#align int.fract_div_mul_self_mem_Ico Int.fract_div_mul_self_mem_Ico
theorem fract_div_mul_self_add_zsmul_eq (a b : k) (ha : a ≠ 0) :
fract (b / a) * a + ⌊b / a⌋ • a = b := by
rw [zsmul_eq_mul, ← add_mul, fract_add_floor, div_mul_cancel₀ b ha]
#align int.fract_div_mul_self_add_zsmul_eq Int.fract_div_mul_self_add_zsmul_eq
theorem sub_floor_div_mul_nonneg (a : k) (hb : 0 < b) : 0 ≤ a - ⌊a / b⌋ * b :=
sub_nonneg_of_le <| (le_div_iff hb).1 <| floor_le _
#align int.sub_floor_div_mul_nonneg Int.sub_floor_div_mul_nonneg
theorem sub_floor_div_mul_lt (a : k) (hb : 0 < b) : a - ⌊a / b⌋ * b < b :=
sub_lt_iff_lt_add.2 <| by
-- Porting note: `← one_add_mul` worked in mathlib3 without the argument
rw [← one_add_mul _ b, ← div_lt_iff hb, add_comm]
exact lt_floor_add_one _
#align int.sub_floor_div_mul_lt Int.sub_floor_div_mul_lt
theorem fract_div_natCast_eq_div_natCast_mod {m n : ℕ} : fract ((m : k) / n) = ↑(m % n) / n := by
rcases n.eq_zero_or_pos with (rfl | hn)
· simp
have hn' : 0 < (n : k) := by
norm_cast
refine fract_eq_iff.mpr ⟨?_, ?_, m / n, ?_⟩
· positivity
· simpa only [div_lt_one hn', Nat.cast_lt] using m.mod_lt hn
· rw [sub_eq_iff_eq_add', ← mul_right_inj' hn'.ne', mul_div_cancel₀ _ hn'.ne', mul_add,
mul_div_cancel₀ _ hn'.ne']
norm_cast
rw [← Nat.cast_add, Nat.mod_add_div m n]
#align int.fract_div_nat_cast_eq_div_nat_cast_mod Int.fract_div_natCast_eq_div_natCast_mod
-- TODO Generalise this to allow `n : ℤ` using `Int.fmod` instead of `Int.mod`.
theorem fract_div_intCast_eq_div_intCast_mod {m : ℤ} {n : ℕ} :
fract ((m : k) / n) = ↑(m % n) / n := by
rcases n.eq_zero_or_pos with (rfl | hn)
· simp
replace hn : 0 < (n : k) := by norm_cast
have : ∀ {l : ℤ}, 0 ≤ l → fract ((l : k) / n) = ↑(l % n) / n := by
intros l hl
obtain ⟨l₀, rfl | rfl⟩ := l.eq_nat_or_neg
· rw [cast_natCast, ← natCast_mod, cast_natCast, fract_div_natCast_eq_div_natCast_mod]
· rw [Right.nonneg_neg_iff, natCast_nonpos_iff] at hl
simp [hl, zero_mod]
obtain ⟨m₀, rfl | rfl⟩ := m.eq_nat_or_neg
· exact this (ofNat_nonneg m₀)
let q := ⌈↑m₀ / (n : k)⌉
let m₁ := q * ↑n - (↑m₀ : ℤ)
have hm₁ : 0 ≤ m₁ := by
simpa [m₁, ← @cast_le k, ← div_le_iff hn] using FloorRing.gc_ceil_coe.le_u_l _
calc
fract ((Int.cast (-(m₀ : ℤ)) : k) / (n : k))
-- Porting note: the `rw [cast_neg, cast_natCast]` was `push_cast`
= fract (-(m₀ : k) / n) := by rw [cast_neg, cast_natCast]
_ = fract ((m₁ : k) / n) := ?_
_ = Int.cast (m₁ % (n : ℤ)) / Nat.cast n := this hm₁
_ = Int.cast (-(↑m₀ : ℤ) % ↑n) / Nat.cast n := ?_
· rw [← fract_int_add q, ← mul_div_cancel_right₀ (q : k) hn.ne', ← add_div, ← sub_eq_add_neg]
-- Porting note: the `simp` was `push_cast`
simp [m₁]
· congr 2
change (q * ↑n - (↑m₀ : ℤ)) % ↑n = _
rw [sub_eq_add_neg, add_comm (q * ↑n), add_mul_emod_self]
#align int.fract_div_int_cast_eq_div_int_cast_mod Int.fract_div_intCast_eq_div_intCast_mod
end LinearOrderedField
/-! #### Ceil -/
theorem gc_ceil_coe : GaloisConnection ceil ((↑) : ℤ → α) :=
FloorRing.gc_ceil_coe
#align int.gc_ceil_coe Int.gc_ceil_coe
theorem ceil_le : ⌈a⌉ ≤ z ↔ a ≤ z :=
gc_ceil_coe a z
#align int.ceil_le Int.ceil_le
theorem floor_neg : ⌊-a⌋ = -⌈a⌉ :=
eq_of_forall_le_iff fun z => by rw [le_neg, ceil_le, le_floor, Int.cast_neg, le_neg]
#align int.floor_neg Int.floor_neg
theorem ceil_neg : ⌈-a⌉ = -⌊a⌋ :=
eq_of_forall_ge_iff fun z => by rw [neg_le, ceil_le, le_floor, Int.cast_neg, neg_le]
#align int.ceil_neg Int.ceil_neg
theorem lt_ceil : z < ⌈a⌉ ↔ (z : α) < a :=
lt_iff_lt_of_le_iff_le ceil_le
#align int.lt_ceil Int.lt_ceil
@[simp]
theorem add_one_le_ceil_iff : z + 1 ≤ ⌈a⌉ ↔ (z : α) < a := by rw [← lt_ceil, add_one_le_iff]
#align int.add_one_le_ceil_iff Int.add_one_le_ceil_iff
@[simp]
theorem one_le_ceil_iff : 1 ≤ ⌈a⌉ ↔ 0 < a := by
rw [← zero_add (1 : ℤ), add_one_le_ceil_iff, cast_zero]
#align int.one_le_ceil_iff Int.one_le_ceil_iff
theorem ceil_le_floor_add_one (a : α) : ⌈a⌉ ≤ ⌊a⌋ + 1 := by
rw [ceil_le, Int.cast_add, Int.cast_one]
exact (lt_floor_add_one a).le
#align int.ceil_le_floor_add_one Int.ceil_le_floor_add_one
theorem le_ceil (a : α) : a ≤ ⌈a⌉ :=
gc_ceil_coe.le_u_l a
#align int.le_ceil Int.le_ceil
@[simp]
theorem ceil_intCast (z : ℤ) : ⌈(z : α)⌉ = z :=
eq_of_forall_ge_iff fun a => by rw [ceil_le, Int.cast_le]
#align int.ceil_int_cast Int.ceil_intCast
@[simp]
theorem ceil_natCast (n : ℕ) : ⌈(n : α)⌉ = n :=
eq_of_forall_ge_iff fun a => by rw [ceil_le, ← cast_natCast, cast_le]
#align int.ceil_nat_cast Int.ceil_natCast
-- See note [no_index around OfNat.ofNat]
@[simp]
theorem ceil_ofNat (n : ℕ) [n.AtLeastTwo] : ⌈(no_index (OfNat.ofNat n : α))⌉ = n := ceil_natCast n
theorem ceil_mono : Monotone (ceil : α → ℤ) :=
gc_ceil_coe.monotone_l
#align int.ceil_mono Int.ceil_mono
@[gcongr]
theorem ceil_le_ceil : ∀ x y : α, x ≤ y → ⌈x⌉ ≤ ⌈y⌉ := ceil_mono
@[simp]
theorem ceil_add_int (a : α) (z : ℤ) : ⌈a + z⌉ = ⌈a⌉ + z := by
rw [← neg_inj, neg_add', ← floor_neg, ← floor_neg, neg_add', floor_sub_int]
#align int.ceil_add_int Int.ceil_add_int
@[simp]
theorem ceil_add_nat (a : α) (n : ℕ) : ⌈a + n⌉ = ⌈a⌉ + n := by rw [← Int.cast_natCast, ceil_add_int]
#align int.ceil_add_nat Int.ceil_add_nat
@[simp]
theorem ceil_add_one (a : α) : ⌈a + 1⌉ = ⌈a⌉ + 1 := by
-- Porting note: broken `convert ceil_add_int a (1 : ℤ)`
rw [← ceil_add_int a (1 : ℤ), cast_one]
#align int.ceil_add_one Int.ceil_add_one
-- See note [no_index around OfNat.ofNat]
@[simp]
theorem ceil_add_ofNat (a : α) (n : ℕ) [n.AtLeastTwo] :
⌈a + (no_index (OfNat.ofNat n))⌉ = ⌈a⌉ + OfNat.ofNat n :=
ceil_add_nat a n
@[simp]
theorem ceil_sub_int (a : α) (z : ℤ) : ⌈a - z⌉ = ⌈a⌉ - z :=
Eq.trans (by rw [Int.cast_neg, sub_eq_add_neg]) (ceil_add_int _ _)
#align int.ceil_sub_int Int.ceil_sub_int
@[simp]
theorem ceil_sub_nat (a : α) (n : ℕ) : ⌈a - n⌉ = ⌈a⌉ - n := by
convert ceil_sub_int a n using 1
simp
#align int.ceil_sub_nat Int.ceil_sub_nat
@[simp]
theorem ceil_sub_one (a : α) : ⌈a - 1⌉ = ⌈a⌉ - 1 := by
rw [eq_sub_iff_add_eq, ← ceil_add_one, sub_add_cancel]
#align int.ceil_sub_one Int.ceil_sub_one
-- See note [no_index around OfNat.ofNat]
@[simp]
theorem ceil_sub_ofNat (a : α) (n : ℕ) [n.AtLeastTwo] :
⌈a - (no_index (OfNat.ofNat n))⌉ = ⌈a⌉ - OfNat.ofNat n :=
ceil_sub_nat a n
theorem ceil_lt_add_one (a : α) : (⌈a⌉ : α) < a + 1 := by
rw [← lt_ceil, ← Int.cast_one, ceil_add_int]
apply lt_add_one
#align int.ceil_lt_add_one Int.ceil_lt_add_one
theorem ceil_add_le (a b : α) : ⌈a + b⌉ ≤ ⌈a⌉ + ⌈b⌉ := by
rw [ceil_le, Int.cast_add]
exact add_le_add (le_ceil _) (le_ceil _)
#align int.ceil_add_le Int.ceil_add_le
theorem ceil_add_ceil_le (a b : α) : ⌈a⌉ + ⌈b⌉ ≤ ⌈a + b⌉ + 1 := by
rw [← le_sub_iff_add_le, ceil_le, Int.cast_sub, Int.cast_add, Int.cast_one, le_sub_comm]
refine (ceil_lt_add_one _).le.trans ?_
rw [le_sub_iff_add_le', ← add_assoc, add_le_add_iff_right]
exact le_ceil _
#align int.ceil_add_ceil_le Int.ceil_add_ceil_le
@[simp]
theorem ceil_pos : 0 < ⌈a⌉ ↔ 0 < a := by rw [lt_ceil, cast_zero]
#align int.ceil_pos Int.ceil_pos
@[simp]
theorem ceil_zero : ⌈(0 : α)⌉ = 0 := by rw [← cast_zero, ceil_intCast]
#align int.ceil_zero Int.ceil_zero
@[simp]
theorem ceil_one : ⌈(1 : α)⌉ = 1 := by rw [← cast_one, ceil_intCast]
#align int.ceil_one Int.ceil_one
theorem ceil_nonneg (ha : 0 ≤ a) : 0 ≤ ⌈a⌉ := mod_cast ha.trans (le_ceil a)
#align int.ceil_nonneg Int.ceil_nonneg
theorem ceil_eq_iff : ⌈a⌉ = z ↔ ↑z - 1 < a ∧ a ≤ z := by
rw [← ceil_le, ← Int.cast_one, ← Int.cast_sub, ← lt_ceil, Int.sub_one_lt_iff, le_antisymm_iff,
and_comm]
#align int.ceil_eq_iff Int.ceil_eq_iff
@[simp]
theorem ceil_eq_zero_iff : ⌈a⌉ = 0 ↔ a ∈ Ioc (-1 : α) 0 := by simp [ceil_eq_iff]
#align int.ceil_eq_zero_iff Int.ceil_eq_zero_iff
theorem ceil_eq_on_Ioc (z : ℤ) : ∀ a ∈ Set.Ioc (z - 1 : α) z, ⌈a⌉ = z := fun _ ⟨h₀, h₁⟩ =>
ceil_eq_iff.mpr ⟨h₀, h₁⟩
#align int.ceil_eq_on_Ioc Int.ceil_eq_on_Ioc
theorem ceil_eq_on_Ioc' (z : ℤ) : ∀ a ∈ Set.Ioc (z - 1 : α) z, (⌈a⌉ : α) = z := fun a ha =>
mod_cast ceil_eq_on_Ioc z a ha
#align int.ceil_eq_on_Ioc' Int.ceil_eq_on_Ioc'
theorem floor_le_ceil (a : α) : ⌊a⌋ ≤ ⌈a⌉ :=
cast_le.1 <| (floor_le _).trans <| le_ceil _
#align int.floor_le_ceil Int.floor_le_ceil
theorem floor_lt_ceil_of_lt {a b : α} (h : a < b) : ⌊a⌋ < ⌈b⌉ :=
cast_lt.1 <| (floor_le a).trans_lt <| h.trans_le <| le_ceil b
#align int.floor_lt_ceil_of_lt Int.floor_lt_ceil_of_lt
-- Porting note: in mathlib3 there was no need for the type annotation in `(m : α)`
@[simp]
theorem preimage_ceil_singleton (m : ℤ) : (ceil : α → ℤ) ⁻¹' {m} = Ioc ((m : α) - 1) m :=
ext fun _ => ceil_eq_iff
#align int.preimage_ceil_singleton Int.preimage_ceil_singleton
theorem fract_eq_zero_or_add_one_sub_ceil (a : α) : fract a = 0 ∨ fract a = a + 1 - (⌈a⌉ : α) := by
rcases eq_or_ne (fract a) 0 with ha | ha
· exact Or.inl ha
right
suffices (⌈a⌉ : α) = ⌊a⌋ + 1 by
rw [this, ← self_sub_fract]
abel
norm_cast
rw [ceil_eq_iff]
refine ⟨?_, _root_.le_of_lt <| by simp⟩
rw [cast_add, cast_one, add_tsub_cancel_right, ← self_sub_fract a, sub_lt_self_iff]
exact ha.symm.lt_of_le (fract_nonneg a)
#align int.fract_eq_zero_or_add_one_sub_ceil Int.fract_eq_zero_or_add_one_sub_ceil
theorem ceil_eq_add_one_sub_fract (ha : fract a ≠ 0) : (⌈a⌉ : α) = a + 1 - fract a := by
rw [(or_iff_right ha).mp (fract_eq_zero_or_add_one_sub_ceil a)]
abel
#align int.ceil_eq_add_one_sub_fract Int.ceil_eq_add_one_sub_fract
theorem ceil_sub_self_eq (ha : fract a ≠ 0) : (⌈a⌉ : α) - a = 1 - fract a := by
rw [(or_iff_right ha).mp (fract_eq_zero_or_add_one_sub_ceil a)]
abel
#align int.ceil_sub_self_eq Int.ceil_sub_self_eq
/-! #### Intervals -/
@[simp]
theorem preimage_Ioo {a b : α} : ((↑) : ℤ → α) ⁻¹' Set.Ioo a b = Set.Ioo ⌊a⌋ ⌈b⌉ := by
ext
simp [floor_lt, lt_ceil]
#align int.preimage_Ioo Int.preimage_Ioo
@[simp]
theorem preimage_Ico {a b : α} : ((↑) : ℤ → α) ⁻¹' Set.Ico a b = Set.Ico ⌈a⌉ ⌈b⌉ := by
ext
simp [ceil_le, lt_ceil]
#align int.preimage_Ico Int.preimage_Ico
@[simp]
theorem preimage_Ioc {a b : α} : ((↑) : ℤ → α) ⁻¹' Set.Ioc a b = Set.Ioc ⌊a⌋ ⌊b⌋ := by
ext
simp [floor_lt, le_floor]
#align int.preimage_Ioc Int.preimage_Ioc
@[simp]
theorem preimage_Icc {a b : α} : ((↑) : ℤ → α) ⁻¹' Set.Icc a b = Set.Icc ⌈a⌉ ⌊b⌋ := by
ext
simp [ceil_le, le_floor]
#align int.preimage_Icc Int.preimage_Icc
@[simp]
theorem preimage_Ioi : ((↑) : ℤ → α) ⁻¹' Set.Ioi a = Set.Ioi ⌊a⌋ := by
ext
simp [floor_lt]
#align int.preimage_Ioi Int.preimage_Ioi
@[simp]
theorem preimage_Ici : ((↑) : ℤ → α) ⁻¹' Set.Ici a = Set.Ici ⌈a⌉ := by
ext
simp [ceil_le]
#align int.preimage_Ici Int.preimage_Ici
@[simp]
| Mathlib/Algebra/Order/Floor.lean | 1,423 | 1,425 | theorem preimage_Iio : ((↑) : ℤ → α) ⁻¹' Set.Iio a = Set.Iio ⌈a⌉ := by |
ext
simp [lt_ceil]
|
/-
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.Module.Defs
import Mathlib.Algebra.Order.Archimedean
import Mathlib.Algebra.Periodic
import Mathlib.Data.Int.SuccPred
import Mathlib.GroupTheory.QuotientGroup
import Mathlib.Order.Circular
import Mathlib.Data.List.TFAE
import Mathlib.Data.Set.Lattice
#align_import algebra.order.to_interval_mod from "leanprover-community/mathlib"@"213b0cff7bc5ab6696ee07cceec80829ce42efec"
/-!
# 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)`.
-/
noncomputable section
section LinearOrderedAddCommGroup
variable {α : Type*} [LinearOrderedAddCommGroup α] [hα : Archimedean α] {p : α} (hp : 0 < p)
{a b c : α} {n : ℤ}
/--
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
#align to_Ico_div toIcoDiv
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
#align sub_to_Ico_div_zsmul_mem_Ico sub_toIcoDiv_zsmul_mem_Ico
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
#align to_Ico_div_eq_of_sub_zsmul_mem_Ico toIcoDiv_eq_of_sub_zsmul_mem_Ico
/--
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
#align to_Ioc_div toIocDiv
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
#align sub_to_Ioc_div_zsmul_mem_Ioc sub_toIocDiv_zsmul_mem_Ioc
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
#align to_Ioc_div_eq_of_sub_zsmul_mem_Ioc toIocDiv_eq_of_sub_zsmul_mem_Ioc
/-- Reduce `b` to the interval `Ico a (a + p)`. -/
def toIcoMod (a b : α) : α :=
b - toIcoDiv hp a b • p
#align to_Ico_mod toIcoMod
/-- Reduce `b` to the interval `Ioc a (a + p)`. -/
def toIocMod (a b : α) : α :=
b - toIocDiv hp a b • p
#align to_Ioc_mod toIocMod
theorem toIcoMod_mem_Ico (a b : α) : toIcoMod hp a b ∈ Set.Ico a (a + p) :=
sub_toIcoDiv_zsmul_mem_Ico hp a b
#align to_Ico_mod_mem_Ico toIcoMod_mem_Ico
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
#align to_Ico_mod_mem_Ico' toIcoMod_mem_Ico'
theorem toIocMod_mem_Ioc (a b : α) : toIocMod hp a b ∈ Set.Ioc a (a + p) :=
sub_toIocDiv_zsmul_mem_Ioc hp a b
#align to_Ioc_mod_mem_Ioc toIocMod_mem_Ioc
theorem left_le_toIcoMod (a b : α) : a ≤ toIcoMod hp a b :=
(Set.mem_Ico.1 (toIcoMod_mem_Ico hp a b)).1
#align left_le_to_Ico_mod left_le_toIcoMod
theorem left_lt_toIocMod (a b : α) : a < toIocMod hp a b :=
(Set.mem_Ioc.1 (toIocMod_mem_Ioc hp a b)).1
#align left_lt_to_Ioc_mod left_lt_toIocMod
theorem toIcoMod_lt_right (a b : α) : toIcoMod hp a b < a + p :=
(Set.mem_Ico.1 (toIcoMod_mem_Ico hp a b)).2
#align to_Ico_mod_lt_right toIcoMod_lt_right
theorem toIocMod_le_right (a b : α) : toIocMod hp a b ≤ a + p :=
(Set.mem_Ioc.1 (toIocMod_mem_Ioc hp a b)).2
#align to_Ioc_mod_le_right toIocMod_le_right
@[simp]
theorem self_sub_toIcoDiv_zsmul (a b : α) : b - toIcoDiv hp a b • p = toIcoMod hp a b :=
rfl
#align self_sub_to_Ico_div_zsmul self_sub_toIcoDiv_zsmul
@[simp]
theorem self_sub_toIocDiv_zsmul (a b : α) : b - toIocDiv hp a b • p = toIocMod hp a b :=
rfl
#align self_sub_to_Ioc_div_zsmul self_sub_toIocDiv_zsmul
@[simp]
theorem toIcoDiv_zsmul_sub_self (a b : α) : toIcoDiv hp a b • p - b = -toIcoMod hp a b := by
rw [toIcoMod, neg_sub]
#align to_Ico_div_zsmul_sub_self toIcoDiv_zsmul_sub_self
@[simp]
theorem toIocDiv_zsmul_sub_self (a b : α) : toIocDiv hp a b • p - b = -toIocMod hp a b := by
rw [toIocMod, neg_sub]
#align to_Ioc_div_zsmul_sub_self toIocDiv_zsmul_sub_self
@[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]
#align to_Ico_mod_sub_self toIcoMod_sub_self
@[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]
#align to_Ioc_mod_sub_self toIocMod_sub_self
@[simp]
theorem self_sub_toIcoMod (a b : α) : b - toIcoMod hp a b = toIcoDiv hp a b • p := by
rw [toIcoMod, sub_sub_cancel]
#align self_sub_to_Ico_mod self_sub_toIcoMod
@[simp]
theorem self_sub_toIocMod (a b : α) : b - toIocMod hp a b = toIocDiv hp a b • p := by
rw [toIocMod, sub_sub_cancel]
#align self_sub_to_Ioc_mod self_sub_toIocMod
@[simp]
theorem toIcoMod_add_toIcoDiv_zsmul (a b : α) : toIcoMod hp a b + toIcoDiv hp a b • p = b := by
rw [toIcoMod, sub_add_cancel]
#align to_Ico_mod_add_to_Ico_div_zsmul toIcoMod_add_toIcoDiv_zsmul
@[simp]
theorem toIocMod_add_toIocDiv_zsmul (a b : α) : toIocMod hp a b + toIocDiv hp a b • p = b := by
rw [toIocMod, sub_add_cancel]
#align to_Ioc_mod_add_to_Ioc_div_zsmul toIocMod_add_toIocDiv_zsmul
@[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]
#align to_Ico_div_zsmul_sub_to_Ico_mod toIcoDiv_zsmul_sub_toIcoMod
@[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]
#align to_Ioc_div_zsmul_sub_to_Ioc_mod toIocDiv_zsmul_sub_toIocMod
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]
#align to_Ico_mod_eq_iff toIcoMod_eq_iff
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]
#align to_Ioc_mod_eq_iff toIocMod_eq_iff
@[simp]
theorem toIcoDiv_apply_left (a : α) : toIcoDiv hp a a = 0 :=
toIcoDiv_eq_of_sub_zsmul_mem_Ico hp <| by simp [hp]
#align to_Ico_div_apply_left toIcoDiv_apply_left
@[simp]
theorem toIocDiv_apply_left (a : α) : toIocDiv hp a a = -1 :=
toIocDiv_eq_of_sub_zsmul_mem_Ioc hp <| by simp [hp]
#align to_Ioc_div_apply_left toIocDiv_apply_left
@[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⟩
#align to_Ico_mod_apply_left toIcoMod_apply_left
@[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⟩
#align to_Ioc_mod_apply_left toIocMod_apply_left
theorem toIcoDiv_apply_right (a : α) : toIcoDiv hp a (a + p) = 1 :=
toIcoDiv_eq_of_sub_zsmul_mem_Ico hp <| by simp [hp]
#align to_Ico_div_apply_right toIcoDiv_apply_right
theorem toIocDiv_apply_right (a : α) : toIocDiv hp a (a + p) = 0 :=
toIocDiv_eq_of_sub_zsmul_mem_Ioc hp <| by simp [hp]
#align to_Ioc_div_apply_right toIocDiv_apply_right
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⟩
#align to_Ico_mod_apply_right toIcoMod_apply_right
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⟩
#align to_Ioc_mod_apply_right toIocMod_apply_right
@[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
#align to_Ico_div_add_zsmul toIcoDiv_add_zsmul
@[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
#align to_Ico_div_add_zsmul' toIcoDiv_add_zsmul'
@[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
#align to_Ioc_div_add_zsmul toIocDiv_add_zsmul
@[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
#align to_Ioc_div_add_zsmul' toIocDiv_add_zsmul'
@[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]
#align to_Ico_div_zsmul_add toIcoDiv_zsmul_add
/-! 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]
#align to_Ioc_div_zsmul_add toIocDiv_zsmul_add
/-! 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]
#align to_Ico_div_sub_zsmul toIcoDiv_sub_zsmul
@[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]
#align to_Ico_div_sub_zsmul' toIcoDiv_sub_zsmul'
@[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]
#align to_Ioc_div_sub_zsmul toIocDiv_sub_zsmul
@[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]
#align to_Ioc_div_sub_zsmul' toIocDiv_sub_zsmul'
@[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
#align to_Ico_div_add_right toIcoDiv_add_right
@[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
#align to_Ico_div_add_right' toIcoDiv_add_right'
@[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
#align to_Ioc_div_add_right toIocDiv_add_right
@[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
#align to_Ioc_div_add_right' toIocDiv_add_right'
@[simp]
theorem toIcoDiv_add_left (a b : α) : toIcoDiv hp a (p + b) = toIcoDiv hp a b + 1 := by
rw [add_comm, toIcoDiv_add_right]
#align to_Ico_div_add_left toIcoDiv_add_left
@[simp]
theorem toIcoDiv_add_left' (a b : α) : toIcoDiv hp (p + a) b = toIcoDiv hp a b - 1 := by
rw [add_comm, toIcoDiv_add_right']
#align to_Ico_div_add_left' toIcoDiv_add_left'
@[simp]
theorem toIocDiv_add_left (a b : α) : toIocDiv hp a (p + b) = toIocDiv hp a b + 1 := by
rw [add_comm, toIocDiv_add_right]
#align to_Ioc_div_add_left toIocDiv_add_left
@[simp]
theorem toIocDiv_add_left' (a b : α) : toIocDiv hp (p + a) b = toIocDiv hp a b - 1 := by
rw [add_comm, toIocDiv_add_right']
#align to_Ioc_div_add_left' toIocDiv_add_left'
@[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
#align to_Ico_div_sub toIcoDiv_sub
@[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
#align to_Ico_div_sub' toIcoDiv_sub'
@[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
#align to_Ioc_div_sub toIocDiv_sub
@[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
#align to_Ioc_div_sub' toIocDiv_sub'
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
#align to_Ico_div_sub_eq_to_Ico_div_add toIcoDiv_sub_eq_toIcoDiv_add
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
#align to_Ioc_div_sub_eq_to_Ioc_div_add toIocDiv_sub_eq_toIocDiv_add
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]
#align to_Ico_div_sub_eq_to_Ico_div_add' toIcoDiv_sub_eq_toIcoDiv_add'
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]
#align to_Ioc_div_sub_eq_to_Ioc_div_add' toIocDiv_sub_eq_toIocDiv_add'
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]
#align to_Ico_div_neg toIcoDiv_neg
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)
#align to_Ico_div_neg' toIcoDiv_neg'
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]
#align to_Ioc_div_neg toIocDiv_neg
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)
#align to_Ioc_div_neg' toIocDiv_neg'
@[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
#align to_Ico_mod_add_zsmul toIcoMod_add_zsmul
@[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]
#align to_Ico_mod_add_zsmul' toIcoMod_add_zsmul'
@[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
#align to_Ioc_mod_add_zsmul toIocMod_add_zsmul
@[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]
#align to_Ioc_mod_add_zsmul' toIocMod_add_zsmul'
@[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]
#align to_Ico_mod_zsmul_add toIcoMod_zsmul_add
@[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]
#align to_Ico_mod_zsmul_add' toIcoMod_zsmul_add'
@[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]
#align to_Ioc_mod_zsmul_add toIocMod_zsmul_add
@[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]
#align to_Ioc_mod_zsmul_add' toIocMod_zsmul_add'
@[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]
#align to_Ico_mod_sub_zsmul toIcoMod_sub_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']
#align to_Ico_mod_sub_zsmul' toIcoMod_sub_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]
#align to_Ioc_mod_sub_zsmul toIocMod_sub_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']
#align to_Ioc_mod_sub_zsmul' toIocMod_sub_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
#align to_Ico_mod_add_right toIcoMod_add_right
@[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
#align to_Ico_mod_add_right' toIcoMod_add_right'
@[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
#align to_Ioc_mod_add_right toIocMod_add_right
@[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
#align to_Ioc_mod_add_right' toIocMod_add_right'
@[simp]
theorem toIcoMod_add_left (a b : α) : toIcoMod hp a (p + b) = toIcoMod hp a b := by
rw [add_comm, toIcoMod_add_right]
#align to_Ico_mod_add_left toIcoMod_add_left
@[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]
#align to_Ico_mod_add_left' toIcoMod_add_left'
@[simp]
theorem toIocMod_add_left (a b : α) : toIocMod hp a (p + b) = toIocMod hp a b := by
rw [add_comm, toIocMod_add_right]
#align to_Ioc_mod_add_left toIocMod_add_left
@[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]
#align to_Ioc_mod_add_left' toIocMod_add_left'
@[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
#align to_Ico_mod_sub toIcoMod_sub
@[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
#align to_Ico_mod_sub' toIcoMod_sub'
@[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
#align to_Ioc_mod_sub toIocMod_sub
@[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
#align to_Ioc_mod_sub' toIocMod_sub'
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]
#align to_Ico_mod_sub_eq_sub toIcoMod_sub_eq_sub
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]
#align to_Ioc_mod_sub_eq_sub toIocMod_sub_eq_sub
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]
#align to_Ico_mod_add_right_eq_add toIcoMod_add_right_eq_add
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]
#align to_Ioc_mod_add_right_eq_add toIocMod_add_right_eq_add
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
#align to_Ico_mod_neg toIcoMod_neg
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)
#align to_Ico_mod_neg' toIcoMod_neg'
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
#align to_Ioc_mod_neg toIocMod_neg
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)
#align to_Ioc_mod_neg' toIocMod_neg'
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]
#align to_Ico_mod_eq_to_Ico_mod toIcoMod_eq_toIcoMod
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]
#align to_Ioc_mod_eq_to_Ioc_mod toIocMod_eq_toIocMod
/-! ### 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⟩⟩
#align add_comm_group.modeq_iff_to_Ico_mod_eq_left AddCommGroup.modEq_iff_toIcoMod_eq_left
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']
#align add_comm_group.modeq_iff_to_Ioc_mod_eq_right AddCommGroup.modEq_iff_toIocMod_eq_right
alias ⟨ModEq.toIcoMod_eq_left, _⟩ := modEq_iff_toIcoMod_eq_left
#align add_comm_group.modeq.to_Ico_mod_eq_left AddCommGroup.ModEq.toIcoMod_eq_left
alias ⟨ModEq.toIcoMod_eq_right, _⟩ := modEq_iff_toIocMod_eq_right
#align add_comm_group.modeq.to_Ico_mod_eq_right AddCommGroup.ModEq.toIcoMod_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
· 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
· intro h
rw [← h, Ne, eq_comm, add_right_eq_self]
exact hp.ne'
tfae_have 1 → 4
· intro h
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_right_neg, add_zero]
conv_lhs => rw [← toIcoMod_add_toIcoDiv_zsmul hp a b, h]
tfae_have 2 → 1
· 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
#align add_comm_group.tfae_modeq AddCommGroup.tfae_modEq
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
#align add_comm_group.modeq_iff_not_forall_mem_Ioo_mod AddCommGroup.modEq_iff_not_forall_mem_Ioo_mod
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
#align add_comm_group.modeq_iff_to_Ico_mod_ne_to_Ioc_mod AddCommGroup.modEq_iff_toIcoMod_ne_toIocMod
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
#align add_comm_group.modeq_iff_to_Ico_mod_add_period_eq_to_Ioc_mod AddCommGroup.modEq_iff_toIcoMod_add_period_eq_toIocMod
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
#align add_comm_group.not_modeq_iff_to_Ico_mod_eq_to_Ioc_mod AddCommGroup.not_modEq_iff_toIcoMod_eq_toIocMod
theorem not_modEq_iff_toIcoDiv_eq_toIocDiv :
¬a ≡ b [PMOD p] ↔ toIcoDiv hp a b = toIocDiv hp a b := by
rw [not_modEq_iff_toIcoMod_eq_toIocMod hp, toIcoMod, toIocMod, sub_right_inj,
(zsmul_strictMono_left hp).injective.eq_iff]
#align add_comm_group.not_modeq_iff_to_Ico_div_eq_to_Ioc_div AddCommGroup.not_modEq_iff_toIcoDiv_eq_toIocDiv
theorem modEq_iff_toIcoDiv_eq_toIocDiv_add_one :
a ≡ b [PMOD p] ↔ toIcoDiv hp a b = toIocDiv hp a b + 1 := by
rw [modEq_iff_toIcoMod_add_period_eq_toIocMod hp, toIcoMod, toIocMod, ← eq_sub_iff_add_eq,
sub_sub, sub_right_inj, ← add_one_zsmul, (zsmul_strictMono_left hp).injective.eq_iff]
#align add_comm_group.modeq_iff_to_Ico_div_eq_to_Ioc_div_add_one AddCommGroup.modEq_iff_toIcoDiv_eq_toIocDiv_add_one
end AddCommGroup
open AddCommGroup
/-- If `a` and `b` fall within the same cycle WRT `c`, then they are congruent modulo `p`. -/
@[simp]
theorem toIcoMod_inj {c : α} : toIcoMod hp c a = toIcoMod hp c b ↔ a ≡ b [PMOD p] := by
simp_rw [toIcoMod_eq_toIcoMod, modEq_iff_eq_add_zsmul, sub_eq_iff_eq_add']
#align to_Ico_mod_inj toIcoMod_inj
alias ⟨_, AddCommGroup.ModEq.toIcoMod_eq_toIcoMod⟩ := toIcoMod_inj
#align add_comm_group.modeq.to_Ico_mod_eq_to_Ico_mod AddCommGroup.ModEq.toIcoMod_eq_toIcoMod
theorem Ico_eq_locus_Ioc_eq_iUnion_Ioo :
{ b | toIcoMod hp a b = toIocMod hp a b } = ⋃ z : ℤ, Set.Ioo (a + z • p) (a + p + z • p) := by
ext1;
simp_rw [Set.mem_setOf, Set.mem_iUnion, ← Set.sub_mem_Ioo_iff_left, ←
not_modEq_iff_toIcoMod_eq_toIocMod, modEq_iff_not_forall_mem_Ioo_mod hp, not_forall,
Classical.not_not]
#align Ico_eq_locus_Ioc_eq_Union_Ioo Ico_eq_locus_Ioc_eq_iUnion_Ioo
theorem toIocDiv_wcovBy_toIcoDiv (a b : α) : toIocDiv hp a b ⩿ toIcoDiv hp a b := by
suffices toIocDiv hp a b = toIcoDiv hp a b ∨ toIocDiv hp a b + 1 = toIcoDiv hp a b by
rwa [wcovBy_iff_eq_or_covBy, ← Order.succ_eq_iff_covBy]
rw [eq_comm, ← not_modEq_iff_toIcoDiv_eq_toIocDiv, eq_comm, ←
modEq_iff_toIcoDiv_eq_toIocDiv_add_one]
exact em' _
#align to_Ioc_div_wcovby_to_Ico_div toIocDiv_wcovBy_toIcoDiv
theorem toIcoMod_le_toIocMod (a b : α) : toIcoMod hp a b ≤ toIocMod hp a b := by
rw [toIcoMod, toIocMod, sub_le_sub_iff_left]
exact zsmul_mono_left hp.le (toIocDiv_wcovBy_toIcoDiv _ _ _).le
#align to_Ico_mod_le_to_Ioc_mod toIcoMod_le_toIocMod
theorem toIocMod_le_toIcoMod_add (a b : α) : toIocMod hp a b ≤ toIcoMod hp a b + p := by
rw [toIcoMod, toIocMod, sub_add, sub_le_sub_iff_left, sub_le_iff_le_add, ← add_one_zsmul,
(zsmul_strictMono_left hp).le_iff_le]
apply (toIocDiv_wcovBy_toIcoDiv _ _ _).le_succ
#align to_Ioc_mod_le_to_Ico_mod_add toIocMod_le_toIcoMod_add
end IcoIoc
open AddCommGroup
theorem toIcoMod_eq_self : toIcoMod hp a b = b ↔ b ∈ Set.Ico a (a + p) := by
rw [toIcoMod_eq_iff, and_iff_left]
exact ⟨0, by simp⟩
#align to_Ico_mod_eq_self toIcoMod_eq_self
theorem toIocMod_eq_self : toIocMod hp a b = b ↔ b ∈ Set.Ioc a (a + p) := by
rw [toIocMod_eq_iff, and_iff_left]
exact ⟨0, by simp⟩
#align to_Ioc_mod_eq_self toIocMod_eq_self
@[simp]
theorem toIcoMod_toIcoMod (a₁ a₂ b : α) : toIcoMod hp a₁ (toIcoMod hp a₂ b) = toIcoMod hp a₁ b :=
(toIcoMod_eq_toIcoMod _).2 ⟨toIcoDiv hp a₂ b, self_sub_toIcoMod hp a₂ b⟩
#align to_Ico_mod_to_Ico_mod toIcoMod_toIcoMod
@[simp]
theorem toIcoMod_toIocMod (a₁ a₂ b : α) : toIcoMod hp a₁ (toIocMod hp a₂ b) = toIcoMod hp a₁ b :=
(toIcoMod_eq_toIcoMod _).2 ⟨toIocDiv hp a₂ b, self_sub_toIocMod hp a₂ b⟩
#align to_Ico_mod_to_Ioc_mod toIcoMod_toIocMod
@[simp]
theorem toIocMod_toIocMod (a₁ a₂ b : α) : toIocMod hp a₁ (toIocMod hp a₂ b) = toIocMod hp a₁ b :=
(toIocMod_eq_toIocMod _).2 ⟨toIocDiv hp a₂ b, self_sub_toIocMod hp a₂ b⟩
#align to_Ioc_mod_to_Ioc_mod toIocMod_toIocMod
@[simp]
theorem toIocMod_toIcoMod (a₁ a₂ b : α) : toIocMod hp a₁ (toIcoMod hp a₂ b) = toIocMod hp a₁ b :=
(toIocMod_eq_toIocMod _).2 ⟨toIcoDiv hp a₂ b, self_sub_toIcoMod hp a₂ b⟩
#align to_Ioc_mod_to_Ico_mod toIocMod_toIcoMod
theorem toIcoMod_periodic (a : α) : Function.Periodic (toIcoMod hp a) p :=
toIcoMod_add_right hp a
#align to_Ico_mod_periodic toIcoMod_periodic
theorem toIocMod_periodic (a : α) : Function.Periodic (toIocMod hp a) p :=
toIocMod_add_right hp a
#align to_Ioc_mod_periodic toIocMod_periodic
-- helper lemmas for when `a = 0`
section Zero
theorem toIcoMod_zero_sub_comm (a b : α) : toIcoMod hp 0 (a - b) = p - toIocMod hp 0 (b - a) := by
rw [← neg_sub, toIcoMod_neg, neg_zero]
#align to_Ico_mod_zero_sub_comm toIcoMod_zero_sub_comm
theorem toIocMod_zero_sub_comm (a b : α) : toIocMod hp 0 (a - b) = p - toIcoMod hp 0 (b - a) := by
rw [← neg_sub, toIocMod_neg, neg_zero]
#align to_Ioc_mod_zero_sub_comm toIocMod_zero_sub_comm
theorem toIcoDiv_eq_sub (a b : α) : toIcoDiv hp a b = toIcoDiv hp 0 (b - a) := by
rw [toIcoDiv_sub_eq_toIcoDiv_add, zero_add]
#align to_Ico_div_eq_sub toIcoDiv_eq_sub
theorem toIocDiv_eq_sub (a b : α) : toIocDiv hp a b = toIocDiv hp 0 (b - a) := by
rw [toIocDiv_sub_eq_toIocDiv_add, zero_add]
#align to_Ioc_div_eq_sub toIocDiv_eq_sub
theorem toIcoMod_eq_sub (a b : α) : toIcoMod hp a b = toIcoMod hp 0 (b - a) + a := by
rw [toIcoMod_sub_eq_sub, zero_add, sub_add_cancel]
#align to_Ico_mod_eq_sub toIcoMod_eq_sub
theorem toIocMod_eq_sub (a b : α) : toIocMod hp a b = toIocMod hp 0 (b - a) + a := by
rw [toIocMod_sub_eq_sub, zero_add, sub_add_cancel]
#align to_Ioc_mod_eq_sub toIocMod_eq_sub
theorem toIcoMod_add_toIocMod_zero (a b : α) :
toIcoMod hp 0 (a - b) + toIocMod hp 0 (b - a) = p := by
rw [toIcoMod_zero_sub_comm, sub_add_cancel]
#align to_Ico_mod_add_to_Ioc_mod_zero toIcoMod_add_toIocMod_zero
theorem toIocMod_add_toIcoMod_zero (a b : α) :
toIocMod hp 0 (a - b) + toIcoMod hp 0 (b - a) = p := by
rw [_root_.add_comm, toIcoMod_add_toIocMod_zero]
#align to_Ioc_mod_add_to_Ico_mod_zero toIocMod_add_toIcoMod_zero
end Zero
/-- `toIcoMod` as an equiv from the quotient. -/
@[simps symm_apply]
def QuotientAddGroup.equivIcoMod (a : α) : α ⧸ AddSubgroup.zmultiples p ≃ Set.Ico a (a + p) where
toFun b :=
⟨(toIcoMod_periodic hp a).lift b, QuotientAddGroup.induction_on' b <| toIcoMod_mem_Ico hp a⟩
invFun := (↑)
right_inv b := Subtype.ext <| (toIcoMod_eq_self hp).mpr b.prop
left_inv b := by
induction b using QuotientAddGroup.induction_on'
dsimp
rw [QuotientAddGroup.eq_iff_sub_mem, toIcoMod_sub_self]
apply AddSubgroup.zsmul_mem_zmultiples
#align quotient_add_group.equiv_Ico_mod QuotientAddGroup.equivIcoMod
@[simp]
theorem QuotientAddGroup.equivIcoMod_coe (a b : α) :
QuotientAddGroup.equivIcoMod hp a ↑b = ⟨toIcoMod hp a b, toIcoMod_mem_Ico hp a _⟩ :=
rfl
#align quotient_add_group.equiv_Ico_mod_coe QuotientAddGroup.equivIcoMod_coe
@[simp]
theorem QuotientAddGroup.equivIcoMod_zero (a : α) :
QuotientAddGroup.equivIcoMod hp a 0 = ⟨toIcoMod hp a 0, toIcoMod_mem_Ico hp a _⟩ :=
rfl
#align quotient_add_group.equiv_Ico_mod_zero QuotientAddGroup.equivIcoMod_zero
/-- `toIocMod` as an equiv from the quotient. -/
@[simps symm_apply]
def QuotientAddGroup.equivIocMod (a : α) : α ⧸ AddSubgroup.zmultiples p ≃ Set.Ioc a (a + p) where
toFun b :=
⟨(toIocMod_periodic hp a).lift b, QuotientAddGroup.induction_on' b <| toIocMod_mem_Ioc hp a⟩
invFun := (↑)
right_inv b := Subtype.ext <| (toIocMod_eq_self hp).mpr b.prop
left_inv b := by
induction b using QuotientAddGroup.induction_on'
dsimp
rw [QuotientAddGroup.eq_iff_sub_mem, toIocMod_sub_self]
apply AddSubgroup.zsmul_mem_zmultiples
#align quotient_add_group.equiv_Ioc_mod QuotientAddGroup.equivIocMod
@[simp]
theorem QuotientAddGroup.equivIocMod_coe (a b : α) :
QuotientAddGroup.equivIocMod hp a ↑b = ⟨toIocMod hp a b, toIocMod_mem_Ioc hp a _⟩ :=
rfl
#align quotient_add_group.equiv_Ioc_mod_coe QuotientAddGroup.equivIocMod_coe
@[simp]
theorem QuotientAddGroup.equivIocMod_zero (a : α) :
QuotientAddGroup.equivIocMod hp a 0 = ⟨toIocMod hp a 0, toIocMod_mem_Ioc hp a _⟩ :=
rfl
#align quotient_add_group.equiv_Ioc_mod_zero QuotientAddGroup.equivIocMod_zero
/-!
### The circular order structure on `α ⧸ AddSubgroup.zmultiples p`
-/
section Circular
private theorem toIxxMod_iff (x₁ x₂ x₃ : α) : toIcoMod hp x₁ x₂ ≤ toIocMod hp x₁ x₃ ↔
toIcoMod hp 0 (x₂ - x₁) + toIcoMod hp 0 (x₁ - x₃) ≤ p := by
rw [toIcoMod_eq_sub, toIocMod_eq_sub _ x₁, add_le_add_iff_right, ← neg_sub x₁ x₃, toIocMod_neg,
neg_zero, le_sub_iff_add_le]
private theorem toIxxMod_cyclic_left {x₁ x₂ x₃ : α} (h : toIcoMod hp x₁ x₂ ≤ toIocMod hp x₁ x₃) :
toIcoMod hp x₂ x₃ ≤ toIocMod hp x₂ x₁ := by
let x₂' := toIcoMod hp x₁ x₂
let x₃' := toIcoMod hp x₂' x₃
have h : x₂' ≤ toIocMod hp x₁ x₃' := by simpa [x₃']
have h₂₁ : x₂' < x₁ + p := toIcoMod_lt_right _ _ _
have h₃₂ : x₃' - p < x₂' := sub_lt_iff_lt_add.2 (toIcoMod_lt_right _ _ _)
suffices hequiv : x₃' ≤ toIocMod hp x₂' x₁ by
obtain ⟨z, hd⟩ : ∃ z : ℤ, x₂ = x₂' + z • p := ((toIcoMod_eq_iff hp).1 rfl).2
rw [hd, toIocMod_add_zsmul', toIcoMod_add_zsmul', add_le_add_iff_right]
assumption -- Porting note: was `simpa`
rcases le_or_lt x₃' (x₁ + p) with h₃₁ | h₁₃
· suffices hIoc₂₁ : toIocMod hp x₂' x₁ = x₁ + p from hIoc₂₁.symm.trans_ge h₃₁
apply (toIocMod_eq_iff hp).2
exact ⟨⟨h₂₁, by simp [x₂', left_le_toIcoMod]⟩, -1, by simp⟩
have hIoc₁₃ : toIocMod hp x₁ x₃' = x₃' - p := by
apply (toIocMod_eq_iff hp).2
exact ⟨⟨lt_sub_iff_add_lt.2 h₁₃, le_of_lt (h₃₂.trans h₂₁)⟩, 1, by simp⟩
have not_h₃₂ := (h.trans hIoc₁₃.le).not_lt
contradiction
private theorem toIxxMod_antisymm (h₁₂₃ : toIcoMod hp a b ≤ toIocMod hp a c)
(h₁₃₂ : toIcoMod hp a c ≤ toIocMod hp a b) :
b ≡ a [PMOD p] ∨ c ≡ b [PMOD p] ∨ a ≡ c [PMOD p] := by
by_contra! h
rw [modEq_comm] at h
rw [← (not_modEq_iff_toIcoMod_eq_toIocMod hp).mp h.2.2] at h₁₂₃
rw [← (not_modEq_iff_toIcoMod_eq_toIocMod hp).mp h.1] at h₁₃₂
exact h.2.1 ((toIcoMod_inj _).1 <| h₁₃₂.antisymm h₁₂₃)
private theorem toIxxMod_total' (a b c : α) :
toIcoMod hp b a ≤ toIocMod hp b c ∨ toIcoMod hp b c ≤ toIocMod hp b a := by
/- an essential ingredient is the lemma saying {a-b} + {b-a} = period if a ≠ b (and = 0 if a = b).
Thus if a ≠ b and b ≠ c then ({a-b} + {b-c}) + ({c-b} + {b-a}) = 2 * period, so one of
`{a-b} + {b-c}` and `{c-b} + {b-a}` must be `≤ period` -/
have := congr_arg₂ (· + ·) (toIcoMod_add_toIocMod_zero hp a b) (toIcoMod_add_toIocMod_zero hp c b)
simp only [add_add_add_comm] at this -- Porting note (#10691): Was `rw`
rw [_root_.add_comm (toIocMod _ _ _), add_add_add_comm, ← two_nsmul] at this
replace := min_le_of_add_le_two_nsmul this.le
rw [min_le_iff] at this
rw [toIxxMod_iff, toIxxMod_iff]
refine this.imp (le_trans <| add_le_add_left ?_ _) (le_trans <| add_le_add_left ?_ _)
· apply toIcoMod_le_toIocMod
· apply toIcoMod_le_toIocMod
private theorem toIxxMod_total (a b c : α) :
toIcoMod hp a b ≤ toIocMod hp a c ∨ toIcoMod hp c b ≤ toIocMod hp c a :=
(toIxxMod_total' _ _ _ _).imp_right <| toIxxMod_cyclic_left _
private theorem toIxxMod_trans {x₁ x₂ x₃ x₄ : α}
(h₁₂₃ : toIcoMod hp x₁ x₂ ≤ toIocMod hp x₁ x₃ ∧ ¬toIcoMod hp x₃ x₂ ≤ toIocMod hp x₃ x₁)
(h₂₃₄ : toIcoMod hp x₂ x₄ ≤ toIocMod hp x₂ x₃ ∧ ¬toIcoMod hp x₃ x₄ ≤ toIocMod hp x₃ x₂) :
toIcoMod hp x₁ x₄ ≤ toIocMod hp x₁ x₃ ∧ ¬toIcoMod hp x₃ x₄ ≤ toIocMod hp x₃ x₁ := by
constructor
· suffices h : ¬x₃ ≡ x₂ [PMOD p] by
have h₁₂₃' := toIxxMod_cyclic_left _ (toIxxMod_cyclic_left _ h₁₂₃.1)
have h₂₃₄' := toIxxMod_cyclic_left _ (toIxxMod_cyclic_left _ h₂₃₄.1)
rw [(not_modEq_iff_toIcoMod_eq_toIocMod hp).1 h] at h₂₃₄'
exact toIxxMod_cyclic_left _ (h₁₂₃'.trans h₂₃₄')
by_contra h
rw [(modEq_iff_toIcoMod_eq_left hp).1 h] at h₁₂₃
exact h₁₂₃.2 (left_lt_toIocMod _ _ _).le
· rw [not_le] at h₁₂₃ h₂₃₄ ⊢
exact (h₁₂₃.2.trans_le (toIcoMod_le_toIocMod _ x₃ x₂)).trans h₂₃₄.2
namespace QuotientAddGroup
variable [hp' : Fact (0 < p)]
instance : Btw (α ⧸ AddSubgroup.zmultiples p) where
btw x₁ x₂ x₃ := (equivIcoMod hp'.out 0 (x₂ - x₁) : α) ≤ equivIocMod hp'.out 0 (x₃ - x₁)
theorem btw_coe_iff' {x₁ x₂ x₃ : α} :
Btw.btw (x₁ : α ⧸ AddSubgroup.zmultiples p) x₂ x₃ ↔
toIcoMod hp'.out 0 (x₂ - x₁) ≤ toIocMod hp'.out 0 (x₃ - x₁) :=
Iff.rfl
#align quotient_add_group.btw_coe_iff' QuotientAddGroup.btw_coe_iff'
-- maybe harder to use than the primed one?
theorem btw_coe_iff {x₁ x₂ x₃ : α} :
Btw.btw (x₁ : α ⧸ AddSubgroup.zmultiples p) x₂ x₃ ↔
toIcoMod hp'.out x₁ x₂ ≤ toIocMod hp'.out x₁ x₃ := by
rw [btw_coe_iff', toIocMod_sub_eq_sub, toIcoMod_sub_eq_sub, zero_add, sub_le_sub_iff_right]
#align quotient_add_group.btw_coe_iff QuotientAddGroup.btw_coe_iff
instance circularPreorder : CircularPreorder (α ⧸ AddSubgroup.zmultiples p) where
btw_refl x := show _ ≤ _ by simp [sub_self, hp'.out.le]
btw_cyclic_left {x₁ x₂ x₃} h := by
induction x₁ using QuotientAddGroup.induction_on'
induction x₂ using QuotientAddGroup.induction_on'
induction x₃ using QuotientAddGroup.induction_on'
simp_rw [btw_coe_iff] at h ⊢
apply toIxxMod_cyclic_left _ h
sbtw := _
sbtw_iff_btw_not_btw := Iff.rfl
sbtw_trans_left {x₁ x₂ x₃ x₄} (h₁₂₃ : _ ∧ _) (h₂₃₄ : _ ∧ _) :=
show _ ∧ _ by
induction x₁ using QuotientAddGroup.induction_on'
induction x₂ using QuotientAddGroup.induction_on'
induction x₃ using QuotientAddGroup.induction_on'
induction x₄ using QuotientAddGroup.induction_on'
simp_rw [btw_coe_iff] at h₁₂₃ h₂₃₄ ⊢
apply toIxxMod_trans _ h₁₂₃ h₂₃₄
#align quotient_add_group.circular_preorder QuotientAddGroup.circularPreorder
instance circularOrder : CircularOrder (α ⧸ AddSubgroup.zmultiples p) :=
{ QuotientAddGroup.circularPreorder with
btw_antisymm := fun {x₁ x₂ x₃} h₁₂₃ h₃₂₁ => by
induction x₁ using QuotientAddGroup.induction_on'
induction x₂ using QuotientAddGroup.induction_on'
induction x₃ using QuotientAddGroup.induction_on'
rw [btw_cyclic] at h₃₂₁
simp_rw [btw_coe_iff] at h₁₂₃ h₃₂₁
simp_rw [← modEq_iff_eq_mod_zmultiples]
exact toIxxMod_antisymm _ h₁₂₃ h₃₂₁
btw_total := fun x₁ x₂ x₃ => by
induction x₁ using QuotientAddGroup.induction_on'
induction x₂ using QuotientAddGroup.induction_on'
induction x₃ using QuotientAddGroup.induction_on'
simp_rw [btw_coe_iff]
apply toIxxMod_total }
#align quotient_add_group.circular_order QuotientAddGroup.circularOrder
end QuotientAddGroup
end Circular
end LinearOrderedAddCommGroup
/-!
### Connections to `Int.floor` and `Int.fract`
-/
section LinearOrderedField
variable {α : Type*} [LinearOrderedField α] [FloorRing α] {p : α} (hp : 0 < p)
theorem toIcoDiv_eq_floor (a b : α) : toIcoDiv hp a b = ⌊(b - a) / p⌋ := by
refine toIcoDiv_eq_of_sub_zsmul_mem_Ico hp ?_
rw [Set.mem_Ico, zsmul_eq_mul, ← sub_nonneg, add_comm, sub_right_comm, ← sub_lt_iff_lt_add,
sub_right_comm _ _ a]
exact ⟨Int.sub_floor_div_mul_nonneg _ hp, Int.sub_floor_div_mul_lt _ hp⟩
#align to_Ico_div_eq_floor toIcoDiv_eq_floor
theorem toIocDiv_eq_neg_floor (a b : α) : toIocDiv hp a b = -⌊(a + p - b) / p⌋ := by
refine toIocDiv_eq_of_sub_zsmul_mem_Ioc hp ?_
rw [Set.mem_Ioc, zsmul_eq_mul, Int.cast_neg, neg_mul, sub_neg_eq_add, ← sub_nonneg,
sub_add_eq_sub_sub]
refine ⟨?_, Int.sub_floor_div_mul_nonneg _ hp⟩
rw [← add_lt_add_iff_right p, add_assoc, add_comm b, ← sub_lt_iff_lt_add, add_comm (_ * _), ←
sub_lt_iff_lt_add]
exact Int.sub_floor_div_mul_lt _ hp
#align to_Ioc_div_eq_neg_floor toIocDiv_eq_neg_floor
theorem toIcoDiv_zero_one (b : α) : toIcoDiv (zero_lt_one' α) 0 b = ⌊b⌋ := by
simp [toIcoDiv_eq_floor]
#align to_Ico_div_zero_one toIcoDiv_zero_one
theorem toIcoMod_eq_add_fract_mul (a b : α) :
toIcoMod hp a b = a + Int.fract ((b - a) / p) * p := by
rw [toIcoMod, toIcoDiv_eq_floor, Int.fract]
field_simp
ring
#align to_Ico_mod_eq_add_fract_mul toIcoMod_eq_add_fract_mul
theorem toIcoMod_eq_fract_mul (b : α) : toIcoMod hp 0 b = Int.fract (b / p) * p := by
simp [toIcoMod_eq_add_fract_mul]
#align to_Ico_mod_eq_fract_mul toIcoMod_eq_fract_mul
theorem toIocMod_eq_sub_fract_mul (a b : α) :
toIocMod hp a b = a + p - Int.fract ((a + p - b) / p) * p := by
rw [toIocMod, toIocDiv_eq_neg_floor, Int.fract]
field_simp
ring
#align to_Ioc_mod_eq_sub_fract_mul toIocMod_eq_sub_fract_mul
theorem toIcoMod_zero_one (b : α) : toIcoMod (zero_lt_one' α) 0 b = Int.fract b := by
simp [toIcoMod_eq_add_fract_mul]
#align to_Ico_mod_zero_one toIcoMod_zero_one
end LinearOrderedField
/-! ### Lemmas about unions of translates of intervals -/
section Union
open Set Int
section LinearOrderedAddCommGroup
variable {α : Type*} [LinearOrderedAddCommGroup α] [Archimedean α] {p : α} (hp : 0 < p) (a : α)
theorem iUnion_Ioc_add_zsmul : ⋃ n : ℤ, Ioc (a + n • p) (a + (n + 1) • p) = univ := by
refine eq_univ_iff_forall.mpr fun b => mem_iUnion.mpr ?_
rcases sub_toIocDiv_zsmul_mem_Ioc hp a b with ⟨hl, hr⟩
refine ⟨toIocDiv hp a b, ⟨lt_sub_iff_add_lt.mp hl, ?_⟩⟩
rw [add_smul, one_smul, ← add_assoc]
convert sub_le_iff_le_add.mp hr using 1; abel
#align Union_Ioc_add_zsmul iUnion_Ioc_add_zsmul
theorem iUnion_Ico_add_zsmul : ⋃ n : ℤ, Ico (a + n • p) (a + (n + 1) • p) = univ := by
refine eq_univ_iff_forall.mpr fun b => mem_iUnion.mpr ?_
rcases sub_toIcoDiv_zsmul_mem_Ico hp a b with ⟨hl, hr⟩
refine ⟨toIcoDiv hp a b, ⟨le_sub_iff_add_le.mp hl, ?_⟩⟩
rw [add_smul, one_smul, ← add_assoc]
convert sub_lt_iff_lt_add.mp hr using 1; abel
#align Union_Ico_add_zsmul iUnion_Ico_add_zsmul
theorem iUnion_Icc_add_zsmul : ⋃ n : ℤ, Icc (a + n • p) (a + (n + 1) • p) = univ := by
simpa only [iUnion_Ioc_add_zsmul hp a, univ_subset_iff] using
iUnion_mono fun n : ℤ => (Ioc_subset_Icc_self : Ioc (a + n • p) (a + (n + 1) • p) ⊆ Icc _ _)
#align Union_Icc_add_zsmul iUnion_Icc_add_zsmul
theorem iUnion_Ioc_zsmul : ⋃ n : ℤ, Ioc (n • p) ((n + 1) • p) = univ := by
simpa only [zero_add] using iUnion_Ioc_add_zsmul hp 0
#align Union_Ioc_zsmul iUnion_Ioc_zsmul
theorem iUnion_Ico_zsmul : ⋃ n : ℤ, Ico (n • p) ((n + 1) • p) = univ := by
simpa only [zero_add] using iUnion_Ico_add_zsmul hp 0
#align Union_Ico_zsmul iUnion_Ico_zsmul
theorem iUnion_Icc_zsmul : ⋃ n : ℤ, Icc (n • p) ((n + 1) • p) = univ := by
simpa only [zero_add] using iUnion_Icc_add_zsmul hp 0
#align Union_Icc_zsmul iUnion_Icc_zsmul
end LinearOrderedAddCommGroup
section LinearOrderedRing
variable {α : Type*} [LinearOrderedRing α] [Archimedean α] (a : α)
theorem iUnion_Ioc_add_intCast : ⋃ n : ℤ, Ioc (a + n) (a + n + 1) = Set.univ := by
simpa only [zsmul_one, Int.cast_add, Int.cast_one, ← add_assoc] using
iUnion_Ioc_add_zsmul zero_lt_one a
#align Union_Ioc_add_int_cast iUnion_Ioc_add_intCast
@[deprecated (since := "2024-04-17")]
alias iUnion_Ioc_add_int_cast := iUnion_Ioc_add_intCast
theorem iUnion_Ico_add_intCast : ⋃ n : ℤ, Ico (a + n) (a + n + 1) = Set.univ := by
simpa only [zsmul_one, Int.cast_add, Int.cast_one, ← add_assoc] using
iUnion_Ico_add_zsmul zero_lt_one a
#align Union_Ico_add_int_cast iUnion_Ico_add_intCast
@[deprecated (since := "2024-04-17")]
alias iUnion_Ico_add_int_cast := iUnion_Ico_add_intCast
| Mathlib/Algebra/Order/ToIntervalMod.lean | 1,113 | 1,115 | theorem iUnion_Icc_add_intCast : ⋃ n : ℤ, Icc (a + n) (a + n + 1) = Set.univ := by |
simpa only [zsmul_one, Int.cast_add, Int.cast_one, ← add_assoc] using
iUnion_Icc_add_zsmul zero_lt_one a
|
/-
Copyright (c) 2022 Heather Macbeth. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Heather Macbeth
-/
import Mathlib.Analysis.InnerProductSpace.Dual
import Mathlib.Analysis.InnerProductSpace.Orientation
import Mathlib.Data.Complex.Orientation
import Mathlib.Tactic.LinearCombination
#align_import analysis.inner_product_space.two_dim from "leanprover-community/mathlib"@"cd8fafa2fac98e1a67097e8a91ad9901cfde48af"
/-!
# Oriented two-dimensional real inner product spaces
This file defines constructions specific to the geometry of an oriented two-dimensional real inner
product space `E`.
## Main declarations
* `Orientation.areaForm`: an antisymmetric bilinear form `E →ₗ[ℝ] E →ₗ[ℝ] ℝ` (usual notation `ω`).
Morally, when `ω` is evaluated on two vectors, it gives the oriented area of the parallelogram
they span. (But mathlib does not yet have a construction of oriented area, and in fact the
construction of oriented area should pass through `ω`.)
* `Orientation.rightAngleRotation`: an isometric automorphism `E ≃ₗᵢ[ℝ] E` (usual notation `J`).
This automorphism squares to -1. In a later file, rotations (`Orientation.rotation`) are defined,
in such a way that this automorphism is equal to rotation by 90 degrees.
* `Orientation.basisRightAngleRotation`: for a nonzero vector `x` in `E`, the basis `![x, J x]`
for `E`.
* `Orientation.kahler`: a complex-valued real-bilinear map `E →ₗ[ℝ] E →ₗ[ℝ] ℂ`. Its real part is the
inner product and its imaginary part is `Orientation.areaForm`. For vectors `x` and `y` in `E`,
the complex number `o.kahler x y` has modulus `‖x‖ * ‖y‖`. In a later file, oriented angles
(`Orientation.oangle`) are defined, in such a way that the argument of `o.kahler x y` is the
oriented angle from `x` to `y`.
## Main results
* `Orientation.rightAngleRotation_rightAngleRotation`: the identity `J (J x) = - x`
* `Orientation.nonneg_inner_and_areaForm_eq_zero_iff_sameRay`: `x`, `y` are in the same ray, if
and only if `0 ≤ ⟪x, y⟫` and `ω x y = 0`
* `Orientation.kahler_mul`: the identity `o.kahler x a * o.kahler a y = ‖a‖ ^ 2 * o.kahler x y`
* `Complex.areaForm`, `Complex.rightAngleRotation`, `Complex.kahler`: the concrete
interpretations of `areaForm`, `rightAngleRotation`, `kahler` for the oriented real inner
product space `ℂ`
* `Orientation.areaForm_map_complex`, `Orientation.rightAngleRotation_map_complex`,
`Orientation.kahler_map_complex`: given an orientation-preserving isometry from `E` to `ℂ`,
expressions for `areaForm`, `rightAngleRotation`, `kahler` as the pullback of their concrete
interpretations on `ℂ`
## Implementation notes
Notation `ω` for `Orientation.areaForm` and `J` for `Orientation.rightAngleRotation` should be
defined locally in each file which uses them, since otherwise one would need a more cumbersome
notation which mentions the orientation explicitly (something like `ω[o]`). Write
```
local notation "ω" => o.areaForm
local notation "J" => o.rightAngleRotation
```
-/
noncomputable section
open scoped RealInnerProductSpace ComplexConjugate
open FiniteDimensional
lemma FiniteDimensional.of_fact_finrank_eq_two {K V : Type*} [DivisionRing K]
[AddCommGroup V] [Module K V] [Fact (finrank K V = 2)] : FiniteDimensional K V :=
.of_fact_finrank_eq_succ 1
attribute [local instance] FiniteDimensional.of_fact_finrank_eq_two
@[deprecated (since := "2024-02-02")]
alias FiniteDimensional.finiteDimensional_of_fact_finrank_eq_two :=
FiniteDimensional.of_fact_finrank_eq_two
variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] [Fact (finrank ℝ E = 2)]
(o : Orientation ℝ E (Fin 2))
namespace Orientation
/-- An antisymmetric bilinear form on an oriented real inner product space of dimension 2 (usual
notation `ω`). When evaluated on two vectors, it gives the oriented area of the parallelogram they
span. -/
irreducible_def areaForm : E →ₗ[ℝ] E →ₗ[ℝ] ℝ := by
let z : E [⋀^Fin 0]→ₗ[ℝ] ℝ ≃ₗ[ℝ] ℝ :=
AlternatingMap.constLinearEquivOfIsEmpty.symm
let y : E [⋀^Fin 1]→ₗ[ℝ] ℝ →ₗ[ℝ] E →ₗ[ℝ] ℝ :=
LinearMap.llcomp ℝ E (E [⋀^Fin 0]→ₗ[ℝ] ℝ) ℝ z ∘ₗ AlternatingMap.curryLeftLinearMap
exact y ∘ₗ AlternatingMap.curryLeftLinearMap (R' := ℝ) o.volumeForm
#align orientation.area_form Orientation.areaForm
local notation "ω" => o.areaForm
theorem areaForm_to_volumeForm (x y : E) : ω x y = o.volumeForm ![x, y] := by simp [areaForm]
#align orientation.area_form_to_volume_form Orientation.areaForm_to_volumeForm
@[simp]
theorem areaForm_apply_self (x : E) : ω x x = 0 := by
rw [areaForm_to_volumeForm]
refine o.volumeForm.map_eq_zero_of_eq ![x, x] ?_ (?_ : (0 : Fin 2) ≠ 1)
· simp
· norm_num
#align orientation.area_form_apply_self Orientation.areaForm_apply_self
theorem areaForm_swap (x y : E) : ω x y = -ω y x := by
simp only [areaForm_to_volumeForm]
convert o.volumeForm.map_swap ![y, x] (_ : (0 : Fin 2) ≠ 1)
· ext i
fin_cases i <;> rfl
· norm_num
#align orientation.area_form_swap Orientation.areaForm_swap
@[simp]
theorem areaForm_neg_orientation : (-o).areaForm = -o.areaForm := by
ext x y
simp [areaForm_to_volumeForm]
#align orientation.area_form_neg_orientation Orientation.areaForm_neg_orientation
/-- Continuous linear map version of `Orientation.areaForm`, useful for calculus. -/
def areaForm' : E →L[ℝ] E →L[ℝ] ℝ :=
LinearMap.toContinuousLinearMap
(↑(LinearMap.toContinuousLinearMap : (E →ₗ[ℝ] ℝ) ≃ₗ[ℝ] E →L[ℝ] ℝ) ∘ₗ o.areaForm)
#align orientation.area_form' Orientation.areaForm'
@[simp]
theorem areaForm'_apply (x : E) :
o.areaForm' x = LinearMap.toContinuousLinearMap (o.areaForm x) :=
rfl
#align orientation.area_form'_apply Orientation.areaForm'_apply
theorem abs_areaForm_le (x y : E) : |ω x y| ≤ ‖x‖ * ‖y‖ := by
simpa [areaForm_to_volumeForm, Fin.prod_univ_succ] using o.abs_volumeForm_apply_le ![x, y]
#align orientation.abs_area_form_le Orientation.abs_areaForm_le
theorem areaForm_le (x y : E) : ω x y ≤ ‖x‖ * ‖y‖ := by
simpa [areaForm_to_volumeForm, Fin.prod_univ_succ] using o.volumeForm_apply_le ![x, y]
#align orientation.area_form_le Orientation.areaForm_le
theorem abs_areaForm_of_orthogonal {x y : E} (h : ⟪x, y⟫ = 0) : |ω x y| = ‖x‖ * ‖y‖ := by
rw [o.areaForm_to_volumeForm, o.abs_volumeForm_apply_of_pairwise_orthogonal]
· simp [Fin.prod_univ_succ]
intro i j hij
fin_cases i <;> fin_cases j
· simp_all
· simpa using h
· simpa [real_inner_comm] using h
· simp_all
#align orientation.abs_area_form_of_orthogonal Orientation.abs_areaForm_of_orthogonal
theorem areaForm_map {F : Type*} [NormedAddCommGroup F] [InnerProductSpace ℝ F]
[hF : Fact (finrank ℝ F = 2)] (φ : E ≃ₗᵢ[ℝ] F) (x y : F) :
(Orientation.map (Fin 2) φ.toLinearEquiv o).areaForm x y =
o.areaForm (φ.symm x) (φ.symm y) := by
have : φ.symm ∘ ![x, y] = ![φ.symm x, φ.symm y] := by
ext i
fin_cases i <;> rfl
simp [areaForm_to_volumeForm, volumeForm_map, this]
#align orientation.area_form_map Orientation.areaForm_map
/-- The area form is invariant under pullback by a positively-oriented isometric automorphism. -/
theorem areaForm_comp_linearIsometryEquiv (φ : E ≃ₗᵢ[ℝ] E)
(hφ : 0 < LinearMap.det (φ.toLinearEquiv : E →ₗ[ℝ] E)) (x y : E) :
o.areaForm (φ x) (φ y) = o.areaForm x y := by
convert o.areaForm_map φ (φ x) (φ y)
· symm
rwa [← o.map_eq_iff_det_pos φ.toLinearEquiv] at hφ
rw [@Fact.out (finrank ℝ E = 2), Fintype.card_fin]
· simp
· simp
#align orientation.area_form_comp_linear_isometry_equiv Orientation.areaForm_comp_linearIsometryEquiv
/-- Auxiliary construction for `Orientation.rightAngleRotation`, rotation by 90 degrees in an
oriented real inner product space of dimension 2. -/
irreducible_def rightAngleRotationAux₁ : E →ₗ[ℝ] E :=
let to_dual : E ≃ₗ[ℝ] E →ₗ[ℝ] ℝ :=
(InnerProductSpace.toDual ℝ E).toLinearEquiv ≪≫ₗ LinearMap.toContinuousLinearMap.symm
↑to_dual.symm ∘ₗ ω
#align orientation.right_angle_rotation_aux₁ Orientation.rightAngleRotationAux₁
@[simp]
theorem inner_rightAngleRotationAux₁_left (x y : E) : ⟪o.rightAngleRotationAux₁ x, y⟫ = ω x y := by
-- Porting note: split `simp only` for greater proof control
simp only [rightAngleRotationAux₁, LinearEquiv.trans_symm, LinearIsometryEquiv.toLinearEquiv_symm,
LinearMap.coe_comp, LinearEquiv.coe_coe, Function.comp_apply, LinearEquiv.trans_apply,
LinearIsometryEquiv.coe_toLinearEquiv]
rw [InnerProductSpace.toDual_symm_apply]
norm_cast
#align orientation.inner_right_angle_rotation_aux₁_left Orientation.inner_rightAngleRotationAux₁_left
@[simp]
theorem inner_rightAngleRotationAux₁_right (x y : E) :
⟪x, o.rightAngleRotationAux₁ y⟫ = -ω x y := by
rw [real_inner_comm]
simp [o.areaForm_swap y x]
#align orientation.inner_right_angle_rotation_aux₁_right Orientation.inner_rightAngleRotationAux₁_right
/-- Auxiliary construction for `Orientation.rightAngleRotation`, rotation by 90 degrees in an
oriented real inner product space of dimension 2. -/
def rightAngleRotationAux₂ : E →ₗᵢ[ℝ] E :=
{ o.rightAngleRotationAux₁ with
norm_map' := fun x => by
dsimp
refine le_antisymm ?_ ?_
· cases' eq_or_lt_of_le (norm_nonneg (o.rightAngleRotationAux₁ x)) with h h
· rw [← h]
positivity
refine le_of_mul_le_mul_right ?_ h
rw [← real_inner_self_eq_norm_mul_norm, o.inner_rightAngleRotationAux₁_left]
exact o.areaForm_le x (o.rightAngleRotationAux₁ x)
· let K : Submodule ℝ E := ℝ ∙ x
have : Nontrivial Kᗮ := by
apply @FiniteDimensional.nontrivial_of_finrank_pos ℝ
have : finrank ℝ K ≤ Finset.card {x} := by
rw [← Set.toFinset_singleton]
exact finrank_span_le_card ({x} : Set E)
have : Finset.card {x} = 1 := Finset.card_singleton x
have : finrank ℝ K + finrank ℝ Kᗮ = finrank ℝ E := K.finrank_add_finrank_orthogonal
have : finrank ℝ E = 2 := Fact.out
linarith
obtain ⟨w, hw₀⟩ : ∃ w : Kᗮ, w ≠ 0 := exists_ne 0
have hw' : ⟪x, (w : E)⟫ = 0 := Submodule.mem_orthogonal_singleton_iff_inner_right.mp w.2
have hw : (w : E) ≠ 0 := fun h => hw₀ (Submodule.coe_eq_zero.mp h)
refine le_of_mul_le_mul_right ?_ (by rwa [norm_pos_iff] : 0 < ‖(w : E)‖)
rw [← o.abs_areaForm_of_orthogonal hw']
rw [← o.inner_rightAngleRotationAux₁_left x w]
exact abs_real_inner_le_norm (o.rightAngleRotationAux₁ x) w }
#align orientation.right_angle_rotation_aux₂ Orientation.rightAngleRotationAux₂
@[simp]
theorem rightAngleRotationAux₁_rightAngleRotationAux₁ (x : E) :
o.rightAngleRotationAux₁ (o.rightAngleRotationAux₁ x) = -x := by
apply ext_inner_left ℝ
intro y
have : ⟪o.rightAngleRotationAux₁ y, o.rightAngleRotationAux₁ x⟫ = ⟪y, x⟫ :=
LinearIsometry.inner_map_map o.rightAngleRotationAux₂ y x
rw [o.inner_rightAngleRotationAux₁_right, ← o.inner_rightAngleRotationAux₁_left, this,
inner_neg_right]
#align orientation.right_angle_rotation_aux₁_right_angle_rotation_aux₁ Orientation.rightAngleRotationAux₁_rightAngleRotationAux₁
/-- An isometric automorphism of an oriented real inner product space of dimension 2 (usual notation
`J`). This automorphism squares to -1. We will define rotations in such a way that this
automorphism is equal to rotation by 90 degrees. -/
irreducible_def rightAngleRotation : E ≃ₗᵢ[ℝ] E :=
LinearIsometryEquiv.ofLinearIsometry o.rightAngleRotationAux₂ (-o.rightAngleRotationAux₁)
(by ext; simp [rightAngleRotationAux₂]) (by ext; simp [rightAngleRotationAux₂])
#align orientation.right_angle_rotation Orientation.rightAngleRotation
local notation "J" => o.rightAngleRotation
@[simp]
theorem inner_rightAngleRotation_left (x y : E) : ⟪J x, y⟫ = ω x y := by
rw [rightAngleRotation]
exact o.inner_rightAngleRotationAux₁_left x y
#align orientation.inner_right_angle_rotation_left Orientation.inner_rightAngleRotation_left
@[simp]
theorem inner_rightAngleRotation_right (x y : E) : ⟪x, J y⟫ = -ω x y := by
rw [rightAngleRotation]
exact o.inner_rightAngleRotationAux₁_right x y
#align orientation.inner_right_angle_rotation_right Orientation.inner_rightAngleRotation_right
@[simp]
theorem rightAngleRotation_rightAngleRotation (x : E) : J (J x) = -x := by
rw [rightAngleRotation]
exact o.rightAngleRotationAux₁_rightAngleRotationAux₁ x
#align orientation.right_angle_rotation_right_angle_rotation Orientation.rightAngleRotation_rightAngleRotation
@[simp]
theorem rightAngleRotation_symm :
LinearIsometryEquiv.symm J = LinearIsometryEquiv.trans J (LinearIsometryEquiv.neg ℝ) := by
rw [rightAngleRotation]
exact LinearIsometryEquiv.toLinearIsometry_injective rfl
#align orientation.right_angle_rotation_symm Orientation.rightAngleRotation_symm
-- @[simp] -- Porting note (#10618): simp already proves this
theorem inner_rightAngleRotation_self (x : E) : ⟪J x, x⟫ = 0 := by simp
#align orientation.inner_right_angle_rotation_self Orientation.inner_rightAngleRotation_self
theorem inner_rightAngleRotation_swap (x y : E) : ⟪x, J y⟫ = -⟪J x, y⟫ := by simp
#align orientation.inner_right_angle_rotation_swap Orientation.inner_rightAngleRotation_swap
theorem inner_rightAngleRotation_swap' (x y : E) : ⟪J x, y⟫ = -⟪x, J y⟫ := by
simp [o.inner_rightAngleRotation_swap x y]
#align orientation.inner_right_angle_rotation_swap' Orientation.inner_rightAngleRotation_swap'
theorem inner_comp_rightAngleRotation (x y : E) : ⟪J x, J y⟫ = ⟪x, y⟫ :=
LinearIsometryEquiv.inner_map_map J x y
#align orientation.inner_comp_right_angle_rotation Orientation.inner_comp_rightAngleRotation
@[simp]
theorem areaForm_rightAngleRotation_left (x y : E) : ω (J x) y = -⟪x, y⟫ := by
rw [← o.inner_comp_rightAngleRotation, o.inner_rightAngleRotation_right, neg_neg]
#align orientation.area_form_right_angle_rotation_left Orientation.areaForm_rightAngleRotation_left
@[simp]
theorem areaForm_rightAngleRotation_right (x y : E) : ω x (J y) = ⟪x, y⟫ := by
rw [← o.inner_rightAngleRotation_left, o.inner_comp_rightAngleRotation]
#align orientation.area_form_right_angle_rotation_right Orientation.areaForm_rightAngleRotation_right
-- @[simp] -- Porting note (#10618): simp already proves this
theorem areaForm_comp_rightAngleRotation (x y : E) : ω (J x) (J y) = ω x y := by simp
#align orientation.area_form_comp_right_angle_rotation Orientation.areaForm_comp_rightAngleRotation
@[simp]
theorem rightAngleRotation_trans_rightAngleRotation :
LinearIsometryEquiv.trans J J = LinearIsometryEquiv.neg ℝ := by ext; simp
#align orientation.right_angle_rotation_trans_right_angle_rotation Orientation.rightAngleRotation_trans_rightAngleRotation
theorem rightAngleRotation_neg_orientation (x : E) :
(-o).rightAngleRotation x = -o.rightAngleRotation x := by
apply ext_inner_right ℝ
intro y
rw [inner_rightAngleRotation_left]
simp
#align orientation.right_angle_rotation_neg_orientation Orientation.rightAngleRotation_neg_orientation
@[simp]
theorem rightAngleRotation_trans_neg_orientation :
(-o).rightAngleRotation = o.rightAngleRotation.trans (LinearIsometryEquiv.neg ℝ) :=
LinearIsometryEquiv.ext <| o.rightAngleRotation_neg_orientation
#align orientation.right_angle_rotation_trans_neg_orientation Orientation.rightAngleRotation_trans_neg_orientation
theorem rightAngleRotation_map {F : Type*} [NormedAddCommGroup F] [InnerProductSpace ℝ F]
[hF : Fact (finrank ℝ F = 2)] (φ : E ≃ₗᵢ[ℝ] F) (x : F) :
(Orientation.map (Fin 2) φ.toLinearEquiv o).rightAngleRotation x =
φ (o.rightAngleRotation (φ.symm x)) := by
apply ext_inner_right ℝ
intro y
rw [inner_rightAngleRotation_left]
trans ⟪J (φ.symm x), φ.symm y⟫
· simp [o.areaForm_map]
trans ⟪φ (J (φ.symm x)), φ (φ.symm y)⟫
· rw [φ.inner_map_map]
· simp
#align orientation.right_angle_rotation_map Orientation.rightAngleRotation_map
/-- `J` commutes with any positively-oriented isometric automorphism. -/
theorem linearIsometryEquiv_comp_rightAngleRotation (φ : E ≃ₗᵢ[ℝ] E)
(hφ : 0 < LinearMap.det (φ.toLinearEquiv : E →ₗ[ℝ] E)) (x : E) : φ (J x) = J (φ x) := by
convert (o.rightAngleRotation_map φ (φ x)).symm
· simp
· symm
rwa [← o.map_eq_iff_det_pos φ.toLinearEquiv] at hφ
rw [@Fact.out (finrank ℝ E = 2), Fintype.card_fin]
#align orientation.linear_isometry_equiv_comp_right_angle_rotation Orientation.linearIsometryEquiv_comp_rightAngleRotation
theorem rightAngleRotation_map' {F : Type*} [NormedAddCommGroup F] [InnerProductSpace ℝ F]
[Fact (finrank ℝ F = 2)] (φ : E ≃ₗᵢ[ℝ] F) :
(Orientation.map (Fin 2) φ.toLinearEquiv o).rightAngleRotation =
(φ.symm.trans o.rightAngleRotation).trans φ :=
LinearIsometryEquiv.ext <| o.rightAngleRotation_map φ
#align orientation.right_angle_rotation_map' Orientation.rightAngleRotation_map'
/-- `J` commutes with any positively-oriented isometric automorphism. -/
theorem linearIsometryEquiv_comp_rightAngleRotation' (φ : E ≃ₗᵢ[ℝ] E)
(hφ : 0 < LinearMap.det (φ.toLinearEquiv : E →ₗ[ℝ] E)) :
LinearIsometryEquiv.trans J φ = φ.trans J :=
LinearIsometryEquiv.ext <| o.linearIsometryEquiv_comp_rightAngleRotation φ hφ
#align orientation.linear_isometry_equiv_comp_right_angle_rotation' Orientation.linearIsometryEquiv_comp_rightAngleRotation'
/-- For a nonzero vector `x` in an oriented two-dimensional real inner product space `E`,
`![x, J x]` forms an (orthogonal) basis for `E`. -/
def basisRightAngleRotation (x : E) (hx : x ≠ 0) : Basis (Fin 2) ℝ E :=
@basisOfLinearIndependentOfCardEqFinrank ℝ _ _ _ _ _ _ _ ![x, J x]
(linearIndependent_of_ne_zero_of_inner_eq_zero (fun i => by fin_cases i <;> simp [hx])
(by
intro i j hij
fin_cases i <;> fin_cases j <;> simp_all))
(@Fact.out (finrank ℝ E = 2)).symm
#align orientation.basis_right_angle_rotation Orientation.basisRightAngleRotation
@[simp]
theorem coe_basisRightAngleRotation (x : E) (hx : x ≠ 0) :
⇑(o.basisRightAngleRotation x hx) = ![x, J x] :=
coe_basisOfLinearIndependentOfCardEqFinrank _ _
#align orientation.coe_basis_right_angle_rotation Orientation.coe_basisRightAngleRotation
/-- For vectors `a x y : E`, the identity `⟪a, x⟫ * ⟪a, y⟫ + ω a x * ω a y = ‖a‖ ^ 2 * ⟪x, y⟫`. (See
`Orientation.inner_mul_inner_add_areaForm_mul_areaForm` for the "applied" form.)-/
theorem inner_mul_inner_add_areaForm_mul_areaForm' (a x : E) :
⟪a, x⟫ • innerₛₗ ℝ a + ω a x • ω a = ‖a‖ ^ 2 • innerₛₗ ℝ x := by
by_cases ha : a = 0
· simp [ha]
apply (o.basisRightAngleRotation a ha).ext
intro i
fin_cases i
· simp only [Fin.mk_zero, coe_basisRightAngleRotation, Matrix.cons_val_zero, LinearMap.add_apply,
LinearMap.smul_apply, innerₛₗ_apply, real_inner_self_eq_norm_sq, smul_eq_mul,
areaForm_apply_self, mul_zero, add_zero, Real.rpow_two, real_inner_comm]
ring
· simp only [Fin.mk_one, coe_basisRightAngleRotation, Matrix.cons_val_one, Matrix.head_cons,
LinearMap.add_apply, LinearMap.smul_apply, innerₛₗ_apply, inner_rightAngleRotation_right,
areaForm_apply_self, neg_zero, smul_eq_mul, mul_zero, areaForm_rightAngleRotation_right,
real_inner_self_eq_norm_sq, zero_add, Real.rpow_two, mul_neg]
rw [o.areaForm_swap]
ring
#align orientation.inner_mul_inner_add_area_form_mul_area_form' Orientation.inner_mul_inner_add_areaForm_mul_areaForm'
/-- For vectors `a x y : E`, the identity `⟪a, x⟫ * ⟪a, y⟫ + ω a x * ω a y = ‖a‖ ^ 2 * ⟪x, y⟫`. -/
theorem inner_mul_inner_add_areaForm_mul_areaForm (a x y : E) :
⟪a, x⟫ * ⟪a, y⟫ + ω a x * ω a y = ‖a‖ ^ 2 * ⟪x, y⟫ :=
congr_arg (fun f : E →ₗ[ℝ] ℝ => f y) (o.inner_mul_inner_add_areaForm_mul_areaForm' a x)
#align orientation.inner_mul_inner_add_area_form_mul_area_form Orientation.inner_mul_inner_add_areaForm_mul_areaForm
theorem inner_sq_add_areaForm_sq (a b : E) : ⟪a, b⟫ ^ 2 + ω a b ^ 2 = ‖a‖ ^ 2 * ‖b‖ ^ 2 := by
simpa [sq, real_inner_self_eq_norm_sq] using o.inner_mul_inner_add_areaForm_mul_areaForm a b b
#align orientation.inner_sq_add_area_form_sq Orientation.inner_sq_add_areaForm_sq
/-- For vectors `a x y : E`, the identity `⟪a, x⟫ * ω a y - ω a x * ⟪a, y⟫ = ‖a‖ ^ 2 * ω x y`. (See
`Orientation.inner_mul_areaForm_sub` for the "applied" form.) -/
theorem inner_mul_areaForm_sub' (a x : E) : ⟪a, x⟫ • ω a - ω a x • innerₛₗ ℝ a = ‖a‖ ^ 2 • ω x := by
by_cases ha : a = 0
· simp [ha]
apply (o.basisRightAngleRotation a ha).ext
intro i
fin_cases i
· simp only [o.areaForm_swap a x, neg_smul, sub_neg_eq_add, Fin.mk_zero,
coe_basisRightAngleRotation, Matrix.cons_val_zero, LinearMap.add_apply, LinearMap.smul_apply,
areaForm_apply_self, smul_eq_mul, mul_zero, innerₛₗ_apply, real_inner_self_eq_norm_sq,
zero_add, Real.rpow_two]
ring
· simp only [Fin.mk_one, coe_basisRightAngleRotation, Matrix.cons_val_one, Matrix.head_cons,
LinearMap.sub_apply, LinearMap.smul_apply, areaForm_rightAngleRotation_right,
real_inner_self_eq_norm_sq, smul_eq_mul, innerₛₗ_apply, inner_rightAngleRotation_right,
areaForm_apply_self, neg_zero, mul_zero, sub_zero, Real.rpow_two, real_inner_comm]
ring
#align orientation.inner_mul_area_form_sub' Orientation.inner_mul_areaForm_sub'
/-- For vectors `a x y : E`, the identity `⟪a, x⟫ * ω a y - ω a x * ⟪a, y⟫ = ‖a‖ ^ 2 * ω x y`. -/
theorem inner_mul_areaForm_sub (a x y : E) : ⟪a, x⟫ * ω a y - ω a x * ⟪a, y⟫ = ‖a‖ ^ 2 * ω x y :=
congr_arg (fun f : E →ₗ[ℝ] ℝ => f y) (o.inner_mul_areaForm_sub' a x)
#align orientation.inner_mul_area_form_sub Orientation.inner_mul_areaForm_sub
theorem nonneg_inner_and_areaForm_eq_zero_iff_sameRay (x y : E) :
0 ≤ ⟪x, y⟫ ∧ ω x y = 0 ↔ SameRay ℝ x y := by
by_cases hx : x = 0
· simp [hx]
constructor
· let a : ℝ := (o.basisRightAngleRotation x hx).repr y 0
let b : ℝ := (o.basisRightAngleRotation x hx).repr y 1
suffices ↑0 ≤ a * ‖x‖ ^ 2 ∧ b * ‖x‖ ^ 2 = 0 → SameRay ℝ x (a • x + b • J x) by
rw [← (o.basisRightAngleRotation x hx).sum_repr y]
simp only [Fin.sum_univ_succ, coe_basisRightAngleRotation, Matrix.cons_val_zero,
Fin.succ_zero_eq_one', Finset.univ_eq_empty, Finset.sum_empty, areaForm_apply_self,
map_smul, map_add, real_inner_smul_right, inner_add_right, Matrix.cons_val_one,
Matrix.head_cons, Algebra.id.smul_eq_mul, areaForm_rightAngleRotation_right,
mul_zero, add_zero, zero_add, neg_zero, inner_rightAngleRotation_right,
real_inner_self_eq_norm_sq, zero_smul, one_smul]
exact this
rintro ⟨ha, hb⟩
have hx' : 0 < ‖x‖ := by simpa using hx
have ha' : 0 ≤ a := nonneg_of_mul_nonneg_left ha (by positivity)
have hb' : b = 0 := eq_zero_of_ne_zero_of_mul_right_eq_zero (pow_ne_zero 2 hx'.ne') hb
exact (SameRay.sameRay_nonneg_smul_right x ha').add_right $ by simp [hb']
· intro h
obtain ⟨r, hr, rfl⟩ := h.exists_nonneg_left hx
simp only [inner_smul_right, real_inner_self_eq_norm_sq, LinearMap.map_smulₛₗ,
areaForm_apply_self, Algebra.id.smul_eq_mul, mul_zero, eq_self_iff_true,
and_true_iff]
positivity
#align orientation.nonneg_inner_and_area_form_eq_zero_iff_same_ray Orientation.nonneg_inner_and_areaForm_eq_zero_iff_sameRay
/-- A complex-valued real-bilinear map on an oriented real inner product space of dimension 2. Its
real part is the inner product and its imaginary part is `Orientation.areaForm`.
On `ℂ` with the standard orientation, `kahler w z = conj w * z`; see `Complex.kahler`. -/
def kahler : E →ₗ[ℝ] E →ₗ[ℝ] ℂ :=
LinearMap.llcomp ℝ E ℝ ℂ Complex.ofRealCLM ∘ₗ innerₛₗ ℝ +
LinearMap.llcomp ℝ E ℝ ℂ ((LinearMap.lsmul ℝ ℂ).flip Complex.I) ∘ₗ ω
#align orientation.kahler Orientation.kahler
theorem kahler_apply_apply (x y : E) : o.kahler x y = ⟪x, y⟫ + ω x y • Complex.I :=
rfl
#align orientation.kahler_apply_apply Orientation.kahler_apply_apply
theorem kahler_swap (x y : E) : o.kahler x y = conj (o.kahler y x) := by
have : ∀ r : ℝ, Complex.ofReal' r = @RCLike.ofReal ℂ _ r := fun r => rfl
simp only [kahler_apply_apply]
rw [real_inner_comm, areaForm_swap]
simp [this]
#align orientation.kahler_swap Orientation.kahler_swap
@[simp]
theorem kahler_apply_self (x : E) : o.kahler x x = ‖x‖ ^ 2 := by
simp [kahler_apply_apply, real_inner_self_eq_norm_sq]
#align orientation.kahler_apply_self Orientation.kahler_apply_self
@[simp]
theorem kahler_rightAngleRotation_left (x y : E) :
o.kahler (J x) y = -Complex.I * o.kahler x y := by
simp only [o.areaForm_rightAngleRotation_left, o.inner_rightAngleRotation_left,
o.kahler_apply_apply, Complex.ofReal_neg, Complex.real_smul]
linear_combination ω x y * Complex.I_sq
#align orientation.kahler_right_angle_rotation_left Orientation.kahler_rightAngleRotation_left
@[simp]
theorem kahler_rightAngleRotation_right (x y : E) :
o.kahler x (J y) = Complex.I * o.kahler x y := by
simp only [o.areaForm_rightAngleRotation_right, o.inner_rightAngleRotation_right,
o.kahler_apply_apply, Complex.ofReal_neg, Complex.real_smul]
linear_combination -ω x y * Complex.I_sq
#align orientation.kahler_right_angle_rotation_right Orientation.kahler_rightAngleRotation_right
-- @[simp] -- Porting note: simp normal form is `kahler_comp_rightAngleRotation'`
theorem kahler_comp_rightAngleRotation (x y : E) : o.kahler (J x) (J y) = o.kahler x y := by
simp only [kahler_rightAngleRotation_left, kahler_rightAngleRotation_right]
linear_combination -o.kahler x y * Complex.I_sq
#align orientation.kahler_comp_right_angle_rotation Orientation.kahler_comp_rightAngleRotation
| Mathlib/Analysis/InnerProductSpace/TwoDim.lean | 521 | 523 | theorem kahler_comp_rightAngleRotation' (x y : E) :
-(Complex.I * (Complex.I * o.kahler x y)) = o.kahler x y := by |
linear_combination -o.kahler x y * Complex.I_sq
|
/-
Copyright (c) 2021 Aaron Anderson. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Aaron Anderson
-/
import Mathlib.Init.Data.Sigma.Lex
import Mathlib.Data.Prod.Lex
import Mathlib.Data.Sigma.Lex
import Mathlib.Order.Antichain
import Mathlib.Order.OrderIsoNat
import Mathlib.Order.WellFounded
import Mathlib.Tactic.TFAE
#align_import order.well_founded_set from "leanprover-community/mathlib"@"2c84c2c5496117349007d97104e7bbb471381592"
/-!
# Well-founded sets
A well-founded subset of an ordered type is one on which the relation `<` is well-founded.
## Main Definitions
* `Set.WellFoundedOn s r` indicates that the relation `r` is
well-founded when restricted to the set `s`.
* `Set.IsWF s` indicates that `<` is well-founded when restricted to `s`.
* `Set.PartiallyWellOrderedOn s r` indicates that the relation `r` is
partially well-ordered (also known as well quasi-ordered) when restricted to the set `s`.
* `Set.IsPWO s` indicates that any infinite sequence of elements in `s` contains an infinite
monotone subsequence. Note that this is equivalent to containing only two comparable elements.
## Main Results
* Higman's Lemma, `Set.PartiallyWellOrderedOn.partiallyWellOrderedOn_sublistForall₂`,
shows that if `r` is partially well-ordered on `s`, then `List.SublistForall₂` is partially
well-ordered on the set of lists of elements of `s`. The result was originally published by
Higman, but this proof more closely follows Nash-Williams.
* `Set.wellFoundedOn_iff` relates `well_founded_on` to the well-foundedness of a relation on the
original type, to avoid dealing with subtypes.
* `Set.IsWF.mono` shows that a subset of a well-founded subset is well-founded.
* `Set.IsWF.union` shows that the union of two well-founded subsets is well-founded.
* `Finset.isWF` shows that all `Finset`s are well-founded.
## TODO
Prove that `s` is partial well ordered iff it has no infinite descending chain or antichain.
## References
* [Higman, *Ordering by Divisibility in Abstract Algebras*][Higman52]
* [Nash-Williams, *On Well-Quasi-Ordering Finite Trees*][Nash-Williams63]
-/
variable {ι α β γ : Type*} {π : ι → Type*}
namespace Set
/-! ### Relations well-founded on sets -/
/-- `s.WellFoundedOn r` indicates that the relation `r` is well-founded when restricted to `s`. -/
def WellFoundedOn (s : Set α) (r : α → α → Prop) : Prop :=
WellFounded fun a b : s => r a b
#align set.well_founded_on Set.WellFoundedOn
@[simp]
theorem wellFoundedOn_empty (r : α → α → Prop) : WellFoundedOn ∅ r :=
wellFounded_of_isEmpty _
#align set.well_founded_on_empty Set.wellFoundedOn_empty
section WellFoundedOn
variable {r r' : α → α → Prop}
section AnyRel
variable {f : β → α} {s t : Set α} {x y : α}
theorem wellFoundedOn_iff :
s.WellFoundedOn r ↔ WellFounded fun a b : α => r a b ∧ a ∈ s ∧ b ∈ s := by
have f : RelEmbedding (fun (a : s) (b : s) => r a b) fun a b : α => r a b ∧ a ∈ s ∧ b ∈ s :=
⟨⟨(↑), Subtype.coe_injective⟩, by simp⟩
refine ⟨fun h => ?_, f.wellFounded⟩
rw [WellFounded.wellFounded_iff_has_min]
intro t ht
by_cases hst : (s ∩ t).Nonempty
· rw [← Subtype.preimage_coe_nonempty] at hst
rcases h.has_min (Subtype.val ⁻¹' t) hst with ⟨⟨m, ms⟩, mt, hm⟩
exact ⟨m, mt, fun x xt ⟨xm, xs, _⟩ => hm ⟨x, xs⟩ xt xm⟩
· rcases ht with ⟨m, mt⟩
exact ⟨m, mt, fun x _ ⟨_, _, ms⟩ => hst ⟨m, ⟨ms, mt⟩⟩⟩
#align set.well_founded_on_iff Set.wellFoundedOn_iff
@[simp]
theorem wellFoundedOn_univ : (univ : Set α).WellFoundedOn r ↔ WellFounded r := by
simp [wellFoundedOn_iff]
#align set.well_founded_on_univ Set.wellFoundedOn_univ
theorem _root_.WellFounded.wellFoundedOn : WellFounded r → s.WellFoundedOn r :=
InvImage.wf _
#align well_founded.well_founded_on WellFounded.wellFoundedOn
@[simp]
theorem wellFoundedOn_range : (range f).WellFoundedOn r ↔ WellFounded (r on f) := by
let f' : β → range f := fun c => ⟨f c, c, rfl⟩
refine ⟨fun h => (InvImage.wf f' h).mono fun c c' => id, fun h => ⟨?_⟩⟩
rintro ⟨_, c, rfl⟩
refine Acc.of_downward_closed f' ?_ _ ?_
· rintro _ ⟨_, c', rfl⟩ -
exact ⟨c', rfl⟩
· exact h.apply _
#align set.well_founded_on_range Set.wellFoundedOn_range
@[simp]
theorem wellFoundedOn_image {s : Set β} : (f '' s).WellFoundedOn r ↔ s.WellFoundedOn (r on f) := by
rw [image_eq_range]; exact wellFoundedOn_range
#align set.well_founded_on_image Set.wellFoundedOn_image
namespace WellFoundedOn
protected theorem induction (hs : s.WellFoundedOn r) (hx : x ∈ s) {P : α → Prop}
(hP : ∀ y ∈ s, (∀ z ∈ s, r z y → P z) → P y) : P x := by
let Q : s → Prop := fun y => P y
change Q ⟨x, hx⟩
refine WellFounded.induction hs ⟨x, hx⟩ ?_
simpa only [Subtype.forall]
#align set.well_founded_on.induction Set.WellFoundedOn.induction
protected theorem mono (h : t.WellFoundedOn r') (hle : r ≤ r') (hst : s ⊆ t) :
s.WellFoundedOn r := by
rw [wellFoundedOn_iff] at *
exact Subrelation.wf (fun xy => ⟨hle _ _ xy.1, hst xy.2.1, hst xy.2.2⟩) h
#align set.well_founded_on.mono Set.WellFoundedOn.mono
theorem mono' (h : ∀ (a) (_ : a ∈ s) (b) (_ : b ∈ s), r' a b → r a b) :
s.WellFoundedOn r → s.WellFoundedOn r' :=
Subrelation.wf @fun a b => h _ a.2 _ b.2
#align set.well_founded_on.mono' Set.WellFoundedOn.mono'
theorem subset (h : t.WellFoundedOn r) (hst : s ⊆ t) : s.WellFoundedOn r :=
h.mono le_rfl hst
#align set.well_founded_on.subset Set.WellFoundedOn.subset
open Relation
open List in
/-- `a` is accessible under the relation `r` iff `r` is well-founded on the downward transitive
closure of `a` under `r` (including `a` or not). -/
theorem acc_iff_wellFoundedOn {α} {r : α → α → Prop} {a : α} :
TFAE [Acc r a,
WellFoundedOn { b | ReflTransGen r b a } r,
WellFoundedOn { b | TransGen r b a } r] := by
tfae_have 1 → 2
· refine fun h => ⟨fun b => InvImage.accessible _ ?_⟩
rw [← acc_transGen_iff] at h ⊢
obtain h' | h' := reflTransGen_iff_eq_or_transGen.1 b.2
· rwa [h'] at h
· exact h.inv h'
tfae_have 2 → 3
· exact fun h => h.subset fun _ => TransGen.to_reflTransGen
tfae_have 3 → 1
· refine fun h => Acc.intro _ (fun b hb => (h.apply ⟨b, .single hb⟩).of_fibration Subtype.val ?_)
exact fun ⟨c, hc⟩ d h => ⟨⟨d, .head h hc⟩, h, rfl⟩
tfae_finish
#align set.well_founded_on.acc_iff_well_founded_on Set.WellFoundedOn.acc_iff_wellFoundedOn
end WellFoundedOn
end AnyRel
section IsStrictOrder
variable [IsStrictOrder α r] {s t : Set α}
instance IsStrictOrder.subset : IsStrictOrder α fun a b : α => r a b ∧ a ∈ s ∧ b ∈ s where
toIsIrrefl := ⟨fun a con => irrefl_of r a con.1⟩
toIsTrans := ⟨fun _ _ _ ab bc => ⟨trans_of r ab.1 bc.1, ab.2.1, bc.2.2⟩⟩
#align set.is_strict_order.subset Set.IsStrictOrder.subset
theorem wellFoundedOn_iff_no_descending_seq :
s.WellFoundedOn r ↔ ∀ f : ((· > ·) : ℕ → ℕ → Prop) ↪r r, ¬∀ n, f n ∈ s := by
simp only [wellFoundedOn_iff, RelEmbedding.wellFounded_iff_no_descending_seq, ← not_exists, ←
not_nonempty_iff, not_iff_not]
constructor
· rintro ⟨⟨f, hf⟩⟩
have H : ∀ n, f n ∈ s := fun n => (hf.2 n.lt_succ_self).2.2
refine ⟨⟨f, ?_⟩, H⟩
simpa only [H, and_true_iff] using @hf
· rintro ⟨⟨f, hf⟩, hfs : ∀ n, f n ∈ s⟩
refine ⟨⟨f, ?_⟩⟩
simpa only [hfs, and_true_iff] using @hf
#align set.well_founded_on_iff_no_descending_seq Set.wellFoundedOn_iff_no_descending_seq
theorem WellFoundedOn.union (hs : s.WellFoundedOn r) (ht : t.WellFoundedOn r) :
(s ∪ t).WellFoundedOn r := by
rw [wellFoundedOn_iff_no_descending_seq] at *
rintro f hf
rcases Nat.exists_subseq_of_forall_mem_union f hf with ⟨g, hg | hg⟩
exacts [hs (g.dual.ltEmbedding.trans f) hg, ht (g.dual.ltEmbedding.trans f) hg]
#align set.well_founded_on.union Set.WellFoundedOn.union
@[simp]
theorem wellFoundedOn_union : (s ∪ t).WellFoundedOn r ↔ s.WellFoundedOn r ∧ t.WellFoundedOn r :=
⟨fun h => ⟨h.subset subset_union_left, h.subset subset_union_right⟩, fun h =>
h.1.union h.2⟩
#align set.well_founded_on_union Set.wellFoundedOn_union
end IsStrictOrder
end WellFoundedOn
/-! ### Sets well-founded w.r.t. the strict inequality -/
section LT
variable [LT α] {s t : Set α}
/-- `s.IsWF` indicates that `<` is well-founded when restricted to `s`. -/
def IsWF (s : Set α) : Prop :=
WellFoundedOn s (· < ·)
#align set.is_wf Set.IsWF
@[simp]
theorem isWF_empty : IsWF (∅ : Set α) :=
wellFounded_of_isEmpty _
#align set.is_wf_empty Set.isWF_empty
theorem isWF_univ_iff : IsWF (univ : Set α) ↔ WellFounded ((· < ·) : α → α → Prop) := by
simp [IsWF, wellFoundedOn_iff]
#align set.is_wf_univ_iff Set.isWF_univ_iff
theorem IsWF.mono (h : IsWF t) (st : s ⊆ t) : IsWF s := h.subset st
#align set.is_wf.mono Set.IsWF.mono
end LT
section Preorder
variable [Preorder α] {s t : Set α} {a : α}
protected nonrec theorem IsWF.union (hs : IsWF s) (ht : IsWF t) : IsWF (s ∪ t) := hs.union ht
#align set.is_wf.union Set.IsWF.union
@[simp] theorem isWF_union : IsWF (s ∪ t) ↔ IsWF s ∧ IsWF t := wellFoundedOn_union
#align set.is_wf_union Set.isWF_union
end Preorder
section Preorder
variable [Preorder α] {s t : Set α} {a : α}
theorem isWF_iff_no_descending_seq :
IsWF s ↔ ∀ f : ℕ → α, StrictAnti f → ¬∀ n, f (OrderDual.toDual n) ∈ s :=
wellFoundedOn_iff_no_descending_seq.trans
⟨fun H f hf => H ⟨⟨f, hf.injective⟩, hf.lt_iff_lt⟩, fun H f => H f fun _ _ => f.map_rel_iff.2⟩
#align set.is_wf_iff_no_descending_seq Set.isWF_iff_no_descending_seq
end Preorder
/-!
### Partially well-ordered sets
A set is partially well-ordered by a relation `r` when any infinite sequence contains two elements
where the first is related to the second by `r`. Equivalently, any antichain (see `IsAntichain`) is
finite, see `Set.partiallyWellOrderedOn_iff_finite_antichains`.
-/
/-- A subset is partially well-ordered by a relation `r` when any infinite sequence contains
two elements where the first is related to the second by `r`. -/
def PartiallyWellOrderedOn (s : Set α) (r : α → α → Prop) : Prop :=
∀ f : ℕ → α, (∀ n, f n ∈ s) → ∃ m n : ℕ, m < n ∧ r (f m) (f n)
#align set.partially_well_ordered_on Set.PartiallyWellOrderedOn
section PartiallyWellOrderedOn
variable {r : α → α → Prop} {r' : β → β → Prop} {f : α → β} {s : Set α} {t : Set α} {a : α}
theorem PartiallyWellOrderedOn.mono (ht : t.PartiallyWellOrderedOn r) (h : s ⊆ t) :
s.PartiallyWellOrderedOn r := fun f hf => ht f fun n => h <| hf n
#align set.partially_well_ordered_on.mono Set.PartiallyWellOrderedOn.mono
@[simp]
theorem partiallyWellOrderedOn_empty (r : α → α → Prop) : PartiallyWellOrderedOn ∅ r := fun _ h =>
(h 0).elim
#align set.partially_well_ordered_on_empty Set.partiallyWellOrderedOn_empty
theorem PartiallyWellOrderedOn.union (hs : s.PartiallyWellOrderedOn r)
(ht : t.PartiallyWellOrderedOn r) : (s ∪ t).PartiallyWellOrderedOn r := by
rintro f hf
rcases Nat.exists_subseq_of_forall_mem_union f hf with ⟨g, hgs | hgt⟩
· rcases hs _ hgs with ⟨m, n, hlt, hr⟩
exact ⟨g m, g n, g.strictMono hlt, hr⟩
· rcases ht _ hgt with ⟨m, n, hlt, hr⟩
exact ⟨g m, g n, g.strictMono hlt, hr⟩
#align set.partially_well_ordered_on.union Set.PartiallyWellOrderedOn.union
@[simp]
theorem partiallyWellOrderedOn_union :
(s ∪ t).PartiallyWellOrderedOn r ↔ s.PartiallyWellOrderedOn r ∧ t.PartiallyWellOrderedOn r :=
⟨fun h => ⟨h.mono subset_union_left, h.mono subset_union_right⟩, fun h =>
h.1.union h.2⟩
#align set.partially_well_ordered_on_union Set.partiallyWellOrderedOn_union
theorem PartiallyWellOrderedOn.image_of_monotone_on (hs : s.PartiallyWellOrderedOn r)
(hf : ∀ a₁ ∈ s, ∀ a₂ ∈ s, r a₁ a₂ → r' (f a₁) (f a₂)) : (f '' s).PartiallyWellOrderedOn r' := by
intro g' hg'
choose g hgs heq using hg'
obtain rfl : f ∘ g = g' := funext heq
obtain ⟨m, n, hlt, hmn⟩ := hs g hgs
exact ⟨m, n, hlt, hf _ (hgs m) _ (hgs n) hmn⟩
#align set.partially_well_ordered_on.image_of_monotone_on Set.PartiallyWellOrderedOn.image_of_monotone_on
theorem _root_.IsAntichain.finite_of_partiallyWellOrderedOn (ha : IsAntichain r s)
(hp : s.PartiallyWellOrderedOn r) : s.Finite := by
refine not_infinite.1 fun hi => ?_
obtain ⟨m, n, hmn, h⟩ := hp (fun n => hi.natEmbedding _ n) fun n => (hi.natEmbedding _ n).2
exact hmn.ne ((hi.natEmbedding _).injective <| Subtype.val_injective <|
ha.eq (hi.natEmbedding _ m).2 (hi.natEmbedding _ n).2 h)
#align is_antichain.finite_of_partially_well_ordered_on IsAntichain.finite_of_partiallyWellOrderedOn
section IsRefl
variable [IsRefl α r]
protected theorem Finite.partiallyWellOrderedOn (hs : s.Finite) : s.PartiallyWellOrderedOn r := by
intro f hf
obtain ⟨m, n, hmn, h⟩ := hs.exists_lt_map_eq_of_forall_mem hf
exact ⟨m, n, hmn, h.subst <| refl (f m)⟩
#align set.finite.partially_well_ordered_on Set.Finite.partiallyWellOrderedOn
theorem _root_.IsAntichain.partiallyWellOrderedOn_iff (hs : IsAntichain r s) :
s.PartiallyWellOrderedOn r ↔ s.Finite :=
⟨hs.finite_of_partiallyWellOrderedOn, Finite.partiallyWellOrderedOn⟩
#align is_antichain.partially_well_ordered_on_iff IsAntichain.partiallyWellOrderedOn_iff
@[simp]
theorem partiallyWellOrderedOn_singleton (a : α) : PartiallyWellOrderedOn {a} r :=
(finite_singleton a).partiallyWellOrderedOn
#align set.partially_well_ordered_on_singleton Set.partiallyWellOrderedOn_singleton
@[nontriviality]
theorem Subsingleton.partiallyWellOrderedOn (hs : s.Subsingleton) : PartiallyWellOrderedOn s r :=
hs.finite.partiallyWellOrderedOn
@[simp]
theorem partiallyWellOrderedOn_insert :
PartiallyWellOrderedOn (insert a s) r ↔ PartiallyWellOrderedOn s r := by
simp only [← singleton_union, partiallyWellOrderedOn_union,
partiallyWellOrderedOn_singleton, true_and_iff]
#align set.partially_well_ordered_on_insert Set.partiallyWellOrderedOn_insert
protected theorem PartiallyWellOrderedOn.insert (h : PartiallyWellOrderedOn s r) (a : α) :
PartiallyWellOrderedOn (insert a s) r :=
partiallyWellOrderedOn_insert.2 h
#align set.partially_well_ordered_on.insert Set.PartiallyWellOrderedOn.insert
theorem partiallyWellOrderedOn_iff_finite_antichains [IsSymm α r] :
s.PartiallyWellOrderedOn r ↔ ∀ t, t ⊆ s → IsAntichain r t → t.Finite := by
refine ⟨fun h t ht hrt => hrt.finite_of_partiallyWellOrderedOn (h.mono ht), ?_⟩
rintro hs f hf
by_contra! H
refine infinite_range_of_injective (fun m n hmn => ?_) (hs _ (range_subset_iff.2 hf) ?_)
· obtain h | h | h := lt_trichotomy m n
· refine (H _ _ h ?_).elim
rw [hmn]
exact refl _
· exact h
· refine (H _ _ h ?_).elim
rw [hmn]
exact refl _
rintro _ ⟨m, hm, rfl⟩ _ ⟨n, hn, rfl⟩ hmn
obtain h | h := (ne_of_apply_ne _ hmn).lt_or_lt
· exact H _ _ h
· exact mt symm (H _ _ h)
#align set.partially_well_ordered_on_iff_finite_antichains Set.partiallyWellOrderedOn_iff_finite_antichains
variable [IsTrans α r]
theorem PartiallyWellOrderedOn.exists_monotone_subseq (h : s.PartiallyWellOrderedOn r) (f : ℕ → α)
(hf : ∀ n, f n ∈ s) : ∃ g : ℕ ↪o ℕ, ∀ m n : ℕ, m ≤ n → r (f (g m)) (f (g n)) := by
obtain ⟨g, h1 | h2⟩ := exists_increasing_or_nonincreasing_subseq r f
· refine ⟨g, fun m n hle => ?_⟩
obtain hlt | rfl := hle.lt_or_eq
exacts [h1 m n hlt, refl_of r _]
· exfalso
obtain ⟨m, n, hlt, hle⟩ := h (f ∘ g) fun n => hf _
exact h2 m n hlt hle
#align set.partially_well_ordered_on.exists_monotone_subseq Set.PartiallyWellOrderedOn.exists_monotone_subseq
theorem partiallyWellOrderedOn_iff_exists_monotone_subseq :
s.PartiallyWellOrderedOn r ↔
∀ f : ℕ → α, (∀ n, f n ∈ s) → ∃ g : ℕ ↪o ℕ, ∀ m n : ℕ, m ≤ n → r (f (g m)) (f (g n)) := by
constructor <;> intro h f hf
· exact h.exists_monotone_subseq f hf
· obtain ⟨g, gmon⟩ := h f hf
exact ⟨g 0, g 1, g.lt_iff_lt.2 zero_lt_one, gmon _ _ zero_le_one⟩
#align set.partially_well_ordered_on_iff_exists_monotone_subseq Set.partiallyWellOrderedOn_iff_exists_monotone_subseq
protected theorem PartiallyWellOrderedOn.prod {t : Set β} (hs : PartiallyWellOrderedOn s r)
(ht : PartiallyWellOrderedOn t r') :
PartiallyWellOrderedOn (s ×ˢ t) fun x y : α × β => r x.1 y.1 ∧ r' x.2 y.2 := by
intro f hf
obtain ⟨g₁, h₁⟩ := hs.exists_monotone_subseq (Prod.fst ∘ f) fun n => (hf n).1
obtain ⟨m, n, hlt, hle⟩ := ht (Prod.snd ∘ f ∘ g₁) fun n => (hf _).2
exact ⟨g₁ m, g₁ n, g₁.strictMono hlt, h₁ _ _ hlt.le, hle⟩
#align set.partially_well_ordered_on.prod Set.PartiallyWellOrderedOn.prod
end IsRefl
theorem PartiallyWellOrderedOn.wellFoundedOn [IsPreorder α r] (h : s.PartiallyWellOrderedOn r) :
s.WellFoundedOn fun a b => r a b ∧ ¬r b a := by
letI : Preorder α :=
{ le := r
le_refl := refl_of r
le_trans := fun _ _ _ => trans_of r }
change s.WellFoundedOn (· < ·)
replace h : s.PartiallyWellOrderedOn (· ≤ ·) := h -- Porting note: was `change _ at h`
rw [wellFoundedOn_iff_no_descending_seq]
intro f hf
obtain ⟨m, n, hlt, hle⟩ := h f hf
exact (f.map_rel_iff.2 hlt).not_le hle
#align set.partially_well_ordered_on.well_founded_on Set.PartiallyWellOrderedOn.wellFoundedOn
end PartiallyWellOrderedOn
section IsPWO
variable [Preorder α] [Preorder β] {s t : Set α}
/-- A subset of a preorder is partially well-ordered when any infinite sequence contains
a monotone subsequence of length 2 (or equivalently, an infinite monotone subsequence). -/
def IsPWO (s : Set α) : Prop :=
PartiallyWellOrderedOn s (· ≤ ·)
#align set.is_pwo Set.IsPWO
nonrec theorem IsPWO.mono (ht : t.IsPWO) : s ⊆ t → s.IsPWO := ht.mono
#align set.is_pwo.mono Set.IsPWO.mono
nonrec theorem IsPWO.exists_monotone_subseq (h : s.IsPWO) (f : ℕ → α) (hf : ∀ n, f n ∈ s) :
∃ g : ℕ ↪o ℕ, Monotone (f ∘ g) :=
h.exists_monotone_subseq f hf
#align set.is_pwo.exists_monotone_subseq Set.IsPWO.exists_monotone_subseq
theorem isPWO_iff_exists_monotone_subseq :
s.IsPWO ↔ ∀ f : ℕ → α, (∀ n, f n ∈ s) → ∃ g : ℕ ↪o ℕ, Monotone (f ∘ g) :=
partiallyWellOrderedOn_iff_exists_monotone_subseq
#align set.is_pwo_iff_exists_monotone_subseq Set.isPWO_iff_exists_monotone_subseq
protected theorem IsPWO.isWF (h : s.IsPWO) : s.IsWF := by
simpa only [← lt_iff_le_not_le] using h.wellFoundedOn
#align set.is_pwo.is_wf Set.IsPWO.isWF
nonrec theorem IsPWO.prod {t : Set β} (hs : s.IsPWO) (ht : t.IsPWO) : IsPWO (s ×ˢ t) :=
hs.prod ht
#align set.is_pwo.prod Set.IsPWO.prod
theorem IsPWO.image_of_monotoneOn (hs : s.IsPWO) {f : α → β} (hf : MonotoneOn f s) :
IsPWO (f '' s) :=
hs.image_of_monotone_on hf
#align set.is_pwo.image_of_monotone_on Set.IsPWO.image_of_monotoneOn
theorem IsPWO.image_of_monotone (hs : s.IsPWO) {f : α → β} (hf : Monotone f) : IsPWO (f '' s) :=
hs.image_of_monotone_on (hf.monotoneOn _)
#align set.is_pwo.image_of_monotone Set.IsPWO.image_of_monotone
protected nonrec theorem IsPWO.union (hs : IsPWO s) (ht : IsPWO t) : IsPWO (s ∪ t) :=
hs.union ht
#align set.is_pwo.union Set.IsPWO.union
@[simp]
theorem isPWO_union : IsPWO (s ∪ t) ↔ IsPWO s ∧ IsPWO t :=
partiallyWellOrderedOn_union
#align set.is_pwo_union Set.isPWO_union
protected theorem Finite.isPWO (hs : s.Finite) : IsPWO s := hs.partiallyWellOrderedOn
#align set.finite.is_pwo Set.Finite.isPWO
@[simp] theorem isPWO_of_finite [Finite α] : s.IsPWO := s.toFinite.isPWO
#align set.is_pwo_of_finite Set.isPWO_of_finite
@[simp] theorem isPWO_singleton (a : α) : IsPWO ({a} : Set α) := (finite_singleton a).isPWO
#align set.is_pwo_singleton Set.isPWO_singleton
@[simp] theorem isPWO_empty : IsPWO (∅ : Set α) := finite_empty.isPWO
#align set.is_pwo_empty Set.isPWO_empty
protected theorem Subsingleton.isPWO (hs : s.Subsingleton) : IsPWO s := hs.finite.isPWO
#align set.subsingleton.is_pwo Set.Subsingleton.isPWO
@[simp]
theorem isPWO_insert {a} : IsPWO (insert a s) ↔ IsPWO s := by
simp only [← singleton_union, isPWO_union, isPWO_singleton, true_and_iff]
#align set.is_pwo_insert Set.isPWO_insert
protected theorem IsPWO.insert (h : IsPWO s) (a : α) : IsPWO (insert a s) :=
isPWO_insert.2 h
#align set.is_pwo.insert Set.IsPWO.insert
protected theorem Finite.isWF (hs : s.Finite) : IsWF s := hs.isPWO.isWF
#align set.finite.is_wf Set.Finite.isWF
@[simp] theorem isWF_singleton {a : α} : IsWF ({a} : Set α) := (finite_singleton a).isWF
#align set.is_wf_singleton Set.isWF_singleton
protected theorem Subsingleton.isWF (hs : s.Subsingleton) : IsWF s := hs.isPWO.isWF
#align set.subsingleton.is_wf Set.Subsingleton.isWF
@[simp]
theorem isWF_insert {a} : IsWF (insert a s) ↔ IsWF s := by
simp only [← singleton_union, isWF_union, isWF_singleton, true_and_iff]
#align set.is_wf_insert Set.isWF_insert
protected theorem IsWF.insert (h : IsWF s) (a : α) : IsWF (insert a s) :=
isWF_insert.2 h
#align set.is_wf.insert Set.IsWF.insert
end IsPWO
section WellFoundedOn
variable {r : α → α → Prop} [IsStrictOrder α r] {s : Set α} {a : α}
protected theorem Finite.wellFoundedOn (hs : s.Finite) : s.WellFoundedOn r :=
letI := partialOrderOfSO r
hs.isWF
#align set.finite.well_founded_on Set.Finite.wellFoundedOn
@[simp]
theorem wellFoundedOn_singleton : WellFoundedOn ({a} : Set α) r :=
(finite_singleton a).wellFoundedOn
#align set.well_founded_on_singleton Set.wellFoundedOn_singleton
protected theorem Subsingleton.wellFoundedOn (hs : s.Subsingleton) : s.WellFoundedOn r :=
hs.finite.wellFoundedOn
#align set.subsingleton.well_founded_on Set.Subsingleton.wellFoundedOn
@[simp]
theorem wellFoundedOn_insert : WellFoundedOn (insert a s) r ↔ WellFoundedOn s r := by
simp only [← singleton_union, wellFoundedOn_union, wellFoundedOn_singleton, true_and_iff]
#align set.well_founded_on_insert Set.wellFoundedOn_insert
protected theorem WellFoundedOn.insert (h : WellFoundedOn s r) (a : α) :
WellFoundedOn (insert a s) r :=
wellFoundedOn_insert.2 h
#align set.well_founded_on.insert Set.WellFoundedOn.insert
end WellFoundedOn
section LinearOrder
variable [LinearOrder α] {s : Set α}
protected theorem IsWF.isPWO (hs : s.IsWF) : s.IsPWO := by
intro f hf
lift f to ℕ → s using hf
rcases hs.has_min (range f) (range_nonempty _) with ⟨_, ⟨m, rfl⟩, hm⟩
simp only [forall_mem_range, not_lt] at hm
exact ⟨m, m + 1, lt_add_one m, hm _⟩
#align set.is_wf.is_pwo Set.IsWF.isPWO
/-- In a linear order, the predicates `Set.IsWF` and `Set.IsPWO` are equivalent. -/
theorem isWF_iff_isPWO : s.IsWF ↔ s.IsPWO :=
⟨IsWF.isPWO, IsPWO.isWF⟩
#align set.is_wf_iff_is_pwo Set.isWF_iff_isPWO
end LinearOrder
end Set
namespace Finset
variable {r : α → α → Prop}
@[simp]
protected theorem partiallyWellOrderedOn [IsRefl α r] (s : Finset α) :
(s : Set α).PartiallyWellOrderedOn r :=
s.finite_toSet.partiallyWellOrderedOn
#align finset.partially_well_ordered_on Finset.partiallyWellOrderedOn
@[simp]
protected theorem isPWO [Preorder α] (s : Finset α) : Set.IsPWO (↑s : Set α) :=
s.partiallyWellOrderedOn
#align finset.is_pwo Finset.isPWO
@[simp]
protected theorem isWF [Preorder α] (s : Finset α) : Set.IsWF (↑s : Set α) :=
s.finite_toSet.isWF
#align finset.is_wf Finset.isWF
@[simp]
protected theorem wellFoundedOn [IsStrictOrder α r] (s : Finset α) :
Set.WellFoundedOn (↑s : Set α) r :=
letI := partialOrderOfSO r
s.isWF
#align finset.well_founded_on Finset.wellFoundedOn
theorem wellFoundedOn_sup [IsStrictOrder α r] (s : Finset ι) {f : ι → Set α} :
(s.sup f).WellFoundedOn r ↔ ∀ i ∈ s, (f i).WellFoundedOn r :=
Finset.cons_induction_on s (by simp) fun a s ha hs => by simp [-sup_set_eq_biUnion, hs]
#align finset.well_founded_on_sup Finset.wellFoundedOn_sup
theorem partiallyWellOrderedOn_sup (s : Finset ι) {f : ι → Set α} :
(s.sup f).PartiallyWellOrderedOn r ↔ ∀ i ∈ s, (f i).PartiallyWellOrderedOn r :=
Finset.cons_induction_on s (by simp) fun a s ha hs => by simp [-sup_set_eq_biUnion, hs]
#align finset.partially_well_ordered_on_sup Finset.partiallyWellOrderedOn_sup
theorem isWF_sup [Preorder α] (s : Finset ι) {f : ι → Set α} :
(s.sup f).IsWF ↔ ∀ i ∈ s, (f i).IsWF :=
s.wellFoundedOn_sup
#align finset.is_wf_sup Finset.isWF_sup
theorem isPWO_sup [Preorder α] (s : Finset ι) {f : ι → Set α} :
(s.sup f).IsPWO ↔ ∀ i ∈ s, (f i).IsPWO :=
s.partiallyWellOrderedOn_sup
#align finset.is_pwo_sup Finset.isPWO_sup
@[simp]
theorem wellFoundedOn_bUnion [IsStrictOrder α r] (s : Finset ι) {f : ι → Set α} :
(⋃ i ∈ s, f i).WellFoundedOn r ↔ ∀ i ∈ s, (f i).WellFoundedOn r := by
simpa only [Finset.sup_eq_iSup] using s.wellFoundedOn_sup
#align finset.well_founded_on_bUnion Finset.wellFoundedOn_bUnion
@[simp]
theorem partiallyWellOrderedOn_bUnion (s : Finset ι) {f : ι → Set α} :
(⋃ i ∈ s, f i).PartiallyWellOrderedOn r ↔ ∀ i ∈ s, (f i).PartiallyWellOrderedOn r := by
simpa only [Finset.sup_eq_iSup] using s.partiallyWellOrderedOn_sup
#align finset.partially_well_ordered_on_bUnion Finset.partiallyWellOrderedOn_bUnion
@[simp]
theorem isWF_bUnion [Preorder α] (s : Finset ι) {f : ι → Set α} :
(⋃ i ∈ s, f i).IsWF ↔ ∀ i ∈ s, (f i).IsWF :=
s.wellFoundedOn_bUnion
#align finset.is_wf_bUnion Finset.isWF_bUnion
@[simp]
theorem isPWO_bUnion [Preorder α] (s : Finset ι) {f : ι → Set α} :
(⋃ i ∈ s, f i).IsPWO ↔ ∀ i ∈ s, (f i).IsPWO :=
s.partiallyWellOrderedOn_bUnion
#align finset.is_pwo_bUnion Finset.isPWO_bUnion
end Finset
namespace Set
section Preorder
variable [Preorder α] {s t : Set α} {a : α}
/-- `Set.IsWF.min` returns a minimal element of a nonempty well-founded set. -/
noncomputable nonrec def IsWF.min (hs : IsWF s) (hn : s.Nonempty) : α :=
hs.min univ (nonempty_iff_univ_nonempty.1 hn.to_subtype)
#align set.is_wf.min Set.IsWF.min
theorem IsWF.min_mem (hs : IsWF s) (hn : s.Nonempty) : hs.min hn ∈ s :=
(WellFounded.min hs univ (nonempty_iff_univ_nonempty.1 hn.to_subtype)).2
#align set.is_wf.min_mem Set.IsWF.min_mem
nonrec theorem IsWF.not_lt_min (hs : IsWF s) (hn : s.Nonempty) (ha : a ∈ s) : ¬a < hs.min hn :=
hs.not_lt_min univ (nonempty_iff_univ_nonempty.1 hn.to_subtype) (mem_univ (⟨a, ha⟩ : s))
#align set.is_wf.not_lt_min Set.IsWF.not_lt_min
theorem IsWF.min_of_subset_not_lt_min {hs : s.IsWF} {hsn : s.Nonempty} {ht : t.IsWF}
{htn : t.Nonempty} (hst : s ⊆ t) : ¬hs.min hsn < ht.min htn :=
ht.not_lt_min htn (hst (min_mem hs hsn))
@[simp]
theorem isWF_min_singleton (a) {hs : IsWF ({a} : Set α)} {hn : ({a} : Set α).Nonempty} :
hs.min hn = a :=
eq_of_mem_singleton (IsWF.min_mem hs hn)
#align set.is_wf_min_singleton Set.isWF_min_singleton
end Preorder
section LinearOrder
variable [LinearOrder α] {s t : Set α} {a : α}
theorem IsWF.min_le (hs : s.IsWF) (hn : s.Nonempty) (ha : a ∈ s) : hs.min hn ≤ a :=
le_of_not_lt (hs.not_lt_min hn ha)
#align set.is_wf.min_le Set.IsWF.min_le
theorem IsWF.le_min_iff (hs : s.IsWF) (hn : s.Nonempty) : a ≤ hs.min hn ↔ ∀ b, b ∈ s → a ≤ b :=
⟨fun ha _b hb => le_trans ha (hs.min_le hn hb), fun h => h _ (hs.min_mem _)⟩
#align set.is_wf.le_min_iff Set.IsWF.le_min_iff
theorem IsWF.min_le_min_of_subset {hs : s.IsWF} {hsn : s.Nonempty} {ht : t.IsWF} {htn : t.Nonempty}
(hst : s ⊆ t) : ht.min htn ≤ hs.min hsn :=
(IsWF.le_min_iff _ _).2 fun _b hb => ht.min_le htn (hst hb)
#align set.is_wf.min_le_min_of_subset Set.IsWF.min_le_min_of_subset
theorem IsWF.min_union (hs : s.IsWF) (hsn : s.Nonempty) (ht : t.IsWF) (htn : t.Nonempty) :
(hs.union ht).min (union_nonempty.2 (Or.intro_left _ hsn)) =
Min.min (hs.min hsn) (ht.min htn) := by
refine le_antisymm (le_min (IsWF.min_le_min_of_subset subset_union_left)
(IsWF.min_le_min_of_subset subset_union_right)) ?_
rw [min_le_iff]
exact ((mem_union _ _ _).1 ((hs.union ht).min_mem (union_nonempty.2 (.inl hsn)))).imp
(hs.min_le _) (ht.min_le _)
#align set.is_wf.min_union Set.IsWF.min_union
end LinearOrder
end Set
open Set
section LocallyFiniteOrder
variable {s : Set α} [Preorder α] [LocallyFiniteOrder α]
theorem BddBelow.wellFoundedOn_lt : BddBelow s → s.WellFoundedOn (· < ·) := by
rw [wellFoundedOn_iff_no_descending_seq]
rintro ⟨a, ha⟩ f hf
refine infinite_range_of_injective f.injective ?_
exact (finite_Icc a <| f 0).subset <| range_subset_iff.2 <| fun n =>
⟨ha <| hf _, antitone_iff_forall_lt.2 (fun a b hab => (f.map_rel_iff.2 hab).le) <| zero_le _⟩
theorem BddAbove.wellFoundedOn_gt : BddAbove s → s.WellFoundedOn (· > ·) :=
fun h => h.dual.wellFoundedOn_lt
end LocallyFiniteOrder
namespace Set.PartiallyWellOrderedOn
variable {r : α → α → Prop}
/-- In the context of partial well-orderings, a bad sequence is a nonincreasing sequence
whose range is contained in a particular set `s`. One exists if and only if `s` is not
partially well-ordered. -/
def IsBadSeq (r : α → α → Prop) (s : Set α) (f : ℕ → α) : Prop :=
(∀ n, f n ∈ s) ∧ ∀ m n : ℕ, m < n → ¬r (f m) (f n)
#align set.partially_well_ordered_on.is_bad_seq Set.PartiallyWellOrderedOn.IsBadSeq
theorem iff_forall_not_isBadSeq (r : α → α → Prop) (s : Set α) :
s.PartiallyWellOrderedOn r ↔ ∀ f, ¬IsBadSeq r s f :=
forall_congr' fun f => by simp [IsBadSeq]
#align set.partially_well_ordered_on.iff_forall_not_is_bad_seq Set.PartiallyWellOrderedOn.iff_forall_not_isBadSeq
/-- This indicates that every bad sequence `g` that agrees with `f` on the first `n`
terms has `rk (f n) ≤ rk (g n)`. -/
def IsMinBadSeq (r : α → α → Prop) (rk : α → ℕ) (s : Set α) (n : ℕ) (f : ℕ → α) : Prop :=
∀ g : ℕ → α, (∀ m : ℕ, m < n → f m = g m) → rk (g n) < rk (f n) → ¬IsBadSeq r s g
#align set.partially_well_ordered_on.is_min_bad_seq Set.PartiallyWellOrderedOn.IsMinBadSeq
/-- Given a bad sequence `f`, this constructs a bad sequence that agrees with `f` on the first `n`
terms and is minimal at `n`.
-/
noncomputable def minBadSeqOfBadSeq (r : α → α → Prop) (rk : α → ℕ) (s : Set α) (n : ℕ) (f : ℕ → α)
(hf : IsBadSeq r s f) :
{ g : ℕ → α // (∀ m : ℕ, m < n → f m = g m) ∧ IsBadSeq r s g ∧ IsMinBadSeq r rk s n g } := by
classical
have h : ∃ (k : ℕ) (g : ℕ → α), (∀ m, m < n → f m = g m) ∧ IsBadSeq r s g ∧ rk (g n) = k :=
⟨_, f, fun _ _ => rfl, hf, rfl⟩
obtain ⟨h1, h2, h3⟩ := Classical.choose_spec (Nat.find_spec h)
refine ⟨Classical.choose (Nat.find_spec h), h1, by convert h2, fun g hg1 hg2 con => ?_⟩
refine Nat.find_min h ?_ ⟨g, fun m mn => (h1 m mn).trans (hg1 m mn), con, rfl⟩
rwa [← h3]
#align set.partially_well_ordered_on.min_bad_seq_of_bad_seq Set.PartiallyWellOrderedOn.minBadSeqOfBadSeq
theorem exists_min_bad_of_exists_bad (r : α → α → Prop) (rk : α → ℕ) (s : Set α) :
(∃ f, IsBadSeq r s f) → ∃ f, IsBadSeq r s f ∧ ∀ n, IsMinBadSeq r rk s n f := by
rintro ⟨f0, hf0 : IsBadSeq r s f0⟩
let fs : ∀ n : ℕ, { f : ℕ → α // IsBadSeq r s f ∧ IsMinBadSeq r rk s n f } := by
refine Nat.rec ?_ fun n fn => ?_
· exact ⟨(minBadSeqOfBadSeq r rk s 0 f0 hf0).1, (minBadSeqOfBadSeq r rk s 0 f0 hf0).2.2⟩
· exact ⟨(minBadSeqOfBadSeq r rk s (n + 1) fn.1 fn.2.1).1,
(minBadSeqOfBadSeq r rk s (n + 1) fn.1 fn.2.1).2.2⟩
have h : ∀ m n, m ≤ n → (fs m).1 m = (fs n).1 m := fun m n mn => by
obtain ⟨k, rfl⟩ := exists_add_of_le mn; clear mn
induction' k with k ih
· rfl
· rw [ih, (minBadSeqOfBadSeq r rk s (m + k + 1) (fs (m + k)).1 (fs (m + k)).2.1).2.1 m
(Nat.lt_succ_iff.2 (Nat.add_le_add_left k.zero_le m))]
rfl
refine ⟨fun n => (fs n).1 n, ⟨fun n => (fs n).2.1.1 n, fun m n mn => ?_⟩, fun n g hg1 hg2 => ?_⟩
· dsimp
rw [h m n mn.le]
exact (fs n).2.1.2 m n mn
· refine (fs n).2.2 g (fun m mn => ?_) hg2
rw [← h m n mn.le, ← hg1 m mn]
#align set.partially_well_ordered_on.exists_min_bad_of_exists_bad Set.PartiallyWellOrderedOn.exists_min_bad_of_exists_bad
theorem iff_not_exists_isMinBadSeq (rk : α → ℕ) {s : Set α} :
s.PartiallyWellOrderedOn r ↔ ¬∃ f, IsBadSeq r s f ∧ ∀ n, IsMinBadSeq r rk s n f := by
rw [iff_forall_not_isBadSeq, ← not_exists, not_congr]
constructor
· apply exists_min_bad_of_exists_bad
· rintro ⟨f, hf1, -⟩
exact ⟨f, hf1⟩
#align set.partially_well_ordered_on.iff_not_exists_is_min_bad_seq Set.PartiallyWellOrderedOn.iff_not_exists_isMinBadSeq
/-- Higman's Lemma, which states that for any reflexive, transitive relation `r` which is
partially well-ordered on a set `s`, the relation `List.SublistForall₂ r` is partially
well-ordered on the set of lists of elements of `s`. That relation is defined so that
`List.SublistForall₂ r l₁ l₂` whenever `l₁` related pointwise by `r` to a sublist of `l₂`. -/
theorem partiallyWellOrderedOn_sublistForall₂ (r : α → α → Prop) [IsRefl α r] [IsTrans α r]
{s : Set α} (h : s.PartiallyWellOrderedOn r) :
{ l : List α | ∀ x, x ∈ l → x ∈ s }.PartiallyWellOrderedOn (List.SublistForall₂ r) := by
rcases isEmpty_or_nonempty α
· exact subsingleton_of_subsingleton.partiallyWellOrderedOn
inhabit α
rw [iff_not_exists_isMinBadSeq List.length]
rintro ⟨f, hf1, hf2⟩
have hnil : ∀ n, f n ≠ List.nil := fun n con =>
hf1.2 n n.succ n.lt_succ_self (con.symm ▸ List.SublistForall₂.nil)
have : ∀ n, (f n).headI ∈ s :=
fun n => hf1.1 n _ (List.head!_mem_self (hnil n))
obtain ⟨g, hg⟩ := h.exists_monotone_subseq (fun n => (f n).headI) this
have hf' :=
hf2 (g 0) (fun n => if n < g 0 then f n else List.tail (f (g (n - g 0))))
(fun m hm => (if_pos hm).symm) ?_
swap;
· simp only [if_neg (lt_irrefl (g 0)), tsub_self]
rw [List.length_tail, ← Nat.pred_eq_sub_one]
exact Nat.pred_lt fun con => hnil _ (List.length_eq_zero.1 con)
rw [IsBadSeq] at hf'
push_neg at hf'
obtain ⟨m, n, mn, hmn⟩ := hf' fun n x hx => by
split_ifs at hx with hn
exacts [hf1.1 _ _ hx, hf1.1 _ _ (List.tail_subset _ hx)]
by_cases hn : n < g 0
· apply hf1.2 m n mn
rwa [if_pos hn, if_pos (mn.trans hn)] at hmn
· obtain ⟨n', rfl⟩ := exists_add_of_le (not_lt.1 hn)
rw [if_neg hn, add_comm (g 0) n', add_tsub_cancel_right] at hmn
split_ifs at hmn with hm
· apply hf1.2 m (g n') (lt_of_lt_of_le hm (g.monotone n'.zero_le))
exact _root_.trans hmn (List.tail_sublistForall₂_self _)
· rw [← tsub_lt_iff_left (le_of_not_lt hm)] at mn
apply hf1.2 _ _ (g.lt_iff_lt.2 mn)
rw [← List.cons_head!_tail (hnil (g (m - g 0))), ← List.cons_head!_tail (hnil (g n'))]
exact List.SublistForall₂.cons (hg _ _ (le_of_lt mn)) hmn
#align set.partially_well_ordered_on.partially_well_ordered_on_sublist_forall₂ Set.PartiallyWellOrderedOn.partiallyWellOrderedOn_sublistForall₂
| Mathlib/Order/WellFoundedSet.lean | 834 | 865 | theorem subsetProdLex [PartialOrder α] [Preorder β] {s : Set (α ×ₗ β)}
(hα : ((fun (x : α ×ₗ β) => (ofLex x).1)'' s).IsPWO)
(hβ : ∀ a, {y | toLex (a, y) ∈ s}.IsPWO) : s.IsPWO := by |
intro f hf
rw [isPWO_iff_exists_monotone_subseq] at hα
obtain ⟨g, hg⟩ : ∃ (g : (ℕ ↪o ℕ)), Monotone fun n => (ofLex f (g n)).1 :=
hα (fun n => (ofLex f n).1) (fun k => mem_image_of_mem (fun x => (ofLex x).1) (hf k))
have hhg : ∀ n, (ofLex f (g 0)).1 ≤ (ofLex f (g n)).1 := fun n => hg n.zero_le
by_cases hc : ∃ n, (ofLex f (g 0)).1 < (ofLex f (g n)).1
· obtain ⟨n, hn⟩ := hc
use (g 0), (g n)
constructor
· by_contra hx
simp_all
· exact (Prod.Lex.le_iff (f (g 0)) _).mpr <| Or.inl hn
· have hhc : ∀ n, (ofLex f (g 0)).1 = (ofLex f (g n)).1 := by
intro n
rw [not_exists] at hc
exact (hhg n).eq_of_not_lt (hc n)
obtain ⟨g', hg'⟩ : ∃ g' : ℕ ↪o ℕ, Monotone ((fun n ↦ (ofLex f (g (g' n))).2)) := by
simp_rw [isPWO_iff_exists_monotone_subseq] at hβ
apply hβ (ofLex f (g 0)).1 fun n ↦ (ofLex f (g n)).2
intro n
rw [hhc n]
simpa using hf _
use (g (g' 0)), (g (g' 1))
suffices (f (g (g' 0))) ≤ (f (g (g' 1))) by simpa
· refine (Prod.Lex.le_iff (f (g (g' 0))) (f (g (g' 1)))).mpr ?_
right
constructor
· exact (hhc (g' 0)).symm.trans (hhc (g' 1))
· exact hg' zero_le_one
|
/-
Copyright (c) 2020 Yury G. Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury G. Kudryashov, Patrick Massot
-/
import Mathlib.Order.Interval.Set.UnorderedInterval
import Mathlib.Algebra.Order.Interval.Set.Monoid
import Mathlib.Data.Set.Pointwise.Basic
import Mathlib.Algebra.Order.Field.Basic
import Mathlib.Algebra.Order.Group.MinMax
#align_import data.set.pointwise.interval from "leanprover-community/mathlib"@"2196ab363eb097c008d4497125e0dde23fb36db2"
/-!
# (Pre)images of intervals
In this file we prove a bunch of trivial lemmas like “if we add `a` to all points of `[b, c]`,
then we get `[a + b, a + c]`”. For the functions `x ↦ x ± a`, `x ↦ a ± x`, and `x ↦ -x` we prove
lemmas about preimages and images of all intervals. We also prove a few lemmas about images under
`x ↦ a * x`, `x ↦ x * a` and `x ↦ x⁻¹`.
-/
open Interval Pointwise
variable {α : Type*}
namespace Set
/-! ### Binary pointwise operations
Note that the subset operations below only cover the cases with the largest possible intervals on
the LHS: to conclude that `Ioo a b * Ioo c d ⊆ Ioo (a * c) (c * d)`, you can use monotonicity of `*`
and `Set.Ico_mul_Ioc_subset`.
TODO: repeat these lemmas for the generality of `mul_le_mul` (which assumes nonnegativity), which
the unprimed names have been reserved for
-/
section ContravariantLE
variable [Mul α] [Preorder α]
variable [CovariantClass α α (· * ·) (· ≤ ·)] [CovariantClass α α (Function.swap HMul.hMul) LE.le]
@[to_additive Icc_add_Icc_subset]
theorem Icc_mul_Icc_subset' (a b c d : α) : Icc a b * Icc c d ⊆ Icc (a * c) (b * d) := by
rintro x ⟨y, ⟨hya, hyb⟩, z, ⟨hzc, hzd⟩, rfl⟩
exact ⟨mul_le_mul' hya hzc, mul_le_mul' hyb hzd⟩
@[to_additive Iic_add_Iic_subset]
theorem Iic_mul_Iic_subset' (a b : α) : Iic a * Iic b ⊆ Iic (a * b) := by
rintro x ⟨y, hya, z, hzb, rfl⟩
exact mul_le_mul' hya hzb
@[to_additive Ici_add_Ici_subset]
theorem Ici_mul_Ici_subset' (a b : α) : Ici a * Ici b ⊆ Ici (a * b) := by
rintro x ⟨y, hya, z, hzb, rfl⟩
exact mul_le_mul' hya hzb
end ContravariantLE
section ContravariantLT
variable [Mul α] [PartialOrder α]
variable [CovariantClass α α (· * ·) (· < ·)] [CovariantClass α α (Function.swap HMul.hMul) LT.lt]
@[to_additive Icc_add_Ico_subset]
theorem Icc_mul_Ico_subset' (a b c d : α) : Icc a b * Ico c d ⊆ Ico (a * c) (b * d) := by
haveI := covariantClass_le_of_lt
rintro x ⟨y, ⟨hya, hyb⟩, z, ⟨hzc, hzd⟩, rfl⟩
exact ⟨mul_le_mul' hya hzc, mul_lt_mul_of_le_of_lt hyb hzd⟩
@[to_additive Ico_add_Icc_subset]
theorem Ico_mul_Icc_subset' (a b c d : α) : Ico a b * Icc c d ⊆ Ico (a * c) (b * d) := by
haveI := covariantClass_le_of_lt
rintro x ⟨y, ⟨hya, hyb⟩, z, ⟨hzc, hzd⟩, rfl⟩
exact ⟨mul_le_mul' hya hzc, mul_lt_mul_of_lt_of_le hyb hzd⟩
@[to_additive Ioc_add_Ico_subset]
theorem Ioc_mul_Ico_subset' (a b c d : α) : Ioc a b * Ico c d ⊆ Ioo (a * c) (b * d) := by
haveI := covariantClass_le_of_lt
rintro x ⟨y, ⟨hya, hyb⟩, z, ⟨hzc, hzd⟩, rfl⟩
exact ⟨mul_lt_mul_of_lt_of_le hya hzc, mul_lt_mul_of_le_of_lt hyb hzd⟩
@[to_additive Ico_add_Ioc_subset]
theorem Ico_mul_Ioc_subset' (a b c d : α) : Ico a b * Ioc c d ⊆ Ioo (a * c) (b * d) := by
haveI := covariantClass_le_of_lt
rintro x ⟨y, ⟨hya, hyb⟩, z, ⟨hzc, hzd⟩, rfl⟩
exact ⟨mul_lt_mul_of_le_of_lt hya hzc, mul_lt_mul_of_lt_of_le hyb hzd⟩
@[to_additive Iic_add_Iio_subset]
theorem Iic_mul_Iio_subset' (a b : α) : Iic a * Iio b ⊆ Iio (a * b) := by
haveI := covariantClass_le_of_lt
rintro x ⟨y, hya, z, hzb, rfl⟩
exact mul_lt_mul_of_le_of_lt hya hzb
@[to_additive Iio_add_Iic_subset]
theorem Iio_mul_Iic_subset' (a b : α) : Iio a * Iic b ⊆ Iio (a * b) := by
haveI := covariantClass_le_of_lt
rintro x ⟨y, hya, z, hzb, rfl⟩
exact mul_lt_mul_of_lt_of_le hya hzb
@[to_additive Ioi_add_Ici_subset]
theorem Ioi_mul_Ici_subset' (a b : α) : Ioi a * Ici b ⊆ Ioi (a * b) := by
haveI := covariantClass_le_of_lt
rintro x ⟨y, hya, z, hzb, rfl⟩
exact mul_lt_mul_of_lt_of_le hya hzb
@[to_additive Ici_add_Ioi_subset]
theorem Ici_mul_Ioi_subset' (a b : α) : Ici a * Ioi b ⊆ Ioi (a * b) := by
haveI := covariantClass_le_of_lt
rintro x ⟨y, hya, z, hzb, rfl⟩
exact mul_lt_mul_of_le_of_lt hya hzb
end ContravariantLT
section OrderedAddCommGroup
variable [OrderedAddCommGroup α] (a b c : α)
/-!
### Preimages under `x ↦ a + x`
-/
@[simp]
theorem preimage_const_add_Ici : (fun x => a + x) ⁻¹' Ici b = Ici (b - a) :=
ext fun _x => sub_le_iff_le_add'.symm
#align set.preimage_const_add_Ici Set.preimage_const_add_Ici
@[simp]
theorem preimage_const_add_Ioi : (fun x => a + x) ⁻¹' Ioi b = Ioi (b - a) :=
ext fun _x => sub_lt_iff_lt_add'.symm
#align set.preimage_const_add_Ioi Set.preimage_const_add_Ioi
@[simp]
theorem preimage_const_add_Iic : (fun x => a + x) ⁻¹' Iic b = Iic (b - a) :=
ext fun _x => le_sub_iff_add_le'.symm
#align set.preimage_const_add_Iic Set.preimage_const_add_Iic
@[simp]
theorem preimage_const_add_Iio : (fun x => a + x) ⁻¹' Iio b = Iio (b - a) :=
ext fun _x => lt_sub_iff_add_lt'.symm
#align set.preimage_const_add_Iio Set.preimage_const_add_Iio
@[simp]
theorem preimage_const_add_Icc : (fun x => a + x) ⁻¹' Icc b c = Icc (b - a) (c - a) := by
simp [← Ici_inter_Iic]
#align set.preimage_const_add_Icc Set.preimage_const_add_Icc
@[simp]
theorem preimage_const_add_Ico : (fun x => a + x) ⁻¹' Ico b c = Ico (b - a) (c - a) := by
simp [← Ici_inter_Iio]
#align set.preimage_const_add_Ico Set.preimage_const_add_Ico
@[simp]
theorem preimage_const_add_Ioc : (fun x => a + x) ⁻¹' Ioc b c = Ioc (b - a) (c - a) := by
simp [← Ioi_inter_Iic]
#align set.preimage_const_add_Ioc Set.preimage_const_add_Ioc
@[simp]
theorem preimage_const_add_Ioo : (fun x => a + x) ⁻¹' Ioo b c = Ioo (b - a) (c - a) := by
simp [← Ioi_inter_Iio]
#align set.preimage_const_add_Ioo Set.preimage_const_add_Ioo
/-!
### Preimages under `x ↦ x + a`
-/
@[simp]
theorem preimage_add_const_Ici : (fun x => x + a) ⁻¹' Ici b = Ici (b - a) :=
ext fun _x => sub_le_iff_le_add.symm
#align set.preimage_add_const_Ici Set.preimage_add_const_Ici
@[simp]
theorem preimage_add_const_Ioi : (fun x => x + a) ⁻¹' Ioi b = Ioi (b - a) :=
ext fun _x => sub_lt_iff_lt_add.symm
#align set.preimage_add_const_Ioi Set.preimage_add_const_Ioi
@[simp]
theorem preimage_add_const_Iic : (fun x => x + a) ⁻¹' Iic b = Iic (b - a) :=
ext fun _x => le_sub_iff_add_le.symm
#align set.preimage_add_const_Iic Set.preimage_add_const_Iic
@[simp]
theorem preimage_add_const_Iio : (fun x => x + a) ⁻¹' Iio b = Iio (b - a) :=
ext fun _x => lt_sub_iff_add_lt.symm
#align set.preimage_add_const_Iio Set.preimage_add_const_Iio
@[simp]
theorem preimage_add_const_Icc : (fun x => x + a) ⁻¹' Icc b c = Icc (b - a) (c - a) := by
simp [← Ici_inter_Iic]
#align set.preimage_add_const_Icc Set.preimage_add_const_Icc
@[simp]
theorem preimage_add_const_Ico : (fun x => x + a) ⁻¹' Ico b c = Ico (b - a) (c - a) := by
simp [← Ici_inter_Iio]
#align set.preimage_add_const_Ico Set.preimage_add_const_Ico
@[simp]
theorem preimage_add_const_Ioc : (fun x => x + a) ⁻¹' Ioc b c = Ioc (b - a) (c - a) := by
simp [← Ioi_inter_Iic]
#align set.preimage_add_const_Ioc Set.preimage_add_const_Ioc
@[simp]
theorem preimage_add_const_Ioo : (fun x => x + a) ⁻¹' Ioo b c = Ioo (b - a) (c - a) := by
simp [← Ioi_inter_Iio]
#align set.preimage_add_const_Ioo Set.preimage_add_const_Ioo
/-!
### Preimages under `x ↦ -x`
-/
@[simp]
theorem preimage_neg_Ici : -Ici a = Iic (-a) :=
ext fun _x => le_neg
#align set.preimage_neg_Ici Set.preimage_neg_Ici
@[simp]
theorem preimage_neg_Iic : -Iic a = Ici (-a) :=
ext fun _x => neg_le
#align set.preimage_neg_Iic Set.preimage_neg_Iic
@[simp]
theorem preimage_neg_Ioi : -Ioi a = Iio (-a) :=
ext fun _x => lt_neg
#align set.preimage_neg_Ioi Set.preimage_neg_Ioi
@[simp]
theorem preimage_neg_Iio : -Iio a = Ioi (-a) :=
ext fun _x => neg_lt
#align set.preimage_neg_Iio Set.preimage_neg_Iio
@[simp]
theorem preimage_neg_Icc : -Icc a b = Icc (-b) (-a) := by simp [← Ici_inter_Iic, inter_comm]
#align set.preimage_neg_Icc Set.preimage_neg_Icc
@[simp]
theorem preimage_neg_Ico : -Ico a b = Ioc (-b) (-a) := by
simp [← Ici_inter_Iio, ← Ioi_inter_Iic, inter_comm]
#align set.preimage_neg_Ico Set.preimage_neg_Ico
@[simp]
theorem preimage_neg_Ioc : -Ioc a b = Ico (-b) (-a) := by
simp [← Ioi_inter_Iic, ← Ici_inter_Iio, inter_comm]
#align set.preimage_neg_Ioc Set.preimage_neg_Ioc
@[simp]
theorem preimage_neg_Ioo : -Ioo a b = Ioo (-b) (-a) := by simp [← Ioi_inter_Iio, inter_comm]
#align set.preimage_neg_Ioo Set.preimage_neg_Ioo
/-!
### Preimages under `x ↦ x - a`
-/
@[simp]
theorem preimage_sub_const_Ici : (fun x => x - a) ⁻¹' Ici b = Ici (b + a) := by
simp [sub_eq_add_neg]
#align set.preimage_sub_const_Ici Set.preimage_sub_const_Ici
@[simp]
theorem preimage_sub_const_Ioi : (fun x => x - a) ⁻¹' Ioi b = Ioi (b + a) := by
simp [sub_eq_add_neg]
#align set.preimage_sub_const_Ioi Set.preimage_sub_const_Ioi
@[simp]
theorem preimage_sub_const_Iic : (fun x => x - a) ⁻¹' Iic b = Iic (b + a) := by
simp [sub_eq_add_neg]
#align set.preimage_sub_const_Iic Set.preimage_sub_const_Iic
@[simp]
theorem preimage_sub_const_Iio : (fun x => x - a) ⁻¹' Iio b = Iio (b + a) := by
simp [sub_eq_add_neg]
#align set.preimage_sub_const_Iio Set.preimage_sub_const_Iio
@[simp]
theorem preimage_sub_const_Icc : (fun x => x - a) ⁻¹' Icc b c = Icc (b + a) (c + a) := by
simp [sub_eq_add_neg]
#align set.preimage_sub_const_Icc Set.preimage_sub_const_Icc
@[simp]
theorem preimage_sub_const_Ico : (fun x => x - a) ⁻¹' Ico b c = Ico (b + a) (c + a) := by
simp [sub_eq_add_neg]
#align set.preimage_sub_const_Ico Set.preimage_sub_const_Ico
@[simp]
theorem preimage_sub_const_Ioc : (fun x => x - a) ⁻¹' Ioc b c = Ioc (b + a) (c + a) := by
simp [sub_eq_add_neg]
#align set.preimage_sub_const_Ioc Set.preimage_sub_const_Ioc
@[simp]
theorem preimage_sub_const_Ioo : (fun x => x - a) ⁻¹' Ioo b c = Ioo (b + a) (c + a) := by
simp [sub_eq_add_neg]
#align set.preimage_sub_const_Ioo Set.preimage_sub_const_Ioo
/-!
### Preimages under `x ↦ a - x`
-/
@[simp]
theorem preimage_const_sub_Ici : (fun x => a - x) ⁻¹' Ici b = Iic (a - b) :=
ext fun _x => le_sub_comm
#align set.preimage_const_sub_Ici Set.preimage_const_sub_Ici
@[simp]
theorem preimage_const_sub_Iic : (fun x => a - x) ⁻¹' Iic b = Ici (a - b) :=
ext fun _x => sub_le_comm
#align set.preimage_const_sub_Iic Set.preimage_const_sub_Iic
@[simp]
theorem preimage_const_sub_Ioi : (fun x => a - x) ⁻¹' Ioi b = Iio (a - b) :=
ext fun _x => lt_sub_comm
#align set.preimage_const_sub_Ioi Set.preimage_const_sub_Ioi
@[simp]
theorem preimage_const_sub_Iio : (fun x => a - x) ⁻¹' Iio b = Ioi (a - b) :=
ext fun _x => sub_lt_comm
#align set.preimage_const_sub_Iio Set.preimage_const_sub_Iio
@[simp]
theorem preimage_const_sub_Icc : (fun x => a - x) ⁻¹' Icc b c = Icc (a - c) (a - b) := by
simp [← Ici_inter_Iic, inter_comm]
#align set.preimage_const_sub_Icc Set.preimage_const_sub_Icc
@[simp]
theorem preimage_const_sub_Ico : (fun x => a - x) ⁻¹' Ico b c = Ioc (a - c) (a - b) := by
simp [← Ioi_inter_Iic, ← Ici_inter_Iio, inter_comm]
#align set.preimage_const_sub_Ico Set.preimage_const_sub_Ico
@[simp]
theorem preimage_const_sub_Ioc : (fun x => a - x) ⁻¹' Ioc b c = Ico (a - c) (a - b) := by
simp [← Ioi_inter_Iic, ← Ici_inter_Iio, inter_comm]
#align set.preimage_const_sub_Ioc Set.preimage_const_sub_Ioc
@[simp]
theorem preimage_const_sub_Ioo : (fun x => a - x) ⁻¹' Ioo b c = Ioo (a - c) (a - b) := by
simp [← Ioi_inter_Iio, inter_comm]
#align set.preimage_const_sub_Ioo Set.preimage_const_sub_Ioo
/-!
### Images under `x ↦ a + x`
-/
-- @[simp] -- Porting note (#10618): simp can prove this modulo `add_comm`
theorem image_const_add_Iic : (fun x => a + x) '' Iic b = Iic (a + b) := by simp [add_comm]
#align set.image_const_add_Iic Set.image_const_add_Iic
-- @[simp] -- Porting note (#10618): simp can prove this modulo `add_comm`
theorem image_const_add_Iio : (fun x => a + x) '' Iio b = Iio (a + b) := by simp [add_comm]
#align set.image_const_add_Iio Set.image_const_add_Iio
/-!
### Images under `x ↦ x + a`
-/
-- @[simp] -- Porting note (#10618): simp can prove this
theorem image_add_const_Iic : (fun x => x + a) '' Iic b = Iic (b + a) := by simp
#align set.image_add_const_Iic Set.image_add_const_Iic
-- @[simp] -- Porting note (#10618): simp can prove this
theorem image_add_const_Iio : (fun x => x + a) '' Iio b = Iio (b + a) := by simp
#align set.image_add_const_Iio Set.image_add_const_Iio
/-!
### Images under `x ↦ -x`
-/
theorem image_neg_Ici : Neg.neg '' Ici a = Iic (-a) := by simp
#align set.image_neg_Ici Set.image_neg_Ici
theorem image_neg_Iic : Neg.neg '' Iic a = Ici (-a) := by simp
#align set.image_neg_Iic Set.image_neg_Iic
theorem image_neg_Ioi : Neg.neg '' Ioi a = Iio (-a) := by simp
#align set.image_neg_Ioi Set.image_neg_Ioi
theorem image_neg_Iio : Neg.neg '' Iio a = Ioi (-a) := by simp
#align set.image_neg_Iio Set.image_neg_Iio
theorem image_neg_Icc : Neg.neg '' Icc a b = Icc (-b) (-a) := by simp
#align set.image_neg_Icc Set.image_neg_Icc
theorem image_neg_Ico : Neg.neg '' Ico a b = Ioc (-b) (-a) := by simp
#align set.image_neg_Ico Set.image_neg_Ico
theorem image_neg_Ioc : Neg.neg '' Ioc a b = Ico (-b) (-a) := by simp
#align set.image_neg_Ioc Set.image_neg_Ioc
theorem image_neg_Ioo : Neg.neg '' Ioo a b = Ioo (-b) (-a) := by simp
#align set.image_neg_Ioo Set.image_neg_Ioo
/-!
### Images under `x ↦ a - x`
-/
@[simp]
theorem image_const_sub_Ici : (fun x => a - x) '' Ici b = Iic (a - b) := by
have := image_comp (fun x => a + x) fun x => -x; dsimp [Function.comp_def] at this
simp [sub_eq_add_neg, this, add_comm]
#align set.image_const_sub_Ici Set.image_const_sub_Ici
@[simp]
theorem image_const_sub_Iic : (fun x => a - x) '' Iic b = Ici (a - b) := by
have := image_comp (fun x => a + x) fun x => -x; dsimp [Function.comp_def] at this
simp [sub_eq_add_neg, this, add_comm]
#align set.image_const_sub_Iic Set.image_const_sub_Iic
@[simp]
theorem image_const_sub_Ioi : (fun x => a - x) '' Ioi b = Iio (a - b) := by
have := image_comp (fun x => a + x) fun x => -x; dsimp [Function.comp_def] at this
simp [sub_eq_add_neg, this, add_comm]
#align set.image_const_sub_Ioi Set.image_const_sub_Ioi
@[simp]
theorem image_const_sub_Iio : (fun x => a - x) '' Iio b = Ioi (a - b) := by
have := image_comp (fun x => a + x) fun x => -x; dsimp [Function.comp_def] at this
simp [sub_eq_add_neg, this, add_comm]
#align set.image_const_sub_Iio Set.image_const_sub_Iio
@[simp]
theorem image_const_sub_Icc : (fun x => a - x) '' Icc b c = Icc (a - c) (a - b) := by
have := image_comp (fun x => a + x) fun x => -x; dsimp [Function.comp_def] at this
simp [sub_eq_add_neg, this, add_comm]
#align set.image_const_sub_Icc Set.image_const_sub_Icc
@[simp]
theorem image_const_sub_Ico : (fun x => a - x) '' Ico b c = Ioc (a - c) (a - b) := by
have := image_comp (fun x => a + x) fun x => -x; dsimp [Function.comp_def] at this
simp [sub_eq_add_neg, this, add_comm]
#align set.image_const_sub_Ico Set.image_const_sub_Ico
@[simp]
theorem image_const_sub_Ioc : (fun x => a - x) '' Ioc b c = Ico (a - c) (a - b) := by
have := image_comp (fun x => a + x) fun x => -x; dsimp [Function.comp_def] at this
simp [sub_eq_add_neg, this, add_comm]
#align set.image_const_sub_Ioc Set.image_const_sub_Ioc
@[simp]
theorem image_const_sub_Ioo : (fun x => a - x) '' Ioo b c = Ioo (a - c) (a - b) := by
have := image_comp (fun x => a + x) fun x => -x; dsimp [Function.comp_def] at this
simp [sub_eq_add_neg, this, add_comm]
#align set.image_const_sub_Ioo Set.image_const_sub_Ioo
/-!
### Images under `x ↦ x - a`
-/
@[simp]
theorem image_sub_const_Ici : (fun x => x - a) '' Ici b = Ici (b - a) := by simp [sub_eq_neg_add]
#align set.image_sub_const_Ici Set.image_sub_const_Ici
@[simp]
theorem image_sub_const_Iic : (fun x => x - a) '' Iic b = Iic (b - a) := by simp [sub_eq_neg_add]
#align set.image_sub_const_Iic Set.image_sub_const_Iic
@[simp]
theorem image_sub_const_Ioi : (fun x => x - a) '' Ioi b = Ioi (b - a) := by simp [sub_eq_neg_add]
#align set.image_sub_const_Ioi Set.image_sub_const_Ioi
@[simp]
theorem image_sub_const_Iio : (fun x => x - a) '' Iio b = Iio (b - a) := by simp [sub_eq_neg_add]
#align set.image_sub_const_Iio Set.image_sub_const_Iio
@[simp]
theorem image_sub_const_Icc : (fun x => x - a) '' Icc b c = Icc (b - a) (c - a) := by
simp [sub_eq_neg_add]
#align set.image_sub_const_Icc Set.image_sub_const_Icc
@[simp]
theorem image_sub_const_Ico : (fun x => x - a) '' Ico b c = Ico (b - a) (c - a) := by
simp [sub_eq_neg_add]
#align set.image_sub_const_Ico Set.image_sub_const_Ico
@[simp]
theorem image_sub_const_Ioc : (fun x => x - a) '' Ioc b c = Ioc (b - a) (c - a) := by
simp [sub_eq_neg_add]
#align set.image_sub_const_Ioc Set.image_sub_const_Ioc
@[simp]
theorem image_sub_const_Ioo : (fun x => x - a) '' Ioo b c = Ioo (b - a) (c - a) := by
simp [sub_eq_neg_add]
#align set.image_sub_const_Ioo Set.image_sub_const_Ioo
/-!
### Bijections
-/
theorem Iic_add_bij : BijOn (· + a) (Iic b) (Iic (b + a)) :=
image_add_const_Iic a b ▸ (add_left_injective _).injOn.bijOn_image
#align set.Iic_add_bij Set.Iic_add_bij
theorem Iio_add_bij : BijOn (· + a) (Iio b) (Iio (b + a)) :=
image_add_const_Iio a b ▸ (add_left_injective _).injOn.bijOn_image
#align set.Iio_add_bij Set.Iio_add_bij
end OrderedAddCommGroup
section LinearOrderedAddCommGroup
variable [LinearOrderedAddCommGroup α] (a b c d : α)
@[simp]
theorem preimage_const_add_uIcc : (fun x => a + x) ⁻¹' [[b, c]] = [[b - a, c - a]] := by
simp only [← Icc_min_max, preimage_const_add_Icc, min_sub_sub_right, max_sub_sub_right]
#align set.preimage_const_add_uIcc Set.preimage_const_add_uIcc
@[simp]
theorem preimage_add_const_uIcc : (fun x => x + a) ⁻¹' [[b, c]] = [[b - a, c - a]] := by
simpa only [add_comm] using preimage_const_add_uIcc a b c
#align set.preimage_add_const_uIcc Set.preimage_add_const_uIcc
-- TODO: Why is the notation `-[[a, b]]` broken?
@[simp]
theorem preimage_neg_uIcc : @Neg.neg (Set α) Set.neg [[a, b]] = [[-a, -b]] := by
simp only [← Icc_min_max, preimage_neg_Icc, min_neg_neg, max_neg_neg]
#align set.preimage_neg_uIcc Set.preimage_neg_uIcc
@[simp]
theorem preimage_sub_const_uIcc : (fun x => x - a) ⁻¹' [[b, c]] = [[b + a, c + a]] := by
simp [sub_eq_add_neg]
#align set.preimage_sub_const_uIcc Set.preimage_sub_const_uIcc
@[simp]
theorem preimage_const_sub_uIcc : (fun x => a - x) ⁻¹' [[b, c]] = [[a - b, a - c]] := by
simp_rw [← Icc_min_max, preimage_const_sub_Icc]
simp only [sub_eq_add_neg, min_add_add_left, max_add_add_left, min_neg_neg, max_neg_neg]
#align set.preimage_const_sub_uIcc Set.preimage_const_sub_uIcc
-- @[simp] -- Porting note (#10618): simp can prove this module `add_comm`
theorem image_const_add_uIcc : (fun x => a + x) '' [[b, c]] = [[a + b, a + c]] := by simp [add_comm]
#align set.image_const_add_uIcc Set.image_const_add_uIcc
-- @[simp] -- Porting note (#10618): simp can prove this
theorem image_add_const_uIcc : (fun x => x + a) '' [[b, c]] = [[b + a, c + a]] := by simp
#align set.image_add_const_uIcc Set.image_add_const_uIcc
@[simp]
theorem image_const_sub_uIcc : (fun x => a - x) '' [[b, c]] = [[a - b, a - c]] := by
have := image_comp (fun x => a + x) fun x => -x; dsimp [Function.comp_def] at this
simp [sub_eq_add_neg, this, add_comm]
#align set.image_const_sub_uIcc Set.image_const_sub_uIcc
@[simp]
theorem image_sub_const_uIcc : (fun x => x - a) '' [[b, c]] = [[b - a, c - a]] := by
simp [sub_eq_add_neg, add_comm]
#align set.image_sub_const_uIcc Set.image_sub_const_uIcc
theorem image_neg_uIcc : Neg.neg '' [[a, b]] = [[-a, -b]] := by simp
#align set.image_neg_uIcc Set.image_neg_uIcc
variable {a b c d}
/-- If `[c, d]` is a subinterval of `[a, b]`, then the distance between `c` and `d` is less than or
equal to that of `a` and `b` -/
theorem abs_sub_le_of_uIcc_subset_uIcc (h : [[c, d]] ⊆ [[a, b]]) : |d - c| ≤ |b - a| := by
rw [← max_sub_min_eq_abs, ← max_sub_min_eq_abs]
rw [uIcc_subset_uIcc_iff_le] at h
exact sub_le_sub h.2 h.1
#align set.abs_sub_le_of_uIcc_subset_uIcc Set.abs_sub_le_of_uIcc_subset_uIcc
/-- If `c ∈ [a, b]`, then the distance between `a` and `c` is less than or equal to
that of `a` and `b` -/
theorem abs_sub_left_of_mem_uIcc (h : c ∈ [[a, b]]) : |c - a| ≤ |b - a| :=
abs_sub_le_of_uIcc_subset_uIcc <| uIcc_subset_uIcc_left h
#align set.abs_sub_left_of_mem_uIcc Set.abs_sub_left_of_mem_uIcc
/-- If `x ∈ [a, b]`, then the distance between `c` and `b` is less than or equal to
that of `a` and `b` -/
theorem abs_sub_right_of_mem_uIcc (h : c ∈ [[a, b]]) : |b - c| ≤ |b - a| :=
abs_sub_le_of_uIcc_subset_uIcc <| uIcc_subset_uIcc_right h
#align set.abs_sub_right_of_mem_uIcc Set.abs_sub_right_of_mem_uIcc
end LinearOrderedAddCommGroup
/-!
### Multiplication and inverse in a field
-/
section LinearOrderedField
variable [LinearOrderedField α] {a : α}
@[simp]
theorem preimage_mul_const_Iio (a : α) {c : α} (h : 0 < c) :
(fun x => x * c) ⁻¹' Iio a = Iio (a / c) :=
ext fun _x => (lt_div_iff h).symm
#align set.preimage_mul_const_Iio Set.preimage_mul_const_Iio
@[simp]
theorem preimage_mul_const_Ioi (a : α) {c : α} (h : 0 < c) :
(fun x => x * c) ⁻¹' Ioi a = Ioi (a / c) :=
ext fun _x => (div_lt_iff h).symm
#align set.preimage_mul_const_Ioi Set.preimage_mul_const_Ioi
@[simp]
theorem preimage_mul_const_Iic (a : α) {c : α} (h : 0 < c) :
(fun x => x * c) ⁻¹' Iic a = Iic (a / c) :=
ext fun _x => (le_div_iff h).symm
#align set.preimage_mul_const_Iic Set.preimage_mul_const_Iic
@[simp]
theorem preimage_mul_const_Ici (a : α) {c : α} (h : 0 < c) :
(fun x => x * c) ⁻¹' Ici a = Ici (a / c) :=
ext fun _x => (div_le_iff h).symm
#align set.preimage_mul_const_Ici Set.preimage_mul_const_Ici
@[simp]
theorem preimage_mul_const_Ioo (a b : α) {c : α} (h : 0 < c) :
(fun x => x * c) ⁻¹' Ioo a b = Ioo (a / c) (b / c) := by simp [← Ioi_inter_Iio, h]
#align set.preimage_mul_const_Ioo Set.preimage_mul_const_Ioo
@[simp]
theorem preimage_mul_const_Ioc (a b : α) {c : α} (h : 0 < c) :
(fun x => x * c) ⁻¹' Ioc a b = Ioc (a / c) (b / c) := by simp [← Ioi_inter_Iic, h]
#align set.preimage_mul_const_Ioc Set.preimage_mul_const_Ioc
@[simp]
theorem preimage_mul_const_Ico (a b : α) {c : α} (h : 0 < c) :
(fun x => x * c) ⁻¹' Ico a b = Ico (a / c) (b / c) := by simp [← Ici_inter_Iio, h]
#align set.preimage_mul_const_Ico Set.preimage_mul_const_Ico
@[simp]
theorem preimage_mul_const_Icc (a b : α) {c : α} (h : 0 < c) :
(fun x => x * c) ⁻¹' Icc a b = Icc (a / c) (b / c) := by simp [← Ici_inter_Iic, h]
#align set.preimage_mul_const_Icc Set.preimage_mul_const_Icc
@[simp]
theorem preimage_mul_const_Iio_of_neg (a : α) {c : α} (h : c < 0) :
(fun x => x * c) ⁻¹' Iio a = Ioi (a / c) :=
ext fun _x => (div_lt_iff_of_neg h).symm
#align set.preimage_mul_const_Iio_of_neg Set.preimage_mul_const_Iio_of_neg
@[simp]
theorem preimage_mul_const_Ioi_of_neg (a : α) {c : α} (h : c < 0) :
(fun x => x * c) ⁻¹' Ioi a = Iio (a / c) :=
ext fun _x => (lt_div_iff_of_neg h).symm
#align set.preimage_mul_const_Ioi_of_neg Set.preimage_mul_const_Ioi_of_neg
@[simp]
theorem preimage_mul_const_Iic_of_neg (a : α) {c : α} (h : c < 0) :
(fun x => x * c) ⁻¹' Iic a = Ici (a / c) :=
ext fun _x => (div_le_iff_of_neg h).symm
#align set.preimage_mul_const_Iic_of_neg Set.preimage_mul_const_Iic_of_neg
@[simp]
theorem preimage_mul_const_Ici_of_neg (a : α) {c : α} (h : c < 0) :
(fun x => x * c) ⁻¹' Ici a = Iic (a / c) :=
ext fun _x => (le_div_iff_of_neg h).symm
#align set.preimage_mul_const_Ici_of_neg Set.preimage_mul_const_Ici_of_neg
@[simp]
theorem preimage_mul_const_Ioo_of_neg (a b : α) {c : α} (h : c < 0) :
(fun x => x * c) ⁻¹' Ioo a b = Ioo (b / c) (a / c) := by simp [← Ioi_inter_Iio, h, inter_comm]
#align set.preimage_mul_const_Ioo_of_neg Set.preimage_mul_const_Ioo_of_neg
@[simp]
theorem preimage_mul_const_Ioc_of_neg (a b : α) {c : α} (h : c < 0) :
(fun x => x * c) ⁻¹' Ioc a b = Ico (b / c) (a / c) := by
simp [← Ioi_inter_Iic, ← Ici_inter_Iio, h, inter_comm]
#align set.preimage_mul_const_Ioc_of_neg Set.preimage_mul_const_Ioc_of_neg
@[simp]
theorem preimage_mul_const_Ico_of_neg (a b : α) {c : α} (h : c < 0) :
(fun x => x * c) ⁻¹' Ico a b = Ioc (b / c) (a / c) := by
simp [← Ici_inter_Iio, ← Ioi_inter_Iic, h, inter_comm]
#align set.preimage_mul_const_Ico_of_neg Set.preimage_mul_const_Ico_of_neg
@[simp]
theorem preimage_mul_const_Icc_of_neg (a b : α) {c : α} (h : c < 0) :
(fun x => x * c) ⁻¹' Icc a b = Icc (b / c) (a / c) := by simp [← Ici_inter_Iic, h, inter_comm]
#align set.preimage_mul_const_Icc_of_neg Set.preimage_mul_const_Icc_of_neg
@[simp]
theorem preimage_const_mul_Iio (a : α) {c : α} (h : 0 < c) : (c * ·) ⁻¹' Iio a = Iio (a / c) :=
ext fun _x => (lt_div_iff' h).symm
#align set.preimage_const_mul_Iio Set.preimage_const_mul_Iio
@[simp]
theorem preimage_const_mul_Ioi (a : α) {c : α} (h : 0 < c) : (c * ·) ⁻¹' Ioi a = Ioi (a / c) :=
ext fun _x => (div_lt_iff' h).symm
#align set.preimage_const_mul_Ioi Set.preimage_const_mul_Ioi
@[simp]
theorem preimage_const_mul_Iic (a : α) {c : α} (h : 0 < c) : (c * ·) ⁻¹' Iic a = Iic (a / c) :=
ext fun _x => (le_div_iff' h).symm
#align set.preimage_const_mul_Iic Set.preimage_const_mul_Iic
@[simp]
theorem preimage_const_mul_Ici (a : α) {c : α} (h : 0 < c) : (c * ·) ⁻¹' Ici a = Ici (a / c) :=
ext fun _x => (div_le_iff' h).symm
#align set.preimage_const_mul_Ici Set.preimage_const_mul_Ici
@[simp]
theorem preimage_const_mul_Ioo (a b : α) {c : α} (h : 0 < c) :
(c * ·) ⁻¹' Ioo a b = Ioo (a / c) (b / c) := by simp [← Ioi_inter_Iio, h]
#align set.preimage_const_mul_Ioo Set.preimage_const_mul_Ioo
@[simp]
theorem preimage_const_mul_Ioc (a b : α) {c : α} (h : 0 < c) :
(c * ·) ⁻¹' Ioc a b = Ioc (a / c) (b / c) := by simp [← Ioi_inter_Iic, h]
#align set.preimage_const_mul_Ioc Set.preimage_const_mul_Ioc
@[simp]
theorem preimage_const_mul_Ico (a b : α) {c : α} (h : 0 < c) :
(c * ·) ⁻¹' Ico a b = Ico (a / c) (b / c) := by simp [← Ici_inter_Iio, h]
#align set.preimage_const_mul_Ico Set.preimage_const_mul_Ico
@[simp]
theorem preimage_const_mul_Icc (a b : α) {c : α} (h : 0 < c) :
(c * ·) ⁻¹' Icc a b = Icc (a / c) (b / c) := by simp [← Ici_inter_Iic, h]
#align set.preimage_const_mul_Icc Set.preimage_const_mul_Icc
@[simp]
theorem preimage_const_mul_Iio_of_neg (a : α) {c : α} (h : c < 0) :
(c * ·) ⁻¹' Iio a = Ioi (a / c) := by
simpa only [mul_comm] using preimage_mul_const_Iio_of_neg a h
#align set.preimage_const_mul_Iio_of_neg Set.preimage_const_mul_Iio_of_neg
@[simp]
theorem preimage_const_mul_Ioi_of_neg (a : α) {c : α} (h : c < 0) :
(c * ·) ⁻¹' Ioi a = Iio (a / c) := by
simpa only [mul_comm] using preimage_mul_const_Ioi_of_neg a h
#align set.preimage_const_mul_Ioi_of_neg Set.preimage_const_mul_Ioi_of_neg
@[simp]
theorem preimage_const_mul_Iic_of_neg (a : α) {c : α} (h : c < 0) :
(c * ·) ⁻¹' Iic a = Ici (a / c) := by
simpa only [mul_comm] using preimage_mul_const_Iic_of_neg a h
#align set.preimage_const_mul_Iic_of_neg Set.preimage_const_mul_Iic_of_neg
@[simp]
theorem preimage_const_mul_Ici_of_neg (a : α) {c : α} (h : c < 0) :
(c * ·) ⁻¹' Ici a = Iic (a / c) := by
simpa only [mul_comm] using preimage_mul_const_Ici_of_neg a h
#align set.preimage_const_mul_Ici_of_neg Set.preimage_const_mul_Ici_of_neg
@[simp]
theorem preimage_const_mul_Ioo_of_neg (a b : α) {c : α} (h : c < 0) :
(c * ·) ⁻¹' Ioo a b = Ioo (b / c) (a / c) := by
simpa only [mul_comm] using preimage_mul_const_Ioo_of_neg a b h
#align set.preimage_const_mul_Ioo_of_neg Set.preimage_const_mul_Ioo_of_neg
@[simp]
theorem preimage_const_mul_Ioc_of_neg (a b : α) {c : α} (h : c < 0) :
(c * ·) ⁻¹' Ioc a b = Ico (b / c) (a / c) := by
simpa only [mul_comm] using preimage_mul_const_Ioc_of_neg a b h
#align set.preimage_const_mul_Ioc_of_neg Set.preimage_const_mul_Ioc_of_neg
@[simp]
| Mathlib/Data/Set/Pointwise/Interval.lean | 761 | 763 | theorem preimage_const_mul_Ico_of_neg (a b : α) {c : α} (h : c < 0) :
(c * ·) ⁻¹' Ico a b = Ioc (b / c) (a / c) := by |
simpa only [mul_comm] using preimage_mul_const_Ico_of_neg a b h
|
/-
Copyright (c) 2022 Chris Birkbeck. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Birkbeck
-/
import Mathlib.Algebra.Group.Subgroup.Pointwise
import Mathlib.Data.ZMod.Basic
import Mathlib.GroupTheory.GroupAction.ConjAct
import Mathlib.LinearAlgebra.Matrix.SpecialLinearGroup
#align_import number_theory.modular_forms.congruence_subgroups from "leanprover-community/mathlib"@"ae690b0c236e488a0043f6faa8ce3546e7f2f9c5"
/-!
# Congruence subgroups
This defines congruence subgroups of `SL(2, ℤ)` such as `Γ(N)`, `Γ₀(N)` and `Γ₁(N)` for `N` a
natural number.
It also contains basic results about congruence subgroups.
-/
local notation "SL(" n ", " R ")" => Matrix.SpecialLinearGroup (Fin n) R
attribute [-instance] Matrix.SpecialLinearGroup.instCoeFun
local notation:1024 "↑ₘ" A:1024 => ((A : SL(2, ℤ)) : Matrix (Fin 2) (Fin 2) ℤ)
open Matrix.SpecialLinearGroup Matrix
variable (N : ℕ)
local notation "SLMOD(" N ")" =>
@Matrix.SpecialLinearGroup.map (Fin 2) _ _ _ _ _ _ (Int.castRingHom (ZMod N))
set_option linter.uppercaseLean3 false
@[simp]
theorem SL_reduction_mod_hom_val (N : ℕ) (γ : SL(2, ℤ)) :
∀ i j : Fin 2, (SLMOD(N) γ : Matrix (Fin 2) (Fin 2) (ZMod N)) i j = ((↑ₘγ i j : ℤ) : ZMod N) :=
fun _ _ => rfl
#align SL_reduction_mod_hom_val SL_reduction_mod_hom_val
/-- The full level `N` congruence subgroup of `SL(2, ℤ)` of matrices that reduce to the identity
modulo `N`. -/
def Gamma (N : ℕ) : Subgroup SL(2, ℤ) :=
SLMOD(N).ker
#align Gamma Gamma
theorem Gamma_mem' (N : ℕ) (γ : SL(2, ℤ)) : γ ∈ Gamma N ↔ SLMOD(N) γ = 1 :=
Iff.rfl
#align Gamma_mem' Gamma_mem'
@[simp]
| Mathlib/NumberTheory/ModularForms/CongruenceSubgroups.lean | 56 | 66 | theorem Gamma_mem (N : ℕ) (γ : SL(2, ℤ)) : γ ∈ Gamma N ↔ ((↑ₘγ 0 0 : ℤ) : ZMod N) = 1 ∧
((↑ₘγ 0 1 : ℤ) : ZMod N) = 0 ∧ ((↑ₘγ 1 0 : ℤ) : ZMod N) = 0 ∧ ((↑ₘγ 1 1 : ℤ) : ZMod N) = 1 := by |
rw [Gamma_mem']
constructor
· intro h
simp [← SL_reduction_mod_hom_val N γ, h]
· intro h
ext i j
rw [SL_reduction_mod_hom_val N γ]
fin_cases i <;> fin_cases j <;> simp only [h]
exacts [h.1, h.2.1, h.2.2.1, h.2.2.2]
|
/-
Copyright (c) 2022 Joseph Myers. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Joseph Myers, Heather Macbeth
-/
import Mathlib.Analysis.InnerProductSpace.TwoDim
import Mathlib.Geometry.Euclidean.Angle.Unoriented.Basic
#align_import geometry.euclidean.angle.oriented.basic from "leanprover-community/mathlib"@"f0c8bf9245297a541f468be517f1bde6195105e9"
/-!
# Oriented angles.
This file defines oriented angles in real inner product spaces.
## Main definitions
* `Orientation.oangle` is the oriented angle between two vectors with respect to an orientation.
## Implementation notes
The definitions here use the `Real.angle` type, angles modulo `2 * π`. For some purposes,
angles modulo `π` are more convenient, because results are true for such angles with less
configuration dependence. Results that are only equalities modulo `π` can be represented
modulo `2 * π` as equalities of `(2 : ℤ) • θ`.
## References
* Evan Chen, Euclidean Geometry in Mathematical Olympiads.
-/
noncomputable section
open FiniteDimensional Complex
open scoped Real RealInnerProductSpace ComplexConjugate
namespace Orientation
attribute [local instance] Complex.finrank_real_complex_fact
variable {V V' : Type*}
variable [NormedAddCommGroup V] [NormedAddCommGroup V']
variable [InnerProductSpace ℝ V] [InnerProductSpace ℝ V']
variable [Fact (finrank ℝ V = 2)] [Fact (finrank ℝ V' = 2)] (o : Orientation ℝ V (Fin 2))
local notation "ω" => o.areaForm
/-- The oriented angle from `x` to `y`, modulo `2 * π`. If either vector is 0, this is 0.
See `InnerProductGeometry.angle` for the corresponding unoriented angle definition. -/
def oangle (x y : V) : Real.Angle :=
Complex.arg (o.kahler x y)
#align orientation.oangle Orientation.oangle
/-- Oriented angles are continuous when the vectors involved are nonzero. -/
theorem continuousAt_oangle {x : V × V} (hx1 : x.1 ≠ 0) (hx2 : x.2 ≠ 0) :
ContinuousAt (fun y : V × V => o.oangle y.1 y.2) x := by
refine (Complex.continuousAt_arg_coe_angle ?_).comp ?_
· exact o.kahler_ne_zero hx1 hx2
exact ((continuous_ofReal.comp continuous_inner).add
((continuous_ofReal.comp o.areaForm'.continuous₂).mul continuous_const)).continuousAt
#align orientation.continuous_at_oangle Orientation.continuousAt_oangle
/-- If the first vector passed to `oangle` is 0, the result is 0. -/
@[simp]
theorem oangle_zero_left (x : V) : o.oangle 0 x = 0 := by simp [oangle]
#align orientation.oangle_zero_left Orientation.oangle_zero_left
/-- If the second vector passed to `oangle` is 0, the result is 0. -/
@[simp]
theorem oangle_zero_right (x : V) : o.oangle x 0 = 0 := by simp [oangle]
#align orientation.oangle_zero_right Orientation.oangle_zero_right
/-- If the two vectors passed to `oangle` are the same, the result is 0. -/
@[simp]
theorem oangle_self (x : V) : o.oangle x x = 0 := by
rw [oangle, kahler_apply_self, ← ofReal_pow]
convert QuotientAddGroup.mk_zero (AddSubgroup.zmultiples (2 * π))
apply arg_ofReal_of_nonneg
positivity
#align orientation.oangle_self Orientation.oangle_self
/-- If the angle between two vectors is nonzero, the first vector is nonzero. -/
theorem left_ne_zero_of_oangle_ne_zero {x y : V} (h : o.oangle x y ≠ 0) : x ≠ 0 := by
rintro rfl; simp at h
#align orientation.left_ne_zero_of_oangle_ne_zero Orientation.left_ne_zero_of_oangle_ne_zero
/-- If the angle between two vectors is nonzero, the second vector is nonzero. -/
theorem right_ne_zero_of_oangle_ne_zero {x y : V} (h : o.oangle x y ≠ 0) : y ≠ 0 := by
rintro rfl; simp at h
#align orientation.right_ne_zero_of_oangle_ne_zero Orientation.right_ne_zero_of_oangle_ne_zero
/-- If the angle between two vectors is nonzero, the vectors are not equal. -/
theorem ne_of_oangle_ne_zero {x y : V} (h : o.oangle x y ≠ 0) : x ≠ y := by
rintro rfl; simp at h
#align orientation.ne_of_oangle_ne_zero Orientation.ne_of_oangle_ne_zero
/-- If the angle between two vectors is `π`, the first vector is nonzero. -/
theorem left_ne_zero_of_oangle_eq_pi {x y : V} (h : o.oangle x y = π) : x ≠ 0 :=
o.left_ne_zero_of_oangle_ne_zero (h.symm ▸ Real.Angle.pi_ne_zero : o.oangle x y ≠ 0)
#align orientation.left_ne_zero_of_oangle_eq_pi Orientation.left_ne_zero_of_oangle_eq_pi
/-- If the angle between two vectors is `π`, the second vector is nonzero. -/
theorem right_ne_zero_of_oangle_eq_pi {x y : V} (h : o.oangle x y = π) : y ≠ 0 :=
o.right_ne_zero_of_oangle_ne_zero (h.symm ▸ Real.Angle.pi_ne_zero : o.oangle x y ≠ 0)
#align orientation.right_ne_zero_of_oangle_eq_pi Orientation.right_ne_zero_of_oangle_eq_pi
/-- If the angle between two vectors is `π`, the vectors are not equal. -/
theorem ne_of_oangle_eq_pi {x y : V} (h : o.oangle x y = π) : x ≠ y :=
o.ne_of_oangle_ne_zero (h.symm ▸ Real.Angle.pi_ne_zero : o.oangle x y ≠ 0)
#align orientation.ne_of_oangle_eq_pi Orientation.ne_of_oangle_eq_pi
/-- If the angle between two vectors is `π / 2`, the first vector is nonzero. -/
theorem left_ne_zero_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = (π / 2 : ℝ)) : x ≠ 0 :=
o.left_ne_zero_of_oangle_ne_zero (h.symm ▸ Real.Angle.pi_div_two_ne_zero : o.oangle x y ≠ 0)
#align orientation.left_ne_zero_of_oangle_eq_pi_div_two Orientation.left_ne_zero_of_oangle_eq_pi_div_two
/-- If the angle between two vectors is `π / 2`, the second vector is nonzero. -/
theorem right_ne_zero_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = (π / 2 : ℝ)) : y ≠ 0 :=
o.right_ne_zero_of_oangle_ne_zero (h.symm ▸ Real.Angle.pi_div_two_ne_zero : o.oangle x y ≠ 0)
#align orientation.right_ne_zero_of_oangle_eq_pi_div_two Orientation.right_ne_zero_of_oangle_eq_pi_div_two
/-- If the angle between two vectors is `π / 2`, the vectors are not equal. -/
theorem ne_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = (π / 2 : ℝ)) : x ≠ y :=
o.ne_of_oangle_ne_zero (h.symm ▸ Real.Angle.pi_div_two_ne_zero : o.oangle x y ≠ 0)
#align orientation.ne_of_oangle_eq_pi_div_two Orientation.ne_of_oangle_eq_pi_div_two
/-- If the angle between two vectors is `-π / 2`, the first vector is nonzero. -/
theorem left_ne_zero_of_oangle_eq_neg_pi_div_two {x y : V} (h : o.oangle x y = (-π / 2 : ℝ)) :
x ≠ 0 :=
o.left_ne_zero_of_oangle_ne_zero (h.symm ▸ Real.Angle.neg_pi_div_two_ne_zero : o.oangle x y ≠ 0)
#align orientation.left_ne_zero_of_oangle_eq_neg_pi_div_two Orientation.left_ne_zero_of_oangle_eq_neg_pi_div_two
/-- If the angle between two vectors is `-π / 2`, the second vector is nonzero. -/
theorem right_ne_zero_of_oangle_eq_neg_pi_div_two {x y : V} (h : o.oangle x y = (-π / 2 : ℝ)) :
y ≠ 0 :=
o.right_ne_zero_of_oangle_ne_zero (h.symm ▸ Real.Angle.neg_pi_div_two_ne_zero : o.oangle x y ≠ 0)
#align orientation.right_ne_zero_of_oangle_eq_neg_pi_div_two Orientation.right_ne_zero_of_oangle_eq_neg_pi_div_two
/-- If the angle between two vectors is `-π / 2`, the vectors are not equal. -/
theorem ne_of_oangle_eq_neg_pi_div_two {x y : V} (h : o.oangle x y = (-π / 2 : ℝ)) : x ≠ y :=
o.ne_of_oangle_ne_zero (h.symm ▸ Real.Angle.neg_pi_div_two_ne_zero : o.oangle x y ≠ 0)
#align orientation.ne_of_oangle_eq_neg_pi_div_two Orientation.ne_of_oangle_eq_neg_pi_div_two
/-- If the sign of the angle between two vectors is nonzero, the first vector is nonzero. -/
theorem left_ne_zero_of_oangle_sign_ne_zero {x y : V} (h : (o.oangle x y).sign ≠ 0) : x ≠ 0 :=
o.left_ne_zero_of_oangle_ne_zero (Real.Angle.sign_ne_zero_iff.1 h).1
#align orientation.left_ne_zero_of_oangle_sign_ne_zero Orientation.left_ne_zero_of_oangle_sign_ne_zero
/-- If the sign of the angle between two vectors is nonzero, the second vector is nonzero. -/
theorem right_ne_zero_of_oangle_sign_ne_zero {x y : V} (h : (o.oangle x y).sign ≠ 0) : y ≠ 0 :=
o.right_ne_zero_of_oangle_ne_zero (Real.Angle.sign_ne_zero_iff.1 h).1
#align orientation.right_ne_zero_of_oangle_sign_ne_zero Orientation.right_ne_zero_of_oangle_sign_ne_zero
/-- If the sign of the angle between two vectors is nonzero, the vectors are not equal. -/
theorem ne_of_oangle_sign_ne_zero {x y : V} (h : (o.oangle x y).sign ≠ 0) : x ≠ y :=
o.ne_of_oangle_ne_zero (Real.Angle.sign_ne_zero_iff.1 h).1
#align orientation.ne_of_oangle_sign_ne_zero Orientation.ne_of_oangle_sign_ne_zero
/-- If the sign of the angle between two vectors is positive, the first vector is nonzero. -/
theorem left_ne_zero_of_oangle_sign_eq_one {x y : V} (h : (o.oangle x y).sign = 1) : x ≠ 0 :=
o.left_ne_zero_of_oangle_sign_ne_zero (h.symm ▸ by decide : (o.oangle x y).sign ≠ 0)
#align orientation.left_ne_zero_of_oangle_sign_eq_one Orientation.left_ne_zero_of_oangle_sign_eq_one
/-- If the sign of the angle between two vectors is positive, the second vector is nonzero. -/
theorem right_ne_zero_of_oangle_sign_eq_one {x y : V} (h : (o.oangle x y).sign = 1) : y ≠ 0 :=
o.right_ne_zero_of_oangle_sign_ne_zero (h.symm ▸ by decide : (o.oangle x y).sign ≠ 0)
#align orientation.right_ne_zero_of_oangle_sign_eq_one Orientation.right_ne_zero_of_oangle_sign_eq_one
/-- If the sign of the angle between two vectors is positive, the vectors are not equal. -/
theorem ne_of_oangle_sign_eq_one {x y : V} (h : (o.oangle x y).sign = 1) : x ≠ y :=
o.ne_of_oangle_sign_ne_zero (h.symm ▸ by decide : (o.oangle x y).sign ≠ 0)
#align orientation.ne_of_oangle_sign_eq_one Orientation.ne_of_oangle_sign_eq_one
/-- If the sign of the angle between two vectors is negative, the first vector is nonzero. -/
theorem left_ne_zero_of_oangle_sign_eq_neg_one {x y : V} (h : (o.oangle x y).sign = -1) : x ≠ 0 :=
o.left_ne_zero_of_oangle_sign_ne_zero (h.symm ▸ by decide : (o.oangle x y).sign ≠ 0)
#align orientation.left_ne_zero_of_oangle_sign_eq_neg_one Orientation.left_ne_zero_of_oangle_sign_eq_neg_one
/-- If the sign of the angle between two vectors is negative, the second vector is nonzero. -/
theorem right_ne_zero_of_oangle_sign_eq_neg_one {x y : V} (h : (o.oangle x y).sign = -1) : y ≠ 0 :=
o.right_ne_zero_of_oangle_sign_ne_zero (h.symm ▸ by decide : (o.oangle x y).sign ≠ 0)
#align orientation.right_ne_zero_of_oangle_sign_eq_neg_one Orientation.right_ne_zero_of_oangle_sign_eq_neg_one
/-- If the sign of the angle between two vectors is negative, the vectors are not equal. -/
theorem ne_of_oangle_sign_eq_neg_one {x y : V} (h : (o.oangle x y).sign = -1) : x ≠ y :=
o.ne_of_oangle_sign_ne_zero (h.symm ▸ by decide : (o.oangle x y).sign ≠ 0)
#align orientation.ne_of_oangle_sign_eq_neg_one Orientation.ne_of_oangle_sign_eq_neg_one
/-- Swapping the two vectors passed to `oangle` negates the angle. -/
theorem oangle_rev (x y : V) : o.oangle y x = -o.oangle x y := by
simp only [oangle, o.kahler_swap y x, Complex.arg_conj_coe_angle]
#align orientation.oangle_rev Orientation.oangle_rev
/-- Adding the angles between two vectors in each order results in 0. -/
@[simp]
theorem oangle_add_oangle_rev (x y : V) : o.oangle x y + o.oangle y x = 0 := by
simp [o.oangle_rev y x]
#align orientation.oangle_add_oangle_rev Orientation.oangle_add_oangle_rev
/-- Negating the first vector passed to `oangle` adds `π` to the angle. -/
theorem oangle_neg_left {x y : V} (hx : x ≠ 0) (hy : y ≠ 0) :
o.oangle (-x) y = o.oangle x y + π := by
simp only [oangle, map_neg]
convert Complex.arg_neg_coe_angle _
exact o.kahler_ne_zero hx hy
#align orientation.oangle_neg_left Orientation.oangle_neg_left
/-- Negating the second vector passed to `oangle` adds `π` to the angle. -/
theorem oangle_neg_right {x y : V} (hx : x ≠ 0) (hy : y ≠ 0) :
o.oangle x (-y) = o.oangle x y + π := by
simp only [oangle, map_neg]
convert Complex.arg_neg_coe_angle _
exact o.kahler_ne_zero hx hy
#align orientation.oangle_neg_right Orientation.oangle_neg_right
/-- Negating the first vector passed to `oangle` does not change twice the angle. -/
@[simp]
theorem two_zsmul_oangle_neg_left (x y : V) :
(2 : ℤ) • o.oangle (-x) y = (2 : ℤ) • o.oangle x y := by
by_cases hx : x = 0
· simp [hx]
· by_cases hy : y = 0
· simp [hy]
· simp [o.oangle_neg_left hx hy]
#align orientation.two_zsmul_oangle_neg_left Orientation.two_zsmul_oangle_neg_left
/-- Negating the second vector passed to `oangle` does not change twice the angle. -/
@[simp]
theorem two_zsmul_oangle_neg_right (x y : V) :
(2 : ℤ) • o.oangle x (-y) = (2 : ℤ) • o.oangle x y := by
by_cases hx : x = 0
· simp [hx]
· by_cases hy : y = 0
· simp [hy]
· simp [o.oangle_neg_right hx hy]
#align orientation.two_zsmul_oangle_neg_right Orientation.two_zsmul_oangle_neg_right
/-- Negating both vectors passed to `oangle` does not change the angle. -/
@[simp]
| Mathlib/Geometry/Euclidean/Angle/Oriented/Basic.lean | 243 | 243 | theorem oangle_neg_neg (x y : V) : o.oangle (-x) (-y) = o.oangle x y := by | simp [oangle]
|
/-
Copyright (c) 2021 Vladimir Goryachev. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies, Vladimir Goryachev, Kyle Miller, Scott Morrison, Eric Rodriguez
-/
import Mathlib.SetTheory.Cardinal.Basic
import Mathlib.Tactic.Ring
#align_import data.nat.count from "leanprover-community/mathlib"@"dc6c365e751e34d100e80fe6e314c3c3e0fd2988"
/-!
# Counting on ℕ
This file defines the `count` function, which gives, for any predicate on the natural numbers,
"how many numbers under `k` satisfy this predicate?".
We then prove several expected lemmas about `count`, relating it to the cardinality of other
objects, and helping to evaluate it for specific `k`.
-/
open Finset
namespace Nat
variable (p : ℕ → Prop)
section Count
variable [DecidablePred p]
/-- Count the number of naturals `k < n` satisfying `p k`. -/
def count (n : ℕ) : ℕ :=
(List.range n).countP p
#align nat.count Nat.count
@[simp]
theorem count_zero : count p 0 = 0 := by
rw [count, List.range_zero, List.countP, List.countP.go]
#align nat.count_zero Nat.count_zero
/-- A fintype instance for the set relevant to `Nat.count`. Locally an instance in locale `count` -/
def CountSet.fintype (n : ℕ) : Fintype { i // i < n ∧ p i } := by
apply Fintype.ofFinset ((Finset.range n).filter p)
intro x
rw [mem_filter, mem_range]
rfl
#align nat.count_set.fintype Nat.CountSet.fintype
scoped[Count] attribute [instance] Nat.CountSet.fintype
open Count
theorem count_eq_card_filter_range (n : ℕ) : count p n = ((range n).filter p).card := by
rw [count, List.countP_eq_length_filter]
rfl
#align nat.count_eq_card_filter_range Nat.count_eq_card_filter_range
/-- `count p n` can be expressed as the cardinality of `{k // k < n ∧ p k}`. -/
theorem count_eq_card_fintype (n : ℕ) : count p n = Fintype.card { k : ℕ // k < n ∧ p k } := by
rw [count_eq_card_filter_range, ← Fintype.card_ofFinset, ← CountSet.fintype]
rfl
#align nat.count_eq_card_fintype Nat.count_eq_card_fintype
theorem count_succ (n : ℕ) : count p (n + 1) = count p n + if p n then 1 else 0 := by
split_ifs with h <;> simp [count, List.range_succ, h]
#align nat.count_succ Nat.count_succ
@[mono]
theorem count_monotone : Monotone (count p) :=
monotone_nat_of_le_succ fun n ↦ by by_cases h : p n <;> simp [count_succ, h]
#align nat.count_monotone Nat.count_monotone
theorem count_add (a b : ℕ) : count p (a + b) = count p a + count (fun k ↦ p (a + k)) b := by
have : Disjoint ((range a).filter p) (((range b).map <| addLeftEmbedding a).filter p) := by
apply disjoint_filter_filter
rw [Finset.disjoint_left]
simp_rw [mem_map, mem_range, addLeftEmbedding_apply]
rintro x hx ⟨c, _, rfl⟩
exact (self_le_add_right _ _).not_lt hx
simp_rw [count_eq_card_filter_range, range_add, filter_union, card_union_of_disjoint this,
filter_map, addLeftEmbedding, card_map]
rfl
#align nat.count_add Nat.count_add
theorem count_add' (a b : ℕ) : count p (a + b) = count (fun k ↦ p (k + b)) a + count p b := by
rw [add_comm, count_add, add_comm]
simp_rw [add_comm b]
#align nat.count_add' Nat.count_add'
| Mathlib/Data/Nat/Count.lean | 91 | 91 | theorem count_one : count p 1 = if p 0 then 1 else 0 := by | simp [count_succ]
|
/-
Copyright (c) 2018 Michael Jendrusch. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Michael Jendrusch, Scott Morrison, Bhavik Mehta
-/
import Mathlib.CategoryTheory.Monoidal.Category
import Mathlib.CategoryTheory.Adjunction.FullyFaithful
import Mathlib.CategoryTheory.Products.Basic
#align_import category_theory.monoidal.functor from "leanprover-community/mathlib"@"3d7987cda72abc473c7cdbbb075170e9ac620042"
/-!
# (Lax) monoidal functors
A lax monoidal functor `F` between monoidal categories `C` and `D`
is a functor between the underlying categories equipped with morphisms
* `ε : 𝟙_ D ⟶ F.obj (𝟙_ C)` (called the unit morphism)
* `μ X Y : (F.obj X) ⊗ (F.obj Y) ⟶ F.obj (X ⊗ Y)` (called the tensorator, or strength).
satisfying various axioms.
A monoidal functor is a lax monoidal functor for which `ε` and `μ` are isomorphisms.
We show that the composition of (lax) monoidal functors gives a (lax) monoidal functor.
See also `CategoryTheory.Monoidal.Functorial` for a typeclass decorating an object-level
function with the additional data of a monoidal functor.
This is useful when stating that a pre-existing functor is monoidal.
See `CategoryTheory.Monoidal.NaturalTransformation` for monoidal natural transformations.
We show in `CategoryTheory.Monoidal.Mon_` that lax monoidal functors take monoid objects
to monoid objects.
## References
See <https://stacks.math.columbia.edu/tag/0FFL>.
-/
open CategoryTheory
universe v₁ v₂ v₃ u₁ u₂ u₃
open CategoryTheory.Category
open CategoryTheory.Functor
namespace CategoryTheory
section
open MonoidalCategory
variable (C : Type u₁) [Category.{v₁} C] [MonoidalCategory.{v₁} C] (D : Type u₂) [Category.{v₂} D]
[MonoidalCategory.{v₂} D]
-- The direction of `left_unitality` and `right_unitality` as simp lemmas may look strange:
-- remember the rule of thumb that component indices of natural transformations
-- "weigh more" than structural maps.
-- (However by this argument `associativity` is currently stated backwards!)
/-- A lax monoidal functor is a functor `F : C ⥤ D` between monoidal categories,
equipped with morphisms `ε : 𝟙 _D ⟶ F.obj (𝟙_ C)` and `μ X Y : F.obj X ⊗ F.obj Y ⟶ F.obj (X ⊗ Y)`,
satisfying the appropriate coherences. -/
structure LaxMonoidalFunctor extends C ⥤ D where
/-- unit morphism -/
ε : 𝟙_ D ⟶ obj (𝟙_ C)
/-- tensorator -/
μ : ∀ X Y : C, obj X ⊗ obj Y ⟶ obj (X ⊗ Y)
μ_natural_left :
∀ {X Y : C} (f : X ⟶ Y) (X' : C),
map f ▷ obj X' ≫ μ Y X' = μ X X' ≫ map (f ▷ X') := by
aesop_cat
μ_natural_right :
∀ {X Y : C} (X' : C) (f : X ⟶ Y) ,
obj X' ◁ map f ≫ μ X' Y = μ X' X ≫ map (X' ◁ f) := by
aesop_cat
/-- associativity of the tensorator -/
associativity :
∀ X Y Z : C,
μ X Y ▷ obj Z ≫ μ (X ⊗ Y) Z ≫ map (α_ X Y Z).hom =
(α_ (obj X) (obj Y) (obj Z)).hom ≫ obj X ◁ μ Y Z ≫ μ X (Y ⊗ Z) := by
aesop_cat
-- unitality
left_unitality : ∀ X : C, (λ_ (obj X)).hom = ε ▷ obj X ≫ μ (𝟙_ C) X ≫ map (λ_ X).hom := by
aesop_cat
right_unitality : ∀ X : C, (ρ_ (obj X)).hom = obj X ◁ ε ≫ μ X (𝟙_ C) ≫ map (ρ_ X).hom := by
aesop_cat
#align category_theory.lax_monoidal_functor CategoryTheory.LaxMonoidalFunctor
-- Porting note (#11215): TODO: remove this configuration and use the default configuration.
-- We keep this to be consistent with Lean 3.
-- See also `initialize_simps_projections MonoidalFunctor` below.
-- This may require waiting on https://github.com/leanprover-community/mathlib4/pull/2936
initialize_simps_projections LaxMonoidalFunctor (+toFunctor, -obj, -map)
attribute [reassoc (attr := simp)] LaxMonoidalFunctor.μ_natural_left
attribute [reassoc (attr := simp)] LaxMonoidalFunctor.μ_natural_right
attribute [simp] LaxMonoidalFunctor.left_unitality
attribute [simp] LaxMonoidalFunctor.right_unitality
attribute [reassoc (attr := simp)] LaxMonoidalFunctor.associativity
-- When `rewrite_search` lands, add @[search] attributes to
-- LaxMonoidalFunctor.μ_natural LaxMonoidalFunctor.left_unitality
-- LaxMonoidalFunctor.right_unitality LaxMonoidalFunctor.associativity
section
variable {C D}
@[reassoc (attr := simp)]
theorem LaxMonoidalFunctor.μ_natural (F : LaxMonoidalFunctor C D) {X Y X' Y' : C}
(f : X ⟶ Y) (g : X' ⟶ Y') :
(F.map f ⊗ F.map g) ≫ F.μ Y Y' = F.μ X X' ≫ F.map (f ⊗ g) := by
simp [tensorHom_def]
/--
A constructor for lax monoidal functors whose axioms are described by `tensorHom` instead of
`whiskerLeft` and `whiskerRight`.
-/
@[simps]
def LaxMonoidalFunctor.ofTensorHom (F : C ⥤ D)
/- unit morphism -/
(ε : 𝟙_ D ⟶ F.obj (𝟙_ C))
/- tensorator -/
(μ : ∀ X Y : C, F.obj X ⊗ F.obj Y ⟶ F.obj (X ⊗ Y))
(μ_natural :
∀ {X Y X' Y' : C} (f : X ⟶ Y) (g : X' ⟶ Y'),
(F.map f ⊗ F.map g) ≫ μ Y Y' = μ X X' ≫ F.map (f ⊗ g) := by
aesop_cat)
/- associativity of the tensorator -/
(associativity :
∀ X Y Z : C,
(μ X Y ⊗ 𝟙 (F.obj Z)) ≫ μ (X ⊗ Y) Z ≫ F.map (α_ X Y Z).hom =
(α_ (F.obj X) (F.obj Y) (F.obj Z)).hom ≫ (𝟙 (F.obj X) ⊗ μ Y Z) ≫ μ X (Y ⊗ Z) := by
aesop_cat)
/- unitality -/
(left_unitality :
∀ X : C, (λ_ (F.obj X)).hom = (ε ⊗ 𝟙 (F.obj X)) ≫ μ (𝟙_ C) X ≫ F.map (λ_ X).hom := by
aesop_cat)
(right_unitality :
∀ X : C, (ρ_ (F.obj X)).hom = (𝟙 (F.obj X) ⊗ ε) ≫ μ X (𝟙_ C) ≫ F.map (ρ_ X).hom := by
aesop_cat) :
LaxMonoidalFunctor C D where
obj := F.obj
map := F.map
map_id := F.map_id
map_comp := F.map_comp
ε := ε
μ := μ
μ_natural_left := fun f X' => by
simp_rw [← tensorHom_id, ← F.map_id, μ_natural]
μ_natural_right := fun X' f => by
simp_rw [← id_tensorHom, ← F.map_id, μ_natural]
associativity := fun X Y Z => by
simp_rw [← tensorHom_id, ← id_tensorHom, associativity]
left_unitality := fun X => by
simp_rw [← tensorHom_id, left_unitality]
right_unitality := fun X => by
simp_rw [← id_tensorHom, right_unitality]
@[reassoc (attr := simp)]
theorem LaxMonoidalFunctor.left_unitality_inv (F : LaxMonoidalFunctor C D) (X : C) :
(λ_ (F.obj X)).inv ≫ F.ε ▷ F.obj X ≫ F.μ (𝟙_ C) X = F.map (λ_ X).inv := by
rw [Iso.inv_comp_eq, F.left_unitality, Category.assoc, Category.assoc, ← F.toFunctor.map_comp,
Iso.hom_inv_id, F.toFunctor.map_id, comp_id]
#align category_theory.lax_monoidal_functor.left_unitality_inv CategoryTheory.LaxMonoidalFunctor.left_unitality_inv
@[reassoc (attr := simp)]
| Mathlib/CategoryTheory/Monoidal/Functor.lean | 171 | 174 | theorem LaxMonoidalFunctor.right_unitality_inv (F : LaxMonoidalFunctor C D) (X : C) :
(ρ_ (F.obj X)).inv ≫ F.obj X ◁ F.ε ≫ F.μ X (𝟙_ C) = F.map (ρ_ X).inv := by |
rw [Iso.inv_comp_eq, F.right_unitality, Category.assoc, Category.assoc, ← F.toFunctor.map_comp,
Iso.hom_inv_id, F.toFunctor.map_id, comp_id]
|
/-
Copyright (c) 2024 Oliver Nash. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Nathaniel Thomas, Jeremy Avigad, Johannes Hölzl, Mario Carneiro, Andrew Yang,
Johannes Hölzl, Kevin Buzzard, Yury Kudryashov
-/
import Mathlib.Algebra.Module.Submodule.Lattice
import Mathlib.Order.Hom.CompleteLattice
/-!
# Restriction of scalars for submodules
If semiring `S` acts on a semiring `R` and `M` is a module over both (compatibly with this action)
then we can turn an `R`-submodule into an `S`-submodule by forgetting the action of `R`. We call
this restriction of scalars for submodules.
## Main definitions:
* `Submodule.restrictScalars`: regard an `R`-submodule as an `S`-submodule if `S` acts on `R`
-/
namespace Submodule
variable (S : Type*) {R M : Type*} [Semiring R] [AddCommMonoid M] [Semiring S]
[Module S M] [Module R M] [SMul S R] [IsScalarTower S R M]
/-- `V.restrictScalars S` is the `S`-submodule of the `S`-module given by restriction of scalars,
corresponding to `V`, an `R`-submodule of the original `R`-module.
-/
def restrictScalars (V : Submodule R M) : Submodule S M where
carrier := V
zero_mem' := V.zero_mem
smul_mem' c _ h := V.smul_of_tower_mem c h
add_mem' hx hy := V.add_mem hx hy
#align submodule.restrict_scalars Submodule.restrictScalars
@[simp]
theorem coe_restrictScalars (V : Submodule R M) : (V.restrictScalars S : Set M) = V :=
rfl
#align submodule.coe_restrict_scalars Submodule.coe_restrictScalars
@[simp]
theorem toAddSubmonoid_restrictScalars (V : Submodule R M) :
(V.restrictScalars S).toAddSubmonoid = V.toAddSubmonoid :=
rfl
@[simp]
theorem restrictScalars_mem (V : Submodule R M) (m : M) : m ∈ V.restrictScalars S ↔ m ∈ V :=
Iff.refl _
#align submodule.restrict_scalars_mem Submodule.restrictScalars_mem
@[simp]
theorem restrictScalars_self (V : Submodule R M) : V.restrictScalars R = V :=
SetLike.coe_injective rfl
#align submodule.restrict_scalars_self Submodule.restrictScalars_self
variable (R M)
theorem restrictScalars_injective :
Function.Injective (restrictScalars S : Submodule R M → Submodule S M) := fun _ _ h =>
ext <| Set.ext_iff.1 (SetLike.ext'_iff.1 h : _)
#align submodule.restrict_scalars_injective Submodule.restrictScalars_injective
@[simp]
theorem restrictScalars_inj {V₁ V₂ : Submodule R M} :
restrictScalars S V₁ = restrictScalars S V₂ ↔ V₁ = V₂ :=
(restrictScalars_injective S _ _).eq_iff
#align submodule.restrict_scalars_inj Submodule.restrictScalars_inj
/-- Even though `p.restrictScalars S` has type `Submodule S M`, it is still an `R`-module. -/
instance restrictScalars.origModule (p : Submodule R M) : Module R (p.restrictScalars S) :=
(by infer_instance : Module R p)
#align submodule.restrict_scalars.orig_module Submodule.restrictScalars.origModule
instance restrictScalars.isScalarTower (p : Submodule R M) :
IsScalarTower S R (p.restrictScalars S) where
smul_assoc r s x := Subtype.ext <| smul_assoc r s (x : M)
#align submodule.restrict_scalars.is_scalar_tower Submodule.restrictScalars.isScalarTower
/-- `restrictScalars S` is an embedding of the lattice of `R`-submodules into
the lattice of `S`-submodules. -/
@[simps]
def restrictScalarsEmbedding : Submodule R M ↪o Submodule S M where
toFun := restrictScalars S
inj' := restrictScalars_injective S R M
map_rel_iff' := by simp [SetLike.le_def]
#align submodule.restrict_scalars_embedding Submodule.restrictScalarsEmbedding
#align submodule.restrict_scalars_embedding_apply Submodule.restrictScalarsEmbedding_apply
/-- Turning `p : Submodule R M` into an `S`-submodule gives the same module structure
as turning it into a type and adding a module structure. -/
@[simps (config := { simpRhs := true })]
def restrictScalarsEquiv (p : Submodule R M) : p.restrictScalars S ≃ₗ[R] p :=
{ AddEquiv.refl p with
map_smul' := fun _ _ => rfl }
#align submodule.restrict_scalars_equiv Submodule.restrictScalarsEquiv
#align submodule.restrict_scalars_equiv_symm_apply Submodule.restrictScalarsEquiv_symm_apply
@[simp]
theorem restrictScalars_bot : restrictScalars S (⊥ : Submodule R M) = ⊥ :=
rfl
#align submodule.restrict_scalars_bot Submodule.restrictScalars_bot
@[simp]
theorem restrictScalars_eq_bot_iff {p : Submodule R M} : restrictScalars S p = ⊥ ↔ p = ⊥ := by
simp [SetLike.ext_iff]
#align submodule.restrict_scalars_eq_bot_iff Submodule.restrictScalars_eq_bot_iff
@[simp]
theorem restrictScalars_top : restrictScalars S (⊤ : Submodule R M) = ⊤ :=
rfl
#align submodule.restrict_scalars_top Submodule.restrictScalars_top
@[simp]
| Mathlib/Algebra/Module/Submodule/RestrictScalars.lean | 116 | 117 | theorem restrictScalars_eq_top_iff {p : Submodule R M} : restrictScalars S p = ⊤ ↔ p = ⊤ := by |
simp [SetLike.ext_iff]
|
/-
Copyright (c) 2024 Chris Birkbeck. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Birkbeck
-/
import Mathlib.NumberTheory.ModularForms.EisensteinSeries.UniformConvergence
import Mathlib.Analysis.Complex.UpperHalfPlane.Manifold
import Mathlib.Analysis.Complex.LocallyUniformLimit
import Mathlib.Geometry.Manifold.MFDeriv.FDeriv
/-!
# Holomorphicity of Eisenstein series
We show that Eisenstein series of weight `k` and level `Γ(N)` with congruence condition
`a : Fin 2 → ZMod N` are holomorphic on the upper half plane, which is stated as being
MDifferentiable.
-/
noncomputable section
open ModularForm EisensteinSeries UpperHalfPlane Set Filter Function Complex Manifold
open scoped Topology BigOperators Nat Classical UpperHalfPlane
namespace EisensteinSeries
/-- Auxilary lemma showing that for any `k : ℤ` the function `z → 1/(c*z+d)^k` is
differentiable on `{z : ℂ | 0 < z.im}`. -/
lemma div_linear_zpow_differentiableOn (k : ℤ) (a : Fin 2 → ℤ) :
DifferentiableOn ℂ (fun z : ℂ => 1 / (a 0 * z + a 1) ^ k) {z : ℂ | 0 < z.im} := by
rcases ne_or_eq a 0 with ha | rfl
· apply DifferentiableOn.div (differentiableOn_const 1)
· apply DifferentiableOn.zpow
· fun_prop
· left
exact fun z hz ↦ linear_ne_zero _ ⟨z, hz⟩
((comp_ne_zero_iff _ Int.cast_injective Int.cast_zero).mpr ha)
· exact fun z hz ↦ zpow_ne_zero k (linear_ne_zero (a ·)
⟨z, hz⟩ ((comp_ne_zero_iff _ Int.cast_injective Int.cast_zero).mpr ha))
· simp only [ Fin.isValue, Pi.zero_apply, Int.cast_zero, zero_mul, add_zero, one_div]
apply differentiableOn_const
/-- Auxilary lemma showing that for any `k : ℤ` and `(a : Fin 2 → ℤ)`
the extension of `eisSummand` is differentiable on `{z : ℂ | 0 < z.im}`.-/
lemma eisSummand_extension_differentiableOn (k : ℤ) (a : Fin 2 → ℤ) :
DifferentiableOn ℂ (↑ₕeisSummand k a) {z : ℂ | 0 < z.im} := by
apply DifferentiableOn.congr (div_linear_zpow_differentiableOn k a)
intro z hz
lift z to ℍ using hz
apply comp_ofComplex
/-- Eisenstein series are MDifferentiable (i.e. holomorphic functions from `ℍ → ℂ`). -/
| Mathlib/NumberTheory/ModularForms/EisensteinSeries/MDifferentiable.lean | 54 | 65 | theorem eisensteinSeries_SIF_MDifferentiable {k : ℤ} {N : ℕ} (hk : 3 ≤ k) (a : Fin 2 → ZMod N) :
MDifferentiable 𝓘(ℂ) 𝓘(ℂ) (eisensteinSeries_SIF a k) := by |
intro τ
suffices DifferentiableAt ℂ (↑ₕeisensteinSeries_SIF a k) τ.1 by
convert MDifferentiableAt.comp τ (DifferentiableAt.mdifferentiableAt this) τ.mdifferentiable_coe
exact funext fun z ↦ (comp_ofComplex (eisensteinSeries_SIF a k) z).symm
refine DifferentiableOn.differentiableAt ?_
((isOpen_lt continuous_const Complex.continuous_im).mem_nhds τ.2)
exact (eisensteinSeries_tendstoLocallyUniformlyOn hk a).differentiableOn
(eventually_of_forall fun s ↦ DifferentiableOn.sum
fun _ _ ↦ eisSummand_extension_differentiableOn _ _)
(isOpen_lt continuous_const continuous_im)
|
/-
Copyright (c) 2019 Zhouhang Zhou. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Zhouhang Zhou, Frédéric Dupuis, Heather Macbeth
-/
import Mathlib.Analysis.Convex.Basic
import Mathlib.Analysis.InnerProductSpace.Orthogonal
import Mathlib.Analysis.InnerProductSpace.Symmetric
import Mathlib.Analysis.NormedSpace.RCLike
import Mathlib.Analysis.RCLike.Lemmas
import Mathlib.Algebra.DirectSum.Decomposition
#align_import analysis.inner_product_space.projection from "leanprover-community/mathlib"@"0b7c740e25651db0ba63648fbae9f9d6f941e31b"
/-!
# The orthogonal projection
Given a nonempty complete subspace `K` of an inner product space `E`, this file constructs
`orthogonalProjection K : E →L[𝕜] K`, the orthogonal projection of `E` onto `K`. This map
satisfies: for any point `u` in `E`, the point `v = orthogonalProjection K u` in `K` minimizes the
distance `‖u - v‖` to `u`.
Also a linear isometry equivalence `reflection K : E ≃ₗᵢ[𝕜] E` is constructed, by choosing, for
each `u : E`, the point `reflection K u` to satisfy
`u + (reflection K u) = 2 • orthogonalProjection K u`.
Basic API for `orthogonalProjection` and `reflection` is developed.
Next, the orthogonal projection is used to prove a series of more subtle lemmas about the
orthogonal complement of complete subspaces of `E` (the orthogonal complement itself was
defined in `Analysis.InnerProductSpace.Orthogonal`); the lemma
`Submodule.sup_orthogonal_of_completeSpace`, stating that for a complete subspace `K` of `E` we have
`K ⊔ Kᗮ = ⊤`, is a typical example.
## References
The orthogonal projection construction is adapted from
* [Clément & Martin, *The Lax-Milgram Theorem. A detailed proof to be formalized in Coq*]
* [Clément & Martin, *A Coq formal proof of the Lax–Milgram theorem*]
The Coq code is available at the following address: <http://www.lri.fr/~sboldo/elfic/index.html>
-/
noncomputable section
open RCLike Real Filter
open LinearMap (ker range)
open Topology
variable {𝕜 E F : Type*} [RCLike 𝕜]
variable [NormedAddCommGroup E] [NormedAddCommGroup F]
variable [InnerProductSpace 𝕜 E] [InnerProductSpace ℝ F]
local notation "⟪" x ", " y "⟫" => @inner 𝕜 _ _ x y
local notation "absR" => abs
/-! ### Orthogonal projection in inner product spaces -/
-- FIXME this monolithic proof causes a deterministic timeout with `-T50000`
-- It should be broken in a sequence of more manageable pieces,
-- perhaps with individual statements for the three steps below.
/-- Existence of minimizers
Let `u` be a point in a real inner product space, and let `K` be a nonempty complete convex subset.
Then there exists a (unique) `v` in `K` that minimizes the distance `‖u - v‖` to `u`.
-/
theorem exists_norm_eq_iInf_of_complete_convex {K : Set F} (ne : K.Nonempty) (h₁ : IsComplete K)
(h₂ : Convex ℝ K) : ∀ u : F, ∃ v ∈ K, ‖u - v‖ = ⨅ w : K, ‖u - w‖ := fun u => by
let δ := ⨅ w : K, ‖u - w‖
letI : Nonempty K := ne.to_subtype
have zero_le_δ : 0 ≤ δ := le_ciInf fun _ => norm_nonneg _
have δ_le : ∀ w : K, δ ≤ ‖u - w‖ := ciInf_le ⟨0, Set.forall_mem_range.2 fun _ => norm_nonneg _⟩
have δ_le' : ∀ w ∈ K, δ ≤ ‖u - w‖ := fun w hw => δ_le ⟨w, hw⟩
-- Step 1: since `δ` is the infimum, can find a sequence `w : ℕ → K` in `K`
-- such that `‖u - w n‖ < δ + 1 / (n + 1)` (which implies `‖u - w n‖ --> δ`);
-- maybe this should be a separate lemma
have exists_seq : ∃ w : ℕ → K, ∀ n, ‖u - w n‖ < δ + 1 / (n + 1) := by
have hδ : ∀ n : ℕ, δ < δ + 1 / (n + 1) := fun n =>
lt_add_of_le_of_pos le_rfl Nat.one_div_pos_of_nat
have h := fun n => exists_lt_of_ciInf_lt (hδ n)
let w : ℕ → K := fun n => Classical.choose (h n)
exact ⟨w, fun n => Classical.choose_spec (h n)⟩
rcases exists_seq with ⟨w, hw⟩
have norm_tendsto : Tendsto (fun n => ‖u - w n‖) atTop (𝓝 δ) := by
have h : Tendsto (fun _ : ℕ => δ) atTop (𝓝 δ) := tendsto_const_nhds
have h' : Tendsto (fun n : ℕ => δ + 1 / (n + 1)) atTop (𝓝 δ) := by
convert h.add tendsto_one_div_add_atTop_nhds_zero_nat
simp only [add_zero]
exact tendsto_of_tendsto_of_tendsto_of_le_of_le h h' (fun x => δ_le _) fun x => le_of_lt (hw _)
-- Step 2: Prove that the sequence `w : ℕ → K` is a Cauchy sequence
have seq_is_cauchy : CauchySeq fun n => (w n : F) := by
rw [cauchySeq_iff_le_tendsto_0]
-- splits into three goals
let b := fun n : ℕ => 8 * δ * (1 / (n + 1)) + 4 * (1 / (n + 1)) * (1 / (n + 1))
use fun n => √(b n)
constructor
-- first goal : `∀ (n : ℕ), 0 ≤ √(b n)`
· intro n
exact sqrt_nonneg _
constructor
-- second goal : `∀ (n m N : ℕ), N ≤ n → N ≤ m → dist ↑(w n) ↑(w m) ≤ √(b N)`
· intro p q N hp hq
let wp := (w p : F)
let wq := (w q : F)
let a := u - wq
let b := u - wp
let half := 1 / (2 : ℝ)
let div := 1 / ((N : ℝ) + 1)
have :
4 * ‖u - half • (wq + wp)‖ * ‖u - half • (wq + wp)‖ + ‖wp - wq‖ * ‖wp - wq‖ =
2 * (‖a‖ * ‖a‖ + ‖b‖ * ‖b‖) :=
calc
4 * ‖u - half • (wq + wp)‖ * ‖u - half • (wq + wp)‖ + ‖wp - wq‖ * ‖wp - wq‖ =
2 * ‖u - half • (wq + wp)‖ * (2 * ‖u - half • (wq + wp)‖) + ‖wp - wq‖ * ‖wp - wq‖ :=
by ring
_ =
absR (2 : ℝ) * ‖u - half • (wq + wp)‖ * (absR (2 : ℝ) * ‖u - half • (wq + wp)‖) +
‖wp - wq‖ * ‖wp - wq‖ := by
rw [_root_.abs_of_nonneg]
exact zero_le_two
_ =
‖(2 : ℝ) • (u - half • (wq + wp))‖ * ‖(2 : ℝ) • (u - half • (wq + wp))‖ +
‖wp - wq‖ * ‖wp - wq‖ := by simp [norm_smul]
_ = ‖a + b‖ * ‖a + b‖ + ‖a - b‖ * ‖a - b‖ := by
rw [smul_sub, smul_smul, mul_one_div_cancel (_root_.two_ne_zero : (2 : ℝ) ≠ 0), ←
one_add_one_eq_two, add_smul]
simp only [one_smul]
have eq₁ : wp - wq = a - b := (sub_sub_sub_cancel_left _ _ _).symm
have eq₂ : u + u - (wq + wp) = a + b := by
show u + u - (wq + wp) = u - wq + (u - wp)
abel
rw [eq₁, eq₂]
_ = 2 * (‖a‖ * ‖a‖ + ‖b‖ * ‖b‖) := parallelogram_law_with_norm ℝ _ _
have eq : δ ≤ ‖u - half • (wq + wp)‖ := by
rw [smul_add]
apply δ_le'
apply h₂
repeat' exact Subtype.mem _
repeat' exact le_of_lt one_half_pos
exact add_halves 1
have eq₁ : 4 * δ * δ ≤ 4 * ‖u - half • (wq + wp)‖ * ‖u - half • (wq + wp)‖ := by
simp_rw [mul_assoc]
gcongr
have eq₂ : ‖a‖ ≤ δ + div :=
le_trans (le_of_lt <| hw q) (add_le_add_left (Nat.one_div_le_one_div hq) _)
have eq₂' : ‖b‖ ≤ δ + div :=
le_trans (le_of_lt <| hw p) (add_le_add_left (Nat.one_div_le_one_div hp) _)
rw [dist_eq_norm]
apply nonneg_le_nonneg_of_sq_le_sq
· exact sqrt_nonneg _
rw [mul_self_sqrt]
· calc
‖wp - wq‖ * ‖wp - wq‖ =
2 * (‖a‖ * ‖a‖ + ‖b‖ * ‖b‖) - 4 * ‖u - half • (wq + wp)‖ * ‖u - half • (wq + wp)‖ := by
simp [← this]
_ ≤ 2 * (‖a‖ * ‖a‖ + ‖b‖ * ‖b‖) - 4 * δ * δ := by gcongr
_ ≤ 2 * ((δ + div) * (δ + div) + (δ + div) * (δ + div)) - 4 * δ * δ := by gcongr
_ = 8 * δ * div + 4 * div * div := by ring
positivity
-- third goal : `Tendsto (fun (n : ℕ) => √(b n)) atTop (𝓝 0)`
suffices Tendsto (fun x ↦ √(8 * δ * x + 4 * x * x) : ℝ → ℝ) (𝓝 0) (𝓝 0)
from this.comp tendsto_one_div_add_atTop_nhds_zero_nat
exact Continuous.tendsto' (by continuity) _ _ (by simp)
-- Step 3: By completeness of `K`, let `w : ℕ → K` converge to some `v : K`.
-- Prove that it satisfies all requirements.
rcases cauchySeq_tendsto_of_isComplete h₁ (fun n => Subtype.mem _) seq_is_cauchy with
⟨v, hv, w_tendsto⟩
use v
use hv
have h_cont : Continuous fun v => ‖u - v‖ :=
Continuous.comp continuous_norm (Continuous.sub continuous_const continuous_id)
have : Tendsto (fun n => ‖u - w n‖) atTop (𝓝 ‖u - v‖) := by
convert Tendsto.comp h_cont.continuousAt w_tendsto
exact tendsto_nhds_unique this norm_tendsto
#align exists_norm_eq_infi_of_complete_convex exists_norm_eq_iInf_of_complete_convex
/-- Characterization of minimizers for the projection on a convex set in a real inner product
space. -/
theorem norm_eq_iInf_iff_real_inner_le_zero {K : Set F} (h : Convex ℝ K) {u : F} {v : F}
(hv : v ∈ K) : (‖u - v‖ = ⨅ w : K, ‖u - w‖) ↔ ∀ w ∈ K, ⟪u - v, w - v⟫_ℝ ≤ 0 := by
letI : Nonempty K := ⟨⟨v, hv⟩⟩
constructor
· intro eq w hw
let δ := ⨅ w : K, ‖u - w‖
let p := ⟪u - v, w - v⟫_ℝ
let q := ‖w - v‖ ^ 2
have δ_le (w : K) : δ ≤ ‖u - w‖ := ciInf_le ⟨0, fun _ ⟨_, h⟩ => h ▸ norm_nonneg _⟩ _
have δ_le' (w) (hw : w ∈ K) : δ ≤ ‖u - w‖ := δ_le ⟨w, hw⟩
have (θ : ℝ) (hθ₁ : 0 < θ) (hθ₂ : θ ≤ 1) : 2 * p ≤ θ * q := by
have : ‖u - v‖ ^ 2 ≤ ‖u - v‖ ^ 2 - 2 * θ * ⟪u - v, w - v⟫_ℝ + θ * θ * ‖w - v‖ ^ 2 :=
calc ‖u - v‖ ^ 2
_ ≤ ‖u - (θ • w + (1 - θ) • v)‖ ^ 2 := by
simp only [sq]; apply mul_self_le_mul_self (norm_nonneg _)
rw [eq]; apply δ_le'
apply h hw hv
exacts [le_of_lt hθ₁, sub_nonneg.2 hθ₂, add_sub_cancel _ _]
_ = ‖u - v - θ • (w - v)‖ ^ 2 := by
have : u - (θ • w + (1 - θ) • v) = u - v - θ • (w - v) := by
rw [smul_sub, sub_smul, one_smul]
simp only [sub_eq_add_neg, add_comm, add_left_comm, add_assoc, neg_add_rev]
rw [this]
_ = ‖u - v‖ ^ 2 - 2 * θ * inner (u - v) (w - v) + θ * θ * ‖w - v‖ ^ 2 := by
rw [@norm_sub_sq ℝ, inner_smul_right, norm_smul]
simp only [sq]
show
‖u - v‖ * ‖u - v‖ - 2 * (θ * inner (u - v) (w - v)) +
absR θ * ‖w - v‖ * (absR θ * ‖w - v‖) =
‖u - v‖ * ‖u - v‖ - 2 * θ * inner (u - v) (w - v) + θ * θ * (‖w - v‖ * ‖w - v‖)
rw [abs_of_pos hθ₁]; ring
have eq₁ :
‖u - v‖ ^ 2 - 2 * θ * inner (u - v) (w - v) + θ * θ * ‖w - v‖ ^ 2 =
‖u - v‖ ^ 2 + (θ * θ * ‖w - v‖ ^ 2 - 2 * θ * inner (u - v) (w - v)) := by
abel
rw [eq₁, le_add_iff_nonneg_right] at this
have eq₂ :
θ * θ * ‖w - v‖ ^ 2 - 2 * θ * inner (u - v) (w - v) =
θ * (θ * ‖w - v‖ ^ 2 - 2 * inner (u - v) (w - v)) := by ring
rw [eq₂] at this
have := le_of_sub_nonneg (nonneg_of_mul_nonneg_right this hθ₁)
exact this
by_cases hq : q = 0
· rw [hq] at this
have : p ≤ 0 := by
have := this (1 : ℝ) (by norm_num) (by norm_num)
linarith
exact this
· have q_pos : 0 < q := lt_of_le_of_ne (sq_nonneg _) fun h ↦ hq h.symm
by_contra hp
rw [not_le] at hp
let θ := min (1 : ℝ) (p / q)
have eq₁ : θ * q ≤ p :=
calc
θ * q ≤ p / q * q := mul_le_mul_of_nonneg_right (min_le_right _ _) (sq_nonneg _)
_ = p := div_mul_cancel₀ _ hq
have : 2 * p ≤ p :=
calc
2 * p ≤ θ * q := by
set_option tactic.skipAssignedInstances false in
exact this θ (lt_min (by norm_num) (div_pos hp q_pos)) (by norm_num [θ])
_ ≤ p := eq₁
linarith
· intro h
apply le_antisymm
· apply le_ciInf
intro w
apply nonneg_le_nonneg_of_sq_le_sq (norm_nonneg _)
have := h w w.2
calc
‖u - v‖ * ‖u - v‖ ≤ ‖u - v‖ * ‖u - v‖ - 2 * inner (u - v) ((w : F) - v) := by linarith
_ ≤ ‖u - v‖ ^ 2 - 2 * inner (u - v) ((w : F) - v) + ‖(w : F) - v‖ ^ 2 := by
rw [sq]
refine le_add_of_nonneg_right ?_
exact sq_nonneg _
_ = ‖u - v - (w - v)‖ ^ 2 := (@norm_sub_sq ℝ _ _ _ _ _ _).symm
_ = ‖u - w‖ * ‖u - w‖ := by
have : u - v - (w - v) = u - w := by abel
rw [this, sq]
· show ⨅ w : K, ‖u - w‖ ≤ (fun w : K => ‖u - w‖) ⟨v, hv⟩
apply ciInf_le
use 0
rintro y ⟨z, rfl⟩
exact norm_nonneg _
#align norm_eq_infi_iff_real_inner_le_zero norm_eq_iInf_iff_real_inner_le_zero
variable (K : Submodule 𝕜 E)
/-- Existence of projections on complete subspaces.
Let `u` be a point in an inner product space, and let `K` be a nonempty complete subspace.
Then there exists a (unique) `v` in `K` that minimizes the distance `‖u - v‖` to `u`.
This point `v` is usually called the orthogonal projection of `u` onto `K`.
-/
theorem exists_norm_eq_iInf_of_complete_subspace (h : IsComplete (↑K : Set E)) :
∀ u : E, ∃ v ∈ K, ‖u - v‖ = ⨅ w : (K : Set E), ‖u - w‖ := by
letI : InnerProductSpace ℝ E := InnerProductSpace.rclikeToReal 𝕜 E
letI : Module ℝ E := RestrictScalars.module ℝ 𝕜 E
let K' : Submodule ℝ E := Submodule.restrictScalars ℝ K
exact exists_norm_eq_iInf_of_complete_convex ⟨0, K'.zero_mem⟩ h K'.convex
#align exists_norm_eq_infi_of_complete_subspace exists_norm_eq_iInf_of_complete_subspace
/-- Characterization of minimizers in the projection on a subspace, in the real case.
Let `u` be a point in a real inner product space, and let `K` be a nonempty subspace.
Then point `v` minimizes the distance `‖u - v‖` over points in `K` if and only if
for all `w ∈ K`, `⟪u - v, w⟫ = 0` (i.e., `u - v` is orthogonal to the subspace `K`).
This is superceded by `norm_eq_iInf_iff_inner_eq_zero` that gives the same conclusion over
any `RCLike` field.
-/
theorem norm_eq_iInf_iff_real_inner_eq_zero (K : Submodule ℝ F) {u : F} {v : F} (hv : v ∈ K) :
(‖u - v‖ = ⨅ w : (↑K : Set F), ‖u - w‖) ↔ ∀ w ∈ K, ⟪u - v, w⟫_ℝ = 0 :=
Iff.intro
(by
intro h
have h : ∀ w ∈ K, ⟪u - v, w - v⟫_ℝ ≤ 0 := by
rwa [norm_eq_iInf_iff_real_inner_le_zero] at h
exacts [K.convex, hv]
intro w hw
have le : ⟪u - v, w⟫_ℝ ≤ 0 := by
let w' := w + v
have : w' ∈ K := Submodule.add_mem _ hw hv
have h₁ := h w' this
have h₂ : w' - v = w := by
simp only [w', add_neg_cancel_right, sub_eq_add_neg]
rw [h₂] at h₁
exact h₁
have ge : ⟪u - v, w⟫_ℝ ≥ 0 := by
let w'' := -w + v
have : w'' ∈ K := Submodule.add_mem _ (Submodule.neg_mem _ hw) hv
have h₁ := h w'' this
have h₂ : w'' - v = -w := by
simp only [w'', neg_inj, add_neg_cancel_right, sub_eq_add_neg]
rw [h₂, inner_neg_right] at h₁
linarith
exact le_antisymm le ge)
(by
intro h
have : ∀ w ∈ K, ⟪u - v, w - v⟫_ℝ ≤ 0 := by
intro w hw
let w' := w - v
have : w' ∈ K := Submodule.sub_mem _ hw hv
have h₁ := h w' this
exact le_of_eq h₁
rwa [norm_eq_iInf_iff_real_inner_le_zero]
exacts [Submodule.convex _, hv])
#align norm_eq_infi_iff_real_inner_eq_zero norm_eq_iInf_iff_real_inner_eq_zero
/-- Characterization of minimizers in the projection on a subspace.
Let `u` be a point in an inner product space, and let `K` be a nonempty subspace.
Then point `v` minimizes the distance `‖u - v‖` over points in `K` if and only if
for all `w ∈ K`, `⟪u - v, w⟫ = 0` (i.e., `u - v` is orthogonal to the subspace `K`)
-/
theorem norm_eq_iInf_iff_inner_eq_zero {u : E} {v : E} (hv : v ∈ K) :
(‖u - v‖ = ⨅ w : K, ‖u - w‖) ↔ ∀ w ∈ K, ⟪u - v, w⟫ = 0 := by
letI : InnerProductSpace ℝ E := InnerProductSpace.rclikeToReal 𝕜 E
letI : Module ℝ E := RestrictScalars.module ℝ 𝕜 E
let K' : Submodule ℝ E := K.restrictScalars ℝ
constructor
· intro H
have A : ∀ w ∈ K, re ⟪u - v, w⟫ = 0 := (norm_eq_iInf_iff_real_inner_eq_zero K' hv).1 H
intro w hw
apply ext
· simp [A w hw]
· symm
calc
im (0 : 𝕜) = 0 := im.map_zero
_ = re ⟪u - v, (-I : 𝕜) • w⟫ := (A _ (K.smul_mem (-I) hw)).symm
_ = re (-I * ⟪u - v, w⟫) := by rw [inner_smul_right]
_ = im ⟪u - v, w⟫ := by simp
· intro H
have : ∀ w ∈ K', ⟪u - v, w⟫_ℝ = 0 := by
intro w hw
rw [real_inner_eq_re_inner, H w hw]
exact zero_re'
exact (norm_eq_iInf_iff_real_inner_eq_zero K' hv).2 this
#align norm_eq_infi_iff_inner_eq_zero norm_eq_iInf_iff_inner_eq_zero
/-- A subspace `K : Submodule 𝕜 E` has an orthogonal projection if evey vector `v : E` admits an
orthogonal projection to `K`. -/
class HasOrthogonalProjection (K : Submodule 𝕜 E) : Prop where
exists_orthogonal (v : E) : ∃ w ∈ K, v - w ∈ Kᗮ
instance (priority := 100) HasOrthogonalProjection.ofCompleteSpace [CompleteSpace K] :
HasOrthogonalProjection K where
exists_orthogonal v := by
rcases exists_norm_eq_iInf_of_complete_subspace K (completeSpace_coe_iff_isComplete.mp ‹_›) v
with ⟨w, hwK, hw⟩
refine ⟨w, hwK, (K.mem_orthogonal' _).2 ?_⟩
rwa [← norm_eq_iInf_iff_inner_eq_zero K hwK]
instance [HasOrthogonalProjection K] : HasOrthogonalProjection Kᗮ where
exists_orthogonal v := by
rcases HasOrthogonalProjection.exists_orthogonal (K := K) v with ⟨w, hwK, hw⟩
refine ⟨_, hw, ?_⟩
rw [sub_sub_cancel]
exact K.le_orthogonal_orthogonal hwK
instance HasOrthogonalProjection.map_linearIsometryEquiv [HasOrthogonalProjection K]
{E' : Type*} [NormedAddCommGroup E'] [InnerProductSpace 𝕜 E'] (f : E ≃ₗᵢ[𝕜] E') :
HasOrthogonalProjection (K.map (f.toLinearEquiv : E →ₗ[𝕜] E')) where
exists_orthogonal v := by
rcases HasOrthogonalProjection.exists_orthogonal (K := K) (f.symm v) with ⟨w, hwK, hw⟩
refine ⟨f w, Submodule.mem_map_of_mem hwK, Set.forall_mem_image.2 fun u hu ↦ ?_⟩
erw [← f.symm.inner_map_map, f.symm_apply_apply, map_sub, f.symm_apply_apply, hw u hu]
instance HasOrthogonalProjection.map_linearIsometryEquiv' [HasOrthogonalProjection K]
{E' : Type*} [NormedAddCommGroup E'] [InnerProductSpace 𝕜 E'] (f : E ≃ₗᵢ[𝕜] E') :
HasOrthogonalProjection (K.map f.toLinearIsometry) :=
HasOrthogonalProjection.map_linearIsometryEquiv K f
instance : HasOrthogonalProjection (⊤ : Submodule 𝕜 E) := ⟨fun v ↦ ⟨v, trivial, by simp⟩⟩
section orthogonalProjection
variable [HasOrthogonalProjection K]
/-- The orthogonal projection onto a complete subspace, as an
unbundled function. This definition is only intended for use in
setting up the bundled version `orthogonalProjection` and should not
be used once that is defined. -/
def orthogonalProjectionFn (v : E) :=
(HasOrthogonalProjection.exists_orthogonal (K := K) v).choose
#align orthogonal_projection_fn orthogonalProjectionFn
variable {K}
/-- The unbundled orthogonal projection is in the given subspace.
This lemma is only intended for use in setting up the bundled version
and should not be used once that is defined. -/
theorem orthogonalProjectionFn_mem (v : E) : orthogonalProjectionFn K v ∈ K :=
(HasOrthogonalProjection.exists_orthogonal (K := K) v).choose_spec.left
#align orthogonal_projection_fn_mem orthogonalProjectionFn_mem
/-- The characterization of the unbundled orthogonal projection. This
lemma is only intended for use in setting up the bundled version
and should not be used once that is defined. -/
theorem orthogonalProjectionFn_inner_eq_zero (v : E) :
∀ w ∈ K, ⟪v - orthogonalProjectionFn K v, w⟫ = 0 :=
(K.mem_orthogonal' _).1 (HasOrthogonalProjection.exists_orthogonal (K := K) v).choose_spec.right
#align orthogonal_projection_fn_inner_eq_zero orthogonalProjectionFn_inner_eq_zero
/-- The unbundled orthogonal projection is the unique point in `K`
with the orthogonality property. This lemma is only intended for use
in setting up the bundled version and should not be used once that is
defined. -/
theorem eq_orthogonalProjectionFn_of_mem_of_inner_eq_zero {u v : E} (hvm : v ∈ K)
(hvo : ∀ w ∈ K, ⟪u - v, w⟫ = 0) : orthogonalProjectionFn K u = v := by
rw [← sub_eq_zero, ← @inner_self_eq_zero 𝕜]
have hvs : orthogonalProjectionFn K u - v ∈ K :=
Submodule.sub_mem K (orthogonalProjectionFn_mem u) hvm
have huo : ⟪u - orthogonalProjectionFn K u, orthogonalProjectionFn K u - v⟫ = 0 :=
orthogonalProjectionFn_inner_eq_zero u _ hvs
have huv : ⟪u - v, orthogonalProjectionFn K u - v⟫ = 0 := hvo _ hvs
have houv : ⟪u - v - (u - orthogonalProjectionFn K u), orthogonalProjectionFn K u - v⟫ = 0 := by
rw [inner_sub_left, huo, huv, sub_zero]
rwa [sub_sub_sub_cancel_left] at houv
#align eq_orthogonal_projection_fn_of_mem_of_inner_eq_zero eq_orthogonalProjectionFn_of_mem_of_inner_eq_zero
variable (K)
theorem orthogonalProjectionFn_norm_sq (v : E) :
‖v‖ * ‖v‖ =
‖v - orthogonalProjectionFn K v‖ * ‖v - orthogonalProjectionFn K v‖ +
‖orthogonalProjectionFn K v‖ * ‖orthogonalProjectionFn K v‖ := by
set p := orthogonalProjectionFn K v
have h' : ⟪v - p, p⟫ = 0 :=
orthogonalProjectionFn_inner_eq_zero _ _ (orthogonalProjectionFn_mem v)
convert norm_add_sq_eq_norm_sq_add_norm_sq_of_inner_eq_zero (v - p) p h' using 2 <;> simp
#align orthogonal_projection_fn_norm_sq orthogonalProjectionFn_norm_sq
/-- The orthogonal projection onto a complete subspace. -/
def orthogonalProjection : E →L[𝕜] K :=
LinearMap.mkContinuous
{ toFun := fun v => ⟨orthogonalProjectionFn K v, orthogonalProjectionFn_mem v⟩
map_add' := fun x y => by
have hm : orthogonalProjectionFn K x + orthogonalProjectionFn K y ∈ K :=
Submodule.add_mem K (orthogonalProjectionFn_mem x) (orthogonalProjectionFn_mem y)
have ho :
∀ w ∈ K, ⟪x + y - (orthogonalProjectionFn K x + orthogonalProjectionFn K y), w⟫ = 0 := by
intro w hw
rw [add_sub_add_comm, inner_add_left, orthogonalProjectionFn_inner_eq_zero _ w hw,
orthogonalProjectionFn_inner_eq_zero _ w hw, add_zero]
ext
simp [eq_orthogonalProjectionFn_of_mem_of_inner_eq_zero hm ho]
map_smul' := fun c x => by
have hm : c • orthogonalProjectionFn K x ∈ K :=
Submodule.smul_mem K _ (orthogonalProjectionFn_mem x)
have ho : ∀ w ∈ K, ⟪c • x - c • orthogonalProjectionFn K x, w⟫ = 0 := by
intro w hw
rw [← smul_sub, inner_smul_left, orthogonalProjectionFn_inner_eq_zero _ w hw,
mul_zero]
ext
simp [eq_orthogonalProjectionFn_of_mem_of_inner_eq_zero hm ho] }
1 fun x => by
simp only [one_mul, LinearMap.coe_mk]
refine le_of_pow_le_pow_left two_ne_zero (norm_nonneg _) ?_
change ‖orthogonalProjectionFn K x‖ ^ 2 ≤ ‖x‖ ^ 2
nlinarith [orthogonalProjectionFn_norm_sq K x]
#align orthogonal_projection orthogonalProjection
variable {K}
@[simp]
theorem orthogonalProjectionFn_eq (v : E) :
orthogonalProjectionFn K v = (orthogonalProjection K v : E) :=
rfl
#align orthogonal_projection_fn_eq orthogonalProjectionFn_eq
/-- The characterization of the orthogonal projection. -/
@[simp]
theorem orthogonalProjection_inner_eq_zero (v : E) :
∀ w ∈ K, ⟪v - orthogonalProjection K v, w⟫ = 0 :=
orthogonalProjectionFn_inner_eq_zero v
#align orthogonal_projection_inner_eq_zero orthogonalProjection_inner_eq_zero
/-- The difference of `v` from its orthogonal projection onto `K` is in `Kᗮ`. -/
@[simp]
theorem sub_orthogonalProjection_mem_orthogonal (v : E) : v - orthogonalProjection K v ∈ Kᗮ := by
intro w hw
rw [inner_eq_zero_symm]
exact orthogonalProjection_inner_eq_zero _ _ hw
#align sub_orthogonal_projection_mem_orthogonal sub_orthogonalProjection_mem_orthogonal
/-- The orthogonal projection is the unique point in `K` with the
orthogonality property. -/
theorem eq_orthogonalProjection_of_mem_of_inner_eq_zero {u v : E} (hvm : v ∈ K)
(hvo : ∀ w ∈ K, ⟪u - v, w⟫ = 0) : (orthogonalProjection K u : E) = v :=
eq_orthogonalProjectionFn_of_mem_of_inner_eq_zero hvm hvo
#align eq_orthogonal_projection_of_mem_of_inner_eq_zero eq_orthogonalProjection_of_mem_of_inner_eq_zero
/-- A point in `K` with the orthogonality property (here characterized in terms of `Kᗮ`) must be the
orthogonal projection. -/
theorem eq_orthogonalProjection_of_mem_orthogonal {u v : E} (hv : v ∈ K)
(hvo : u - v ∈ Kᗮ) : (orthogonalProjection K u : E) = v :=
eq_orthogonalProjectionFn_of_mem_of_inner_eq_zero hv <| (Submodule.mem_orthogonal' _ _).1 hvo
#align eq_orthogonal_projection_of_mem_orthogonal eq_orthogonalProjection_of_mem_orthogonal
/-- A point in `K` with the orthogonality property (here characterized in terms of `Kᗮ`) must be the
orthogonal projection. -/
theorem eq_orthogonalProjection_of_mem_orthogonal' {u v z : E}
(hv : v ∈ K) (hz : z ∈ Kᗮ) (hu : u = v + z) : (orthogonalProjection K u : E) = v :=
eq_orthogonalProjection_of_mem_orthogonal hv (by simpa [hu] )
#align eq_orthogonal_projection_of_mem_orthogonal' eq_orthogonalProjection_of_mem_orthogonal'
@[simp]
theorem orthogonalProjection_orthogonal_val (u : E) :
(orthogonalProjection Kᗮ u : E) = u - orthogonalProjection K u :=
eq_orthogonalProjection_of_mem_orthogonal' (sub_orthogonalProjection_mem_orthogonal _)
(K.le_orthogonal_orthogonal (orthogonalProjection K u).2) <| by simp
theorem orthogonalProjection_orthogonal (u : E) :
orthogonalProjection Kᗮ u =
⟨u - orthogonalProjection K u, sub_orthogonalProjection_mem_orthogonal _⟩ :=
Subtype.eq <| orthogonalProjection_orthogonal_val _
/-- The orthogonal projection of `y` on `U` minimizes the distance `‖y - x‖` for `x ∈ U`. -/
theorem orthogonalProjection_minimal {U : Submodule 𝕜 E} [HasOrthogonalProjection U] (y : E) :
‖y - orthogonalProjection U y‖ = ⨅ x : U, ‖y - x‖ := by
rw [norm_eq_iInf_iff_inner_eq_zero _ (Submodule.coe_mem _)]
exact orthogonalProjection_inner_eq_zero _
#align orthogonal_projection_minimal orthogonalProjection_minimal
/-- The orthogonal projections onto equal subspaces are coerced back to the same point in `E`. -/
theorem eq_orthogonalProjection_of_eq_submodule {K' : Submodule 𝕜 E} [HasOrthogonalProjection K']
(h : K = K') (u : E) : (orthogonalProjection K u : E) = (orthogonalProjection K' u : E) := by
subst h; rfl
#align eq_orthogonal_projection_of_eq_submodule eq_orthogonalProjection_of_eq_submodule
/-- The orthogonal projection sends elements of `K` to themselves. -/
@[simp]
theorem orthogonalProjection_mem_subspace_eq_self (v : K) : orthogonalProjection K v = v := by
ext
apply eq_orthogonalProjection_of_mem_of_inner_eq_zero <;> simp
#align orthogonal_projection_mem_subspace_eq_self orthogonalProjection_mem_subspace_eq_self
/-- A point equals its orthogonal projection if and only if it lies in the subspace. -/
theorem orthogonalProjection_eq_self_iff {v : E} : (orthogonalProjection K v : E) = v ↔ v ∈ K := by
refine ⟨fun h => ?_, fun h => eq_orthogonalProjection_of_mem_of_inner_eq_zero h ?_⟩
· rw [← h]
simp
· simp
#align orthogonal_projection_eq_self_iff orthogonalProjection_eq_self_iff
@[simp]
| Mathlib/Analysis/InnerProductSpace/Projection.lean | 565 | 569 | theorem orthogonalProjection_eq_zero_iff {v : E} : orthogonalProjection K v = 0 ↔ v ∈ Kᗮ := by |
refine ⟨fun h ↦ ?_, fun h ↦ Subtype.eq <| eq_orthogonalProjection_of_mem_orthogonal
(zero_mem _) ?_⟩
· simpa [h] using sub_orthogonalProjection_mem_orthogonal (K := K) v
· simpa
|
/-
Copyright (c) 2022 Thomas Browning. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Thomas Browning
-/
import Mathlib.GroupTheory.Abelianization
import Mathlib.GroupTheory.Exponent
import Mathlib.GroupTheory.Transfer
#align_import group_theory.schreier from "leanprover-community/mathlib"@"8350c34a64b9bc3fc64335df8006bffcadc7baa6"
/-!
# Schreier's Lemma
In this file we prove Schreier's lemma.
## Main results
- `closure_mul_image_eq` : **Schreier's Lemma**: If `R : Set G` is a right_transversal
of `H : Subgroup G` with `1 ∈ R`, and if `G` is generated by `S : Set G`,
then `H` is generated by the `Set` `(R * S).image (fun g ↦ g * (toFun hR g)⁻¹)`.
- `fg_of_index_ne_zero` : **Schreier's Lemma**: A finite index subgroup of a finitely generated
group is finitely generated.
- `card_commutator_le_of_finite_commutatorSet`: A theorem of Schur: The size of the commutator
subgroup is bounded in terms of the number of commutators.
-/
open scoped Pointwise
namespace Subgroup
open MemRightTransversals
variable {G : Type*} [Group G] {H : Subgroup G} {R S : Set G}
theorem closure_mul_image_mul_eq_top
(hR : R ∈ rightTransversals (H : Set G)) (hR1 : (1 : G) ∈ R) (hS : closure S = ⊤) :
(closure ((R * S).image fun g => g * (toFun hR g : G)⁻¹)) * R = ⊤ := by
let f : G → R := fun g => toFun hR g
let U : Set G := (R * S).image fun g => g * (f g : G)⁻¹
change (closure U : Set G) * R = ⊤
refine top_le_iff.mp fun g _ => ?_
refine closure_induction_right ?_ ?_ ?_ (eq_top_iff.mp hS (mem_top g))
· exact ⟨1, (closure U).one_mem, 1, hR1, one_mul 1⟩
· rintro - - s hs ⟨u, hu, r, hr, rfl⟩
rw [show u * r * s = u * (r * s * (f (r * s) : G)⁻¹) * f (r * s) by group]
refine Set.mul_mem_mul ((closure U).mul_mem hu ?_) (f (r * s)).coe_prop
exact subset_closure ⟨r * s, Set.mul_mem_mul hr hs, rfl⟩
· rintro - - s hs ⟨u, hu, r, hr, rfl⟩
rw [show u * r * s⁻¹ = u * (f (r * s⁻¹) * s * r⁻¹)⁻¹ * f (r * s⁻¹) by group]
refine Set.mul_mem_mul ((closure U).mul_mem hu ((closure U).inv_mem ?_)) (f (r * s⁻¹)).2
refine subset_closure ⟨f (r * s⁻¹) * s, Set.mul_mem_mul (f (r * s⁻¹)).2 hs, ?_⟩
rw [mul_right_inj, inv_inj, ← Subtype.coe_mk r hr, ← Subtype.ext_iff, Subtype.coe_mk]
apply (mem_rightTransversals_iff_existsUnique_mul_inv_mem.mp hR (f (r * s⁻¹) * s)).unique
(mul_inv_toFun_mem hR (f (r * s⁻¹) * s))
rw [mul_assoc, ← inv_inv s, ← mul_inv_rev, inv_inv]
exact toFun_mul_inv_mem hR (r * s⁻¹)
#align subgroup.closure_mul_image_mul_eq_top Subgroup.closure_mul_image_mul_eq_top
/-- **Schreier's Lemma**: If `R : Set G` is a `rightTransversal` of `H : Subgroup G`
with `1 ∈ R`, and if `G` is generated by `S : Set G`, then `H` is generated by the `Set`
`(R * S).image (fun g ↦ g * (toFun hR g)⁻¹)`. -/
theorem closure_mul_image_eq (hR : R ∈ rightTransversals (H : Set G)) (hR1 : (1 : G) ∈ R)
(hS : closure S = ⊤) : closure ((R * S).image fun g => g * (toFun hR g : G)⁻¹) = H := by
have hU : closure ((R * S).image fun g => g * (toFun hR g : G)⁻¹) ≤ H := by
rw [closure_le]
rintro - ⟨g, -, rfl⟩
exact mul_inv_toFun_mem hR g
refine le_antisymm hU fun h hh => ?_
obtain ⟨g, hg, r, hr, rfl⟩ :=
show h ∈ _ from eq_top_iff.mp (closure_mul_image_mul_eq_top hR hR1 hS) (mem_top h)
suffices (⟨r, hr⟩ : R) = (⟨1, hR1⟩ : R) by
simpa only [show r = 1 from Subtype.ext_iff.mp this, mul_one]
apply (mem_rightTransversals_iff_existsUnique_mul_inv_mem.mp hR r).unique
· rw [Subtype.coe_mk, mul_inv_self]
exact H.one_mem
· rw [Subtype.coe_mk, inv_one, mul_one]
exact (H.mul_mem_cancel_left (hU hg)).mp hh
#align subgroup.closure_mul_image_eq Subgroup.closure_mul_image_eq
/-- **Schreier's Lemma**: If `R : Set G` is a `rightTransversal` of `H : Subgroup G`
with `1 ∈ R`, and if `G` is generated by `S : Set G`, then `H` is generated by the `Set`
`(R * S).image (fun g ↦ g * (toFun hR g)⁻¹)`. -/
| Mathlib/GroupTheory/Schreier.lean | 85 | 89 | theorem closure_mul_image_eq_top (hR : R ∈ rightTransversals (H : Set G)) (hR1 : (1 : G) ∈ R)
(hS : closure S = ⊤) : closure ((R * S).image fun g =>
⟨g * (toFun hR g : G)⁻¹, mul_inv_toFun_mem hR g⟩ : Set H) = ⊤ := by |
rw [eq_top_iff, ← map_subtype_le_map_subtype, MonoidHom.map_closure, Set.image_image]
exact (map_subtype_le ⊤).trans (ge_of_eq (closure_mul_image_eq hR hR1 hS))
|
/-
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
-/
import Mathlib.MeasureTheory.Measure.Lebesgue.EqHaar
import Mathlib.MeasureTheory.Covering.Besicovitch
import Mathlib.Tactic.AdaptationNote
#align_import measure_theory.covering.besicovitch_vector_space from "leanprover-community/mathlib"@"fd5edc43dc4f10b85abfe544b88f82cf13c5f844"
/-!
# Satellite configurations for Besicovitch covering lemma in vector spaces
The Besicovitch covering theorem ensures that, in a nice metric space, there exists a number `N`
such that, from any family of balls with bounded radii, one can extract `N` families, each made of
disjoint balls, covering together all the centers of the initial family.
A key tool in the proof of this theorem is the notion of a satellite configuration, i.e., a family
of `N + 1` balls, where the first `N` balls all intersect the last one, but none of them contains
the center of another one and their radii are controlled. This is a technical notion, but it shows
up naturally in the proof of the Besicovitch theorem (which goes through a greedy algorithm): to
ensure that in the end one needs at most `N` families of balls, the crucial property of the
underlying metric space is that there should be no satellite configuration of `N + 1` points.
This file is devoted to the study of this property in vector spaces: we prove the main result
of [Füredi and Loeb, On the best constant for the Besicovitch covering theorem][furedi-loeb1994],
which shows that the optimal such `N` in a vector space coincides with the maximal number
of points one can put inside the unit ball of radius `2` under the condition that their distances
are bounded below by `1`.
In particular, this number is bounded by `5 ^ dim` by a straightforward measure argument.
## Main definitions and results
* `multiplicity E` is the maximal number of points one can put inside the unit ball
of radius `2` in the vector space `E`, under the condition that their distances
are bounded below by `1`.
* `multiplicity_le E` shows that `multiplicity E ≤ 5 ^ (dim E)`.
* `good_τ E` is a constant `> 1`, but close enough to `1` that satellite configurations
with this parameter `τ` are not worst than for `τ = 1`.
* `isEmpty_satelliteConfig_multiplicity` is the main theorem, saying that there are
no satellite configurations of `(multiplicity E) + 1` points, for the parameter `goodτ E`.
-/
universe u
open Metric Set FiniteDimensional MeasureTheory Filter Fin
open scoped ENNReal Topology
noncomputable section
namespace Besicovitch
variable {E : Type*} [NormedAddCommGroup E]
namespace SatelliteConfig
variable [NormedSpace ℝ E] {N : ℕ} {τ : ℝ} (a : SatelliteConfig E N τ)
/-- Rescaling a satellite configuration in a vector space, to put the basepoint at `0` and the base
radius at `1`. -/
def centerAndRescale : SatelliteConfig E N τ where
c i := (a.r (last N))⁻¹ • (a.c i - a.c (last N))
r i := (a.r (last N))⁻¹ * a.r i
rpos i := by positivity
h i j hij := by
simp (disch := positivity) only [dist_smul₀, dist_sub_right, mul_left_comm τ,
Real.norm_of_nonneg]
rcases a.h hij with (⟨H₁, H₂⟩ | ⟨H₁, H₂⟩) <;> [left; right] <;> constructor <;> gcongr
hlast i hi := by
simp (disch := positivity) only [dist_smul₀, dist_sub_right, mul_left_comm τ,
Real.norm_of_nonneg]
have ⟨H₁, H₂⟩ := a.hlast i hi
constructor <;> gcongr
inter i hi := by
simp (disch := positivity) only [dist_smul₀, ← mul_add, dist_sub_right, Real.norm_of_nonneg]
gcongr
exact a.inter i hi
#align besicovitch.satellite_config.center_and_rescale Besicovitch.SatelliteConfig.centerAndRescale
theorem centerAndRescale_center : a.centerAndRescale.c (last N) = 0 := by
simp [SatelliteConfig.centerAndRescale]
#align besicovitch.satellite_config.center_and_rescale_center Besicovitch.SatelliteConfig.centerAndRescale_center
theorem centerAndRescale_radius {N : ℕ} {τ : ℝ} (a : SatelliteConfig E N τ) :
a.centerAndRescale.r (last N) = 1 := by
simp [SatelliteConfig.centerAndRescale, inv_mul_cancel (a.rpos _).ne']
#align besicovitch.satellite_config.center_and_rescale_radius Besicovitch.SatelliteConfig.centerAndRescale_radius
end SatelliteConfig
/-! ### Disjoint balls of radius close to `1` in the radius `2` ball. -/
/-- The maximum cardinality of a `1`-separated set in the ball of radius `2`. This is also the
optimal number of families in the Besicovitch covering theorem. -/
def multiplicity (E : Type*) [NormedAddCommGroup E] :=
sSup {N | ∃ s : Finset E, s.card = N ∧ (∀ c ∈ s, ‖c‖ ≤ 2) ∧ ∀ c ∈ s, ∀ d ∈ s, c ≠ d → 1 ≤ ‖c - d‖}
#align besicovitch.multiplicity Besicovitch.multiplicity
section
variable [NormedSpace ℝ E] [FiniteDimensional ℝ E]
/-- Any `1`-separated set in the ball of radius `2` has cardinality at most `5 ^ dim`. This is
useful to show that the supremum in the definition of `Besicovitch.multiplicity E` is
well behaved. -/
theorem card_le_of_separated (s : Finset E) (hs : ∀ c ∈ s, ‖c‖ ≤ 2)
(h : ∀ c ∈ s, ∀ d ∈ s, c ≠ d → 1 ≤ ‖c - d‖) : s.card ≤ 5 ^ finrank ℝ E := by
/- We consider balls of radius `1/2` around the points in `s`. They are disjoint, and all
contained in the ball of radius `5/2`. A volume argument gives `s.card * (1/2)^dim ≤ (5/2)^dim`,
i.e., `s.card ≤ 5^dim`. -/
borelize E
let μ : Measure E := Measure.addHaar
let δ : ℝ := (1 : ℝ) / 2
let ρ : ℝ := (5 : ℝ) / 2
have ρpos : 0 < ρ := by norm_num
set A := ⋃ c ∈ s, ball (c : E) δ with hA
have D : Set.Pairwise (s : Set E) (Disjoint on fun c => ball (c : E) δ) := by
rintro c hc d hd hcd
apply ball_disjoint_ball
rw [dist_eq_norm]
convert h c hc d hd hcd
norm_num
have A_subset : A ⊆ ball (0 : E) ρ := by
refine iUnion₂_subset fun x hx => ?_
apply ball_subset_ball'
calc
δ + dist x 0 ≤ δ + 2 := by rw [dist_zero_right]; exact add_le_add le_rfl (hs x hx)
_ = 5 / 2 := by norm_num
have I :
(s.card : ℝ≥0∞) * ENNReal.ofReal (δ ^ finrank ℝ E) * μ (ball 0 1) ≤
ENNReal.ofReal (ρ ^ finrank ℝ E) * μ (ball 0 1) :=
calc
(s.card : ℝ≥0∞) * ENNReal.ofReal (δ ^ finrank ℝ E) * μ (ball 0 1) = μ A := by
rw [hA, measure_biUnion_finset D fun c _ => measurableSet_ball]
have I : 0 < δ := by norm_num
simp only [div_pow, μ.addHaar_ball_of_pos _ I]
simp only [one_div, one_pow, Finset.sum_const, nsmul_eq_mul, mul_assoc]
_ ≤ μ (ball (0 : E) ρ) := measure_mono A_subset
_ = ENNReal.ofReal (ρ ^ finrank ℝ E) * μ (ball 0 1) := by
simp only [μ.addHaar_ball_of_pos _ ρpos]
have J : (s.card : ℝ≥0∞) * ENNReal.ofReal (δ ^ finrank ℝ E) ≤ ENNReal.ofReal (ρ ^ finrank ℝ E) :=
(ENNReal.mul_le_mul_right (measure_ball_pos _ _ zero_lt_one).ne' measure_ball_lt_top.ne).1 I
have K : (s.card : ℝ) ≤ (5 : ℝ) ^ finrank ℝ E := by
have := ENNReal.toReal_le_of_le_ofReal (pow_nonneg ρpos.le _) J
simpa [ρ, δ, div_eq_mul_inv, mul_pow] using this
exact mod_cast K
#align besicovitch.card_le_of_separated Besicovitch.card_le_of_separated
theorem multiplicity_le : multiplicity E ≤ 5 ^ finrank ℝ E := by
apply csSup_le
· refine ⟨0, ⟨∅, by simp⟩⟩
· rintro _ ⟨s, ⟨rfl, h⟩⟩
exact Besicovitch.card_le_of_separated s h.1 h.2
#align besicovitch.multiplicity_le Besicovitch.multiplicity_le
theorem card_le_multiplicity {s : Finset E} (hs : ∀ c ∈ s, ‖c‖ ≤ 2)
(h's : ∀ c ∈ s, ∀ d ∈ s, c ≠ d → 1 ≤ ‖c - d‖) : s.card ≤ multiplicity E := by
apply le_csSup
· refine ⟨5 ^ finrank ℝ E, ?_⟩
rintro _ ⟨s, ⟨rfl, h⟩⟩
exact Besicovitch.card_le_of_separated s h.1 h.2
· simp only [mem_setOf_eq, Ne]
exact ⟨s, rfl, hs, h's⟩
#align besicovitch.card_le_multiplicity Besicovitch.card_le_multiplicity
variable (E)
/-- If `δ` is small enough, a `(1-δ)`-separated set in the ball of radius `2` also has cardinality
at most `multiplicity E`. -/
| Mathlib/MeasureTheory/Covering/BesicovitchVectorSpace.lean | 174 | 246 | theorem exists_goodδ :
∃ δ : ℝ, 0 < δ ∧ δ < 1 ∧ ∀ s : Finset E, (∀ c ∈ s, ‖c‖ ≤ 2) →
(∀ c ∈ s, ∀ d ∈ s, c ≠ d → 1 - δ ≤ ‖c - d‖) → s.card ≤ multiplicity E := by |
classical
/- This follows from a compactness argument: otherwise, one could extract a converging
subsequence, to obtain a `1`-separated set in the ball of radius `2` with cardinality
`N = multiplicity E + 1`. To formalize this, we work with functions `Fin N → E`.
-/
by_contra! h
set N := multiplicity E + 1 with hN
have :
∀ δ : ℝ, 0 < δ → ∃ f : Fin N → E, (∀ i : Fin N, ‖f i‖ ≤ 2) ∧
Pairwise fun i j => 1 - δ ≤ ‖f i - f j‖ := by
intro δ hδ
rcases lt_or_le δ 1 with (hδ' | hδ')
· rcases h δ hδ hδ' with ⟨s, hs, h's, s_card⟩
obtain ⟨f, f_inj, hfs⟩ : ∃ f : Fin N → E, Function.Injective f ∧ range f ⊆ ↑s := by
have : Fintype.card (Fin N) ≤ s.card := by simp only [Fintype.card_fin]; exact s_card
rcases Function.Embedding.exists_of_card_le_finset this with ⟨f, hf⟩
exact ⟨f, f.injective, hf⟩
simp only [range_subset_iff, Finset.mem_coe] at hfs
exact ⟨f, fun i => hs _ (hfs i), fun i j hij => h's _ (hfs i) _ (hfs j) (f_inj.ne hij)⟩
· exact
⟨fun _ => 0, by simp, fun i j _ => by
simpa only [norm_zero, sub_nonpos, sub_self]⟩
-- For `δ > 0`, `F δ` is a function from `fin N` to the ball of radius `2` for which two points
-- in the image are separated by `1 - δ`.
choose! F hF using this
-- Choose a converging subsequence when `δ → 0`.
have : ∃ f : Fin N → E, (∀ i : Fin N, ‖f i‖ ≤ 2) ∧ Pairwise fun i j => 1 ≤ ‖f i - f j‖ := by
obtain ⟨u, _, zero_lt_u, hu⟩ :
∃ u : ℕ → ℝ,
(∀ m n : ℕ, m < n → u n < u m) ∧ (∀ n : ℕ, 0 < u n) ∧ Filter.Tendsto u Filter.atTop (𝓝 0) :=
exists_seq_strictAnti_tendsto (0 : ℝ)
have A : ∀ n, F (u n) ∈ closedBall (0 : Fin N → E) 2 := by
intro n
simp only [pi_norm_le_iff_of_nonneg zero_le_two, mem_closedBall, dist_zero_right,
(hF (u n) (zero_lt_u n)).left, forall_const]
obtain ⟨f, fmem, φ, φ_mono, hf⟩ :
∃ f ∈ closedBall (0 : Fin N → E) 2,
∃ φ : ℕ → ℕ, StrictMono φ ∧ Tendsto ((F ∘ u) ∘ φ) atTop (𝓝 f) :=
IsCompact.tendsto_subseq (isCompact_closedBall _ _) A
refine ⟨f, fun i => ?_, fun i j hij => ?_⟩
· simp only [pi_norm_le_iff_of_nonneg zero_le_two, mem_closedBall, dist_zero_right] at fmem
exact fmem i
· have A : Tendsto (fun n => ‖F (u (φ n)) i - F (u (φ n)) j‖) atTop (𝓝 ‖f i - f j‖) :=
((hf.apply_nhds i).sub (hf.apply_nhds j)).norm
have B : Tendsto (fun n => 1 - u (φ n)) atTop (𝓝 (1 - 0)) :=
tendsto_const_nhds.sub (hu.comp φ_mono.tendsto_atTop)
rw [sub_zero] at B
exact le_of_tendsto_of_tendsto' B A fun n => (hF (u (φ n)) (zero_lt_u _)).2 hij
rcases this with ⟨f, hf, h'f⟩
-- the range of `f` contradicts the definition of `multiplicity E`.
have finj : Function.Injective f := by
intro i j hij
by_contra h
have : 1 ≤ ‖f i - f j‖ := h'f h
simp only [hij, norm_zero, sub_self] at this
exact lt_irrefl _ (this.trans_lt zero_lt_one)
let s := Finset.image f Finset.univ
have s_card : s.card = N := by rw [Finset.card_image_of_injective _ finj]; exact Finset.card_fin N
have hs : ∀ c ∈ s, ‖c‖ ≤ 2 := by
simp only [s, hf, forall_apply_eq_imp_iff, forall_const, forall_exists_index, Finset.mem_univ,
Finset.mem_image, true_and]
have h's : ∀ c ∈ s, ∀ d ∈ s, c ≠ d → 1 ≤ ‖c - d‖ := by
simp only [s, forall_apply_eq_imp_iff, forall_exists_index, Finset.mem_univ, Finset.mem_image,
Ne, exists_true_left, forall_apply_eq_imp_iff, forall_true_left, true_and]
intro i j hij
have : i ≠ j := fun h => by rw [h] at hij; exact hij rfl
exact h'f this
have : s.card ≤ multiplicity E := card_le_multiplicity hs h's
rw [s_card, hN] at this
exact lt_irrefl _ ((Nat.lt_succ_self (multiplicity E)).trans_le this)
|
/-
Copyright (c) 2020 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov, Johannes Hölzl, Mario Carneiro, Patrick Massot
-/
import Mathlib.Data.Prod.PProd
import Mathlib.Data.Set.Countable
import Mathlib.Order.Filter.Prod
import Mathlib.Order.Filter.Ker
#align_import order.filter.bases from "leanprover-community/mathlib"@"996b0ff959da753a555053a480f36e5f264d4207"
/-!
# Filter bases
A filter basis `B : FilterBasis α` on a type `α` is a nonempty collection of sets of `α`
such that the intersection of two elements of this collection contains some element of
the collection. Compared to filters, filter bases do not require that any set containing
an element of `B` belongs to `B`.
A filter basis `B` can be used to construct `B.filter : Filter α` such that a set belongs
to `B.filter` if and only if it contains an element of `B`.
Given an indexing type `ι`, a predicate `p : ι → Prop`, and a map `s : ι → Set α`,
the proposition `h : Filter.IsBasis p s` makes sure the range of `s` bounded by `p`
(ie. `s '' setOf p`) defines a filter basis `h.filterBasis`.
If one already has a filter `l` on `α`, `Filter.HasBasis l p s` (where `p : ι → Prop`
and `s : ι → Set α` as above) means that a set belongs to `l` if and
only if it contains some `s i` with `p i`. It implies `h : Filter.IsBasis p s`, and
`l = h.filterBasis.filter`. The point of this definition is that checking statements
involving elements of `l` often reduces to checking them on the basis elements.
We define a function `HasBasis.index (h : Filter.HasBasis l p s) (t) (ht : t ∈ l)` that returns
some index `i` such that `p i` and `s i ⊆ t`. This function can be useful to avoid manual
destruction of `h.mem_iff.mpr ht` using `cases` or `let`.
This file also introduces more restricted classes of bases, involving monotonicity or
countability. In particular, for `l : Filter α`, `l.IsCountablyGenerated` means
there is a countable set of sets which generates `s`. This is reformulated in term of bases,
and consequences are derived.
## Main statements
* `Filter.HasBasis.mem_iff`, `HasBasis.mem_of_superset`, `HasBasis.mem_of_mem` : restate `t ∈ f` in
terms of a basis;
* `Filter.basis_sets` : all sets of a filter form a basis;
* `Filter.HasBasis.inf`, `Filter.HasBasis.inf_principal`, `Filter.HasBasis.prod`,
`Filter.HasBasis.prod_self`, `Filter.HasBasis.map`, `Filter.HasBasis.comap` : combinators to
construct filters of `l ⊓ l'`, `l ⊓ 𝓟 t`, `l ×ˢ l'`, `l ×ˢ l`, `l.map f`, `l.comap f`
respectively;
* `Filter.HasBasis.le_iff`, `Filter.HasBasis.ge_iff`, `Filter.HasBasis.le_basis_iff` : restate
`l ≤ l'` in terms of bases.
* `Filter.HasBasis.tendsto_right_iff`, `Filter.HasBasis.tendsto_left_iff`,
`Filter.HasBasis.tendsto_iff` : restate `Tendsto f l l'` in terms of bases.
* `isCountablyGenerated_iff_exists_antitone_basis` : proves a filter is countably generated if and
only if it admits a basis parametrized by a decreasing sequence of sets indexed by `ℕ`.
* `tendsto_iff_seq_tendsto` : an abstract version of "sequentially continuous implies continuous".
## Implementation notes
As with `Set.iUnion`/`biUnion`/`Set.sUnion`, there are three different approaches to filter bases:
* `Filter.HasBasis l s`, `s : Set (Set α)`;
* `Filter.HasBasis l s`, `s : ι → Set α`;
* `Filter.HasBasis l p s`, `p : ι → Prop`, `s : ι → Set α`.
We use the latter one because, e.g., `𝓝 x` in an `EMetricSpace` or in a `MetricSpace` has a basis
of this form. The other two can be emulated using `s = id` or `p = fun _ ↦ True`.
With this approach sometimes one needs to `simp` the statement provided by the `Filter.HasBasis`
machinery, e.g., `simp only [true_and]` or `simp only [forall_const]` can help with the case
`p = fun _ ↦ True`.
-/
set_option autoImplicit true
open Set Filter
open scoped Classical
open Filter
section sort
variable {α β γ : Type*} {ι ι' : Sort*}
/-- A filter basis `B` on a type `α` is a nonempty collection of sets of `α`
such that the intersection of two elements of this collection contains some element
of the collection. -/
structure FilterBasis (α : Type*) where
/-- Sets of a filter basis. -/
sets : Set (Set α)
/-- The set of filter basis sets is nonempty. -/
nonempty : sets.Nonempty
/-- The set of filter basis sets is directed downwards. -/
inter_sets {x y} : x ∈ sets → y ∈ sets → ∃ z ∈ sets, z ⊆ x ∩ y
#align filter_basis FilterBasis
instance FilterBasis.nonempty_sets (B : FilterBasis α) : Nonempty B.sets :=
B.nonempty.to_subtype
#align filter_basis.nonempty_sets FilterBasis.nonempty_sets
-- Porting note: this instance was reducible but it doesn't work the same way in Lean 4
/-- If `B` is a filter basis on `α`, and `U` a subset of `α` then we can write `U ∈ B` as
on paper. -/
instance {α : Type*} : Membership (Set α) (FilterBasis α) :=
⟨fun U B => U ∈ B.sets⟩
@[simp] theorem FilterBasis.mem_sets {s : Set α} {B : FilterBasis α} : s ∈ B.sets ↔ s ∈ B := Iff.rfl
-- For illustration purposes, the filter basis defining `(atTop : Filter ℕ)`
instance : Inhabited (FilterBasis ℕ) :=
⟨{ sets := range Ici
nonempty := ⟨Ici 0, mem_range_self 0⟩
inter_sets := by
rintro _ _ ⟨n, rfl⟩ ⟨m, rfl⟩
exact ⟨Ici (max n m), mem_range_self _, Ici_inter_Ici.symm.subset⟩ }⟩
/-- View a filter as a filter basis. -/
def Filter.asBasis (f : Filter α) : FilterBasis α :=
⟨f.sets, ⟨univ, univ_mem⟩, fun {x y} hx hy => ⟨x ∩ y, inter_mem hx hy, subset_rfl⟩⟩
#align filter.as_basis Filter.asBasis
-- Porting note: was `protected` in Lean 3 but `protected` didn't work; removed
/-- `is_basis p s` means the image of `s` bounded by `p` is a filter basis. -/
structure Filter.IsBasis (p : ι → Prop) (s : ι → Set α) : Prop where
/-- There exists at least one `i` that satisfies `p`. -/
nonempty : ∃ i, p i
/-- `s` is directed downwards on `i` such that `p i`. -/
inter : ∀ {i j}, p i → p j → ∃ k, p k ∧ s k ⊆ s i ∩ s j
#align filter.is_basis Filter.IsBasis
namespace Filter
namespace IsBasis
/-- Constructs a filter basis from an indexed family of sets satisfying `IsBasis`. -/
protected def filterBasis {p : ι → Prop} {s : ι → Set α} (h : IsBasis p s) : FilterBasis α where
sets := { t | ∃ i, p i ∧ s i = t }
nonempty :=
let ⟨i, hi⟩ := h.nonempty
⟨s i, ⟨i, hi, rfl⟩⟩
inter_sets := by
rintro _ _ ⟨i, hi, rfl⟩ ⟨j, hj, rfl⟩
rcases h.inter hi hj with ⟨k, hk, hk'⟩
exact ⟨_, ⟨k, hk, rfl⟩, hk'⟩
#align filter.is_basis.filter_basis Filter.IsBasis.filterBasis
variable {p : ι → Prop} {s : ι → Set α} (h : IsBasis p s)
theorem mem_filterBasis_iff {U : Set α} : U ∈ h.filterBasis ↔ ∃ i, p i ∧ s i = U :=
Iff.rfl
#align filter.is_basis.mem_filter_basis_iff Filter.IsBasis.mem_filterBasis_iff
end IsBasis
end Filter
namespace FilterBasis
/-- The filter associated to a filter basis. -/
protected def filter (B : FilterBasis α) : Filter α where
sets := { s | ∃ t ∈ B, t ⊆ s }
univ_sets := B.nonempty.imp fun s s_in => ⟨s_in, s.subset_univ⟩
sets_of_superset := fun ⟨s, s_in, h⟩ hxy => ⟨s, s_in, Set.Subset.trans h hxy⟩
inter_sets := fun ⟨_s, s_in, hs⟩ ⟨_t, t_in, ht⟩ =>
let ⟨u, u_in, u_sub⟩ := B.inter_sets s_in t_in
⟨u, u_in, u_sub.trans (inter_subset_inter hs ht)⟩
#align filter_basis.filter FilterBasis.filter
theorem mem_filter_iff (B : FilterBasis α) {U : Set α} : U ∈ B.filter ↔ ∃ s ∈ B, s ⊆ U :=
Iff.rfl
#align filter_basis.mem_filter_iff FilterBasis.mem_filter_iff
theorem mem_filter_of_mem (B : FilterBasis α) {U : Set α} : U ∈ B → U ∈ B.filter := fun U_in =>
⟨U, U_in, Subset.refl _⟩
#align filter_basis.mem_filter_of_mem FilterBasis.mem_filter_of_mem
theorem eq_iInf_principal (B : FilterBasis α) : B.filter = ⨅ s : B.sets, 𝓟 s := by
have : Directed (· ≥ ·) fun s : B.sets => 𝓟 (s : Set α) := by
rintro ⟨U, U_in⟩ ⟨V, V_in⟩
rcases B.inter_sets U_in V_in with ⟨W, W_in, W_sub⟩
use ⟨W, W_in⟩
simp only [ge_iff_le, le_principal_iff, mem_principal, Subtype.coe_mk]
exact subset_inter_iff.mp W_sub
ext U
simp [mem_filter_iff, mem_iInf_of_directed this]
#align filter_basis.eq_infi_principal FilterBasis.eq_iInf_principal
protected theorem generate (B : FilterBasis α) : generate B.sets = B.filter := by
apply le_antisymm
· intro U U_in
rcases B.mem_filter_iff.mp U_in with ⟨V, V_in, h⟩
exact GenerateSets.superset (GenerateSets.basic V_in) h
· rw [le_generate_iff]
apply mem_filter_of_mem
#align filter_basis.generate FilterBasis.generate
end FilterBasis
namespace Filter
namespace IsBasis
variable {p : ι → Prop} {s : ι → Set α}
/-- Constructs a filter from an indexed family of sets satisfying `IsBasis`. -/
protected def filter (h : IsBasis p s) : Filter α :=
h.filterBasis.filter
#align filter.is_basis.filter Filter.IsBasis.filter
protected theorem mem_filter_iff (h : IsBasis p s) {U : Set α} :
U ∈ h.filter ↔ ∃ i, p i ∧ s i ⊆ U := by
simp only [IsBasis.filter, FilterBasis.mem_filter_iff, mem_filterBasis_iff,
exists_exists_and_eq_and]
#align filter.is_basis.mem_filter_iff Filter.IsBasis.mem_filter_iff
theorem filter_eq_generate (h : IsBasis p s) : h.filter = generate { U | ∃ i, p i ∧ s i = U } := by
erw [h.filterBasis.generate]; rfl
#align filter.is_basis.filter_eq_generate Filter.IsBasis.filter_eq_generate
end IsBasis
-- Porting note: was `protected` in Lean 3 but `protected` didn't work; removed
/-- We say that a filter `l` has a basis `s : ι → Set α` bounded by `p : ι → Prop`,
if `t ∈ l` if and only if `t` includes `s i` for some `i` such that `p i`. -/
structure HasBasis (l : Filter α) (p : ι → Prop) (s : ι → Set α) : Prop where
/-- A set `t` belongs to a filter `l` iff it includes an element of the basis. -/
mem_iff' : ∀ t : Set α, t ∈ l ↔ ∃ i, p i ∧ s i ⊆ t
#align filter.has_basis Filter.HasBasis
section SameType
variable {l l' : Filter α} {p : ι → Prop} {s : ι → Set α} {t : Set α} {i : ι} {p' : ι' → Prop}
{s' : ι' → Set α} {i' : ι'}
theorem hasBasis_generate (s : Set (Set α)) :
(generate s).HasBasis (fun t => Set.Finite t ∧ t ⊆ s) fun t => ⋂₀ t :=
⟨fun U => by simp only [mem_generate_iff, exists_prop, and_assoc, and_left_comm]⟩
#align filter.has_basis_generate Filter.hasBasis_generate
/-- The smallest filter basis containing a given collection of sets. -/
def FilterBasis.ofSets (s : Set (Set α)) : FilterBasis α where
sets := sInter '' { t | Set.Finite t ∧ t ⊆ s }
nonempty := ⟨univ, ∅, ⟨⟨finite_empty, empty_subset s⟩, sInter_empty⟩⟩
inter_sets := by
rintro _ _ ⟨a, ⟨fina, suba⟩, rfl⟩ ⟨b, ⟨finb, subb⟩, rfl⟩
exact ⟨⋂₀ (a ∪ b), mem_image_of_mem _ ⟨fina.union finb, union_subset suba subb⟩,
(sInter_union _ _).subset⟩
#align filter.filter_basis.of_sets Filter.FilterBasis.ofSets
lemma FilterBasis.ofSets_sets (s : Set (Set α)) :
(FilterBasis.ofSets s).sets = sInter '' { t | Set.Finite t ∧ t ⊆ s } :=
rfl
-- Porting note: use `∃ i, p i ∧ _` instead of `∃ i (hi : p i), _`.
/-- Definition of `HasBasis` unfolded with implicit set argument. -/
theorem HasBasis.mem_iff (hl : l.HasBasis p s) : t ∈ l ↔ ∃ i, p i ∧ s i ⊆ t :=
hl.mem_iff' t
#align filter.has_basis.mem_iff Filter.HasBasis.mem_iffₓ
theorem HasBasis.eq_of_same_basis (hl : l.HasBasis p s) (hl' : l'.HasBasis p s) : l = l' := by
ext t
rw [hl.mem_iff, hl'.mem_iff]
#align filter.has_basis.eq_of_same_basis Filter.HasBasis.eq_of_same_basis
-- Porting note: use `∃ i, p i ∧ _` instead of `∃ i (hi : p i), _`.
theorem hasBasis_iff : l.HasBasis p s ↔ ∀ t, t ∈ l ↔ ∃ i, p i ∧ s i ⊆ t :=
⟨fun ⟨h⟩ => h, fun h => ⟨h⟩⟩
#align filter.has_basis_iff Filter.hasBasis_iffₓ
theorem HasBasis.ex_mem (h : l.HasBasis p s) : ∃ i, p i :=
(h.mem_iff.mp univ_mem).imp fun _ => And.left
#align filter.has_basis.ex_mem Filter.HasBasis.ex_mem
protected theorem HasBasis.nonempty (h : l.HasBasis p s) : Nonempty ι :=
nonempty_of_exists h.ex_mem
#align filter.has_basis.nonempty Filter.HasBasis.nonempty
protected theorem IsBasis.hasBasis (h : IsBasis p s) : HasBasis h.filter p s :=
⟨fun t => by simp only [h.mem_filter_iff, exists_prop]⟩
#align filter.is_basis.has_basis Filter.IsBasis.hasBasis
protected theorem HasBasis.mem_of_superset (hl : l.HasBasis p s) (hi : p i) (ht : s i ⊆ t) :
t ∈ l :=
hl.mem_iff.2 ⟨i, hi, ht⟩
#align filter.has_basis.mem_of_superset Filter.HasBasis.mem_of_superset
theorem HasBasis.mem_of_mem (hl : l.HasBasis p s) (hi : p i) : s i ∈ l :=
hl.mem_of_superset hi Subset.rfl
#align filter.has_basis.mem_of_mem Filter.HasBasis.mem_of_mem
/-- Index of a basis set such that `s i ⊆ t` as an element of `Subtype p`. -/
noncomputable def HasBasis.index (h : l.HasBasis p s) (t : Set α) (ht : t ∈ l) : { i : ι // p i } :=
⟨(h.mem_iff.1 ht).choose, (h.mem_iff.1 ht).choose_spec.1⟩
#align filter.has_basis.index Filter.HasBasis.index
theorem HasBasis.property_index (h : l.HasBasis p s) (ht : t ∈ l) : p (h.index t ht) :=
(h.index t ht).2
#align filter.has_basis.property_index Filter.HasBasis.property_index
theorem HasBasis.set_index_mem (h : l.HasBasis p s) (ht : t ∈ l) : s (h.index t ht) ∈ l :=
h.mem_of_mem <| h.property_index _
#align filter.has_basis.set_index_mem Filter.HasBasis.set_index_mem
theorem HasBasis.set_index_subset (h : l.HasBasis p s) (ht : t ∈ l) : s (h.index t ht) ⊆ t :=
(h.mem_iff.1 ht).choose_spec.2
#align filter.has_basis.set_index_subset Filter.HasBasis.set_index_subset
theorem HasBasis.isBasis (h : l.HasBasis p s) : IsBasis p s where
nonempty := h.ex_mem
inter hi hj := by
simpa only [h.mem_iff] using inter_mem (h.mem_of_mem hi) (h.mem_of_mem hj)
#align filter.has_basis.is_basis Filter.HasBasis.isBasis
theorem HasBasis.filter_eq (h : l.HasBasis p s) : h.isBasis.filter = l := by
ext U
simp [h.mem_iff, IsBasis.mem_filter_iff]
#align filter.has_basis.filter_eq Filter.HasBasis.filter_eq
theorem HasBasis.eq_generate (h : l.HasBasis p s) : l = generate { U | ∃ i, p i ∧ s i = U } := by
rw [← h.isBasis.filter_eq_generate, h.filter_eq]
#align filter.has_basis.eq_generate Filter.HasBasis.eq_generate
theorem generate_eq_generate_inter (s : Set (Set α)) :
generate s = generate (sInter '' { t | Set.Finite t ∧ t ⊆ s }) := by
rw [← FilterBasis.ofSets_sets, FilterBasis.generate, ← (hasBasis_generate s).filter_eq]; rfl
#align filter.generate_eq_generate_inter Filter.generate_eq_generate_inter
theorem ofSets_filter_eq_generate (s : Set (Set α)) :
(FilterBasis.ofSets s).filter = generate s := by
rw [← (FilterBasis.ofSets s).generate, FilterBasis.ofSets_sets, ← generate_eq_generate_inter]
#align filter.of_sets_filter_eq_generate Filter.ofSets_filter_eq_generate
protected theorem _root_.FilterBasis.hasBasis (B : FilterBasis α) :
HasBasis B.filter (fun s : Set α => s ∈ B) id :=
⟨fun _ => B.mem_filter_iff⟩
#align filter_basis.has_basis FilterBasis.hasBasis
theorem HasBasis.to_hasBasis' (hl : l.HasBasis p s) (h : ∀ i, p i → ∃ i', p' i' ∧ s' i' ⊆ s i)
(h' : ∀ i', p' i' → s' i' ∈ l) : l.HasBasis p' s' := by
refine ⟨fun t => ⟨fun ht => ?_, fun ⟨i', hi', ht⟩ => mem_of_superset (h' i' hi') ht⟩⟩
rcases hl.mem_iff.1 ht with ⟨i, hi, ht⟩
rcases h i hi with ⟨i', hi', hs's⟩
exact ⟨i', hi', hs's.trans ht⟩
#align filter.has_basis.to_has_basis' Filter.HasBasis.to_hasBasis'
theorem HasBasis.to_hasBasis (hl : l.HasBasis p s) (h : ∀ i, p i → ∃ i', p' i' ∧ s' i' ⊆ s i)
(h' : ∀ i', p' i' → ∃ i, p i ∧ s i ⊆ s' i') : l.HasBasis p' s' :=
hl.to_hasBasis' h fun i' hi' =>
let ⟨i, hi, hss'⟩ := h' i' hi'
hl.mem_iff.2 ⟨i, hi, hss'⟩
#align filter.has_basis.to_has_basis Filter.HasBasis.to_hasBasis
protected lemma HasBasis.congr (hl : l.HasBasis p s) {p' s'} (hp : ∀ i, p i ↔ p' i)
(hs : ∀ i, p i → s i = s' i) : l.HasBasis p' s' :=
⟨fun t ↦ by simp only [hl.mem_iff, ← hp]; exact exists_congr fun i ↦
and_congr_right fun hi ↦ hs i hi ▸ Iff.rfl⟩
theorem HasBasis.to_subset (hl : l.HasBasis p s) {t : ι → Set α} (h : ∀ i, p i → t i ⊆ s i)
(ht : ∀ i, p i → t i ∈ l) : l.HasBasis p t :=
hl.to_hasBasis' (fun i hi => ⟨i, hi, h i hi⟩) ht
#align filter.has_basis.to_subset Filter.HasBasis.to_subset
theorem HasBasis.eventually_iff (hl : l.HasBasis p s) {q : α → Prop} :
(∀ᶠ x in l, q x) ↔ ∃ i, p i ∧ ∀ ⦃x⦄, x ∈ s i → q x := by simpa using hl.mem_iff
#align filter.has_basis.eventually_iff Filter.HasBasis.eventually_iff
theorem HasBasis.frequently_iff (hl : l.HasBasis p s) {q : α → Prop} :
(∃ᶠ x in l, q x) ↔ ∀ i, p i → ∃ x ∈ s i, q x := by
simp only [Filter.Frequently, hl.eventually_iff]; push_neg; rfl
#align filter.has_basis.frequently_iff Filter.HasBasis.frequently_iff
-- Porting note: use `∃ i, p i ∧ _` instead of `∃ i (hi : p i), _`.
theorem HasBasis.exists_iff (hl : l.HasBasis p s) {P : Set α → Prop}
(mono : ∀ ⦃s t⦄, s ⊆ t → P t → P s) : (∃ s ∈ l, P s) ↔ ∃ i, p i ∧ P (s i) :=
⟨fun ⟨_s, hs, hP⟩ =>
let ⟨i, hi, his⟩ := hl.mem_iff.1 hs
⟨i, hi, mono his hP⟩,
fun ⟨i, hi, hP⟩ => ⟨s i, hl.mem_of_mem hi, hP⟩⟩
#align filter.has_basis.exists_iff Filter.HasBasis.exists_iffₓ
theorem HasBasis.forall_iff (hl : l.HasBasis p s) {P : Set α → Prop}
(mono : ∀ ⦃s t⦄, s ⊆ t → P s → P t) : (∀ s ∈ l, P s) ↔ ∀ i, p i → P (s i) :=
⟨fun H i hi => H (s i) <| hl.mem_of_mem hi, fun H _s hs =>
let ⟨i, hi, his⟩ := hl.mem_iff.1 hs
mono his (H i hi)⟩
#align filter.has_basis.forall_iff Filter.HasBasis.forall_iff
protected theorem HasBasis.neBot_iff (hl : l.HasBasis p s) :
NeBot l ↔ ∀ {i}, p i → (s i).Nonempty :=
forall_mem_nonempty_iff_neBot.symm.trans <| hl.forall_iff fun _ _ => Nonempty.mono
#align filter.has_basis.ne_bot_iff Filter.HasBasis.neBot_iff
theorem HasBasis.eq_bot_iff (hl : l.HasBasis p s) : l = ⊥ ↔ ∃ i, p i ∧ s i = ∅ :=
not_iff_not.1 <| neBot_iff.symm.trans <|
hl.neBot_iff.trans <| by simp only [not_exists, not_and, nonempty_iff_ne_empty]
#align filter.has_basis.eq_bot_iff Filter.HasBasis.eq_bot_iff
theorem generate_neBot_iff {s : Set (Set α)} :
NeBot (generate s) ↔ ∀ t, t ⊆ s → t.Finite → (⋂₀ t).Nonempty :=
(hasBasis_generate s).neBot_iff.trans <| by simp only [← and_imp, and_comm]
#align filter.generate_ne_bot_iff Filter.generate_neBot_iff
theorem basis_sets (l : Filter α) : l.HasBasis (fun s : Set α => s ∈ l) id :=
⟨fun _ => exists_mem_subset_iff.symm⟩
#align filter.basis_sets Filter.basis_sets
theorem asBasis_filter (f : Filter α) : f.asBasis.filter = f :=
Filter.ext fun _ => exists_mem_subset_iff
#align filter.as_basis_filter Filter.asBasis_filter
theorem hasBasis_self {l : Filter α} {P : Set α → Prop} :
HasBasis l (fun s => s ∈ l ∧ P s) id ↔ ∀ t ∈ l, ∃ r ∈ l, P r ∧ r ⊆ t := by
simp only [hasBasis_iff, id, and_assoc]
exact forall_congr' fun s =>
⟨fun h => h.1, fun h => ⟨h, fun ⟨t, hl, _, hts⟩ => mem_of_superset hl hts⟩⟩
#align filter.has_basis_self Filter.hasBasis_self
theorem HasBasis.comp_surjective (h : l.HasBasis p s) {g : ι' → ι} (hg : Function.Surjective g) :
l.HasBasis (p ∘ g) (s ∘ g) :=
⟨fun _ => h.mem_iff.trans hg.exists⟩
#align filter.has_basis.comp_surjective Filter.HasBasis.comp_surjective
theorem HasBasis.comp_equiv (h : l.HasBasis p s) (e : ι' ≃ ι) : l.HasBasis (p ∘ e) (s ∘ e) :=
h.comp_surjective e.surjective
#align filter.has_basis.comp_equiv Filter.HasBasis.comp_equiv
theorem HasBasis.to_image_id' (h : l.HasBasis p s) : l.HasBasis (fun t ↦ ∃ i, p i ∧ s i = t) id :=
⟨fun _ ↦ by simp [h.mem_iff]⟩
theorem HasBasis.to_image_id {ι : Type*} {p : ι → Prop} {s : ι → Set α} (h : l.HasBasis p s) :
l.HasBasis (· ∈ s '' {i | p i}) id :=
h.to_image_id'
/-- If `{s i | p i}` is a basis of a filter `l` and each `s i` includes `s j` such that
`p j ∧ q j`, then `{s j | p j ∧ q j}` is a basis of `l`. -/
theorem HasBasis.restrict (h : l.HasBasis p s) {q : ι → Prop}
(hq : ∀ i, p i → ∃ j, p j ∧ q j ∧ s j ⊆ s i) : l.HasBasis (fun i => p i ∧ q i) s := by
refine ⟨fun t => ⟨fun ht => ?_, fun ⟨i, hpi, hti⟩ => h.mem_iff.2 ⟨i, hpi.1, hti⟩⟩⟩
rcases h.mem_iff.1 ht with ⟨i, hpi, hti⟩
rcases hq i hpi with ⟨j, hpj, hqj, hji⟩
exact ⟨j, ⟨hpj, hqj⟩, hji.trans hti⟩
#align filter.has_basis.restrict Filter.HasBasis.restrict
/-- If `{s i | p i}` is a basis of a filter `l` and `V ∈ l`, then `{s i | p i ∧ s i ⊆ V}`
is a basis of `l`. -/
theorem HasBasis.restrict_subset (h : l.HasBasis p s) {V : Set α} (hV : V ∈ l) :
l.HasBasis (fun i => p i ∧ s i ⊆ V) s :=
h.restrict fun _i hi => (h.mem_iff.1 (inter_mem hV (h.mem_of_mem hi))).imp fun _j hj =>
⟨hj.1, subset_inter_iff.1 hj.2⟩
#align filter.has_basis.restrict_subset Filter.HasBasis.restrict_subset
theorem HasBasis.hasBasis_self_subset {p : Set α → Prop} (h : l.HasBasis (fun s => s ∈ l ∧ p s) id)
{V : Set α} (hV : V ∈ l) : l.HasBasis (fun s => s ∈ l ∧ p s ∧ s ⊆ V) id := by
simpa only [and_assoc] using h.restrict_subset hV
#align filter.has_basis.has_basis_self_subset Filter.HasBasis.hasBasis_self_subset
theorem HasBasis.ge_iff (hl' : l'.HasBasis p' s') : l ≤ l' ↔ ∀ i', p' i' → s' i' ∈ l :=
⟨fun h _i' hi' => h <| hl'.mem_of_mem hi', fun h _s hs =>
let ⟨_i', hi', hs⟩ := hl'.mem_iff.1 hs
mem_of_superset (h _ hi') hs⟩
#align filter.has_basis.ge_iff Filter.HasBasis.ge_iff
-- Porting note: use `∃ i, p i ∧ _` instead of `∃ i (hi : p i), _`.
theorem HasBasis.le_iff (hl : l.HasBasis p s) : l ≤ l' ↔ ∀ t ∈ l', ∃ i, p i ∧ s i ⊆ t := by
simp only [le_def, hl.mem_iff]
#align filter.has_basis.le_iff Filter.HasBasis.le_iffₓ
-- Porting note: use `∃ i, p i ∧ _` instead of `∃ i (hi : p i), _`.
theorem HasBasis.le_basis_iff (hl : l.HasBasis p s) (hl' : l'.HasBasis p' s') :
l ≤ l' ↔ ∀ i', p' i' → ∃ i, p i ∧ s i ⊆ s' i' := by
simp only [hl'.ge_iff, hl.mem_iff]
#align filter.has_basis.le_basis_iff Filter.HasBasis.le_basis_iffₓ
-- Porting note: use `∃ i, p i ∧ _` instead of `∃ i (hi : p i), _`.
theorem HasBasis.ext (hl : l.HasBasis p s) (hl' : l'.HasBasis p' s')
(h : ∀ i, p i → ∃ i', p' i' ∧ s' i' ⊆ s i) (h' : ∀ i', p' i' → ∃ i, p i ∧ s i ⊆ s' i') :
l = l' := by
apply le_antisymm
· rw [hl.le_basis_iff hl']
simpa using h'
· rw [hl'.le_basis_iff hl]
simpa using h
#align filter.has_basis.ext Filter.HasBasis.extₓ
theorem HasBasis.inf' (hl : l.HasBasis p s) (hl' : l'.HasBasis p' s') :
(l ⊓ l').HasBasis (fun i : PProd ι ι' => p i.1 ∧ p' i.2) fun i => s i.1 ∩ s' i.2 :=
⟨by
intro t
constructor
· simp only [mem_inf_iff, hl.mem_iff, hl'.mem_iff]
rintro ⟨t, ⟨i, hi, ht⟩, t', ⟨i', hi', ht'⟩, rfl⟩
exact ⟨⟨i, i'⟩, ⟨hi, hi'⟩, inter_subset_inter ht ht'⟩
· rintro ⟨⟨i, i'⟩, ⟨hi, hi'⟩, H⟩
exact mem_inf_of_inter (hl.mem_of_mem hi) (hl'.mem_of_mem hi') H⟩
#align filter.has_basis.inf' Filter.HasBasis.inf'
theorem HasBasis.inf {ι ι' : Type*} {p : ι → Prop} {s : ι → Set α} {p' : ι' → Prop}
{s' : ι' → Set α} (hl : l.HasBasis p s) (hl' : l'.HasBasis p' s') :
(l ⊓ l').HasBasis (fun i : ι × ι' => p i.1 ∧ p' i.2) fun i => s i.1 ∩ s' i.2 :=
(hl.inf' hl').comp_equiv Equiv.pprodEquivProd.symm
#align filter.has_basis.inf Filter.HasBasis.inf
theorem hasBasis_iInf' {ι : Type*} {ι' : ι → Type*} {l : ι → Filter α} {p : ∀ i, ι' i → Prop}
{s : ∀ i, ι' i → Set α} (hl : ∀ i, (l i).HasBasis (p i) (s i)) :
(⨅ i, l i).HasBasis (fun If : Set ι × ∀ i, ι' i => If.1.Finite ∧ ∀ i ∈ If.1, p i (If.2 i))
fun If : Set ι × ∀ i, ι' i => ⋂ i ∈ If.1, s i (If.2 i) :=
⟨by
intro t
constructor
· simp only [mem_iInf', (hl _).mem_iff]
rintro ⟨I, hI, V, hV, -, rfl, -⟩
choose u hu using hV
exact ⟨⟨I, u⟩, ⟨hI, fun i _ => (hu i).1⟩, iInter₂_mono fun i _ => (hu i).2⟩
· rintro ⟨⟨I, f⟩, ⟨hI₁, hI₂⟩, hsub⟩
refine mem_of_superset ?_ hsub
exact (biInter_mem hI₁).mpr fun i hi => mem_iInf_of_mem i <| (hl i).mem_of_mem <| hI₂ _ hi⟩
#align filter.has_basis_infi' Filter.hasBasis_iInf'
theorem hasBasis_iInf {ι : Type*} {ι' : ι → Type*} {l : ι → Filter α} {p : ∀ i, ι' i → Prop}
{s : ∀ i, ι' i → Set α} (hl : ∀ i, (l i).HasBasis (p i) (s i)) :
(⨅ i, l i).HasBasis
(fun If : Σ I : Set ι, ∀ i : I, ι' i => If.1.Finite ∧ ∀ i : If.1, p i (If.2 i)) fun If =>
⋂ i : If.1, s i (If.2 i) := by
refine ⟨fun t => ⟨fun ht => ?_, ?_⟩⟩
· rcases (hasBasis_iInf' hl).mem_iff.mp ht with ⟨⟨I, f⟩, ⟨hI, hf⟩, hsub⟩
exact ⟨⟨I, fun i => f i⟩, ⟨hI, Subtype.forall.mpr hf⟩, trans (iInter_subtype _ _) hsub⟩
· rintro ⟨⟨I, f⟩, ⟨hI, hf⟩, hsub⟩
refine mem_of_superset ?_ hsub
cases hI.nonempty_fintype
exact iInter_mem.2 fun i => mem_iInf_of_mem ↑i <| (hl i).mem_of_mem <| hf _
#align filter.has_basis_infi Filter.hasBasis_iInf
theorem hasBasis_iInf_of_directed' {ι : Type*} {ι' : ι → Sort _} [Nonempty ι] {l : ι → Filter α}
(s : ∀ i, ι' i → Set α) (p : ∀ i, ι' i → Prop) (hl : ∀ i, (l i).HasBasis (p i) (s i))
(h : Directed (· ≥ ·) l) :
(⨅ i, l i).HasBasis (fun ii' : Σi, ι' i => p ii'.1 ii'.2) fun ii' => s ii'.1 ii'.2 := by
refine ⟨fun t => ?_⟩
rw [mem_iInf_of_directed h, Sigma.exists]
exact exists_congr fun i => (hl i).mem_iff
#align filter.has_basis_infi_of_directed' Filter.hasBasis_iInf_of_directed'
theorem hasBasis_iInf_of_directed {ι : Type*} {ι' : Sort _} [Nonempty ι] {l : ι → Filter α}
(s : ι → ι' → Set α) (p : ι → ι' → Prop) (hl : ∀ i, (l i).HasBasis (p i) (s i))
(h : Directed (· ≥ ·) l) :
(⨅ i, l i).HasBasis (fun ii' : ι × ι' => p ii'.1 ii'.2) fun ii' => s ii'.1 ii'.2 := by
refine ⟨fun t => ?_⟩
rw [mem_iInf_of_directed h, Prod.exists]
exact exists_congr fun i => (hl i).mem_iff
#align filter.has_basis_infi_of_directed Filter.hasBasis_iInf_of_directed
theorem hasBasis_biInf_of_directed' {ι : Type*} {ι' : ι → Sort _} {dom : Set ι}
(hdom : dom.Nonempty) {l : ι → Filter α} (s : ∀ i, ι' i → Set α) (p : ∀ i, ι' i → Prop)
(hl : ∀ i ∈ dom, (l i).HasBasis (p i) (s i)) (h : DirectedOn (l ⁻¹'o GE.ge) dom) :
(⨅ i ∈ dom, l i).HasBasis (fun ii' : Σi, ι' i => ii'.1 ∈ dom ∧ p ii'.1 ii'.2) fun ii' =>
s ii'.1 ii'.2 := by
refine ⟨fun t => ?_⟩
rw [mem_biInf_of_directed h hdom, Sigma.exists]
refine exists_congr fun i => ⟨?_, ?_⟩
· rintro ⟨hi, hti⟩
rcases (hl i hi).mem_iff.mp hti with ⟨b, hb, hbt⟩
exact ⟨b, ⟨hi, hb⟩, hbt⟩
· rintro ⟨b, ⟨hi, hb⟩, hibt⟩
exact ⟨hi, (hl i hi).mem_iff.mpr ⟨b, hb, hibt⟩⟩
#align filter.has_basis_binfi_of_directed' Filter.hasBasis_biInf_of_directed'
theorem hasBasis_biInf_of_directed {ι : Type*} {ι' : Sort _} {dom : Set ι} (hdom : dom.Nonempty)
{l : ι → Filter α} (s : ι → ι' → Set α) (p : ι → ι' → Prop)
(hl : ∀ i ∈ dom, (l i).HasBasis (p i) (s i)) (h : DirectedOn (l ⁻¹'o GE.ge) dom) :
(⨅ i ∈ dom, l i).HasBasis (fun ii' : ι × ι' => ii'.1 ∈ dom ∧ p ii'.1 ii'.2) fun ii' =>
s ii'.1 ii'.2 := by
refine ⟨fun t => ?_⟩
rw [mem_biInf_of_directed h hdom, Prod.exists]
refine exists_congr fun i => ⟨?_, ?_⟩
· rintro ⟨hi, hti⟩
rcases (hl i hi).mem_iff.mp hti with ⟨b, hb, hbt⟩
exact ⟨b, ⟨hi, hb⟩, hbt⟩
· rintro ⟨b, ⟨hi, hb⟩, hibt⟩
exact ⟨hi, (hl i hi).mem_iff.mpr ⟨b, hb, hibt⟩⟩
#align filter.has_basis_binfi_of_directed Filter.hasBasis_biInf_of_directed
theorem hasBasis_principal (t : Set α) : (𝓟 t).HasBasis (fun _ : Unit => True) fun _ => t :=
⟨fun U => by simp⟩
#align filter.has_basis_principal Filter.hasBasis_principal
theorem hasBasis_pure (x : α) :
(pure x : Filter α).HasBasis (fun _ : Unit => True) fun _ => {x} := by
simp only [← principal_singleton, hasBasis_principal]
#align filter.has_basis_pure Filter.hasBasis_pure
theorem HasBasis.sup' (hl : l.HasBasis p s) (hl' : l'.HasBasis p' s') :
(l ⊔ l').HasBasis (fun i : PProd ι ι' => p i.1 ∧ p' i.2) fun i => s i.1 ∪ s' i.2 :=
⟨by
intro t
simp_rw [mem_sup, hl.mem_iff, hl'.mem_iff, PProd.exists, union_subset_iff,
← exists_and_right, ← exists_and_left]
simp only [and_assoc, and_left_comm]⟩
#align filter.has_basis.sup' Filter.HasBasis.sup'
theorem HasBasis.sup {ι ι' : Type*} {p : ι → Prop} {s : ι → Set α} {p' : ι' → Prop}
{s' : ι' → Set α} (hl : l.HasBasis p s) (hl' : l'.HasBasis p' s') :
(l ⊔ l').HasBasis (fun i : ι × ι' => p i.1 ∧ p' i.2) fun i => s i.1 ∪ s' i.2 :=
(hl.sup' hl').comp_equiv Equiv.pprodEquivProd.symm
#align filter.has_basis.sup Filter.HasBasis.sup
theorem hasBasis_iSup {ι : Sort*} {ι' : ι → Type*} {l : ι → Filter α} {p : ∀ i, ι' i → Prop}
{s : ∀ i, ι' i → Set α} (hl : ∀ i, (l i).HasBasis (p i) (s i)) :
(⨆ i, l i).HasBasis (fun f : ∀ i, ι' i => ∀ i, p i (f i)) fun f : ∀ i, ι' i => ⋃ i, s i (f i) :=
hasBasis_iff.mpr fun t => by
simp only [hasBasis_iff, (hl _).mem_iff, Classical.skolem, forall_and, iUnion_subset_iff,
mem_iSup]
#align filter.has_basis_supr Filter.hasBasis_iSup
theorem HasBasis.sup_principal (hl : l.HasBasis p s) (t : Set α) :
(l ⊔ 𝓟 t).HasBasis p fun i => s i ∪ t :=
⟨fun u => by
simp only [(hl.sup' (hasBasis_principal t)).mem_iff, PProd.exists, exists_prop, and_true_iff,
Unique.exists_iff]⟩
#align filter.has_basis.sup_principal Filter.HasBasis.sup_principal
theorem HasBasis.sup_pure (hl : l.HasBasis p s) (x : α) :
(l ⊔ pure x).HasBasis p fun i => s i ∪ {x} := by
simp only [← principal_singleton, hl.sup_principal]
#align filter.has_basis.sup_pure Filter.HasBasis.sup_pure
theorem HasBasis.inf_principal (hl : l.HasBasis p s) (s' : Set α) :
(l ⊓ 𝓟 s').HasBasis p fun i => s i ∩ s' :=
⟨fun t => by
simp only [mem_inf_principal, hl.mem_iff, subset_def, mem_setOf_eq, mem_inter_iff, and_imp]⟩
#align filter.has_basis.inf_principal Filter.HasBasis.inf_principal
theorem HasBasis.principal_inf (hl : l.HasBasis p s) (s' : Set α) :
(𝓟 s' ⊓ l).HasBasis p fun i => s' ∩ s i := by
simpa only [inf_comm, inter_comm] using hl.inf_principal s'
#align filter.has_basis.principal_inf Filter.HasBasis.principal_inf
theorem HasBasis.inf_basis_neBot_iff (hl : l.HasBasis p s) (hl' : l'.HasBasis p' s') :
NeBot (l ⊓ l') ↔ ∀ ⦃i⦄, p i → ∀ ⦃i'⦄, p' i' → (s i ∩ s' i').Nonempty :=
(hl.inf' hl').neBot_iff.trans <| by simp [@forall_swap _ ι']
#align filter.has_basis.inf_basis_ne_bot_iff Filter.HasBasis.inf_basis_neBot_iff
theorem HasBasis.inf_neBot_iff (hl : l.HasBasis p s) :
NeBot (l ⊓ l') ↔ ∀ ⦃i⦄, p i → ∀ ⦃s'⦄, s' ∈ l' → (s i ∩ s').Nonempty :=
hl.inf_basis_neBot_iff l'.basis_sets
#align filter.has_basis.inf_ne_bot_iff Filter.HasBasis.inf_neBot_iff
theorem HasBasis.inf_principal_neBot_iff (hl : l.HasBasis p s) {t : Set α} :
NeBot (l ⊓ 𝓟 t) ↔ ∀ ⦃i⦄, p i → (s i ∩ t).Nonempty :=
(hl.inf_principal t).neBot_iff
#align filter.has_basis.inf_principal_ne_bot_iff Filter.HasBasis.inf_principal_neBot_iff
-- Porting note: use `∃ i, p i ∧ _` instead of `∃ i (hi : p i), _`.
theorem HasBasis.disjoint_iff (hl : l.HasBasis p s) (hl' : l'.HasBasis p' s') :
Disjoint l l' ↔ ∃ i, p i ∧ ∃ i', p' i' ∧ Disjoint (s i) (s' i') :=
not_iff_not.mp <| by simp only [_root_.disjoint_iff, ← Ne.eq_def, ← neBot_iff, inf_eq_inter,
hl.inf_basis_neBot_iff hl', not_exists, not_and, bot_eq_empty, ← nonempty_iff_ne_empty]
#align filter.has_basis.disjoint_iff Filter.HasBasis.disjoint_iffₓ
-- Porting note: use `∃ i, p i ∧ _` instead of `∃ i (hi : p i), _`.
theorem _root_.Disjoint.exists_mem_filter_basis (h : Disjoint l l') (hl : l.HasBasis p s)
(hl' : l'.HasBasis p' s') : ∃ i, p i ∧ ∃ i', p' i' ∧ Disjoint (s i) (s' i') :=
(hl.disjoint_iff hl').1 h
#align disjoint.exists_mem_filter_basis Disjoint.exists_mem_filter_basisₓ
theorem _root_.Pairwise.exists_mem_filter_basis_of_disjoint {I} [Finite I] {l : I → Filter α}
{ι : I → Sort*} {p : ∀ i, ι i → Prop} {s : ∀ i, ι i → Set α} (hd : Pairwise (Disjoint on l))
(h : ∀ i, (l i).HasBasis (p i) (s i)) :
∃ ind : ∀ i, ι i, (∀ i, p i (ind i)) ∧ Pairwise (Disjoint on fun i => s i (ind i)) := by
rcases hd.exists_mem_filter_of_disjoint with ⟨t, htl, hd⟩
choose ind hp ht using fun i => (h i).mem_iff.1 (htl i)
exact ⟨ind, hp, hd.mono fun i j hij => hij.mono (ht _) (ht _)⟩
#align pairwise.exists_mem_filter_basis_of_disjoint Pairwise.exists_mem_filter_basis_of_disjoint
theorem _root_.Set.PairwiseDisjoint.exists_mem_filter_basis {I : Type*} {l : I → Filter α}
{ι : I → Sort*} {p : ∀ i, ι i → Prop} {s : ∀ i, ι i → Set α} {S : Set I}
(hd : S.PairwiseDisjoint l) (hS : S.Finite) (h : ∀ i, (l i).HasBasis (p i) (s i)) :
∃ ind : ∀ i, ι i, (∀ i, p i (ind i)) ∧ S.PairwiseDisjoint fun i => s i (ind i) := by
rcases hd.exists_mem_filter hS with ⟨t, htl, hd⟩
choose ind hp ht using fun i => (h i).mem_iff.1 (htl i)
exact ⟨ind, hp, hd.mono ht⟩
#align set.pairwise_disjoint.exists_mem_filter_basis Set.PairwiseDisjoint.exists_mem_filter_basis
theorem inf_neBot_iff :
NeBot (l ⊓ l') ↔ ∀ ⦃s : Set α⦄, s ∈ l → ∀ ⦃s'⦄, s' ∈ l' → (s ∩ s').Nonempty :=
l.basis_sets.inf_neBot_iff
#align filter.inf_ne_bot_iff Filter.inf_neBot_iff
theorem inf_principal_neBot_iff {s : Set α} : NeBot (l ⊓ 𝓟 s) ↔ ∀ U ∈ l, (U ∩ s).Nonempty :=
l.basis_sets.inf_principal_neBot_iff
#align filter.inf_principal_ne_bot_iff Filter.inf_principal_neBot_iff
theorem mem_iff_inf_principal_compl {f : Filter α} {s : Set α} : s ∈ f ↔ f ⊓ 𝓟 sᶜ = ⊥ := by
refine not_iff_not.1 ((inf_principal_neBot_iff.trans ?_).symm.trans neBot_iff)
exact
⟨fun h hs => by simpa [Set.not_nonempty_empty] using h s hs, fun hs t ht =>
inter_compl_nonempty_iff.2 fun hts => hs <| mem_of_superset ht hts⟩
#align filter.mem_iff_inf_principal_compl Filter.mem_iff_inf_principal_compl
theorem not_mem_iff_inf_principal_compl {f : Filter α} {s : Set α} : s ∉ f ↔ NeBot (f ⊓ 𝓟 sᶜ) :=
(not_congr mem_iff_inf_principal_compl).trans neBot_iff.symm
#align filter.not_mem_iff_inf_principal_compl Filter.not_mem_iff_inf_principal_compl
@[simp]
theorem disjoint_principal_right {f : Filter α} {s : Set α} : Disjoint f (𝓟 s) ↔ sᶜ ∈ f := by
rw [mem_iff_inf_principal_compl, compl_compl, disjoint_iff]
#align filter.disjoint_principal_right Filter.disjoint_principal_right
@[simp]
theorem disjoint_principal_left {f : Filter α} {s : Set α} : Disjoint (𝓟 s) f ↔ sᶜ ∈ f := by
rw [disjoint_comm, disjoint_principal_right]
#align filter.disjoint_principal_left Filter.disjoint_principal_left
@[simp 1100] -- Porting note: higher priority for linter
theorem disjoint_principal_principal {s t : Set α} : Disjoint (𝓟 s) (𝓟 t) ↔ Disjoint s t := by
rw [← subset_compl_iff_disjoint_left, disjoint_principal_left, mem_principal]
#align filter.disjoint_principal_principal Filter.disjoint_principal_principal
alias ⟨_, _root_.Disjoint.filter_principal⟩ := disjoint_principal_principal
#align disjoint.filter_principal Disjoint.filter_principal
@[simp]
theorem disjoint_pure_pure {x y : α} : Disjoint (pure x : Filter α) (pure y) ↔ x ≠ y := by
simp only [← principal_singleton, disjoint_principal_principal, disjoint_singleton]
#align filter.disjoint_pure_pure Filter.disjoint_pure_pure
@[simp]
theorem compl_diagonal_mem_prod {l₁ l₂ : Filter α} : (diagonal α)ᶜ ∈ l₁ ×ˢ l₂ ↔ Disjoint l₁ l₂ := by
simp only [mem_prod_iff, Filter.disjoint_iff, prod_subset_compl_diagonal_iff_disjoint]
#align filter.compl_diagonal_mem_prod Filter.compl_diagonal_mem_prod
-- Porting note: use `∃ i, p i ∧ _` instead of `∃ i (hi : p i), _`.
theorem HasBasis.disjoint_iff_left (h : l.HasBasis p s) :
Disjoint l l' ↔ ∃ i, p i ∧ (s i)ᶜ ∈ l' := by
simp only [h.disjoint_iff l'.basis_sets, id, ← disjoint_principal_left,
(hasBasis_principal _).disjoint_iff l'.basis_sets, true_and, Unique.exists_iff]
#align filter.has_basis.disjoint_iff_left Filter.HasBasis.disjoint_iff_leftₓ
-- Porting note: use `∃ i, p i ∧ _` instead of `∃ i (hi : p i), _`.
theorem HasBasis.disjoint_iff_right (h : l.HasBasis p s) :
Disjoint l' l ↔ ∃ i, p i ∧ (s i)ᶜ ∈ l' :=
disjoint_comm.trans h.disjoint_iff_left
#align filter.has_basis.disjoint_iff_right Filter.HasBasis.disjoint_iff_rightₓ
theorem le_iff_forall_inf_principal_compl {f g : Filter α} : f ≤ g ↔ ∀ V ∈ g, f ⊓ 𝓟 Vᶜ = ⊥ :=
forall₂_congr fun _ _ => mem_iff_inf_principal_compl
#align filter.le_iff_forall_inf_principal_compl Filter.le_iff_forall_inf_principal_compl
theorem inf_neBot_iff_frequently_left {f g : Filter α} :
NeBot (f ⊓ g) ↔ ∀ {p : α → Prop}, (∀ᶠ x in f, p x) → ∃ᶠ x in g, p x := by
simp only [inf_neBot_iff, frequently_iff, and_comm]; rfl
#align filter.inf_ne_bot_iff_frequently_left Filter.inf_neBot_iff_frequently_left
theorem inf_neBot_iff_frequently_right {f g : Filter α} :
NeBot (f ⊓ g) ↔ ∀ {p : α → Prop}, (∀ᶠ x in g, p x) → ∃ᶠ x in f, p x := by
rw [inf_comm]
exact inf_neBot_iff_frequently_left
#align filter.inf_ne_bot_iff_frequently_right Filter.inf_neBot_iff_frequently_right
theorem HasBasis.eq_biInf (h : l.HasBasis p s) : l = ⨅ (i) (_ : p i), 𝓟 (s i) :=
eq_biInf_of_mem_iff_exists_mem fun {_} => by simp only [h.mem_iff, mem_principal, exists_prop]
#align filter.has_basis.eq_binfi Filter.HasBasis.eq_biInf
theorem HasBasis.eq_iInf (h : l.HasBasis (fun _ => True) s) : l = ⨅ i, 𝓟 (s i) := by
simpa only [iInf_true] using h.eq_biInf
#align filter.has_basis.eq_infi Filter.HasBasis.eq_iInf
theorem hasBasis_iInf_principal {s : ι → Set α} (h : Directed (· ≥ ·) s) [Nonempty ι] :
(⨅ i, 𝓟 (s i)).HasBasis (fun _ => True) s :=
⟨fun t => by
simpa only [true_and] using mem_iInf_of_directed (h.mono_comp monotone_principal.dual) t⟩
#align filter.has_basis_infi_principal Filter.hasBasis_iInf_principal
/-- If `s : ι → Set α` is an indexed family of sets, then finite intersections of `s i` form a basis
of `⨅ i, 𝓟 (s i)`. -/
theorem hasBasis_iInf_principal_finite {ι : Type*} (s : ι → Set α) :
(⨅ i, 𝓟 (s i)).HasBasis (fun t : Set ι => t.Finite) fun t => ⋂ i ∈ t, s i := by
refine ⟨fun U => (mem_iInf_finite _).trans ?_⟩
simp only [iInf_principal_finset, mem_iUnion, mem_principal, exists_prop,
exists_finite_iff_finset, Finset.set_biInter_coe]
#align filter.has_basis_infi_principal_finite Filter.hasBasis_iInf_principal_finite
theorem hasBasis_biInf_principal {s : β → Set α} {S : Set β} (h : DirectedOn (s ⁻¹'o (· ≥ ·)) S)
(ne : S.Nonempty) : (⨅ i ∈ S, 𝓟 (s i)).HasBasis (fun i => i ∈ S) s :=
⟨fun t => by
refine mem_biInf_of_directed ?_ ne
rw [directedOn_iff_directed, ← directed_comp] at h ⊢
refine h.mono_comp ?_
exact fun _ _ => principal_mono.2⟩
#align filter.has_basis_binfi_principal Filter.hasBasis_biInf_principal
theorem hasBasis_biInf_principal' {ι : Type*} {p : ι → Prop} {s : ι → Set α}
(h : ∀ i, p i → ∀ j, p j → ∃ k, p k ∧ s k ⊆ s i ∧ s k ⊆ s j) (ne : ∃ i, p i) :
(⨅ (i) (_ : p i), 𝓟 (s i)).HasBasis p s :=
Filter.hasBasis_biInf_principal h ne
#align filter.has_basis_binfi_principal' Filter.hasBasis_biInf_principal'
theorem HasBasis.map (f : α → β) (hl : l.HasBasis p s) : (l.map f).HasBasis p fun i => f '' s i :=
⟨fun t => by simp only [mem_map, image_subset_iff, hl.mem_iff, preimage]⟩
#align filter.has_basis.map Filter.HasBasis.map
theorem HasBasis.comap (f : β → α) (hl : l.HasBasis p s) :
(l.comap f).HasBasis p fun i => f ⁻¹' s i :=
⟨fun t => by
simp only [mem_comap', hl.mem_iff]
refine exists_congr (fun i => Iff.rfl.and ?_)
exact ⟨fun h x hx => h hx rfl, fun h y hy x hx => h <| by rwa [mem_preimage, hx]⟩⟩
#align filter.has_basis.comap Filter.HasBasis.comap
theorem comap_hasBasis (f : α → β) (l : Filter β) :
HasBasis (comap f l) (fun s : Set β => s ∈ l) fun s => f ⁻¹' s :=
⟨fun _ => mem_comap⟩
#align filter.comap_has_basis Filter.comap_hasBasis
theorem HasBasis.forall_mem_mem (h : HasBasis l p s) {x : α} :
(∀ t ∈ l, x ∈ t) ↔ ∀ i, p i → x ∈ s i := by
simp only [h.mem_iff, exists_imp, and_imp]
exact ⟨fun h i hi => h (s i) i hi Subset.rfl, fun h t i hi ht => ht (h i hi)⟩
#align filter.has_basis.forall_mem_mem Filter.HasBasis.forall_mem_mem
protected theorem HasBasis.biInf_mem [CompleteLattice β] {f : Set α → β} (h : HasBasis l p s)
(hf : Monotone f) : ⨅ t ∈ l, f t = ⨅ (i) (_ : p i), f (s i) :=
le_antisymm (le_iInf₂ fun i hi => iInf₂_le (s i) (h.mem_of_mem hi)) <|
le_iInf₂ fun _t ht =>
let ⟨i, hpi, hi⟩ := h.mem_iff.1 ht
iInf₂_le_of_le i hpi (hf hi)
#align filter.has_basis.binfi_mem Filter.HasBasis.biInf_mem
protected theorem HasBasis.biInter_mem {f : Set α → Set β} (h : HasBasis l p s) (hf : Monotone f) :
⋂ t ∈ l, f t = ⋂ (i) (_ : p i), f (s i) :=
h.biInf_mem hf
#align filter.has_basis.bInter_mem Filter.HasBasis.biInter_mem
protected theorem HasBasis.ker (h : HasBasis l p s) : l.ker = ⋂ (i) (_ : p i), s i :=
l.ker_def.trans <| h.biInter_mem monotone_id
#align filter.has_basis.sInter_sets Filter.HasBasis.ker
variable {ι'' : Type*} [Preorder ι''] (l) (s'' : ι'' → Set α)
/-- `IsAntitoneBasis s` means the image of `s` is a filter basis such that `s` is decreasing. -/
structure IsAntitoneBasis extends IsBasis (fun _ => True) s'' : Prop where
/-- The sequence of sets is antitone. -/
protected antitone : Antitone s''
#align filter.is_antitone_basis Filter.IsAntitoneBasis
/-- We say that a filter `l` has an antitone basis `s : ι → Set α`, if `t ∈ l` if and only if `t`
includes `s i` for some `i`, and `s` is decreasing. -/
structure HasAntitoneBasis (l : Filter α) (s : ι'' → Set α)
extends HasBasis l (fun _ => True) s : Prop where
/-- The sequence of sets is antitone. -/
protected antitone : Antitone s
#align filter.has_antitone_basis Filter.HasAntitoneBasis
protected theorem HasAntitoneBasis.map {l : Filter α} {s : ι'' → Set α}
(hf : HasAntitoneBasis l s) (m : α → β) : HasAntitoneBasis (map m l) (m '' s ·) :=
⟨HasBasis.map _ hf.toHasBasis, fun _ _ h => image_subset _ <| hf.2 h⟩
#align filter.has_antitone_basis.map Filter.HasAntitoneBasis.map
protected theorem HasAntitoneBasis.comap {l : Filter α} {s : ι'' → Set α}
(hf : HasAntitoneBasis l s) (m : β → α) : HasAntitoneBasis (comap m l) (m ⁻¹' s ·) :=
⟨hf.1.comap _, fun _ _ h ↦ preimage_mono (hf.2 h)⟩
lemma HasAntitoneBasis.iInf_principal {ι : Type*} [Preorder ι] [Nonempty ι] [IsDirected ι (· ≤ ·)]
{s : ι → Set α} (hs : Antitone s) : (⨅ i, 𝓟 (s i)).HasAntitoneBasis s :=
⟨hasBasis_iInf_principal hs.directed_ge, hs⟩
end SameType
section TwoTypes
variable {la : Filter α} {pa : ι → Prop} {sa : ι → Set α} {lb : Filter β} {pb : ι' → Prop}
{sb : ι' → Set β} {f : α → β}
-- Porting note: use `∃ i, p i ∧ _` instead of `∃ i (hi : p i), _`.
theorem HasBasis.tendsto_left_iff (hla : la.HasBasis pa sa) :
Tendsto f la lb ↔ ∀ t ∈ lb, ∃ i, pa i ∧ MapsTo f (sa i) t := by
simp only [Tendsto, (hla.map f).le_iff, image_subset_iff]
rfl
#align filter.has_basis.tendsto_left_iff Filter.HasBasis.tendsto_left_iffₓ
theorem HasBasis.tendsto_right_iff (hlb : lb.HasBasis pb sb) :
Tendsto f la lb ↔ ∀ i, pb i → ∀ᶠ x in la, f x ∈ sb i := by
simp only [Tendsto, hlb.ge_iff, mem_map', Filter.Eventually]
#align filter.has_basis.tendsto_right_iff Filter.HasBasis.tendsto_right_iff
-- Porting note: use `∃ i, p i ∧ _` instead of `∃ i (hi : p i), _`.
theorem HasBasis.tendsto_iff (hla : la.HasBasis pa sa) (hlb : lb.HasBasis pb sb) :
Tendsto f la lb ↔ ∀ ib, pb ib → ∃ ia, pa ia ∧ ∀ x ∈ sa ia, f x ∈ sb ib := by
simp [hlb.tendsto_right_iff, hla.eventually_iff]
#align filter.has_basis.tendsto_iff Filter.HasBasis.tendsto_iffₓ
-- Porting note: use `∃ i, p i ∧ _` instead of `∃ i (hi : p i), _`.
theorem Tendsto.basis_left (H : Tendsto f la lb) (hla : la.HasBasis pa sa) :
∀ t ∈ lb, ∃ i, pa i ∧ MapsTo f (sa i) t :=
hla.tendsto_left_iff.1 H
#align filter.tendsto.basis_left Filter.Tendsto.basis_leftₓ
theorem Tendsto.basis_right (H : Tendsto f la lb) (hlb : lb.HasBasis pb sb) :
∀ i, pb i → ∀ᶠ x in la, f x ∈ sb i :=
hlb.tendsto_right_iff.1 H
#align filter.tendsto.basis_right Filter.Tendsto.basis_right
-- Porting note: use `∃ i, p i ∧ _` instead of `∃ i (hi : p i), _`.
theorem Tendsto.basis_both (H : Tendsto f la lb) (hla : la.HasBasis pa sa)
(hlb : lb.HasBasis pb sb) :
∀ ib, pb ib → ∃ ia, pa ia ∧ MapsTo f (sa ia) (sb ib) :=
(hla.tendsto_iff hlb).1 H
#align filter.tendsto.basis_both Filter.Tendsto.basis_bothₓ
theorem HasBasis.prod_pprod (hla : la.HasBasis pa sa) (hlb : lb.HasBasis pb sb) :
(la ×ˢ lb).HasBasis (fun i : PProd ι ι' => pa i.1 ∧ pb i.2) fun i => sa i.1 ×ˢ sb i.2 :=
(hla.comap Prod.fst).inf' (hlb.comap Prod.snd)
#align filter.has_basis.prod_pprod Filter.HasBasis.prod_pprod
theorem HasBasis.prod {ι ι' : Type*} {pa : ι → Prop} {sa : ι → Set α} {pb : ι' → Prop}
{sb : ι' → Set β} (hla : la.HasBasis pa sa) (hlb : lb.HasBasis pb sb) :
(la ×ˢ lb).HasBasis (fun i : ι × ι' => pa i.1 ∧ pb i.2) fun i => sa i.1 ×ˢ sb i.2 :=
(hla.comap Prod.fst).inf (hlb.comap Prod.snd)
#align filter.has_basis.prod Filter.HasBasis.prod
theorem HasBasis.prod_same_index {p : ι → Prop} {sb : ι → Set β} (hla : la.HasBasis p sa)
(hlb : lb.HasBasis p sb) (h_dir : ∀ {i j}, p i → p j → ∃ k, p k ∧ sa k ⊆ sa i ∧ sb k ⊆ sb j) :
(la ×ˢ lb).HasBasis p fun i => sa i ×ˢ sb i := by
simp only [hasBasis_iff, (hla.prod_pprod hlb).mem_iff]
refine fun t => ⟨?_, ?_⟩
· rintro ⟨⟨i, j⟩, ⟨hi, hj⟩, hsub : sa i ×ˢ sb j ⊆ t⟩
rcases h_dir hi hj with ⟨k, hk, ki, kj⟩
exact ⟨k, hk, (Set.prod_mono ki kj).trans hsub⟩
· rintro ⟨i, hi, h⟩
exact ⟨⟨i, i⟩, ⟨hi, hi⟩, h⟩
#align filter.has_basis.prod_same_index Filter.HasBasis.prod_same_index
theorem HasBasis.prod_same_index_mono {ι : Type*} [LinearOrder ι] {p : ι → Prop} {sa : ι → Set α}
{sb : ι → Set β} (hla : la.HasBasis p sa) (hlb : lb.HasBasis p sb)
(hsa : MonotoneOn sa { i | p i }) (hsb : MonotoneOn sb { i | p i }) :
(la ×ˢ lb).HasBasis p fun i => sa i ×ˢ sb i :=
hla.prod_same_index hlb fun {i j} hi hj =>
have : p (min i j) := min_rec' _ hi hj
⟨min i j, this, hsa this hi <| min_le_left _ _, hsb this hj <| min_le_right _ _⟩
#align filter.has_basis.prod_same_index_mono Filter.HasBasis.prod_same_index_mono
theorem HasBasis.prod_same_index_anti {ι : Type*} [LinearOrder ι] {p : ι → Prop} {sa : ι → Set α}
{sb : ι → Set β} (hla : la.HasBasis p sa) (hlb : lb.HasBasis p sb)
(hsa : AntitoneOn sa { i | p i }) (hsb : AntitoneOn sb { i | p i }) :
(la ×ˢ lb).HasBasis p fun i => sa i ×ˢ sb i :=
@HasBasis.prod_same_index_mono _ _ _ _ ιᵒᵈ _ _ _ _ hla hlb hsa.dual_left hsb.dual_left
#align filter.has_basis.prod_same_index_anti Filter.HasBasis.prod_same_index_anti
theorem HasBasis.prod_self (hl : la.HasBasis pa sa) :
(la ×ˢ la).HasBasis pa fun i => sa i ×ˢ sa i :=
hl.prod_same_index hl fun {i j} hi hj => by
simpa only [exists_prop, subset_inter_iff] using
hl.mem_iff.1 (inter_mem (hl.mem_of_mem hi) (hl.mem_of_mem hj))
#align filter.has_basis.prod_self Filter.HasBasis.prod_self
theorem mem_prod_self_iff {s} : s ∈ la ×ˢ la ↔ ∃ t ∈ la, t ×ˢ t ⊆ s :=
la.basis_sets.prod_self.mem_iff
#align filter.mem_prod_self_iff Filter.mem_prod_self_iff
lemma eventually_prod_self_iff {r : α → α → Prop} :
(∀ᶠ x in la ×ˢ la, r x.1 x.2) ↔ ∃ t ∈ la, ∀ x ∈ t, ∀ y ∈ t, r x y :=
mem_prod_self_iff.trans <| by simp only [prod_subset_iff, mem_setOf_eq]
theorem HasAntitoneBasis.prod {ι : Type*} [LinearOrder ι] {f : Filter α} {g : Filter β}
{s : ι → Set α} {t : ι → Set β} (hf : HasAntitoneBasis f s) (hg : HasAntitoneBasis g t) :
HasAntitoneBasis (f ×ˢ g) fun n => s n ×ˢ t n :=
⟨hf.1.prod_same_index_anti hg.1 (hf.2.antitoneOn _) (hg.2.antitoneOn _), hf.2.set_prod hg.2⟩
#align filter.has_antitone_basis.prod Filter.HasAntitoneBasis.prod
theorem HasBasis.coprod {ι ι' : Type*} {pa : ι → Prop} {sa : ι → Set α} {pb : ι' → Prop}
{sb : ι' → Set β} (hla : la.HasBasis pa sa) (hlb : lb.HasBasis pb sb) :
(la.coprod lb).HasBasis (fun i : ι × ι' => pa i.1 ∧ pb i.2) fun i =>
Prod.fst ⁻¹' sa i.1 ∪ Prod.snd ⁻¹' sb i.2 :=
(hla.comap Prod.fst).sup (hlb.comap Prod.snd)
#align filter.has_basis.coprod Filter.HasBasis.coprod
end TwoTypes
| Mathlib/Order/Filter/Bases.lean | 985 | 990 | theorem map_sigma_mk_comap {π : α → Type*} {π' : β → Type*} {f : α → β}
(hf : Function.Injective f) (g : ∀ a, π a → π' (f a)) (a : α) (l : Filter (π' (f a))) :
map (Sigma.mk a) (comap (g a) l) = comap (Sigma.map f g) (map (Sigma.mk (f a)) l) := by |
refine (((basis_sets _).comap _).map _).eq_of_same_basis ?_
convert ((basis_sets l).map (Sigma.mk (f a))).comap (Sigma.map f g)
apply image_sigmaMk_preimage_sigmaMap hf
|
/-
Copyright (c) 2018 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Johannes Hölzl
-/
import Mathlib.MeasureTheory.Constructions.BorelSpace.Order
#align_import measure_theory.function.simple_func from "leanprover-community/mathlib"@"bf6a01357ff5684b1ebcd0f1a13be314fc82c0bf"
/-!
# Simple functions
A function `f` from a measurable space to any type is called *simple*, if every preimage `f ⁻¹' {x}`
is measurable, and the range is finite. In this file, we define simple functions and establish their
basic properties; and we construct a sequence of simple functions approximating an arbitrary Borel
measurable function `f : α → ℝ≥0∞`.
The theorem `Measurable.ennreal_induction` shows that in order to prove something for an arbitrary
measurable function into `ℝ≥0∞`, it is sufficient to show that the property holds for (multiples of)
characteristic functions and is closed under addition and supremum of increasing sequences of
functions.
-/
noncomputable section
open Set hiding restrict restrict_apply
open Filter ENNReal
open Function (support)
open scoped Classical
open Topology NNReal ENNReal MeasureTheory
namespace MeasureTheory
variable {α β γ δ : Type*}
/-- A function `f` from a measurable space to any type is called *simple*,
if every preimage `f ⁻¹' {x}` is measurable, and the range is finite. This structure bundles
a function with these properties. -/
structure SimpleFunc.{u, v} (α : Type u) [MeasurableSpace α] (β : Type v) where
toFun : α → β
measurableSet_fiber' : ∀ x, MeasurableSet (toFun ⁻¹' {x})
finite_range' : (Set.range toFun).Finite
#align measure_theory.simple_func MeasureTheory.SimpleFunc
#align measure_theory.simple_func.to_fun MeasureTheory.SimpleFunc.toFun
#align measure_theory.simple_func.measurable_set_fiber' MeasureTheory.SimpleFunc.measurableSet_fiber'
#align measure_theory.simple_func.finite_range' MeasureTheory.SimpleFunc.finite_range'
local infixr:25 " →ₛ " => SimpleFunc
namespace SimpleFunc
section Measurable
variable [MeasurableSpace α]
attribute [coe] toFun
instance instCoeFun : CoeFun (α →ₛ β) fun _ => α → β :=
⟨toFun⟩
#align measure_theory.simple_func.has_coe_to_fun MeasureTheory.SimpleFunc.instCoeFun
theorem coe_injective ⦃f g : α →ₛ β⦄ (H : (f : α → β) = g) : f = g := by
cases f; cases g; congr
#align measure_theory.simple_func.coe_injective MeasureTheory.SimpleFunc.coe_injective
@[ext]
theorem ext {f g : α →ₛ β} (H : ∀ a, f a = g a) : f = g :=
coe_injective <| funext H
#align measure_theory.simple_func.ext MeasureTheory.SimpleFunc.ext
theorem finite_range (f : α →ₛ β) : (Set.range f).Finite :=
f.finite_range'
#align measure_theory.simple_func.finite_range MeasureTheory.SimpleFunc.finite_range
theorem measurableSet_fiber (f : α →ₛ β) (x : β) : MeasurableSet (f ⁻¹' {x}) :=
f.measurableSet_fiber' x
#align measure_theory.simple_func.measurable_set_fiber MeasureTheory.SimpleFunc.measurableSet_fiber
-- @[simp] -- Porting note (#10618): simp can prove this
theorem apply_mk (f : α → β) (h h') (x : α) : SimpleFunc.mk f h h' x = f x :=
rfl
#align measure_theory.simple_func.apply_mk MeasureTheory.SimpleFunc.apply_mk
/-- Simple function defined on a finite type. -/
def ofFinite [Finite α] [MeasurableSingletonClass α] (f : α → β) : α →ₛ β where
toFun := f
measurableSet_fiber' x := (toFinite (f ⁻¹' {x})).measurableSet
finite_range' := Set.finite_range f
@[deprecated (since := "2024-02-05")] alias ofFintype := ofFinite
/-- Simple function defined on the empty type. -/
def ofIsEmpty [IsEmpty α] : α →ₛ β := ofFinite isEmptyElim
#align measure_theory.simple_func.of_is_empty MeasureTheory.SimpleFunc.ofIsEmpty
/-- Range of a simple function `α →ₛ β` as a `Finset β`. -/
protected def range (f : α →ₛ β) : Finset β :=
f.finite_range.toFinset
#align measure_theory.simple_func.range MeasureTheory.SimpleFunc.range
@[simp]
theorem mem_range {f : α →ₛ β} {b} : b ∈ f.range ↔ b ∈ range f :=
Finite.mem_toFinset _
#align measure_theory.simple_func.mem_range MeasureTheory.SimpleFunc.mem_range
theorem mem_range_self (f : α →ₛ β) (x : α) : f x ∈ f.range :=
mem_range.2 ⟨x, rfl⟩
#align measure_theory.simple_func.mem_range_self MeasureTheory.SimpleFunc.mem_range_self
@[simp]
theorem coe_range (f : α →ₛ β) : (↑f.range : Set β) = Set.range f :=
f.finite_range.coe_toFinset
#align measure_theory.simple_func.coe_range MeasureTheory.SimpleFunc.coe_range
theorem mem_range_of_measure_ne_zero {f : α →ₛ β} {x : β} {μ : Measure α} (H : μ (f ⁻¹' {x}) ≠ 0) :
x ∈ f.range :=
let ⟨a, ha⟩ := nonempty_of_measure_ne_zero H
mem_range.2 ⟨a, ha⟩
#align measure_theory.simple_func.mem_range_of_measure_ne_zero MeasureTheory.SimpleFunc.mem_range_of_measure_ne_zero
theorem forall_mem_range {f : α →ₛ β} {p : β → Prop} : (∀ y ∈ f.range, p y) ↔ ∀ x, p (f x) := by
simp only [mem_range, Set.forall_mem_range]
#align measure_theory.simple_func.forall_mem_range MeasureTheory.SimpleFunc.forall_mem_range
theorem exists_range_iff {f : α →ₛ β} {p : β → Prop} : (∃ y ∈ f.range, p y) ↔ ∃ x, p (f x) := by
simpa only [mem_range, exists_prop] using Set.exists_range_iff
#align measure_theory.simple_func.exists_range_iff MeasureTheory.SimpleFunc.exists_range_iff
theorem preimage_eq_empty_iff (f : α →ₛ β) (b : β) : f ⁻¹' {b} = ∅ ↔ b ∉ f.range :=
preimage_singleton_eq_empty.trans <| not_congr mem_range.symm
#align measure_theory.simple_func.preimage_eq_empty_iff MeasureTheory.SimpleFunc.preimage_eq_empty_iff
theorem exists_forall_le [Nonempty β] [Preorder β] [IsDirected β (· ≤ ·)] (f : α →ₛ β) :
∃ C, ∀ x, f x ≤ C :=
f.range.exists_le.imp fun _ => forall_mem_range.1
#align measure_theory.simple_func.exists_forall_le MeasureTheory.SimpleFunc.exists_forall_le
/-- Constant function as a `SimpleFunc`. -/
def const (α) {β} [MeasurableSpace α] (b : β) : α →ₛ β :=
⟨fun _ => b, fun _ => MeasurableSet.const _, finite_range_const⟩
#align measure_theory.simple_func.const MeasureTheory.SimpleFunc.const
instance instInhabited [Inhabited β] : Inhabited (α →ₛ β) :=
⟨const _ default⟩
#align measure_theory.simple_func.inhabited MeasureTheory.SimpleFunc.instInhabited
theorem const_apply (a : α) (b : β) : (const α b) a = b :=
rfl
#align measure_theory.simple_func.const_apply MeasureTheory.SimpleFunc.const_apply
@[simp]
theorem coe_const (b : β) : ⇑(const α b) = Function.const α b :=
rfl
#align measure_theory.simple_func.coe_const MeasureTheory.SimpleFunc.coe_const
@[simp]
theorem range_const (α) [MeasurableSpace α] [Nonempty α] (b : β) : (const α b).range = {b} :=
Finset.coe_injective <| by simp (config := { unfoldPartialApp := true }) [Function.const]
#align measure_theory.simple_func.range_const MeasureTheory.SimpleFunc.range_const
theorem range_const_subset (α) [MeasurableSpace α] (b : β) : (const α b).range ⊆ {b} :=
Finset.coe_subset.1 <| by simp
#align measure_theory.simple_func.range_const_subset MeasureTheory.SimpleFunc.range_const_subset
theorem simpleFunc_bot {α} (f : @SimpleFunc α ⊥ β) [Nonempty β] : ∃ c, ∀ x, f x = c := by
have hf_meas := @SimpleFunc.measurableSet_fiber α _ ⊥ f
simp_rw [MeasurableSpace.measurableSet_bot_iff] at hf_meas
exact (exists_eq_const_of_preimage_singleton hf_meas).imp fun c hc ↦ congr_fun hc
#align measure_theory.simple_func.simple_func_bot MeasureTheory.SimpleFunc.simpleFunc_bot
theorem simpleFunc_bot' {α} [Nonempty β] (f : @SimpleFunc α ⊥ β) :
∃ c, f = @SimpleFunc.const α _ ⊥ c :=
letI : MeasurableSpace α := ⊥; (simpleFunc_bot f).imp fun _ ↦ ext
#align measure_theory.simple_func.simple_func_bot' MeasureTheory.SimpleFunc.simpleFunc_bot'
theorem measurableSet_cut (r : α → β → Prop) (f : α →ₛ β) (h : ∀ b, MeasurableSet { a | r a b }) :
MeasurableSet { a | r a (f a) } := by
have : { a | r a (f a) } = ⋃ b ∈ range f, { a | r a b } ∩ f ⁻¹' {b} := by
ext a
suffices r a (f a) ↔ ∃ i, r a (f i) ∧ f a = f i by simpa
exact ⟨fun h => ⟨a, ⟨h, rfl⟩⟩, fun ⟨a', ⟨h', e⟩⟩ => e.symm ▸ h'⟩
rw [this]
exact
MeasurableSet.biUnion f.finite_range.countable fun b _ =>
MeasurableSet.inter (h b) (f.measurableSet_fiber _)
#align measure_theory.simple_func.measurable_set_cut MeasureTheory.SimpleFunc.measurableSet_cut
@[measurability]
theorem measurableSet_preimage (f : α →ₛ β) (s) : MeasurableSet (f ⁻¹' s) :=
measurableSet_cut (fun _ b => b ∈ s) f fun b => MeasurableSet.const (b ∈ s)
#align measure_theory.simple_func.measurable_set_preimage MeasureTheory.SimpleFunc.measurableSet_preimage
/-- A simple function is measurable -/
@[measurability]
protected theorem measurable [MeasurableSpace β] (f : α →ₛ β) : Measurable f := fun s _ =>
measurableSet_preimage f s
#align measure_theory.simple_func.measurable MeasureTheory.SimpleFunc.measurable
@[measurability]
protected theorem aemeasurable [MeasurableSpace β] {μ : Measure α} (f : α →ₛ β) :
AEMeasurable f μ :=
f.measurable.aemeasurable
#align measure_theory.simple_func.ae_measurable MeasureTheory.SimpleFunc.aemeasurable
protected theorem sum_measure_preimage_singleton (f : α →ₛ β) {μ : Measure α} (s : Finset β) :
(∑ y ∈ s, μ (f ⁻¹' {y})) = μ (f ⁻¹' ↑s) :=
sum_measure_preimage_singleton _ fun _ _ => f.measurableSet_fiber _
#align measure_theory.simple_func.sum_measure_preimage_singleton MeasureTheory.SimpleFunc.sum_measure_preimage_singleton
theorem sum_range_measure_preimage_singleton (f : α →ₛ β) (μ : Measure α) :
(∑ y ∈ f.range, μ (f ⁻¹' {y})) = μ univ := by
rw [f.sum_measure_preimage_singleton, coe_range, preimage_range]
#align measure_theory.simple_func.sum_range_measure_preimage_singleton MeasureTheory.SimpleFunc.sum_range_measure_preimage_singleton
/-- If-then-else as a `SimpleFunc`. -/
def piecewise (s : Set α) (hs : MeasurableSet s) (f g : α →ₛ β) : α →ₛ β :=
⟨s.piecewise f g, fun _ =>
letI : MeasurableSpace β := ⊤
f.measurable.piecewise hs g.measurable trivial,
(f.finite_range.union g.finite_range).subset range_ite_subset⟩
#align measure_theory.simple_func.piecewise MeasureTheory.SimpleFunc.piecewise
@[simp]
theorem coe_piecewise {s : Set α} (hs : MeasurableSet s) (f g : α →ₛ β) :
⇑(piecewise s hs f g) = s.piecewise f g :=
rfl
#align measure_theory.simple_func.coe_piecewise MeasureTheory.SimpleFunc.coe_piecewise
theorem piecewise_apply {s : Set α} (hs : MeasurableSet s) (f g : α →ₛ β) (a) :
piecewise s hs f g a = if a ∈ s then f a else g a :=
rfl
#align measure_theory.simple_func.piecewise_apply MeasureTheory.SimpleFunc.piecewise_apply
@[simp]
theorem piecewise_compl {s : Set α} (hs : MeasurableSet sᶜ) (f g : α →ₛ β) :
piecewise sᶜ hs f g = piecewise s hs.of_compl g f :=
coe_injective <| by
set_option tactic.skipAssignedInstances false in
simp [hs]; convert Set.piecewise_compl s f g
#align measure_theory.simple_func.piecewise_compl MeasureTheory.SimpleFunc.piecewise_compl
@[simp]
theorem piecewise_univ (f g : α →ₛ β) : piecewise univ MeasurableSet.univ f g = f :=
coe_injective <| by
set_option tactic.skipAssignedInstances false in
simp; convert Set.piecewise_univ f g
#align measure_theory.simple_func.piecewise_univ MeasureTheory.SimpleFunc.piecewise_univ
@[simp]
theorem piecewise_empty (f g : α →ₛ β) : piecewise ∅ MeasurableSet.empty f g = g :=
coe_injective <| by
set_option tactic.skipAssignedInstances false in
simp; convert Set.piecewise_empty f g
#align measure_theory.simple_func.piecewise_empty MeasureTheory.SimpleFunc.piecewise_empty
@[simp]
theorem piecewise_same (f : α →ₛ β) {s : Set α} (hs : MeasurableSet s) :
piecewise s hs f f = f :=
coe_injective <| Set.piecewise_same _ _
theorem support_indicator [Zero β] {s : Set α} (hs : MeasurableSet s) (f : α →ₛ β) :
Function.support (f.piecewise s hs (SimpleFunc.const α 0)) = s ∩ Function.support f :=
Set.support_indicator
#align measure_theory.simple_func.support_indicator MeasureTheory.SimpleFunc.support_indicator
theorem range_indicator {s : Set α} (hs : MeasurableSet s) (hs_nonempty : s.Nonempty)
(hs_ne_univ : s ≠ univ) (x y : β) :
(piecewise s hs (const α x) (const α y)).range = {x, y} := by
simp only [← Finset.coe_inj, coe_range, coe_piecewise, range_piecewise, coe_const,
Finset.coe_insert, Finset.coe_singleton, hs_nonempty.image_const,
(nonempty_compl.2 hs_ne_univ).image_const, singleton_union, Function.const]
#align measure_theory.simple_func.range_indicator MeasureTheory.SimpleFunc.range_indicator
theorem measurable_bind [MeasurableSpace γ] (f : α →ₛ β) (g : β → α → γ)
(hg : ∀ b, Measurable (g b)) : Measurable fun a => g (f a) a := fun s hs =>
f.measurableSet_cut (fun a b => g b a ∈ s) fun b => hg b hs
#align measure_theory.simple_func.measurable_bind MeasureTheory.SimpleFunc.measurable_bind
/-- If `f : α →ₛ β` is a simple function and `g : β → α →ₛ γ` is a family of simple functions,
then `f.bind g` binds the first argument of `g` to `f`. In other words, `f.bind g a = g (f a) a`. -/
def bind (f : α →ₛ β) (g : β → α →ₛ γ) : α →ₛ γ :=
⟨fun a => g (f a) a, fun c =>
f.measurableSet_cut (fun a b => g b a = c) fun b => (g b).measurableSet_preimage {c},
(f.finite_range.biUnion fun b _ => (g b).finite_range).subset <| by
rintro _ ⟨a, rfl⟩; simp⟩
#align measure_theory.simple_func.bind MeasureTheory.SimpleFunc.bind
@[simp]
theorem bind_apply (f : α →ₛ β) (g : β → α →ₛ γ) (a) : f.bind g a = g (f a) a :=
rfl
#align measure_theory.simple_func.bind_apply MeasureTheory.SimpleFunc.bind_apply
/-- Given a function `g : β → γ` and a simple function `f : α →ₛ β`, `f.map g` return the simple
function `g ∘ f : α →ₛ γ` -/
def map (g : β → γ) (f : α →ₛ β) : α →ₛ γ :=
bind f (const α ∘ g)
#align measure_theory.simple_func.map MeasureTheory.SimpleFunc.map
theorem map_apply (g : β → γ) (f : α →ₛ β) (a) : f.map g a = g (f a) :=
rfl
#align measure_theory.simple_func.map_apply MeasureTheory.SimpleFunc.map_apply
theorem map_map (g : β → γ) (h : γ → δ) (f : α →ₛ β) : (f.map g).map h = f.map (h ∘ g) :=
rfl
#align measure_theory.simple_func.map_map MeasureTheory.SimpleFunc.map_map
@[simp]
theorem coe_map (g : β → γ) (f : α →ₛ β) : (f.map g : α → γ) = g ∘ f :=
rfl
#align measure_theory.simple_func.coe_map MeasureTheory.SimpleFunc.coe_map
@[simp]
theorem range_map [DecidableEq γ] (g : β → γ) (f : α →ₛ β) : (f.map g).range = f.range.image g :=
Finset.coe_injective <| by simp only [coe_range, coe_map, Finset.coe_image, range_comp]
#align measure_theory.simple_func.range_map MeasureTheory.SimpleFunc.range_map
@[simp]
theorem map_const (g : β → γ) (b : β) : (const α b).map g = const α (g b) :=
rfl
#align measure_theory.simple_func.map_const MeasureTheory.SimpleFunc.map_const
theorem map_preimage (f : α →ₛ β) (g : β → γ) (s : Set γ) :
f.map g ⁻¹' s = f ⁻¹' ↑(f.range.filter fun b => g b ∈ s) := by
simp only [coe_range, sep_mem_eq, coe_map, Finset.coe_filter,
← mem_preimage, inter_comm, preimage_inter_range, ← Finset.mem_coe]
exact preimage_comp
#align measure_theory.simple_func.map_preimage MeasureTheory.SimpleFunc.map_preimage
theorem map_preimage_singleton (f : α →ₛ β) (g : β → γ) (c : γ) :
f.map g ⁻¹' {c} = f ⁻¹' ↑(f.range.filter fun b => g b = c) :=
map_preimage _ _ _
#align measure_theory.simple_func.map_preimage_singleton MeasureTheory.SimpleFunc.map_preimage_singleton
/-- Composition of a `SimpleFun` and a measurable function is a `SimpleFunc`. -/
def comp [MeasurableSpace β] (f : β →ₛ γ) (g : α → β) (hgm : Measurable g) : α →ₛ γ where
toFun := f ∘ g
finite_range' := f.finite_range.subset <| Set.range_comp_subset_range _ _
measurableSet_fiber' z := hgm (f.measurableSet_fiber z)
#align measure_theory.simple_func.comp MeasureTheory.SimpleFunc.comp
@[simp]
theorem coe_comp [MeasurableSpace β] (f : β →ₛ γ) {g : α → β} (hgm : Measurable g) :
⇑(f.comp g hgm) = f ∘ g :=
rfl
#align measure_theory.simple_func.coe_comp MeasureTheory.SimpleFunc.coe_comp
theorem range_comp_subset_range [MeasurableSpace β] (f : β →ₛ γ) {g : α → β} (hgm : Measurable g) :
(f.comp g hgm).range ⊆ f.range :=
Finset.coe_subset.1 <| by simp only [coe_range, coe_comp, Set.range_comp_subset_range]
#align measure_theory.simple_func.range_comp_subset_range MeasureTheory.SimpleFunc.range_comp_subset_range
/-- Extend a `SimpleFunc` along a measurable embedding: `f₁.extend g hg f₂` is the function
`F : β →ₛ γ` such that `F ∘ g = f₁` and `F y = f₂ y` whenever `y ∉ range g`. -/
def extend [MeasurableSpace β] (f₁ : α →ₛ γ) (g : α → β) (hg : MeasurableEmbedding g)
(f₂ : β →ₛ γ) : β →ₛ γ where
toFun := Function.extend g f₁ f₂
finite_range' :=
(f₁.finite_range.union <| f₂.finite_range.subset (image_subset_range _ _)).subset
(range_extend_subset _ _ _)
measurableSet_fiber' := by
letI : MeasurableSpace γ := ⊤; haveI : MeasurableSingletonClass γ := ⟨fun _ => trivial⟩
exact fun x => hg.measurable_extend f₁.measurable f₂.measurable (measurableSet_singleton _)
#align measure_theory.simple_func.extend MeasureTheory.SimpleFunc.extend
@[simp]
theorem extend_apply [MeasurableSpace β] (f₁ : α →ₛ γ) {g : α → β} (hg : MeasurableEmbedding g)
(f₂ : β →ₛ γ) (x : α) : (f₁.extend g hg f₂) (g x) = f₁ x :=
hg.injective.extend_apply _ _ _
#align measure_theory.simple_func.extend_apply MeasureTheory.SimpleFunc.extend_apply
@[simp]
theorem extend_apply' [MeasurableSpace β] (f₁ : α →ₛ γ) {g : α → β} (hg : MeasurableEmbedding g)
(f₂ : β →ₛ γ) {y : β} (h : ¬∃ x, g x = y) : (f₁.extend g hg f₂) y = f₂ y :=
Function.extend_apply' _ _ _ h
#align measure_theory.simple_func.extend_apply' MeasureTheory.SimpleFunc.extend_apply'
@[simp]
theorem extend_comp_eq' [MeasurableSpace β] (f₁ : α →ₛ γ) {g : α → β} (hg : MeasurableEmbedding g)
(f₂ : β →ₛ γ) : f₁.extend g hg f₂ ∘ g = f₁ :=
funext fun _ => extend_apply _ _ _ _
#align measure_theory.simple_func.extend_comp_eq' MeasureTheory.SimpleFunc.extend_comp_eq'
@[simp]
theorem extend_comp_eq [MeasurableSpace β] (f₁ : α →ₛ γ) {g : α → β} (hg : MeasurableEmbedding g)
(f₂ : β →ₛ γ) : (f₁.extend g hg f₂).comp g hg.measurable = f₁ :=
coe_injective <| extend_comp_eq' _ hg _
#align measure_theory.simple_func.extend_comp_eq MeasureTheory.SimpleFunc.extend_comp_eq
/-- If `f` is a simple function taking values in `β → γ` and `g` is another simple function
with the same domain and codomain `β`, then `f.seq g = f a (g a)`. -/
def seq (f : α →ₛ β → γ) (g : α →ₛ β) : α →ₛ γ :=
f.bind fun f => g.map f
#align measure_theory.simple_func.seq MeasureTheory.SimpleFunc.seq
@[simp]
theorem seq_apply (f : α →ₛ β → γ) (g : α →ₛ β) (a : α) : f.seq g a = f a (g a) :=
rfl
#align measure_theory.simple_func.seq_apply MeasureTheory.SimpleFunc.seq_apply
/-- Combine two simple functions `f : α →ₛ β` and `g : α →ₛ β`
into `fun a => (f a, g a)`. -/
def pair (f : α →ₛ β) (g : α →ₛ γ) : α →ₛ β × γ :=
(f.map Prod.mk).seq g
#align measure_theory.simple_func.pair MeasureTheory.SimpleFunc.pair
@[simp]
theorem pair_apply (f : α →ₛ β) (g : α →ₛ γ) (a) : pair f g a = (f a, g a) :=
rfl
#align measure_theory.simple_func.pair_apply MeasureTheory.SimpleFunc.pair_apply
theorem pair_preimage (f : α →ₛ β) (g : α →ₛ γ) (s : Set β) (t : Set γ) :
pair f g ⁻¹' s ×ˢ t = f ⁻¹' s ∩ g ⁻¹' t :=
rfl
#align measure_theory.simple_func.pair_preimage MeasureTheory.SimpleFunc.pair_preimage
-- A special form of `pair_preimage`
theorem pair_preimage_singleton (f : α →ₛ β) (g : α →ₛ γ) (b : β) (c : γ) :
pair f g ⁻¹' {(b, c)} = f ⁻¹' {b} ∩ g ⁻¹' {c} := by
rw [← singleton_prod_singleton]
exact pair_preimage _ _ _ _
#align measure_theory.simple_func.pair_preimage_singleton MeasureTheory.SimpleFunc.pair_preimage_singleton
theorem bind_const (f : α →ₛ β) : f.bind (const α) = f := by ext; simp
#align measure_theory.simple_func.bind_const MeasureTheory.SimpleFunc.bind_const
@[to_additive]
instance instOne [One β] : One (α →ₛ β) :=
⟨const α 1⟩
#align measure_theory.simple_func.has_one MeasureTheory.SimpleFunc.instOne
#align measure_theory.simple_func.has_zero MeasureTheory.SimpleFunc.instZero
@[to_additive]
instance instMul [Mul β] : Mul (α →ₛ β) :=
⟨fun f g => (f.map (· * ·)).seq g⟩
#align measure_theory.simple_func.has_mul MeasureTheory.SimpleFunc.instMul
#align measure_theory.simple_func.has_add MeasureTheory.SimpleFunc.instAdd
@[to_additive]
instance instDiv [Div β] : Div (α →ₛ β) :=
⟨fun f g => (f.map (· / ·)).seq g⟩
#align measure_theory.simple_func.has_div MeasureTheory.SimpleFunc.instDiv
#align measure_theory.simple_func.has_sub MeasureTheory.SimpleFunc.instSub
@[to_additive]
instance instInv [Inv β] : Inv (α →ₛ β) :=
⟨fun f => f.map Inv.inv⟩
#align measure_theory.simple_func.has_inv MeasureTheory.SimpleFunc.instInv
#align measure_theory.simple_func.has_neg MeasureTheory.SimpleFunc.instNeg
instance instSup [Sup β] : Sup (α →ₛ β) :=
⟨fun f g => (f.map (· ⊔ ·)).seq g⟩
#align measure_theory.simple_func.has_sup MeasureTheory.SimpleFunc.instSup
instance instInf [Inf β] : Inf (α →ₛ β) :=
⟨fun f g => (f.map (· ⊓ ·)).seq g⟩
#align measure_theory.simple_func.has_inf MeasureTheory.SimpleFunc.instInf
instance instLE [LE β] : LE (α →ₛ β) :=
⟨fun f g => ∀ a, f a ≤ g a⟩
#align measure_theory.simple_func.has_le MeasureTheory.SimpleFunc.instLE
@[to_additive (attr := simp)]
theorem const_one [One β] : const α (1 : β) = 1 :=
rfl
#align measure_theory.simple_func.const_one MeasureTheory.SimpleFunc.const_one
#align measure_theory.simple_func.const_zero MeasureTheory.SimpleFunc.const_zero
@[to_additive (attr := simp, norm_cast)]
theorem coe_one [One β] : ⇑(1 : α →ₛ β) = 1 :=
rfl
#align measure_theory.simple_func.coe_one MeasureTheory.SimpleFunc.coe_one
#align measure_theory.simple_func.coe_zero MeasureTheory.SimpleFunc.coe_zero
@[to_additive (attr := simp, norm_cast)]
theorem coe_mul [Mul β] (f g : α →ₛ β) : ⇑(f * g) = ⇑f * ⇑g :=
rfl
#align measure_theory.simple_func.coe_mul MeasureTheory.SimpleFunc.coe_mul
#align measure_theory.simple_func.coe_add MeasureTheory.SimpleFunc.coe_add
@[to_additive (attr := simp, norm_cast)]
theorem coe_inv [Inv β] (f : α →ₛ β) : ⇑(f⁻¹) = (⇑f)⁻¹ :=
rfl
#align measure_theory.simple_func.coe_inv MeasureTheory.SimpleFunc.coe_inv
#align measure_theory.simple_func.coe_neg MeasureTheory.SimpleFunc.coe_neg
@[to_additive (attr := simp, norm_cast)]
theorem coe_div [Div β] (f g : α →ₛ β) : ⇑(f / g) = ⇑f / ⇑g :=
rfl
#align measure_theory.simple_func.coe_div MeasureTheory.SimpleFunc.coe_div
#align measure_theory.simple_func.coe_sub MeasureTheory.SimpleFunc.coe_sub
@[simp, norm_cast]
theorem coe_le [Preorder β] {f g : α →ₛ β} : (f : α → β) ≤ g ↔ f ≤ g :=
Iff.rfl
#align measure_theory.simple_func.coe_le MeasureTheory.SimpleFunc.coe_le
@[simp, norm_cast]
theorem coe_sup [Sup β] (f g : α →ₛ β) : ⇑(f ⊔ g) = ⇑f ⊔ ⇑g :=
rfl
#align measure_theory.simple_func.coe_sup MeasureTheory.SimpleFunc.coe_sup
@[simp, norm_cast]
theorem coe_inf [Inf β] (f g : α →ₛ β) : ⇑(f ⊓ g) = ⇑f ⊓ ⇑g :=
rfl
#align measure_theory.simple_func.coe_inf MeasureTheory.SimpleFunc.coe_inf
@[to_additive]
theorem mul_apply [Mul β] (f g : α →ₛ β) (a : α) : (f * g) a = f a * g a :=
rfl
#align measure_theory.simple_func.mul_apply MeasureTheory.SimpleFunc.mul_apply
#align measure_theory.simple_func.add_apply MeasureTheory.SimpleFunc.add_apply
@[to_additive]
theorem div_apply [Div β] (f g : α →ₛ β) (x : α) : (f / g) x = f x / g x :=
rfl
#align measure_theory.simple_func.div_apply MeasureTheory.SimpleFunc.div_apply
#align measure_theory.simple_func.sub_apply MeasureTheory.SimpleFunc.sub_apply
@[to_additive]
theorem inv_apply [Inv β] (f : α →ₛ β) (x : α) : f⁻¹ x = (f x)⁻¹ :=
rfl
#align measure_theory.simple_func.inv_apply MeasureTheory.SimpleFunc.inv_apply
#align measure_theory.simple_func.neg_apply MeasureTheory.SimpleFunc.neg_apply
theorem sup_apply [Sup β] (f g : α →ₛ β) (a : α) : (f ⊔ g) a = f a ⊔ g a :=
rfl
#align measure_theory.simple_func.sup_apply MeasureTheory.SimpleFunc.sup_apply
theorem inf_apply [Inf β] (f g : α →ₛ β) (a : α) : (f ⊓ g) a = f a ⊓ g a :=
rfl
#align measure_theory.simple_func.inf_apply MeasureTheory.SimpleFunc.inf_apply
@[to_additive (attr := simp)]
theorem range_one [Nonempty α] [One β] : (1 : α →ₛ β).range = {1} :=
Finset.ext fun x => by simp [eq_comm]
#align measure_theory.simple_func.range_one MeasureTheory.SimpleFunc.range_one
#align measure_theory.simple_func.range_zero MeasureTheory.SimpleFunc.range_zero
@[simp]
theorem range_eq_empty_of_isEmpty {β} [hα : IsEmpty α] (f : α →ₛ β) : f.range = ∅ := by
rw [← Finset.not_nonempty_iff_eq_empty]
by_contra h
obtain ⟨y, hy_mem⟩ := h
rw [SimpleFunc.mem_range, Set.mem_range] at hy_mem
obtain ⟨x, hxy⟩ := hy_mem
rw [isEmpty_iff] at hα
exact hα x
#align measure_theory.simple_func.range_eq_empty_of_is_empty MeasureTheory.SimpleFunc.range_eq_empty_of_isEmpty
theorem eq_zero_of_mem_range_zero [Zero β] : ∀ {y : β}, y ∈ (0 : α →ₛ β).range → y = 0 :=
@(forall_mem_range.2 fun _ => rfl)
#align measure_theory.simple_func.eq_zero_of_mem_range_zero MeasureTheory.SimpleFunc.eq_zero_of_mem_range_zero
@[to_additive]
theorem mul_eq_map₂ [Mul β] (f g : α →ₛ β) : f * g = (pair f g).map fun p : β × β => p.1 * p.2 :=
rfl
#align measure_theory.simple_func.mul_eq_map₂ MeasureTheory.SimpleFunc.mul_eq_map₂
#align measure_theory.simple_func.add_eq_map₂ MeasureTheory.SimpleFunc.add_eq_map₂
theorem sup_eq_map₂ [Sup β] (f g : α →ₛ β) : f ⊔ g = (pair f g).map fun p : β × β => p.1 ⊔ p.2 :=
rfl
#align measure_theory.simple_func.sup_eq_map₂ MeasureTheory.SimpleFunc.sup_eq_map₂
@[to_additive]
theorem const_mul_eq_map [Mul β] (f : α →ₛ β) (b : β) : const α b * f = f.map fun a => b * a :=
rfl
#align measure_theory.simple_func.const_mul_eq_map MeasureTheory.SimpleFunc.const_mul_eq_map
#align measure_theory.simple_func.const_add_eq_map MeasureTheory.SimpleFunc.const_add_eq_map
@[to_additive]
theorem map_mul [Mul β] [Mul γ] {g : β → γ} (hg : ∀ x y, g (x * y) = g x * g y) (f₁ f₂ : α →ₛ β) :
(f₁ * f₂).map g = f₁.map g * f₂.map g :=
ext fun _ => hg _ _
#align measure_theory.simple_func.map_mul MeasureTheory.SimpleFunc.map_mul
#align measure_theory.simple_func.map_add MeasureTheory.SimpleFunc.map_add
variable {K : Type*}
@[to_additive]
instance instSMul [SMul K β] : SMul K (α →ₛ β) :=
⟨fun k f => f.map (k • ·)⟩
#align measure_theory.simple_func.has_smul MeasureTheory.SimpleFunc.instSMul
@[to_additive (attr := simp)]
theorem coe_smul [SMul K β] (c : K) (f : α →ₛ β) : ⇑(c • f) = c • ⇑f :=
rfl
#align measure_theory.simple_func.coe_smul MeasureTheory.SimpleFunc.coe_smul
@[to_additive (attr := simp)]
theorem smul_apply [SMul K β] (k : K) (f : α →ₛ β) (a : α) : (k • f) a = k • f a :=
rfl
#align measure_theory.simple_func.smul_apply MeasureTheory.SimpleFunc.smul_apply
instance hasNatSMul [AddMonoid β] : SMul ℕ (α →ₛ β) := inferInstance
@[to_additive existing hasNatSMul]
instance hasNatPow [Monoid β] : Pow (α →ₛ β) ℕ :=
⟨fun f n => f.map (· ^ n)⟩
#align measure_theory.simple_func.has_nat_pow MeasureTheory.SimpleFunc.hasNatPow
@[simp]
theorem coe_pow [Monoid β] (f : α →ₛ β) (n : ℕ) : ⇑(f ^ n) = (⇑f) ^ n :=
rfl
#align measure_theory.simple_func.coe_pow MeasureTheory.SimpleFunc.coe_pow
theorem pow_apply [Monoid β] (n : ℕ) (f : α →ₛ β) (a : α) : (f ^ n) a = f a ^ n :=
rfl
#align measure_theory.simple_func.pow_apply MeasureTheory.SimpleFunc.pow_apply
instance hasIntPow [DivInvMonoid β] : Pow (α →ₛ β) ℤ :=
⟨fun f n => f.map (· ^ n)⟩
#align measure_theory.simple_func.has_int_pow MeasureTheory.SimpleFunc.hasIntPow
@[simp]
theorem coe_zpow [DivInvMonoid β] (f : α →ₛ β) (z : ℤ) : ⇑(f ^ z) = (⇑f) ^ z :=
rfl
#align measure_theory.simple_func.coe_zpow MeasureTheory.SimpleFunc.coe_zpow
theorem zpow_apply [DivInvMonoid β] (z : ℤ) (f : α →ₛ β) (a : α) : (f ^ z) a = f a ^ z :=
rfl
#align measure_theory.simple_func.zpow_apply MeasureTheory.SimpleFunc.zpow_apply
-- TODO: work out how to generate these instances with `to_additive`, which gets confused by the
-- argument order swap between `coe_smul` and `coe_pow`.
section Additive
instance instAddMonoid [AddMonoid β] : AddMonoid (α →ₛ β) :=
Function.Injective.addMonoid (fun f => show α → β from f) coe_injective coe_zero coe_add
fun _ _ => coe_smul _ _
#align measure_theory.simple_func.add_monoid MeasureTheory.SimpleFunc.instAddMonoid
instance instAddCommMonoid [AddCommMonoid β] : AddCommMonoid (α →ₛ β) :=
Function.Injective.addCommMonoid (fun f => show α → β from f) coe_injective coe_zero coe_add
fun _ _ => coe_smul _ _
#align measure_theory.simple_func.add_comm_monoid MeasureTheory.SimpleFunc.instAddCommMonoid
instance instAddGroup [AddGroup β] : AddGroup (α →ₛ β) :=
Function.Injective.addGroup (fun f => show α → β from f) coe_injective coe_zero coe_add coe_neg
coe_sub (fun _ _ => coe_smul _ _) fun _ _ => coe_smul _ _
#align measure_theory.simple_func.add_group MeasureTheory.SimpleFunc.instAddGroup
instance instAddCommGroup [AddCommGroup β] : AddCommGroup (α →ₛ β) :=
Function.Injective.addCommGroup (fun f => show α → β from f) coe_injective coe_zero coe_add
coe_neg coe_sub (fun _ _ => coe_smul _ _) fun _ _ => coe_smul _ _
#align measure_theory.simple_func.add_comm_group MeasureTheory.SimpleFunc.instAddCommGroup
end Additive
@[to_additive existing]
instance instMonoid [Monoid β] : Monoid (α →ₛ β) :=
Function.Injective.monoid (fun f => show α → β from f) coe_injective coe_one coe_mul coe_pow
#align measure_theory.simple_func.monoid MeasureTheory.SimpleFunc.instMonoid
@[to_additive existing]
instance instCommMonoid [CommMonoid β] : CommMonoid (α →ₛ β) :=
Function.Injective.commMonoid (fun f => show α → β from f) coe_injective coe_one coe_mul coe_pow
#align measure_theory.simple_func.comm_monoid MeasureTheory.SimpleFunc.instCommMonoid
@[to_additive existing]
instance instGroup [Group β] : Group (α →ₛ β) :=
Function.Injective.group (fun f => show α → β from f) coe_injective coe_one coe_mul coe_inv
coe_div coe_pow coe_zpow
#align measure_theory.simple_func.group MeasureTheory.SimpleFunc.instGroup
@[to_additive existing]
instance instCommGroup [CommGroup β] : CommGroup (α →ₛ β) :=
Function.Injective.commGroup (fun f => show α → β from f) coe_injective coe_one coe_mul coe_inv
coe_div coe_pow coe_zpow
#align measure_theory.simple_func.comm_group MeasureTheory.SimpleFunc.instCommGroup
instance instModule [Semiring K] [AddCommMonoid β] [Module K β] : Module K (α →ₛ β) :=
Function.Injective.module K ⟨⟨fun f => show α → β from f, coe_zero⟩, coe_add⟩
coe_injective coe_smul
#align measure_theory.simple_func.module MeasureTheory.SimpleFunc.instModule
theorem smul_eq_map [SMul K β] (k : K) (f : α →ₛ β) : k • f = f.map (k • ·) :=
rfl
#align measure_theory.simple_func.smul_eq_map MeasureTheory.SimpleFunc.smul_eq_map
instance instPreorder [Preorder β] : Preorder (α →ₛ β) :=
{ SimpleFunc.instLE with
le_refl := fun f a => le_rfl
le_trans := fun f g h hfg hgh a => le_trans (hfg _) (hgh a) }
#align measure_theory.simple_func.preorder MeasureTheory.SimpleFunc.instPreorder
instance instPartialOrder [PartialOrder β] : PartialOrder (α →ₛ β) :=
{ SimpleFunc.instPreorder with
le_antisymm := fun _f _g hfg hgf => ext fun a => le_antisymm (hfg a) (hgf a) }
#align measure_theory.simple_func.partial_order MeasureTheory.SimpleFunc.instPartialOrder
instance instOrderBot [LE β] [OrderBot β] : OrderBot (α →ₛ β) where
bot := const α ⊥
bot_le _ _ := bot_le
#align measure_theory.simple_func.order_bot MeasureTheory.SimpleFunc.instOrderBot
instance instOrderTop [LE β] [OrderTop β] : OrderTop (α →ₛ β) where
top := const α ⊤
le_top _ _ := le_top
#align measure_theory.simple_func.order_top MeasureTheory.SimpleFunc.instOrderTop
instance instSemilatticeInf [SemilatticeInf β] : SemilatticeInf (α →ₛ β) :=
{ SimpleFunc.instPartialOrder with
inf := (· ⊓ ·)
inf_le_left := fun _ _ _ => inf_le_left
inf_le_right := fun _ _ _ => inf_le_right
le_inf := fun _f _g _h hfh hgh a => le_inf (hfh a) (hgh a) }
#align measure_theory.simple_func.semilattice_inf MeasureTheory.SimpleFunc.instSemilatticeInf
instance instSemilatticeSup [SemilatticeSup β] : SemilatticeSup (α →ₛ β) :=
{ SimpleFunc.instPartialOrder with
sup := (· ⊔ ·)
le_sup_left := fun _ _ _ => le_sup_left
le_sup_right := fun _ _ _ => le_sup_right
sup_le := fun _f _g _h hfh hgh a => sup_le (hfh a) (hgh a) }
#align measure_theory.simple_func.semilattice_sup MeasureTheory.SimpleFunc.instSemilatticeSup
instance instLattice [Lattice β] : Lattice (α →ₛ β) :=
{ SimpleFunc.instSemilatticeSup, SimpleFunc.instSemilatticeInf with }
#align measure_theory.simple_func.lattice MeasureTheory.SimpleFunc.instLattice
instance instBoundedOrder [LE β] [BoundedOrder β] : BoundedOrder (α →ₛ β) :=
{ SimpleFunc.instOrderBot, SimpleFunc.instOrderTop with }
#align measure_theory.simple_func.bounded_order MeasureTheory.SimpleFunc.instBoundedOrder
theorem finset_sup_apply [SemilatticeSup β] [OrderBot β] {f : γ → α →ₛ β} (s : Finset γ) (a : α) :
s.sup f a = s.sup fun c => f c a := by
refine Finset.induction_on s rfl ?_
intro a s _ ih
rw [Finset.sup_insert, Finset.sup_insert, sup_apply, ih]
#align measure_theory.simple_func.finset_sup_apply MeasureTheory.SimpleFunc.finset_sup_apply
section Restrict
variable [Zero β]
/-- Restrict a simple function `f : α →ₛ β` to a set `s`. If `s` is measurable,
then `f.restrict s a = if a ∈ s then f a else 0`, otherwise `f.restrict s = const α 0`. -/
def restrict (f : α →ₛ β) (s : Set α) : α →ₛ β :=
if hs : MeasurableSet s then piecewise s hs f 0 else 0
#align measure_theory.simple_func.restrict MeasureTheory.SimpleFunc.restrict
theorem restrict_of_not_measurable {f : α →ₛ β} {s : Set α} (hs : ¬MeasurableSet s) :
restrict f s = 0 :=
dif_neg hs
#align measure_theory.simple_func.restrict_of_not_measurable MeasureTheory.SimpleFunc.restrict_of_not_measurable
@[simp]
theorem coe_restrict (f : α →ₛ β) {s : Set α} (hs : MeasurableSet s) :
⇑(restrict f s) = indicator s f := by
rw [restrict, dif_pos hs, coe_piecewise, coe_zero, piecewise_eq_indicator]
#align measure_theory.simple_func.coe_restrict MeasureTheory.SimpleFunc.coe_restrict
@[simp]
theorem restrict_univ (f : α →ₛ β) : restrict f univ = f := by simp [restrict]
#align measure_theory.simple_func.restrict_univ MeasureTheory.SimpleFunc.restrict_univ
@[simp]
theorem restrict_empty (f : α →ₛ β) : restrict f ∅ = 0 := by simp [restrict]
#align measure_theory.simple_func.restrict_empty MeasureTheory.SimpleFunc.restrict_empty
theorem map_restrict_of_zero [Zero γ] {g : β → γ} (hg : g 0 = 0) (f : α →ₛ β) (s : Set α) :
(f.restrict s).map g = (f.map g).restrict s :=
ext fun x =>
if hs : MeasurableSet s then by simp [hs, Set.indicator_comp_of_zero hg]
else by simp [restrict_of_not_measurable hs, hg]
#align measure_theory.simple_func.map_restrict_of_zero MeasureTheory.SimpleFunc.map_restrict_of_zero
theorem map_coe_ennreal_restrict (f : α →ₛ ℝ≥0) (s : Set α) :
(f.restrict s).map ((↑) : ℝ≥0 → ℝ≥0∞) = (f.map (↑)).restrict s :=
map_restrict_of_zero ENNReal.coe_zero _ _
#align measure_theory.simple_func.map_coe_ennreal_restrict MeasureTheory.SimpleFunc.map_coe_ennreal_restrict
theorem map_coe_nnreal_restrict (f : α →ₛ ℝ≥0) (s : Set α) :
(f.restrict s).map ((↑) : ℝ≥0 → ℝ) = (f.map (↑)).restrict s :=
map_restrict_of_zero NNReal.coe_zero _ _
#align measure_theory.simple_func.map_coe_nnreal_restrict MeasureTheory.SimpleFunc.map_coe_nnreal_restrict
theorem restrict_apply (f : α →ₛ β) {s : Set α} (hs : MeasurableSet s) (a) :
restrict f s a = indicator s f a := by simp only [f.coe_restrict hs]
#align measure_theory.simple_func.restrict_apply MeasureTheory.SimpleFunc.restrict_apply
theorem restrict_preimage (f : α →ₛ β) {s : Set α} (hs : MeasurableSet s) {t : Set β}
(ht : (0 : β) ∉ t) : restrict f s ⁻¹' t = s ∩ f ⁻¹' t := by
simp [hs, indicator_preimage_of_not_mem _ _ ht, inter_comm]
#align measure_theory.simple_func.restrict_preimage MeasureTheory.SimpleFunc.restrict_preimage
theorem restrict_preimage_singleton (f : α →ₛ β) {s : Set α} (hs : MeasurableSet s) {r : β}
(hr : r ≠ 0) : restrict f s ⁻¹' {r} = s ∩ f ⁻¹' {r} :=
f.restrict_preimage hs hr.symm
#align measure_theory.simple_func.restrict_preimage_singleton MeasureTheory.SimpleFunc.restrict_preimage_singleton
theorem mem_restrict_range {r : β} {s : Set α} {f : α →ₛ β} (hs : MeasurableSet s) :
r ∈ (restrict f s).range ↔ r = 0 ∧ s ≠ univ ∨ r ∈ f '' s := by
rw [← Finset.mem_coe, coe_range, coe_restrict _ hs, mem_range_indicator]
#align measure_theory.simple_func.mem_restrict_range MeasureTheory.SimpleFunc.mem_restrict_range
theorem mem_image_of_mem_range_restrict {r : β} {s : Set α} {f : α →ₛ β}
(hr : r ∈ (restrict f s).range) (h0 : r ≠ 0) : r ∈ f '' s :=
if hs : MeasurableSet s then by simpa [mem_restrict_range hs, h0, -mem_range] using hr
else by
rw [restrict_of_not_measurable hs] at hr
exact (h0 <| eq_zero_of_mem_range_zero hr).elim
#align measure_theory.simple_func.mem_image_of_mem_range_restrict MeasureTheory.SimpleFunc.mem_image_of_mem_range_restrict
@[mono]
theorem restrict_mono [Preorder β] (s : Set α) {f g : α →ₛ β} (H : f ≤ g) :
f.restrict s ≤ g.restrict s :=
if hs : MeasurableSet s then fun x => by
simp only [coe_restrict _ hs, indicator_le_indicator (H x)]
else by simp only [restrict_of_not_measurable hs, le_refl]
#align measure_theory.simple_func.restrict_mono MeasureTheory.SimpleFunc.restrict_mono
end Restrict
section Approx
section
variable [SemilatticeSup β] [OrderBot β] [Zero β]
/-- Fix a sequence `i : ℕ → β`. Given a function `α → β`, its `n`-th approximation
by simple functions is defined so that in case `β = ℝ≥0∞` it sends each `a` to the supremum
of the set `{i k | k ≤ n ∧ i k ≤ f a}`, see `approx_apply` and `iSup_approx_apply` for details. -/
def approx (i : ℕ → β) (f : α → β) (n : ℕ) : α →ₛ β :=
(Finset.range n).sup fun k => restrict (const α (i k)) { a : α | i k ≤ f a }
#align measure_theory.simple_func.approx MeasureTheory.SimpleFunc.approx
theorem approx_apply [TopologicalSpace β] [OrderClosedTopology β] [MeasurableSpace β]
[OpensMeasurableSpace β] {i : ℕ → β} {f : α → β} {n : ℕ} (a : α) (hf : Measurable f) :
(approx i f n : α →ₛ β) a = (Finset.range n).sup fun k => if i k ≤ f a then i k else 0 := by
dsimp only [approx]
rw [finset_sup_apply]
congr
funext k
rw [restrict_apply]
· simp only [coe_const, mem_setOf_eq, indicator_apply, Function.const_apply]
· exact hf measurableSet_Ici
#align measure_theory.simple_func.approx_apply MeasureTheory.SimpleFunc.approx_apply
theorem monotone_approx (i : ℕ → β) (f : α → β) : Monotone (approx i f) := fun _ _ h =>
Finset.sup_mono <| Finset.range_subset.2 h
#align measure_theory.simple_func.monotone_approx MeasureTheory.SimpleFunc.monotone_approx
theorem approx_comp [TopologicalSpace β] [OrderClosedTopology β] [MeasurableSpace β]
[OpensMeasurableSpace β] [MeasurableSpace γ] {i : ℕ → β} {f : γ → β} {g : α → γ} {n : ℕ} (a : α)
(hf : Measurable f) (hg : Measurable g) :
(approx i (f ∘ g) n : α →ₛ β) a = (approx i f n : γ →ₛ β) (g a) := by
rw [approx_apply _ hf, approx_apply _ (hf.comp hg), Function.comp_apply]
#align measure_theory.simple_func.approx_comp MeasureTheory.SimpleFunc.approx_comp
end
| Mathlib/MeasureTheory/Function/SimpleFunc.lean | 857 | 870 | theorem iSup_approx_apply [TopologicalSpace β] [CompleteLattice β] [OrderClosedTopology β] [Zero β]
[MeasurableSpace β] [OpensMeasurableSpace β] (i : ℕ → β) (f : α → β) (a : α) (hf : Measurable f)
(h_zero : (0 : β) = ⊥) : ⨆ n, (approx i f n : α →ₛ β) a = ⨆ (k) (_ : i k ≤ f a), i k := by |
refine le_antisymm (iSup_le fun n => ?_) (iSup_le fun k => iSup_le fun hk => ?_)
· rw [approx_apply a hf, h_zero]
refine Finset.sup_le fun k _ => ?_
split_ifs with h
· exact le_iSup_of_le k (le_iSup (fun _ : i k ≤ f a => i k) h)
· exact bot_le
· refine le_iSup_of_le (k + 1) ?_
rw [approx_apply a hf]
have : k ∈ Finset.range (k + 1) := Finset.mem_range.2 (Nat.lt_succ_self _)
refine le_trans (le_of_eq ?_) (Finset.le_sup this)
rw [if_pos hk]
|
/-
Copyright (c) 2022 Yaël Dillies, Bhavik Mehta. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies, Bhavik Mehta
-/
import Mathlib.Algebra.BigOperators.Group.Finset
import Mathlib.Order.SupIndep
import Mathlib.Order.Atoms
#align_import order.partition.finpartition from "leanprover-community/mathlib"@"d6fad0e5bf2d6f48da9175d25c3dc5706b3834ce"
/-!
# Finite partitions
In this file, we define finite partitions. A finpartition of `a : α` is a finite set of pairwise
disjoint parts `parts : Finset α` which does not contain `⊥` and whose supremum is `a`.
Finpartitions of a finset are at the heart of Szemerédi's regularity lemma. They are also studied
purely order theoretically in Sperner theory.
## Constructions
We provide many ways to build finpartitions:
* `Finpartition.ofErase`: Builds a finpartition by erasing `⊥` for you.
* `Finpartition.ofSubset`: Builds a finpartition from a subset of the parts of a previous
finpartition.
* `Finpartition.empty`: The empty finpartition of `⊥`.
* `Finpartition.indiscrete`: The indiscrete, aka trivial, aka pure, finpartition made of a single
part.
* `Finpartition.discrete`: The discrete finpartition of `s : Finset α` made of singletons.
* `Finpartition.bind`: Puts together the finpartitions of the parts of a finpartition into a new
finpartition.
* `Finpartition.ofSetoid`: With `Fintype α`, constructs the finpartition of `univ : Finset α`
induced by the equivalence classes of `s : Setoid α`.
* `Finpartition.atomise`: Makes a finpartition of `s : Finset α` by breaking `s` along all finsets
in `F : Finset (Finset α)`. Two elements of `s` belong to the same part iff they belong to the
same elements of `F`.
`Finpartition.indiscrete` and `Finpartition.bind` together form the monadic structure of
`Finpartition`.
## Implementation notes
Forbidding `⊥` as a part follows mathematical tradition and is a pragmatic choice concerning
operations on `Finpartition`. Not caring about `⊥` being a part or not breaks extensionality (it's
not because the parts of `P` and the parts of `Q` have the same elements that `P = Q`). Enforcing
`⊥` to be a part makes `Finpartition.bind` uglier and doesn't rid us of the need of
`Finpartition.ofErase`.
## TODO
The order is the wrong way around to make `Finpartition a` a graded order. Is it bad to depart from
the literature and turn the order around?
-/
open Finset Function
variable {α : Type*}
/-- A finite partition of `a : α` is a pairwise disjoint finite set of elements whose supremum is
`a`. We forbid `⊥` as a part. -/
@[ext]
structure Finpartition [Lattice α] [OrderBot α] (a : α) where
-- Porting note: Docstrings added
/-- The elements of the finite partition of `a` -/
parts : Finset α
/-- The partition is supremum-independent -/
supIndep : parts.SupIndep id
/-- The supremum of the partition is `a` -/
sup_parts : parts.sup id = a
/-- No element of the partition is bottom-/
not_bot_mem : ⊥ ∉ parts
deriving DecidableEq
#align finpartition Finpartition
#align finpartition.parts Finpartition.parts
#align finpartition.sup_indep Finpartition.supIndep
#align finpartition.sup_parts Finpartition.sup_parts
#align finpartition.not_bot_mem Finpartition.not_bot_mem
-- Porting note: attribute [protected] doesn't work
-- attribute [protected] Finpartition.supIndep
namespace Finpartition
section Lattice
variable [Lattice α] [OrderBot α]
/-- A `Finpartition` constructor which does not insist on `⊥` not being a part. -/
@[simps]
def ofErase [DecidableEq α] {a : α} (parts : Finset α) (sup_indep : parts.SupIndep id)
(sup_parts : parts.sup id = a) : Finpartition a where
parts := parts.erase ⊥
supIndep := sup_indep.subset (erase_subset _ _)
sup_parts := (sup_erase_bot _).trans sup_parts
not_bot_mem := not_mem_erase _ _
#align finpartition.of_erase Finpartition.ofErase
/-- A `Finpartition` constructor from a bigger existing finpartition. -/
@[simps]
def ofSubset {a b : α} (P : Finpartition a) {parts : Finset α} (subset : parts ⊆ P.parts)
(sup_parts : parts.sup id = b) : Finpartition b :=
{ parts := parts
supIndep := P.supIndep.subset subset
sup_parts := sup_parts
not_bot_mem := fun h ↦ P.not_bot_mem (subset h) }
#align finpartition.of_subset Finpartition.ofSubset
/-- Changes the type of a finpartition to an equal one. -/
@[simps]
def copy {a b : α} (P : Finpartition a) (h : a = b) : Finpartition b where
parts := P.parts
supIndep := P.supIndep
sup_parts := h ▸ P.sup_parts
not_bot_mem := P.not_bot_mem
#align finpartition.copy Finpartition.copy
/-- Transfer a finpartition over an order isomorphism. -/
def map {β : Type*} [Lattice β] [OrderBot β] {a : α} (e : α ≃o β) (P : Finpartition a) :
Finpartition (e a) where
parts := P.parts.map e
supIndep u hu _ hb hbu _ hx hxu := by
rw [← map_symm_subset] at hu
simp only [mem_map_equiv] at hb
have := P.supIndep hu hb (by simp [hbu]) (map_rel e.symm hx) ?_
· rw [← e.symm.map_bot] at this
exact e.symm.map_rel_iff.mp this
· convert e.symm.map_rel_iff.mpr hxu
rw [map_finset_sup, sup_map]
rfl
sup_parts := by simp [← P.sup_parts]
not_bot_mem := by
rw [mem_map_equiv]
convert P.not_bot_mem
exact e.symm.map_bot
@[simp]
theorem parts_map {β : Type*} [Lattice β] [OrderBot β] {a : α} {e : α ≃o β} {P : Finpartition a} :
(P.map e).parts = P.parts.map e := rfl
variable (α)
/-- The empty finpartition. -/
@[simps]
protected def empty : Finpartition (⊥ : α) where
parts := ∅
supIndep := supIndep_empty _
sup_parts := Finset.sup_empty
not_bot_mem := not_mem_empty ⊥
#align finpartition.empty Finpartition.empty
instance : Inhabited (Finpartition (⊥ : α)) :=
⟨Finpartition.empty α⟩
@[simp]
theorem default_eq_empty : (default : Finpartition (⊥ : α)) = Finpartition.empty α :=
rfl
#align finpartition.default_eq_empty Finpartition.default_eq_empty
variable {α} {a : α}
/-- The finpartition in one part, aka indiscrete finpartition. -/
@[simps]
def indiscrete (ha : a ≠ ⊥) : Finpartition a where
parts := {a}
supIndep := supIndep_singleton _ _
sup_parts := Finset.sup_singleton
not_bot_mem h := ha (mem_singleton.1 h).symm
#align finpartition.indiscrete Finpartition.indiscrete
variable (P : Finpartition a)
protected theorem le {b : α} (hb : b ∈ P.parts) : b ≤ a :=
(le_sup hb).trans P.sup_parts.le
#align finpartition.le Finpartition.le
theorem ne_bot {b : α} (hb : b ∈ P.parts) : b ≠ ⊥ := by
intro h
refine P.not_bot_mem (?_)
rw [h] at hb
exact hb
#align finpartition.ne_bot Finpartition.ne_bot
protected theorem disjoint : (P.parts : Set α).PairwiseDisjoint id :=
P.supIndep.pairwiseDisjoint
#align finpartition.disjoint Finpartition.disjoint
variable {P}
theorem parts_eq_empty_iff : P.parts = ∅ ↔ a = ⊥ := by
simp_rw [← P.sup_parts]
refine ⟨fun h ↦ ?_, fun h ↦ eq_empty_iff_forall_not_mem.2 fun b hb ↦ P.not_bot_mem ?_⟩
· rw [h]
exact Finset.sup_empty
· rwa [← le_bot_iff.1 ((le_sup hb).trans h.le)]
#align finpartition.parts_eq_empty_iff Finpartition.parts_eq_empty_iff
theorem parts_nonempty_iff : P.parts.Nonempty ↔ a ≠ ⊥ := by
rw [nonempty_iff_ne_empty, not_iff_not, parts_eq_empty_iff]
#align finpartition.parts_nonempty_iff Finpartition.parts_nonempty_iff
theorem parts_nonempty (P : Finpartition a) (ha : a ≠ ⊥) : P.parts.Nonempty :=
parts_nonempty_iff.2 ha
#align finpartition.parts_nonempty Finpartition.parts_nonempty
instance : Unique (Finpartition (⊥ : α)) :=
{ (inferInstance : Inhabited (Finpartition (⊥ : α))) with
uniq := fun P ↦ by
ext a
exact iff_of_false (fun h ↦ P.ne_bot h <| le_bot_iff.1 <| P.le h) (not_mem_empty a) }
-- See note [reducible non instances]
/-- There's a unique partition of an atom. -/
abbrev _root_.IsAtom.uniqueFinpartition (ha : IsAtom a) : Unique (Finpartition a) where
default := indiscrete ha.1
uniq P := by
have h : ∀ b ∈ P.parts, b = a := fun _ hb ↦
(ha.le_iff.mp <| P.le hb).resolve_left (P.ne_bot hb)
ext b
refine Iff.trans ⟨h b, ?_⟩ mem_singleton.symm
rintro rfl
obtain ⟨c, hc⟩ := P.parts_nonempty ha.1
simp_rw [← h c hc]
exact hc
#align is_atom.unique_finpartition IsAtom.uniqueFinpartition
instance [Fintype α] [DecidableEq α] (a : α) : Fintype (Finpartition a) :=
@Fintype.ofSurjective { p : Finset α // p.SupIndep id ∧ p.sup id = a ∧ ⊥ ∉ p } (Finpartition a) _
(Subtype.fintype _) (fun i ↦ ⟨i.1, i.2.1, i.2.2.1, i.2.2.2⟩) fun ⟨_, y, z, w⟩ ↦
⟨⟨_, y, z, w⟩, rfl⟩
/-! ### Refinement order -/
section Order
/-- We say that `P ≤ Q` if `P` refines `Q`: each part of `P` is less than some part of `Q`. -/
instance : LE (Finpartition a) :=
⟨fun P Q ↦ ∀ ⦃b⦄, b ∈ P.parts → ∃ c ∈ Q.parts, b ≤ c⟩
instance : PartialOrder (Finpartition a) :=
{ (inferInstance : LE (Finpartition a)) with
le_refl := fun P b hb ↦ ⟨b, hb, le_rfl⟩
le_trans := fun P Q R hPQ hQR b hb ↦ by
obtain ⟨c, hc, hbc⟩ := hPQ hb
obtain ⟨d, hd, hcd⟩ := hQR hc
exact ⟨d, hd, hbc.trans hcd⟩
le_antisymm := fun P Q hPQ hQP ↦ by
ext b
refine ⟨fun hb ↦ ?_, fun hb ↦ ?_⟩
· obtain ⟨c, hc, hbc⟩ := hPQ hb
obtain ⟨d, hd, hcd⟩ := hQP hc
rwa [hbc.antisymm]
rwa [P.disjoint.eq_of_le hb hd (P.ne_bot hb) (hbc.trans hcd)]
· obtain ⟨c, hc, hbc⟩ := hQP hb
obtain ⟨d, hd, hcd⟩ := hPQ hc
rwa [hbc.antisymm]
rwa [Q.disjoint.eq_of_le hb hd (Q.ne_bot hb) (hbc.trans hcd)] }
instance [Decidable (a = ⊥)] : OrderTop (Finpartition a) where
top := if ha : a = ⊥ then (Finpartition.empty α).copy ha.symm else indiscrete ha
le_top P := by
split_ifs with h
· intro x hx
simpa [h, P.ne_bot hx] using P.le hx
· exact fun b hb ↦ ⟨a, mem_singleton_self _, P.le hb⟩
theorem parts_top_subset (a : α) [Decidable (a = ⊥)] : (⊤ : Finpartition a).parts ⊆ {a} := by
intro b hb
have hb : b ∈ Finpartition.parts (dite _ _ _) := hb
split_ifs at hb
· simp only [copy_parts, empty_parts, not_mem_empty] at hb
· exact hb
#align finpartition.parts_top_subset Finpartition.parts_top_subset
theorem parts_top_subsingleton (a : α) [Decidable (a = ⊥)] :
((⊤ : Finpartition a).parts : Set α).Subsingleton :=
Set.subsingleton_of_subset_singleton fun _ hb ↦ mem_singleton.1 <| parts_top_subset _ hb
#align finpartition.parts_top_subsingleton Finpartition.parts_top_subsingleton
end Order
end Lattice
section DistribLattice
variable [DistribLattice α] [OrderBot α]
section Inf
variable [DecidableEq α] {a b c : α}
instance : Inf (Finpartition a) :=
⟨fun P Q ↦
ofErase ((P.parts ×ˢ Q.parts).image fun bc ↦ bc.1 ⊓ bc.2)
(by
rw [supIndep_iff_disjoint_erase]
simp only [mem_image, and_imp, exists_prop, forall_exists_index, id, Prod.exists,
mem_product, Finset.disjoint_sup_right, mem_erase, Ne]
rintro _ x₁ y₁ hx₁ hy₁ rfl _ h x₂ y₂ hx₂ hy₂ rfl
rcases eq_or_ne x₁ x₂ with (rfl | xdiff)
· refine Disjoint.mono inf_le_right inf_le_right (Q.disjoint hy₁ hy₂ ?_)
intro t
simp [t] at h
exact Disjoint.mono inf_le_left inf_le_left (P.disjoint hx₁ hx₂ xdiff))
(by
rw [sup_image, id_comp, sup_product_left]
trans P.parts.sup id ⊓ Q.parts.sup id
· simp_rw [Finset.sup_inf_distrib_right, Finset.sup_inf_distrib_left]
rfl
· rw [P.sup_parts, Q.sup_parts, inf_idem])⟩
@[simp]
theorem parts_inf (P Q : Finpartition a) :
(P ⊓ Q).parts = ((P.parts ×ˢ Q.parts).image fun bc : α × α ↦ bc.1 ⊓ bc.2).erase ⊥ :=
rfl
#align finpartition.parts_inf Finpartition.parts_inf
instance : SemilatticeInf (Finpartition a) :=
{ (inferInstance : PartialOrder (Finpartition a)),
(inferInstance : Inf (Finpartition a)) with
inf_le_left := fun P Q b hb ↦ by
obtain ⟨c, hc, rfl⟩ := mem_image.1 (mem_of_mem_erase hb)
rw [mem_product] at hc
exact ⟨c.1, hc.1, inf_le_left⟩
inf_le_right := fun P Q b hb ↦ by
obtain ⟨c, hc, rfl⟩ := mem_image.1 (mem_of_mem_erase hb)
rw [mem_product] at hc
exact ⟨c.2, hc.2, inf_le_right⟩
le_inf := fun P Q R hPQ hPR b hb ↦ by
obtain ⟨c, hc, hbc⟩ := hPQ hb
obtain ⟨d, hd, hbd⟩ := hPR hb
have h := _root_.le_inf hbc hbd
refine
⟨c ⊓ d,
mem_erase_of_ne_of_mem (ne_bot_of_le_ne_bot (P.ne_bot hb) h)
(mem_image.2 ⟨(c, d), mem_product.2 ⟨hc, hd⟩, rfl⟩),
h⟩ }
end Inf
theorem exists_le_of_le {a b : α} {P Q : Finpartition a} (h : P ≤ Q) (hb : b ∈ Q.parts) :
∃ c ∈ P.parts, c ≤ b := by
by_contra H
refine Q.ne_bot hb (disjoint_self.1 <| Disjoint.mono_right (Q.le hb) ?_)
rw [← P.sup_parts, Finset.disjoint_sup_right]
rintro c hc
obtain ⟨d, hd, hcd⟩ := h hc
refine (Q.disjoint hb hd ?_).mono_right hcd
rintro rfl
simp only [not_exists, not_and] at H
exact H _ hc hcd
#align finpartition.exists_le_of_le Finpartition.exists_le_of_le
theorem card_mono {a : α} {P Q : Finpartition a} (h : P ≤ Q) : Q.parts.card ≤ P.parts.card := by
classical
have : ∀ b ∈ Q.parts, ∃ c ∈ P.parts, c ≤ b := fun b ↦ exists_le_of_le h
choose f hP hf using this
rw [← card_attach]
refine card_le_card_of_inj_on (fun b ↦ f _ b.2) (fun b _ ↦ hP _ b.2) fun b _ c _ h ↦ ?_
exact
Subtype.coe_injective
(Q.disjoint.elim b.2 c.2 fun H ↦
P.ne_bot (hP _ b.2) <| disjoint_self.1 <| H.mono (hf _ b.2) <| h.le.trans <| hf _ c.2)
#align finpartition.card_mono Finpartition.card_mono
variable [DecidableEq α] {a b c : α}
section Bind
variable {P : Finpartition a} {Q : ∀ i ∈ P.parts, Finpartition i}
/-- Given a finpartition `P` of `a` and finpartitions of each part of `P`, this yields the
finpartition of `a` obtained by juxtaposing all the subpartitions. -/
@[simps]
def bind (P : Finpartition a) (Q : ∀ i ∈ P.parts, Finpartition i) : Finpartition a where
parts := P.parts.attach.biUnion fun i ↦ (Q i.1 i.2).parts
supIndep := by
rw [supIndep_iff_pairwiseDisjoint]
rintro a ha b hb h
rw [Finset.mem_coe, Finset.mem_biUnion] at ha hb
obtain ⟨⟨A, hA⟩, -, ha⟩ := ha
obtain ⟨⟨B, hB⟩, -, hb⟩ := hb
obtain rfl | hAB := eq_or_ne A B
· exact (Q A hA).disjoint ha hb h
· exact (P.disjoint hA hB hAB).mono ((Q A hA).le ha) ((Q B hB).le hb)
sup_parts := by
simp_rw [sup_biUnion]
trans (sup P.parts id)
· rw [eq_comm, ← Finset.sup_attach]
exact sup_congr rfl fun b _hb ↦ (Q b.1 b.2).sup_parts.symm
· exact P.sup_parts
not_bot_mem h := by
rw [Finset.mem_biUnion] at h
obtain ⟨⟨A, hA⟩, -, h⟩ := h
exact (Q A hA).not_bot_mem h
#align finpartition.bind Finpartition.bind
theorem mem_bind : b ∈ (P.bind Q).parts ↔ ∃ A hA, b ∈ (Q A hA).parts := by
rw [bind, mem_biUnion]
constructor
· rintro ⟨⟨A, hA⟩, -, h⟩
exact ⟨A, hA, h⟩
· rintro ⟨A, hA, h⟩
exact ⟨⟨A, hA⟩, mem_attach _ ⟨A, hA⟩, h⟩
#align finpartition.mem_bind Finpartition.mem_bind
theorem card_bind (Q : ∀ i ∈ P.parts, Finpartition i) :
(P.bind Q).parts.card = ∑ A ∈ P.parts.attach, (Q _ A.2).parts.card := by
apply card_biUnion
rintro ⟨b, hb⟩ - ⟨c, hc⟩ - hbc
rw [Finset.disjoint_left]
rintro d hdb hdc
rw [Ne, Subtype.mk_eq_mk] at hbc
exact
(Q b hb).ne_bot hdb
(eq_bot_iff.2 <|
(le_inf ((Q b hb).le hdb) <| (Q c hc).le hdc).trans <| (P.disjoint hb hc hbc).le_bot)
#align finpartition.card_bind Finpartition.card_bind
end Bind
/-- Adds `b` to a finpartition of `a` to make a finpartition of `a ⊔ b`. -/
@[simps]
def extend (P : Finpartition a) (hb : b ≠ ⊥) (hab : Disjoint a b) (hc : a ⊔ b = c) :
Finpartition c where
parts := insert b P.parts
supIndep := by
rw [supIndep_iff_pairwiseDisjoint, coe_insert]
exact P.disjoint.insert fun d hd _ ↦ hab.symm.mono_right <| P.le hd
sup_parts := by rwa [sup_insert, P.sup_parts, id, _root_.sup_comm]
not_bot_mem h := (mem_insert.1 h).elim hb.symm P.not_bot_mem
#align finpartition.extend Finpartition.extend
theorem card_extend (P : Finpartition a) (b c : α) {hb : b ≠ ⊥} {hab : Disjoint a b}
{hc : a ⊔ b = c} : (P.extend hb hab hc).parts.card = P.parts.card + 1 :=
card_insert_of_not_mem fun h ↦ hb <| hab.symm.eq_bot_of_le <| P.le h
#align finpartition.card_extend Finpartition.card_extend
end DistribLattice
section GeneralizedBooleanAlgebra
variable [GeneralizedBooleanAlgebra α] [DecidableEq α] {a b c : α} (P : Finpartition a)
/-- Restricts a finpartition to avoid a given element. -/
@[simps!]
def avoid (b : α) : Finpartition (a \ b) :=
ofErase
(P.parts.image (· \ b))
(P.disjoint.image_finset_of_le fun a ↦ sdiff_le).supIndep
(by rw [sup_image, id_comp, Finset.sup_sdiff_right, ← Function.id_def, P.sup_parts])
#align finpartition.avoid Finpartition.avoid
@[simp]
| Mathlib/Order/Partition/Finpartition.lean | 457 | 462 | theorem mem_avoid : c ∈ (P.avoid b).parts ↔ ∃ d ∈ P.parts, ¬d ≤ b ∧ d \ b = c := by |
simp only [avoid, ofErase, mem_erase, Ne, mem_image, exists_prop, ← exists_and_left,
@and_left_comm (c ≠ ⊥)]
refine exists_congr fun d ↦ and_congr_right' <| and_congr_left ?_
rintro rfl
rw [sdiff_eq_bot_iff]
|
/-
Copyright (c) 2015 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura, Jeremy Avigad, Minchao Wu, Mario Carneiro
-/
import Mathlib.Data.Finset.Attr
import Mathlib.Data.Multiset.FinsetOps
import Mathlib.Logic.Equiv.Set
import Mathlib.Order.Directed
import Mathlib.Order.Interval.Set.Basic
#align_import data.finset.basic from "leanprover-community/mathlib"@"442a83d738cb208d3600056c489be16900ba701d"
/-!
# Finite sets
Terms of type `Finset α` are one way of talking about finite subsets of `α` in mathlib.
Below, `Finset α` is defined as a structure with 2 fields:
1. `val` is a `Multiset α` of elements;
2. `nodup` is a proof that `val` has no duplicates.
Finsets in Lean are constructive in that they have an underlying `List` that enumerates their
elements. In particular, any function that uses the data of the underlying list cannot depend on its
ordering. This is handled on the `Multiset` level by multiset API, so in most cases one needn't
worry about it explicitly.
Finsets give a basic foundation for defining finite sums and products over types:
1. `∑ i ∈ (s : Finset α), f i`;
2. `∏ i ∈ (s : Finset α), f i`.
Lean refers to these operations as big operators.
More information can be found in `Mathlib.Algebra.BigOperators.Group.Finset`.
Finsets are directly used to define fintypes in Lean.
A `Fintype α` instance for a type `α` consists of a universal `Finset α` containing every term of
`α`, called `univ`. See `Mathlib.Data.Fintype.Basic`.
There is also `univ'`, the noncomputable partner to `univ`,
which is defined to be `α` as a finset if `α` is finite,
and the empty finset otherwise. See `Mathlib.Data.Fintype.Basic`.
`Finset.card`, the size of a finset is defined in `Mathlib.Data.Finset.Card`.
This is then used to define `Fintype.card`, the size of a type.
## Main declarations
### Main definitions
* `Finset`: Defines a type for the finite subsets of `α`.
Constructing a `Finset` requires two pieces of data: `val`, a `Multiset α` of elements,
and `nodup`, a proof that `val` has no duplicates.
* `Finset.instMembershipFinset`: Defines membership `a ∈ (s : Finset α)`.
* `Finset.instCoeTCFinsetSet`: Provides a coercion `s : Finset α` to `s : Set α`.
* `Finset.instCoeSortFinsetType`: Coerce `s : Finset α` to the type of all `x ∈ s`.
* `Finset.induction_on`: Induction on finsets. To prove a proposition about an arbitrary `Finset α`,
it suffices to prove it for the empty finset, and to show that if it holds for some `Finset α`,
then it holds for the finset obtained by inserting a new element.
* `Finset.choose`: Given a proof `h` of existence and uniqueness of a certain element
satisfying a predicate, `choose s h` returns the element of `s` satisfying that predicate.
### Finset constructions
* `Finset.instSingletonFinset`: Denoted by `{a}`; the finset consisting of one element.
* `Finset.empty`: Denoted by `∅`. The finset associated to any type consisting of no elements.
* `Finset.range`: For any `n : ℕ`, `range n` is equal to `{0, 1, ... , n - 1} ⊆ ℕ`.
This convention is consistent with other languages and normalizes `card (range n) = n`.
Beware, `n` is not in `range n`.
* `Finset.attach`: Given `s : Finset α`, `attach s` forms a finset of elements of the subtype
`{a // a ∈ s}`; in other words, it attaches elements to a proof of membership in the set.
### Finsets from functions
* `Finset.filter`: Given a decidable predicate `p : α → Prop`, `s.filter p` is
the finset consisting of those elements in `s` satisfying the predicate `p`.
### The lattice structure on subsets of finsets
There is a natural lattice structure on the subsets of a set.
In Lean, we use lattice notation to talk about things involving unions and intersections. See
`Mathlib.Order.Lattice`. For the lattice structure on finsets, `⊥` is called `bot` with `⊥ = ∅` and
`⊤` is called `top` with `⊤ = univ`.
* `Finset.instHasSubsetFinset`: Lots of API about lattices, otherwise behaves as one would expect.
* `Finset.instUnionFinset`: Defines `s ∪ t` (or `s ⊔ t`) as the union of `s` and `t`.
See `Finset.sup`/`Finset.biUnion` for finite unions.
* `Finset.instInterFinset`: Defines `s ∩ t` (or `s ⊓ t`) as the intersection of `s` and `t`.
See `Finset.inf` for finite intersections.
### Operations on two or more finsets
* `insert` and `Finset.cons`: For any `a : α`, `insert s a` returns `s ∪ {a}`. `cons s a h`
returns the same except that it requires a hypothesis stating that `a` is not already in `s`.
This does not require decidable equality on the type `α`.
* `Finset.instUnionFinset`: see "The lattice structure on subsets of finsets"
* `Finset.instInterFinset`: see "The lattice structure on subsets of finsets"
* `Finset.erase`: For any `a : α`, `erase s a` returns `s` with the element `a` removed.
* `Finset.instSDiffFinset`: Defines the set difference `s \ t` for finsets `s` and `t`.
* `Finset.product`: Given finsets of `α` and `β`, defines finsets of `α × β`.
For arbitrary dependent products, see `Mathlib.Data.Finset.Pi`.
### Predicates on finsets
* `Disjoint`: defined via the lattice structure on finsets; two sets are disjoint if their
intersection is empty.
* `Finset.Nonempty`: A finset is nonempty if it has elements. This is equivalent to saying `s ≠ ∅`.
### Equivalences between finsets
* The `Mathlib.Data.Equiv` files describe a general type of equivalence, so look in there for any
lemmas. There is some API for rewriting sums and products from `s` to `t` given that `s ≃ t`.
TODO: examples
## Tags
finite sets, finset
-/
-- Assert that we define `Finset` without the material on `List.sublists`.
-- Note that we cannot use `List.sublists` itself as that is defined very early.
assert_not_exists List.sublistsLen
assert_not_exists Multiset.Powerset
assert_not_exists CompleteLattice
open Multiset Subtype Nat Function
universe u
variable {α : Type*} {β : Type*} {γ : Type*}
/-- `Finset α` is the type of finite sets of elements of `α`. It is implemented
as a multiset (a list up to permutation) which has no duplicate elements. -/
structure Finset (α : Type*) where
/-- The underlying multiset -/
val : Multiset α
/-- `val` contains no duplicates -/
nodup : Nodup val
#align finset Finset
instance Multiset.canLiftFinset {α} : CanLift (Multiset α) (Finset α) Finset.val Multiset.Nodup :=
⟨fun m hm => ⟨⟨m, hm⟩, rfl⟩⟩
#align multiset.can_lift_finset Multiset.canLiftFinset
namespace Finset
theorem eq_of_veq : ∀ {s t : Finset α}, s.1 = t.1 → s = t
| ⟨s, _⟩, ⟨t, _⟩, h => by cases h; rfl
#align finset.eq_of_veq Finset.eq_of_veq
theorem val_injective : Injective (val : Finset α → Multiset α) := fun _ _ => eq_of_veq
#align finset.val_injective Finset.val_injective
@[simp]
theorem val_inj {s t : Finset α} : s.1 = t.1 ↔ s = t :=
val_injective.eq_iff
#align finset.val_inj Finset.val_inj
@[simp]
theorem dedup_eq_self [DecidableEq α] (s : Finset α) : dedup s.1 = s.1 :=
s.2.dedup
#align finset.dedup_eq_self Finset.dedup_eq_self
instance decidableEq [DecidableEq α] : DecidableEq (Finset α)
| _, _ => decidable_of_iff _ val_inj
#align finset.has_decidable_eq Finset.decidableEq
/-! ### membership -/
instance : Membership α (Finset α) :=
⟨fun a s => a ∈ s.1⟩
theorem mem_def {a : α} {s : Finset α} : a ∈ s ↔ a ∈ s.1 :=
Iff.rfl
#align finset.mem_def Finset.mem_def
@[simp]
theorem mem_val {a : α} {s : Finset α} : a ∈ s.1 ↔ a ∈ s :=
Iff.rfl
#align finset.mem_val Finset.mem_val
@[simp]
theorem mem_mk {a : α} {s nd} : a ∈ @Finset.mk α s nd ↔ a ∈ s :=
Iff.rfl
#align finset.mem_mk Finset.mem_mk
instance decidableMem [_h : DecidableEq α] (a : α) (s : Finset α) : Decidable (a ∈ s) :=
Multiset.decidableMem _ _
#align finset.decidable_mem Finset.decidableMem
@[simp] lemma forall_mem_not_eq {s : Finset α} {a : α} : (∀ b ∈ s, ¬ a = b) ↔ a ∉ s := by aesop
@[simp] lemma forall_mem_not_eq' {s : Finset α} {a : α} : (∀ b ∈ s, ¬ b = a) ↔ a ∉ s := by aesop
/-! ### set coercion -/
-- Porting note (#11445): new definition
/-- Convert a finset to a set in the natural way. -/
@[coe] def toSet (s : Finset α) : Set α :=
{ a | a ∈ s }
/-- Convert a finset to a set in the natural way. -/
instance : CoeTC (Finset α) (Set α) :=
⟨toSet⟩
@[simp, norm_cast]
theorem mem_coe {a : α} {s : Finset α} : a ∈ (s : Set α) ↔ a ∈ (s : Finset α) :=
Iff.rfl
#align finset.mem_coe Finset.mem_coe
@[simp]
theorem setOf_mem {α} {s : Finset α} : { a | a ∈ s } = s :=
rfl
#align finset.set_of_mem Finset.setOf_mem
@[simp]
theorem coe_mem {s : Finset α} (x : (s : Set α)) : ↑x ∈ s :=
x.2
#align finset.coe_mem Finset.coe_mem
-- Porting note (#10618): @[simp] can prove this
theorem mk_coe {s : Finset α} (x : (s : Set α)) {h} : (⟨x, h⟩ : (s : Set α)) = x :=
Subtype.coe_eta _ _
#align finset.mk_coe Finset.mk_coe
instance decidableMem' [DecidableEq α] (a : α) (s : Finset α) : Decidable (a ∈ (s : Set α)) :=
s.decidableMem _
#align finset.decidable_mem' Finset.decidableMem'
/-! ### extensionality -/
theorem ext_iff {s₁ s₂ : Finset α} : s₁ = s₂ ↔ ∀ a, a ∈ s₁ ↔ a ∈ s₂ :=
val_inj.symm.trans <| s₁.nodup.ext s₂.nodup
#align finset.ext_iff Finset.ext_iff
@[ext]
theorem ext {s₁ s₂ : Finset α} : (∀ a, a ∈ s₁ ↔ a ∈ s₂) → s₁ = s₂ :=
ext_iff.2
#align finset.ext Finset.ext
@[simp, norm_cast]
theorem coe_inj {s₁ s₂ : Finset α} : (s₁ : Set α) = s₂ ↔ s₁ = s₂ :=
Set.ext_iff.trans ext_iff.symm
#align finset.coe_inj Finset.coe_inj
theorem coe_injective {α} : Injective ((↑) : Finset α → Set α) := fun _s _t => coe_inj.1
#align finset.coe_injective Finset.coe_injective
/-! ### type coercion -/
/-- Coercion from a finset to the corresponding subtype. -/
instance {α : Type u} : CoeSort (Finset α) (Type u) :=
⟨fun s => { x // x ∈ s }⟩
-- Porting note (#10618): @[simp] can prove this
protected theorem forall_coe {α : Type*} (s : Finset α) (p : s → Prop) :
(∀ x : s, p x) ↔ ∀ (x : α) (h : x ∈ s), p ⟨x, h⟩ :=
Subtype.forall
#align finset.forall_coe Finset.forall_coe
-- Porting note (#10618): @[simp] can prove this
protected theorem exists_coe {α : Type*} (s : Finset α) (p : s → Prop) :
(∃ x : s, p x) ↔ ∃ (x : α) (h : x ∈ s), p ⟨x, h⟩ :=
Subtype.exists
#align finset.exists_coe Finset.exists_coe
instance PiFinsetCoe.canLift (ι : Type*) (α : ι → Type*) [_ne : ∀ i, Nonempty (α i)]
(s : Finset ι) : CanLift (∀ i : s, α i) (∀ i, α i) (fun f i => f i) fun _ => True :=
PiSubtype.canLift ι α (· ∈ s)
#align finset.pi_finset_coe.can_lift Finset.PiFinsetCoe.canLift
instance PiFinsetCoe.canLift' (ι α : Type*) [_ne : Nonempty α] (s : Finset ι) :
CanLift (s → α) (ι → α) (fun f i => f i) fun _ => True :=
PiFinsetCoe.canLift ι (fun _ => α) s
#align finset.pi_finset_coe.can_lift' Finset.PiFinsetCoe.canLift'
instance FinsetCoe.canLift (s : Finset α) : CanLift α s (↑) fun a => a ∈ s where
prf a ha := ⟨⟨a, ha⟩, rfl⟩
#align finset.finset_coe.can_lift Finset.FinsetCoe.canLift
@[simp, norm_cast]
theorem coe_sort_coe (s : Finset α) : ((s : Set α) : Sort _) = s :=
rfl
#align finset.coe_sort_coe Finset.coe_sort_coe
/-! ### Subset and strict subset relations -/
section Subset
variable {s t : Finset α}
instance : HasSubset (Finset α) :=
⟨fun s t => ∀ ⦃a⦄, a ∈ s → a ∈ t⟩
instance : HasSSubset (Finset α) :=
⟨fun s t => s ⊆ t ∧ ¬t ⊆ s⟩
instance partialOrder : PartialOrder (Finset α) where
le := (· ⊆ ·)
lt := (· ⊂ ·)
le_refl s a := id
le_trans s t u hst htu a ha := htu <| hst ha
le_antisymm s t hst hts := ext fun a => ⟨@hst _, @hts _⟩
instance : IsRefl (Finset α) (· ⊆ ·) :=
show IsRefl (Finset α) (· ≤ ·) by infer_instance
instance : IsTrans (Finset α) (· ⊆ ·) :=
show IsTrans (Finset α) (· ≤ ·) by infer_instance
instance : IsAntisymm (Finset α) (· ⊆ ·) :=
show IsAntisymm (Finset α) (· ≤ ·) by infer_instance
instance : IsIrrefl (Finset α) (· ⊂ ·) :=
show IsIrrefl (Finset α) (· < ·) by infer_instance
instance : IsTrans (Finset α) (· ⊂ ·) :=
show IsTrans (Finset α) (· < ·) by infer_instance
instance : IsAsymm (Finset α) (· ⊂ ·) :=
show IsAsymm (Finset α) (· < ·) by infer_instance
instance : IsNonstrictStrictOrder (Finset α) (· ⊆ ·) (· ⊂ ·) :=
⟨fun _ _ => Iff.rfl⟩
theorem subset_def : s ⊆ t ↔ s.1 ⊆ t.1 :=
Iff.rfl
#align finset.subset_def Finset.subset_def
theorem ssubset_def : s ⊂ t ↔ s ⊆ t ∧ ¬t ⊆ s :=
Iff.rfl
#align finset.ssubset_def Finset.ssubset_def
@[simp]
theorem Subset.refl (s : Finset α) : s ⊆ s :=
Multiset.Subset.refl _
#align finset.subset.refl Finset.Subset.refl
protected theorem Subset.rfl {s : Finset α} : s ⊆ s :=
Subset.refl _
#align finset.subset.rfl Finset.Subset.rfl
protected theorem subset_of_eq {s t : Finset α} (h : s = t) : s ⊆ t :=
h ▸ Subset.refl _
#align finset.subset_of_eq Finset.subset_of_eq
theorem Subset.trans {s₁ s₂ s₃ : Finset α} : s₁ ⊆ s₂ → s₂ ⊆ s₃ → s₁ ⊆ s₃ :=
Multiset.Subset.trans
#align finset.subset.trans Finset.Subset.trans
theorem Superset.trans {s₁ s₂ s₃ : Finset α} : s₁ ⊇ s₂ → s₂ ⊇ s₃ → s₁ ⊇ s₃ := fun h' h =>
Subset.trans h h'
#align finset.superset.trans Finset.Superset.trans
theorem mem_of_subset {s₁ s₂ : Finset α} {a : α} : s₁ ⊆ s₂ → a ∈ s₁ → a ∈ s₂ :=
Multiset.mem_of_subset
#align finset.mem_of_subset Finset.mem_of_subset
theorem not_mem_mono {s t : Finset α} (h : s ⊆ t) {a : α} : a ∉ t → a ∉ s :=
mt <| @h _
#align finset.not_mem_mono Finset.not_mem_mono
theorem Subset.antisymm {s₁ s₂ : Finset α} (H₁ : s₁ ⊆ s₂) (H₂ : s₂ ⊆ s₁) : s₁ = s₂ :=
ext fun a => ⟨@H₁ a, @H₂ a⟩
#align finset.subset.antisymm Finset.Subset.antisymm
theorem subset_iff {s₁ s₂ : Finset α} : s₁ ⊆ s₂ ↔ ∀ ⦃x⦄, x ∈ s₁ → x ∈ s₂ :=
Iff.rfl
#align finset.subset_iff Finset.subset_iff
@[simp, norm_cast]
theorem coe_subset {s₁ s₂ : Finset α} : (s₁ : Set α) ⊆ s₂ ↔ s₁ ⊆ s₂ :=
Iff.rfl
#align finset.coe_subset Finset.coe_subset
@[simp]
theorem val_le_iff {s₁ s₂ : Finset α} : s₁.1 ≤ s₂.1 ↔ s₁ ⊆ s₂ :=
le_iff_subset s₁.2
#align finset.val_le_iff Finset.val_le_iff
theorem Subset.antisymm_iff {s₁ s₂ : Finset α} : s₁ = s₂ ↔ s₁ ⊆ s₂ ∧ s₂ ⊆ s₁ :=
le_antisymm_iff
#align finset.subset.antisymm_iff Finset.Subset.antisymm_iff
theorem not_subset : ¬s ⊆ t ↔ ∃ x ∈ s, x ∉ t := by simp only [← coe_subset, Set.not_subset, mem_coe]
#align finset.not_subset Finset.not_subset
@[simp]
theorem le_eq_subset : ((· ≤ ·) : Finset α → Finset α → Prop) = (· ⊆ ·) :=
rfl
#align finset.le_eq_subset Finset.le_eq_subset
@[simp]
theorem lt_eq_subset : ((· < ·) : Finset α → Finset α → Prop) = (· ⊂ ·) :=
rfl
#align finset.lt_eq_subset Finset.lt_eq_subset
theorem le_iff_subset {s₁ s₂ : Finset α} : s₁ ≤ s₂ ↔ s₁ ⊆ s₂ :=
Iff.rfl
#align finset.le_iff_subset Finset.le_iff_subset
theorem lt_iff_ssubset {s₁ s₂ : Finset α} : s₁ < s₂ ↔ s₁ ⊂ s₂ :=
Iff.rfl
#align finset.lt_iff_ssubset Finset.lt_iff_ssubset
@[simp, norm_cast]
theorem coe_ssubset {s₁ s₂ : Finset α} : (s₁ : Set α) ⊂ s₂ ↔ s₁ ⊂ s₂ :=
show (s₁ : Set α) ⊂ s₂ ↔ s₁ ⊆ s₂ ∧ ¬s₂ ⊆ s₁ by simp only [Set.ssubset_def, Finset.coe_subset]
#align finset.coe_ssubset Finset.coe_ssubset
@[simp]
theorem val_lt_iff {s₁ s₂ : Finset α} : s₁.1 < s₂.1 ↔ s₁ ⊂ s₂ :=
and_congr val_le_iff <| not_congr val_le_iff
#align finset.val_lt_iff Finset.val_lt_iff
lemma val_strictMono : StrictMono (val : Finset α → Multiset α) := fun _ _ ↦ val_lt_iff.2
theorem ssubset_iff_subset_ne {s t : Finset α} : s ⊂ t ↔ s ⊆ t ∧ s ≠ t :=
@lt_iff_le_and_ne _ _ s t
#align finset.ssubset_iff_subset_ne Finset.ssubset_iff_subset_ne
theorem ssubset_iff_of_subset {s₁ s₂ : Finset α} (h : s₁ ⊆ s₂) : s₁ ⊂ s₂ ↔ ∃ x ∈ s₂, x ∉ s₁ :=
Set.ssubset_iff_of_subset h
#align finset.ssubset_iff_of_subset Finset.ssubset_iff_of_subset
theorem ssubset_of_ssubset_of_subset {s₁ s₂ s₃ : Finset α} (hs₁s₂ : s₁ ⊂ s₂) (hs₂s₃ : s₂ ⊆ s₃) :
s₁ ⊂ s₃ :=
Set.ssubset_of_ssubset_of_subset hs₁s₂ hs₂s₃
#align finset.ssubset_of_ssubset_of_subset Finset.ssubset_of_ssubset_of_subset
theorem ssubset_of_subset_of_ssubset {s₁ s₂ s₃ : Finset α} (hs₁s₂ : s₁ ⊆ s₂) (hs₂s₃ : s₂ ⊂ s₃) :
s₁ ⊂ s₃ :=
Set.ssubset_of_subset_of_ssubset hs₁s₂ hs₂s₃
#align finset.ssubset_of_subset_of_ssubset Finset.ssubset_of_subset_of_ssubset
theorem exists_of_ssubset {s₁ s₂ : Finset α} (h : s₁ ⊂ s₂) : ∃ x ∈ s₂, x ∉ s₁ :=
Set.exists_of_ssubset h
#align finset.exists_of_ssubset Finset.exists_of_ssubset
instance isWellFounded_ssubset : IsWellFounded (Finset α) (· ⊂ ·) :=
Subrelation.isWellFounded (InvImage _ _) val_lt_iff.2
#align finset.is_well_founded_ssubset Finset.isWellFounded_ssubset
instance wellFoundedLT : WellFoundedLT (Finset α) :=
Finset.isWellFounded_ssubset
#align finset.is_well_founded_lt Finset.wellFoundedLT
end Subset
-- TODO: these should be global attributes, but this will require fixing other files
attribute [local trans] Subset.trans Superset.trans
/-! ### Order embedding from `Finset α` to `Set α` -/
/-- Coercion to `Set α` as an `OrderEmbedding`. -/
def coeEmb : Finset α ↪o Set α :=
⟨⟨(↑), coe_injective⟩, coe_subset⟩
#align finset.coe_emb Finset.coeEmb
@[simp]
theorem coe_coeEmb : ⇑(coeEmb : Finset α ↪o Set α) = ((↑) : Finset α → Set α) :=
rfl
#align finset.coe_coe_emb Finset.coe_coeEmb
/-! ### Nonempty -/
/-- The property `s.Nonempty` expresses the fact that the finset `s` is not empty. It should be used
in theorem assumptions instead of `∃ x, x ∈ s` or `s ≠ ∅` as it gives access to a nice API thanks
to the dot notation. -/
protected def Nonempty (s : Finset α) : Prop := ∃ x : α, x ∈ s
#align finset.nonempty Finset.Nonempty
-- Porting note: Much longer than in Lean3
instance decidableNonempty {s : Finset α} : Decidable s.Nonempty :=
Quotient.recOnSubsingleton (motive := fun s : Multiset α => Decidable (∃ a, a ∈ s)) s.1
(fun l : List α =>
match l with
| [] => isFalse <| by simp
| a::l => isTrue ⟨a, by simp⟩)
#align finset.decidable_nonempty Finset.decidableNonempty
@[simp, norm_cast]
theorem coe_nonempty {s : Finset α} : (s : Set α).Nonempty ↔ s.Nonempty :=
Iff.rfl
#align finset.coe_nonempty Finset.coe_nonempty
-- Porting note: Left-hand side simplifies @[simp]
theorem nonempty_coe_sort {s : Finset α} : Nonempty (s : Type _) ↔ s.Nonempty :=
nonempty_subtype
#align finset.nonempty_coe_sort Finset.nonempty_coe_sort
alias ⟨_, Nonempty.to_set⟩ := coe_nonempty
#align finset.nonempty.to_set Finset.Nonempty.to_set
alias ⟨_, Nonempty.coe_sort⟩ := nonempty_coe_sort
#align finset.nonempty.coe_sort Finset.Nonempty.coe_sort
theorem Nonempty.exists_mem {s : Finset α} (h : s.Nonempty) : ∃ x : α, x ∈ s :=
h
#align finset.nonempty.bex Finset.Nonempty.exists_mem
@[deprecated (since := "2024-03-23")] alias Nonempty.bex := Nonempty.exists_mem
theorem Nonempty.mono {s t : Finset α} (hst : s ⊆ t) (hs : s.Nonempty) : t.Nonempty :=
Set.Nonempty.mono hst hs
#align finset.nonempty.mono Finset.Nonempty.mono
theorem Nonempty.forall_const {s : Finset α} (h : s.Nonempty) {p : Prop} : (∀ x ∈ s, p) ↔ p :=
let ⟨x, hx⟩ := h
⟨fun h => h x hx, fun h _ _ => h⟩
#align finset.nonempty.forall_const Finset.Nonempty.forall_const
theorem Nonempty.to_subtype {s : Finset α} : s.Nonempty → Nonempty s :=
nonempty_coe_sort.2
#align finset.nonempty.to_subtype Finset.Nonempty.to_subtype
theorem Nonempty.to_type {s : Finset α} : s.Nonempty → Nonempty α := fun ⟨x, _hx⟩ => ⟨x⟩
#align finset.nonempty.to_type Finset.Nonempty.to_type
/-! ### empty -/
section Empty
variable {s : Finset α}
/-- The empty finset -/
protected def empty : Finset α :=
⟨0, nodup_zero⟩
#align finset.empty Finset.empty
instance : EmptyCollection (Finset α) :=
⟨Finset.empty⟩
instance inhabitedFinset : Inhabited (Finset α) :=
⟨∅⟩
#align finset.inhabited_finset Finset.inhabitedFinset
@[simp]
theorem empty_val : (∅ : Finset α).1 = 0 :=
rfl
#align finset.empty_val Finset.empty_val
@[simp]
theorem not_mem_empty (a : α) : a ∉ (∅ : Finset α) := by
-- Porting note: was `id`. `a ∈ List.nil` is no longer definitionally equal to `False`
simp only [mem_def, empty_val, not_mem_zero, not_false_iff]
#align finset.not_mem_empty Finset.not_mem_empty
@[simp]
theorem not_nonempty_empty : ¬(∅ : Finset α).Nonempty := fun ⟨x, hx⟩ => not_mem_empty x hx
#align finset.not_nonempty_empty Finset.not_nonempty_empty
@[simp]
theorem mk_zero : (⟨0, nodup_zero⟩ : Finset α) = ∅ :=
rfl
#align finset.mk_zero Finset.mk_zero
theorem ne_empty_of_mem {a : α} {s : Finset α} (h : a ∈ s) : s ≠ ∅ := fun e =>
not_mem_empty a <| e ▸ h
#align finset.ne_empty_of_mem Finset.ne_empty_of_mem
theorem Nonempty.ne_empty {s : Finset α} (h : s.Nonempty) : s ≠ ∅ :=
(Exists.elim h) fun _a => ne_empty_of_mem
#align finset.nonempty.ne_empty Finset.Nonempty.ne_empty
@[simp]
theorem empty_subset (s : Finset α) : ∅ ⊆ s :=
zero_subset _
#align finset.empty_subset Finset.empty_subset
theorem eq_empty_of_forall_not_mem {s : Finset α} (H : ∀ x, x ∉ s) : s = ∅ :=
eq_of_veq (eq_zero_of_forall_not_mem H)
#align finset.eq_empty_of_forall_not_mem Finset.eq_empty_of_forall_not_mem
theorem eq_empty_iff_forall_not_mem {s : Finset α} : s = ∅ ↔ ∀ x, x ∉ s :=
-- Porting note: used `id`
⟨by rintro rfl x; apply not_mem_empty, fun h => eq_empty_of_forall_not_mem h⟩
#align finset.eq_empty_iff_forall_not_mem Finset.eq_empty_iff_forall_not_mem
@[simp]
theorem val_eq_zero {s : Finset α} : s.1 = 0 ↔ s = ∅ :=
@val_inj _ s ∅
#align finset.val_eq_zero Finset.val_eq_zero
theorem subset_empty {s : Finset α} : s ⊆ ∅ ↔ s = ∅ :=
subset_zero.trans val_eq_zero
#align finset.subset_empty Finset.subset_empty
@[simp]
theorem not_ssubset_empty (s : Finset α) : ¬s ⊂ ∅ := fun h =>
let ⟨_, he, _⟩ := exists_of_ssubset h
-- Porting note: was `he`
not_mem_empty _ he
#align finset.not_ssubset_empty Finset.not_ssubset_empty
theorem nonempty_of_ne_empty {s : Finset α} (h : s ≠ ∅) : s.Nonempty :=
exists_mem_of_ne_zero (mt val_eq_zero.1 h)
#align finset.nonempty_of_ne_empty Finset.nonempty_of_ne_empty
theorem nonempty_iff_ne_empty {s : Finset α} : s.Nonempty ↔ s ≠ ∅ :=
⟨Nonempty.ne_empty, nonempty_of_ne_empty⟩
#align finset.nonempty_iff_ne_empty Finset.nonempty_iff_ne_empty
@[simp]
theorem not_nonempty_iff_eq_empty {s : Finset α} : ¬s.Nonempty ↔ s = ∅ :=
nonempty_iff_ne_empty.not.trans not_not
#align finset.not_nonempty_iff_eq_empty Finset.not_nonempty_iff_eq_empty
theorem eq_empty_or_nonempty (s : Finset α) : s = ∅ ∨ s.Nonempty :=
by_cases Or.inl fun h => Or.inr (nonempty_of_ne_empty h)
#align finset.eq_empty_or_nonempty Finset.eq_empty_or_nonempty
@[simp, norm_cast]
theorem coe_empty : ((∅ : Finset α) : Set α) = ∅ :=
Set.ext <| by simp
#align finset.coe_empty Finset.coe_empty
@[simp, norm_cast]
theorem coe_eq_empty {s : Finset α} : (s : Set α) = ∅ ↔ s = ∅ := by rw [← coe_empty, coe_inj]
#align finset.coe_eq_empty Finset.coe_eq_empty
-- Porting note: Left-hand side simplifies @[simp]
theorem isEmpty_coe_sort {s : Finset α} : IsEmpty (s : Type _) ↔ s = ∅ := by
simpa using @Set.isEmpty_coe_sort α s
#align finset.is_empty_coe_sort Finset.isEmpty_coe_sort
instance instIsEmpty : IsEmpty (∅ : Finset α) :=
isEmpty_coe_sort.2 rfl
/-- A `Finset` for an empty type is empty. -/
theorem eq_empty_of_isEmpty [IsEmpty α] (s : Finset α) : s = ∅ :=
Finset.eq_empty_of_forall_not_mem isEmptyElim
#align finset.eq_empty_of_is_empty Finset.eq_empty_of_isEmpty
instance : OrderBot (Finset α) where
bot := ∅
bot_le := empty_subset
@[simp]
theorem bot_eq_empty : (⊥ : Finset α) = ∅ :=
rfl
#align finset.bot_eq_empty Finset.bot_eq_empty
@[simp]
theorem empty_ssubset : ∅ ⊂ s ↔ s.Nonempty :=
(@bot_lt_iff_ne_bot (Finset α) _ _ _).trans nonempty_iff_ne_empty.symm
#align finset.empty_ssubset Finset.empty_ssubset
alias ⟨_, Nonempty.empty_ssubset⟩ := empty_ssubset
#align finset.nonempty.empty_ssubset Finset.Nonempty.empty_ssubset
end Empty
/-! ### singleton -/
section Singleton
variable {s : Finset α} {a b : α}
/-- `{a} : Finset a` is the set `{a}` containing `a` and nothing else.
This differs from `insert a ∅` in that it does not require a `DecidableEq` instance for `α`.
-/
instance : Singleton α (Finset α) :=
⟨fun a => ⟨{a}, nodup_singleton a⟩⟩
@[simp]
theorem singleton_val (a : α) : ({a} : Finset α).1 = {a} :=
rfl
#align finset.singleton_val Finset.singleton_val
@[simp]
theorem mem_singleton {a b : α} : b ∈ ({a} : Finset α) ↔ b = a :=
Multiset.mem_singleton
#align finset.mem_singleton Finset.mem_singleton
theorem eq_of_mem_singleton {x y : α} (h : x ∈ ({y} : Finset α)) : x = y :=
mem_singleton.1 h
#align finset.eq_of_mem_singleton Finset.eq_of_mem_singleton
theorem not_mem_singleton {a b : α} : a ∉ ({b} : Finset α) ↔ a ≠ b :=
not_congr mem_singleton
#align finset.not_mem_singleton Finset.not_mem_singleton
theorem mem_singleton_self (a : α) : a ∈ ({a} : Finset α) :=
-- Porting note: was `Or.inl rfl`
mem_singleton.mpr rfl
#align finset.mem_singleton_self Finset.mem_singleton_self
@[simp]
theorem val_eq_singleton_iff {a : α} {s : Finset α} : s.val = {a} ↔ s = {a} := by
rw [← val_inj]
rfl
#align finset.val_eq_singleton_iff Finset.val_eq_singleton_iff
theorem singleton_injective : Injective (singleton : α → Finset α) := fun _a _b h =>
mem_singleton.1 (h ▸ mem_singleton_self _)
#align finset.singleton_injective Finset.singleton_injective
@[simp]
theorem singleton_inj : ({a} : Finset α) = {b} ↔ a = b :=
singleton_injective.eq_iff
#align finset.singleton_inj Finset.singleton_inj
@[simp, aesop safe apply (rule_sets := [finsetNonempty])]
theorem singleton_nonempty (a : α) : ({a} : Finset α).Nonempty :=
⟨a, mem_singleton_self a⟩
#align finset.singleton_nonempty Finset.singleton_nonempty
@[simp]
theorem singleton_ne_empty (a : α) : ({a} : Finset α) ≠ ∅ :=
(singleton_nonempty a).ne_empty
#align finset.singleton_ne_empty Finset.singleton_ne_empty
theorem empty_ssubset_singleton : (∅ : Finset α) ⊂ {a} :=
(singleton_nonempty _).empty_ssubset
#align finset.empty_ssubset_singleton Finset.empty_ssubset_singleton
@[simp, norm_cast]
theorem coe_singleton (a : α) : (({a} : Finset α) : Set α) = {a} := by
ext
simp
#align finset.coe_singleton Finset.coe_singleton
@[simp, norm_cast]
theorem coe_eq_singleton {s : Finset α} {a : α} : (s : Set α) = {a} ↔ s = {a} := by
rw [← coe_singleton, coe_inj]
#align finset.coe_eq_singleton Finset.coe_eq_singleton
@[norm_cast]
lemma coe_subset_singleton : (s : Set α) ⊆ {a} ↔ s ⊆ {a} := by rw [← coe_subset, coe_singleton]
@[norm_cast]
lemma singleton_subset_coe : {a} ⊆ (s : Set α) ↔ {a} ⊆ s := by rw [← coe_subset, coe_singleton]
theorem eq_singleton_iff_unique_mem {s : Finset α} {a : α} : s = {a} ↔ a ∈ s ∧ ∀ x ∈ s, x = a := by
constructor <;> intro t
· rw [t]
exact ⟨Finset.mem_singleton_self _, fun _ => Finset.mem_singleton.1⟩
· ext
rw [Finset.mem_singleton]
exact ⟨t.right _, fun r => r.symm ▸ t.left⟩
#align finset.eq_singleton_iff_unique_mem Finset.eq_singleton_iff_unique_mem
theorem eq_singleton_iff_nonempty_unique_mem {s : Finset α} {a : α} :
s = {a} ↔ s.Nonempty ∧ ∀ x ∈ s, x = a := by
constructor
· rintro rfl
simp
· rintro ⟨hne, h_uniq⟩
rw [eq_singleton_iff_unique_mem]
refine ⟨?_, h_uniq⟩
rw [← h_uniq hne.choose hne.choose_spec]
exact hne.choose_spec
#align finset.eq_singleton_iff_nonempty_unique_mem Finset.eq_singleton_iff_nonempty_unique_mem
theorem nonempty_iff_eq_singleton_default [Unique α] {s : Finset α} :
s.Nonempty ↔ s = {default} := by
simp [eq_singleton_iff_nonempty_unique_mem, eq_iff_true_of_subsingleton]
#align finset.nonempty_iff_eq_singleton_default Finset.nonempty_iff_eq_singleton_default
alias ⟨Nonempty.eq_singleton_default, _⟩ := nonempty_iff_eq_singleton_default
#align finset.nonempty.eq_singleton_default Finset.Nonempty.eq_singleton_default
theorem singleton_iff_unique_mem (s : Finset α) : (∃ a, s = {a}) ↔ ∃! a, a ∈ s := by
simp only [eq_singleton_iff_unique_mem, ExistsUnique]
#align finset.singleton_iff_unique_mem Finset.singleton_iff_unique_mem
theorem singleton_subset_set_iff {s : Set α} {a : α} : ↑({a} : Finset α) ⊆ s ↔ a ∈ s := by
rw [coe_singleton, Set.singleton_subset_iff]
#align finset.singleton_subset_set_iff Finset.singleton_subset_set_iff
@[simp]
theorem singleton_subset_iff {s : Finset α} {a : α} : {a} ⊆ s ↔ a ∈ s :=
singleton_subset_set_iff
#align finset.singleton_subset_iff Finset.singleton_subset_iff
@[simp]
theorem subset_singleton_iff {s : Finset α} {a : α} : s ⊆ {a} ↔ s = ∅ ∨ s = {a} := by
rw [← coe_subset, coe_singleton, Set.subset_singleton_iff_eq, coe_eq_empty, coe_eq_singleton]
#align finset.subset_singleton_iff Finset.subset_singleton_iff
theorem singleton_subset_singleton : ({a} : Finset α) ⊆ {b} ↔ a = b := by simp
#align finset.singleton_subset_singleton Finset.singleton_subset_singleton
protected theorem Nonempty.subset_singleton_iff {s : Finset α} {a : α} (h : s.Nonempty) :
s ⊆ {a} ↔ s = {a} :=
subset_singleton_iff.trans <| or_iff_right h.ne_empty
#align finset.nonempty.subset_singleton_iff Finset.Nonempty.subset_singleton_iff
theorem subset_singleton_iff' {s : Finset α} {a : α} : s ⊆ {a} ↔ ∀ b ∈ s, b = a :=
forall₂_congr fun _ _ => mem_singleton
#align finset.subset_singleton_iff' Finset.subset_singleton_iff'
@[simp]
theorem ssubset_singleton_iff {s : Finset α} {a : α} : s ⊂ {a} ↔ s = ∅ := by
rw [← coe_ssubset, coe_singleton, Set.ssubset_singleton_iff, coe_eq_empty]
#align finset.ssubset_singleton_iff Finset.ssubset_singleton_iff
theorem eq_empty_of_ssubset_singleton {s : Finset α} {x : α} (hs : s ⊂ {x}) : s = ∅ :=
ssubset_singleton_iff.1 hs
#align finset.eq_empty_of_ssubset_singleton Finset.eq_empty_of_ssubset_singleton
/-- A finset is nontrivial if it has at least two elements. -/
protected abbrev Nontrivial (s : Finset α) : Prop := (s : Set α).Nontrivial
#align finset.nontrivial Finset.Nontrivial
@[simp]
theorem not_nontrivial_empty : ¬ (∅ : Finset α).Nontrivial := by simp [Finset.Nontrivial]
#align finset.not_nontrivial_empty Finset.not_nontrivial_empty
@[simp]
theorem not_nontrivial_singleton : ¬ ({a} : Finset α).Nontrivial := by simp [Finset.Nontrivial]
#align finset.not_nontrivial_singleton Finset.not_nontrivial_singleton
theorem Nontrivial.ne_singleton (hs : s.Nontrivial) : s ≠ {a} := by
rintro rfl; exact not_nontrivial_singleton hs
#align finset.nontrivial.ne_singleton Finset.Nontrivial.ne_singleton
nonrec lemma Nontrivial.exists_ne (hs : s.Nontrivial) (a : α) : ∃ b ∈ s, b ≠ a := hs.exists_ne _
theorem eq_singleton_or_nontrivial (ha : a ∈ s) : s = {a} ∨ s.Nontrivial := by
rw [← coe_eq_singleton]; exact Set.eq_singleton_or_nontrivial ha
#align finset.eq_singleton_or_nontrivial Finset.eq_singleton_or_nontrivial
theorem nontrivial_iff_ne_singleton (ha : a ∈ s) : s.Nontrivial ↔ s ≠ {a} :=
⟨Nontrivial.ne_singleton, (eq_singleton_or_nontrivial ha).resolve_left⟩
#align finset.nontrivial_iff_ne_singleton Finset.nontrivial_iff_ne_singleton
theorem Nonempty.exists_eq_singleton_or_nontrivial : s.Nonempty → (∃ a, s = {a}) ∨ s.Nontrivial :=
fun ⟨a, ha⟩ => (eq_singleton_or_nontrivial ha).imp_left <| Exists.intro a
#align finset.nonempty.exists_eq_singleton_or_nontrivial Finset.Nonempty.exists_eq_singleton_or_nontrivial
instance instNontrivial [Nonempty α] : Nontrivial (Finset α) :=
‹Nonempty α›.elim fun a => ⟨⟨{a}, ∅, singleton_ne_empty _⟩⟩
#align finset.nontrivial' Finset.instNontrivial
instance [IsEmpty α] : Unique (Finset α) where
default := ∅
uniq _ := eq_empty_of_forall_not_mem isEmptyElim
instance (i : α) : Unique ({i} : Finset α) where
default := ⟨i, mem_singleton_self i⟩
uniq j := Subtype.ext <| mem_singleton.mp j.2
@[simp]
lemma default_singleton (i : α) : ((default : ({i} : Finset α)) : α) = i := rfl
end Singleton
/-! ### cons -/
section Cons
variable {s t : Finset α} {a b : α}
/-- `cons a s h` is the set `{a} ∪ s` containing `a` and the elements of `s`. It is the same as
`insert a s` when it is defined, but unlike `insert a s` it does not require `DecidableEq α`,
and the union is guaranteed to be disjoint. -/
def cons (a : α) (s : Finset α) (h : a ∉ s) : Finset α :=
⟨a ::ₘ s.1, nodup_cons.2 ⟨h, s.2⟩⟩
#align finset.cons Finset.cons
@[simp]
theorem mem_cons {h} : b ∈ s.cons a h ↔ b = a ∨ b ∈ s :=
Multiset.mem_cons
#align finset.mem_cons Finset.mem_cons
theorem mem_cons_of_mem {a b : α} {s : Finset α} {hb : b ∉ s} (ha : a ∈ s) : a ∈ cons b s hb :=
Multiset.mem_cons_of_mem ha
-- Porting note (#10618): @[simp] can prove this
theorem mem_cons_self (a : α) (s : Finset α) {h} : a ∈ cons a s h :=
Multiset.mem_cons_self _ _
#align finset.mem_cons_self Finset.mem_cons_self
@[simp]
theorem cons_val (h : a ∉ s) : (cons a s h).1 = a ::ₘ s.1 :=
rfl
#align finset.cons_val Finset.cons_val
theorem forall_mem_cons (h : a ∉ s) (p : α → Prop) :
(∀ x, x ∈ cons a s h → p x) ↔ p a ∧ ∀ x, x ∈ s → p x := by
simp only [mem_cons, or_imp, forall_and, forall_eq]
#align finset.forall_mem_cons Finset.forall_mem_cons
/-- Useful in proofs by induction. -/
theorem forall_of_forall_cons {p : α → Prop} {h : a ∉ s} (H : ∀ x, x ∈ cons a s h → p x) (x)
(h : x ∈ s) : p x :=
H _ <| mem_cons.2 <| Or.inr h
#align finset.forall_of_forall_cons Finset.forall_of_forall_cons
@[simp]
theorem mk_cons {s : Multiset α} (h : (a ::ₘ s).Nodup) :
(⟨a ::ₘ s, h⟩ : Finset α) = cons a ⟨s, (nodup_cons.1 h).2⟩ (nodup_cons.1 h).1 :=
rfl
#align finset.mk_cons Finset.mk_cons
@[simp]
theorem cons_empty (a : α) : cons a ∅ (not_mem_empty _) = {a} := rfl
#align finset.cons_empty Finset.cons_empty
@[simp, aesop safe apply (rule_sets := [finsetNonempty])]
theorem nonempty_cons (h : a ∉ s) : (cons a s h).Nonempty :=
⟨a, mem_cons.2 <| Or.inl rfl⟩
#align finset.nonempty_cons Finset.nonempty_cons
@[simp]
theorem nonempty_mk {m : Multiset α} {hm} : (⟨m, hm⟩ : Finset α).Nonempty ↔ m ≠ 0 := by
induction m using Multiset.induction_on <;> simp
#align finset.nonempty_mk Finset.nonempty_mk
@[simp]
theorem coe_cons {a s h} : (@cons α a s h : Set α) = insert a (s : Set α) := by
ext
simp
#align finset.coe_cons Finset.coe_cons
theorem subset_cons (h : a ∉ s) : s ⊆ s.cons a h :=
Multiset.subset_cons _ _
#align finset.subset_cons Finset.subset_cons
theorem ssubset_cons (h : a ∉ s) : s ⊂ s.cons a h :=
Multiset.ssubset_cons h
#align finset.ssubset_cons Finset.ssubset_cons
theorem cons_subset {h : a ∉ s} : s.cons a h ⊆ t ↔ a ∈ t ∧ s ⊆ t :=
Multiset.cons_subset
#align finset.cons_subset Finset.cons_subset
@[simp]
theorem cons_subset_cons {hs ht} : s.cons a hs ⊆ t.cons a ht ↔ s ⊆ t := by
rwa [← coe_subset, coe_cons, coe_cons, Set.insert_subset_insert_iff, coe_subset]
#align finset.cons_subset_cons Finset.cons_subset_cons
theorem ssubset_iff_exists_cons_subset : s ⊂ t ↔ ∃ (a : _) (h : a ∉ s), s.cons a h ⊆ t := by
refine ⟨fun h => ?_, fun ⟨a, ha, h⟩ => ssubset_of_ssubset_of_subset (ssubset_cons _) h⟩
obtain ⟨a, hs, ht⟩ := not_subset.1 h.2
exact ⟨a, ht, cons_subset.2 ⟨hs, h.subset⟩⟩
#align finset.ssubset_iff_exists_cons_subset Finset.ssubset_iff_exists_cons_subset
end Cons
/-! ### disjoint -/
section Disjoint
variable {f : α → β} {s t u : Finset α} {a b : α}
theorem disjoint_left : Disjoint s t ↔ ∀ ⦃a⦄, a ∈ s → a ∉ t :=
⟨fun h a hs ht => not_mem_empty a <|
singleton_subset_iff.mp (h (singleton_subset_iff.mpr hs) (singleton_subset_iff.mpr ht)),
fun h _ hs ht _ ha => (h (hs ha) (ht ha)).elim⟩
#align finset.disjoint_left Finset.disjoint_left
theorem disjoint_right : Disjoint s t ↔ ∀ ⦃a⦄, a ∈ t → a ∉ s := by
rw [_root_.disjoint_comm, disjoint_left]
#align finset.disjoint_right Finset.disjoint_right
theorem disjoint_iff_ne : Disjoint s t ↔ ∀ a ∈ s, ∀ b ∈ t, a ≠ b := by
simp only [disjoint_left, imp_not_comm, forall_eq']
#align finset.disjoint_iff_ne Finset.disjoint_iff_ne
@[simp]
theorem disjoint_val : s.1.Disjoint t.1 ↔ Disjoint s t :=
disjoint_left.symm
#align finset.disjoint_val Finset.disjoint_val
theorem _root_.Disjoint.forall_ne_finset (h : Disjoint s t) (ha : a ∈ s) (hb : b ∈ t) : a ≠ b :=
disjoint_iff_ne.1 h _ ha _ hb
#align disjoint.forall_ne_finset Disjoint.forall_ne_finset
theorem not_disjoint_iff : ¬Disjoint s t ↔ ∃ a, a ∈ s ∧ a ∈ t :=
disjoint_left.not.trans <| not_forall.trans <| exists_congr fun _ => by
rw [Classical.not_imp, not_not]
#align finset.not_disjoint_iff Finset.not_disjoint_iff
theorem disjoint_of_subset_left (h : s ⊆ u) (d : Disjoint u t) : Disjoint s t :=
disjoint_left.2 fun _x m₁ => (disjoint_left.1 d) (h m₁)
#align finset.disjoint_of_subset_left Finset.disjoint_of_subset_left
theorem disjoint_of_subset_right (h : t ⊆ u) (d : Disjoint s u) : Disjoint s t :=
disjoint_right.2 fun _x m₁ => (disjoint_right.1 d) (h m₁)
#align finset.disjoint_of_subset_right Finset.disjoint_of_subset_right
@[simp]
theorem disjoint_empty_left (s : Finset α) : Disjoint ∅ s :=
disjoint_bot_left
#align finset.disjoint_empty_left Finset.disjoint_empty_left
@[simp]
theorem disjoint_empty_right (s : Finset α) : Disjoint s ∅ :=
disjoint_bot_right
#align finset.disjoint_empty_right Finset.disjoint_empty_right
@[simp]
theorem disjoint_singleton_left : Disjoint (singleton a) s ↔ a ∉ s := by
simp only [disjoint_left, mem_singleton, forall_eq]
#align finset.disjoint_singleton_left Finset.disjoint_singleton_left
@[simp]
theorem disjoint_singleton_right : Disjoint s (singleton a) ↔ a ∉ s :=
disjoint_comm.trans disjoint_singleton_left
#align finset.disjoint_singleton_right Finset.disjoint_singleton_right
-- Porting note: Left-hand side simplifies @[simp]
theorem disjoint_singleton : Disjoint ({a} : Finset α) {b} ↔ a ≠ b := by
rw [disjoint_singleton_left, mem_singleton]
#align finset.disjoint_singleton Finset.disjoint_singleton
theorem disjoint_self_iff_empty (s : Finset α) : Disjoint s s ↔ s = ∅ :=
disjoint_self
#align finset.disjoint_self_iff_empty Finset.disjoint_self_iff_empty
@[simp, norm_cast]
theorem disjoint_coe : Disjoint (s : Set α) t ↔ Disjoint s t := by
simp only [Finset.disjoint_left, Set.disjoint_left, mem_coe]
#align finset.disjoint_coe Finset.disjoint_coe
@[simp, norm_cast]
theorem pairwiseDisjoint_coe {ι : Type*} {s : Set ι} {f : ι → Finset α} :
s.PairwiseDisjoint (fun i => f i : ι → Set α) ↔ s.PairwiseDisjoint f :=
forall₅_congr fun _ _ _ _ _ => disjoint_coe
#align finset.pairwise_disjoint_coe Finset.pairwiseDisjoint_coe
end Disjoint
/-! ### disjoint union -/
/-- `disjUnion s t h` is the set such that `a ∈ disjUnion s t h` iff `a ∈ s` or `a ∈ t`.
It is the same as `s ∪ t`, but it does not require decidable equality on the type. The hypothesis
ensures that the sets are disjoint. -/
def disjUnion (s t : Finset α) (h : Disjoint s t) : Finset α :=
⟨s.1 + t.1, Multiset.nodup_add.2 ⟨s.2, t.2, disjoint_val.2 h⟩⟩
#align finset.disj_union Finset.disjUnion
@[simp]
theorem mem_disjUnion {α s t h a} : a ∈ @disjUnion α s t h ↔ a ∈ s ∨ a ∈ t := by
rcases s with ⟨⟨s⟩⟩; rcases t with ⟨⟨t⟩⟩; apply List.mem_append
#align finset.mem_disj_union Finset.mem_disjUnion
@[simp, norm_cast]
theorem coe_disjUnion {s t : Finset α} (h : Disjoint s t) :
(disjUnion s t h : Set α) = (s : Set α) ∪ t :=
Set.ext <| by simp
theorem disjUnion_comm (s t : Finset α) (h : Disjoint s t) :
disjUnion s t h = disjUnion t s h.symm :=
eq_of_veq <| add_comm _ _
#align finset.disj_union_comm Finset.disjUnion_comm
@[simp]
theorem empty_disjUnion (t : Finset α) (h : Disjoint ∅ t := disjoint_bot_left) :
disjUnion ∅ t h = t :=
eq_of_veq <| zero_add _
#align finset.empty_disj_union Finset.empty_disjUnion
@[simp]
theorem disjUnion_empty (s : Finset α) (h : Disjoint s ∅ := disjoint_bot_right) :
disjUnion s ∅ h = s :=
eq_of_veq <| add_zero _
#align finset.disj_union_empty Finset.disjUnion_empty
theorem singleton_disjUnion (a : α) (t : Finset α) (h : Disjoint {a} t) :
disjUnion {a} t h = cons a t (disjoint_singleton_left.mp h) :=
eq_of_veq <| Multiset.singleton_add _ _
#align finset.singleton_disj_union Finset.singleton_disjUnion
theorem disjUnion_singleton (s : Finset α) (a : α) (h : Disjoint s {a}) :
disjUnion s {a} h = cons a s (disjoint_singleton_right.mp h) := by
rw [disjUnion_comm, singleton_disjUnion]
#align finset.disj_union_singleton Finset.disjUnion_singleton
/-! ### insert -/
section Insert
variable [DecidableEq α] {s t u v : Finset α} {a b : α}
/-- `insert a s` is the set `{a} ∪ s` containing `a` and the elements of `s`. -/
instance : Insert α (Finset α) :=
⟨fun a s => ⟨_, s.2.ndinsert a⟩⟩
theorem insert_def (a : α) (s : Finset α) : insert a s = ⟨_, s.2.ndinsert a⟩ :=
rfl
#align finset.insert_def Finset.insert_def
@[simp]
theorem insert_val (a : α) (s : Finset α) : (insert a s).1 = ndinsert a s.1 :=
rfl
#align finset.insert_val Finset.insert_val
theorem insert_val' (a : α) (s : Finset α) : (insert a s).1 = dedup (a ::ₘ s.1) := by
rw [dedup_cons, dedup_eq_self]; rfl
#align finset.insert_val' Finset.insert_val'
theorem insert_val_of_not_mem {a : α} {s : Finset α} (h : a ∉ s) : (insert a s).1 = a ::ₘ s.1 := by
rw [insert_val, ndinsert_of_not_mem h]
#align finset.insert_val_of_not_mem Finset.insert_val_of_not_mem
@[simp]
theorem mem_insert : a ∈ insert b s ↔ a = b ∨ a ∈ s :=
mem_ndinsert
#align finset.mem_insert Finset.mem_insert
theorem mem_insert_self (a : α) (s : Finset α) : a ∈ insert a s :=
mem_ndinsert_self a s.1
#align finset.mem_insert_self Finset.mem_insert_self
theorem mem_insert_of_mem (h : a ∈ s) : a ∈ insert b s :=
mem_ndinsert_of_mem h
#align finset.mem_insert_of_mem Finset.mem_insert_of_mem
theorem mem_of_mem_insert_of_ne (h : b ∈ insert a s) : b ≠ a → b ∈ s :=
(mem_insert.1 h).resolve_left
#align finset.mem_of_mem_insert_of_ne Finset.mem_of_mem_insert_of_ne
theorem eq_of_not_mem_of_mem_insert (ha : b ∈ insert a s) (hb : b ∉ s) : b = a :=
(mem_insert.1 ha).resolve_right hb
#align finset.eq_of_not_mem_of_mem_insert Finset.eq_of_not_mem_of_mem_insert
/-- A version of `LawfulSingleton.insert_emptyc_eq` that works with `dsimp`. -/
@[simp, nolint simpNF] lemma insert_empty : insert a (∅ : Finset α) = {a} := rfl
@[simp]
theorem cons_eq_insert (a s h) : @cons α a s h = insert a s :=
ext fun a => by simp
#align finset.cons_eq_insert Finset.cons_eq_insert
@[simp, norm_cast]
theorem coe_insert (a : α) (s : Finset α) : ↑(insert a s) = (insert a s : Set α) :=
Set.ext fun x => by simp only [mem_coe, mem_insert, Set.mem_insert_iff]
#align finset.coe_insert Finset.coe_insert
theorem mem_insert_coe {s : Finset α} {x y : α} : x ∈ insert y s ↔ x ∈ insert y (s : Set α) := by
simp
#align finset.mem_insert_coe Finset.mem_insert_coe
instance : LawfulSingleton α (Finset α) :=
⟨fun a => by ext; simp⟩
@[simp]
theorem insert_eq_of_mem (h : a ∈ s) : insert a s = s :=
eq_of_veq <| ndinsert_of_mem h
#align finset.insert_eq_of_mem Finset.insert_eq_of_mem
@[simp]
theorem insert_eq_self : insert a s = s ↔ a ∈ s :=
⟨fun h => h ▸ mem_insert_self _ _, insert_eq_of_mem⟩
#align finset.insert_eq_self Finset.insert_eq_self
theorem insert_ne_self : insert a s ≠ s ↔ a ∉ s :=
insert_eq_self.not
#align finset.insert_ne_self Finset.insert_ne_self
-- Porting note (#10618): @[simp] can prove this
theorem pair_eq_singleton (a : α) : ({a, a} : Finset α) = {a} :=
insert_eq_of_mem <| mem_singleton_self _
#align finset.pair_eq_singleton Finset.pair_eq_singleton
theorem Insert.comm (a b : α) (s : Finset α) : insert a (insert b s) = insert b (insert a s) :=
ext fun x => by simp only [mem_insert, or_left_comm]
#align finset.insert.comm Finset.Insert.comm
-- Porting note (#10618): @[simp] can prove this
@[norm_cast]
theorem coe_pair {a b : α} : (({a, b} : Finset α) : Set α) = {a, b} := by
ext
simp
#align finset.coe_pair Finset.coe_pair
@[simp, norm_cast]
theorem coe_eq_pair {s : Finset α} {a b : α} : (s : Set α) = {a, b} ↔ s = {a, b} := by
rw [← coe_pair, coe_inj]
#align finset.coe_eq_pair Finset.coe_eq_pair
theorem pair_comm (a b : α) : ({a, b} : Finset α) = {b, a} :=
Insert.comm a b ∅
#align finset.pair_comm Finset.pair_comm
-- Porting note (#10618): @[simp] can prove this
theorem insert_idem (a : α) (s : Finset α) : insert a (insert a s) = insert a s :=
ext fun x => by simp only [mem_insert, ← or_assoc, or_self_iff]
#align finset.insert_idem Finset.insert_idem
@[simp, aesop safe apply (rule_sets := [finsetNonempty])]
theorem insert_nonempty (a : α) (s : Finset α) : (insert a s).Nonempty :=
⟨a, mem_insert_self a s⟩
#align finset.insert_nonempty Finset.insert_nonempty
@[simp]
theorem insert_ne_empty (a : α) (s : Finset α) : insert a s ≠ ∅ :=
(insert_nonempty a s).ne_empty
#align finset.insert_ne_empty Finset.insert_ne_empty
-- Porting note: explicit universe annotation is no longer required.
instance (i : α) (s : Finset α) : Nonempty ((insert i s : Finset α) : Set α) :=
(Finset.coe_nonempty.mpr (s.insert_nonempty i)).to_subtype
theorem ne_insert_of_not_mem (s t : Finset α) {a : α} (h : a ∉ s) : s ≠ insert a t := by
contrapose! h
simp [h]
#align finset.ne_insert_of_not_mem Finset.ne_insert_of_not_mem
theorem insert_subset_iff : insert a s ⊆ t ↔ a ∈ t ∧ s ⊆ t := by
simp only [subset_iff, mem_insert, forall_eq, or_imp, forall_and]
#align finset.insert_subset Finset.insert_subset_iff
theorem insert_subset (ha : a ∈ t) (hs : s ⊆ t) : insert a s ⊆ t :=
insert_subset_iff.mpr ⟨ha,hs⟩
@[simp] theorem subset_insert (a : α) (s : Finset α) : s ⊆ insert a s := fun _b => mem_insert_of_mem
#align finset.subset_insert Finset.subset_insert
@[gcongr]
theorem insert_subset_insert (a : α) {s t : Finset α} (h : s ⊆ t) : insert a s ⊆ insert a t :=
insert_subset_iff.2 ⟨mem_insert_self _ _, Subset.trans h (subset_insert _ _)⟩
#align finset.insert_subset_insert Finset.insert_subset_insert
@[simp] lemma insert_subset_insert_iff (ha : a ∉ s) : insert a s ⊆ insert a t ↔ s ⊆ t := by
simp_rw [← coe_subset]; simp [-coe_subset, ha]
theorem insert_inj (ha : a ∉ s) : insert a s = insert b s ↔ a = b :=
⟨fun h => eq_of_not_mem_of_mem_insert (h.subst <| mem_insert_self _ _) ha, congr_arg (insert · s)⟩
#align finset.insert_inj Finset.insert_inj
theorem insert_inj_on (s : Finset α) : Set.InjOn (fun a => insert a s) sᶜ := fun _ h _ _ =>
(insert_inj h).1
#align finset.insert_inj_on Finset.insert_inj_on
theorem ssubset_iff : s ⊂ t ↔ ∃ a ∉ s, insert a s ⊆ t := mod_cast @Set.ssubset_iff_insert α s t
#align finset.ssubset_iff Finset.ssubset_iff
theorem ssubset_insert (h : a ∉ s) : s ⊂ insert a s :=
ssubset_iff.mpr ⟨a, h, Subset.rfl⟩
#align finset.ssubset_insert Finset.ssubset_insert
@[elab_as_elim]
theorem cons_induction {α : Type*} {p : Finset α → Prop} (empty : p ∅)
(cons : ∀ (a : α) (s : Finset α) (h : a ∉ s), p s → p (cons a s h)) : ∀ s, p s
| ⟨s, nd⟩ => by
induction s using Multiset.induction with
| empty => exact empty
| cons a s IH =>
rw [mk_cons nd]
exact cons a _ _ (IH _)
#align finset.cons_induction Finset.cons_induction
@[elab_as_elim]
theorem cons_induction_on {α : Type*} {p : Finset α → Prop} (s : Finset α) (h₁ : p ∅)
(h₂ : ∀ ⦃a : α⦄ {s : Finset α} (h : a ∉ s), p s → p (cons a s h)) : p s :=
cons_induction h₁ h₂ s
#align finset.cons_induction_on Finset.cons_induction_on
@[elab_as_elim]
protected theorem induction {α : Type*} {p : Finset α → Prop} [DecidableEq α] (empty : p ∅)
(insert : ∀ ⦃a : α⦄ {s : Finset α}, a ∉ s → p s → p (insert a s)) : ∀ s, p s :=
cons_induction empty fun a s ha => (s.cons_eq_insert a ha).symm ▸ insert ha
#align finset.induction Finset.induction
/-- To prove a proposition about an arbitrary `Finset α`,
it suffices to prove it for the empty `Finset`,
and to show that if it holds for some `Finset α`,
then it holds for the `Finset` obtained by inserting a new element.
-/
@[elab_as_elim]
protected theorem induction_on {α : Type*} {p : Finset α → Prop} [DecidableEq α] (s : Finset α)
(empty : p ∅) (insert : ∀ ⦃a : α⦄ {s : Finset α}, a ∉ s → p s → p (insert a s)) : p s :=
Finset.induction empty insert s
#align finset.induction_on Finset.induction_on
/-- To prove a proposition about `S : Finset α`,
it suffices to prove it for the empty `Finset`,
and to show that if it holds for some `Finset α ⊆ S`,
then it holds for the `Finset` obtained by inserting a new element of `S`.
-/
@[elab_as_elim]
theorem induction_on' {α : Type*} {p : Finset α → Prop} [DecidableEq α] (S : Finset α) (h₁ : p ∅)
(h₂ : ∀ {a s}, a ∈ S → s ⊆ S → a ∉ s → p s → p (insert a s)) : p S :=
@Finset.induction_on α (fun T => T ⊆ S → p T) _ S (fun _ => h₁)
(fun _ _ has hqs hs =>
let ⟨hS, sS⟩ := Finset.insert_subset_iff.1 hs
h₂ hS sS has (hqs sS))
(Finset.Subset.refl S)
#align finset.induction_on' Finset.induction_on'
/-- To prove a proposition about a nonempty `s : Finset α`, it suffices to show it holds for all
singletons and that if it holds for nonempty `t : Finset α`, then it also holds for the `Finset`
obtained by inserting an element in `t`. -/
@[elab_as_elim]
theorem Nonempty.cons_induction {α : Type*} {p : ∀ s : Finset α, s.Nonempty → Prop}
(singleton : ∀ a, p {a} (singleton_nonempty _))
(cons : ∀ a s (h : a ∉ s) (hs), p s hs → p (Finset.cons a s h) (nonempty_cons h))
{s : Finset α} (hs : s.Nonempty) : p s hs := by
induction s using Finset.cons_induction with
| empty => exact (not_nonempty_empty hs).elim
| cons a t ha h =>
obtain rfl | ht := t.eq_empty_or_nonempty
· exact singleton a
· exact cons a t ha ht (h ht)
#align finset.nonempty.cons_induction Finset.Nonempty.cons_induction
lemma Nonempty.exists_cons_eq (hs : s.Nonempty) : ∃ t a ha, cons a t ha = s :=
hs.cons_induction (fun a ↦ ⟨∅, a, _, cons_empty _⟩) fun _ _ _ _ _ ↦ ⟨_, _, _, rfl⟩
/-- Inserting an element to a finite set is equivalent to the option type. -/
def subtypeInsertEquivOption {t : Finset α} {x : α} (h : x ∉ t) :
{ i // i ∈ insert x t } ≃ Option { i // i ∈ t } where
toFun y := if h : ↑y = x then none else some ⟨y, (mem_insert.mp y.2).resolve_left h⟩
invFun y := (y.elim ⟨x, mem_insert_self _ _⟩) fun z => ⟨z, mem_insert_of_mem z.2⟩
left_inv y := by
by_cases h : ↑y = x
· simp only [Subtype.ext_iff, h, Option.elim, dif_pos, Subtype.coe_mk]
· simp only [h, Option.elim, dif_neg, not_false_iff, Subtype.coe_eta, Subtype.coe_mk]
right_inv := by
rintro (_ | y)
· simp only [Option.elim, dif_pos]
· have : ↑y ≠ x := by
rintro ⟨⟩
exact h y.2
simp only [this, Option.elim, Subtype.eta, dif_neg, not_false_iff, Subtype.coe_mk]
#align finset.subtype_insert_equiv_option Finset.subtypeInsertEquivOption
@[simp]
theorem disjoint_insert_left : Disjoint (insert a s) t ↔ a ∉ t ∧ Disjoint s t := by
simp only [disjoint_left, mem_insert, or_imp, forall_and, forall_eq]
#align finset.disjoint_insert_left Finset.disjoint_insert_left
@[simp]
theorem disjoint_insert_right : Disjoint s (insert a t) ↔ a ∉ s ∧ Disjoint s t :=
disjoint_comm.trans <| by rw [disjoint_insert_left, _root_.disjoint_comm]
#align finset.disjoint_insert_right Finset.disjoint_insert_right
end Insert
/-! ### Lattice structure -/
section Lattice
variable [DecidableEq α] {s s₁ s₂ t t₁ t₂ u v : Finset α} {a b : α}
/-- `s ∪ t` is the set such that `a ∈ s ∪ t` iff `a ∈ s` or `a ∈ t`. -/
instance : Union (Finset α) :=
⟨fun s t => ⟨_, t.2.ndunion s.1⟩⟩
/-- `s ∩ t` is the set such that `a ∈ s ∩ t` iff `a ∈ s` and `a ∈ t`. -/
instance : Inter (Finset α) :=
⟨fun s t => ⟨_, s.2.ndinter t.1⟩⟩
instance : Lattice (Finset α) :=
{ Finset.partialOrder with
sup := (· ∪ ·)
sup_le := fun _ _ _ hs ht _ ha => (mem_ndunion.1 ha).elim (fun h => hs h) fun h => ht h
le_sup_left := fun _ _ _ h => mem_ndunion.2 <| Or.inl h
le_sup_right := fun _ _ _ h => mem_ndunion.2 <| Or.inr h
inf := (· ∩ ·)
le_inf := fun _ _ _ ht hu _ h => mem_ndinter.2 ⟨ht h, hu h⟩
inf_le_left := fun _ _ _ h => (mem_ndinter.1 h).1
inf_le_right := fun _ _ _ h => (mem_ndinter.1 h).2 }
@[simp]
theorem sup_eq_union : (Sup.sup : Finset α → Finset α → Finset α) = Union.union :=
rfl
#align finset.sup_eq_union Finset.sup_eq_union
@[simp]
theorem inf_eq_inter : (Inf.inf : Finset α → Finset α → Finset α) = Inter.inter :=
rfl
#align finset.inf_eq_inter Finset.inf_eq_inter
theorem disjoint_iff_inter_eq_empty : Disjoint s t ↔ s ∩ t = ∅ :=
disjoint_iff
#align finset.disjoint_iff_inter_eq_empty Finset.disjoint_iff_inter_eq_empty
instance decidableDisjoint (U V : Finset α) : Decidable (Disjoint U V) :=
decidable_of_iff _ disjoint_left.symm
#align finset.decidable_disjoint Finset.decidableDisjoint
/-! #### union -/
theorem union_val_nd (s t : Finset α) : (s ∪ t).1 = ndunion s.1 t.1 :=
rfl
#align finset.union_val_nd Finset.union_val_nd
@[simp]
theorem union_val (s t : Finset α) : (s ∪ t).1 = s.1 ∪ t.1 :=
ndunion_eq_union s.2
#align finset.union_val Finset.union_val
@[simp]
theorem mem_union : a ∈ s ∪ t ↔ a ∈ s ∨ a ∈ t :=
mem_ndunion
#align finset.mem_union Finset.mem_union
@[simp]
theorem disjUnion_eq_union (s t h) : @disjUnion α s t h = s ∪ t :=
ext fun a => by simp
#align finset.disj_union_eq_union Finset.disjUnion_eq_union
theorem mem_union_left (t : Finset α) (h : a ∈ s) : a ∈ s ∪ t :=
mem_union.2 <| Or.inl h
#align finset.mem_union_left Finset.mem_union_left
theorem mem_union_right (s : Finset α) (h : a ∈ t) : a ∈ s ∪ t :=
mem_union.2 <| Or.inr h
#align finset.mem_union_right Finset.mem_union_right
theorem forall_mem_union {p : α → Prop} : (∀ a ∈ s ∪ t, p a) ↔ (∀ a ∈ s, p a) ∧ ∀ a ∈ t, p a :=
⟨fun h => ⟨fun a => h a ∘ mem_union_left _, fun b => h b ∘ mem_union_right _⟩,
fun h _ab hab => (mem_union.mp hab).elim (h.1 _) (h.2 _)⟩
#align finset.forall_mem_union Finset.forall_mem_union
theorem not_mem_union : a ∉ s ∪ t ↔ a ∉ s ∧ a ∉ t := by rw [mem_union, not_or]
#align finset.not_mem_union Finset.not_mem_union
@[simp, norm_cast]
theorem coe_union (s₁ s₂ : Finset α) : ↑(s₁ ∪ s₂) = (s₁ ∪ s₂ : Set α) :=
Set.ext fun _ => mem_union
#align finset.coe_union Finset.coe_union
theorem union_subset (hs : s ⊆ u) : t ⊆ u → s ∪ t ⊆ u :=
sup_le <| le_iff_subset.2 hs
#align finset.union_subset Finset.union_subset
theorem subset_union_left {s₁ s₂ : Finset α} : s₁ ⊆ s₁ ∪ s₂ := fun _x => mem_union_left _
#align finset.subset_union_left Finset.subset_union_left
theorem subset_union_right {s₁ s₂ : Finset α} : s₂ ⊆ s₁ ∪ s₂ := fun _x => mem_union_right _
#align finset.subset_union_right Finset.subset_union_right
@[gcongr]
theorem union_subset_union (hsu : s ⊆ u) (htv : t ⊆ v) : s ∪ t ⊆ u ∪ v :=
sup_le_sup (le_iff_subset.2 hsu) htv
#align finset.union_subset_union Finset.union_subset_union
@[gcongr]
theorem union_subset_union_left (h : s₁ ⊆ s₂) : s₁ ∪ t ⊆ s₂ ∪ t :=
union_subset_union h Subset.rfl
#align finset.union_subset_union_left Finset.union_subset_union_left
@[gcongr]
theorem union_subset_union_right (h : t₁ ⊆ t₂) : s ∪ t₁ ⊆ s ∪ t₂ :=
union_subset_union Subset.rfl h
#align finset.union_subset_union_right Finset.union_subset_union_right
theorem union_comm (s₁ s₂ : Finset α) : s₁ ∪ s₂ = s₂ ∪ s₁ := sup_comm _ _
#align finset.union_comm Finset.union_comm
instance : Std.Commutative (α := Finset α) (· ∪ ·) :=
⟨union_comm⟩
@[simp]
theorem union_assoc (s₁ s₂ s₃ : Finset α) : s₁ ∪ s₂ ∪ s₃ = s₁ ∪ (s₂ ∪ s₃) := sup_assoc _ _ _
#align finset.union_assoc Finset.union_assoc
instance : Std.Associative (α := Finset α) (· ∪ ·) :=
⟨union_assoc⟩
@[simp]
theorem union_idempotent (s : Finset α) : s ∪ s = s := sup_idem _
#align finset.union_idempotent Finset.union_idempotent
instance : Std.IdempotentOp (α := Finset α) (· ∪ ·) :=
⟨union_idempotent⟩
theorem union_subset_left (h : s ∪ t ⊆ u) : s ⊆ u :=
subset_union_left.trans h
#align finset.union_subset_left Finset.union_subset_left
theorem union_subset_right {s t u : Finset α} (h : s ∪ t ⊆ u) : t ⊆ u :=
Subset.trans subset_union_right h
#align finset.union_subset_right Finset.union_subset_right
theorem union_left_comm (s t u : Finset α) : s ∪ (t ∪ u) = t ∪ (s ∪ u) :=
ext fun _ => by simp only [mem_union, or_left_comm]
#align finset.union_left_comm Finset.union_left_comm
theorem union_right_comm (s t u : Finset α) : s ∪ t ∪ u = s ∪ u ∪ t :=
ext fun x => by simp only [mem_union, or_assoc, @or_comm (x ∈ t)]
#align finset.union_right_comm Finset.union_right_comm
theorem union_self (s : Finset α) : s ∪ s = s :=
union_idempotent s
#align finset.union_self Finset.union_self
@[simp]
theorem union_empty (s : Finset α) : s ∪ ∅ = s :=
ext fun x => mem_union.trans <| by simp
#align finset.union_empty Finset.union_empty
@[simp]
theorem empty_union (s : Finset α) : ∅ ∪ s = s :=
ext fun x => mem_union.trans <| by simp
#align finset.empty_union Finset.empty_union
@[aesop unsafe apply (rule_sets := [finsetNonempty])]
theorem Nonempty.inl {s t : Finset α} (h : s.Nonempty) : (s ∪ t).Nonempty :=
h.mono subset_union_left
@[aesop unsafe apply (rule_sets := [finsetNonempty])]
theorem Nonempty.inr {s t : Finset α} (h : t.Nonempty) : (s ∪ t).Nonempty :=
h.mono subset_union_right
theorem insert_eq (a : α) (s : Finset α) : insert a s = {a} ∪ s :=
rfl
#align finset.insert_eq Finset.insert_eq
@[simp]
theorem insert_union (a : α) (s t : Finset α) : insert a s ∪ t = insert a (s ∪ t) := by
simp only [insert_eq, union_assoc]
#align finset.insert_union Finset.insert_union
@[simp]
theorem union_insert (a : α) (s t : Finset α) : s ∪ insert a t = insert a (s ∪ t) := by
simp only [insert_eq, union_left_comm]
#align finset.union_insert Finset.union_insert
theorem insert_union_distrib (a : α) (s t : Finset α) :
insert a (s ∪ t) = insert a s ∪ insert a t := by
simp only [insert_union, union_insert, insert_idem]
#align finset.insert_union_distrib Finset.insert_union_distrib
@[simp] lemma union_eq_left : s ∪ t = s ↔ t ⊆ s := sup_eq_left
#align finset.union_eq_left_iff_subset Finset.union_eq_left
@[simp] lemma left_eq_union : s = s ∪ t ↔ t ⊆ s := by rw [eq_comm, union_eq_left]
#align finset.left_eq_union_iff_subset Finset.left_eq_union
@[simp] lemma union_eq_right : s ∪ t = t ↔ s ⊆ t := sup_eq_right
#align finset.union_eq_right_iff_subset Finset.union_eq_right
@[simp] lemma right_eq_union : s = t ∪ s ↔ t ⊆ s := by rw [eq_comm, union_eq_right]
#align finset.right_eq_union_iff_subset Finset.right_eq_union
-- Porting note: replaced `⊔` in RHS
theorem union_congr_left (ht : t ⊆ s ∪ u) (hu : u ⊆ s ∪ t) : s ∪ t = s ∪ u :=
sup_congr_left ht hu
#align finset.union_congr_left Finset.union_congr_left
theorem union_congr_right (hs : s ⊆ t ∪ u) (ht : t ⊆ s ∪ u) : s ∪ u = t ∪ u :=
sup_congr_right hs ht
#align finset.union_congr_right Finset.union_congr_right
theorem union_eq_union_iff_left : s ∪ t = s ∪ u ↔ t ⊆ s ∪ u ∧ u ⊆ s ∪ t :=
sup_eq_sup_iff_left
#align finset.union_eq_union_iff_left Finset.union_eq_union_iff_left
theorem union_eq_union_iff_right : s ∪ u = t ∪ u ↔ s ⊆ t ∪ u ∧ t ⊆ s ∪ u :=
sup_eq_sup_iff_right
#align finset.union_eq_union_iff_right Finset.union_eq_union_iff_right
@[simp]
theorem disjoint_union_left : Disjoint (s ∪ t) u ↔ Disjoint s u ∧ Disjoint t u := by
simp only [disjoint_left, mem_union, or_imp, forall_and]
#align finset.disjoint_union_left Finset.disjoint_union_left
@[simp]
theorem disjoint_union_right : Disjoint s (t ∪ u) ↔ Disjoint s t ∧ Disjoint s u := by
simp only [disjoint_right, mem_union, or_imp, forall_and]
#align finset.disjoint_union_right Finset.disjoint_union_right
/-- To prove a relation on pairs of `Finset X`, it suffices to show that it is
* symmetric,
* it holds when one of the `Finset`s is empty,
* it holds for pairs of singletons,
* if it holds for `[a, c]` and for `[b, c]`, then it holds for `[a ∪ b, c]`.
-/
theorem induction_on_union (P : Finset α → Finset α → Prop) (symm : ∀ {a b}, P a b → P b a)
(empty_right : ∀ {a}, P a ∅) (singletons : ∀ {a b}, P {a} {b})
(union_of : ∀ {a b c}, P a c → P b c → P (a ∪ b) c) : ∀ a b, P a b := by
intro a b
refine Finset.induction_on b empty_right fun x s _xs hi => symm ?_
rw [Finset.insert_eq]
apply union_of _ (symm hi)
refine Finset.induction_on a empty_right fun a t _ta hi => symm ?_
rw [Finset.insert_eq]
exact union_of singletons (symm hi)
#align finset.induction_on_union Finset.induction_on_union
/-! #### inter -/
theorem inter_val_nd (s₁ s₂ : Finset α) : (s₁ ∩ s₂).1 = ndinter s₁.1 s₂.1 :=
rfl
#align finset.inter_val_nd Finset.inter_val_nd
@[simp]
theorem inter_val (s₁ s₂ : Finset α) : (s₁ ∩ s₂).1 = s₁.1 ∩ s₂.1 :=
ndinter_eq_inter s₁.2
#align finset.inter_val Finset.inter_val
@[simp]
theorem mem_inter {a : α} {s₁ s₂ : Finset α} : a ∈ s₁ ∩ s₂ ↔ a ∈ s₁ ∧ a ∈ s₂ :=
mem_ndinter
#align finset.mem_inter Finset.mem_inter
theorem mem_of_mem_inter_left {a : α} {s₁ s₂ : Finset α} (h : a ∈ s₁ ∩ s₂) : a ∈ s₁ :=
(mem_inter.1 h).1
#align finset.mem_of_mem_inter_left Finset.mem_of_mem_inter_left
theorem mem_of_mem_inter_right {a : α} {s₁ s₂ : Finset α} (h : a ∈ s₁ ∩ s₂) : a ∈ s₂ :=
(mem_inter.1 h).2
#align finset.mem_of_mem_inter_right Finset.mem_of_mem_inter_right
theorem mem_inter_of_mem {a : α} {s₁ s₂ : Finset α} : a ∈ s₁ → a ∈ s₂ → a ∈ s₁ ∩ s₂ :=
and_imp.1 mem_inter.2
#align finset.mem_inter_of_mem Finset.mem_inter_of_mem
theorem inter_subset_left {s₁ s₂ : Finset α} : s₁ ∩ s₂ ⊆ s₁ := fun _a => mem_of_mem_inter_left
#align finset.inter_subset_left Finset.inter_subset_left
theorem inter_subset_right {s₁ s₂ : Finset α} : s₁ ∩ s₂ ⊆ s₂ := fun _a => mem_of_mem_inter_right
#align finset.inter_subset_right Finset.inter_subset_right
theorem subset_inter {s₁ s₂ u : Finset α} : s₁ ⊆ s₂ → s₁ ⊆ u → s₁ ⊆ s₂ ∩ u := by
simp (config := { contextual := true }) [subset_iff, mem_inter]
#align finset.subset_inter Finset.subset_inter
@[simp, norm_cast]
theorem coe_inter (s₁ s₂ : Finset α) : ↑(s₁ ∩ s₂) = (s₁ ∩ s₂ : Set α) :=
Set.ext fun _ => mem_inter
#align finset.coe_inter Finset.coe_inter
@[simp]
theorem union_inter_cancel_left {s t : Finset α} : (s ∪ t) ∩ s = s := by
rw [← coe_inj, coe_inter, coe_union, Set.union_inter_cancel_left]
#align finset.union_inter_cancel_left Finset.union_inter_cancel_left
@[simp]
theorem union_inter_cancel_right {s t : Finset α} : (s ∪ t) ∩ t = t := by
rw [← coe_inj, coe_inter, coe_union, Set.union_inter_cancel_right]
#align finset.union_inter_cancel_right Finset.union_inter_cancel_right
theorem inter_comm (s₁ s₂ : Finset α) : s₁ ∩ s₂ = s₂ ∩ s₁ :=
ext fun _ => by simp only [mem_inter, and_comm]
#align finset.inter_comm Finset.inter_comm
@[simp]
theorem inter_assoc (s₁ s₂ s₃ : Finset α) : s₁ ∩ s₂ ∩ s₃ = s₁ ∩ (s₂ ∩ s₃) :=
ext fun _ => by simp only [mem_inter, and_assoc]
#align finset.inter_assoc Finset.inter_assoc
theorem inter_left_comm (s₁ s₂ s₃ : Finset α) : s₁ ∩ (s₂ ∩ s₃) = s₂ ∩ (s₁ ∩ s₃) :=
ext fun _ => by simp only [mem_inter, and_left_comm]
#align finset.inter_left_comm Finset.inter_left_comm
theorem inter_right_comm (s₁ s₂ s₃ : Finset α) : s₁ ∩ s₂ ∩ s₃ = s₁ ∩ s₃ ∩ s₂ :=
ext fun _ => by simp only [mem_inter, and_right_comm]
#align finset.inter_right_comm Finset.inter_right_comm
@[simp]
theorem inter_self (s : Finset α) : s ∩ s = s :=
ext fun _ => mem_inter.trans <| and_self_iff
#align finset.inter_self Finset.inter_self
@[simp]
theorem inter_empty (s : Finset α) : s ∩ ∅ = ∅ :=
ext fun _ => mem_inter.trans <| by simp
#align finset.inter_empty Finset.inter_empty
@[simp]
theorem empty_inter (s : Finset α) : ∅ ∩ s = ∅ :=
ext fun _ => mem_inter.trans <| by simp
#align finset.empty_inter Finset.empty_inter
@[simp]
theorem inter_union_self (s t : Finset α) : s ∩ (t ∪ s) = s := by
rw [inter_comm, union_inter_cancel_right]
#align finset.inter_union_self Finset.inter_union_self
@[simp]
theorem insert_inter_of_mem {s₁ s₂ : Finset α} {a : α} (h : a ∈ s₂) :
insert a s₁ ∩ s₂ = insert a (s₁ ∩ s₂) :=
ext fun x => by
have : x = a ∨ x ∈ s₂ ↔ x ∈ s₂ := or_iff_right_of_imp <| by rintro rfl; exact h
simp only [mem_inter, mem_insert, or_and_left, this]
#align finset.insert_inter_of_mem Finset.insert_inter_of_mem
@[simp]
| Mathlib/Data/Finset/Basic.lean | 1,693 | 1,694 | theorem inter_insert_of_mem {s₁ s₂ : Finset α} {a : α} (h : a ∈ s₁) :
s₁ ∩ insert a s₂ = insert a (s₁ ∩ s₂) := by | rw [inter_comm, insert_inter_of_mem h, inter_comm]
|
/-
Copyright (c) 2021 Yury Kudriashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudriashov, Malo Jaffré
-/
import Mathlib.Analysis.Convex.Function
import Mathlib.Tactic.AdaptationNote
import Mathlib.Tactic.FieldSimp
import Mathlib.Tactic.Linarith
#align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb"
/-!
# Slopes of convex functions
This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity
of their slopes.
The main use is to show convexity/concavity from monotonicity of the derivative.
-/
variable {𝕜 : Type*} [LinearOrderedField 𝕜] {s : Set 𝕜} {f : 𝕜 → 𝕜}
#adaptation_note /-- after v4.7.0-rc1, there is a performance problem in `field_simp`.
(Part of the code was ignoring the `maxDischargeDepth` setting:
now that we have to increase it, other paths become slow.) -/
/-- If `f : 𝕜 → 𝕜` is convex, then for any three points `x < y < z` the slope of the secant line of
`f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/
theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn 𝕜 s f) {x y z : 𝕜} (hx : x ∈ s) (hz : z ∈ s)
(hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≤ (f z - f y) / (z - y) := by
have hxz := hxy.trans hyz
rw [← sub_pos] at hxy hxz hyz
suffices f y / (y - x) + f y / (z - y) ≤ f x / (y - x) + f z / (z - y) by
ring_nf at this ⊢
linarith
set a := (z - y) / (z - x)
set b := (y - x) / (z - x)
have hy : a • x + b • z = y := by field_simp [a, b]; ring
have key :=
hf.2 hx hz (show 0 ≤ a by apply div_nonneg <;> linarith)
(show 0 ≤ b by apply div_nonneg <;> linarith)
(show a + b = 1 by field_simp [a, b])
rw [hy] at key
replace key := mul_le_mul_of_nonneg_left key hxz.le
field_simp [a, b, mul_comm (z - x) _] at key ⊢
rw [div_le_div_right]
· linarith
· nlinarith
#align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent
/-- If `f : 𝕜 → 𝕜` is concave, then for any three points `x < y < z` the slope of the secant line of
`f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/
theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn 𝕜 s f) {x y z : 𝕜} (hx : x ∈ s) (hz : z ∈ s)
(hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≤ (f y - f x) / (y - x) := by
have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz)
simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this
exact this
#align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent
/-- If `f : 𝕜 → 𝕜` is strictly convex, then for any three points `x < y < z` the slope of the
secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on
`[x, z]`. -/
theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn 𝕜 s f) {x y z : 𝕜}
(hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) :
(f y - f x) / (y - x) < (f z - f y) / (z - y) := by
have hxz := hxy.trans hyz
have hxz' := hxz.ne
rw [← sub_pos] at hxy hxz hyz
suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by
ring_nf at this ⊢
linarith
set a := (z - y) / (z - x)
set b := (y - x) / (z - x)
have hy : a • x + b • z = y := by field_simp [a, b]; ring
have key :=
hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz)
(show a + b = 1 by field_simp [a, b])
rw [hy] at key
replace key := mul_lt_mul_of_pos_left key hxz
field_simp [mul_comm (z - x) _] at key ⊢
rw [div_lt_div_right]
· linarith
· nlinarith
#align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent
/-- If `f : 𝕜 → 𝕜` is strictly concave, then for any three points `x < y < z` the slope of the
secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on
`[x, z]`. -/
theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn 𝕜 s f) {x y z : 𝕜} (hx : x ∈ s)
(hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by
have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz)
simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this
exact this
#align strict_concave_on.slope_anti_adjacent StrictConcaveOn.slope_anti_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : 𝕜 → 𝕜` on `[x, y]` is
less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/
theorem convexOn_of_slope_mono_adjacent (hs : Convex 𝕜 s)
(hf :
∀ {x y z : 𝕜},
x ∈ s → z ∈ s → x < y → y < z → (f y - f x) / (y - x) ≤ (f z - f y) / (z - y)) :
ConvexOn 𝕜 s f :=
LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by
let y := a * x + b * z
have hxy : x < y := by
rw [← one_mul x, ← hab, add_mul]
exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _
have hyz : y < z := by
rw [← one_mul z, ← hab, add_mul]
exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _
have : (f y - f x) * (z - y) ≤ (f z - f y) * (y - x) :=
(div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz)
have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz)
have ha : (z - y) / (z - x) = a := by
rw [eq_comm, ← sub_eq_iff_eq_add'] at hab
dsimp [y]
simp_rw [div_eq_iff hxz.ne', ← hab]
ring
have hb : (y - x) / (z - x) = b := by
rw [eq_comm, ← sub_eq_iff_eq_add] at hab
dsimp [y]
simp_rw [div_eq_iff hxz.ne', ← hab]
ring
rwa [sub_mul, sub_mul, sub_le_iff_le_add', ← add_sub_assoc, le_sub_iff_add_le, ← mul_add,
sub_add_sub_cancel, ← le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x),
mul_comm (f z), ha, hb] at this
#align convex_on_of_slope_mono_adjacent convexOn_of_slope_mono_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : 𝕜 → 𝕜` on `[x, y]` is
greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/
theorem concaveOn_of_slope_anti_adjacent (hs : Convex 𝕜 s)
(hf :
∀ {x y z : 𝕜},
x ∈ s → z ∈ s → x < y → y < z → (f z - f y) / (z - y) ≤ (f y - f x) / (y - x)) :
ConcaveOn 𝕜 s f := by
rw [← neg_convexOn_iff]
refine convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => ?_
rw [← neg_le_neg_iff]
simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg]
exact hf hx hz hxy hyz
#align concave_on_of_slope_anti_adjacent concaveOn_of_slope_anti_adjacent
/-- If for any three points `x < y < z`, the slope of the secant line of `f : 𝕜 → 𝕜` on `[x, y]` is
strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/
| Mathlib/Analysis/Convex/Slope.lean | 145 | 173 | theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex 𝕜 s)
(hf :
∀ {x y z : 𝕜},
x ∈ s → z ∈ s → x < y → y < z → (f y - f x) / (y - x) < (f z - f y) / (z - y)) :
StrictConvexOn 𝕜 s f :=
LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by
let y := a * x + b * z
have hxy : x < y := by |
rw [← one_mul x, ← hab, add_mul]
exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _
have hyz : y < z := by
rw [← one_mul z, ← hab, add_mul]
exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _
have : (f y - f x) * (z - y) < (f z - f y) * (y - x) :=
(div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz)
have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz)
have ha : (z - y) / (z - x) = a := by
rw [eq_comm, ← sub_eq_iff_eq_add'] at hab
dsimp [y]
simp_rw [div_eq_iff hxz.ne', ← hab]
ring
have hb : (y - x) / (z - x) = b := by
rw [eq_comm, ← sub_eq_iff_eq_add] at hab
dsimp [y]
simp_rw [div_eq_iff hxz.ne', ← hab]
ring
rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', ← add_sub_assoc, lt_sub_iff_add_lt, ← mul_add,
sub_add_sub_cancel, ← lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x),
mul_comm (f z), ha, hb] at this
|
/-
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
-/
import Mathlib.MeasureTheory.Measure.Trim
import Mathlib.MeasureTheory.MeasurableSpace.CountablyGenerated
#align_import measure_theory.measure.ae_measurable from "leanprover-community/mathlib"@"3310acfa9787aa171db6d4cba3945f6f275fe9f2"
/-!
# Almost everywhere measurable functions
A function is almost everywhere measurable if it coincides almost everywhere with a measurable
function. This property, called `AEMeasurable f μ`, is defined in the file `MeasureSpaceDef`.
We discuss several of its properties that are analogous to properties of measurable functions.
-/
open scoped Classical
open MeasureTheory MeasureTheory.Measure Filter Set Function ENNReal
variable {ι α β γ δ R : Type*} {m0 : MeasurableSpace α} [MeasurableSpace β] [MeasurableSpace γ]
[MeasurableSpace δ] {f g : α → β} {μ ν : Measure α}
section
@[nontriviality, measurability]
theorem Subsingleton.aemeasurable [Subsingleton α] : AEMeasurable f μ :=
Subsingleton.measurable.aemeasurable
#align subsingleton.ae_measurable Subsingleton.aemeasurable
@[nontriviality, measurability]
theorem aemeasurable_of_subsingleton_codomain [Subsingleton β] : AEMeasurable f μ :=
(measurable_of_subsingleton_codomain f).aemeasurable
#align ae_measurable_of_subsingleton_codomain aemeasurable_of_subsingleton_codomain
@[simp, measurability]
theorem aemeasurable_zero_measure : AEMeasurable f (0 : Measure α) := by
nontriviality α; inhabit α
exact ⟨fun _ => f default, measurable_const, rfl⟩
#align ae_measurable_zero_measure aemeasurable_zero_measure
theorem aemeasurable_id'' (μ : Measure α) {m : MeasurableSpace α} (hm : m ≤ m0) :
@AEMeasurable α α m m0 id μ :=
@Measurable.aemeasurable α α m0 m id μ (measurable_id'' hm)
#align probability_theory.ae_measurable_id'' aemeasurable_id''
lemma aemeasurable_of_map_neZero {mβ : MeasurableSpace β} {μ : Measure α}
{f : α → β} (h : NeZero (μ.map f)) :
AEMeasurable f μ := by
by_contra h'
simp [h'] at h
namespace AEMeasurable
lemma mono_ac (hf : AEMeasurable f ν) (hμν : μ ≪ ν) : AEMeasurable f μ :=
⟨hf.mk f, hf.measurable_mk, hμν.ae_le hf.ae_eq_mk⟩
theorem mono_measure (h : AEMeasurable f μ) (h' : ν ≤ μ) : AEMeasurable f ν :=
mono_ac h h'.absolutelyContinuous
#align ae_measurable.mono_measure AEMeasurable.mono_measure
theorem mono_set {s t} (h : s ⊆ t) (ht : AEMeasurable f (μ.restrict t)) :
AEMeasurable f (μ.restrict s) :=
ht.mono_measure (restrict_mono h le_rfl)
#align ae_measurable.mono_set AEMeasurable.mono_set
protected theorem mono' (h : AEMeasurable f μ) (h' : ν ≪ μ) : AEMeasurable f ν :=
⟨h.mk f, h.measurable_mk, h' h.ae_eq_mk⟩
#align ae_measurable.mono' AEMeasurable.mono'
theorem ae_mem_imp_eq_mk {s} (h : AEMeasurable f (μ.restrict s)) :
∀ᵐ x ∂μ, x ∈ s → f x = h.mk f x :=
ae_imp_of_ae_restrict h.ae_eq_mk
#align ae_measurable.ae_mem_imp_eq_mk AEMeasurable.ae_mem_imp_eq_mk
theorem ae_inf_principal_eq_mk {s} (h : AEMeasurable f (μ.restrict s)) : f =ᶠ[ae μ ⊓ 𝓟 s] h.mk f :=
le_ae_restrict h.ae_eq_mk
#align ae_measurable.ae_inf_principal_eq_mk AEMeasurable.ae_inf_principal_eq_mk
@[measurability]
theorem sum_measure [Countable ι] {μ : ι → Measure α} (h : ∀ i, AEMeasurable f (μ i)) :
AEMeasurable f (sum μ) := by
nontriviality β
inhabit β
set s : ι → Set α := fun i => toMeasurable (μ i) { x | f x ≠ (h i).mk f x }
have hsμ : ∀ i, μ i (s i) = 0 := by
intro i
rw [measure_toMeasurable]
exact (h i).ae_eq_mk
have hsm : MeasurableSet (⋂ i, s i) :=
MeasurableSet.iInter fun i => measurableSet_toMeasurable _ _
have hs : ∀ i x, x ∉ s i → f x = (h i).mk f x := by
intro i x hx
contrapose! hx
exact subset_toMeasurable _ _ hx
set g : α → β := (⋂ i, s i).piecewise (const α default) f
refine ⟨g, measurable_of_restrict_of_restrict_compl hsm ?_ ?_, ae_sum_iff.mpr fun i => ?_⟩
· rw [restrict_piecewise]
simp only [s, Set.restrict, const]
exact measurable_const
· rw [restrict_piecewise_compl, compl_iInter]
intro t ht
refine ⟨⋃ i, (h i).mk f ⁻¹' t ∩ (s i)ᶜ, MeasurableSet.iUnion fun i ↦
(measurable_mk _ ht).inter (measurableSet_toMeasurable _ _).compl, ?_⟩
ext ⟨x, hx⟩
simp only [mem_preimage, mem_iUnion, Subtype.coe_mk, Set.restrict, mem_inter_iff,
mem_compl_iff] at hx ⊢
constructor
· rintro ⟨i, hxt, hxs⟩
rwa [hs _ _ hxs]
· rcases hx with ⟨i, hi⟩
rw [hs _ _ hi]
exact fun h => ⟨i, h, hi⟩
· refine measure_mono_null (fun x (hx : f x ≠ g x) => ?_) (hsμ i)
contrapose! hx
refine (piecewise_eq_of_not_mem _ _ _ ?_).symm
exact fun h => hx (mem_iInter.1 h i)
#align ae_measurable.sum_measure AEMeasurable.sum_measure
@[simp]
theorem _root_.aemeasurable_sum_measure_iff [Countable ι] {μ : ι → Measure α} :
AEMeasurable f (sum μ) ↔ ∀ i, AEMeasurable f (μ i) :=
⟨fun h _ => h.mono_measure (le_sum _ _), sum_measure⟩
#align ae_measurable_sum_measure_iff aemeasurable_sum_measure_iff
@[simp]
theorem _root_.aemeasurable_add_measure_iff :
AEMeasurable f (μ + ν) ↔ AEMeasurable f μ ∧ AEMeasurable f ν := by
rw [← sum_cond, aemeasurable_sum_measure_iff, Bool.forall_bool, and_comm]
rfl
#align ae_measurable_add_measure_iff aemeasurable_add_measure_iff
@[measurability]
theorem add_measure {f : α → β} (hμ : AEMeasurable f μ) (hν : AEMeasurable f ν) :
AEMeasurable f (μ + ν) :=
aemeasurable_add_measure_iff.2 ⟨hμ, hν⟩
#align ae_measurable.add_measure AEMeasurable.add_measure
@[measurability]
protected theorem iUnion [Countable ι] {s : ι → Set α}
(h : ∀ i, AEMeasurable f (μ.restrict (s i))) : AEMeasurable f (μ.restrict (⋃ i, s i)) :=
(sum_measure h).mono_measure <| restrict_iUnion_le
#align ae_measurable.Union AEMeasurable.iUnion
@[simp]
theorem _root_.aemeasurable_iUnion_iff [Countable ι] {s : ι → Set α} :
AEMeasurable f (μ.restrict (⋃ i, s i)) ↔ ∀ i, AEMeasurable f (μ.restrict (s i)) :=
⟨fun h _ => h.mono_measure <| restrict_mono (subset_iUnion _ _) le_rfl, AEMeasurable.iUnion⟩
#align ae_measurable_Union_iff aemeasurable_iUnion_iff
@[simp]
theorem _root_.aemeasurable_union_iff {s t : Set α} :
AEMeasurable f (μ.restrict (s ∪ t)) ↔
AEMeasurable f (μ.restrict s) ∧ AEMeasurable f (μ.restrict t) := by
simp only [union_eq_iUnion, aemeasurable_iUnion_iff, Bool.forall_bool, cond, and_comm]
#align ae_measurable_union_iff aemeasurable_union_iff
@[measurability]
theorem smul_measure [Monoid R] [DistribMulAction R ℝ≥0∞] [IsScalarTower R ℝ≥0∞ ℝ≥0∞]
(h : AEMeasurable f μ) (c : R) : AEMeasurable f (c • μ) :=
⟨h.mk f, h.measurable_mk, ae_smul_measure h.ae_eq_mk c⟩
#align ae_measurable.smul_measure AEMeasurable.smul_measure
theorem comp_aemeasurable {f : α → δ} {g : δ → β} (hg : AEMeasurable g (μ.map f))
(hf : AEMeasurable f μ) : AEMeasurable (g ∘ f) μ :=
⟨hg.mk g ∘ hf.mk f, hg.measurable_mk.comp hf.measurable_mk,
(ae_eq_comp hf hg.ae_eq_mk).trans (hf.ae_eq_mk.fun_comp (mk g hg))⟩
#align ae_measurable.comp_ae_measurable AEMeasurable.comp_aemeasurable
theorem comp_measurable {f : α → δ} {g : δ → β} (hg : AEMeasurable g (μ.map f))
(hf : Measurable f) : AEMeasurable (g ∘ f) μ :=
hg.comp_aemeasurable hf.aemeasurable
#align ae_measurable.comp_measurable AEMeasurable.comp_measurable
theorem comp_quasiMeasurePreserving {ν : Measure δ} {f : α → δ} {g : δ → β} (hg : AEMeasurable g ν)
(hf : QuasiMeasurePreserving f μ ν) : AEMeasurable (g ∘ f) μ :=
(hg.mono' hf.absolutelyContinuous).comp_measurable hf.measurable
#align ae_measurable.comp_quasi_measure_preserving AEMeasurable.comp_quasiMeasurePreserving
theorem map_map_of_aemeasurable {g : β → γ} {f : α → β} (hg : AEMeasurable g (Measure.map f μ))
(hf : AEMeasurable f μ) : (μ.map f).map g = μ.map (g ∘ f) := by
ext1 s hs
rw [map_apply_of_aemeasurable hg hs, map_apply₀ hf (hg.nullMeasurable hs),
map_apply_of_aemeasurable (hg.comp_aemeasurable hf) hs, preimage_comp]
#align ae_measurable.map_map_of_ae_measurable AEMeasurable.map_map_of_aemeasurable
@[measurability]
theorem prod_mk {f : α → β} {g : α → γ} (hf : AEMeasurable f μ) (hg : AEMeasurable g μ) :
AEMeasurable (fun x => (f x, g x)) μ :=
⟨fun a => (hf.mk f a, hg.mk g a), hf.measurable_mk.prod_mk hg.measurable_mk,
EventuallyEq.prod_mk hf.ae_eq_mk hg.ae_eq_mk⟩
#align ae_measurable.prod_mk AEMeasurable.prod_mk
theorem exists_ae_eq_range_subset (H : AEMeasurable f μ) {t : Set β} (ht : ∀ᵐ x ∂μ, f x ∈ t)
(h₀ : t.Nonempty) : ∃ g, Measurable g ∧ range g ⊆ t ∧ f =ᵐ[μ] g := by
let s : Set α := toMeasurable μ { x | f x = H.mk f x ∧ f x ∈ t }ᶜ
let g : α → β := piecewise s (fun _ => h₀.some) (H.mk f)
refine ⟨g, ?_, ?_, ?_⟩
· exact Measurable.piecewise (measurableSet_toMeasurable _ _) measurable_const H.measurable_mk
· rintro _ ⟨x, rfl⟩
by_cases hx : x ∈ s
· simpa [g, hx] using h₀.some_mem
· simp only [g, hx, piecewise_eq_of_not_mem, not_false_iff]
contrapose! hx
apply subset_toMeasurable
simp (config := { contextual := true }) only [hx, mem_compl_iff, mem_setOf_eq, not_and,
not_false_iff, imp_true_iff]
· have A : μ (toMeasurable μ { x | f x = H.mk f x ∧ f x ∈ t }ᶜ) = 0 := by
rw [measure_toMeasurable, ← compl_mem_ae_iff, compl_compl]
exact H.ae_eq_mk.and ht
filter_upwards [compl_mem_ae_iff.2 A] with x hx
rw [mem_compl_iff] at hx
simp only [g, hx, piecewise_eq_of_not_mem, not_false_iff]
contrapose! hx
apply subset_toMeasurable
simp only [hx, mem_compl_iff, mem_setOf_eq, false_and_iff, not_false_iff]
#align ae_measurable.exists_ae_eq_range_subset AEMeasurable.exists_ae_eq_range_subset
theorem exists_measurable_nonneg {β} [Preorder β] [Zero β] {mβ : MeasurableSpace β} {f : α → β}
(hf : AEMeasurable f μ) (f_nn : ∀ᵐ t ∂μ, 0 ≤ f t) : ∃ g, Measurable g ∧ 0 ≤ g ∧ f =ᵐ[μ] g := by
obtain ⟨G, hG_meas, hG_mem, hG_ae_eq⟩ := hf.exists_ae_eq_range_subset f_nn ⟨0, le_rfl⟩
exact ⟨G, hG_meas, fun x => hG_mem (mem_range_self x), hG_ae_eq⟩
#align ae_measurable.exists_measurable_nonneg AEMeasurable.exists_measurable_nonneg
theorem subtype_mk (h : AEMeasurable f μ) {s : Set β} {hfs : ∀ x, f x ∈ s} :
AEMeasurable (codRestrict f s hfs) μ := by
nontriviality α; inhabit α
obtain ⟨g, g_meas, hg, fg⟩ : ∃ g : α → β, Measurable g ∧ range g ⊆ s ∧ f =ᵐ[μ] g :=
h.exists_ae_eq_range_subset (eventually_of_forall hfs) ⟨_, hfs default⟩
refine ⟨codRestrict g s fun x => hg (mem_range_self _), Measurable.subtype_mk g_meas, ?_⟩
filter_upwards [fg] with x hx
simpa [Subtype.ext_iff]
#align ae_measurable.subtype_mk AEMeasurable.subtype_mk
end AEMeasurable
theorem aemeasurable_const' (h : ∀ᵐ (x) (y) ∂μ, f x = f y) : AEMeasurable f μ := by
rcases eq_or_ne μ 0 with (rfl | hμ)
· exact aemeasurable_zero_measure
· haveI := ae_neBot.2 hμ
rcases h.exists with ⟨x, hx⟩
exact ⟨const α (f x), measurable_const, EventuallyEq.symm hx⟩
#align ae_measurable_const' aemeasurable_const'
theorem aemeasurable_uIoc_iff [LinearOrder α] {f : α → β} {a b : α} :
(AEMeasurable f <| μ.restrict <| Ι a b) ↔
(AEMeasurable f <| μ.restrict <| Ioc a b) ∧ (AEMeasurable f <| μ.restrict <| Ioc b a) := by
rw [uIoc_eq_union, aemeasurable_union_iff]
#align ae_measurable_uIoc_iff aemeasurable_uIoc_iff
theorem aemeasurable_iff_measurable [μ.IsComplete] : AEMeasurable f μ ↔ Measurable f :=
⟨fun h => h.nullMeasurable.measurable_of_complete, fun h => h.aemeasurable⟩
#align ae_measurable_iff_measurable aemeasurable_iff_measurable
theorem MeasurableEmbedding.aemeasurable_map_iff {g : β → γ} (hf : MeasurableEmbedding f) :
AEMeasurable g (μ.map f) ↔ AEMeasurable (g ∘ f) μ := by
refine ⟨fun H => H.comp_measurable hf.measurable, ?_⟩
rintro ⟨g₁, hgm₁, heq⟩
rcases hf.exists_measurable_extend hgm₁ fun x => ⟨g x⟩ with ⟨g₂, hgm₂, rfl⟩
exact ⟨g₂, hgm₂, hf.ae_map_iff.2 heq⟩
#align measurable_embedding.ae_measurable_map_iff MeasurableEmbedding.aemeasurable_map_iff
theorem MeasurableEmbedding.aemeasurable_comp_iff {g : β → γ} (hg : MeasurableEmbedding g)
{μ : Measure α} : AEMeasurable (g ∘ f) μ ↔ AEMeasurable f μ := by
refine ⟨fun H => ?_, hg.measurable.comp_aemeasurable⟩
suffices AEMeasurable ((rangeSplitting g ∘ rangeFactorization g) ∘ f) μ by
rwa [(rightInverse_rangeSplitting hg.injective).comp_eq_id] at this
exact hg.measurable_rangeSplitting.comp_aemeasurable H.subtype_mk
#align measurable_embedding.ae_measurable_comp_iff MeasurableEmbedding.aemeasurable_comp_iff
theorem aemeasurable_restrict_iff_comap_subtype {s : Set α} (hs : MeasurableSet s) {μ : Measure α}
{f : α → β} : AEMeasurable f (μ.restrict s) ↔ AEMeasurable (f ∘ (↑) : s → β) (comap (↑) μ) := by
rw [← map_comap_subtype_coe hs, (MeasurableEmbedding.subtype_coe hs).aemeasurable_map_iff]
#align ae_measurable_restrict_iff_comap_subtype aemeasurable_restrict_iff_comap_subtype
@[to_additive] -- @[to_additive (attr := simp)] -- Porting note (#10618): simp can prove this
theorem aemeasurable_one [One β] : AEMeasurable (fun _ : α => (1 : β)) μ :=
measurable_one.aemeasurable
#align ae_measurable_one aemeasurable_one
#align ae_measurable_zero aemeasurable_zero
@[simp]
theorem aemeasurable_smul_measure_iff {c : ℝ≥0∞} (hc : c ≠ 0) :
AEMeasurable f (c • μ) ↔ AEMeasurable f μ :=
⟨fun h => ⟨h.mk f, h.measurable_mk, (ae_smul_measure_iff hc).1 h.ae_eq_mk⟩, fun h =>
⟨h.mk f, h.measurable_mk, (ae_smul_measure_iff hc).2 h.ae_eq_mk⟩⟩
#align ae_measurable_smul_measure_iff aemeasurable_smul_measure_iff
theorem aemeasurable_of_aemeasurable_trim {α} {m m0 : MeasurableSpace α} {μ : Measure α}
(hm : m ≤ m0) {f : α → β} (hf : AEMeasurable f (μ.trim hm)) : AEMeasurable f μ :=
⟨hf.mk f, Measurable.mono hf.measurable_mk hm le_rfl, ae_eq_of_ae_eq_trim hf.ae_eq_mk⟩
#align ae_measurable_of_ae_measurable_trim aemeasurable_of_aemeasurable_trim
theorem aemeasurable_restrict_of_measurable_subtype {s : Set α} (hs : MeasurableSet s)
(hf : Measurable fun x : s => f x) : AEMeasurable f (μ.restrict s) :=
(aemeasurable_restrict_iff_comap_subtype hs).2 hf.aemeasurable
#align ae_measurable_restrict_of_measurable_subtype aemeasurable_restrict_of_measurable_subtype
theorem aemeasurable_map_equiv_iff (e : α ≃ᵐ β) {f : β → γ} :
AEMeasurable f (μ.map e) ↔ AEMeasurable (f ∘ e) μ :=
e.measurableEmbedding.aemeasurable_map_iff
#align ae_measurable_map_equiv_iff aemeasurable_map_equiv_iff
end
theorem AEMeasurable.restrict (hfm : AEMeasurable f μ) {s} : AEMeasurable f (μ.restrict s) :=
⟨AEMeasurable.mk f hfm, hfm.measurable_mk, ae_restrict_of_ae hfm.ae_eq_mk⟩
#align ae_measurable.restrict AEMeasurable.restrict
theorem aemeasurable_Ioi_of_forall_Ioc {β} {mβ : MeasurableSpace β} [LinearOrder α]
[(atTop : Filter α).IsCountablyGenerated] {x : α} {g : α → β}
(g_meas : ∀ t > x, AEMeasurable g (μ.restrict (Ioc x t))) :
AEMeasurable g (μ.restrict (Ioi x)) := by
haveI : Nonempty α := ⟨x⟩
obtain ⟨u, hu_tendsto⟩ := exists_seq_tendsto (atTop : Filter α)
have Ioi_eq_iUnion : Ioi x = ⋃ n : ℕ, Ioc x (u n) := by
rw [iUnion_Ioc_eq_Ioi_self_iff.mpr _]
exact fun y _ => (hu_tendsto.eventually (eventually_ge_atTop y)).exists
rw [Ioi_eq_iUnion, aemeasurable_iUnion_iff]
intro n
cases' lt_or_le x (u n) with h h
· exact g_meas (u n) h
· rw [Ioc_eq_empty (not_lt.mpr h), Measure.restrict_empty]
exact aemeasurable_zero_measure
#align ae_measurable_Ioi_of_forall_Ioc aemeasurable_Ioi_of_forall_Ioc
section Zero
variable [Zero β]
theorem aemeasurable_indicator_iff {s} (hs : MeasurableSet s) :
AEMeasurable (indicator s f) μ ↔ AEMeasurable f (μ.restrict s) := by
constructor
· intro h
exact (h.mono_measure Measure.restrict_le_self).congr (indicator_ae_eq_restrict hs)
· intro h
refine ⟨indicator s (h.mk f), h.measurable_mk.indicator hs, ?_⟩
have A : s.indicator f =ᵐ[μ.restrict s] s.indicator (AEMeasurable.mk f h) :=
(indicator_ae_eq_restrict hs).trans (h.ae_eq_mk.trans <| (indicator_ae_eq_restrict hs).symm)
have B : s.indicator f =ᵐ[μ.restrict sᶜ] s.indicator (AEMeasurable.mk f h) :=
(indicator_ae_eq_restrict_compl hs).trans (indicator_ae_eq_restrict_compl hs).symm
exact ae_of_ae_restrict_of_ae_restrict_compl _ A B
#align ae_measurable_indicator_iff aemeasurable_indicator_iff
theorem aemeasurable_indicator_iff₀ {s} (hs : NullMeasurableSet s μ) :
AEMeasurable (indicator s f) μ ↔ AEMeasurable f (μ.restrict s) := by
rcases hs with ⟨t, ht, hst⟩
rw [← aemeasurable_congr (indicator_ae_eq_of_ae_eq_set hst.symm), aemeasurable_indicator_iff ht,
restrict_congr_set hst]
/-- A characterization of the a.e.-measurability of the indicator function which takes a constant
value `b` on a set `A` and `0` elsewhere. -/
lemma aemeasurable_indicator_const_iff {s} [MeasurableSingletonClass β] (b : β) [NeZero b] :
AEMeasurable (s.indicator (fun _ ↦ b)) μ ↔ NullMeasurableSet s μ := by
constructor <;> intro h
· convert h.nullMeasurable (MeasurableSet.singleton (0 : β)).compl
rw [indicator_const_preimage_eq_union s {0}ᶜ b]
simp [NeZero.ne b]
· exact (aemeasurable_indicator_iff₀ h).mpr aemeasurable_const
@[measurability]
theorem AEMeasurable.indicator (hfm : AEMeasurable f μ) {s} (hs : MeasurableSet s) :
AEMeasurable (s.indicator f) μ :=
(aemeasurable_indicator_iff hs).mpr hfm.restrict
#align ae_measurable.indicator AEMeasurable.indicator
theorem AEMeasurable.indicator₀ (hfm : AEMeasurable f μ) {s} (hs : NullMeasurableSet s μ) :
AEMeasurable (s.indicator f) μ :=
(aemeasurable_indicator_iff₀ hs).mpr hfm.restrict
end Zero
| Mathlib/MeasureTheory/Measure/AEMeasurable.lean | 374 | 388 | theorem MeasureTheory.Measure.restrict_map_of_aemeasurable {f : α → δ} (hf : AEMeasurable f μ)
{s : Set δ} (hs : MeasurableSet s) : (μ.map f).restrict s = (μ.restrict <| f ⁻¹' s).map f :=
calc
(μ.map f).restrict s = (μ.map (hf.mk f)).restrict s := by |
congr 1
apply Measure.map_congr hf.ae_eq_mk
_ = (μ.restrict <| hf.mk f ⁻¹' s).map (hf.mk f) := Measure.restrict_map hf.measurable_mk hs
_ = (μ.restrict <| hf.mk f ⁻¹' s).map f :=
(Measure.map_congr (ae_restrict_of_ae hf.ae_eq_mk.symm))
_ = (μ.restrict <| f ⁻¹' s).map f := by
apply congr_arg
ext1 t ht
simp only [ht, Measure.restrict_apply]
apply measure_congr
apply (EventuallyEq.refl _ _).inter (hf.ae_eq_mk.symm.preimage s)
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.