Inequality on the integers

Content created by Fredrik Bakke, Egbert Rijke, Jonathan Prieto-Cubides, malarbol, Bryan Lu, Julian KG, Victor Blanchi, fernabnor and louismntnu.

Created on 2022-01-26.
Last modified on 2024-04-09.

module elementary-number-theory.inequality-integers where
open import elementary-number-theory.addition-integers
open import elementary-number-theory.addition-positive-and-negative-integers
open import elementary-number-theory.difference-integers
open import elementary-number-theory.inequality-natural-numbers
open import elementary-number-theory.integers
open import elementary-number-theory.natural-numbers
open import elementary-number-theory.negative-integers
open import elementary-number-theory.nonnegative-integers
open import elementary-number-theory.nonpositive-integers
open import elementary-number-theory.positive-and-negative-integers
open import elementary-number-theory.positive-integers

open import foundation.action-on-identifications-functions
open import foundation.coproduct-types
open import foundation.decidable-propositions
open import foundation.dependent-pair-types
open import foundation.function-types
open import foundation.functoriality-coproduct-types
open import foundation.identity-types
open import foundation.negated-equality
open import foundation.negation
open import foundation.propositions
open import foundation.transport-along-identifications
open import foundation.unit-type
open import foundation.universe-levels

open import order-theory.posets
open import order-theory.preorders


An integer x is less than or equal to the integer y if the difference y - x is nonnegative. This relation defines the standard ordering on the integers.


Inequality on the integers

leq-ℤ-Prop :     Prop lzero
leq-ℤ-Prop x y = subtype-nonnegative-ℤ (y -ℤ x)

leq-ℤ :     UU lzero
leq-ℤ x y = type-Prop (leq-ℤ-Prop x y)

is-prop-leq-ℤ : (x y : )  is-prop (leq-ℤ x y)
is-prop-leq-ℤ x y = is-prop-type-Prop (leq-ℤ-Prop x y)

infix 30 _≤-ℤ_
_≤-ℤ_ = leq-ℤ


Inequality on the integers is reflexive, antisymmetric and transitive

refl-leq-ℤ : (k : )  leq-ℤ k k
refl-leq-ℤ k = tr is-nonnegative-ℤ (inv (right-inverse-law-add-ℤ k)) star

antisymmetric-leq-ℤ : {x y : }  leq-ℤ x y  leq-ℤ y x  x  y
antisymmetric-leq-ℤ {x} {y} H K =
    ( is-zero-is-nonnegative-neg-is-nonnegative-ℤ K
      ( is-nonnegative-eq-ℤ (inv (distributive-neg-diff-ℤ x y)) H))

transitive-leq-ℤ : (k l m : )  leq-ℤ l m  leq-ℤ k l  leq-ℤ k m
transitive-leq-ℤ k l m H K =
    ( triangle-diff-ℤ m l k)
    ( is-nonnegative-add-ℤ H K)

Inequality on the integers is decidable

is-decidable-leq-ℤ : (x y : )  (leq-ℤ x y) + ¬ (leq-ℤ x y)
is-decidable-leq-ℤ x y = is-decidable-is-nonnegative-ℤ (y -ℤ x)

leq-ℤ-Decidable-Prop : (x y : )  Decidable-Prop lzero
leq-ℤ-Decidable-Prop x y =
  ( leq-ℤ x y ,
    is-prop-leq-ℤ x y ,
    is-decidable-leq-ℤ x y)

Inequality on the integers is linear

linear-leq-ℤ : (x y : )  (leq-ℤ x y) + (leq-ℤ y x)
linear-leq-ℤ x y =
    ( λ H 
        ( is-positive-eq-ℤ
          ( distributive-neg-diff-ℤ x y)
          ( is-positive-neg-is-negative-ℤ H)))
    ( id)
    ( decide-is-negative-is-nonnegative-ℤ)

An integer is lesser than its successor

succ-leq-ℤ : (k : )  leq-ℤ k (succ-ℤ k)
succ-leq-ℤ k =
    ( inv
      ( ( left-successor-law-add-ℤ k (neg-ℤ k)) 
        ( ap succ-ℤ (right-inverse-law-add-ℤ k))))
    ( star)

leq-ℤ-succ-leq-ℤ : (k l : )  leq-ℤ k l  leq-ℤ k (succ-ℤ l)
leq-ℤ-succ-leq-ℤ k l = transitive-leq-ℤ k l (succ-ℤ l) (succ-leq-ℤ l)

Chaining rules for equality and inequality

concatenate-eq-leq-eq-ℤ :
  {x' x y y' : }  x'  x  leq-ℤ x y  y  y'  leq-ℤ x' y'
concatenate-eq-leq-eq-ℤ refl H refl = H

