Real Numbers

General postulates for real numbers. These define the reals as a mathematical structure, independent of any specific application.

module plumbing.Reals where

open import Relation.Binary.PropositionalEquality using (_≡_; refl; sym; trans)

The Real Numbers ℝ

postulate
   : Set

Ordering

postulate
  _≤ℝ_ :     Set
  _<ℝ_ :     Set
  _≥ℝ_ :     Set

  ≤ℝ-refl :  {x : }  x ≤ℝ x
  ≤ℝ-trans :  {x y z : }  x ≤ℝ y  y ≤ℝ z  x ≤ℝ z
  ≤ℝ-antisym :  {x y : }  x ≤ℝ y  y ≤ℝ x  x  y

infix 4 _≤ℝ_ _<ℝ_ _≥ℝ_

Arithmetic

postulate
  0ℝ : 
  1ℝ : 
  _+_ :     
  _-_ :     
  _*_ :     
  -_ :     -- negation

infixl 6 _+_ _-_
infixl 7 _*_
infix 8 -_

Field Properties

We postulate the minimal set and derive the rest.

postulate
  -- Addition (core)
  +-identityˡ :  {x : }  0ℝ + x  x
  +-assoc :  {x y z : }  (x + y) + z  x + (y + z)
  +-comm :  {x y : }  x + y  y + x
  +-inverseˡ :  {x : }  (- x) + x  0ℝ

  -- Multiplication (core)
  *-identityˡ :  {x : }  1ℝ * x  x
  *-assoc :  {x y z : }  (x * y) * z  x * (y * z)
  *-comm :  {x y : }  x * y  y * x

  -- Distributivity
  *-distribˡ :  {x y z : }  x * (y + z)  (x * y) + (x * z)

  -- Subtraction definition
  x-y≡x+-y :  {x y : }  x - y  x + (- y)

-- Derived from commutativity
+-identityʳ :  {x : }  x + 0ℝ  x
+-identityʳ = trans +-comm +-identityˡ

+-inverseʳ :  {x : }  x + (- x)  0ℝ
+-inverseʳ = trans +-comm +-inverseˡ

*-identityʳ :  {x : }  x * 1ℝ  x
*-identityʳ = trans *-comm *-identityˡ

*-distribʳ :  {x y z : }  (x + y) * z  (x * z) + (y * z)
*-distribʳ {x} {y} {z} = trans *-comm (trans *-distribˡ (trans (cong₂ _+_ *-comm *-comm) refl))
  where
    cong₂ :  {A B C : Set} (f : A  B  C) {x₁ x₂ : A} {y₁ y₂ : B}
           x₁  x₂  y₁  y₂  f x₁ y₁  f x₂ y₂
    cong₂ f refl refl = refl

Ordered Field Properties

postulate
  +-mono :  {x₁ x₂ y₁ y₂ : }  x₁ ≤ℝ y₁  x₂ ≤ℝ y₂  (x₁ + x₂) ≤ℝ (y₁ + y₂)
  *-mono-pos :  {x y z : }  0ℝ ≤ℝ z  x ≤ℝ y  (x * z) ≤ℝ (y * z)

Absolute Value

postulate
  ∣_∣ :   

  ∣x∣≥0 :  {x : }  0ℝ ≤ℝ  x 
  ∣0∣≡0 :  0ℝ   0ℝ
  ∣-x∣≡∣x∣ :  {x : }   - x    x 
  ∣x*y∣≡∣x∣*∣y∣ :  {x y : }   x * y    x  *  y 
  ∣x+y∣≤∣x∣+∣y∣ :  {x y : }   x + y  ≤ℝ ( x  +  y )  -- triangle inequality
  ∣x∣≡0→x≡0 :  {x : }   x   0ℝ  x  0ℝ

Extended Nonnegative Reals [0, ∞]

For metric spaces and Cost, we need [0, ∞] = ℝ≥0 ∪ {∞}.

postulate
  [0,∞] : Set

  -- Embedding from ℝ (partial - only for nonnegative)
  ιℝ :   [0,∞]

  -- Distinguished elements
  0∞ : [0,∞]
   : [0,∞]

  -- Ordering (reversed: ≥ for Cost)
  _≥_ : [0,∞]  [0,∞]  Set

  -- Addition
  _+ℝ_ : [0,∞]  [0,∞]  [0,∞]

infixl 6 _+ℝ_
infix 4 _≥_

[0, ∞] Properties

postulate
  -- Ordering
  ≥-refl :  {x : [0,∞]}  x  x
  ≥-trans :  {x y z : [0,∞]}  x  y  y  z  x  z
  ∞-greatest :  {x : [0,∞]}    x
  0-least :  {x : [0,∞]}  x  0∞

  -- Addition (core)
  +ℝ-identityˡ :  {x : [0,∞]}  0∞ +ℝ x  x
  +ℝ-assoc :  {x y z : [0,∞]}  (x +ℝ y) +ℝ z  x +ℝ (y +ℝ z)
  +ℝ-comm :  {x y : [0,∞]}  x +ℝ y  y +ℝ x
  +ℝ-mono :  {x₁ x₂ y₁ y₂ : [0,∞]}  x₁  y₁  x₂  y₂  (x₁ +ℝ x₂)  (y₁ +ℝ y₂)
  +ℝ-∞ˡ :  {x : [0,∞]}   +ℝ x  

-- Derived from commutativity
+ℝ-identityʳ :  {x : [0,∞]}  x +ℝ 0∞  x
+ℝ-identityʳ = trans +ℝ-comm +ℝ-identityˡ

+ℝ-∞ʳ :  {x : [0,∞]}  x +ℝ   
+ℝ-∞ʳ = trans +ℝ-comm +ℝ-∞ˡ

Metric Space Adaptations

Properties connecting ℝ to metric space concepts via distance.

postulate
  -- Distance function (|x - y| lifted to [0,∞])
  dist :     [0,∞]

  -- Self-distance is zero
  dist-refl :  {x : }  dist x x  0∞

  -- Symmetry
  dist-sym :  {x y : }  dist x y  dist y x

  -- Triangle inequality for distances
  dist-triangle :  {x y z : }  (dist x y +ℝ dist y z)  dist x z

  -- Separation
  dist-zero→eq :  {x y : }  dist x y  0∞  x  y