1010type abduction_graph ;
1111
1212val any_of_these_is_refuted: Proof.state -> terms -> bool;
13+ val get_lemma_name : Proof.context -> term -> string;
14+ (* TODO: share abduction_graph*)
1315
1416end ;
1517
@@ -18,34 +20,42 @@ struct
1820
1921type 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+
2126local
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*)
2529type 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.*)
3234fun 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
3739in
3840
39- fun update_synched_refutation_table (pair: (term * bool)) = Synchronized.change refutation_table (insert pair): unit;
40-
4141fun 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
5565end ;
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+
5793end ;
0 commit comments