src/Pure/General/integer.ML
changeset 77768 65008644d394
parent 73020 b51515722274
child 78171 412a24a4c751
equal deleted inserted replaced
77766:c6c4069a86f3 77768:65008644d394
     4 Auxiliary operations on (unbounded) integers.
     4 Auxiliary operations on (unbounded) integers.
     5 *)
     5 *)
     6 
     6 
     7 signature INTEGER =
     7 signature INTEGER =
     8 sig
     8 sig
       
     9   val build: (int -> int) -> int
     9   val min: int -> int -> int
    10   val min: int -> int -> int
    10   val max: int -> int -> int
    11   val max: int -> int -> int
    11   val add: int -> int -> int
    12   val add: int -> int -> int
    12   val mult: int -> int -> int
    13   val mult: int -> int -> int
    13   val sum: int list -> int
    14   val sum: int list -> int
    26   val eval_radix: int -> int list -> int (* base -> coefficients -> value *)
    27   val eval_radix: int -> int list -> int (* base -> coefficients -> value *)
    27 end;
    28 end;
    28 
    29 
    29 structure Integer : INTEGER =
    30 structure Integer : INTEGER =
    30 struct
    31 struct
       
    32 
       
    33 fun build (f: int -> int) = f 0;
    31 
    34 
    32 fun min x y = Int.min (x, y);
    35 fun min x y = Int.min (x, y);
    33 fun max x y = Int.max (x, y);
    36 fun max x y = Int.max (x, y);
    34 
    37 
    35 fun add x y = x + y;
    38 fun add x y = x + y;
    63     val _ = if base < 2
    66     val _ = if base < 2
    64       then error ("Bad radix base: " ^ string_of_int base) else ();
    67       then error ("Bad radix base: " ^ string_of_int base) else ();
    65     fun shift i = swap (div_mod i base);
    68     fun shift i = swap (div_mod i base);
    66   in funpow_yield len shift k |> fst end;
    69   in funpow_yield len shift k |> fst end;
    67 
    70 
    68 fun eval_radix base ks =
    71 fun eval_radix base =
    69   fold_rev (fn k => fn i => k + i * base) ks 0;
    72   build o fold_rev (fn k => fn i => k + i * base);
    70 
    73 
    71 end;
    74 end;