export { import "int.lt"; import "euclidean.lt"; /* Implementation of Rational Numbers */ let ratio-sign = λ{ p: machine.Int64 ~ machine.Word; q: machine.Int64 ~ machine.Word; } ↦ bool-xor (int-sign p) (int-sign q); let ratio-scale = λ{ { p: machine.Int64~machine.Word; q: machine.Int64~machine.Word; } : ℚ ~ ; n : machine.Int64 ~machine.Word; } ↦ { i* q n; i* p n; }; let ratio-normalize = λ{ p: machine.Int64 ~ machine.Word; q: machine.Int64 ~ machine.Word; } : ℚ ~ ↦ { let s = gcd p q; i/ q s; i/ p s; }; let ratio-add = λ{ { ap:machine.Int64~machine.Word; aq:machine.Int64~machine.Word; }: ℚ ~ ; { bp:machine.Int64~machine.Word; bq:machine.Int64~machine.Word; }: ℚ ~ ; } ↦ { let l = lcm aq bq; let a = i/ l aq; let b = i/ l bq; i* aq a; i+ (i* ap a) (i* bp b); }; let ratio-mul = λ{ { ap:machine.Int64~machine.Word; aq:machine.Int64~machine.Word; }: ℚ ~ ; { bp:machine.Int64~machine.Word; bq:machine.Int64~machine.Word; }: ℚ ~ ; } ↦ ratio-normalize (i* ap bp) (i* aq bq); /* let fmt-ratio = λ{ p:ℤ; q:ℤ; }: ℚ~ ↦ { fmt-int q;':';fmt-int p; }; */ }