source stringlengths 17 118 | lean4 stringlengths 0 335k |
|---|---|
.lake/packages/mathlib/Mathlib/Algebra/Opposites.lean | import Mathlib.Algebra.Group.Defs
import Mathlib.Logic.Equiv.Defs
import Mathlib.Logic.Nontrivial.Basic
/-!
# Multiplicative opposite and algebraic operations on it
In this file we define `MulOpposite α = αᵐᵒᵖ` to be the multiplicative opposite of `α`. It inherits
all additive algebraic structures on `α` (in other files), and reverses the order of multipliers in
multiplicative structures, i.e., `op (x * y) = op y * op x`, where `MulOpposite.op` is the
canonical map from `α` to `αᵐᵒᵖ`.
We also define `AddOpposite α = αᵃᵒᵖ` to be the additive opposite of `α`. It inherits all
multiplicative algebraic structures on `α` (in other files), and reverses the order of summands in
additive structures, i.e. `op (x + y) = op y + op x`, where `AddOpposite.op` is the canonical map
from `α` to `αᵃᵒᵖ`.
## Notation
* `αᵐᵒᵖ = MulOpposite α`
* `αᵃᵒᵖ = AddOpposite α`
## Implementation notes
In mathlib3 `αᵐᵒᵖ` was just a type synonym for `α`, marked irreducible after the API
was developed. In mathlib4 we use a structure with one field, because it is not possible
to change the reducibility of a declaration after its definition, and because Lean 4 has
definitional eta reduction for structures (Lean 3 does not).
## Tags
multiplicative opposite, additive opposite
-/
variable {α β : Type*}
open Function
/-- Auxiliary type to implement `MulOpposite` and `AddOpposite`.
It turns out to be convenient to have `MulOpposite α = AddOpposite α` true by definition, in the
same way that it is convenient to have `Additive α = α`; this means that we also get the defeq
`AddOpposite (Additive α) = MulOpposite α`, which is convenient when working with quotients.
This is a compromise between making `MulOpposite α = AddOpposite α = α` (what we had in Lean 3) and
having no defeqs within those three types (which we had as of https://github.com/leanprover-community/mathlib4/pull/1036). -/
structure PreOpposite (α : Type*) : Type _ where
/-- The element of `PreOpposite α` that represents `x : α`. -/ op' ::
/-- The element of `α` represented by `x : PreOpposite α`. -/ unop' : α
/-- Multiplicative opposite of a type. This type inherits all additive structures on `α` and
reverses left and right in multiplication. -/
@[to_additive
/-- Additive opposite of a type. This type inherits all multiplicative structures on `α` and
reverses left and right in addition. -/]
def MulOpposite (α : Type*) : Type _ := PreOpposite α
/-- Multiplicative opposite of a type. -/
postfix:max "ᵐᵒᵖ" => MulOpposite
/-- Additive opposite of a type. -/
postfix:max "ᵃᵒᵖ" => AddOpposite
namespace MulOpposite
/-- The element of `MulOpposite α` that represents `x : α`. -/
@[to_additive /-- The element of `αᵃᵒᵖ` that represents `x : α`. -/]
def op : α → αᵐᵒᵖ :=
PreOpposite.op'
/-- The element of `α` represented by `x : αᵐᵒᵖ`. -/
@[to_additive (attr := pp_nodot) /-- The element of `α` represented by `x : αᵃᵒᵖ`. -/]
def unop : αᵐᵒᵖ → α :=
PreOpposite.unop'
@[to_additive (attr := simp)]
theorem unop_op (x : α) : unop (op x) = x := rfl
@[to_additive (attr := simp)]
theorem op_unop (x : αᵐᵒᵖ) : op (unop x) = x :=
rfl
@[to_additive (attr := simp)]
theorem op_comp_unop : (op : α → αᵐᵒᵖ) ∘ unop = id :=
rfl
@[to_additive (attr := simp)]
theorem unop_comp_op : (unop : αᵐᵒᵖ → α) ∘ op = id :=
rfl
/-- A recursor for `MulOpposite`. Use as `induction x`. -/
@[to_additive (attr := simp, elab_as_elim, induction_eliminator, cases_eliminator)
/-- A recursor for `AddOpposite`. Use as `induction x`. -/]
protected def rec' {F : αᵐᵒᵖ → Sort*} (h : ∀ X, F (op X)) : ∀ X, F X := fun X ↦ h (unop X)
/-- The canonical bijection between `α` and `αᵐᵒᵖ`. -/
@[to_additive (attr := simps -fullyApplied apply symm_apply)
/-- The canonical bijection between `α` and `αᵃᵒᵖ`. -/]
def opEquiv : α ≃ αᵐᵒᵖ :=
⟨op, unop, unop_op, op_unop⟩
@[to_additive]
theorem op_bijective : Bijective (op : α → αᵐᵒᵖ) :=
opEquiv.bijective
@[to_additive]
theorem unop_bijective : Bijective (unop : αᵐᵒᵖ → α) :=
opEquiv.symm.bijective
@[to_additive]
theorem op_injective : Injective (op : α → αᵐᵒᵖ) :=
op_bijective.injective
@[to_additive]
theorem op_surjective : Surjective (op : α → αᵐᵒᵖ) :=
op_bijective.surjective
@[to_additive]
theorem unop_injective : Injective (unop : αᵐᵒᵖ → α) :=
unop_bijective.injective
@[to_additive]
theorem unop_surjective : Surjective (unop : αᵐᵒᵖ → α) :=
unop_bijective.surjective
@[to_additive (attr := simp)]
theorem op_inj {x y : α} : op x = op y ↔ x = y := iff_of_eq <| PreOpposite.op'.injEq _ _
@[to_additive (attr := simp, nolint simpComm)]
theorem unop_inj {x y : αᵐᵒᵖ} : unop x = unop y ↔ x = y :=
unop_injective.eq_iff
attribute [nolint simpComm] AddOpposite.unop_inj
@[to_additive (attr := simp)] lemma «forall» {p : αᵐᵒᵖ → Prop} : (∀ a, p a) ↔ ∀ a, p (op a) :=
op_surjective.forall
@[to_additive (attr := simp)] lemma «exists» {p : αᵐᵒᵖ → Prop} : (∃ a, p a) ↔ ∃ a, p (op a) :=
op_surjective.exists
@[to_additive] instance instNontrivial [Nontrivial α] : Nontrivial αᵐᵒᵖ := op_injective.nontrivial
@[to_additive] instance instInhabited [Inhabited α] : Inhabited αᵐᵒᵖ := ⟨op default⟩
@[to_additive]
instance instSubsingleton [Subsingleton α] : Subsingleton αᵐᵒᵖ := unop_injective.subsingleton
@[to_additive] instance instUnique [Unique α] : Unique αᵐᵒᵖ := Unique.mk' _
@[to_additive] instance instIsEmpty [IsEmpty α] : IsEmpty αᵐᵒᵖ := Function.isEmpty unop
@[to_additive]
instance instDecidableEq [DecidableEq α] : DecidableEq αᵐᵒᵖ := unop_injective.decidableEq
instance instZero [Zero α] : Zero αᵐᵒᵖ where zero := op 0
@[to_additive] instance instOne [One α] : One αᵐᵒᵖ where one := op 1
instance instAdd [Add α] : Add αᵐᵒᵖ where add x y := op (unop x + unop y)
instance instSub [Sub α] : Sub αᵐᵒᵖ where sub x y := op (unop x - unop y)
instance instNeg [Neg α] : Neg αᵐᵒᵖ where neg x := op <| -unop x
instance instInvolutiveNeg [InvolutiveNeg α] : InvolutiveNeg αᵐᵒᵖ where
neg_neg _ := unop_injective <| neg_neg _
@[to_additive] instance instMul [Mul α] : Mul αᵐᵒᵖ where mul x y := op (unop y * unop x)
@[to_additive] instance instInv [Inv α] : Inv αᵐᵒᵖ where inv x := op <| (unop x)⁻¹
@[to_additive]
instance instInvolutiveInv [InvolutiveInv α] : InvolutiveInv αᵐᵒᵖ where
inv_inv _ := unop_injective <| inv_inv _
instance [Add α] [IsLeftCancelAdd α] : IsLeftCancelAdd αᵐᵒᵖ where
add_left_cancel _ _ _ eq := unop_injective <| add_left_cancel (congr_arg unop eq)
instance [Add α] [IsRightCancelAdd α] : IsRightCancelAdd αᵐᵒᵖ where
add_right_cancel _ _ _ eq := unop_injective <| add_right_cancel (congr_arg unop eq)
instance [Add α] [IsCancelAdd α] : IsCancelAdd αᵐᵒᵖ where
theorem isLeftCancelAdd_iff [Add α] : IsLeftCancelAdd αᵐᵒᵖ ↔ IsLeftCancelAdd α where
mp _ := ⟨fun _ _ _ eq ↦ op_injective <| add_left_cancel (congr_arg op eq)⟩
mpr _ := inferInstance
theorem isRightCancelAdd_iff [Add α] : IsRightCancelAdd αᵐᵒᵖ ↔ IsRightCancelAdd α where
mp _ := ⟨fun _ _ _ eq ↦ op_injective <| add_right_cancel (congr_arg op eq)⟩
mpr _ := inferInstance
protected theorem isCancelAdd_iff [Add α] : IsCancelAdd αᵐᵒᵖ ↔ IsCancelAdd α := by
simp_rw [isCancelAdd_iff, isLeftCancelAdd_iff, isRightCancelAdd_iff]
@[to_additive] instance instSMul [SMul α β] : SMul α βᵐᵒᵖ where smul c x := op (c • unop x)
@[simp] lemma op_zero [Zero α] : op (0 : α) = 0 := rfl
@[simp] lemma unop_zero [Zero α] : unop (0 : αᵐᵒᵖ) = 0 := rfl
@[to_additive (attr := simp)] lemma op_one [One α] : op (1 : α) = 1 := rfl
@[to_additive (attr := simp)] lemma unop_one [One α] : unop (1 : αᵐᵒᵖ) = 1 := rfl
@[simp] lemma op_add [Add α] (x y : α) : op (x + y) = op x + op y := rfl
@[simp] lemma unop_add [Add α] (x y : αᵐᵒᵖ) : unop (x + y) = unop x + unop y := rfl
@[simp] lemma op_neg [Neg α] (x : α) : op (-x) = -op x := rfl
@[simp] lemma unop_neg [Neg α] (x : αᵐᵒᵖ) : unop (-x) = -unop x := rfl
@[to_additive (attr := simp)] lemma op_mul [Mul α] (x y : α) : op (x * y) = op y * op x := rfl
@[to_additive (attr := simp)]
lemma unop_mul [Mul α] (x y : αᵐᵒᵖ) : unop (x * y) = unop y * unop x := rfl
@[to_additive (attr := simp)] lemma op_inv [Inv α] (x : α) : op x⁻¹ = (op x)⁻¹ := rfl
@[to_additive (attr := simp)] lemma unop_inv [Inv α] (x : αᵐᵒᵖ) : unop x⁻¹ = (unop x)⁻¹ := rfl
@[simp] lemma op_sub [Sub α] (x y : α) : op (x - y) = op x - op y := rfl
@[simp] lemma unop_sub [Sub α] (x y : αᵐᵒᵖ) : unop (x - y) = unop x - unop y := rfl
@[to_additive (attr := simp)]
lemma op_smul [SMul α β] (a : α) (b : β) : op (a • b) = a • op b := rfl
@[to_additive (attr := simp)]
lemma unop_smul [SMul α β] (a : α) (b : βᵐᵒᵖ) : unop (a • b) = a • unop b := rfl
@[simp, nolint simpComm]
theorem unop_eq_zero_iff [Zero α] (a : αᵐᵒᵖ) : a.unop = (0 : α) ↔ a = (0 : αᵐᵒᵖ) :=
unop_injective.eq_iff' rfl
@[simp]
theorem op_eq_zero_iff [Zero α] (a : α) : op a = (0 : αᵐᵒᵖ) ↔ a = (0 : α) :=
op_injective.eq_iff' rfl
theorem unop_ne_zero_iff [Zero α] (a : αᵐᵒᵖ) : a.unop ≠ (0 : α) ↔ a ≠ (0 : αᵐᵒᵖ) :=
not_congr <| unop_eq_zero_iff a
theorem op_ne_zero_iff [Zero α] (a : α) : op a ≠ (0 : αᵐᵒᵖ) ↔ a ≠ (0 : α) :=
not_congr <| op_eq_zero_iff a
@[to_additive (attr := simp, nolint simpComm)]
theorem unop_eq_one_iff [One α] (a : αᵐᵒᵖ) : a.unop = 1 ↔ a = 1 :=
unop_injective.eq_iff' rfl
attribute [nolint simpComm] AddOpposite.unop_eq_zero_iff
@[to_additive (attr := simp)]
lemma op_eq_one_iff [One α] (a : α) : op a = 1 ↔ a = 1 := op_injective.eq_iff
end MulOpposite
namespace AddOpposite
instance instOne [One α] : One αᵃᵒᵖ where one := op 1
@[simp] lemma op_one [One α] : op (1 : α) = 1 := rfl
@[simp] lemma unop_one [One α] : unop 1 = (1 : α) := rfl
@[simp] lemma op_eq_one_iff [One α] {a : α} : op a = 1 ↔ a = 1 := op_injective.eq_iff
@[simp] lemma unop_eq_one_iff [One α] {a : αᵃᵒᵖ} : unop a = 1 ↔ a = 1 := unop_injective.eq_iff
attribute [nolint simpComm] unop_eq_one_iff
instance instMul [Mul α] : Mul αᵃᵒᵖ where mul a b := op (unop a * unop b)
@[simp] lemma op_mul [Mul α] (a b : α) : op (a * b) = op a * op b := rfl
@[simp] lemma unop_mul [Mul α] (a b : αᵃᵒᵖ) : unop (a * b) = unop a * unop b := rfl
instance instInv [Inv α] : Inv αᵃᵒᵖ where inv a := op (unop a)⁻¹
instance instInvolutiveInv [InvolutiveInv α] : InvolutiveInv αᵃᵒᵖ where
inv_inv _ := unop_injective <| inv_inv _
@[simp] lemma op_inv [Inv α] (a : α) : op a⁻¹ = (op a)⁻¹ := rfl
@[simp] lemma unop_inv [Inv α] (a : αᵃᵒᵖ) : unop a⁻¹ = (unop a)⁻¹ := rfl
instance instDiv [Div α] : Div αᵃᵒᵖ where div a b := op (unop a / unop b)
@[simp] lemma op_div [Div α] (a b : α) : op (a / b) = op a / op b := rfl
@[simp] lemma unop_div [Div α] (a b : αᵃᵒᵖ) : unop (a / b) = unop a / unop b := rfl
end AddOpposite |
.lake/packages/mathlib/Mathlib/Algebra/DualQuaternion.lean | import Mathlib.Algebra.DualNumber
import Mathlib.Algebra.Quaternion
/-!
# Dual quaternions
Similar to the way that rotations in 3D space can be represented by quaternions of unit length,
rigid motions in 3D space can be represented by dual quaternions of unit length.
## Main results
* `Quaternion.dualNumberEquiv`: quaternions over dual numbers or dual
numbers over quaternions are equivalent constructions.
## References
* <https://en.wikipedia.org/wiki/Dual_quaternion>
-/
variable {R : Type*} [CommRing R]
namespace Quaternion
/-- The dual quaternions can be equivalently represented as a quaternion with dual coefficients,
or as a dual number with quaternion coefficients.
See also `Matrix.dualNumberEquiv` for a similar result. -/
def dualNumberEquiv : Quaternion (DualNumber R) ≃ₐ[R] DualNumber (Quaternion R) where
toFun q :=
(⟨q.re.fst, q.imI.fst, q.imJ.fst, q.imK.fst⟩, ⟨q.re.snd, q.imI.snd, q.imJ.snd, q.imK.snd⟩)
invFun d :=
⟨(d.fst.re, d.snd.re), (d.fst.imI, d.snd.imI), (d.fst.imJ, d.snd.imJ), (d.fst.imK, d.snd.imK)⟩
map_mul' := by
intros
ext : 1
· rfl
· dsimp
congr 1 <;> simp <;> ring
map_add' := by
intros
rfl
commutes' _ := rfl
/-! Lemmas characterizing `Quaternion.dualNumberEquiv`. -/
-- `simps` can't work on `DualNumber` because it's not a structure
@[simp]
theorem re_fst_dualNumberEquiv (q : Quaternion (DualNumber R)) :
(dualNumberEquiv q).fst.re = q.re.fst :=
rfl
@[simp]
theorem imI_fst_dualNumberEquiv (q : Quaternion (DualNumber R)) :
(dualNumberEquiv q).fst.imI = q.imI.fst :=
rfl
@[simp]
theorem imJ_fst_dualNumberEquiv (q : Quaternion (DualNumber R)) :
(dualNumberEquiv q).fst.imJ = q.imJ.fst :=
rfl
@[simp]
theorem imK_fst_dualNumberEquiv (q : Quaternion (DualNumber R)) :
(dualNumberEquiv q).fst.imK = q.imK.fst :=
rfl
@[simp]
theorem re_snd_dualNumberEquiv (q : Quaternion (DualNumber R)) :
(dualNumberEquiv q).snd.re = q.re.snd :=
rfl
@[simp]
theorem imI_snd_dualNumberEquiv (q : Quaternion (DualNumber R)) :
(dualNumberEquiv q).snd.imI = q.imI.snd :=
rfl
@[simp]
theorem imJ_snd_dualNumberEquiv (q : Quaternion (DualNumber R)) :
(dualNumberEquiv q).snd.imJ = q.imJ.snd :=
rfl
@[simp]
theorem imK_snd_dualNumberEquiv (q : Quaternion (DualNumber R)) :
(dualNumberEquiv q).snd.imK = q.imK.snd :=
rfl
@[simp]
theorem fst_re_dualNumberEquiv_symm (d : DualNumber (Quaternion R)) :
(dualNumberEquiv.symm d).re.fst = d.fst.re :=
rfl
@[simp]
theorem fst_imI_dualNumberEquiv_symm (d : DualNumber (Quaternion R)) :
(dualNumberEquiv.symm d).imI.fst = d.fst.imI :=
rfl
@[simp]
theorem fst_imJ_dualNumberEquiv_symm (d : DualNumber (Quaternion R)) :
(dualNumberEquiv.symm d).imJ.fst = d.fst.imJ :=
rfl
@[simp]
theorem fst_imK_dualNumberEquiv_symm (d : DualNumber (Quaternion R)) :
(dualNumberEquiv.symm d).imK.fst = d.fst.imK :=
rfl
@[simp]
theorem snd_re_dualNumberEquiv_symm (d : DualNumber (Quaternion R)) :
(dualNumberEquiv.symm d).re.snd = d.snd.re :=
rfl
@[simp]
theorem snd_imI_dualNumberEquiv_symm (d : DualNumber (Quaternion R)) :
(dualNumberEquiv.symm d).imI.snd = d.snd.imI :=
rfl
@[simp]
theorem snd_imJ_dualNumberEquiv_symm (d : DualNumber (Quaternion R)) :
(dualNumberEquiv.symm d).imJ.snd = d.snd.imJ :=
rfl
@[simp]
theorem snd_imK_dualNumberEquiv_symm (d : DualNumber (Quaternion R)) :
(dualNumberEquiv.symm d).imK.snd = d.snd.imK :=
rfl
end Quaternion |
.lake/packages/mathlib/Mathlib/Algebra/Quandle.lean | import Mathlib.Algebra.Group.End
import Mathlib.Data.ZMod.Defs
import Mathlib.Tactic.Ring
/-!
# Racks and Quandles
This file defines racks and quandles, algebraic structures for sets
that bijectively act on themselves with a self-distributivity
property. If `R` is a rack and `act : R → (R ≃ R)` is the self-action,
then the self-distributivity is, equivalently, that
```
act (act x y) = act x * act y * (act x)⁻¹
```
where multiplication is composition in `R ≃ R` as a group.
Quandles are racks such that `act x x = x` for all `x`.
One example of a quandle (not yet in mathlib) is the action of a Lie
algebra on itself, defined by `act x y = Ad (exp x) y`.
Quandles and racks were independently developed by multiple
mathematicians. David Joyce introduced quandles in his thesis
[Joyce1982] to define an algebraic invariant of knot and link
complements that is analogous to the fundamental group of the
exterior, and he showed that the quandle associated to an oriented
knot is invariant up to orientation-reversed mirror image. Racks were
used by Fenn and Rourke for framed codimension-2 knots and
links in [FennRourke1992]. Unital shelves are discussed in [crans2017].
The name "rack" came from wordplay by Conway and Wraith for the "wrack
and ruin" of forgetting everything but the conjugation operation for a
group.
## Main definitions
* `Shelf` is a type with a self-distributive action
* `UnitalShelf` is a shelf with a left and right unit
* `Rack` is a shelf whose action for each element is invertible
* `Quandle` is a rack whose action for an element fixes that element
* `Quandle.conj` defines a quandle of a group acting on itself by conjugation.
* `ShelfHom` is homomorphisms of shelves, racks, and quandles.
* `Rack.EnvelGroup` gives the universal group the rack maps to as a conjugation quandle.
* `Rack.oppositeRack` gives the rack with the action replaced by its inverse.
## Main statements
* `Rack.EnvelGroup` is left adjoint to `Quandle.Conj` (`toEnvelGroup.map`).
The universality statements are `toEnvelGroup.univ` and `toEnvelGroup.univ_uniq`.
## Implementation notes
"Unital racks" are uninteresting (see `Rack.assoc_iff_id`, `UnitalShelf.assoc`), so we do not
define them.
## Notation
The following notation is localized in `quandles`:
* `x ◃ y` is `Shelf.act x y`
* `x ◃⁻¹ y` is `Rack.inv_act x y`
* `S →◃ S'` is `ShelfHom S S'`
Use `open quandles` to use these.
## TODO
* If `g` is the Lie algebra of a Lie group `G`, then `(x ◃ y) = Ad (exp x) x` forms a quandle.
* If `X` is a symmetric space, then each point has a corresponding involution that acts on `X`,
forming a quandle.
* Alexander quandle with `a ◃ b = t * b + (1 - t) * b`, with `a` and `b` elements
of a module over `Z[t,t⁻¹]`.
* If `G` is a group, `H` a subgroup, and `z` in `H`, then there is a quandle `(G/H;z)` defined by
`yH ◃ xH = yzy⁻¹xH`. Every homogeneous quandle (i.e., a quandle `Q` whose automorphism group acts
transitively on `Q` as a set) is isomorphic to such a quandle.
There is a generalization to this arbitrary quandles in [Joyce's paper (Theorem 7.2)][Joyce1982].
## Tags
rack, quandle
-/
open MulOpposite
universe u v
/-- A *Shelf* is a structure with a self-distributive binary operation.
The binary operation is regarded as a left action of the type on itself.
-/
class Shelf (α : Type u) where
/-- The action of the `Shelf` over `α` -/
act : α → α → α
/-- A verification that `act` is self-distributive -/
self_distrib : ∀ {x y z : α}, act x (act y z) = act (act x y) (act x z)
/--
A *unital shelf* is a shelf equipped with an element `1` such that, for all elements `x`,
we have both `x ◃ 1` and `1 ◃ x` equal `x`.
-/
class UnitalShelf (α : Type u) extends Shelf α, One α where
one_act : ∀ a : α, act 1 a = a
act_one : ∀ a : α, act a 1 = a
/-- The type of homomorphisms between shelves.
This is also the notion of rack and quandle homomorphisms.
-/
@[ext]
structure ShelfHom (S₁ : Type*) (S₂ : Type*) [Shelf S₁] [Shelf S₂] where
/-- The function under the Shelf Homomorphism -/
toFun : S₁ → S₂
/-- The homomorphism property of a Shelf Homomorphism -/
map_act' : ∀ {x y : S₁}, toFun (Shelf.act x y) = Shelf.act (toFun x) (toFun y)
/-- A *rack* is an automorphic set (a set with an action on itself by
bijections) that is self-distributive. It is a shelf such that each
element's action is invertible.
The notations `x ◃ y` and `x ◃⁻¹ y` denote the action and the
inverse action, respectively, and they are right associative.
-/
class Rack (α : Type u) extends Shelf α where
/-- The inverse actions of the elements -/
invAct : α → α → α
/-- Proof of left inverse -/
left_inv : ∀ x, Function.LeftInverse (invAct x) (act x)
/-- Proof of right inverse -/
right_inv : ∀ x, Function.RightInverse (invAct x) (act x)
/-- Action of a Shelf -/
scoped[Quandles] infixr:65 " ◃ " => Shelf.act
/-- Inverse Action of a Rack -/
scoped[Quandles] infixr:65 " ◃⁻¹ " => Rack.invAct
/-- Shelf Homomorphism -/
scoped[Quandles] infixr:25 " →◃ " => ShelfHom
open Quandles
namespace UnitalShelf
open Shelf
variable {S : Type*} [UnitalShelf S]
/--
A monoid is *graphic* if, for all `x` and `y`, the *graphic identity*
`(x * y) * x = x * y` holds. For a unital shelf, this graphic
identity holds.
-/
lemma act_act_self_eq (x y : S) : (x ◃ y) ◃ x = x ◃ y := by
have h : (x ◃ y) ◃ x = (x ◃ y) ◃ (x ◃ 1) := by rw [act_one]
rw [h, ← Shelf.self_distrib, act_one]
lemma act_idem (x : S) : (x ◃ x) = x := by rw [← act_one x, ← Shelf.self_distrib, act_one]
lemma act_self_act_eq (x y : S) : x ◃ (x ◃ y) = x ◃ y := by
have h : x ◃ (x ◃ y) = (x ◃ 1) ◃ (x ◃ y) := by rw [act_one]
rw [h, ← Shelf.self_distrib, one_act]
/--
The associativity of a unital shelf comes for free.
-/
lemma assoc (x y z : S) : (x ◃ y) ◃ z = x ◃ y ◃ z := by
rw [self_distrib, self_distrib, act_act_self_eq, act_self_act_eq]
end UnitalShelf
namespace Rack
variable {R : Type*} [Rack R]
export Shelf (self_distrib)
/-- A rack acts on itself by equivalences. -/
def act' (x : R) : R ≃ R where
toFun := Shelf.act x
invFun := invAct x
left_inv := left_inv x
right_inv := right_inv x
@[simp]
theorem act'_apply (x y : R) : act' x y = x ◃ y :=
rfl
@[simp]
theorem act'_symm_apply (x y : R) : (act' x).symm y = x ◃⁻¹ y :=
rfl
@[simp]
theorem invAct_apply (x y : R) : (act' x)⁻¹ y = x ◃⁻¹ y :=
rfl
@[simp]
theorem invAct_act_eq (x y : R) : x ◃⁻¹ x ◃ y = y :=
left_inv x y
@[simp]
theorem act_invAct_eq (x y : R) : x ◃ x ◃⁻¹ y = y :=
right_inv x y
theorem left_cancel (x : R) {y y' : R} : x ◃ y = x ◃ y' ↔ y = y' := by
constructor
· apply (act' x).injective
rintro rfl
rfl
theorem left_cancel_inv (x : R) {y y' : R} : x ◃⁻¹ y = x ◃⁻¹ y' ↔ y = y' := by
constructor
· apply (act' x).symm.injective
rintro rfl
rfl
theorem self_distrib_inv {x y z : R} : x ◃⁻¹ y ◃⁻¹ z = (x ◃⁻¹ y) ◃⁻¹ x ◃⁻¹ z := by
rw [← left_cancel (x ◃⁻¹ y), right_inv, ← left_cancel x, right_inv, self_distrib]
repeat' rw [right_inv]
/-- The *adjoint action* of a rack on itself is `op'`, and the adjoint
action of `x ◃ y` is the conjugate of the action of `y` by the action
of `x`. It is another way to understand the self-distributivity axiom.
This is used in the natural rack homomorphism `toConj` from `R` to
`Conj (R ≃ R)` defined by `op'`.
-/
theorem ad_conj {R : Type*} [Rack R] (x y : R) : act' (x ◃ y) = act' x * act' y * (act' x)⁻¹ := by
rw [eq_mul_inv_iff_mul_eq]; ext z
apply self_distrib.symm
/-- The opposite rack, swapping the roles of `◃` and `◃⁻¹`.
-/
instance oppositeRack : Rack Rᵐᵒᵖ where
act x y := op (invAct (unop x) (unop y))
self_distrib := by
intro x y z
induction x
induction y
induction z
simp only [op_inj, unop_op]
rw [self_distrib_inv]
invAct x y := op (Shelf.act (unop x) (unop y))
left_inv := MulOpposite.rec' fun x => MulOpposite.rec' fun y => by simp
right_inv := MulOpposite.rec' fun x => MulOpposite.rec' fun y => by simp
@[simp]
theorem op_act_op_eq {x y : R} : op x ◃ op y = op (x ◃⁻¹ y) :=
rfl
@[simp]
theorem op_invAct_op_eq {x y : R} : op x ◃⁻¹ op y = op (x ◃ y) :=
rfl
@[simp]
theorem self_act_act_eq {x y : R} : (x ◃ x) ◃ y = x ◃ y := by rw [← right_inv x y, ← self_distrib]
@[simp]
theorem self_invAct_invAct_eq {x y : R} : (x ◃⁻¹ x) ◃⁻¹ y = x ◃⁻¹ y := by
have h := @self_act_act_eq _ _ (op x) (op y)
simpa using h
@[simp]
theorem self_act_invAct_eq {x y : R} : (x ◃ x) ◃⁻¹ y = x ◃⁻¹ y := by
rw [← left_cancel (x ◃ x)]
rw [right_inv]
rw [self_act_act_eq]
rw [right_inv]
@[simp]
theorem self_invAct_act_eq {x y : R} : (x ◃⁻¹ x) ◃ y = x ◃ y := by
have h := @self_act_invAct_eq _ _ (op x) (op y)
simpa using h
theorem self_act_eq_iff_eq {x y : R} : x ◃ x = y ◃ y ↔ x = y := by
constructor; swap
· rintro rfl; rfl
intro h
trans (x ◃ x) ◃⁻¹ x ◃ x
· rw [← left_cancel (x ◃ x), right_inv, self_act_act_eq]
· rw [h, ← left_cancel (y ◃ y), right_inv, self_act_act_eq]
theorem self_invAct_eq_iff_eq {x y : R} : x ◃⁻¹ x = y ◃⁻¹ y ↔ x = y := by
have h := @self_act_eq_iff_eq _ _ (op x) (op y)
simpa using h
/-- The map `x ↦ x ◃ x` is a bijection. (This has applications for the
regular isotopy version of the Reidemeister I move for knot diagrams.)
-/
def selfApplyEquiv (R : Type*) [Rack R] : R ≃ R where
toFun x := x ◃ x
invFun x := x ◃⁻¹ x
left_inv x := by simp
right_inv x := by simp
/-- An involutory rack is one for which `Rack.oppositeRack R x` is an involution for every x.
-/
def IsInvolutory (R : Type*) [Rack R] : Prop :=
∀ x : R, Function.Involutive (Shelf.act x)
theorem involutory_invAct_eq_act {R : Type*} [Rack R] (h : IsInvolutory R) (x y : R) :
x ◃⁻¹ y = x ◃ y := by
rw [← left_cancel x, right_inv, h x]
/-- An abelian rack is one for which the mediality axiom holds.
-/
def IsAbelian (R : Type*) [Rack R] : Prop :=
∀ x y z w : R, (x ◃ y) ◃ z ◃ w = (x ◃ z) ◃ y ◃ w
/-- Associative racks are uninteresting.
-/
theorem assoc_iff_id {R : Type*} [Rack R] {x y z : R} : x ◃ y ◃ z = (x ◃ y) ◃ z ↔ x ◃ z = z := by
rw [self_distrib]
rw [left_cancel]
end Rack
namespace ShelfHom
variable {S₁ : Type*} {S₂ : Type*} {S₃ : Type*} [Shelf S₁] [Shelf S₂] [Shelf S₃]
instance : FunLike (S₁ →◃ S₂) S₁ S₂ where
coe := toFun
coe_injective' | ⟨_, _⟩, ⟨_, _⟩, rfl => rfl
@[simp] theorem toFun_eq_coe (f : S₁ →◃ S₂) : f.toFun = f := rfl
@[simp]
theorem map_act (f : S₁ →◃ S₂) {x y : S₁} : f (x ◃ y) = f x ◃ f y :=
map_act' f
/-- The identity homomorphism -/
def id (S : Type*) [Shelf S] : S →◃ S where
toFun := fun x => x
map_act' := by simp
instance inhabited (S : Type*) [Shelf S] : Inhabited (S →◃ S) :=
⟨id S⟩
/-- The composition of shelf homomorphisms -/
def comp (g : S₂ →◃ S₃) (f : S₁ →◃ S₂) : S₁ →◃ S₃ where
toFun := g.toFun ∘ f.toFun
map_act' := by simp
@[simp]
theorem comp_apply (g : S₂ →◃ S₃) (f : S₁ →◃ S₂) (x : S₁) : (g.comp f) x = g (f x) :=
rfl
end ShelfHom
/-- A quandle is a rack such that each automorphism fixes its corresponding element.
-/
class Quandle (α : Type*) extends Rack α where
/-- The fixing property of a Quandle -/
fix : ∀ {x : α}, act x x = x
namespace Quandle
open Rack
variable {Q : Type*} [Quandle Q]
attribute [simp] fix
@[simp]
theorem fix_inv {x : Q} : x ◃⁻¹ x = x := by
rw [← left_cancel x]
simp
instance oppositeQuandle : Quandle Qᵐᵒᵖ where
fix := by
intro x
induction x
simp
/-- The conjugation quandle of a group. Each element of the group acts by
the corresponding inner automorphism. -/
abbrev Conj (G : Type*) := G
instance Conj.quandle (G : Type*) [Group G] : Quandle (Conj G) where
act x := @MulAut.conj G _ x
self_distrib := by
intro x y z
dsimp only [MulAut.conj_apply]
simp [mul_assoc]
invAct x := (@MulAut.conj G _ x).symm
left_inv x y := by
simp [mul_assoc]
right_inv x y := by
simp [mul_assoc]
fix := by simp
@[simp]
theorem conj_act_eq_conj {G : Type*} [Group G] (x y : Conj G) :
x ◃ y = ((x : G) * (y : G) * (x : G)⁻¹ : G) :=
rfl
theorem conj_swap {G : Type*} [Group G] (x y : Conj G) : x ◃ y = y ↔ y ◃ x = x := by
dsimp [Conj] at *; constructor
repeat' intro h; conv_rhs => rw [eq_mul_inv_of_mul_eq (eq_mul_inv_of_mul_eq h)]; simp
/-- `Conj` is functorial
-/
def Conj.map {G : Type*} {H : Type*} [Group G] [Group H] (f : G →* H) : Conj G →◃ Conj H where
toFun := f
map_act' := by simp
/-- The dihedral quandle. This is the conjugation quandle of the dihedral group restricted to flips.
Used for Fox n-colorings of knots. -/
def Dihedral (n : ℕ) :=
ZMod n
/-- The operation for the dihedral quandle. It does not need to be an equivalence
because it is an involution (see `dihedralAct.inv`). -/
def dihedralAct (n : ℕ) (a : ZMod n) : ZMod n → ZMod n := fun b => 2 * a - b
theorem dihedralAct.inv (n : ℕ) (a : ZMod n) : Function.Involutive (dihedralAct n a) := by
intro b
dsimp only [dihedralAct]
simp
instance (n : ℕ) : Quandle (Dihedral n) where
act := dihedralAct n
self_distrib := by
intro x y z
simp only [dihedralAct]
ring_nf
invAct := dihedralAct n
left_inv x := (dihedralAct.inv n x).leftInverse
right_inv x := (dihedralAct.inv n x).rightInverse
fix := by
intro x
simp only [dihedralAct]
ring_nf
end Quandle
namespace Rack
/-- This is the natural rack homomorphism to the conjugation quandle of the group `R ≃ R`
that acts on the rack. -/
def toConj (R : Type*) [Rack R] : R →◃ Quandle.Conj (R ≃ R) where
toFun := act'
map_act' := by
intro x y
exact ad_conj x y
section EnvelGroup
/-!
### Universal enveloping group of a rack
The universal enveloping group `EnvelGroup R` of a rack `R` is the
universal group such that every rack homomorphism `R →◃ conj G` is
induced by a unique group homomorphism `EnvelGroup R →* G`.
For quandles, Joyce called this group `AdConj R`.
The `EnvelGroup` functor is left adjoint to the `Conj` forgetful
functor, and the way we construct the enveloping group is via a
technique that should work for left adjoints of forgetful functors in
general. It involves thinking a little about 2-categories, but the
payoff is that the map `EnvelGroup R →* G` has a nice description.
Let's think of a group as being a one-object category. The first step
is to define `PreEnvelGroup`, which gives formal expressions for all
the 1-morphisms and includes the unit element, elements of `R`,
multiplication, and inverses. To introduce relations, the second step
is to define `PreEnvelGroupRel'`, which gives formal expressions
for all 2-morphisms between the 1-morphisms. The 2-morphisms include
associativity, multiplication by the unit, multiplication by inverses,
compatibility with multiplication and inverses (`congr_mul` and
`congr_inv`), the axioms for an equivalence relation, and,
importantly, the relationship between conjugation and the rack action
(see `Rack.ad_conj`).
None of this forms a 2-category yet, for example due to lack of
associativity of `trans`. The `PreEnvelGroupRel` relation is a
`Prop`-valued version of `PreEnvelGroupRel'`, and making it
`Prop`-valued essentially introduces enough 3-isomorphisms so that
every pair of compatible 2-morphisms is isomorphic. Now, while
composition in `PreEnvelGroup` does not strictly satisfy the category
axioms, `PreEnvelGroup` and `PreEnvelGroupRel'` do form a weak
2-category.
Since we just want a 1-category, the last step is to quotient
`PreEnvelGroup` by `PreEnvelGroupRel'`, and the result is the
group `EnvelGroup`.
For a homomorphism `f : R →◃ Conj G`, how does
`EnvelGroup.map f : EnvelGroup R →* G` work? Let's think of `G` as
being a 2-category with one object, a 1-morphism per element of `G`,
and a single 2-morphism called `Eq.refl` for each 1-morphism. We
define the map using a "higher `Quotient.lift`" -- not only do we
evaluate elements of `PreEnvelGroup` as expressions in `G` (this is
`toEnvelGroup.mapAux`), but we evaluate elements of
`PreEnvelGroup'` as expressions of 2-morphisms of `G` (this is
`toEnvelGroup.mapAux.well_def`). That is to say,
`toEnvelGroup.mapAux.well_def` recursively evaluates formal
expressions of 2-morphisms as equality proofs in `G`. Now that all
morphisms are accounted for, the map descends to a homomorphism
`EnvelGroup R →* G`.
Note: `Type`-valued relations are not common. The fact it is
`Type`-valued is what makes `toEnvelGroup.mapAux.well_def` have
well-founded recursion.
-/
/-- Free generators of the enveloping group.
-/
inductive PreEnvelGroup (R : Type u) : Type u
| unit : PreEnvelGroup R
| incl (x : R) : PreEnvelGroup R
| mul (a b : PreEnvelGroup R) : PreEnvelGroup R
| inv (a : PreEnvelGroup R) : PreEnvelGroup R
instance PreEnvelGroup.inhabited (R : Type u) : Inhabited (PreEnvelGroup R) :=
⟨PreEnvelGroup.unit⟩
open PreEnvelGroup
/-- Relations for the enveloping group. This is a type-valued relation because
`toEnvelGroup.mapAux.well_def` inducts on it to show `toEnvelGroup.map`
is well-defined. The relation `PreEnvelGroupRel` is the `Prop`-valued version,
which is used to define `EnvelGroup` itself.
-/
inductive PreEnvelGroupRel' (R : Type u) [Rack R] : PreEnvelGroup R → PreEnvelGroup R → Type u
| refl {a : PreEnvelGroup R} : PreEnvelGroupRel' R a a
| symm {a b : PreEnvelGroup R} (hab : PreEnvelGroupRel' R a b) : PreEnvelGroupRel' R b a
| trans {a b c : PreEnvelGroup R} (hab : PreEnvelGroupRel' R a b)
(hbc : PreEnvelGroupRel' R b c) : PreEnvelGroupRel' R a c
| congr_mul {a b a' b' : PreEnvelGroup R} (ha : PreEnvelGroupRel' R a a')
(hb : PreEnvelGroupRel' R b b') : PreEnvelGroupRel' R (mul a b) (mul a' b')
| congr_inv {a a' : PreEnvelGroup R} (ha : PreEnvelGroupRel' R a a') :
PreEnvelGroupRel' R (inv a) (inv a')
| assoc (a b c : PreEnvelGroup R) : PreEnvelGroupRel' R (mul (mul a b) c) (mul a (mul b c))
| one_mul (a : PreEnvelGroup R) : PreEnvelGroupRel' R (mul unit a) a
| mul_one (a : PreEnvelGroup R) : PreEnvelGroupRel' R (mul a unit) a
| inv_mul_cancel (a : PreEnvelGroup R) : PreEnvelGroupRel' R (mul (inv a) a) unit
| act_incl (x y : R) :
PreEnvelGroupRel' R (mul (mul (incl x) (incl y)) (inv (incl x))) (incl (x ◃ y))
instance PreEnvelGroupRel'.inhabited (R : Type u) [Rack R] :
Inhabited (PreEnvelGroupRel' R unit unit) :=
⟨PreEnvelGroupRel'.refl⟩
/--
The `PreEnvelGroupRel` relation as a `Prop`. Used as the relation for `PreEnvelGroup.setoid`.
-/
inductive PreEnvelGroupRel (R : Type u) [Rack R] : PreEnvelGroup R → PreEnvelGroup R → Prop
| rel {a b : PreEnvelGroup R} (r : PreEnvelGroupRel' R a b) : PreEnvelGroupRel R a b
/-- A quick way to convert a `PreEnvelGroupRel'` to a `PreEnvelGroupRel`.
-/
theorem PreEnvelGroupRel'.rel {R : Type u} [Rack R] {a b : PreEnvelGroup R} :
PreEnvelGroupRel' R a b → PreEnvelGroupRel R a b := PreEnvelGroupRel.rel
@[refl]
theorem PreEnvelGroupRel.refl {R : Type u} [Rack R] {a : PreEnvelGroup R} :
PreEnvelGroupRel R a a :=
PreEnvelGroupRel.rel PreEnvelGroupRel'.refl
@[symm]
theorem PreEnvelGroupRel.symm {R : Type u} [Rack R] {a b : PreEnvelGroup R} :
PreEnvelGroupRel R a b → PreEnvelGroupRel R b a
| ⟨r⟩ => r.symm.rel
@[trans]
theorem PreEnvelGroupRel.trans {R : Type u} [Rack R] {a b c : PreEnvelGroup R} :
PreEnvelGroupRel R a b → PreEnvelGroupRel R b c → PreEnvelGroupRel R a c
| ⟨rab⟩, ⟨rbc⟩ => (rab.trans rbc).rel
instance PreEnvelGroup.setoid (R : Type*) [Rack R] : Setoid (PreEnvelGroup R) where
r := PreEnvelGroupRel R
iseqv := by
constructor
· apply PreEnvelGroupRel.refl
· apply PreEnvelGroupRel.symm
· apply PreEnvelGroupRel.trans
/-- The universal enveloping group for the rack R.
-/
def EnvelGroup (R : Type*) [Rack R] :=
Quotient (PreEnvelGroup.setoid R)
-- Define the `Group` instances in two steps so `inv` can be inferred correctly.
-- TODO: is there a non-invasive way of defining the instance directly?
instance (R : Type*) [Rack R] : DivInvMonoid (EnvelGroup R) where
mul a b :=
Quotient.liftOn₂ a b (fun a b => ⟦PreEnvelGroup.mul a b⟧) fun _ _ _ _ ⟨ha⟩ ⟨hb⟩ =>
Quotient.sound (PreEnvelGroupRel'.congr_mul ha hb).rel
one := ⟦unit⟧
inv a :=
Quotient.liftOn a (fun a => ⟦PreEnvelGroup.inv a⟧) fun _ _ ⟨ha⟩ =>
Quotient.sound (PreEnvelGroupRel'.congr_inv ha).rel
mul_assoc a b c :=
Quotient.inductionOn₃ a b c fun a b c => Quotient.sound (PreEnvelGroupRel'.assoc a b c).rel
one_mul a := Quotient.inductionOn a fun a => Quotient.sound (PreEnvelGroupRel'.one_mul a).rel
mul_one a := Quotient.inductionOn a fun a => Quotient.sound (PreEnvelGroupRel'.mul_one a).rel
instance (R : Type*) [Rack R] : Group (EnvelGroup R) :=
{ inv_mul_cancel := fun a =>
Quotient.inductionOn a fun a => Quotient.sound (PreEnvelGroupRel'.inv_mul_cancel a).rel }
instance EnvelGroup.inhabited (R : Type*) [Rack R] : Inhabited (EnvelGroup R) :=
⟨1⟩
/-- The canonical homomorphism from a rack to its enveloping group.
Satisfies universal properties given by `toEnvelGroup.map` and `toEnvelGroup.univ`.
-/
def toEnvelGroup (R : Type*) [Rack R] : R →◃ Quandle.Conj (EnvelGroup R) where
toFun x := ⟦incl x⟧
map_act' := @fun x y => Quotient.sound (PreEnvelGroupRel'.act_incl x y).symm.rel
/-- The preliminary definition of the induced map from the enveloping group.
See `toEnvelGroup.map`.
-/
def toEnvelGroup.mapAux {R : Type*} [Rack R] {G : Type*} [Group G] (f : R →◃ Quandle.Conj G) :
PreEnvelGroup R → G
| .unit => 1
| .incl x => f x
| .mul a b => toEnvelGroup.mapAux f a * toEnvelGroup.mapAux f b
| .inv a => (toEnvelGroup.mapAux f a)⁻¹
namespace toEnvelGroup.mapAux
open PreEnvelGroupRel'
/-- Show that `toEnvelGroup.mapAux` sends equivalent expressions to equal terms.
-/
theorem well_def {R : Type*} [Rack R] {G : Type*} [Group G] (f : R →◃ Quandle.Conj G) :
∀ {a b : PreEnvelGroup R},
PreEnvelGroupRel' R a b → toEnvelGroup.mapAux f a = toEnvelGroup.mapAux f b
| _, _, PreEnvelGroupRel'.refl => rfl
| _, _, PreEnvelGroupRel'.symm h => (well_def f h).symm
| _, _, PreEnvelGroupRel'.trans hac hcb => Eq.trans (well_def f hac) (well_def f hcb)
| _, _, PreEnvelGroupRel'.congr_mul ha hb => by
simp [toEnvelGroup.mapAux, well_def f ha, well_def f hb]
| _, _, congr_inv ha => by simp [toEnvelGroup.mapAux, well_def f ha]
| _, _, assoc a b c => by apply mul_assoc
| _, _, PreEnvelGroupRel'.one_mul a => by simp [toEnvelGroup.mapAux]
| _, _, PreEnvelGroupRel'.mul_one a => by simp [toEnvelGroup.mapAux]
| _, _, PreEnvelGroupRel'.inv_mul_cancel a => by simp [toEnvelGroup.mapAux]
| _, _, act_incl x y => by simp [toEnvelGroup.mapAux]
end toEnvelGroup.mapAux
/-- Given a map from a rack to a group, lift it to being a map from the enveloping group.
More precisely, the `EnvelGroup` functor is left adjoint to `Quandle.Conj`.
-/
def toEnvelGroup.map {R : Type*} [Rack R] {G : Type*} [Group G] :
(R →◃ Quandle.Conj G) ≃ (EnvelGroup R →* G) where
toFun f :=
{ toFun := fun x =>
Quotient.liftOn x (toEnvelGroup.mapAux f) fun _ _ ⟨hab⟩ =>
toEnvelGroup.mapAux.well_def f hab
map_one' := by
change Quotient.liftOn ⟦Rack.PreEnvelGroup.unit⟧ (toEnvelGroup.mapAux f) _ = 1
simp only [Quotient.lift_mk, mapAux]
map_mul' := fun x y =>
Quotient.inductionOn₂ x y fun x y => by
change Quotient.liftOn ⟦mul x y⟧ (toEnvelGroup.mapAux f) _ = _
simp [toEnvelGroup.mapAux] }
invFun F := (Quandle.Conj.map F).comp (toEnvelGroup R)
right_inv F :=
MonoidHom.ext fun x =>
Quotient.inductionOn x fun x => by
induction x with
| unit => exact F.map_one.symm
| incl => rfl
| mul x y ih_x ih_y =>
have hm : ⟦x.mul y⟧ = @Mul.mul (EnvelGroup R) _ ⟦x⟧ ⟦y⟧ := rfl
simp only [MonoidHom.coe_mk, OneHom.coe_mk, Quotient.lift_mk]
suffices ∀ x y, F (Mul.mul x y) = F (x) * F (y) by
simp_all only [MonoidHom.coe_mk, OneHom.coe_mk, Quotient.lift_mk]
rw [← ih_x, ← ih_y, mapAux]
exact F.map_mul
| inv x ih_x =>
have hm : ⟦x.inv⟧ = @Inv.inv (EnvelGroup R) _ ⟦x⟧ := rfl
rw [hm, F.map_inv, MonoidHom.map_inv, ih_x]
/-- Given a homomorphism from a rack to a group, it factors through the enveloping group.
-/
theorem toEnvelGroup.univ (R : Type*) [Rack R] (G : Type*) [Group G] (f : R →◃ Quandle.Conj G) :
(Quandle.Conj.map (toEnvelGroup.map f)).comp (toEnvelGroup R) = f :=
toEnvelGroup.map.symm_apply_apply f
/-- The homomorphism `toEnvelGroup.map f` is the unique map that fits into the commutative
triangle in `toEnvelGroup.univ`.
-/
theorem toEnvelGroup.univ_uniq (R : Type*) [Rack R] (G : Type*) [Group G]
(f : R →◃ Quandle.Conj G) (g : EnvelGroup R →* G)
(h : f = (Quandle.Conj.map g).comp (toEnvelGroup R)) : g = toEnvelGroup.map f :=
h.symm ▸ (toEnvelGroup.map.apply_symm_apply g).symm
/-- The induced group homomorphism from the enveloping group into bijections of the rack,
using `Rack.toConj`. Satisfies the property `envelAction_prop`.
This gives the rack `R` the structure of an augmented rack over `EnvelGroup R`.
-/
def envelAction {R : Type*} [Rack R] : EnvelGroup R →* R ≃ R :=
toEnvelGroup.map (toConj R)
@[simp]
theorem envelAction_prop {R : Type*} [Rack R] (x y : R) :
envelAction (toEnvelGroup R x) y = x ◃ y :=
rfl
end EnvelGroup
end Rack |
.lake/packages/mathlib/Mathlib/Algebra/Expr.lean | import Mathlib.Init
import Qq
/-! # Helpers to invoke functions involving algebra at tactic time
This file provides instances on `x y : Q($α)` such that `x + y = q($x + $y)`.
-/
open Qq
/-- Produce a `One` instance for `Q($α)` such that `1 : Q($α)` is `q(1 : $α)`. -/
def Expr.instOne {u : Lean.Level} (α : Q(Type u)) (_ : Q(One $α)) : One Q($α) where
one := q(1 : $α)
/-- Produce a `Zero` instance for `Q($α)` such that `0 : Q($α)` is `q(0 : $α)`. -/
def Expr.instZero {u : Lean.Level} (α : Q(Type u)) (_ : Q(Zero $α)) : Zero Q($α) where
zero := q(0 : $α)
/-- Produce a `Mul` instance for `Q($α)` such that `x * y : Q($α)` is `q($x * $y)`. -/
def Expr.instMul {u : Lean.Level} (α : Q(Type u)) (_ : Q(Mul $α)) : Mul Q($α) where
mul x y := q($x * $y)
/-- Produce an `Add` instance for `Q($α)` such that `x + y : Q($α)` is `q($x + $y)`. -/
def Expr.instAdd {u : Lean.Level} (α : Q(Type u)) (_ : Q(Add $α)) : Add Q($α) where
add x y := q($x + $y) |
.lake/packages/mathlib/Mathlib/Algebra/NeZero.lean | import Mathlib.Logic.Basic
import Mathlib.Order.Defs.PartialOrder
/-!
# `NeZero` typeclass
We give basic facts about the `NeZero n` typeclass.
-/
variable {R : Type*} [Zero R]
theorem not_neZero {n : R} : ¬NeZero n ↔ n = 0 := by simp [neZero_iff]
theorem eq_zero_or_neZero (a : R) : a = 0 ∨ NeZero a :=
(eq_or_ne a 0).imp_right NeZero.mk
section
variable {α : Type*} [Zero α]
@[simp] lemma zero_ne_one [One α] [NeZero (1 : α)] : (0 : α) ≠ 1 := NeZero.ne' (1 : α)
@[simp] lemma one_ne_zero [One α] [NeZero (1 : α)] : (1 : α) ≠ 0 := NeZero.ne (1 : α)
lemma ne_zero_of_eq_one [One α] [NeZero (1 : α)] {a : α} (h : a = 1) : a ≠ 0 := h ▸ one_ne_zero
lemma two_ne_zero [OfNat α 2] [NeZero (2 : α)] : (2 : α) ≠ 0 := NeZero.ne (2 : α)
lemma three_ne_zero [OfNat α 3] [NeZero (3 : α)] : (3 : α) ≠ 0 := NeZero.ne (3 : α)
lemma four_ne_zero [OfNat α 4] [NeZero (4 : α)] : (4 : α) ≠ 0 := NeZero.ne (4 : α)
variable (α)
lemma zero_ne_one' [One α] [NeZero (1 : α)] : (0 : α) ≠ 1 := zero_ne_one
lemma one_ne_zero' [One α] [NeZero (1 : α)] : (1 : α) ≠ 0 := one_ne_zero
lemma two_ne_zero' [OfNat α 2] [NeZero (2 : α)] : (2 : α) ≠ 0 := two_ne_zero
lemma three_ne_zero' [OfNat α 3] [NeZero (3 : α)] : (3 : α) ≠ 0 := three_ne_zero
lemma four_ne_zero' [OfNat α 4] [NeZero (4 : α)] : (4 : α) ≠ 0 := four_ne_zero
end
namespace NeZero
variable {M : Type*} {x : M}
theorem of_pos [Preorder M] [Zero M] (h : 0 < x) : NeZero x := ⟨ne_of_gt h⟩
end NeZero |
.lake/packages/mathlib/Mathlib/Algebra/TrivSqZeroExt.lean | import Mathlib.Algebra.BigOperators.GroupWithZero.Action
import Mathlib.Algebra.GroupWithZero.Invertible
import Mathlib.LinearAlgebra.Prod
import Mathlib.Algebra.Algebra.Subalgebra.Lattice
/-!
# Trivial Square-Zero Extension
Given a ring `R` together with an `(R, R)`-bimodule `M`, the trivial square-zero extension of `M`
over `R` is defined to be the `R`-algebra `R ⊕ M` with multiplication given by
`(r₁ + m₁) * (r₂ + m₂) = r₁ r₂ + r₁ m₂ + m₁ r₂`.
It is a square-zero extension because `M^2 = 0`.
Note that expressing this requires bimodules; we write these in general for a
not-necessarily-commutative `R` as:
```lean
variable {R M : Type*} [Semiring R] [AddCommMonoid M]
variable [Module R M] [Module Rᵐᵒᵖ M] [SMulCommClass R Rᵐᵒᵖ M]
```
If we instead work with a commutative `R'` acting symmetrically on `M`, we write
```lean
variable {R' M : Type*} [CommSemiring R'] [AddCommMonoid M]
variable [Module R' M] [Module R'ᵐᵒᵖ M] [IsCentralScalar R' M]
```
noting that in this context `IsCentralScalar R' M` implies `SMulCommClass R' R'ᵐᵒᵖ M`.
Many of the later results in this file are only stated for the commutative `R'` for simplicity.
## Main definitions
* `TrivSqZeroExt.inl`, `TrivSqZeroExt.inr`: the canonical inclusions into
`TrivSqZeroExt R M`.
* `TrivSqZeroExt.fst`, `TrivSqZeroExt.snd`: the canonical projections from
`TrivSqZeroExt R M`.
* `triv_sq_zero_ext.algebra`: the associated `R`-algebra structure.
* `TrivSqZeroExt.lift`: the universal property of the trivial square-zero extension; algebra
morphisms `TrivSqZeroExt R M →ₐ[S] A` are uniquely defined by an algebra morphism `f : R →ₐ[S] A`
on `R` and a linear map `g : M →ₗ[S] A` on `M` such that:
* `g x * g y = 0`: the elements of `M` continue to square to zero.
* `g (r •> x) = f r * g x` and `g (x <• r) = g x * f r`: left and right actions are preserved by
`g`.
* `TrivSqZeroExt.lift`: the universal property of the trivial square-zero extension; algebra
morphisms `TrivSqZeroExt R M →ₐ[R] A` are uniquely defined by linear maps `M →ₗ[R] A` for
which the product of any two elements in the range is zero.
-/
universe u v w
/-- "Trivial Square-Zero Extension".
Given a module `M` over a ring `R`, the trivial square-zero extension of `M` over `R` is defined
to be the `R`-algebra `R × M` with multiplication given by
`(r₁ + m₁) * (r₂ + m₂) = r₁ r₂ + r₁ m₂ + r₂ m₁`.
It is a square-zero extension because `M^2 = 0`.
-/
def TrivSqZeroExt (R : Type u) (M : Type v) :=
R × M
local notation "tsze" => TrivSqZeroExt
open scoped RightActions
namespace TrivSqZeroExt
open MulOpposite
section Basic
variable {R : Type u} {M : Type v}
/-- The canonical inclusion `R → TrivSqZeroExt R M`. -/
def inl [Zero M] (r : R) : tsze R M :=
(r, 0)
/-- The canonical inclusion `M → TrivSqZeroExt R M`. -/
def inr [Zero R] (m : M) : tsze R M :=
(0, m)
/-- The canonical projection `TrivSqZeroExt R M → R`. -/
def fst (x : tsze R M) : R :=
x.1
/-- The canonical projection `TrivSqZeroExt R M → M`. -/
def snd (x : tsze R M) : M :=
x.2
@[simp]
theorem fst_mk (r : R) (m : M) : fst (r, m) = r :=
rfl
@[simp]
theorem snd_mk (r : R) (m : M) : snd (r, m) = m :=
rfl
@[ext]
theorem ext {x y : tsze R M} (h1 : x.fst = y.fst) (h2 : x.snd = y.snd) : x = y :=
Prod.ext h1 h2
section
variable (M)
@[simp]
theorem fst_inl [Zero M] (r : R) : (inl r : tsze R M).fst = r :=
rfl
@[simp]
theorem snd_inl [Zero M] (r : R) : (inl r : tsze R M).snd = 0 :=
rfl
@[simp]
theorem fst_comp_inl [Zero M] : fst ∘ (inl : R → tsze R M) = id :=
rfl
@[simp]
theorem snd_comp_inl [Zero M] : snd ∘ (inl : R → tsze R M) = 0 :=
rfl
end
section
variable (R)
@[simp]
theorem fst_inr [Zero R] (m : M) : (inr m : tsze R M).fst = 0 :=
rfl
@[simp]
theorem snd_inr [Zero R] (m : M) : (inr m : tsze R M).snd = m :=
rfl
@[simp]
theorem fst_comp_inr [Zero R] : fst ∘ (inr : M → tsze R M) = 0 :=
rfl
@[simp]
theorem snd_comp_inr [Zero R] : snd ∘ (inr : M → tsze R M) = id :=
rfl
end
theorem fst_surjective [Nonempty M] : Function.Surjective (fst : tsze R M → R) :=
Prod.fst_surjective
theorem snd_surjective [Nonempty R] : Function.Surjective (snd : tsze R M → M) :=
Prod.snd_surjective
theorem inl_injective [Zero M] : Function.Injective (inl : R → tsze R M) :=
Function.LeftInverse.injective <| fst_inl _
theorem inr_injective [Zero R] : Function.Injective (inr : M → tsze R M) :=
Function.LeftInverse.injective <| snd_inr _
end Basic
/-! ### Structures inherited from `Prod`
Additive operators and scalar multiplication operate elementwise. -/
section Additive
variable {T : Type*} {S : Type*} {R : Type u} {M : Type v}
instance inhabited [Inhabited R] [Inhabited M] : Inhabited (tsze R M) :=
instInhabitedProd
instance zero [Zero R] [Zero M] : Zero (tsze R M) :=
Prod.instZero
instance add [Add R] [Add M] : Add (tsze R M) :=
Prod.instAdd
instance sub [Sub R] [Sub M] : Sub (tsze R M) :=
Prod.instSub
instance neg [Neg R] [Neg M] : Neg (tsze R M) :=
Prod.instNeg
instance addSemigroup [AddSemigroup R] [AddSemigroup M] : AddSemigroup (tsze R M) :=
Prod.instAddSemigroup
instance addZeroClass [AddZeroClass R] [AddZeroClass M] : AddZeroClass (tsze R M) :=
Prod.instAddZeroClass
instance addMonoid [AddMonoid R] [AddMonoid M] : AddMonoid (tsze R M) :=
Prod.instAddMonoid
instance addGroup [AddGroup R] [AddGroup M] : AddGroup (tsze R M) :=
Prod.instAddGroup
instance addCommSemigroup [AddCommSemigroup R] [AddCommSemigroup M] : AddCommSemigroup (tsze R M) :=
Prod.instAddCommSemigroup
instance addCommMonoid [AddCommMonoid R] [AddCommMonoid M] : AddCommMonoid (tsze R M) :=
Prod.instAddCommMonoid
instance addCommGroup [AddCommGroup R] [AddCommGroup M] : AddCommGroup (tsze R M) :=
Prod.instAddCommGroup
instance smul [SMul S R] [SMul S M] : SMul S (tsze R M) :=
Prod.instSMul
instance isScalarTower [SMul T R] [SMul T M] [SMul S R] [SMul S M] [SMul T S]
[IsScalarTower T S R] [IsScalarTower T S M] : IsScalarTower T S (tsze R M) :=
Prod.isScalarTower
instance smulCommClass [SMul T R] [SMul T M] [SMul S R] [SMul S M]
[SMulCommClass T S R] [SMulCommClass T S M] : SMulCommClass T S (tsze R M) :=
Prod.smulCommClass
instance isCentralScalar [SMul S R] [SMul S M] [SMul Sᵐᵒᵖ R] [SMul Sᵐᵒᵖ M] [IsCentralScalar S R]
[IsCentralScalar S M] : IsCentralScalar S (tsze R M) :=
Prod.isCentralScalar
instance mulAction [Monoid S] [MulAction S R] [MulAction S M] : MulAction S (tsze R M) :=
Prod.mulAction
instance distribMulAction [Monoid S] [AddMonoid R] [AddMonoid M]
[DistribMulAction S R] [DistribMulAction S M] : DistribMulAction S (tsze R M) :=
Prod.distribMulAction
instance module [Semiring S] [AddCommMonoid R] [AddCommMonoid M] [Module S R] [Module S M] :
Module S (tsze R M) :=
Prod.instModule
/-- The trivial square-zero extension is nontrivial if it is over a nontrivial ring. -/
instance instNontrivial_of_left {R M : Type*} [Nontrivial R] [Nonempty M] :
Nontrivial (TrivSqZeroExt R M) :=
fst_surjective.nontrivial
/-- The trivial square-zero extension is nontrivial if it is over a nontrivial module. -/
instance instNontrivial_of_right {R M : Type*} [Nonempty R] [Nontrivial M] :
Nontrivial (TrivSqZeroExt R M) :=
snd_surjective.nontrivial
@[simp]
theorem fst_zero [Zero R] [Zero M] : (0 : tsze R M).fst = 0 :=
rfl
@[simp]
theorem snd_zero [Zero R] [Zero M] : (0 : tsze R M).snd = 0 :=
rfl
@[simp]
theorem fst_add [Add R] [Add M] (x₁ x₂ : tsze R M) : (x₁ + x₂).fst = x₁.fst + x₂.fst :=
rfl
@[simp]
theorem snd_add [Add R] [Add M] (x₁ x₂ : tsze R M) : (x₁ + x₂).snd = x₁.snd + x₂.snd :=
rfl
@[simp]
theorem fst_neg [Neg R] [Neg M] (x : tsze R M) : (-x).fst = -x.fst :=
rfl
@[simp]
theorem snd_neg [Neg R] [Neg M] (x : tsze R M) : (-x).snd = -x.snd :=
rfl
@[simp]
theorem fst_sub [Sub R] [Sub M] (x₁ x₂ : tsze R M) : (x₁ - x₂).fst = x₁.fst - x₂.fst :=
rfl
@[simp]
theorem snd_sub [Sub R] [Sub M] (x₁ x₂ : tsze R M) : (x₁ - x₂).snd = x₁.snd - x₂.snd :=
rfl
@[simp]
theorem fst_smul [SMul S R] [SMul S M] (s : S) (x : tsze R M) : (s • x).fst = s • x.fst :=
rfl
@[simp]
theorem snd_smul [SMul S R] [SMul S M] (s : S) (x : tsze R M) : (s • x).snd = s • x.snd :=
rfl
theorem fst_sum {ι} [AddCommMonoid R] [AddCommMonoid M] (s : Finset ι) (f : ι → tsze R M) :
(∑ i ∈ s, f i).fst = ∑ i ∈ s, (f i).fst :=
Prod.fst_sum
theorem snd_sum {ι} [AddCommMonoid R] [AddCommMonoid M] (s : Finset ι) (f : ι → tsze R M) :
(∑ i ∈ s, f i).snd = ∑ i ∈ s, (f i).snd :=
Prod.snd_sum
section
variable (M)
@[simp]
theorem inl_zero [Zero R] [Zero M] : (inl 0 : tsze R M) = 0 :=
rfl
@[simp]
theorem inl_add [Add R] [AddZeroClass M] (r₁ r₂ : R) :
(inl (r₁ + r₂) : tsze R M) = inl r₁ + inl r₂ :=
ext rfl (add_zero 0).symm
@[simp]
theorem inl_neg [Neg R] [NegZeroClass M] (r : R) : (inl (-r) : tsze R M) = -inl r :=
ext rfl neg_zero.symm
@[simp]
theorem inl_sub [Sub R] [SubNegZeroMonoid M] (r₁ r₂ : R) :
(inl (r₁ - r₂) : tsze R M) = inl r₁ - inl r₂ :=
ext rfl (sub_zero _).symm
@[simp]
theorem inl_smul [Monoid S] [AddMonoid M] [SMul S R] [DistribMulAction S M] (s : S) (r : R) :
(inl (s • r) : tsze R M) = s • inl r :=
ext rfl (smul_zero s).symm
theorem inl_sum {ι} [AddCommMonoid R] [AddCommMonoid M] (s : Finset ι) (f : ι → R) :
(inl (∑ i ∈ s, f i) : tsze R M) = ∑ i ∈ s, inl (f i) :=
map_sum (LinearMap.inl ℕ _ _) _ _
end
section
variable (R)
@[simp]
theorem inr_zero [Zero R] [Zero M] : (inr 0 : tsze R M) = 0 :=
rfl
@[simp]
theorem inr_add [AddZeroClass R] [Add M] (m₁ m₂ : M) :
(inr (m₁ + m₂) : tsze R M) = inr m₁ + inr m₂ :=
ext (add_zero 0).symm rfl
@[simp]
theorem inr_neg [NegZeroClass R] [Neg M] (m : M) : (inr (-m) : tsze R M) = -inr m :=
ext neg_zero.symm rfl
@[simp]
theorem inr_sub [SubNegZeroMonoid R] [Sub M] (m₁ m₂ : M) :
(inr (m₁ - m₂) : tsze R M) = inr m₁ - inr m₂ :=
ext (sub_zero _).symm rfl
@[simp]
theorem inr_smul [Zero R] [SMulZeroClass S R] [SMul S M] (r : S) (m : M) :
(inr (r • m) : tsze R M) = r • inr m :=
ext (smul_zero _).symm rfl
theorem inr_sum {ι} [AddCommMonoid R] [AddCommMonoid M] (s : Finset ι) (f : ι → M) :
(inr (∑ i ∈ s, f i) : tsze R M) = ∑ i ∈ s, inr (f i) :=
map_sum (LinearMap.inr ℕ _ _) _ _
end
theorem inl_fst_add_inr_snd_eq [AddZeroClass R] [AddZeroClass M] (x : tsze R M) :
inl x.fst + inr x.snd = x :=
ext (add_zero x.1) (zero_add x.2)
/-- To show a property hold on all `TrivSqZeroExt R M` it suffices to show it holds
on terms of the form `inl r + inr m`. -/
@[elab_as_elim, induction_eliminator, cases_eliminator]
theorem ind {R M} [AddZeroClass R] [AddZeroClass M] {P : TrivSqZeroExt R M → Prop}
(inl_add_inr : ∀ r m, P (inl r + inr m)) (x) : P x :=
inl_fst_add_inr_snd_eq x ▸ inl_add_inr x.1 x.2
/-- This cannot be marked `@[ext]` as it ends up being used instead of `LinearMap.prod_ext` when
working with `R × M`. -/
theorem linearMap_ext {N} [Semiring S] [AddCommMonoid R] [AddCommMonoid M] [AddCommMonoid N]
[Module S R] [Module S M] [Module S N] ⦃f g : tsze R M →ₗ[S] N⦄
(hl : ∀ r, f (inl r) = g (inl r)) (hr : ∀ m, f (inr m) = g (inr m)) : f = g :=
LinearMap.prod_ext (LinearMap.ext hl) (LinearMap.ext hr)
variable (R M)
/-- The canonical `R`-linear inclusion `M → TrivSqZeroExt R M`. -/
@[simps apply]
def inrHom [Semiring R] [AddCommMonoid M] [Module R M] : M →ₗ[R] tsze R M :=
{ LinearMap.inr R R M with toFun := inr }
/-- The canonical `R`-linear projection `TrivSqZeroExt R M → M`. -/
@[simps apply]
def sndHom [Semiring R] [AddCommMonoid M] [Module R M] : tsze R M →ₗ[R] M :=
{ LinearMap.snd _ _ _ with toFun := snd }
end Additive
/-! ### Multiplicative structure -/
section Mul
variable {R : Type u} {M : Type v}
instance one [One R] [Zero M] : One (tsze R M) :=
⟨(1, 0)⟩
instance mul [Mul R] [Add M] [SMul R M] [SMul Rᵐᵒᵖ M] : Mul (tsze R M) :=
⟨fun x y => (x.1 * y.1, x.1 •> y.2 + x.2 <• y.1)⟩
@[simp]
theorem fst_one [One R] [Zero M] : (1 : tsze R M).fst = 1 :=
rfl
@[simp]
theorem snd_one [One R] [Zero M] : (1 : tsze R M).snd = 0 :=
rfl
@[simp]
theorem fst_mul [Mul R] [Add M] [SMul R M] [SMul Rᵐᵒᵖ M] (x₁ x₂ : tsze R M) :
(x₁ * x₂).fst = x₁.fst * x₂.fst :=
rfl
@[simp]
theorem snd_mul [Mul R] [Add M] [SMul R M] [SMul Rᵐᵒᵖ M] (x₁ x₂ : tsze R M) :
(x₁ * x₂).snd = x₁.fst •> x₂.snd + x₁.snd <• x₂.fst :=
rfl
section
variable (M)
@[simp]
theorem inl_one [One R] [Zero M] : (inl 1 : tsze R M) = 1 :=
rfl
@[simp]
theorem inl_mul [Monoid R] [AddMonoid M] [DistribMulAction R M] [DistribMulAction Rᵐᵒᵖ M]
(r₁ r₂ : R) : (inl (r₁ * r₂) : tsze R M) = inl r₁ * inl r₂ :=
ext rfl <| show (0 : M) = r₁ •> (0 : M) + (0 : M) <• r₂ by rw [smul_zero, zero_add, smul_zero]
theorem inl_mul_inl [Monoid R] [AddMonoid M] [DistribMulAction R M] [DistribMulAction Rᵐᵒᵖ M]
(r₁ r₂ : R) : (inl r₁ * inl r₂ : tsze R M) = inl (r₁ * r₂) :=
(inl_mul M r₁ r₂).symm
end
section
variable (R)
@[simp]
theorem inr_mul_inr [Semiring R] [AddCommMonoid M] [Module R M] [Module Rᵐᵒᵖ M] (m₁ m₂ : M) :
(inr m₁ * inr m₂ : tsze R M) = 0 :=
ext (mul_zero _) <|
show (0 : R) •> m₂ + m₁ <• (0 : R) = 0 by rw [zero_smul, zero_add, op_zero, zero_smul]
end
theorem inl_mul_inr [MonoidWithZero R] [AddMonoid M] [DistribMulAction R M]
[DistribMulAction Rᵐᵒᵖ M] (r : R) (m : M) : (inl r * inr m : tsze R M) = inr (r • m) :=
ext (mul_zero r) <|
show r • m + (0 : Rᵐᵒᵖ) • (0 : M) = r • m by rw [smul_zero, add_zero]
theorem inr_mul_inl [MonoidWithZero R] [AddMonoid M] [DistribMulAction R M]
[DistribMulAction Rᵐᵒᵖ M] (r : R) (m : M) : (inr m * inl r : tsze R M) = inr (m <• r) :=
ext (zero_mul r) <|
show (0 : R) •> (0 : M) + m <• r = m <• r by rw [smul_zero, zero_add]
theorem inl_mul_eq_smul [Monoid R] [AddMonoid M] [DistribMulAction R M] [DistribMulAction Rᵐᵒᵖ M]
(r : R) (x : tsze R M) :
inl r * x = r •> x :=
ext rfl (by dsimp; rw [smul_zero, add_zero])
theorem mul_inl_eq_op_smul [Monoid R] [AddMonoid M] [DistribMulAction R M] [DistribMulAction Rᵐᵒᵖ M]
(x : tsze R M) (r : R) :
x * inl r = x <• r :=
ext rfl (by dsimp; rw [smul_zero, zero_add])
instance mulOneClass [Monoid R] [AddMonoid M] [DistribMulAction R M] [DistribMulAction Rᵐᵒᵖ M] :
MulOneClass (tsze R M) :=
{ TrivSqZeroExt.one, TrivSqZeroExt.mul with
one_mul := fun x =>
ext (one_mul x.1) <|
show (1 : R) •> x.2 + (0 : M) <• x.1 = x.2 by rw [one_smul, smul_zero, add_zero]
mul_one := fun x =>
ext (mul_one x.1) <|
show x.1 • (0 : M) + x.2 <• (1 : R) = x.2 by rw [smul_zero, zero_add, op_one, one_smul] }
instance addMonoidWithOne [AddMonoidWithOne R] [AddMonoid M] : AddMonoidWithOne (tsze R M) :=
{ TrivSqZeroExt.addMonoid, TrivSqZeroExt.one with
natCast := fun n => inl n
natCast_zero := by simp [Nat.cast]
natCast_succ := fun _ => by ext <;> simp [Nat.cast] }
@[simp]
theorem fst_natCast [AddMonoidWithOne R] [AddMonoid M] (n : ℕ) : (n : tsze R M).fst = n :=
rfl
@[simp]
theorem snd_natCast [AddMonoidWithOne R] [AddMonoid M] (n : ℕ) : (n : tsze R M).snd = 0 :=
rfl
@[simp]
theorem inl_natCast [AddMonoidWithOne R] [AddMonoid M] (n : ℕ) : (inl n : tsze R M) = n :=
rfl
instance addGroupWithOne [AddGroupWithOne R] [AddGroup M] : AddGroupWithOne (tsze R M) :=
{ TrivSqZeroExt.addGroup, TrivSqZeroExt.addMonoidWithOne with
intCast := fun z => inl z
intCast_ofNat := fun _n => ext (Int.cast_natCast _) rfl
intCast_negSucc := fun _n => ext (Int.cast_negSucc _) neg_zero.symm }
@[simp]
theorem fst_intCast [AddGroupWithOne R] [AddGroup M] (z : ℤ) : (z : tsze R M).fst = z :=
rfl
@[simp]
theorem snd_intCast [AddGroupWithOne R] [AddGroup M] (z : ℤ) : (z : tsze R M).snd = 0 :=
rfl
@[simp]
theorem inl_intCast [AddGroupWithOne R] [AddGroup M] (z : ℤ) : (inl z : tsze R M) = z :=
rfl
instance nonAssocSemiring [Semiring R] [AddCommMonoid M] [Module R M] [Module Rᵐᵒᵖ M] :
NonAssocSemiring (tsze R M) :=
{ TrivSqZeroExt.addMonoidWithOne, TrivSqZeroExt.mulOneClass, TrivSqZeroExt.addCommMonoid with
zero_mul := fun x =>
ext (zero_mul x.1) <|
show (0 : R) •> x.2 + (0 : M) <• x.1 = 0 by rw [zero_smul, zero_add, smul_zero]
mul_zero := fun x =>
ext (mul_zero x.1) <|
show x.1 • (0 : M) + (0 : Rᵐᵒᵖ) • x.2 = 0 by rw [smul_zero, zero_add, zero_smul]
left_distrib := fun x₁ x₂ x₃ =>
ext (mul_add x₁.1 x₂.1 x₃.1) <|
show
x₁.1 •> (x₂.2 + x₃.2) + x₁.2 <• (x₂.1 + x₃.1) =
x₁.1 •> x₂.2 + x₁.2 <• x₂.1 + (x₁.1 •> x₃.2 + x₁.2 <• x₃.1)
by simp_rw [smul_add, MulOpposite.op_add, add_smul, add_add_add_comm]
right_distrib := fun x₁ x₂ x₃ =>
ext (add_mul x₁.1 x₂.1 x₃.1) <|
show
(x₁.1 + x₂.1) •> x₃.2 + (x₁.2 + x₂.2) <• x₃.1 =
x₁.1 •> x₃.2 + x₁.2 <• x₃.1 + (x₂.1 •> x₃.2 + x₂.2 <• x₃.1)
by simp_rw [add_smul, smul_add, add_add_add_comm] }
instance nonAssocRing [Ring R] [AddCommGroup M] [Module R M] [Module Rᵐᵒᵖ M] :
NonAssocRing (tsze R M) :=
{ TrivSqZeroExt.addGroupWithOne, TrivSqZeroExt.nonAssocSemiring with }
/-- In the general non-commutative case, the power operator is
$$\begin{align}
(r + m)^n &= r^n + r^{n-1}m + r^{n-2}mr + \cdots + rmr^{n-2} + mr^{n-1} \\
& =r^n + \sum_{i = 0}^{n - 1} r^{(n - 1) - i} m r^{i}
\end{align}$$
In the commutative case this becomes the simpler $(r + m)^n = r^n + nr^{n-1}m$.
-/
instance [Monoid R] [AddMonoid M] [DistribMulAction R M] [DistribMulAction Rᵐᵒᵖ M] :
Pow (tsze R M) ℕ :=
⟨fun x n =>
⟨x.fst ^ n, ((List.range n).map fun i => x.fst ^ (n.pred - i) •> x.snd <• x.fst ^ i).sum⟩⟩
@[simp]
theorem fst_pow [Monoid R] [AddMonoid M] [DistribMulAction R M] [DistribMulAction Rᵐᵒᵖ M]
(x : tsze R M) (n : ℕ) : fst (x ^ n) = x.fst ^ n :=
rfl
theorem snd_pow_eq_sum [Monoid R] [AddMonoid M] [DistribMulAction R M] [DistribMulAction Rᵐᵒᵖ M]
(x : tsze R M) (n : ℕ) :
snd (x ^ n) = ((List.range n).map fun i => x.fst ^ (n.pred - i) •> x.snd <• x.fst ^ i).sum :=
rfl
theorem snd_pow_of_smul_comm [Monoid R] [AddMonoid M] [DistribMulAction R M]
[DistribMulAction Rᵐᵒᵖ M] [SMulCommClass R Rᵐᵒᵖ M] (x : tsze R M) (n : ℕ)
(h : x.snd <• x.fst = x.fst •> x.snd) : snd (x ^ n) = n • x.fst ^ n.pred •> x.snd := by
simp_rw [snd_pow_eq_sum, ← smul_comm (_ : R) (_ : Rᵐᵒᵖ), aux, smul_smul, ← pow_add]
match n with
| 0 => rw [Nat.pred_zero, pow_zero, List.range_zero, zero_smul, List.map_nil, List.sum_nil]
| (Nat.succ n) =>
simp_rw [Nat.pred_succ]
exact (List.sum_eq_card_nsmul _ (x.fst ^ n • x.snd) (by grind)).trans
(by rw [List.length_map, List.length_range])
where
aux : ∀ n : ℕ, x.snd <• x.fst ^ n = x.fst ^ n •> x.snd := by
intro n
induction n with
| zero => simp
| succ n ih =>
rw [pow_succ, op_mul, mul_smul, mul_smul, ← h, smul_comm (_ : R) (op x.fst) x.snd, ih]
theorem snd_pow_of_smul_comm' [Monoid R] [AddMonoid M] [DistribMulAction R M]
[DistribMulAction Rᵐᵒᵖ M] [SMulCommClass R Rᵐᵒᵖ M] (x : tsze R M) (n : ℕ)
(h : x.snd <• x.fst = x.fst •> x.snd) : snd (x ^ n) = n • (x.snd <• x.fst ^ n.pred) := by
rw [snd_pow_of_smul_comm _ _ h, snd_pow_of_smul_comm.aux _ h]
@[simp]
theorem snd_pow [CommMonoid R] [AddMonoid M] [DistribMulAction R M] [DistribMulAction Rᵐᵒᵖ M]
[IsCentralScalar R M] (x : tsze R M) (n : ℕ) : snd (x ^ n) = n • x.fst ^ n.pred • x.snd :=
snd_pow_of_smul_comm _ _ (op_smul_eq_smul _ _)
@[simp]
theorem inl_pow [Monoid R] [AddMonoid M] [DistribMulAction R M] [DistribMulAction Rᵐᵒᵖ M] (r : R)
(n : ℕ) : (inl r ^ n : tsze R M) = inl (r ^ n) :=
ext rfl <| by simp [snd_pow_eq_sum, List.map_const']
instance monoid [Monoid R] [AddMonoid M] [DistribMulAction R M] [DistribMulAction Rᵐᵒᵖ M]
[SMulCommClass R Rᵐᵒᵖ M] : Monoid (tsze R M) :=
{ TrivSqZeroExt.mulOneClass with
mul_assoc := fun x y z =>
ext (mul_assoc x.1 y.1 z.1) <|
show
(x.1 * y.1) •> z.2 + (x.1 •> y.2 + x.2 <• y.1) <• z.1 =
x.1 •> (y.1 •> z.2 + y.2 <• z.1) + x.2 <• (y.1 * z.1)
by simp_rw [smul_add, ← mul_smul, add_assoc, smul_comm, op_mul]
npow := fun n x => x ^ n
npow_zero := fun x => ext (pow_zero x.fst) (by simp [snd_pow_eq_sum])
npow_succ := fun n x =>
ext (pow_succ _ _)
(by
simp_rw [snd_mul, snd_pow_eq_sum, Nat.pred_succ]
cases n
· simp [List.range_succ]
rw [List.sum_range_succ']
simp only [pow_zero, op_one, Nat.sub_zero, one_smul, Nat.succ_sub_succ_eq_sub, fst_pow,
Nat.pred_succ, List.smul_sum, List.map_map, Function.comp_def]
simp_rw [← smul_comm (_ : R) (_ : Rᵐᵒᵖ), smul_smul, pow_succ]
rfl) }
theorem fst_list_prod [Monoid R] [AddMonoid M] [DistribMulAction R M] [DistribMulAction Rᵐᵒᵖ M]
[SMulCommClass R Rᵐᵒᵖ M] (l : List (tsze R M)) : l.prod.fst = (l.map fst).prod :=
map_list_prod ({ toFun := fst, map_one' := fst_one, map_mul' := fst_mul } : tsze R M →* R) _
instance semiring [Semiring R] [AddCommMonoid M]
[Module R M] [Module Rᵐᵒᵖ M] [SMulCommClass R Rᵐᵒᵖ M] : Semiring (tsze R M) :=
{ TrivSqZeroExt.monoid, TrivSqZeroExt.nonAssocSemiring with }
/-- The second element of a product $\prod_{i=0}^n (r_i + m_i)$ is a sum of terms of the form
$r_0\cdots r_{i-1}m_ir_{i+1}\cdots r_n$. -/
theorem snd_list_prod [Monoid R] [AddCommMonoid M] [DistribMulAction R M] [DistribMulAction Rᵐᵒᵖ M]
[SMulCommClass R Rᵐᵒᵖ M] (l : List (tsze R M)) :
l.prod.snd =
(l.zipIdx.map fun x : tsze R M × ℕ =>
((l.map fst).take x.2).prod •> x.fst.snd <• ((l.map fst).drop x.2.succ).prod).sum := by
induction l with
| nil => simp
| cons x xs ih =>
rw [List.zipIdx_cons']
simp_rw [List.map_cons, List.map_map, Function.comp_def, Prod.map_snd, Prod.map_fst, id,
List.take_zero, List.take_succ_cons, List.prod_nil, List.prod_cons, snd_mul, one_smul,
List.drop, mul_smul, List.sum_cons, fst_list_prod, ih, List.smul_sum, List.map_map,
← smul_comm (_ : R) (_ : Rᵐᵒᵖ)]
exact add_comm _ _
instance ring [Ring R] [AddCommGroup M] [Module R M] [Module Rᵐᵒᵖ M] [SMulCommClass R Rᵐᵒᵖ M] :
Ring (tsze R M) :=
{ TrivSqZeroExt.semiring, TrivSqZeroExt.nonAssocRing with }
instance commMonoid [CommMonoid R] [AddCommMonoid M] [DistribMulAction R M]
[DistribMulAction Rᵐᵒᵖ M] [IsCentralScalar R M] : CommMonoid (tsze R M) :=
{ TrivSqZeroExt.monoid with
mul_comm := fun x₁ x₂ =>
ext (mul_comm x₁.1 x₂.1) <|
show x₁.1 •> x₂.2 + x₁.2 <• x₂.1 = x₂.1 •> x₁.2 + x₂.2 <• x₁.1 by
rw [op_smul_eq_smul, op_smul_eq_smul, add_comm] }
instance commSemiring [CommSemiring R] [AddCommMonoid M] [Module R M] [Module Rᵐᵒᵖ M]
[IsCentralScalar R M] : CommSemiring (tsze R M) :=
{ TrivSqZeroExt.commMonoid, TrivSqZeroExt.nonAssocSemiring with }
instance commRing [CommRing R] [AddCommGroup M] [Module R M] [Module Rᵐᵒᵖ M] [IsCentralScalar R M] :
CommRing (tsze R M) :=
{ TrivSqZeroExt.nonAssocRing, TrivSqZeroExt.commSemiring with }
variable (R M)
/-- The canonical inclusion of rings `R → TrivSqZeroExt R M`. -/
@[simps apply]
def inlHom [Semiring R] [AddCommMonoid M] [Module R M] [Module Rᵐᵒᵖ M] : R →+* tsze R M where
toFun := inl
map_one' := inl_one M
map_mul' := inl_mul M
map_zero' := inl_zero M
map_add' := inl_add M
end Mul
section Inv
variable {R : Type u} {M : Type v}
variable [Neg M] [Inv R] [SMul Rᵐᵒᵖ M] [SMul R M]
/-- Inversion of the trivial-square-zero extension, sending $r + m$ to $r^{-1} - r^{-1}mr^{-1}$.
Strictly this is only a _two_-sided inverse when the left and right actions associate. -/
instance instInv : Inv (tsze R M) :=
⟨fun b => (b.1⁻¹, -(b.1⁻¹ •> b.2 <• b.1⁻¹))⟩
@[simp] theorem fst_inv (x : tsze R M) : fst x⁻¹ = (fst x)⁻¹ :=
rfl
@[simp] theorem snd_inv (x : tsze R M) : snd x⁻¹ = -((fst x)⁻¹ •> snd x <• (fst x)⁻¹) :=
rfl
end Inv
/-! This section is heavily inspired by analogous results about matrices. -/
section Invertible
variable {R : Type u} {M : Type v}
variable [AddCommGroup M] [Semiring R] [Module Rᵐᵒᵖ M] [Module R M]
/-- `x.fst : R` is invertible when `x : tzre R M` is. -/
abbrev invertibleFstOfInvertible (x : tsze R M) [Invertible x] : Invertible x.fst where
invOf := (⅟x).fst
invOf_mul_self := by rw [← fst_mul, invOf_mul_self, fst_one]
mul_invOf_self := by rw [← fst_mul, mul_invOf_self, fst_one]
theorem fst_invOf (x : tsze R M) [Invertible x] [Invertible x.fst] : (⅟x).fst = ⅟(x.fst) := by
letI := invertibleFstOfInvertible x
convert (rfl : _ = ⅟x.fst)
theorem mul_left_eq_one (r : R) (x : tsze R M) (h : r * x.fst = 1) :
(inl r + inr (-((r •> x.snd) <• r))) * x = 1 := by
ext <;> dsimp
· rw [add_zero, h]
· rw [add_zero, zero_add, smul_neg, op_smul_op_smul, h, op_one, one_smul,
add_neg_cancel]
theorem mul_right_eq_one (x : tsze R M) (r : R) (h : x.fst * r = 1) :
x * (inl r + inr (-(r •> (x.snd <• r)))) = 1 := by
ext <;> dsimp
· rw [add_zero, h]
· rw [add_zero, zero_add, smul_neg, smul_smul, h, one_smul, neg_add_cancel]
variable [SMulCommClass R Rᵐᵒᵖ M]
/-- `x : tzre R M` is invertible when `x.fst : R` is. -/
abbrev invertibleOfInvertibleFst (x : tsze R M) [Invertible x.fst] : Invertible x where
invOf := (⅟x.fst, -(⅟x.fst •> x.snd <• ⅟x.fst))
invOf_mul_self := by
convert mul_left_eq_one _ _ (invOf_mul_self x.fst)
ext <;> simp
mul_invOf_self := by
convert mul_right_eq_one _ _ (mul_invOf_self x.fst)
ext <;> simp [smul_comm]
theorem snd_invOf (x : tsze R M) [Invertible x] [Invertible x.fst] :
(⅟x).snd = -(⅟x.fst •> x.snd <• ⅟x.fst) := by
letI := invertibleOfInvertibleFst x
convert congr_arg (TrivSqZeroExt.snd (R := R) (M := M)) (_ : _ = ⅟x)
convert rfl
/-- Together `TrivSqZeroExt.detInvertibleOfInvertible` and `TrivSqZeroExt.invertibleOfDetInvertible`
form an equivalence, although both sides of the equiv are subsingleton anyway. -/
@[simps]
def invertibleEquivInvertibleFst (x : tsze R M) : Invertible x ≃ Invertible x.fst where
toFun _ := invertibleFstOfInvertible x
invFun _ := invertibleOfInvertibleFst x
left_inv _ := Subsingleton.elim _ _
right_inv _ := Subsingleton.elim _ _
/-- When lowered to a prop, `Matrix.invertibleEquivInvertibleFst` forms an `iff`. -/
theorem isUnit_iff_isUnit_fst {x : tsze R M} : IsUnit x ↔ IsUnit x.fst := by
simp only [← nonempty_invertible_iff_isUnit, (invertibleEquivInvertibleFst x).nonempty_congr]
@[simp]
theorem isUnit_inl_iff {r : R} : IsUnit (inl r : tsze R M) ↔ IsUnit r := by
rw [isUnit_iff_isUnit_fst, fst_inl]
@[simp]
theorem isUnit_inr_iff {m : M} : IsUnit (inr m : tsze R M) ↔ Subsingleton R := by
simp_rw [isUnit_iff_isUnit_fst, fst_inr, isUnit_zero_iff, subsingleton_iff_zero_eq_one]
end Invertible
section DivisionSemiring
variable {R : Type u} {M : Type v}
variable [DivisionSemiring R] [AddCommGroup M] [Module Rᵐᵒᵖ M] [Module R M]
protected theorem inv_inl (r : R) :
(inl r)⁻¹ = (inl (r⁻¹ : R) : tsze R M) := by
ext
· rw [fst_inv, fst_inl, fst_inl]
· rw [snd_inv, fst_inl, snd_inl, snd_inl, smul_zero, smul_zero, neg_zero]
@[simp]
theorem inv_inr (m : M) : (inr m)⁻¹ = (0 : tsze R M) := by
ext
· rw [fst_inv, fst_inr, fst_zero, inv_zero]
· rw [snd_inv, snd_inr, fst_inr, inv_zero, op_zero, zero_smul, snd_zero, neg_zero]
@[simp]
protected theorem inv_zero : (0 : tsze R M)⁻¹ = (0 : tsze R M) := by
rw [← inl_zero, TrivSqZeroExt.inv_inl, inv_zero]
@[simp]
protected theorem inv_one : (1 : tsze R M)⁻¹ = (1 : tsze R M) := by
rw [← inl_one, TrivSqZeroExt.inv_inl, inv_one]
protected theorem inv_mul_cancel {x : tsze R M} (hx : fst x ≠ 0) : x⁻¹ * x = 1 := by
convert mul_left_eq_one _ _ (_root_.inv_mul_cancel₀ hx) using 2
ext <;> simp
variable [SMulCommClass R Rᵐᵒᵖ M]
@[simp] theorem invOf_eq_inv (x : tsze R M) [Invertible x] : ⅟x = x⁻¹ := by
letI := invertibleFstOfInvertible x
ext <;> simp [fst_invOf, snd_invOf]
protected theorem mul_inv_cancel {x : tsze R M} (hx : fst x ≠ 0) : x * x⁻¹ = 1 := by
have : Invertible x.fst := Units.invertible (.mk0 _ hx)
have := invertibleOfInvertibleFst x
rw [← invOf_eq_inv, mul_invOf_self]
protected theorem mul_inv_rev (a b : tsze R M) :
(a * b)⁻¹ = b⁻¹ * a⁻¹ := by
ext
· rw [fst_inv, fst_mul, fst_mul, mul_inv_rev, fst_inv, fst_inv]
· simp only [snd_inv, snd_mul, fst_mul, fst_inv]
simp only [smul_neg, smul_add]
simp_rw [mul_inv_rev, smul_comm (_ : R), op_smul_op_smul, smul_smul, add_comm, neg_add]
obtain ha0 | ha := eq_or_ne (fst a) 0
· simp [ha0]
obtain hb0 | hb := eq_or_ne (fst b) 0
· simp [hb0]
rw [inv_mul_cancel_right₀ ha, mul_inv_cancel_left₀ hb]
protected theorem inv_inv {x : tsze R M} (hx : fst x ≠ 0) : x⁻¹⁻¹ = x :=
-- adapted from `Matrix.nonsing_inv_nonsing_inv`
calc
x⁻¹⁻¹ = 1 * x⁻¹⁻¹ := by rw [one_mul]
_ = x * x⁻¹ * x⁻¹⁻¹ := by rw [TrivSqZeroExt.mul_inv_cancel hx]
_ = x := by
rw [mul_assoc, TrivSqZeroExt.mul_inv_cancel, mul_one]
rw [fst_inv]
apply inv_ne_zero hx
@[simp]
theorem isUnit_inv_iff {x : tsze R M} : IsUnit x⁻¹ ↔ IsUnit x := by
simp_rw [isUnit_iff_isUnit_fst, fst_inv, isUnit_iff_ne_zero, ne_eq, inv_eq_zero]
end DivisionSemiring
section DivisionRing
variable {R : Type u} {M : Type v}
variable [DivisionRing R] [AddCommGroup M] [Module Rᵐᵒᵖ M] [Module R M]
protected theorem inv_neg {x : tsze R M} : (-x)⁻¹ = -(x⁻¹) := by
ext <;> simp [inv_neg]
end DivisionRing
section Algebra
variable (S : Type*) (R R' : Type u) (M : Type v)
variable [CommSemiring S] [Semiring R] [CommSemiring R'] [AddCommMonoid M]
variable [Algebra S R] [Module S M] [Module R M] [Module Rᵐᵒᵖ M] [SMulCommClass R Rᵐᵒᵖ M]
variable [IsScalarTower S R M] [IsScalarTower S Rᵐᵒᵖ M]
variable [Module R' M] [Module R'ᵐᵒᵖ M] [IsCentralScalar R' M]
instance algebra' : Algebra S (tsze R M) where
algebraMap := (TrivSqZeroExt.inlHom R M).comp (algebraMap S R)
commutes' := fun s x =>
ext (Algebra.commutes _ _) <|
show algebraMap S R s •> x.snd + (0 : M) <• x.fst
= x.fst •> (0 : M) + x.snd <• algebraMap S R s by
rw [smul_zero, smul_zero, add_zero, zero_add]
rw [Algebra.algebraMap_eq_smul_one, MulOpposite.op_smul, op_one, smul_assoc,
one_smul, smul_assoc, one_smul]
smul_def' := fun s x =>
ext (Algebra.smul_def _ _) <|
show s • x.snd = algebraMap S R s •> x.snd + (0 : M) <• x.fst by
rw [smul_zero, add_zero, algebraMap_smul]
-- shortcut instance for the common case
instance : Algebra R' (tsze R' M) :=
TrivSqZeroExt.algebra' _ _ _
theorem algebraMap_eq_inl : ⇑(algebraMap R' (tsze R' M)) = inl :=
rfl
theorem algebraMap_eq_inlHom : algebraMap R' (tsze R' M) = inlHom R' M :=
rfl
theorem algebraMap_eq_inl' (s : S) : algebraMap S (tsze R M) s = inl (algebraMap S R s) :=
rfl
/-- The canonical `S`-algebra projection `TrivSqZeroExt R M → R`. -/
@[simps]
def fstHom : tsze R M →ₐ[S] R where
toFun := fst
map_one' := fst_one
map_mul' := fst_mul
map_zero' := fst_zero (M := M)
map_add' := fst_add
commutes' _r := fst_inl M _
/-- The canonical `S`-algebra inclusion `R → TrivSqZeroExt R M`. -/
@[simps]
def inlAlgHom : R →ₐ[S] tsze R M where
toFun := inl
map_one' := inl_one _
map_mul' := inl_mul _
map_zero' := inl_zero (M := M)
map_add' := inl_add _
commutes' _r := (algebraMap_eq_inl' _ _ _ _).symm
variable {R R' S M}
theorem algHom_ext {A} [Semiring A] [Algebra R' A] ⦃f g : tsze R' M →ₐ[R'] A⦄
(h : ∀ m, f (inr m) = g (inr m)) : f = g :=
AlgHom.toLinearMap_injective <|
linearMap_ext (fun _r => (f.commutes _).trans (g.commutes _).symm) h
@[ext]
theorem algHom_ext' {A} [Semiring A] [Algebra S A] ⦃f g : tsze R M →ₐ[S] A⦄
(hinl : f.comp (inlAlgHom S R M) = g.comp (inlAlgHom S R M))
(hinr : f.toLinearMap.comp (inrHom R M |>.restrictScalars S) =
g.toLinearMap.comp (inrHom R M |>.restrictScalars S)) : f = g :=
AlgHom.toLinearMap_injective <|
linearMap_ext (AlgHom.congr_fun hinl) (LinearMap.congr_fun hinr)
variable {A : Type*} [Semiring A] [Algebra S A] [Algebra R' A]
/--
Assemble an algebra morphism `TrivSqZeroExt R M →ₐ[S] A` from separate morphisms on `R` and `M`.
Namely, we require that for an algebra morphism `f : R →ₐ[S] A` and a linear map `g : M →ₗ[S] A`,
we have:
* `g x * g y = 0`: the elements of `M` continue to square to zero.
* `g (r •> x) = f r * g x` and `g (x <• r) = g x * f r`: scalar multiplication on the left and
right is sent to left- and right- multiplication by the image under `f`.
See `TrivSqZeroExt.liftEquiv` for this as an equiv; namely that any such algebra morphism can be
factored in this way.
When `R` is commutative, this can be invoked with `f = Algebra.ofId R A`, which satisfies `hfg` and
`hgf`. This version is captured as an equiv by `TrivSqZeroExt.liftEquivOfComm`. -/
def lift (f : R →ₐ[S] A) (g : M →ₗ[S] A)
(hg : ∀ x y, g x * g y = 0)
(hfg : ∀ r x, g (r •> x) = f r * g x)
(hgf : ∀ r x, g (x <• r) = g x * f r) : tsze R M →ₐ[S] A :=
AlgHom.ofLinearMap
((f.comp <| fstHom S R M).toLinearMap + g ∘ₗ (sndHom R M |>.restrictScalars S))
(show f 1 + g (0 : M) = 1 by rw [map_zero, map_one, add_zero])
(TrivSqZeroExt.ind fun r₁ m₁ =>
TrivSqZeroExt.ind fun r₂ m₂ => by
dsimp
simp only [add_zero, zero_add, add_mul, mul_add, hg]
rw [← map_mul, LinearMap.map_add, add_comm (g _), add_assoc, hfg, hgf])
theorem lift_def (f : R →ₐ[S] A) (g : M →ₗ[S] A)
(hg : ∀ x y, g x * g y = 0)
(hfg : ∀ r x, g (r • x) = f r * g x)
(hgf : ∀ r x, g (op r • x) = g x * f r) (x : tsze R M) :
lift f g hg hfg hgf x = f x.fst + g x.snd :=
rfl
@[simp]
theorem lift_apply_inl (f : R →ₐ[S] A) (g : M →ₗ[S] A)
(hg : ∀ x y, g x * g y = 0)
(hfg : ∀ r x, g (r •> x) = f r * g x)
(hgf : ∀ r x, g (x <• r) = g x * f r)
(r : R) :
lift f g hg hfg hgf (inl r) = f r :=
show f r + g 0 = f r by rw [map_zero, add_zero]
@[simp]
theorem lift_apply_inr (f : R →ₐ[S] A) (g : M →ₗ[S] A)
(hg : ∀ x y, g x * g y = 0)
(hfg : ∀ r x, g (r •> x) = f r * g x)
(hgf : ∀ r x, g (x <• r) = g x * f r)
(m : M) :
lift f g hg hfg hgf (inr m) = g m :=
show f 0 + g m = g m by rw [map_zero, zero_add]
@[simp]
theorem lift_comp_inlHom (f : R →ₐ[S] A) (g : M →ₗ[S] A)
(hg : ∀ x y, g x * g y = 0)
(hfg : ∀ r x, g (r •> x) = f r * g x)
(hgf : ∀ r x, g (x <• r) = g x * f r) :
(lift f g hg hfg hgf).comp (inlAlgHom S R M) = f :=
AlgHom.ext <| lift_apply_inl f g hg hfg hgf
@[simp]
theorem lift_comp_inrHom (f : R →ₐ[S] A) (g : M →ₗ[S] A)
(hg : ∀ x y, g x * g y = 0)
(hfg : ∀ r x, g (r •> x) = f r * g x)
(hgf : ∀ r x, g (x <• r) = g x * f r) :
(lift f g hg hfg hgf).toLinearMap.comp (inrHom R M |>.restrictScalars S) = g :=
LinearMap.ext <| lift_apply_inr f g hg hfg hgf
/-- When applied to `inr` and `inl` themselves, `lift` is the identity. -/
@[simp]
theorem lift_inlAlgHom_inrHom :
lift (inlAlgHom _ _ _) (inrHom R M |>.restrictScalars S)
(inr_mul_inr R) (fun _ _ => (inl_mul_inr _ _).symm) (fun _ _ => (inr_mul_inl _ _).symm) =
AlgHom.id S (tsze R M) :=
algHom_ext' (lift_comp_inlHom _ _ _ _ _) (lift_comp_inrHom _ _ _ _ _)
@[simp]
theorem range_inlAlgHom_sup_adjoin_range_inr :
(inlAlgHom S R M).range ⊔ Algebra.adjoin S (Set.range inr) = (⊤ : Subalgebra S (tsze R M)) := by
refine top_unique fun x hx => ?_; clear hx
rw [← x.inl_fst_add_inr_snd_eq]
refine add_mem ?_ ?_
· exact le_sup_left (α := Subalgebra S _) <| Set.mem_range_self x.fst
· exact le_sup_right (α := Subalgebra S _) <| Algebra.subset_adjoin <| Set.mem_range_self x.snd
@[simp]
theorem range_liftAux (f : R →ₐ[S] A) (g : M →ₗ[S] A)
(hg : ∀ x y, g x * g y = 0)
(hfg : ∀ r x, g (r •> x) = f r * g x)
(hgf : ∀ r x, g (x <• r) = g x * f r) :
(lift f g hg hfg hgf).range = f.range ⊔ Algebra.adjoin S (Set.range g) := by
simp_rw [← Algebra.map_top, ← range_inlAlgHom_sup_adjoin_range_inr, Algebra.map_sup,
AlgHom.map_adjoin, ← AlgHom.range_comp, lift_comp_inlHom, ← Set.range_comp, Function.comp_def,
lift_apply_inr, Algebra.map_top]
/-- A universal property of the trivial square-zero extension, providing a unique
`TrivSqZeroExt R M →ₐ[R] A` for every pair of maps `f : R →ₐ[S] A` and `g : M →ₗ[S] A`,
where the range of `g` has no non-zero products, and scaling the input to `g` on the left or right
amounts to a corresponding multiplication by `f` in the output.
This isomorphism is named to match the very similar `Complex.lift`. -/
@[simps! apply symm_apply_coe]
def liftEquiv :
{fg : (R →ₐ[S] A) × (M →ₗ[S] A) //
(∀ x y, fg.2 x * fg.2 y = 0) ∧
(∀ r x, fg.2 (r •> x) = fg.1 r * fg.2 x) ∧
(∀ r x, fg.2 (x <• r) = fg.2 x * fg.1 r)} ≃ (tsze R M →ₐ[S] A) where
toFun fg := lift fg.val.1 fg.val.2 fg.prop.1 fg.prop.2.1 fg.prop.2.2
invFun F :=
⟨(F.comp (inlAlgHom _ _ _), F.toLinearMap ∘ₗ (inrHom _ _ |>.restrictScalars _)),
(fun _x _y =>
(map_mul F _ _).symm.trans <| (F.congr_arg <| inr_mul_inr _ _ _).trans (map_zero F)),
(fun _r _x => (F.congr_arg (inl_mul_inr _ _).symm).trans (map_mul F _ _)),
(fun _r _x => (F.congr_arg (inr_mul_inl _ _).symm).trans (map_mul F _ _))⟩
left_inv _f := Subtype.ext <| Prod.ext (lift_comp_inlHom _ _ _ _ _) (lift_comp_inrHom _ _ _ _ _)
right_inv _F := algHom_ext' (lift_comp_inlHom _ _ _ _ _) (lift_comp_inrHom _ _ _ _ _)
/-- A simplified version of `TrivSqZeroExt.liftEquiv` for the commutative case. -/
@[simps! apply symm_apply_coe]
def liftEquivOfComm :
{ f : M →ₗ[R'] A // ∀ x y, f x * f y = 0 } ≃ (tsze R' M →ₐ[R'] A) := by
refine Equiv.trans ?_ liftEquiv
exact {
toFun := fun f => ⟨(Algebra.ofId _ _, f.val), f.prop,
fun r x => by simp [Algebra.smul_def, Algebra.ofId_apply],
fun r x => by simp [Algebra.smul_def, Algebra.ofId_apply, Algebra.commutes]⟩
invFun := fun fg => ⟨fg.val.2, fg.prop.1⟩ }
section map
variable {N P : Type*} [AddCommMonoid N] [Module R' N] [Module R'ᵐᵒᵖ N] [IsCentralScalar R' N]
[AddCommMonoid P] [Module R' P] [Module R'ᵐᵒᵖ P] [IsCentralScalar R' P]
/-- Functoriality of `TrivSqZeroExt` when the ring is commutative: a linear map
`f : M →ₗ[R'] N` induces a morphism of `R'`-algebras from `TrivSqZeroExt R' M` to
`TrivSqZeroExt R' N`.
Note that we cannot neatly state the non-commutative case, as we do not have morphisms of bimodules.
-/
def map (f : M →ₗ[R'] N) : TrivSqZeroExt R' M →ₐ[R'] TrivSqZeroExt R' N :=
liftEquivOfComm ⟨inrHom R' N ∘ₗ f, fun _ _ => inr_mul_inr _ _ _⟩
@[simp]
theorem map_inl (f : M →ₗ[R'] N) (r : R') : map f (inl r) = inl r := by
rw [map, liftEquivOfComm_apply, lift_apply_inl, Algebra.ofId_apply, algebraMap_eq_inl]
@[simp]
theorem map_inr (f : M →ₗ[R'] N) (x : M) : map f (inr x) = inr (f x) := by
rw [map, liftEquivOfComm_apply, lift_apply_inr, LinearMap.comp_apply, inrHom_apply]
@[simp]
theorem fst_map (f : M →ₗ[R'] N) (x : TrivSqZeroExt R' M) : fst (map f x) = fst x := by
simp [map, lift_def, Algebra.ofId_apply, algebraMap_eq_inl]
@[simp]
theorem snd_map (f : M →ₗ[R'] N) (x : TrivSqZeroExt R' M) : snd (map f x) = f (snd x) := by
simp [map, lift_def, Algebra.ofId_apply, algebraMap_eq_inl]
@[simp]
theorem map_comp_inlAlgHom (f : M →ₗ[R'] N) :
(map f).comp (inlAlgHom R' R' M) = inlAlgHom R' R' N :=
AlgHom.ext <| map_inl _
@[simp]
theorem map_comp_inrHom (f : M →ₗ[R'] N) :
(map f).toLinearMap ∘ₗ inrHom R' M = inrHom R' N ∘ₗ f :=
LinearMap.ext <| map_inr _
@[simp]
theorem fstHom_comp_map (f : M →ₗ[R'] N) :
(fstHom R' R' N).comp (map f) = fstHom R' R' M :=
AlgHom.ext <| fst_map _
@[simp]
theorem sndHom_comp_map (f : M →ₗ[R'] N) :
sndHom R' N ∘ₗ (map f).toLinearMap = f ∘ₗ sndHom R' M :=
LinearMap.ext <| snd_map _
@[simp]
theorem map_id : map (LinearMap.id : M →ₗ[R'] M) = AlgHom.id R' _ := by
apply algHom_ext
simp only [map_inr, LinearMap.id_coe, id_eq, AlgHom.coe_id, forall_const]
theorem map_comp_map (f : M →ₗ[R'] N) (g : N →ₗ[R'] P) :
map (g.comp f) = (map g).comp (map f) := by
apply algHom_ext
simp only [map_inr, LinearMap.coe_comp, Function.comp_apply, AlgHom.coe_comp, forall_const]
end map
end Algebra
end TrivSqZeroExt |
.lake/packages/mathlib/Mathlib/Algebra/Free.lean | import Mathlib.Algebra.Group.Basic
import Mathlib.Algebra.Group.Equiv.Defs
import Mathlib.Control.Applicative
import Mathlib.Control.Traversable.Basic
import Mathlib.Logic.Equiv.Defs
import Mathlib.Tactic.AdaptationNote
/-!
# Free constructions
## Main definitions
* `FreeMagma α`: free magma (structure with binary operation without any axioms) over alphabet `α`,
defined inductively, with traversable instance and decidable equality.
* `MagmaAssocQuotient α`: quotient of a magma `α` by the associativity equivalence relation.
* `FreeSemigroup α`: free semigroup over alphabet `α`, defined as a structure with two fields
`head : α` and `tail : List α` (i.e. nonempty lists), with traversable instance and decidable
equality.
* `FreeMagmaAssocQuotientEquiv α`: isomorphism between `MagmaAssocQuotient (FreeMagma α)` and
`FreeSemigroup α`.
* `FreeMagma.lift`: the universal property of the free magma, expressing its adjointness.
-/
universe u v l
-- Disable generation of `sizeOf_spec` and `injEq`,
-- which are not needed and the `simpNF` linter will complain about.
set_option genSizeOfSpec false in
set_option genInjectivity false in
/--
If `α` is a type, then `FreeAddMagma α` is the free additive magma generated by `α`.
This is an additive magma equipped with a function `FreeAddMagma.of : α → FreeAddMagma α` which has
the following universal property: if `M` is any magma, and `f : α → M` is any function,
then this function is the composite of `FreeAddMagma.of` and a unique additive homomorphism
`FreeAddMagma.lift f : FreeAddMagma α →ₙ+ M`.
A typical element of `FreeAddMagma α` is a formal non-associative sum of
elements of `α`. For example if `x` and `y` are terms of type `α` then `x + ((y + y) + x)` is a
"typical" element of `FreeAddMagma α`.
One can think of `FreeAddMagma α` as the type of binary trees with leaves labelled by `α`.
In general, no pair of distinct elements in `FreeAddMagma α` will commute.
-/
inductive FreeAddMagma (α : Type u) : Type u
| of : α → FreeAddMagma α
| add : FreeAddMagma α → FreeAddMagma α → FreeAddMagma α
deriving DecidableEq
compile_inductive% FreeAddMagma
-- Disable generation of `sizeOf_spec` and `injEq`,
-- which are not needed and the `simpNF` linter will complain about.
set_option genSizeOfSpec false in
set_option genInjectivity false in
/--
If `α` is a type, then `FreeMagma α` is the free magma generated by `α`.
This is a magma equipped with a function `FreeMagma.of : α → FreeMagma α` which has
the following universal property: if `M` is any magma, and `f : α → M` is any function,
then this function is the composite of `FreeMagma.of` and a unique multiplicative homomorphism
`FreeMagma.lift f : FreeMagma α →ₙ* M`.
A typical element of `FreeMagma α` is a formal non-associative product of
elements of `α`. For example if `x` and `y` are terms of type `α` then `x * ((y * y) * x)` is a
"typical" element of `FreeMagma α`.
One can think of `FreeMagma α` as the type of binary trees with leaves labelled by `α`.
In general, no pair of distinct elements in `FreeMagma α` will commute.
-/
@[to_additive]
inductive FreeMagma (α : Type u) : Type u
| of : α → FreeMagma α
| mul : FreeMagma α → FreeMagma α → FreeMagma α
deriving DecidableEq
compile_inductive% FreeMagma
namespace FreeMagma
variable {α : Type u}
@[to_additive]
instance [Inhabited α] : Inhabited (FreeMagma α) := ⟨of default⟩
@[to_additive]
instance : Mul (FreeMagma α) := ⟨FreeMagma.mul⟩
@[to_additive (attr := simp)]
theorem mul_eq (x y : FreeMagma α) : mul x y = x * y := rfl
/-- Recursor for `FreeMagma` using `x * y` instead of `FreeMagma.mul x y`. -/
@[to_additive (attr := elab_as_elim, induction_eliminator)
/-- Recursor for `FreeAddMagma` using `x + y` instead of `FreeAddMagma.add x y`. -/]
def recOnMul {C : FreeMagma α → Sort l} (x) (ih1 : ∀ x, C (of x))
(ih2 : ∀ x y, C x → C y → C (x * y)) : C x :=
FreeMagma.recOn x ih1 ih2
@[to_additive (attr := ext 1100)]
theorem hom_ext {β : Type v} [Mul β] {f g : FreeMagma α →ₙ* β} (h : f ∘ of = g ∘ of) : f = g :=
(DFunLike.ext _ _) fun x ↦ recOnMul x (congr_fun h) <| by intros; simp only [map_mul, *]
end FreeMagma
/-- Lifts a function `α → β` to a magma homomorphism `FreeMagma α → β` given a magma `β`. -/
def FreeMagma.liftAux {α : Type u} {β : Type v} [Mul β] (f : α → β) : FreeMagma α → β
| FreeMagma.of x => f x
| x * y => liftAux f x * liftAux f y
/-- Lifts a function `α → β` to an additive magma homomorphism `FreeAddMagma α → β` given
an additive magma `β`. -/
def FreeAddMagma.liftAux {α : Type u} {β : Type v} [Add β] (f : α → β) : FreeAddMagma α → β
| FreeAddMagma.of x => f x
| x + y => liftAux f x + liftAux f y
attribute [to_additive existing] FreeMagma.liftAux
namespace FreeMagma
section lift
variable {α : Type u} {β : Type v} [Mul β] (f : α → β)
/-- The universal property of the free magma expressing its adjointness. -/
@[to_additive (attr := simps symm_apply)
/-- The universal property of the free additive magma expressing its adjointness. -/]
def lift : (α → β) ≃ (FreeMagma α →ₙ* β) where
toFun f :=
{ toFun := liftAux f
map_mul' := fun _ _ ↦ rfl }
invFun F := F ∘ of
@[to_additive (attr := simp)]
theorem lift_of (x) : lift f (of x) = f x := rfl
@[to_additive (attr := simp)]
theorem lift_comp_of : lift f ∘ of = f := rfl
@[to_additive (attr := simp)]
theorem lift_comp_of' (f : FreeMagma α →ₙ* β) : lift (f ∘ of) = f := lift.apply_symm_apply f
end lift
section Map
variable {α : Type u} {β : Type v} (f : α → β)
/-- The unique magma homomorphism `FreeMagma α →ₙ* FreeMagma β` that sends
each `of x` to `of (f x)`. -/
@[to_additive /-- The unique additive magma homomorphism `FreeAddMagma α → FreeAddMagma β` that
sends each `of x` to `of (f x)`. -/]
def map (f : α → β) : FreeMagma α →ₙ* FreeMagma β := lift (of ∘ f)
@[to_additive (attr := simp)]
theorem map_of (x) : map f (of x) = of (f x) := rfl
end Map
section Category
variable {α β : Type u}
@[to_additive]
instance : Monad FreeMagma where
pure := of
bind x f := lift f x
/-- Recursor on `FreeMagma` using `pure` instead of `of`. -/
@[to_additive (attr := elab_as_elim)
/-- Recursor on `FreeAddMagma` using `pure` instead of `of`. -/]
protected def recOnPure {C : FreeMagma α → Sort l} (x) (ih1 : ∀ x, C (pure x))
(ih2 : ∀ x y, C x → C y → C (x * y)) : C x :=
FreeMagma.recOnMul x ih1 ih2
@[to_additive (attr := simp)]
protected theorem map_pure (f : α → β) (x) : (f <$> pure x : FreeMagma β) = pure (f x) := rfl
@[to_additive (attr := simp)]
theorem map_mul' (f : α → β) (x y : FreeMagma α) : f <$> (x * y) = f <$> x * f <$> y := rfl
@[to_additive (attr := simp)]
theorem pure_bind (f : α → FreeMagma β) (x) : pure x >>= f = f x := rfl
@[to_additive (attr := simp)]
theorem mul_bind (f : α → FreeMagma β) (x y : FreeMagma α) : x * y >>= f = (x >>= f) * (y >>= f) :=
rfl
@[to_additive (attr := simp)]
theorem pure_seq {α β : Type u} {f : α → β} {x : FreeMagma α} : pure f <*> x = f <$> x := rfl
@[to_additive (attr := simp)]
theorem mul_seq {α β : Type u} {f g : FreeMagma (α → β)} {x : FreeMagma α} :
f * g <*> x = (f <*> x) * (g <*> x) := rfl
@[to_additive]
instance instLawfulMonad : LawfulMonad FreeMagma.{u} := LawfulMonad.mk'
(pure_bind := fun _ _ ↦ rfl)
(bind_assoc := fun x f g ↦ FreeMagma.recOnPure x (fun _ ↦ rfl) fun x y ih1 ih2 ↦ by
rw [mul_bind, mul_bind, mul_bind, ih1, ih2])
(id_map := fun x ↦ FreeMagma.recOnPure x (fun _ ↦ rfl) fun x y ih1 ih2 ↦ by
rw [map_mul', ih1, ih2])
end Category
end FreeMagma
/-- `FreeMagma` is traversable. -/
protected def FreeMagma.traverse {m : Type u → Type u} [Applicative m] {α β : Type u}
(F : α → m β) : FreeMagma α → m (FreeMagma β)
| FreeMagma.of x => FreeMagma.of <$> F x
| x * y => (· * ·) <$> x.traverse F <*> y.traverse F
/-- `FreeAddMagma` is traversable. -/
protected def FreeAddMagma.traverse {m : Type u → Type u} [Applicative m] {α β : Type u}
(F : α → m β) : FreeAddMagma α → m (FreeAddMagma β)
| FreeAddMagma.of x => FreeAddMagma.of <$> F x
| x + y => (· + ·) <$> x.traverse F <*> y.traverse F
attribute [to_additive existing] FreeMagma.traverse
namespace FreeMagma
variable {α : Type u}
section Category
variable {β : Type u}
@[to_additive]
instance : Traversable FreeMagma := ⟨@FreeMagma.traverse⟩
variable {m : Type u → Type u} [Applicative m] (F : α → m β)
@[to_additive (attr := simp)]
theorem traverse_pure (x) : traverse F (pure x : FreeMagma α) = pure <$> F x := rfl
@[to_additive (attr := simp)]
theorem traverse_pure' : traverse F ∘ pure = fun x ↦ (pure <$> F x : m (FreeMagma β)) := rfl
@[to_additive (attr := simp)]
theorem traverse_mul (x y : FreeMagma α) :
traverse F (x * y) = (· * ·) <$> traverse F x <*> traverse F y := rfl
@[to_additive (attr := simp)]
theorem traverse_mul' :
Function.comp (traverse F) ∘ (HMul.hMul : FreeMagma α → FreeMagma α → FreeMagma α) = fun x y ↦
(· * ·) <$> traverse F x <*> traverse F y := rfl
@[to_additive (attr := simp)]
theorem traverse_eq (x) : FreeMagma.traverse F x = traverse F x := rfl
@[to_additive (attr := deprecated "Use map_pure and seq_pure" (since := "2025-05-21"))]
theorem mul_map_seq (x y : FreeMagma α) :
((· * ·) <$> x <*> y : Id (FreeMagma α)) = (x * y : FreeMagma α) := rfl
@[to_additive]
instance : LawfulTraversable FreeMagma.{u} :=
{ instLawfulMonad with
id_traverse := fun x ↦
FreeMagma.recOnPure x (fun _ ↦ rfl) fun x y ih1 ih2 ↦ by
rw [traverse_mul, ih1, ih2, seq_pure, map_pure, map_pure]
comp_traverse := fun f g x ↦
FreeMagma.recOnPure x
(fun x ↦ by simp only [Function.comp_def, traverse_pure, functor_norm])
(fun x y ih1 ih2 ↦ by
rw [traverse_mul, ih1, ih2, traverse_mul]
simp [Functor.Comp.map_mk, Functor.map_map, Function.comp_def, Comp.seq_mk, seq_map_assoc,
map_seq, traverse_mul])
naturality := fun η α β f x ↦
FreeMagma.recOnPure x
(fun x ↦ by simp only [traverse_pure, functor_norm, Function.comp_apply])
(fun x y ih1 ih2 ↦ by simp only [traverse_mul, functor_norm, ih1, ih2])
traverse_eq_map_id := fun f x ↦
FreeMagma.recOnPure x (fun _ ↦ rfl) fun x y ih1 ih2 ↦ by
rw [traverse_mul, ih1, ih2, map_mul', map_pure, seq_pure, map_pure] }
end Category
end FreeMagma
/-- Representation of an element of a free magma. -/
protected def FreeMagma.repr {α : Type u} [Repr α] : FreeMagma α → Lean.Format
| FreeMagma.of x => repr x
| x * y => "( " ++ x.repr ++ " * " ++ y.repr ++ " )"
/-- Representation of an element of a free additive magma. -/
protected def FreeAddMagma.repr {α : Type u} [Repr α] : FreeAddMagma α → Lean.Format
| FreeAddMagma.of x => repr x
| x + y => "( " ++ x.repr ++ " + " ++ y.repr ++ " )"
attribute [to_additive existing] FreeMagma.repr
@[to_additive]
instance {α : Type u} [Repr α] : Repr (FreeMagma α) := ⟨fun o _ => FreeMagma.repr o⟩
/-- Length of an element of a free magma. -/
def FreeMagma.length {α : Type u} : FreeMagma α → ℕ
| FreeMagma.of _x => 1
| x * y => x.length + y.length
/-- Length of an element of a free additive magma. -/
def FreeAddMagma.length {α : Type u} : FreeAddMagma α → ℕ
| FreeAddMagma.of _x => 1
| x + y => x.length + y.length
attribute [to_additive existing (attr := simp)] FreeMagma.length
/-- The length of an element of a free magma is positive. -/
@[to_additive /-- The length of an element of a free additive magma is positive. -/]
lemma FreeMagma.length_pos {α : Type u} (x : FreeMagma α) : 0 < x.length :=
match x with
| FreeMagma.of _ => Nat.succ_pos 0
| mul y z => Nat.add_pos_left (length_pos y) z.length
/-- Associativity relations for an additive magma. -/
inductive AddMagma.AssocRel (α : Type u) [Add α] : α → α → Prop
| intro : ∀ x y z, AddMagma.AssocRel α (x + y + z) (x + (y + z))
| left : ∀ w x y z, AddMagma.AssocRel α (w + (x + y + z)) (w + (x + (y + z)))
/-- Associativity relations for a magma. -/
@[to_additive AddMagma.AssocRel /-- Associativity relations for an additive magma. -/]
inductive Magma.AssocRel (α : Type u) [Mul α] : α → α → Prop
| intro : ∀ x y z, Magma.AssocRel α (x * y * z) (x * (y * z))
| left : ∀ w x y z, Magma.AssocRel α (w * (x * y * z)) (w * (x * (y * z)))
namespace Magma
/-- Semigroup quotient of a magma. -/
@[to_additive AddMagma.FreeAddSemigroup /-- Additive semigroup quotient of an additive magma. -/]
def AssocQuotient (α : Type u) [Mul α] : Type u :=
Quot <| AssocRel α
namespace AssocQuotient
variable {α : Type u} [Mul α]
@[to_additive]
theorem quot_mk_assoc (x y z : α) : Quot.mk (AssocRel α) (x * y * z) = Quot.mk _ (x * (y * z)) :=
Quot.sound (AssocRel.intro _ _ _)
@[to_additive]
theorem quot_mk_assoc_left (x y z w : α) :
Quot.mk (AssocRel α) (x * (y * z * w)) = Quot.mk _ (x * (y * (z * w))) :=
Quot.sound (AssocRel.left _ _ _ _)
@[to_additive]
instance : Semigroup (AssocQuotient α) where
mul x y := by
refine Quot.liftOn₂ x y (fun x y ↦ Quot.mk _ (x * y)) ?_ ?_
· rintro a b₁ b₂ (⟨c, d, e⟩ | ⟨c, d, e, f⟩) <;> simp only
· exact quot_mk_assoc_left _ _ _ _
· rw [← quot_mk_assoc, quot_mk_assoc_left, quot_mk_assoc]
· rintro a₁ a₂ b (⟨c, d, e⟩ | ⟨c, d, e, f⟩) <;> simp only
· simp only [quot_mk_assoc, quot_mk_assoc_left]
· rw [quot_mk_assoc, quot_mk_assoc, quot_mk_assoc_left, quot_mk_assoc_left,
quot_mk_assoc_left, ← quot_mk_assoc c d, ← quot_mk_assoc c d, quot_mk_assoc_left]
mul_assoc x y z :=
Quot.induction_on₃ x y z fun a b c ↦ quot_mk_assoc a b c
/-- Embedding from magma to its free semigroup. -/
@[to_additive /-- Embedding from additive magma to its free additive semigroup. -/]
def of : α →ₙ* AssocQuotient α where toFun := Quot.mk _; map_mul' _x _y := rfl
@[to_additive]
instance [Inhabited α] : Inhabited (AssocQuotient α) := ⟨of default⟩
@[to_additive (attr := elab_as_elim, induction_eliminator)]
protected theorem induction_on {C : AssocQuotient α → Prop} (x : AssocQuotient α)
(ih : ∀ x, C (of x)) : C x := Quot.induction_on x ih
section lift
variable {β : Type v} [Semigroup β] (f : α →ₙ* β)
@[to_additive (attr := ext 1100)]
theorem hom_ext {f g : AssocQuotient α →ₙ* β} (h : f.comp of = g.comp of) : f = g :=
(DFunLike.ext _ _) fun x => AssocQuotient.induction_on x <| DFunLike.congr_fun h
/-- Lifts a magma homomorphism `α → β` to a semigroup homomorphism `Magma.AssocQuotient α → β`
given a semigroup `β`. -/
@[to_additive (attr := simps symm_apply) /-- Lifts an additive magma homomorphism `α → β` to an
additive semigroup homomorphism `AddMagma.AssocQuotient α → β` given an additive semigroup `β`. -/]
def lift : (α →ₙ* β) ≃ (AssocQuotient α →ₙ* β) where
toFun f :=
{ toFun := fun x ↦
Quot.liftOn x f <| by rintro a b (⟨c, d, e⟩ | ⟨c, d, e, f⟩) <;> simp only [map_mul, mul_assoc]
map_mul' := fun x y ↦ Quot.induction_on₂ x y (map_mul f) }
invFun f := f.comp of
@[to_additive (attr := simp)]
theorem lift_of (x : α) : lift f (of x) = f x := rfl
@[to_additive (attr := simp)]
theorem lift_comp_of : (lift f).comp of = f := lift.symm_apply_apply f
@[to_additive (attr := simp)]
theorem lift_comp_of' (f : AssocQuotient α →ₙ* β) : lift (f.comp of) = f := lift.apply_symm_apply f
end lift
variable {β : Type v} [Mul β] (f : α →ₙ* β)
/-- From a magma homomorphism `α →ₙ* β` to a semigroup homomorphism
`Magma.AssocQuotient α →ₙ* Magma.AssocQuotient β`. -/
@[to_additive /-- From an additive magma homomorphism `α → β` to an additive semigroup homomorphism
`AddMagma.AssocQuotient α → AddMagma.AssocQuotient β`. -/]
def map : AssocQuotient α →ₙ* AssocQuotient β := lift (of.comp f)
@[to_additive (attr := simp)]
theorem map_of (x) : map f (of x) = of (f x) := rfl
end AssocQuotient
end Magma
/--
If `α` is a type, then `FreeAddSemigroup α` is the free additive semigroup generated by `α`.
This is an additive semigroup equipped with a function
`FreeAddSemigroup.of : α → FreeAddSemigroup α` which has the following universal property:
if `M` is any additive semigroup, and `f : α → M` is any function,
then this function is the composite of `FreeAddSemigroup.of` and a unique semigroup homomorphism
`FreeAddSemigroup.lift f : FreeAddSemigroup α →ₙ+ M`.
A typical element of `FreeAddSemigroup α` is a nonempty formal sum of elements of `α`.
For example if `x` and `y` are terms of type `α` then `x + y + y + x` is a
"typical" element of `FreeAddSemigroup α`. In particular if `α` is empty
then `FreeAddSemigroup α` is also empty, and if `α` has one term
then `FreeAddSemigroup α` is isomorphic to `ℕ+`.
If `α` has two or more terms then `FreeAddSemigroup α` is not commutative.
One can think of `FreeAddSemigroup α` as the type of nonempty lists of `α`, with addition
given by concatenation.
-/
structure FreeAddSemigroup (α : Type u) where
/-- The head of the element -/
head : α
/-- The tail of the element -/
tail : List α
compile_inductive% FreeAddSemigroup
/--
If `α` is a type, then `FreeSemigroup α` is the free semigroup generated by `α`.
This is a semigroup equipped with a function `FreeSemigroup.of : α → FreeSemigroup α` which has
the following universal property: if `M` is any semigroup, and `f : α → M` is any function,
then this function is the composite of `FreeSemigroup.of` and a unique semigroup homomorphism
`FreeSemigroup.lift f : FreeSemigroup α →ₙ* M`.
A typical element of `FreeSemigroup α` is a nonempty formal product of elements of `α`.
For example if `x` and `y` are terms of type `α` then `x * y * y * x` is a
"typical" element of `FreeSemigroup α`. In particular if `α` is empty
then `FreeSemigroup α` is also empty, and if `α` has one term
then `FreeSemigroup α` is isomorphic to `Multiplicative ℕ+`.
If `α` has two or more terms then `FreeSemigroup α` is not commutative.
One can think of `FreeSemigroup α` as the type of nonempty lists of `α`, with multiplication
given by concatenation.
-/
@[to_additive (attr := ext)]
structure FreeSemigroup (α : Type u) where
/-- The head of the element -/
head : α
/-- The tail of the element -/
tail : List α
compile_inductive% FreeSemigroup
namespace FreeSemigroup
variable {α : Type u}
@[to_additive]
instance : Semigroup (FreeSemigroup α) where
mul L1 L2 := ⟨L1.1, L1.2 ++ L2.1 :: L2.2⟩
mul_assoc _L1 _L2 _L3 := FreeSemigroup.ext rfl <| List.append_assoc _ _ _
@[to_additive (attr := simp)]
theorem head_mul (x y : FreeSemigroup α) : (x * y).1 = x.1 := rfl
@[to_additive (attr := simp)]
theorem tail_mul (x y : FreeSemigroup α) : (x * y).2 = x.2 ++ y.1 :: y.2 := rfl
@[to_additive (attr := simp)]
theorem mk_mul_mk (x y : α) (L1 L2 : List α) : mk x L1 * mk y L2 = mk x (L1 ++ y :: L2) := rfl
/-- The embedding `α → FreeSemigroup α`. -/
@[to_additive (attr := simps) /-- The embedding `α → FreeAddSemigroup α`. -/]
def of (x : α) : FreeSemigroup α := ⟨x, []⟩
/-- Length of an element of free semigroup. -/
@[to_additive /-- Length of an element of free additive semigroup -/]
def length (x : FreeSemigroup α) : ℕ := x.tail.length + 1
@[to_additive (attr := simp)]
theorem length_mul (x y : FreeSemigroup α) : (x * y).length = x.length + y.length := by
simp [length, Nat.add_right_comm, List.length, List.length_append]
@[to_additive (attr := simp)]
theorem length_of (x : α) : (of x).length = 1 := rfl
@[to_additive]
instance [Inhabited α] : Inhabited (FreeSemigroup α) := ⟨of default⟩
/-- Recursor for free semigroup using `of` and `*`. -/
@[to_additive (attr := elab_as_elim, induction_eliminator)
/-- Recursor for free additive semigroup using `of` and `+`. -/]
protected def recOnMul {C : FreeSemigroup α → Sort l} (x) (ih1 : ∀ x, C (of x))
(ih2 : ∀ x y, C (of x) → C y → C (of x * y)) : C x :=
FreeSemigroup.recOn x fun f s ↦
List.recOn s ih1 (fun hd tl ih f ↦ ih2 f ⟨hd, tl⟩ (ih1 f) (ih hd)) f
@[to_additive (attr := ext 1100)]
theorem hom_ext {β : Type v} [Mul β] {f g : FreeSemigroup α →ₙ* β} (h : f ∘ of = g ∘ of) : f = g :=
(DFunLike.ext _ _) fun x ↦
FreeSemigroup.recOnMul x (congr_fun h) fun x y hx hy ↦ by simp only [map_mul, *]
section lift
variable {β : Type v} [Semigroup β] (f : α → β)
/-- Lifts a function `α → β` to a semigroup homomorphism `FreeSemigroup α → β` given
a semigroup `β`. -/
@[to_additive (attr := simps symm_apply) /-- Lifts a function `α → β` to an additive semigroup
homomorphism `FreeAddSemigroup α → β` given an additive semigroup `β`. -/]
def lift : (α → β) ≃ (FreeSemigroup α →ₙ* β) where
toFun f :=
{ toFun := fun x ↦ x.2.foldl (fun a b ↦ a * f b) (f x.1)
map_mul' := fun x y ↦ by
simp [head_mul, tail_mul, ← List.foldl_map, List.foldl_append, List.foldl_cons,
List.foldl_assoc] }
invFun f := f ∘ of
@[to_additive (attr := simp)]
theorem lift_of (x : α) : lift f (of x) = f x := rfl
@[to_additive (attr := simp)]
theorem lift_comp_of : lift f ∘ of = f := rfl
@[to_additive (attr := simp)]
theorem lift_comp_of' (f : FreeSemigroup α →ₙ* β) : lift (f ∘ of) = f := hom_ext rfl
@[to_additive]
theorem lift_of_mul (x y) : lift f (of x * y) = f x * lift f y := by rw [map_mul, lift_of]
end lift
section Map
variable {β : Type v} (f : α → β)
/-- The unique semigroup homomorphism that sends `of x` to `of (f x)`. -/
@[to_additive /-- The unique additive semigroup homomorphism that sends `of x` to `of (f x)`. -/]
def map : FreeSemigroup α →ₙ* FreeSemigroup β :=
lift <| of ∘ f
@[to_additive (attr := simp)]
theorem map_of (x) : map f (of x) = of (f x) := rfl
@[to_additive (attr := simp)]
theorem length_map (x) : (map f x).length = x.length :=
FreeSemigroup.recOnMul x (fun _ ↦ rfl) (fun x y hx hy ↦ by simp only [map_mul, length_mul, *])
end Map
section Category
variable {β : Type u}
@[to_additive]
instance : Monad FreeSemigroup where
pure := of
bind x f := lift f x
/-- Recursor that uses `pure` instead of `of`. -/
@[to_additive (attr := elab_as_elim) /-- Recursor that uses `pure` instead of `of`. -/]
def recOnPure {C : FreeSemigroup α → Sort l} (x) (ih1 : ∀ x, C (pure x))
(ih2 : ∀ x y, C (pure x) → C y → C (pure x * y)) : C x :=
FreeSemigroup.recOnMul x ih1 ih2
@[to_additive (attr := simp)]
protected theorem map_pure (f : α → β) (x) : (f <$> pure x : FreeSemigroup β) = pure (f x) := rfl
@[to_additive (attr := simp)]
theorem map_mul' (f : α → β) (x y : FreeSemigroup α) : f <$> (x * y) = f <$> x * f <$> y :=
map_mul (map f) _ _
@[to_additive (attr := simp)]
theorem pure_bind (f : α → FreeSemigroup β) (x) : pure x >>= f = f x := rfl
@[to_additive (attr := simp)]
theorem mul_bind (f : α → FreeSemigroup β) (x y : FreeSemigroup α) :
x * y >>= f = (x >>= f) * (y >>= f) := map_mul (lift f) _ _
@[to_additive (attr := simp)]
theorem pure_seq {f : α → β} {x : FreeSemigroup α} : pure f <*> x = f <$> x := rfl
@[to_additive (attr := simp)]
theorem mul_seq {f g : FreeSemigroup (α → β)} {x : FreeSemigroup α} :
f * g <*> x = (f <*> x) * (g <*> x) := mul_bind _ _ _
@[to_additive]
instance instLawfulMonad : LawfulMonad FreeSemigroup.{u} := LawfulMonad.mk'
(pure_bind := fun _ _ ↦ rfl)
(bind_assoc := fun x g f ↦
recOnPure x (fun _ ↦ rfl) fun x y ih1 ih2 ↦ by rw [mul_bind, mul_bind, mul_bind, ih1, ih2])
(id_map := fun x ↦ recOnPure x (fun _ ↦ rfl) fun x y ih1 ih2 ↦ by rw [map_mul', ih1, ih2])
/-- `FreeSemigroup` is traversable. -/
@[to_additive /-- `FreeAddSemigroup` is traversable. -/]
protected def traverse {m : Type u → Type u} [Applicative m] {α β : Type u}
(F : α → m β) (x : FreeSemigroup α) : m (FreeSemigroup β) :=
recOnPure x (fun x ↦ pure <$> F x) fun _x _y ihx ihy ↦ (· * ·) <$> ihx <*> ihy
@[to_additive]
instance : Traversable FreeSemigroup := ⟨@FreeSemigroup.traverse⟩
variable {m : Type u → Type u} [Applicative m] (F : α → m β)
@[to_additive (attr := simp)]
theorem traverse_pure (x) : traverse F (pure x : FreeSemigroup α) = pure <$> F x := rfl
@[to_additive (attr := simp)]
theorem traverse_pure' : traverse F ∘ pure = fun x ↦ (pure <$> F x : m (FreeSemigroup β)) := rfl
section
variable [LawfulApplicative m]
@[to_additive (attr := simp)]
theorem traverse_mul (x y : FreeSemigroup α) :
traverse F (x * y) = (· * ·) <$> traverse F x <*> traverse F y :=
let ⟨x, L1⟩ := x
let ⟨y, L2⟩ := y
List.recOn L1 (fun _ ↦ rfl)
(fun hd tl ih x ↦ show
(· * ·) <$> pure <$> F x <*> traverse F (mk hd tl * mk y L2) =
(· * ·) <$> ((· * ·) <$> pure <$> F x <*> traverse F (mk hd tl)) <*> traverse F (mk y L2)
by rw [ih]; simp only [Function.comp_def, (mul_assoc _ _ _).symm, functor_norm])
x
@[to_additive (attr := simp)]
theorem traverse_mul' :
Function.comp (traverse F) ∘ (HMul.hMul : FreeSemigroup α → FreeSemigroup α → FreeSemigroup α) =
fun x y ↦ (· * ·) <$> traverse F x <*> traverse F y :=
funext fun x ↦ funext fun y ↦ traverse_mul F x y
end
@[to_additive (attr := simp)]
theorem traverse_eq (x) : FreeSemigroup.traverse F x = traverse F x := rfl
@[to_additive (attr := deprecated "Use map_pure and seq_pure" (since := "2025-05-21"))]
theorem mul_map_seq (x y : FreeSemigroup α) :
((· * ·) <$> x <*> y : Id (FreeSemigroup α)) = (x * y : FreeSemigroup α) := rfl
@[to_additive]
instance : LawfulTraversable FreeSemigroup.{u} :=
{ instLawfulMonad with
id_traverse := fun x ↦
FreeSemigroup.recOnMul x (fun _ ↦ rfl) fun x y ih1 ih2 ↦ by
rw [traverse_mul, ih1, ih2, seq_pure, map_pure, map_pure]
comp_traverse := fun f g x ↦
recOnPure x (fun x ↦ by simp only [traverse_pure, functor_norm, Function.comp_def])
fun x y ih1 ih2 ↦ by
rw [traverse_mul, ih1, ih2, traverse_mul, Functor.Comp.map_mk]
simp only [Function.comp_def, functor_norm, traverse_mul]
naturality := fun η α β f x ↦
recOnPure x (fun x ↦ by simp only [traverse_pure, functor_norm, Function.comp])
(fun x y ih1 ih2 ↦ by simp only [traverse_mul, functor_norm, ih1, ih2])
traverse_eq_map_id := fun f x ↦
FreeSemigroup.recOnMul x (fun _ ↦ rfl) fun x y ih1 ih2 ↦ by
rw [traverse_mul, ih1, ih2, map_mul', map_pure, seq_pure, map_pure] }
end Category
@[to_additive]
instance [DecidableEq α] : DecidableEq (FreeSemigroup α) :=
fun _ _ ↦ decidable_of_iff' _ FreeSemigroup.ext_iff
end FreeSemigroup
namespace FreeMagma
variable {α : Type u} {β : Type v}
/-- The canonical multiplicative morphism from `FreeMagma α` to `FreeSemigroup α`. -/
@[to_additive /-- The canonical additive morphism from `FreeAddMagma α` to `FreeAddSemigroup α`. -/]
def toFreeSemigroup : FreeMagma α →ₙ* FreeSemigroup α := FreeMagma.lift FreeSemigroup.of
@[to_additive (attr := simp)]
theorem toFreeSemigroup_of (x : α) : toFreeSemigroup (of x) = FreeSemigroup.of x := rfl
@[to_additive (attr := simp)]
theorem toFreeSemigroup_comp_of : @toFreeSemigroup α ∘ of = FreeSemigroup.of := rfl
@[to_additive]
theorem toFreeSemigroup_comp_map (f : α → β) :
toFreeSemigroup.comp (map f) = (FreeSemigroup.map f).comp toFreeSemigroup := by ext1; rfl
@[to_additive]
theorem toFreeSemigroup_map (f : α → β) (x : FreeMagma α) :
toFreeSemigroup (map f x) = FreeSemigroup.map f (toFreeSemigroup x) :=
DFunLike.congr_fun (toFreeSemigroup_comp_map f) x
@[to_additive (attr := simp)]
theorem length_toFreeSemigroup (x : FreeMagma α) : (toFreeSemigroup x).length = x.length :=
FreeMagma.recOnMul x (fun _ ↦ rfl) fun x y hx hy ↦ by
rw [map_mul, FreeSemigroup.length_mul, hx, hy]; rfl
end FreeMagma
/-- Isomorphism between `Magma.AssocQuotient (FreeMagma α)` and `FreeSemigroup α`. -/
@[to_additive /-- Isomorphism between `AddMagma.AssocQuotient (FreeAddMagma α)` and
`FreeAddSemigroup α`. -/]
def FreeMagmaAssocQuotientEquiv (α : Type u) :
Magma.AssocQuotient (FreeMagma α) ≃* FreeSemigroup α :=
(Magma.AssocQuotient.lift FreeMagma.toFreeSemigroup).toMulEquiv
(FreeSemigroup.lift (Magma.AssocQuotient.of ∘ FreeMagma.of))
(by ext; rfl)
(by ext1; rfl) |
.lake/packages/mathlib/Mathlib/Algebra/QuadraticAlgebra.lean | import Mathlib.Algebra.QuadraticAlgebra.Defs
deprecated_module (since := "2025-11-10") |
.lake/packages/mathlib/Mathlib/Algebra/DualNumber.lean | import Mathlib.Algebra.TrivSqZeroExt
/-!
# Dual numbers
The dual numbers over `R` are of the form `a + bε`, where `a` and `b` are typically elements of a
commutative ring `R`, and `ε` is a symbol satisfying `ε^2 = 0` that commutes with every other
element. They are a special case of `TrivSqZeroExt R M` with `M = R`.
## Notation
In the `DualNumber` locale:
* `R[ε]` is a shorthand for `DualNumber R`
* `ε` is a shorthand for `DualNumber.eps`
## Main definitions
* `DualNumber`
* `DualNumber.eps`
* `DualNumber.lift`
## Implementation notes
Rather than duplicating the API of `TrivSqZeroExt`, this file reuses the functions there.
## References
* https://en.wikipedia.org/wiki/Dual_number
-/
variable {R A B : Type*}
/-- The type of dual numbers, numbers of the form $a + bε$ where $ε^2 = 0$.
`R[ε]` is notation for `DualNumber R`. -/
abbrev DualNumber (R : Type*) : Type _ :=
TrivSqZeroExt R R
/-- The unit element $ε$ that squares to zero, with notation `ε`. -/
def DualNumber.eps [Zero R] [One R] : DualNumber R :=
TrivSqZeroExt.inr 1
@[inherit_doc]
scoped[DualNumber] notation "ε" => DualNumber.eps
@[inherit_doc]
scoped[DualNumber] postfix:1024 "[ε]" => DualNumber
open DualNumber
namespace DualNumber
open TrivSqZeroExt
@[simp]
theorem fst_eps [Zero R] [One R] : fst ε = (0 : R) :=
rfl
@[simp]
theorem snd_eps [Zero R] [One R] : snd ε = (1 : R) :=
rfl
/-- A version of `TrivSqZeroExt.snd_mul` with `*` instead of `•`. -/
@[simp]
theorem snd_mul [Semiring R] (x y : R[ε]) : snd (x * y) = fst x * snd y + snd x * fst y :=
rfl
@[simp]
theorem eps_mul_eps [Semiring R] : (ε * ε : R[ε]) = 0 :=
inr_mul_inr _ _ _
@[simp]
theorem inv_eps [DivisionRing R] : (ε : R[ε])⁻¹ = 0 :=
TrivSqZeroExt.inv_inr 1
@[simp]
theorem inr_eq_smul_eps [MulZeroOneClass R] (r : R) : inr r = (r • ε : R[ε]) :=
ext (mul_zero r).symm (mul_one r).symm
/-- `ε` commutes with every element of the algebra. -/
theorem commute_eps_left [Semiring R] (x : DualNumber R) : Commute ε x := by
ext <;> simp
/-- `ε` commutes with every element of the algebra. -/
theorem commute_eps_right [Semiring R] (x : DualNumber R) : Commute x ε := (commute_eps_left x).symm
variable {A : Type*} [CommSemiring R] [Semiring A] [Semiring B] [Algebra R A] [Algebra R B]
/-- For two `R`-algebra morphisms out of `A[ε]` to agree, it suffices for them to agree on the
elements of `A` and the `A`-multiples of `ε`. -/
@[ext 1100]
nonrec theorem algHom_ext' ⦃f g : A[ε] →ₐ[R] B⦄
(hinl : f.comp (inlAlgHom _ _ _) = g.comp (inlAlgHom _ _ _))
(hinr : f.toLinearMap ∘ₗ (LinearMap.toSpanSingleton A A[ε] ε).restrictScalars R =
g.toLinearMap ∘ₗ (LinearMap.toSpanSingleton A A[ε] ε).restrictScalars R) :
f = g :=
algHom_ext' hinl (by
ext a
change f (inr a) = g (inr a)
simpa only [inr_eq_smul_eps] using DFunLike.congr_fun hinr a)
/-- For two `R`-algebra morphisms out of `R[ε]` to agree, it suffices for them to agree on `ε`. -/
@[ext 1200]
theorem algHom_ext ⦃f g : R[ε] →ₐ[R] A⦄ (hε : f ε = g ε) : f = g := by
ext
dsimp
simp only [one_smul, hε]
/-- A universal property of the dual numbers, providing a unique `A[ε] →ₐ[R] B` for every map
`f : A →ₐ[R] B` and a choice of element `e : B` which squares to `0` and commutes with the range of
`f`.
This isomorphism is named to match the similar `Complex.lift`.
Note that when `f : R →ₐ[R] B := Algebra.ofId R B`, the commutativity assumption is automatic, and
we are free to choose any element `e : B`. -/
def lift :
{fe : (A →ₐ[R] B) × B // fe.2 * fe.2 = 0 ∧ ∀ a, Commute fe.2 (fe.1 a)} ≃ (A[ε] →ₐ[R] B) := by
refine Equiv.trans ?_ TrivSqZeroExt.liftEquiv
exact {
toFun := fun fe => ⟨
(fe.val.1, MulOpposite.op fe.val.2 • fe.val.1.toLinearMap),
fun x y => show (fe.val.1 x * fe.val.2) * (fe.val.1 y * fe.val.2) = 0 by
rw [(fe.prop.2 _).mul_mul_mul_comm, fe.prop.1, mul_zero],
fun r x => show fe.val.1 (r * x) * fe.val.2 = fe.val.1 r * (fe.val.1 x * fe.val.2) by
rw [map_mul, mul_assoc],
fun r x => show fe.val.1 (x * r) * fe.val.2 = (fe.val.1 x * fe.val.2) * fe.val.1 r by
rw [map_mul, (fe.prop.2 _).right_comm]⟩
invFun := fun fg => ⟨
(fg.val.1, fg.val.2 1),
fg.prop.1 _ _,
fun a => show fg.val.2 1 * fg.val.1 a = fg.val.1 a * fg.val.2 1 by
rw [← fg.prop.2.1, ← fg.prop.2.2, smul_eq_mul, op_smul_eq_mul, mul_one, one_mul]⟩
left_inv := fun fe => Subtype.ext <| Prod.ext rfl <|
show fe.val.1 1 * fe.val.2 = fe.val.2 by
rw [map_one, one_mul]
right_inv := fun fg => Subtype.ext <| Prod.ext rfl <| LinearMap.ext fun x =>
show fg.val.1 x * fg.val.2 1 = fg.val.2 x by
rw [← fg.prop.2.1, smul_eq_mul, mul_one] }
theorem lift_apply_apply (fe : {_fe : (A →ₐ[R] B) × B // _}) (a : A[ε]) :
lift fe a = fe.val.1 a.fst + fe.val.1 a.snd * fe.val.2 := rfl
@[simp] theorem coe_lift_symm_apply (F : A[ε] →ₐ[R] B) :
(lift.symm F).val = (F.comp (inlAlgHom _ _ _), F ε) := rfl
/-- When applied to `inl`, `DualNumber.lift` applies the map `f : A →ₐ[R] B`. -/
@[simp] theorem lift_apply_inl (fe : {_fe : (A →ₐ[R] B) × B // _}) (a : A) :
lift fe (inl a : A[ε]) = fe.val.1 a := by
rw [lift_apply_apply, fst_inl, snd_inl, map_zero, zero_mul, add_zero]
@[simp] theorem lift_comp_inlHom (fe : {_fe : (A →ₐ[R] B) × B // _}) :
(lift fe).comp (inlAlgHom R A A) = fe.val.1 :=
AlgHom.ext <| lift_apply_inl fe
/-- Scaling on the left is sent by `DualNumber.lift` to multiplication on the left -/
@[simp] theorem lift_smul (fe : {_fe : (A →ₐ[R] B) × B // _}) (a : A) (ad : A[ε]) :
lift fe (a • ad) = fe.val.1 a * lift fe ad := by
rw [← inl_mul_eq_smul, map_mul, lift_apply_inl]
/-- Scaling on the right is sent by `DualNumber.lift` to multiplication on the right -/
@[simp] theorem lift_op_smul (fe : {_fe : (A →ₐ[R] B) × B // _}) (a : A) (ad : A[ε]) :
lift fe (MulOpposite.op a • ad) = lift fe ad * fe.val.1 a := by
rw [← mul_inl_eq_op_smul, map_mul, lift_apply_inl]
/-- When applied to `ε`, `DualNumber.lift` produces the element of `B` that squares to 0. -/
@[simp] theorem lift_apply_eps
(fe : {fe : (A →ₐ[R] B) × B // fe.2 * fe.2 = 0 ∧ ∀ a, Commute fe.2 (fe.1 a)}) :
lift fe (ε : A[ε]) = fe.val.2 := by
simp only [lift_apply_apply, fst_eps, map_zero, snd_eps, map_one, one_mul, zero_add]
/-- Lifting `DualNumber.eps` itself gives the identity. -/
@[simp]
theorem lift_inlAlgHom_eps :
lift ⟨(inlAlgHom _ _ _, ε), eps_mul_eps, fun _ => commute_eps_left _⟩ = AlgHom.id R A[ε] :=
lift.apply_symm_apply <| AlgHom.id R A[ε]
@[simp]
theorem range_inlAlgHom_sup_adjoin_eps :
(inlAlgHom R A A).range ⊔ Algebra.adjoin R {ε} = ⊤ := by
refine top_unique fun x hx => ?_; clear hx
rw [← x.inl_fst_add_inr_snd_eq, inr_eq_smul_eps, ← inl_mul_eq_smul]
refine add_mem ?_ (mul_mem ?_ ?_)
· exact le_sup_left (α := Subalgebra R _) <| Set.mem_range_self x.fst
· exact le_sup_left (α := Subalgebra R _) <| Set.mem_range_self x.snd
· refine le_sup_right (α := Subalgebra R _) <| Algebra.subset_adjoin <| Set.mem_singleton ε
@[simp]
theorem range_lift
(fe : {fe : (A →ₐ[R] B) × B // fe.2 * fe.2 = 0 ∧ ∀ a, Commute fe.2 (fe.1 a)}) :
(lift fe).range = fe.1.1.range ⊔ Algebra.adjoin R {fe.1.2} := by
simp_rw [← Algebra.map_top, ← range_inlAlgHom_sup_adjoin_eps, Algebra.map_sup,
AlgHom.map_adjoin, ← AlgHom.range_comp, Set.image_singleton, lift_apply_eps, lift_comp_inlHom,
Algebra.map_top]
/-- Show DualNumber with values x and y as an "x + y*ε" string -/
instance instRepr [Repr R] : Repr (DualNumber R) where
reprPrec f p :=
(if p > 65 then (Std.Format.bracket "(" · ")") else (·)) <|
reprPrec f.fst 65 ++ " + " ++ reprPrec f.snd 70 ++ "*ε"
end DualNumber |
.lake/packages/mathlib/Mathlib/Algebra/FreeAlgebra.lean | import Mathlib.Algebra.Algebra.Subalgebra.Basic
import Mathlib.Algebra.Algebra.Subalgebra.Lattice
import Mathlib.Algebra.FreeMonoid.UniqueProds
import Mathlib.Algebra.MonoidAlgebra.Basic
import Mathlib.Algebra.MonoidAlgebra.NoZeroDivisors
/-!
# Free Algebras
Given a commutative semiring `R`, and a type `X`, we construct the free unital, associative
`R`-algebra on `X`.
## Notation
1. `FreeAlgebra R X` is the free algebra itself. It is endowed with an `R`-algebra structure.
2. `FreeAlgebra.ι R` is the function `X → FreeAlgebra R X`.
3. Given a function `f : X → A` to an R-algebra `A`, `lift R f` is the lift of `f` to an
`R`-algebra morphism `FreeAlgebra R X → A`.
## Theorems
1. `ι_comp_lift` states that the composition `(lift R f) ∘ (ι R)` is identical to `f`.
2. `lift_unique` states that whenever an R-algebra morphism `g : FreeAlgebra R X → A` is
given whose composition with `ι R` is `f`, then one has `g = lift R f`.
3. `hom_ext` is a variant of `lift_unique` in the form of an extensionality theorem.
4. `lift_comp_ι` is a combination of `ι_comp_lift` and `lift_unique`. It states that the lift
of the composition of an algebra morphism with `ι` is the algebra morphism itself.
5. `equivMonoidAlgebraFreeMonoid : FreeAlgebra R X ≃ₐ[R] MonoidAlgebra R (FreeMonoid X)`
6. An inductive principle `induction`.
## Implementation details
We construct the free algebra on `X` as a quotient of an inductive type `FreeAlgebra.Pre` by an
inductively defined relation `FreeAlgebra.Rel`. Explicitly, the construction involves three steps:
1. We construct an inductive type `FreeAlgebra.Pre R X`, the terms of which should be thought
of as representatives for the elements of `FreeAlgebra R X`.
It is the free type with maps from `R` and `X`, and with two binary operations `add` and `mul`.
2. We construct an inductive relation `FreeAlgebra.Rel R X` on `FreeAlgebra.Pre R X`.
This is the smallest relation for which the quotient is an `R`-algebra where addition resp.
multiplication are induced by `add` resp. `mul` from 1., and for which the map from `R` is the
structure map for the algebra.
3. The free algebra `FreeAlgebra R X` is the quotient of `FreeAlgebra.Pre R X` by
the relation `FreeAlgebra.Rel R X`.
-/
variable (R : Type*) [CommSemiring R]
variable (X : Type*)
namespace FreeAlgebra
/-- This inductive type is used to express representatives of the free algebra.
-/
inductive Pre
| of : X → Pre
| ofScalar : R → Pre
| add : Pre → Pre → Pre
| mul : Pre → Pre → Pre
namespace Pre
instance : Inhabited (Pre R X) := ⟨ofScalar 0⟩
-- Note: These instances are only used to simplify the notation.
/-- Coercion from `X` to `Pre R X`. Note: Used for notation only. -/
def hasCoeGenerator : Coe X (Pre R X) := ⟨of⟩
/-- Coercion from `R` to `Pre R X`. Note: Used for notation only. -/
def hasCoeSemiring : Coe R (Pre R X) := ⟨ofScalar⟩
/-- Multiplication in `Pre R X` defined as `Pre.mul`. Note: Used for notation only. -/
def hasMul : Mul (Pre R X) := ⟨mul⟩
/-- Addition in `Pre R X` defined as `Pre.add`. Note: Used for notation only. -/
def hasAdd : Add (Pre R X) := ⟨add⟩
/-- Zero in `Pre R X` defined as the image of `0` from `R`. Note: Used for notation only. -/
def hasZero : Zero (Pre R X) := ⟨ofScalar 0⟩
/-- One in `Pre R X` defined as the image of `1` from `R`. Note: Used for notation only. -/
def hasOne : One (Pre R X) := ⟨ofScalar 1⟩
/-- Scalar multiplication defined as multiplication by the image of elements from `R`.
Note: Used for notation only.
-/
def hasSMul : SMul R (Pre R X) := ⟨fun r m ↦ mul (ofScalar r) m⟩
end Pre
attribute [local instance] Pre.hasCoeGenerator Pre.hasCoeSemiring Pre.hasMul Pre.hasAdd
Pre.hasZero Pre.hasOne Pre.hasSMul
/-- Given a function from `X` to an `R`-algebra `A`, `lift_fun` provides a lift of `f` to a function
from `Pre R X` to `A`. This is mainly used in the construction of `FreeAlgebra.lift`. -/
def liftFun {A : Type*} [Semiring A] [Algebra R A] (f : X → A) :
Pre R X → A
| .of t => f t
| .add a b => liftFun f a + liftFun f b
| .mul a b => liftFun f a * liftFun f b
| .ofScalar c => algebraMap _ _ c
/-- An inductively defined relation on `Pre R X` used to force the initial algebra structure on
the associated quotient.
-/
inductive Rel : Pre R X → Pre R X → Prop
-- force `ofScalar` to be a central semiring morphism
| add_scalar {r s : R} : Rel (↑(r + s)) (↑r + ↑s)
| mul_scalar {r s : R} : Rel (↑(r * s)) (↑r * ↑s)
| central_scalar {r : R} {a : Pre R X} : Rel (r * a) (a * r)
-- commutative additive semigroup
| add_assoc {a b c : Pre R X} : Rel (a + b + c) (a + (b + c))
| add_comm {a b : Pre R X} : Rel (a + b) (b + a)
| zero_add {a : Pre R X} : Rel (0 + a) a
-- multiplicative monoid
| mul_assoc {a b c : Pre R X} : Rel (a * b * c) (a * (b * c))
| one_mul {a : Pre R X} : Rel (1 * a) a
| mul_one {a : Pre R X} : Rel (a * 1) a
-- distributivity
| left_distrib {a b c : Pre R X} : Rel (a * (b + c)) (a * b + a * c)
| right_distrib {a b c : Pre R X} :
Rel ((a + b) * c) (a * c + b * c)
-- other relations needed for semiring
| zero_mul {a : Pre R X} : Rel (0 * a) 0
| mul_zero {a : Pre R X} : Rel (a * 0) 0
-- compatibility
| add_compat_left {a b c : Pre R X} : Rel a b → Rel (a + c) (b + c)
| add_compat_right {a b c : Pre R X} : Rel a b → Rel (c + a) (c + b)
| mul_compat_left {a b c : Pre R X} : Rel a b → Rel (a * c) (b * c)
| mul_compat_right {a b c : Pre R X} : Rel a b → Rel (c * a) (c * b)
end FreeAlgebra
/--
If `α` is a type, and `R` is a commutative semiring, then `FreeAlgebra R α` is the
free (unital, associative) `R`-algebra generated by `α`.
This is an `R`-algebra equipped with a function `FreeAlgebra.ι R : α → FreeAlgebra R α` which has
the following universal property: if `A` is any `R`-algebra, and `f : α → A` is any function,
then this function is the composite of `FreeAlgebra.ι R` and a unique `R`-algebra homomorphism
`FreeAlgebra.lift R f : FreeAlgebra R α →ₐ[R] A`.
A typical element of `FreeAlgebra R α` is an `R`-linear
combination of formal products of elements of `α`.
For example if `x` and `y` are terms of type `α` and `a`, `b` are terms of type `R` then
`(3 * a * a) • (x * y * x) + (2 * b + 1) • (y * x) + (a * b * b + 3)` is a
"typical" element of `FreeAlgebra R α`. In particular if `α` is empty
then `FreeAlgebra R α` is isomorphic to `R`, and if `α` has one term `t`
then `FreeAlgebra R α` is isomorphic to the polynomial ring `R[t]`.
If `α` has two or more terms then `FreeAlgebra R α` is not commutative.
One can think of `FreeAlgebra R α` as the free non-commutative polynomial ring
with coefficients in `R` and variables indexed by `α`.
-/
def FreeAlgebra :=
Quot (FreeAlgebra.Rel R X)
namespace FreeAlgebra
attribute [local instance] Pre.hasCoeGenerator Pre.hasCoeSemiring Pre.hasMul Pre.hasAdd
Pre.hasZero Pre.hasOne Pre.hasSMul
/-! Define the basic operations -/
instance instSMul {A} [CommSemiring A] [Algebra R A] : SMul R (FreeAlgebra A X) where
smul r := Quot.map (HMul.hMul (algebraMap R A r : Pre A X)) fun _ _ ↦ Rel.mul_compat_right
instance instZero : Zero (FreeAlgebra R X) where zero := Quot.mk _ 0
instance instOne : One (FreeAlgebra R X) where one := Quot.mk _ 1
instance instAdd : Add (FreeAlgebra R X) where
add := Quot.map₂ HAdd.hAdd (fun _ _ _ ↦ Rel.add_compat_right) fun _ _ _ ↦ Rel.add_compat_left
instance instMul : Mul (FreeAlgebra R X) where
mul := Quot.map₂ HMul.hMul (fun _ _ _ ↦ Rel.mul_compat_right) fun _ _ _ ↦ Rel.mul_compat_left
-- `Quot.mk` is an implementation detail of `FreeAlgebra`, so this lemma is private
private theorem mk_mul (x y : Pre R X) :
Quot.mk (Rel R X) (x * y) = (HMul.hMul (self := instHMul (α := FreeAlgebra R X))
(Quot.mk (Rel R X) x) (Quot.mk (Rel R X) y)) :=
rfl
/-! Build the semiring structure. We do this one piece at a time as this is convenient for proving
the `nsmul` fields. -/
instance instMonoidWithZero : MonoidWithZero (FreeAlgebra R X) where
mul_assoc := by
rintro ⟨⟩ ⟨⟩ ⟨⟩
exact Quot.sound Rel.mul_assoc
one := Quot.mk _ 1
one_mul := by
rintro ⟨⟩
exact Quot.sound Rel.one_mul
mul_one := by
rintro ⟨⟩
exact Quot.sound Rel.mul_one
zero_mul := by
rintro ⟨⟩
exact Quot.sound Rel.zero_mul
mul_zero := by
rintro ⟨⟩
exact Quot.sound Rel.mul_zero
instance instDistrib : Distrib (FreeAlgebra R X) where
left_distrib := by
rintro ⟨⟩ ⟨⟩ ⟨⟩
exact Quot.sound Rel.left_distrib
right_distrib := by
rintro ⟨⟩ ⟨⟩ ⟨⟩
exact Quot.sound Rel.right_distrib
instance instAddCommMonoid : AddCommMonoid (FreeAlgebra R X) where
add_assoc := by
rintro ⟨⟩ ⟨⟩ ⟨⟩
exact Quot.sound Rel.add_assoc
zero_add := by
rintro ⟨⟩
exact Quot.sound Rel.zero_add
add_zero := by
rintro ⟨⟩
change Quot.mk _ _ = _
rw [Quot.sound Rel.add_comm, Quot.sound Rel.zero_add]
add_comm := by
rintro ⟨⟩ ⟨⟩
exact Quot.sound Rel.add_comm
nsmul := (· • ·)
nsmul_zero := by
rintro ⟨⟩
change Quot.mk _ (_ * _) = _
rw [map_zero]
exact Quot.sound Rel.zero_mul
nsmul_succ n := by
rintro ⟨a⟩
dsimp only [HSMul.hSMul, instSMul, Quot.map]
rw [map_add, map_one, mk_mul, mk_mul, ← add_one_mul (_ : FreeAlgebra R X)]
congr 1
exact Quot.sound Rel.add_scalar
instance : Semiring (FreeAlgebra R X) where
__ := instMonoidWithZero R X
__ := instAddCommMonoid R X
__ := instDistrib R X
natCast n := Quot.mk _ (n : R)
natCast_zero := by simp; rfl
natCast_succ n := by simpa using Quot.sound Rel.add_scalar
instance : Inhabited (FreeAlgebra R X) :=
⟨0⟩
instance instAlgebra {A} [CommSemiring A] [Algebra R A] : Algebra R (FreeAlgebra A X) where
algebraMap := ({
toFun := fun r => Quot.mk _ r
map_one' := rfl
map_mul' := fun _ _ => Quot.sound Rel.mul_scalar
map_zero' := rfl
map_add' := fun _ _ => Quot.sound Rel.add_scalar } : A →+* FreeAlgebra A X).comp
(algebraMap R A)
commutes' _ := by
rintro ⟨⟩
exact Quot.sound Rel.central_scalar
smul_def' _ _ := rfl
-- verify there is no diamond at `default` transparency but we will need
-- `reducible_and_instances` which currently fails https://github.com/leanprover-community/mathlib4/issues/10906
variable (S : Type) [CommSemiring S] in
example : (Semiring.toNatAlgebra : Algebra ℕ (FreeAlgebra S X)) = instAlgebra _ _ := rfl
instance {R S A} [CommSemiring R] [CommSemiring S] [CommSemiring A]
[SMul R S] [Algebra R A] [Algebra S A] [IsScalarTower R S A] :
IsScalarTower R S (FreeAlgebra A X) where
smul_assoc r s x := by
change algebraMap S A (r • s) • x = algebraMap R A _ • (algebraMap S A _ • x)
rw [← smul_assoc]
congr
simp only [Algebra.algebraMap_eq_smul_one, smul_eq_mul]
rw [smul_assoc, ← smul_one_mul]
instance {R S A} [CommSemiring R] [CommSemiring S] [CommSemiring A] [Algebra R A] [Algebra S A] :
SMulCommClass R S (FreeAlgebra A X) where
smul_comm r s x := smul_comm (algebraMap R A r) (algebraMap S A s) x
instance {S : Type*} [CommRing S] : Ring (FreeAlgebra S X) :=
Algebra.semiringToRing S
-- verify there is no diamond but we will need
-- `reducible_and_instances` which currently fails https://github.com/leanprover-community/mathlib4/issues/10906
variable (S : Type) [CommRing S] in
example : (Ring.toIntAlgebra _ : Algebra ℤ (FreeAlgebra S X)) = instAlgebra _ _ := rfl
variable {X}
/-- The canonical function `X → FreeAlgebra R X`.
-/
irreducible_def ι : X → FreeAlgebra R X := fun m ↦ Quot.mk _ m
@[simp]
theorem quot_mk_eq_ι (m : X) : Quot.mk (FreeAlgebra.Rel R X) m = ι R m := by rw [ι_def]
variable {A : Type*} [Semiring A] [Algebra R A]
/-- Internal definition used to define `lift` -/
private def liftAux (f : X → A) : FreeAlgebra R X →ₐ[R] A where
toFun a :=
Quot.liftOn a (liftFun _ _ f) fun a b h ↦ by
induction h
· exact (algebraMap R A).map_add _ _
· exact (algebraMap R A).map_mul _ _
· apply Algebra.commutes
· change _ + _ + _ = _ + (_ + _)
rw [add_assoc]
· change _ + _ = _ + _
rw [add_comm]
· change algebraMap _ _ _ + liftFun R X f _ = liftFun R X f _
simp
· change _ * _ * _ = _ * (_ * _)
rw [mul_assoc]
· change algebraMap _ _ _ * liftFun R X f _ = liftFun R X f _
simp
· change liftFun R X f _ * algebraMap _ _ _ = liftFun R X f _
simp
· change _ * (_ + _) = _ * _ + _ * _
rw [left_distrib]
· change (_ + _) * _ = _ * _ + _ * _
rw [right_distrib]
· change algebraMap _ _ _ * _ = algebraMap _ _ _
simp
· change _ * algebraMap _ _ _ = algebraMap _ _ _
simp
repeat
change liftFun R X f _ + liftFun R X f _ = _
simp only [*]
rfl
repeat
change liftFun R X f _ * liftFun R X f _ = _
simp only [*]
rfl
map_one' := by
change algebraMap _ _ _ = _
simp
map_mul' := by
rintro ⟨⟩ ⟨⟩
rfl
map_zero' := by
change algebraMap _ _ _ = _
simp
map_add' := by
rintro ⟨⟩ ⟨⟩
rfl
commutes' := by tauto
/-- Given a function `f : X → A` where `A` is an `R`-algebra, `lift R f` is the unique lift
of `f` to a morphism of `R`-algebras `FreeAlgebra R X → A`. -/
@[irreducible]
def lift : (X → A) ≃ (FreeAlgebra R X →ₐ[R] A) :=
{ toFun := liftAux R
invFun := fun F ↦ F ∘ ι R
left_inv := fun f ↦ by
ext
simp only [Function.comp_apply, ι_def]
rfl
right_inv := fun F ↦ by
ext t
rcases t with ⟨x⟩
induction x with
| of =>
change ((F : FreeAlgebra R X → A) ∘ ι R) _ = _
simp only [Function.comp_apply, ι_def]
| ofScalar x =>
change algebraMap _ _ x = F (algebraMap _ _ x)
rw [AlgHom.commutes F _]
| add a b ha hb =>
-- Porting note: it is necessary to declare fa and fb explicitly otherwise Lean refuses
-- to consider `Quot.mk (Rel R X) ·` as element of FreeAlgebra R X
let fa : FreeAlgebra R X := Quot.mk (Rel R X) a
let fb : FreeAlgebra R X := Quot.mk (Rel R X) b
change liftAux R (F ∘ ι R) (fa + fb) = F (fa + fb)
grind
| mul a b ha hb =>
let fa : FreeAlgebra R X := Quot.mk (Rel R X) a
let fb : FreeAlgebra R X := Quot.mk (Rel R X) b
change liftAux R (F ∘ ι R) (fa * fb) = F (fa * fb)
grind }
@[simp]
theorem liftAux_eq (f : X → A) : liftAux R f = lift R f := by
rw [lift]
rfl
@[simp]
theorem lift_symm_apply (F : FreeAlgebra R X →ₐ[R] A) : (lift R).symm F = F ∘ ι R := by
rw [lift]
rfl
variable {R}
@[simp]
theorem ι_comp_lift (f : X → A) : (lift R f : FreeAlgebra R X → A) ∘ ι R = f := by
ext
rw [Function.comp_apply, ι_def, lift]
rfl
@[simp]
theorem lift_ι_apply (f : X → A) (x) : lift R f (ι R x) = f x := by
rw [ι_def, lift]
rfl
@[simp]
theorem lift_unique (f : X → A) (g : FreeAlgebra R X →ₐ[R] A) :
(g : FreeAlgebra R X → A) ∘ ι R = f ↔ g = lift R f := by
rw [← (lift R).symm_apply_eq, lift]
rfl
/-!
Since we have set the basic definitions as `@[Irreducible]`, from this point onwards one
should only use the universal properties of the free algebra, and consider the actual implementation
as a quotient of an inductive type as completely hidden. -/
-- Marking `FreeAlgebra` irreducible makes `Ring` instances inaccessible on quotients.
-- https://leanprover.zulipchat.com/#narrow/stream/113488-general/topic/algebra.2Esemiring_to_ring.20breaks.20semimodule.20typeclass.20lookup/near/212580241
-- For now, we avoid this by not marking it irreducible.
@[simp]
theorem lift_comp_ι (g : FreeAlgebra R X →ₐ[R] A) :
lift R ((g : FreeAlgebra R X → A) ∘ ι R) = g := by
rw [← lift_symm_apply]
exact (lift R).apply_symm_apply g
/-- See note [partially-applied ext lemmas]. -/
@[ext high]
theorem hom_ext {f g : FreeAlgebra R X →ₐ[R] A}
(w : (f : FreeAlgebra R X → A) ∘ ι R = (g : FreeAlgebra R X → A) ∘ ι R) : f = g := by
rw [← lift_symm_apply, ← lift_symm_apply] at w
exact (lift R).symm.injective w
/-- The free algebra on `X` is "just" the monoid algebra on the free monoid on `X`.
This would be useful when constructing linear maps out of a free algebra,
for example.
-/
noncomputable def equivMonoidAlgebraFreeMonoid :
FreeAlgebra R X ≃ₐ[R] MonoidAlgebra R (FreeMonoid X) :=
AlgEquiv.ofAlgHom (lift R fun x ↦ (MonoidAlgebra.of R (FreeMonoid X)) (FreeMonoid.of x))
((MonoidAlgebra.lift R (FreeMonoid X) (FreeAlgebra R X)) (FreeMonoid.lift (ι R)))
(by
apply MonoidAlgebra.algHom_ext; intro x
refine FreeMonoid.recOn x ?_ ?_
· simp
rfl
· intro x y ih
simp at ih
simp [ih])
(by
ext
simp)
/-- `FreeAlgebra R X` is nontrivial when `R` is. -/
instance [Nontrivial R] : Nontrivial (FreeAlgebra R X) :=
equivMonoidAlgebraFreeMonoid.surjective.nontrivial
/-- `FreeAlgebra R X` has no zero-divisors when `R` has no zero-divisors. -/
instance instNoZeroDivisors [NoZeroDivisors R] : NoZeroDivisors (FreeAlgebra R X) :=
equivMonoidAlgebraFreeMonoid.toMulEquiv.noZeroDivisors
/-- `FreeAlgebra R X` is a domain when `R` is an integral domain. -/
instance instIsDomain {R X} [CommRing R] [IsDomain R] : IsDomain (FreeAlgebra R X) :=
NoZeroDivisors.to_isDomain _
section
/-- The left-inverse of `algebraMap`. -/
def algebraMapInv : FreeAlgebra R X →ₐ[R] R :=
lift R (0 : X → R)
theorem algebraMap_leftInverse :
Function.LeftInverse algebraMapInv (algebraMap R <| FreeAlgebra R X) := fun x ↦ by
simp [algebraMapInv]
@[simp]
theorem algebraMap_inj (x y : R) :
algebraMap R (FreeAlgebra R X) x = algebraMap R (FreeAlgebra R X) y ↔ x = y :=
algebraMap_leftInverse.injective.eq_iff
@[simp]
theorem algebraMap_eq_zero_iff (x : R) : algebraMap R (FreeAlgebra R X) x = 0 ↔ x = 0 :=
map_eq_zero_iff (algebraMap _ _) algebraMap_leftInverse.injective
@[simp]
theorem algebraMap_eq_one_iff (x : R) : algebraMap R (FreeAlgebra R X) x = 1 ↔ x = 1 :=
map_eq_one_iff (algebraMap _ _) algebraMap_leftInverse.injective
-- this proof is copied from the approach in `FreeAbelianGroup.of_injective`
theorem ι_injective [Nontrivial R] : Function.Injective (ι R : X → FreeAlgebra R X) :=
fun x y hoxy ↦
by_contradiction <| by
classical exact fun hxy : x ≠ y ↦
let f : FreeAlgebra R X →ₐ[R] R := lift R fun z ↦ if x = z then (1 : R) else 0
have hfx1 : f (ι R x) = 1 := (lift_ι_apply _ _).trans <| if_pos rfl
have hfy1 : f (ι R y) = 1 := hoxy ▸ hfx1
have hfy0 : f (ι R y) = 0 := (lift_ι_apply _ _).trans <| if_neg hxy
one_ne_zero <| hfy1.symm.trans hfy0
@[simp]
theorem ι_inj [Nontrivial R] (x y : X) : ι R x = ι R y ↔ x = y :=
ι_injective.eq_iff
@[simp]
theorem ι_ne_algebraMap [Nontrivial R] (x : X) (r : R) : ι R x ≠ algebraMap R _ r := fun h ↦ by
let f0 : FreeAlgebra R X →ₐ[R] R := lift R 0
let f1 : FreeAlgebra R X →ₐ[R] R := lift R 1
have hf0 : f0 (ι R x) = 0 := lift_ι_apply _ _
have hf1 : f1 (ι R x) = 1 := lift_ι_apply _ _
rw [h, f0.commutes, Algebra.algebraMap_self_apply] at hf0
rw [h, f1.commutes, Algebra.algebraMap_self_apply] at hf1
exact zero_ne_one (hf0.symm.trans hf1)
@[simp]
theorem ι_ne_zero [Nontrivial R] (x : X) : ι R x ≠ 0 :=
ι_ne_algebraMap x 0
@[simp]
theorem ι_ne_one [Nontrivial R] (x : X) : ι R x ≠ 1 :=
ι_ne_algebraMap x 1
end
end FreeAlgebra
/- There is something weird in the above namespace that breaks the typeclass resolution of
`CoeSort` below. Closing it and reopening it fixes it... -/
namespace FreeAlgebra
/-- An induction principle for the free algebra.
If `C` holds for the `algebraMap` of `r : R` into `FreeAlgebra R X`, the `ι` of `x : X`, and is
preserved under addition and multiplication, then it holds for all of `FreeAlgebra R X`.
-/
@[elab_as_elim, induction_eliminator]
theorem induction {motive : FreeAlgebra R X → Prop}
(grade0 : ∀ r, motive (algebraMap R (FreeAlgebra R X) r)) (grade1 : ∀ x, motive (ι R x))
(mul : ∀ a b, motive a → motive b → motive (a * b))
(add : ∀ a b, motive a → motive b → motive (a + b))
(a : FreeAlgebra R X) : motive a := by
-- the arguments are enough to construct a subalgebra, and a mapping into it from X
let s : Subalgebra R (FreeAlgebra R X) :=
{ carrier := motive
mul_mem' := mul _ _
add_mem' := add _ _
algebraMap_mem' := grade0 }
let of : X → s := Subtype.coind (ι R) grade1
-- the mapping through the subalgebra is the identity
have of_id : AlgHom.id R (FreeAlgebra R X) = s.val.comp (lift R of) := by
ext
simp [of, Subtype.coind]
-- finding a proof is finding an element of the subalgebra
suffices a = lift R of a by
rw [this]
exact Subtype.prop (lift R of a)
simp [AlgHom.ext_iff] at of_id
exact of_id a
@[simp]
theorem adjoin_range_ι : Algebra.adjoin R (Set.range (ι R : X → FreeAlgebra R X)) = ⊤ := by
set S := Algebra.adjoin R (Set.range (ι R : X → FreeAlgebra R X))
refine top_unique fun x hx => ?_; clear hx
induction x with
| grade0 => exact S.algebraMap_mem _
| add x y hx hy => exact S.add_mem hx hy
| mul x y hx hy => exact S.mul_mem hx hy
| grade1 x => exact Algebra.subset_adjoin (Set.mem_range_self _)
variable {A : Type*} [Semiring A] [Algebra R A]
/-- Noncommutative version of `Algebra.adjoin_range_eq_range_aeval`. -/
theorem _root_.Algebra.adjoin_range_eq_range_freeAlgebra_lift (f : X → A) :
Algebra.adjoin R (Set.range f) = (FreeAlgebra.lift R f).range := by
simp only [← Algebra.map_top, ← adjoin_range_ι, AlgHom.map_adjoin, ← Set.range_comp,
Function.comp_def, lift_ι_apply]
/-- Noncommutative version of `Algebra.adjoin_range_eq_range`. -/
theorem _root_.Algebra.adjoin_eq_range_freeAlgebra_lift (s : Set A) :
Algebra.adjoin R s = (FreeAlgebra.lift R ((↑) : s → A)).range := by
rw [← Algebra.adjoin_range_eq_range_freeAlgebra_lift, Subtype.range_coe]
end FreeAlgebra |
.lake/packages/mathlib/Mathlib/Algebra/CharZero/AddMonoidHom.lean | import Mathlib.Algebra.CharZero.Defs
import Mathlib.Algebra.Group.Equiv.Defs
import Mathlib.Data.Nat.Cast.Basic
/-!
# Transporting `CharZero` accross injective `AddMonoidHom`s
This file exists in order to avoid adding extra imports to other files in this subdirectory.
-/
theorem CharZero.of_addMonoidHom {M N : Type*} [AddCommMonoidWithOne M] [AddCommMonoidWithOne N]
[CharZero M] (e : M →+ N) (he : e 1 = 1) (he' : Function.Injective e) : CharZero N where
cast_injective n m h := by
rwa [← map_natCast' _ he, ← map_natCast' _ he, he'.eq_iff, Nat.cast_inj] at h |
.lake/packages/mathlib/Mathlib/Algebra/CharZero/Quotient.lean | import Mathlib.Algebra.Field.Basic
import Mathlib.Algebra.Order.Group.Unbundled.Int
import Mathlib.Algebra.Module.NatInt
import Mathlib.GroupTheory.QuotientGroup.Defs
import Mathlib.Algebra.Group.Subgroup.ZPowers.Basic
/-!
# Lemmas about quotients in characteristic zero
-/
variable {R : Type*} [DivisionRing R] [CharZero R] {p : R}
namespace AddSubgroup
/-- `z • r` is a multiple of `p` iff `r` is `k * (p / z)` above a multiple of `p`, where
`0 ≤ k < |z|`. -/
theorem zsmul_mem_zmultiples_iff_exists_sub_div {r : R} {z : ℤ} (hz : z ≠ 0) :
z • r ∈ AddSubgroup.zmultiples p ↔
∃ k : Fin z.natAbs, r - (k : ℕ) • (p / z : R) ∈ AddSubgroup.zmultiples p := by
rw [AddSubgroup.mem_zmultiples_iff]
simp_rw [AddSubgroup.mem_zmultiples_iff, div_eq_mul_inv, ← smul_mul_assoc, eq_sub_iff_add_eq]
have hz' : (z : R) ≠ 0 := Int.cast_ne_zero.mpr hz
conv_rhs => simp +singlePass only [← (mul_right_injective₀ hz').eq_iff]
simp_rw [← zsmul_eq_mul, smul_add, ← mul_smul_comm, zsmul_eq_mul (z : R)⁻¹, mul_inv_cancel₀ hz',
mul_one, ← natCast_zsmul, smul_smul, ← add_smul]
constructor
· rintro ⟨k, h⟩
simp_rw [← h]
refine ⟨⟨(k % z).toNat, ?_⟩, k / z, ?_⟩
· rw [← Int.ofNat_lt, Int.toNat_of_nonneg (Int.emod_nonneg _ hz)]
exact (Int.emod_lt_abs _ hz).trans_eq (Int.abs_eq_natAbs _)
rw [Fin.val_mk, Int.toNat_of_nonneg (Int.emod_nonneg _ hz)]
nth_rewrite 3 [← Int.mul_ediv_add_emod k z]
rfl
· rintro ⟨k, n, h⟩
exact ⟨_, h⟩
theorem nsmul_mem_zmultiples_iff_exists_sub_div {r : R} {n : ℕ} (hn : n ≠ 0) :
n • r ∈ AddSubgroup.zmultiples p ↔
∃ k : Fin n, r - (k : ℕ) • (p / n : R) ∈ AddSubgroup.zmultiples p := by
rw [← natCast_zsmul r, zsmul_mem_zmultiples_iff_exists_sub_div (Int.natCast_ne_zero.mpr hn),
Int.cast_natCast]
rfl
end AddSubgroup
namespace QuotientAddGroup
theorem zmultiples_zsmul_eq_zsmul_iff {ψ θ : R ⧸ AddSubgroup.zmultiples p} {z : ℤ} (hz : z ≠ 0) :
z • ψ = z • θ ↔ ∃ k : Fin z.natAbs, ψ = θ + ((k : ℕ) • (p / z) : R) := by
induction ψ using Quotient.inductionOn
induction θ using Quotient.inductionOn
simp_rw [← QuotientAddGroup.mk_zsmul, ← QuotientAddGroup.mk_add,
QuotientAddGroup.eq_iff_sub_mem, ← smul_sub, ← sub_sub]
exact AddSubgroup.zsmul_mem_zmultiples_iff_exists_sub_div hz
theorem zmultiples_nsmul_eq_nsmul_iff {ψ θ : R ⧸ AddSubgroup.zmultiples p} {n : ℕ} (hz : n ≠ 0) :
n • ψ = n • θ ↔ ∃ k : Fin n, ψ = θ + (k : ℕ) • (p / n : R) := by
rw [← natCast_zsmul ψ, ← natCast_zsmul θ,
zmultiples_zsmul_eq_zsmul_iff (Int.natCast_ne_zero.mpr hz), Int.cast_natCast]
rfl
end QuotientAddGroup |
.lake/packages/mathlib/Mathlib/Algebra/CharZero/Defs.lean | import Mathlib.Data.Int.Cast.Defs
import Mathlib.Logic.Basic
/-!
# Characteristic zero
A ring `R` is called of characteristic zero if every natural number `n` is non-zero when considered
as an element of `R`. Since this definition doesn't mention the multiplicative structure of `R`
except for the existence of `1` in this file characteristic zero is defined for additive monoids
with `1`.
## Main definition
`CharZero` is the typeclass of an additive monoid with one such that the natural homomorphism
from the natural numbers into it is injective.
## TODO
* Unify with `CharP` (possibly using an out-parameter)
-/
/-- Typeclass for monoids with characteristic zero.
(This is usually stated on fields but it makes sense for any additive monoid with 1.)
*Warning*: for a semiring `R`, `CharZero R` and `CharP R 0` need not coincide.
* `CharZero R` requires an injection `ℕ ↪ R`;
* `CharP R 0` asks that only `0 : ℕ` maps to `0 : R` under the map `ℕ → R`.
For instance, endowing `{0, 1}` with addition given by `max` (i.e. `1` is absorbing), shows that
`CharZero {0, 1}` does not hold and yet `CharP {0, 1} 0` does.
This example is formalized in `Counterexamples/CharPZeroNeCharZero.lean`.
-/
class CharZero (R) [AddMonoidWithOne R] : Prop where
/-- An additive monoid with one has characteristic zero if the canonical map `ℕ → R` is
injective. -/
cast_injective : Function.Injective (Nat.cast : ℕ → R)
variable {R : Type*}
theorem charZero_of_inj_zero [AddGroupWithOne R] (H : ∀ n : ℕ, (n : R) = 0 → n = 0) :
CharZero R :=
⟨@fun m n h => by
induction m generalizing n with
| zero => rw [H n]; rw [← h, Nat.cast_zero]
| succ m ih =>
cases n
· apply H; rw [h, Nat.cast_zero]
· simp only [Nat.cast_succ, add_right_cancel_iff] at h; rwa [ih]⟩
namespace Nat
variable [AddMonoidWithOne R] [CharZero R]
theorem cast_injective : Function.Injective (Nat.cast : ℕ → R) :=
CharZero.cast_injective
@[simp, norm_cast]
theorem cast_inj {m n : ℕ} : (m : R) = n ↔ m = n :=
cast_injective.eq_iff
@[simp, norm_cast]
theorem cast_eq_zero {n : ℕ} : (n : R) = 0 ↔ n = 0 := by rw [← cast_zero, cast_inj]
@[norm_cast]
theorem cast_ne_zero {n : ℕ} : (n : R) ≠ 0 ↔ n ≠ 0 :=
not_congr cast_eq_zero
theorem cast_add_one_ne_zero (n : ℕ) : (n + 1 : R) ≠ 0 :=
mod_cast n.succ_ne_zero
@[simp, norm_cast]
theorem cast_eq_one {n : ℕ} : (n : R) = 1 ↔ n = 1 := by rw [← cast_one, cast_inj]
@[norm_cast]
theorem cast_ne_one {n : ℕ} : (n : R) ≠ 1 ↔ n ≠ 1 :=
cast_eq_one.not
end Nat
namespace OfNat
variable [AddMonoidWithOne R] [CharZero R]
@[simp] lemma ofNat_ne_zero (n : ℕ) [n.AtLeastTwo] : (ofNat(n) : R) ≠ 0 :=
Nat.cast_ne_zero.2 (NeZero.ne n)
@[simp] lemma zero_ne_ofNat (n : ℕ) [n.AtLeastTwo] : 0 ≠ (ofNat(n) : R) :=
(ofNat_ne_zero n).symm
@[simp] lemma ofNat_ne_one (n : ℕ) [n.AtLeastTwo] : (ofNat(n) : R) ≠ 1 :=
Nat.cast_ne_one.2 (Nat.AtLeastTwo.ne_one)
@[simp] lemma one_ne_ofNat (n : ℕ) [n.AtLeastTwo] : (1 : R) ≠ ofNat(n) :=
(ofNat_ne_one n).symm
@[simp] lemma ofNat_eq_ofNat {m n : ℕ} [m.AtLeastTwo] [n.AtLeastTwo] :
(ofNat(m) : R) = ofNat(n) ↔ (ofNat m : ℕ) = ofNat n :=
Nat.cast_inj
end OfNat
namespace NeZero
instance charZero {M} {n : ℕ} [NeZero n] [AddMonoidWithOne M] [CharZero M] : NeZero (n : M) :=
⟨Nat.cast_ne_zero.mpr out⟩
instance charZero_one {M} [AddMonoidWithOne M] [CharZero M] : NeZero (1 : M) where
out := by
rw [← Nat.cast_one, Nat.cast_ne_zero]
trivial
instance charZero_ofNat {M} {n : ℕ} [n.AtLeastTwo] [AddMonoidWithOne M] [CharZero M] :
NeZero (OfNat.ofNat n : M) :=
⟨OfNat.ofNat_ne_zero n⟩
end NeZero |
.lake/packages/mathlib/Mathlib/Algebra/CharZero/Infinite.lean | import Mathlib.Algebra.CharZero.Defs
import Mathlib.Data.Fintype.EquivFin
/-! # A characteristic-zero semiring is infinite -/
open Set
variable (M : Type*) [AddMonoidWithOne M] [CharZero M]
-- see Note [lower instance priority]
instance (priority := 100) CharZero.infinite : Infinite M :=
Infinite.of_injective Nat.cast Nat.cast_injective |
.lake/packages/mathlib/Mathlib/Algebra/AddTorsor/Basic.lean | import Mathlib.Algebra.AddTorsor.Defs
import Mathlib.Algebra.Group.Action.Basic
import Mathlib.Algebra.Group.Action.Pi
import Mathlib.Algebra.Group.End
import Mathlib.Algebra.Group.Pointwise.Set.Scalar
/-!
# Torsors of additive group actions
Further results for torsors, that are not in `Mathlib/Algebra/AddTorsor/Defs.lean` to avoid
increasing imports there.
-/
open scoped Pointwise
section General
variable {G : Type*} {P : Type*} [AddGroup G] [T : AddTorsor G P]
namespace Set
theorem singleton_vsub_self (p : P) : ({p} : Set P) -ᵥ {p} = {(0 : G)} := by
rw [Set.singleton_vsub_singleton, vsub_self]
end Set
/-- If the same point subtracted from two points produces equal
results, those points are equal. -/
theorem vsub_left_cancel {p₁ p₂ p : P} (h : p₁ -ᵥ p = p₂ -ᵥ p) : p₁ = p₂ := by
rwa [← sub_eq_zero, vsub_sub_vsub_cancel_right, vsub_eq_zero_iff_eq] at h
/-- The same point subtracted from two points produces equal results
if and only if those points are equal. -/
@[simp]
theorem vsub_left_cancel_iff {p₁ p₂ p : P} : p₁ -ᵥ p = p₂ -ᵥ p ↔ p₁ = p₂ :=
⟨vsub_left_cancel, fun h => h ▸ rfl⟩
/-- Subtracting the point `p` is an injective function. -/
theorem vsub_left_injective (p : P) : Function.Injective ((· -ᵥ p) : P → G) := fun _ _ =>
vsub_left_cancel
/-- If subtracting two points from the same point produces equal
results, those points are equal. -/
theorem vsub_right_cancel {p₁ p₂ p : P} (h : p -ᵥ p₁ = p -ᵥ p₂) : p₁ = p₂ := by
refine vadd_left_cancel (p -ᵥ p₂) ?_
rw [vsub_vadd, ← h, vsub_vadd]
/-- Subtracting two points from the same point produces equal results
if and only if those points are equal. -/
@[simp]
theorem vsub_right_cancel_iff {p₁ p₂ p : P} : p -ᵥ p₁ = p -ᵥ p₂ ↔ p₁ = p₂ :=
⟨vsub_right_cancel, fun h => h ▸ rfl⟩
/-- Subtracting a point from the point `p` is an injective
function. -/
theorem vsub_right_injective (p : P) : Function.Injective ((p -ᵥ ·) : P → G) := fun _ _ =>
vsub_right_cancel
end General
section comm
variable {G : Type*} {P : Type*} [AddCommGroup G] [AddTorsor G P]
/-- Cancellation subtracting the results of two subtractions. -/
@[simp]
theorem vsub_sub_vsub_cancel_left (p₁ p₂ p₃ : P) : p₃ -ᵥ p₂ - (p₃ -ᵥ p₁) = p₁ -ᵥ p₂ := by
rw [sub_eq_add_neg, neg_vsub_eq_vsub_rev, add_comm, vsub_add_vsub_cancel]
@[simp]
theorem vadd_vsub_vadd_cancel_left (v : G) (p₁ p₂ : P) : (v +ᵥ p₁) -ᵥ (v +ᵥ p₂) = p₁ -ᵥ p₂ := by
rw [vsub_vadd_eq_vsub_sub, vadd_vsub_assoc, add_sub_cancel_left]
theorem vadd_vsub_vadd_comm (v₁ v₂ : G) (p₁ p₂ : P) :
(v₁ +ᵥ p₁) -ᵥ (v₂ +ᵥ p₂) = (v₁ - v₂) + (p₁ -ᵥ p₂) := by
rw [vsub_vadd_eq_vsub_sub, vadd_vsub_assoc, add_sub_assoc, ← add_comm_sub]
theorem sub_add_vsub_comm (v₁ v₂ : G) (p₁ p₂ : P) :
(v₁ - v₂) + (p₁ -ᵥ p₂) = (v₁ +ᵥ p₁) -ᵥ (v₂ +ᵥ p₂) :=
vadd_vsub_vadd_comm _ _ _ _ |>.symm
theorem vsub_vadd_comm (p₁ p₂ p₃ : P) : (p₁ -ᵥ p₂ : G) +ᵥ p₃ = (p₃ -ᵥ p₂) +ᵥ p₁ := by
rw [← @vsub_eq_zero_iff_eq G, vadd_vsub_assoc, vsub_vadd_eq_vsub_sub]
simp
theorem vadd_eq_vadd_iff_sub_eq_vsub {v₁ v₂ : G} {p₁ p₂ : P} :
v₁ +ᵥ p₁ = v₂ +ᵥ p₂ ↔ v₂ - v₁ = p₁ -ᵥ p₂ := by
rw [vadd_eq_vadd_iff_neg_add_eq_vsub, neg_add_eq_sub]
theorem vsub_sub_vsub_comm (p₁ p₂ p₃ p₄ : P) : p₁ -ᵥ p₂ - (p₃ -ᵥ p₄) = p₁ -ᵥ p₃ - (p₂ -ᵥ p₄) := by
rw [← vsub_vadd_eq_vsub_sub, vsub_vadd_comm, vsub_vadd_eq_vsub_sub]
namespace Set
@[simp] lemma vadd_set_vsub_vadd_set (v : G) (s t : Set P) : (v +ᵥ s) -ᵥ (v +ᵥ t) = s -ᵥ t := by
ext; simp [mem_vsub, mem_vadd_set]
end Set
end comm
namespace Prod
variable {G G' P P' : Type*} [AddGroup G] [AddGroup G'] [AddTorsor G P] [AddTorsor G' P']
instance instAddTorsor : AddTorsor (G × G') (P × P') where
vadd v p := (v.1 +ᵥ p.1, v.2 +ᵥ p.2)
zero_vadd _ := Prod.ext (zero_vadd _ _) (zero_vadd _ _)
add_vadd _ _ _ := Prod.ext (add_vadd _ _ _) (add_vadd _ _ _)
vsub p₁ p₂ := (p₁.1 -ᵥ p₂.1, p₁.2 -ᵥ p₂.2)
vsub_vadd' _ _ := Prod.ext (vsub_vadd _ _) (vsub_vadd _ _)
vadd_vsub' _ _ := Prod.ext (vadd_vsub _ _) (vadd_vsub _ _)
@[simp]
theorem fst_vadd (v : G × G') (p : P × P') : (v +ᵥ p).1 = v.1 +ᵥ p.1 :=
rfl
@[simp]
theorem snd_vadd (v : G × G') (p : P × P') : (v +ᵥ p).2 = v.2 +ᵥ p.2 :=
rfl
@[simp]
theorem mk_vadd_mk (v : G) (v' : G') (p : P) (p' : P') : (v, v') +ᵥ (p, p') = (v +ᵥ p, v' +ᵥ p') :=
rfl
@[simp]
theorem fst_vsub (p₁ p₂ : P × P') : (p₁ -ᵥ p₂ : G × G').1 = p₁.1 -ᵥ p₂.1 :=
rfl
@[simp]
theorem snd_vsub (p₁ p₂ : P × P') : (p₁ -ᵥ p₂ : G × G').2 = p₁.2 -ᵥ p₂.2 :=
rfl
@[simp]
theorem mk_vsub_mk (p₁ p₂ : P) (p₁' p₂' : P') :
((p₁, p₁') -ᵥ (p₂, p₂') : G × G') = (p₁ -ᵥ p₂, p₁' -ᵥ p₂') :=
rfl
end Prod
namespace Pi
universe u v w
variable {I : Type u} {fg : I → Type v} [∀ i, AddGroup (fg i)] {fp : I → Type w}
[∀ i, AddTorsor (fg i) (fp i)]
open AddAction AddTorsor
/-- A product of `AddTorsor`s is an `AddTorsor`. -/
instance instAddTorsor : AddTorsor (∀ i, fg i) (∀ i, fp i) where
vsub p₁ p₂ i := p₁ i -ᵥ p₂ i
vsub_vadd' p₁ p₂ := funext fun i => vsub_vadd (p₁ i) (p₂ i)
vadd_vsub' g p := funext fun i => vadd_vsub (g i) (p i)
@[simp]
theorem vsub_apply (p q : ∀ i, fp i) (i : I) : (p -ᵥ q) i = p i -ᵥ q i :=
rfl
@[push ←]
theorem vsub_def (p q : ∀ i, fp i) : p -ᵥ q = fun i => p i -ᵥ q i :=
rfl
end Pi
namespace Equiv
variable (G : Type*) (P : Type*) [AddGroup G] [AddTorsor G P]
@[simp]
theorem constVAdd_zero : constVAdd P (0 : G) = 1 :=
ext <| zero_vadd G
variable {G}
@[simp]
theorem constVAdd_add (v₁ v₂ : G) : constVAdd P (v₁ + v₂) = constVAdd P v₁ * constVAdd P v₂ :=
ext <| add_vadd v₁ v₂
/-- `Equiv.constVAdd` as a homomorphism from `Multiplicative G` to `Equiv.perm P` -/
def constVAddHom : Multiplicative G →* Equiv.Perm P where
toFun v := constVAdd P (v.toAdd)
map_one' := constVAdd_zero G P
map_mul' := constVAdd_add P
variable {P}
open Function
@[simp]
theorem left_vsub_pointReflection (x y : P) : x -ᵥ pointReflection x y = y -ᵥ x :=
neg_injective <| by simp
@[simp]
theorem right_vsub_pointReflection (x y : P) : y -ᵥ pointReflection x y = 2 • (y -ᵥ x) :=
neg_injective <| by simp [← neg_nsmul]
/-- `x` is the only fixed point of `pointReflection x`. This lemma requires
`x + x = y + y ↔ x = y`. There is no typeclass to use here, so we add it as an explicit argument. -/
theorem pointReflection_fixed_iff_of_injective_two_nsmul {x y : P} (h : Injective (2 • · : G → G)) :
pointReflection x y = y ↔ y = x := by
rw [pointReflection_apply, eq_comm, eq_vadd_iff_vsub_eq, ← neg_vsub_eq_vsub_rev,
neg_eq_iff_add_eq_zero, ← two_nsmul, ← nsmul_zero 2, h.eq_iff, vsub_eq_zero_iff_eq, eq_comm]
theorem injective_pointReflection_left_of_injective_two_nsmul {G P : Type*} [AddCommGroup G]
[AddTorsor G P] (h : Injective (2 • · : G → G)) (y : P) :
Injective fun x : P => pointReflection x y :=
fun x₁ x₂ (hy : pointReflection x₁ y = pointReflection x₂ y) => by
rwa [pointReflection_apply, pointReflection_apply, vadd_eq_vadd_iff_sub_eq_vsub,
vsub_sub_vsub_cancel_right, ← neg_vsub_eq_vsub_rev, neg_eq_iff_add_eq_zero,
← two_nsmul, ← nsmul_zero 2, h.eq_iff, vsub_eq_zero_iff_eq] at hy
/-- In the special case of additive commutative groups (as opposed to just additive torsors),
`Equiv.pointReflection x` coincides with `Equiv.subLeft (2 • x)`. -/
lemma pointReflection_eq_subLeft {G : Type*} [AddCommGroup G] (x : G) :
pointReflection x = Equiv.subLeft (2 • x) := by
ext; simp [pointReflection, sub_add_eq_add_sub, two_nsmul]
end Equiv |
.lake/packages/mathlib/Mathlib/Algebra/AddTorsor/Defs.lean | import Mathlib.Algebra.Group.Action.Defs
/-!
# Torsors of additive group actions
This file defines torsors of additive group actions.
## Notation
The group elements are referred to as acting on points. This file
defines the notation `+ᵥ` for adding a group element to a point and
`-ᵥ` for subtracting two points to produce a group element.
## Implementation notes
Affine spaces are the motivating example of torsors of additive group actions. It may be appropriate
to refactor in terms of the general definition of group actions, via `to_additive`, when there is a
use for multiplicative torsors (currently mathlib only develops the theory of group actions for
multiplicative group actions).
## Notation
* `v +ᵥ p` is a notation for `VAdd.vadd`, the left action of an additive monoid;
* `p₁ -ᵥ p₂` is a notation for `VSub.vsub`, difference between two points in an additive torsor
as an element of the corresponding additive group;
## References
* https://en.wikipedia.org/wiki/Principal_homogeneous_space
* https://en.wikipedia.org/wiki/Affine_space
-/
assert_not_exists MonoidWithZero
/-- An `AddTorsor G P` gives a structure to the nonempty type `P`,
acted on by an `AddGroup G` with a transitive and free action given
by the `+ᵥ` operation and a corresponding subtraction given by the
`-ᵥ` operation. In the case of a vector space, it is an affine
space. -/
class AddTorsor (G : outParam Type*) (P : Type*) [AddGroup G] extends AddAction G P,
VSub G P where
[nonempty : Nonempty P]
/-- Torsor subtraction and addition with the same element cancels out. -/
vsub_vadd' : ∀ p₁ p₂ : P, (p₁ -ᵥ p₂ : G) +ᵥ p₂ = p₁
/-- Torsor addition and subtraction with the same element cancels out. -/
vadd_vsub' : ∀ (g : G) (p : P), (g +ᵥ p) -ᵥ p = g
-- Porting note (https://github.com/leanprover-community/mathlib4/issues/12096): removed `nolint instance_priority`; lint not ported yet
attribute [instance 100] AddTorsor.nonempty
/-- An `AddGroup G` is a torsor for itself. -/
-- Porting note (https://github.com/leanprover-community/mathlib4/issues/12096): linter not ported yet
--@[nolint instance_priority]
instance addGroupIsAddTorsor (G : Type*) [AddGroup G] : AddTorsor G G where
vsub := Sub.sub
vsub_vadd' := sub_add_cancel
vadd_vsub' := add_sub_cancel_right
/-- Simplify subtraction for a torsor for an `AddGroup G` over
itself. -/
@[simp]
theorem vsub_eq_sub {G : Type*} [AddGroup G] (g₁ g₂ : G) : g₁ -ᵥ g₂ = g₁ - g₂ :=
rfl
section General
variable {G : Type*} {P : Type*} [AddGroup G] [T : AddTorsor G P]
/-- Adding the result of subtracting from another point produces that
point. -/
@[simp]
theorem vsub_vadd (p₁ p₂ : P) : (p₁ -ᵥ p₂) +ᵥ p₂ = p₁ :=
AddTorsor.vsub_vadd' p₁ p₂
/-- Adding a group element then subtracting the original point
produces that group element. -/
@[simp]
theorem vadd_vsub (g : G) (p : P) : (g +ᵥ p) -ᵥ p = g :=
AddTorsor.vadd_vsub' g p
/-- If the same point added to two group elements produces equal
results, those group elements are equal. -/
theorem vadd_right_cancel {g₁ g₂ : G} (p : P) (h : g₁ +ᵥ p = g₂ +ᵥ p) : g₁ = g₂ := by
rw [← vadd_vsub g₁ p, h, vadd_vsub]
@[simp]
theorem vadd_right_cancel_iff {g₁ g₂ : G} (p : P) : g₁ +ᵥ p = g₂ +ᵥ p ↔ g₁ = g₂ :=
⟨vadd_right_cancel p, fun h => h ▸ rfl⟩
/-- Adding a group element to the point `p` is an injective
function. -/
theorem vadd_right_injective (p : P) : Function.Injective ((· +ᵥ p) : G → P) := fun _ _ =>
vadd_right_cancel p
/-- Adding a group element to a point, then subtracting another point,
produces the same result as subtracting the points then adding the
group element. -/
theorem vadd_vsub_assoc (g : G) (p₁ p₂ : P) : (g +ᵥ p₁) -ᵥ p₂ = g + (p₁ -ᵥ p₂) := by
apply vadd_right_cancel p₂
rw [vsub_vadd, add_vadd, vsub_vadd]
/-- Subtracting a point from itself produces 0. -/
@[simp]
theorem vsub_self (p : P) : p -ᵥ p = (0 : G) := by
rw [← zero_add (p -ᵥ p), ← vadd_vsub_assoc, vadd_vsub]
/-- If subtracting two points produces 0, they are equal. -/
theorem eq_of_vsub_eq_zero {p₁ p₂ : P} (h : p₁ -ᵥ p₂ = (0 : G)) : p₁ = p₂ := by
rw [← vsub_vadd p₁ p₂, h, zero_vadd]
/-- Subtracting two points produces 0 if and only if they are
equal. -/
@[simp]
theorem vsub_eq_zero_iff_eq {p₁ p₂ : P} : p₁ -ᵥ p₂ = (0 : G) ↔ p₁ = p₂ :=
Iff.intro eq_of_vsub_eq_zero fun h => h ▸ vsub_self _
theorem vsub_ne_zero {p q : P} : p -ᵥ q ≠ (0 : G) ↔ p ≠ q :=
not_congr vsub_eq_zero_iff_eq
/-- Cancellation adding the results of two subtractions. -/
@[simp]
theorem vsub_add_vsub_cancel (p₁ p₂ p₃ : P) : p₁ -ᵥ p₂ + (p₂ -ᵥ p₃) = p₁ -ᵥ p₃ := by
apply vadd_right_cancel p₃
rw [add_vadd, vsub_vadd, vsub_vadd, vsub_vadd]
/-- Subtracting two points in the reverse order produces the negation
of subtracting them. -/
@[simp]
theorem neg_vsub_eq_vsub_rev (p₁ p₂ : P) : -(p₁ -ᵥ p₂) = p₂ -ᵥ p₁ := by
refine neg_eq_of_add_eq_zero_right (vadd_right_cancel p₁ ?_)
rw [vsub_add_vsub_cancel, vsub_self]
theorem vadd_vsub_eq_sub_vsub (g : G) (p q : P) : (g +ᵥ p) -ᵥ q = g - (q -ᵥ p) := by
rw [vadd_vsub_assoc, sub_eq_add_neg, neg_vsub_eq_vsub_rev]
/-- Subtracting the result of adding a group element produces the same result
as subtracting the points and subtracting that group element. -/
theorem vsub_vadd_eq_vsub_sub (p₁ p₂ : P) (g : G) : p₁ -ᵥ (g +ᵥ p₂) = p₁ -ᵥ p₂ - g := by
rw [← add_right_inj (p₂ -ᵥ p₁ : G), vsub_add_vsub_cancel, ← neg_vsub_eq_vsub_rev, vadd_vsub, ←
add_sub_assoc, ← neg_vsub_eq_vsub_rev, neg_add_cancel, zero_sub]
/-- Cancellation subtracting the results of two subtractions. -/
@[simp]
theorem vsub_sub_vsub_cancel_right (p₁ p₂ p₃ : P) : p₁ -ᵥ p₃ - (p₂ -ᵥ p₃) = p₁ -ᵥ p₂ := by
rw [← vsub_vadd_eq_vsub_sub, vsub_vadd]
/-- Convert between an equality with adding a group element to a point
and an equality of a subtraction of two points with a group
element. -/
theorem eq_vadd_iff_vsub_eq (p₁ : P) (g : G) (p₂ : P) : p₁ = g +ᵥ p₂ ↔ p₁ -ᵥ p₂ = g :=
⟨fun h => h.symm ▸ vadd_vsub _ _, fun h => h ▸ (vsub_vadd _ _).symm⟩
theorem vadd_eq_vadd_iff_neg_add_eq_vsub {v₁ v₂ : G} {p₁ p₂ : P} :
v₁ +ᵥ p₁ = v₂ +ᵥ p₂ ↔ -v₁ + v₂ = p₁ -ᵥ p₂ := by
rw [eq_vadd_iff_vsub_eq, vadd_vsub_assoc, ← add_right_inj (-v₁), neg_add_cancel_left, eq_comm]
@[simp]
theorem vadd_vsub_vadd_cancel_right (v₁ v₂ : G) (p : P) : (v₁ +ᵥ p) -ᵥ (v₂ +ᵥ p) = v₁ - v₂ := by
rw [vsub_vadd_eq_vsub_sub, vadd_vsub_assoc, vsub_self, add_zero]
end General
namespace Equiv
variable {G : Type*} {P : Type*} [AddGroup G] [AddTorsor G P]
/-- `v ↦ v +ᵥ p` as an equivalence. -/
def vaddConst (p : P) : G ≃ P where
toFun v := v +ᵥ p
invFun p' := p' -ᵥ p
left_inv _ := vadd_vsub _ _
right_inv _ := vsub_vadd _ _
@[simp]
theorem coe_vaddConst (p : P) : ⇑(vaddConst p) = fun v => v +ᵥ p :=
rfl
@[simp]
theorem coe_vaddConst_symm (p : P) : ⇑(vaddConst p).symm = fun p' => p' -ᵥ p :=
rfl
/-- `p' ↦ p -ᵥ p'` as an equivalence. -/
def constVSub (p : P) : P ≃ G where
toFun := (p -ᵥ ·)
invFun := (-· +ᵥ p)
left_inv p' := by simp
right_inv v := by simp [vsub_vadd_eq_vsub_sub]
@[simp] lemma coe_constVSub (p : P) : ⇑(constVSub p) = (p -ᵥ ·) := rfl
@[simp]
theorem coe_constVSub_symm (p : P) : ⇑(constVSub p).symm = fun (v : G) => -v +ᵥ p :=
rfl
variable (P)
/-- The permutation given by `p ↦ v +ᵥ p`. -/
def constVAdd (v : G) : Equiv.Perm P where
toFun := (v +ᵥ ·)
invFun := (-v +ᵥ ·)
left_inv p := by simp [vadd_vadd]
right_inv p := by simp [vadd_vadd]
@[simp] lemma coe_constVAdd (v : G) : ⇑(constVAdd P v) = (v +ᵥ ·) := rfl
variable {P}
open Function
/-- Point reflection in `x` as a permutation. -/
def pointReflection (x : P) : Perm P :=
(constVSub x).trans (vaddConst x)
theorem pointReflection_apply (x y : P) : pointReflection x y = (x -ᵥ y) +ᵥ x :=
rfl
@[simp]
theorem pointReflection_vsub_left (x y : P) : pointReflection x y -ᵥ x = x -ᵥ y :=
vadd_vsub ..
@[simp]
theorem pointReflection_vsub_right (x y : P) : pointReflection x y -ᵥ y = 2 • (x -ᵥ y) := by
simp [pointReflection, two_nsmul, vadd_vsub_assoc]
@[simp]
theorem pointReflection_symm (x : P) : (pointReflection x).symm = pointReflection x :=
ext <| by simp [pointReflection]
@[simp]
theorem pointReflection_self (x : P) : pointReflection x x = x :=
vsub_vadd _ _
theorem pointReflection_involutive (x : P) : Involutive (pointReflection x : P → P) := fun y =>
(Equiv.apply_eq_iff_eq_symm_apply _).2 <| by rw [pointReflection_symm]
end Equiv
theorem AddTorsor.subsingleton_iff (G P : Type*) [AddGroup G] [AddTorsor G P] :
Subsingleton G ↔ Subsingleton P := by
inhabit P
exact (Equiv.vaddConst default).subsingleton_congr |
.lake/packages/mathlib/Mathlib/Algebra/Order/CompleteField.lean | import Mathlib.Algebra.Order.Archimedean.Hom
import Mathlib.Algebra.Order.Group.Pointwise.CompleteLattice
/-!
# 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 Set
open scoped Pointwise
/-- A field which is both linearly ordered and conditionally complete with respect to the order.
This axiomatizes the reals. -/
class ConditionallyCompleteLinearOrderedField (α : Type*) extends
Field α, ConditionallyCompleteLinearOrder α, IsStrictOrderedRing α where
-- 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)
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 [Field α] [LinearOrder α]
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_mono fun _ => h.trans_lt'
variable {β}
@[simp]
theorem mem_cutMap_iff : b ∈ cutMap β a ↔ ∃ q : ℚ, (q : α) < a ∧ (q : β) = b := Iff.rfl
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
grind [mem_cutMap_iff]
end DivisionRing
variable (β) [IsStrictOrderedRing α] [Field β] [LinearOrder β] [IsStrictOrderedRing β]
{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 α]
omit [LinearOrder β] [IsStrictOrderedRing β] in
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 https://github.com/leanprover/lean4/pull/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 (α β γ) [Field α] [LinearOrder α] [IsStrictOrderedRing α]
[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 _ => 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]
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_ge 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*} [Ring R] [PartialOrder R] [IsOrderedRing R]
[Ring S] [LinearOrder S] [IsStrictOrderedRing 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
end Real |
.lake/packages/mathlib/Mathlib/Algebra/Order/Sum.lean | import Mathlib.Algebra.Notation.Pi.Defs
import Mathlib.Order.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 |
.lake/packages/mathlib/Mathlib/Algebra/Order/SuccPred.lean | import Mathlib.Algebra.Group.Basic
import Mathlib.Algebra.Order.Monoid.Canonical.Defs
import Mathlib.Algebra.Order.ZeroLEOne
import Mathlib.Data.Int.Cast.Defs
import Mathlib.Order.SuccPred.Limit
import Mathlib.Order.SuccPred.WithBot
/-!
# Interaction between successors and arithmetic
We define the `SuccAddOrder` and `PredSubOrder` typeclasses, for orders satisfying `succ x = x + 1`
and `pred x = x - 1` respectively. This allows us to transfer the API for successors and
predecessors into these common arithmetical forms.
## Todo
In the future, we will make `x + 1` and `x - 1` the `simp`-normal forms for `succ x` and `pred x`
respectively. This will require a refactor of `Ordinal` first, as the `simp`-normal form is
currently set the other way around.
-/
/-- A typeclass for `succ x = x + 1`. -/
class SuccAddOrder (α : Type*) [Preorder α] [Add α] [One α] extends SuccOrder α where
succ_eq_add_one (x : α) : succ x = x + 1
/-- A typeclass for `pred x = x - 1`. -/
class PredSubOrder (α : Type*) [Preorder α] [Sub α] [One α] extends PredOrder α where
pred_eq_sub_one (x : α) : pred x = x - 1
variable {α : Type*} {x y : α}
namespace Order
section Preorder
variable [Preorder α]
section Add
variable [Add α] [One α] [SuccAddOrder α]
theorem succ_eq_add_one (x : α) : succ x = x + 1 :=
SuccAddOrder.succ_eq_add_one x
theorem add_one_le_of_lt (h : x < y) : x + 1 ≤ y := by
rw [← succ_eq_add_one]
exact succ_le_of_lt h
theorem add_one_le_iff_of_not_isMax (hx : ¬ IsMax x) : x + 1 ≤ y ↔ x < y := by
rw [← succ_eq_add_one, succ_le_iff_of_not_isMax hx]
theorem add_one_le_iff [NoMaxOrder α] : x + 1 ≤ y ↔ x < y :=
add_one_le_iff_of_not_isMax (not_isMax x)
@[simp]
theorem wcovBy_add_one (x : α) : x ⩿ x + 1 := by
rw [← succ_eq_add_one]
exact wcovBy_succ x
@[simp]
theorem covBy_add_one [NoMaxOrder α] (x : α) : x ⋖ x + 1 := by
rw [← succ_eq_add_one]
exact covBy_succ x
end Add
section Sub
variable [Sub α] [One α] [PredSubOrder α]
theorem pred_eq_sub_one (x : α) : pred x = x - 1 :=
PredSubOrder.pred_eq_sub_one x
theorem le_sub_one_of_lt (h : x < y) : x ≤ y - 1 := by
rw [← pred_eq_sub_one]
exact le_pred_of_lt h
theorem le_sub_one_iff_of_not_isMin (hy : ¬ IsMin y) : x ≤ y - 1 ↔ x < y := by
rw [← pred_eq_sub_one, le_pred_iff_of_not_isMin hy]
theorem le_sub_one_iff [NoMinOrder α] : x ≤ y - 1 ↔ x < y :=
le_sub_one_iff_of_not_isMin (not_isMin y)
@[simp]
theorem sub_one_wcovBy (x : α) : x - 1 ⩿ x := by
rw [← pred_eq_sub_one]
exact pred_wcovBy x
@[simp]
theorem sub_one_covBy [NoMinOrder α] (x : α) : x - 1 ⋖ x := by
rw [← pred_eq_sub_one]
exact pred_covBy x
end Sub
@[simp]
theorem succ_iterate [AddMonoidWithOne α] [SuccAddOrder α] (x : α) (n : ℕ) :
succ^[n] x = x + n := by
induction n with
| zero =>
rw [Function.iterate_zero_apply, Nat.cast_zero, add_zero]
| succ n IH =>
rw [Function.iterate_succ_apply', IH, Nat.cast_add, succ_eq_add_one, Nat.cast_one, add_assoc]
@[simp]
theorem pred_iterate [AddCommGroupWithOne α] [PredSubOrder α] (x : α) (n : ℕ) :
pred^[n] x = x - n := by
induction n with
| zero =>
rw [Function.iterate_zero_apply, Nat.cast_zero, sub_zero]
| succ n IH =>
rw [Function.iterate_succ_apply', IH, Nat.cast_add, pred_eq_sub_one, Nat.cast_one, sub_sub]
end Preorder
section PartialOrder
variable [PartialOrder α]
theorem not_isMax_zero [Zero α] [One α] [ZeroLEOneClass α] [NeZero (1 : α)] : ¬ IsMax (0 : α) := by
rw [not_isMax_iff]
exact ⟨1, one_pos⟩
theorem one_le_iff_pos [AddMonoidWithOne α] [ZeroLEOneClass α] [NeZero (1 : α)]
[SuccAddOrder α] : 1 ≤ x ↔ 0 < x := by
rw [← succ_le_iff_of_not_isMax not_isMax_zero, succ_eq_add_one, zero_add]
theorem covBy_iff_add_one_eq [Add α] [One α] [SuccAddOrder α] [NoMaxOrder α] :
x ⋖ y ↔ x + 1 = y := by
rw [← succ_eq_add_one]
exact succ_eq_iff_covBy.symm
theorem covBy_iff_sub_one_eq [Sub α] [One α] [PredSubOrder α] [NoMinOrder α] :
x ⋖ y ↔ y - 1 = x := by
rw [← pred_eq_sub_one]
exact pred_eq_iff_covBy.symm
theorem IsSuccPrelimit.add_one_lt [Add α] [One α] [SuccAddOrder α]
(hx : IsSuccPrelimit x) (hy : y < x) : y + 1 < x := by
rw [← succ_eq_add_one]
exact hx.succ_lt hy
theorem IsPredPrelimit.lt_sub_one [Sub α] [One α] [PredSubOrder α]
(hx : IsPredPrelimit x) (hy : x < y) : x < y - 1 := by
rw [← pred_eq_sub_one]
exact hx.lt_pred hy
theorem IsSuccLimit.add_one_lt [Add α] [One α] [SuccAddOrder α]
(hx : IsSuccLimit x) (hy : y < x) : y + 1 < x :=
hx.isSuccPrelimit.add_one_lt hy
theorem IsPredLimit.lt_sub_one [Sub α] [One α] [PredSubOrder α]
(hx : IsPredLimit x) (hy : x < y) : x < y - 1 :=
hx.isPredPrelimit.lt_sub_one hy
theorem IsSuccPrelimit.add_natCast_lt [AddMonoidWithOne α] [SuccAddOrder α]
(hx : IsSuccPrelimit x) (hy : y < x) : ∀ n : ℕ, y + n < x
| 0 => by simpa
| n + 1 => by
rw [Nat.cast_add_one, ← add_assoc]
exact hx.add_one_lt (hx.add_natCast_lt hy n)
theorem IsPredPrelimit.lt_sub_natCast [AddCommGroupWithOne α] [PredSubOrder α]
(hx : IsPredPrelimit x) (hy : x < y) : ∀ n : ℕ, x < y - n
| 0 => by simpa
| n + 1 => by
rw [Nat.cast_add_one, ← sub_sub]
exact hx.lt_sub_one (hx.lt_sub_natCast hy n)
theorem IsSuccLimit.add_natCast_lt [AddMonoidWithOne α] [SuccAddOrder α]
(hx : IsSuccLimit x) (hy : y < x) : ∀ n : ℕ, y + n < x :=
hx.isSuccPrelimit.add_natCast_lt hy
theorem IsPredLimit.lt_sub_natCast [AddCommGroupWithOne α] [PredSubOrder α]
(hx : IsPredLimit x) (hy : x < y) : ∀ n : ℕ, x < y - n :=
hx.isPredPrelimit.lt_sub_natCast hy
theorem IsSuccLimit.natCast_lt [AddMonoidWithOne α] [SuccAddOrder α]
[OrderBot α] [CanonicallyOrderedAdd α]
(hx : IsSuccLimit x) : ∀ n : ℕ, n < x := by
simpa [bot_eq_zero] using hx.add_natCast_lt hx.bot_lt
theorem not_isSuccLimit_natCast [AddMonoidWithOne α] [SuccAddOrder α]
[OrderBot α] [CanonicallyOrderedAdd α]
(n : ℕ) : ¬ IsSuccLimit (n : α) :=
fun h ↦ (h.natCast_lt n).false
@[simp]
theorem succ_eq_zero [AddZeroClass α] [OrderBot α] [CanonicallyOrderedAdd α] [One α] [NoMaxOrder α]
[SuccAddOrder α] {a : WithBot α} : WithBot.succ a = 0 ↔ a = ⊥ := by
cases a
· simp [bot_eq_zero]
· rename_i a
simp only [WithBot.succ_coe, WithBot.coe_ne_bot, iff_false]
by_contra h
simpa [h] using max_of_succ_le (a := a)
end PartialOrder
section LinearOrder
variable [LinearOrder α]
section Add
variable [Add α] [One α] [SuccAddOrder α]
theorem le_of_lt_add_one (h : x < y + 1) : x ≤ y := by
rw [← succ_eq_add_one] at h
exact le_of_lt_succ h
theorem lt_add_one_iff_of_not_isMax (hy : ¬ IsMax y) : x < y + 1 ↔ x ≤ y := by
rw [← succ_eq_add_one, lt_succ_iff_of_not_isMax hy]
theorem lt_add_one_iff [NoMaxOrder α] : x < y + 1 ↔ x ≤ y :=
lt_add_one_iff_of_not_isMax (not_isMax y)
end Add
section Sub
variable [Sub α] [One α] [PredSubOrder α]
theorem le_of_sub_one_lt (h : x - 1 < y) : x ≤ y := by
rw [← pred_eq_sub_one] at h
exact le_of_pred_lt h
theorem sub_one_lt_iff_of_not_isMin (hx : ¬ IsMin x) : x - 1 < y ↔ x ≤ y := by
rw [← pred_eq_sub_one, pred_lt_iff_of_not_isMin hx]
theorem sub_one_lt_iff [NoMinOrder α] : x - 1 < y ↔ x ≤ y :=
sub_one_lt_iff_of_not_isMin (not_isMin x)
end Sub
theorem lt_one_iff_nonpos [AddMonoidWithOne α] [ZeroLEOneClass α] [NeZero (1 : α)]
[SuccAddOrder α] : x < 1 ↔ x ≤ 0 := by
rw [← lt_succ_iff_of_not_isMax not_isMax_zero, succ_eq_add_one, zero_add]
end LinearOrder
end Order
section Monotone
variable {α β : Type*} [PartialOrder α] [Preorder β]
section SuccAddOrder
variable [Add α] [One α] [SuccAddOrder α] [IsSuccArchimedean α] {s : Set α} {f : α → β}
lemma monotoneOn_of_le_add_one (hs : s.OrdConnected) :
(∀ a, ¬ IsMax a → a ∈ s → a + 1 ∈ s → f a ≤ f (a + 1)) → MonotoneOn f s := by
simpa [Order.succ_eq_add_one] using monotoneOn_of_le_succ hs (f := f)
lemma antitoneOn_of_add_one_le (hs : s.OrdConnected) :
(∀ a, ¬ IsMax a → a ∈ s → a + 1 ∈ s → f (a + 1) ≤ f a) → AntitoneOn f s := by
simpa [Order.succ_eq_add_one] using antitoneOn_of_succ_le hs (f := f)
lemma strictMonoOn_of_lt_add_one (hs : s.OrdConnected) :
(∀ a, ¬ IsMax a → a ∈ s → a + 1 ∈ s → f a < f (a + 1)) → StrictMonoOn f s := by
simpa [Order.succ_eq_add_one] using strictMonoOn_of_lt_succ hs (f := f)
lemma strictAntiOn_of_add_one_lt (hs : s.OrdConnected) :
(∀ a, ¬ IsMax a → a ∈ s → a + 1 ∈ s → f (a + 1) < f a) → StrictAntiOn f s := by
simpa [Order.succ_eq_add_one] using strictAntiOn_of_succ_lt hs (f := f)
lemma monotone_of_le_add_one : (∀ a, ¬ IsMax a → f a ≤ f (a + 1)) → Monotone f := by
simpa [Order.succ_eq_add_one] using monotone_of_le_succ (f := f)
lemma antitone_of_add_one_le : (∀ a, ¬ IsMax a → f (a + 1) ≤ f a) → Antitone f := by
simpa [Order.succ_eq_add_one] using antitone_of_succ_le (f := f)
lemma strictMono_of_lt_add_one : (∀ a, ¬ IsMax a → f a < f (a + 1)) → StrictMono f := by
simpa [Order.succ_eq_add_one] using strictMono_of_lt_succ (f := f)
lemma strictAnti_of_add_one_lt : (∀ a, ¬ IsMax a → f (a + 1) < f a) → StrictAnti f := by
simpa [Order.succ_eq_add_one] using strictAnti_of_succ_lt (f := f)
end SuccAddOrder
section PredSubOrder
variable [Sub α] [One α] [PredSubOrder α] [IsPredArchimedean α] {s : Set α} {f : α → β}
lemma monotoneOn_of_sub_one_le (hs : s.OrdConnected) :
(∀ a, ¬ IsMin a → a ∈ s → a - 1 ∈ s → f (a - 1) ≤ f a) → MonotoneOn f s := by
simpa [Order.pred_eq_sub_one] using monotoneOn_of_pred_le hs (f := f)
lemma antitoneOn_of_le_sub_one (hs : s.OrdConnected) :
(∀ a, ¬ IsMin a → a ∈ s → a - 1 ∈ s → f a ≤ f (a - 1)) → AntitoneOn f s := by
simpa [Order.pred_eq_sub_one] using antitoneOn_of_le_pred hs (f := f)
lemma strictMonoOn_of_sub_one_lt (hs : s.OrdConnected) :
(∀ a, ¬ IsMin a → a ∈ s → a - 1 ∈ s → f (a - 1) < f a) → StrictMonoOn f s := by
simpa [Order.pred_eq_sub_one] using strictMonoOn_of_pred_lt hs (f := f)
lemma strictAntiOn_of_lt_sub_one (hs : s.OrdConnected) :
(∀ a, ¬ IsMin a → a ∈ s → a - 1 ∈ s → f a < f (a - 1)) → StrictAntiOn f s := by
simpa [Order.pred_eq_sub_one] using strictAntiOn_of_lt_pred hs (f := f)
lemma monotone_of_sub_one_le : (∀ a, ¬ IsMin a → f (a - 1) ≤ f a) → Monotone f := by
simpa [Order.pred_eq_sub_one] using monotone_of_pred_le (f := f)
lemma antitone_of_le_sub_one : (∀ a, ¬ IsMin a → f a ≤ f (a - 1)) → Antitone f := by
simpa [Order.pred_eq_sub_one] using antitone_of_le_pred (f := f)
lemma strictMono_of_sub_one_lt : (∀ a, ¬ IsMin a → f (a - 1) < f a) → StrictMono f := by
simpa [Order.pred_eq_sub_one] using strictMono_of_pred_lt (f := f)
lemma strictAnti_of_lt_sub_one : (∀ a, ¬ IsMin a → f a < f (a - 1)) → StrictAnti f := by
simpa [Order.pred_eq_sub_one] using strictAnti_of_lt_pred (f := f)
end PredSubOrder
end Monotone |
.lake/packages/mathlib/Mathlib/Algebra/Order/PUnit.lean | import Mathlib.Algebra.Group.PUnit
import Mathlib.Algebra.Order.AddGroupWithTop
/-!
# Instances on PUnit
This file collects facts about ordered algebraic structures on the one-element type.
-/
namespace PUnit
instance canonicallyOrderedAdd : CanonicallyOrderedAdd PUnit where
exists_add_of_le {_ _} _ := ⟨unit, by subsingleton⟩
le_add_self _ _ := trivial
le_self_add _ _ := trivial
instance isOrderedCancelAddMonoid : IsOrderedCancelAddMonoid PUnit where
le_of_add_le_add_left _ _ _ _ := trivial
add_le_add_left := by intros; rfl
instance : LinearOrderedAddCommMonoidWithTop PUnit where
top := ()
le_top _ := le_rfl
top_add' _ := rfl
end PUnit |
.lake/packages/mathlib/Mathlib/Algebra/Order/Disjointed.lean | import Mathlib.Algebra.Order.SuccPred.PartialSups
import Mathlib.Data.Nat.SuccPred
import Mathlib.Order.Disjointed
/-!
# `Disjointed` for functions on a `SuccAddOrder`
This file contains material excised from `Mathlib/Order/Disjointed.lean` to avoid import
dependencies from `Mathlib.Algebra.Order` into `Mathlib.Order`.
## TODO
Find a useful statement of `disjointedRec_succ`.
-/
open Order
variable {α ι : Type*} [GeneralizedBooleanAlgebra α]
section SuccAddOrder
variable [LinearOrder ι] [LocallyFiniteOrderBot ι] [Add ι] [One ι] [SuccAddOrder ι]
theorem disjointed_add_one [NoMaxOrder ι] (f : ι → α) (i : ι) :
disjointed f (i + 1) = f (i + 1) \ partialSups f i := by
simpa only [succ_eq_add_one] using disjointed_succ f (not_isMax i)
protected lemma Monotone.disjointed_add_one_sup {f : ι → α} (hf : Monotone f) (i : ι) :
disjointed f (i + 1) ⊔ f i = f (i + 1) := by
simpa only [succ_eq_add_one i] using hf.disjointed_succ_sup i
protected lemma Monotone.disjointed_add_one [NoMaxOrder ι] {f : ι → α} (hf : Monotone f) (i : ι) :
disjointed f (i + 1) = f (i + 1) \ f i := by
rw [← succ_eq_add_one, hf.disjointed_succ]
exact not_isMax i
end SuccAddOrder
section Nat
/-- A recursion principle for `disjointed`. To construct / define something for `disjointed f i`,
it's enough to construct / define it for `f n` and to able to extend through diffs.
Note that this version allows an arbitrary `Sort*`, but requires the domain to be `Nat`, while
the root-level `disjointedRec` allows more general domains but requires `p` to be `Prop`-valued. -/
def Nat.disjointedRec {f : ℕ → α} {p : α → Sort*} (hdiff : ∀ ⦃t i⦄, p t → p (t \ f i)) :
∀ ⦃n⦄, p (f n) → p (disjointed f n)
| 0 => fun h₀ ↦ disjointed_zero f ▸ h₀
| n + 1 => fun h => by
suffices H : ∀ k, p (f (n + 1) \ partialSups f k) from disjointed_add_one f n ▸ H n
intro k
induction k with
| zero => exact hdiff h
| succ k ih => simpa only [partialSups_add_one, ← sdiff_sdiff_left] using hdiff ih
@[simp]
theorem disjointedRec_zero {f : ℕ → α} {p : α → Sort*}
(hdiff : ∀ ⦃t i⦄, p t → p (t \ f i)) (h₀ : p (f 0)) :
Nat.disjointedRec hdiff h₀ = (disjointed_zero f ▸ h₀) :=
rfl
-- TODO: Find a useful statement of `disjointedRec_succ`.
end Nat |
.lake/packages/mathlib/Mathlib/Algebra/Order/AddTorsor.lean | 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
/-- An ordered scalar multiplication is a bi-monotone scalar multiplication. Note that this is
different from `IsOrderedModule` whose defining conditions are restricted to nonnegative elements.
-/
@[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 [CommMonoid G] [PartialOrder G] [IsOrderedMonoid 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 [LE 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) _)
/-- 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] : Prop
extends IsOrderedVAdd G P 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
/-- 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] : Prop
extends IsOrderedSMul G P 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 [CommMonoid G] [PartialOrder G] [IsOrderedCancelMonoid 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_ge (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_ge] 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_ge (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_ge] at h₁
simp_all only [not_true_eq_false, and_false]
end SMul |
.lake/packages/mathlib/Mathlib/Algebra/Order/Round.lean | import Mathlib.Algebra.Order.Floor.Ring
import Mathlib.Algebra.Order.Interval.Set.Group
/-!
# Rounding
This file defines the `round` function, which uses the `floor` or `ceil` function to round a number
to the nearest integer.
## Main Definitions
* `round a`: Nearest integer to `a`. It rounds halves towards infinity.
## Tags
rounding
-/
assert_not_exists Finset
open Set
variable {F α β : Type*}
open Int
/-! ### Round -/
section round
section LinearOrderedRing
variable [Ring α] [LinearOrder α] [IsStrictOrderedRing α] [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]
@[simp]
theorem round_ofNat (n : ℕ) [n.AtLeastTwo] : round (ofNat(n) : α) = ofNat(n) :=
round_natCast n
@[simp]
theorem round_intCast (n : ℤ) : round (n : α) = n := by simp [round]
@[simp]
theorem round_add_intCast (x : α) (y : ℤ) : round (x + y) = round x + y := by
rw [round, round, Int.fract_add_intCast, Int.floor_add_intCast, Int.ceil_add_intCast,
← apply_ite₂, ite_self]
@[simp]
theorem round_add_one (a : α) : round (a + 1) = round a + 1 := by
rw [← round_add_intCast a 1, cast_one]
@[simp]
theorem round_sub_intCast (x : α) (y : ℤ) : round (x - y) = round x - y := by
rw [sub_eq_add_neg]
norm_cast
rw [round_add_intCast, sub_eq_add_neg]
@[simp]
theorem round_sub_one (a : α) : round (a - 1) = round a - 1 := by
rw [← round_sub_intCast a 1, cast_one]
@[simp]
theorem round_add_natCast (x : α) (y : ℕ) : round (x + y) = round x + y :=
mod_cast round_add_intCast x y
@[simp]
theorem round_add_ofNat (x : α) (n : ℕ) [n.AtLeastTwo] :
round (x + ofNat(n)) = round x + ofNat(n) :=
round_add_natCast x n
@[simp]
theorem round_sub_natCast (x : α) (y : ℕ) : round (x - y) = round x - y :=
mod_cast round_sub_intCast x y
@[simp]
theorem round_sub_ofNat (x : α) (n : ℕ) [n.AtLeastTwo] :
round (x - ofNat(n)) = round x - ofNat(n) :=
round_sub_natCast x n
@[simp]
theorem round_intCast_add (x : α) (y : ℤ) : round ((y : α) + x) = y + round x := by
rw [add_comm, round_add_intCast, add_comm]
@[simp]
theorem round_natCast_add (x : α) (y : ℕ) : round ((y : α) + x) = y + round x := by
rw [add_comm, round_add_natCast, add_comm]
@[simp]
theorem round_ofNat_add (n : ℕ) [n.AtLeastTwo] (x : α) :
round (ofNat(n) + x) = ofNat(n) + round x :=
round_natCast_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]
rcases 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_gt (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 [Field α] [LinearOrder α] [IsStrictOrderedRing α] [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)]
rcases lt_or_ge (fract x) (1 / 2) with hx | hx
· conv_rhs => rw [← fract_add_floor x, add_assoc, add_left_comm, floor_intCast_add]
rw [if_pos hx, left_eq_add, 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_intCast_add,
ceil_add_intCast, 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, neg_add_cancel, 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']
@[bound]
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 linarith]
exact Int.sub_one_lt_floor (x + 1 / 2)
@[bound]
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 Int
variable [Field α] [LinearOrder α] [IsStrictOrderedRing α]
[Field β] [LinearOrder β] [IsStrictOrderedRing β] [FloorRing α] [FloorRing β]
variable [FunLike F α β] [RingHomClass F α β] {a : α} {b : β}
theorem map_round (f : F) (hf : StrictMono f) (a : α) : round (f a) = round a := by
simp_rw [round_eq, ← map_floor _ hf, map_add, one_div, map_inv₀, map_ofNat]
end Int |
.lake/packages/mathlib/Mathlib/Algebra/Order/Monovary.lean | import Mathlib.Algebra.Field.Defs
import Mathlib.Algebra.Order.Module.Defs
import Mathlib.Algebra.Order.Module.Synonym
import Mathlib.Algebra.Order.Monoid.OrderDual
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
`Mathlib.Algebra.Order.Rearrangement` for the n-ary rearrangement inequality
-/
variable {ι α β : Type*}
/-! ### Algebraic operations on monovarying functions -/
section OrderedCommGroup
section
variable [CommGroup α] [PartialOrder α] [IsOrderedMonoid α] [PartialOrder β]
{s : Set ι} {f f₁ f₂ : ι → α} {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 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] 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
section
variable [PartialOrder α] [CommGroup β] [PartialOrder β] [IsOrderedMonoid β]
{s : Set ι} {f f₁ f₂ : ι → α} {g : ι → β}
@[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 (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
end
section
variable [CommGroup α] [PartialOrder α] [IsOrderedMonoid α]
[CommGroup β] [PartialOrder β] [IsOrderedMonoid β]
{s : Set ι} {f f₁ f₂ : ι → α} {g : ι → β}
@[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] lemma monovary_inv : Monovary f⁻¹ g⁻¹ ↔ Monovary f g := by simp
@[to_additive] lemma antivary_inv : Antivary f⁻¹ g⁻¹ ↔ Antivary f g := by simp
end
@[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
end OrderedCommGroup
section LinearOrderedCommGroup
variable [PartialOrder α] [CommGroup β] [LinearOrder β] [IsOrderedMonoid β] {s : Set ι} {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 [Semiring α] [PartialOrder α] [IsOrderedRing α] [PartialOrder β]
{s : Set ι} {f f₁ f₂ : ι → α} {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 [LinearOrder α] [Semiring β] [LinearOrder β] [IsStrictOrderedRing β]
{s : Set ι} {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
section
variable [Semifield α] [LinearOrder α] [IsStrictOrderedRing α] [LinearOrder β]
{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 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 _)
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
end
section
variable [LinearOrder α] [Semifield β] [LinearOrder β] [IsStrictOrderedRing β]
{s : Set ι} {f f₁ f₂ : ι → α} {g g₁ g₂ : ι → β}
@[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 simp [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 simp [inv_lt_inv₀ (hg _ hj) (hg _ hi)]
@[simp] lemma monovary_inv_right₀ (hg : StrongLT 0 g) : Monovary f g⁻¹ ↔ Antivary f g :=
forall_swap.trans <| forall₂_congr fun i j ↦ by simp [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 simp [inv_lt_inv₀ (hg _) (hg _)]
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
section
variable [Semifield α] [LinearOrder α] [IsStrictOrderedRing α]
[Semifield β] [LinearOrder β] [IsStrictOrderedRing β]
{s : Set ι} {f f₁ f₂ : ι → α} {g g₁ g₂ : ι → β}
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]
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]
end
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₀
end LinearOrderedSemifield
/-! ### Rearrangement inequality characterisation -/
section LinearOrderedAddCommGroup
variable [Ring α] [LinearOrder α] [IsStrictOrderedRing α]
[AddCommGroup β] [LinearOrder β] [IsOrderedAddMonoid β] [Module α β]
[IsStrictOrderedModule α β] {f : ι → α} {g : ι → β} {s : Set ι}
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 [Ring α] [LinearOrder α] [IsStrictOrderedRing α] {f g : ι → α} {s : Set ι}
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 |
.lake/packages/mathlib/Mathlib/Algebra/Order/ToIntervalMod.lean | import Mathlib.Algebra.ModEq
import Mathlib.Algebra.Order.Archimedean.Basic
import Mathlib.Algebra.Ring.Periodic
import Mathlib.Data.Int.SuccPred
import Mathlib.Order.Circular
/-!
# Reducing to an interval modulo its length
This file defines operations that reduce a number (in an `Archimedean`
`LinearOrderedAddCommGroup`) to a number in a given interval, modulo the length of that
interval.
## Main definitions
* `toIcoDiv hp a b` (where `hp : 0 < p`): The unique integer such that this multiple of `p`,
subtracted from `b`, is in `Ico a (a + p)`.
* `toIcoMod hp a b` (where `hp : 0 < p`): Reduce `b` to the interval `Ico a (a + p)`.
* `toIocDiv hp a b` (where `hp : 0 < p`): The unique integer such that this multiple of `p`,
subtracted from `b`, is in `Ioc a (a + p)`.
* `toIocMod hp a b` (where `hp : 0 < p`): Reduce `b` to the interval `Ioc a (a + p)`.
-/
assert_not_exists TwoSidedIdeal
noncomputable section
section LinearOrderedAddCommGroup
variable {α : Type*} [AddCommGroup α] [LinearOrder α] [IsOrderedAddMonoid α] [hα : Archimedean α]
{p : α} (hp : 0 < p)
{a b c : α} {n : ℤ}
section
include hp
/--
The unique integer such that this multiple of `p`, subtracted from `b`, is in `Ico a (a + p)`. -/
def toIcoDiv (a b : α) : ℤ :=
(existsUnique_sub_zsmul_mem_Ico hp b a).choose
theorem sub_toIcoDiv_zsmul_mem_Ico (a b : α) : b - toIcoDiv hp a b • p ∈ Set.Ico a (a + p) :=
(existsUnique_sub_zsmul_mem_Ico hp b a).choose_spec.1
theorem toIcoDiv_eq_of_sub_zsmul_mem_Ico (h : b - n • p ∈ Set.Ico a (a + p)) :
toIcoDiv hp a b = n :=
((existsUnique_sub_zsmul_mem_Ico hp b a).choose_spec.2 _ h).symm
/--
The unique integer such that this multiple of `p`, subtracted from `b`, is in `Ioc a (a + p)`. -/
def toIocDiv (a b : α) : ℤ :=
(existsUnique_sub_zsmul_mem_Ioc hp b a).choose
theorem sub_toIocDiv_zsmul_mem_Ioc (a b : α) : b - toIocDiv hp a b • p ∈ Set.Ioc a (a + p) :=
(existsUnique_sub_zsmul_mem_Ioc hp b a).choose_spec.1
theorem toIocDiv_eq_of_sub_zsmul_mem_Ioc (h : b - n • p ∈ Set.Ioc a (a + p)) :
toIocDiv hp a b = n :=
((existsUnique_sub_zsmul_mem_Ioc hp b a).choose_spec.2 _ h).symm
/-- Reduce `b` to the interval `Ico a (a + p)`. -/
def toIcoMod (a b : α) : α :=
b - toIcoDiv hp a b • p
/-- Reduce `b` to the interval `Ioc a (a + p)`. -/
def toIocMod (a b : α) : α :=
b - toIocDiv hp a b • p
theorem toIcoMod_mem_Ico (a b : α) : toIcoMod hp a b ∈ Set.Ico a (a + p) :=
sub_toIcoDiv_zsmul_mem_Ico hp a b
theorem toIcoMod_mem_Ico' (b : α) : toIcoMod hp 0 b ∈ Set.Ico 0 p := by
convert toIcoMod_mem_Ico hp 0 b
exact (zero_add p).symm
theorem toIocMod_mem_Ioc (a b : α) : toIocMod hp a b ∈ Set.Ioc a (a + p) :=
sub_toIocDiv_zsmul_mem_Ioc hp a b
theorem left_le_toIcoMod (a b : α) : a ≤ toIcoMod hp a b :=
(Set.mem_Ico.1 (toIcoMod_mem_Ico hp a b)).1
theorem left_lt_toIocMod (a b : α) : a < toIocMod hp a b :=
(Set.mem_Ioc.1 (toIocMod_mem_Ioc hp a b)).1
theorem toIcoMod_lt_right (a b : α) : toIcoMod hp a b < a + p :=
(Set.mem_Ico.1 (toIcoMod_mem_Ico hp a b)).2
theorem toIocMod_le_right (a b : α) : toIocMod hp a b ≤ a + p :=
(Set.mem_Ioc.1 (toIocMod_mem_Ioc hp a b)).2
@[simp]
theorem self_sub_toIcoDiv_zsmul (a b : α) : b - toIcoDiv hp a b • p = toIcoMod hp a b :=
rfl
@[simp]
theorem self_sub_toIocDiv_zsmul (a b : α) : b - toIocDiv hp a b • p = toIocMod hp a b :=
rfl
@[simp]
theorem toIcoDiv_zsmul_sub_self (a b : α) : toIcoDiv hp a b • p - b = -toIcoMod hp a b := by
rw [toIcoMod, neg_sub]
@[simp]
theorem toIocDiv_zsmul_sub_self (a b : α) : toIocDiv hp a b • p - b = -toIocMod hp a b := by
rw [toIocMod, neg_sub]
@[simp]
theorem toIcoMod_sub_self (a b : α) : toIcoMod hp a b - b = -toIcoDiv hp a b • p := by
rw [toIcoMod, sub_sub_cancel_left, neg_smul]
@[simp]
theorem toIocMod_sub_self (a b : α) : toIocMod hp a b - b = -toIocDiv hp a b • p := by
rw [toIocMod, sub_sub_cancel_left, neg_smul]
@[simp]
theorem self_sub_toIcoMod (a b : α) : b - toIcoMod hp a b = toIcoDiv hp a b • p := by
rw [toIcoMod, sub_sub_cancel]
@[simp]
theorem self_sub_toIocMod (a b : α) : b - toIocMod hp a b = toIocDiv hp a b • p := by
rw [toIocMod, sub_sub_cancel]
@[simp]
theorem toIcoMod_add_toIcoDiv_zsmul (a b : α) : toIcoMod hp a b + toIcoDiv hp a b • p = b := by
rw [toIcoMod, sub_add_cancel]
@[simp]
theorem toIocMod_add_toIocDiv_zsmul (a b : α) : toIocMod hp a b + toIocDiv hp a b • p = b := by
rw [toIocMod, sub_add_cancel]
@[simp]
theorem toIcoDiv_zsmul_sub_toIcoMod (a b : α) : toIcoDiv hp a b • p + toIcoMod hp a b = b := by
rw [add_comm, toIcoMod_add_toIcoDiv_zsmul]
@[simp]
theorem toIocDiv_zsmul_sub_toIocMod (a b : α) : toIocDiv hp a b • p + toIocMod hp a b = b := by
rw [add_comm, toIocMod_add_toIocDiv_zsmul]
theorem toIcoMod_eq_iff : toIcoMod hp a b = c ↔ c ∈ Set.Ico a (a + p) ∧ ∃ z : ℤ, b = c + z • p := by
refine
⟨fun h =>
⟨h ▸ toIcoMod_mem_Ico hp a b, toIcoDiv hp a b, h ▸ (toIcoMod_add_toIcoDiv_zsmul _ _ _).symm⟩,
?_⟩
simp_rw [← @sub_eq_iff_eq_add]
rintro ⟨hc, n, rfl⟩
rw [← toIcoDiv_eq_of_sub_zsmul_mem_Ico hp hc, toIcoMod]
theorem toIocMod_eq_iff : toIocMod hp a b = c ↔ c ∈ Set.Ioc a (a + p) ∧ ∃ z : ℤ, b = c + z • p := by
refine
⟨fun h =>
⟨h ▸ toIocMod_mem_Ioc hp a b, toIocDiv hp a b, h ▸ (toIocMod_add_toIocDiv_zsmul hp _ _).symm⟩,
?_⟩
simp_rw [← @sub_eq_iff_eq_add]
rintro ⟨hc, n, rfl⟩
rw [← toIocDiv_eq_of_sub_zsmul_mem_Ioc hp hc, toIocMod]
@[simp]
theorem toIcoDiv_apply_left (a : α) : toIcoDiv hp a a = 0 :=
toIcoDiv_eq_of_sub_zsmul_mem_Ico hp <| by simp [hp]
@[simp]
theorem toIocDiv_apply_left (a : α) : toIocDiv hp a a = -1 :=
toIocDiv_eq_of_sub_zsmul_mem_Ioc hp <| by simp [hp]
@[simp]
theorem toIcoMod_apply_left (a : α) : toIcoMod hp a a = a := by
rw [toIcoMod_eq_iff hp, Set.left_mem_Ico]
exact ⟨lt_add_of_pos_right _ hp, 0, by simp⟩
@[simp]
theorem toIocMod_apply_left (a : α) : toIocMod hp a a = a + p := by
rw [toIocMod_eq_iff hp, Set.right_mem_Ioc]
exact ⟨lt_add_of_pos_right _ hp, -1, by simp⟩
theorem toIcoDiv_apply_right (a : α) : toIcoDiv hp a (a + p) = 1 :=
toIcoDiv_eq_of_sub_zsmul_mem_Ico hp <| by simp [hp]
theorem toIocDiv_apply_right (a : α) : toIocDiv hp a (a + p) = 0 :=
toIocDiv_eq_of_sub_zsmul_mem_Ioc hp <| by simp [hp]
theorem toIcoMod_apply_right (a : α) : toIcoMod hp a (a + p) = a := by
rw [toIcoMod_eq_iff hp, Set.left_mem_Ico]
exact ⟨lt_add_of_pos_right _ hp, 1, by simp⟩
theorem toIocMod_apply_right (a : α) : toIocMod hp a (a + p) = a + p := by
rw [toIocMod_eq_iff hp, Set.right_mem_Ioc]
exact ⟨lt_add_of_pos_right _ hp, 0, by simp⟩
@[simp]
theorem toIcoDiv_add_zsmul (a b : α) (m : ℤ) : toIcoDiv hp a (b + m • p) = toIcoDiv hp a b + m :=
toIcoDiv_eq_of_sub_zsmul_mem_Ico hp <| by
simpa only [add_smul, add_sub_add_right_eq_sub] using sub_toIcoDiv_zsmul_mem_Ico hp a b
@[simp]
theorem toIcoDiv_add_zsmul' (a b : α) (m : ℤ) :
toIcoDiv hp (a + m • p) b = toIcoDiv hp a b - m := by
refine toIcoDiv_eq_of_sub_zsmul_mem_Ico _ ?_
rw [sub_smul, ← sub_add, add_right_comm]
simpa using sub_toIcoDiv_zsmul_mem_Ico hp a b
@[simp]
theorem toIocDiv_add_zsmul (a b : α) (m : ℤ) : toIocDiv hp a (b + m • p) = toIocDiv hp a b + m :=
toIocDiv_eq_of_sub_zsmul_mem_Ioc hp <| by
simpa only [add_smul, add_sub_add_right_eq_sub] using sub_toIocDiv_zsmul_mem_Ioc hp a b
@[simp]
theorem toIocDiv_add_zsmul' (a b : α) (m : ℤ) :
toIocDiv hp (a + m • p) b = toIocDiv hp a b - m := by
refine toIocDiv_eq_of_sub_zsmul_mem_Ioc _ ?_
rw [sub_smul, ← sub_add, add_right_comm]
simpa using sub_toIocDiv_zsmul_mem_Ioc hp a b
@[simp]
theorem toIcoDiv_zsmul_add (a b : α) (m : ℤ) : toIcoDiv hp a (m • p + b) = m + toIcoDiv hp a b := by
rw [add_comm, toIcoDiv_add_zsmul, add_comm]
/-! Note we omit `toIcoDiv_zsmul_add'` as `-m + toIcoDiv hp a b` is not very convenient. -/
@[simp]
theorem toIocDiv_zsmul_add (a b : α) (m : ℤ) : toIocDiv hp a (m • p + b) = m + toIocDiv hp a b := by
rw [add_comm, toIocDiv_add_zsmul, add_comm]
/-! Note we omit `toIocDiv_zsmul_add'` as `-m + toIocDiv hp a b` is not very convenient. -/
@[simp]
theorem toIcoDiv_sub_zsmul (a b : α) (m : ℤ) : toIcoDiv hp a (b - m • p) = toIcoDiv hp a b - m := by
rw [sub_eq_add_neg, ← neg_smul, toIcoDiv_add_zsmul, sub_eq_add_neg]
@[simp]
theorem toIcoDiv_sub_zsmul' (a b : α) (m : ℤ) :
toIcoDiv hp (a - m • p) b = toIcoDiv hp a b + m := by
rw [sub_eq_add_neg, ← neg_smul, toIcoDiv_add_zsmul', sub_neg_eq_add]
@[simp]
theorem toIocDiv_sub_zsmul (a b : α) (m : ℤ) : toIocDiv hp a (b - m • p) = toIocDiv hp a b - m := by
rw [sub_eq_add_neg, ← neg_smul, toIocDiv_add_zsmul, sub_eq_add_neg]
@[simp]
theorem toIocDiv_sub_zsmul' (a b : α) (m : ℤ) :
toIocDiv hp (a - m • p) b = toIocDiv hp a b + m := by
rw [sub_eq_add_neg, ← neg_smul, toIocDiv_add_zsmul', sub_neg_eq_add]
@[simp]
theorem toIcoDiv_add_right (a b : α) : toIcoDiv hp a (b + p) = toIcoDiv hp a b + 1 := by
simpa only [one_zsmul] using toIcoDiv_add_zsmul hp a b 1
@[simp]
theorem toIcoDiv_add_right' (a b : α) : toIcoDiv hp (a + p) b = toIcoDiv hp a b - 1 := by
simpa only [one_zsmul] using toIcoDiv_add_zsmul' hp a b 1
@[simp]
theorem toIocDiv_add_right (a b : α) : toIocDiv hp a (b + p) = toIocDiv hp a b + 1 := by
simpa only [one_zsmul] using toIocDiv_add_zsmul hp a b 1
@[simp]
theorem toIocDiv_add_right' (a b : α) : toIocDiv hp (a + p) b = toIocDiv hp a b - 1 := by
simpa only [one_zsmul] using toIocDiv_add_zsmul' hp a b 1
@[simp]
theorem toIcoDiv_add_left (a b : α) : toIcoDiv hp a (p + b) = toIcoDiv hp a b + 1 := by
rw [add_comm, toIcoDiv_add_right]
@[simp]
theorem toIcoDiv_add_left' (a b : α) : toIcoDiv hp (p + a) b = toIcoDiv hp a b - 1 := by
rw [add_comm, toIcoDiv_add_right']
@[simp]
theorem toIocDiv_add_left (a b : α) : toIocDiv hp a (p + b) = toIocDiv hp a b + 1 := by
rw [add_comm, toIocDiv_add_right]
@[simp]
theorem toIocDiv_add_left' (a b : α) : toIocDiv hp (p + a) b = toIocDiv hp a b - 1 := by
rw [add_comm, toIocDiv_add_right']
@[simp]
theorem toIcoDiv_sub (a b : α) : toIcoDiv hp a (b - p) = toIcoDiv hp a b - 1 := by
simpa only [one_zsmul] using toIcoDiv_sub_zsmul hp a b 1
@[simp]
theorem toIcoDiv_sub' (a b : α) : toIcoDiv hp (a - p) b = toIcoDiv hp a b + 1 := by
simpa only [one_zsmul] using toIcoDiv_sub_zsmul' hp a b 1
@[simp]
theorem toIocDiv_sub (a b : α) : toIocDiv hp a (b - p) = toIocDiv hp a b - 1 := by
simpa only [one_zsmul] using toIocDiv_sub_zsmul hp a b 1
@[simp]
theorem toIocDiv_sub' (a b : α) : toIocDiv hp (a - p) b = toIocDiv hp a b + 1 := by
simpa only [one_zsmul] using toIocDiv_sub_zsmul' hp a b 1
theorem toIcoDiv_sub_eq_toIcoDiv_add (a b c : α) :
toIcoDiv hp a (b - c) = toIcoDiv hp (a + c) b := by
apply toIcoDiv_eq_of_sub_zsmul_mem_Ico
rw [← sub_right_comm, Set.sub_mem_Ico_iff_left, add_right_comm]
exact sub_toIcoDiv_zsmul_mem_Ico hp (a + c) b
theorem toIocDiv_sub_eq_toIocDiv_add (a b c : α) :
toIocDiv hp a (b - c) = toIocDiv hp (a + c) b := by
apply toIocDiv_eq_of_sub_zsmul_mem_Ioc
rw [← sub_right_comm, Set.sub_mem_Ioc_iff_left, add_right_comm]
exact sub_toIocDiv_zsmul_mem_Ioc hp (a + c) b
theorem toIcoDiv_sub_eq_toIcoDiv_add' (a b c : α) :
toIcoDiv hp (a - c) b = toIcoDiv hp a (b + c) := by
rw [← sub_neg_eq_add, toIcoDiv_sub_eq_toIcoDiv_add, sub_eq_add_neg]
theorem toIocDiv_sub_eq_toIocDiv_add' (a b c : α) :
toIocDiv hp (a - c) b = toIocDiv hp a (b + c) := by
rw [← sub_neg_eq_add, toIocDiv_sub_eq_toIocDiv_add, sub_eq_add_neg]
theorem toIcoDiv_neg (a b : α) : toIcoDiv hp a (-b) = -(toIocDiv hp (-a) b + 1) := by
suffices toIcoDiv hp a (-b) = -toIocDiv hp (-(a + p)) b by
rwa [neg_add, ← sub_eq_add_neg, toIocDiv_sub_eq_toIocDiv_add', toIocDiv_add_right] at this
rw [← neg_eq_iff_eq_neg, eq_comm]
apply toIocDiv_eq_of_sub_zsmul_mem_Ioc
obtain ⟨hc, ho⟩ := sub_toIcoDiv_zsmul_mem_Ico hp a (-b)
rw [← neg_lt_neg_iff, neg_sub' (-b), neg_neg, ← neg_smul] at ho
rw [← neg_le_neg_iff, neg_sub' (-b), neg_neg, ← neg_smul] at hc
refine ⟨ho, hc.trans_eq ?_⟩
rw [neg_add, neg_add_cancel_right]
theorem toIcoDiv_neg' (a b : α) : toIcoDiv hp (-a) b = -(toIocDiv hp a (-b) + 1) := by
simpa only [neg_neg] using toIcoDiv_neg hp (-a) (-b)
theorem toIocDiv_neg (a b : α) : toIocDiv hp a (-b) = -(toIcoDiv hp (-a) b + 1) := by
rw [← neg_neg b, toIcoDiv_neg, neg_neg, neg_neg, neg_add', neg_neg, add_sub_cancel_right]
theorem toIocDiv_neg' (a b : α) : toIocDiv hp (-a) b = -(toIcoDiv hp a (-b) + 1) := by
simpa only [neg_neg] using toIocDiv_neg hp (-a) (-b)
@[simp]
theorem toIcoMod_add_zsmul (a b : α) (m : ℤ) : toIcoMod hp a (b + m • p) = toIcoMod hp a b := by
rw [toIcoMod, toIcoDiv_add_zsmul, toIcoMod, add_smul]
abel
@[simp]
theorem toIcoMod_add_zsmul' (a b : α) (m : ℤ) :
toIcoMod hp (a + m • p) b = toIcoMod hp a b + m • p := by
simp only [toIcoMod, toIcoDiv_add_zsmul', sub_smul, sub_add]
@[simp]
theorem toIocMod_add_zsmul (a b : α) (m : ℤ) : toIocMod hp a (b + m • p) = toIocMod hp a b := by
rw [toIocMod, toIocDiv_add_zsmul, toIocMod, add_smul]
abel
@[simp]
theorem toIocMod_add_zsmul' (a b : α) (m : ℤ) :
toIocMod hp (a + m • p) b = toIocMod hp a b + m • p := by
simp only [toIocMod, toIocDiv_add_zsmul', sub_smul, sub_add]
@[simp]
theorem toIcoMod_zsmul_add (a b : α) (m : ℤ) : toIcoMod hp a (m • p + b) = toIcoMod hp a b := by
rw [add_comm, toIcoMod_add_zsmul]
@[simp]
theorem toIcoMod_zsmul_add' (a b : α) (m : ℤ) :
toIcoMod hp (m • p + a) b = m • p + toIcoMod hp a b := by
rw [add_comm, toIcoMod_add_zsmul', add_comm]
@[simp]
theorem toIocMod_zsmul_add (a b : α) (m : ℤ) : toIocMod hp a (m • p + b) = toIocMod hp a b := by
rw [add_comm, toIocMod_add_zsmul]
@[simp]
theorem toIocMod_zsmul_add' (a b : α) (m : ℤ) :
toIocMod hp (m • p + a) b = m • p + toIocMod hp a b := by
rw [add_comm, toIocMod_add_zsmul', add_comm]
@[simp]
theorem toIcoMod_sub_zsmul (a b : α) (m : ℤ) : toIcoMod hp a (b - m • p) = toIcoMod hp a b := by
rw [sub_eq_add_neg, ← neg_smul, toIcoMod_add_zsmul]
@[simp]
theorem toIcoMod_sub_zsmul' (a b : α) (m : ℤ) :
toIcoMod hp (a - m • p) b = toIcoMod hp a b - m • p := by
simp_rw [sub_eq_add_neg, ← neg_smul, toIcoMod_add_zsmul']
@[simp]
theorem toIocMod_sub_zsmul (a b : α) (m : ℤ) : toIocMod hp a (b - m • p) = toIocMod hp a b := by
rw [sub_eq_add_neg, ← neg_smul, toIocMod_add_zsmul]
@[simp]
theorem toIocMod_sub_zsmul' (a b : α) (m : ℤ) :
toIocMod hp (a - m • p) b = toIocMod hp a b - m • p := by
simp_rw [sub_eq_add_neg, ← neg_smul, toIocMod_add_zsmul']
@[simp]
theorem toIcoMod_add_right (a b : α) : toIcoMod hp a (b + p) = toIcoMod hp a b := by
simpa only [one_zsmul] using toIcoMod_add_zsmul hp a b 1
@[simp]
theorem toIcoMod_add_right' (a b : α) : toIcoMod hp (a + p) b = toIcoMod hp a b + p := by
simpa only [one_zsmul] using toIcoMod_add_zsmul' hp a b 1
@[simp]
theorem toIocMod_add_right (a b : α) : toIocMod hp a (b + p) = toIocMod hp a b := by
simpa only [one_zsmul] using toIocMod_add_zsmul hp a b 1
@[simp]
theorem toIocMod_add_right' (a b : α) : toIocMod hp (a + p) b = toIocMod hp a b + p := by
simpa only [one_zsmul] using toIocMod_add_zsmul' hp a b 1
@[simp]
theorem toIcoMod_add_left (a b : α) : toIcoMod hp a (p + b) = toIcoMod hp a b := by
rw [add_comm, toIcoMod_add_right]
@[simp]
theorem toIcoMod_add_left' (a b : α) : toIcoMod hp (p + a) b = p + toIcoMod hp a b := by
rw [add_comm, toIcoMod_add_right', add_comm]
@[simp]
theorem toIocMod_add_left (a b : α) : toIocMod hp a (p + b) = toIocMod hp a b := by
rw [add_comm, toIocMod_add_right]
@[simp]
theorem toIocMod_add_left' (a b : α) : toIocMod hp (p + a) b = p + toIocMod hp a b := by
rw [add_comm, toIocMod_add_right', add_comm]
@[simp]
theorem toIcoMod_sub (a b : α) : toIcoMod hp a (b - p) = toIcoMod hp a b := by
simpa only [one_zsmul] using toIcoMod_sub_zsmul hp a b 1
@[simp]
theorem toIcoMod_sub' (a b : α) : toIcoMod hp (a - p) b = toIcoMod hp a b - p := by
simpa only [one_zsmul] using toIcoMod_sub_zsmul' hp a b 1
@[simp]
theorem toIocMod_sub (a b : α) : toIocMod hp a (b - p) = toIocMod hp a b := by
simpa only [one_zsmul] using toIocMod_sub_zsmul hp a b 1
@[simp]
theorem toIocMod_sub' (a b : α) : toIocMod hp (a - p) b = toIocMod hp a b - p := by
simpa only [one_zsmul] using toIocMod_sub_zsmul' hp a b 1
theorem toIcoMod_sub_eq_sub (a b c : α) : toIcoMod hp a (b - c) = toIcoMod hp (a + c) b - c := by
simp_rw [toIcoMod, toIcoDiv_sub_eq_toIcoDiv_add, sub_right_comm]
theorem toIocMod_sub_eq_sub (a b c : α) : toIocMod hp a (b - c) = toIocMod hp (a + c) b - c := by
simp_rw [toIocMod, toIocDiv_sub_eq_toIocDiv_add, sub_right_comm]
theorem toIcoMod_add_right_eq_add (a b c : α) :
toIcoMod hp a (b + c) = toIcoMod hp (a - c) b + c := by
simp_rw [toIcoMod, toIcoDiv_sub_eq_toIcoDiv_add', sub_add_eq_add_sub]
theorem toIocMod_add_right_eq_add (a b c : α) :
toIocMod hp a (b + c) = toIocMod hp (a - c) b + c := by
simp_rw [toIocMod, toIocDiv_sub_eq_toIocDiv_add', sub_add_eq_add_sub]
theorem toIcoMod_neg (a b : α) : toIcoMod hp a (-b) = p - toIocMod hp (-a) b := by
simp_rw [toIcoMod, toIocMod, toIcoDiv_neg, neg_smul, add_smul]
abel
theorem toIcoMod_neg' (a b : α) : toIcoMod hp (-a) b = p - toIocMod hp a (-b) := by
simpa only [neg_neg] using toIcoMod_neg hp (-a) (-b)
theorem toIocMod_neg (a b : α) : toIocMod hp a (-b) = p - toIcoMod hp (-a) b := by
simp_rw [toIocMod, toIcoMod, toIocDiv_neg, neg_smul, add_smul]
abel
theorem toIocMod_neg' (a b : α) : toIocMod hp (-a) b = p - toIcoMod hp a (-b) := by
simpa only [neg_neg] using toIocMod_neg hp (-a) (-b)
theorem toIcoMod_eq_toIcoMod : toIcoMod hp a b = toIcoMod hp a c ↔ ∃ n : ℤ, c - b = n • p := by
refine ⟨fun h => ⟨toIcoDiv hp a c - toIcoDiv hp a b, ?_⟩, fun h => ?_⟩
· conv_lhs => rw [← toIcoMod_add_toIcoDiv_zsmul hp a b, ← toIcoMod_add_toIcoDiv_zsmul hp a c]
rw [h, sub_smul]
abel
· rcases h with ⟨z, hz⟩
rw [sub_eq_iff_eq_add] at hz
rw [hz, toIcoMod_zsmul_add]
theorem toIocMod_eq_toIocMod : toIocMod hp a b = toIocMod hp a c ↔ ∃ n : ℤ, c - b = n • p := by
refine ⟨fun h => ⟨toIocDiv hp a c - toIocDiv hp a b, ?_⟩, fun h => ?_⟩
· conv_lhs => rw [← toIocMod_add_toIocDiv_zsmul hp a b, ← toIocMod_add_toIocDiv_zsmul hp a c]
rw [h, sub_smul]
abel
· rcases h with ⟨z, hz⟩
rw [sub_eq_iff_eq_add] at hz
rw [hz, toIocMod_zsmul_add]
/-! ### Links between the `Ico` and `Ioc` variants applied to the same element -/
section IcoIoc
namespace AddCommGroup
theorem modEq_iff_toIcoMod_eq_left : a ≡ b [PMOD p] ↔ toIcoMod hp a b = a :=
modEq_iff_eq_add_zsmul.trans
⟨by
rintro ⟨n, rfl⟩
rw [toIcoMod_add_zsmul, toIcoMod_apply_left], fun h => ⟨toIcoDiv hp a b, eq_add_of_sub_eq h⟩⟩
theorem modEq_iff_toIocMod_eq_right : a ≡ b [PMOD p] ↔ toIocMod hp a b = a + p := by
refine modEq_iff_eq_add_zsmul.trans ⟨?_, fun h => ⟨toIocDiv hp a b + 1, ?_⟩⟩
· rintro ⟨z, rfl⟩
rw [toIocMod_add_zsmul, toIocMod_apply_left]
· rwa [add_one_zsmul, add_left_comm, ← sub_eq_iff_eq_add']
alias ⟨ModEq.toIcoMod_eq_left, _⟩ := modEq_iff_toIcoMod_eq_left
alias ⟨ModEq.toIcoMod_eq_right, _⟩ := modEq_iff_toIocMod_eq_right
variable (a b)
open List in
theorem tfae_modEq :
TFAE
[a ≡ b [PMOD p], ∀ z : ℤ, b - z • p ∉ Set.Ioo a (a + p), toIcoMod hp a b ≠ toIocMod hp a b,
toIcoMod hp a b + p = toIocMod hp a b] := by
rw [modEq_iff_toIcoMod_eq_left hp]
tfae_have 3 → 2 := by
rw [← not_exists, not_imp_not]
exact fun ⟨i, hi⟩ =>
((toIcoMod_eq_iff hp).2 ⟨Set.Ioo_subset_Ico_self hi, i, (sub_add_cancel b _).symm⟩).trans
((toIocMod_eq_iff hp).2 ⟨Set.Ioo_subset_Ioc_self hi, i, (sub_add_cancel b _).symm⟩).symm
tfae_have 4 → 3
| h => by
rw [← h, Ne, eq_comm, add_eq_left]
exact hp.ne'
tfae_have 1 → 4
| h => by
rw [h, eq_comm, toIocMod_eq_iff, Set.right_mem_Ioc]
refine ⟨lt_add_of_pos_right a hp, toIcoDiv hp a b - 1, ?_⟩
rw [sub_one_zsmul, add_add_add_comm, add_neg_cancel, add_zero]
conv_lhs => rw [← toIcoMod_add_toIcoDiv_zsmul hp a b, h]
tfae_have 2 → 1 := by
rw [← not_exists, not_imp_comm]
have h' := toIcoMod_mem_Ico hp a b
exact fun h => ⟨_, h'.1.lt_of_ne' h, h'.2⟩
tfae_finish
variable {a b}
theorem modEq_iff_forall_notMem_Ioo_mod :
a ≡ b [PMOD p] ↔ ∀ z : ℤ, b - z • p ∉ Set.Ioo a (a + p) :=
(tfae_modEq hp a b).out 0 1
@[deprecated (since := "2025-05-23")]
alias modEq_iff_not_forall_mem_Ioo_mod := modEq_iff_forall_notMem_Ioo_mod
theorem modEq_iff_toIcoMod_ne_toIocMod : a ≡ b [PMOD p] ↔ toIcoMod hp a b ≠ toIocMod hp a b :=
(tfae_modEq hp a b).out 0 2
theorem modEq_iff_toIcoMod_add_period_eq_toIocMod :
a ≡ b [PMOD p] ↔ toIcoMod hp a b + p = toIocMod hp a b :=
(tfae_modEq hp a b).out 0 3
theorem not_modEq_iff_toIcoMod_eq_toIocMod : ¬a ≡ b [PMOD p] ↔ toIcoMod hp a b = toIocMod hp a b :=
(modEq_iff_toIcoMod_ne_toIocMod _).not_left
theorem not_modEq_iff_toIcoDiv_eq_toIocDiv :
¬a ≡ b [PMOD p] ↔ toIcoDiv hp a b = toIocDiv hp a b := by
rw [not_modEq_iff_toIcoMod_eq_toIocMod hp, toIcoMod, toIocMod, sub_right_inj,
zsmul_left_inj hp]
theorem modEq_iff_toIcoDiv_eq_toIocDiv_add_one :
a ≡ b [PMOD p] ↔ toIcoDiv hp a b = toIocDiv hp a b + 1 := by
rw [modEq_iff_toIcoMod_add_period_eq_toIocMod hp, toIcoMod, toIocMod, ← eq_sub_iff_add_eq,
sub_sub, sub_right_inj, ← add_one_zsmul, zsmul_left_inj hp]
end AddCommGroup
open AddCommGroup
/-- If `a` and `b` fall within the same cycle w.r.t. `c`, then they are congruent modulo `p`. -/
@[simp]
theorem toIcoMod_inj {c : α} : toIcoMod hp c a = toIcoMod hp c b ↔ a ≡ b [PMOD p] :=
toIcoMod_eq_toIcoMod _
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_forall_notMem_Ioo_mod hp, not_forall,
Classical.not_not]
theorem toIocDiv_wcovBy_toIcoDiv (a b : α) : toIocDiv hp a b ⩿ toIcoDiv hp a b := by
suffices toIocDiv hp a b = toIcoDiv hp a b ∨ toIocDiv hp a b + 1 = toIcoDiv hp a b by
rwa [wcovBy_iff_eq_or_covBy, ← Order.succ_eq_iff_covBy]
rw [eq_comm, ← not_modEq_iff_toIcoDiv_eq_toIocDiv, eq_comm, ←
modEq_iff_toIcoDiv_eq_toIocDiv_add_one]
exact em' _
theorem toIcoMod_le_toIocMod (a b : α) : toIcoMod hp a b ≤ toIocMod hp a b := by
rw [toIcoMod, toIocMod, sub_le_sub_iff_left]
exact zsmul_left_mono hp.le (toIocDiv_wcovBy_toIcoDiv _ _ _).le
theorem toIocMod_le_toIcoMod_add (a b : α) : toIocMod hp a b ≤ toIcoMod hp a b + p := by
rw [toIcoMod, toIocMod, sub_add, sub_le_sub_iff_left, sub_le_iff_le_add, ← add_one_zsmul,
(zsmul_left_strictMono hp).le_iff_le]
apply (toIocDiv_wcovBy_toIcoDiv _ _ _).le_succ
end IcoIoc
open AddCommGroup
theorem toIcoMod_eq_self : toIcoMod hp a b = b ↔ b ∈ Set.Ico a (a + p) := by
rw [toIcoMod_eq_iff, and_iff_left]
exact ⟨0, by simp⟩
theorem toIocMod_eq_self : toIocMod hp a b = b ↔ b ∈ Set.Ioc a (a + p) := by
rw [toIocMod_eq_iff, and_iff_left]
exact ⟨0, by simp⟩
@[simp]
theorem toIcoMod_toIcoMod (a₁ a₂ b : α) : toIcoMod hp a₁ (toIcoMod hp a₂ b) = toIcoMod hp a₁ b :=
(toIcoMod_eq_toIcoMod _).2 ⟨toIcoDiv hp a₂ b, self_sub_toIcoMod hp a₂ b⟩
@[simp]
theorem toIcoMod_toIocMod (a₁ a₂ b : α) : toIcoMod hp a₁ (toIocMod hp a₂ b) = toIcoMod hp a₁ b :=
(toIcoMod_eq_toIcoMod _).2 ⟨toIocDiv hp a₂ b, self_sub_toIocMod hp a₂ b⟩
@[simp]
theorem toIocMod_toIocMod (a₁ a₂ b : α) : toIocMod hp a₁ (toIocMod hp a₂ b) = toIocMod hp a₁ b :=
(toIocMod_eq_toIocMod _).2 ⟨toIocDiv hp a₂ b, self_sub_toIocMod hp a₂ b⟩
@[simp]
theorem toIocMod_toIcoMod (a₁ a₂ b : α) : toIocMod hp a₁ (toIcoMod hp a₂ b) = toIocMod hp a₁ b :=
(toIocMod_eq_toIocMod _).2 ⟨toIcoDiv hp a₂ b, self_sub_toIcoMod hp a₂ b⟩
theorem toIcoMod_periodic (a : α) : Function.Periodic (toIcoMod hp a) p :=
toIcoMod_add_right hp a
theorem toIocMod_periodic (a : α) : Function.Periodic (toIocMod hp a) p :=
toIocMod_add_right hp a
-- helper lemmas for when `a = 0`
section Zero
theorem toIcoMod_zero_sub_comm (a b : α) : toIcoMod hp 0 (a - b) = p - toIocMod hp 0 (b - a) := by
rw [← neg_sub, toIcoMod_neg, neg_zero]
theorem toIocMod_zero_sub_comm (a b : α) : toIocMod hp 0 (a - b) = p - toIcoMod hp 0 (b - a) := by
rw [← neg_sub, toIocMod_neg, neg_zero]
theorem toIcoDiv_eq_sub (a b : α) : toIcoDiv hp a b = toIcoDiv hp 0 (b - a) := by
rw [toIcoDiv_sub_eq_toIcoDiv_add, zero_add]
theorem toIocDiv_eq_sub (a b : α) : toIocDiv hp a b = toIocDiv hp 0 (b - a) := by
rw [toIocDiv_sub_eq_toIocDiv_add, zero_add]
theorem toIcoMod_eq_sub (a b : α) : toIcoMod hp a b = toIcoMod hp 0 (b - a) + a := by
rw [toIcoMod_sub_eq_sub, zero_add, sub_add_cancel]
theorem toIocMod_eq_sub (a b : α) : toIocMod hp a b = toIocMod hp 0 (b - a) + a := by
rw [toIocMod_sub_eq_sub, zero_add, sub_add_cancel]
theorem toIcoMod_add_toIocMod_zero (a b : α) :
toIcoMod hp 0 (a - b) + toIocMod hp 0 (b - a) = p := by
rw [toIcoMod_zero_sub_comm, sub_add_cancel]
theorem toIocMod_add_toIcoMod_zero (a b : α) :
toIocMod hp 0 (a - b) + toIcoMod hp 0 (b - a) = p := by
rw [_root_.add_comm, toIcoMod_add_toIocMod_zero]
end Zero
/-- `toIcoMod` as an equiv from the quotient. -/
@[simps symm_apply]
def QuotientAddGroup.equivIcoMod (a : α) : α ⧸ AddSubgroup.zmultiples p ≃ Set.Ico a (a + p) where
toFun b :=
⟨(toIcoMod_periodic hp a).lift b, QuotientAddGroup.induction_on b <| toIcoMod_mem_Ico hp a⟩
invFun := (↑)
right_inv b := Subtype.ext <| (toIcoMod_eq_self hp).mpr b.prop
left_inv b := by
induction b using QuotientAddGroup.induction_on
dsimp
rw [QuotientAddGroup.eq_iff_sub_mem, toIcoMod_sub_self]
apply AddSubgroup.zsmul_mem_zmultiples
@[simp]
theorem QuotientAddGroup.equivIcoMod_coe (a b : α) :
QuotientAddGroup.equivIcoMod hp a ↑b = ⟨toIcoMod hp a b, toIcoMod_mem_Ico hp a _⟩ :=
rfl
@[simp]
theorem QuotientAddGroup.equivIcoMod_zero (a : α) :
QuotientAddGroup.equivIcoMod hp a 0 = ⟨toIcoMod hp a 0, toIcoMod_mem_Ico hp a _⟩ :=
rfl
/-- `toIocMod` as an equiv from the quotient. -/
@[simps symm_apply]
def QuotientAddGroup.equivIocMod (a : α) : α ⧸ AddSubgroup.zmultiples p ≃ Set.Ioc a (a + p) where
toFun b :=
⟨(toIocMod_periodic hp a).lift b, QuotientAddGroup.induction_on b <| toIocMod_mem_Ioc hp a⟩
invFun := (↑)
right_inv b := Subtype.ext <| (toIocMod_eq_self hp).mpr b.prop
left_inv b := by
induction b using QuotientAddGroup.induction_on
dsimp
rw [QuotientAddGroup.eq_iff_sub_mem, toIocMod_sub_self]
apply AddSubgroup.zsmul_mem_zmultiples
@[simp]
theorem QuotientAddGroup.equivIocMod_coe (a b : α) :
QuotientAddGroup.equivIocMod hp a ↑b = ⟨toIocMod hp a b, toIocMod_mem_Ioc hp a _⟩ :=
rfl
@[simp]
theorem QuotientAddGroup.equivIocMod_zero (a : α) :
QuotientAddGroup.equivIocMod hp a 0 = ⟨toIocMod hp a 0, toIocMod_mem_Ioc hp a _⟩ :=
rfl
end
/-!
### The circular order structure on `α ⧸ AddSubgroup.zmultiples p`
-/
section Circular
open AddCommGroup
private theorem toIxxMod_iff (x₁ x₂ x₃ : α) : toIcoMod hp x₁ x₂ ≤ toIocMod hp x₁ x₃ ↔
toIcoMod hp 0 (x₂ - x₁) + toIcoMod hp 0 (x₁ - x₃) ≤ p := by
rw [toIcoMod_eq_sub, toIocMod_eq_sub _ x₁, add_le_add_iff_right, ← neg_sub x₁ x₃, toIocMod_neg,
neg_zero, le_sub_iff_add_le]
private theorem toIxxMod_cyclic_left {x₁ x₂ x₃ : α} (h : toIcoMod hp x₁ x₂ ≤ toIocMod hp x₁ x₃) :
toIcoMod hp x₂ x₃ ≤ toIocMod hp x₂ x₁ := by
let x₂' := toIcoMod hp x₁ x₂
let x₃' := toIcoMod hp x₂' x₃
have h : x₂' ≤ toIocMod hp x₁ x₃' := by simpa [x₃']
have h₂₁ : x₂' < x₁ + p := toIcoMod_lt_right _ _ _
have h₃₂ : x₃' - p < x₂' := sub_lt_iff_lt_add.2 (toIcoMod_lt_right _ _ _)
suffices hequiv : x₃' ≤ toIocMod hp x₂' x₁ by
obtain ⟨z, hd⟩ : ∃ z : ℤ, x₂ = x₂' + z • p := ((toIcoMod_eq_iff hp).1 rfl).2
simpa [hd, toIocMod_add_zsmul', toIcoMod_add_zsmul', add_le_add_iff_right]
rcases le_or_gt 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_gt
contradiction
private theorem toIxxMod_antisymm (h₁₂₃ : toIcoMod hp a b ≤ toIocMod hp a c)
(h₁₃₂ : toIcoMod hp a c ≤ toIocMod hp a b) :
b ≡ a [PMOD p] ∨ c ≡ b [PMOD p] ∨ a ≡ c [PMOD p] := by
by_contra! h
rw [modEq_comm] at h
rw [← (not_modEq_iff_toIcoMod_eq_toIocMod hp).mp h.2.2] at h₁₂₃
rw [← (not_modEq_iff_toIcoMod_eq_toIocMod hp).mp h.1] at h₁₃₂
exact h.2.1 ((toIcoMod_inj _).1 <| h₁₃₂.antisymm h₁₂₃)
private theorem toIxxMod_total' (a b c : α) :
toIcoMod hp b a ≤ toIocMod hp b c ∨ toIcoMod hp b c ≤ toIocMod hp b a := by
/- an essential ingredient is the lemma saying {a-b} + {b-a} = period if a ≠ b (and = 0 if a = b).
Thus if a ≠ b and b ≠ c then ({a-b} + {b-c}) + ({c-b} + {b-a}) = 2 * period, so one of
`{a-b} + {b-c}` and `{c-b} + {b-a}` must be `≤ period` -/
have := congr_arg₂ (· + ·) (toIcoMod_add_toIocMod_zero hp a b) (toIcoMod_add_toIocMod_zero hp c b)
simp only [add_add_add_comm] at this
rw [_root_.add_comm (toIocMod _ _ _), add_add_add_comm, ← two_nsmul] at this
replace := min_le_of_add_le_two_nsmul this.le
rw [min_le_iff] at this
rw [toIxxMod_iff, toIxxMod_iff]
refine this.imp (le_trans <| add_le_add_left ?_ _) (le_trans <| add_le_add_left ?_ _)
· apply toIcoMod_le_toIocMod
· apply toIcoMod_le_toIocMod
private theorem toIxxMod_total (a b c : α) :
toIcoMod hp a b ≤ toIocMod hp a c ∨ toIcoMod hp c b ≤ toIocMod hp c a :=
(toIxxMod_total' _ _ _ _).imp_right <| toIxxMod_cyclic_left _
private theorem toIxxMod_trans {x₁ x₂ x₃ x₄ : α}
(h₁₂₃ : toIcoMod hp x₁ x₂ ≤ toIocMod hp x₁ x₃ ∧ ¬toIcoMod hp x₃ x₂ ≤ toIocMod hp x₃ x₁)
(h₂₃₄ : toIcoMod hp x₂ x₄ ≤ toIocMod hp x₂ x₃ ∧ ¬toIcoMod hp x₃ x₄ ≤ toIocMod hp x₃ x₂) :
toIcoMod hp x₁ x₄ ≤ toIocMod hp x₁ x₃ ∧ ¬toIcoMod hp x₃ x₄ ≤ toIocMod hp x₃ x₁ := by
constructor
· suffices h : ¬x₃ ≡ x₂ [PMOD p] by
have h₁₂₃' := toIxxMod_cyclic_left _ (toIxxMod_cyclic_left _ h₁₂₃.1)
have h₂₃₄' := toIxxMod_cyclic_left _ (toIxxMod_cyclic_left _ h₂₃₄.1)
rw [(not_modEq_iff_toIcoMod_eq_toIocMod hp).1 h] at h₂₃₄'
exact toIxxMod_cyclic_left _ (h₁₂₃'.trans h₂₃₄')
by_contra h
rw [(modEq_iff_toIcoMod_eq_left hp).1 h] at h₁₂₃
exact h₁₂₃.2 (left_lt_toIocMod _ _ _).le
· rw [not_le] at h₁₂₃ h₂₃₄ ⊢
exact (h₁₂₃.2.trans_le (toIcoMod_le_toIocMod _ x₃ x₂)).trans h₂₃₄.2
namespace QuotientAddGroup
variable [hp' : Fact (0 < p)]
instance : Btw (α ⧸ AddSubgroup.zmultiples p) where
btw x₁ x₂ x₃ := (equivIcoMod hp'.out 0 (x₂ - x₁) : α) ≤ equivIocMod hp'.out 0 (x₃ - x₁)
theorem btw_coe_iff' {x₁ x₂ x₃ : α} :
Btw.btw (x₁ : α ⧸ AddSubgroup.zmultiples p) x₂ x₃ ↔
toIcoMod hp'.out 0 (x₂ - x₁) ≤ toIocMod hp'.out 0 (x₃ - x₁) :=
Iff.rfl
-- maybe harder to use than the primed one?
theorem btw_coe_iff {x₁ x₂ x₃ : α} :
Btw.btw (x₁ : α ⧸ AddSubgroup.zmultiples p) x₂ x₃ ↔
toIcoMod hp'.out x₁ x₂ ≤ toIocMod hp'.out x₁ x₃ := by
rw [btw_coe_iff', toIocMod_sub_eq_sub, toIcoMod_sub_eq_sub, zero_add, sub_le_sub_iff_right]
instance circularPreorder : CircularPreorder (α ⧸ AddSubgroup.zmultiples p) where
btw_refl x := show _ ≤ _ by simp [sub_self, hp'.out.le]
btw_cyclic_left {x₁ x₂ x₃} h := by
induction x₁ using QuotientAddGroup.induction_on
induction x₂ using QuotientAddGroup.induction_on
induction x₃ using QuotientAddGroup.induction_on
simp_rw [btw_coe_iff] at h ⊢
apply toIxxMod_cyclic_left _ h
sbtw := _
sbtw_iff_btw_not_btw := Iff.rfl
sbtw_trans_left {x₁ x₂ x₃ x₄} (h₁₂₃ : _ ∧ _) (h₂₃₄ : _ ∧ _) :=
show _ ∧ _ by
induction x₁ using QuotientAddGroup.induction_on
induction x₂ using QuotientAddGroup.induction_on
induction x₃ using QuotientAddGroup.induction_on
induction x₄ using QuotientAddGroup.induction_on
simp_rw [btw_coe_iff] at h₁₂₃ h₂₃₄ ⊢
apply toIxxMod_trans _ h₁₂₃ h₂₃₄
instance circularOrder : CircularOrder (α ⧸ AddSubgroup.zmultiples p) :=
{ QuotientAddGroup.circularPreorder with
btw_antisymm := fun {x₁ x₂ x₃} h₁₂₃ h₃₂₁ => by
induction x₁ using QuotientAddGroup.induction_on
induction x₂ using QuotientAddGroup.induction_on
induction x₃ using QuotientAddGroup.induction_on
rw [btw_cyclic] at h₃₂₁
simp_rw [btw_coe_iff] at h₁₂₃ h₃₂₁
simp_rw [← modEq_iff_eq_mod_zmultiples]
simpa only [modEq_comm] using toIxxMod_antisymm _ h₁₂₃ h₃₂₁
btw_total := fun x₁ x₂ x₃ => by
induction x₁ using QuotientAddGroup.induction_on
induction x₂ using QuotientAddGroup.induction_on
induction x₃ using QuotientAddGroup.induction_on
simp_rw [btw_coe_iff]
apply toIxxMod_total }
end QuotientAddGroup
end Circular
end LinearOrderedAddCommGroup
/-!
### Connections to `Int.floor` and `Int.fract`
-/
section LinearOrderedField
variable {α : Type*} [Field α] [LinearOrder α] [IsStrictOrderedRing α] [FloorRing α]
{p : α} (hp : 0 < p)
theorem toIcoDiv_eq_floor (a b : α) : toIcoDiv hp a b = ⌊(b - a) / p⌋ := by
refine toIcoDiv_eq_of_sub_zsmul_mem_Ico hp ?_
rw [Set.mem_Ico, zsmul_eq_mul, ← sub_nonneg, add_comm, sub_right_comm, ← sub_lt_iff_lt_add,
sub_right_comm _ _ a]
exact ⟨Int.sub_floor_div_mul_nonneg _ hp, Int.sub_floor_div_mul_lt _ hp⟩
theorem toIocDiv_eq_neg_floor (a b : α) : toIocDiv hp a b = -⌊(a + p - b) / p⌋ := by
refine toIocDiv_eq_of_sub_zsmul_mem_Ioc hp ?_
rw [Set.mem_Ioc, zsmul_eq_mul, Int.cast_neg, neg_mul, sub_neg_eq_add, ← sub_nonneg,
sub_add_eq_sub_sub]
refine ⟨?_, Int.sub_floor_div_mul_nonneg _ hp⟩
rw [← add_lt_add_iff_right p, add_assoc, add_comm b, ← sub_lt_iff_lt_add, add_comm (_ * _), ←
sub_lt_iff_lt_add]
exact Int.sub_floor_div_mul_lt _ hp
theorem toIcoDiv_zero_one (b : α) : toIcoDiv (zero_lt_one' α) 0 b = ⌊b⌋ := by
simp [toIcoDiv_eq_floor]
theorem toIcoMod_eq_add_fract_mul (a b : α) :
toIcoMod hp a b = a + Int.fract ((b - a) / p) * p := by
rw [toIcoMod, toIcoDiv_eq_floor, Int.fract]
simp [field, -Int.self_sub_floor]
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]
simp [field, -Int.self_sub_floor]
ring
theorem toIcoMod_zero_one (b : α) : toIcoMod (zero_lt_one' α) 0 b = Int.fract b := by
simp [toIcoMod_eq_add_fract_mul]
end LinearOrderedField
/-! ### Lemmas about unions of translates of intervals -/
section Union
open Set Int
section LinearOrderedAddCommGroup
variable {α : Type*} [AddCommGroup α] [LinearOrder α] [IsOrderedAddMonoid α] [Archimedean α]
{p : α} (hp : 0 < p) (a : α)
include hp
theorem iUnion_Ioc_add_zsmul : ⋃ n : ℤ, Ioc (a + n • p) (a + (n + 1) • p) = univ := by
refine eq_univ_iff_forall.mpr fun b => mem_iUnion.mpr ?_
rcases sub_toIocDiv_zsmul_mem_Ioc hp a b with ⟨hl, hr⟩
refine ⟨toIocDiv hp a b, ⟨lt_sub_iff_add_lt.mp hl, ?_⟩⟩
rw [add_smul, one_smul, ← add_assoc]
convert sub_le_iff_le_add.mp hr using 1; abel
theorem iUnion_Ico_add_zsmul : ⋃ n : ℤ, Ico (a + n • p) (a + (n + 1) • p) = univ := by
refine eq_univ_iff_forall.mpr fun b => mem_iUnion.mpr ?_
rcases sub_toIcoDiv_zsmul_mem_Ico hp a b with ⟨hl, hr⟩
refine ⟨toIcoDiv hp a b, ⟨le_sub_iff_add_le.mp hl, ?_⟩⟩
rw [add_smul, one_smul, ← add_assoc]
convert sub_lt_iff_lt_add.mp hr using 1; abel
theorem iUnion_Icc_add_zsmul : ⋃ n : ℤ, Icc (a + n • p) (a + (n + 1) • p) = univ := by
simpa only [iUnion_Ioc_add_zsmul hp a, univ_subset_iff] using
iUnion_mono fun n : ℤ => (Ioc_subset_Icc_self : Ioc (a + n • p) (a + (n + 1) • p) ⊆ Icc _ _)
theorem iUnion_Ioc_zsmul : ⋃ n : ℤ, Ioc (n • p) ((n + 1) • p) = univ := by
simpa only [zero_add] using iUnion_Ioc_add_zsmul hp 0
theorem iUnion_Ico_zsmul : ⋃ n : ℤ, Ico (n • p) ((n + 1) • p) = univ := by
simpa only [zero_add] using iUnion_Ico_add_zsmul hp 0
theorem iUnion_Icc_zsmul : ⋃ n : ℤ, Icc (n • p) ((n + 1) • p) = univ := by
simpa only [zero_add] using iUnion_Icc_add_zsmul hp 0
end LinearOrderedAddCommGroup
section LinearOrderedRing
variable {α : Type*} [Ring α] [LinearOrder α] [IsStrictOrderedRing α] [Archimedean α] (a : α)
theorem iUnion_Ioc_add_intCast : ⋃ n : ℤ, Ioc (a + n) (a + n + 1) = Set.univ := by
simpa only [zsmul_one, Int.cast_add, Int.cast_one, ← add_assoc] using
iUnion_Ioc_add_zsmul zero_lt_one a
theorem iUnion_Ico_add_intCast : ⋃ n : ℤ, Ico (a + n) (a + n + 1) = Set.univ := by
simpa only [zsmul_one, Int.cast_add, Int.cast_one, ← add_assoc] using
iUnion_Ico_add_zsmul zero_lt_one a
theorem iUnion_Icc_add_intCast : ⋃ n : ℤ, Icc (a + n) (a + n + 1) = Set.univ := by
simpa only [zsmul_one, Int.cast_add, Int.cast_one, ← add_assoc] using
iUnion_Icc_add_zsmul zero_lt_one a
variable (α)
theorem iUnion_Ioc_intCast : ⋃ n : ℤ, Ioc (n : α) (n + 1) = Set.univ := by
simpa only [zero_add] using iUnion_Ioc_add_intCast (0 : α)
theorem iUnion_Ico_intCast : ⋃ n : ℤ, Ico (n : α) (n + 1) = Set.univ := by
simpa only [zero_add] using iUnion_Ico_add_intCast (0 : α)
theorem iUnion_Icc_intCast : ⋃ n : ℤ, Icc (n : α) (n + 1) = Set.univ := by
simpa only [zero_add] using iUnion_Icc_add_intCast (0 : α)
end LinearOrderedRing
end Union |
.lake/packages/mathlib/Mathlib/Algebra/Order/Invertible.lean | 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 {R : Type*} [Semiring R] [LinearOrder R] [IsStrictOrderedRing R] {a : R}
@[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 R] (n : ℕ)
[Invertible (n : R)] : 0 < ⅟(n : R) :=
invOf_pos.2 <| Nat.cast_pos.2 <| pos_of_invertible_cast (R := R) n |
.lake/packages/mathlib/Mathlib/Algebra/Order/Pi.lean | import Mathlib.Algebra.Notation.Lemmas
import Mathlib.Algebra.Order.Monoid.Canonical.Defs
import Mathlib.Algebra.Order.Ring.Defs
import Mathlib.Algebra.Ring.Pi
/-!
# 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*}
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 isOrderedMonoid {ι : Type*} {Z : ι → Type*} [∀ i, CommMonoid (Z i)]
[∀ i, PartialOrder (Z i)] [∀ i, IsOrderedMonoid (Z i)] :
IsOrderedMonoid (∀ i, Z i) where
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, Monoid (Z i)] [∀ i, PartialOrder (Z i)]
[∀ i, CanonicallyOrderedMul (Z i)] :
CanonicallyOrderedMul (∀ i, Z i) where
__ := Pi.existsMulOfLe
le_mul_self _ _ := fun _ => le_mul_self
le_self_mul _ _ := fun _ => le_self_mul
@[to_additive]
instance isOrderedCancelMonoid [∀ i, CommMonoid <| f i] [∀ i, PartialOrder <| f i]
[∀ i, IsOrderedCancelMonoid <| f i] :
IsOrderedCancelMonoid (∀ i : I, f i) where
le_of_mul_le_mul_left _ _ _ h i := le_of_mul_le_mul_left' (h i)
instance isOrderedRing [∀ i, Semiring (f i)] [∀ i, PartialOrder (f i)] [∀ i, IsOrderedRing (f i)] :
IsOrderedRing (∀ i, f i) where
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 _ hc _ _ hab := fun _ => mul_le_mul_of_nonneg_left (hab _) <| hc _
mul_le_mul_of_nonneg_right _ hc _ _ hab := fun _ => mul_le_mul_of_nonneg_right (hab _) <| hc _
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
namespace Pi
variable {ι : Type*} {α : ι → Type*} [DecidableEq ι] [∀ i, One (α i)] [∀ i, Preorder (α i)] {i : ι}
{a b : α i}
@[to_additive (attr := simp)]
lemma mulSingle_le_mulSingle : mulSingle i a ≤ mulSingle i b ↔ a ≤ b := by
simp [mulSingle]
@[to_additive (attr := gcongr)] alias ⟨_, GCongr.mulSingle_mono⟩ := mulSingle_le_mulSingle
@[to_additive (attr := simp) single_nonneg]
lemma one_le_mulSingle : 1 ≤ mulSingle i a ↔ 1 ≤ a := by simp [mulSingle]
@[to_additive (attr := simp)]
lemma mulSingle_le_one : mulSingle i a ≤ 1 ↔ a ≤ 1 := by simp [mulSingle]
end Pi
-- 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 |
.lake/packages/mathlib/Mathlib/Algebra/Order/PartialSups.lean | import Mathlib.Algebra.Order.SuccPred.PartialSups
deprecated_module (since := "2025-08-18") |
.lake/packages/mathlib/Mathlib/Algebra/Order/UpperLower.lean | import Mathlib.Algebra.Group.Action.Pointwise.Set.Basic
import Mathlib.Algebra.Group.Pointwise.Set.Lattice
import Mathlib.Algebra.Order.Group.Defs
import Mathlib.Algebra.Order.Group.OrderIso
import Mathlib.Algebra.Order.Monoid.OrderDual
import Mathlib.Order.UpperLower.Closure
/-!
# 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*} [CommMonoid α] [PartialOrder α] [IsOrderedMonoid α] {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*} [CommGroup α] [PartialOrder α] [IsOrderedMonoid α] {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⟩⟩
omit [IsOrderedMonoid α] in
@[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
omit [IsOrderedMonoid α] in
@[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_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
omit [IsOrderedMonoid α] in
@[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_mul := one_mul
mul_one := fun s ↦ by
rw [mul_comm]
exact one_mul _ }
end LowerSet
variable (a s t)
omit [IsOrderedMonoid α] in
@[to_additive (attr := simp)]
theorem upperClosure_one : upperClosure (1 : Set α) = 1 :=
upperClosure_singleton _
omit [IsOrderedMonoid α] in
@[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 |
.lake/packages/mathlib/Mathlib/Algebra/Order/Rearrangement.lean | import Mathlib.Algebra.Order.Module.Defs
import Mathlib.Algebra.Order.Module.Synonym
import Mathlib.Algebra.Order.Monoid.OrderDual
import Mathlib.Data.Finset.Max
import Mathlib.Data.Prod.Lex
import Mathlib.GroupTheory.Perm.Support
import Mathlib.Order.Monotone.Monovary
/-!
# 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.
## TODO
Add equality cases for when the permute function is injective. This comes from the following fact:
If `Monovary f g`, `Injective g` and `σ` is a permutation, then `Monovary f (g ∘ σ) ↔ σ = 1`.
-/
open Equiv Equiv.Perm Finset Function OrderDual
variable {ι α β : Type*} [Semiring α] [LinearOrder α] [IsStrictOrderedRing α] [ExistsAddOfLE α]
[AddCommMonoid β] [LinearOrder β] [IsOrderedCancelAddMonoid β] [Module α β]
/-! ### Scalar multiplication versions -/
section SMul
/-! #### Weak rearrangement inequality -/
section weak_inequality
variable [PosSMulMono α β] {s : Finset ι} {σ : Perm ι} {f : ι → α} {g : ι → β}
/-- **Rearrangement Inequality**: Pointwise scalar multiplication of `f` and `g` is maximized when
`f` and `g` monovary together on `s`. 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
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.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]
grw [← 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.toLex_le_toLex] at hamax
rcases 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.toLex_le_toLex] at hamax
rcases 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
/-- **Rearrangement Inequality**: Pointwise scalar multiplication of `f` and `g` is minimized when
`f` and `g` antivary together on `s`. 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σ
/-- **Rearrangement Inequality**: Pointwise scalar multiplication of `f` and `g` is maximized when
`f` and `g` monovary together on `s`. 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σ
/-- **Rearrangement Inequality**: Pointwise scalar multiplication of `f` and `g` is minimized when
`f` and `g` antivary together on `s`. 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 :=
hfg.dual_right.sum_comp_perm_smul_le_sum_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 _
/-- **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 _
/-- **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 _
/-- **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 _
end weak_inequality
/-! #### Equality case of the rearrangement inequality -/
section equality_case
variable [PosSMulStrictMono α β] {s : Finset ι} {σ : Perm ι} {f : ι → α} {g : ι → β}
/-- **Equality case of the Rearrangement Inequality**: Pointwise scalar multiplication of `f` and
`g`, which monovary together on `s`, is unchanged by a permutation if and only if `f` and `g ∘ σ`
monovary together on `s`. 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 <| by
simpa using h.sum_smul_comp_perm_le_sum_smul ((set_support_inv_eq _).subset.trans hσ)⟩
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]
/-- **Equality case of the Rearrangement Inequality**: Pointwise scalar multiplication of `f` and
`g`, which antivary together on `s`, is unchanged by a permutation if and only if `f` and `g ∘ σ`
antivary together on `s`. 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
/-- **Equality case of the Rearrangement Inequality**: Pointwise scalar multiplication of `f` and
`g`, which monovary together on `s`, is unchanged by a permutation if and only if `f ∘ σ` and `g`
monovary together on `s`. 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
/-- **Equality case of the Rearrangement Inequality**: Pointwise scalar multiplication of `f` and
`g`, which antivary together on `s`, is unchanged by a permutation if and only if `f ∘ σ` and `g`
antivary together on `s`. 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
variable [Fintype ι]
/-- **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 _]
/-- **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 _]
/-- **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 _]
/-- **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 _]
end equality_case
/-! #### Strict rearrangement inequality -/
section strict_inequality
variable [PosSMulStrictMono α β] {s : Finset ι} {σ : Perm ι} {f : ι → α} {g : ι → β}
/-- **Strict inequality case of the Rearrangement Inequality**: Pointwise scalar multiplication of
`f` and `g`, which monovary together on `s`, is strictly decreased by a permutation if and only if
`f` and `g ∘ σ` do not monovary together on `s`. 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σ]
/-- **Strict inequality case of the Rearrangement Inequality**: Pointwise scalar multiplication of
`f` and `g`, which antivary together on `s`, is strictly decreased by a permutation if and only if
`f` and `g ∘ σ` do not antivary together on `s`. 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σ]
/-- **Strict inequality case of the Rearrangement Inequality**: Pointwise scalar multiplication of
`f` and `g`, which monovary together on `s`, is strictly decreased by a permutation if and only if
`f ∘ σ` and `g` do not monovary together on `s`. 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σ]
/-- **Strict inequality case of the Rearrangement Inequality**: Pointwise scalar multiplication of
`f` and `g`, which antivary together on `s`, is strictly decreased by a permutation if and only if
`f ∘ σ` and `g` do not antivary together on `s`. 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 ι]
/-- **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 _]
/-- **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 _]
/-- **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 _]
/-- **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 strict_inequality
end SMul
/-!
### Multiplication versions
Special cases of the above when scalar multiplication is actually multiplication.
-/
section Mul
variable {s : Finset ι} {σ : Perm ι} {f g : ι → α}
/-- **Rearrangement Inequality**: Pointwise multiplication of `f` and `g` is maximized when `f` and
`g` monovary together on `s`. 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 on `s`, is unchanged by a permutation if and only if `f` and `g ∘ σ`
monovary together on `s`. 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 on `s`, is strictly decreased by a permutation if and only if
`f` and `g ∘ σ` do not monovary together on `s`. 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 on `s`. 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 on `s`, is unchanged by a permutation if and only if `f ∘ σ` and `g`
monovary together on `s`. 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 on `s`, is strictly decreased by a permutation if and only if
`f ∘ σ` and `g` do not monovary together on `s`. 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 on `s`. 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 on `s`, is unchanged by a permutation if and only if `f` and `g ∘ σ`
antivary together on `s`. 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 on `s`, is strictly decreased by a permutation if and only if
`f` and `g ∘ σ` do not antivary together on `s`. 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 on `s`. 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 on `s`, is unchanged by a permutation if and only if `f ∘ σ` and `g`
antivary together on `s`. 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σ
/-- **Strict inequality case of the Rearrangement Inequality**: Pointwise multiplication of
`f` and `g`, which antivary together on `s`, is strictly decreased by a permutation if and only if
`f ∘ σ` and `g` do not antivary together on `s`. 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
/-- **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 |
.lake/packages/mathlib/Mathlib/Algebra/Order/ZeroLEOne.lean | import Mathlib.Algebra.Notation.Pi.Defs
import Mathlib.Algebra.Notation.Prod
import Mathlib.Order.Basic
/-!
# 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
instance ZeroLEOneClass.factZeroLeOne [Zero α] [One α] [LE α] [ZeroLEOneClass α] :
Fact ((0 : α) ≤ 1) where
out := zero_le_one
/-- `zero_le_one` with the type argument explicit. -/
lemma zero_le_one' (α) [Zero α] [One α] [LE α] [ZeroLEOneClass α] : (0 : α) ≤ 1 :=
zero_le_one
instance Prod.instZeroLEOneClass {R S : Type*} [Zero R] [One R] [LE R] [ZeroLEOneClass R]
[Zero S] [One S] [LE S] [ZeroLEOneClass S] : ZeroLEOneClass (R × S) :=
⟨⟨zero_le_one, zero_le_one⟩⟩
instance Pi.instZeroLEOneClass {ι : Type*} {R : ι → Type*} [∀ i, Zero (R i)] [∀ i, One (R i)]
[∀ i, LE (R i)] [∀ i, ZeroLEOneClass (R i)] : ZeroLEOneClass (∀ i, R i) :=
⟨fun _ ↦ 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)
instance ZeroLEOneClass.factZeroLtOne : Fact ((0 : α) < 1) where
out := zero_lt_one
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
instance Nat.instZeroLEOneClass : ZeroLEOneClass Nat := ⟨Nat.le_of_lt Nat.zero_lt_one⟩
instance Int.instZeroLEOneClass : ZeroLEOneClass Int := ⟨Int.le_of_lt Int.zero_lt_one⟩
instance Rat.instZeroLEOneClass : ZeroLEOneClass Rat := ⟨by decide⟩ |
.lake/packages/mathlib/Mathlib/Algebra/Order/Quantale.lean | import Mathlib.Algebra.Order.Monoid.Unbundled.Basic
import Mathlib.Order.CompleteLattice.Basic
import Mathlib.Tactic.Variable
/-!
# Theory of quantales
Quantales are the non-commutative generalization of locales/frames and as such are linked
to point-free topology and order theory. Applications are found throughout logic,
quantum mechanics, and computer science (see e.g. [Vickers1989] and [Mulvey1986]).
The most general definition of quantale occurring in literature, is that a quantale is a semigroup
distributing over a complete sup-semilattice. In our definition below, we use the fact that
every complete sup-semilattice is in fact a complete lattice, and make constructs defined for
those immediately available. Another view could be to define a quantale as a complete idempotent
semiring, i.e. a complete semiring in which + and sup coincide. However, we will often encounter
additive quantales, i.e. quantales in which the semigroup operator is thought of as addition, in
which case the link with semirings will lead to confusion notationally.
In this file, we follow the basic definition set out on the wikipedia page on quantales,
using a mixin typeclass to make the special cases of unital, commutative, idempotent,
integral, and involutive quantales easier to add on later.
## Main definitions
* `IsQuantale` and `IsAddQuantale` : Typeclass mixin for a (additive) semigroup distributing
over a complete lattice, i.e satisfying `x * (sSup s) = ⨆ y ∈ s, x * y` and
`(sSup s) * y = ⨆ x ∈ s, x * y`;
* `Quantale` and `AddQuantale` : Structures serving as a typeclass alias, so one can write
`variable? [Quantale α]` instead of `variable [Semigroup α] [CompleteLattice α] [IsQuantale α]`,
and similarly for the additive variant.
* `leftMulResiduation`, `rightMulResiduation`, `leftAddResiduation`, `rightAddResiduation` :
Defining the left- and right- residuations of the semigroup (see notation below).
* Finally, we provide basic distributivity laws for sSup into iSup and sup, monotonicity of
the semigroup operator, and basic equivalences for left- and right-residuation.
## Notation
* `x ⇨ₗ y` : `sSup {z | z * x ≤ y}`, the `leftMulResiduation` of `y` over `x`;
* `x ⇨ᵣ y` : `sSup {z | x * z ≤ y}`, the `rightMulResiduation` of `y` over `x`;
## References
<https://en.wikipedia.org/wiki/Quantale>
<https://encyclopediaofmath.org/wiki/Quantale>
<https://ncatlab.org/nlab/show/quantale>
-/
open Function
/-- An additive quantale is an additive semigroup distributing over a complete lattice. -/
class IsAddQuantale (α : Type*) [AddSemigroup α] [CompleteLattice α] where
/-- Addition is distributive over join in a quantale -/
protected add_sSup_distrib (x : α) (s : Set α) : x + sSup s = ⨆ y ∈ s, x + y
/-- Addition is distributive over join in a quantale -/
protected sSup_add_distrib (s : Set α) (y : α) : sSup s + y = ⨆ x ∈ s, x + y
/-- A quantale is a semigroup distributing over a complete lattice. -/
@[variable_alias]
structure AddQuantale (α : Type*)
[AddSemigroup α] [CompleteLattice α] [IsAddQuantale α]
/-- A quantale is a semigroup distributing over a complete lattice. -/
@[to_additive]
class IsQuantale (α : Type*) [Semigroup α] [CompleteLattice α] where
/-- Multiplication is distributive over join in a quantale -/
protected mul_sSup_distrib (x : α) (s : Set α) : x * sSup s = ⨆ y ∈ s, x * y
/-- Multiplication is distributive over join in a quantale -/
protected sSup_mul_distrib (s : Set α) (y : α) : sSup s * y = ⨆ x ∈ s, x * y
/-- A quantale is a semigroup distributing over a complete lattice. -/
@[variable_alias, to_additive]
structure Quantale (α : Type*)
[Semigroup α] [CompleteLattice α] [IsQuantale α]
section
variable {α : Type*} {ι : Type*} {x y z : α} {s : Set α} {f : ι → α}
variable [Semigroup α] [CompleteLattice α] [IsQuantale α]
@[to_additive]
theorem mul_sSup_distrib : x * sSup s = ⨆ y ∈ s, x * y := IsQuantale.mul_sSup_distrib _ _
@[to_additive]
theorem sSup_mul_distrib : sSup s * x = ⨆ y ∈ s, y * x := IsQuantale.sSup_mul_distrib _ _
end
namespace AddQuantale
variable {α : Type*} {ι : Type*} {x y z : α} {s : Set α} {f : ι → α}
variable [AddSemigroup α] [CompleteLattice α] [IsAddQuantale α]
/-- Left- and right- residuation operators on an additive quantale are similar
to the Heyting operator on complete lattices, but for a non-commutative logic.
I.e. `x ≤ y ⇨ₗ z ↔ x + y ≤ z` or alternatively `x ⇨ₗ y = sSup { z | z + x ≤ y }`. -/
def leftAddResiduation (x y : α) := sSup {z | z + x ≤ y}
/-- Left- and right- residuation operators on an additive quantale are similar
to the Heyting operator on complete lattices, but for a non-commutative logic.
I.e. `x ≤ y ⇨ᵣ z ↔ y + x ≤ z` or alternatively `x ⇨ₗ y = sSup { z | x + z ≤ y }`." -/
def rightAddResiduation (x y : α) := sSup {z | x + z ≤ y}
@[inherit_doc]
scoped infixr:60 " ⇨ₗ " => leftAddResiduation
@[inherit_doc]
scoped infixr:60 " ⇨ᵣ " => rightAddResiduation
end AddQuantale
namespace Quantale
variable {α : Type*} {ι : Type*} {x y z : α} {s : Set α} {f : ι → α}
variable [Semigroup α] [CompleteLattice α] [IsQuantale α]
/-- Left- and right-residuation operators on a quantale are similar to the Heyting
operator on complete lattices, but for a non-commutative logic.
I.e. `x ≤ y ⇨ₗ z ↔ x * y ≤ z` or alternatively `x ⇨ₗ y = sSup { z | z * x ≤ y }`.
-/
@[to_additive existing]
def leftMulResiduation (x y : α) := sSup {z | z * x ≤ y}
/-- Left- and right- residuation operators on a quantale are similar to the Heyting
operator on complete lattices, but for a non-commutative logic.
I.e. `x ≤ y ⇨ᵣ z ↔ y * x ≤ z` or alternatively `x ⇨ₗ y = sSup { z | x * z ≤ y }`.
-/
@[to_additive existing]
def rightMulResiduation (x y : α) := sSup {z | x * z ≤ y}
@[inherit_doc, to_additive existing]
scoped infixr:60 " ⇨ₗ " => leftMulResiduation
@[inherit_doc, to_additive existing]
scoped infixr:60 " ⇨ᵣ " => rightMulResiduation
@[to_additive]
theorem mul_iSup_distrib : x * ⨆ i, f i = ⨆ i, x * f i := by
rw [iSup, mul_sSup_distrib, iSup_range]
@[to_additive]
theorem iSup_mul_distrib : (⨆ i, f i) * x = ⨆ i, f i * x := by
rw [iSup, sSup_mul_distrib, iSup_range]
@[to_additive]
theorem mul_sup_distrib : x * (y ⊔ z) = (x * y) ⊔ (x * z) := by
rw [← iSup_pair, ← sSup_pair, mul_sSup_distrib]
@[to_additive]
theorem sup_mul_distrib : (x ⊔ y) * z = (x * z) ⊔ (y * z) := by
rw [← (@iSup_pair _ _ _ (fun _? => _? * z) _ _), ← sSup_pair, sSup_mul_distrib]
@[to_additive]
instance : MulLeftMono α where
elim := by
intro _ _ _; simp only; intro
rwa [← left_eq_sup, ← mul_sup_distrib, sup_of_le_left]
@[to_additive]
instance : MulRightMono α where
elim := by
intro _ _ _; simp only; intro
rwa [← left_eq_sup, ← sup_mul_distrib, sup_of_le_left]
@[to_additive]
theorem leftMulResiduation_le_iff_mul_le : x ≤ y ⇨ₗ z ↔ x * y ≤ z where
mp h1 := by
grw [h1]
simp_all only [leftMulResiduation, sSup_mul_distrib, Set.mem_setOf_eq,
iSup_le_iff, implies_true]
mpr h1 := le_sSup h1
@[to_additive]
theorem rightMulResiduation_le_iff_mul_le : x ≤ y ⇨ᵣ z ↔ y * x ≤ z where
mp h1 := by
grw [h1]
simp_all only [rightMulResiduation, mul_sSup_distrib, Set.mem_setOf_eq,
iSup_le_iff, implies_true]
mpr h1 := le_sSup h1
section Zero
variable {α : Type*} [Semigroup α] [CompleteLattice α] [IsQuantale α]
variable {x : α}
@[to_additive (attr := simp)]
theorem bot_mul : ⊥ * x = ⊥ := by
rw [← sSup_empty, sSup_mul_distrib]
simp only [Set.mem_empty_iff_false, not_false_eq_true, iSup_neg, iSup_bot, sSup_empty]
@[to_additive (attr := simp)]
theorem mul_bot : x * ⊥ = ⊥ := by
rw [← sSup_empty, mul_sSup_distrib]
simp only [Set.mem_empty_iff_false, not_false_eq_true, iSup_neg, iSup_bot, sSup_empty]
end Zero
end Quantale |
.lake/packages/mathlib/Mathlib/Algebra/Order/AddGroupWithTop.lean | import Mathlib.Algebra.Order.Monoid.WithTop
import Mathlib.Algebra.Group.Hom.Defs
import Mathlib.Algebra.CharZero.Defs
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
AddCommMonoid α, LinearOrder α, IsOrderedAddMonoid α, 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
[AddCommMonoid α] [LinearOrder α] [IsOrderedAddMonoid α] :
LinearOrderedAddCommMonoidWithTop (WithTop α) :=
{ top_add' := WithTop.top_add }
section LinearOrderedAddCommMonoidWithTop
variable [LinearOrderedAddCommMonoidWithTop α]
@[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
instance instNeg [AddCommGroup α] : Neg (WithTop α) where
neg := WithTop.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 [AddCommGroup α] :
WithTop α → WithTop α → WithTop α
| _, ⊤ => ⊤
| ⊤, (x : α) => ⊤
| (x : α), (y : α) => (x - y : α)
instance instSub [AddCommGroup α] : Sub (WithTop α) where
sub := WithTop.LinearOrderedAddCommGroup.sub
variable [AddCommGroup α]
@[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 [LinearOrder α] [IsOrderedAddMonoid α] : LinearOrderedAddCommGroupWithTop (WithTop α) where
__ := WithTop.linearOrderedAddCommMonoidWithTop
__ := WithTop.nontrivial
sub_eq_add_neg a b := by
cases a <;> cases b <;> simp [← coe_sub, ← coe_neg, sub_eq_add_neg]
neg_top := WithTop.map_top _
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_cancel a))
end LinearOrderedAddCommGroup
end WithTop
namespace LinearOrderedAddCommGroupWithTop
variable [LinearOrderedAddCommGroupWithTop α] {a b : α}
attribute [simp] LinearOrderedAddCommGroupWithTop.neg_top
lemma add_neg_cancel_of_ne_top {α : Type*} [LinearOrderedAddCommGroupWithTop α]
{a : α} (h : a ≠ ⊤) :
a + -a = 0 :=
LinearOrderedAddCommGroupWithTop.add_neg_cancel a h
@[simp]
lemma add_eq_top : a + b = ⊤ ↔ a = ⊤ ∨ b = ⊤ := by
constructor
· intro h
by_contra nh
rw [not_or] at nh
replace h := congrArg (-a + ·) h
dsimp only at h
rw [add_top, ← add_assoc, add_comm (-a), add_neg_cancel_of_ne_top,
zero_add] at h
· exact nh.2 h
· exact nh.1
· rintro (rfl | rfl)
· simp
· simp
@[simp]
lemma top_ne_zero :
(⊤ : α) ≠ 0 := by
intro nh
have ⟨a, b, h⟩ := Nontrivial.exists_pair_ne (α := α)
have : a + 0 ≠ b + 0 := by simpa
rw [← nh] at this
simp at this
@[simp] lemma neg_eq_top {a : α} : -a = ⊤ ↔ a = ⊤ where
mp h := by
by_contra nh
replace nh := add_neg_cancel_of_ne_top nh
rw [h, add_top] at nh
exact top_ne_zero nh
mpr h := by simp [h]
instance (priority := 100) toSubtractionMonoid : SubtractionMonoid α where
neg_neg a := by
by_cases h : a = ⊤
· simp [h]
· have h2 : ¬ -a = ⊤ := fun nh ↦ h <| neg_eq_top.mp nh
replace h2 : a + (-a + - -a) = a + 0 := congrArg (a + ·) (add_neg_cancel_of_ne_top h2)
rw [← add_assoc, add_neg_cancel_of_ne_top h] at h2
simp only [zero_add, add_zero] at h2
exact h2
neg_add_rev a b := by
by_cases ha : a = ⊤
· simp [ha]
by_cases hb : b = ⊤
· simp [hb]
apply (_ : Function.Injective (a + b + ·))
· dsimp
rw [add_neg_cancel_of_ne_top, ← add_assoc, add_assoc a,
add_neg_cancel_of_ne_top hb, add_zero,
add_neg_cancel_of_ne_top ha]
simp [ha, hb]
· apply Function.LeftInverse.injective (g := (-(a + b) + ·))
intro x
dsimp only
rw [← add_assoc, add_comm (-(a + b)), add_neg_cancel_of_ne_top, zero_add]
simp [ha, hb]
neg_eq_of_add a b h := by
have oh := congrArg (-a + ·) h
dsimp only at oh
rw [add_zero, ← add_assoc, add_comm (-a), add_neg_cancel_of_ne_top, zero_add] at oh
· exact oh.symm
intro v
simp [v] at h
lemma injective_add_left_of_ne_top (b : α) (h : b ≠ ⊤) : Function.Injective (fun x ↦ x + b) := by
intro x y h2
replace h2 : x + (b + -b) = y + (b + -b) := by simp [← add_assoc, h2]
simpa only [LinearOrderedAddCommGroupWithTop.add_neg_cancel _ h, add_zero] using h2
lemma injective_add_right_of_ne_top (b : α) (h : b ≠ ⊤) : Function.Injective (fun x ↦ b + x) := by
simpa [add_comm] using injective_add_left_of_ne_top b h
lemma strictMono_add_left_of_ne_top (b : α) (h : b ≠ ⊤) : StrictMono (fun x ↦ x + b) := by
apply Monotone.strictMono_of_injective
· apply Monotone.add_const monotone_id
· apply injective_add_left_of_ne_top _ h
lemma strictMono_add_right_of_ne_top (b : α) (h : b ≠ ⊤) : StrictMono (fun x ↦ b + x) := by
simpa [add_comm] using strictMono_add_left_of_ne_top b h
lemma sub_pos (a b : α) : 0 < a - b ↔ b < a ∨ b = ⊤ where
mp h := by
refine or_iff_not_imp_right.mpr fun h2 ↦ ?_
replace h := strictMono_add_left_of_ne_top _ h2 h
simp only [zero_add] at h
rw [sub_eq_add_neg, add_assoc, add_comm (-b),
add_neg_cancel_of_ne_top h2, add_zero] at h
exact h
mpr h := by
rcases h with h | h
· convert strictMono_add_left_of_ne_top (-b) (by simp [h.ne_top]) h using 1
· simp [add_neg_cancel_of_ne_top h.ne_top]
· simp [sub_eq_add_neg]
· rw [h]
simp only [sub_eq_add_neg, LinearOrderedAddCommGroupWithTop.neg_top, add_top]
apply lt_of_le_of_ne le_top
exact Ne.symm top_ne_zero
end LinearOrderedAddCommGroupWithTop |
.lake/packages/mathlib/Mathlib/Algebra/Order/Floor.lean | import Mathlib.Algebra.Order.Floor.Defs
import Mathlib.Algebra.Order.Floor.Ring
import Mathlib.Algebra.Order.Floor.Semiring
deprecated_module (since := "2025-04-13") |
.lake/packages/mathlib/Mathlib/Algebra/Order/Chebyshev.lean | import Mathlib.Algebra.Order.Monovary
import Mathlib.Algebra.Order.Rearrangement
import Mathlib.GroupTheory.Perm.Cycle.Basic
import Mathlib.Tactic.GCongr
import Mathlib.Tactic.Positivity
/-!
# Chebyshev's sum inequality
This file proves the Chebyshev sum inequality.
Chebyshev's inequality states `(∑ i ∈ s, f i) * (∑ i ∈ s, g i) ≤ #s * ∑ 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 [Semiring α] [LinearOrder α] [IsStrictOrderedRing α] [ExistsAddOfLE α]
[AddCommMonoid β] [LinearOrder β] [IsOrderedCancelAddMonoid β]
[Module α β] [PosSMulMono α β] {s : Finset ι} {σ : Perm ι} {f : ι → α} {g : ι → β}
/-- **Chebyshev's Sum Inequality**: When `f` and `g` monovary together (e.g. 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 • ∑ i ∈ s, f i • g i := by
classical
obtain ⟨σ, hσ, hs⟩ := s.countable_toSet.exists_cycleOn
rw [← card_range #s, 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 (e.g. 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 • ∑ i ∈ s, f i • g i ≤ (∑ i ∈ s, f i) • ∑ i ∈ s, g i :=
hfg.dual_right.sum_smul_sum_le_card_smul_sum
variable [Fintype ι]
/-- **Chebyshev's Sum Inequality**: When `f` and `g` monovary together (e.g. 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 (e.g. 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 :=
(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 [Semiring α] [LinearOrder α] [IsStrictOrderedRing α] [ExistsAddOfLE α]
{s : Finset ι} {σ : Perm ι} {f g : ι → α}
/-- **Chebyshev's Sum Inequality**: When `f` and `g` monovary together (e.g. 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 * ∑ 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 (e.g. 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 : α) * ∑ 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 **Jensen's inequality** for sums of powers. -/
lemma pow_sum_le_card_mul_sum_pow (hf : ∀ i ∈ s, 0 ≤ f i) :
∀ n, (∑ i ∈ s, f i) ^ (n + 1) ≤ (#s : α) ^ n * ∑ i ∈ s, f i ^ (n + 1)
| 0 => by simp
| n + 1 =>
calc
_ = (∑ i ∈ s, f i) ^ (n + 1) * ∑ i ∈ s, f i := by rw [pow_succ]
_ ≤ (#s ^ n * ∑ i ∈ s, f i ^ (n + 1)) * ∑ i ∈ s, f i := by
gcongr
exacts [sum_nonneg hf, pow_sum_le_card_mul_sum_pow hf _]
_ = #s ^ n * ((∑ i ∈ s, f i ^ (n + 1)) * ∑ i ∈ s, f i) := by rw [mul_assoc]
_ ≤ #s ^ n * (#s * ∑ i ∈ s, f i ^ (n + 1) * f i) := by
gcongr _ * ?_
exact ((monovaryOn_self ..).pow_left₀ hf _).sum_mul_sum_le_card_mul_sum
_ = _ := by simp_rw [← mul_assoc, ← pow_succ]
/-- 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 * ∑ 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 (e.g. 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 (e.g. 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 [Semifield α] [LinearOrder α] [IsStrictOrderedRing α] [ExistsAddOfLE α]
{s : Finset ι} {f : ι → α}
/-- Special case of **Jensen's inequality** for sums of powers. -/
lemma pow_sum_div_card_le_sum_pow (hf : ∀ i ∈ s, 0 ≤ f i) (n : ℕ) :
(∑ i ∈ s, f i) ^ (n + 1) / #s ^ n ≤ ∑ i ∈ s, f i ^ (n + 1) := by
obtain rfl | hs := s.eq_empty_or_nonempty
· simp
rw [div_le_iff₀' (by positivity)]
exact pow_sum_le_card_mul_sum_pow hf _
theorem sum_div_card_sq_le_sum_sq_div_card :
((∑ i ∈ s, f i) / #s) ^ 2 ≤ (∑ i ∈ s, f i ^ 2) / #s := by
obtain rfl | hs := s.eq_empty_or_nonempty
· simp
rw [div_pow, div_le_div_iff₀ (by positivity) (by positivity), sq (#s : α), mul_left_comm,
← mul_assoc]
exact mul_le_mul_of_nonneg_right sq_sum_le_card_mul_sum_sq (by positivity) |
.lake/packages/mathlib/Mathlib/Algebra/Order/Algebra.lean | import Mathlib.Algebra.Algebra.Defs
import Mathlib.Algebra.Order.Module.Defs
/-!
# 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 `IsOrderedModule`
and `IsStrictOrderedModule` mixins.
## Tags
ordered algebra
-/
section OrderedAlgebra
variable {R A : Type*} [CommRing R] [PartialOrder R] [IsOrderedRing R]
[Ring A] [PartialOrder A] [IsOrderedRing A] [Algebra R A] [IsOrderedModule 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 |
.lake/packages/mathlib/Mathlib/Algebra/Order/Kleene.lean | import Mathlib.Algebra.Order.Monoid.Canonical.Defs
import Mathlib.Algebra.Ring.InjSurj
import Mathlib.Algebra.Ring.Pi
import Mathlib.Algebra.Ring.Prod
import Mathlib.Tactic.Monotonicity.Attr
/-!
# 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 scope `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
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
rw [← add_assoc, h]
le_sup_right := fun a b ↦ by
rw [add_comm, add_assoc, h]
sup_le := fun a b c hab hbc ↦ by
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 _ _
scoped[Computability] attribute [simp] add_eq_sup
theorem add_idem (a : α) : a + a = a := by simp
lemma natCast_eq_one {n : ℕ} (nezero : n ≠ 0) : (n : α) = 1 := by
rw [← Nat.one_le_iff_ne_zero] at nezero
induction n, nezero using Nat.le_induction with
| base => exact Nat.cast_one
| succ x _ hx => rw [Nat.cast_add, hx, Nat.cast_one, add_idem 1]
lemma ofNat_eq_one {n : ℕ} [n.AtLeastTwo] : (ofNat(n) : α) = 1 :=
natCast_eq_one <| Nat.ne_zero_of_lt Nat.AtLeastTwo.prop
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.toIsOrderedAddMonoid :
IsOrderedAddMonoid α :=
{ add_le_add_left := fun a b hbc c ↦ by
simp_rw [add_eq_sup]
grw [hbc] }
-- See note [lower instance priority]
instance (priority := 100) IdemSemiring.toCanonicallyOrderedAdd :
CanonicallyOrderedAdd α where
exists_add_of_le h := ⟨_, h.add_eq_right.symm⟩
le_add_self a b := add_eq_left_iff_le.1 <| by rw [add_assoc, add_idem]
le_self_add a b := add_eq_right_iff_le.1 <| by rw [← add_assoc, add_idem]
-- See note [lower instance priority]
instance (priority := 100) IdemSemiring.toMulLeftMono : MulLeftMono α :=
⟨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.toMulRightMono : MulRightMono α :=
⟨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 := by grw [hb, mul_kstar_le_self ha]
theorem kstar_mul_le (hb : b ≤ c) (ha : a * c ≤ c) : a∗ * b ≤ c := by grw [hb, 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 grw [pow_succ', pow_le_kstar, 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 _ }
@[push ←]
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 β] [Max β] [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 rw [sup, add, add_eq_sup]
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 β] [Max β] [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 β] [Max β] [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
rw [kstar]
exact one_le_kstar
mul_kstar_le_kstar := fun a ↦ by
change f _ ≤ _
rw [mul, kstar]
exact mul_kstar_le_kstar
kstar_mul_le_kstar := fun a ↦ by
change f _ ≤ _
rw [mul, kstar]
exact kstar_mul_le_kstar
mul_kstar_le_self := fun a b (h : f _ ≤ _) ↦ by
change f _ ≤ _
rw [mul, kstar]
rw [mul] at h
exact mul_kstar_le_self h
kstar_mul_le_self := fun a b (h : f _ ≤ _) ↦ by
change f _ ≤ _
rw [mul, kstar]
rw [mul] at h
exact kstar_mul_le_self h }
end Function.Injective |
.lake/packages/mathlib/Mathlib/Algebra/Order/Nonneg/Module.lean | import Mathlib.Algebra.Module.RingHom
import Mathlib.Algebra.Order.Module.Defs
import Mathlib.Algebra.Order.Nonneg.Basic
/-!
# Modules over nonnegative elements
For an ordered ring `R`, this file proves that any (ordered) `R`-module `M` is also an (ordered)
`R≥0`-module.
Among other things, these instances are useful for working with `ConvexCone`.
-/
assert_not_exists Finset
variable {R S M : Type*}
local notation3 "R≥0" => {c : R // 0 ≤ c}
namespace Nonneg
variable [Semiring R] [PartialOrder R]
section SMul
variable [SMul R S]
instance instSMul : SMul R≥0 S where
smul c x := c.val • x
@[simp, norm_cast]
lemma coe_smul (a : R≥0) (x : S) : (a : R) • x = a • x :=
rfl
@[simp]
lemma mk_smul (a) (ha) (x : S) : (⟨a, ha⟩ : R≥0) • x = a • x :=
rfl
end SMul
section IsScalarTower
variable [IsOrderedRing R] [SMul R S] [SMul R M] [SMul S M] [IsScalarTower R S M]
instance instIsScalarTower : IsScalarTower R≥0 S M :=
SMul.comp.isScalarTower ↑Nonneg.coeRingHom
end IsScalarTower
section SMulWithZero
variable [Zero S] [SMulWithZero R S]
instance instSMulWithZero : SMulWithZero R≥0 S where
smul_zero _ := smul_zero _
zero_smul _ := zero_smul _ _
end SMulWithZero
section IsOrderedModule
variable [IsOrderedRing R] [AddCommMonoid M] [PartialOrder M] [IsOrderedAddMonoid M]
[SMulWithZero R M]
instance instIsOrderedModule [hM : IsOrderedModule R M] : IsOrderedModule R≥0 M where
smul_le_smul_of_nonneg_left _b hb _a₁ _a₂ ha := hM.smul_le_smul_of_nonneg_left hb ha
smul_le_smul_of_nonneg_right _b hb _a₁ _a₂ ha := hM.smul_le_smul_of_nonneg_right hb ha
instance instIsStrictOrderedModule [hM : IsStrictOrderedModule R M] :
IsStrictOrderedModule R≥0 M where
smul_lt_smul_of_pos_left _b hb _a₁ _a₂ ha := hM.smul_lt_smul_of_pos_left hb ha
smul_lt_smul_of_pos_right _b hb _a₁ _a₂ ha := hM.smul_lt_smul_of_pos_right hb ha
end IsOrderedModule
section Module
variable [IsOrderedRing R] [AddCommMonoid M] [Module R M]
/-- A module over an ordered semiring is also a module over just the non-negative scalars. -/
instance instModule : Module R≥0 M := .compHom M coeRingHom
end Module
end Nonneg |
.lake/packages/mathlib/Mathlib/Algebra/Order/Nonneg/Ring.lean | import Mathlib.Algebra.Order.GroupWithZero.Canonical
import Mathlib.Algebra.Order.Nonneg.Basic
import Mathlib.Algebra.Order.Nonneg.Lattice
import Mathlib.Algebra.Order.Ring.InjSurj
import Mathlib.Tactic.FastInstance
/-!
# Bundled ordered algebra instance on the type of nonnegative elements
This file defines instances and prove some properties about the nonnegative elements
`{x : α // 0 ≤ x}` of an arbitrary type `α`.
Currently we only state instances and states some `simp`/`norm_cast` lemmas.
When `α` is `ℝ`, this will give us some properties about `ℝ≥0`.
## Main declarations
* `{x : α // 0 ≤ x}` is a `CanonicallyLinearOrderedAddCommMonoid` if `α` is a `LinearOrderedRing`.
## Implementation Notes
Instead of `{x : α // 0 ≤ x}` we could also use `Set.Ici (0 : α)`, which is definitionally equal.
However, using the explicit subtype has a big advantage: when writing an element explicitly
with a proof of nonnegativity as `⟨x, hx⟩`, the `hx` is expected to have type `0 ≤ x`. If we would
use `Ici 0`, then the type is expected to be `x ∈ Ici 0`. Although these types are definitionally
equal, this often confuses the elaborator. Similar problems arise when doing cases on an element.
The disadvantage is that we have to duplicate some instances about `Set.Ici` to this subtype.
-/
open Set
variable {α : Type*}
namespace Nonneg
instance isOrderedAddMonoid [AddCommMonoid α] [PartialOrder α] [IsOrderedAddMonoid α] :
IsOrderedAddMonoid { x : α // 0 ≤ x } :=
Function.Injective.isOrderedAddMonoid Subtype.val Nonneg.coe_add .rfl
instance isOrderedCancelAddMonoid [AddCommMonoid α] [PartialOrder α] [IsOrderedCancelAddMonoid α] :
IsOrderedCancelAddMonoid { x : α // 0 ≤ x } :=
Function.Injective.isOrderedCancelAddMonoid _ Nonneg.coe_add .rfl
instance isOrderedRing [Semiring α] [PartialOrder α] [IsOrderedRing α] :
IsOrderedRing { x : α // 0 ≤ x } :=
Function.Injective.isOrderedRing Subtype.val Nonneg.coe_zero Nonneg.coe_one Nonneg.coe_add
Nonneg.coe_mul .rfl
instance isStrictOrderedRing [Semiring α] [PartialOrder α] [IsStrictOrderedRing α] :
IsStrictOrderedRing { x : α // 0 ≤ x } :=
Function.Injective.isStrictOrderedRing Subtype.val Nonneg.coe_zero Nonneg.coe_one Nonneg.coe_add
Nonneg.coe_mul .rfl .rfl
instance existsAddOfLE [Semiring α] [PartialOrder α] [IsStrictOrderedRing α] [ExistsAddOfLE α] :
ExistsAddOfLE { x : α // 0 ≤ x } :=
⟨fun {a b} h ↦ by
rw [← Subtype.coe_le_coe] at h
obtain ⟨c, hc⟩ := exists_add_of_le h
refine ⟨⟨c, ?_⟩, by simp [Subtype.ext_iff, hc]⟩
rw [← add_zero a.val, hc] at h
exact le_of_add_le_add_left h⟩
instance nontrivial [Semiring α] [LinearOrder α] [IsStrictOrderedRing α] :
Nontrivial { x : α // 0 ≤ x } :=
⟨⟨0, 1, fun h => zero_ne_one (congr_arg Subtype.val h)⟩⟩
instance [Nontrivial α] [AddGroup α] [LinearOrder α] [AddLeftMono α] :
Nontrivial { x : α // 0 ≤ x } := by
have ⟨a, ha⟩ := exists_ne (0 : α)
obtain lt | lt := ha.lt_or_gt
· exact ⟨0, ⟨-a, neg_nonneg.mpr lt.le⟩, Subtype.coe_ne_coe.mp (neg_ne_zero.mpr ha).symm⟩
· exact ⟨0, ⟨a, lt.le⟩, Subtype.coe_ne_coe.mp ha.symm⟩
instance linearOrderedCommMonoidWithZero [CommSemiring α] [LinearOrder α] [IsStrictOrderedRing α] :
LinearOrderedCommMonoidWithZero { x : α // 0 ≤ x } :=
{ Nonneg.commSemiring, Nonneg.isOrderedRing with
mul_le_mul_left := fun _ _ h c ↦ mul_le_mul_of_nonneg_left h c.prop }
instance canonicallyOrderedAdd [Ring α] [PartialOrder α] [IsOrderedRing α] :
CanonicallyOrderedAdd { x : α // 0 ≤ x } where
le_add_self _ b := le_add_of_nonneg_left b.2
le_self_add _ b := le_add_of_nonneg_right b.2
exists_add_of_le := fun {a b} h =>
⟨⟨b - a, sub_nonneg_of_le h⟩, Subtype.ext (add_sub_cancel _ _).symm⟩
instance noZeroDivisors [Semiring α] [PartialOrder α] [IsOrderedRing α] [NoZeroDivisors α] :
NoZeroDivisors { x : α // 0 ≤ x } :=
{ eq_zero_or_eq_zero_of_mul_eq_zero := by
rintro ⟨a, ha⟩ ⟨b, hb⟩
simp only [mk_mul_mk, mk_eq_zero, mul_eq_zero, imp_self]}
instance orderedSub [Ring α] [LinearOrder α] [IsStrictOrderedRing α] :
OrderedSub { x : α // 0 ≤ x } :=
⟨by
rintro ⟨a, ha⟩ ⟨b, hb⟩ ⟨c, hc⟩
simp only [sub_le_iff_le_add, Subtype.mk_le_mk, mk_sub_mk, mk_add_mk, toNonneg_le]⟩
end Nonneg |
.lake/packages/mathlib/Mathlib/Algebra/Order/Nonneg/Basic.lean | import Mathlib.Algebra.Order.GroupWithZero.Unbundled.Basic
import Mathlib.Algebra.Order.Monoid.Unbundled.Pow
import Mathlib.Algebra.Order.ZeroLEOne
import Mathlib.Algebra.Ring.Defs
import Mathlib.Algebra.Ring.InjSurj
import Mathlib.Data.Nat.Cast.Order.Basic
/-!
# The type of nonnegative elements
This file defines instances and prove some properties about the nonnegative elements
`{x : α // 0 ≤ x}` of an arbitrary type `α`.
Currently we only state instances and states some `simp`/`norm_cast` lemmas.
When `α` is `ℝ`, this will give us some properties about `ℝ≥0`.
## Implementation Notes
Instead of `{x : α // 0 ≤ x}` we could also use `Set.Ici (0 : α)`, which is definitionally equal.
However, using the explicit subtype has a big advantage: when writing an element explicitly
with a proof of nonnegativity as `⟨x, hx⟩`, the `hx` is expected to have type `0 ≤ x`. If we would
use `Ici 0`, then the type is expected to be `x ∈ Ici 0`. Although these types are definitionally
equal, this often confuses the elaborator. Similar problems arise when doing cases on an element.
The disadvantage is that we have to duplicate some instances about `Set.Ici` to this subtype.
-/
assert_not_exists GeneralizedHeytingAlgebra
assert_not_exists IsOrderedMonoid
-- TODO -- assert_not_exists PosMulMono
assert_not_exists mem_upperBounds
open Set
variable {α : Type*}
namespace Nonneg
instance inhabited [Preorder α] {a : α} : Inhabited { x : α // a ≤ x } :=
⟨⟨a, le_rfl⟩⟩
instance zero [Zero α] [Preorder α] : Zero { x : α // 0 ≤ x } :=
⟨⟨0, le_rfl⟩⟩
@[simp, norm_cast]
protected theorem coe_zero [Zero α] [Preorder α] : ((0 : { x : α // 0 ≤ x }) : α) = 0 :=
rfl
@[simp]
theorem mk_eq_zero [Zero α] [Preorder α] {x : α} (hx : 0 ≤ x) :
(⟨x, hx⟩ : { x : α // 0 ≤ x }) = 0 ↔ x = 0 :=
Subtype.ext_iff
instance add [AddZeroClass α] [Preorder α] [AddLeftMono α] : Add { x : α // 0 ≤ x } :=
⟨fun x y => ⟨x + y, add_nonneg x.2 y.2⟩⟩
@[simp]
theorem mk_add_mk [AddZeroClass α] [Preorder α] [AddLeftMono α] {x y : α}
(hx : 0 ≤ x) (hy : 0 ≤ y) :
(⟨x, hx⟩ : { x : α // 0 ≤ x }) + ⟨y, hy⟩ = ⟨x + y, add_nonneg hx hy⟩ :=
rfl
@[simp, norm_cast]
protected theorem coe_add [AddZeroClass α] [Preorder α] [AddLeftMono α]
(a b : { x : α // 0 ≤ x }) : ((a + b : { x : α // 0 ≤ x }) : α) = a + b :=
rfl
instance [AddZeroClass α] [Preorder α] [AddLeftMono α] [IsLeftCancelAdd α] :
IsLeftCancelAdd { x : α // 0 ≤ x } where
add_left_cancel _ _ _ eq := Subtype.ext (add_left_cancel congr($eq))
instance [AddZeroClass α] [Preorder α] [AddLeftMono α] [IsRightCancelAdd α] :
IsRightCancelAdd { x : α // 0 ≤ x } where
add_right_cancel _ _ _ eq := Subtype.ext (add_right_cancel congr($eq))
instance [AddZeroClass α] [Preorder α] [AddLeftMono α] [IsCancelAdd α] :
IsCancelAdd { x : α // 0 ≤ x } where
instance nsmul [AddMonoid α] [Preorder α] [AddLeftMono α] : SMul ℕ { x : α // 0 ≤ x } :=
⟨fun n x => ⟨n • (x : α), nsmul_nonneg x.prop n⟩⟩
@[simp]
theorem nsmul_mk [AddMonoid α] [Preorder α] [AddLeftMono α] (n : ℕ) {x : α}
(hx : 0 ≤ x) : (n • (⟨x, hx⟩ : { x : α // 0 ≤ x })) = ⟨n • x, nsmul_nonneg hx n⟩ :=
rfl
@[simp, norm_cast]
protected theorem coe_nsmul [AddMonoid α] [Preorder α] [AddLeftMono α]
(n : ℕ) (a : { x : α // 0 ≤ x }) : ((n • a : { x : α // 0 ≤ x }) : α) = n • (a : α) :=
rfl
section One
variable [Zero α] [One α] [LE α] [ZeroLEOneClass α]
instance one : One { x : α // 0 ≤ x } where
one := ⟨1, zero_le_one⟩
@[simp, norm_cast]
protected theorem coe_one : ((1 : { x : α // 0 ≤ x }) : α) = 1 :=
rfl
@[simp]
theorem mk_eq_one {x : α} (hx : 0 ≤ x) :
(⟨x, hx⟩ : { x : α // 0 ≤ x }) = 1 ↔ x = 1 :=
Subtype.ext_iff
end One
section Mul
variable [MulZeroClass α] [Preorder α] [PosMulMono α]
instance mul : Mul { x : α // 0 ≤ x } where
mul x y := ⟨x * y, mul_nonneg x.2 y.2⟩
@[simp, norm_cast]
protected theorem coe_mul (a b : { x : α // 0 ≤ x }) :
((a * b : { x : α // 0 ≤ x }) : α) = a * b :=
rfl
@[simp]
theorem mk_mul_mk {x y : α} (hx : 0 ≤ x) (hy : 0 ≤ y) :
(⟨x, hx⟩ : { x : α // 0 ≤ x }) * ⟨y, hy⟩ = ⟨x * y, mul_nonneg hx hy⟩ :=
rfl
end Mul
section AddMonoid
variable [AddMonoid α] [Preorder α] [AddLeftMono α]
instance addMonoid : AddMonoid { x : α // 0 ≤ x } :=
Subtype.coe_injective.addMonoid _ Nonneg.coe_zero (fun _ _ => rfl) fun _ _ => rfl
/-- Coercion `{x : α // 0 ≤ x} → α` as an `AddMonoidHom`. -/
@[simps]
def coeAddMonoidHom : { x : α // 0 ≤ x } →+ α :=
{ toFun := ((↑) : { x : α // 0 ≤ x } → α)
map_zero' := Nonneg.coe_zero
map_add' := Nonneg.coe_add }
@[norm_cast]
theorem nsmul_coe (n : ℕ) (r : { x : α // 0 ≤ x }) :
↑(n • r) = n • (r : α) :=
Nonneg.coeAddMonoidHom.map_nsmul _ _
end AddMonoid
section AddCommMonoid
variable [AddCommMonoid α] [Preorder α] [AddLeftMono α]
instance addCommMonoid : AddCommMonoid { x : α // 0 ≤ x } :=
Subtype.coe_injective.addCommMonoid _ Nonneg.coe_zero (fun _ _ => rfl) (fun _ _ => rfl)
end AddCommMonoid
section AddMonoidWithOne
variable [AddMonoidWithOne α] [PartialOrder α] [AddLeftMono α] [ZeroLEOneClass α]
instance natCast : NatCast { x : α // 0 ≤ x } :=
⟨fun n => ⟨n, Nat.cast_nonneg' n⟩⟩
@[simp, norm_cast]
protected theorem coe_natCast (n : ℕ) : ((↑n : { x : α // 0 ≤ x }) : α) = n :=
rfl
@[simp]
theorem mk_natCast (n : ℕ) : (⟨n, n.cast_nonneg'⟩ : { x : α // 0 ≤ x }) = n :=
rfl
instance addMonoidWithOne : AddMonoidWithOne { x : α // 0 ≤ x } :=
{ Nonneg.one (α := α) with
toNatCast := Nonneg.natCast
natCast_zero := by ext; simp
natCast_succ := fun _ => by ext; simp }
end AddMonoidWithOne
section Pow
variable [MonoidWithZero α] [Preorder α] [ZeroLEOneClass α] [PosMulMono α]
instance pow : Pow { x : α // 0 ≤ x } ℕ where
pow x n := ⟨(x : α) ^ n, pow_nonneg x.2 n⟩
@[simp, norm_cast]
protected theorem coe_pow (a : { x : α // 0 ≤ x }) (n : ℕ) :
(↑(a ^ n) : α) = (a : α) ^ n :=
rfl
@[simp]
theorem mk_pow {x : α} (hx : 0 ≤ x) (n : ℕ) :
(⟨x, hx⟩ : { x : α // 0 ≤ x }) ^ n = ⟨x ^ n, pow_nonneg hx n⟩ :=
rfl
@[deprecated (since := "2025-05-19")] alias pow_nonneg := _root_.pow_nonneg
end Pow
section Semiring
variable [Semiring α] [PartialOrder α] [ZeroLEOneClass α]
[AddLeftMono α] [PosMulMono α]
instance semiring : Semiring { x : α // 0 ≤ x } :=
Subtype.coe_injective.semiring _ Nonneg.coe_zero Nonneg.coe_one
(fun _ _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl)
(fun _ _ => rfl) fun _ => rfl
instance monoidWithZero : MonoidWithZero { x : α // 0 ≤ x } := by infer_instance
/-- Coercion `{x : α // 0 ≤ x} → α` as a `RingHom`. -/
def coeRingHom : { x : α // 0 ≤ x } →+* α :=
{ toFun := ((↑) : { x : α // 0 ≤ x } → α)
map_one' := Nonneg.coe_one
map_mul' := Nonneg.coe_mul
map_zero' := Nonneg.coe_zero,
map_add' := Nonneg.coe_add }
end Semiring
section CommSemiring
variable [CommSemiring α] [PartialOrder α] [ZeroLEOneClass α]
[AddLeftMono α] [PosMulMono α]
instance commSemiring : CommSemiring { x : α // 0 ≤ x } :=
Subtype.coe_injective.commSemiring _ Nonneg.coe_zero Nonneg.coe_one
(fun _ _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl)
(fun _ _ => rfl) fun _ => rfl
instance commMonoidWithZero : CommMonoidWithZero { x : α // 0 ≤ x } := inferInstance
end CommSemiring
section SemilatticeSup
variable [Zero α] [SemilatticeSup α]
/-- The function `a ↦ max a 0` of type `α → {x : α // 0 ≤ x}`. -/
def toNonneg (a : α) : { x : α // 0 ≤ x } :=
⟨max a 0, le_sup_right⟩
@[simp]
theorem coe_toNonneg {a : α} : (toNonneg a : α) = max a 0 :=
rfl
@[simp]
theorem toNonneg_of_nonneg {a : α} (h : 0 ≤ a) : toNonneg a = ⟨a, h⟩ := by simp [toNonneg, h]
@[simp]
theorem toNonneg_coe {a : { x : α // 0 ≤ x }} : toNonneg (a : α) = a :=
toNonneg_of_nonneg a.2
@[simp]
theorem toNonneg_le {a : α} {b : { x : α // 0 ≤ x }} : toNonneg a ≤ b ↔ a ≤ b := by
obtain ⟨b, hb⟩ := b
simp [toNonneg, hb]
instance sub [Sub α] : Sub { x : α // 0 ≤ x } :=
⟨fun x y => toNonneg (x - y)⟩
@[simp]
theorem mk_sub_mk [Sub α] {x y : α} (hx : 0 ≤ x) (hy : 0 ≤ y) :
(⟨x, hx⟩ : { x : α // 0 ≤ x }) - ⟨y, hy⟩ = toNonneg (x - y) :=
rfl
end SemilatticeSup
section LinearOrder
variable [Zero α] [LinearOrder α]
@[simp]
theorem toNonneg_lt {a : { x : α // 0 ≤ x }} {b : α} : a < toNonneg b ↔ ↑a < b := by
obtain ⟨a, ha⟩ := a
simp [toNonneg, ha.not_gt]
end LinearOrder
end Nonneg |
.lake/packages/mathlib/Mathlib/Algebra/Order/Nonneg/Floor.lean | import Mathlib.Algebra.Order.Floor.Defs
import Mathlib.Algebra.Order.Nonneg.Basic
/-!
# Nonnegative elements are archimedean
This file defines instances and prove some properties about the nonnegative elements
`{x : α // 0 ≤ x}` of an arbitrary type `α`.
This is used to derive algebraic structures on `ℝ≥0` and `ℚ≥0` automatically.
## Main declarations
* `{x : α // 0 ≤ x}` is a `FloorSemiring` if `α` is.
-/
assert_not_exists Finset Field
namespace Nonneg
variable {α : Type*}
instance floorSemiring [Semiring α] [PartialOrder α] [IsOrderedRing α] [FloorSemiring α] :
FloorSemiring { r : α // 0 ≤ r } where
floor a := ⌊(a : α)⌋₊
ceil a := ⌈(a : α)⌉₊
floor_of_neg ha := FloorSemiring.floor_of_neg ha
gc_floor ha := FloorSemiring.gc_floor (Subtype.coe_le_coe.2 ha)
gc_ceil a n := FloorSemiring.gc_ceil (a : α) n
@[norm_cast]
theorem nat_floor_coe [Semiring α] [PartialOrder α] [IsOrderedRing α] [FloorSemiring α]
(a : { r : α // 0 ≤ r }) :
⌊(a : α)⌋₊ = ⌊a⌋₊ :=
rfl
@[norm_cast]
theorem nat_ceil_coe [Semiring α] [PartialOrder α] [IsOrderedRing α] [FloorSemiring α]
(a : { r : α // 0 ≤ r }) :
⌈(a : α)⌉₊ = ⌈a⌉₊ :=
rfl
end Nonneg |
.lake/packages/mathlib/Mathlib/Algebra/Order/Nonneg/Field.lean | import Mathlib.Algebra.Field.Basic
import Mathlib.Algebra.Order.Field.Canonical
import Mathlib.Algebra.Order.Nonneg.Ring
import Mathlib.Algebra.Order.Positive.Ring
import Mathlib.Data.Nat.Cast.Order.Ring
/-!
# Semifield structure on the type of nonnegative elements
This file defines instances and prove some properties about the nonnegative elements
`{x : α // 0 ≤ x}` of an arbitrary type `α`.
This is used to derive algebraic structures on `ℝ≥0` and `ℚ≥0` automatically.
## Main declarations
* `{x : α // 0 ≤ x}` is a `CanonicallyLinearOrderedSemifield` if `α` is a `LinearOrderedField`.
-/
assert_not_exists abs_inv
open Set
variable {α : Type*}
section NNRat
variable [Semifield α] [LinearOrder α] [IsStrictOrderedRing α] {a : α}
lemma NNRat.cast_nonneg (q : ℚ≥0) : 0 ≤ (q : α) := by
rw [cast_def]; exact div_nonneg q.num.cast_nonneg q.den.cast_nonneg
lemma nnqsmul_nonneg (q : ℚ≥0) (ha : 0 ≤ a) : 0 ≤ q • a := by
rw [NNRat.smul_def]; exact mul_nonneg q.cast_nonneg ha
end NNRat
namespace Nonneg
/-- In an ordered field, the units of the nonnegative elements are the positive elements. -/
@[simps]
def unitsEquivPos (R : Type*) [DivisionSemiring R] [PartialOrder R]
[IsStrictOrderedRing R] [PosMulReflectLT R] :
{ r : R // 0 ≤ r }ˣ ≃* { r : R // 0 < r } where
toFun r := ⟨r, lt_of_le_of_ne r.1.2 (Subtype.val_injective.ne r.ne_zero.symm)⟩
invFun r := ⟨⟨r.1, r.2.le⟩, ⟨r.1⁻¹, inv_nonneg.mpr r.2.le⟩,
by ext; simp [r.2.ne'], by ext; simp [r.2.ne']⟩
left_inv r := by ext; rfl
right_inv r := by ext; rfl
map_mul' _ _ := rfl
section LinearOrderedSemifield
variable [Semifield α] [LinearOrder α] [IsStrictOrderedRing α] {x y : α}
instance inv : Inv { x : α // 0 ≤ x } :=
⟨fun x => ⟨x⁻¹, inv_nonneg.2 x.2⟩⟩
@[simp, norm_cast]
protected theorem coe_inv (a : { x : α // 0 ≤ x }) : ((a⁻¹ : { x : α // 0 ≤ x }) : α) = (a : α)⁻¹ :=
rfl
@[simp]
theorem inv_mk (hx : 0 ≤ x) :
(⟨x, hx⟩ : { x : α // 0 ≤ x })⁻¹ = ⟨x⁻¹, inv_nonneg.2 hx⟩ :=
rfl
instance div : Div { x : α // 0 ≤ x } :=
⟨fun x y => ⟨x / y, div_nonneg x.2 y.2⟩⟩
@[simp, norm_cast]
protected theorem coe_div (a b : { x : α // 0 ≤ x }) : ((a / b : { x : α // 0 ≤ x }) : α) = a / b :=
rfl
@[simp]
theorem mk_div_mk (hx : 0 ≤ x) (hy : 0 ≤ y) :
(⟨x, hx⟩ : { x : α // 0 ≤ x }) / ⟨y, hy⟩ = ⟨x / y, div_nonneg hx hy⟩ :=
rfl
instance zpow : Pow { x : α // 0 ≤ x } ℤ :=
⟨fun a n => ⟨(a : α) ^ n, zpow_nonneg a.2 _⟩⟩
@[simp, norm_cast]
protected theorem coe_zpow (a : { x : α // 0 ≤ x }) (n : ℤ) :
((a ^ n : { x : α // 0 ≤ x }) : α) = (a : α) ^ n :=
rfl
@[simp]
theorem mk_zpow (hx : 0 ≤ x) (n : ℤ) :
(⟨x, hx⟩ : { x : α // 0 ≤ x }) ^ n = ⟨x ^ n, zpow_nonneg hx n⟩ :=
rfl
instance instNNRatCast : NNRatCast {x : α // 0 ≤ x} := ⟨fun q ↦ ⟨q, q.cast_nonneg⟩⟩
instance instNNRatSMul : SMul ℚ≥0 {x : α // 0 ≤ x} where
smul q a := ⟨q • a, by rw [NNRat.smul_def]; exact mul_nonneg q.cast_nonneg a.2⟩
@[simp, norm_cast] lemma coe_nnratCast (q : ℚ≥0) : (q : {x : α // 0 ≤ x}) = (q : α) := rfl
@[simp] lemma mk_nnratCast (q : ℚ≥0) : (⟨q, q.cast_nonneg⟩ : {x : α // 0 ≤ x}) = q := rfl
@[simp, norm_cast] lemma coe_nnqsmul (q : ℚ≥0) (a : {x : α // 0 ≤ x}) :
↑(q • a) = (q • a : α) := rfl
@[simp] lemma mk_nnqsmul (q : ℚ≥0) (a : α) (ha : 0 ≤ a) :
(⟨q • a, by rw [NNRat.smul_def]; exact mul_nonneg q.cast_nonneg ha⟩ : {x : α // 0 ≤ x}) =
q • a := rfl
instance semifield : Semifield { x : α // 0 ≤ x } := fast_instance%
Subtype.coe_injective.semifield _ Nonneg.coe_zero Nonneg.coe_one Nonneg.coe_add
Nonneg.coe_mul Nonneg.coe_inv Nonneg.coe_div (fun _ _ => rfl) coe_nnqsmul Nonneg.coe_pow
Nonneg.coe_zpow Nonneg.coe_natCast coe_nnratCast
end LinearOrderedSemifield
instance linearOrderedCommGroupWithZero [Field α] [LinearOrder α] [IsStrictOrderedRing α] :
LinearOrderedCommGroupWithZero { x : α // 0 ≤ x } :=
CanonicallyOrderedAdd.toLinearOrderedCommGroupWithZero
end Nonneg |
.lake/packages/mathlib/Mathlib/Algebra/Order/Nonneg/Lattice.lean | import Mathlib.Order.CompleteLatticeIntervals
import Mathlib.Order.LatticeIntervals
/-!
# Lattice structures on the type of nonnegative elements
-/
assert_not_exists Ring
assert_not_exists IsOrderedMonoid
open Set
variable {α : Type*}
namespace Nonneg
/-- This instance uses data fields from `Subtype.partialOrder` to help type-class inference.
The `Set.Ici` data fields are definitionally equal, but that requires unfolding semireducible
definitions, so type-class inference won't see this. -/
instance orderBot [Preorder α] {a : α} : OrderBot { x : α // a ≤ x } :=
{ Set.Ici.orderBot with }
theorem bot_eq [Preorder α] {a : α} : (⊥ : { x : α // a ≤ x }) = ⟨a, le_rfl⟩ :=
rfl
instance noMaxOrder [PartialOrder α] [NoMaxOrder α] {a : α} : NoMaxOrder { x : α // a ≤ x } :=
show NoMaxOrder (Ici a) by infer_instance
instance semilatticeSup [SemilatticeSup α] {a : α} : SemilatticeSup { x : α // a ≤ x } :=
Set.Ici.semilatticeSup
instance semilatticeInf [SemilatticeInf α] {a : α} : SemilatticeInf { x : α // a ≤ x } :=
Set.Ici.semilatticeInf
instance distribLattice [DistribLattice α] {a : α} : DistribLattice { x : α // a ≤ x } :=
Set.Ici.distribLattice
instance instDenselyOrdered [Preorder α] [DenselyOrdered α] {a : α} :
DenselyOrdered { x : α // a ≤ x } :=
show DenselyOrdered (Ici a) from Set.instDenselyOrdered
/-- If `sSup ∅ ≤ a` then `{x : α // a ≤ x}` is a `ConditionallyCompleteLinearOrder`. -/
protected noncomputable abbrev conditionallyCompleteLinearOrder [ConditionallyCompleteLinearOrder α]
{a : α} : ConditionallyCompleteLinearOrder { x : α // a ≤ x } :=
{ @ordConnectedSubsetConditionallyCompleteLinearOrder α (Set.Ici a) _ ⟨⟨a, le_rfl⟩⟩ _ with }
/-- If `sSup ∅ ≤ a` then `{x : α // a ≤ x}` is a `ConditionallyCompleteLinearOrderBot`.
This instance uses data fields from `Subtype.linearOrder` to help type-class inference.
The `Set.Ici` data fields are definitionally equal, but that requires unfolding semireducible
definitions, so type-class inference won't see this. -/
protected noncomputable abbrev conditionallyCompleteLinearOrderBot
[ConditionallyCompleteLinearOrder α] (a : α) :
ConditionallyCompleteLinearOrderBot { x : α // a ≤ x } :=
{ Nonneg.orderBot, Nonneg.conditionallyCompleteLinearOrder with
csSup_empty := by
rw [@subset_sSup_def α (Set.Ici a) _ _ ⟨⟨a, le_rfl⟩⟩]; simp [bot_eq] }
end Nonneg |
.lake/packages/mathlib/Mathlib/Algebra/Order/Positive/Ring.lean | import Mathlib.Algebra.Order.Ring.Defs
import Mathlib.Algebra.Ring.InjSurj
import Mathlib.Tactic.FastInstance
/-!
# Algebraic structures on the set of positive numbers
In this file we define various instances (`AddSemigroup`, `OrderedCommMonoid` etc) on the
type `{x : R // 0 < x}`. In each case we try to require the weakest possible typeclass
assumptions on `R` but possibly, there is a room for improvements.
-/
open Function
namespace Positive
variable {M R : Type*}
section AddBasic
variable [AddMonoid M] [Preorder M] [AddLeftStrictMono M]
instance : Add { x : M // 0 < x } :=
⟨fun x y => ⟨x + y, add_pos x.2 y.2⟩⟩
@[simp, norm_cast]
theorem coe_add (x y : { x : M // 0 < x }) : ↑(x + y) = (x + y : M) :=
rfl
instance addSemigroup : AddSemigroup { x : M // 0 < x } := fast_instance%
Subtype.coe_injective.addSemigroup _ coe_add
instance addCommSemigroup {M : Type*} [AddCommMonoid M] [Preorder M]
[AddLeftStrictMono M] : AddCommSemigroup { x : M // 0 < x } := fast_instance%
Subtype.coe_injective.addCommSemigroup _ coe_add
instance addLeftCancelSemigroup {M : Type*} [AddLeftCancelMonoid M] [Preorder M]
[AddLeftStrictMono M] : AddLeftCancelSemigroup { x : M // 0 < x } := fast_instance%
Subtype.coe_injective.addLeftCancelSemigroup _ coe_add
instance addRightCancelSemigroup {M : Type*} [AddRightCancelMonoid M] [Preorder M]
[AddLeftStrictMono M] : AddRightCancelSemigroup { x : M // 0 < x } := fast_instance%
Subtype.coe_injective.addRightCancelSemigroup _ coe_add
instance addLeftStrictMono : AddLeftStrictMono { x : M // 0 < x } :=
⟨fun _ y z hyz => Subtype.coe_lt_coe.1 <| add_lt_add_left (show (y : M) < z from hyz) _⟩
instance addRightStrictMono [AddRightStrictMono M] : AddRightStrictMono { x : M // 0 < x } :=
⟨fun _ y z hyz => Subtype.coe_lt_coe.1 <| add_lt_add_right (show (y : M) < z from hyz) _⟩
instance addLeftReflectLT [AddLeftReflectLT M] : AddLeftReflectLT { x : M // 0 < x } :=
⟨fun _ _ _ h => Subtype.coe_lt_coe.1 <| lt_of_add_lt_add_left h⟩
instance addRightReflectLT [AddRightReflectLT M] : AddRightReflectLT { x : M // 0 < x } :=
⟨fun _ _ _ h => Subtype.coe_lt_coe.1 <| lt_of_add_lt_add_right h⟩
instance addLeftReflectLE [AddLeftReflectLE M] : AddLeftReflectLE { x : M // 0 < x } :=
⟨fun _ _ _ h => Subtype.coe_le_coe.1 <| le_of_add_le_add_left h⟩
instance addRightReflectLE [AddRightReflectLE M] : AddRightReflectLE { x : M // 0 < x } :=
⟨fun _ _ _ h => Subtype.coe_le_coe.1 <| le_of_add_le_add_right h⟩
end AddBasic
instance addLeftMono [AddMonoid M] [PartialOrder M] [AddLeftStrictMono M] :
AddLeftMono { x : M // 0 < x } :=
⟨@fun _ _ _ h₁ => StrictMono.monotone (fun _ _ h => add_lt_add_left h _) h₁⟩
section Mul
variable [Semiring R] [PartialOrder R] [IsStrictOrderedRing R]
instance : Mul { x : R // 0 < x } :=
⟨fun x y => ⟨x * y, mul_pos x.2 y.2⟩⟩
@[simp]
theorem val_mul (x y : { x : R // 0 < x }) : ↑(x * y) = (x * y : R) :=
rfl
instance : Pow { x : R // 0 < x } ℕ :=
⟨fun x n => ⟨(x : R) ^ n, pow_pos x.2 n⟩⟩
@[simp]
theorem val_pow (x : { x : R // 0 < x }) (n : ℕ) :
↑(x ^ n) = (x : R) ^ n :=
rfl
instance : Semigroup { x : R // 0 < x } := fast_instance%
Subtype.coe_injective.semigroup Subtype.val val_mul
instance : Distrib { x : R // 0 < x } := fast_instance%
Subtype.coe_injective.distrib _ coe_add val_mul
instance : One { x : R // 0 < x } :=
⟨⟨1, one_pos⟩⟩
@[simp]
theorem val_one : ((1 : { x : R // 0 < x }) : R) = 1 :=
rfl
instance : Monoid { x : R // 0 < x } := fast_instance%
Subtype.coe_injective.monoid _ val_one val_mul val_pow
end Mul
section mul_comm
instance commMonoid [CommSemiring R] [PartialOrder R] [IsStrictOrderedRing R] :
CommMonoid { x : R // 0 < x } := fast_instance%
Subtype.coe_injective.commMonoid (M₂ := R) (Subtype.val) val_one val_mul val_pow
instance isOrderedMonoid [CommSemiring R] [PartialOrder R] [IsStrictOrderedRing R] :
IsOrderedMonoid { x : R // 0 < x } :=
{ mul_le_mul_left := fun _ _ hxy c =>
Subtype.coe_le_coe.1 <| mul_le_mul_of_nonneg_left hxy c.2.le }
/-- If `R` is a nontrivial linear ordered commutative semiring, then `{x : R // 0 < x}` is a linear
ordered cancellative commutative monoid. -/
instance isOrderedCancelMonoid [CommSemiring R] [LinearOrder R] [IsStrictOrderedRing R] :
IsOrderedCancelMonoid { x : R // 0 < x } where
le_of_mul_le_mul_left a _ _ := (mul_le_mul_iff_right₀ a.2).1
end mul_comm
end Positive |
.lake/packages/mathlib/Mathlib/Algebra/Order/Positive/Field.lean | import Mathlib.Algebra.Field.Defs
import Mathlib.Algebra.Order.Positive.Ring
/-!
# Algebraic structures on the set of positive numbers
In this file we prove that the set of positive elements of a linear ordered field is a linear
ordered commutative group.
-/
variable {K : Type*} [Field K] [LinearOrder K] [IsStrictOrderedRing K]
namespace Positive
instance Subtype.inv : Inv { x : K // 0 < x } := ⟨fun x => ⟨x⁻¹, inv_pos.2 x.2⟩⟩
@[simp]
theorem coe_inv (x : { x : K // 0 < x }) : ↑x⁻¹ = (x⁻¹ : K) :=
rfl
instance : Pow { x : K // 0 < x } ℤ :=
⟨fun x n => ⟨(x : K) ^ n, zpow_pos x.2 _⟩⟩
@[simp]
theorem coe_zpow (x : { x : K // 0 < x }) (n : ℤ) : ↑(x ^ n) = (x : K) ^ n :=
rfl
instance : CommGroup { x : K // 0 < x } :=
{ Positive.commMonoid with
inv_mul_cancel := fun a => Subtype.ext <| inv_mul_cancel₀ a.2.ne' }
end Positive |
.lake/packages/mathlib/Mathlib/Algebra/Order/Monoid/WithTop.lean | import Mathlib.Algebra.Order.Monoid.Unbundled.WithTop
import Mathlib.Algebra.Order.Monoid.Canonical.Defs
/-! # Adjoining top/bottom elements to ordered monoids.
-/
universe u
variable {α : Type u}
open Function
namespace WithTop
instance isOrderedAddMonoid [AddCommMonoid α] [PartialOrder α] [IsOrderedAddMonoid α] :
IsOrderedAddMonoid (WithTop α) where
add_le_add_left _ _ := add_le_add_left
instance canonicallyOrderedAdd [Add α] [Preorder α] [CanonicallyOrderedAdd α] :
CanonicallyOrderedAdd (WithTop α) where
le_self_add
| ⊤, _ => le_rfl
| (a : α), ⊤ => le_top
| (a : α), (b : α) => WithTop.coe_le_coe.2 le_self_add
le_add_self
| ⊤, ⊤ | ⊤, (b : α) => le_rfl
| (a : α), ⊤ => le_top
| (a : α), (b : α) => WithTop.coe_le_coe.2 le_add_self
end WithTop
namespace WithBot
instance isOrderedAddMonoid [AddCommMonoid α] [PartialOrder α] [IsOrderedAddMonoid α] :
IsOrderedAddMonoid (WithBot α) :=
{ add_le_add_left := fun _ _ h c => add_le_add_left h c }
protected theorem le_self_add [Add α] [LE α] [CanonicallyOrderedAdd α]
{x : WithBot α} (hx : x ≠ ⊥) (y : WithBot α) :
y ≤ y + x := by
induction x
· simp at hx
induction y
· simp
· rw [← WithBot.coe_add, WithBot.coe_le_coe]
exact le_self_add
protected theorem le_add_self [AddCommMagma α] [LE α] [CanonicallyOrderedAdd α]
{x : WithBot α} (hx : x ≠ ⊥) (y : WithBot α) :
y ≤ x + y := by
induction x
· simp at hx
induction y
· simp
· rw [← WithBot.coe_add, WithBot.coe_le_coe]
exact le_add_self
end WithBot |
.lake/packages/mathlib/Mathlib/Algebra/Order/Monoid/OrderDual.lean | import Mathlib.Algebra.Order.Group.Synonym
import Mathlib.Algebra.Order.Monoid.Unbundled.OrderDual
import Mathlib.Algebra.Order.Monoid.Defs
/-! # Ordered monoid structures on the order dual. -/
universe u
variable {α : Type u}
open Function
namespace OrderDual
@[to_additive]
instance isOrderedMonoid [CommMonoid α] [PartialOrder α] [IsOrderedMonoid α] :
IsOrderedMonoid αᵒᵈ :=
{ mul_le_mul_left := fun _ _ h c => mul_le_mul_left' h c }
@[to_additive]
instance isOrderedCancelMonoid [CommMonoid α] [PartialOrder α] [IsOrderedCancelMonoid α] :
IsOrderedCancelMonoid αᵒᵈ :=
{ le_of_mul_le_mul_left := fun _ _ _ : α => le_of_mul_le_mul_left' }
end OrderDual |
.lake/packages/mathlib/Mathlib/Algebra/Order/Monoid/ToMulBot.lean | import Mathlib.Algebra.Order.GroupWithZero.Canonical
import Mathlib.Algebra.Order.Monoid.Unbundled.TypeTags
import Mathlib.Algebra.Order.Monoid.Unbundled.WithTop
/-!
Making an additive monoid multiplicative then adding a zero is the same as adding a bottom
element then making it multiplicative.
-/
universe u
variable {α : Type u}
namespace WithZero
variable [Add α]
/-- Making an additive monoid multiplicative then adding a zero is the same as adding a bottom
element then making it multiplicative. -/
def toMulBot : WithZero (Multiplicative α) ≃* Multiplicative (WithBot α) :=
MulEquiv.refl _
@[simp]
theorem toMulBot_zero : toMulBot (0 : WithZero (Multiplicative α)) = Multiplicative.ofAdd ⊥ :=
rfl
@[simp]
theorem toMulBot_coe (x : Multiplicative α) :
toMulBot ↑x = Multiplicative.ofAdd (↑x.toAdd : WithBot α) :=
rfl
@[simp]
theorem toMulBot_symm_bot : toMulBot.symm (Multiplicative.ofAdd (⊥ : WithBot α)) = 0 :=
rfl
@[simp]
theorem toMulBot_coe_ofAdd (x : α) :
toMulBot.symm (Multiplicative.ofAdd (x : WithBot α)) = Multiplicative.ofAdd x :=
rfl
variable [Preorder α] (a b : WithZero (Multiplicative α))
theorem toMulBot_strictMono : StrictMono (@toMulBot α _) := fun _ _ => id
@[simp]
theorem toMulBot_le : toMulBot a ≤ toMulBot b ↔ a ≤ b :=
Iff.rfl
@[simp]
theorem toMulBot_lt : toMulBot a < toMulBot b ↔ a < b :=
Iff.rfl
end WithZero |
.lake/packages/mathlib/Mathlib/Algebra/Order/Monoid/Lex.lean | import Mathlib.Algebra.Group.Prod
import Mathlib.Algebra.Order.Hom.Monoid
import Mathlib.Data.Prod.Lex
import Mathlib.Order.Prod.Lex.Hom
/-!
# Order homomorphisms for products of ordered monoids
This file defines order homomorphisms for products of ordered monoids, for both the plain product
and the lexicographic product.
The product of ordered monoids `α × β` is an ordered monoid itself with both natural inclusions
and projections, making it the coproduct as well.
## TODO
Create the "OrdCommMon" category.
-/
namespace MonoidHom
variable {α β : Type*} [Monoid α] [Preorder α] [Monoid β] [Preorder β]
@[to_additive]
lemma inl_mono : Monotone (MonoidHom.inl α β) :=
fun _ _ ↦ by simp
@[to_additive]
lemma inl_strictMono : StrictMono (MonoidHom.inl α β) :=
fun _ _ ↦ by simp
@[to_additive]
lemma inr_mono : Monotone (MonoidHom.inr α β) :=
fun _ _ ↦ by simp
@[to_additive]
lemma inr_strictMono : StrictMono (MonoidHom.inr α β) :=
fun _ _ ↦ by simp
@[to_additive]
lemma fst_mono : Monotone (MonoidHom.fst α β) :=
fun _ _ ↦ by simp +contextual [Prod.le_def]
@[to_additive]
lemma snd_mono : Monotone (MonoidHom.snd α β) :=
fun _ _ ↦ by simp +contextual [Prod.le_def]
end MonoidHom
namespace OrderMonoidHom
variable (α β : Type*) [Monoid α] [PartialOrder α] [Monoid β] [Preorder β]
/-- Given ordered monoids M, N, the natural inclusion ordered homomorphism from M to M × N. -/
@[to_additive (attr := simps!) /-- Given ordered additive monoids M, N, the natural inclusion
ordered homomorphism from M to M × N. -/]
def inl : α →*o α × β where
__ := MonoidHom.inl _ _
monotone' := MonoidHom.inl_mono
/-- Given ordered monoids M, N, the natural inclusion ordered homomorphism from N to M × N. -/
@[to_additive (attr := simps!) /-- Given ordered additive monoids M, N, the natural inclusion
ordered homomorphism from N to M × N. -/]
def inr : β →*o α × β where
__ := MonoidHom.inr _ _
monotone' := MonoidHom.inr_mono
/-- Given ordered monoids M, N, the natural projection ordered homomorphism from M × N to M. -/
@[to_additive (attr := simps!) /-- Given ordered additive monoids M, N, the natural projection
ordered homomorphism from M × N to M. -/]
def fst : α × β →*o α where
__ := MonoidHom.fst _ _
monotone' := MonoidHom.fst_mono
/-- Given ordered monoids M, N, the natural projection ordered homomorphism from M × N to N. -/
@[to_additive (attr := simps!) /-- Given ordered additive monoids M, N, the natural projection
ordered homomorphism from M × N to N. -/]
def snd : α × β →*o β where
__ := MonoidHom.snd _ _
monotone' := MonoidHom.snd_mono
/-- Given ordered monoids M, N, the natural inclusion ordered homomorphism from M to the
lexicographic M ×ₗ N. -/
@[to_additive (attr := simps!) /-- Given ordered additive monoids M, N, the natural inclusion
ordered homomorphism from M to the lexicographic M ×ₗ N. -/]
def inlₗ : α →*o α ×ₗ β where
__ := (Prod.Lex.toLexOrderHom).comp (inl α β)
map_one' := rfl
map_mul' := by simp [← toLex_mul]
/-- Given ordered monoids M, N, the natural inclusion ordered homomorphism from N to the
lexicographic M ×ₗ N. -/
@[to_additive (attr := simps!) /-- Given ordered additive monoids M, N, the natural inclusion
ordered homomorphism from N to the lexicographic M ×ₗ N. -/]
def inrₗ : β →*o (α ×ₗ β) where
__ := Prod.Lex.toLexOrderHom.comp (inr α β)
map_one' := rfl
map_mul' := by simp [← toLex_mul]
/-- Given ordered monoids M, N, the natural projection ordered homomorphism from the
lexicographic M ×ₗ N to M. -/
@[to_additive (attr := simps!) /-- Given ordered additive monoids M, N, the natural projection
ordered homomorphism from the lexicographic M ×ₗ N to M. -/]
def fstₗ : (α ×ₗ β) →*o α where
toFun p := (ofLex p).fst
map_one' := rfl
map_mul' := by simp
monotone' := Prod.Lex.monotone_fst_ofLex
@[to_additive (attr := simp)]
theorem fst_comp_inl : (fst α β).comp (inl α β) = .id α :=
rfl
@[to_additive (attr := simp)]
theorem fstₗ_comp_inlₗ : (fstₗ α β).comp (inlₗ α β) = .id α :=
rfl
@[to_additive (attr := simp)]
theorem snd_comp_inl : (snd α β).comp (inl α β) = 1 :=
rfl
@[to_additive (attr := simp)]
theorem fst_comp_inr : (fst α β).comp (inr α β) = 1 :=
rfl
@[to_additive (attr := simp)]
theorem snd_comp_inr : (snd α β).comp (inr α β) = .id β :=
rfl
@[to_additive]
theorem inl_mul_inr_eq_mk (m : α) (n : β) : inl α β m * inr α β n = (m, n) := by
simp
@[to_additive]
theorem inlₗ_mul_inrₗ_eq_toLex (m : α) (n : β) : inlₗ α β m * inrₗ α β n = toLex (m, n) := by
simp [← toLex_mul]
variable {α β}
@[to_additive]
theorem commute_inl_inr (m : α) (n : β) : Commute (inl α β m) (inr α β n) :=
Commute.prod (.one_right m) (.one_left n)
@[to_additive]
theorem commute_inlₗ_inrₗ (m : α) (n : β) : Commute (inlₗ α β m) (inrₗ α β n) :=
Commute.prod (.one_right m) (.one_left n)
end OrderMonoidHom |
.lake/packages/mathlib/Mathlib/Algebra/Order/Monoid/Prod.lean | import Mathlib.Algebra.Group.Prod
import Mathlib.Algebra.Order.Group.Synonym
import Mathlib.Algebra.Order.Monoid.Canonical.Defs
import Mathlib.Data.Prod.Lex
/-! # Products of ordered monoids -/
assert_not_exists MonoidWithZero
namespace Prod
variable {α β : Type*}
@[to_additive]
instance [CommMonoid α] [PartialOrder α] [IsOrderedMonoid α]
[CommMonoid β] [PartialOrder β] [IsOrderedMonoid β] : IsOrderedMonoid (α × β) where
mul_le_mul_left _ _ h _ := ⟨mul_le_mul_left' h.1 _, mul_le_mul_left' h.2 _⟩
@[to_additive]
instance instIsOrderedCancelMonoid
[CommMonoid α] [PartialOrder α] [IsOrderedCancelMonoid α]
[CommMonoid β] [PartialOrder β] [IsOrderedCancelMonoid β] :
IsOrderedCancelMonoid (α × β) :=
{ le_of_mul_le_mul_left :=
fun _ _ _ h ↦ ⟨le_of_mul_le_mul_left' h.1, le_of_mul_le_mul_left' h.2⟩ }
@[to_additive]
instance [LE α] [LE β] [Mul α] [Mul β] [ExistsMulOfLE α] [ExistsMulOfLE β] :
ExistsMulOfLE (α × β) :=
⟨fun h =>
let ⟨c, hc⟩ := exists_mul_of_le h.1
let ⟨d, hd⟩ := exists_mul_of_le h.2
⟨(c, d), Prod.ext hc hd⟩⟩
@[to_additive]
instance [Mul α] [LE α] [CanonicallyOrderedMul α]
[Mul β] [LE β] [CanonicallyOrderedMul β] : CanonicallyOrderedMul (α × β) where
le_mul_self := fun _ _ ↦ le_def.mpr ⟨le_mul_self, le_mul_self⟩
le_self_mul := fun _ _ ↦ le_def.mpr ⟨le_self_mul, le_self_mul⟩
namespace Lex
@[to_additive]
instance isOrderedMonoid [CommMonoid α] [PartialOrder α] [MulLeftStrictMono α]
[CommMonoid β] [PartialOrder β] [IsOrderedMonoid β] :
IsOrderedMonoid (α ×ₗ β) where
mul_le_mul_left _ _ hxy z := (le_iff.1 hxy).elim
(fun hxy => left _ _ <| mul_lt_mul_left' hxy _)
(fun hxy => le_iff.2 <|
Or.inr ⟨by simp only [ofLex_mul, fst_mul, hxy.1], mul_le_mul_left' hxy.2 _⟩)
@[to_additive]
instance isOrderedCancelMonoid [CommMonoid α] [PartialOrder α] [IsOrderedCancelMonoid α]
[CommMonoid β] [PartialOrder β] [IsOrderedCancelMonoid β] :
IsOrderedCancelMonoid (α ×ₗ β) where
mul_le_mul_left _ _ := mul_le_mul_left'
le_of_mul_le_mul_left _ _ _ hxyz := (le_iff.1 hxyz).elim
(fun hxy => left _ _ <| lt_of_mul_lt_mul_left' hxy)
(fun hxy => le_iff.2 <| Or.inr ⟨mul_left_cancel hxy.1, le_of_mul_le_mul_left' hxy.2⟩)
end Lex
end Prod |
.lake/packages/mathlib/Mathlib/Algebra/Order/Monoid/Basic.lean | import Mathlib.Algebra.Order.Monoid.Defs
import Mathlib.Order.Hom.Basic
/-!
# Ordered monoids
This file develops some additional material on ordered monoids.
-/
open Function
universe u
variable {α : Type u} {β : Type*} [CommMonoid α] [PartialOrder α]
/-- Pullback an `IsOrderedMonoid` under an injective map. -/
@[to_additive /-- Pullback an `IsOrderedAddMonoid` under an injective map. -/]
lemma Function.Injective.isOrderedMonoid [IsOrderedMonoid α] [CommMonoid β]
[PartialOrder β] (f : β → α) (mul : ∀ x y, f (x * y) = f x * f y)
(le : ∀ {x y}, f x ≤ f y ↔ x ≤ y) :
IsOrderedMonoid β where
mul_le_mul_left a b ab c := le.1 <| by rw [mul, mul]; grw [le.2 ab]
/-- Pullback an `IsOrderedMonoid` under a strictly monotone map. -/
@[to_additive /-- Pullback an `IsOrderedAddMonoid` under a strictly monotone map. -/]
lemma StrictMono.isOrderedMonoid [IsOrderedMonoid α] [CommMonoid β] [LinearOrder β]
(f : β → α) (hf : StrictMono f) (mul : ∀ x y, f (x * y) = f x * f y) :
IsOrderedMonoid β :=
Function.Injective.isOrderedMonoid f mul hf.le_iff_le
/-- Pullback an `IsOrderedCancelMonoid` under an injective map. -/
@[to_additive Function.Injective.isOrderedCancelAddMonoid
/-- Pullback an `IsOrderedCancelAddMonoid` under an injective map. -/]
lemma Function.Injective.isOrderedCancelMonoid [IsOrderedCancelMonoid α] [CommMonoid β]
[PartialOrder β]
(f : β → α) (mul : ∀ x y, f (x * y) = f x * f y)
(le : ∀ {x y}, f x ≤ f y ↔ x ≤ y) :
IsOrderedCancelMonoid β where
__ := Function.Injective.isOrderedMonoid f mul le
le_of_mul_le_mul_left a b c bc := le.1 <|
(mul_le_mul_iff_left (f a)).1 (by rwa [← mul, ← mul, le])
/-- Pullback an `IsOrderedCancelMonoid` under a strictly monotone map. -/
@[to_additive /-- Pullback an `IsOrderedAddCancelMonoid` under a strictly monotone map. -/]
lemma StrictMono.isOrderedCancelMonoid [IsOrderedCancelMonoid α] [CommMonoid β] [LinearOrder β]
(f : β → α) (hf : StrictMono f) (mul : ∀ x y, f (x * y) = f x * f y) :
IsOrderedCancelMonoid β where
__ := hf.isOrderedMonoid f mul
le_of_mul_le_mul_left a b c h := by simpa [← hf.le_iff_le, mul] using h
-- TODO find a better home for the next two constructions.
/-- The order embedding sending `b` to `a * b`, for some fixed `a`.
See also `OrderIso.mulLeft` when working in an ordered group. -/
@[to_additive (attr := simps!)
/-- The order embedding sending `b` to `a + b`, for some fixed `a`.
See also `OrderIso.addLeft` when working in an additive ordered group. -/]
def OrderEmbedding.mulLeft {α : Type*} [Mul α] [LinearOrder α]
[MulLeftStrictMono α] (m : α) : α ↪o α :=
OrderEmbedding.ofStrictMono (fun n => m * n) mul_right_strictMono
/-- The order embedding sending `b` to `b * a`, for some fixed `a`.
See also `OrderIso.mulRight` when working in an ordered group. -/
@[to_additive (attr := simps!)
/-- The order embedding sending `b` to `b + a`, for some fixed `a`.
See also `OrderIso.addRight` when working in an additive ordered group. -/]
def OrderEmbedding.mulRight {α : Type*} [Mul α] [LinearOrder α]
[MulRightStrictMono α] (m : α) : α ↪o α :=
OrderEmbedding.ofStrictMono (fun n => n * m) mul_left_strictMono |
.lake/packages/mathlib/Mathlib/Algebra/Order/Monoid/PNat.lean | import Mathlib.Algebra.GroupWithZero.NonZeroDivisors
import Mathlib.Algebra.Order.Hom.Monoid
import Mathlib.Data.PNat.Basic
/-!
# Equivalence between `ℕ+` and `nonZeroDivisors ℕ`
-/
/-- `ℕ+` is equivalent to `nonZeroDivisors ℕ` in terms of order and multiplication. -/
@[simps]
def PNat.equivNonZeroDivisorsNat : ℕ+ ≃*o nonZeroDivisors ℕ where
toFun x := ⟨x.val, by simp⟩
invFun x := ⟨x.val, by simp [Nat.pos_iff_ne_zero]⟩
map_mul' := by simp
map_le_map_iff' := by simp |
.lake/packages/mathlib/Mathlib/Algebra/Order/Monoid/NatCast.lean | import Mathlib.Algebra.Order.Monoid.Unbundled.Basic
import Mathlib.Algebra.Order.ZeroLEOne
import Mathlib.Data.Nat.Cast.Defs
/-!
# Order of numerals in an `AddMonoidWithOne`.
-/
variable {α : Type*}
open Function
lemma lt_add_one [One α] [AddZeroClass α] [PartialOrder α] [ZeroLEOneClass α]
[NeZero (1 : α)] [AddLeftStrictMono α] (a : α) : a < a + 1 :=
lt_add_of_pos_right _ zero_lt_one
lemma lt_one_add [One α] [AddZeroClass α] [PartialOrder α] [ZeroLEOneClass α]
[NeZero (1 : α)] [AddRightStrictMono α] (a : α) : a < 1 + a :=
lt_add_of_pos_left _ zero_lt_one
variable [AddMonoidWithOne α]
lemma zero_le_two [Preorder α] [ZeroLEOneClass α] [AddLeftMono α] :
(0 : α) ≤ 2 := by
rw [← one_add_one_eq_two]
exact add_nonneg zero_le_one zero_le_one
lemma zero_le_three [Preorder α] [ZeroLEOneClass α] [AddLeftMono α] :
(0 : α) ≤ 3 := by
rw [← two_add_one_eq_three]
exact add_nonneg zero_le_two zero_le_one
lemma zero_le_four [Preorder α] [ZeroLEOneClass α] [AddLeftMono α] :
(0 : α) ≤ 4 := by
rw [← three_add_one_eq_four]
exact add_nonneg zero_le_three zero_le_one
lemma one_le_two [LE α] [ZeroLEOneClass α] [AddLeftMono α] :
(1 : α) ≤ 2 :=
calc (1 : α) = 1 + 0 := (add_zero 1).symm
_ ≤ 1 + 1 := by gcongr; exact zero_le_one
_ = 2 := one_add_one_eq_two
lemma one_le_two' [LE α] [ZeroLEOneClass α] [AddRightMono α] :
(1 : α) ≤ 2 :=
calc (1 : α) = 0 + 1 := (zero_add 1).symm
_ ≤ 1 + 1 := by gcongr; exact zero_le_one
_ = 2 := one_add_one_eq_two
section
variable [PartialOrder α] [ZeroLEOneClass α] [NeZero (1 : α)]
section
variable [AddLeftMono α]
/-- See `zero_lt_two'` for a version with the type explicit. -/
@[simp] lemma zero_lt_two : (0 : α) < 2 := zero_lt_one.trans_le one_le_two
/-- See `zero_lt_three'` for a version with the type explicit. -/
@[simp] lemma zero_lt_three : (0 : α) < 3 := by
rw [← two_add_one_eq_three]
exact lt_add_of_lt_of_nonneg zero_lt_two zero_le_one
/-- See `zero_lt_four'` for a version with the type explicit. -/
@[simp] lemma zero_lt_four : (0 : α) < 4 := by
rw [← three_add_one_eq_four]
exact lt_add_of_lt_of_nonneg zero_lt_three zero_le_one
variable (α)
/-- See `zero_lt_two` for a version with the type implicit. -/
lemma zero_lt_two' : (0 : α) < 2 := zero_lt_two
/-- See `zero_lt_three` for a version with the type implicit. -/
lemma zero_lt_three' : (0 : α) < 3 := zero_lt_three
/-- See `zero_lt_four` for a version with the type implicit. -/
lemma zero_lt_four' : (0 : α) < 4 := zero_lt_four
instance ZeroLEOneClass.neZero.two : NeZero (2 : α) := ⟨zero_lt_two.ne'⟩
instance ZeroLEOneClass.neZero.three : NeZero (3 : α) := ⟨zero_lt_three.ne'⟩
instance ZeroLEOneClass.neZero.four : NeZero (4 : α) := ⟨zero_lt_four.ne'⟩
end
lemma one_lt_two [AddLeftStrictMono α] : (1 : α) < 2 := by
rw [← one_add_one_eq_two]
exact lt_add_one _
end
alias two_pos := zero_lt_two
alias three_pos := zero_lt_three
alias four_pos := zero_lt_four |
.lake/packages/mathlib/Mathlib/Algebra/Order/Monoid/Defs.lean | import Mathlib.Algebra.Order.Monoid.Unbundled.Basic
/-!
# Ordered monoids
This file provides the definitions of ordered monoids.
-/
open Function
variable {α : Type*}
-- TODO: assume weaker typeclasses
/-- An ordered (additive) monoid is a monoid with a partial order such that addition is monotone. -/
class IsOrderedAddMonoid (α : Type*) [AddCommMonoid α] [PartialOrder α] where
protected add_le_add_left : ∀ a b : α, a ≤ b → ∀ c, c + a ≤ c + b
protected add_le_add_right : ∀ a b : α, a ≤ b → ∀ c, a + c ≤ b + c := fun a b h c ↦ by
rw [add_comm _ c, add_comm _ c]; exact add_le_add_left a b h c
/-- An ordered monoid is a monoid with a partial order such that multiplication is monotone. -/
@[to_additive]
class IsOrderedMonoid (α : Type*) [CommMonoid α] [PartialOrder α] where
protected mul_le_mul_left : ∀ a b : α, a ≤ b → ∀ c, c * a ≤ c * b
protected mul_le_mul_right : ∀ a b : α, a ≤ b → ∀ c, a * c ≤ b * c := fun a b h c ↦ by
rw [mul_comm _ c, mul_comm _ c]; exact mul_le_mul_left a b h c
section IsOrderedMonoid
variable [CommMonoid α] [PartialOrder α] [IsOrderedMonoid α]
@[to_additive]
instance (priority := 900) IsOrderedMonoid.toMulLeftMono : MulLeftMono α where
elim := fun a _ _ bc ↦ IsOrderedMonoid.mul_le_mul_left _ _ bc a
@[to_additive]
instance (priority := 900) IsOrderedMonoid.toMulRightMono : MulRightMono α where
elim := fun a _ _ bc ↦ IsOrderedMonoid.mul_le_mul_right _ _ bc a
end IsOrderedMonoid
/-- An ordered cancellative additive monoid is an ordered additive
monoid in which addition is cancellative and monotone. -/
class IsOrderedCancelAddMonoid (α : Type*) [AddCommMonoid α] [PartialOrder α] extends
IsOrderedAddMonoid α where
protected le_of_add_le_add_left : ∀ a b c : α, a + b ≤ a + c → b ≤ c
protected le_of_add_le_add_right : ∀ a b c : α, b + a ≤ c + a → b ≤ c := fun a b c h ↦ by
rw [add_comm _ a, add_comm _ a] at h; exact le_of_add_le_add_left a b c h
/-- An ordered cancellative monoid is an ordered monoid in which
multiplication is cancellative and monotone. -/
@[to_additive IsOrderedCancelAddMonoid]
class IsOrderedCancelMonoid (α : Type*) [CommMonoid α] [PartialOrder α] extends
IsOrderedMonoid α where
protected le_of_mul_le_mul_left : ∀ a b c : α, a * b ≤ a * c → b ≤ c
protected le_of_mul_le_mul_right : ∀ a b c : α, b * a ≤ c * a → b ≤ c := fun a b c h ↦ by
rw [mul_comm _ a, mul_comm _ a] at h; exact le_of_mul_le_mul_left a b c h
section IsOrderedCancelMonoid
variable [CommMonoid α] [PartialOrder α] [IsOrderedCancelMonoid α]
-- See note [lower instance priority]
@[to_additive]
instance (priority := 200) IsOrderedCancelMonoid.toMulLeftReflectLE :
MulLeftReflectLE α :=
⟨IsOrderedCancelMonoid.le_of_mul_le_mul_left⟩
@[to_additive]
instance (priority := 900) IsOrderedCancelMonoid.toMulLeftReflectLT :
MulLeftReflectLT α where
elim := contravariant_lt_of_contravariant_le α α _ ContravariantClass.elim
@[to_additive]
theorem IsOrderedCancelMonoid.toMulRightReflectLT :
MulRightReflectLT α :=
inferInstance
-- See note [lower instance priority]
@[to_additive]
instance (priority := 100) IsOrderedCancelMonoid.toIsCancelMul : IsCancelMul α where
mul_left_cancel _ _ _ h :=
(le_of_mul_le_mul_left' h.le).antisymm <| le_of_mul_le_mul_left' h.ge
mul_right_cancel _ _ _ h :=
(le_of_mul_le_mul_right' h.le).antisymm <| le_of_mul_le_mul_right' h.ge
@[to_additive]
theorem IsOrderedCancelMonoid.of_mul_lt_mul_left {α : Type*} [CommMonoid α] [LinearOrder α]
(hmul : ∀ a b c : α, b < c → a * b < a * c) : IsOrderedCancelMonoid α where
mul_le_mul_left a b h c := by
obtain rfl | h := eq_or_lt_of_le h
· simp
exact (hmul _ _ _ h).le
le_of_mul_le_mul_left a b c h := by
contrapose! h
exact hmul _ _ _ h
end IsOrderedCancelMonoid
variable [CommMonoid α] [LinearOrder α] [IsOrderedMonoid α] {a : α}
@[to_additive (attr := simp)]
theorem one_le_mul_self_iff : 1 ≤ a * a ↔ 1 ≤ a :=
⟨(fun h ↦ by push_neg at h ⊢; exact mul_lt_one' h h).mtr, fun h ↦ one_le_mul h h⟩
@[to_additive (attr := simp)]
theorem one_lt_mul_self_iff : 1 < a * a ↔ 1 < a :=
⟨(fun h ↦ by push_neg at h ⊢; exact mul_le_one' h h).mtr, fun h ↦ one_lt_mul'' h h⟩
@[to_additive (attr := simp)]
theorem mul_self_le_one_iff : a * a ≤ 1 ↔ a ≤ 1 := by simp [← not_iff_not]
@[to_additive (attr := simp)]
theorem mul_self_lt_one_iff : a * a < 1 ↔ a < 1 := by simp [← not_iff_not] |
.lake/packages/mathlib/Mathlib/Algebra/Order/Monoid/Submonoid.lean | import Mathlib.Algebra.Group.Submonoid.Defs
import Mathlib.Algebra.Order.Monoid.Basic
import Mathlib.Order.Interval.Set.Defs
/-!
# Ordered instances on submonoids
-/
assert_not_exists MonoidWithZero
namespace SubmonoidClass
variable {M S : Type*} [SetLike S M]
-- Prefer subclasses of `Monoid` over subclasses of `SubmonoidClass`.
/-- A submonoid of an ordered monoid is an ordered monoid. -/
@[to_additive /-- An `AddSubmonoid` of an ordered additive monoid is an ordered additive monoid. -/]
instance (priority := 75) toIsOrderedMonoid [CommMonoid M] [PartialOrder M] [IsOrderedMonoid M]
[SubmonoidClass S M] (s : S) : IsOrderedMonoid s :=
Function.Injective.isOrderedMonoid Subtype.val (fun _ _ => rfl) .rfl
-- Prefer subclasses of `Monoid` over subclasses of `SubmonoidClass`.
/-- A submonoid of an ordered cancellative monoid is an ordered cancellative monoid. -/
@[to_additive AddSubmonoidClass.toIsOrderedCancelAddMonoid
/-- An `AddSubmonoid` of an ordered cancellative additive monoid is an ordered cancellative
additive monoid. -/]
instance (priority := 75) toIsOrderedCancelMonoid
[CommMonoid M] [PartialOrder M] [IsOrderedCancelMonoid M]
[SubmonoidClass S M] (s : S) : IsOrderedCancelMonoid s :=
Function.Injective.isOrderedCancelMonoid Subtype.val (fun _ _ => rfl) .rfl
end SubmonoidClass
namespace Submonoid
variable {M : Type*}
/-- A submonoid of an ordered monoid is an ordered monoid. -/
@[to_additive /-- An `AddSubmonoid` of an ordered additive monoid is an ordered additive monoid. -/]
instance toIsOrderedMonoid [CommMonoid M] [PartialOrder M] [IsOrderedMonoid M]
(S : Submonoid M) : IsOrderedMonoid S :=
Function.Injective.isOrderedMonoid Subtype.val (fun _ _ => rfl) .rfl
/-- A submonoid of an ordered cancellative monoid is an ordered cancellative monoid. -/
@[to_additive AddSubmonoid.toIsOrderedCancelAddMonoid
/-- An `AddSubmonoid` of an ordered cancellative additive monoid is an ordered cancellative
additive monoid. -/]
instance toIsOrderedCancelMonoid [CommMonoid M] [PartialOrder M] [IsOrderedCancelMonoid M]
(S : Submonoid M) : IsOrderedCancelMonoid S :=
Function.Injective.isOrderedCancelMonoid Subtype.val (fun _ _ => rfl) .rfl
section Preorder
variable (M)
variable [Monoid M] [Preorder M] [MulLeftMono M] {a : M}
/-- The submonoid of elements that are at least `1`. -/
@[to_additive (attr := simps) /-- The submonoid of nonnegative elements. -/]
def oneLE : Submonoid M where
carrier := Set.Ici 1
mul_mem' := one_le_mul
one_mem' := le_rfl
variable {M}
@[to_additive (attr := simp)] lemma mem_oneLE : a ∈ oneLE M ↔ 1 ≤ a := Iff.rfl
end Preorder
end Submonoid |
.lake/packages/mathlib/Mathlib/Algebra/Order/Monoid/LocallyFiniteOrder.lean | import Mathlib.Algebra.Group.Subgroup.Ker
import Mathlib.Algebra.Order.Group.Units
import Mathlib.Algebra.Order.Hom.MonoidWithZero
import Mathlib.Algebra.Order.Hom.TypeTags
import Mathlib.Algebra.Order.Ring.Int
import Mathlib.Data.Nat.Cast.Order.Ring
import Mathlib.Tactic.Abel
import Mathlib.Algebra.Group.Embedding
import Mathlib.Order.Interval.Finset.Basic
/-!
# Locally Finite Linearly Ordered Abelian Groups
## Main results
- `LocallyFiniteOrder.orderAddMonoidEquiv`:
Any nontrivial linearly ordered additive abelian group that is locally finite is
isomorphic to `ℤ`.
- `LocallyFiniteOrder.orderMonoidEquiv`:
Any nontrivial linearly ordered abelian group that is locally finite is isomorphic to
`Multiplicative ℤ`.
- `LocallyFiniteOrder.orderMonoidWithZeroEquiv`:
Any nontrivial linearly ordered abelian group with zero that is locally finite
is isomorphic to `ℤᵐ⁰`.
-/
open Finset
section Multiplicative
variable {M : Type*} [CancelCommMonoid M] [LinearOrder M] [IsOrderedMonoid M] [LocallyFiniteOrder M]
@[to_additive]
lemma Finset.card_Ico_mul_right [ExistsMulOfLE M] (a b c : M) :
#(Ico (a * c) (b * c)) = #(Ico a b) := by
have : (Ico (a * c) (b * c)) = (Ico a b).map (mulRightEmbedding c) := by
ext x
simp only [mem_Ico, mem_map, mulRightEmbedding_apply]
constructor
· rintro ⟨h₁, h₂⟩
obtain ⟨d, rfl⟩ := exists_mul_of_le h₁
exact ⟨a * d, ⟨by simpa using h₁, by simpa [mul_right_comm a c d] using h₂⟩,
by simp_rw [mul_assoc, mul_comm]⟩
· aesop
simp [this]
@[to_additive]
lemma card_Ico_one_mul [ExistsMulOfLE M] (a b : M)
(ha : 1 ≤ a) (hb : 1 ≤ b) :
#(Ico 1 (a * b)) = #(Ico 1 a) + #(Ico 1 b) := by
have : Ico 1 b ∪ Ico (1 * b) (a * b) = Ico 1 (a * b) := by
simp [Ico_union_Ico, ha, hb, Right.one_le_mul ha hb]
rw [← this, Finset.card_union, Finset.card_Ico_mul_right]
simp [add_comm]
end Multiplicative
variable {M G : Type*} [AddCancelCommMonoid M] [LinearOrder M] [IsOrderedAddMonoid M]
[LocallyFiniteOrder M] [AddCommGroup G] [LinearOrder G]
[IsOrderedAddMonoid G] [LocallyFiniteOrder G]
variable (G) in
/-- The canonical embedding (as a monoid hom) from a linearly ordered cancellative additive monoid
into `ℤ`. This is either surjective or zero. -/
def LocallyFiniteOrder.addMonoidHom :
G →+ ℤ where
toFun a := #(Ico 0 a) - #(Ico 0 (-a))
map_zero' := by simp
map_add' a b := by
wlog hab : a ≤ b generalizing a b
· convert this b a (le_of_not_ge hab) using 1 <;> simp only [add_comm]
obtain ha | ha := le_total 0 a <;> obtain hb | hb := le_total 0 b
· have : -b ≤ a := by trans 0 <;> simp [ha, hb]
simp [ha, hb, card_Ico_zero_add, this]
· obtain rfl := hb.antisymm (ha.trans hab)
obtain rfl := ha.antisymm hab
simp
· simp only [neg_add_rev, ha, Ico_eq_empty_of_le, card_empty, Nat.cast_zero, zero_sub,
Left.neg_nonpos_iff, hb, sub_zero]
obtain ⟨b, rfl⟩ : ∃ r, b = r - a := ⟨a + b, by abel⟩
simp only [add_sub_cancel, neg_sub, sub_add_eq_add_sub, add_neg_cancel, zero_sub]
obtain hb' | hb' := le_total 0 b
· simp [hb', neg_add_eq_sub, eq_sub_iff_add_eq, ← Nat.cast_add,
← card_Ico_zero_add, ha, ← sub_eq_add_neg]
· simp [hb', neg_add_eq_sub, eq_sub_iff_add_eq, sub_eq_iff_eq_add,
← Nat.cast_add, ← card_Ico_zero_add, hb, sub_add_eq_add_sub]
· have : ¬0 < a + b := by simpa using add_nonpos ha hb
simp [ha, hb, card_Ico_zero_add, Ico_eq_empty, this]
variable (G) in
/-- The canonical embedding (as an ordered monoid hom) from a linearly ordered cancellative
group into `ℤ`. This is either surjective or zero. -/
def LocallyFiniteOrder.orderAddMonoidHom :
G →+o ℤ where
__ := addMonoidHom G
monotone' a b hab := by
obtain ⟨b, rfl⟩ := add_left_surjective a b
replace hab : 0 ≤ b := by simpa using hab
suffices 0 ≤ addMonoidHom G b by simpa
simp [addMonoidHom, hab]
@[simp]
lemma LocallyFiniteOrder.orderAddMonoidHom_toAddMonoidHom :
orderAddMonoidHom G = addMonoidHom G := rfl
@[simp]
lemma LocallyFiniteOrder.orderAddMonoidHom_apply (x : G) :
orderAddMonoidHom G x = addMonoidHom G x := rfl
lemma LocallyFiniteOrder.orderAddMonoidHom_strictMono :
StrictMono (orderAddMonoidHom G) := by
rw [strictMono_iff_map_pos]
intro g H
simpa [addMonoidHom, H.le]
lemma LocallyFiniteOrder.orderAddMonoidHom_bijective [Nontrivial G] :
Function.Bijective (orderAddMonoidHom G) := by
refine ⟨orderAddMonoidHom_strictMono.injective, ?_⟩
suffices 1 ∈ (orderAddMonoidHom G).range by
obtain ⟨x, hx⟩ := this
exact fun a ↦ ⟨a • x, by simp_all⟩
have ⟨a, ha⟩ := exists_zero_lt (α := G)
obtain ⟨b, hb⟩ := exists_covBy_of_wellFoundedLT (α := Icc 0 a) (a := ⟨0, by simpa using ha.le⟩)
(fun H ↦ ha.not_ge (@H ⟨a, by simpa using ha.le⟩ ha.le))
use b.1
have : 0 ≤ b.1 := hb.1.le
suffices Ico 0 b.1 = {0} by simpa [orderAddMonoidHom, addMonoidHom, this]
ext x
simp only [mem_Ico, mem_singleton]
constructor
· rintro ⟨h₁, h₂⟩
by_contra hx'
have := b.2
simp only [Finset.mem_Icc] at this
exact hb.2 (c := ⟨x, by simpa [h₁] using h₂.le.trans this.2⟩)
(lt_of_le_of_ne h₁ (by simpa using Ne.symm hx')) h₂
· rintro rfl
simpa using hb.1
variable (G) in
/-- Any nontrivial linearly ordered abelian group that is locally finite is isomorphic to `ℤ`. -/
noncomputable
def LocallyFiniteOrder.orderAddMonoidEquiv [Nontrivial G] :
G ≃+o ℤ where
__ := orderAddMonoidHom G
__ := AddEquiv.ofBijective (orderAddMonoidHom G) orderAddMonoidHom_bijective
map_le_map_iff' {a b} := by
obtain ⟨b, rfl⟩ := add_left_surjective a b
suffices 0 ≤ orderAddMonoidHom G b ↔ 0 ≤ b by simpa
obtain hb | hb := le_total 0 b
· simp [orderAddMonoidHom, addMonoidHom, hb]
· simp [orderAddMonoidHom, addMonoidHom, hb]
lemma LocallyFiniteOrder.orderAddMonoidEquiv_apply [Nontrivial G] (x : G) :
orderAddMonoidEquiv G x = addMonoidHom G x := rfl
/-- Any linearly ordered abelian group that is locally finite embeds to `Multiplicative ℤ`. -/
noncomputable
def LocallyFiniteOrder.orderMonoidEquiv (G : Type*) [CommGroup G] [LinearOrder G]
[IsOrderedMonoid G] [LocallyFiniteOrder G] [Nontrivial G] :
G ≃*o Multiplicative ℤ :=
have : LocallyFiniteOrder (Additive G) := ‹LocallyFiniteOrder G›
(orderAddMonoidEquiv (Additive G)).toMultiplicative
/-- Any linearly ordered abelian group that is locally finite embeds into `Multiplicative ℤ`. -/
noncomputable
def LocallyFiniteOrder.orderMonoidHom (G : Type*) [CommGroup G] [LinearOrder G]
[IsOrderedMonoid G] [LocallyFiniteOrder G] :
G →*o Multiplicative ℤ :=
have : LocallyFiniteOrder (Additive G) := ‹LocallyFiniteOrder G›
⟨(orderAddMonoidHom (Additive G)).toMultiplicative, (orderAddMonoidHom (Additive G)).2⟩
lemma LocallyFiniteOrder.orderMonoidHom_strictMono {G : Type*} [CommGroup G] [LinearOrder G]
[IsOrderedMonoid G] [LocallyFiniteOrder G] :
StrictMono (orderMonoidHom G) :=
let : LocallyFiniteOrder (Additive G) := ‹LocallyFiniteOrder G›
fun a b h ↦ orderAddMonoidHom_strictMono h
open scoped WithZero in
/-- Any nontrivial linearly ordered abelian group with zero that is locally finite
is isomorphic to `ℤᵐ⁰`. -/
noncomputable
def LocallyFiniteOrder.orderMonoidWithZeroEquiv (G : Type*) [LinearOrderedCommGroupWithZero G]
[LocallyFiniteOrder Gˣ] [Nontrivial Gˣ] : G ≃*o ℤᵐ⁰ :=
OrderMonoidIso.withZeroUnits.symm.trans (LocallyFiniteOrder.orderMonoidEquiv _).withZero
open scoped WithZero in
/-- Any linearly ordered abelian group with zero that is locally finite embeds into `ℤᵐ⁰`. -/
noncomputable
def LocallyFiniteOrder.orderMonoidWithZeroHom (G : Type*) [LinearOrderedCommGroupWithZero G]
[LocallyFiniteOrder Gˣ] : G →*₀o ℤᵐ⁰ where
__ := (WithZero.map' (orderMonoidHom Gˣ)).comp
OrderMonoidIso.withZeroUnits.symm.toMonoidWithZeroHom
monotone' a b h := by have := (orderMonoidHom Gˣ).monotone'; aesop
lemma LocallyFiniteOrder.orderMonoidWithZeroHom_strictMono {G : Type*}
[LinearOrderedCommGroupWithZero G] [LocallyFiniteOrder Gˣ] :
StrictMono (orderMonoidWithZeroHom G) := by
have := orderMonoidHom_strictMono (G := Gˣ)
intro a b h
aesop (add simp orderMonoidWithZeroHom) |
.lake/packages/mathlib/Mathlib/Algebra/Order/Monoid/TypeTags.lean | import Mathlib.Algebra.Order.Monoid.Unbundled.TypeTags
import Mathlib.Algebra.Order.Monoid.Canonical.Defs
/-! # Bundled ordered monoid structures on `Multiplicative α` and `Additive α`. -/
variable {α : Type*}
instance Multiplicative.isOrderedMonoid [AddCommMonoid α] [PartialOrder α] [IsOrderedAddMonoid α] :
IsOrderedMonoid (Multiplicative α) :=
{ mul_le_mul_left := @IsOrderedAddMonoid.add_le_add_left α _ _ _ }
instance Additive.isOrderedAddMonoid [CommMonoid α] [PartialOrder α] [IsOrderedMonoid α] :
IsOrderedAddMonoid (Additive α) :=
{ add_le_add_left := @IsOrderedMonoid.mul_le_mul_left α _ _ _ }
instance Multiplicative.isOrderedCancelMonoid
[AddCommMonoid α] [PartialOrder α] [IsOrderedCancelAddMonoid α] :
IsOrderedCancelMonoid (Multiplicative α) :=
{ le_of_mul_le_mul_left := @IsOrderedCancelAddMonoid.le_of_add_le_add_left α _ _ _ }
instance Additive.isOrderedCancelAddMonoid
[CommMonoid α] [PartialOrder α] [IsOrderedCancelMonoid α] :
IsOrderedCancelAddMonoid (Additive α) :=
{ le_of_add_le_add_left := @IsOrderedCancelMonoid.le_of_mul_le_mul_left α _ _ _ }
instance Multiplicative.canonicallyOrderedMul
[AddMonoid α] [PartialOrder α] [CanonicallyOrderedAdd α] :
CanonicallyOrderedMul (Multiplicative α) where
le_mul_self _ _ := le_add_self (α := α)
le_self_mul _ _ := le_self_add (α := α)
instance Additive.canonicallyOrderedAdd
[Monoid α] [PartialOrder α] [CanonicallyOrderedMul α] :
CanonicallyOrderedAdd (Additive α) where
le_add_self _ _ := le_mul_self (α := α)
le_self_add _ _ := le_self_mul (α := α) |
.lake/packages/mathlib/Mathlib/Algebra/Order/Monoid/Units.lean | import Mathlib.Order.Hom.Basic
import Mathlib.Algebra.Group.Units.Defs
/-!
# Units in ordered monoids
-/
namespace Units
variable {α : Type*}
@[to_additive]
instance [Monoid α] [Preorder α] : Preorder αˣ :=
Preorder.lift val
@[to_additive (attr := simp, norm_cast)]
theorem val_le_val [Monoid α] [Preorder α] {a b : αˣ} : (a : α) ≤ b ↔ a ≤ b :=
Iff.rfl
@[to_additive (attr := simp, norm_cast)]
theorem val_lt_val [Monoid α] [Preorder α] {a b : αˣ} : (a : α) < b ↔ a < b :=
Iff.rfl
@[to_additive]
instance instPartialOrderUnits [Monoid α] [PartialOrder α] : PartialOrder αˣ :=
PartialOrder.lift val val_injective
@[to_additive]
instance [Monoid α] [LinearOrder α] : Max αˣ where
max a b := if a ≤ b then b else a
@[to_additive]
instance [Monoid α] [LinearOrder α] : Min αˣ where
min a b := if a ≤ b then a else b
@[to_additive (attr := simp, norm_cast)]
theorem max_val [Monoid α] [LinearOrder α] (a b : αˣ) : (max a b).val = max a.val b.val := by
simp_rw [max_def, val_le_val, ← apply_ite]
rfl
@[to_additive (attr := simp, norm_cast)]
theorem min_val [Monoid α] [LinearOrder α] (a b : αˣ) : (min a b).val = min a.val b.val := by
simp_rw [min_def, val_le_val, ← apply_ite]
rfl
@[to_additive]
instance [Monoid α] [Ord α] : Ord αˣ where
compare a b := compare a.val b.val
@[to_additive]
theorem compare_val [Monoid α] [Ord α] (a b : αˣ) : compare a.val b.val = compare a b := rfl
@[to_additive]
instance [Monoid α] [LinearOrder α] : LinearOrder αˣ :=
val_injective.linearOrder _ val_le_val val_lt_val min_val max_val compare_val
/-- `val : αˣ → α` as an order embedding. -/
@[to_additive (attr := simps -fullyApplied)
/-- `val : add_units α → α` as an order embedding. -/]
def orderEmbeddingVal [Monoid α] [LinearOrder α] : αˣ ↪o α :=
⟨⟨val, val_injective⟩, .rfl⟩
end Units |
.lake/packages/mathlib/Mathlib/Algebra/Order/Monoid/Associated.lean | import Mathlib.Algebra.GroupWithZero.Associated
import Mathlib.Algebra.Order.Monoid.Canonical.Defs
/-!
# Order on associates
This file shows that divisibility makes associates into a canonically ordered monoid.
-/
variable {M : Type*} [CancelCommMonoidWithZero M]
namespace Associates
instance instIsOrderedMonoid : IsOrderedMonoid (Associates M) where
mul_le_mul_left := fun a _ ⟨d, hd⟩ c => hd.symm ▸ mul_assoc c a d ▸ le_mul_right
instance : CanonicallyOrderedMul (Associates M) where
exists_mul_of_le h := h
le_mul_self _ b := ⟨b, mul_comm ..⟩
le_self_mul _ b := ⟨b, rfl⟩
end Associates |
.lake/packages/mathlib/Mathlib/Algebra/Order/Monoid/Canonical/Basic.lean | import Mathlib.Algebra.Order.Monoid.Canonical.Defs
import Mathlib.Data.Finset.Lattice.Fold
/-!
# Extra lemmas about canonically ordered monoids
-/
namespace Finset
variable {ι α : Type*} [AddCommMonoid α] [LinearOrder α] [OrderBot α] [CanonicallyOrderedAdd α]
{s : Finset ι} {f : ι → α}
@[simp] lemma sup_eq_zero : s.sup f = 0 ↔ ∀ i ∈ s, f i = 0 := by simp [← bot_eq_zero']
@[simp] lemma sup'_eq_zero (hs) : s.sup' hs f = 0 ↔ ∀ i ∈ s, f i = 0 := by simp [sup'_eq_sup]
end Finset |
.lake/packages/mathlib/Mathlib/Algebra/Order/Monoid/Canonical/Defs.lean | import Mathlib.Algebra.Group.Units.Basic
import Mathlib.Algebra.Order.Monoid.Defs
import Mathlib.Algebra.Order.Monoid.Unbundled.ExistsOfLE
import Mathlib.Algebra.NeZero
import Mathlib.Order.BoundedOrder.Basic
/-!
# Canonically ordered monoids
-/
universe u
variable {α : Type u}
/-- An ordered additive monoid is `CanonicallyOrderedAdd`
if the ordering coincides with the subtractibility relation,
which is to say, `a ≤ b` iff there exists `c` with `b = a + c`.
This is satisfied by the natural numbers, for example, but not
the integers or other nontrivial `OrderedAddCommGroup`s.
We have `a ≤ b + a` and `a ≤ a + b` as separate fields. In the commutative case the second field
is redundant, but in the noncommutative case (satisfied most relevantly by the ordinals), this
extra field allows us to prove more things without the extra commutativity assumption. -/
class CanonicallyOrderedAdd (α : Type*) [Add α] [LE α] : Prop
extends ExistsAddOfLE α where
/-- For any `a` and `b`, `a ≤ a + b` -/
protected le_add_self : ∀ a b : α, a ≤ b + a
protected le_self_add : ∀ a b : α, a ≤ a + b
attribute [instance 50] CanonicallyOrderedAdd.toExistsAddOfLE
/-- An ordered monoid is `CanonicallyOrderedMul`
if the ordering coincides with the divisibility relation,
which is to say, `a ≤ b` iff there exists `c` with `b = a * c`.
Examples seem rare; it seems more likely that the `OrderDual`
of a naturally-occurring lattice satisfies this than the lattice
itself (for example, dual of the lattice of ideals of a PID or
Dedekind domain satisfy this; collections of all things ≤ 1 seem to
be more natural that collections of all things ≥ 1). -/
@[to_additive]
class CanonicallyOrderedMul (α : Type*) [Mul α] [LE α] : Prop
extends ExistsMulOfLE α where
/-- For any `a` and `b`, `a ≤ a * b` -/
protected le_mul_self : ∀ a b : α, a ≤ b * a
protected le_self_mul : ∀ a b : α, a ≤ a * b
attribute [instance 50] CanonicallyOrderedMul.toExistsMulOfLE
section Mul
variable [Mul α]
section LE
variable [LE α] [CanonicallyOrderedMul α] {a b c : α}
@[to_additive]
theorem le_mul_self : a ≤ b * a :=
CanonicallyOrderedMul.le_mul_self _ _
@[to_additive]
theorem le_self_mul : a ≤ a * b :=
CanonicallyOrderedMul.le_self_mul _ _
@[to_additive (attr := simp)]
theorem self_le_mul_left (a b : α) : a ≤ b * a :=
le_mul_self
@[to_additive (attr := simp)]
theorem self_le_mul_right (a b : α) : a ≤ a * b :=
le_self_mul
@[to_additive]
theorem le_iff_exists_mul : a ≤ b ↔ ∃ c, b = a * c :=
⟨exists_mul_of_le, by
rintro ⟨c, rfl⟩
exact le_self_mul⟩
end LE
section Preorder
variable [Preorder α] [CanonicallyOrderedMul α] {a b c : α}
@[to_additive]
theorem le_of_mul_le_left : a * b ≤ c → a ≤ c :=
le_self_mul.trans
@[to_additive]
theorem le_mul_of_le_left : a ≤ b → a ≤ b * c :=
le_self_mul.trans'
@[to_additive]
theorem le_of_mul_le_right : a * b ≤ c → b ≤ c :=
le_mul_self.trans
@[to_additive]
theorem le_mul_of_le_right : a ≤ c → a ≤ b * c :=
le_mul_self.trans'
@[to_additive] alias le_mul_left := le_mul_of_le_right
@[to_additive] alias le_mul_right := le_mul_of_le_left
end Preorder
end Mul
section CommMagma
variable [CommMagma α] [Preorder α] [CanonicallyOrderedMul α] {a b c : α}
@[to_additive]
theorem le_iff_exists_mul' : a ≤ b ↔ ∃ c, b = c * a := by
simp only [mul_comm _ a, le_iff_exists_mul]
end CommMagma
section MulOneClass
variable [MulOneClass α]
section LE
variable [LE α] [CanonicallyOrderedMul α] {a b : α}
@[to_additive (attr := simp) zero_le]
theorem one_le (a : α) : 1 ≤ a :=
le_self_mul.trans_eq (one_mul _)
@[to_additive] theorem isBot_one : IsBot (1 : α) := one_le
end LE
section Preorder
variable [Preorder α] [CanonicallyOrderedMul α] {a b : α}
@[to_additive] -- `(attr := simp)` cannot be used here because `a` cannot be inferred by `simp`.
theorem one_lt_of_gt (h : a < b) : 1 < b :=
(one_le _).trans_lt h
alias LT.lt.pos := pos_of_gt
@[to_additive existing] alias LT.lt.one_lt := one_lt_of_gt
end Preorder
section PartialOrder
variable [PartialOrder α] [CanonicallyOrderedMul α] {a b c : α}
@[to_additive]
theorem bot_eq_one [OrderBot α] : (⊥ : α) = 1 := isBot_one.eq_bot.symm
@[to_additive (attr := simp)]
theorem le_one_iff_eq_one : a ≤ 1 ↔ a = 1 :=
(one_le a).ge_iff_eq'
@[to_additive]
theorem one_lt_iff_ne_one : 1 < a ↔ a ≠ 1 :=
(one_le a).lt_iff_ne.trans ne_comm
@[to_additive]
theorem one_lt_of_ne_one (h : a ≠ 1) : 1 < a :=
one_lt_iff_ne_one.2 h
@[to_additive]
theorem eq_one_or_one_lt (a : α) : a = 1 ∨ 1 < a := (one_le a).eq_or_lt.imp_left Eq.symm
@[to_additive]
lemma one_notMem_iff [OrderBot α] {s : Set α} : 1 ∉ s ↔ ∀ x ∈ s, 1 < x :=
bot_eq_one (α := α) ▸ bot_notMem_iff
@[deprecated (since := "2025-05-23")] alias zero_not_mem_iff := zero_notMem_iff
@[to_additive existing, deprecated (since := "2025-05-23")] alias one_not_mem_iff := one_notMem_iff
alias NE.ne.pos := pos_of_ne_zero
@[to_additive existing] alias NE.ne.one_lt := one_lt_of_ne_one
@[to_additive]
theorem exists_one_lt_mul_of_lt (h : a < b) : ∃ (c : _) (_ : 1 < c), a * c = b := by
obtain ⟨c, hc⟩ := le_iff_exists_mul.1 h.le
refine ⟨c, one_lt_iff_ne_one.2 ?_, hc.symm⟩
rintro rfl
simp [hc] at h
@[to_additive]
theorem lt_iff_exists_mul [MulLeftStrictMono α] : a < b ↔ ∃ c > 1, b = a * c := by
rw [lt_iff_le_and_ne, le_iff_exists_mul, ← exists_and_right]
apply exists_congr
intro c
rw [and_comm, and_congr_left_iff, gt_iff_lt]
rintro rfl
constructor
· rw [one_lt_iff_ne_one]
apply mt
rintro rfl
rw [mul_one]
· rw [← (self_le_mul_right a c).lt_iff_ne]
apply lt_mul_of_one_lt_right'
end PartialOrder
end MulOneClass
section Semigroup
variable [Semigroup α]
section LE
variable [LE α] [CanonicallyOrderedMul α]
-- see Note [lower instance priority]
@[to_additive]
instance (priority := 10) CanonicallyOrderedMul.toMulLeftMono :
MulLeftMono α where
elim a b c hbc := by
obtain ⟨c, hc, rfl⟩ := exists_mul_of_le hbc
rw [le_iff_exists_mul]
exact ⟨c, (mul_assoc _ _ _).symm⟩
end LE
end Semigroup
-- TODO: make it an instance
@[to_additive]
lemma CanonicallyOrderedMul.toIsOrderedMonoid
[CommMonoid α] [PartialOrder α] [CanonicallyOrderedMul α] : IsOrderedMonoid α where
mul_le_mul_left _ _ := mul_le_mul_left'
section Monoid
variable [Monoid α]
section PartialOrder
variable [PartialOrder α] [CanonicallyOrderedMul α] {a b c : α}
@[to_additive] instance CanonicallyOrderedCommMonoid.toUniqueUnits : Unique αˣ where
uniq a := Units.ext <| le_one_iff_eq_one.mp (le_of_mul_le_left a.mul_inv.le)
end PartialOrder
end Monoid
section CommMonoid
variable [CommMonoid α]
section PartialOrder
variable [PartialOrder α] [CanonicallyOrderedMul α] {a b c : α}
@[to_additive (attr := simp) add_pos_iff]
theorem one_lt_mul_iff : 1 < a * b ↔ 1 < a ∨ 1 < b := by
simp only [one_lt_iff_ne_one, Ne, mul_eq_one, not_and_or]
end PartialOrder
end CommMonoid
namespace NeZero
theorem pos {M} [AddZeroClass M] [PartialOrder M] [CanonicallyOrderedAdd M]
(a : M) [NeZero a] : 0 < a :=
(zero_le a).lt_of_ne <| NeZero.out.symm
theorem of_gt {M} [AddZeroClass M] [Preorder M] [CanonicallyOrderedAdd M]
{x y : M} (h : x < y) : NeZero y :=
of_pos <| pos_of_gt h
-- 1 < p is still an often-used `Fact`, due to `Nat.Prime` implying it, and it implying `Nontrivial`
-- on `ZMod`'s ring structure. We cannot just set this to be any `x < y`, else that becomes a
-- metavariable and it will hugely slow down typeclass inference.
instance (priority := 10) of_gt' {M : Type*} [AddZeroClass M] [Preorder M] [CanonicallyOrderedAdd M]
[One M] {y : M}
[Fact (1 < y)] : NeZero y := of_gt <| @Fact.out (1 < y) _
theorem of_ge {M} [AddZeroClass M] [PartialOrder M] [CanonicallyOrderedAdd M]
{x y : M} [NeZero x] (h : x ≤ y) : NeZero y :=
of_pos <| lt_of_lt_of_le (pos x) h
end NeZero
section CanonicallyLinearOrderedMonoid
variable [Monoid α] [LinearOrder α] [CanonicallyOrderedMul α]
@[to_additive]
theorem min_mul_distrib (a b c : α) : min a (b * c) = min a (min a b * min a c) := by
rcases le_total a b with hb | hb
· simp [hb, le_mul_right]
· rcases le_total a c with hc | hc
· simp [hc, le_mul_left]
· simp [hb, hc]
@[to_additive]
theorem min_mul_distrib' (a b c : α) : min (a * b) c = min (min a c * min b c) c := by
simpa [min_comm _ c] using min_mul_distrib c a b
@[to_additive]
theorem one_min (a : α) : min 1 a = 1 :=
min_eq_left (one_le a)
@[to_additive]
theorem min_one (a : α) : min a 1 = 1 :=
min_eq_right (one_le a)
/-- In a linearly ordered monoid, we are happy for `bot_eq_one` to be a `@[simp]` lemma. -/
@[to_additive (attr := simp)
/-- In a linearly ordered monoid, we are happy for `bot_eq_zero` to be a `@[simp]` lemma -/]
theorem bot_eq_one' [OrderBot α] : (⊥ : α) = 1 :=
bot_eq_one
end CanonicallyLinearOrderedMonoid |
.lake/packages/mathlib/Mathlib/Algebra/Order/Monoid/Unbundled/WithTop.lean | import Mathlib.Algebra.CharZero.Defs
import Mathlib.Algebra.Group.Hom.Defs
import Mathlib.Algebra.Order.Monoid.Unbundled.ExistsOfLE
import Mathlib.Algebra.Order.ZeroLEOne
import Mathlib.Order.WithBot
/-! # Adjoining top/bottom elements to ordered monoids.
-/
universe u v
variable {α : Type u} {β : Type v}
open Function
namespace WithTop
section One
variable [One α] {a : α}
@[to_additive]
instance one : One (WithTop α) :=
⟨(1 : α)⟩
@[to_additive (attr := simp, norm_cast)]
theorem coe_one : ((1 : α) : WithTop α) = 1 :=
rfl
@[to_additive (attr := simp, norm_cast)]
lemma coe_eq_one : (a : WithTop α) = 1 ↔ a = 1 := coe_eq_coe
@[to_additive] lemma coe_ne_one : (a : WithTop α) ≠ 1 ↔ a ≠ 1 := coe_eq_one.ne
@[to_additive (attr := simp, norm_cast)]
lemma one_eq_coe : 1 = (a : WithTop α) ↔ a = 1 := eq_comm.trans coe_eq_one
@[to_additive (attr := simp)] lemma top_ne_one : (⊤ : WithTop α) ≠ 1 := top_ne_coe
@[to_additive (attr := simp)] lemma one_ne_top : (1 : WithTop α) ≠ ⊤ := coe_ne_top
@[to_additive (attr := simp)]
theorem untop_one : (1 : WithTop α).untop coe_ne_top = 1 :=
rfl
@[to_additive (attr := simp)]
theorem untopD_one (d : α) : (1 : WithTop α).untopD d = 1 :=
rfl
@[to_additive (attr := simp, norm_cast) coe_nonneg]
theorem one_le_coe [LE α] {a : α} : 1 ≤ (a : WithTop α) ↔ 1 ≤ a :=
coe_le_coe
@[to_additive (attr := simp, norm_cast) coe_le_zero]
theorem coe_le_one [LE α] {a : α} : (a : WithTop α) ≤ 1 ↔ a ≤ 1 :=
coe_le_coe
@[to_additive (attr := simp, norm_cast) coe_pos]
theorem one_lt_coe [LT α] {a : α} : 1 < (a : WithTop α) ↔ 1 < a :=
coe_lt_coe
@[to_additive (attr := simp, norm_cast) coe_lt_zero]
theorem coe_lt_one [LT α] {a : α} : (a : WithTop α) < 1 ↔ a < 1 :=
coe_lt_coe
@[to_additive (attr := simp)]
protected theorem map_one {β} (f : α → β) : (1 : WithTop α).map f = (f 1 : WithTop β) :=
rfl
@[to_additive]
theorem map_eq_one_iff {α} {f : α → β} {v : WithTop α} [One β] :
WithTop.map f v = 1 ↔ ∃ x, v = .some x ∧ f x = 1 := map_eq_some_iff
@[to_additive]
theorem one_eq_map_iff {α} {f : α → β} {v : WithTop α} [One β] :
1 = WithTop.map f v ↔ ∃ x, v = .some x ∧ f x = 1 := some_eq_map_iff
instance zeroLEOneClass [Zero α] [LE α] [ZeroLEOneClass α] : ZeroLEOneClass (WithTop α) :=
⟨coe_le_coe.2 zero_le_one⟩
end One
section Add
variable [Add α] {w x y z : WithTop α} {a b : α}
instance add : Add (WithTop α) :=
⟨Option.map₂ (· + ·)⟩
@[simp, norm_cast] lemma coe_add (a b : α) : ↑(a + b) = (a + b : WithTop α) := rfl
@[simp] lemma top_add (x : WithTop α) : ⊤ + x = ⊤ := rfl
@[simp] lemma add_top (x : WithTop α) : x + ⊤ = ⊤ := by cases x <;> rfl
@[simp] lemma add_eq_top : x + y = ⊤ ↔ x = ⊤ ∨ y = ⊤ := by cases x <;> cases y <;> simp [← coe_add]
lemma add_ne_top : x + y ≠ ⊤ ↔ x ≠ ⊤ ∧ y ≠ ⊤ := by cases x <;> cases y <;> simp [← coe_add]
@[simp]
lemma add_lt_top [LT α] : x + y < ⊤ ↔ x < ⊤ ∧ y < ⊤ := by
simp_rw [WithTop.lt_top_iff_ne_top, add_ne_top]
theorem add_eq_coe :
∀ {a b : WithTop α} {c : α}, a + b = c ↔ ∃ a' b' : α, ↑a' = a ∧ ↑b' = b ∧ a' + b' = c
| ⊤, b, c => by simp
| some a, ⊤, c => by simp
| some a, some b, c => by norm_cast; simp
lemma add_coe_eq_top_iff : x + b = ⊤ ↔ x = ⊤ := by simp
lemma coe_add_eq_top_iff : a + y = ⊤ ↔ y = ⊤ := by simp
lemma add_right_inj [IsRightCancelAdd α] (hz : z ≠ ⊤) : x + z = y + z ↔ x = y := by
lift z to α using hz; cases x <;> cases y <;> simp [← coe_add]
lemma add_right_cancel [IsRightCancelAdd α] (hz : z ≠ ⊤) (h : x + z = y + z) : x = y :=
(WithTop.add_right_inj hz).1 h
lemma add_left_inj [IsLeftCancelAdd α] (hx : x ≠ ⊤) : x + y = x + z ↔ y = z := by
lift x to α using hx; cases y <;> cases z <;> simp [← coe_add]
lemma add_left_cancel [IsLeftCancelAdd α] (hx : x ≠ ⊤) (h : x + y = x + z) : y = z :=
(WithTop.add_left_inj hx).1 h
instance addLeftMono [LE α] [AddLeftMono α] : AddLeftMono (WithTop α) where
elim x y z := by
cases x <;> cases y <;> cases z <;> simp [← coe_add]; simpa using fun _ ↦ by gcongr
instance addRightMono [LE α] [AddRightMono α] : AddRightMono (WithTop α) where
elim x y z := by
cases x <;> cases y <;> cases z <;> simp [← coe_add, swap]; simpa using fun _ ↦ by gcongr
instance addLeftReflectLT [LT α] [AddLeftReflectLT α] : AddLeftReflectLT (WithTop α) where
elim x y z := by
cases x <;> cases y <;> cases z <;> simp [← coe_add]; simpa using lt_of_add_lt_add_left
instance addRightReflectLT [LT α] [AddRightReflectLT α] : AddRightReflectLT (WithTop α) where
elim x y z := by
cases x <;> cases y <;> cases z <;> simp [← coe_add, swap]; simpa using lt_of_add_lt_add_right
protected lemma le_of_add_le_add_left [LE α] [AddLeftReflectLE α] (hx : x ≠ ⊤) :
x + y ≤ x + z → y ≤ z := by
lift x to α using hx; cases y <;> cases z <;> simp [← coe_add]; simpa using le_of_add_le_add_left
protected lemma le_of_add_le_add_right [LE α] [AddRightReflectLE α] (hz : z ≠ ⊤) :
x + z ≤ y + z → x ≤ y := by
lift z to α using hz; cases x <;> cases y <;> simp [← coe_add]; simpa using le_of_add_le_add_right
protected lemma add_lt_add_left [LT α] [AddLeftStrictMono α] (hx : x ≠ ⊤) :
y < z → x + y < x + z := by
lift x to α using hx; cases y <;> cases z <;> simp [← coe_add]; simpa using fun _ ↦ by gcongr
protected lemma add_lt_add_right [LT α] [AddRightStrictMono α] (hz : z ≠ ⊤) :
x < y → x + z < y + z := by
lift z to α using hz; cases x <;> cases y <;> simp [← coe_add]; simpa using fun _ ↦ by gcongr
protected lemma add_le_add_iff_left [LE α] [AddLeftMono α] [AddLeftReflectLE α] (hx : x ≠ ⊤) :
x + y ≤ x + z ↔ y ≤ z := ⟨WithTop.le_of_add_le_add_left hx, fun _ ↦ by gcongr⟩
protected lemma add_le_add_iff_right [LE α] [AddRightMono α] [AddRightReflectLE α] (hz : z ≠ ⊤) :
x + z ≤ y + z ↔ x ≤ y := ⟨WithTop.le_of_add_le_add_right hz, fun _ ↦ by gcongr⟩
protected lemma add_lt_add_iff_left [LT α] [AddLeftStrictMono α] [AddLeftReflectLT α] (hx : x ≠ ⊤) :
x + y < x + z ↔ y < z := ⟨lt_of_add_lt_add_left, WithTop.add_lt_add_left hx⟩
protected lemma add_lt_add_iff_right [LT α] [AddRightStrictMono α] [AddRightReflectLT α]
(hz : z ≠ ⊤) : x + z < y + z ↔ x < y := ⟨lt_of_add_lt_add_right, WithTop.add_lt_add_right hz⟩
protected theorem add_lt_add_of_le_of_lt [Preorder α] [AddLeftStrictMono α]
[AddRightMono α] (hw : w ≠ ⊤) (hwy : w ≤ y) (hxz : x < z) :
w + x < y + z :=
(WithTop.add_lt_add_left hw hxz).trans_le <| by gcongr
protected theorem add_lt_add_of_lt_of_le [Preorder α] [AddLeftMono α]
[AddRightStrictMono α] (hx : x ≠ ⊤) (hwy : w < y) (hxz : x ≤ z) :
w + x < y + z :=
(WithTop.add_lt_add_right hx hwy).trans_le <| by gcongr
lemma addLECancellable_of_ne_top [LE α] [AddLeftReflectLE α]
(hx : x ≠ ⊤) : AddLECancellable x := fun _b _c ↦ WithTop.le_of_add_le_add_left hx
lemma addLECancellable_of_lt_top [Preorder α] [AddLeftReflectLE α]
(hx : x < ⊤) : AddLECancellable x := addLECancellable_of_ne_top hx.ne
lemma addLECancellable_coe [LE α] [AddLeftReflectLE α] (a : α) :
AddLECancellable (a : WithTop α) := addLECancellable_of_ne_top coe_ne_top
lemma addLECancellable_iff_ne_top [Nonempty α] [Preorder α]
[AddLeftReflectLE α] : AddLECancellable x ↔ x ≠ ⊤ where
mp := by rintro h rfl; exact (coe_lt_top <| Classical.arbitrary _).not_ge <| h <| by simp
mpr := addLECancellable_of_ne_top
-- There is no `WithTop.map_mul_of_mulHom`, since `WithTop` does not have a multiplication.
@[simp]
protected theorem map_add {F} [Add β] [FunLike F α β] [AddHomClass F α β]
(f : F) (a b : WithTop α) :
(a + b).map f = a.map f + b.map f := by
induction a
· exact (top_add _).symm
· induction b
· exact (add_top _).symm
· rw [map_coe, map_coe, ← coe_add, ← coe_add, ← map_add]
rfl
end Add
instance addSemigroup [AddSemigroup α] : AddSemigroup (WithTop α) :=
{ WithTop.add with
add_assoc := fun _ _ _ => Option.map₂_assoc add_assoc }
instance addCommSemigroup [AddCommSemigroup α] : AddCommSemigroup (WithTop α) :=
{ WithTop.addSemigroup with
add_comm := fun _ _ => Option.map₂_comm add_comm }
instance addZeroClass [AddZeroClass α] : AddZeroClass (WithTop α) :=
{ WithTop.zero, WithTop.add with
zero_add := Option.map₂_left_identity zero_add
add_zero := Option.map₂_right_identity add_zero }
section AddMonoid
variable [AddMonoid α]
instance addMonoid : AddMonoid (WithTop α) where
__ := WithTop.addSemigroup
__ := WithTop.addZeroClass
nsmul n a := match a, n with
| (a : α), n => ↑(n • a)
| ⊤, 0 => 0
| ⊤, _n + 1 => ⊤
nsmul_zero a := by cases a <;> simp [zero_nsmul]
nsmul_succ n a := by cases a <;> cases n <;> simp [succ_nsmul, coe_add]
@[simp, norm_cast] lemma coe_nsmul (a : α) (n : ℕ) : ↑(n • a) = n • (a : WithTop α) := rfl
/-- Coercion from `α` to `WithTop α` as an `AddMonoidHom`. -/
def addHom : α →+ WithTop α where
toFun := WithTop.some
map_zero' := rfl
map_add' _ _ := rfl
@[simp, norm_cast] lemma coe_addHom : ⇑(addHom : α →+ WithTop α) = WithTop.some := rfl
end AddMonoid
instance addCommMonoid [AddCommMonoid α] : AddCommMonoid (WithTop α) :=
{ WithTop.addMonoid, WithTop.addCommSemigroup with }
section AddMonoidWithOne
variable [AddMonoidWithOne α]
instance addMonoidWithOne : AddMonoidWithOne (WithTop α) :=
{ WithTop.one, WithTop.addMonoid with
natCast := fun n => ↑(n : α),
natCast_zero := by
simp only [Nat.cast_zero, WithTop.coe_zero],
natCast_succ := fun n => by
simp only [Nat.cast_add_one, WithTop.coe_add, WithTop.coe_one] }
@[simp, norm_cast] lemma coe_natCast (n : ℕ) : ((n : α) : WithTop α) = n := rfl
@[simp] lemma top_ne_natCast (n : ℕ) : (⊤ : WithTop α) ≠ n := top_ne_coe
@[simp] lemma natCast_ne_top (n : ℕ) : (n : WithTop α) ≠ ⊤ := coe_ne_top
@[simp] lemma natCast_lt_top [LT α] (n : ℕ) : (n : WithTop α) < ⊤ := coe_lt_top _
@[simp] lemma coe_ofNat (n : ℕ) [n.AtLeastTwo] :
((ofNat(n) : α) : WithTop α) = ofNat(n) := rfl
@[simp] lemma coe_eq_ofNat (n : ℕ) [n.AtLeastTwo] (m : α) :
(m : WithTop α) = ofNat(n) ↔ m = ofNat(n) :=
coe_eq_coe
@[simp] lemma ofNat_eq_coe (n : ℕ) [n.AtLeastTwo] (m : α) :
ofNat(n) = (m : WithTop α) ↔ ofNat(n) = m :=
coe_eq_coe
@[simp] lemma ofNat_ne_top (n : ℕ) [n.AtLeastTwo] : (ofNat(n) : WithTop α) ≠ ⊤ :=
natCast_ne_top n
@[simp] lemma top_ne_ofNat (n : ℕ) [n.AtLeastTwo] : (⊤ : WithTop α) ≠ ofNat(n) :=
top_ne_natCast n
@[simp] lemma map_ofNat {f : α → β} (n : ℕ) [n.AtLeastTwo] :
WithTop.map f (ofNat(n) : WithTop α) = f (ofNat(n)) := map_coe f n
@[simp] lemma map_natCast {f : α → β} (n : ℕ) :
WithTop.map f (n : WithTop α) = f n := map_coe f n
lemma map_eq_ofNat_iff {f : β → α} {n : ℕ} [n.AtLeastTwo] {a : WithTop β} :
a.map f = ofNat(n) ↔ ∃ x, a = .some x ∧ f x = n := map_eq_some_iff
lemma ofNat_eq_map_iff {f : β → α} {n : ℕ} [n.AtLeastTwo] {a : WithTop β} :
ofNat(n) = a.map f ↔ ∃ x, a = .some x ∧ f x = n := some_eq_map_iff
lemma map_eq_natCast_iff {f : β → α} {n : ℕ} {a : WithTop β} :
a.map f = n ↔ ∃ x, a = .some x ∧ f x = n := map_eq_some_iff
lemma natCast_eq_map_iff {f : β → α} {n : ℕ} {a : WithTop β} :
n = a.map f ↔ ∃ x, a = .some x ∧ f x = n := some_eq_map_iff
end AddMonoidWithOne
instance charZero [AddMonoidWithOne α] [CharZero α] : CharZero (WithTop α) :=
{ cast_injective := Function.Injective.comp (f := Nat.cast (R := α))
(fun _ _ => WithTop.coe_eq_coe.1) Nat.cast_injective}
instance addCommMonoidWithOne [AddCommMonoidWithOne α] : AddCommMonoidWithOne (WithTop α) :=
{ WithTop.addMonoidWithOne, WithTop.addCommMonoid with }
-- instance orderedAddCommMonoid [OrderedAddCommMonoid α] : OrderedAddCommMonoid (WithTop α) where
-- add_le_add_left _ _ := add_le_add_left
--
-- instance linearOrderedAddCommMonoidWithTop [LinearOrderedAddCommMonoid α] :
-- LinearOrderedAddCommMonoidWithTop (WithTop α) :=
-- { WithTop.orderTop, WithTop.linearOrder, WithTop.orderedAddCommMonoid with
-- top_add' := WithTop.top_add }
--
instance existsAddOfLE [LE α] [Add α] [ExistsAddOfLE α] : ExistsAddOfLE (WithTop α) :=
⟨fun {a} {b} =>
match a, b with
| ⊤, ⊤ => by simp
| (a : α), ⊤ => fun _ => ⟨⊤, rfl⟩
| (a : α), (b : α) => fun h => by
obtain ⟨c, rfl⟩ := exists_add_of_le (WithTop.coe_le_coe.1 h)
exact ⟨c, rfl⟩
| ⊤, (b : α) => fun h => (not_top_le_coe _ h).elim⟩
-- instance canonicallyOrderedAddCommMonoid [CanonicallyOrderedAddCommMonoid α] :
-- CanonicallyOrderedAddCommMonoid (WithTop α) :=
-- { WithTop.orderBot, WithTop.orderedAddCommMonoid, WithTop.existsAddOfLE with
-- le_self_add := fun a b =>
-- match a, b with
-- | ⊤, ⊤ => le_rfl
-- | (a : α), ⊤ => le_top
-- | (a : α), (b : α) => WithTop.coe_le_coe.2 le_self_add
-- | ⊤, (b : α) => le_rfl }
--
-- instance [CanonicallyLinearOrderedAddCommMonoid α] :
-- CanonicallyLinearOrderedAddCommMonoid (WithTop α) :=
-- { WithTop.canonicallyOrderedAddCommMonoid, WithTop.linearOrder with }
@[to_additive (attr := simp) top_pos]
theorem one_lt_top [One α] [LT α] : (1 : WithTop α) < ⊤ := coe_lt_top _
/-- A version of `WithTop.map` for `OneHom`s. -/
@[to_additive (attr := simps -fullyApplied)
/-- A version of `WithTop.map` for `ZeroHom`s -/]
protected def _root_.OneHom.withTopMap {M N : Type*} [One M] [One N] (f : OneHom M N) :
OneHom (WithTop M) (WithTop N) where
toFun := WithTop.map f
map_one' := by rw [WithTop.map_one, map_one, coe_one]
/-- A version of `WithTop.map` for `AddHom`s. -/
@[simps -fullyApplied]
protected def _root_.AddHom.withTopMap {M N : Type*} [Add M] [Add N] (f : AddHom M N) :
AddHom (WithTop M) (WithTop N) where
toFun := WithTop.map f
map_add' := WithTop.map_add f
/-- A version of `WithTop.map` for `AddMonoidHom`s. -/
@[simps -fullyApplied]
protected def _root_.AddMonoidHom.withTopMap {M N : Type*} [AddZeroClass M] [AddZeroClass N]
(f : M →+ N) : WithTop M →+ WithTop N :=
{ ZeroHom.withTopMap f.toZeroHom, AddHom.withTopMap f.toAddHom with toFun := WithTop.map f }
end WithTop
namespace WithBot
section One
variable [One α] {a : α}
@[to_additive] instance one : One (WithBot α) := WithTop.one
@[to_additive (attr := simp, norm_cast)] lemma coe_one : ((1 : α) : WithBot α) = 1 := rfl
@[to_additive (attr := simp, norm_cast)]
lemma coe_eq_one : (a : WithBot α) = 1 ↔ a = 1 := coe_eq_coe
@[to_additive (attr := simp, norm_cast)]
lemma one_eq_coe : 1 = (a : WithBot α) ↔ a = 1 := eq_comm.trans coe_eq_one
@[to_additive (attr := simp)] lemma bot_ne_one : (⊥ : WithBot α) ≠ 1 := bot_ne_coe
@[to_additive (attr := simp)] lemma one_ne_bot : (1 : WithBot α) ≠ ⊥ := coe_ne_bot
@[to_additive (attr := simp)]
theorem unbot_one : (1 : WithBot α).unbot coe_ne_bot = 1 :=
rfl
@[to_additive (attr := simp)]
theorem unbotD_one (d : α) : (1 : WithBot α).unbotD d = 1 :=
rfl
@[to_additive (attr := simp, norm_cast) coe_nonneg]
theorem one_le_coe [LE α] : 1 ≤ (a : WithBot α) ↔ 1 ≤ a := coe_le_coe
@[to_additive (attr := simp, norm_cast) coe_le_zero]
theorem coe_le_one [LE α] : (a : WithBot α) ≤ 1 ↔ a ≤ 1 := coe_le_coe
@[to_additive (attr := simp, norm_cast) coe_pos]
theorem one_lt_coe [LT α] : 1 < (a : WithBot α) ↔ 1 < a := coe_lt_coe
@[to_additive (attr := simp, norm_cast) coe_lt_zero]
theorem coe_lt_one [LT α] : (a : WithBot α) < 1 ↔ a < 1 := coe_lt_coe
@[to_additive (attr := simp)]
protected theorem map_one {β} (f : α → β) : (1 : WithBot α).map f = (f 1 : WithBot β) :=
rfl
@[to_additive]
theorem map_eq_one_iff {α} {f : α → β} {v : WithBot α} [One β] :
WithBot.map f v = 1 ↔ ∃ x, v = .some x ∧ f x = 1 := map_eq_some_iff
@[to_additive]
theorem one_eq_map_iff {α} {f : α → β} {v : WithBot α} [One β] :
1 = WithBot.map f v ↔ ∃ x, v = .some x ∧ f x = 1 := some_eq_map_iff
instance zeroLEOneClass [Zero α] [LE α] [ZeroLEOneClass α] : ZeroLEOneClass (WithBot α) :=
⟨coe_le_coe.2 zero_le_one⟩
end One
section Add
variable [Add α] {w x y z : WithBot α} {a b : α}
instance add : Add (WithBot α) :=
⟨Option.map₂ (· + ·)⟩
@[simp, norm_cast] lemma coe_add (a b : α) : ↑(a + b) = (a + b : WithBot α) := rfl
@[simp] lemma bot_add (x : WithBot α) : ⊥ + x = ⊥ := rfl
@[simp] lemma add_bot (x : WithBot α) : x + ⊥ = ⊥ := by cases x <;> rfl
@[simp] lemma add_eq_bot : x + y = ⊥ ↔ x = ⊥ ∨ y = ⊥ := by cases x <;> cases y <;> simp [← coe_add]
lemma add_ne_bot : x + y ≠ ⊥ ↔ x ≠ ⊥ ∧ y ≠ ⊥ := by cases x <;> cases y <;> simp [← coe_add]
@[simp]
lemma bot_lt_add [LT α] : ⊥ < x + y ↔ ⊥ < x ∧ ⊥ < y := by
simp_rw [WithBot.bot_lt_iff_ne_bot, add_ne_bot]
theorem add_eq_coe :
∀ {a b : WithBot α} {c : α}, a + b = c ↔ ∃ a' b' : α, ↑a' = a ∧ ↑b' = b ∧ a' + b' = c
| ⊥, b, c => by simp
| some a, ⊥, c => by simp
| some a, some b, c => by norm_cast; simp
lemma add_coe_eq_bot_iff : x + b = ⊥ ↔ x = ⊥ := by simp
lemma coe_add_eq_bot_iff : a + y = ⊥ ↔ y = ⊥ := by simp
lemma add_right_inj [IsRightCancelAdd α] (hz : z ≠ ⊥) : x + z = y + z ↔ x = y := by
lift z to α using hz; cases x <;> cases y <;> simp [← coe_add]
lemma add_right_cancel [IsRightCancelAdd α] (hz : z ≠ ⊥) (h : x + z = y + z) : x = y :=
(WithBot.add_right_inj hz).1 h
lemma add_left_inj [IsLeftCancelAdd α] (hx : x ≠ ⊥) : x + y = x + z ↔ y = z := by
lift x to α using hx; cases y <;> cases z <;> simp [← coe_add]
lemma add_left_cancel [IsLeftCancelAdd α] (hx : x ≠ ⊥) (h : x + y = x + z) : y = z :=
(WithBot.add_left_inj hx).1 h
instance addLeftMono [LE α] [AddLeftMono α] : AddLeftMono (WithBot α) where
elim x y z := by
cases x <;> cases y <;> cases z <;> simp [← coe_add]; simpa using fun _ ↦ by gcongr
instance addRightMono [LE α] [AddRightMono α] : AddRightMono (WithBot α) where
elim x y z := by
cases x <;> cases y <;> cases z <;> simp [← coe_add, swap]; simpa using fun _ ↦ by gcongr
instance addLeftReflectLT [LT α] [AddLeftReflectLT α] : AddLeftReflectLT (WithBot α) where
elim x y z := by
cases x <;> cases y <;> cases z <;> simp [← coe_add]; simpa using lt_of_add_lt_add_left
instance addRightReflectLT [LT α] [AddRightReflectLT α] : AddRightReflectLT (WithBot α) where
elim x y z := by
cases x <;> cases y <;> cases z <;> simp [← coe_add, swap]; simpa using lt_of_add_lt_add_right
protected lemma le_of_add_le_add_left [LE α] [AddLeftReflectLE α] (hx : x ≠ ⊥) :
x + y ≤ x + z → y ≤ z := by
lift x to α using hx; cases y <;> cases z <;> simp [← coe_add]; simpa using le_of_add_le_add_left
protected lemma le_of_add_le_add_right [LE α] [AddRightReflectLE α] (hz : z ≠ ⊥) :
x + z ≤ y + z → x ≤ y := by
lift z to α using hz; cases x <;> cases y <;> simp [← coe_add]; simpa using le_of_add_le_add_right
protected lemma add_lt_add_left [LT α] [AddLeftStrictMono α] (hx : x ≠ ⊥) :
y < z → x + y < x + z := by
lift x to α using hx; cases y <;> cases z <;> simp [← coe_add]; simpa using fun _ ↦ by gcongr
protected lemma add_lt_add_right [LT α] [AddRightStrictMono α] (hz : z ≠ ⊥) :
x < y → x + z < y + z := by
lift z to α using hz; cases x <;> cases y <;> simp [← coe_add]; simpa using fun _ ↦ by gcongr
protected lemma add_le_add_iff_left [LE α] [AddLeftMono α] [AddLeftReflectLE α] (hx : x ≠ ⊥) :
x + y ≤ x + z ↔ y ≤ z := ⟨WithBot.le_of_add_le_add_left hx, fun _ ↦ by gcongr⟩
protected lemma add_le_add_iff_right [LE α] [AddRightMono α] [AddRightReflectLE α] (hz : z ≠ ⊥) :
x + z ≤ y + z ↔ x ≤ y := ⟨WithBot.le_of_add_le_add_right hz, fun _ ↦ by gcongr⟩
protected lemma add_lt_add_iff_left [LT α] [AddLeftStrictMono α] [AddLeftReflectLT α] (hx : x ≠ ⊥) :
x + y < x + z ↔ y < z := ⟨lt_of_add_lt_add_left, WithBot.add_lt_add_left hx⟩
protected lemma add_lt_add_iff_right [LT α] [AddRightStrictMono α] [AddRightReflectLT α]
(hz : z ≠ ⊥) : x + z < y + z ↔ x < y := ⟨lt_of_add_lt_add_right, WithBot.add_lt_add_right hz⟩
protected theorem add_lt_add_of_le_of_lt [Preorder α] [AddLeftStrictMono α]
[AddRightMono α] (hw : w ≠ ⊥) (hwy : w ≤ y) (hxz : x < z) :
w + x < y + z :=
(WithBot.add_lt_add_left hw hxz).trans_le <| by gcongr
protected theorem add_lt_add_of_lt_of_le [Preorder α] [AddLeftMono α]
[AddRightStrictMono α] (hx : x ≠ ⊥) (hwy : w < y) (hxz : x ≤ z) :
w + x < y + z :=
(WithBot.add_lt_add_right hx hwy).trans_le <| by gcongr
lemma addLECancellable_of_ne_bot [LE α] [AddLeftReflectLE α]
(hx : x ≠ ⊥) : AddLECancellable x := fun _b _c ↦ WithBot.le_of_add_le_add_left hx
lemma addLECancellable_of_lt_bot [Preorder α] [AddLeftReflectLE α]
(hx : x < ⊥) : AddLECancellable x := addLECancellable_of_ne_bot hx.ne
lemma addLECancellable_coe [LE α] [AddLeftReflectLE α] (a : α) :
AddLECancellable (a : WithBot α) := addLECancellable_of_ne_bot coe_ne_bot
lemma addLECancellable_iff_ne_bot [Nonempty α] [Preorder α]
[AddLeftReflectLE α] : AddLECancellable x ↔ x ≠ ⊥ where
mp := by rintro h rfl; exact (bot_lt_coe <| Classical.arbitrary _).not_ge <| h <| by simp
mpr := addLECancellable_of_ne_bot
/--
Addition in `WithBot (WithTop α)` is right cancellative provided the element
being cancelled is not `⊤` or `⊥`.
-/
lemma add_le_add_iff_right' {α : Type*} [Add α] [LE α]
[AddRightMono α] [AddRightReflectLE α]
{a b c : WithBot (WithTop α)} (hc : c ≠ ⊥) (hc' : c ≠ ⊤) :
a + c ≤ b + c ↔ a ≤ b := by
induction a <;> induction b <;> induction c <;> norm_cast at * <;>
aesop (add simp WithTop.add_le_add_iff_right)
-- There is no `WithBot.map_mul_of_mulHom`, since `WithBot` does not have a multiplication.
@[simp]
protected theorem map_add {F} [Add β] [FunLike F α β] [AddHomClass F α β]
(f : F) (a b : WithBot α) :
(a + b).map f = a.map f + b.map f := by
induction a
· exact (bot_add _).symm
· induction b
· exact (add_bot _).symm
· rw [map_coe, map_coe, ← coe_add, ← coe_add, ← map_add]
rfl
end Add
instance AddSemigroup [AddSemigroup α] : AddSemigroup (WithBot α) :=
WithTop.addSemigroup
instance addCommSemigroup [AddCommSemigroup α] : AddCommSemigroup (WithBot α) :=
WithTop.addCommSemigroup
instance addZeroClass [AddZeroClass α] : AddZeroClass (WithBot α) :=
WithTop.addZeroClass
section AddMonoid
variable [AddMonoid α]
instance addMonoid : AddMonoid (WithBot α) := WithTop.addMonoid
/-- Coercion from `α` to `WithBot α` as an `AddMonoidHom`. -/
def addHom : α →+ WithBot α where
toFun := WithTop.some
map_zero' := rfl
map_add' _ _ := rfl
@[simp, norm_cast] lemma coe_addHom : ⇑(addHom : α →+ WithBot α) = WithBot.some := rfl
@[simp, norm_cast]
lemma coe_nsmul (a : α) (n : ℕ) : ↑(n • a) = n • (a : WithBot α) :=
(addHom : α →+ WithBot α).map_nsmul _ _
end AddMonoid
instance addCommMonoid [AddCommMonoid α] : AddCommMonoid (WithBot α) :=
WithTop.addCommMonoid
section AddMonoidWithOne
variable [AddMonoidWithOne α]
instance addMonoidWithOne : AddMonoidWithOne (WithBot α) := WithTop.addMonoidWithOne
@[norm_cast] lemma coe_natCast (n : ℕ) : ((n : α) : WithBot α) = n := rfl
@[simp] lemma natCast_ne_bot (n : ℕ) : (n : WithBot α) ≠ ⊥ := coe_ne_bot
@[simp] lemma bot_ne_natCast (n : ℕ) : (⊥ : WithBot α) ≠ n := bot_ne_coe
@[simp] lemma coe_ofNat (n : ℕ) [n.AtLeastTwo] :
((ofNat(n) : α) : WithBot α) = ofNat(n) := rfl
@[simp] lemma coe_eq_ofNat (n : ℕ) [n.AtLeastTwo] (m : α) :
(m : WithBot α) = ofNat(n) ↔ m = ofNat(n) :=
coe_eq_coe
@[simp] lemma ofNat_eq_coe (n : ℕ) [n.AtLeastTwo] (m : α) :
ofNat(n) = (m : WithBot α) ↔ ofNat(n) = m :=
coe_eq_coe
@[simp] lemma ofNat_ne_bot (n : ℕ) [n.AtLeastTwo] : (ofNat(n) : WithBot α) ≠ ⊥ :=
natCast_ne_bot n
@[simp] lemma bot_ne_ofNat (n : ℕ) [n.AtLeastTwo] : (⊥ : WithBot α) ≠ ofNat(n) :=
bot_ne_natCast n
@[simp] lemma map_ofNat {f : α → β} (n : ℕ) [n.AtLeastTwo] :
WithBot.map f (ofNat(n) : WithBot α) = f ofNat(n) := map_coe f n
@[simp] lemma map_natCast {f : α → β} (n : ℕ) :
WithBot.map f (n : WithBot α) = f n := map_coe f n
lemma map_eq_ofNat_iff {f : β → α} {n : ℕ} [n.AtLeastTwo] {a : WithBot β} :
a.map f = ofNat(n) ↔ ∃ x, a = .some x ∧ f x = n := map_eq_some_iff
lemma ofNat_eq_map_iff {f : β → α} {n : ℕ} [n.AtLeastTwo] {a : WithBot β} :
ofNat(n) = a.map f ↔ ∃ x, a = .some x ∧ f x = n := some_eq_map_iff
lemma map_eq_natCast_iff {f : β → α} {n : ℕ} {a : WithBot β} :
a.map f = n ↔ ∃ x, a = .some x ∧ f x = n := map_eq_some_iff
lemma natCast_eq_map_iff {f : β → α} {n : ℕ} {a : WithBot β} :
n = a.map f ↔ ∃ x, a = .some x ∧ f x = n := some_eq_map_iff
end AddMonoidWithOne
instance charZero [AddMonoidWithOne α] [CharZero α] : CharZero (WithBot α) :=
WithTop.charZero
instance addCommMonoidWithOne [AddCommMonoidWithOne α] : AddCommMonoidWithOne (WithBot α) :=
WithTop.addCommMonoidWithOne
/-- A version of `WithBot.map` for `OneHom`s. -/
@[to_additive (attr := simps -fullyApplied)
/-- A version of `WithBot.map` for `ZeroHom`s -/]
protected def _root_.OneHom.withBotMap {M N : Type*} [One M] [One N] (f : OneHom M N) :
OneHom (WithBot M) (WithBot N) where
toFun := WithBot.map f
map_one' := by rw [WithBot.map_one, map_one, coe_one]
/-- A version of `WithBot.map` for `AddHom`s. -/
@[simps -fullyApplied]
protected def _root_.AddHom.withBotMap {M N : Type*} [Add M] [Add N] (f : AddHom M N) :
AddHom (WithBot M) (WithBot N) where
toFun := WithBot.map f
map_add' := WithBot.map_add f
/-- A version of `WithBot.map` for `AddMonoidHom`s. -/
@[simps -fullyApplied]
protected def _root_.AddMonoidHom.withBotMap {M N : Type*} [AddZeroClass M] [AddZeroClass N]
(f : M →+ N) : WithBot M →+ WithBot N :=
{ ZeroHom.withBotMap f.toZeroHom, AddHom.withBotMap f.toAddHom with toFun := WithBot.map f }
-- instance orderedAddCommMonoid [OrderedAddCommMonoid α] : OrderedAddCommMonoid (WithBot α) :=
-- { WithBot.partialOrder, WithBot.addCommMonoid with
-- add_le_add_left := fun _ _ h c => add_le_add_left h c }
--
-- instance linearOrderedAddCommMonoid [LinearOrderedAddCommMonoid α] :
-- LinearOrderedAddCommMonoid (WithBot α) :=
-- { WithBot.linearOrder, WithBot.orderedAddCommMonoid with }
end WithBot |
.lake/packages/mathlib/Mathlib/Algebra/Order/Monoid/Unbundled/Pow.lean | import Mathlib.Algebra.Order.Monoid.Unbundled.Basic
import Mathlib.Algebra.Order.Monoid.Unbundled.OrderDual
import Mathlib.Tactic.Lift
import Mathlib.Tactic.Monotonicity.Attr
/-!
# Lemmas about the interaction of power operations with order in terms of `CovariantClass`
-/
open Function
variable {β G M : Type*}
section Monoid
variable [Monoid M]
section Preorder
variable [Preorder M]
namespace Left
variable [MulLeftMono M] {a : M}
@[to_additive Left.nsmul_nonneg]
theorem one_le_pow_of_le (ha : 1 ≤ a) : ∀ n : ℕ, 1 ≤ a ^ n
| 0 => by simp
| k + 1 => by
rw [pow_succ]
exact one_le_mul (one_le_pow_of_le ha k) ha
@[to_additive nsmul_nonpos]
theorem pow_le_one_of_le (ha : a ≤ 1) (n : ℕ) : a ^ n ≤ 1 := one_le_pow_of_le (M := Mᵒᵈ) ha n
@[to_additive nsmul_neg]
theorem pow_lt_one_of_lt {a : M} {n : ℕ} (h : a < 1) (hn : n ≠ 0) : a ^ n < 1 := by
rcases Nat.exists_eq_succ_of_ne_zero hn with ⟨k, rfl⟩
rw [pow_succ']
exact mul_lt_one_of_lt_of_le h (pow_le_one_of_le h.le _)
end Left
@[to_additive nsmul_nonneg] alias one_le_pow_of_one_le' := Left.one_le_pow_of_le
@[to_additive nsmul_nonpos] alias pow_le_one' := Left.pow_le_one_of_le
@[to_additive nsmul_neg] alias pow_lt_one' := Left.pow_lt_one_of_lt
section Left
variable [MulLeftMono M] {a : M} {n : ℕ}
@[to_additive nsmul_left_monotone]
theorem pow_right_monotone (ha : 1 ≤ a) : Monotone fun n : ℕ ↦ a ^ n :=
monotone_nat_of_le_succ fun n ↦ by rw [pow_succ]; exact le_mul_of_one_le_right' ha
@[to_additive (attr := gcongr) nsmul_le_nsmul_left]
theorem pow_le_pow_right' {n m : ℕ} (ha : 1 ≤ a) (h : n ≤ m) : a ^ n ≤ a ^ m :=
pow_right_monotone ha h
@[to_additive nsmul_le_nsmul_left_of_nonpos]
theorem pow_le_pow_right_of_le_one' {n m : ℕ} (ha : a ≤ 1) (h : n ≤ m) : a ^ m ≤ a ^ n :=
pow_le_pow_right' (M := Mᵒᵈ) ha h
@[to_additive nsmul_pos]
theorem one_lt_pow' (ha : 1 < a) {k : ℕ} (hk : k ≠ 0) : 1 < a ^ k :=
pow_lt_one' (M := Mᵒᵈ) ha hk
@[to_additive]
lemma le_self_pow (ha : 1 ≤ a) (hn : n ≠ 0) : a ≤ a ^ n := by
simpa using pow_le_pow_right' ha (Nat.one_le_iff_ne_zero.2 hn)
end Left
section LeftLt
variable [MulLeftStrictMono M] {a : M} {n m : ℕ}
@[to_additive nsmul_left_strictMono]
theorem pow_right_strictMono' (ha : 1 < a) : StrictMono ((a ^ ·) : ℕ → M) :=
strictMono_nat_of_lt_succ fun n ↦ by rw [pow_succ]; exact lt_mul_of_one_lt_right' (a ^ n) ha
@[to_additive (attr := gcongr) nsmul_lt_nsmul_left]
theorem pow_lt_pow_right' (ha : 1 < a) (h : n < m) : a ^ n < a ^ m :=
pow_right_strictMono' ha h
end LeftLt
section Right
variable [MulRightMono M] {x : M}
@[to_additive Right.nsmul_nonneg]
theorem Right.one_le_pow_of_le (hx : 1 ≤ x) : ∀ {n : ℕ}, 1 ≤ x ^ n
| 0 => (pow_zero _).ge
| n + 1 => by
rw [pow_succ]
exact Right.one_le_mul (Right.one_le_pow_of_le hx) hx
@[to_additive Right.nsmul_nonpos]
theorem Right.pow_le_one_of_le (hx : x ≤ 1) {n : ℕ} : x ^ n ≤ 1 :=
Right.one_le_pow_of_le (M := Mᵒᵈ) hx
@[to_additive Right.nsmul_neg]
theorem Right.pow_lt_one_of_lt {n : ℕ} {x : M} (hn : 0 < n) (h : x < 1) : x ^ n < 1 := by
rcases Nat.exists_eq_succ_of_ne_zero hn.ne' with ⟨k, rfl⟩
rw [pow_succ]
exact mul_lt_one_of_le_of_lt (pow_le_one_of_le h.le) h
/-- This lemma is useful in non-cancellative monoids, like sets under pointwise operations. -/
@[to_additive
/-- This lemma is useful in non-cancellative monoids, like sets under pointwise operations. -/]
lemma pow_le_pow_mul_of_sq_le_mul [MulLeftMono M] {a b : M} (hab : a ^ 2 ≤ b * a) :
∀ {n}, n ≠ 0 → a ^ n ≤ b ^ (n - 1) * a
| 1, _ => by simp
| n + 2, _ => by
calc
a ^ (n + 2) = a ^ (n + 1) * a := by rw [pow_succ]
_ ≤ b ^ n * a * a := by grw [pow_le_pow_mul_of_sq_le_mul hab (by cutsat)]; simp
_ = b ^ n * a ^ 2 := by rw [mul_assoc, sq]
_ ≤ b ^ n * (b * a) := by grw [hab]
_ = b ^ (n + 1) * a := by rw [← mul_assoc, ← pow_succ]
end Right
section CovariantLTSwap
variable [Preorder β] [MulLeftStrictMono M] [MulRightStrictMono M] {f : β → M} {n : ℕ}
@[to_additive StrictMono.const_nsmul]
theorem StrictMono.pow_const (hf : StrictMono f) : ∀ {n : ℕ}, n ≠ 0 → StrictMono (f · ^ n)
| 0, hn => (hn rfl).elim
| 1, _ => by simpa
| Nat.succ <| Nat.succ n, _ => by
simpa only [pow_succ] using (hf.pow_const n.succ_ne_zero).mul' hf
/-- See also `pow_left_strictMonoOn₀`. -/
@[to_additive nsmul_right_strictMono]
theorem pow_left_strictMono (hn : n ≠ 0) : StrictMono (· ^ n : M → M) := strictMono_id.pow_const hn
@[to_additive (attr := mono, gcongr) nsmul_lt_nsmul_right]
lemma pow_lt_pow_left' (hn : n ≠ 0) {a b : M} (hab : a < b) : a ^ n < b ^ n :=
pow_left_strictMono hn hab
end CovariantLTSwap
section CovariantLESwap
variable [Preorder β] [MulLeftMono M] [MulRightMono M]
@[to_additive (attr := mono, gcongr) nsmul_le_nsmul_right]
theorem pow_le_pow_left' {a b : M} (hab : a ≤ b) : ∀ i : ℕ, a ^ i ≤ b ^ i
| 0 => by simp
| k + 1 => by
rw [pow_succ, pow_succ]
exact mul_le_mul' (pow_le_pow_left' hab k) hab
@[to_additive Monotone.const_nsmul]
theorem Monotone.pow_const {f : β → M} (hf : Monotone f) : ∀ n : ℕ, Monotone fun a => f a ^ n
| 0 => by simpa using monotone_const
| n + 1 => by
simp_rw [pow_succ]
exact (Monotone.pow_const hf _).mul' hf
@[to_additive nsmul_right_mono]
theorem pow_left_mono (n : ℕ) : Monotone fun a : M => a ^ n := monotone_id.pow_const _
@[to_additive (attr := gcongr)]
lemma pow_le_pow {a b : M} (hab : a ≤ b) (ht : 1 ≤ b) {m n : ℕ} (hmn : m ≤ n) : a ^ m ≤ b ^ n :=
(pow_le_pow_left' hab _).trans (pow_le_pow_right' ht hmn)
end CovariantLESwap
end Preorder
section SemilatticeSup
variable [SemilatticeSup M] [MulLeftMono M] [MulRightMono M] {a b : M} {n : ℕ}
lemma le_pow_sup : a ^ n ⊔ b ^ n ≤ (a ⊔ b) ^ n :=
sup_le (pow_le_pow_left' le_sup_left _) (pow_le_pow_left' le_sup_right _)
end SemilatticeSup
section SemilatticeInf
variable [SemilatticeInf M] [MulLeftMono M] [MulRightMono M] {a b : M} {n : ℕ}
lemma pow_inf_le : (a ⊓ b) ^ n ≤ a ^ n ⊓ b ^ n :=
le_inf (pow_le_pow_left' inf_le_left _) (pow_le_pow_left' inf_le_right _)
end SemilatticeInf
section LinearOrder
variable [LinearOrder M]
section CovariantLE
variable [MulLeftMono M]
-- This generalises to lattices. See `pow_two_semiclosed`
@[to_additive nsmul_nonneg_iff]
theorem one_le_pow_iff {x : M} {n : ℕ} (hn : n ≠ 0) : 1 ≤ x ^ n ↔ 1 ≤ x :=
⟨le_imp_le_of_lt_imp_lt fun h => pow_lt_one' h hn, fun h => one_le_pow_of_one_le' h n⟩
@[to_additive]
theorem pow_le_one_iff {x : M} {n : ℕ} (hn : n ≠ 0) : x ^ n ≤ 1 ↔ x ≤ 1 :=
one_le_pow_iff (M := Mᵒᵈ) hn
@[to_additive nsmul_pos_iff]
theorem one_lt_pow_iff {x : M} {n : ℕ} (hn : n ≠ 0) : 1 < x ^ n ↔ 1 < x :=
lt_iff_lt_of_le_iff_le (pow_le_one_iff hn)
@[to_additive]
theorem pow_lt_one_iff {x : M} {n : ℕ} (hn : n ≠ 0) : x ^ n < 1 ↔ x < 1 :=
lt_iff_lt_of_le_iff_le (one_le_pow_iff hn)
@[to_additive]
theorem pow_eq_one_iff {x : M} {n : ℕ} (hn : n ≠ 0) : x ^ n = 1 ↔ x = 1 := by
simp only [le_antisymm_iff]
rw [pow_le_one_iff hn, one_le_pow_iff hn]
end CovariantLE
section CovariantLT
variable [MulLeftStrictMono M] {a : M} {m n : ℕ}
@[to_additive nsmul_le_nsmul_iff_left]
theorem pow_le_pow_iff_right' (ha : 1 < a) : a ^ m ≤ a ^ n ↔ m ≤ n :=
(pow_right_strictMono' ha).le_iff_le
@[to_additive nsmul_lt_nsmul_iff_left]
theorem pow_lt_pow_iff_right' (ha : 1 < a) : a ^ m < a ^ n ↔ m < n :=
(pow_right_strictMono' ha).lt_iff_lt
end CovariantLT
section CovariantLESwap
variable [MulLeftMono M] [MulRightMono M]
@[to_additive lt_of_nsmul_lt_nsmul_right]
theorem lt_of_pow_lt_pow_left' {a b : M} (n : ℕ) : a ^ n < b ^ n → a < b :=
(pow_left_mono _).reflect_lt
@[to_additive min_lt_of_add_lt_two_nsmul]
theorem min_lt_of_mul_lt_sq {a b c : M} (h : a * b < c ^ 2) : min a b < c := by
simpa using min_lt_max_of_mul_lt_mul (h.trans_eq <| pow_two _)
@[to_additive lt_max_of_two_nsmul_lt_add]
theorem lt_max_of_sq_lt_mul {a b c : M} (h : a ^ 2 < b * c) : a < max b c := by
simpa using min_lt_max_of_mul_lt_mul ((pow_two _).symm.trans_lt h)
end CovariantLESwap
section CovariantLTSwap
variable [MulLeftStrictMono M] [MulRightStrictMono M]
@[to_additive nsmul_le_nsmul_iff_right]
theorem pow_le_pow_iff_left {a b : M} {n : ℕ} (hn : n ≠ 0) : a ^ n ≤ b ^ n ↔ a ≤ b :=
(pow_left_strictMono hn).le_iff_le
@[to_additive le_of_nsmul_le_nsmul_right]
alias ⟨le_of_pow_le_pow_left', _⟩ := pow_le_pow_iff_left
@[to_additive min_le_of_add_le_two_nsmul]
theorem min_le_of_mul_le_sq {a b c : M} (h : a * b ≤ c ^ 2) : min a b ≤ c := by
simpa using min_le_max_of_mul_le_mul (h.trans_eq <| pow_two _)
@[to_additive le_max_of_two_nsmul_le_add]
theorem le_max_of_sq_le_mul {a b c : M} (h : a ^ 2 ≤ b * c) : a ≤ max b c := by
simpa using min_le_max_of_mul_le_mul ((pow_two _).symm.trans_le h)
end CovariantLTSwap
@[to_additive Left.nsmul_neg_iff]
theorem Left.pow_lt_one_iff' [MulLeftStrictMono M] {n : ℕ} {x : M} (hn : 0 < n) :
x ^ n < 1 ↔ x < 1 :=
haveI := mulLeftMono_of_mulLeftStrictMono M
pow_lt_one_iff hn.ne'
theorem Left.pow_lt_one_iff [MulLeftStrictMono M] {n : ℕ} {x : M} (hn : 0 < n) :
x ^ n < 1 ↔ x < 1 := Left.pow_lt_one_iff' hn
@[to_additive]
theorem Right.pow_lt_one_iff [MulRightStrictMono M] {n : ℕ} {x : M}
(hn : 0 < n) : x ^ n < 1 ↔ x < 1 :=
haveI := mulRightMono_of_mulRightStrictMono M
⟨fun H => not_le.mp fun k => H.not_ge <| Right.one_le_pow_of_le k, Right.pow_lt_one_of_lt hn⟩
@[to_additive]
instance [MulLeftStrictMono M] [MulRightStrictMono M] : IsMulTorsionFree M where
pow_left_injective _ hn := (pow_left_strictMono hn).injective
end LinearOrder
end Monoid
section DivInvMonoid
variable [DivInvMonoid G] [Preorder G] [MulLeftMono G]
@[to_additive zsmul_nonneg]
theorem one_le_zpow {x : G} (H : 1 ≤ x) {n : ℤ} (hn : 0 ≤ n) : 1 ≤ x ^ n := by
lift n to ℕ using hn
rw [zpow_natCast]
apply one_le_pow_of_one_le' H
@[to_additive zsmul_pos]
lemma one_lt_zpow {x : G} (hx : 1 < x) {n : ℤ} (hn : 0 < n) : 1 < x ^ n := by
lift n to ℕ using Int.le_of_lt hn
rw [zpow_natCast]
exact one_lt_pow' hx (Int.natCast_pos.mp hn).ne'
end DivInvMonoid |
.lake/packages/mathlib/Mathlib/Algebra/Order/Monoid/Unbundled/OrderDual.lean | import Mathlib.Algebra.Order.Group.Synonym
import Mathlib.Algebra.Order.Monoid.Unbundled.Defs
/-! # Unbundled ordered monoid structures on the order dual. -/
universe u
variable {α : Type u}
open Function
namespace OrderDual
@[to_additive]
instance mulLeftReflectLE [LE α] [Mul α] [c : MulLeftReflectLE α] : MulLeftReflectLE αᵒᵈ :=
⟨c.1.flip⟩
@[to_additive]
instance mulLeftMono [LE α] [Mul α] [c : MulLeftMono α] : MulLeftMono αᵒᵈ :=
⟨c.1.flip⟩
@[to_additive]
instance mulRightReflectLE [LE α] [Mul α] [c : MulRightReflectLE α] : MulRightReflectLE αᵒᵈ :=
⟨c.1.flip⟩
@[to_additive]
instance mulRightMono [LE α] [Mul α] [c : MulRightMono α] : MulRightMono αᵒᵈ :=
⟨c.1.flip⟩
@[to_additive]
instance mulLeftReflectLT [LT α] [Mul α] [c : MulLeftReflectLT α] : MulLeftReflectLT αᵒᵈ :=
⟨c.1.flip⟩
@[to_additive]
instance mulLeftStrictMono [LT α] [Mul α] [c : MulLeftStrictMono α] : MulLeftStrictMono αᵒᵈ :=
⟨c.1.flip⟩
@[to_additive]
instance mulRightReflectLT [LT α] [Mul α] [c : MulRightReflectLT α] : MulRightReflectLT αᵒᵈ :=
⟨c.1.flip⟩
@[to_additive]
instance mulRightStrictMono [LT α] [Mul α] [c : MulRightStrictMono α] : MulRightStrictMono αᵒᵈ :=
⟨c.1.flip⟩
end OrderDual |
.lake/packages/mathlib/Mathlib/Algebra/Order/Monoid/Unbundled/MinMax.lean | import Mathlib.Algebra.Order.Monoid.Unbundled.Basic
/-!
# Lemmas about `min` and `max` in an ordered monoid.
-/
open Function
variable {α β : Type*}
/-! Some lemmas about types that have an ordering and a binary operation, with no
rules relating them. -/
section CommSemigroup
variable [LinearOrder α] [CommSemigroup β]
@[to_additive]
lemma fn_min_mul_fn_max (f : α → β) (a b : α) : f (min a b) * f (max a b) = f a * f b := by
grind
@[to_additive]
lemma fn_max_mul_fn_min (f : α → β) (a b : α) : f (max a b) * f (min a b) = f a * f b := by
grind
variable [CommSemigroup α]
@[to_additive (attr := simp)]
lemma min_mul_max (a b : α) : min a b * max a b = a * b := fn_min_mul_fn_max id _ _
@[to_additive (attr := simp)]
lemma max_mul_min (a b : α) : max a b * min a b = a * b := fn_max_mul_fn_min id _ _
end CommSemigroup
section CovariantClassMulLe
variable [LinearOrder α]
section Mul
variable [Mul α]
section Left
variable [MulLeftMono α]
@[to_additive]
theorem min_mul_mul_left (a b c : α) : min (a * b) (a * c) = a * min b c :=
(monotone_id.const_mul' a).map_min.symm
@[to_additive]
theorem max_mul_mul_left (a b c : α) : max (a * b) (a * c) = a * max b c :=
(monotone_id.const_mul' a).map_max.symm
end Left
section Right
variable [MulRightMono α]
@[to_additive]
theorem min_mul_mul_right (a b c : α) : min (a * c) (b * c) = min a b * c :=
(monotone_id.mul_const' c).map_min.symm
@[to_additive]
theorem max_mul_mul_right (a b c : α) : max (a * c) (b * c) = max a b * c :=
(monotone_id.mul_const' c).map_max.symm
end Right
@[to_additive]
theorem lt_or_lt_of_mul_lt_mul [MulLeftMono α] [MulRightMono α] {a₁ a₂ b₁ b₂ : α} :
a₁ * b₁ < a₂ * b₂ → a₁ < a₂ ∨ b₁ < b₂ := by
contrapose!
exact fun h => mul_le_mul' h.1 h.2
@[to_additive]
theorem le_or_lt_of_mul_le_mul [MulLeftMono α] [MulRightStrictMono α] {a₁ a₂ b₁ b₂ : α} :
a₁ * b₁ ≤ a₂ * b₂ → a₁ ≤ a₂ ∨ b₁ < b₂ := by
contrapose!
exact fun h => mul_lt_mul_of_lt_of_le h.1 h.2
@[to_additive]
theorem lt_or_le_of_mul_le_mul [MulLeftStrictMono α] [MulRightMono α] {a₁ a₂ b₁ b₂ : α} :
a₁ * b₁ ≤ a₂ * b₂ → a₁ < a₂ ∨ b₁ ≤ b₂ := by
contrapose!
exact fun h => mul_lt_mul_of_le_of_lt h.1 h.2
@[to_additive]
theorem le_or_le_of_mul_le_mul [MulLeftStrictMono α] [MulRightStrictMono α] {a₁ a₂ b₁ b₂ : α} :
a₁ * b₁ ≤ a₂ * b₂ → a₁ ≤ a₂ ∨ b₁ ≤ b₂ := by
contrapose!
exact fun h => mul_lt_mul_of_lt_of_lt h.1 h.2
@[to_additive]
theorem mul_lt_mul_iff_of_le_of_le [MulLeftMono α]
[MulRightMono α] [MulLeftStrictMono α]
[MulRightStrictMono α] {a₁ a₂ b₁ b₂ : α} (ha : a₁ ≤ a₂)
(hb : b₁ ≤ b₂) : a₁ * b₁ < a₂ * b₂ ↔ a₁ < a₂ ∨ b₁ < b₂ := by
refine ⟨lt_or_lt_of_mul_lt_mul, fun h => ?_⟩
rcases h with ha' | hb'
· exact mul_lt_mul_of_lt_of_le ha' hb
· exact mul_lt_mul_of_le_of_lt ha hb'
end Mul
variable [MulOneClass α]
@[to_additive]
theorem min_le_mul_of_one_le_right [MulLeftMono α] {a b : α} (hb : 1 ≤ b) :
min a b ≤ a * b :=
min_le_iff.2 <| Or.inl <| le_mul_of_one_le_right' hb
@[to_additive]
theorem min_le_mul_of_one_le_left [MulRightMono α] {a b : α} (ha : 1 ≤ a) :
min a b ≤ a * b :=
min_le_iff.2 <| Or.inr <| le_mul_of_one_le_left' ha
@[to_additive]
theorem max_le_mul_of_one_le [MulLeftMono α] [MulRightMono α] {a b : α} (ha : 1 ≤ a) (hb : 1 ≤ b) :
max a b ≤ a * b :=
max_le_iff.2 ⟨le_mul_of_one_le_right' hb, le_mul_of_one_le_left' ha⟩
end CovariantClassMulLe |
.lake/packages/mathlib/Mathlib/Algebra/Order/Monoid/Unbundled/Basic.lean | import Mathlib.Algebra.Order.Monoid.Unbundled.Defs
import Mathlib.Data.Ordering.Basic
import Mathlib.Order.MinMax
import Mathlib.Tactic.Contrapose
import Mathlib.Tactic.Use
/-!
# Ordered monoids
This file develops the basics of ordered monoids.
## 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.
## Remark
Almost no monoid is actually present in this file: most assumptions have been generalized to
`Mul` or `MulOneClass`.
-/
-- TODO: If possible, uniformize lemma names, taking special care of `'`,
-- after the `ordered`-refactor is done.
open Function
section Nat
instance Nat.instMulLeftMono : MulLeftMono ℕ where
elim := fun _ _ _ h => mul_le_mul_left _ h
end Nat
section Int
instance Int.instAddLeftMono : AddLeftMono ℤ where
elim := fun _ _ _ h => Int.add_le_add_left h _
end Int
variable {α β : Type*}
section Mul
variable [Mul α]
section LE
variable [LE α]
-- Note: in this section, we use `@[gcongr high]` so that these lemmas have a higher priority than
-- lemmas like `mul_le_mul_of_nonneg_left`, which have an extra side condition.
/- The prime on this lemma is present only on the multiplicative version. The unprimed version
is taken by the analogous lemma for semiring, with an extra non-negativity assumption. -/
@[to_additive (attr := gcongr high) add_le_add_left]
theorem mul_le_mul_left' [MulLeftMono α] {b c : α} (bc : b ≤ c) (a : α) :
a * b ≤ a * c :=
CovariantClass.elim _ bc
@[to_additive le_of_add_le_add_left]
theorem le_of_mul_le_mul_left' [MulLeftReflectLE α] {a b c : α}
(bc : a * b ≤ a * c) :
b ≤ c :=
ContravariantClass.elim _ bc
/- The prime on this lemma is present only on the multiplicative version. The unprimed version
is taken by the analogous lemma for semiring, with an extra non-negativity assumption. -/
@[to_additive (attr := gcongr high) add_le_add_right]
theorem mul_le_mul_right' [i : MulRightMono α] {b c : α} (bc : b ≤ c)
(a : α) :
b * a ≤ c * a :=
i.elim a bc
@[to_additive le_of_add_le_add_right]
theorem le_of_mul_le_mul_right' [i : MulRightReflectLE α] {a b c : α}
(bc : b * a ≤ c * a) :
b ≤ c :=
i.elim a bc
@[to_additive (attr := simp)]
theorem mul_le_mul_iff_left [MulLeftMono α]
[MulLeftReflectLE α] (a : α) {b c : α} :
a * b ≤ a * c ↔ b ≤ c :=
rel_iff_cov α α (· * ·) (· ≤ ·) a
@[to_additive (attr := simp)]
theorem mul_le_mul_iff_right [MulRightMono α]
[MulRightReflectLE α] (a : α) {b c : α} :
b * a ≤ c * a ↔ b ≤ c :=
rel_iff_cov α α (swap (· * ·)) (· ≤ ·) a
end LE
section LT
variable [LT α]
@[to_additive (attr := simp)]
theorem mul_lt_mul_iff_left [MulLeftStrictMono α]
[MulLeftReflectLT α] (a : α) {b c : α} :
a * b < a * c ↔ b < c :=
rel_iff_cov α α (· * ·) (· < ·) a
@[to_additive (attr := simp)]
theorem mul_lt_mul_iff_right [MulRightStrictMono α]
[MulRightReflectLT α] (a : α) {b c : α} :
b * a < c * a ↔ b < c :=
rel_iff_cov α α (swap (· * ·)) (· < ·) a
-- Note: in this section, we use `@[gcongr high]` so that these lemmas have a higher priority than
-- lemmas like `mul_lt_mul_of_pos_left`, which have an extra side condition.
@[to_additive (attr := gcongr high) add_lt_add_left]
theorem mul_lt_mul_left' [MulLeftStrictMono α] {b c : α} (bc : b < c) (a : α) :
a * b < a * c :=
CovariantClass.elim _ bc
@[to_additive lt_of_add_lt_add_left]
theorem lt_of_mul_lt_mul_left' [MulLeftReflectLT α] {a b c : α}
(bc : a * b < a * c) :
b < c :=
ContravariantClass.elim _ bc
@[to_additive (attr := gcongr high) add_lt_add_right]
theorem mul_lt_mul_right' [i : MulRightStrictMono α] {b c : α} (bc : b < c)
(a : α) :
b * a < c * a :=
i.elim a bc
@[to_additive lt_of_add_lt_add_right]
theorem lt_of_mul_lt_mul_right' [i : MulRightReflectLT α] {a b c : α}
(bc : b * a < c * a) :
b < c :=
i.elim a bc
end LT
section Preorder
variable [Preorder α]
@[to_additive]
lemma mul_right_mono [MulLeftMono α] {a : α} : Monotone (a * ·) :=
fun _ _ h ↦ mul_le_mul_left' h _
@[to_additive]
lemma mul_left_mono [MulRightMono α] {a : α} : Monotone (· * a) :=
fun _ _ h ↦ mul_le_mul_right' h _
@[to_additive]
lemma mul_right_strictMono [MulLeftStrictMono α] {a : α} : StrictMono (a * ·) :=
fun _ _ h ↦ mul_lt_mul_left' h _
@[to_additive]
lemma mul_left_strictMono [MulRightStrictMono α] {a : α} : StrictMono (· * a) :=
fun _ _ h ↦ mul_lt_mul_right' h _
-- Note: in this section, we use `@[gcongr high]` so that these lemmas have a higher priority than
-- lemmas like `mul_le_mul_of_nonneg`, which have an extra side condition.
@[to_additive (attr := gcongr high)]
theorem mul_lt_mul_of_lt_of_lt [MulLeftStrictMono α]
[MulRightStrictMono α]
{a b c d : α} (h₁ : a < b) (h₂ : c < d) : a * c < b * d :=
calc
a * c < a * d := mul_lt_mul_left' h₂ a
_ < b * d := mul_lt_mul_right' h₁ d
alias add_lt_add := add_lt_add_of_lt_of_lt
@[to_additive]
theorem mul_lt_mul_of_le_of_lt [MulLeftStrictMono α]
[MulRightMono α] {a b c d : α} (h₁ : a ≤ b) (h₂ : c < d) :
a * c < b * d :=
(mul_le_mul_right' h₁ _).trans_lt (mul_lt_mul_left' h₂ b)
@[to_additive]
theorem mul_lt_mul_of_lt_of_le [MulLeftMono α]
[MulRightStrictMono α] {a b c d : α} (h₁ : a < b) (h₂ : c ≤ d) :
a * c < b * d :=
(mul_le_mul_left' h₂ _).trans_lt (mul_lt_mul_right' h₁ d)
/-- Only assumes left strict covariance. -/
@[to_additive /-- Only assumes left strict covariance -/]
theorem Left.mul_lt_mul [MulLeftStrictMono α]
[MulRightMono α] {a b c d : α} (h₁ : a < b) (h₂ : c < d) :
a * c < b * d :=
mul_lt_mul_of_le_of_lt h₁.le h₂
/-- Only assumes right strict covariance. -/
@[to_additive /-- Only assumes right strict covariance -/]
theorem Right.mul_lt_mul [MulLeftMono α]
[MulRightStrictMono α] {a b c d : α}
(h₁ : a < b) (h₂ : c < d) :
a * c < b * d :=
mul_lt_mul_of_lt_of_le h₁ h₂.le
@[to_additive (attr := gcongr high) add_le_add]
theorem mul_le_mul' [MulLeftMono α] [MulRightMono α]
{a b c d : α} (h₁ : a ≤ b) (h₂ : c ≤ d) :
a * c ≤ b * d := by grw [h₁, h₂]
@[to_additive]
theorem mul_le_mul_three [MulLeftMono α]
[MulRightMono α] {a b c d e f : α} (h₁ : a ≤ d) (h₂ : b ≤ e)
(h₃ : c ≤ f) :
a * b * c ≤ d * e * f :=
mul_le_mul' (mul_le_mul' h₁ h₂) h₃
@[to_additive]
theorem mul_lt_of_mul_lt_left [MulLeftMono α] {a b c d : α} (h : a * b < c)
(hle : d ≤ b) :
a * d < c :=
(mul_le_mul_left' hle a).trans_lt h
@[to_additive]
theorem mul_le_of_mul_le_left [MulLeftMono α] {a b c d : α} (h : a * b ≤ c)
(hle : d ≤ b) :
a * d ≤ c :=
@act_rel_of_rel_of_act_rel _ _ _ (· ≤ ·) _ _ a _ _ _ hle h
@[to_additive]
theorem mul_lt_of_mul_lt_right [MulRightMono α] {a b c d : α}
(h : a * b < c) (hle : d ≤ a) :
d * b < c :=
(mul_le_mul_right' hle b).trans_lt h
@[to_additive]
theorem mul_le_of_mul_le_right [MulRightMono α] {a b c d : α}
(h : a * b ≤ c) (hle : d ≤ a) :
d * b ≤ c :=
(mul_le_mul_right' hle b).trans h
@[to_additive]
theorem lt_mul_of_lt_mul_left [MulLeftMono α] {a b c d : α} (h : a < b * c)
(hle : c ≤ d) :
a < b * d :=
h.trans_le (mul_le_mul_left' hle b)
@[to_additive]
theorem le_mul_of_le_mul_left [MulLeftMono α] {a b c d : α} (h : a ≤ b * c)
(hle : c ≤ d) :
a ≤ b * d :=
@rel_act_of_rel_of_rel_act _ _ _ (· ≤ ·) _ _ b _ _ _ hle h
@[to_additive]
theorem lt_mul_of_lt_mul_right [MulRightMono α] {a b c d : α}
(h : a < b * c) (hle : b ≤ d) :
a < d * c :=
h.trans_le (mul_le_mul_right' hle c)
@[to_additive]
theorem le_mul_of_le_mul_right [MulRightMono α] {a b c d : α}
(h : a ≤ b * c) (hle : b ≤ d) :
a ≤ d * c :=
h.trans (mul_le_mul_right' hle c)
end Preorder
section PartialOrder
variable [PartialOrder α]
@[to_additive]
theorem mul_left_cancel'' [MulLeftReflectLE α] {a b c : α} (h : a * b = a * c) :
b = c :=
(le_of_mul_le_mul_left' h.le).antisymm (le_of_mul_le_mul_left' h.ge)
@[to_additive]
theorem mul_right_cancel'' [MulRightReflectLE α] {a b c : α}
(h : a * b = c * b) :
a = c :=
(le_of_mul_le_mul_right' h.le).antisymm (le_of_mul_le_mul_right' h.ge)
@[to_additive] lemma mul_le_mul_iff_of_ge [MulLeftStrictMono α]
[MulRightStrictMono α] {a₁ a₂ b₁ b₂ : α} (ha : a₁ ≤ a₂) (hb : b₁ ≤ b₂) :
a₂ * b₂ ≤ a₁ * b₁ ↔ a₁ = a₂ ∧ b₁ = b₂ := by
haveI := mulLeftMono_of_mulLeftStrictMono α
haveI := mulRightMono_of_mulRightStrictMono α
refine ⟨fun h ↦ ?_, by rintro ⟨rfl, rfl⟩; rfl⟩
simp only [eq_iff_le_not_lt, ha, hb, true_and]
refine ⟨fun ha ↦ h.not_gt ?_, fun hb ↦ h.not_gt ?_⟩
exacts [mul_lt_mul_of_lt_of_le ha hb, mul_lt_mul_of_le_of_lt ha hb]
@[to_additive] theorem mul_eq_mul_iff_eq_and_eq [MulLeftStrictMono α]
[MulRightStrictMono α] {a b c d : α} (hac : a ≤ c) (hbd : b ≤ d) :
a * b = c * d ↔ a = c ∧ b = d := by
haveI := mulLeftMono_of_mulLeftStrictMono α
haveI := mulRightMono_of_mulRightStrictMono α
rw [le_antisymm_iff, eq_true (mul_le_mul' hac hbd), true_and, mul_le_mul_iff_of_ge hac hbd]
@[to_additive]
lemma mul_left_inj_of_comparable [MulRightStrictMono α] {a b c : α} (h : b ≤ c ∨ c ≤ b) :
c * a = b * a ↔ c = b := by
refine ⟨fun h' => ?_, (· ▸ rfl)⟩
contrapose h'
obtain h | h := h
· exact mul_lt_mul_right' (h.lt_of_ne' h') a |>.ne'
· exact mul_lt_mul_right' (h.lt_of_ne h') a |>.ne
@[to_additive]
lemma mul_right_inj_of_comparable [MulLeftStrictMono α] {a b c : α} (h : b ≤ c ∨ c ≤ b) :
a * c = a * b ↔ c = b := by
refine ⟨fun h' => ?_, (· ▸ rfl)⟩
contrapose h'
obtain h | h := h
· exact mul_lt_mul_left' (h.lt_of_ne' h') a |>.ne'
· exact mul_lt_mul_left' (h.lt_of_ne h') a |>.ne
end PartialOrder
section LinearOrder
variable [LinearOrder α] {a b c d : α}
@[to_additive]
theorem trichotomy_of_mul_eq_mul
[MulLeftStrictMono α] [MulRightStrictMono α]
(h : a * b = c * d) : (a = c ∧ b = d) ∨ a < c ∨ b < d := by
obtain hac | rfl | hca := lt_trichotomy a c
· grind
· left; simpa using mul_right_inj_of_comparable (LinearOrder.le_total d b) |>.1 h
· obtain hbd | rfl | hdb := lt_trichotomy b d
· grind
· exact False.elim <| ne_of_lt (mul_lt_mul_right' hca b) h.symm
· exact False.elim <| ne_of_lt (mul_lt_mul_of_lt_of_lt hca hdb) h.symm
@[to_additive]
lemma mul_max [MulLeftMono α] (a b c : α) :
a * max b c = max (a * b) (a * c) := mul_right_mono.map_max
@[to_additive]
lemma max_mul [MulRightMono α] (a b c : α) :
max a b * c = max (a * c) (b * c) := mul_left_mono.map_max
@[to_additive]
lemma mul_min [MulLeftMono α] (a b c : α) :
a * min b c = min (a * b) (a * c) := mul_right_mono.map_min
@[to_additive]
lemma min_mul [MulRightMono α] (a b c : α) :
min a b * c = min (a * c) (b * c) := mul_left_mono.map_min
@[to_additive] lemma min_lt_max_of_mul_lt_mul
[MulLeftMono α] [MulRightMono α]
(h : a * b < c * d) : min a b < max c d := by
simp_rw [min_lt_iff, lt_max_iff]; contrapose! h; exact mul_le_mul' h.1.1 h.2.2
@[to_additive] lemma Left.min_le_max_of_mul_le_mul
[MulLeftStrictMono α] [MulRightMono α]
(h : a * b ≤ c * d) : min a b ≤ max c d := by
simp_rw [min_le_iff, le_max_iff]; contrapose! h; exact mul_lt_mul_of_le_of_lt h.1.1.le h.2.2
@[to_additive] lemma Right.min_le_max_of_mul_le_mul
[MulLeftMono α] [MulRightStrictMono α]
(h : a * b ≤ c * d) : min a b ≤ max c d := by
simp_rw [min_le_iff, le_max_iff]; contrapose! h; exact mul_lt_mul_of_lt_of_le h.1.1 h.2.2.le
@[to_additive] lemma min_le_max_of_mul_le_mul
[MulLeftStrictMono α] [MulRightStrictMono α]
(h : a * b ≤ c * d) : min a b ≤ max c d :=
haveI := mulRightMono_of_mulRightStrictMono α
Left.min_le_max_of_mul_le_mul h
/-- Not an instance, to avoid loops with `IsLeftCancelMul.mulLeftStrictMono_of_mulLeftMono`. -/
@[to_additive]
theorem MulLeftStrictMono.toIsLeftCancelMul [MulLeftStrictMono α] : IsLeftCancelMul α where
mul_left_cancel _ _ _ h := mul_right_strictMono.injective h
/-- Not an instance, to avoid loops with `IsRightCancelMul.mulRightStrictMono_of_mulRightMono`. -/
@[to_additive]
theorem MulRightStrictMono.toIsRightCancelMul [MulRightStrictMono α] : IsRightCancelMul α where
mul_right_cancel _ _ _ h := mul_left_strictMono.injective h
end LinearOrder
section LinearOrder
variable [LinearOrder α] [MulLeftMono α] [MulRightMono α] {a b c d : α}
@[to_additive max_add_add_le_max_add_max]
theorem max_mul_mul_le_max_mul_max' : max (a * b) (c * d) ≤ max a c * max b d :=
max_le (mul_le_mul' (le_max_left _ _) <| le_max_left _ _) <|
mul_le_mul' (le_max_right _ _) <| le_max_right _ _
@[to_additive min_add_min_le_min_add_add]
theorem min_mul_min_le_min_mul_mul' : min a c * min b d ≤ min (a * b) (c * d) :=
le_min (mul_le_mul' (min_le_left _ _) <| min_le_left _ _) <|
mul_le_mul' (min_le_right _ _) <| min_le_right _ _
end LinearOrder
end Mul
-- using one
section MulOneClass
variable [MulOneClass α]
section LE
variable [LE α]
@[to_additive le_add_of_nonneg_right]
theorem le_mul_of_one_le_right' [MulLeftMono α] {a b : α} (h : 1 ≤ b) :
a ≤ a * b :=
calc
a = a * 1 := (mul_one a).symm
_ ≤ a * b := mul_le_mul_left' h a
@[to_additive add_le_of_nonpos_right]
theorem mul_le_of_le_one_right' [MulLeftMono α] {a b : α} (h : b ≤ 1) :
a * b ≤ a :=
calc
a * b ≤ a * 1 := mul_le_mul_left' h a
_ = a := mul_one a
@[to_additive le_add_of_nonneg_left]
theorem le_mul_of_one_le_left' [MulRightMono α] {a b : α} (h : 1 ≤ b) :
a ≤ b * a :=
calc
a = 1 * a := (one_mul a).symm
_ ≤ b * a := mul_le_mul_right' h a
@[to_additive add_le_of_nonpos_left]
theorem mul_le_of_le_one_left' [MulRightMono α] {a b : α} (h : b ≤ 1) :
b * a ≤ a :=
calc
b * a ≤ 1 * a := mul_le_mul_right' h a
_ = a := one_mul a
@[to_additive]
theorem one_le_of_le_mul_right [MulLeftReflectLE α] {a b : α} (h : a ≤ a * b) :
1 ≤ b :=
le_of_mul_le_mul_left' (a := a) <| by simpa only [mul_one]
@[to_additive]
theorem le_one_of_mul_le_right [MulLeftReflectLE α] {a b : α} (h : a * b ≤ a) :
b ≤ 1 :=
le_of_mul_le_mul_left' (a := a) <| by simpa only [mul_one]
@[to_additive]
theorem one_le_of_le_mul_left [MulRightReflectLE α] {a b : α}
(h : b ≤ a * b) :
1 ≤ a :=
le_of_mul_le_mul_right' (a := b) <| by simpa only [one_mul]
@[to_additive]
theorem le_one_of_mul_le_left [MulRightReflectLE α] {a b : α}
(h : a * b ≤ b) :
a ≤ 1 :=
le_of_mul_le_mul_right' (a := b) <| by simpa only [one_mul]
@[to_additive (attr := simp) le_add_iff_nonneg_right]
theorem le_mul_iff_one_le_right' [MulLeftMono α]
[MulLeftReflectLE α] (a : α) {b : α} :
a ≤ a * b ↔ 1 ≤ b :=
Iff.trans (by rw [mul_one]) (mul_le_mul_iff_left a)
@[to_additive (attr := simp) le_add_iff_nonneg_left]
theorem le_mul_iff_one_le_left' [MulRightMono α]
[MulRightReflectLE α] (a : α) {b : α} :
a ≤ b * a ↔ 1 ≤ b :=
Iff.trans (by rw [one_mul]) (mul_le_mul_iff_right a)
@[to_additive (attr := simp) add_le_iff_nonpos_right]
theorem mul_le_iff_le_one_right' [MulLeftMono α]
[MulLeftReflectLE α] (a : α) {b : α} :
a * b ≤ a ↔ b ≤ 1 :=
Iff.trans (by rw [mul_one]) (mul_le_mul_iff_left a)
@[to_additive (attr := simp) add_le_iff_nonpos_left]
theorem mul_le_iff_le_one_left' [MulRightMono α]
[MulRightReflectLE α] {a b : α} :
a * b ≤ b ↔ a ≤ 1 :=
Iff.trans (by rw [one_mul]) (mul_le_mul_iff_right b)
end LE
section LT
variable [LT α]
@[to_additive lt_add_of_pos_right]
theorem lt_mul_of_one_lt_right' [MulLeftStrictMono α] (a : α) {b : α} (h : 1 < b) :
a < a * b :=
calc
a = a * 1 := (mul_one a).symm
_ < a * b := mul_lt_mul_left' h a
@[to_additive add_lt_of_neg_right]
theorem mul_lt_of_lt_one_right' [MulLeftStrictMono α] (a : α) {b : α} (h : b < 1) :
a * b < a :=
calc
a * b < a * 1 := mul_lt_mul_left' h a
_ = a := mul_one a
@[to_additive lt_add_of_pos_left]
theorem lt_mul_of_one_lt_left' [MulRightStrictMono α] (a : α) {b : α}
(h : 1 < b) :
a < b * a :=
calc
a = 1 * a := (one_mul a).symm
_ < b * a := mul_lt_mul_right' h a
@[to_additive add_lt_of_neg_left]
theorem mul_lt_of_lt_one_left' [MulRightStrictMono α] (a : α) {b : α}
(h : b < 1) :
b * a < a :=
calc
b * a < 1 * a := mul_lt_mul_right' h a
_ = a := one_mul a
@[to_additive]
theorem one_lt_of_lt_mul_right [MulLeftReflectLT α] {a b : α} (h : a < a * b) :
1 < b :=
lt_of_mul_lt_mul_left' (a := a) <| by simpa only [mul_one]
@[to_additive]
theorem lt_one_of_mul_lt_right [MulLeftReflectLT α] {a b : α} (h : a * b < a) :
b < 1 :=
lt_of_mul_lt_mul_left' (a := a) <| by simpa only [mul_one]
@[to_additive]
theorem one_lt_of_lt_mul_left [MulRightReflectLT α] {a b : α}
(h : b < a * b) :
1 < a :=
lt_of_mul_lt_mul_right' (a := b) <| by simpa only [one_mul]
@[to_additive]
theorem lt_one_of_mul_lt_left [MulRightReflectLT α] {a b : α}
(h : a * b < b) :
a < 1 :=
lt_of_mul_lt_mul_right' (a := b) <| by simpa only [one_mul]
@[to_additive (attr := simp) lt_add_iff_pos_right]
theorem lt_mul_iff_one_lt_right' [MulLeftStrictMono α]
[MulLeftReflectLT α] (a : α) {b : α} :
a < a * b ↔ 1 < b :=
Iff.trans (by rw [mul_one]) (mul_lt_mul_iff_left a)
@[to_additive (attr := simp) lt_add_iff_pos_left]
theorem lt_mul_iff_one_lt_left' [MulRightStrictMono α]
[MulRightReflectLT α] (a : α) {b : α} : a < b * a ↔ 1 < b :=
Iff.trans (by rw [one_mul]) (mul_lt_mul_iff_right a)
@[to_additive (attr := simp) add_lt_iff_neg_left]
theorem mul_lt_iff_lt_one_left' [MulLeftStrictMono α]
[MulLeftReflectLT α] {a b : α} :
a * b < a ↔ b < 1 :=
Iff.trans (by rw [mul_one]) (mul_lt_mul_iff_left a)
@[to_additive (attr := simp) add_lt_iff_neg_right]
theorem mul_lt_iff_lt_one_right' [MulRightStrictMono α]
[MulRightReflectLT α] {a : α} (b : α) : a * b < b ↔ a < 1 :=
Iff.trans (by rw [one_mul]) (mul_lt_mul_iff_right b)
end LT
section Preorder
variable [Preorder α]
/-! Lemmas of the form `b ≤ c → a ≤ 1 → b * a ≤ c`,
which assume left covariance. -/
@[to_additive]
theorem mul_le_of_le_of_le_one [MulLeftMono α] {a b c : α} (hbc : b ≤ c)
(ha : a ≤ 1) :
b * a ≤ c :=
calc
b * a ≤ b * 1 := mul_le_mul_left' ha b
_ = b := mul_one b
_ ≤ c := hbc
@[to_additive]
theorem mul_lt_of_le_of_lt_one [MulLeftStrictMono α] {a b c : α} (hbc : b ≤ c)
(ha : a < 1) :
b * a < c :=
calc
b * a < b * 1 := mul_lt_mul_left' ha b
_ = b := mul_one b
_ ≤ c := hbc
@[to_additive]
theorem mul_lt_of_lt_of_le_one [MulLeftMono α] {a b c : α} (hbc : b < c)
(ha : a ≤ 1) :
b * a < c :=
calc
b * a ≤ b * 1 := mul_le_mul_left' ha b
_ = b := mul_one b
_ < c := hbc
@[to_additive]
theorem mul_lt_of_lt_of_lt_one [MulLeftStrictMono α] {a b c : α} (hbc : b < c)
(ha : a < 1) :
b * a < c :=
calc
b * a < b * 1 := mul_lt_mul_left' ha b
_ = b := mul_one b
_ < c := hbc
@[to_additive]
theorem mul_lt_of_lt_of_lt_one' [MulLeftMono α] {a b c : α} (hbc : b < c)
(ha : a < 1) :
b * a < c :=
mul_lt_of_lt_of_le_one hbc ha.le
/-- Assumes left covariance.
The lemma assuming right covariance is `Right.mul_le_one`. -/
@[to_additive /-- Assumes left covariance.
The lemma assuming right covariance is `Right.add_nonpos`. -/]
theorem Left.mul_le_one [MulLeftMono α] {a b : α} (ha : a ≤ 1) (hb : b ≤ 1) :
a * b ≤ 1 :=
mul_le_of_le_of_le_one ha hb
/-- Assumes left covariance.
The lemma assuming right covariance is `Right.mul_lt_one_of_le_of_lt`. -/
@[to_additive Left.add_neg_of_nonpos_of_neg
/-- Assumes left covariance.
The lemma assuming right covariance is `Right.add_neg_of_nonpos_of_neg`. -/]
theorem Left.mul_lt_one_of_le_of_lt [MulLeftStrictMono α] {a b : α} (ha : a ≤ 1)
(hb : b < 1) :
a * b < 1 :=
mul_lt_of_le_of_lt_one ha hb
/-- Assumes left covariance.
The lemma assuming right covariance is `Right.mul_lt_one_of_lt_of_le`. -/
@[to_additive Left.add_neg_of_neg_of_nonpos
/-- Assumes left covariance.
The lemma assuming right covariance is `Right.add_neg_of_neg_of_nonpos`. -/]
theorem Left.mul_lt_one_of_lt_of_le [MulLeftMono α] {a b : α} (ha : a < 1)
(hb : b ≤ 1) :
a * b < 1 :=
mul_lt_of_lt_of_le_one ha hb
/-- Assumes left covariance.
The lemma assuming right covariance is `Right.mul_lt_one`. -/
@[to_additive /-- Assumes left covariance.
The lemma assuming right covariance is `Right.add_neg`. -/]
theorem Left.mul_lt_one [MulLeftStrictMono α] {a b : α} (ha : a < 1) (hb : b < 1) :
a * b < 1 :=
mul_lt_of_lt_of_lt_one ha hb
/-- Assumes left covariance.
The lemma assuming right covariance is `Right.mul_lt_one'`. -/
@[to_additive /-- Assumes left covariance.
The lemma assuming right covariance is `Right.add_neg'`. -/]
theorem Left.mul_lt_one' [MulLeftMono α] {a b : α} (ha : a < 1) (hb : b < 1) :
a * b < 1 :=
mul_lt_of_lt_of_lt_one' ha hb
/-! Lemmas of the form `b ≤ c → 1 ≤ a → b ≤ c * a`,
which assume left covariance. -/
@[to_additive]
theorem le_mul_of_le_of_one_le [MulLeftMono α] {a b c : α} (hbc : b ≤ c)
(ha : 1 ≤ a) :
b ≤ c * a :=
calc
b ≤ c := hbc
_ = c * 1 := (mul_one c).symm
_ ≤ c * a := mul_le_mul_left' ha c
@[to_additive]
theorem lt_mul_of_le_of_one_lt [MulLeftStrictMono α] {a b c : α} (hbc : b ≤ c)
(ha : 1 < a) :
b < c * a :=
calc
b ≤ c := hbc
_ = c * 1 := (mul_one c).symm
_ < c * a := mul_lt_mul_left' ha c
@[to_additive]
theorem lt_mul_of_lt_of_one_le [MulLeftMono α] {a b c : α} (hbc : b < c)
(ha : 1 ≤ a) :
b < c * a :=
calc
b < c := hbc
_ = c * 1 := (mul_one c).symm
_ ≤ c * a := mul_le_mul_left' ha c
@[to_additive]
theorem lt_mul_of_lt_of_one_lt [MulLeftStrictMono α] {a b c : α} (hbc : b < c)
(ha : 1 < a) :
b < c * a :=
calc
b < c := hbc
_ = c * 1 := (mul_one c).symm
_ < c * a := mul_lt_mul_left' ha c
@[to_additive]
theorem lt_mul_of_lt_of_one_lt' [MulLeftMono α] {a b c : α} (hbc : b < c)
(ha : 1 < a) :
b < c * a :=
lt_mul_of_lt_of_one_le hbc ha.le
/-- Assumes left covariance.
The lemma assuming right covariance is `Right.one_le_mul`. -/
@[to_additive Left.add_nonneg /-- Assumes left covariance.
The lemma assuming right covariance is `Right.add_nonneg`. -/]
theorem Left.one_le_mul [MulLeftMono α] {a b : α} (ha : 1 ≤ a) (hb : 1 ≤ b) :
1 ≤ a * b :=
le_mul_of_le_of_one_le ha hb
/-- Assumes left covariance.
The lemma assuming right covariance is `Right.one_lt_mul_of_le_of_lt`. -/
@[to_additive Left.add_pos_of_nonneg_of_pos
/-- Assumes left covariance.
The lemma assuming right covariance is `Right.add_pos_of_nonneg_of_pos`. -/]
theorem Left.one_lt_mul_of_le_of_lt [MulLeftStrictMono α] {a b : α} (ha : 1 ≤ a)
(hb : 1 < b) :
1 < a * b :=
lt_mul_of_le_of_one_lt ha hb
/-- Assumes left covariance.
The lemma assuming right covariance is `Right.one_lt_mul_of_lt_of_le`. -/
@[to_additive Left.add_pos_of_pos_of_nonneg
/-- Assumes left covariance.
The lemma assuming right covariance is `Right.add_pos_of_pos_of_nonneg`. -/]
theorem Left.one_lt_mul_of_lt_of_le [MulLeftMono α] {a b : α} (ha : 1 < a)
(hb : 1 ≤ b) :
1 < a * b :=
lt_mul_of_lt_of_one_le ha hb
/-- Assumes left covariance.
The lemma assuming right covariance is `Right.one_lt_mul`. -/
@[to_additive Left.add_pos /-- Assumes left covariance.
The lemma assuming right covariance is `Right.add_pos`. -/]
theorem Left.one_lt_mul [MulLeftStrictMono α] {a b : α} (ha : 1 < a) (hb : 1 < b) :
1 < a * b :=
lt_mul_of_lt_of_one_lt ha hb
/-- Assumes left covariance.
The lemma assuming right covariance is `Right.one_lt_mul'`. -/
@[to_additive Left.add_pos' /-- Assumes left covariance.
The lemma assuming right covariance is `Right.add_pos'`. -/]
theorem Left.one_lt_mul' [MulLeftMono α] {a b : α} (ha : 1 < a) (hb : 1 < b) :
1 < a * b :=
lt_mul_of_lt_of_one_lt' ha hb
/-! Lemmas of the form `a ≤ 1 → b ≤ c → a * b ≤ c`,
which assume right covariance. -/
@[to_additive]
theorem mul_le_of_le_one_of_le [MulRightMono α] {a b c : α} (ha : a ≤ 1)
(hbc : b ≤ c) :
a * b ≤ c :=
calc
a * b ≤ 1 * b := mul_le_mul_right' ha b
_ = b := one_mul b
_ ≤ c := hbc
@[to_additive]
theorem mul_lt_of_lt_one_of_le [MulRightStrictMono α] {a b c : α} (ha : a < 1)
(hbc : b ≤ c) :
a * b < c :=
calc
a * b < 1 * b := mul_lt_mul_right' ha b
_ = b := one_mul b
_ ≤ c := hbc
@[to_additive]
theorem mul_lt_of_le_one_of_lt [MulRightMono α] {a b c : α} (ha : a ≤ 1)
(hb : b < c) :
a * b < c :=
calc
a * b ≤ 1 * b := mul_le_mul_right' ha b
_ = b := one_mul b
_ < c := hb
@[to_additive]
theorem mul_lt_of_lt_one_of_lt [MulRightStrictMono α] {a b c : α} (ha : a < 1)
(hb : b < c) :
a * b < c :=
calc
a * b < 1 * b := mul_lt_mul_right' ha b
_ = b := one_mul b
_ < c := hb
@[to_additive]
theorem mul_lt_of_lt_one_of_lt' [MulRightMono α] {a b c : α} (ha : a < 1)
(hbc : b < c) :
a * b < c :=
mul_lt_of_le_one_of_lt ha.le hbc
/-- Assumes right covariance.
The lemma assuming left covariance is `Left.mul_le_one`. -/
@[to_additive /-- Assumes right covariance.
The lemma assuming left covariance is `Left.add_nonpos`. -/]
theorem Right.mul_le_one [MulRightMono α] {a b : α} (ha : a ≤ 1)
(hb : b ≤ 1) :
a * b ≤ 1 :=
mul_le_of_le_one_of_le ha hb
/-- Assumes right covariance.
The lemma assuming left covariance is `Left.mul_lt_one_of_lt_of_le`. -/
@[to_additive Right.add_neg_of_neg_of_nonpos
/-- Assumes right covariance.
The lemma assuming left covariance is `Left.add_neg_of_neg_of_nonpos`. -/]
theorem Right.mul_lt_one_of_lt_of_le [MulRightStrictMono α] {a b : α}
(ha : a < 1) (hb : b ≤ 1) :
a * b < 1 :=
mul_lt_of_lt_one_of_le ha hb
/-- Assumes right covariance.
The lemma assuming left covariance is `Left.mul_lt_one_of_le_of_lt`. -/
@[to_additive Right.add_neg_of_nonpos_of_neg
/-- Assumes right covariance.
The lemma assuming left covariance is `Left.add_neg_of_nonpos_of_neg`. -/]
theorem Right.mul_lt_one_of_le_of_lt [MulRightMono α] {a b : α}
(ha : a ≤ 1) (hb : b < 1) :
a * b < 1 :=
mul_lt_of_le_one_of_lt ha hb
/-- Assumes right covariance.
The lemma assuming left covariance is `Left.mul_lt_one`. -/
@[to_additive /-- Assumes right covariance.
The lemma assuming left covariance is `Left.add_neg`. -/]
theorem Right.mul_lt_one [MulRightStrictMono α] {a b : α} (ha : a < 1)
(hb : b < 1) :
a * b < 1 :=
mul_lt_of_lt_one_of_lt ha hb
/-- Assumes right covariance.
The lemma assuming left covariance is `Left.mul_lt_one'`. -/
@[to_additive /-- Assumes right covariance.
The lemma assuming left covariance is `Left.add_neg'`. -/]
theorem Right.mul_lt_one' [MulRightMono α] {a b : α} (ha : a < 1)
(hb : b < 1) :
a * b < 1 :=
mul_lt_of_lt_one_of_lt' ha hb
/-! Lemmas of the form `1 ≤ a → b ≤ c → b ≤ a * c`,
which assume right covariance. -/
@[to_additive]
theorem le_mul_of_one_le_of_le [MulRightMono α] {a b c : α} (ha : 1 ≤ a)
(hbc : b ≤ c) :
b ≤ a * c :=
calc
b ≤ c := hbc
_ = 1 * c := (one_mul c).symm
_ ≤ a * c := mul_le_mul_right' ha c
@[to_additive]
theorem lt_mul_of_one_lt_of_le [MulRightStrictMono α] {a b c : α} (ha : 1 < a)
(hbc : b ≤ c) :
b < a * c :=
calc
b ≤ c := hbc
_ = 1 * c := (one_mul c).symm
_ < a * c := mul_lt_mul_right' ha c
@[to_additive]
theorem lt_mul_of_one_le_of_lt [MulRightMono α] {a b c : α} (ha : 1 ≤ a)
(hbc : b < c) :
b < a * c :=
calc
b < c := hbc
_ = 1 * c := (one_mul c).symm
_ ≤ a * c := mul_le_mul_right' ha c
@[to_additive]
theorem lt_mul_of_one_lt_of_lt [MulRightStrictMono α] {a b c : α} (ha : 1 < a)
(hbc : b < c) :
b < a * c :=
calc
b < c := hbc
_ = 1 * c := (one_mul c).symm
_ < a * c := mul_lt_mul_right' ha c
@[to_additive]
theorem lt_mul_of_one_lt_of_lt' [MulRightMono α] {a b c : α} (ha : 1 < a)
(hbc : b < c) :
b < a * c :=
lt_mul_of_one_le_of_lt ha.le hbc
/-- Assumes right covariance.
The lemma assuming left covariance is `Left.one_le_mul`. -/
@[to_additive Right.add_nonneg /-- Assumes right covariance.
The lemma assuming left covariance is `Left.add_nonneg`. -/]
theorem Right.one_le_mul [MulRightMono α] {a b : α} (ha : 1 ≤ a)
(hb : 1 ≤ b) :
1 ≤ a * b :=
le_mul_of_one_le_of_le ha hb
/-- Assumes right covariance.
The lemma assuming left covariance is `Left.one_lt_mul_of_lt_of_le`. -/
@[to_additive Right.add_pos_of_pos_of_nonneg
/-- Assumes right covariance.
The lemma assuming left covariance is `Left.add_pos_of_pos_of_nonneg`. -/]
theorem Right.one_lt_mul_of_lt_of_le [MulRightStrictMono α] {a b : α}
(ha : 1 < a) (hb : 1 ≤ b) :
1 < a * b :=
lt_mul_of_one_lt_of_le ha hb
/-- Assumes right covariance.
The lemma assuming left covariance is `Left.one_lt_mul_of_le_of_lt`. -/
@[to_additive Right.add_pos_of_nonneg_of_pos
/-- Assumes right covariance.
The lemma assuming left covariance is `Left.add_pos_of_nonneg_of_pos`. -/]
theorem Right.one_lt_mul_of_le_of_lt [MulRightMono α] {a b : α}
(ha : 1 ≤ a) (hb : 1 < b) :
1 < a * b :=
lt_mul_of_one_le_of_lt ha hb
/-- Assumes right covariance.
The lemma assuming left covariance is `Left.one_lt_mul`. -/
@[to_additive Right.add_pos /-- Assumes right covariance.
The lemma assuming left covariance is `Left.add_pos`. -/]
theorem Right.one_lt_mul [MulRightStrictMono α] {a b : α} (ha : 1 < a)
(hb : 1 < b) :
1 < a * b :=
lt_mul_of_one_lt_of_lt ha hb
/-- Assumes right covariance.
The lemma assuming left covariance is `Left.one_lt_mul'`. -/
@[to_additive Right.add_pos' /-- Assumes right covariance.
The lemma assuming left covariance is `Left.add_pos'`. -/]
theorem Right.one_lt_mul' [MulRightMono α] {a b : α} (ha : 1 < a)
(hb : 1 < b) :
1 < a * b :=
lt_mul_of_one_lt_of_lt' ha hb
alias mul_le_one' := Left.mul_le_one
alias mul_lt_one_of_le_of_lt := Left.mul_lt_one_of_le_of_lt
alias mul_lt_one_of_lt_of_le := Left.mul_lt_one_of_lt_of_le
alias mul_lt_one := Left.mul_lt_one
alias mul_lt_one' := Left.mul_lt_one'
attribute [to_additive add_nonpos /-- **Alias** of `Left.add_nonpos`. -/] mul_le_one'
attribute [to_additive add_neg_of_nonpos_of_neg
/-- **Alias** of `Left.add_neg_of_nonpos_of_neg`. -/]
mul_lt_one_of_le_of_lt
attribute [to_additive add_neg_of_neg_of_nonpos
/-- **Alias** of `Left.add_neg_of_neg_of_nonpos`. -/]
mul_lt_one_of_lt_of_le
attribute [to_additive /-- **Alias** of `Left.add_neg`. -/] mul_lt_one
attribute [to_additive /-- **Alias** of `Left.add_neg'`. -/] mul_lt_one'
alias one_le_mul := Left.one_le_mul
alias one_lt_mul_of_le_of_lt' := Left.one_lt_mul_of_le_of_lt
alias one_lt_mul_of_lt_of_le' := Left.one_lt_mul_of_lt_of_le
alias one_lt_mul' := Left.one_lt_mul
alias one_lt_mul'' := Left.one_lt_mul'
attribute [to_additive add_nonneg /-- **Alias** of `Left.add_nonneg`. -/] one_le_mul
attribute [to_additive add_pos_of_nonneg_of_pos
/-- **Alias** of `Left.add_pos_of_nonneg_of_pos`. -/]
one_lt_mul_of_le_of_lt'
attribute [to_additive add_pos_of_pos_of_nonneg
/-- **Alias** of `Left.add_pos_of_pos_of_nonneg`. -/]
one_lt_mul_of_lt_of_le'
attribute [to_additive add_pos /-- **Alias** of `Left.add_pos`. -/] one_lt_mul'
attribute [to_additive add_pos' /-- **Alias** of `Left.add_pos'`. -/] one_lt_mul''
@[to_additive]
theorem lt_of_mul_lt_of_one_le_left [MulLeftMono α] {a b c : α} (h : a * b < c)
(hle : 1 ≤ b) :
a < c :=
(le_mul_of_one_le_right' hle).trans_lt h
@[to_additive]
theorem le_of_mul_le_of_one_le_left [MulLeftMono α] {a b c : α} (h : a * b ≤ c)
(hle : 1 ≤ b) :
a ≤ c :=
(le_mul_of_one_le_right' hle).trans h
@[to_additive]
theorem lt_of_lt_mul_of_le_one_left [MulLeftMono α] {a b c : α} (h : a < b * c)
(hle : c ≤ 1) :
a < b :=
h.trans_le (mul_le_of_le_one_right' hle)
@[to_additive]
theorem le_of_le_mul_of_le_one_left [MulLeftMono α] {a b c : α} (h : a ≤ b * c)
(hle : c ≤ 1) :
a ≤ b :=
h.trans (mul_le_of_le_one_right' hle)
@[to_additive]
theorem lt_of_mul_lt_of_one_le_right [MulRightMono α] {a b c : α}
(h : a * b < c) (hle : 1 ≤ a) :
b < c :=
(le_mul_of_one_le_left' hle).trans_lt h
@[to_additive]
theorem le_of_mul_le_of_one_le_right [MulRightMono α] {a b c : α}
(h : a * b ≤ c) (hle : 1 ≤ a) :
b ≤ c :=
(le_mul_of_one_le_left' hle).trans h
@[to_additive]
theorem lt_of_lt_mul_of_le_one_right [MulRightMono α] {a b c : α}
(h : a < b * c) (hle : b ≤ 1) :
a < c :=
h.trans_le (mul_le_of_le_one_left' hle)
@[to_additive]
theorem le_of_le_mul_of_le_one_right [MulRightMono α] {a b c : α}
(h : a ≤ b * c) (hle : b ≤ 1) :
a ≤ c :=
h.trans (mul_le_of_le_one_left' hle)
end Preorder
section PartialOrder
variable [PartialOrder α]
@[to_additive]
theorem mul_eq_one_iff_of_one_le [MulLeftMono α]
[MulRightMono α] {a b : α} (ha : 1 ≤ a) (hb : 1 ≤ b) :
a * b = 1 ↔ a = 1 ∧ b = 1 :=
Iff.intro
(fun hab : a * b = 1 =>
have : a ≤ 1 := hab ▸ le_mul_of_le_of_one_le le_rfl hb
have : a = 1 := le_antisymm this ha
have : b ≤ 1 := hab ▸ le_mul_of_one_le_of_le ha le_rfl
have : b = 1 := le_antisymm this hb
And.intro ‹a = 1› ‹b = 1›)
(by rintro ⟨rfl, rfl⟩; rw [mul_one])
section Left
variable [MulLeftMono α] {a b : α}
@[to_additive eq_zero_of_add_nonneg_left]
theorem eq_one_of_one_le_mul_left (ha : a ≤ 1) (hb : b ≤ 1) (hab : 1 ≤ a * b) : a = 1 :=
ha.eq_of_not_lt fun h => hab.not_gt <| mul_lt_one_of_lt_of_le h hb
@[to_additive]
theorem eq_one_of_mul_le_one_left (ha : 1 ≤ a) (hb : 1 ≤ b) (hab : a * b ≤ 1) : a = 1 :=
ha.eq_of_not_lt' fun h => hab.not_gt <| one_lt_mul_of_lt_of_le' h hb
end Left
section Right
variable [MulRightMono α] {a b : α}
@[to_additive eq_zero_of_add_nonneg_right]
theorem eq_one_of_one_le_mul_right (ha : a ≤ 1) (hb : b ≤ 1) (hab : 1 ≤ a * b) : b = 1 :=
hb.eq_of_not_lt fun h => hab.not_gt <| Right.mul_lt_one_of_le_of_lt ha h
@[to_additive]
theorem eq_one_of_mul_le_one_right (ha : 1 ≤ a) (hb : 1 ≤ b) (hab : a * b ≤ 1) : b = 1 :=
hb.eq_of_not_lt' fun h => hab.not_gt <| Right.one_lt_mul_of_le_of_lt ha h
end Right
end PartialOrder
section LinearOrder
variable [LinearOrder α]
theorem exists_square_le [MulLeftStrictMono α] (a : α) : ∃ b : α, b * b ≤ a := by
by_cases! h : a < 1
· use a
have : a * a < a * 1 := mul_lt_mul_left' h a
rw [mul_one] at this
exact le_of_lt this
· use 1
rwa [mul_one]
end LinearOrder
end MulOneClass
section Semigroup
variable [Semigroup α]
section PartialOrder
variable [PartialOrder α]
/- This is not instance, since we want to have an instance from `LeftCancelSemigroup`s
to the appropriate covariant class. -/
/-- A semigroup with a partial order and satisfying `LeftCancelSemigroup`
(i.e. `a * c < b * c → a < b`) is a `LeftCancelSemigroup`. -/
@[to_additive
/-- An additive semigroup with a partial order and satisfying `AddLeftCancelSemigroup`
(i.e. `c + a < c + b → a < b`) is a `AddLeftCancelSemigroup`. -/]
def Contravariant.toLeftCancelSemigroup [MulLeftReflectLE α] :
LeftCancelSemigroup α :=
{ ‹Semigroup α› with mul_left_cancel := fun _ _ _ => mul_left_cancel'' }
/- This is not instance, since we want to have an instance from `RightCancelSemigroup`s
to the appropriate covariant class. -/
/-- A semigroup with a partial order and satisfying `RightCancelSemigroup`
(i.e. `a * c < b * c → a < b`) is a `RightCancelSemigroup`. -/
@[to_additive
/-- An additive semigroup with a partial order and satisfying `AddRightCancelSemigroup`
(`a + c < b + c → a < b`) is a `AddRightCancelSemigroup`. -/]
def Contravariant.toRightCancelSemigroup [MulRightReflectLE α] :
RightCancelSemigroup α :=
{ ‹Semigroup α› with mul_right_cancel := fun _ _ _ => mul_right_cancel'' }
end PartialOrder
end Semigroup
section Mono
variable [Mul α] [Preorder α] [Preorder β] {f g : β → α} {s : Set β}
@[to_additive const_add]
theorem Monotone.const_mul' [MulLeftMono α] (hf : Monotone f) (a : α) : Monotone fun x ↦ a * f x :=
mul_right_mono.comp hf
@[to_additive const_add]
theorem MonotoneOn.const_mul' [MulLeftMono α] (hf : MonotoneOn f s) (a : α) :
MonotoneOn (fun x => a * f x) s := mul_right_mono.comp_monotoneOn hf
@[to_additive const_add]
theorem Antitone.const_mul' [MulLeftMono α] (hf : Antitone f) (a : α) : Antitone fun x ↦ a * f x :=
mul_right_mono.comp_antitone hf
@[to_additive const_add]
theorem AntitoneOn.const_mul' [MulLeftMono α] (hf : AntitoneOn f s) (a : α) :
AntitoneOn (fun x => a * f x) s := mul_right_mono.comp_antitoneOn hf
@[to_additive add_const]
theorem Monotone.mul_const' [MulRightMono α] (hf : Monotone f) (a : α) :
Monotone fun x => f x * a := mul_left_mono.comp hf
@[to_additive add_const]
theorem MonotoneOn.mul_const' [MulRightMono α] (hf : MonotoneOn f s) (a : α) :
MonotoneOn (fun x => f x * a) s := mul_left_mono.comp_monotoneOn hf
@[to_additive add_const]
theorem Antitone.mul_const' [MulRightMono α] (hf : Antitone f) (a : α) : Antitone fun x ↦ f x * a :=
mul_left_mono.comp_antitone hf
@[to_additive add_const]
theorem AntitoneOn.mul_const' [MulRightMono α] (hf : AntitoneOn f s) (a : α) :
AntitoneOn (fun x => f x * a) s := mul_left_mono.comp_antitoneOn hf
/-- The product of two monotone functions is monotone. -/
@[to_additive add /-- The sum of two monotone functions is monotone. -/]
theorem Monotone.mul' [MulLeftMono α]
[MulRightMono α] (hf : Monotone f) (hg : Monotone g) :
Monotone fun x => f x * g x := fun _ _ h => mul_le_mul' (hf h) (hg h)
/-- The product of two monotone functions is monotone. -/
@[to_additive add /-- The sum of two monotone functions is monotone. -/]
theorem MonotoneOn.mul' [MulLeftMono α]
[MulRightMono α] (hf : MonotoneOn f s) (hg : MonotoneOn g s) :
MonotoneOn (fun x => f x * g x) s := fun _ hx _ hy h =>
mul_le_mul' (hf hx hy h) (hg hx hy h)
/-- The product of two antitone functions is antitone. -/
@[to_additive add /-- The sum of two antitone functions is antitone. -/]
theorem Antitone.mul' [MulLeftMono α]
[MulRightMono α] (hf : Antitone f) (hg : Antitone g) :
Antitone fun x => f x * g x := fun _ _ h => mul_le_mul' (hf h) (hg h)
/-- The product of two antitone functions is antitone. -/
@[to_additive add /-- The sum of two antitone functions is antitone. -/]
theorem AntitoneOn.mul' [MulLeftMono α]
[MulRightMono α] (hf : AntitoneOn f s) (hg : AntitoneOn g s) :
AntitoneOn (fun x => f x * g x) s :=
fun _ hx _ hy h => mul_le_mul' (hf hx hy h) (hg hx hy h)
section Left
variable [MulLeftStrictMono α]
@[to_additive const_add]
theorem StrictMono.const_mul' (hf : StrictMono f) (c : α) : StrictMono fun x => c * f x :=
fun _ _ ab => mul_lt_mul_left' (hf ab) c
@[to_additive const_add]
theorem StrictMonoOn.const_mul' (hf : StrictMonoOn f s) (c : α) :
StrictMonoOn (fun x => c * f x) s :=
fun _ ha _ hb ab => mul_lt_mul_left' (hf ha hb ab) c
@[to_additive const_add]
theorem StrictAnti.const_mul' (hf : StrictAnti f) (c : α) : StrictAnti fun x => c * f x :=
fun _ _ ab => mul_lt_mul_left' (hf ab) c
@[to_additive const_add]
theorem StrictAntiOn.const_mul' (hf : StrictAntiOn f s) (c : α) :
StrictAntiOn (fun x => c * f x) s :=
fun _ ha _ hb ab => mul_lt_mul_left' (hf ha hb ab) c
end Left
section Right
variable [MulRightStrictMono α]
@[to_additive add_const]
theorem StrictMono.mul_const' (hf : StrictMono f) (c : α) : StrictMono fun x => f x * c :=
fun _ _ ab => mul_lt_mul_right' (hf ab) c
@[to_additive add_const]
theorem StrictMonoOn.mul_const' (hf : StrictMonoOn f s) (c : α) :
StrictMonoOn (fun x => f x * c) s :=
fun _ ha _ hb ab => mul_lt_mul_right' (hf ha hb ab) c
@[to_additive add_const]
theorem StrictAnti.mul_const' (hf : StrictAnti f) (c : α) : StrictAnti fun x => f x * c :=
fun _ _ ab => mul_lt_mul_right' (hf ab) c
@[to_additive add_const]
theorem StrictAntiOn.mul_const' (hf : StrictAntiOn f s) (c : α) :
StrictAntiOn (fun x => f x * c) s :=
fun _ ha _ hb ab => mul_lt_mul_right' (hf ha hb ab) c
end Right
/-- The product of two strictly monotone functions is strictly monotone. -/
@[to_additive add /-- The sum of two strictly monotone functions is strictly monotone. -/]
theorem StrictMono.mul' [MulLeftStrictMono α]
[MulRightStrictMono α] (hf : StrictMono f) (hg : StrictMono g) :
StrictMono fun x => f x * g x := fun _ _ ab =>
mul_lt_mul_of_lt_of_lt (hf ab) (hg ab)
/-- The product of two strictly monotone functions is strictly monotone. -/
@[to_additive add /-- The sum of two strictly monotone functions is strictly monotone. -/]
theorem StrictMonoOn.mul' [MulLeftStrictMono α]
[MulRightStrictMono α] (hf : StrictMonoOn f s) (hg : StrictMonoOn g s) :
StrictMonoOn (fun x => f x * g x) s :=
fun _ ha _ hb ab => mul_lt_mul_of_lt_of_lt (hf ha hb ab) (hg ha hb ab)
/-- The product of two strictly antitone functions is strictly antitone. -/
@[to_additive add /-- The sum of two strictly antitone functions is strictly antitone. -/]
theorem StrictAnti.mul' [MulLeftStrictMono α]
[MulRightStrictMono α] (hf : StrictAnti f) (hg : StrictAnti g) :
StrictAnti fun x => f x * g x :=
fun _ _ ab => mul_lt_mul_of_lt_of_lt (hf ab) (hg ab)
/-- The product of two strictly antitone functions is strictly antitone. -/
@[to_additive add /-- The sum of two strictly antitone functions is strictly antitone. -/]
theorem StrictAntiOn.mul' [MulLeftStrictMono α]
[MulRightStrictMono α] (hf : StrictAntiOn f s) (hg : StrictAntiOn g s) :
StrictAntiOn (fun x => f x * g x) s :=
fun _ ha _ hb ab => mul_lt_mul_of_lt_of_lt (hf ha hb ab) (hg ha hb ab)
/-- The product of a monotone function and a strictly monotone function is strictly monotone. -/
@[to_additive add_strictMono /-- The sum of a monotone function and a strictly monotone function is
strictly monotone. -/]
theorem Monotone.mul_strictMono' [MulLeftStrictMono α]
[MulRightMono α] {f g : β → α} (hf : Monotone f)
(hg : StrictMono g) :
StrictMono fun x => f x * g x :=
fun _ _ h => mul_lt_mul_of_le_of_lt (hf h.le) (hg h)
/-- The product of a monotone function and a strictly monotone function is strictly monotone. -/
@[to_additive add_strictMono /-- The sum of a monotone function and a strictly monotone function is
strictly monotone. -/]
theorem MonotoneOn.mul_strictMono' [MulLeftStrictMono α]
[MulRightMono α] {f g : β → α} (hf : MonotoneOn f s)
(hg : StrictMonoOn g s) : StrictMonoOn (fun x => f x * g x) s :=
fun _ hx _ hy h => mul_lt_mul_of_le_of_lt (hf hx hy h.le) (hg hx hy h)
/-- The product of an antitone function and a strictly antitone function is strictly antitone. -/
@[to_additive add_strictAnti /-- The sum of an antitone function and a strictly antitone function is
strictly antitone. -/]
theorem Antitone.mul_strictAnti' [MulLeftStrictMono α]
[MulRightMono α] {f g : β → α} (hf : Antitone f)
(hg : StrictAnti g) :
StrictAnti fun x => f x * g x :=
fun _ _ h => mul_lt_mul_of_le_of_lt (hf h.le) (hg h)
/-- The product of an antitone function and a strictly antitone function is strictly antitone. -/
@[to_additive add_strictAnti /-- The sum of an antitone function and a strictly antitone function is
strictly antitone. -/]
theorem AntitoneOn.mul_strictAnti' [MulLeftStrictMono α]
[MulRightMono α] {f g : β → α} (hf : AntitoneOn f s)
(hg : StrictAntiOn g s) :
StrictAntiOn (fun x => f x * g x) s :=
fun _ hx _ hy h => mul_lt_mul_of_le_of_lt (hf hx hy h.le) (hg hx hy h)
variable [MulLeftMono α] [MulRightStrictMono α]
/-- The product of a strictly monotone function and a monotone function is strictly monotone. -/
@[to_additive add_monotone /-- The sum of a strictly monotone function and a monotone function is
strictly monotone. -/]
theorem StrictMono.mul_monotone' (hf : StrictMono f) (hg : Monotone g) :
StrictMono fun x => f x * g x :=
fun _ _ h => mul_lt_mul_of_lt_of_le (hf h) (hg h.le)
/-- The product of a strictly monotone function and a monotone function is strictly monotone. -/
@[to_additive add_monotone /-- The sum of a strictly monotone function and a monotone function is
strictly monotone. -/]
theorem StrictMonoOn.mul_monotone' (hf : StrictMonoOn f s) (hg : MonotoneOn g s) :
StrictMonoOn (fun x => f x * g x) s :=
fun _ hx _ hy h => mul_lt_mul_of_lt_of_le (hf hx hy h) (hg hx hy h.le)
/-- The product of a strictly antitone function and an antitone function is strictly antitone. -/
@[to_additive add_antitone /-- The sum of a strictly antitone function and an antitone function is
strictly antitone. -/]
theorem StrictAnti.mul_antitone' (hf : StrictAnti f) (hg : Antitone g) :
StrictAnti fun x => f x * g x :=
fun _ _ h => mul_lt_mul_of_lt_of_le (hf h) (hg h.le)
/-- The product of a strictly antitone function and an antitone function is strictly antitone. -/
@[to_additive add_antitone /-- The sum of a strictly antitone function and an antitone function is
strictly antitone. -/]
theorem StrictAntiOn.mul_antitone' (hf : StrictAntiOn f s) (hg : AntitoneOn g s) :
StrictAntiOn (fun x => f x * g x) s :=
fun _ hx _ hy h => mul_lt_mul_of_lt_of_le (hf hx hy h) (hg hx hy h.le)
@[to_additive (attr := simp) cmp_add_left]
theorem cmp_mul_left' {α : Type*} [Mul α] [LinearOrder α] [MulLeftStrictMono α]
(a b c : α) :
cmp (a * b) (a * c) = cmp b c :=
(strictMono_id.const_mul' a).cmp_map_eq b c
@[to_additive (attr := simp) cmp_add_right]
theorem cmp_mul_right' {α : Type*} [Mul α] [LinearOrder α]
[MulRightStrictMono α] (a b c : α) :
cmp (a * c) (b * c) = cmp a b :=
(strictMono_id.mul_const' c).cmp_map_eq a b
end Mono
/-- An element `a : α` is `MulLECancellable` if `x ↦ a * x` is order-reflecting.
We will make a separate version of many lemmas that require `[MulLeftReflectLE α]` with
`MulLECancellable` assumptions instead. These lemmas can then be instantiated to specific types,
like `ENNReal`, where we can replace the assumption `AddLECancellable x` by `x ≠ ∞`.
-/
@[to_additive
/-- An element `a : α` is `AddLECancellable` if `x ↦ a + x` is order-reflecting.
We will make a separate version of many lemmas that require `[MulLeftReflectLE α]` with
`AddLECancellable` assumptions instead. These lemmas can then be instantiated to specific types,
like `ENNReal`, where we can replace the assumption `AddLECancellable x` by `x ≠ ∞`. -/]
def MulLECancellable [Mul α] [LE α] (a : α) : Prop :=
∀ ⦃b c⦄, a * b ≤ a * c → b ≤ c
@[to_additive]
theorem Contravariant.MulLECancellable [Mul α] [LE α] [MulLeftReflectLE α]
{a : α} :
MulLECancellable a :=
fun _ _ => le_of_mul_le_mul_left'
@[to_additive (attr := simp)]
theorem mulLECancellable_one [MulOneClass α] [LE α] : MulLECancellable (1 : α) := fun a b => by
simpa only [one_mul] using id
namespace MulLECancellable
@[to_additive]
protected theorem Injective [Mul α] [PartialOrder α] {a : α} (ha : MulLECancellable a) :
Injective (a * ·) :=
fun _ _ h => le_antisymm (ha h.le) (ha h.ge)
@[to_additive]
protected theorem isLeftRegular [Mul α] [PartialOrder α] {a : α}
(ha : MulLECancellable a) : IsLeftRegular a :=
ha.Injective
@[to_additive]
protected theorem inj [Mul α] [PartialOrder α] {a b c : α} (ha : MulLECancellable a) :
a * b = a * c ↔ b = c :=
ha.Injective.eq_iff
@[to_additive]
protected theorem injective_left [Mul α] [i : @Std.Commutative α (· * ·)] [PartialOrder α] {a : α}
(ha : MulLECancellable a) :
Injective (· * a) := fun b c h => ha.Injective <| by dsimp; rwa [i.comm a, i.comm a]
@[to_additive]
protected theorem inj_left [Mul α] [@Std.Commutative α (· * ·)] [PartialOrder α] {a b c : α}
(hc : MulLECancellable c) :
a * c = b * c ↔ a = b :=
hc.injective_left.eq_iff
variable [LE α]
@[to_additive]
protected theorem mul_le_mul_iff_left [Mul α] [MulLeftMono α] {a b c : α}
(ha : MulLECancellable a) : a * b ≤ a * c ↔ b ≤ c :=
⟨fun h => ha h, fun h => mul_le_mul_left' h a⟩
@[to_additive]
protected theorem mul_le_mul_iff_right [Mul α] [i : @Std.Commutative α (· * ·)]
[MulLeftMono α] {a b c : α} (ha : MulLECancellable a) :
b * a ≤ c * a ↔ b ≤ c := by rw [i.comm b, i.comm c, ha.mul_le_mul_iff_left]
@[to_additive]
protected theorem le_mul_iff_one_le_right [MulOneClass α] [MulLeftMono α]
{a b : α} (ha : MulLECancellable a) :
a ≤ a * b ↔ 1 ≤ b :=
Iff.trans (by rw [mul_one]) ha.mul_le_mul_iff_left
@[to_additive]
protected theorem mul_le_iff_le_one_right [MulOneClass α] [MulLeftMono α]
{a b : α} (ha : MulLECancellable a) :
a * b ≤ a ↔ b ≤ 1 :=
Iff.trans (by rw [mul_one]) ha.mul_le_mul_iff_left
@[to_additive]
protected theorem le_mul_iff_one_le_left [MulOneClass α] [i : @Std.Commutative α (· * ·)]
[MulLeftMono α] {a b : α} (ha : MulLECancellable a) :
a ≤ b * a ↔ 1 ≤ b := by rw [i.comm, ha.le_mul_iff_one_le_right]
@[to_additive]
protected theorem mul_le_iff_le_one_left [MulOneClass α] [i : @Std.Commutative α (· * ·)]
[MulLeftMono α] {a b : α} (ha : MulLECancellable a) :
b * a ≤ a ↔ b ≤ 1 := by rw [i.comm, ha.mul_le_iff_le_one_right]
@[to_additive] lemma mul [Semigroup α] {a b : α} (ha : MulLECancellable a)
(hb : MulLECancellable b) : MulLECancellable (a * b) :=
fun c d hcd ↦ hb <| ha <| by rwa [← mul_assoc, ← mul_assoc]
@[to_additive] lemma of_mul_right [Semigroup α] [MulLeftMono α] {a b : α}
(h : MulLECancellable (a * b)) : MulLECancellable b :=
fun c d hcd ↦ h <| by rw [mul_assoc, mul_assoc]; exact mul_le_mul_left' hcd _
@[to_additive] lemma of_mul_left [CommSemigroup α] [MulLeftMono α] {a b : α}
(h : MulLECancellable (a * b)) : MulLECancellable a := (mul_comm a b ▸ h).of_mul_right
end MulLECancellable
@[to_additive (attr := simp)]
lemma mulLECancellable_mul [LE α] [CommSemigroup α] [MulLeftMono α] {a b : α} :
MulLECancellable (a * b) ↔ MulLECancellable a ∧ MulLECancellable b :=
⟨fun h ↦ ⟨h.of_mul_left, h.of_mul_right⟩, fun h ↦ h.1.mul h.2⟩ |
.lake/packages/mathlib/Mathlib/Algebra/Order/Monoid/Unbundled/Defs.lean | import Mathlib.Algebra.Group.Basic
import Mathlib.Order.Basic
import Mathlib.Order.Monotone.Defs
/-!
# Covariants and contravariants
This file contains general lemmas and instances to work with the interactions between a relation and
an action on a Type.
The intended application is the splitting of the ordering from the algebraic assumptions on the
operations in the `Ordered[...]` hierarchy.
The strategy is to introduce two more flexible typeclasses, `CovariantClass` and
`ContravariantClass`:
* `CovariantClass` models the implication `a ≤ b → c * a ≤ c * b` (multiplication is monotone),
* `ContravariantClass` models the implication `a * b < a * c → b < c`.
Since `Co(ntra)variantClass` takes as input the operation (typically `(+)` or `(*)`) and the order
relation (typically `(≤)` or `(<)`), these are the only two typeclasses that I have used.
The general approach is to formulate the lemma that you are interested in and prove it, with the
`Ordered[...]` typeclass of your liking. After that, you convert the single typeclass,
say `[OrderedCancelMonoid M]`, into three typeclasses, e.g.
`[CancelMonoid M] [PartialOrder M] [CovariantClass M M (Function.swap (*)) (≤)]`
and have a go at seeing if the proof still works!
Note that it is possible to combine several `Co(ntra)variantClass` assumptions together.
Indeed, the usual ordered typeclasses arise from assuming the pair
`[CovariantClass M M (*) (≤)] [ContravariantClass M M (*) (<)]`
on top of order/algebraic assumptions.
A formal remark is that normally `CovariantClass` uses the `(≤)`-relation, while
`ContravariantClass` uses the `(<)`-relation. This need not be the case in general, but seems to be
the most common usage. In the opposite direction, the implication
```lean
[Semigroup α] [PartialOrder α] [ContravariantClass α α (*) (≤)] → LeftCancelSemigroup α
```
holds -- note the `Co*ntra*` assumption on the `(≤)`-relation.
## Formalization notes
We stick to the convention of using `Function.swap (*)` (or `Function.swap (+)`), for the
typeclass assumptions, since `Function.swap` is slightly better behaved than `flip`.
However, sometimes as a **non-typeclass** assumption, we prefer `flip (*)` (or `flip (+)`),
as it is easier to use.
-/
-- TODO: convert `ExistsMulOfLE`, `ExistsAddOfLE`?
-- TODO: relationship with `Con/AddCon`
-- TODO: include equivalence of `LeftCancelSemigroup` with
-- `Semigroup PartialOrder ContravariantClass α α (*) (≤)`?
-- TODO : use ⇒, as per Eric's suggestion? See
-- https://leanprover.zulipchat.com/#narrow/stream/116395-maths/topic/ordered.20stuff/near/236148738
-- for a discussion.
open Function
section Variants
variable {M N : Type*} (μ : M → N → N) (r : N → N → Prop)
variable (M N)
/-- `Covariant` is useful to formulate succinctly statements about the interactions between an
action of a Type on another one and a relation on the acted-upon Type.
See the `CovariantClass` doc-string for its meaning. -/
def Covariant : Prop :=
∀ (m) {n₁ n₂}, r n₁ n₂ → r (μ m n₁) (μ m n₂)
/-- `Contravariant` is useful to formulate succinctly statements about the interactions between an
action of a Type on another one and a relation on the acted-upon Type.
See the `ContravariantClass` doc-string for its meaning. -/
def Contravariant : Prop :=
∀ (m) {n₁ n₂}, r (μ m n₁) (μ m n₂) → r n₁ n₂
/-- Given an action `μ` of a Type `M` on a Type `N` and a relation `r` on `N`, informally, the
`CovariantClass` says that "the action `μ` preserves the relation `r`."
More precisely, the `CovariantClass` is a class taking two Types `M N`, together with an "action"
`μ : M → N → N` and a relation `r : N → N → Prop`. Its unique field `elim` is the assertion that
for all `m ∈ M` and all elements `n₁, n₂ ∈ N`, if the relation `r` holds for the pair
`(n₁, n₂)`, then, the relation `r` also holds for the pair `(μ m n₁, μ m n₂)`,
obtained from `(n₁, n₂)` by acting upon it by `m`.
If `m : M` and `h : r n₁ n₂`, then `CovariantClass.elim m h : r (μ m n₁) (μ m n₂)`.
-/
class CovariantClass : Prop where
/-- For all `m ∈ M` and all elements `n₁, n₂ ∈ N`, if the relation `r` holds for the pair
`(n₁, n₂)`, then, the relation `r` also holds for the pair `(μ m n₁, μ m n₂)` -/
protected elim : Covariant M N μ r
/-- Given an action `μ` of a Type `M` on a Type `N` and a relation `r` on `N`, informally, the
`ContravariantClass` says that "if the result of the action `μ` on a pair satisfies the
relation `r`, then the initial pair satisfied the relation `r`."
More precisely, the `ContravariantClass` is a class taking two Types `M N`, together with an
"action" `μ : M → N → N` and a relation `r : N → N → Prop`. Its unique field `elim` is the
assertion that for all `m ∈ M` and all elements `n₁, n₂ ∈ N`, if the relation `r` holds for the
pair `(μ m n₁, μ m n₂)` obtained from `(n₁, n₂)` by acting upon it by `m`, then, the relation
`r` also holds for the pair `(n₁, n₂)`.
If `m : M` and `h : r (μ m n₁) (μ m n₂)`, then `ContravariantClass.elim m h : r n₁ n₂`.
-/
class ContravariantClass : Prop where
/-- For all `m ∈ M` and all elements `n₁, n₂ ∈ N`, if the relation `r` holds for the
pair `(μ m n₁, μ m n₂)` obtained from `(n₁, n₂)` by acting upon it by `m`, then, the relation
`r` also holds for the pair `(n₁, n₂)`. -/
protected elim : Contravariant M N μ r
/-- Typeclass for monotonicity of multiplication on the left,
namely `b₁ ≤ b₂ → a * b₁ ≤ a * b₂`.
You should usually not use this very granular typeclass directly, but rather a typeclass like
`OrderedCommMonoid`. -/
abbrev MulLeftMono [Mul M] [LE M] : Prop :=
CovariantClass M M (· * ·) (· ≤ ·)
/-- Typeclass for monotonicity of multiplication on the right,
namely `a₁ ≤ a₂ → a₁ * b ≤ a₂ * b`.
You should usually not use this very granular typeclass directly, but rather a typeclass like
`OrderedCommMonoid`. -/
abbrev MulRightMono [Mul M] [LE M] : Prop :=
CovariantClass M M (swap (· * ·)) (· ≤ ·)
/-- Typeclass for monotonicity of addition on the left,
namely `b₁ ≤ b₂ → a + b₁ ≤ a + b₂`.
You should usually not use this very granular typeclass directly, but rather a typeclass like
`OrderedAddCommMonoid`. -/
abbrev AddLeftMono [Add M] [LE M] : Prop :=
CovariantClass M M (· + ·) (· ≤ ·)
/-- Typeclass for monotonicity of addition on the right,
namely `a₁ ≤ a₂ → a₁ + b ≤ a₂ + b`.
You should usually not use this very granular typeclass directly, but rather a typeclass like
`OrderedAddCommMonoid`. -/
abbrev AddRightMono [Add M] [LE M] : Prop :=
CovariantClass M M (swap (· + ·)) (· ≤ ·)
attribute [to_additive existing] MulLeftMono MulRightMono
/-- Typeclass for monotonicity of multiplication on the left,
namely `b₁ < b₂ → a * b₁ < a * b₂`.
You should usually not use this very granular typeclass directly, but rather a typeclass like
`OrderedCommGroup`. -/
abbrev MulLeftStrictMono [Mul M] [LT M] : Prop :=
CovariantClass M M (· * ·) (· < ·)
/-- Typeclass for monotonicity of multiplication on the right,
namely `a₁ < a₂ → a₁ * b < a₂ * b`.
You should usually not use this very granular typeclass directly, but rather a typeclass like
`OrderedCommGroup`. -/
abbrev MulRightStrictMono [Mul M] [LT M] : Prop :=
CovariantClass M M (swap (· * ·)) (· < ·)
/-- Typeclass for monotonicity of addition on the left,
namely `b₁ < b₂ → a + b₁ < a + b₂`.
You should usually not use this very granular typeclass directly, but rather a typeclass like
`OrderedAddCommGroup`. -/
abbrev AddLeftStrictMono [Add M] [LT M] : Prop :=
CovariantClass M M (· + ·) (· < ·)
/-- Typeclass for monotonicity of addition on the right,
namely `a₁ < a₂ → a₁ + b < a₂ + b`.
You should usually not use this very granular typeclass directly, but rather a typeclass like
`OrderedAddCommGroup`. -/
abbrev AddRightStrictMono [Add M] [LT M] : Prop :=
CovariantClass M M (swap (· + ·)) (· < ·)
attribute [to_additive existing] MulLeftStrictMono MulRightStrictMono
/-- Typeclass for strict reverse monotonicity of multiplication on the left,
namely `a * b₁ < a * b₂ → b₁ < b₂`.
You should usually not use this very granular typeclass directly, but rather a typeclass like
`OrderedCommGroup`. -/
abbrev MulLeftReflectLT [Mul M] [LT M] : Prop :=
ContravariantClass M M (· * ·) (· < ·)
/-- Typeclass for strict reverse monotonicity of multiplication on the right,
namely `a₁ * b < a₂ * b → a₁ < a₂`.
You should usually not use this very granular typeclass directly, but rather a typeclass like
`OrderedCommGroup`. -/
abbrev MulRightReflectLT [Mul M] [LT M] : Prop :=
ContravariantClass M M (swap (· * ·)) (· < ·)
/-- Typeclass for strict reverse monotonicity of addition on the left,
namely `a + b₁ < a + b₂ → b₁ < b₂`.
You should usually not use this very granular typeclass directly, but rather a typeclass like
`OrderedAddCommGroup`. -/
abbrev AddLeftReflectLT [Add M] [LT M] : Prop :=
ContravariantClass M M (· + ·) (· < ·)
/-- Typeclass for strict reverse monotonicity of addition on the right,
namely `a₁ * b < a₂ * b → a₁ < a₂`.
You should usually not use this very granular typeclass directly, but rather a typeclass like
`OrderedAddCommGroup`. -/
abbrev AddRightReflectLT [Add M] [LT M] : Prop :=
ContravariantClass M M (swap (· + ·)) (· < ·)
attribute [to_additive existing] MulLeftReflectLT MulRightReflectLT
/-- Typeclass for reverse monotonicity of multiplication on the left,
namely `a * b₁ ≤ a * b₂ → b₁ ≤ b₂`.
You should usually not use this very granular typeclass directly, but rather a typeclass like
`OrderedCancelCommMonoid`. -/
abbrev MulLeftReflectLE [Mul M] [LE M] : Prop :=
ContravariantClass M M (· * ·) (· ≤ ·)
/-- Typeclass for reverse monotonicity of multiplication on the right,
namely `a₁ * b ≤ a₂ * b → a₁ ≤ a₂`.
You should usually not use this very granular typeclass directly, but rather a typeclass like
`OrderedCancelCommMonoid`. -/
abbrev MulRightReflectLE [Mul M] [LE M] : Prop :=
ContravariantClass M M (swap (· * ·)) (· ≤ ·)
/-- Typeclass for reverse monotonicity of addition on the left,
namely `a + b₁ ≤ a + b₂ → b₁ ≤ b₂`.
You should usually not use this very granular typeclass directly, but rather a typeclass like
`OrderedCancelAddCommMonoid`. -/
abbrev AddLeftReflectLE [Add M] [LE M] : Prop :=
ContravariantClass M M (· + ·) (· ≤ ·)
/-- Typeclass for reverse monotonicity of addition on the right,
namely `a₁ + b ≤ a₂ + b → a₁ ≤ a₂`.
You should usually not use this very granular typeclass directly, but rather a typeclass like
`OrderedCancelAddCommMonoid`. -/
abbrev AddRightReflectLE [Add M] [LE M] : Prop :=
ContravariantClass M M (swap (· + ·)) (· ≤ ·)
attribute [to_additive existing] MulLeftReflectLE MulRightReflectLE
instance [Add M] [Preorder M] [i₁ : AddRightMono M] [i₂ : AddRightReflectLE M] :
Lean.Grind.OrderedAdd M where
add_le_left_iff := fun c => ⟨i₁.elim c, i₂.elim c⟩
theorem rel_iff_cov [CovariantClass M N μ r] [ContravariantClass M N μ r] (m : M) {a b : N} :
r (μ m a) (μ m b) ↔ r a b :=
⟨ContravariantClass.elim _, CovariantClass.elim _⟩
section flip
variable {M N μ r}
theorem Covariant.flip (h : Covariant M N μ r) : Covariant M N μ (flip r) :=
fun a _ _ ↦ h a
theorem Contravariant.flip (h : Contravariant M N μ r) : Contravariant M N μ (flip r) :=
fun a _ _ ↦ h a
end flip
section Covariant
variable {M N μ r} [CovariantClass M N μ r]
theorem act_rel_act_of_rel (m : M) {a b : N} (ab : r a b) : r (μ m a) (μ m b) :=
CovariantClass.elim _ ab
@[to_additive]
theorem Group.covariant_iff_contravariant [Group N] :
Covariant N N (· * ·) r ↔ Contravariant N N (· * ·) r := by
refine ⟨fun h a b c bc ↦ ?_, fun h a b c bc ↦ ?_⟩
· rw [← inv_mul_cancel_left a b, ← inv_mul_cancel_left a c]
exact h a⁻¹ bc
· rw [← inv_mul_cancel_left a b, ← inv_mul_cancel_left a c] at bc
exact h a⁻¹ bc
@[to_additive]
instance (priority := 100) Group.covconv [Group N] [CovariantClass N N (· * ·) r] :
ContravariantClass N N (· * ·) r :=
⟨Group.covariant_iff_contravariant.mp CovariantClass.elim⟩
@[to_additive]
theorem Group.mulLeftReflectLE_of_mulLeftMono [Group N] [LE N]
[MulLeftMono N] : MulLeftReflectLE N :=
inferInstance
@[to_additive]
theorem Group.mulLeftReflectLT_of_mulLeftStrictMono [Group N] [LT N]
[MulLeftStrictMono N] : MulLeftReflectLT N :=
inferInstance
@[to_additive]
theorem Group.covariant_swap_iff_contravariant_swap [Group N] :
Covariant N N (swap (· * ·)) r ↔ Contravariant N N (swap (· * ·)) r := by
refine ⟨fun h a b c bc ↦ ?_, fun h a b c bc ↦ ?_⟩
· rw [← mul_inv_cancel_right b a, ← mul_inv_cancel_right c a]
exact h a⁻¹ bc
· rw [← mul_inv_cancel_right b a, ← mul_inv_cancel_right c a] at bc
exact h a⁻¹ bc
@[to_additive]
instance (priority := 100) Group.covconv_swap [Group N] [CovariantClass N N (swap (· * ·)) r] :
ContravariantClass N N (swap (· * ·)) r :=
⟨Group.covariant_swap_iff_contravariant_swap.mp CovariantClass.elim⟩
@[to_additive]
theorem Group.mulRightReflectLE_of_mulRightMono [Group N] [LE N]
[MulRightMono N] : MulRightReflectLE N :=
inferInstance
@[to_additive]
theorem Group.mulRightReflectLT_of_mulRightStrictMono [Group N] [LT N]
[MulRightStrictMono N] : MulRightReflectLT N :=
inferInstance
section Trans
variable [IsTrans N r] (m : M) {a b c : N}
-- Lemmas with 3 elements.
theorem act_rel_of_rel_of_act_rel (ab : r a b) (rl : r (μ m b) c) : r (μ m a) c :=
_root_.trans (act_rel_act_of_rel m ab) rl
theorem rel_act_of_rel_of_rel_act (ab : r a b) (rr : r c (μ m a)) : r c (μ m b) :=
_root_.trans rr (act_rel_act_of_rel _ ab)
end Trans
end Covariant
-- Lemma with 4 elements.
section MEqN
variable {M N μ r} {mu : N → N → N} [IsTrans N r] [i : CovariantClass N N mu r]
[i' : CovariantClass N N (swap mu) r] {a b c d : N}
theorem act_rel_act_of_rel_of_rel (ab : r a b) (cd : r c d) : r (mu a c) (mu b d) :=
_root_.trans (@act_rel_act_of_rel _ _ (swap mu) r _ c _ _ ab) (act_rel_act_of_rel b cd)
end MEqN
section Contravariant
variable {M N μ r} [ContravariantClass M N μ r]
theorem rel_of_act_rel_act (m : M) {a b : N} (ab : r (μ m a) (μ m b)) : r a b :=
ContravariantClass.elim _ ab
section Trans
variable [IsTrans N r] (m : M) {a b c : N}
-- Lemmas with 3 elements.
theorem act_rel_of_act_rel_of_rel_act_rel (ab : r (μ m a) b) (rl : r (μ m b) (μ m c)) :
r (μ m a) c :=
_root_.trans ab (rel_of_act_rel_act m rl)
theorem rel_act_of_act_rel_act_of_rel_act (ab : r (μ m a) (μ m b)) (rr : r b (μ m c)) :
r a (μ m c) :=
_root_.trans (rel_of_act_rel_act m ab) rr
end Trans
end Contravariant
section Monotone
variable {α : Type*} {M N μ} [Preorder α] [Preorder N]
variable {f : N → α}
/-- The partial application of a constant to a covariant operator is monotone. -/
theorem Covariant.monotone_of_const [CovariantClass M N μ (· ≤ ·)] (m : M) : Monotone (μ m) :=
fun _ _ ↦ CovariantClass.elim m
/-- A monotone function remains monotone when composed with the partial application
of a covariant operator. E.g., `∀ (m : ℕ), Monotone f → Monotone (fun n ↦ f (m + n))`. -/
theorem Monotone.covariant_of_const [CovariantClass M N μ (· ≤ ·)] (hf : Monotone f) (m : M) :
Monotone (f <| μ m ·) :=
hf.comp (Covariant.monotone_of_const m)
/-- Same as `Monotone.covariant_of_const`, but with the constant on the other side of
the operator. E.g., `∀ (m : ℕ), Monotone f → Monotone (fun n ↦ f (n + m))`. -/
theorem Monotone.covariant_of_const' {μ : N → N → N} [CovariantClass N N (swap μ) (· ≤ ·)]
(hf : Monotone f) (m : N) : Monotone (f <| μ · m) :=
Monotone.covariant_of_const (μ := swap μ) hf m
/-- Dual of `Monotone.covariant_of_const` -/
theorem Antitone.covariant_of_const [CovariantClass M N μ (· ≤ ·)] (hf : Antitone f) (m : M) :
Antitone (f <| μ m ·) :=
hf.comp_monotone <| Covariant.monotone_of_const m
/-- Dual of `Monotone.covariant_of_const'` -/
theorem Antitone.covariant_of_const' {μ : N → N → N} [CovariantClass N N (swap μ) (· ≤ ·)]
(hf : Antitone f) (m : N) : Antitone (f <| μ · m) :=
Antitone.covariant_of_const (μ := swap μ) hf m
end Monotone
theorem covariant_le_of_covariant_lt [PartialOrder N] :
Covariant M N μ (· < ·) → Covariant M N μ (· ≤ ·) := by
intro h a b c bc
rcases bc.eq_or_lt with (rfl | bc)
· exact le_rfl
· exact (h _ bc).le
theorem covariantClass_le_of_lt [PartialOrder N] [CovariantClass M N μ (· < ·)] :
CovariantClass M N μ (· ≤ ·) := ⟨covariant_le_of_covariant_lt _ _ _ CovariantClass.elim⟩
@[to_additive]
theorem mulLeftMono_of_mulLeftStrictMono (M) [Mul M] [PartialOrder M] [MulLeftStrictMono M] :
MulLeftMono M := covariantClass_le_of_lt _ _ _
@[to_additive]
theorem mulRightMono_of_mulRightStrictMono (M) [Mul M] [PartialOrder M] [MulRightStrictMono M] :
MulRightMono M := covariantClass_le_of_lt _ _ _
theorem contravariant_le_iff_contravariant_lt_and_eq [PartialOrder N] :
Contravariant M N μ (· ≤ ·) ↔ Contravariant M N μ (· < ·) ∧ Contravariant M N μ (· = ·) := by
refine ⟨fun h ↦ ⟨fun a b c bc ↦ ?_, fun a b c bc ↦ ?_⟩, fun h ↦ fun a b c bc ↦ ?_⟩
· exact (h a bc.le).lt_of_ne (by rintro rfl; exact lt_irrefl _ bc)
· exact (h a bc.le).antisymm (h a bc.ge)
· exact bc.lt_or_eq.elim (fun bc ↦ (h.1 a bc).le) (fun bc ↦ (h.2 a bc).le)
theorem contravariant_lt_of_contravariant_le [PartialOrder N] :
Contravariant M N μ (· ≤ ·) → Contravariant M N μ (· < ·) :=
And.left ∘ (contravariant_le_iff_contravariant_lt_and_eq M N μ).mp
theorem covariant_le_iff_contravariant_lt [LinearOrder N] :
Covariant M N μ (· ≤ ·) ↔ Contravariant M N μ (· < ·) :=
⟨fun h _ _ _ bc ↦ not_le.mp fun k ↦ bc.not_ge (h _ k),
fun h _ _ _ bc ↦ not_lt.mp fun k ↦ bc.not_gt (h _ k)⟩
theorem covariant_lt_iff_contravariant_le [LinearOrder N] :
Covariant M N μ (· < ·) ↔ Contravariant M N μ (· ≤ ·) :=
⟨fun h _ _ _ bc ↦ not_lt.mp fun k ↦ bc.not_gt (h _ k),
fun h _ _ _ bc ↦ not_le.mp fun k ↦ bc.not_ge (h _ k)⟩
variable (mu : N → N → N)
theorem covariant_flip_iff [h : Std.Commutative mu] :
Covariant N N (flip mu) r ↔ Covariant N N mu r := by unfold flip; simp_rw [h.comm]
theorem contravariant_flip_iff [h : Std.Commutative mu] :
Contravariant N N (flip mu) r ↔ Contravariant N N mu r := by unfold flip; simp_rw [h.comm]
instance contravariant_lt_of_covariant_le [LinearOrder N]
[CovariantClass N N mu (· ≤ ·)] : ContravariantClass N N mu (· < ·) where
elim := (covariant_le_iff_contravariant_lt N N mu).mp CovariantClass.elim
@[to_additive]
theorem mulLeftReflectLT_of_mulLeftMono [Mul N] [LinearOrder N] [MulLeftMono N] :
MulLeftReflectLT N :=
inferInstance
@[to_additive]
theorem mulRightReflectLT_of_mulRightMono [Mul N] [LinearOrder N] [MulRightMono N] :
MulRightReflectLT N :=
inferInstance
instance covariant_lt_of_contravariant_le [LinearOrder N]
[ContravariantClass N N mu (· ≤ ·)] : CovariantClass N N mu (· < ·) where
elim := (covariant_lt_iff_contravariant_le N N mu).mpr ContravariantClass.elim
@[to_additive]
theorem mulLeftStrictMono_of_mulLeftReflectLE [Mul N] [LinearOrder N] [MulLeftReflectLE N] :
MulLeftStrictMono N :=
inferInstance
@[to_additive]
theorem mulRightStrictMono_of_mulRightReflectLE [Mul N] [LinearOrder N] [MulRightReflectLE N] :
MulRightStrictMono N :=
inferInstance
@[to_additive]
instance covariant_swap_mul_of_covariant_mul [CommSemigroup N]
[CovariantClass N N (· * ·) r] : CovariantClass N N (swap (· * ·)) r where
elim := (covariant_flip_iff N r (· * ·)).mpr CovariantClass.elim
@[to_additive]
theorem mulRightMono_of_mulLeftMono [CommSemigroup N] [LE N] [MulLeftMono N] :
MulRightMono N :=
inferInstance
@[to_additive]
theorem mulRightStrictMono_of_mulLeftStrictMono [CommSemigroup N] [LT N] [MulLeftStrictMono N] :
MulRightStrictMono N :=
inferInstance
@[to_additive]
instance contravariant_swap_mul_of_contravariant_mul [CommSemigroup N]
[ContravariantClass N N (· * ·) r] : ContravariantClass N N (swap (· * ·)) r where
elim := (contravariant_flip_iff N r (· * ·)).mpr ContravariantClass.elim
@[to_additive]
theorem mulRightReflectLE_of_mulLeftReflectLE [CommSemigroup N] [LE N] [MulLeftReflectLE N] :
MulRightReflectLE N :=
inferInstance
@[to_additive]
theorem mulRightReflectLT_of_mulLeftReflectLT [CommSemigroup N] [LT N] [MulLeftReflectLT N] :
MulRightReflectLT N :=
inferInstance
theorem covariant_lt_of_covariant_le_of_contravariant_eq [ContravariantClass M N μ (· = ·)]
[PartialOrder N] [CovariantClass M N μ (· ≤ ·)] : CovariantClass M N μ (· < ·) where
elim a _ _ bc := (CovariantClass.elim a bc.le).lt_of_ne (bc.ne ∘ ContravariantClass.elim _)
theorem contravariant_le_of_contravariant_eq_and_lt [PartialOrder N]
[ContravariantClass M N μ (· = ·)] [ContravariantClass M N μ (· < ·)] :
ContravariantClass M N μ (· ≤ ·) where
elim := (contravariant_le_iff_contravariant_lt_and_eq M N μ).mpr
⟨ContravariantClass.elim, ContravariantClass.elim⟩
/- TODO:
redefine `IsLeftCancel N mu` as abbrev of `ContravariantClass N N mu (· = ·)`,
redefine `IsRightCancel N mu` as abbrev of `ContravariantClass N N (flip mu) (· = ·)`,
redefine `IsLeftCancelMul` as abbrev of `IsLeftCancel`,
then the following four instances (actually eight) can be removed in favor of the above two. -/
@[to_additive]
instance IsLeftCancelMul.mulLeftStrictMono_of_mulLeftMono [Mul N] [IsLeftCancelMul N]
[PartialOrder N] [MulLeftMono N] :
MulLeftStrictMono N where
elim a _ _ bc := (CovariantClass.elim a bc.le).lt_of_ne ((mul_ne_mul_right a).mpr bc.ne)
@[to_additive]
instance IsRightCancelMul.mulRightStrictMono_of_mulRightMono
[Mul N] [IsRightCancelMul N] [PartialOrder N] [MulRightMono N] :
MulRightStrictMono N where
elim a _ _ bc := (CovariantClass.elim a bc.le).lt_of_ne ((mul_ne_mul_left a).mpr bc.ne)
@[to_additive]
instance IsLeftCancelMul.mulLeftReflectLE_of_mulLeftReflectLT [Mul N] [IsLeftCancelMul N]
[PartialOrder N] [MulLeftReflectLT N] :
MulLeftReflectLE N where
elim := (contravariant_le_iff_contravariant_lt_and_eq N N _).mpr
⟨ContravariantClass.elim, fun _ ↦ mul_left_cancel⟩
@[to_additive]
instance IsRightCancelMul.mulRightReflectLE_of_mulRightReflectLT
[Mul N] [IsRightCancelMul N] [PartialOrder N] [MulRightReflectLT N] :
MulRightReflectLE N where
elim := (contravariant_le_iff_contravariant_lt_and_eq N N _).mpr
⟨ContravariantClass.elim, fun _ ↦ mul_right_cancel⟩
end Variants |
.lake/packages/mathlib/Mathlib/Algebra/Order/Monoid/Unbundled/TypeTags.lean | import Mathlib.Algebra.Order.Monoid.Unbundled.ExistsOfLE
import Mathlib.Algebra.Group.TypeTags.Basic
import Mathlib.Order.BoundedOrder.Basic
/-! # Ordered monoid structures on `Multiplicative α` and `Additive α`. -/
variable {α : Type*}
instance : ∀ [LE α], LE (Multiplicative α) :=
fun {inst} => inst
instance : ∀ [LE α], LE (Additive α) :=
fun {inst} => inst
instance : ∀ [LT α], LT (Multiplicative α) :=
fun {inst} => inst
instance : ∀ [LT α], LT (Additive α) :=
fun {inst} => inst
instance Multiplicative.preorder : ∀ [Preorder α], Preorder (Multiplicative α) :=
fun {inst} => inst
instance Additive.preorder : ∀ [Preorder α], Preorder (Additive α) :=
fun {inst} => inst
instance Multiplicative.partialOrder : ∀ [PartialOrder α], PartialOrder (Multiplicative α) :=
fun {inst} => inst
instance Additive.partialOrder : ∀ [PartialOrder α], PartialOrder (Additive α) :=
fun {inst} => inst
instance Multiplicative.linearOrder : ∀ [LinearOrder α], LinearOrder (Multiplicative α) :=
fun {inst} => inst
instance Additive.linearOrder : ∀ [LinearOrder α], LinearOrder (Additive α) :=
fun {inst} => inst
instance Multiplicative.orderBot [LE α] : ∀ [OrderBot α], OrderBot (Multiplicative α) :=
fun {inst} => inst
instance Additive.orderBot [LE α] : ∀ [OrderBot α], OrderBot (Additive α) :=
fun {inst} => inst
instance Multiplicative.orderTop [LE α] : ∀ [OrderTop α], OrderTop (Multiplicative α) :=
fun {inst} => inst
instance Additive.orderTop [LE α] : ∀ [OrderTop α], OrderTop (Additive α) :=
fun {inst} => inst
instance Multiplicative.boundedOrder [LE α] : ∀ [BoundedOrder α], BoundedOrder (Multiplicative α) :=
fun {inst} => inst
instance Additive.boundedOrder [LE α] : ∀ [BoundedOrder α], BoundedOrder (Additive α) :=
fun {inst} => inst
instance Multiplicative.existsMulOfLe [Add α] [LE α] [ExistsAddOfLE α] :
ExistsMulOfLE (Multiplicative α) :=
⟨@exists_add_of_le α _ _ _⟩
instance Additive.existsAddOfLe [Mul α] [LE α] [ExistsMulOfLE α] : ExistsAddOfLE (Additive α) :=
⟨@exists_mul_of_le α _ _ _⟩
namespace Additive
variable [Preorder α]
@[simp]
theorem ofMul_le {a b : α} : ofMul a ≤ ofMul b ↔ a ≤ b :=
Iff.rfl
@[simp]
theorem ofMul_lt {a b : α} : ofMul a < ofMul b ↔ a < b :=
Iff.rfl
@[simp]
theorem toMul_le {a b : Additive α} : a.toMul ≤ b.toMul ↔ a ≤ b :=
Iff.rfl
@[simp]
theorem toMul_lt {a b : Additive α} : a.toMul < b.toMul ↔ a < b :=
Iff.rfl
@[gcongr] alias ⟨_, toMul_mono⟩ := toMul_le
@[gcongr] alias ⟨_, ofMul_mono⟩ := ofMul_le
@[gcongr] alias ⟨_, toMul_strictMono⟩ := toMul_lt
@[gcongr] alias ⟨_, foMul_strictMono⟩ := ofMul_lt
end Additive
namespace Multiplicative
variable [Preorder α]
@[simp]
theorem ofAdd_le {a b : α} : ofAdd a ≤ ofAdd b ↔ a ≤ b :=
Iff.rfl
@[simp]
theorem ofAdd_lt {a b : α} : ofAdd a < ofAdd b ↔ a < b :=
Iff.rfl
@[simp]
theorem toAdd_le {a b : Multiplicative α} : a.toAdd ≤ b.toAdd ↔ a ≤ b :=
Iff.rfl
@[simp]
theorem toAdd_lt {a b : Multiplicative α} : a.toAdd < b.toAdd ↔ a < b :=
Iff.rfl
@[gcongr] alias ⟨_, toAdd_mono⟩ := toAdd_le
@[gcongr] alias ⟨_, ofAdd_mono⟩ := ofAdd_le
@[gcongr] alias ⟨_, toAdd_strictMono⟩ := toAdd_lt
@[gcongr] alias ⟨_, ofAdd_strictMono⟩ := ofAdd_lt
end Multiplicative |
.lake/packages/mathlib/Mathlib/Algebra/Order/Monoid/Unbundled/ExistsOfLE.lean | import Mathlib.Algebra.Order.Monoid.Unbundled.Basic
import Mathlib.Order.MinMax
/-!
# Unbundled and weaker forms of canonically ordered monoids
This file provides a Prop-valued mixin for monoids satisfying a one-sided cancellativity property,
namely that there is some `c` such that `b = a + c` if `a ≤ b`. This is particularly useful for
generalising statements from groups/rings/fields that don't mention negation or subtraction to
monoids/semirings/semifields.
-/
universe u
variable {α : Type u}
/-- An `OrderedAddCommMonoid` with one-sided 'subtraction' in the sense that
if `a ≤ b`, then there is some `c` for which `a + c = b`. This is a weaker version
of the condition on canonical orderings defined by `CanonicallyOrderedAddCommMonoid`. -/
class ExistsAddOfLE (α : Type u) [Add α] [LE α] : Prop where
/-- For `a ≤ b`, there is a `c` so `b = a + c`. -/
exists_add_of_le : ∀ {a b : α}, a ≤ b → ∃ c : α, b = a + c
/-- An `OrderedCommMonoid` with one-sided 'division' in the sense that
if `a ≤ b`, there is some `c` for which `a * c = b`. This is a weaker version
of the condition on canonical orderings defined by `CanonicallyOrderedCommMonoid`. -/
@[to_additive]
class ExistsMulOfLE (α : Type u) [Mul α] [LE α] : Prop where
/-- For `a ≤ b`, `a` left divides `b` -/
exists_mul_of_le : ∀ {a b : α}, a ≤ b → ∃ c : α, b = a * c
export ExistsMulOfLE (exists_mul_of_le)
export ExistsAddOfLE (exists_add_of_le)
-- See note [lower instance priority]
@[to_additive]
instance (priority := 100) Group.existsMulOfLE (α : Type u) [Group α] [LE α] : ExistsMulOfLE α :=
⟨fun {a b} _ => ⟨a⁻¹ * b, (mul_inv_cancel_left _ _).symm⟩⟩
section MulOneClass
variable [MulOneClass α] [Preorder α] [ExistsMulOfLE α] {a b : α}
@[to_additive] lemma exists_one_le_mul_of_le [MulLeftReflectLE α] (h : a ≤ b) :
∃ c, 1 ≤ c ∧ a * c = b := by
obtain ⟨c, rfl⟩ := exists_mul_of_le h; exact ⟨c, one_le_of_le_mul_right h, rfl⟩
@[to_additive] lemma exists_one_lt_mul_of_lt' [MulLeftReflectLT α] (h : a < b) :
∃ c, 1 < c ∧ a * c = b := by
obtain ⟨c, rfl⟩ := exists_mul_of_le h.le; exact ⟨c, one_lt_of_lt_mul_right h, rfl⟩
@[to_additive] lemma le_iff_exists_one_le_mul [MulLeftMono α]
[MulLeftReflectLE α] : a ≤ b ↔ ∃ c, 1 ≤ c ∧ a * c = b :=
⟨exists_one_le_mul_of_le, by rintro ⟨c, hc, rfl⟩; exact le_mul_of_one_le_right' hc⟩
@[to_additive] lemma lt_iff_exists_one_lt_mul [MulLeftStrictMono α]
[MulLeftReflectLT α] : a < b ↔ ∃ c, 1 < c ∧ a * c = b :=
⟨exists_one_lt_mul_of_lt', by rintro ⟨c, hc, rfl⟩; exact lt_mul_of_one_lt_right' _ hc⟩
end MulOneClass
section ExistsMulOfLE
variable [LinearOrder α] [DenselyOrdered α] [Monoid α] [ExistsMulOfLE α]
[MulLeftReflectLT α] {a b : α}
@[to_additive]
theorem le_of_forall_one_lt_le_mul (h : ∀ ε : α, 1 < ε → a ≤ b * ε) : a ≤ b :=
le_of_forall_gt_imp_ge_of_dense fun x hxb => by
obtain ⟨ε, rfl⟩ := exists_mul_of_le hxb.le
exact h _ (one_lt_of_lt_mul_right hxb)
@[to_additive]
theorem le_of_forall_one_lt_lt_mul' (h : ∀ ε : α, 1 < ε → a < b * ε) : a ≤ b :=
le_of_forall_one_lt_le_mul fun ε hε => (h ε hε).le
@[to_additive]
theorem le_iff_forall_one_lt_lt_mul' [MulLeftStrictMono α] :
a ≤ b ↔ ∀ ε, 1 < ε → a < b * ε :=
⟨fun h _ => lt_mul_of_le_of_one_lt h, le_of_forall_one_lt_lt_mul'⟩
@[to_additive]
theorem le_iff_forall_one_lt_le_mul [MulLeftStrictMono α] :
a ≤ b ↔ ∀ ε, 1 < ε → a ≤ b * ε :=
⟨fun h _ hε ↦ lt_mul_of_le_of_one_lt h hε |>.le, le_of_forall_one_lt_le_mul⟩
end ExistsMulOfLE |
.lake/packages/mathlib/Mathlib/Algebra/Order/Monoid/Unbundled/Units.lean | import Mathlib.Algebra.Group.Units.Basic
import Mathlib.Algebra.Order.Monoid.Unbundled.Basic
/-!
# Lemmas for units in an ordered monoid
-/
variable {M : Type*} [Monoid M] [LE M]
namespace Units
section MulLeftMono
variable [MulLeftMono M] (u : Mˣ) {a b : M}
theorem mulLECancellable_val : MulLECancellable (↑u : M) := fun _ _ h ↦ by
simpa using mul_le_mul_left' h ↑u⁻¹
private theorem mul_le_mul_iff_left : u * a ≤ u * b ↔ a ≤ b :=
u.mulLECancellable_val.mul_le_mul_iff_left
theorem inv_mul_le_iff : u⁻¹ * a ≤ b ↔ a ≤ u * b := by
rw [← u.mul_le_mul_iff_left, mul_inv_cancel_left]
theorem le_inv_mul_iff : a ≤ u⁻¹ * b ↔ u * a ≤ b := by
rw [← u.mul_le_mul_iff_left, mul_inv_cancel_left]
@[simp] theorem one_le_inv : (1 : M) ≤ u⁻¹ ↔ (u : M) ≤ 1 := by
rw [← u.mul_le_mul_iff_left, mul_one, mul_inv]
@[simp] theorem inv_le_one : u⁻¹ ≤ (1 : M) ↔ (1 : M) ≤ u := by
rw [← u.mul_le_mul_iff_left, mul_one, mul_inv]
theorem one_le_inv_mul : 1 ≤ u⁻¹ * a ↔ u ≤ a := by
rw [u.le_inv_mul_iff, mul_one]
theorem inv_mul_le_one : u⁻¹ * a ≤ 1 ↔ a ≤ u := by
rw [u.inv_mul_le_iff, mul_one]
alias ⟨le_mul_of_inv_mul_le, inv_mul_le_of_le_mul⟩ := inv_mul_le_iff
alias ⟨mul_le_of_le_inv_mul, le_inv_mul_of_mul_le⟩ := le_inv_mul_iff
alias ⟨le_of_one_le_inv, one_le_inv_of_le⟩ := one_le_inv
alias ⟨le_of_inv_le_one, inv_le_one_of_le⟩ := inv_le_one
alias ⟨le_of_one_le_inv_mul, one_le_inv_mul_of_le⟩ := one_le_inv_mul
alias ⟨le_of_inv_mul_le_one, inv_mul_le_one_of_le⟩ := inv_mul_le_one
end MulLeftMono
section MulRightMono
variable [MulRightMono M] {a b : M} (u : Mˣ)
private theorem mul_le_mul_iff_right : a * u ≤ b * u ↔ a ≤ b :=
⟨(by simpa using mul_le_mul_right' · ↑u⁻¹), (mul_le_mul_right' · _)⟩
theorem mul_inv_le_iff : a * u⁻¹ ≤ b ↔ a ≤ b * u := by
rw [← u.mul_le_mul_iff_right, u.inv_mul_cancel_right]
theorem le_mul_inv_iff : a ≤ b * u⁻¹ ↔ a * u ≤ b := by
rw [← u.mul_le_mul_iff_right, inv_mul_cancel_right]
theorem one_le_mul_inv : 1 ≤ a * u⁻¹ ↔ u ≤ a := by
rw [u.le_mul_inv_iff, one_mul]
theorem mul_inv_le_one : a * u⁻¹ ≤ 1 ↔ a ≤ u := by
rw [u.mul_inv_le_iff, one_mul]
alias ⟨le_mul_of_mul_inv_le, mul_inv_le_of_le_mul⟩ := mul_inv_le_iff
alias ⟨mul_le_of_le_mul_inv, le_mul_inv_of_mul_le⟩ := le_mul_inv_iff
alias ⟨le_of_one_le_mul_inv, one_le_mul_inv_of_le⟩ := one_le_mul_inv
alias ⟨le_of_mul_inv_le_one, mul_inv_le_one_of_le⟩ := mul_inv_le_one
end MulRightMono
end Units
namespace IsUnit
section MulLeftMono
variable [MulLeftMono M] {a b c : M} (ha : IsUnit a)
include ha
theorem mulLECancellable : MulLECancellable a :=
ha.unit.mulLECancellable_val
theorem mul_le_mul_left : a * b ≤ a * c ↔ b ≤ c :=
ha.unit.mul_le_mul_iff_left
alias ⟨le_of_mul_le_mul_left, _⟩ := mul_le_mul_left
end MulLeftMono
section MulRightMono
variable [MulRightMono M] {a b c : M} (hc : IsUnit c)
include hc
theorem mul_le_mul_right : a * c ≤ b * c ↔ a ≤ b :=
hc.unit.mul_le_mul_iff_right
alias ⟨le_of_mul_le_mul_right, _⟩ := mul_le_mul_right
end MulRightMono
end IsUnit |
.lake/packages/mathlib/Mathlib/Algebra/Order/Archimedean/Class.lean | import Mathlib.Algebra.BigOperators.Group.Finset.Basic
import Mathlib.Algebra.Group.Subgroup.Lattice
import Mathlib.Algebra.Order.Archimedean.Basic
import Mathlib.Algebra.Order.Hom.Monoid
import Mathlib.Data.Finset.Max
import Mathlib.Order.Antisymmetrization
import Mathlib.Order.Hom.WithTopBot
import Mathlib.Order.UpperLower.CompleteLattice
import Mathlib.Order.UpperLower.Principal
/-!
# Archimedean classes of a linearly ordered group
This file defines archimedean classes of a given linearly ordered group. Archimedean classes
measure to what extent the group fails to be Archimedean. For additive group, elements `a` and `b`
in the same class are "equivalent" in the sense that there exist two natural numbers
`m` and `n` such that `|a| ≤ m • |b|` and `|b| ≤ n • |a|`. An element `a` in a higher class than `b`
is "infinitesimal" to `b` in the sense that `n • |a| < |b|` for all natural number `n`.
## Main definitions
* `ArchimedeanClass` is the archimedean class for additive linearly ordered group.
* `MulArchimedeanClass` is the archimedean class for multiplicative linearly ordered group.
* `ArchimedeanClass.orderHom` and `MulArchimedeanClass.orderHom` are `OrderHom` over
archimedean classes lifted from ordered group homomorphisms.
* `ArchimedeanClass.ballAddSubgroup` and `MulArchimedeanClass.ballSubgroup` are subgroups
formed by an open interval of archimedean classes
* `ArchimedeanClass.closedBallAddSubgroup` and `MulArchimedeanClass.closedBallSubgroup` are
subgroups formed by a closed interval of archimedean classes.
## Main statements
The following theorems state that an ordered commutative group is (mul-)archimedean if and only if
all non-identity elements belong to the same (`Mul`-)`ArchimedeanClass`:
* `ArchimedeanClass.archimedean_of_mk_eq_mk` / `MulArchimedeanClass.mulArchimedean_of_mk_eq_mk`
* `ArchimedeanClass.mk_eq_mk_of_archimedean` / `MulArchimedeanClass.mk_eq_mk_of_mulArchimedean`
## Implementation notes
Archimedean classes are equipped with a linear order, where elements with smaller absolute value
are placed in a *higher* classes by convention. Ordering backwards this way simplifies
formalization of theorems such as the Hahn embedding theorem.
To naturally derive this order, we first define it on the underlying group via the type
synonym (`Mul`-)`ArchimedeanOrder`, and define (`Mul`-)`ArchimedeanClass` as `Antisymmetrization` of
the order.
-/
section ArchimedeanOrder
variable {M : Type*}
variable (M) in
/-- Type synonym to equip a ordered group with a new `Preorder` defined by the infinitesimal order
of elements. `a` is said less than `b` if `b` is infinitesimal comparing to `a`, or more precisely,
`∀ n, |b|ₘ ^ n < |a|ₘ`. If `a` and `b` are neither infinitesimal to each other, they are equivalent
in this order. -/
@[to_additive ArchimedeanOrder
/-- Type synonym to equip a ordered group with a new `Preorder` defined by the infinitesimal order
of elements. `a` is said less than `b` if `b` is infinitesimal comparing to `a`, or more precisely,
`∀ n, n • |b| < |a|`. If `a` and `b` are neither infinitesimal to each other, they are equivalent
in this order. -/]
def MulArchimedeanOrder := M
namespace MulArchimedeanOrder
/-- Create a `MulArchimedeanOrder` element from the underlying type. -/
@[to_additive /-- Create a `ArchimedeanOrder` element from the underlying type. -/]
def of : M ≃ MulArchimedeanOrder M := Equiv.refl _
/-- Retrieve the underlying value from a `MulArchimedeanOrder` element. -/
@[to_additive /-- Retrieve the underlying value from a `ArchimedeanOrder` element. -/]
def val : MulArchimedeanOrder M ≃ M := Equiv.refl _
@[to_additive (attr := simp)]
theorem of_symm_eq : (of (M := M)).symm = val := rfl
@[to_additive (attr := simp)]
theorem val_symm_eq : (val (M := M)).symm = of := rfl
@[to_additive (attr := simp)]
theorem of_val (a : MulArchimedeanOrder M) : of (val a) = a := rfl
@[to_additive (attr := simp)]
theorem val_of (a : M) : val (of a) = a := rfl
@[to_additive]
instance [Nonempty M] : Nonempty (MulArchimedeanOrder M) :=
inferInstanceAs (Nonempty M)
@[to_additive]
instance [Inhabited M] : Inhabited (MulArchimedeanOrder M) :=
⟨of default⟩
@[to_additive]
instance [Subsingleton M] : Subsingleton (MulArchimedeanOrder M) :=
inferInstanceAs (Subsingleton M)
variable [Group M] [Lattice M]
@[to_additive]
instance : LE (MulArchimedeanOrder M) where
le a b := ∃ n, |b.val|ₘ ≤ |a.val|ₘ ^ n
@[to_additive]
instance : LT (MulArchimedeanOrder M) where
lt a b := ∀ n, |b.val|ₘ ^ n < |a.val|ₘ
@[to_additive]
theorem le_def {a b : MulArchimedeanOrder M} : a ≤ b ↔ ∃ n, |b.val|ₘ ≤ |a.val|ₘ ^ n := .rfl
@[to_additive]
theorem lt_def {a b : MulArchimedeanOrder M} : a < b ↔ ∀ n, |b.val|ₘ ^ n < |a.val|ₘ := .rfl
variable {M : Type*}
variable [CommGroup M] [LinearOrder M] [IsOrderedMonoid M] {a b : M}
@[to_additive]
instance : Preorder (MulArchimedeanOrder M) where
le_refl a := ⟨1, by simp⟩
le_trans a b c := by
intro ⟨m, hm⟩ ⟨n, hn⟩
use m * n
rw [pow_mul]
exact hn.trans (pow_le_pow_left' hm n)
lt_iff_le_not_ge a b := by
rw [lt_def, le_def, le_def]
suffices (∀ (n : ℕ), |b.val|ₘ ^ n < |a.val|ₘ) → ∃ n, |b.val|ₘ ≤ |a.val|ₘ ^ n by
simpa using this
intro h
obtain h := (h 1).le
exact ⟨1, by simpa using h⟩
@[to_additive]
instance : IsTotal (MulArchimedeanOrder M) (· ≤ ·) where
total a b := by
obtain hab | hab := le_total |a.val|ₘ |b.val|ₘ
· exact .inr ⟨1, by simpa using hab⟩
· exact .inl ⟨1, by simpa using hab⟩
variable {N : Type*} [CommGroup N] [LinearOrder N] [IsOrderedMonoid N]
/-- An `OrderMonoidHom` can be made to an `OrderHom` between their `MulArchimedeanOrder`. -/
@[to_additive /-- An `OrderAddMonoidHom` can be made to an `OrderHom` between their
`ArchimedeanOrder`. -/]
noncomputable
def orderHom (f : M →*o N) : MulArchimedeanOrder M →o MulArchimedeanOrder N where
toFun a := of (f a.val)
monotone' := by
rintro a b ⟨n, hn⟩
simp_rw [le_def, val_of, ← map_mabs, ← map_pow]
exact ⟨n, OrderHomClass.monotone f hn⟩
end MulArchimedeanOrder
end ArchimedeanOrder
variable {M : Type*}
variable [CommGroup M] [LinearOrder M] [IsOrderedMonoid M] {a b : M}
variable (M) in
/-- `MulArchimedeanClass M` is the quotient of the group `M` by multiplicative archimedean
equivalence, where two elements `a` and `b` are in the same class iff
`(∃ m : ℕ, |b|ₘ ≤ |a|ₘ ^ m) ∧ (∃ n : ℕ, |a|ₘ ≤ |b|ₘ ^ n)`. -/
@[to_additive ArchimedeanClass
/-- `ArchimedeanClass M` is the quotient of the additive group `M` by additive archimedean
equivalence, where two elements `a` and `b` are in the same class iff
`(∃ m : ℕ, |b| ≤ m • |a|) ∧ (∃ n : ℕ, |a| ≤ n • |b|)`. -/]
def MulArchimedeanClass := Antisymmetrization (MulArchimedeanOrder M) (· ≤ ·)
namespace MulArchimedeanClass
/-- The archimedean class of a given element. -/
@[to_additive /-- The archimedean class of a given element. -/]
def mk (a : M) : MulArchimedeanClass M := toAntisymmetrization _ (MulArchimedeanOrder.of a)
/-- An induction principle for `MulArchimedeanClass`. -/
@[to_additive (attr := elab_as_elim, induction_eliminator)
/-- An induction principle for `ArchimedeanClass` -/]
theorem ind {motive : MulArchimedeanClass M → Prop} (mk : ∀ a, motive (.mk a)) : ∀ x, motive x :=
Antisymmetrization.ind _ mk
@[to_additive]
theorem «forall» {p : MulArchimedeanClass M → Prop} : (∀ A, p A) ↔ ∀ a, p (mk a) := Quotient.forall
variable (M) in
@[to_additive]
theorem mk_surjective : Function.Surjective <| mk (M := M) := Quotient.mk_surjective
variable (M) in
@[to_additive (attr := simp)]
theorem range_mk : Set.range (mk (M := M)) = Set.univ := Set.range_eq_univ.mpr (mk_surjective M)
@[to_additive]
theorem mk_eq_mk {a b : M} : mk a = mk b ↔ (∃ m, |b|ₘ ≤ |a|ₘ ^ m) ∧ (∃ n, |a|ₘ ≤ |b|ₘ ^ n) := by
unfold mk toAntisymmetrization
rw [Quotient.eq]
rfl
/-- Lift a `M → α` function to `MulArchimedeanClass M → α`. -/
@[to_additive /-- Lift a `M → α` function to `ArchimedeanClass M → α`. -/]
def lift {α : Type*} (f : M → α) (h : ∀ a b, mk a = mk b → f a = f b) :
MulArchimedeanClass M → α :=
Quotient.lift f fun _ _ h' ↦ h _ _ <| mk_eq_mk.mpr h'
@[to_additive (attr := simp)]
theorem lift_mk {α : Type*} (f : M → α) (h : ∀ a b, mk a = mk b → f a = f b)
(a : M) : lift f h (mk a) = f a := by
unfold lift
exact Quotient.lift_mk f (fun _ _ h' ↦ h _ _ <| mk_eq_mk.mpr h') a
/-- Lift a `M → M → α` function to `MulArchimedeanClass M → MulArchimedeanClass M → α`. -/
@[to_additive /-- Lift a `M → M → α` function to `ArchimedeanClass M → ArchimedeanClass M → α`. -/]
def lift₂ {α : Type*} (f : M → M → α)
(h : ∀ a₁ b₁ a₂ b₂, mk a₁ = mk b₁ → mk a₂ = mk b₂ → f a₁ a₂ = f b₁ b₂) :
MulArchimedeanClass M → MulArchimedeanClass M → α :=
Quotient.lift₂ f fun _ _ _ _ h₁ h₂ ↦ h _ _ _ _ (mk_eq_mk.mpr h₁) (mk_eq_mk.mpr h₂)
@[to_additive (attr := simp)]
theorem lift₂_mk {α : Type*} (f : M → M → α)
(h : ∀ a₁ b₁ a₂ b₂, mk a₁ = mk b₁ → mk a₂ = mk b₂ → f a₁ a₂ = f b₁ b₂)
(a b : M) : lift₂ f h (mk a) (mk b) = f a b := by
unfold lift₂
exact Quotient.lift₂_mk f (fun _ _ _ _ h₁ h₂ ↦ h _ _ _ _ (mk_eq_mk.mpr h₁) (mk_eq_mk.mpr h₂)) a b
/-- Choose a representative element from a given archimedean class. -/
@[to_additive /-- Choose a representative element from a given archimedean class. -/]
noncomputable
def out (A : MulArchimedeanClass M) : M := (Quotient.out A).val
@[to_additive (attr := simp)]
theorem mk_out (A : MulArchimedeanClass M) : mk A.out = A := Quotient.out_eq' A
@[to_additive (attr := simp)]
theorem mk_inv (a : M) : mk a⁻¹ = mk a :=
mk_eq_mk.mpr ⟨⟨1, by simp⟩, ⟨1, by simp⟩⟩
@[to_additive]
theorem mk_div_comm (a b : M) : mk (a / b) = mk (b / a) := by
rw [← mk_inv, inv_div]
@[to_additive (attr := simp)]
theorem mk_mabs (a : M) : mk |a|ₘ = mk a :=
mk_eq_mk.mpr ⟨⟨1, by simp⟩, ⟨1, by simp⟩⟩
@[to_additive]
instance [Subsingleton M] : Subsingleton (MulArchimedeanClass M) :=
inferInstanceAs (Subsingleton (Antisymmetrization ..))
@[to_additive]
noncomputable
instance : LinearOrder (MulArchimedeanClass M) := by
classical
unfold MulArchimedeanClass
infer_instance
@[to_additive]
theorem mk_le_mk : mk a ≤ mk b ↔ ∃ n, |b|ₘ ≤ |a|ₘ ^ n := .rfl
@[to_additive]
theorem mk_lt_mk : mk a < mk b ↔ ∀ n, |b|ₘ ^ n < |a|ₘ := .rfl
@[to_additive]
theorem mk_le_mk_iff_lt (ha : a ≠ 1) : mk a ≤ mk b ↔ ∃ n, |b|ₘ < |a|ₘ ^ n := by
refine ⟨fun ⟨n, hn⟩ ↦ ⟨n + 1, hn.trans_lt ?_⟩, fun ⟨n, hn⟩ ↦ ?_⟩
· rw [pow_succ]
exact lt_mul_of_one_lt_right' _ (one_lt_mabs.mpr ha)
· exact ⟨n, hn.le⟩
/-- 1 is in its own class (see `MulArchimedeanClass.mk_eq_top_iff`),
which is also the largest class. -/
@[to_additive /-- 0 is in its own class (see `ArchimedeanClass.mk_eq_top_iff`),
which is also the largest class. -/]
instance : OrderTop (MulArchimedeanClass M) where
top := mk 1
le_top A := by
induction A using ind with | mk a
rw [mk_le_mk]
exact ⟨1, by simp⟩
@[to_additive]
instance : Inhabited (MulArchimedeanClass M) := ⟨⊤⟩
@[to_additive (attr := simp)]
theorem mk_one : mk 1 = (⊤ : MulArchimedeanClass M) := rfl
@[to_additive (attr := simp)]
theorem mk_eq_top_iff : mk a = ⊤ ↔ a = 1 where
mp := by simp [← mk_one, mk_eq_mk]
mpr := by simp_all
@[to_additive (attr := simp)]
theorem top_eq_mk_iff : ⊤ = mk a ↔ a = 1 := by
rw [eq_comm, mk_eq_top_iff]
@[to_additive (attr := simp)]
theorem out_top : (⊤ : MulArchimedeanClass M).out = 1 := by
rw [← mk_eq_top_iff, mk_out]
@[to_additive]
instance [Nontrivial M] : Nontrivial (MulArchimedeanClass M) where
exists_pair_ne := by
obtain ⟨x, hx⟩ := exists_ne (1 : M)
exact ⟨mk x, ⊤, mk_eq_top_iff.ne.mpr hx⟩
@[to_additive]
theorem mk_antitoneOn : AntitoneOn mk (Set.Ici (1 : M)) := by
intro a ha b hb hab
contrapose! hab
rw [mk_lt_mk] at hab
obtain h := hab 1
rw [mabs_eq_self.mpr ha, mabs_eq_self.mpr hb] at h
simpa using h
@[to_additive]
theorem mk_monotoneOn : MonotoneOn mk (Set.Iic (1 : M)) := by
intro a ha b hb hab
contrapose! hab
rw [mk_lt_mk] at hab
obtain h := hab 1
rw [mabs_eq_inv_self.mpr ha, mabs_eq_inv_self.mpr hb] at h
simpa using h
@[to_additive]
theorem min_le_mk_mul (a b : M) : min (mk a) (mk b) ≤ mk (a * b) := by
by_contra! h
rw [lt_min_iff] at h
have h1 := (mk_lt_mk.mp h.1 2).trans_le (mabs_mul_le _ _)
have h2 := (mk_lt_mk.mp h.2 2).trans_le (mabs_mul_le _ _)
simp only [mul_lt_mul_iff_left, mul_lt_mul_iff_right, pow_two] at h1 h2
exact h1.not_gt h2
@[to_additive]
theorem min_le_mk_div (a b : M) : min (mk a) (mk b) ≤ mk (a / b) := by
simpa [div_eq_mul_inv] using min_le_mk_mul (a := a) (b := b⁻¹)
@[to_additive]
theorem mk_left_le_mk_mul (hab : mk a ≤ mk b) : mk a ≤ mk (a * b) := by
simpa [hab] using min_le_mk_mul (a := a) (b := b)
@[to_additive]
theorem mk_right_le_mk_mul (hba : mk b ≤ mk a) : mk b ≤ mk (a * b) := by
simpa [hba] using min_le_mk_mul (a := a) (b := b)
@[to_additive]
theorem mk_left_le_mk_div (hab : mk a ≤ mk b) : mk a ≤ mk (a / b) := by
simpa [div_eq_mul_inv, hab] using mk_left_le_mk_mul (a := a) (b := b⁻¹)
@[to_additive]
theorem mk_right_le_mk_div (hba : mk b ≤ mk a) : mk b ≤ mk (a / b) := by
simpa [div_eq_mul_inv, hba] using mk_right_le_mk_mul (a := a) (b := b⁻¹)
@[to_additive]
theorem mk_mul_eq_mk_left (h : mk a < mk b) : mk (a * b) = mk a := by
refine le_antisymm (mk_le_mk.mpr ⟨2, ?_⟩) (mk_left_le_mk_mul h.le)
rw [mk_lt_mk] at h
apply (mabs_mul' _ b).trans
rw [mul_comm b a, pow_two, mul_le_mul_iff_right]
apply le_of_mul_le_mul_left' (a := |b|ₘ)
rw [mul_comm a b]
exact (pow_two |b|ₘ ▸ (h 2).le).trans (mabs_mul' a b)
@[to_additive]
theorem mk_mul_eq_mk_right (h : mk b < mk a) : mk (a * b) = mk b :=
mul_comm a b ▸ mk_mul_eq_mk_left h
@[to_additive]
theorem mk_div_eq_mk_left (h : mk a < mk b) : mk (a / b) = mk a := by
simpa [h, div_eq_mul_inv] using mk_mul_eq_mk_left (a := a) (b := b⁻¹)
@[to_additive]
theorem mk_div_eq_mk_right (h : mk b < mk a) : mk (a / b) = mk b := by
simpa [h, div_eq_mul_inv] using mk_mul_eq_mk_right (a := a) (b := b⁻¹)
/-- The product over a set of an elements in distinct classes is in the lowest class. -/
@[to_additive /-- The sum over a set of an elements in distinct classes is in the lowest class. -/]
theorem mk_prod {ι : Type*} [LinearOrder ι] {s : Finset ι} (hnonempty : s.Nonempty)
{a : ι → M} :
StrictMonoOn (mk ∘ a) s → mk (∏ i ∈ s, (a i)) = mk (a (s.min' hnonempty)) := by
induction hnonempty using Finset.Nonempty.cons_induction with
| singleton i => simp
| cons i s hi hs ih =>
intro hmono
obtain ih := ih (hmono.mono (by simp))
rw [Finset.prod_cons]
have hminmem : s.min' hs ∈ (Finset.cons i s hi) :=
Finset.mem_cons_of_mem (Finset.min'_mem _ _)
have hne : mk (a i) ≠ mk (a (s.min' hs)) := by
by_contra!
obtain eq := hmono.injOn (by simp) hminmem this
rw [eq] at hi
exact hi (Finset.min'_mem _ hs)
rw [← ih] at hne
obtain hlt|hlt := lt_or_gt_of_ne hne
· rw [mk_mul_eq_mk_left hlt]
congr
apply le_antisymm (Finset.le_min' _ _ _ ?_) (Finset.min'_le _ _ (by simp))
intro y hy
obtain rfl | hmem := Finset.mem_cons.mp hy
· rfl
· refine (lt_of_lt_of_le ?_ (Finset.min'_le _ _ hmem)).le
apply (hmono.lt_iff_lt (by simp) hminmem).mp
rw [ih] at hlt
exact hlt
· rw [mul_comm, mk_mul_eq_mk_left hlt, ih]
congr 2
refine le_antisymm (Finset.le_min' _ _ _ ?_) (Finset.min'_le _ _ hminmem)
intro y hy
obtain rfl | hmem := Finset.mem_cons.mp hy
· apply ((hmono.lt_iff_lt hminmem (by simp)).mp ?_).le
rw [ih] at hlt
exact hlt
· exact Finset.min'_le _ _ hmem
@[to_additive]
theorem lt_of_mk_lt_mk_of_one_le (h : mk a < mk b) (hpos : 1 ≤ a) : b < a := by
obtain h := (mk_lt_mk).mp h 1
rw [pow_one, mabs_lt, mabs_eq_self.mpr hpos] at h
exact h.2
@[to_additive]
theorem lt_of_mk_lt_mk_of_le_one (h : mk a < mk b) (hneg : a ≤ 1) : a < b := by
obtain h := (mk_lt_mk).mp h 1
rw [pow_one, mabs_lt, mabs_eq_inv_self.mpr hneg, inv_inv] at h
exact h.1
@[to_additive]
theorem one_lt_of_one_lt_of_mk_lt (ha : 1 < a) (hab : mk a < mk (b / a)) :
1 < b := by
suffices a⁻¹ < b / a by
simpa using this
apply lt_of_mk_lt_mk_of_le_one
· simpa using hab
· simpa using ha.le
@[to_additive archimedean_of_mk_eq_mk]
theorem mulArchimedean_of_mk_eq_mk (h : ∀ a ≠ (1 : M), ∀ b ≠ 1, mk a = mk b) :
MulArchimedean M where
arch x y hy := by
by_cases! hx : x ≤ 1
· use 0
simpa using hx
· have hxy : mk x = mk y := h x hx.ne.symm y hy.ne.symm
obtain ⟨_, ⟨m, hm⟩⟩ := (mk_eq_mk).mp hxy
rw [mabs_eq_self.mpr hx.le, mabs_eq_self.mpr hy.le] at hm
exact ⟨m, hm⟩
@[to_additive mk_eq_mk_of_archimedean]
theorem mk_eq_mk_of_mulArchimedean [MulArchimedean M] (ha : a ≠ 1) (hb : b ≠ 1) :
mk a = mk b := by
obtain hm := MulArchimedean.arch |b|ₘ (show 1 < |a|ₘ by simpa using ha)
obtain hn := MulArchimedean.arch |a|ₘ (show 1 < |b|ₘ by simpa using hb)
exact mk_eq_mk.mpr ⟨hm, hn⟩
section Hom
variable {N : Type*} [CommGroup N] [LinearOrder N] [IsOrderedMonoid N]
/-- An `OrderMonoidHom` can be lifted to an `OrderHom` over archimedean classes. -/
@[to_additive
/-- An `OrderAddMonoidHom` can be lifted to an `OrderHom` over archimedean classes. -/]
noncomputable
def orderHom (f : M →*o N) : MulArchimedeanClass M →o MulArchimedeanClass N :=
(MulArchimedeanOrder.orderHom f).antisymmetrization
@[to_additive (attr := simp)]
theorem orderHom_mk (f : M →*o N) (a : M) : orderHom f (mk a) = mk (f a) := rfl
@[to_additive]
theorem map_mk_eq (f : M →*o N) (h : mk a = mk b) : mk (f a) = mk (f b) := by
rw [← orderHom_mk, ← orderHom_mk, h]
@[to_additive]
theorem map_mk_le (f : M →*o N) (h : mk a ≤ mk b) : mk (f a) ≤ mk (f b) := by
rw [← orderHom_mk, ← orderHom_mk]
exact OrderHomClass.monotone _ h
@[to_additive]
theorem orderHom_injective {f : M →*o N} (h : Function.Injective f) :
Function.Injective (orderHom f) := by
intro a b
induction a using ind with | mk a
induction b using ind with | mk b
simp_rw [orderHom_mk, mk_eq_mk, ← map_mabs, ← map_pow]
obtain hmono := (OrderHomClass.monotone f).strictMono_of_injective h
intro ⟨⟨m, hm⟩, ⟨n, hn⟩⟩
exact ⟨⟨m, hmono.le_iff_le.mp hm⟩, ⟨n, hmono.le_iff_le.mp hn⟩⟩
@[to_additive (attr := simp)]
theorem orderHom_top (f : M →*o N) : orderHom f ⊤ = ⊤ := by
rw [← mk_one, ← mk_one, orderHom_mk, map_one]
end Hom
section LiftHom
variable {α : Type*} [PartialOrder α]
/-- Lift a function `M → α` that's monotone along archimedean classes to a
monotone function `MulArchimedeanClass M →o α`. -/
@[to_additive /-- Lift a function `M → α` that's monotone along archimedean classes to a
monotone function `ArchimedeanClass M →o α`. -/]
noncomputable
def liftOrderHom (f : M → α) (h : ∀ a b, mk a ≤ mk b → f a ≤ f b) :
MulArchimedeanClass M →o α where
toFun := lift f fun a b heq ↦ le_antisymm (h a b heq.le) (h b a heq.ge)
monotone' A B hle := by
induction A using ind with | mk a
induction B using ind with | mk b
simpa using h a b (mk_le_mk.mp hle)
@[to_additive (attr := simp)]
theorem liftOrderHom_mk (f : M → α) (h : ∀ a b, mk a ≤ mk b → f a ≤ f b) (a : M) :
liftOrderHom f h (mk a) = f a :=
lift_mk f (fun a b heq ↦ le_antisymm (h a b heq.le) (h b a heq.ge)) a
end LiftHom
/-- Given a `UpperSet` of `MulArchimedeanClass`,
all group elements belonging to these classes form a subsemigroup.
This is not yet a subgroup because it doesn't contain the identity if `s = ⊤`. -/
@[to_additive /-- Given a `UpperSet` of `ArchimedeanClass`,
all group elements belonging to these classes form a subsemigroup.
This is not yet a subgroup because it doesn't contain the identity if `s = ⊤`. -/]
def subsemigroup (s : UpperSet (MulArchimedeanClass M)) : Subsemigroup M where
carrier := mk ⁻¹' s
mul_mem' {a b} ha hb := by
rw [Set.mem_preimage] at ha hb ⊢
obtain h | h := min_le_iff.mp (min_le_mk_mul a b)
· exact s.upper h ha
· exact s.upper h hb
/-- Make `MulArchimedeanClass.subsemigroup` a subgroup by assigning
s = ⊤ with a junk value ⊥. -/
@[to_additive /-- Make `ArchimedeanClass.subsemigroup` a subgroup by assigning
s = ⊤ with a junk value ⊥. -/]
noncomputable
def subgroup (s : UpperSet (MulArchimedeanClass M)) : Subgroup M :=
open Classical in
if hs : s = ⊤ then
⊥
else {
subsemigroup s with
one_mem' := by
rw [subsemigroup, Set.mem_preimage]
obtain ⟨u, hu⟩ := UpperSet.coe_nonempty.mpr hs
simpa using s.upper (by simp) hu
inv_mem' := by simp [subsemigroup]
}
variable {s : UpperSet (MulArchimedeanClass M)}
@[to_additive]
theorem subsemigroup_eq_subgroup_of_ne_top (hs : s ≠ ⊤) :
subsemigroup s = (subgroup s : Set M) := by
simp [subgroup, hs]
variable (M) in
@[to_additive (attr := simp)]
theorem subgroup_eq_bot : subgroup (M := M) ⊤ = ⊥ := by
simp [subgroup]
@[to_additive (attr := simp)]
theorem mem_subgroup_iff (hs : s ≠ ⊤) : a ∈ subgroup s ↔ mk a ∈ s := by
simp [subgroup, subsemigroup, hs]
@[to_additive]
theorem subgroup_strictAntiOn : StrictAntiOn (subgroup (M := M)) (Set.Iio ⊤) := by
intro s hs t ht hst
rw [← SetLike.coe_ssubset_coe]
rw [← subsemigroup_eq_subgroup_of_ne_top (Set.mem_Iio.mp hs).ne_top]
rw [← subsemigroup_eq_subgroup_of_ne_top (Set.mem_Iio.mp ht).ne_top]
refine Set.ssubset_iff_subset_ne.mpr ⟨by simpa [subsemigroup] using hst.le, ?_⟩
contrapose! hst with heq
apply le_of_eq
simpa [mk_surjective, subsemigroup] using heq
@[to_additive]
theorem subgroup_antitone : Antitone (subgroup (M := M)) := by
intro s t hst
obtain rfl | hs := eq_or_ne s ⊤
· rw [eq_top_iff.mpr hst]
obtain rfl | ht := eq_or_ne t ⊤
· simp
rwa [subgroup_strictAntiOn.le_iff_ge ht.lt_top hs.lt_top]
/-- An open ball defined by `MulArchimedeanClass.subgroup` of `UpperSet.Ioi c`.
For `c = ⊤`, we assign the junk value `⊥`. -/
@[to_additive /--An open ball defined by `ArchimedeanClass.addSubgroup` of `UpperSet.Ioi c`.
For `c = ⊤`, we assign the junk value `⊥`. -/]
noncomputable
abbrev ballSubgroup (c : MulArchimedeanClass M) := subgroup (UpperSet.Ioi c)
/-- A closed ball defined by `MulArchimedeanClass.subgroup` of `UpperSet.Ici c`. -/
@[to_additive /-- A closed ball defined by `ArchimedeanClass.addSubgroup` of `UpperSet.Ici c`. -/]
noncomputable
abbrev closedBallSubgroup (c : MulArchimedeanClass M) := subgroup (UpperSet.Ici c)
@[to_additive]
theorem mem_ballSubgroup_iff {a : M} {c : MulArchimedeanClass M} (hA : c ≠ ⊤) :
a ∈ ballSubgroup c ↔ c < mk a := by
simp [hA]
@[to_additive]
theorem mem_closedBallSubgroup_iff {a : M} {c : MulArchimedeanClass M} :
a ∈ closedBallSubgroup c ↔ c ≤ mk a := by
simp
variable (M) in
@[to_additive (attr := simp)]
theorem ballSubgroup_top : ballSubgroup (M := M) ⊤ = ⊥ := by
convert subgroup_eq_bot M
simp
variable (M) in
@[to_additive (attr := simp)]
theorem closedBallSubgroup_top : closedBallSubgroup (M := M) ⊤ = ⊥ := by
ext
simp
@[to_additive]
theorem ballSubgroup_antitone : Antitone (ballSubgroup (M := M)) := by
intro _ _ h
exact subgroup_antitone <| (UpperSet.Ioi_strictMono _).monotone h
end MulArchimedeanClass
variable (M) in
/-- `FiniteMulArchimedeanClass M` is the quotient of the non-one elements of the group `M` by
multiplicative archimedean equivalence, where two elements `a` and `b` are in the same class iff
`(∃ m : ℕ, |b|ₘ ≤ |a|ₘ ^ m) ∧ (∃ n : ℕ, |a|ₘ ≤ |b|ₘ ^ n)`.
It is defined as the subtype of non-top elements of `MulArchimedeanClass M`
(`⊤ : MulArchimedeanClass M` is the archimedean class of `1`).
This is useful since the family of non-top archimedean classes is linearly independent. -/
@[to_additive FiniteArchimedeanClass
/-- `FiniteArchimedeanClass M` is the quotient of the non-zero elements of the additive group `M` by
additive archimedean equivalence, where two elements `a` and `b` are in the same class iff
`(∃ m : ℕ, |b| ≤ m • |a|) ∧ (∃ n : ℕ, |a| ≤ n • |b|)`.
It is defined as the subtype of non-top elements of `ArchimedeanClass M`
(`⊤ : ArchimedeanClass M` is the archimedean class of `0`).
This is useful since the family of non-top archimedean classes is linearly independent. -/]
abbrev FiniteMulArchimedeanClass := {A : MulArchimedeanClass M // A ≠ ⊤}
namespace FiniteMulArchimedeanClass
/-- Create a `FiniteMulArchimedeanClass` from a non-one element. -/
@[to_additive /-- Create a `FiniteArchimedeanClass` from a non-zero element. -/]
def mk (a : M) (h : a ≠ 1) : FiniteMulArchimedeanClass M :=
⟨MulArchimedeanClass.mk a, MulArchimedeanClass.mk_eq_top_iff.not.mpr h⟩
@[to_additive (attr := simp)]
theorem val_mk {a : M} (h : a ≠ 1) : (mk a h).val = MulArchimedeanClass.mk a := rfl
@[to_additive]
theorem mk_le_mk {a : M} (ha : a ≠ 1) {b : M} (hb : b ≠ 1) :
mk a ha ≤ mk b hb ↔ MulArchimedeanClass.mk a ≤ MulArchimedeanClass.mk b := .rfl
@[to_additive]
theorem mk_lt_mk {a : M} (ha : a ≠ 1) {b : M} (hb : b ≠ 1) :
mk a ha < mk b hb ↔ MulArchimedeanClass.mk a < MulArchimedeanClass.mk b := .rfl
/-- An induction principle for `FiniteMulArchimedeanClass`. -/
@[to_additive (attr := elab_as_elim) /--An induction principle for `FiniteArchimedeanClass`. -/]
theorem ind {motive : FiniteMulArchimedeanClass M → Prop}
(mk : ∀ a, (ha : a ≠ 1) → motive (.mk a ha)) : ∀ x, motive x := by
simpa [FiniteMulArchimedeanClass, MulArchimedeanClass.forall]
@[to_additive]
instance [MulArchimedean M] : Subsingleton (FiniteMulArchimedeanClass M) where
allEq A B := by
induction A using ind with | mk a ha
induction B using ind with | mk b hb
simpa [mk] using MulArchimedeanClass.mk_eq_mk_of_mulArchimedean ha hb
@[to_additive]
instance [Nontrivial M] : Nonempty (FiniteMulArchimedeanClass M) := by
obtain ⟨x, hx⟩ := exists_ne (1 : M)
exact ⟨mk x hx, by simpa using hx⟩
/-- Lift a `f : {a : M // a ≠ 1} → α` function to `FiniteMulArchimedeanClass M → α`. -/
@[to_additive /-- Lift a `f : {a : M // a ≠ 0} → α` function to `FiniteArchimedeanClass M → α`. -/]
def lift {α : Type*} (f : {a : M // a ≠ 1} → α)
(h : ∀ (a b : {a : M // a ≠ 1}), mk a.val a.prop = mk b.val b.prop → f a = f b) :
FiniteMulArchimedeanClass M → α := fun ⟨A, hA⟩ ↦ by
refine (MulArchimedeanClass.lift
(fun b ↦ if h : b = 1 then ⊤ else WithTop.some (f ⟨b, h⟩)) (fun a b h' ↦ ?_) A).untop ?_
· simp only
split_ifs with ha hb hb
· rfl
· exact (hb (MulArchimedeanClass.mk_eq_top_iff.mp (ha ▸ h').symm)).elim
· exact (ha (MulArchimedeanClass.mk_eq_top_iff.mp (by apply hb ▸ h'))).elim
· rw [h ⟨a, ha⟩ ⟨b, hb⟩ (by simpa [mk] using h')]
· induction A using MulArchimedeanClass.ind with | mk a
simpa using MulArchimedeanClass.mk_eq_top_iff.not.mp hA
@[to_additive (attr := simp)]
theorem lift_mk {α : Type*} (f : {a : M // a ≠ 1} → α)
(h : ∀ (a b : {a : M // a ≠ 1}), mk a.val a.prop = mk b.val b.prop → f a = f b)
{a : M} (ha : a ≠ 1) :
lift f h (mk a ha) = f ⟨a, ha⟩ := by simp [lift, mk, ha]
/-- Lift a function `{a : M // a ≠ 1} → α` that's monotone along archimedean classes to a
monotone function `FiniteMulArchimedeanClass M →o α`. -/
@[to_additive /-- Lift a function `{a : M // a ≠ 1} → α` that's monotone along archimedean
classes to a monotone function `FiniteArchimedeanClass M₁ →o α`. -/]
noncomputable
def liftOrderHom {α : Type*} [PartialOrder α]
(f : {a : M // a ≠ 1} → α)
(h : ∀ (a b : {a : M // a ≠ 1}), mk a.val a.prop ≤ mk b.val b.prop → f a ≤ f b) :
FiniteMulArchimedeanClass M →o α where
toFun := lift f fun a b heq ↦ le_antisymm (h a b heq.le) (h b a heq.ge)
monotone' A B hAB := by
induction A using ind with | mk a ha
induction B using ind with | mk b hb
simpa using h ⟨a, ha⟩ ⟨b, hb⟩ hAB
@[to_additive (attr := simp)]
theorem liftOrderHom_mk {α : Type*} [PartialOrder α]
(f : {a : M // a ≠ 1} → α)
(h : ∀ (a b : {a : M // a ≠ 1}), mk a.val a.prop ≤ mk b.val b.prop → f a ≤ f b)
{a : M} (ha : a ≠ 1) : liftOrderHom f h (mk a ha) = f ⟨a, ha⟩ :=
lift_mk f (fun a b heq ↦ le_antisymm (h a b heq.le) (h b a heq.ge)) ha
variable (M) in
/-- Adding top to the type of finite classes yields the type of all classes. -/
@[to_additive /-- Adding top to the type of finite classes yields the type of all classes. -/]
noncomputable
def withTopOrderIso : WithTop (FiniteMulArchimedeanClass M) ≃o MulArchimedeanClass M :=
WithTop.subtypeOrderIso
@[to_additive (attr := simp)]
theorem withTopOrderIso_apply_coe (A : FiniteMulArchimedeanClass M) :
withTopOrderIso M (A : WithTop (FiniteMulArchimedeanClass M)) = A.val :=
WithTop.subtypeOrderIso_apply_coe A
@[to_additive]
theorem withTopOrderIso_symm_apply {a : M} (h : a ≠ 1) :
(withTopOrderIso M).symm (MulArchimedeanClass.mk a) = mk a h :=
WithTop.subtypeOrderIso_symm_apply (MulArchimedeanClass.mk_eq_top_iff.ne.mpr h)
variable {N : Type*} [CommGroup N] [LinearOrder N] [IsOrderedMonoid N]
/-- An `OrderIso` on `MulArchimedeanClass` induces an `OrderIso` on `FiniteMulArchimedeanClass`. -/
@[to_additive
/-- An `OrderIso` on `ArchimedeanClass` induces an `OrderIso` on `FiniteArchimedeanClass`. -/]
noncomputable
def congrOrderIso (e : MulArchimedeanClass M ≃o MulArchimedeanClass N) :
FiniteMulArchimedeanClass M ≃o FiniteMulArchimedeanClass N where
__ := Equiv.subtypeEquiv e (by simp)
map_rel_iff' := by simp
@[to_additive (attr := simp)]
theorem coe_congrOrderIso_apply (e : MulArchimedeanClass M ≃o MulArchimedeanClass N)
(a : FiniteMulArchimedeanClass M) :
(congrOrderIso e a : MulArchimedeanClass N) = e a := rfl
@[to_additive (attr := simp)]
theorem congrOrderIso_symm (e : MulArchimedeanClass M ≃o MulArchimedeanClass N) :
(congrOrderIso e).symm = congrOrderIso e.symm := rfl
end FiniteMulArchimedeanClass |
.lake/packages/mathlib/Mathlib/Algebra/Order/Archimedean/Basic.lean | import Mathlib.Algebra.Order.Floor.Semiring
import Mathlib.Algebra.Order.Monoid.Units
import Mathlib.Algebra.Order.Ring.Pow
import Mathlib.Data.Int.LeastGreatest
import Mathlib.Data.Rat.Floor
/-!
# 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.
* `MulArchimedean` is a typeclass for an ordered commutative monoid to have the "mul-archimedean
property" where for `x` and `y > 1`, there exists a natural number `n` such that `x ≤ y ^ n`.
* `Archimedean.floorRing` defines a floor function on an archimedean linearly ordered ring making
it into a `floorRing`.
## Main statements
* `ℕ`, `ℤ`, and `ℚ` are archimedean.
-/
assert_not_exists Finset
open Int Set
variable {G M R K : 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 (M) [AddCommMonoid M] [PartialOrder M] : 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 : M) {y : M}, 0 < y → ∃ n : ℕ, x ≤ n • y
section MulArchimedean
/-- An ordered commutative monoid is called `MulArchimedean` if for any two elements `x`, `y`
such that `1 < y`, there exists a natural number `n` such that `x ≤ y ^ n`. -/
@[to_additive Archimedean]
class MulArchimedean (M) [CommMonoid M] [PartialOrder M] : Prop where
/-- For any two elements `x`, `y` such that `1 < y`, there exists a natural number `n`
such that `x ≤ y ^ n`. -/
arch : ∀ (x : M) {y : M}, 1 < y → ∃ n : ℕ, x ≤ y ^ n
end MulArchimedean
@[to_additive]
lemma MulArchimedean.comap [CommMonoid G] [LinearOrder G] [CommMonoid M] [PartialOrder M]
[MulArchimedean M] (f : G →* M) (hf : StrictMono f) :
MulArchimedean G where
arch x _ h := by
refine (MulArchimedean.arch (f x) (by simpa using hf h)).imp ?_
simp [← map_pow, hf.le_iff_le]
@[to_additive]
instance OrderDual.instMulArchimedean [CommGroup G] [PartialOrder G] [IsOrderedMonoid G]
[MulArchimedean G] :
MulArchimedean Gᵒᵈ :=
⟨fun x y hy =>
let ⟨n, hn⟩ := MulArchimedean.arch (ofDual x)⁻¹ (inv_lt_one_iff_one_lt.2 hy)
⟨n, by rwa [inv_pow, inv_le_inv_iff] at hn⟩⟩
instance Additive.instArchimedean [CommGroup G] [PartialOrder G] [MulArchimedean G] :
Archimedean (Additive G) :=
⟨fun x _ hy ↦ MulArchimedean.arch x.toMul hy⟩
instance Multiplicative.instMulArchimedean [AddCommGroup G] [PartialOrder G] [Archimedean G] :
MulArchimedean (Multiplicative G) :=
⟨fun x _ hy ↦ Archimedean.arch x.toAdd hy⟩
@[to_additive]
theorem exists_lt_pow [CommMonoid M] [PartialOrder M] [MulArchimedean M] [MulLeftStrictMono M]
{a : M} (ha : 1 < a) (b : M) : ∃ n : ℕ, b < a ^ n :=
let ⟨k, hk⟩ := MulArchimedean.arch b ha
⟨k + 1, hk.trans_lt <| pow_lt_pow_right' ha k.lt_succ_self⟩
section LinearOrderedCommGroup
variable [CommGroup G] [LinearOrder G] [IsOrderedMonoid G] [MulArchimedean G]
/-- An archimedean decidable linearly ordered `CommGroup` has a version of the floor: for
`a > 1`, any `g` in the group lies between some two consecutive powers of `a`. -/
@[to_additive /-- 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_zpow_near_of_one_lt {a : G} (ha : 1 < a) (g : G) :
∃! k : ℤ, a ^ k ≤ g ∧ g < a ^ (k + 1) := by
let s : Set ℤ := { n : ℤ | a ^ n ≤ g }
obtain ⟨k, hk : g⁻¹ ≤ a ^ k⟩ := MulArchimedean.arch g⁻¹ ha
have h_ne : s.Nonempty := ⟨-k, by simpa [s] using inv_le_inv' hk⟩
obtain ⟨k, hk⟩ := MulArchimedean.arch g ha
have h_bdd : ∀ n ∈ s, n ≤ (k : ℤ) := by
intro n hn
apply (zpow_le_zpow_iff_right ha).mp
rw [← zpow_natCast] at hk
exact le_trans hn hk
obtain ⟨m, hm, hm'⟩ := Int.exists_greatest_of_bdd ⟨k, h_bdd⟩ h_ne
have hm'' : g < a ^ (m + 1) := 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 [← zpow_lt_zpow_iff_right ha]
exact lt_of_le_of_lt hm hn.2
@[to_additive]
theorem existsUnique_zpow_near_of_one_lt' {a : G} (ha : 1 < a) (g : G) :
∃! k : ℤ, 1 ≤ g / a ^ k ∧ g / a ^ k < a := by
simpa only [one_le_div', zpow_add_one, div_lt_iff_lt_mul'] using
existsUnique_zpow_near_of_one_lt ha g
@[to_additive]
theorem existsUnique_div_zpow_mem_Ico {a : G} (ha : 1 < a) (b c : G) :
∃! m : ℤ, b / a ^ m ∈ Set.Ico c (c * a) := by
simpa only [mem_Ico, le_div_iff_mul_le, one_mul, mul_comm c, div_lt_iff_lt_mul, mul_assoc] using
existsUnique_zpow_near_of_one_lt' ha (b / c)
@[to_additive]
theorem existsUnique_mul_zpow_mem_Ico {a : G} (ha : 1 < a) (b c : G) :
∃! m : ℤ, b * a ^ m ∈ Set.Ico c (c * a) :=
(Equiv.neg ℤ).bijective.existsUnique_iff.2 <| by
simpa only [Equiv.neg_apply, mem_Ico, zpow_neg, ← div_eq_mul_inv, le_div_iff_mul_le, one_mul,
mul_comm c, div_lt_iff_lt_mul, mul_assoc] using existsUnique_zpow_near_of_one_lt' ha (b / c)
@[to_additive]
theorem existsUnique_add_zpow_mem_Ioc {a : G} (ha : 1 < a) (b c : G) :
∃! m : ℤ, b * a ^ m ∈ Set.Ioc c (c * a) :=
(Equiv.addRight (1 : ℤ)).bijective.existsUnique_iff.2 <| by
simpa only [zpow_add_one, div_lt_iff_lt_mul', le_div_iff_mul_le', ← mul_assoc, and_comm,
mem_Ioc, Equiv.coe_addRight, mul_le_mul_iff_right] using
existsUnique_zpow_near_of_one_lt ha (c / b)
@[to_additive]
theorem existsUnique_sub_zpow_mem_Ioc {a : G} (ha : 1 < a) (b c : G) :
∃! m : ℤ, b / a ^ m ∈ Set.Ioc c (c * a) :=
(Equiv.neg ℤ).bijective.existsUnique_iff.2 <| by
simpa only [Equiv.neg_apply, zpow_neg, div_inv_eq_mul] using
existsUnique_add_zpow_mem_Ioc ha b c
@[to_additive]
theorem exists_pow_lt {a : G} (ha : a < 1) (b : G) : ∃ n : ℕ, a ^ n < b :=
(exists_lt_pow (one_lt_inv'.mpr ha) b⁻¹).imp <| by simp
end LinearOrderedCommGroup
section OrderedSemiring
variable [Semiring R] [PartialOrder R] [IsOrderedRing R] [Archimedean R]
theorem exists_nat_ge (x : R) :
∃ n : ℕ, x ≤ n := by
nontriviality R
exact (Archimedean.arch x one_pos).imp fun n h => by rwa [← nsmul_one]
instance (priority := 100) : IsDirected R (· ≤ ·) :=
⟨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⟩⟩
end OrderedSemiring
section StrictOrderedSemiring
variable [Semiring R] [PartialOrder R] [IsStrictOrderedRing R] [Archimedean R] {y : R}
lemma exists_nat_gt (x : R) : ∃ 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 : R) (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 R] (x : R) (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 OrderedRing
variable [Ring R] [PartialOrder R] [IsOrderedRing R] [Archimedean R]
theorem exists_int_ge (x : R) : ∃ n : ℤ, x ≤ n := let ⟨n, h⟩ := exists_nat_ge x; ⟨n, mod_cast h⟩
theorem exists_int_le (x : R) : ∃ n : ℤ, n ≤ x :=
let ⟨n, h⟩ := exists_int_ge (-x); ⟨-n, by simpa [neg_le] using h⟩
instance (priority := 100) : IsDirected R (· ≥ ·) where
directed a b :=
let ⟨m, hm⟩ := exists_int_le a; let ⟨n, hn⟩ := exists_int_le b
⟨(min m n : ℤ), le_trans (Int.cast_mono <| min_le_left _ _) hm,
le_trans (Int.cast_mono <| min_le_right _ _) hn⟩
end OrderedRing
section StrictOrderedRing
variable [Ring R] [PartialOrder R] [IsStrictOrderedRing R] [Archimedean R]
theorem exists_int_gt (x : R) : ∃ n : ℤ, x < n :=
let ⟨n, h⟩ := exists_nat_gt x
⟨n, by rwa [Int.cast_natCast]⟩
theorem exists_int_lt (x : R) : ∃ n : ℤ, (n : R) < x :=
let ⟨n, h⟩ := exists_int_gt (-x)
⟨-n, by rw [Int.cast_neg]; exact neg_lt.1 h⟩
theorem exists_floor (x : R) : ∃ fl : ℤ, ∀ z : ℤ, z ≤ fl ↔ (z : R) ≤ x := by
classical
have : ∃ ub : ℤ, (ub : R) ≤ x ∧ ∀ z : ℤ, (z : R) ≤ 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 => ?_
obtain ⟨h₁, h₂⟩ := h
exact ⟨fun h => le_trans (Int.cast_le.2 h) h₁, h₂ z⟩
end StrictOrderedRing
section LinearOrderedSemiring
variable [Semiring R] [LinearOrder R] [IsStrictOrderedRing R] [Archimedean R] [ExistsAddOfLE R]
{x y : R}
/-- 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_gt (Nat.find_min h hltn), by rwa [hnsp]⟩
end LinearOrderedSemiring
section LinearOrderedSemifield
variable [Semifield K] [LinearOrder K] [IsStrictOrderedRing K] [Archimedean K] {x y ε : K}
lemma exists_nat_one_div_lt (hε : 0 < ε) : ∃ n : ℕ, 1 / (n + 1 : K) < ε := by
obtain ⟨n, hn⟩ := exists_nat_gt (1 / ε)
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 K]
/-- 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
have he : ∃ m : ℤ, y ^ m ≤ x := by
obtain ⟨N, hN⟩ := pow_unbounded_of_one_lt x⁻¹ hy
use -N
rw [zpow_neg y ↑N, zpow_natCast]
exact ((inv_lt_comm₀ hx (lt_trans (inv_pos.2 hx) hN)).1 hN).le
have hb : ∃ b : ℤ, ∀ m, y ^ m ≤ x → m ≤ b := by
obtain ⟨M, hM⟩ := pow_unbounded_of_one_lt x hy
refine ⟨M, fun m hm ↦ ?_⟩
contrapose! hM
rw [← zpow_natCast]
exact le_trans (zpow_le_zpow_right₀ hy.le hM.le) hm
obtain ⟨n, hn₁, hn₂⟩ := Int.exists_greatest_of_bdd hb he
exact ⟨n, hn₁, lt_of_not_ge fun hge => (Int.lt_succ _).not_ge (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_comm₀ (zpow_pos hyp _) hx], by
rwa [neg_add, neg_add_cancel_right, zpow_neg, le_inv_comm₀ hx (zpow_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
rcases pow_unbounded_of_one_lt x⁻¹ ((one_lt_inv₀ y_pos).2 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
/-- If `a < b * c`, `0 < b ≤ 1` and `0 < c < 1`, then there is a power `c ^ n` with `n : ℕ`
strictly between `a` and `b`. -/
lemma exists_pow_btwn_of_lt_mul {a b c : K} (h : a < b * c) (hb₀ : 0 < b) (hb₁ : b ≤ 1)
(hc₀ : 0 < c) (hc₁ : c < 1) :
∃ n : ℕ, a < c ^ n ∧ c ^ n < b := by
have := exists_pow_lt_of_lt_one hb₀ hc₁
refine ⟨Nat.find this, h.trans_le ?_, Nat.find_spec this⟩
by_contra! H
have hn : Nat.find this ≠ 0 := by
intro hf
simp only [hf, pow_zero] at H
exact (H.trans <| (mul_lt_of_lt_one_right hb₀ hc₁).trans_le hb₁).false
rw [(Nat.succ_pred_eq_of_ne_zero hn).symm, pow_succ, mul_lt_mul_iff_left₀ hc₀] at H
exact Nat.find_min this (Nat.sub_one_lt hn) H
/-- If `a < b * c`, `b` is positive and `0 < c < 1`, then there is a power `c ^ n` with `n : ℤ`
strictly between `a` and `b`. -/
lemma exists_zpow_btwn_of_lt_mul {a b c : K} (h : a < b * c) (hb₀ : 0 < b) (hc₀ : 0 < c)
(hc₁ : c < 1) :
∃ n : ℤ, a < c ^ n ∧ c ^ n < b := by
rcases le_or_gt a 0 with ha | ha
· obtain ⟨n, hn⟩ := exists_pow_lt_of_lt_one hb₀ hc₁
exact ⟨n, ha.trans_lt (zpow_pos hc₀ _), mod_cast hn⟩
· rcases le_or_gt b 1 with hb₁ | hb₁
· obtain ⟨n, hn⟩ := exists_pow_btwn_of_lt_mul h hb₀ hb₁ hc₀ hc₁
exact ⟨n, mod_cast hn⟩
· rcases lt_or_ge a 1 with ha₁ | ha₁
· refine ⟨0, ?_⟩
rw [zpow_zero]
exact ⟨ha₁, hb₁⟩
· have : b⁻¹ < a⁻¹ * c := by rwa [lt_inv_mul_iff₀' ha, inv_mul_lt_iff₀ hb₀]
obtain ⟨n, hn₁, hn₂⟩ :=
exists_pow_btwn_of_lt_mul this (inv_pos_of_pos ha) (inv_le_one_of_one_le₀ ha₁) hc₀ hc₁
refine ⟨-n, ?_, ?_⟩
· rwa [lt_inv_comm₀ (pow_pos hc₀ n) ha, ← zpow_natCast, ← zpow_neg] at hn₂
· rwa [inv_lt_comm₀ hb₀ (pow_pos hc₀ n), ← zpow_natCast, ← zpow_neg] at hn₁
end LinearOrderedSemifield
section LinearOrderedField
variable [Field K] [LinearOrder K] [IsStrictOrderedRing K]
theorem archimedean_iff_nat_lt : Archimedean K ↔ ∀ x : K, ∃ n : ℕ, x < n :=
⟨@exists_nat_gt K _ _ _, 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 K ↔ ∀ x : K, ∃ 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 K ↔ ∀ x : K, ∃ n : ℤ, x < n :=
⟨@exists_int_gt K _ _ _, 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 K ↔ ∀ x : K, ∃ 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 K ↔ ∀ x : K, ∃ q : ℚ, x < q where
mp _ x :=
let ⟨n, h⟩ := exists_nat_gt x
⟨n, by rwa [Rat.cast_natCast]⟩
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 K ↔ ∀ x : K, ∃ 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 _))⟩⟩
instance : Archimedean ℚ :=
archimedean_iff_rat_le.2 fun q => ⟨q, by rw [Rat.cast_id]⟩
variable [Archimedean K] {x y ε : K}
theorem exists_rat_gt (x : K) : ∃ q : ℚ, x < q := archimedean_iff_rat_lt.mp ‹_› _
theorem exists_rat_lt (x : K) : ∃ q : ℚ, (q : K) < x :=
let ⟨n, h⟩ := exists_int_lt x
⟨n, by rwa [Rat.cast_intCast]⟩
theorem exists_div_btwn {x y : K} {n : ℕ} (h : x < y) (nh : (y - x)⁻¹ < n) :
∃ z : ℤ, x < (z : K) / n ∧ (z : K) / n < y := by
obtain ⟨z, zh⟩ := exists_floor (x * n)
refine ⟨z + 1, ?_⟩
have n0' := (inv_pos.2 (sub_pos.2 h)).trans nh
rw [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]
grw [(zh _).1 le_rfl]
rwa [← lt_sub_iff_add_lt', ← sub_mul, ← div_lt_iff₀' (sub_pos.2 h), one_div]
theorem exists_rat_btwn {x y : K} (h : x < y) : ∃ q : ℚ, x < q ∧ q < y := by
obtain ⟨n, nh⟩ := exists_nat_gt (y - x)⁻¹
obtain ⟨z, zh, zh'⟩ := exists_div_btwn h nh
refine ⟨(z : ℚ) / n, ?_, ?_⟩ <;> simpa
theorem exists_rat_mem_uIoo {x y : K} (h : x ≠ y) : ∃ q : ℚ, ↑q ∈ Set.uIoo x y :=
exists_rat_btwn (min_lt_max.mpr h)
theorem exists_pow_btwn {n : ℕ} (hn : n ≠ 0) {x y : K} (h : x < y) (hy : 0 < y) :
∃ q : K, 0 < q ∧ x < q ^ n ∧ q ^ n < y := by
have ⟨δ, δ_pos, cont⟩ := uniform_continuous_npow_on_bounded (max 1 y)
(sub_pos.mpr <| max_lt_iff.mpr ⟨h, hy⟩) n
have ex : ∃ m : ℕ, y ≤ (m * δ) ^ n := by
have ⟨m, hm⟩ := exists_nat_ge (y / δ + 1 / δ)
refine ⟨m, le_trans ?_ (le_self_pow₀ ?_ hn)⟩ <;> rw [← div_le_iff₀ δ_pos]
· exact (lt_add_of_pos_right _ <| by positivity).le.trans hm
· exact (le_add_of_nonneg_left <| by positivity).trans hm
let m := Nat.find ex
have m_pos : 0 < m := (Nat.find_pos _).mpr <| by simpa [zero_pow hn] using hy
let q := m.pred * δ
have qny : q ^ n < y := lt_of_not_ge (Nat.find_min ex <| Nat.pred_lt m_pos.ne')
have q1y : |q| < max 1 y := (abs_eq_self.mpr <| by positivity).trans_lt <| lt_max_iff.mpr
(or_iff_not_imp_left.mpr fun q1 ↦ (le_self_pow₀ (le_of_not_gt q1) hn).trans_lt qny)
have xqn : max x 0 < q ^ n :=
calc _ = y - (y - max x 0) := by rw [sub_sub_cancel]
_ ≤ (m * δ) ^ n - (y - max x 0) := sub_le_sub_right (Nat.find_spec ex) _
_ < (m * δ) ^ n - ((m * δ) ^ n - q ^ n) := by
refine sub_lt_sub_left ((le_abs_self _).trans_lt <| cont _ _ q1y.le ?_) _
rw [← Nat.succ_pred_eq_of_pos m_pos, Nat.cast_succ, ← sub_mul,
add_sub_cancel_left, one_mul, abs_eq_self.mpr (by positivity)]
_ = q ^ n := sub_sub_cancel ..
exact ⟨q, lt_of_le_of_ne (by positivity) fun q0 ↦
(le_sup_right.trans_lt xqn).ne <| q0 ▸ (zero_pow hn).symm, le_sup_left.trans_lt xqn, qny⟩
/-- There is a rational power between any two positive elements of an archimedean ordered field. -/
theorem exists_rat_pow_btwn {n : ℕ} (hn : n ≠ 0) {x y : K} (h : x < y) (hy : 0 < y) :
∃ q : ℚ, 0 < q ∧ x < (q : K) ^ n ∧ (q : K) ^ n < y := by
obtain ⟨q₂, hx₂, hy₂⟩ := exists_rat_btwn (max_lt h hy)
obtain ⟨q₁, hx₁, hq₁₂⟩ := exists_rat_btwn hx₂
have : (0 : K) < q₂ := (le_max_right _ _).trans_lt hx₂
norm_cast at hq₁₂ this
obtain ⟨q, hq, hq₁, hq₂⟩ := exists_pow_btwn hn hq₁₂ this
refine ⟨q, hq, (le_max_left _ _).trans_lt <| hx₁.trans ?_, hy₂.trans' ?_⟩ <;> assumption_mod_cast
theorem le_of_forall_rat_lt_imp_le (h : ∀ q : ℚ, (q : K) < x → (q : K) ≤ y) : x ≤ y :=
le_of_not_gt fun hyx =>
let ⟨_, hy, hx⟩ := exists_rat_btwn hyx
hy.not_ge <| h _ hx
theorem le_of_forall_lt_rat_imp_le (h : ∀ q : ℚ, y < q → x ≤ q) : x ≤ y :=
le_of_not_gt fun hyx =>
let ⟨_, hy, hx⟩ := exists_rat_btwn hyx
hx.not_ge <| h _ hy
theorem le_iff_forall_rat_lt_imp_le : x ≤ y ↔ ∀ q : ℚ, (q : K) < x → (q : K) ≤ 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 : K) < x ↔ (q : K) < 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 : K} (x0 : 0 < x) : ∃ q : ℚ, 0 < q ∧ (q : K) < x := by
simpa only [Rat.cast_pos] using exists_rat_btwn x0
theorem exists_rat_near (x : K) (ε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
instance : Archimedean ℕ :=
⟨fun n m m0 => ⟨n, by
rw [← mul_one n, nsmul_eq_mul, Nat.cast_id, mul_one]
exact Nat.le_mul_of_pos_right n m0⟩⟩
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 Nonneg.instArchimedean [AddCommMonoid M] [PartialOrder M] [IsOrderedAddMonoid M]
[Archimedean M] :
Archimedean { x : M // 0 ≤ x } :=
⟨fun x y hy =>
let ⟨n, hr⟩ := Archimedean.arch (x : M) (hy : (0 : M) < y)
⟨n, mod_cast hr⟩⟩
instance Nonneg.instMulArchimedean [CommSemiring R] [PartialOrder R] [IsStrictOrderedRing R]
[Archimedean R] [ExistsAddOfLE R] :
MulArchimedean { x : R // 0 ≤ x } :=
⟨fun x _ hy ↦ (pow_unbounded_of_one_lt x hy).imp fun _ h ↦ h.le⟩
instance : Archimedean NNRat := Nonneg.instArchimedean
instance : MulArchimedean NNRat := Nonneg.instMulArchimedean
/-- 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 (R) [Ring R] [LinearOrder R] [IsStrictOrderedRing R]
[Archimedean R] : FloorRing R :=
.ofFloor R (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 (K) [Field K] [LinearOrder K]
[IsStrictOrderedRing K] [FloorRing K] :
Archimedean K := by
rw [archimedean_iff_int_le]
exact fun x => ⟨⌈x⌉, Int.le_ceil x⟩
@[to_additive]
instance Units.instMulArchimedean (M) [CommMonoid M] [PartialOrder M] [MulArchimedean M] :
MulArchimedean Mˣ :=
⟨fun x {_} h ↦ MulArchimedean.arch x.val h⟩
instance WithBot.instArchimedean (M) [AddCommMonoid M] [PartialOrder M] [Archimedean M] :
Archimedean (WithBot M) := by
constructor
intro x y hxy
cases y with
| bot => exact absurd hxy bot_le.not_gt
| coe y =>
cases x with
| bot => refine ⟨0, bot_le⟩
| coe x => simpa [← WithBot.coe_nsmul] using (Archimedean.arch x (by simpa using hxy))
instance WithZero.instMulArchimedean (M) [CommMonoid M] [PartialOrder M] [MulArchimedean M] :
MulArchimedean (WithZero M) := by
constructor
intro x y hxy
cases y with
| zero => exact absurd hxy (zero_le _).not_gt
| coe y =>
cases x with
| zero => refine ⟨0, zero_le _⟩
| coe x => simpa [← WithZero.coe_pow] using (MulArchimedean.arch x (by simpa using hxy)) |
.lake/packages/mathlib/Mathlib/Algebra/Order/Archimedean/Submonoid.lean | import Mathlib.Algebra.Group.Submonoid.Defs
import Mathlib.Algebra.Order.Archimedean.Basic
/-!
# Submonoids of archimedean monoids
This file defines the instances that show that the (mul)archimedean property is retained in a
submonoid of the ambient group.
## Main statements
* `SubmonoidClass.instMulArchimedean`: the submonoid (and similar subobjects) of a mul-archimedean
group retains the mul-archimedean property when restricted to the submonoid.
* `AddSubmonoidClass.instArchimedean`: the additive submonoid (and similar subobjects) of an
archimedean additive group retains the archimedean property when restricted to the additive
submonoid.
-/
assert_not_exists Finset
@[to_additive]
instance SubmonoidClass.instMulArchimedean {M S : Type*} [SetLike S M]
[CommMonoid M] [PartialOrder M]
[SubmonoidClass S M] [MulArchimedean M] (H : S) : MulArchimedean H := by
constructor
rintro x _
simp only [← Subtype.coe_lt_coe, OneMemClass.coe_one]
exact MulArchimedean.arch x.val |
.lake/packages/mathlib/Mathlib/Algebra/Order/Archimedean/IndicatorCard.lean | import Mathlib.Algebra.BigOperators.Group.Finset.Indicator
import Mathlib.Algebra.Order.Archimedean.Basic
import Mathlib.Algebra.Order.BigOperators.Group.Finset
import Mathlib.Algebra.Order.Group.Indicator
import Mathlib.Order.LiminfLimsup
import Mathlib.SetTheory.Cardinal.Finite
/-!
# Cardinality and limit of sum of indicators
This file contains results relating the cardinality of subsets of ℕ and limits,
limsups of sums of indicators.
## Tags
finite, indicator, limsup, tendsto
-/
namespace Set
open Filter Finset
lemma sum_indicator_eventually_eq_card {α : Type*} [AddCommMonoid α] (a : α) {s : Set ℕ}
(hs : s.Finite) :
∀ᶠ n in atTop, ∑ k ∈ Finset.range n, s.indicator (fun _ ↦ a) k = (Nat.card s) • a := by
have key : ∀ x ∈ hs.toFinset, s.indicator (fun _ ↦ a) x = a := by
intro x hx
rw [indicator_of_mem (hs.mem_toFinset.1 hx) (fun _ ↦ a)]
rw [Nat.card_eq_card_finite_toFinset hs, ← sum_eq_card_nsmul key, eventually_atTop]
obtain ⟨m, hm⟩ := hs.bddAbove
refine ⟨m + 1, fun n n_m ↦ (sum_subset ?_ ?_).symm⟩ <;> intro x <;> rw [hs.mem_toFinset]
· rw [Finset.mem_range]
exact fun x_s ↦ ((mem_upperBounds.1 hm) x x_s).trans_lt (Nat.lt_of_succ_le n_m)
· exact fun _ x_s ↦ indicator_of_notMem x_s (fun _ ↦ a)
lemma infinite_iff_tendsto_sum_indicator_atTop {R : Type*}
[AddCommMonoid R] [PartialOrder R] [IsOrderedAddMonoid R]
[AddLeftStrictMono R] [Archimedean R] {r : R} (h : 0 < r) {s : Set ℕ} :
s.Infinite ↔ atTop.Tendsto (fun n ↦ ∑ k ∈ Finset.range n, s.indicator (fun _ ↦ r) k) atTop := by
constructor
· have h_mono : Monotone fun n ↦ ∑ k ∈ Finset.range n, s.indicator (fun _ ↦ r) k := by
refine (sum_mono_set_of_nonneg ?_).comp range_mono
exact (fun _ ↦ indicator_nonneg (fun _ _ ↦ h.le) _)
rw [h_mono.tendsto_atTop_atTop_iff]
intro hs n
obtain ⟨n', hn'⟩ := exists_lt_nsmul h n
obtain ⟨t, t_s, t_card⟩ := hs.exists_subset_card_eq n'
obtain ⟨m, hm⟩ := t.bddAbove
refine ⟨m + 1, hn'.le.trans ?_⟩
apply (sum_le_sum fun i _ ↦ (indicator_le_indicator_of_subset t_s (fun _ ↦ h.le)) i).trans_eq'
have h : t ⊆ Finset.range (m + 1) := by
intro i i_t
rw [Finset.mem_range]
exact (hm i_t).trans_lt (lt_add_one m)
rw [sum_indicator_subset (fun _ ↦ r) h, sum_eq_card_nsmul (fun _ _ ↦ rfl), t_card]
· contrapose
intro hs
rw [not_infinite] at hs
rw [tendsto_congr' (sum_indicator_eventually_eq_card r hs), tendsto_atTop_atTop]
push_neg
obtain ⟨m, hm⟩ := exists_lt_nsmul h (Nat.card s • r)
exact ⟨m • r, fun n ↦ ⟨n, le_refl n, not_le_of_gt hm⟩⟩
lemma limsup_eq_tendsto_sum_indicator_atTop {α R : Type*}
[AddCommMonoid R] [PartialOrder R] [IsOrderedAddMonoid R]
[AddLeftStrictMono R] [Archimedean R] {r : R} (h : 0 < r) (s : ℕ → Set α) :
atTop.limsup s = { ω | atTop.Tendsto
(fun n ↦ ∑ k ∈ Finset.range n, (s k).indicator (fun _ ↦ r) ω) atTop } := by
nth_rw 1 [← Nat.cofinite_eq_atTop, cofinite.limsup_set_eq]
ext ω
rw [mem_setOf_eq, mem_setOf_eq, infinite_iff_tendsto_sum_indicator_atTop h, iff_eq_eq]
congr
end Set |
.lake/packages/mathlib/Mathlib/Algebra/Order/Archimedean/Hom.lean | 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.
-/
assert_not_exists Finset
variable {α β : Type*} [Field α] [LinearOrder α] [Field β] [LinearOrder β]
/-- There is at most one ordered ring homomorphism from a linear ordered field to an archimedean
linear ordered field. -/
instance OrderRingHom.subsingleton [IsStrictOrderedRing β] [Archimedean β] :
Subsingleton (α →+*o β) :=
⟨fun f g => by
ext x
by_contra! h' : f x ≠ g x
wlog h : f x < g x with h₂
· exact h₂ g f x (Ne.symm h') (h'.lt_or_gt.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 [IsStrictOrderedRing β] [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 [IsStrictOrderedRing α] [Archimedean α] :
Subsingleton (α ≃+*o β) :=
OrderRingIso.symm_bijective.injective.subsingleton
theorem OrderRingHom.eq_id [IsStrictOrderedRing α] [Archimedean α] (f : α →+*o α) : f = .id _ :=
Subsingleton.elim ..
theorem OrderRingIso.eq_refl [IsStrictOrderedRing α] [Archimedean α] (f : α ≃+*o α) : f = .refl _ :=
Subsingleton.elim ..
theorem OrderRingHom.apply_eq_self [IsStrictOrderedRing α] [Archimedean α] (f : α →+*o α) (x : α) :
f x = x := by
rw [f.eq_id]; rfl
theorem OrderRingIso.apply_eq_self [IsStrictOrderedRing α] [Archimedean α] (f : α ≃+*o α) (x : α) :
f x = x :=
f.toOrderRingHom.apply_eq_self x |
.lake/packages/mathlib/Mathlib/Algebra/Order/Hom/Monoid.lean | import Mathlib.Algebra.Group.Equiv.Defs
import Mathlib.Algebra.Group.Hom.Basic
import Mathlib.Algebra.Order.Group.Unbundled.Basic
import Mathlib.Algebra.Order.Monoid.OrderDual
import Mathlib.Order.Hom.Basic
/-!
# Ordered monoid and group homomorphisms
This file defines morphisms between (additive) ordered monoids.
## Types of morphisms
* `OrderAddMonoidHom`: Ordered additive monoid homomorphisms.
* `OrderMonoidHom`: Ordered monoid homomorphisms.
* `OrderAddMonoidIso`: Ordered additive monoid isomorphisms.
* `OrderMonoidIso`: Ordered monoid isomorphisms.
## Notation
* `→+o`: Bundled ordered additive monoid homs. Also use for additive group homs.
* `→*o`: Bundled ordered monoid homs. Also use for group homs.
* `≃+o`: Bundled ordered additive monoid isos. Also use for additive group isos.
* `≃*o`: Bundled ordered monoid isos. Also use for group isos.
## Implementation notes
There's a coercion from bundled homs to fun, and the canonical notation is to use the bundled hom as
a function via this coercion.
There is no `OrderGroupHom` -- the idea is that `OrderMonoidHom` is used.
The constructor for `OrderMonoidHom` needs a proof of `map_one` as well as `map_mul`; a separate
constructor `OrderMonoidHom.mk'` will construct ordered group homs (i.e. ordered monoid homs
between ordered groups) given only a proof that multiplication is preserved,
Implicit `{}` brackets are often used instead of type class `[]` brackets. This is done when the
instances can be inferred because they are implicit arguments to the type `OrderMonoidHom`. When
they can be inferred from the type it is faster to use this method than to use type class inference.
### Removed typeclasses
This file used to define typeclasses for order-preserving (additive) monoid homomorphisms:
`OrderAddMonoidHomClass`, `OrderMonoidHomClass`, and `OrderMonoidWithZeroHomClass`.
In https://github.com/leanprover-community/mathlib4/pull/10544 we migrated from these typeclasses
to assumptions like `[FunLike F M N] [MonoidHomClass F M N] [OrderHomClass F M N]`,
making some definitions and lemmas irrelevant.
## Tags
ordered monoid, ordered group
-/
assert_not_exists MonoidWithZero
open Function
variable {F α β γ δ : Type*}
section AddMonoid
/-- `α →+o β` is the type of monotone functions `α → β` that preserve the `OrderedAddCommMonoid`
structure.
`OrderAddMonoidHom` is also used for ordered group homomorphisms.
When possible, instead of parametrizing results over `(f : α →+o β)`,
you should parametrize over
`(F : Type*) [FunLike F M N] [MonoidHomClass F M N] [OrderHomClass F M N] (f : F)`. -/
structure OrderAddMonoidHom (α β : Type*) [Preorder α] [Preorder β] [AddZeroClass α]
[AddZeroClass β] extends α →+ β where
/-- An `OrderAddMonoidHom` is a monotone function. -/
monotone' : Monotone toFun
/-- Infix notation for `OrderAddMonoidHom`. -/
infixr:25 " →+o " => OrderAddMonoidHom
/-- `α ≃+o β` is the type of monotone isomorphisms `α ≃ β` that preserve the `OrderedAddCommMonoid`
structure.
`OrderAddMonoidIso` is also used for ordered group isomorphisms.
When possible, instead of parametrizing results over `(f : α ≃+o β)`,
you should parametrize over
`(F : Type*) [FunLike F M N] [AddEquivClass F M N] [OrderIsoClass F M N] (f : F)`. -/
structure OrderAddMonoidIso (α β : Type*) [Preorder α] [Preorder β] [Add α] [Add β]
extends α ≃+ β where
/-- An `OrderAddMonoidIso` respects `≤`. -/
map_le_map_iff' {a b : α} : toFun a ≤ toFun b ↔ a ≤ b
/-- Infix notation for `OrderAddMonoidIso`. -/
infixr:25 " ≃+o " => OrderAddMonoidIso
-- Instances and lemmas are defined below through `@[to_additive]`.
end AddMonoid
section Monoid
/-- `α →*o β` is the type of functions `α → β` that preserve the `OrderedCommMonoid` structure.
`OrderMonoidHom` is also used for ordered group homomorphisms.
When possible, instead of parametrizing results over `(f : α →*o β)`,
you should parametrize over
`(F : Type*) [FunLike F M N] [MonoidHomClass F M N] [OrderHomClass F M N] (f : F)`. -/
@[to_additive]
structure OrderMonoidHom (α β : Type*) [Preorder α] [Preorder β] [MulOneClass α]
[MulOneClass β] extends α →* β where
/-- An `OrderMonoidHom` is a monotone function. -/
monotone' : Monotone toFun
/-- Infix notation for `OrderMonoidHom`. -/
infixr:25 " →*o " => OrderMonoidHom
variable [Preorder α] [Preorder β] [MulOneClass α] [MulOneClass β] [FunLike F α β]
/-- Turn an element of a type `F` satisfying `OrderHomClass F α β` and `MonoidHomClass F α β`
into an actual `OrderMonoidHom`. This is declared as the default coercion from `F` to `α →*o β`. -/
@[to_additive (attr := coe)
/-- Turn an element of a type `F` satisfying `OrderHomClass F α β` and `AddMonoidHomClass F α β`
into an actual `OrderAddMonoidHom`.
This is declared as the default coercion from `F` to `α →+o β`. -/]
def OrderMonoidHomClass.toOrderMonoidHom [OrderHomClass F α β] [MonoidHomClass F α β] (f : F) :
α →*o β :=
{ (f : α →* β) with monotone' := OrderHomClass.monotone f }
/-- Any type satisfying `OrderMonoidHomClass` can be cast into `OrderMonoidHom` via
`OrderMonoidHomClass.toOrderMonoidHom`. -/
@[to_additive /-- Any type satisfying `OrderAddMonoidHomClass` can be cast into `OrderAddMonoidHom`
via `OrderAddMonoidHomClass.toOrderAddMonoidHom`. -/]
instance [OrderHomClass F α β] [MonoidHomClass F α β] : CoeTC F (α →*o β) :=
⟨OrderMonoidHomClass.toOrderMonoidHom⟩
/-- `α ≃*o β` is the type of isomorphisms `α ≃ β` that preserve the `OrderedCommMonoid` structure.
`OrderMonoidIso` is also used for ordered group isomorphisms.
When possible, instead of parametrizing results over `(f : α ≃*o β)`,
you should parametrize over
`(F : Type*) [FunLike F M N] [MulEquivClass F M N] [OrderIsoClass F M N] (f : F)`. -/
@[to_additive]
structure OrderMonoidIso (α β : Type*) [Preorder α] [Preorder β] [Mul α] [Mul β]
extends α ≃* β where
/-- An `OrderMonoidIso` respects `≤`. -/
map_le_map_iff' {a b : α} : toFun a ≤ toFun b ↔ a ≤ b
/-- Infix notation for `OrderMonoidIso`. -/
infixr:25 " ≃*o " => OrderMonoidIso
variable [Preorder α] [Preorder β] [MulOneClass α] [MulOneClass β] [FunLike F α β]
/-- Turn an element of a type `F` satisfying `OrderIsoClass F α β` and `MulEquivClass F α β`
into an actual `OrderMonoidIso`. This is declared as the default coercion from `F` to `α ≃*o β`. -/
@[to_additive (attr := coe)
/-- Turn an element of a type `F` satisfying `OrderIsoClass F α β` and `AddEquivClass F α β`
into an actual `OrderAddMonoidIso`.
This is declared as the default coercion from `F` to `α ≃+o β`. -/]
def OrderMonoidIsoClass.toOrderMonoidIso [EquivLike F α β] [OrderIsoClass F α β]
[MulEquivClass F α β] (f : F) :
α ≃*o β :=
{ (f : α ≃* β) with map_le_map_iff' := OrderIsoClass.map_le_map_iff f }
/-- Any type satisfying `OrderMonoidIsoClass` can be cast into `OrderMonoidIso` via
`OrderMonoidIsoClass.toOrderMonoidIso`. -/
@[to_additive /-- Any type satisfying `OrderAddMonoidIsoClass` can be cast into `OrderAddMonoidIso`
via `OrderAddMonoidIsoClass.toOrderAddMonoidIso`. -/]
instance [EquivLike F α β] [OrderIsoClass F α β] [MulEquivClass F α β] : CoeTC F (α ≃*o β) :=
⟨OrderMonoidIsoClass.toOrderMonoidIso⟩
end Monoid
section OrderedZero
variable [FunLike F α β]
variable [Preorder α] [Zero α] [Preorder β] [Zero β] [OrderHomClass F α β]
[ZeroHomClass F α β] (f : F) {a : α}
/-- See also `NonnegHomClass.apply_nonneg`. -/
theorem map_nonneg (ha : 0 ≤ a) : 0 ≤ f a := by
rw [← map_zero f]
exact OrderHomClass.mono _ ha
theorem map_nonpos (ha : a ≤ 0) : f a ≤ 0 := by
rw [← map_zero f]
exact OrderHomClass.mono _ ha
end OrderedZero
section OrderedAddCommGroup
variable [AddCommGroup α] [PartialOrder α] [IsOrderedAddMonoid α]
[AddCommGroup β] [PartialOrder β] [IsOrderedAddMonoid β] [i : FunLike F α β]
variable (f : F)
theorem monotone_iff_map_nonneg [iamhc : AddMonoidHomClass F α β] :
Monotone (f : α → β) ↔ ∀ a, 0 ≤ a → 0 ≤ f a :=
⟨fun h a => by
rw [← map_zero f]
apply h, fun h a b hl => by
rw [← sub_add_cancel b a, map_add f]
exact le_add_of_nonneg_left (h _ <| sub_nonneg.2 hl)⟩
variable [iamhc : AddMonoidHomClass F α β]
theorem antitone_iff_map_nonpos : Antitone (f : α → β) ↔ ∀ a, 0 ≤ a → f a ≤ 0 :=
monotone_toDual_comp_iff.symm.trans <| monotone_iff_map_nonneg (β := βᵒᵈ) (iamhc := iamhc) _
theorem monotone_iff_map_nonpos : Monotone (f : α → β) ↔ ∀ a ≤ 0, f a ≤ 0 :=
antitone_comp_ofDual_iff.symm.trans <| antitone_iff_map_nonpos (α := αᵒᵈ) (iamhc := iamhc) _
theorem antitone_iff_map_nonneg : Antitone (f : α → β) ↔ ∀ a ≤ 0, 0 ≤ f a :=
monotone_comp_ofDual_iff.symm.trans <| monotone_iff_map_nonneg (α := αᵒᵈ) (iamhc := iamhc) _
theorem strictMono_iff_map_pos :
StrictMono (f : α → β) ↔ ∀ a, 0 < a → 0 < f a := by
refine ⟨fun h a => ?_, fun h a b hl => ?_⟩
· rw [← map_zero f]
apply h
· rw [← sub_add_cancel b a, map_add f]
exact lt_add_of_pos_left _ (h _ <| sub_pos.2 hl)
theorem strictAnti_iff_map_neg : StrictAnti (f : α → β) ↔ ∀ a, 0 < a → f a < 0 :=
strictMono_toDual_comp_iff.symm.trans <| strictMono_iff_map_pos (β := βᵒᵈ) (iamhc := iamhc) _
theorem strictMono_iff_map_neg : StrictMono (f : α → β) ↔ ∀ a < 0, f a < 0 :=
strictAnti_comp_ofDual_iff.symm.trans <| strictAnti_iff_map_neg (α := αᵒᵈ) (iamhc := iamhc) _
theorem strictAnti_iff_map_pos : StrictAnti (f : α → β) ↔ ∀ a < 0, 0 < f a :=
strictMono_comp_ofDual_iff.symm.trans <| strictMono_iff_map_pos (α := αᵒᵈ) (iamhc := iamhc) _
end OrderedAddCommGroup
namespace OrderMonoidHom
section Preorder
variable [Preorder α] [Preorder β] [Preorder γ] [Preorder δ] [MulOneClass α] [MulOneClass β]
[MulOneClass γ] [MulOneClass δ] {f g : α →*o β}
@[to_additive]
instance : FunLike (α →*o β) α β where
coe f := f.toFun
coe_injective' f g h := by
obtain ⟨⟨⟨_, _⟩⟩, _⟩ := f
obtain ⟨⟨⟨_, _⟩⟩, _⟩ := g
congr
initialize_simps_projections OrderAddMonoidHom (toFun → apply, -toAddMonoidHom)
initialize_simps_projections OrderMonoidHom (toFun → apply, -toMonoidHom)
@[to_additive]
instance : OrderHomClass (α →*o β) α β where
map_rel f _ _ h := f.monotone' h
@[to_additive]
instance : MonoidHomClass (α →*o β) α β where
map_mul f := f.map_mul'
map_one f := f.map_one'
-- Other lemmas should be accessed through the `FunLike` API
@[to_additive (attr := ext)]
theorem ext (h : ∀ a, f a = g a) : f = g :=
DFunLike.ext f g h
@[to_additive]
theorem toFun_eq_coe (f : α →*o β) : f.toFun = (f : α → β) :=
rfl
@[to_additive (attr := simp)]
theorem coe_mk (f : α →* β) (h) : (OrderMonoidHom.mk f h : α → β) = f :=
rfl
@[to_additive (attr := simp)]
theorem mk_coe (f : α →*o β) (h) : OrderMonoidHom.mk (f : α →* β) h = f := by
ext
rfl
/-- Reinterpret an ordered monoid homomorphism as an order homomorphism. -/
@[to_additive /-- Reinterpret an ordered additive monoid homomorphism as an order homomorphism. -/]
def toOrderHom (f : α →*o β) : α →o β :=
{ f with }
@[to_additive (attr := simp)]
theorem coe_monoidHom (f : α →*o β) : ((f : α →* β) : α → β) = f :=
rfl
@[to_additive (attr := simp)]
theorem coe_orderHom (f : α →*o β) : ((f : α →o β) : α → β) = f :=
rfl
@[to_additive]
theorem toMonoidHom_injective : Injective (toMonoidHom : _ → α →* β) := fun f g h =>
ext <| by convert DFunLike.ext_iff.1 h using 0
@[to_additive]
theorem toOrderHom_injective : Injective (toOrderHom : _ → α →o β) := fun f g h =>
ext <| by convert DFunLike.ext_iff.1 h using 0
/-- Copy of an `OrderMonoidHom` with a new `toFun` equal to the old one. Useful to fix
definitional equalities. -/
@[to_additive /-- Copy of an `OrderAddMonoidHom` with a new `toFun` equal to the old one. Useful to
fix definitional equalities. -/]
protected def copy (f : α →*o β) (f' : α → β) (h : f' = f) : α →*o β :=
{ f.toMonoidHom.copy f' h with toFun := f', monotone' := h.symm.subst f.monotone' }
@[to_additive (attr := simp)]
theorem coe_copy (f : α →*o β) (f' : α → β) (h : f' = f) : ⇑(f.copy f' h) = f' :=
rfl
@[to_additive]
theorem copy_eq (f : α →*o β) (f' : α → β) (h : f' = f) : f.copy f' h = f :=
DFunLike.ext' h
variable (α)
/-- The identity map as an ordered monoid homomorphism. -/
@[to_additive /-- The identity map as an ordered additive monoid homomorphism. -/]
protected def id : α →*o α :=
{ MonoidHom.id α, OrderHom.id with }
@[to_additive (attr := simp)]
theorem coe_id : ⇑(OrderMonoidHom.id α) = id :=
rfl
@[to_additive]
instance : Inhabited (α →*o α) :=
⟨OrderMonoidHom.id α⟩
variable {α}
/-- Composition of `OrderMonoidHom`s as an `OrderMonoidHom`. -/
@[to_additive /-- Composition of `OrderAddMonoidHom`s as an `OrderAddMonoidHom` -/]
def comp (f : β →*o γ) (g : α →*o β) : α →*o γ :=
{ f.toMonoidHom.comp (g : α →* β), f.toOrderHom.comp (g : α →o β) with }
@[to_additive (attr := simp)]
theorem coe_comp (f : β →*o γ) (g : α →*o β) : (f.comp g : α → γ) = f ∘ g :=
rfl
@[to_additive (attr := simp)]
theorem comp_apply (f : β →*o γ) (g : α →*o β) (a : α) : (f.comp g) a = f (g a) :=
rfl
@[to_additive]
theorem coe_comp_monoidHom (f : β →*o γ) (g : α →*o β) :
(f.comp g : α →* γ) = (f : β →* γ).comp g :=
rfl
@[to_additive]
theorem coe_comp_orderHom (f : β →*o γ) (g : α →*o β) :
(f.comp g : α →o γ) = (f : β →o γ).comp g :=
rfl
@[to_additive (attr := simp)]
theorem comp_assoc (f : γ →*o δ) (g : β →*o γ) (h : α →*o β) :
(f.comp g).comp h = f.comp (g.comp h) :=
rfl
@[to_additive (attr := simp)]
theorem comp_id (f : α →*o β) : f.comp (OrderMonoidHom.id α) = f :=
rfl
@[to_additive (attr := simp)]
theorem id_comp (f : α →*o β) : (OrderMonoidHom.id β).comp f = f :=
rfl
@[to_additive (attr := simp)]
theorem cancel_right {g₁ g₂ : β →*o γ} {f : α →*o β} (hf : Function.Surjective f) :
g₁.comp f = g₂.comp f ↔ g₁ = g₂ :=
⟨fun h => ext <| hf.forall.2 <| DFunLike.ext_iff.1 h, fun _ => by congr⟩
@[to_additive (attr := simp)]
theorem cancel_left {g : β →*o γ} {f₁ f₂ : α →*o β} (hg : Function.Injective g) :
g.comp f₁ = g.comp f₂ ↔ f₁ = f₂ :=
⟨fun h => ext fun a => hg <| by rw [← comp_apply, h, comp_apply], congr_arg _⟩
/-- `1` is the homomorphism sending all elements to `1`. -/
@[to_additive /-- `0` is the homomorphism sending all elements to `0`. -/]
instance : One (α →*o β) :=
⟨{ (1 : α →* β) with monotone' := monotone_const }⟩
@[to_additive (attr := simp)]
theorem coe_one : ⇑(1 : α →*o β) = 1 :=
rfl
@[to_additive (attr := simp)]
theorem one_apply (a : α) : (1 : α →*o β) a = 1 :=
rfl
@[to_additive (attr := simp)]
theorem one_comp (f : α →*o β) : (1 : β →*o γ).comp f = 1 :=
rfl
@[to_additive (attr := simp)]
theorem comp_one (f : β →*o γ) : f.comp (1 : α →*o β) = 1 :=
ext fun _ => map_one f
end Preorder
section Mul
variable [CommMonoid α] [PartialOrder α]
[CommMonoid β] [PartialOrder β]
[CommMonoid γ] [PartialOrder γ]
/-- For two ordered monoid morphisms `f` and `g`, their product is the ordered monoid morphism
sending `a` to `f a * g a`. -/
@[to_additive /-- For two ordered additive monoid morphisms `f` and `g`, their product is the
ordered additive monoid morphism sending `a` to `f a + g a`. -/]
instance [IsOrderedMonoid β] : Mul (α →*o β) :=
⟨fun f g => { (f * g : α →* β) with monotone' := f.monotone'.mul' g.monotone' }⟩
@[to_additive (attr := simp)]
theorem coe_mul [IsOrderedMonoid β] (f g : α →*o β) : ⇑(f * g) = f * g :=
rfl
@[to_additive (attr := simp)]
theorem mul_apply [IsOrderedMonoid β] (f g : α →*o β) (a : α) : (f * g) a = f a * g a :=
rfl
@[to_additive]
theorem mul_comp [IsOrderedMonoid γ] (g₁ g₂ : β →*o γ) (f : α →*o β) :
(g₁ * g₂).comp f = g₁.comp f * g₂.comp f :=
rfl
@[to_additive]
theorem comp_mul [IsOrderedMonoid β] [IsOrderedMonoid γ] (g : β →*o γ) (f₁ f₂ : α →*o β) :
g.comp (f₁ * f₂) = g.comp f₁ * g.comp f₂ :=
ext fun _ => map_mul g _ _
end Mul
section OrderedCommMonoid
variable {_ : Preorder α} {_ : Preorder β} {_ : MulOneClass α} {_ : MulOneClass β}
@[to_additive (attr := simp)]
theorem toMonoidHom_eq_coe (f : α →*o β) : f.toMonoidHom = f :=
rfl
@[to_additive (attr := simp)]
theorem toOrderHom_eq_coe (f : α →*o β) : f.toOrderHom = f :=
rfl
end OrderedCommMonoid
section OrderedCommGroup
variable {_ : CommGroup α} {_ : PartialOrder α} {_ : CommGroup β} {_ : PartialOrder β}
/-- Makes an ordered group homomorphism from a proof that the map preserves multiplication. -/
@[to_additive
/-- Makes an ordered additive group homomorphism from a proof that the map preserves
addition. -/]
def mk' (f : α → β) (hf : Monotone f) (map_mul : ∀ a b : α, f (a * b) = f a * f b) : α →*o β :=
{ MonoidHom.mk' f map_mul with monotone' := hf }
end OrderedCommGroup
end OrderMonoidHom
namespace OrderMonoidIso
section Preorder
variable [Preorder α] [Preorder β] [Preorder γ] [Preorder δ] [Mul α] [Mul β]
[Mul γ] [Mul δ] {f g : α ≃*o β}
@[to_additive]
instance : EquivLike (α ≃*o β) α β where
coe f := f.toFun
inv f := f.invFun
left_inv f := f.left_inv
right_inv f := f.right_inv
coe_injective' f g h₁ h₂ := by
obtain ⟨⟨⟨_, _⟩⟩, _⟩ := f
obtain ⟨⟨⟨_, _⟩⟩, _⟩ := g
congr
@[to_additive]
instance : OrderIsoClass (α ≃*o β) α β where
map_le_map_iff f := f.map_le_map_iff'
@[to_additive]
instance : MulEquivClass (α ≃*o β) α β where
map_mul f := map_mul f.toMulEquiv
-- Other lemmas should be accessed through the `FunLike` API
@[to_additive (attr := ext)]
theorem ext (h : ∀ a, f a = g a) : f = g :=
DFunLike.ext f g h
@[to_additive]
theorem toFun_eq_coe (f : α ≃*o β) : f.toFun = (f : α → β) :=
rfl
@[to_additive (attr := simp)]
theorem coe_mk (f : α ≃* β) (h) : (OrderMonoidIso.mk f h : α → β) = f :=
rfl
@[to_additive (attr := simp)]
theorem mk_coe (f : α ≃*o β) (h) : OrderMonoidIso.mk (f : α ≃* β) h = f := rfl
/-- Reinterpret an ordered monoid isomorphism as an order isomorphism. -/
@[to_additive
/-- Reinterpret an ordered additive monoid isomomorphism as an order isomomorphism. -/]
def toOrderIso (f : α ≃*o β) : α ≃o β :=
{ f with
map_rel_iff' := map_le_map_iff f }
@[to_additive (attr := simp)]
theorem coe_mulEquiv (f : α ≃*o β) : ((f : α ≃* β) : α → β) = f :=
rfl
@[to_additive (attr := simp)]
theorem coe_orderIso (f : α ≃*o β) : ((f : α →o β) : α → β) = f :=
rfl
@[to_additive]
theorem toMulEquiv_injective : Injective (toMulEquiv : _ → α ≃* β) := fun f g h =>
ext <| by convert DFunLike.ext_iff.1 h using 0
@[to_additive]
theorem toOrderIso_injective : Injective (toOrderIso : _ → α ≃o β) := fun f g h =>
ext <| by convert DFunLike.ext_iff.1 h using 0
variable (α)
/-- The identity map as an ordered monoid isomorphism. -/
@[to_additive /-- The identity map as an ordered additive monoid isomorphism. -/]
protected def refl : α ≃*o α :=
{ MulEquiv.refl α with map_le_map_iff' := by simp }
@[to_additive (attr := simp)]
theorem coe_refl : ⇑(OrderMonoidIso.refl α) = id :=
rfl
@[to_additive]
instance : Inhabited (α ≃*o α) :=
⟨OrderMonoidIso.refl α⟩
variable {α}
/-- Transitivity of multiplication-preserving order isomorphisms -/
@[to_additive (attr := trans) /-- Transitivity of addition-preserving order isomorphisms -/]
def trans (f : α ≃*o β) (g : β ≃*o γ) : α ≃*o γ :=
{ (f : α ≃* β).trans g with map_le_map_iff' := by simp }
@[to_additive (attr := simp)]
theorem coe_trans (f : α ≃*o β) (g : β ≃*o γ) : (f.trans g : α → γ) = g ∘ f :=
rfl
@[to_additive (attr := simp)]
theorem trans_apply (f : α ≃*o β) (g : β ≃*o γ) (a : α) : (f.trans g) a = g (f a) :=
rfl
@[to_additive]
theorem coe_trans_mulEquiv (f : α ≃*o β) (g : β ≃*o γ) :
(f.trans g : α ≃* γ) = (f : α ≃* β).trans g :=
rfl
@[to_additive]
theorem coe_trans_orderIso (f : α ≃*o β) (g : β ≃*o γ) :
(f.trans g : α ≃o γ) = (f : α ≃o β).trans g :=
rfl
@[to_additive (attr := simp)]
theorem trans_assoc (f : α ≃*o β) (g : β ≃*o γ) (h : γ ≃*o δ) :
(f.trans g).trans h = f.trans (g.trans h) :=
rfl
@[to_additive (attr := simp)]
theorem trans_refl (f : α ≃*o β) : f.trans (OrderMonoidIso.refl β) = f :=
rfl
@[to_additive (attr := simp)]
theorem refl_trans (f : α ≃*o β) : (OrderMonoidIso.refl α).trans f = f :=
rfl
@[to_additive (attr := simp)]
theorem cancel_right {g₁ g₂ : α ≃*o β} {f : β ≃*o γ} (hf : Function.Injective f) :
g₁.trans f = g₂.trans f ↔ g₁ = g₂ :=
⟨fun h => ext fun a => hf <| by rw [← trans_apply, h, trans_apply], by rintro rfl; rfl⟩
@[to_additive (attr := simp)]
theorem cancel_left {g : α ≃*o β} {f₁ f₂ : β ≃*o γ} (hg : Function.Surjective g) :
g.trans f₁ = g.trans f₂ ↔ f₁ = f₂ :=
⟨fun h => ext <| hg.forall.2 <| DFunLike.ext_iff.1 h, fun _ => by congr⟩
@[to_additive (attr := simp)]
theorem toMulEquiv_eq_coe (f : α ≃*o β) : f.toMulEquiv = f :=
rfl
@[to_additive (attr := simp)]
theorem toOrderIso_eq_coe (f : α ≃*o β) : f.toOrderIso = f :=
rfl
/-- The inverse of an isomorphism is an isomorphism. -/
@[to_additive (attr := symm) /-- The inverse of an order isomorphism is an order isomorphism. -/]
def symm (f : α ≃*o β) : β ≃*o α :=
⟨f.toMulEquiv.symm, f.toOrderIso.symm.map_rel_iff⟩
/-- See Note [custom simps projection]. -/
@[to_additive /-- See Note [custom simps projection]. -/]
def Simps.apply (h : α ≃*o β) : α → β :=
h
/-- See Note [custom simps projection] -/
@[to_additive /-- See Note [custom simps projection]. -/]
def Simps.symm_apply (h : α ≃*o β) : β → α :=
h.symm
initialize_simps_projections OrderAddMonoidIso (toFun → apply, invFun → symm_apply)
initialize_simps_projections OrderMonoidIso (toFun → apply, invFun → symm_apply)
@[to_additive]
theorem invFun_eq_symm {f : α ≃*o β} : f.invFun = f.symm := rfl
/-- `simp`-normal form of `invFun_eq_symm`. -/
@[to_additive (attr := simp)]
theorem coe_toEquiv_symm (f : α ≃*o β) : ((f : α ≃ β).symm : β → α) = f.symm := rfl
@[to_additive (attr := simp)]
theorem equivLike_inv_eq_symm (f : α ≃*o β) : EquivLike.inv f = f.symm := rfl
@[to_additive (attr := simp)]
theorem toEquiv_symm (f : α ≃*o β) : (f.symm : β ≃ α) = (f : α ≃ β).symm := rfl
@[to_additive (attr := simp)]
theorem symm_symm (f : α ≃*o β) : f.symm.symm = f := rfl
@[to_additive]
theorem symm_bijective : Function.Bijective (symm : (α ≃*o β) → β ≃*o α) :=
Function.bijective_iff_has_inverse.mpr ⟨_, symm_symm, symm_symm⟩
@[to_additive (attr := simp)]
theorem refl_symm : (OrderMonoidIso.refl α).symm = .refl α := rfl
/-- `e.symm` is a right inverse of `e`, written as `e (e.symm y) = y`. -/
@[to_additive (attr := simp)
/-- `e.symm` is a right inverse of `e`, written as `e (e.symm y) = y`. -/]
theorem apply_symm_apply (e : α ≃*o β) (y : β) : e (e.symm y) = y :=
e.toEquiv.apply_symm_apply y
/-- `e.symm` is a left inverse of `e`, written as `e.symm (e y) = y`. -/
@[to_additive (attr := simp)
/-- `e.symm` is a left inverse of `e`, written as `e.symm (e y) = y`. -/]
theorem symm_apply_apply (e : α ≃*o β) (x : α) : e.symm (e x) = x :=
e.toEquiv.symm_apply_apply x
@[to_additive (attr := simp)]
theorem symm_comp_self (e : α ≃*o β) : e.symm ∘ e = id :=
funext e.symm_apply_apply
@[to_additive (attr := simp)]
theorem self_comp_symm (e : α ≃*o β) : e ∘ e.symm = id :=
funext e.apply_symm_apply
@[to_additive]
theorem apply_eq_iff_symm_apply (e : α ≃*o β) {x : α} {y : β} : e x = y ↔ x = e.symm y :=
e.toEquiv.apply_eq_iff_eq_symm_apply
@[to_additive]
theorem symm_apply_eq (e : α ≃*o β) {x y} : e.symm x = y ↔ x = e y :=
e.toEquiv.symm_apply_eq
@[to_additive]
theorem eq_symm_apply (e : α ≃*o β) {x y} : y = e.symm x ↔ e y = x :=
e.toEquiv.eq_symm_apply
@[to_additive]
theorem eq_comp_symm (e : α ≃*o β) (f : β → α) (g : α → α) :
f = g ∘ e.symm ↔ f ∘ e = g :=
e.toEquiv.eq_comp_symm f g
@[to_additive]
theorem comp_symm_eq (e : α ≃*o β) (f : β → α) (g : α → α) :
g ∘ e.symm = f ↔ g = f ∘ e :=
e.toEquiv.comp_symm_eq f g
@[to_additive]
theorem eq_symm_comp (e : α ≃*o β) (f : α → α) (g : α → β) :
f = e.symm ∘ g ↔ e ∘ f = g :=
e.toEquiv.eq_symm_comp f g
@[to_additive]
theorem symm_comp_eq (e : α ≃*o β) (f : α → α) (g : α → β) :
e.symm ∘ g = f ↔ g = e ∘ f :=
e.toEquiv.symm_comp_eq f g
variable (f)
@[to_additive]
protected lemma strictMono : StrictMono f :=
strictMono_of_le_iff_le fun _ _ ↦ (map_le_map_iff _).symm
@[to_additive]
protected lemma strictMono_symm : StrictMono f.symm :=
strictMono_of_le_iff_le <| fun a b ↦ by
rw [← map_le_map_iff f]
convert Iff.rfl <;>
exact f.toEquiv.apply_symm_apply _
end Preorder
section OrderedCommGroup
variable {_ : CommGroup α} {_ : PartialOrder α} {_ : CommGroup β} {_ : PartialOrder β}
/-- Makes an ordered group isomorphism from a proof that the map preserves multiplication. -/
@[to_additive
/-- Makes an ordered additive group isomorphism from a proof that the map preserves
addition. -/]
def mk' (f : α ≃ β) (hf : ∀ {a b}, f a ≤ f b ↔ a ≤ b) (map_mul : ∀ a b : α, f (a * b) = f a * f b) :
α ≃*o β :=
{ MulEquiv.mk' f map_mul with map_le_map_iff' := hf }
end OrderedCommGroup
end OrderMonoidIso |
.lake/packages/mathlib/Mathlib/Algebra/Order/Hom/Ring.lean | import Mathlib.Algebra.Order.Hom.MonoidWithZero
import Mathlib.Algebra.Ring.Equiv
/-!
# Ordered ring homomorphisms
Homomorphisms between ordered (semi)rings that respect the ordering.
## Main definitions
* `OrderRingHom` : Monotone semiring homomorphisms.
* `OrderRingIso` : Monotone semiring isomorphisms.
## Notation
* `→+*o`: Ordered ring homomorphisms.
* `≃+*o`: Ordered ring isomorphisms.
## Implementation notes
This file used to define typeclasses for order-preserving ring homomorphisms and isomorphisms.
In https://github.com/leanprover-community/mathlib4/pull/10544, we migrated from assumptions like `[FunLike F R S] [OrderRingHomClass F R S]`
to assumptions like `[FunLike F R S] [OrderHomClass F R S] [RingHomClass F R S]`,
making some typeclasses and instances irrelevant.
## Tags
ordered ring homomorphism, order homomorphism
-/
assert_not_exists FloorRing Archimedean
open Function
variable {F α β γ δ : Type*}
/-- `OrderRingHom α β`, denoted `α →+*o β`,
is the type of monotone semiring homomorphisms from `α` to `β`.
When possible, instead of parametrizing results over `(f : OrderRingHom α β)`,
you should parametrize over `(F : Type*) [OrderRingHomClass F α β] (f : F)`.
When you extend this structure, make sure to extend `OrderRingHomClass`. -/
structure OrderRingHom (α β : Type*) [NonAssocSemiring α] [Preorder α] [NonAssocSemiring β]
[Preorder β] extends α →+* β where
/-- The proposition that the function preserves the order. -/
monotone' : Monotone toFun
/-- Reinterpret an ordered ring homomorphism as a ring homomorphism. -/
add_decl_doc OrderRingHom.toRingHom
@[inherit_doc]
infixl:25 " →+*o " => OrderRingHom
/-- `OrderRingIso α β`, denoted as `α ≃+*o β`,
is the type of order-preserving semiring isomorphisms between `α` and `β`.
When possible, instead of parametrizing results over `(f : OrderRingIso α β)`,
you should parametrize over `(F : Type*) [OrderRingIsoClass F α β] (f : F)`.
When you extend this structure, make sure to extend `OrderRingIsoClass`. -/
structure OrderRingIso (α β : Type*) [Mul α] [Add α] [Mul β] [Add β] [LE α] [LE β] extends
α ≃+* β where
/-- The proposition that the function preserves the order bijectively. -/
map_le_map_iff' {a b : α} : toFun a ≤ toFun b ↔ a ≤ b
@[inherit_doc]
infixl:25 " ≃+*o " => OrderRingIso
-- See module docstring for details
section Hom
variable [FunLike F α β]
/-- Turn an element of a type `F` satisfying `OrderHomClass F α β` and `RingHomClass F α β`
into an actual `OrderRingHom`.
This is declared as the default coercion from `F` to `α →+*o β`. -/
@[coe]
def OrderRingHomClass.toOrderRingHom [NonAssocSemiring α] [Preorder α] [NonAssocSemiring β]
[Preorder β] [OrderHomClass F α β] [RingHomClass F α β] (f : F) : α →+*o β :=
{ (f : α →+* β) with monotone' := OrderHomClass.monotone f}
/-- Any type satisfying `OrderRingHomClass` can be cast into `OrderRingHom` via
`OrderRingHomClass.toOrderRingHom`. -/
instance [NonAssocSemiring α] [Preorder α] [NonAssocSemiring β] [Preorder β]
[OrderHomClass F α β] [RingHomClass F α β] : CoeTC F (α →+*o β) :=
⟨OrderRingHomClass.toOrderRingHom⟩
end Hom
section Equiv
variable [EquivLike F α β]
/-- Turn an element of a type `F` satisfying `OrderIsoClass F α β` and `RingEquivClass F α β`
into an actual `OrderRingIso`.
This is declared as the default coercion from `F` to `α ≃+*o β`. -/
@[coe]
def OrderRingIsoClass.toOrderRingIso [Mul α] [Add α] [LE α] [Mul β] [Add β] [LE β]
[OrderIsoClass F α β] [RingEquivClass F α β] (f : F) : α ≃+*o β :=
{ (f : α ≃+* β) with map_le_map_iff' := map_le_map_iff f}
/-- Any type satisfying `OrderRingIsoClass` can be cast into `OrderRingIso` via
`OrderRingIsoClass.toOrderRingIso`. -/
instance [Mul α] [Add α] [LE α] [Mul β] [Add β] [LE β] [OrderIsoClass F α β]
[RingEquivClass F α β] : CoeTC F (α ≃+*o β) :=
⟨OrderRingIsoClass.toOrderRingIso⟩
end Equiv
/-! ### Ordered ring homomorphisms -/
namespace OrderRingHom
variable [NonAssocSemiring α] [Preorder α]
section Preorder
variable [NonAssocSemiring β] [Preorder β] [NonAssocSemiring γ] [Preorder γ] [NonAssocSemiring δ]
[Preorder δ]
/-- Reinterpret an ordered ring homomorphism as an ordered additive monoid homomorphism. -/
def toOrderAddMonoidHom (f : α →+*o β) : α →+o β :=
{ f with }
/-- Reinterpret an ordered ring homomorphism as an order homomorphism. -/
def toOrderMonoidWithZeroHom (f : α →+*o β) : α →*₀o β :=
{ f with }
instance : FunLike (α →+*o β) α β where
coe f := f.toFun
coe_injective' f g h := by
cases f; cases g; congr
exact DFunLike.coe_injective' h
instance : OrderHomClass (α →+*o β) α β where
map_rel f _ _ h := f.monotone' h
instance : RingHomClass (α →+*o β) α β where
map_mul f := f.map_mul'
map_one f := f.map_one'
map_add f := f.map_add'
map_zero f := f.map_zero'
theorem toFun_eq_coe (f : α →+*o β) : f.toFun = f :=
rfl
@[ext]
theorem ext {f g : α →+*o β} (h : ∀ a, f a = g a) : f = g :=
DFunLike.ext f g h
@[simp]
theorem toRingHom_eq_coe (f : α →+*o β) : f.toRingHom = f :=
RingHom.ext fun _ => rfl
@[simp]
theorem toOrderAddMonoidHom_eq_coe (f : α →+*o β) : f.toOrderAddMonoidHom = f :=
rfl
@[simp]
theorem toOrderMonoidWithZeroHom_eq_coe (f : α →+*o β) : f.toOrderMonoidWithZeroHom = f :=
rfl
@[simp]
theorem coe_coe_ringHom (f : α →+*o β) : ⇑(f : α →+* β) = f :=
rfl
@[simp]
theorem coe_coe_orderAddMonoidHom (f : α →+*o β) : ⇑(f : α →+o β) = f :=
rfl
@[simp]
theorem coe_coe_orderMonoidWithZeroHom (f : α →+*o β) : ⇑(f : α →*₀o β) = f :=
rfl
@[norm_cast]
theorem coe_ringHom_apply (f : α →+*o β) (a : α) : (f : α →+* β) a = f a :=
rfl
@[norm_cast]
theorem coe_orderAddMonoidHom_apply (f : α →+*o β) (a : α) : (f : α →+o β) a = f a :=
rfl
@[norm_cast]
theorem coe_orderMonoidWithZeroHom_apply (f : α →+*o β) (a : α) : (f : α →*₀o β) a = f a :=
rfl
/-- Copy of an `OrderRingHom` with a new `toFun` equal to the old one. Useful to fix definitional
equalities. -/
protected def copy (f : α →+*o β) (f' : α → β) (h : f' = f) : α →+*o β :=
{ f.toRingHom.copy f' h, f.toOrderAddMonoidHom.copy f' h with }
@[simp]
theorem coe_copy (f : α →+*o β) (f' : α → β) (h : f' = f) : ⇑(f.copy f' h) = f' :=
rfl
theorem copy_eq (f : α →+*o β) (f' : α → β) (h : f' = f) : f.copy f' h = f :=
DFunLike.ext' h
variable (α)
/-- The identity as an ordered ring homomorphism. -/
protected def id : α →+*o α :=
{ RingHom.id _, OrderHom.id with }
instance : Inhabited (α →+*o α) :=
⟨OrderRingHom.id α⟩
@[simp, norm_cast]
theorem coe_id : ⇑(OrderRingHom.id α) = id :=
rfl
variable {α}
@[simp]
theorem id_apply (a : α) : OrderRingHom.id α a = a :=
rfl
@[simp]
theorem coe_ringHom_id : (OrderRingHom.id α : α →+* α) = RingHom.id α :=
rfl
@[simp]
theorem coe_orderAddMonoidHom_id : (OrderRingHom.id α : α →+o α) = OrderAddMonoidHom.id α :=
rfl
@[simp]
theorem coe_orderMonoidWithZeroHom_id :
(OrderRingHom.id α : α →*₀o α) = OrderMonoidWithZeroHom.id α :=
rfl
/-- Composition of two `OrderRingHom`s as an `OrderRingHom`. -/
protected def comp (f : β →+*o γ) (g : α →+*o β) : α →+*o γ :=
{ f.toRingHom.comp g.toRingHom, f.toOrderAddMonoidHom.comp g.toOrderAddMonoidHom with }
@[simp]
theorem coe_comp (f : β →+*o γ) (g : α →+*o β) : ⇑(f.comp g) = f ∘ g :=
rfl
@[simp]
theorem comp_apply (f : β →+*o γ) (g : α →+*o β) (a : α) : f.comp g a = f (g a) :=
rfl
theorem comp_assoc (f : γ →+*o δ) (g : β →+*o γ) (h : α →+*o β) :
(f.comp g).comp h = f.comp (g.comp h) :=
rfl
@[simp]
theorem comp_id (f : α →+*o β) : f.comp (OrderRingHom.id α) = f :=
rfl
@[simp]
theorem id_comp (f : α →+*o β) : (OrderRingHom.id β).comp f = f :=
rfl
@[simp]
theorem cancel_right {f₁ f₂ : β →+*o γ} {g : α →+*o β} (hg : Surjective g) :
f₁.comp g = f₂.comp g ↔ f₁ = f₂ :=
⟨fun h => ext <| hg.forall.2 <| DFunLike.ext_iff.1 h, fun h => by rw [h]⟩
@[simp]
theorem cancel_left {f : β →+*o γ} {g₁ g₂ : α →+*o β} (hf : Injective f) :
f.comp g₁ = f.comp g₂ ↔ g₁ = g₂ :=
⟨fun h => ext fun a => hf <| by rw [← comp_apply, h, comp_apply], congr_arg _⟩
end Preorder
variable [NonAssocSemiring β]
instance [Preorder β] : Preorder (OrderRingHom α β) :=
Preorder.lift ((⇑) : _ → α → β)
instance [PartialOrder β] : PartialOrder (OrderRingHom α β) :=
PartialOrder.lift _ DFunLike.coe_injective
end OrderRingHom
/-! ### Ordered ring isomorphisms -/
namespace OrderRingIso
section LE
variable [Mul α] [Add α] [LE α] [Mul β] [Add β] [LE β] [Mul γ] [Add γ] [LE γ]
/-- Reinterpret an ordered ring isomorphism as an order isomorphism. -/
@[coe]
def toOrderIso (f : α ≃+*o β) : α ≃o β :=
⟨f.toRingEquiv.toEquiv, f.map_le_map_iff'⟩
instance : EquivLike (α ≃+*o β) α β where
coe f := f.toFun
inv f := f.invFun
coe_injective' f g h₁ h₂ := by
obtain ⟨⟨⟨_, _⟩, _⟩, _⟩ := f
obtain ⟨⟨⟨_, _⟩, _⟩, _⟩ := g
congr
left_inv f := f.left_inv
right_inv f := f.right_inv
instance : OrderIsoClass (α ≃+*o β) α β where
map_le_map_iff f _ _ := f.map_le_map_iff'
instance : RingEquivClass (α ≃+*o β) α β where
map_mul f := f.map_mul'
map_add f := f.map_add'
theorem toFun_eq_coe (f : α ≃+*o β) : f.toFun = f :=
rfl
@[ext]
theorem ext {f g : α ≃+*o β} (h : ∀ a, f a = g a) : f = g :=
DFunLike.ext f g h
@[simp]
theorem coe_mk (e : α ≃+* β) (h) : ⇑(⟨e, h⟩ : α ≃+*o β) = e :=
rfl
@[simp]
theorem mk_coe (e : α ≃+*o β) (h) : (⟨e, h⟩ : α ≃+*o β) = e :=
ext fun _ => rfl
@[simp]
theorem toRingEquiv_eq_coe (f : α ≃+*o β) : f.toRingEquiv = f :=
RingEquiv.ext fun _ => rfl
@[simp]
theorem toOrderIso_eq_coe (f : α ≃+*o β) : f.toOrderIso = f :=
OrderIso.ext rfl
@[simp, norm_cast]
theorem coe_toRingEquiv (f : α ≃+*o β) : ⇑(f : α ≃+* β) = f :=
rfl
@[simp, norm_cast]
theorem coe_toOrderIso (f : α ≃+*o β) : DFunLike.coe (f : α ≃o β) = f :=
rfl
variable (α)
/-- The identity map as an ordered ring isomorphism. -/
@[refl]
protected def refl : α ≃+*o α :=
⟨RingEquiv.refl α, Iff.rfl⟩
instance : Inhabited (α ≃+*o α) :=
⟨OrderRingIso.refl α⟩
@[simp]
theorem refl_apply (x : α) : OrderRingIso.refl α x = x := by
rfl
@[simp]
theorem coe_ringEquiv_refl : (OrderRingIso.refl α : α ≃+* α) = RingEquiv.refl α :=
rfl
@[simp]
theorem coe_orderIso_refl : (OrderRingIso.refl α : α ≃o α) = OrderIso.refl α :=
rfl
variable {α}
/-- The inverse of an ordered ring isomorphism as an ordered ring isomorphism. -/
@[symm]
protected def symm (e : α ≃+*o β) : β ≃+*o α :=
⟨e.toRingEquiv.symm, by
intro a b
erw [← map_le_map_iff e, e.1.apply_symm_apply, e.1.apply_symm_apply]⟩
/-- See Note [custom simps projection] -/
def Simps.symm_apply (e : α ≃+*o β) : β → α :=
e.symm
@[simp]
theorem symm_symm (e : α ≃+*o β) : e.symm.symm = e := rfl
theorem symm_bijective : Bijective (OrderRingIso.symm : (α ≃+*o β) → β ≃+*o α) :=
Function.bijective_iff_has_inverse.mpr ⟨_, symm_symm, symm_symm⟩
/-- Composition of `OrderRingIso`s as an `OrderRingIso`. -/
@[trans]
protected def trans (f : α ≃+*o β) (g : β ≃+*o γ) : α ≃+*o γ :=
⟨f.toRingEquiv.trans g.toRingEquiv, (map_le_map_iff g).trans (map_le_map_iff f)⟩
/-- This lemma used to be generated by [simps] on `trans`, but the lhs of this simplifies under
simp. Removed [simps] attribute and added aux version below. -/
theorem trans_toRingEquiv (f : α ≃+*o β) (g : β ≃+*o γ) :
(OrderRingIso.trans f g).toRingEquiv = RingEquiv.trans f.toRingEquiv g.toRingEquiv :=
rfl
/-- `simp`-normal form of `trans_toRingEquiv`. -/
@[simp]
theorem trans_toRingEquiv_aux (f : α ≃+*o β) (g : β ≃+*o γ) :
RingEquivClass.toRingEquiv (OrderRingIso.trans f g)
= RingEquiv.trans f.toRingEquiv g.toRingEquiv :=
rfl
@[simp]
theorem trans_apply (f : α ≃+*o β) (g : β ≃+*o γ) (a : α) : f.trans g a = g (f a) :=
rfl
@[simp]
theorem self_trans_symm (e : α ≃+*o β) : e.trans e.symm = OrderRingIso.refl α :=
ext e.left_inv
@[simp]
theorem symm_trans_self (e : α ≃+*o β) : e.symm.trans e = OrderRingIso.refl β :=
ext e.right_inv
end LE
section NonAssocSemiring
variable [NonAssocSemiring α] [Preorder α] [NonAssocSemiring β] [Preorder β]
/-- Reinterpret an ordered ring isomorphism as an ordered ring homomorphism. -/
def toOrderRingHom (f : α ≃+*o β) : α →+*o β :=
⟨f.toRingEquiv.toRingHom, fun _ _ => (map_le_map_iff f).2⟩
@[simp]
theorem toOrderRingHom_eq_coe (f : α ≃+*o β) : f.toOrderRingHom = f :=
rfl
@[simp, norm_cast]
theorem coe_toOrderRingHom (f : α ≃+*o β) : ⇑(f : α →+*o β) = f :=
rfl
@[simp]
theorem coe_toOrderRingHom_refl : (OrderRingIso.refl α : α →+*o α) = OrderRingHom.id α :=
rfl
theorem toOrderRingHom_injective : Injective (toOrderRingHom : α ≃+*o β → α →+*o β) :=
fun f g h => DFunLike.coe_injective <| by convert DFunLike.ext'_iff.1 h using 0
end NonAssocSemiring
end OrderRingIso |
.lake/packages/mathlib/Mathlib/Algebra/Order/Hom/MonoidWithZero.lean | import Mathlib.Algebra.Order.GroupWithZero.Canonical
import Mathlib.Algebra.Order.Hom.Monoid
/-!
# Ordered monoid and group homomorphisms
This file defines morphisms between (additive) ordered monoids with zero.
## Types of morphisms
* `OrderMonoidWithZeroHom`: Ordered monoid with zero homomorphisms.
## Notation
* `→*₀o`: Bundled ordered monoid with zero homs. Also use for group with zero homs.
## TODO
* `≃*₀o`: Bundled ordered monoid with zero isos. Also use for group with zero isos.
## Tags
monoid with zero
-/
open Function
variable {F α β γ δ : Type*}
section MonoidWithZero
variable [Preorder α] [Preorder β] [MulZeroOneClass α] [MulZeroOneClass β]
/-- `OrderMonoidWithZeroHom α β` is the type of functions `α → β` that preserve
the `MonoidWithZero` structure.
`OrderMonoidWithZeroHom` is also used for group homomorphisms.
When possible, instead of parametrizing results over `(f : α →+ β)`,
you should parameterize over
`(F : Type*) [FunLike F M N] [MonoidWithZeroHomClass F M N] [OrderHomClass F M N] (f : F)`. -/
structure OrderMonoidWithZeroHom (α β : Type*) [Preorder α] [Preorder β] [MulZeroOneClass α]
[MulZeroOneClass β] extends α →*₀ β where
/-- An `OrderMonoidWithZeroHom` is a monotone function. -/
monotone' : Monotone toFun
/-- Infix notation for `OrderMonoidWithZeroHom`. -/
infixr:25 " →*₀o " => OrderMonoidWithZeroHom
section
variable [FunLike F α β]
/-- Turn an element of a type `F`
satisfying `OrderHomClass F α β` and `MonoidWithZeroHomClass F α β`
into an actual `OrderMonoidWithZeroHom`.
This is declared as the default coercion from `F` to `α →+*₀o β`. -/
@[coe]
def OrderMonoidWithZeroHomClass.toOrderMonoidWithZeroHom [OrderHomClass F α β]
[MonoidWithZeroHomClass F α β] (f : F) : α →*₀o β :=
{ (f : α →*₀ β) with monotone' := OrderHomClass.monotone f }
end
variable [FunLike F α β]
instance [OrderHomClass F α β] [MonoidWithZeroHomClass F α β] : CoeTC F (α →*₀o β) :=
⟨OrderMonoidWithZeroHomClass.toOrderMonoidWithZeroHom⟩
end MonoidWithZero
namespace OrderMonoidWithZeroHom
section Preorder
variable [Preorder α] [Preorder β] [Preorder γ] [Preorder δ] [MulZeroOneClass α] [MulZeroOneClass β]
[MulZeroOneClass γ] [MulZeroOneClass δ] {f g : α →*₀o β}
instance : FunLike (α →*₀o β) α β where
coe f := f.toFun
coe_injective' f g h := by
obtain ⟨⟨⟨_, _⟩⟩, _⟩ := f
obtain ⟨⟨⟨_, _⟩⟩, _⟩ := g
congr
initialize_simps_projections OrderMonoidWithZeroHom (toFun → apply, -toMonoidWithZeroHom)
instance : MonoidWithZeroHomClass (α →*₀o β) α β where
map_mul f := f.map_mul'
map_one f := f.map_one'
map_zero f := f.map_zero'
instance : OrderHomClass (α →*₀o β) α β where
map_rel f _ _ h := f.monotone' h
-- Other lemmas should be accessed through the `FunLike` API
@[ext]
theorem ext (h : ∀ a, f a = g a) : f = g :=
DFunLike.ext f g h
theorem toFun_eq_coe (f : α →*₀o β) : f.toFun = (f : α → β) :=
rfl
@[simp]
theorem coe_mk (f : α →*₀ β) (h) : (OrderMonoidWithZeroHom.mk f h : α → β) = f :=
rfl
@[simp]
theorem mk_coe (f : α →*₀o β) (h) : OrderMonoidWithZeroHom.mk (f : α →*₀ β) h = f := rfl
/-- Reinterpret an ordered monoid with zero homomorphism as an order monoid homomorphism. -/
def toOrderMonoidHom (f : α →*₀o β) : α →*o β :=
{ f with }
@[simp]
theorem coe_monoidWithZeroHom (f : α →*₀o β) : ⇑(f : α →*₀ β) = f :=
rfl
@[simp]
theorem coe_orderMonoidHom (f : α →*₀o β) : ⇑(f : α →*o β) = f :=
rfl
theorem toOrderMonoidHom_injective : Injective (toOrderMonoidHom : _ → α →*o β) := fun f g h =>
ext <| by convert DFunLike.ext_iff.1 h using 0
theorem toMonoidWithZeroHom_injective : Injective (toMonoidWithZeroHom : _ → α →*₀ β) :=
fun f g h => ext <| by convert DFunLike.ext_iff.1 h using 0
/-- Copy of an `OrderMonoidWithZeroHom` with a new `toFun` equal to the old one. Useful to fix
definitional equalities. -/
protected def copy (f : α →*₀o β) (f' : α → β) (h : f' = f) : α →*o β :=
{ f.toOrderMonoidHom.copy f' h, f.toMonoidWithZeroHom.copy f' h with toFun := f' }
@[simp]
theorem coe_copy (f : α →*₀o β) (f' : α → β) (h : f' = f) : ⇑(f.copy f' h) = f' :=
rfl
theorem copy_eq (f : α →*₀o β) (f' : α → β) (h : f' = f) : f.copy f' h = f :=
DFunLike.ext' h
variable (α)
/-- The identity map as an ordered monoid with zero homomorphism. -/
protected def id : α →*₀o α :=
{ MonoidWithZeroHom.id α, OrderHom.id with }
@[simp, norm_cast]
theorem coe_id : ⇑(OrderMonoidWithZeroHom.id α) = id :=
rfl
instance : Inhabited (α →*₀o α) :=
⟨OrderMonoidWithZeroHom.id α⟩
variable {α}
/-- Composition of `OrderMonoidWithZeroHom`s as an `OrderMonoidWithZeroHom`. -/
def comp (f : β →*₀o γ) (g : α →*₀o β) : α →*₀o γ :=
{ f.toMonoidWithZeroHom.comp (g : α →*₀ β), f.toOrderMonoidHom.comp (g : α →*o β) with }
@[simp]
theorem coe_comp (f : β →*₀o γ) (g : α →*₀o β) : (f.comp g : α → γ) = f ∘ g :=
rfl
@[simp]
theorem comp_apply (f : β →*₀o γ) (g : α →*₀o β) (a : α) : (f.comp g) a = f (g a) :=
rfl
theorem coe_comp_monoidWithZeroHom (f : β →*₀o γ) (g : α →*₀o β) :
(f.comp g : α →*₀ γ) = (f : β →*₀ γ).comp g :=
rfl
theorem coe_comp_orderMonoidHom (f : β →*₀o γ) (g : α →*₀o β) :
(f.comp g : α →*o γ) = (f : β →*o γ).comp g :=
rfl
@[simp]
theorem comp_assoc (f : γ →*₀o δ) (g : β →*₀o γ) (h : α →*₀o β) :
(f.comp g).comp h = f.comp (g.comp h) :=
rfl
@[simp]
theorem comp_id (f : α →*₀o β) : f.comp (OrderMonoidWithZeroHom.id α) = f := rfl
@[simp]
theorem id_comp (f : α →*₀o β) : (OrderMonoidWithZeroHom.id β).comp f = f := rfl
@[simp]
theorem cancel_right {g₁ g₂ : β →*₀o γ} {f : α →*₀o β} (hf : Function.Surjective f) :
g₁.comp f = g₂.comp f ↔ g₁ = g₂ :=
⟨fun h => ext <| hf.forall.2 <| DFunLike.ext_iff.1 h, fun _ => by congr⟩
@[simp]
theorem cancel_left {g : β →*₀o γ} {f₁ f₂ : α →*₀o β} (hg : Function.Injective g) :
g.comp f₁ = g.comp f₂ ↔ f₁ = f₂ :=
⟨fun h => ext fun a => hg <| by rw [← comp_apply, h, comp_apply], congr_arg _⟩
end Preorder
section Mul
variable [LinearOrderedCommMonoidWithZero α] [LinearOrderedCommMonoidWithZero β]
[LinearOrderedCommMonoidWithZero γ]
/-- For two ordered monoid morphisms `f` and `g`, their product is the ordered monoid morphism
sending `a` to `f a * g a`. -/
instance : Mul (α →*₀o β) :=
⟨fun f g => { (f * g : α →*₀ β) with monotone' := f.monotone'.mul' g.monotone' }⟩
@[simp]
theorem coe_mul (f g : α →*₀o β) : ⇑(f * g) = f * g :=
rfl
@[simp]
theorem mul_apply (f g : α →*₀o β) (a : α) : (f * g) a = f a * g a :=
rfl
theorem mul_comp (g₁ g₂ : β →*₀o γ) (f : α →*₀o β) : (g₁ * g₂).comp f = g₁.comp f * g₂.comp f :=
rfl
theorem comp_mul (g : β →*₀o γ) (f₁ f₂ : α →*₀o β) : g.comp (f₁ * f₂) = g.comp f₁ * g.comp f₂ :=
ext fun _ => map_mul g _ _
end Mul
section LinearOrderedCommMonoidWithZero
variable {hα : Preorder α} {hα' : MulZeroOneClass α} {hβ : Preorder β} {hβ' : MulZeroOneClass β}
{hγ : Preorder γ} {hγ' : MulZeroOneClass γ}
@[simp]
theorem toMonoidWithZeroHom_eq_coe (f : α →*₀o β) : f.toMonoidWithZeroHom = f := by
rfl
@[simp]
theorem toMonoidWithZeroHom_mk (f : α →*₀ β) (hf : Monotone f) :
((OrderMonoidWithZeroHom.mk f hf) : α →*₀ β) = f := by
rfl
@[simp]
lemma toMonoidWithZeroHom_coe (f : β →*₀o γ) (g : α →*₀o β) :
(f.comp g : α →*₀ γ) = (f : β →*₀ γ).comp g :=
rfl
@[simp]
theorem toOrderMonoidHom_eq_coe (f : α →*₀o β) : f.toOrderMonoidHom = f :=
rfl
@[simp]
lemma toOrderMonoidHom_comp (f : β →*₀o γ) (g : α →*₀o β) :
(f.comp g : α →*o γ) = (f : β →*o γ).comp g :=
rfl
end LinearOrderedCommMonoidWithZero
end OrderMonoidWithZeroHom
/-- Any ordered group is isomorphic to the units of itself adjoined with `0`. -/
@[simps!]
def OrderMonoidIso.unitsWithZero {α : Type*} [Group α] [Preorder α] : (WithZero α)ˣ ≃*o α where
toMulEquiv := WithZero.unitsWithZeroEquiv
map_le_map_iff' {a b} := by simp [WithZero.unitsWithZeroEquiv]
/-- A version of `Equiv.optionCongr` for `WithZero` on `OrderMonoidIso`. -/
@[simps!]
def OrderMonoidIso.withZero {G H : Type*}
[Group G] [PartialOrder G] [Group H] [PartialOrder H] :
(G ≃*o H) ≃ (WithZero G ≃*o WithZero H) where
toFun e := ⟨e.toMulEquiv.withZero, fun {a b} ↦ by cases a <;> cases b <;> simp⟩
invFun e := ⟨MulEquiv.withZero.symm e, fun {a b} ↦ by simp⟩
left_inv _ := by ext; simp
right_inv _ := by ext x; cases x <;> simp
/-- Any linearly ordered group with zero is isomorphic to adjoining `0` to the units of itself. -/
@[simps!]
def OrderMonoidIso.withZeroUnits {α : Type*} [LinearOrderedCommGroupWithZero α]
[DecidablePred (fun a : α ↦ a = 0)] :
WithZero αˣ ≃*o α where
toMulEquiv := WithZero.withZeroUnitsEquiv
map_le_map_iff' {a b} := by
cases a <;> cases b <;>
simp |
.lake/packages/mathlib/Mathlib/Algebra/Order/Hom/Basic.lean | import Mathlib.Algebra.GroupWithZero.Hom
import Mathlib.Algebra.Order.Group.Abs
import Mathlib.Algebra.Ring.Defs
/-!
# Algebraic order homomorphism classes
This file defines hom classes for common properties at the intersection of order theory and algebra.
## Typeclasses
Basic typeclasses
* `NonnegHomClass`: Homs are nonnegative: `∀ f a, 0 ≤ f a`
* `SubadditiveHomClass`: Homs are subadditive: `∀ f a b, f (a + b) ≤ f a + f b`
* `SubmultiplicativeHomClass`: Homs are submultiplicative: `∀ f a b, f (a * b) ≤ f a * f b`
* `MulLEAddHomClass`: `∀ f a b, f (a * b) ≤ f a + f b`
* `NonarchimedeanHomClass`: `∀ a b, f (a + b) ≤ max (f a) (f b)`
Group norms
* `AddGroupSeminormClass`: Homs are nonnegative, subadditive, even and preserve zero.
* `GroupSeminormClass`: Homs are nonnegative, respect `f (a * b) ≤ f a + f b`, `f a⁻¹ = f a` and
preserve zero.
* `AddGroupNormClass`: Homs are seminorms such that `f x = 0 → x = 0` for all `x`.
* `GroupNormClass`: Homs are seminorms such that `f x = 0 → x = 1` for all `x`.
Ring norms
* `RingSeminormClass`: Homs are submultiplicative group norms.
* `RingNormClass`: Homs are ring seminorms that are also additive group norms.
* `MulRingSeminormClass`: Homs are ring seminorms that are multiplicative.
* `MulRingNormClass`: Homs are ring norms that are multiplicative.
## Notes
Typeclasses for seminorms are defined here while types of seminorms are defined in
`Analysis.Normed.Group.Seminorm` and `Analysis.Normed.Ring.Seminorm` because absolute values are
multiplicative ring norms but outside of this use we only consider real-valued seminorms.
## TODO
Finitary versions of the current lemmas.
-/
assert_not_exists Field
library_note2 «out-param inheritance» /--
Diamond inheritance cannot depend on `outParam`s in the following circumstances:
* there are three classes `Top`, `Middle`, `Bottom`
* all of these classes have a parameter `(α : outParam _)`
* all of these classes have an instance parameter `[Root α]` that depends on this `outParam`
* the `Root` class has two child classes: `Left` and `Right`, these are siblings in the hierarchy
* the instance `Bottom.toMiddle` takes a `[Left α]` parameter
* the instance `Middle.toTop` takes a `[Right α]` parameter
* there is a `Leaf` class that inherits from both `Left` and `Right`.
In that case, given instances `Bottom α` and `Leaf α`, Lean cannot synthesize a `Top α` instance,
even though the hypotheses of the instances `Bottom.toMiddle` and `Middle.toTop` are satisfied.
There are two workarounds:
* You could replace the bundled inheritance implemented by the instance `Middle.toTop` with
unbundled inheritance implemented by adding a `[Top α]` parameter to the `Middle` class. This is
the preferred option since it is also more compatible with Lean 4, at the cost of being more work
to implement and more verbose to use.
* You could weaken the `Bottom.toMiddle` instance by making it depend on a subclass of
`Middle.toTop`'s parameter, in this example replacing `[Left α]` with `[Leaf α]`.
-/
open Function
variable {ι F α β γ δ : Type*}
/-! ### Basics -/
/-- `NonnegHomClass F α β` states that `F` is a type of nonnegative morphisms. -/
class NonnegHomClass (F : Type*) (α β : outParam Type*) [Zero β] [LE β] [FunLike F α β] : Prop where
/-- the image of any element is nonnegative. -/
apply_nonneg (f : F) : ∀ a, 0 ≤ f a
/-- `SubadditiveHomClass F α β` states that `F` is a type of subadditive morphisms. -/
class SubadditiveHomClass (F : Type*) (α β : outParam Type*)
[Add α] [Add β] [LE β] [FunLike F α β] : Prop where
/-- the image of a sum is less or equal than the sum of the images. -/
map_add_le_add (f : F) : ∀ a b, f (a + b) ≤ f a + f b
/-- `SubmultiplicativeHomClass F α β` states that `F` is a type of submultiplicative morphisms. -/
@[to_additive SubadditiveHomClass]
class SubmultiplicativeHomClass (F : Type*) (α β : outParam (Type*)) [Mul α] [Mul β] [LE β]
[FunLike F α β] : Prop where
/-- the image of a product is less or equal than the product of the images. -/
map_mul_le_mul (f : F) : ∀ a b, f (a * b) ≤ f a * f b
/-- `MulLEAddHomClass F α β` states that `F` is a type of subadditive morphisms. -/
@[to_additive SubadditiveHomClass]
class MulLEAddHomClass (F : Type*) (α β : outParam Type*) [Mul α] [Add β] [LE β] [FunLike F α β] :
Prop where
/-- the image of a product is less or equal than the sum of the images. -/
map_mul_le_add (f : F) : ∀ a b, f (a * b) ≤ f a + f b
/-- `NonarchimedeanHomClass F α β` states that `F` is a type of non-archimedean morphisms. -/
class NonarchimedeanHomClass (F : Type*) (α β : outParam Type*)
[Add α] [LinearOrder β] [FunLike F α β] : Prop where
/-- the image of a sum is less or equal than the maximum of the images. -/
map_add_le_max (f : F) : ∀ a b, f (a + b) ≤ max (f a) (f b)
export NonnegHomClass (apply_nonneg)
export SubadditiveHomClass (map_add_le_add)
export SubmultiplicativeHomClass (map_mul_le_mul)
export MulLEAddHomClass (map_mul_le_add)
export NonarchimedeanHomClass (map_add_le_max)
attribute [simp] apply_nonneg
variable [FunLike F α β]
@[to_additive]
theorem le_map_mul_map_div [Group α] [CommMagma β] [LE β] [SubmultiplicativeHomClass F α β]
(f : F) (a b : α) : f a ≤ f b * f (a / b) := by
simpa only [mul_comm, div_mul_cancel] using map_mul_le_mul f (a / b) b
@[to_additive existing]
theorem le_map_add_map_div [Group α] [AddCommMagma β] [LE β] [MulLEAddHomClass F α β] (f : F)
(a b : α) : f a ≤ f b + f (a / b) := by
simpa only [add_comm, div_mul_cancel] using map_mul_le_add f (a / b) b
@[to_additive]
theorem le_map_div_mul_map_div [Group α] [Mul β] [LE β] [SubmultiplicativeHomClass F α β]
(f : F) (a b c : α) : f (a / c) ≤ f (a / b) * f (b / c) := by
simpa only [div_mul_div_cancel] using map_mul_le_mul f (a / b) (b / c)
@[to_additive existing]
theorem le_map_div_add_map_div [Group α] [Add β] [LE β] [MulLEAddHomClass F α β]
(f : F) (a b c : α) : f (a / c) ≤ f (a / b) + f (b / c) := by
simpa only [div_mul_div_cancel] using map_mul_le_add f (a / b) (b / c)
/-! ### Group (semi)norms -/
/-- `AddGroupSeminormClass F α` states that `F` is a type of `β`-valued seminorms on the additive
group `α`.
You should extend this class when you extend `AddGroupSeminorm`. -/
class AddGroupSeminormClass (F : Type*) (α β : outParam Type*)
[AddGroup α] [AddCommMonoid β] [PartialOrder β] [FunLike F α β] : Prop
extends SubadditiveHomClass F α β where
/-- The image of zero is zero. -/
map_zero (f : F) : f 0 = 0
/-- The map is invariant under negation of its argument. -/
map_neg_eq_map (f : F) (a : α) : f (-a) = f a
/-- `GroupSeminormClass F α` states that `F` is a type of `β`-valued seminorms on the group `α`.
You should extend this class when you extend `GroupSeminorm`. -/
@[to_additive]
class GroupSeminormClass (F : Type*) (α β : outParam Type*)
[Group α] [AddCommMonoid β] [PartialOrder β] [FunLike F α β] : Prop
extends MulLEAddHomClass F α β where
/-- The image of one is zero. -/
map_one_eq_zero (f : F) : f 1 = 0
/-- The map is invariant under inversion of its argument. -/
map_inv_eq_map (f : F) (a : α) : f a⁻¹ = f a
/-- `AddGroupNormClass F α` states that `F` is a type of `β`-valued norms on the additive group
`α`.
You should extend this class when you extend `AddGroupNorm`. -/
class AddGroupNormClass (F : Type*) (α β : outParam Type*)
[AddGroup α] [AddCommMonoid β] [PartialOrder β] [FunLike F α β] : Prop
extends AddGroupSeminormClass F α β where
/-- The argument is zero if its image under the map is zero. -/
eq_zero_of_map_eq_zero (f : F) {a : α} : f a = 0 → a = 0
/-- `GroupNormClass F α` states that `F` is a type of `β`-valued norms on the group `α`.
You should extend this class when you extend `GroupNorm`. -/
@[to_additive]
class GroupNormClass (F : Type*) (α β : outParam Type*)
[Group α] [AddCommMonoid β] [PartialOrder β] [FunLike F α β] : Prop
extends GroupSeminormClass F α β where
/-- The argument is one if its image under the map is zero. -/
eq_one_of_map_eq_zero (f : F) {a : α} : f a = 0 → a = 1
export AddGroupSeminormClass (map_neg_eq_map)
export GroupSeminormClass (map_one_eq_zero map_inv_eq_map)
export AddGroupNormClass (eq_zero_of_map_eq_zero)
export GroupNormClass (eq_one_of_map_eq_zero)
attribute [simp] map_one_eq_zero map_neg_eq_map map_inv_eq_map
-- See note [lower instance priority]
instance (priority := 100) AddGroupSeminormClass.toZeroHomClass [AddGroup α]
[AddCommMonoid β] [PartialOrder β] [AddGroupSeminormClass F α β] : ZeroHomClass F α β :=
{ ‹AddGroupSeminormClass F α β› with }
section GroupSeminormClass
variable [Group α] [AddCommMonoid β] [PartialOrder β] [GroupSeminormClass F α β] (f : F) (x y : α)
@[to_additive]
theorem map_div_le_add : f (x / y) ≤ f x + f y := by
rw [div_eq_mul_inv, ← map_inv_eq_map f y]
exact map_mul_le_add _ _ _
@[to_additive]
theorem map_div_rev : f (x / y) = f (y / x) := by rw [← inv_div, map_inv_eq_map]
@[to_additive]
theorem le_map_add_map_div' : f x ≤ f y + f (y / x) := by
simpa only [add_comm, map_div_rev, div_mul_cancel] using map_mul_le_add f (x / y) y
end GroupSeminormClass
@[to_additive]
theorem abs_sub_map_le_div [Group α] [AddCommGroup β] [LinearOrder β] [IsOrderedAddMonoid β]
[GroupSeminormClass F α β]
(f : F) (x y : α) : |f x - f y| ≤ f (x / y) := by
rw [abs_sub_le_iff, sub_le_iff_le_add', sub_le_iff_le_add']
exact ⟨le_map_add_map_div _ _ _, le_map_add_map_div' _ _ _⟩
-- See note [lower instance priority]
@[to_additive]
instance (priority := 100) GroupSeminormClass.toNonnegHomClass [Group α]
[AddCommMonoid β] [LinearOrder β] [IsOrderedAddMonoid β] [GroupSeminormClass F α β] :
NonnegHomClass F α β :=
{ ‹GroupSeminormClass F α β› with
apply_nonneg := fun f a =>
(nsmul_nonneg_iff two_ne_zero).1 <| by
rw [two_nsmul, ← map_one_eq_zero f, ← div_self' a]
exact map_div_le_add _ _ _ }
section GroupNormClass
variable [Group α] [AddCommMonoid β] [PartialOrder β] [GroupNormClass F α β] (f : F) {x : α}
@[to_additive]
theorem map_eq_zero_iff_eq_one : f x = 0 ↔ x = 1 :=
⟨eq_one_of_map_eq_zero _, by
rintro rfl
exact map_one_eq_zero _⟩
@[to_additive]
theorem map_ne_zero_iff_ne_one : f x ≠ 0 ↔ x ≠ 1 :=
(map_eq_zero_iff_eq_one _).not
end GroupNormClass
@[to_additive]
theorem map_pos_of_ne_one [Group α] [AddCommMonoid β] [LinearOrder β] [IsOrderedAddMonoid β]
[GroupNormClass F α β] (f : F)
{x : α} (hx : x ≠ 1) : 0 < f x :=
(apply_nonneg _ _).lt_of_ne <| ((map_ne_zero_iff_ne_one _).2 hx).symm
/-! ### Ring (semi)norms -/
/-- `RingSeminormClass F α` states that `F` is a type of `β`-valued seminorms on the ring `α`.
You should extend this class when you extend `RingSeminorm`. -/
class RingSeminormClass (F : Type*) (α β : outParam Type*)
[NonUnitalNonAssocRing α] [Semiring β] [PartialOrder β] [FunLike F α β] : Prop
extends AddGroupSeminormClass F α β, SubmultiplicativeHomClass F α β
/-- `RingNormClass F α` states that `F` is a type of `β`-valued norms on the ring `α`.
You should extend this class when you extend `RingNorm`. -/
class RingNormClass (F : Type*) (α β : outParam Type*)
[NonUnitalNonAssocRing α] [Semiring β] [PartialOrder β] [FunLike F α β] : Prop
extends RingSeminormClass F α β, AddGroupNormClass F α β
/-- `MulRingSeminormClass F α` states that `F` is a type of `β`-valued multiplicative seminorms
on the ring `α`.
You should extend this class when you extend `MulRingSeminorm`. -/
class MulRingSeminormClass (F : Type*) (α β : outParam Type*)
[NonAssocRing α] [Semiring β] [PartialOrder β] [FunLike F α β] : Prop
extends AddGroupSeminormClass F α β, MonoidWithZeroHomClass F α β
-- Lower the priority of these instances since they require synthesizing an order structure.
attribute [instance 50]
MulRingSeminormClass.toMonoidHomClass MulRingSeminormClass.toMonoidWithZeroHomClass
/-- `MulRingNormClass F α` states that `F` is a type of `β`-valued multiplicative norms on the
ring `α`.
You should extend this class when you extend `MulRingNorm`. -/
class MulRingNormClass (F : Type*) (α β : outParam Type*)
[NonAssocRing α] [Semiring β] [PartialOrder β] [FunLike F α β] : Prop
extends MulRingSeminormClass F α β, AddGroupNormClass F α β
-- See note [out-param inheritance]
-- See note [lower instance priority]
instance (priority := 100) RingSeminormClass.toNonnegHomClass [NonUnitalNonAssocRing α]
[Semiring β] [LinearOrder β] [IsOrderedAddMonoid β] [RingSeminormClass F α β] :
NonnegHomClass F α β :=
AddGroupSeminormClass.toNonnegHomClass
-- See note [lower instance priority]
instance (priority := 100) MulRingSeminormClass.toRingSeminormClass [NonAssocRing α]
[Semiring β] [PartialOrder β] [MulRingSeminormClass F α β] : RingSeminormClass F α β :=
{ ‹MulRingSeminormClass F α β› with map_mul_le_mul := fun _ _ _ => (map_mul _ _ _).le }
-- See note [lower instance priority]
instance (priority := 100) MulRingNormClass.toRingNormClass [NonAssocRing α]
[Semiring β] [PartialOrder β] [MulRingNormClass F α β] : RingNormClass F α β :=
{ ‹MulRingNormClass F α β›, MulRingSeminormClass.toRingSeminormClass with } |
.lake/packages/mathlib/Mathlib/Algebra/Order/Hom/Submonoid.lean | import Mathlib.Algebra.Group.Submonoid.Operations
import Mathlib.Algebra.Order.Hom.Monoid
/-!
# Isomorphism of submonoids of ordered monoids
-/
/-- The top submonoid is order isomorphic to the whole monoid. -/
@[simps!]
def Submonoid.topOrderMonoidIso {α : Type*} [Preorder α] [Monoid α] : (⊤ : Submonoid α) ≃*o α where
__ := Submonoid.topEquiv
map_le_map_iff' := Iff.rfl |
.lake/packages/mathlib/Mathlib/Algebra/Order/Hom/TypeTags.lean | import Mathlib.Algebra.Group.Equiv.TypeTags
import Mathlib.Algebra.Order.Hom.Monoid
import Mathlib.Algebra.Order.Monoid.Unbundled.TypeTags
/-!
# Order Monoid Isomorphisms on `Additive` and `Multiplicative`.
-/
section TypeTags
/-- Reinterpret `G ≃*o H` as `Additive G ≃+o Additive H`. -/
def OrderMonoidIso.toAdditive {G H : Type*}
[CommMonoid G] [PartialOrder G] [CommMonoid H] [PartialOrder H] :
(G ≃*o H) ≃ (Additive G ≃+o Additive H) where
toFun e := ⟨MulEquiv.toAdditive e, by simp⟩
invFun e := ⟨MulEquiv.toAdditive.symm e, by simp⟩
left_inv e := by ext; simp
right_inv e := by ext; simp
/-- Reinterpret `G ≃+o H` as `Multiplicative G ≃*o Multiplicative H`. -/
def OrderAddMonoidIso.toMultiplicative {G H : Type*}
[AddCommMonoid G] [PartialOrder G] [AddCommMonoid H] [PartialOrder H] :
(G ≃+o H) ≃ (Multiplicative G ≃*o Multiplicative H) where
toFun e := ⟨AddEquiv.toMultiplicative e, by simp⟩
invFun e := ⟨AddEquiv.toMultiplicative.symm e, by simp⟩
left_inv e := by ext; simp
right_inv e := by ext; simp
/-- Reinterpret `Additive G ≃+o H` as `G ≃*o Multiplicative H`. -/
def OrderAddMonoidIso.toMultiplicativeRight {G H : Type*}
[CommMonoid G] [PartialOrder G] [AddCommMonoid H] [PartialOrder H] :
(Additive G ≃+o H) ≃ (G ≃*o Multiplicative H) where
toFun e := ⟨e.toAddEquiv.toMultiplicativeRight, by simp⟩
invFun e := ⟨e.toMulEquiv.toAdditiveLeft, by simp⟩
left_inv e := by ext; simp
right_inv e := by ext; simp
@[deprecated (since := "2025-09-19")]
alias OrderAddMonoidIso.toMultiplicative' := OrderAddMonoidIso.toMultiplicativeRight
/-- Reinterpret `G ≃* Multiplicative H` as `Additive G ≃+ H`. -/
abbrev OrderMonoidIso.toAdditiveLeft {G H : Type*}
[CommMonoid G] [PartialOrder G] [AddCommMonoid H] [PartialOrder H] :
(G ≃*o Multiplicative H) ≃ (Additive G ≃+o H) :=
OrderAddMonoidIso.toMultiplicativeRight.symm
@[deprecated (since := "2025-09-19")]
alias OrderMonoidIso.toAdditive' := OrderMonoidIso.toAdditiveLeft
/-- Reinterpret `G ≃+o Additive H` as `Multiplicative G ≃*o H`. -/
def OrderAddMonoidIso.toMultiplicativeLeft {G H : Type*}
[AddCommMonoid G] [PartialOrder G] [CommMonoid H] [PartialOrder H] :
(G ≃+o Additive H) ≃ (Multiplicative G ≃*o H) where
toFun e := ⟨e.toAddEquiv.toMultiplicativeLeft, by simp⟩
invFun e := ⟨e.toMulEquiv.toAdditiveRight, by simp⟩
left_inv e := by ext; simp
right_inv e := by ext; simp
@[deprecated (since := "2025-09-19")]
alias OrderAddMonoidIso.toMultiplicative'' := OrderAddMonoidIso.toMultiplicativeLeft
/-- Reinterpret `Multiplicative G ≃*o H` as `G ≃+o Additive H` as. -/
abbrev OrderMonoidIso.toAdditiveRight {G H : Type*}
[AddCommMonoid G] [PartialOrder G] [CommMonoid H] [PartialOrder H] :
(Multiplicative G ≃*o H) ≃ (G ≃+o Additive H) :=
OrderAddMonoidIso.toMultiplicativeLeft.symm
@[deprecated (since := "2025-09-19")]
alias OrderMonoidIso.toAdditive'' := OrderMonoidIso.toAdditiveRight
/-- The multiplicative version of an additivized ordered monoid is order-mul-equivalent to itself.
-/
def OrderMonoidIso.toMultiplicative_toAdditive {G : Type*} [CommMonoid G] [PartialOrder G] :
Multiplicative (Additive G) ≃*o G :=
OrderAddMonoidIso.toMultiplicativeLeft <| OrderMonoidIso.toAdditive (.refl _)
/-- The additive version of an multiplicativized ordered additive monoid is
order-add-equivalent to itself. -/
def OrderAddMonoidIso.toAdditive_toMultiplicative {G : Type*} [AddCommMonoid G] [PartialOrder G] :
Additive (Multiplicative G) ≃+o G :=
OrderMonoidIso.toAdditiveLeft <| OrderAddMonoidIso.toMultiplicative (.refl _)
instance Additive.instUniqueOrderAddMonoidIso {G H : Type*}
[CommMonoid G] [PartialOrder G] [CommMonoid H] [PartialOrder H] [Unique (G ≃*o H)] :
Unique (Additive G ≃+o Additive H) :=
OrderMonoidIso.toAdditive.symm.unique
instance Multiplicative.instUniqueOrderdMonoidIso {G H : Type*}
[AddCommMonoid G] [PartialOrder G] [AddCommMonoid H] [PartialOrder H] [Unique (G ≃+o H)] :
Unique (Multiplicative G ≃*o Multiplicative H) :=
OrderAddMonoidIso.toMultiplicative.symm.unique
end TypeTags |
.lake/packages/mathlib/Mathlib/Algebra/Order/Hom/Units.lean | import Mathlib.Algebra.Group.Units.Equiv
import Mathlib.Algebra.Order.Hom.Monoid
import Mathlib.Algebra.Order.Monoid.Units
/-! # Isomorphism of ordered monoids descends to units
-/
/-- An isomorphism of ordered monoids descends to their units. -/
@[simps!]
def OrderMonoidIso.unitsCongr {α β : Type*} [Preorder α] [Monoid α] [Preorder β] [Monoid β]
(e : α ≃*o β) : αˣ ≃*o βˣ where
__ := Units.mapEquiv e.toMulEquiv
map_le_map_iff' {x y} := by simp [← Units.val_le_val] |
.lake/packages/mathlib/Mathlib/Algebra/Order/SuccPred/PartialSups.lean | import Mathlib.Algebra.Order.SuccPred
import Mathlib.Order.PartialSups
import Mathlib.Order.SuccPred.LinearLocallyFinite
/-!
# `PartialSups` in a `SuccAddOrder`
Basic results concerning `PartialSups` which follow with minimal assumptions beyond the fact that
the `PartialSup` is defined over a `SuccAddOrder`.
-/
open Finset
variable {α ι : Type*} [SemilatticeSup α] [LinearOrder ι]
@[simp]
lemma partialSups_add_one [Add ι] [One ι] [LocallyFiniteOrderBot ι] [SuccAddOrder ι]
(f : ι → α) (i : ι) : partialSups f (i + 1) = partialSups f i ⊔ f (i + 1) :=
Order.succ_eq_add_one i ▸ partialSups_succ f i
/-- See `partialSups_succ` for another decomposition of `(partialSups f) (Order.succ i)`. -/
lemma partialSups_succ' {α : Type*} [SemilatticeSup α] [LocallyFiniteOrder ι]
[SuccOrder ι] [OrderBot ι] (f : ι → α) (i : ι) :
(partialSups f) (Order.succ i) = f ⊥ ⊔ (partialSups (f ∘ Order.succ)) i := by
refine Succ.rec (by simp) (fun j _ h ↦ ?_) (bot_le (a := i))
have : (partialSups (f ∘ Order.succ)) (Order.succ j) =
((partialSups (f ∘ Order.succ)) j ⊔ (f ∘ Order.succ) (Order.succ j)) := by simp
simp [this, h, sup_assoc]
/-- See `partialSups_add_one` for another decomposition of `partialSups f (i + 1)`. -/
lemma partialSups_add_one' [Add ι] [One ι] [OrderBot ι] [LocallyFiniteOrder ι]
[SuccAddOrder ι] (f : ι → α) (i : ι) :
partialSups f (i + 1) = f ⊥ ⊔ partialSups (f ∘ (fun k ↦ k + 1)) i := by
simpa [← Order.succ_eq_add_one] using partialSups_succ' f i |
.lake/packages/mathlib/Mathlib/Algebra/Order/SuccPred/WithBot.lean | import Mathlib.Algebra.Order.Monoid.Unbundled.WithTop
import Mathlib.Algebra.Order.SuccPred
import Mathlib.Order.SuccPred.WithBot
/-!
# Algebraic properties of the successor function on `WithBot`
-/
namespace WithBot
variable {α : Type*} [Preorder α] [OrderBot α] [AddMonoidWithOne α] [SuccAddOrder α]
lemma succ_natCast (n : ℕ) : succ (n : WithBot α) = n + 1 := by
rw [← WithBot.coe_natCast, succ_coe, Order.succ_eq_add_one]
@[simp] lemma succ_zero : succ (0 : WithBot α) = 1 := by simpa using succ_natCast 0
@[simp]
lemma succ_one : succ (1 : WithBot α) = 2 := by simpa [one_add_one_eq_two] using succ_natCast 1
@[simp]
lemma succ_ofNat (n : ℕ) [n.AtLeastTwo] :
succ (ofNat(n) : WithBot α) = ofNat(n) + 1 := succ_natCast n
lemma one_le_iff_pos {α : Type*} [PartialOrder α] [AddMonoidWithOne α]
[ZeroLEOneClass α] [NeZero (1 : α)] [SuccAddOrder α] (a : WithBot α) : 1 ≤ a ↔ 0 < a := by
cases a <;> simp [Order.one_le_iff_pos]
end WithBot |
.lake/packages/mathlib/Mathlib/Algebra/Order/SuccPred/TypeTags.lean | import Mathlib.Order.SuccPred.Archimedean
import Mathlib.Algebra.Order.Monoid.Unbundled.TypeTags
/-!
# Successor and predecessor on type tags
This file declates successor and predecessor orders on type tags.
-/
variable {X : Type*}
instance [Preorder X] [h : SuccOrder X] : SuccOrder (Multiplicative X) := h
instance [Preorder X] [h : SuccOrder X] : SuccOrder (Additive X) := h
instance [Preorder X] [h : PredOrder X] : PredOrder (Multiplicative X) := h
instance [Preorder X] [h : PredOrder X] : PredOrder (Additive X) := h
instance [Preorder X] [SuccOrder X] [h : IsSuccArchimedean X] :
IsSuccArchimedean (Multiplicative X) := h
instance [Preorder X] [SuccOrder X] [h : IsSuccArchimedean X] :
IsSuccArchimedean (Additive X) := h
instance [Preorder X] [PredOrder X] [h : IsPredArchimedean X] :
IsPredArchimedean (Multiplicative X) := h
instance [Preorder X] [PredOrder X] [h : IsPredArchimedean X] :
IsPredArchimedean (Additive X) := h
namespace Order
open Additive Multiplicative
@[simp] lemma succ_ofMul [Preorder X] [SuccOrder X] (x : X) : succ (ofMul x) = ofMul (succ x) := rfl
@[simp] lemma succ_toMul [Preorder X] [SuccOrder X] (x : Additive X) :
succ x.toMul = (succ x).toMul := rfl
@[simp] lemma succ_ofAdd [Preorder X] [SuccOrder X] (x : X) : succ (ofAdd x) = ofAdd (succ x) := rfl
@[simp] lemma succ_toAdd [Preorder X] [SuccOrder X] (x : Multiplicative X) :
succ x.toAdd = (succ x).toAdd :=
rfl
@[simp] lemma pred_ofMul [Preorder X] [PredOrder X] (x : X) : pred (ofMul x) = ofMul (pred x) := rfl
@[simp]
lemma pred_toMul [Preorder X] [PredOrder X] (x : Additive X) : pred x.toMul = (pred x).toMul := rfl
@[simp] lemma pred_ofAdd [Preorder X] [PredOrder X] (x : X) : pred (ofAdd x) = ofAdd (pred x) := rfl
@[simp] lemma pred_toAdd [Preorder X] [PredOrder X] (x : Multiplicative X) :
pred x.toAdd = (pred x).toAdd :=
rfl
end Order |
.lake/packages/mathlib/Mathlib/Algebra/Order/Group/OrderIso.lean | 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 α] [MulLeftMono α] [MulRightMono α] {a b : α}
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 [MulRightMono α] {a : α}
/-- `Equiv.mulRight` as an `OrderIso`. See also `OrderEmbedding.mulRight`. -/
@[to_additive (attr := simps! +simpRhs 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 [MulLeftMono α]
/-- `Equiv.mulLeft` as an `OrderIso`. See also `OrderEmbedding.mulLeft`. -/
@[to_additive (attr := simps! +simpRhs 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 |
.lake/packages/mathlib/Mathlib/Algebra/Order/Group/DenselyOrdered.lean | import Mathlib.Algebra.Order.Group.Defs
import Mathlib.Algebra.Order.Group.Unbundled.Basic
import Mathlib.Algebra.Order.Monoid.Defs
import Mathlib.Algebra.Order.Monoid.Unbundled.ExistsOfLE
import Mathlib.Algebra.Order.Monoid.Unbundled.OrderDual
import Mathlib.Algebra.Order.Monoid.Unbundled.Pow
/-!
# Lemmas about densely linearly ordered groups.
-/
variable {α : Type*}
section DenselyOrdered
variable [Group α] [LinearOrder α]
variable [MulLeftMono α]
variable [DenselyOrdered α] {a b : α}
@[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_lt_one_mul_le : a ≤ b ↔ ∀ ε < 1, a * ε ≤ b :=
le_iff_forall_one_lt_le_mul (α := αᵒᵈ)
end DenselyOrdered
section DenselyOrdered
@[to_additive]
private lemma exists_lt_mul_left [Group α] [LT α] [DenselyOrdered α]
[MulRightStrictMono α] {a b c : α} (hc : c < a * b) :
∃ a' < a, c < a' * b := by
obtain ⟨a', hc', ha'⟩ := exists_between (div_lt_iff_lt_mul.2 hc)
exact ⟨a', ha', div_lt_iff_lt_mul.1 hc'⟩
@[to_additive]
private lemma exists_lt_mul_right [CommGroup α] [LT α] [DenselyOrdered α]
[MulLeftStrictMono α] {a b c : α} (hc : c < a * b) :
∃ b' < b, c < a * b' := by
obtain ⟨a', hc', ha'⟩ := exists_between (div_lt_iff_lt_mul'.2 hc)
exact ⟨a', ha', div_lt_iff_lt_mul'.1 hc'⟩
@[to_additive]
private lemma exists_mul_left_lt [Group α] [LT α] [DenselyOrdered α]
[MulRightStrictMono α] {a b c : α} (hc : a * b < c) :
∃ a' > a, a' * b < c := by
obtain ⟨a', ha', hc'⟩ := exists_between (lt_div_iff_mul_lt.2 hc)
exact ⟨a', ha', lt_div_iff_mul_lt.1 hc'⟩
@[to_additive]
private lemma exists_mul_right_lt [CommGroup α] [LT α] [DenselyOrdered α]
[MulLeftStrictMono α] {a b c : α} (hc : a * b < c) :
∃ b' > b, a * b' < c := by
obtain ⟨a', ha', hc'⟩ := exists_between (lt_div_iff_mul_lt'.2 hc)
exact ⟨a', ha', lt_div_iff_mul_lt'.1 hc'⟩
@[to_additive]
lemma le_mul_of_forall_lt [CommGroup α] [LinearOrder α] [MulLeftMono α]
[DenselyOrdered α] {a b c : α} (h : ∀ a' > a, ∀ b' > b, c ≤ a' * b') :
c ≤ a * b := by
refine le_of_forall_gt_imp_ge_of_dense fun d hd ↦ ?_
obtain ⟨a', ha', hd⟩ := exists_mul_left_lt hd
obtain ⟨b', hb', hd⟩ := exists_mul_right_lt hd
exact (h a' ha' b' hb').trans hd.le
@[to_additive]
lemma mul_le_of_forall_lt [CommGroup α] [LinearOrder α] [MulLeftMono α]
[DenselyOrdered α] {a b c : α} (h : ∀ a' < a, ∀ b' < b, a' * b' ≤ c) :
a * b ≤ c := by
refine le_of_forall_lt_imp_le_of_dense fun d hd ↦ ?_
obtain ⟨a', ha', hd⟩ := exists_lt_mul_left hd
obtain ⟨b', hb', hd⟩ := exists_lt_mul_right hd
exact hd.le.trans (h a' ha' b' hb')
end DenselyOrdered
variable {M : Type*} [LinearOrder M] [DenselyOrdered M] {x : M}
section Monoid
variable [CommMonoid M] [ExistsMulOfLE M] [IsOrderedCancelMonoid M]
@[to_additive]
private theorem exists_pow_two_le_of_one_lt (hx : 1 < x) : ∃ y : M, 1 < y ∧ y ^ 2 ≤ x := by
obtain ⟨y, hy, hyx⟩ := exists_between hx
obtain hyx | hxy := le_total (y ^ 2) x
· exact ⟨y, hy, hyx⟩
obtain ⟨z, hz, rfl⟩ := exists_one_lt_mul_of_lt' hyx
exact ⟨z, hz, by simpa [pow_succ] using hxy⟩
@[to_additive]
theorem exists_pow_lt_of_one_lt (hx : 1 < x) : ∀ n : ℕ, ∃ y : M, 1 < y ∧ y ^ n < x
| 0 => ⟨x, by simpa⟩
| 1 => by simpa using exists_between hx
| n + 2 => by
obtain ⟨y, hy, hyx⟩ := exists_pow_lt_of_one_lt hx (n + 1)
obtain ⟨z, hz, hzy⟩ := exists_pow_two_le_of_one_lt hy
refine ⟨z, hz, hyx.trans_le' ?_⟩
calc z ^ (n + 2)
_ ≤ z ^ (2 * (n + 1)) := pow_right_monotone hz.le (by cutsat)
_ = (z ^ 2) ^ (n + 1) := by rw [pow_mul]
_ ≤ y ^ (n + 1) := pow_le_pow_left' hzy (n + 1)
end Monoid
section Group
variable [CommGroup M] [IsOrderedCancelMonoid M]
@[to_additive]
theorem exists_lt_pow_of_lt_one (hx : x < 1) (n : ℕ) : ∃ y : M, y < 1 ∧ x < y ^ n := by
obtain ⟨y, hy, hy'⟩ := exists_pow_lt_of_one_lt (one_lt_inv_of_inv hx) n
use y⁻¹, inv_lt_one_of_one_lt hy
simpa [lt_inv'] using hy'
end Group |
.lake/packages/mathlib/Mathlib/Algebra/Order/Group/Synonym.lean | import Mathlib.Algebra.Group.Defs
import Mathlib.Order.Synonym
/-!
# Group structure on the order type synonyms
Transfer algebraic instances from `α` to `αᵒᵈ`, `Lex α`, and `Colex α`.
-/
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]
instance [h : DivisionMonoid α] : DivisionMonoid αᵒᵈ := h
@[to_additive]
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 [Mul α] [IsLeftCancelMul α] : IsLeftCancelMul (Lex α) :=
inferInstanceAs <| IsLeftCancelMul α
@[to_additive]
instance [Mul α] [IsRightCancelMul α] : IsRightCancelMul (Lex α) :=
inferInstanceAs <| IsRightCancelMul α
@[to_additive]
instance [Mul α] [IsCancelMul α] : IsCancelMul (Lex α) :=
inferInstanceAs <| IsCancelMul α
@[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]
instance [h : DivisionMonoid α] : DivisionMonoid (Lex α) := h
@[to_additive]
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 toLex_eq_one [One α] {a : α} : toLex a = 1 ↔ a = 1 := .rfl
@[to_additive (attr := simp)]
theorem ofLex_one [One α] : (ofLex 1 : α) = 1 := rfl
@[to_additive (attr := simp)]
theorem ofLex_eq_one [One α] {a : Lex α} : ofLex a = 1 ↔ a = 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
/-! ### Colexicographical order -/
@[to_additive]
instance [h : One α] : One (Colex α) := h
@[to_additive]
instance [h : Mul α] : Mul (Colex α) := h
@[to_additive]
instance [h : Inv α] : Inv (Colex α) := h
@[to_additive]
instance [h : Div α] : Div (Colex α) := h
@[to_additive (attr := to_additive) (reorder := 1 2) Colex.instSMul]
instance Colex.instPow [h : Pow α β] : Pow (Colex α) β := h
@[to_additive (attr := to_additive) (reorder := 1 2) Colex.instSMul']
instance Colex.instPow' [h : Pow α β] : Pow α (Colex β) := h
@[to_additive]
instance [h : Semigroup α] : Semigroup (Colex α) := h
@[to_additive]
instance [h : CommSemigroup α] : CommSemigroup (Colex α) := h
@[to_additive]
instance [Mul α] [IsLeftCancelMul α] : IsLeftCancelMul (Colex α) :=
inferInstanceAs <| IsLeftCancelMul α
@[to_additive]
instance [Mul α] [IsRightCancelMul α] : IsRightCancelMul (Colex α) :=
inferInstanceAs <| IsRightCancelMul α
@[to_additive]
instance [Mul α] [IsCancelMul α] : IsCancelMul (Colex α) :=
inferInstanceAs <| IsCancelMul α
@[to_additive]
instance [h : LeftCancelSemigroup α] : LeftCancelSemigroup (Colex α) := h
@[to_additive]
instance [h : RightCancelSemigroup α] : RightCancelSemigroup (Colex α) := h
@[to_additive]
instance [h : MulOneClass α] : MulOneClass (Colex α) := h
@[to_additive]
instance [h : Monoid α] : Monoid (Colex α) := h
@[to_additive]
instance [h : CommMonoid α] : CommMonoid (Colex α) := h
@[to_additive]
instance [h : LeftCancelMonoid α] : LeftCancelMonoid (Colex α) := h
@[to_additive]
instance [h : RightCancelMonoid α] : RightCancelMonoid (Colex α) := h
@[to_additive]
instance [h : CancelMonoid α] : CancelMonoid (Colex α) := h
@[to_additive]
instance [h : CancelCommMonoid α] : CancelCommMonoid (Colex α) := h
@[to_additive]
instance [h : InvolutiveInv α] : InvolutiveInv (Colex α) := h
@[to_additive]
instance [h : DivInvMonoid α] : DivInvMonoid (Colex α) := h
@[to_additive]
instance [h : DivisionMonoid α] : DivisionMonoid (Colex α) := h
@[to_additive]
instance [h : DivisionCommMonoid α] : DivisionCommMonoid (Colex α) := h
@[to_additive]
instance [h : Group α] : Group (Colex α) := h
@[to_additive]
instance [h : CommGroup α] : CommGroup (Colex α) := h
@[to_additive (attr := simp)]
theorem toColex_one [One α] : toColex (1 : α) = 1 := rfl
@[to_additive (attr := simp)]
theorem toColex_eq_one [One α] {a : α} : toColex a = 1 ↔ a = 1 := .rfl
@[to_additive (attr := simp)]
theorem ofColex_one [One α] : (ofColex 1 : α) = 1 := rfl
@[to_additive (attr := simp)]
theorem ofColex_eq_one [One α] {a : Colex α} : ofColex a = 1 ↔ a = 1 := .rfl
@[to_additive (attr := simp)]
theorem toColex_mul [Mul α] (a b : α) : toColex (a * b) = toColex a * toColex b := rfl
@[to_additive (attr := simp)]
theorem ofColex_mul [Mul α] (a b : Colex α) : ofColex (a * b) = ofColex a * ofColex b := rfl
@[to_additive (attr := simp)]
theorem toColex_inv [Inv α] (a : α) : toColex a⁻¹ = (toColex a)⁻¹ := rfl
@[to_additive (attr := simp)]
theorem ofColex_inv [Inv α] (a : Colex α) : ofColex a⁻¹ = (ofColex a)⁻¹ := rfl
@[to_additive (attr := simp)]
theorem toColex_div [Div α] (a b : α) : toColex (a / b) = toColex a / toColex b := rfl
@[to_additive (attr := simp)]
theorem ofColex_div [Div α] (a b : Colex α) : ofColex (a / b) = ofColex a / ofColex b := rfl
@[to_additive (attr := simp, to_additive) (reorder := 1 2, 4 5) toColex_smul]
theorem toColex_pow [Pow α β] (a : α) (b : β) : toColex (a ^ b) = toColex a ^ b := rfl
@[to_additive (attr := simp, to_additive) (reorder := 1 2, 4 5) ofColex_smul]
theorem ofColex_pow [Pow α β] (a : Colex α) (b : β) : ofColex (a ^ b) = ofColex a ^ b := rfl
@[to_additive (attr := simp, to_additive) (reorder := 1 2, 4 5) toColex_smul']
theorem pow_toColex [Pow α β] (a : α) (b : β) : a ^ toColex b = a ^ b := rfl
@[to_additive (attr := simp, to_additive) (reorder := 1 2, 4 5) ofColex_smul']
theorem pow_ofColex [Pow α β] (a : α) (b : Colex β) : a ^ ofColex b = a ^ b := rfl |
.lake/packages/mathlib/Mathlib/Algebra/Order/Group/Instances.lean | import Mathlib.Algebra.Order.Group.Defs
import Mathlib.Algebra.Order.Monoid.OrderDual
import Mathlib.Tactic.Linter.DeprecatedModule
deprecated_module (since := "2025-04-16") |
.lake/packages/mathlib/Mathlib/Algebra/Order/Group/Opposite.lean | import Mathlib.Algebra.Group.Opposite
import Mathlib.Algebra.Order.Monoid.Defs
/-!
# Order instances for `MulOpposite`/`AddOpposite`
This file transfers order instances and ordered monoid/group instances from `α` to `αᵐᵒᵖ` and
`αᵃᵒᵖ`.
-/
variable {α : Type*}
namespace MulOpposite
section Preorder
variable [Preorder α]
@[to_additive] instance : Preorder αᵐᵒᵖ := Preorder.lift unop
@[to_additive (attr := simp)] lemma unop_le_unop {a b : αᵐᵒᵖ} : a.unop ≤ b.unop ↔ a ≤ b := .rfl
@[to_additive (attr := simp)] lemma op_le_op {a b : α} : op a ≤ op b ↔ a ≤ b := .rfl
end Preorder
@[to_additive] instance [PartialOrder α] : PartialOrder αᵐᵒᵖ := PartialOrder.lift _ unop_injective
section OrderedCommMonoid
variable [CommMonoid α] [PartialOrder α]
@[to_additive] instance [IsOrderedMonoid α] : IsOrderedMonoid αᵐᵒᵖ where
mul_le_mul_left a b hab c := mul_le_mul_right' (by simpa) c.unop
@[to_additive (attr := simp)] lemma unop_le_one {a : αᵐᵒᵖ} : unop a ≤ 1 ↔ a ≤ 1 := .rfl
@[to_additive (attr := simp)] lemma one_le_unop {a : αᵐᵒᵖ} : 1 ≤ unop a ↔ 1 ≤ a := .rfl
@[to_additive (attr := simp)] lemma op_le_one {a : α} : op a ≤ 1 ↔ a ≤ 1 := .rfl
@[to_additive (attr := simp)] lemma one_le_op {a : α} : 1 ≤ op a ↔ 1 ≤ a := .rfl
end OrderedCommMonoid
section OrderedAddCommMonoid
variable [AddCommMonoid α] [PartialOrder α]
instance [IsOrderedAddMonoid α] : IsOrderedAddMonoid αᵐᵒᵖ where
add_le_add_left a b hab c := add_le_add_left (by simpa) c.unop
@[simp] lemma unop_nonpos {a : αᵐᵒᵖ} : unop a ≤ 0 ↔ a ≤ 0 := .rfl
@[simp] lemma unop_nonneg {a : αᵐᵒᵖ} : 0 ≤ unop a ↔ 0 ≤ a := .rfl
@[simp] lemma op_nonpos {a : α} : op a ≤ 0 ↔ a ≤ 0 := .rfl
@[simp] lemma op_nonneg {a : α} : 0 ≤ op a ↔ 0 ≤ a := .rfl
end OrderedAddCommMonoid
end MulOpposite
namespace AddOpposite
section OrderedCommMonoid
variable [CommMonoid α] [PartialOrder α]
instance [IsOrderedMonoid α] : IsOrderedMonoid αᵃᵒᵖ where
mul_le_mul_left a b hab c := mul_le_mul_left' (by simpa) c.unop
@[simp] lemma unop_le_one {a : αᵃᵒᵖ} : unop a ≤ 1 ↔ a ≤ 1 := .rfl
@[simp] lemma one_le_unop {a : αᵃᵒᵖ} : 1 ≤ unop a ↔ 1 ≤ a := .rfl
@[simp] lemma op_le_one {a : α} : op a ≤ 1 ↔ a ≤ 1 := .rfl
@[simp] lemma one_le_op {a : α} : 1 ≤ op a ↔ 1 ≤ a := .rfl
end OrderedCommMonoid
end AddOpposite |
.lake/packages/mathlib/Mathlib/Algebra/Order/Group/Int.lean | import Mathlib.Algebra.Group.Int.Defs
import Mathlib.Algebra.Order.Monoid.Defs
/-!
# The integers form a linear ordered group
This file contains the instance necessary to show that the integers are a linear ordered
additive group.
See note [foundational algebra order theory].
-/
-- We should need only a minimal development of sets in order to get here.
assert_not_exists Set.Subsingleton Ring
instance Int.instIsOrderedAddMonoid : IsOrderedAddMonoid ℤ where
add_le_add_left _ _ := Int.add_le_add_left |
.lake/packages/mathlib/Mathlib/Algebra/Order/Group/Indicator.lean | import Mathlib.Algebra.Group.Indicator
import Mathlib.Order.ConditionallyCompleteLattice.Indexed
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, notMem_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 : 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 : α}
@[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 : a ∈ s → f a ≤ g a) :
mulIndicator s f a ≤ mulIndicator s g a :=
mulIndicator_rel_mulIndicator le_rfl h
@[to_additive (attr := mono, gcongr)]
lemma mulIndicator_le_mulIndicator (h : f a ≤ g a) : mulIndicator s f a ≤ mulIndicator s g a :=
mulIndicator_rel_mulIndicator le_rfl fun _ ↦ h
@[to_additive (attr := gcongr)]
lemma mulIndicator_mono (h : f ≤ g) : s.mulIndicator f ≤ s.mulIndicator g :=
fun _ ↦ mulIndicator_le_mulIndicator (h _)
@[to_additive]
lemma mulIndicator_le_mulIndicator_apply_of_subset (h : s ⊆ t) (hf : 1 ≤ f 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_mulIndicator_of_subset (h : s ⊆ t) (hf : 1 ≤ f) :
mulIndicator s f ≤ mulIndicator t f :=
fun _ ↦ mulIndicator_le_mulIndicator_apply_of_subset h (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]
@[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_notMem 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
· simp_all
· rw [mulIndicator_of_notMem hx]
simp only [mem_iInter, 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_notMem hj] using (iInf_le (fun i ↦ (s i).mulIndicator f) j) x
@[to_additive]
lemma iSup_mulIndicator {ι : Type*} [Preorder ι] [IsDirected ι (· ≤ ·)] {f : ι → α → M}
{s : ι → Set α} (h1 : (⊥ : M) = 1) (hf : Monotone f) (hs : Monotone s) :
⨆ i, (s i).mulIndicator (f i) = (⋃ i, s i).mulIndicator (⨆ i, f i) := by
simp only [le_antisymm_iff, iSup_le_iff]
refine ⟨fun i ↦ (mulIndicator_mono (le_iSup _ _)).trans (mulIndicator_le_mulIndicator_of_subset
(subset_iUnion _ _) (fun _ ↦ by simp [← h1])), fun a ↦ ?_⟩
by_cases ha : a ∈ ⋃ i, s i
· obtain ⟨i, hi⟩ : ∃ i, a ∈ s i := by simpa using ha
rw [mulIndicator_of_mem ha, iSup_apply, iSup_apply]
refine iSup_le fun j ↦ ?_
obtain ⟨k, hik, hjk⟩ := exists_ge_ge i j
refine le_iSup_of_le k <| (hf hjk _).trans_eq ?_
rw [mulIndicator_of_mem (hs hik hi)]
· rw [mulIndicator_of_notMem ha, ← h1]
exact bot_le
end CompleteLattice
section CanonicallyOrderedMul
variable [Monoid M] [PartialOrder M] [CanonicallyOrderedMul 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 CanonicallyOrderedMul
section LatticeOrderedCommGroup
variable [CommGroup M] [Lattice 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 LatticeOrderedCommGroup
end Set |
.lake/packages/mathlib/Mathlib/Algebra/Order/Group/MinMax.lean | 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 α] [MulLeftMono α]
-- 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*} [CommGroup α] [LinearOrder α] [IsOrderedMonoid α]
@[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 _ _ =>
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 _ _ =>
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*} [AddCommGroup α] [LinearOrder α] [IsOrderedAddMonoid α]
theorem max_sub_max_le_max (a b c d : α) : max a b - max c d ≤ max (a - c) (b - d) := by
grind
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 |
.lake/packages/mathlib/Mathlib/Algebra/Order/Group/Cyclic.lean | import Mathlib.Algebra.Order.Group.Basic
import Mathlib.GroupTheory.SpecificGroups.Cyclic
/-!
# Cyclic linearly ordered groups
This file contains basic results about cyclic linearly ordered groups and cyclic subgroups of
linearly ordered groups.
The definitions `LinearOrderedCommGroup.Subgroup.genLTOne` (*resp.*
`LinearOrderedCommGroup.genLTOone`) yields a generator of a non-trivial subgroup of a linearly
ordered commutative group with (*resp.* of a non-trivial linearly ordered commutative group) that
is strictly less than `1`. The corresponding additive definitions are also provided.
-/
noncomputable section
namespace LinearOrderedCommGroup
open LinearOrderedCommGroup
variable {G : Type*} [CommGroup G] [LinearOrder G] [IsOrderedMonoid G]
namespace Subgroup
variable (H : Subgroup G) [Nontrivial H] [hH : IsCyclic H]
@[to_additive exists_neg_generator]
lemma exists_generator_lt_one : ∃ (a : G), a < 1 ∧ Subgroup.zpowers a = H := by
obtain ⟨a, ha⟩ := H.isCyclic_iff_exists_zpowers_eq_top.mp hH
obtain ha1 | rfl | ha1 := lt_trichotomy a 1
· exact ⟨a, ha1, ha⟩
· rw [Subgroup.zpowers_one_eq_bot] at ha
exact absurd ha.symm <| (H.nontrivial_iff_ne_bot).mp inferInstance
· use a⁻¹, Left.inv_lt_one_iff.mpr ha1
rw [Subgroup.zpowers_inv, ha]
/-- Given a subgroup of a cyclic linearly ordered commutative group, this is a generator of
the subgroup that is `< 1`. -/
@[to_additive negGen /-- Given an additive subgroup of an additive cyclic linearly ordered
commutative group, this is a negative generator of the subgroup. -/]
protected noncomputable def genLTOne : G := H.exists_generator_lt_one.choose
@[to_additive negGen_neg]
lemma genLTOne_lt_one : H.genLTOne < 1 :=
H.exists_generator_lt_one.choose_spec.1
@[to_additive (attr := simp) negGen_zmultiples_eq_top]
lemma genLTOne_zpowers_eq_top : Subgroup.zpowers H.genLTOne = H :=
H.exists_generator_lt_one.choose_spec.2
lemma genLTOne_mem : H.genLTOne ∈ H := by
nth_rewrite 1 [← H.genLTOne_zpowers_eq_top]
exact Subgroup.mem_zpowers (Subgroup.genLTOne H)
lemma genLTOne_unique {g : G} (hg : g < 1) (hH : Subgroup.zpowers g = H) : g = H.genLTOne := by
have hg' : ¬ IsOfFinOrder g := not_isOfFinOrder_of_isMulTorsionFree (ne_of_lt hg)
rw [← H.genLTOne_zpowers_eq_top] at hH
rcases (Subgroup.zpowers_eq_zpowers_iff hg').mp hH with _ | h
· assumption
rw [← one_lt_inv', h] at hg
exact (not_lt_of_gt hg <| Subgroup.genLTOne_lt_one _).elim
lemma genLTOne_unique_of_zpowers_eq {g1 g2 : G} (hg1 : g1 < 1) (hg2 : g2 < 1)
(h : Subgroup.zpowers g1 = Subgroup.zpowers g2) : g1 = g2 := by
rcases (Subgroup.zpowers g2).bot_or_nontrivial with (h' | h')
· rw [h'] at h
simp_all only [Subgroup.zpowers_eq_bot]
· have h1 : IsCyclic ↥(Subgroup.zpowers g2) := by
rw [Subgroup.isCyclic_iff_exists_zpowers_eq_top]; use g2
have h2 : Nontrivial ↥(Subgroup.zpowers g1) := by rw [h]; exact h'
have h3 : IsCyclic ↥(Subgroup.zpowers g1) := by rw [h]; exact h1
simp only [(Subgroup.zpowers g2).genLTOne_unique hg1 h]
simp only [← h]
simp only [(Subgroup.zpowers g1).genLTOne_unique hg2 h.symm]
end Subgroup
section IsCyclic
variable (G) [Nontrivial G] [IsCyclic G]
/-- Given a cyclic linearly ordered commutative group, this is a generator that is `< 1`. -/
@[to_additive negGen /-- Given an additive cyclic linearly ordered commutative group, this is a
negative generator of it. -/]
noncomputable def genLTOne : G := (⊤ : Subgroup G).genLTOne
@[to_additive (attr := simp) negGen_eq_of_top]
lemma genLTOne_eq_of_top : genLTOne G = (⊤ : Subgroup G).genLTOne := rfl
lemma genLTOne_unique {g : G} (hg : g < 1) (htop : Subgroup.zpowers g = ⊤) : g = genLTOne G :=
(⊤ : Subgroup G).genLTOne_unique hg htop
end IsCyclic
end LinearOrderedCommGroup |
.lake/packages/mathlib/Mathlib/Algebra/Order/Group/Prod.lean | import Mathlib.Algebra.Order.Group.Defs
import Mathlib.Algebra.Order.Monoid.Prod
import Mathlib.Tactic.Linter.DeprecatedModule
deprecated_module (since := "2025-04-16") |
.lake/packages/mathlib/Mathlib/Algebra/Order/Group/Nat.lean | import Mathlib.Algebra.Group.Nat.Defs
import Mathlib.Algebra.Order.Monoid.Canonical.Defs
import Mathlib.Algebra.Order.Sub.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 instIsOrderedAddMonoid : IsOrderedAddMonoid ℕ where
add_le_add_left := @Nat.add_le_add_left
instance instIsOrderedCancelAddMonoid : IsOrderedCancelAddMonoid ℕ where
add_le_add_left := @Nat.add_le_add_left
le_of_add_le_add_left := @Nat.le_of_add_le_add_left
instance instCanonicallyOrderedAdd : CanonicallyOrderedAdd ℕ where
le_add_self := Nat.le_add_left
le_self_add := Nat.le_add_right
exists_add_of_le := Nat.exists_eq_add_of_le
instance instOrderedSub : OrderedSub ℕ := by
refine ⟨fun m n k ↦ ?_⟩
induction n generalizing k with
| zero => simp
| succ n ih => 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 |
.lake/packages/mathlib/Mathlib/Algebra/Order/Group/Cone.lean | import Mathlib.Algebra.Group.Subgroup.Defs
import Mathlib.Algebra.Order.Group.Unbundled.Basic
import Mathlib.Algebra.Order.Monoid.Submonoid
/-!
# Construct ordered groups from groups with a specified positive cone.
In this file we provide the structure `GroupCone` and the predicate `IsMaxCone`
that encode axioms of `OrderedCommGroup` and `LinearOrderedCommGroup`
in terms of the subset of non-negative elements.
We also provide constructors that convert between
cones in groups and the corresponding ordered groups.
-/
/-- `AddGroupConeClass S G` says that `S` is a type of cones in `G`. -/
class AddGroupConeClass (S : Type*) (G : outParam Type*) [AddCommGroup G] [SetLike S G] : Prop
extends AddSubmonoidClass S G where
eq_zero_of_mem_of_neg_mem {C : S} {a : G} : a ∈ C → -a ∈ C → a = 0
/-- `GroupConeClass S G` says that `S` is a type of cones in `G`. -/
@[to_additive]
class GroupConeClass (S : Type*) (G : outParam Type*) [CommGroup G] [SetLike S G] : Prop
extends SubmonoidClass S G where
eq_one_of_mem_of_inv_mem {C : S} {a : G} : a ∈ C → a⁻¹ ∈ C → a = 1
export GroupConeClass (eq_one_of_mem_of_inv_mem)
export AddGroupConeClass (eq_zero_of_mem_of_neg_mem)
/-- A (positive) cone in an abelian group is a submonoid that
does not contain both `a` and `-a` for any nonzero `a`.
This is equivalent to being the set of non-negative elements of
some order making the group into a partially ordered group. -/
structure AddGroupCone (G : Type*) [AddCommGroup G] extends AddSubmonoid G where
eq_zero_of_mem_of_neg_mem' {a} : a ∈ carrier → -a ∈ carrier → a = 0
/-- A (positive) cone in an abelian group is a submonoid that
does not contain both `a` and `a⁻¹` for any non-identity `a`.
This is equivalent to being the set of elements that are at least 1 in
some order making the group into a partially ordered group. -/
@[to_additive]
structure GroupCone (G : Type*) [CommGroup G] extends Submonoid G where
eq_one_of_mem_of_inv_mem' {a} : a ∈ carrier → a⁻¹ ∈ carrier → a = 1
@[to_additive]
instance GroupCone.instSetLike (G : Type*) [CommGroup G] : SetLike (GroupCone G) G where
coe C := C.carrier
coe_injective' p q h := by cases p; cases q; congr; exact SetLike.ext' h
@[to_additive]
instance GroupCone.instGroupConeClass (G : Type*) [CommGroup G] :
GroupConeClass (GroupCone G) G where
mul_mem {C} := C.mul_mem'
one_mem {C} := C.one_mem'
eq_one_of_mem_of_inv_mem {C} := C.eq_one_of_mem_of_inv_mem'
initialize_simps_projections GroupCone (carrier → coe, as_prefix coe)
initialize_simps_projections AddGroupCone (carrier → coe, as_prefix coe)
@[deprecated (since := "2025-08-21")] alias IsMaxCone := NegMemClass
@[deprecated (since := "2025-08-21")] alias IsMaxMulCone := InvMemClass
namespace GroupCone
variable {H : Type*} [CommGroup H] [PartialOrder H] [IsOrderedMonoid H] {a : H}
variable (H) in
/-- The cone of elements that are at least 1. -/
@[to_additive /-- The cone of non-negative elements. -/]
def oneLE : GroupCone H where
__ := Submonoid.oneLE H
eq_one_of_mem_of_inv_mem' {a} := by simpa using ge_antisymm
@[to_additive (attr := simp)]
lemma oneLE_toSubmonoid : (oneLE H).toSubmonoid = .oneLE H := rfl
@[to_additive (attr := simp)]
lemma mem_oneLE : a ∈ oneLE H ↔ 1 ≤ a := Iff.rfl
@[to_additive (attr := simp, norm_cast)]
lemma coe_oneLE : oneLE H = {x : H | 1 ≤ x} := rfl
@[to_additive]
instance oneLE.hasMemOrInvMem {H : Type*} [CommGroup H] [LinearOrder H] [IsOrderedMonoid H] :
HasMemOrInvMem (oneLE H) where
mem_or_inv_mem := by simpa using le_total 1
@[deprecated (since := "2025-08-21")] alias oneLE.isMaxMulCone := oneLE.hasMemOrInvMem
@[deprecated (since := "2025-08-21")] alias _root_.AddGroupCone.nonneg.isMaxCone :=
AddGroupCone.nonneg.hasMemOrNegMem
end GroupCone
variable {S G : Type*} [CommGroup G] [SetLike S G] (C : S)
/-- Construct a partial order by designating a cone in an abelian group. -/
@[to_additive /-- Construct a partial order by designating a cone in an abelian group. -/]
abbrev PartialOrder.mkOfGroupCone [GroupConeClass S G] : PartialOrder G where
le a b := b / a ∈ C
le_refl a := by simp [one_mem]
le_trans a b c nab nbc := by simpa using mul_mem nbc nab
le_antisymm a b nab nba := by
simpa [div_eq_one, eq_comm] using eq_one_of_mem_of_inv_mem nab (by simpa using nba)
@[to_additive (attr := simp)]
lemma PartialOrder.mkOfGroupCone_le_iff {S G : Type*} [CommGroup G] [SetLike S G]
[GroupConeClass S G] {C : S} {a b : G} :
(mkOfGroupCone C).le a b ↔ b / a ∈ C := Iff.rfl
/-- Construct a linear order by designating a maximal cone in an abelian group. -/
@[to_additive /-- Construct a linear order by designating a maximal cone in an abelian group. -/]
abbrev LinearOrder.mkOfGroupCone
[GroupConeClass S G] [HasMemOrInvMem C] [DecidablePred (· ∈ C)] : LinearOrder G where
__ := PartialOrder.mkOfGroupCone C
le_total a b := by simpa using mem_or_inv_mem C (b / a)
toDecidableLE _ := _
/-- Construct a partially ordered abelian group by designating a cone in an abelian group. -/
@[to_additive
/-- Construct a partially ordered abelian group by designating a cone in an abelian group. -/]
lemma IsOrderedMonoid.mkOfCone [GroupConeClass S G] :
let _ : PartialOrder G := PartialOrder.mkOfGroupCone C
IsOrderedMonoid G :=
let _ : PartialOrder G := PartialOrder.mkOfGroupCone C
{ mul_le_mul_left := fun a b nab c ↦ by simpa [· ≤ ·] using nab } |
.lake/packages/mathlib/Mathlib/Algebra/Order/Group/Finset.lean | import Mathlib.Algebra.Order.Group.OrderIso
import Mathlib.Algebra.Order.Monoid.Canonical.Defs
import Mathlib.Algebra.Order.Monoid.Unbundled.MinMax
import Mathlib.Algebra.Order.Monoid.Unbundled.Pow
import Mathlib.Algebra.Order.Monoid.Unbundled.WithTop
import Mathlib.Data.Finset.Lattice.Prod
/-!
# `Finset.sup` in a group
-/
open scoped Finset
assert_not_exists MonoidWithZero
namespace Multiset
variable {α : Type*} [DecidableEq α]
@[simp] lemma toFinset_nsmul (s : Multiset α) : ∀ n ≠ 0, (n • s).toFinset = s.toFinset
| 0, h => by contradiction
| n + 1, _ => by
by_cases h : n = 0
· rw [h, zero_add, one_nsmul]
· rw [add_nsmul, toFinset_add, one_nsmul, toFinset_nsmul s n h, Finset.union_idempotent]
lemma toFinset_eq_singleton_iff (s : Multiset α) (a : α) :
s.toFinset = {a} ↔ card s ≠ 0 ∧ s = card s • {a} := by
refine ⟨fun H ↦ ⟨fun h ↦ ?_, ext' fun x ↦ ?_⟩, fun H ↦ ?_⟩
· rw [card_eq_zero.1 h, toFinset_zero] at H
exact Finset.empty_ne_singleton _ H
· rw [count_nsmul, count_singleton]
by_cases hx : x = a
· simp_rw [hx, ite_true, mul_one, count_eq_card]
intro y hy
rw [← mem_toFinset, H, Finset.mem_singleton] at hy
exact hy.symm
have hx' : x ∉ s := fun h' ↦ hx <| by rwa [← mem_toFinset, H, Finset.mem_singleton] at h'
simp_rw [count_eq_zero_of_notMem hx', hx, ite_false, Nat.mul_zero]
simpa only [toFinset_nsmul _ _ H.1, toFinset_singleton] using congr($(H.2).toFinset)
lemma toFinset_card_eq_one_iff (s : Multiset α) :
#s.toFinset = 1 ↔ Multiset.card s ≠ 0 ∧ ∃ a : α, s = Multiset.card s • {a} := by
simp_rw [Finset.card_eq_one, Multiset.toFinset_eq_singleton_iff, exists_and_left]
end Multiset
namespace Finset
variable {ι κ M G : Type*}
lemma fold_max_add [LinearOrder M] [Add M] [AddRightMono M] (s : Finset ι) (a : WithBot M)
(f : ι → M) : s.fold max ⊥ (fun i ↦ ↑(f i) + a) = s.fold max ⊥ ((↑) ∘ f) + a := by
classical induction s using Finset.induction_on <;> simp [*, max_add_add_right]
@[to_additive nsmul_inf']
lemma inf'_pow [LinearOrder M] [Monoid M] [MulLeftMono M] [MulRightMono M] (s : Finset ι)
(f : ι → M) (n : ℕ) (hs) : s.inf' hs f ^ n = s.inf' hs fun a ↦ f a ^ n :=
map_finset_inf' (OrderHom.mk _ <| pow_left_mono n) hs _
@[to_additive nsmul_sup']
lemma sup'_pow [LinearOrder M] [Monoid M] [MulLeftMono M] [MulRightMono M] (s : Finset ι)
(f : ι → M) (n : ℕ) (hs) : s.sup' hs f ^ n = s.sup' hs fun a ↦ f a ^ n :=
map_finset_sup' (OrderHom.mk _ <| pow_left_mono n) hs _
section Group
variable [Group G] [LinearOrder G]
@[to_additive /-- Also see `Finset.sup'_add'` that works for canonically ordered monoids. -/]
lemma sup'_mul [MulRightMono G] (s : Finset ι) (f : ι → G) (a : G) (hs) :
s.sup' hs f * a = s.sup' hs fun i ↦ f i * a := map_finset_sup' (OrderIso.mulRight a) hs f
set_option linter.docPrime false in
@[to_additive /-- Also see `Finset.add_sup''` that works for canonically ordered monoids. -/]
lemma mul_sup' [MulLeftMono G] (s : Finset ι) (f : ι → G) (a : G) (hs) :
a * s.sup' hs f = s.sup' hs fun i ↦ a * f i := map_finset_sup' (OrderIso.mulLeft a) hs f
end Group
section CanonicallyLinearOrderedAddCommMonoid
variable [AddCommMonoid M] [LinearOrder M] [CanonicallyOrderedAdd M]
[Sub M] [AddLeftReflectLE M] [OrderedSub M] {s : Finset ι} {t : Finset κ}
/-- Also see `Finset.sup'_add` that works for ordered groups. -/
lemma sup'_add' (s : Finset ι) (f : ι → M) (a : M) (hs : s.Nonempty) :
s.sup' hs f + a = s.sup' hs fun i ↦ f i + a := by
apply le_antisymm
· apply add_le_of_le_tsub_right_of_le
· exact Finset.le_sup'_of_le _ hs.choose_spec le_add_self
· exact Finset.sup'_le _ _ fun i hi ↦ le_tsub_of_add_le_right (Finset.le_sup' (f · + a) hi)
· exact Finset.sup'_le _ _ fun i hi ↦ by grw [← Finset.le_sup' _ hi]
/-- Also see `Finset.add_sup'` that works for ordered groups. -/
lemma add_sup'' (hs : s.Nonempty) (f : ι → M) (a : M) :
a + s.sup' hs f = s.sup' hs fun i ↦ a + f i := by simp_rw [add_comm a, Finset.sup'_add']
variable [OrderBot M]
protected lemma sup_add (hs : s.Nonempty) (f : ι → M) (a : M) :
s.sup f + a = s.sup fun i ↦ f i + a := by
rw [← Finset.sup'_eq_sup hs, ← Finset.sup'_eq_sup hs, sup'_add']
protected lemma add_sup (hs : s.Nonempty) (f : ι → M) (a : M) :
a + s.sup f = s.sup fun i ↦ a + f i := by
rw [← Finset.sup'_eq_sup hs, ← Finset.sup'_eq_sup hs, add_sup'']
lemma sup_add_sup (hs : s.Nonempty) (ht : t.Nonempty) (f : ι → M) (g : κ → M) :
s.sup f + t.sup g = (s ×ˢ t).sup fun ij ↦ f ij.1 + g ij.2 := by
simp only [Finset.sup_add hs, Finset.add_sup ht, Finset.sup_product_left]
end CanonicallyLinearOrderedAddCommMonoid
end Finset |
.lake/packages/mathlib/Mathlib/Algebra/Order/Group/Basic.lean | import Mathlib.Algebra.Order.Group.Unbundled.Basic
import Mathlib.Algebra.Order.Monoid.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 {α : Type*}
section OrderedCommGroup
variable [CommGroup α] [PartialOrder α] [IsOrderedMonoid α] {m n : ℤ} {a b : α}
@[to_additive zsmul_left_strictMono]
lemma zpow_right_strictMono (ha : 1 < a) : StrictMono fun n : ℤ ↦ a ^ n := by
refine strictMono_int_of_lt_succ fun n ↦ ?_
rw [zpow_add_one]
exact lt_mul_of_one_lt_right' (a ^ n) ha
@[to_additive zsmul_left_strictAnti]
lemma zpow_right_strictAnti (ha : a < 1) : StrictAnti fun n : ℤ ↦ a ^ n := by
refine strictAnti_int_of_succ_lt fun n ↦ ?_
rw [zpow_add_one]
exact mul_lt_of_lt_one_right' (a ^ n) ha
@[to_additive zsmul_left_inj]
lemma zpow_right_inj (ha : 1 < a) {m n : ℤ} : a ^ m = a ^ n ↔ m = n :=
(zpow_right_strictMono ha).injective.eq_iff
@[to_additive zsmul_left_mono]
lemma zpow_right_mono (ha : 1 ≤ a) : Monotone fun n : ℤ ↦ a ^ n := by
refine monotone_int_of_le_succ fun n ↦ ?_
rw [zpow_add_one]
exact le_mul_of_one_le_right' ha
@[to_additive (attr := gcongr) zsmul_le_zsmul_left]
lemma zpow_le_zpow_right (ha : 1 ≤ a) (h : m ≤ n) : a ^ m ≤ a ^ n := zpow_right_mono ha h
@[to_additive (attr := gcongr) zsmul_lt_zsmul_left]
lemma zpow_lt_zpow_right (ha : 1 < a) (h : m < n) : a ^ m < a ^ n := zpow_right_strictMono ha h
@[to_additive zsmul_le_zsmul_iff_left]
lemma zpow_le_zpow_iff_right (ha : 1 < a) : a ^ m ≤ a ^ n ↔ m ≤ n :=
(zpow_right_strictMono ha).le_iff_le
@[to_additive zsmul_lt_zsmul_iff_left]
lemma zpow_lt_zpow_iff_right (ha : 1 < a) : a ^ m < a ^ n ↔ m < n :=
(zpow_right_strictMono ha).lt_iff_lt
variable (α)
@[to_additive zsmul_strictMono_right]
lemma zpow_left_strictMono (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_left_mono (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) zsmul_le_zsmul_right]
lemma zpow_le_zpow_left (hn : 0 ≤ n) (h : a ≤ b) : a ^ n ≤ b ^ n := zpow_left_mono α hn h
@[to_additive (attr := gcongr) zsmul_lt_zsmul_right]
lemma zpow_lt_zpow_left (hn : 0 < n) (h : a < b) : a ^ n < b ^ n := zpow_left_strictMono α hn h
end OrderedCommGroup
section LinearOrderedCommGroup
variable [CommGroup α] [LinearOrder α] [IsOrderedMonoid α] {n : ℤ} {a b : α}
@[to_additive zsmul_le_zsmul_iff_right]
lemma zpow_le_zpow_iff_left (hn : 0 < n) : a ^ n ≤ b ^ n ↔ a ≤ b :=
(zpow_left_strictMono α hn).le_iff_le
@[to_additive zsmul_lt_zsmul_iff_right]
lemma zpow_lt_zpow_iff_left (hn : 0 < n) : a ^ n < b ^ n ↔ a < b :=
(zpow_left_strictMono α hn).lt_iff_lt
variable (α) in
/-- A nontrivial densely linear ordered commutative group can't be a cyclic group. -/
@[to_additive
/-- A nontrivial densely linear ordered additive commutative group can't be a cyclic group. -/]
theorem not_isCyclic_of_denselyOrdered [DenselyOrdered α] [Nontrivial α] : ¬IsCyclic α := by
intro h
rcases exists_zpow_surjective α with ⟨a, ha⟩
rcases lt_trichotomy a 1 with hlt | rfl | hlt
· rcases exists_between hlt with ⟨b, hab, hb⟩
rcases ha b with ⟨k, rfl⟩
suffices 0 < k ∧ k < 1 by cutsat
rw [← one_lt_inv'] at hlt
simp_rw [← zpow_lt_zpow_iff_right hlt]
simp_all
· rcases exists_ne (1 : α) with ⟨b, hb⟩
simpa [hb.symm] using ha b
· rcases exists_between hlt with ⟨b, hb, hba⟩
rcases ha b with ⟨k, rfl⟩
suffices 0 < k ∧ k < 1 by cutsat
simp_rw [← zpow_lt_zpow_iff_right hlt]
simp_all
end LinearOrderedCommGroup |
.lake/packages/mathlib/Mathlib/Algebra/Order/Group/Multiset.lean | import Mathlib.Algebra.Group.Hom.Defs
import Mathlib.Algebra.Group.Nat.Defs
import Mathlib.Algebra.Order.Monoid.Unbundled.ExistsOfLE
import Mathlib.Algebra.Order.Sub.Defs
import Mathlib.Data.Multiset.Fold
/-!
# Multisets form an ordered monoid
This file contains the ordered monoid instance on multisets, and lemmas related to it.
See note [foundational algebra order theory].
-/
open List Nat
variable {α β : Type*}
namespace Multiset
/-! ### Additive monoid -/
instance instAddLeftMono : AddLeftMono (Multiset α) where elim _s _t _u := Multiset.add_le_add_left
instance instAddLeftReflectLE : AddLeftReflectLE (Multiset α) where
elim _s _t _u := Multiset.le_of_add_le_add_left
instance instAddCancelCommMonoid : AddCancelCommMonoid (Multiset α) where
add_comm := Multiset.add_comm
add_assoc := Multiset.add_assoc
zero_add := Multiset.zero_add
add_zero := Multiset.add_zero
add_left_cancel _ _ _ := Multiset.add_right_inj.1
nsmul := nsmulRec
lemma mem_of_mem_nsmul {a : α} {s : Multiset α} {n : ℕ} (h : a ∈ n • s) : a ∈ s := by
induction n with
| zero =>
rw [zero_nsmul] at h
exact absurd h (notMem_zero _)
| succ n ih =>
rw [succ_nsmul, mem_add] at h
exact h.elim ih id
@[simp]
lemma mem_nsmul {a : α} {s : Multiset α} {n : ℕ} : a ∈ n • s ↔ n ≠ 0 ∧ a ∈ s := by
refine ⟨fun ha ↦ ⟨?_, mem_of_mem_nsmul ha⟩, fun h ↦ ?_⟩
· rintro rfl
simp [zero_nsmul] at ha
obtain ⟨n, rfl⟩ := exists_eq_succ_of_ne_zero h.1
rw [succ_nsmul, mem_add]
exact Or.inr h.2
lemma mem_nsmul_of_ne_zero {a : α} {s : Multiset α} {n : ℕ} (h0 : n ≠ 0) : a ∈ n • s ↔ a ∈ s := by
simp [*]
lemma nsmul_cons {s : Multiset α} (n : ℕ) (a : α) :
n • (a ::ₘ s) = n • ({a} : Multiset α) + n • s := by
rw [← singleton_add, nsmul_add]
/-! ### Cardinality -/
/-- `Multiset.card` bundled as a group hom. -/
@[simps]
def cardHom : Multiset α →+ ℕ where
toFun := card
map_zero' := card_zero
map_add' := card_add
@[simp]
lemma card_nsmul (s : Multiset α) (n : ℕ) : card (n • s) = n * card s := cardHom.map_nsmul ..
/-! ### `Multiset.replicate` -/
/-- `Multiset.replicate` as an `AddMonoidHom`. -/
@[simps]
def replicateAddMonoidHom (a : α) : ℕ →+ Multiset α where
toFun n := replicate n a
map_zero' := replicate_zero a
map_add' _ _ := replicate_add _ _ a
lemma nsmul_replicate {a : α} (n m : ℕ) : n • replicate m a = replicate (n * m) a :=
((replicateAddMonoidHom a).map_nsmul _ _).symm
lemma nsmul_singleton (a : α) (n) : n • ({a} : Multiset α) = replicate n a := by
rw [← replicate_one, nsmul_replicate, mul_one]
/-! ### `Multiset.map` -/
/-- `Multiset.map` as an `AddMonoidHom`. -/
@[simps]
def mapAddMonoidHom (f : α → β) : Multiset α →+ Multiset β where
toFun := map f
map_zero' := map_zero _
map_add' := map_add _
@[simp]
lemma coe_mapAddMonoidHom (f : α → β) : (mapAddMonoidHom f : Multiset α → Multiset β) = map f := rfl
lemma map_nsmul (f : α → β) (n : ℕ) (s) : map f (n • s) = n • map f s :=
(mapAddMonoidHom f).map_nsmul _ _
/-! ### Subtraction -/
section
variable [DecidableEq α]
instance : OrderedSub (Multiset α) where tsub_le_iff_right _n _m _k := Multiset.sub_le_iff_le_add
instance : ExistsAddOfLE (Multiset α) where
exists_add_of_le h := leInductionOn h fun s ↦
let ⟨l, p⟩ := s.exists_perm_append; ⟨l, Quot.sound p⟩
end
/-! ### `Multiset.filter` -/
section
variable (p : α → Prop) [DecidablePred p]
lemma filter_nsmul (s : Multiset α) (n : ℕ) : filter p (n • s) = n • filter p s := by
refine s.induction_on ?_ ?_
· simp only [filter_zero, nsmul_zero]
· intro a ha ih
rw [nsmul_cons, filter_add, ih, filter_cons, nsmul_add]
congr
split_ifs with hp <;>
· simp only [filter_eq_self, nsmul_zero, filter_eq_nil]
intro b hb
rwa [mem_singleton.mp (mem_of_mem_nsmul hb)]
/-! ### countP -/
@[simp]
lemma countP_nsmul (s) (n : ℕ) : countP p (n • s) = n * countP p s := by
induction n <;> simp [*, succ_nsmul, succ_mul, zero_nsmul]
/-- `countP p`, the number of elements of a multiset satisfying `p`, promoted to an
`AddMonoidHom`. -/
def countPAddMonoidHom : Multiset α →+ ℕ where
toFun := countP p
map_zero' := countP_zero _
map_add' := countP_add _
@[simp] lemma coe_countPAddMonoidHom : (countPAddMonoidHom p : Multiset α → ℕ) = countP p := rfl
end
@[simp] lemma dedup_nsmul [DecidableEq α] {s : Multiset α} {n : ℕ} (hn : n ≠ 0) :
(n • s).dedup = s.dedup := by ext a; by_cases h : a ∈ s <;> simp [h, hn]
lemma Nodup.le_nsmul_iff_le {s t : Multiset α} {n : ℕ} (h : s.Nodup) (hn : n ≠ 0) :
s ≤ n • t ↔ s ≤ t := by
classical simp [← h.le_dedup_iff_le, hn]
/-! ### Multiplicity of an element -/
section
variable [DecidableEq α] {s : Multiset α}
/-- `count a`, the multiplicity of `a` in a multiset, promoted to an `AddMonoidHom`. -/
def countAddMonoidHom (a : α) : Multiset α →+ ℕ :=
countPAddMonoidHom (a = ·)
@[simp]
lemma coe_countAddMonoidHom (a : α) : (countAddMonoidHom a : Multiset α → ℕ) = count a := rfl
@[simp]
lemma count_nsmul (a : α) (n s) : count a (n • s) = n * count a s := by
induction n <;> simp [*, succ_nsmul, succ_mul, zero_nsmul]
end
-- TODO: This should be `addMonoidHom_ext`
@[ext]
lemma addHom_ext [AddZeroClass β] ⦃f g : Multiset α →+ β⦄ (h : ∀ x, f {x} = g {x}) : f = g := by
ext s
induction s using Multiset.induction_on with
| empty => simp only [_root_.map_zero]
| cons a s ih => simp only [← singleton_add, _root_.map_add, ih, h]
theorem le_smul_dedup [DecidableEq α] (s : Multiset α) : ∃ n : ℕ, s ≤ n • dedup s :=
⟨(s.map fun a => count a s).fold max 0,
le_iff_count.2 fun a => by
rw [count_nsmul]; by_cases h : a ∈ s
· grw [← one_le_count_iff_mem.2 <| mem_dedup.2 h]
have : count a s ≤ fold max 0 (map (fun a => count a s) (a ::ₘ erase s a)) := by
simp
rw [cons_erase h] at this
simpa [mul_succ] using this
· simp [count_eq_zero.2 h, Nat.zero_le]⟩
end Multiset |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.