path stringlengths 11 71 | content stringlengths 75 124k |
|---|---|
Algebra\Module\Submodule\Range.lean | /-
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, Kevin Buzzard, Yury Kudryashov, Frédéric Dupuis,
Heather Macbeth
-/
import Mathlib.Algebra.Module.Submodule.Ker
/-!
# Range of linear maps
The range `LinearMap.range` of a (semi)linear map `f : M → M₂` is a submodule of `M₂`.
More specifically, `LinearMap.range` applies to any `SemilinearMapClass` over a `RingHomSurjective`
ring homomorphism.
Note that this also means that dot notation (i.e. `f.range` for a linear map `f`) does not work.
## Notations
* We continue to use the notations `M →ₛₗ[σ] M₂` and `M →ₗ[R] M₂` for the type of semilinear
(resp. linear) maps from `M` to `M₂` over the ring homomorphism `σ` (resp. over the ring `R`).
## Tags
linear algebra, vector space, module, range
-/
open Function
variable {R : Type*} {R₂ : Type*} {R₃ : Type*}
variable {K : Type*} {K₂ : Type*}
variable {M : Type*} {M₂ : Type*} {M₃ : Type*}
variable {V : Type*} {V₂ : Type*}
namespace LinearMap
section AddCommMonoid
variable [Semiring R] [Semiring R₂] [Semiring R₃]
variable [AddCommMonoid M] [AddCommMonoid M₂] [AddCommMonoid M₃]
variable {σ₁₂ : R →+* R₂} {σ₂₃ : R₂ →+* R₃} {σ₁₃ : R →+* R₃}
variable [RingHomCompTriple σ₁₂ σ₂₃ σ₁₃]
variable [Module R M] [Module R₂ M₂] [Module R₃ M₃]
open Submodule
variable {σ₂₁ : R₂ →+* R} {τ₁₂ : R →+* R₂} {τ₂₃ : R₂ →+* R₃} {τ₁₃ : R →+* R₃}
variable [RingHomCompTriple τ₁₂ τ₂₃ τ₁₃]
section
variable {F : Type*} [FunLike F M M₂] [SemilinearMapClass F τ₁₂ M M₂]
/-- The range of a linear map `f : M → M₂` is a submodule of `M₂`.
See Note [range copy pattern]. -/
def range [RingHomSurjective τ₁₂] (f : F) : Submodule R₂ M₂ :=
(map f ⊤).copy (Set.range f) Set.image_univ.symm
theorem range_coe [RingHomSurjective τ₁₂] (f : F) : (range f : Set M₂) = Set.range f :=
rfl
theorem range_toAddSubmonoid [RingHomSurjective τ₁₂] (f : M →ₛₗ[τ₁₂] M₂) :
f.range.toAddSubmonoid = AddMonoidHom.mrange f :=
rfl
@[simp]
theorem mem_range [RingHomSurjective τ₁₂] {f : F} {x} : x ∈ range f ↔ ∃ y, f y = x :=
Iff.rfl
theorem range_eq_map [RingHomSurjective τ₁₂] (f : F) : range f = map f ⊤ := by
ext
simp
theorem mem_range_self [RingHomSurjective τ₁₂] (f : F) (x : M) : f x ∈ range f :=
⟨x, rfl⟩
@[simp]
theorem range_id : range (LinearMap.id : M →ₗ[R] M) = ⊤ :=
SetLike.coe_injective Set.range_id
theorem range_comp [RingHomSurjective τ₁₂] [RingHomSurjective τ₂₃] [RingHomSurjective τ₁₃]
(f : M →ₛₗ[τ₁₂] M₂) (g : M₂ →ₛₗ[τ₂₃] M₃) : range (g.comp f : M →ₛₗ[τ₁₃] M₃) = map g (range f) :=
SetLike.coe_injective (Set.range_comp g f)
theorem range_comp_le_range [RingHomSurjective τ₂₃] [RingHomSurjective τ₁₃] (f : M →ₛₗ[τ₁₂] M₂)
(g : M₂ →ₛₗ[τ₂₃] M₃) : range (g.comp f : M →ₛₗ[τ₁₃] M₃) ≤ range g :=
SetLike.coe_mono (Set.range_comp_subset_range f g)
theorem range_eq_top [RingHomSurjective τ₁₂] {f : F} : range f = ⊤ ↔ Surjective f := by
rw [SetLike.ext'_iff, range_coe, top_coe, Set.range_iff_surjective]
theorem range_le_iff_comap [RingHomSurjective τ₁₂] {f : F} {p : Submodule R₂ M₂} :
range f ≤ p ↔ comap f p = ⊤ := by rw [range_eq_map, map_le_iff_le_comap, eq_top_iff]
theorem map_le_range [RingHomSurjective τ₁₂] {f : F} {p : Submodule R M} : map f p ≤ range f :=
SetLike.coe_mono (Set.image_subset_range f p)
@[simp]
theorem range_neg {R : Type*} {R₂ : Type*} {M : Type*} {M₂ : Type*} [Semiring R] [Ring R₂]
[AddCommMonoid M] [AddCommGroup M₂] [Module R M] [Module R₂ M₂] {τ₁₂ : R →+* R₂}
[RingHomSurjective τ₁₂] (f : M →ₛₗ[τ₁₂] M₂) : LinearMap.range (-f) = LinearMap.range f := by
change range ((-LinearMap.id : M₂ →ₗ[R₂] M₂).comp f) = _
rw [range_comp, Submodule.map_neg, Submodule.map_id]
lemma range_domRestrict_le_range [RingHomSurjective τ₁₂] (f : M →ₛₗ[τ₁₂] M₂) (S : Submodule R M) :
LinearMap.range (f.domRestrict S) ≤ LinearMap.range f := by
rintro x ⟨⟨y, hy⟩, rfl⟩
exact LinearMap.mem_range_self f y
@[simp]
theorem _root_.AddMonoidHom.coe_toIntLinearMap_range {M M₂ : Type*} [AddCommGroup M]
[AddCommGroup M₂] (f : M →+ M₂) :
LinearMap.range f.toIntLinearMap = AddSubgroup.toIntSubmodule f.range := rfl
lemma _root_.Submodule.map_comap_eq_of_le [RingHomSurjective τ₁₂] {f : F} {p : Submodule R₂ M₂}
(h : p ≤ LinearMap.range f) : (p.comap f).map f = p :=
SetLike.coe_injective <| Set.image_preimage_eq_of_subset h
end
/-- The decreasing sequence of submodules consisting of the ranges of the iterates of a linear map.
-/
@[simps]
def iterateRange (f : M →ₗ[R] M) : ℕ →o (Submodule R M)ᵒᵈ where
toFun n := LinearMap.range (f ^ n)
monotone' n m w x h := by
obtain ⟨c, rfl⟩ := Nat.exists_eq_add_of_le w
rw [LinearMap.mem_range] at h
obtain ⟨m, rfl⟩ := h
rw [LinearMap.mem_range]
use (f ^ c) m
rw [pow_add, LinearMap.mul_apply]
/-- Restrict the codomain of a linear map `f` to `f.range`.
This is the bundled version of `Set.rangeFactorization`. -/
abbrev rangeRestrict [RingHomSurjective τ₁₂] (f : M →ₛₗ[τ₁₂] M₂) : M →ₛₗ[τ₁₂] LinearMap.range f :=
f.codRestrict (LinearMap.range f) (LinearMap.mem_range_self f)
/-- The range of a linear map is finite if the domain is finite.
Note: this instance can form a diamond with `Subtype.fintype` in the
presence of `Fintype M₂`. -/
instance fintypeRange [Fintype M] [DecidableEq M₂] [RingHomSurjective τ₁₂] (f : M →ₛₗ[τ₁₂] M₂) :
Fintype (range f) :=
Set.fintypeRange f
variable {F : Type*} [FunLike F M M₂] [SemilinearMapClass F τ₁₂ M M₂]
theorem range_codRestrict {τ₂₁ : R₂ →+* R} [RingHomSurjective τ₂₁] (p : Submodule R M)
(f : M₂ →ₛₗ[τ₂₁] M) (hf) :
range (codRestrict p f hf) = comap p.subtype (LinearMap.range f) := by
simpa only [range_eq_map] using map_codRestrict _ _ _ _
theorem _root_.Submodule.map_comap_eq [RingHomSurjective τ₁₂] (f : F) (q : Submodule R₂ M₂) :
map f (comap f q) = range f ⊓ q :=
le_antisymm (le_inf map_le_range (map_comap_le _ _)) <| by
rintro _ ⟨⟨x, _, rfl⟩, hx⟩; exact ⟨x, hx, rfl⟩
theorem _root_.Submodule.map_comap_eq_self [RingHomSurjective τ₁₂] {f : F} {q : Submodule R₂ M₂}
(h : q ≤ range f) : map f (comap f q) = q := by rwa [Submodule.map_comap_eq, inf_eq_right]
@[simp]
theorem range_zero [RingHomSurjective τ₁₂] : range (0 : M →ₛₗ[τ₁₂] M₂) = ⊥ := by
simpa only [range_eq_map] using Submodule.map_zero _
section
variable [RingHomSurjective τ₁₂]
theorem range_le_bot_iff (f : M →ₛₗ[τ₁₂] M₂) : range f ≤ ⊥ ↔ f = 0 := by
rw [range_le_iff_comap]; exact ker_eq_top
theorem range_eq_bot {f : M →ₛₗ[τ₁₂] M₂} : range f = ⊥ ↔ f = 0 := by
rw [← range_le_bot_iff, le_bot_iff]
theorem range_le_ker_iff {f : M →ₛₗ[τ₁₂] M₂} {g : M₂ →ₛₗ[τ₂₃] M₃} :
range f ≤ ker g ↔ (g.comp f : M →ₛₗ[τ₁₃] M₃) = 0 :=
⟨fun h => ker_eq_top.1 <| eq_top_iff'.2 fun x => h <| ⟨_, rfl⟩, fun h x hx =>
mem_ker.2 <| Exists.elim hx fun y hy => by rw [← hy, ← comp_apply, h, zero_apply]⟩
theorem comap_le_comap_iff {f : F} (hf : range f = ⊤) {p p'} : comap f p ≤ comap f p' ↔ p ≤ p' :=
⟨fun H x hx => by rcases range_eq_top.1 hf x with ⟨y, hy, rfl⟩; exact H hx, comap_mono⟩
theorem comap_injective {f : F} (hf : range f = ⊤) : Injective (comap f) := fun _ _ h =>
le_antisymm ((comap_le_comap_iff hf).1 (le_of_eq h)) ((comap_le_comap_iff hf).1 (ge_of_eq h))
end
end AddCommMonoid
section Ring
variable [Ring R] [Ring R₂] [Ring R₃]
variable [AddCommGroup M] [AddCommGroup M₂] [AddCommGroup M₃]
variable [Module R M] [Module R₂ M₂] [Module R₃ M₃]
variable {τ₁₂ : R →+* R₂} {τ₂₃ : R₂ →+* R₃} {τ₁₃ : R →+* R₃}
variable [RingHomCompTriple τ₁₂ τ₂₃ τ₁₃]
variable {F : Type*} [FunLike F M M₂] [SemilinearMapClass F τ₁₂ M M₂]
variable {f : F}
open Submodule
theorem range_toAddSubgroup [RingHomSurjective τ₁₂] (f : M →ₛₗ[τ₁₂] M₂) :
(range f).toAddSubgroup = f.toAddMonoidHom.range :=
rfl
theorem ker_le_iff [RingHomSurjective τ₁₂] {p : Submodule R M} :
ker f ≤ p ↔ ∃ y ∈ range f, f ⁻¹' {y} ⊆ p := by
constructor
· intro h
use 0
rw [← SetLike.mem_coe, range_coe]
exact ⟨⟨0, map_zero f⟩, h⟩
· rintro ⟨y, h₁, h₂⟩
rw [SetLike.le_def]
intro z hz
simp only [mem_ker, SetLike.mem_coe] at hz
rw [← SetLike.mem_coe, range_coe, Set.mem_range] at h₁
obtain ⟨x, hx⟩ := h₁
have hx' : x ∈ p := h₂ hx
have hxz : z + x ∈ p := by
apply h₂
simp [hx, hz]
suffices z + x - x ∈ p by simpa only [this, add_sub_cancel_right]
exact p.sub_mem hxz hx'
end Ring
section Semifield
variable [Semifield K] [Semifield K₂]
variable [AddCommMonoid V] [Module K V]
variable [AddCommMonoid V₂] [Module K V₂]
theorem range_smul (f : V →ₗ[K] V₂) (a : K) (h : a ≠ 0) : range (a • f) = range f := by
simpa only [range_eq_map] using Submodule.map_smul f _ a h
theorem range_smul' (f : V →ₗ[K] V₂) (a : K) :
range (a • f) = ⨆ _ : a ≠ 0, range f := by
simpa only [range_eq_map] using Submodule.map_smul' f _ a
end Semifield
end LinearMap
namespace Submodule
section AddCommMonoid
variable [Semiring R] [Semiring R₂] [AddCommMonoid M] [AddCommMonoid M₂]
variable [Module R M] [Module R₂ M₂]
variable (p p' : Submodule R M) (q : Submodule R₂ M₂)
variable {τ₁₂ : R →+* R₂}
variable {F : Type*} [FunLike F M M₂] [SemilinearMapClass F τ₁₂ M M₂]
open LinearMap
@[simp]
theorem map_top [RingHomSurjective τ₁₂] (f : F) : map f ⊤ = range f :=
(range_eq_map f).symm
@[simp]
theorem range_subtype : range p.subtype = p := by simpa using map_comap_subtype p ⊤
theorem map_subtype_le (p' : Submodule R p) : map p.subtype p' ≤ p := by
simpa using (map_le_range : map p.subtype p' ≤ range p.subtype)
/-- Under the canonical linear map from a submodule `p` to the ambient space `M`, the image of the
maximal submodule of `p` is just `p`. -/
-- @[simp] -- Porting note (#10618): simp can prove this
theorem map_subtype_top : map p.subtype (⊤ : Submodule R p) = p := by simp
@[simp]
theorem comap_subtype_eq_top {p p' : Submodule R M} : comap p.subtype p' = ⊤ ↔ p ≤ p' :=
eq_top_iff.trans <| map_le_iff_le_comap.symm.trans <| by rw [map_subtype_top]
@[simp]
theorem comap_subtype_self : comap p.subtype p = ⊤ :=
comap_subtype_eq_top.2 le_rfl
theorem range_inclusion (p q : Submodule R M) (h : p ≤ q) :
range (inclusion h) = comap q.subtype p := by
rw [← map_top, inclusion, LinearMap.map_codRestrict, map_top, range_subtype]
@[simp]
theorem map_subtype_range_inclusion {p p' : Submodule R M} (h : p ≤ p') :
map p'.subtype (range <| inclusion h) = p := by simp [range_inclusion, map_comap_eq, h]
/-- If `N ⊆ M` then submodules of `N` are the same as submodules of `M` contained in `N`.
See also `Submodule.mapIic`. -/
def MapSubtype.relIso : Submodule R p ≃o { p' : Submodule R M // p' ≤ p } where
toFun p' := ⟨map p.subtype p', map_subtype_le p _⟩
invFun q := comap p.subtype q
left_inv p' := comap_map_eq_of_injective (by exact Subtype.val_injective) p'
right_inv := fun ⟨q, hq⟩ => Subtype.ext_val <| by simp [map_comap_subtype p, inf_of_le_right hq]
map_rel_iff' {p₁ p₂} := Subtype.coe_le_coe.symm.trans <| by
dsimp
rw [map_le_iff_le_comap,
comap_map_eq_of_injective (show Injective p.subtype from Subtype.coe_injective) p₂]
/-- If `p ⊆ M` is a submodule, the ordering of submodules of `p` is embedded in the ordering of
submodules of `M`. -/
def MapSubtype.orderEmbedding : Submodule R p ↪o Submodule R M :=
(RelIso.toRelEmbedding <| MapSubtype.relIso p).trans <|
Subtype.relEmbedding (X := Submodule R M) (fun p p' ↦ p ≤ p') _
@[simp]
theorem map_subtype_embedding_eq (p' : Submodule R p) :
MapSubtype.orderEmbedding p p' = map p.subtype p' :=
rfl
/-- If `N ⊆ M` then submodules of `N` are the same as submodules of `M` contained in `N`. -/
def mapIic (p : Submodule R M) :
Submodule R p ≃o Set.Iic p :=
Submodule.MapSubtype.relIso p
@[simp] lemma coe_mapIic_apply
(p : Submodule R M) (q : Submodule R p) :
(p.mapIic q : Submodule R M) = q.map p.subtype :=
rfl
end AddCommMonoid
end Submodule
namespace LinearMap
section Semiring
variable [Semiring R] [Semiring R₂] [Semiring R₃]
variable [AddCommMonoid M] [AddCommMonoid M₂] [AddCommMonoid M₃]
variable [Module R M] [Module R₂ M₂] [Module R₃ M₃]
variable {τ₁₂ : R →+* R₂} {τ₂₃ : R₂ →+* R₃} {τ₁₃ : R →+* R₃}
variable [RingHomCompTriple τ₁₂ τ₂₃ τ₁₃]
/-- A monomorphism is injective. -/
theorem ker_eq_bot_of_cancel {f : M →ₛₗ[τ₁₂] M₂}
(h : ∀ u v : ker f →ₗ[R] M, f.comp u = f.comp v → u = v) : ker f = ⊥ := by
have h₁ : f.comp (0 : ker f →ₗ[R] M) = 0 := comp_zero _
rw [← Submodule.range_subtype (ker f),
← h 0 f.ker.subtype (Eq.trans h₁ (comp_ker_subtype f).symm)]
exact range_zero
theorem range_comp_of_range_eq_top [RingHomSurjective τ₁₂] [RingHomSurjective τ₂₃]
[RingHomSurjective τ₁₃] {f : M →ₛₗ[τ₁₂] M₂} (g : M₂ →ₛₗ[τ₂₃] M₃) (hf : range f = ⊤) :
range (g.comp f : M →ₛₗ[τ₁₃] M₃) = range g := by rw [range_comp, hf, Submodule.map_top]
section Image
/-- If `O` is a submodule of `M`, and `Φ : O →ₗ M'` is a linear map,
then `(ϕ : O →ₗ M').submoduleImage N` is `ϕ(N)` as a submodule of `M'` -/
def submoduleImage {M' : Type*} [AddCommMonoid M'] [Module R M'] {O : Submodule R M}
(ϕ : O →ₗ[R] M') (N : Submodule R M) : Submodule R M' :=
(N.comap O.subtype).map ϕ
@[simp]
theorem mem_submoduleImage {M' : Type*} [AddCommMonoid M'] [Module R M'] {O : Submodule R M}
{ϕ : O →ₗ[R] M'} {N : Submodule R M} {x : M'} :
x ∈ ϕ.submoduleImage N ↔ ∃ (y : _) (yO : y ∈ O), y ∈ N ∧ ϕ ⟨y, yO⟩ = x := by
refine Submodule.mem_map.trans ⟨?_, ?_⟩ <;> simp_rw [Submodule.mem_comap]
· rintro ⟨⟨y, yO⟩, yN : y ∈ N, h⟩
exact ⟨y, yO, yN, h⟩
· rintro ⟨y, yO, yN, h⟩
exact ⟨⟨y, yO⟩, yN, h⟩
theorem mem_submoduleImage_of_le {M' : Type*} [AddCommMonoid M'] [Module R M'] {O : Submodule R M}
{ϕ : O →ₗ[R] M'} {N : Submodule R M} (hNO : N ≤ O) {x : M'} :
x ∈ ϕ.submoduleImage N ↔ ∃ (y : _) (yN : y ∈ N), ϕ ⟨y, hNO yN⟩ = x := by
refine mem_submoduleImage.trans ⟨?_, ?_⟩
· rintro ⟨y, yO, yN, h⟩
exact ⟨y, yN, h⟩
· rintro ⟨y, yN, h⟩
exact ⟨y, hNO yN, yN, h⟩
theorem submoduleImage_apply_of_le {M' : Type*} [AddCommGroup M'] [Module R M']
{O : Submodule R M} (ϕ : O →ₗ[R] M') (N : Submodule R M) (hNO : N ≤ O) :
ϕ.submoduleImage N = range (ϕ.comp (Submodule.inclusion hNO)) := by
rw [submoduleImage, range_comp, Submodule.range_inclusion]
end Image
section rangeRestrict
variable [RingHomSurjective τ₁₂] (f : M →ₛₗ[τ₁₂] M₂)
@[simp] theorem range_rangeRestrict : range f.rangeRestrict = ⊤ := by simp [f.range_codRestrict _]
theorem surjective_rangeRestrict : Surjective f.rangeRestrict := by
rw [← range_eq_top, range_rangeRestrict]
@[simp] theorem ker_rangeRestrict : ker f.rangeRestrict = ker f := LinearMap.ker_codRestrict _ _ _
end rangeRestrict
end Semiring
end LinearMap
|
Algebra\Module\Submodule\RestrictScalars.lean | /-
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
@[simp]
theorem coe_restrictScalars (V : Submodule R M) : (V.restrictScalars S : Set M) = V :=
rfl
@[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 _
@[simp]
theorem restrictScalars_self (V : Submodule R M) : V.restrictScalars R = V :=
SetLike.coe_injective rfl
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 : _)
@[simp]
theorem restrictScalars_inj {V₁ V₂ : Submodule R M} :
restrictScalars S V₁ = restrictScalars S V₂ ↔ V₁ = V₂ :=
(restrictScalars_injective S _ _).eq_iff
/-- 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)
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)
/-- `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]
/-- 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 }
@[simp]
theorem restrictScalars_bot : restrictScalars S (⊥ : Submodule R M) = ⊥ :=
rfl
@[simp]
theorem restrictScalars_eq_bot_iff {p : Submodule R M} : restrictScalars S p = ⊥ ↔ p = ⊥ := by
simp [SetLike.ext_iff]
@[simp]
theorem restrictScalars_top : restrictScalars S (⊤ : Submodule R M) = ⊤ :=
rfl
@[simp]
theorem restrictScalars_eq_top_iff {p : Submodule R M} : restrictScalars S p = ⊤ ↔ p = ⊤ := by
simp [SetLike.ext_iff]
/-- If ring `S` acts on a ring `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`. -/
def restrictScalarsLatticeHom : CompleteLatticeHom (Submodule R M) (Submodule S M) where
toFun := restrictScalars S
map_sInf' s := by ext; simp
map_sSup' s := by rw [← toAddSubmonoid_eq, toAddSubmonoid_sSup, ← Set.image_comp]; simp
end Submodule
|
Algebra\Module\Zlattice\Basic.lean | /-
Copyright (c) 2023 Xavier Roblot. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Xavier Roblot
-/
import Mathlib.LinearAlgebra.FreeModule.PID
import Mathlib.MeasureTheory.Group.FundamentalDomain
import Mathlib.MeasureTheory.Measure.Lebesgue.EqHaar
import Mathlib.RingTheory.Localization.Module
/-!
# ℤ-lattices
Let `E` be a finite dimensional vector space over a `NormedLinearOrderedField` `K` with a solid
norm that is also a `FloorRing`, e.g. `ℝ`. A (full) `ℤ`-lattice `L` of `E` is a discrete
subgroup of `E` such that `L` spans `E` over `K`.
A `ℤ`-lattice `L` can be defined in two ways:
* For `b` a basis of `E`, then `L = Submodule.span ℤ (Set.range b)` is a ℤ-lattice of `E`
* As an `AddSubgroup E` with the additional properties:
* `DiscreteTopology L`, that is `L` is discrete
* `Submodule.span ℝ (L : Set E) = ⊤`, that is `L` spans `E` over `K`.
Results about the first point of view are in the `Zspan` namespace and results about the second
point of view are in the `Zlattice` namespace.
## Main results
* `Zspan.isAddFundamentalDomain`: for a ℤ-lattice `Submodule.span ℤ (Set.range b)`, proves that
the set defined by `Zspan.fundamentalDomain` is a fundamental domain.
* `Zlattice.module_free`: an AddSubgroup of `E` that is discrete and spans `E` over `K` is a free
`ℤ`-module
* `Zlattice.rank`: an AddSubgroup of `E` that is discrete and spans `E` over `K` is a free
`ℤ`-module of `ℤ`-rank equal to the `K`-rank of `E`
-/
noncomputable section
namespace Zspan
open MeasureTheory MeasurableSet Submodule Bornology
variable {E ι : Type*}
section NormedLatticeField
variable {K : Type*} [NormedLinearOrderedField K]
variable [NormedAddCommGroup E] [NormedSpace K E]
variable (b : Basis ι K E)
theorem span_top : span K (span ℤ (Set.range b) : Set E) = ⊤ := by simp [span_span_of_tower]
/-- The fundamental domain of the ℤ-lattice spanned by `b`. See `Zspan.isAddFundamentalDomain`
for the proof that it is a fundamental domain. -/
def fundamentalDomain : Set E := {m | ∀ i, b.repr m i ∈ Set.Ico (0 : K) 1}
@[simp]
theorem mem_fundamentalDomain {m : E} :
m ∈ fundamentalDomain b ↔ ∀ i, b.repr m i ∈ Set.Ico (0 : K) 1 := Iff.rfl
theorem map_fundamentalDomain {F : Type*} [NormedAddCommGroup F] [NormedSpace K F] (f : E ≃ₗ[K] F) :
f '' (fundamentalDomain b) = fundamentalDomain (b.map f) := by
ext x
rw [mem_fundamentalDomain, Basis.map_repr, LinearEquiv.trans_apply, ← mem_fundamentalDomain,
show f.symm x = f.toEquiv.symm x by rfl, ← Set.mem_image_equiv]
rfl
@[simp]
theorem fundamentalDomain_reindex {ι' : Type*} (e : ι ≃ ι') :
fundamentalDomain (b.reindex e) = fundamentalDomain b := by
ext
simp_rw [mem_fundamentalDomain, Basis.repr_reindex_apply]
rw [Equiv.forall_congr' e]
simp_rw [implies_true]
lemma fundamentalDomain_pi_basisFun [Fintype ι] :
fundamentalDomain (Pi.basisFun ℝ ι) = Set.pi Set.univ fun _ : ι ↦ Set.Ico (0 : ℝ) 1 := by
ext; simp
variable [FloorRing K]
section Fintype
variable [Fintype ι]
/-- The map that sends a vector of `E` to the element of the ℤ-lattice spanned by `b` obtained
by rounding down its coordinates on the basis `b`. -/
def floor (m : E) : span ℤ (Set.range b) := ∑ i, ⌊b.repr m i⌋ • b.restrictScalars ℤ i
/-- The map that sends a vector of `E` to the element of the ℤ-lattice spanned by `b` obtained
by rounding up its coordinates on the basis `b`. -/
def ceil (m : E) : span ℤ (Set.range b) := ∑ i, ⌈b.repr m i⌉ • b.restrictScalars ℤ i
@[simp]
theorem repr_floor_apply (m : E) (i : ι) : b.repr (floor b m) i = ⌊b.repr m i⌋ := by
classical simp only [floor, ← Int.cast_smul_eq_zsmul K, b.repr.map_smul, Finsupp.single_apply,
Finset.sum_apply', Basis.repr_self, Finsupp.smul_single', mul_one, Finset.sum_ite_eq', coe_sum,
Finset.mem_univ, if_true, coe_smul_of_tower, Basis.restrictScalars_apply, map_sum]
@[simp]
theorem repr_ceil_apply (m : E) (i : ι) : b.repr (ceil b m) i = ⌈b.repr m i⌉ := by
classical simp only [ceil, ← Int.cast_smul_eq_zsmul K, b.repr.map_smul, Finsupp.single_apply,
Finset.sum_apply', Basis.repr_self, Finsupp.smul_single', mul_one, Finset.sum_ite_eq', coe_sum,
Finset.mem_univ, if_true, coe_smul_of_tower, Basis.restrictScalars_apply, map_sum]
@[simp]
theorem floor_eq_self_of_mem (m : E) (h : m ∈ span ℤ (Set.range b)) : (floor b m : E) = m := by
apply b.ext_elem
simp_rw [repr_floor_apply b]
intro i
obtain ⟨z, hz⟩ := (b.mem_span_iff_repr_mem ℤ _).mp h i
rw [← hz]
exact congr_arg (Int.cast : ℤ → K) (Int.floor_intCast z)
@[simp]
theorem ceil_eq_self_of_mem (m : E) (h : m ∈ span ℤ (Set.range b)) : (ceil b m : E) = m := by
apply b.ext_elem
simp_rw [repr_ceil_apply b]
intro i
obtain ⟨z, hz⟩ := (b.mem_span_iff_repr_mem ℤ _).mp h i
rw [← hz]
exact congr_arg (Int.cast : ℤ → K) (Int.ceil_intCast z)
/-- The map that sends a vector `E` to the `fundamentalDomain` of the lattice,
see `Zspan.fract_mem_fundamentalDomain`, and `fractRestrict` for the map with the codomain
restricted to `fundamentalDomain`. -/
def fract (m : E) : E := m - floor b m
theorem fract_apply (m : E) : fract b m = m - floor b m := rfl
@[simp]
theorem repr_fract_apply (m : E) (i : ι) : b.repr (fract b m) i = Int.fract (b.repr m i) := by
rw [fract, map_sub, Finsupp.coe_sub, Pi.sub_apply, repr_floor_apply, Int.fract]
@[simp]
theorem fract_fract (m : E) : fract b (fract b m) = fract b m :=
Basis.ext_elem b fun _ => by classical simp only [repr_fract_apply, Int.fract_fract]
@[simp]
theorem fract_zspan_add (m : E) {v : E} (h : v ∈ span ℤ (Set.range b)) :
fract b (v + m) = fract b m := by
classical
refine (Basis.ext_elem_iff b).mpr fun i => ?_
simp_rw [repr_fract_apply, Int.fract_eq_fract]
use (b.restrictScalars ℤ).repr ⟨v, h⟩ i
rw [map_add, Finsupp.coe_add, Pi.add_apply, add_tsub_cancel_right,
← eq_intCast (algebraMap ℤ K) _, Basis.restrictScalars_repr_apply, coe_mk]
@[simp]
theorem fract_add_zspan (m : E) {v : E} (h : v ∈ span ℤ (Set.range b)) :
fract b (m + v) = fract b m := by rw [add_comm, fract_zspan_add b m h]
variable {b}
theorem fract_eq_self {x : E} : fract b x = x ↔ x ∈ fundamentalDomain b := by
classical simp only [Basis.ext_elem_iff b, repr_fract_apply, Int.fract_eq_self,
mem_fundamentalDomain, Set.mem_Ico]
variable (b)
theorem fract_mem_fundamentalDomain (x : E) : fract b x ∈ fundamentalDomain b :=
fract_eq_self.mp (fract_fract b _)
/-- The map `fract` with codomain restricted to `fundamentalDomain`. -/
def fractRestrict (x : E) : fundamentalDomain b := ⟨fract b x, fract_mem_fundamentalDomain b x⟩
theorem fractRestrict_surjective : Function.Surjective (fractRestrict b) :=
fun x => ⟨↑x, Subtype.eq (fract_eq_self.mpr (Subtype.mem x))⟩
@[simp]
theorem fractRestrict_apply (x : E) : (fractRestrict b x : E) = fract b x := rfl
theorem fract_eq_fract (m n : E) : fract b m = fract b n ↔ -m + n ∈ span ℤ (Set.range b) := by
classical
rw [eq_comm, Basis.ext_elem_iff b]
simp_rw [repr_fract_apply, Int.fract_eq_fract, eq_comm, Basis.mem_span_iff_repr_mem,
sub_eq_neg_add, map_add, map_neg, Finsupp.coe_add, Finsupp.coe_neg, Pi.add_apply,
Pi.neg_apply, ← eq_intCast (algebraMap ℤ K) _, Set.mem_range]
theorem norm_fract_le [HasSolidNorm K] (m : E) : ‖fract b m‖ ≤ ∑ i, ‖b i‖ := by
classical
calc
‖fract b m‖ = ‖∑ i, b.repr (fract b m) i • b i‖ := by rw [b.sum_repr]
_ = ‖∑ i, Int.fract (b.repr m i) • b i‖ := by simp_rw [repr_fract_apply]
_ ≤ ∑ i, ‖Int.fract (b.repr m i) • b i‖ := norm_sum_le _ _
_ = ∑ i, ‖Int.fract (b.repr m i)‖ * ‖b i‖ := by simp_rw [norm_smul]
_ ≤ ∑ i, ‖b i‖ := Finset.sum_le_sum fun i _ => ?_
suffices ‖Int.fract ((b.repr m) i)‖ ≤ 1 by
convert mul_le_mul_of_nonneg_right this (norm_nonneg _ : 0 ≤ ‖b i‖)
exact (one_mul _).symm
rw [(norm_one.symm : 1 = ‖(1 : K)‖)]
apply norm_le_norm_of_abs_le_abs
rw [abs_one, Int.abs_fract]
exact le_of_lt (Int.fract_lt_one _)
section Unique
variable [Unique ι]
@[simp]
theorem coe_floor_self (k : K) : (floor (Basis.singleton ι K) k : K) = ⌊k⌋ :=
Basis.ext_elem _ fun _ => by rw [repr_floor_apply, Basis.singleton_repr, Basis.singleton_repr]
@[simp]
theorem coe_fract_self (k : K) : (fract (Basis.singleton ι K) k : K) = Int.fract k :=
Basis.ext_elem _ fun _ => by rw [repr_fract_apply, Basis.singleton_repr, Basis.singleton_repr]
end Unique
end Fintype
theorem fundamentalDomain_isBounded [Finite ι] [HasSolidNorm K] :
IsBounded (fundamentalDomain b) := by
cases nonempty_fintype ι
refine isBounded_iff_forall_norm_le.2 ⟨∑ j, ‖b j‖, fun x hx ↦ ?_⟩
rw [← fract_eq_self.mpr hx]
apply norm_fract_le
theorem vadd_mem_fundamentalDomain [Fintype ι] (y : span ℤ (Set.range b)) (x : E) :
y +ᵥ x ∈ fundamentalDomain b ↔ y = -floor b x := by
rw [Subtype.ext_iff, ← add_right_inj x, NegMemClass.coe_neg, ← sub_eq_add_neg, ← fract_apply,
← fract_zspan_add b _ (Subtype.mem y), add_comm, ← vadd_eq_add, ← vadd_def, eq_comm, ←
fract_eq_self]
theorem exist_unique_vadd_mem_fundamentalDomain [Finite ι] (x : E) :
∃! v : span ℤ (Set.range b), v +ᵥ x ∈ fundamentalDomain b := by
cases nonempty_fintype ι
refine ⟨-floor b x, ?_, fun y h => ?_⟩
· exact (vadd_mem_fundamentalDomain b (-floor b x) x).mpr rfl
· exact (vadd_mem_fundamentalDomain b y x).mp h
/-- The map `Zspan.fractRestrict` defines an equiv map between `E ⧸ span ℤ (Set.range b)`
and `Zspan.fundamentalDomain b`. -/
def quotientEquiv [Fintype ι] :
E ⧸ span ℤ (Set.range b) ≃ (fundamentalDomain b) := by
refine Equiv.ofBijective ?_ ⟨fun x y => ?_, fun x => ?_⟩
· refine fun q => Quotient.liftOn q (fractRestrict b) (fun _ _ h => ?_)
rw [Subtype.mk.injEq, fractRestrict_apply, fractRestrict_apply, fract_eq_fract]
exact QuotientAddGroup.leftRel_apply.mp h
· refine Quotient.inductionOn₂ x y (fun _ _ hxy => ?_)
rw [Quotient.liftOn_mk (s := quotientRel (span ℤ (Set.range b))), fractRestrict,
Quotient.liftOn_mk (s := quotientRel (span ℤ (Set.range b))), fractRestrict,
Subtype.mk.injEq] at hxy
apply Quotient.sound'
rwa [QuotientAddGroup.leftRel_apply, mem_toAddSubgroup, ← fract_eq_fract]
· obtain ⟨a, rfl⟩ := fractRestrict_surjective b x
exact ⟨Quotient.mk'' a, rfl⟩
@[simp]
theorem quotientEquiv_apply_mk [Fintype ι] (x : E) :
quotientEquiv b (Submodule.Quotient.mk x) = fractRestrict b x := rfl
@[simp]
theorem quotientEquiv.symm_apply [Fintype ι] (x : fundamentalDomain b) :
(quotientEquiv b).symm x = Submodule.Quotient.mk ↑x := by
rw [Equiv.symm_apply_eq, quotientEquiv_apply_mk b ↑x, Subtype.ext_iff, fractRestrict_apply]
exact (fract_eq_self.mpr x.prop).symm
end NormedLatticeField
section Real
theorem discreteTopology_pi_basisFun [Finite ι] :
DiscreteTopology (span ℤ (Set.range (Pi.basisFun ℝ ι))) := by
cases nonempty_fintype ι
refine discreteTopology_iff_isOpen_singleton_zero.mpr ⟨Metric.ball 0 1, Metric.isOpen_ball, ?_⟩
ext x
rw [Set.mem_preimage, mem_ball_zero_iff, pi_norm_lt_iff zero_lt_one, Set.mem_singleton_iff]
simp_rw [← coe_eq_zero, Function.funext_iff, Pi.zero_apply, Real.norm_eq_abs]
refine forall_congr' (fun i => ?_)
rsuffices ⟨y, hy⟩ : ∃ (y : ℤ), (y : ℝ) = (x : ι → ℝ) i
· rw [← hy, ← Int.cast_abs, ← Int.cast_one, Int.cast_lt, Int.abs_lt_one_iff, Int.cast_eq_zero]
exact ((Pi.basisFun ℝ ι).mem_span_iff_repr_mem ℤ x).mp (SetLike.coe_mem x) i
variable [NormedAddCommGroup E] [NormedSpace ℝ E] (b : Basis ι ℝ E)
theorem fundamentalDomain_subset_parallelepiped [Fintype ι] :
fundamentalDomain b ⊆ parallelepiped b := by
rw [fundamentalDomain, parallelepiped_basis_eq, Set.setOf_subset_setOf]
exact fun _ h i ↦ Set.Ico_subset_Icc_self (h i)
instance [Finite ι] : DiscreteTopology (span ℤ (Set.range b)) := by
have h : Set.MapsTo b.equivFun (span ℤ (Set.range b)) (span ℤ (Set.range (Pi.basisFun ℝ ι))) := by
intro _ hx
rwa [SetLike.mem_coe, Basis.mem_span_iff_repr_mem] at hx ⊢
convert DiscreteTopology.of_continuous_injective ((continuous_equivFun_basis b).restrict h) ?_
· exact discreteTopology_pi_basisFun
· refine Subtype.map_injective _ (Basis.equivFun b).injective
instance [Finite ι] : DiscreteTopology (span ℤ (Set.range b)).toAddSubgroup :=
inferInstanceAs <| DiscreteTopology (span ℤ (Set.range b))
@[measurability]
theorem fundamentalDomain_measurableSet [MeasurableSpace E] [OpensMeasurableSpace E] [Finite ι] :
MeasurableSet (fundamentalDomain b) := by
cases nonempty_fintype ι
haveI : FiniteDimensional ℝ E := FiniteDimensional.of_fintype_basis b
let D : Set (ι → ℝ) := Set.pi Set.univ fun _ : ι => Set.Ico (0 : ℝ) 1
rw [(_ : fundamentalDomain b = b.equivFun.toLinearMap ⁻¹' D)]
· refine measurableSet_preimage (LinearMap.continuous_of_finiteDimensional _).measurable ?_
exact MeasurableSet.pi Set.countable_univ fun _ _ => measurableSet_Ico
· ext
simp only [D, fundamentalDomain, Set.mem_Ico, Set.mem_setOf_eq, LinearEquiv.coe_coe,
Set.mem_preimage, Basis.equivFun_apply, Set.mem_pi, Set.mem_univ, forall_true_left]
/-- For a ℤ-lattice `Submodule.span ℤ (Set.range b)`, proves that the set defined
by `Zspan.fundamentalDomain` is a fundamental domain. -/
protected theorem isAddFundamentalDomain [Finite ι] [MeasurableSpace E] [OpensMeasurableSpace E]
(μ : Measure E) :
IsAddFundamentalDomain (span ℤ (Set.range b)).toAddSubgroup (fundamentalDomain b) μ := by
cases nonempty_fintype ι
exact IsAddFundamentalDomain.mk' (nullMeasurableSet (fundamentalDomain_measurableSet b))
fun x => exist_unique_vadd_mem_fundamentalDomain b x
theorem measure_fundamentalDomain_ne_zero [Finite ι] [MeasurableSpace E] [BorelSpace E]
{μ : Measure E} [Measure.IsAddHaarMeasure μ] :
μ (fundamentalDomain b) ≠ 0 := by
convert (Zspan.isAddFundamentalDomain b μ).measure_ne_zero (NeZero.ne μ)
simp only [mem_toAddSubgroup]
infer_instance
theorem measure_fundamentalDomain [Fintype ι] [DecidableEq ι] [MeasurableSpace E] (μ : Measure E)
[BorelSpace E] [Measure.IsAddHaarMeasure μ] (b₀ : Basis ι ℝ E) :
μ (fundamentalDomain b) = ENNReal.ofReal |b₀.det b| * μ (fundamentalDomain b₀) := by
have : FiniteDimensional ℝ E := FiniteDimensional.of_fintype_basis b
convert μ.addHaar_preimage_linearEquiv (b.equiv b₀ (Equiv.refl ι)) (fundamentalDomain b₀)
· rw [Set.eq_preimage_iff_image_eq (LinearEquiv.bijective _), map_fundamentalDomain,
Basis.map_equiv, Equiv.refl_symm, Basis.reindex_refl]
· rw [← LinearMap.det_toMatrix b₀, Basis.equiv_symm, Equiv.refl_symm, Basis.det_apply]
congr
ext
simp [Basis.toMatrix_apply, LinearMap.toMatrix_apply, LinearEquiv.coe_coe, Basis.equiv_apply]
@[simp]
theorem volume_fundamentalDomain [Fintype ι] [DecidableEq ι] (b : Basis ι ℝ (ι → ℝ)) :
volume (fundamentalDomain b) = ENNReal.ofReal |(Matrix.of b).det| := by
rw [measure_fundamentalDomain b volume (b₀ := Pi.basisFun ℝ ι), fundamentalDomain_pi_basisFun,
volume_pi, Measure.pi_pi, Real.volume_Ico, sub_zero, ENNReal.ofReal_one, Finset.prod_const_one,
mul_one, ← Matrix.det_transpose]
rfl
theorem fundamentalDomain_ae_parallelepiped [Fintype ι] [MeasurableSpace E] (μ : Measure E)
[BorelSpace E] [Measure.IsAddHaarMeasure μ] :
fundamentalDomain b =ᵐ[μ] parallelepiped b := by
classical
have : FiniteDimensional ℝ E := FiniteDimensional.of_fintype_basis b
rw [← measure_symmDiff_eq_zero_iff, symmDiff_of_le (fundamentalDomain_subset_parallelepiped b)]
suffices (parallelepiped b \ fundamentalDomain b) ⊆ ⋃ i,
AffineSubspace.mk' (b i) (span ℝ (b '' (Set.univ \ {i}))) by
refine measure_mono_null this
(measure_iUnion_null_iff.mpr fun i ↦ Measure.addHaar_affineSubspace μ _ ?_)
refine (ne_of_mem_of_not_mem' (AffineSubspace.mem_top _ _ 0)
(AffineSubspace.mem_mk'_iff_vsub_mem.not.mpr ?_)).symm
simp_rw [vsub_eq_sub, zero_sub, neg_mem_iff]
exact linearIndependent_iff_not_mem_span.mp b.linearIndependent i
intro x hx
simp_rw [parallelepiped_basis_eq, Set.mem_Icc, Set.mem_diff, Set.mem_setOf_eq,
mem_fundamentalDomain, Set.mem_Ico, not_forall, not_and, not_lt] at hx
obtain ⟨i, hi⟩ := hx.2
have : b.repr x i = 1 := le_antisymm (hx.1 i).2 (hi (hx.1 i).1)
rw [← b.sum_repr x, ← Finset.sum_erase_add _ _ (Finset.mem_univ i), this, one_smul, ← vadd_eq_add]
refine Set.mem_iUnion.mpr ⟨i, AffineSubspace.vadd_mem_mk' _
(sum_smul_mem _ _ (fun i hi ↦ Submodule.subset_span ?_))⟩
exact ⟨i, Set.mem_diff_singleton.mpr ⟨trivial, Finset.ne_of_mem_erase hi⟩, rfl⟩
end Real
end Zspan
section Zlattice
open Submodule FiniteDimensional
-- TODO: generalize this class to other rings than `ℤ`
/-- An `L : Addsubgroup E` where `E` is a vector space over a normed field `K` is a `ℤ`-lattice if
it is discrete and spans `E` over `K`. -/
class IsZlattice (K : Type*) [NormedField K] {E : Type*} [NormedAddCommGroup E] [NormedSpace K E]
(L : AddSubgroup E) [DiscreteTopology L] : Prop where
/-- `L` spans the full space `E` over `K`. -/
span_top : span K (L : Set E) = ⊤
theorem _root_.Zspan.isZlattice {E ι : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E]
[Finite ι] (b : Basis ι ℝ E) :
IsZlattice ℝ (span ℤ (Set.range b)).toAddSubgroup where
span_top := Zspan.span_top b
variable (K : Type*) [NormedLinearOrderedField K] [HasSolidNorm K] [FloorRing K]
variable {E : Type*} [NormedAddCommGroup E] [NormedSpace K E] [FiniteDimensional K E]
variable [ProperSpace E] (L : AddSubgroup E) [DiscreteTopology L]
theorem Zlattice.FG [hs : IsZlattice K L] : AddSubgroup.FG L := by
suffices (AddSubgroup.toIntSubmodule L).FG by exact (fg_iff_add_subgroup_fg _).mp this
obtain ⟨s, ⟨h_incl, ⟨h_span, h_lind⟩⟩⟩ := exists_linearIndependent K (L : Set E)
-- Let `s` be a maximal `K`-linear independent family of elements of `L`. We show that
-- `L` is finitely generated (as a ℤ-module) because it fits in the exact sequence
-- `0 → span ℤ s → L → L ⧸ span ℤ s → 0` with `span ℤ s` and `L ⧸ span ℤ s` finitely generated.
refine fg_of_fg_map_of_fg_inf_ker (span ℤ s).mkQ ?_ ?_
· -- Let `b` be the `K`-basis of `E` formed by the vectors in `s`. The elements of
-- `L ⧸ span ℤ s = L ⧸ span ℤ b` are in bijection with elements of `L ∩ fundamentalDomain b`
-- so there are finitely many since `fundamentalDomain b` is bounded.
refine fg_def.mpr ⟨map (span ℤ s).mkQ (AddSubgroup.toIntSubmodule L), ?_, span_eq _⟩
let b := Basis.mk h_lind (by
rw [← hs.span_top, ← h_span]
exact span_mono (by simp only [Subtype.range_coe_subtype, Set.setOf_mem_eq, subset_rfl]))
rw [show span ℤ s = span ℤ (Set.range b) by simp [b, Basis.coe_mk, Subtype.range_coe_subtype]]
have : Fintype s := h_lind.setFinite.fintype
refine Set.Finite.of_finite_image (f := ((↑) : _ → E) ∘ Zspan.quotientEquiv b) ?_
(Function.Injective.injOn (Subtype.coe_injective.comp (Zspan.quotientEquiv b).injective))
have : Set.Finite ((Zspan.fundamentalDomain b) ∩ L) :=
Metric.finite_isBounded_inter_isClosed (Zspan.fundamentalDomain_isBounded b) inferInstance
refine Set.Finite.subset this ?_
rintro _ ⟨_, ⟨⟨x, ⟨h_mem, rfl⟩⟩, rfl⟩⟩
rw [Function.comp_apply, mkQ_apply, Zspan.quotientEquiv_apply_mk, Zspan.fractRestrict_apply]
refine ⟨?_, ?_⟩
· exact Zspan.fract_mem_fundamentalDomain b x
· rw [Zspan.fract, SetLike.mem_coe, sub_eq_add_neg]
refine AddSubgroup.add_mem _ h_mem
(neg_mem (Set.mem_of_subset_of_mem ?_ (Subtype.mem (Zspan.floor b x))))
rw [show (L : Set E) = AddSubgroup.toIntSubmodule L by rfl]
rw [SetLike.coe_subset_coe, Basis.coe_mk, Subtype.range_coe_subtype, Set.setOf_mem_eq]
exact span_le.mpr h_incl
· -- `span ℤ s` is finitely generated because `s` is finite
rw [ker_mkQ, inf_of_le_right (span_le.mpr h_incl)]
exact fg_span (LinearIndependent.setFinite h_lind)
theorem Zlattice.module_finite [IsZlattice K L] : Module.Finite ℤ L :=
Module.Finite.iff_addGroup_fg.mpr ((AddGroup.fg_iff_addSubgroup_fg L).mpr (FG K L))
instance instModuleFinite_of_discrete_addSubgroup {E : Type*} [NormedAddCommGroup E]
[NormedSpace ℝ E] [FiniteDimensional ℝ E] (L : AddSubgroup E) [DiscreteTopology L] :
Module.Finite ℤ L := by
let f := (span ℝ (L : Set E)).subtype
let L₀ := (AddSubgroup.toIntSubmodule L).comap (f.restrictScalars ℤ)
have h_img : f '' L₀ = L := by
rw [← LinearMap.coe_restrictScalars ℤ f, ← Submodule.map_coe (f.restrictScalars ℤ),
Submodule.map_comap_eq_self, AddSubgroup.coe_toIntSubmodule]
exact fun x hx ↦ LinearMap.mem_range.mpr ⟨⟨x, Submodule.subset_span hx⟩, rfl⟩
suffices Module.Finite ℤ L₀ by
have : L₀.map (f.restrictScalars ℤ) = (AddSubgroup.toIntSubmodule L) :=
SetLike.ext'_iff.mpr h_img
convert this ▸ Module.Finite.map L₀ (f.restrictScalars ℤ)
have : DiscreteTopology L₀.toAddSubgroup := by
refine DiscreteTopology.preimage_of_continuous_injective (L : Set E) ?_ (injective_subtype _)
exact LinearMap.continuous_of_finiteDimensional f
have : IsZlattice ℝ L₀.toAddSubgroup := ⟨by
rw [← (Submodule.map_injective_of_injective (injective_subtype _)).eq_iff, Submodule.map_span,
Submodule.map_top, range_subtype, coe_toAddSubgroup, h_img]⟩
exact Zlattice.module_finite ℝ L₀.toAddSubgroup
theorem Zlattice.module_free [IsZlattice K L] : Module.Free ℤ L := by
have : Module.Finite ℤ L := module_finite K L
have : Module ℚ E := Module.compHom E (algebraMap ℚ K)
have : NoZeroSMulDivisors ℤ E := RatModule.noZeroSMulDivisors
have : NoZeroSMulDivisors ℤ L := by
change NoZeroSMulDivisors ℤ (AddSubgroup.toIntSubmodule L)
exact noZeroSMulDivisors _
infer_instance
instance instModuleFree_of_discrete_addSubgroup {E : Type*} [NormedAddCommGroup E]
[NormedSpace ℝ E] [FiniteDimensional ℝ E] (L : AddSubgroup E) [DiscreteTopology L] :
Module.Free ℤ L := by
have : Module ℚ E := Module.compHom E (algebraMap ℚ ℝ)
have : NoZeroSMulDivisors ℤ E := RatModule.noZeroSMulDivisors
have : NoZeroSMulDivisors ℤ L := by
change NoZeroSMulDivisors ℤ (AddSubgroup.toIntSubmodule L)
exact noZeroSMulDivisors _
infer_instance
theorem Zlattice.rank [hs : IsZlattice K L] : finrank ℤ L = finrank K E := by
classical
have : Module.Finite ℤ L := module_finite K L
have : Module.Free ℤ L := module_free K L
have : Module ℚ E := Module.compHom E (algebraMap ℚ K)
let b₀ := Module.Free.chooseBasis ℤ L
-- Let `b` be a `ℤ`-basis of `L` formed of vectors of `E`
let b := Subtype.val ∘ b₀
have : LinearIndependent ℤ b :=
LinearIndependent.map' b₀.linearIndependent (L.toIntSubmodule.subtype) (ker_subtype _)
-- We prove some assertions that will be useful later on
have h_spanL : span ℤ (Set.range b) = AddSubgroup.toIntSubmodule L := by
convert congrArg (map (Submodule.subtype (AddSubgroup.toIntSubmodule L))) b₀.span_eq
· rw [map_span, Set.range_comp]
rfl
· exact (map_subtype_top _).symm
have h_spanE : span K (Set.range b) = ⊤ := by
rw [← span_span_of_tower (R := ℤ), h_spanL]
exact hs.span_top
have h_card : Fintype.card (Module.Free.ChooseBasisIndex ℤ L) =
(Set.range b).toFinset.card := by
rw [Set.toFinset_range, Finset.univ.card_image_of_injective]
· rfl
· exact Subtype.coe_injective.comp (Basis.injective _)
rw [finrank_eq_card_chooseBasisIndex]
-- We prove that `finrank ℤ L ≤ finrank K E` and `finrank K E ≤ finrank ℤ L`
refine le_antisymm ?_ ?_
· -- To prove that `finrank ℤ L ≤ finrank K E`, we proceed by contradiction and prove that, in
-- this case, there is a ℤ-relation between the vectors of `b`
obtain ⟨t, ⟨ht_inc, ⟨ht_span, ht_lin⟩⟩⟩ := exists_linearIndependent K (Set.range b)
-- `e` is a `K`-basis of `E` formed of vectors of `b`
let e : Basis t K E := Basis.mk ht_lin (by simp [ht_span, h_spanE])
have : Fintype t := Set.Finite.fintype ((Set.range b).toFinite.subset ht_inc)
have h : LinearIndependent ℤ (fun x : (Set.range b) => (x : E)) := by
rwa [linearIndependent_subtype_range (Subtype.coe_injective.comp b₀.injective)]
contrapose! h
-- Since `finrank ℤ L > finrank K E`, there exists a vector `v ∈ b` with `v ∉ e`
obtain ⟨v, hv⟩ : (Set.range b \ Set.range e).Nonempty := by
rw [Basis.coe_mk, Subtype.range_coe_subtype, Set.setOf_mem_eq, ← Set.toFinset_nonempty]
contrapose h
rw [Finset.not_nonempty_iff_eq_empty, Set.toFinset_diff,
Finset.sdiff_eq_empty_iff_subset] at h
replace h := Finset.card_le_card h
rwa [not_lt, h_card, ← topEquiv.finrank_eq, ← h_spanE, ← ht_span,
finrank_span_set_eq_card ht_lin]
-- Assume that `e ∪ {v}` is not `ℤ`-linear independent then we get the contradiction
suffices ¬ LinearIndependent ℤ (fun x : ↥(insert v (Set.range e)) => (x : E)) by
contrapose! this
refine LinearIndependent.mono ?_ this
exact Set.insert_subset (Set.mem_of_mem_diff hv) (by simp [e, ht_inc])
-- We prove finally that `e ∪ {v}` is not ℤ-linear independent or, equivalently,
-- not ℚ-linear independent by showing that `v ∈ span ℚ e`.
rw [LinearIndependent.iff_fractionRing ℤ ℚ,
linearIndependent_insert (Set.not_mem_of_mem_diff hv), not_and, not_not]
intro _
-- But that follows from the fact that there exist `n, m : ℕ`, `n ≠ m`
-- such that `(n - m) • v ∈ span ℤ e` which is true since `n ↦ Zspan.fract e (n • v)`
-- takes value into the finite set `fundamentalDomain e ∩ L`
have h_mapsto : Set.MapsTo (fun n : ℤ => Zspan.fract e (n • v)) Set.univ
(Metric.closedBall 0 (∑ i, ‖e i‖) ∩ (L : Set E)) := by
rw [Set.mapsTo_inter, Set.mapsTo_univ_iff, Set.mapsTo_univ_iff]
refine ⟨fun _ ↦ mem_closedBall_zero_iff.mpr (Zspan.norm_fract_le e _), fun _ => ?_⟩
· change _ ∈ AddSubgroup.toIntSubmodule L
rw [← h_spanL]
refine sub_mem ?_ ?_
· exact zsmul_mem (subset_span (Set.diff_subset hv)) _
· exact span_mono (by simp [e, ht_inc]) (coe_mem _)
have h_finite : Set.Finite (Metric.closedBall 0 (∑ i, ‖e i‖) ∩ (L : Set E)) :=
Metric.finite_isBounded_inter_isClosed Metric.isBounded_closedBall inferInstance
obtain ⟨n, -, m, -, h_neq, h_eq⟩ := Set.Infinite.exists_ne_map_eq_of_mapsTo
Set.infinite_univ h_mapsto h_finite
have h_nz : (-n + m : ℚ) ≠ 0 := by
rwa [Ne, add_eq_zero_iff_eq_neg.not, neg_inj, Rat.coe_int_inj, ← Ne]
apply (smul_mem_iff _ h_nz).mp
refine span_subset_span ℤ ℚ _ ?_
rwa [add_smul, neg_smul, SetLike.mem_coe, ← Zspan.fract_eq_fract, Int.cast_smul_eq_zsmul ℚ,
Int.cast_smul_eq_zsmul ℚ]
· -- To prove that `finrank K E ≤ finrank ℤ L`, we use the fact `b` generates `E` over `K`
-- and thus `finrank K E ≤ card b = finrank ℤ L`
rw [← topEquiv.finrank_eq, ← h_spanE]
convert finrank_span_le_card (R := K) (Set.range b)
open Module
variable {ι : Type*} [hs : IsZlattice K L] (b : Basis ι ℤ L)
/-- Any `ℤ`-basis of `L` is also a `K`-basis of `E`. -/
def Basis.ofZlatticeBasis :
Basis ι K E := by
have : Finite ℤ L := Zlattice.module_finite K L
have : Free ℤ L := Zlattice.module_free K L
let e := Basis.indexEquiv (Free.chooseBasis ℤ L) b
have : Fintype ι := Fintype.ofEquiv _ e
refine basisOfTopLeSpanOfCardEqFinrank (L.subtype.toIntLinearMap ∘ b) ?_ ?_
· rw [← span_span_of_tower ℤ, Set.range_comp, ← map_span, Basis.span_eq, Submodule.map_top,
top_le_iff, AddMonoidHom.coe_toIntLinearMap_range, AddSubgroup.subtype_range,
AddSubgroup.coe_toIntSubmodule, hs.span_top]
· rw [← Fintype.card_congr e, ← finrank_eq_card_chooseBasisIndex, Zlattice.rank K L]
@[simp]
theorem Basis.ofZlatticeBasis_apply (i : ι) :
b.ofZlatticeBasis K L i = b i := by simp [Basis.ofZlatticeBasis]
@[simp]
theorem Basis.ofZlatticeBasis_repr_apply (x : L) (i : ι) :
(b.ofZlatticeBasis K L).repr x i = b.repr x i := by
suffices ((b.ofZlatticeBasis K L).repr.toLinearMap.restrictScalars ℤ) ∘ₗ L.subtype.toIntLinearMap
= Finsupp.mapRange.linearMap (Algebra.linearMap ℤ K) ∘ₗ b.repr.toLinearMap by
exact DFunLike.congr_fun (LinearMap.congr_fun this x) i
refine Basis.ext b fun i ↦ ?_
simp_rw [LinearMap.coe_comp, Function.comp_apply, LinearMap.coe_restrictScalars,
LinearEquiv.coe_coe, AddMonoidHom.coe_toIntLinearMap, AddSubgroup.coeSubtype,
← b.ofZlatticeBasis_apply K, repr_self, Finsupp.mapRange.linearMap_apply,
Finsupp.mapRange_single, Algebra.linearMap_apply, map_one]
theorem Basis.ofZlatticeBasis_span :
(span ℤ (Set.range (b.ofZlatticeBasis K))).toAddSubgroup = L := by
calc (span ℤ (Set.range (b.ofZlatticeBasis K))).toAddSubgroup
_ = (span ℤ (L.subtype.toIntLinearMap '' (Set.range b))).toAddSubgroup := by congr; ext; simp
_ = (map L.subtype.toIntLinearMap (span ℤ (Set.range b))).toAddSubgroup := by
rw [Submodule.map_span]
_ = L := by simp [b.span_eq]
theorem Zlattice.isAddFundamentalDomain {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E]
[FiniteDimensional ℝ E] {L : AddSubgroup E} [DiscreteTopology L] [IsZlattice ℝ L] [Finite ι]
(b : Basis ι ℤ L) [MeasurableSpace E] [OpensMeasurableSpace E] (μ : MeasureTheory.Measure E) :
MeasureTheory.IsAddFundamentalDomain L (Zspan.fundamentalDomain (b.ofZlatticeBasis ℝ)) μ := by
convert Zspan.isAddFundamentalDomain (b.ofZlatticeBasis ℝ) μ
all_goals exact (b.ofZlatticeBasis_span ℝ).symm
instance instCountable_of_discrete_addSubgroup {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E]
[FiniteDimensional ℝ E] (L : AddSubgroup E) [DiscreteTopology L] [IsZlattice ℝ L] :
Countable L := by
simp_rw [← (Module.Free.chooseBasis ℤ L).ofZlatticeBasis_span ℝ, mem_toAddSubgroup]
infer_instance
end Zlattice
|
Algebra\Module\Zlattice\Covolume.lean | /-
Copyright (c) 2024 Xavier Roblot. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Xavier Roblot
-/
import Mathlib.Algebra.Module.Zlattice.Basic
/-!
# Covolume of ℤ-lattices
Let `E` be a finite dimensional real vector space with an inner product.
Let `L` be a `ℤ`-lattice `L` defined as a discrete `AddSubgroup E` that spans `E` over `ℝ`.
## Main definitions and results
* `Zlattice.covolume`: the covolume of `L` defined as the volume of an arbitrary fundamental
domain of `L`.
* `Zlattice.covolume_eq_measure_fundamentalDomain`: the covolume of `L` does not depend on the
choice of the fundamental domain of `L`.
* `Zlattice.covolume_eq_det`: if `L` is a lattice in `ℝ^n`, then its covolume is the absolute
value of the determinant of any `ℤ`-basis of `L`.
-/
noncomputable section
namespace Zlattice
open Submodule MeasureTheory FiniteDimensional MeasureTheory Module
section General
variable (K : Type*) [NormedLinearOrderedField K] [HasSolidNorm K] [FloorRing K]
variable {E : Type*} [NormedAddCommGroup E] [NormedSpace K E] [FiniteDimensional K E]
variable [ProperSpace E] [MeasurableSpace E]
variable (L : AddSubgroup E) [DiscreteTopology L] [IsZlattice K L]
/-- The covolume of a `ℤ`-lattice is the volume of some fundamental domain; see
`Zlattice.covolume_eq_volume` for the proof that the volume does not depend on the choice of
the fundamental domain. -/
def covolume (μ : Measure E := by volume_tac) : ℝ := (addCovolume L E μ).toReal
end General
section Real
variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [FiniteDimensional ℝ E]
variable [MeasurableSpace E] [BorelSpace E]
variable (L : AddSubgroup E) [DiscreteTopology L] [IsZlattice ℝ L]
variable (μ : Measure E := by volume_tac) [Measure.IsAddHaarMeasure μ]
theorem covolume_eq_measure_fundamentalDomain {F : Set E} (h : IsAddFundamentalDomain L F μ) :
covolume L μ = (μ F).toReal := congr_arg ENNReal.toReal (h.covolume_eq_volume μ)
theorem covolume_ne_zero : covolume L μ ≠ 0 := by
rw [covolume_eq_measure_fundamentalDomain L μ (isAddFundamentalDomain (Free.chooseBasis ℤ L) μ),
ENNReal.toReal_ne_zero]
refine ⟨Zspan.measure_fundamentalDomain_ne_zero _, ne_of_lt ?_⟩
exact Bornology.IsBounded.measure_lt_top (Zspan.fundamentalDomain_isBounded _)
theorem covolume_pos : 0 < covolume L μ :=
lt_of_le_of_ne ENNReal.toReal_nonneg (covolume_ne_zero L μ).symm
theorem covolume_eq_det_mul_measure {ι : Type*} [Fintype ι] [DecidableEq ι] (b : Basis ι ℤ L)
(b₀ : Basis ι ℝ E) :
covolume L μ = |b₀.det ((↑) ∘ b)| * (μ (Zspan.fundamentalDomain b₀)).toReal := by
rw [covolume_eq_measure_fundamentalDomain L μ (isAddFundamentalDomain b μ),
Zspan.measure_fundamentalDomain _ _ b₀,
measure_congr (Zspan.fundamentalDomain_ae_parallelepiped b₀ μ), ENNReal.toReal_mul,
ENNReal.toReal_ofReal (by positivity)]
congr
ext
exact b.ofZlatticeBasis_apply ℝ L _
theorem covolume_eq_det {ι : Type*} [Fintype ι] [DecidableEq ι] (L : AddSubgroup (ι → ℝ))
[DiscreteTopology L] [IsZlattice ℝ L] (b : Basis ι ℤ L) :
covolume L = |(Matrix.of ((↑) ∘ b)).det| := by
rw [covolume_eq_measure_fundamentalDomain L volume (isAddFundamentalDomain b volume),
Zspan.volume_fundamentalDomain, ENNReal.toReal_ofReal (by positivity)]
congr
ext1
exact b.ofZlatticeBasis_apply ℝ L _
end Real
end Zlattice
|
Algebra\MonoidAlgebra\Basic.lean | /-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Yury G. Kudryashov, Scott Morrison
-/
import Mathlib.Algebra.Algebra.Equiv
import Mathlib.Algebra.Algebra.NonUnitalHom
import Mathlib.Algebra.BigOperators.Finsupp
import Mathlib.Algebra.Module.BigOperators
import Mathlib.Data.Finsupp.Basic
import Mathlib.LinearAlgebra.Finsupp
/-!
# Monoid algebras
When the domain of a `Finsupp` has a multiplicative or additive structure, we can define
a convolution product. To mathematicians this structure is known as the "monoid algebra",
i.e. the finite formal linear combinations over a given semiring of elements of the monoid.
The "group ring" ℤ[G] or the "group algebra" k[G] are typical uses.
In fact the construction of the "monoid algebra" makes sense when `G` is not even a monoid, but
merely a magma, i.e., when `G` carries a multiplication which is not required to satisfy any
conditions at all. In this case the construction yields a not-necessarily-unital,
not-necessarily-associative algebra but it is still adjoint to the forgetful functor from such
algebras to magmas, and we prove this as `MonoidAlgebra.liftMagma`.
In this file we define `MonoidAlgebra k G := G →₀ k`, and `AddMonoidAlgebra k G`
in the same way, and then define the convolution product on these.
When the domain is additive, this is used to define polynomials:
```
Polynomial R := AddMonoidAlgebra R ℕ
MvPolynomial σ α := AddMonoidAlgebra R (σ →₀ ℕ)
```
When the domain is multiplicative, e.g. a group, this will be used to define the group ring.
## Notation
We introduce the notation `R[A]` for `AddMonoidAlgebra R A`.
## Implementation note
Unfortunately because additive and multiplicative structures both appear in both cases,
it doesn't appear to be possible to make much use of `to_additive`, and we just settle for
saying everything twice.
Similarly, I attempted to just define
`k[G] := MonoidAlgebra k (Multiplicative G)`, but the definitional equality
`Multiplicative G = G` leaks through everywhere, and seems impossible to use.
-/
noncomputable section
open Finset
open Finsupp hiding single mapDomain
universe u₁ u₂ u₃ u₄
variable (k : Type u₁) (G : Type u₂) (H : Type*) {R : Type*}
/-! ### Multiplicative monoids -/
section
variable [Semiring k]
/-- The monoid algebra over a semiring `k` generated by the monoid `G`.
It is the type of finite formal `k`-linear combinations of terms of `G`,
endowed with the convolution product.
-/
def MonoidAlgebra : Type max u₁ u₂ :=
G →₀ k
-- Porting note: The compiler couldn't derive this.
instance MonoidAlgebra.inhabited : Inhabited (MonoidAlgebra k G) :=
inferInstanceAs (Inhabited (G →₀ k))
-- Porting note: The compiler couldn't derive this.
instance MonoidAlgebra.addCommMonoid : AddCommMonoid (MonoidAlgebra k G) :=
inferInstanceAs (AddCommMonoid (G →₀ k))
instance MonoidAlgebra.instIsCancelAdd [IsCancelAdd k] : IsCancelAdd (MonoidAlgebra k G) :=
inferInstanceAs (IsCancelAdd (G →₀ k))
instance MonoidAlgebra.coeFun : CoeFun (MonoidAlgebra k G) fun _ => G → k :=
Finsupp.instCoeFun
end
namespace MonoidAlgebra
variable {k G}
section
variable [Semiring k] [NonUnitalNonAssocSemiring R]
-- Porting note: `reducible` cannot be `local`, so we replace some definitions and theorems with
-- new ones which have new types.
abbrev single (a : G) (b : k) : MonoidAlgebra k G := Finsupp.single a b
theorem single_zero (a : G) : (single a 0 : MonoidAlgebra k G) = 0 := Finsupp.single_zero a
theorem single_add (a : G) (b₁ b₂ : k) : single a (b₁ + b₂) = single a b₁ + single a b₂ :=
Finsupp.single_add a b₁ b₂
@[simp]
theorem sum_single_index {N} [AddCommMonoid N] {a : G} {b : k} {h : G → k → N}
(h_zero : h a 0 = 0) :
(single a b).sum h = h a b := Finsupp.sum_single_index h_zero
@[simp]
theorem sum_single (f : MonoidAlgebra k G) : f.sum single = f :=
Finsupp.sum_single f
theorem single_apply {a a' : G} {b : k} [Decidable (a = a')] :
single a b a' = if a = a' then b else 0 :=
Finsupp.single_apply
@[simp]
theorem single_eq_zero {a : G} {b : k} : single a b = 0 ↔ b = 0 := Finsupp.single_eq_zero
abbrev mapDomain {G' : Type*} (f : G → G') (v : MonoidAlgebra k G) : MonoidAlgebra k G' :=
Finsupp.mapDomain f v
theorem mapDomain_sum {k' G' : Type*} [Semiring k'] {f : G → G'} {s : MonoidAlgebra k' G}
{v : G → k' → MonoidAlgebra k G} :
mapDomain f (s.sum v) = s.sum fun a b => mapDomain f (v a b) :=
Finsupp.mapDomain_sum
/-- A non-commutative version of `MonoidAlgebra.lift`: given an additive homomorphism `f : k →+ R`
and a homomorphism `g : G → R`, returns the additive homomorphism from
`MonoidAlgebra k G` such that `liftNC f g (single a b) = f b * g a`. If `f` is a ring homomorphism
and the range of either `f` or `g` is in center of `R`, then the result is a ring homomorphism. If
`R` is a `k`-algebra and `f = algebraMap k R`, then the result is an algebra homomorphism called
`MonoidAlgebra.lift`. -/
def liftNC (f : k →+ R) (g : G → R) : MonoidAlgebra k G →+ R :=
liftAddHom fun x : G => (AddMonoidHom.mulRight (g x)).comp f
@[simp]
theorem liftNC_single (f : k →+ R) (g : G → R) (a : G) (b : k) :
liftNC f g (single a b) = f b * g a :=
liftAddHom_apply_single _ _ _
end
section Mul
variable [Semiring k] [Mul G]
/-- The multiplication in a monoid algebra. We make it irreducible so that Lean doesn't unfold
it trying to unify two things that are different. -/
@[irreducible] def mul' (f g : MonoidAlgebra k G) : MonoidAlgebra k G :=
f.sum fun a₁ b₁ => g.sum fun a₂ b₂ => single (a₁ * a₂) (b₁ * b₂)
/-- The product of `f g : MonoidAlgebra k G` is the finitely supported function
whose value at `a` is the sum of `f x * g y` over all pairs `x, y`
such that `x * y = a`. (Think of the group ring of a group.) -/
instance instMul : Mul (MonoidAlgebra k G) := ⟨MonoidAlgebra.mul'⟩
theorem mul_def {f g : MonoidAlgebra k G} :
f * g = f.sum fun a₁ b₁ => g.sum fun a₂ b₂ => single (a₁ * a₂) (b₁ * b₂) := by
with_unfolding_all rfl
instance nonUnitalNonAssocSemiring : NonUnitalNonAssocSemiring (MonoidAlgebra k G) :=
{ Finsupp.instAddCommMonoid with
-- Porting note: `refine` & `exact` are required because `simp` behaves differently.
left_distrib := fun f g h => by
haveI := Classical.decEq G
simp only [mul_def]
refine Eq.trans (congr_arg (sum f) (funext₂ fun a₁ b₁ => sum_add_index ?_ ?_)) ?_ <;>
simp only [mul_add, mul_zero, single_zero, single_add, forall_true_iff, sum_add]
right_distrib := fun f g h => by
haveI := Classical.decEq G
simp only [mul_def]
refine Eq.trans (sum_add_index ?_ ?_) ?_ <;>
simp only [add_mul, zero_mul, single_zero, single_add, forall_true_iff, sum_zero, sum_add]
zero_mul := fun f => by
simp only [mul_def]
exact sum_zero_index
mul_zero := fun f => by
simp only [mul_def]
exact Eq.trans (congr_arg (sum f) (funext₂ fun a₁ b₁ => sum_zero_index)) sum_zero }
variable [Semiring R]
theorem liftNC_mul {g_hom : Type*} [FunLike g_hom G R] [MulHomClass g_hom G R]
(f : k →+* R) (g : g_hom) (a b : MonoidAlgebra k G)
(h_comm : ∀ {x y}, y ∈ a.support → Commute (f (b x)) (g y)) :
liftNC (f : k →+ R) g (a * b) = liftNC (f : k →+ R) g a * liftNC (f : k →+ R) g b := by
conv_rhs => rw [← sum_single a, ← sum_single b]
-- Porting note: `(liftNC _ g).map_finsupp_sum` → `map_finsupp_sum`
simp_rw [mul_def, map_finsupp_sum, liftNC_single, Finsupp.sum_mul, Finsupp.mul_sum]
refine Finset.sum_congr rfl fun y hy => Finset.sum_congr rfl fun x _hx => ?_
simp [mul_assoc, (h_comm hy).left_comm]
end Mul
section Semigroup
variable [Semiring k] [Semigroup G] [Semiring R]
instance nonUnitalSemiring : NonUnitalSemiring (MonoidAlgebra k G) :=
{ MonoidAlgebra.nonUnitalNonAssocSemiring with
mul_assoc := fun f g h => by
-- Porting note: `reducible` cannot be `local` so proof gets long.
simp only [mul_def]
rw [sum_sum_index]; congr; ext a₁ b₁
rw [sum_sum_index, sum_sum_index]; congr; ext a₂ b₂
rw [sum_sum_index, sum_single_index]; congr; ext a₃ b₃
rw [sum_single_index, mul_assoc, mul_assoc]
all_goals simp only [single_zero, single_add, forall_true_iff, add_mul,
mul_add, zero_mul, mul_zero, sum_zero, sum_add] }
end Semigroup
section One
variable [NonAssocSemiring R] [Semiring k] [One G]
/-- The unit of the multiplication is `single 1 1`, i.e. the function
that is `1` at `1` and zero elsewhere. -/
instance one : One (MonoidAlgebra k G) :=
⟨single 1 1⟩
theorem one_def : (1 : MonoidAlgebra k G) = single 1 1 :=
rfl
@[simp]
theorem liftNC_one {g_hom : Type*} [FunLike g_hom G R] [OneHomClass g_hom G R]
(f : k →+* R) (g : g_hom) :
liftNC (f : k →+ R) g 1 = 1 := by simp [one_def]
end One
section MulOneClass
variable [Semiring k] [MulOneClass G]
instance nonAssocSemiring : NonAssocSemiring (MonoidAlgebra k G) :=
{ MonoidAlgebra.nonUnitalNonAssocSemiring with
natCast := fun n => single 1 n
natCast_zero := by simp
natCast_succ := fun _ => by simp; rfl
one_mul := fun f => by
simp only [mul_def, one_def, sum_single_index, zero_mul, single_zero, sum_zero, zero_add,
one_mul, sum_single]
mul_one := fun f => by
simp only [mul_def, one_def, sum_single_index, mul_zero, single_zero, sum_zero, add_zero,
mul_one, sum_single] }
theorem natCast_def (n : ℕ) : (n : MonoidAlgebra k G) = single (1 : G) (n : k) :=
rfl
@[deprecated (since := "2024-04-17")]
alias nat_cast_def := natCast_def
end MulOneClass
/-! #### Semiring structure -/
section Semiring
variable [Semiring k] [Monoid G]
instance semiring : Semiring (MonoidAlgebra k G) :=
{ MonoidAlgebra.nonUnitalSemiring,
MonoidAlgebra.nonAssocSemiring with }
variable [Semiring R]
/-- `liftNC` as a `RingHom`, for when `f x` and `g y` commute -/
def liftNCRingHom (f : k →+* R) (g : G →* R) (h_comm : ∀ x y, Commute (f x) (g y)) :
MonoidAlgebra k G →+* R :=
{ liftNC (f : k →+ R) g with
map_one' := liftNC_one _ _
map_mul' := fun _a _b => liftNC_mul _ _ _ _ fun {_ _} _ => h_comm _ _ }
end Semiring
instance nonUnitalCommSemiring [CommSemiring k] [CommSemigroup G] :
NonUnitalCommSemiring (MonoidAlgebra k G) :=
{ MonoidAlgebra.nonUnitalSemiring with
mul_comm := fun f g => by
simp only [mul_def, Finsupp.sum, mul_comm]
rw [Finset.sum_comm]
simp only [mul_comm] }
instance nontrivial [Semiring k] [Nontrivial k] [Nonempty G] : Nontrivial (MonoidAlgebra k G) :=
Finsupp.instNontrivial
/-! #### Derived instances -/
section DerivedInstances
instance commSemiring [CommSemiring k] [CommMonoid G] : CommSemiring (MonoidAlgebra k G) :=
{ MonoidAlgebra.nonUnitalCommSemiring, MonoidAlgebra.semiring with }
instance unique [Semiring k] [Subsingleton k] : Unique (MonoidAlgebra k G) :=
Finsupp.uniqueOfRight
instance addCommGroup [Ring k] : AddCommGroup (MonoidAlgebra k G) :=
Finsupp.instAddCommGroup
instance nonUnitalNonAssocRing [Ring k] [Mul G] : NonUnitalNonAssocRing (MonoidAlgebra k G) :=
{ MonoidAlgebra.addCommGroup, MonoidAlgebra.nonUnitalNonAssocSemiring with }
instance nonUnitalRing [Ring k] [Semigroup G] : NonUnitalRing (MonoidAlgebra k G) :=
{ MonoidAlgebra.addCommGroup, MonoidAlgebra.nonUnitalSemiring with }
instance nonAssocRing [Ring k] [MulOneClass G] : NonAssocRing (MonoidAlgebra k G) :=
{ MonoidAlgebra.addCommGroup,
MonoidAlgebra.nonAssocSemiring with
intCast := fun z => single 1 (z : k)
-- Porting note: Both were `simpa`.
intCast_ofNat := fun n => by simp; rfl
intCast_negSucc := fun n => by simp; rfl }
theorem intCast_def [Ring k] [MulOneClass G] (z : ℤ) :
(z : MonoidAlgebra k G) = single (1 : G) (z : k) :=
rfl
@[deprecated (since := "2024-04-17")]
alias int_cast_def := intCast_def
instance ring [Ring k] [Monoid G] : Ring (MonoidAlgebra k G) :=
{ MonoidAlgebra.nonAssocRing, MonoidAlgebra.semiring with }
instance nonUnitalCommRing [CommRing k] [CommSemigroup G] :
NonUnitalCommRing (MonoidAlgebra k G) :=
{ MonoidAlgebra.nonUnitalCommSemiring, MonoidAlgebra.nonUnitalRing with }
instance commRing [CommRing k] [CommMonoid G] : CommRing (MonoidAlgebra k G) :=
{ MonoidAlgebra.nonUnitalCommRing, MonoidAlgebra.ring with }
variable {S : Type*}
instance smulZeroClass [Semiring k] [SMulZeroClass R k] : SMulZeroClass R (MonoidAlgebra k G) :=
Finsupp.smulZeroClass
instance distribSMul [Semiring k] [DistribSMul R k] : DistribSMul R (MonoidAlgebra k G) :=
Finsupp.distribSMul _ _
instance distribMulAction [Monoid R] [Semiring k] [DistribMulAction R k] :
DistribMulAction R (MonoidAlgebra k G) :=
Finsupp.distribMulAction G k
instance module [Semiring R] [Semiring k] [Module R k] : Module R (MonoidAlgebra k G) :=
Finsupp.module G k
instance faithfulSMul [Semiring k] [SMulZeroClass R k] [FaithfulSMul R k] [Nonempty G] :
FaithfulSMul R (MonoidAlgebra k G) :=
Finsupp.faithfulSMul
instance isScalarTower [Semiring k] [SMulZeroClass R k] [SMulZeroClass S k] [SMul R S]
[IsScalarTower R S k] : IsScalarTower R S (MonoidAlgebra k G) :=
Finsupp.isScalarTower G k
instance smulCommClass [Semiring k] [SMulZeroClass R k] [SMulZeroClass S k] [SMulCommClass R S k] :
SMulCommClass R S (MonoidAlgebra k G) :=
Finsupp.smulCommClass G k
instance isCentralScalar [Semiring k] [SMulZeroClass R k] [SMulZeroClass Rᵐᵒᵖ k]
[IsCentralScalar R k] : IsCentralScalar R (MonoidAlgebra k G) :=
Finsupp.isCentralScalar G k
/-- This is not an instance as it conflicts with `MonoidAlgebra.distribMulAction` when `G = kˣ`.
-/
def comapDistribMulActionSelf [Group G] [Semiring k] : DistribMulAction G (MonoidAlgebra k G) :=
Finsupp.comapDistribMulAction
end DerivedInstances
section MiscTheorems
variable [Semiring k]
-- attribute [local reducible] MonoidAlgebra -- Porting note: `reducible` cannot be `local`.
theorem mul_apply [DecidableEq G] [Mul G] (f g : MonoidAlgebra k G) (x : G) :
(f * g) x = f.sum fun a₁ b₁ => g.sum fun a₂ b₂ => if a₁ * a₂ = x then b₁ * b₂ else 0 := by
-- Porting note: `reducible` cannot be `local` so proof gets long.
rw [mul_def, Finsupp.sum_apply]; congr; ext
rw [Finsupp.sum_apply]; congr; ext
apply single_apply
theorem mul_apply_antidiagonal [Mul G] (f g : MonoidAlgebra k G) (x : G) (s : Finset (G × G))
(hs : ∀ {p : G × G}, p ∈ s ↔ p.1 * p.2 = x) : (f * g) x = ∑ p ∈ s, f p.1 * g p.2 := by
classical exact
let F : G × G → k := fun p => if p.1 * p.2 = x then f p.1 * g p.2 else 0
calc
(f * g) x = ∑ a₁ ∈ f.support, ∑ a₂ ∈ g.support, F (a₁, a₂) := mul_apply f g x
_ = ∑ p ∈ f.support ×ˢ g.support, F p := Finset.sum_product.symm
_ = ∑ p ∈ (f.support ×ˢ g.support).filter fun p : G × G => p.1 * p.2 = x, f p.1 * g p.2 :=
(Finset.sum_filter _ _).symm
_ = ∑ p ∈ s.filter fun p : G × G => p.1 ∈ f.support ∧ p.2 ∈ g.support, f p.1 * g p.2 :=
(sum_congr
(by
ext
simp only [mem_filter, mem_product, hs, and_comm])
fun _ _ => rfl)
_ = ∑ p ∈ s, f p.1 * g p.2 :=
sum_subset (filter_subset _ _) fun p hps hp => by
simp only [mem_filter, mem_support_iff, not_and, Classical.not_not] at hp ⊢
by_cases h1 : f p.1 = 0
· rw [h1, zero_mul]
· rw [hp hps h1, mul_zero]
@[simp]
theorem single_mul_single [Mul G] {a₁ a₂ : G} {b₁ b₂ : k} :
single a₁ b₁ * single a₂ b₂ = single (a₁ * a₂) (b₁ * b₂) := by
rw [mul_def]
exact (sum_single_index (by simp only [zero_mul, single_zero, sum_zero])).trans
(sum_single_index (by rw [mul_zero, single_zero]))
theorem single_commute_single [Mul G] {a₁ a₂ : G} {b₁ b₂ : k}
(ha : Commute a₁ a₂) (hb : Commute b₁ b₂) :
Commute (single a₁ b₁) (single a₂ b₂) :=
single_mul_single.trans <| congr_arg₂ single ha hb |>.trans single_mul_single.symm
theorem single_commute [Mul G] {a : G} {b : k} (ha : ∀ a', Commute a a') (hb : ∀ b', Commute b b') :
∀ f : MonoidAlgebra k G, Commute (single a b) f :=
suffices AddMonoidHom.mulLeft (single a b) = AddMonoidHom.mulRight (single a b) from
DFunLike.congr_fun this
addHom_ext' fun a' => AddMonoidHom.ext fun b' => single_commute_single (ha a') (hb b')
@[simp]
theorem single_pow [Monoid G] {a : G} {b : k} : ∀ n : ℕ, single a b ^ n = single (a ^ n) (b ^ n)
| 0 => by
simp only [pow_zero]
rfl
| n + 1 => by simp only [pow_succ, single_pow n, single_mul_single]
section
/-- Like `Finsupp.mapDomain_zero`, but for the `1` we define in this file -/
@[simp]
theorem mapDomain_one {α : Type*} {β : Type*} {α₂ : Type*} [Semiring β] [One α] [One α₂]
{F : Type*} [FunLike F α α₂] [OneHomClass F α α₂] (f : F) :
(mapDomain f (1 : MonoidAlgebra β α) : MonoidAlgebra β α₂) = (1 : MonoidAlgebra β α₂) := by
simp_rw [one_def, mapDomain_single, map_one]
/-- Like `Finsupp.mapDomain_add`, but for the convolutive multiplication we define in this file -/
theorem mapDomain_mul {α : Type*} {β : Type*} {α₂ : Type*} [Semiring β] [Mul α] [Mul α₂]
{F : Type*} [FunLike F α α₂] [MulHomClass F α α₂] (f : F) (x y : MonoidAlgebra β α) :
mapDomain f (x * y) = mapDomain f x * mapDomain f y := by
simp_rw [mul_def, mapDomain_sum, mapDomain_single, map_mul]
rw [Finsupp.sum_mapDomain_index]
· congr
ext a b
rw [Finsupp.sum_mapDomain_index]
· simp
· simp [mul_add]
· simp
· simp [add_mul]
variable (k G)
/-- The embedding of a magma into its magma algebra. -/
@[simps]
def ofMagma [Mul G] : G →ₙ* MonoidAlgebra k G where
toFun a := single a 1
map_mul' a b := by simp only [mul_def, mul_one, sum_single_index, single_eq_zero, mul_zero]
/-- The embedding of a unital magma into its magma algebra. -/
@[simps]
def of [MulOneClass G] : G →* MonoidAlgebra k G :=
{ ofMagma k G with
toFun := fun a => single a 1
map_one' := rfl }
end
theorem smul_of [MulOneClass G] (g : G) (r : k) : r • of k G g = single g r := by
-- porting note (#10745): was `simp`.
rw [of_apply, smul_single', mul_one]
theorem of_injective [MulOneClass G] [Nontrivial k] :
Function.Injective (of k G) := fun a b h => by
simpa using (single_eq_single_iff _ _ _ _).mp h
theorem of_commute [MulOneClass G] {a : G} (h : ∀ a', Commute a a') (f : MonoidAlgebra k G) :
Commute (of k G a) f :=
single_commute h Commute.one_left f
/-- `Finsupp.single` as a `MonoidHom` from the product type into the monoid algebra.
Note the order of the elements of the product are reversed compared to the arguments of
`Finsupp.single`.
-/
@[simps]
def singleHom [MulOneClass G] : k × G →* MonoidAlgebra k G where
toFun a := single a.2 a.1
map_one' := rfl
map_mul' _a _b := single_mul_single.symm
theorem mul_single_apply_aux [Mul G] (f : MonoidAlgebra k G) {r : k} {x y z : G}
(H : ∀ a, a * x = z ↔ a = y) : (f * single x r) z = f y * r := by
classical exact
have A :
∀ a₁ b₁,
((single x r).sum fun a₂ b₂ => ite (a₁ * a₂ = z) (b₁ * b₂) 0) =
ite (a₁ * x = z) (b₁ * r) 0 :=
fun a₁ b₁ => sum_single_index <| by simp
calc
(HMul.hMul (β := MonoidAlgebra k G) f (single x r)) z =
sum f fun a b => if a = y then b * r else 0 := by simp only [mul_apply, A, H]
_ = if y ∈ f.support then f y * r else 0 := f.support.sum_ite_eq' _ _
_ = f y * r := by split_ifs with h <;> simp at h <;> simp [h]
theorem mul_single_one_apply [MulOneClass G] (f : MonoidAlgebra k G) (r : k) (x : G) :
(HMul.hMul (β := MonoidAlgebra k G) f (single 1 r)) x = f x * r :=
f.mul_single_apply_aux fun a => by rw [mul_one]
theorem mul_single_apply_of_not_exists_mul [Mul G] (r : k) {g g' : G} (x : MonoidAlgebra k G)
(h : ¬∃ d, g' = d * g) : (x * single g r) g' = 0 := by
classical
rw [mul_apply, Finsupp.sum_comm, Finsupp.sum_single_index]
swap
· simp_rw [Finsupp.sum, mul_zero, ite_self, Finset.sum_const_zero]
· apply Finset.sum_eq_zero
simp_rw [ite_eq_right_iff]
rintro g'' _hg'' rfl
exfalso
exact h ⟨_, rfl⟩
theorem single_mul_apply_aux [Mul G] (f : MonoidAlgebra k G) {r : k} {x y z : G}
(H : ∀ a, x * a = y ↔ a = z) : (single x r * f) y = r * f z := by
classical exact
have : (f.sum fun a b => ite (x * a = y) (0 * b) 0) = 0 := by simp
calc
(HMul.hMul (α := MonoidAlgebra k G) (single x r) f) y =
sum f fun a b => ite (x * a = y) (r * b) 0 :=
(mul_apply _ _ _).trans <| sum_single_index this
_ = f.sum fun a b => ite (a = z) (r * b) 0 := by simp only [H]
_ = if z ∈ f.support then r * f z else 0 := f.support.sum_ite_eq' _ _
_ = _ := by split_ifs with h <;> simp at h <;> simp [h]
theorem single_one_mul_apply [MulOneClass G] (f : MonoidAlgebra k G) (r : k) (x : G) :
(single (1 : G) r * f) x = r * f x :=
f.single_mul_apply_aux fun a => by rw [one_mul]
theorem single_mul_apply_of_not_exists_mul [Mul G] (r : k) {g g' : G} (x : MonoidAlgebra k G)
(h : ¬∃ d, g' = g * d) : (single g r * x) g' = 0 := by
classical
rw [mul_apply, Finsupp.sum_single_index]
swap
· simp_rw [Finsupp.sum, zero_mul, ite_self, Finset.sum_const_zero]
· apply Finset.sum_eq_zero
simp_rw [ite_eq_right_iff]
rintro g'' _hg'' rfl
exfalso
exact h ⟨_, rfl⟩
theorem liftNC_smul [MulOneClass G] {R : Type*} [Semiring R] (f : k →+* R) (g : G →* R) (c : k)
(φ : MonoidAlgebra k G) : liftNC (f : k →+ R) g (c • φ) = f c * liftNC (f : k →+ R) g φ := by
suffices (liftNC (↑f) g).comp (smulAddHom k (MonoidAlgebra k G) c) =
(AddMonoidHom.mulLeft (f c)).comp (liftNC (↑f) g) from
DFunLike.congr_fun this φ
-- Porting note: `ext` couldn't a find appropriate theorem.
refine addHom_ext' fun a => AddMonoidHom.ext fun b => ?_
-- Porting note: `reducible` cannot be `local` so the proof gets more complex.
unfold MonoidAlgebra
simp only [AddMonoidHom.coe_comp, Function.comp_apply, singleAddHom_apply, smulAddHom_apply,
smul_single, smul_eq_mul, AddMonoidHom.coe_mulLeft]
-- This used to be `rw`, but we need `erw` after leanprover/lean4#2644
erw [liftNC_single, liftNC_single]; rw [AddMonoidHom.coe_coe, map_mul, mul_assoc]
end MiscTheorems
/-! #### Non-unital, non-associative algebra structure -/
section NonUnitalNonAssocAlgebra
variable (k) [Semiring k] [DistribSMul R k] [Mul G]
instance isScalarTower_self [IsScalarTower R k k] :
IsScalarTower R (MonoidAlgebra k G) (MonoidAlgebra k G) :=
⟨fun t a b => by
-- Porting note: `ext` → `refine Finsupp.ext fun _ => ?_`
refine Finsupp.ext fun m => ?_
-- Porting note: `refine` & `rw` are required because `simp` behaves differently.
classical
simp only [smul_eq_mul, mul_apply]
rw [coe_smul]
refine Eq.trans (sum_smul_index' (g := a) (b := t) ?_) ?_ <;>
simp only [mul_apply, Finsupp.smul_sum, smul_ite, smul_mul_assoc,
zero_mul, ite_self, imp_true_iff, sum_zero, Pi.smul_apply, smul_zero]⟩
/-- Note that if `k` is a `CommSemiring` then we have `SMulCommClass k k k` and so we can take
`R = k` in the below. In other words, if the coefficients are commutative amongst themselves, they
also commute with the algebra multiplication. -/
instance smulCommClass_self [SMulCommClass R k k] :
SMulCommClass R (MonoidAlgebra k G) (MonoidAlgebra k G) :=
⟨fun t a b => by
-- Porting note: `ext` → `refine Finsupp.ext fun _ => ?_`
refine Finsupp.ext fun m => ?_
-- Porting note: `refine` & `rw` are required because `simp` behaves differently.
classical
simp only [smul_eq_mul, mul_apply]
rw [coe_smul]
refine Eq.symm (Eq.trans (congr_arg (sum a)
(funext₂ fun a₁ b₁ => sum_smul_index' (g := b) (b := t) ?_)) ?_) <;>
simp only [mul_apply, Finsupp.sum, Finset.smul_sum, smul_ite, mul_smul_comm,
imp_true_iff, ite_eq_right_iff, Pi.smul_apply, mul_zero, smul_zero]⟩
instance smulCommClass_symm_self [SMulCommClass k R k] :
SMulCommClass (MonoidAlgebra k G) R (MonoidAlgebra k G) :=
⟨fun t a b => by
haveI := SMulCommClass.symm k R k
rw [← smul_comm]⟩
variable {A : Type u₃} [NonUnitalNonAssocSemiring A]
/-- A non_unital `k`-algebra homomorphism from `MonoidAlgebra k G` is uniquely defined by its
values on the functions `single a 1`. -/
theorem nonUnitalAlgHom_ext [DistribMulAction k A] {φ₁ φ₂ : MonoidAlgebra k G →ₙₐ[k] A}
(h : ∀ x, φ₁ (single x 1) = φ₂ (single x 1)) : φ₁ = φ₂ :=
NonUnitalAlgHom.to_distribMulActionHom_injective <|
Finsupp.distribMulActionHom_ext' fun a => DistribMulActionHom.ext_ring (h a)
/-- See note [partially-applied ext lemmas]. -/
@[ext high]
theorem nonUnitalAlgHom_ext' [DistribMulAction k A] {φ₁ φ₂ : MonoidAlgebra k G →ₙₐ[k] A}
(h : φ₁.toMulHom.comp (ofMagma k G) = φ₂.toMulHom.comp (ofMagma k G)) : φ₁ = φ₂ :=
nonUnitalAlgHom_ext k <| DFunLike.congr_fun h
/-- The functor `G ↦ MonoidAlgebra k G`, from the category of magmas to the category of non-unital,
non-associative algebras over `k` is adjoint to the forgetful functor in the other direction. -/
@[simps apply_apply symm_apply]
def liftMagma [Module k A] [IsScalarTower k A A] [SMulCommClass k A A] :
(G →ₙ* A) ≃ (MonoidAlgebra k G →ₙₐ[k] A) where
toFun f :=
{ liftAddHom fun x => (smulAddHom k A).flip (f x) with
toFun := fun a => a.sum fun m t => t • f m
map_smul' := fun t' a => by
-- Porting note(#12129): additional beta reduction needed
beta_reduce
rw [Finsupp.smul_sum, sum_smul_index']
· simp_rw [smul_assoc, MonoidHom.id_apply]
· intro m
exact zero_smul k (f m)
map_mul' := fun a₁ a₂ => by
let g : G → k → A := fun m t => t • f m
have h₁ : ∀ m, g m 0 = 0 := by
intro m
exact zero_smul k (f m)
have h₂ : ∀ (m) (t₁ t₂ : k), g m (t₁ + t₂) = g m t₁ + g m t₂ := by
intros
rw [← add_smul]
-- Porting note: `reducible` cannot be `local` so proof gets long.
simp_rw [Finsupp.mul_sum, Finsupp.sum_mul, smul_mul_smul, ← f.map_mul, mul_def,
sum_comm a₂ a₁]
rw [sum_sum_index h₁ h₂]; congr; ext
rw [sum_sum_index h₁ h₂]; congr; ext
rw [sum_single_index (h₁ _)] }
invFun F := F.toMulHom.comp (ofMagma k G)
left_inv f := by
ext m
simp only [NonUnitalAlgHom.coe_mk, ofMagma_apply, NonUnitalAlgHom.toMulHom_eq_coe,
sum_single_index, Function.comp_apply, one_smul, zero_smul, MulHom.coe_comp,
NonUnitalAlgHom.coe_to_mulHom]
right_inv F := by
-- Porting note: `ext` → `refine nonUnitalAlgHom_ext' k (MulHom.ext fun m => ?_)`
refine nonUnitalAlgHom_ext' k (MulHom.ext fun m => ?_)
simp only [NonUnitalAlgHom.coe_mk, ofMagma_apply, NonUnitalAlgHom.toMulHom_eq_coe,
sum_single_index, Function.comp_apply, one_smul, zero_smul, MulHom.coe_comp,
NonUnitalAlgHom.coe_to_mulHom]
end NonUnitalNonAssocAlgebra
/-! #### Algebra structure -/
section Algebra
-- attribute [local reducible] MonoidAlgebra -- Porting note: `reducible` cannot be `local`.
theorem single_one_comm [CommSemiring k] [MulOneClass G] (r : k) (f : MonoidAlgebra k G) :
single (1 : G) r * f = f * single (1 : G) r :=
single_commute Commute.one_left (Commute.all _) f
/-- `Finsupp.single 1` as a `RingHom` -/
@[simps]
def singleOneRingHom [Semiring k] [MulOneClass G] : k →+* MonoidAlgebra k G :=
{ Finsupp.singleAddHom 1 with
map_one' := rfl
map_mul' := fun x y => by
-- Porting note (#10691): Was `rw`.
simp only [ZeroHom.toFun_eq_coe, AddMonoidHom.toZeroHom_coe, singleAddHom_apply,
single_mul_single, mul_one] }
/-- If `f : G → H` is a multiplicative homomorphism between two monoids, then
`Finsupp.mapDomain f` is a ring homomorphism between their monoid algebras. -/
@[simps]
def mapDomainRingHom (k : Type*) {H F : Type*} [Semiring k] [Monoid G] [Monoid H]
[FunLike F G H] [MonoidHomClass F G H] (f : F) : MonoidAlgebra k G →+* MonoidAlgebra k H :=
{ (Finsupp.mapDomain.addMonoidHom f : MonoidAlgebra k G →+ MonoidAlgebra k H) with
map_one' := mapDomain_one f
map_mul' := fun x y => mapDomain_mul f x y }
/-- If two ring homomorphisms from `MonoidAlgebra k G` are equal on all `single a 1`
and `single 1 b`, then they are equal. -/
theorem ringHom_ext {R} [Semiring k] [MulOneClass G] [Semiring R] {f g : MonoidAlgebra k G →+* R}
(h₁ : ∀ b, f (single 1 b) = g (single 1 b)) (h_of : ∀ a, f (single a 1) = g (single a 1)) :
f = g :=
RingHom.coe_addMonoidHom_injective <|
addHom_ext fun a b => by
rw [← single, ← one_mul a, ← mul_one b, ← single_mul_single]
-- This used to be `rw`, but we need `erw` after leanprover/lean4#2644
erw [AddMonoidHom.coe_coe f, AddMonoidHom.coe_coe g]; rw [f.map_mul, g.map_mul, h₁, h_of]
/-- If two ring homomorphisms from `MonoidAlgebra k G` are equal on all `single a 1`
and `single 1 b`, then they are equal.
See note [partially-applied ext lemmas]. -/
@[ext high]
theorem ringHom_ext' {R} [Semiring k] [MulOneClass G] [Semiring R] {f g : MonoidAlgebra k G →+* R}
(h₁ : f.comp singleOneRingHom = g.comp singleOneRingHom)
(h_of :
(f : MonoidAlgebra k G →* R).comp (of k G) = (g : MonoidAlgebra k G →* R).comp (of k G)) :
f = g :=
ringHom_ext (RingHom.congr_fun h₁) (DFunLike.congr_fun h_of)
/-- The instance `Algebra k (MonoidAlgebra A G)` whenever we have `Algebra k A`.
In particular this provides the instance `Algebra k (MonoidAlgebra k G)`.
-/
instance algebra {A : Type*} [CommSemiring k] [Semiring A] [Algebra k A] [Monoid G] :
Algebra k (MonoidAlgebra A G) :=
{ singleOneRingHom.comp (algebraMap k A) with
-- Porting note: `ext` → `refine Finsupp.ext fun _ => ?_`
smul_def' := fun r a => by
refine Finsupp.ext fun _ => ?_
-- Porting note: Newly required.
rw [Finsupp.coe_smul]
simp [single_one_mul_apply, Algebra.smul_def, Pi.smul_apply]
commutes' := fun r f => by
refine Finsupp.ext fun _ => ?_
simp [single_one_mul_apply, mul_single_one_apply, Algebra.commutes] }
/-- `Finsupp.single 1` as an `AlgHom` -/
@[simps! apply]
def singleOneAlgHom {A : Type*} [CommSemiring k] [Semiring A] [Algebra k A] [Monoid G] :
A →ₐ[k] MonoidAlgebra A G :=
{ singleOneRingHom with
commutes' := fun r => by
-- Porting note: `ext` → `refine Finsupp.ext fun _ => ?_`
refine Finsupp.ext fun _ => ?_
simp
rfl }
@[simp]
theorem coe_algebraMap {A : Type*} [CommSemiring k] [Semiring A] [Algebra k A] [Monoid G] :
⇑(algebraMap k (MonoidAlgebra A G)) = single 1 ∘ algebraMap k A :=
rfl
theorem single_eq_algebraMap_mul_of [CommSemiring k] [Monoid G] (a : G) (b : k) :
single a b = algebraMap k (MonoidAlgebra k G) b * of k G a := by simp
theorem single_algebraMap_eq_algebraMap_mul_of {A : Type*} [CommSemiring k] [Semiring A]
[Algebra k A] [Monoid G] (a : G) (b : k) :
single a (algebraMap k A b) = algebraMap k (MonoidAlgebra A G) b * of A G a := by simp
theorem induction_on [Semiring k] [Monoid G] {p : MonoidAlgebra k G → Prop} (f : MonoidAlgebra k G)
(hM : ∀ g, p (of k G g)) (hadd : ∀ f g : MonoidAlgebra k G, p f → p g → p (f + g))
(hsmul : ∀ (r : k) (f), p f → p (r • f)) : p f := by
refine Finsupp.induction_linear f ?_ (fun f g hf hg => hadd f g hf hg) fun g r => ?_
· simpa using hsmul 0 (of k G 1) (hM 1)
· convert hsmul r (of k G g) (hM g)
-- Porting note: Was `simp only`.
rw [of_apply, smul_single', mul_one]
end Algebra
section lift
variable [CommSemiring k] [Monoid G] [Monoid H]
variable {A : Type u₃} [Semiring A] [Algebra k A] {B : Type*} [Semiring B] [Algebra k B]
/-- `liftNCRingHom` as an `AlgHom`, for when `f` is an `AlgHom` -/
def liftNCAlgHom (f : A →ₐ[k] B) (g : G →* B) (h_comm : ∀ x y, Commute (f x) (g y)) :
MonoidAlgebra A G →ₐ[k] B :=
{ liftNCRingHom (f : A →+* B) g h_comm with
commutes' := by simp [liftNCRingHom] }
/-- A `k`-algebra homomorphism from `MonoidAlgebra k G` is uniquely defined by its
values on the functions `single a 1`. -/
theorem algHom_ext ⦃φ₁ φ₂ : MonoidAlgebra k G →ₐ[k] A⦄
(h : ∀ x, φ₁ (single x 1) = φ₂ (single x 1)) : φ₁ = φ₂ :=
AlgHom.toLinearMap_injective <| Finsupp.lhom_ext' fun a => LinearMap.ext_ring (h a)
-- Porting note: The priority must be `high`.
/-- See note [partially-applied ext lemmas]. -/
@[ext high]
theorem algHom_ext' ⦃φ₁ φ₂ : MonoidAlgebra k G →ₐ[k] A⦄
(h :
(φ₁ : MonoidAlgebra k G →* A).comp (of k G) = (φ₂ : MonoidAlgebra k G →* A).comp (of k G)) :
φ₁ = φ₂ :=
algHom_ext <| DFunLike.congr_fun h
variable (k G A)
/-- Any monoid homomorphism `G →* A` can be lifted to an algebra homomorphism
`MonoidAlgebra k G →ₐ[k] A`. -/
def lift : (G →* A) ≃ (MonoidAlgebra k G →ₐ[k] A) where
invFun f := (f : MonoidAlgebra k G →* A).comp (of k G)
toFun F := liftNCAlgHom (Algebra.ofId k A) F fun _ _ => Algebra.commutes _ _
left_inv f := by
ext
simp [liftNCAlgHom, liftNCRingHom]
right_inv F := by
ext
simp [liftNCAlgHom, liftNCRingHom]
variable {k G H A}
theorem lift_apply' (F : G →* A) (f : MonoidAlgebra k G) :
lift k G A F f = f.sum fun a b => algebraMap k A b * F a :=
rfl
theorem lift_apply (F : G →* A) (f : MonoidAlgebra k G) :
lift k G A F f = f.sum fun a b => b • F a := by simp only [lift_apply', Algebra.smul_def]
theorem lift_def (F : G →* A) : ⇑(lift k G A F) = liftNC ((algebraMap k A : k →+* A) : k →+ A) F :=
rfl
@[simp]
theorem lift_symm_apply (F : MonoidAlgebra k G →ₐ[k] A) (x : G) :
(lift k G A).symm F x = F (single x 1) :=
rfl
@[simp]
theorem lift_single (F : G →* A) (a b) : lift k G A F (single a b) = b • F a := by
rw [lift_def, liftNC_single, Algebra.smul_def, AddMonoidHom.coe_coe]
theorem lift_of (F : G →* A) (x) : lift k G A F (of k G x) = F x := by simp
theorem lift_unique' (F : MonoidAlgebra k G →ₐ[k] A) :
F = lift k G A ((F : MonoidAlgebra k G →* A).comp (of k G)) :=
((lift k G A).apply_symm_apply F).symm
/-- Decomposition of a `k`-algebra homomorphism from `MonoidAlgebra k G` by
its values on `F (single a 1)`. -/
theorem lift_unique (F : MonoidAlgebra k G →ₐ[k] A) (f : MonoidAlgebra k G) :
F f = f.sum fun a b => b • F (single a 1) := by
conv_lhs =>
rw [lift_unique' F]
simp [lift_apply]
/-- If `f : G → H` is a homomorphism between two magmas, then
`Finsupp.mapDomain f` is a non-unital algebra homomorphism between their magma algebras. -/
@[simps apply]
def mapDomainNonUnitalAlgHom (k A : Type*) [CommSemiring k] [Semiring A] [Algebra k A]
{G H F : Type*} [Mul G] [Mul H] [FunLike F G H] [MulHomClass F G H] (f : F) :
MonoidAlgebra A G →ₙₐ[k] MonoidAlgebra A H :=
{ (Finsupp.mapDomain.addMonoidHom f : MonoidAlgebra A G →+ MonoidAlgebra A H) with
map_mul' := fun x y => mapDomain_mul f x y
map_smul' := fun r x => mapDomain_smul r x }
variable (A) in
theorem mapDomain_algebraMap {F : Type*} [FunLike F G H] [MonoidHomClass F G H] (f : F) (r : k) :
mapDomain f (algebraMap k (MonoidAlgebra A G) r) = algebraMap k (MonoidAlgebra A H) r := by
simp only [coe_algebraMap, mapDomain_single, map_one, (· ∘ ·)]
/-- If `f : G → H` is a multiplicative homomorphism between two monoids, then
`Finsupp.mapDomain f` is an algebra homomorphism between their monoid algebras. -/
@[simps!]
def mapDomainAlgHom (k A : Type*) [CommSemiring k] [Semiring A] [Algebra k A] {H F : Type*}
[Monoid H] [FunLike F G H] [MonoidHomClass F G H] (f : F) :
MonoidAlgebra A G →ₐ[k] MonoidAlgebra A H :=
{ mapDomainRingHom A f with commutes' := mapDomain_algebraMap A f }
@[simp]
lemma mapDomainAlgHom_id (k A) [CommSemiring k] [Semiring A] [Algebra k A] :
mapDomainAlgHom k A (MonoidHom.id G) = AlgHom.id k (MonoidAlgebra A G) := by
ext; simp [MonoidHom.id, ← Function.id_def]
@[simp]
lemma mapDomainAlgHom_comp (k A) {G₁ G₂ G₃} [CommSemiring k] [Semiring A] [Algebra k A]
[Monoid G₁] [Monoid G₂] [Monoid G₃] (f : G₁ →* G₂) (g : G₂ →* G₃) :
mapDomainAlgHom k A (g.comp f) = (mapDomainAlgHom k A g).comp (mapDomainAlgHom k A f) := by
ext; simp [mapDomain_comp]
variable (k A)
/-- If `e : G ≃* H` is a multiplicative equivalence between two monoids, then
`MonoidAlgebra.domCongr e` is an algebra equivalence between their monoid algebras. -/
def domCongr (e : G ≃* H) : MonoidAlgebra A G ≃ₐ[k] MonoidAlgebra A H :=
AlgEquiv.ofLinearEquiv
(Finsupp.domLCongr e : (G →₀ A) ≃ₗ[k] (H →₀ A))
((equivMapDomain_eq_mapDomain _ _).trans <| mapDomain_one e)
(fun f g => (equivMapDomain_eq_mapDomain _ _).trans <| (mapDomain_mul e f g).trans <|
congr_arg₂ _ (equivMapDomain_eq_mapDomain _ _).symm (equivMapDomain_eq_mapDomain _ _).symm)
theorem domCongr_toAlgHom (e : G ≃* H) : (domCongr k A e).toAlgHom = mapDomainAlgHom k A e :=
AlgHom.ext fun _ => equivMapDomain_eq_mapDomain _ _
@[simp] theorem domCongr_apply (e : G ≃* H) (f : MonoidAlgebra A G) (h : H) :
domCongr k A e f h = f (e.symm h) :=
rfl
@[simp] theorem domCongr_support (e : G ≃* H) (f : MonoidAlgebra A G) :
(domCongr k A e f).support = f.support.map e :=
rfl
@[simp] theorem domCongr_single (e : G ≃* H) (g : G) (a : A) :
domCongr k A e (single g a) = single (e g) a :=
Finsupp.equivMapDomain_single _ _ _
@[simp] theorem domCongr_refl : domCongr k A (MulEquiv.refl G) = AlgEquiv.refl :=
AlgEquiv.ext fun _ => Finsupp.ext fun _ => rfl
@[simp] theorem domCongr_symm (e : G ≃* H) : (domCongr k A e).symm = domCongr k A e.symm := rfl
end lift
section
-- attribute [local reducible] MonoidAlgebra -- Porting note: `reducible` cannot be `local`.
variable (k)
/-- When `V` is a `k[G]`-module, multiplication by a group element `g` is a `k`-linear map. -/
def GroupSMul.linearMap [Monoid G] [CommSemiring k] (V : Type u₃) [AddCommMonoid V] [Module k V]
[Module (MonoidAlgebra k G) V] [IsScalarTower k (MonoidAlgebra k G) V] (g : G) : V →ₗ[k] V where
toFun v := single g (1 : k) • v
map_add' x y := smul_add (single g (1 : k)) x y
map_smul' _c _x := smul_algebra_smul_comm _ _ _
@[simp]
theorem GroupSMul.linearMap_apply [Monoid G] [CommSemiring k] (V : Type u₃) [AddCommMonoid V]
[Module k V] [Module (MonoidAlgebra k G) V] [IsScalarTower k (MonoidAlgebra k G) V] (g : G)
(v : V) : (GroupSMul.linearMap k V g) v = single g (1 : k) • v :=
rfl
section
variable {k}
variable [Monoid G] [CommSemiring k] {V : Type u₃} {W : Type u₄} [AddCommMonoid V] [Module k V]
[Module (MonoidAlgebra k G) V] [IsScalarTower k (MonoidAlgebra k G) V] [AddCommMonoid W]
[Module k W] [Module (MonoidAlgebra k G) W] [IsScalarTower k (MonoidAlgebra k G) W]
(f : V →ₗ[k] W)
/-- Build a `k[G]`-linear map from a `k`-linear map and evidence that it is `G`-equivariant. -/
def equivariantOfLinearOfComm
(h : ∀ (g : G) (v : V), f (single g (1 : k) • v) = single g (1 : k) • f v) :
V →ₗ[MonoidAlgebra k G] W where
toFun := f
map_add' v v' := by simp
map_smul' c v := by
-- Porting note: Was `apply`.
refine Finsupp.induction c ?_ ?_
· simp
· intro g r c' _nm _nz w
dsimp at *
simp only [add_smul, f.map_add, w, add_left_inj, single_eq_algebraMap_mul_of, ← smul_smul]
erw [algebraMap_smul (MonoidAlgebra k G) r, algebraMap_smul (MonoidAlgebra k G) r, f.map_smul,
h g v, of_apply]
variable (h : ∀ (g : G) (v : V), f (single g (1 : k) • v) = single g (1 : k) • f v)
@[simp]
theorem equivariantOfLinearOfComm_apply (v : V) : (equivariantOfLinearOfComm f h) v = f v :=
rfl
end
end
section
universe ui
variable {ι : Type ui}
-- attribute [local reducible] MonoidAlgebra -- Porting note: `reducible` cannot be `local`.
theorem prod_single [CommSemiring k] [CommMonoid G] {s : Finset ι} {a : ι → G} {b : ι → k} :
(∏ i ∈ s, single (a i) (b i)) = single (∏ i ∈ s, a i) (∏ i ∈ s, b i) :=
Finset.cons_induction_on s rfl fun a s has ih => by
rw [prod_cons has, ih, single_mul_single, prod_cons has, prod_cons has]
end
section
-- We now prove some additional statements that hold for group algebras.
variable [Semiring k] [Group G]
-- attribute [local reducible] MonoidAlgebra -- Porting note: `reducible` cannot be `local`.
@[simp]
theorem mul_single_apply (f : MonoidAlgebra k G) (r : k) (x y : G) :
(f * single x r) y = f (y * x⁻¹) * r :=
f.mul_single_apply_aux fun _a => eq_mul_inv_iff_mul_eq.symm
@[simp]
theorem single_mul_apply (r : k) (x : G) (f : MonoidAlgebra k G) (y : G) :
(single x r * f) y = r * f (x⁻¹ * y) :=
f.single_mul_apply_aux fun _z => eq_inv_mul_iff_mul_eq.symm
theorem mul_apply_left (f g : MonoidAlgebra k G) (x : G) :
(f * g) x = f.sum fun a b => b * g (a⁻¹ * x) :=
calc
(f * g) x = sum f fun a b => (single a b * g) x := by
rw [← Finsupp.sum_apply, ← Finsupp.sum_mul g f, f.sum_single]
_ = _ := by simp only [single_mul_apply, Finsupp.sum]
-- If we'd assumed `CommSemiring`, we could deduce this from `mul_apply_left`.
theorem mul_apply_right (f g : MonoidAlgebra k G) (x : G) :
(f * g) x = g.sum fun a b => f (x * a⁻¹) * b :=
calc
(f * g) x = sum g fun a b => (f * single a b) x := by
rw [← Finsupp.sum_apply, ← Finsupp.mul_sum f g, g.sum_single]
_ = _ := by simp only [mul_single_apply, Finsupp.sum]
end
section Opposite
open Finsupp MulOpposite
variable [Semiring k]
/-- The opposite of a `MonoidAlgebra R I` equivalent as a ring to
the `MonoidAlgebra Rᵐᵒᵖ Iᵐᵒᵖ` over the opposite ring, taking elements to their opposite. -/
@[simps! (config := { simpRhs := true }) apply symm_apply]
protected noncomputable def opRingEquiv [Monoid G] :
(MonoidAlgebra k G)ᵐᵒᵖ ≃+* MonoidAlgebra kᵐᵒᵖ Gᵐᵒᵖ :=
{ opAddEquiv.symm.trans <|
(Finsupp.mapRange.addEquiv (opAddEquiv : k ≃+ kᵐᵒᵖ)).trans <| Finsupp.domCongr opEquiv with
map_mul' := by
-- This used to be `rw`, but we need `erw` after leanprover/lean4#2644
rw [Equiv.toFun_as_coe, AddEquiv.toEquiv_eq_coe]; erw [AddEquiv.coe_toEquiv]
rw [← AddEquiv.coe_toAddMonoidHom]
refine Iff.mpr (AddMonoidHom.map_mul_iff (R := (MonoidAlgebra k G)ᵐᵒᵖ)
(S := MonoidAlgebra kᵐᵒᵖ Gᵐᵒᵖ) _) ?_
-- Porting note: Was `ext`.
refine AddMonoidHom.mul_op_ext _ _ <| addHom_ext' fun i₁ => AddMonoidHom.ext fun r₁ =>
AddMonoidHom.mul_op_ext _ _ <| addHom_ext' fun i₂ => AddMonoidHom.ext fun r₂ => ?_
-- Porting note: `reducible` cannot be `local` so proof gets long.
simp only [AddMonoidHom.coe_comp, AddEquiv.coe_toAddMonoidHom, opAddEquiv_apply,
Function.comp_apply, singleAddHom_apply, AddMonoidHom.compr₂_apply, AddMonoidHom.coe_mul,
AddMonoidHom.coe_mulLeft, AddMonoidHom.compl₂_apply]
-- This used to be `rw`, but we need `erw` after leanprover/lean4#2644
erw [AddEquiv.trans_apply, AddEquiv.trans_apply, AddEquiv.trans_apply, AddEquiv.trans_apply,
AddEquiv.trans_apply, AddEquiv.trans_apply, MulOpposite.opAddEquiv_symm_apply]
rw [MulOpposite.unop_mul (α := MonoidAlgebra k G)]
-- This was not needed before leanprover/lean4#2644
erw [unop_op, unop_op, single_mul_single]
simp }
-- @[simp] -- Porting note (#10618): simp can prove this
theorem opRingEquiv_single [Monoid G] (r : k) (x : G) :
MonoidAlgebra.opRingEquiv (op (single x r)) = single (op x) (op r) := by simp
-- @[simp] -- Porting note (#10618): simp can prove this
theorem opRingEquiv_symm_single [Monoid G] (r : kᵐᵒᵖ) (x : Gᵐᵒᵖ) :
MonoidAlgebra.opRingEquiv.symm (single x r) = op (single x.unop r.unop) := by simp
end Opposite
section Submodule
variable [CommSemiring k] [Monoid G]
variable {V : Type*} [AddCommMonoid V]
variable [Module k V] [Module (MonoidAlgebra k G) V] [IsScalarTower k (MonoidAlgebra k G) V]
/-- A submodule over `k` which is stable under scalar multiplication by elements of `G` is a
submodule over `MonoidAlgebra k G` -/
def submoduleOfSMulMem (W : Submodule k V) (h : ∀ (g : G) (v : V), v ∈ W → of k G g • v ∈ W) :
Submodule (MonoidAlgebra k G) V where
carrier := W
zero_mem' := W.zero_mem'
add_mem' := W.add_mem'
smul_mem' := by
intro f v hv
rw [← Finsupp.sum_single f, Finsupp.sum, Finset.sum_smul]
simp_rw [← smul_of, smul_assoc]
exact Submodule.sum_smul_mem W _ fun g _ => h g v hv
end Submodule
end MonoidAlgebra
/-! ### Additive monoids -/
section
variable [Semiring k]
/-- The monoid algebra over a semiring `k` generated by the additive monoid `G`.
It is the type of finite formal `k`-linear combinations of terms of `G`,
endowed with the convolution product.
-/
def AddMonoidAlgebra :=
G →₀ k
@[inherit_doc]
scoped[AddMonoidAlgebra] notation:9000 R:max "[" A "]" => AddMonoidAlgebra R A
namespace AddMonoidAlgebra
-- Porting note: The compiler couldn't derive this.
instance inhabited : Inhabited k[G] :=
inferInstanceAs (Inhabited (G →₀ k))
-- Porting note: The compiler couldn't derive this.
instance addCommMonoid : AddCommMonoid k[G] :=
inferInstanceAs (AddCommMonoid (G →₀ k))
instance instIsCancelAdd [IsCancelAdd k] : IsCancelAdd (AddMonoidAlgebra k G) :=
inferInstanceAs (IsCancelAdd (G →₀ k))
instance coeFun : CoeFun k[G] fun _ => G → k :=
Finsupp.instCoeFun
end AddMonoidAlgebra
end
namespace AddMonoidAlgebra
variable {k G}
section
variable [Semiring k] [NonUnitalNonAssocSemiring R]
-- Porting note: `reducible` cannot be `local`, so we replace some definitions and theorems with
-- new ones which have new types.
abbrev single (a : G) (b : k) : k[G] := Finsupp.single a b
theorem single_zero (a : G) : (single a 0 : k[G]) = 0 := Finsupp.single_zero a
theorem single_add (a : G) (b₁ b₂ : k) : single a (b₁ + b₂) = single a b₁ + single a b₂ :=
Finsupp.single_add a b₁ b₂
@[simp]
theorem sum_single_index {N} [AddCommMonoid N] {a : G} {b : k} {h : G → k → N}
(h_zero : h a 0 = 0) :
(single a b).sum h = h a b := Finsupp.sum_single_index h_zero
@[simp]
theorem sum_single (f : k[G]) : f.sum single = f :=
Finsupp.sum_single f
theorem single_apply {a a' : G} {b : k} [Decidable (a = a')] :
single a b a' = if a = a' then b else 0 :=
Finsupp.single_apply
@[simp]
theorem single_eq_zero {a : G} {b : k} : single a b = 0 ↔ b = 0 := Finsupp.single_eq_zero
abbrev mapDomain {G' : Type*} (f : G → G') (v : k[G]) : k[G'] :=
Finsupp.mapDomain f v
theorem mapDomain_sum {k' G' : Type*} [Semiring k'] {f : G → G'} {s : AddMonoidAlgebra k' G}
{v : G → k' → k[G]} :
mapDomain f (s.sum v) = s.sum fun a b => mapDomain f (v a b) :=
Finsupp.mapDomain_sum
theorem mapDomain_single {G' : Type*} {f : G → G'} {a : G} {b : k} :
mapDomain f (single a b) = single (f a) b :=
Finsupp.mapDomain_single
/-- A non-commutative version of `AddMonoidAlgebra.lift`: given an additive homomorphism
`f : k →+ R` and a map `g : Multiplicative G → R`, returns the additive
homomorphism from `k[G]` such that `liftNC f g (single a b) = f b * g a`. If `f`
is a ring homomorphism and the range of either `f` or `g` is in center of `R`, then the result is a
ring homomorphism. If `R` is a `k`-algebra and `f = algebraMap k R`, then the result is an algebra
homomorphism called `AddMonoidAlgebra.lift`. -/
def liftNC (f : k →+ R) (g : Multiplicative G → R) : k[G] →+ R :=
liftAddHom fun x : G => (AddMonoidHom.mulRight (g <| Multiplicative.ofAdd x)).comp f
@[simp]
theorem liftNC_single (f : k →+ R) (g : Multiplicative G → R) (a : G) (b : k) :
liftNC f g (single a b) = f b * g (Multiplicative.ofAdd a) :=
liftAddHom_apply_single _ _ _
end
section Mul
variable [Semiring k] [Add G]
/-- The product of `f g : k[G]` is the finitely supported function
whose value at `a` is the sum of `f x * g y` over all pairs `x, y`
such that `x + y = a`. (Think of the product of multivariate
polynomials where `α` is the additive monoid of monomial exponents.) -/
instance hasMul : Mul k[G] :=
⟨fun f g => MonoidAlgebra.mul' (G := Multiplicative G) f g⟩
theorem mul_def {f g : k[G]} :
f * g = f.sum fun a₁ b₁ => g.sum fun a₂ b₂ => single (a₁ + a₂) (b₁ * b₂) :=
MonoidAlgebra.mul_def (G := Multiplicative G)
instance nonUnitalNonAssocSemiring : NonUnitalNonAssocSemiring k[G] :=
{ Finsupp.instAddCommMonoid with
-- Porting note: `refine` & `exact` are required because `simp` behaves differently.
left_distrib := fun f g h => by
haveI := Classical.decEq G
simp only [mul_def]
refine Eq.trans (congr_arg (sum f) (funext₂ fun a₁ b₁ => sum_add_index ?_ ?_)) ?_ <;>
simp only [mul_add, mul_zero, single_zero, single_add, forall_true_iff, sum_add]
right_distrib := fun f g h => by
haveI := Classical.decEq G
simp only [mul_def]
refine Eq.trans (sum_add_index ?_ ?_) ?_ <;>
simp only [add_mul, zero_mul, single_zero, single_add, forall_true_iff, sum_zero, sum_add]
zero_mul := fun f => by
simp only [mul_def]
exact sum_zero_index
mul_zero := fun f => by
simp only [mul_def]
exact Eq.trans (congr_arg (sum f) (funext₂ fun a₁ b₁ => sum_zero_index)) sum_zero
nsmul := fun n f => n • f
-- Porting note: `ext` → `refine Finsupp.ext fun _ => ?_`
nsmul_zero := by
intros
refine Finsupp.ext fun _ => ?_
simp [-nsmul_eq_mul, add_smul]
nsmul_succ := by
intros
refine Finsupp.ext fun _ => ?_
simp [-nsmul_eq_mul, add_smul] }
variable [Semiring R]
theorem liftNC_mul {g_hom : Type*}
[FunLike g_hom (Multiplicative G) R] [MulHomClass g_hom (Multiplicative G) R]
(f : k →+* R) (g : g_hom) (a b : k[G])
(h_comm : ∀ {x y}, y ∈ a.support → Commute (f (b x)) (g <| Multiplicative.ofAdd y)) :
liftNC (f : k →+ R) g (a * b) = liftNC (f : k →+ R) g a * liftNC (f : k →+ R) g b :=
(MonoidAlgebra.liftNC_mul f g _ _ @h_comm : _)
end Mul
section One
variable [Semiring k] [Zero G] [NonAssocSemiring R]
/-- The unit of the multiplication is `single 0 1`, i.e. the function
that is `1` at `0` and zero elsewhere. -/
instance one : One k[G] :=
⟨single 0 1⟩
theorem one_def : (1 : k[G]) = single 0 1 :=
rfl
@[simp]
theorem liftNC_one {g_hom : Type*}
[FunLike g_hom (Multiplicative G) R] [OneHomClass g_hom (Multiplicative G) R]
(f : k →+* R) (g : g_hom) : liftNC (f : k →+ R) g 1 = 1 :=
(MonoidAlgebra.liftNC_one f g : _)
end One
section Semigroup
variable [Semiring k] [AddSemigroup G]
instance nonUnitalSemiring : NonUnitalSemiring k[G] :=
{ AddMonoidAlgebra.nonUnitalNonAssocSemiring with
mul_assoc := fun f g h => by
-- Porting note: `reducible` cannot be `local` so proof gets long.
simp only [mul_def]
rw [sum_sum_index]; congr; ext a₁ b₁
rw [sum_sum_index, sum_sum_index]; congr; ext a₂ b₂
rw [sum_sum_index, sum_single_index]; congr; ext a₃ b₃
rw [sum_single_index, mul_assoc, add_assoc]
all_goals simp only [single_zero, single_add, forall_true_iff, add_mul,
mul_add, zero_mul, mul_zero, sum_zero, sum_add] }
end Semigroup
section MulOneClass
variable [Semiring k] [AddZeroClass G]
instance nonAssocSemiring : NonAssocSemiring k[G] :=
{ AddMonoidAlgebra.nonUnitalNonAssocSemiring with
natCast := fun n => single 0 n
natCast_zero := by simp
natCast_succ := fun _ => by simp; rfl
one_mul := fun f => by
simp only [mul_def, one_def, sum_single_index, zero_mul, single_zero, sum_zero, zero_add,
one_mul, sum_single]
mul_one := fun f => by
simp only [mul_def, one_def, sum_single_index, mul_zero, single_zero, sum_zero, add_zero,
mul_one, sum_single] }
theorem natCast_def (n : ℕ) : (n : k[G]) = single (0 : G) (n : k) :=
rfl
@[deprecated (since := "2024-04-17")]
alias nat_cast_def := natCast_def
end MulOneClass
/-! #### Semiring structure -/
section Semiring
instance smulZeroClass [Semiring k] [SMulZeroClass R k] : SMulZeroClass R k[G] :=
Finsupp.smulZeroClass
variable [Semiring k] [AddMonoid G]
instance semiring : Semiring k[G] :=
{ AddMonoidAlgebra.nonUnitalSemiring,
AddMonoidAlgebra.nonAssocSemiring with }
variable [Semiring R]
/-- `liftNC` as a `RingHom`, for when `f` and `g` commute -/
def liftNCRingHom (f : k →+* R) (g : Multiplicative G →* R) (h_comm : ∀ x y, Commute (f x) (g y)) :
k[G] →+* R :=
{ liftNC (f : k →+ R) g with
map_one' := liftNC_one _ _
map_mul' := fun _a _b => liftNC_mul _ _ _ _ fun {_ _} _ => h_comm _ _ }
end Semiring
instance nonUnitalCommSemiring [CommSemiring k] [AddCommSemigroup G] :
NonUnitalCommSemiring k[G] :=
{ AddMonoidAlgebra.nonUnitalSemiring with
mul_comm := @mul_comm (MonoidAlgebra k <| Multiplicative G) _ }
instance nontrivial [Semiring k] [Nontrivial k] [Nonempty G] : Nontrivial k[G] :=
Finsupp.instNontrivial
/-! #### Derived instances -/
section DerivedInstances
instance commSemiring [CommSemiring k] [AddCommMonoid G] : CommSemiring k[G] :=
{ AddMonoidAlgebra.nonUnitalCommSemiring, AddMonoidAlgebra.semiring with }
instance unique [Semiring k] [Subsingleton k] : Unique k[G] :=
Finsupp.uniqueOfRight
instance addCommGroup [Ring k] : AddCommGroup k[G] :=
Finsupp.instAddCommGroup
instance nonUnitalNonAssocRing [Ring k] [Add G] : NonUnitalNonAssocRing k[G] :=
{ AddMonoidAlgebra.addCommGroup, AddMonoidAlgebra.nonUnitalNonAssocSemiring with }
instance nonUnitalRing [Ring k] [AddSemigroup G] : NonUnitalRing k[G] :=
{ AddMonoidAlgebra.addCommGroup, AddMonoidAlgebra.nonUnitalSemiring with }
instance nonAssocRing [Ring k] [AddZeroClass G] : NonAssocRing k[G] :=
{ AddMonoidAlgebra.addCommGroup,
AddMonoidAlgebra.nonAssocSemiring with
intCast := fun z => single 0 (z : k)
-- Porting note: Both were `simpa`.
intCast_ofNat := fun n => by simp; rfl
intCast_negSucc := fun n => by simp; rfl }
theorem intCast_def [Ring k] [AddZeroClass G] (z : ℤ) :
(z : k[G]) = single (0 : G) (z : k) :=
rfl
@[deprecated (since := "2024-04-17")]
alias int_cast_def := intCast_def
instance ring [Ring k] [AddMonoid G] : Ring k[G] :=
{ AddMonoidAlgebra.nonAssocRing, AddMonoidAlgebra.semiring with }
instance nonUnitalCommRing [CommRing k] [AddCommSemigroup G] :
NonUnitalCommRing k[G] :=
{ AddMonoidAlgebra.nonUnitalCommSemiring, AddMonoidAlgebra.nonUnitalRing with }
instance commRing [CommRing k] [AddCommMonoid G] : CommRing k[G] :=
{ AddMonoidAlgebra.nonUnitalCommRing, AddMonoidAlgebra.ring with }
variable {S : Type*}
instance distribSMul [Semiring k] [DistribSMul R k] : DistribSMul R k[G] :=
Finsupp.distribSMul G k
instance distribMulAction [Monoid R] [Semiring k] [DistribMulAction R k] :
DistribMulAction R k[G] :=
Finsupp.distribMulAction G k
instance faithfulSMul [Semiring k] [SMulZeroClass R k] [FaithfulSMul R k] [Nonempty G] :
FaithfulSMul R k[G] :=
Finsupp.faithfulSMul
instance module [Semiring R] [Semiring k] [Module R k] : Module R k[G] :=
Finsupp.module G k
instance isScalarTower [Semiring k] [SMulZeroClass R k] [SMulZeroClass S k] [SMul R S]
[IsScalarTower R S k] : IsScalarTower R S k[G] :=
Finsupp.isScalarTower G k
instance smulCommClass [Semiring k] [SMulZeroClass R k] [SMulZeroClass S k] [SMulCommClass R S k] :
SMulCommClass R S k[G] :=
Finsupp.smulCommClass G k
instance isCentralScalar [Semiring k] [SMulZeroClass R k] [SMulZeroClass Rᵐᵒᵖ k]
[IsCentralScalar R k] : IsCentralScalar R k[G] :=
Finsupp.isCentralScalar G k
/-! It is hard to state the equivalent of `DistribMulAction G k[G]`
because we've never discussed actions of additive groups. -/
end DerivedInstances
section MiscTheorems
variable [Semiring k]
theorem mul_apply [DecidableEq G] [Add G] (f g : k[G]) (x : G) :
(f * g) x = f.sum fun a₁ b₁ => g.sum fun a₂ b₂ => if a₁ + a₂ = x then b₁ * b₂ else 0 :=
@MonoidAlgebra.mul_apply k (Multiplicative G) _ _ _ _ _ _
theorem mul_apply_antidiagonal [Add G] (f g : k[G]) (x : G) (s : Finset (G × G))
(hs : ∀ {p : G × G}, p ∈ s ↔ p.1 + p.2 = x) : (f * g) x = ∑ p ∈ s, f p.1 * g p.2 :=
@MonoidAlgebra.mul_apply_antidiagonal k (Multiplicative G) _ _ _ _ _ s @hs
theorem single_mul_single [Add G] {a₁ a₂ : G} {b₁ b₂ : k} :
single a₁ b₁ * single a₂ b₂ = single (a₁ + a₂) (b₁ * b₂) :=
@MonoidAlgebra.single_mul_single k (Multiplicative G) _ _ _ _ _ _
theorem single_commute_single [Add G] {a₁ a₂ : G} {b₁ b₂ : k}
(ha : AddCommute a₁ a₂) (hb : Commute b₁ b₂) :
Commute (single a₁ b₁) (single a₂ b₂) :=
@MonoidAlgebra.single_commute_single k (Multiplicative G) _ _ _ _ _ _ ha hb
-- This should be a `@[simp]` lemma, but the simp_nf linter times out if we add this.
-- Probably the correct fix is to make a `[Add]MonoidAlgebra.single` with the correct type,
-- instead of relying on `Finsupp.single`.
theorem single_pow [AddMonoid G] {a : G} {b : k} : ∀ n : ℕ, single a b ^ n = single (n • a) (b ^ n)
| 0 => by
simp only [pow_zero, zero_nsmul]
rfl
| n + 1 => by
rw [pow_succ, pow_succ, single_pow n, single_mul_single, add_nsmul, one_nsmul]
/-- Like `Finsupp.mapDomain_zero`, but for the `1` we define in this file -/
@[simp]
theorem mapDomain_one {α : Type*} {β : Type*} {α₂ : Type*} [Semiring β] [Zero α] [Zero α₂]
{F : Type*} [FunLike F α α₂] [ZeroHomClass F α α₂] (f : F) :
(mapDomain f (1 : AddMonoidAlgebra β α) : AddMonoidAlgebra β α₂) =
(1 : AddMonoidAlgebra β α₂) := by
simp_rw [one_def, mapDomain_single, map_zero]
/-- Like `Finsupp.mapDomain_add`, but for the convolutive multiplication we define in this file -/
theorem mapDomain_mul {α : Type*} {β : Type*} {α₂ : Type*} [Semiring β] [Add α] [Add α₂]
{F : Type*} [FunLike F α α₂] [AddHomClass F α α₂] (f : F) (x y : AddMonoidAlgebra β α) :
mapDomain f (x * y) = mapDomain f x * mapDomain f y := by
simp_rw [mul_def, mapDomain_sum, mapDomain_single, map_add]
rw [Finsupp.sum_mapDomain_index]
· congr
ext a b
rw [Finsupp.sum_mapDomain_index]
· simp
· simp [mul_add]
· simp
· simp [add_mul]
section
variable (k G)
/-- The embedding of an additive magma into its additive magma algebra. -/
@[simps]
def ofMagma [Add G] : Multiplicative G →ₙ* k[G] where
toFun a := single a 1
map_mul' a b := by simp only [mul_def, mul_one, sum_single_index, single_eq_zero, mul_zero]; rfl
/-- Embedding of a magma with zero into its magma algebra. -/
def of [AddZeroClass G] : Multiplicative G →* k[G] :=
{ ofMagma k G with
toFun := fun a => single a 1
map_one' := rfl }
/-- Embedding of a magma with zero `G`, into its magma algebra, having `G` as source. -/
def of' : G → k[G] := fun a => single a 1
end
@[simp]
theorem of_apply [AddZeroClass G] (a : Multiplicative G) :
of k G a = single (Multiplicative.toAdd a) 1 :=
rfl
@[simp]
theorem of'_apply (a : G) : of' k G a = single a 1 :=
rfl
theorem of'_eq_of [AddZeroClass G] (a : G) : of' k G a = of k G (.ofAdd a) := rfl
theorem of_injective [Nontrivial k] [AddZeroClass G] : Function.Injective (of k G) :=
MonoidAlgebra.of_injective
theorem of'_commute [AddZeroClass G] {a : G} (h : ∀ a', AddCommute a a')
(f : AddMonoidAlgebra k G) :
Commute (of' k G a) f :=
MonoidAlgebra.of_commute (G := Multiplicative G) h f
/-- `Finsupp.single` as a `MonoidHom` from the product type into the additive monoid algebra.
Note the order of the elements of the product are reversed compared to the arguments of
`Finsupp.single`.
-/
@[simps]
def singleHom [AddZeroClass G] : k × Multiplicative G →* k[G] where
toFun a := single (Multiplicative.toAdd a.2) a.1
map_one' := rfl
map_mul' _a _b := single_mul_single.symm
theorem mul_single_apply_aux [Add G] (f : k[G]) (r : k) (x y z : G)
(H : ∀ a, a + x = z ↔ a = y) : (f * single x r) z = f y * r :=
@MonoidAlgebra.mul_single_apply_aux k (Multiplicative G) _ _ _ _ _ _ _ H
theorem mul_single_zero_apply [AddZeroClass G] (f : k[G]) (r : k) (x : G) :
(f * single (0 : G) r) x = f x * r :=
f.mul_single_apply_aux r _ _ _ fun a => by rw [add_zero]
theorem mul_single_apply_of_not_exists_add [Add G] (r : k) {g g' : G} (x : k[G])
(h : ¬∃ d, g' = d + g) : (x * single g r) g' = 0 :=
@MonoidAlgebra.mul_single_apply_of_not_exists_mul k (Multiplicative G) _ _ _ _ _ _ h
theorem single_mul_apply_aux [Add G] (f : k[G]) (r : k) (x y z : G)
(H : ∀ a, x + a = y ↔ a = z) : (single x r * f) y = r * f z :=
@MonoidAlgebra.single_mul_apply_aux k (Multiplicative G) _ _ _ _ _ _ _ H
theorem single_zero_mul_apply [AddZeroClass G] (f : k[G]) (r : k) (x : G) :
(single (0 : G) r * f) x = r * f x :=
f.single_mul_apply_aux r _ _ _ fun a => by rw [zero_add]
theorem single_mul_apply_of_not_exists_add [Add G] (r : k) {g g' : G} (x : k[G])
(h : ¬∃ d, g' = g + d) : (single g r * x) g' = 0 :=
@MonoidAlgebra.single_mul_apply_of_not_exists_mul k (Multiplicative G) _ _ _ _ _ _ h
theorem mul_single_apply [AddGroup G] (f : k[G]) (r : k) (x y : G) :
(f * single x r) y = f (y - x) * r :=
(sub_eq_add_neg y x).symm ▸ @MonoidAlgebra.mul_single_apply k (Multiplicative G) _ _ _ _ _ _
theorem single_mul_apply [AddGroup G] (r : k) (x : G) (f : k[G]) (y : G) :
(single x r * f) y = r * f (-x + y) :=
@MonoidAlgebra.single_mul_apply k (Multiplicative G) _ _ _ _ _ _
theorem liftNC_smul {R : Type*} [AddZeroClass G] [Semiring R] (f : k →+* R)
(g : Multiplicative G →* R) (c : k) (φ : MonoidAlgebra k G) :
liftNC (f : k →+ R) g (c • φ) = f c * liftNC (f : k →+ R) g φ :=
@MonoidAlgebra.liftNC_smul k (Multiplicative G) _ _ _ _ f g c φ
theorem induction_on [AddMonoid G] {p : k[G] → Prop} (f : k[G])
(hM : ∀ g, p (of k G (Multiplicative.ofAdd g)))
(hadd : ∀ f g : k[G], p f → p g → p (f + g))
(hsmul : ∀ (r : k) (f), p f → p (r • f)) : p f := by
refine Finsupp.induction_linear f ?_ (fun f g hf hg => hadd f g hf hg) fun g r => ?_
· simpa using hsmul 0 (of k G (Multiplicative.ofAdd 0)) (hM 0)
· convert hsmul r (of k G (Multiplicative.ofAdd g)) (hM g)
-- Porting note: Was `simp only`.
rw [of_apply, toAdd_ofAdd, smul_single', mul_one]
/-- If `f : G → H` is an additive homomorphism between two additive monoids, then
`Finsupp.mapDomain f` is a ring homomorphism between their add monoid algebras. -/
@[simps]
def mapDomainRingHom (k : Type*) [Semiring k] {H F : Type*} [AddMonoid G] [AddMonoid H]
[FunLike F G H] [AddMonoidHomClass F G H] (f : F) : k[G] →+* k[H] :=
{ (Finsupp.mapDomain.addMonoidHom f : MonoidAlgebra k G →+ MonoidAlgebra k H) with
map_one' := mapDomain_one f
map_mul' := fun x y => mapDomain_mul f x y }
end MiscTheorems
end AddMonoidAlgebra
/-!
#### Conversions between `AddMonoidAlgebra` and `MonoidAlgebra`
We have not defined `k[G] = MonoidAlgebra k (Multiplicative G)`
because historically this caused problems;
since the changes that have made `nsmul` definitional, this would be possible,
but for now we just construct the ring isomorphisms using `RingEquiv.refl _`.
-/
/-- The equivalence between `AddMonoidAlgebra` and `MonoidAlgebra` in terms of
`Multiplicative` -/
protected def AddMonoidAlgebra.toMultiplicative [Semiring k] [Add G] :
AddMonoidAlgebra k G ≃+* MonoidAlgebra k (Multiplicative G) :=
{ Finsupp.domCongr
Multiplicative.ofAdd with
toFun := equivMapDomain Multiplicative.ofAdd
map_mul' := fun x y => by
-- Porting note: added `dsimp only`; `beta_reduce` alone is not sufficient
dsimp only
repeat' rw [equivMapDomain_eq_mapDomain (M := k)]
dsimp [Multiplicative.ofAdd]
exact MonoidAlgebra.mapDomain_mul (α := Multiplicative G) (β := k)
(MulHom.id (Multiplicative G)) x y }
/-- The equivalence between `MonoidAlgebra` and `AddMonoidAlgebra` in terms of `Additive` -/
protected def MonoidAlgebra.toAdditive [Semiring k] [Mul G] :
MonoidAlgebra k G ≃+* AddMonoidAlgebra k (Additive G) :=
{ Finsupp.domCongr Additive.ofMul with
toFun := equivMapDomain Additive.ofMul
map_mul' := fun x y => by
-- Porting note: added `dsimp only`; `beta_reduce` alone is not sufficient
dsimp only
repeat' rw [equivMapDomain_eq_mapDomain (M := k)]
dsimp [Additive.ofMul]
convert MonoidAlgebra.mapDomain_mul (β := k) (MulHom.id G) x y }
namespace AddMonoidAlgebra
variable {k G H}
/-! #### Non-unital, non-associative algebra structure -/
section NonUnitalNonAssocAlgebra
variable (k) [Semiring k] [DistribSMul R k] [Add G]
instance isScalarTower_self [IsScalarTower R k k] :
IsScalarTower R k[G] k[G] :=
@MonoidAlgebra.isScalarTower_self k (Multiplicative G) R _ _ _ _
/-- Note that if `k` is a `CommSemiring` then we have `SMulCommClass k k k` and so we can take
`R = k` in the below. In other words, if the coefficients are commutative amongst themselves, they
also commute with the algebra multiplication. -/
instance smulCommClass_self [SMulCommClass R k k] :
SMulCommClass R k[G] k[G] :=
@MonoidAlgebra.smulCommClass_self k (Multiplicative G) R _ _ _ _
instance smulCommClass_symm_self [SMulCommClass k R k] :
SMulCommClass k[G] R k[G] :=
@MonoidAlgebra.smulCommClass_symm_self k (Multiplicative G) R _ _ _ _
variable {A : Type u₃} [NonUnitalNonAssocSemiring A]
/-- A non_unital `k`-algebra homomorphism from `k[G]` is uniquely defined by its
values on the functions `single a 1`. -/
theorem nonUnitalAlgHom_ext [DistribMulAction k A] {φ₁ φ₂ : k[G] →ₙₐ[k] A}
(h : ∀ x, φ₁ (single x 1) = φ₂ (single x 1)) : φ₁ = φ₂ :=
@MonoidAlgebra.nonUnitalAlgHom_ext k (Multiplicative G) _ _ _ _ _ φ₁ φ₂ h
/-- See note [partially-applied ext lemmas]. -/
@[ext high]
theorem nonUnitalAlgHom_ext' [DistribMulAction k A] {φ₁ φ₂ : k[G] →ₙₐ[k] A}
(h : φ₁.toMulHom.comp (ofMagma k G) = φ₂.toMulHom.comp (ofMagma k G)) : φ₁ = φ₂ :=
@MonoidAlgebra.nonUnitalAlgHom_ext' k (Multiplicative G) _ _ _ _ _ φ₁ φ₂ h
/-- The functor `G ↦ k[G]`, from the category of magmas to the category of
non-unital, non-associative algebras over `k` is adjoint to the forgetful functor in the other
direction. -/
@[simps apply_apply symm_apply]
def liftMagma [Module k A] [IsScalarTower k A A] [SMulCommClass k A A] :
(Multiplicative G →ₙ* A) ≃ (k[G] →ₙₐ[k] A) :=
{ (MonoidAlgebra.liftMagma k : (Multiplicative G →ₙ* A) ≃ (_ →ₙₐ[k] A)) with
toFun := fun f =>
{ (MonoidAlgebra.liftMagma k f : _) with
toFun := fun a => sum a fun m t => t • f (Multiplicative.ofAdd m) }
invFun := fun F => F.toMulHom.comp (ofMagma k G) }
end NonUnitalNonAssocAlgebra
/-! #### Algebra structure -/
section Algebra
-- attribute [local reducible] MonoidAlgebra -- Porting note: `reducible` cannot be `local`.
/-- `Finsupp.single 0` as a `RingHom` -/
@[simps]
def singleZeroRingHom [Semiring k] [AddMonoid G] : k →+* k[G] :=
{ Finsupp.singleAddHom 0 with
map_one' := rfl
-- Porting note (#10691): Was `rw`.
map_mul' := fun x y => by simp only [singleAddHom, single_mul_single, zero_add] }
/-- If two ring homomorphisms from `k[G]` are equal on all `single a 1`
and `single 0 b`, then they are equal. -/
theorem ringHom_ext {R} [Semiring k] [AddMonoid G] [Semiring R] {f g : k[G] →+* R}
(h₀ : ∀ b, f (single 0 b) = g (single 0 b)) (h_of : ∀ a, f (single a 1) = g (single a 1)) :
f = g :=
@MonoidAlgebra.ringHom_ext k (Multiplicative G) R _ _ _ _ _ h₀ h_of
/-- If two ring homomorphisms from `k[G]` are equal on all `single a 1`
and `single 0 b`, then they are equal.
See note [partially-applied ext lemmas]. -/
@[ext high]
theorem ringHom_ext' {R} [Semiring k] [AddMonoid G] [Semiring R] {f g : k[G] →+* R}
(h₁ : f.comp singleZeroRingHom = g.comp singleZeroRingHom)
(h_of : (f : k[G] →* R).comp (of k G) = (g : k[G] →* R).comp (of k G)) :
f = g :=
ringHom_ext (RingHom.congr_fun h₁) (DFunLike.congr_fun h_of)
section Opposite
open Finsupp MulOpposite
variable [Semiring k]
/-- The opposite of an `R[I]` is ring equivalent to
the `AddMonoidAlgebra Rᵐᵒᵖ I` over the opposite ring, taking elements to their opposite. -/
@[simps! (config := { simpRhs := true }) apply symm_apply]
protected noncomputable def opRingEquiv [AddCommMonoid G] :
k[G]ᵐᵒᵖ ≃+* kᵐᵒᵖ[G] :=
{ MulOpposite.opAddEquiv.symm.trans
(Finsupp.mapRange.addEquiv (MulOpposite.opAddEquiv : k ≃+ kᵐᵒᵖ)) with
map_mul' := by
-- This used to be `rw`, but we need `erw` after leanprover/lean4#2644
rw [Equiv.toFun_as_coe, AddEquiv.toEquiv_eq_coe]; erw [AddEquiv.coe_toEquiv]
rw [← AddEquiv.coe_toAddMonoidHom]
refine Iff.mpr (AddMonoidHom.map_mul_iff (R := k[G]ᵐᵒᵖ) (S := kᵐᵒᵖ[G]) _) ?_
-- Porting note: Was `ext`.
refine AddMonoidHom.mul_op_ext _ _ <| addHom_ext' fun i₁ => AddMonoidHom.ext fun r₁ =>
AddMonoidHom.mul_op_ext _ _ <| addHom_ext' fun i₂ => AddMonoidHom.ext fun r₂ => ?_
-- Porting note: `reducible` cannot be `local` so proof gets long.
dsimp
-- This used to be `rw`, but we need `erw` after leanprover/lean4#2644
erw [AddEquiv.trans_apply, AddEquiv.trans_apply, AddEquiv.trans_apply,
MulOpposite.opAddEquiv_symm_apply]; rw [MulOpposite.unop_mul (α := k[G])]
dsimp
-- This was not needed before leanprover/lean4#2644
erw [mapRange_single, single_mul_single, mapRange_single, mapRange_single]
simp only [mapRange_single, single_mul_single, ← op_mul, add_comm] }
-- @[simp] -- Porting note (#10618): simp can prove this
theorem opRingEquiv_single [AddCommMonoid G] (r : k) (x : G) :
AddMonoidAlgebra.opRingEquiv (op (single x r)) = single x (op r) := by simp
-- @[simp] -- Porting note (#10618): simp can prove this
theorem opRingEquiv_symm_single [AddCommMonoid G] (r : kᵐᵒᵖ) (x : Gᵐᵒᵖ) :
AddMonoidAlgebra.opRingEquiv.symm (single x r) = op (single x r.unop) := by simp
end Opposite
/-- The instance `Algebra R k[G]` whenever we have `Algebra R k`.
In particular this provides the instance `Algebra k k[G]`.
-/
instance algebra [CommSemiring R] [Semiring k] [Algebra R k] [AddMonoid G] :
Algebra R k[G] :=
{ singleZeroRingHom.comp (algebraMap R k) with
-- Porting note: `ext` → `refine Finsupp.ext fun _ => ?_`
smul_def' := fun r a => by
refine Finsupp.ext fun _ => ?_
-- Porting note: Newly required.
rw [Finsupp.coe_smul]
simp [single_zero_mul_apply, Algebra.smul_def, Pi.smul_apply]
commutes' := fun r f => by
refine Finsupp.ext fun _ => ?_
simp [single_zero_mul_apply, mul_single_zero_apply, Algebra.commutes] }
/-- `Finsupp.single 0` as an `AlgHom` -/
@[simps! apply]
def singleZeroAlgHom [CommSemiring R] [Semiring k] [Algebra R k] [AddMonoid G] : k →ₐ[R] k[G] :=
{ singleZeroRingHom with
commutes' := fun r => by
-- Porting note: `ext` → `refine Finsupp.ext fun _ => ?_`
refine Finsupp.ext fun _ => ?_
simp
rfl }
@[simp]
theorem coe_algebraMap [CommSemiring R] [Semiring k] [Algebra R k] [AddMonoid G] :
(algebraMap R k[G] : R → k[G]) = single 0 ∘ algebraMap R k :=
rfl
end Algebra
section lift
variable [CommSemiring k] [AddMonoid G]
variable {A : Type u₃} [Semiring A] [Algebra k A] {B : Type*} [Semiring B] [Algebra k B]
/-- `liftNCRingHom` as an `AlgHom`, for when `f` is an `AlgHom` -/
def liftNCAlgHom (f : A →ₐ[k] B) (g : Multiplicative G →* B) (h_comm : ∀ x y, Commute (f x) (g y)) :
A[G] →ₐ[k] B :=
{ liftNCRingHom (f : A →+* B) g h_comm with
commutes' := by simp [liftNCRingHom] }
/-- A `k`-algebra homomorphism from `k[G]` is uniquely defined by its
values on the functions `single a 1`. -/
theorem algHom_ext ⦃φ₁ φ₂ : k[G] →ₐ[k] A⦄
(h : ∀ x, φ₁ (single x 1) = φ₂ (single x 1)) : φ₁ = φ₂ :=
@MonoidAlgebra.algHom_ext k (Multiplicative G) _ _ _ _ _ _ _ h
/-- See note [partially-applied ext lemmas]. -/
@[ext high]
theorem algHom_ext' ⦃φ₁ φ₂ : k[G] →ₐ[k] A⦄
(h : (φ₁ : k[G] →* A).comp (of k G) = (φ₂ : k[G] →* A).comp (of k G)) :
φ₁ = φ₂ :=
algHom_ext <| DFunLike.congr_fun h
variable (k G A)
/-- Any monoid homomorphism `G →* A` can be lifted to an algebra homomorphism
`k[G] →ₐ[k] A`. -/
def lift : (Multiplicative G →* A) ≃ (k[G] →ₐ[k] A) :=
{ @MonoidAlgebra.lift k (Multiplicative G) _ _ A _ _ with
invFun := fun f => (f : k[G] →* A).comp (of k G)
toFun := fun F =>
{ @MonoidAlgebra.lift k (Multiplicative G) _ _ A _ _ F with
toFun := liftNCAlgHom (Algebra.ofId k A) F fun _ _ => Algebra.commutes _ _ } }
variable {k G A}
theorem lift_apply' (F : Multiplicative G →* A) (f : MonoidAlgebra k G) :
lift k G A F f = f.sum fun a b => algebraMap k A b * F (Multiplicative.ofAdd a) :=
rfl
theorem lift_apply (F : Multiplicative G →* A) (f : MonoidAlgebra k G) :
lift k G A F f = f.sum fun a b => b • F (Multiplicative.ofAdd a) := by
simp only [lift_apply', Algebra.smul_def]
theorem lift_def (F : Multiplicative G →* A) :
⇑(lift k G A F) = liftNC ((algebraMap k A : k →+* A) : k →+ A) F :=
rfl
@[simp]
theorem lift_symm_apply (F : k[G] →ₐ[k] A) (x : Multiplicative G) :
(lift k G A).symm F x = F (single (Multiplicative.toAdd x) 1) :=
rfl
theorem lift_of (F : Multiplicative G →* A) (x : Multiplicative G) :
lift k G A F (of k G x) = F x := MonoidAlgebra.lift_of F x
@[simp]
theorem lift_single (F : Multiplicative G →* A) (a b) :
lift k G A F (single a b) = b • F (Multiplicative.ofAdd a) :=
MonoidAlgebra.lift_single F (.ofAdd a) b
lemma lift_of' (F : Multiplicative G →* A) (x : G) :
lift k G A F (of' k G x) = F (Multiplicative.ofAdd x) :=
lift_of F x
theorem lift_unique' (F : k[G] →ₐ[k] A) :
F = lift k G A ((F : k[G] →* A).comp (of k G)) :=
((lift k G A).apply_symm_apply F).symm
/-- Decomposition of a `k`-algebra homomorphism from `MonoidAlgebra k G` by
its values on `F (single a 1)`. -/
theorem lift_unique (F : k[G] →ₐ[k] A) (f : MonoidAlgebra k G) :
F f = f.sum fun a b => b • F (single a 1) := by
conv_lhs =>
rw [lift_unique' F]
simp [lift_apply]
theorem algHom_ext_iff {φ₁ φ₂ : k[G] →ₐ[k] A} :
(∀ x, φ₁ (Finsupp.single x 1) = φ₂ (Finsupp.single x 1)) ↔ φ₁ = φ₂ :=
⟨fun h => algHom_ext h, by rintro rfl _; rfl⟩
end lift
section
-- attribute [local reducible] MonoidAlgebra -- Porting note: `reducible` cannot be `local`.
universe ui
variable {ι : Type ui}
theorem prod_single [CommSemiring k] [AddCommMonoid G] {s : Finset ι} {a : ι → G} {b : ι → k} :
(∏ i ∈ s, single (a i) (b i)) = single (∑ i ∈ s, a i) (∏ i ∈ s, b i) :=
Finset.cons_induction_on s rfl fun a s has ih => by
rw [prod_cons has, ih, single_mul_single, sum_cons has, prod_cons has]
end
theorem mapDomain_algebraMap (A : Type*) {H F : Type*} [CommSemiring k] [Semiring A] [Algebra k A]
[AddMonoid G] [AddMonoid H] [FunLike F G H] [AddMonoidHomClass F G H]
(f : F) (r : k) :
mapDomain f (algebraMap k A[G] r) = algebraMap k A[H] r := by
simp only [Function.comp_apply, mapDomain_single, AddMonoidAlgebra.coe_algebraMap, map_zero]
/-- If `f : G → H` is a homomorphism between two additive magmas, then `Finsupp.mapDomain f` is a
non-unital algebra homomorphism between their additive magma algebras. -/
@[simps apply]
def mapDomainNonUnitalAlgHom (k A : Type*) [CommSemiring k] [Semiring A] [Algebra k A]
{G H F : Type*} [Add G] [Add H] [FunLike F G H] [AddHomClass F G H] (f : F) :
A[G] →ₙₐ[k] A[H] :=
{ (Finsupp.mapDomain.addMonoidHom f : MonoidAlgebra A G →+ MonoidAlgebra A H) with
map_mul' := fun x y => mapDomain_mul f x y
map_smul' := fun r x => mapDomain_smul r x }
/-- If `f : G → H` is an additive homomorphism between two additive monoids, then
`Finsupp.mapDomain f` is an algebra homomorphism between their add monoid algebras. -/
@[simps!]
def mapDomainAlgHom (k A : Type*) [CommSemiring k] [Semiring A] [Algebra k A] [AddMonoid G]
{H F : Type*} [AddMonoid H] [FunLike F G H] [AddMonoidHomClass F G H] (f : F) :
A[G] →ₐ[k] A[H] :=
{ mapDomainRingHom A f with commutes' := mapDomain_algebraMap A f }
@[simp]
lemma mapDomainAlgHom_id (k A) [CommSemiring k] [Semiring A] [Algebra k A] [AddMonoid G] :
mapDomainAlgHom k A (AddMonoidHom.id G) = AlgHom.id k (AddMonoidAlgebra A G) := by
ext; simp [AddMonoidHom.id, ← Function.id_def]
@[simp]
lemma mapDomainAlgHom_comp (k A) {G₁ G₂ G₃} [CommSemiring k] [Semiring A] [Algebra k A]
[AddMonoid G₁] [AddMonoid G₂] [AddMonoid G₃] (f : G₁ →+ G₂) (g : G₂ →+ G₃) :
mapDomainAlgHom k A (g.comp f) = (mapDomainAlgHom k A g).comp (mapDomainAlgHom k A f) := by
ext; simp [mapDomain_comp]
variable (k A)
variable [CommSemiring k] [AddMonoid G] [AddMonoid H] [Semiring A] [Algebra k A]
/-- If `e : G ≃* H` is a multiplicative equivalence between two monoids, then
`AddMonoidAlgebra.domCongr e` is an algebra equivalence between their monoid algebras. -/
def domCongr (e : G ≃+ H) : A[G] ≃ₐ[k] A[H] :=
AlgEquiv.ofLinearEquiv
(Finsupp.domLCongr e : (G →₀ A) ≃ₗ[k] (H →₀ A))
((equivMapDomain_eq_mapDomain _ _).trans <| mapDomain_one e)
(fun f g => (equivMapDomain_eq_mapDomain _ _).trans <| (mapDomain_mul e f g).trans <|
congr_arg₂ _ (equivMapDomain_eq_mapDomain _ _).symm (equivMapDomain_eq_mapDomain _ _).symm)
theorem domCongr_toAlgHom (e : G ≃+ H) : (domCongr k A e).toAlgHom = mapDomainAlgHom k A e :=
AlgHom.ext fun _ => equivMapDomain_eq_mapDomain _ _
@[simp] theorem domCongr_apply (e : G ≃+ H) (f : MonoidAlgebra A G) (h : H) :
domCongr k A e f h = f (e.symm h) :=
rfl
@[simp] theorem domCongr_support (e : G ≃+ H) (f : MonoidAlgebra A G) :
(domCongr k A e f).support = f.support.map e :=
rfl
@[simp] theorem domCongr_single (e : G ≃+ H) (g : G) (a : A) :
domCongr k A e (single g a) = single (e g) a :=
Finsupp.equivMapDomain_single _ _ _
@[simp] theorem domCongr_refl : domCongr k A (AddEquiv.refl G) = AlgEquiv.refl :=
AlgEquiv.ext fun _ => Finsupp.ext fun _ => rfl
@[simp] theorem domCongr_symm (e : G ≃+ H) : (domCongr k A e).symm = domCongr k A e.symm := rfl
end AddMonoidAlgebra
variable [CommSemiring R]
/-- The algebra equivalence between `AddMonoidAlgebra` and `MonoidAlgebra` in terms of
`Multiplicative`. -/
def AddMonoidAlgebra.toMultiplicativeAlgEquiv [Semiring k] [Algebra R k] [AddMonoid G] :
AddMonoidAlgebra k G ≃ₐ[R] MonoidAlgebra k (Multiplicative G) :=
{ AddMonoidAlgebra.toMultiplicative k G with
commutes' := fun r => by simp [AddMonoidAlgebra.toMultiplicative] }
/-- The algebra equivalence between `MonoidAlgebra` and `AddMonoidAlgebra` in terms of
`Additive`. -/
def MonoidAlgebra.toAdditiveAlgEquiv [Semiring k] [Algebra R k] [Monoid G] :
MonoidAlgebra k G ≃ₐ[R] AddMonoidAlgebra k (Additive G) :=
{ MonoidAlgebra.toAdditive k G with commutes' := fun r => by simp [MonoidAlgebra.toAdditive] }
|
Algebra\MonoidAlgebra\Degree.lean | /-
Copyright (c) 2022 Damiano Testa. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Damiano Testa
-/
import Mathlib.Algebra.MonoidAlgebra.Support
/-!
# Lemmas about the `sup` and `inf` of the support of `AddMonoidAlgebra`
## TODO
The current plan is to state and prove lemmas about `Finset.sup (Finsupp.support f) D` with a
"generic" degree/weight function `D` from the grading Type `A` to a somewhat ordered Type `B`.
Next, the general lemmas get specialized for some yet-to-be-defined `degree`s.
-/
variable {R R' A T B ι : Type*}
namespace AddMonoidAlgebra
/-!
# sup-degree and inf-degree of an `AddMonoidAlgebra`
Let `R` be a semiring and let `A` be a `SemilatticeSup`.
For an element `f : R[A]`, this file defines
* `AddMonoidAlgebra.supDegree`: the sup-degree taking values in `WithBot A`,
* `AddMonoidAlgebra.infDegree`: the inf-degree taking values in `WithTop A`.
If the grading type `A` is a linearly ordered additive monoid, then these two notions of degree
coincide with the standard one:
* the sup-degree is the maximum of the exponents of the monomials that appear with non-zero
coefficient in `f`, or `⊥`, if `f = 0`;
* the inf-degree is the minimum of the exponents of the monomials that appear with non-zero
coefficient in `f`, or `⊤`, if `f = 0`.
The main results are
* `AddMonoidAlgebra.supDegree_mul_le`:
the sup-degree of a product is at most the sum of the sup-degrees,
* `AddMonoidAlgebra.le_infDegree_mul`:
the inf-degree of a product is at least the sum of the inf-degrees,
* `AddMonoidAlgebra.supDegree_add_le`:
the sup-degree of a sum is at most the sup of the sup-degrees,
* `AddMonoidAlgebra.le_infDegree_add`:
the inf-degree of a sum is at least the inf of the inf-degrees.
## Implementation notes
The current plan is to state and prove lemmas about `Finset.sup (Finsupp.support f) D` with a
"generic" degree/weight function `D` from the grading Type `A` to a somewhat ordered Type `B`.
Next, the general lemmas get specialized twice:
* once for `supDegree` (essentially a simple application) and
* once for `infDegree` (a simple application, via `OrderDual`).
These final lemmas are the ones that likely get used the most. The generic lemmas about
`Finset.support.sup` may not be used directly much outside of this file.
To see this in action, you can look at the triple
`(sup_support_mul_le, maxDegree_mul_le, le_minDegree_mul)`.
-/
section GeneralResultsAssumingSemilatticeSup
variable [SemilatticeSup B] [OrderBot B] [SemilatticeInf T] [OrderTop T]
section Semiring
variable [Semiring R]
section ExplicitDegrees
/-!
In this section, we use `degb` and `degt` to denote "degree functions" on `A` with values in
a type with *b*ot or *t*op respectively.
-/
variable (degb : A → B) (degt : A → T) (f g : R[A])
theorem sup_support_add_le :
(f + g).support.sup degb ≤ f.support.sup degb ⊔ g.support.sup degb := by
classical
exact (Finset.sup_mono Finsupp.support_add).trans_eq Finset.sup_union
theorem le_inf_support_add : f.support.inf degt ⊓ g.support.inf degt ≤ (f + g).support.inf degt :=
sup_support_add_le (fun a : A => OrderDual.toDual (degt a)) f g
end ExplicitDegrees
section AddOnly
variable [Add A] [Add B] [Add T] [CovariantClass B B (· + ·) (· ≤ ·)]
[CovariantClass B B (Function.swap (· + ·)) (· ≤ ·)] [CovariantClass T T (· + ·) (· ≤ ·)]
[CovariantClass T T (Function.swap (· + ·)) (· ≤ ·)]
theorem sup_support_mul_le {degb : A → B} (degbm : ∀ {a b}, degb (a + b) ≤ degb a + degb b)
(f g : R[A]) :
(f * g).support.sup degb ≤ f.support.sup degb + g.support.sup degb := by
classical
exact (Finset.sup_mono <| support_mul _ _).trans <| Finset.sup_add_le.2 fun _fd fds _gd gds ↦
degbm.trans <| add_le_add (Finset.le_sup fds) (Finset.le_sup gds)
theorem le_inf_support_mul {degt : A → T} (degtm : ∀ {a b}, degt a + degt b ≤ degt (a + b))
(f g : R[A]) :
f.support.inf degt + g.support.inf degt ≤ (f * g).support.inf degt :=
sup_support_mul_le (B := Tᵒᵈ) degtm f g
end AddOnly
section AddMonoids
variable [AddMonoid A] [AddMonoid B] [CovariantClass B B (· + ·) (· ≤ ·)]
[CovariantClass B B (Function.swap (· + ·)) (· ≤ ·)] [AddMonoid T]
[CovariantClass T T (· + ·) (· ≤ ·)] [CovariantClass T T (Function.swap (· + ·)) (· ≤ ·)]
{degb : A → B} {degt : A → T}
theorem sup_support_list_prod_le (degb0 : degb 0 ≤ 0)
(degbm : ∀ a b, degb (a + b) ≤ degb a + degb b) :
∀ l : List R[A],
l.prod.support.sup degb ≤ (l.map fun f : R[A] => f.support.sup degb).sum
| [] => by
rw [List.map_nil, Finset.sup_le_iff, List.prod_nil, List.sum_nil]
exact fun a ha => by rwa [Finset.mem_singleton.mp (Finsupp.support_single_subset ha)]
| f::fs => by
rw [List.prod_cons, List.map_cons, List.sum_cons]
exact (sup_support_mul_le (@fun a b => degbm a b) _ _).trans
(add_le_add_left (sup_support_list_prod_le degb0 degbm fs) _)
theorem le_inf_support_list_prod (degt0 : 0 ≤ degt 0)
(degtm : ∀ a b, degt a + degt b ≤ degt (a + b)) (l : List R[A]) :
(l.map fun f : R[A] => f.support.inf degt).sum ≤ l.prod.support.inf degt := by
refine OrderDual.ofDual_le_ofDual.mpr ?_
refine sup_support_list_prod_le ?_ ?_ l
· refine (OrderDual.ofDual_le_ofDual.mp ?_)
exact degt0
· refine (fun a b => OrderDual.ofDual_le_ofDual.mp ?_)
exact degtm a b
theorem sup_support_pow_le (degb0 : degb 0 ≤ 0) (degbm : ∀ a b, degb (a + b) ≤ degb a + degb b)
(n : ℕ) (f : R[A]) : (f ^ n).support.sup degb ≤ n • f.support.sup degb := by
rw [← List.prod_replicate, ← List.sum_replicate]
refine (sup_support_list_prod_le degb0 degbm _).trans_eq ?_
rw [List.map_replicate]
theorem le_inf_support_pow (degt0 : 0 ≤ degt 0) (degtm : ∀ a b, degt a + degt b ≤ degt (a + b))
(n : ℕ) (f : R[A]) : n • f.support.inf degt ≤ (f ^ n).support.inf degt := by
refine OrderDual.ofDual_le_ofDual.mpr <| sup_support_pow_le (OrderDual.ofDual_le_ofDual.mp ?_)
(fun a b => OrderDual.ofDual_le_ofDual.mp ?_) n f
· exact degt0
· exact degtm _ _
end AddMonoids
end Semiring
section CommutativeLemmas
variable [CommSemiring R] [AddCommMonoid A] [AddCommMonoid B] [CovariantClass B B (· + ·) (· ≤ ·)]
[CovariantClass B B (Function.swap (· + ·)) (· ≤ ·)] [AddCommMonoid T]
[CovariantClass T T (· + ·) (· ≤ ·)] [CovariantClass T T (Function.swap (· + ·)) (· ≤ ·)]
{degb : A → B} {degt : A → T}
theorem sup_support_multiset_prod_le (degb0 : degb 0 ≤ 0)
(degbm : ∀ a b, degb (a + b) ≤ degb a + degb b) (m : Multiset R[A]) :
m.prod.support.sup degb ≤ (m.map fun f : R[A] => f.support.sup degb).sum := by
induction m using Quot.inductionOn
rw [Multiset.quot_mk_to_coe'', Multiset.map_coe, Multiset.sum_coe, Multiset.prod_coe]
exact sup_support_list_prod_le degb0 degbm _
theorem le_inf_support_multiset_prod (degt0 : 0 ≤ degt 0)
(degtm : ∀ a b, degt a + degt b ≤ degt (a + b)) (m : Multiset R[A]) :
(m.map fun f : R[A] => f.support.inf degt).sum ≤ m.prod.support.inf degt := by
refine OrderDual.ofDual_le_ofDual.mpr <|
sup_support_multiset_prod_le (OrderDual.ofDual_le_ofDual.mp ?_)
(fun a b => OrderDual.ofDual_le_ofDual.mp ?_) m
· exact degt0
· exact degtm _ _
theorem sup_support_finset_prod_le (degb0 : degb 0 ≤ 0)
(degbm : ∀ a b, degb (a + b) ≤ degb a + degb b) (s : Finset ι) (f : ι → R[A]) :
(∏ i ∈ s, f i).support.sup degb ≤ ∑ i ∈ s, (f i).support.sup degb :=
(sup_support_multiset_prod_le degb0 degbm _).trans_eq <| congr_arg _ <| Multiset.map_map _ _ _
theorem le_inf_support_finset_prod (degt0 : 0 ≤ degt 0)
(degtm : ∀ a b, degt a + degt b ≤ degt (a + b)) (s : Finset ι) (f : ι → R[A]) :
(∑ i ∈ s, (f i).support.inf degt) ≤ (∏ i ∈ s, f i).support.inf degt :=
le_of_eq_of_le (by rw [Multiset.map_map]; rfl) (le_inf_support_multiset_prod degt0 degtm _)
end CommutativeLemmas
end GeneralResultsAssumingSemilatticeSup
/-! ### Shorthands for special cases
Note that these definitions are reducible, in order to make it easier to apply the more generic
lemmas above. -/
section Degrees
variable [Semiring R] [Ring R']
section SupDegree
variable [SemilatticeSup B] [OrderBot B] (D : A → B)
/-- Let `R` be a semiring, let `A` be an `AddZeroClass`, let `B` be an `OrderBot`,
and let `D : A → B` be a "degree" function.
For an element `f : R[A]`, the element `supDegree f : B` is the supremum of all the elements in the
support of `f`, or `⊥` if `f` is zero.
Often, the Type `B` is `WithBot A`,
If, further, `A` has a linear order, then this notion coincides with the usual one,
using the maximum of the exponents. -/
abbrev supDegree (f : R[A]) : B :=
f.support.sup D
variable {D}
theorem supDegree_add_le {f g : R[A]} :
(f + g).supDegree D ≤ (f.supDegree D) ⊔ (g.supDegree D) :=
sup_support_add_le D f g
@[simp]
theorem supDegree_neg {f : R'[A]} :
(-f).supDegree D = f.supDegree D := by
rw [supDegree, supDegree, Finsupp.support_neg]
theorem supDegree_sub_le {f g : R'[A]} :
(f - g).supDegree D ≤ f.supDegree D ⊔ g.supDegree D := by
rw [sub_eq_add_neg, ← supDegree_neg (f := g)]; apply supDegree_add_le
theorem supDegree_sum_le {ι} {s : Finset ι} {f : ι → R[A]} :
(∑ i ∈ s, f i).supDegree D ≤ s.sup (fun i => (f i).supDegree D) := by
classical
exact (Finset.sup_mono Finsupp.support_finset_sum).trans_eq (Finset.sup_biUnion _ _)
theorem supDegree_single_ne_zero (a : A) {r : R} (hr : r ≠ 0) :
(single a r).supDegree D = D a := by
rw [supDegree, Finsupp.support_single_ne_zero a hr, Finset.sup_singleton]
open Classical in
theorem supDegree_single (a : A) (r : R) :
(single a r).supDegree D = if r = 0 then ⊥ else D a := by
split_ifs with hr <;> simp [supDegree_single_ne_zero, hr]
theorem apply_eq_zero_of_not_le_supDegree {p : R[A]} {a : A} (hlt : ¬ D a ≤ p.supDegree D) :
p a = 0 := by
contrapose! hlt
exact Finset.le_sup (Finsupp.mem_support_iff.2 hlt)
theorem supDegree_withBot_some_comp {s : AddMonoidAlgebra R A} (hs : s.support.Nonempty) :
supDegree (WithBot.some ∘ D) s = supDegree D s := by
unfold AddMonoidAlgebra.supDegree
rw [← Finset.coe_sup' hs, Finset.sup'_eq_sup]
variable [AddZeroClass A] {p q : R[A]}
@[simp]
theorem supDegree_zero : (0 : R[A]).supDegree D = ⊥ := by simp [supDegree]
theorem ne_zero_of_supDegree_ne_bot : p.supDegree D ≠ ⊥ → p ≠ 0 := mt (fun h => h ▸ supDegree_zero)
theorem ne_zero_of_not_supDegree_le {b : B} (h : ¬ p.supDegree D ≤ b) : p ≠ 0 :=
ne_zero_of_supDegree_ne_bot (fun he => h <| he ▸ bot_le)
variable [Add B]
theorem supDegree_mul_le (hadd : ∀ a1 a2, D (a1 + a2) = D a1 + D a2)
[CovariantClass B B (· + ·) (· ≤ ·)] [CovariantClass B B (Function.swap (· + ·)) (· ≤ ·)] :
(p * q).supDegree D ≤ p.supDegree D + q.supDegree D :=
sup_support_mul_le (fun {_ _} => (hadd _ _).le) p q
theorem supDegree_prod_le {R A B : Type*} [CommSemiring R] [AddCommMonoid A] [AddCommMonoid B]
[SemilatticeSup B] [OrderBot B]
[CovariantClass B B (· + ·) (· ≤ ·)] [CovariantClass B B (Function.swap (· + ·)) (· ≤ ·)]
{D : A → B} (hzero : D 0 = 0) (hadd : ∀ a1 a2, D (a1 + a2) = D a1 + D a2)
{ι} {s : Finset ι} {f : ι → R[A]} :
(∏ i ∈ s, f i).supDegree D ≤ ∑ i ∈ s, (f i).supDegree D := by
classical
refine s.induction ?_ ?_
· rw [Finset.prod_empty, Finset.sum_empty, one_def, supDegree_single]
split_ifs; exacts [bot_le, hzero.le]
· intro i s his ih
rw [Finset.prod_insert his, Finset.sum_insert his]
exact (supDegree_mul_le hadd).trans (add_le_add_left ih _)
theorem apply_add_of_supDegree_le (hadd : ∀ a1 a2, D (a1 + a2) = D a1 + D a2)
[CovariantClass B B (· + ·) (· < ·)] [CovariantClass B B (Function.swap (· + ·)) (· < ·)]
(hD : D.Injective) {ap aq : A} (hp : p.supDegree D ≤ D ap) (hq : q.supDegree D ≤ D aq) :
(p * q) (ap + aq) = p ap * q aq := by
classical
simp_rw [mul_apply, Finsupp.sum]
rw [Finset.sum_eq_single ap, Finset.sum_eq_single aq, if_pos rfl]
· refine fun a ha hne => if_neg (fun he => ?_)
apply_fun D at he; simp_rw [hadd] at he
exact (add_lt_add_left (((Finset.le_sup ha).trans hq).lt_of_ne <| hD.ne_iff.2 hne) _).ne he
· intro h; rw [if_pos rfl, Finsupp.not_mem_support_iff.1 h, mul_zero]
· refine fun a ha hne => Finset.sum_eq_zero (fun a' ha' => if_neg <| fun he => ?_)
apply_fun D at he
simp_rw [hadd] at he
have := covariantClass_le_of_lt B B (· + ·)
exact (add_lt_add_of_lt_of_le (((Finset.le_sup ha).trans hp).lt_of_ne <| hD.ne_iff.2 hne)
<| (Finset.le_sup ha').trans hq).ne he
· refine fun h => Finset.sum_eq_zero (fun a _ => ite_eq_right_iff.mpr <| fun _ => ?_)
rw [Finsupp.not_mem_support_iff.mp h, zero_mul]
end SupDegree
section InfDegree
variable [SemilatticeInf T] [OrderTop T] (D : A → T)
/-- Let `R` be a semiring, let `A` be an `AddZeroClass`, let `T` be an `OrderTop`,
and let `D : A → T` be a "degree" function.
For an element `f : R[A]`, the element `infDegree f : T` is the infimum of all the elements in the
support of `f`, or `⊤` if `f` is zero.
Often, the Type `T` is `WithTop A`,
If, further, `A` has a linear order, then this notion coincides with the usual one,
using the minimum of the exponents. -/
abbrev infDegree (f : R[A]) : T :=
f.support.inf D
theorem le_infDegree_add (f g : R[A]) :
(f.infDegree D) ⊓ (g.infDegree D) ≤ (f + g).infDegree D :=
le_inf_support_add D f g
variable {D} in
theorem infDegree_withTop_some_comp {s : AddMonoidAlgebra R A} (hs : s.support.Nonempty) :
infDegree (WithTop.some ∘ D) s = infDegree D s := by
unfold AddMonoidAlgebra.infDegree
rw [← Finset.coe_inf' hs, Finset.inf'_eq_inf]
theorem le_infDegree_mul
[AddZeroClass A] [Add T]
[CovariantClass T T (· + ·) (· ≤ ·)] [CovariantClass T T (Function.swap (· + ·)) (· ≤ ·)]
(D : AddHom A T) (f g : R[A]) :
f.infDegree D + g.infDegree D ≤ (f * g).infDegree D :=
le_inf_support_mul (fun {a b : A} => (map_add D a b).ge) _ _
end InfDegree
end Degrees
end AddMonoidAlgebra
|
Algebra\MonoidAlgebra\Division.lean | /-
Copyright (c) 2022 Eric Wieser. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Eric Wieser
-/
import Mathlib.Algebra.MonoidAlgebra.Basic
/-!
# Division of `AddMonoidAlgebra` by monomials
This file is most important for when `G = ℕ` (polynomials) or `G = σ →₀ ℕ` (multivariate
polynomials).
In order to apply in maximal generality (such as for `LaurentPolynomial`s), this uses
`∃ d, g' = g + d` in many places instead of `g ≤ g'`.
## Main definitions
* `AddMonoidAlgebra.divOf x g`: divides `x` by the monomial `AddMonoidAlgebra.of k G g`
* `AddMonoidAlgebra.modOf x g`: the remainder upon dividing `x` by the monomial
`AddMonoidAlgebra.of k G g`.
## Main results
* `AddMonoidAlgebra.divOf_add_modOf`, `AddMonoidAlgebra.modOf_add_divOf`: `divOf` and
`modOf` are well-behaved as quotient and remainder operators.
## Implementation notes
`∃ d, g' = g + d` is used as opposed to some other permutation up to commutativity in order to match
the definition of `semigroupDvd`. The results in this file could be duplicated for
`MonoidAlgebra` by using `g ∣ g'`, but this can't be done automatically, and in any case is not
likely to be very useful.
-/
variable {k G : Type*} [Semiring k]
namespace AddMonoidAlgebra
section
variable [AddCancelCommMonoid G]
/-- Divide by `of' k G g`, discarding terms not divisible by this. -/
noncomputable def divOf (x : k[G]) (g : G) : k[G] :=
-- note: comapping by `+ g` has the effect of subtracting `g` from every element in
-- the support, and discarding the elements of the support from which `g` can't be subtracted.
-- If `G` is an additive group, such as `ℤ` when used for `LaurentPolynomial`,
-- then no discarding occurs.
@Finsupp.comapDomain.addMonoidHom _ _ _ _ (g + ·) (add_right_injective g) x
local infixl:70 " /ᵒᶠ " => divOf
@[simp]
theorem divOf_apply (g : G) (x : k[G]) (g' : G) : (x /ᵒᶠ g) g' = x (g + g') :=
rfl
@[simp]
theorem support_divOf (g : G) (x : k[G]) :
(x /ᵒᶠ g).support =
x.support.preimage (g + ·) (Function.Injective.injOn (add_right_injective g)) :=
rfl
@[simp]
theorem zero_divOf (g : G) : (0 : k[G]) /ᵒᶠ g = 0 :=
map_zero (Finsupp.comapDomain.addMonoidHom _)
@[simp]
theorem divOf_zero (x : k[G]) : x /ᵒᶠ 0 = x := by
refine Finsupp.ext fun _ => ?_ -- Porting note: `ext` doesn't work
simp only [AddMonoidAlgebra.divOf_apply, zero_add]
theorem add_divOf (x y : k[G]) (g : G) : (x + y) /ᵒᶠ g = x /ᵒᶠ g + y /ᵒᶠ g :=
map_add (Finsupp.comapDomain.addMonoidHom _) _ _
theorem divOf_add (x : k[G]) (a b : G) : x /ᵒᶠ (a + b) = x /ᵒᶠ a /ᵒᶠ b := by
refine Finsupp.ext fun _ => ?_ -- Porting note: `ext` doesn't work
simp only [AddMonoidAlgebra.divOf_apply, add_assoc]
/-- A bundled version of `AddMonoidAlgebra.divOf`. -/
@[simps]
noncomputable def divOfHom : Multiplicative G →* AddMonoid.End k[G] where
toFun g :=
{ toFun := fun x => divOf x (Multiplicative.toAdd g)
map_zero' := zero_divOf _
map_add' := fun x y => add_divOf x y (Multiplicative.toAdd g) }
map_one' := AddMonoidHom.ext divOf_zero
map_mul' g₁ g₂ :=
AddMonoidHom.ext fun _x =>
(congr_arg _ (add_comm (Multiplicative.toAdd g₁) (Multiplicative.toAdd g₂))).trans
(divOf_add _ _ _)
theorem of'_mul_divOf (a : G) (x : k[G]) : of' k G a * x /ᵒᶠ a = x := by
refine Finsupp.ext fun _ => ?_ -- Porting note: `ext` doesn't work
rw [AddMonoidAlgebra.divOf_apply, of'_apply, single_mul_apply_aux, one_mul]
intro c
exact add_right_inj _
theorem mul_of'_divOf (x : k[G]) (a : G) : x * of' k G a /ᵒᶠ a = x := by
refine Finsupp.ext fun _ => ?_ -- Porting note: `ext` doesn't work
rw [AddMonoidAlgebra.divOf_apply, of'_apply, mul_single_apply_aux, mul_one]
intro c
rw [add_comm]
exact add_right_inj _
theorem of'_divOf (a : G) : of' k G a /ᵒᶠ a = 1 := by
simpa only [one_mul] using mul_of'_divOf (1 : k[G]) a
/-- The remainder upon division by `of' k G g`. -/
noncomputable def modOf (x : k[G]) (g : G) : k[G] :=
letI := Classical.decPred fun g₁ => ∃ g₂, g₁ = g + g₂
x.filter fun g₁ => ¬∃ g₂, g₁ = g + g₂
local infixl:70 " %ᵒᶠ " => modOf
@[simp]
theorem modOf_apply_of_not_exists_add (x : k[G]) (g : G) (g' : G)
(h : ¬∃ d, g' = g + d) : (x %ᵒᶠ g) g' = x g' := by
classical exact Finsupp.filter_apply_pos _ _ h
@[simp]
theorem modOf_apply_of_exists_add (x : k[G]) (g : G) (g' : G)
(h : ∃ d, g' = g + d) : (x %ᵒᶠ g) g' = 0 := by
classical exact Finsupp.filter_apply_neg _ _ <| by rwa [Classical.not_not]
@[simp]
theorem modOf_apply_add_self (x : k[G]) (g : G) (d : G) : (x %ᵒᶠ g) (d + g) = 0 :=
modOf_apply_of_exists_add _ _ _ ⟨_, add_comm _ _⟩
-- @[simp] -- Porting note (#10618): simp can prove this
theorem modOf_apply_self_add (x : k[G]) (g : G) (d : G) : (x %ᵒᶠ g) (g + d) = 0 :=
modOf_apply_of_exists_add _ _ _ ⟨_, rfl⟩
theorem of'_mul_modOf (g : G) (x : k[G]) : of' k G g * x %ᵒᶠ g = 0 := by
refine Finsupp.ext fun g' => ?_ -- Porting note: `ext g'` doesn't work
rw [Finsupp.zero_apply]
obtain ⟨d, rfl⟩ | h := em (∃ d, g' = g + d)
· rw [modOf_apply_self_add]
· rw [modOf_apply_of_not_exists_add _ _ _ h, of'_apply, single_mul_apply_of_not_exists_add _ _ h]
theorem mul_of'_modOf (x : k[G]) (g : G) : x * of' k G g %ᵒᶠ g = 0 := by
refine Finsupp.ext fun g' => ?_ -- Porting note: `ext g'` doesn't work
rw [Finsupp.zero_apply]
obtain ⟨d, rfl⟩ | h := em (∃ d, g' = g + d)
· rw [modOf_apply_self_add]
· rw [modOf_apply_of_not_exists_add _ _ _ h, of'_apply, mul_single_apply_of_not_exists_add]
simpa only [add_comm] using h
theorem of'_modOf (g : G) : of' k G g %ᵒᶠ g = 0 := by
simpa only [one_mul] using mul_of'_modOf (1 : k[G]) g
theorem divOf_add_modOf (x : k[G]) (g : G) :
of' k G g * (x /ᵒᶠ g) + x %ᵒᶠ g = x := by
refine Finsupp.ext fun g' => ?_ -- Porting note: `ext` doesn't work
rw [Finsupp.add_apply] -- Porting note: changed from `simp_rw` which can't see through the type
obtain ⟨d, rfl⟩ | h := em (∃ d, g' = g + d)
swap
· rw [modOf_apply_of_not_exists_add x _ _ h, of'_apply, single_mul_apply_of_not_exists_add _ _ h,
zero_add]
· rw [modOf_apply_self_add, add_zero]
rw [of'_apply, single_mul_apply_aux _ _ _, one_mul, divOf_apply]
intro a
exact add_right_inj _
theorem modOf_add_divOf (x : k[G]) (g : G) : x %ᵒᶠ g + of' k G g * (x /ᵒᶠ g) = x := by
rw [add_comm, divOf_add_modOf]
theorem of'_dvd_iff_modOf_eq_zero {x : k[G]} {g : G} :
of' k G g ∣ x ↔ x %ᵒᶠ g = 0 := by
constructor
· rintro ⟨x, rfl⟩
rw [of'_mul_modOf]
· intro h
rw [← divOf_add_modOf x g, h, add_zero]
exact dvd_mul_right _ _
end
end AddMonoidAlgebra
|
Algebra\MonoidAlgebra\Grading.lean | /-
Copyright (c) 2021 Eric Wieser. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Eric Wieser
-/
import Mathlib.LinearAlgebra.Finsupp
import Mathlib.Algebra.MonoidAlgebra.Support
import Mathlib.Algebra.DirectSum.Internal
import Mathlib.RingTheory.GradedAlgebra.Basic
/-!
# Internal grading of an `AddMonoidAlgebra`
In this file, we show that an `AddMonoidAlgebra` has an internal direct sum structure.
## Main results
* `AddMonoidAlgebra.gradeBy R f i`: the `i`th grade of an `R[M]` given by the
degree function `f`.
* `AddMonoidAlgebra.grade R i`: the `i`th grade of an `R[M]` when the degree
function is the identity.
* `AddMonoidAlgebra.gradeBy.gradedAlgebra`: `AddMonoidAlgebra` is an algebra graded by
`AddMonoidAlgebra.gradeBy`.
* `AddMonoidAlgebra.grade.gradedAlgebra`: `AddMonoidAlgebra` is an algebra graded by
`AddMonoidAlgebra.grade`.
* `AddMonoidAlgebra.gradeBy.isInternal`: propositionally, the statement that
`AddMonoidAlgebra.gradeBy` defines an internal graded structure.
* `AddMonoidAlgebra.grade.isInternal`: propositionally, the statement that
`AddMonoidAlgebra.grade` defines an internal graded structure when the degree function
is the identity.
-/
noncomputable section
namespace AddMonoidAlgebra
variable {M : Type*} {ι : Type*} {R : Type*}
section
variable (R) [CommSemiring R]
/-- The submodule corresponding to each grade given by the degree function `f`. -/
abbrev gradeBy (f : M → ι) (i : ι) : Submodule R R[M] where
carrier := { a | ∀ m, m ∈ a.support → f m = i }
zero_mem' m h := by cases h
add_mem' {a b} ha hb m h := by
classical exact (Finset.mem_union.mp (Finsupp.support_add h)).elim (ha m) (hb m)
smul_mem' a m h := Set.Subset.trans Finsupp.support_smul h
/-- The submodule corresponding to each grade. -/
abbrev grade (m : M) : Submodule R R[M] :=
gradeBy R id m
theorem gradeBy_id : gradeBy R (id : M → M) = grade R := rfl
theorem mem_gradeBy_iff (f : M → ι) (i : ι) (a : R[M]) :
a ∈ gradeBy R f i ↔ (a.support : Set M) ⊆ f ⁻¹' {i} := by rfl
theorem mem_grade_iff (m : M) (a : R[M]) : a ∈ grade R m ↔ a.support ⊆ {m} := by
rw [← Finset.coe_subset, Finset.coe_singleton]
rfl
theorem mem_grade_iff' (m : M) (a : R[M]) :
a ∈ grade R m ↔ a ∈ (LinearMap.range (Finsupp.lsingle m : R →ₗ[R] M →₀ R) :
Submodule R R[M]) := by
rw [mem_grade_iff, Finsupp.support_subset_singleton']
apply exists_congr
intro r
constructor <;> exact Eq.symm
theorem grade_eq_lsingle_range (m : M) :
grade R m = LinearMap.range (Finsupp.lsingle m : R →ₗ[R] M →₀ R) :=
Submodule.ext (mem_grade_iff' R m)
theorem single_mem_gradeBy {R} [CommSemiring R] (f : M → ι) (m : M) (r : R) :
Finsupp.single m r ∈ gradeBy R f (f m) := by
intro x hx
rw [Finset.mem_singleton.mp (Finsupp.support_single_subset hx)]
theorem single_mem_grade {R} [CommSemiring R] (i : M) (r : R) : Finsupp.single i r ∈ grade R i :=
single_mem_gradeBy _ _ _
end
open DirectSum
instance gradeBy.gradedMonoid [AddMonoid M] [AddMonoid ι] [CommSemiring R] (f : M →+ ι) :
SetLike.GradedMonoid (gradeBy R f : ι → Submodule R R[M]) where
one_mem m h := by
rw [one_def] at h
obtain rfl : m = 0 := Finset.mem_singleton.1 <| Finsupp.support_single_subset h
apply map_zero
mul_mem i j a b ha hb c hc := by
classical
obtain ⟨ma, hma, mb, hmb, rfl⟩ : ∃ y ∈ a.support, ∃ z ∈ b.support, y + z = c :=
Finset.mem_add.1 <| support_mul a b hc
rw [map_add, ha ma hma, hb mb hmb]
instance grade.gradedMonoid [AddMonoid M] [CommSemiring R] :
SetLike.GradedMonoid (grade R : M → Submodule R R[M]) := by
apply gradeBy.gradedMonoid (AddMonoidHom.id _)
variable [AddMonoid M] [DecidableEq ι] [AddMonoid ι] [CommSemiring R] (f : M →+ ι)
/-- Auxiliary definition; the canonical grade decomposition, used to provide
`DirectSum.decompose`. -/
def decomposeAux : R[M] →ₐ[R] ⨁ i : ι, gradeBy R f i :=
AddMonoidAlgebra.lift R M _
{ toFun := fun m =>
DirectSum.of (fun i : ι => gradeBy R f i) (f (Multiplicative.toAdd m))
⟨Finsupp.single (Multiplicative.toAdd m) 1, single_mem_gradeBy _ _ _⟩
map_one' :=
DirectSum.of_eq_of_gradedMonoid_eq
(by congr 2 <;> simp)
map_mul' := fun i j => by
symm
dsimp only [toAdd_one, Eq.ndrec, Set.mem_setOf_eq, ne_eq, OneHom.toFun_eq_coe,
OneHom.coe_mk, toAdd_mul]
convert DirectSum.of_mul_of (A := (fun i : ι => gradeBy R f i)) _ _
repeat { rw [AddMonoidHom.map_add] }
simp only [SetLike.coe_gMul]
exact Eq.trans (by rw [one_mul]) single_mul_single.symm }
theorem decomposeAux_single (m : M) (r : R) :
decomposeAux f (Finsupp.single m r) =
DirectSum.of (fun i : ι => gradeBy R f i) (f m)
⟨Finsupp.single m r, single_mem_gradeBy _ _ _⟩ := by
refine (lift_single _ _ _).trans ?_
refine (DirectSum.of_smul R _ _ _).symm.trans ?_
apply DirectSum.of_eq_of_gradedMonoid_eq
refine Sigma.subtype_ext rfl ?_
refine (Finsupp.smul_single' _ _ _).trans ?_
rw [mul_one]
rfl
theorem decomposeAux_coe {i : ι} (x : gradeBy R f i) :
decomposeAux f ↑x = DirectSum.of (fun i => gradeBy R f i) i x := by
classical
obtain ⟨x, hx⟩ := x
revert hx
refine Finsupp.induction x ?_ ?_
· intro hx
symm
exact AddMonoidHom.map_zero _
· intro m b y hmy hb ih hmby
have : Disjoint (Finsupp.single m b).support y.support := by
simpa only [Finsupp.support_single_ne_zero _ hb, Finset.disjoint_singleton_left]
rw [mem_gradeBy_iff, Finsupp.support_add_eq this, Finset.coe_union, Set.union_subset_iff]
at hmby
cases' hmby with h1 h2
have : f m = i := by
rwa [Finsupp.support_single_ne_zero _ hb, Finset.coe_singleton, Set.singleton_subset_iff]
at h1
subst this
simp only [map_add, Submodule.coe_mk, decomposeAux_single f m]
let ih' := ih h2
dsimp at ih'
rw [ih', ← AddMonoidHom.map_add]
apply DirectSum.of_eq_of_gradedMonoid_eq
congr 2
instance gradeBy.gradedAlgebra : GradedAlgebra (gradeBy R f) :=
GradedAlgebra.ofAlgHom _ (decomposeAux f)
(by
ext : 2
simp only [MonoidHom.coe_comp, MonoidHom.coe_coe, AlgHom.coe_comp, Function.comp_apply,
of_apply, AlgHom.coe_id, id_eq]
rw [decomposeAux_single, DirectSum.coeAlgHom_of, Subtype.coe_mk])
fun i x => by rw [decomposeAux_coe f x]
-- Lean can't find this later without us repeating it
instance gradeBy.decomposition : DirectSum.Decomposition (gradeBy R f) := by infer_instance
@[simp]
theorem decomposeAux_eq_decompose :
⇑(decomposeAux f : R[M] →ₐ[R] ⨁ i : ι, gradeBy R f i) =
DirectSum.decompose (gradeBy R f) :=
rfl
theorem GradesBy.decompose_single (m : M) (r : R) :
DirectSum.decompose (gradeBy R f) (Finsupp.single m r : R[M]) =
DirectSum.of (fun i : ι => gradeBy R f i) (f m)
⟨Finsupp.single m r, single_mem_gradeBy _ _ _⟩ :=
decomposeAux_single _ _ _
instance grade.gradedAlgebra : GradedAlgebra (grade R : ι → Submodule _ _) :=
AddMonoidAlgebra.gradeBy.gradedAlgebra (AddMonoidHom.id _)
-- Lean can't find this later without us repeating it
instance grade.decomposition : DirectSum.Decomposition (grade R : ι → Submodule _ _) := by
infer_instance
theorem grade.decompose_single (i : ι) (r : R) :
DirectSum.decompose (grade R : ι → Submodule _ _) (Finsupp.single i r : AddMonoidAlgebra _ _) =
DirectSum.of (fun i : ι => grade R i) i ⟨Finsupp.single i r, single_mem_grade _ _⟩ :=
decomposeAux_single _ _ _
/-- `AddMonoidAlgebra.gradeBy` describe an internally graded algebra. -/
theorem gradeBy.isInternal : DirectSum.IsInternal (gradeBy R f) :=
DirectSum.Decomposition.isInternal _
/-- `AddMonoidAlgebra.grade` describe an internally graded algebra. -/
theorem grade.isInternal : DirectSum.IsInternal (grade R : ι → Submodule R _) :=
DirectSum.Decomposition.isInternal _
end AddMonoidAlgebra
|
Algebra\MonoidAlgebra\Ideal.lean | /-
Copyright (c) 2023 Eric Wieser. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Eric Wieser
-/
import Mathlib.Algebra.MonoidAlgebra.Basic
import Mathlib.RingTheory.Ideal.Basic
/-!
# Lemmas about ideals of `MonoidAlgebra` and `AddMonoidAlgebra`
-/
variable {k A G : Type*}
/-- If `x` belongs to the ideal generated by generators in `s`, then every element of the support of
`x` factors through an element of `s`.
We could spell `∃ d, m = d * m` as `MulOpposite.op m' ∣ MulOpposite.op m` but this would be worse.
-/
theorem MonoidAlgebra.mem_ideal_span_of_image [Monoid G] [Semiring k] {s : Set G}
{x : MonoidAlgebra k G} :
x ∈ Ideal.span (MonoidAlgebra.of k G '' s) ↔ ∀ m ∈ x.support, ∃ m' ∈ s, ∃ d, m = d * m' := by
let RHS : Ideal (MonoidAlgebra k G) :=
{ carrier := { p | ∀ m : G, m ∈ p.support → ∃ m' ∈ s, ∃ d, m = d * m' }
add_mem' := fun {x y} hx hy m hm => by
classical exact (Finset.mem_union.1 <| Finsupp.support_add hm).elim (hx m) (hy m)
zero_mem' := fun m hm => by cases hm
smul_mem' := fun x y hy m hm => by
classical
rw [smul_eq_mul, mul_def] at hm
replace hm := Finset.mem_biUnion.mp (Finsupp.support_sum hm)
obtain ⟨xm, -, hm⟩ := hm
replace hm := Finset.mem_biUnion.mp (Finsupp.support_sum hm)
obtain ⟨ym, hym, hm⟩ := hm
obtain rfl := Finset.mem_singleton.mp (Finsupp.support_single_subset hm)
refine (hy _ hym).imp fun sm p => And.imp_right ?_ p
rintro ⟨d, rfl⟩
exact ⟨xm * d, (mul_assoc _ _ _).symm⟩ }
change _ ↔ x ∈ RHS
constructor
· revert x
rw [← SetLike.le_def] -- Porting note: refine needs this even though it's defeq?
refine Ideal.span_le.2 ?_
rintro _ ⟨i, hi, rfl⟩ m hm
refine ⟨_, hi, 1, ?_⟩
obtain rfl := Finset.mem_singleton.mp (Finsupp.support_single_subset hm)
exact (one_mul _).symm
· intro hx
rw [← Finsupp.sum_single x]
refine Ideal.sum_mem _ fun i hi => ?_ -- Porting note: changed `apply` to `refine`
obtain ⟨d, hd, d2, rfl⟩ := hx _ hi
convert Ideal.mul_mem_left _ (id <| Finsupp.single d2 <| x (d2 * d) : MonoidAlgebra k G) _
pick_goal 3
· exact Ideal.subset_span ⟨_, hd, rfl⟩
rw [id, MonoidAlgebra.of_apply, MonoidAlgebra.single_mul_single, mul_one]
/-- If `x` belongs to the ideal generated by generators in `s`, then every element of the support of
`x` factors additively through an element of `s`.
-/
theorem AddMonoidAlgebra.mem_ideal_span_of'_image [AddMonoid A] [Semiring k] {s : Set A}
{x : AddMonoidAlgebra k A} :
x ∈ Ideal.span (AddMonoidAlgebra.of' k A '' s) ↔ ∀ m ∈ x.support, ∃ m' ∈ s, ∃ d, m = d + m' :=
@MonoidAlgebra.mem_ideal_span_of_image k (Multiplicative A) _ _ _ _
|
Algebra\MonoidAlgebra\NoZeroDivisors.lean | /-
Copyright (c) 2022 Damiano Testa. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Damiano Testa
-/
import Mathlib.Algebra.MonoidAlgebra.Basic
import Mathlib.Algebra.Group.UniqueProds
/-!
# Variations on non-zero divisors in `AddMonoidAlgebra`s
This file studies the interaction between typeclass assumptions on two Types `R` and `A` and
whether `R[A]` has non-zero zero-divisors. For some background on related
questions, see [Kaplansky's Conjectures](https://en.wikipedia.org/wiki/Kaplansky%27s_conjectures),
especially the *zero divisor conjecture*.
_Conjecture._
Let `K` be a field, and `G` a torsion-free group. The group ring `K[G]` does not contain
nontrivial zero divisors, that is, it is a domain.
In this file we show that if `R` satisfies `NoZeroDivisors` and `A` is a grading type satisfying
`UniqueProds A` (resp. `UniqueSums A`), then `MonoidAlgebra R A` (resp. `R[A]`)
also satisfies `NoZeroDivisors`.
Because of the instances to `UniqueProds/Sums`, we obtain a formalization of the well-known result
that if `R` is a field and `A` is a left-ordered group, then `R[A]` contains no non-zero
zero-divisors.
The actual assumptions on `R` are weaker.
## Main results
* `MonoidAlgebra.mul_apply_mul_eq_mul_of_uniqueMul` and
`AddMonoidAlgebra.mul_apply_add_eq_mul_of_uniqueAdd`
general sufficient results stating that certain monomials in a product have as coefficient a
product of coefficients of the factors.
* The instance showing that `Semiring R, NoZeroDivisors R, Mul A, UniqueProds A` imply
`NoZeroDivisors (MonoidAlgebra R A)`.
* The instance showing that `Semiring R, NoZeroDivisors R, Add A, UniqueSums A` imply
`NoZeroDivisors R[A]`.
TODO: move the rest of the docs to UniqueProds?
`NoZeroDivisors.of_left_ordered` shows that if `R` is a semiring with no non-zero
zero-divisors, `A` is a linearly ordered, add right cancel semigroup with strictly monotone
left addition, then `R[A]` has no non-zero zero-divisors.
* `NoZeroDivisors.of_right_ordered` shows that if `R` is a semiring with no non-zero
zero-divisors, `A` is a linearly ordered, add left cancel semigroup with strictly monotone
right addition, then `R[A]` has no non-zero zero-divisors.
The conditions on `A` imposed in `NoZeroDivisors.of_left_ordered` are sometimes referred to as
`left-ordered`.
The conditions on `A` imposed in `NoZeroDivisors.of_right_ordered` are sometimes referred to as
`right-ordered`.
These conditions are sufficient, but not necessary. As mentioned above, *Kaplansky's Conjecture*
asserts that `A` being torsion-free may be enough.
-/
open Finsupp
variable {R A : Type*} [Semiring R]
namespace MonoidAlgebra
/-- The coefficient of a monomial in a product `f * g` that can be reached in at most one way
as a product of monomials in the supports of `f` and `g` is a product. -/
theorem mul_apply_mul_eq_mul_of_uniqueMul [Mul A] {f g : MonoidAlgebra R A} {a0 b0 : A}
(h : UniqueMul f.support g.support a0 b0) :
(f * g) (a0 * b0) = f a0 * g b0 := by
classical
simp_rw [mul_apply, sum, ← Finset.sum_product']
refine (Finset.sum_eq_single (a0, b0) ?_ ?_).trans (if_pos rfl) <;> simp_rw [Finset.mem_product]
· refine fun ab hab hne => if_neg (fun he => hne <| Prod.ext ?_ ?_)
exacts [(h hab.1 hab.2 he).1, (h hab.1 hab.2 he).2]
· refine fun hnmem => ite_eq_right_iff.mpr (fun _ => ?_)
rcases not_and_or.mp hnmem with af | bg
· rw [not_mem_support_iff.mp af, zero_mul]
· rw [not_mem_support_iff.mp bg, mul_zero]
instance instNoZeroDivisorsOfUniqueProds [NoZeroDivisors R] [Mul A] [UniqueProds A] :
NoZeroDivisors (MonoidAlgebra R A) where
eq_zero_or_eq_zero_of_mul_eq_zero {a b} ab := by
contrapose! ab
obtain ⟨da, a0, db, b0, h⟩ := UniqueProds.uniqueMul_of_nonempty
(support_nonempty_iff.mpr ab.1) (support_nonempty_iff.mpr ab.2)
refine support_nonempty_iff.mp ⟨da * db, ?_⟩
rw [mem_support_iff] at a0 b0 ⊢
exact mul_apply_mul_eq_mul_of_uniqueMul h ▸ mul_ne_zero a0 b0
end MonoidAlgebra
namespace AddMonoidAlgebra
/-- The coefficient of a monomial in a product `f * g` that can be reached in at most one way
as a product of monomials in the supports of `f` and `g` is a product. -/
theorem mul_apply_add_eq_mul_of_uniqueAdd [Add A] {f g : R[A]} {a0 b0 : A}
(h : UniqueAdd f.support g.support a0 b0) :
(f * g) (a0 + b0) = f a0 * g b0 :=
MonoidAlgebra.mul_apply_mul_eq_mul_of_uniqueMul (A := Multiplicative A) h
instance [NoZeroDivisors R] [Add A] [UniqueSums A] : NoZeroDivisors R[A] :=
MonoidAlgebra.instNoZeroDivisorsOfUniqueProds (A := Multiplicative A)
end AddMonoidAlgebra
|
Algebra\MonoidAlgebra\Support.lean | /-
Copyright (c) 2022 Damiano Testa. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Damiano Testa
-/
import Mathlib.Algebra.MonoidAlgebra.Basic
import Mathlib.Data.Finset.Pointwise
/-!
# Lemmas about the support of a finitely supported function
-/
open scoped Pointwise
universe u₁ u₂ u₃
namespace MonoidAlgebra
open Finset Finsupp
variable {k : Type u₁} {G : Type u₂} [Semiring k]
theorem support_mul [Mul G] [DecidableEq G] (a b : MonoidAlgebra k G) :
(a * b).support ⊆ a.support * b.support := by
rw [MonoidAlgebra.mul_def]
exact support_sum.trans <| biUnion_subset.2 fun _x hx ↦
support_sum.trans <| biUnion_subset.2 fun _y hy ↦
support_single_subset.trans <| singleton_subset_iff.2 <| mem_image₂_of_mem hx hy
theorem support_single_mul_subset [DecidableEq G] [Mul G] (f : MonoidAlgebra k G) (r : k) (a : G) :
(single a r * f : MonoidAlgebra k G).support ⊆ Finset.image (a * ·) f.support :=
(support_mul _ _).trans <| (Finset.image₂_subset_right support_single_subset).trans <| by
rw [Finset.image₂_singleton_left]
theorem support_mul_single_subset [DecidableEq G] [Mul G] (f : MonoidAlgebra k G) (r : k) (a : G) :
(f * single a r).support ⊆ Finset.image (· * a) f.support :=
(support_mul _ _).trans <| (Finset.image₂_subset_left support_single_subset).trans <| by
rw [Finset.image₂_singleton_right]
theorem support_single_mul_eq_image [DecidableEq G] [Mul G] (f : MonoidAlgebra k G) {r : k}
(hr : ∀ y, r * y = 0 ↔ y = 0) {x : G} (lx : IsLeftRegular x) :
(single x r * f : MonoidAlgebra k G).support = Finset.image (x * ·) f.support := by
refine subset_antisymm (support_single_mul_subset f _ _) fun y hy => ?_
obtain ⟨y, yf, rfl⟩ : ∃ a : G, a ∈ f.support ∧ x * a = y := by
simpa only [Finset.mem_image, exists_prop] using hy
simp only [mul_apply, mem_support_iff.mp yf, hr, mem_support_iff, sum_single_index,
Finsupp.sum_ite_eq', Ne, not_false_iff, if_true, zero_mul, ite_self, sum_zero, lx.eq_iff]
theorem support_mul_single_eq_image [DecidableEq G] [Mul G] (f : MonoidAlgebra k G) {r : k}
(hr : ∀ y, y * r = 0 ↔ y = 0) {x : G} (rx : IsRightRegular x) :
(f * single x r).support = Finset.image (· * x) f.support := by
refine subset_antisymm (support_mul_single_subset f _ _) fun y hy => ?_
obtain ⟨y, yf, rfl⟩ : ∃ a : G, a ∈ f.support ∧ a * x = y := by
simpa only [Finset.mem_image, exists_prop] using hy
simp only [mul_apply, mem_support_iff.mp yf, hr, mem_support_iff, sum_single_index,
Finsupp.sum_ite_eq', Ne, not_false_iff, if_true, mul_zero, ite_self, sum_zero, rx.eq_iff]
theorem support_mul_single [Mul G] [IsRightCancelMul G] (f : MonoidAlgebra k G) (r : k)
(hr : ∀ y, y * r = 0 ↔ y = 0) (x : G) :
(f * single x r).support = f.support.map (mulRightEmbedding x) := by
classical
ext
simp only [support_mul_single_eq_image f hr (IsRightRegular.all x),
mem_image, mem_map, mulRightEmbedding_apply]
theorem support_single_mul [Mul G] [IsLeftCancelMul G] (f : MonoidAlgebra k G) (r : k)
(hr : ∀ y, r * y = 0 ↔ y = 0) (x : G) :
(single x r * f : MonoidAlgebra k G).support = f.support.map (mulLeftEmbedding x) := by
classical
ext
simp only [support_single_mul_eq_image f hr (IsLeftRegular.all x), mem_image,
mem_map, mulLeftEmbedding_apply]
lemma support_one_subset [One G] : (1 : MonoidAlgebra k G).support ⊆ 1 :=
Finsupp.support_single_subset
@[simp]
lemma support_one [One G] [NeZero (1 : k)] : (1 : MonoidAlgebra k G).support = 1 :=
Finsupp.support_single_ne_zero _ one_ne_zero
section Span
variable [MulOneClass G]
/-- An element of `MonoidAlgebra k G` is in the subalgebra generated by its support. -/
theorem mem_span_support (f : MonoidAlgebra k G) :
f ∈ Submodule.span k (of k G '' (f.support : Set G)) := by
erw [of, MonoidHom.coe_mk, ← supported_eq_span_single, Finsupp.mem_supported]
end Span
end MonoidAlgebra
namespace AddMonoidAlgebra
open Finset Finsupp MulOpposite
variable {k : Type u₁} {G : Type u₂} [Semiring k]
theorem support_mul [DecidableEq G] [Add G] (a b : k[G]) :
(a * b).support ⊆ a.support + b.support :=
@MonoidAlgebra.support_mul k (Multiplicative G) _ _ _ _ _
theorem support_mul_single [Add G] [IsRightCancelAdd G] (f : k[G]) (r : k)
(hr : ∀ y, y * r = 0 ↔ y = 0) (x : G) :
(f * single x r : k[G]).support = f.support.map (addRightEmbedding x) :=
MonoidAlgebra.support_mul_single (G := Multiplicative G) _ _ hr _
theorem support_single_mul [Add G] [IsLeftCancelAdd G] (f : k[G]) (r : k)
(hr : ∀ y, r * y = 0 ↔ y = 0) (x : G) :
(single x r * f : k[G]).support = f.support.map (addLeftEmbedding x) :=
MonoidAlgebra.support_single_mul (G := Multiplicative G) _ _ hr _
lemma support_one_subset [Zero G] : (1 : k[G]).support ⊆ 0 := Finsupp.support_single_subset
@[simp]
lemma support_one [Zero G] [NeZero (1 : k)] : (1 : k[G]).support = 0 :=
Finsupp.support_single_ne_zero _ one_ne_zero
section Span
/-- An element of `k[G]` is in the submodule generated by its support. -/
theorem mem_span_support [AddZeroClass G] (f : k[G]) :
f ∈ Submodule.span k (of k G '' (f.support : Set G)) := by
erw [of, MonoidHom.coe_mk, ← Finsupp.supported_eq_span_single, Finsupp.mem_supported]
/-- An element of `k[G]` is in the subalgebra generated by its support, using
unbundled inclusion. -/
theorem mem_span_support' (f : k[G]) :
f ∈ Submodule.span k (of' k G '' (f.support : Set G)) := by
delta of'
rw [← Finsupp.supported_eq_span_single, Finsupp.mem_supported]
end Span
end AddMonoidAlgebra
|
Algebra\MonoidAlgebra\ToDirectSum.lean | /-
Copyright (c) 2021 Eric Wieser. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Eric Wieser
-/
import Mathlib.Algebra.DirectSum.Algebra
import Mathlib.Algebra.MonoidAlgebra.Basic
import Mathlib.Data.Finsupp.ToDFinsupp
/-!
# Conversion between `AddMonoidAlgebra` and homogenous `DirectSum`
This module provides conversions between `AddMonoidAlgebra` and `DirectSum`.
The latter is essentially a dependent version of the former.
Note that since `direct_sum.has_mul` combines indices additively, there is no equivalent to
`MonoidAlgebra`.
## Main definitions
* `AddMonoidAlgebra.toDirectSum : AddMonoidAlgebra M ι → (⨁ i : ι, M)`
* `DirectSum.toAddMonoidAlgebra : (⨁ i : ι, M) → AddMonoidAlgebra M ι`
* Bundled equiv versions of the above:
* `addMonoidAlgebraEquivDirectSum : AddMonoidAlgebra M ι ≃ (⨁ i : ι, M)`
* `addMonoidAlgebraAddEquivDirectSum : AddMonoidAlgebra M ι ≃+ (⨁ i : ι, M)`
* `addMonoidAlgebraRingEquivDirectSum R : AddMonoidAlgebra M ι ≃+* (⨁ i : ι, M)`
* `addMonoidAlgebraAlgEquivDirectSum R : AddMonoidAlgebra A ι ≃ₐ[R] (⨁ i : ι, A)`
## Theorems
The defining feature of these operations is that they map `Finsupp.single` to
`DirectSum.of` and vice versa:
* `AddMonoidAlgebra.toDirectSum_single`
* `DirectSum.toAddMonoidAlgebra_of`
as well as preserving arithmetic operations.
For the bundled equivalences, we provide lemmas that they reduce to
`AddMonoidAlgebra.toDirectSum`:
* `addMonoidAlgebraAddEquivDirectSum_apply`
* `add_monoid_algebra_lequiv_direct_sum_apply`
* `addMonoidAlgebraAddEquivDirectSum_symm_apply`
* `add_monoid_algebra_lequiv_direct_sum_symm_apply`
## Implementation notes
This file largely just copies the API of `Mathlib/Data/Finsupp/ToDFinsupp.lean`, and reuses the
proofs. Recall that `AddMonoidAlgebra M ι` is defeq to `ι →₀ M` and `⨁ i : ι, M` is defeq to
`Π₀ i : ι, M`.
Note that there is no `AddMonoidAlgebra` equivalent to `Finsupp.single`, so many statements
still involve this definition.
-/
variable {ι : Type*} {R : Type*} {M : Type*} {A : Type*}
open DirectSum
/-! ### Basic definitions and lemmas -/
section Defs
/-- Interpret an `AddMonoidAlgebra` as a homogenous `DirectSum`. -/
def AddMonoidAlgebra.toDirectSum [Semiring M] (f : AddMonoidAlgebra M ι) : ⨁ _ : ι, M :=
Finsupp.toDFinsupp f
section
variable [DecidableEq ι] [Semiring M]
@[simp]
theorem AddMonoidAlgebra.toDirectSum_single (i : ι) (m : M) :
AddMonoidAlgebra.toDirectSum (Finsupp.single i m) = DirectSum.of _ i m :=
Finsupp.toDFinsupp_single i m
variable [∀ m : M, Decidable (m ≠ 0)]
/-- Interpret a homogenous `DirectSum` as an `AddMonoidAlgebra`. -/
def DirectSum.toAddMonoidAlgebra (f : ⨁ _ : ι, M) : AddMonoidAlgebra M ι :=
DFinsupp.toFinsupp f
@[simp]
theorem DirectSum.toAddMonoidAlgebra_of (i : ι) (m : M) :
(DirectSum.of _ i m : ⨁ _ : ι, M).toAddMonoidAlgebra = Finsupp.single i m :=
DFinsupp.toFinsupp_single i m
@[simp]
theorem AddMonoidAlgebra.toDirectSum_toAddMonoidAlgebra (f : AddMonoidAlgebra M ι) :
f.toDirectSum.toAddMonoidAlgebra = f :=
Finsupp.toDFinsupp_toFinsupp f
@[simp]
theorem DirectSum.toAddMonoidAlgebra_toDirectSum (f : ⨁ _ : ι, M) :
f.toAddMonoidAlgebra.toDirectSum = f :=
(DFinsupp.toFinsupp_toDFinsupp (show Π₀ _ : ι, M from f) : _)
end
end Defs
/-! ### Lemmas about arithmetic operations -/
section Lemmas
namespace AddMonoidAlgebra
@[simp]
theorem toDirectSum_zero [Semiring M] : (0 : AddMonoidAlgebra M ι).toDirectSum = 0 :=
Finsupp.toDFinsupp_zero
@[simp]
theorem toDirectSum_add [Semiring M] (f g : AddMonoidAlgebra M ι) :
(f + g).toDirectSum = f.toDirectSum + g.toDirectSum :=
Finsupp.toDFinsupp_add _ _
@[simp]
theorem toDirectSum_mul [DecidableEq ι] [AddMonoid ι] [Semiring M] (f g : AddMonoidAlgebra M ι) :
(f * g).toDirectSum = f.toDirectSum * g.toDirectSum := by
let to_hom : AddMonoidAlgebra M ι →+ ⨁ _ : ι, M :=
{ toFun := toDirectSum
map_zero' := toDirectSum_zero
map_add' := toDirectSum_add }
show to_hom (f * g) = to_hom f * to_hom g
let _ : NonUnitalNonAssocSemiring (ι →₀ M) := AddMonoidAlgebra.nonUnitalNonAssocSemiring
revert f g
rw [AddMonoidHom.map_mul_iff]
-- Porting note: does not find `addHom_ext'`, was `ext (xi xv yi yv) : 4`
refine Finsupp.addHom_ext' fun xi => AddMonoidHom.ext fun xv => ?_
refine Finsupp.addHom_ext' fun yi => AddMonoidHom.ext fun yv => ?_
dsimp only [AddMonoidHom.comp_apply, AddMonoidHom.compl₂_apply, AddMonoidHom.compr₂_apply,
AddMonoidHom.mul_apply, Finsupp.singleAddHom_apply]
-- This was not needed before leanprover/lean4#2644
erw [AddMonoidHom.compl₂_apply]
-- This was not needed before leanprover/lean4#2644
erw [AddMonoidHom.coe_mk]
simp only [AddMonoidHom.coe_mk, ZeroHom.coe_mk, toDirectSum_single]
-- This was not needed before leanprover/lean4#2644
dsimp
erw [AddMonoidAlgebra.single_mul_single, AddMonoidHom.coe_mk, ZeroHom.coe_mk,
AddMonoidAlgebra.toDirectSum_single]
simp only [AddMonoidHom.coe_comp, AddMonoidHom.coe_mul, AddMonoidHom.coe_mk, ZeroHom.coe_mk,
Function.comp_apply, toDirectSum_single, AddMonoidHom.id_apply, Finsupp.singleAddHom_apply,
AddMonoidHom.coe_mulLeft]
erw [DirectSum.of_mul_of, Mul.gMul_mul]
end AddMonoidAlgebra
namespace DirectSum
variable [DecidableEq ι]
@[simp]
theorem toAddMonoidAlgebra_zero [Semiring M] [∀ m : M, Decidable (m ≠ 0)] :
toAddMonoidAlgebra 0 = (0 : AddMonoidAlgebra M ι) :=
DFinsupp.toFinsupp_zero
@[simp]
theorem toAddMonoidAlgebra_add [Semiring M] [∀ m : M, Decidable (m ≠ 0)] (f g : ⨁ _ : ι, M) :
(f + g).toAddMonoidAlgebra = toAddMonoidAlgebra f + toAddMonoidAlgebra g :=
DFinsupp.toFinsupp_add _ _
@[simp]
theorem toAddMonoidAlgebra_mul [AddMonoid ι] [Semiring M]
[∀ m : M, Decidable (m ≠ 0)] (f g : ⨁ _ : ι, M) :
(f * g).toAddMonoidAlgebra = toAddMonoidAlgebra f * toAddMonoidAlgebra g := by
apply_fun AddMonoidAlgebra.toDirectSum
· simp
· apply Function.LeftInverse.injective
apply AddMonoidAlgebra.toDirectSum_toAddMonoidAlgebra
end DirectSum
end Lemmas
/-! ### Bundled `Equiv`s -/
section Equivs
/-- `AddMonoidAlgebra.toDirectSum` and `DirectSum.toAddMonoidAlgebra` together form an
equiv. -/
@[simps (config := .asFn)]
def addMonoidAlgebraEquivDirectSum [DecidableEq ι] [Semiring M] [∀ m : M, Decidable (m ≠ 0)] :
AddMonoidAlgebra M ι ≃ ⨁ _ : ι, M :=
{ finsuppEquivDFinsupp with
toFun := AddMonoidAlgebra.toDirectSum
invFun := DirectSum.toAddMonoidAlgebra }
/-- The additive version of `AddMonoidAlgebra.addMonoidAlgebraEquivDirectSum`. -/
@[simps (config := .asFn)]
def addMonoidAlgebraAddEquivDirectSum [DecidableEq ι] [Semiring M] [∀ m : M, Decidable (m ≠ 0)] :
AddMonoidAlgebra M ι ≃+ ⨁ _ : ι, M :=
{ addMonoidAlgebraEquivDirectSum with
toFun := AddMonoidAlgebra.toDirectSum
invFun := DirectSum.toAddMonoidAlgebra
map_add' := AddMonoidAlgebra.toDirectSum_add }
/-- The ring version of `AddMonoidAlgebra.addMonoidAlgebraEquivDirectSum`. -/
@[simps (config := .asFn)]
def addMonoidAlgebraRingEquivDirectSum [DecidableEq ι] [AddMonoid ι] [Semiring M]
[∀ m : M, Decidable (m ≠ 0)] : AddMonoidAlgebra M ι ≃+* ⨁ _ : ι, M :=
{ (addMonoidAlgebraAddEquivDirectSum : AddMonoidAlgebra M ι ≃+ ⨁ _ : ι, M) with
toFun := AddMonoidAlgebra.toDirectSum
invFun := DirectSum.toAddMonoidAlgebra
map_mul' := AddMonoidAlgebra.toDirectSum_mul }
/-- The algebra version of `AddMonoidAlgebra.addMonoidAlgebraEquivDirectSum`. -/
@[simps (config := .asFn)]
def addMonoidAlgebraAlgEquivDirectSum [DecidableEq ι] [AddMonoid ι] [CommSemiring R] [Semiring A]
[Algebra R A] [∀ m : A, Decidable (m ≠ 0)] : AddMonoidAlgebra A ι ≃ₐ[R] ⨁ _ : ι, A :=
{ (addMonoidAlgebraRingEquivDirectSum : AddMonoidAlgebra A ι ≃+* ⨁ _ : ι, A) with
toFun := AddMonoidAlgebra.toDirectSum
invFun := DirectSum.toAddMonoidAlgebra
commutes' := fun _r => AddMonoidAlgebra.toDirectSum_single _ _ }
end Equivs
|
Algebra\MvPolynomial\Basic.lean | /-
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
/-!
# 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`
* `aeval (g : σ → S₁) p` : evaluates the multivariate polynomial obtained from `p` by the change
of coefficient semiring corresponding to `g` (`a` stands for `Algebra`)
## Implementation notes
Recall that if `Y` has a zero, then `X →₀ Y` is the type of functions from `X` to `Y` with finite
support, i.e. such that only finitely many elements of `X` get sent to non-zero terms in `Y`.
The definition of `MvPolynomial σ R` is `(σ →₀ ℕ) →₀ R`; here `σ →₀ ℕ` denotes the space of all
monomials in the variables, and the function to `R` sends a monomial to its coefficient in
the polynomial being represented.
## Tags
polynomial, multivariate polynomial, multivariable polynomial
-/
noncomputable section
open Set Function Finsupp AddMonoidAlgebra
open scoped Pointwise
universe u v w x
variable {R : Type u} {S₁ : Type v} {S₂ : Type w} {S₃ : Type x}
/-- Multivariate polynomial, where `σ` is the index set of the variables and
`R` is the coefficient ring -/
def MvPolynomial (σ : Type*) (R : Type*) [CommSemiring R] :=
AddMonoidAlgebra R (σ →₀ ℕ)
namespace MvPolynomial
-- Porting note: because of `MvPolynomial.C` and `MvPolynomial.X` this linter throws
-- tons of warnings in this file, and it's easier to just disable them globally in the file
variable {σ : Type*} {a a' a₁ a₂ : R} {e : ℕ} {n m : σ} {s : σ →₀ ℕ}
section CommSemiring
section Instances
instance decidableEqMvPolynomial [CommSemiring R] [DecidableEq σ] [DecidableEq R] :
DecidableEq (MvPolynomial σ R) :=
Finsupp.instDecidableEq
instance commSemiring [CommSemiring R] : CommSemiring (MvPolynomial σ R) :=
AddMonoidAlgebra.commSemiring
instance inhabited [CommSemiring R] : Inhabited (MvPolynomial σ R) :=
⟨0⟩
instance distribuMulAction [Monoid R] [CommSemiring S₁] [DistribMulAction R S₁] :
DistribMulAction R (MvPolynomial σ S₁) :=
AddMonoidAlgebra.distribMulAction
instance smulZeroClass [CommSemiring S₁] [SMulZeroClass R S₁] :
SMulZeroClass R (MvPolynomial σ S₁) :=
AddMonoidAlgebra.smulZeroClass
instance faithfulSMul [CommSemiring S₁] [SMulZeroClass R S₁] [FaithfulSMul R S₁] :
FaithfulSMul R (MvPolynomial σ S₁) :=
AddMonoidAlgebra.faithfulSMul
instance module [Semiring R] [CommSemiring S₁] [Module R S₁] : Module R (MvPolynomial σ S₁) :=
AddMonoidAlgebra.module
instance isScalarTower [CommSemiring S₂] [SMul R S₁] [SMulZeroClass R S₂] [SMulZeroClass S₁ S₂]
[IsScalarTower R S₁ S₂] : IsScalarTower R S₁ (MvPolynomial σ S₂) :=
AddMonoidAlgebra.isScalarTower
instance smulCommClass [CommSemiring S₂] [SMulZeroClass R S₂] [SMulZeroClass S₁ S₂]
[SMulCommClass R S₁ S₂] : SMulCommClass R S₁ (MvPolynomial σ S₂) :=
AddMonoidAlgebra.smulCommClass
instance isCentralScalar [CommSemiring S₁] [SMulZeroClass R S₁] [SMulZeroClass Rᵐᵒᵖ S₁]
[IsCentralScalar R S₁] : IsCentralScalar R (MvPolynomial σ S₁) :=
AddMonoidAlgebra.isCentralScalar
instance algebra [CommSemiring R] [CommSemiring S₁] [Algebra R S₁] :
Algebra R (MvPolynomial σ S₁) :=
AddMonoidAlgebra.algebra
instance isScalarTower_right [CommSemiring S₁] [DistribSMul R S₁] [IsScalarTower R S₁ S₁] :
IsScalarTower R (MvPolynomial σ S₁) (MvPolynomial σ S₁) :=
AddMonoidAlgebra.isScalarTower_self _
instance smulCommClass_right [CommSemiring S₁] [DistribSMul R S₁] [SMulCommClass R S₁ S₁] :
SMulCommClass R (MvPolynomial σ S₁) (MvPolynomial σ S₁) :=
AddMonoidAlgebra.smulCommClass_self _
/-- If `R` is a subsingleton, then `MvPolynomial σ R` has a unique element -/
instance unique [CommSemiring R] [Subsingleton R] : Unique (MvPolynomial σ R) :=
AddMonoidAlgebra.unique
end Instances
variable [CommSemiring R] [CommSemiring S₁] {p q : MvPolynomial σ R}
/-- `monomial s a` is the monomial with coefficient `a` and exponents given by `s` -/
def monomial (s : σ →₀ ℕ) : R →ₗ[R] MvPolynomial σ R :=
lsingle s
theorem single_eq_monomial (s : σ →₀ ℕ) (a : R) : Finsupp.single s a = monomial s a :=
rfl
theorem mul_def : p * q = p.sum fun m a => q.sum fun n b => monomial (m + n) (a * b) :=
AddMonoidAlgebra.mul_def
/-- `C a` is the constant polynomial with value `a` -/
def C : R →+* MvPolynomial σ R :=
{ singleZeroRingHom with toFun := monomial 0 }
variable (R σ)
@[simp]
theorem algebraMap_eq : algebraMap R (MvPolynomial σ R) = C :=
rfl
variable {R σ}
/-- `X n` is the degree `1` monomial $X_n$. -/
def X (n : σ) : MvPolynomial σ R :=
monomial (Finsupp.single n 1) 1
theorem monomial_left_injective {r : R} (hr : r ≠ 0) :
Function.Injective fun s : σ →₀ ℕ => monomial s r :=
Finsupp.single_left_injective hr
@[simp]
theorem monomial_left_inj {s t : σ →₀ ℕ} {r : R} (hr : r ≠ 0) :
monomial s r = monomial t r ↔ s = t :=
Finsupp.single_left_inj hr
theorem C_apply : (C a : MvPolynomial σ R) = monomial 0 a :=
rfl
-- Porting note (#10618): `simp` can prove this
theorem C_0 : C 0 = (0 : MvPolynomial σ R) := map_zero _
-- Porting note (#10618): `simp` can prove this
theorem C_1 : C 1 = (1 : MvPolynomial σ R) :=
rfl
theorem C_mul_monomial : C a * monomial s a' = monomial s (a * a') := by
-- Porting note: this `show` feels like defeq abuse, but I can't find the appropriate lemmas
show AddMonoidAlgebra.single _ _ * AddMonoidAlgebra.single _ _ = AddMonoidAlgebra.single _ _
simp [C_apply, single_mul_single]
-- Porting note (#10618): `simp` can prove this
theorem C_add : (C (a + a') : MvPolynomial σ R) = C a + C a' :=
Finsupp.single_add _ _ _
-- Porting note (#10618): `simp` can prove this
theorem C_mul : (C (a * a') : MvPolynomial σ R) = C a * C a' :=
C_mul_monomial.symm
-- Porting note (#10618): `simp` can prove this
theorem C_pow (a : R) (n : ℕ) : (C (a ^ n) : MvPolynomial σ R) = C a ^ n :=
map_pow _ _ _
theorem C_injective (σ : Type*) (R : Type*) [CommSemiring R] :
Function.Injective (C : R → MvPolynomial σ R) :=
Finsupp.single_injective _
theorem C_surjective {R : Type*} [CommSemiring R] (σ : Type*) [IsEmpty σ] :
Function.Surjective (C : R → MvPolynomial σ R) := by
refine fun p => ⟨p.toFun 0, Finsupp.ext fun a => ?_⟩
simp only [C_apply, ← single_eq_monomial, (Finsupp.ext isEmptyElim (α := σ) : a = 0),
single_eq_same]
rfl
@[simp]
theorem C_inj {σ : Type*} (R : Type*) [CommSemiring R] (r s : R) :
(C r : MvPolynomial σ R) = C s ↔ r = s :=
(C_injective σ R).eq_iff
instance nontrivial_of_nontrivial (σ : Type*) (R : Type*) [CommSemiring R] [Nontrivial R] :
Nontrivial (MvPolynomial σ R) :=
inferInstanceAs (Nontrivial <| AddMonoidAlgebra R (σ →₀ ℕ))
instance infinite_of_infinite (σ : Type*) (R : Type*) [CommSemiring R] [Infinite R] :
Infinite (MvPolynomial σ R) :=
Infinite.of_injective C (C_injective _ _)
instance infinite_of_nonempty (σ : Type*) (R : Type*) [Nonempty σ] [CommSemiring R]
[Nontrivial R] : Infinite (MvPolynomial σ R) :=
Infinite.of_injective ((fun s : σ →₀ ℕ => monomial s 1) ∘ Finsupp.single (Classical.arbitrary σ))
<| (monomial_left_injective one_ne_zero).comp (Finsupp.single_injective _)
theorem C_eq_coe_nat (n : ℕ) : (C ↑n : MvPolynomial σ R) = n := by
induction n <;> simp [*]
theorem C_mul' : MvPolynomial.C a * p = a • p :=
(Algebra.smul_def a p).symm
theorem smul_eq_C_mul (p : MvPolynomial σ R) (a : R) : a • p = C a * p :=
C_mul'.symm
theorem C_eq_smul_one : (C a : MvPolynomial σ R) = a • (1 : MvPolynomial σ R) := by
rw [← C_mul', mul_one]
theorem smul_monomial {S₁ : Type*} [SMulZeroClass S₁ R] (r : S₁) :
r • monomial s a = monomial s (r • a) :=
Finsupp.smul_single _ _ _
theorem X_injective [Nontrivial R] : Function.Injective (X : σ → MvPolynomial σ R) :=
(monomial_left_injective one_ne_zero).comp (Finsupp.single_left_injective one_ne_zero)
@[simp]
theorem X_inj [Nontrivial R] (m n : σ) : X m = (X n : MvPolynomial σ R) ↔ m = n :=
X_injective.eq_iff
theorem monomial_pow : monomial s a ^ e = monomial (e • s) (a ^ e) :=
AddMonoidAlgebra.single_pow e
@[simp]
theorem monomial_mul {s s' : σ →₀ ℕ} {a b : R} :
monomial s a * monomial s' b = monomial (s + s') (a * b) :=
AddMonoidAlgebra.single_mul_single
variable (σ R)
/-- `fun s ↦ monomial s 1` as a homomorphism. -/
def monomialOneHom : Multiplicative (σ →₀ ℕ) →* MvPolynomial σ R :=
AddMonoidAlgebra.of _ _
variable {σ R}
@[simp]
theorem monomialOneHom_apply : monomialOneHom R σ s = (monomial s 1 : MvPolynomial σ R) :=
rfl
theorem X_pow_eq_monomial : X n ^ e = monomial (Finsupp.single n e) (1 : R) := by
simp [X, monomial_pow]
theorem monomial_add_single : monomial (s + Finsupp.single n e) a = monomial s a * X n ^ e := by
rw [X_pow_eq_monomial, monomial_mul, mul_one]
theorem monomial_single_add : monomial (Finsupp.single n e + s) a = X n ^ e * monomial s a := by
rw [X_pow_eq_monomial, monomial_mul, one_mul]
theorem C_mul_X_pow_eq_monomial {s : σ} {a : R} {n : ℕ} :
C a * X s ^ n = monomial (Finsupp.single s n) a := by
rw [← zero_add (Finsupp.single s n), monomial_add_single, C_apply]
theorem C_mul_X_eq_monomial {s : σ} {a : R} : C a * X s = monomial (Finsupp.single s 1) a := by
rw [← C_mul_X_pow_eq_monomial, pow_one]
-- Porting note (#10618): `simp` can prove this
theorem monomial_zero {s : σ →₀ ℕ} : monomial s (0 : R) = 0 :=
Finsupp.single_zero _
@[simp]
theorem monomial_zero' : (monomial (0 : σ →₀ ℕ) : R → MvPolynomial σ R) = C :=
rfl
@[simp]
theorem monomial_eq_zero {s : σ →₀ ℕ} {b : R} : monomial s b = 0 ↔ b = 0 :=
Finsupp.single_eq_zero
@[simp]
theorem sum_monomial_eq {A : Type*} [AddCommMonoid A] {u : σ →₀ ℕ} {r : R} {b : (σ →₀ ℕ) → R → A}
(w : b u 0 = 0) : sum (monomial u r) b = b u r :=
Finsupp.sum_single_index w
@[simp]
theorem sum_C {A : Type*} [AddCommMonoid A] {b : (σ →₀ ℕ) → R → A} (w : b 0 0 = 0) :
sum (C a) b = b 0 a :=
sum_monomial_eq w
theorem monomial_sum_one {α : Type*} (s : Finset α) (f : α → σ →₀ ℕ) :
(monomial (∑ i ∈ s, f i) 1 : MvPolynomial σ R) = ∏ i ∈ s, monomial (f i) 1 :=
map_prod (monomialOneHom R σ) (fun i => Multiplicative.ofAdd (f i)) s
theorem monomial_sum_index {α : Type*} (s : Finset α) (f : α → σ →₀ ℕ) (a : R) :
monomial (∑ i ∈ s, f i) a = C a * ∏ i ∈ s, monomial (f i) 1 := by
rw [← monomial_sum_one, C_mul', ← (monomial _).map_smul, smul_eq_mul, mul_one]
theorem monomial_finsupp_sum_index {α β : Type*} [Zero β] (f : α →₀ β) (g : α → β → σ →₀ ℕ)
(a : R) : monomial (f.sum g) a = C a * f.prod fun a b => monomial (g a b) 1 :=
monomial_sum_index _ _ _
theorem monomial_eq_monomial_iff {α : Type*} (a₁ a₂ : α →₀ ℕ) (b₁ b₂ : R) :
monomial a₁ b₁ = monomial a₂ b₂ ↔ a₁ = a₂ ∧ b₁ = b₂ ∨ b₁ = 0 ∧ b₂ = 0 :=
Finsupp.single_eq_single_iff _ _ _ _
theorem monomial_eq : monomial s a = C a * (s.prod fun n e => X n ^ e : MvPolynomial σ R) := by
simp only [X_pow_eq_monomial, ← monomial_finsupp_sum_index, Finsupp.sum_single]
@[simp]
lemma prod_X_pow_eq_monomial : ∏ x ∈ s.support, X x ^ s x = monomial s (1 : R) := by
simp only [monomial_eq, map_one, one_mul, Finsupp.prod]
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]
/-- 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
/-- 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
/-- 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
/-- 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
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 _
/-- See note [partially-applied ext lemmas]. -/
@[ext 1100]
theorem ringHom_ext' {A : Type*} [Semiring A] {f g : MvPolynomial σ R →+* A}
(hC : f.comp C = g.comp C) (hX : ∀ i, f (X i) = g (X i)) : f = g :=
ringHom_ext (RingHom.ext_iff.1 hC) hX
theorem hom_eq_hom [Semiring S₂] (f g : MvPolynomial σ R →+* S₂) (hC : f.comp C = g.comp C)
(hX : ∀ n : σ, f (X n) = g (X n)) (p : MvPolynomial σ R) : f p = g p :=
RingHom.congr_fun (ringHom_ext' hC hX) p
theorem is_id (f : MvPolynomial σ R →+* MvPolynomial σ R) (hC : f.comp C = C)
(hX : ∀ n : σ, f (X n) = X n) (p : MvPolynomial σ R) : f p = p :=
hom_eq_hom f (RingHom.id _) hC hX p
@[ext 1100]
theorem algHom_ext' {A B : Type*} [CommSemiring A] [CommSemiring B] [Algebra R A] [Algebra R B]
{f g : MvPolynomial σ A →ₐ[R] B}
(h₁ :
f.comp (IsScalarTower.toAlgHom R A (MvPolynomial σ A)) =
g.comp (IsScalarTower.toAlgHom R A (MvPolynomial σ A)))
(h₂ : ∀ i, f (X i) = g (X i)) : f = g :=
AlgHom.coe_ringHom_injective (MvPolynomial.ringHom_ext' (congr_arg AlgHom.toRingHom h₁) h₂)
@[ext 1200]
theorem algHom_ext {A : Type*} [Semiring A] [Algebra R A] {f g : MvPolynomial σ R →ₐ[R] A}
(hf : ∀ i : σ, f (X i) = g (X i)) : f = g :=
AddMonoidAlgebra.algHom_ext' (mulHom_ext' fun X : σ => MonoidHom.ext_mnat (hf X))
@[simp]
theorem algHom_C {A : Type*} [Semiring A] [Algebra R A] (f : MvPolynomial σ R →ₐ[R] A) (r : R) :
f (C r) = algebraMap R A r :=
f.commutes r
@[simp]
theorem adjoin_range_X : Algebra.adjoin R (range (X : σ → MvPolynomial σ R)) = ⊤ := by
set S := Algebra.adjoin R (range (X : σ → MvPolynomial σ R))
refine top_unique fun p hp => ?_; clear hp
induction p using MvPolynomial.induction_on with
| 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 _)
@[ext]
theorem linearMap_ext {M : Type*} [AddCommMonoid M] [Module R M] {f g : MvPolynomial σ R →ₗ[R] M}
(h : ∀ s, f ∘ₗ monomial s = g ∘ₗ monomial s) : f = g :=
Finsupp.lhom_ext' h
section Support
/-- The finite set of all `m : σ →₀ ℕ` such that `X^m` has a non-zero coefficient. -/
def support (p : MvPolynomial σ R) : Finset (σ →₀ ℕ) :=
Finsupp.support p
theorem finsupp_support_eq_support (p : MvPolynomial σ R) : Finsupp.support p = p.support :=
rfl
theorem support_monomial [h : Decidable (a = 0)] :
(monomial s a).support = if a = 0 then ∅ else {s} := by
rw [← Subsingleton.elim (Classical.decEq R a 0) h]
rfl
-- 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
theorem support_monomial_subset : (monomial s a).support ⊆ {s} :=
support_single_subset
theorem support_add [DecidableEq σ] : (p + q).support ⊆ p.support ∪ q.support :=
Finsupp.support_add
theorem support_X [Nontrivial R] : (X n : MvPolynomial σ R).support = {Finsupp.single n 1} := by
classical rw [X, support_monomial, if_neg]; exact one_ne_zero
theorem support_X_pow [Nontrivial R] (s : σ) (n : ℕ) :
(X s ^ n : MvPolynomial σ R).support = {Finsupp.single s n} := by
classical
rw [X_pow_eq_monomial, support_monomial, if_neg (one_ne_zero' R)]
@[simp]
theorem support_zero : (0 : MvPolynomial σ R).support = ∅ :=
rfl
theorem support_smul {S₁ : Type*} [SMulZeroClass S₁ R] {a : S₁} {f : MvPolynomial σ R} :
(a • f).support ⊆ f.support :=
Finsupp.support_smul
theorem support_sum {α : Type*} [DecidableEq σ] {s : Finset α} {f : α → MvPolynomial σ R} :
(∑ x ∈ s, f x).support ⊆ s.biUnion fun x => (f x).support :=
Finsupp.support_finset_sum
end Support
section Coeff
/-- The coefficient of the monomial `m` in the multi-variable polynomial `p`. -/
def coeff (m : σ →₀ ℕ) (p : MvPolynomial σ R) : R :=
@DFunLike.coe ((σ →₀ ℕ) →₀ R) _ _ _ p m
-- Porting note: I changed this from `@CoeFun.coe _ _ (MonoidAlgebra.coeFun _ _) p m` because
-- I think it should work better syntactically. They are defeq.
@[simp]
theorem mem_support_iff {p : MvPolynomial σ R} {m : σ →₀ ℕ} : m ∈ p.support ↔ p.coeff m ≠ 0 := by
simp [support, coeff]
theorem not_mem_support_iff {p : MvPolynomial σ R} {m : σ →₀ ℕ} : m ∉ p.support ↔ p.coeff m = 0 :=
by simp
theorem sum_def {A} [AddCommMonoid A] {p : MvPolynomial σ R} {b : (σ →₀ ℕ) → R → A} :
p.sum b = ∑ m ∈ p.support, b m (p.coeff m) := by simp [support, Finsupp.sum, coeff]
theorem support_mul [DecidableEq σ] (p q : MvPolynomial σ R) :
(p * q).support ⊆ p.support + q.support :=
AddMonoidAlgebra.support_mul p q
@[ext]
theorem ext (p q : MvPolynomial σ R) : (∀ m, coeff m p = coeff m q) → p = q :=
Finsupp.ext
@[simp]
theorem coeff_add (m : σ →₀ ℕ) (p q : MvPolynomial σ R) : coeff m (p + q) = coeff m p + coeff m q :=
add_apply p q m
@[simp]
theorem coeff_smul {S₁ : Type*} [SMulZeroClass S₁ R] (m : σ →₀ ℕ) (C : S₁) (p : MvPolynomial σ R) :
coeff m (C • p) = C • coeff m p :=
smul_apply C p m
@[simp]
theorem coeff_zero (m : σ →₀ ℕ) : coeff m (0 : MvPolynomial σ R) = 0 :=
rfl
@[simp]
theorem coeff_zero_X (i : σ) : coeff 0 (X i : MvPolynomial σ R) = 0 :=
single_eq_of_ne fun h => by cases Finsupp.single_eq_zero.1 h
/-- `MvPolynomial.coeff m` but promoted to an `AddMonoidHom`. -/
@[simps]
def coeffAddMonoidHom (m : σ →₀ ℕ) : MvPolynomial σ R →+ R where
toFun := coeff m
map_zero' := coeff_zero m
map_add' := coeff_add m
variable (R) in
/-- `MvPolynomial.coeff m` but promoted to a `LinearMap`. -/
@[simps]
def lcoeff (m : σ →₀ ℕ) : MvPolynomial σ R →ₗ[R] R where
toFun := coeff m
map_add' := coeff_add m
map_smul' := coeff_smul m
theorem coeff_sum {X : Type*} (s : Finset X) (f : X → MvPolynomial σ R) (m : σ →₀ ℕ) :
coeff m (∑ x ∈ s, f x) = ∑ x ∈ s, coeff m (f x) :=
map_sum (@coeffAddMonoidHom R σ _ _) _ s
theorem monic_monomial_eq (m) :
monomial m (1 : R) = (m.prod fun n e => X n ^ e : MvPolynomial σ R) := by simp [monomial_eq]
@[simp]
theorem coeff_monomial [DecidableEq σ] (m n) (a) :
coeff m (monomial n a : MvPolynomial σ R) = if n = m then a else 0 :=
Finsupp.single_apply
@[simp]
theorem coeff_C [DecidableEq σ] (m) (a) :
coeff m (C a : MvPolynomial σ R) = if 0 = m then a else 0 :=
Finsupp.single_apply
lemma eq_C_of_isEmpty [IsEmpty σ] (p : MvPolynomial σ R) :
p = C (p.coeff 0) := by
obtain ⟨x, rfl⟩ := C_surjective σ p
simp
theorem coeff_one [DecidableEq σ] (m) : coeff m (1 : MvPolynomial σ R) = if 0 = m then 1 else 0 :=
coeff_C m 1
@[simp]
theorem coeff_zero_C (a) : coeff 0 (C a : MvPolynomial σ R) = a :=
single_eq_same
@[simp]
theorem coeff_zero_one : coeff 0 (1 : MvPolynomial σ R) = 1 :=
coeff_zero_C 1
theorem coeff_X_pow [DecidableEq σ] (i : σ) (m) (k : ℕ) :
coeff m (X i ^ k : MvPolynomial σ R) = if Finsupp.single i k = m then 1 else 0 := by
have := coeff_monomial m (Finsupp.single i k) (1 : R)
rwa [@monomial_eq _ _ (1 : R) (Finsupp.single i k) _, C_1, one_mul, Finsupp.prod_single_index]
at this
exact pow_zero _
theorem coeff_X' [DecidableEq σ] (i : σ) (m) :
coeff m (X i : MvPolynomial σ R) = if Finsupp.single i 1 = m then 1 else 0 := by
rw [← coeff_X_pow, pow_one]
@[simp]
theorem coeff_X (i : σ) : coeff (Finsupp.single i 1) (X i : MvPolynomial σ R) = 1 := by
classical rw [coeff_X', if_pos rfl]
@[simp]
theorem coeff_C_mul (m) (a : R) (p : MvPolynomial σ R) : coeff m (C a * p) = a * coeff m p := by
classical
rw [mul_def, sum_C]
· simp (config := { contextual := true }) [sum_def, coeff_sum]
simp
theorem coeff_mul [DecidableEq σ] (p q : MvPolynomial σ R) (n : σ →₀ ℕ) :
coeff n (p * q) = ∑ x ∈ Finset.antidiagonal n, coeff x.1 p * coeff x.2 q :=
AddMonoidAlgebra.mul_apply_antidiagonal p q _ _ Finset.mem_antidiagonal
@[simp]
theorem coeff_mul_monomial (m) (s : σ →₀ ℕ) (r : R) (p : MvPolynomial σ R) :
coeff (m + s) (p * monomial s r) = coeff m p * r :=
AddMonoidAlgebra.mul_single_apply_aux p _ _ _ _ fun _a => add_left_inj _
@[simp]
theorem coeff_monomial_mul (m) (s : σ →₀ ℕ) (r : R) (p : MvPolynomial σ R) :
coeff (s + m) (monomial s r * p) = r * coeff m p :=
AddMonoidAlgebra.single_mul_apply_aux p _ _ _ _ fun _a => add_right_inj _
@[simp]
theorem coeff_mul_X (m) (s : σ) (p : MvPolynomial σ R) :
coeff (m + Finsupp.single s 1) (p * X s) = coeff m p :=
(coeff_mul_monomial _ _ _ _).trans (mul_one _)
@[simp]
theorem coeff_X_mul (m) (s : σ) (p : MvPolynomial σ R) :
coeff (Finsupp.single s 1 + m) (X s * p) = coeff m p :=
(coeff_monomial_mul _ _ _ _).trans (one_mul _)
lemma coeff_single_X_pow [DecidableEq σ] (s s' : σ) (n n' : ℕ) :
(X (R := R) s ^ n).coeff (Finsupp.single s' n')
= if s = s' ∧ n = n' ∨ n = 0 ∧ n' = 0 then 1 else 0 := by
simp only [coeff_X_pow, single_eq_single_iff]
@[simp]
lemma coeff_single_X [DecidableEq σ] (s s' : σ) (n : ℕ) :
(X s).coeff (R := R) (Finsupp.single s' n) = if n = 1 ∧ s = s' then 1 else 0 := by
simpa [eq_comm, and_comm] using coeff_single_X_pow s s' 1 n
@[simp]
theorem support_mul_X (s : σ) (p : MvPolynomial σ R) :
(p * X s).support = p.support.map (addRightEmbedding (Finsupp.single s 1)) :=
AddMonoidAlgebra.support_mul_single p _ (by simp) _
@[simp]
theorem support_X_mul (s : σ) (p : MvPolynomial σ R) :
(X s * p).support = p.support.map (addLeftEmbedding (Finsupp.single s 1)) :=
AddMonoidAlgebra.support_single_mul p _ (by simp) _
@[simp]
theorem support_smul_eq {S₁ : Type*} [Semiring S₁] [Module S₁ R] [NoZeroSMulDivisors S₁ R] {a : S₁}
(h : a ≠ 0) (p : MvPolynomial σ R) : (a • p).support = p.support :=
Finsupp.support_smul_eq h
theorem support_sdiff_support_subset_support_add [DecidableEq σ] (p q : MvPolynomial σ R) :
p.support \ q.support ⊆ (p + q).support := by
intro m hm
simp only [Classical.not_not, mem_support_iff, Finset.mem_sdiff, Ne] at hm
simp [hm.2, hm.1]
open scoped symmDiff in
theorem support_symmDiff_support_subset_support_add [DecidableEq σ] (p q : MvPolynomial σ R) :
p.support ∆ q.support ⊆ (p + q).support := by
rw [symmDiff_def, Finset.sup_eq_union]
apply Finset.union_subset
· exact support_sdiff_support_subset_support_add p q
· rw [add_comm]
exact support_sdiff_support_subset_support_add q p
theorem coeff_mul_monomial' (m) (s : σ →₀ ℕ) (r : R) (p : MvPolynomial σ R) :
coeff m (p * monomial s r) = if s ≤ m then coeff (m - s) p * r else 0 := by
classical
split_ifs with h
· conv_rhs => rw [← coeff_mul_monomial _ s]
congr with t
rw [tsub_add_cancel_of_le h]
· contrapose! h
rw [← mem_support_iff] at h
obtain ⟨j, -, rfl⟩ : ∃ j ∈ support p, j + s = m := by
simpa [Finset.add_singleton]
using Finset.add_subset_add_left support_monomial_subset <| support_mul _ _ h
exact le_add_left le_rfl
theorem coeff_monomial_mul' (m) (s : σ →₀ ℕ) (r : R) (p : MvPolynomial σ R) :
coeff m (monomial s r * p) = if s ≤ m then r * coeff (m - s) p else 0 := by
-- note that if we allow `R` to be non-commutative we will have to duplicate the proof above.
rw [mul_comm, mul_comm r]
exact coeff_mul_monomial' _ _ _ _
theorem coeff_mul_X' [DecidableEq σ] (m) (s : σ) (p : MvPolynomial σ R) :
coeff m (p * X s) = if s ∈ m.support then coeff (m - Finsupp.single s 1) p else 0 := by
refine (coeff_mul_monomial' _ _ _ _).trans ?_
simp_rw [Finsupp.single_le_iff, Finsupp.mem_support_iff, Nat.succ_le_iff, pos_iff_ne_zero,
mul_one]
theorem coeff_X_mul' [DecidableEq σ] (m) (s : σ) (p : MvPolynomial σ R) :
coeff m (X s * p) = if s ∈ m.support then coeff (m - Finsupp.single s 1) p else 0 := by
refine (coeff_monomial_mul' _ _ _ _).trans ?_
simp_rw [Finsupp.single_le_iff, Finsupp.mem_support_iff, Nat.succ_le_iff, pos_iff_ne_zero,
one_mul]
theorem eq_zero_iff {p : MvPolynomial σ R} : p = 0 ↔ ∀ d, coeff d p = 0 := by
rw [MvPolynomial.ext_iff]
simp only [coeff_zero]
theorem ne_zero_iff {p : MvPolynomial σ R} : p ≠ 0 ↔ ∃ d, coeff d p ≠ 0 := by
rw [Ne, eq_zero_iff]
push_neg
rfl
@[simp]
theorem X_ne_zero [Nontrivial R] (s : σ) :
X (R := R) s ≠ 0 := by
rw [ne_zero_iff]
use Finsupp.single s 1
simp only [coeff_X, ne_eq, one_ne_zero, not_false_eq_true]
@[simp]
theorem support_eq_empty {p : MvPolynomial σ R} : p.support = ∅ ↔ p = 0 :=
Finsupp.support_eq_empty
@[simp]
lemma support_nonempty {p : MvPolynomial σ R} : p.support.Nonempty ↔ p ≠ 0 := by
rw [Finset.nonempty_iff_ne_empty, ne_eq, support_eq_empty]
theorem exists_coeff_ne_zero {p : MvPolynomial σ R} (h : p ≠ 0) : ∃ d, coeff d p ≠ 0 :=
ne_zero_iff.mp h
theorem C_dvd_iff_dvd_coeff (r : R) (φ : MvPolynomial σ R) : C r ∣ φ ↔ ∀ i, r ∣ φ.coeff i := by
constructor
· rintro ⟨φ, rfl⟩ c
rw [coeff_C_mul]
apply dvd_mul_right
· intro h
choose C hc using h
classical
let c' : (σ →₀ ℕ) → R := fun i => if i ∈ φ.support then C i else 0
let ψ : MvPolynomial σ R := ∑ i ∈ φ.support, monomial i (c' i)
use ψ
apply MvPolynomial.ext
intro i
simp only [ψ, c', coeff_C_mul, coeff_sum, coeff_monomial, Finset.sum_ite_eq']
split_ifs with hi
· rw [hc]
· rw [not_mem_support_iff] at hi
rwa [mul_zero]
@[simp] lemma isRegular_X : IsRegular (X n : MvPolynomial σ R) := by
suffices IsLeftRegular (X n : MvPolynomial σ R) from
⟨this, this.right_of_commute <| Commute.all _⟩
intro P Q (hPQ : (X n) * P = (X n) * Q)
ext i
rw [← coeff_X_mul i n P, hPQ, coeff_X_mul i n Q]
@[simp] lemma isRegular_X_pow (k : ℕ) : IsRegular (X n ^ k : MvPolynomial σ R) := isRegular_X.pow k
@[simp] lemma isRegular_prod_X (s : Finset σ) :
IsRegular (∏ n ∈ s, X n : MvPolynomial σ R) :=
IsRegular.prod fun _ _ ↦ isRegular_X
/-- The finset of nonzero coefficients of a multivariate polynomial. -/
def coeffs (p : MvPolynomial σ R) : Finset R :=
letI := Classical.decEq R
Finset.image p.coeff p.support
@[simp]
lemma coeffs_zero : coeffs (0 : MvPolynomial σ R) = ∅ :=
rfl
lemma coeffs_one : coeffs (1 : MvPolynomial σ R) ⊆ {1} := by
classical
rw [coeffs, Finset.image_subset_iff]
simp_all [coeff_one]
@[nontriviality]
lemma coeffs_eq_empty_of_subsingleton [Subsingleton R] (p : MvPolynomial σ R) : p.coeffs = ∅ := by
simpa [coeffs] using Subsingleton.eq_zero p
@[simp]
lemma coeffs_one_of_nontrivial [Nontrivial R] : coeffs (1 : MvPolynomial σ R) = {1} := by
apply Finset.Subset.antisymm coeffs_one
simp only [coeffs, Finset.singleton_subset_iff, Finset.mem_image]
exact ⟨0, by simp⟩
lemma mem_coeffs_iff {p : MvPolynomial σ R} {c : R} :
c ∈ p.coeffs ↔ ∃ n ∈ p.support, c = p.coeff n := by
simp [coeffs, eq_comm, (Finset.mem_image)]
lemma coeff_mem_coeffs {p : MvPolynomial σ R} (m : σ →₀ ℕ)
(h : p.coeff m ≠ 0) : p.coeff m ∈ p.coeffs :=
letI := Classical.decEq R
Finset.mem_image_of_mem p.coeff (mem_support_iff.mpr h)
lemma zero_not_mem_coeffs (p : MvPolynomial σ R) : 0 ∉ p.coeffs := by
intro hz
obtain ⟨n, hnsupp, hn⟩ := mem_coeffs_iff.mp hz
exact (mem_support_iff.mp hnsupp) hn.symm
end Coeff
section ConstantCoeff
/-- `constantCoeff p` returns the constant term of the polynomial `p`, defined as `coeff 0 p`.
This is a ring homomorphism.
-/
def constantCoeff : MvPolynomial σ R →+* R where
toFun := coeff 0
map_one' := by simp [AddMonoidAlgebra.one_def]
map_mul' := by classical simp [coeff_mul, Finsupp.support_single_ne_zero]
map_zero' := coeff_zero _
map_add' := coeff_add _
theorem constantCoeff_eq : (constantCoeff : MvPolynomial σ R → R) = coeff 0 :=
rfl
variable (σ)
@[simp]
theorem constantCoeff_C (r : R) : constantCoeff (C r : MvPolynomial σ R) = r := by
classical simp [constantCoeff_eq]
variable {σ}
variable (R)
@[simp]
theorem constantCoeff_X (i : σ) : constantCoeff (X i : MvPolynomial σ R) = 0 := by
simp [constantCoeff_eq]
variable {R}
/- porting note: increased priority because otherwise `simp` time outs when trying to simplify
the left-hand side. `simpNF` linter indicated this and it was verified. -/
@[simp 1001]
theorem constantCoeff_smul {R : Type*} [SMulZeroClass R S₁] (a : R) (f : MvPolynomial σ S₁) :
constantCoeff (a • f) = a • constantCoeff f :=
rfl
theorem constantCoeff_monomial [DecidableEq σ] (d : σ →₀ ℕ) (r : R) :
constantCoeff (monomial d r) = if d = 0 then r else 0 := by
rw [constantCoeff_eq, coeff_monomial]
variable (σ R)
@[simp]
theorem constantCoeff_comp_C : constantCoeff.comp (C : R →+* MvPolynomial σ R) = RingHom.id R := by
ext x
exact constantCoeff_C σ x
theorem constantCoeff_comp_algebraMap :
constantCoeff.comp (algebraMap R (MvPolynomial σ R)) = RingHom.id R :=
constantCoeff_comp_C _ _
end ConstantCoeff
section AsSum
@[simp]
theorem support_sum_monomial_coeff (p : MvPolynomial σ R) :
(∑ v ∈ p.support, monomial v (coeff v p)) = p :=
Finsupp.sum_single p
theorem as_sum (p : MvPolynomial σ R) : p = ∑ v ∈ p.support, monomial v (coeff v p) :=
(support_sum_monomial_coeff p).symm
end AsSum
section Eval₂
variable (f : R →+* S₁) (g : σ → S₁)
/-- Evaluate a polynomial `p` given a valuation `g` of all the variables
and a ring hom `f` from the scalar ring to the target -/
def eval₂ (p : MvPolynomial σ R) : S₁ :=
p.sum fun s a => f a * s.prod fun n e => g n ^ e
theorem eval₂_eq (g : R →+* S₁) (X : σ → S₁) (f : MvPolynomial σ R) :
f.eval₂ g X = ∑ d ∈ f.support, g (f.coeff d) * ∏ i ∈ d.support, X i ^ d i :=
rfl
theorem eval₂_eq' [Fintype σ] (g : R →+* S₁) (X : σ → S₁) (f : MvPolynomial σ R) :
f.eval₂ g X = ∑ d ∈ f.support, g (f.coeff d) * ∏ i, X i ^ d i := by
simp only [eval₂_eq, ← Finsupp.prod_pow]
rfl
@[simp]
theorem eval₂_zero : (0 : MvPolynomial σ R).eval₂ f g = 0 :=
Finsupp.sum_zero_index
section
@[simp]
theorem eval₂_add : (p + q).eval₂ f g = p.eval₂ f g + q.eval₂ f g := by
classical exact Finsupp.sum_add_index (by simp [f.map_zero]) (by simp [add_mul, f.map_add])
@[simp]
theorem eval₂_monomial : (monomial s a).eval₂ f g = f a * s.prod fun n e => g n ^ e :=
Finsupp.sum_single_index (by simp [f.map_zero])
@[simp]
theorem eval₂_C (a) : (C a).eval₂ f g = f a := by
rw [C_apply, eval₂_monomial, prod_zero_index, mul_one]
@[simp]
theorem eval₂_one : (1 : MvPolynomial σ R).eval₂ f g = 1 :=
(eval₂_C _ _ _).trans f.map_one
@[simp]
theorem eval₂_X (n) : (X n).eval₂ f g = g n := by
simp [eval₂_monomial, f.map_one, X, prod_single_index, pow_one]
theorem eval₂_mul_monomial :
∀ {s a}, (p * monomial s a).eval₂ f g = p.eval₂ f g * f a * s.prod fun n e => g n ^ e := by
classical
apply MvPolynomial.induction_on p
· intro a' s a
simp [C_mul_monomial, eval₂_monomial, f.map_mul]
· intro p q ih_p ih_q
simp [add_mul, eval₂_add, ih_p, ih_q]
· intro p n ih s a
exact
calc (p * X n * monomial s a).eval₂ f g
_ = (p * monomial (Finsupp.single n 1 + s) a).eval₂ f g := by
rw [monomial_single_add, pow_one, mul_assoc]
_ = (p * monomial (Finsupp.single n 1) 1).eval₂ f g * f a * s.prod fun n e => g n ^ e := by
simp [ih, prod_single_index, prod_add_index, pow_one, pow_add, mul_assoc, mul_left_comm,
f.map_one]
theorem eval₂_mul_C : (p * C a).eval₂ f g = p.eval₂ f g * f a :=
(eval₂_mul_monomial _ _).trans <| by simp
@[simp]
theorem eval₂_mul : ∀ {p}, (p * q).eval₂ f g = p.eval₂ f g * q.eval₂ f g := by
apply MvPolynomial.induction_on q
· simp [eval₂_C, eval₂_mul_C]
· simp (config := { contextual := true }) [mul_add, eval₂_add]
· simp (config := { contextual := true }) [X, eval₂_monomial, eval₂_mul_monomial, ← mul_assoc]
@[simp]
theorem eval₂_pow {p : MvPolynomial σ R} : ∀ {n : ℕ}, (p ^ n).eval₂ f g = p.eval₂ f g ^ n
| 0 => by
rw [pow_zero, pow_zero]
exact eval₂_one _ _
| n + 1 => by rw [pow_add, pow_one, pow_add, pow_one, eval₂_mul, eval₂_pow]
/-- `MvPolynomial.eval₂` as a `RingHom`. -/
def eval₂Hom (f : R →+* S₁) (g : σ → S₁) : MvPolynomial σ R →+* S₁ where
toFun := eval₂ f g
map_one' := eval₂_one _ _
map_mul' _ _ := eval₂_mul _ _
map_zero' := eval₂_zero f g
map_add' _ _ := eval₂_add _ _
@[simp]
theorem coe_eval₂Hom (f : R →+* S₁) (g : σ → S₁) : ⇑(eval₂Hom f g) = eval₂ f g :=
rfl
theorem eval₂Hom_congr {f₁ f₂ : R →+* S₁} {g₁ g₂ : σ → S₁} {p₁ p₂ : MvPolynomial σ R} :
f₁ = f₂ → g₁ = g₂ → p₁ = p₂ → eval₂Hom f₁ g₁ p₁ = eval₂Hom f₂ g₂ p₂ := by
rintro rfl rfl rfl; rfl
end
@[simp]
theorem eval₂Hom_C (f : R →+* S₁) (g : σ → S₁) (r : R) : eval₂Hom f g (C r) = f r :=
eval₂_C f g r
@[simp]
theorem eval₂Hom_X' (f : R →+* S₁) (g : σ → S₁) (i : σ) : eval₂Hom f g (X i) = g i :=
eval₂_X f g i
@[simp]
theorem comp_eval₂Hom [CommSemiring S₂] (f : R →+* S₁) (g : σ → S₁) (φ : S₁ →+* S₂) :
φ.comp (eval₂Hom f g) = eval₂Hom (φ.comp f) fun i => φ (g i) := by
apply MvPolynomial.ringHom_ext
· intro r
rw [RingHom.comp_apply, eval₂Hom_C, eval₂Hom_C, RingHom.comp_apply]
· intro i
rw [RingHom.comp_apply, eval₂Hom_X', eval₂Hom_X']
theorem map_eval₂Hom [CommSemiring S₂] (f : R →+* S₁) (g : σ → S₁) (φ : S₁ →+* S₂)
(p : MvPolynomial σ R) : φ (eval₂Hom f g p) = eval₂Hom (φ.comp f) (fun i => φ (g i)) p := by
rw [← comp_eval₂Hom]
rfl
theorem eval₂Hom_monomial (f : R →+* S₁) (g : σ → S₁) (d : σ →₀ ℕ) (r : R) :
eval₂Hom f g (monomial d r) = f r * d.prod fun i k => g i ^ k := by
simp only [monomial_eq, RingHom.map_mul, eval₂Hom_C, Finsupp.prod, map_prod,
RingHom.map_pow, eval₂Hom_X']
section
theorem eval₂_comp_left {S₂} [CommSemiring S₂] (k : S₁ →+* S₂) (f : R →+* S₁) (g : σ → S₁) (p) :
k (eval₂ f g p) = eval₂ (k.comp f) (k ∘ g) p := by
apply MvPolynomial.induction_on p <;>
simp (config := { contextual := true }) [eval₂_add, k.map_add, eval₂_mul, k.map_mul]
end
@[simp]
theorem eval₂_eta (p : MvPolynomial σ R) : eval₂ C X p = p := by
apply MvPolynomial.induction_on p <;>
simp (config := { contextual := true }) [eval₂_add, eval₂_mul]
theorem eval₂_congr (g₁ g₂ : σ → S₁)
(h : ∀ {i : σ} {c : σ →₀ ℕ}, i ∈ c.support → coeff c p ≠ 0 → g₁ i = g₂ i) :
p.eval₂ f g₁ = p.eval₂ f g₂ := by
apply Finset.sum_congr rfl
intro C hc; dsimp; congr 1
apply Finset.prod_congr rfl
intro i hi; dsimp; congr 1
apply h hi
rwa [Finsupp.mem_support_iff] at hc
theorem eval₂_sum (s : Finset S₂) (p : S₂ → MvPolynomial σ R) :
eval₂ f g (∑ x ∈ s, p x) = ∑ x ∈ s, eval₂ f g (p x) :=
map_sum (eval₂Hom f g) _ s
@[to_additive existing (attr := simp)]
theorem eval₂_prod (s : Finset S₂) (p : S₂ → MvPolynomial σ R) :
eval₂ f g (∏ x ∈ s, p x) = ∏ x ∈ s, eval₂ f g (p x) :=
map_prod (eval₂Hom f g) _ s
theorem eval₂_assoc (q : S₂ → MvPolynomial σ R) (p : MvPolynomial S₂ R) :
eval₂ f (fun t => eval₂ f g (q t)) p = eval₂ f g (eval₂ C q p) := by
show _ = eval₂Hom f g (eval₂ C q p)
rw [eval₂_comp_left (eval₂Hom f g)]; congr with a; simp
end Eval₂
section Eval
variable {f : σ → R}
/-- Evaluate a polynomial `p` given a valuation `f` of all the variables -/
def eval (f : σ → R) : MvPolynomial σ R →+* R :=
eval₂Hom (RingHom.id _) f
theorem eval_eq (X : σ → R) (f : MvPolynomial σ R) :
eval X f = ∑ d ∈ f.support, f.coeff d * ∏ i ∈ d.support, X i ^ d i :=
rfl
theorem eval_eq' [Fintype σ] (X : σ → R) (f : MvPolynomial σ R) :
eval X f = ∑ d ∈ f.support, f.coeff d * ∏ i, X i ^ d i :=
eval₂_eq' (RingHom.id R) X f
theorem eval_monomial : eval f (monomial s a) = a * s.prod fun n e => f n ^ e :=
eval₂_monomial _ _
@[simp]
theorem eval_C : ∀ a, eval f (C a) = a :=
eval₂_C _ _
@[simp]
theorem eval_X : ∀ n, eval f (X n) = f n :=
eval₂_X _ _
@[simp]
theorem smul_eval (x) (p : MvPolynomial σ R) (s) : eval x (s • p) = s * eval x p := by
rw [smul_eq_C_mul, (eval x).map_mul, eval_C]
theorem eval_add : eval f (p + q) = eval f p + eval f q :=
eval₂_add _ _
theorem eval_mul : eval f (p * q) = eval f p * eval f q :=
eval₂_mul _ _
theorem eval_pow : ∀ n, eval f (p ^ n) = eval f p ^ n :=
fun _ => eval₂_pow _ _
theorem eval_sum {ι : Type*} (s : Finset ι) (f : ι → MvPolynomial σ R) (g : σ → R) :
eval g (∑ i ∈ s, f i) = ∑ i ∈ s, eval g (f i) :=
map_sum (eval g) _ _
@[to_additive existing]
theorem eval_prod {ι : Type*} (s : Finset ι) (f : ι → MvPolynomial σ R) (g : σ → R) :
eval g (∏ i ∈ s, f i) = ∏ i ∈ s, eval g (f i) :=
map_prod (eval g) _ _
theorem eval_assoc {τ} (f : σ → MvPolynomial τ R) (g : τ → R) (p : MvPolynomial σ R) :
eval (eval g ∘ f) p = eval g (eval₂ C f p) := by
rw [eval₂_comp_left (eval g)]
unfold eval; simp only [coe_eval₂Hom]
congr with a; simp
@[simp]
theorem eval₂_id {g : σ → R} (p : MvPolynomial σ R) : eval₂ (RingHom.id _) g p = eval g p :=
rfl
theorem eval_eval₂ {S τ : Type*} {x : τ → S} [CommSemiring S]
(f : R →+* MvPolynomial τ S) (g : σ → MvPolynomial τ S) (p : MvPolynomial σ R) :
eval x (eval₂ f g p) = eval₂ ((eval x).comp f) (fun s => eval x (g s)) p := by
apply induction_on p
· simp
· intro p q hp hq
simp [hp, hq]
· intro p n hp
simp [hp]
end Eval
section Map
variable (f : R →+* S₁)
/-- `map f p` maps a polynomial `p` across a ring hom `f` -/
def map : MvPolynomial σ R →+* MvPolynomial σ S₁ :=
eval₂Hom (C.comp f) X
@[simp]
theorem map_monomial (s : σ →₀ ℕ) (a : R) : map f (monomial s a) = monomial s (f a) :=
(eval₂_monomial _ _).trans monomial_eq.symm
@[simp]
theorem map_C : ∀ a : R, map f (C a : MvPolynomial σ R) = C (f a) :=
map_monomial _ _
@[simp]
theorem map_X : ∀ n : σ, map f (X n : MvPolynomial σ R) = X n :=
eval₂_X _ _
theorem map_id : ∀ p : MvPolynomial σ R, map (RingHom.id R) p = p :=
eval₂_eta
theorem map_map [CommSemiring S₂] (g : S₁ →+* S₂) (p : MvPolynomial σ R) :
map g (map f p) = map (g.comp f) p :=
(eval₂_comp_left (map g) (C.comp f) X p).trans <| by
congr
· ext1 a
simp only [map_C, comp_apply, RingHom.coe_comp]
· ext1 n
simp only [map_X, comp_apply]
theorem eval₂_eq_eval_map (g : σ → S₁) (p : MvPolynomial σ R) : p.eval₂ f g = eval g (map f p) := by
unfold map eval; simp only [coe_eval₂Hom]
have h := eval₂_comp_left (eval₂Hom (RingHom.id S₁) g) (C.comp f) X p
-- Porting note: the Lean 3 version of `h` was full of metavariables which
-- were later unified during `rw [h]`. Also needed to add `-eval₂_id`.
dsimp [-eval₂_id] at h
rw [h]
congr
· ext1 a
simp only [coe_eval₂Hom, RingHom.id_apply, comp_apply, eval₂_C, RingHom.coe_comp]
· ext1 n
simp only [comp_apply, eval₂_X]
theorem eval₂_comp_right {S₂} [CommSemiring S₂] (k : S₁ →+* S₂) (f : R →+* S₁) (g : σ → S₁) (p) :
k (eval₂ f g p) = eval₂ k (k ∘ g) (map f p) := by
apply MvPolynomial.induction_on p
· intro r
rw [eval₂_C, map_C, eval₂_C]
· intro p q hp hq
rw [eval₂_add, k.map_add, (map f).map_add, eval₂_add, hp, hq]
· intro p s hp
rw [eval₂_mul, k.map_mul, (map f).map_mul, eval₂_mul, map_X, hp, eval₂_X, eval₂_X]
rfl
theorem map_eval₂ (f : R →+* S₁) (g : S₂ → MvPolynomial S₃ R) (p : MvPolynomial S₂ R) :
map f (eval₂ C g p) = eval₂ C (map f ∘ g) (map f p) := by
apply MvPolynomial.induction_on p
· intro r
rw [eval₂_C, map_C, map_C, eval₂_C]
· intro p q hp hq
rw [eval₂_add, (map f).map_add, hp, hq, (map f).map_add, eval₂_add]
· intro p s hp
rw [eval₂_mul, (map f).map_mul, hp, (map f).map_mul, map_X, eval₂_mul, eval₂_X, eval₂_X]
rfl
theorem coeff_map (p : MvPolynomial σ R) : ∀ m : σ →₀ ℕ, coeff m (map f p) = f (coeff m p) := by
classical
apply MvPolynomial.induction_on p <;> clear p
· intro r m
rw [map_C]
simp only [coeff_C]
split_ifs
· rfl
rw [f.map_zero]
· intro p q hp hq m
simp only [hp, hq, (map f).map_add, coeff_add]
rw [f.map_add]
· intro p i hp m
simp only [hp, (map f).map_mul, map_X]
simp only [hp, mem_support_iff, coeff_mul_X']
split_ifs
· rfl
rw [f.map_zero]
theorem map_injective (hf : Function.Injective f) :
Function.Injective (map f : MvPolynomial σ R → MvPolynomial σ S₁) := by
intro p q h
simp only [MvPolynomial.ext_iff, coeff_map] at h ⊢
intro m
exact hf (h m)
theorem map_surjective (hf : Function.Surjective f) :
Function.Surjective (map f : MvPolynomial σ R → MvPolynomial σ S₁) := fun p => by
induction' p using MvPolynomial.induction_on' with i fr a b ha hb
· obtain ⟨r, rfl⟩ := hf fr
exact ⟨monomial i r, map_monomial _ _ _⟩
· obtain ⟨a, rfl⟩ := ha
obtain ⟨b, rfl⟩ := hb
exact ⟨a + b, RingHom.map_add _ _ _⟩
/-- If `f` is a left-inverse of `g` then `map f` is a left-inverse of `map g`. -/
theorem map_leftInverse {f : R →+* S₁} {g : S₁ →+* R} (hf : Function.LeftInverse f g) :
Function.LeftInverse (map f : MvPolynomial σ R → MvPolynomial σ S₁) (map g) := fun X => by
rw [map_map, (RingHom.ext hf : f.comp g = RingHom.id _), map_id]
/-- If `f` is a right-inverse of `g` then `map f` is a right-inverse of `map g`. -/
theorem map_rightInverse {f : R →+* S₁} {g : S₁ →+* R} (hf : Function.RightInverse f g) :
Function.RightInverse (map f : MvPolynomial σ R → MvPolynomial σ S₁) (map g) :=
(map_leftInverse hf.leftInverse).rightInverse
@[simp]
theorem eval_map (f : R →+* S₁) (g : σ → S₁) (p : MvPolynomial σ R) :
eval g (map f p) = eval₂ f g p := by
apply MvPolynomial.induction_on p <;> · simp (config := { contextual := true })
@[simp]
theorem eval₂_map [CommSemiring S₂] (f : R →+* S₁) (g : σ → S₂) (φ : S₁ →+* S₂)
(p : MvPolynomial σ R) : eval₂ φ g (map f p) = eval₂ (φ.comp f) g p := by
rw [← eval_map, ← eval_map, map_map]
@[simp]
theorem eval₂Hom_map_hom [CommSemiring S₂] (f : R →+* S₁) (g : σ → S₂) (φ : S₁ →+* S₂)
(p : MvPolynomial σ R) : eval₂Hom φ g (map f p) = eval₂Hom (φ.comp f) g p :=
eval₂_map f g φ p
@[simp]
theorem constantCoeff_map (f : R →+* S₁) (φ : MvPolynomial σ R) :
constantCoeff (MvPolynomial.map f φ) = f (constantCoeff φ) :=
coeff_map f φ 0
theorem constantCoeff_comp_map (f : R →+* S₁) :
(constantCoeff : MvPolynomial σ S₁ →+* S₁).comp (MvPolynomial.map f) = f.comp constantCoeff :=
by ext <;> simp
theorem support_map_subset (p : MvPolynomial σ R) : (map f p).support ⊆ p.support := by
intro x
simp only [mem_support_iff]
contrapose!
change p.coeff x = 0 → (map f p).coeff x = 0
rw [coeff_map]
intro hx
rw [hx]
exact RingHom.map_zero f
theorem support_map_of_injective (p : MvPolynomial σ R) {f : R →+* S₁} (hf : Injective f) :
(map f p).support = p.support := by
apply Finset.Subset.antisymm
· exact MvPolynomial.support_map_subset _ _
intro x hx
rw [mem_support_iff]
contrapose! hx
simp only [Classical.not_not, mem_support_iff]
replace hx : (map f p).coeff x = 0 := hx
rw [coeff_map, ← f.map_zero] at hx
exact hf hx
theorem C_dvd_iff_map_hom_eq_zero (q : R →+* S₁) (r : R) (hr : ∀ r' : R, q r' = 0 ↔ r ∣ r')
(φ : MvPolynomial σ R) : C r ∣ φ ↔ map q φ = 0 := by
rw [C_dvd_iff_dvd_coeff, MvPolynomial.ext_iff]
simp only [coeff_map, coeff_zero, hr]
theorem map_mapRange_eq_iff (f : R →+* S₁) (g : S₁ → R) (hg : g 0 = 0) (φ : MvPolynomial σ S₁) :
map f (Finsupp.mapRange g hg φ) = φ ↔ ∀ d, f (g (coeff d φ)) = coeff d φ := by
rw [MvPolynomial.ext_iff]
apply forall_congr'; intro m
rw [coeff_map]
apply eq_iff_eq_cancel_right.mpr
rfl
/-- If `f : S₁ →ₐ[R] S₂` is a morphism of `R`-algebras, then so is `MvPolynomial.map f`. -/
@[simps!]
def mapAlgHom [CommSemiring S₂] [Algebra R S₁] [Algebra R S₂] (f : S₁ →ₐ[R] S₂) :
MvPolynomial σ S₁ →ₐ[R] MvPolynomial σ S₂ :=
{ map (↑f : S₁ →+* S₂) with
commutes' := fun r => by
have h₁ : algebraMap R (MvPolynomial σ S₁) r = C (algebraMap R S₁ r) := rfl
have h₂ : algebraMap R (MvPolynomial σ S₂) r = C (algebraMap R S₂ r) := rfl
simp_rw [OneHom.toFun_eq_coe]
-- Porting note: we're missing some `simp` lemmas like `MonoidHom.coe_toOneHom`
change @DFunLike.coe (_ →+* _) _ _ _ _ _ = _
rw [h₁, h₂, map, eval₂Hom_C, RingHom.comp_apply, AlgHom.coe_toRingHom, AlgHom.commutes] }
@[simp]
theorem mapAlgHom_id [Algebra R S₁] :
mapAlgHom (AlgHom.id R S₁) = AlgHom.id R (MvPolynomial σ S₁) :=
AlgHom.ext map_id
@[simp]
theorem mapAlgHom_coe_ringHom [CommSemiring S₂] [Algebra R S₁] [Algebra R S₂] (f : S₁ →ₐ[R] S₂) :
↑(mapAlgHom f : _ →ₐ[R] MvPolynomial σ S₂) =
(map ↑f : MvPolynomial σ S₁ →+* MvPolynomial σ S₂) :=
RingHom.mk_coe _ _ _ _ _
end Map
section Aeval
/-! ### The algebra of multivariate polynomials -/
variable [Algebra R S₁] [CommSemiring S₂]
variable (f : σ → S₁)
@[simp]
theorem algebraMap_apply (r : R) : algebraMap R (MvPolynomial σ S₁) r = C (algebraMap R S₁ r) := rfl
/-- A map `σ → S₁` where `S₁` is an algebra over `R` generates an `R`-algebra homomorphism
from multivariate polynomials over `σ` to `S₁`. -/
def aeval : MvPolynomial σ R →ₐ[R] S₁ :=
{ eval₂Hom (algebraMap R S₁) f with commutes' := fun _r => eval₂_C _ _ _ }
theorem aeval_def (p : MvPolynomial σ R) : aeval f p = eval₂ (algebraMap R S₁) f p :=
rfl
theorem aeval_eq_eval₂Hom (p : MvPolynomial σ R) : aeval f p = eval₂Hom (algebraMap R S₁) f p :=
rfl
@[simp]
lemma coe_aeval_eq_eval : RingHomClass.toRingHom (MvPolynomial.aeval f) = MvPolynomial.eval f :=
rfl
@[simp]
theorem aeval_X (s : σ) : aeval f (X s : MvPolynomial _ R) = f s :=
eval₂_X _ _ _
theorem aeval_C (r : R) : aeval f (C r) = algebraMap R S₁ r :=
eval₂_C _ _ _
theorem aeval_unique (φ : MvPolynomial σ R →ₐ[R] S₁) : φ = aeval (φ ∘ X) := by
ext i
simp
theorem aeval_X_left : aeval X = AlgHom.id R (MvPolynomial σ R) :=
(aeval_unique (AlgHom.id R _)).symm
theorem aeval_X_left_apply (p : MvPolynomial σ R) : aeval X p = p :=
AlgHom.congr_fun aeval_X_left p
theorem comp_aeval {B : Type*} [CommSemiring B] [Algebra R B] (φ : S₁ →ₐ[R] B) :
φ.comp (aeval f) = aeval fun i => φ (f i) := by
ext i
simp
@[simp]
theorem map_aeval {B : Type*} [CommSemiring B] (g : σ → S₁) (φ : S₁ →+* B) (p : MvPolynomial σ R) :
φ (aeval g p) = eval₂Hom (φ.comp (algebraMap R S₁)) (fun i => φ (g i)) p := by
rw [← comp_eval₂Hom]
rfl
@[simp]
theorem eval₂Hom_zero (f : R →+* S₂) : eval₂Hom f (0 : σ → S₂) = f.comp constantCoeff := by
ext <;> simp
@[simp]
theorem eval₂Hom_zero' (f : R →+* S₂) : eval₂Hom f (fun _ => 0 : σ → S₂) = f.comp constantCoeff :=
eval₂Hom_zero f
theorem eval₂Hom_zero_apply (f : R →+* S₂) (p : MvPolynomial σ R) :
eval₂Hom f (0 : σ → S₂) p = f (constantCoeff p) :=
RingHom.congr_fun (eval₂Hom_zero f) p
theorem eval₂Hom_zero'_apply (f : R →+* S₂) (p : MvPolynomial σ R) :
eval₂Hom f (fun _ => 0 : σ → S₂) p = f (constantCoeff p) :=
eval₂Hom_zero_apply f p
@[simp]
theorem eval₂_zero_apply (f : R →+* S₂) (p : MvPolynomial σ R) :
eval₂ f (0 : σ → S₂) p = f (constantCoeff p) :=
eval₂Hom_zero_apply _ _
@[simp]
theorem eval₂_zero'_apply (f : R →+* S₂) (p : MvPolynomial σ R) :
eval₂ f (fun _ => 0 : σ → S₂) p = f (constantCoeff p) :=
eval₂_zero_apply f p
@[simp]
theorem aeval_zero (p : MvPolynomial σ R) :
aeval (0 : σ → S₁) p = algebraMap _ _ (constantCoeff p) :=
eval₂Hom_zero_apply (algebraMap R S₁) p
@[simp]
theorem aeval_zero' (p : MvPolynomial σ R) :
aeval (fun _ => 0 : σ → S₁) p = algebraMap _ _ (constantCoeff p) :=
aeval_zero p
@[simp]
theorem eval_zero : eval (0 : σ → R) = constantCoeff :=
eval₂Hom_zero _
@[simp]
theorem eval_zero' : eval (fun _ => 0 : σ → R) = constantCoeff :=
eval₂Hom_zero _
theorem aeval_monomial (g : σ → S₁) (d : σ →₀ ℕ) (r : R) :
aeval g (monomial d r) = algebraMap _ _ r * d.prod fun i k => g i ^ k :=
eval₂Hom_monomial _ _ _ _
theorem eval₂Hom_eq_zero (f : R →+* S₂) (g : σ → S₂) (φ : MvPolynomial σ R)
(h : ∀ d, φ.coeff d ≠ 0 → ∃ i ∈ d.support, g i = 0) : eval₂Hom f g φ = 0 := by
rw [φ.as_sum, map_sum]
refine Finset.sum_eq_zero fun d hd => ?_
obtain ⟨i, hi, hgi⟩ : ∃ i ∈ d.support, g i = 0 := h d (Finsupp.mem_support_iff.mp hd)
rw [eval₂Hom_monomial, Finsupp.prod, Finset.prod_eq_zero hi, mul_zero]
rw [hgi, zero_pow]
rwa [← Finsupp.mem_support_iff]
theorem aeval_eq_zero [Algebra R S₂] (f : σ → S₂) (φ : MvPolynomial σ R)
(h : ∀ d, φ.coeff d ≠ 0 → ∃ i ∈ d.support, f i = 0) : aeval f φ = 0 :=
eval₂Hom_eq_zero _ _ _ h
theorem aeval_sum {ι : Type*} (s : Finset ι) (φ : ι → MvPolynomial σ R) :
aeval f (∑ i ∈ s, φ i) = ∑ i ∈ s, aeval f (φ i) :=
map_sum (MvPolynomial.aeval f) _ _
@[to_additive existing]
theorem aeval_prod {ι : Type*} (s : Finset ι) (φ : ι → MvPolynomial σ R) :
aeval f (∏ i ∈ s, φ i) = ∏ i ∈ s, aeval f (φ i) :=
map_prod (MvPolynomial.aeval f) _ _
variable (R)
theorem _root_.Algebra.adjoin_range_eq_range_aeval :
Algebra.adjoin R (Set.range f) = (MvPolynomial.aeval f).range := by
simp only [← Algebra.map_top, ← MvPolynomial.adjoin_range_X, AlgHom.map_adjoin, ← Set.range_comp,
(· ∘ ·), MvPolynomial.aeval_X]
theorem _root_.Algebra.adjoin_eq_range (s : Set S₁) :
Algebra.adjoin R s = (MvPolynomial.aeval ((↑) : s → S₁)).range := by
rw [← Algebra.adjoin_range_eq_range_aeval, Subtype.range_coe]
end Aeval
section AevalTower
variable {S A B : Type*} [CommSemiring S] [CommSemiring A] [CommSemiring B]
variable [Algebra S R] [Algebra S A] [Algebra S B]
/-- Version of `aeval` for defining algebra homs out of `MvPolynomial σ R` over a smaller base ring
than `R`. -/
def aevalTower (f : R →ₐ[S] A) (X : σ → A) : MvPolynomial σ R →ₐ[S] A :=
{ eval₂Hom (↑f) X with
commutes' := fun r => by
simp [IsScalarTower.algebraMap_eq S R (MvPolynomial σ R), algebraMap_eq] }
variable (g : R →ₐ[S] A) (y : σ → A)
@[simp]
theorem aevalTower_X (i : σ) : aevalTower g y (X i) = y i :=
eval₂_X _ _ _
@[simp]
theorem aevalTower_C (x : R) : aevalTower g y (C x) = g x :=
eval₂_C _ _ _
@[simp]
theorem aevalTower_comp_C : (aevalTower g y : MvPolynomial σ R →+* A).comp C = g :=
RingHom.ext <| aevalTower_C _ _
theorem aevalTower_algebraMap (x : R) : aevalTower g y (algebraMap R (MvPolynomial σ R) x) = g x :=
eval₂_C _ _ _
theorem aevalTower_comp_algebraMap :
(aevalTower g y : MvPolynomial σ R →+* A).comp (algebraMap R (MvPolynomial σ R)) = g :=
aevalTower_comp_C _ _
theorem aevalTower_toAlgHom (x : R) :
aevalTower g y (IsScalarTower.toAlgHom S R (MvPolynomial σ R) x) = g x :=
aevalTower_algebraMap _ _ _
@[simp]
theorem aevalTower_comp_toAlgHom :
(aevalTower g y).comp (IsScalarTower.toAlgHom S R (MvPolynomial σ R)) = g :=
AlgHom.coe_ringHom_injective <| aevalTower_comp_algebraMap _ _
@[simp]
theorem aevalTower_id :
aevalTower (AlgHom.id S S) = (aeval : (σ → S) → MvPolynomial σ S →ₐ[S] S) := by
ext
simp only [aevalTower_X, aeval_X]
@[simp]
theorem aevalTower_ofId :
aevalTower (Algebra.ofId S A) = (aeval : (σ → A) → MvPolynomial σ S →ₐ[S] A) := by
ext
simp only [aeval_X, aevalTower_X]
end AevalTower
section EvalMem
variable {S subS : Type*} [CommSemiring S] [SetLike subS S] [SubsemiringClass subS S]
theorem eval₂_mem {f : R →+* S} {p : MvPolynomial σ R} {s : subS}
(hs : ∀ i ∈ p.support, f (p.coeff i) ∈ s) {v : σ → S} (hv : ∀ i, v i ∈ s) :
MvPolynomial.eval₂ f v p ∈ s := by
classical
replace hs : ∀ i, f (p.coeff i) ∈ s := by
intro i
by_cases hi : i ∈ p.support
· exact hs i hi
· rw [MvPolynomial.not_mem_support_iff.1 hi, f.map_zero]
exact zero_mem s
induction' p using MvPolynomial.induction_on''' with a a b f ha _ ih
· simpa using hs 0
rw [eval₂_add, eval₂_monomial]
refine add_mem (mul_mem ?_ <| prod_mem fun i _ => pow_mem (hv _) _) (ih fun i => ?_)
· have := hs a -- Porting note: was `simpa only [...]`
rwa [coeff_add, MvPolynomial.not_mem_support_iff.1 ha, add_zero, coeff_monomial,
if_pos rfl] at this
have := hs i
rw [coeff_add, coeff_monomial] at this
split_ifs at this with h
· subst h
rw [MvPolynomial.not_mem_support_iff.1 ha, map_zero]
exact zero_mem _
· rwa [zero_add] at this
theorem eval_mem {p : MvPolynomial σ S} {s : subS} (hs : ∀ i ∈ p.support, p.coeff i ∈ s) {v : σ → S}
(hv : ∀ i, v i ∈ s) : MvPolynomial.eval v p ∈ s :=
eval₂_mem hs hv
end EvalMem
end CommSemiring
end MvPolynomial
|
Algebra\MvPolynomial\Cardinal.lean | /-
Copyright (c) 2021 Chris Hughes, Junyan Xu. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Junyan Xu
-/
import Mathlib.Algebra.MvPolynomial.Equiv
import Mathlib.Data.Finsupp.Fintype
import Mathlib.SetTheory.Cardinal.Ordinal
/-!
# Cardinality of Multivariate Polynomial Ring
The main result in this file is `MvPolynomial.cardinal_mk_le_max`, which says that
the cardinality of `MvPolynomial σ R` is bounded above by the maximum of `#R`, `#σ`
and `ℵ₀`.
-/
universe u v
open Cardinal
open Cardinal
namespace MvPolynomial
section TwoUniverses
variable {σ : Type u} {R : Type v} [CommSemiring R]
@[simp]
theorem cardinal_mk_eq_max_lift [Nonempty σ] [Nontrivial R] :
#(MvPolynomial σ R) = max (max (Cardinal.lift.{u} #R) <| Cardinal.lift.{v} #σ) ℵ₀ :=
(mk_finsupp_lift_of_infinite _ R).trans <| by
rw [mk_finsupp_nat, max_assoc, lift_max, lift_aleph0, max_comm]
@[simp]
theorem cardinal_mk_eq_lift [IsEmpty σ] : #(MvPolynomial σ R) = Cardinal.lift.{u} #R :=
((isEmptyRingEquiv R σ).toEquiv.trans Equiv.ulift.{u}.symm).cardinal_eq
theorem cardinal_lift_mk_le_max {σ : Type u} {R : Type v} [CommSemiring R] : #(MvPolynomial σ R) ≤
max (max (Cardinal.lift.{u} #R) <| Cardinal.lift.{v} #σ) ℵ₀ := by
cases subsingleton_or_nontrivial R
· exact (mk_eq_one _).trans_le (le_max_of_le_right one_le_aleph0)
cases isEmpty_or_nonempty σ
· exact cardinal_mk_eq_lift.trans_le (le_max_of_le_left <| le_max_left _ _)
· exact cardinal_mk_eq_max_lift.le
end TwoUniverses
variable {σ R : Type u} [CommSemiring R]
theorem cardinal_mk_eq_max [Nonempty σ] [Nontrivial R] :
#(MvPolynomial σ R) = max (max #R #σ) ℵ₀ := by simp
/-- The cardinality of the multivariate polynomial ring, `MvPolynomial σ R` is at most the maximum
of `#R`, `#σ` and `ℵ₀` -/
theorem cardinal_mk_le_max : #(MvPolynomial σ R) ≤ max (max #R #σ) ℵ₀ :=
cardinal_lift_mk_le_max.trans <| by rw [lift_id, lift_id]
end MvPolynomial
|
Algebra\MvPolynomial\Comap.lean | /-
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.Rename
/-!
# `comap` operation on `MvPolynomial`
This file defines the `comap` function on `MvPolynomial`.
`MvPolynomial.comap` is a low-tech example of a map of "algebraic varieties," modulo the fact that
`mathlib` does not yet define varieties.
## Notation
As in other polynomial files, we typically use the notation:
+ `σ : Type*` (indexing the variables)
+ `R : Type*` `[CommSemiring R]` (the coefficients)
-/
namespace MvPolynomial
variable {σ : Type*} {τ : Type*} {υ : Type*} {R : Type*} [CommSemiring R]
/-- Given an algebra hom `f : MvPolynomial σ R →ₐ[R] MvPolynomial τ R`
and a variable evaluation `v : τ → R`,
`comap f v` produces a variable evaluation `σ → R`.
-/
noncomputable def comap (f : MvPolynomial σ R →ₐ[R] MvPolynomial τ R) : (τ → R) → σ → R :=
fun x i => aeval x (f (X i))
@[simp]
theorem comap_apply (f : MvPolynomial σ R →ₐ[R] MvPolynomial τ R) (x : τ → R) (i : σ) :
comap f x i = aeval x (f (X i)) :=
rfl
@[simp]
theorem comap_id_apply (x : σ → R) : comap (AlgHom.id R (MvPolynomial σ R)) x = x := by
funext i
simp only [comap, AlgHom.id_apply, id, aeval_X]
variable (σ R)
theorem comap_id : comap (AlgHom.id R (MvPolynomial σ R)) = id := by
funext x
exact comap_id_apply x
variable {σ R}
theorem comap_comp_apply (f : MvPolynomial σ R →ₐ[R] MvPolynomial τ R)
(g : MvPolynomial τ R →ₐ[R] MvPolynomial υ R) (x : υ → R) :
comap (g.comp f) x = comap f (comap g x) := by
funext i
trans aeval x (aeval (fun i => g (X i)) (f (X i)))
· apply eval₂Hom_congr rfl rfl
rw [AlgHom.comp_apply]
suffices g = aeval fun i => g (X i) by rw [← this]
exact aeval_unique g
· simp only [comap, aeval_eq_eval₂Hom, map_eval₂Hom, AlgHom.comp_apply]
refine eval₂Hom_congr ?_ rfl rfl
ext r
apply aeval_C
theorem comap_comp (f : MvPolynomial σ R →ₐ[R] MvPolynomial τ R)
(g : MvPolynomial τ R →ₐ[R] MvPolynomial υ R) : comap (g.comp f) = comap f ∘ comap g := by
funext x
exact comap_comp_apply _ _ _
theorem comap_eq_id_of_eq_id (f : MvPolynomial σ R →ₐ[R] MvPolynomial σ R) (hf : ∀ φ, f φ = φ)
(x : σ → R) : comap f x = x := by
convert comap_id_apply x
ext1 φ
simp [hf, AlgHom.id_apply]
theorem comap_rename (f : σ → τ) (x : τ → R) : comap (rename f) x = x ∘ f := by
funext
simp [rename_X, comap_apply, aeval_X]
/-- If two polynomial types over the same coefficient ring `R` are equivalent,
there is a bijection between the types of functions from their variable types to `R`.
-/
noncomputable def comapEquiv (f : MvPolynomial σ R ≃ₐ[R] MvPolynomial τ R) : (τ → R) ≃ (σ → R) where
toFun := comap f
invFun := comap f.symm
left_inv := by
intro x
rw [← comap_comp_apply]
apply comap_eq_id_of_eq_id
intro
simp only [AlgHom.id_apply, AlgEquiv.comp_symm]
right_inv := by
intro x
rw [← comap_comp_apply]
apply comap_eq_id_of_eq_id
intro
simp only [AlgHom.id_apply, AlgEquiv.symm_comp]
@[simp]
theorem comapEquiv_coe (f : MvPolynomial σ R ≃ₐ[R] MvPolynomial τ R) :
(comapEquiv f : (τ → R) → σ → R) = comap f :=
rfl
@[simp]
theorem comapEquiv_symm_coe (f : MvPolynomial σ R ≃ₐ[R] MvPolynomial τ R) :
((comapEquiv f).symm : (σ → R) → τ → R) = comap f.symm :=
rfl
end MvPolynomial
|
Algebra\MvPolynomial\CommRing.lean | /-
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.MvPolynomial.Variables
/-!
# Multivariate polynomials over a ring
Many results about polynomials hold when the coefficient ring is a commutative semiring.
Some stronger results can be derived when we assume this semiring is a ring.
This file does not define any new operations, but proves some of these stronger results.
## Notation
As in other polynomial files, we typically use the notation:
+ `σ : Type*` (indexing the variables)
+ `R : Type*` `[CommRing 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`
-/
noncomputable section
open Set Function Finsupp AddMonoidAlgebra
universe u v
variable {R : Type u} {S : Type v}
namespace MvPolynomial
variable {σ : Type*} {a a' a₁ a₂ : R} {e : ℕ} {n m : σ} {s : σ →₀ ℕ}
section CommRing
variable [CommRing R]
variable {p q : MvPolynomial σ R}
instance instCommRingMvPolynomial : CommRing (MvPolynomial σ R) :=
AddMonoidAlgebra.commRing
variable (σ a a')
-- @[simp] -- Porting note (#10618): simp can prove this
theorem C_sub : (C (a - a') : MvPolynomial σ R) = C a - C a' :=
RingHom.map_sub _ _ _
-- @[simp] -- Porting note (#10618): simp can prove this
theorem C_neg : (C (-a) : MvPolynomial σ R) = -C a :=
RingHom.map_neg _ _
@[simp]
theorem coeff_neg (m : σ →₀ ℕ) (p : MvPolynomial σ R) : coeff m (-p) = -coeff m p :=
Finsupp.neg_apply _ _
@[simp]
theorem coeff_sub (m : σ →₀ ℕ) (p q : MvPolynomial σ R) : coeff m (p - q) = coeff m p - coeff m q :=
Finsupp.sub_apply _ _ _
@[simp]
theorem support_neg : (-p).support = p.support :=
Finsupp.support_neg p
theorem support_sub [DecidableEq σ] (p q : MvPolynomial σ R) :
(p - q).support ⊆ p.support ∪ q.support :=
Finsupp.support_sub
variable {σ} (p)
section Degrees
theorem degrees_neg (p : MvPolynomial σ R) : (-p).degrees = p.degrees := by
rw [degrees, support_neg]; rfl
theorem degrees_sub [DecidableEq σ] (p q : MvPolynomial σ R) :
(p - q).degrees ≤ p.degrees ⊔ q.degrees := by
simpa only [sub_eq_add_neg] using le_trans (degrees_add p (-q)) (by rw [degrees_neg])
end Degrees
section Vars
@[simp]
theorem vars_neg : (-p).vars = p.vars := by simp [vars, degrees_neg]
theorem vars_sub_subset [DecidableEq σ] : (p - q).vars ⊆ p.vars ∪ q.vars := by
convert vars_add_subset p (-q) using 2 <;> simp [sub_eq_add_neg]
@[simp]
theorem vars_sub_of_disjoint [DecidableEq σ] (hpq : Disjoint p.vars q.vars) :
(p - q).vars = p.vars ∪ q.vars := by
rw [← vars_neg q] at hpq
convert vars_add_of_disjoint hpq using 2 <;> simp [sub_eq_add_neg]
end Vars
section Eval
variable [CommRing S]
variable (f : R →+* S) (g : σ → S)
@[simp]
theorem eval₂_sub : (p - q).eval₂ f g = p.eval₂ f g - q.eval₂ f g :=
(eval₂Hom f g).map_sub _ _
theorem eval_sub (f : σ → R) : eval f (p - q) = eval f p - eval f q :=
eval₂_sub _ _ _
@[simp]
theorem eval₂_neg : (-p).eval₂ f g = -p.eval₂ f g :=
(eval₂Hom f g).map_neg _
theorem eval_neg (f : σ → R) : eval f (-p) = -eval f p :=
eval₂_neg _ _ _
theorem hom_C (f : MvPolynomial σ ℤ →+* S) (n : ℤ) : f (C n) = (n : S) :=
eq_intCast (f.comp C) n
/-- A ring homomorphism f : Z[X_1, X_2, ...] → R
is determined by the evaluations f(X_1), f(X_2), ... -/
@[simp]
theorem eval₂Hom_X {R : Type u} (c : ℤ →+* S) (f : MvPolynomial R ℤ →+* S) (x : MvPolynomial R ℤ) :
eval₂ c (f ∘ X) x = f x := by
apply MvPolynomial.induction_on x
(fun n => by
rw [hom_C f, eval₂_C]
exact eq_intCast c n)
(fun p q hp hq => by
rw [eval₂_add, hp, hq]
exact (f.map_add _ _).symm)
(fun p n hp => by
rw [eval₂_mul, eval₂_X, hp]
exact (f.map_mul _ _).symm)
/-- Ring homomorphisms out of integer polynomials on a type `σ` are the same as
functions out of the type `σ`, -/
def homEquiv : (MvPolynomial σ ℤ →+* S) ≃ (σ → S) where
toFun f := f ∘ X
invFun f := eval₂Hom (Int.castRingHom S) f
left_inv f := RingHom.ext <| eval₂Hom_X _ _
right_inv f := funext fun x => by simp only [coe_eval₂Hom, Function.comp_apply, eval₂_X]
end Eval
section DegreeOf
theorem degreeOf_sub_lt {x : σ} {f g : MvPolynomial σ R} {k : ℕ} (h : 0 < k)
(hf : ∀ m : σ →₀ ℕ, m ∈ f.support → k ≤ m x → coeff m f = coeff m g)
(hg : ∀ m : σ →₀ ℕ, m ∈ g.support → k ≤ m x → coeff m f = coeff m g) :
degreeOf x (f - g) < k := by
classical
rw [degreeOf_lt_iff h]
intro m hm
by_contra! hc
have h := support_sub σ f g hm
simp only [mem_support_iff, Ne, coeff_sub, sub_eq_zero] at hm
cases' Finset.mem_union.1 h with cf cg
· exact hm (hf m cf hc)
· exact hm (hg m cg hc)
end DegreeOf
section TotalDegree
@[simp]
theorem totalDegree_neg (a : MvPolynomial σ R) : (-a).totalDegree = a.totalDegree := by
simp only [totalDegree, support_neg]
theorem totalDegree_sub (a b : MvPolynomial σ R) :
(a - b).totalDegree ≤ max a.totalDegree b.totalDegree :=
calc
(a - b).totalDegree = (a + -b).totalDegree := by rw [sub_eq_add_neg]
_ ≤ max a.totalDegree (-b).totalDegree := totalDegree_add a (-b)
_ = max a.totalDegree b.totalDegree := by rw [totalDegree_neg]
theorem totalDegree_sub_C_le (p : MvPolynomial σ R) (r : R) :
totalDegree (p - C r) ≤ totalDegree p :=
(totalDegree_sub _ _).trans_eq <| by rw [totalDegree_C, Nat.max_zero]
end TotalDegree
end CommRing
end MvPolynomial
|
Algebra\MvPolynomial\Counit.lean | /-
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.Basic
/-!
## Counit morphisms for multivariate polynomials
One may consider the ring of multivariate polynomials `MvPolynomial A R` with coefficients in `R`
and variables indexed by `A`. If `A` is not just a type, but an algebra over `R`,
then there is a natural surjective algebra homomorphism `MvPolynomial A R →ₐ[R] A`
obtained by `X a ↦ a`.
### Main declarations
* `MvPolynomial.ACounit R A` is the natural surjective algebra homomorphism
`MvPolynomial A R →ₐ[R] A` obtained by `X a ↦ a`
* `MvPolynomial.counit` is an “absolute” variant with `R = ℤ`
* `MvPolynomial.counitNat` is an “absolute” variant with `R = ℕ`
-/
namespace MvPolynomial
open Function
variable (A B R : Type*) [CommSemiring A] [CommSemiring B] [CommRing R] [Algebra A B]
/-- `MvPolynomial.ACounit A B` is the natural surjective algebra homomorphism
`MvPolynomial B A →ₐ[A] B` obtained by `X a ↦ a`.
See `MvPolynomial.counit` for the “absolute” variant with `A = ℤ`,
and `MvPolynomial.counitNat` for the “absolute” variant with `A = ℕ`. -/
noncomputable def ACounit : MvPolynomial B A →ₐ[A] B :=
aeval id
variable {B}
@[simp]
theorem ACounit_X (b : B) : ACounit A B (X b) = b :=
aeval_X _ b
variable {A} (B)
theorem ACounit_C (a : A) : ACounit A B (C a) = algebraMap A B a :=
aeval_C _ a
variable (A)
theorem ACounit_surjective : Surjective (ACounit A B) := fun b => ⟨X b, ACounit_X A b⟩
/-- `MvPolynomial.counit R` is the natural surjective ring homomorphism
`MvPolynomial R ℤ →+* R` obtained by `X r ↦ r`.
See `MvPolynomial.ACounit` for a “relative” variant for algebras over a base ring,
and `MvPolynomial.counitNat` for the “absolute” variant with `R = ℕ`. -/
noncomputable def counit : MvPolynomial R ℤ →+* R :=
(ACounit ℤ R).toRingHom
/-- `MvPolynomial.counitNat A` is the natural surjective ring homomorphism
`MvPolynomial A ℕ →+* A` obtained by `X a ↦ a`.
See `MvPolynomial.ACounit` for a “relative” variant for algebras over a base ring
and `MvPolynomial.counit` for the “absolute” variant with `A = ℤ`. -/
noncomputable def counitNat : MvPolynomial A ℕ →+* A :=
ACounit ℕ A
theorem counit_surjective : Surjective (counit R) :=
ACounit_surjective ℤ R
theorem counitNat_surjective : Surjective (counitNat A) :=
ACounit_surjective ℕ A
theorem counit_C (n : ℤ) : counit R (C n) = n :=
ACounit_C _ _
theorem counitNat_C (n : ℕ) : counitNat A (C n) = n :=
ACounit_C _ _
variable {R A}
@[simp]
theorem counit_X (r : R) : counit R (X r) = r :=
ACounit_X _ _
@[simp]
theorem counitNat_X (a : A) : counitNat A (X a) = a :=
ACounit_X _ _
end MvPolynomial
|
Algebra\MvPolynomial\Degrees.lean | /-
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.MonoidAlgebra.Degree
import Mathlib.Algebra.MvPolynomial.Rename
/-!
# Degrees of polynomials
This file establishes many results about the degree of a multivariate polynomial.
The *degree set* of a polynomial $P \in R[X]$ is a `Multiset` containing, for each $x$ in the
variable set, $n$ copies of $x$, where $n$ is the maximum number of copies of $x$ appearing in a
monomial of $P$.
## Main declarations
* `MvPolynomial.degrees p` : the multiset of variables representing the union of the multisets
corresponding to each non-zero monomial in `p`.
For example if `7 ≠ 0` in `R` and `p = x²y+7y³` then `degrees p = {x, x, y, y, y}`
* `MvPolynomial.degreeOf n p : ℕ` : the total degree of `p` with respect to the variable `n`.
For example if `p = x⁴y+yz` then `degreeOf y p = 1`.
* `MvPolynomial.totalDegree p : ℕ` :
the max of the sizes of the multisets `s` whose monomials `X^s` occur in `p`.
For example if `p = x⁴y+yz` then `totalDegree p = 5`.
## Notation
As in other polynomial files, we typically use the 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`
+ `r : R`
+ `i : σ`, with corresponding monomial `X i`, often denoted `X_i` by mathematicians
+ `p : MvPolynomial σ R`
-/
noncomputable section
open Set Function Finsupp AddMonoidAlgebra
universe u v w
variable {R : Type u} {S : Type v}
namespace MvPolynomial
variable {σ τ : Type*} {r : R} {e : ℕ} {n m : σ} {s : σ →₀ ℕ}
section CommSemiring
variable [CommSemiring R] {p q : MvPolynomial σ R}
section Degrees
/-! ### `degrees` -/
/-- The maximal degrees of each variable in a multi-variable polynomial, expressed as a multiset.
(For example, `degrees (x^2 * y + y^3)` would be `{x, x, y, y, y}`.)
-/
def degrees (p : MvPolynomial σ R) : Multiset σ :=
letI := Classical.decEq σ
p.support.sup fun s : σ →₀ ℕ => toMultiset s
theorem degrees_def [DecidableEq σ] (p : MvPolynomial σ R) :
p.degrees = p.support.sup fun s : σ →₀ ℕ => Finsupp.toMultiset s := by rw [degrees]; convert rfl
theorem degrees_monomial (s : σ →₀ ℕ) (a : R) : degrees (monomial s a) ≤ toMultiset s := by
classical
refine (supDegree_single s a).trans_le ?_
split_ifs
exacts [bot_le, le_rfl]
theorem degrees_monomial_eq (s : σ →₀ ℕ) (a : R) (ha : a ≠ 0) :
degrees (monomial s a) = toMultiset s := by
classical
exact (supDegree_single s a).trans (if_neg ha)
theorem degrees_C (a : R) : degrees (C a : MvPolynomial σ R) = 0 :=
Multiset.le_zero.1 <| degrees_monomial _ _
theorem degrees_X' (n : σ) : degrees (X n : MvPolynomial σ R) ≤ {n} :=
le_trans (degrees_monomial _ _) <| le_of_eq <| toMultiset_single _ _
@[simp]
theorem degrees_X [Nontrivial R] (n : σ) : degrees (X n : MvPolynomial σ R) = {n} :=
(degrees_monomial_eq _ (1 : R) one_ne_zero).trans (toMultiset_single _ _)
@[simp]
theorem degrees_zero : degrees (0 : MvPolynomial σ R) = 0 := by
rw [← C_0]
exact degrees_C 0
@[simp]
theorem degrees_one : degrees (1 : MvPolynomial σ R) = 0 :=
degrees_C 1
theorem degrees_add [DecidableEq σ] (p q : MvPolynomial σ R) :
(p + q).degrees ≤ p.degrees ⊔ q.degrees := by
simp_rw [degrees_def]; exact supDegree_add_le
theorem degrees_sum {ι : Type*} [DecidableEq σ] (s : Finset ι) (f : ι → MvPolynomial σ R) :
(∑ i ∈ s, f i).degrees ≤ s.sup fun i => (f i).degrees := by
simp_rw [degrees_def]; exact supDegree_sum_le
theorem degrees_mul (p q : MvPolynomial σ R) : (p * q).degrees ≤ p.degrees + q.degrees := by
classical
simp_rw [degrees_def]
exact supDegree_mul_le (map_add _)
theorem degrees_prod {ι : Type*} (s : Finset ι) (f : ι → MvPolynomial σ R) :
(∏ i ∈ s, f i).degrees ≤ ∑ i ∈ s, (f i).degrees := by
classical exact supDegree_prod_le (map_zero _) (map_add _)
theorem degrees_pow (p : MvPolynomial σ R) (n : ℕ) : (p ^ n).degrees ≤ n • p.degrees := by
simpa using degrees_prod (Finset.range n) fun _ ↦ p
theorem mem_degrees {p : MvPolynomial σ R} {i : σ} :
i ∈ p.degrees ↔ ∃ d, p.coeff d ≠ 0 ∧ i ∈ d.support := by
classical
simp only [degrees_def, Multiset.mem_sup, ← mem_support_iff, Finsupp.mem_toMultiset, exists_prop]
theorem le_degrees_add {p q : MvPolynomial σ R} (h : p.degrees.Disjoint q.degrees) :
p.degrees ≤ (p + q).degrees := by
classical
apply Finset.sup_le
intro d hd
rw [Multiset.disjoint_iff_ne] at h
obtain rfl | h0 := eq_or_ne d 0
· rw [toMultiset_zero]; apply Multiset.zero_le
· refine Finset.le_sup_of_le (b := d) ?_ le_rfl
rw [mem_support_iff, coeff_add]
suffices q.coeff d = 0 by rwa [this, add_zero, coeff, ← Finsupp.mem_support_iff]
rw [Ne, ← Finsupp.support_eq_empty, ← Ne, ← Finset.nonempty_iff_ne_empty] at h0
obtain ⟨j, hj⟩ := h0
contrapose! h
rw [mem_support_iff] at hd
refine ⟨j, ?_, j, ?_, rfl⟩
all_goals rw [mem_degrees]; refine ⟨d, ?_, hj⟩; assumption
theorem degrees_add_of_disjoint [DecidableEq σ] {p q : MvPolynomial σ R}
(h : Multiset.Disjoint p.degrees q.degrees) : (p + q).degrees = p.degrees ∪ q.degrees := by
apply le_antisymm
· apply degrees_add
· apply Multiset.union_le
· apply le_degrees_add h
· rw [add_comm]
apply le_degrees_add h.symm
theorem degrees_map [CommSemiring S] (p : MvPolynomial σ R) (f : R →+* S) :
(map f p).degrees ⊆ p.degrees := by
classical
dsimp only [degrees]
apply Multiset.subset_of_le
apply Finset.sup_mono
apply MvPolynomial.support_map_subset
theorem degrees_rename (f : σ → τ) (φ : MvPolynomial σ R) :
(rename f φ).degrees ⊆ φ.degrees.map f := by
classical
intro i
rw [mem_degrees, Multiset.mem_map]
rintro ⟨d, hd, hi⟩
obtain ⟨x, rfl, hx⟩ := coeff_rename_ne_zero _ _ _ hd
simp only [Finsupp.mapDomain, Finsupp.mem_support_iff] at hi
rw [sum_apply, Finsupp.sum] at hi
contrapose! hi
rw [Finset.sum_eq_zero]
intro j hj
simp only [exists_prop, mem_degrees] at hi
specialize hi j ⟨x, hx, hj⟩
rw [Finsupp.single_apply, if_neg hi]
theorem degrees_map_of_injective [CommSemiring S] (p : MvPolynomial σ R) {f : R →+* S}
(hf : Injective f) : (map f p).degrees = p.degrees := by
simp only [degrees, MvPolynomial.support_map_of_injective _ hf]
theorem degrees_rename_of_injective {p : MvPolynomial σ R} {f : σ → τ} (h : Function.Injective f) :
degrees (rename f p) = (degrees p).map f := by
classical
simp only [degrees, Multiset.map_finset_sup p.support Finsupp.toMultiset f h,
support_rename_of_injective h, Finset.sup_image]
refine Finset.sup_congr rfl fun x _ => ?_
exact (Finsupp.toMultiset_map _ _).symm
end Degrees
section DegreeOf
/-! ### `degreeOf` -/
/-- `degreeOf n p` gives the highest power of X_n that appears in `p` -/
def degreeOf (n : σ) (p : MvPolynomial σ R) : ℕ :=
letI := Classical.decEq σ
p.degrees.count n
theorem degreeOf_def [DecidableEq σ] (n : σ) (p : MvPolynomial σ R) :
p.degreeOf n = p.degrees.count n := by rw [degreeOf]; convert rfl
theorem degreeOf_eq_sup (n : σ) (f : MvPolynomial σ R) :
degreeOf n f = f.support.sup fun m => m n := by
classical
rw [degreeOf_def, degrees, Multiset.count_finset_sup]
congr
ext
simp
theorem degreeOf_lt_iff {n : σ} {f : MvPolynomial σ R} {d : ℕ} (h : 0 < d) :
degreeOf n f < d ↔ ∀ m : σ →₀ ℕ, m ∈ f.support → m n < d := by
rwa [degreeOf_eq_sup, Finset.sup_lt_iff]
lemma degreeOf_le_iff {n : σ} {f : MvPolynomial σ R} {d : ℕ} :
degreeOf n f ≤ d ↔ ∀ m ∈ support f, m n ≤ d := by
rw [degreeOf_eq_sup, Finset.sup_le_iff]
@[simp]
theorem degreeOf_zero (n : σ) : degreeOf n (0 : MvPolynomial σ R) = 0 := by
classical simp only [degreeOf_def, degrees_zero, Multiset.count_zero]
@[simp]
theorem degreeOf_C (a : R) (x : σ) : degreeOf x (C a : MvPolynomial σ R) = 0 := by
classical simp [degreeOf_def, degrees_C]
theorem degreeOf_X [DecidableEq σ] (i j : σ) [Nontrivial R] :
degreeOf i (X j : MvPolynomial σ R) = if i = j then 1 else 0 := by
classical
by_cases c : i = j
· simp only [c, if_true, eq_self_iff_true, degreeOf_def, degrees_X, Multiset.count_singleton]
simp [c, if_false, degreeOf_def, degrees_X]
theorem degreeOf_add_le (n : σ) (f g : MvPolynomial σ R) :
degreeOf n (f + g) ≤ max (degreeOf n f) (degreeOf n g) := by
simp_rw [degreeOf_eq_sup]; exact supDegree_add_le
theorem monomial_le_degreeOf (i : σ) {f : MvPolynomial σ R} {m : σ →₀ ℕ} (h_m : m ∈ f.support) :
m i ≤ degreeOf i f := by
rw [degreeOf_eq_sup i]
apply Finset.le_sup h_m
-- TODO we can prove equality here if R is a domain
theorem degreeOf_mul_le (i : σ) (f g : MvPolynomial σ R) :
degreeOf i (f * g) ≤ degreeOf i f + degreeOf i g := by
classical
repeat' rw [degreeOf]
convert Multiset.count_le_of_le i (degrees_mul f g)
rw [Multiset.count_add]
theorem degreeOf_mul_X_ne {i j : σ} (f : MvPolynomial σ R) (h : i ≠ j) :
degreeOf i (f * X j) = degreeOf i f := by
classical
repeat' rw [degreeOf_eq_sup (R := R) i]
rw [support_mul_X]
simp only [Finset.sup_map]
congr
ext
simp only [Finsupp.single, Nat.one_ne_zero, add_right_eq_self, addRightEmbedding_apply, coe_mk,
Pi.add_apply, comp_apply, ite_eq_right_iff, Finsupp.coe_add, Pi.single_eq_of_ne h]
-- TODO in the following we have equality iff f ≠ 0
theorem degreeOf_mul_X_eq (j : σ) (f : MvPolynomial σ R) :
degreeOf j (f * X j) ≤ degreeOf j f + 1 := by
classical
repeat' rw [degreeOf]
apply (Multiset.count_le_of_le j (degrees_mul f (X j))).trans
simp only [Multiset.count_add, add_le_add_iff_left]
convert Multiset.count_le_of_le j (degrees_X' (R := R) j)
rw [Multiset.count_singleton_self]
theorem degreeOf_C_mul_le (p : MvPolynomial σ R) (i : σ) (c : R) :
(C c * p).degreeOf i ≤ p.degreeOf i := by
unfold degreeOf
convert Multiset.count_le_of_le i <| degrees_mul (C c) p
simp [degrees_C]
theorem degreeOf_mul_C_le (p : MvPolynomial σ R) (i : σ) (c : R) :
(p * C c).degreeOf i ≤ p.degreeOf i := by
unfold degreeOf
convert Multiset.count_le_of_le i <| degrees_mul p (C c)
simp [degrees_C]
theorem degreeOf_rename_of_injective {p : MvPolynomial σ R} {f : σ → τ} (h : Function.Injective f)
(i : σ) : degreeOf (f i) (rename f p) = degreeOf i p := by
classical
simp only [degreeOf, degrees_rename_of_injective h, Multiset.count_map_eq_count' f p.degrees h]
end DegreeOf
section TotalDegree
/-! ### `totalDegree` -/
/-- `totalDegree p` gives the maximum |s| over the monomials X^s in `p` -/
def totalDegree (p : MvPolynomial σ R) : ℕ :=
p.support.sup fun s => s.sum fun _ e => e
theorem totalDegree_eq (p : MvPolynomial σ R) :
p.totalDegree = p.support.sup fun m => Multiset.card (toMultiset m) := by
rw [totalDegree]
congr; funext m
exact (Finsupp.card_toMultiset _).symm
theorem le_totalDegree {p : MvPolynomial σ R} {s : σ →₀ ℕ} (h : s ∈ p.support) :
(s.sum fun _ e => e) ≤ totalDegree p :=
Finset.le_sup (α := ℕ) (f := fun s => sum s fun _ e => e) h
theorem totalDegree_le_degrees_card (p : MvPolynomial σ R) :
p.totalDegree ≤ Multiset.card p.degrees := by
classical
rw [totalDegree_eq]
exact Finset.sup_le fun s hs => Multiset.card_le_card <| Finset.le_sup hs
theorem totalDegree_le_of_support_subset (h : p.support ⊆ q.support) :
totalDegree p ≤ totalDegree q :=
Finset.sup_mono h
@[simp]
theorem totalDegree_C (a : R) : (C a : MvPolynomial σ R).totalDegree = 0 :=
(supDegree_single 0 a).trans <| by rw [sum_zero_index, bot_eq_zero', ite_self]
@[simp]
theorem totalDegree_zero : (0 : MvPolynomial σ R).totalDegree = 0 := by
rw [← C_0]; exact totalDegree_C (0 : R)
@[simp]
theorem totalDegree_one : (1 : MvPolynomial σ R).totalDegree = 0 :=
totalDegree_C (1 : R)
@[simp]
theorem totalDegree_X {R} [CommSemiring R] [Nontrivial R] (s : σ) :
(X s : MvPolynomial σ R).totalDegree = 1 := by
rw [totalDegree, support_X]
simp only [Finset.sup, Finsupp.sum_single_index, Finset.fold_singleton, sup_bot_eq]
theorem totalDegree_add (a b : MvPolynomial σ R) :
(a + b).totalDegree ≤ max a.totalDegree b.totalDegree :=
sup_support_add_le _ _ _
theorem totalDegree_add_eq_left_of_totalDegree_lt {p q : MvPolynomial σ R}
(h : q.totalDegree < p.totalDegree) : (p + q).totalDegree = p.totalDegree := by
classical
apply le_antisymm
· rw [← max_eq_left_of_lt h]
exact totalDegree_add p q
by_cases hp : p = 0
· simp [hp]
obtain ⟨b, hb₁, hb₂⟩ :=
p.support.exists_mem_eq_sup (Finsupp.support_nonempty_iff.mpr hp) fun m : σ →₀ ℕ =>
Multiset.card (toMultiset m)
have hb : ¬b ∈ q.support := by
contrapose! h
rw [totalDegree_eq p, hb₂, totalDegree_eq]
apply Finset.le_sup h
have hbb : b ∈ (p + q).support := by
apply support_sdiff_support_subset_support_add
rw [Finset.mem_sdiff]
exact ⟨hb₁, hb⟩
rw [totalDegree_eq, hb₂, totalDegree_eq]
exact Finset.le_sup (f := fun m => Multiset.card (Finsupp.toMultiset m)) hbb
theorem totalDegree_add_eq_right_of_totalDegree_lt {p q : MvPolynomial σ R}
(h : q.totalDegree < p.totalDegree) : (q + p).totalDegree = p.totalDegree := by
rw [add_comm, totalDegree_add_eq_left_of_totalDegree_lt h]
theorem totalDegree_mul (a b : MvPolynomial σ R) :
(a * b).totalDegree ≤ a.totalDegree + b.totalDegree :=
sup_support_mul_le (by exact (Finsupp.sum_add_index' (fun _ => rfl) (fun _ _ _ => rfl)).le) _ _
theorem totalDegree_smul_le [CommSemiring S] [DistribMulAction R S] (a : R) (f : MvPolynomial σ S) :
(a • f).totalDegree ≤ f.totalDegree :=
Finset.sup_mono support_smul
theorem totalDegree_pow (a : MvPolynomial σ R) (n : ℕ) :
(a ^ n).totalDegree ≤ n * a.totalDegree := by
rw [Finset.pow_eq_prod_const, ← Nat.nsmul_eq_mul, Finset.nsmul_eq_sum_const]
refine supDegree_prod_le rfl (fun _ _ => ?_)
exact Finsupp.sum_add_index' (fun _ => rfl) (fun _ _ _ => rfl)
@[simp]
theorem totalDegree_monomial (s : σ →₀ ℕ) {c : R} (hc : c ≠ 0) :
(monomial s c : MvPolynomial σ R).totalDegree = s.sum fun _ e => e := by
classical simp [totalDegree, support_monomial, if_neg hc]
theorem totalDegree_monomial_le (s : σ →₀ ℕ) (c : R) :
(monomial s c).totalDegree ≤ s.sum fun _ ↦ id := by
if hc : c = 0 then
simp only [hc, map_zero, totalDegree_zero, zero_le]
else
rw [totalDegree_monomial _ hc, Function.id_def]
@[simp]
theorem totalDegree_X_pow [Nontrivial R] (s : σ) (n : ℕ) :
(X s ^ n : MvPolynomial σ R).totalDegree = n := by simp [X_pow_eq_monomial, one_ne_zero]
theorem totalDegree_list_prod :
∀ s : List (MvPolynomial σ R), s.prod.totalDegree ≤ (s.map MvPolynomial.totalDegree).sum
| [] => by rw [List.prod_nil, totalDegree_one, List.map_nil, List.sum_nil]
| p::ps => by
rw [List.prod_cons, List.map, List.sum_cons]
exact le_trans (totalDegree_mul _ _) (add_le_add_left (totalDegree_list_prod ps) _)
theorem totalDegree_multiset_prod (s : Multiset (MvPolynomial σ R)) :
s.prod.totalDegree ≤ (s.map MvPolynomial.totalDegree).sum := by
refine Quotient.inductionOn s fun l => ?_
rw [Multiset.quot_mk_to_coe, Multiset.prod_coe, Multiset.map_coe, Multiset.sum_coe]
exact totalDegree_list_prod l
theorem totalDegree_finset_prod {ι : Type*} (s : Finset ι) (f : ι → MvPolynomial σ R) :
(s.prod f).totalDegree ≤ ∑ i ∈ s, (f i).totalDegree := by
refine le_trans (totalDegree_multiset_prod _) ?_
simp only [Multiset.map_map, comp_apply, Finset.sum_map_val, le_refl]
theorem totalDegree_finset_sum {ι : Type*} (s : Finset ι) (f : ι → MvPolynomial σ R) :
(s.sum f).totalDegree ≤ Finset.sup s fun i => (f i).totalDegree := by
induction' s using Finset.cons_induction with a s has hind
· exact zero_le _
· rw [Finset.sum_cons, Finset.sup_cons, sup_eq_max]
exact (MvPolynomial.totalDegree_add _ _).trans (max_le_max le_rfl hind)
lemma totalDegree_finsetSum_le {ι : Type*} {s : Finset ι} {f : ι → MvPolynomial σ R} {d : ℕ}
(hf : ∀ i ∈ s, (f i).totalDegree ≤ d) : (s.sum f).totalDegree ≤ d :=
(totalDegree_finset_sum ..).trans $ Finset.sup_le hf
lemma degreeOf_le_totalDegree (f : MvPolynomial σ R) (i : σ) : f.degreeOf i ≤ f.totalDegree :=
degreeOf_le_iff.mpr fun d hd ↦ (eq_or_ne (d i) 0).elim (·.trans_le zero_le') fun h ↦
(Finset.single_le_sum (fun _ _ ↦ zero_le') <| Finsupp.mem_support_iff.mpr h).trans
(le_totalDegree hd)
theorem exists_degree_lt [Fintype σ] (f : MvPolynomial σ R) (n : ℕ)
(h : f.totalDegree < n * Fintype.card σ) {d : σ →₀ ℕ} (hd : d ∈ f.support) : ∃ i, d i < n := by
contrapose! h
calc
n * Fintype.card σ = ∑ _s : σ, n := by
rw [Finset.sum_const, Nat.nsmul_eq_mul, mul_comm, Finset.card_univ]
_ ≤ ∑ s, d s := Finset.sum_le_sum fun s _ => h s
_ ≤ d.sum fun _ e => e := by
rw [Finsupp.sum_fintype]
intros
rfl
_ ≤ f.totalDegree := le_totalDegree hd
theorem coeff_eq_zero_of_totalDegree_lt {f : MvPolynomial σ R} {d : σ →₀ ℕ}
(h : f.totalDegree < ∑ i ∈ d.support, d i) : coeff d f = 0 := by
classical
rw [totalDegree, Finset.sup_lt_iff] at h
· specialize h d
rw [mem_support_iff] at h
refine not_not.mp (mt h ?_)
exact lt_irrefl _
· exact lt_of_le_of_lt (Nat.zero_le _) h
theorem totalDegree_rename_le (f : σ → τ) (p : MvPolynomial σ R) :
(rename f p).totalDegree ≤ p.totalDegree :=
Finset.sup_le fun b => by
classical
intro h
rw [rename_eq] at h
have h' := Finsupp.mapDomain_support h
rw [Finset.mem_image] at h'
rcases h' with ⟨s, hs, rfl⟩
exact (sum_mapDomain_index (fun _ => rfl) (fun _ _ _ => rfl)).trans_le (le_totalDegree hs)
end TotalDegree
end CommSemiring
end MvPolynomial
|
Algebra\MvPolynomial\Derivation.lean | /-
Copyright (c) 2021 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov
-/
import Mathlib.Algebra.MvPolynomial.Supported
import Mathlib.RingTheory.Derivation.Basic
/-!
# Derivations of multivariate polynomials
In this file we prove that a derivation of `MvPolynomial σ R` is determined by its values on all
monomials `MvPolynomial.X i`. We also provide a constructor `MvPolynomial.mkDerivation` that
builds a derivation from its values on `X i`s and a linear equivalence
`MvPolynomial.mkDerivationEquiv` between `σ → A` and `Derivation (MvPolynomial σ R) A`.
-/
namespace MvPolynomial
noncomputable section
variable {σ R A : Type*} [CommSemiring R] [AddCommMonoid A] [Module R A]
[Module (MvPolynomial σ R) A]
section
variable (R)
/-- The derivation on `MvPolynomial σ R` that takes value `f i` on `X i`, as a linear map.
Use `MvPolynomial.mkDerivation` instead. -/
def mkDerivationₗ (f : σ → A) : MvPolynomial σ R →ₗ[R] A :=
Finsupp.lsum R fun xs : σ →₀ ℕ =>
(LinearMap.ringLmapEquivSelf R R A).symm <|
xs.sum fun i k => monomial (xs - Finsupp.single i 1) (k : R) • f i
end
theorem mkDerivationₗ_monomial (f : σ → A) (s : σ →₀ ℕ) (r : R) :
mkDerivationₗ R f (monomial s r) =
r • s.sum fun i k => monomial (s - Finsupp.single i 1) (k : R) • f i :=
sum_monomial_eq <| LinearMap.map_zero _
theorem mkDerivationₗ_C (f : σ → A) (r : R) : mkDerivationₗ R f (C r) = 0 :=
(mkDerivationₗ_monomial f _ _).trans (smul_zero _)
theorem mkDerivationₗ_X (f : σ → A) (i : σ) : mkDerivationₗ R f (X i) = f i :=
(mkDerivationₗ_monomial f _ _).trans <| by simp
@[simp]
theorem derivation_C (D : Derivation R (MvPolynomial σ R) A) (a : R) : D (C a) = 0 :=
D.map_algebraMap a
@[simp]
theorem derivation_C_mul (D : Derivation R (MvPolynomial σ R) A) (a : R) (f : MvPolynomial σ R) :
C (σ := σ) a • D f = a • D f := by
have : C (σ := σ) a • D f = D (C a * f) := by simp
rw [this, C_mul', D.map_smul]
/-- If two derivations agree on `X i`, `i ∈ s`, then they agree on all polynomials from
`MvPolynomial.supported R s`. -/
theorem derivation_eqOn_supported {D₁ D₂ : Derivation R (MvPolynomial σ R) A} {s : Set σ}
(h : Set.EqOn (D₁ ∘ X) (D₂ ∘ X) s) {f : MvPolynomial σ R} (hf : f ∈ supported R s) :
D₁ f = D₂ f :=
Derivation.eqOn_adjoin (Set.forall_mem_image.2 h) hf
theorem derivation_eq_of_forall_mem_vars {D₁ D₂ : Derivation R (MvPolynomial σ R) A}
{f : MvPolynomial σ R} (h : ∀ i ∈ f.vars, D₁ (X i) = D₂ (X i)) : D₁ f = D₂ f :=
derivation_eqOn_supported h f.mem_supported_vars
theorem derivation_eq_zero_of_forall_mem_vars {D : Derivation R (MvPolynomial σ R) A}
{f : MvPolynomial σ R} (h : ∀ i ∈ f.vars, D (X i) = 0) : D f = 0 :=
show D f = (0 : Derivation R (MvPolynomial σ R) A) f from derivation_eq_of_forall_mem_vars h
@[ext]
theorem derivation_ext {D₁ D₂ : Derivation R (MvPolynomial σ R) A} (h : ∀ i, D₁ (X i) = D₂ (X i)) :
D₁ = D₂ :=
Derivation.ext fun _ => derivation_eq_of_forall_mem_vars fun i _ => h i
variable [IsScalarTower R (MvPolynomial σ R) A]
theorem leibniz_iff_X (D : MvPolynomial σ R →ₗ[R] A) (h₁ : D 1 = 0) :
(∀ p q, D (p * q) = p • D q + q • D p) ↔ ∀ s i, D (monomial s 1 * X i) =
(monomial s 1 : MvPolynomial σ R) • D (X i) + (X i : MvPolynomial σ R) • D (monomial s 1) := by
refine ⟨fun H p i => H _ _, fun H => ?_⟩
have hC : ∀ r, D (C r) = 0 := by intro r; rw [C_eq_smul_one, D.map_smul, h₁, smul_zero]
have : ∀ p i, D (p * X i) = p • D (X i) + (X i : MvPolynomial σ R) • D p := by
intro p i
induction' p using MvPolynomial.induction_on' with s r p q hp hq
· rw [← mul_one r, ← C_mul_monomial, mul_assoc, C_mul', D.map_smul, H, C_mul', smul_assoc,
smul_add, D.map_smul, smul_comm r (X i)]
· rw [add_mul, map_add, map_add, hp, hq, add_smul, smul_add, add_add_add_comm]
intro p q
induction q using MvPolynomial.induction_on with
| h_C c =>
rw [mul_comm, C_mul', hC, smul_zero, zero_add, D.map_smul, C_eq_smul_one, smul_one_smul]
| h_add q₁ q₂ h₁ h₂ => simp only [mul_add, map_add, h₁, h₂, smul_add, add_smul]; abel
| h_X q i hq =>
simp only [this, ← mul_assoc, hq, mul_smul, smul_add, add_assoc]
rw [smul_comm (X i), smul_comm (X i)]
variable (R)
/-- The derivation on `MvPolynomial σ R` that takes value `f i` on `X i`. -/
def mkDerivation (f : σ → A) : Derivation R (MvPolynomial σ R) A where
toLinearMap := mkDerivationₗ R f
map_one_eq_zero' := mkDerivationₗ_C _ 1
leibniz' :=
(leibniz_iff_X (mkDerivationₗ R f) (mkDerivationₗ_C _ 1)).2 fun s i => by
simp only [mkDerivationₗ_monomial, X, monomial_mul, one_smul, one_mul]
rw [Finsupp.sum_add_index'] <;>
[skip; simp; (intros; simp only [Nat.cast_add, (monomial _).map_add, add_smul])]
rw [Finsupp.sum_single_index, Finsupp.sum_single_index] <;> [skip; simp; simp]
rw [tsub_self, add_tsub_cancel_right, Nat.cast_one, ← C_apply, C_1, one_smul, add_comm,
Finsupp.smul_sum]
refine congr_arg₂ (· + ·) rfl (Finset.sum_congr rfl fun j hj => ?_); dsimp only
rw [smul_smul, monomial_mul, one_mul, add_comm s, add_tsub_assoc_of_le]
rwa [Finsupp.single_le_iff, Nat.succ_le_iff, pos_iff_ne_zero, ← Finsupp.mem_support_iff]
@[simp]
theorem mkDerivation_X (f : σ → A) (i : σ) : mkDerivation R f (X i) = f i :=
mkDerivationₗ_X f i
theorem mkDerivation_monomial (f : σ → A) (s : σ →₀ ℕ) (r : R) :
mkDerivation R f (monomial s r) =
r • s.sum fun i k => monomial (s - Finsupp.single i 1) (k : R) • f i :=
mkDerivationₗ_monomial f s r
/-- `MvPolynomial.mkDerivation` as a linear equivalence. -/
def mkDerivationEquiv : (σ → A) ≃ₗ[R] Derivation R (MvPolynomial σ R) A :=
LinearEquiv.symm <|
{ invFun := mkDerivation R
toFun := fun D i => D (X i)
map_add' := fun _ _ => rfl
map_smul' := fun _ _ => rfl
left_inv := fun _ => derivation_ext <| mkDerivation_X _ _
right_inv := fun _ => funext <| mkDerivation_X _ _ }
end
end MvPolynomial
|
Algebra\MvPolynomial\Division.lean | /-
Copyright (c) 2022 Eric Wieser. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Eric Wieser
-/
import Mathlib.Algebra.MonoidAlgebra.Division
import Mathlib.Algebra.MvPolynomial.Basic
/-!
# Division of `MvPolynomial` by monomials
## Main definitions
* `MvPolynomial.divMonomial x s`: divides `x` by the monomial `MvPolynomial.monomial 1 s`
* `MvPolynomial.modMonomial x s`: the remainder upon dividing `x` by the monomial
`MvPolynomial.monomial 1 s`.
## Main results
* `MvPolynomial.divMonomial_add_modMonomial`, `MvPolynomial.modMonomial_add_divMonomial`:
`divMonomial` and `modMonomial` are well-behaved as quotient and remainder operators.
## Implementation notes
Where possible, the results in this file should be first proved in the generality of
`AddMonoidAlgebra`, and then the versions specialized to `MvPolynomial` proved in terms of these.
-/
variable {σ R : Type*} [CommSemiring R]
namespace MvPolynomial
section CopiedDeclarations
/-! Please ensure the declarations in this section are direct translations of `AddMonoidAlgebra`
results. -/
/-- Divide by `monomial 1 s`, discarding terms not divisible by this. -/
noncomputable def divMonomial (p : MvPolynomial σ R) (s : σ →₀ ℕ) : MvPolynomial σ R :=
AddMonoidAlgebra.divOf p s
local infixl:70 " /ᵐᵒⁿᵒᵐⁱᵃˡ " => divMonomial
@[simp]
theorem coeff_divMonomial (s : σ →₀ ℕ) (x : MvPolynomial σ R) (s' : σ →₀ ℕ) :
coeff s' (x /ᵐᵒⁿᵒᵐⁱᵃˡ s) = coeff (s + s') x :=
rfl
@[simp]
theorem support_divMonomial (s : σ →₀ ℕ) (x : MvPolynomial σ R) :
(x /ᵐᵒⁿᵒᵐⁱᵃˡ s).support = x.support.preimage _ (add_right_injective s).injOn :=
rfl
@[simp]
theorem zero_divMonomial (s : σ →₀ ℕ) : (0 : MvPolynomial σ R) /ᵐᵒⁿᵒᵐⁱᵃˡ s = 0 :=
AddMonoidAlgebra.zero_divOf _
theorem divMonomial_zero (x : MvPolynomial σ R) : x /ᵐᵒⁿᵒᵐⁱᵃˡ 0 = x :=
x.divOf_zero
theorem add_divMonomial (x y : MvPolynomial σ R) (s : σ →₀ ℕ) :
(x + y) /ᵐᵒⁿᵒᵐⁱᵃˡ s = x /ᵐᵒⁿᵒᵐⁱᵃˡ s + y /ᵐᵒⁿᵒᵐⁱᵃˡ s :=
map_add (N := _ →₀ _) _ _ _
theorem divMonomial_add (a b : σ →₀ ℕ) (x : MvPolynomial σ R) :
x /ᵐᵒⁿᵒᵐⁱᵃˡ (a + b) = x /ᵐᵒⁿᵒᵐⁱᵃˡ a /ᵐᵒⁿᵒᵐⁱᵃˡ b :=
x.divOf_add _ _
@[simp]
theorem divMonomial_monomial_mul (a : σ →₀ ℕ) (x : MvPolynomial σ R) :
monomial a 1 * x /ᵐᵒⁿᵒᵐⁱᵃˡ a = x :=
x.of'_mul_divOf _
@[simp]
theorem divMonomial_mul_monomial (a : σ →₀ ℕ) (x : MvPolynomial σ R) :
x * monomial a 1 /ᵐᵒⁿᵒᵐⁱᵃˡ a = x :=
x.mul_of'_divOf _
@[simp]
theorem divMonomial_monomial (a : σ →₀ ℕ) : monomial a 1 /ᵐᵒⁿᵒᵐⁱᵃˡ a = (1 : MvPolynomial σ R) :=
AddMonoidAlgebra.of'_divOf _
/-- The remainder upon division by `monomial 1 s`. -/
noncomputable def modMonomial (x : MvPolynomial σ R) (s : σ →₀ ℕ) : MvPolynomial σ R :=
x.modOf s
local infixl:70 " %ᵐᵒⁿᵒᵐⁱᵃˡ " => modMonomial
@[simp]
theorem coeff_modMonomial_of_not_le {s' s : σ →₀ ℕ} (x : MvPolynomial σ R) (h : ¬s ≤ s') :
coeff s' (x %ᵐᵒⁿᵒᵐⁱᵃˡ s) = coeff s' x :=
x.modOf_apply_of_not_exists_add s s'
(by
rintro ⟨d, rfl⟩
exact h le_self_add)
@[simp]
theorem coeff_modMonomial_of_le {s' s : σ →₀ ℕ} (x : MvPolynomial σ R) (h : s ≤ s') :
coeff s' (x %ᵐᵒⁿᵒᵐⁱᵃˡ s) = 0 :=
x.modOf_apply_of_exists_add _ _ <| exists_add_of_le h
@[simp]
theorem monomial_mul_modMonomial (s : σ →₀ ℕ) (x : MvPolynomial σ R) :
monomial s 1 * x %ᵐᵒⁿᵒᵐⁱᵃˡ s = 0 :=
x.of'_mul_modOf _
@[simp]
theorem mul_monomial_modMonomial (s : σ →₀ ℕ) (x : MvPolynomial σ R) :
x * monomial s 1 %ᵐᵒⁿᵒᵐⁱᵃˡ s = 0 :=
x.mul_of'_modOf _
@[simp]
theorem monomial_modMonomial (s : σ →₀ ℕ) : monomial s (1 : R) %ᵐᵒⁿᵒᵐⁱᵃˡ s = 0 :=
AddMonoidAlgebra.of'_modOf _
theorem divMonomial_add_modMonomial (x : MvPolynomial σ R) (s : σ →₀ ℕ) :
monomial s 1 * (x /ᵐᵒⁿᵒᵐⁱᵃˡ s) + x %ᵐᵒⁿᵒᵐⁱᵃˡ s = x :=
AddMonoidAlgebra.divOf_add_modOf x s
theorem modMonomial_add_divMonomial (x : MvPolynomial σ R) (s : σ →₀ ℕ) :
x %ᵐᵒⁿᵒᵐⁱᵃˡ s + monomial s 1 * (x /ᵐᵒⁿᵒᵐⁱᵃˡ s) = x :=
AddMonoidAlgebra.modOf_add_divOf x s
theorem monomial_one_dvd_iff_modMonomial_eq_zero {i : σ →₀ ℕ} {x : MvPolynomial σ R} :
monomial i (1 : R) ∣ x ↔ x %ᵐᵒⁿᵒᵐⁱᵃˡ i = 0 :=
AddMonoidAlgebra.of'_dvd_iff_modOf_eq_zero
end CopiedDeclarations
section XLemmas
local infixl:70 " /ᵐᵒⁿᵒᵐⁱᵃˡ " => divMonomial
local infixl:70 " %ᵐᵒⁿᵒᵐⁱᵃˡ " => modMonomial
@[simp]
theorem X_mul_divMonomial (i : σ) (x : MvPolynomial σ R) :
X i * x /ᵐᵒⁿᵒᵐⁱᵃˡ Finsupp.single i 1 = x :=
divMonomial_monomial_mul _ _
@[simp]
theorem X_divMonomial (i : σ) : (X i : MvPolynomial σ R) /ᵐᵒⁿᵒᵐⁱᵃˡ Finsupp.single i 1 = 1 :=
divMonomial_monomial (Finsupp.single i 1)
@[simp]
theorem mul_X_divMonomial (x : MvPolynomial σ R) (i : σ) :
x * X i /ᵐᵒⁿᵒᵐⁱᵃˡ Finsupp.single i 1 = x :=
divMonomial_mul_monomial _ _
@[simp]
theorem X_mul_modMonomial (i : σ) (x : MvPolynomial σ R) :
X i * x %ᵐᵒⁿᵒᵐⁱᵃˡ Finsupp.single i 1 = 0 :=
monomial_mul_modMonomial _ _
@[simp]
theorem mul_X_modMonomial (x : MvPolynomial σ R) (i : σ) :
x * X i %ᵐᵒⁿᵒᵐⁱᵃˡ Finsupp.single i 1 = 0 :=
mul_monomial_modMonomial _ _
@[simp]
theorem modMonomial_X (i : σ) : (X i : MvPolynomial σ R) %ᵐᵒⁿᵒᵐⁱᵃˡ Finsupp.single i 1 = 0 :=
monomial_modMonomial _
theorem divMonomial_add_modMonomial_single (x : MvPolynomial σ R) (i : σ) :
X i * (x /ᵐᵒⁿᵒᵐⁱᵃˡ Finsupp.single i 1) + x %ᵐᵒⁿᵒᵐⁱᵃˡ Finsupp.single i 1 = x :=
divMonomial_add_modMonomial _ _
theorem modMonomial_add_divMonomial_single (x : MvPolynomial σ R) (i : σ) :
x %ᵐᵒⁿᵒᵐⁱᵃˡ Finsupp.single i 1 + X i * (x /ᵐᵒⁿᵒᵐⁱᵃˡ Finsupp.single i 1) = x :=
modMonomial_add_divMonomial _ _
theorem X_dvd_iff_modMonomial_eq_zero {i : σ} {x : MvPolynomial σ R} :
X i ∣ x ↔ x %ᵐᵒⁿᵒᵐⁱᵃˡ Finsupp.single i 1 = 0 :=
monomial_one_dvd_iff_modMonomial_eq_zero
end XLemmas
/-! ### Some results about dvd (`∣`) on `monomial` and `X` -/
theorem monomial_dvd_monomial {r s : R} {i j : σ →₀ ℕ} :
monomial i r ∣ monomial j s ↔ (s = 0 ∨ i ≤ j) ∧ r ∣ s := by
constructor
· rintro ⟨x, hx⟩
rw [MvPolynomial.ext_iff] at hx
have hj := hx j
have hi := hx i
classical
simp_rw [coeff_monomial, if_pos] at hj hi
simp_rw [coeff_monomial_mul'] at hi hj
split_ifs at hi hj with hi hi
· exact ⟨Or.inr hi, _, hj⟩
· exact ⟨Or.inl hj, hj.symm ▸ dvd_zero _⟩
-- Porting note: two goals remain at this point in Lean 4
· simp_all only [or_true, dvd_mul_right, and_self]
· simp_all only [ite_self, le_refl, ite_true, dvd_mul_right, or_false, and_self]
· rintro ⟨h | hij, d, rfl⟩
· simp_rw [h, monomial_zero, dvd_zero]
· refine ⟨monomial (j - i) d, ?_⟩
rw [monomial_mul, add_tsub_cancel_of_le hij]
@[simp]
theorem monomial_one_dvd_monomial_one [Nontrivial R] {i j : σ →₀ ℕ} :
monomial i (1 : R) ∣ monomial j 1 ↔ i ≤ j := by
rw [monomial_dvd_monomial]
simp_rw [one_ne_zero, false_or_iff, dvd_rfl, and_true_iff]
@[simp]
theorem X_dvd_X [Nontrivial R] {i j : σ} :
(X i : MvPolynomial σ R) ∣ (X j : MvPolynomial σ R) ↔ i = j := by
refine monomial_one_dvd_monomial_one.trans ?_
simp_rw [Finsupp.single_le_iff, Nat.one_le_iff_ne_zero, Finsupp.single_apply_ne_zero,
ne_eq, not_false_eq_true, and_true]
@[simp]
theorem X_dvd_monomial {i : σ} {j : σ →₀ ℕ} {r : R} :
(X i : MvPolynomial σ R) ∣ monomial j r ↔ r = 0 ∨ j i ≠ 0 := by
refine monomial_dvd_monomial.trans ?_
simp_rw [one_dvd, and_true_iff, Finsupp.single_le_iff, Nat.one_le_iff_ne_zero]
end MvPolynomial
|
Algebra\MvPolynomial\Equiv.lean | /-
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.BigOperators.Fin
import Mathlib.Algebra.MvPolynomial.Rename
import Mathlib.Algebra.MvPolynomial.Degrees
import Mathlib.Algebra.Polynomial.AlgebraMap
import Mathlib.Data.Finsupp.Fin
import Mathlib.Logic.Equiv.Fin
/-!
# Equivalences between polynomial rings
This file establishes a number of equivalences between polynomial rings,
based on equivalences between the underlying types.
## Notation
As in other polynomial files, we typically use the 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`
## Tags
equivalence, isomorphism, morphism, ring hom, hom
-/
noncomputable section
open Polynomial Set Function Finsupp AddMonoidAlgebra
universe u v w x
variable {R : Type u} {S₁ : Type v} {S₂ : Type w} {S₃ : Type x}
namespace MvPolynomial
variable {σ : Type*} {a a' a₁ a₂ : R} {e : ℕ} {s : σ →₀ ℕ}
section Equiv
variable (R) [CommSemiring R]
/-- The ring isomorphism between multivariable polynomials in a single variable and
polynomials over the ground ring.
-/
@[simps]
def pUnitAlgEquiv : MvPolynomial PUnit R ≃ₐ[R] R[X] where
toFun := eval₂ Polynomial.C fun _ => Polynomial.X
invFun := Polynomial.eval₂ MvPolynomial.C (X PUnit.unit)
left_inv := by
let f : R[X] →+* MvPolynomial PUnit R := Polynomial.eval₂RingHom MvPolynomial.C (X PUnit.unit)
let g : MvPolynomial PUnit R →+* R[X] := eval₂Hom Polynomial.C fun _ => Polynomial.X
show ∀ p, f.comp g p = p
apply is_id
· ext a
dsimp [f, g]
rw [eval₂_C, Polynomial.eval₂_C]
· rintro ⟨⟩
dsimp [f, g]
rw [eval₂_X, Polynomial.eval₂_X]
right_inv p :=
Polynomial.induction_on p (fun a => by rw [Polynomial.eval₂_C, MvPolynomial.eval₂_C])
(fun p q hp hq => by rw [Polynomial.eval₂_add, MvPolynomial.eval₂_add, hp, hq]) fun p n _ => by
rw [Polynomial.eval₂_mul, Polynomial.eval₂_pow, Polynomial.eval₂_X, Polynomial.eval₂_C,
eval₂_mul, eval₂_C, eval₂_pow, eval₂_X]
map_mul' _ _ := eval₂_mul _ _
map_add' _ _ := eval₂_add _ _
commutes' _ := eval₂_C _ _ _
section Map
variable {R} (σ)
/-- If `e : A ≃+* B` is an isomorphism of rings, then so is `map e`. -/
@[simps apply]
def mapEquiv [CommSemiring S₁] [CommSemiring S₂] (e : S₁ ≃+* S₂) :
MvPolynomial σ S₁ ≃+* MvPolynomial σ S₂ :=
{ map (e : S₁ →+* S₂) with
toFun := map (e : S₁ →+* S₂)
invFun := map (e.symm : S₂ →+* S₁)
left_inv := map_leftInverse e.left_inv
right_inv := map_rightInverse e.right_inv }
@[simp]
theorem mapEquiv_refl : mapEquiv σ (RingEquiv.refl R) = RingEquiv.refl _ :=
RingEquiv.ext map_id
@[simp]
theorem mapEquiv_symm [CommSemiring S₁] [CommSemiring S₂] (e : S₁ ≃+* S₂) :
(mapEquiv σ e).symm = mapEquiv σ e.symm :=
rfl
@[simp]
theorem mapEquiv_trans [CommSemiring S₁] [CommSemiring S₂] [CommSemiring S₃] (e : S₁ ≃+* S₂)
(f : S₂ ≃+* S₃) : (mapEquiv σ e).trans (mapEquiv σ f) = mapEquiv σ (e.trans f) :=
RingEquiv.ext fun p => by
simp only [RingEquiv.coe_trans, comp_apply, mapEquiv_apply, RingEquiv.coe_ringHom_trans,
map_map]
variable {A₁ A₂ A₃ : Type*} [CommSemiring A₁] [CommSemiring A₂] [CommSemiring A₃]
variable [Algebra R A₁] [Algebra R A₂] [Algebra R A₃]
/-- If `e : A ≃ₐ[R] B` is an isomorphism of `R`-algebras, then so is `map e`. -/
@[simps apply]
def mapAlgEquiv (e : A₁ ≃ₐ[R] A₂) : MvPolynomial σ A₁ ≃ₐ[R] MvPolynomial σ A₂ :=
{ mapAlgHom (e : A₁ →ₐ[R] A₂), mapEquiv σ (e : A₁ ≃+* A₂) with toFun := map (e : A₁ →+* A₂) }
@[simp]
theorem mapAlgEquiv_refl : mapAlgEquiv σ (AlgEquiv.refl : A₁ ≃ₐ[R] A₁) = AlgEquiv.refl :=
AlgEquiv.ext map_id
@[simp]
theorem mapAlgEquiv_symm (e : A₁ ≃ₐ[R] A₂) : (mapAlgEquiv σ e).symm = mapAlgEquiv σ e.symm :=
rfl
@[simp]
theorem mapAlgEquiv_trans (e : A₁ ≃ₐ[R] A₂) (f : A₂ ≃ₐ[R] A₃) :
(mapAlgEquiv σ e).trans (mapAlgEquiv σ f) = mapAlgEquiv σ (e.trans f) := by
ext
simp only [AlgEquiv.trans_apply, mapAlgEquiv_apply, map_map]
rfl
end Map
section
variable (S₁ S₂ S₃)
/-- The function from multivariable polynomials in a sum of two types,
to multivariable polynomials in one of the types,
with coefficients in multivariable polynomials in the other type.
See `sumRingEquiv` for the ring isomorphism.
-/
def sumToIter : MvPolynomial (S₁ ⊕ S₂) R →+* MvPolynomial S₁ (MvPolynomial S₂ R) :=
eval₂Hom (C.comp C) fun bc => Sum.recOn bc X (C ∘ X)
@[simp]
theorem sumToIter_C (a : R) : sumToIter R S₁ S₂ (C a) = C (C a) :=
eval₂_C _ _ a
@[simp]
theorem sumToIter_Xl (b : S₁) : sumToIter R S₁ S₂ (X (Sum.inl b)) = X b :=
eval₂_X _ _ (Sum.inl b)
@[simp]
theorem sumToIter_Xr (c : S₂) : sumToIter R S₁ S₂ (X (Sum.inr c)) = C (X c) :=
eval₂_X _ _ (Sum.inr c)
/-- The function from multivariable polynomials in one type,
with coefficients in multivariable polynomials in another type,
to multivariable polynomials in the sum of the two types.
See `sumRingEquiv` for the ring isomorphism.
-/
def iterToSum : MvPolynomial S₁ (MvPolynomial S₂ R) →+* MvPolynomial (S₁ ⊕ S₂) R :=
eval₂Hom (eval₂Hom C (X ∘ Sum.inr)) (X ∘ Sum.inl)
@[simp]
theorem iterToSum_C_C (a : R) : iterToSum R S₁ S₂ (C (C a)) = C a :=
Eq.trans (eval₂_C _ _ (C a)) (eval₂_C _ _ _)
@[simp]
theorem iterToSum_X (b : S₁) : iterToSum R S₁ S₂ (X b) = X (Sum.inl b) :=
eval₂_X _ _ _
@[simp]
theorem iterToSum_C_X (c : S₂) : iterToSum R S₁ S₂ (C (X c)) = X (Sum.inr c) :=
Eq.trans (eval₂_C _ _ (X c)) (eval₂_X _ _ _)
variable (σ)
/-- The algebra isomorphism between multivariable polynomials in no variables
and the ground ring. -/
@[simps!]
def isEmptyAlgEquiv [he : IsEmpty σ] : MvPolynomial σ R ≃ₐ[R] R :=
AlgEquiv.ofAlgHom (aeval (IsEmpty.elim he)) (Algebra.ofId _ _)
(by ext)
(by
ext i m
exact IsEmpty.elim' he i)
/-- The ring isomorphism between multivariable polynomials in no variables
and the ground ring. -/
@[simps!]
def isEmptyRingEquiv [IsEmpty σ] : MvPolynomial σ R ≃+* R :=
(isEmptyAlgEquiv R σ).toRingEquiv
variable {σ}
/-- A helper function for `sumRingEquiv`. -/
@[simps]
def mvPolynomialEquivMvPolynomial [CommSemiring S₃] (f : MvPolynomial S₁ R →+* MvPolynomial S₂ S₃)
(g : MvPolynomial S₂ S₃ →+* MvPolynomial S₁ R) (hfgC : (f.comp g).comp C = C)
(hfgX : ∀ n, f (g (X n)) = X n) (hgfC : (g.comp f).comp C = C) (hgfX : ∀ n, g (f (X n)) = X n) :
MvPolynomial S₁ R ≃+* MvPolynomial S₂ S₃ where
toFun := f
invFun := g
left_inv := is_id (RingHom.comp _ _) hgfC hgfX
right_inv := is_id (RingHom.comp _ _) hfgC hfgX
map_mul' := f.map_mul
map_add' := f.map_add
/-- The ring isomorphism between multivariable polynomials in a sum of two types,
and multivariable polynomials in one of the types,
with coefficients in multivariable polynomials in the other type.
-/
def sumRingEquiv : MvPolynomial (S₁ ⊕ S₂) R ≃+* MvPolynomial S₁ (MvPolynomial S₂ R) := by
apply mvPolynomialEquivMvPolynomial R (S₁ ⊕ S₂) _ _ (sumToIter R S₁ S₂) (iterToSum R S₁ S₂)
· refine RingHom.ext (hom_eq_hom _ _ ?hC ?hX)
case hC => ext1; simp only [RingHom.comp_apply, iterToSum_C_C, sumToIter_C]
case hX => intro; simp only [RingHom.comp_apply, iterToSum_C_X, sumToIter_Xr]
· simp [iterToSum_X, sumToIter_Xl]
· ext1; simp only [RingHom.comp_apply, sumToIter_C, iterToSum_C_C]
· rintro ⟨⟩ <;> simp only [sumToIter_Xl, iterToSum_X, sumToIter_Xr, iterToSum_C_X]
/-- The algebra isomorphism between multivariable polynomials in a sum of two types,
and multivariable polynomials in one of the types,
with coefficients in multivariable polynomials in the other type.
-/
@[simps!]
def sumAlgEquiv : MvPolynomial (S₁ ⊕ S₂) R ≃ₐ[R] MvPolynomial S₁ (MvPolynomial S₂ R) :=
{ sumRingEquiv R S₁ S₂ with
commutes' := by
intro r
have A : algebraMap R (MvPolynomial S₁ (MvPolynomial S₂ R)) r = (C (C r) : _) := rfl
have B : algebraMap R (MvPolynomial (S₁ ⊕ S₂) R) r = C r := rfl
simp only [sumRingEquiv, mvPolynomialEquivMvPolynomial, Equiv.toFun_as_coe,
Equiv.coe_fn_mk, B, sumToIter_C, A] }
section
-- this speeds up typeclass search in the lemma below
attribute [local instance] IsScalarTower.right
/-- The algebra isomorphism between multivariable polynomials in `Option S₁` and
polynomials with coefficients in `MvPolynomial S₁ R`.
-/
@[simps!]
def optionEquivLeft : MvPolynomial (Option S₁) R ≃ₐ[R] Polynomial (MvPolynomial S₁ R) :=
AlgEquiv.ofAlgHom (MvPolynomial.aeval fun o => o.elim Polynomial.X fun s => Polynomial.C (X s))
(Polynomial.aevalTower (MvPolynomial.rename some) (X none))
(by ext : 2 <;> simp) (by ext i : 2; cases i <;> simp)
lemma optionEquivLeft_X_some (x : S₁) : optionEquivLeft R S₁ (X (some x)) = Polynomial.C (X x) := by
simp [optionEquivLeft_apply, aeval_X]
lemma optionEquivLeft_X_none : optionEquivLeft R S₁ (X none) = Polynomial.X := by
simp [optionEquivLeft_apply, aeval_X]
lemma optionEquivLeft_C (r : R) : optionEquivLeft R S₁ (C r) = Polynomial.C (C r) := by
simp only [optionEquivLeft_apply, aeval_C, Polynomial.algebraMap_apply, algebraMap_eq]
end
/-- The algebra isomorphism between multivariable polynomials in `Option S₁` and
multivariable polynomials with coefficients in polynomials.
-/
@[simps!]
def optionEquivRight : MvPolynomial (Option S₁) R ≃ₐ[R] MvPolynomial S₁ R[X] :=
AlgEquiv.ofAlgHom (MvPolynomial.aeval fun o => o.elim (C Polynomial.X) X)
(MvPolynomial.aevalTower (Polynomial.aeval (X none)) fun i => X (Option.some i))
(by
ext : 2 <;>
simp only [MvPolynomial.algebraMap_eq, Option.elim, AlgHom.coe_comp, AlgHom.id_comp,
IsScalarTower.coe_toAlgHom', comp_apply, aevalTower_C, Polynomial.aeval_X, aeval_X,
Option.elim', aevalTower_X, AlgHom.coe_id, id, eq_self_iff_true, imp_true_iff])
(by
ext ⟨i⟩ : 2 <;>
simp only [Option.elim, AlgHom.coe_comp, comp_apply, aeval_X, aevalTower_C,
Polynomial.aeval_X, AlgHom.coe_id, id, aevalTower_X])
lemma optionEquivRight_X_some (x : S₁) : optionEquivRight R S₁ (X (some x)) = X x := by
simp [optionEquivRight_apply, aeval_X]
lemma optionEquivRight_X_none : optionEquivRight R S₁ (X none) = C Polynomial.X := by
simp [optionEquivRight_apply, aeval_X]
lemma optionEquivRight_C (r : R) : optionEquivRight R S₁ (C r) = C (Polynomial.C r) := by
simp only [optionEquivRight_apply, aeval_C, algebraMap_apply, Polynomial.algebraMap_eq]
variable (n : ℕ)
/-- The algebra isomorphism between multivariable polynomials in `Fin (n + 1)` and
polynomials over multivariable polynomials in `Fin n`.
-/
def finSuccEquiv : MvPolynomial (Fin (n + 1)) R ≃ₐ[R] Polynomial (MvPolynomial (Fin n) R) :=
(renameEquiv R (_root_.finSuccEquiv n)).trans (optionEquivLeft R (Fin n))
theorem finSuccEquiv_eq :
(finSuccEquiv R n : MvPolynomial (Fin (n + 1)) R →+* Polynomial (MvPolynomial (Fin n) R)) =
eval₂Hom (Polynomial.C.comp (C : R →+* MvPolynomial (Fin n) R)) fun i : Fin (n + 1) =>
Fin.cases Polynomial.X (fun k => Polynomial.C (X k)) i := by
ext i : 2
· simp only [finSuccEquiv, optionEquivLeft_apply, aeval_C, AlgEquiv.coe_trans, RingHom.coe_coe,
coe_eval₂Hom, comp_apply, renameEquiv_apply, eval₂_C, RingHom.coe_comp, rename_C]
rfl
· refine Fin.cases ?_ ?_ i <;> simp [finSuccEquiv]
@[simp]
theorem finSuccEquiv_apply (p : MvPolynomial (Fin (n + 1)) R) :
finSuccEquiv R n p =
eval₂Hom (Polynomial.C.comp (C : R →+* MvPolynomial (Fin n) R))
(fun i : Fin (n + 1) => Fin.cases Polynomial.X (fun k => Polynomial.C (X k)) i) p := by
rw [← finSuccEquiv_eq, RingHom.coe_coe]
theorem finSuccEquiv_comp_C_eq_C {R : Type u} [CommSemiring R] (n : ℕ) :
(↑(MvPolynomial.finSuccEquiv R n).symm : Polynomial (MvPolynomial (Fin n) R) →+* _).comp
(Polynomial.C.comp MvPolynomial.C) =
(MvPolynomial.C : R →+* MvPolynomial (Fin n.succ) R) := by
refine RingHom.ext fun x => ?_
rw [RingHom.comp_apply]
refine
(MvPolynomial.finSuccEquiv R n).injective
(Trans.trans ((MvPolynomial.finSuccEquiv R n).apply_symm_apply _) ?_)
simp only [MvPolynomial.finSuccEquiv_apply, MvPolynomial.eval₂Hom_C]
variable {n} {R}
theorem finSuccEquiv_X_zero : finSuccEquiv R n (X 0) = Polynomial.X := by simp
theorem finSuccEquiv_X_succ {j : Fin n} : finSuccEquiv R n (X j.succ) = Polynomial.C (X j) := by
simp
/-- The coefficient of `m` in the `i`-th coefficient of `finSuccEquiv R n f` equals the
coefficient of `Finsupp.cons i m` in `f`. -/
theorem finSuccEquiv_coeff_coeff (m : Fin n →₀ ℕ) (f : MvPolynomial (Fin (n + 1)) R) (i : ℕ) :
coeff m (Polynomial.coeff (finSuccEquiv R n f) i) = coeff (m.cons i) f := by
induction' f using MvPolynomial.induction_on' with j r p q hp hq generalizing i m
swap
· simp only [map_add, Polynomial.coeff_add, coeff_add, hp, hq]
simp only [finSuccEquiv_apply, coe_eval₂Hom, eval₂_monomial, RingHom.coe_comp, prod_pow,
Polynomial.coeff_C_mul, coeff_C_mul, coeff_monomial, Fin.prod_univ_succ, Fin.cases_zero,
Fin.cases_succ, ← map_prod, ← RingHom.map_pow, Function.comp_apply]
rw [← mul_boole, mul_comm (Polynomial.X ^ j 0), Polynomial.coeff_C_mul_X_pow]; congr 1
obtain rfl | hjmi := eq_or_ne j (m.cons i)
· simpa only [cons_zero, cons_succ, if_pos rfl, monomial_eq, C_1, one_mul, prod_pow] using
coeff_monomial m m (1 : R)
· simp only [hjmi, if_false]
obtain hij | rfl := ne_or_eq i (j 0)
· simp only [hij, if_false, coeff_zero]
simp only [eq_self_iff_true, if_true]
have hmj : m ≠ j.tail := by
rintro rfl
rw [cons_tail] at hjmi
contradiction
simpa only [monomial_eq, C_1, one_mul, prod_pow, Finsupp.tail_apply, if_neg hmj.symm] using
coeff_monomial m j.tail (1 : R)
theorem eval_eq_eval_mv_eval' (s : Fin n → R) (y : R) (f : MvPolynomial (Fin (n + 1)) R) :
eval (Fin.cons y s : Fin (n + 1) → R) f =
Polynomial.eval y (Polynomial.map (eval s) (finSuccEquiv R n f)) := by
-- turn this into a def `Polynomial.mapAlgHom`
let φ : (MvPolynomial (Fin n) R)[X] →ₐ[R] R[X] :=
{ Polynomial.mapRingHom (eval s) with
commutes' := fun r => by
convert Polynomial.map_C (eval s)
exact (eval_C _).symm }
show
aeval (Fin.cons y s : Fin (n + 1) → R) f =
(Polynomial.aeval y).comp (φ.comp (finSuccEquiv R n).toAlgHom) f
congr 2
apply MvPolynomial.algHom_ext
rw [Fin.forall_fin_succ]
simp only [φ, aeval_X, Fin.cons_zero, AlgEquiv.toAlgHom_eq_coe, AlgHom.coe_comp,
Polynomial.coe_aeval_eq_eval, Polynomial.map_C, AlgHom.coe_mk, RingHom.toFun_eq_coe,
Polynomial.coe_mapRingHom, comp_apply, finSuccEquiv_apply, eval₂Hom_X',
Fin.cases_zero, Polynomial.map_X, Polynomial.eval_X, Fin.cons_succ,
Fin.cases_succ, eval_X, Polynomial.eval_C,
RingHom.coe_mk, MonoidHom.coe_coe, AlgHom.coe_coe, implies_true, and_self,
RingHom.toMonoidHom_eq_coe]
theorem coeff_eval_eq_eval_coeff (s' : Fin n → R) (f : Polynomial (MvPolynomial (Fin n) R))
(i : ℕ) : Polynomial.coeff (Polynomial.map (eval s') f) i = eval s' (Polynomial.coeff f i) := by
simp only [Polynomial.coeff_map]
theorem support_coeff_finSuccEquiv {f : MvPolynomial (Fin (n + 1)) R} {i : ℕ} {m : Fin n →₀ ℕ} :
m ∈ (Polynomial.coeff ((finSuccEquiv R n) f) i).support ↔ Finsupp.cons i m ∈ f.support := by
apply Iff.intro
· intro h
simpa [← finSuccEquiv_coeff_coeff] using h
· intro h
simpa [mem_support_iff, ← finSuccEquiv_coeff_coeff m f i] using h
/--
The `totalDegree` of a multivariable polynomial `p` is at least `i` more than the `totalDegree` of
the `i`th coefficient of `finSuccEquiv` applied to `p`, if this is nonzero.
-/
lemma totalDegree_coeff_finSuccEquiv_add_le (f : MvPolynomial (Fin (n + 1)) R) (i : ℕ)
(hi : (finSuccEquiv R n f).coeff i ≠ 0) :
totalDegree ((finSuccEquiv R n f).coeff i) + i ≤ totalDegree f := by
have hf'_sup : ((finSuccEquiv R n f).coeff i).support.Nonempty := by
rw [Finset.nonempty_iff_ne_empty, ne_eq, support_eq_empty]
exact hi
-- Let σ be a monomial index of ((finSuccEquiv R n p).coeff i) of maximal total degree
have ⟨σ, hσ1, hσ2⟩ := Finset.exists_mem_eq_sup (support _) hf'_sup
(fun s => Finsupp.sum s fun _ e => e)
-- Then cons i σ is a monomial index of p with total degree equal to the desired bound
let σ' : Fin (n+1) →₀ ℕ := cons i σ
convert le_totalDegree (s := σ') _
· rw [totalDegree, hσ2, sum_cons, add_comm]
· rw [← support_coeff_finSuccEquiv]
exact hσ1
theorem finSuccEquiv_support (f : MvPolynomial (Fin (n + 1)) R) :
(finSuccEquiv R n f).support = Finset.image (fun m : Fin (n + 1) →₀ ℕ => m 0) f.support := by
ext i
rw [Polynomial.mem_support_iff, Finset.mem_image, Finsupp.ne_iff]
constructor
· rintro ⟨m, hm⟩
refine ⟨cons i m, ?_, cons_zero _ _⟩
rw [← support_coeff_finSuccEquiv]
simpa using hm
· rintro ⟨m, h, rfl⟩
refine ⟨tail m, ?_⟩
rwa [← coeff, zero_apply, ← mem_support_iff, support_coeff_finSuccEquiv, cons_tail]
theorem finSuccEquiv_support' {f : MvPolynomial (Fin (n + 1)) R} {i : ℕ} :
Finset.image (Finsupp.cons i) (Polynomial.coeff ((finSuccEquiv R n) f) i).support =
f.support.filter fun m => m 0 = i := by
ext m
rw [Finset.mem_filter, Finset.mem_image, mem_support_iff]
conv_lhs =>
congr
ext
rw [mem_support_iff, finSuccEquiv_coeff_coeff, Ne]
constructor
· rintro ⟨m', ⟨h, hm'⟩⟩
simp only [← hm']
exact ⟨h, by rw [cons_zero]⟩
· intro h
use tail m
rw [← h.2, cons_tail]
simp [h.1]
-- TODO: generalize `finSuccEquiv R n` to an arbitrary ZeroHom
theorem support_finSuccEquiv_nonempty {f : MvPolynomial (Fin (n + 1)) R} (h : f ≠ 0) :
(finSuccEquiv R n f).support.Nonempty := by
rwa [Polynomial.support_nonempty, AddEquivClass.map_ne_zero_iff]
theorem degree_finSuccEquiv {f : MvPolynomial (Fin (n + 1)) R} (h : f ≠ 0) :
(finSuccEquiv R n f).degree = degreeOf 0 f := by
-- TODO: these should be lemmas
have h₀ : ∀ {α β : Type _} (f : α → β), (fun x => x) ∘ f = f := fun f => rfl
have h₁ : ∀ {α β : Type _} (f : α → β), f ∘ (fun x => x) = f := fun f => rfl
have h₂ : WithBot.some = Nat.cast := rfl
have h' : ((finSuccEquiv R n f).support.sup fun x => x) = degreeOf 0 f := by
rw [degreeOf_eq_sup, finSuccEquiv_support f, Finset.sup_image, h₀]
rw [Polynomial.degree, ← h', ← h₂, Finset.coe_sup_of_nonempty (support_finSuccEquiv_nonempty h),
Finset.max_eq_sup_coe, h₁]
theorem natDegree_finSuccEquiv (f : MvPolynomial (Fin (n + 1)) R) :
(finSuccEquiv R n f).natDegree = degreeOf 0 f := by
by_cases c : f = 0
· rw [c, map_zero, Polynomial.natDegree_zero, degreeOf_zero]
· rw [Polynomial.natDegree, degree_finSuccEquiv (by simpa only [Ne] )]
erw [WithBot.unbot'_coe]
simp
theorem degreeOf_coeff_finSuccEquiv (p : MvPolynomial (Fin (n + 1)) R) (j : Fin n) (i : ℕ) :
degreeOf j (Polynomial.coeff (finSuccEquiv R n p) i) ≤ degreeOf j.succ p := by
rw [degreeOf_eq_sup, degreeOf_eq_sup, Finset.sup_le_iff]
intro m hm
rw [← Finsupp.cons_succ j i m]
exact Finset.le_sup
(f := fun (g : Fin (Nat.succ n) →₀ ℕ) => g (Fin.succ j))
(support_coeff_finSuccEquiv.1 hm)
/-- Consider a multivariate polynomial `φ` whose variables are indexed by `Option σ`,
and suppose that `σ ≃ Fin n`.
Then one may view `φ` as a polynomial over `MvPolynomial (Fin n) R`, by
1. renaming the variables via `Option σ ≃ Fin (n+1)`, and then singling out the `0`-th variable
via `MvPolynomial.finSuccEquiv`;
2. first viewing it as polynomial over `MvPolynomial σ R` via `MvPolynomial.optionEquivLeft`,
and then renaming the variables.
This lemma shows that both constructions are the same. -/
lemma finSuccEquiv_rename_finSuccEquiv (e : σ ≃ Fin n) (φ : MvPolynomial (Option σ) R) :
((finSuccEquiv R n) ((rename ((Equiv.optionCongr e).trans (_root_.finSuccEquiv n).symm)) φ)) =
Polynomial.map (rename e).toRingHom (optionEquivLeft R σ φ) := by
suffices (finSuccEquiv R n).toRingEquiv.toRingHom.comp (rename ((Equiv.optionCongr e).trans
(_root_.finSuccEquiv n).symm)).toRingHom =
(Polynomial.mapRingHom (rename e).toRingHom).comp (optionEquivLeft R σ) by
exact DFunLike.congr_fun this φ
apply ringHom_ext
· simp [Polynomial.algebraMap_apply, algebraMap_eq]
· rintro (i|i) <;> simp
end
end Equiv
end MvPolynomial
|
Algebra\MvPolynomial\Expand.lean | /-
Copyright (c) 2020 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin, Robert Y. Lewis
-/
import Mathlib.Algebra.MvPolynomial.Monad
/-!
## Expand multivariate polynomials
Given a multivariate polynomial `φ`, one may replace every occurrence of `X i` by `X i ^ n`,
for some natural number `n`.
This operation is called `MvPolynomial.expand` and it is an algebra homomorphism.
### Main declaration
* `MvPolynomial.expand`: expand a polynomial by a factor of p, so `∑ aₙ xⁿ` becomes `∑ aₙ xⁿᵖ`.
-/
namespace MvPolynomial
variable {σ τ R S : Type*} [CommSemiring R] [CommSemiring S]
/-- Expand the polynomial by a factor of p, so `∑ aₙ xⁿ` becomes `∑ aₙ xⁿᵖ`.
See also `Polynomial.expand`. -/
noncomputable def expand (p : ℕ) : MvPolynomial σ R →ₐ[R] MvPolynomial σ R :=
{ (eval₂Hom C fun i ↦ X i ^ p : MvPolynomial σ R →+* MvPolynomial σ R) with
commutes' := fun _ ↦ eval₂Hom_C _ _ _ }
-- @[simp] -- Porting note (#10618): simp can prove this
theorem expand_C (p : ℕ) (r : R) : expand p (C r : MvPolynomial σ R) = C r :=
eval₂Hom_C _ _ _
@[simp]
theorem expand_X (p : ℕ) (i : σ) : expand p (X i : MvPolynomial σ R) = X i ^ p :=
eval₂Hom_X' _ _ _
@[simp]
theorem expand_monomial (p : ℕ) (d : σ →₀ ℕ) (r : R) :
expand p (monomial d r) = C r * ∏ i ∈ d.support, (X i ^ p) ^ d i :=
bind₁_monomial _ _ _
theorem expand_one_apply (f : MvPolynomial σ R) : expand 1 f = f := by
simp only [expand, pow_one, eval₂Hom_eq_bind₂, bind₂_C_left, RingHom.toMonoidHom_eq_coe,
RingHom.coe_monoidHom_id, AlgHom.coe_mk, RingHom.coe_mk, MonoidHom.id_apply, RingHom.id_apply]
@[simp]
theorem expand_one : expand 1 = AlgHom.id R (MvPolynomial σ R) := by
ext1 f
rw [expand_one_apply, AlgHom.id_apply]
theorem expand_comp_bind₁ (p : ℕ) (f : σ → MvPolynomial τ R) :
(expand p).comp (bind₁ f) = bind₁ fun i ↦ expand p (f i) := by
apply algHom_ext
intro i
simp only [AlgHom.comp_apply, bind₁_X_right]
theorem expand_bind₁ (p : ℕ) (f : σ → MvPolynomial τ R) (φ : MvPolynomial σ R) :
expand p (bind₁ f φ) = bind₁ (fun i ↦ expand p (f i)) φ := by
rw [← AlgHom.comp_apply, expand_comp_bind₁]
@[simp]
theorem map_expand (f : R →+* S) (p : ℕ) (φ : MvPolynomial σ R) :
map f (expand p φ) = expand p (map f φ) := by simp [expand, map_bind₁]
@[simp]
theorem rename_expand (f : σ → τ) (p : ℕ) (φ : MvPolynomial σ R) :
rename f (expand p φ) = expand p (rename f φ) := by
simp [expand, bind₁_rename, rename_bind₁, Function.comp]
@[simp]
theorem rename_comp_expand (f : σ → τ) (p : ℕ) :
(rename f).comp (expand p) =
(expand p).comp (rename f : MvPolynomial σ R →ₐ[R] MvPolynomial τ R) := by
ext1 φ
simp only [rename_expand, AlgHom.comp_apply]
end MvPolynomial
|
Algebra\MvPolynomial\Funext.lean | /-
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.Polynomial.RingDivision
import Mathlib.Algebra.MvPolynomial.Polynomial
import Mathlib.Algebra.MvPolynomial.Rename
import Mathlib.RingTheory.Polynomial.Basic
/-!
## Function extensionality for multivariate polynomials
In this file we show that two multivariate polynomials over an infinite integral domain are equal
if they are equal upon evaluating them on an arbitrary assignment of the variables.
# Main declaration
* `MvPolynomial.funext`: two polynomials `φ ψ : MvPolynomial σ R`
over an infinite integral domain `R` are equal if `eval x φ = eval x ψ` for all `x : σ → R`.
-/
namespace MvPolynomial
variable {R : Type*} [CommRing R] [IsDomain R] [Infinite R]
private theorem funext_fin {n : ℕ} {p : MvPolynomial (Fin n) R}
(h : ∀ x : Fin n → R, eval x p = 0) : p = 0 := by
induction' n with n ih
· apply (MvPolynomial.isEmptyRingEquiv R (Fin 0)).injective
rw [RingEquiv.map_zero]
convert h finZeroElim
· apply (finSuccEquiv R n).injective
simp only [map_zero]
refine Polynomial.funext fun q => ?_
rw [Polynomial.eval_zero]
apply ih fun x => ?_
calc _ = _ := eval_polynomial_eval_finSuccEquiv p _
_ = 0 := h _
/-- Two multivariate polynomials over an infinite integral domain are equal
if they are equal upon evaluating them on an arbitrary assignment of the variables. -/
theorem funext {σ : Type*} {p q : MvPolynomial σ R} (h : ∀ x : σ → R, eval x p = eval x q) :
p = q := by
suffices ∀ p, (∀ x : σ → R, eval x p = 0) → p = 0 by
rw [← sub_eq_zero, this (p - q)]
simp only [h, RingHom.map_sub, forall_const, sub_self]
clear h p q
intro p h
obtain ⟨n, f, hf, p, rfl⟩ := exists_fin_rename p
suffices p = 0 by rw [this, map_zero]
apply funext_fin
intro x
classical
convert h (Function.extend f x 0)
simp only [eval, eval₂Hom_rename, Function.extend_comp hf]
theorem funext_iff {σ : Type*} {p q : MvPolynomial σ R} :
p = q ↔ ∀ x : σ → R, eval x p = eval x q :=
⟨by rintro rfl; simp only [forall_const, eq_self_iff_true], funext⟩
end MvPolynomial
|
Algebra\MvPolynomial\Invertible.lean | /-
Copyright (c) 2020 Johan Commelin, Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin, Robert Y. Lewis
-/
import Mathlib.Algebra.MvPolynomial.Basic
import Mathlib.RingTheory.AlgebraTower
/-!
# Invertible polynomials
This file is a stub containing some basic facts about
invertible elements in the ring of polynomials.
-/
open MvPolynomial
noncomputable instance MvPolynomial.invertibleC (σ : Type*) {R : Type*} [CommSemiring R] (r : R)
[Invertible r] : Invertible (C r : MvPolynomial σ R) :=
Invertible.map (C : R →+* MvPolynomial σ R) _
/-- A natural number that is invertible when coerced to a commutative semiring `R`
is also invertible when coerced to any polynomial ring with rational coefficients.
Short-cut for typeclass resolution. -/
noncomputable instance MvPolynomial.invertibleCoeNat (σ R : Type*) (p : ℕ) [CommSemiring R]
[Invertible (p : R)] : Invertible (p : MvPolynomial σ R) :=
IsScalarTower.invertibleAlgebraCoeNat R _ _
|
Algebra\MvPolynomial\Monad.lean | /-
Copyright (c) 2020 Johan Commelin, Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin, Robert Y. Lewis
-/
import Mathlib.Algebra.MvPolynomial.Rename
import Mathlib.Algebra.MvPolynomial.Variables
/-!
# Monad operations on `MvPolynomial`
This file defines two monadic operations on `MvPolynomial`. Given `p : MvPolynomial σ R`,
* `MvPolynomial.bind₁` and `MvPolynomial.join₁` operate on the variable type `σ`.
* `MvPolynomial.bind₂` and `MvPolynomial.join₂` operate on the coefficient type `R`.
- `MvPolynomial.bind₁ f φ` with `f : σ → MvPolynomial τ R` and `φ : MvPolynomial σ R`,
is the polynomial `φ(f 1, ..., f i, ...) : MvPolynomial τ R`.
- `MvPolynomial.join₁ φ` with `φ : MvPolynomial (MvPolynomial σ R) R` collapses `φ` to
a `MvPolynomial σ R`, by evaluating `φ` under the map `X f ↦ f` for `f : MvPolynomial σ R`.
In other words, if you have a polynomial `φ` in a set of variables indexed by a polynomial ring,
you evaluate the polynomial in these indexing polynomials.
- `MvPolynomial.bind₂ f φ` with `f : R →+* MvPolynomial σ S` and `φ : MvPolynomial σ R`
is the `MvPolynomial σ S` obtained from `φ` by mapping the coefficients of `φ` through `f`
and considering the resulting polynomial as polynomial expression in `MvPolynomial σ R`.
- `MvPolynomial.join₂ φ` with `φ : MvPolynomial σ (MvPolynomial σ R)` collapses `φ` to
a `MvPolynomial σ R`, by considering `φ` as polynomial expression in `MvPolynomial σ R`.
These operations themselves have algebraic structure: `MvPolynomial.bind₁`
and `MvPolynomial.join₁` are algebra homs and
`MvPolynomial.bind₂` and `MvPolynomial.join₂` are ring homs.
They interact in convenient ways with `MvPolynomial.rename`, `MvPolynomial.map`,
`MvPolynomial.vars`, and other polynomial operations.
Indeed, `MvPolynomial.rename` is the "map" operation for the (`bind₁`, `join₁`) pair,
whereas `MvPolynomial.map` is the "map" operation for the other pair.
## Implementation notes
We add a `LawfulMonad` instance for the (`bind₁`, `join₁`) pair.
The second pair cannot be instantiated as a `Monad`,
since it is not a monad in `Type` but in `CommRingCat` (or rather `CommSemiRingCat`).
-/
noncomputable section
namespace MvPolynomial
open Finsupp
variable {σ : Type*} {τ : Type*}
variable {R S T : Type*} [CommSemiring R] [CommSemiring S] [CommSemiring T]
/--
`bind₁` is the "left hand side" bind operation on `MvPolynomial`, operating on the variable type.
Given a polynomial `p : MvPolynomial σ R` and a map `f : σ → MvPolynomial τ R` taking variables
in `p` to polynomials in the variable type `τ`, `bind₁ f p` replaces each variable in `p` with
its value under `f`, producing a new polynomial in `τ`. The coefficient type remains the same.
This operation is an algebra hom.
-/
def bind₁ (f : σ → MvPolynomial τ R) : MvPolynomial σ R →ₐ[R] MvPolynomial τ R :=
aeval f
/-- `bind₂` is the "right hand side" bind operation on `MvPolynomial`,
operating on the coefficient type.
Given a polynomial `p : MvPolynomial σ R` and
a map `f : R → MvPolynomial σ S` taking coefficients in `p` to polynomials over a new ring `S`,
`bind₂ f p` replaces each coefficient in `p` with its value under `f`,
producing a new polynomial over `S`.
The variable type remains the same. This operation is a ring hom.
-/
def bind₂ (f : R →+* MvPolynomial σ S) : MvPolynomial σ R →+* MvPolynomial σ S :=
eval₂Hom f X
/--
`join₁` is the monadic join operation corresponding to `MvPolynomial.bind₁`. Given a polynomial `p`
with coefficients in `R` whose variables are polynomials in `σ` with coefficients in `R`,
`join₁ p` collapses `p` to a polynomial with variables in `σ` and coefficients in `R`.
This operation is an algebra hom.
-/
def join₁ : MvPolynomial (MvPolynomial σ R) R →ₐ[R] MvPolynomial σ R :=
aeval id
/--
`join₂` is the monadic join operation corresponding to `MvPolynomial.bind₂`. Given a polynomial `p`
with variables in `σ` whose coefficients are polynomials in `σ` with coefficients in `R`,
`join₂ p` collapses `p` to a polynomial with variables in `σ` and coefficients in `R`.
This operation is a ring hom.
-/
def join₂ : MvPolynomial σ (MvPolynomial σ R) →+* MvPolynomial σ R :=
eval₂Hom (RingHom.id _) X
@[simp]
theorem aeval_eq_bind₁ (f : σ → MvPolynomial τ R) : aeval f = bind₁ f :=
rfl
@[simp]
theorem eval₂Hom_C_eq_bind₁ (f : σ → MvPolynomial τ R) : eval₂Hom C f = bind₁ f :=
rfl
@[simp]
theorem eval₂Hom_eq_bind₂ (f : R →+* MvPolynomial σ S) : eval₂Hom f X = bind₂ f :=
rfl
section
variable (σ R)
@[simp]
theorem aeval_id_eq_join₁ : aeval id = @join₁ σ R _ :=
rfl
theorem eval₂Hom_C_id_eq_join₁ (φ : MvPolynomial (MvPolynomial σ R) R) :
eval₂Hom C id φ = join₁ φ :=
rfl
@[simp]
theorem eval₂Hom_id_X_eq_join₂ : eval₂Hom (RingHom.id _) X = @join₂ σ R _ :=
rfl
end
-- In this file, we don't want to use these simp lemmas,
-- because we first need to show how these new definitions interact
-- and the proofs fall back on unfolding the definitions and call simp afterwards
attribute [-simp]
aeval_eq_bind₁ eval₂Hom_C_eq_bind₁ eval₂Hom_eq_bind₂ aeval_id_eq_join₁ eval₂Hom_id_X_eq_join₂
@[simp]
theorem bind₁_X_right (f : σ → MvPolynomial τ R) (i : σ) : bind₁ f (X i) = f i :=
aeval_X f i
@[simp]
theorem bind₂_X_right (f : R →+* MvPolynomial σ S) (i : σ) : bind₂ f (X i) = X i :=
eval₂Hom_X' f X i
@[simp]
theorem bind₁_X_left : bind₁ (X : σ → MvPolynomial σ R) = AlgHom.id R _ := by
ext1 i
simp
variable (f : σ → MvPolynomial τ R)
theorem bind₁_C_right (f : σ → MvPolynomial τ R) (x) : bind₁ f (C x) = C x := algHom_C _ _
@[simp]
theorem bind₂_C_right (f : R →+* MvPolynomial σ S) (r : R) : bind₂ f (C r) = f r :=
eval₂Hom_C f X r
@[simp]
theorem bind₂_C_left : bind₂ (C : R →+* MvPolynomial σ R) = RingHom.id _ := by ext : 2 <;> simp
@[simp]
theorem bind₂_comp_C (f : R →+* MvPolynomial σ S) : (bind₂ f).comp C = f :=
RingHom.ext <| bind₂_C_right _
@[simp]
theorem join₂_map (f : R →+* MvPolynomial σ S) (φ : MvPolynomial σ R) :
join₂ (map f φ) = bind₂ f φ := by simp only [join₂, bind₂, eval₂Hom_map_hom, RingHom.id_comp]
@[simp]
theorem join₂_comp_map (f : R →+* MvPolynomial σ S) : join₂.comp (map f) = bind₂ f :=
RingHom.ext <| join₂_map _
theorem aeval_id_rename (f : σ → MvPolynomial τ R) (p : MvPolynomial σ R) :
aeval id (rename f p) = aeval f p := by rw [aeval_rename, Function.id_comp]
@[simp]
theorem join₁_rename (f : σ → MvPolynomial τ R) (φ : MvPolynomial σ R) :
join₁ (rename f φ) = bind₁ f φ :=
aeval_id_rename _ _
@[simp]
theorem bind₁_id : bind₁ (@id (MvPolynomial σ R)) = join₁ :=
rfl
@[simp]
theorem bind₂_id : bind₂ (RingHom.id (MvPolynomial σ R)) = join₂ :=
rfl
theorem bind₁_bind₁ {υ : Type*} (f : σ → MvPolynomial τ R) (g : τ → MvPolynomial υ R)
(φ : MvPolynomial σ R) : (bind₁ g) (bind₁ f φ) = bind₁ (fun i => bind₁ g (f i)) φ := by
simp [bind₁, ← comp_aeval]
theorem bind₁_comp_bind₁ {υ : Type*} (f : σ → MvPolynomial τ R) (g : τ → MvPolynomial υ R) :
(bind₁ g).comp (bind₁ f) = bind₁ fun i => bind₁ g (f i) := by
ext1
apply bind₁_bind₁
theorem bind₂_comp_bind₂ (f : R →+* MvPolynomial σ S) (g : S →+* MvPolynomial σ T) :
(bind₂ g).comp (bind₂ f) = bind₂ ((bind₂ g).comp f) := by ext : 2 <;> simp
theorem bind₂_bind₂ (f : R →+* MvPolynomial σ S) (g : S →+* MvPolynomial σ T)
(φ : MvPolynomial σ R) : (bind₂ g) (bind₂ f φ) = bind₂ ((bind₂ g).comp f) φ :=
RingHom.congr_fun (bind₂_comp_bind₂ f g) φ
theorem rename_comp_bind₁ {υ : Type*} (f : σ → MvPolynomial τ R) (g : τ → υ) :
(rename g).comp (bind₁ f) = bind₁ fun i => rename g <| f i := by
ext1 i
simp
theorem rename_bind₁ {υ : Type*} (f : σ → MvPolynomial τ R) (g : τ → υ) (φ : MvPolynomial σ R) :
rename g (bind₁ f φ) = bind₁ (fun i => rename g <| f i) φ :=
AlgHom.congr_fun (rename_comp_bind₁ f g) φ
theorem map_bind₂ (f : R →+* MvPolynomial σ S) (g : S →+* T) (φ : MvPolynomial σ R) :
map g (bind₂ f φ) = bind₂ ((map g).comp f) φ := by
simp only [bind₂, eval₂_comp_right, coe_eval₂Hom, eval₂_map]
congr 1 with : 1
simp only [Function.comp_apply, map_X]
theorem bind₁_comp_rename {υ : Type*} (f : τ → MvPolynomial υ R) (g : σ → τ) :
(bind₁ f).comp (rename g) = bind₁ (f ∘ g) := by
ext1 i
simp
theorem bind₁_rename {υ : Type*} (f : τ → MvPolynomial υ R) (g : σ → τ) (φ : MvPolynomial σ R) :
bind₁ f (rename g φ) = bind₁ (f ∘ g) φ :=
AlgHom.congr_fun (bind₁_comp_rename f g) φ
theorem bind₂_map (f : S →+* MvPolynomial σ T) (g : R →+* S) (φ : MvPolynomial σ R) :
bind₂ f (map g φ) = bind₂ (f.comp g) φ := by simp [bind₂]
@[simp]
theorem map_comp_C (f : R →+* S) : (map f).comp (C : R →+* MvPolynomial σ R) = C.comp f := by
ext1
apply map_C
-- mixing the two monad structures
theorem hom_bind₁ (f : MvPolynomial τ R →+* S) (g : σ → MvPolynomial τ R) (φ : MvPolynomial σ R) :
f (bind₁ g φ) = eval₂Hom (f.comp C) (fun i => f (g i)) φ := by
rw [bind₁, map_aeval, algebraMap_eq]
theorem map_bind₁ (f : R →+* S) (g : σ → MvPolynomial τ R) (φ : MvPolynomial σ R) :
map f (bind₁ g φ) = bind₁ (fun i : σ => (map f) (g i)) (map f φ) := by
rw [hom_bind₁, map_comp_C, ← eval₂Hom_map_hom]
rfl
@[simp]
theorem eval₂Hom_comp_C (f : R →+* S) (g : σ → S) : (eval₂Hom f g).comp C = f := by
ext1 r
exact eval₂_C f g r
theorem eval₂Hom_bind₁ (f : R →+* S) (g : τ → S) (h : σ → MvPolynomial τ R) (φ : MvPolynomial σ R) :
eval₂Hom f g (bind₁ h φ) = eval₂Hom f (fun i => eval₂Hom f g (h i)) φ := by
rw [hom_bind₁, eval₂Hom_comp_C]
theorem aeval_bind₁ [Algebra R S] (f : τ → S) (g : σ → MvPolynomial τ R) (φ : MvPolynomial σ R) :
aeval f (bind₁ g φ) = aeval (fun i => aeval f (g i)) φ :=
eval₂Hom_bind₁ _ _ _ _
theorem aeval_comp_bind₁ [Algebra R S] (f : τ → S) (g : σ → MvPolynomial τ R) :
(aeval f).comp (bind₁ g) = aeval fun i => aeval f (g i) := by
ext1
apply aeval_bind₁
theorem eval₂Hom_comp_bind₂ (f : S →+* T) (g : σ → T) (h : R →+* MvPolynomial σ S) :
(eval₂Hom f g).comp (bind₂ h) = eval₂Hom ((eval₂Hom f g).comp h) g := by ext : 2 <;> simp
theorem eval₂Hom_bind₂ (f : S →+* T) (g : σ → T) (h : R →+* MvPolynomial σ S)
(φ : MvPolynomial σ R) : eval₂Hom f g (bind₂ h φ) = eval₂Hom ((eval₂Hom f g).comp h) g φ :=
RingHom.congr_fun (eval₂Hom_comp_bind₂ f g h) φ
theorem aeval_bind₂ [Algebra S T] (f : σ → T) (g : R →+* MvPolynomial σ S) (φ : MvPolynomial σ R) :
aeval f (bind₂ g φ) = eval₂Hom ((↑(aeval f : _ →ₐ[S] _) : _ →+* _).comp g) f φ :=
eval₂Hom_bind₂ _ _ _ _
theorem eval₂Hom_C_left (f : σ → MvPolynomial τ R) : eval₂Hom C f = bind₁ f :=
rfl
theorem bind₁_monomial (f : σ → MvPolynomial τ R) (d : σ →₀ ℕ) (r : R) :
bind₁ f (monomial d r) = C r * ∏ i ∈ d.support, f i ^ d i := by
simp only [monomial_eq, map_mul, bind₁_C_right, Finsupp.prod, map_prod,
map_pow, bind₁_X_right]
theorem bind₂_monomial (f : R →+* MvPolynomial σ S) (d : σ →₀ ℕ) (r : R) :
bind₂ f (monomial d r) = f r * monomial d 1 := by
simp only [monomial_eq, RingHom.map_mul, bind₂_C_right, Finsupp.prod, map_prod,
map_pow, bind₂_X_right, C_1, one_mul]
@[simp]
theorem bind₂_monomial_one (f : R →+* MvPolynomial σ S) (d : σ →₀ ℕ) :
bind₂ f (monomial d 1) = monomial d 1 := by rw [bind₂_monomial, f.map_one, one_mul]
section
theorem vars_bind₁ [DecidableEq τ] (f : σ → MvPolynomial τ R) (φ : MvPolynomial σ R) :
(bind₁ f φ).vars ⊆ φ.vars.biUnion fun i => (f i).vars := by
calc (bind₁ f φ).vars
_ = (φ.support.sum fun x : σ →₀ ℕ => (bind₁ f) (monomial x (coeff x φ))).vars := by
rw [← map_sum, ← φ.as_sum]
_ ≤ φ.support.biUnion fun i : σ →₀ ℕ => ((bind₁ f) (monomial i (coeff i φ))).vars :=
(vars_sum_subset _ _)
_ = φ.support.biUnion fun d : σ →₀ ℕ => vars (C (coeff d φ) * ∏ i ∈ d.support, f i ^ d i) := by
simp only [bind₁_monomial]
_ ≤ φ.support.biUnion fun d : σ →₀ ℕ => d.support.biUnion fun i => vars (f i) := ?_
-- proof below
_ ≤ φ.vars.biUnion fun i : σ => vars (f i) := ?_
-- proof below
· apply Finset.biUnion_mono
intro d _hd
calc
vars (C (coeff d φ) * ∏ i ∈ d.support, f i ^ d i) ≤
(C (coeff d φ)).vars ∪ (∏ i ∈ d.support, f i ^ d i).vars :=
vars_mul _ _
_ ≤ (∏ i ∈ d.support, f i ^ d i).vars := by
simp only [Finset.empty_union, vars_C, Finset.le_iff_subset, Finset.Subset.refl]
_ ≤ d.support.biUnion fun i : σ => vars (f i ^ d i) := vars_prod _
_ ≤ d.support.biUnion fun i : σ => (f i).vars := ?_
apply Finset.biUnion_mono
intro i _hi
apply vars_pow
· intro j
simp_rw [Finset.mem_biUnion]
rintro ⟨d, hd, ⟨i, hi, hj⟩⟩
exact ⟨i, (mem_vars _).mpr ⟨d, hd, hi⟩, hj⟩
end
theorem mem_vars_bind₁ (f : σ → MvPolynomial τ R) (φ : MvPolynomial σ R) {j : τ}
(h : j ∈ (bind₁ f φ).vars) : ∃ i : σ, i ∈ φ.vars ∧ j ∈ (f i).vars := by
classical
simpa only [exists_prop, Finset.mem_biUnion, mem_support_iff, Ne] using vars_bind₁ f φ h
instance monad : Monad fun σ => MvPolynomial σ R where
map f p := rename f p
pure := X
bind p f := bind₁ f p
instance lawfulFunctor : LawfulFunctor fun σ => MvPolynomial σ R where
map_const := by intros; rfl
-- Porting note: I guess `map_const` no longer has a default implementation?
id_map := by intros; simp [(· <$> ·)]
comp_map := by intros; simp [(· <$> ·)]
instance lawfulMonad : LawfulMonad fun σ => MvPolynomial σ R where
pure_bind := by intros; simp [pure, bind]
bind_assoc := by intros; simp [bind, ← bind₁_comp_bind₁]
seqLeft_eq := by intros; simp [SeqLeft.seqLeft, Seq.seq, (· <$> ·), bind₁_rename]; rfl
seqRight_eq := by intros; simp [SeqRight.seqRight, Seq.seq, (· <$> ·), bind₁_rename]; rfl
pure_seq := by intros; simp [(· <$> ·), pure, Seq.seq]
bind_pure_comp := by aesop
bind_map := by aesop
/-
Possible TODO for the future:
Enable the following definitions, and write a lot of supporting lemmas.
def bind (f : R →+* mv_polynomial τ S) (g : σ → mv_polynomial τ S) :
mv_polynomial σ R →+* mv_polynomial τ S :=
eval₂_hom f g
def join (f : R →+* S) : mv_polynomial (mv_polynomial σ R) S →ₐ[S] mv_polynomial σ S :=
aeval (map f)
def ajoin [algebra R S] : mv_polynomial (mv_polynomial σ R) S →ₐ[S] mv_polynomial σ S :=
join (algebra_map R S)
-/
end MvPolynomial
|
Algebra\MvPolynomial\PDeriv.lean | /-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Shing Tak Lam, Yury Kudryashov
-/
import Mathlib.Algebra.MvPolynomial.Derivation
import Mathlib.Algebra.MvPolynomial.Variables
/-!
# Partial derivatives of polynomials
This file defines the notion of the formal *partial derivative* of a polynomial,
the derivative with respect to a single variable.
This derivative is not connected to the notion of derivative from analysis.
It is based purely on the polynomial exponents and coefficients.
## Main declarations
* `MvPolynomial.pderiv i p` : the partial derivative of `p` with respect to `i`, as a bundled
derivation of `MvPolynomial σ R`.
## Notation
As in other polynomial files, we typically use the notation:
+ `σ : Type*` (indexing the variables)
+ `R : Type*` `[CommRing 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`
-/
noncomputable section
universe u v
namespace MvPolynomial
open Set Function Finsupp
variable {R : Type u} {σ : Type v} {a a' a₁ a₂ : R} {s : σ →₀ ℕ}
section PDeriv
variable [CommSemiring R]
/-- `pderiv i p` is the partial derivative of `p` with respect to `i` -/
def pderiv (i : σ) : Derivation R (MvPolynomial σ R) (MvPolynomial σ R) :=
letI := Classical.decEq σ
mkDerivation R <| Pi.single i 1
theorem pderiv_def [DecidableEq σ] (i : σ) : pderiv i = mkDerivation R (Pi.single i 1) := by
unfold pderiv; congr!
@[simp]
theorem pderiv_monomial {i : σ} :
pderiv i (monomial s a) = monomial (s - single i 1) (a * s i) := by
classical
simp only [pderiv_def, mkDerivation_monomial, Finsupp.smul_sum, smul_eq_mul, ← smul_mul_assoc,
← (monomial _).map_smul]
refine (Finset.sum_eq_single i (fun j _ hne => ?_) fun hi => ?_).trans ?_
· simp [Pi.single_eq_of_ne hne]
· rw [Finsupp.not_mem_support_iff] at hi; simp [hi]
· simp
theorem pderiv_C {i : σ} : pderiv i (C a) = 0 :=
derivation_C _ _
theorem pderiv_one {i : σ} : pderiv i (1 : MvPolynomial σ R) = 0 := pderiv_C
@[simp]
theorem pderiv_X [DecidableEq σ] (i j : σ) :
pderiv i (X j : MvPolynomial σ R) = Pi.single (f := fun j => _) i 1 j := by
rw [pderiv_def, mkDerivation_X]
@[simp]
theorem pderiv_X_self (i : σ) : pderiv i (X i : MvPolynomial σ R) = 1 := by classical simp
@[simp]
theorem pderiv_X_of_ne {i j : σ} (h : j ≠ i) : pderiv i (X j : MvPolynomial σ R) = 0 := by
classical simp [h]
theorem pderiv_eq_zero_of_not_mem_vars {i : σ} {f : MvPolynomial σ R} (h : i ∉ f.vars) :
pderiv i f = 0 :=
derivation_eq_zero_of_forall_mem_vars fun _ hj => pderiv_X_of_ne <| ne_of_mem_of_not_mem hj h
theorem pderiv_monomial_single {i : σ} {n : ℕ} : pderiv i (monomial (single i n) a) =
monomial (single i (n - 1)) (a * n) := by simp
theorem pderiv_mul {i : σ} {f g : MvPolynomial σ R} :
pderiv i (f * g) = pderiv i f * g + f * pderiv i g := by
simp only [(pderiv i).leibniz f g, smul_eq_mul, mul_comm, add_comm]
theorem pderiv_pow {i : σ} {f : MvPolynomial σ R} {n : ℕ} :
pderiv i (f ^ n) = n * f ^ (n - 1) * pderiv i f := by
rw [(pderiv i).leibniz_pow f n, nsmul_eq_mul, smul_eq_mul, mul_assoc]
-- @[simp] -- Porting note (#10618): simp can prove this
theorem pderiv_C_mul {f : MvPolynomial σ R} {i : σ} : pderiv i (C a * f) = C a * pderiv i f := by
rw [C_mul', Derivation.map_smul, C_mul']
theorem pderiv_map {S} [CommSemiring S] {φ : R →+* S} {f : MvPolynomial σ R} {i : σ} :
pderiv i (map φ f) = map φ (pderiv i f) := by
apply induction_on f (fun r ↦ by simp) (fun p q hp hq ↦ by simp [hp, hq]) fun p j eq ↦ ?_
obtain rfl | h := eq_or_ne j i
· simp [eq]
· simp [eq, h]
end PDeriv
end MvPolynomial
|
Algebra\MvPolynomial\Polynomial.lean | /-
Copyright (c) 2023 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.Algebra.MvPolynomial.Equiv
import Mathlib.Algebra.Polynomial.Eval
/-!
# Some lemmas relating polynomials and multivariable polynomials.
-/
namespace MvPolynomial
variable {R S σ : Type*}
theorem polynomial_eval_eval₂ [CommSemiring R] [CommSemiring S]
{x : S} (f : R →+* Polynomial S) (g : σ → Polynomial S) (p : MvPolynomial σ R) :
Polynomial.eval x (eval₂ f g p) =
eval₂ ((Polynomial.evalRingHom x).comp f) (fun s => Polynomial.eval x (g s)) p := by
apply induction_on p
· simp
· intro p q hp hq
simp [hp, hq]
· intro p n hp
simp [hp]
theorem eval_polynomial_eval_finSuccEquiv {n : ℕ} {x : Fin n → R}
[CommSemiring R] (f : MvPolynomial (Fin (n + 1)) R) (q : MvPolynomial (Fin n) R) :
(eval x) (Polynomial.eval q (finSuccEquiv R n f)) = eval (Fin.cases (eval x q) x) f := by
simp only [finSuccEquiv_apply, coe_eval₂Hom, polynomial_eval_eval₂, eval_eval₂]
conv in RingHom.comp _ _ =>
refine @RingHom.ext _ _ _ _ _ (RingHom.id _) fun r => ?_
simp
simp only [eval₂_id]
congr
funext i
refine Fin.cases (by simp) (by simp) i
end MvPolynomial
|
Algebra\MvPolynomial\Rename.lean | /-
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.MvPolynomial.Basic
/-!
# Renaming variables of polynomials
This file establishes the `rename` operation on multivariate polynomials,
which modifies the set of variables.
## Main declarations
* `MvPolynomial.rename`
* `MvPolynomial.renameEquiv`
## Notation
As in other polynomial files, we typically use the notation:
+ `σ τ α : Type*` (indexing the variables)
+ `R S : Type*` `[CommSemiring R]` `[CommSemiring S]` (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`
+ `r : R` elements of the coefficient ring
+ `i : σ`, with corresponding monomial `X i`, often denoted `X_i` by mathematicians
+ `p : MvPolynomial σ α`
-/
noncomputable section
open Set Function Finsupp AddMonoidAlgebra
variable {σ τ α R S : Type*} [CommSemiring R] [CommSemiring S]
namespace MvPolynomial
section Rename
/-- Rename all the variables in a multivariable polynomial. -/
def rename (f : σ → τ) : MvPolynomial σ R →ₐ[R] MvPolynomial τ R :=
aeval (X ∘ f)
theorem rename_C (f : σ → τ) (r : R) : rename f (C r) = C r :=
eval₂_C _ _ _
@[simp]
theorem rename_X (f : σ → τ) (i : σ) : rename f (X i : MvPolynomial σ R) = X (f i) :=
eval₂_X _ _ _
theorem map_rename (f : R →+* S) (g : σ → τ) (p : MvPolynomial σ R) :
map f (rename g p) = rename g (map f p) := by
apply MvPolynomial.induction_on p
(fun a => by simp only [map_C, rename_C])
(fun p q hp hq => by simp only [hp, hq, map_add]) fun p n hp => by
simp only [hp, rename_X, map_X, map_mul]
@[simp]
theorem rename_rename (f : σ → τ) (g : τ → α) (p : MvPolynomial σ R) :
rename g (rename f p) = rename (g ∘ f) p :=
show rename g (eval₂ C (X ∘ f) p) = _ by
simp only [rename, aeval_eq_eval₂Hom]
-- Porting note: the Lean 3 proof of this was very fragile and included a nonterminal `simp`.
-- Hopefully this is less prone to breaking
rw [eval₂_comp_left (eval₂Hom (algebraMap R (MvPolynomial α R)) (X ∘ g)) C (X ∘ f) p]
simp only [(· ∘ ·), eval₂Hom_X']
refine eval₂Hom_congr ?_ rfl rfl
ext1; simp only [comp_apply, RingHom.coe_comp, eval₂Hom_C]
@[simp]
theorem rename_id (p : MvPolynomial σ R) : rename id p = p :=
eval₂_eta p
theorem rename_monomial (f : σ → τ) (d : σ →₀ ℕ) (r : R) :
rename f (monomial d r) = monomial (d.mapDomain f) r := by
rw [rename, aeval_monomial, monomial_eq (s := Finsupp.mapDomain f d),
Finsupp.prod_mapDomain_index]
· rfl
· exact fun n => pow_zero _
· exact fun n i₁ i₂ => pow_add _ _ _
theorem rename_eq (f : σ → τ) (p : MvPolynomial σ R) :
rename f p = Finsupp.mapDomain (Finsupp.mapDomain f) p := by
simp only [rename, aeval_def, eval₂, Finsupp.mapDomain, algebraMap_eq, comp_apply,
X_pow_eq_monomial, ← monomial_finsupp_sum_index]
rfl
theorem rename_injective (f : σ → τ) (hf : Function.Injective f) :
Function.Injective (rename f : MvPolynomial σ R → MvPolynomial τ R) := by
have :
(rename f : MvPolynomial σ R → MvPolynomial τ R) = Finsupp.mapDomain (Finsupp.mapDomain f) :=
funext (rename_eq f)
rw [this]
exact Finsupp.mapDomain_injective (Finsupp.mapDomain_injective hf)
section
variable {f : σ → τ} (hf : Function.Injective f)
open Classical in
/-- Given a function between sets of variables `f : σ → τ` that is injective with proof `hf`,
`MvPolynomial.killCompl hf` is the `AlgHom` from `R[τ]` to `R[σ]` that is left inverse to
`rename f : R[σ] → R[τ]` and sends the variables in the complement of the range of `f` to `0`. -/
def killCompl : MvPolynomial τ R →ₐ[R] MvPolynomial σ R :=
aeval fun i => if h : i ∈ Set.range f then X <| (Equiv.ofInjective f hf).symm ⟨i, h⟩ else 0
theorem killCompl_C (r : R) : killCompl hf (C r) = C r := algHom_C _ _
theorem killCompl_comp_rename : (killCompl hf).comp (rename f) = AlgHom.id R _ :=
algHom_ext fun i => by
dsimp
rw [rename, killCompl, aeval_X, comp_apply, aeval_X, dif_pos, Equiv.ofInjective_symm_apply]
@[simp]
theorem killCompl_rename_app (p : MvPolynomial σ R) : killCompl hf (rename f p) = p :=
AlgHom.congr_fun (killCompl_comp_rename hf) p
end
section
variable (R)
/-- `MvPolynomial.rename e` is an equivalence when `e` is. -/
@[simps apply]
def renameEquiv (f : σ ≃ τ) : MvPolynomial σ R ≃ₐ[R] MvPolynomial τ R :=
{ rename f with
toFun := rename f
invFun := rename f.symm
left_inv := fun p => by rw [rename_rename, f.symm_comp_self, rename_id]
right_inv := fun p => by rw [rename_rename, f.self_comp_symm, rename_id] }
@[simp]
theorem renameEquiv_refl : renameEquiv R (Equiv.refl σ) = AlgEquiv.refl :=
AlgEquiv.ext rename_id
@[simp]
theorem renameEquiv_symm (f : σ ≃ τ) : (renameEquiv R f).symm = renameEquiv R f.symm :=
rfl
@[simp]
theorem renameEquiv_trans (e : σ ≃ τ) (f : τ ≃ α) :
(renameEquiv R e).trans (renameEquiv R f) = renameEquiv R (e.trans f) :=
AlgEquiv.ext (rename_rename e f)
end
section
variable (f : R →+* S) (k : σ → τ) (g : τ → S) (p : MvPolynomial σ R)
theorem eval₂_rename : (rename k p).eval₂ f g = p.eval₂ f (g ∘ k) := by
apply MvPolynomial.induction_on p <;>
· intros
simp [*]
theorem eval_rename (g : τ → R) (p : MvPolynomial σ R) : eval g (rename k p) = eval (g ∘ k) p :=
eval₂_rename _ _ _ _
theorem eval₂Hom_rename : eval₂Hom f g (rename k p) = eval₂Hom f (g ∘ k) p :=
eval₂_rename _ _ _ _
theorem aeval_rename [Algebra R S] : aeval g (rename k p) = aeval (g ∘ k) p :=
eval₂Hom_rename _ _ _ _
theorem rename_eval₂ (g : τ → MvPolynomial σ R) :
rename k (p.eval₂ C (g ∘ k)) = (rename k p).eval₂ C (rename k ∘ g) := by
apply MvPolynomial.induction_on p <;>
· intros
simp [*]
theorem rename_prod_mk_eval₂ (j : τ) (g : σ → MvPolynomial σ R) :
rename (Prod.mk j) (p.eval₂ C g) = p.eval₂ C fun x => rename (Prod.mk j) (g x) := by
apply MvPolynomial.induction_on p <;>
· intros
simp [*]
theorem eval₂_rename_prod_mk (g : σ × τ → S) (i : σ) (p : MvPolynomial τ R) :
(rename (Prod.mk i) p).eval₂ f g = eval₂ f (fun j => g (i, j)) p := by
apply MvPolynomial.induction_on p <;>
· intros
simp [*]
theorem eval_rename_prod_mk (g : σ × τ → R) (i : σ) (p : MvPolynomial τ R) :
eval g (rename (Prod.mk i) p) = eval (fun j => g (i, j)) p :=
eval₂_rename_prod_mk (RingHom.id _) _ _ _
end
/-- Every polynomial is a polynomial in finitely many variables. -/
theorem exists_finset_rename (p : MvPolynomial σ R) :
∃ (s : Finset σ) (q : MvPolynomial { x // x ∈ s } R), p = rename (↑) q := by
classical
apply induction_on p
· intro r
exact ⟨∅, C r, by rw [rename_C]⟩
· rintro p q ⟨s, p, rfl⟩ ⟨t, q, rfl⟩
refine ⟨s ∪ t, ⟨?_, ?_⟩⟩
· refine rename (Subtype.map id ?_) p + rename (Subtype.map id ?_) q <;>
simp (config := { contextual := true }) only [id, true_or_iff, or_true_iff,
Finset.mem_union, forall_true_iff]
· simp only [rename_rename, map_add]
rfl
· rintro p n ⟨s, p, rfl⟩
refine ⟨insert n s, ⟨?_, ?_⟩⟩
· refine rename (Subtype.map id ?_) p * X ⟨n, s.mem_insert_self n⟩
simp (config := { contextual := true }) only [id, or_true_iff, Finset.mem_insert,
forall_true_iff]
· simp only [rename_rename, rename_X, Subtype.coe_mk, map_mul]
rfl
/-- `exists_finset_rename` for two polynomials at once: for any two polynomials `p₁`, `p₂` in a
polynomial semiring `R[σ]` of possibly infinitely many variables, `exists_finset_rename₂` yields
a finite subset `s` of `σ` such that both `p₁` and `p₂` are contained in the polynomial semiring
`R[s]` of finitely many variables. -/
theorem exists_finset_rename₂ (p₁ p₂ : MvPolynomial σ R) :
∃ (s : Finset σ) (q₁ q₂ : MvPolynomial s R), p₁ = rename (↑) q₁ ∧ p₂ = rename (↑) q₂ := by
obtain ⟨s₁, q₁, rfl⟩ := exists_finset_rename p₁
obtain ⟨s₂, q₂, rfl⟩ := exists_finset_rename p₂
classical
use s₁ ∪ s₂
use rename (Set.inclusion s₁.subset_union_left) q₁
use rename (Set.inclusion s₁.subset_union_right) q₂
constructor -- Porting note: was `<;> simp <;> rfl` but Lean couldn't infer the arguments
· -- This used to be `rw`, but we need `erw` after leanprover/lean4#2644
erw [rename_rename (Set.inclusion s₁.subset_union_left)]
rfl
· -- This used to be `rw`, but we need `erw` after leanprover/lean4#2644
erw [rename_rename (Set.inclusion s₁.subset_union_right)]
rfl
/-- Every polynomial is a polynomial in finitely many variables. -/
theorem exists_fin_rename (p : MvPolynomial σ R) :
∃ (n : ℕ) (f : Fin n → σ) (_hf : Injective f) (q : MvPolynomial (Fin n) R), p = rename f q := by
obtain ⟨s, q, rfl⟩ := exists_finset_rename p
let n := Fintype.card { x // x ∈ s }
let e := Fintype.equivFin { x // x ∈ s }
refine ⟨n, (↑) ∘ e.symm, Subtype.val_injective.comp e.symm.injective, rename e q, ?_⟩
rw [← rename_rename, rename_rename e]
simp only [Function.comp, Equiv.symm_apply_apply, rename_rename]
end Rename
theorem eval₂_cast_comp (f : σ → τ) (c : ℤ →+* R) (g : τ → R) (p : MvPolynomial σ ℤ) :
eval₂ c (g ∘ f) p = eval₂ c g (rename f p) := by
apply MvPolynomial.induction_on p (fun n => by simp only [eval₂_C, rename_C])
(fun p q hp hq => by simp only [hp, hq, rename, eval₂_add, map_add])
fun p n hp => by simp only [eval₂_mul, hp, eval₂_X, comp_apply, map_mul, rename_X, eval₂_mul]
section Coeff
@[simp]
theorem coeff_rename_mapDomain (f : σ → τ) (hf : Injective f) (φ : MvPolynomial σ R) (d : σ →₀ ℕ) :
(rename f φ).coeff (d.mapDomain f) = φ.coeff d := by
classical
apply φ.induction_on' (P := fun ψ => coeff (Finsupp.mapDomain f d) ((rename f) ψ) = coeff d ψ)
-- Lean could no longer infer the motive
· intro u r
rw [rename_monomial, coeff_monomial, coeff_monomial]
simp only [(Finsupp.mapDomain_injective hf).eq_iff]
· intros
simp only [*, map_add, coeff_add]
@[simp]
theorem coeff_rename_embDomain (f : σ ↪ τ) (φ : MvPolynomial σ R) (d : σ →₀ ℕ) :
(rename f φ).coeff (d.embDomain f) = φ.coeff d := by
rw [Finsupp.embDomain_eq_mapDomain f, coeff_rename_mapDomain f f.injective]
theorem coeff_rename_eq_zero (f : σ → τ) (φ : MvPolynomial σ R) (d : τ →₀ ℕ)
(h : ∀ u : σ →₀ ℕ, u.mapDomain f = d → φ.coeff u = 0) : (rename f φ).coeff d = 0 := by
classical
rw [rename_eq, ← not_mem_support_iff]
intro H
replace H := mapDomain_support H
rw [Finset.mem_image] at H
obtain ⟨u, hu, rfl⟩ := H
specialize h u rfl
simp? at h hu says simp only [Finsupp.mem_support_iff, ne_eq] at h hu
contradiction
theorem coeff_rename_ne_zero (f : σ → τ) (φ : MvPolynomial σ R) (d : τ →₀ ℕ)
(h : (rename f φ).coeff d ≠ 0) : ∃ u : σ →₀ ℕ, u.mapDomain f = d ∧ φ.coeff u ≠ 0 := by
contrapose! h
apply coeff_rename_eq_zero _ _ _ h
@[simp]
theorem constantCoeff_rename {τ : Type*} (f : σ → τ) (φ : MvPolynomial σ R) :
constantCoeff (rename f φ) = constantCoeff φ := by
apply φ.induction_on
· intro a
simp only [constantCoeff_C, rename_C]
· intro p q hp hq
simp only [hp, hq, map_add]
· intro p n hp
simp only [hp, rename_X, constantCoeff_X, map_mul]
end Coeff
section Support
theorem support_rename_of_injective {p : MvPolynomial σ R} {f : σ → τ} [DecidableEq τ]
(h : Function.Injective f) :
(rename f p).support = Finset.image (Finsupp.mapDomain f) p.support := by
rw [rename_eq]
exact Finsupp.mapDomain_support_of_injective (mapDomain_injective h) _
end Support
end MvPolynomial
|
Algebra\MvPolynomial\Supported.lean | /-
Copyright (c) 2021 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes
-/
import Mathlib.Algebra.MvPolynomial.Variables
/-!
# Polynomials supported by a set of variables
This file contains the definition and lemmas about `MvPolynomial.supported`.
## Main definitions
* `MvPolynomial.supported` : Given a set `s : Set σ`, `supported R s` is the subalgebra of
`MvPolynomial σ R` consisting of polynomials whose set of variables is contained in `s`.
This subalgebra is isomorphic to `MvPolynomial s R`.
## Tags
variables, polynomial, vars
-/
universe u v w
namespace MvPolynomial
variable {σ τ : Type*} {R : Type u} {S : Type v} {r : R} {e : ℕ} {n m : σ}
section CommSemiring
variable [CommSemiring R] {p q : MvPolynomial σ R}
variable (R)
/-- The set of polynomials whose variables are contained in `s` as a `Subalgebra` over `R`. -/
noncomputable def supported (s : Set σ) : Subalgebra R (MvPolynomial σ R) :=
Algebra.adjoin R (X '' s)
variable {R}
open Algebra
theorem supported_eq_range_rename (s : Set σ) : supported R s = (rename ((↑) : s → σ)).range := by
rw [supported, Set.image_eq_range, adjoin_range_eq_range_aeval, rename]
congr
/-- The isomorphism between the subalgebra of polynomials supported by `s` and
`MvPolynomial s R`. -/
noncomputable def supportedEquivMvPolynomial (s : Set σ) : supported R s ≃ₐ[R] MvPolynomial s R :=
(Subalgebra.equivOfEq _ _ (supported_eq_range_rename s)).trans
(AlgEquiv.ofInjective (rename ((↑) : s → σ)) (rename_injective _ Subtype.val_injective)).symm
@[simp]
theorem supportedEquivMvPolynomial_symm_C (s : Set σ) (x : R) :
(supportedEquivMvPolynomial s).symm (C x) = algebraMap R (supported R s) x := by
ext1
simp [supportedEquivMvPolynomial, MvPolynomial.algebraMap_eq]
@[simp]
theorem supportedEquivMvPolynomial_symm_X (s : Set σ) (i : s) :
(↑((supportedEquivMvPolynomial s).symm (X i : MvPolynomial s R)) : MvPolynomial σ R) = X ↑i :=
by simp [supportedEquivMvPolynomial]
variable {s t : Set σ}
theorem mem_supported : p ∈ supported R s ↔ ↑p.vars ⊆ s := by
classical
rw [supported_eq_range_rename, AlgHom.mem_range]
constructor
· rintro ⟨p, rfl⟩
refine _root_.trans (Finset.coe_subset.2 (vars_rename _ _)) ?_
simp
· intro hs
exact exists_rename_eq_of_vars_subset_range p ((↑) : s → σ) Subtype.val_injective (by simpa)
theorem supported_eq_vars_subset : (supported R s : Set (MvPolynomial σ R)) = { p | ↑p.vars ⊆ s } :=
Set.ext fun _ ↦ mem_supported
@[simp]
theorem mem_supported_vars (p : MvPolynomial σ R) : p ∈ supported R (↑p.vars : Set σ) := by
rw [mem_supported]
variable (s)
theorem supported_eq_adjoin_X : supported R s = Algebra.adjoin R (X '' s) := rfl
@[simp]
theorem supported_univ : supported R (Set.univ : Set σ) = ⊤ := by
simp [Algebra.eq_top_iff, mem_supported]
@[simp]
theorem supported_empty : supported R (∅ : Set σ) = ⊥ := by simp [supported_eq_adjoin_X]
variable {s}
theorem supported_mono (st : s ⊆ t) : supported R s ≤ supported R t :=
Algebra.adjoin_mono (Set.image_subset _ st)
@[simp]
theorem X_mem_supported [Nontrivial R] {i : σ} : X i ∈ supported R s ↔ i ∈ s := by
simp [mem_supported]
@[simp]
theorem supported_le_supported_iff [Nontrivial R] : supported R s ≤ supported R t ↔ s ⊆ t := by
constructor
· intro h i
simpa using @h (X i)
· exact supported_mono
theorem supported_strictMono [Nontrivial R] :
StrictMono (supported R : Set σ → Subalgebra R (MvPolynomial σ R)) :=
strictMono_of_le_iff_le fun _ _ ↦ supported_le_supported_iff.symm
theorem exists_restrict_to_vars (R : Type*) [CommRing R] {F : MvPolynomial σ ℤ}
(hF : ↑F.vars ⊆ s) : ∃ f : (s → R) → R, ∀ x : σ → R, f (x ∘ (↑) : s → R) = aeval x F := by
rw [← mem_supported, supported_eq_range_rename, AlgHom.mem_range] at hF
cases' hF with F' hF'
use fun z ↦ aeval z F'
intro x
simp only [← hF', aeval_rename]
end CommSemiring
end MvPolynomial
|
Algebra\MvPolynomial\Variables.lean | /-
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.MvPolynomial.Degrees
/-!
# Variables of polynomials
This file establishes many results about the variable sets of a multivariate polynomial.
The *variable set* of a polynomial $P \in R[X]$ is a `Finset` containing each $x \in X$
that appears in a monomial in $P$.
## Main declarations
* `MvPolynomial.vars p` : the finset of variables occurring in `p`.
For example if `p = x⁴y+yz` then `vars p = {x, y, z}`
## Notation
As in other polynomial files, we typically use the 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`
+ `r : R`
+ `i : σ`, with corresponding monomial `X i`, often denoted `X_i` by mathematicians
+ `p : MvPolynomial σ R`
-/
noncomputable section
open Set Function Finsupp AddMonoidAlgebra
universe u v w
variable {R : Type u} {S : Type v}
namespace MvPolynomial
variable {σ τ : Type*} {r : R} {e : ℕ} {n m : σ} {s : σ →₀ ℕ}
section CommSemiring
variable [CommSemiring R] {p q : MvPolynomial σ R}
section Vars
/-! ### `vars` -/
/-- `vars p` is the set of variables appearing in the polynomial `p` -/
def vars (p : MvPolynomial σ R) : Finset σ :=
letI := Classical.decEq σ
p.degrees.toFinset
theorem vars_def [DecidableEq σ] (p : MvPolynomial σ R) : p.vars = p.degrees.toFinset := by
rw [vars]
convert rfl
@[simp]
theorem vars_0 : (0 : MvPolynomial σ R).vars = ∅ := by
classical rw [vars_def, degrees_zero, Multiset.toFinset_zero]
@[simp]
theorem vars_monomial (h : r ≠ 0) : (monomial s r).vars = s.support := by
classical rw [vars_def, degrees_monomial_eq _ _ h, Finsupp.toFinset_toMultiset]
@[simp]
theorem vars_C : (C r : MvPolynomial σ R).vars = ∅ := by
classical rw [vars_def, degrees_C, Multiset.toFinset_zero]
@[simp]
theorem vars_X [Nontrivial R] : (X n : MvPolynomial σ R).vars = {n} := by
rw [X, vars_monomial (one_ne_zero' R), Finsupp.support_single_ne_zero _ (one_ne_zero' ℕ)]
theorem mem_vars (i : σ) : i ∈ p.vars ↔ ∃ d ∈ p.support, i ∈ d.support := by
classical simp only [vars_def, Multiset.mem_toFinset, mem_degrees, mem_support_iff, exists_prop]
theorem mem_support_not_mem_vars_zero {f : MvPolynomial σ R} {x : σ →₀ ℕ} (H : x ∈ f.support)
{v : σ} (h : v ∉ vars f) : x v = 0 := by
contrapose! h
exact (mem_vars v).mpr ⟨x, H, Finsupp.mem_support_iff.mpr h⟩
theorem vars_add_subset [DecidableEq σ] (p q : MvPolynomial σ R) :
(p + q).vars ⊆ p.vars ∪ q.vars := by
intro x hx
simp only [vars_def, Finset.mem_union, Multiset.mem_toFinset] at hx ⊢
simpa using Multiset.mem_of_le (degrees_add _ _) hx
theorem vars_add_of_disjoint [DecidableEq σ] (h : Disjoint p.vars q.vars) :
(p + q).vars = p.vars ∪ q.vars := by
refine (vars_add_subset p q).antisymm fun x hx => ?_
simp only [vars_def, Multiset.disjoint_toFinset] at h hx ⊢
rwa [degrees_add_of_disjoint h, Multiset.toFinset_union]
section Mul
theorem vars_mul [DecidableEq σ] (φ ψ : MvPolynomial σ R) : (φ * ψ).vars ⊆ φ.vars ∪ ψ.vars := by
simp_rw [vars_def, ← Multiset.toFinset_add, Multiset.toFinset_subset]
exact Multiset.subset_of_le (degrees_mul φ ψ)
@[simp]
theorem vars_one : (1 : MvPolynomial σ R).vars = ∅ :=
vars_C
theorem vars_pow (φ : MvPolynomial σ R) (n : ℕ) : (φ ^ n).vars ⊆ φ.vars := by
classical
induction' n with n ih
· simp
· rw [pow_succ']
apply Finset.Subset.trans (vars_mul _ _)
exact Finset.union_subset (Finset.Subset.refl _) ih
/-- The variables of the product of a family of polynomials
are a subset of the union of the sets of variables of each polynomial.
-/
theorem vars_prod {ι : Type*} [DecidableEq σ] {s : Finset ι} (f : ι → MvPolynomial σ R) :
(∏ i ∈ s, f i).vars ⊆ s.biUnion fun i => (f i).vars := by
classical
induction s using Finset.induction_on with
| empty => simp
| insert hs hsub =>
simp only [hs, Finset.biUnion_insert, Finset.prod_insert, not_false_iff]
apply Finset.Subset.trans (vars_mul _ _)
exact Finset.union_subset_union (Finset.Subset.refl _) hsub
section IsDomain
variable {A : Type*} [CommRing A] [IsDomain A]
theorem vars_C_mul (a : A) (ha : a ≠ 0) (φ : MvPolynomial σ A) :
(C a * φ : MvPolynomial σ A).vars = φ.vars := by
ext1 i
simp only [mem_vars, exists_prop, mem_support_iff]
apply exists_congr
intro d
apply and_congr _ Iff.rfl
rw [coeff_C_mul, mul_ne_zero_iff, eq_true ha, true_and_iff]
end IsDomain
end Mul
section Sum
variable {ι : Type*} (t : Finset ι) (φ : ι → MvPolynomial σ R)
theorem vars_sum_subset [DecidableEq σ] :
(∑ i ∈ t, φ i).vars ⊆ Finset.biUnion t fun i => (φ i).vars := by
classical
induction t using Finset.induction_on with
| empty => simp
| insert has hsum =>
rw [Finset.biUnion_insert, Finset.sum_insert has]
refine Finset.Subset.trans
(vars_add_subset _ _) (Finset.union_subset_union (Finset.Subset.refl _) ?_)
assumption
theorem vars_sum_of_disjoint [DecidableEq σ] (h : Pairwise <| (Disjoint on fun i => (φ i).vars)) :
(∑ i ∈ t, φ i).vars = Finset.biUnion t fun i => (φ i).vars := by
classical
induction t using Finset.induction_on with
| empty => simp
| insert has hsum =>
rw [Finset.biUnion_insert, Finset.sum_insert has, vars_add_of_disjoint, hsum]
unfold Pairwise onFun at h
rw [hsum]
simp only [Finset.disjoint_iff_ne] at h ⊢
intro v hv v2 hv2
rw [Finset.mem_biUnion] at hv2
rcases hv2 with ⟨i, his, hi⟩
refine h ?_ _ hv _ hi
rintro rfl
contradiction
end Sum
section Map
variable [CommSemiring S] (f : R →+* S)
variable (p)
theorem vars_map : (map f p).vars ⊆ p.vars := by classical simp [vars_def, degrees_map]
variable {f}
theorem vars_map_of_injective (hf : Injective f) : (map f p).vars = p.vars := by
simp [vars, degrees_map_of_injective _ hf]
theorem vars_monomial_single (i : σ) {e : ℕ} {r : R} (he : e ≠ 0) (hr : r ≠ 0) :
(monomial (Finsupp.single i e) r).vars = {i} := by
rw [vars_monomial hr, Finsupp.support_single_ne_zero _ he]
theorem vars_eq_support_biUnion_support [DecidableEq σ] :
p.vars = p.support.biUnion Finsupp.support := by
ext i
rw [mem_vars, Finset.mem_biUnion]
end Map
end Vars
section EvalVars
/-! ### `vars` and `eval` -/
variable [CommSemiring S]
theorem eval₂Hom_eq_constantCoeff_of_vars (f : R →+* S) {g : σ → S} {p : MvPolynomial σ R}
(hp : ∀ i ∈ p.vars, g i = 0) : eval₂Hom f g p = f (constantCoeff p) := by
conv_lhs => rw [p.as_sum]
simp only [map_sum, eval₂Hom_monomial]
by_cases h0 : constantCoeff p = 0
on_goal 1 =>
rw [h0, f.map_zero, Finset.sum_eq_zero]
intro d hd
on_goal 2 =>
rw [Finset.sum_eq_single (0 : σ →₀ ℕ)]
· rw [Finsupp.prod_zero_index, mul_one]
rfl
on_goal 1 => intro d hd hd0
on_goal 3 =>
rw [constantCoeff_eq, coeff, ← Ne, ← Finsupp.mem_support_iff] at h0
intro
contradiction
repeat'
obtain ⟨i, hi⟩ : Finset.Nonempty (Finsupp.support d) := by
rw [constantCoeff_eq, coeff, ← Finsupp.not_mem_support_iff] at h0
rw [Finset.nonempty_iff_ne_empty, Ne, Finsupp.support_eq_empty]
rintro rfl
contradiction
rw [Finsupp.prod, Finset.prod_eq_zero hi, mul_zero]
rw [hp, zero_pow (Finsupp.mem_support_iff.1 hi)]
rw [mem_vars]
exact ⟨d, hd, hi⟩
theorem aeval_eq_constantCoeff_of_vars [Algebra R S] {g : σ → S} {p : MvPolynomial σ R}
(hp : ∀ i ∈ p.vars, g i = 0) : aeval g p = algebraMap _ _ (constantCoeff p) :=
eval₂Hom_eq_constantCoeff_of_vars _ hp
theorem eval₂Hom_congr' {f₁ f₂ : R →+* S} {g₁ g₂ : σ → S} {p₁ p₂ : MvPolynomial σ R} :
f₁ = f₂ →
(∀ i, i ∈ p₁.vars → i ∈ p₂.vars → g₁ i = g₂ i) →
p₁ = p₂ → eval₂Hom f₁ g₁ p₁ = eval₂Hom f₂ g₂ p₂ := by
rintro rfl h rfl
rw [p₁.as_sum]
simp only [map_sum, eval₂Hom_monomial]
apply Finset.sum_congr rfl
intro d hd
congr 1
simp only [Finsupp.prod]
apply Finset.prod_congr rfl
intro i hi
have : i ∈ p₁.vars := by
rw [mem_vars]
exact ⟨d, hd, hi⟩
rw [h i this this]
/-- If `f₁` and `f₂` are ring homs out of the polynomial ring and `p₁` and `p₂` are polynomials,
then `f₁ p₁ = f₂ p₂` if `p₁ = p₂` and `f₁` and `f₂` are equal on `R` and on the variables
of `p₁`. -/
theorem hom_congr_vars {f₁ f₂ : MvPolynomial σ R →+* S} {p₁ p₂ : MvPolynomial σ R}
(hC : f₁.comp C = f₂.comp C) (hv : ∀ i, i ∈ p₁.vars → i ∈ p₂.vars → f₁ (X i) = f₂ (X i))
(hp : p₁ = p₂) : f₁ p₁ = f₂ p₂ :=
calc
f₁ p₁ = eval₂Hom (f₁.comp C) (f₁ ∘ X) p₁ := RingHom.congr_fun (by ext <;> simp) _
_ = eval₂Hom (f₂.comp C) (f₂ ∘ X) p₂ := eval₂Hom_congr' hC hv hp
_ = f₂ p₂ := RingHom.congr_fun (by ext <;> simp) _
theorem exists_rename_eq_of_vars_subset_range (p : MvPolynomial σ R) (f : τ → σ) (hfi : Injective f)
(hf : ↑p.vars ⊆ Set.range f) : ∃ q : MvPolynomial τ R, rename f q = p :=
⟨aeval (fun i : σ => Option.elim' 0 X <| partialInv f i) p,
by
show (rename f).toRingHom.comp _ p = RingHom.id _ p
refine hom_congr_vars ?_ ?_ ?_
· ext1
simp [algebraMap_eq]
· intro i hip _
rcases hf hip with ⟨i, rfl⟩
simp [partialInv_left hfi]
· rfl⟩
theorem vars_rename [DecidableEq τ] (f : σ → τ) (φ : MvPolynomial σ R) :
(rename f φ).vars ⊆ φ.vars.image f := by
classical
intro i hi
simp only [vars_def, exists_prop, Multiset.mem_toFinset, Finset.mem_image] at hi ⊢
simpa only [Multiset.mem_map] using degrees_rename _ _ hi
theorem mem_vars_rename (f : σ → τ) (φ : MvPolynomial σ R) {j : τ} (h : j ∈ (rename f φ).vars) :
∃ i : σ, i ∈ φ.vars ∧ f i = j := by
classical
simpa only [exists_prop, Finset.mem_image] using vars_rename f φ h
end EvalVars
end CommSemiring
end MvPolynomial
|
Algebra\Order\AbsoluteValue.lean | /-
Copyright (c) 2021 Anne Baanen. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Anne Baanen
-/
import Mathlib.Algebra.GroupWithZero.Units.Lemmas
import Mathlib.Algebra.Order.Field.Defs
import Mathlib.Algebra.Order.Hom.Basic
import Mathlib.Algebra.Order.Ring.Abs
import Mathlib.Algebra.Regular.Basic
import Mathlib.Tactic.Bound.Attribute
/-!
# Absolute values
This file defines a bundled type of absolute values `AbsoluteValue R S`.
## Main definitions
* `AbsoluteValue R S` is the type of absolute values on `R` mapping to `S`.
* `AbsoluteValue.abs` is the "standard" absolute value on `S`, mapping negative `x` to `-x`.
* `AbsoluteValue.toMonoidWithZeroHom`: absolute values mapping to a
linear ordered field preserve `0`, `*` and `1`
* `IsAbsoluteValue`: a type class stating that `f : β → α` satisfies the axioms of an absolute
value
-/
variable {ι α R S : Type*}
/-- `AbsoluteValue R S` is the type of absolute values on `R` mapping to `S`:
the maps that preserve `*`, are nonnegative, positive definite and satisfy the triangle equality. -/
structure AbsoluteValue (R S : Type*) [Semiring R] [OrderedSemiring S] extends R →ₙ* S where
/-- The absolute value is nonnegative -/
nonneg' : ∀ x, 0 ≤ toFun x
/-- The absolute value is positive definitive -/
eq_zero' : ∀ x, toFun x = 0 ↔ x = 0
/-- The absolute value satisfies the triangle inequality -/
add_le' : ∀ x y, toFun (x + y) ≤ toFun x + toFun y
namespace AbsoluteValue
attribute [nolint docBlame] AbsoluteValue.toMulHom
section OrderedSemiring
section Semiring
variable {R S : Type*} [Semiring R] [OrderedSemiring S] (abv : AbsoluteValue R S)
instance funLike : FunLike (AbsoluteValue R S) R S where
coe f := f.toFun
coe_injective' f g h := by obtain ⟨⟨_, _⟩, _⟩ := f; obtain ⟨⟨_, _⟩, _⟩ := g; congr
instance zeroHomClass : ZeroHomClass (AbsoluteValue R S) R S where
map_zero f := (f.eq_zero' _).2 rfl
instance mulHomClass : MulHomClass (AbsoluteValue R S) R S :=
{ AbsoluteValue.zeroHomClass (R := R) (S := S) with map_mul := fun f => f.map_mul' }
instance nonnegHomClass : NonnegHomClass (AbsoluteValue R S) R S :=
{ AbsoluteValue.zeroHomClass (R := R) (S := S) with apply_nonneg := fun f => f.nonneg' }
instance subadditiveHomClass : SubadditiveHomClass (AbsoluteValue R S) R S :=
{ AbsoluteValue.zeroHomClass (R := R) (S := S) with map_add_le_add := fun f => f.add_le' }
@[simp]
theorem coe_mk (f : R →ₙ* S) {h₁ h₂ h₃} : (AbsoluteValue.mk f h₁ h₂ h₃ : R → S) = f :=
rfl
@[ext]
theorem ext ⦃f g : AbsoluteValue R S⦄ : (∀ x, f x = g x) → f = g :=
DFunLike.ext _ _
/-- See Note [custom simps projection]. -/
def Simps.apply (f : AbsoluteValue R S) : R → S :=
f
initialize_simps_projections AbsoluteValue (toMulHom_toFun → apply)
/-- Helper instance for when there's too many metavariables to apply `DFunLike.has_coe_to_fun`
directly. -/
instance : CoeFun (AbsoluteValue R S) fun _ => R → S :=
DFunLike.hasCoeToFun
@[simp]
theorem coe_toMulHom : ⇑abv.toMulHom = abv :=
rfl
@[bound]
protected theorem nonneg (x : R) : 0 ≤ abv x :=
abv.nonneg' x
@[simp]
protected theorem eq_zero {x : R} : abv x = 0 ↔ x = 0 :=
abv.eq_zero' x
@[bound]
protected theorem add_le (x y : R) : abv (x + y) ≤ abv x + abv y :=
abv.add_le' x y
-- Porting note (#10618): was `@[simp]` but `simp` can prove it
protected theorem map_mul (x y : R) : abv (x * y) = abv x * abv y :=
abv.map_mul' x y
protected theorem ne_zero_iff {x : R} : abv x ≠ 0 ↔ x ≠ 0 :=
abv.eq_zero.not
protected theorem pos {x : R} (hx : x ≠ 0) : 0 < abv x :=
lt_of_le_of_ne (abv.nonneg x) (Ne.symm <| mt abv.eq_zero.mp hx)
@[simp]
protected theorem pos_iff {x : R} : 0 < abv x ↔ x ≠ 0 :=
⟨fun h₁ => mt abv.eq_zero.mpr h₁.ne', abv.pos⟩
protected theorem ne_zero {x : R} (hx : x ≠ 0) : abv x ≠ 0 :=
(abv.pos hx).ne'
theorem map_one_of_isLeftRegular (h : IsLeftRegular (abv 1)) : abv 1 = 1 :=
h <| by simp [← abv.map_mul]
-- Porting note (#10618): was `@[simp]` but `simp` can prove it
protected theorem map_zero : abv 0 = 0 :=
abv.eq_zero.2 rfl
end Semiring
section Ring
variable {R S : Type*} [Ring R] [OrderedSemiring S] (abv : AbsoluteValue R S)
protected theorem sub_le (a b c : R) : abv (a - c) ≤ abv (a - b) + abv (b - c) := by
simpa [sub_eq_add_neg, add_assoc] using abv.add_le (a - b) (b - c)
@[simp high] -- Porting note: added `high` to apply it before `AbsoluteValue.eq_zero`
theorem map_sub_eq_zero_iff (a b : R) : abv (a - b) = 0 ↔ a = b :=
abv.eq_zero.trans sub_eq_zero
end Ring
end OrderedSemiring
section OrderedRing
section Semiring
section IsDomain
-- all of these are true for `NoZeroDivisors S`; but it doesn't work smoothly with the
-- `IsDomain`/`CancelMonoidWithZero` API
variable {R S : Type*} [Semiring R] [OrderedRing S] (abv : AbsoluteValue R S)
variable [IsDomain S] [Nontrivial R]
-- Porting note (#10618): was `@[simp]` but `simp` can prove it
protected theorem map_one : abv 1 = 1 :=
abv.map_one_of_isLeftRegular (isRegular_of_ne_zero <| abv.ne_zero one_ne_zero).left
instance monoidWithZeroHomClass : MonoidWithZeroHomClass (AbsoluteValue R S) R S :=
{ AbsoluteValue.mulHomClass with
map_zero := fun f => f.map_zero
map_one := fun f => f.map_one }
/-- Absolute values from a nontrivial `R` to a linear ordered ring preserve `*`, `0` and `1`. -/
def toMonoidWithZeroHom : R →*₀ S :=
abv
@[simp]
theorem coe_toMonoidWithZeroHom : ⇑abv.toMonoidWithZeroHom = abv :=
rfl
/-- Absolute values from a nontrivial `R` to a linear ordered ring preserve `*` and `1`. -/
def toMonoidHom : R →* S :=
abv
@[simp]
theorem coe_toMonoidHom : ⇑abv.toMonoidHom = abv :=
rfl
-- Porting note (#10618): was `@[simp]` but `simp` can prove it
protected theorem map_pow (a : R) (n : ℕ) : abv (a ^ n) = abv a ^ n :=
abv.toMonoidHom.map_pow a n
end IsDomain
end Semiring
section Ring
variable {R S : Type*} [Ring R] [OrderedRing S] (abv : AbsoluteValue R S)
@[bound]
protected theorem le_sub (a b : R) : abv a - abv b ≤ abv (a - b) :=
sub_le_iff_le_add.2 <| by simpa using abv.add_le (a - b) b
end Ring
end OrderedRing
section OrderedCommRing
variable [OrderedCommRing S] [Ring R] (abv : AbsoluteValue R S)
variable [NoZeroDivisors S]
@[simp]
protected theorem map_neg (a : R) : abv (-a) = abv a := by
by_cases ha : a = 0; · simp [ha]
refine
(mul_self_eq_mul_self_iff.mp (by rw [← abv.map_mul, neg_mul_neg, abv.map_mul])).resolve_right ?_
exact ((neg_lt_zero.mpr (abv.pos ha)).trans (abv.pos (neg_ne_zero.mpr ha))).ne'
protected theorem map_sub (a b : R) : abv (a - b) = abv (b - a) := by rw [← neg_sub, abv.map_neg]
/-- Bound `abv (a + b)` from below -/
@[bound]
protected theorem le_add (a b : R) : abv a - abv b ≤ abv (a + b) := by
simpa only [tsub_le_iff_right, add_neg_cancel_right, abv.map_neg] using abv.add_le (a + b) (-b)
/-- Bound `abv (a - b)` from above -/
@[bound]
lemma sub_le_add (a b : R) : abv (a - b) ≤ abv a + abv b := by
simpa only [← sub_eq_add_neg, AbsoluteValue.map_neg] using abv.add_le a (-b)
instance [Nontrivial R] [IsDomain S] : MulRingNormClass (AbsoluteValue R S) R S :=
{ AbsoluteValue.subadditiveHomClass,
AbsoluteValue.monoidWithZeroHomClass with
map_neg_eq_map := fun f => f.map_neg
eq_zero_of_map_eq_zero := fun f _ => f.eq_zero.1 }
end OrderedCommRing
section LinearOrderedRing
variable {R S : Type*} [Semiring R] [LinearOrderedRing S] (abv : AbsoluteValue R S)
/-- `AbsoluteValue.abs` is `abs` as a bundled `AbsoluteValue`. -/
@[simps]
protected def abs : AbsoluteValue S S where
toFun := abs
nonneg' := abs_nonneg
eq_zero' _ := abs_eq_zero
add_le' := abs_add
map_mul' := abs_mul
instance : Inhabited (AbsoluteValue S S) :=
⟨AbsoluteValue.abs⟩
end LinearOrderedRing
section LinearOrderedCommRing
variable {R S : Type*} [Ring R] [LinearOrderedCommRing S] (abv : AbsoluteValue R S)
@[bound]
theorem abs_abv_sub_le_abv_sub (a b : R) : abs (abv a - abv b) ≤ abv (a - b) :=
abs_sub_le_iff.2 ⟨abv.le_sub _ _, by rw [abv.map_sub]; apply abv.le_sub⟩
end LinearOrderedCommRing
end AbsoluteValue
-- Porting note: Removed [] in fields, see
-- leanprover.zulipchat.com/#narrow/stream/287929-mathlib4/topic/Infer.20kinds.20are.20unsupported
/-- A function `f` is an absolute value if it is nonnegative, zero only at 0, additive, and
multiplicative.
See also the type `AbsoluteValue` which represents a bundled version of absolute values.
-/
class IsAbsoluteValue {S} [OrderedSemiring S] {R} [Semiring R] (f : R → S) : Prop where
/-- The absolute value is nonnegative -/
abv_nonneg' : ∀ x, 0 ≤ f x
/-- The absolute value is positive definitive -/
abv_eq_zero' : ∀ {x}, f x = 0 ↔ x = 0
/-- The absolute value satisfies the triangle inequality -/
abv_add' : ∀ x y, f (x + y) ≤ f x + f y
/-- The absolute value is multiplicative -/
abv_mul' : ∀ x y, f (x * y) = f x * f y
namespace IsAbsoluteValue
section OrderedSemiring
variable {S : Type*} [OrderedSemiring S]
variable {R : Type*} [Semiring R] (abv : R → S) [IsAbsoluteValue abv]
lemma abv_nonneg (x) : 0 ≤ abv x := abv_nonneg' x
open Lean Meta Mathlib Meta Positivity Qq in
/-- The `positivity` extension which identifies expressions of the form `abv a`. -/
@[positivity _]
def Mathlib.Meta.Positivity.evalAbv : PositivityExt where eval {_ _α} _zα _pα e := do
let (.app f a) ← whnfR e | throwError "not abv ·"
let pa' ← mkAppM ``abv_nonneg #[f, a]
pure (.nonnegative pa')
lemma abv_eq_zero {x} : abv x = 0 ↔ x = 0 := abv_eq_zero'
lemma abv_add (x y) : abv (x + y) ≤ abv x + abv y := abv_add' x y
lemma abv_mul (x y) : abv (x * y) = abv x * abv y := abv_mul' x y
/-- A bundled absolute value is an absolute value. -/
instance _root_.AbsoluteValue.isAbsoluteValue (abv : AbsoluteValue R S) : IsAbsoluteValue abv where
abv_nonneg' := abv.nonneg
abv_eq_zero' := abv.eq_zero
abv_add' := abv.add_le
abv_mul' := abv.map_mul
/-- Convert an unbundled `IsAbsoluteValue` to a bundled `AbsoluteValue`. -/
@[simps]
def toAbsoluteValue : AbsoluteValue R S where
toFun := abv
add_le' := abv_add'
eq_zero' _ := abv_eq_zero'
nonneg' := abv_nonneg'
map_mul' := abv_mul'
theorem abv_zero : abv 0 = 0 :=
(toAbsoluteValue abv).map_zero
theorem abv_pos {a : R} : 0 < abv a ↔ a ≠ 0 :=
(toAbsoluteValue abv).pos_iff
end OrderedSemiring
section LinearOrderedRing
variable {S : Type*} [LinearOrderedRing S]
instance abs_isAbsoluteValue : IsAbsoluteValue (abs : S → S) :=
AbsoluteValue.abs.isAbsoluteValue
end LinearOrderedRing
section OrderedRing
variable {S : Type*} [OrderedRing S]
section Semiring
variable {R : Type*} [Semiring R] (abv : R → S) [IsAbsoluteValue abv]
variable [IsDomain S]
theorem abv_one [Nontrivial R] : abv 1 = 1 :=
(toAbsoluteValue abv).map_one
/-- `abv` as a `MonoidWithZeroHom`. -/
def abvHom [Nontrivial R] : R →*₀ S :=
(toAbsoluteValue abv).toMonoidWithZeroHom
theorem abv_pow [Nontrivial R] (abv : R → S) [IsAbsoluteValue abv] (a : R) (n : ℕ) :
abv (a ^ n) = abv a ^ n :=
(toAbsoluteValue abv).map_pow a n
end Semiring
section Ring
variable {R : Type*} [Ring R] (abv : R → S) [IsAbsoluteValue abv]
theorem abv_sub_le (a b c : R) : abv (a - c) ≤ abv (a - b) + abv (b - c) := by
simpa [sub_eq_add_neg, add_assoc] using abv_add abv (a - b) (b - c)
theorem sub_abv_le_abv_sub (a b : R) : abv a - abv b ≤ abv (a - b) :=
(toAbsoluteValue abv).le_sub a b
end Ring
end OrderedRing
section OrderedCommRing
variable [OrderedCommRing S] [NoZeroDivisors S] [Ring R] (abv : R → S) [IsAbsoluteValue abv]
theorem abv_neg (a : R) : abv (-a) = abv a :=
(toAbsoluteValue abv).map_neg a
theorem abv_sub (a b : R) : abv (a - b) = abv (b - a) :=
(toAbsoluteValue abv).map_sub a b
end OrderedCommRing
section LinearOrderedCommRing
variable {S : Type*} [LinearOrderedCommRing S]
section Ring
variable {R : Type*} [Ring R] (abv : R → S) [IsAbsoluteValue abv]
theorem abs_abv_sub_le_abv_sub (a b : R) : abs (abv a - abv b) ≤ abv (a - b) :=
(toAbsoluteValue abv).abs_abv_sub_le_abv_sub a b
end Ring
end LinearOrderedCommRing
section LinearOrderedField
variable {S : Type*} [LinearOrderedSemifield S]
section Semiring
variable {R : Type*} [Semiring R] [Nontrivial R] (abv : R → S) [IsAbsoluteValue abv]
theorem abv_one' : abv 1 = 1 :=
(toAbsoluteValue abv).map_one_of_isLeftRegular <|
(isRegular_of_ne_zero <| (toAbsoluteValue abv).ne_zero one_ne_zero).left
/-- An absolute value as a monoid with zero homomorphism, assuming the target is a semifield. -/
def abvHom' : R →*₀ S where
toFun := abv; map_zero' := abv_zero abv; map_one' := abv_one' abv; map_mul' := abv_mul abv
end Semiring
section DivisionSemiring
variable {R : Type*} [DivisionSemiring R] (abv : R → S) [IsAbsoluteValue abv]
theorem abv_inv (a : R) : abv a⁻¹ = (abv a)⁻¹ :=
map_inv₀ (abvHom' abv) a
theorem abv_div (a b : R) : abv (a / b) = abv a / abv b :=
map_div₀ (abvHom' abv) a b
end DivisionSemiring
end LinearOrderedField
end IsAbsoluteValue
|
Algebra\Order\AddGroupWithTop.lean | /-
Copyright (c) 2016 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura, Mario Carneiro, Johannes Hölzl
-/
import Mathlib.Algebra.Order.Group.Defs
import Mathlib.Algebra.Order.Monoid.WithTop
import Mathlib.Algebra.Group.Hom.Defs
import Mathlib.Algebra.CharZero.Defs
import Mathlib.Algebra.Order.Monoid.Unbundled.OrderDual
import Mathlib.Algebra.Order.Monoid.Canonical.Defs
/-!
# Linearly ordered commutative additive groups and monoids with a top element adjoined
This file sets up a special class of linearly ordered commutative additive monoids
that show up as the target of so-called “valuations” in algebraic number theory.
Usually, in the informal literature, these objects are constructed
by taking a linearly ordered commutative additive group Γ and formally adjoining a
top element: Γ ∪ {⊤}.
The disadvantage is that a type such as `ENNReal` is not of that form,
whereas it is a very common target for valuations.
The solutions is to use a typeclass, and that is exactly what we do in this file.
-/
variable {α β : Type*}
/-- A linearly ordered commutative monoid with an additively absorbing `⊤` element.
Instances should include number systems with an infinite element adjoined. -/
class LinearOrderedAddCommMonoidWithTop (α : Type*) extends LinearOrderedAddCommMonoid α,
OrderTop α where
/-- In a `LinearOrderedAddCommMonoidWithTop`, the `⊤` element is invariant under addition. -/
protected top_add' : ∀ x : α, ⊤ + x = ⊤
/-- A linearly ordered commutative group with an additively absorbing `⊤` element.
Instances should include number systems with an infinite element adjoined. -/
class LinearOrderedAddCommGroupWithTop (α : Type*) extends LinearOrderedAddCommMonoidWithTop α,
SubNegMonoid α, Nontrivial α where
protected neg_top : -(⊤ : α) = ⊤
protected add_neg_cancel : ∀ a : α, a ≠ ⊤ → a + -a = 0
instance WithTop.linearOrderedAddCommMonoidWithTop [LinearOrderedAddCommMonoid α] :
LinearOrderedAddCommMonoidWithTop (WithTop α) :=
{ WithTop.orderTop, WithTop.linearOrder, WithTop.orderedAddCommMonoid with
top_add' := WithTop.top_add }
section LinearOrderedAddCommMonoidWithTop
variable [LinearOrderedAddCommMonoidWithTop α] {a b c d x y z : α} {n : ℕ}
@[simp]
theorem top_add (a : α) : ⊤ + a = ⊤ :=
LinearOrderedAddCommMonoidWithTop.top_add' a
@[simp]
theorem add_top (a : α) : a + ⊤ = ⊤ :=
Trans.trans (add_comm _ _) (top_add _)
end LinearOrderedAddCommMonoidWithTop
namespace WithTop
open Function
namespace LinearOrderedAddCommGroup
variable [LinearOrderedAddCommGroup α] {a b c d : α}
instance instNeg : Neg (WithTop α) where neg := Option.map fun a : α => -a
/-- If `α` has subtraction, we can extend the subtraction to `WithTop α`, by
setting `x - ⊤ = ⊤` and `⊤ - x = ⊤`. This definition is only registered as an instance on linearly
ordered additive commutative groups, to avoid conflicting with the instance `WithTop.instSub` on
types with a bottom element. -/
protected def sub : ∀ _ _ : WithTop α, WithTop α
| _, ⊤ => ⊤
| ⊤, (x : α) => ⊤
| (x : α), (y : α) => (x - y : α)
instance instSub : Sub (WithTop α) where sub := WithTop.LinearOrderedAddCommGroup.sub
@[simp, norm_cast]
theorem coe_neg (a : α) : ((-a : α) : WithTop α) = -a :=
rfl
@[simp]
theorem neg_top : -(⊤ : WithTop α) = ⊤ := rfl
@[simp, norm_cast]
theorem coe_sub {a b : α} : (↑(a - b) : WithTop α) = ↑a - ↑b := rfl
@[simp]
theorem top_sub {a : WithTop α} : (⊤ : WithTop α) - a = ⊤ := by
cases a <;> rfl
@[simp]
theorem sub_top {a : WithTop α} : a - ⊤ = ⊤ := by cases a <;> rfl
@[simp]
lemma sub_eq_top_iff {a b : WithTop α} : a - b = ⊤ ↔ (a = ⊤ ∨ b = ⊤) := by
cases a <;> cases b <;> simp [← coe_sub]
instance : LinearOrderedAddCommGroupWithTop (WithTop α) where
__ := WithTop.linearOrderedAddCommMonoidWithTop
__ := Option.nontrivial
sub_eq_add_neg a b := by
cases a <;> cases b <;> simp [← coe_sub, ← coe_neg, sub_eq_add_neg]
neg_top := Option.map_none
zsmul := zsmulRec
add_neg_cancel := by
rintro (a | a) ha
· exact (ha rfl).elim
· exact (WithTop.coe_add ..).symm.trans (WithTop.coe_eq_coe.2 (add_neg_self a))
end LinearOrderedAddCommGroup
end WithTop
|
Algebra\Order\AddTorsor.lean | /-
Copyright (c) 2024 Scott Carnahan. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Carnahan
-/
import Mathlib.Algebra.Group.Action.Defs
import Mathlib.Algebra.Order.Monoid.Defs
/-!
# Ordered scalar multiplication and vector addition
This file defines ordered scalar multiplication and vector addition, and proves some properties.
In the additive case, a motivating example is given by the additive action of `ℤ` on subsets of
reals that are closed under integer translation. The order compatibility allows for a treatment of
the `R((z))`-module structure on `(z ^ s) V((z))` for an `R`-module `V`, using the formalism of Hahn
series. In the multiplicative case, a standard example is the action of non-negative rationals on
an ordered field.
## Implementation notes
* Because these classes mix the algebra and order hierarchies, we write them as `Prop`-valued
mixins.
* Despite the file name, Ordered AddTorsors are not defined as a separate class. To implement them,
combine `[AddTorsor G P]` with `[IsOrderedCancelVAdd G P]`
## Definitions
* IsOrderedSMul : inequalities are preserved by scalar multiplication.
* IsOrderedVAdd : inequalities are preserved by translation.
* IsCancelSMul : the scalar multiplication version of cancellative multiplication
* IsCancelVAdd : the vector addition version of cancellative addition
* IsOrderedCancelSMul : inequalities are preserved and reflected by scalar multiplication.
* IsOrderedCancelVAdd : inequalities are preserved and reflected by translation.
## Instances
* OrderedCommMonoid.toIsOrderedSMul
* OrderedAddCommMonoid.toIsOrderedVAdd
* IsOrderedSMul.toCovariantClassLeft
* IsOrderedVAdd.toCovariantClassLeft
* IsOrderedCancelSMul.toCancelSMul
* IsOrderedCancelVAdd.toCancelVAdd
* OrderedCancelCommMonoid.toIsOrderedCancelSMul
* OrderedCancelAddCommMonoid.toIsOrderedCancelVAdd
* IsOrderedCancelSMul.toContravariantClassLeft
* IsOrderedCancelVAdd.toContravariantClassLeft
## TODO
* (lex) prod instances
* Pi instances
* WithTop (in a different file?)
-/
open Function
variable {G P : Type*}
/-- An ordered vector addition is a bi-monotone vector addition. -/
class IsOrderedVAdd (G P : Type*) [LE G] [LE P] [VAdd G P] : Prop where
protected vadd_le_vadd_left : ∀ a b : P, a ≤ b → ∀ c : G, c +ᵥ a ≤ c +ᵥ b
protected vadd_le_vadd_right : ∀ c d : G, c ≤ d → ∀ a : P, c +ᵥ a ≤ d +ᵥ a
@[deprecated (since := "2024-07-15")] alias OrderedVAdd := IsOrderedVAdd
/-- An ordered scalar multiplication is a bi-monotone scalar multiplication. Note that this is
different from `OrderedSMul`, which uses strict inequality, requires `G` to be a semiring, and the
defining conditions are restricted to positive elements of `G`. -/
@[to_additive]
class IsOrderedSMul (G P : Type*) [LE G] [LE P] [SMul G P] : Prop where
protected smul_le_smul_left : ∀ a b : P, a ≤ b → ∀ c : G, c • a ≤ c • b
protected smul_le_smul_right : ∀ c d : G, c ≤ d → ∀ a : P, c • a ≤ d • a
@[to_additive]
instance [LE G] [LE P] [SMul G P] [IsOrderedSMul G P] : CovariantClass G P (· • ·) (· ≤ ·) where
elim := fun a _ _ bc ↦ IsOrderedSMul.smul_le_smul_left _ _ bc a
@[to_additive]
instance [OrderedCommMonoid G] : IsOrderedSMul G G where
smul_le_smul_left _ _ := mul_le_mul_left'
smul_le_smul_right _ _ := mul_le_mul_right'
@[to_additive]
theorem IsOrderedSMul.smul_le_smul [Preorder G] [Preorder P] [SMul G P] [IsOrderedSMul G P]
{a b : G} {c d : P} (hab : a ≤ b) (hcd : c ≤ d) : a • c ≤ b • d :=
(IsOrderedSMul.smul_le_smul_left _ _ hcd _).trans (IsOrderedSMul.smul_le_smul_right _ _ hab _)
@[to_additive]
theorem Monotone.smul {γ : Type*} [Preorder G] [Preorder P] [Preorder γ] [SMul G P]
[IsOrderedSMul G P] {f : γ → G} {g : γ → P} (hf : Monotone f) (hg : Monotone g) :
Monotone fun x => f x • g x :=
fun _ _ hab => (IsOrderedSMul.smul_le_smul_left _ _ (hg hab) _).trans
(IsOrderedSMul.smul_le_smul_right _ _ (hf hab) _)
/-- A vector addition is cancellative if it is pointwise injective on the left and right. -/
class IsCancelVAdd (G P : Type*) [VAdd G P] : Prop where
protected left_cancel : ∀ (a : G) (b c : P), a +ᵥ b = a +ᵥ c → b = c
protected right_cancel : ∀ (a b : G) (c : P), a +ᵥ c = b +ᵥ c → a = b
@[deprecated (since := "2024-07-15")] alias CancelVAdd := IsCancelVAdd
/-- A scalar multiplication is cancellative if it is pointwise injective on the left and right. -/
@[to_additive]
class IsCancelSMul (G P : Type*) [SMul G P] : Prop where
protected left_cancel : ∀ (a : G) (b c : P), a • b = a • c → b = c
protected right_cancel : ∀ (a b : G) (c : P), a • c = b • c → a = b
/-- An ordered cancellative vector addition is an ordered vector addition that is cancellative. -/
class IsOrderedCancelVAdd (G P : Type*) [LE G] [LE P] [VAdd G P] extends
IsOrderedVAdd G P : Prop where
protected le_of_vadd_le_vadd_left : ∀ (a : G) (b c : P), a +ᵥ b ≤ a +ᵥ c → b ≤ c
protected le_of_vadd_le_vadd_right : ∀ (a b : G) (c : P), a +ᵥ c ≤ b +ᵥ c → a ≤ b
@[deprecated (since := "2024-07-15")] alias OrderedCancelVAdd := IsOrderedCancelVAdd
/-- An ordered cancellative scalar multiplication is an ordered scalar multiplication that is
cancellative. -/
@[to_additive]
class IsOrderedCancelSMul (G P : Type*) [LE G] [LE P] [SMul G P] extends
IsOrderedSMul G P : Prop where
protected le_of_smul_le_smul_left : ∀ (a : G) (b c : P), a • b ≤ a • c → b ≤ c
protected le_of_smul_le_smul_right : ∀ (a b : G) (c : P), a • c ≤ b • c → a ≤ b
@[to_additive]
instance [PartialOrder G] [PartialOrder P] [SMul G P] [IsOrderedCancelSMul G P] :
IsCancelSMul G P where
left_cancel a b c h := (IsOrderedCancelSMul.le_of_smul_le_smul_left a b c h.le).antisymm
(IsOrderedCancelSMul.le_of_smul_le_smul_left a c b h.ge)
right_cancel a b c h := (IsOrderedCancelSMul.le_of_smul_le_smul_right a b c h.le).antisymm
(IsOrderedCancelSMul.le_of_smul_le_smul_right b a c h.ge)
@[to_additive]
instance [OrderedCancelCommMonoid G] : IsOrderedCancelSMul G G where
le_of_smul_le_smul_left _ _ _ := le_of_mul_le_mul_left'
le_of_smul_le_smul_right _ _ _ := le_of_mul_le_mul_right'
@[to_additive]
instance (priority := 200) [LE G] [LE P] [SMul G P] [IsOrderedCancelSMul G P] :
ContravariantClass G P (· • ·) (· ≤ ·) :=
⟨IsOrderedCancelSMul.le_of_smul_le_smul_left⟩
namespace SMul
@[to_additive]
theorem smul_lt_smul_of_le_of_lt [LE G] [Preorder P] [SMul G P] [IsOrderedCancelSMul G P]
{a b : G} {c d : P} (h₁ : a ≤ b) (h₂ : c < d) :
a • c < b • d := by
refine lt_of_le_of_lt (IsOrderedSMul.smul_le_smul_right a b h₁ c) ?_
refine lt_of_le_not_le (IsOrderedSMul.smul_le_smul_left c d (le_of_lt h₂) b) ?_
by_contra hbdc
have h : d ≤ c := IsOrderedCancelSMul.le_of_smul_le_smul_left b d c hbdc
rw [@lt_iff_le_not_le] at h₂
simp_all only [not_true_eq_false, and_false]
@[to_additive]
theorem smul_lt_smul_of_lt_of_le [Preorder G] [Preorder P] [SMul G P] [IsOrderedCancelSMul G P]
{a b : G} {c d : P} (h₁ : a < b) (h₂ : c ≤ d) : a • c < b • d := by
refine lt_of_le_of_lt (IsOrderedSMul.smul_le_smul_left c d h₂ a) ?_
refine lt_of_le_not_le (IsOrderedSMul.smul_le_smul_right a b (le_of_lt h₁) d) ?_
by_contra hbad
have h : b ≤ a := IsOrderedCancelSMul.le_of_smul_le_smul_right b a d hbad
rw [@lt_iff_le_not_le] at h₁
simp_all only [not_true_eq_false, and_false]
end SMul
|
Algebra\Order\Algebra.lean | /-
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.Algebra.Algebra.Defs
import Mathlib.Algebra.Order.Module.OrderedSMul
/-!
# Ordered algebras
An ordered algebra is an ordered semiring, which is an algebra over an ordered commutative semiring,
for which scalar multiplication is "compatible" with the two orders.
The prototypical example is 2x2 matrices over the reals or complexes (or indeed any C^* algebra)
where the ordering the one determined by the positive cone of positive operators,
i.e. `A ≤ B` iff `B - A = star R * R` for some `R`.
(We don't yet have this example in mathlib.)
## Implementation
Because the axioms for an ordered algebra are exactly the same as those for the underlying
module being ordered, we don't actually introduce a new class, but just use the `OrderedSMul`
mixin.
## Tags
ordered algebra
-/
section OrderedAlgebra
variable {R A : Type*} {a b : A} {r : R}
variable [OrderedCommRing R] [OrderedRing A] [Algebra R A]
variable [OrderedSMul R A]
theorem algebraMap_monotone : Monotone (algebraMap R A) := fun a b h => by
rw [Algebra.algebraMap_eq_smul_one, Algebra.algebraMap_eq_smul_one, ← sub_nonneg, ← sub_smul]
trans (b - a) • (0 : A)
· simp
· exact smul_le_smul_of_nonneg_left zero_le_one (sub_nonneg.mpr h)
end OrderedAlgebra
|
Algebra\Order\Chebyshev.lean | /-
Copyright (c) 2023 Mantas Bakšys, Yaël Dillies. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mantas Bakšys, Yaël Dillies
-/
import Mathlib.Algebra.Order.BigOperators.Group.Finset
import Mathlib.Algebra.Order.Rearrangement
import Mathlib.Algebra.Order.Ring.Basic
import Mathlib.GroupTheory.Perm.Cycle.Basic
/-!
# Chebyshev's sum inequality
This file proves the Chebyshev sum inequality.
Chebyshev's inequality states `(∑ i ∈ s, f i) * (∑ i ∈ s, g i) ≤ s.card * ∑ i ∈ s, f i * g i`
when `f g : ι → α` monovary, and the reverse inequality when `f` and `g` antivary.
## Main declarations
* `MonovaryOn.sum_mul_sum_le_card_mul_sum`: Chebyshev's inequality.
* `AntivaryOn.card_mul_sum_le_sum_mul_sum`: Chebyshev's inequality, dual version.
* `sq_sum_le_card_mul_sum_sq`: Special case of Chebyshev's inequality when `f = g`.
## Implementation notes
In fact, we don't need much compatibility between the addition and multiplication of `α`, so we can
actually decouple them by replacing multiplication with scalar multiplication and making `f` and `g`
land in different types.
As a bonus, this makes the dual statement trivial. The multiplication versions are provided for
convenience.
The case for `Monotone`/`Antitone` pairs of functions over a `LinearOrder` is not deduced in this
file because it is easily deducible from the `Monovary` API.
-/
open Equiv Equiv.Perm Finset Function OrderDual
variable {ι α β : Type*}
/-! ### Scalar multiplication versions -/
section SMul
variable [LinearOrderedRing α] [LinearOrderedAddCommGroup β] [Module α β] [OrderedSMul α β]
{s : Finset ι} {σ : Perm ι} {f : ι → α} {g : ι → β}
/-- **Chebyshev's Sum Inequality**: When `f` and `g` monovary together (eg they are both
monotone/antitone), the scalar product of their sum is less than the size of the set times their
scalar product. -/
theorem MonovaryOn.sum_smul_sum_le_card_smul_sum (hfg : MonovaryOn f g s) :
((∑ i ∈ s, f i) • ∑ i ∈ s, g i) ≤ s.card • ∑ i ∈ s, f i • g i := by
classical
obtain ⟨σ, hσ, hs⟩ := s.countable_toSet.exists_cycleOn
rw [← card_range s.card, sum_smul_sum_eq_sum_perm hσ]
exact
sum_le_card_nsmul _ _ _ fun n _ =>
hfg.sum_smul_comp_perm_le_sum_smul fun x hx => hs fun h => hx <| IsFixedPt.perm_pow h _
/-- **Chebyshev's Sum Inequality**: When `f` and `g` antivary together (eg one is monotone, the
other is antitone), the scalar product of their sum is less than the size of the set times their
scalar product. -/
theorem AntivaryOn.card_smul_sum_le_sum_smul_sum (hfg : AntivaryOn f g s) :
(s.card • ∑ i ∈ s, f i • g i) ≤ (∑ i ∈ s, f i) • ∑ i ∈ s, g i := by
exact hfg.dual_right.sum_smul_sum_le_card_smul_sum
variable [Fintype ι]
/-- **Chebyshev's Sum Inequality**: When `f` and `g` monovary together (eg they are both
monotone/antitone), the scalar product of their sum is less than the size of the set times their
scalar product. -/
theorem Monovary.sum_smul_sum_le_card_smul_sum (hfg : Monovary f g) :
((∑ i, f i) • ∑ i, g i) ≤ Fintype.card ι • ∑ i, f i • g i :=
(hfg.monovaryOn _).sum_smul_sum_le_card_smul_sum
/-- **Chebyshev's Sum Inequality**: When `f` and `g` antivary together (eg one is monotone, the
other is antitone), the scalar product of their sum is less than the size of the set times their
scalar product. -/
theorem Antivary.card_smul_sum_le_sum_smul_sum (hfg : Antivary f g) :
(Fintype.card ι • ∑ i, f i • g i) ≤ (∑ i, f i) • ∑ i, g i := by
exact (hfg.dual_right.monovaryOn _).sum_smul_sum_le_card_smul_sum
end SMul
/-!
### Multiplication versions
Special cases of the above when scalar multiplication is actually multiplication.
-/
section Mul
variable [LinearOrderedRing α] {s : Finset ι} {σ : Perm ι} {f g : ι → α}
/-- **Chebyshev's Sum Inequality**: When `f` and `g` monovary together (eg they are both
monotone/antitone), the product of their sum is less than the size of the set times their scalar
product. -/
theorem MonovaryOn.sum_mul_sum_le_card_mul_sum (hfg : MonovaryOn f g s) :
((∑ i ∈ s, f i) * ∑ i ∈ s, g i) ≤ s.card * ∑ i ∈ s, f i * g i := by
rw [← nsmul_eq_mul]
exact hfg.sum_smul_sum_le_card_smul_sum
/-- **Chebyshev's Sum Inequality**: When `f` and `g` antivary together (eg one is monotone, the
other is antitone), the product of their sum is greater than the size of the set times their scalar
product. -/
theorem AntivaryOn.card_mul_sum_le_sum_mul_sum (hfg : AntivaryOn f g s) :
((s.card : α) * ∑ i ∈ s, f i * g i) ≤ (∑ i ∈ s, f i) * ∑ i ∈ s, g i := by
rw [← nsmul_eq_mul]
exact hfg.card_smul_sum_le_sum_smul_sum
/-- Special case of **Chebyshev's Sum Inequality** or the **Cauchy-Schwarz Inequality**: The square
of the sum is less than the size of the set times the sum of the squares. -/
theorem sq_sum_le_card_mul_sum_sq : (∑ i ∈ s, f i) ^ 2 ≤ s.card * ∑ i ∈ s, f i ^ 2 := by
simp_rw [sq]
exact (monovaryOn_self _ _).sum_mul_sum_le_card_mul_sum
variable [Fintype ι]
/-- **Chebyshev's Sum Inequality**: When `f` and `g` monovary together (eg they are both
monotone/antitone), the product of their sum is less than the size of the set times their scalar
product. -/
theorem Monovary.sum_mul_sum_le_card_mul_sum (hfg : Monovary f g) :
((∑ i, f i) * ∑ i, g i) ≤ Fintype.card ι * ∑ i, f i * g i :=
(hfg.monovaryOn _).sum_mul_sum_le_card_mul_sum
/-- **Chebyshev's Sum Inequality**: When `f` and `g` antivary together (eg one is monotone, the
other is antitone), the product of their sum is less than the size of the set times their scalar
product. -/
theorem Antivary.card_mul_sum_le_sum_mul_sum (hfg : Antivary f g) :
((Fintype.card ι : α) * ∑ i, f i * g i) ≤ (∑ i, f i) * ∑ i, g i :=
(hfg.antivaryOn _).card_mul_sum_le_sum_mul_sum
end Mul
variable [LinearOrderedField α] {s : Finset ι} {f : ι → α}
theorem sum_div_card_sq_le_sum_sq_div_card :
((∑ i ∈ s, f i) / s.card) ^ 2 ≤ (∑ i ∈ s, f i ^ 2) / s.card := by
obtain rfl | hs := s.eq_empty_or_nonempty
· simp
rw [← card_pos, ← @Nat.cast_pos α] at hs
rw [div_pow, div_le_div_iff (sq_pos_of_ne_zero hs.ne') hs, sq (s.card : α), mul_left_comm, ←
mul_assoc]
exact mul_le_mul_of_nonneg_right sq_sum_le_card_mul_sum_sq hs.le
|
Algebra\Order\CompleteField.lean | /-
Copyright (c) 2022 Alex J. Best. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Alex J. Best, Yaël Dillies
-/
import Mathlib.Algebra.Order.Archimedean.Hom
import Mathlib.Algebra.Order.Pointwise
import Mathlib.Analysis.SpecialFunctions.Pow.Real
/-!
# Conditionally complete linear ordered fields
This file shows that the reals are unique, or, more formally, given a type satisfying the common
axioms of the reals (field, conditionally complete, linearly ordered) that there is an isomorphism
preserving these properties to the reals. This is `LinearOrderedField.inducedOrderRingIso` for `ℚ`.
Moreover this isomorphism is unique.
We introduce definitions of conditionally complete linear ordered fields, and show all such are
archimedean. We also construct the natural map from a `LinearOrderedField` to such a field.
## Main definitions
* `ConditionallyCompleteLinearOrderedField`: A field satisfying the standard axiomatization of
the real numbers, being a Dedekind complete and linear ordered field.
* `LinearOrderedField.inducedMap`: A (unique) map from any archimedean linear ordered field to a
conditionally complete linear ordered field. Various bundlings are available.
## Main results
* `LinearOrderedField.uniqueOrderRingHom` : Uniqueness of `OrderRingHom`s from an archimedean
linear ordered field to a conditionally complete linear ordered field.
* `LinearOrderedField.uniqueOrderRingIso` : Uniqueness of `OrderRingIso`s between two
conditionally complete linearly ordered fields.
## References
* https://mathoverflow.net/questions/362991/
who-first-characterized-the-real-numbers-as-the-unique-complete-ordered-field
## Tags
reals, conditionally complete, ordered field, uniqueness
-/
variable {F α β γ : Type*}
noncomputable section
open Function Rat Real Set
open scoped Pointwise
/-- A field which is both linearly ordered and conditionally complete with respect to the order.
This axiomatizes the reals. -/
-- @[protect_proj] -- Porting note: does not exist anymore
class ConditionallyCompleteLinearOrderedField (α : Type*) extends
LinearOrderedField α, ConditionallyCompleteLinearOrder α
-- see Note [lower instance priority]
/-- Any conditionally complete linearly ordered field is archimedean. -/
instance (priority := 100) ConditionallyCompleteLinearOrderedField.to_archimedean
[ConditionallyCompleteLinearOrderedField α] : Archimedean α :=
archimedean_iff_nat_lt.2
(by
by_contra! h
obtain ⟨x, h⟩ := h
have := csSup_le _ _ (range_nonempty Nat.cast)
(forall_mem_range.2 fun m =>
le_sub_iff_add_le.2 <| le_csSup _ _ ⟨x, forall_mem_range.2 h⟩ ⟨m+1, Nat.cast_succ m⟩)
linarith)
/-- The reals are a conditionally complete linearly ordered field. -/
instance : ConditionallyCompleteLinearOrderedField ℝ :=
{ (inferInstance : LinearOrderedField ℝ),
(inferInstance : ConditionallyCompleteLinearOrder ℝ) with }
namespace LinearOrderedField
/-!
### Rational cut map
The idea is that a conditionally complete linear ordered field is fully characterized by its copy of
the rationals. Hence we define `LinearOrderedField.cutMap β : α → Set β` which sends `a : α` to the
"rationals in `β`" that are less than `a`.
-/
section CutMap
variable [LinearOrderedField α]
section DivisionRing
variable (β) [DivisionRing β] {a a₁ a₂ : α} {b : β} {q : ℚ}
/-- The lower cut of rationals inside a linear ordered field that are less than a given element of
another linear ordered field. -/
def cutMap (a : α) : Set β :=
(Rat.cast : ℚ → β) '' {t | ↑t < a}
theorem cutMap_mono (h : a₁ ≤ a₂) : cutMap β a₁ ⊆ cutMap β a₂ := image_subset _ fun _ => h.trans_lt'
variable {β}
@[simp]
theorem mem_cutMap_iff : b ∈ cutMap β a ↔ ∃ q : ℚ, (q : α) < a ∧ (q : β) = b := Iff.rfl
-- @[simp] -- Porting note: not in simpNF
theorem coe_mem_cutMap_iff [CharZero β] : (q : β) ∈ cutMap β a ↔ (q : α) < a :=
Rat.cast_injective.mem_set_image
theorem cutMap_self (a : α) : cutMap α a = Iio a ∩ range (Rat.cast : ℚ → α) := by
ext
constructor
· rintro ⟨q, h, rfl⟩
exact ⟨h, q, rfl⟩
· rintro ⟨h, q, rfl⟩
exact ⟨q, h, rfl⟩
end DivisionRing
variable (β) [LinearOrderedField β] {a a₁ a₂ : α} {b : β} {q : ℚ}
theorem cutMap_coe (q : ℚ) : cutMap β (q : α) = Rat.cast '' {r : ℚ | (r : β) < q} := by
simp_rw [cutMap, Rat.cast_lt]
variable [Archimedean α]
theorem cutMap_nonempty (a : α) : (cutMap β a).Nonempty :=
Nonempty.image _ <| exists_rat_lt a
theorem cutMap_bddAbove (a : α) : BddAbove (cutMap β a) := by
obtain ⟨q, hq⟩ := exists_rat_gt a
exact ⟨q, forall_mem_image.2 fun r hr => mod_cast (hq.trans' hr).le⟩
theorem cutMap_add (a b : α) : cutMap β (a + b) = cutMap β a + cutMap β b := by
refine (image_subset_iff.2 fun q hq => ?_).antisymm ?_
· rw [mem_setOf_eq, ← sub_lt_iff_lt_add] at hq
obtain ⟨q₁, hq₁q, hq₁ab⟩ := exists_rat_btwn hq
refine ⟨q₁, by rwa [coe_mem_cutMap_iff], q - q₁, ?_, add_sub_cancel _ _⟩
norm_cast
rw [coe_mem_cutMap_iff]
exact mod_cast sub_lt_comm.mp hq₁q
· rintro _ ⟨_, ⟨qa, ha, rfl⟩, _, ⟨qb, hb, rfl⟩, rfl⟩
-- After leanprover/lean4#2734, `norm_cast` needs help with beta reduction.
refine ⟨qa + qb, ?_, by beta_reduce; norm_cast⟩
rw [mem_setOf_eq, cast_add]
exact add_lt_add ha hb
end CutMap
/-!
### Induced map
`LinearOrderedField.cutMap` spits out a `Set β`. To get something in `β`, we now take the supremum.
-/
section InducedMap
variable (α β γ) [LinearOrderedField α] [ConditionallyCompleteLinearOrderedField β]
[ConditionallyCompleteLinearOrderedField γ]
/-- The induced order preserving function from a linear ordered field to a conditionally complete
linear ordered field, defined by taking the Sup in the codomain of all the rationals less than the
input. -/
def inducedMap (x : α) : β :=
sSup <| cutMap β x
variable [Archimedean α]
theorem inducedMap_mono : Monotone (inducedMap α β) := fun _ _ h =>
csSup_le_csSup (cutMap_bddAbove β _) (cutMap_nonempty β _) (cutMap_mono β h)
theorem inducedMap_rat (q : ℚ) : inducedMap α β (q : α) = q := by
refine csSup_eq_of_forall_le_of_forall_lt_exists_gt
(cutMap_nonempty β (q : α)) (fun x h => ?_) fun w h => ?_
· rw [cutMap_coe] at h
obtain ⟨r, h, rfl⟩ := h
exact le_of_lt h
· obtain ⟨q', hwq, hq⟩ := exists_rat_btwn h
rw [cutMap_coe]
exact ⟨q', ⟨_, hq, rfl⟩, hwq⟩
@[simp]
theorem inducedMap_zero : inducedMap α β 0 = 0 := mod_cast inducedMap_rat α β 0
@[simp]
theorem inducedMap_one : inducedMap α β 1 = 1 := mod_cast inducedMap_rat α β 1
variable {α β} {a : α} {b : β} {q : ℚ}
theorem inducedMap_nonneg (ha : 0 ≤ a) : 0 ≤ inducedMap α β a :=
(inducedMap_zero α _).ge.trans <| inducedMap_mono _ _ ha
theorem coe_lt_inducedMap_iff : (q : β) < inducedMap α β a ↔ (q : α) < a := by
refine ⟨fun h => ?_, fun hq => ?_⟩
· rw [← inducedMap_rat α] at h
exact (inducedMap_mono α β).reflect_lt h
· obtain ⟨q', hq, hqa⟩ := exists_rat_btwn hq
apply lt_csSup_of_lt (cutMap_bddAbove β a) (coe_mem_cutMap_iff.mpr hqa)
exact mod_cast hq
theorem lt_inducedMap_iff : b < inducedMap α β a ↔ ∃ q : ℚ, b < q ∧ (q : α) < a :=
⟨fun h => (exists_rat_btwn h).imp fun q => And.imp_right coe_lt_inducedMap_iff.1,
fun ⟨q, hbq, hqa⟩ => hbq.trans <| by rwa [coe_lt_inducedMap_iff]⟩
@[simp]
theorem inducedMap_self (b : β) : inducedMap β β b = b :=
eq_of_forall_rat_lt_iff_lt fun _ => coe_lt_inducedMap_iff
variable (α β)
@[simp]
theorem inducedMap_inducedMap (a : α) : inducedMap β γ (inducedMap α β a) = inducedMap α γ a :=
eq_of_forall_rat_lt_iff_lt fun q => by
rw [coe_lt_inducedMap_iff, coe_lt_inducedMap_iff, Iff.comm, coe_lt_inducedMap_iff]
--@[simp] -- Porting note (#10618): simp can prove it
theorem inducedMap_inv_self (b : β) : inducedMap γ β (inducedMap β γ b) = b := by
rw [inducedMap_inducedMap, inducedMap_self]
theorem inducedMap_add (x y : α) :
inducedMap α β (x + y) = inducedMap α β x + inducedMap α β y := by
rw [inducedMap, cutMap_add]
exact csSup_add (cutMap_nonempty β x) (cutMap_bddAbove β x) (cutMap_nonempty β y)
(cutMap_bddAbove β y)
variable {α β}
/-- Preparatory lemma for `inducedOrderRingHom`. -/
theorem le_inducedMap_mul_self_of_mem_cutMap (ha : 0 < a) (b : β) (hb : b ∈ cutMap β (a * a)) :
b ≤ inducedMap α β a * inducedMap α β a := by
obtain ⟨q, hb, rfl⟩ := hb
obtain ⟨q', hq', hqq', hqa⟩ := exists_rat_pow_btwn two_ne_zero hb (mul_self_pos.2 ha.ne')
trans (q' : β) ^ 2
· exact mod_cast hqq'.le
· rw [pow_two] at hqa ⊢
exact mul_self_le_mul_self (mod_cast hq'.le)
(le_csSup (cutMap_bddAbove β a) <|
coe_mem_cutMap_iff.2 <| lt_of_mul_self_lt_mul_self ha.le hqa)
/-- Preparatory lemma for `inducedOrderRingHom`. -/
theorem exists_mem_cutMap_mul_self_of_lt_inducedMap_mul_self (ha : 0 < a) (b : β)
(hba : b < inducedMap α β a * inducedMap α β a) : ∃ c ∈ cutMap β (a * a), b < c := by
obtain hb | hb := lt_or_le b 0
· refine ⟨0, ?_, hb⟩
rw [← Rat.cast_zero, coe_mem_cutMap_iff, Rat.cast_zero]
exact mul_self_pos.2 ha.ne'
obtain ⟨q, hq, hbq, hqa⟩ := exists_rat_pow_btwn two_ne_zero hba (hb.trans_lt hba)
rw [← cast_pow] at hbq
refine ⟨(q ^ 2 : ℚ), coe_mem_cutMap_iff.2 ?_, hbq⟩
rw [pow_two] at hqa ⊢
push_cast
obtain ⟨q', hq', hqa'⟩ := lt_inducedMap_iff.1 (lt_of_mul_self_lt_mul_self
(inducedMap_nonneg ha.le) hqa)
exact mul_self_lt_mul_self (mod_cast hq.le) (hqa'.trans' <| by assumption_mod_cast)
variable (α β)
/-- `inducedMap` as an additive homomorphism. -/
def inducedAddHom : α →+ β :=
⟨⟨inducedMap α β, inducedMap_zero α β⟩, inducedMap_add α β⟩
/-- `inducedMap` as an `OrderRingHom`. -/
@[simps!]
def inducedOrderRingHom : α →+*o β :=
{ AddMonoidHom.mkRingHomOfMulSelfOfTwoNeZero (inducedAddHom α β) (by
suffices ∀ x, 0 < x → inducedAddHom α β (x * x) = inducedAddHom α β x * inducedAddHom α β x by
intro x
obtain h | rfl | h := lt_trichotomy x 0
· convert this (-x) (neg_pos.2 h) using 1
· rw [neg_mul, mul_neg, neg_neg]
· simp_rw [AddMonoidHom.map_neg, neg_mul, mul_neg, neg_neg]
· simp only [mul_zero, AddMonoidHom.map_zero]
· exact this x h
-- prove that the (Sup of rationals less than x) ^ 2 is the Sup of the set of rationals less
-- than (x ^ 2) by showing it is an upper bound and any smaller number is not an upper bound
refine fun x hx => csSup_eq_of_forall_le_of_forall_lt_exists_gt (cutMap_nonempty β _) ?_ ?_
· exact le_inducedMap_mul_self_of_mem_cutMap hx
· exact exists_mem_cutMap_mul_self_of_lt_inducedMap_mul_self hx)
(two_ne_zero) (inducedMap_one _ _) with
monotone' := inducedMap_mono _ _ }
/-- The isomorphism of ordered rings between two conditionally complete linearly ordered fields. -/
def inducedOrderRingIso : β ≃+*o γ :=
{ inducedOrderRingHom β γ with
invFun := inducedMap γ β
left_inv := inducedMap_inv_self _ _
right_inv := inducedMap_inv_self _ _
map_le_map_iff' := by
dsimp
refine ⟨fun h => ?_, fun h => inducedMap_mono _ _ h⟩
convert inducedMap_mono γ β h <;>
· rw [inducedOrderRingHom, AddMonoidHom.coe_fn_mkRingHomOfMulSelfOfTwoNeZero, inducedAddHom]
dsimp
rw [inducedMap_inv_self β γ _] }
@[simp]
theorem coe_inducedOrderRingIso : ⇑(inducedOrderRingIso β γ) = inducedMap β γ := rfl
@[simp]
theorem inducedOrderRingIso_symm : (inducedOrderRingIso β γ).symm = inducedOrderRingIso γ β := rfl
@[simp]
theorem inducedOrderRingIso_self : inducedOrderRingIso β β = OrderRingIso.refl β :=
OrderRingIso.ext inducedMap_self
open OrderRingIso
/-- There is a unique ordered ring homomorphism from an archimedean linear ordered field to a
conditionally complete linear ordered field. -/
instance uniqueOrderRingHom : Unique (α →+*o β) :=
uniqueOfSubsingleton <| inducedOrderRingHom α β
/-- There is a unique ordered ring isomorphism between two conditionally complete linear ordered
fields. -/
instance uniqueOrderRingIso : Unique (β ≃+*o γ) :=
uniqueOfSubsingleton <| inducedOrderRingIso β γ
end InducedMap
end LinearOrderedField
section Real
variable {R S : Type*} [OrderedRing R] [LinearOrderedRing S]
theorem ringHom_monotone (hR : ∀ r : R, 0 ≤ r → ∃ s : R, s ^ 2 = r) (f : R →+* S) : Monotone f :=
(monotone_iff_map_nonneg f).2 fun r h => by
obtain ⟨s, rfl⟩ := hR r h; rw [map_pow]; apply sq_nonneg
/-- There exists no nontrivial ring homomorphism `ℝ →+* ℝ`. -/
instance Real.RingHom.unique : Unique (ℝ →+* ℝ) where
default := RingHom.id ℝ
uniq f := congr_arg OrderRingHom.toRingHom (@Subsingleton.elim (ℝ →+*o ℝ) _
⟨f, ringHom_monotone (fun r hr => ⟨√r, sq_sqrt hr⟩) f⟩ default)
end Real
|
Algebra\Order\EuclideanAbsoluteValue.lean | /-
Copyright (c) 2021 Anne Baanen. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Anne Baanen
-/
import Mathlib.Algebra.Order.AbsoluteValue
import Mathlib.Algebra.EuclideanDomain.Int
/-!
# Euclidean absolute values
This file defines a predicate `AbsoluteValue.IsEuclidean abv` stating the
absolute value is compatible with the Euclidean domain structure on its domain.
## Main definitions
* `AbsoluteValue.IsEuclidean abv` is a predicate on absolute values on `R` mapping to `S`
that preserve the order on `R` arising from the Euclidean domain structure.
* `AbsoluteValue.abs_isEuclidean` shows the "standard" absolute value on `ℤ`,
mapping negative `x` to `-x`, is euclidean.
-/
@[inherit_doc]
local infixl:50 " ≺ " => EuclideanDomain.r
namespace AbsoluteValue
section OrderedSemiring
variable {R S : Type*} [EuclideanDomain R] [OrderedSemiring S]
variable (abv : AbsoluteValue R S)
/-- An absolute value `abv : R → S` is Euclidean if it is compatible with the
`EuclideanDomain` structure on `R`, namely `abv` is strictly monotone with respect to the well
founded relation `≺` on `R`. -/
structure IsEuclidean : Prop where
/-- The requirement of a Euclidean absolute value
that `abv` is monotone with respect to `≺` -/
map_lt_map_iff' : ∀ {x y}, abv x < abv y ↔ x ≺ y
namespace IsEuclidean
variable {abv}
-- Rearrange the parameters to `map_lt_map_iff'` so it elaborates better.
theorem map_lt_map_iff {x y : R} (h : abv.IsEuclidean) : abv x < abv y ↔ x ≺ y :=
map_lt_map_iff' h
attribute [simp] map_lt_map_iff
theorem sub_mod_lt (h : abv.IsEuclidean) (a : R) {b : R} (hb : b ≠ 0) : abv (a % b) < abv b :=
h.map_lt_map_iff.mpr (EuclideanDomain.mod_lt a hb)
end IsEuclidean
end OrderedSemiring
section Int
open Int
-- TODO: generalize to `LinearOrderedEuclideanDomain`s if we ever get a definition of those
/-- `abs : ℤ → ℤ` is a Euclidean absolute value -/
protected theorem abs_isEuclidean : IsEuclidean (AbsoluteValue.abs : AbsoluteValue ℤ ℤ) :=
{ map_lt_map_iff' := fun {x y} =>
show abs x < abs y ↔ natAbs x < natAbs y by rw [abs_eq_natAbs, abs_eq_natAbs, ofNat_lt] }
end Int
end AbsoluteValue
|
Algebra\Order\Floor.lean | /-
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.Nat.Cast.Order.Field
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
/-!
# 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 (↑)
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
/-- `⌈a⌉₊` is the least natural `n` such that `a ≤ n` -/
def ceil : α → ℕ :=
FloorSemiring.ceil
@[simp]
theorem floor_nat : (Nat.floor : ℕ → ℕ) = id :=
rfl
@[simp]
theorem ceil_nat : (Nat.ceil : ℕ → ℕ) = id :=
rfl
@[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
theorem le_floor (h : (n : α) ≤ a) : n ≤ ⌊a⌋₊ :=
(le_floor_iff <| n.cast_nonneg.trans h).2 h
theorem floor_lt (ha : 0 ≤ a) : ⌊a⌋₊ < n ↔ a < n :=
lt_iff_lt_of_le_iff_le <| le_floor_iff ha
theorem floor_lt_one (ha : 0 ≤ a) : ⌊a⌋₊ < 1 ↔ a < 1 :=
(floor_lt ha).trans <| by rw [Nat.cast_one]
theorem lt_of_floor_lt (h : ⌊a⌋₊ < n) : a < n :=
lt_of_not_le fun h' => (le_floor h').not_lt h
theorem lt_one_of_floor_lt_one (h : ⌊a⌋₊ < 1) : a < 1 := mod_cast lt_of_floor_lt h
theorem floor_le (ha : 0 ≤ a) : (⌊a⌋₊ : α) ≤ a :=
(le_floor_iff ha).1 le_rfl
theorem lt_succ_floor (a : α) : a < ⌊a⌋₊.succ :=
lt_of_floor_lt <| Nat.lt_succ_self _
theorem lt_floor_add_one (a : α) : a < ⌊a⌋₊ + 1 := by simpa using lt_succ_floor a
@[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
@[deprecated (since := "2024-06-08")] alias floor_coe := floor_natCast
@[simp]
theorem floor_zero : ⌊(0 : α)⌋₊ = 0 := by rw [← Nat.cast_zero, floor_natCast]
@[simp]
theorem floor_one : ⌊(1 : α)⌋₊ = 1 := by rw [← Nat.cast_one, floor_natCast]
-- 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
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)
@[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
@[simp]
theorem one_le_floor_iff (x : α) : 1 ≤ ⌊x⌋₊ ↔ 1 ≤ x :=
mod_cast @le_floor_iff' α _ _ x 1 one_ne_zero
theorem floor_lt' (hn : n ≠ 0) : ⌊a⌋₊ < n ↔ a < n :=
lt_iff_lt_of_le_iff_le <| le_floor_iff' hn
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]
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
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
theorem floor_le_of_le (h : a ≤ n) : ⌊a⌋₊ ≤ n :=
le_imp_le_iff_lt_imp_lt.2 lt_of_lt_floor h
theorem floor_le_one_of_le_one (h : a ≤ 1) : ⌊a⌋₊ ≤ 1 :=
floor_le_of_le <| h.trans_eq <| Nat.cast_one.symm
@[simp]
theorem floor_eq_zero : ⌊a⌋₊ = 0 ↔ a < 1 := by
rw [← lt_one_iff, ← @cast_one α]
exact floor_lt' Nat.one_ne_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]
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]
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₁⟩
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
@[simp]
theorem preimage_floor_zero : (floor : α → ℕ) ⁻¹' {0} = Iio 1 :=
ext fun _ => floor_eq_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
/-! #### Ceil -/
theorem gc_ceil_coe : GaloisConnection (ceil : α → ℕ) (↑) :=
FloorSemiring.gc_ceil
@[simp]
theorem ceil_le : ⌈a⌉₊ ≤ n ↔ a ≤ n :=
gc_ceil_coe _ _
theorem lt_ceil : n < ⌈a⌉₊ ↔ (n : α) < a :=
lt_iff_lt_of_le_iff_le ceil_le
-- 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]
@[simp]
theorem one_le_ceil_iff : 1 ≤ ⌈a⌉₊ ↔ 0 < a := by
rw [← zero_add 1, Nat.add_one_le_ceil_iff, Nat.cast_zero]
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
theorem le_ceil (a : α) : a ≤ ⌈a⌉₊ :=
ceil_le.1 le_rfl
@[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
@[simp]
theorem ceil_natCast (n : ℕ) : ⌈(n : α)⌉₊ = n :=
eq_of_forall_ge_iff fun a => by rw [ceil_le, cast_le]
theorem ceil_mono : Monotone (ceil : α → ℕ) :=
gc_ceil_coe.monotone_l
@[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]
@[simp]
theorem ceil_one : ⌈(1 : α)⌉₊ = 1 := by rw [← Nat.cast_one, 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
@[simp]
theorem ceil_eq_zero : ⌈a⌉₊ = 0 ↔ a ≤ 0 := by rw [← Nat.le_zero, ceil_le, Nat.cast_zero]
@[simp]
theorem ceil_pos : 0 < ⌈a⌉₊ ↔ 0 < a := by rw [lt_ceil, cast_zero]
theorem lt_of_ceil_lt (h : ⌈a⌉₊ < n) : a < n :=
(le_ceil a).trans_lt (Nat.cast_lt.2 h)
theorem le_of_ceil_le (h : ⌈a⌉₊ ≤ n) : a ≤ n :=
(le_ceil a).trans (Nat.cast_le.2 h)
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 _)
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]
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]
@[simp]
theorem preimage_ceil_zero : (Nat.ceil : α → ℕ) ⁻¹' {0} = Iic 0 :=
ext fun _ => ceil_eq_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
/-! #### 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]
-- 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]
-- 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]
-- 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]
-- 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]
-- 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]
-- 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]
-- 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]
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
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]
-- 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)
@[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)
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]
-- 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
@[bound]
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
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 _)
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
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
-- 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]
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
/-! ### 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 (↑)
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] }
/-- 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 }
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
/-- `Int.ceil a` is the smallest integer `z` such that `a ≤ z`. It is denoted with `⌈a⌉`. -/
def ceil : α → ℤ :=
FloorRing.ceil
/-- `Int.fract a`, the fractional part of `a`, is `a` minus its floor. -/
def fract (a : α) : α :=
a - floor a
@[simp]
theorem floor_int : (Int.floor : ℤ → ℤ) = id :=
rfl
@[simp]
theorem ceil_int : (Int.ceil : ℤ → ℤ) = id :=
rfl
@[simp]
theorem fract_int : (Int.fract : ℤ → ℤ) = 0 :=
funext fun x => by simp [fract]
@[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
@[simp]
theorem floorRing_ceil_eq : @FloorRing.ceil = @Int.ceil :=
rfl
/-! #### Floor -/
theorem gc_coe_floor : GaloisConnection ((↑) : ℤ → α) floor :=
FloorRing.gc_coe_floor
theorem le_floor : z ≤ ⌊a⌋ ↔ (z : α) ≤ a :=
(gc_coe_floor z a).symm
theorem floor_lt : ⌊a⌋ < z ↔ a < z :=
lt_iff_lt_of_le_iff_le le_floor
theorem floor_le (a : α) : (⌊a⌋ : α) ≤ a :=
gc_coe_floor.l_u_le a
theorem floor_nonneg : 0 ≤ ⌊a⌋ ↔ 0 ≤ a := by rw [le_floor, Int.cast_zero]
@[simp]
theorem floor_le_sub_one_iff : ⌊a⌋ ≤ z - 1 ↔ a < z := by rw [← floor_lt, 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]
theorem floor_nonpos (ha : a ≤ 0) : ⌊a⌋ ≤ 0 := by
rw [← @cast_le α, Int.cast_zero]
exact (floor_le a).trans ha
theorem lt_succ_floor (a : α) : a < ⌊a⌋.succ :=
floor_lt.1 <| Int.lt_succ_self _
@[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
@[simp]
theorem sub_one_lt_floor (a : α) : a - 1 < ⌊a⌋ :=
sub_lt_iff_lt_add.2 (lt_floor_add_one a)
@[simp]
theorem floor_intCast (z : ℤ) : ⌊(z : α)⌋ = z :=
eq_of_forall_le_iff fun a => by rw [le_floor, Int.cast_le]
@[simp]
theorem floor_natCast (n : ℕ) : ⌊(n : α)⌋ = n :=
eq_of_forall_le_iff fun a => by rw [le_floor, ← cast_natCast, cast_le]
@[simp]
theorem floor_zero : ⌊(0 : α)⌋ = 0 := by rw [← cast_zero, floor_intCast]
@[simp]
theorem floor_one : ⌊(1 : α)⌋ = 1 := by rw [← cast_one, floor_intCast]
-- 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
@[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]
@[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]
@[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]
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 _)
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 _
@[simp]
theorem floor_int_add (z : ℤ) (a : α) : ⌊↑z + a⌋ = z + ⌊a⌋ := by
simpa only [add_comm] using floor_add_int a z
@[simp]
theorem floor_add_nat (a : α) (n : ℕ) : ⌊a + n⌋ = ⌊a⌋ + n := by
rw [← Int.cast_natCast, floor_add_int]
-- 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]
-- 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 _ _)
@[simp]
theorem floor_sub_nat (a : α) (n : ℕ) : ⌊a - n⌋ = ⌊a⌋ - n := by
rw [← Int.cast_natCast, floor_sub_int]
@[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⟩
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]
@[simp]
theorem floor_eq_zero_iff : ⌊a⌋ = 0 ↔ a ∈ Ico (0 : α) 1 := by simp [floor_eq_iff]
theorem floor_eq_on_Ico (n : ℤ) : ∀ a ∈ Set.Ico (n : α) (n + 1), ⌊a⌋ = n := fun _ ⟨h₀, h₁⟩ =>
floor_eq_iff.mpr ⟨h₀, h₁⟩
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
-- 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
/-! #### Fractional part -/
@[simp]
theorem self_sub_floor (a : α) : a - ⌊a⌋ = fract a :=
rfl
@[simp]
theorem floor_add_fract (a : α) : (⌊a⌋ : α) + fract a = a :=
add_sub_cancel _ _
@[simp]
theorem fract_add_floor (a : α) : fract a + ⌊a⌋ = a :=
sub_add_cancel _ _
@[simp]
theorem fract_add_int (a : α) (m : ℤ) : fract (a + m) = fract a := by
rw [fract]
simp
@[simp]
theorem fract_add_nat (a : α) (m : ℕ) : fract (a + m) = fract a := by
rw [fract]
simp
@[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]
@[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
@[simp]
theorem fract_sub_nat (a : α) (n : ℕ) : fract (a - n) = fract a := by
rw [fract]
simp
@[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
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 _ _
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
@[simp]
theorem self_sub_fract (a : α) : a - fract a = ⌊a⌋ :=
sub_sub_cancel _ _
@[simp]
theorem fract_sub_self (a : α) : fract a - a = -⌊a⌋ :=
sub_sub_cancel_left _ _
@[simp]
theorem fract_nonneg (a : α) : 0 ≤ fract a :=
sub_nonneg.2 <| floor_le _
/-- 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
theorem fract_lt_one (a : α) : fract a < 1 :=
sub_lt_comm.1 <| sub_one_lt_floor _
@[simp]
theorem fract_zero : fract (0 : α) = 0 := by rw [fract, floor_zero, cast_zero, sub_self]
@[simp]
theorem fract_one : fract (1 : α) = 0 := by simp [fract]
theorem abs_fract : |fract a| = fract a :=
abs_eq_self.mpr <| fract_nonneg a
@[simp]
theorem abs_one_sub_fract : |1 - fract a| = 1 - fract a :=
abs_eq_self.mpr <| sub_nonneg.mpr (fract_lt_one a).le
@[simp]
theorem fract_intCast (z : ℤ) : fract (z : α) = 0 := by
unfold fract
rw [floor_intCast]
exact sub_self _
@[simp]
theorem fract_natCast (n : ℕ) : fract (n : α) = 0 := by simp [fract]
-- 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 _
@[simp]
theorem floor_fract (a : α) : ⌊fract a⌋ = 0 := by
rw [floor_eq_iff, Int.cast_zero, zero_add]; exact ⟨fract_nonneg _, fract_lt_one _⟩
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] ⟩
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 _ _ _⟩
@[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⟩
@[simp]
theorem fract_fract (a : α) : fract (fract a) = fract a :=
fract_eq_self.2 ⟨fract_nonneg _, fract_lt_one _⟩
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⟩
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]
@[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]
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
-- 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
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⟩
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))⟩
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]
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 _
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 _
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]
-- 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]
end LinearOrderedField
/-! #### Ceil -/
theorem gc_ceil_coe : GaloisConnection ceil ((↑) : ℤ → α) :=
FloorRing.gc_ceil_coe
theorem ceil_le : ⌈a⌉ ≤ z ↔ a ≤ z :=
gc_ceil_coe a z
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]
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]
theorem lt_ceil : z < ⌈a⌉ ↔ (z : α) < a :=
lt_iff_lt_of_le_iff_le ceil_le
@[simp]
theorem add_one_le_ceil_iff : z + 1 ≤ ⌈a⌉ ↔ (z : α) < a := by rw [← lt_ceil, add_one_le_iff]
@[simp]
theorem one_le_ceil_iff : 1 ≤ ⌈a⌉ ↔ 0 < a := by
rw [← zero_add (1 : ℤ), add_one_le_ceil_iff, cast_zero]
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
@[bound]
theorem le_ceil (a : α) : a ≤ ⌈a⌉ :=
gc_ceil_coe.le_u_l a
@[simp]
theorem ceil_intCast (z : ℤ) : ⌈(z : α)⌉ = z :=
eq_of_forall_ge_iff fun a => by rw [ceil_le, Int.cast_le]
@[simp]
theorem ceil_natCast (n : ℕ) : ⌈(n : α)⌉ = n :=
eq_of_forall_ge_iff fun a => by rw [ceil_le, ← cast_natCast, cast_le]
-- 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
@[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]
@[simp]
theorem ceil_add_nat (a : α) (n : ℕ) : ⌈a + n⌉ = ⌈a⌉ + n := by rw [← Int.cast_natCast, ceil_add_int]
@[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]
-- 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 _ _)
@[simp]
theorem ceil_sub_nat (a : α) (n : ℕ) : ⌈a - n⌉ = ⌈a⌉ - n := by
convert ceil_sub_int a n using 1
simp
@[simp]
theorem ceil_sub_one (a : α) : ⌈a - 1⌉ = ⌈a⌉ - 1 := by
rw [eq_sub_iff_add_eq, ← ceil_add_one, sub_add_cancel]
-- 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
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 _)
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 _
@[simp]
theorem ceil_pos : 0 < ⌈a⌉ ↔ 0 < a := by rw [lt_ceil, cast_zero]
@[simp]
theorem ceil_zero : ⌈(0 : α)⌉ = 0 := by rw [← cast_zero, ceil_intCast]
@[simp]
theorem ceil_one : ⌈(1 : α)⌉ = 1 := by rw [← cast_one, ceil_intCast]
theorem ceil_nonneg (ha : 0 ≤ a) : 0 ≤ ⌈a⌉ := mod_cast ha.trans (le_ceil a)
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]
@[simp]
theorem ceil_eq_zero_iff : ⌈a⌉ = 0 ↔ a ∈ Ioc (-1 : α) 0 := by simp [ceil_eq_iff]
theorem ceil_eq_on_Ioc (z : ℤ) : ∀ a ∈ Set.Ioc (z - 1 : α) z, ⌈a⌉ = z := fun _ ⟨h₀, h₁⟩ =>
ceil_eq_iff.mpr ⟨h₀, h₁⟩
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
theorem floor_le_ceil (a : α) : ⌊a⌋ ≤ ⌈a⌉ :=
cast_le.1 <| (floor_le _).trans <| 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
-- 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
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)
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
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
/-! #### Intervals -/
@[simp]
theorem preimage_Ioo {a b : α} : ((↑) : ℤ → α) ⁻¹' Set.Ioo a b = Set.Ioo ⌊a⌋ ⌈b⌉ := by
ext
simp [floor_lt, lt_ceil]
@[simp]
theorem preimage_Ico {a b : α} : ((↑) : ℤ → α) ⁻¹' Set.Ico a b = Set.Ico ⌈a⌉ ⌈b⌉ := by
ext
simp [ceil_le, lt_ceil]
@[simp]
theorem preimage_Ioc {a b : α} : ((↑) : ℤ → α) ⁻¹' Set.Ioc a b = Set.Ioc ⌊a⌋ ⌊b⌋ := by
ext
simp [floor_lt, le_floor]
@[simp]
theorem preimage_Icc {a b : α} : ((↑) : ℤ → α) ⁻¹' Set.Icc a b = Set.Icc ⌈a⌉ ⌊b⌋ := by
ext
simp [ceil_le, le_floor]
@[simp]
theorem preimage_Ioi : ((↑) : ℤ → α) ⁻¹' Set.Ioi a = Set.Ioi ⌊a⌋ := by
ext
simp [floor_lt]
@[simp]
theorem preimage_Ici : ((↑) : ℤ → α) ⁻¹' Set.Ici a = Set.Ici ⌈a⌉ := by
ext
simp [ceil_le]
@[simp]
theorem preimage_Iio : ((↑) : ℤ → α) ⁻¹' Set.Iio a = Set.Iio ⌈a⌉ := by
ext
simp [lt_ceil]
@[simp]
theorem preimage_Iic : ((↑) : ℤ → α) ⁻¹' Set.Iic a = Set.Iic ⌊a⌋ := by
ext
simp [le_floor]
end Int
open Int
/-! ### Round -/
section round
section LinearOrderedRing
variable [LinearOrderedRing α] [FloorRing α]
/-- `round` rounds a number to the nearest integer. `round (1 / 2) = 1` -/
def round (x : α) : ℤ :=
if 2 * fract x < 1 then ⌊x⌋ else ⌈x⌉
@[simp]
theorem round_zero : round (0 : α) = 0 := by simp [round]
@[simp]
theorem round_one : round (1 : α) = 1 := by simp [round]
@[simp]
theorem round_natCast (n : ℕ) : round (n : α) = n := by simp [round]
-- See note [no_index around OfNat.ofNat]
@[simp]
theorem round_ofNat (n : ℕ) [n.AtLeastTwo] : round (no_index (OfNat.ofNat n : α)) = n :=
round_natCast n
@[simp]
theorem round_intCast (n : ℤ) : round (n : α) = n := by simp [round]
@[simp]
theorem round_add_int (x : α) (y : ℤ) : round (x + y) = round x + y := by
rw [round, round, Int.fract_add_int, Int.floor_add_int, Int.ceil_add_int, ← apply_ite₂, ite_self]
@[simp]
theorem round_add_one (a : α) : round (a + 1) = round a + 1 := by
-- Porting note: broken `convert round_add_int a 1`
rw [← round_add_int a 1, cast_one]
@[simp]
theorem round_sub_int (x : α) (y : ℤ) : round (x - y) = round x - y := by
rw [sub_eq_add_neg]
norm_cast
rw [round_add_int, sub_eq_add_neg]
@[simp]
theorem round_sub_one (a : α) : round (a - 1) = round a - 1 := by
-- Porting note: broken `convert round_sub_int a 1`
rw [← round_sub_int a 1, cast_one]
@[simp]
theorem round_add_nat (x : α) (y : ℕ) : round (x + y) = round x + y :=
mod_cast round_add_int x y
-- See note [no_index around OfNat.ofNat]
@[simp]
theorem round_add_ofNat (x : α) (n : ℕ) [n.AtLeastTwo] :
round (x + (no_index (OfNat.ofNat n))) = round x + OfNat.ofNat n :=
round_add_nat x n
@[simp]
theorem round_sub_nat (x : α) (y : ℕ) : round (x - y) = round x - y :=
mod_cast round_sub_int x y
-- See note [no_index around OfNat.ofNat]
@[simp]
theorem round_sub_ofNat (x : α) (n : ℕ) [n.AtLeastTwo] :
round (x - (no_index (OfNat.ofNat n))) = round x - OfNat.ofNat n :=
round_sub_nat x n
@[simp]
theorem round_int_add (x : α) (y : ℤ) : round ((y : α) + x) = y + round x := by
rw [add_comm, round_add_int, add_comm]
@[simp]
theorem round_nat_add (x : α) (y : ℕ) : round ((y : α) + x) = y + round x := by
rw [add_comm, round_add_nat, add_comm]
-- See note [no_index around OfNat.ofNat]
@[simp]
theorem round_ofNat_add (n : ℕ) [n.AtLeastTwo] (x : α) :
round ((no_index (OfNat.ofNat n)) + x) = OfNat.ofNat n + round x :=
round_nat_add x n
theorem abs_sub_round_eq_min (x : α) : |x - round x| = min (fract x) (1 - fract x) := by
simp_rw [round, min_def_lt, two_mul, ← lt_tsub_iff_left]
cases' lt_or_ge (fract x) (1 - fract x) with hx hx
· rw [if_pos hx, if_pos hx, self_sub_floor, abs_fract]
· have : 0 < fract x := by
replace hx : 0 < fract x + fract x := lt_of_lt_of_le zero_lt_one (tsub_le_iff_left.mp hx)
simpa only [← two_mul, mul_pos_iff_of_pos_left, zero_lt_two] using hx
rw [if_neg (not_lt.mpr hx), if_neg (not_lt.mpr hx), abs_sub_comm, ceil_sub_self_eq this.ne.symm,
abs_one_sub_fract]
theorem round_le (x : α) (z : ℤ) : |x - round x| ≤ |x - z| := by
rw [abs_sub_round_eq_min, min_le_iff]
rcases le_or_lt (z : α) x with (hx | hx) <;> [left; right]
· conv_rhs => rw [abs_eq_self.mpr (sub_nonneg.mpr hx), ← fract_add_floor x, add_sub_assoc]
simpa only [le_add_iff_nonneg_right, sub_nonneg, cast_le] using le_floor.mpr hx
· rw [abs_eq_neg_self.mpr (sub_neg.mpr hx).le]
conv_rhs => rw [← fract_add_floor x]
rw [add_sub_assoc, add_comm, neg_add, neg_sub, le_add_neg_iff_add_le, sub_add_cancel,
le_sub_comm]
norm_cast
exact floor_le_sub_one_iff.mpr hx
end LinearOrderedRing
section LinearOrderedField
variable [LinearOrderedField α] [FloorRing α]
theorem round_eq (x : α) : round x = ⌊x + 1 / 2⌋ := by
simp_rw [round, (by simp only [lt_div_iff', two_pos] : 2 * fract x < 1 ↔ fract x < 1 / 2)]
cases' lt_or_le (fract x) (1 / 2) with hx hx
· conv_rhs => rw [← fract_add_floor x, add_assoc, add_left_comm, floor_int_add]
rw [if_pos hx, self_eq_add_right, floor_eq_iff, cast_zero, zero_add]
constructor
· linarith [fract_nonneg x]
· linarith
· have : ⌊fract x + 1 / 2⌋ = 1 := by
rw [floor_eq_iff]
constructor
· norm_num
linarith
· norm_num
linarith [fract_lt_one x]
rw [if_neg (not_lt.mpr hx), ← fract_add_floor x, add_assoc, add_left_comm, floor_int_add,
ceil_add_int, add_comm _ ⌊x⌋, add_right_inj, ceil_eq_iff, this, cast_one, sub_self]
constructor
· linarith
· linarith [fract_lt_one x]
@[simp]
theorem round_two_inv : round (2⁻¹ : α) = 1 := by
simp only [round_eq, ← one_div, add_halves, floor_one]
@[simp]
theorem round_neg_two_inv : round (-2⁻¹ : α) = 0 := by
simp only [round_eq, ← one_div, add_left_neg, floor_zero]
@[simp]
theorem round_eq_zero_iff {x : α} : round x = 0 ↔ x ∈ Ico (-(1 / 2)) ((1 : α) / 2) := by
rw [round_eq, floor_eq_zero_iff, add_mem_Ico_iff_left]
norm_num
theorem abs_sub_round (x : α) : |x - round x| ≤ 1 / 2 := by
rw [round_eq, abs_sub_le_iff]
have := floor_le (x + 1 / 2)
have := lt_floor_add_one (x + 1 / 2)
constructor <;> linarith
theorem abs_sub_round_div_natCast_eq {m n : ℕ} :
|(m : α) / n - round ((m : α) / n)| = ↑(min (m % n) (n - m % n)) / n := by
rcases n.eq_zero_or_pos with (rfl | hn)
· simp
have hn' : 0 < (n : α) := by
norm_cast
rw [abs_sub_round_eq_min, Nat.cast_min, ← min_div_div_right hn'.le,
fract_div_natCast_eq_div_natCast_mod, Nat.cast_sub (m.mod_lt hn).le, sub_div, div_self hn'.ne']
theorem sub_half_lt_round (x : α) : x - 1 / 2 < round x := by
rw [round_eq x, show x - 1 / 2 = x + 1 / 2 - 1 by nlinarith]
exact Int.sub_one_lt_floor (x + 1 / 2)
theorem round_le_add_half (x : α) : round x ≤ x + 1 / 2 := by
rw [round_eq x]
exact Int.floor_le (x + 1 / 2)
end LinearOrderedField
end round
namespace Nat
variable [LinearOrderedSemiring α] [LinearOrderedSemiring β] [FloorSemiring α] [FloorSemiring β]
variable [FunLike F α β] [RingHomClass F α β] {a : α} {b : β}
theorem floor_congr (h : ∀ n : ℕ, (n : α) ≤ a ↔ (n : β) ≤ b) : ⌊a⌋₊ = ⌊b⌋₊ := by
have h₀ : 0 ≤ a ↔ 0 ≤ b := by simpa only [cast_zero] using h 0
obtain ha | ha := lt_or_le a 0
· rw [floor_of_nonpos ha.le, floor_of_nonpos (le_of_not_le <| h₀.not.mp ha.not_le)]
exact (le_floor <| (h _).1 <| floor_le ha).antisymm (le_floor <| (h _).2 <| floor_le <| h₀.1 ha)
theorem ceil_congr (h : ∀ n : ℕ, a ≤ n ↔ b ≤ n) : ⌈a⌉₊ = ⌈b⌉₊ :=
(ceil_le.2 <| (h _).2 <| le_ceil _).antisymm <| ceil_le.2 <| (h _).1 <| le_ceil _
theorem map_floor (f : F) (hf : StrictMono f) (a : α) : ⌊f a⌋₊ = ⌊a⌋₊ :=
floor_congr fun n => by rw [← map_natCast f, hf.le_iff_le]
theorem map_ceil (f : F) (hf : StrictMono f) (a : α) : ⌈f a⌉₊ = ⌈a⌉₊ :=
ceil_congr fun n => by rw [← map_natCast f, hf.le_iff_le]
end Nat
namespace Int
variable [LinearOrderedRing α] [LinearOrderedRing β] [FloorRing α] [FloorRing β]
variable [FunLike F α β] [RingHomClass F α β] {a : α} {b : β}
theorem floor_congr (h : ∀ n : ℤ, (n : α) ≤ a ↔ (n : β) ≤ b) : ⌊a⌋ = ⌊b⌋ :=
(le_floor.2 <| (h _).1 <| floor_le _).antisymm <| le_floor.2 <| (h _).2 <| floor_le _
theorem ceil_congr (h : ∀ n : ℤ, a ≤ n ↔ b ≤ n) : ⌈a⌉ = ⌈b⌉ :=
(ceil_le.2 <| (h _).2 <| le_ceil _).antisymm <| ceil_le.2 <| (h _).1 <| le_ceil _
theorem map_floor (f : F) (hf : StrictMono f) (a : α) : ⌊f a⌋ = ⌊a⌋ :=
floor_congr fun n => by rw [← map_intCast f, hf.le_iff_le]
theorem map_ceil (f : F) (hf : StrictMono f) (a : α) : ⌈f a⌉ = ⌈a⌉ :=
ceil_congr fun n => by rw [← map_intCast f, hf.le_iff_le]
theorem map_fract (f : F) (hf : StrictMono f) (a : α) : fract (f a) = f (fract a) := by
simp_rw [fract, map_sub, map_intCast, map_floor _ hf]
end Int
namespace Int
variable [LinearOrderedField α] [LinearOrderedField β] [FloorRing α] [FloorRing β]
variable [FunLike F α β] [RingHomClass F α β] {a : α} {b : β}
theorem map_round (f : F) (hf : StrictMono f) (a : α) : round (f a) = round a := by
have H : f 2 = 2 := map_natCast f 2
simp_rw [round_eq, ← map_floor _ hf, map_add, one_div, map_inv₀, H]
-- Porting note: was
-- simp_rw [round_eq, ← map_floor _ hf, map_add, one_div, map_inv₀, map_bit0, map_one]
-- Would have thought that `map_natCast` would replace `map_bit0, map_one` but seems not
end Int
section FloorRingToSemiring
variable [LinearOrderedRing α] [FloorRing α]
/-! #### A floor ring as a floor semiring -/
-- see Note [lower instance priority]
instance (priority := 100) FloorRing.toFloorSemiring : FloorSemiring α where
floor a := ⌊a⌋.toNat
ceil a := ⌈a⌉.toNat
floor_of_neg {a} ha := Int.toNat_of_nonpos (Int.floor_nonpos ha.le)
gc_floor {a n} ha := by rw [Int.le_toNat (Int.floor_nonneg.2 ha), Int.le_floor, Int.cast_natCast]
gc_ceil a n := by rw [Int.toNat_le, Int.ceil_le, Int.cast_natCast]
theorem Int.floor_toNat (a : α) : ⌊a⌋.toNat = ⌊a⌋₊ :=
rfl
theorem Int.ceil_toNat (a : α) : ⌈a⌉.toNat = ⌈a⌉₊ :=
rfl
@[simp]
theorem Nat.floor_int : (Nat.floor : ℤ → ℕ) = Int.toNat :=
rfl
@[simp]
theorem Nat.ceil_int : (Nat.ceil : ℤ → ℕ) = Int.toNat :=
rfl
variable {a : α}
theorem Int.ofNat_floor_eq_floor (ha : 0 ≤ a) : (⌊a⌋₊ : ℤ) = ⌊a⌋ := by
rw [← Int.floor_toNat, Int.toNat_of_nonneg (Int.floor_nonneg.2 ha)]
theorem Int.ofNat_ceil_eq_ceil (ha : 0 ≤ a) : (⌈a⌉₊ : ℤ) = ⌈a⌉ := by
rw [← Int.ceil_toNat, Int.toNat_of_nonneg (Int.ceil_nonneg ha)]
theorem natCast_floor_eq_intCast_floor (ha : 0 ≤ a) : (⌊a⌋₊ : α) = ⌊a⌋ := by
rw [← Int.ofNat_floor_eq_floor ha, Int.cast_natCast]
theorem natCast_ceil_eq_intCast_ceil (ha : 0 ≤ a) : (⌈a⌉₊ : α) = ⌈a⌉ := by
rw [← Int.ofNat_ceil_eq_ceil ha, Int.cast_natCast]
@[deprecated (since := "2024-02-14")] alias Nat.cast_floor_eq_int_floor := Int.ofNat_floor_eq_floor
@[deprecated (since := "2024-02-14")] alias Nat.cast_ceil_eq_int_ceil := Int.ofNat_ceil_eq_ceil
@[deprecated (since := "2024-02-14")]
alias Nat.cast_floor_eq_cast_int_floor := natCast_floor_eq_intCast_floor
@[deprecated (since := "2024-02-14")]
alias Nat.cast_ceil_eq_cast_int_ceil := natCast_ceil_eq_intCast_ceil
end FloorRingToSemiring
/-- There exists at most one `FloorRing` structure on a given linear ordered ring. -/
theorem subsingleton_floorRing {α} [LinearOrderedRing α] : Subsingleton (FloorRing α) := by
refine ⟨fun H₁ H₂ => ?_⟩
have : H₁.floor = H₂.floor :=
funext fun a => (H₁.gc_coe_floor.u_unique H₂.gc_coe_floor) fun _ => rfl
have : H₁.ceil = H₂.ceil := funext fun a => (H₁.gc_ceil_coe.l_unique H₂.gc_ceil_coe) fun _ => rfl
cases H₁; cases H₂; congr
namespace Mathlib.Meta.Positivity
open Lean.Meta Qq
private theorem int_floor_nonneg [LinearOrderedRing α] [FloorRing α] {a : α} (ha : 0 ≤ a) :
0 ≤ ⌊a⌋ :=
Int.floor_nonneg.2 ha
private theorem int_floor_nonneg_of_pos [LinearOrderedRing α] [FloorRing α] {a : α}
(ha : 0 < a) :
0 ≤ ⌊a⌋ :=
int_floor_nonneg ha.le
/-- Extension for the `positivity` tactic: `Int.floor` is nonnegative if its input is. -/
@[positivity ⌊ _ ⌋]
def evalIntFloor : PositivityExt where eval {u α} _zα _pα e := do
match u, α, e with
| 0, ~q(ℤ), ~q(@Int.floor $α' $i $j $a) =>
match ← core q(inferInstance) q(inferInstance) a with
| .positive pa =>
assertInstancesCommute
pure (.nonnegative q(int_floor_nonneg_of_pos (α := $α') $pa))
| .nonnegative pa =>
assertInstancesCommute
pure (.nonnegative q(int_floor_nonneg (α := $α') $pa))
| _ => pure .none
| _, _, _ => throwError "failed to match on Int.floor application"
private theorem nat_ceil_pos [LinearOrderedSemiring α] [FloorSemiring α] {a : α} :
0 < a → 0 < ⌈a⌉₊ :=
Nat.ceil_pos.2
/-- Extension for the `positivity` tactic: `Nat.ceil` is positive if its input is. -/
@[positivity ⌈ _ ⌉₊]
def evalNatCeil : PositivityExt where eval {u α} _zα _pα e := do
match u, α, e with
| 0, ~q(ℕ), ~q(@Nat.ceil $α' $i $j $a) =>
let _i : Q(LinearOrderedSemiring $α') ← synthInstanceQ (u := u_1) _
assertInstancesCommute
match ← core q(inferInstance) q(inferInstance) a with
| .positive pa =>
assertInstancesCommute
pure (.positive q(nat_ceil_pos (α := $α') $pa))
| _ => pure .none
| _, _, _ => throwError "failed to match on Nat.ceil application"
private theorem int_ceil_pos [LinearOrderedRing α] [FloorRing α] {a : α} : 0 < a → 0 < ⌈a⌉ :=
Int.ceil_pos.2
/-- Extension for the `positivity` tactic: `Int.ceil` is positive/nonnegative if its input is. -/
@[positivity ⌈ _ ⌉]
def evalIntCeil : PositivityExt where eval {u α} _zα _pα e := do
match u, α, e with
| 0, ~q(ℤ), ~q(@Int.ceil $α' $i $j $a) =>
match ← core q(inferInstance) q(inferInstance) a with
| .positive pa =>
assertInstancesCommute
pure (.positive q(int_ceil_pos (α := $α') $pa))
| .nonnegative pa =>
assertInstancesCommute
pure (.nonnegative q(Int.ceil_nonneg (α := $α') $pa))
| _ => pure .none
| _, _, _ => throwError "failed to match on Int.ceil application"
end Mathlib.Meta.Positivity
|
Algebra\Order\Invertible.lean | /-
Copyright (c) 2021 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.Order.Ring.Defs
import Mathlib.Algebra.Ring.Invertible
import Mathlib.Data.Nat.Cast.Order.Ring
/-!
# Lemmas about `invOf` in ordered (semi)rings.
-/
variable {α : Type*} [LinearOrderedSemiring α] {a : α}
@[simp]
theorem invOf_pos [Invertible a] : 0 < ⅟ a ↔ 0 < a :=
haveI : 0 < a * ⅟ a := by simp only [mul_invOf_self, zero_lt_one]
⟨fun h => pos_of_mul_pos_left this h.le, fun h => pos_of_mul_pos_right this h.le⟩
@[simp]
theorem invOf_nonpos [Invertible a] : ⅟ a ≤ 0 ↔ a ≤ 0 := by simp only [← not_lt, invOf_pos]
@[simp]
theorem invOf_nonneg [Invertible a] : 0 ≤ ⅟ a ↔ 0 ≤ a :=
haveI : 0 < a * ⅟ a := by simp only [mul_invOf_self, zero_lt_one]
⟨fun h => (pos_of_mul_pos_left this h).le, fun h => (pos_of_mul_pos_right this h).le⟩
@[simp]
theorem invOf_lt_zero [Invertible a] : ⅟ a < 0 ↔ a < 0 := by simp only [← not_le, invOf_nonneg]
@[simp]
theorem invOf_le_one [Invertible a] (h : 1 ≤ a) : ⅟ a ≤ 1 :=
mul_invOf_self a ▸ le_mul_of_one_le_left (invOf_nonneg.2 <| zero_le_one.trans h) h
theorem pos_invOf_of_invertible_cast [Nontrivial α] (n : ℕ)
[Invertible (n : α)] : 0 < ⅟(n : α) :=
invOf_pos.2 <| Nat.cast_pos.2 <| pos_of_invertible_cast (α := α) n
|
Algebra\Order\Kleene.lean | /-
Copyright (c) 2022 Siddhartha Prasad, Yaël Dillies. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Siddhartha Prasad, Yaël Dillies
-/
import Mathlib.Algebra.Order.Monoid.Canonical.Defs
import Mathlib.Algebra.Ring.Pi
import Mathlib.Algebra.Ring.InjSurj
import Mathlib.Tactic.Monotonicity.Attr
import Mathlib.Algebra.Ring.Prod
import Mathlib.Algebra.Order.Monoid.Canonical.Defs
/-!
# Kleene Algebras
This file defines idempotent semirings and Kleene algebras, which are used extensively in the theory
of computation.
An idempotent semiring is a semiring whose addition is idempotent. An idempotent semiring is
naturally a semilattice by setting `a ≤ b` if `a + b = b`.
A Kleene algebra is an idempotent semiring equipped with an additional unary operator `∗`, the
Kleene star.
## Main declarations
* `IdemSemiring`: Idempotent semiring
* `IdemCommSemiring`: Idempotent commutative semiring
* `KleeneAlgebra`: Kleene algebra
## Notation
`a∗` is notation for `kstar a` in locale `Computability`.
## References
* [D. Kozen, *A completeness theorem for Kleene algebras and the algebra of regular events*]
[kozen1994]
* https://planetmath.org/idempotentsemiring
* https://encyclopediaofmath.org/wiki/Idempotent_semi-ring
* https://planetmath.org/kleene_algebra
## TODO
Instances for `AddOpposite`, `MulOpposite`, `ULift`, `Subsemiring`, `Subring`, `Subalgebra`.
## Tags
kleene algebra, idempotent semiring
-/
open Function
universe u
variable {α β ι : Type*} {π : ι → Type*}
/-- An idempotent semiring is a semiring with the additional property that addition is idempotent.
-/
class IdemSemiring (α : Type u) extends Semiring α, SemilatticeSup α where
protected sup := (· + ·)
protected add_eq_sup : ∀ a b : α, a + b = a ⊔ b := by
intros
rfl
/-- The bottom element of an idempotent semiring: `0` by default -/
protected bot : α := 0
protected bot_le : ∀ a, bot ≤ a
/-- An idempotent commutative semiring is a commutative semiring with the additional property that
addition is idempotent. -/
class IdemCommSemiring (α : Type u) extends CommSemiring α, IdemSemiring α
/-- Notation typeclass for the Kleene star `∗`. -/
class KStar (α : Type*) where
/-- The Kleene star operator on a Kleene algebra -/
protected kstar : α → α
@[inherit_doc] scoped[Computability] postfix:1024 "∗" => KStar.kstar
open Computability
/-- A Kleene Algebra is an idempotent semiring with an additional unary operator `kstar` (for Kleene
star) that satisfies the following properties:
* `1 + a * a∗ ≤ a∗`
* `1 + a∗ * a ≤ a∗`
* If `a * c + b ≤ c`, then `a∗ * b ≤ c`
* If `c * a + b ≤ c`, then `b * a∗ ≤ c`
-/
class KleeneAlgebra (α : Type*) extends IdemSemiring α, KStar α where
protected one_le_kstar : ∀ a : α, 1 ≤ a∗
protected mul_kstar_le_kstar : ∀ a : α, a * a∗ ≤ a∗
protected kstar_mul_le_kstar : ∀ a : α, a∗ * a ≤ a∗
protected mul_kstar_le_self : ∀ a b : α, b * a ≤ b → b * a∗ ≤ b
protected kstar_mul_le_self : ∀ a b : α, a * b ≤ b → a∗ * b ≤ b
-- See note [lower instance priority]
instance (priority := 100) IdemSemiring.toOrderBot [IdemSemiring α] : OrderBot α :=
{ ‹IdemSemiring α› with }
-- See note [reducible non-instances]
/-- Construct an idempotent semiring from an idempotent addition. -/
abbrev IdemSemiring.ofSemiring [Semiring α] (h : ∀ a : α, a + a = a) : IdemSemiring α :=
{ ‹Semiring α› with
le := fun a b ↦ a + b = b
le_refl := h
le_trans := fun a b c hab hbc ↦ by
simp only
rw [← hbc, ← add_assoc, hab]
le_antisymm := fun a b hab hba ↦ by rwa [← hba, add_comm]
sup := (· + ·)
le_sup_left := fun a b ↦ by
simp only
rw [← add_assoc, h]
le_sup_right := fun a b ↦ by
simp only
rw [add_comm, add_assoc, h]
sup_le := fun a b c hab hbc ↦ by
simp only
rwa [add_assoc, hbc]
bot := 0
bot_le := zero_add }
section IdemSemiring
variable [IdemSemiring α] {a b c : α}
theorem add_eq_sup (a b : α) : a + b = a ⊔ b :=
IdemSemiring.add_eq_sup _ _
-- Porting note: This simp theorem often leads to timeout when `α` has rich structure.
-- So, this theorem should be scoped.
scoped[Computability] attribute [simp] add_eq_sup
theorem add_idem (a : α) : a + a = a := by simp
theorem nsmul_eq_self : ∀ {n : ℕ} (_ : n ≠ 0) (a : α), n • a = a
| 0, h => (h rfl).elim
| 1, _ => one_nsmul
| n + 2, _ => fun a ↦ by rw [succ_nsmul, nsmul_eq_self n.succ_ne_zero, add_idem]
theorem add_eq_left_iff_le : a + b = a ↔ b ≤ a := by simp
theorem add_eq_right_iff_le : a + b = b ↔ a ≤ b := by simp
alias ⟨_, LE.le.add_eq_left⟩ := add_eq_left_iff_le
alias ⟨_, LE.le.add_eq_right⟩ := add_eq_right_iff_le
theorem add_le_iff : a + b ≤ c ↔ a ≤ c ∧ b ≤ c := by simp
theorem add_le (ha : a ≤ c) (hb : b ≤ c) : a + b ≤ c :=
add_le_iff.2 ⟨ha, hb⟩
-- See note [lower instance priority]
instance (priority := 100) IdemSemiring.toCanonicallyOrderedAddCommMonoid :
CanonicallyOrderedAddCommMonoid α :=
{ ‹IdemSemiring α› with
add_le_add_left := fun a b hbc c ↦ by
simp_rw [add_eq_sup]
exact sup_le_sup_left hbc _
exists_add_of_le := fun h ↦ ⟨_, h.add_eq_right.symm⟩
le_self_add := fun a b ↦ add_eq_right_iff_le.1 <| by rw [← add_assoc, add_idem] }
-- See note [lower instance priority]
instance (priority := 100) IdemSemiring.toCovariantClass_mul_le :
CovariantClass α α (· * ·) (· ≤ ·) :=
⟨fun a b c hbc ↦ add_eq_left_iff_le.1 <| by rw [← mul_add, hbc.add_eq_left]⟩
-- See note [lower instance priority]
instance (priority := 100) IdemSemiring.toCovariantClass_swap_mul_le :
CovariantClass α α (swap (· * ·)) (· ≤ ·) :=
⟨fun a b c hbc ↦ add_eq_left_iff_le.1 <| by rw [← add_mul, hbc.add_eq_left]⟩
end IdemSemiring
section KleeneAlgebra
variable [KleeneAlgebra α] {a b c : α}
@[simp]
theorem one_le_kstar : 1 ≤ a∗ :=
KleeneAlgebra.one_le_kstar _
theorem mul_kstar_le_kstar : a * a∗ ≤ a∗ :=
KleeneAlgebra.mul_kstar_le_kstar _
theorem kstar_mul_le_kstar : a∗ * a ≤ a∗ :=
KleeneAlgebra.kstar_mul_le_kstar _
theorem mul_kstar_le_self : b * a ≤ b → b * a∗ ≤ b :=
KleeneAlgebra.mul_kstar_le_self _ _
theorem kstar_mul_le_self : a * b ≤ b → a∗ * b ≤ b :=
KleeneAlgebra.kstar_mul_le_self _ _
theorem mul_kstar_le (hb : b ≤ c) (ha : c * a ≤ c) : b * a∗ ≤ c :=
(mul_le_mul_right' hb _).trans <| mul_kstar_le_self ha
theorem kstar_mul_le (hb : b ≤ c) (ha : a * c ≤ c) : a∗ * b ≤ c :=
(mul_le_mul_left' hb _).trans <| kstar_mul_le_self ha
theorem kstar_le_of_mul_le_left (hb : 1 ≤ b) : b * a ≤ b → a∗ ≤ b := by
simpa using mul_kstar_le hb
theorem kstar_le_of_mul_le_right (hb : 1 ≤ b) : a * b ≤ b → a∗ ≤ b := by
simpa using kstar_mul_le hb
@[simp]
theorem le_kstar : a ≤ a∗ :=
le_trans (le_mul_of_one_le_left' one_le_kstar) kstar_mul_le_kstar
@[mono]
theorem kstar_mono : Monotone (KStar.kstar : α → α) :=
fun _ _ h ↦
kstar_le_of_mul_le_left one_le_kstar <| kstar_mul_le (h.trans le_kstar) <| mul_kstar_le_kstar
@[simp]
theorem kstar_eq_one : a∗ = 1 ↔ a ≤ 1 :=
⟨le_kstar.trans_eq,
fun h ↦ one_le_kstar.antisymm' <| kstar_le_of_mul_le_left le_rfl <| by rwa [one_mul]⟩
@[simp] lemma kstar_zero : (0 : α)∗ = 1 := kstar_eq_one.2 (zero_le _)
@[simp]
theorem kstar_one : (1 : α)∗ = 1 :=
kstar_eq_one.2 le_rfl
@[simp]
theorem kstar_mul_kstar (a : α) : a∗ * a∗ = a∗ :=
(mul_kstar_le le_rfl <| kstar_mul_le_kstar).antisymm <| le_mul_of_one_le_left' one_le_kstar
@[simp]
theorem kstar_eq_self : a∗ = a ↔ a * a = a ∧ 1 ≤ a :=
⟨fun h ↦ ⟨by rw [← h, kstar_mul_kstar], one_le_kstar.trans_eq h⟩,
fun h ↦ (kstar_le_of_mul_le_left h.2 h.1.le).antisymm le_kstar⟩
@[simp]
theorem kstar_idem (a : α) : a∗∗ = a∗ :=
kstar_eq_self.2 ⟨kstar_mul_kstar _, one_le_kstar⟩
@[simp]
theorem pow_le_kstar : ∀ {n : ℕ}, a ^ n ≤ a∗
| 0 => (pow_zero _).trans_le one_le_kstar
| n + 1 => by
rw [pow_succ']
exact (mul_le_mul_left' pow_le_kstar _).trans mul_kstar_le_kstar
end KleeneAlgebra
namespace Prod
instance instIdemSemiring [IdemSemiring α] [IdemSemiring β] : IdemSemiring (α × β) :=
{ Prod.instSemiring, Prod.instSemilatticeSup _ _, Prod.instOrderBot _ _ with
add_eq_sup := fun _ _ ↦ Prod.ext (add_eq_sup _ _) (add_eq_sup _ _) }
instance [IdemCommSemiring α] [IdemCommSemiring β] : IdemCommSemiring (α × β) :=
{ Prod.instCommSemiring, Prod.instIdemSemiring with }
variable [KleeneAlgebra α] [KleeneAlgebra β]
instance : KleeneAlgebra (α × β) :=
{ Prod.instIdemSemiring with
kstar := fun a ↦ (a.1∗, a.2∗)
one_le_kstar := fun _ ↦ ⟨one_le_kstar, one_le_kstar⟩
mul_kstar_le_kstar := fun _ ↦ ⟨mul_kstar_le_kstar, mul_kstar_le_kstar⟩
kstar_mul_le_kstar := fun _ ↦ ⟨kstar_mul_le_kstar, kstar_mul_le_kstar⟩
mul_kstar_le_self := fun _ _ ↦ And.imp mul_kstar_le_self mul_kstar_le_self
kstar_mul_le_self := fun _ _ ↦ And.imp kstar_mul_le_self kstar_mul_le_self }
theorem kstar_def (a : α × β) : a∗ = (a.1∗, a.2∗) :=
rfl
@[simp]
theorem fst_kstar (a : α × β) : a∗.1 = a.1∗ :=
rfl
@[simp]
theorem snd_kstar (a : α × β) : a∗.2 = a.2∗ :=
rfl
end Prod
namespace Pi
instance instIdemSemiring [∀ i, IdemSemiring (π i)] : IdemSemiring (∀ i, π i) :=
{ Pi.semiring, Pi.instSemilatticeSup, Pi.instOrderBot with
add_eq_sup := fun _ _ ↦ funext fun _ ↦ add_eq_sup _ _ }
instance [∀ i, IdemCommSemiring (π i)] : IdemCommSemiring (∀ i, π i) :=
{ Pi.commSemiring, Pi.instIdemSemiring with }
variable [∀ i, KleeneAlgebra (π i)]
instance : KleeneAlgebra (∀ i, π i) :=
{ Pi.instIdemSemiring with
kstar := fun a i ↦ (a i)∗
one_le_kstar := fun _ _ ↦ one_le_kstar
mul_kstar_le_kstar := fun _ _ ↦ mul_kstar_le_kstar
kstar_mul_le_kstar := fun _ _ ↦ kstar_mul_le_kstar
mul_kstar_le_self := fun _ _ h _ ↦ mul_kstar_le_self <| h _
kstar_mul_le_self := fun _ _ h _ ↦ kstar_mul_le_self <| h _ }
theorem kstar_def (a : ∀ i, π i) : a∗ = fun i ↦ (a i)∗ :=
rfl
@[simp]
theorem kstar_apply (a : ∀ i, π i) (i : ι) : a∗ i = (a i)∗ :=
rfl
end Pi
namespace Function.Injective
-- See note [reducible non-instances]
/-- Pullback an `IdemSemiring` instance along an injective function. -/
protected abbrev idemSemiring [IdemSemiring α] [Zero β] [One β] [Add β] [Mul β] [Pow β ℕ] [SMul ℕ β]
[NatCast β] [Sup β] [Bot β] (f : β → α) (hf : Injective f) (zero : f 0 = 0) (one : f 1 = 1)
(add : ∀ x y, f (x + y) = f x + f y) (mul : ∀ x y, f (x * y) = f x * f y)
(nsmul : ∀ (n : ℕ) (x), f (n • x) = n • f x) (npow : ∀ (x) (n : ℕ), f (x ^ n) = f x ^ n)
(natCast : ∀ n : ℕ, f n = n) (sup : ∀ a b, f (a ⊔ b) = f a ⊔ f b) (bot : f ⊥ = ⊥) :
IdemSemiring β :=
{ hf.semiring f zero one add mul nsmul npow natCast, hf.semilatticeSup _ sup,
‹Bot β› with
add_eq_sup := fun a b ↦ hf <| by erw [sup, add, add_eq_sup]
bot := ⊥
bot_le := fun a ↦ bot.trans_le <| @bot_le _ _ _ <| f a }
-- See note [reducible non-instances]
/-- Pullback an `IdemCommSemiring` instance along an injective function. -/
protected abbrev idemCommSemiring [IdemCommSemiring α] [Zero β] [One β] [Add β] [Mul β] [Pow β ℕ]
[SMul ℕ β] [NatCast β] [Sup β] [Bot β] (f : β → α) (hf : Injective f) (zero : f 0 = 0)
(one : f 1 = 1) (add : ∀ x y, f (x + y) = f x + f y) (mul : ∀ x y, f (x * y) = f x * f y)
(nsmul : ∀ (n : ℕ) (x), f (n • x) = n • f x) (npow : ∀ (x) (n : ℕ), f (x ^ n) = f x ^ n)
(natCast : ∀ n : ℕ, f n = n) (sup : ∀ a b, f (a ⊔ b) = f a ⊔ f b) (bot : f ⊥ = ⊥) :
IdemCommSemiring β :=
{ hf.commSemiring f zero one add mul nsmul npow natCast,
hf.idemSemiring f zero one add mul nsmul npow natCast sup bot with }
-- See note [reducible non-instances]
/-- Pullback a `KleeneAlgebra` instance along an injective function. -/
protected abbrev kleeneAlgebra [KleeneAlgebra α] [Zero β] [One β] [Add β] [Mul β] [Pow β ℕ]
[SMul ℕ β] [NatCast β] [Sup β] [Bot β] [KStar β] (f : β → α) (hf : Injective f) (zero : f 0 = 0)
(one : f 1 = 1) (add : ∀ x y, f (x + y) = f x + f y) (mul : ∀ x y, f (x * y) = f x * f y)
(nsmul : ∀ (n : ℕ) (x), f (n • x) = n • f x) (npow : ∀ (x) (n : ℕ), f (x ^ n) = f x ^ n)
(natCast : ∀ n : ℕ, f n = n) (sup : ∀ a b, f (a ⊔ b) = f a ⊔ f b) (bot : f ⊥ = ⊥)
(kstar : ∀ a, f a∗ = (f a)∗) : KleeneAlgebra β :=
{ hf.idemSemiring f zero one add mul nsmul npow natCast sup bot,
‹KStar β› with
one_le_kstar := fun a ↦ one.trans_le <| by
erw [kstar]
exact one_le_kstar
mul_kstar_le_kstar := fun a ↦ by
change f _ ≤ _
erw [mul, kstar]
exact mul_kstar_le_kstar
kstar_mul_le_kstar := fun a ↦ by
change f _ ≤ _
erw [mul, kstar]
exact kstar_mul_le_kstar
mul_kstar_le_self := fun a b (h : f _ ≤ _) ↦ by
change f _ ≤ _
erw [mul, kstar]
erw [mul] at h
exact mul_kstar_le_self h
kstar_mul_le_self := fun a b (h : f _ ≤ _) ↦ by
change f _ ≤ _
erw [mul, kstar]
erw [mul] at h
exact kstar_mul_le_self h }
end Function.Injective
|
Algebra\Order\Monovary.lean | /-
Copyright (c) 2023 Yaël Dillies. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies
-/
import Mathlib.Algebra.Order.Field.Basic
import Mathlib.Algebra.Order.Group.Instances
import Mathlib.Algebra.Order.Module.OrderedSMul
import Mathlib.Algebra.Order.Monoid.Unbundled.MinMax
import Mathlib.Order.Monotone.Monovary
/-!
# Monovarying functions and algebraic operations
This file characterises the interaction of ordered algebraic structures with monovariance
of functions.
## See also
`Algebra.Order.Rearrangement` for the n-ary rearrangement inequality
-/
variable {ι α β : Type*}
/-! ### Algebraic operations on monovarying functions -/
section OrderedCommGroup
variable [OrderedCommGroup α] [OrderedCommGroup β] {s : Set ι} {f f₁ f₂ : ι → α} {g g₁ g₂ : ι → β}
@[to_additive (attr := simp)]
lemma monovaryOn_inv_left : MonovaryOn f⁻¹ g s ↔ AntivaryOn f g s := by
simp [MonovaryOn, AntivaryOn]
@[to_additive (attr := simp)]
lemma antivaryOn_inv_left : AntivaryOn f⁻¹ g s ↔ MonovaryOn f g s := by
simp [MonovaryOn, AntivaryOn]
@[to_additive (attr := simp)]
lemma monovaryOn_inv_right : MonovaryOn f g⁻¹ s ↔ AntivaryOn f g s := by
simpa [MonovaryOn, AntivaryOn] using forall₂_swap
@[to_additive (attr := simp)]
lemma antivaryOn_inv_right : AntivaryOn f g⁻¹ s ↔ MonovaryOn f g s := by
simpa [MonovaryOn, AntivaryOn] using forall₂_swap
@[to_additive] lemma monovaryOn_inv : MonovaryOn f⁻¹ g⁻¹ s ↔ MonovaryOn f g s := by simp
@[to_additive] lemma antivaryOn_inv : AntivaryOn f⁻¹ g⁻¹ s ↔ AntivaryOn f g s := by simp
@[to_additive (attr := simp)] lemma monovary_inv_left : Monovary f⁻¹ g ↔ Antivary f g := by
simp [Monovary, Antivary]
@[to_additive (attr := simp)] lemma antivary_inv_left : Antivary f⁻¹ g ↔ Monovary f g := by
simp [Monovary, Antivary]
@[to_additive (attr := simp)] lemma monovary_inv_right : Monovary f g⁻¹ ↔ Antivary f g := by
simpa [Monovary, Antivary] using forall_swap
@[to_additive (attr := simp)] lemma antivary_inv_right : Antivary f g⁻¹ ↔ Monovary f g := by
simpa [Monovary, Antivary] using forall_swap
@[to_additive] lemma monovary_inv : Monovary f⁻¹ g⁻¹ ↔ Monovary f g := by simp
@[to_additive] lemma antivary_inv : Antivary f⁻¹ g⁻¹ ↔ Antivary f g := by simp
@[to_additive] alias ⟨MonovaryOn.of_inv_left, AntivaryOn.inv_left⟩ := monovaryOn_inv_left
@[to_additive] alias ⟨AntivaryOn.of_inv_left, MonovaryOn.inv_left⟩ := antivaryOn_inv_left
@[to_additive] alias ⟨MonovaryOn.of_inv_right, AntivaryOn.inv_right⟩ := monovaryOn_inv_right
@[to_additive] alias ⟨AntivaryOn.of_inv_right, MonovaryOn.inv_right⟩ := antivaryOn_inv_right
@[to_additive] alias ⟨MonovaryOn.of_inv, MonovaryOn.inv⟩ := monovaryOn_inv
@[to_additive] alias ⟨AntivaryOn.of_inv, AntivaryOn.inv⟩ := antivaryOn_inv
@[to_additive] alias ⟨Monovary.of_inv_left, Antivary.inv_left⟩ := monovary_inv_left
@[to_additive] alias ⟨Antivary.of_inv_left, Monovary.inv_left⟩ := antivary_inv_left
@[to_additive] alias ⟨Monovary.of_inv_right, Antivary.inv_right⟩ := monovary_inv_right
@[to_additive] alias ⟨Antivary.of_inv_right, Monovary.inv_right⟩ := antivary_inv_right
@[to_additive] alias ⟨Monovary.of_inv, Monovary.inv⟩ := monovary_inv
@[to_additive] alias ⟨Antivary.of_inv, Antivary.inv⟩ := antivary_inv
@[to_additive] lemma MonovaryOn.mul_left (h₁ : MonovaryOn f₁ g s) (h₂ : MonovaryOn f₂ g s) :
MonovaryOn (f₁ * f₂) g s := fun _i hi _j hj hij ↦ mul_le_mul' (h₁ hi hj hij) (h₂ hi hj hij)
@[to_additive] lemma AntivaryOn.mul_left (h₁ : AntivaryOn f₁ g s) (h₂ : AntivaryOn f₂ g s) :
AntivaryOn (f₁ * f₂) g s := fun _i hi _j hj hij ↦ mul_le_mul' (h₁ hi hj hij) (h₂ hi hj hij)
@[to_additive] lemma MonovaryOn.div_left (h₁ : MonovaryOn f₁ g s) (h₂ : AntivaryOn f₂ g s) :
MonovaryOn (f₁ / f₂) g s := fun _i hi _j hj hij ↦ div_le_div'' (h₁ hi hj hij) (h₂ hi hj hij)
@[to_additive] lemma AntivaryOn.div_left (h₁ : AntivaryOn f₁ g s) (h₂ : MonovaryOn f₂ g s) :
AntivaryOn (f₁ / f₂) g s := fun _i hi _j hj hij ↦ div_le_div'' (h₁ hi hj hij) (h₂ hi hj hij)
@[to_additive] lemma MonovaryOn.pow_left (hfg : MonovaryOn f g s) (n : ℕ) :
MonovaryOn (f ^ n) g s := fun _i hi _j hj hij ↦ pow_le_pow_left' (hfg hi hj hij) _
@[to_additive] lemma AntivaryOn.pow_left (hfg : AntivaryOn f g s) (n : ℕ) :
AntivaryOn (f ^ n) g s := fun _i hi _j hj hij ↦ pow_le_pow_left' (hfg hi hj hij) _
@[to_additive]
lemma Monovary.mul_left (h₁ : Monovary f₁ g) (h₂ : Monovary f₂ g) : Monovary (f₁ * f₂) g :=
fun _i _j hij ↦ mul_le_mul' (h₁ hij) (h₂ hij)
@[to_additive]
lemma Antivary.mul_left (h₁ : Antivary f₁ g) (h₂ : Antivary f₂ g) : Antivary (f₁ * f₂) g :=
fun _i _j hij ↦ mul_le_mul' (h₁ hij) (h₂ hij)
@[to_additive]
lemma Monovary.div_left (h₁ : Monovary f₁ g) (h₂ : Antivary f₂ g) : Monovary (f₁ / f₂) g :=
fun _i _j hij ↦ div_le_div'' (h₁ hij) (h₂ hij)
@[to_additive]
lemma Antivary.div_left (h₁ : Antivary f₁ g) (h₂ : Monovary f₂ g) : Antivary (f₁ / f₂) g :=
fun _i _j hij ↦ div_le_div'' (h₁ hij) (h₂ hij)
@[to_additive] lemma Monovary.pow_left (hfg : Monovary f g) (n : ℕ) : Monovary (f ^ n) g :=
fun _i _j hij ↦ pow_le_pow_left' (hfg hij) _
@[to_additive] lemma Antivary.pow_left (hfg : Antivary f g) (n : ℕ) : Antivary (f ^ n) g :=
fun _i _j hij ↦ pow_le_pow_left' (hfg hij) _
end OrderedCommGroup
section LinearOrderedCommGroup
variable [OrderedCommGroup α] [LinearOrderedCommGroup β] {s : Set ι} {f f₁ f₂ : ι → α}
{g g₁ g₂ : ι → β}
@[to_additive] lemma MonovaryOn.mul_right (h₁ : MonovaryOn f g₁ s) (h₂ : MonovaryOn f g₂ s) :
MonovaryOn f (g₁ * g₂) s :=
fun _i hi _j hj hij ↦ (lt_or_lt_of_mul_lt_mul hij).elim (h₁ hi hj) <| h₂ hi hj
@[to_additive] lemma AntivaryOn.mul_right (h₁ : AntivaryOn f g₁ s) (h₂ : AntivaryOn f g₂ s) :
AntivaryOn f (g₁ * g₂) s :=
fun _i hi _j hj hij ↦ (lt_or_lt_of_mul_lt_mul hij).elim (h₁ hi hj) <| h₂ hi hj
@[to_additive] lemma MonovaryOn.div_right (h₁ : MonovaryOn f g₁ s) (h₂ : AntivaryOn f g₂ s) :
MonovaryOn f (g₁ / g₂) s :=
fun _i hi _j hj hij ↦ (lt_or_lt_of_div_lt_div hij).elim (h₁ hi hj) <| h₂ hj hi
@[to_additive] lemma AntivaryOn.div_right (h₁ : AntivaryOn f g₁ s) (h₂ : MonovaryOn f g₂ s) :
AntivaryOn f (g₁ / g₂) s :=
fun _i hi _j hj hij ↦ (lt_or_lt_of_div_lt_div hij).elim (h₁ hi hj) <| h₂ hj hi
@[to_additive] lemma MonovaryOn.pow_right (hfg : MonovaryOn f g s) (n : ℕ) :
MonovaryOn f (g ^ n) s := fun _i hi _j hj hij ↦ hfg hi hj <| lt_of_pow_lt_pow_left' _ hij
@[to_additive] lemma AntivaryOn.pow_right (hfg : AntivaryOn f g s) (n : ℕ) :
AntivaryOn f (g ^ n) s := fun _i hi _j hj hij ↦ hfg hi hj <| lt_of_pow_lt_pow_left' _ hij
@[to_additive] lemma Monovary.mul_right (h₁ : Monovary f g₁) (h₂ : Monovary f g₂) :
Monovary f (g₁ * g₂) :=
fun _i _j hij ↦ (lt_or_lt_of_mul_lt_mul hij).elim (fun h ↦ h₁ h) fun h ↦ h₂ h
@[to_additive] lemma Antivary.mul_right (h₁ : Antivary f g₁) (h₂ : Antivary f g₂) :
Antivary f (g₁ * g₂) :=
fun _i _j hij ↦ (lt_or_lt_of_mul_lt_mul hij).elim (fun h ↦ h₁ h) fun h ↦ h₂ h
@[to_additive] lemma Monovary.div_right (h₁ : Monovary f g₁) (h₂ : Antivary f g₂) :
Monovary f (g₁ / g₂) :=
fun _i _j hij ↦ (lt_or_lt_of_div_lt_div hij).elim (fun h ↦ h₁ h) fun h ↦ h₂ h
@[to_additive] lemma Antivary.div_right (h₁ : Antivary f g₁) (h₂ : Monovary f g₂) :
Antivary f (g₁ / g₂) :=
fun _i _j hij ↦ (lt_or_lt_of_div_lt_div hij).elim (fun h ↦ h₁ h) fun h ↦ h₂ h
@[to_additive] lemma Monovary.pow_right (hfg : Monovary f g) (n : ℕ) : Monovary f (g ^ n) :=
fun _i _j hij ↦ hfg <| lt_of_pow_lt_pow_left' _ hij
@[to_additive] lemma Antivary.pow_right (hfg : Antivary f g) (n : ℕ) : Antivary f (g ^ n) :=
fun _i _j hij ↦ hfg <| lt_of_pow_lt_pow_left' _ hij
end LinearOrderedCommGroup
section OrderedSemiring
variable [OrderedSemiring α] [OrderedSemiring β] {s : Set ι} {f f₁ f₂ : ι → α} {g g₁ g₂ : ι → β}
lemma MonovaryOn.mul_left₀ (hf₁ : ∀ i ∈ s, 0 ≤ f₁ i) (hf₂ : ∀ i ∈ s, 0 ≤ f₂ i)
(h₁ : MonovaryOn f₁ g s) (h₂ : MonovaryOn f₂ g s) : MonovaryOn (f₁ * f₂) g s :=
fun _i hi _j hj hij ↦ mul_le_mul (h₁ hi hj hij) (h₂ hi hj hij) (hf₂ _ hi) (hf₁ _ hj)
lemma AntivaryOn.mul_left₀ (hf₁ : ∀ i ∈ s, 0 ≤ f₁ i) (hf₂ : ∀ i ∈ s, 0 ≤ f₂ i)
(h₁ : AntivaryOn f₁ g s) (h₂ : AntivaryOn f₂ g s) : AntivaryOn (f₁ * f₂) g s :=
fun _i hi _j hj hij ↦ mul_le_mul (h₁ hi hj hij) (h₂ hi hj hij) (hf₂ _ hj) (hf₁ _ hi)
lemma MonovaryOn.pow_left₀ (hf : ∀ i ∈ s, 0 ≤ f i) (hfg : MonovaryOn f g s) (n : ℕ) :
MonovaryOn (f ^ n) g s :=
fun _i hi _j hj hij ↦ pow_le_pow_left (hf _ hi) (hfg hi hj hij) _
lemma AntivaryOn.pow_left₀ (hf : ∀ i ∈ s, 0 ≤ f i) (hfg : AntivaryOn f g s) (n : ℕ) :
AntivaryOn (f ^ n) g s :=
fun _i hi _j hj hij ↦ pow_le_pow_left (hf _ hj) (hfg hi hj hij) _
lemma Monovary.mul_left₀ (hf₁ : 0 ≤ f₁) (hf₂ : 0 ≤ f₂) (h₁ : Monovary f₁ g) (h₂ : Monovary f₂ g) :
Monovary (f₁ * f₂) g := fun _i _j hij ↦ mul_le_mul (h₁ hij) (h₂ hij) (hf₂ _) (hf₁ _)
lemma Antivary.mul_left₀ (hf₁ : 0 ≤ f₁) (hf₂ : 0 ≤ f₂) (h₁ : Antivary f₁ g) (h₂ : Antivary f₂ g) :
Antivary (f₁ * f₂) g := fun _i _j hij ↦ mul_le_mul (h₁ hij) (h₂ hij) (hf₂ _) (hf₁ _)
lemma Monovary.pow_left₀ (hf : 0 ≤ f) (hfg : Monovary f g) (n : ℕ) : Monovary (f ^ n) g :=
fun _i _j hij ↦ pow_le_pow_left (hf _) (hfg hij) _
lemma Antivary.pow_left₀ (hf : 0 ≤ f) (hfg : Antivary f g) (n : ℕ) : Antivary (f ^ n) g :=
fun _i _j hij ↦ pow_le_pow_left (hf _) (hfg hij) _
end OrderedSemiring
section LinearOrderedSemiring
variable [LinearOrderedSemiring α] [LinearOrderedSemiring β] {s : Set ι} {f f₁ f₂ : ι → α}
{g g₁ g₂ : ι → β}
lemma MonovaryOn.mul_right₀ (hg₁ : ∀ i ∈ s, 0 ≤ g₁ i) (hg₂ : ∀ i ∈ s, 0 ≤ g₂ i)
(h₁ : MonovaryOn f g₁ s) (h₂ : MonovaryOn f g₂ s) : MonovaryOn f (g₁ * g₂) s :=
(h₁.symm.mul_left₀ hg₁ hg₂ h₂.symm).symm
lemma AntivaryOn.mul_right₀ (hg₁ : ∀ i ∈ s, 0 ≤ g₁ i) (hg₂ : ∀ i ∈ s, 0 ≤ g₂ i)
(h₁ : AntivaryOn f g₁ s) (h₂ : AntivaryOn f g₂ s) : AntivaryOn f (g₁ * g₂) s :=
(h₁.symm.mul_left₀ hg₁ hg₂ h₂.symm).symm
lemma MonovaryOn.pow_right₀ (hg : ∀ i ∈ s, 0 ≤ g i) (hfg : MonovaryOn f g s) (n : ℕ) :
MonovaryOn f (g ^ n) s := (hfg.symm.pow_left₀ hg _).symm
lemma AntivaryOn.pow_right₀ (hg : ∀ i ∈ s, 0 ≤ g i) (hfg : AntivaryOn f g s) (n : ℕ) :
AntivaryOn f (g ^ n) s := (hfg.symm.pow_left₀ hg _).symm
lemma Monovary.mul_right₀ (hg₁ : 0 ≤ g₁) (hg₂ : 0 ≤ g₂) (h₁ : Monovary f g₁) (h₂ : Monovary f g₂) :
Monovary f (g₁ * g₂) := (h₁.symm.mul_left₀ hg₁ hg₂ h₂.symm).symm
lemma Antivary.mul_right₀ (hg₁ : 0 ≤ g₁) (hg₂ : 0 ≤ g₂) (h₁ : Antivary f g₁) (h₂ : Antivary f g₂) :
Antivary f (g₁ * g₂) := (h₁.symm.mul_left₀ hg₁ hg₂ h₂.symm).symm
lemma Monovary.pow_right₀ (hg : 0 ≤ g) (hfg : Monovary f g) (n : ℕ) : Monovary f (g ^ n) :=
(hfg.symm.pow_left₀ hg _).symm
lemma Antivary.pow_right₀ (hg : 0 ≤ g) (hfg : Antivary f g) (n : ℕ) : Antivary f (g ^ n) :=
(hfg.symm.pow_left₀ hg _).symm
end LinearOrderedSemiring
section LinearOrderedSemifield
variable [LinearOrderedSemifield α] [LinearOrderedSemifield β] {s : Set ι} {f f₁ f₂ : ι → α}
{g g₁ g₂ : ι → β}
@[simp]
lemma monovaryOn_inv_left₀ (hf : ∀ i ∈ s, 0 < f i) : MonovaryOn f⁻¹ g s ↔ AntivaryOn f g s :=
forall₅_congr fun _i hi _j hj _ ↦ inv_le_inv (hf _ hi) (hf _ hj)
@[simp]
lemma antivaryOn_inv_left₀ (hf : ∀ i ∈ s, 0 < f i) : AntivaryOn f⁻¹ g s ↔ MonovaryOn f g s :=
forall₅_congr fun _i hi _j hj _ ↦ inv_le_inv (hf _ hj) (hf _ hi)
@[simp]
lemma monovaryOn_inv_right₀ (hg : ∀ i ∈ s, 0 < g i) : MonovaryOn f g⁻¹ s ↔ AntivaryOn f g s :=
forall₂_swap.trans <| forall₄_congr fun i hi j hj ↦ by erw [inv_lt_inv (hg _ hj) (hg _ hi)]
@[simp]
lemma antivaryOn_inv_right₀ (hg : ∀ i ∈ s, 0 < g i) : AntivaryOn f g⁻¹ s ↔ MonovaryOn f g s :=
forall₂_swap.trans <| forall₄_congr fun i hi j hj ↦ by erw [inv_lt_inv (hg _ hj) (hg _ hi)]
lemma monovaryOn_inv₀ (hf : ∀ i ∈ s, 0 < f i) (hg : ∀ i ∈ s, 0 < g i) :
MonovaryOn f⁻¹ g⁻¹ s ↔ MonovaryOn f g s := by
rw [monovaryOn_inv_left₀ hf, antivaryOn_inv_right₀ hg]
lemma antivaryOn_inv₀ (hf : ∀ i ∈ s, 0 < f i) (hg : ∀ i ∈ s, 0 < g i) :
AntivaryOn f⁻¹ g⁻¹ s ↔ AntivaryOn f g s := by
rw [antivaryOn_inv_left₀ hf, monovaryOn_inv_right₀ hg]
@[simp] lemma monovary_inv_left₀ (hf : StrongLT 0 f) : Monovary f⁻¹ g ↔ Antivary f g :=
forall₃_congr fun _i _j _ ↦ inv_le_inv (hf _) (hf _)
@[simp] lemma antivary_inv_left₀ (hf : StrongLT 0 f) : Antivary f⁻¹ g ↔ Monovary f g :=
forall₃_congr fun _i _j _ ↦ inv_le_inv (hf _) (hf _)
@[simp] lemma monovary_inv_right₀ (hg : StrongLT 0 g) : Monovary f g⁻¹ ↔ Antivary f g :=
forall_swap.trans <| forall₂_congr fun i j ↦ by erw [inv_lt_inv (hg _) (hg _)]
@[simp] lemma antivary_inv_right₀ (hg : StrongLT 0 g) : Antivary f g⁻¹ ↔ Monovary f g :=
forall_swap.trans <| forall₂_congr fun i j ↦ by erw [inv_lt_inv (hg _) (hg _)]
lemma monovary_inv₀ (hf : StrongLT 0 f) (hg : StrongLT 0 g) : Monovary f⁻¹ g⁻¹ ↔ Monovary f g := by
rw [monovary_inv_left₀ hf, antivary_inv_right₀ hg]
lemma antivary_inv₀ (hf : StrongLT 0 f) (hg : StrongLT 0 g) : Antivary f⁻¹ g⁻¹ ↔ Antivary f g := by
rw [antivary_inv_left₀ hf, monovary_inv_right₀ hg]
alias ⟨MonovaryOn.of_inv_left₀, AntivaryOn.inv_left₀⟩ := monovaryOn_inv_left₀
alias ⟨AntivaryOn.of_inv_left₀, MonovaryOn.inv_left₀⟩ := antivaryOn_inv_left₀
alias ⟨MonovaryOn.of_inv_right₀, AntivaryOn.inv_right₀⟩ := monovaryOn_inv_right₀
alias ⟨AntivaryOn.of_inv_right₀, MonovaryOn.inv_right₀⟩ := antivaryOn_inv_right₀
alias ⟨MonovaryOn.of_inv₀, MonovaryOn.inv₀⟩ := monovaryOn_inv₀
alias ⟨AntivaryOn.of_inv₀, AntivaryOn.inv₀⟩ := antivaryOn_inv₀
alias ⟨Monovary.of_inv_left₀, Antivary.inv_left₀⟩ := monovary_inv_left₀
alias ⟨Antivary.of_inv_left₀, Monovary.inv_left₀⟩ := antivary_inv_left₀
alias ⟨Monovary.of_inv_right₀, Antivary.inv_right₀⟩ := monovary_inv_right₀
alias ⟨Antivary.of_inv_right₀, Monovary.inv_right₀⟩ := antivary_inv_right₀
alias ⟨Monovary.of_inv₀, Monovary.inv₀⟩ := monovary_inv₀
alias ⟨Antivary.of_inv₀, Antivary.inv₀⟩ := antivary_inv₀
lemma MonovaryOn.div_left₀ (hf₁ : ∀ i ∈ s, 0 ≤ f₁ i) (hf₂ : ∀ i ∈ s, 0 < f₂ i)
(h₁ : MonovaryOn f₁ g s) (h₂ : AntivaryOn f₂ g s) : MonovaryOn (f₁ / f₂) g s :=
fun _i hi _j hj hij ↦ div_le_div (hf₁ _ hj) (h₁ hi hj hij) (hf₂ _ hj) <| h₂ hi hj hij
lemma AntivaryOn.div_left₀ (hf₁ : ∀ i ∈ s, 0 ≤ f₁ i) (hf₂ : ∀ i ∈ s, 0 < f₂ i)
(h₁ : AntivaryOn f₁ g s) (h₂ : MonovaryOn f₂ g s) : AntivaryOn (f₁ / f₂) g s :=
fun _i hi _j hj hij ↦ div_le_div (hf₁ _ hi) (h₁ hi hj hij) (hf₂ _ hi) <| h₂ hi hj hij
lemma Monovary.div_left₀ (hf₁ : 0 ≤ f₁) (hf₂ : StrongLT 0 f₂) (h₁ : Monovary f₁ g)
(h₂ : Antivary f₂ g) : Monovary (f₁ / f₂) g :=
fun _i _j hij ↦ div_le_div (hf₁ _) (h₁ hij) (hf₂ _) <| h₂ hij
lemma Antivary.div_left₀ (hf₁ : 0 ≤ f₁) (hf₂ : StrongLT 0 f₂) (h₁ : Antivary f₁ g)
(h₂ : Monovary f₂ g) : Antivary (f₁ / f₂) g :=
fun _i _j hij ↦ div_le_div (hf₁ _) (h₁ hij) (hf₂ _) <| h₂ hij
lemma MonovaryOn.div_right₀ (hg₁ : ∀ i ∈ s, 0 ≤ g₁ i) (hg₂ : ∀ i ∈ s, 0 < g₂ i)
(h₁ : MonovaryOn f g₁ s) (h₂ : AntivaryOn f g₂ s) : MonovaryOn f (g₁ / g₂) s :=
(h₁.symm.div_left₀ hg₁ hg₂ h₂.symm).symm
lemma AntivaryOn.div_right₀ (hg₁ : ∀ i ∈ s, 0 ≤ g₁ i) (hg₂ : ∀ i ∈ s, 0 < g₂ i)
(h₁ : AntivaryOn f g₁ s) (h₂ : MonovaryOn f g₂ s) : AntivaryOn f (g₁ / g₂) s :=
(h₁.symm.div_left₀ hg₁ hg₂ h₂.symm).symm
lemma Monovary.div_right₀ (hg₁ : 0 ≤ g₁) (hg₂ : StrongLT 0 g₂) (h₁ : Monovary f g₁)
(h₂ : Antivary f g₂) : Monovary f (g₁ / g₂) := (h₁.symm.div_left₀ hg₁ hg₂ h₂.symm).symm
lemma Antivary.div_right₀ (hg₁ : 0 ≤ g₁) (hg₂ : StrongLT 0 g₂) (h₁ : Antivary f g₁)
(h₂ : Monovary f g₂) : Antivary f (g₁ / g₂) := (h₁.symm.div_left₀ hg₁ hg₂ h₂.symm).symm
end LinearOrderedSemifield
/-! ### Rearrangement inequality characterisation -/
section LinearOrderedAddCommGroup
variable [LinearOrderedRing α] [LinearOrderedAddCommGroup β] [Module α β]
[OrderedSMul α β] {f : ι → α} {g : ι → β} {s : Set ι} {a a₁ a₂ : α} {b b₁ b₂ : β}
lemma monovaryOn_iff_forall_smul_nonneg :
MonovaryOn f g s ↔ ∀ ⦃i⦄, i ∈ s → ∀ ⦃j⦄, j ∈ s → 0 ≤ (f j - f i) • (g j - g i) := by
simp_rw [smul_nonneg_iff_pos_imp_nonneg, sub_pos, sub_nonneg, forall_and]
exact (and_iff_right_of_imp MonovaryOn.symm).symm
lemma antivaryOn_iff_forall_smul_nonpos :
AntivaryOn f g s ↔ ∀ ⦃i⦄, i ∈ s → ∀ ⦃j⦄, j ∈ s → (f j - f i) • (g j - g i) ≤ 0 :=
monovaryOn_toDual_right.symm.trans <| by rw [monovaryOn_iff_forall_smul_nonneg]; rfl
lemma monovary_iff_forall_smul_nonneg : Monovary f g ↔ ∀ i j, 0 ≤ (f j - f i) • (g j - g i) :=
monovaryOn_univ.symm.trans <| monovaryOn_iff_forall_smul_nonneg.trans <| by
simp only [Set.mem_univ, forall_true_left]
lemma antivary_iff_forall_smul_nonpos : Antivary f g ↔ ∀ i j, (f j - f i) • (g j - g i) ≤ 0 :=
monovary_toDual_right.symm.trans <| by rw [monovary_iff_forall_smul_nonneg]; rfl
/-- Two functions monovary iff the rearrangement inequality holds. -/
lemma monovaryOn_iff_smul_rearrangement :
MonovaryOn f g s ↔
∀ ⦃i⦄, i ∈ s → ∀ ⦃j⦄, j ∈ s → f i • g j + f j • g i ≤ f i • g i + f j • g j :=
monovaryOn_iff_forall_smul_nonneg.trans <| forall₄_congr fun i _ j _ ↦ by
simp [smul_sub, sub_smul, ← add_sub_right_comm, le_sub_iff_add_le, add_comm (f i • g i),
add_comm (f i • g j)]
/-- Two functions antivary iff the rearrangement inequality holds. -/
lemma antivaryOn_iff_smul_rearrangement :
AntivaryOn f g s ↔
∀ ⦃i⦄, i ∈ s → ∀ ⦃j⦄, j ∈ s → f i • g i + f j • g j ≤ f i • g j + f j • g i :=
monovaryOn_toDual_right.symm.trans <| by rw [monovaryOn_iff_smul_rearrangement]; rfl
/-- Two functions monovary iff the rearrangement inequality holds. -/
lemma monovary_iff_smul_rearrangement :
Monovary f g ↔ ∀ i j, f i • g j + f j • g i ≤ f i • g i + f j • g j :=
monovaryOn_univ.symm.trans <| monovaryOn_iff_smul_rearrangement.trans <| by
simp only [Set.mem_univ, forall_true_left]
/-- Two functions antivary iff the rearrangement inequality holds. -/
lemma antivary_iff_smul_rearrangement :
Antivary f g ↔ ∀ i j, f i • g i + f j • g j ≤ f i • g j + f j • g i :=
monovary_toDual_right.symm.trans <| by rw [monovary_iff_smul_rearrangement]; rfl
alias ⟨MonovaryOn.sub_smul_sub_nonneg, _⟩ := monovaryOn_iff_forall_smul_nonneg
alias ⟨AntivaryOn.sub_smul_sub_nonpos, _⟩ := antivaryOn_iff_forall_smul_nonpos
alias ⟨Monovary.sub_smul_sub_nonneg, _⟩ := monovary_iff_forall_smul_nonneg
alias ⟨Antivary.sub_smul_sub_nonpos, _⟩ := antivary_iff_forall_smul_nonpos
alias ⟨Monovary.smul_add_smul_le_smul_add_smul, _⟩ := monovary_iff_smul_rearrangement
alias ⟨Antivary.smul_add_smul_le_smul_add_smul, _⟩ := antivary_iff_smul_rearrangement
alias ⟨MonovaryOn.smul_add_smul_le_smul_add_smul, _⟩ := monovaryOn_iff_smul_rearrangement
alias ⟨AntivaryOn.smul_add_smul_le_smul_add_smul, _⟩ := antivaryOn_iff_smul_rearrangement
end LinearOrderedAddCommGroup
section LinearOrderedRing
variable [LinearOrderedRing α] {f g : ι → α} {s : Set ι} {a b c d : α}
lemma monovaryOn_iff_forall_mul_nonneg :
MonovaryOn f g s ↔ ∀ ⦃i⦄, i ∈ s → ∀ ⦃j⦄, j ∈ s → 0 ≤ (f j - f i) * (g j - g i) := by
simp only [smul_eq_mul, monovaryOn_iff_forall_smul_nonneg]
lemma antivaryOn_iff_forall_mul_nonpos :
AntivaryOn f g s ↔ ∀ ⦃i⦄, i ∈ s → ∀ ⦃j⦄, j ∈ s → (f j - f i) * (g j - g i) ≤ 0 := by
simp only [smul_eq_mul, antivaryOn_iff_forall_smul_nonpos]
lemma monovary_iff_forall_mul_nonneg : Monovary f g ↔ ∀ i j, 0 ≤ (f j - f i) * (g j - g i) := by
simp only [smul_eq_mul, monovary_iff_forall_smul_nonneg]
lemma antivary_iff_forall_mul_nonpos : Antivary f g ↔ ∀ i j, (f j - f i) * (g j - g i) ≤ 0 := by
simp only [smul_eq_mul, antivary_iff_forall_smul_nonpos]
/-- Two functions monovary iff the rearrangement inequality holds. -/
lemma monovaryOn_iff_mul_rearrangement :
MonovaryOn f g s ↔
∀ ⦃i⦄, i ∈ s → ∀ ⦃j⦄, j ∈ s → f i * g j + f j * g i ≤ f i * g i + f j * g j := by
simp only [smul_eq_mul, monovaryOn_iff_smul_rearrangement]
/-- Two functions antivary iff the rearrangement inequality holds. -/
lemma antivaryOn_iff_mul_rearrangement :
AntivaryOn f g s ↔
∀ ⦃i⦄, i ∈ s → ∀ ⦃j⦄, j ∈ s → f i * g i + f j * g j ≤ f i * g j + f j * g i := by
simp only [smul_eq_mul, antivaryOn_iff_smul_rearrangement]
/-- Two functions monovary iff the rearrangement inequality holds. -/
lemma monovary_iff_mul_rearrangement :
Monovary f g ↔ ∀ i j, f i * g j + f j * g i ≤ f i * g i + f j * g j := by
simp only [smul_eq_mul, monovary_iff_smul_rearrangement]
/-- Two functions antivary iff the rearrangement inequality holds. -/
lemma antivary_iff_mul_rearrangement :
Antivary f g ↔ ∀ i j, f i * g i + f j * g j ≤ f i * g j + f j * g i := by
simp only [smul_eq_mul, antivary_iff_smul_rearrangement]
alias ⟨MonovaryOn.sub_mul_sub_nonneg, _⟩ := monovaryOn_iff_forall_mul_nonneg
alias ⟨AntivaryOn.sub_mul_sub_nonpos, _⟩ := antivaryOn_iff_forall_mul_nonpos
alias ⟨Monovary.sub_mul_sub_nonneg, _⟩ := monovary_iff_forall_mul_nonneg
alias ⟨Antivary.sub_mul_sub_nonpos, _⟩ := antivary_iff_forall_mul_nonpos
alias ⟨Monovary.mul_add_mul_le_mul_add_mul, _⟩ := monovary_iff_mul_rearrangement
alias ⟨Antivary.mul_add_mul_le_mul_add_mul, _⟩ := antivary_iff_mul_rearrangement
alias ⟨MonovaryOn.mul_add_mul_le_mul_add_mul, _⟩ := monovaryOn_iff_mul_rearrangement
alias ⟨AntivaryOn.mul_add_mul_le_mul_add_mul, _⟩ := antivaryOn_iff_mul_rearrangement
end LinearOrderedRing
|
Algebra\Order\Pi.lean | /-
Copyright (c) 2018 Simon Hudon. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Simon Hudon, Patrick Massot
-/
import Mathlib.Algebra.Order.Monoid.Canonical.Defs
import Mathlib.Algebra.Order.Ring.Defs
import Mathlib.Algebra.Ring.Pi
import Mathlib.Algebra.Order.Monoid.Canonical.Defs
/-!
# Pi instances for ordered groups and monoids
This file defines instances for ordered group, monoid, and related structures on Pi types.
-/
variable {ι I α β γ : Type*}
-- The indexing type
variable {f : I → Type*}
-- The family of types already equipped with instances
variable (x y : ∀ i, f i) (i : I)
namespace Pi
/-- The product of a family of ordered commutative monoids is an ordered commutative monoid. -/
@[to_additive
"The product of a family of ordered additive commutative monoids is
an ordered additive commutative monoid."]
instance orderedCommMonoid {ι : Type*} {Z : ι → Type*} [∀ i, OrderedCommMonoid (Z i)] :
OrderedCommMonoid (∀ i, Z i) where
__ := Pi.partialOrder
__ := Pi.commMonoid
mul_le_mul_left _ _ w _ := fun i => mul_le_mul_left' (w i) _
@[to_additive]
instance existsMulOfLe {ι : Type*} {α : ι → Type*} [∀ i, LE (α i)] [∀ i, Mul (α i)]
[∀ i, ExistsMulOfLE (α i)] : ExistsMulOfLE (∀ i, α i) :=
⟨fun h =>
⟨fun i => (exists_mul_of_le <| h i).choose,
funext fun i => (exists_mul_of_le <| h i).choose_spec⟩⟩
/-- The product of a family of canonically ordered monoids is a canonically ordered monoid. -/
@[to_additive
"The product of a family of canonically ordered additive monoids is
a canonically ordered additive monoid."]
instance {ι : Type*} {Z : ι → Type*} [∀ i, CanonicallyOrderedCommMonoid (Z i)] :
CanonicallyOrderedCommMonoid (∀ i, Z i) where
__ := Pi.instOrderBot
__ := Pi.orderedCommMonoid
__ := Pi.existsMulOfLe
le_self_mul _ _ := fun _ => le_self_mul
@[to_additive]
instance orderedCancelCommMonoid [∀ i, OrderedCancelCommMonoid <| f i] :
OrderedCancelCommMonoid (∀ i : I, f i) where
__ := Pi.commMonoid
le_of_mul_le_mul_left _ _ _ h i := le_of_mul_le_mul_left' (h i)
mul_le_mul_left _ _ c h i := mul_le_mul_left' (c i) (h i)
@[to_additive]
instance orderedCommGroup [∀ i, OrderedCommGroup <| f i] : OrderedCommGroup (∀ i : I, f i) where
__ := Pi.commGroup
__ := Pi.orderedCommMonoid
npow := Monoid.npow
instance orderedSemiring [∀ i, OrderedSemiring (f i)] : OrderedSemiring (∀ i, f i) where
__ := Pi.semiring
__ := Pi.partialOrder
add_le_add_left _ _ hab _ := fun _ => add_le_add_left (hab _) _
zero_le_one := fun i => zero_le_one (α := f i)
mul_le_mul_of_nonneg_left _ _ _ hab hc := fun _ => mul_le_mul_of_nonneg_left (hab _) <| hc _
mul_le_mul_of_nonneg_right _ _ _ hab hc := fun _ => mul_le_mul_of_nonneg_right (hab _) <| hc _
instance orderedCommSemiring [∀ i, OrderedCommSemiring (f i)] : OrderedCommSemiring (∀ i, f i) where
__ := Pi.commSemiring
__ := Pi.orderedSemiring
instance orderedRing [∀ i, OrderedRing (f i)] : OrderedRing (∀ i, f i) where
__ := Pi.ring
__ := Pi.orderedSemiring
mul_nonneg _ _ ha hb := fun _ => mul_nonneg (ha _) (hb _)
instance orderedCommRing [∀ i, OrderedCommRing (f i)] : OrderedCommRing (∀ i, f i) where
__ := Pi.commRing
__ := Pi.orderedRing
end Pi
namespace Function
section const
variable (β) [One α] [Preorder α] {a : α}
@[to_additive const_nonneg_of_nonneg]
theorem one_le_const_of_one_le (ha : 1 ≤ a) : 1 ≤ const β a := fun _ => ha
@[to_additive]
theorem const_le_one_of_le_one (ha : a ≤ 1) : const β a ≤ 1 := fun _ => ha
variable {β} [Nonempty β]
@[to_additive (attr := simp) const_nonneg]
theorem one_le_const : 1 ≤ const β a ↔ 1 ≤ a :=
const_le_const
@[to_additive (attr := simp) const_pos]
theorem one_lt_const : 1 < const β a ↔ 1 < a :=
const_lt_const
@[to_additive (attr := simp)]
theorem const_le_one : const β a ≤ 1 ↔ a ≤ 1 :=
const_le_const
@[to_additive (attr := simp) const_neg']
theorem const_lt_one : const β a < 1 ↔ a < 1 :=
const_lt_const
end const
section extend
variable [One γ] [LE γ] {f : α → β} {g : α → γ} {e : β → γ}
@[to_additive extend_nonneg] lemma one_le_extend (hg : 1 ≤ g) (he : 1 ≤ e) : 1 ≤ extend f g e :=
fun _b ↦ by classical exact one_le_dite (fun _ ↦ hg _) (fun _ ↦ he _)
@[to_additive] lemma extend_le_one (hg : g ≤ 1) (he : e ≤ 1) : extend f g e ≤ 1 :=
fun _b ↦ by classical exact dite_le_one (fun _ ↦ hg _) (fun _ ↦ he _)
end extend
end Function
-- Porting note: Tactic code not ported yet
-- namespace Tactic
-- open Function
-- variable (ι) [Zero α] {a : α}
-- private theorem function_const_nonneg_of_pos [Preorder α] (ha : 0 < a) : 0 ≤ const ι a :=
-- const_nonneg_of_nonneg _ ha.le
-- variable [Nonempty ι]
-- private theorem function_const_ne_zero : a ≠ 0 → const ι a ≠ 0 :=
-- const_ne_zero.2
-- private theorem function_const_pos [Preorder α] : 0 < a → 0 < const ι a :=
-- const_pos.2
-- /-- Extension for the `positivity` tactic: `Function.const` is positive/nonnegative/nonzero if
-- its input is. -/
-- @[positivity]
-- unsafe def positivity_const : expr → tactic strictness
-- | q(Function.const $(ι) $(a)) => do
-- let strict_a ← core a
-- match strict_a with
-- | positive p =>
-- positive <$> to_expr ``(function_const_pos $(ι) $(p)) <|>
-- nonnegative <$> to_expr ``(function_const_nonneg_of_pos $(ι) $(p))
-- | nonnegative p => nonnegative <$> to_expr ``(const_nonneg_of_nonneg $(ι) $(p))
-- | nonzero p => nonzero <$> to_expr ``(function_const_ne_zero $(ι) $(p))
-- | e =>
-- pp e >>= fail ∘ format.bracket "The expression `" "` is not of the form `Function.const ι a`"
-- end Tactic
|
Algebra\Order\Pointwise.lean | /-
Copyright (c) 2021 Alex J. Best. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Alex J. Best, Yaël Dillies
-/
import Mathlib.Algebra.Bounds
import Mathlib.Algebra.Order.Field.Basic -- Porting note: `LinearOrderedField`, etc
import Mathlib.Data.Set.Pointwise.SMul
/-!
# Pointwise operations on ordered algebraic objects
This file contains lemmas about the effect of pointwise operations on sets with an order structure.
## TODO
`sSup (s • t) = sSup s • sSup t` and `sInf (s • t) = sInf s • sInf t` hold as well but
`CovariantClass` is currently not polymorphic enough to state it.
-/
open Function Set
open Pointwise
variable {α : Type*}
-- Porting note: Swapped the place of `CompleteLattice` and `ConditionallyCompleteLattice`
-- due to simpNF problem between `sSup_xx` `csSup_xx`.
section CompleteLattice
variable [CompleteLattice α]
section One
variable [One α]
@[to_additive (attr := simp)]
theorem sSup_one : sSup (1 : Set α) = 1 :=
sSup_singleton
@[to_additive (attr := simp)]
theorem sInf_one : sInf (1 : Set α) = 1 :=
sInf_singleton
end One
section Group
variable [Group α] [CovariantClass α α (· * ·) (· ≤ ·)] [CovariantClass α α (swap (· * ·)) (· ≤ ·)]
(s t : Set α)
@[to_additive]
theorem sSup_inv (s : Set α) : sSup s⁻¹ = (sInf s)⁻¹ := by
rw [← image_inv, sSup_image]
exact ((OrderIso.inv α).map_sInf _).symm
@[to_additive]
theorem sInf_inv (s : Set α) : sInf s⁻¹ = (sSup s)⁻¹ := by
rw [← image_inv, sInf_image]
exact ((OrderIso.inv α).map_sSup _).symm
@[to_additive]
theorem sSup_mul : sSup (s * t) = sSup s * sSup t :=
(sSup_image2_eq_sSup_sSup fun _ => (OrderIso.mulRight _).to_galoisConnection) fun _ =>
(OrderIso.mulLeft _).to_galoisConnection
@[to_additive]
theorem sInf_mul : sInf (s * t) = sInf s * sInf t :=
(sInf_image2_eq_sInf_sInf fun _ => (OrderIso.mulRight _).symm.to_galoisConnection) fun _ =>
(OrderIso.mulLeft _).symm.to_galoisConnection
@[to_additive]
theorem sSup_div : sSup (s / t) = sSup s / sInf t := by simp_rw [div_eq_mul_inv, sSup_mul, sSup_inv]
@[to_additive]
theorem sInf_div : sInf (s / t) = sInf s / sSup t := by simp_rw [div_eq_mul_inv, sInf_mul, sInf_inv]
end Group
end CompleteLattice
section ConditionallyCompleteLattice
variable [ConditionallyCompleteLattice α]
section One
variable [One α]
@[to_additive (attr := simp)]
theorem csSup_one : sSup (1 : Set α) = 1 :=
csSup_singleton _
@[to_additive (attr := simp)]
theorem csInf_one : sInf (1 : Set α) = 1 :=
csInf_singleton _
end One
section Group
variable [Group α] [CovariantClass α α (· * ·) (· ≤ ·)] [CovariantClass α α (swap (· * ·)) (· ≤ ·)]
{s t : Set α}
@[to_additive]
theorem csSup_inv (hs₀ : s.Nonempty) (hs₁ : BddBelow s) : sSup s⁻¹ = (sInf s)⁻¹ := by
rw [← image_inv]
exact ((OrderIso.inv α).map_csInf' hs₀ hs₁).symm
@[to_additive]
theorem csInf_inv (hs₀ : s.Nonempty) (hs₁ : BddAbove s) : sInf s⁻¹ = (sSup s)⁻¹ := by
rw [← image_inv]
exact ((OrderIso.inv α).map_csSup' hs₀ hs₁).symm
@[to_additive]
theorem csSup_mul (hs₀ : s.Nonempty) (hs₁ : BddAbove s) (ht₀ : t.Nonempty) (ht₁ : BddAbove t) :
sSup (s * t) = sSup s * sSup t :=
csSup_image2_eq_csSup_csSup (fun _ => (OrderIso.mulRight _).to_galoisConnection)
(fun _ => (OrderIso.mulLeft _).to_galoisConnection) hs₀ hs₁ ht₀ ht₁
@[to_additive]
theorem csInf_mul (hs₀ : s.Nonempty) (hs₁ : BddBelow s) (ht₀ : t.Nonempty) (ht₁ : BddBelow t) :
sInf (s * t) = sInf s * sInf t :=
csInf_image2_eq_csInf_csInf (fun _ => (OrderIso.mulRight _).symm.to_galoisConnection)
(fun _ => (OrderIso.mulLeft _).symm.to_galoisConnection) hs₀ hs₁ ht₀ ht₁
@[to_additive]
theorem csSup_div (hs₀ : s.Nonempty) (hs₁ : BddAbove s) (ht₀ : t.Nonempty) (ht₁ : BddBelow t) :
sSup (s / t) = sSup s / sInf t := by
rw [div_eq_mul_inv, csSup_mul hs₀ hs₁ ht₀.inv ht₁.inv, csSup_inv ht₀ ht₁, div_eq_mul_inv]
@[to_additive]
theorem csInf_div (hs₀ : s.Nonempty) (hs₁ : BddBelow s) (ht₀ : t.Nonempty) (ht₁ : BddAbove t) :
sInf (s / t) = sInf s / sSup t := by
rw [div_eq_mul_inv, csInf_mul hs₀ hs₁ ht₀.inv ht₁.inv, csInf_inv ht₀ ht₁, div_eq_mul_inv]
end Group
end ConditionallyCompleteLattice
namespace LinearOrderedField
variable {K : Type*} [LinearOrderedField K] {a b r : K} (hr : 0 < r)
open Set
theorem smul_Ioo : r • Ioo a b = Ioo (r • a) (r • b) := by
ext x
simp only [mem_smul_set, smul_eq_mul, mem_Ioo]
constructor
· rintro ⟨a, ⟨a_h_left_left, a_h_left_right⟩, rfl⟩
constructor
· exact (mul_lt_mul_left hr).mpr a_h_left_left
· exact (mul_lt_mul_left hr).mpr a_h_left_right
· rintro ⟨a_left, a_right⟩
use x / r
refine ⟨⟨(lt_div_iff' hr).mpr a_left, (div_lt_iff' hr).mpr a_right⟩, ?_⟩
rw [mul_div_cancel₀ _ (ne_of_gt hr)]
theorem smul_Icc : r • Icc a b = Icc (r • a) (r • b) := by
ext x
simp only [mem_smul_set, smul_eq_mul, mem_Icc]
constructor
· rintro ⟨a, ⟨a_h_left_left, a_h_left_right⟩, rfl⟩
constructor
· exact (mul_le_mul_left hr).mpr a_h_left_left
· exact (mul_le_mul_left hr).mpr a_h_left_right
· rintro ⟨a_left, a_right⟩
use x / r
refine ⟨⟨(le_div_iff' hr).mpr a_left, (div_le_iff' hr).mpr a_right⟩, ?_⟩
rw [mul_div_cancel₀ _ (ne_of_gt hr)]
theorem smul_Ico : r • Ico a b = Ico (r • a) (r • b) := by
ext x
simp only [mem_smul_set, smul_eq_mul, mem_Ico]
constructor
· rintro ⟨a, ⟨a_h_left_left, a_h_left_right⟩, rfl⟩
constructor
· exact (mul_le_mul_left hr).mpr a_h_left_left
· exact (mul_lt_mul_left hr).mpr a_h_left_right
· rintro ⟨a_left, a_right⟩
use x / r
refine ⟨⟨(le_div_iff' hr).mpr a_left, (div_lt_iff' hr).mpr a_right⟩, ?_⟩
rw [mul_div_cancel₀ _ (ne_of_gt hr)]
theorem smul_Ioc : r • Ioc a b = Ioc (r • a) (r • b) := by
ext x
simp only [mem_smul_set, smul_eq_mul, mem_Ioc]
constructor
· rintro ⟨a, ⟨a_h_left_left, a_h_left_right⟩, rfl⟩
constructor
· exact (mul_lt_mul_left hr).mpr a_h_left_left
· exact (mul_le_mul_left hr).mpr a_h_left_right
· rintro ⟨a_left, a_right⟩
use x / r
refine ⟨⟨(lt_div_iff' hr).mpr a_left, (div_le_iff' hr).mpr a_right⟩, ?_⟩
rw [mul_div_cancel₀ _ (ne_of_gt hr)]
theorem smul_Ioi : r • Ioi a = Ioi (r • a) := by
ext x
simp only [mem_smul_set, smul_eq_mul, mem_Ioi]
constructor
· rintro ⟨a_w, a_h_left, rfl⟩
exact (mul_lt_mul_left hr).mpr a_h_left
· rintro h
use x / r
constructor
· exact (lt_div_iff' hr).mpr h
· exact mul_div_cancel₀ _ (ne_of_gt hr)
theorem smul_Iio : r • Iio a = Iio (r • a) := by
ext x
simp only [mem_smul_set, smul_eq_mul, mem_Iio]
constructor
· rintro ⟨a_w, a_h_left, rfl⟩
exact (mul_lt_mul_left hr).mpr a_h_left
· rintro h
use x / r
constructor
· exact (div_lt_iff' hr).mpr h
· exact mul_div_cancel₀ _ (ne_of_gt hr)
theorem smul_Ici : r • Ici a = Ici (r • a) := by
ext x
simp only [mem_smul_set, smul_eq_mul, mem_Ioi]
constructor
· rintro ⟨a_w, a_h_left, rfl⟩
exact (mul_le_mul_left hr).mpr a_h_left
· rintro h
use x / r
constructor
· exact (le_div_iff' hr).mpr h
· exact mul_div_cancel₀ _ (ne_of_gt hr)
theorem smul_Iic : r • Iic a = Iic (r • a) := by
ext x
simp only [mem_smul_set, smul_eq_mul, mem_Iio]
constructor
· rintro ⟨a_w, a_h_left, rfl⟩
exact (mul_le_mul_left hr).mpr a_h_left
· rintro h
use x / r
constructor
· exact (div_le_iff' hr).mpr h
· exact mul_div_cancel₀ _ (ne_of_gt hr)
end LinearOrderedField
|
Algebra\Order\Rearrangement.lean | /-
Copyright (c) 2022 Mantas Bakšys. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mantas Bakšys
-/
import Mathlib.Algebra.BigOperators.Group.Finset
import Mathlib.Algebra.Order.Module.OrderedSMul
import Mathlib.Algebra.Order.Group.Instances
import Mathlib.Data.Prod.Lex
import Mathlib.Data.Set.Image
import Mathlib.GroupTheory.Perm.Support
import Mathlib.Order.Monotone.Monovary
import Mathlib.Tactic.Abel
/-!
# Rearrangement inequality
This file proves the rearrangement inequality and deduces the conditions for equality and strict
inequality.
The rearrangement inequality tells you that for two functions `f g : ι → α`, the sum
`∑ i, f i * g (σ i)` is maximized over all `σ : Perm ι` when `g ∘ σ` monovaries with `f` and
minimized when `g ∘ σ` antivaries with `f`.
The inequality also tells you that `∑ i, f i * g (σ i) = ∑ i, f i * g i` if and only if `g ∘ σ`
monovaries with `f` when `g` monovaries with `f`. The above equality also holds if and only if
`g ∘ σ` antivaries with `f` when `g` antivaries with `f`.
From the above two statements, we deduce that the inequality is strict if and only if `g ∘ σ` does
not monovary with `f` when `g` monovaries with `f`. Analogously, the inequality is strict if and
only if `g ∘ σ` does not antivary with `f` when `g` antivaries with `f`.
## Implementation notes
In fact, we don't need much compatibility between the addition and multiplication of `α`, so we can
actually decouple them by replacing multiplication with scalar multiplication and making `f` and `g`
land in different types.
As a bonus, this makes the dual statement trivial. The multiplication versions are provided for
convenience.
The case for `Monotone`/`Antitone` pairs of functions over a `LinearOrder` is not deduced in this
file because it is easily deducible from the `Monovary` API.
-/
open Equiv Equiv.Perm Finset Function OrderDual
variable {ι α β : Type*}
/-! ### Scalar multiplication versions -/
section SMul
variable [LinearOrderedRing α] [LinearOrderedAddCommGroup β] [Module α β] [OrderedSMul α β]
{s : Finset ι} {σ : Perm ι} {f : ι → α} {g : ι → β}
/-- **Rearrangement Inequality**: Pointwise scalar multiplication of `f` and `g` is maximized when
`f` and `g` monovary together. Stated by permuting the entries of `g`. -/
theorem MonovaryOn.sum_smul_comp_perm_le_sum_smul (hfg : MonovaryOn f g s)
(hσ : {x | σ x ≠ x} ⊆ s) : ∑ i ∈ s, f i • g (σ i) ≤ ∑ i ∈ s, f i • g i := by
classical
revert hσ σ hfg
-- Porting note: Specify `p` to get around `∀ {σ}` in the current goal.
apply Finset.induction_on_max_value (fun i ↦ toLex (g i, f i))
(p := fun t ↦ ∀ {σ : Perm ι}, MonovaryOn f g t → {x | σ x ≠ x} ⊆ t →
∑ i ∈ t, f i • g (σ i) ≤ ∑ i ∈ t, f i • g i) s
· simp only [le_rfl, Finset.sum_empty, imp_true_iff]
intro a s has hamax hind σ hfg hσ
set τ : Perm ι := σ.trans (swap a (σ a)) with hτ
have hτs : {x | τ x ≠ x} ⊆ s := by
intro x hx
simp only [τ, Ne, Set.mem_setOf_eq, Equiv.coe_trans, Equiv.swap_comp_apply] at hx
split_ifs at hx with h₁ h₂
· obtain rfl | hax := eq_or_ne x a
· contradiction
· exact mem_of_mem_insert_of_ne (hσ fun h ↦ hax <| h.symm.trans h₁) hax
· exact (hx <| σ.injective h₂.symm).elim
· exact mem_of_mem_insert_of_ne (hσ hx) (ne_of_apply_ne _ h₂)
specialize hind (hfg.subset <| subset_insert _ _) hτs
simp_rw [sum_insert has]
refine le_trans ?_ (add_le_add_left hind _)
obtain hσa | hσa := eq_or_ne a (σ a)
· rw [hτ, ← hσa, swap_self, trans_refl]
have h1s : σ⁻¹ a ∈ s := by
rw [Ne, ← inv_eq_iff_eq] at hσa
refine mem_of_mem_insert_of_ne (hσ fun h ↦ hσa ?_) hσa
rwa [apply_inv_self, eq_comm] at h
simp only [← s.sum_erase_add _ h1s, add_comm]
rw [← add_assoc, ← add_assoc]
simp only [hτ, swap_apply_left, Function.comp_apply, Equiv.coe_trans, apply_inv_self]
refine add_le_add (smul_add_smul_le_smul_add_smul' ?_ ?_) (sum_congr rfl fun x hx ↦ ?_).le
· specialize hamax (σ⁻¹ a) h1s
rw [Prod.Lex.le_iff] at hamax
cases' hamax with hamax hamax
· exact hfg (mem_insert_of_mem h1s) (mem_insert_self _ _) hamax
· exact hamax.2
· specialize hamax (σ a) (mem_of_mem_insert_of_ne (hσ <| σ.injective.ne hσa.symm) hσa.symm)
rw [Prod.Lex.le_iff] at hamax
cases' hamax with hamax hamax
· exact hamax.le
· exact hamax.1.le
· rw [mem_erase, Ne, eq_inv_iff_eq] at hx
rw [swap_apply_of_ne_of_ne hx.1 (σ.injective.ne _)]
rintro rfl
exact has hx.2
/-- **Equality case of the Rearrangement Inequality**: Pointwise scalar multiplication of `f` and
`g`, which monovary together, is unchanged by a permutation if and only if `f` and `g ∘ σ` monovary
together. Stated by permuting the entries of `g`. -/
theorem MonovaryOn.sum_smul_comp_perm_eq_sum_smul_iff (hfg : MonovaryOn f g s)
(hσ : {x | σ x ≠ x} ⊆ s) :
∑ i ∈ s, f i • g (σ i) = ∑ i ∈ s, f i • g i ↔ MonovaryOn f (g ∘ σ) s := by
classical
refine ⟨not_imp_not.1 fun h ↦ ?_, fun h ↦ (hfg.sum_smul_comp_perm_le_sum_smul hσ).antisymm ?_⟩
· rw [MonovaryOn] at h
push_neg at h
obtain ⟨x, hx, y, hy, hgxy, hfxy⟩ := h
set τ : Perm ι := (Equiv.swap x y).trans σ
have hτs : {x | τ x ≠ x} ⊆ s := by
refine (set_support_mul_subset σ <| swap x y).trans (Set.union_subset hσ fun z hz ↦ ?_)
obtain ⟨_, rfl | rfl⟩ := swap_apply_ne_self_iff.1 hz <;> assumption
refine ((hfg.sum_smul_comp_perm_le_sum_smul hτs).trans_lt' ?_).ne
obtain rfl | hxy := eq_or_ne x y
· cases lt_irrefl _ hfxy
simp only [τ, ← s.sum_erase_add _ hx,
← (s.erase x).sum_erase_add _ (mem_erase.2 ⟨hxy.symm, hy⟩),
add_assoc, Equiv.coe_trans, Function.comp_apply, swap_apply_right, swap_apply_left]
refine add_lt_add_of_le_of_lt (Finset.sum_congr rfl fun z hz ↦ ?_).le
(smul_add_smul_lt_smul_add_smul hfxy hgxy)
simp_rw [mem_erase] at hz
rw [swap_apply_of_ne_of_ne hz.2.1 hz.1]
· convert h.sum_smul_comp_perm_le_sum_smul ((set_support_inv_eq _).subset.trans hσ) using 1
simp_rw [Function.comp_apply, apply_inv_self]
/-- **Strict inequality case of the Rearrangement Inequality**: Pointwise scalar multiplication of
`f` and `g`, which monovary together, is strictly decreased by a permutation if and only if
`f` and `g ∘ σ` do not monovary together. Stated by permuting the entries of `g`. -/
theorem MonovaryOn.sum_smul_comp_perm_lt_sum_smul_iff (hfg : MonovaryOn f g s)
(hσ : {x | σ x ≠ x} ⊆ s) :
∑ i ∈ s, f i • g (σ i) < ∑ i ∈ s, f i • g i ↔ ¬MonovaryOn f (g ∘ σ) s := by
simp [← hfg.sum_smul_comp_perm_eq_sum_smul_iff hσ, lt_iff_le_and_ne,
hfg.sum_smul_comp_perm_le_sum_smul hσ]
/-- **Rearrangement Inequality**: Pointwise scalar multiplication of `f` and `g` is maximized when
`f` and `g` monovary together. Stated by permuting the entries of `f`. -/
theorem MonovaryOn.sum_comp_perm_smul_le_sum_smul (hfg : MonovaryOn f g s)
(hσ : {x | σ x ≠ x} ⊆ s) : ∑ i ∈ s, f (σ i) • g i ≤ ∑ i ∈ s, f i • g i := by
convert hfg.sum_smul_comp_perm_le_sum_smul
(show { x | σ⁻¹ x ≠ x } ⊆ s by simp only [set_support_inv_eq, hσ]) using 1
exact σ.sum_comp' s (fun i j ↦ f i • g j) hσ
/-- **Equality case of the Rearrangement Inequality**: Pointwise scalar multiplication of `f` and
`g`, which monovary together, is unchanged by a permutation if and only if `f ∘ σ` and `g` monovary
together. Stated by permuting the entries of `f`. -/
theorem MonovaryOn.sum_comp_perm_smul_eq_sum_smul_iff (hfg : MonovaryOn f g s)
(hσ : {x | σ x ≠ x} ⊆ s) :
∑ i ∈ s, f (σ i) • g i = ∑ i ∈ s, f i • g i ↔ MonovaryOn (f ∘ σ) g s := by
have hσinv : { x | σ⁻¹ x ≠ x } ⊆ s := (set_support_inv_eq _).subset.trans hσ
refine (Iff.trans ?_ <| hfg.sum_smul_comp_perm_eq_sum_smul_iff hσinv).trans
⟨fun h ↦ ?_, fun h ↦ ?_⟩
· apply eq_iff_eq_cancel_right.2
rw [σ.sum_comp' s (fun i j ↦ f i • g j) hσ]
congr
· convert h.comp_right σ
· rw [comp.assoc, inv_def, symm_comp_self, comp_id]
· rw [σ.eq_preimage_iff_image_eq, Set.image_perm hσ]
· convert h.comp_right σ.symm
· rw [comp.assoc, self_comp_symm, comp_id]
· rw [σ.symm.eq_preimage_iff_image_eq]
exact Set.image_perm hσinv
/-- **Strict inequality case of the Rearrangement Inequality**: Pointwise scalar multiplication of
`f` and `g`, which monovary together, is strictly decreased by a permutation if and only if
`f ∘ σ` and `g` do not monovary together. Stated by permuting the entries of `f`. -/
theorem MonovaryOn.sum_comp_perm_smul_lt_sum_smul_iff (hfg : MonovaryOn f g s)
(hσ : {x | σ x ≠ x} ⊆ s) :
∑ i ∈ s, f (σ i) • g i < ∑ i ∈ s, f i • g i ↔ ¬MonovaryOn (f ∘ σ) g s := by
simp [← hfg.sum_comp_perm_smul_eq_sum_smul_iff hσ, lt_iff_le_and_ne,
hfg.sum_comp_perm_smul_le_sum_smul hσ]
/-- **Rearrangement Inequality**: Pointwise scalar multiplication of `f` and `g` is minimized when
`f` and `g` antivary together. Stated by permuting the entries of `g`. -/
theorem AntivaryOn.sum_smul_le_sum_smul_comp_perm (hfg : AntivaryOn f g s)
(hσ : {x | σ x ≠ x} ⊆ s) : ∑ i ∈ s, f i • g i ≤ ∑ i ∈ s, f i • g (σ i) :=
hfg.dual_right.sum_smul_comp_perm_le_sum_smul hσ
/-- **Equality case of the Rearrangement Inequality**: Pointwise scalar multiplication of `f` and
`g`, which antivary together, is unchanged by a permutation if and only if `f` and `g ∘ σ` antivary
together. Stated by permuting the entries of `g`. -/
theorem AntivaryOn.sum_smul_comp_perm_eq_sum_smul_iff (hfg : AntivaryOn f g s)
(hσ : {x | σ x ≠ x} ⊆ s) :
∑ i ∈ s, f i • g (σ i) = ∑ i ∈ s, f i • g i ↔ AntivaryOn f (g ∘ σ) s :=
(hfg.dual_right.sum_smul_comp_perm_eq_sum_smul_iff hσ).trans monovaryOn_toDual_right
@[deprecated (since := "2024-06-25")]
alias AntivaryOn.sum_smul_eq_sum_smul_comp_perm_iff := AntivaryOn.sum_smul_comp_perm_eq_sum_smul_iff
/-- **Strict inequality case of the Rearrangement Inequality**: Pointwise scalar multiplication of
`f` and `g`, which antivary together, is strictly decreased by a permutation if and only if
`f` and `g ∘ σ` do not antivary together. Stated by permuting the entries of `g`. -/
theorem AntivaryOn.sum_smul_lt_sum_smul_comp_perm_iff (hfg : AntivaryOn f g s)
(hσ : {x | σ x ≠ x} ⊆ s) :
∑ i ∈ s, f i • g i < ∑ i ∈ s, f i • g (σ i) ↔ ¬AntivaryOn f (g ∘ σ) s := by
simp [← hfg.sum_smul_comp_perm_eq_sum_smul_iff hσ, lt_iff_le_and_ne, eq_comm,
hfg.sum_smul_le_sum_smul_comp_perm hσ]
/-- **Rearrangement Inequality**: Pointwise scalar multiplication of `f` and `g` is minimized when
`f` and `g` antivary together. Stated by permuting the entries of `f`. -/
theorem AntivaryOn.sum_smul_le_sum_comp_perm_smul (hfg : AntivaryOn f g s)
(hσ : {x | σ x ≠ x} ⊆ s) : ∑ i ∈ s, f i • g i ≤ ∑ i ∈ s, f (σ i) • g i := by
convert hfg.sum_smul_le_sum_smul_comp_perm
(show { x | σ⁻¹ x ≠ x } ⊆ s by simp only [set_support_inv_eq, hσ]) using 1
exact σ.sum_comp' s (fun i j ↦ f i • g j) hσ
/-- **Equality case of the Rearrangement Inequality**: Pointwise scalar multiplication of `f` and
`g`, which antivary together, is unchanged by a permutation if and only if `f ∘ σ` and `g` antivary
together. Stated by permuting the entries of `f`. -/
theorem AntivaryOn.sum_comp_perm_smul_eq_sum_smul_iff (hfg : AntivaryOn f g s)
(hσ : {x | σ x ≠ x} ⊆ s) :
∑ i ∈ s, f (σ i) • g i = ∑ i ∈ s, f i • g i ↔ AntivaryOn (f ∘ σ) g s :=
(hfg.dual_right.sum_comp_perm_smul_eq_sum_smul_iff hσ).trans monovaryOn_toDual_right
@[deprecated (since := "2024-06-25")]
alias AntivaryOn.sum_smul_eq_sum_comp_perm_smul_iff := AntivaryOn.sum_comp_perm_smul_eq_sum_smul_iff
/-- **Strict inequality case of the Rearrangement Inequality**: Pointwise scalar multiplication of
`f` and `g`, which antivary together, is strictly decreased by a permutation if and only if
`f ∘ σ` and `g` do not antivary together. Stated by permuting the entries of `f`. -/
theorem AntivaryOn.sum_smul_lt_sum_comp_perm_smul_iff (hfg : AntivaryOn f g s)
(hσ : {x | σ x ≠ x} ⊆ s) :
∑ i ∈ s, f i • g i < ∑ i ∈ s, f (σ i) • g i ↔ ¬AntivaryOn (f ∘ σ) g s := by
simp [← hfg.sum_comp_perm_smul_eq_sum_smul_iff hσ, eq_comm, lt_iff_le_and_ne,
hfg.sum_smul_le_sum_comp_perm_smul hσ]
variable [Fintype ι]
/-- **Rearrangement Inequality**: Pointwise scalar multiplication of `f` and `g` is maximized when
`f` and `g` monovary together. Stated by permuting the entries of `g`. -/
theorem Monovary.sum_smul_comp_perm_le_sum_smul (hfg : Monovary f g) :
∑ i, f i • g (σ i) ≤ ∑ i, f i • g i :=
(hfg.monovaryOn _).sum_smul_comp_perm_le_sum_smul fun _ _ ↦ mem_univ _
/-- **Equality case of the Rearrangement Inequality**: Pointwise scalar multiplication of `f` and
`g`, which monovary together, is unchanged by a permutation if and only if `f` and `g ∘ σ` monovary
together. Stated by permuting the entries of `g`. -/
theorem Monovary.sum_smul_comp_perm_eq_sum_smul_iff (hfg : Monovary f g) :
∑ i, f i • g (σ i) = ∑ i, f i • g i ↔ Monovary f (g ∘ σ) := by
simp [(hfg.monovaryOn _).sum_smul_comp_perm_eq_sum_smul_iff fun _ _ ↦ mem_univ _]
/-- **Strict inequality case of the Rearrangement Inequality**: Pointwise scalar multiplication of
`f` and `g`, which monovary together, is strictly decreased by a permutation if and only if
`f` and `g ∘ σ` do not monovary together. Stated by permuting the entries of `g`. -/
theorem Monovary.sum_smul_comp_perm_lt_sum_smul_iff (hfg : Monovary f g) :
∑ i, f i • g (σ i) < ∑ i, f i • g i ↔ ¬Monovary f (g ∘ σ) := by
simp [(hfg.monovaryOn _).sum_smul_comp_perm_lt_sum_smul_iff fun _ _ ↦ mem_univ _]
/-- **Rearrangement Inequality**: Pointwise scalar multiplication of `f` and `g` is maximized when
`f` and `g` monovary together. Stated by permuting the entries of `f`. -/
theorem Monovary.sum_comp_perm_smul_le_sum_smul (hfg : Monovary f g) :
∑ i, f (σ i) • g i ≤ ∑ i, f i • g i :=
(hfg.monovaryOn _).sum_comp_perm_smul_le_sum_smul fun _ _ ↦ mem_univ _
/-- **Equality case of the Rearrangement Inequality**: Pointwise scalar multiplication of `f` and
`g`, which monovary together, is unchanged by a permutation if and only if `f ∘ σ` and `g` monovary
together. Stated by permuting the entries of `g`. -/
theorem Monovary.sum_comp_perm_smul_eq_sum_smul_iff (hfg : Monovary f g) :
∑ i, f (σ i) • g i = ∑ i, f i • g i ↔ Monovary (f ∘ σ) g := by
simp [(hfg.monovaryOn _).sum_comp_perm_smul_eq_sum_smul_iff fun _ _ ↦ mem_univ _]
/-- **Strict inequality case of the Rearrangement Inequality**: Pointwise scalar multiplication of
`f` and `g`, which monovary together, is strictly decreased by a permutation if and only if
`f` and `g ∘ σ` do not monovary together. Stated by permuting the entries of `g`. -/
theorem Monovary.sum_comp_perm_smul_lt_sum_smul_iff (hfg : Monovary f g) :
∑ i, f (σ i) • g i < ∑ i, f i • g i ↔ ¬Monovary (f ∘ σ) g := by
simp [(hfg.monovaryOn _).sum_comp_perm_smul_lt_sum_smul_iff fun _ _ ↦ mem_univ _]
/-- **Rearrangement Inequality**: Pointwise scalar multiplication of `f` and `g` is minimized when
`f` and `g` antivary together. Stated by permuting the entries of `g`. -/
theorem Antivary.sum_smul_le_sum_smul_comp_perm (hfg : Antivary f g) :
∑ i, f i • g i ≤ ∑ i, f i • g (σ i) :=
(hfg.antivaryOn _).sum_smul_le_sum_smul_comp_perm fun _ _ ↦ mem_univ _
/-- **Equality case of the Rearrangement Inequality**: Pointwise scalar multiplication of `f` and
`g`, which antivary together, is unchanged by a permutation if and only if `f` and `g ∘ σ` antivary
together. Stated by permuting the entries of `g`. -/
theorem Antivary.sum_smul_comp_perm_eq_sum_smul_iff (hfg : Antivary f g) :
∑ i, f i • g (σ i) = ∑ i, f i • g i ↔ Antivary f (g ∘ σ) := by
simp [(hfg.antivaryOn _).sum_smul_comp_perm_eq_sum_smul_iff fun _ _ ↦ mem_univ _]
@[deprecated (since := "2024-06-25")]
alias Antivary.sum_smul_eq_sum_smul_comp_perm_iff := Antivary.sum_smul_comp_perm_eq_sum_smul_iff
/-- **Strict inequality case of the Rearrangement Inequality**: Pointwise scalar multiplication of
`f` and `g`, which antivary together, is strictly decreased by a permutation if and only if
`f` and `g ∘ σ` do not antivary together. Stated by permuting the entries of `g`. -/
theorem Antivary.sum_smul_lt_sum_smul_comp_perm_iff (hfg : Antivary f g) :
∑ i, f i • g i < ∑ i, f i • g (σ i) ↔ ¬Antivary f (g ∘ σ) := by
simp [(hfg.antivaryOn _).sum_smul_lt_sum_smul_comp_perm_iff fun _ _ ↦ mem_univ _]
/-- **Rearrangement Inequality**: Pointwise scalar multiplication of `f` and `g` is minimized when
`f` and `g` antivary together. Stated by permuting the entries of `f`. -/
theorem Antivary.sum_smul_le_sum_comp_perm_smul (hfg : Antivary f g) :
∑ i, f i • g i ≤ ∑ i, f (σ i) • g i :=
(hfg.antivaryOn _).sum_smul_le_sum_comp_perm_smul fun _ _ ↦ mem_univ _
/-- **Equality case of the Rearrangement Inequality**: Pointwise scalar multiplication of `f` and
`g`, which antivary together, is unchanged by a permutation if and only if `f ∘ σ` and `g` antivary
together. Stated by permuting the entries of `f`. -/
theorem Antivary.sum_comp_perm_smul_eq_sum_smul_iff (hfg : Antivary f g) :
∑ i, f (σ i) • g i = ∑ i, f i • g i ↔ Antivary (f ∘ σ) g := by
simp [(hfg.antivaryOn _).sum_comp_perm_smul_eq_sum_smul_iff fun _ _ ↦ mem_univ _]
@[deprecated (since := "2024-06-25")]
alias Antivary.sum_smul_eq_sum_comp_perm_smul_iff := Antivary.sum_comp_perm_smul_eq_sum_smul_iff
/-- **Strict inequality case of the Rearrangement Inequality**: Pointwise scalar multiplication of
`f` and `g`, which antivary together, is strictly decreased by a permutation if and only if
`f ∘ σ` and `g` do not antivary together. Stated by permuting the entries of `f`. -/
theorem Antivary.sum_smul_lt_sum_comp_perm_smul_iff (hfg : Antivary f g) :
∑ i, f i • g i < ∑ i, f (σ i) • g i ↔ ¬Antivary (f ∘ σ) g := by
simp [(hfg.antivaryOn _).sum_smul_lt_sum_comp_perm_smul_iff fun _ _ ↦ mem_univ _]
end SMul
/-!
### Multiplication versions
Special cases of the above when scalar multiplication is actually multiplication.
-/
section Mul
variable [LinearOrderedRing α] {s : Finset ι} {σ : Perm ι} {f g : ι → α}
/-- **Rearrangement Inequality**: Pointwise multiplication of `f` and `g` is maximized when `f` and
`g` monovary together. Stated by permuting the entries of `g`. -/
theorem MonovaryOn.sum_mul_comp_perm_le_sum_mul (hfg : MonovaryOn f g s)
(hσ : {x | σ x ≠ x} ⊆ s) : ∑ i ∈ s, f i * g (σ i) ≤ ∑ i ∈ s, f i * g i :=
hfg.sum_smul_comp_perm_le_sum_smul hσ
/-- **Equality case of the Rearrangement Inequality**: Pointwise multiplication of `f` and `g`,
which monovary together, is unchanged by a permutation if and only if `f` and `g ∘ σ` monovary
together. Stated by permuting the entries of `g`. -/
theorem MonovaryOn.sum_mul_comp_perm_eq_sum_mul_iff (hfg : MonovaryOn f g s)
(hσ : {x | σ x ≠ x} ⊆ s) :
∑ i ∈ s, f i * g (σ i) = ∑ i ∈ s, f i * g i ↔ MonovaryOn f (g ∘ σ) s :=
hfg.sum_smul_comp_perm_eq_sum_smul_iff hσ
/-- **Strict inequality case of the Rearrangement Inequality**: Pointwise scalar multiplication of
`f` and `g`, which monovary together, is strictly decreased by a permutation if and only if
`f` and `g ∘ σ` do not monovary together. Stated by permuting the entries of `g`. -/
theorem MonovaryOn.sum_mul_comp_perm_lt_sum_mul_iff (hfg : MonovaryOn f g s)
(hσ : {x | σ x ≠ x} ⊆ s) :
∑ i ∈ s, f i • g (σ i) < ∑ i ∈ s, f i • g i ↔ ¬MonovaryOn f (g ∘ σ) s :=
hfg.sum_smul_comp_perm_lt_sum_smul_iff hσ
/-- **Rearrangement Inequality**: Pointwise multiplication of `f` and `g` is maximized when `f` and
`g` monovary together. Stated by permuting the entries of `f`. -/
theorem MonovaryOn.sum_comp_perm_mul_le_sum_mul (hfg : MonovaryOn f g s)
(hσ : {x | σ x ≠ x} ⊆ s) : ∑ i ∈ s, f (σ i) * g i ≤ ∑ i ∈ s, f i * g i :=
hfg.sum_comp_perm_smul_le_sum_smul hσ
/-- **Equality case of the Rearrangement Inequality**: Pointwise multiplication of `f` and `g`,
which monovary together, is unchanged by a permutation if and only if `f ∘ σ` and `g` monovary
together. Stated by permuting the entries of `f`. -/
theorem MonovaryOn.sum_comp_perm_mul_eq_sum_mul_iff (hfg : MonovaryOn f g s)
(hσ : {x | σ x ≠ x} ⊆ s) :
∑ i ∈ s, f (σ i) * g i = ∑ i ∈ s, f i * g i ↔ MonovaryOn (f ∘ σ) g s :=
hfg.sum_comp_perm_smul_eq_sum_smul_iff hσ
/-- **Strict inequality case of the Rearrangement Inequality**: Pointwise multiplication of
`f` and `g`, which monovary together, is strictly decreased by a permutation if and only if
`f ∘ σ` and `g` do not monovary together. Stated by permuting the entries of `f`. -/
theorem MonovaryOn.sum_comp_perm_mul_lt_sum_mul_iff (hfg : MonovaryOn f g s)
(hσ : {x | σ x ≠ x} ⊆ s) :
∑ i ∈ s, f (σ i) * g i < ∑ i ∈ s, f i * g i ↔ ¬MonovaryOn (f ∘ σ) g s :=
hfg.sum_comp_perm_smul_lt_sum_smul_iff hσ
/-- **Rearrangement Inequality**: Pointwise multiplication of `f` and `g` is minimized when `f` and
`g` antivary together. Stated by permuting the entries of `g`. -/
theorem AntivaryOn.sum_mul_le_sum_mul_comp_perm (hfg : AntivaryOn f g s)
(hσ : {x | σ x ≠ x} ⊆ s) : ∑ i ∈ s, f i * g i ≤ ∑ i ∈ s, f i * g (σ i) :=
hfg.sum_smul_le_sum_smul_comp_perm hσ
/-- **Equality case of the Rearrangement Inequality**: Pointwise multiplication of `f` and `g`,
which antivary together, is unchanged by a permutation if and only if `f` and `g ∘ σ` antivary
together. Stated by permuting the entries of `g`. -/
theorem AntivaryOn.sum_mul_eq_sum_mul_comp_perm_iff (hfg : AntivaryOn f g s)
(hσ : {x | σ x ≠ x} ⊆ s) :
∑ i ∈ s, f i * g (σ i) = ∑ i ∈ s, f i * g i ↔ AntivaryOn f (g ∘ σ) s :=
hfg.sum_smul_comp_perm_eq_sum_smul_iff hσ
/-- **Strict inequality case of the Rearrangement Inequality**: Pointwise multiplication of
`f` and `g`, which antivary together, is strictly decreased by a permutation if and only if
`f` and `g ∘ σ` do not antivary together. Stated by permuting the entries of `g`. -/
theorem AntivaryOn.sum_mul_lt_sum_mul_comp_perm_iff (hfg : AntivaryOn f g s)
(hσ : {x | σ x ≠ x} ⊆ s) :
∑ i ∈ s, f i * g i < ∑ i ∈ s, f i * g (σ i) ↔ ¬AntivaryOn f (g ∘ σ) s :=
hfg.sum_smul_lt_sum_smul_comp_perm_iff hσ
/-- **Rearrangement Inequality**: Pointwise multiplication of `f` and `g` is minimized when `f` and
`g` antivary together. Stated by permuting the entries of `f`. -/
theorem AntivaryOn.sum_mul_le_sum_comp_perm_mul (hfg : AntivaryOn f g s)
(hσ : {x | σ x ≠ x} ⊆ s) : ∑ i ∈ s, f i * g i ≤ ∑ i ∈ s, f (σ i) * g i :=
hfg.sum_smul_le_sum_comp_perm_smul hσ
/-- **Equality case of the Rearrangement Inequality**: Pointwise multiplication of `f` and `g`,
which antivary together, is unchanged by a permutation if and only if `f ∘ σ` and `g` antivary
together. Stated by permuting the entries of `f`. -/
theorem AntivaryOn.sum_comp_perm_mul_eq_sum_mul_iff (hfg : AntivaryOn f g s)
(hσ : {x | σ x ≠ x} ⊆ s) :
∑ i ∈ s, f (σ i) * g i = ∑ i ∈ s, f i * g i ↔ AntivaryOn (f ∘ σ) g s :=
hfg.sum_comp_perm_smul_eq_sum_smul_iff hσ
@[deprecated (since := "2024-06-25")]
alias AntivaryOn.sum_mul_eq_sum_comp_perm_mul_iff := AntivaryOn.sum_comp_perm_mul_eq_sum_mul_iff
/-- **Strict inequality case of the Rearrangement Inequality**: Pointwise multiplication of
`f` and `g`, which antivary together, is strictly decreased by a permutation if and only if
`f ∘ σ` and `g` do not antivary together. Stated by permuting the entries of `f`. -/
theorem AntivaryOn.sum_mul_lt_sum_comp_perm_mul_iff (hfg : AntivaryOn f g s)
(hσ : {x | σ x ≠ x} ⊆ s) :
∑ i ∈ s, f i * g i < ∑ i ∈ s, f (σ i) * g i ↔ ¬AntivaryOn (f ∘ σ) g s :=
hfg.sum_smul_lt_sum_comp_perm_smul_iff hσ
variable [Fintype ι]
/-- **Rearrangement Inequality**: Pointwise multiplication of `f` and `g` is maximized when `f` and
`g` monovary together. Stated by permuting the entries of `g`. -/
theorem Monovary.sum_mul_comp_perm_le_sum_mul (hfg : Monovary f g) :
∑ i, f i * g (σ i) ≤ ∑ i, f i * g i :=
hfg.sum_smul_comp_perm_le_sum_smul
/-- **Equality case of the Rearrangement Inequality**: Pointwise multiplication of `f` and `g`,
which monovary together, is unchanged by a permutation if and only if `f` and `g ∘ σ` monovary
together. Stated by permuting the entries of `g`. -/
theorem Monovary.sum_mul_comp_perm_eq_sum_mul_iff (hfg : Monovary f g) :
∑ i, f i * g (σ i) = ∑ i, f i * g i ↔ Monovary f (g ∘ σ) :=
hfg.sum_smul_comp_perm_eq_sum_smul_iff
/-- **Strict inequality case of the Rearrangement Inequality**: Pointwise multiplication of
`f` and `g`, which monovary together, is strictly decreased by a permutation if and only if
`f` and `g ∘ σ` do not monovary together. Stated by permuting the entries of `g`. -/
theorem Monovary.sum_mul_comp_perm_lt_sum_mul_iff (hfg : Monovary f g) :
∑ i, f i * g (σ i) < ∑ i, f i * g i ↔ ¬Monovary f (g ∘ σ) :=
hfg.sum_smul_comp_perm_lt_sum_smul_iff
/-- **Rearrangement Inequality**: Pointwise multiplication of `f` and `g` is maximized when `f` and
`g` monovary together. Stated by permuting the entries of `f`. -/
theorem Monovary.sum_comp_perm_mul_le_sum_mul (hfg : Monovary f g) :
∑ i, f (σ i) * g i ≤ ∑ i, f i * g i :=
hfg.sum_comp_perm_smul_le_sum_smul
/-- **Equality case of the Rearrangement Inequality**: Pointwise multiplication of `f` and `g`,
which monovary together, is unchanged by a permutation if and only if `f ∘ σ` and `g` monovary
together. Stated by permuting the entries of `g`. -/
theorem Monovary.sum_comp_perm_mul_eq_sum_mul_iff (hfg : Monovary f g) :
∑ i, f (σ i) * g i = ∑ i, f i * g i ↔ Monovary (f ∘ σ) g :=
hfg.sum_comp_perm_smul_eq_sum_smul_iff
/-- **Strict inequality case of the Rearrangement Inequality**: Pointwise multiplication of
`f` and `g`, which monovary together, is strictly decreased by a permutation if and only if
`f` and `g ∘ σ` do not monovary together. Stated by permuting the entries of `g`. -/
theorem Monovary.sum_comp_perm_mul_lt_sum_mul_iff (hfg : Monovary f g) :
∑ i, f (σ i) * g i < ∑ i, f i * g i ↔ ¬Monovary (f ∘ σ) g :=
hfg.sum_comp_perm_smul_lt_sum_smul_iff
/-- **Rearrangement Inequality**: Pointwise multiplication of `f` and `g` is minimized when `f` and
`g` antivary together. Stated by permuting the entries of `g`. -/
theorem Antivary.sum_mul_le_sum_mul_comp_perm (hfg : Antivary f g) :
∑ i, f i * g i ≤ ∑ i, f i * g (σ i) :=
hfg.sum_smul_le_sum_smul_comp_perm
/-- **Equality case of the Rearrangement Inequality**: Pointwise multiplication of `f` and `g`,
which antivary together, is unchanged by a permutation if and only if `f` and `g ∘ σ` antivary
together. Stated by permuting the entries of `g`. -/
theorem Antivary.sum_mul_eq_sum_mul_comp_perm_iff (hfg : Antivary f g) :
∑ i, f i * g (σ i) = ∑ i, f i * g i ↔ Antivary f (g ∘ σ) :=
hfg.sum_smul_comp_perm_eq_sum_smul_iff
/-- **Strict inequality case of the Rearrangement Inequality**: Pointwise multiplication of
`f` and `g`, which antivary together, is strictly decreased by a permutation if and only if
`f` and `g ∘ σ` do not antivary together. Stated by permuting the entries of `g`. -/
theorem Antivary.sum_mul_lt_sum_mul_comp_perm_iff (hfg : Antivary f g) :
∑ i, f i • g i < ∑ i, f i • g (σ i) ↔ ¬Antivary f (g ∘ σ) :=
hfg.sum_smul_lt_sum_smul_comp_perm_iff
/-- **Rearrangement Inequality**: Pointwise multiplication of `f` and `g` is minimized when `f` and
`g` antivary together. Stated by permuting the entries of `f`. -/
theorem Antivary.sum_mul_le_sum_comp_perm_mul (hfg : Antivary f g) :
∑ i, f i * g i ≤ ∑ i, f (σ i) * g i :=
hfg.sum_smul_le_sum_comp_perm_smul
/-- **Equality case of the Rearrangement Inequality**: Pointwise multiplication of `f` and `g`,
which antivary together, is unchanged by a permutation if and only if `f ∘ σ` and `g` antivary
together. Stated by permuting the entries of `f`. -/
theorem Antivary.sum_comp_perm_mul_eq_sum_mul_iff (hfg : Antivary f g) :
∑ i, f (σ i) * g i = ∑ i, f i * g i ↔ Antivary (f ∘ σ) g :=
hfg.sum_comp_perm_smul_eq_sum_smul_iff
@[deprecated (since := "2024-06-25")]
alias Antivary.sum_mul_eq_sum_comp_perm_mul_iff := Antivary.sum_comp_perm_mul_eq_sum_mul_iff
/-- **Strict inequality case of the Rearrangement Inequality**: Pointwise multiplication of
`f` and `g`, which antivary together, is strictly decreased by a permutation if and only if
`f ∘ σ` and `g` do not antivary together. Stated by permuting the entries of `f`. -/
theorem Antivary.sum_mul_lt_sum_comp_perm_mul_iff (hfg : Antivary f g) :
∑ i, f i * g i < ∑ i, f (σ i) * g i ↔ ¬Antivary (f ∘ σ) g :=
hfg.sum_smul_lt_sum_comp_perm_smul_iff
end Mul
|
Algebra\Order\Sum.lean | /-
Copyright (c) 2024 Martin Dvorak. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Martin Dvorak
-/
import Mathlib.Order.Basic
import Mathlib.Algebra.Group.Pi.Basic
/-!
# Interaction between `Sum.elim`, `≤`, and `0` or `1`
This file provides basic API for part-wise comparison of `Sum.elim` vectors against `0` or `1`.
-/
namespace Sum
variable {α₁ α₂ β : Type*} [LE β] [One β] {v₁ : α₁ → β} {v₂ : α₂ → β}
@[to_additive]
lemma one_le_elim_iff : 1 ≤ Sum.elim v₁ v₂ ↔ 1 ≤ v₁ ∧ 1 ≤ v₂ :=
const_le_elim_iff
@[to_additive]
lemma elim_le_one_iff : Sum.elim v₁ v₂ ≤ 1 ↔ v₁ ≤ 1 ∧ v₂ ≤ 1 :=
elim_le_const_iff
end Sum
|
Algebra\Order\ToIntervalMod.lean | /-
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.Basic
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
/-!
# 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
theorem sub_toIcoDiv_zsmul_mem_Ico (a b : α) : b - toIcoDiv hp a b • p ∈ Set.Ico a (a + p) :=
(existsUnique_sub_zsmul_mem_Ico hp b a).choose_spec.1
theorem toIcoDiv_eq_of_sub_zsmul_mem_Ico (h : b - n • p ∈ Set.Ico a (a + p)) :
toIcoDiv hp a b = n :=
((existsUnique_sub_zsmul_mem_Ico hp b a).choose_spec.2 _ h).symm
/--
The unique integer such that this multiple of `p`, subtracted from `b`, is in `Ioc a (a + p)`. -/
def toIocDiv (a b : α) : ℤ :=
(existsUnique_sub_zsmul_mem_Ioc hp b a).choose
theorem sub_toIocDiv_zsmul_mem_Ioc (a b : α) : b - toIocDiv hp a b • p ∈ Set.Ioc a (a + p) :=
(existsUnique_sub_zsmul_mem_Ioc hp b a).choose_spec.1
theorem toIocDiv_eq_of_sub_zsmul_mem_Ioc (h : b - n • p ∈ Set.Ioc a (a + p)) :
toIocDiv hp a b = n :=
((existsUnique_sub_zsmul_mem_Ioc hp b a).choose_spec.2 _ h).symm
/-- Reduce `b` to the interval `Ico a (a + p)`. -/
def toIcoMod (a b : α) : α :=
b - toIcoDiv hp a b • p
/-- Reduce `b` to the interval `Ioc a (a + p)`. -/
def toIocMod (a b : α) : α :=
b - toIocDiv hp a b • p
theorem toIcoMod_mem_Ico (a b : α) : toIcoMod hp a b ∈ Set.Ico a (a + p) :=
sub_toIcoDiv_zsmul_mem_Ico hp a b
theorem toIcoMod_mem_Ico' (b : α) : toIcoMod hp 0 b ∈ Set.Ico 0 p := by
convert toIcoMod_mem_Ico hp 0 b
exact (zero_add p).symm
theorem toIocMod_mem_Ioc (a b : α) : toIocMod hp a b ∈ Set.Ioc a (a + p) :=
sub_toIocDiv_zsmul_mem_Ioc hp a b
theorem left_le_toIcoMod (a b : α) : a ≤ toIcoMod hp a b :=
(Set.mem_Ico.1 (toIcoMod_mem_Ico hp a b)).1
theorem left_lt_toIocMod (a b : α) : a < toIocMod hp a b :=
(Set.mem_Ioc.1 (toIocMod_mem_Ioc hp a b)).1
theorem toIcoMod_lt_right (a b : α) : toIcoMod hp a b < a + p :=
(Set.mem_Ico.1 (toIcoMod_mem_Ico hp a b)).2
theorem toIocMod_le_right (a b : α) : toIocMod hp a b ≤ a + p :=
(Set.mem_Ioc.1 (toIocMod_mem_Ioc hp a b)).2
@[simp]
theorem self_sub_toIcoDiv_zsmul (a b : α) : b - toIcoDiv hp a b • p = toIcoMod hp a b :=
rfl
@[simp]
theorem self_sub_toIocDiv_zsmul (a b : α) : b - toIocDiv hp a b • p = toIocMod hp a b :=
rfl
@[simp]
theorem toIcoDiv_zsmul_sub_self (a b : α) : toIcoDiv hp a b • p - b = -toIcoMod hp a b := by
rw [toIcoMod, neg_sub]
@[simp]
theorem toIocDiv_zsmul_sub_self (a b : α) : toIocDiv hp a b • p - b = -toIocMod hp a b := by
rw [toIocMod, neg_sub]
@[simp]
theorem toIcoMod_sub_self (a b : α) : toIcoMod hp a b - b = -toIcoDiv hp a b • p := by
rw [toIcoMod, sub_sub_cancel_left, neg_smul]
@[simp]
theorem toIocMod_sub_self (a b : α) : toIocMod hp a b - b = -toIocDiv hp a b • p := by
rw [toIocMod, sub_sub_cancel_left, neg_smul]
@[simp]
theorem self_sub_toIcoMod (a b : α) : b - toIcoMod hp a b = toIcoDiv hp a b • p := by
rw [toIcoMod, sub_sub_cancel]
@[simp]
theorem self_sub_toIocMod (a b : α) : b - toIocMod hp a b = toIocDiv hp a b • p := by
rw [toIocMod, sub_sub_cancel]
@[simp]
theorem toIcoMod_add_toIcoDiv_zsmul (a b : α) : toIcoMod hp a b + toIcoDiv hp a b • p = b := by
rw [toIcoMod, sub_add_cancel]
@[simp]
theorem toIocMod_add_toIocDiv_zsmul (a b : α) : toIocMod hp a b + toIocDiv hp a b • p = b := by
rw [toIocMod, sub_add_cancel]
@[simp]
theorem toIcoDiv_zsmul_sub_toIcoMod (a b : α) : toIcoDiv hp a b • p + toIcoMod hp a b = b := by
rw [add_comm, toIcoMod_add_toIcoDiv_zsmul]
@[simp]
theorem toIocDiv_zsmul_sub_toIocMod (a b : α) : toIocDiv hp a b • p + toIocMod hp a b = b := by
rw [add_comm, toIocMod_add_toIocDiv_zsmul]
theorem toIcoMod_eq_iff : toIcoMod hp a b = c ↔ c ∈ Set.Ico a (a + p) ∧ ∃ z : ℤ, b = c + z • p := by
refine
⟨fun h =>
⟨h ▸ toIcoMod_mem_Ico hp a b, toIcoDiv hp a b, h ▸ (toIcoMod_add_toIcoDiv_zsmul _ _ _).symm⟩,
?_⟩
simp_rw [← @sub_eq_iff_eq_add]
rintro ⟨hc, n, rfl⟩
rw [← toIcoDiv_eq_of_sub_zsmul_mem_Ico hp hc, toIcoMod]
theorem toIocMod_eq_iff : toIocMod hp a b = c ↔ c ∈ Set.Ioc a (a + p) ∧ ∃ z : ℤ, b = c + z • p := by
refine
⟨fun h =>
⟨h ▸ toIocMod_mem_Ioc hp a b, toIocDiv hp a b, h ▸ (toIocMod_add_toIocDiv_zsmul hp _ _).symm⟩,
?_⟩
simp_rw [← @sub_eq_iff_eq_add]
rintro ⟨hc, n, rfl⟩
rw [← toIocDiv_eq_of_sub_zsmul_mem_Ioc hp hc, toIocMod]
@[simp]
theorem toIcoDiv_apply_left (a : α) : toIcoDiv hp a a = 0 :=
toIcoDiv_eq_of_sub_zsmul_mem_Ico hp <| by simp [hp]
@[simp]
theorem toIocDiv_apply_left (a : α) : toIocDiv hp a a = -1 :=
toIocDiv_eq_of_sub_zsmul_mem_Ioc hp <| by simp [hp]
@[simp]
theorem toIcoMod_apply_left (a : α) : toIcoMod hp a a = a := by
rw [toIcoMod_eq_iff hp, Set.left_mem_Ico]
exact ⟨lt_add_of_pos_right _ hp, 0, by simp⟩
@[simp]
theorem toIocMod_apply_left (a : α) : toIocMod hp a a = a + p := by
rw [toIocMod_eq_iff hp, Set.right_mem_Ioc]
exact ⟨lt_add_of_pos_right _ hp, -1, by simp⟩
theorem toIcoDiv_apply_right (a : α) : toIcoDiv hp a (a + p) = 1 :=
toIcoDiv_eq_of_sub_zsmul_mem_Ico hp <| by simp [hp]
theorem toIocDiv_apply_right (a : α) : toIocDiv hp a (a + p) = 0 :=
toIocDiv_eq_of_sub_zsmul_mem_Ioc hp <| by simp [hp]
theorem toIcoMod_apply_right (a : α) : toIcoMod hp a (a + p) = a := by
rw [toIcoMod_eq_iff hp, Set.left_mem_Ico]
exact ⟨lt_add_of_pos_right _ hp, 1, by simp⟩
theorem toIocMod_apply_right (a : α) : toIocMod hp a (a + p) = a + p := by
rw [toIocMod_eq_iff hp, Set.right_mem_Ioc]
exact ⟨lt_add_of_pos_right _ hp, 0, by simp⟩
@[simp]
theorem toIcoDiv_add_zsmul (a b : α) (m : ℤ) : toIcoDiv hp a (b + m • p) = toIcoDiv hp a b + m :=
toIcoDiv_eq_of_sub_zsmul_mem_Ico hp <| by
simpa only [add_smul, add_sub_add_right_eq_sub] using sub_toIcoDiv_zsmul_mem_Ico hp a b
@[simp]
theorem toIcoDiv_add_zsmul' (a b : α) (m : ℤ) :
toIcoDiv hp (a + m • p) b = toIcoDiv hp a b - m := by
refine toIcoDiv_eq_of_sub_zsmul_mem_Ico _ ?_
rw [sub_smul, ← sub_add, add_right_comm]
simpa using sub_toIcoDiv_zsmul_mem_Ico hp a b
@[simp]
theorem toIocDiv_add_zsmul (a b : α) (m : ℤ) : toIocDiv hp a (b + m • p) = toIocDiv hp a b + m :=
toIocDiv_eq_of_sub_zsmul_mem_Ioc hp <| by
simpa only [add_smul, add_sub_add_right_eq_sub] using sub_toIocDiv_zsmul_mem_Ioc hp a b
@[simp]
theorem toIocDiv_add_zsmul' (a b : α) (m : ℤ) :
toIocDiv hp (a + m • p) b = toIocDiv hp a b - m := by
refine toIocDiv_eq_of_sub_zsmul_mem_Ioc _ ?_
rw [sub_smul, ← sub_add, add_right_comm]
simpa using sub_toIocDiv_zsmul_mem_Ioc hp a b
@[simp]
theorem toIcoDiv_zsmul_add (a b : α) (m : ℤ) : toIcoDiv hp a (m • p + b) = m + toIcoDiv hp a b := by
rw [add_comm, toIcoDiv_add_zsmul, add_comm]
/-! Note we omit `toIcoDiv_zsmul_add'` as `-m + toIcoDiv hp a b` is not very convenient. -/
@[simp]
theorem toIocDiv_zsmul_add (a b : α) (m : ℤ) : toIocDiv hp a (m • p + b) = m + toIocDiv hp a b := by
rw [add_comm, toIocDiv_add_zsmul, add_comm]
/-! Note we omit `toIocDiv_zsmul_add'` as `-m + toIocDiv hp a b` is not very convenient. -/
@[simp]
theorem toIcoDiv_sub_zsmul (a b : α) (m : ℤ) : toIcoDiv hp a (b - m • p) = toIcoDiv hp a b - m := by
rw [sub_eq_add_neg, ← neg_smul, toIcoDiv_add_zsmul, sub_eq_add_neg]
@[simp]
theorem toIcoDiv_sub_zsmul' (a b : α) (m : ℤ) :
toIcoDiv hp (a - m • p) b = toIcoDiv hp a b + m := by
rw [sub_eq_add_neg, ← neg_smul, toIcoDiv_add_zsmul', sub_neg_eq_add]
@[simp]
theorem toIocDiv_sub_zsmul (a b : α) (m : ℤ) : toIocDiv hp a (b - m • p) = toIocDiv hp a b - m := by
rw [sub_eq_add_neg, ← neg_smul, toIocDiv_add_zsmul, sub_eq_add_neg]
@[simp]
theorem toIocDiv_sub_zsmul' (a b : α) (m : ℤ) :
toIocDiv hp (a - m • p) b = toIocDiv hp a b + m := by
rw [sub_eq_add_neg, ← neg_smul, toIocDiv_add_zsmul', sub_neg_eq_add]
@[simp]
theorem toIcoDiv_add_right (a b : α) : toIcoDiv hp a (b + p) = toIcoDiv hp a b + 1 := by
simpa only [one_zsmul] using toIcoDiv_add_zsmul hp a b 1
@[simp]
theorem toIcoDiv_add_right' (a b : α) : toIcoDiv hp (a + p) b = toIcoDiv hp a b - 1 := by
simpa only [one_zsmul] using toIcoDiv_add_zsmul' hp a b 1
@[simp]
theorem toIocDiv_add_right (a b : α) : toIocDiv hp a (b + p) = toIocDiv hp a b + 1 := by
simpa only [one_zsmul] using toIocDiv_add_zsmul hp a b 1
@[simp]
theorem toIocDiv_add_right' (a b : α) : toIocDiv hp (a + p) b = toIocDiv hp a b - 1 := by
simpa only [one_zsmul] using toIocDiv_add_zsmul' hp a b 1
@[simp]
theorem toIcoDiv_add_left (a b : α) : toIcoDiv hp a (p + b) = toIcoDiv hp a b + 1 := by
rw [add_comm, toIcoDiv_add_right]
@[simp]
theorem toIcoDiv_add_left' (a b : α) : toIcoDiv hp (p + a) b = toIcoDiv hp a b - 1 := by
rw [add_comm, toIcoDiv_add_right']
@[simp]
theorem toIocDiv_add_left (a b : α) : toIocDiv hp a (p + b) = toIocDiv hp a b + 1 := by
rw [add_comm, toIocDiv_add_right]
@[simp]
theorem toIocDiv_add_left' (a b : α) : toIocDiv hp (p + a) b = toIocDiv hp a b - 1 := by
rw [add_comm, toIocDiv_add_right']
@[simp]
theorem toIcoDiv_sub (a b : α) : toIcoDiv hp a (b - p) = toIcoDiv hp a b - 1 := by
simpa only [one_zsmul] using toIcoDiv_sub_zsmul hp a b 1
@[simp]
theorem toIcoDiv_sub' (a b : α) : toIcoDiv hp (a - p) b = toIcoDiv hp a b + 1 := by
simpa only [one_zsmul] using toIcoDiv_sub_zsmul' hp a b 1
@[simp]
theorem toIocDiv_sub (a b : α) : toIocDiv hp a (b - p) = toIocDiv hp a b - 1 := by
simpa only [one_zsmul] using toIocDiv_sub_zsmul hp a b 1
@[simp]
theorem toIocDiv_sub' (a b : α) : toIocDiv hp (a - p) b = toIocDiv hp a b + 1 := by
simpa only [one_zsmul] using toIocDiv_sub_zsmul' hp a b 1
theorem toIcoDiv_sub_eq_toIcoDiv_add (a b c : α) :
toIcoDiv hp a (b - c) = toIcoDiv hp (a + c) b := by
apply toIcoDiv_eq_of_sub_zsmul_mem_Ico
rw [← sub_right_comm, Set.sub_mem_Ico_iff_left, add_right_comm]
exact sub_toIcoDiv_zsmul_mem_Ico hp (a + c) b
theorem toIocDiv_sub_eq_toIocDiv_add (a b c : α) :
toIocDiv hp a (b - c) = toIocDiv hp (a + c) b := by
apply toIocDiv_eq_of_sub_zsmul_mem_Ioc
rw [← sub_right_comm, Set.sub_mem_Ioc_iff_left, add_right_comm]
exact sub_toIocDiv_zsmul_mem_Ioc hp (a + c) b
theorem toIcoDiv_sub_eq_toIcoDiv_add' (a b c : α) :
toIcoDiv hp (a - c) b = toIcoDiv hp a (b + c) := by
rw [← sub_neg_eq_add, toIcoDiv_sub_eq_toIcoDiv_add, sub_eq_add_neg]
theorem toIocDiv_sub_eq_toIocDiv_add' (a b c : α) :
toIocDiv hp (a - c) b = toIocDiv hp a (b + c) := by
rw [← sub_neg_eq_add, toIocDiv_sub_eq_toIocDiv_add, sub_eq_add_neg]
theorem toIcoDiv_neg (a b : α) : toIcoDiv hp a (-b) = -(toIocDiv hp (-a) b + 1) := by
suffices toIcoDiv hp a (-b) = -toIocDiv hp (-(a + p)) b by
rwa [neg_add, ← sub_eq_add_neg, toIocDiv_sub_eq_toIocDiv_add', toIocDiv_add_right] at this
rw [← neg_eq_iff_eq_neg, eq_comm]
apply toIocDiv_eq_of_sub_zsmul_mem_Ioc
obtain ⟨hc, ho⟩ := sub_toIcoDiv_zsmul_mem_Ico hp a (-b)
rw [← neg_lt_neg_iff, neg_sub' (-b), neg_neg, ← neg_smul] at ho
rw [← neg_le_neg_iff, neg_sub' (-b), neg_neg, ← neg_smul] at hc
refine ⟨ho, hc.trans_eq ?_⟩
rw [neg_add, neg_add_cancel_right]
theorem toIcoDiv_neg' (a b : α) : toIcoDiv hp (-a) b = -(toIocDiv hp a (-b) + 1) := by
simpa only [neg_neg] using toIcoDiv_neg hp (-a) (-b)
theorem toIocDiv_neg (a b : α) : toIocDiv hp a (-b) = -(toIcoDiv hp (-a) b + 1) := by
rw [← neg_neg b, toIcoDiv_neg, neg_neg, neg_neg, neg_add', neg_neg, add_sub_cancel_right]
theorem toIocDiv_neg' (a b : α) : toIocDiv hp (-a) b = -(toIcoDiv hp a (-b) + 1) := by
simpa only [neg_neg] using toIocDiv_neg hp (-a) (-b)
@[simp]
theorem toIcoMod_add_zsmul (a b : α) (m : ℤ) : toIcoMod hp a (b + m • p) = toIcoMod hp a b := by
rw [toIcoMod, toIcoDiv_add_zsmul, toIcoMod, add_smul]
abel
@[simp]
theorem toIcoMod_add_zsmul' (a b : α) (m : ℤ) :
toIcoMod hp (a + m • p) b = toIcoMod hp a b + m • p := by
simp only [toIcoMod, toIcoDiv_add_zsmul', sub_smul, sub_add]
@[simp]
theorem toIocMod_add_zsmul (a b : α) (m : ℤ) : toIocMod hp a (b + m • p) = toIocMod hp a b := by
rw [toIocMod, toIocDiv_add_zsmul, toIocMod, add_smul]
abel
@[simp]
theorem toIocMod_add_zsmul' (a b : α) (m : ℤ) :
toIocMod hp (a + m • p) b = toIocMod hp a b + m • p := by
simp only [toIocMod, toIocDiv_add_zsmul', sub_smul, sub_add]
@[simp]
theorem toIcoMod_zsmul_add (a b : α) (m : ℤ) : toIcoMod hp a (m • p + b) = toIcoMod hp a b := by
rw [add_comm, toIcoMod_add_zsmul]
@[simp]
theorem toIcoMod_zsmul_add' (a b : α) (m : ℤ) :
toIcoMod hp (m • p + a) b = m • p + toIcoMod hp a b := by
rw [add_comm, toIcoMod_add_zsmul', add_comm]
@[simp]
theorem toIocMod_zsmul_add (a b : α) (m : ℤ) : toIocMod hp a (m • p + b) = toIocMod hp a b := by
rw [add_comm, toIocMod_add_zsmul]
@[simp]
theorem toIocMod_zsmul_add' (a b : α) (m : ℤ) :
toIocMod hp (m • p + a) b = m • p + toIocMod hp a b := by
rw [add_comm, toIocMod_add_zsmul', add_comm]
@[simp]
theorem toIcoMod_sub_zsmul (a b : α) (m : ℤ) : toIcoMod hp a (b - m • p) = toIcoMod hp a b := by
rw [sub_eq_add_neg, ← neg_smul, toIcoMod_add_zsmul]
@[simp]
theorem toIcoMod_sub_zsmul' (a b : α) (m : ℤ) :
toIcoMod hp (a - m • p) b = toIcoMod hp a b - m • p := by
simp_rw [sub_eq_add_neg, ← neg_smul, toIcoMod_add_zsmul']
@[simp]
theorem toIocMod_sub_zsmul (a b : α) (m : ℤ) : toIocMod hp a (b - m • p) = toIocMod hp a b := by
rw [sub_eq_add_neg, ← neg_smul, toIocMod_add_zsmul]
@[simp]
theorem toIocMod_sub_zsmul' (a b : α) (m : ℤ) :
toIocMod hp (a - m • p) b = toIocMod hp a b - m • p := by
simp_rw [sub_eq_add_neg, ← neg_smul, toIocMod_add_zsmul']
@[simp]
theorem toIcoMod_add_right (a b : α) : toIcoMod hp a (b + p) = toIcoMod hp a b := by
simpa only [one_zsmul] using toIcoMod_add_zsmul hp a b 1
@[simp]
theorem toIcoMod_add_right' (a b : α) : toIcoMod hp (a + p) b = toIcoMod hp a b + p := by
simpa only [one_zsmul] using toIcoMod_add_zsmul' hp a b 1
@[simp]
theorem toIocMod_add_right (a b : α) : toIocMod hp a (b + p) = toIocMod hp a b := by
simpa only [one_zsmul] using toIocMod_add_zsmul hp a b 1
@[simp]
theorem toIocMod_add_right' (a b : α) : toIocMod hp (a + p) b = toIocMod hp a b + p := by
simpa only [one_zsmul] using toIocMod_add_zsmul' hp a b 1
@[simp]
theorem toIcoMod_add_left (a b : α) : toIcoMod hp a (p + b) = toIcoMod hp a b := by
rw [add_comm, toIcoMod_add_right]
@[simp]
theorem toIcoMod_add_left' (a b : α) : toIcoMod hp (p + a) b = p + toIcoMod hp a b := by
rw [add_comm, toIcoMod_add_right', add_comm]
@[simp]
theorem toIocMod_add_left (a b : α) : toIocMod hp a (p + b) = toIocMod hp a b := by
rw [add_comm, toIocMod_add_right]
@[simp]
theorem toIocMod_add_left' (a b : α) : toIocMod hp (p + a) b = p + toIocMod hp a b := by
rw [add_comm, toIocMod_add_right', add_comm]
@[simp]
theorem toIcoMod_sub (a b : α) : toIcoMod hp a (b - p) = toIcoMod hp a b := by
simpa only [one_zsmul] using toIcoMod_sub_zsmul hp a b 1
@[simp]
theorem toIcoMod_sub' (a b : α) : toIcoMod hp (a - p) b = toIcoMod hp a b - p := by
simpa only [one_zsmul] using toIcoMod_sub_zsmul' hp a b 1
@[simp]
theorem toIocMod_sub (a b : α) : toIocMod hp a (b - p) = toIocMod hp a b := by
simpa only [one_zsmul] using toIocMod_sub_zsmul hp a b 1
@[simp]
theorem toIocMod_sub' (a b : α) : toIocMod hp (a - p) b = toIocMod hp a b - p := by
simpa only [one_zsmul] using toIocMod_sub_zsmul' hp a b 1
theorem toIcoMod_sub_eq_sub (a b c : α) : toIcoMod hp a (b - c) = toIcoMod hp (a + c) b - c := by
simp_rw [toIcoMod, toIcoDiv_sub_eq_toIcoDiv_add, sub_right_comm]
theorem toIocMod_sub_eq_sub (a b c : α) : toIocMod hp a (b - c) = toIocMod hp (a + c) b - c := by
simp_rw [toIocMod, toIocDiv_sub_eq_toIocDiv_add, sub_right_comm]
theorem toIcoMod_add_right_eq_add (a b c : α) :
toIcoMod hp a (b + c) = toIcoMod hp (a - c) b + c := by
simp_rw [toIcoMod, toIcoDiv_sub_eq_toIcoDiv_add', sub_add_eq_add_sub]
theorem toIocMod_add_right_eq_add (a b c : α) :
toIocMod hp a (b + c) = toIocMod hp (a - c) b + c := by
simp_rw [toIocMod, toIocDiv_sub_eq_toIocDiv_add', sub_add_eq_add_sub]
theorem toIcoMod_neg (a b : α) : toIcoMod hp a (-b) = p - toIocMod hp (-a) b := by
simp_rw [toIcoMod, toIocMod, toIcoDiv_neg, neg_smul, add_smul]
abel
theorem toIcoMod_neg' (a b : α) : toIcoMod hp (-a) b = p - toIocMod hp a (-b) := by
simpa only [neg_neg] using toIcoMod_neg hp (-a) (-b)
theorem toIocMod_neg (a b : α) : toIocMod hp a (-b) = p - toIcoMod hp (-a) b := by
simp_rw [toIocMod, toIcoMod, toIocDiv_neg, neg_smul, add_smul]
abel
theorem toIocMod_neg' (a b : α) : toIocMod hp (-a) b = p - toIcoMod hp a (-b) := by
simpa only [neg_neg] using toIocMod_neg hp (-a) (-b)
theorem toIcoMod_eq_toIcoMod : toIcoMod hp a b = toIcoMod hp a c ↔ ∃ n : ℤ, c - b = n • p := by
refine ⟨fun h => ⟨toIcoDiv hp a c - toIcoDiv hp a b, ?_⟩, fun h => ?_⟩
· conv_lhs => rw [← toIcoMod_add_toIcoDiv_zsmul hp a b, ← toIcoMod_add_toIcoDiv_zsmul hp a c]
rw [h, sub_smul]
abel
· rcases h with ⟨z, hz⟩
rw [sub_eq_iff_eq_add] at hz
rw [hz, toIcoMod_zsmul_add]
theorem toIocMod_eq_toIocMod : toIocMod hp a b = toIocMod hp a c ↔ ∃ n : ℤ, c - b = n • p := by
refine ⟨fun h => ⟨toIocDiv hp a c - toIocDiv hp a b, ?_⟩, fun h => ?_⟩
· conv_lhs => rw [← toIocMod_add_toIocDiv_zsmul hp a b, ← toIocMod_add_toIocDiv_zsmul hp a c]
rw [h, sub_smul]
abel
· rcases h with ⟨z, hz⟩
rw [sub_eq_iff_eq_add] at hz
rw [hz, toIocMod_zsmul_add]
/-! ### Links between the `Ico` and `Ioc` variants applied to the same element -/
section IcoIoc
namespace AddCommGroup
theorem modEq_iff_toIcoMod_eq_left : a ≡ b [PMOD p] ↔ toIcoMod hp a b = a :=
modEq_iff_eq_add_zsmul.trans
⟨by
rintro ⟨n, rfl⟩
rw [toIcoMod_add_zsmul, toIcoMod_apply_left], fun h => ⟨toIcoDiv hp a b, eq_add_of_sub_eq h⟩⟩
theorem modEq_iff_toIocMod_eq_right : a ≡ b [PMOD p] ↔ toIocMod hp a b = a + p := by
refine modEq_iff_eq_add_zsmul.trans ⟨?_, fun h => ⟨toIocDiv hp a b + 1, ?_⟩⟩
· rintro ⟨z, rfl⟩
rw [toIocMod_add_zsmul, toIocMod_apply_left]
· rwa [add_one_zsmul, add_left_comm, ← sub_eq_iff_eq_add']
alias ⟨ModEq.toIcoMod_eq_left, _⟩ := modEq_iff_toIcoMod_eq_left
alias ⟨ModEq.toIcoMod_eq_right, _⟩ := modEq_iff_toIocMod_eq_right
variable (a b)
open List in
theorem tfae_modEq :
TFAE
[a ≡ b [PMOD p], ∀ z : ℤ, b - z • p ∉ Set.Ioo a (a + p), toIcoMod hp a b ≠ toIocMod hp a b,
toIcoMod hp a b + p = toIocMod hp a b] := by
rw [modEq_iff_toIcoMod_eq_left hp]
tfae_have 3 → 2
· 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
variable {a b}
theorem modEq_iff_not_forall_mem_Ioo_mod :
a ≡ b [PMOD p] ↔ ∀ z : ℤ, b - z • p ∉ Set.Ioo a (a + p) :=
(tfae_modEq hp a b).out 0 1
theorem modEq_iff_toIcoMod_ne_toIocMod : a ≡ b [PMOD p] ↔ toIcoMod hp a b ≠ toIocMod hp a b :=
(tfae_modEq hp a b).out 0 2
theorem modEq_iff_toIcoMod_add_period_eq_toIocMod :
a ≡ b [PMOD p] ↔ toIcoMod hp a b + p = toIocMod hp a b :=
(tfae_modEq hp a b).out 0 3
theorem not_modEq_iff_toIcoMod_eq_toIocMod : ¬a ≡ b [PMOD p] ↔ toIcoMod hp a b = toIocMod hp a b :=
(modEq_iff_toIcoMod_ne_toIocMod _).not_left
theorem not_modEq_iff_toIcoDiv_eq_toIocDiv :
¬a ≡ b [PMOD p] ↔ toIcoDiv hp a b = toIocDiv hp a b := by
rw [not_modEq_iff_toIcoMod_eq_toIocMod hp, toIcoMod, toIocMod, sub_right_inj,
(zsmul_strictMono_left hp).injective.eq_iff]
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]
end AddCommGroup
open AddCommGroup
/-- If `a` and `b` fall within the same cycle WRT `c`, then they are congruent modulo `p`. -/
@[simp]
theorem toIcoMod_inj {c : α} : toIcoMod hp c a = toIcoMod hp c b ↔ a ≡ b [PMOD p] := by
simp_rw [toIcoMod_eq_toIcoMod, modEq_iff_eq_add_zsmul, sub_eq_iff_eq_add']
alias ⟨_, AddCommGroup.ModEq.toIcoMod_eq_toIcoMod⟩ := toIcoMod_inj
theorem Ico_eq_locus_Ioc_eq_iUnion_Ioo :
{ b | toIcoMod hp a b = toIocMod hp a b } = ⋃ z : ℤ, Set.Ioo (a + z • p) (a + p + z • p) := by
ext1
simp_rw [Set.mem_setOf, Set.mem_iUnion, ← Set.sub_mem_Ioo_iff_left, ←
not_modEq_iff_toIcoMod_eq_toIocMod, modEq_iff_not_forall_mem_Ioo_mod hp, not_forall,
Classical.not_not]
theorem toIocDiv_wcovBy_toIcoDiv (a b : α) : toIocDiv hp a b ⩿ toIcoDiv hp a b := by
suffices toIocDiv hp a b = toIcoDiv hp a b ∨ toIocDiv hp a b + 1 = toIcoDiv hp a b by
rwa [wcovBy_iff_eq_or_covBy, ← Order.succ_eq_iff_covBy]
rw [eq_comm, ← not_modEq_iff_toIcoDiv_eq_toIocDiv, eq_comm, ←
modEq_iff_toIcoDiv_eq_toIocDiv_add_one]
exact em' _
theorem toIcoMod_le_toIocMod (a b : α) : toIcoMod hp a b ≤ toIocMod hp a b := by
rw [toIcoMod, toIocMod, sub_le_sub_iff_left]
exact zsmul_mono_left hp.le (toIocDiv_wcovBy_toIcoDiv _ _ _).le
theorem toIocMod_le_toIcoMod_add (a b : α) : toIocMod hp a b ≤ toIcoMod hp a b + p := by
rw [toIcoMod, toIocMod, sub_add, sub_le_sub_iff_left, sub_le_iff_le_add, ← add_one_zsmul,
(zsmul_strictMono_left hp).le_iff_le]
apply (toIocDiv_wcovBy_toIcoDiv _ _ _).le_succ
end IcoIoc
open AddCommGroup
theorem toIcoMod_eq_self : toIcoMod hp a b = b ↔ b ∈ Set.Ico a (a + p) := by
rw [toIcoMod_eq_iff, and_iff_left]
exact ⟨0, by simp⟩
theorem toIocMod_eq_self : toIocMod hp a b = b ↔ b ∈ Set.Ioc a (a + p) := by
rw [toIocMod_eq_iff, and_iff_left]
exact ⟨0, by simp⟩
@[simp]
theorem toIcoMod_toIcoMod (a₁ a₂ b : α) : toIcoMod hp a₁ (toIcoMod hp a₂ b) = toIcoMod hp a₁ b :=
(toIcoMod_eq_toIcoMod _).2 ⟨toIcoDiv hp a₂ b, self_sub_toIcoMod hp a₂ b⟩
@[simp]
theorem toIcoMod_toIocMod (a₁ a₂ b : α) : toIcoMod hp a₁ (toIocMod hp a₂ b) = toIcoMod hp a₁ b :=
(toIcoMod_eq_toIcoMod _).2 ⟨toIocDiv hp a₂ b, self_sub_toIocMod hp a₂ b⟩
@[simp]
theorem toIocMod_toIocMod (a₁ a₂ b : α) : toIocMod hp a₁ (toIocMod hp a₂ b) = toIocMod hp a₁ b :=
(toIocMod_eq_toIocMod _).2 ⟨toIocDiv hp a₂ b, self_sub_toIocMod hp a₂ b⟩
@[simp]
theorem toIocMod_toIcoMod (a₁ a₂ b : α) : toIocMod hp a₁ (toIcoMod hp a₂ b) = toIocMod hp a₁ b :=
(toIocMod_eq_toIocMod _).2 ⟨toIcoDiv hp a₂ b, self_sub_toIcoMod hp a₂ b⟩
theorem toIcoMod_periodic (a : α) : Function.Periodic (toIcoMod hp a) p :=
toIcoMod_add_right hp a
theorem toIocMod_periodic (a : α) : Function.Periodic (toIocMod hp a) p :=
toIocMod_add_right hp a
-- helper lemmas for when `a = 0`
section Zero
theorem toIcoMod_zero_sub_comm (a b : α) : toIcoMod hp 0 (a - b) = p - toIocMod hp 0 (b - a) := by
rw [← neg_sub, toIcoMod_neg, neg_zero]
theorem toIocMod_zero_sub_comm (a b : α) : toIocMod hp 0 (a - b) = p - toIcoMod hp 0 (b - a) := by
rw [← neg_sub, toIocMod_neg, neg_zero]
theorem toIcoDiv_eq_sub (a b : α) : toIcoDiv hp a b = toIcoDiv hp 0 (b - a) := by
rw [toIcoDiv_sub_eq_toIcoDiv_add, zero_add]
theorem toIocDiv_eq_sub (a b : α) : toIocDiv hp a b = toIocDiv hp 0 (b - a) := by
rw [toIocDiv_sub_eq_toIocDiv_add, zero_add]
theorem toIcoMod_eq_sub (a b : α) : toIcoMod hp a b = toIcoMod hp 0 (b - a) + a := by
rw [toIcoMod_sub_eq_sub, zero_add, sub_add_cancel]
theorem toIocMod_eq_sub (a b : α) : toIocMod hp a b = toIocMod hp 0 (b - a) + a := by
rw [toIocMod_sub_eq_sub, zero_add, sub_add_cancel]
theorem toIcoMod_add_toIocMod_zero (a b : α) :
toIcoMod hp 0 (a - b) + toIocMod hp 0 (b - a) = p := by
rw [toIcoMod_zero_sub_comm, sub_add_cancel]
theorem toIocMod_add_toIcoMod_zero (a b : α) :
toIocMod hp 0 (a - b) + toIcoMod hp 0 (b - a) = p := by
rw [_root_.add_comm, toIcoMod_add_toIocMod_zero]
end Zero
/-- `toIcoMod` as an equiv from the quotient. -/
@[simps symm_apply]
def QuotientAddGroup.equivIcoMod (a : α) : α ⧸ AddSubgroup.zmultiples p ≃ Set.Ico a (a + p) where
toFun b :=
⟨(toIcoMod_periodic hp a).lift b, QuotientAddGroup.induction_on b <| toIcoMod_mem_Ico hp a⟩
invFun := (↑)
right_inv b := Subtype.ext <| (toIcoMod_eq_self hp).mpr b.prop
left_inv b := by
induction b using QuotientAddGroup.induction_on
dsimp
rw [QuotientAddGroup.eq_iff_sub_mem, toIcoMod_sub_self]
apply AddSubgroup.zsmul_mem_zmultiples
@[simp]
theorem QuotientAddGroup.equivIcoMod_coe (a b : α) :
QuotientAddGroup.equivIcoMod hp a ↑b = ⟨toIcoMod hp a b, toIcoMod_mem_Ico hp a _⟩ :=
rfl
@[simp]
theorem QuotientAddGroup.equivIcoMod_zero (a : α) :
QuotientAddGroup.equivIcoMod hp a 0 = ⟨toIcoMod hp a 0, toIcoMod_mem_Ico hp a _⟩ :=
rfl
/-- `toIocMod` as an equiv from the quotient. -/
@[simps symm_apply]
def QuotientAddGroup.equivIocMod (a : α) : α ⧸ AddSubgroup.zmultiples p ≃ Set.Ioc a (a + p) where
toFun b :=
⟨(toIocMod_periodic hp a).lift b, QuotientAddGroup.induction_on b <| toIocMod_mem_Ioc hp a⟩
invFun := (↑)
right_inv b := Subtype.ext <| (toIocMod_eq_self hp).mpr b.prop
left_inv b := by
induction b using QuotientAddGroup.induction_on
dsimp
rw [QuotientAddGroup.eq_iff_sub_mem, toIocMod_sub_self]
apply AddSubgroup.zsmul_mem_zmultiples
@[simp]
theorem QuotientAddGroup.equivIocMod_coe (a b : α) :
QuotientAddGroup.equivIocMod hp a ↑b = ⟨toIocMod hp a b, toIocMod_mem_Ioc hp a _⟩ :=
rfl
@[simp]
theorem QuotientAddGroup.equivIocMod_zero (a : α) :
QuotientAddGroup.equivIocMod hp a 0 = ⟨toIocMod hp a 0, toIocMod_mem_Ioc hp a _⟩ :=
rfl
/-!
### 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
-- maybe harder to use than the primed one?
theorem btw_coe_iff {x₁ x₂ x₃ : α} :
Btw.btw (x₁ : α ⧸ AddSubgroup.zmultiples p) x₂ x₃ ↔
toIcoMod hp'.out x₁ x₂ ≤ toIocMod hp'.out x₁ x₃ := by
rw [btw_coe_iff', toIocMod_sub_eq_sub, toIcoMod_sub_eq_sub, zero_add, sub_le_sub_iff_right]
instance circularPreorder : CircularPreorder (α ⧸ AddSubgroup.zmultiples p) where
btw_refl x := show _ ≤ _ by simp [sub_self, hp'.out.le]
btw_cyclic_left {x₁ x₂ x₃} h := by
induction x₁ using QuotientAddGroup.induction_on
induction x₂ using QuotientAddGroup.induction_on
induction x₃ using QuotientAddGroup.induction_on
simp_rw [btw_coe_iff] at h ⊢
apply toIxxMod_cyclic_left _ h
sbtw := _
sbtw_iff_btw_not_btw := Iff.rfl
sbtw_trans_left {x₁ x₂ x₃ x₄} (h₁₂₃ : _ ∧ _) (h₂₃₄ : _ ∧ _) :=
show _ ∧ _ by
induction x₁ using QuotientAddGroup.induction_on
induction x₂ using QuotientAddGroup.induction_on
induction x₃ using QuotientAddGroup.induction_on
induction x₄ using QuotientAddGroup.induction_on
simp_rw [btw_coe_iff] at h₁₂₃ h₂₃₄ ⊢
apply toIxxMod_trans _ h₁₂₃ h₂₃₄
instance circularOrder : CircularOrder (α ⧸ AddSubgroup.zmultiples p) :=
{ QuotientAddGroup.circularPreorder with
btw_antisymm := fun {x₁ x₂ x₃} h₁₂₃ h₃₂₁ => by
induction x₁ using QuotientAddGroup.induction_on
induction x₂ using QuotientAddGroup.induction_on
induction x₃ using QuotientAddGroup.induction_on
rw [btw_cyclic] at h₃₂₁
simp_rw [btw_coe_iff] at h₁₂₃ h₃₂₁
simp_rw [← modEq_iff_eq_mod_zmultiples]
exact toIxxMod_antisymm _ h₁₂₃ h₃₂₁
btw_total := fun x₁ x₂ x₃ => by
induction x₁ using QuotientAddGroup.induction_on
induction x₂ using QuotientAddGroup.induction_on
induction x₃ using QuotientAddGroup.induction_on
simp_rw [btw_coe_iff]
apply toIxxMod_total }
end QuotientAddGroup
end Circular
end LinearOrderedAddCommGroup
/-!
### Connections to `Int.floor` and `Int.fract`
-/
section LinearOrderedField
variable {α : Type*} [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⟩
theorem toIocDiv_eq_neg_floor (a b : α) : toIocDiv hp a b = -⌊(a + p - b) / p⌋ := by
refine toIocDiv_eq_of_sub_zsmul_mem_Ioc hp ?_
rw [Set.mem_Ioc, zsmul_eq_mul, Int.cast_neg, neg_mul, sub_neg_eq_add, ← sub_nonneg,
sub_add_eq_sub_sub]
refine ⟨?_, Int.sub_floor_div_mul_nonneg _ hp⟩
rw [← add_lt_add_iff_right p, add_assoc, add_comm b, ← sub_lt_iff_lt_add, add_comm (_ * _), ←
sub_lt_iff_lt_add]
exact Int.sub_floor_div_mul_lt _ hp
theorem toIcoDiv_zero_one (b : α) : toIcoDiv (zero_lt_one' α) 0 b = ⌊b⌋ := by
simp [toIcoDiv_eq_floor]
theorem toIcoMod_eq_add_fract_mul (a b : α) :
toIcoMod hp a b = a + Int.fract ((b - a) / p) * p := by
rw [toIcoMod, toIcoDiv_eq_floor, Int.fract]
field_simp
ring
theorem toIcoMod_eq_fract_mul (b : α) : toIcoMod hp 0 b = Int.fract (b / p) * p := by
simp [toIcoMod_eq_add_fract_mul]
theorem toIocMod_eq_sub_fract_mul (a b : α) :
toIocMod hp a b = a + p - Int.fract ((a + p - b) / p) * p := by
rw [toIocMod, toIocDiv_eq_neg_floor, Int.fract]
field_simp
ring
theorem toIcoMod_zero_one (b : α) : toIcoMod (zero_lt_one' α) 0 b = Int.fract b := by
simp [toIcoMod_eq_add_fract_mul]
end LinearOrderedField
/-! ### Lemmas about unions of translates of intervals -/
section Union
open Set Int
section LinearOrderedAddCommGroup
variable {α : Type*} [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
theorem iUnion_Ico_add_zsmul : ⋃ n : ℤ, Ico (a + n • p) (a + (n + 1) • p) = univ := by
refine eq_univ_iff_forall.mpr fun b => mem_iUnion.mpr ?_
rcases sub_toIcoDiv_zsmul_mem_Ico hp a b with ⟨hl, hr⟩
refine ⟨toIcoDiv hp a b, ⟨le_sub_iff_add_le.mp hl, ?_⟩⟩
rw [add_smul, one_smul, ← add_assoc]
convert sub_lt_iff_lt_add.mp hr using 1; abel
theorem iUnion_Icc_add_zsmul : ⋃ n : ℤ, Icc (a + n • p) (a + (n + 1) • p) = univ := by
simpa only [iUnion_Ioc_add_zsmul hp a, univ_subset_iff] using
iUnion_mono fun n : ℤ => (Ioc_subset_Icc_self : Ioc (a + n • p) (a + (n + 1) • p) ⊆ Icc _ _)
theorem iUnion_Ioc_zsmul : ⋃ n : ℤ, Ioc (n • p) ((n + 1) • p) = univ := by
simpa only [zero_add] using iUnion_Ioc_add_zsmul hp 0
theorem iUnion_Ico_zsmul : ⋃ n : ℤ, Ico (n • p) ((n + 1) • p) = univ := by
simpa only [zero_add] using iUnion_Ico_add_zsmul hp 0
theorem iUnion_Icc_zsmul : ⋃ n : ℤ, Icc (n • p) ((n + 1) • p) = univ := by
simpa only [zero_add] using iUnion_Icc_add_zsmul hp 0
end LinearOrderedAddCommGroup
section LinearOrderedRing
variable {α : Type*} [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
@[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
@[deprecated (since := "2024-04-17")]
alias iUnion_Ico_add_int_cast := iUnion_Ico_add_intCast
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
@[deprecated (since := "2024-04-17")]
alias iUnion_Icc_add_int_cast := iUnion_Icc_add_intCast
variable (α)
theorem iUnion_Ioc_intCast : ⋃ n : ℤ, Ioc (n : α) (n + 1) = Set.univ := by
simpa only [zero_add] using iUnion_Ioc_add_intCast (0 : α)
@[deprecated (since := "2024-04-17")]
alias iUnion_Ioc_int_cast := iUnion_Ioc_intCast
theorem iUnion_Ico_intCast : ⋃ n : ℤ, Ico (n : α) (n + 1) = Set.univ := by
simpa only [zero_add] using iUnion_Ico_add_intCast (0 : α)
@[deprecated (since := "2024-04-17")]
alias iUnion_Ico_int_cast := iUnion_Ico_intCast
theorem iUnion_Icc_intCast : ⋃ n : ℤ, Icc (n : α) (n + 1) = Set.univ := by
simpa only [zero_add] using iUnion_Icc_add_intCast (0 : α)
@[deprecated (since := "2024-04-17")]
alias iUnion_Icc_int_cast := iUnion_Icc_intCast
end LinearOrderedRing
end Union
|
Algebra\Order\UpperLower.lean | /-
Copyright (c) 2022 Yaël Dillies. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies
-/
import Mathlib.Algebra.Order.Group.Instances
import Mathlib.Algebra.Order.Group.OrderIso
import Mathlib.Data.Set.Pointwise.SMul
import Mathlib.Order.UpperLower.Basic
/-!
# Algebraic operations on upper/lower sets
Upper/lower sets are preserved under pointwise algebraic operations in ordered groups.
-/
open Function Set
open Pointwise
section OrderedCommMonoid
variable {α : Type*} [OrderedCommMonoid α] {s : Set α} {x : α}
@[to_additive]
theorem IsUpperSet.smul_subset (hs : IsUpperSet s) (hx : 1 ≤ x) : x • s ⊆ s :=
smul_set_subset_iff.2 fun _ ↦ hs <| le_mul_of_one_le_left' hx
@[to_additive]
theorem IsLowerSet.smul_subset (hs : IsLowerSet s) (hx : x ≤ 1) : x • s ⊆ s :=
smul_set_subset_iff.2 fun _ ↦ hs <| mul_le_of_le_one_left' hx
end OrderedCommMonoid
section OrderedCommGroup
variable {α : Type*} [OrderedCommGroup α] {s t : Set α} {a : α}
@[to_additive]
theorem IsUpperSet.smul (hs : IsUpperSet s) : IsUpperSet (a • s) := hs.image <| OrderIso.mulLeft _
@[to_additive]
theorem IsLowerSet.smul (hs : IsLowerSet s) : IsLowerSet (a • s) := hs.image <| OrderIso.mulLeft _
@[to_additive]
theorem Set.OrdConnected.smul (hs : s.OrdConnected) : (a • s).OrdConnected := by
rw [← hs.upperClosure_inter_lowerClosure, smul_set_inter]
exact (upperClosure _).upper.smul.ordConnected.inter (lowerClosure _).lower.smul.ordConnected
@[to_additive]
theorem IsUpperSet.mul_left (ht : IsUpperSet t) : IsUpperSet (s * t) := by
rw [← smul_eq_mul, ← Set.iUnion_smul_set]
exact isUpperSet_iUnion₂ fun x _ ↦ ht.smul
@[to_additive]
theorem IsUpperSet.mul_right (hs : IsUpperSet s) : IsUpperSet (s * t) := by
rw [mul_comm]
exact hs.mul_left
@[to_additive]
theorem IsLowerSet.mul_left (ht : IsLowerSet t) : IsLowerSet (s * t) := ht.toDual.mul_left
@[to_additive]
theorem IsLowerSet.mul_right (hs : IsLowerSet s) : IsLowerSet (s * t) := hs.toDual.mul_right
@[to_additive]
theorem IsUpperSet.inv (hs : IsUpperSet s) : IsLowerSet s⁻¹ := fun _ _ h ↦ hs <| inv_le_inv' h
@[to_additive]
theorem IsLowerSet.inv (hs : IsLowerSet s) : IsUpperSet s⁻¹ := fun _ _ h ↦ hs <| inv_le_inv' h
@[to_additive]
theorem IsUpperSet.div_left (ht : IsUpperSet t) : IsLowerSet (s / t) := by
rw [div_eq_mul_inv]
exact ht.inv.mul_left
@[to_additive]
theorem IsUpperSet.div_right (hs : IsUpperSet s) : IsUpperSet (s / t) := by
rw [div_eq_mul_inv]
exact hs.mul_right
@[to_additive]
theorem IsLowerSet.div_left (ht : IsLowerSet t) : IsUpperSet (s / t) := ht.toDual.div_left
@[to_additive]
theorem IsLowerSet.div_right (hs : IsLowerSet s) : IsLowerSet (s / t) := hs.toDual.div_right
namespace UpperSet
@[to_additive]
instance : One (UpperSet α) :=
⟨Ici 1⟩
@[to_additive]
instance : Mul (UpperSet α) :=
⟨fun s t ↦ ⟨image2 (· * ·) s t, s.2.mul_right⟩⟩
@[to_additive]
instance : Div (UpperSet α) :=
⟨fun s t ↦ ⟨image2 (· / ·) s t, s.2.div_right⟩⟩
@[to_additive]
instance : SMul α (UpperSet α) :=
⟨fun a s ↦ ⟨(a • ·) '' s, s.2.smul⟩⟩
@[to_additive (attr := simp,norm_cast)]
theorem coe_one : ((1 : UpperSet α) : Set α) = Set.Ici 1 :=
rfl
@[to_additive (attr := simp,norm_cast)]
theorem coe_mul (s t : UpperSet α) : (↑(s * t) : Set α) = s * t :=
rfl
@[to_additive (attr := simp,norm_cast)]
theorem coe_div (s t : UpperSet α) : (↑(s / t) : Set α) = s / t :=
rfl
@[to_additive (attr := simp)]
theorem Ici_one : Ici (1 : α) = 1 :=
rfl
@[to_additive]
instance : MulAction α (UpperSet α) :=
SetLike.coe_injective.mulAction _ (fun _ _ => rfl)
@[to_additive]
instance commSemigroup : CommSemigroup (UpperSet α) :=
{ (SetLike.coe_injective.commSemigroup _ coe_mul : CommSemigroup (UpperSet α)) with }
@[to_additive]
private theorem one_mul (s : UpperSet α) : 1 * s = s :=
SetLike.coe_injective <|
(subset_mul_right _ left_mem_Ici).antisymm' <| by
rw [← smul_eq_mul, ← Set.iUnion_smul_set]
exact Set.iUnion₂_subset fun _ ↦ s.upper.smul_subset
@[to_additive]
instance : CommMonoid (UpperSet α) :=
{ UpperSet.commSemigroup with
one := 1
one_mul := one_mul
mul_one := fun s ↦ by
rw [mul_comm]
exact one_mul _ }
end UpperSet
namespace LowerSet
@[to_additive]
instance : One (LowerSet α) :=
⟨Iic 1⟩
@[to_additive]
instance : Mul (LowerSet α) :=
⟨fun s t ↦ ⟨image2 (· * ·) s t, s.2.mul_right⟩⟩
@[to_additive]
instance : Div (LowerSet α) :=
⟨fun s t ↦ ⟨image2 (· / ·) s t, s.2.div_right⟩⟩
@[to_additive]
instance : SMul α (LowerSet α) :=
⟨fun a s ↦ ⟨(a • ·) '' s, s.2.smul⟩⟩
@[to_additive (attr := simp,norm_cast)]
theorem coe_mul (s t : LowerSet α) : (↑(s * t) : Set α) = s * t :=
rfl
@[to_additive (attr := simp,norm_cast)]
theorem coe_div (s t : LowerSet α) : (↑(s / t) : Set α) = s / t :=
rfl
@[to_additive (attr := simp)]
theorem Iic_one : Iic (1 : α) = 1 :=
rfl
@[to_additive]
instance : MulAction α (LowerSet α) :=
SetLike.coe_injective.mulAction _ (fun _ _ => rfl)
@[to_additive]
instance commSemigroup : CommSemigroup (LowerSet α) :=
{ (SetLike.coe_injective.commSemigroup _ coe_mul : CommSemigroup (LowerSet α)) with }
@[to_additive]
private theorem one_mul (s : LowerSet α) : 1 * s = s :=
SetLike.coe_injective <|
(subset_mul_right _ right_mem_Iic).antisymm' <| by
rw [← smul_eq_mul, ← Set.iUnion_smul_set]
exact Set.iUnion₂_subset fun _ ↦ s.lower.smul_subset
@[to_additive]
instance : CommMonoid (LowerSet α) :=
{ LowerSet.commSemigroup with
one := 1
one_mul := one_mul
mul_one := fun s ↦ by
rw [mul_comm]
exact one_mul _ }
end LowerSet
variable (a s t)
@[to_additive (attr := simp)]
theorem upperClosure_one : upperClosure (1 : Set α) = 1 :=
upperClosure_singleton _
@[to_additive (attr := simp)]
theorem lowerClosure_one : lowerClosure (1 : Set α) = 1 :=
lowerClosure_singleton _
@[to_additive (attr := simp)]
theorem upperClosure_smul : upperClosure (a • s) = a • upperClosure s :=
upperClosure_image <| OrderIso.mulLeft a
@[to_additive (attr := simp)]
theorem lowerClosure_smul : lowerClosure (a • s) = a • lowerClosure s :=
lowerClosure_image <| OrderIso.mulLeft a
@[to_additive]
theorem mul_upperClosure : s * upperClosure t = upperClosure (s * t) := by
simp_rw [← smul_eq_mul, ← Set.iUnion_smul_set, upperClosure_iUnion, upperClosure_smul,
UpperSet.coe_iInf₂]
rfl
@[to_additive]
theorem mul_lowerClosure : s * lowerClosure t = lowerClosure (s * t) := by
simp_rw [← smul_eq_mul, ← Set.iUnion_smul_set, lowerClosure_iUnion, lowerClosure_smul,
LowerSet.coe_iSup₂]
rfl
@[to_additive]
theorem upperClosure_mul : ↑(upperClosure s) * t = upperClosure (s * t) := by
simp_rw [mul_comm _ t]
exact mul_upperClosure _ _
@[to_additive]
theorem lowerClosure_mul : ↑(lowerClosure s) * t = lowerClosure (s * t) := by
simp_rw [mul_comm _ t]
exact mul_lowerClosure _ _
@[to_additive (attr := simp)]
theorem upperClosure_mul_distrib : upperClosure (s * t) = upperClosure s * upperClosure t :=
SetLike.coe_injective <| by
rw [UpperSet.coe_mul, mul_upperClosure, upperClosure_mul, UpperSet.upperClosure]
@[to_additive (attr := simp)]
theorem lowerClosure_mul_distrib : lowerClosure (s * t) = lowerClosure s * lowerClosure t :=
SetLike.coe_injective <| by
rw [LowerSet.coe_mul, mul_lowerClosure, lowerClosure_mul, LowerSet.lowerClosure]
end OrderedCommGroup
|
Algebra\Order\ZeroLEOne.lean | /-
Copyright (c) 2016 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura, Mario Carneiro, Johannes Hölzl
-/
import Mathlib.Order.Basic
import Mathlib.Algebra.NeZero
/-!
# Typeclass expressing `0 ≤ 1`.
-/
variable {α : Type*}
open Function
/-- Typeclass for expressing that the `0` of a type is less or equal to its `1`. -/
class ZeroLEOneClass (α : Type*) [Zero α] [One α] [LE α] : Prop where
/-- Zero is less than or equal to one. -/
zero_le_one : (0 : α) ≤ 1
/-- `zero_le_one` with the type argument implicit. -/
@[simp] lemma zero_le_one [Zero α] [One α] [LE α] [ZeroLEOneClass α] : (0 : α) ≤ 1 :=
ZeroLEOneClass.zero_le_one
/-- `zero_le_one` with the type argument explicit. -/
lemma zero_le_one' (α) [Zero α] [One α] [LE α] [ZeroLEOneClass α] : (0 : α) ≤ 1 :=
zero_le_one
section
variable [Zero α] [One α] [PartialOrder α] [ZeroLEOneClass α] [NeZero (1 : α)]
/-- See `zero_lt_one'` for a version with the type explicit. -/
@[simp] lemma zero_lt_one : (0 : α) < 1 := zero_le_one.lt_of_ne (NeZero.ne' 1)
variable (α)
/-- See `zero_lt_one` for a version with the type implicit. -/
lemma zero_lt_one' : (0 : α) < 1 := zero_lt_one
end
alias one_pos := zero_lt_one
|
Algebra\Order\Antidiag\Finsupp.lean | /-
Copyright (c) 2023 Antoine Chambert-Loir and María Inés de Frutos-Fernández. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Antoine Chambert-Loir, María Inés de Frutos-Fernández, Eric Wieser, Bhavik Mehta,
Yaël Dillies
-/
import Mathlib.Algebra.Order.Antidiag.Pi
import Mathlib.Algebra.Order.BigOperators.Group.Finset
import Mathlib.Data.Finsupp.Basic
/-!
# Antidiagonal of finitely supported functions as finsets
This file defines the finset of finitely functions summing to a specific value on a finset. Such
finsets should be thought of as the "antidiagonals" in the space of finitely supported functions.
Precisely, for a commutative monoid `μ` with antidiagonals (see `Finset.HasAntidiagonal`),
`Finset.finsuppAntidiag s n` is the finset of all finitely supported functions `f : ι →₀ μ` with
support contained in `s` and such that the sum of its values equals `n : μ`.
We define it using `Finset.piAntidiag s n`, the corresponding antidiagonal in `ι → μ`.
## Main declarations
* `Finset.finsuppAntidiag s n`: Finset of all finitely supported functions `f : ι →₀ μ` with support
contained in `s` and such that the sum of its values equals `n : μ`.
-/
open Finsupp Function
variable {ι μ μ' : Type*}
namespace Finset
section AddCommMonoid
variable [DecidableEq ι] [AddCommMonoid μ] [HasAntidiagonal μ] [DecidableEq μ] {s : Finset ι}
{n : μ} {f : ι →₀ μ}
/-- The finset of functions `ι →₀ μ` with support contained in `s` and sum equal to `n`. -/
def finsuppAntidiag (s : Finset ι) (n : μ) : Finset (ι →₀ μ) :=
(piAntidiag s n).attach.map ⟨fun f ↦ ⟨s.filter (f.1 · ≠ 0), f.1, by
simpa using (mem_piAntidiag.1 f.2).2⟩, fun f g hfg ↦ Subtype.ext (congr_arg (⇑) hfg)⟩
@[simp] lemma mem_finsuppAntidiag : f ∈ finsuppAntidiag s n ↔ s.sum f = n ∧ f.support ⊆ s := by
simp [finsuppAntidiag, ← DFunLike.coe_fn_eq, subset_iff]
lemma mem_finsuppAntidiag' :
f ∈ finsuppAntidiag s n ↔ f.sum (fun _ x ↦ x) = n ∧ f.support ⊆ s := by
simp only [mem_finsuppAntidiag, and_congr_left_iff]
rintro hf
rw [sum_of_support_subset (N := μ) f hf (fun _ x ↦ x) fun _ _ ↦ rfl]
@[simp] lemma finsuppAntidiag_empty_zero : finsuppAntidiag (∅ : Finset ι) (0 : μ) = {0} := by
ext f; simp [finsuppAntidiag, ← DFunLike.coe_fn_eq (g := f), eq_comm]
@[simp] lemma finsuppAntidiag_empty_of_ne_zero (hn : n ≠ 0) :
finsuppAntidiag (∅ : Finset ι) n = ∅ :=
eq_empty_of_forall_not_mem (by simp [@eq_comm _ 0, hn.symm])
lemma finsuppAntidiag_empty (n : μ) :
finsuppAntidiag (∅ : Finset ι) n = if n = 0 then {0} else ∅ := by split_ifs with hn <;> simp [*]
theorem mem_finsuppAntidiag_insert {a : ι} {s : Finset ι}
(h : a ∉ s) (n : μ) {f : ι →₀ μ} :
f ∈ finsuppAntidiag (insert a s) n ↔
∃ m ∈ antidiagonal n, ∃ (g : ι →₀ μ),
f = Finsupp.update g a m.1 ∧ g ∈ finsuppAntidiag s m.2 := by
simp only [mem_finsuppAntidiag, mem_antidiagonal, Prod.exists, sum_insert h]
constructor
· rintro ⟨rfl, hsupp⟩
refine ⟨_, _, rfl, Finsupp.erase a f, ?_, ?_, ?_⟩
· rw [update_erase_eq_update, update_self]
· apply sum_congr rfl
intro x hx
rw [Finsupp.erase_ne (ne_of_mem_of_not_mem hx h)]
· rwa [support_erase, ← subset_insert_iff]
· rintro ⟨n1, n2, rfl, g, rfl, rfl, hgsupp⟩
refine ⟨?_, (support_update_subset _ _).trans (insert_subset_insert a hgsupp)⟩
simp only [coe_update]
apply congr_arg₂
· rw [update_same]
· apply sum_congr rfl
intro x hx
rw [update_noteq (ne_of_mem_of_not_mem hx h) n1 ⇑g]
theorem finsuppAntidiag_insert {a : ι} {s : Finset ι}
(h : a ∉ s) (n : μ) :
finsuppAntidiag (insert a s) n = (antidiagonal n).biUnion
(fun p : μ × μ =>
(finsuppAntidiag s p.snd).attach.map
⟨fun f => Finsupp.update f.val a p.fst,
(fun ⟨f, hf⟩ ⟨g, hg⟩ hfg => Subtype.ext <| by
simp only [mem_val, mem_finsuppAntidiag] at hf hg
simp only [DFunLike.ext_iff] at hfg ⊢
intro x
obtain rfl | hx := eq_or_ne x a
· replace hf := mt (hf.2 ·) h
replace hg := mt (hg.2 ·) h
rw [not_mem_support_iff.mp hf, not_mem_support_iff.mp hg]
· simpa only [coe_update, Function.update, dif_neg hx] using hfg x)⟩) := by
ext f
rw [mem_finsuppAntidiag_insert h, mem_biUnion]
simp_rw [mem_map, mem_attach, true_and, Subtype.exists, Embedding.coeFn_mk, exists_prop, and_comm,
eq_comm]
variable [AddCommMonoid μ'] [HasAntidiagonal μ'] [DecidableEq μ']
-- This should work under the assumption that e is an embedding and an AddHom
lemma mapRange_finsuppAntidiag_subset {e : μ ≃+ μ'} {s : Finset ι} {n : μ} :
(finsuppAntidiag s n).map (mapRange.addEquiv e).toEmbedding ⊆ finsuppAntidiag s (e n) := by
intro f
simp only [mem_map, mem_finsuppAntidiag']
rintro ⟨g, ⟨hsum, hsupp⟩, rfl⟩
simp only [AddEquiv.toEquiv_eq_coe, mapRange.addEquiv_toEquiv, Equiv.coe_toEmbedding,
mapRange.equiv_apply, EquivLike.coe_coe]
constructor
· rw [sum_mapRange_index (fun _ ↦ rfl), ← hsum, _root_.map_finsupp_sum]
· exact subset_trans (support_mapRange) hsupp
lemma mapRange_finsuppAntidiag_eq {e : μ ≃+ μ'} {s : Finset ι} {n : μ} :
(finsuppAntidiag s n).map (mapRange.addEquiv e).toEmbedding = finsuppAntidiag s (e n) := by
ext f
constructor
· apply mapRange_finsuppAntidiag_subset
· set h := (mapRange.addEquiv e).toEquiv with hh
intro hf
have : n = e.symm (e n) := (AddEquiv.eq_symm_apply e).mpr rfl
rw [mem_map_equiv, this]
apply mapRange_finsuppAntidiag_subset
rw [← mem_map_equiv]
convert hf
rw [map_map, hh]
convert map_refl
apply Function.Embedding.equiv_symm_toEmbedding_trans_toEmbedding
end AddCommMonoid
section CanonicallyOrderedAddCommMonoid
variable [DecidableEq ι] [DecidableEq μ] [CanonicallyOrderedAddCommMonoid μ] [HasAntidiagonal μ]
@[simp] lemma finsuppAntidiag_zero (s : Finset ι) : finsuppAntidiag s (0 : μ) = {0} := by
ext f; simp [finsuppAntidiag, ← DFunLike.coe_fn_eq (g := f), -mem_piAntidiag, eq_comm]
end CanonicallyOrderedAddCommMonoid
end Finset
|
Algebra\Order\Antidiag\Pi.lean | /-
Copyright (c) 2023 Antoine Chambert-Loir and María Inés de Frutos-Fernández. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Antoine Chambert-Loir, María Inés de Frutos-Fernández, Eric Wieser, Bhavik Mehta,
Yaël Dillies
-/
import Mathlib.Algebra.Order.BigOperators.Group.Finset
import Mathlib.Data.Finset.Pointwise
import Mathlib.Data.Fin.Tuple.NatAntidiagonal
/-!
# Antidiagonal of functions as finsets
This file provides the finset of functions summing to a specific value on a finset. Such finsets
should be thought of as the "antidiagonals" in the space of functions.
Precisely, for a commutative monoid `μ` with antidiagonals (see `Finset.HasAntidiagonal`),
`Finset.piAntidiag s n` is the finset of all functions `f : ι → μ` with support contained in `s` and
such that the sum of its values equals `n : μ`.
We define it recursively on `s` using `Finset.HasAntidiagonal.antidiagonal : μ → Finset (μ × μ)`.
Technically, we non-canonically identify `s` with `Fin n` where `n = s.card`, recurse on `n` using
that `(Fin (n + 1) → μ) ≃ (Fin n → μ) × μ`, and show the end result doesn't depend on our
identification. See `Finset.finAntidiag` for the details.
## Main declarations
* `Finset.piAntidiag s n`: Finset of all functions `f : ι → μ` with support contained in `s` and
such that the sum of its values equals `n : μ`.
* `Finset.finAntidiagonal d n`: Computationally efficient special case of `Finset.piAntidiag` when
`ι := Fin d`.
## TODO
`Finset.finAntidiagonal` is strictly more general than `Finset.Nat.antidiagonalTuple`. Deduplicate.
## See also
`Finset.finsuppAntidiag` for the `Finset (ι →₀ μ)`-valued version of `Finset.piAntidiag`.
-/
open Function
variable {ι μ μ' : Type*}
namespace Finset
section AddCommMonoid
variable [DecidableEq ι] [AddCommMonoid μ] [HasAntidiagonal μ] [DecidableEq μ] {n : μ}
/-!
### `Fin d → μ`
In this section, we define the antidiagonals in `Fin d → μ` by recursion on `d`. Note that this is
computationally efficient, although probably not as efficient as `Finset.Nat.antidiagonalTuple`.
-/
/-- `finAntidiagonal d n` is the type of `d`-tuples with sum `n`.
TODO: deduplicate with the less general `Finset.Nat.antidiagonalTuple`. -/
def finAntidiagonal (d : ℕ) (n : μ) : Finset (Fin d → μ) :=
aux d n
where
/-- Auxiliary construction for `finAntidiagonal` that bundles a proof of lawfulness
(`mem_finAntidiagonal`), as this is needed to invoke `disjiUnion`. Using `Finset.disjiUnion` makes
this computationally much more efficient than using `Finset.biUnion`. -/
aux (d : ℕ) (n : μ) : {s : Finset (Fin d → μ) // ∀ f, f ∈ s ↔ ∑ i, f i = n} :=
match d with
| 0 =>
if h : n = 0 then
⟨{0}, by simp [h, Subsingleton.elim _ ![]]⟩
else
⟨∅, by simp [Ne.symm h]⟩
| d + 1 =>
{ val := (antidiagonal n).disjiUnion
(fun ab => (aux d ab.2).1.map {
toFun := Fin.cons (ab.1)
inj' := Fin.cons_right_injective _ })
(fun i _hi j _hj hij => Finset.disjoint_left.2 fun t hti htj => hij $ by
simp_rw [Finset.mem_map, Embedding.coeFn_mk] at hti htj
obtain ⟨ai, hai, hij'⟩ := hti
obtain ⟨aj, haj, rfl⟩ := htj
rw [Fin.cons_eq_cons] at hij'
ext
· exact hij'.1
· obtain ⟨-, rfl⟩ := hij'
rw [← (aux d i.2).prop ai |>.mp hai, ← (aux d j.2).prop ai |>.mp haj])
property := fun f => by
simp_rw [mem_disjiUnion, mem_antidiagonal, mem_map, Embedding.coeFn_mk, Prod.exists,
(aux d _).prop, Fin.sum_univ_succ]
constructor
· rintro ⟨a, b, rfl, g, rfl, rfl⟩
simp only [Fin.cons_zero, Fin.cons_succ]
· intro hf
exact ⟨_, _, hf, _, rfl, Fin.cons_self_tail f⟩ }
@[simp] lemma mem_finAntidiagonal {d : ℕ} {f : Fin d → μ} :
f ∈ finAntidiagonal d n ↔ ∑ i, f i = n := (finAntidiagonal.aux d n).prop f
/-!
### `ι → μ`
In this section, we transfer the antidiagonals in `Fin s.card → μ` to antidiagonals in `ι → s` by
choosing an identification `s ≃ Fin s.card` and proving that the end result does not depend on that
choice.
-/
/-- The finset of functions `ι → μ` with support contained in `s` and sum `n`. -/
def piAntidiag (s : Finset ι) (n : μ) : Finset (ι → μ) := by
refine (Fintype.truncEquivFinOfCardEq $ Fintype.card_coe s).lift
(fun e ↦ (finAntidiagonal s.card n).map ⟨fun f i ↦ if hi : i ∈ s then f (e ⟨i, hi⟩) else 0, ?_⟩)
fun e₁ e₂ ↦ ?_
· rintro f g hfg
ext i
simpa using congr_fun hfg (e.symm i)
· ext f
simp only [mem_map, mem_finAntidiagonal]
refine Equiv.exists_congr ((e₁.symm.trans e₂).arrowCongr $ .refl _) fun g ↦ ?_
have := Fintype.sum_equiv (e₂.symm.trans e₁) _ g fun _ ↦ rfl
aesop
variable {s : Finset ι} {n : μ} {f : ι → μ}
@[simp] lemma mem_piAntidiag : f ∈ piAntidiag s n ↔ s.sum f = n ∧ ∀ i, f i ≠ 0 → i ∈ s := by
rw [piAntidiag]
induction' Fintype.truncEquivFinOfCardEq (Fintype.card_coe s) using Trunc.ind with e
simp only [Trunc.lift_mk, mem_map, mem_finAntidiagonal, Embedding.coeFn_mk]
constructor
· rintro ⟨f, ⟨hf, rfl⟩, rfl⟩
rw [sum_dite_of_true fun _ ↦ id]
exact ⟨Fintype.sum_equiv e _ _ (by simp), by simp (config := { contextual := true })⟩
· rintro ⟨rfl, hf⟩
refine ⟨f ∘ (↑) ∘ e.symm, ?_, by ext i; have := not_imp_comm.1 (hf i); aesop⟩
rw [← sum_attach s]
exact Fintype.sum_equiv e.symm _ _ (by simp)
@[simp] lemma piAntidiag_empty_zero : piAntidiag (∅ : Finset ι) (0 : μ) = {0} := by
ext; simp [Fintype.sum_eq_zero_iff_of_nonneg, funext_iff, not_imp_comm, ← forall_and]
@[simp] lemma piAntidiag_empty_of_ne_zero (hn : n ≠ 0) : piAntidiag (∅ : Finset ι) n = ∅ :=
eq_empty_of_forall_not_mem (by simp [@eq_comm _ 0, hn.symm])
lemma piAntidiag_empty (n : μ) : piAntidiag (∅ : Finset ι) n = if n = 0 then {0} else ∅ := by
split_ifs with hn <;> simp [*]
lemma finsetCongr_piAntidiag_eq_antidiag (n : μ) :
Equiv.finsetCongr (Equiv.boolArrowEquivProd _) (piAntidiag univ n) = antidiagonal n := by
ext ⟨x₁, x₂⟩
simp_rw [Equiv.finsetCongr_apply, mem_map, Equiv.toEmbedding, Function.Embedding.coeFn_mk,
← Equiv.eq_symm_apply]
simp [add_comm]
end AddCommMonoid
section AddCancelCommMonoid
variable [DecidableEq ι] [AddCancelCommMonoid μ] [HasAntidiagonal μ] [DecidableEq μ] {i : ι}
{s : Finset ι}
lemma pairwiseDisjoint_piAntidiag_map_addRightEmbedding (hi : i ∉ s) (n : μ) :
(antidiagonal n : Set (μ × μ)).PairwiseDisjoint fun p ↦
map (addRightEmbedding fun j ↦ if j = i then p.1 else 0) (s.piAntidiag p.2) := by
rintro ⟨a, b⟩ hab ⟨c, d⟩ hcd
simp only [ne_eq, antidiagonal_congr' hab hcd, disjoint_left, mem_map, mem_piAntidiag,
addRightEmbedding_apply, not_exists, not_and, and_imp, forall_exists_index]
rintro hfg _ f rfl - rfl g rfl - hgf
exact hfg $ by simpa [sum_add_distrib, hi] using congr_arg (∑ j ∈ s, · j) hgf.symm
lemma piAntidiag_cons (hi : i ∉ s) (n : μ) :
piAntidiag (cons i s hi) n = (antidiagonal n).disjiUnion (fun p : μ × μ ↦
(piAntidiag s p.snd).map (addRightEmbedding fun t ↦ if t = i then p.fst else 0))
(pairwiseDisjoint_piAntidiag_map_addRightEmbedding hi _) := by
ext f
simp only [mem_piAntidiag, sum_cons, ne_eq, mem_cons, mem_disjiUnion, mem_antidiagonal, mem_map,
addLeftEmbedding_apply, Prod.exists]
constructor
· rintro ⟨hn, hf⟩
refine ⟨_, _, hn, update f i 0, ⟨sum_update_of_not_mem hi _ _, fun j ↦ ?_⟩, by aesop⟩
have := fun h₁ h₂ ↦ (hf j h₁).resolve_left h₂
aesop (add simp [update])
· rintro ⟨a, _, hn, g, ⟨rfl, hg⟩, rfl⟩
have := hg i
aesop (add simp [sum_add_distrib])
lemma piAntidiag_insert [DecidableEq (ι → μ)] (hi : i ∉ s) (n : μ) :
piAntidiag (insert i s) n = (antidiagonal n).biUnion fun p : μ × μ ↦ (piAntidiag s p.snd).image
(fun f j ↦ f j + if j = i then p.fst else 0) := by
simpa [map_eq_image, addRightEmbedding] using piAntidiag_cons hi n
end AddCancelCommMonoid
section CanonicallyOrderedAddCommMonoid
variable [DecidableEq ι] [CanonicallyOrderedAddCommMonoid μ] [HasAntidiagonal μ] [DecidableEq μ]
@[simp] lemma piAntidiag_zero (s : Finset ι) : piAntidiag s (0 : μ) = {0} := by
ext; simp [Fintype.sum_eq_zero_iff_of_nonneg, funext_iff, not_imp_comm, ← forall_and]
end CanonicallyOrderedAddCommMonoid
section Nat
variable [DecidableEq ι]
/-- Local notation for the pointwise operation `n • s := {n • a | a ∈ s}` to avoid conflict with the
pointwise operation `n • s := s + ... + s` (`n` times). -/
local infixr:73 "•ℕ" => @SMul.smul _ _ Finset.smulFinset
lemma piAntidiag_univ_fin_eq_antidiagonalTuple (n k : ℕ) :
piAntidiag univ n = Nat.antidiagonalTuple k n := by
ext; simp [Nat.mem_antidiagonalTuple]
lemma nsmul_piAntidiag [DecidableEq (ι → ℕ)] (s : Finset ι) (m : ℕ) {n : ℕ} (hn : n ≠ 0) :
n •ℕ piAntidiag s m = (piAntidiag s (n * m)).filter fun f : ι → ℕ ↦ ∀ i ∈ s, n ∣ f i := by
ext f
refine mem_smul_finset.trans ?_
simp only [mem_smul_finset, mem_filter, mem_piAntidiag, Function.Embedding.coeFn_mk, exists_prop,
and_assoc]
constructor
· rintro ⟨f, rfl, hf, rfl⟩
simpa [← mul_sum, hn] using hf
rintro ⟨hfsum, hfsup, hfdvd⟩
have (i) : n ∣ f i := by
by_cases hi : i ∈ s
· exact hfdvd _ hi
· rw [not_imp_comm.1 (hfsup _) hi]
exact dvd_zero _
refine ⟨fun i ↦ f i / n, ?_⟩
simpa [Nat.sum_div, Nat.div_ne_zero_iff_of_dvd, funext_iff, Nat.mul_div_cancel', ← Nat.sum_div, *]
lemma map_nsmul_piAntidiag (s : Finset ι) (m : ℕ) {n : ℕ} (hn : n ≠ 0) :
(piAntidiag s m).map
⟨(n • ·), fun f g h ↦ funext fun i ↦ mul_right_injective₀ hn (congr_fun h i)⟩ =
(piAntidiag s (n * m)).filter fun f : ι → ℕ ↦ ∀ i ∈ s, n ∣ f i := by
classical rw [map_eq_image]; exact nsmul_piAntidiag _ _ hn
lemma nsmul_piAntidiag_univ [Fintype ι] (m : ℕ) {n : ℕ} (hn : n ≠ 0) :
@SMul.smul _ _ Finset.smulFinset n (piAntidiag univ m) =
(piAntidiag univ (n * m)).filter fun f : ι → ℕ ↦ ∀ i, n ∣ f i := by
have := nsmul_piAntidiag (univ : Finset ι) m hn
simp at this
convert this
lemma map_nsmul_piAntidiag_univ [Fintype ι] (m : ℕ) {n : ℕ} (hn : n ≠ 0) :
(piAntidiag (univ : Finset ι) m).map
⟨(n • ·), fun f g h ↦ funext fun i ↦ mul_right_injective₀ hn (congr_fun h i)⟩ =
(piAntidiag univ (n * m)).filter fun f : ι → ℕ ↦ ∀ i, n ∣ f i := by
simpa using map_nsmul_piAntidiag (univ : Finset ι) m hn
end Nat
lemma map_sym_eq_piAntidiag [DecidableEq ι] (s : Finset ι) (n : ℕ) :
(s.sym n).map ⟨fun m a ↦ m.1.count a, Multiset.count_injective.comp Sym.coe_injective⟩ =
piAntidiag s n := by
ext f
simp only [Sym.val_eq_coe, mem_map, mem_sym_iff, Embedding.coeFn_mk, funext_iff, Sym.exists,
Sym.mem_mk, Sym.coe_mk, exists_and_left, exists_prop, mem_piAntidiag, ne_eq]
constructor
· rintro ⟨m, hm, rfl, hf⟩
simpa [← hf, Multiset.sum_count_eq_card hm]
· rintro ⟨rfl, hf⟩
refine ⟨∑ a ∈ s, f a • {a}, ?_, ?_⟩
· simp (config := { contextual := true })
· simpa [Multiset.count_sum', Multiset.count_singleton, not_imp_comm, eq_comm (a := 0)] using hf
end Finset
|
Algebra\Order\Antidiag\Prod.lean | /-
Copyright (c) 2023 Antoine Chambert-Loir and María Inés de Frutos-Fernández. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Antoine Chambert-Loir, María Inés de Frutos-Fernández, Bhavik Mehta, Eric Wieser
-/
import Mathlib.Algebra.Order.Sub.Defs
import Mathlib.Data.Finset.Basic
import Mathlib.Order.Interval.Finset.Defs
/-! # Antidiagonal with values in general types
We define a type class `Finset.HasAntidiagonal A` which contains a function
`antidiagonal : A → Finset (A × A)` such that `antidiagonal n`
is the finset of all pairs adding to `n`, as witnessed by `mem_antidiagonal`.
When `A` is a canonically ordered add monoid with locally finite order
this typeclass can be instantiated with `Finset.antidiagonalOfLocallyFinite`.
This applies in particular when `A` is `ℕ`, more generally or `σ →₀ ℕ`,
or even `ι →₀ A` under the additional assumption `OrderedSub A`
that make it a canonically ordered add monoid.
(In fact, we would just need an `AddMonoid` with a compatible order,
finite `Iic`, such that if `a + b = n`, then `a, b ≤ n`,
and any finiteness condition would be OK.)
For computational reasons it is better to manually provide instances for `ℕ`
and `σ →₀ ℕ`, to avoid quadratic runtime performance.
These instances are provided as `Finset.Nat.instHasAntidiagonal` and `Finsupp.instHasAntidiagonal`.
This is why `Finset.antidiagonalOfLocallyFinite` is an `abbrev` and not an `instance`.
This definition does not exactly match with that of `Multiset.antidiagonal`
defined in `Mathlib.Data.Multiset.Antidiagonal`, because of the multiplicities.
Indeed, by counting multiplicities, `Multiset α` is equivalent to `α →₀ ℕ`,
but `Finset.antidiagonal` and `Multiset.antidiagonal` will return different objects.
For example, for `s : Multiset ℕ := {0,0,0}`, `Multiset.antidiagonal s` has 8 elements
but `Finset.antidiagonal s` has only 4.
```lean
def s : Multiset ℕ := {0, 0, 0}
#eval (Finset.antidiagonal s).card -- 4
#eval Multiset.card (Multiset.antidiagonal s) -- 8
```
## TODO
* Define `HasMulAntidiagonal` (for monoids).
For `PNat`, we will recover the set of divisors of a strictly positive integer.
-/
open Function
namespace Finset
/-- The class of additive monoids with an antidiagonal -/
class HasAntidiagonal (A : Type*) [AddMonoid A] where
/-- The antidiagonal of an element `n` is the finset of pairs `(i, j)` such that `i + j = n`. -/
antidiagonal : A → Finset (A × A)
/-- A pair belongs to `antidiagonal n` iff the sum of its components is equal to `n`. -/
mem_antidiagonal {n} {a} : a ∈ antidiagonal n ↔ a.fst + a.snd = n
export HasAntidiagonal (antidiagonal mem_antidiagonal)
attribute [simp] mem_antidiagonal
variable {A : Type*}
/-- All `HasAntidiagonal` instances are equal -/
instance [AddMonoid A] : Subsingleton (HasAntidiagonal A) where
allEq := by
rintro ⟨a, ha⟩ ⟨b, hb⟩
congr with n xy
rw [ha, hb]
-- The goal of this lemma is to allow to rewrite antidiagonal
-- when the decidability instances obsucate Lean
lemma hasAntidiagonal_congr (A : Type*) [AddMonoid A]
[H1 : HasAntidiagonal A] [H2 : HasAntidiagonal A] :
H1.antidiagonal = H2.antidiagonal := by congr!; subsingleton
theorem swap_mem_antidiagonal [AddCommMonoid A] [HasAntidiagonal A] {n : A} {xy : A × A} :
xy.swap ∈ antidiagonal n ↔ xy ∈ antidiagonal n := by
simp [add_comm]
@[simp] theorem map_prodComm_antidiagonal [AddCommMonoid A] [HasAntidiagonal A] {n : A} :
(antidiagonal n).map (Equiv.prodComm A A) = antidiagonal n :=
Finset.ext fun ⟨a, b⟩ => by simp [add_comm]
/-- See also `Finset.map_prodComm_antidiagonal`. -/
@[simp] theorem map_swap_antidiagonal [AddCommMonoid A] [HasAntidiagonal A] {n : A} :
(antidiagonal n).map ⟨Prod.swap, Prod.swap_injective⟩ = antidiagonal n :=
map_prodComm_antidiagonal
section AddCancelMonoid
variable [AddCancelMonoid A] [HasAntidiagonal A] {p q : A × A} {n : A}
/-- A point in the antidiagonal is determined by its first coordinate.
See also `Finset.antidiagonal_congr'`. -/
theorem antidiagonal_congr (hp : p ∈ antidiagonal n) (hq : q ∈ antidiagonal n) :
p = q ↔ p.1 = q.1 := by
refine ⟨congr_arg Prod.fst, fun h ↦ Prod.ext h ((add_right_inj q.fst).mp ?_)⟩
rw [mem_antidiagonal] at hp hq
rw [hq, ← h, hp]
/-- A point in the antidiagonal is determined by its first co-ordinate (subtype version of
`Finset.antidiagonal_congr`). This lemma is used by the `ext` tactic. -/
@[ext] theorem antidiagonal_subtype_ext {p q : antidiagonal n} (h : p.val.1 = q.val.1) : p = q :=
Subtype.ext ((antidiagonal_congr p.prop q.prop).mpr h)
end AddCancelMonoid
section AddCancelCommMonoid
variable [AddCancelCommMonoid A] [HasAntidiagonal A] {p q : A × A} {n : A}
/-- A point in the antidiagonal is determined by its second coordinate.
See also `Finset.antidiagonal_congr`. -/
lemma antidiagonal_congr' (hp : p ∈ antidiagonal n) (hq : q ∈ antidiagonal n) :
p = q ↔ p.2 = q.2 := by
rw [← Prod.swap_inj]
exact antidiagonal_congr (swap_mem_antidiagonal.2 hp) (swap_mem_antidiagonal.2 hq)
end AddCancelCommMonoid
section CanonicallyOrderedAddCommMonoid
variable [CanonicallyOrderedAddCommMonoid A] [HasAntidiagonal A]
@[simp]
theorem antidiagonal_zero : antidiagonal (0 : A) = {(0, 0)} := by
ext ⟨x, y⟩
simp
theorem antidiagonal.fst_le {n : A} {kl : A × A} (hlk : kl ∈ antidiagonal n) : kl.1 ≤ n := by
rw [le_iff_exists_add]
use kl.2
rwa [mem_antidiagonal, eq_comm] at hlk
theorem antidiagonal.snd_le {n : A} {kl : A × A} (hlk : kl ∈ antidiagonal n) : kl.2 ≤ n := by
rw [le_iff_exists_add]
use kl.1
rwa [mem_antidiagonal, eq_comm, add_comm] at hlk
end CanonicallyOrderedAddCommMonoid
section OrderedSub
variable [CanonicallyOrderedAddCommMonoid A] [Sub A] [OrderedSub A]
variable [ContravariantClass A A (· + ·) (· ≤ ·)]
variable [HasAntidiagonal A]
theorem filter_fst_eq_antidiagonal (n m : A) [DecidablePred (· = m)] [Decidable (m ≤ n)] :
filter (fun x : A × A ↦ x.fst = m) (antidiagonal n) = if m ≤ n then {(m, n - m)} else ∅ := by
ext ⟨a, b⟩
suffices a = m → (a + b = n ↔ m ≤ n ∧ b = n - m) by
rw [mem_filter, mem_antidiagonal, apply_ite (fun n ↦ (a, b) ∈ n), mem_singleton,
Prod.mk.inj_iff, ite_prop_iff_or]
simpa [← and_assoc, @and_right_comm _ (a = _), and_congr_left_iff]
rintro rfl
constructor
· rintro rfl
exact ⟨le_add_right le_rfl, (add_tsub_cancel_left _ _).symm⟩
· rintro ⟨h, rfl⟩
exact add_tsub_cancel_of_le h
theorem filter_snd_eq_antidiagonal (n m : A) [DecidablePred (· = m)] [Decidable (m ≤ n)] :
filter (fun x : A × A ↦ x.snd = m) (antidiagonal n) = if m ≤ n then {(n - m, m)} else ∅ := by
have : (fun x : A × A ↦ (x.snd = m)) ∘ Prod.swap = fun x : A × A ↦ x.fst = m := by
ext; simp
rw [← map_swap_antidiagonal, filter_map]
simp [this, filter_fst_eq_antidiagonal, apply_ite (Finset.map _)]
end OrderedSub
/-- The disjoint union of antidiagonals `Σ (n : A), antidiagonal n` is equivalent to the product
`A × A`. This is such an equivalence, obtained by mapping `(n, (k, l))` to `(k, l)`. -/
@[simps]
def sigmaAntidiagonalEquivProd [AddMonoid A] [HasAntidiagonal A] :
(Σ n : A, antidiagonal n) ≃ A × A where
toFun x := x.2
invFun x := ⟨x.1 + x.2, x, mem_antidiagonal.mpr rfl⟩
left_inv := by
rintro ⟨n, ⟨k, l⟩, h⟩
rw [mem_antidiagonal] at h
exact Sigma.subtype_ext h rfl
right_inv x := rfl
variable {A : Type*}
[CanonicallyOrderedAddCommMonoid A]
[LocallyFiniteOrder A] [DecidableEq A]
/-- In a canonically ordered add monoid, the antidiagonal can be construct by filtering.
Note that this is not an instance, as for some times a more efficient algorithm is available. -/
abbrev antidiagonalOfLocallyFinite : HasAntidiagonal A where
antidiagonal n := Finset.filter (fun uv => uv.fst + uv.snd = n) (Finset.product (Iic n) (Iic n))
mem_antidiagonal {n} {a} := by
simp only [Prod.forall, mem_filter, and_iff_right_iff_imp]
intro h; rw [← h]
erw [mem_product, mem_Iic, mem_Iic]
exact ⟨le_self_add, le_add_self⟩
end Finset
|
Algebra\Order\Archimedean\Basic.lean | /-
Copyright (c) 2018 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
-/
import Mathlib.Algebra.Order.Field.Power
import Mathlib.Data.Int.LeastGreatest
import Mathlib.Data.Rat.Floor
import Mathlib.Data.NNRat.Defs
/-!
# Archimedean groups and fields.
This file defines the archimedean property for ordered groups and proves several results connected
to this notion. Being archimedean means that for all elements `x` and `y>0` there exists a natural
number `n` such that `x ≤ n • y`.
## Main definitions
* `Archimedean` is a typeclass for an ordered additive commutative monoid to have the archimedean
property.
* `Archimedean.floorRing` defines a floor function on an archimedean linearly ordered ring making
it into a `floorRing`.
## Main statements
* `ℕ`, `ℤ`, and `ℚ` are archimedean.
-/
open Int Set
variable {α : Type*}
/-- An ordered additive commutative monoid is called `Archimedean` if for any two elements `x`, `y`
such that `0 < y`, there exists a natural number `n` such that `x ≤ n • y`. -/
class Archimedean (α) [OrderedAddCommMonoid α] : Prop where
/-- For any two elements `x`, `y` such that `0 < y`, there exists a natural number `n`
such that `x ≤ n • y`. -/
arch : ∀ (x : α) {y : α}, 0 < y → ∃ n : ℕ, x ≤ n • y
instance OrderDual.archimedean [OrderedAddCommGroup α] [Archimedean α] : Archimedean αᵒᵈ :=
⟨fun x y hy =>
let ⟨n, hn⟩ := Archimedean.arch (-ofDual x) (neg_pos.2 hy)
⟨n, by rwa [neg_nsmul, neg_le_neg_iff] at hn⟩⟩
variable {M : Type*}
theorem exists_lt_nsmul [OrderedAddCommMonoid M] [Archimedean M]
[CovariantClass M M (· + ·) (· < ·)] {a : M} (ha : 0 < a) (b : M) :
∃ n : ℕ, b < n • a :=
let ⟨k, hk⟩ := Archimedean.arch b ha
⟨k + 1, hk.trans_lt <| nsmul_lt_nsmul_left ha k.lt_succ_self⟩
section LinearOrderedAddCommGroup
variable [LinearOrderedAddCommGroup α] [Archimedean α]
/-- An archimedean decidable linearly ordered `AddCommGroup` has a version of the floor: for
`a > 0`, any `g` in the group lies between some two consecutive multiples of `a`. -/
theorem existsUnique_zsmul_near_of_pos {a : α} (ha : 0 < a) (g : α) :
∃! k : ℤ, k • a ≤ g ∧ g < (k + 1) • a := by
let s : Set ℤ := { n : ℤ | n • a ≤ g }
obtain ⟨k, hk : -g ≤ k • a⟩ := Archimedean.arch (-g) ha
have h_ne : s.Nonempty := ⟨-k, by simpa [s] using neg_le_neg hk⟩
obtain ⟨k, hk⟩ := Archimedean.arch g ha
have h_bdd : ∀ n ∈ s, n ≤ (k : ℤ) := by
intro n hn
apply (zsmul_le_zsmul_iff ha).mp
rw [← natCast_zsmul] at hk
exact le_trans hn hk
obtain ⟨m, hm, hm'⟩ := Int.exists_greatest_of_bdd ⟨k, h_bdd⟩ h_ne
have hm'' : g < (m + 1) • a := by
contrapose! hm'
exact ⟨m + 1, hm', lt_add_one _⟩
refine ⟨m, ⟨hm, hm''⟩, fun n hn => (hm' n hn.1).antisymm <| Int.le_of_lt_add_one ?_⟩
rw [← zsmul_lt_zsmul_iff ha]
exact lt_of_le_of_lt hm hn.2
theorem existsUnique_zsmul_near_of_pos' {a : α} (ha : 0 < a) (g : α) :
∃! k : ℤ, 0 ≤ g - k • a ∧ g - k • a < a := by
simpa only [sub_nonneg, add_zsmul, one_zsmul, sub_lt_iff_lt_add'] using
existsUnique_zsmul_near_of_pos ha g
theorem existsUnique_sub_zsmul_mem_Ico {a : α} (ha : 0 < a) (b c : α) :
∃! m : ℤ, b - m • a ∈ Set.Ico c (c + a) := by
simpa only [mem_Ico, le_sub_iff_add_le, zero_add, add_comm c, sub_lt_iff_lt_add', add_assoc] using
existsUnique_zsmul_near_of_pos' ha (b - c)
theorem existsUnique_add_zsmul_mem_Ico {a : α} (ha : 0 < a) (b c : α) :
∃! m : ℤ, b + m • a ∈ Set.Ico c (c + a) :=
(Equiv.neg ℤ).bijective.existsUnique_iff.2 <| by
simpa only [Equiv.neg_apply, mem_Ico, neg_zsmul, ← sub_eq_add_neg, le_sub_iff_add_le, zero_add,
add_comm c, sub_lt_iff_lt_add', add_assoc] using existsUnique_zsmul_near_of_pos' ha (b - c)
theorem existsUnique_add_zsmul_mem_Ioc {a : α} (ha : 0 < a) (b c : α) :
∃! m : ℤ, b + m • a ∈ Set.Ioc c (c + a) :=
(Equiv.addRight (1 : ℤ)).bijective.existsUnique_iff.2 <| by
simpa only [add_zsmul, sub_lt_iff_lt_add', le_sub_iff_add_le', ← add_assoc, and_comm, mem_Ioc,
Equiv.coe_addRight, one_zsmul, add_le_add_iff_right] using
existsUnique_zsmul_near_of_pos ha (c - b)
theorem existsUnique_sub_zsmul_mem_Ioc {a : α} (ha : 0 < a) (b c : α) :
∃! m : ℤ, b - m • a ∈ Set.Ioc c (c + a) :=
(Equiv.neg ℤ).bijective.existsUnique_iff.2 <| by
simpa only [Equiv.neg_apply, neg_zsmul, sub_neg_eq_add] using
existsUnique_add_zsmul_mem_Ioc ha b c
end LinearOrderedAddCommGroup
theorem exists_nat_ge [OrderedSemiring α] [Archimedean α] (x : α) : ∃ n : ℕ, x ≤ n := by
nontriviality α
exact (Archimedean.arch x one_pos).imp fun n h => by rwa [← nsmul_one]
instance (priority := 100) [OrderedSemiring α] [Archimedean α] : IsDirected α (· ≤ ·) :=
⟨fun x y ↦
let ⟨m, hm⟩ := exists_nat_ge x; let ⟨n, hn⟩ := exists_nat_ge y
let ⟨k, hmk, hnk⟩ := exists_ge_ge m n
⟨k, hm.trans <| Nat.mono_cast hmk, hn.trans <| Nat.mono_cast hnk⟩⟩
section StrictOrderedSemiring
variable [StrictOrderedSemiring α] [Archimedean α] {y : α}
lemma exists_nat_gt (x : α) : ∃ n : ℕ, x < n :=
(exists_lt_nsmul zero_lt_one x).imp fun n hn ↦ by rwa [← nsmul_one]
theorem add_one_pow_unbounded_of_pos (x : α) (hy : 0 < y) : ∃ n : ℕ, x < (y + 1) ^ n :=
have : 0 ≤ 1 + y := add_nonneg zero_le_one hy.le
(Archimedean.arch x hy).imp fun n h ↦
calc
x ≤ n • y := h
_ = n * y := nsmul_eq_mul _ _
_ < 1 + n * y := lt_one_add _
_ ≤ (1 + y) ^ n :=
one_add_mul_le_pow' (mul_nonneg hy.le hy.le) (mul_nonneg this this)
(add_nonneg zero_le_two hy.le) _
_ = (y + 1) ^ n := by rw [add_comm]
lemma pow_unbounded_of_one_lt [ExistsAddOfLE α] (x : α) (hy1 : 1 < y) : ∃ n : ℕ, x < y ^ n := by
obtain ⟨z, hz, rfl⟩ := exists_pos_add_of_lt' hy1
rw [add_comm]
exact add_one_pow_unbounded_of_pos _ hz
end StrictOrderedSemiring
section StrictOrderedRing
variable [StrictOrderedRing α] [Archimedean α]
theorem exists_int_gt (x : α) : ∃ n : ℤ, x < n :=
let ⟨n, h⟩ := exists_nat_gt x
⟨n, by rwa [Int.cast_natCast]⟩
theorem exists_int_lt (x : α) : ∃ n : ℤ, (n : α) < x :=
let ⟨n, h⟩ := exists_int_gt (-x)
⟨-n, by rw [Int.cast_neg]; exact neg_lt.1 h⟩
theorem exists_floor (x : α) : ∃ fl : ℤ, ∀ z : ℤ, z ≤ fl ↔ (z : α) ≤ x := by
haveI := Classical.propDecidable
have : ∃ ub : ℤ, (ub : α) ≤ x ∧ ∀ z : ℤ, (z : α) ≤ x → z ≤ ub :=
Int.exists_greatest_of_bdd
(let ⟨n, hn⟩ := exists_int_gt x
⟨n, fun z h' => Int.cast_le.1 <| le_trans h' <| le_of_lt hn⟩)
(let ⟨n, hn⟩ := exists_int_lt x
⟨n, le_of_lt hn⟩)
refine this.imp fun fl h z => ?_
cases' h with h₁ h₂
exact ⟨fun h => le_trans (Int.cast_le.2 h) h₁, h₂ z⟩
end StrictOrderedRing
section LinearOrderedSemiring
variable [LinearOrderedSemiring α] [Archimedean α] [ExistsAddOfLE α] {x y : α}
/-- Every x greater than or equal to 1 is between two successive
natural-number powers of every y greater than one. -/
theorem exists_nat_pow_near (hx : 1 ≤ x) (hy : 1 < y) : ∃ n : ℕ, y ^ n ≤ x ∧ x < y ^ (n + 1) := by
have h : ∃ n : ℕ, x < y ^ n := pow_unbounded_of_one_lt _ hy
classical exact
let n := Nat.find h
have hn : x < y ^ n := Nat.find_spec h
have hnp : 0 < n :=
pos_iff_ne_zero.2 fun hn0 => by rw [hn0, pow_zero] at hn; exact not_le_of_gt hn hx
have hnsp : Nat.pred n + 1 = n := Nat.succ_pred_eq_of_pos hnp
have hltn : Nat.pred n < n := Nat.pred_lt (ne_of_gt hnp)
⟨Nat.pred n, le_of_not_lt (Nat.find_min h hltn), by rwa [hnsp]⟩
end LinearOrderedSemiring
section LinearOrderedSemifield
variable [LinearOrderedSemifield α] [Archimedean α] {x y ε : α}
lemma exists_nat_one_div_lt (hε : 0 < ε) : ∃ n : ℕ, 1 / (n + 1 : α) < ε := by
cases' exists_nat_gt (1 / ε) with n hn
use n
rw [div_lt_iff, ← div_lt_iff' hε]
· apply hn.trans
simp [zero_lt_one]
· exact n.cast_add_one_pos
variable [ExistsAddOfLE α]
/-- Every positive `x` is between two successive integer powers of
another `y` greater than one. This is the same as `exists_mem_Ioc_zpow`,
but with ≤ and < the other way around. -/
theorem exists_mem_Ico_zpow (hx : 0 < x) (hy : 1 < y) : ∃ n : ℤ, x ∈ Ico (y ^ n) (y ^ (n + 1)) := by
classical exact
let ⟨N, hN⟩ := pow_unbounded_of_one_lt x⁻¹ hy
have he : ∃ m : ℤ, y ^ m ≤ x :=
⟨-N,
le_of_lt
(by
rw [zpow_neg y ↑N, zpow_natCast]
exact (inv_lt hx (lt_trans (inv_pos.2 hx) hN)).1 hN)⟩
let ⟨M, hM⟩ := pow_unbounded_of_one_lt x hy
have hb : ∃ b : ℤ, ∀ m, y ^ m ≤ x → m ≤ b :=
⟨M, fun m hm =>
le_of_not_lt fun hlt =>
not_lt_of_ge (zpow_le_of_le hy.le hlt.le)
(lt_of_le_of_lt hm (by rwa [← zpow_natCast] at hM))⟩
let ⟨n, hn₁, hn₂⟩ := Int.exists_greatest_of_bdd hb he
⟨n, hn₁, lt_of_not_ge fun hge => not_le_of_gt (Int.lt_succ _) (hn₂ _ hge)⟩
/-- Every positive `x` is between two successive integer powers of
another `y` greater than one. This is the same as `exists_mem_Ico_zpow`,
but with ≤ and < the other way around. -/
theorem exists_mem_Ioc_zpow (hx : 0 < x) (hy : 1 < y) : ∃ n : ℤ, x ∈ Ioc (y ^ n) (y ^ (n + 1)) :=
let ⟨m, hle, hlt⟩ := exists_mem_Ico_zpow (inv_pos.2 hx) hy
have hyp : 0 < y := lt_trans zero_lt_one hy
⟨-(m + 1), by rwa [zpow_neg, inv_lt (zpow_pos_of_pos hyp _) hx], by
rwa [neg_add, neg_add_cancel_right, zpow_neg, le_inv hx (zpow_pos_of_pos hyp _)]⟩
/-- For any `y < 1` and any positive `x`, there exists `n : ℕ` with `y ^ n < x`. -/
theorem exists_pow_lt_of_lt_one (hx : 0 < x) (hy : y < 1) : ∃ n : ℕ, y ^ n < x := by
by_cases y_pos : y ≤ 0
· use 1
simp only [pow_one]
exact y_pos.trans_lt hx
rw [not_le] at y_pos
rcases pow_unbounded_of_one_lt x⁻¹ (one_lt_inv y_pos hy) with ⟨q, hq⟩
exact ⟨q, by rwa [inv_pow, inv_lt_inv hx (pow_pos y_pos _)] at hq⟩
/-- Given `x` and `y` between `0` and `1`, `x` is between two successive powers of `y`.
This is the same as `exists_nat_pow_near`, but for elements between `0` and `1` -/
theorem exists_nat_pow_near_of_lt_one (xpos : 0 < x) (hx : x ≤ 1) (ypos : 0 < y) (hy : y < 1) :
∃ n : ℕ, y ^ (n + 1) < x ∧ x ≤ y ^ n := by
rcases exists_nat_pow_near (one_le_inv_iff.2 ⟨xpos, hx⟩) (one_lt_inv_iff.2 ⟨ypos, hy⟩) with
⟨n, hn, h'n⟩
refine ⟨n, ?_, ?_⟩
· rwa [inv_pow, inv_lt_inv xpos (pow_pos ypos _)] at h'n
· rwa [inv_pow, inv_le_inv (pow_pos ypos _) xpos] at hn
end LinearOrderedSemifield
section LinearOrderedField
variable [LinearOrderedField α] [Archimedean α] {x y ε : α}
theorem exists_rat_gt (x : α) : ∃ q : ℚ, x < q :=
let ⟨n, h⟩ := exists_nat_gt x
⟨n, by rwa [Rat.cast_natCast]⟩
theorem exists_rat_lt (x : α) : ∃ q : ℚ, (q : α) < x :=
let ⟨n, h⟩ := exists_int_lt x
⟨n, by rwa [Rat.cast_intCast]⟩
theorem exists_rat_btwn {x y : α} (h : x < y) : ∃ q : ℚ, x < q ∧ (q : α) < y := by
cases' exists_nat_gt (y - x)⁻¹ with n nh
cases' exists_floor (x * n) with z zh
refine ⟨(z + 1 : ℤ) / n, ?_⟩
have n0' := (inv_pos.2 (sub_pos.2 h)).trans nh
have n0 := Nat.cast_pos.1 n0'
rw [Rat.cast_div_of_ne_zero, Rat.cast_natCast, Rat.cast_intCast, div_lt_iff n0']
· refine ⟨(lt_div_iff n0').2 <| (lt_iff_lt_of_le_iff_le (zh _)).1 (lt_add_one _), ?_⟩
rw [Int.cast_add, Int.cast_one]
refine lt_of_le_of_lt (add_le_add_right ((zh _).1 le_rfl) _) ?_
rwa [← lt_sub_iff_add_lt', ← sub_mul, ← div_lt_iff' (sub_pos.2 h), one_div]
· rw [Rat.den_intCast, Nat.cast_one]
exact one_ne_zero
· intro H
rw [Rat.num_natCast, Int.cast_natCast, Nat.cast_eq_zero] at H
subst H
cases n0
theorem le_of_forall_rat_lt_imp_le (h : ∀ q : ℚ, (q : α) < x → (q : α) ≤ y) : x ≤ y :=
le_of_not_lt fun hyx =>
let ⟨_, hy, hx⟩ := exists_rat_btwn hyx
hy.not_le <| h _ hx
theorem le_of_forall_lt_rat_imp_le (h : ∀ q : ℚ, y < q → x ≤ q) : x ≤ y :=
le_of_not_lt fun hyx =>
let ⟨_, hy, hx⟩ := exists_rat_btwn hyx
hx.not_le <| h _ hy
theorem le_iff_forall_rat_lt_imp_le : x ≤ y ↔ ∀ q : ℚ, (q : α) < x → (q : α) ≤ y :=
⟨fun hxy _ hqx ↦ hqx.le.trans hxy, le_of_forall_rat_lt_imp_le⟩
theorem le_iff_forall_lt_rat_imp_le : x ≤ y ↔ ∀ q : ℚ, y < q → x ≤ q :=
⟨fun hxy _ hqx ↦ hxy.trans hqx.le, le_of_forall_lt_rat_imp_le⟩
theorem eq_of_forall_rat_lt_iff_lt (h : ∀ q : ℚ, (q : α) < x ↔ (q : α) < y) : x = y :=
(le_of_forall_rat_lt_imp_le fun q hq => ((h q).1 hq).le).antisymm <|
le_of_forall_rat_lt_imp_le fun q hq => ((h q).2 hq).le
theorem eq_of_forall_lt_rat_iff_lt (h : ∀ q : ℚ, x < q ↔ y < q) : x = y :=
(le_of_forall_lt_rat_imp_le fun q hq => ((h q).2 hq).le).antisymm <|
le_of_forall_lt_rat_imp_le fun q hq => ((h q).1 hq).le
theorem exists_pos_rat_lt {x : α} (x0 : 0 < x) : ∃ q : ℚ, 0 < q ∧ (q : α) < x := by
simpa only [Rat.cast_pos] using exists_rat_btwn x0
theorem exists_rat_near (x : α) (ε0 : 0 < ε) : ∃ q : ℚ, |x - q| < ε :=
let ⟨q, h₁, h₂⟩ :=
exists_rat_btwn <| ((sub_lt_self_iff x).2 ε0).trans ((lt_add_iff_pos_left x).2 ε0)
⟨q, abs_sub_lt_iff.2 ⟨sub_lt_comm.1 h₁, sub_lt_iff_lt_add.2 h₂⟩⟩
end LinearOrderedField
section LinearOrderedField
variable [LinearOrderedField α]
theorem archimedean_iff_nat_lt : Archimedean α ↔ ∀ x : α, ∃ n : ℕ, x < n :=
⟨@exists_nat_gt α _, fun H =>
⟨fun x y y0 =>
(H (x / y)).imp fun n h => le_of_lt <| by rwa [div_lt_iff y0, ← nsmul_eq_mul] at h⟩⟩
theorem archimedean_iff_nat_le : Archimedean α ↔ ∀ x : α, ∃ n : ℕ, x ≤ n :=
archimedean_iff_nat_lt.trans
⟨fun H x => (H x).imp fun _ => le_of_lt, fun H x =>
let ⟨n, h⟩ := H x
⟨n + 1, lt_of_le_of_lt h (Nat.cast_lt.2 (lt_add_one _))⟩⟩
theorem archimedean_iff_int_lt : Archimedean α ↔ ∀ x : α, ∃ n : ℤ, x < n :=
⟨@exists_int_gt α _, by
rw [archimedean_iff_nat_lt]
intro h x
obtain ⟨n, h⟩ := h x
refine ⟨n.toNat, h.trans_le ?_⟩
exact mod_cast Int.self_le_toNat _⟩
theorem archimedean_iff_int_le : Archimedean α ↔ ∀ x : α, ∃ n : ℤ, x ≤ n :=
archimedean_iff_int_lt.trans
⟨fun H x => (H x).imp fun _ => le_of_lt, fun H x =>
let ⟨n, h⟩ := H x
⟨n + 1, lt_of_le_of_lt h (Int.cast_lt.2 (lt_add_one _))⟩⟩
theorem archimedean_iff_rat_lt : Archimedean α ↔ ∀ x : α, ∃ q : ℚ, x < q where
mp := @exists_rat_gt α _
mpr H := archimedean_iff_nat_lt.2 fun x ↦
let ⟨q, h⟩ := H x; ⟨⌈q⌉₊, lt_of_lt_of_le h <| mod_cast Nat.le_ceil _⟩
theorem archimedean_iff_rat_le : Archimedean α ↔ ∀ x : α, ∃ q : ℚ, x ≤ q :=
archimedean_iff_rat_lt.trans
⟨fun H x => (H x).imp fun _ => le_of_lt, fun H x =>
let ⟨n, h⟩ := H x
⟨n + 1, lt_of_le_of_lt h (Rat.cast_lt.2 (lt_add_one _))⟩⟩
end LinearOrderedField
instance : Archimedean ℕ :=
⟨fun n m m0 => ⟨n, by
rw [← mul_one n, smul_eq_mul, mul_assoc, one_mul m]
exact Nat.mul_le_mul_left n (by omega)⟩⟩
instance : Archimedean ℤ :=
⟨fun n m m0 =>
⟨n.toNat,
le_trans (Int.self_le_toNat _) <| by
simpa only [nsmul_eq_mul, zero_add, mul_one] using
mul_le_mul_of_nonneg_left (Int.add_one_le_iff.2 m0) (Int.ofNat_zero_le n.toNat)⟩⟩
instance : Archimedean ℚ :=
archimedean_iff_rat_le.2 fun q => ⟨q, by rw [Rat.cast_id]⟩
instance Nonneg.archimedean [OrderedAddCommMonoid α] [Archimedean α] :
Archimedean { x : α // 0 ≤ x } :=
⟨fun x y hy =>
let ⟨n, hr⟩ := Archimedean.arch (x : α) (hy : (0 : α) < y)
⟨n, show (x : α) ≤ (n • y : { x : α // 0 ≤ x }) by simp [*, -nsmul_eq_mul, nsmul_coe]⟩⟩
instance : Archimedean NNRat := Nonneg.archimedean
/-- A linear ordered archimedean ring is a floor ring. This is not an `instance` because in some
cases we have a computable `floor` function. -/
noncomputable def Archimedean.floorRing (α) [LinearOrderedRing α] [Archimedean α] : FloorRing α :=
FloorRing.ofFloor α (fun a => Classical.choose (exists_floor a)) fun z a =>
(Classical.choose_spec (exists_floor a) z).symm
-- see Note [lower instance priority]
/-- A linear ordered field that is a floor ring is archimedean. -/
instance (priority := 100) FloorRing.archimedean (α) [LinearOrderedField α] [FloorRing α] :
Archimedean α := by
rw [archimedean_iff_int_le]
exact fun x => ⟨⌈x⌉, Int.le_ceil x⟩
|
Algebra\Order\Archimedean\Hom.lean | /-
Copyright (c) 2022 Alex J. Best, Yaël Dillies. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Alex J. Best, Yaël Dillies
-/
import Mathlib.Algebra.Order.Archimedean.Basic
import Mathlib.Algebra.Order.Hom.Ring
/-!
### Uniqueness of ring homomorphisms to archimedean fields.
There is at most one ordered ring homomorphism from a linear ordered field to an archimedean linear
ordered field. Reciprocally, such an ordered ring homomorphism exists when the codomain is further
conditionally complete.
-/
variable {α β : Type*}
/-- There is at most one ordered ring homomorphism from a linear ordered field to an archimedean
linear ordered field. -/
instance OrderRingHom.subsingleton [LinearOrderedField α] [LinearOrderedField β] [Archimedean β] :
Subsingleton (α →+*o β) :=
⟨fun f g => by
ext x
by_contra! h' : f x ≠ g x
wlog h : f x < g x generalizing α β with h₂
-- Porting note: had to add the `generalizing` as there are random variables
-- `F γ δ` flying around in context.
· exact h₂ g f x (Ne.symm h') (h'.lt_or_lt.resolve_left h)
obtain ⟨q, hf, hg⟩ := exists_rat_btwn h
rw [← map_ratCast f] at hf
rw [← map_ratCast g] at hg
exact
(lt_asymm ((OrderHomClass.mono g).reflect_lt hg) <|
(OrderHomClass.mono f).reflect_lt hf).elim⟩
/-- There is at most one ordered ring isomorphism between a linear ordered field and an archimedean
linear ordered field. -/
instance OrderRingIso.subsingleton_right [LinearOrderedField α] [LinearOrderedField β]
[Archimedean β] : Subsingleton (α ≃+*o β) :=
OrderRingIso.toOrderRingHom_injective.subsingleton
/-- There is at most one ordered ring isomorphism between an archimedean linear ordered field and a
linear ordered field. -/
instance OrderRingIso.subsingleton_left [LinearOrderedField α] [Archimedean α]
[LinearOrderedField β] : Subsingleton (α ≃+*o β) :=
OrderRingIso.symm_bijective.injective.subsingleton
|
Algebra\Order\BigOperators\Group\Finset.lean | /-
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.Algebra.BigOperators.Group.Finset
import Mathlib.Algebra.Order.BigOperators.Group.Multiset
import Mathlib.Tactic.Bound.Attribute
import Mathlib.Tactic.NormNum.Basic
import Mathlib.Tactic.Positivity.Core
/-!
# Big operators on a finset in ordered groups
This file contains the results concerning the interaction of multiset big operators with ordered
groups/monoids.
-/
open Function
variable {ι α β M N G k R : Type*}
namespace Finset
section OrderedCommMonoid
variable [CommMonoid M] [OrderedCommMonoid N]
/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map
submultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be
a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then
`f (∏ x ∈ s, g x) ≤ ∏ x ∈ s, f (g x)`. -/
@[to_additive le_sum_nonempty_of_subadditive_on_pred]
theorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)
(h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))
(g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :
f (∏ i ∈ s, g i) ≤ ∏ i ∈ s, f (g i) := by
refine le_trans
(Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ ?_ ?_) ?_
· simp [hs_nonempty.ne_empty]
· exact Multiset.forall_mem_map_iff.mpr hs
rw [Multiset.map_map]
rfl
/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let
`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let
`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then
`f (∑ i ∈ s, g i) ≤ ∑ i ∈ s, f (g i)`. -/
add_decl_doc le_sum_nonempty_of_subadditive_on_pred
/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a
nonempty finite family of elements of `M`, then `f (∏ i ∈ s, g i) ≤ ∏ i ∈ s, f (g i)`. -/
@[to_additive le_sum_nonempty_of_subadditive]
theorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)
{s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i ∈ s, g i) ≤ ∏ i ∈ s, f (g i) :=
le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)
(fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial
/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a
nonempty finite family of elements of `M`, then `f (∑ i ∈ s, g i) ≤ ∑ i ∈ s, f (g i)`. -/
add_decl_doc le_sum_nonempty_of_subadditive
/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map
such that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,
`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such
that `∀ i ∈ s, p (g i)`. Then `f (∏ i ∈ s, g i) ≤ ∏ i ∈ s, f (g i)`. -/
@[to_additive le_sum_of_subadditive_on_pred]
theorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)
(h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))
(g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i ∈ s, g i) ≤ ∏ i ∈ s, f (g i) := by
rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)
· simp [h_one]
· exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs
/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map
such that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.
Let `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then
`f (∑ x ∈ s, g x) ≤ ∑ x ∈ s, f (g x)`. -/
add_decl_doc le_sum_of_subadditive_on_pred
/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,
`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i ∈ s, g i) ≤ ∏ i ∈ s, f (g i)`. -/
@[to_additive le_sum_of_subadditive]
theorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)
(h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :
f (∏ i ∈ s, g i) ≤ ∏ i ∈ s, f (g i) := by
refine le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) ?_
rw [Multiset.map_map]
rfl
/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,
`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i ∈ s, g i) ≤ ∑ i ∈ s, f (g i)`. -/
add_decl_doc le_sum_of_subadditive
variable {f g : ι → N} {s t : Finset ι}
/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or
equal to the corresponding factor `g i` of another finite product, then
`∏ i ∈ s, f i ≤ ∏ i ∈ s, g i`. -/
@[to_additive (attr := gcongr) sum_le_sum]
theorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i ∈ s, f i ≤ ∏ i ∈ s, g i :=
Multiset.prod_map_le_prod_map f g h
attribute [bound] sum_le_sum
/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than
or equal to the corresponding summand `g i` of another finite sum, then
`∑ i ∈ s, f i ≤ ∑ i ∈ s, g i`. -/
add_decl_doc sum_le_sum
@[to_additive sum_nonneg]
theorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i ∈ s, f i :=
le_trans (by rw [prod_const_one]) (prod_le_prod' h)
@[to_additive Finset.sum_nonneg']
theorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i ∈ s, f i :=
Finset.one_le_prod' fun i _ ↦ h i
@[to_additive sum_nonpos]
theorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i ∈ s, f i ≤ 1 :=
(prod_le_prod' h).trans_eq (by rw [prod_const_one])
@[to_additive sum_le_sum_of_subset_of_nonneg]
theorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :
∏ i ∈ s, f i ≤ ∏ i ∈ t, f i := by
classical calc
∏ i ∈ s, f i ≤ (∏ i ∈ t \ s, f i) * ∏ i ∈ s, f i :=
le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]
_ = ∏ i ∈ t \ s ∪ s, f i := (prod_union sdiff_disjoint).symm
_ = ∏ i ∈ t, f i := by rw [sdiff_union_of_subset h]
@[to_additive sum_mono_set_of_nonneg]
theorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x ∈ s, f x :=
fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x
@[to_additive sum_le_univ_sum_of_nonneg]
theorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :
∏ x ∈ s, f x ≤ ∏ x, f x :=
prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a
-- Porting note (#11215): TODO -- The two next lemmas give the same lemma in additive version
@[to_additive sum_eq_zero_iff_of_nonneg]
theorem prod_eq_one_iff_of_one_le' :
(∀ i ∈ s, 1 ≤ f i) → ((∏ i ∈ s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by
classical
refine Finset.induction_on s
(fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_
intro a s ha ih H
have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem
rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),
forall_mem_insert, ih this]
@[to_additive sum_eq_zero_iff_of_nonpos]
theorem prod_eq_one_iff_of_le_one' :
(∀ i ∈ s, f i ≤ 1) → ((∏ i ∈ s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=
@prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _
@[to_additive single_le_sum]
theorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x ∈ s, f x :=
calc
f a = ∏ i ∈ {a}, f i := (prod_singleton _ _).symm
_ ≤ ∏ i ∈ s, f i :=
prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi
@[to_additive]
lemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :
f i * f j ≤ ∏ k ∈ s, f k :=
calc
f i * f j = ∏ k ∈ .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]
_ ≤ ∏ k ∈ s, f k := by
refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk
simp [cons_subset, *]
@[to_additive sum_le_card_nsmul]
theorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :
s.prod f ≤ n ^ s.card := by
refine (Multiset.prod_le_pow_card (s.val.map f) n ?_).trans ?_
· simpa using h
· simp
@[to_additive card_nsmul_le_sum]
theorem pow_card_le_prod (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, n ≤ f x) :
n ^ s.card ≤ s.prod f := @Finset.prod_le_pow_card _ Nᵒᵈ _ _ _ _ h
theorem card_biUnion_le_card_mul [DecidableEq β] (s : Finset ι) (f : ι → Finset β) (n : ℕ)
(h : ∀ a ∈ s, (f a).card ≤ n) : (s.biUnion f).card ≤ s.card * n :=
card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h
variable {ι' : Type*} [DecidableEq ι']
-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)
@[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg]
theorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ι'} {g : ι → ι'} {f : ι → N}
(h : ∀ y ∉ t, (1 : N) ≤ ∏ x ∈ s.filter fun x ↦ g x = y, f x) :
(∏ y ∈ t, ∏ x ∈ s.filter fun x ↦ g x = y, f x) ≤ ∏ x ∈ s, f x :=
calc
(∏ y ∈ t, ∏ x ∈ s.filter fun x ↦ g x = y, f x) ≤
∏ y ∈ t ∪ s.image g, ∏ x ∈ s.filter fun x ↦ g x = y, f x :=
prod_le_prod_of_subset_of_one_le' subset_union_left fun y _ ↦ h y
_ = ∏ x ∈ s, f x :=
prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _
-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)
@[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos]
theorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ι'} {g : ι → ι'} {f : ι → N}
(h : ∀ y ∉ t, ∏ x ∈ s.filter fun x ↦ g x = y, f x ≤ 1) :
∏ x ∈ s, f x ≤ ∏ y ∈ t, ∏ x ∈ s.filter fun x ↦ g x = y, f x :=
@prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nᵒᵈ _ _ _ _ _ _ _ h
end OrderedCommMonoid
theorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ι → G) (s : Finset ι) :
|∑ i ∈ s, f i| ≤ ∑ i ∈ s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f
theorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}
(hf : ∀ i ∈ s, 0 ≤ f i) : |∑ i ∈ s, f i| = ∑ i ∈ s, f i := by
rw [abs_of_nonneg (Finset.sum_nonneg hf)]
theorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}
(hf : ∀ i, 0 ≤ f i) : |∑ i ∈ s, f i| = ∑ i ∈ s, f i := by
rw [abs_of_nonneg (Finset.sum_nonneg' hf)]
section Pigeonhole
variable [DecidableEq β]
theorem card_le_mul_card_image_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}
(Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, (s.filter fun x ↦ f x = a).card ≤ n) :
s.card ≤ n * t.card :=
calc
s.card = ∑ a ∈ t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf
_ ≤ ∑ _a ∈ t, n := sum_le_sum hn
_ = _ := by simp [mul_comm]
theorem card_le_mul_card_image {f : α → β} (s : Finset α) (n : ℕ)
(hn : ∀ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≤ n) : s.card ≤ n * (s.image f).card :=
card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn
theorem mul_card_image_le_card_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}
(Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, n ≤ (s.filter fun x ↦ f x = a).card) :
n * t.card ≤ s.card :=
calc
n * t.card = ∑ _a ∈ t, n := by simp [mul_comm]
_ ≤ ∑ a ∈ t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn
_ = s.card := by rw [← card_eq_sum_card_fiberwise Hf]
theorem mul_card_image_le_card {f : α → β} (s : Finset α) (n : ℕ)
(hn : ∀ a ∈ s.image f, n ≤ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≤ s.card :=
mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn
end Pigeonhole
section DoubleCounting
variable [DecidableEq α] {s : Finset α} {B : Finset (Finset α)} {n : ℕ}
/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`
times how many they are. -/
theorem sum_card_inter_le (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card ≤ n) :
(∑ t ∈ B, (s ∩ t).card) ≤ s.card * n := by
refine le_trans ?_ (s.sum_le_card_nsmul _ _ h)
simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]
exact sum_comm.le
/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`
times how many they are. -/
theorem sum_card_le [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card ≤ n) :
∑ s ∈ B, s.card ≤ Fintype.card α * n :=
calc
∑ s ∈ B, s.card = ∑ s ∈ B, (univ ∩ s).card := by simp_rw [univ_inter]
_ ≤ Fintype.card α * n := sum_card_inter_le fun a _ ↦ h a
/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`
times how many they are. -/
theorem le_sum_card_inter (h : ∀ a ∈ s, n ≤ (B.filter (a ∈ ·)).card) :
s.card * n ≤ ∑ t ∈ B, (s ∩ t).card := by
apply (s.card_nsmul_le_sum _ _ h).trans
simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]
exact sum_comm.le
/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`
times how many they are. -/
theorem le_sum_card [Fintype α] (h : ∀ a, n ≤ (B.filter (a ∈ ·)).card) :
Fintype.card α * n ≤ ∑ s ∈ B, s.card :=
calc
Fintype.card α * n ≤ ∑ s ∈ B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a
_ = ∑ s ∈ B, s.card := by simp_rw [univ_inter]
/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how
many they are. -/
theorem sum_card_inter (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card = n) :
(∑ t ∈ B, (s ∩ t).card) = s.card * n :=
(sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge)
/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how
many they are. -/
theorem sum_card [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card = n) :
∑ s ∈ B, s.card = Fintype.card α * n := by
simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter]
theorem card_le_card_biUnion {s : Finset ι} {f : ι → Finset α} (hs : (s : Set ι).PairwiseDisjoint f)
(hf : ∀ i ∈ s, (f i).Nonempty) : s.card ≤ (s.biUnion f).card := by
rw [card_biUnion hs, card_eq_sum_ones]
exact sum_le_sum fun i hi ↦ (hf i hi).card_pos
theorem card_le_card_biUnion_add_card_fiber {s : Finset ι} {f : ι → Finset α}
(hs : (s : Set ι).PairwiseDisjoint f) :
s.card ≤ (s.biUnion f).card + (s.filter fun i ↦ f i = ∅).card := by
rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = ∅, add_comm]
exact
add_le_add_right
((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦
nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <|
card_le_card <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _)
_
theorem card_le_card_biUnion_add_one {s : Finset ι} {f : ι → Finset α} (hf : Injective f)
(hs : (s : Set ι).PairwiseDisjoint f) : s.card ≤ (s.biUnion f).card + 1 :=
(card_le_card_biUnion_add_card_fiber hs).trans <|
add_le_add_left
(card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _
end DoubleCounting
section CanonicallyOrderedCommMonoid
variable [CanonicallyOrderedCommMonoid M] {f : ι → M} {s t : Finset ι}
/-- In a canonically-ordered monoid, a product bounds each of its terms.
See also `Finset.single_le_prod'`. -/
@[to_additive "In a canonically-ordered additive monoid, a sum bounds each of its terms.
See also `Finset.single_le_sum`."]
lemma _root_.CanonicallyOrderedCommMonoid.single_le_prod {i : ι} (hi : i ∈ s) :
f i ≤ ∏ j ∈ s, f j :=
single_le_prod' (fun _ _ ↦ one_le _) hi
@[to_additive (attr := simp) sum_eq_zero_iff]
theorem prod_eq_one_iff' : ∏ x ∈ s, f x = 1 ↔ ∀ x ∈ s, f x = 1 :=
prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x)
@[to_additive sum_le_sum_of_subset]
theorem prod_le_prod_of_subset' (h : s ⊆ t) : ∏ x ∈ s, f x ≤ ∏ x ∈ t, f x :=
prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _
@[to_additive sum_mono_set]
theorem prod_mono_set' (f : ι → M) : Monotone fun s ↦ ∏ x ∈ s, f x := fun _ _ hs ↦
prod_le_prod_of_subset' hs
@[to_additive sum_le_sum_of_ne_zero]
theorem prod_le_prod_of_ne_one' (h : ∀ x ∈ s, f x ≠ 1 → x ∈ t) :
∏ x ∈ s, f x ≤ ∏ x ∈ t, f x := by
classical calc
∏ x ∈ s, f x = (∏ x ∈ s.filter fun x ↦ f x = 1, f x) *
∏ x ∈ s.filter fun x ↦ f x ≠ 1, f x := by
rw [← prod_union, filter_union_filter_neg_eq]
exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h
_ ≤ ∏ x ∈ t, f x :=
mul_le_of_le_one_of_le
(prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq)
(prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] )
end CanonicallyOrderedCommMonoid
section OrderedCancelCommMonoid
variable [OrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}
@[to_additive sum_lt_sum]
theorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :
∏ i ∈ s, f i < ∏ i ∈ s, g i :=
Multiset.prod_lt_prod' hle hlt
/-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is
strictly less than the corresponding factor `g i` of another nontrivial finite product, then
`s.prod f < s.prod g`. -/
@[to_additive (attr := gcongr) sum_lt_sum_of_nonempty]
theorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : ∀ i ∈ s, f i < g i) :
∏ i ∈ s, f i < ∏ i ∈ s, g i :=
Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt
/-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is
strictly less than the corresponding summand `g i` of another nontrivial finite sum, then
`s.sum f < s.sum g`. -/
add_decl_doc sum_lt_sum_of_nonempty
-- Porting note (#11215): TODO -- calc indentation
@[to_additive sum_lt_sum_of_subset]
theorem prod_lt_prod_of_subset' (h : s ⊆ t) {i : ι} (ht : i ∈ t) (hs : i ∉ s) (hlt : 1 < f i)
(hle : ∀ j ∈ t, j ∉ s → 1 ≤ f j) : ∏ j ∈ s, f j < ∏ j ∈ t, f j := by
classical calc
∏ j ∈ s, f j < ∏ j ∈ insert i s, f j := by
rw [prod_insert hs]
exact lt_mul_of_one_lt_left' (∏ j ∈ s, f j) hlt
_ ≤ ∏ j ∈ t, f j := by
apply prod_le_prod_of_subset_of_one_le'
· simp [Finset.insert_subset_iff, h, ht]
· intro x hx h'x
simp only [mem_insert, not_or] at h'x
exact hle x hx h'x.2
@[to_additive single_lt_sum]
theorem single_lt_prod' {i j : ι} (hij : j ≠ i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j)
(hle : ∀ k ∈ s, k ≠ i → 1 ≤ f k) : f i < ∏ k ∈ s, f k :=
calc
f i = ∏ k ∈ {i}, f k := by rw [prod_singleton]
_ < ∏ k ∈ s, f k :=
prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt
fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki)
@[to_additive sum_pos]
theorem one_lt_prod (h : ∀ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i ∈ s, f i :=
lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h
@[to_additive]
theorem prod_lt_one (h : ∀ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i ∈ s, f i < 1 :=
(prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one])
@[to_additive sum_pos']
theorem one_lt_prod' (h : ∀ i ∈ s, 1 ≤ f i) (hs : ∃ i ∈ s, 1 < f i) : 1 < ∏ i ∈ s, f i :=
prod_const_one.symm.trans_lt <| prod_lt_prod' h hs
@[to_additive]
theorem prod_lt_one' (h : ∀ i ∈ s, f i ≤ 1) (hs : ∃ i ∈ s, f i < 1) : ∏ i ∈ s, f i < 1 :=
prod_const_one.le.trans_lt' <| prod_lt_prod' h hs
@[to_additive]
theorem prod_eq_prod_iff_of_le {f g : ι → M} (h : ∀ i ∈ s, f i ≤ g i) :
((∏ i ∈ s, f i) = ∏ i ∈ s, g i) ↔ ∀ i ∈ s, f i = g i := by
classical
revert h
refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h),
fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_
specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem
rw [Finset.prod_insert ha, Finset.prod_insert ha, Finset.forall_mem_insert, ← ih]
exact
mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a))
(Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem)
variable [DecidableEq ι]
@[to_additive] lemma prod_sdiff_le_prod_sdiff :
∏ i ∈ s \ t, f i ≤ ∏ i ∈ t \ s, f i ↔ ∏ i ∈ s, f i ≤ ∏ i ∈ t, f i := by
rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,
← prod_union, inter_comm, sdiff_union_inter]
simpa only [inter_comm] using disjoint_sdiff_inter t s
@[to_additive] lemma prod_sdiff_lt_prod_sdiff :
∏ i ∈ s \ t, f i < ∏ i ∈ t \ s, f i ↔ ∏ i ∈ s, f i < ∏ i ∈ t, f i := by
rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,
← prod_union, inter_comm, sdiff_union_inter]
simpa only [inter_comm] using disjoint_sdiff_inter t s
end OrderedCancelCommMonoid
section LinearOrderedCancelCommMonoid
variable [LinearOrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}
@[to_additive exists_lt_of_sum_lt]
theorem exists_lt_of_prod_lt' (Hlt : ∏ i ∈ s, f i < ∏ i ∈ s, g i) : ∃ i ∈ s, f i < g i := by
contrapose! Hlt with Hle
exact prod_le_prod' Hle
@[to_additive exists_le_of_sum_le]
theorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i ∈ s, f i ≤ ∏ i ∈ s, g i) :
∃ i ∈ s, f i ≤ g i := by
contrapose! Hle with Hlt
exact prod_lt_prod_of_nonempty' hs Hlt
@[to_additive exists_pos_of_sum_zero_of_exists_nonzero]
theorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ι → M) (h₁ : ∏ i ∈ s, f i = 1)
(h₂ : ∃ i ∈ s, f i ≠ 1) : ∃ i ∈ s, 1 < f i := by
contrapose! h₁
obtain ⟨i, m, i_ne⟩ : ∃ i ∈ s, f i ≠ 1 := h₂
apply ne_of_lt
calc
∏ j ∈ s, f j < ∏ j ∈ s, 1 := prod_lt_prod' h₁ ⟨i, m, (h₁ i m).lt_of_ne i_ne⟩
_ = 1 := prod_const_one
end LinearOrderedCancelCommMonoid
end Finset
namespace Fintype
section OrderedCommMonoid
variable [Fintype ι] [OrderedCommMonoid M] {f : ι → M}
@[to_additive (attr := mono) sum_mono]
theorem prod_mono' : Monotone fun f : ι → M ↦ ∏ i, f i := fun _ _ hfg ↦
Finset.prod_le_prod' fun x _ ↦ hfg x
@[to_additive sum_nonneg]
lemma one_le_prod (hf : 1 ≤ f) : 1 ≤ ∏ i, f i := Finset.one_le_prod' fun _ _ ↦ hf _
@[to_additive] lemma prod_le_one (hf : f ≤ 1) : ∏ i, f i ≤ 1 := Finset.prod_le_one' fun _ _ ↦ hf _
@[to_additive]
lemma prod_eq_one_iff_of_one_le (hf : 1 ≤ f) : ∏ i, f i = 1 ↔ f = 1 :=
(Finset.prod_eq_one_iff_of_one_le' fun i _ ↦ hf i).trans <| by simp [Function.funext_iff]
@[to_additive]
lemma prod_eq_one_iff_of_le_one (hf : f ≤ 1) : ∏ i, f i = 1 ↔ f = 1 :=
(Finset.prod_eq_one_iff_of_le_one' fun i _ ↦ hf i).trans <| by simp [Function.funext_iff]
end OrderedCommMonoid
section OrderedCancelCommMonoid
variable [Fintype ι] [OrderedCancelCommMonoid M] {f : ι → M}
@[to_additive sum_strictMono]
theorem prod_strictMono' : StrictMono fun f : ι → M ↦ ∏ x, f x :=
fun _ _ hfg ↦
let ⟨hle, i, hlt⟩ := Pi.lt_def.mp hfg
Finset.prod_lt_prod' (fun i _ ↦ hle i) ⟨i, Finset.mem_univ i, hlt⟩
@[to_additive sum_pos]
lemma one_lt_prod (hf : 1 < f) : 1 < ∏ i, f i :=
Finset.one_lt_prod' (fun _ _ ↦ hf.le _) <| by simpa using (Pi.lt_def.1 hf).2
@[to_additive]
lemma prod_lt_one (hf : f < 1) : ∏ i, f i < 1 :=
Finset.prod_lt_one' (fun _ _ ↦ hf.le _) <| by simpa using (Pi.lt_def.1 hf).2
@[to_additive sum_pos_iff_of_nonneg]
lemma one_lt_prod_iff_of_one_le (hf : 1 ≤ f) : 1 < ∏ i, f i ↔ 1 < f := by
obtain rfl | hf := hf.eq_or_lt <;> simp [*, one_lt_prod]
@[to_additive]
lemma prod_lt_one_iff_of_le_one (hf : f ≤ 1) : ∏ i, f i < 1 ↔ f < 1 := by
obtain rfl | hf := hf.eq_or_lt <;> simp [*, prod_lt_one]
end OrderedCancelCommMonoid
end Fintype
namespace Multiset
theorem finset_sum_eq_sup_iff_disjoint [DecidableEq α] {β : Type*} {i : Finset β}
{f : β → Multiset α} :
i.sum f = i.sup f ↔
∀ᵉ (x ∈ i) (y ∈ i), x ≠ y → Multiset.Disjoint (f x) (f y) := by
induction' i using Finset.cons_induction_on with z i hz hr
· simp only [Finset.not_mem_empty, IsEmpty.forall_iff, imp_true_iff, Finset.sum_empty,
Finset.sup_empty, bot_eq_zero, eq_self_iff_true]
· simp_rw [Finset.sum_cons hz, Finset.sup_cons, Finset.mem_cons, Multiset.sup_eq_union,
forall_eq_or_imp, Ne, not_true_eq_false, IsEmpty.forall_iff, true_and_iff,
imp_and, forall_and, ← hr, @eq_comm _ z]
have := fun x (H : x ∈ i) => ne_of_mem_of_not_mem H hz
simp (config := { contextual := true }) only [this, not_false_iff, true_imp_iff]
simp_rw [← disjoint_finset_sum_left, ← disjoint_finset_sum_right, disjoint_comm, ← and_assoc,
and_self_iff]
exact add_eq_union_left_of_le (Finset.sup_le fun x hx => le_sum_of_mem (mem_map_of_mem f hx))
theorem sup_powerset_len {α : Type*} [DecidableEq α] (x : Multiset α) :
(Finset.sup (Finset.range (card x + 1)) fun k => x.powersetCard k) = x.powerset := by
convert bind_powerset_len x using 1
rw [Multiset.bind, Multiset.join, ← Finset.range_val, ← Finset.sum_eq_multiset_sum]
exact
Eq.symm (finset_sum_eq_sup_iff_disjoint.mpr fun _ _ _ _ h => pairwise_disjoint_powersetCard x h)
end Multiset
namespace Mathlib.Meta.Positivity
open Qq Lean Meta Finset
/-- The `positivity` extension which proves that `∑ i ∈ s, f i` is nonnegative if `f` is, and
positive if each `f i` is and `s` is nonempty.
TODO: The following example does not work
```
example (s : Finset ℕ) (f : ℕ → ℤ) (hf : ∀ n, 0 ≤ f n) : 0 ≤ s.sum f := by positivity
```
because `compareHyp` can't look for assumptions behind binders.
-/
@[positivity Finset.sum _ _]
def evalFinsetSum : PositivityExt where eval {u α} zα pα e := do
match e with
| ~q(@Finset.sum $ι _ $instα $s $f) =>
let i : Q($ι) ← mkFreshExprMVarQ q($ι) .syntheticOpaque
have body : Q($α) := .betaRev f #[i]
let rbody ← core zα pα body
let p_pos : Option Q(0 < $e) := ← (do
let .positive pbody := rbody | pure none -- Fail if the body is not provably positive
let .some ps ← proveFinsetNonempty s | pure none
let .some pα' ← trySynthInstanceQ q(OrderedCancelAddCommMonoid $α) | pure none
assertInstancesCommute
let pr : Q(∀ i, 0 < $f i) ← mkLambdaFVars #[i] pbody
return some q(@sum_pos $ι $α $pα' $f $s (fun i _ ↦ $pr i) $ps))
-- Try to show that the sum is positive
if let some p_pos := p_pos then
return .positive p_pos
-- Fall back to showing that the sum is nonnegative
else
let pbody ← rbody.toNonneg
let pr : Q(∀ i, 0 ≤ $f i) ← mkLambdaFVars #[i] pbody
let pα' ← synthInstanceQ q(OrderedAddCommMonoid $α)
assertInstancesCommute
return .nonnegative q(@sum_nonneg $ι $α $pα' $f $s fun i _ ↦ $pr i)
| _ => throwError "not Finset.sum"
end Mathlib.Meta.Positivity
|
Algebra\Order\BigOperators\Group\List.lean | /-
Copyright (c) 2021 Yakov Pechersky. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yakov Pechersky
-/
import Mathlib.Algebra.BigOperators.Group.List
import Mathlib.Algebra.Order.Monoid.Canonical.Defs
import Mathlib.Algebra.Order.Monoid.Unbundled.OrderDual
/-!
# Big operators on a list in ordered groups
This file contains the results concerning the interaction of list big operators with ordered
groups/monoids.
-/
variable {ι α M N P M₀ G R : Type*}
namespace List
section Monoid
variable [Monoid M]
@[to_additive sum_le_sum]
lemma Forall₂.prod_le_prod' [Preorder M] [CovariantClass M M (Function.swap (· * ·)) (· ≤ ·)]
[CovariantClass M M (· * ·) (· ≤ ·)] {l₁ l₂ : List M} (h : Forall₂ (· ≤ ·) l₁ l₂) :
l₁.prod ≤ l₂.prod := by
induction' h with a b la lb hab ih ih'
· rfl
· simpa only [prod_cons] using mul_le_mul' hab ih'
/-- If `l₁` is a sublist of `l₂` and all elements of `l₂` are greater than or equal to one, then
`l₁.prod ≤ l₂.prod`. One can prove a stronger version assuming `∀ a ∈ l₂.diff l₁, 1 ≤ a` instead
of `∀ a ∈ l₂, 1 ≤ a` but this lemma is not yet in `mathlib`. -/
@[to_additive sum_le_sum "If `l₁` is a sublist of `l₂` and all elements of `l₂` are nonnegative,
then `l₁.sum ≤ l₂.sum`.
One can prove a stronger version assuming `∀ a ∈ l₂.diff l₁, 0 ≤ a` instead of `∀ a ∈ l₂, 0 ≤ a`
but this lemma is not yet in `mathlib`."]
lemma Sublist.prod_le_prod' [Preorder M] [CovariantClass M M (Function.swap (· * ·)) (· ≤ ·)]
[CovariantClass M M (· * ·) (· ≤ ·)] {l₁ l₂ : List M} (h : l₁ <+ l₂)
(h₁ : ∀ a ∈ l₂, (1 : M) ≤ a) : l₁.prod ≤ l₂.prod := by
induction h with
| slnil => rfl
| cons a _ ih' =>
simp only [prod_cons, forall_mem_cons] at h₁ ⊢
exact (ih' h₁.2).trans (le_mul_of_one_le_left' h₁.1)
| cons₂ a _ ih' =>
simp only [prod_cons, forall_mem_cons] at h₁ ⊢
exact mul_le_mul_left' (ih' h₁.2) _
@[to_additive sum_le_sum]
lemma SublistForall₂.prod_le_prod' [Preorder M]
[CovariantClass M M (Function.swap (· * ·)) (· ≤ ·)] [CovariantClass M M (· * ·) (· ≤ ·)]
{l₁ l₂ : List M} (h : SublistForall₂ (· ≤ ·) l₁ l₂) (h₁ : ∀ a ∈ l₂, (1 : M) ≤ a) :
l₁.prod ≤ l₂.prod :=
let ⟨_, hall, hsub⟩ := sublistForall₂_iff.1 h
hall.prod_le_prod'.trans <| hsub.prod_le_prod' h₁
@[to_additive sum_le_sum]
lemma prod_le_prod' [Preorder M] [CovariantClass M M (Function.swap (· * ·)) (· ≤ ·)]
[CovariantClass M M (· * ·) (· ≤ ·)] {l : List ι} {f g : ι → M} (h : ∀ i ∈ l, f i ≤ g i) :
(l.map f).prod ≤ (l.map g).prod :=
Forall₂.prod_le_prod' <| by simpa
@[to_additive sum_lt_sum]
lemma prod_lt_prod' [Preorder M] [CovariantClass M M (· * ·) (· < ·)]
[CovariantClass M M (· * ·) (· ≤ ·)] [CovariantClass M M (Function.swap (· * ·)) (· < ·)]
[CovariantClass M M (Function.swap (· * ·)) (· ≤ ·)] {l : List ι} (f g : ι → M)
(h₁ : ∀ i ∈ l, f i ≤ g i) (h₂ : ∃ i ∈ l, f i < g i) : (l.map f).prod < (l.map g).prod := by
induction' l with i l ihl
· rcases h₂ with ⟨_, ⟨⟩, _⟩
simp only [forall_mem_cons, map_cons, prod_cons] at h₁ ⊢
simp only [mem_cons, exists_eq_or_imp] at h₂
cases h₂
· exact mul_lt_mul_of_lt_of_le ‹_› (prod_le_prod' h₁.2)
· exact mul_lt_mul_of_le_of_lt h₁.1 <| ihl h₁.2 ‹_›
@[to_additive]
lemma prod_lt_prod_of_ne_nil [Preorder M] [CovariantClass M M (· * ·) (· < ·)]
[CovariantClass M M (· * ·) (· ≤ ·)] [CovariantClass M M (Function.swap (· * ·)) (· < ·)]
[CovariantClass M M (Function.swap (· * ·)) (· ≤ ·)] {l : List ι} (hl : l ≠ []) (f g : ι → M)
(hlt : ∀ i ∈ l, f i < g i) : (l.map f).prod < (l.map g).prod :=
(prod_lt_prod' f g fun i hi => (hlt i hi).le) <|
(exists_mem_of_ne_nil l hl).imp fun i hi => ⟨hi, hlt i hi⟩
@[to_additive sum_le_card_nsmul]
lemma prod_le_pow_card [Preorder M] [CovariantClass M M (Function.swap (· * ·)) (· ≤ ·)]
[CovariantClass M M (· * ·) (· ≤ ·)] (l : List M) (n : M) (h : ∀ x ∈ l, x ≤ n) :
l.prod ≤ n ^ l.length := by
simpa only [map_id', map_const', prod_replicate] using prod_le_prod' h
@[to_additive card_nsmul_le_sum]
lemma pow_card_le_prod [Preorder M] [CovariantClass M M (Function.swap (· * ·)) (· ≤ ·)]
[CovariantClass M M (· * ·) (· ≤ ·)] (l : List M) (n : M) (h : ∀ x ∈ l, n ≤ x) :
n ^ l.length ≤ l.prod :=
@prod_le_pow_card Mᵒᵈ _ _ _ _ l n h
@[to_additive exists_lt_of_sum_lt]
lemma exists_lt_of_prod_lt' [LinearOrder M] [CovariantClass M M (Function.swap (· * ·)) (· ≤ ·)]
[CovariantClass M M (· * ·) (· ≤ ·)] {l : List ι} (f g : ι → M)
(h : (l.map f).prod < (l.map g).prod) : ∃ i ∈ l, f i < g i := by
contrapose! h
exact prod_le_prod' h
@[to_additive exists_le_of_sum_le]
lemma exists_le_of_prod_le' [LinearOrder M] [CovariantClass M M (· * ·) (· < ·)]
[CovariantClass M M (· * ·) (· ≤ ·)] [CovariantClass M M (Function.swap (· * ·)) (· < ·)]
[CovariantClass M M (Function.swap (· * ·)) (· ≤ ·)] {l : List ι} (hl : l ≠ []) (f g : ι → M)
(h : (l.map f).prod ≤ (l.map g).prod) : ∃ x ∈ l, f x ≤ g x := by
contrapose! h
exact prod_lt_prod_of_ne_nil hl _ _ h
@[to_additive sum_nonneg]
lemma one_le_prod_of_one_le [Preorder M] [CovariantClass M M (· * ·) (· ≤ ·)] {l : List M}
(hl₁ : ∀ x ∈ l, (1 : M) ≤ x) : 1 ≤ l.prod := by
-- We don't use `pow_card_le_prod` to avoid assumption
-- [covariant_class M M (function.swap (*)) (≤)]
induction' l with hd tl ih
· rfl
rw [prod_cons]
exact one_le_mul (hl₁ hd (mem_cons_self hd tl)) (ih fun x h => hl₁ x (mem_cons_of_mem hd h))
end Monoid
-- TODO: develop theory of tropical rings
lemma sum_le_foldr_max [AddMonoid M] [AddMonoid N] [LinearOrder N] (f : M → N) (h0 : f 0 ≤ 0)
(hadd : ∀ x y, f (x + y) ≤ max (f x) (f y)) (l : List M) : f l.sum ≤ (l.map f).foldr max 0 := by
induction' l with hd tl IH
· simpa using h0
simp only [List.sum_cons, List.foldr_map, List.foldr] at IH ⊢
exact (hadd _ _).trans (max_le_max le_rfl IH)
@[to_additive sum_pos]
lemma one_lt_prod_of_one_lt [OrderedCommMonoid M] :
∀ l : List M, (∀ x ∈ l, (1 : M) < x) → l ≠ [] → 1 < l.prod
| [], _, h => (h rfl).elim
| [b], h, _ => by simpa using h
| a :: b :: l, hl₁, _ => by
simp only [forall_eq_or_imp, List.mem_cons] at hl₁
rw [List.prod_cons]
apply one_lt_mul_of_lt_of_le' hl₁.1
apply le_of_lt ((b :: l).one_lt_prod_of_one_lt _ (l.cons_ne_nil b))
intro x hx; cases hx
· exact hl₁.2.1
· exact hl₁.2.2 _ ‹_›
@[to_additive]
lemma single_le_prod [OrderedCommMonoid M] {l : List M} (hl₁ : ∀ x ∈ l, (1 : M) ≤ x) :
∀ x ∈ l, x ≤ l.prod := by
induction l
· simp
simp_rw [prod_cons, forall_mem_cons] at hl₁ ⊢
constructor
case cons.left => exact le_mul_of_one_le_right' (one_le_prod_of_one_le hl₁.2)
case cons.right hd tl ih => exact fun x H => le_mul_of_one_le_of_le hl₁.1 (ih hl₁.right x H)
@[to_additive all_zero_of_le_zero_le_of_sum_eq_zero]
lemma all_one_of_le_one_le_of_prod_eq_one [OrderedCommMonoid M] {l : List M}
(hl₁ : ∀ x ∈ l, (1 : M) ≤ x) (hl₂ : l.prod = 1) {x : M} (hx : x ∈ l) : x = 1 :=
_root_.le_antisymm (hl₂ ▸ single_le_prod hl₁ _ hx) (hl₁ x hx)
section CanonicallyOrderedCommMonoid
variable [CanonicallyOrderedCommMonoid M] {l : List M}
@[to_additive] lemma prod_eq_one_iff : l.prod = 1 ↔ ∀ x ∈ l, x = (1 : M) :=
⟨all_one_of_le_one_le_of_prod_eq_one fun _ _ => one_le _, fun h => by
rw [List.eq_replicate.2 ⟨_, h⟩, prod_replicate, one_pow]
· exact (length l)
· rfl⟩
@[to_additive] lemma monotone_prod_take (L : List M) : Monotone fun i => (L.take i).prod := by
refine monotone_nat_of_le_succ fun n => ?_
cases' lt_or_le n L.length with h h
· rw [prod_take_succ _ _ h]
exact le_self_mul
· simp [take_of_length_le h, take_of_length_le (le_trans h (Nat.le_succ _))]
end CanonicallyOrderedCommMonoid
end List
|
Algebra\Order\BigOperators\Group\Multiset.lean | /-
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
-/
import Mathlib.Algebra.BigOperators.Group.Multiset
import Mathlib.Algebra.Order.BigOperators.Group.List
import Mathlib.Algebra.Order.Group.Abs
import Mathlib.Data.List.MinMax
import Mathlib.Data.Multiset.Fold
import Mathlib.Algebra.Order.Monoid.OrderDual
/-!
# Big operators on a multiset in ordered groups
This file contains the results concerning the interaction of multiset big operators with ordered
groups.
-/
assert_not_exists MonoidWithZero
variable {ι α β : Type*}
namespace Multiset
section OrderedCommMonoid
variable [OrderedCommMonoid α] {s t : Multiset α} {a : α}
@[to_additive sum_nonneg]
lemma one_le_prod_of_one_le : (∀ x ∈ s, (1 : α) ≤ x) → 1 ≤ s.prod :=
Quotient.inductionOn s fun l hl => by simpa using List.one_le_prod_of_one_le hl
@[to_additive]
lemma single_le_prod : (∀ x ∈ s, (1 : α) ≤ x) → ∀ x ∈ s, x ≤ s.prod :=
Quotient.inductionOn s fun l hl x hx => by simpa using List.single_le_prod hl x hx
@[to_additive sum_le_card_nsmul]
lemma prod_le_pow_card (s : Multiset α) (n : α) (h : ∀ x ∈ s, x ≤ n) : s.prod ≤ n ^ card s := by
induction s using Quotient.inductionOn
simpa using List.prod_le_pow_card _ _ h
@[to_additive all_zero_of_le_zero_le_of_sum_eq_zero]
lemma all_one_of_le_one_le_of_prod_eq_one :
(∀ x ∈ s, (1 : α) ≤ x) → s.prod = 1 → ∀ x ∈ s, x = (1 : α) :=
Quotient.inductionOn s (by
simp only [quot_mk_to_coe, prod_coe, mem_coe]
exact fun l => List.all_one_of_le_one_le_of_prod_eq_one)
@[to_additive]
lemma prod_le_prod_of_rel_le (h : s.Rel (· ≤ ·) t) : s.prod ≤ t.prod := by
induction' h with _ _ _ _ rh _ rt
· rfl
· rw [prod_cons, prod_cons]
exact mul_le_mul' rh rt
@[to_additive]
lemma prod_map_le_prod_map {s : Multiset ι} (f : ι → α) (g : ι → α) (h : ∀ i, i ∈ s → f i ≤ g i) :
(s.map f).prod ≤ (s.map g).prod :=
prod_le_prod_of_rel_le <| rel_map.2 <| rel_refl_of_refl_on h
@[to_additive]
lemma prod_map_le_prod (f : α → α) (h : ∀ x, x ∈ s → f x ≤ x) : (s.map f).prod ≤ s.prod :=
prod_le_prod_of_rel_le <| rel_map_left.2 <| rel_refl_of_refl_on h
@[to_additive]
lemma prod_le_prod_map (f : α → α) (h : ∀ x, x ∈ s → x ≤ f x) : s.prod ≤ (s.map f).prod :=
@prod_map_le_prod αᵒᵈ _ _ f h
@[to_additive card_nsmul_le_sum]
lemma pow_card_le_prod (h : ∀ x ∈ s, a ≤ x) : a ^ card s ≤ s.prod := by
rw [← Multiset.prod_replicate, ← Multiset.map_const]
exact prod_map_le_prod _ h
end OrderedCommMonoid
section
variable [CommMonoid α] [OrderedCommMonoid β]
@[to_additive le_sum_of_subadditive_on_pred]
lemma le_prod_of_submultiplicative_on_pred (f : α → β)
(p : α → Prop) (h_one : f 1 = 1) (hp_one : p 1)
(h_mul : ∀ a b, p a → p b → f (a * b) ≤ f a * f b) (hp_mul : ∀ a b, p a → p b → p (a * b))
(s : Multiset α) (hps : ∀ a, a ∈ s → p a) : f s.prod ≤ (s.map f).prod := by
revert s
refine Multiset.induction ?_ ?_
· simp [le_of_eq h_one]
intro a s hs hpsa
have hps : ∀ x, x ∈ s → p x := fun x hx => hpsa x (mem_cons_of_mem hx)
have hp_prod : p s.prod := prod_induction p s hp_mul hp_one hps
rw [prod_cons, map_cons, prod_cons]
exact (h_mul a s.prod (hpsa a (mem_cons_self a s)) hp_prod).trans (mul_le_mul_left' (hs hps) _)
@[to_additive le_sum_of_subadditive]
lemma le_prod_of_submultiplicative (f : α → β) (h_one : f 1 = 1)
(h_mul : ∀ a b, f (a * b) ≤ f a * f b) (s : Multiset α) : f s.prod ≤ (s.map f).prod :=
le_prod_of_submultiplicative_on_pred f (fun _ => True) h_one trivial (fun x y _ _ => h_mul x y)
(by simp) s (by simp)
@[to_additive le_sum_nonempty_of_subadditive_on_pred]
lemma le_prod_nonempty_of_submultiplicative_on_pred (f : α → β) (p : α → Prop)
(h_mul : ∀ a b, p a → p b → f (a * b) ≤ f a * f b) (hp_mul : ∀ a b, p a → p b → p (a * b))
(s : Multiset α) (hs_nonempty : s ≠ ∅) (hs : ∀ a, a ∈ s → p a) : f s.prod ≤ (s.map f).prod := by
revert s
refine Multiset.induction ?_ ?_
· simp
rintro a s hs - hsa_prop
rw [prod_cons, map_cons, prod_cons]
by_cases hs_empty : s = ∅
· simp [hs_empty]
have hsa_restrict : ∀ x, x ∈ s → p x := fun x hx => hsa_prop x (mem_cons_of_mem hx)
have hp_sup : p s.prod := prod_induction_nonempty p hp_mul hs_empty hsa_restrict
have hp_a : p a := hsa_prop a (mem_cons_self a s)
exact (h_mul a _ hp_a hp_sup).trans (mul_le_mul_left' (hs hs_empty hsa_restrict) _)
@[to_additive le_sum_nonempty_of_subadditive]
lemma le_prod_nonempty_of_submultiplicative (f : α → β) (h_mul : ∀ a b, f (a * b) ≤ f a * f b)
(s : Multiset α) (hs_nonempty : s ≠ ∅) : f s.prod ≤ (s.map f).prod :=
le_prod_nonempty_of_submultiplicative_on_pred f (fun _ => True) (by simp [h_mul]) (by simp) s
hs_nonempty (by simp)
end
section OrderedCancelCommMonoid
variable [OrderedCancelCommMonoid α] {s : Multiset ι} {f g : ι → α}
@[to_additive sum_lt_sum]
lemma prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :
(s.map f).prod < (s.map g).prod := by
obtain ⟨l⟩ := s
simp only [Multiset.quot_mk_to_coe'', Multiset.map_coe, Multiset.prod_coe]
exact List.prod_lt_prod' f g hle hlt
@[to_additive sum_lt_sum_of_nonempty]
lemma prod_lt_prod_of_nonempty' (hs : s ≠ ∅) (hfg : ∀ i ∈ s, f i < g i) :
(s.map f).prod < (s.map g).prod := by
obtain ⟨i, hi⟩ := exists_mem_of_ne_zero hs
exact prod_lt_prod' (fun i hi => le_of_lt (hfg i hi)) ⟨i, hi, hfg i hi⟩
end OrderedCancelCommMonoid
section CanonicallyOrderedCommMonoid
variable [CanonicallyOrderedCommMonoid α] {m : Multiset α} {a : α}
@[to_additive] lemma prod_eq_one_iff : m.prod = 1 ↔ ∀ x ∈ m, x = (1 : α) :=
Quotient.inductionOn m fun l ↦ by simpa using List.prod_eq_one_iff
@[to_additive] lemma le_prod_of_mem (ha : a ∈ m) : a ≤ m.prod := by
obtain ⟨t, rfl⟩ := exists_cons_of_mem ha
rw [prod_cons]
exact _root_.le_mul_right (le_refl a)
end CanonicallyOrderedCommMonoid
lemma max_le_of_forall_le {α : Type*} [LinearOrder α] [OrderBot α] (l : Multiset α)
(n : α) (h : ∀ x ∈ l, x ≤ n) : l.fold max ⊥ ≤ n := by
induction l using Quotient.inductionOn
simpa using List.max_le_of_forall_le _ _ h
lemma abs_sum_le_sum_abs [LinearOrderedAddCommGroup α] {s : Multiset α} :
|s.sum| ≤ (s.map abs).sum :=
le_sum_of_subadditive _ abs_zero abs_add s
end Multiset
|
Algebra\Order\BigOperators\Ring\Finset.lean | /-
Copyright (c) 2019 Floris van Doorn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Floris van Doorn
-/
import Mathlib.Algebra.BigOperators.Ring
import Mathlib.Algebra.Order.AbsoluteValue
import Mathlib.Algebra.Order.BigOperators.Group.Finset
import Mathlib.Algebra.Order.BigOperators.Ring.Multiset
import Mathlib.Tactic.Ring
/-!
# Big operators on a finset in ordered rings
This file contains the results concerning the interaction of finset big operators with ordered
rings.
-/
variable {ι R : Type*}
namespace Finset
section CommMonoidWithZero
variable [CommMonoidWithZero R] [PartialOrder R] [ZeroLEOneClass R]
section PosMulMono
variable [PosMulMono R] {f g : ι → R} {s t : Finset ι}
lemma prod_nonneg (h0 : ∀ i ∈ s, 0 ≤ f i) : 0 ≤ ∏ i ∈ s, f i :=
prod_induction f (fun i ↦ 0 ≤ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0
/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the
product of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for
the case of an ordered commutative multiplicative monoid. -/
@[gcongr]
lemma prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :
∏ i ∈ s, f i ≤ ∏ i ∈ s, g i := by
induction' s using Finset.cons_induction with a s has ih h
· simp
· simp only [prod_cons]
have := posMulMono_iff_mulPosMono.1 ‹PosMulMono R›
apply mul_le_mul
· exact h1 a (mem_cons_self a s)
· refine ih (fun x H ↦ h0 _ ?_) (fun x H ↦ h1 _ ?_) <;> exact subset_cons _ H
· apply prod_nonneg fun x H ↦ h0 x (subset_cons _ H)
· apply le_trans (h0 a (mem_cons_self a s)) (h1 a (mem_cons_self a s))
/-- If each `f i`, `i ∈ s` belongs to `[0, 1]`, then their product is less than or equal to one.
See also `Finset.prod_le_one'` for the case of an ordered commutative multiplicative monoid. -/
lemma prod_le_one (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ 1) : ∏ i ∈ s, f i ≤ 1 := by
convert ← prod_le_prod h0 h1
exact Finset.prod_const_one
end PosMulMono
section PosMulStrictMono
variable [PosMulStrictMono R] [Nontrivial R] {f g : ι → R} {s t : Finset ι}
lemma prod_pos (h0 : ∀ i ∈ s, 0 < f i) : 0 < ∏ i ∈ s, f i :=
prod_induction f (fun x ↦ 0 < x) (fun _ _ ha hb ↦ mul_pos ha hb) zero_lt_one h0
lemma prod_lt_prod (hf : ∀ i ∈ s, 0 < f i) (hfg : ∀ i ∈ s, f i ≤ g i)
(hlt : ∃ i ∈ s, f i < g i) :
∏ i ∈ s, f i < ∏ i ∈ s, g i := by
classical
obtain ⟨i, hi, hilt⟩ := hlt
rw [← insert_erase hi, prod_insert (not_mem_erase _ _), prod_insert (not_mem_erase _ _)]
have := posMulStrictMono_iff_mulPosStrictMono.1 ‹PosMulStrictMono R›
refine mul_lt_mul_of_pos_of_nonneg' hilt ?_ ?_ ?_
· exact prod_le_prod (fun j hj => le_of_lt (hf j (mem_of_mem_erase hj)))
(fun _ hj ↦ hfg _ <| mem_of_mem_erase hj)
· exact prod_pos fun j hj => hf j (mem_of_mem_erase hj)
· exact (hf i hi).le.trans hilt.le
lemma prod_lt_prod_of_nonempty (hf : ∀ i ∈ s, 0 < f i) (hfg : ∀ i ∈ s, f i < g i)
(h_ne : s.Nonempty) :
∏ i ∈ s, f i < ∏ i ∈ s, g i := by
apply prod_lt_prod hf fun i hi => le_of_lt (hfg i hi)
obtain ⟨i, hi⟩ := h_ne
exact ⟨i, hi, hfg i hi⟩
end PosMulStrictMono
end CommMonoidWithZero
section OrderedCommSemiring
variable [OrderedCommSemiring R] {f g : ι → R} {s t : Finset ι}
/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the
sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/
lemma prod_add_prod_le {i : ι} {f g h : ι → R} (hi : i ∈ s) (h2i : g i + h i ≤ f i)
(hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j) (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) (hg : ∀ i ∈ s, 0 ≤ g i)
(hh : ∀ i ∈ s, 0 ≤ h i) : ((∏ i ∈ s, g i) + ∏ i ∈ s, h i) ≤ ∏ i ∈ s, f i := by
classical
simp_rw [prod_eq_mul_prod_diff_singleton hi]
refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_)
· rw [right_distrib]
refine add_le_add ?_ ?_ <;>
· refine mul_le_mul_of_nonneg_left ?_ ?_
· refine prod_le_prod ?_ ?_ <;> simp (config := { contextual := true }) [*]
· try apply_assumption
try assumption
· apply prod_nonneg
simp only [and_imp, mem_sdiff, mem_singleton]
exact fun j hj hji ↦ le_trans (hg j hj) (hgf j hj hji)
end OrderedCommSemiring
section LinearOrderedCommSemiring
variable [LinearOrderedCommSemiring R] [ExistsAddOfLE R]
/-- **Cauchy-Schwarz inequality** for finsets. -/
lemma sum_mul_sq_le_sq_mul_sq (s : Finset ι) (f g : ι → R) :
(∑ i ∈ s, f i * g i) ^ 2 ≤ (∑ i ∈ s, f i ^ 2) * ∑ i ∈ s, g i ^ 2 := by
nontriviality R
obtain h' | h' := (sum_nonneg fun _ _ ↦ sq_nonneg <| g _).eq_or_lt
· have h'' : ∀ i ∈ s, g i = 0 := fun i hi ↦ by
simpa using (sum_eq_zero_iff_of_nonneg fun i _ ↦ sq_nonneg (g i)).1 h'.symm i hi
rw [← h', sum_congr rfl (show ∀ i ∈ s, f i * g i = 0 from fun i hi ↦ by simp [h'' i hi])]
simp
refine le_of_mul_le_mul_of_pos_left
(le_of_add_le_add_left (a := (∑ i ∈ s, g i ^ 2) * (∑ j ∈ s, f j * g j) ^ 2) ?_) h'
calc
_ = ∑ i ∈ s, 2 * (f i * ∑ j ∈ s, g j ^ 2) * (g i * ∑ j ∈ s, f j * g j) := by
simp_rw [mul_assoc (2 : R), mul_mul_mul_comm, ← mul_sum, ← sum_mul]; ring
_ ≤ ∑ i ∈ s, ((f i * ∑ j ∈ s, g j ^ 2) ^ 2 + (g i * ∑ j ∈ s, f j * g j) ^ 2) :=
sum_le_sum fun i _ ↦ two_mul_le_add_sq (f i * ∑ j ∈ s, g j ^ 2) (g i * ∑ j ∈ s, f j * g j)
_ = _ := by simp_rw [sum_add_distrib, mul_pow, ← sum_mul]; ring
end LinearOrderedCommSemiring
lemma abs_prod [LinearOrderedCommRing R] (s : Finset ι) (f : ι → R) :
|∏ x ∈ s, f x| = ∏ x ∈ s, |f x| :=
map_prod absHom _ _
section CanonicallyOrderedCommSemiring
variable [CanonicallyOrderedCommSemiring R] {f g h : ι → R} {s : Finset ι} {i : ι}
/-- Note that the name is to match `CanonicallyOrderedCommSemiring.mul_pos`. -/
@[simp] lemma _root_.CanonicallyOrderedCommSemiring.prod_pos [Nontrivial R] :
0 < ∏ i ∈ s, f i ↔ (∀ i ∈ s, (0 : R) < f i) :=
CanonicallyOrderedCommSemiring.multiset_prod_pos.trans Multiset.forall_mem_map_iff
/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the
sum of the products of `g` and `h`. This is the version for `CanonicallyOrderedCommSemiring`.
-/
lemma prod_add_prod_le' (hi : i ∈ s) (h2i : g i + h i ≤ f i) (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j)
(hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) : ((∏ i ∈ s, g i) + ∏ i ∈ s, h i) ≤ ∏ i ∈ s, f i := by
classical
simp_rw [prod_eq_mul_prod_diff_singleton hi]
refine le_trans ?_ (mul_le_mul_right' h2i _)
rw [right_distrib]
apply add_le_add <;> apply mul_le_mul_left' <;> apply prod_le_prod' <;>
simp only [and_imp, mem_sdiff, mem_singleton] <;>
intros <;>
apply_assumption <;>
assumption
end CanonicallyOrderedCommSemiring
end Finset
section AbsoluteValue
variable {S : Type*}
lemma AbsoluteValue.sum_le [Semiring R] [OrderedSemiring S] (abv : AbsoluteValue R S)
(s : Finset ι) (f : ι → R) : abv (∑ i ∈ s, f i) ≤ ∑ i ∈ s, abv (f i) :=
Finset.le_sum_of_subadditive abv (map_zero _) abv.add_le _ _
lemma IsAbsoluteValue.abv_sum [Semiring R] [OrderedSemiring S] (abv : R → S) [IsAbsoluteValue abv]
(f : ι → R) (s : Finset ι) : abv (∑ i ∈ s, f i) ≤ ∑ i ∈ s, abv (f i) :=
(IsAbsoluteValue.toAbsoluteValue abv).sum_le _ _
@[deprecated (since := "2024-02-14")] alias abv_sum_le_sum_abv := IsAbsoluteValue.abv_sum
nonrec lemma AbsoluteValue.map_prod [CommSemiring R] [Nontrivial R] [LinearOrderedCommRing S]
(abv : AbsoluteValue R S) (f : ι → R) (s : Finset ι) :
abv (∏ i ∈ s, f i) = ∏ i ∈ s, abv (f i) :=
map_prod abv f s
lemma IsAbsoluteValue.map_prod [CommSemiring R] [Nontrivial R] [LinearOrderedCommRing S]
(abv : R → S) [IsAbsoluteValue abv] (f : ι → R) (s : Finset ι) :
abv (∏ i ∈ s, f i) = ∏ i ∈ s, abv (f i) :=
(IsAbsoluteValue.toAbsoluteValue abv).map_prod _ _
end AbsoluteValue
namespace Mathlib.Meta.Positivity
open Qq Lean Meta Finset
private alias ⟨_, prod_ne_zero⟩ := prod_ne_zero_iff
/-- The `positivity` extension which proves that `∏ i ∈ s, f i` is nonnegative if `f` is, and
positive if each `f i` is.
TODO: The following example does not work
```
example (s : Finset ℕ) (f : ℕ → ℤ) (hf : ∀ n, 0 ≤ f n) : 0 ≤ s.prod f := by positivity
```
because `compareHyp` can't look for assumptions behind binders.
-/
@[positivity Finset.prod _ _]
def evalFinsetProd : PositivityExt where eval {u α} zα pα e := do
match e with
| ~q(@Finset.prod $ι _ $instα $s $f) =>
let i : Q($ι) ← mkFreshExprMVarQ q($ι) .syntheticOpaque
have body : Q($α) := Expr.betaRev f #[i]
let rbody ← core zα pα body
let _instαmon ← synthInstanceQ q(CommMonoidWithZero $α)
-- Try to show that the product is positive
let p_pos : Option Q(0 < $e) := ← do
let .positive pbody := rbody | pure none -- Fail if the body is not provably positive
-- TODO(quote4#38): We must name the following, else `assertInstancesCommute` loops.
let .some _instαzeroone ← trySynthInstanceQ q(ZeroLEOneClass $α) | pure none
let .some _instαposmul ← trySynthInstanceQ q(PosMulStrictMono $α) | pure none
let .some _instαnontriv ← trySynthInstanceQ q(Nontrivial $α) | pure none
assertInstancesCommute
let pr : Q(∀ i, 0 < $f i) ← mkLambdaFVars #[i] pbody (binderInfoForMVars := .default)
return some q(prod_pos fun i _ ↦ $pr i)
if let some p_pos := p_pos then return .positive p_pos
-- Try to show that the product is nonnegative
let p_nonneg : Option Q(0 ≤ $e) := ← do
let .some pbody := rbody.toNonneg
| return none -- Fail if the body is not provably nonnegative
let pr : Q(∀ i, 0 ≤ $f i) ← mkLambdaFVars #[i] pbody (binderInfoForMVars := .default)
-- TODO(quote4#38): We must name the following, else `assertInstancesCommute` loops.
let .some _instαzeroone ← trySynthInstanceQ q(ZeroLEOneClass $α) | pure none
let .some _instαposmul ← trySynthInstanceQ q(PosMulMono $α) | pure none
assertInstancesCommute
return some q(prod_nonneg fun i _ ↦ $pr i)
if let some p_nonneg := p_nonneg then return .nonnegative p_nonneg
-- Fall back to showing that the product is nonzero
let pbody ← rbody.toNonzero
let pr : Q(∀ i, $f i ≠ 0) ← mkLambdaFVars #[i] pbody (binderInfoForMVars := .default)
-- TODO(quote4#38): We must name the following, else `assertInstancesCommute` loops.
let _instαnontriv ← synthInstanceQ q(Nontrivial $α)
let _instαnozerodiv ← synthInstanceQ q(NoZeroDivisors $α)
assertInstancesCommute
return .nonzero q(prod_ne_zero fun i _ ↦ $pr i)
end Mathlib.Meta.Positivity
|
Algebra\Order\BigOperators\Ring\List.lean | /-
Copyright (c) 2021 Stuart Presnell. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Stuart Presnell
-/
import Mathlib.Algebra.BigOperators.Group.List
import Mathlib.Algebra.Order.Ring.Canonical
/-!
# Big operators on a list in ordered rings
This file contains the results concerning the interaction of list big operators with ordered rings.
-/
variable {R : Type*}
namespace List
/-- The product of a list of positive natural numbers is positive,
and likewise for any nontrivial ordered semiring. -/
lemma prod_pos [StrictOrderedSemiring R] (l : List R) (h : ∀ a ∈ l, (0 : R) < a) :
0 < l.prod := by
induction' l with a l ih
· simp
· rw [prod_cons]
exact mul_pos (h _ <| mem_cons_self _ _) (ih fun a ha => h a <| mem_cons_of_mem _ ha)
/-- A variant of `List.prod_pos` for `CanonicallyOrderedCommSemiring`. -/
@[simp] lemma _root_.CanonicallyOrderedCommSemiring.list_prod_pos
{α : Type*} [CanonicallyOrderedCommSemiring α] [Nontrivial α] :
∀ {l : List α}, 0 < l.prod ↔ (∀ x ∈ l, (0 : α) < x)
| [] => by simp
| (x :: xs) => by simp_rw [prod_cons, forall_mem_cons, CanonicallyOrderedCommSemiring.mul_pos,
list_prod_pos]
end List
|
Algebra\Order\BigOperators\Ring\Multiset.lean | /-
Copyright (c) 2021 Ruben Van de Velde. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Ruben Van de Velde
-/
import Mathlib.Algebra.BigOperators.Group.Multiset
import Mathlib.Algebra.Order.BigOperators.Ring.List
/-!
# Big operators on a multiset in ordered rings
This file contains the results concerning the interaction of multiset big operators with ordered
rings.
-/
namespace Multiset
variable {R : Type*}
section OrderedCommSemiring
variable [OrderedCommSemiring R] {s : Multiset R}
lemma prod_nonneg (h : ∀ a ∈ s, 0 ≤ a) : 0 ≤ s.prod := by
revert h
refine s.induction_on ?_ fun a s hs ih ↦ ?_
· simp
· rw [prod_cons]
exact mul_nonneg (ih _ <| mem_cons_self _ _) (hs fun a ha ↦ ih _ <| mem_cons_of_mem ha)
end OrderedCommSemiring
@[simp]
lemma _root_.CanonicallyOrderedCommSemiring.multiset_prod_pos [CanonicallyOrderedCommSemiring R]
[Nontrivial R] {m : Multiset R} : 0 < m.prod ↔ ∀ x ∈ m, 0 < x := by
rcases m with ⟨l⟩
rw [Multiset.quot_mk_to_coe'', Multiset.prod_coe]
exact CanonicallyOrderedCommSemiring.list_prod_pos
end Multiset
|
Algebra\Order\CauSeq\Basic.lean | /-
Copyright (c) 2018 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
-/
import Mathlib.Algebra.Group.Action.Pi
import Mathlib.Algebra.Order.AbsoluteValue
import Mathlib.Algebra.Order.Field.Basic
import Mathlib.Algebra.Order.Group.MinMax
import Mathlib.Algebra.Ring.Pi
import Mathlib.Data.Setoid.Basic
import Mathlib.GroupTheory.GroupAction.Ring
import Mathlib.Tactic.GCongr
/-!
# Cauchy sequences
A basic theory of Cauchy sequences, used in the construction of the reals and p-adic numbers. Where
applicable, lemmas that will be reused in other contexts have been stated in extra generality.
There are other "versions" of Cauchyness in the library, in particular Cauchy filters in topology.
This is a concrete implementation that is useful for simplicity and computability reasons.
## Important definitions
* `IsCauSeq`: a predicate that says `f : ℕ → β` is Cauchy.
* `CauSeq`: the type of Cauchy sequences valued in type `β` with respect to an absolute value
function `abv`.
## Tags
sequence, cauchy, abs val, absolute value
-/
assert_not_exists Finset
assert_not_exists Module
assert_not_exists Submonoid
assert_not_exists FloorRing
variable {α β : Type*}
open IsAbsoluteValue
section
variable [LinearOrderedField α] [Ring β] (abv : β → α) [IsAbsoluteValue abv]
theorem rat_add_continuous_lemma {ε : α} (ε0 : 0 < ε) :
∃ δ > 0, ∀ {a₁ a₂ b₁ b₂ : β}, abv (a₁ - b₁) < δ → abv (a₂ - b₂) < δ →
abv (a₁ + a₂ - (b₁ + b₂)) < ε :=
⟨ε / 2, half_pos ε0, fun {a₁ a₂ b₁ b₂} h₁ h₂ => by
simpa [add_halves, sub_eq_add_neg, add_comm, add_left_comm, add_assoc] using
lt_of_le_of_lt (abv_add abv _ _) (add_lt_add h₁ h₂)⟩
theorem rat_mul_continuous_lemma {ε K₁ K₂ : α} (ε0 : 0 < ε) :
∃ δ > 0, ∀ {a₁ a₂ b₁ b₂ : β}, abv a₁ < K₁ → abv b₂ < K₂ → abv (a₁ - b₁) < δ →
abv (a₂ - b₂) < δ → abv (a₁ * a₂ - b₁ * b₂) < ε := by
have K0 : (0 : α) < max 1 (max K₁ K₂) := lt_of_lt_of_le zero_lt_one (le_max_left _ _)
have εK := div_pos (half_pos ε0) K0
refine ⟨_, εK, fun {a₁ a₂ b₁ b₂} ha₁ hb₂ h₁ h₂ => ?_⟩
replace ha₁ := lt_of_lt_of_le ha₁ (le_trans (le_max_left _ K₂) (le_max_right 1 _))
replace hb₂ := lt_of_lt_of_le hb₂ (le_trans (le_max_right K₁ _) (le_max_right 1 _))
set M := max 1 (max K₁ K₂)
have : abv (a₁ - b₁) * abv b₂ + abv (a₂ - b₂) * abv a₁ < ε / 2 / M * M + ε / 2 / M * M := by
gcongr
rw [← abv_mul abv, mul_comm, div_mul_cancel₀ _ (ne_of_gt K0), ← abv_mul abv, add_halves] at this
simpa [sub_eq_add_neg, mul_add, add_mul, add_left_comm] using
lt_of_le_of_lt (abv_add abv _ _) this
theorem rat_inv_continuous_lemma {β : Type*} [DivisionRing β] (abv : β → α) [IsAbsoluteValue abv]
{ε K : α} (ε0 : 0 < ε) (K0 : 0 < K) :
∃ δ > 0, ∀ {a b : β}, K ≤ abv a → K ≤ abv b → abv (a - b) < δ → abv (a⁻¹ - b⁻¹) < ε := by
refine ⟨K * ε * K, mul_pos (mul_pos K0 ε0) K0, fun {a b} ha hb h => ?_⟩
have a0 := K0.trans_le ha
have b0 := K0.trans_le hb
rw [inv_sub_inv' ((abv_pos abv).1 a0) ((abv_pos abv).1 b0), abv_mul abv, abv_mul abv, abv_inv abv,
abv_inv abv, abv_sub abv]
refine lt_of_mul_lt_mul_left (lt_of_mul_lt_mul_right ?_ b0.le) a0.le
rw [mul_assoc, inv_mul_cancel_right₀ b0.ne', ← mul_assoc, mul_inv_cancel a0.ne', one_mul]
refine h.trans_le ?_
gcongr
end
/-- A sequence is Cauchy if the distance between its entries tends to zero. -/
def IsCauSeq {α : Type*} [LinearOrderedField α] {β : Type*} [Ring β] (abv : β → α) (f : ℕ → β) :
Prop :=
∀ ε > 0, ∃ i, ∀ j ≥ i, abv (f j - f i) < ε
namespace IsCauSeq
variable [LinearOrderedField α] [Ring β] {abv : β → α} [IsAbsoluteValue abv] {f g : ℕ → β}
-- see Note [nolint_ge]
--@[nolint ge_or_gt] -- Porting note: restore attribute
theorem cauchy₂ (hf : IsCauSeq abv f) {ε : α} (ε0 : 0 < ε) :
∃ i, ∀ j ≥ i, ∀ k ≥ i, abv (f j - f k) < ε := by
refine (hf _ (half_pos ε0)).imp fun i hi j ij k ik => ?_
rw [← add_halves ε]
refine lt_of_le_of_lt (abv_sub_le abv _ _ _) (add_lt_add (hi _ ij) ?_)
rw [abv_sub abv]; exact hi _ ik
theorem cauchy₃ (hf : IsCauSeq abv f) {ε : α} (ε0 : 0 < ε) :
∃ i, ∀ j ≥ i, ∀ k ≥ j, abv (f k - f j) < ε :=
let ⟨i, H⟩ := hf.cauchy₂ ε0
⟨i, fun _ ij _ jk => H _ (le_trans ij jk) _ ij⟩
lemma bounded (hf : IsCauSeq abv f) : ∃ r, ∀ i, abv (f i) < r := by
obtain ⟨i, h⟩ := hf _ zero_lt_one
set R : ℕ → α := @Nat.rec (fun _ => α) (abv (f 0)) fun i c => max c (abv (f i.succ)) with hR
have : ∀ i, ∀ j ≤ i, abv (f j) ≤ R i := by
refine Nat.rec (by simp [hR]) ?_
rintro i hi j (rfl | hj)
· simp [R]
· exact (hi j hj).trans (le_max_left _ _)
refine ⟨R i + 1, fun j ↦ ?_⟩
obtain hji | hij := le_total j i
· exact (this i _ hji).trans_lt (lt_add_one _)
· simpa using (abv_add abv _ _).trans_lt $ add_lt_add_of_le_of_lt (this i _ le_rfl) (h _ hij)
lemma bounded' (hf : IsCauSeq abv f) (x : α) : ∃ r > x, ∀ i, abv (f i) < r :=
let ⟨r, h⟩ := hf.bounded
⟨max r (x + 1), (lt_add_one x).trans_le (le_max_right _ _),
fun i ↦ (h i).trans_le (le_max_left _ _)⟩
lemma const (x : β) : IsCauSeq abv fun _ ↦ x :=
fun ε ε0 ↦ ⟨0, fun j _ => by simpa [abv_zero] using ε0⟩
theorem add (hf : IsCauSeq abv f) (hg : IsCauSeq abv g) : IsCauSeq abv (f + g) := fun _ ε0 =>
let ⟨_, δ0, Hδ⟩ := rat_add_continuous_lemma abv ε0
let ⟨i, H⟩ := exists_forall_ge_and (hf.cauchy₃ δ0) (hg.cauchy₃ δ0)
⟨i, fun _ ij =>
let ⟨H₁, H₂⟩ := H _ le_rfl
Hδ (H₁ _ ij) (H₂ _ ij)⟩
lemma mul (hf : IsCauSeq abv f) (hg : IsCauSeq abv g) : IsCauSeq abv (f * g) := fun _ ε0 =>
let ⟨_, _, hF⟩ := hf.bounded' 0
let ⟨_, _, hG⟩ := hg.bounded' 0
let ⟨_, δ0, Hδ⟩ := rat_mul_continuous_lemma abv ε0
let ⟨i, H⟩ := exists_forall_ge_and (hf.cauchy₃ δ0) (hg.cauchy₃ δ0)
⟨i, fun j ij =>
let ⟨H₁, H₂⟩ := H _ le_rfl
Hδ (hF j) (hG i) (H₁ _ ij) (H₂ _ ij)⟩
@[simp] lemma _root_.isCauSeq_neg : IsCauSeq abv (-f) ↔ IsCauSeq abv f := by
simp only [IsCauSeq, Pi.neg_apply, ← neg_sub', abv_neg]
protected alias ⟨of_neg, neg⟩ := isCauSeq_neg
end IsCauSeq
/-- `CauSeq β abv` is the type of `β`-valued Cauchy sequences, with respect to the absolute value
function `abv`. -/
def CauSeq {α : Type*} [LinearOrderedField α] (β : Type*) [Ring β] (abv : β → α) : Type _ :=
{ f : ℕ → β // IsCauSeq abv f }
namespace CauSeq
variable [LinearOrderedField α]
section Ring
variable [Ring β] {abv : β → α}
instance : CoeFun (CauSeq β abv) fun _ => ℕ → β :=
⟨Subtype.val⟩
-- Porting note: Remove coeFn theorem
/-@[simp]
theorem mk_to_fun (f) (hf : IsCauSeq abv f) : @coeFn (CauSeq β abv) _ _ ⟨f, hf⟩ = f :=
rfl -/
@[ext]
theorem ext {f g : CauSeq β abv} (h : ∀ i, f i = g i) : f = g := Subtype.eq (funext h)
theorem isCauSeq (f : CauSeq β abv) : IsCauSeq abv f :=
f.2
theorem cauchy (f : CauSeq β abv) : ∀ {ε}, 0 < ε → ∃ i, ∀ j ≥ i, abv (f j - f i) < ε := @f.2
/-- Given a Cauchy sequence `f`, create a Cauchy sequence from a sequence `g` with
the same values as `f`. -/
def ofEq (f : CauSeq β abv) (g : ℕ → β) (e : ∀ i, f i = g i) : CauSeq β abv :=
⟨g, fun ε => by rw [show g = f from (funext e).symm]; exact f.cauchy⟩
variable [IsAbsoluteValue abv]
-- see Note [nolint_ge]
-- @[nolint ge_or_gt] -- Porting note: restore attribute
theorem cauchy₂ (f : CauSeq β abv) {ε} :
0 < ε → ∃ i, ∀ j ≥ i, ∀ k ≥ i, abv (f j - f k) < ε :=
f.2.cauchy₂
theorem cauchy₃ (f : CauSeq β abv) {ε} : 0 < ε → ∃ i, ∀ j ≥ i, ∀ k ≥ j, abv (f k - f j) < ε :=
f.2.cauchy₃
theorem bounded (f : CauSeq β abv) : ∃ r, ∀ i, abv (f i) < r := f.2.bounded
theorem bounded' (f : CauSeq β abv) (x : α) : ∃ r > x, ∀ i, abv (f i) < r := f.2.bounded' x
instance : Add (CauSeq β abv) :=
⟨fun f g => ⟨f + g, f.2.add g.2⟩⟩
@[simp, norm_cast]
theorem coe_add (f g : CauSeq β abv) : ⇑(f + g) = (f : ℕ → β) + g :=
rfl
@[simp, norm_cast]
theorem add_apply (f g : CauSeq β abv) (i : ℕ) : (f + g) i = f i + g i :=
rfl
variable (abv)
/-- The constant Cauchy sequence. -/
def const (x : β) : CauSeq β abv := ⟨fun _ ↦ x, IsCauSeq.const _⟩
variable {abv}
/-- The constant Cauchy sequence -/
local notation "const" => const abv
@[simp, norm_cast]
theorem coe_const (x : β) : (const x : ℕ → β) = Function.const ℕ x :=
rfl
@[simp, norm_cast]
theorem const_apply (x : β) (i : ℕ) : (const x : ℕ → β) i = x :=
rfl
theorem const_inj {x y : β} : (const x : CauSeq β abv) = const y ↔ x = y :=
⟨fun h => congr_arg (fun f : CauSeq β abv => (f : ℕ → β) 0) h, congr_arg _⟩
instance : Zero (CauSeq β abv) :=
⟨const 0⟩
instance : One (CauSeq β abv) :=
⟨const 1⟩
instance : Inhabited (CauSeq β abv) :=
⟨0⟩
@[simp, norm_cast]
theorem coe_zero : ⇑(0 : CauSeq β abv) = 0 :=
rfl
@[simp, norm_cast]
theorem coe_one : ⇑(1 : CauSeq β abv) = 1 :=
rfl
@[simp, norm_cast]
theorem zero_apply (i) : (0 : CauSeq β abv) i = 0 :=
rfl
@[simp, norm_cast]
theorem one_apply (i) : (1 : CauSeq β abv) i = 1 :=
rfl
@[simp]
theorem const_zero : const 0 = 0 :=
rfl
@[simp]
theorem const_one : const 1 = 1 :=
rfl
theorem const_add (x y : β) : const (x + y) = const x + const y :=
rfl
instance : Mul (CauSeq β abv) := ⟨fun f g ↦ ⟨f * g, f.2.mul g.2⟩⟩
@[simp, norm_cast]
theorem coe_mul (f g : CauSeq β abv) : ⇑(f * g) = (f : ℕ → β) * g :=
rfl
@[simp, norm_cast]
theorem mul_apply (f g : CauSeq β abv) (i : ℕ) : (f * g) i = f i * g i :=
rfl
theorem const_mul (x y : β) : const (x * y) = const x * const y :=
rfl
instance : Neg (CauSeq β abv) := ⟨fun f ↦ ⟨-f, f.2.neg⟩⟩
@[simp, norm_cast]
theorem coe_neg (f : CauSeq β abv) : ⇑(-f) = -f :=
rfl
@[simp, norm_cast]
theorem neg_apply (f : CauSeq β abv) (i) : (-f) i = -f i :=
rfl
theorem const_neg (x : β) : const (-x) = -const x :=
rfl
instance : Sub (CauSeq β abv) :=
⟨fun f g => ofEq (f + -g) (fun x => f x - g x) fun i => by simp [sub_eq_add_neg]⟩
@[simp, norm_cast]
theorem coe_sub (f g : CauSeq β abv) : ⇑(f - g) = (f : ℕ → β) - g :=
rfl
@[simp, norm_cast]
theorem sub_apply (f g : CauSeq β abv) (i : ℕ) : (f - g) i = f i - g i :=
rfl
theorem const_sub (x y : β) : const (x - y) = const x - const y :=
rfl
section SMul
variable {G : Type*} [SMul G β] [IsScalarTower G β β]
instance : SMul G (CauSeq β abv) :=
⟨fun a f => (ofEq (const (a • (1 : β)) * f) (a • (f : ℕ → β))) fun _ => smul_one_mul _ _⟩
@[simp, norm_cast]
theorem coe_smul (a : G) (f : CauSeq β abv) : ⇑(a • f) = a • (f : ℕ → β) :=
rfl
@[simp, norm_cast]
theorem smul_apply (a : G) (f : CauSeq β abv) (i : ℕ) : (a • f) i = a • f i :=
rfl
theorem const_smul (a : G) (x : β) : const (a • x) = a • const x :=
rfl
instance : IsScalarTower G (CauSeq β abv) (CauSeq β abv) :=
⟨fun a f g => Subtype.ext <| smul_assoc a (f : ℕ → β) (g : ℕ → β)⟩
end SMul
instance addGroup : AddGroup (CauSeq β abv) :=
Function.Injective.addGroup Subtype.val Subtype.val_injective rfl coe_add coe_neg coe_sub
(fun _ _ => coe_smul _ _) fun _ _ => coe_smul _ _
instance instNatCast : NatCast (CauSeq β abv) := ⟨fun n => const n⟩
instance instIntCast : IntCast (CauSeq β abv) := ⟨fun n => const n⟩
instance addGroupWithOne : AddGroupWithOne (CauSeq β abv) :=
Function.Injective.addGroupWithOne Subtype.val Subtype.val_injective rfl rfl
coe_add coe_neg coe_sub
(by intros; rfl)
(by intros; rfl)
(by intros; rfl)
(by intros; rfl)
instance : Pow (CauSeq β abv) ℕ :=
⟨fun f n =>
(ofEq (npowRec n f) fun i => f i ^ n) <| by induction n <;> simp [*, npowRec, pow_succ]⟩
@[simp, norm_cast]
theorem coe_pow (f : CauSeq β abv) (n : ℕ) : ⇑(f ^ n) = (f : ℕ → β) ^ n :=
rfl
@[simp, norm_cast]
theorem pow_apply (f : CauSeq β abv) (n i : ℕ) : (f ^ n) i = f i ^ n :=
rfl
theorem const_pow (x : β) (n : ℕ) : const (x ^ n) = const x ^ n :=
rfl
instance ring : Ring (CauSeq β abv) :=
Function.Injective.ring Subtype.val Subtype.val_injective rfl rfl coe_add coe_mul coe_neg coe_sub
(fun _ _ => coe_smul _ _) (fun _ _ => coe_smul _ _) coe_pow (fun _ => rfl) fun _ => rfl
instance {β : Type*} [CommRing β] {abv : β → α} [IsAbsoluteValue abv] : CommRing (CauSeq β abv) :=
{ CauSeq.ring with
mul_comm := fun a b => ext fun n => by simp [mul_left_comm, mul_comm] }
/-- `LimZero f` holds when `f` approaches 0. -/
def LimZero {abv : β → α} (f : CauSeq β abv) : Prop :=
∀ ε > 0, ∃ i, ∀ j ≥ i, abv (f j) < ε
theorem add_limZero {f g : CauSeq β abv} (hf : LimZero f) (hg : LimZero g) : LimZero (f + g)
| ε, ε0 =>
(exists_forall_ge_and (hf _ <| half_pos ε0) (hg _ <| half_pos ε0)).imp fun i H j ij => by
let ⟨H₁, H₂⟩ := H _ ij
simpa [add_halves ε] using lt_of_le_of_lt (abv_add abv _ _) (add_lt_add H₁ H₂)
theorem mul_limZero_right (f : CauSeq β abv) {g} (hg : LimZero g) : LimZero (f * g)
| ε, ε0 =>
let ⟨F, F0, hF⟩ := f.bounded' 0
(hg _ <| div_pos ε0 F0).imp fun i H j ij => by
have := mul_lt_mul' (le_of_lt <| hF j) (H _ ij) (abv_nonneg abv _) F0
rwa [mul_comm F, div_mul_cancel₀ _ (ne_of_gt F0), ← abv_mul] at this
theorem mul_limZero_left {f} (g : CauSeq β abv) (hg : LimZero f) : LimZero (f * g)
| ε, ε0 =>
let ⟨G, G0, hG⟩ := g.bounded' 0
(hg _ <| div_pos ε0 G0).imp fun i H j ij => by
have := mul_lt_mul'' (H _ ij) (hG j) (abv_nonneg abv _) (abv_nonneg abv _)
rwa [div_mul_cancel₀ _ (ne_of_gt G0), ← abv_mul] at this
theorem neg_limZero {f : CauSeq β abv} (hf : LimZero f) : LimZero (-f) := by
rw [← neg_one_mul f]
exact mul_limZero_right _ hf
theorem sub_limZero {f g : CauSeq β abv} (hf : LimZero f) (hg : LimZero g) : LimZero (f - g) := by
simpa only [sub_eq_add_neg] using add_limZero hf (neg_limZero hg)
theorem limZero_sub_rev {f g : CauSeq β abv} (hfg : LimZero (f - g)) : LimZero (g - f) := by
simpa using neg_limZero hfg
theorem zero_limZero : LimZero (0 : CauSeq β abv)
| ε, ε0 => ⟨0, fun j _ => by simpa [abv_zero abv] using ε0⟩
theorem const_limZero {x : β} : LimZero (const x) ↔ x = 0 :=
⟨fun H =>
(abv_eq_zero abv).1 <|
(eq_of_le_of_forall_le_of_dense (abv_nonneg abv _)) fun _ ε0 =>
let ⟨_, hi⟩ := H _ ε0
le_of_lt <| hi _ le_rfl,
fun e => e.symm ▸ zero_limZero⟩
instance equiv : Setoid (CauSeq β abv) :=
⟨fun f g => LimZero (f - g),
⟨fun f => by simp [zero_limZero],
fun f ε hε => by simpa using neg_limZero f ε hε,
fun fg gh => by simpa using add_limZero fg gh⟩⟩
theorem add_equiv_add {f1 f2 g1 g2 : CauSeq β abv} (hf : f1 ≈ f2) (hg : g1 ≈ g2) :
f1 + g1 ≈ f2 + g2 := by simpa only [← add_sub_add_comm] using add_limZero hf hg
theorem neg_equiv_neg {f g : CauSeq β abv} (hf : f ≈ g) : -f ≈ -g := by
simpa only [neg_sub'] using neg_limZero hf
theorem sub_equiv_sub {f1 f2 g1 g2 : CauSeq β abv} (hf : f1 ≈ f2) (hg : g1 ≈ g2) :
f1 - g1 ≈ f2 - g2 := by simpa only [sub_eq_add_neg] using add_equiv_add hf (neg_equiv_neg hg)
theorem equiv_def₃ {f g : CauSeq β abv} (h : f ≈ g) {ε : α} (ε0 : 0 < ε) :
∃ i, ∀ j ≥ i, ∀ k ≥ j, abv (f k - g j) < ε :=
(exists_forall_ge_and (h _ <| half_pos ε0) (f.cauchy₃ <| half_pos ε0)).imp fun i H j ij k jk => by
let ⟨h₁, h₂⟩ := H _ ij
have := lt_of_le_of_lt (abv_add abv (f j - g j) _) (add_lt_add h₁ (h₂ _ jk))
rwa [sub_add_sub_cancel', add_halves] at this
theorem limZero_congr {f g : CauSeq β abv} (h : f ≈ g) : LimZero f ↔ LimZero g :=
⟨fun l => by simpa using add_limZero (Setoid.symm h) l, fun l => by simpa using add_limZero h l⟩
theorem abv_pos_of_not_limZero {f : CauSeq β abv} (hf : ¬LimZero f) :
∃ K > 0, ∃ i, ∀ j ≥ i, K ≤ abv (f j) := by
haveI := Classical.propDecidable
by_contra nk
refine hf fun ε ε0 => ?_
simp? [not_forall] at nk says
simp only [gt_iff_lt, ge_iff_le, not_exists, not_and, not_forall, Classical.not_imp,
not_le] at nk
cases' f.cauchy₃ (half_pos ε0) with i hi
rcases nk _ (half_pos ε0) i with ⟨j, ij, hj⟩
refine ⟨j, fun k jk => ?_⟩
have := lt_of_le_of_lt (abv_add abv _ _) (add_lt_add (hi j ij k jk) hj)
rwa [sub_add_cancel, add_halves] at this
theorem of_near (f : ℕ → β) (g : CauSeq β abv) (h : ∀ ε > 0, ∃ i, ∀ j ≥ i, abv (f j - g j) < ε) :
IsCauSeq abv f
| ε, ε0 =>
let ⟨i, hi⟩ := exists_forall_ge_and (h _ (half_pos <| half_pos ε0)) (g.cauchy₃ <| half_pos ε0)
⟨i, fun j ij => by
cases' hi _ le_rfl with h₁ h₂; rw [abv_sub abv] at h₁
have := lt_of_le_of_lt (abv_add abv _ _) (add_lt_add (hi _ ij).1 h₁)
have := lt_of_le_of_lt (abv_add abv _ _) (add_lt_add this (h₂ _ ij))
rwa [add_halves, add_halves, add_right_comm, sub_add_sub_cancel, sub_add_sub_cancel] at this⟩
theorem not_limZero_of_not_congr_zero {f : CauSeq _ abv} (hf : ¬f ≈ 0) : ¬LimZero f := by
intro h
have : LimZero (f - 0) := by simp [h]
exact hf this
theorem mul_equiv_zero (g : CauSeq _ abv) {f : CauSeq _ abv} (hf : f ≈ 0) : g * f ≈ 0 :=
have : LimZero (f - 0) := hf
have : LimZero (g * f) := mul_limZero_right _ <| by simpa
show LimZero (g * f - 0) by simpa
theorem mul_equiv_zero' (g : CauSeq _ abv) {f : CauSeq _ abv} (hf : f ≈ 0) : f * g ≈ 0 :=
have : LimZero (f - 0) := hf
have : LimZero (f * g) := mul_limZero_left _ <| by simpa
show LimZero (f * g - 0) by simpa
theorem mul_not_equiv_zero {f g : CauSeq _ abv} (hf : ¬f ≈ 0) (hg : ¬g ≈ 0) : ¬f * g ≈ 0 :=
fun (this : LimZero (f * g - 0)) => by
have hlz : LimZero (f * g) := by simpa
have hf' : ¬LimZero f := by simpa using show ¬LimZero (f - 0) from hf
have hg' : ¬LimZero g := by simpa using show ¬LimZero (g - 0) from hg
rcases abv_pos_of_not_limZero hf' with ⟨a1, ha1, N1, hN1⟩
rcases abv_pos_of_not_limZero hg' with ⟨a2, ha2, N2, hN2⟩
have : 0 < a1 * a2 := mul_pos ha1 ha2
cases' hlz _ this with N hN
let i := max N (max N1 N2)
have hN' := hN i (le_max_left _ _)
have hN1' := hN1 i (le_trans (le_max_left _ _) (le_max_right _ _))
have hN1' := hN2 i (le_trans (le_max_right _ _) (le_max_right _ _))
apply not_le_of_lt hN'
change _ ≤ abv (_ * _)
rw [abv_mul abv]
gcongr
theorem const_equiv {x y : β} : const x ≈ const y ↔ x = y :=
show LimZero _ ↔ _ by rw [← const_sub, const_limZero, sub_eq_zero]
theorem mul_equiv_mul {f1 f2 g1 g2 : CauSeq β abv} (hf : f1 ≈ f2) (hg : g1 ≈ g2) :
f1 * g1 ≈ f2 * g2 := by
change LimZero (f1 * g1 - f2 * g2)
convert add_limZero (mul_limZero_left g1 hf) (mul_limZero_right f2 hg) using 1
rw [mul_sub, sub_mul]
-- Porting note: doesn't work with `rw`, but did in Lean 3
exact (sub_add_sub_cancel (f1*g1) (f2*g1) (f2*g2)).symm
-- Porting note: was
/-
simpa only [mul_sub, sub_mul, sub_add_sub_cancel] using
add_lim_zero (mul_limZero_left g1 hf) (mul_limZero_right f2 hg)
-/
theorem smul_equiv_smul {G : Type*} [SMul G β] [IsScalarTower G β β] {f1 f2 : CauSeq β abv} (c : G)
(hf : f1 ≈ f2) : c • f1 ≈ c • f2 := by
simpa [const_smul, smul_one_mul _ _] using
mul_equiv_mul (const_equiv.mpr <| Eq.refl <| c • (1 : β)) hf
theorem pow_equiv_pow {f1 f2 : CauSeq β abv} (hf : f1 ≈ f2) (n : ℕ) : f1 ^ n ≈ f2 ^ n := by
induction' n with n ih
· simp only [Nat.zero_eq, pow_zero, Setoid.refl]
· simpa only [pow_succ'] using mul_equiv_mul hf ih
end Ring
section IsDomain
variable [Ring β] [IsDomain β] (abv : β → α) [IsAbsoluteValue abv]
theorem one_not_equiv_zero : ¬const abv 1 ≈ const abv 0 := fun h =>
have : ∀ ε > 0, ∃ i, ∀ k, i ≤ k → abv (1 - 0) < ε := h
have h1 : abv 1 ≤ 0 :=
le_of_not_gt fun h2 : 0 < abv 1 =>
(Exists.elim (this _ h2)) fun i hi => lt_irrefl (abv 1) <| by simpa using hi _ le_rfl
have h2 : 0 ≤ abv 1 := abv_nonneg abv _
have : abv 1 = 0 := le_antisymm h1 h2
have : (1 : β) = 0 := (abv_eq_zero abv).mp this
absurd this one_ne_zero
end IsDomain
section DivisionRing
variable [DivisionRing β] {abv : β → α} [IsAbsoluteValue abv]
theorem inv_aux {f : CauSeq β abv} (hf : ¬LimZero f) :
∀ ε > 0, ∃ i, ∀ j ≥ i, abv ((f j)⁻¹ - (f i)⁻¹) < ε
| _, ε0 =>
let ⟨_, K0, HK⟩ := abv_pos_of_not_limZero hf
let ⟨_, δ0, Hδ⟩ := rat_inv_continuous_lemma abv ε0 K0
let ⟨i, H⟩ := exists_forall_ge_and HK (f.cauchy₃ δ0)
⟨i, fun _ ij =>
let ⟨iK, H'⟩ := H _ le_rfl
Hδ (H _ ij).1 iK (H' _ ij)⟩
/-- Given a Cauchy sequence `f` with nonzero limit, create a Cauchy sequence with values equal to
the inverses of the values of `f`. -/
def inv (f : CauSeq β abv) (hf : ¬LimZero f) : CauSeq β abv :=
⟨_, inv_aux hf⟩
@[simp, norm_cast]
theorem coe_inv {f : CauSeq β abv} (hf) : ⇑(inv f hf) = (f : ℕ → β)⁻¹ :=
rfl
@[simp, norm_cast]
theorem inv_apply {f : CauSeq β abv} (hf i) : inv f hf i = (f i)⁻¹ :=
rfl
theorem inv_mul_cancel {f : CauSeq β abv} (hf) : inv f hf * f ≈ 1 := fun ε ε0 =>
let ⟨K, K0, i, H⟩ := abv_pos_of_not_limZero hf
⟨i, fun j ij => by simpa [(abv_pos abv).1 (lt_of_lt_of_le K0 (H _ ij)), abv_zero abv] using ε0⟩
theorem mul_inv_cancel {f : CauSeq β abv} (hf) : f * inv f hf ≈ 1 := fun ε ε0 =>
let ⟨K, K0, i, H⟩ := abv_pos_of_not_limZero hf
⟨i, fun j ij => by simpa [(abv_pos abv).1 (lt_of_lt_of_le K0 (H _ ij)), abv_zero abv] using ε0⟩
theorem const_inv {x : β} (hx : x ≠ 0) :
const abv x⁻¹ = inv (const abv x) (by rwa [const_limZero]) :=
rfl
end DivisionRing
section Abs
/-- The constant Cauchy sequence -/
local notation "const" => const abs
/-- The entries of a positive Cauchy sequence eventually have a positive lower bound. -/
def Pos (f : CauSeq α abs) : Prop :=
∃ K > 0, ∃ i, ∀ j ≥ i, K ≤ f j
theorem not_limZero_of_pos {f : CauSeq α abs} : Pos f → ¬LimZero f
| ⟨_, F0, hF⟩, H =>
let ⟨_, h⟩ := exists_forall_ge_and hF (H _ F0)
let ⟨h₁, h₂⟩ := h _ le_rfl
not_lt_of_le h₁ (abs_lt.1 h₂).2
theorem const_pos {x : α} : Pos (const x) ↔ 0 < x :=
⟨fun ⟨_, K0, _, h⟩ => lt_of_lt_of_le K0 (h _ le_rfl), fun h => ⟨x, h, 0, fun _ _ => le_rfl⟩⟩
theorem add_pos {f g : CauSeq α abs} : Pos f → Pos g → Pos (f + g)
| ⟨_, F0, hF⟩, ⟨_, G0, hG⟩ =>
let ⟨i, h⟩ := exists_forall_ge_and hF hG
⟨_, _root_.add_pos F0 G0, i, fun _ ij =>
let ⟨h₁, h₂⟩ := h _ ij
add_le_add h₁ h₂⟩
theorem pos_add_limZero {f g : CauSeq α abs} : Pos f → LimZero g → Pos (f + g)
| ⟨F, F0, hF⟩, H =>
let ⟨i, h⟩ := exists_forall_ge_and hF (H _ (half_pos F0))
⟨_, half_pos F0, i, fun j ij => by
cases' h j ij with h₁ h₂
have := add_le_add h₁ (le_of_lt (abs_lt.1 h₂).1)
rwa [← sub_eq_add_neg, sub_self_div_two] at this⟩
protected theorem mul_pos {f g : CauSeq α abs} : Pos f → Pos g → Pos (f * g)
| ⟨_, F0, hF⟩, ⟨_, G0, hG⟩ =>
let ⟨i, h⟩ := exists_forall_ge_and hF hG
⟨_, mul_pos F0 G0, i, fun _ ij =>
let ⟨h₁, h₂⟩ := h _ ij
mul_le_mul h₁ h₂ (le_of_lt G0) (le_trans (le_of_lt F0) h₁)⟩
theorem trichotomy (f : CauSeq α abs) : Pos f ∨ LimZero f ∨ Pos (-f) := by
cases' Classical.em (LimZero f) with h h <;> simp [*]
rcases abv_pos_of_not_limZero h with ⟨K, K0, hK⟩
rcases exists_forall_ge_and hK (f.cauchy₃ K0) with ⟨i, hi⟩
refine (le_total 0 (f i)).imp ?_ ?_ <;>
refine fun h => ⟨K, K0, i, fun j ij => ?_⟩ <;>
have := (hi _ ij).1 <;>
cases' hi _ le_rfl with h₁ h₂
· rwa [abs_of_nonneg] at this
rw [abs_of_nonneg h] at h₁
exact
(le_add_iff_nonneg_right _).1
(le_trans h₁ <| neg_le_sub_iff_le_add'.1 <| le_of_lt (abs_lt.1 <| h₂ _ ij).1)
· rwa [abs_of_nonpos] at this
rw [abs_of_nonpos h] at h₁
rw [← sub_le_sub_iff_right, zero_sub]
exact le_trans (le_of_lt (abs_lt.1 <| h₂ _ ij).2) h₁
instance : LT (CauSeq α abs) :=
⟨fun f g => Pos (g - f)⟩
instance : LE (CauSeq α abs) :=
⟨fun f g => f < g ∨ f ≈ g⟩
theorem lt_of_lt_of_eq {f g h : CauSeq α abs} (fg : f < g) (gh : g ≈ h) : f < h :=
show Pos (h - f) by
convert pos_add_limZero fg (neg_limZero gh) using 1
simp
theorem lt_of_eq_of_lt {f g h : CauSeq α abs} (fg : f ≈ g) (gh : g < h) : f < h := by
have := pos_add_limZero gh (neg_limZero fg)
rwa [← sub_eq_add_neg, sub_sub_sub_cancel_right] at this
theorem lt_trans {f g h : CauSeq α abs} (fg : f < g) (gh : g < h) : f < h :=
show Pos (h - f) by
convert add_pos fg gh using 1
simp
theorem lt_irrefl {f : CauSeq α abs} : ¬f < f
| h => not_limZero_of_pos h (by simp [zero_limZero])
theorem le_of_eq_of_le {f g h : CauSeq α abs} (hfg : f ≈ g) (hgh : g ≤ h) : f ≤ h :=
hgh.elim (Or.inl ∘ CauSeq.lt_of_eq_of_lt hfg) (Or.inr ∘ Setoid.trans hfg)
theorem le_of_le_of_eq {f g h : CauSeq α abs} (hfg : f ≤ g) (hgh : g ≈ h) : f ≤ h :=
hfg.elim (fun h => Or.inl (CauSeq.lt_of_lt_of_eq h hgh)) fun h => Or.inr (Setoid.trans h hgh)
instance : Preorder (CauSeq α abs) where
lt := (· < ·)
le f g := f < g ∨ f ≈ g
le_refl _ := Or.inr (Setoid.refl _)
le_trans _ _ _ fg gh :=
match fg, gh with
| Or.inl fg, Or.inl gh => Or.inl <| lt_trans fg gh
| Or.inl fg, Or.inr gh => Or.inl <| lt_of_lt_of_eq fg gh
| Or.inr fg, Or.inl gh => Or.inl <| lt_of_eq_of_lt fg gh
| Or.inr fg, Or.inr gh => Or.inr <| Setoid.trans fg gh
lt_iff_le_not_le _ _ :=
⟨fun h => ⟨Or.inl h, not_or_of_not (mt (lt_trans h) lt_irrefl) (not_limZero_of_pos h)⟩,
fun ⟨h₁, h₂⟩ => h₁.resolve_right (mt (fun h => Or.inr (Setoid.symm h)) h₂)⟩
theorem le_antisymm {f g : CauSeq α abs} (fg : f ≤ g) (gf : g ≤ f) : f ≈ g :=
fg.resolve_left (not_lt_of_le gf)
theorem lt_total (f g : CauSeq α abs) : f < g ∨ f ≈ g ∨ g < f :=
(trichotomy (g - f)).imp_right fun h =>
h.imp (fun h => Setoid.symm h) fun h => by rwa [neg_sub] at h
theorem le_total (f g : CauSeq α abs) : f ≤ g ∨ g ≤ f :=
(or_assoc.2 (lt_total f g)).imp_right Or.inl
theorem const_lt {x y : α} : const x < const y ↔ x < y :=
show Pos _ ↔ _ by rw [← const_sub, const_pos, sub_pos]
theorem const_le {x y : α} : const x ≤ const y ↔ x ≤ y := by
rw [le_iff_lt_or_eq]; exact or_congr const_lt const_equiv
theorem le_of_exists {f g : CauSeq α abs} (h : ∃ i, ∀ j ≥ i, f j ≤ g j) : f ≤ g :=
let ⟨i, hi⟩ := h
(or_assoc.2 (CauSeq.lt_total f g)).elim id fun hgf =>
False.elim
(let ⟨_, hK0, j, hKj⟩ := hgf
not_lt_of_ge (hi (max i j) (le_max_left _ _))
(sub_pos.1 (lt_of_lt_of_le hK0 (hKj _ (le_max_right _ _)))))
theorem exists_gt (f : CauSeq α abs) : ∃ a : α, f < const a :=
let ⟨K, H⟩ := f.bounded
⟨K + 1, 1, zero_lt_one, 0, fun i _ => by
rw [sub_apply, const_apply, le_sub_iff_add_le', add_le_add_iff_right]
exact le_of_lt (abs_lt.1 (H _)).2⟩
theorem exists_lt (f : CauSeq α abs) : ∃ a : α, const a < f :=
let ⟨a, h⟩ := (-f).exists_gt
⟨-a, show Pos _ by rwa [const_neg, sub_neg_eq_add, add_comm, ← sub_neg_eq_add]⟩
-- so named to match `rat_add_continuous_lemma`
theorem rat_sup_continuous_lemma {ε : α} {a₁ a₂ b₁ b₂ : α} :
abs (a₁ - b₁) < ε → abs (a₂ - b₂) < ε → abs (a₁ ⊔ a₂ - b₁ ⊔ b₂) < ε := fun h₁ h₂ =>
(abs_max_sub_max_le_max _ _ _ _).trans_lt (max_lt h₁ h₂)
-- so named to match `rat_add_continuous_lemma`
theorem rat_inf_continuous_lemma {ε : α} {a₁ a₂ b₁ b₂ : α} :
abs (a₁ - b₁) < ε → abs (a₂ - b₂) < ε → abs (a₁ ⊓ a₂ - b₁ ⊓ b₂) < ε := fun h₁ h₂ =>
(abs_min_sub_min_le_max _ _ _ _).trans_lt (max_lt h₁ h₂)
instance : Sup (CauSeq α abs) :=
⟨fun f g =>
⟨f ⊔ g, fun _ ε0 =>
(exists_forall_ge_and (f.cauchy₃ ε0) (g.cauchy₃ ε0)).imp fun _ H _ ij =>
let ⟨H₁, H₂⟩ := H _ le_rfl
rat_sup_continuous_lemma (H₁ _ ij) (H₂ _ ij)⟩⟩
instance : Inf (CauSeq α abs) :=
⟨fun f g =>
⟨f ⊓ g, fun _ ε0 =>
(exists_forall_ge_and (f.cauchy₃ ε0) (g.cauchy₃ ε0)).imp fun _ H _ ij =>
let ⟨H₁, H₂⟩ := H _ le_rfl
rat_inf_continuous_lemma (H₁ _ ij) (H₂ _ ij)⟩⟩
@[simp, norm_cast]
theorem coe_sup (f g : CauSeq α abs) : ⇑(f ⊔ g) = (f : ℕ → α) ⊔ g :=
rfl
@[simp, norm_cast]
theorem coe_inf (f g : CauSeq α abs) : ⇑(f ⊓ g) = (f : ℕ → α) ⊓ g :=
rfl
theorem sup_limZero {f g : CauSeq α abs} (hf : LimZero f) (hg : LimZero g) : LimZero (f ⊔ g)
| ε, ε0 =>
(exists_forall_ge_and (hf _ ε0) (hg _ ε0)).imp fun i H j ij => by
let ⟨H₁, H₂⟩ := H _ ij
rw [abs_lt] at H₁ H₂ ⊢
exact ⟨lt_sup_iff.mpr (Or.inl H₁.1), sup_lt_iff.mpr ⟨H₁.2, H₂.2⟩⟩
theorem inf_limZero {f g : CauSeq α abs} (hf : LimZero f) (hg : LimZero g) : LimZero (f ⊓ g)
| ε, ε0 =>
(exists_forall_ge_and (hf _ ε0) (hg _ ε0)).imp fun i H j ij => by
let ⟨H₁, H₂⟩ := H _ ij
rw [abs_lt] at H₁ H₂ ⊢
exact ⟨lt_inf_iff.mpr ⟨H₁.1, H₂.1⟩, inf_lt_iff.mpr (Or.inl H₁.2)⟩
theorem sup_equiv_sup {a₁ b₁ a₂ b₂ : CauSeq α abs} (ha : a₁ ≈ a₂) (hb : b₁ ≈ b₂) :
a₁ ⊔ b₁ ≈ a₂ ⊔ b₂ := by
intro ε ε0
obtain ⟨ai, hai⟩ := ha ε ε0
obtain ⟨bi, hbi⟩ := hb ε ε0
exact
⟨ai ⊔ bi, fun i hi =>
(abs_max_sub_max_le_max (a₁ i) (b₁ i) (a₂ i) (b₂ i)).trans_lt
(max_lt (hai i (sup_le_iff.mp hi).1) (hbi i (sup_le_iff.mp hi).2))⟩
theorem inf_equiv_inf {a₁ b₁ a₂ b₂ : CauSeq α abs} (ha : a₁ ≈ a₂) (hb : b₁ ≈ b₂) :
a₁ ⊓ b₁ ≈ a₂ ⊓ b₂ := by
intro ε ε0
obtain ⟨ai, hai⟩ := ha ε ε0
obtain ⟨bi, hbi⟩ := hb ε ε0
exact
⟨ai ⊔ bi, fun i hi =>
(abs_min_sub_min_le_max (a₁ i) (b₁ i) (a₂ i) (b₂ i)).trans_lt
(max_lt (hai i (sup_le_iff.mp hi).1) (hbi i (sup_le_iff.mp hi).2))⟩
protected theorem sup_lt {a b c : CauSeq α abs} (ha : a < c) (hb : b < c) : a ⊔ b < c := by
obtain ⟨⟨εa, εa0, ia, ha⟩, ⟨εb, εb0, ib, hb⟩⟩ := ha, hb
refine ⟨εa ⊓ εb, lt_inf_iff.mpr ⟨εa0, εb0⟩, ia ⊔ ib, fun i hi => ?_⟩
have := min_le_min (ha _ (sup_le_iff.mp hi).1) (hb _ (sup_le_iff.mp hi).2)
exact this.trans_eq (min_sub_sub_left _ _ _)
protected theorem lt_inf {a b c : CauSeq α abs} (hb : a < b) (hc : a < c) : a < b ⊓ c := by
obtain ⟨⟨εb, εb0, ib, hb⟩, ⟨εc, εc0, ic, hc⟩⟩ := hb, hc
refine ⟨εb ⊓ εc, lt_inf_iff.mpr ⟨εb0, εc0⟩, ib ⊔ ic, fun i hi => ?_⟩
have := min_le_min (hb _ (sup_le_iff.mp hi).1) (hc _ (sup_le_iff.mp hi).2)
exact this.trans_eq (min_sub_sub_right _ _ _)
@[simp]
protected theorem sup_idem (a : CauSeq α abs) : a ⊔ a = a := Subtype.ext (sup_idem _)
@[simp]
protected theorem inf_idem (a : CauSeq α abs) : a ⊓ a = a := Subtype.ext (inf_idem _)
protected theorem sup_comm (a b : CauSeq α abs) : a ⊔ b = b ⊔ a := Subtype.ext (sup_comm _ _)
protected theorem inf_comm (a b : CauSeq α abs) : a ⊓ b = b ⊓ a := Subtype.ext (inf_comm _ _)
protected theorem sup_eq_right {a b : CauSeq α abs} (h : a ≤ b) : a ⊔ b ≈ b := by
obtain ⟨ε, ε0 : _ < _, i, h⟩ | h := h
· intro _ _
refine ⟨i, fun j hj => ?_⟩
dsimp
erw [← max_sub_sub_right]
rwa [sub_self, max_eq_right, abs_zero]
rw [sub_nonpos, ← sub_nonneg]
exact ε0.le.trans (h _ hj)
· refine Setoid.trans (sup_equiv_sup h (Setoid.refl _)) ?_
rw [CauSeq.sup_idem]
protected theorem inf_eq_right {a b : CauSeq α abs} (h : b ≤ a) : a ⊓ b ≈ b := by
obtain ⟨ε, ε0 : _ < _, i, h⟩ | h := h
· intro _ _
refine ⟨i, fun j hj => ?_⟩
dsimp
erw [← min_sub_sub_right]
rwa [sub_self, min_eq_right, abs_zero]
exact ε0.le.trans (h _ hj)
· refine Setoid.trans (inf_equiv_inf (Setoid.symm h) (Setoid.refl _)) ?_
rw [CauSeq.inf_idem]
protected theorem sup_eq_left {a b : CauSeq α abs} (h : b ≤ a) : a ⊔ b ≈ a := by
simpa only [CauSeq.sup_comm] using CauSeq.sup_eq_right h
protected theorem inf_eq_left {a b : CauSeq α abs} (h : a ≤ b) : a ⊓ b ≈ a := by
simpa only [CauSeq.inf_comm] using CauSeq.inf_eq_right h
protected theorem le_sup_left {a b : CauSeq α abs} : a ≤ a ⊔ b :=
le_of_exists ⟨0, fun _ _ => le_sup_left⟩
protected theorem inf_le_left {a b : CauSeq α abs} : a ⊓ b ≤ a :=
le_of_exists ⟨0, fun _ _ => inf_le_left⟩
protected theorem le_sup_right {a b : CauSeq α abs} : b ≤ a ⊔ b :=
le_of_exists ⟨0, fun _ _ => le_sup_right⟩
protected theorem inf_le_right {a b : CauSeq α abs} : a ⊓ b ≤ b :=
le_of_exists ⟨0, fun _ _ => inf_le_right⟩
protected theorem sup_le {a b c : CauSeq α abs} (ha : a ≤ c) (hb : b ≤ c) : a ⊔ b ≤ c := by
cases' ha with ha ha
· cases' hb with hb hb
· exact Or.inl (CauSeq.sup_lt ha hb)
· replace ha := le_of_le_of_eq ha.le (Setoid.symm hb)
refine le_of_le_of_eq (Or.inr ?_) hb
exact CauSeq.sup_eq_right ha
· replace hb := le_of_le_of_eq hb (Setoid.symm ha)
refine le_of_le_of_eq (Or.inr ?_) ha
exact CauSeq.sup_eq_left hb
protected theorem le_inf {a b c : CauSeq α abs} (hb : a ≤ b) (hc : a ≤ c) : a ≤ b ⊓ c := by
cases' hb with hb hb
· cases' hc with hc hc
· exact Or.inl (CauSeq.lt_inf hb hc)
· replace hb := le_of_eq_of_le (Setoid.symm hc) hb.le
refine le_of_eq_of_le hc (Or.inr ?_)
exact Setoid.symm (CauSeq.inf_eq_right hb)
· replace hc := le_of_eq_of_le (Setoid.symm hb) hc
refine le_of_eq_of_le hb (Or.inr ?_)
exact Setoid.symm (CauSeq.inf_eq_left hc)
/-! Note that `DistribLattice (CauSeq α abs)` is not true because there is no `PartialOrder`. -/
protected theorem sup_inf_distrib_left (a b c : CauSeq α abs) : a ⊔ b ⊓ c = (a ⊔ b) ⊓ (a ⊔ c) :=
ext fun _ ↦ max_min_distrib_left _ _ _
protected theorem sup_inf_distrib_right (a b c : CauSeq α abs) : a ⊓ b ⊔ c = (a ⊔ c) ⊓ (b ⊔ c) :=
ext fun _ ↦ max_min_distrib_right _ _ _
end Abs
end CauSeq
assert_not_exists Module
|
Algebra\Order\CauSeq\BigOperators.lean | /-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Yaël Dillies
-/
import Mathlib.Algebra.GeomSum
import Mathlib.Algebra.Order.Archimedean.Basic
import Mathlib.Algebra.Order.CauSeq.Basic
/-!
# Cauchy sequences and big operators
This file proves some more lemmas about basic Cauchy sequences that involve finite sums.
-/
open Finset IsAbsoluteValue
namespace IsCauSeq
variable {α β : Type*} [LinearOrderedField α] [Ring β] {abv : β → α} [IsAbsoluteValue abv]
{f g : ℕ → β} {a : ℕ → α}
lemma of_abv_le (n : ℕ) (hm : ∀ m, n ≤ m → abv (f m) ≤ a m) :
IsCauSeq abs (fun n ↦ ∑ i ∈ range n, a i) → IsCauSeq abv fun n ↦ ∑ i ∈ range n, f i := by
intro hg ε ε0
cases' hg (ε / 2) (div_pos ε0 (by norm_num)) with i hi
exists max n i
intro j ji
have hi₁ := hi j (le_trans (le_max_right n i) ji)
have hi₂ := hi (max n i) (le_max_right n i)
have sub_le :=
abs_sub_le (∑ k ∈ range j, a k) (∑ k ∈ range i, a k) (∑ k ∈ range (max n i), a k)
have := add_lt_add hi₁ hi₂
rw [abs_sub_comm (∑ k ∈ range (max n i), a k), add_halves ε] at this
refine lt_of_le_of_lt (le_trans (le_trans ?_ (le_abs_self _)) sub_le) this
generalize hk : j - max n i = k
clear this hi₂ hi₁ hi ε0 ε hg sub_le
rw [tsub_eq_iff_eq_add_of_le ji] at hk
rw [hk]
dsimp only
clear hk ji j
induction' k with k' hi
· simp [abv_zero abv]
simp only [Nat.succ_add, Nat.succ_eq_add_one, Finset.sum_range_succ_comm]
simp only [add_assoc, sub_eq_add_neg]
refine le_trans (abv_add _ _ _) ?_
simp only [sub_eq_add_neg] at hi
exact add_le_add (hm _ (le_add_of_nonneg_of_le (Nat.zero_le _) (le_max_left _ _))) hi
lemma of_abv (hf : IsCauSeq abs fun m ↦ ∑ n ∈ range m, abv (f n)) :
IsCauSeq abv fun m ↦ ∑ n ∈ range m, f n :=
hf.of_abv_le 0 fun _ _ ↦ le_rfl
theorem _root_.cauchy_product (ha : IsCauSeq abs fun m ↦ ∑ n ∈ range m, abv (f n))
(hb : IsCauSeq abv fun m ↦ ∑ n ∈ range m, g n) (ε : α) (ε0 : 0 < ε) :
∃ i : ℕ, ∀ j ≥ i,
abv ((∑ k ∈ range j, f k) * ∑ k ∈ range j, g k -
∑ n ∈ range j, ∑ m ∈ range (n + 1), f m * g (n - m)) < ε := by
let ⟨P, hP⟩ := ha.bounded
let ⟨Q, hQ⟩ := hb.bounded
have hP0 : 0 < P := lt_of_le_of_lt (abs_nonneg _) (hP 0)
have hPε0 : 0 < ε / (2 * P) := div_pos ε0 (mul_pos (show (2 : α) > 0 by norm_num) hP0)
let ⟨N, hN⟩ := hb.cauchy₂ hPε0
have hQε0 : 0 < ε / (4 * Q) :=
div_pos ε0 (mul_pos (show (0 : α) < 4 by norm_num) (lt_of_le_of_lt (abv_nonneg _ _) (hQ 0)))
let ⟨M, hM⟩ := ha.cauchy₂ hQε0
refine ⟨2 * (max N M + 1), fun K hK ↦ ?_⟩
have h₁ :
(∑ m ∈ range K, ∑ k ∈ range (m + 1), f k * g (m - k)) =
∑ m ∈ range K, ∑ n ∈ range (K - m), f m * g n := by
simpa using sum_range_diag_flip K fun m n ↦ f m * g n
have h₂ :
(fun i ↦ ∑ k ∈ range (K - i), f i * g k) = fun i ↦ f i * ∑ k ∈ range (K - i), g k := by
simp [Finset.mul_sum]
have h₃ :
∑ i ∈ range K, f i * ∑ k ∈ range (K - i), g k =
∑ i ∈ range K, f i * (∑ k ∈ range (K - i), g k - ∑ k ∈ range K, g k) +
∑ i ∈ range K, f i * ∑ k ∈ range K, g k := by
rw [← sum_add_distrib]; simp [(mul_add _ _ _).symm]
have two_mul_two : (4 : α) = 2 * 2 := by norm_num
have hQ0 : Q ≠ 0 := fun h ↦ by simp [h, lt_irrefl] at hQε0
have h2Q0 : 2 * Q ≠ 0 := mul_ne_zero two_ne_zero hQ0
have hε : ε / (2 * P) * P + ε / (4 * Q) * (2 * Q) = ε := by
rw [← div_div, div_mul_cancel₀ _ (Ne.symm (ne_of_lt hP0)), two_mul_two, mul_assoc, ← div_div,
div_mul_cancel₀ _ h2Q0, add_halves]
have hNMK : max N M + 1 < K :=
lt_of_lt_of_le (by rw [two_mul]; exact lt_add_of_pos_left _ (Nat.succ_pos _)) hK
have hKN : N < K :=
calc
N ≤ max N M := le_max_left _ _
_ < max N M + 1 := Nat.lt_succ_self _
_ < K := hNMK
have hsumlesum :
(∑ i ∈ range (max N M + 1),
abv (f i) * abv ((∑ k ∈ range (K - i), g k) - ∑ k ∈ range K, g k)) ≤
∑ i ∈ range (max N M + 1), abv (f i) * (ε / (2 * P)) := by
gcongr with m hmJ
refine le_of_lt $ hN (K - m) (le_tsub_of_add_le_left $ hK.trans' ?_) K hKN.le
rw [two_mul]
gcongr
· exact (mem_range.1 hmJ).le
· exact Nat.le_succ_of_le (le_max_left _ _)
have hsumltP : (∑ n ∈ range (max N M + 1), abv (f n)) < P :=
calc
(∑ n ∈ range (max N M + 1), abv (f n)) = |∑ n ∈ range (max N M + 1), abv (f n)| :=
Eq.symm (abs_of_nonneg (sum_nonneg fun x _ ↦ abv_nonneg abv (f x)))
_ < P := hP (max N M + 1)
rw [h₁, h₂, h₃, sum_mul, ← sub_sub, sub_right_comm, sub_self, zero_sub, abv_neg abv]
refine lt_of_le_of_lt (IsAbsoluteValue.abv_sum _ _ _) ?_
suffices
(∑ i ∈ range (max N M + 1),
abv (f i) * abv ((∑ k ∈ range (K - i), g k) - ∑ k ∈ range K, g k)) +
((∑ i ∈ range K, abv (f i) * abv ((∑ k ∈ range (K - i), g k) - ∑ k ∈ range K, g k)) -
∑ i ∈ range (max N M + 1),
abv (f i) * abv ((∑ k ∈ range (K - i), g k) - ∑ k ∈ range K, g k)) <
ε / (2 * P) * P + ε / (4 * Q) * (2 * Q) by
rw [hε] at this
simpa [abv_mul abv] using this
gcongr
· exact lt_of_le_of_lt hsumlesum
(by rw [← sum_mul, mul_comm]; gcongr)
rw [sum_range_sub_sum_range (le_of_lt hNMK)]
calc
(∑ i ∈ (range K).filter fun k ↦ max N M + 1 ≤ k,
abv (f i) * abv ((∑ k ∈ range (K - i), g k) - ∑ k ∈ range K, g k)) ≤
∑ i ∈ (range K).filter fun k ↦ max N M + 1 ≤ k, abv (f i) * (2 * Q) := by
gcongr
rw [sub_eq_add_neg]
refine le_trans (abv_add _ _ _) ?_
rw [two_mul, abv_neg abv]
gcongr <;> exact le_of_lt (hQ _)
_ < ε / (4 * Q) * (2 * Q) := by
rw [← sum_mul, ← sum_range_sub_sum_range (le_of_lt hNMK)]
have := lt_of_le_of_lt (abv_nonneg _ _) (hQ 0)
gcongr
exact (le_abs_self _).trans_lt $ hM _ ((Nat.le_succ_of_le (le_max_right _ _)).trans hNMK.le)
_ $ Nat.le_succ_of_le $ le_max_right _ _
variable [Archimedean α]
lemma of_decreasing_bounded (f : ℕ → α) {a : α} {m : ℕ} (ham : ∀ n ≥ m, |f n| ≤ a)
(hnm : ∀ n ≥ m, f n.succ ≤ f n) : IsCauSeq abs f := fun ε ε0 ↦ by
classical
let ⟨k, hk⟩ := Archimedean.arch a ε0
have h : ∃ l, ∀ n ≥ m, a - l • ε < f n :=
⟨k + k + 1, fun n hnm ↦
lt_of_lt_of_le (show a - (k + (k + 1)) • ε < -|f n| from
lt_neg.1 <| (ham n hnm).trans_lt
(by
rw [neg_sub, lt_sub_iff_add_lt, add_nsmul, add_nsmul, one_nsmul]
exact add_lt_add_of_le_of_lt hk (lt_of_le_of_lt hk (lt_add_of_pos_right _ ε0))))
(neg_le.2 <| abs_neg (f n) ▸ le_abs_self _)⟩
let l := Nat.find h
have hl : ∀ n : ℕ, n ≥ m → f n > a - l • ε := Nat.find_spec h
have hl0 : l ≠ 0 := fun hl0 ↦
not_lt_of_ge (ham m le_rfl)
(lt_of_lt_of_le (by have := hl m (le_refl m); simpa [hl0] using this) (le_abs_self (f m)))
cases' not_forall.1 (Nat.find_min h (Nat.pred_lt hl0)) with i hi
rw [Classical.not_imp, not_lt] at hi
exists i
intro j hj
have hfij : f j ≤ f i := (Nat.rel_of_forall_rel_succ_of_le_of_le (· ≥ ·) hnm hi.1 hj).le
rw [abs_of_nonpos (sub_nonpos.2 hfij), neg_sub, sub_lt_iff_lt_add']
calc
f i ≤ a - Nat.pred l • ε := hi.2
_ = a - l • ε + ε := by
conv =>
rhs
rw [← Nat.succ_pred_eq_of_pos (Nat.pos_of_ne_zero hl0), succ_nsmul, sub_add,
add_sub_cancel_right]
_ < f j + ε := add_lt_add_right (hl j (le_trans hi.1 hj)) _
lemma of_mono_bounded (f : ℕ → α) {a : α} {m : ℕ} (ham : ∀ n ≥ m, |f n| ≤ a)
(hnm : ∀ n ≥ m, f n ≤ f n.succ) : IsCauSeq abs f :=
(of_decreasing_bounded (-f) (a := a) (m := m) (by simpa using ham) $ by simpa using hnm).of_neg
lemma geo_series [Nontrivial β] (x : β) (hx1 : abv x < 1) :
IsCauSeq abv fun n ↦ ∑ m ∈ range n, x ^ m := by
have hx1' : abv x ≠ 1 := fun h ↦ by simp [h, lt_irrefl] at hx1
refine of_abv ?_
simp only [abv_pow abv, geom_sum_eq hx1']
conv in _ / _ => rw [← neg_div_neg_eq, neg_sub, neg_sub]
have : 0 < 1 - abv x := sub_pos.2 hx1
refine @of_mono_bounded _ _ _ _ ((1 : α) / (1 - abv x)) 0 ?_ ?_
· intro n _
rw [abs_of_nonneg]
· gcongr
exact sub_le_self _ (abv_pow abv x n ▸ abv_nonneg _ _)
refine div_nonneg (sub_nonneg.2 ?_) (sub_nonneg.2 <| le_of_lt hx1)
exact pow_le_one _ (by positivity) hx1.le
· intro n _
rw [← one_mul (abv x ^ n), pow_succ']
gcongr
lemma geo_series_const (a : α) {x : α} (hx1 : |x| < 1) :
IsCauSeq abs fun m ↦ ∑ n ∈ range m, (a * x ^ n) := by
simpa [mul_sum, Pi.mul_def] using (const a).mul (geo_series x hx1)
lemma series_ratio_test {f : ℕ → β} (n : ℕ) (r : α) (hr0 : 0 ≤ r) (hr1 : r < 1)
(h : ∀ m, n ≤ m → abv (f m.succ) ≤ r * abv (f m)) :
IsCauSeq abv fun m ↦ ∑ n ∈ range m, f n := by
have har1 : |r| < 1 := by rwa [abs_of_nonneg hr0]
refine (geo_series_const (abv (f n.succ) * r⁻¹ ^ n.succ) har1).of_abv_le n.succ fun m hmn ↦ ?_
obtain rfl | hr := hr0.eq_or_lt
· have m_pos := lt_of_lt_of_le (Nat.succ_pos n) hmn
have := h m.pred (Nat.le_of_succ_le_succ (by rwa [Nat.succ_pred_eq_of_pos m_pos]))
simpa [Nat.sub_add_cancel m_pos, pow_succ] using this
generalize hk : m - n.succ = k
replace hk : m = k + n.succ := (tsub_eq_iff_eq_add_of_le hmn).1 hk
induction' k with k ih generalizing m n
· rw [hk, Nat.zero_add, mul_right_comm, inv_pow _ _, ← div_eq_mul_inv, mul_div_cancel_right₀]
positivity
· have kn : k + n.succ ≥ n.succ := by
rw [← zero_add n.succ]; exact add_le_add (Nat.zero_le _) (by simp)
erw [hk, Nat.succ_add, pow_succ r, ← mul_assoc]
refine
le_trans (by rw [mul_comm] <;> exact h _ (Nat.le_of_succ_le kn))
(mul_le_mul_of_nonneg_right ?_ hr0)
exact ih _ h _ (by simp) rfl
end IsCauSeq
|
Algebra\Order\CauSeq\Completion.lean | /-
Copyright (c) 2018 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Robert Y. Lewis
-/
import Mathlib.Algebra.Order.CauSeq.Basic
import Mathlib.Data.Rat.Cast.Defs
/-!
# Cauchy completion
This file generalizes the Cauchy completion of `(ℚ, abs)` to the completion of a ring
with absolute value.
-/
namespace CauSeq.Completion
open CauSeq
section
variable {α : Type*} [LinearOrderedField α]
variable {β : Type*} [Ring β] (abv : β → α) [IsAbsoluteValue abv]
-- TODO: rename this to `CauSeq.Completion` instead of `CauSeq.Completion.Cauchy`.
/-- The Cauchy completion of a ring with absolute value. -/
def Cauchy :=
@Quotient (CauSeq _ abv) CauSeq.equiv
variable {abv}
/-- The map from Cauchy sequences into the Cauchy completion. -/
def mk : CauSeq _ abv → Cauchy abv :=
Quotient.mk''
@[simp]
theorem mk_eq_mk (f : CauSeq _ abv) : @Eq (Cauchy abv) ⟦f⟧ (mk f) :=
rfl
theorem mk_eq {f g : CauSeq _ abv} : mk f = mk g ↔ f ≈ g :=
Quotient.eq
/-- The map from the original ring into the Cauchy completion. -/
def ofRat (x : β) : Cauchy abv :=
mk (const abv x)
instance : Zero (Cauchy abv) :=
⟨ofRat 0⟩
instance : One (Cauchy abv) :=
⟨ofRat 1⟩
instance : Inhabited (Cauchy abv) :=
⟨0⟩
theorem ofRat_zero : (ofRat 0 : Cauchy abv) = 0 :=
rfl
theorem ofRat_one : (ofRat 1 : Cauchy abv) = 1 :=
rfl
@[simp]
theorem mk_eq_zero {f : CauSeq _ abv} : mk f = 0 ↔ LimZero f := by
have : mk f = 0 ↔ LimZero (f - 0) := Quotient.eq
rwa [sub_zero] at this
instance : Add (Cauchy abv) :=
⟨(Quotient.map₂ (· + ·)) fun _ _ hf _ _ hg => add_equiv_add hf hg⟩
@[simp]
theorem mk_add (f g : CauSeq β abv) : mk f + mk g = mk (f + g) :=
rfl
instance : Neg (Cauchy abv) :=
⟨(Quotient.map Neg.neg) fun _ _ hf => neg_equiv_neg hf⟩
@[simp]
theorem mk_neg (f : CauSeq β abv) : -mk f = mk (-f) :=
rfl
instance : Mul (Cauchy abv) :=
⟨(Quotient.map₂ (· * ·)) fun _ _ hf _ _ hg => mul_equiv_mul hf hg⟩
@[simp]
theorem mk_mul (f g : CauSeq β abv) : mk f * mk g = mk (f * g) :=
rfl
instance : Sub (Cauchy abv) :=
⟨(Quotient.map₂ Sub.sub) fun _ _ hf _ _ hg => sub_equiv_sub hf hg⟩
@[simp]
theorem mk_sub (f g : CauSeq β abv) : mk f - mk g = mk (f - g) :=
rfl
instance {γ : Type*} [SMul γ β] [IsScalarTower γ β β] : SMul γ (Cauchy abv) :=
⟨fun c => (Quotient.map (c • ·)) fun _ _ hf => smul_equiv_smul _ hf⟩
@[simp]
theorem mk_smul {γ : Type*} [SMul γ β] [IsScalarTower γ β β] (c : γ) (f : CauSeq β abv) :
c • mk f = mk (c • f) :=
rfl
instance : Pow (Cauchy abv) ℕ :=
⟨fun x n => Quotient.map (· ^ n) (fun _ _ hf => pow_equiv_pow hf _) x⟩
@[simp]
theorem mk_pow (n : ℕ) (f : CauSeq β abv) : mk f ^ n = mk (f ^ n) :=
rfl
instance : NatCast (Cauchy abv) :=
⟨fun n => mk n⟩
instance : IntCast (Cauchy abv) :=
⟨fun n => mk n⟩
@[simp]
theorem ofRat_natCast (n : ℕ) : (ofRat n : Cauchy abv) = n :=
rfl
@[simp]
theorem ofRat_intCast (z : ℤ) : (ofRat z : Cauchy abv) = z :=
rfl
theorem ofRat_add (x y : β) :
ofRat (x + y) = (ofRat x + ofRat y : Cauchy abv) :=
congr_arg mk (const_add _ _)
theorem ofRat_neg (x : β) : ofRat (-x) = (-ofRat x : Cauchy abv) :=
congr_arg mk (const_neg _)
theorem ofRat_mul (x y : β) :
ofRat (x * y) = (ofRat x * ofRat y : Cauchy abv) :=
congr_arg mk (const_mul _ _)
private theorem zero_def : 0 = mk (abv := abv) 0 :=
rfl
private theorem one_def : 1 = mk (abv := abv) 1 :=
rfl
instance Cauchy.ring : Ring (Cauchy abv) :=
Function.Surjective.ring mk (surjective_quotient_mk' _) zero_def.symm one_def.symm
(fun _ _ => (mk_add _ _).symm) (fun _ _ => (mk_mul _ _).symm) (fun _ => (mk_neg _).symm)
(fun _ _ => (mk_sub _ _).symm) (fun _ _ => (mk_smul _ _).symm) (fun _ _ => (mk_smul _ _).symm)
(fun _ _ => (mk_pow _ _).symm) (fun _ => rfl) fun _ => rfl
/-- `CauSeq.Completion.ofRat` as a `RingHom` -/
@[simps]
def ofRatRingHom : β →+* (Cauchy abv) where
toFun := ofRat
map_zero' := ofRat_zero
map_one' := ofRat_one
map_add' := ofRat_add
map_mul' := ofRat_mul
theorem ofRat_sub (x y : β) : ofRat (x - y) = (ofRat x - ofRat y : Cauchy abv) :=
congr_arg mk (const_sub _ _)
end
section
variable {α : Type*} [LinearOrderedField α]
variable {β : Type*} [CommRing β] {abv : β → α} [IsAbsoluteValue abv]
instance Cauchy.commRing : CommRing (Cauchy abv) :=
Function.Surjective.commRing mk (surjective_quotient_mk' _) zero_def.symm one_def.symm
(fun _ _ => (mk_add _ _).symm) (fun _ _ => (mk_mul _ _).symm) (fun _ => (mk_neg _).symm)
(fun _ _ => (mk_sub _ _).symm) (fun _ _ => (mk_smul _ _).symm) (fun _ _ => (mk_smul _ _).symm)
(fun _ _ => (mk_pow _ _).symm) (fun _ => rfl) fun _ => rfl
end
section
variable {α : Type*} [LinearOrderedField α]
variable {β : Type*} [DivisionRing β] {abv : β → α} [IsAbsoluteValue abv]
instance instNNRatCast : NNRatCast (Cauchy abv) where nnratCast q := ofRat q
instance instRatCast : RatCast (Cauchy abv) where ratCast q := ofRat q
@[simp, norm_cast] lemma ofRat_nnratCast (q : ℚ≥0) : ofRat (q : β) = (q : Cauchy abv) := rfl
@[simp, norm_cast] lemma ofRat_ratCast (q : ℚ) : ofRat (q : β) = (q : Cauchy abv) := rfl
open Classical in
noncomputable instance : Inv (Cauchy abv) :=
⟨fun x =>
(Quotient.liftOn x fun f => mk <| if h : LimZero f then 0 else inv f h) fun f g fg => by
have := limZero_congr fg
by_cases hf : LimZero f
· simp [hf, this.1 hf, Setoid.refl]
· have hg := mt this.2 hf
simp only [hf, dite_false, hg]
have If : mk (inv f hf) * mk f = 1 := mk_eq.2 (inv_mul_cancel hf)
have Ig : mk (inv g hg) * mk g = 1 := mk_eq.2 (inv_mul_cancel hg)
have Ig' : mk g * mk (inv g hg) = 1 := mk_eq.2 (mul_inv_cancel hg)
rw [mk_eq.2 fg, ← Ig] at If
rw [← mul_one (mk (inv f hf)), ← Ig', ← mul_assoc, If, mul_assoc, Ig', mul_one]⟩
-- porting note (#10618): simp can prove this
-- @[simp]
theorem inv_zero : (0 : (Cauchy abv))⁻¹ = 0 :=
congr_arg mk <| by rw [dif_pos] <;> [rfl; exact zero_limZero]
@[simp]
theorem inv_mk {f} (hf) : (mk (abv := abv) f)⁻¹ = mk (inv f hf) :=
congr_arg mk <| by rw [dif_neg]
theorem cau_seq_zero_ne_one : ¬(0 : CauSeq _ abv) ≈ 1 := fun h =>
have : LimZero (1 - 0 : CauSeq _ abv) := Setoid.symm h
have : LimZero (1 : CauSeq _ abv) := by simpa
by apply one_ne_zero <| const_limZero.1 this
theorem zero_ne_one : (0 : (Cauchy abv)) ≠ 1 := fun h => cau_seq_zero_ne_one <| mk_eq.1 h
protected theorem inv_mul_cancel {x : (Cauchy abv)} : x ≠ 0 → x⁻¹ * x = 1 :=
Quotient.inductionOn x fun f hf => by
simp only [mk_eq_mk, ne_eq, mk_eq_zero] at hf
simp only [mk_eq_mk, hf, not_false_eq_true, inv_mk, mk_mul]
exact Quotient.sound (CauSeq.inv_mul_cancel hf)
protected theorem mul_inv_cancel {x : (Cauchy abv)} : x ≠ 0 → x * x⁻¹ = 1 :=
Quotient.inductionOn x fun f hf => by
simp only [mk_eq_mk, ne_eq, mk_eq_zero] at hf
simp only [mk_eq_mk, hf, not_false_eq_true, inv_mk, mk_mul]
exact Quotient.sound (CauSeq.mul_inv_cancel hf)
theorem ofRat_inv (x : β) : ofRat x⁻¹ = ((ofRat x)⁻¹ : (Cauchy abv)) :=
congr_arg mk <| by split_ifs with h <;>
[simp only [const_limZero.1 h, GroupWithZero.inv_zero, const_zero]; rfl]
noncomputable instance instDivInvMonoid : DivInvMonoid (Cauchy abv) where
lemma ofRat_div (x y : β) : ofRat (x / y) = (ofRat x / ofRat y : Cauchy abv) := by
simp only [div_eq_mul_inv, ofRat_inv, ofRat_mul]
/-- The Cauchy completion forms a division ring. -/
noncomputable instance Cauchy.divisionRing : DivisionRing (Cauchy abv) where
exists_pair_ne := ⟨0, 1, zero_ne_one⟩
inv_zero := inv_zero
mul_inv_cancel x := CauSeq.Completion.mul_inv_cancel
nnqsmul := (· • ·)
qsmul := (· • ·)
nnratCast_def q := by simp_rw [← ofRat_nnratCast, NNRat.cast_def, ofRat_div, ofRat_natCast]
ratCast_def q := by rw [← ofRat_ratCast, Rat.cast_def, ofRat_div, ofRat_natCast, ofRat_intCast]
nnqsmul_def q x := Quotient.inductionOn x fun f ↦ congr_arg mk <| ext fun i ↦ NNRat.smul_def _ _
qsmul_def q x := Quotient.inductionOn x fun f ↦ congr_arg mk <| ext fun i ↦ Rat.smul_def _ _
/-- Show the first 10 items of a representative of this equivalence class of cauchy sequences.
The representative chosen is the one passed in the VM to `Quot.mk`, so two cauchy sequences
converging to the same number may be printed differently.
-/
unsafe instance [Repr β] : Repr (Cauchy abv) where
reprPrec r _ :=
let N := 10
let seq := r.unquot
"(sorry /- " ++ Std.Format.joinSep ((List.range N).map <| repr ∘ seq) ", " ++ ", ... -/)"
end
section
variable {α : Type*} [LinearOrderedField α]
variable {β : Type*} [Field β] {abv : β → α} [IsAbsoluteValue abv]
/-- The Cauchy completion forms a field. -/
noncomputable instance Cauchy.field : Field (Cauchy abv) :=
{ Cauchy.divisionRing, Cauchy.commRing with }
end
end CauSeq.Completion
variable {α : Type*} [LinearOrderedField α]
namespace CauSeq
section
variable (β : Type*) [Ring β] (abv : β → α) [IsAbsoluteValue abv]
/-- A class stating that a ring with an absolute value is complete, i.e. every Cauchy
sequence has a limit. -/
class IsComplete : Prop where
/-- Every Cauchy sequence has a limit. -/
isComplete : ∀ s : CauSeq β abv, ∃ b : β, s ≈ const abv b
end
section
variable {β : Type*} [Ring β] {abv : β → α} [IsAbsoluteValue abv]
variable [IsComplete β abv]
theorem complete : ∀ s : CauSeq β abv, ∃ b : β, s ≈ const abv b :=
IsComplete.isComplete
/-- The limit of a Cauchy sequence in a complete ring. Chosen non-computably. -/
noncomputable def lim (s : CauSeq β abv) : β :=
Classical.choose (complete s)
theorem equiv_lim (s : CauSeq β abv) : s ≈ const abv (lim s) :=
Classical.choose_spec (complete s)
theorem eq_lim_of_const_equiv {f : CauSeq β abv} {x : β} (h : CauSeq.const abv x ≈ f) : x = lim f :=
const_equiv.mp <| Setoid.trans h <| equiv_lim f
theorem lim_eq_of_equiv_const {f : CauSeq β abv} {x : β} (h : f ≈ CauSeq.const abv x) : lim f = x :=
(eq_lim_of_const_equiv <| Setoid.symm h).symm
theorem lim_eq_lim_of_equiv {f g : CauSeq β abv} (h : f ≈ g) : lim f = lim g :=
lim_eq_of_equiv_const <| Setoid.trans h <| equiv_lim g
@[simp]
theorem lim_const (x : β) : lim (const abv x) = x :=
lim_eq_of_equiv_const <| Setoid.refl _
theorem lim_add (f g : CauSeq β abv) : lim f + lim g = lim (f + g) :=
eq_lim_of_const_equiv <|
show LimZero (const abv (lim f + lim g) - (f + g)) by
rw [const_add, add_sub_add_comm]
exact add_limZero (Setoid.symm (equiv_lim f)) (Setoid.symm (equiv_lim g))
theorem lim_mul_lim (f g : CauSeq β abv) : lim f * lim g = lim (f * g) :=
eq_lim_of_const_equiv <|
show LimZero (const abv (lim f * lim g) - f * g) by
have h :
const abv (lim f * lim g) - f * g =
(const abv (lim f) - f) * g + const abv (lim f) * (const abv (lim g) - g) := by
apply Subtype.ext
rw [coe_add]
simp [sub_mul, mul_sub]
rw [h]
exact
add_limZero (mul_limZero_left _ (Setoid.symm (equiv_lim _)))
(mul_limZero_right _ (Setoid.symm (equiv_lim _)))
theorem lim_mul (f : CauSeq β abv) (x : β) : lim f * x = lim (f * const abv x) := by
rw [← lim_mul_lim, lim_const]
theorem lim_neg (f : CauSeq β abv) : lim (-f) = -lim f :=
lim_eq_of_equiv_const
(show LimZero (-f - const abv (-lim f)) by
rw [const_neg, sub_neg_eq_add, add_comm, ← sub_eq_add_neg]
exact Setoid.symm (equiv_lim f))
theorem lim_eq_zero_iff (f : CauSeq β abv) : lim f = 0 ↔ LimZero f :=
⟨fun h => by
have hf := equiv_lim f
rw [h] at hf
exact (limZero_congr hf).mpr (const_limZero.mpr rfl),
fun h => by
have h₁ : f = f - const abv 0 := ext fun n => by simp [sub_apply, const_apply]
rw [h₁] at h
exact lim_eq_of_equiv_const h⟩
end
section
variable {β : Type*} [Field β] {abv : β → α} [IsAbsoluteValue abv] [IsComplete β abv]
theorem lim_inv {f : CauSeq β abv} (hf : ¬LimZero f) : lim (inv f hf) = (lim f)⁻¹ :=
have hl : lim f ≠ 0 := by rwa [← lim_eq_zero_iff] at hf
lim_eq_of_equiv_const <|
show LimZero (inv f hf - const abv (lim f)⁻¹) from
have h₁ : ∀ (g f : CauSeq β abv) (hf : ¬LimZero f), LimZero (g - f * inv f hf * g) :=
fun g f hf => by
have h₂ : g - f * inv f hf * g = 1 * g - f * inv f hf * g := by rw [one_mul g]
have h₃ : f * inv f hf * g = (f * inv f hf) * g := by simp [mul_assoc]
have h₄ : g - f * inv f hf * g = (1 - f * inv f hf) * g := by rw [h₂, h₃, ← sub_mul]
have h₅ : g - f * inv f hf * g = g * (1 - f * inv f hf) := by rw [h₄, mul_comm]
have h₆ : g - f * inv f hf * g = g * (1 - inv f hf * f) := by rw [h₅, mul_comm f]
rw [h₆]; exact mul_limZero_right _ (Setoid.symm (CauSeq.inv_mul_cancel _))
have h₂ :
LimZero
(inv f hf - const abv (lim f)⁻¹ -
(const abv (lim f) - f) * (inv f hf * const abv (lim f)⁻¹)) := by
rw [sub_mul, ← sub_add, sub_sub, sub_add_eq_sub_sub, sub_right_comm, sub_add]
show LimZero
(inv f hf - const abv (lim f) * (inv f hf * const abv (lim f)⁻¹) -
(const abv (lim f)⁻¹ - f * (inv f hf * const abv (lim f)⁻¹)))
exact sub_limZero
(by rw [← mul_assoc, mul_right_comm, const_inv hl]; exact h₁ _ _ _)
(by rw [← mul_assoc]; exact h₁ _ _ _)
(limZero_congr h₂).mpr <| mul_limZero_left _ (Setoid.symm (equiv_lim f))
end
section
variable [IsComplete α abs]
theorem lim_le {f : CauSeq α abs} {x : α} (h : f ≤ CauSeq.const abs x) : lim f ≤ x :=
CauSeq.const_le.1 <| CauSeq.le_of_eq_of_le (Setoid.symm (equiv_lim f)) h
theorem le_lim {f : CauSeq α abs} {x : α} (h : CauSeq.const abs x ≤ f) : x ≤ lim f :=
CauSeq.const_le.1 <| CauSeq.le_of_le_of_eq h (equiv_lim f)
theorem lt_lim {f : CauSeq α abs} {x : α} (h : CauSeq.const abs x < f) : x < lim f :=
CauSeq.const_lt.1 <| CauSeq.lt_of_lt_of_eq h (equiv_lim f)
theorem lim_lt {f : CauSeq α abs} {x : α} (h : f < CauSeq.const abs x) : lim f < x :=
CauSeq.const_lt.1 <| CauSeq.lt_of_eq_of_lt (Setoid.symm (equiv_lim f)) h
end
end CauSeq
|
Algebra\Order\Field\Basic.lean | /-
Copyright (c) 2014 Robert Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Lewis, Leonardo de Moura, Mario Carneiro, Floris van Doorn
-/
import Mathlib.Algebra.CharZero.Lemmas
import Mathlib.Algebra.Order.Field.Defs
import Mathlib.Algebra.Order.Ring.Abs
import Mathlib.Order.Bounds.OrderIso
import Mathlib.Tactic.Bound.Attribute
import Mathlib.Tactic.Positivity.Core
import Mathlib.Algebra.Order.Field.Unbundled.Basic
/-!
# Lemmas about linear ordered (semi)fields
-/
open Function OrderDual
variable {ι α β : Type*}
section LinearOrderedSemifield
variable [LinearOrderedSemifield α] {a b c d e : α} {m n : ℤ}
/-- `Equiv.mulLeft₀` as an order_iso. -/
@[simps! (config := { simpRhs := true })]
def OrderIso.mulLeft₀ (a : α) (ha : 0 < a) : α ≃o α :=
{ Equiv.mulLeft₀ a ha.ne' with map_rel_iff' := @fun _ _ => mul_le_mul_left ha }
/-- `Equiv.mulRight₀` as an order_iso. -/
@[simps! (config := { simpRhs := true })]
def OrderIso.mulRight₀ (a : α) (ha : 0 < a) : α ≃o α :=
{ Equiv.mulRight₀ a ha.ne' with map_rel_iff' := @fun _ _ => mul_le_mul_right ha }
/-!
### Relating one division with another term.
-/
theorem le_div_iff (hc : 0 < c) : a ≤ b / c ↔ a * c ≤ b :=
⟨fun h => div_mul_cancel₀ b (ne_of_lt hc).symm ▸ mul_le_mul_of_nonneg_right h hc.le, fun h =>
calc
a = a * c * (1 / c) := mul_mul_div a (ne_of_lt hc).symm
_ ≤ b * (1 / c) := mul_le_mul_of_nonneg_right h (one_div_pos (α := α) |>.2 hc).le
_ = b / c := (div_eq_mul_one_div b c).symm
⟩
theorem le_div_iff' (hc : 0 < c) : a ≤ b / c ↔ c * a ≤ b := by rw [mul_comm, le_div_iff hc]
theorem div_le_iff (hb : 0 < b) : a / b ≤ c ↔ a ≤ c * b :=
⟨fun h =>
calc
a = a / b * b := by rw [div_mul_cancel₀ _ (ne_of_lt hb).symm]
_ ≤ c * b := mul_le_mul_of_nonneg_right h hb.le
,
fun h =>
calc
a / b = a * (1 / b) := div_eq_mul_one_div a b
_ ≤ c * b * (1 / b) := mul_le_mul_of_nonneg_right h (one_div_pos (α := α) |>.2 hb).le
_ = c * b / b := (div_eq_mul_one_div (c * b) b).symm
_ = c := by refine (div_eq_iff (ne_of_gt hb)).mpr rfl
⟩
theorem div_le_iff' (hb : 0 < b) : a / b ≤ c ↔ a ≤ b * c := by rw [mul_comm, div_le_iff hb]
lemma div_le_comm₀ (hb : 0 < b) (hc : 0 < c) : a / b ≤ c ↔ a / c ≤ b := by
rw [div_le_iff hb, div_le_iff' hc]
theorem lt_div_iff (hc : 0 < c) : a < b / c ↔ a * c < b :=
lt_iff_lt_of_le_iff_le <| div_le_iff hc
theorem lt_div_iff' (hc : 0 < c) : a < b / c ↔ c * a < b := by rw [mul_comm, lt_div_iff hc]
theorem div_lt_iff (hc : 0 < c) : b / c < a ↔ b < a * c :=
lt_iff_lt_of_le_iff_le (le_div_iff hc)
theorem div_lt_iff' (hc : 0 < c) : b / c < a ↔ b < c * a := by rw [mul_comm, div_lt_iff hc]
lemma div_lt_comm₀ (hb : 0 < b) (hc : 0 < c) : a / b < c ↔ a / c < b := by
rw [div_lt_iff hb, div_lt_iff' hc]
theorem inv_mul_le_iff (h : 0 < b) : b⁻¹ * a ≤ c ↔ a ≤ b * c := by
rw [inv_eq_one_div, mul_comm, ← div_eq_mul_one_div]
exact div_le_iff' h
theorem inv_mul_le_iff' (h : 0 < b) : b⁻¹ * a ≤ c ↔ a ≤ c * b := by rw [inv_mul_le_iff h, mul_comm]
theorem mul_inv_le_iff (h : 0 < b) : a * b⁻¹ ≤ c ↔ a ≤ b * c := by rw [mul_comm, inv_mul_le_iff h]
theorem mul_inv_le_iff' (h : 0 < b) : a * b⁻¹ ≤ c ↔ a ≤ c * b := by rw [mul_comm, inv_mul_le_iff' h]
theorem div_self_le_one (a : α) : a / a ≤ 1 :=
if h : a = 0 then by simp [h] else by simp [h]
theorem inv_mul_lt_iff (h : 0 < b) : b⁻¹ * a < c ↔ a < b * c := by
rw [inv_eq_one_div, mul_comm, ← div_eq_mul_one_div]
exact div_lt_iff' h
theorem inv_mul_lt_iff' (h : 0 < b) : b⁻¹ * a < c ↔ a < c * b := by rw [inv_mul_lt_iff h, mul_comm]
theorem mul_inv_lt_iff (h : 0 < b) : a * b⁻¹ < c ↔ a < b * c := by rw [mul_comm, inv_mul_lt_iff h]
theorem mul_inv_lt_iff' (h : 0 < b) : a * b⁻¹ < c ↔ a < c * b := by rw [mul_comm, inv_mul_lt_iff' h]
theorem inv_pos_le_iff_one_le_mul (ha : 0 < a) : a⁻¹ ≤ b ↔ 1 ≤ b * a := by
rw [inv_eq_one_div]
exact div_le_iff ha
theorem inv_pos_le_iff_one_le_mul' (ha : 0 < a) : a⁻¹ ≤ b ↔ 1 ≤ a * b := by
rw [inv_eq_one_div]
exact div_le_iff' ha
theorem inv_pos_lt_iff_one_lt_mul (ha : 0 < a) : a⁻¹ < b ↔ 1 < b * a := by
rw [inv_eq_one_div]
exact div_lt_iff ha
theorem inv_pos_lt_iff_one_lt_mul' (ha : 0 < a) : a⁻¹ < b ↔ 1 < a * b := by
rw [inv_eq_one_div]
exact div_lt_iff' ha
/-- One direction of `div_le_iff` where `b` is allowed to be `0` (but `c` must be nonnegative) -/
theorem div_le_of_nonneg_of_le_mul (hb : 0 ≤ b) (hc : 0 ≤ c) (h : a ≤ c * b) : a / b ≤ c := by
rcases eq_or_lt_of_le hb with (rfl | hb')
· simp only [div_zero, hc]
· rwa [div_le_iff hb']
/-- One direction of `div_le_iff` where `c` is allowed to be `0` (but `b` must be nonnegative) -/
lemma mul_le_of_nonneg_of_le_div (hb : 0 ≤ b) (hc : 0 ≤ c) (h : a ≤ b / c) : a * c ≤ b := by
obtain rfl | hc := hc.eq_or_lt
· simpa using hb
· rwa [le_div_iff hc] at h
@[bound]
theorem div_le_one_of_le (h : a ≤ b) (hb : 0 ≤ b) : a / b ≤ 1 :=
div_le_of_nonneg_of_le_mul hb zero_le_one <| by rwa [one_mul]
@[bound]
lemma mul_inv_le_one_of_le (h : a ≤ b) (hb : 0 ≤ b) : a * b⁻¹ ≤ 1 := by
simpa only [← div_eq_mul_inv] using div_le_one_of_le h hb
@[bound]
lemma inv_mul_le_one_of_le (h : a ≤ b) (hb : 0 ≤ b) : b⁻¹ * a ≤ 1 := by
simpa only [← div_eq_inv_mul] using div_le_one_of_le h hb
/-!
### Bi-implications of inequalities using inversions
-/
@[gcongr, bound]
theorem inv_le_inv_of_le (ha : 0 < a) (h : a ≤ b) : b⁻¹ ≤ a⁻¹ := by
rwa [← one_div a, le_div_iff' ha, ← div_eq_mul_inv, div_le_iff (ha.trans_le h), one_mul]
/-- See `inv_le_inv_of_le` for the implication from right-to-left with one fewer assumption. -/
theorem inv_le_inv (ha : 0 < a) (hb : 0 < b) : a⁻¹ ≤ b⁻¹ ↔ b ≤ a := by
rw [← one_div, div_le_iff ha, ← div_eq_inv_mul, le_div_iff hb, one_mul]
/-- In a linear ordered field, for positive `a` and `b` we have `a⁻¹ ≤ b ↔ b⁻¹ ≤ a`.
See also `inv_le_of_inv_le` for a one-sided implication with one fewer assumption. -/
theorem inv_le (ha : 0 < a) (hb : 0 < b) : a⁻¹ ≤ b ↔ b⁻¹ ≤ a := by
rw [← inv_le_inv hb (inv_pos (α := α) |>.2 ha), inv_inv]
theorem inv_le_of_inv_le (ha : 0 < a) (h : a⁻¹ ≤ b) : b⁻¹ ≤ a :=
(inv_le ha ((inv_pos (α := α) |>.2 ha).trans_le h)).1 h
theorem le_inv (ha : 0 < a) (hb : 0 < b) : a ≤ b⁻¹ ↔ b ≤ a⁻¹ := by
rw [← inv_le_inv (inv_pos (α := α) |>.2 hb) ha, inv_inv]
/-- See `inv_lt_inv_of_lt` for the implication from right-to-left with one fewer assumption. -/
theorem inv_lt_inv (ha : 0 < a) (hb : 0 < b) : a⁻¹ < b⁻¹ ↔ b < a :=
lt_iff_lt_of_le_iff_le (inv_le_inv hb ha)
@[gcongr]
theorem inv_lt_inv_of_lt (hb : 0 < b) (h : b < a) : a⁻¹ < b⁻¹ :=
(inv_lt_inv (hb.trans h) hb).2 h
/-- In a linear ordered field, for positive `a` and `b` we have `a⁻¹ < b ↔ b⁻¹ < a`.
See also `inv_lt_of_inv_lt` for a one-sided implication with one fewer assumption. -/
theorem inv_lt (ha : 0 < a) (hb : 0 < b) : a⁻¹ < b ↔ b⁻¹ < a :=
lt_iff_lt_of_le_iff_le (le_inv hb ha)
theorem inv_lt_of_inv_lt (ha : 0 < a) (h : a⁻¹ < b) : b⁻¹ < a :=
(inv_lt ha ((inv_pos (α := α) |>.2 ha).trans h)).1 h
theorem lt_inv (ha : 0 < a) (hb : 0 < b) : a < b⁻¹ ↔ b < a⁻¹ :=
lt_iff_lt_of_le_iff_le (inv_le hb ha)
theorem inv_lt_one (ha : 1 < a) : a⁻¹ < 1 := by
rwa [inv_lt (zero_lt_one.trans ha) zero_lt_one, inv_one]
theorem one_lt_inv (h₁ : 0 < a) (h₂ : a < 1) : 1 < a⁻¹ := by
rwa [lt_inv (@zero_lt_one α _ _ _ _ _) h₁, inv_one]
@[bound]
theorem inv_le_one (ha : 1 ≤ a) : a⁻¹ ≤ 1 := by
rwa [inv_le (zero_lt_one.trans_le ha) zero_lt_one, inv_one]
theorem one_le_inv (h₁ : 0 < a) (h₂ : a ≤ 1) : 1 ≤ a⁻¹ := by
rwa [le_inv (@zero_lt_one α _ _ _ _ _) h₁, inv_one]
theorem inv_lt_one_iff_of_pos (h₀ : 0 < a) : a⁻¹ < 1 ↔ 1 < a :=
⟨fun h₁ => inv_inv a ▸ one_lt_inv (inv_pos (α := α) |>.2 h₀) h₁, inv_lt_one⟩
theorem inv_lt_one_iff : a⁻¹ < 1 ↔ a ≤ 0 ∨ 1 < a := by
rcases le_or_lt a 0 with ha | ha
· simp [ha, (inv_nonpos (α := α) |>.2 ha).trans_lt zero_lt_one]
· simp only [ha.not_le, false_or_iff, inv_lt_one_iff_of_pos ha]
theorem one_lt_inv_iff : 1 < a⁻¹ ↔ 0 < a ∧ a < 1 :=
⟨fun h => ⟨inv_pos (α := α) |>.1 (zero_lt_one.trans h),
inv_inv a ▸ inv_lt_one h⟩, and_imp.2 one_lt_inv⟩
theorem inv_le_one_iff : a⁻¹ ≤ 1 ↔ a ≤ 0 ∨ 1 ≤ a := by
rcases em (a = 1) with (rfl | ha)
· simp [le_rfl]
· simp only [Ne.le_iff_lt (Ne.symm ha), Ne.le_iff_lt (mt inv_eq_one.1 ha), inv_lt_one_iff]
theorem one_le_inv_iff : 1 ≤ a⁻¹ ↔ 0 < a ∧ a ≤ 1 :=
⟨fun h => ⟨inv_pos (α := α) |>.1 (zero_lt_one.trans_le h),
inv_inv a ▸ inv_le_one h⟩, and_imp.2 one_le_inv⟩
/-!
### Relating two divisions.
-/
@[mono, gcongr, bound]
lemma div_le_div_of_nonneg_right (hab : a ≤ b) (hc : 0 ≤ c) : a / c ≤ b / c := by
rw [div_eq_mul_one_div a c, div_eq_mul_one_div b c]
exact mul_le_mul_of_nonneg_right hab (one_div_nonneg (α := α) |>.2 hc)
@[gcongr, bound]
lemma div_lt_div_of_pos_right (h : a < b) (hc : 0 < c) : a / c < b / c := by
rw [div_eq_mul_one_div a c, div_eq_mul_one_div b c]
exact mul_lt_mul_of_pos_right h (one_div_pos (α := α) |>.2 hc)
-- Not a `mono` lemma b/c `div_le_div` is strictly more general
@[gcongr]
lemma div_le_div_of_nonneg_left (ha : 0 ≤ a) (hc : 0 < c) (h : c ≤ b) : a / b ≤ a / c := by
rw [div_eq_mul_inv, div_eq_mul_inv]
exact mul_le_mul_of_nonneg_left ((inv_le_inv (hc.trans_le h) hc).mpr h) ha
@[gcongr, bound]
lemma div_lt_div_of_pos_left (ha : 0 < a) (hc : 0 < c) (h : c < b) : a / b < a / c := by
simpa only [div_eq_mul_inv, mul_lt_mul_left ha, inv_lt_inv (hc.trans h) hc]
@[deprecated (since := "2024-02-16")] alias div_le_div_of_le_of_nonneg := div_le_div_of_nonneg_right
@[deprecated (since := "2024-02-16")] alias div_lt_div_of_lt := div_lt_div_of_pos_right
@[deprecated (since := "2024-02-16")] alias div_le_div_of_le_left := div_le_div_of_nonneg_left
@[deprecated (since := "2024-02-16")] alias div_lt_div_of_lt_left := div_lt_div_of_pos_left
@[deprecated div_le_div_of_nonneg_right (since := "2024-02-16")]
lemma div_le_div_of_le (hc : 0 ≤ c) (hab : a ≤ b) : a / c ≤ b / c :=
div_le_div_of_nonneg_right hab hc
theorem div_le_div_right (hc : 0 < c) : a / c ≤ b / c ↔ a ≤ b :=
⟨le_imp_le_of_lt_imp_lt fun hab ↦ div_lt_div_of_pos_right hab hc,
fun hab ↦ div_le_div_of_nonneg_right hab hc.le⟩
theorem div_lt_div_right (hc : 0 < c) : a / c < b / c ↔ a < b :=
lt_iff_lt_of_le_iff_le <| div_le_div_right hc
theorem div_lt_div_left (ha : 0 < a) (hb : 0 < b) (hc : 0 < c) : a / b < a / c ↔ c < b := by
simp only [div_eq_mul_inv, mul_lt_mul_left ha, inv_lt_inv hb hc]
theorem div_le_div_left (ha : 0 < a) (hb : 0 < b) (hc : 0 < c) : a / b ≤ a / c ↔ c ≤ b :=
le_iff_le_iff_lt_iff_lt.2 (div_lt_div_left ha hc hb)
theorem div_lt_div_iff (b0 : 0 < b) (d0 : 0 < d) : a / b < c / d ↔ a * d < c * b := by
rw [lt_div_iff d0, div_mul_eq_mul_div, div_lt_iff b0]
theorem div_le_div_iff (b0 : 0 < b) (d0 : 0 < d) : a / b ≤ c / d ↔ a * d ≤ c * b := by
rw [le_div_iff d0, div_mul_eq_mul_div, div_le_iff b0]
@[mono, gcongr, bound]
theorem div_le_div (hc : 0 ≤ c) (hac : a ≤ c) (hd : 0 < d) (hbd : d ≤ b) : a / b ≤ c / d := by
rw [div_le_div_iff (hd.trans_le hbd) hd]
exact mul_le_mul hac hbd hd.le hc
@[gcongr]
theorem div_lt_div (hac : a < c) (hbd : d ≤ b) (c0 : 0 ≤ c) (d0 : 0 < d) : a / b < c / d :=
(div_lt_div_iff (d0.trans_le hbd) d0).2 (mul_lt_mul hac hbd d0 c0)
theorem div_lt_div' (hac : a ≤ c) (hbd : d < b) (c0 : 0 < c) (d0 : 0 < d) : a / b < c / d :=
(div_lt_div_iff (d0.trans hbd) d0).2 (mul_lt_mul' hac hbd d0.le c0)
/-!
### Relating one division and involving `1`
-/
@[bound]
theorem div_le_self (ha : 0 ≤ a) (hb : 1 ≤ b) : a / b ≤ a := by
simpa only [div_one] using div_le_div_of_nonneg_left ha zero_lt_one hb
@[bound]
theorem div_lt_self (ha : 0 < a) (hb : 1 < b) : a / b < a := by
simpa only [div_one] using div_lt_div_of_pos_left ha zero_lt_one hb
@[bound]
theorem le_div_self (ha : 0 ≤ a) (hb₀ : 0 < b) (hb₁ : b ≤ 1) : a ≤ a / b := by
simpa only [div_one] using div_le_div_of_nonneg_left ha hb₀ hb₁
theorem one_le_div (hb : 0 < b) : 1 ≤ a / b ↔ b ≤ a := by rw [le_div_iff hb, one_mul]
theorem div_le_one (hb : 0 < b) : a / b ≤ 1 ↔ a ≤ b := by rw [div_le_iff hb, one_mul]
theorem one_lt_div (hb : 0 < b) : 1 < a / b ↔ b < a := by rw [lt_div_iff hb, one_mul]
theorem div_lt_one (hb : 0 < b) : a / b < 1 ↔ a < b := by rw [div_lt_iff hb, one_mul]
theorem one_div_le (ha : 0 < a) (hb : 0 < b) : 1 / a ≤ b ↔ 1 / b ≤ a := by simpa using inv_le ha hb
theorem one_div_lt (ha : 0 < a) (hb : 0 < b) : 1 / a < b ↔ 1 / b < a := by simpa using inv_lt ha hb
theorem le_one_div (ha : 0 < a) (hb : 0 < b) : a ≤ 1 / b ↔ b ≤ 1 / a := by simpa using le_inv ha hb
theorem lt_one_div (ha : 0 < a) (hb : 0 < b) : a < 1 / b ↔ b < 1 / a := by simpa using lt_inv ha hb
@[bound] lemma Bound.one_lt_div_of_pos_of_lt (b0 : 0 < b) : b < a → 1 < a / b := (one_lt_div b0).mpr
@[bound] lemma Bound.div_lt_one_of_pos_of_lt (b0 : 0 < b) : a < b → a / b < 1 := (div_lt_one b0).mpr
/-!
### Relating two divisions, involving `1`
-/
theorem one_div_le_one_div_of_le (ha : 0 < a) (h : a ≤ b) : 1 / b ≤ 1 / a := by
simpa using inv_le_inv_of_le ha h
theorem one_div_lt_one_div_of_lt (ha : 0 < a) (h : a < b) : 1 / b < 1 / a := by
rwa [lt_div_iff' ha, ← div_eq_mul_one_div, div_lt_one (ha.trans h)]
theorem le_of_one_div_le_one_div (ha : 0 < a) (h : 1 / a ≤ 1 / b) : b ≤ a :=
le_imp_le_of_lt_imp_lt (one_div_lt_one_div_of_lt ha) h
theorem lt_of_one_div_lt_one_div (ha : 0 < a) (h : 1 / a < 1 / b) : b < a :=
lt_imp_lt_of_le_imp_le (one_div_le_one_div_of_le ha) h
/-- For the single implications with fewer assumptions, see `one_div_le_one_div_of_le` and
`le_of_one_div_le_one_div` -/
theorem one_div_le_one_div (ha : 0 < a) (hb : 0 < b) : 1 / a ≤ 1 / b ↔ b ≤ a :=
div_le_div_left zero_lt_one ha hb
/-- For the single implications with fewer assumptions, see `one_div_lt_one_div_of_lt` and
`lt_of_one_div_lt_one_div` -/
theorem one_div_lt_one_div (ha : 0 < a) (hb : 0 < b) : 1 / a < 1 / b ↔ b < a :=
div_lt_div_left zero_lt_one ha hb
theorem one_lt_one_div (h1 : 0 < a) (h2 : a < 1) : 1 < 1 / a := by
rwa [lt_one_div (@zero_lt_one α _ _ _ _ _) h1, one_div_one]
theorem one_le_one_div (h1 : 0 < a) (h2 : a ≤ 1) : 1 ≤ 1 / a := by
rwa [le_one_div (@zero_lt_one α _ _ _ _ _) h1, one_div_one]
/-!
### Results about halving.
The equalities also hold in semifields of characteristic `0`.
-/
theorem half_pos (h : 0 < a) : 0 < a / 2 :=
div_pos h zero_lt_two
theorem one_half_pos : (0 : α) < 1 / 2 :=
half_pos zero_lt_one
@[simp]
theorem half_le_self_iff : a / 2 ≤ a ↔ 0 ≤ a := by
rw [div_le_iff (zero_lt_two' α), mul_two, le_add_iff_nonneg_left]
@[simp]
theorem half_lt_self_iff : a / 2 < a ↔ 0 < a := by
rw [div_lt_iff (zero_lt_two' α), mul_two, lt_add_iff_pos_left]
alias ⟨_, half_le_self⟩ := half_le_self_iff
alias ⟨_, half_lt_self⟩ := half_lt_self_iff
alias div_two_lt_of_pos := half_lt_self
theorem one_half_lt_one : (1 / 2 : α) < 1 :=
half_lt_self zero_lt_one
theorem two_inv_lt_one : (2⁻¹ : α) < 1 :=
(one_div _).symm.trans_lt one_half_lt_one
theorem left_lt_add_div_two : a < (a + b) / 2 ↔ a < b := by simp [lt_div_iff, mul_two]
theorem add_div_two_lt_right : (a + b) / 2 < b ↔ a < b := by simp [div_lt_iff, mul_two]
theorem add_thirds (a : α) : a / 3 + a / 3 + a / 3 = a := by
rw [div_add_div_same, div_add_div_same, ← two_mul, ← add_one_mul 2 a, two_add_one_eq_three,
mul_div_cancel_left₀ a three_ne_zero]
/-!
### Miscellaneous lemmas
-/
@[simp] lemma div_pos_iff_of_pos_left (ha : 0 < a) : 0 < a / b ↔ 0 < b := by
simp only [div_eq_mul_inv, mul_pos_iff_of_pos_left ha, inv_pos]
@[simp] lemma div_pos_iff_of_pos_right (hb : 0 < b) : 0 < a / b ↔ 0 < a := by
simp only [div_eq_mul_inv, mul_pos_iff_of_pos_right (inv_pos (α := α) |>.2 hb)]
theorem mul_le_mul_of_mul_div_le (h : a * (b / c) ≤ d) (hc : 0 < c) : b * a ≤ d * c := by
rw [← mul_div_assoc] at h
rwa [mul_comm b, ← div_le_iff hc]
theorem div_mul_le_div_mul_of_div_le_div (h : a / b ≤ c / d) (he : 0 ≤ e) :
a / (b * e) ≤ c / (d * e) := by
rw [div_mul_eq_div_mul_one_div, div_mul_eq_div_mul_one_div]
exact mul_le_mul_of_nonneg_right h (one_div_nonneg (α := α) |>.2 he)
theorem exists_pos_mul_lt {a : α} (h : 0 < a) (b : α) : ∃ c : α, 0 < c ∧ b * c < a := by
have : 0 < a / max (b + 1) 1 := div_pos h (lt_max_iff.2 (Or.inr zero_lt_one))
refine ⟨a / max (b + 1) 1, this, ?_⟩
rw [← lt_div_iff this, div_div_cancel' h.ne']
exact lt_max_iff.2 (Or.inl <| lt_add_one _)
theorem exists_pos_lt_mul {a : α} (h : 0 < a) (b : α) : ∃ c : α, 0 < c ∧ b < c * a :=
let ⟨c, hc₀, hc⟩ := exists_pos_mul_lt h b;
⟨c⁻¹, inv_pos (α := α) |>.2 hc₀, by rwa [← div_eq_inv_mul, lt_div_iff hc₀]⟩
lemma monotone_div_right_of_nonneg (ha : 0 ≤ a) : Monotone (· / a) :=
fun _b _c hbc ↦ div_le_div_of_nonneg_right hbc ha
lemma strictMono_div_right_of_pos (ha : 0 < a) : StrictMono (· / a) :=
fun _b _c hbc ↦ div_lt_div_of_pos_right hbc ha
theorem Monotone.div_const {β : Type*} [Preorder β] {f : β → α} (hf : Monotone f) {c : α}
(hc : 0 ≤ c) : Monotone fun x => f x / c := (monotone_div_right_of_nonneg hc).comp hf
theorem StrictMono.div_const {β : Type*} [Preorder β] {f : β → α} (hf : StrictMono f) {c : α}
(hc : 0 < c) : StrictMono fun x => f x / c := by
simpa only [div_eq_mul_inv] using hf.mul_const (inv_pos (α := α) |>.2 hc)
-- see Note [lower instance priority]
instance (priority := 100) LinearOrderedSemiField.toDenselyOrdered : DenselyOrdered α where
dense a₁ a₂ h :=
⟨(a₁ + a₂) / 2,
calc
a₁ = (a₁ + a₁) / 2 := (add_self_div_two a₁).symm
_ < (a₁ + a₂) / 2 := div_lt_div_of_pos_right (add_lt_add_left h _) zero_lt_two
,
calc
(a₁ + a₂) / 2 < (a₂ + a₂) / 2 := div_lt_div_of_pos_right (add_lt_add_right h _) zero_lt_two
_ = a₂ := add_self_div_two a₂
⟩
theorem min_div_div_right {c : α} (hc : 0 ≤ c) (a b : α) : min (a / c) (b / c) = min a b / c :=
(monotone_div_right_of_nonneg hc).map_min.symm
theorem max_div_div_right {c : α} (hc : 0 ≤ c) (a b : α) : max (a / c) (b / c) = max a b / c :=
(monotone_div_right_of_nonneg hc).map_max.symm
theorem one_div_strictAntiOn : StrictAntiOn (fun x : α => 1 / x) (Set.Ioi 0) :=
fun _ x1 _ y1 xy => (one_div_lt_one_div (Set.mem_Ioi.mp y1) (Set.mem_Ioi.mp x1)).mpr xy
theorem one_div_pow_le_one_div_pow_of_le (a1 : 1 ≤ a) {m n : ℕ} (mn : m ≤ n) :
1 / a ^ n ≤ 1 / a ^ m := by
refine (one_div_le_one_div ?_ ?_).mpr (pow_le_pow_right a1 mn) <;>
exact pow_pos (zero_lt_one.trans_le a1) _
theorem one_div_pow_lt_one_div_pow_of_lt (a1 : 1 < a) {m n : ℕ} (mn : m < n) :
1 / a ^ n < 1 / a ^ m := by
refine (one_div_lt_one_div ?_ ?_).2 (pow_lt_pow_right a1 mn) <;>
exact pow_pos (zero_lt_one.trans a1) _
theorem one_div_pow_anti (a1 : 1 ≤ a) : Antitone fun n : ℕ => 1 / a ^ n := fun _ _ =>
one_div_pow_le_one_div_pow_of_le a1
theorem one_div_pow_strictAnti (a1 : 1 < a) : StrictAnti fun n : ℕ => 1 / a ^ n := fun _ _ =>
one_div_pow_lt_one_div_pow_of_lt a1
theorem inv_strictAntiOn : StrictAntiOn (fun x : α => x⁻¹) (Set.Ioi 0) := fun _ hx _ hy xy =>
(inv_lt_inv hy hx).2 xy
theorem inv_pow_le_inv_pow_of_le (a1 : 1 ≤ a) {m n : ℕ} (mn : m ≤ n) : (a ^ n)⁻¹ ≤ (a ^ m)⁻¹ := by
convert one_div_pow_le_one_div_pow_of_le a1 mn using 1 <;> simp
theorem inv_pow_lt_inv_pow_of_lt (a1 : 1 < a) {m n : ℕ} (mn : m < n) : (a ^ n)⁻¹ < (a ^ m)⁻¹ := by
convert one_div_pow_lt_one_div_pow_of_lt a1 mn using 1 <;> simp
theorem inv_pow_anti (a1 : 1 ≤ a) : Antitone fun n : ℕ => (a ^ n)⁻¹ := fun _ _ =>
inv_pow_le_inv_pow_of_le a1
theorem inv_pow_strictAnti (a1 : 1 < a) : StrictAnti fun n : ℕ => (a ^ n)⁻¹ := fun _ _ =>
inv_pow_lt_inv_pow_of_lt a1
/-! ### Results about `IsGLB` -/
theorem IsGLB.mul_left {s : Set α} (ha : 0 ≤ a) (hs : IsGLB s b) :
IsGLB ((fun b => a * b) '' s) (a * b) := by
rcases lt_or_eq_of_le ha with (ha | rfl)
· exact (OrderIso.mulLeft₀ _ ha).isGLB_image'.2 hs
· simp_rw [zero_mul]
rw [hs.nonempty.image_const]
exact isGLB_singleton
theorem IsGLB.mul_right {s : Set α} (ha : 0 ≤ a) (hs : IsGLB s b) :
IsGLB ((fun b => b * a) '' s) (b * a) := by simpa [mul_comm] using hs.mul_left ha
end LinearOrderedSemifield
section
variable [LinearOrderedField α] {a b c d : α} {n : ℤ}
/-! ### Lemmas about pos, nonneg, nonpos, neg -/
theorem div_pos_iff : 0 < a / b ↔ 0 < a ∧ 0 < b ∨ a < 0 ∧ b < 0 := by
simp only [division_def, mul_pos_iff, inv_pos, inv_lt_zero]
theorem div_neg_iff : a / b < 0 ↔ 0 < a ∧ b < 0 ∨ a < 0 ∧ 0 < b := by
simp [division_def, mul_neg_iff]
theorem div_nonneg_iff : 0 ≤ a / b ↔ 0 ≤ a ∧ 0 ≤ b ∨ a ≤ 0 ∧ b ≤ 0 := by
simp [division_def, mul_nonneg_iff]
theorem div_nonpos_iff : a / b ≤ 0 ↔ 0 ≤ a ∧ b ≤ 0 ∨ a ≤ 0 ∧ 0 ≤ b := by
simp [division_def, mul_nonpos_iff]
theorem div_nonneg_of_nonpos (ha : a ≤ 0) (hb : b ≤ 0) : 0 ≤ a / b :=
div_nonneg_iff.2 <| Or.inr ⟨ha, hb⟩
theorem div_pos_of_neg_of_neg (ha : a < 0) (hb : b < 0) : 0 < a / b :=
div_pos_iff.2 <| Or.inr ⟨ha, hb⟩
theorem div_neg_of_neg_of_pos (ha : a < 0) (hb : 0 < b) : a / b < 0 :=
div_neg_iff.2 <| Or.inr ⟨ha, hb⟩
theorem div_neg_of_pos_of_neg (ha : 0 < a) (hb : b < 0) : a / b < 0 :=
div_neg_iff.2 <| Or.inl ⟨ha, hb⟩
/-! ### Relating one division with another term -/
theorem div_le_iff_of_neg (hc : c < 0) : b / c ≤ a ↔ a * c ≤ b :=
⟨fun h => div_mul_cancel₀ b (ne_of_lt hc) ▸ mul_le_mul_of_nonpos_right h hc.le, fun h =>
calc
a = a * c * (1 / c) := mul_mul_div a (ne_of_lt hc)
_ ≥ b * (1 / c) := mul_le_mul_of_nonpos_right h (one_div_neg (α := α) |>.2 hc).le
_ = b / c := (div_eq_mul_one_div b c).symm
⟩
theorem div_le_iff_of_neg' (hc : c < 0) : b / c ≤ a ↔ c * a ≤ b := by
rw [mul_comm, div_le_iff_of_neg hc]
theorem le_div_iff_of_neg (hc : c < 0) : a ≤ b / c ↔ b ≤ a * c := by
rw [← neg_neg c, mul_neg, div_neg, le_neg, div_le_iff (neg_pos.2 hc), neg_mul]
theorem le_div_iff_of_neg' (hc : c < 0) : a ≤ b / c ↔ b ≤ c * a := by
rw [mul_comm, le_div_iff_of_neg hc]
theorem div_lt_iff_of_neg (hc : c < 0) : b / c < a ↔ a * c < b :=
lt_iff_lt_of_le_iff_le <| le_div_iff_of_neg hc
theorem div_lt_iff_of_neg' (hc : c < 0) : b / c < a ↔ c * a < b := by
rw [mul_comm, div_lt_iff_of_neg hc]
theorem lt_div_iff_of_neg (hc : c < 0) : a < b / c ↔ b < a * c :=
lt_iff_lt_of_le_iff_le <| div_le_iff_of_neg hc
theorem lt_div_iff_of_neg' (hc : c < 0) : a < b / c ↔ b < c * a := by
rw [mul_comm, lt_div_iff_of_neg hc]
theorem div_le_one_of_ge (h : b ≤ a) (hb : b ≤ 0) : a / b ≤ 1 := by
simpa only [neg_div_neg_eq] using div_le_one_of_le (neg_le_neg h) (neg_nonneg_of_nonpos hb)
/-! ### Bi-implications of inequalities using inversions -/
theorem inv_le_inv_of_neg (ha : a < 0) (hb : b < 0) : a⁻¹ ≤ b⁻¹ ↔ b ≤ a := by
rw [← one_div, div_le_iff_of_neg ha, ← div_eq_inv_mul, div_le_iff_of_neg hb, one_mul]
theorem inv_le_of_neg (ha : a < 0) (hb : b < 0) : a⁻¹ ≤ b ↔ b⁻¹ ≤ a := by
rw [← inv_le_inv_of_neg hb (inv_lt_zero (α := α) |>.2 ha), inv_inv]
theorem le_inv_of_neg (ha : a < 0) (hb : b < 0) : a ≤ b⁻¹ ↔ b ≤ a⁻¹ := by
rw [← inv_le_inv_of_neg (inv_lt_zero (α := α) |>.2 hb) ha, inv_inv]
theorem inv_lt_inv_of_neg (ha : a < 0) (hb : b < 0) : a⁻¹ < b⁻¹ ↔ b < a :=
lt_iff_lt_of_le_iff_le (inv_le_inv_of_neg hb ha)
theorem inv_lt_of_neg (ha : a < 0) (hb : b < 0) : a⁻¹ < b ↔ b⁻¹ < a :=
lt_iff_lt_of_le_iff_le (le_inv_of_neg hb ha)
theorem lt_inv_of_neg (ha : a < 0) (hb : b < 0) : a < b⁻¹ ↔ b < a⁻¹ :=
lt_iff_lt_of_le_iff_le (inv_le_of_neg hb ha)
/-!
### Monotonicity results involving inversion
-/
theorem sub_inv_antitoneOn_Ioi :
AntitoneOn (fun x ↦ (x-c)⁻¹) (Set.Ioi c) :=
antitoneOn_iff_forall_lt.mpr fun _ ha _ hb hab ↦
inv_le_inv (sub_pos.mpr hb) (sub_pos.mpr ha) |>.mpr <| sub_le_sub (le_of_lt hab) le_rfl
theorem sub_inv_antitoneOn_Iio :
AntitoneOn (fun x ↦ (x-c)⁻¹) (Set.Iio c) :=
antitoneOn_iff_forall_lt.mpr fun _ ha _ hb hab ↦
inv_le_inv_of_neg (sub_neg.mpr hb) (sub_neg.mpr ha) |>.mpr <| sub_le_sub (le_of_lt hab) le_rfl
theorem sub_inv_antitoneOn_Icc_right (ha : c < a) :
AntitoneOn (fun x ↦ (x-c)⁻¹) (Set.Icc a b) := by
by_cases hab : a ≤ b
· exact sub_inv_antitoneOn_Ioi.mono <| (Set.Icc_subset_Ioi_iff hab).mpr ha
· simp [hab, Set.Subsingleton.antitoneOn]
theorem sub_inv_antitoneOn_Icc_left (ha : b < c) :
AntitoneOn (fun x ↦ (x-c)⁻¹) (Set.Icc a b) := by
by_cases hab : a ≤ b
· exact sub_inv_antitoneOn_Iio.mono <| (Set.Icc_subset_Iio_iff hab).mpr ha
· simp [hab, Set.Subsingleton.antitoneOn]
theorem inv_antitoneOn_Ioi :
AntitoneOn (fun x : α ↦ x⁻¹) (Set.Ioi 0) := by
convert sub_inv_antitoneOn_Ioi
exact (sub_zero _).symm
theorem inv_antitoneOn_Iio :
AntitoneOn (fun x : α ↦ x⁻¹) (Set.Iio 0) := by
convert sub_inv_antitoneOn_Iio
exact (sub_zero _).symm
theorem inv_antitoneOn_Icc_right (ha : 0 < a) :
AntitoneOn (fun x : α ↦ x⁻¹) (Set.Icc a b) := by
convert sub_inv_antitoneOn_Icc_right ha
exact (sub_zero _).symm
theorem inv_antitoneOn_Icc_left (hb : b < 0) :
AntitoneOn (fun x : α ↦ x⁻¹) (Set.Icc a b) := by
convert sub_inv_antitoneOn_Icc_left hb
exact (sub_zero _).symm
/-! ### Relating two divisions -/
theorem div_le_div_of_nonpos_of_le (hc : c ≤ 0) (h : b ≤ a) : a / c ≤ b / c := by
rw [div_eq_mul_one_div a c, div_eq_mul_one_div b c]
exact mul_le_mul_of_nonpos_right h (one_div_nonpos (α := α) |>.2 hc)
theorem div_lt_div_of_neg_of_lt (hc : c < 0) (h : b < a) : a / c < b / c := by
rw [div_eq_mul_one_div a c, div_eq_mul_one_div b c]
exact mul_lt_mul_of_neg_right h (one_div_neg (α := α) |>.2 hc)
theorem div_le_div_right_of_neg (hc : c < 0) : a / c ≤ b / c ↔ b ≤ a :=
⟨le_imp_le_of_lt_imp_lt <| div_lt_div_of_neg_of_lt hc, div_le_div_of_nonpos_of_le <| hc.le⟩
theorem div_lt_div_right_of_neg (hc : c < 0) : a / c < b / c ↔ b < a :=
lt_iff_lt_of_le_iff_le <| div_le_div_right_of_neg hc
/-! ### Relating one division and involving `1` -/
theorem one_le_div_of_neg (hb : b < 0) : 1 ≤ a / b ↔ a ≤ b := by rw [le_div_iff_of_neg hb, one_mul]
theorem div_le_one_of_neg (hb : b < 0) : a / b ≤ 1 ↔ b ≤ a := by rw [div_le_iff_of_neg hb, one_mul]
theorem one_lt_div_of_neg (hb : b < 0) : 1 < a / b ↔ a < b := by rw [lt_div_iff_of_neg hb, one_mul]
theorem div_lt_one_of_neg (hb : b < 0) : a / b < 1 ↔ b < a := by rw [div_lt_iff_of_neg hb, one_mul]
theorem one_div_le_of_neg (ha : a < 0) (hb : b < 0) : 1 / a ≤ b ↔ 1 / b ≤ a := by
simpa using inv_le_of_neg ha hb
theorem one_div_lt_of_neg (ha : a < 0) (hb : b < 0) : 1 / a < b ↔ 1 / b < a := by
simpa using inv_lt_of_neg ha hb
theorem le_one_div_of_neg (ha : a < 0) (hb : b < 0) : a ≤ 1 / b ↔ b ≤ 1 / a := by
simpa using le_inv_of_neg ha hb
theorem lt_one_div_of_neg (ha : a < 0) (hb : b < 0) : a < 1 / b ↔ b < 1 / a := by
simpa using lt_inv_of_neg ha hb
theorem one_lt_div_iff : 1 < a / b ↔ 0 < b ∧ b < a ∨ b < 0 ∧ a < b := by
rcases lt_trichotomy b 0 with (hb | rfl | hb)
· simp [hb, hb.not_lt, one_lt_div_of_neg]
· simp [lt_irrefl, zero_le_one]
· simp [hb, hb.not_lt, one_lt_div]
theorem one_le_div_iff : 1 ≤ a / b ↔ 0 < b ∧ b ≤ a ∨ b < 0 ∧ a ≤ b := by
rcases lt_trichotomy b 0 with (hb | rfl | hb)
· simp [hb, hb.not_lt, one_le_div_of_neg]
· simp [lt_irrefl, zero_lt_one.not_le, zero_lt_one]
· simp [hb, hb.not_lt, one_le_div]
theorem div_lt_one_iff : a / b < 1 ↔ 0 < b ∧ a < b ∨ b = 0 ∨ b < 0 ∧ b < a := by
rcases lt_trichotomy b 0 with (hb | rfl | hb)
· simp [hb, hb.not_lt, hb.ne, div_lt_one_of_neg]
· simp [zero_lt_one]
· simp [hb, hb.not_lt, div_lt_one, hb.ne.symm]
theorem div_le_one_iff : a / b ≤ 1 ↔ 0 < b ∧ a ≤ b ∨ b = 0 ∨ b < 0 ∧ b ≤ a := by
rcases lt_trichotomy b 0 with (hb | rfl | hb)
· simp [hb, hb.not_lt, hb.ne, div_le_one_of_neg]
· simp [zero_le_one]
· simp [hb, hb.not_lt, div_le_one, hb.ne.symm]
/-! ### Relating two divisions, involving `1` -/
theorem one_div_le_one_div_of_neg_of_le (hb : b < 0) (h : a ≤ b) : 1 / b ≤ 1 / a := by
rwa [div_le_iff_of_neg' hb, ← div_eq_mul_one_div, div_le_one_of_neg (h.trans_lt hb)]
theorem one_div_lt_one_div_of_neg_of_lt (hb : b < 0) (h : a < b) : 1 / b < 1 / a := by
rwa [div_lt_iff_of_neg' hb, ← div_eq_mul_one_div, div_lt_one_of_neg (h.trans hb)]
theorem le_of_neg_of_one_div_le_one_div (hb : b < 0) (h : 1 / a ≤ 1 / b) : b ≤ a :=
le_imp_le_of_lt_imp_lt (one_div_lt_one_div_of_neg_of_lt hb) h
theorem lt_of_neg_of_one_div_lt_one_div (hb : b < 0) (h : 1 / a < 1 / b) : b < a :=
lt_imp_lt_of_le_imp_le (one_div_le_one_div_of_neg_of_le hb) h
/-- For the single implications with fewer assumptions, see `one_div_lt_one_div_of_neg_of_lt` and
`lt_of_one_div_lt_one_div` -/
theorem one_div_le_one_div_of_neg (ha : a < 0) (hb : b < 0) : 1 / a ≤ 1 / b ↔ b ≤ a := by
simpa [one_div] using inv_le_inv_of_neg ha hb
/-- For the single implications with fewer assumptions, see `one_div_lt_one_div_of_lt` and
`lt_of_one_div_lt_one_div` -/
theorem one_div_lt_one_div_of_neg (ha : a < 0) (hb : b < 0) : 1 / a < 1 / b ↔ b < a :=
lt_iff_lt_of_le_iff_le (one_div_le_one_div_of_neg hb ha)
theorem one_div_lt_neg_one (h1 : a < 0) (h2 : -1 < a) : 1 / a < -1 :=
suffices 1 / a < 1 / -1 by rwa [one_div_neg_one_eq_neg_one] at this
one_div_lt_one_div_of_neg_of_lt h1 h2
theorem one_div_le_neg_one (h1 : a < 0) (h2 : -1 ≤ a) : 1 / a ≤ -1 :=
suffices 1 / a ≤ 1 / -1 by rwa [one_div_neg_one_eq_neg_one] at this
one_div_le_one_div_of_neg_of_le h1 h2
/-! ### Results about halving -/
theorem sub_self_div_two (a : α) : a - a / 2 = a / 2 := by
suffices a / 2 + a / 2 - a / 2 = a / 2 by rwa [add_halves] at this
rw [add_sub_cancel_right]
theorem div_two_sub_self (a : α) : a / 2 - a = -(a / 2) := by
suffices a / 2 - (a / 2 + a / 2) = -(a / 2) by rwa [add_halves] at this
rw [sub_add_eq_sub_sub, sub_self, zero_sub]
theorem add_sub_div_two_lt (h : a < b) : a + (b - a) / 2 < b := by
rwa [← div_sub_div_same, sub_eq_add_neg, add_comm (b / 2), ← add_assoc, ← sub_eq_add_neg, ←
lt_sub_iff_add_lt, sub_self_div_two, sub_self_div_two, div_lt_div_right (zero_lt_two' α)]
/-- An inequality involving `2`. -/
theorem sub_one_div_inv_le_two (a2 : 2 ≤ a) : (1 - 1 / a)⁻¹ ≤ 2 := by
-- Take inverses on both sides to obtain `2⁻¹ ≤ 1 - 1 / a`
refine (inv_le_inv_of_le (inv_pos (α := α) |>.2 <| zero_lt_two' α) ?_).trans_eq (inv_inv (2 : α))
-- move `1 / a` to the left and `2⁻¹` to the right.
rw [le_sub_iff_add_le, add_comm, ← le_sub_iff_add_le]
-- take inverses on both sides and use the assumption `2 ≤ a`.
convert (one_div a).le.trans (inv_le_inv_of_le zero_lt_two a2) using 1
-- show `1 - 1 / 2 = 1 / 2`.
rw [sub_eq_iff_eq_add, ← two_mul, mul_inv_cancel two_ne_zero]
/-! ### Results about `IsLUB` -/
-- TODO: Generalize to `LinearOrderedSemifield`
theorem IsLUB.mul_left {s : Set α} (ha : 0 ≤ a) (hs : IsLUB s b) :
IsLUB ((fun b => a * b) '' s) (a * b) := by
rcases lt_or_eq_of_le ha with (ha | rfl)
· exact (OrderIso.mulLeft₀ _ ha).isLUB_image'.2 hs
· simp_rw [zero_mul]
rw [hs.nonempty.image_const]
exact isLUB_singleton
-- TODO: Generalize to `LinearOrderedSemifield`
theorem IsLUB.mul_right {s : Set α} (ha : 0 ≤ a) (hs : IsLUB s b) :
IsLUB ((fun b => b * a) '' s) (b * a) := by simpa [mul_comm] using hs.mul_left ha
/-! ### Miscellaneous lemmas -/
theorem mul_sub_mul_div_mul_neg_iff (hc : c ≠ 0) (hd : d ≠ 0) :
(a * d - b * c) / (c * d) < 0 ↔ a / c < b / d := by
rw [mul_comm b c, ← div_sub_div _ _ hc hd, sub_lt_zero]
theorem mul_sub_mul_div_mul_nonpos_iff (hc : c ≠ 0) (hd : d ≠ 0) :
(a * d - b * c) / (c * d) ≤ 0 ↔ a / c ≤ b / d := by
rw [mul_comm b c, ← div_sub_div _ _ hc hd, sub_nonpos]
alias ⟨div_lt_div_of_mul_sub_mul_div_neg, mul_sub_mul_div_mul_neg⟩ := mul_sub_mul_div_mul_neg_iff
alias ⟨div_le_div_of_mul_sub_mul_div_nonpos, mul_sub_mul_div_mul_nonpos⟩ :=
mul_sub_mul_div_mul_nonpos_iff
theorem exists_add_lt_and_pos_of_lt (h : b < a) : ∃ c, b + c < a ∧ 0 < c :=
⟨(a - b) / 2, add_sub_div_two_lt h, div_pos (sub_pos_of_lt h) zero_lt_two⟩
theorem le_of_forall_sub_le (h : ∀ ε > 0, b - ε ≤ a) : b ≤ a := by
contrapose! h
simpa only [@and_comm ((0 : α) < _), lt_sub_iff_add_lt, gt_iff_lt] using
exists_add_lt_and_pos_of_lt h
theorem mul_self_inj_of_nonneg (a0 : 0 ≤ a) (b0 : 0 ≤ b) : a * a = b * b ↔ a = b :=
mul_self_eq_mul_self_iff.trans <|
or_iff_left_of_imp fun h => by
subst a
have : b = 0 := le_antisymm (neg_nonneg.1 a0) b0
rw [this, neg_zero]
theorem min_div_div_right_of_nonpos (hc : c ≤ 0) (a b : α) : min (a / c) (b / c) = max a b / c :=
Eq.symm <| Antitone.map_max fun _ _ => div_le_div_of_nonpos_of_le hc
theorem max_div_div_right_of_nonpos (hc : c ≤ 0) (a b : α) : max (a / c) (b / c) = min a b / c :=
Eq.symm <| Antitone.map_min fun _ _ => div_le_div_of_nonpos_of_le hc
theorem abs_inv (a : α) : |a⁻¹| = |a|⁻¹ :=
map_inv₀ (absHom : α →*₀ α) a
theorem abs_div (a b : α) : |a / b| = |a| / |b| :=
map_div₀ (absHom : α →*₀ α) a b
theorem abs_one_div (a : α) : |1 / a| = 1 / |a| := by rw [abs_div, abs_one]
end
namespace Mathlib.Meta.Positivity
open Lean Meta Qq Function
section LinearOrderedSemifield
variable {α : Type*} [LinearOrderedSemifield α] {a b : α}
private lemma div_nonneg_of_pos_of_nonneg (ha : 0 < a) (hb : 0 ≤ b) : 0 ≤ a / b :=
div_nonneg ha.le hb
private lemma div_nonneg_of_nonneg_of_pos (ha : 0 ≤ a) (hb : 0 < b) : 0 ≤ a / b :=
div_nonneg ha hb.le
private lemma div_ne_zero_of_pos_of_ne_zero (ha : 0 < a) (hb : b ≠ 0) : a / b ≠ 0 :=
div_ne_zero ha.ne' hb
private lemma div_ne_zero_of_ne_zero_of_pos (ha : a ≠ 0) (hb : 0 < b) : a / b ≠ 0 :=
div_ne_zero ha hb.ne'
private lemma zpow_zero_pos (a : α) : 0 < a ^ (0 : ℤ) := zero_lt_one.trans_eq (zpow_zero a).symm
end LinearOrderedSemifield
/-- The `positivity` extension which identifies expressions of the form `a / b`,
such that `positivity` successfully recognises both `a` and `b`. -/
@[positivity _ / _] def evalDiv : PositivityExt where eval {u α} zα pα e := do
let .app (.app (f : Q($α → $α → $α)) (a : Q($α))) (b : Q($α)) ← withReducible (whnf e)
| throwError "not /"
let _e_eq : $e =Q $f $a $b := ⟨⟩
let _a ← synthInstanceQ (q(LinearOrderedSemifield $α) : Q(Type u))
assumeInstancesCommute
let ⟨_f_eq⟩ ← withDefault <| withNewMCtxDepth <| assertDefEqQ (u := u.succ) f q(HDiv.hDiv)
let ra ← core zα pα a; let rb ← core zα pα b
match ra, rb with
| .positive pa, .positive pb => pure (.positive q(div_pos $pa $pb))
| .positive pa, .nonnegative pb => pure (.nonnegative q(div_nonneg_of_pos_of_nonneg $pa $pb))
| .nonnegative pa, .positive pb => pure (.nonnegative q(div_nonneg_of_nonneg_of_pos $pa $pb))
| .nonnegative pa, .nonnegative pb => pure (.nonnegative q(div_nonneg $pa $pb))
| .positive pa, .nonzero pb => pure (.nonzero q(div_ne_zero_of_pos_of_ne_zero $pa $pb))
| .nonzero pa, .positive pb => pure (.nonzero q(div_ne_zero_of_ne_zero_of_pos $pa $pb))
| .nonzero pa, .nonzero pb => pure (.nonzero q(div_ne_zero $pa $pb))
| _, _ => pure .none
/-- The `positivity` extension which identifies expressions of the form `a⁻¹`,
such that `positivity` successfully recognises `a`. -/
@[positivity _⁻¹]
def evalInv : PositivityExt where eval {u α} zα pα e := do
let .app (f : Q($α → $α)) (a : Q($α)) ← withReducible (whnf e) | throwError "not ⁻¹"
let _e_eq : $e =Q $f $a := ⟨⟩
let _a ← synthInstanceQ (q(LinearOrderedSemifield $α) : Q(Type u))
assumeInstancesCommute
let ⟨_f_eq⟩ ← withDefault <| withNewMCtxDepth <| assertDefEqQ (u := u.succ) f q(Inv.inv)
let ra ← core zα pα a
match ra with
| .positive pa => pure (.positive q(inv_pos_of_pos $pa))
| .nonnegative pa => pure (.nonnegative q(inv_nonneg_of_nonneg $pa))
| .nonzero pa => pure (.nonzero q(inv_ne_zero $pa))
| .none => pure .none
/-- The `positivity` extension which identifies expressions of the form `a ^ (0:ℤ)`. -/
@[positivity _ ^ (0 : ℤ), Pow.pow _ (0 : ℤ)]
def evalPowZeroInt : PositivityExt where eval {u α} _zα _pα e := do
let .app (.app _ (a : Q($α))) _ ← withReducible (whnf e) | throwError "not ^"
_ ← synthInstanceQ (q(LinearOrderedSemifield $α) : Q(Type u))
pure (.positive (q(zpow_zero_pos $a) : Expr))
end Mathlib.Meta.Positivity
|
Algebra\Order\Field\Defs.lean | /-
Copyright (c) 2014 Robert Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Lewis, Leonardo de Moura, Mario Carneiro, Floris van Doorn
-/
import Mathlib.Algebra.Order.Ring.Defs
import Mathlib.Algebra.Field.Defs
/-!
# Linear ordered (semi)fields
A linear ordered (semi)field is a (semi)field equipped with a linear order such that
* addition respects the order: `a ≤ b → c + a ≤ c + b`;
* multiplication of positives is positive: `0 < a → 0 < b → 0 < a * b`;
* `0 < 1`.
## Main Definitions
* `LinearOrderedSemifield`: Typeclass for linear order semifields.
* `LinearOrderedField`: Typeclass for linear ordered fields.
-/
-- Guard against import creep.
assert_not_exists MonoidHom
variable {α : Type*}
/-- A linear ordered semifield is a field with a linear order respecting the operations. -/
class LinearOrderedSemifield (α : Type*) extends LinearOrderedCommSemiring α, Semifield α
/-- A linear ordered field is a field with a linear order respecting the operations. -/
class LinearOrderedField (α : Type*) extends LinearOrderedCommRing α, Field α
-- See note [lower instance priority]
instance (priority := 100) LinearOrderedField.toLinearOrderedSemifield [LinearOrderedField α] :
LinearOrderedSemifield α :=
{ LinearOrderedRing.toLinearOrderedSemiring, ‹LinearOrderedField α› with }
|
Algebra\Order\Field\InjSurj.lean | /-
Copyright (c) 2014 Robert Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Lewis, Leonardo de Moura, Mario Carneiro, Floris van Doorn
-/
import Mathlib.Algebra.Field.Basic
import Mathlib.Algebra.Order.Field.Defs
import Mathlib.Algebra.Order.Ring.InjSurj
/-!
# Pulling back linearly ordered fields along injective maps
-/
open Function OrderDual
variable {ι α β : Type*}
namespace Function.Injective
variable [Zero β] [One β] [Add β] [Mul β] [Neg β] [Sub β] [Pow β ℕ] [SMul ℕ β] [SMul ℤ β]
[SMul ℚ≥0 β] [SMul ℚ β] [NatCast β] [IntCast β] [NNRatCast β] [RatCast β] [Inv β] [Div β]
[Pow β ℤ] [Sup β] [Inf β] (f : β → α) (hf : Injective f)
/-- Pullback a `LinearOrderedSemifield` under an injective map. -/
-- See note [reducible non-instances]
abbrev linearOrderedSemifield [LinearOrderedSemifield α] (zero : f 0 = 0) (one : f 1 = 1)
(add : ∀ x y, f (x + y) = f x + f y) (mul : ∀ x y, f (x * y) = f x * f y)
(inv : ∀ x, f x⁻¹ = (f x)⁻¹) (div : ∀ x y, f (x / y) = f x / f y)
(nsmul : ∀ (n : ℕ) (x), f (n • x) = n • f x) (nnqsmul : ∀ (q : ℚ≥0) (x), f (q • x) = q • f x)
(npow : ∀ (x) (n : ℕ), f (x ^ n) = f x ^ n) (zpow : ∀ (x) (n : ℤ), f (x ^ n) = f x ^ n)
(natCast : ∀ n : ℕ, f n = n) (nnratCast : ∀ q : ℚ≥0, f q = q)
(hsup : ∀ x y, f (x ⊔ y) = max (f x) (f y)) (hinf : ∀ x y, f (x ⊓ y) = min (f x) (f y)) :
LinearOrderedSemifield β where
__ := hf.linearOrderedCommSemiring f zero one add mul nsmul npow natCast hsup hinf
__ := hf.semifield f zero one add mul inv div nsmul nnqsmul npow zpow natCast nnratCast
/-- Pullback a `LinearOrderedField` under an injective map. -/
-- See note [reducible non-instances]
abbrev linearOrderedField [LinearOrderedField α] (zero : f 0 = 0) (one : f 1 = 1)
(add : ∀ x y, f (x + y) = f x + f y) (mul : ∀ x y, f (x * y) = f x * f y)
(neg : ∀ x, f (-x) = -f x) (sub : ∀ x y, f (x - y) = f x - f y) (inv : ∀ x, f x⁻¹ = (f x)⁻¹)
(div : ∀ x y, f (x / y) = f x / f y)
(nsmul : ∀ (n : ℕ) (x), f (n • x) = n • f x) (zsmul : ∀ (n : ℤ) (x), f (n • x) = n • f x)
(nnqsmul : ∀ (q : ℚ≥0) (x), f (q • x) = q • f x) (qsmul : ∀ (q : ℚ) (x), f (q • x) = q • f x)
(npow : ∀ (x) (n : ℕ), f (x ^ n) = f x ^ n) (zpow : ∀ (x) (n : ℤ), f (x ^ n) = f x ^ n)
(natCast : ∀ n : ℕ, f n = n) (intCast : ∀ n : ℤ, f n = n) (nnratCast : ∀ q : ℚ≥0, f q = q)
(ratCast : ∀ q : ℚ, f q = q) (hsup : ∀ x y, f (x ⊔ y) = max (f x) (f y))
(hinf : ∀ x y, f (x ⊓ y) = min (f x) (f y)) : LinearOrderedField β where
__ := hf.linearOrderedCommRing f zero one add mul neg sub nsmul zsmul npow natCast intCast
hsup hinf
__ := hf.field f zero one add mul neg sub inv div nsmul zsmul nnqsmul qsmul npow zpow natCast
intCast nnratCast ratCast
end Function.Injective
|
Algebra\Order\Field\Pi.lean | /-
Copyright (c) 2023 Yaël Dillies. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies
-/
import Mathlib.Data.Finset.Lattice
import Mathlib.Data.Fintype.Card
/-!
# Lemmas about (finite domain) functions into fields.
We split this from `Algebra.Order.Field.Basic` to avoid importing the finiteness hierarchy there.
-/
variable {α ι : Type*} [LinearOrderedCancelAddCommMonoid α] [Nontrivial α] [DenselyOrdered α]
theorem Pi.exists_forall_pos_add_lt [ExistsAddOfLE α] [Finite ι] {x y : ι → α}
(h : ∀ i, x i < y i) : ∃ ε, 0 < ε ∧ ∀ i, x i + ε < y i := by
cases nonempty_fintype ι
cases isEmpty_or_nonempty ι
· obtain ⟨a, ha⟩ := exists_ne (0 : α)
obtain ha | ha := ha.lt_or_lt <;> obtain ⟨b, hb, -⟩ := exists_pos_add_of_lt' ha <;>
exact ⟨b, hb, isEmptyElim⟩
choose ε hε hxε using fun i => exists_pos_add_of_lt' (h i)
obtain rfl : x + ε = y := funext hxε
have hε : 0 < Finset.univ.inf' Finset.univ_nonempty ε := (Finset.lt_inf'_iff _).2 fun i _ => hε _
obtain ⟨δ, hδ, hδε⟩ := exists_between hε
exact ⟨δ, hδ, fun i ↦ add_lt_add_left (hδε.trans_le <| Finset.inf'_le _ <| Finset.mem_univ _) _⟩
|
Algebra\Order\Field\Power.lean | /-
Copyright (c) 2014 Robert Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Lewis, Leonardo de Moura, Mario Carneiro, Floris van Doorn
-/
import Mathlib.Algebra.CharZero.Lemmas
import Mathlib.Algebra.GroupWithZero.Commute
import Mathlib.Algebra.Order.Field.Basic
import Mathlib.Algebra.Order.Ring.Pow
import Mathlib.Algebra.Ring.Int
/-!
# Lemmas about powers in ordered fields.
-/
variable {α : Type*}
open Function Int
section LinearOrderedSemifield
variable [LinearOrderedSemifield α] {a b c d e : α} {m n : ℤ}
/-! ### Integer powers -/
@[gcongr]
theorem zpow_le_of_le (ha : 1 ≤ a) (h : m ≤ n) : a ^ m ≤ a ^ n := by
have ha₀ : 0 < a := one_pos.trans_le ha
lift n - m to ℕ using sub_nonneg.2 h with k hk
calc
a ^ m = a ^ m * 1 := (mul_one _).symm
_ ≤ a ^ m * a ^ k :=
mul_le_mul_of_nonneg_left (one_le_pow_of_one_le ha _) (zpow_nonneg ha₀.le _)
_ = a ^ n := by rw [← zpow_natCast, ← zpow_add₀ ha₀.ne', hk, add_sub_cancel]
theorem zpow_le_one_of_nonpos (ha : 1 ≤ a) (hn : n ≤ 0) : a ^ n ≤ 1 :=
(zpow_le_of_le ha hn).trans_eq <| zpow_zero _
theorem one_le_zpow_of_nonneg (ha : 1 ≤ a) (hn : 0 ≤ n) : 1 ≤ a ^ n :=
(zpow_zero _).symm.trans_le <| zpow_le_of_le ha hn
protected theorem Nat.zpow_pos_of_pos {a : ℕ} (h : 0 < a) (n : ℤ) : 0 < (a : α) ^ n := by
apply zpow_pos_of_pos
exact mod_cast h
theorem Nat.zpow_ne_zero_of_pos {a : ℕ} (h : 0 < a) (n : ℤ) : (a : α) ^ n ≠ 0 :=
(Nat.zpow_pos_of_pos h n).ne'
theorem one_lt_zpow (ha : 1 < a) : ∀ n : ℤ, 0 < n → 1 < a ^ n
| (n : ℕ), h => (zpow_natCast _ _).symm.subst (one_lt_pow ha <| Int.natCast_ne_zero.mp h.ne')
| -[_+1], h => ((Int.negSucc_not_pos _).mp h).elim
theorem zpow_strictMono (hx : 1 < a) : StrictMono (a ^ · : ℤ → α) :=
strictMono_int_of_lt_succ fun n =>
have xpos : 0 < a := zero_lt_one.trans hx
calc
a ^ n < a ^ n * a := lt_mul_of_one_lt_right (zpow_pos_of_pos xpos _) hx
_ = a ^ (n + 1) := (zpow_add_one₀ xpos.ne' _).symm
theorem zpow_strictAnti (h₀ : 0 < a) (h₁ : a < 1) : StrictAnti (a ^ · : ℤ → α) :=
strictAnti_int_of_succ_lt fun n =>
calc
a ^ (n + 1) = a ^ n * a := zpow_add_one₀ h₀.ne' _
_ < a ^ n * 1 := (mul_lt_mul_left <| zpow_pos_of_pos h₀ _).2 h₁
_ = a ^ n := mul_one _
@[simp]
theorem zpow_lt_iff_lt (hx : 1 < a) : a ^ m < a ^ n ↔ m < n :=
(zpow_strictMono hx).lt_iff_lt
@[gcongr] alias ⟨_, GCongr.zpow_lt_of_lt⟩ := zpow_lt_iff_lt
@[deprecated (since := "2024-02-10")] alias zpow_lt_of_lt := GCongr.zpow_lt_of_lt
@[simp]
theorem zpow_le_iff_le (hx : 1 < a) : a ^ m ≤ a ^ n ↔ m ≤ n :=
(zpow_strictMono hx).le_iff_le
@[simp]
theorem div_pow_le (ha : 0 ≤ a) (hb : 1 ≤ b) (k : ℕ) : a / b ^ k ≤ a :=
div_le_self ha <| one_le_pow_of_one_le hb _
theorem zpow_injective (h₀ : 0 < a) (h₁ : a ≠ 1) : Injective (a ^ · : ℤ → α) := by
rcases h₁.lt_or_lt with (H | H)
· exact (zpow_strictAnti h₀ H).injective
· exact (zpow_strictMono H).injective
@[simp]
theorem zpow_inj (h₀ : 0 < a) (h₁ : a ≠ 1) : a ^ m = a ^ n ↔ m = n :=
(zpow_injective h₀ h₁).eq_iff
theorem zpow_le_max_of_min_le {x : α} (hx : 1 ≤ x) {a b c : ℤ} (h : min a b ≤ c) :
x ^ (-c) ≤ max (x ^ (-a)) (x ^ (-b)) :=
have : Antitone fun n : ℤ => x ^ (-n) := fun _ _ h => zpow_le_of_le hx (neg_le_neg h)
(this h).trans_eq this.map_min
theorem zpow_le_max_iff_min_le {x : α} (hx : 1 < x) {a b c : ℤ} :
x ^ (-c) ≤ max (x ^ (-a)) (x ^ (-b)) ↔ min a b ≤ c := by
simp_rw [le_max_iff, min_le_iff, zpow_le_iff_le hx, neg_le_neg_iff]
end LinearOrderedSemifield
section LinearOrderedField
variable [LinearOrderedField α] {a b c d : α} {n : ℤ}
protected theorem Even.zpow_nonneg (hn : Even n) (a : α) : 0 ≤ a ^ n := by
obtain ⟨k, rfl⟩ := hn; rw [zpow_add' (by simp [em'])]; exact mul_self_nonneg _
lemma zpow_two_nonneg (a : α) : 0 ≤ a ^ (2 : ℤ) := even_two.zpow_nonneg _
lemma zpow_neg_two_nonneg (a : α) : 0 ≤ a ^ (-2 : ℤ) := even_neg_two.zpow_nonneg _
protected lemma Even.zpow_pos (hn : Even n) (ha : a ≠ 0) : 0 < a ^ n :=
(hn.zpow_nonneg _).lt_of_ne' (zpow_ne_zero _ ha)
lemma zpow_two_pos_of_ne_zero (ha : a ≠ 0) : 0 < a ^ (2 : ℤ) := even_two.zpow_pos ha
theorem Even.zpow_pos_iff (hn : Even n) (h : n ≠ 0) : 0 < a ^ n ↔ a ≠ 0 := by
obtain ⟨k, rfl⟩ := hn
rw [zpow_add' (by simp [em']), mul_self_pos, zpow_ne_zero_iff (by simpa using h)]
theorem Odd.zpow_neg_iff (hn : Odd n) : a ^ n < 0 ↔ a < 0 := by
refine ⟨lt_imp_lt_of_le_imp_le (zpow_nonneg · _), fun ha ↦ ?_⟩
obtain ⟨k, rfl⟩ := hn
rw [zpow_add_one₀ ha.ne]
exact mul_neg_of_pos_of_neg (Even.zpow_pos (even_two_mul _) ha.ne) ha
protected lemma Odd.zpow_nonneg_iff (hn : Odd n) : 0 ≤ a ^ n ↔ 0 ≤ a :=
le_iff_le_iff_lt_iff_lt.2 hn.zpow_neg_iff
theorem Odd.zpow_nonpos_iff (hn : Odd n) : a ^ n ≤ 0 ↔ a ≤ 0 := by
rw [le_iff_lt_or_eq, le_iff_lt_or_eq, hn.zpow_neg_iff, zpow_eq_zero_iff]
rintro rfl
exact Int.odd_iff_not_even.1 hn even_zero
lemma Odd.zpow_pos_iff (hn : Odd n) : 0 < a ^ n ↔ 0 < a := lt_iff_lt_of_le_iff_le hn.zpow_nonpos_iff
alias ⟨_, Odd.zpow_neg⟩ := Odd.zpow_neg_iff
alias ⟨_, Odd.zpow_nonpos⟩ := Odd.zpow_nonpos_iff
theorem Even.zpow_abs {p : ℤ} (hp : Even p) (a : α) : |a| ^ p = a ^ p := by
cases' abs_choice a with h h <;> simp only [h, hp.neg_zpow _]
/-! ### Bernoulli's inequality -/
/-- Bernoulli's inequality reformulated to estimate `(n : α)`. -/
theorem Nat.cast_le_pow_sub_div_sub (H : 1 < a) (n : ℕ) : (n : α) ≤ (a ^ n - 1) / (a - 1) :=
(le_div_iff (sub_pos.2 H)).2 <|
le_sub_left_of_add_le <| one_add_mul_sub_le_pow ((neg_le_self zero_le_one).trans H.le) _
/-- For any `a > 1` and a natural `n` we have `n ≤ a ^ n / (a - 1)`. See also
`Nat.cast_le_pow_sub_div_sub` for a stronger inequality with `a ^ n - 1` in the numerator. -/
theorem Nat.cast_le_pow_div_sub (H : 1 < a) (n : ℕ) : (n : α) ≤ a ^ n / (a - 1) :=
(n.cast_le_pow_sub_div_sub H).trans <|
div_le_div_of_nonneg_right (sub_le_self _ zero_le_one) (sub_nonneg.2 H.le)
end LinearOrderedField
namespace Mathlib.Meta.Positivity
open Lean Meta Qq Function
/-- The `positivity` extension which identifies expressions of the form `a ^ (b : ℤ)`,
such that `positivity` successfully recognises both `a` and `b`. -/
@[positivity _ ^ (_ : ℤ), Pow.pow _ (_ : ℤ)]
def evalZPow : PositivityExt where eval {u α} zα pα e := do
let .app (.app _ (a : Q($α))) (b : Q(ℤ)) ← withReducible (whnf e) | throwError "not ^"
let result ← catchNone do
let _a ← synthInstanceQ q(LinearOrderedField $α)
assumeInstancesCommute
match ← whnfR b with
| .app (.app (.app (.const `OfNat.ofNat _) _) (.lit (Literal.natVal n))) _ =>
guard (n % 2 = 0)
have m : Q(ℕ) := mkRawNatLit (n / 2)
haveI' : $b =Q $m + $m := ⟨⟩
haveI' : $e =Q $a ^ $b := ⟨⟩
pure (.nonnegative q(Even.zpow_nonneg (even_add_self _) $a))
| .app (.app (.app (.const `Neg.neg _) _) _) b' =>
let b' ← whnfR b'
let .true := b'.isAppOfArity ``OfNat.ofNat 3 | throwError "not a ^ -n where n is a literal"
let some n := (b'.getRevArg! 1).rawNatLit? | throwError "not a ^ -n where n is a literal"
guard (n % 2 = 0)
have m : Q(ℕ) := mkRawNatLit (n / 2)
haveI' : $b =Q (-$m) + (-$m) := ⟨⟩
haveI' : $e =Q $a ^ $b := ⟨⟩
pure (.nonnegative q(Even.zpow_nonneg (even_add_self _) $a))
| _ => throwError "not a ^ n where n is a literal or a negated literal"
orElse result do
let ra ← core zα pα a
let ofNonneg (pa : Q(0 ≤ $a)) (_oα : Q(LinearOrderedSemifield $α)) :
MetaM (Strictness zα pα e) := do
haveI' : $e =Q $a ^ $b := ⟨⟩
assumeInstancesCommute
pure (.nonnegative q(zpow_nonneg $pa $b))
let ofNonzero (pa : Q($a ≠ 0)) (_oα : Q(GroupWithZero $α)) : MetaM (Strictness zα pα e) := do
haveI' : $e =Q $a ^ $b := ⟨⟩
let _a ← synthInstanceQ q(GroupWithZero $α)
assumeInstancesCommute
pure (.nonzero q(zpow_ne_zero $b $pa))
match ra with
| .positive pa =>
try
let _a ← synthInstanceQ (q(LinearOrderedSemifield $α) : Q(Type u))
haveI' : $e =Q $a ^ $b := ⟨⟩
assumeInstancesCommute
pure (.positive q(zpow_pos_of_pos $pa $b))
catch e : Exception =>
trace[Tactic.positivity.failure] "{e.toMessageData}"
let oα ← synthInstanceQ q(LinearOrderedSemifield $α)
orElse (← catchNone (ofNonneg q(le_of_lt $pa) oα)) (ofNonzero q(ne_of_gt $pa) oα)
| .nonnegative pa => ofNonneg pa (← synthInstanceQ (_ : Q(Type u)))
| .nonzero pa => ofNonzero pa (← synthInstanceQ (_ : Q(Type u)))
| .none => pure .none
end Mathlib.Meta.Positivity
|
Algebra\Order\Field\Rat.lean | /-
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.Field.Rat
import Mathlib.Algebra.Order.Nonneg.Field
import Mathlib.Algebra.Order.Ring.Rat
import Mathlib.Data.NNRat.Defs
/-!
# The rational numbers form a linear ordered field
This file contains the linear ordered field instance on the rational numbers.
See note [foundational algebra order theory].
## Tags
rat, rationals, field, ℚ, numerator, denominator, num, denom
-/
namespace Rat
instance instLinearOrderedField : LinearOrderedField ℚ where
__ := instLinearOrderedCommRing
__ := instField
end Rat
-- The `LinearOrderedSemifield` and `LinearOrderedCommGroupWithZero` instances are shortcut
-- instances for performance
deriving instance CanonicallyLinearOrderedSemifield, LinearOrderedSemifield,
LinearOrderedCommGroupWithZero for NNRat
/-! ### Miscellaneous lemmas -/
namespace NNRat
@[simp, norm_cast] lemma coe_inv (q : ℚ≥0) : ((q⁻¹ : ℚ≥0) : ℚ) = (q : ℚ)⁻¹ := rfl
@[simp, norm_cast] lemma coe_div (p q : ℚ≥0) : ((p / q : ℚ≥0) : ℚ) = p / q := rfl
lemma inv_def (q : ℚ≥0) : q⁻¹ = divNat q.den q.num := by ext; simp [Rat.inv_def', num_coe, den_coe]
lemma div_def (p q : ℚ≥0) : p / q = divNat (p.num * q.den) (p.den * q.num) := by
ext; simp [Rat.div_def', num_coe, den_coe]
lemma num_inv_of_ne_zero {q : ℚ≥0} (hq : q ≠ 0) : q⁻¹.num = q.den := by
rw [inv_def, divNat, num, coe_mk, Rat.divInt_ofNat, ← Rat.mk_eq_mkRat _ _ (num_ne_zero.mpr hq),
Int.natAbs_ofNat]
simpa using q.coprime_num_den.symm
lemma den_inv_of_ne_zero {q : ℚ≥0} (hq : q ≠ 0) : q⁻¹.den = q.num := by
rw [inv_def, divNat, den, coe_mk, Rat.divInt_ofNat, ← Rat.mk_eq_mkRat _ _ (num_ne_zero.mpr hq)]
simpa using q.coprime_num_den.symm
end NNRat
|
Algebra\Order\Field\Subfield.lean | /-
Copyright (c) 2021 Damiano Testa. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Damiano Testa
-/
import Mathlib.Algebra.Order.Field.InjSurj
import Mathlib.Algebra.Field.Subfield
/-!
# Ordered instances on subfields
-/
namespace SubfieldClass
variable {K S : Type*} [SetLike S K]
-- Prefer subclasses of `Field` over subclasses of `SubfieldClass`.
/-- A subfield of a `LinearOrderedField` is a `LinearOrderedField`. -/
instance (priority := 75) toLinearOrderedField [LinearOrderedField K]
[SubfieldClass S K] (s : S) : LinearOrderedField s :=
Subtype.coe_injective.linearOrderedField (↑) rfl rfl (fun _ _ => rfl)
(fun _ _ => rfl)
(fun _ => rfl) (fun _ _ => rfl) (fun _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl)
(fun _ _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) (by intros; rfl)
(fun _ => rfl) (fun _ => rfl) (fun _ => rfl) (by intros; rfl) (fun _ _ => rfl) fun _ _ => rfl
end SubfieldClass
namespace Subfield
variable {K : Type*}
/-- A subfield of a `LinearOrderedField` is a `LinearOrderedField`. -/
instance toLinearOrderedField [LinearOrderedField K] (s : Subfield K) : LinearOrderedField s :=
Subtype.coe_injective.linearOrderedField (↑) rfl rfl (fun _ _ => rfl) (fun _ _ => rfl)
(fun _ => rfl) (fun _ _ => rfl) (fun _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl)
(fun _ _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) (by intros; rfl)
(fun _ => rfl) (fun _ => rfl) (fun _ => rfl) (by intros; rfl) (fun _ _ => rfl) fun _ _ => rfl
end Subfield
|
Algebra\Order\Field\Canonical\Basic.lean | /-
Copyright (c) 2014 Robert Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Lewis, Leonardo de Moura, Mario Carneiro, Floris van Doorn
-/
import Mathlib.Algebra.Order.Field.Canonical.Defs
/-!
# Lemmas about canonically ordered semifields.
-/
variable {α : Type*}
section CanonicallyLinearOrderedSemifield
variable [CanonicallyLinearOrderedSemifield α] [Sub α] [OrderedSub α]
theorem tsub_div (a b c : α) : (a - b) / c = a / c - b / c := by simp_rw [div_eq_mul_inv, tsub_mul]
end CanonicallyLinearOrderedSemifield
|
Algebra\Order\Field\Canonical\Defs.lean | /-
Copyright (c) 2014 Robert Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Lewis, Leonardo de Moura, Mario Carneiro, Floris van Doorn
-/
import Mathlib.Algebra.Order.Field.Defs
import Mathlib.Algebra.Order.Ring.Canonical
import Mathlib.Algebra.Order.GroupWithZero.Canonical
/-!
# Canonically ordered semifields
-/
variable {α : Type*}
/-- A canonically linear ordered field is a linear ordered field in which `a ≤ b` iff there exists
`c` with `b = a + c`. -/
class CanonicallyLinearOrderedSemifield (α : Type*) extends CanonicallyOrderedCommSemiring α,
LinearOrderedSemifield α
-- See note [lower instance priority]
instance (priority := 100) CanonicallyLinearOrderedSemifield.toLinearOrderedCommGroupWithZero
[CanonicallyLinearOrderedSemifield α] : LinearOrderedCommGroupWithZero α :=
{ ‹CanonicallyLinearOrderedSemifield α› with
mul_le_mul_left := fun a b h c ↦ mul_le_mul_of_nonneg_left h <| zero_le _ }
-- See note [lower instance priority]
instance (priority := 100) CanonicallyLinearOrderedSemifield.toCanonicallyLinearOrderedAddCommMonoid
[CanonicallyLinearOrderedSemifield α] : CanonicallyLinearOrderedAddCommMonoid α :=
{ ‹CanonicallyLinearOrderedSemifield α› with }
|
Algebra\Order\Field\Unbundled\Basic.lean | /-
Copyright (c) 2014 Robert Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Lewis, Leonardo de Moura, Mario Carneiro, Floris van Doorn
-/
import Mathlib.Algebra.Field.Defs
import Mathlib.Algebra.GroupWithZero.Basic
import Mathlib.Algebra.Order.Ring.Unbundled.Basic
/-!
# Basic facts for unbundled linear ordered (semi)fields
-/
-- Guard against import creep.
assert_not_exists OrderedCommMonoid
assert_not_exists MonoidHom
variable {α : Type*}
variable [Semifield α] [LinearOrder α] [PosMulReflectLT α] [ZeroLEOneClass α] {a b : α}
@[simp] lemma inv_pos : 0 < a⁻¹ ↔ 0 < a :=
suffices ∀ a : α, 0 < a → 0 < a⁻¹ from ⟨fun h ↦ inv_inv a ▸ this _ h, this a⟩
fun a ha ↦ flip lt_of_mul_lt_mul_left ha.le <| by simp [ne_of_gt ha, zero_lt_one]
alias ⟨_, inv_pos_of_pos⟩ := inv_pos
@[simp] lemma inv_nonneg : 0 ≤ a⁻¹ ↔ 0 ≤ a := by simp only [le_iff_eq_or_lt, inv_pos, zero_eq_inv]
alias ⟨_, inv_nonneg_of_nonneg⟩ := inv_nonneg
@[simp] lemma inv_lt_zero : a⁻¹ < 0 ↔ a < 0 := by simp only [← not_le, inv_nonneg]
@[simp] lemma inv_nonpos : a⁻¹ ≤ 0 ↔ a ≤ 0 := by simp only [← not_lt, inv_pos]
lemma one_div_pos : 0 < 1 / a ↔ 0 < a := inv_eq_one_div a ▸ inv_pos
lemma one_div_neg : 1 / a < 0 ↔ a < 0 := inv_eq_one_div a ▸ inv_lt_zero
lemma one_div_nonneg : 0 ≤ 1 / a ↔ 0 ≤ a := inv_eq_one_div a ▸ inv_nonneg
lemma one_div_nonpos : 1 / a ≤ 0 ↔ a ≤ 0 := inv_eq_one_div a ▸ inv_nonpos
lemma div_pos [PosMulStrictMono α] (ha : 0 < a) (hb : 0 < b) : 0 < a / b := by
rw [div_eq_mul_inv]; exact mul_pos ha (inv_pos.2 hb)
lemma div_nonneg [PosMulMono α] (ha : 0 ≤ a) (hb : 0 ≤ b) : 0 ≤ a / b := by
rw [div_eq_mul_inv]; exact mul_nonneg ha (inv_nonneg.2 hb)
lemma div_nonpos_of_nonpos_of_nonneg [MulPosMono α] (ha : a ≤ 0) (hb : 0 ≤ b) : a / b ≤ 0 := by
rw [div_eq_mul_inv]; exact mul_nonpos_of_nonpos_of_nonneg ha (inv_nonneg.2 hb)
lemma div_nonpos_of_nonneg_of_nonpos [PosMulMono α] (ha : 0 ≤ a) (hb : b ≤ 0) : a / b ≤ 0 := by
rw [div_eq_mul_inv]; exact mul_nonpos_of_nonneg_of_nonpos ha (inv_nonpos.2 hb)
lemma zpow_nonneg [PosMulMono α] (ha : 0 ≤ a) : ∀ n : ℤ, 0 ≤ a ^ n
| (n : ℕ) => by rw [zpow_natCast]; exact pow_nonneg ha _
| -(n + 1 : ℕ) => by rw [zpow_neg, inv_nonneg, zpow_natCast]; exact pow_nonneg ha _
lemma zpow_pos_of_pos [PosMulStrictMono α] (ha : 0 < a) : ∀ n : ℤ, 0 < a ^ n
| (n : ℕ) => by rw [zpow_natCast]; exact pow_pos ha _
| -(n + 1 : ℕ) => by rw [zpow_neg, inv_pos, zpow_natCast]; exact pow_pos ha _
|
Algebra\Order\Floor\Div.lean | /-
Copyright (c) 2023 Yaël Dillies. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies
-/
import Mathlib.Algebra.GroupWithZero.Action.Pi
import Mathlib.Algebra.Order.Module.Defs
import Mathlib.Algebra.Order.Pi
import Mathlib.Data.Finsupp.Order
import Mathlib.Order.GaloisConnection
/-!
# Flooring, ceiling division
This file defines division rounded up and down.
The setup is an ordered monoid `α` acting on an ordered monoid `β`. If `a : α`, `b : β`, we would
like to be able to "divide" `b` by `a`, namely find `c : β` such that `a • c = b`.
This is of course not always possible, but in some cases at least there is a least `c` such that
`b ≤ a • c` and a greatest `c` such that `a • c ≤ b`. We call the first one the "ceiling division
of `b` by `a`" and the second one the "flooring division of `b` by `a`"
If `α` and `β` are both `ℕ`, then one can check that our flooring and ceiling divisions really are
the floor and ceil of the exact division.
If `α` is `ℕ` and `β` is the functions `ι → ℕ`, then the flooring and ceiling divisions are taken
pointwise.
In order theory terms, those operations are respectively the right and left adjoints to the map
`b ↦ a • b`.
## Main declarations
* `FloorDiv`: Typeclass for the existence of a flooring division, denoted `b ⌊/⌋ a`.
* `CeilDiv`: Typeclass for the existence of a ceiling division, denoted `b ⌈/⌉ a`.
Note in both cases we only allow dividing by positive inputs. We enforce the following junk values:
* `b ⌊/⌋ a = b ⌈/⌉ a = 0` if `a ≤ 0`
* `0 ⌊/⌋ a = 0 ⌈/⌉ a = 0`
## Notation
* `b ⌊/⌋ a` for the flooring division of `b` by `a`
* `b ⌈/⌉ a` for the ceiling division of `b` by `a`
## TODO
* `norm_num` extension
* Prove `⌈a / b⌉ = a ⌈/⌉ b` when `a, b : ℕ`
-/
variable {ι α β : Type*}
section OrderedAddCommMonoid
variable (α β) [OrderedAddCommMonoid α] [OrderedAddCommMonoid β] [SMulZeroClass α β]
/-- Typeclass for division rounded down. For each `a > 0`, this asserts the existence of a right
adjoint to the map `b ↦ a • b : β → β`. -/
class FloorDiv where
/-- Flooring division. If `a > 0`, then `b ⌊/⌋ a` is the greatest `c` such that `a • c ≤ b`. -/
floorDiv : β → α → β
/-- Do not use this. Use `gc_floorDiv_smul` or `gc_floorDiv_mul` instead. -/
protected floorDiv_gc ⦃a⦄ : 0 < a → GaloisConnection (a • ·) (floorDiv · a)
/-- Do not use this. Use `floorDiv_nonpos` instead. -/
protected floorDiv_nonpos ⦃a⦄ : a ≤ 0 → ∀ b, floorDiv b a = 0
/-- Do not use this. Use `zero_floorDiv` instead. -/
protected zero_floorDiv (a) : floorDiv 0 a = 0
/-- Typeclass for division rounded up. For each `a > 0`, this asserts the existence of a left
adjoint to the map `b ↦ a • b : β → β`. -/
class CeilDiv where
/-- Ceiling division. If `a > 0`, then `b ⌈/⌉ a` is the least `c` such that `b ≤ a • c`. -/
ceilDiv : β → α → β
/-- Do not use this. Use `gc_smul_ceilDiv` or `gc_mul_ceilDiv` instead. -/
protected ceilDiv_gc ⦃a⦄ : 0 < a → GaloisConnection (ceilDiv · a) (a • ·)
/-- Do not use this. Use `ceilDiv_nonpos` instead. -/
protected ceilDiv_nonpos ⦃a⦄ : a ≤ 0 → ∀ b, ceilDiv b a = 0
/-- Do not use this. Use `zero_ceilDiv` instead. -/
protected zero_ceilDiv (a) : ceilDiv 0 a = 0
@[inherit_doc] infixl:70 " ⌊/⌋ " => FloorDiv.floorDiv
@[inherit_doc] infixl:70 " ⌈/⌉ " => CeilDiv.ceilDiv
variable {α β}
section FloorDiv
variable [FloorDiv α β] {a : α} {b c : β}
lemma gc_floorDiv_smul (ha : 0 < a) : GaloisConnection (a • · : β → β) (· ⌊/⌋ a) :=
FloorDiv.floorDiv_gc ha
@[simp] lemma le_floorDiv_iff_smul_le (ha : 0 < a) : c ≤ b ⌊/⌋ a ↔ a • c ≤ b :=
(gc_floorDiv_smul ha _ _).symm
@[simp] lemma floorDiv_of_nonpos (ha : a ≤ 0) (b : β) : b ⌊/⌋ a = 0 := FloorDiv.floorDiv_nonpos ha _
lemma floorDiv_zero (b : β) : b ⌊/⌋ (0 : α) = 0 := by simp
@[simp] lemma zero_floorDiv (a : α) : (0 : β) ⌊/⌋ a = 0 := FloorDiv.zero_floorDiv _
lemma smul_floorDiv_le (ha : 0 < a) : a • (b ⌊/⌋ a) ≤ b := (le_floorDiv_iff_smul_le ha).1 le_rfl
end FloorDiv
section CeilDiv
variable [CeilDiv α β] {a : α} {b c : β}
lemma gc_smul_ceilDiv (ha : 0 < a) : GaloisConnection (· ⌈/⌉ a) (a • · : β → β) :=
CeilDiv.ceilDiv_gc ha
@[simp]
lemma ceilDiv_le_iff_le_smul (ha : 0 < a) : b ⌈/⌉ a ≤ c ↔ b ≤ a • c := gc_smul_ceilDiv ha _ _
@[simp] lemma ceilDiv_of_nonpos (ha : a ≤ 0) (b : β) : b ⌈/⌉ a = 0 := CeilDiv.ceilDiv_nonpos ha _
lemma ceilDiv_zero (b : β) : b ⌈/⌉ (0 : α) = 0 := by simp
@[simp] lemma zero_ceilDiv (a : α) : (0 : β) ⌈/⌉ a = 0 := CeilDiv.zero_ceilDiv _
lemma le_smul_ceilDiv (ha : 0 < a) : b ≤ a • (b ⌈/⌉ a) := (ceilDiv_le_iff_le_smul ha).1 le_rfl
end CeilDiv
end OrderedAddCommMonoid
section LinearOrderedAddCommMonoid
variable [LinearOrderedAddCommMonoid α] [OrderedAddCommMonoid β] [SMulZeroClass α β]
[PosSMulReflectLE α β] [FloorDiv α β] [CeilDiv α β] {a : α} {b c : β}
lemma floorDiv_le_ceilDiv : b ⌊/⌋ a ≤ b ⌈/⌉ a := by
obtain ha | ha := le_or_lt a 0
· simp [ha]
· exact le_of_smul_le_smul_left ((smul_floorDiv_le ha).trans $ le_smul_ceilDiv ha) ha
end LinearOrderedAddCommMonoid
section OrderedSemiring
variable [OrderedSemiring α] [OrderedAddCommMonoid β] [MulActionWithZero α β]
section FloorDiv
variable [FloorDiv α β] {a : α}
@[simp] lemma floorDiv_one [Nontrivial α] (b : β) : b ⌊/⌋ (1 : α) = b :=
eq_of_forall_le_iff $ fun c ↦ by simp [zero_lt_one' α]
@[simp] lemma smul_floorDiv [PosSMulMono α β] [PosSMulReflectLE α β] (ha : 0 < a) (b : β) :
a • b ⌊/⌋ a = b :=
eq_of_forall_le_iff $ by simp [smul_le_smul_iff_of_pos_left, ha]
end FloorDiv
section CeilDiv
variable [CeilDiv α β] {a : α}
@[simp] lemma ceilDiv_one [Nontrivial α] (b : β) : b ⌈/⌉ (1 : α) = b :=
eq_of_forall_ge_iff $ fun c ↦ by simp [zero_lt_one' α]
@[simp] lemma smul_ceilDiv [PosSMulMono α β] [PosSMulReflectLE α β] (ha : 0 < a) (b : β) :
a • b ⌈/⌉ a = b :=
eq_of_forall_ge_iff $ by simp [smul_le_smul_iff_of_pos_left, ha]
end CeilDiv
section FloorDiv
variable [FloorDiv α α] {a b c : α}
lemma gc_floorDiv_mul (ha : 0 < a) : GaloisConnection (a * ·) (· ⌊/⌋ a) := gc_floorDiv_smul ha
lemma le_floorDiv_iff_mul_le (ha : 0 < a) : c ≤ b ⌊/⌋ a ↔ a • c ≤ b := le_floorDiv_iff_smul_le ha
end FloorDiv
section CeilDiv
variable [CeilDiv α α] {a b c : α}
lemma gc_mul_ceilDiv (ha : 0 < a) : GaloisConnection (· ⌈/⌉ a) (a * ·) := gc_smul_ceilDiv ha
lemma ceilDiv_le_iff_le_mul (ha : 0 < a) : b ⌈/⌉ a ≤ c ↔ b ≤ a * c := ceilDiv_le_iff_le_smul ha
end CeilDiv
end OrderedSemiring
namespace Nat
instance instFloorDiv : FloorDiv ℕ ℕ where
floorDiv := HDiv.hDiv
floorDiv_gc a ha := by simpa [mul_comm] using Nat.galoisConnection_mul_div ha
floorDiv_nonpos a ha b := by rw [ha.antisymm $ zero_le _, Nat.div_zero]
zero_floorDiv := Nat.zero_div
instance instCeilDiv : CeilDiv ℕ ℕ where
ceilDiv a b := (a + b - 1) / b
ceilDiv_gc a ha b c := by
simp [div_le_iff_le_mul_add_pred ha, add_assoc, tsub_add_cancel_of_le $ succ_le_iff.2 ha]
ceilDiv_nonpos a ha b := by simp_rw [ha.antisymm $ zero_le _, Nat.div_zero]
zero_ceilDiv a := by cases a <;> simp [Nat.div_eq_zero_iff]
@[simp] lemma floorDiv_eq_div (a b : ℕ) : a ⌊/⌋ b = a / b := rfl
lemma ceilDiv_eq_add_pred_div (a b : ℕ) : a ⌈/⌉ b = (a + b - 1) / b := rfl
end Nat
namespace Pi
variable {π : ι → Type*} [OrderedAddCommMonoid α] [∀ i, OrderedAddCommMonoid (π i)]
[∀ i, SMulZeroClass α (π i)]
section FloorDiv
variable [∀ i, FloorDiv α (π i)]
instance instFloorDiv : FloorDiv α (∀ i, π i) where
floorDiv f a i := f i ⌊/⌋ a
floorDiv_gc _a ha _f _g := forall_congr' fun _i ↦ gc_floorDiv_smul ha _ _
floorDiv_nonpos a ha f := by ext i; exact floorDiv_of_nonpos ha _
zero_floorDiv a := by ext i; exact zero_floorDiv a
lemma floorDiv_def (f : ∀ i, π i) (a : α) : f ⌊/⌋ a = fun i ↦ f i ⌊/⌋ a := rfl
@[simp] lemma floorDiv_apply (f : ∀ i, π i) (a : α) (i : ι) : (f ⌊/⌋ a) i = f i ⌊/⌋ a := rfl
end FloorDiv
section CeilDiv
variable [∀ i, CeilDiv α (π i)]
instance instCeilDiv : CeilDiv α (∀ i, π i) where
ceilDiv f a i := f i ⌈/⌉ a
ceilDiv_gc _a ha _f _g := forall_congr' fun _i ↦ gc_smul_ceilDiv ha _ _
ceilDiv_nonpos a ha f := by ext i; exact ceilDiv_of_nonpos ha _
zero_ceilDiv a := by ext; exact zero_ceilDiv _
lemma ceilDiv_def (f : ∀ i, π i) (a : α) : f ⌈/⌉ a = fun i ↦ f i ⌈/⌉ a := rfl
@[simp] lemma ceilDiv_apply (f : ∀ i, π i) (a : α) (i : ι) : (f ⌈/⌉ a) i = f i ⌈/⌉ a := rfl
end CeilDiv
end Pi
namespace Finsupp
variable [OrderedAddCommMonoid α] [OrderedAddCommMonoid β] [SMulZeroClass α β]
section FloorDiv
variable [FloorDiv α β] {f : ι →₀ β} {a : α}
noncomputable instance instFloorDiv : FloorDiv α (ι →₀ β) where
floorDiv f a := f.mapRange (· ⌊/⌋ a) <| zero_floorDiv _
floorDiv_gc _a ha f _g := forall_congr' fun i ↦ by
simpa only [coe_smul, Pi.smul_apply, mapRange_apply] using gc_floorDiv_smul ha (f i) _
floorDiv_nonpos a ha f := by ext i; exact floorDiv_of_nonpos ha _
zero_floorDiv a := by ext; exact zero_floorDiv _
lemma floorDiv_def (f : ι →₀ β) (a : α) : f ⌊/⌋ a = f.mapRange (· ⌊/⌋ a) (zero_floorDiv _) := rfl
@[norm_cast] lemma coe_floorDiv (f : ι →₀ β) (a : α) : f ⌊/⌋ a = fun i ↦ f i ⌊/⌋ a := rfl
@[simp] lemma floorDiv_apply (f : ι →₀ β) (a : α) (i : ι) : (f ⌊/⌋ a) i = f i ⌊/⌋ a := rfl
lemma support_floorDiv_subset : (f ⌊/⌋ a).support ⊆ f.support := by
simp (config := { contextual := true}) [Finset.subset_iff, not_imp_not]
end FloorDiv
section CeilDiv
variable [CeilDiv α β] {f : ι →₀ β} {a : α}
noncomputable instance instCeilDiv : CeilDiv α (ι →₀ β) where
ceilDiv f a := f.mapRange (· ⌈/⌉ a) <| zero_ceilDiv _
ceilDiv_gc _a ha f _g := forall_congr' fun i ↦ by
simpa only [coe_smul, Pi.smul_apply, mapRange_apply] using gc_smul_ceilDiv ha (f i) _
ceilDiv_nonpos a ha f := by ext i; exact ceilDiv_of_nonpos ha _
zero_ceilDiv a := by ext; exact zero_ceilDiv _
lemma ceilDiv_def (f : ι →₀ β) (a : α) : f ⌈/⌉ a = f.mapRange (· ⌈/⌉ a) (zero_ceilDiv _) := rfl
@[norm_cast] lemma coe_ceilDiv_def (f : ι →₀ β) (a : α) : f ⌈/⌉ a = fun i ↦ f i ⌈/⌉ a := rfl
@[simp] lemma ceilDiv_apply (f : ι →₀ β) (a : α) (i : ι) : (f ⌈/⌉ a) i = f i ⌈/⌉ a := rfl
lemma support_ceilDiv_subset : (f ⌈/⌉ a).support ⊆ f.support := by
simp (config := { contextual := true}) [Finset.subset_iff, not_imp_not]
end CeilDiv
end Finsupp
/-- This is the motivating example. -/
noncomputable example : FloorDiv ℕ (ℕ →₀ ℕ) := inferInstance
|
Algebra\Order\Floor\Prime.lean | /-
Copyright (c) 2022 Yuyang Zhao. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yuyang Zhao
-/
import Mathlib.Algebra.Order.Floor
import Mathlib.Data.Nat.Prime.Basic
/-!
# Existence of a sufficiently large prime for which `a * c ^ p / (p - 1)! < 1`
This is a technical result used in the proof of the Lindemann-Weierstrass theorem.
-/
namespace FloorRing
open scoped Nat
variable {K : Type*}
theorem exists_prime_mul_pow_lt_factorial [LinearOrderedRing K] [FloorRing K] (n : ℕ) (a c : K) :
∃ p > n, p.Prime ∧ a * c ^ p < (p - 1)! := by
obtain ⟨p, pn, pp, h⟩ := n.exists_prime_mul_pow_lt_factorial ⌈|a|⌉.natAbs ⌈|c|⌉.natAbs
use p, pn, pp
calc a * c ^ p
_ ≤ |a * c ^ p| := le_abs_self _
_ ≤ ⌈|a|⌉ * (⌈|c|⌉ : K) ^ p := ?_
_ = ↑(Int.natAbs ⌈|a|⌉ * Int.natAbs ⌈|c|⌉ ^ p) := ?_
_ < ↑(p - 1)! := Nat.cast_lt.mpr h
· rw [abs_mul, abs_pow]
gcongr <;> try first | positivity | apply Int.le_ceil
· simp_rw [Nat.cast_mul, Nat.cast_pow, Int.cast_natAbs,
abs_eq_self.mpr (Int.ceil_nonneg (abs_nonneg (_ : K)))]
theorem exists_prime_mul_pow_div_factorial_lt_one [LinearOrderedField K] [FloorRing K]
(n : ℕ) (a c : K) :
∃ p > n, p.Prime ∧ a * c ^ p / (p - 1)! < 1 := by
simp_rw [div_lt_one (α := K) (Nat.cast_pos.mpr (Nat.factorial_pos _))]
exact exists_prime_mul_pow_lt_factorial ..
end FloorRing
|
Algebra\Order\Group\Abs.lean | /-
Copyright (c) 2016 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura, Mario Carneiro, Johannes Hölzl
-/
import Mathlib.Algebra.Order.Group.Defs
import Mathlib.Algebra.Order.Group.Unbundled.Abs
import Mathlib.Algebra.Order.Monoid.Unbundled.Pow
/-!
# Absolute values in ordered groups
The absolute value of an element in a group which is also a lattice is its supremum with its
negation. This generalizes the usual absolute value on real numbers (`|x| = max x (-x)`).
## Notations
- `|a|`: The *absolute value* of an element `a` of an additive lattice ordered group
- `|a|ₘ`: The *absolute value* of an element `a` of a multiplicative lattice ordered group
-/
open Function
variable {α : Type*}
section LinearOrderedCommGroup
variable [LinearOrderedCommGroup α] {a b : α}
@[to_additive] lemma mabs_pow (n : ℕ) (a : α) : |a ^ n|ₘ = |a|ₘ ^ n := by
obtain ha | ha := le_total a 1
· rw [mabs_of_le_one ha, ← mabs_inv, ← inv_pow, mabs_of_one_le]
exact one_le_pow_of_one_le' (one_le_inv'.2 ha) n
· rw [mabs_of_one_le ha, mabs_of_one_le (one_le_pow_of_one_le' ha n)]
@[to_additive] private lemma mabs_mul_eq_mul_mabs_le (hab : a ≤ b) :
|a * b|ₘ = |a|ₘ * |b|ₘ ↔ 1 ≤ a ∧ 1 ≤ b ∨ a ≤ 1 ∧ b ≤ 1 := by
obtain ha | ha := le_or_lt 1 a <;> obtain hb | hb := le_or_lt 1 b
· simp [ha, hb, mabs_of_one_le, one_le_mul ha hb]
· exact (lt_irrefl (1 : α) <| ha.trans_lt <| hab.trans_lt hb).elim
swap
· simp [ha.le, hb.le, mabs_of_le_one, mul_le_one', mul_comm]
have : (|a * b|ₘ = a⁻¹ * b ↔ b ≤ 1) ↔
(|a * b|ₘ = |a|ₘ * |b|ₘ ↔ 1 ≤ a ∧ 1 ≤ b ∨ a ≤ 1 ∧ b ≤ 1) := by
simp [ha.le, ha.not_le, hb, mabs_of_le_one, mabs_of_one_le]
refine this.mp ⟨fun h ↦ ?_, fun h ↦ by simp only [h.antisymm hb, mabs_of_lt_one ha, mul_one]⟩
obtain ab | ab := le_or_lt (a * b) 1
· refine (eq_one_of_inv_eq' ?_).le
rwa [mabs_of_le_one ab, mul_inv_rev, mul_comm, mul_right_inj] at h
· rw [mabs_of_one_lt ab, mul_left_inj] at h
rw [eq_one_of_inv_eq' h.symm] at ha
cases ha.false
@[to_additive] lemma mabs_mul_eq_mul_mabs_iff (a b : α) :
|a * b|ₘ = |a|ₘ * |b|ₘ ↔ 1 ≤ a ∧ 1 ≤ b ∨ a ≤ 1 ∧ b ≤ 1 := by
obtain ab | ab := le_total a b
· exact mabs_mul_eq_mul_mabs_le ab
· simpa only [mul_comm, and_comm] using mabs_mul_eq_mul_mabs_le ab
end LinearOrderedCommGroup
section LinearOrderedAddCommGroup
variable [LinearOrderedAddCommGroup α] {a b c d : α}
-- Porting note:
-- Lean can perfectly well find this instance,
-- but in the rewrites below it is going looking for it without having fixed `α`.
example : CovariantClass α α (swap fun x y ↦ x + y) fun x y ↦ x ≤ y := inferInstance
theorem abs_le : |a| ≤ b ↔ -b ≤ a ∧ a ≤ b := by rw [abs_le', and_comm, @neg_le α]
theorem le_abs' : a ≤ |b| ↔ b ≤ -a ∨ a ≤ b := by rw [le_abs, or_comm, @le_neg α]
theorem neg_le_of_abs_le (h : |a| ≤ b) : -b ≤ a :=
(abs_le.mp h).1
theorem le_of_abs_le (h : |a| ≤ b) : a ≤ b :=
(abs_le.mp h).2
@[to_additive]
theorem apply_abs_le_mul_of_one_le' {β : Type*} [MulOneClass β] [Preorder β]
[CovariantClass β β (· * ·) (· ≤ ·)] [CovariantClass β β (swap (· * ·)) (· ≤ ·)] {f : α → β}
{a : α} (h₁ : 1 ≤ f a) (h₂ : 1 ≤ f (-a)) : f |a| ≤ f a * f (-a) :=
(le_total a 0).rec (fun ha => (abs_of_nonpos ha).symm ▸ le_mul_of_one_le_left' h₁) fun ha =>
(abs_of_nonneg ha).symm ▸ le_mul_of_one_le_right' h₂
@[to_additive]
theorem apply_abs_le_mul_of_one_le {β : Type*} [MulOneClass β] [Preorder β]
[CovariantClass β β (· * ·) (· ≤ ·)] [CovariantClass β β (swap (· * ·)) (· ≤ ·)] {f : α → β}
(h : ∀ x, 1 ≤ f x) (a : α) : f |a| ≤ f a * f (-a) :=
apply_abs_le_mul_of_one_le' (h _) (h _)
/-- The **triangle inequality** in `LinearOrderedAddCommGroup`s. -/
theorem abs_add (a b : α) : |a + b| ≤ |a| + |b| :=
abs_le.2
⟨(neg_add |a| |b|).symm ▸
add_le_add ((@neg_le α ..).2 <| neg_le_abs _) ((@neg_le α ..).2 <| neg_le_abs _),
add_le_add (le_abs_self _) (le_abs_self _)⟩
theorem abs_add' (a b : α) : |a| ≤ |b| + |b + a| := by simpa using abs_add (-b) (b + a)
theorem abs_sub (a b : α) : |a - b| ≤ |a| + |b| := by
rw [sub_eq_add_neg, ← abs_neg b]
exact abs_add a _
theorem abs_sub_le_iff : |a - b| ≤ c ↔ a - b ≤ c ∧ b - a ≤ c := by
rw [abs_le, neg_le_sub_iff_le_add, sub_le_iff_le_add', and_comm, sub_le_iff_le_add']
theorem abs_sub_lt_iff : |a - b| < c ↔ a - b < c ∧ b - a < c := by
rw [@abs_lt α, neg_lt_sub_iff_lt_add', sub_lt_iff_lt_add', and_comm, sub_lt_iff_lt_add']
theorem sub_le_of_abs_sub_le_left (h : |a - b| ≤ c) : b - c ≤ a :=
sub_le_comm.1 <| (abs_sub_le_iff.1 h).2
theorem sub_le_of_abs_sub_le_right (h : |a - b| ≤ c) : a - c ≤ b :=
sub_le_of_abs_sub_le_left (abs_sub_comm a b ▸ h)
theorem sub_lt_of_abs_sub_lt_left (h : |a - b| < c) : b - c < a :=
sub_lt_comm.1 <| (abs_sub_lt_iff.1 h).2
theorem sub_lt_of_abs_sub_lt_right (h : |a - b| < c) : a - c < b :=
sub_lt_of_abs_sub_lt_left (abs_sub_comm a b ▸ h)
theorem abs_sub_abs_le_abs_sub (a b : α) : |a| - |b| ≤ |a - b| :=
(@sub_le_iff_le_add α ..).2 <|
calc
|a| = |a - b + b| := by rw [sub_add_cancel]
_ ≤ |a - b| + |b| := abs_add _ _
theorem abs_abs_sub_abs_le_abs_sub (a b : α) : |(|a| - |b|)| ≤ |a - b| :=
abs_sub_le_iff.2
⟨abs_sub_abs_le_abs_sub _ _, by rw [abs_sub_comm]; apply abs_sub_abs_le_abs_sub⟩
/-- `|a - b| ≤ n` if `0 ≤ a ≤ n` and `0 ≤ b ≤ n`. -/
theorem abs_sub_le_of_nonneg_of_le {a b n : α} (a_nonneg : 0 ≤ a) (a_le_n : a ≤ n)
(b_nonneg : 0 ≤ b) (b_le_n : b ≤ n) : |a - b| ≤ n := by
rw [abs_sub_le_iff, sub_le_iff_le_add, sub_le_iff_le_add]
exact ⟨le_add_of_le_of_nonneg a_le_n b_nonneg, le_add_of_le_of_nonneg b_le_n a_nonneg⟩
/-- `|a - b| < n` if `0 ≤ a < n` and `0 ≤ b < n`. -/
theorem abs_sub_lt_of_nonneg_of_lt {a b n : α} (a_nonneg : 0 ≤ a) (a_lt_n : a < n)
(b_nonneg : 0 ≤ b) (b_lt_n : b < n) : |a - b| < n := by
rw [abs_sub_lt_iff, sub_lt_iff_lt_add, sub_lt_iff_lt_add]
exact ⟨lt_add_of_lt_of_nonneg a_lt_n b_nonneg, lt_add_of_lt_of_nonneg b_lt_n a_nonneg⟩
theorem abs_eq (hb : 0 ≤ b) : |a| = b ↔ a = b ∨ a = -b := by
refine ⟨eq_or_eq_neg_of_abs_eq, ?_⟩
rintro (rfl | rfl) <;> simp only [abs_neg, abs_of_nonneg hb]
theorem abs_le_max_abs_abs (hab : a ≤ b) (hbc : b ≤ c) : |b| ≤ max |a| |c| :=
abs_le'.2
⟨by simp [hbc.trans (le_abs_self c)], by
simp [((@neg_le_neg_iff α ..).mpr hab).trans (neg_le_abs a)]⟩
theorem min_abs_abs_le_abs_max : min |a| |b| ≤ |max a b| :=
(le_total a b).elim (fun h => (min_le_right _ _).trans_eq <| congr_arg _ (max_eq_right h).symm)
fun h => (min_le_left _ _).trans_eq <| congr_arg _ (max_eq_left h).symm
theorem min_abs_abs_le_abs_min : min |a| |b| ≤ |min a b| :=
(le_total a b).elim (fun h => (min_le_left _ _).trans_eq <| congr_arg _ (min_eq_left h).symm)
fun h => (min_le_right _ _).trans_eq <| congr_arg _ (min_eq_right h).symm
theorem abs_max_le_max_abs_abs : |max a b| ≤ max |a| |b| :=
(le_total a b).elim (fun h => (congr_arg _ <| max_eq_right h).trans_le <| le_max_right _ _)
fun h => (congr_arg _ <| max_eq_left h).trans_le <| le_max_left _ _
theorem abs_min_le_max_abs_abs : |min a b| ≤ max |a| |b| :=
(le_total a b).elim (fun h => (congr_arg _ <| min_eq_left h).trans_le <| le_max_left _ _) fun h =>
(congr_arg _ <| min_eq_right h).trans_le <| le_max_right _ _
theorem eq_of_abs_sub_eq_zero {a b : α} (h : |a - b| = 0) : a = b :=
sub_eq_zero.1 <| (abs_eq_zero (α := α)).1 h
theorem abs_sub_le (a b c : α) : |a - c| ≤ |a - b| + |b - c| :=
calc
|a - c| = |a - b + (b - c)| := by rw [sub_add_sub_cancel]
_ ≤ |a - b| + |b - c| := abs_add _ _
theorem abs_add_three (a b c : α) : |a + b + c| ≤ |a| + |b| + |c| :=
(abs_add _ _).trans (add_le_add_right (abs_add _ _) _)
theorem dist_bdd_within_interval {a b lb ub : α} (hal : lb ≤ a) (hau : a ≤ ub) (hbl : lb ≤ b)
(hbu : b ≤ ub) : |a - b| ≤ ub - lb :=
abs_sub_le_iff.2 ⟨sub_le_sub hau hbl, sub_le_sub hbu hal⟩
theorem eq_of_abs_sub_nonpos (h : |a - b| ≤ 0) : a = b :=
eq_of_abs_sub_eq_zero (le_antisymm h (abs_nonneg (a - b)))
theorem abs_sub_nonpos : |a - b| ≤ 0 ↔ a = b :=
⟨eq_of_abs_sub_nonpos, by rintro rfl; rw [sub_self, abs_zero]⟩
theorem abs_sub_pos : 0 < |a - b| ↔ a ≠ b :=
not_le.symm.trans abs_sub_nonpos.not
@[simp]
theorem abs_eq_self : |a| = a ↔ 0 ≤ a := by
rw [abs_eq_max_neg, max_eq_left_iff, neg_le_self_iff]
@[simp]
theorem abs_eq_neg_self : |a| = -a ↔ a ≤ 0 := by
rw [abs_eq_max_neg, max_eq_right_iff, le_neg_self_iff]
/-- For an element `a` of a linear ordered ring, either `abs a = a` and `0 ≤ a`,
or `abs a = -a` and `a < 0`.
Use cases on this lemma to automate linarith in inequalities -/
theorem abs_cases (a : α) : |a| = a ∧ 0 ≤ a ∨ |a| = -a ∧ a < 0 := by
by_cases h : 0 ≤ a
· left
exact ⟨abs_eq_self.mpr h, h⟩
· right
push_neg at h
exact ⟨abs_eq_neg_self.mpr (le_of_lt h), h⟩
@[simp]
theorem max_zero_add_max_neg_zero_eq_abs_self (a : α) : max a 0 + max (-a) 0 = |a| := by
symm
rcases le_total 0 a with (ha | ha) <;> simp [ha]
end LinearOrderedAddCommGroup
|
Algebra\Order\Group\Action.lean | /-
Copyright (c) 2024 Eric Wieser. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Eric Wieser
-/
import Mathlib.Algebra.Order.Monoid.Unbundled.Defs
import Mathlib.Order.ConditionallyCompleteLattice.Basic
/-!
# Results about `CovariantClass G α HSMul.hSMul LE.le`
When working with group actions rather than modules, we drop the `0 < c` condition.
Notably these are relevant for pointwise actions on set-like objects.
-/
variable {ι : Sort*} {M α : Type*}
theorem smul_mono_right [SMul M α] [Preorder α] [CovariantClass M α HSMul.hSMul LE.le]
(m : M) : Monotone (HSMul.hSMul m : α → α) :=
fun _ _ => CovariantClass.elim _
/-- A copy of `smul_mono_right` that is understood by `gcongr`. -/
@[gcongr]
theorem smul_le_smul_left [SMul M α] [Preorder α] [CovariantClass M α HSMul.hSMul LE.le]
(m : M) {a b : α} (h : a ≤ b) :
m • a ≤ m • b :=
smul_mono_right _ h
theorem smul_inf_le [SMul M α] [SemilatticeInf α] [CovariantClass M α HSMul.hSMul LE.le]
(m : M) (a₁ a₂ : α) : m • (a₁ ⊓ a₂) ≤ m • a₁ ⊓ m • a₂ :=
(smul_mono_right _).map_inf_le _ _
theorem smul_iInf_le [SMul M α] [CompleteLattice α] [CovariantClass M α HSMul.hSMul LE.le]
{m : M} {t : ι → α} :
m • iInf t ≤ ⨅ i, m • t i :=
le_iInf fun _ => smul_mono_right _ (iInf_le _ _)
theorem smul_strictMono_right [SMul M α] [Preorder α] [CovariantClass M α HSMul.hSMul LT.lt]
(m : M) : StrictMono (HSMul.hSMul m : α → α) :=
fun _ _ => CovariantClass.elim _
|
Algebra\Order\Group\Basic.lean | /-
Copyright (c) 2015 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Robert Y. Lewis
-/
import Mathlib.Algebra.Order.Group.Defs
import Mathlib.Algebra.Order.Monoid.Unbundled.Pow
/-!
# Lemmas about the interaction of power operations with order
-/
-- We should need only a minimal development of sets in order to get here.
assert_not_exists Set.Subsingleton
open Function Int
variable {α M R : Type*}
section OrderedCommGroup
variable [OrderedCommGroup α] {m n : ℤ} {a b : α}
@[to_additive zsmul_pos] lemma one_lt_zpow' (ha : 1 < a) (hn : 0 < n) : 1 < a ^ n := by
obtain ⟨n, rfl⟩ := Int.eq_ofNat_of_zero_le hn.le
rw [zpow_natCast]
refine one_lt_pow' ha ?_
rintro rfl
simp at hn
@[to_additive zsmul_strictMono_left]
lemma zpow_right_strictMono (ha : 1 < a) : StrictMono fun n : ℤ ↦ a ^ n := fun m n h ↦
calc
a ^ m = a ^ m * 1 := (mul_one _).symm
_ < a ^ m * a ^ (n - m) := mul_lt_mul_left' (one_lt_zpow' ha <| Int.sub_pos_of_lt h) _
_ = a ^ n := by simp [← zpow_add, m.add_comm]
@[to_additive zsmul_mono_left]
lemma zpow_mono_right (ha : 1 ≤ a) : Monotone fun n : ℤ ↦ a ^ n := fun m n h ↦
calc
a ^ m = a ^ m * 1 := (mul_one _).symm
_ ≤ a ^ m * a ^ (n - m) := mul_le_mul_left' (one_le_zpow ha <| Int.sub_nonneg_of_le h) _
_ = a ^ n := by simp [← zpow_add, m.add_comm]
@[to_additive (attr := gcongr)]
lemma zpow_le_zpow (ha : 1 ≤ a) (h : m ≤ n) : a ^ m ≤ a ^ n := zpow_mono_right ha h
@[to_additive (attr := gcongr)]
lemma zpow_lt_zpow (ha : 1 < a) (h : m < n) : a ^ m < a ^ n := zpow_right_strictMono ha h
@[to_additive]
lemma zpow_le_zpow_iff (ha : 1 < a) : a ^ m ≤ a ^ n ↔ m ≤ n := (zpow_right_strictMono ha).le_iff_le
@[to_additive]
lemma zpow_lt_zpow_iff (ha : 1 < a) : a ^ m < a ^ n ↔ m < n := (zpow_right_strictMono ha).lt_iff_lt
variable (α)
@[to_additive zsmul_strictMono_right]
lemma zpow_strictMono_left (hn : 0 < n) : StrictMono ((· ^ n) : α → α) := fun a b hab => by
rw [← one_lt_div', ← div_zpow]; exact one_lt_zpow' (one_lt_div'.2 hab) hn
@[to_additive zsmul_mono_right]
lemma zpow_mono_left (hn : 0 ≤ n) : Monotone ((· ^ n) : α → α) := fun a b hab => by
rw [← one_le_div', ← div_zpow]; exact one_le_zpow (one_le_div'.2 hab) hn
variable {α}
@[to_additive (attr := gcongr)]
lemma zpow_le_zpow' (hn : 0 ≤ n) (h : a ≤ b) : a ^ n ≤ b ^ n := zpow_mono_left α hn h
@[to_additive (attr := gcongr)]
lemma zpow_lt_zpow' (hn : 0 < n) (h : a < b) : a ^ n < b ^ n := zpow_strictMono_left α hn h
end OrderedCommGroup
section LinearOrderedCommGroup
variable [LinearOrderedCommGroup α] {n : ℤ} {a b : α}
@[to_additive] lemma zpow_le_zpow_iff' (hn : 0 < n) : a ^ n ≤ b ^ n ↔ a ≤ b :=
(zpow_strictMono_left α hn).le_iff_le
@[to_additive] lemma zpow_lt_zpow_iff' (hn : 0 < n) : a ^ n < b ^ n ↔ a < b :=
(zpow_strictMono_left α hn).lt_iff_lt
@[to_additive zsmul_right_injective
"See also `smul_right_injective`. TODO: provide a `NoZeroSMulDivisors` instance. We can't do
that here because importing that definition would create import cycles."]
lemma zpow_left_injective (hn : n ≠ 0) : Injective ((· ^ n) : α → α) := by
obtain hn | hn := hn.lt_or_lt
· refine fun a b (hab : a ^ n = b ^ n) ↦
(zpow_strictMono_left _ $ Int.neg_pos_of_neg hn).injective ?_
rw [zpow_neg, zpow_neg, hab]
· exact (zpow_strictMono_left _ hn).injective
@[to_additive zsmul_right_inj]
lemma zpow_left_inj (hn : n ≠ 0) : a ^ n = b ^ n ↔ a = b := (zpow_left_injective hn).eq_iff
/-- Alias of `zpow_left_inj`, for ease of discovery alongside `zsmul_le_zsmul_iff'` and
`zsmul_lt_zsmul_iff'`. -/
@[to_additive "Alias of `zsmul_right_inj`, for ease of discovery alongside `zsmul_le_zsmul_iff'` and
`zsmul_lt_zsmul_iff'`."]
lemma zpow_eq_zpow_iff' (hn : n ≠ 0) : a ^ n = b ^ n ↔ a = b := zpow_left_inj hn
end LinearOrderedCommGroup
|
Algebra\Order\Group\Bounds.lean | /-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Yury Kudryashov
-/
import Mathlib.Order.Bounds.Basic
import Mathlib.Algebra.Order.Group.Defs
/-!
# Least upper bound and the greatest lower bound in linear ordered additive commutative groups
-/
section LinearOrderedAddCommGroup
variable {α : Type*} [LinearOrderedAddCommGroup α] {s : Set α} {a ε : α}
theorem IsGLB.exists_between_self_add (h : IsGLB s a) (hε : 0 < ε) : ∃ b ∈ s, a ≤ b ∧ b < a + ε :=
h.exists_between <| lt_add_of_pos_right _ hε
theorem IsGLB.exists_between_self_add' (h : IsGLB s a) (h₂ : a ∉ s) (hε : 0 < ε) :
∃ b ∈ s, a < b ∧ b < a + ε :=
h.exists_between' h₂ <| lt_add_of_pos_right _ hε
theorem IsLUB.exists_between_sub_self (h : IsLUB s a) (hε : 0 < ε) : ∃ b ∈ s, a - ε < b ∧ b ≤ a :=
h.exists_between <| sub_lt_self _ hε
theorem IsLUB.exists_between_sub_self' (h : IsLUB s a) (h₂ : a ∉ s) (hε : 0 < ε) :
∃ b ∈ s, a - ε < b ∧ b < a :=
h.exists_between' h₂ <| sub_lt_self _ hε
end LinearOrderedAddCommGroup
|
Algebra\Order\Group\Cone.lean | /-
Copyright (c) 2017 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Scott Morrison
-/
import Mathlib.Algebra.Order.Group.Defs
/-!
# Construct ordered groups from positive cones
In this file we provide structures `PositiveCone` and `TotalPositiveCone`
that encode axioms of `OrderedAddCommGroup` and `LinearOrderedAddCommGroup`
in terms of the `(0 ≤ ·)` predicate.
We also provide two constructors,
`OrderedAddCommGroup.mkOfPositiveCone` and `LinearOrderedAddCommGroup.mkOfPositiveCone`,
that turn these structures into instances of the corresponding typeclasses.
-/
namespace AddCommGroup
/-- A collection of elements in an `AddCommGroup` designated as "non-negative".
This is useful for constructing an `OrderedAddCommGroup`
by choosing a positive cone in an existing `AddCommGroup`. -/
-- Porting note(#5171): @[nolint has_nonempty_instance]
structure PositiveCone (α : Type*) [AddCommGroup α] where
/-- The characteristic predicate of a positive cone. `nonneg a` means that `0 ≤ a` according to
the cone. -/
nonneg : α → Prop
/-- The characteristic predicate of a positive cone. `pos a` means that `0 < a` according to
the cone. -/
pos : α → Prop := fun a => nonneg a ∧ ¬nonneg (-a)
pos_iff : ∀ a, pos a ↔ nonneg a ∧ ¬nonneg (-a) := by intros; rfl
zero_nonneg : nonneg 0
add_nonneg : ∀ {a b}, nonneg a → nonneg b → nonneg (a + b)
nonneg_antisymm : ∀ {a}, nonneg a → nonneg (-a) → a = 0
/-- A positive cone in an `AddCommGroup` induces a linear order if
for every `a`, either `a` or `-a` is non-negative. -/
-- Porting note(#5171): @[nolint has_nonempty_instance]
structure TotalPositiveCone (α : Type*) [AddCommGroup α] extends PositiveCone α where
/-- For any `a` the proposition `nonneg a` is decidable -/
nonnegDecidable : DecidablePred nonneg
/-- Either `a` or `-a` is `nonneg` -/
nonneg_total : ∀ a : α, nonneg a ∨ nonneg (-a)
/-- Forget that a `TotalPositiveCone` is total. -/
add_decl_doc TotalPositiveCone.toPositiveCone
end AddCommGroup
namespace OrderedAddCommGroup
open AddCommGroup
/-- Construct an `OrderedAddCommGroup` by
designating a positive cone in an existing `AddCommGroup`. -/
def mkOfPositiveCone {α : Type*} [AddCommGroup α] (C : PositiveCone α) : OrderedAddCommGroup α :=
{ ‹AddCommGroup α› with
le := fun a b => C.nonneg (b - a),
lt := fun a b => C.pos (b - a),
lt_iff_le_not_le := fun a b => by simp [C.pos_iff],
le_refl := fun a => by simp [C.zero_nonneg],
le_trans := fun a b c nab nbc => by simpa using C.add_nonneg nbc nab,
le_antisymm := fun a b nab nba =>
eq_of_sub_eq_zero <| C.nonneg_antisymm nba (by rwa [neg_sub]),
add_le_add_left := fun a b nab c => by simpa using nab }
end OrderedAddCommGroup
namespace LinearOrderedAddCommGroup
open AddCommGroup
/-- Construct a `LinearOrderedAddCommGroup` by
designating a positive cone in an existing `AddCommGroup`
such that for every `a`, either `a` or `-a` is non-negative. -/
def mkOfPositiveCone {α : Type*} [AddCommGroup α] (C : TotalPositiveCone α) :
LinearOrderedAddCommGroup α :=
{ OrderedAddCommGroup.mkOfPositiveCone C.toPositiveCone with
-- Porting note: was `C.nonneg_total (b - a)`
le_total := fun a b => by simpa [neg_sub] using C.nonneg_total (b - a)
decidableLE := fun a b => C.nonnegDecidable _ }
end LinearOrderedAddCommGroup
|
Algebra\Order\Group\Defs.lean | /-
Copyright (c) 2016 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura, Mario Carneiro, Johannes Hölzl
-/
import Mathlib.Algebra.Order.Group.Unbundled.Basic
import Mathlib.Algebra.Order.Monoid.Defs
import Mathlib.Algebra.Order.Sub.Defs
import Mathlib.Util.AssertExists
/-!
# Ordered groups
This file defines bundled ordered groups and develops a few basic results.
## Implementation details
Unfortunately, the number of `'` appended to lemmas in this file
may differ between the multiplicative and the additive version of a lemma.
The reason is that we did not want to change existing names in the library.
-/
open Function
universe u
variable {α : Type u}
/-- An ordered additive commutative group is an additive commutative group
with a partial order in which addition is strictly monotone. -/
class OrderedAddCommGroup (α : Type u) extends AddCommGroup α, PartialOrder α where
/-- Addition is monotone in an ordered additive commutative group. -/
protected add_le_add_left : ∀ a b : α, a ≤ b → ∀ c : α, c + a ≤ c + b
/-- An ordered commutative group is a commutative group
with a partial order in which multiplication is strictly monotone. -/
class OrderedCommGroup (α : Type u) extends CommGroup α, PartialOrder α where
/-- Multiplication is monotone in an ordered commutative group. -/
protected mul_le_mul_left : ∀ a b : α, a ≤ b → ∀ c : α, c * a ≤ c * b
attribute [to_additive] OrderedCommGroup
@[to_additive]
instance OrderedCommGroup.to_covariantClass_left_le (α : Type u) [OrderedCommGroup α] :
CovariantClass α α (· * ·) (· ≤ ·) where
elim a b c bc := OrderedCommGroup.mul_le_mul_left b c bc a
-- See note [lower instance priority]
@[to_additive OrderedAddCommGroup.toOrderedCancelAddCommMonoid]
instance (priority := 100) OrderedCommGroup.toOrderedCancelCommMonoid [OrderedCommGroup α] :
OrderedCancelCommMonoid α :=
{ ‹OrderedCommGroup α› with le_of_mul_le_mul_left := fun a b c ↦ le_of_mul_le_mul_left' }
example (α : Type u) [OrderedAddCommGroup α] : CovariantClass α α (swap (· + ·)) (· < ·) :=
IsRightCancelAdd.covariant_swap_add_lt_of_covariant_swap_add_le α
-- Porting note: this instance is not used,
-- and causes timeouts after lean4#2210.
-- It was introduced in https://github.com/leanprover-community/mathlib/pull/17564
-- but without the motivation clearly explained.
/-- A choice-free shortcut instance. -/
@[to_additive "A choice-free shortcut instance."]
theorem OrderedCommGroup.to_contravariantClass_left_le (α : Type u) [OrderedCommGroup α] :
ContravariantClass α α (· * ·) (· ≤ ·) where
elim a b c bc := by simpa using mul_le_mul_left' bc a⁻¹
-- Porting note: this instance is not used,
-- and causes timeouts after lean4#2210.
-- See further explanation on `OrderedCommGroup.to_contravariantClass_left_le`.
/-- A choice-free shortcut instance. -/
@[to_additive "A choice-free shortcut instance."]
theorem OrderedCommGroup.to_contravariantClass_right_le (α : Type u) [OrderedCommGroup α] :
ContravariantClass α α (swap (· * ·)) (· ≤ ·) where
elim a b c bc := by simpa using mul_le_mul_right' bc a⁻¹
alias OrderedCommGroup.mul_lt_mul_left' := mul_lt_mul_left'
attribute [to_additive OrderedAddCommGroup.add_lt_add_left] OrderedCommGroup.mul_lt_mul_left'
alias OrderedCommGroup.le_of_mul_le_mul_left := le_of_mul_le_mul_left'
attribute [to_additive] OrderedCommGroup.le_of_mul_le_mul_left
alias OrderedCommGroup.lt_of_mul_lt_mul_left := lt_of_mul_lt_mul_left'
attribute [to_additive] OrderedCommGroup.lt_of_mul_lt_mul_left
/-!
### Linearly ordered commutative groups
-/
/-- A linearly ordered additive commutative group is an
additive commutative group with a linear order in which
addition is monotone. -/
class LinearOrderedAddCommGroup (α : Type u) extends OrderedAddCommGroup α, LinearOrder α
/-- A linearly ordered commutative group is a
commutative group with a linear order in which
multiplication is monotone. -/
@[to_additive]
class LinearOrderedCommGroup (α : Type u) extends OrderedCommGroup α, LinearOrder α
section LinearOrderedCommGroup
variable [LinearOrderedCommGroup α] {a b c : α}
@[to_additive LinearOrderedAddCommGroup.add_lt_add_left]
theorem LinearOrderedCommGroup.mul_lt_mul_left' (a b : α) (h : a < b) (c : α) : c * a < c * b :=
_root_.mul_lt_mul_left' h c
@[to_additive eq_zero_of_neg_eq]
theorem eq_one_of_inv_eq' (h : a⁻¹ = a) : a = 1 :=
match lt_trichotomy a 1 with
| Or.inl h₁ =>
have : 1 < a := h ▸ one_lt_inv_of_inv h₁
absurd h₁ this.asymm
| Or.inr (Or.inl h₁) => h₁
| Or.inr (Or.inr h₁) =>
have : a < 1 := h ▸ inv_lt_one'.mpr h₁
absurd h₁ this.asymm
@[to_additive exists_zero_lt]
theorem exists_one_lt' [Nontrivial α] : ∃ a : α, 1 < a := by
obtain ⟨y, hy⟩ := Decidable.exists_ne (1 : α)
obtain h|h := hy.lt_or_lt
· exact ⟨y⁻¹, one_lt_inv'.mpr h⟩
· exact ⟨y, h⟩
-- see Note [lower instance priority]
@[to_additive]
instance (priority := 100) LinearOrderedCommGroup.to_noMaxOrder [Nontrivial α] : NoMaxOrder α :=
⟨by
obtain ⟨y, hy⟩ : ∃ a : α, 1 < a := exists_one_lt'
exact fun a => ⟨a * y, lt_mul_of_one_lt_right' a hy⟩⟩
-- see Note [lower instance priority]
@[to_additive]
instance (priority := 100) LinearOrderedCommGroup.to_noMinOrder [Nontrivial α] : NoMinOrder α :=
⟨by
obtain ⟨y, hy⟩ : ∃ a : α, 1 < a := exists_one_lt'
exact fun a => ⟨a / y, (div_lt_self_iff a).mpr hy⟩⟩
-- See note [lower instance priority]
@[to_additive]
instance (priority := 100) LinearOrderedCommGroup.toLinearOrderedCancelCommMonoid
[LinearOrderedCommGroup α] : LinearOrderedCancelCommMonoid α :=
{ ‹LinearOrderedCommGroup α›, OrderedCommGroup.toOrderedCancelCommMonoid with }
@[to_additive (attr := simp)]
theorem inv_le_self_iff : a⁻¹ ≤ a ↔ 1 ≤ a := by simp [inv_le_iff_one_le_mul']
@[to_additive (attr := simp)]
theorem inv_lt_self_iff : a⁻¹ < a ↔ 1 < a := by simp [inv_lt_iff_one_lt_mul]
@[to_additive (attr := simp)]
theorem le_inv_self_iff : a ≤ a⁻¹ ↔ a ≤ 1 := by simp [← not_iff_not]
@[to_additive (attr := simp)]
theorem lt_inv_self_iff : a < a⁻¹ ↔ a < 1 := by simp [← not_iff_not]
end LinearOrderedCommGroup
section NormNumLemmas
/- The following lemmas are stated so that the `norm_num` tactic can use them with the
expected signatures. -/
variable [OrderedCommGroup α] {a b : α}
@[to_additive (attr := gcongr) neg_le_neg]
theorem inv_le_inv' : a ≤ b → b⁻¹ ≤ a⁻¹ :=
-- Porting note: explicit type annotation was not needed before.
(@inv_le_inv_iff α ..).mpr
@[to_additive (attr := gcongr) neg_lt_neg]
theorem inv_lt_inv' : a < b → b⁻¹ < a⁻¹ :=
-- Porting note: explicit type annotation was not needed before.
(@inv_lt_inv_iff α ..).mpr
-- The additive version is also a `linarith` lemma.
@[to_additive]
theorem inv_lt_one_of_one_lt : 1 < a → a⁻¹ < 1 :=
inv_lt_one_iff_one_lt.mpr
-- The additive version is also a `linarith` lemma.
@[to_additive]
theorem inv_le_one_of_one_le : 1 ≤ a → a⁻¹ ≤ 1 :=
inv_le_one'.mpr
@[to_additive neg_nonneg_of_nonpos]
theorem one_le_inv_of_le_one : a ≤ 1 → 1 ≤ a⁻¹ :=
one_le_inv'.mpr
end NormNumLemmas
/-
`NeZero` should not be needed at this point in the ordered algebraic hierarchy.
-/
assert_not_exists NeZero
|
Algebra\Order\Group\DenselyOrdered.lean | /-
Copyright (c) 2016 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura, Mario Carneiro, Johannes Hölzl
-/
import Mathlib.Algebra.Order.Group.Unbundled.Basic
import Mathlib.Algebra.Order.Monoid.Unbundled.OrderDual
import Mathlib.Algebra.Order.Monoid.Unbundled.ExistsOfLE
/-!
# Lemmas about densely linearly ordered groups.
-/
variable {α : Type*}
section DenselyOrdered
variable [Group α] [LinearOrder α]
variable [CovariantClass α α (· * ·) (· ≤ ·)]
variable [DenselyOrdered α] {a b c : α}
@[to_additive]
theorem le_of_forall_lt_one_mul_le (h : ∀ ε < 1, a * ε ≤ b) : a ≤ b :=
le_of_forall_one_lt_le_mul (α := αᵒᵈ) h
@[to_additive]
theorem le_of_forall_one_lt_div_le (h : ∀ ε : α, 1 < ε → a / ε ≤ b) : a ≤ b :=
le_of_forall_lt_one_mul_le fun ε ε1 => by
simpa only [div_eq_mul_inv, inv_inv] using h ε⁻¹ (Left.one_lt_inv_iff.2 ε1)
@[to_additive]
theorem le_iff_forall_one_lt_le_mul : a ≤ b ↔ ∀ ε, 1 < ε → a ≤ b * ε :=
⟨fun h _ ε_pos => le_mul_of_le_of_one_le h ε_pos.le, le_of_forall_one_lt_le_mul⟩
@[to_additive]
theorem le_iff_forall_lt_one_mul_le : a ≤ b ↔ ∀ ε < 1, a * ε ≤ b :=
le_iff_forall_one_lt_le_mul (α := αᵒᵈ)
end DenselyOrdered
|
Algebra\Order\Group\Indicator.lean | /-
Copyright (c) 2020 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov
-/
import Mathlib.Algebra.Group.Indicator
import Mathlib.Order.ConditionallyCompleteLattice.Basic
import Mathlib.Algebra.Order.Group.Defs
import Mathlib.Algebra.Order.Group.Synonym
import Mathlib.Algebra.Order.Group.Unbundled.Abs
import Mathlib.Algebra.Order.Monoid.Canonical.Defs
/-!
# Support of a function in an order
This file relates the support of a function to order constructions.
-/
assert_not_exists MonoidWithZero
open Set
variable {ι : Sort*} {α β M : Type*}
namespace Function
variable [One M]
@[to_additive]
lemma mulSupport_sup [SemilatticeSup M] (f g : α → M) :
mulSupport (fun x ↦ f x ⊔ g x) ⊆ mulSupport f ∪ mulSupport g :=
mulSupport_binop_subset (· ⊔ ·) (sup_idem _) f g
@[to_additive]
lemma mulSupport_inf [SemilatticeInf M] (f g : α → M) :
mulSupport (fun x ↦ f x ⊓ g x) ⊆ mulSupport f ∪ mulSupport g :=
mulSupport_binop_subset (· ⊓ ·) (inf_idem _) f g
@[to_additive]
lemma mulSupport_max [LinearOrder M] (f g : α → M) :
mulSupport (fun x ↦ max (f x) (g x)) ⊆ mulSupport f ∪ mulSupport g := mulSupport_sup f g
@[to_additive]
lemma mulSupport_min [LinearOrder M] (f g : α → M) :
mulSupport (fun x ↦ min (f x) (g x)) ⊆ mulSupport f ∪ mulSupport g := mulSupport_inf f g
@[to_additive]
lemma mulSupport_iSup [ConditionallyCompleteLattice M] [Nonempty ι] (f : ι → α → M) :
mulSupport (fun x ↦ ⨆ i, f i x) ⊆ ⋃ i, mulSupport (f i) := by
simp only [mulSupport_subset_iff', mem_iUnion, not_exists, nmem_mulSupport]
intro x hx
simp only [hx, ciSup_const]
@[to_additive]
lemma mulSupport_iInf [ConditionallyCompleteLattice M] [Nonempty ι] (f : ι → α → M) :
mulSupport (fun x ↦ ⨅ i, f i x) ⊆ ⋃ i, mulSupport (f i) := mulSupport_iSup (M := Mᵒᵈ) f
end Function
namespace Set
section LE
variable [LE M] [One M] {s t : Set α} {f g : α → M} {a : α} {y : M}
@[to_additive]
lemma mulIndicator_apply_le' (hfg : a ∈ s → f a ≤ y) (hg : a ∉ s → 1 ≤ y) :
mulIndicator s f a ≤ y := by
by_cases ha : a ∈ s
· simpa [ha] using hfg ha
· simpa [ha] using hg ha
@[to_additive]
lemma mulIndicator_le' (hfg : ∀ a ∈ s, f a ≤ g a) (hg : ∀ a, a ∉ s → 1 ≤ g a) :
mulIndicator s f ≤ g := fun _ ↦ mulIndicator_apply_le' (hfg _) (hg _)
@[to_additive]
lemma le_mulIndicator_apply (hfg : a ∈ s → y ≤ g a) (hf : a ∉ s → y ≤ 1) :
y ≤ mulIndicator s g a := mulIndicator_apply_le' (M := Mᵒᵈ) hfg hf
@[to_additive]
lemma le_mulIndicator (hfg : ∀ a ∈ s, f a ≤ g a) (hf : ∀ a ∉ s, f a ≤ 1) :
f ≤ mulIndicator s g := fun _ ↦ le_mulIndicator_apply (hfg _) (hf _)
end LE
section Preorder
variable [Preorder M] [One M] {s t : Set α} {f g : α → M} {a : α} {y : M}
@[to_additive indicator_apply_nonneg]
lemma one_le_mulIndicator_apply (h : a ∈ s → 1 ≤ f a) : 1 ≤ mulIndicator s f a :=
le_mulIndicator_apply h fun _ ↦ le_rfl
@[to_additive indicator_nonneg]
lemma one_le_mulIndicator (h : ∀ a ∈ s, 1 ≤ f a) (a : α) : 1 ≤ mulIndicator s f a :=
one_le_mulIndicator_apply (h a)
@[to_additive]
lemma mulIndicator_apply_le_one (h : a ∈ s → f a ≤ 1) : mulIndicator s f a ≤ 1 :=
mulIndicator_apply_le' h fun _ ↦ le_rfl
@[to_additive]
lemma mulIndicator_le_one (h : ∀ a ∈ s, f a ≤ 1) (a : α) : mulIndicator s f a ≤ 1 :=
mulIndicator_apply_le_one (h a)
@[to_additive]
lemma mulIndicator_le_mulIndicator (h : f a ≤ g a) : mulIndicator s f a ≤ mulIndicator s g a :=
mulIndicator_rel_mulIndicator le_rfl fun _ ↦ h
attribute [mono] mulIndicator_le_mulIndicator indicator_le_indicator
@[to_additive]
lemma mulIndicator_le_mulIndicator_of_subset (h : s ⊆ t) (hf : ∀ a, 1 ≤ f a) (a : α) :
mulIndicator s f a ≤ mulIndicator t f a :=
mulIndicator_apply_le'
(fun ha ↦ le_mulIndicator_apply (fun _ ↦ le_rfl) fun hat ↦ (hat <| h ha).elim) fun _ ↦
one_le_mulIndicator_apply fun _ ↦ hf _
@[to_additive]
lemma mulIndicator_le_self' (hf : ∀ x ∉ s, 1 ≤ f x) : mulIndicator s f ≤ f :=
mulIndicator_le' (fun _ _ ↦ le_rfl) hf
end Preorder
section LinearOrder
variable [Zero M] [LinearOrder M]
lemma indicator_le_indicator_nonneg (s : Set α) (f : α → M) :
s.indicator f ≤ {a | 0 ≤ f a}.indicator f := by
intro a
classical
simp_rw [indicator_apply]
split_ifs
exacts [le_rfl, (not_le.1 ‹_›).le, ‹_›, le_rfl]
lemma indicator_nonpos_le_indicator (s : Set α) (f : α → M) :
{a | f a ≤ 0}.indicator f ≤ s.indicator f :=
indicator_le_indicator_nonneg (M := Mᵒᵈ) _ _
end LinearOrder
section CompleteLattice
variable [CompleteLattice M] [One M] {s t : Set α} {f g : α → M} {a : α} {y : M}
@[to_additive]
lemma mulIndicator_iUnion_apply (h1 : (⊥ : M) = 1) (s : ι → Set α) (f : α → M) (x : α) :
mulIndicator (⋃ i, s i) f x = ⨆ i, mulIndicator (s i) f x := by
by_cases hx : x ∈ ⋃ i, s i
· rw [mulIndicator_of_mem hx]
rw [mem_iUnion] at hx
refine le_antisymm ?_ (iSup_le fun i ↦ mulIndicator_le_self' (fun x _ ↦ h1 ▸ bot_le) x)
rcases hx with ⟨i, hi⟩
exact le_iSup_of_le i (ge_of_eq <| mulIndicator_of_mem hi _)
· rw [mulIndicator_of_not_mem hx]
simp only [mem_iUnion, not_exists] at hx
simp [hx, ← h1]
variable [Nonempty ι]
@[to_additive]
lemma mulIndicator_iInter_apply (h1 : (⊥ : M) = 1) (s : ι → Set α) (f : α → M) (x : α) :
mulIndicator (⋂ i, s i) f x = ⨅ i, mulIndicator (s i) f x := by
by_cases hx : x ∈ ⋂ i, s i
· rw [mulIndicator_of_mem hx]
rw [mem_iInter] at hx
refine le_antisymm ?_ (by simp only [mulIndicator_of_mem (hx _), ciInf_const, le_refl])
exact le_iInf (fun j ↦ by simp only [mulIndicator_of_mem (hx j), le_refl])
· rw [mulIndicator_of_not_mem hx]
simp only [mem_iInter, not_exists, not_forall] at hx
rcases hx with ⟨j, hj⟩
refine le_antisymm (by simp only [← h1, le_iInf_iff, bot_le, forall_const]) ?_
simpa [mulIndicator_of_not_mem hj] using (iInf_le (fun i ↦ (s i).mulIndicator f) j) x
end CompleteLattice
section CanonicallyOrderedCommMonoid
variable [CanonicallyOrderedCommMonoid M]
@[to_additive]
lemma mulIndicator_le_self (s : Set α) (f : α → M) : mulIndicator s f ≤ f :=
mulIndicator_le_self' fun _ _ ↦ one_le _
@[to_additive]
lemma mulIndicator_apply_le {a : α} {s : Set α} {f g : α → M} (hfg : a ∈ s → f a ≤ g a) :
mulIndicator s f a ≤ g a :=
mulIndicator_apply_le' hfg fun _ ↦ one_le _
@[to_additive]
lemma mulIndicator_le {s : Set α} {f g : α → M} (hfg : ∀ a ∈ s, f a ≤ g a) :
mulIndicator s f ≤ g :=
mulIndicator_le' hfg fun _ _ ↦ one_le _
end CanonicallyOrderedCommMonoid
section LinearOrderedCommGroup
variable [LinearOrderedCommGroup M]
open scoped symmDiff
@[to_additive]
lemma mabs_mulIndicator_symmDiff (s t : Set α) (f : α → M) (x : α) :
|mulIndicator (s ∆ t) f x|ₘ = |mulIndicator s f x / mulIndicator t f x|ₘ :=
apply_mulIndicator_symmDiff mabs_inv s t f x
end LinearOrderedCommGroup
end Set
|
Algebra\Order\Group\InjSurj.lean | /-
Copyright (c) 2016 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura, Mario Carneiro, Johannes Hölzl
-/
import Mathlib.Algebra.Order.Group.Defs
import Mathlib.Algebra.Order.Monoid.Basic
/-!
# Pull back ordered groups along injective maps.
-/
variable {α β : Type*}
/-- Pullback an `OrderedCommGroup` under an injective map.
See note [reducible non-instances]. -/
@[to_additive (attr := reducible) "Pullback an `OrderedAddCommGroup` under an injective map."]
def Function.Injective.orderedCommGroup [OrderedCommGroup α] {β : Type*} [One β] [Mul β] [Inv β]
[Div β] [Pow β ℕ] [Pow β ℤ] (f : β → α) (hf : Function.Injective f) (one : f 1 = 1)
(mul : ∀ x y, f (x * y) = f x * f y) (inv : ∀ x, f x⁻¹ = (f x)⁻¹)
(div : ∀ x y, f (x / y) = f x / f y) (npow : ∀ (x) (n : ℕ), f (x ^ n) = f x ^ n)
(zpow : ∀ (x) (n : ℤ), f (x ^ n) = f x ^ n) : OrderedCommGroup β where
toCommGroup := hf.commGroup f one mul inv div npow zpow
toPartialOrder := PartialOrder.lift f hf
__ := hf.orderedCommMonoid f one mul npow
/-- Pullback a `LinearOrderedCommGroup` under an injective map.
See note [reducible non-instances]. -/
@[to_additive (attr := reducible) "Pullback a `LinearOrderedAddCommGroup` under an injective map."]
def Function.Injective.linearOrderedCommGroup [LinearOrderedCommGroup α] {β : Type*} [One β]
[Mul β] [Inv β] [Div β] [Pow β ℕ] [Pow β ℤ] [Sup β] [Inf β] (f : β → α)
(hf : Function.Injective f) (one : f 1 = 1) (mul : ∀ x y, f (x * y) = f x * f y)
(inv : ∀ x, f x⁻¹ = (f x)⁻¹) (div : ∀ x y, f (x / y) = f x / f y)
(npow : ∀ (x) (n : ℕ), f (x ^ n) = f x ^ n) (zpow : ∀ (x) (n : ℤ), f (x ^ n) = f x ^ n)
(sup : ∀ x y, f (x ⊔ y) = max (f x) (f y)) (inf : ∀ x y, f (x ⊓ y) = min (f x) (f y)) :
LinearOrderedCommGroup β where
toOrderedCommGroup := hf.orderedCommGroup f one mul inv div npow zpow
__ := LinearOrder.lift f hf sup inf
|
Algebra\Order\Group\Instances.lean | /-
Copyright (c) 2016 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura, Mario Carneiro, Johannes Hölzl
-/
import Mathlib.Algebra.Order.Group.Defs
import Mathlib.Algebra.Order.Monoid.OrderDual
/-!
# Additional instances for ordered commutative groups.
-/
variable {α : Type*}
@[to_additive]
instance OrderDual.orderedCommGroup [OrderedCommGroup α] : OrderedCommGroup αᵒᵈ :=
{ OrderDual.orderedCommMonoid, OrderDual.instGroup with }
@[to_additive]
instance OrderDual.linearOrderedCommGroup [LinearOrderedCommGroup α] : LinearOrderedCommGroup αᵒᵈ :=
{ OrderDual.orderedCommGroup, OrderDual.instLinearOrder α with }
|
Algebra\Order\Group\Int.lean | /-
Copyright (c) 2016 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad
-/
import Mathlib.Algebra.Group.Int
import Mathlib.Algebra.Order.Group.Abs
/-!
# The integers form a linear ordered group
This file contains the linear ordered group instance on the integers.
See note [foundational algebra order theory].
## Recursors
* `Int.rec`: Sign disjunction. Something is true/defined on `ℤ` if it's true/defined for nonnegative
and for negative values. (Defined in core Lean 3)
* `Int.inductionOn`: Simple growing induction on positive numbers, plus simple decreasing induction
on negative numbers. Note that this recursor is currently only `Prop`-valued.
* `Int.inductionOn'`: Simple growing induction for numbers greater than `b`, plus simple decreasing
induction on numbers less than `b`.
-/
-- We should need only a minimal development of sets in order to get here.
assert_not_exists Set.Subsingleton
assert_not_exists Ring
open Function Nat
namespace Int
theorem natCast_strictMono : StrictMono (· : ℕ → ℤ) := fun _ _ ↦ Int.ofNat_lt.2
@[deprecated (since := "2024-05-25")] alias coe_nat_strictMono := natCast_strictMono
instance linearOrderedAddCommGroup : LinearOrderedAddCommGroup ℤ where
__ := instLinearOrder
__ := instAddCommGroup
add_le_add_left _ _ := Int.add_le_add_left
/-! ### Miscellaneous lemmas -/
theorem abs_eq_natAbs : ∀ a : ℤ, |a| = natAbs a
| (n : ℕ) => abs_of_nonneg <| ofNat_zero_le _
| -[_+1] => abs_of_nonpos <| le_of_lt <| negSucc_lt_zero _
@[simp, norm_cast] lemma natCast_natAbs (n : ℤ) : (n.natAbs : ℤ) = |n| := n.abs_eq_natAbs.symm
theorem natAbs_abs (a : ℤ) : natAbs |a| = natAbs a := by rw [abs_eq_natAbs]; rfl
theorem sign_mul_abs (a : ℤ) : sign a * |a| = a := by
rw [abs_eq_natAbs, sign_mul_natAbs a]
lemma natAbs_le_self_sq (a : ℤ) : (Int.natAbs a : ℤ) ≤ a ^ 2 := by
rw [← Int.natAbs_sq a, sq]
norm_cast
apply Nat.le_mul_self
alias natAbs_le_self_pow_two := natAbs_le_self_sq
lemma le_self_sq (b : ℤ) : b ≤ b ^ 2 := le_trans le_natAbs (natAbs_le_self_sq _)
alias le_self_pow_two := le_self_sq
@[norm_cast] lemma abs_natCast (n : ℕ) : |(n : ℤ)| = n := abs_of_nonneg (natCast_nonneg n)
theorem natAbs_sub_pos_iff {i j : ℤ} : 0 < natAbs (i - j) ↔ i ≠ j := by
rw [natAbs_pos, ne_eq, sub_eq_zero]
theorem natAbs_sub_ne_zero_iff {i j : ℤ} : natAbs (i - j) ≠ 0 ↔ i ≠ j :=
Nat.ne_zero_iff_zero_lt.trans natAbs_sub_pos_iff
@[simp]
theorem abs_lt_one_iff {a : ℤ} : |a| < 1 ↔ a = 0 := by
rw [← zero_add 1, lt_add_one_iff, abs_nonpos_iff]
theorem abs_le_one_iff {a : ℤ} : |a| ≤ 1 ↔ a = 0 ∨ a = 1 ∨ a = -1 := by
rw [le_iff_lt_or_eq, abs_lt_one_iff, abs_eq Int.one_nonneg]
theorem one_le_abs {z : ℤ} (h₀ : z ≠ 0) : 1 ≤ |z| :=
add_one_le_iff.mpr (abs_pos.mpr h₀)
/-! #### `/` -/
theorem ediv_eq_zero_of_lt_abs {a b : ℤ} (H1 : 0 ≤ a) (H2 : a < |b|) : a / b = 0 :=
match b, |b|, abs_eq_natAbs b, H2 with
| (n : ℕ), _, rfl, H2 => ediv_eq_zero_of_lt H1 H2
| -[n+1], _, rfl, H2 => neg_injective <| by rw [← Int.ediv_neg]; exact ediv_eq_zero_of_lt H1 H2
/-! #### mod -/
@[simp]
theorem emod_abs (a b : ℤ) : a % |b| = a % b :=
abs_by_cases (fun i => a % i = a % b) rfl (emod_neg _ _)
theorem emod_lt (a : ℤ) {b : ℤ} (H : b ≠ 0) : a % b < |b| := by
rw [← emod_abs]; exact emod_lt_of_pos _ (abs_pos.2 H)
/-! ### properties of `/` and `%` -/
theorem abs_ediv_le_abs : ∀ a b : ℤ, |a / b| ≤ |a| :=
suffices ∀ (a : ℤ) (n : ℕ), |a / n| ≤ |a| from fun a b =>
match b, eq_nat_or_neg b with
| _, ⟨n, Or.inl rfl⟩ => this _ _
| _, ⟨n, Or.inr rfl⟩ => by rw [Int.ediv_neg, abs_neg]; apply this
fun a n => by
rw [abs_eq_natAbs, abs_eq_natAbs]
exact ofNat_le_ofNat_of_le
(match a, n with
| (m : ℕ), n => Nat.div_le_self _ _
| -[m+1], 0 => Nat.zero_le _
| -[m+1], n + 1 => Nat.succ_le_succ (Nat.div_le_self _ _))
theorem abs_sign_of_nonzero {z : ℤ} (hz : z ≠ 0) : |z.sign| = 1 := by
rw [abs_eq_natAbs, natAbs_sign_of_nonzero hz, Int.ofNat_one]
protected theorem sign_eq_ediv_abs (a : ℤ) : sign a = a / |a| :=
if az : a = 0 then by simp [az]
else (Int.ediv_eq_of_eq_mul_left (mt abs_eq_zero.1 az) (sign_mul_abs _).symm).symm
end Int
section Group
variable {G : Type*} [Group G]
@[to_additive (attr := simp) abs_zsmul_eq_zero]
lemma zpow_abs_eq_one (a : G) (n : ℤ) : a ^ |n| = 1 ↔ a ^ n = 1 := by
rw [← Int.natCast_natAbs, zpow_natCast, pow_natAbs_eq_one]
end Group
|
Algebra\Order\Group\Lattice.lean | /-
Copyright (c) 2021 Christopher Hoskin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Christopher Hoskin, Yaël Dillies
-/
import Mathlib.Algebra.Order.Group.OrderIso
/-!
# Lattice ordered groups
Lattice ordered groups were introduced by [Birkhoff][birkhoff1942]. They form the algebraic
underpinnings of vector lattices, Banach lattices, AL-space, AM-space etc.
A lattice ordered group is a type `α` satisfying:
* `Lattice α`
* `CommGroup α`
* `CovariantClass α α (· * ·) (· ≤ ·)`
* `CovariantClass α α (swap (· * ·)) (· ≤ ·)`
This file establishes basic properties of lattice ordered groups. It is shown that when the group is
commutative, the lattice is distributive. This also holds in the non-commutative case
([Birkhoff][birkhoff1942],[Fuchs][fuchs1963]) but we do not yet have the machinery to establish this
in mathlib.
## References
* [Birkhoff, Lattice-ordered Groups][birkhoff1942]
* [Bourbaki, Algebra II][bourbaki1981]
* [Fuchs, Partially Ordered Algebraic Systems][fuchs1963]
* [Zaanen, Lectures on "Riesz Spaces"][zaanen1966]
* [Banasiak, Banach Lattices in Applications][banasiak]
## Tags
lattice, order, group
-/
open Function
variable {α β : Type*}
section Group
variable [Lattice α] [Group α]
-- Special case of Bourbaki A.VI.9 (1)
@[to_additive]
lemma mul_sup [CovariantClass α α (· * ·) (· ≤ ·)] (a b c : α) :
c * (a ⊔ b) = c * a ⊔ c * b :=
(OrderIso.mulLeft _).map_sup _ _
@[to_additive]
lemma sup_mul [CovariantClass α α (swap (· * ·)) (· ≤ ·)] (a b c : α) :
(a ⊔ b) * c = a * c ⊔ b * c :=
(OrderIso.mulRight _).map_sup _ _
@[to_additive]
lemma mul_inf [CovariantClass α α (· * ·) (· ≤ ·)] (a b c : α) :
c * (a ⊓ b) = c * a ⊓ c * b :=
(OrderIso.mulLeft _).map_inf _ _
@[to_additive]
lemma inf_mul [CovariantClass α α (swap (· * ·)) (· ≤ ·)] (a b c : α) :
(a ⊓ b) * c = a * c ⊓ b * c :=
(OrderIso.mulRight _).map_inf _ _
@[to_additive]
lemma sup_div [CovariantClass α α (swap (· * ·)) (· ≤ ·)] (a b c : α) :
(a ⊔ b) / c = a / c ⊔ b / c :=
(OrderIso.divRight _).map_sup _ _
@[to_additive]
lemma inf_div [CovariantClass α α (swap (· * ·)) (· ≤ ·)] (a b c : α) :
(a ⊓ b) / c = a / c ⊓ b / c :=
(OrderIso.divRight _).map_inf _ _
section
variable [CovariantClass α α (· * ·) (· ≤ ·)] [CovariantClass α α (swap (· * ·)) (· ≤ ·)]
@[to_additive] lemma inv_sup (a b : α) : (a ⊔ b)⁻¹ = a⁻¹ ⊓ b⁻¹ := (OrderIso.inv α).map_sup _ _
@[to_additive] lemma inv_inf (a b : α) : (a ⊓ b)⁻¹ = a⁻¹ ⊔ b⁻¹ := (OrderIso.inv α).map_inf _ _
@[to_additive]
lemma div_sup (a b c : α) : c / (a ⊔ b) = c / a ⊓ c / b := (OrderIso.divLeft c).map_sup _ _
@[to_additive]
lemma div_inf (a b c : α) : c / (a ⊓ b) = c / a ⊔ c / b := (OrderIso.divLeft c).map_inf _ _
-- In fact 0 ≤ n•a implies 0 ≤ a, see L. Fuchs, "Partially ordered algebraic systems"
-- Chapter V, 1.E
-- See also `one_le_pow_iff` for the existing version in linear orders
@[to_additive]
lemma pow_two_semiclosed
{a : α} (ha : 1 ≤ a ^ 2) : 1 ≤ a := by
suffices this : (a ⊓ 1) * (a ⊓ 1) = a ⊓ 1 by
rwa [← inf_eq_right, ← mul_right_eq_self]
rw [mul_inf, inf_mul, ← pow_two, mul_one, one_mul, inf_assoc, inf_left_idem, inf_comm,
inf_assoc, inf_of_le_left ha]
end
end Group
variable [Lattice α] [CommGroup α]
-- Fuchs p67
-- Bourbaki A.VI.10 Prop 7
@[to_additive]
lemma inf_mul_sup [CovariantClass α α (· * ·) (· ≤ ·)] (a b : α) : (a ⊓ b) * (a ⊔ b) = a * b :=
calc
(a ⊓ b) * (a ⊔ b) = (a ⊓ b) * (a * b * (b⁻¹ ⊔ a⁻¹)) := by
rw [mul_sup b⁻¹ a⁻¹ (a * b), mul_inv_cancel_right, mul_inv_cancel_comm]
_ = (a ⊓ b) * (a * b * (a ⊓ b)⁻¹) := by rw [inv_inf, sup_comm]
_ = a * b := by rw [mul_comm, inv_mul_cancel_right]
/-- Every lattice ordered commutative group is a distributive lattice. -/
-- Non-comm case needs cancellation law https://ncatlab.org/nlab/show/distributive+lattice
@[to_additive "Every lattice ordered commutative additive group is a distributive lattice"]
def CommGroup.toDistribLattice (α : Type*) [Lattice α] [CommGroup α]
[CovariantClass α α (· * ·) (· ≤ ·)] : DistribLattice α where
le_sup_inf x y z := by
rw [← mul_le_mul_iff_left (x ⊓ (y ⊓ z)), inf_mul_sup x (y ⊓ z), ← inv_mul_le_iff_le_mul,
le_inf_iff]
constructor
· rw [inv_mul_le_iff_le_mul, ← inf_mul_sup x y]
exact mul_le_mul' (inf_le_inf_left _ inf_le_left) inf_le_left
· rw [inv_mul_le_iff_le_mul, ← inf_mul_sup x z]
exact mul_le_mul' (inf_le_inf_left _ inf_le_right) inf_le_right
|
Algebra\Order\Group\MinMax.lean | /-
Copyright (c) 2016 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura, Mario Carneiro, Johannes Hölzl
-/
import Mathlib.Algebra.Order.Group.Abs
import Mathlib.Algebra.Order.Monoid.Unbundled.MinMax
/-!
# `min` and `max` in linearly ordered groups.
-/
section
variable {α : Type*} [Group α] [LinearOrder α] [CovariantClass α α (· * ·) (· ≤ ·)]
-- TODO: This duplicates `oneLePart_div_leOnePart`
@[to_additive (attr := simp)]
theorem max_one_div_max_inv_one_eq_self (a : α) : max a 1 / max a⁻¹ 1 = a := by
rcases le_total a 1 with (h | h) <;> simp [h]
alias max_zero_sub_eq_self := max_zero_sub_max_neg_zero_eq_self
@[to_additive]
lemma max_inv_one (a : α) : max a⁻¹ 1 = a⁻¹ * max a 1 := by
rw [eq_inv_mul_iff_mul_eq, ← eq_div_iff_mul_eq', max_one_div_max_inv_one_eq_self]
end
section LinearOrderedCommGroup
variable {α : Type*} [LinearOrderedCommGroup α] {a b c : α}
@[to_additive min_neg_neg]
theorem min_inv_inv' (a b : α) : min a⁻¹ b⁻¹ = (max a b)⁻¹ :=
Eq.symm <| (@Monotone.map_max α αᵒᵈ _ _ Inv.inv a b) fun _ _ =>
-- Porting note: Explicit `α` necessary to infer `CovariantClass` instance
(@inv_le_inv_iff α _ _ _).mpr
@[to_additive max_neg_neg]
theorem max_inv_inv' (a b : α) : max a⁻¹ b⁻¹ = (min a b)⁻¹ :=
Eq.symm <| (@Monotone.map_min α αᵒᵈ _ _ Inv.inv a b) fun _ _ =>
-- Porting note: Explicit `α` necessary to infer `CovariantClass` instance
(@inv_le_inv_iff α _ _ _).mpr
@[to_additive min_sub_sub_right]
theorem min_div_div_right' (a b c : α) : min (a / c) (b / c) = min a b / c := by
simpa only [div_eq_mul_inv] using min_mul_mul_right a b c⁻¹
@[to_additive max_sub_sub_right]
theorem max_div_div_right' (a b c : α) : max (a / c) (b / c) = max a b / c := by
simpa only [div_eq_mul_inv] using max_mul_mul_right a b c⁻¹
@[to_additive min_sub_sub_left]
theorem min_div_div_left' (a b c : α) : min (a / b) (a / c) = a / max b c := by
simp only [div_eq_mul_inv, min_mul_mul_left, min_inv_inv']
@[to_additive max_sub_sub_left]
theorem max_div_div_left' (a b c : α) : max (a / b) (a / c) = a / min b c := by
simp only [div_eq_mul_inv, max_mul_mul_left, max_inv_inv']
end LinearOrderedCommGroup
section LinearOrderedAddCommGroup
variable {α : Type*} [LinearOrderedAddCommGroup α] {a b c : α}
theorem max_sub_max_le_max (a b c d : α) : max a b - max c d ≤ max (a - c) (b - d) := by
simp only [sub_le_iff_le_add, max_le_iff]; constructor
· calc
a = a - c + c := (sub_add_cancel a c).symm
_ ≤ max (a - c) (b - d) + max c d := add_le_add (le_max_left _ _) (le_max_left _ _)
· calc
b = b - d + d := (sub_add_cancel b d).symm
_ ≤ max (a - c) (b - d) + max c d := add_le_add (le_max_right _ _) (le_max_right _ _)
theorem abs_max_sub_max_le_max (a b c d : α) : |max a b - max c d| ≤ max |a - c| |b - d| := by
refine abs_sub_le_iff.2 ⟨?_, ?_⟩
· exact (max_sub_max_le_max _ _ _ _).trans (max_le_max (le_abs_self _) (le_abs_self _))
· rw [abs_sub_comm a c, abs_sub_comm b d]
exact (max_sub_max_le_max _ _ _ _).trans (max_le_max (le_abs_self _) (le_abs_self _))
theorem abs_min_sub_min_le_max (a b c d : α) : |min a b - min c d| ≤ max |a - c| |b - d| := by
simpa only [max_neg_neg, neg_sub_neg, abs_sub_comm] using
abs_max_sub_max_le_max (-a) (-b) (-c) (-d)
theorem abs_max_sub_max_le_abs (a b c : α) : |max a c - max b c| ≤ |a - b| := by
simpa only [sub_self, abs_zero, max_eq_left (abs_nonneg (a - b))]
using abs_max_sub_max_le_max a c b c
end LinearOrderedAddCommGroup
|
Algebra\Order\Group\Nat.lean | /-
Copyright (c) 2014 Floris van Doorn (c) 2016 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Floris van Doorn, Leonardo de Moura, Jeremy Avigad, Mario Carneiro
-/
import Mathlib.Algebra.Group.Nat
import Mathlib.Algebra.Order.Monoid.Canonical.Defs
import Mathlib.Algebra.Order.Sub.Defs
import Mathlib.Data.Nat.Defs
/-!
# The naturals form a linear ordered monoid
This file contains the linear ordered monoid instance on the natural numbers.
See note [foundational algebra order theory].
-/
namespace Nat
/-! ### Instances -/
instance instCanonicallyLinearOrderedAddCommMonoid : CanonicallyLinearOrderedAddCommMonoid ℕ where
__ := instLinearOrder
bot := 0
bot_le := Nat.zero_le
add_le_add_left := @Nat.add_le_add_left
le_self_add := Nat.le_add_right
exists_add_of_le := Nat.exists_eq_add_of_le
instance instLinearOrderedCommMonoid : LinearOrderedCommMonoid ℕ where
__ := instLinearOrder
mul_le_mul_left _ _ h _ := mul_le_mul_left _ h
instance instLinearOrderedCancelAddCommMonoid : LinearOrderedCancelAddCommMonoid ℕ where
__ := instLinearOrder
add_le_add_left := @Nat.add_le_add_left
le_of_add_le_add_left := @Nat.le_of_add_le_add_left
instance instOrderedSub : OrderedSub ℕ := by
refine ⟨fun m n k ↦ ?_⟩
induction' n with n ih generalizing k
· simp
· simp only [sub_succ, pred_le_iff, ih, succ_add, add_succ]
/-! ### Miscellaneous lemmas -/
variable {α : Type*} {n : ℕ} {f : α → ℕ}
/-- See also `pow_left_strictMonoOn`. -/
protected lemma pow_left_strictMono (hn : n ≠ 0) : StrictMono (· ^ n : ℕ → ℕ) :=
fun _ _ h ↦ Nat.pow_lt_pow_left h hn
lemma _root_.StrictMono.nat_pow [Preorder α] (hn : n ≠ 0) (hf : StrictMono f) :
StrictMono (f · ^ n) := (Nat.pow_left_strictMono hn).comp hf
end Nat
|
Algebra\Order\Group\OrderIso.lean | /-
Copyright (c) 2016 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura, Mario Carneiro, Johannes Hölzl
-/
import Mathlib.Algebra.Group.Units.Equiv
import Mathlib.Algebra.Order.Group.Unbundled.Basic
import Mathlib.Order.Hom.Basic
/-!
# Inverse and multiplication as order isomorphisms in ordered groups
-/
open Function
universe u
variable {α : Type u}
section Group
variable [Group α]
section TypeclassesLeftRightLE
variable [LE α] [CovariantClass α α (· * ·) (· ≤ ·)] [CovariantClass α α (swap (· * ·)) (· ≤ ·)]
{a b c d : α}
section
variable (α)
/-- `x ↦ x⁻¹` as an order-reversing equivalence. -/
@[to_additive (attr := simps!) "`x ↦ -x` as an order-reversing equivalence."]
def OrderIso.inv : α ≃o αᵒᵈ where
toEquiv := (Equiv.inv α).trans OrderDual.toDual
map_rel_iff' {_ _} := inv_le_inv_iff (α := α)
end
@[to_additive neg_le]
theorem inv_le' : a⁻¹ ≤ b ↔ b⁻¹ ≤ a :=
(OrderIso.inv α).symm_apply_le
alias ⟨inv_le_of_inv_le', _⟩ := inv_le'
attribute [to_additive neg_le_of_neg_le] inv_le_of_inv_le'
@[to_additive le_neg]
theorem le_inv' : a ≤ b⁻¹ ↔ b ≤ a⁻¹ :=
(OrderIso.inv α).le_symm_apply
/-- `x ↦ a / x` as an order-reversing equivalence. -/
@[to_additive (attr := simps!) "`x ↦ a - x` as an order-reversing equivalence."]
def OrderIso.divLeft (a : α) : α ≃o αᵒᵈ where
toEquiv := (Equiv.divLeft a).trans OrderDual.toDual
map_rel_iff' {_ _} := div_le_div_iff_left (α := α) _
end TypeclassesLeftRightLE
end Group
alias ⟨le_inv_of_le_inv, _⟩ := le_inv'
attribute [to_additive] le_inv_of_le_inv
section Group
variable [Group α] [LE α]
section Right
variable [CovariantClass α α (swap (· * ·)) (· ≤ ·)] {a b c d : α}
/-- `Equiv.mulRight` as an `OrderIso`. See also `OrderEmbedding.mulRight`. -/
@[to_additive (attr := simps! (config := { simpRhs := true }) toEquiv apply)
"`Equiv.addRight` as an `OrderIso`. See also `OrderEmbedding.addRight`."]
def OrderIso.mulRight (a : α) : α ≃o α where
map_rel_iff' {_ _} := mul_le_mul_iff_right a
toEquiv := Equiv.mulRight a
@[to_additive (attr := simp)]
theorem OrderIso.mulRight_symm (a : α) : (OrderIso.mulRight a).symm = OrderIso.mulRight a⁻¹ := by
ext x
rfl
/-- `x ↦ x / a` as an order isomorphism. -/
@[to_additive (attr := simps!) "`x ↦ x - a` as an order isomorphism."]
def OrderIso.divRight (a : α) : α ≃o α where
toEquiv := Equiv.divRight a
map_rel_iff' {_ _} := div_le_div_iff_right a
end Right
section Left
variable [CovariantClass α α (· * ·) (· ≤ ·)]
/-- `Equiv.mulLeft` as an `OrderIso`. See also `OrderEmbedding.mulLeft`. -/
@[to_additive (attr := simps! (config := { simpRhs := true }) toEquiv apply)
"`Equiv.addLeft` as an `OrderIso`. See also `OrderEmbedding.addLeft`."]
def OrderIso.mulLeft (a : α) : α ≃o α where
map_rel_iff' {_ _} := mul_le_mul_iff_left a
toEquiv := Equiv.mulLeft a
@[to_additive (attr := simp)]
theorem OrderIso.mulLeft_symm (a : α) : (OrderIso.mulLeft a).symm = OrderIso.mulLeft a⁻¹ := by
ext x
rfl
end Left
end Group
|
Algebra\Order\Group\PiLex.lean | /-
Copyright (c) 2019 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes
-/
import Mathlib.Algebra.Group.Pi.Basic
import Mathlib.Algebra.Order.Group.Defs
import Mathlib.Algebra.Order.Group.Synonym
import Mathlib.Order.PiLex
/-!
# Lexicographic product of algebraic order structures
This file proves that the lexicographic order on pi types is compatible with the pointwise algebraic
operations.
-/
namespace Pi.Lex
variable {ι : Type*} {α : ι → Type*} [LinearOrder ι]
@[to_additive]
instance orderedCancelCommMonoid [∀ i, OrderedCancelCommMonoid (α i)] :
OrderedCancelCommMonoid (Lex (∀ i, α i)) where
mul_le_mul_left _ _ hxy z :=
hxy.elim (fun hxyz => hxyz ▸ le_rfl) fun ⟨i, hi⟩ =>
Or.inr ⟨i, fun j hji => congr_arg (z j * ·) (hi.1 j hji), mul_lt_mul_left' hi.2 _⟩
le_of_mul_le_mul_left _ _ _ hxyz :=
hxyz.elim (fun h => (mul_left_cancel h).le) fun ⟨i, hi⟩ =>
Or.inr ⟨i, fun j hj => (mul_left_cancel <| hi.1 j hj), lt_of_mul_lt_mul_left' hi.2⟩
@[to_additive]
instance orderedCommGroup [∀ i, OrderedCommGroup (α i)] : OrderedCommGroup (Lex (∀ i, α i)) where
mul_le_mul_left _ _ := mul_le_mul_left'
@[to_additive]
noncomputable instance linearOrderedCancelCommMonoid [IsWellOrder ι (· < ·)]
[∀ i, LinearOrderedCancelCommMonoid (α i)] :
LinearOrderedCancelCommMonoid (Lex (∀ i, α i)) where
__ : LinearOrder (Lex (∀ i, α i)) := inferInstance
__ : OrderedCancelCommMonoid (Lex (∀ i, α i)) := inferInstance
@[to_additive]
noncomputable instance linearOrderedCommGroup [IsWellOrder ι (· < ·)]
[∀ i, LinearOrderedCommGroup (α i)] :
LinearOrderedCommGroup (Lex (∀ i, α i)) where
__ : LinearOrder (Lex (∀ i, α i)) := inferInstance
mul_le_mul_left _ _ := mul_le_mul_left'
end Pi.Lex
|
Algebra\Order\Group\PosPart.lean | /-
Copyright (c) 2021 Christopher Hoskin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Christopher Hoskin, Yaël Dillies
-/
import Mathlib.Algebra.Order.Group.Unbundled.Abs
/-!
# Positive & negative parts
Mathematical structures possessing an absolute value often also possess a unique decomposition of
elements into "positive" and "negative" parts which are in some sense "disjoint" (e.g. the Jordan
decomposition of a measure).
This file defines `posPart` and `negPart`, the positive and negative parts of an element in a
lattice ordered group.
## Main statements
* `posPart_sub_negPart`: Every element `a` can be decomposed into `a⁺ - a⁻`, the difference of its
positive and negative parts.
* `posPart_inf_negPart_eq_zero`: The positive and negative parts are coprime.
## Notations
* `a⁺ᵐ = a ⊔ 1`: *Positive component* of an element `a` of a multiplicative lattice ordered group
* `a⁻ᵐ = a⁻¹ ⊔ 1`: *Negative component* of an element `a` of a multiplicative lattice ordered group
* `a⁺ = a ⊔ 0`: *Positive component* of an element `a` of a lattice ordered group
* `a⁻ = (-a) ⊔ 0`: *Negative component* of an element `a` of a lattice ordered group
## References
* [Birkhoff, Lattice-ordered Groups][birkhoff1942]
* [Bourbaki, Algebra II][bourbaki1981]
* [Fuchs, Partially Ordered Algebraic Systems][fuchs1963]
* [Zaanen, Lectures on "Riesz Spaces"][zaanen1966]
* [Banasiak, Banach Lattices in Applications][banasiak]
## Tags
positive part, negative part
-/
open Function
variable {α β : Type*}
section Lattice
variable [Lattice α]
section Group
variable [Group α] {a : α}
/-- The *positive part* of an element `a` in a lattice ordered group is `a ⊔ 1`, denoted `a⁺ᵐ`. -/
@[to_additive
"The *positive part* of an element `a` in a lattice ordered group is `a ⊔ 0`, denoted `a⁺`."]
def oneLePart (a : α) : α := a ⊔ 1
/-- The *negative part* of an element `a` in a lattice ordered group is `a⁻¹ ⊔ 1`, denoted `a⁻ᵐ `.
-/
@[to_additive
"The *negative part* of an element `a` in a lattice ordered group is `(-a) ⊔ 0`, denoted `a⁻`."]
def leOnePart (a : α) : α := a⁻¹ ⊔ 1
@[inherit_doc] postfix:max "⁺ᵐ " => oneLePart
@[inherit_doc] postfix:max "⁻ᵐ" => leOnePart
@[inherit_doc] postfix:max "⁺" => posPart
@[inherit_doc] postfix:max "⁻" => negPart
@[to_additive] lemma oneLePart_mono : Monotone (oneLePart : α → α) :=
fun _a _b hab ↦ sup_le_sup_right hab _
@[to_additive (attr := simp)] lemma oneLePart_one : (1 : α)⁺ᵐ = 1 := sup_idem _
@[to_additive (attr := simp)] lemma leOnePart_one : (1 : α)⁻ᵐ = 1 := by simp [leOnePart]
@[to_additive posPart_nonneg] lemma one_le_oneLePart (a : α) : 1 ≤ a⁺ᵐ := le_sup_right
@[to_additive negPart_nonneg] lemma one_le_leOnePart (a : α) : 1 ≤ a⁻ᵐ := le_sup_right
-- TODO: `to_additive` guesses `nonposPart`
@[to_additive le_posPart] lemma le_oneLePart (a : α) : a ≤ a⁺ᵐ := le_sup_left
@[to_additive] lemma inv_le_leOnePart (a : α) : a⁻¹ ≤ a⁻ᵐ := le_sup_left
@[to_additive (attr := simp)] lemma oneLePart_eq_self : a⁺ᵐ = a ↔ 1 ≤ a := sup_eq_left
@[to_additive] lemma oneLePart_eq_one : a⁺ᵐ = 1 ↔ a ≤ 1 := sup_eq_right
/-- See also `leOnePart_eq_inv`. -/
@[to_additive "See also `negPart_eq_neg`."]
lemma leOnePart_eq_inv' : a⁻ᵐ = a⁻¹ ↔ 1 ≤ a⁻¹ := sup_eq_left
/-- See also `leOnePart_eq_one`. -/
@[to_additive "See also `negPart_eq_zero`."]
lemma leOnePart_eq_one' : a⁻ᵐ = 1 ↔ a⁻¹ ≤ 1 := sup_eq_right
@[to_additive] lemma oneLePart_le_one : a⁺ᵐ ≤ 1 ↔ a ≤ 1 := by simp [oneLePart]
/-- See also `leOnePart_le_one`. -/
@[to_additive "See also `negPart_nonpos`."]
lemma leOnePart_le_one' : a⁻ᵐ ≤ 1 ↔ a⁻¹ ≤ 1 := by simp [leOnePart]
@[to_additive] lemma leOnePart_le_one : a⁻ᵐ ≤ 1 ↔ a⁻¹ ≤ 1 := by simp [leOnePart]
@[to_additive (attr := simp) posPart_pos] lemma one_lt_oneLePart (ha : 1 < a) : 1 < a⁺ᵐ := by
rwa [oneLePart_eq_self.2 ha.le]
@[to_additive (attr := simp)] lemma oneLePart_inv (a : α) : a⁻¹⁺ᵐ = a⁻ᵐ := rfl
@[to_additive (attr := simp)] lemma leOnePart_inv (a : α) : a⁻¹⁻ᵐ = a⁺ᵐ := by
simp [oneLePart, leOnePart]
section covariantmul
variable [CovariantClass α α (· * ·) (· ≤ ·)]
@[to_additive (attr := simp)] lemma leOnePart_eq_inv : a⁻ᵐ = a⁻¹ ↔ a ≤ 1 := by simp [leOnePart]
@[to_additive (attr := simp)]
lemma leOnePart_eq_one : a⁻ᵐ = 1 ↔ 1 ≤ a := by simp [leOnePart_eq_one']
@[to_additive (attr := simp) negPart_pos] lemma one_lt_ltOnePart (ha : a < 1) : 1 < a⁻ᵐ := by
rwa [leOnePart_eq_inv.2 ha.le, one_lt_inv']
-- Bourbaki A.VI.12 Prop 9 a)
@[to_additive (attr := simp)] lemma oneLePart_div_leOnePart (a : α) : a⁺ᵐ / a⁻ᵐ = a := by
rw [div_eq_mul_inv, mul_inv_eq_iff_eq_mul, leOnePart, mul_sup, mul_one, mul_right_inv, sup_comm,
oneLePart]
@[to_additive (attr := simp)] lemma leOnePart_div_oneLePart (a : α) : a⁻ᵐ / a⁺ᵐ = a⁻¹ := by
rw [← inv_div, oneLePart_div_leOnePart]
section covariantmulop
variable [CovariantClass α α (swap (· * ·)) (· ≤ ·)]
@[to_additive] lemma leOnePart_anti : Antitone (leOnePart : α → α) :=
fun _a _b hab ↦ sup_le_sup_right (inv_le_inv_iff.2 hab) _
@[to_additive]
lemma leOnePart_eq_inv_inf_one (a : α) : a⁻ᵐ = (a ⊓ 1)⁻¹ := by
rw [leOnePart, ← inv_inj, inv_sup, inv_inv, inv_inv, inv_one]
-- Bourbaki A.VI.12 Prop 9 d)
@[to_additive] lemma oneLePart_mul_leOnePart (a : α) : a⁺ᵐ * a⁻ᵐ = |a|ₘ := by
rw [oneLePart, sup_mul, one_mul, leOnePart, mul_sup, mul_one, mul_inv_self, sup_assoc,
← sup_assoc a, sup_eq_right.2 le_sup_right]
exact sup_eq_left.2 <| one_le_mabs a
@[to_additive] lemma leOnePart_mul_oneLePart (a : α) : a⁻ᵐ * a⁺ᵐ = |a|ₘ := by
rw [oneLePart, mul_sup, mul_one, leOnePart, sup_mul, one_mul, inv_mul_self, sup_assoc,
← @sup_assoc _ _ a, sup_eq_right.2 le_sup_right]
exact sup_eq_left.2 <| one_le_mabs a
-- Bourbaki A.VI.12 Prop 9 a)
-- a⁺ᵐ ⊓ a⁻ᵐ = 0 (`a⁺` and `a⁻` are co-prime, and, since they are positive, disjoint)
@[to_additive] lemma oneLePart_inf_leOnePart_eq_one (a : α) : a⁺ᵐ ⊓ a⁻ᵐ = 1 := by
rw [← mul_left_inj a⁻ᵐ⁻¹, inf_mul, one_mul, mul_right_inv, ← div_eq_mul_inv,
oneLePart_div_leOnePart, leOnePart_eq_inv_inf_one, inv_inv]
end covariantmulop
end covariantmul
end Group
section CommGroup
variable [CommGroup α] [CovariantClass α α (· * ·) (· ≤ ·)]
-- Bourbaki A.VI.12 (with a and b swapped)
@[to_additive] lemma sup_eq_mul_oneLePart_div (a b : α) : a ⊔ b = b * (a / b)⁺ᵐ := by
simp [oneLePart, mul_sup]
-- Bourbaki A.VI.12 (with a and b swapped)
@[to_additive] lemma inf_eq_div_oneLePart_div (a b : α) : a ⊓ b = a / (a / b)⁺ᵐ := by
simp [oneLePart, div_sup, inf_comm]
-- Bourbaki A.VI.12 Prop 9 c)
@[to_additive] lemma le_iff_oneLePart_leOnePart (a b : α) : a ≤ b ↔ a⁺ᵐ ≤ b⁺ᵐ ∧ b⁻ᵐ ≤ a⁻ᵐ := by
refine ⟨fun h ↦ ⟨oneLePart_mono h, leOnePart_anti h⟩, fun h ↦ ?_⟩
rw [← oneLePart_div_leOnePart a, ← oneLePart_div_leOnePart b]
exact div_le_div'' h.1 h.2
@[to_additive abs_add_eq_two_nsmul_posPart]
lemma mabs_mul_eq_oneLePart_sq (a : α) : |a|ₘ * a = a⁺ᵐ ^ 2 := by
rw [sq, ← mul_mul_div_cancel a⁺ᵐ, oneLePart_mul_leOnePart, oneLePart_div_leOnePart]
@[to_additive add_abs_eq_two_nsmul_posPart]
lemma mul_mabs_eq_oneLePart_sq (a : α) : a * |a|ₘ = a⁺ᵐ ^ 2 := by
rw [mul_comm, mabs_mul_eq_oneLePart_sq]
@[to_additive abs_sub_eq_two_nsmul_negPart]
lemma mabs_div_eq_leOnePart_sq (a : α) : |a|ₘ / a = a⁻ᵐ ^ 2 := by
rw [sq, ← mul_div_div_cancel, oneLePart_mul_leOnePart, oneLePart_div_leOnePart]
@[to_additive sub_abs_eq_neg_two_nsmul_negPart]
lemma div_mabs_eq_inv_leOnePart_sq (a : α) : a / |a|ₘ = (a⁻ᵐ ^ 2)⁻¹ := by
rw [← mabs_div_eq_leOnePart_sq, inv_div]
end CommGroup
end Lattice
section LinearOrder
variable [LinearOrder α] [Group α] {a : α}
@[to_additive] lemma oneLePart_eq_ite : a⁺ᵐ = if 1 ≤ a then a else 1 := by
rw [oneLePart, ← maxDefault, ← sup_eq_maxDefault]; simp_rw [sup_comm]
@[to_additive (attr := simp) posPart_pos_iff] lemma one_lt_oneLePart_iff : 1 < a⁺ᵐ ↔ 1 < a :=
lt_iff_lt_of_le_iff_le $ (one_le_oneLePart _).le_iff_eq.trans oneLePart_eq_one
@[to_additive posPart_eq_of_posPart_pos]
lemma oneLePart_of_one_lt_oneLePart (ha : 1 < a⁺ᵐ) : a⁺ᵐ = a := by
rw [oneLePart, right_lt_sup, not_le] at ha; exact oneLePart_eq_self.2 ha.le
section covariantmul
variable [CovariantClass α α (· * ·) (· ≤ ·)]
@[to_additive] lemma leOnePart_eq_ite : a⁻ᵐ = if a ≤ 1 then a⁻¹ else 1 := by
simp_rw [← one_le_inv']; rw [leOnePart, ← maxDefault, ← sup_eq_maxDefault]; simp_rw [sup_comm]
@[to_additive (attr := simp) negPart_pos_iff] lemma one_lt_ltOnePart_iff : 1 < a⁻ᵐ ↔ a < 1 :=
lt_iff_lt_of_le_iff_le $ (one_le_leOnePart _).le_iff_eq.trans leOnePart_eq_one
end covariantmul
end LinearOrder
namespace Pi
variable {ι : Type*} {α : ι → Type*} [∀ i, Lattice (α i)] [∀ i, AddCommGroup (α i)]
@[to_additive (attr := simp)] lemma oneLePart_apply (f : ∀ i, α i) (i : ι) : f⁺ i = (f i)⁺ := rfl
@[to_additive (attr := simp)] lemma leOnePart_apply (f : ∀ i, α i) (i : ι) : f⁻ i = (f i)⁻ := rfl
@[to_additive] lemma oneLePart_def (f : ∀ i, α i) : f⁺ = fun i ↦ (f i)⁺ := rfl
@[to_additive] lemma leOnePart_def (f : ∀ i, α i) : f⁻ = fun i ↦ (f i)⁻ := rfl
end Pi
|
Algebra\Order\Group\Prod.lean | /-
Copyright (c) 2016 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura, Mario Carneiro, Johannes Hölzl
-/
import Mathlib.Algebra.Order.Group.Defs
import Mathlib.Algebra.Order.Monoid.Prod
/-!
# Products of ordered commutative groups.
-/
variable {α : Type*}
namespace Prod
variable {G H : Type*}
@[to_additive]
instance [OrderedCommGroup G] [OrderedCommGroup H] : OrderedCommGroup (G × H) :=
{ Prod.instCommGroup, Prod.instPartialOrder G H, Prod.instOrderedCancelCommMonoid
with }
namespace Lex
@[to_additive]
instance orderedCommGroup [OrderedCommGroup G] [OrderedCommGroup H] :
OrderedCommGroup (G ×ₗ H) where
mul_le_mul_left _ _ := mul_le_mul_left'
@[to_additive]
instance linearOrderedCommGroup [LinearOrderedCommGroup G] [LinearOrderedCommGroup H] :
LinearOrderedCommGroup (G ×ₗ H) where
__ : LinearOrder (G ×ₗ H) := inferInstance
mul_le_mul_left _ _ := mul_le_mul_left'
end Lex
end Prod
|
Algebra\Order\Group\Synonym.lean | /-
Copyright (c) 2021 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov, Yaël Dillies
-/
import Mathlib.Algebra.Group.Defs
import Mathlib.Order.Synonym
/-!
# Group structure on the order type synonyms
Transfer algebraic instances from `α` to `αᵒᵈ` and `Lex α`.
-/
open OrderDual
variable {α β : Type*}
/-! ### `OrderDual` -/
@[to_additive]
instance [h : One α] : One αᵒᵈ := h
@[to_additive]
instance [h : Mul α] : Mul αᵒᵈ := h
@[to_additive]
instance [h : Inv α] : Inv αᵒᵈ := h
@[to_additive]
instance [h : Div α] : Div αᵒᵈ := h
@[to_additive (attr := to_additive) (reorder := 1 2) OrderDual.instSMul]
instance OrderDual.instPow [h : Pow α β] : Pow αᵒᵈ β := h
@[to_additive (attr := to_additive) (reorder := 1 2) OrderDual.instSMul']
instance OrderDual.instPow' [h : Pow α β] : Pow α βᵒᵈ := h
@[to_additive]
instance [h : Semigroup α] : Semigroup αᵒᵈ := h
@[to_additive]
instance [h : CommSemigroup α] : CommSemigroup αᵒᵈ := h
@[to_additive]
instance [Mul α] [h : IsLeftCancelMul α] : IsLeftCancelMul αᵒᵈ := h
@[to_additive]
instance [Mul α] [h : IsRightCancelMul α] : IsRightCancelMul αᵒᵈ := h
@[to_additive]
instance [Mul α] [h : IsCancelMul α] : IsCancelMul αᵒᵈ := h
@[to_additive]
instance [h : LeftCancelSemigroup α] : LeftCancelSemigroup αᵒᵈ := h
@[to_additive]
instance [h : RightCancelSemigroup α] : RightCancelSemigroup αᵒᵈ := h
@[to_additive]
instance [h : MulOneClass α] : MulOneClass αᵒᵈ := h
@[to_additive]
instance [h : Monoid α] : Monoid αᵒᵈ := h
@[to_additive]
instance OrderDual.instCommMonoid [h : CommMonoid α] : CommMonoid αᵒᵈ := h
@[to_additive]
instance [h : LeftCancelMonoid α] : LeftCancelMonoid αᵒᵈ := h
@[to_additive]
instance [h : RightCancelMonoid α] : RightCancelMonoid αᵒᵈ := h
@[to_additive]
instance [h : CancelMonoid α] : CancelMonoid αᵒᵈ := h
@[to_additive]
instance OrderDual.instCancelCommMonoid [h : CancelCommMonoid α] : CancelCommMonoid αᵒᵈ := h
@[to_additive]
instance [h : InvolutiveInv α] : InvolutiveInv αᵒᵈ := h
@[to_additive]
instance [h : DivInvMonoid α] : DivInvMonoid αᵒᵈ := h
@[to_additive OrderDual.subtractionMonoid]
instance [h : DivisionMonoid α] : DivisionMonoid αᵒᵈ := h
@[to_additive OrderDual.subtractionCommMonoid]
instance [h : DivisionCommMonoid α] : DivisionCommMonoid αᵒᵈ := h
@[to_additive]
instance OrderDual.instGroup [h : Group α] : Group αᵒᵈ := h
@[to_additive]
instance [h : CommGroup α] : CommGroup αᵒᵈ := h
@[to_additive (attr := simp)]
theorem toDual_one [One α] : toDual (1 : α) = 1 := rfl
@[to_additive (attr := simp)]
theorem ofDual_one [One α] : (ofDual 1 : α) = 1 := rfl
@[to_additive (attr := simp)]
theorem toDual_mul [Mul α] (a b : α) : toDual (a * b) = toDual a * toDual b := rfl
@[to_additive (attr := simp)]
theorem ofDual_mul [Mul α] (a b : αᵒᵈ) : ofDual (a * b) = ofDual a * ofDual b := rfl
@[to_additive (attr := simp)]
theorem toDual_inv [Inv α] (a : α) : toDual a⁻¹ = (toDual a)⁻¹ := rfl
@[to_additive (attr := simp)]
theorem ofDual_inv [Inv α] (a : αᵒᵈ) : ofDual a⁻¹ = (ofDual a)⁻¹ := rfl
@[to_additive (attr := simp)]
theorem toDual_div [Div α] (a b : α) : toDual (a / b) = toDual a / toDual b := rfl
@[to_additive (attr := simp)]
theorem ofDual_div [Div α] (a b : αᵒᵈ) : ofDual (a / b) = ofDual a / ofDual b := rfl
@[to_additive (attr := simp, to_additive) (reorder := 1 2, 4 5) toDual_smul]
theorem toDual_pow [Pow α β] (a : α) (b : β) : toDual (a ^ b) = toDual a ^ b := rfl
@[to_additive (attr := simp, to_additive) (reorder := 1 2, 4 5) ofDual_smul]
theorem ofDual_pow [Pow α β] (a : αᵒᵈ) (b : β) : ofDual (a ^ b) = ofDual a ^ b := rfl
@[to_additive (attr := simp, to_additive) (reorder := 1 2, 4 5) toDual_smul']
theorem pow_toDual [Pow α β] (a : α) (b : β) : a ^ toDual b = a ^ b := rfl
@[to_additive (attr := simp, to_additive) (reorder := 1 2, 4 5) ofDual_smul']
theorem pow_ofDual [Pow α β] (a : α) (b : βᵒᵈ) : a ^ ofDual b = a ^ b := rfl
/-! ### Lexicographical order -/
@[to_additive]
instance [h : One α] : One (Lex α) := h
@[to_additive]
instance [h : Mul α] : Mul (Lex α) := h
@[to_additive]
instance [h : Inv α] : Inv (Lex α) := h
@[to_additive]
instance [h : Div α] : Div (Lex α) := h
@[to_additive (attr := to_additive) (reorder := 1 2) Lex.instSMul]
instance Lex.instPow [h : Pow α β] : Pow (Lex α) β := h
@[to_additive (attr := to_additive) (reorder := 1 2) Lex.instSMul']
instance Lex.instPow' [h : Pow α β] : Pow α (Lex β) := h
@[to_additive]
instance [h : Semigroup α] : Semigroup (Lex α) := h
@[to_additive]
instance [h : CommSemigroup α] : CommSemigroup (Lex α) := h
@[to_additive]
instance [h : LeftCancelSemigroup α] : LeftCancelSemigroup (Lex α) := h
@[to_additive]
instance [h : RightCancelSemigroup α] : RightCancelSemigroup (Lex α) := h
@[to_additive]
instance [h : MulOneClass α] : MulOneClass (Lex α) := h
@[to_additive]
instance [h : Monoid α] : Monoid (Lex α) := h
@[to_additive]
instance [h : CommMonoid α] : CommMonoid (Lex α) := h
@[to_additive]
instance [h : LeftCancelMonoid α] : LeftCancelMonoid (Lex α) := h
@[to_additive]
instance [h : RightCancelMonoid α] : RightCancelMonoid (Lex α) := h
@[to_additive]
instance [h : CancelMonoid α] : CancelMonoid (Lex α) := h
@[to_additive]
instance [h : CancelCommMonoid α] : CancelCommMonoid (Lex α) := h
@[to_additive]
instance [h : InvolutiveInv α] : InvolutiveInv (Lex α) := h
@[to_additive]
instance [h : DivInvMonoid α] : DivInvMonoid (Lex α) := h
@[to_additive existing OrderDual.subtractionMonoid]
instance [h : DivisionMonoid α] : DivisionMonoid (Lex α) := h
@[to_additive existing OrderDual.subtractionCommMonoid]
instance [h : DivisionCommMonoid α] : DivisionCommMonoid (Lex α) := h
@[to_additive]
instance [h : Group α] : Group (Lex α) := h
@[to_additive]
instance [h : CommGroup α] : CommGroup (Lex α) := h
@[to_additive (attr := simp)]
theorem toLex_one [One α] : toLex (1 : α) = 1 := rfl
@[to_additive (attr := simp)]
theorem ofLex_one [One α] : (ofLex 1 : α) = 1 := rfl
@[to_additive (attr := simp)]
theorem toLex_mul [Mul α] (a b : α) : toLex (a * b) = toLex a * toLex b := rfl
@[to_additive (attr := simp)]
theorem ofLex_mul [Mul α] (a b : Lex α) : ofLex (a * b) = ofLex a * ofLex b := rfl
@[to_additive (attr := simp)]
theorem toLex_inv [Inv α] (a : α) : toLex a⁻¹ = (toLex a)⁻¹ := rfl
@[to_additive (attr := simp)]
theorem ofLex_inv [Inv α] (a : Lex α) : ofLex a⁻¹ = (ofLex a)⁻¹ := rfl
@[to_additive (attr := simp)]
theorem toLex_div [Div α] (a b : α) : toLex (a / b) = toLex a / toLex b := rfl
@[to_additive (attr := simp)]
theorem ofLex_div [Div α] (a b : Lex α) : ofLex (a / b) = ofLex a / ofLex b := rfl
@[to_additive (attr := simp, to_additive) (reorder := 1 2, 4 5) toLex_smul]
theorem toLex_pow [Pow α β] (a : α) (b : β) : toLex (a ^ b) = toLex a ^ b := rfl
@[to_additive (attr := simp, to_additive) (reorder := 1 2, 4 5) ofLex_smul]
theorem ofLex_pow [Pow α β] (a : Lex α) (b : β) : ofLex (a ^ b) = ofLex a ^ b := rfl
@[to_additive (attr := simp, to_additive) (reorder := 1 2, 4 5) toLex_smul']
theorem pow_toLex [Pow α β] (a : α) (b : β) : a ^ toLex b = a ^ b := rfl
@[to_additive (attr := simp, to_additive) (reorder := 1 2, 4 5) ofLex_smul']
theorem pow_ofLex [Pow α β] (a : α) (b : Lex β) : a ^ ofLex b = a ^ b := rfl
|
Algebra\Order\Group\TypeTags.lean | /-
Copyright (c) 2016 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura, Mario Carneiro, Johannes Hölzl
-/
import Mathlib.Algebra.Order.Group.Defs
import Mathlib.Algebra.Order.Monoid.TypeTags
/-! # Ordered group structures on `Multiplicative α` and `Additive α`. -/
variable {α : Type*}
instance Multiplicative.orderedCommGroup [OrderedAddCommGroup α] :
OrderedCommGroup (Multiplicative α) :=
{ Multiplicative.commGroup, Multiplicative.orderedCommMonoid with }
instance Additive.orderedAddCommGroup [OrderedCommGroup α] :
OrderedAddCommGroup (Additive α) :=
{ Additive.addCommGroup, Additive.orderedAddCommMonoid with }
instance Multiplicative.linearOrderedCommGroup [LinearOrderedAddCommGroup α] :
LinearOrderedCommGroup (Multiplicative α) :=
{ Multiplicative.linearOrder, Multiplicative.orderedCommGroup with }
instance Additive.linearOrderedAddCommGroup [LinearOrderedCommGroup α] :
LinearOrderedAddCommGroup (Additive α) :=
{ Additive.linearOrder, Additive.orderedAddCommGroup with }
|
Algebra\Order\Group\Units.lean | /-
Copyright (c) 2016 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura, Mario Carneiro, Johannes Hölzl
-/
import Mathlib.Algebra.Order.Group.Defs
import Mathlib.Algebra.Order.Monoid.Defs
import Mathlib.Algebra.Order.Monoid.Units
/-!
# The units of an ordered commutative monoid form an ordered commutative group
-/
variable {α : Type*}
/-- The units of an ordered commutative monoid form an ordered commutative group. -/
@[to_additive
"The units of an ordered commutative additive monoid form an ordered commutative
additive group."]
instance Units.orderedCommGroup [OrderedCommMonoid α] : OrderedCommGroup αˣ :=
{ Units.instPartialOrderUnits, Units.instCommGroupUnits with
mul_le_mul_left := fun _ _ h _ => (@mul_le_mul_left' α _ _ _ _ _ h _) }
-- Porting note: the mathlib3 proof was
-- mul_le_mul_left := fun a b h c => (mul_le_mul_left' (h : (a : α) ≤ b) _ : (c : α) * a ≤ c * b) }
-- see https://leanprover.zulipchat.com/#narrow/stream/287929-mathlib4/topic/elaboration.20failure.20in.20algebra.2Eorder.2Egroup.2Eunits
|
Algebra\Order\Group\Unbundled\Abs.lean | /-
Copyright (c) 2016 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura, Mario Carneiro, Johannes Hölzl
-/
import Mathlib.Algebra.Group.Even
import Mathlib.Algebra.Order.Group.Lattice
/-!
# Absolute values in ordered groups
The absolute value of an element in a group which is also a lattice is its supremum with its
negation. This generalizes the usual absolute value on real numbers (`|x| = max x (-x)`).
## Notations
- `|a|`: The *absolute value* of an element `a` of an additive lattice ordered group
- `|a|ₘ`: The *absolute value* of an element `a` of a multiplicative lattice ordered group
-/
open Function
variable {α : Type*}
section Lattice
variable [Lattice α]
section Group
variable [Group α] {a b : α}
/-- `mabs a` is the absolute value of `a`. -/
@[to_additive "`abs a` is the absolute value of `a`"] def mabs (a : α) : α := a ⊔ a⁻¹
@[inherit_doc mabs]
macro:max atomic("|" noWs) a:term noWs "|ₘ" : term => `(mabs $a)
@[inherit_doc abs]
macro:max atomic("|" noWs) a:term noWs "|" : term => `(abs $a)
/-- Unexpander for the notation `|a|ₘ` for `mabs a`.
Tries to add discretionary parentheses in unparseable cases. -/
@[app_unexpander abs]
def mabs.unexpander : Lean.PrettyPrinter.Unexpander
| `($_ $a) =>
match a with
| `(|$_|ₘ) | `(-$_) => `(|($a)|ₘ)
| _ => `(|$a|ₘ)
| _ => throw ()
/-- Unexpander for the notation `|a|` for `abs a`.
Tries to add discretionary parentheses in unparseable cases. -/
@[app_unexpander abs]
def abs.unexpander : Lean.PrettyPrinter.Unexpander
| `($_ $a) =>
match a with
| `(|$_|) | `(-$_) => `(|($a)|)
| _ => `(|$a|)
| _ => throw ()
@[to_additive] lemma mabs_le' : |a|ₘ ≤ b ↔ a ≤ b ∧ a⁻¹ ≤ b := sup_le_iff
@[to_additive] lemma le_mabs_self (a : α) : a ≤ |a|ₘ := le_sup_left
@[to_additive] lemma inv_le_mabs (a : α) : a⁻¹ ≤ |a|ₘ := le_sup_right
@[to_additive] lemma mabs_le_mabs (h₀ : a ≤ b) (h₁ : a⁻¹ ≤ b) : |a|ₘ ≤ |b|ₘ :=
(mabs_le'.2 ⟨h₀, h₁⟩).trans (le_mabs_self b)
@[to_additive (attr := simp)] lemma mabs_inv (a : α) : |a⁻¹|ₘ = |a|ₘ := by simp [mabs, sup_comm]
@[to_additive] lemma mabs_div_comm (a b : α) : |a / b|ₘ = |b / a|ₘ := by rw [← mabs_inv, inv_div]
variable [CovariantClass α α (· * ·) (· ≤ ·)]
@[to_additive] lemma mabs_of_one_le (h : 1 ≤ a) : |a|ₘ = a :=
sup_eq_left.2 <| (inv_le_one'.2 h).trans h
@[to_additive] lemma mabs_of_one_lt (h : 1 < a) : |a|ₘ = a := mabs_of_one_le h.le
@[to_additive] lemma mabs_of_le_one (h : a ≤ 1) : |a|ₘ = a⁻¹ :=
sup_eq_right.2 <| h.trans (one_le_inv'.2 h)
@[to_additive] lemma mabs_of_lt_one (h : a < 1) : |a|ₘ = a⁻¹ := mabs_of_le_one h.le
@[to_additive] lemma mabs_le_mabs_of_one_le (ha : 1 ≤ a) (hab : a ≤ b) : |a|ₘ ≤ |b|ₘ := by
rwa [mabs_of_one_le ha, mabs_of_one_le (ha.trans hab)]
attribute [gcongr] abs_le_abs_of_nonneg
@[to_additive (attr := simp)] lemma mabs_one : |(1 : α)|ₘ = 1 := mabs_of_one_le le_rfl
variable [CovariantClass α α (swap (· * ·)) (· ≤ ·)]
@[to_additive (attr := simp) abs_nonneg] lemma one_le_mabs (a : α) : 1 ≤ |a|ₘ := by
apply pow_two_semiclosed _
rw [mabs, pow_two, mul_sup, sup_mul, ← pow_two, mul_left_inv, sup_comm, ← sup_assoc]
apply le_sup_right
@[to_additive (attr := simp)] lemma mabs_mabs (a : α) : |(|a|ₘ)|ₘ = |a|ₘ :=
mabs_of_one_le <| one_le_mabs a
end Group
section CommGroup
variable [CommGroup α] [CovariantClass α α (· * ·) (· ≤ ·)] {a b : α}
-- Banasiak Proposition 2.12, Zaanen 2nd lecture
/-- The absolute value satisfies the triangle inequality. -/
@[to_additive "The absolute value satisfies the triangle inequality."]
lemma mabs_mul_le (a b : α) : |a * b|ₘ ≤ |a|ₘ * |b|ₘ := by
apply sup_le
· exact mul_le_mul' (le_mabs_self a) (le_mabs_self b)
· rw [mul_inv]
exact mul_le_mul' (inv_le_mabs _) (inv_le_mabs _)
@[to_additive]
lemma mabs_mabs_div_mabs_le (a b : α) : |(|a|ₘ / |b|ₘ)|ₘ ≤ |a / b|ₘ := by
rw [mabs, sup_le_iff]
constructor
· apply div_le_iff_le_mul.2
convert mabs_mul_le (a / b) b
rw [div_mul_cancel]
· rw [div_eq_mul_inv, mul_inv_rev, inv_inv, mul_inv_le_iff_le_mul, mabs_div_comm]
convert mabs_mul_le (b / a) a
· rw [div_mul_cancel]
@[to_additive] lemma sup_div_inf_eq_mabs_div (a b : α) : (a ⊔ b) / (a ⊓ b) = |b / a|ₘ := by
simp_rw [sup_div, div_inf, div_self', sup_comm, sup_sup_sup_comm, sup_idem]
rw [← inv_div, sup_comm (b := _ / _), ← mabs, sup_eq_left]
exact one_le_mabs _
@[to_additive two_nsmul_sup_eq_add_add_abs_sub]
lemma sup_sq_eq_mul_mul_mabs_div (a b : α) : (a ⊔ b) ^ 2 = a * b * |b / a|ₘ := by
rw [← inf_mul_sup a b, ← sup_div_inf_eq_mabs_div, div_eq_mul_inv, ← mul_assoc, mul_comm,
mul_assoc, ← pow_two, inv_mul_cancel_left]
@[to_additive two_nsmul_inf_eq_add_sub_abs_sub]
lemma inf_sq_eq_mul_div_mabs_div (a b : α) : (a ⊓ b) ^ 2 = a * b / |b / a|ₘ := by
rw [← inf_mul_sup a b, ← sup_div_inf_eq_mabs_div, div_eq_mul_inv, div_eq_mul_inv, mul_inv_rev,
inv_inv, mul_assoc, mul_inv_cancel_comm_assoc, ← pow_two]
-- See, e.g. Zaanen, Lectures on Riesz Spaces
-- 3rd lecture
@[to_additive]
lemma mabs_div_sup_mul_mabs_div_inf (a b c : α) :
|(a ⊔ c) / (b ⊔ c)|ₘ * |(a ⊓ c) / (b ⊓ c)|ₘ = |a / b|ₘ := by
letI : DistribLattice α := CommGroup.toDistribLattice α
calc
|(a ⊔ c) / (b ⊔ c)|ₘ * |(a ⊓ c) / (b ⊓ c)|ₘ =
(b ⊔ c ⊔ (a ⊔ c)) / ((b ⊔ c) ⊓ (a ⊔ c)) * |(a ⊓ c) / (b ⊓ c)|ₘ := by
rw [sup_div_inf_eq_mabs_div]
_ = (b ⊔ c ⊔ (a ⊔ c)) / ((b ⊔ c) ⊓ (a ⊔ c)) * ((b ⊓ c ⊔ a ⊓ c) / (b ⊓ c ⊓ (a ⊓ c))) := by
rw [sup_div_inf_eq_mabs_div (b ⊓ c) (a ⊓ c)]
_ = (b ⊔ a ⊔ c) / (b ⊓ a ⊔ c) * (((b ⊔ a) ⊓ c) / (b ⊓ a ⊓ c)) := by
rw [← sup_inf_right, ← inf_sup_right, sup_assoc, sup_comm c (a ⊔ c), sup_right_idem,
sup_assoc, inf_assoc, inf_comm c (a ⊓ c), inf_right_idem, inf_assoc]
_ = (b ⊔ a ⊔ c) * ((b ⊔ a) ⊓ c) / ((b ⊓ a ⊔ c) * (b ⊓ a ⊓ c)) := by rw [div_mul_div_comm]
_ = (b ⊔ a) * c / ((b ⊓ a) * c) := by
rw [mul_comm, inf_mul_sup, mul_comm (b ⊓ a ⊔ c), inf_mul_sup]
_ = (b ⊔ a) / (b ⊓ a) := by
rw [div_eq_mul_inv, mul_inv_rev, mul_assoc, mul_inv_cancel_left, ← div_eq_mul_inv]
_ = |a / b|ₘ := by rw [sup_div_inf_eq_mabs_div]
@[to_additive] lemma mabs_sup_div_sup_le_mabs (a b c : α) : |(a ⊔ c) / (b ⊔ c)|ₘ ≤ |a / b|ₘ := by
apply le_of_mul_le_of_one_le_left _ (one_le_mabs _); rw [mabs_div_sup_mul_mabs_div_inf]
@[to_additive] lemma mabs_inf_div_inf_le_mabs (a b c : α) : |(a ⊓ c) / (b ⊓ c)|ₘ ≤ |a / b|ₘ := by
apply le_of_mul_le_of_one_le_right _ (one_le_mabs _); rw [mabs_div_sup_mul_mabs_div_inf]
-- Commutative case, Zaanen, 3rd lecture
-- For the non-commutative case, see Birkhoff Theorem 19 (27)
@[to_additive Birkhoff_inequalities]
lemma m_Birkhoff_inequalities (a b c : α) :
|(a ⊔ c) / (b ⊔ c)|ₘ ⊔ |(a ⊓ c) / (b ⊓ c)|ₘ ≤ |a / b|ₘ :=
sup_le (mabs_sup_div_sup_le_mabs a b c) (mabs_inf_div_inf_le_mabs a b c)
end CommGroup
end Lattice
section LinearOrder
variable [Group α] [LinearOrder α] {a b : α}
@[to_additive] lemma mabs_choice (x : α) : |x|ₘ = x ∨ |x|ₘ = x⁻¹ := max_choice _ _
@[to_additive] lemma le_mabs : a ≤ |b|ₘ ↔ a ≤ b ∨ a ≤ b⁻¹ := le_max_iff
@[to_additive] lemma mabs_eq_max_inv : |a|ₘ = max a a⁻¹ := rfl
@[to_additive] lemma lt_mabs : a < |b|ₘ ↔ a < b ∨ a < b⁻¹ := lt_max_iff
@[to_additive] lemma mabs_by_cases (P : α → Prop) (h1 : P a) (h2 : P a⁻¹) : P |a|ₘ :=
sup_ind _ _ h1 h2
@[to_additive] lemma eq_or_eq_inv_of_mabs_eq (h : |a|ₘ = b) : a = b ∨ a = b⁻¹ := by
simpa only [← h, eq_comm (a := |a|ₘ), inv_eq_iff_eq_inv] using mabs_choice a
@[to_additive] lemma mabs_eq_mabs : |a|ₘ = |b|ₘ ↔ a = b ∨ a = b⁻¹ := by
refine ⟨fun h ↦ ?_, by rintro (h | h) <;> simp [h, abs_neg]⟩
obtain rfl | rfl := eq_or_eq_inv_of_mabs_eq h <;>
simpa only [inv_eq_iff_eq_inv (a := |b|ₘ), inv_inv, inv_inj, or_comm] using mabs_choice b
@[to_additive] lemma isSquare_mabs : IsSquare |a|ₘ ↔ IsSquare a :=
mabs_by_cases (IsSquare · ↔ _) Iff.rfl isSquare_inv
@[to_additive] lemma lt_of_mabs_lt : |a|ₘ < b → a < b := (le_mabs_self _).trans_lt
variable [CovariantClass α α (· * ·) (· ≤ ·)] {a b c : α}
@[to_additive (attr := simp) abs_pos] lemma one_lt_mabs : 1 < |a|ₘ ↔ a ≠ 1 := by
obtain ha | rfl | ha := lt_trichotomy a 1
· simp [mabs_of_lt_one ha, neg_pos, ha.ne, ha]
· simp
· simp [mabs_of_one_lt ha, ha, ha.ne']
@[to_additive abs_pos_of_pos] lemma one_lt_mabs_pos_of_one_lt (h : 1 < a) : 1 < |a|ₘ :=
one_lt_mabs.2 h.ne'
@[to_additive abs_pos_of_neg] lemma one_lt_mabs_of_lt_one (h : a < 1) : 1 < |a|ₘ :=
one_lt_mabs.2 h.ne
@[to_additive] lemma inv_mabs_le (a : α) : |a|ₘ⁻¹ ≤ a := by
obtain h | h := le_total 1 a
· simpa [mabs_of_one_le h] using (inv_le_one'.2 h).trans h
· simp [mabs_of_le_one h]
@[to_additive add_abs_nonneg] lemma one_le_mul_mabs (a : α) : 1 ≤ a * |a|ₘ := by
rw [← mul_right_inv a]; exact mul_le_mul_left' (inv_le_mabs a) _
@[to_additive] lemma inv_mabs_le_inv (a : α) : |a|ₘ⁻¹ ≤ a⁻¹ := by simpa using inv_mabs_le a⁻¹
variable [CovariantClass α α (swap (· * ·)) (· ≤ ·)]
@[to_additive] lemma mabs_ne_one : |a|ₘ ≠ 1 ↔ a ≠ 1 :=
(one_le_mabs a).gt_iff_ne.symm.trans one_lt_mabs
@[to_additive (attr := simp)] lemma mabs_eq_one : |a|ₘ = 1 ↔ a = 1 := not_iff_not.1 mabs_ne_one
@[to_additive (attr := simp) abs_nonpos_iff] lemma mabs_le_one : |a|ₘ ≤ 1 ↔ a = 1 :=
(one_le_mabs a).le_iff_eq.trans mabs_eq_one
@[to_additive] lemma mabs_le_mabs_of_le_one (ha : a ≤ 1) (hab : b ≤ a) : |a|ₘ ≤ |b|ₘ := by
rw [mabs_of_le_one ha, mabs_of_le_one (hab.trans ha)]; exact inv_le_inv_iff.mpr hab
@[to_additive] lemma mabs_lt : |a|ₘ < b ↔ b⁻¹ < a ∧ a < b :=
max_lt_iff.trans <| and_comm.trans <| by rw [inv_lt']
@[to_additive] lemma inv_lt_of_mabs_lt (h : |a|ₘ < b) : b⁻¹ < a := (mabs_lt.mp h).1
@[to_additive] lemma max_div_min_eq_mabs' (a b : α) : max a b / min a b = |a / b|ₘ := by
rcases le_total a b with ab | ba
· rw [max_eq_right ab, min_eq_left ab, mabs_of_le_one, inv_div]
rwa [div_le_one']
· rw [max_eq_left ba, min_eq_right ba, mabs_of_one_le]
rwa [one_le_div']
@[to_additive] lemma max_div_min_eq_mabs (a b : α) : max a b / min a b = |b / a|ₘ := by
rw [mabs_div_comm, max_div_min_eq_mabs']
end LinearOrder
namespace LatticeOrderedAddCommGroup
variable [Lattice α] [AddCommGroup α] {s t : Set α}
/-- A set `s` in a lattice ordered group is *solid* if for all `x ∈ s` and all `y ∈ α` such that
`|y| ≤ |x|`, then `y ∈ s`. -/
def IsSolid (s : Set α) : Prop := ∀ ⦃x⦄, x ∈ s → ∀ ⦃y⦄, |y| ≤ |x| → y ∈ s
/-- The solid closure of a subset `s` is the smallest superset of `s` that is solid. -/
def solidClosure (s : Set α) : Set α := {y | ∃ x ∈ s, |y| ≤ |x|}
lemma isSolid_solidClosure (s : Set α) : IsSolid (solidClosure s) :=
fun _ ⟨y, hy, hxy⟩ _ hzx ↦ ⟨y, hy, hzx.trans hxy⟩
lemma solidClosure_min (hst : s ⊆ t) (ht : IsSolid t) : solidClosure s ⊆ t :=
fun _ ⟨_, hy, hxy⟩ ↦ ht (hst hy) hxy
end LatticeOrderedAddCommGroup
namespace Pi
variable {ι : Type*} {α : ι → Type*} [∀ i, AddGroup (α i)] [∀ i, Lattice (α i)]
@[simp] lemma abs_apply (f : ∀ i, α i) (i : ι) : |f| i = |f i| := rfl
lemma abs_def (f : ∀ i, α i) : |f| = fun i ↦ |f i| := rfl
end Pi
@[deprecated (since := "2024-01-13")] alias neg_le_abs_self := neg_le_abs
@[deprecated (since := "2024-01-13")] alias neg_abs_le_self := neg_abs_le
|
Algebra\Order\Group\Unbundled\Basic.lean | /-
Copyright (c) 2016 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura, Mario Carneiro, Johannes Hölzl
-/
import Mathlib.Algebra.Order.Monoid.Unbundled.Basic
import Mathlib.Algebra.Order.Sub.Defs
import Mathlib.Util.AssertExists
/-!
# Ordered groups
This file develops the basics of unbundled ordered groups.
## Implementation details
Unfortunately, the number of `'` appended to lemmas in this file
may differ between the multiplicative and the additive version of a lemma.
The reason is that we did not want to change existing names in the library.
-/
assert_not_exists OrderedCommMonoid
open Function
universe u
variable {α : Type u}
section Group
variable [Group α]
section TypeclassesLeftLE
variable [LE α] [CovariantClass α α (· * ·) (· ≤ ·)] {a b c d : α}
/-- Uses `left` co(ntra)variant. -/
@[to_additive (attr := simp) "Uses `left` co(ntra)variant."]
theorem Left.inv_le_one_iff : a⁻¹ ≤ 1 ↔ 1 ≤ a := by
rw [← mul_le_mul_iff_left a]
simp
/-- Uses `left` co(ntra)variant. -/
@[to_additive (attr := simp) "Uses `left` co(ntra)variant."]
theorem Left.one_le_inv_iff : 1 ≤ a⁻¹ ↔ a ≤ 1 := by
rw [← mul_le_mul_iff_left a]
simp
@[to_additive (attr := simp)]
theorem le_inv_mul_iff_mul_le : b ≤ a⁻¹ * c ↔ a * b ≤ c := by
rw [← mul_le_mul_iff_left a]
simp
@[to_additive (attr := simp)]
theorem inv_mul_le_iff_le_mul : b⁻¹ * a ≤ c ↔ a ≤ b * c := by
rw [← mul_le_mul_iff_left b, mul_inv_cancel_left]
@[to_additive neg_le_iff_add_nonneg']
theorem inv_le_iff_one_le_mul' : a⁻¹ ≤ b ↔ 1 ≤ a * b :=
(mul_le_mul_iff_left a).symm.trans <| by rw [mul_inv_self]
@[to_additive]
theorem le_inv_iff_mul_le_one_left : a ≤ b⁻¹ ↔ b * a ≤ 1 :=
(mul_le_mul_iff_left b).symm.trans <| by rw [mul_inv_self]
@[to_additive]
theorem le_inv_mul_iff_le : 1 ≤ b⁻¹ * a ↔ b ≤ a := by
rw [← mul_le_mul_iff_left b, mul_one, mul_inv_cancel_left]
@[to_additive]
theorem inv_mul_le_one_iff : a⁻¹ * b ≤ 1 ↔ b ≤ a :=
-- Porting note: why is the `_root_` needed?
_root_.trans inv_mul_le_iff_le_mul <| by rw [mul_one]
end TypeclassesLeftLE
section TypeclassesLeftLT
variable [LT α] [CovariantClass α α (· * ·) (· < ·)] {a b c : α}
/-- Uses `left` co(ntra)variant. -/
@[to_additive (attr := simp) Left.neg_pos_iff "Uses `left` co(ntra)variant."]
theorem Left.one_lt_inv_iff : 1 < a⁻¹ ↔ a < 1 := by
rw [← mul_lt_mul_iff_left a, mul_inv_self, mul_one]
/-- Uses `left` co(ntra)variant. -/
@[to_additive (attr := simp) "Uses `left` co(ntra)variant."]
theorem Left.inv_lt_one_iff : a⁻¹ < 1 ↔ 1 < a := by
rw [← mul_lt_mul_iff_left a, mul_inv_self, mul_one]
@[to_additive (attr := simp)]
theorem lt_inv_mul_iff_mul_lt : b < a⁻¹ * c ↔ a * b < c := by
rw [← mul_lt_mul_iff_left a]
simp
@[to_additive (attr := simp)]
theorem inv_mul_lt_iff_lt_mul : b⁻¹ * a < c ↔ a < b * c := by
rw [← mul_lt_mul_iff_left b, mul_inv_cancel_left]
@[to_additive]
theorem inv_lt_iff_one_lt_mul' : a⁻¹ < b ↔ 1 < a * b :=
(mul_lt_mul_iff_left a).symm.trans <| by rw [mul_inv_self]
@[to_additive]
theorem lt_inv_iff_mul_lt_one' : a < b⁻¹ ↔ b * a < 1 :=
(mul_lt_mul_iff_left b).symm.trans <| by rw [mul_inv_self]
@[to_additive]
theorem lt_inv_mul_iff_lt : 1 < b⁻¹ * a ↔ b < a := by
rw [← mul_lt_mul_iff_left b, mul_one, mul_inv_cancel_left]
@[to_additive]
theorem inv_mul_lt_one_iff : a⁻¹ * b < 1 ↔ b < a :=
_root_.trans inv_mul_lt_iff_lt_mul <| by rw [mul_one]
end TypeclassesLeftLT
section TypeclassesRightLE
variable [LE α] [CovariantClass α α (swap (· * ·)) (· ≤ ·)] {a b c : α}
/-- Uses `right` co(ntra)variant. -/
@[to_additive (attr := simp) "Uses `right` co(ntra)variant."]
theorem Right.inv_le_one_iff : a⁻¹ ≤ 1 ↔ 1 ≤ a := by
rw [← mul_le_mul_iff_right a]
simp
/-- Uses `right` co(ntra)variant. -/
@[to_additive (attr := simp) "Uses `right` co(ntra)variant."]
theorem Right.one_le_inv_iff : 1 ≤ a⁻¹ ↔ a ≤ 1 := by
rw [← mul_le_mul_iff_right a]
simp
@[to_additive neg_le_iff_add_nonneg]
theorem inv_le_iff_one_le_mul : a⁻¹ ≤ b ↔ 1 ≤ b * a :=
(mul_le_mul_iff_right a).symm.trans <| by rw [inv_mul_self]
@[to_additive]
theorem le_inv_iff_mul_le_one_right : a ≤ b⁻¹ ↔ a * b ≤ 1 :=
(mul_le_mul_iff_right b).symm.trans <| by rw [inv_mul_self]
@[to_additive (attr := simp)]
theorem mul_inv_le_iff_le_mul : a * b⁻¹ ≤ c ↔ a ≤ c * b :=
(mul_le_mul_iff_right b).symm.trans <| by rw [inv_mul_cancel_right]
@[to_additive (attr := simp)]
theorem le_mul_inv_iff_mul_le : c ≤ a * b⁻¹ ↔ c * b ≤ a :=
(mul_le_mul_iff_right b).symm.trans <| by rw [inv_mul_cancel_right]
-- Porting note (#10618): `simp` can prove this
@[to_additive]
theorem mul_inv_le_one_iff_le : a * b⁻¹ ≤ 1 ↔ a ≤ b :=
mul_inv_le_iff_le_mul.trans <| by rw [one_mul]
@[to_additive]
theorem le_mul_inv_iff_le : 1 ≤ a * b⁻¹ ↔ b ≤ a := by
rw [← mul_le_mul_iff_right b, one_mul, inv_mul_cancel_right]
@[to_additive]
theorem mul_inv_le_one_iff : b * a⁻¹ ≤ 1 ↔ b ≤ a :=
_root_.trans mul_inv_le_iff_le_mul <| by rw [one_mul]
end TypeclassesRightLE
section TypeclassesRightLT
variable [LT α] [CovariantClass α α (swap (· * ·)) (· < ·)] {a b c : α}
/-- Uses `right` co(ntra)variant. -/
@[to_additive (attr := simp) "Uses `right` co(ntra)variant."]
theorem Right.inv_lt_one_iff : a⁻¹ < 1 ↔ 1 < a := by
rw [← mul_lt_mul_iff_right a, inv_mul_self, one_mul]
/-- Uses `right` co(ntra)variant. -/
@[to_additive (attr := simp) Right.neg_pos_iff "Uses `right` co(ntra)variant."]
theorem Right.one_lt_inv_iff : 1 < a⁻¹ ↔ a < 1 := by
rw [← mul_lt_mul_iff_right a, inv_mul_self, one_mul]
@[to_additive]
theorem inv_lt_iff_one_lt_mul : a⁻¹ < b ↔ 1 < b * a :=
(mul_lt_mul_iff_right a).symm.trans <| by rw [inv_mul_self]
@[to_additive]
theorem lt_inv_iff_mul_lt_one : a < b⁻¹ ↔ a * b < 1 :=
(mul_lt_mul_iff_right b).symm.trans <| by rw [inv_mul_self]
@[to_additive (attr := simp)]
theorem mul_inv_lt_iff_lt_mul : a * b⁻¹ < c ↔ a < c * b := by
rw [← mul_lt_mul_iff_right b, inv_mul_cancel_right]
@[to_additive (attr := simp)]
theorem lt_mul_inv_iff_mul_lt : c < a * b⁻¹ ↔ c * b < a :=
(mul_lt_mul_iff_right b).symm.trans <| by rw [inv_mul_cancel_right]
-- Porting note (#10618): `simp` can prove this
@[to_additive]
theorem inv_mul_lt_one_iff_lt : a * b⁻¹ < 1 ↔ a < b := by
rw [← mul_lt_mul_iff_right b, inv_mul_cancel_right, one_mul]
@[to_additive]
theorem lt_mul_inv_iff_lt : 1 < a * b⁻¹ ↔ b < a := by
rw [← mul_lt_mul_iff_right b, one_mul, inv_mul_cancel_right]
@[to_additive]
theorem mul_inv_lt_one_iff : b * a⁻¹ < 1 ↔ b < a :=
_root_.trans mul_inv_lt_iff_lt_mul <| by rw [one_mul]
end TypeclassesRightLT
section TypeclassesLeftRightLE
variable [LE α] [CovariantClass α α (· * ·) (· ≤ ·)]
{a b c d : α}
@[to_additive (attr := simp)]
theorem div_le_self_iff (a : α) {b : α} : a / b ≤ a ↔ 1 ≤ b := by
simp [div_eq_mul_inv]
@[to_additive (attr := simp)]
theorem le_div_self_iff (a : α) {b : α} : a ≤ a / b ↔ b ≤ 1 := by
simp [div_eq_mul_inv]
alias ⟨_, sub_le_self⟩ := sub_le_self_iff
variable [CovariantClass α α (swap (· * ·)) (· ≤ ·)]
@[to_additive (attr := simp)]
theorem inv_le_inv_iff : a⁻¹ ≤ b⁻¹ ↔ b ≤ a := by
rw [← mul_le_mul_iff_left a, ← mul_le_mul_iff_right b]
simp
alias ⟨le_of_neg_le_neg, _⟩ := neg_le_neg_iff
@[to_additive]
theorem mul_inv_le_inv_mul_iff : a * b⁻¹ ≤ d⁻¹ * c ↔ d * a ≤ c * b := by
rw [← mul_le_mul_iff_left d, ← mul_le_mul_iff_right b, mul_inv_cancel_left, mul_assoc,
inv_mul_cancel_right]
end TypeclassesLeftRightLE
section TypeclassesLeftRightLT
variable [LT α] [CovariantClass α α (· * ·) (· < ·)]
{a b c d : α}
@[to_additive (attr := simp)]
theorem div_lt_self_iff (a : α) {b : α} : a / b < a ↔ 1 < b := by
simp [div_eq_mul_inv]
alias ⟨_, sub_lt_self⟩ := sub_lt_self_iff
variable [CovariantClass α α (swap (· * ·)) (· < ·)]
@[to_additive (attr := simp)]
theorem inv_lt_inv_iff : a⁻¹ < b⁻¹ ↔ b < a := by
rw [← mul_lt_mul_iff_left a, ← mul_lt_mul_iff_right b]
simp
@[to_additive neg_lt]
theorem inv_lt' : a⁻¹ < b ↔ b⁻¹ < a := by rw [← inv_lt_inv_iff, inv_inv]
@[to_additive lt_neg]
theorem lt_inv' : a < b⁻¹ ↔ b < a⁻¹ := by rw [← inv_lt_inv_iff, inv_inv]
alias ⟨lt_inv_of_lt_inv, _⟩ := lt_inv'
attribute [to_additive] lt_inv_of_lt_inv
alias ⟨inv_lt_of_inv_lt', _⟩ := inv_lt'
attribute [to_additive neg_lt_of_neg_lt] inv_lt_of_inv_lt'
@[to_additive]
theorem mul_inv_lt_inv_mul_iff : a * b⁻¹ < d⁻¹ * c ↔ d * a < c * b := by
rw [← mul_lt_mul_iff_left d, ← mul_lt_mul_iff_right b, mul_inv_cancel_left, mul_assoc,
inv_mul_cancel_right]
end TypeclassesLeftRightLT
section Preorder
variable [Preorder α]
section LeftLE
variable [CovariantClass α α (· * ·) (· ≤ ·)] {a : α}
@[to_additive]
theorem Left.inv_le_self (h : 1 ≤ a) : a⁻¹ ≤ a :=
le_trans (Left.inv_le_one_iff.mpr h) h
alias neg_le_self := Left.neg_le_self
@[to_additive]
theorem Left.self_le_inv (h : a ≤ 1) : a ≤ a⁻¹ :=
le_trans h (Left.one_le_inv_iff.mpr h)
end LeftLE
section LeftLT
variable [CovariantClass α α (· * ·) (· < ·)] {a : α}
@[to_additive]
theorem Left.inv_lt_self (h : 1 < a) : a⁻¹ < a :=
(Left.inv_lt_one_iff.mpr h).trans h
alias neg_lt_self := Left.neg_lt_self
@[to_additive]
theorem Left.self_lt_inv (h : a < 1) : a < a⁻¹ :=
lt_trans h (Left.one_lt_inv_iff.mpr h)
end LeftLT
section RightLE
variable [CovariantClass α α (swap (· * ·)) (· ≤ ·)] {a : α}
@[to_additive]
theorem Right.inv_le_self (h : 1 ≤ a) : a⁻¹ ≤ a :=
le_trans (Right.inv_le_one_iff.mpr h) h
@[to_additive]
theorem Right.self_le_inv (h : a ≤ 1) : a ≤ a⁻¹ :=
le_trans h (Right.one_le_inv_iff.mpr h)
end RightLE
section RightLT
variable [CovariantClass α α (swap (· * ·)) (· < ·)] {a : α}
@[to_additive]
theorem Right.inv_lt_self (h : 1 < a) : a⁻¹ < a :=
(Right.inv_lt_one_iff.mpr h).trans h
@[to_additive]
theorem Right.self_lt_inv (h : a < 1) : a < a⁻¹ :=
lt_trans h (Right.one_lt_inv_iff.mpr h)
end RightLT
end Preorder
end Group
section CommGroup
variable [CommGroup α]
section LE
variable [LE α] [CovariantClass α α (· * ·) (· ≤ ·)] {a b c d : α}
@[to_additive]
theorem inv_mul_le_iff_le_mul' : c⁻¹ * a ≤ b ↔ a ≤ b * c := by rw [inv_mul_le_iff_le_mul, mul_comm]
-- Porting note: `simp` simplifies LHS to `a ≤ c * b`
@[to_additive]
theorem mul_inv_le_iff_le_mul' : a * b⁻¹ ≤ c ↔ a ≤ b * c := by
rw [← inv_mul_le_iff_le_mul, mul_comm]
@[to_additive add_neg_le_add_neg_iff]
theorem mul_inv_le_mul_inv_iff' : a * b⁻¹ ≤ c * d⁻¹ ↔ a * d ≤ c * b := by
rw [mul_comm c, mul_inv_le_inv_mul_iff, mul_comm]
end LE
section LT
variable [LT α] [CovariantClass α α (· * ·) (· < ·)] {a b c d : α}
@[to_additive]
theorem inv_mul_lt_iff_lt_mul' : c⁻¹ * a < b ↔ a < b * c := by rw [inv_mul_lt_iff_lt_mul, mul_comm]
-- Porting note: `simp` simplifies LHS to `a < c * b`
@[to_additive]
theorem mul_inv_lt_iff_le_mul' : a * b⁻¹ < c ↔ a < b * c := by
rw [← inv_mul_lt_iff_lt_mul, mul_comm]
@[to_additive add_neg_lt_add_neg_iff]
theorem mul_inv_lt_mul_inv_iff' : a * b⁻¹ < c * d⁻¹ ↔ a * d < c * b := by
rw [mul_comm c, mul_inv_lt_inv_mul_iff, mul_comm]
end LT
end CommGroup
alias ⟨one_le_of_inv_le_one, _⟩ := Left.inv_le_one_iff
attribute [to_additive] one_le_of_inv_le_one
alias ⟨le_one_of_one_le_inv, _⟩ := Left.one_le_inv_iff
attribute [to_additive nonpos_of_neg_nonneg] le_one_of_one_le_inv
alias ⟨lt_of_inv_lt_inv, _⟩ := inv_lt_inv_iff
attribute [to_additive] lt_of_inv_lt_inv
alias ⟨one_lt_of_inv_lt_one, _⟩ := Left.inv_lt_one_iff
attribute [to_additive] one_lt_of_inv_lt_one
alias inv_lt_one_iff_one_lt := Left.inv_lt_one_iff
attribute [to_additive] inv_lt_one_iff_one_lt
alias inv_lt_one' := Left.inv_lt_one_iff
attribute [to_additive neg_lt_zero] inv_lt_one'
alias ⟨inv_of_one_lt_inv, _⟩ := Left.one_lt_inv_iff
attribute [to_additive neg_of_neg_pos] inv_of_one_lt_inv
alias ⟨_, one_lt_inv_of_inv⟩ := Left.one_lt_inv_iff
attribute [to_additive neg_pos_of_neg] one_lt_inv_of_inv
alias ⟨mul_le_of_le_inv_mul, _⟩ := le_inv_mul_iff_mul_le
attribute [to_additive] mul_le_of_le_inv_mul
alias ⟨_, le_inv_mul_of_mul_le⟩ := le_inv_mul_iff_mul_le
attribute [to_additive] le_inv_mul_of_mul_le
alias ⟨_, inv_mul_le_of_le_mul⟩ := inv_mul_le_iff_le_mul
-- Porting note: was `inv_mul_le_iff_le_mul`
attribute [to_additive] inv_mul_le_of_le_mul
alias ⟨mul_lt_of_lt_inv_mul, _⟩ := lt_inv_mul_iff_mul_lt
attribute [to_additive] mul_lt_of_lt_inv_mul
alias ⟨_, lt_inv_mul_of_mul_lt⟩ := lt_inv_mul_iff_mul_lt
attribute [to_additive] lt_inv_mul_of_mul_lt
alias ⟨lt_mul_of_inv_mul_lt, inv_mul_lt_of_lt_mul⟩ := inv_mul_lt_iff_lt_mul
attribute [to_additive] lt_mul_of_inv_mul_lt
attribute [to_additive] inv_mul_lt_of_lt_mul
alias lt_mul_of_inv_mul_lt_left := lt_mul_of_inv_mul_lt
attribute [to_additive] lt_mul_of_inv_mul_lt_left
alias inv_le_one' := Left.inv_le_one_iff
attribute [to_additive neg_nonpos] inv_le_one'
alias one_le_inv' := Left.one_le_inv_iff
attribute [to_additive neg_nonneg] one_le_inv'
alias one_lt_inv' := Left.one_lt_inv_iff
attribute [to_additive neg_pos] one_lt_inv'
-- Most of the lemmas that are primed in this section appear in ordered_field.
-- I (DT) did not try to minimise the assumptions.
section Group
variable [Group α] [LE α]
section Right
variable [CovariantClass α α (swap (· * ·)) (· ≤ ·)] {a b c d : α}
@[to_additive]
theorem div_le_div_iff_right (c : α) : a / c ≤ b / c ↔ a ≤ b := by
simpa only [div_eq_mul_inv] using mul_le_mul_iff_right _
@[to_additive (attr := gcongr) sub_le_sub_right]
theorem div_le_div_right' (h : a ≤ b) (c : α) : a / c ≤ b / c :=
(div_le_div_iff_right c).2 h
@[to_additive (attr := simp) sub_nonneg]
theorem one_le_div' : 1 ≤ a / b ↔ b ≤ a := by
rw [← mul_le_mul_iff_right b, one_mul, div_eq_mul_inv, inv_mul_cancel_right]
alias ⟨le_of_sub_nonneg, sub_nonneg_of_le⟩ := sub_nonneg
@[to_additive sub_nonpos]
theorem div_le_one' : a / b ≤ 1 ↔ a ≤ b := by
rw [← mul_le_mul_iff_right b, one_mul, div_eq_mul_inv, inv_mul_cancel_right]
alias ⟨le_of_sub_nonpos, sub_nonpos_of_le⟩ := sub_nonpos
@[to_additive]
theorem le_div_iff_mul_le : a ≤ c / b ↔ a * b ≤ c := by
rw [← mul_le_mul_iff_right b, div_eq_mul_inv, inv_mul_cancel_right]
alias ⟨add_le_of_le_sub_right, le_sub_right_of_add_le⟩ := le_sub_iff_add_le
@[to_additive]
theorem div_le_iff_le_mul : a / c ≤ b ↔ a ≤ b * c := by
rw [← mul_le_mul_iff_right c, div_eq_mul_inv, inv_mul_cancel_right]
-- Note: we intentionally don't have `@[simp]` for the additive version,
-- since the LHS simplifies with `tsub_le_iff_right`
attribute [simp] div_le_iff_le_mul
-- TODO: Should we get rid of `sub_le_iff_le_add` in favor of
-- (a renamed version of) `tsub_le_iff_right`?
-- see Note [lower instance priority]
instance (priority := 100) AddGroup.toOrderedSub {α : Type*} [AddGroup α] [LE α]
[CovariantClass α α (swap (· + ·)) (· ≤ ·)] : OrderedSub α :=
⟨fun _ _ _ => sub_le_iff_le_add⟩
end Right
section Left
variable [CovariantClass α α (· * ·) (· ≤ ·)]
variable [CovariantClass α α (swap (· * ·)) (· ≤ ·)] {a b c : α}
@[to_additive]
theorem div_le_div_iff_left (a : α) : a / b ≤ a / c ↔ c ≤ b := by
rw [div_eq_mul_inv, div_eq_mul_inv, ← mul_le_mul_iff_left a⁻¹, inv_mul_cancel_left,
inv_mul_cancel_left, inv_le_inv_iff]
@[to_additive (attr := gcongr) sub_le_sub_left]
theorem div_le_div_left' (h : a ≤ b) (c : α) : c / b ≤ c / a :=
(div_le_div_iff_left c).2 h
end Left
end Group
section CommGroup
variable [CommGroup α]
section LE
variable [LE α] [CovariantClass α α (· * ·) (· ≤ ·)] {a b c d : α}
@[to_additive sub_le_sub_iff]
theorem div_le_div_iff' : a / b ≤ c / d ↔ a * d ≤ c * b := by
simpa only [div_eq_mul_inv] using mul_inv_le_mul_inv_iff'
@[to_additive]
theorem le_div_iff_mul_le' : b ≤ c / a ↔ a * b ≤ c := by rw [le_div_iff_mul_le, mul_comm]
alias ⟨add_le_of_le_sub_left, le_sub_left_of_add_le⟩ := le_sub_iff_add_le'
@[to_additive]
theorem div_le_iff_le_mul' : a / b ≤ c ↔ a ≤ b * c := by rw [div_le_iff_le_mul, mul_comm]
alias ⟨le_add_of_sub_left_le, sub_left_le_of_le_add⟩ := sub_le_iff_le_add'
@[to_additive (attr := simp)]
theorem inv_le_div_iff_le_mul : b⁻¹ ≤ a / c ↔ c ≤ a * b :=
le_div_iff_mul_le.trans inv_mul_le_iff_le_mul'
@[to_additive]
theorem inv_le_div_iff_le_mul' : a⁻¹ ≤ b / c ↔ c ≤ a * b := by rw [inv_le_div_iff_le_mul, mul_comm]
@[to_additive]
theorem div_le_comm : a / b ≤ c ↔ a / c ≤ b :=
div_le_iff_le_mul'.trans div_le_iff_le_mul.symm
@[to_additive]
theorem le_div_comm : a ≤ b / c ↔ c ≤ b / a :=
le_div_iff_mul_le'.trans le_div_iff_mul_le.symm
end LE
section Preorder
variable [Preorder α] [CovariantClass α α (· * ·) (· ≤ ·)] {a b c d : α}
@[to_additive (attr := gcongr) sub_le_sub]
theorem div_le_div'' (hab : a ≤ b) (hcd : c ≤ d) : a / d ≤ b / c := by
rw [div_eq_mul_inv, div_eq_mul_inv, mul_comm b, mul_inv_le_inv_mul_iff, mul_comm]
exact mul_le_mul' hab hcd
end Preorder
end CommGroup
-- Most of the lemmas that are primed in this section appear in ordered_field.
-- I (DT) did not try to minimise the assumptions.
section Group
variable [Group α] [LT α]
section Right
variable [CovariantClass α α (swap (· * ·)) (· < ·)] {a b c d : α}
@[to_additive (attr := simp)]
theorem div_lt_div_iff_right (c : α) : a / c < b / c ↔ a < b := by
simpa only [div_eq_mul_inv] using mul_lt_mul_iff_right _
@[to_additive (attr := gcongr) sub_lt_sub_right]
theorem div_lt_div_right' (h : a < b) (c : α) : a / c < b / c :=
(div_lt_div_iff_right c).2 h
@[to_additive (attr := simp) sub_pos]
theorem one_lt_div' : 1 < a / b ↔ b < a := by
rw [← mul_lt_mul_iff_right b, one_mul, div_eq_mul_inv, inv_mul_cancel_right]
alias ⟨lt_of_sub_pos, sub_pos_of_lt⟩ := sub_pos
@[to_additive (attr := simp) sub_neg "For `a - -b = a + b`, see `sub_neg_eq_add`."]
theorem div_lt_one' : a / b < 1 ↔ a < b := by
rw [← mul_lt_mul_iff_right b, one_mul, div_eq_mul_inv, inv_mul_cancel_right]
alias ⟨lt_of_sub_neg, sub_neg_of_lt⟩ := sub_neg
alias sub_lt_zero := sub_neg
@[to_additive]
theorem lt_div_iff_mul_lt : a < c / b ↔ a * b < c := by
rw [← mul_lt_mul_iff_right b, div_eq_mul_inv, inv_mul_cancel_right]
alias ⟨add_lt_of_lt_sub_right, lt_sub_right_of_add_lt⟩ := lt_sub_iff_add_lt
@[to_additive]
theorem div_lt_iff_lt_mul : a / c < b ↔ a < b * c := by
rw [← mul_lt_mul_iff_right c, div_eq_mul_inv, inv_mul_cancel_right]
alias ⟨lt_add_of_sub_right_lt, sub_right_lt_of_lt_add⟩ := sub_lt_iff_lt_add
end Right
section Left
variable [CovariantClass α α (· * ·) (· < ·)] [CovariantClass α α (swap (· * ·)) (· < ·)]
{a b c : α}
@[to_additive (attr := simp)]
theorem div_lt_div_iff_left (a : α) : a / b < a / c ↔ c < b := by
rw [div_eq_mul_inv, div_eq_mul_inv, ← mul_lt_mul_iff_left a⁻¹, inv_mul_cancel_left,
inv_mul_cancel_left, inv_lt_inv_iff]
@[to_additive (attr := simp)]
theorem inv_lt_div_iff_lt_mul : a⁻¹ < b / c ↔ c < a * b := by
rw [div_eq_mul_inv, lt_mul_inv_iff_mul_lt, inv_mul_lt_iff_lt_mul]
@[to_additive (attr := gcongr) sub_lt_sub_left]
theorem div_lt_div_left' (h : a < b) (c : α) : c / b < c / a :=
(div_lt_div_iff_left c).2 h
end Left
end Group
section CommGroup
variable [CommGroup α]
section LT
variable [LT α] [CovariantClass α α (· * ·) (· < ·)] {a b c d : α}
@[to_additive sub_lt_sub_iff]
theorem div_lt_div_iff' : a / b < c / d ↔ a * d < c * b := by
simpa only [div_eq_mul_inv] using mul_inv_lt_mul_inv_iff'
@[to_additive]
theorem lt_div_iff_mul_lt' : b < c / a ↔ a * b < c := by rw [lt_div_iff_mul_lt, mul_comm]
alias ⟨add_lt_of_lt_sub_left, lt_sub_left_of_add_lt⟩ := lt_sub_iff_add_lt'
@[to_additive]
theorem div_lt_iff_lt_mul' : a / b < c ↔ a < b * c := by rw [div_lt_iff_lt_mul, mul_comm]
alias ⟨lt_add_of_sub_left_lt, sub_left_lt_of_lt_add⟩ := sub_lt_iff_lt_add'
@[to_additive]
theorem inv_lt_div_iff_lt_mul' : b⁻¹ < a / c ↔ c < a * b :=
lt_div_iff_mul_lt.trans inv_mul_lt_iff_lt_mul'
@[to_additive]
theorem div_lt_comm : a / b < c ↔ a / c < b :=
div_lt_iff_lt_mul'.trans div_lt_iff_lt_mul.symm
@[to_additive]
theorem lt_div_comm : a < b / c ↔ c < b / a :=
lt_div_iff_mul_lt'.trans lt_div_iff_mul_lt.symm
end LT
section Preorder
variable [Preorder α] [CovariantClass α α (· * ·) (· < ·)] {a b c d : α}
@[to_additive (attr := gcongr) sub_lt_sub]
theorem div_lt_div'' (hab : a < b) (hcd : c < d) : a / d < b / c := by
rw [div_eq_mul_inv, div_eq_mul_inv, mul_comm b, mul_inv_lt_inv_mul_iff, mul_comm]
exact mul_lt_mul_of_lt_of_lt hab hcd
end Preorder
section LinearOrder
variable [LinearOrder α] [CovariantClass α α (· * ·) (· ≤ ·)] {a b c d : α}
@[to_additive] lemma lt_or_lt_of_div_lt_div : a / d < b / c → a < b ∨ c < d := by
contrapose!; exact fun h ↦ div_le_div'' h.1 h.2
end LinearOrder
end CommGroup
section LinearOrder
variable [Group α] [LinearOrder α]
@[to_additive (attr := simp) cmp_sub_zero]
theorem cmp_div_one' [CovariantClass α α (swap (· * ·)) (· ≤ ·)] (a b : α) :
cmp (a / b) 1 = cmp a b := by rw [← cmp_mul_right' _ _ b, one_mul, div_mul_cancel]
variable [CovariantClass α α (· * ·) (· ≤ ·)]
section VariableNames
variable {a b c : α}
@[to_additive]
theorem le_of_forall_one_lt_lt_mul (h : ∀ ε : α, 1 < ε → a < b * ε) : a ≤ b :=
le_of_not_lt fun h₁ => lt_irrefl a (by simpa using h _ (lt_inv_mul_iff_lt.mpr h₁))
@[to_additive]
theorem le_iff_forall_one_lt_lt_mul : a ≤ b ↔ ∀ ε, 1 < ε → a < b * ε :=
⟨fun h _ => lt_mul_of_le_of_one_lt h, le_of_forall_one_lt_lt_mul⟩
/- I (DT) introduced this lemma to prove (the additive version `sub_le_sub_flip` of)
`div_le_div_flip` below. Now I wonder what is the point of either of these lemmas... -/
@[to_additive]
theorem div_le_inv_mul_iff [CovariantClass α α (swap (· * ·)) (· ≤ ·)] :
a / b ≤ a⁻¹ * b ↔ a ≤ b := by
rw [div_eq_mul_inv, mul_inv_le_inv_mul_iff]
exact
⟨fun h => not_lt.mp fun k => not_lt.mpr h (mul_lt_mul_of_lt_of_lt k k), fun h =>
mul_le_mul' h h⟩
-- What is the point of this lemma? See comment about `div_le_inv_mul_iff` above.
-- Note: we intentionally don't have `@[simp]` for the additive version,
-- since the LHS simplifies with `tsub_le_iff_right`
@[to_additive]
theorem div_le_div_flip {α : Type*} [CommGroup α] [LinearOrder α]
[CovariantClass α α (· * ·) (· ≤ ·)] {a b : α} : a / b ≤ b / a ↔ a ≤ b := by
rw [div_eq_mul_inv b, mul_comm]
exact div_le_inv_mul_iff
end VariableNames
end LinearOrder
section
variable {β : Type*} [Group α] [Preorder α] [CovariantClass α α (· * ·) (· ≤ ·)]
[CovariantClass α α (swap (· * ·)) (· ≤ ·)] [Preorder β] {f : β → α} {s : Set β}
@[to_additive]
theorem Monotone.inv (hf : Monotone f) : Antitone fun x => (f x)⁻¹ := fun _ _ hxy =>
inv_le_inv_iff.2 (hf hxy)
@[to_additive]
theorem Antitone.inv (hf : Antitone f) : Monotone fun x => (f x)⁻¹ := fun _ _ hxy =>
inv_le_inv_iff.2 (hf hxy)
@[to_additive]
theorem MonotoneOn.inv (hf : MonotoneOn f s) : AntitoneOn (fun x => (f x)⁻¹) s :=
fun _ hx _ hy hxy => inv_le_inv_iff.2 (hf hx hy hxy)
@[to_additive]
theorem AntitoneOn.inv (hf : AntitoneOn f s) : MonotoneOn (fun x => (f x)⁻¹) s :=
fun _ hx _ hy hxy => inv_le_inv_iff.2 (hf hx hy hxy)
end
section
variable {β : Type*} [Group α] [Preorder α] [CovariantClass α α (· * ·) (· < ·)]
[CovariantClass α α (swap (· * ·)) (· < ·)] [Preorder β] {f : β → α} {s : Set β}
@[to_additive]
theorem StrictMono.inv (hf : StrictMono f) : StrictAnti fun x => (f x)⁻¹ := fun _ _ hxy =>
inv_lt_inv_iff.2 (hf hxy)
@[to_additive]
theorem StrictAnti.inv (hf : StrictAnti f) : StrictMono fun x => (f x)⁻¹ := fun _ _ hxy =>
inv_lt_inv_iff.2 (hf hxy)
@[to_additive]
theorem StrictMonoOn.inv (hf : StrictMonoOn f s) : StrictAntiOn (fun x => (f x)⁻¹) s :=
fun _ hx _ hy hxy => inv_lt_inv_iff.2 (hf hx hy hxy)
@[to_additive]
theorem StrictAntiOn.inv (hf : StrictAntiOn f s) : StrictMonoOn (fun x => (f x)⁻¹) s :=
fun _ hx _ hy hxy => inv_lt_inv_iff.2 (hf hx hy hxy)
end
|
Algebra\Order\GroupWithZero\Canonical.lean | /-
Copyright (c) 2020 Kenny Lau. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kenny Lau, Johan Commelin, Patrick Massot
-/
import Mathlib.Algebra.Group.WithOne.Defs
import Mathlib.Algebra.GroupWithZero.InjSurj
import Mathlib.Algebra.GroupWithZero.Units.Equiv
import Mathlib.Algebra.GroupWithZero.WithZero
import Mathlib.Algebra.Order.Group.Units
import Mathlib.Algebra.Order.GroupWithZero.Synonym
import Mathlib.Algebra.Order.Monoid.Basic
import Mathlib.Algebra.Order.AddGroupWithTop
import Mathlib.Algebra.Order.Monoid.OrderDual
import Mathlib.Algebra.Order.Monoid.TypeTags
import Mathlib.Algebra.Order.ZeroLEOne
/-!
# Linearly ordered commutative groups and monoids with a zero element adjoined
This file sets up a special class of linearly ordered commutative monoids
that show up as the target of so-called “valuations” in algebraic number theory.
Usually, in the informal literature, these objects are constructed
by taking a linearly ordered commutative group Γ and formally adjoining a zero element: Γ ∪ {0}.
The disadvantage is that a type such as `NNReal` is not of that form,
whereas it is a very common target for valuations.
The solutions is to use a typeclass, and that is exactly what we do in this file.
-/
variable {α : Type*}
/-- A linearly ordered commutative monoid with a zero element. -/
class LinearOrderedCommMonoidWithZero (α : Type*) extends LinearOrderedCommMonoid α,
CommMonoidWithZero α where
/-- `0 ≤ 1` in any linearly ordered commutative monoid. -/
zero_le_one : (0 : α) ≤ 1
/-- A linearly ordered commutative group with a zero element. -/
class LinearOrderedCommGroupWithZero (α : Type*) extends LinearOrderedCommMonoidWithZero α,
CommGroupWithZero α
instance (priority := 100) LinearOrderedCommMonoidWithZero.toZeroLeOneClass
[LinearOrderedCommMonoidWithZero α] : ZeroLEOneClass α :=
{ ‹LinearOrderedCommMonoidWithZero α› with }
instance (priority := 100) canonicallyOrderedAddCommMonoid.toZeroLeOneClass
[CanonicallyOrderedAddCommMonoid α] [One α] : ZeroLEOneClass α :=
⟨zero_le 1⟩
section LinearOrderedCommMonoidWithZero
variable [LinearOrderedCommMonoidWithZero α] {a b c d x y z : α} {n : ℕ}
/-
The following facts are true more generally in a (linearly) ordered commutative monoid.
-/
/-- Pullback a `LinearOrderedCommMonoidWithZero` under an injective map.
See note [reducible non-instances]. -/
abbrev Function.Injective.linearOrderedCommMonoidWithZero {β : Type*} [Zero β] [One β] [Mul β]
[Pow β ℕ] [Sup β] [Inf β] (f : β → α) (hf : Function.Injective f) (zero : f 0 = 0)
(one : f 1 = 1) (mul : ∀ x y, f (x * y) = f x * f y) (npow : ∀ (x) (n : ℕ), f (x ^ n) = f x ^ n)
(hsup : ∀ x y, f (x ⊔ y) = max (f x) (f y)) (hinf : ∀ x y, f (x ⊓ y) = min (f x) (f y)) :
LinearOrderedCommMonoidWithZero β :=
{ LinearOrder.lift f hf hsup hinf, hf.orderedCommMonoid f one mul npow,
hf.commMonoidWithZero f zero one mul npow with
zero_le_one :=
show f 0 ≤ f 1 by simp only [zero, one, LinearOrderedCommMonoidWithZero.zero_le_one] }
@[simp] lemma zero_le' : 0 ≤ a := by
simpa only [mul_zero, mul_one] using mul_le_mul_left' (zero_le_one' α) a
@[simp]
theorem not_lt_zero' : ¬a < 0 :=
not_lt_of_le zero_le'
@[simp]
theorem le_zero_iff : a ≤ 0 ↔ a = 0 :=
⟨fun h ↦ le_antisymm h zero_le', fun h ↦ h ▸ le_rfl⟩
theorem zero_lt_iff : 0 < a ↔ a ≠ 0 :=
⟨ne_of_gt, fun h ↦ lt_of_le_of_ne zero_le' h.symm⟩
theorem ne_zero_of_lt (h : b < a) : a ≠ 0 := fun h1 ↦ not_lt_zero' <| show b < 0 from h1 ▸ h
instance instLinearOrderedAddCommMonoidWithTopAdditiveOrderDual :
LinearOrderedAddCommMonoidWithTop (Additive αᵒᵈ) :=
{ Additive.orderedAddCommMonoid, Additive.linearOrder with
top := (0 : α)
top_add' := fun a ↦ zero_mul (Additive.toMul a)
le_top := fun _ ↦ zero_le' }
variable [NoZeroDivisors α]
lemma pow_pos_iff (hn : n ≠ 0) : 0 < a ^ n ↔ 0 < a := by simp_rw [zero_lt_iff, pow_ne_zero_iff hn]
end LinearOrderedCommMonoidWithZero
section LinearOrderedCommGroupWithZero
variable [LinearOrderedCommGroupWithZero α] {a b c d : α} {m n : ℕ}
-- TODO: Do we really need the following two?
/-- Alias of `mul_le_one'` for unification. -/
theorem mul_le_one₀ (ha : a ≤ 1) (hb : b ≤ 1) : a * b ≤ 1 :=
mul_le_one' ha hb
/-- Alias of `one_le_mul'` for unification. -/
theorem one_le_mul₀ (ha : 1 ≤ a) (hb : 1 ≤ b) : 1 ≤ a * b :=
one_le_mul ha hb
theorem le_of_le_mul_right (h : c ≠ 0) (hab : a * c ≤ b * c) : a ≤ b := by
simpa only [mul_inv_cancel_right₀ h] using mul_le_mul_right' hab c⁻¹
theorem le_mul_inv_of_mul_le (h : c ≠ 0) (hab : a * c ≤ b) : a ≤ b * c⁻¹ :=
le_of_le_mul_right h (by simpa [h] using hab)
theorem mul_inv_le_of_le_mul (hab : a ≤ b * c) : a * c⁻¹ ≤ b := by
by_cases h : c = 0
· simp [h]
· exact le_of_le_mul_right h (by simpa [h] using hab)
theorem inv_le_one₀ (ha : a ≠ 0) : a⁻¹ ≤ 1 ↔ 1 ≤ a :=
inv_le_one' (a := Units.mk0 a ha)
theorem one_le_inv₀ (ha : a ≠ 0) : 1 ≤ a⁻¹ ↔ a ≤ 1 :=
one_le_inv' (a := Units.mk0 a ha)
theorem le_mul_inv_iff₀ (hc : c ≠ 0) : a ≤ b * c⁻¹ ↔ a * c ≤ b :=
⟨fun h ↦ inv_inv c ▸ mul_inv_le_of_le_mul h, le_mul_inv_of_mul_le hc⟩
theorem mul_inv_le_iff₀ (hc : c ≠ 0) : a * c⁻¹ ≤ b ↔ a ≤ b * c :=
⟨fun h ↦ inv_inv c ▸ le_mul_inv_of_mul_le (inv_ne_zero hc) h, mul_inv_le_of_le_mul⟩
theorem div_le_div₀ (a b c d : α) (hb : b ≠ 0) (hd : d ≠ 0) :
a * b⁻¹ ≤ c * d⁻¹ ↔ a * d ≤ c * b := by
rw [mul_inv_le_iff₀ hb, mul_right_comm, le_mul_inv_iff₀ hd]
@[simp]
theorem Units.zero_lt (u : αˣ) : (0 : α) < u :=
zero_lt_iff.2 <| u.ne_zero
theorem mul_lt_mul_of_lt_of_le₀ (hab : a ≤ b) (hb : b ≠ 0) (hcd : c < d) : a * c < b * d :=
have hd : d ≠ 0 := ne_zero_of_lt hcd
if ha : a = 0 then by
rw [ha, zero_mul, zero_lt_iff]
exact mul_ne_zero hb hd
else
if hc : c = 0 then by
rw [hc, mul_zero, zero_lt_iff]
exact mul_ne_zero hb hd
else
show Units.mk0 a ha * Units.mk0 c hc < Units.mk0 b hb * Units.mk0 d hd from
mul_lt_mul_of_le_of_lt hab hcd
theorem mul_lt_mul₀ (hab : a < b) (hcd : c < d) : a * c < b * d :=
mul_lt_mul_of_lt_of_le₀ hab.le (ne_zero_of_lt hab) hcd
theorem mul_inv_lt_of_lt_mul₀ (h : a < b * c) : a * c⁻¹ < b := by
contrapose! h
simpa only [inv_inv] using mul_inv_le_of_le_mul h
theorem inv_mul_lt_of_lt_mul₀ (h : a < b * c) : b⁻¹ * a < c := by
rw [mul_comm] at *
exact mul_inv_lt_of_lt_mul₀ h
theorem mul_lt_right₀ (c : α) (h : a < b) (hc : c ≠ 0) : a * c < b * c := by
contrapose! h
exact le_of_le_mul_right hc h
theorem inv_lt_one₀ (ha : a ≠ 0) : a⁻¹ < 1 ↔ 1 < a :=
inv_lt_one' (a := Units.mk0 a ha)
theorem one_lt_inv₀ (ha : a ≠ 0) : 1 < a⁻¹ ↔ a < 1 :=
one_lt_inv' (a := Units.mk0 a ha)
theorem inv_lt_inv₀ (ha : a ≠ 0) (hb : b ≠ 0) : a⁻¹ < b⁻¹ ↔ b < a :=
show (Units.mk0 a ha)⁻¹ < (Units.mk0 b hb)⁻¹ ↔ Units.mk0 b hb < Units.mk0 a ha from
have : CovariantClass αˣ αˣ (· * ·) (· < ·) :=
IsLeftCancelMul.covariant_mul_lt_of_covariant_mul_le αˣ
inv_lt_inv_iff
theorem inv_le_inv₀ (ha : a ≠ 0) (hb : b ≠ 0) : a⁻¹ ≤ b⁻¹ ↔ b ≤ a :=
show (Units.mk0 a ha)⁻¹ ≤ (Units.mk0 b hb)⁻¹ ↔ Units.mk0 b hb ≤ Units.mk0 a ha from
inv_le_inv_iff
theorem lt_of_mul_lt_mul_of_le₀ (h : a * b < c * d) (hc : 0 < c) (hh : c ≤ a) : b < d := by
have ha : a ≠ 0 := ne_of_gt (lt_of_lt_of_le hc hh)
simp_rw [← inv_le_inv₀ ha (ne_of_gt hc)] at hh
have := mul_lt_mul_of_lt_of_le₀ hh (inv_ne_zero (ne_of_gt hc)) h
simpa [inv_mul_cancel_left₀ ha, inv_mul_cancel_left₀ (ne_of_gt hc)] using this
theorem mul_le_mul_right₀ (hc : c ≠ 0) : a * c ≤ b * c ↔ a ≤ b :=
⟨le_of_le_mul_right hc, fun hab ↦ mul_le_mul_right' hab _⟩
theorem mul_le_mul_left₀ (ha : a ≠ 0) : a * b ≤ a * c ↔ b ≤ c := by
simp only [mul_comm a]
exact mul_le_mul_right₀ ha
theorem div_le_div_right₀ (hc : c ≠ 0) : a / c ≤ b / c ↔ a ≤ b := by
rw [div_eq_mul_inv, div_eq_mul_inv, mul_le_mul_right₀ (inv_ne_zero hc)]
theorem div_le_div_left₀ (ha : a ≠ 0) (hb : b ≠ 0) (hc : c ≠ 0) : a / b ≤ a / c ↔ c ≤ b := by
simp only [div_eq_mul_inv, mul_le_mul_left₀ ha, inv_le_inv₀ hb hc]
theorem le_div_iff₀ (hc : c ≠ 0) : a ≤ b / c ↔ a * c ≤ b := by
rw [div_eq_mul_inv, le_mul_inv_iff₀ hc]
theorem div_le_iff₀ (hc : c ≠ 0) : a / c ≤ b ↔ a ≤ b * c := by
rw [div_eq_mul_inv, mul_inv_le_iff₀ hc]
/-- `Equiv.mulLeft₀` as an `OrderIso` on a `LinearOrderedCommGroupWithZero.`.
Note that `OrderIso.mulLeft₀` refers to the `LinearOrderedField` version. -/
@[simps! (config := { simpRhs := true }) apply toEquiv]
def OrderIso.mulLeft₀' {a : α} (ha : a ≠ 0) : α ≃o α :=
{ Equiv.mulLeft₀ a ha with map_rel_iff' := mul_le_mul_left₀ ha }
theorem OrderIso.mulLeft₀'_symm {a : α} (ha : a ≠ 0) :
(OrderIso.mulLeft₀' ha).symm = OrderIso.mulLeft₀' (inv_ne_zero ha) := by
ext
rfl
/-- `Equiv.mulRight₀` as an `OrderIso` on a `LinearOrderedCommGroupWithZero.`.
Note that `OrderIso.mulRight₀` refers to the `LinearOrderedField` version. -/
@[simps! (config := { simpRhs := true }) apply toEquiv]
def OrderIso.mulRight₀' {a : α} (ha : a ≠ 0) : α ≃o α :=
{ Equiv.mulRight₀ a ha with map_rel_iff' := mul_le_mul_right₀ ha }
theorem OrderIso.mulRight₀'_symm {a : α} (ha : a ≠ 0) :
(OrderIso.mulRight₀' ha).symm = OrderIso.mulRight₀' (inv_ne_zero ha) := by
ext
rfl
#adaptation_note /-- 2024-04-23
After https://github.com/leanprover/lean4/pull/3965,
we need to either write `@inv_zero (G₀ := α) (_)` in `neg_top`,
or use `set_option backward.isDefEq.lazyProjDelta false`.
See https://github.com/leanprover-community/mathlib4/issues/12535 -/
instance : LinearOrderedAddCommGroupWithTop (Additive αᵒᵈ) :=
{ Additive.subNegMonoid, instLinearOrderedAddCommMonoidWithTopAdditiveOrderDual,
Additive.instNontrivial with
neg_top := set_option backward.isDefEq.lazyProjDelta false in @inv_zero _ (_)
add_neg_cancel := fun a ha ↦ mul_inv_cancel (G₀ := α) (id ha : Additive.toMul a ≠ 0) }
lemma pow_lt_pow_succ (ha : 1 < a) : a ^ n < a ^ n.succ := by
rw [← one_mul (a ^ n), pow_succ']
exact mul_lt_right₀ _ ha (pow_ne_zero _ (zero_lt_one.trans ha).ne')
lemma pow_lt_pow_right₀ (ha : 1 < a) (hmn : m < n) : a ^ m < a ^ n := by
induction' hmn with n _ ih; exacts [pow_lt_pow_succ ha, lt_trans ih (pow_lt_pow_succ ha)]
@[deprecated (since := "2023-12-23")] alias pow_lt_pow₀ := pow_lt_pow_right₀
end LinearOrderedCommGroupWithZero
instance instLinearOrderedCommMonoidWithZeroMultiplicativeOrderDual
[LinearOrderedAddCommMonoidWithTop α] :
LinearOrderedCommMonoidWithZero (Multiplicative αᵒᵈ) :=
{ Multiplicative.orderedCommMonoid, Multiplicative.linearOrder with
zero := Multiplicative.ofAdd (⊤ : α)
zero_mul := @top_add _ (_)
-- Porting note: Here and elsewhere in the file, just `zero_mul` worked in Lean 3. See
-- https://leanprover.zulipchat.com/#narrow/stream/287929-mathlib4/topic/Type.20synonyms
mul_zero := @add_top _ (_)
zero_le_one := (le_top : (0 : α) ≤ ⊤) }
instance [LinearOrderedAddCommGroupWithTop α] :
LinearOrderedCommGroupWithZero (Multiplicative αᵒᵈ) :=
{ Multiplicative.divInvMonoid, instLinearOrderedCommMonoidWithZeroMultiplicativeOrderDual,
Multiplicative.instNontrivial with
inv_zero := @LinearOrderedAddCommGroupWithTop.neg_top _ (_)
mul_inv_cancel := @LinearOrderedAddCommGroupWithTop.add_neg_cancel _ (_) }
namespace WithZero
section Preorder
variable [Preorder α] {a b : α}
instance preorder : Preorder (WithZero α) := WithBot.preorder
instance orderBot : OrderBot (WithZero α) := WithBot.orderBot
lemma zero_le (a : WithZero α) : 0 ≤ a := bot_le
lemma zero_lt_coe (a : α) : (0 : WithZero α) < a := WithBot.bot_lt_coe a
lemma zero_eq_bot : (0 : WithZero α) = ⊥ := rfl
@[simp, norm_cast] lemma coe_lt_coe : (a : WithZero α) < b ↔ a < b := WithBot.coe_lt_coe
@[simp, norm_cast] lemma coe_le_coe : (a : WithZero α) ≤ b ↔ a ≤ b := WithBot.coe_le_coe
@[simp, norm_cast] lemma one_lt_coe [One α] : 1 < (a : WithZero α) ↔ 1 < a := coe_lt_coe
@[simp, norm_cast] lemma one_le_coe [One α] : 1 ≤ (a : WithZero α) ↔ 1 ≤ a := coe_le_coe
@[simp, norm_cast] lemma coe_lt_one [One α] : (a : WithZero α) < 1 ↔ a < 1 := coe_lt_coe
@[simp, norm_cast] lemma coe_le_one [One α] : (a : WithZero α) ≤ 1 ↔ a ≤ 1 := coe_le_coe
theorem coe_le_iff {x : WithZero α} : (a : WithZero α) ≤ x ↔ ∃ b : α, x = b ∧ a ≤ b :=
WithBot.coe_le_iff
instance covariantClass_mul_le [Mul α] [CovariantClass α α (· * ·) (· ≤ ·)] :
CovariantClass (WithZero α) (WithZero α) (· * ·) (· ≤ ·) := by
refine ⟨fun a b c hbc => ?_⟩
induction a; · exact zero_le _
induction b; · exact zero_le _
rcases WithZero.coe_le_iff.1 hbc with ⟨c, rfl, hbc'⟩
rw [← coe_mul _ c, ← coe_mul, coe_le_coe]
exact mul_le_mul_left' hbc' _
protected lemma covariantClass_add_le [AddZeroClass α] [CovariantClass α α (· + ·) (· ≤ ·)]
(h : ∀ a : α, 0 ≤ a) : CovariantClass (WithZero α) (WithZero α) (· + ·) (· ≤ ·) := by
refine ⟨fun a b c hbc => ?_⟩
induction a
· rwa [zero_add, zero_add]
induction b
· rw [add_zero]
induction c
· rw [add_zero]
· rw [← coe_add, coe_le_coe]
exact le_add_of_nonneg_right (h _)
· rcases WithZero.coe_le_iff.1 hbc with ⟨c, rfl, hbc'⟩
rw [← coe_add, ← coe_add _ c, coe_le_coe]
exact add_le_add_left hbc' _
instance existsAddOfLE [Add α] [ExistsAddOfLE α] : ExistsAddOfLE (WithZero α) :=
⟨fun {a b} => by
induction a
· exact fun _ => ⟨b, (zero_add b).symm⟩
induction b
· exact fun h => (WithBot.not_coe_le_bot _ h).elim
intro h
obtain ⟨c, rfl⟩ := exists_add_of_le (WithZero.coe_le_coe.1 h)
exact ⟨c, rfl⟩⟩
end Preorder
section PartialOrder
variable [PartialOrder α]
instance partialOrder : PartialOrder (WithZero α) := WithBot.partialOrder
instance contravariantClass_mul_lt [Mul α] [ContravariantClass α α (· * ·) (· < ·)] :
ContravariantClass (WithZero α) (WithZero α) (· * ·) (· < ·) := by
refine ⟨fun a b c h => ?_⟩
have := ((zero_le _).trans_lt h).ne'
induction a
· simp at this
induction c
· simp at this
induction b
exacts [zero_lt_coe _, coe_lt_coe.mpr (lt_of_mul_lt_mul_left' <| coe_lt_coe.mp h)]
end PartialOrder
instance lattice [Lattice α] : Lattice (WithZero α) := WithBot.lattice
section LinearOrder
variable [LinearOrder α] {a b c : α}
instance linearOrder : LinearOrder (WithZero α) := WithBot.linearOrder
-- Porting note (#10618): @[simp] can prove this
protected lemma le_max_iff : (a : WithZero α) ≤ max (b : WithZero α) c ↔ a ≤ max b c := by
simp only [WithZero.coe_le_coe, le_max_iff]
-- Porting note (#10618): @[simp] can prove this
protected lemma min_le_iff : min (a : WithZero α) b ≤ c ↔ min a b ≤ c := by
simp only [WithZero.coe_le_coe, min_le_iff]
end LinearOrder
instance orderedCommMonoid [OrderedCommMonoid α] : OrderedCommMonoid (WithZero α) :=
{ WithZero.commMonoidWithZero.toCommMonoid, WithZero.partialOrder with
mul_le_mul_left := fun _ _ => mul_le_mul_left' }
/-
Note 1 : the below is not an instance because it requires `zero_le`. It seems
like a rather pathological definition because α already has a zero.
Note 2 : there is no multiplicative analogue because it does not seem necessary.
Mathematicians might be more likely to use the order-dual version, where all
elements are ≤ 1 and then 1 is the top element.
-/
/-- If `0` is the least element in `α`, then `WithZero α` is an `OrderedAddCommMonoid`. -/
-- See note [reducible non-instances]
protected abbrev orderedAddCommMonoid [OrderedAddCommMonoid α] (zero_le : ∀ a : α, 0 ≤ a) :
OrderedAddCommMonoid (WithZero α) :=
{ WithZero.partialOrder, WithZero.addCommMonoid with
add_le_add_left := @add_le_add_left _ _ _ (WithZero.covariantClass_add_le zero_le).. }
-- This instance looks absurd: a monoid already has a zero
/-- Adding a new zero to a canonically ordered additive monoid produces another one. -/
instance canonicallyOrderedAddCommMonoid [CanonicallyOrderedAddCommMonoid α] :
CanonicallyOrderedAddCommMonoid (WithZero α) :=
{ WithZero.orderBot,
WithZero.orderedAddCommMonoid _root_.zero_le,
WithZero.existsAddOfLE with
le_self_add := fun a b => by
induction a
· exact bot_le
induction b
· exact le_rfl
· exact WithZero.coe_le_coe.2 le_self_add }
instance canonicallyLinearOrderedAddCommMonoid [CanonicallyLinearOrderedAddCommMonoid α] :
CanonicallyLinearOrderedAddCommMonoid (WithZero α) :=
{ WithZero.canonicallyOrderedAddCommMonoid, WithZero.linearOrder with }
instance instLinearOrderedCommMonoidWithZero [LinearOrderedCommMonoid α] :
LinearOrderedCommMonoidWithZero (WithZero α) :=
{ WithZero.linearOrder, WithZero.commMonoidWithZero with
mul_le_mul_left := fun _ _ ↦ mul_le_mul_left', zero_le_one := WithZero.zero_le _ }
instance instLinearOrderedCommGroupWithZero [LinearOrderedCommGroup α] :
LinearOrderedCommGroupWithZero (WithZero α) where
__ := instLinearOrderedCommMonoidWithZero
__ := commGroupWithZero
end WithZero
|
Algebra\Order\GroupWithZero\Synonym.lean | /-
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.GroupWithZero.Defs
import Mathlib.Algebra.Order.Group.Synonym
/-!
# Group with zero structure on the order type synonyms
Transfer algebraic instances from `α` to `αᵒᵈ` and `Lex α`.
-/
open Function
variable {α : Type*}
/-! ### Order dual -/
open OrderDual
instance [h : MulZeroClass α] : MulZeroClass αᵒᵈ := h
instance [h : MulZeroOneClass α] : MulZeroOneClass αᵒᵈ := h
instance [Mul α] [Zero α] [h : NoZeroDivisors α] : NoZeroDivisors αᵒᵈ := h
instance [h : SemigroupWithZero α] : SemigroupWithZero αᵒᵈ := h
instance [h : MonoidWithZero α] : MonoidWithZero αᵒᵈ := h
instance [h : CancelMonoidWithZero α] : CancelMonoidWithZero αᵒᵈ := h
instance [h : CommMonoidWithZero α] : CommMonoidWithZero αᵒᵈ := h
instance [h : CancelCommMonoidWithZero α] : CancelCommMonoidWithZero αᵒᵈ := h
instance [h : GroupWithZero α] : GroupWithZero αᵒᵈ := h
instance [h : CommGroupWithZero α] : CommGroupWithZero αᵒᵈ := h
/-! ### Lexicographic order -/
instance [h : MulZeroClass α] : MulZeroClass (Lex α) := h
instance [h : MulZeroOneClass α] : MulZeroOneClass (Lex α) := h
instance [Mul α] [Zero α] [h : NoZeroDivisors α] : NoZeroDivisors (Lex α) := h
instance [h : SemigroupWithZero α] : SemigroupWithZero (Lex α) := h
instance [h : MonoidWithZero α] : MonoidWithZero (Lex α) := h
instance [h : CancelMonoidWithZero α] : CancelMonoidWithZero (Lex α) := h
instance [h : CommMonoidWithZero α] : CommMonoidWithZero (Lex α) := h
instance [h : CancelCommMonoidWithZero α] : CancelCommMonoidWithZero (Lex α) := h
instance [h : GroupWithZero α] : GroupWithZero (Lex α) := h
instance [h : CommGroupWithZero α] : CommGroupWithZero (Lex α) := h
|
Algebra\Order\GroupWithZero\Unbundled.lean | /-
Copyright (c) 2022 Damiano Testa. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Damiano Testa, Yuyang Zhao
-/
import Mathlib.Algebra.GroupWithZero.Defs
import Mathlib.Algebra.Order.Monoid.Unbundled.Defs
import Mathlib.Tactic.GCongr.Core
/-!
# Monotonicity of multiplication by positive elements
This file defines typeclasses to reason about monotonicity of the operations
* `b ↦ a * b`, "left multiplication"
* `a ↦ a * b`, "right multiplication"
We use eight typeclasses to encode the various properties we care about for those two operations.
These typeclasses are meant to be mostly internal to this file, to set up each lemma in the
appropriate generality.
Less granular typeclasses like `OrderedAddCommMonoid`, `LinearOrderedField` should be enough for
most purposes, and the system is set up so that they imply the correct granular typeclasses here.
If those are enough for you, you may stop reading here! Else, beware that what follows is a bit
technical.
## Definitions
In all that follows, `α` is an orders which has a `0` and a multiplication. Note however that we do
not use lawfulness of this action in most of the file. Hence `*` should be considered here as a
mostly arbitrary function `α → α → α`.
We use the following four typeclasses to reason about left multiplication (`b ↦ a * b`):
* `PosMulMono`: If `a ≥ 0`, then `b₁ ≤ b₂ → a * b₁ ≤ a * b₂`.
* `PosMulStrictMono`: If `a > 0`, then `b₁ < b₂ → a * b₁ < a * b₂`.
* `PosMulReflectLT`: If `a ≥ 0`, then `a * b₁ < a * b₂ → b₁ < b₂`.
* `PosMulReflectLE`: If `a > 0`, then `a * b₁ ≤ a * b₂ → b₁ ≤ b₂`.
We use the following four typeclasses to reason about right multiplication (`a ↦ a * b`):
* `MulPosMono`: If `b ≥ 0`, then `a₁ ≤ a₂ → a₁ * b ≤ a₂ * b`.
* `MulPosStrictMono`: If `b > 0`, then `a₁ < a₂ → a₁ * b < a₂ * b`.
* `MulPosReflectLT`: If `b ≥ 0`, then `a₁ * b < a₂ * b → a₁ < a₂`.
* `MulPosReflectLE`: If `b > 0`, then `a₁ * b ≤ a₂ * b → a₁ ≤ a₂`.
## Implications
As `α` gets more and more structure, those typeclasses end up being equivalent. The commonly used
implications are:
* When `α` is a partial order:
* `PosMulStrictMono → PosMulMono`
* `MulPosStrictMono → MulPosMono`
* `PosMulReflectLE → PosMulReflectLT`
* `MulPosReflectLE → MulPosReflectLT`
* When `α` is a linear order:
* `PosMulStrictMono → PosMulReflectLE`
* `MulPosStrictMono → MulPosReflectLE` .
* When the multiplication of `α` is commutative:
* `PosMulMono → MulPosMono`
* `PosMulStrictMono → MulPosStrictMono`
* `PosMulReflectLE → MulPosReflectLE`
* `PosMulReflectLT → MulPosReflectLT`
Further, the bundled non-granular typeclasses imply the granular ones like so:
* `OrderedSemiring → PosMulMono`
* `OrderedSemiring → MulPosMono`
* `StrictOrderedSemiring → PosMulStrictMono`
* `StrictOrderedSemiring → MulPosStrictMono`
All these are registered as instances, which means that in practice you should not worry about these
implications. However, if you encounter a case where you think a statement is true but not covered
by the current implications, please bring it up on Zulip!
## Notation
The following is local notation in this file:
* `α≥0`: `{x : α // 0 ≤ x}`
* `α>0`: `{x : α // 0 < x}`
See https://leanprover.zulipchat.com/#narrow/stream/113488-general/topic/notation.20for.20positive.20elements
for a discussion about this notation, and whether to enable it globally (note that the notation is
currently global but broken, hence actually only works locally).
-/
variable (α : Type*)
set_option quotPrecheck false in
/-- Local notation for the nonnegative elements of a type `α`. TODO: actually make local. -/
notation "α≥0" => { x : α // 0 ≤ x }
set_option quotPrecheck false in
/-- Local notation for the positive elements of a type `α`. TODO: actually make local. -/
notation "α>0" => { x : α // 0 < x }
section Abbreviations
variable [Mul α] [Zero α] [Preorder α]
/-- Typeclass for monotonicity of multiplication by nonnegative elements on the left,
namely `b₁ ≤ b₂ → a * b₁ ≤ a * b₂` if `0 ≤ a`.
You should usually not use this very granular typeclass directly, but rather a typeclass like
`OrderedSemiring`. -/
abbrev PosMulMono : Prop :=
CovariantClass α≥0 α (fun x y => x * y) (· ≤ ·)
/-- Typeclass for monotonicity of multiplication by nonnegative elements on the right,
namely `a₁ ≤ a₂ → a₁ * b ≤ a₂ * b` if `0 ≤ b`.
You should usually not use this very granular typeclass directly, but rather a typeclass like
`OrderedSemiring`. -/
abbrev MulPosMono : Prop :=
CovariantClass α≥0 α (fun x y => y * x) (· ≤ ·)
/-- Typeclass for strict monotonicity of multiplication by positive elements on the left,
namely `b₁ < b₂ → a * b₁ < a * b₂` if `0 < a`.
You should usually not use this very granular typeclass directly, but rather a typeclass like
`StrictOrderedSemiring`. -/
abbrev PosMulStrictMono : Prop :=
CovariantClass α>0 α (fun x y => x * y) (· < ·)
/-- Typeclass for strict monotonicity of multiplication by positive elements on the right,
namely `a₁ < a₂ → a₁ * b < a₂ * b` if `0 < b`.
You should usually not use this very granular typeclass directly, but rather a typeclass like
`StrictOrderedSemiring`. -/
abbrev MulPosStrictMono : Prop :=
CovariantClass α>0 α (fun x y => y * x) (· < ·)
/-- Typeclass for strict reverse monotonicity of multiplication by nonnegative elements on
the left, namely `a * b₁ < a * b₂ → b₁ < b₂` if `0 ≤ a`.
You should usually not use this very granular typeclass directly, but rather a typeclass like
`LinearOrderedSemiring`. -/
abbrev PosMulReflectLT : Prop :=
ContravariantClass α≥0 α (fun x y => x * y) (· < ·)
/-- Typeclass for strict reverse monotonicity of multiplication by nonnegative elements on
the right, namely `a₁ * b < a₂ * b → a₁ < a₂` if `0 ≤ b`.
You should usually not use this very granular typeclass directly, but rather a typeclass like
`LinearOrderedSemiring`. -/
abbrev MulPosReflectLT : Prop :=
ContravariantClass α≥0 α (fun x y => y * x) (· < ·)
/-- Typeclass for reverse monotonicity of multiplication by positive elements on the left,
namely `a * b₁ ≤ a * b₂ → b₁ ≤ b₂` if `0 < a`.
You should usually not use this very granular typeclass directly, but rather a typeclass like
`LinearOrderedSemiring`. -/
abbrev PosMulReflectLE : Prop :=
ContravariantClass α>0 α (fun x y => x * y) (· ≤ ·)
/-- Typeclass for reverse monotonicity of multiplication by positive elements on the right,
namely `a₁ * b ≤ a₂ * b → a₁ ≤ a₂` if `0 < b`.
You should usually not use this very granular typeclass directly, but rather a typeclass like
`LinearOrderedSemiring`. -/
abbrev MulPosReflectLE : Prop :=
ContravariantClass α>0 α (fun x y => y * x) (· ≤ ·)
end Abbreviations
variable {α} {a b c d : α}
section MulZero
variable [Mul α] [Zero α]
section Preorder
variable [Preorder α]
instance PosMulMono.to_covariantClass_pos_mul_le [PosMulMono α] :
CovariantClass α>0 α (fun x y => x * y) (· ≤ ·) :=
⟨fun a _ _ bc => @CovariantClass.elim α≥0 α (fun x y => x * y) (· ≤ ·) _ ⟨_, a.2.le⟩ _ _ bc⟩
instance MulPosMono.to_covariantClass_pos_mul_le [MulPosMono α] :
CovariantClass α>0 α (fun x y => y * x) (· ≤ ·) :=
⟨fun a _ _ bc => @CovariantClass.elim α≥0 α (fun x y => y * x) (· ≤ ·) _ ⟨_, a.2.le⟩ _ _ bc⟩
instance PosMulReflectLT.to_contravariantClass_pos_mul_lt [PosMulReflectLT α] :
ContravariantClass α>0 α (fun x y => x * y) (· < ·) :=
⟨fun a _ _ bc => @ContravariantClass.elim α≥0 α (fun x y => x * y) (· < ·) _ ⟨_, a.2.le⟩ _ _ bc⟩
instance MulPosReflectLT.to_contravariantClass_pos_mul_lt [MulPosReflectLT α] :
ContravariantClass α>0 α (fun x y => y * x) (· < ·) :=
⟨fun a _ _ bc => @ContravariantClass.elim α≥0 α (fun x y => y * x) (· < ·) _ ⟨_, a.2.le⟩ _ _ bc⟩
@[gcongr]
theorem mul_le_mul_of_nonneg_left [PosMulMono α] (h : b ≤ c) (a0 : 0 ≤ a) : a * b ≤ a * c :=
@CovariantClass.elim α≥0 α (fun x y => x * y) (· ≤ ·) _ ⟨a, a0⟩ _ _ h
@[gcongr]
theorem mul_le_mul_of_nonneg_right [MulPosMono α] (h : b ≤ c) (a0 : 0 ≤ a) : b * a ≤ c * a :=
@CovariantClass.elim α≥0 α (fun x y => y * x) (· ≤ ·) _ ⟨a, a0⟩ _ _ h
@[gcongr]
theorem mul_lt_mul_of_pos_left [PosMulStrictMono α] (bc : b < c) (a0 : 0 < a) : a * b < a * c :=
@CovariantClass.elim α>0 α (fun x y => x * y) (· < ·) _ ⟨a, a0⟩ _ _ bc
@[gcongr]
theorem mul_lt_mul_of_pos_right [MulPosStrictMono α] (bc : b < c) (a0 : 0 < a) : b * a < c * a :=
@CovariantClass.elim α>0 α (fun x y => y * x) (· < ·) _ ⟨a, a0⟩ _ _ bc
theorem lt_of_mul_lt_mul_left [PosMulReflectLT α] (h : a * b < a * c) (a0 : 0 ≤ a) : b < c :=
@ContravariantClass.elim α≥0 α (fun x y => x * y) (· < ·) _ ⟨a, a0⟩ _ _ h
theorem lt_of_mul_lt_mul_right [MulPosReflectLT α] (h : b * a < c * a) (a0 : 0 ≤ a) : b < c :=
@ContravariantClass.elim α≥0 α (fun x y => y * x) (· < ·) _ ⟨a, a0⟩ _ _ h
theorem le_of_mul_le_mul_left [PosMulReflectLE α] (bc : a * b ≤ a * c) (a0 : 0 < a) : b ≤ c :=
@ContravariantClass.elim α>0 α (fun x y => x * y) (· ≤ ·) _ ⟨a, a0⟩ _ _ bc
theorem le_of_mul_le_mul_right [MulPosReflectLE α] (bc : b * a ≤ c * a) (a0 : 0 < a) : b ≤ c :=
@ContravariantClass.elim α>0 α (fun x y => y * x) (· ≤ ·) _ ⟨a, a0⟩ _ _ bc
alias lt_of_mul_lt_mul_of_nonneg_left := lt_of_mul_lt_mul_left
alias lt_of_mul_lt_mul_of_nonneg_right := lt_of_mul_lt_mul_right
alias le_of_mul_le_mul_of_pos_left := le_of_mul_le_mul_left
alias le_of_mul_le_mul_of_pos_right := le_of_mul_le_mul_right
@[simp]
theorem mul_lt_mul_left [PosMulStrictMono α] [PosMulReflectLT α] (a0 : 0 < a) :
a * b < a * c ↔ b < c :=
@rel_iff_cov α>0 α (fun x y => x * y) (· < ·) _ _ ⟨a, a0⟩ _ _
@[simp]
theorem mul_lt_mul_right [MulPosStrictMono α] [MulPosReflectLT α] (a0 : 0 < a) :
b * a < c * a ↔ b < c :=
@rel_iff_cov α>0 α (fun x y => y * x) (· < ·) _ _ ⟨a, a0⟩ _ _
@[simp]
theorem mul_le_mul_left [PosMulMono α] [PosMulReflectLE α] (a0 : 0 < a) : a * b ≤ a * c ↔ b ≤ c :=
@rel_iff_cov α>0 α (fun x y => x * y) (· ≤ ·) _ _ ⟨a, a0⟩ _ _
@[simp]
theorem mul_le_mul_right [MulPosMono α] [MulPosReflectLE α] (a0 : 0 < a) : b * a ≤ c * a ↔ b ≤ c :=
@rel_iff_cov α>0 α (fun x y => y * x) (· ≤ ·) _ _ ⟨a, a0⟩ _ _
alias mul_le_mul_iff_of_pos_left := mul_le_mul_left
alias mul_le_mul_iff_of_pos_right := mul_le_mul_right
alias mul_lt_mul_iff_of_pos_left := mul_lt_mul_left
alias mul_lt_mul_iff_of_pos_right := mul_lt_mul_right
theorem mul_le_mul_of_nonneg [PosMulMono α] [MulPosMono α]
(h₁ : a ≤ b) (h₂ : c ≤ d) (a0 : 0 ≤ a) (d0 : 0 ≤ d) : a * c ≤ b * d :=
(mul_le_mul_of_nonneg_left h₂ a0).trans (mul_le_mul_of_nonneg_right h₁ d0)
@[deprecated (since := "2024-07-13")]
alias mul_le_mul_of_le_of_le := mul_le_mul_of_nonneg
theorem mul_le_mul_of_nonneg' [PosMulMono α] [MulPosMono α]
(h₁ : a ≤ b) (h₂ : c ≤ d) (c0 : 0 ≤ c) (b0 : 0 ≤ b) : a * c ≤ b * d :=
(mul_le_mul_of_nonneg_right h₁ c0).trans (mul_le_mul_of_nonneg_left h₂ b0)
theorem mul_lt_mul_of_le_of_lt_of_pos_of_nonneg [PosMulStrictMono α] [MulPosMono α]
(h₁ : a ≤ b) (h₂ : c < d) (a0 : 0 < a) (d0 : 0 ≤ d) : a * c < b * d :=
(mul_lt_mul_of_pos_left h₂ a0).trans_le (mul_le_mul_of_nonneg_right h₁ d0)
alias mul_lt_mul_of_pos_of_nonneg := mul_lt_mul_of_le_of_lt_of_pos_of_nonneg
theorem mul_lt_mul_of_le_of_lt_of_nonneg_of_pos [PosMulStrictMono α] [MulPosMono α]
(h₁ : a ≤ b) (h₂ : c < d) (c0 : 0 ≤ c) (b0 : 0 < b) : a * c < b * d :=
(mul_le_mul_of_nonneg_right h₁ c0).trans_lt (mul_lt_mul_of_pos_left h₂ b0)
alias mul_lt_mul_of_nonneg_of_pos' := mul_lt_mul_of_le_of_lt_of_nonneg_of_pos
@[deprecated (since := "2024-07-13")]
alias mul_lt_mul_of_le_of_le' := mul_lt_mul_of_le_of_lt_of_nonneg_of_pos
theorem mul_lt_mul_of_lt_of_le_of_nonneg_of_pos [PosMulMono α] [MulPosStrictMono α]
(h₁ : a < b) (h₂ : c ≤ d) (a0 : 0 ≤ a) (d0 : 0 < d) : a * c < b * d :=
(mul_le_mul_of_nonneg_left h₂ a0).trans_lt (mul_lt_mul_of_pos_right h₁ d0)
alias mul_lt_mul_of_nonneg_of_pos := mul_lt_mul_of_lt_of_le_of_nonneg_of_pos
theorem mul_lt_mul_of_lt_of_le_of_pos_of_nonneg [PosMulMono α] [MulPosStrictMono α]
(h₁ : a < b) (h₂ : c ≤ d) (c0 : 0 < c) (b0 : 0 ≤ b) : a * c < b * d :=
(mul_lt_mul_of_pos_right h₁ c0).trans_le (mul_le_mul_of_nonneg_left h₂ b0)
alias mul_lt_mul_of_pos_of_nonneg' := mul_lt_mul_of_lt_of_le_of_pos_of_nonneg
@[deprecated (since := "2024-07-13")]
alias mul_lt_mul_of_le_of_lt' := mul_lt_mul_of_lt_of_le_of_pos_of_nonneg
theorem mul_lt_mul_of_pos [PosMulStrictMono α] [MulPosStrictMono α]
(h₁ : a < b) (h₂ : c < d) (a0 : 0 < a) (d0 : 0 < d) : a * c < b * d :=
(mul_lt_mul_of_pos_left h₂ a0).trans (mul_lt_mul_of_pos_right h₁ d0)
@[deprecated (since := "2024-07-13")]
alias mul_lt_mul_of_pos_of_pos := mul_lt_mul_of_pos
theorem mul_lt_mul_of_pos' [PosMulStrictMono α] [MulPosStrictMono α]
(h₁ : a < b) (h₂ : c < d) (c0 : 0 < c) (b0 : 0 < b) : a * c < b * d :=
(mul_lt_mul_of_pos_right h₁ c0).trans (mul_lt_mul_of_pos_left h₂ b0)
@[deprecated (since := "2024-07-13")]
alias mul_lt_mul_of_lt_of_lt' := mul_lt_mul_of_pos'
alias mul_le_mul := mul_le_mul_of_nonneg'
attribute [gcongr] mul_le_mul
alias mul_lt_mul := mul_lt_mul_of_pos_of_nonneg'
alias mul_lt_mul' := mul_lt_mul_of_nonneg_of_pos'
theorem mul_le_of_mul_le_of_nonneg_left [PosMulMono α] (h : a * b ≤ c) (hle : d ≤ b) (a0 : 0 ≤ a) :
a * d ≤ c :=
(mul_le_mul_of_nonneg_left hle a0).trans h
theorem mul_lt_of_mul_lt_of_nonneg_left [PosMulMono α] (h : a * b < c) (hle : d ≤ b) (a0 : 0 ≤ a) :
a * d < c :=
(mul_le_mul_of_nonneg_left hle a0).trans_lt h
theorem le_mul_of_le_mul_of_nonneg_left [PosMulMono α] (h : a ≤ b * c) (hle : c ≤ d) (b0 : 0 ≤ b) :
a ≤ b * d :=
h.trans (mul_le_mul_of_nonneg_left hle b0)
theorem lt_mul_of_lt_mul_of_nonneg_left [PosMulMono α] (h : a < b * c) (hle : c ≤ d) (b0 : 0 ≤ b) :
a < b * d :=
h.trans_le (mul_le_mul_of_nonneg_left hle b0)
theorem mul_le_of_mul_le_of_nonneg_right [MulPosMono α] (h : a * b ≤ c) (hle : d ≤ a) (b0 : 0 ≤ b) :
d * b ≤ c :=
(mul_le_mul_of_nonneg_right hle b0).trans h
theorem mul_lt_of_mul_lt_of_nonneg_right [MulPosMono α] (h : a * b < c) (hle : d ≤ a) (b0 : 0 ≤ b) :
d * b < c :=
(mul_le_mul_of_nonneg_right hle b0).trans_lt h
theorem le_mul_of_le_mul_of_nonneg_right [MulPosMono α] (h : a ≤ b * c) (hle : b ≤ d) (c0 : 0 ≤ c) :
a ≤ d * c :=
h.trans (mul_le_mul_of_nonneg_right hle c0)
theorem lt_mul_of_lt_mul_of_nonneg_right [MulPosMono α] (h : a < b * c) (hle : b ≤ d) (c0 : 0 ≤ c) :
a < d * c :=
h.trans_le (mul_le_mul_of_nonneg_right hle c0)
end Preorder
section LinearOrder
variable [LinearOrder α]
-- see Note [lower instance priority]
instance (priority := 100) PosMulStrictMono.toPosMulReflectLE [PosMulStrictMono α] :
PosMulReflectLE α :=
⟨(covariant_lt_iff_contravariant_le _ _ _).1 CovariantClass.elim⟩
-- see Note [lower instance priority]
instance (priority := 100) MulPosStrictMono.toMulPosReflectLE [MulPosStrictMono α] :
MulPosReflectLE α :=
⟨(covariant_lt_iff_contravariant_le _ _ _).1 CovariantClass.elim⟩
theorem PosMulReflectLE.toPosMulStrictMono [PosMulReflectLE α] : PosMulStrictMono α :=
⟨(covariant_lt_iff_contravariant_le _ _ _).2 ContravariantClass.elim⟩
theorem MulPosReflectLE.toMulPosStrictMono [MulPosReflectLE α] : MulPosStrictMono α :=
⟨(covariant_lt_iff_contravariant_le _ _ _).2 ContravariantClass.elim⟩
theorem posMulStrictMono_iff_posMulReflectLE : PosMulStrictMono α ↔ PosMulReflectLE α :=
⟨@PosMulStrictMono.toPosMulReflectLE _ _ _ _, @PosMulReflectLE.toPosMulStrictMono _ _ _ _⟩
theorem mulPosStrictMono_iff_mulPosReflectLE : MulPosStrictMono α ↔ MulPosReflectLE α :=
⟨@MulPosStrictMono.toMulPosReflectLE _ _ _ _, @MulPosReflectLE.toMulPosStrictMono _ _ _ _⟩
theorem PosMulReflectLT.toPosMulMono [PosMulReflectLT α] : PosMulMono α :=
⟨(covariant_le_iff_contravariant_lt _ _ _).2 ContravariantClass.elim⟩
theorem MulPosReflectLT.toMulPosMono [MulPosReflectLT α] : MulPosMono α :=
⟨(covariant_le_iff_contravariant_lt _ _ _).2 ContravariantClass.elim⟩
theorem PosMulMono.toPosMulReflectLT [PosMulMono α] : PosMulReflectLT α :=
⟨(covariant_le_iff_contravariant_lt _ _ _).1 CovariantClass.elim⟩
theorem MulPosMono.toMulPosReflectLT [MulPosMono α] : MulPosReflectLT α :=
⟨(covariant_le_iff_contravariant_lt _ _ _).1 CovariantClass.elim⟩
/- TODO: Currently, only one in four of the above are made instances; we could consider making
both directions of `covariant_le_iff_contravariant_lt` and `covariant_lt_iff_contravariant_le`
instances, then all of the above become redundant instances, but there are performance issues. -/
theorem posMulMono_iff_posMulReflectLT : PosMulMono α ↔ PosMulReflectLT α :=
⟨@PosMulMono.toPosMulReflectLT _ _ _ _, @PosMulReflectLT.toPosMulMono _ _ _ _⟩
theorem mulPosMono_iff_mulPosReflectLT : MulPosMono α ↔ MulPosReflectLT α :=
⟨@MulPosMono.toMulPosReflectLT _ _ _ _, @MulPosReflectLT.toMulPosMono _ _ _ _⟩
end LinearOrder
end MulZero
section MulZeroClass
variable [MulZeroClass α]
section Preorder
variable [Preorder α]
/-- Assumes left covariance. -/
theorem Left.mul_pos [PosMulStrictMono α] (ha : 0 < a) (hb : 0 < b) : 0 < a * b := by
simpa only [mul_zero] using mul_lt_mul_of_pos_left hb ha
alias mul_pos := Left.mul_pos
theorem mul_neg_of_pos_of_neg [PosMulStrictMono α] (ha : 0 < a) (hb : b < 0) : a * b < 0 := by
simpa only [mul_zero] using mul_lt_mul_of_pos_left hb ha
@[simp]
theorem mul_pos_iff_of_pos_left [PosMulStrictMono α] [PosMulReflectLT α] (h : 0 < a) :
0 < a * b ↔ 0 < b := by simpa using mul_lt_mul_left (b := 0) h
/-- Assumes right covariance. -/
theorem Right.mul_pos [MulPosStrictMono α] (ha : 0 < a) (hb : 0 < b) : 0 < a * b := by
simpa only [zero_mul] using mul_lt_mul_of_pos_right ha hb
theorem mul_neg_of_neg_of_pos [MulPosStrictMono α] (ha : a < 0) (hb : 0 < b) : a * b < 0 := by
simpa only [zero_mul] using mul_lt_mul_of_pos_right ha hb
@[simp]
theorem mul_pos_iff_of_pos_right [MulPosStrictMono α] [MulPosReflectLT α] (h : 0 < b) :
0 < a * b ↔ 0 < a := by simpa using mul_lt_mul_right (b := 0) h
/-- Assumes left covariance. -/
theorem Left.mul_nonneg [PosMulMono α] (ha : 0 ≤ a) (hb : 0 ≤ b) : 0 ≤ a * b := by
simpa only [mul_zero] using mul_le_mul_of_nonneg_left hb ha
alias mul_nonneg := Left.mul_nonneg
theorem mul_nonpos_of_nonneg_of_nonpos [PosMulMono α] (ha : 0 ≤ a) (hb : b ≤ 0) : a * b ≤ 0 := by
simpa only [mul_zero] using mul_le_mul_of_nonneg_left hb ha
/-- Assumes right covariance. -/
theorem Right.mul_nonneg [MulPosMono α] (ha : 0 ≤ a) (hb : 0 ≤ b) : 0 ≤ a * b := by
simpa only [zero_mul] using mul_le_mul_of_nonneg_right ha hb
theorem mul_nonpos_of_nonpos_of_nonneg [MulPosMono α] (ha : a ≤ 0) (hb : 0 ≤ b) : a * b ≤ 0 := by
simpa only [zero_mul] using mul_le_mul_of_nonneg_right ha hb
theorem pos_of_mul_pos_right [PosMulReflectLT α] (h : 0 < a * b) (ha : 0 ≤ a) : 0 < b :=
lt_of_mul_lt_mul_left ((mul_zero a).symm ▸ h : a * 0 < a * b) ha
theorem pos_of_mul_pos_left [MulPosReflectLT α] (h : 0 < a * b) (hb : 0 ≤ b) : 0 < a :=
lt_of_mul_lt_mul_right ((zero_mul b).symm ▸ h : 0 * b < a * b) hb
theorem pos_iff_pos_of_mul_pos [PosMulReflectLT α] [MulPosReflectLT α] (hab : 0 < a * b) :
0 < a ↔ 0 < b :=
⟨pos_of_mul_pos_right hab ∘ le_of_lt, pos_of_mul_pos_left hab ∘ le_of_lt⟩
/-- Assumes left strict covariance. -/
theorem Left.mul_lt_mul_of_nonneg [PosMulStrictMono α] [MulPosMono α]
(h₁ : a < b) (h₂ : c < d) (a0 : 0 ≤ a) (c0 : 0 ≤ c) : a * c < b * d :=
mul_lt_mul_of_le_of_lt_of_nonneg_of_pos h₁.le h₂ c0 (a0.trans_lt h₁)
/-- Assumes right strict covariance. -/
theorem Right.mul_lt_mul_of_nonneg [PosMulMono α] [MulPosStrictMono α]
(h₁ : a < b) (h₂ : c < d) (a0 : 0 ≤ a) (c0 : 0 ≤ c) : a * c < b * d :=
mul_lt_mul_of_lt_of_le_of_nonneg_of_pos h₁ h₂.le a0 (c0.trans_lt h₂)
alias mul_lt_mul_of_nonneg := Left.mul_lt_mul_of_nonneg
alias mul_lt_mul'' := Left.mul_lt_mul_of_nonneg
attribute [gcongr] mul_lt_mul''
theorem mul_self_le_mul_self [PosMulMono α] [MulPosMono α] (ha : 0 ≤ a) (hab : a ≤ b) :
a * a ≤ b * b :=
mul_le_mul hab hab ha <| ha.trans hab
end Preorder
section PartialOrder
variable [PartialOrder α]
theorem posMulMono_iff_covariant_pos :
PosMulMono α ↔ CovariantClass α>0 α (fun x y => x * y) (· ≤ ·) :=
⟨@PosMulMono.to_covariantClass_pos_mul_le _ _ _ _, fun h =>
⟨fun a b c h => by
obtain ha | ha := a.prop.eq_or_lt
· simp [← ha]
· exact @CovariantClass.elim α>0 α (fun x y => x * y) (· ≤ ·) _ ⟨_, ha⟩ _ _ h ⟩⟩
theorem mulPosMono_iff_covariant_pos :
MulPosMono α ↔ CovariantClass α>0 α (fun x y => y * x) (· ≤ ·) :=
⟨@MulPosMono.to_covariantClass_pos_mul_le _ _ _ _, fun h =>
⟨fun a b c h => by
obtain ha | ha := a.prop.eq_or_lt
· simp [← ha]
· exact @CovariantClass.elim α>0 α (fun x y => y * x) (· ≤ ·) _ ⟨_, ha⟩ _ _ h ⟩⟩
theorem posMulReflectLT_iff_contravariant_pos :
PosMulReflectLT α ↔ ContravariantClass α>0 α (fun x y => x * y) (· < ·) :=
⟨@PosMulReflectLT.to_contravariantClass_pos_mul_lt _ _ _ _, fun h =>
⟨fun a b c h => by
obtain ha | ha := a.prop.eq_or_lt
· simp [← ha] at h
· exact @ContravariantClass.elim α>0 α (fun x y => x * y) (· < ·) _ ⟨_, ha⟩ _ _ h ⟩⟩
theorem mulPosReflectLT_iff_contravariant_pos :
MulPosReflectLT α ↔ ContravariantClass α>0 α (fun x y => y * x) (· < ·) :=
⟨@MulPosReflectLT.to_contravariantClass_pos_mul_lt _ _ _ _, fun h =>
⟨fun a b c h => by
obtain ha | ha := a.prop.eq_or_lt
· simp [← ha] at h
· exact @ContravariantClass.elim α>0 α (fun x y => y * x) (· < ·) _ ⟨_, ha⟩ _ _ h ⟩⟩
-- Porting note: mathlib3 proofs would look like `StrictMono.monotone <| @CovariantClass.elim ..`
-- but implicit argument handling causes that to break
-- see Note [lower instance priority]
instance (priority := 100) PosMulStrictMono.toPosMulMono [PosMulStrictMono α] : PosMulMono α :=
posMulMono_iff_covariant_pos.2 (covariantClass_le_of_lt _ _ _)
-- Porting note: mathlib3 proofs would look like `StrictMono.monotone <| @CovariantClass.elim ..`
-- but implicit argument handling causes that to break
-- see Note [lower instance priority]
instance (priority := 100) MulPosStrictMono.toMulPosMono [MulPosStrictMono α] : MulPosMono α :=
mulPosMono_iff_covariant_pos.2 (covariantClass_le_of_lt _ _ _)
-- see Note [lower instance priority]
instance (priority := 100) PosMulReflectLE.toPosMulReflectLT [PosMulReflectLE α] :
PosMulReflectLT α :=
posMulReflectLT_iff_contravariant_pos.2
⟨fun a b c h =>
(le_of_mul_le_mul_of_pos_left h.le a.2).lt_of_ne <| by
rintro rfl
simp at h⟩
-- see Note [lower instance priority]
instance (priority := 100) MulPosReflectLE.toMulPosReflectLT [MulPosReflectLE α] :
MulPosReflectLT α :=
mulPosReflectLT_iff_contravariant_pos.2
⟨fun a b c h =>
(le_of_mul_le_mul_of_pos_right h.le a.2).lt_of_ne <| by
rintro rfl
simp at h⟩
theorem mul_left_cancel_iff_of_pos [PosMulReflectLE α] (a0 : 0 < a) : a * b = a * c ↔ b = c :=
⟨fun h => (le_of_mul_le_mul_of_pos_left h.le a0).antisymm <|
le_of_mul_le_mul_of_pos_left h.ge a0, congr_arg _⟩
theorem mul_right_cancel_iff_of_pos [MulPosReflectLE α] (b0 : 0 < b) : a * b = c * b ↔ a = c :=
⟨fun h => (le_of_mul_le_mul_of_pos_right h.le b0).antisymm <|
le_of_mul_le_mul_of_pos_right h.ge b0, congr_arg (· * b)⟩
theorem mul_eq_mul_iff_eq_and_eq_of_pos [PosMulStrictMono α] [MulPosStrictMono α]
(hab : a ≤ b) (hcd : c ≤ d) (a0 : 0 < a) (d0 : 0 < d) :
a * c = b * d ↔ a = b ∧ c = d := by
refine ⟨fun h ↦ ?_, by rintro ⟨rfl, rfl⟩; rfl⟩
simp only [eq_iff_le_not_lt, hab, hcd, true_and]
refine ⟨fun hab ↦ h.not_lt ?_, fun hcd ↦ h.not_lt ?_⟩
· exact (mul_le_mul_of_nonneg_left hcd a0.le).trans_lt (mul_lt_mul_of_pos_right hab d0)
· exact (mul_lt_mul_of_pos_left hcd a0).trans_le (mul_le_mul_of_nonneg_right hab d0.le)
theorem mul_eq_mul_iff_eq_and_eq_of_pos' [PosMulStrictMono α] [MulPosStrictMono α]
(hab : a ≤ b) (hcd : c ≤ d) (b0 : 0 < b) (c0 : 0 < c) :
a * c = b * d ↔ a = b ∧ c = d := by
refine ⟨fun h ↦ ?_, by rintro ⟨rfl, rfl⟩; rfl⟩
simp only [eq_iff_le_not_lt, hab, hcd, true_and]
refine ⟨fun hab ↦ h.not_lt ?_, fun hcd ↦ h.not_lt ?_⟩
· exact (mul_lt_mul_of_pos_right hab c0).trans_le (mul_le_mul_of_nonneg_left hcd b0.le)
· exact (mul_le_mul_of_nonneg_right hab c0.le).trans_lt (mul_lt_mul_of_pos_left hcd b0)
end PartialOrder
section LinearOrder
variable [LinearOrder α]
theorem pos_and_pos_or_neg_and_neg_of_mul_pos [PosMulMono α] [MulPosMono α] (hab : 0 < a * b) :
0 < a ∧ 0 < b ∨ a < 0 ∧ b < 0 := by
rcases lt_trichotomy a 0 with (ha | rfl | ha)
· refine Or.inr ⟨ha, lt_imp_lt_of_le_imp_le (fun hb => ?_) hab⟩
exact mul_nonpos_of_nonpos_of_nonneg ha.le hb
· rw [zero_mul] at hab
exact hab.false.elim
· refine Or.inl ⟨ha, lt_imp_lt_of_le_imp_le (fun hb => ?_) hab⟩
exact mul_nonpos_of_nonneg_of_nonpos ha.le hb
theorem neg_of_mul_pos_right [PosMulMono α] [MulPosMono α] (h : 0 < a * b) (ha : a ≤ 0) : b < 0 :=
((pos_and_pos_or_neg_and_neg_of_mul_pos h).resolve_left fun h => h.1.not_le ha).2
theorem neg_of_mul_pos_left [PosMulMono α] [MulPosMono α] (h : 0 < a * b) (ha : b ≤ 0) : a < 0 :=
((pos_and_pos_or_neg_and_neg_of_mul_pos h).resolve_left fun h => h.2.not_le ha).1
theorem neg_iff_neg_of_mul_pos [PosMulMono α] [MulPosMono α] (hab : 0 < a * b) : a < 0 ↔ b < 0 :=
⟨neg_of_mul_pos_right hab ∘ le_of_lt, neg_of_mul_pos_left hab ∘ le_of_lt⟩
theorem Left.neg_of_mul_neg_right [PosMulMono α] (h : a * b < 0) (a0 : 0 ≤ a) : b < 0 :=
lt_of_not_ge fun b0 : b ≥ 0 => (Left.mul_nonneg a0 b0).not_lt h
alias neg_of_mul_neg_right := Left.neg_of_mul_neg_right
theorem Right.neg_of_mul_neg_right [MulPosMono α] (h : a * b < 0) (a0 : 0 ≤ a) : b < 0 :=
lt_of_not_ge fun b0 : b ≥ 0 => (Right.mul_nonneg a0 b0).not_lt h
theorem Left.neg_of_mul_neg_left [PosMulMono α] (h : a * b < 0) (b0 : 0 ≤ b) : a < 0 :=
lt_of_not_ge fun a0 : a ≥ 0 => (Left.mul_nonneg a0 b0).not_lt h
alias neg_of_mul_neg_left := Left.neg_of_mul_neg_left
theorem Right.neg_of_mul_neg_left [MulPosMono α] (h : a * b < 0) (b0 : 0 ≤ b) : a < 0 :=
lt_of_not_ge fun a0 : a ≥ 0 => (Right.mul_nonneg a0 b0).not_lt h
end LinearOrder
end MulZeroClass
section MulOneClass
variable [MulOneClass α] [Zero α]
section Preorder
variable [Preorder α]
/-! Lemmas of the form `a ≤ a * b ↔ 1 ≤ b` and `a * b ≤ a ↔ b ≤ 1`,
which assume left covariance. -/
@[simp]
lemma le_mul_iff_one_le_right [PosMulMono α] [PosMulReflectLE α] (a0 : 0 < a) : a ≤ a * b ↔ 1 ≤ b :=
Iff.trans (by rw [mul_one]) (mul_le_mul_left a0)
@[simp]
theorem lt_mul_iff_one_lt_right [PosMulStrictMono α] [PosMulReflectLT α] (a0 : 0 < a) :
a < a * b ↔ 1 < b :=
Iff.trans (by rw [mul_one]) (mul_lt_mul_left a0)
@[simp]
lemma mul_le_iff_le_one_right [PosMulMono α] [PosMulReflectLE α] (a0 : 0 < a) : a * b ≤ a ↔ b ≤ 1 :=
Iff.trans (by rw [mul_one]) (mul_le_mul_left a0)
@[simp]
theorem mul_lt_iff_lt_one_right [PosMulStrictMono α] [PosMulReflectLT α] (a0 : 0 < a) :
a * b < a ↔ b < 1 :=
Iff.trans (by rw [mul_one]) (mul_lt_mul_left a0)
/-! Lemmas of the form `a ≤ b * a ↔ 1 ≤ b` and `a * b ≤ b ↔ a ≤ 1`,
which assume right covariance. -/
@[simp]
lemma le_mul_iff_one_le_left [MulPosMono α] [MulPosReflectLE α] (a0 : 0 < a) : a ≤ b * a ↔ 1 ≤ b :=
Iff.trans (by rw [one_mul]) (mul_le_mul_right a0)
@[simp]
theorem lt_mul_iff_one_lt_left [MulPosStrictMono α] [MulPosReflectLT α] (a0 : 0 < a) :
a < b * a ↔ 1 < b :=
Iff.trans (by rw [one_mul]) (mul_lt_mul_right a0)
@[simp]
lemma mul_le_iff_le_one_left [MulPosMono α] [MulPosReflectLE α] (b0 : 0 < b) : a * b ≤ b ↔ a ≤ 1 :=
Iff.trans (by rw [one_mul]) (mul_le_mul_right b0)
@[simp]
theorem mul_lt_iff_lt_one_left [MulPosStrictMono α] [MulPosReflectLT α] (b0 : 0 < b) :
a * b < b ↔ a < 1 :=
Iff.trans (by rw [one_mul]) (mul_lt_mul_right b0)
/-! Lemmas of the form `1 ≤ b → a ≤ a * b`.
Variants with `< 0` and `≤ 0` instead of `0 <` and `0 ≤` appear in `Mathlib/Algebra/Order/Ring/Defs`
(which imports this file) as they need additional results which are not yet available here. -/
theorem mul_le_of_le_one_left [MulPosMono α] (hb : 0 ≤ b) (h : a ≤ 1) : a * b ≤ b := by
simpa only [one_mul] using mul_le_mul_of_nonneg_right h hb
theorem le_mul_of_one_le_left [MulPosMono α] (hb : 0 ≤ b) (h : 1 ≤ a) : b ≤ a * b := by
simpa only [one_mul] using mul_le_mul_of_nonneg_right h hb
theorem mul_le_of_le_one_right [PosMulMono α] (ha : 0 ≤ a) (h : b ≤ 1) : a * b ≤ a := by
simpa only [mul_one] using mul_le_mul_of_nonneg_left h ha
theorem le_mul_of_one_le_right [PosMulMono α] (ha : 0 ≤ a) (h : 1 ≤ b) : a ≤ a * b := by
simpa only [mul_one] using mul_le_mul_of_nonneg_left h ha
theorem mul_lt_of_lt_one_left [MulPosStrictMono α] (hb : 0 < b) (h : a < 1) : a * b < b := by
simpa only [one_mul] using mul_lt_mul_of_pos_right h hb
theorem lt_mul_of_one_lt_left [MulPosStrictMono α] (hb : 0 < b) (h : 1 < a) : b < a * b := by
simpa only [one_mul] using mul_lt_mul_of_pos_right h hb
theorem mul_lt_of_lt_one_right [PosMulStrictMono α] (ha : 0 < a) (h : b < 1) : a * b < a := by
simpa only [mul_one] using mul_lt_mul_of_pos_left h ha
theorem lt_mul_of_one_lt_right [PosMulStrictMono α] (ha : 0 < a) (h : 1 < b) : a < a * b := by
simpa only [mul_one] using mul_lt_mul_of_pos_left h ha
/-! Lemmas of the form `b ≤ c → a ≤ 1 → b * a ≤ c`. -/
/- Yaël: What's the point of these lemmas? They just chain an existing lemma with an assumption in
all possible ways, thereby artificially inflating the API and making the truly relevant lemmas hard
to find -/
theorem mul_le_of_le_of_le_one_of_nonneg [PosMulMono α] (h : b ≤ c) (ha : a ≤ 1) (hb : 0 ≤ b) :
b * a ≤ c :=
(mul_le_of_le_one_right hb ha).trans h
theorem mul_lt_of_le_of_lt_one_of_pos [PosMulStrictMono α] (bc : b ≤ c) (ha : a < 1) (b0 : 0 < b) :
b * a < c :=
(mul_lt_of_lt_one_right b0 ha).trans_le bc
theorem mul_lt_of_lt_of_le_one_of_nonneg [PosMulMono α] (h : b < c) (ha : a ≤ 1) (hb : 0 ≤ b) :
b * a < c :=
(mul_le_of_le_one_right hb ha).trans_lt h
/-- Assumes left covariance. -/
theorem Left.mul_le_one_of_le_of_le [PosMulMono α] (ha : a ≤ 1) (hb : b ≤ 1) (a0 : 0 ≤ a) :
a * b ≤ 1 :=
mul_le_of_le_of_le_one_of_nonneg ha hb a0
/-- Assumes left covariance. -/
theorem Left.mul_lt_of_le_of_lt_one_of_pos [PosMulStrictMono α] (ha : a ≤ 1) (hb : b < 1)
(a0 : 0 < a) : a * b < 1 :=
_root_.mul_lt_of_le_of_lt_one_of_pos ha hb a0
/-- Assumes left covariance. -/
theorem Left.mul_lt_of_lt_of_le_one_of_nonneg [PosMulMono α] (ha : a < 1) (hb : b ≤ 1)
(a0 : 0 ≤ a) : a * b < 1 :=
_root_.mul_lt_of_lt_of_le_one_of_nonneg ha hb a0
theorem mul_le_of_le_of_le_one' [PosMulMono α] [MulPosMono α] (bc : b ≤ c) (ha : a ≤ 1) (a0 : 0 ≤ a)
(c0 : 0 ≤ c) : b * a ≤ c :=
(mul_le_mul_of_nonneg_right bc a0).trans <| mul_le_of_le_one_right c0 ha
theorem mul_lt_of_lt_of_le_one' [PosMulMono α] [MulPosStrictMono α] (bc : b < c) (ha : a ≤ 1)
(a0 : 0 < a) (c0 : 0 ≤ c) : b * a < c :=
(mul_lt_mul_of_pos_right bc a0).trans_le <| mul_le_of_le_one_right c0 ha
theorem mul_lt_of_le_of_lt_one' [PosMulStrictMono α] [MulPosMono α] (bc : b ≤ c) (ha : a < 1)
(a0 : 0 ≤ a) (c0 : 0 < c) : b * a < c :=
(mul_le_mul_of_nonneg_right bc a0).trans_lt <| mul_lt_of_lt_one_right c0 ha
theorem mul_lt_of_lt_of_lt_one_of_pos [PosMulMono α] [MulPosStrictMono α] (bc : b < c) (ha : a ≤ 1)
(a0 : 0 < a) (c0 : 0 ≤ c) : b * a < c :=
(mul_lt_mul_of_pos_right bc a0).trans_le <| mul_le_of_le_one_right c0 ha
/-! Lemmas of the form `b ≤ c → 1 ≤ a → b ≤ c * a`. -/
theorem le_mul_of_le_of_one_le_of_nonneg [PosMulMono α] (h : b ≤ c) (ha : 1 ≤ a) (hc : 0 ≤ c) :
b ≤ c * a :=
h.trans <| le_mul_of_one_le_right hc ha
theorem lt_mul_of_le_of_one_lt_of_pos [PosMulStrictMono α] (bc : b ≤ c) (ha : 1 < a) (c0 : 0 < c) :
b < c * a :=
bc.trans_lt <| lt_mul_of_one_lt_right c0 ha
theorem lt_mul_of_lt_of_one_le_of_nonneg [PosMulMono α] (h : b < c) (ha : 1 ≤ a) (hc : 0 ≤ c) :
b < c * a :=
h.trans_le <| le_mul_of_one_le_right hc ha
/-- Assumes left covariance. -/
theorem Left.one_le_mul_of_le_of_le [PosMulMono α] (ha : 1 ≤ a) (hb : 1 ≤ b) (a0 : 0 ≤ a) :
1 ≤ a * b :=
le_mul_of_le_of_one_le_of_nonneg ha hb a0
/-- Assumes left covariance. -/
theorem Left.one_lt_mul_of_le_of_lt_of_pos [PosMulStrictMono α] (ha : 1 ≤ a) (hb : 1 < b)
(a0 : 0 < a) : 1 < a * b :=
lt_mul_of_le_of_one_lt_of_pos ha hb a0
/-- Assumes left covariance. -/
theorem Left.lt_mul_of_lt_of_one_le_of_nonneg [PosMulMono α] (ha : 1 < a) (hb : 1 ≤ b)
(a0 : 0 ≤ a) : 1 < a * b :=
_root_.lt_mul_of_lt_of_one_le_of_nonneg ha hb a0
theorem le_mul_of_le_of_one_le' [PosMulMono α] [MulPosMono α] (bc : b ≤ c) (ha : 1 ≤ a)
(a0 : 0 ≤ a) (b0 : 0 ≤ b) : b ≤ c * a :=
(le_mul_of_one_le_right b0 ha).trans <| mul_le_mul_of_nonneg_right bc a0
theorem lt_mul_of_le_of_one_lt' [PosMulStrictMono α] [MulPosMono α] (bc : b ≤ c) (ha : 1 < a)
(a0 : 0 ≤ a) (b0 : 0 < b) : b < c * a :=
(lt_mul_of_one_lt_right b0 ha).trans_le <| mul_le_mul_of_nonneg_right bc a0
theorem lt_mul_of_lt_of_one_le' [PosMulMono α] [MulPosStrictMono α] (bc : b < c) (ha : 1 ≤ a)
(a0 : 0 < a) (b0 : 0 ≤ b) : b < c * a :=
(le_mul_of_one_le_right b0 ha).trans_lt <| mul_lt_mul_of_pos_right bc a0
theorem lt_mul_of_lt_of_one_lt_of_pos [PosMulStrictMono α] [MulPosStrictMono α] (bc : b < c)
(ha : 1 < a) (a0 : 0 < a) (b0 : 0 < b) : b < c * a :=
(lt_mul_of_one_lt_right b0 ha).trans <| mul_lt_mul_of_pos_right bc a0
/-! Lemmas of the form `a ≤ 1 → b ≤ c → a * b ≤ c`. -/
theorem mul_le_of_le_one_of_le_of_nonneg [MulPosMono α] (ha : a ≤ 1) (h : b ≤ c) (hb : 0 ≤ b) :
a * b ≤ c :=
(mul_le_of_le_one_left hb ha).trans h
theorem mul_lt_of_lt_one_of_le_of_pos [MulPosStrictMono α] (ha : a < 1) (h : b ≤ c) (hb : 0 < b) :
a * b < c :=
(mul_lt_of_lt_one_left hb ha).trans_le h
theorem mul_lt_of_le_one_of_lt_of_nonneg [MulPosMono α] (ha : a ≤ 1) (h : b < c) (hb : 0 ≤ b) :
a * b < c :=
(mul_le_of_le_one_left hb ha).trans_lt h
/-- Assumes right covariance. -/
theorem Right.mul_lt_one_of_lt_of_le_of_pos [MulPosStrictMono α] (ha : a < 1) (hb : b ≤ 1)
(b0 : 0 < b) : a * b < 1 :=
mul_lt_of_lt_one_of_le_of_pos ha hb b0
/-- Assumes right covariance. -/
theorem Right.mul_lt_one_of_le_of_lt_of_nonneg [MulPosMono α] (ha : a ≤ 1) (hb : b < 1)
(b0 : 0 ≤ b) : a * b < 1 :=
mul_lt_of_le_one_of_lt_of_nonneg ha hb b0
theorem mul_lt_of_lt_one_of_lt_of_pos [PosMulStrictMono α] [MulPosStrictMono α] (ha : a < 1)
(bc : b < c) (a0 : 0 < a) (c0 : 0 < c) : a * b < c :=
(mul_lt_mul_of_pos_left bc a0).trans <| mul_lt_of_lt_one_left c0 ha
/-- Assumes right covariance. -/
theorem Right.mul_le_one_of_le_of_le [MulPosMono α] (ha : a ≤ 1) (hb : b ≤ 1) (b0 : 0 ≤ b) :
a * b ≤ 1 :=
mul_le_of_le_one_of_le_of_nonneg ha hb b0
theorem mul_le_of_le_one_of_le' [PosMulMono α] [MulPosMono α] (ha : a ≤ 1) (bc : b ≤ c) (a0 : 0 ≤ a)
(c0 : 0 ≤ c) : a * b ≤ c :=
(mul_le_mul_of_nonneg_left bc a0).trans <| mul_le_of_le_one_left c0 ha
theorem mul_lt_of_lt_one_of_le' [PosMulMono α] [MulPosStrictMono α] (ha : a < 1) (bc : b ≤ c)
(a0 : 0 ≤ a) (c0 : 0 < c) : a * b < c :=
(mul_le_mul_of_nonneg_left bc a0).trans_lt <| mul_lt_of_lt_one_left c0 ha
theorem mul_lt_of_le_one_of_lt' [PosMulStrictMono α] [MulPosMono α] (ha : a ≤ 1) (bc : b < c)
(a0 : 0 < a) (c0 : 0 ≤ c) : a * b < c :=
(mul_lt_mul_of_pos_left bc a0).trans_le <| mul_le_of_le_one_left c0 ha
/-! Lemmas of the form `1 ≤ a → b ≤ c → b ≤ a * c`. -/
theorem lt_mul_of_one_lt_of_le_of_pos [MulPosStrictMono α] (ha : 1 < a) (h : b ≤ c) (hc : 0 < c) :
b < a * c :=
h.trans_lt <| lt_mul_of_one_lt_left hc ha
theorem lt_mul_of_one_le_of_lt_of_nonneg [MulPosMono α] (ha : 1 ≤ a) (h : b < c) (hc : 0 ≤ c) :
b < a * c :=
h.trans_le <| le_mul_of_one_le_left hc ha
theorem lt_mul_of_one_lt_of_lt_of_pos [MulPosStrictMono α] (ha : 1 < a) (h : b < c) (hc : 0 < c) :
b < a * c :=
h.trans <| lt_mul_of_one_lt_left hc ha
/-- Assumes right covariance. -/
theorem Right.one_lt_mul_of_lt_of_le_of_pos [MulPosStrictMono α] (ha : 1 < a) (hb : 1 ≤ b)
(b0 : 0 < b) : 1 < a * b :=
lt_mul_of_one_lt_of_le_of_pos ha hb b0
/-- Assumes right covariance. -/
theorem Right.one_lt_mul_of_le_of_lt_of_nonneg [MulPosMono α] (ha : 1 ≤ a) (hb : 1 < b)
(b0 : 0 ≤ b) : 1 < a * b :=
lt_mul_of_one_le_of_lt_of_nonneg ha hb b0
/-- Assumes right covariance. -/
theorem Right.one_lt_mul_of_lt_of_lt [MulPosStrictMono α] (ha : 1 < a) (hb : 1 < b) (b0 : 0 < b) :
1 < a * b :=
lt_mul_of_one_lt_of_lt_of_pos ha hb b0
theorem lt_mul_of_one_lt_of_lt_of_nonneg [MulPosMono α] (ha : 1 ≤ a) (h : b < c) (hc : 0 ≤ c) :
b < a * c :=
h.trans_le <| le_mul_of_one_le_left hc ha
theorem lt_of_mul_lt_of_one_le_of_nonneg_left [PosMulMono α] (h : a * b < c) (hle : 1 ≤ b)
(ha : 0 ≤ a) : a < c :=
(le_mul_of_one_le_right ha hle).trans_lt h
theorem lt_of_lt_mul_of_le_one_of_nonneg_left [PosMulMono α] (h : a < b * c) (hc : c ≤ 1)
(hb : 0 ≤ b) : a < b :=
h.trans_le <| mul_le_of_le_one_right hb hc
theorem lt_of_lt_mul_of_le_one_of_nonneg_right [MulPosMono α] (h : a < b * c) (hb : b ≤ 1)
(hc : 0 ≤ c) : a < c :=
h.trans_le <| mul_le_of_le_one_left hc hb
theorem le_mul_of_one_le_of_le_of_nonneg [MulPosMono α] (ha : 1 ≤ a) (bc : b ≤ c) (c0 : 0 ≤ c) :
b ≤ a * c :=
bc.trans <| le_mul_of_one_le_left c0 ha
/-- Assumes right covariance. -/
theorem Right.one_le_mul_of_le_of_le [MulPosMono α] (ha : 1 ≤ a) (hb : 1 ≤ b) (b0 : 0 ≤ b) :
1 ≤ a * b :=
le_mul_of_one_le_of_le_of_nonneg ha hb b0
theorem le_of_mul_le_of_one_le_of_nonneg_left [PosMulMono α] (h : a * b ≤ c) (hb : 1 ≤ b)
(ha : 0 ≤ a) : a ≤ c :=
(le_mul_of_one_le_right ha hb).trans h
theorem le_of_le_mul_of_le_one_of_nonneg_left [PosMulMono α] (h : a ≤ b * c) (hc : c ≤ 1)
(hb : 0 ≤ b) : a ≤ b :=
h.trans <| mul_le_of_le_one_right hb hc
theorem le_of_mul_le_of_one_le_nonneg_right [MulPosMono α] (h : a * b ≤ c) (ha : 1 ≤ a)
(hb : 0 ≤ b) : b ≤ c :=
(le_mul_of_one_le_left hb ha).trans h
theorem le_of_le_mul_of_le_one_of_nonneg_right [MulPosMono α] (h : a ≤ b * c) (hb : b ≤ 1)
(hc : 0 ≤ c) : a ≤ c :=
h.trans <| mul_le_of_le_one_left hc hb
end Preorder
section LinearOrder
variable [LinearOrder α]
-- Yaël: What's the point of this lemma? If we have `0 * 0 = 0`, then we can just take `b = 0`.
-- proven with `a0 : 0 ≤ a` as `exists_square_le`
theorem exists_square_le' [PosMulStrictMono α] (a0 : 0 < a) : ∃ b : α, b * b ≤ a := by
obtain ha | ha := lt_or_le a 1
· exact ⟨a, (mul_lt_of_lt_one_right a0 ha).le⟩
· exact ⟨1, by rwa [mul_one]⟩
end LinearOrder
end MulOneClass
section CancelMonoidWithZero
variable [CancelMonoidWithZero α]
section PartialOrder
variable [PartialOrder α]
theorem PosMulMono.toPosMulStrictMono [PosMulMono α] : PosMulStrictMono α :=
⟨fun x _ _ h => (mul_le_mul_of_nonneg_left h.le x.2.le).lt_of_ne
(h.ne ∘ mul_left_cancel₀ x.2.ne')⟩
theorem posMulMono_iff_posMulStrictMono : PosMulMono α ↔ PosMulStrictMono α :=
⟨@PosMulMono.toPosMulStrictMono α _ _, @PosMulStrictMono.toPosMulMono α _ _⟩
theorem MulPosMono.toMulPosStrictMono [MulPosMono α] : MulPosStrictMono α :=
⟨fun x _ _ h => (mul_le_mul_of_nonneg_right h.le x.2.le).lt_of_ne
(h.ne ∘ mul_right_cancel₀ x.2.ne')⟩
theorem mulPosMono_iff_mulPosStrictMono : MulPosMono α ↔ MulPosStrictMono α :=
⟨@MulPosMono.toMulPosStrictMono α _ _, @MulPosStrictMono.toMulPosMono α _ _⟩
theorem PosMulReflectLT.toPosMulReflectLE [PosMulReflectLT α] : PosMulReflectLE α :=
⟨fun x _ _ h =>
h.eq_or_lt.elim (le_of_eq ∘ mul_left_cancel₀ x.2.ne.symm) fun h' =>
(lt_of_mul_lt_mul_left h' x.2.le).le⟩
theorem posMulReflectLE_iff_posMulReflectLT : PosMulReflectLE α ↔ PosMulReflectLT α :=
⟨@PosMulReflectLE.toPosMulReflectLT α _ _, @PosMulReflectLT.toPosMulReflectLE α _ _⟩
theorem MulPosReflectLT.toMulPosReflectLE [MulPosReflectLT α] : MulPosReflectLE α :=
⟨fun x _ _ h => h.eq_or_lt.elim (le_of_eq ∘ mul_right_cancel₀ x.2.ne.symm) fun h' =>
(lt_of_mul_lt_mul_right h' x.2.le).le⟩
theorem mulPosReflectLE_iff_mulPosReflectLT : MulPosReflectLE α ↔ MulPosReflectLT α :=
⟨@MulPosReflectLE.toMulPosReflectLT α _ _, @MulPosReflectLT.toMulPosReflectLE α _ _⟩
end PartialOrder
end CancelMonoidWithZero
section CommSemigroupHasZero
variable [Mul α] [IsSymmOp α α (· * ·)] [Zero α] [Preorder α]
theorem posMulStrictMono_iff_mulPosStrictMono : PosMulStrictMono α ↔ MulPosStrictMono α := by
simp only [PosMulStrictMono, MulPosStrictMono, IsSymmOp.symm_op]
theorem posMulReflectLT_iff_mulPosReflectLT : PosMulReflectLT α ↔ MulPosReflectLT α := by
simp only [PosMulReflectLT, MulPosReflectLT, IsSymmOp.symm_op]
theorem posMulMono_iff_mulPosMono : PosMulMono α ↔ MulPosMono α := by
simp only [PosMulMono, MulPosMono, IsSymmOp.symm_op]
theorem posMulReflectLE_iff_mulPosReflectLE : PosMulReflectLE α ↔ MulPosReflectLE α := by
simp only [PosMulReflectLE, MulPosReflectLE, IsSymmOp.symm_op]
end CommSemigroupHasZero
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.