Skip to content

Commit bc42ca5

Browse files
committed
save lemma names in Shared_State.
1 parent a6b2439 commit bc42ca5

3 files changed

Lines changed: 67 additions & 32 deletions

File tree

Abduction/Abduction.thy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ strategy Extend_Leaf =
4040
]
4141
]
4242

43-
strategy finish_goal_after_assuming_subgoals_n_conjectures =
43+
strategy Finish_Goal_After_Assuming_Subgoals_And_Conjectures =
4444
Thens [
4545
Repeat (Hammer),
4646
IsSolved

Abduction/Seed_Of_Or2And_Edge.ML

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -151,26 +151,15 @@ fun conjectures_to_seeds_of_or2and_edge (pst:Proof.state, pst_to_prove_ornode:Pr
151151
fun seed_has_counterexample (pst:Proof.state) ({new_goals,...}:seed_of_or2and_edge) =
152152
Shared_State.any_of_these_is_refuted pst new_goals;
153153

154-
fun add_or2and_edge_connected_to_parental_ornode
154+
fun add_or2and_edge_and_connect_it_to_parental_ornode
155155
(parent_or_key as (Or_N, _): key)(*parent node*)
156156
({new_goals : terms,
157157
proof : how_to_get_andnodes_from_ornode,
158158
state(*chained*) : Proof.state, ...}: seed_of_or2and_edge)(*child nodes*)
159159
(graph:abduction_graph): (key option * (string * term) list * abduction_graph) =
160160
let
161-
fun mk_temp_name (trm:term) =
162-
let
163-
val child_or_key = (Or_N, [trm]) : key;
164-
val maybe_child_or_val = try (PGraph.get_node graph) child_or_key: abduction_node option;
165-
val child_or_already_exists = is_some (maybe_child_or_val): bool;
166-
in
167-
if child_or_already_exists
168-
then
169-
lemma_name_of graph child_or_key: string
170-
else
171-
Top_Down_Util.mk_new_lemma_name (Proof.context_of state)
172-
end;
173-
val name_term_pairs = map (fn and_trm => (mk_temp_name and_trm, and_trm)) new_goals : (string * term) list;
161+
val ctxt = Proof.context_of state;
162+
val name_term_pairs = map (fn and_trm => (Shared_State.get_lemma_name ctxt and_trm, and_trm)) new_goals : (string * term) list;
174163
val pst_w_or_terms_assmd = Top_Down_Util.assume_cnjctrs_in_pst name_term_pairs state : Proof.state;
175164
(*TODO: maybe we should assume or-nodes that have been already proved completely in the abduction_graph.*)
176165
val timeouts = {overall = 30.0, hammer = 10.0, quickcheck = 1.0, nitpick = 2.0}: TBC_Utils.timeouts;
@@ -207,14 +196,24 @@ fun add_or2and_edge_connected_to_parental_ornode
207196
end
208197
else (NONE, [], graph)
209198
end
210-
| add_or2and_edge_connected_to_parental_ornode _ _ _ = error "how_to_prove_ornode_assmng_subgs_of_andnode failed.";
199+
| add_or2and_edge_and_connect_it_to_parental_ornode _ _ _ = error "how_to_prove_ornode_assmng_subgs_of_andnode failed.";
211200

201+
(*
202+
* 0. We have an or-node to expand.
203+
* 1. add an or2and-edge.
204+
* 2. connect the or2and-edge to its parental or-node.
205+
* 3. prove the parental or-node using the sub-goals or some conjectures.
206+
* 4. add an and-node that consists of the sub-goals or used conjectures.
207+
* 5. connect the and-node to its parental or2and-edge.
208+
* 6. add child-or-nodes that correspond to the sub-goals or used conjectures in the and-node.
209+
* 7. connect the child-or-nodes to the and-node.
210+
*)
212211
fun add_then_connect_or2and_edge_andnd_ornds (parent_ornd:key) (seed: seed_of_or2and_edge) (graph:abduction_graph): abduction_graph =
213212
let
214213
val graph_w_ornode_is_now_branch = UAG.update_is_branch parent_ornd graph : abduction_graph;
215214
(*add an or2and_ege and connect them to their parental or-node if we can prove the or-node assuming the and-node.*)
216215
val (or2and_edge_opt, used_and_node_name_term_pairs, graph_w_connected_or2add_edges) =
217-
add_or2and_edge_connected_to_parental_ornode parent_ornd seed graph_w_ornode_is_now_branch: (key option * (string * term) list * abduction_graph);
216+
add_or2and_edge_and_connect_it_to_parental_ornode parent_ornd seed graph_w_ornode_is_now_branch: (key option * (string * term) list * abduction_graph);
218217
val parent_ornd_is_proved_assmng_seed = is_some or2and_edge_opt: bool;
219218
in
220219
if parent_ornd_is_proved_assmng_seed

Abduction/Shared_State.ML

Lines changed: 51 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ sig
1010
type abduction_graph;
1111

1212
val any_of_these_is_refuted: Proof.state -> terms -> bool;
13+
val get_lemma_name : Proof.context -> term -> string;
14+
(*TODO: share abduction_graph*)
1315

1416
end;
1517

@@ -18,34 +20,42 @@ struct
1820

1921
type abduction_graph = Abduction_Graph.abduction_graph;
2022

23+
structure Term_Table = Table (type key = term val ord = Term_Ord.term_ord);
24+
val defined = Term_Table.defined;
25+
2126
local
2227

23-
structure Term_Refuted_Table = Table (type key = term val ord = Term_Ord.term_ord);
24-
type term_refute_table = bool Term_Refuted_Table.table; (*true = refuted, false = not refuted*)
28+
type term_refute_table = bool Term_Table.table; (*true = refuted, false = not refuted*)
2529
type synched_refutation_table = term_refute_table Synchronized.var;
2630

27-
val defined = Term_Refuted_Table.defined;
28-
val lookup = Utils.the' "lookup in Shared_State failed." oo Term_Refuted_Table.lookup;
29-
val refutation_table = Synchronized.var "refutation_table" Term_Refuted_Table.empty: synched_refutation_table;
30-
31+
val refutation_table = Synchronized.var "refutation_table" Term_Table.empty: synched_refutation_table;
32+
val lookup = Utils.the' "lookup for get_lemma_name failed." oo Term_Table.lookup;
3133
(*Once we refute a term. The term remains refuted in the table forever.*)
3234
fun insert (cnjctr:term, refuted:bool) (table:term_refute_table) =
33-
case try (Term_Refuted_Table.insert (op =) (cnjctr, refuted)) table
35+
case try (Term_Table.insert (op =) (cnjctr, refuted)) table
3436
of NONE => table
3537
| SOME new_table => new_table;
3638

3739
in
3840

39-
fun update_synched_refutation_table (pair: (term * bool)) = Synchronized.change refutation_table (insert pair): unit;
40-
4141
fun is_refuted (pst:Proof.state) (cnjctr:term) =
4242
let
43-
val old_table = Synchronized.value refutation_table : term_refute_table;
44-
val already_checked = defined old_table cnjctr : bool;
45-
fun quickcheck cnjctr = (cnjctr, TBC_Utils.term_has_counterexample_in_pst pst cnjctr) : (term * bool);
46-
val _ = if already_checked then () else update_synched_refutation_table (quickcheck cnjctr): unit;
47-
val new_table = Synchronized.value refutation_table : term_refute_table;
48-
val result = lookup new_table cnjctr : bool;
43+
val old_table = Synchronized.value refutation_table : term_refute_table;
44+
val already_checked = defined old_table cnjctr : bool;
45+
fun quickcheck cnjctr = (cnjctr, TBC_Utils.term_has_counterexample_in_pst pst cnjctr): (term * bool);
46+
val _ =
47+
if already_checked then ()
48+
else
49+
let
50+
(* It is okay to spend some time to run quick-check before calling Synchronized.change:
51+
* Even if other threads find a counter-example for the same conjecture,
52+
* the result should be the same. *)
53+
val pair = quickcheck cnjctr
54+
in
55+
Synchronized.change refutation_table (insert pair): unit
56+
end;
57+
val new_table = Synchronized.value refutation_table : term_refute_table;
58+
val result = lookup new_table cnjctr : bool;
4959
in
5060
result
5161
end;
@@ -54,4 +64,30 @@ fun any_of_these_is_refuted (pst:Proof.state) (terms:terms) = exists (is_refuted
5464

5565
end;
5666

67+
local
68+
69+
type term_lemma_name_table = string Term_Table.table;
70+
type synched_lemma_name_table = term_lemma_name_table Synchronized.var;
71+
72+
val lemma_name_table = Synchronized.var "lemma_name_table" Term_Table.empty: synched_lemma_name_table;
73+
val lookup = Utils.the' "lookup for get_lemma_name failed." oo Term_Table.lookup;
74+
fun insert (cnjctr:term, lemma_name:string) (old_table:term_lemma_name_table) =
75+
if defined old_table cnjctr
76+
then old_table
77+
else Term_Table.insert (op =) (cnjctr, lemma_name) old_table;
78+
79+
in
80+
81+
fun get_lemma_name (ctxt:Proof.context) (term:term) =
82+
let
83+
fun mk_new_name_pair _ = (term, Top_Down_Util.mk_new_lemma_name ctxt) : (term * string);
84+
val _ = Synchronized.change lemma_name_table (insert (mk_new_name_pair ())) : unit;
85+
val new_table = Synchronized.value lemma_name_table : term_lemma_name_table;
86+
val result = lookup new_table term : string;
87+
in
88+
result
89+
end;
90+
91+
end;
92+
5793
end;

0 commit comments

Comments
 (0)