33419
|
1 |
(* Title: HOL/Boogie/Tools/boogie_split.ML
|
|
2 |
Author: Sascha Boehme, TU Muenchen
|
|
3 |
|
|
4 |
Method to split Boogie-generate verification conditions and pass the splinters
|
|
5 |
to user-supplied automated sub-tactics.
|
|
6 |
*)
|
|
7 |
|
|
8 |
signature BOOGIE_SPLIT =
|
|
9 |
sig
|
|
10 |
val add_sub_tactic: string * (Proof.context -> int -> tactic) -> theory ->
|
|
11 |
theory
|
|
12 |
val sub_tactic_names: theory -> string list
|
|
13 |
val setup: theory -> theory
|
|
14 |
end
|
|
15 |
|
|
16 |
structure Boogie_Split: BOOGIE_SPLIT =
|
|
17 |
struct
|
|
18 |
|
|
19 |
(* sub-tactics store *)
|
|
20 |
|
|
21 |
structure Sub_Tactics = TheoryDataFun
|
|
22 |
(
|
|
23 |
type T = (Proof.context -> int -> tactic) Symtab.table
|
|
24 |
val empty = Symtab.empty
|
|
25 |
val copy = I
|
|
26 |
val extend = I
|
|
27 |
fun merge _ = Symtab.merge (K true)
|
|
28 |
)
|
|
29 |
|
|
30 |
fun add_sub_tactic tac = Sub_Tactics.map (Symtab.update_new tac)
|
|
31 |
|
|
32 |
val sub_tactic_names = Symtab.keys o Sub_Tactics.get
|
|
33 |
|
|
34 |
fun lookup_sub_tactic ctxt name =
|
|
35 |
(case Symtab.lookup (Sub_Tactics.get (ProofContext.theory_of ctxt)) name of
|
|
36 |
SOME tac => SOME (name, tac)
|
|
37 |
| NONE => (warning ("Unknown sub-tactic: " ^ quote name); NONE))
|
|
38 |
|
|
39 |
fun as_meta_eq eq = eq RS @{thm eq_reflection}
|
|
40 |
|
|
41 |
fun full_implies_conv cv ct =
|
|
42 |
(case try Thm.dest_implies ct of
|
|
43 |
NONE => cv ct
|
|
44 |
| SOME (cp, cc) => Drule.imp_cong_rule (cv cp) (full_implies_conv cv cc))
|
|
45 |
|
|
46 |
fun sub_tactics_tac ctxt (verbose, sub_tac_names) case_name =
|
|
47 |
let
|
|
48 |
fun trace msg = if verbose then tracing msg else ()
|
|
49 |
fun trying name = trace ("Trying tactic " ^ quote name ^ " on case " ^
|
|
50 |
quote case_name ^ " ...")
|
|
51 |
fun solved () = trace ("Case solved: " ^ quote case_name)
|
|
52 |
fun failed () = trace ("Case remains unsolved: " ^ quote case_name)
|
|
53 |
|
|
54 |
infix IF_UNSOLVED
|
|
55 |
fun (tac1 IF_UNSOLVED tac2) i st = st |> (tac1 i THEN (fn st' =>
|
|
56 |
if i > i + nprems_of st' - nprems_of st
|
|
57 |
then (solved (); Tactical.all_tac st')
|
|
58 |
else Seq.INTERVAL tac2 i (i + nprems_of st' - nprems_of st) st'))
|
|
59 |
|
|
60 |
fun TRY_ALL [] _ st = (failed (); Tactical.no_tac st)
|
|
61 |
| TRY_ALL ((name, tac) :: tacs) i st = (trying name;
|
|
62 |
(TRY o tac ctxt IF_UNSOLVED TRY_ALL tacs) i st)
|
|
63 |
|
|
64 |
val unfold_labels = Conv.try_conv (Conv.arg_conv
|
|
65 |
(More_Conv.rewrs_conv (map as_meta_eq @{thms labels})))
|
|
66 |
in
|
|
67 |
CONVERSION (full_implies_conv unfold_labels)
|
|
68 |
THEN' TRY_ALL (map_filter (lookup_sub_tactic ctxt) sub_tac_names)
|
|
69 |
end
|
|
70 |
|
|
71 |
|
|
72 |
(* splitting method *)
|
|
73 |
|
|
74 |
local
|
|
75 |
fun case_name_of _ i = "goal" ^ string_of_int i
|
|
76 |
(*FIXME: proper case names*)
|
|
77 |
|
|
78 |
val split_rules = [@{thm impI}, @{thm conjI}, @{thm TrueI}]
|
|
79 |
|
|
80 |
fun prep_tac ctxt args facts =
|
|
81 |
Method.insert_tac facts
|
|
82 |
THEN' REPEAT_ALL_NEW (Tactic.resolve_tac split_rules)
|
|
83 |
THEN_ALL_NEW SUBGOAL (fn (t, i) =>
|
|
84 |
TRY (sub_tactics_tac ctxt args (case_name_of t i) i))
|
|
85 |
|
|
86 |
fun case_names st =
|
|
87 |
map_index (fn (i, t) => (case_name_of t (i + 1), [])) (Thm.prems_of st)
|
|
88 |
|
|
89 |
val drop_assert_at = Conv.concl_conv ~1 (Conv.try_conv (Conv.arg_conv
|
|
90 |
(Conv.rewr_conv (as_meta_eq @{thm assert_at_def}))))
|
|
91 |
|
|
92 |
fun split_vc args ctxt = METHOD_CASES (fn facts =>
|
|
93 |
prep_tac ctxt args facts 1 #>
|
|
94 |
Seq.maps (fn st =>
|
|
95 |
st
|
|
96 |
|> ALLGOALS (CONVERSION drop_assert_at)
|
|
97 |
|> Seq.map (pair (case_names st))) #>
|
|
98 |
Seq.maps (fn (names, st) =>
|
|
99 |
CASES
|
|
100 |
(Rule_Cases.make_common false
|
|
101 |
(ProofContext.theory_of ctxt, Thm.prop_of st) names)
|
|
102 |
Tactical.all_tac st))
|
|
103 |
|
|
104 |
val verbose_opt = Args.parens (Args.$$$ "verbose") >> K true
|
|
105 |
val sub_tactics = Args.$$$ "try" -- Args.colon |-- Scan.repeat1 Args.name
|
|
106 |
in
|
|
107 |
val setup_split_vc = Method.setup @{binding split_vc}
|
|
108 |
(Scan.lift (Scan.optional verbose_opt false -- Scan.optional sub_tactics [])
|
|
109 |
>> split_vc)
|
|
110 |
("Splits a Boogie-generated verification conditions into smaller problems" ^
|
|
111 |
" and tries to solve the splinters with the supplied sub-tactics.")
|
|
112 |
end
|
|
113 |
|
|
114 |
|
|
115 |
(* predefined sub-tactics *)
|
|
116 |
|
|
117 |
fun fast_sub_tac ctxt = Classical.fast_tac (Classical.claset_of ctxt)
|
|
118 |
fun simp_sub_tac ctxt =
|
|
119 |
Simplifier.asm_full_simp_tac (Simplifier.simpset_of ctxt)
|
|
120 |
fun smt_sub_tac ctxt = SMT_Solver.smt_tac ctxt (Split_VC_SMT_Rules.get ctxt)
|
|
121 |
|
|
122 |
|
|
123 |
(* setup *)
|
|
124 |
|
|
125 |
val setup =
|
|
126 |
setup_split_vc #>
|
|
127 |
add_sub_tactic ("fast", fast_sub_tac) #>
|
|
128 |
add_sub_tactic ("simp", simp_sub_tac) #>
|
|
129 |
add_sub_tactic ("smt", smt_sub_tac)
|
|
130 |
|
|
131 |
end
|