68 val mk_Suc: term -> term |
69 val mk_Suc: term -> term |
69 val dest_Suc: term -> term |
70 val dest_Suc: term -> term |
70 val mk_nat: int -> term |
71 val mk_nat: int -> term |
71 val dest_nat: term -> int |
72 val dest_nat: term -> int |
72 val intT: typ |
73 val intT: typ |
73 val mk_int: int -> term |
74 val mk_int: IntInf.int -> term |
74 val realT: typ |
75 val realT: typ |
75 val bitT: typ |
76 val bitT: typ |
76 val B0_const: term |
77 val B0_const: term |
77 val B1_const: term |
78 val B1_const: term |
78 val binT: typ |
79 val binT: typ |
79 val pls_const: term |
80 val pls_const: term |
80 val min_const: term |
81 val min_const: term |
81 val bit_const: term |
82 val bit_const: term |
82 val number_of_const: typ -> term |
83 val number_of_const: typ -> term |
83 val int_of: int list -> int |
84 val int_of: int list -> IntInf.int |
84 val intinf_of: int list -> IntInf.int |
85 val dest_binum: term -> IntInf.int |
85 val dest_binum: term -> int |
86 val mk_bin: IntInf.int -> term |
86 val mk_bin: int -> term |
|
87 val mk_bin_from_intinf: IntInf.int -> term |
|
88 val bin_of : term -> int list |
87 val bin_of : term -> int list |
89 val mk_list: ('a -> term) -> typ -> 'a list -> term |
88 val mk_list: ('a -> term) -> typ -> 'a list -> term |
90 val dest_list: term -> term list |
89 val dest_list: term -> term list |
91 end; |
90 end; |
92 |
91 |
309 and min_const = Const ("Numeral.Min", binT) |
308 and min_const = Const ("Numeral.Min", binT) |
310 and bit_const = Const ("Numeral.Bit", [binT, bitT] ---> binT); |
309 and bit_const = Const ("Numeral.Bit", [binT, bitT] ---> binT); |
311 |
310 |
312 fun number_of_const T = Const ("Numeral.number_of", binT --> T); |
311 fun number_of_const T = Const ("Numeral.number_of", binT --> T); |
313 |
312 |
314 |
313 fun int_of [] = 0 |
315 fun int_of [] = 0 |
314 | int_of (b :: bs) = IntInf.fromInt b + (2 * int_of bs); |
316 | int_of (b :: bs) = b + 2 * int_of bs; |
|
317 |
|
318 fun intinf_of [] = IntInf.fromInt 0 |
|
319 | intinf_of (b :: bs) = IntInf.+ (IntInf.fromInt b, IntInf.*(IntInf.fromInt 2, intinf_of bs)); |
|
320 |
315 |
321 (*When called from a print translation, the Numeral qualifier will probably have |
316 (*When called from a print translation, the Numeral qualifier will probably have |
322 been removed from Bit, bin.B0, etc.*) |
317 been removed from Bit, bin.B0, etc.*) |
323 fun dest_bit (Const ("Numeral.bit.B0", _)) = 0 |
318 fun dest_bit (Const ("Numeral.bit.B0", _)) = 0 |
324 | dest_bit (Const ("Numeral.bit.B1", _)) = 1 |
319 | dest_bit (Const ("Numeral.bit.B1", _)) = 1 |
336 |
331 |
337 fun mk_bit 0 = B0_const |
332 fun mk_bit 0 = B0_const |
338 | mk_bit 1 = B1_const |
333 | mk_bit 1 = B1_const |
339 | mk_bit _ = sys_error "mk_bit"; |
334 | mk_bit _ = sys_error "mk_bit"; |
340 |
335 |
341 fun mk_bin_from_intinf n = |
336 fun mk_bin n = |
342 let |
337 let |
343 val zero = IntInf.fromInt 0 |
338 fun mk_bit n = if n = 0 then B0_const else B1_const |
344 val minus_one = IntInf.fromInt ~1 |
|
345 val two = IntInf.fromInt 2 |
|
346 |
|
347 fun mk_bit n = if n = zero then B0_const else B1_const |
|
348 |
339 |
349 fun bin_of n = |
340 fun bin_of n = |
350 if n = zero then pls_const |
341 if n = 0 then pls_const |
351 else if n = minus_one then min_const |
342 else if n = ~1 then min_const |
352 else |
343 else |
353 let |
344 let |
354 (*val (q,r) = IntInf.divMod (n, two): doesn't work in SML 10.0.7, but in newer versions!*) |
345 (*val (q,r) = IntInf.divMod (n, 2): doesn't work in SML 10.0.7, but in newer versions! FIXME: put this back after new SML released!*) |
355 val q = IntInf.div (n, two) |
346 val q = IntInf.div (n, 2) |
356 val r = IntInf.mod (n, two) |
347 val r = IntInf.mod (n, 2) |
357 in |
348 in |
358 bit_const $ bin_of q $ mk_bit r |
349 bit_const $ bin_of q $ mk_bit r |
359 end |
350 end |
360 in |
351 in |
361 bin_of n |
352 bin_of n |
362 end |
353 end |
363 |
354 |
364 val mk_bin = mk_bin_from_intinf o IntInf.fromInt; |
|
365 |
|
366 |
355 |
367 (* int *) |
356 (* int *) |
368 |
357 |
369 val intT = Type ("IntDef.int", []); |
358 val intT = Type ("IntDef.int", []); |
370 |
359 |