src/HOL/Tools/SMT/z3_proof_reconstruction.ML
changeset 42992 4fc15e3217eb
parent 42793 88bee9f6eec7
child 43893 f3e75541cb78
equal deleted inserted replaced
42991:3fa22920bf86 42992:4fc15e3217eb
   358       | _ => raise CTERM ("prove_def_axiom", [ct]))
   358       | _ => raise CTERM ("prove_def_axiom", [ct]))
   359     end
   359     end
   360 in
   360 in
   361 fun def_axiom ctxt = Thm o try_apply ctxt [] [
   361 fun def_axiom ctxt = Thm o try_apply ctxt [] [
   362   named ctxt "conj/disj/distinct" prove_def_axiom,
   362   named ctxt "conj/disj/distinct" prove_def_axiom,
   363   Z3_Proof_Tools.by_abstraction (true, false) ctxt [] (fn ctxt' =>
   363   Z3_Proof_Tools.by_abstraction 0 (true, false) ctxt [] (fn ctxt' =>
   364     named ctxt' "simp+fast" (Z3_Proof_Tools.by_tac (simp_fast_tac ctxt')))]
   364     named ctxt' "simp+fast" (Z3_Proof_Tools.by_tac (simp_fast_tac ctxt')))]
   365 end
   365 end
   366 
   366 
   367 
   367 
   368 (* local definitions *)
   368 (* local definitions *)
   419     Z3_Proof_Tools.as_meta_eq ct
   419     Z3_Proof_Tools.as_meta_eq ct
   420     |> Z3_Proof_Tools.by_tac (nnf_quant_tac_varified vars (meta_eq_of p) qs)
   420     |> Z3_Proof_Tools.by_tac (nnf_quant_tac_varified vars (meta_eq_of p) qs)
   421 
   421 
   422   fun prove_nnf ctxt = try_apply ctxt [] [
   422   fun prove_nnf ctxt = try_apply ctxt [] [
   423     named ctxt "conj/disj" Z3_Proof_Literals.prove_conj_disj_eq,
   423     named ctxt "conj/disj" Z3_Proof_Literals.prove_conj_disj_eq,
   424     Z3_Proof_Tools.by_abstraction (true, false) ctxt [] (fn ctxt' =>
   424     Z3_Proof_Tools.by_abstraction 0 (true, false) ctxt [] (fn ctxt' =>
   425       named ctxt' "simp+fast" (Z3_Proof_Tools.by_tac (simp_fast_tac ctxt')))]
   425       named ctxt' "simp+fast" (Z3_Proof_Tools.by_tac (simp_fast_tac ctxt')))]
   426 in
   426 in
   427 fun nnf ctxt vars ps ct =
   427 fun nnf ctxt vars ps ct =
   428   (case SMT_Utils.term_of ct of
   428   (case SMT_Utils.term_of ct of
   429     _ $ (l as Const _ $ Abs _) $ (r as Const _ $ Abs _) =>
   429     _ $ (l as Const _ $ Abs _) $ (r as Const _ $ Abs _) =>
   641 
   641 
   642 (** theory proof rules **)
   642 (** theory proof rules **)
   643 
   643 
   644 (* theory lemmas: linear arithmetic, arrays *)
   644 (* theory lemmas: linear arithmetic, arrays *)
   645 fun th_lemma ctxt simpset thms = Thm o try_apply ctxt thms [
   645 fun th_lemma ctxt simpset thms = Thm o try_apply ctxt thms [
   646   Z3_Proof_Tools.by_abstraction (false, true) ctxt thms (fn ctxt' =>
   646   Z3_Proof_Tools.by_abstraction 0 (false, true) ctxt thms (fn ctxt' =>
   647     Z3_Proof_Tools.by_tac (
   647     Z3_Proof_Tools.by_tac (
   648       NAMED ctxt' "arith" (Arith_Data.arith_tac ctxt')
   648       NAMED ctxt' "arith" (Arith_Data.arith_tac ctxt')
   649       ORELSE' NAMED ctxt' "simp+arith" (
   649       ORELSE' NAMED ctxt' "simp+arith" (
   650         Simplifier.simp_tac simpset
   650         Simplifier.simp_tac simpset
   651         THEN_ALL_NEW Arith_Data.arith_tac ctxt')))]
   651         THEN_ALL_NEW Arith_Data.arith_tac ctxt')))]
   691 
   691 
   692   fun declare_hyps ctxt thm =
   692   fun declare_hyps ctxt thm =
   693     (thm, snd (Assumption.add_assumes (#hyps (Thm.crep_thm thm)) ctxt))
   693     (thm, snd (Assumption.add_assumes (#hyps (Thm.crep_thm thm)) ctxt))
   694 in
   694 in
   695 
   695 
       
   696 val abstraction_depth = 3
       
   697   (*
       
   698     This value was chosen large enough to potentially catch exceptions,
       
   699     yet small enough to not cause too much harm.  The value might be
       
   700     increased in the future, if reconstructing 'rewrite' fails on problems
       
   701     that get too much abstracted to be reconstructable.
       
   702   *)
       
   703 
   696 fun rewrite simpset ths ct ctxt =
   704 fun rewrite simpset ths ct ctxt =
   697   apfst Thm (declare_hyps ctxt (with_conv ctxt ths (try_apply ctxt [] [
   705   apfst Thm (declare_hyps ctxt (with_conv ctxt ths (try_apply ctxt [] [
   698     named ctxt "conj/disj/distinct" prove_conj_disj_eq,
   706     named ctxt "conj/disj/distinct" prove_conj_disj_eq,
   699     Z3_Proof_Tools.by_abstraction (true, false) ctxt [] (fn ctxt' =>
   707     Z3_Proof_Tools.by_abstraction 0 (true, false) ctxt [] (fn ctxt' =>
   700       Z3_Proof_Tools.by_tac (
   708       Z3_Proof_Tools.by_tac (
   701         NAMED ctxt' "simp (logic)" (Simplifier.simp_tac simpset)
   709         NAMED ctxt' "simp (logic)" (Simplifier.simp_tac simpset)
   702         THEN_ALL_NEW NAMED ctxt' "fast (logic)" (fast_tac ctxt'))),
   710         THEN_ALL_NEW NAMED ctxt' "fast (logic)" (fast_tac ctxt'))),
   703     Z3_Proof_Tools.by_abstraction (false, true) ctxt [] (fn ctxt' =>
   711     Z3_Proof_Tools.by_abstraction 0 (false, true) ctxt [] (fn ctxt' =>
   704       Z3_Proof_Tools.by_tac (
   712       Z3_Proof_Tools.by_tac (
   705         NAMED ctxt' "simp (theory)" (Simplifier.simp_tac simpset)
   713         NAMED ctxt' "simp (theory)" (Simplifier.simp_tac simpset)
   706         THEN_ALL_NEW (
   714         THEN_ALL_NEW (
   707           NAMED ctxt' "fast (theory)" (HOL_fast_tac ctxt')
   715           NAMED ctxt' "fast (theory)" (HOL_fast_tac ctxt')
   708           ORELSE' NAMED ctxt' "arith (theory)" (Arith_Data.arith_tac ctxt')))),
   716           ORELSE' NAMED ctxt' "arith (theory)" (Arith_Data.arith_tac ctxt')))),
   709     Z3_Proof_Tools.by_abstraction (true, true) ctxt [] (fn ctxt' =>
   717     Z3_Proof_Tools.by_abstraction 0 (true, true) ctxt [] (fn ctxt' =>
   710       Z3_Proof_Tools.by_tac (
   718       Z3_Proof_Tools.by_tac (
   711         NAMED ctxt' "simp (full)" (Simplifier.simp_tac simpset)
   719         NAMED ctxt' "simp (full)" (Simplifier.simp_tac simpset)
   712         THEN_ALL_NEW (
   720         THEN_ALL_NEW (
   713           NAMED ctxt' "fast (full)" (HOL_fast_tac ctxt')
   721           NAMED ctxt' "fast (full)" (HOL_fast_tac ctxt')
   714           ORELSE' NAMED ctxt' "arith (full)" (Arith_Data.arith_tac ctxt')))),
   722           ORELSE' NAMED ctxt' "arith (full)" (Arith_Data.arith_tac ctxt')))),
   715     named ctxt "injectivity" (Z3_Proof_Methods.prove_injectivity ctxt)]) ct))
   723     named ctxt "injectivity" (Z3_Proof_Methods.prove_injectivity ctxt),
       
   724     Z3_Proof_Tools.by_abstraction abstraction_depth (true, true) ctxt []
       
   725       (fn ctxt' =>
       
   726         Z3_Proof_Tools.by_tac (
       
   727           NAMED ctxt' "simp (deepen)" (Simplifier.simp_tac simpset)
       
   728           THEN_ALL_NEW (
       
   729             NAMED ctxt' "fast (deepen)" (HOL_fast_tac ctxt')
       
   730             ORELSE' NAMED ctxt' "arith (deepen)" (Arith_Data.arith_tac
       
   731               ctxt'))))]) ct))
   716 
   732 
   717 end
   733 end
   718 
   734 
   719 
   735 
   720 
   736