Documentation

Lean.Data.Rat

Rational numbers for implementing decision procedures. We should not confuse them with the Mathlib rational numbers.

Equations
Equations
  • One or more equations did not get rendered due to their size.
Equations
  • One or more equations did not get rendered due to their size.
@[inline]
Equations
  • a.normalize = let n := a.num.natAbs.gcd a.den; if (n == 1) = true then a else { num := a.num.div n, den := a.den / n }
def Lean.mkRat (num : Int) (den : Nat) :
Equations
  • Lean.mkRat num den = if (den == 0) = true then { num := 0, den := 1 } else { num := num, den := den }.normalize
Equations
  • a.isInt = (a.den == 1)
Equations
  • One or more equations did not get rendered due to their size.
Equations
  • a.mul b = let g1 := a.den.gcd b.num.natAbs; let g2 := a.num.natAbs.gcd b.den; { num := a.num.div g2 * b.num.div g1, den := b.den / g2 * (a.den / g1) }
Equations
  • a.inv = if a.num < 0 then { num := -a.den, den := a.num.natAbs } else if (a.num == 0) = true then a else { num := a.den, den := a.num.natAbs }
Equations
  • a.div b = a.mul b.inv
Equations
  • One or more equations did not get rendered due to their size.
Equations
  • One or more equations did not get rendered due to their size.
Equations
  • a.neg = { num := -a.num, den := a.den }
Equations
  • a.floor = if (a.den == 1) = true then a.num else let r := a.num.mod a.den; if a.num < 0 then r - 1 else r
Equations
  • a.ceil = if (a.den == 1) = true then a.num else let r := a.num.mod a.den; if a.num > 0 then r + 1 else r
Equations
Equations
Equations
Equations
Equations
Equations
  • Lean.Rat.instOfNat = { ofNat := { num := n, den := 1 } }
Equations