29 (* general theorem normalizations *) |
29 (* general theorem normalizations *) |
30 |
30 |
31 (** instantiate elimination rules **) |
31 (** instantiate elimination rules **) |
32 |
32 |
33 local |
33 local |
34 val (cpfalse, cfalse) = `SMT_Util.mk_cprop (Thm.cterm_of @{context} \<^const>\<open>False\<close>) |
34 val (cpfalse, cfalse) = `SMT_Util.mk_cprop (Thm.cterm_of \<^context> \<^const>\<open>False\<close>) |
35 |
35 |
36 fun inst f ct thm = |
36 fun inst f ct thm = |
37 let val cv = f (Drule.strip_imp_concl (Thm.cprop_of thm)) |
37 let val cv = f (Drule.strip_imp_concl (Thm.cprop_of thm)) |
38 in Thm.instantiate ([], [(dest_Var (Thm.term_of cv), ct)]) thm end |
38 in Thm.instantiate ([], [(dest_Var (Thm.term_of cv), ct)]) thm end |
39 in |
39 in |
184 val tps = (op ~~) (`gen (map Thm.term_of cts)) |
184 val tps = (op ~~) (`gen (map Thm.term_of cts)) |
185 fun some_match u = tps |> exists (fn (t', t) => |
185 fun some_match u = tps |> exists (fn (t', t) => |
186 Pattern.matches thy (t', u) andalso not (t aconv u)) |
186 Pattern.matches thy (t', u) andalso not (t aconv u)) |
187 in not (Term.exists_subterm some_match u) end |
187 in not (Term.exists_subterm some_match u) end |
188 |
188 |
189 val pat = SMT_Util.mk_const_pat @{theory} \<^const_name>\<open>pat\<close> SMT_Util.destT1 |
189 val pat = SMT_Util.mk_const_pat \<^theory> \<^const_name>\<open>pat\<close> SMT_Util.destT1 |
190 fun mk_pat ct = Thm.apply (SMT_Util.instT' ct pat) ct |
190 fun mk_pat ct = Thm.apply (SMT_Util.instT' ct pat) ct |
191 |
191 |
192 fun mk_clist T = |
192 fun mk_clist T = |
193 apply2 (Thm.cterm_of @{context}) (SMT_Util.symb_cons_const T, SMT_Util.symb_nil_const T) |
193 apply2 (Thm.cterm_of \<^context>) (SMT_Util.symb_cons_const T, SMT_Util.symb_nil_const T) |
194 fun mk_list (ccons, cnil) f cts = fold_rev (Thm.mk_binop ccons o f) cts cnil |
194 fun mk_list (ccons, cnil) f cts = fold_rev (Thm.mk_binop ccons o f) cts cnil |
195 val mk_pat_list = mk_list (mk_clist \<^typ>\<open>pattern\<close>) |
195 val mk_pat_list = mk_list (mk_clist \<^typ>\<open>pattern\<close>) |
196 val mk_mpat_list = mk_list (mk_clist \<^typ>\<open>pattern symb_list\<close>) |
196 val mk_mpat_list = mk_list (mk_clist \<^typ>\<open>pattern symb_list\<close>) |
197 fun mk_trigger ctss = mk_mpat_list (mk_pat_list mk_pat) ctss |
197 fun mk_trigger ctss = mk_mpat_list (mk_pat_list mk_pat) ctss |
198 |
198 |
347 |
347 |
348 fun if_conv cv1 cv2 = Conv.combination_conv (Conv.combination_conv (Conv.arg_conv cv1) cv2) cv2 |
348 fun if_conv cv1 cv2 = Conv.combination_conv (Conv.combination_conv (Conv.arg_conv cv1) cv2) cv2 |
349 |
349 |
350 fun int_ops_conv cv ctxt ct = |
350 fun int_ops_conv cv ctxt ct = |
351 (case Thm.term_of ct of |
351 (case Thm.term_of ct of |
352 @{const of_nat (int)} $ (Const (@{const_name If}, _) $ _ $ _ $ _) => |
352 @{const of_nat (int)} $ (Const (\<^const_name>\<open>If\<close>, _) $ _ $ _ $ _) => |
353 Conv.rewr_conv int_if_thm then_conv |
353 Conv.rewr_conv int_if_thm then_conv |
354 if_conv (cv ctxt) (int_ops_conv cv ctxt) |
354 if_conv (cv ctxt) (int_ops_conv cv ctxt) |
355 | @{const of_nat (int)} $ _ => |
355 | @{const of_nat (int)} $ _ => |
356 (Conv.rewrs_conv int_ops_thms then_conv |
356 (Conv.rewrs_conv int_ops_thms then_conv |
357 Conv.top_sweep_conv (int_ops_conv cv) ctxt) else_conv |
357 Conv.top_sweep_conv (int_ops_conv cv) ctxt) else_conv |
428 | is_irregular_number _ = false |
428 | is_irregular_number _ = false |
429 |
429 |
430 fun is_strange_number ctxt t = is_irregular_number t andalso SMT_Builtin.is_builtin_num ctxt t |
430 fun is_strange_number ctxt t = is_irregular_number t andalso SMT_Builtin.is_builtin_num ctxt t |
431 |
431 |
432 val proper_num_ss = |
432 val proper_num_ss = |
433 simpset_of (put_simpset HOL_ss @{context} addsimps @{thms Num.numeral_One minus_zero}) |
433 simpset_of (put_simpset HOL_ss \<^context> addsimps @{thms Num.numeral_One minus_zero}) |
434 |
434 |
435 fun norm_num_conv ctxt = |
435 fun norm_num_conv ctxt = |
436 SMT_Util.if_conv (is_strange_number ctxt) (Simplifier.rewrite (put_simpset proper_num_ss ctxt)) |
436 SMT_Util.if_conv (is_strange_number ctxt) (Simplifier.rewrite (put_simpset proper_num_ss ctxt)) |
437 Conv.no_conv |
437 Conv.no_conv |
438 in |
438 in |