36 {order = SMT_Util.First_Order, |
36 {order = SMT_Util.First_Order, |
37 logic = K "", |
37 logic = K "", |
38 fp_kinds = [BNF_Util.Least_FP], |
38 fp_kinds = [BNF_Util.Least_FP], |
39 serialize = #serialize (SMTLIB_Interface.translate_config SMT_Util.First_Order ctxt)} |
39 serialize = #serialize (SMTLIB_Interface.translate_config SMT_Util.First_Order ctxt)} |
40 |
40 |
41 fun is_div_mod @{const divide (int)} = true |
41 fun is_div_mod \<^Const_>\<open>divide \<^Type>\<open>int\<close>\<close> = true |
42 | is_div_mod @{const modulo (int)} = true |
42 | is_div_mod \<^Const>\<open>modulo \<^Type>\<open>int\<close>\<close> = true |
43 | is_div_mod _ = false |
43 | is_div_mod _ = false |
44 |
44 |
45 val have_int_div_mod = exists (Term.exists_subterm is_div_mod o Thm.prop_of) |
45 val have_int_div_mod = exists (Term.exists_subterm is_div_mod o Thm.prop_of) |
46 |
46 |
47 fun add_div_mod _ (thms, extra_thms) = |
47 fun add_div_mod _ (thms, extra_thms) = |
48 if have_int_div_mod thms orelse have_int_div_mod extra_thms then |
48 if have_int_div_mod thms orelse have_int_div_mod extra_thms then |
49 (thms, @{thms div_as_z3div mod_as_z3mod} @ extra_thms) |
49 (thms, @{thms div_as_z3div mod_as_z3mod} @ extra_thms) |
50 else (thms, extra_thms) |
50 else (thms, extra_thms) |
51 |
51 |
52 val setup_builtins = |
52 val setup_builtins = |
53 SMT_Builtin.add_builtin_fun' smtlib_z3C (@{const times (int)}, "*") #> |
53 SMT_Builtin.add_builtin_fun' smtlib_z3C (\<^Const>\<open>times \<^Type>\<open>int\<close>\<close>, "*") #> |
54 SMT_Builtin.add_builtin_fun' smtlib_z3C (\<^const>\<open>z3div\<close>, "div") #> |
54 SMT_Builtin.add_builtin_fun' smtlib_z3C (\<^Const>\<open>z3div\<close>, "div") #> |
55 SMT_Builtin.add_builtin_fun' smtlib_z3C (\<^const>\<open>z3mod\<close>, "mod") |
55 SMT_Builtin.add_builtin_fun' smtlib_z3C (\<^Const>\<open>z3mod\<close>, "mod") |
56 in |
56 in |
57 |
57 |
58 val _ = Theory.setup (Context.theory_map ( |
58 val _ = Theory.setup (Context.theory_map ( |
59 setup_builtins #> |
59 setup_builtins #> |
60 SMT_Normalize.add_extra_norm (smtlib_z3C, add_div_mod) #> |
60 SMT_Normalize.add_extra_norm (smtlib_z3C, add_div_mod) #> |
114 |
114 |
115 fun mk_builtin_num _ i \<^typ>\<open>int\<close> = SOME (Numeral.mk_cnumber \<^ctyp>\<open>int\<close> i) |
115 fun mk_builtin_num _ i \<^typ>\<open>int\<close> = SOME (Numeral.mk_cnumber \<^ctyp>\<open>int\<close> i) |
116 | mk_builtin_num ctxt i T = |
116 | mk_builtin_num ctxt i T = |
117 chained_mk_builtin_num ctxt (get_mk_builtins ctxt) i T |
117 chained_mk_builtin_num ctxt (get_mk_builtins ctxt) i T |
118 |
118 |
119 val mk_true = Thm.cterm_of \<^context> (\<^const>\<open>Not\<close> $ \<^const>\<open>False\<close>) |
119 val mk_true = \<^cterm>\<open>\<not> False\<close> |
120 val mk_false = Thm.cterm_of \<^context> \<^const>\<open>False\<close> |
120 val mk_false = \<^cterm>\<open>False\<close> |
121 val mk_not = Thm.apply (Thm.cterm_of \<^context> \<^const>\<open>Not\<close>) |
121 val mk_not = Thm.apply \<^cterm>\<open>HOL.Not\<close> |
122 val mk_implies = Thm.mk_binop (Thm.cterm_of \<^context> \<^const>\<open>HOL.implies\<close>) |
122 val mk_implies = Thm.mk_binop \<^cterm>\<open>HOL.implies\<close> |
123 val mk_iff = Thm.mk_binop (Thm.cterm_of \<^context> @{const HOL.eq (bool)}) |
123 val mk_iff = Thm.mk_binop \<^cterm>\<open>(=) :: bool \<Rightarrow> _\<close> |
124 val conj = Thm.cterm_of \<^context> \<^const>\<open>HOL.conj\<close> |
124 val conj = \<^cterm>\<open>HOL.conj\<close> |
125 val disj = Thm.cterm_of \<^context> \<^const>\<open>HOL.disj\<close> |
125 val disj = \<^cterm>\<open>HOL.disj\<close> |
126 |
126 |
127 fun mk_nary _ cu [] = cu |
127 fun mk_nary _ cu [] = cu |
128 | mk_nary ct _ cts = uncurry (fold_rev (Thm.mk_binop ct)) (split_last cts) |
128 | mk_nary ct _ cts = uncurry (fold_rev (Thm.mk_binop ct)) (split_last cts) |
129 |
129 |
130 val eq = SMT_Util.mk_const_pat \<^theory> \<^const_name>\<open>HOL.eq\<close> Thm.dest_ctyp0 |
130 val eq = SMT_Util.mk_const_pat \<^theory> \<^const_name>\<open>HOL.eq\<close> Thm.dest_ctyp0 |
141 SMT_Util.mk_const_pat \<^theory> \<^const_name>\<open>fun_upd\<close> (Thm.dest_ctyp o Thm.dest_ctyp0) |
141 SMT_Util.mk_const_pat \<^theory> \<^const_name>\<open>fun_upd\<close> (Thm.dest_ctyp o Thm.dest_ctyp0) |
142 fun mk_update array index value = |
142 fun mk_update array index value = |
143 let val cTs = Thm.dest_ctyp (Thm.ctyp_of_cterm array) |
143 let val cTs = Thm.dest_ctyp (Thm.ctyp_of_cterm array) |
144 in Thm.apply (Thm.mk_binop (SMT_Util.instTs cTs update) array index) value end |
144 in Thm.apply (Thm.mk_binop (SMT_Util.instTs cTs update) array index) value end |
145 |
145 |
146 val mk_uminus = Thm.apply (Thm.cterm_of \<^context> @{const uminus (int)}) |
146 val mk_uminus = Thm.apply \<^cterm>\<open>uminus :: int \<Rightarrow> _\<close> |
147 val add = Thm.cterm_of \<^context> @{const plus (int)} |
147 val add = \<^cterm>\<open>(+) :: int \<Rightarrow> _\<close> |
148 val int0 = Numeral.mk_cnumber \<^ctyp>\<open>int\<close> 0 |
148 val int0 = Numeral.mk_cnumber \<^ctyp>\<open>int\<close> 0 |
149 val mk_sub = Thm.mk_binop (Thm.cterm_of \<^context> @{const minus (int)}) |
149 val mk_sub = Thm.mk_binop \<^cterm>\<open>(-) :: int \<Rightarrow> _\<close> |
150 val mk_mul = Thm.mk_binop (Thm.cterm_of \<^context> @{const times (int)}) |
150 val mk_mul = Thm.mk_binop \<^cterm>\<open>(*) :: int \<Rightarrow> _\<close> |
151 val mk_div = Thm.mk_binop (Thm.cterm_of \<^context> \<^const>\<open>z3div\<close>) |
151 val mk_div = Thm.mk_binop \<^cterm>\<open>z3div\<close> |
152 val mk_mod = Thm.mk_binop (Thm.cterm_of \<^context> \<^const>\<open>z3mod\<close>) |
152 val mk_mod = Thm.mk_binop \<^cterm>\<open>z3mod\<close> |
153 val mk_lt = Thm.mk_binop (Thm.cterm_of \<^context> @{const less (int)}) |
153 val mk_lt = Thm.mk_binop \<^cterm>\<open>(<) :: int \<Rightarrow> _\<close> |
154 val mk_le = Thm.mk_binop (Thm.cterm_of \<^context> @{const less_eq (int)}) |
154 val mk_le = Thm.mk_binop \<^cterm>\<open>(\<le>) :: int \<Rightarrow> _\<close> |
155 |
155 |
156 fun mk_builtin_fun ctxt sym cts = |
156 fun mk_builtin_fun ctxt sym cts = |
157 (case (sym, cts) of |
157 (case (sym, cts) of |
158 (Sym ("true", _), []) => SOME mk_true |
158 (Sym ("true", _), []) => SOME mk_true |
159 | (Sym ("false", _), []) => SOME mk_false |
159 | (Sym ("false", _), []) => SOME mk_false |