54 let val (m, _) = Term.dest_Const t |
54 let val (m, _) = Term.dest_Const t |
55 in SMT_Builtin.add_builtin_fun smtlibC (Term.dest_Const t, K (f m n)) end |
55 in SMT_Builtin.add_builtin_fun smtlibC (Term.dest_Const t, K (f m n)) end |
56 |
56 |
57 val mk_nat = HOLogic.mk_number \<^typ>\<open>nat\<close> |
57 val mk_nat = HOLogic.mk_number \<^typ>\<open>nat\<close> |
58 |
58 |
|
59 fun mk_shift c [u, t] = Const c $ mk_nat (snd (HOLogic.dest_number u)) $ t |
|
60 | mk_shift c ts = raise TERM ("bad arguments", Const c :: ts) |
|
61 |
|
62 fun shift m n T ts = |
|
63 let val U = Term.domain_type (Term.range_type T) |
|
64 in |
|
65 (case (can dest_wordT U, try (snd o HOLogic.dest_number o hd) ts) of |
|
66 (true, SOME i) => |
|
67 SOME (n, 2, [hd (tl ts), HOLogic.mk_number U i], mk_shift (m, T)) |
|
68 | _ => NONE) (* FIXME: also support non-numerical shifts *) |
|
69 end |
|
70 |
59 fun mk_shift' c [t, u] = Const c $ t $ mk_nat (snd (HOLogic.dest_number u)) |
71 fun mk_shift' c [t, u] = Const c $ t $ mk_nat (snd (HOLogic.dest_number u)) |
60 | mk_shift' c ts = raise TERM ("bad arguments", Const c :: ts) |
72 | mk_shift' c ts = raise TERM ("bad arguments", Const c :: ts) |
61 |
73 |
62 fun shift' m n T ts = |
74 fun shift' m n T ts = |
63 let val U = Term.domain_type T |
75 let val U = Term.domain_type T |
64 in |
76 in |
65 (case (can dest_wordT U, try (snd o HOLogic.dest_number o hd o tl) ts) of |
77 (case (can dest_wordT U, try (snd o HOLogic.dest_number o hd o tl) ts) of |
66 (true, SOME i) => |
78 (true, SOME i) => |
67 SOME (n, 2, [hd ts, HOLogic.mk_number U i], mk_shift' (m, T)) |
79 SOME (n, 2, [hd ts, HOLogic.mk_number U i], mk_shift' (m, T)) |
68 | _ => NONE) (* FIXME: also support non-numerical shifts *) |
|
69 end |
|
70 |
|
71 fun mk_shift c [u, t] = Const c $ mk_nat (snd (HOLogic.dest_number u)) $ t |
|
72 | mk_shift c ts = raise TERM ("bad arguments", Const c :: ts) |
|
73 |
|
74 fun shift m n T ts = |
|
75 let val U = Term.domain_type T |
|
76 in |
|
77 (case (can dest_wordT U, try (snd o HOLogic.dest_number o hd) ts) of |
|
78 (true, SOME i) => |
|
79 SOME (n, 2, [hd ts, HOLogic.mk_number U i], mk_shift (m, T)) |
|
80 | _ => NONE) (* FIXME: also support non-numerical shifts *) |
80 | _ => NONE) (* FIXME: also support non-numerical shifts *) |
81 end |
81 end |
82 |
82 |
83 fun mk_extract c i ts = Term.list_comb (Const c, mk_nat i :: ts) |
83 fun mk_extract c i ts = Term.list_comb (Const c, mk_nat i :: ts) |
84 |
84 |