85 val min_const: term |
85 val min_const: term |
86 val bit_const: term |
86 val bit_const: term |
87 val mk_numeral: integer -> term |
87 val mk_numeral: integer -> term |
88 val dest_numeral: term -> integer |
88 val dest_numeral: term -> integer |
89 val number_of_const: typ -> term |
89 val number_of_const: typ -> term |
90 val add_numerals_of: term -> (term * typ) list -> (term * typ) list |
90 val add_numerals: term -> (term * typ) list -> (term * typ) list |
91 val mk_number: typ -> integer -> term |
91 val mk_number: typ -> integer -> term |
92 val dest_number: term -> typ * integer |
92 val dest_number: term -> typ * integer |
93 val realT: typ |
93 val realT: typ |
94 val nibbleT: typ |
94 val nibbleT: typ |
95 val mk_nibble: int -> term |
95 val mk_nibble: int -> term |
349 2 *% dest_numeral bs +% Integer.int (dest_bit b) |
349 2 *% dest_numeral bs +% Integer.int (dest_bit b) |
350 | dest_numeral t = raise TERM ("dest_numeral", [t]); |
350 | dest_numeral t = raise TERM ("dest_numeral", [t]); |
351 |
351 |
352 fun number_of_const T = Const ("Numeral.number_class.number_of", intT --> T); |
352 fun number_of_const T = Const ("Numeral.number_class.number_of", intT --> T); |
353 |
353 |
354 fun add_numerals_of (Const _) = |
354 fun add_numerals (Const ("Numeral.number_class.number_of", Type (_, [_, T])) $ t) = cons (t, T) |
355 I |
355 | add_numerals (t $ u) = add_numerals t #> add_numerals u |
356 | add_numerals_of (Var _) = |
356 | add_numerals (Abs (_, _, t)) = add_numerals t |
357 I |
357 | add_numerals _ = I; |
358 | add_numerals_of (Free _) = |
|
359 I |
|
360 | add_numerals_of (Bound _) = |
|
361 I |
|
362 | add_numerals_of (Abs (_, _, t)) = |
|
363 add_numerals_of t |
|
364 | add_numerals_of (t as _ $ _) = |
|
365 case strip_comb t |
|
366 of (Const ("Numeral.number_class.number_of", |
|
367 Type (_, [_, T])), ts) => fold (cons o rpair T) ts |
|
368 | (t', ts) => add_numerals_of t' #> fold add_numerals_of ts; |
|
369 |
358 |
370 fun mk_number T 0 = Const ("HOL.zero_class.zero", T) |
359 fun mk_number T 0 = Const ("HOL.zero_class.zero", T) |
371 | mk_number T 1 = Const ("HOL.one_class.one", T) |
360 | mk_number T 1 = Const ("HOL.one_class.one", T) |
372 | mk_number T i = number_of_const T $ mk_numeral i; |
361 | mk_number T i = number_of_const T $ mk_numeral i; |
373 |
362 |