doc-next-gen

Mathlib.Algebra.Order.AddGroupWithTop

Module docstring

{"# 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. "}

LinearOrderedAddCommMonoidWithTop structure
(α : Type*) extends AddCommMonoid α, LinearOrder α, IsOrderedAddMonoid α, OrderTop α
Full source
/-- 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 = 
Linearly Ordered Commutative Additive Monoid with Top Element
Informal description
A structure representing a linearly ordered commutative additive monoid $\alpha$ with a top element $\top$ that is additively absorbing (i.e., $a + \top = \top$ for all $a \in \alpha$). This structure combines the properties of a commutative additive monoid, a linear order, and an ordered additive monoid, while also including a top element that is greater than all other elements in the order.
LinearOrderedAddCommGroupWithTop structure
(α : Type*) extends LinearOrderedAddCommMonoidWithTop α, SubNegMonoid α, Nontrivial α
Full source
/-- 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
Linearly ordered commutative additive group with top element
Informal description
A linearly ordered commutative additive group with a top element $\top$ that is additively absorbing (i.e., $\top + a = \top$ for any $a$). This structure is used to model number systems with an infinite element adjoined, such as the extended non-negative real numbers $\mathbb{R}_{\geq 0} \cup \{\infty\}$.
WithTop.linearOrderedAddCommMonoidWithTop instance
[AddCommMonoid α] [LinearOrder α] [IsOrderedAddMonoid α] : LinearOrderedAddCommMonoidWithTop (WithTop α)
Full source
instance WithTop.linearOrderedAddCommMonoidWithTop
    [AddCommMonoid α] [LinearOrder α] [IsOrderedAddMonoid α] :
    LinearOrderedAddCommMonoidWithTop (WithTop α) :=
  { top_add' := WithTop.top_add }
The Linearly Ordered Commutative Additive Monoid Structure on $\alpha \cup \{\top\}$
Informal description
For any linearly ordered commutative additive monoid $\alpha$, the type $\alpha \cup \{\top\}$ (denoted `WithTop α`) is also a linearly ordered commutative additive monoid with top element $\top$, where $\top$ is additively absorbing (i.e., $a + \top = \top + a = \top$ for all $a \in \alpha \cup \{\top\}$).
top_add theorem
(a : α) : ⊤ + a = ⊤
Full source
@[simp]
theorem top_add (a : α) :  + a =  :=
  LinearOrderedAddCommMonoidWithTop.top_add' a
Top Element is Additively Absorbing on the Left
Informal description
For any element $a$ in a linearly ordered commutative additive monoid $\alpha$ with a top element $\top$, the sum of $\top$ and $a$ equals $\top$, i.e., $\top + a = \top$.
add_top theorem
(a : α) : a + ⊤ = ⊤
Full source
@[simp]
theorem add_top (a : α) : a +  =  :=
  Trans.trans (add_comm _ _) (top_add _)
Top Element is Additively Absorbing on the Right
Informal description
For any element $a$ in a linearly ordered commutative additive monoid $\alpha$ with a top element $\top$, the sum of $a$ and $\top$ equals $\top$, i.e., $a + \top = \top$.
WithTop.LinearOrderedAddCommGroup.instNeg instance
[AddCommGroup α] : Neg (WithTop α)
Full source
instance instNeg [AddCommGroup α] : Neg (WithTop α) where
  neg := Option.map fun a : α => -a
Negation Operation on Linearly Ordered Commutative Additive Groups with Top Element
Informal description
For any linearly ordered commutative additive group $\alpha$, the type $\alpha \cup \{\top\}$ (denoted as `WithTop α`) has a negation operation defined by $\neg \top = \top$ and $\neg x = -x$ for $x \in \alpha$.
WithTop.LinearOrderedAddCommGroup.sub definition
[AddCommGroup α] : WithTop α → WithTop α → WithTop α
Full source
/-- 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 : α)
Subtraction on a linearly ordered commutative additive group with top element
Informal description
The subtraction operation on `WithTop α`, where `α` is an additive commutative group, is defined as follows: - For any element $x \in \alpha$ and the top element $\top$, $x - \top = \top$ and $\top - x = \top$. - For $x, y \in \alpha$, the subtraction is defined as the usual subtraction in $\alpha$, i.e., $x - y$ (as elements of $\alpha$). This operation extends the subtraction from $\alpha$ to $\WithTop \alpha$ in a way that preserves the order structure when $\alpha$ is linearly ordered.
WithTop.LinearOrderedAddCommGroup.instSub instance
[AddCommGroup α] : Sub (WithTop α)
Full source
instance instSub [AddCommGroup α] : Sub (WithTop α) where
  sub := WithTop.LinearOrderedAddCommGroup.sub
