Equations
- Lean.instInhabitedRat = { default := { num := default, den := default } }
@[inline]
Equations
- Lean.Rat.normalize a = let n := Nat.gcd (Int.natAbs a.num) a.den; if (n == 1) = true then a else { num := a.num / Int.ofNat n, den := a.den / n }
Equations
- Lean.mkRat num den = if (den == 0) = true then { num := 0, den := 1 } else Lean.Rat.normalize { num := num, den := den }
Equations
- Lean.Rat.mul a b = let g1 := Nat.gcd a.den (Int.natAbs b.num); let g2 := Nat.gcd (Int.natAbs a.num) b.den; { num := a.num / Int.ofNat g2 * (b.num / Int.ofNat g1), den := b.den / g2 * (a.den / g1) }
Equations
- Lean.Rat.inv a = if a.num < 0 then { num := -Int.ofNat a.den, den := Int.natAbs a.num } else if (a.num == 0) = true then a else { num := Int.ofNat a.den, den := Int.natAbs a.num }
Equations
- Lean.Rat.div a b = Lean.Rat.mul a (Lean.Rat.inv b)
Equations
- Lean.Rat.add a b = let g := Nat.gcd a.den b.den; if (g == 1) = true then { num := a.num * Int.ofNat b.den + b.num * Int.ofNat a.den, den := a.den * b.den } else let den := a.den / g * b.den; let num := Int.ofNat b.den / Int.ofNat g * a.num + Int.ofNat a.den / Int.ofNat g * b.num; let g1 := Nat.gcd (Int.natAbs num) g; if (g1 == 1) = true then { num := num, den := den } else { num := num / Int.ofNat g1, den := den / g1 }
Equations
- Lean.Rat.sub a b = let g := Nat.gcd a.den b.den; if (g == 1) = true then { num := a.num * Int.ofNat b.den - b.num * Int.ofNat a.den, den := a.den * b.den } else let den := a.den / g * b.den; let num := Int.ofNat b.den / Int.ofNat g * a.num - Int.ofNat a.den / Int.ofNat g * b.num; let g1 := Nat.gcd (Int.natAbs num) g; if (g1 == 1) = true then { num := num, den := den } else { num := num / Int.ofNat g1, den := den / g1 }
Equations
- Lean.Rat.neg a = { num := -a.num, den := a.den }
Equations
- Lean.Rat.instLTRat = { lt := fun a b => Lean.Rat.lt a b = true }
Equations
Equations
- Lean.Rat.instLERat = { le := fun a b => ¬b < a }
Equations
Equations
- Lean.Rat.instAddRat = { add := Lean.Rat.add }
Equations
- Lean.Rat.instSubRat = { sub := Lean.Rat.sub }
Equations
- Lean.Rat.instNegRat = { neg := Lean.Rat.neg }
Equations
- Lean.Rat.instMulRat = { mul := Lean.Rat.mul }
Equations
- Lean.Rat.instDivRat = { div := fun a b => a * Lean.Rat.inv b }
Equations
- Lean.Rat.instCoeIntRat = { coe := fun num => { num := num, den := 1 } }