The absolute value of real numbers

Content created by Fredrik Bakke and Louis Wasserman.

Created on 2025-03-26.
Last modified on 2025-03-26.

{-# OPTIONS --lossy-unification #-}

module real-numbers.absolute-value-real-numbers where
Imports
open import elementary-number-theory.rational-numbers

open import foundation.action-on-identifications-functions
open import foundation.dependent-pair-types
open import foundation.disjunction
open import foundation.empty-types
open import foundation.function-types
open import foundation.identity-types
open import foundation.transport-along-identifications
open import foundation.universe-levels

open import real-numbers.dedekind-real-numbers
open import real-numbers.inequality-real-numbers
open import real-numbers.maximum-real-numbers
open import real-numbers.negation-real-numbers
open import real-numbers.nonnegative-real-numbers

Idea

The absolute value of a real number is the maximum of it and its negation.

abs-ℝ : {l : Level}   l   l
abs-ℝ x = binary-max-ℝ x (neg-ℝ x)

Properties

The absolute value of a real number is nonnegative

abstract
  is-nonnegative-abs-ℝ : {l : Level}  (x :  l)  is-nonnegative-ℝ (abs-ℝ x)
  is-nonnegative-abs-ℝ x q q<0 =
    elim-disjunction
      ( lower-cut-ℝ (abs-ℝ x) q)
      ( id)
      ( λ (x<0 , 0<x)  ex-falso (is-disjoint-cut-ℝ x zero-ℚ (0<x , x<0)))
      ( is-located-lower-upper-cut-ℝ (abs-ℝ x) q zero-ℚ q<0)

The absolute value of the negation of a real number is its absolute value

abstract
  abs-neg-ℝ : {l : Level}  (x :  l)  abs-ℝ (neg-ℝ x)  abs-ℝ x
  abs-neg-ℝ x =
    ap (binary-max-ℝ (neg-ℝ x)) (neg-neg-ℝ x)  commutative-binary-max-ℝ _ _

x is between -|x| and |x|

module _
  {l : Level} (x :  l)
  where

  abstract
    leq-abs-ℝ : leq-ℝ x (abs-ℝ x)
    leq-abs-ℝ = leq-left-binary-max-ℝ x (neg-ℝ x)

    neg-leq-abs-ℝ : leq-ℝ (neg-ℝ x) (abs-ℝ x)
    neg-leq-abs-ℝ = leq-right-binary-max-ℝ x (neg-ℝ x)

    leq-neg-abs-ℝ : leq-ℝ (neg-ℝ (abs-ℝ x)) x
    leq-neg-abs-ℝ =
      tr
        ( leq-ℝ (neg-ℝ (abs-ℝ x)))
        ( neg-neg-ℝ x)
        ( neg-leq-ℝ (neg-ℝ x) (abs-ℝ x) neg-leq-abs-ℝ)

    neg-leq-neg-abs-ℝ : leq-ℝ (neg-ℝ (abs-ℝ x)) (neg-ℝ x)
    neg-leq-neg-abs-ℝ = neg-leq-ℝ x (abs-ℝ x) leq-abs-ℝ

Recent changes