Subtraction Operation on Linearly Ordered Commutative Additive Groups with Top Element
Informal description
For any linearly ordered commutative additive group $\alpha$, the type $\alpha \cup \{\top\}$ (denoted as `WithTop α`) has a subtraction operation defined by: - $\top - x = \top$ for any $x \in \alpha \cup \{\top\}$ - $x - \top = \top$ for any $x \in \alpha \cup \{\top\}$ - $x - y$ is the usual subtraction in $\alpha$ for $x, y \in \alpha$ This operation extends the subtraction from $\alpha$ to $\WithTop \alpha$ while preserving the order structure.
WithTop.LinearOrderedAddCommGroup.coe_neg theorem
(a : α) : ((-a : α) : WithTop α) = -a
Full source
@[simp, norm_cast]
theorem coe_neg (a : α) : ((-a : α) : WithTop α) = -a :=
  rfl
Negation Compatibility in Linearly Ordered Commutative Additive Groups with Top Element
Informal description
For any element $a$ in a linearly ordered commutative additive group $\alpha$, the negation operation on $\alpha \cup \{\top\}$ (denoted as `WithTop α`) satisfies $(-a : \alpha) = -a$ when viewed as an element of `WithTop α`.
WithTop.LinearOrderedAddCommGroup.neg_top theorem
: -(⊤ : WithTop α) = ⊤
Full source
@[simp]
theorem neg_top : -( : WithTop α) =  := rfl
Negation of Top Element: $- \top = \top$
Informal description
The negation of the top element $\top$ in the type $\alpha \cup \{\top\}$ is itself, i.e., $- \top = \top$.
WithTop.LinearOrderedAddCommGroup.coe_sub theorem
{a b : α} : (↑(a - b) : WithTop α) = ↑a - ↑b
Full source
@[simp, norm_cast]
theorem coe_sub {a b : α} : (↑(a - b) : WithTop α) = ↑a - ↑b := rfl
Embedding Preserves Subtraction in Linearly Ordered Commutative Additive Groups with Top Element
Informal description
For any elements $a$ and $b$ in a linearly ordered commutative additive group $\alpha$, the canonical embedding of their difference into $\alpha \cup \{\top\}$ (denoted as `WithTop α`) equals the difference of their embeddings, i.e., $(a - b : \alpha) = (a : \WithTop \alpha) - (b : \WithTop \alpha)$.
WithTop.LinearOrderedAddCommGroup.top_sub theorem
{a : WithTop α} : (⊤ : WithTop α) - a = ⊤
Full source
@[simp]
theorem top_sub {a : WithTop α} : ( : WithTop α) - a =  := by
  cases a <;> rfl
