Absolute value

Uses Real numbers

The absolute value of any real number is a non-negative real number:
 abs(ℝ) : ℝ.nn

Special cases for the rational numbers and the integers:
 abs(ℚ) : ℚ.nn
 abs(ℤ) : ℕ

Special cases for the non-zero numbers are also useful:
 abs(ℝ.nz) : ℝ.p
 abs(ℚ.nz) : ℚ.p
 abs(ℤ.nz) : ℕ.nz

Simplification rules

The absolute value of a non-negative number is the number itself:
 abs(x:ℝ.nn) ⇒ x
 abs(x:ℝ) ⇒ x | x ≥ 0

For a negative number, it is the negative:
 abs(x:ℝ) ⇒ -(x) | x < 0

Examples

Given:
 example aPositiveNumber : ℝ.p
 example aNegativeNumber : ℝ with example aNegativeNumber < 0 ⇒ ⊤
 example anUnknownNumber : ℝ

We find:
 example abs(aPositiveNumber) ⇒ aPositiveNumber
 example abs(aNegativeNumber) ⇒ -(aNegativeNumber)
 example abs(anUnknownNumber) ⇒ abs(anUnknownNumber)

For literals:
 example abs(2) ⇒ 2
 example abs(-2/3) ⇒ 2/3