concatenate-leq-eq-ℤ :
  (x : ) {y y' : }  leq-ℤ x y  y  y'  leq-ℤ x y'
concatenate-leq-eq-ℤ x H refl = H

concatenate-eq-leq-ℤ :
  {x x' : } (y : )  x'  x  leq-ℤ x y  leq-ℤ x' y
concatenate-eq-leq-ℤ y refl H = H

Addition on the integers preserves inequality

preserves-leq-left-add-ℤ :
  (z x y : )  leq-ℤ x y  leq-ℤ (x +ℤ z) (y +ℤ z)
preserves-leq-left-add-ℤ z x y =
  is-nonnegative-eq-ℤ (inv (right-translation-diff-ℤ y x z))

preserves-leq-right-add-ℤ :
  (z x y : )  leq-ℤ x y  leq-ℤ (z +ℤ x) (z +ℤ y)
preserves-leq-right-add-ℤ z x y =
  is-nonnegative-eq-ℤ (inv (left-translation-diff-ℤ y x z))

preserves-leq-add-ℤ :
  {a b c d : }  leq-ℤ a b  leq-ℤ c d  leq-ℤ (a +ℤ c) (b +ℤ d)
preserves-leq-add-ℤ {a} {b} {c} {d} H K =
    ( a +ℤ c)
    ( b +ℤ c)
    ( b +ℤ d)
    ( preserves-leq-right-add-ℤ b c d K)
    ( preserves-leq-left-add-ℤ c a b H)

Addition on the integers reflects inequality

reflects-leq-left-add-ℤ :
  (z x y : )  leq-ℤ (x +ℤ z) (y +ℤ z)  leq-ℤ x y
reflects-leq-left-add-ℤ z x y =
  is-nonnegative-eq-ℤ (right-translation-diff-ℤ y x z)

reflects-leq-right-add-ℤ :
  (z x y : )  leq-ℤ (z +ℤ x) (z +ℤ y)  leq-ℤ x y
reflects-leq-right-add-ℤ z x y =
  is-nonnegative-eq-ℤ (left-translation-diff-ℤ y x z)

The inclusion of ℕ into ℤ preserves inequality

leq-int-ℕ : (x y : )  leq-ℕ x y  leq-ℤ (int-ℕ x) (int-ℕ y)
leq-int-ℕ zero-ℕ y H =
    ( is-nonnegative-ℤ)
    ( inv (right-unit-law-add-ℤ (int-ℕ y)))
    ( is-nonnegative-int-ℕ y)
leq-int-ℕ (succ-ℕ x) (succ-ℕ y) H = tr (is-nonnegative-ℤ)
  ( inv (diff-succ-ℤ (int-ℕ y) (int-ℕ x)) 
    ( ap (_-ℤ (succ-ℤ (int-ℕ x))) (succ-int-ℕ y) 
      ap ((int-ℕ (succ-ℕ y)) -ℤ_) (succ-int-ℕ x)))
  ( leq-int-ℕ x y H)

The partially ordered set of integers ordered by inequality

ℤ-Preorder : Preorder lzero lzero
ℤ-Preorder =
  ( , leq-ℤ-Prop , refl-leq-ℤ , transitive-leq-ℤ)

ℤ-Poset : Poset lzero lzero
ℤ-Poset = (ℤ-Preorder , λ x y  antisymmetric-leq-ℤ)

An integer x is nonnegative if and only if 0 ≤ x

module _
  (x : )

    leq-zero-is-nonnegative-ℤ : is-nonnegative-ℤ x  leq-ℤ zero-ℤ x
    leq-zero-is-nonnegative-ℤ =
      is-nonnegative-eq-ℤ (inv (right-zero-law-diff-ℤ x))

    is-nonnegative-leq-zero-ℤ : leq-ℤ zero-ℤ x  is-nonnegative-ℤ x
    is-nonnegative-leq-zero-ℤ =
      is-nonnegative-eq-ℤ (right-zero-law-diff-ℤ x)

An integer greater than or equal to a nonnegative integer is nonnegative

module _
  (x y : ) (I : leq-ℤ x y)

    is-nonnegative-leq-nonnegative-ℤ : is-nonnegative-ℤ x  is-nonnegative-ℤ y
    is-nonnegative-leq-nonnegative-ℤ H =
      is-nonnegative-leq-zero-ℤ y
        ( transitive-leq-ℤ
          ( zero-ℤ)
          ( x)
          ( y)
          ( I)
          ( leq-zero-is-nonnegative-ℤ x H))

An integer x is nonpositive if and only if x ≤ 0

module _
  (x : )

    leq-zero-is-nonpositive-ℤ : is-nonpositive-ℤ x  leq-ℤ x zero-ℤ
    leq-zero-is-nonpositive-ℤ = is-nonnegative-neg-is-nonpositive-ℤ

    is-nonpositive-leq-zero-ℤ : leq-ℤ x zero-ℤ  is-nonpositive-ℤ x
    is-nonpositive-leq-zero-ℤ H =
        ( neg-neg-ℤ x)
        ( is-nonpositive-neg-is-nonnegative-ℤ H)

An integer less than or equal to a nonpositive integer is nonpositive

module _
  (x y : ) (I : leq-ℤ x y)

    is-nonpositive-leq-nonpositive-ℤ : is-nonpositive-ℤ y  is-nonpositive-ℤ x
    is-nonpositive-leq-nonpositive-ℤ H =
      is-nonpositive-leq-zero-ℤ x
        ( transitive-leq-ℤ
          ( x)
          ( y)
          ( zero-ℤ)
          ( leq-zero-is-nonpositive-ℤ y H)
          ( I))

See also

Recent changes