Subtraction from Top Yields Top in $\alpha \cup \{\top\}$
Informal description
For any element $a$ in the type $\alpha \cup \{\top\}$ (where $\alpha$ is a linearly ordered commutative additive group), the subtraction $\top - a$ equals $\top$.
WithTop.LinearOrderedAddCommGroup.sub_top theorem
{a : WithTop α} : a - ⊤ = ⊤
Full source
@[simp]
theorem sub_top {a : WithTop α} : a -  =  := by cases a <;> rfl
Subtraction of Any Element by Top Yields Top in $\alpha \cup \{\top\}$
Informal description
For any element $a$ in the type $\alpha \cup \{\top\}$ (where $\alpha$ is a linearly ordered commutative additive group), the subtraction $a - \top$ equals $\top$.
WithTop.LinearOrderedAddCommGroup.sub_eq_top_iff theorem
{a b : WithTop α} : a - b = ⊤ ↔ (a = ⊤ ∨ b = ⊤)
Full source
@[simp]
lemma sub_eq_top_iff {a b : WithTop α} : a - b = ⊤ ↔ (a = ⊤ ∨ b = ⊤) := by
  cases a <;> cases b <;> simp [← coe_sub]
Subtraction Yields Top if and only if Either Operand is Top in $\alpha \cup \{\top\}$
Informal description
For any elements $a, b$ in the type $\alpha \cup \{\top\}$ (where $\alpha$ is a linearly ordered commutative additive group), the subtraction $a - b$ equals $\top$ if and only if either $a = \top$ or $b = \top$.
WithTop.LinearOrderedAddCommGroup.instLinearOrderedAddCommGroupWithTopOfIsOrderedAddMonoid instance
[LinearOrder α] [IsOrderedAddMonoid α] : LinearOrderedAddCommGroupWithTop (WithTop α)
Full source
instance [LinearOrder α] [IsOrderedAddMonoid α] : LinearOrderedAddCommGroupWithTop (WithTop α) where
  __ := WithTop.linearOrderedAddCommMonoidWithTop
  __ := Option.nontrivial
  sub_eq_add_neg a b := by
    cases a <;> cases b <;> simp [← coe_sub, ← coe_neg, sub_eq_add_neg]
  neg_top := Option.map_none
  zsmul := zsmulRec
  add_neg_cancel := by
    rintro (a | a) ha
    · exact (ha rfl).elim
    · exact (WithTop.coe_add ..).symm.trans (WithTop.coe_eq_coe.2 (add_neg_cancel a))
Linearly Ordered Commutative Additive Group Structure on $\alpha \cup \{\top\}$ for Ordered Monoids
Informal description
For any linearly ordered commutative additive monoid $\alpha$ where addition is order-preserving (i.e., $a \leq b$ implies $a + c \leq b + c$ for all $c$), the type $\alpha \cup \{\top\}$ (denoted `WithTop α`) is a linearly ordered commutative additive group with top element $\top$. Here $\top$ is additively absorbing (i.e., $a + \top = \top + a = \top$ for all $a \in \alpha \cup \{\top\}$), and the negation and subtraction operations are extended from $\alpha$ to $\alpha \cup \{\top\}$ by setting $\neg \top = \top$ and $\top - a = a - \top = \top$ for all $a \in \alpha \cup \{\top\}$.
LinearOrderedAddCommGroupWithTop.add_neg_cancel_of_ne_top theorem
{α : Type*} [LinearOrderedAddCommGroupWithTop α] {a : α} (h : a ≠ ⊤) : a + -a = 0
Full source
lemma add_neg_cancel_of_ne_top {α : Type*} [LinearOrderedAddCommGroupWithTop α]
    {a : α} (h : a ≠ ⊤) :
    a + -a = 0 :=
  LinearOrderedAddCommGroupWithTop.add_neg_cancel a h
