equal
deleted
inserted
replaced
18 val pow: int -> int -> int (* exponent -> base -> result *) |
18 val pow: int -> int -> int (* exponent -> base -> result *) |
19 val gcd: int -> int -> int |
19 val gcd: int -> int -> int |
20 val lcm: int -> int -> int |
20 val lcm: int -> int -> int |
21 val gcds: int list -> int |
21 val gcds: int list -> int |
22 val lcms: int list -> int |
22 val lcms: int list -> int |
|
23 val radicify: int -> int -> int -> int list (* base -> number of positions -> value -> coefficients *) |
|
24 val eval_radix: int -> int list -> int (* base -> coefficients -> value *) |
23 end; |
25 end; |
24 |
26 |
25 structure Integer : INTEGER = |
27 structure Integer : INTEGER = |
26 struct |
28 struct |
27 |
29 |
62 | gcds (x :: xs) = fold gcd xs x; |
64 | gcds (x :: xs) = fold gcd xs x; |
63 |
65 |
64 fun lcms [] = 1 |
66 fun lcms [] = 1 |
65 | lcms (x :: xs) = abs (Library.foldl PolyML.IntInf.lcm (x, xs)); |
67 | lcms (x :: xs) = abs (Library.foldl PolyML.IntInf.lcm (x, xs)); |
66 |
68 |
|
69 fun radicify base len k = |
|
70 let |
|
71 val _ = if base < 2 |
|
72 then error ("Bad radix base: " ^ string_of_int base) else (); |
|
73 fun shift i = swap (div_mod i base); |
|
74 in funpow_yield len shift k |> fst end; |
|
75 |
|
76 fun eval_radix base ks = |
|
77 fold_rev (fn k => fn i => k + i * base) ks 0; |
|
78 |
67 end; |
79 end; |
68 |
80 |
69 (*slightly faster than Poly/ML 5.7.1 library implementation, notably on 32bit multicore*) |
81 (*slightly faster than Poly/ML 5.7.1 library implementation, notably on 32bit multicore*) |
70 structure IntInf = |
82 structure IntInf = |
71 struct |
83 struct |