Additive Inverse Cancellation in Linearly Ordered Commutative Additive Group with Top Element
Informal description
Let $\alpha$ be a linearly ordered commutative additive group with a top element $\top$. For any element $a \in \alpha$ such that $a \neq \top$, we have $a + (-a) = 0$.
LinearOrderedAddCommGroupWithTop.add_eq_top theorem
: a + b = ⊤ ↔ a = ⊤ ∨ b = ⊤
Full source
@[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
Sum Equals Top iff Either Operand is Top
Informal description
For any elements $a$ and $b$ in a linearly ordered commutative additive group with a top element $\top$, the sum $a + b$ equals $\top$ if and only if either $a = \top$ or $b = \top$.
LinearOrderedAddCommGroupWithTop.top_ne_zero theorem
: (⊤ : α) ≠ 0
Full source
@[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
Non-identity of Top Element: $\top \neq 0$ in Linearly Ordered Commutative Additive Group with Top
Informal description
In a linearly ordered commutative additive group $\alpha$ with a top element $\top$, the top element is not equal to the additive identity, i.e., $\top \neq 0$.
LinearOrderedAddCommGroupWithTop.neg_eq_top theorem
{a : α} : -a = ⊤ ↔ a = ⊤
Full source
@[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]
Negation of Top Element in Ordered Additive Group with Top
Informal description
For any element $a$ in a linearly ordered commutative additive group $\alpha$ with a top element $\top$, the negation of $a$ equals $\top$ if and only if $a$ itself equals $\top$, i.e., $-a = \top \leftrightarrow a = \top$.
LinearOrderedAddCommGroupWithTop.toSubtractionMonoid instance
: SubtractionMonoid α
Full source
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
Linearly Ordered Commutative Additive Group with Top as Subtraction Monoid
Informal description
Every linearly ordered commutative additive group with a top element is a subtraction monoid.
LinearOrderedAddCommGroupWithTop.injective_add_left_of_ne_top theorem
(b : α) (h : b ≠ ⊤) : Function.Injective (fun x ↦ x + b)
Full source
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
Left Addition by Non-Top Element is Injective in Ordered Additive Group with Top
Informal description
For any element $b$ in a linearly ordered commutative additive group with a top element $\top$, if $b \neq \top$, then the function $x \mapsto x + b$ is injective.
LinearOrderedAddCommGroupWithTop.injective_add_right_of_ne_top theorem
(b : α) (h : b ≠ ⊤) : Function.Injective (fun x ↦ b + x)
Full source
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
Right Addition by Non-Top Element is Injective in Ordered Additive Group with Top
Informal description
For any element $b$ in a linearly ordered commutative additive group with a top element $\top$, if $b \neq \top$, then the function $x \mapsto b + x$ is injective.
LinearOrderedAddCommGroupWithTop.strictMono_add_left_of_ne_top theorem
(b : α) (h : b ≠ ⊤) : StrictMono (fun x ↦ x + b)
Full source
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
Strict Monotonicity of Left Addition by Non-Top Element in Ordered Additive Group with Top
Informal description
Let $\alpha$ be a linearly ordered commutative additive group with a top element $\top$. For any element $b \in \alpha$ such that $b \neq \top$, the function $x \mapsto x + b$ is strictly increasing.
LinearOrderedAddCommGroupWithTop.strictMono_add_right_of_ne_top theorem
(b : α) (h : b ≠ ⊤) : StrictMono (fun x ↦ b + x)
Full source
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
Strict Monotonicity of Right Addition by Non-Top Element in Ordered Additive Group with Top
Informal description
Let $\alpha$ be a linearly ordered commutative additive group with a top element $\top$. For any element $b \in \alpha$ such that $b \neq \top$, the function $x \mapsto b + x$ is strictly increasing.
LinearOrderedAddCommGroupWithTop.sub_pos theorem
(a b : α) : 0 < a - b ↔ b < a ∨ b = ⊤
Full source
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
Positivity of Difference in Ordered Additive Group with Top: $0 < a - b \leftrightarrow (b < a \lor b = \top)$
Informal description
Let $\alpha$ be a linearly ordered commutative additive group with a top element $\top$. For any elements $a, b \in \alpha$, the difference $a - b$ is positive (i.e., $0 < a - b$) if and only if either $b < a$ or $b = \top$.