Skip to content

Commit c712a74

Browse files
committed
sort terms when addning new nodes to graphs.
1 parent 7eb6ee9 commit c712a74

5 files changed

Lines changed: 48 additions & 22 deletions

File tree

Abduction/Abduction_Graph.ML

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -99,14 +99,11 @@ fun node_type_compare (Or_N, Or_N ) = EQUAL
9999
| node_type_compare (O2A_E i1, O2A_E i2) = Int.compare (i1, i2)
100100
| node_type_compare (O2A_E _, _ ) = GREATER;
101101

102-
fun term_compare (trm1, trm2) =
103-
Term_Ord.term_ord ((Top_Down_Util.standardize_vnames trm1), (Top_Down_Util.standardize_vnames trm2))
104-
105102
(* PGraph_Key *)
106103
structure PGraph_Key =
107104
struct
108105
type key = (node_type * terms(*normal terms not thms*))
109-
val ord = prod_ord node_type_compare (list_ord term_compare)
106+
val ord = prod_ord node_type_compare (list_ord Top_Down_Util.term_compare)
110107
end:KEY
111108

112109
(* PGraph *)
@@ -134,14 +131,23 @@ fun equal_keys key_pair = PGraph_Key.ord key_pair = EQUAL;
134131
type is_final_goal = bool;
135132

136133
fun mk_ornode (is_final_goal:is_final_goal) (lemma_name:string) (goal:term) =
134+
let
135+
val standardized_goal = Top_Down_Util.standardize_vnames goal;
136+
in
137137
(
138-
(Or_N, [goal]): key,
139-
Abduction_Node.mk_ornode is_final_goal lemma_name goal: abduction_node
140-
);
138+
(Or_N, [standardized_goal]): key,
139+
Abduction_Node.mk_ornode is_final_goal lemma_name standardized_goal: abduction_node
140+
)
141+
end;
141142

142143
fun mk_andnode (goals:terms) =
143-
((And_N, goals): key,
144-
Abduction_Node.mk_andnode goals);
144+
let
145+
val standardized_terms = map Top_Down_Util.standardize_vnames goals;
146+
val sorted_terms = sort Term_Ord.term_ord standardized_terms;
147+
in
148+
((And_N, sorted_terms): key,
149+
Abduction_Node.mk_andnode sorted_terms)
150+
end;
145151

146152
(* key to term *)
147153
fun orkey_to_term (Or_N, [orleaf_term]) = orleaf_term

Abduction/All_Top_Down_Conjecturing.ML

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,11 @@ fun template_conjectures (ctxt:Proof.context) (trm:term): (string * term) list =
158158
result
159159
end;
160160

161+
structure S4TD = SeLFiE_for_Top_Down;
162+
163+
fun run_assertion (ctxt:Proof.context) (trm:term) (assert:Eval_Syntactic_Sugar.assert) =
164+
S4TD.run_assertion (Top_Down_Util.mk_pst_to_prove_from_term ctxt trm) assert trm;
165+
161166
fun top_down_conjectures (ctxt:Proof.context) trm =
162167
let
163168
val _ = tracing "[[[[[[[[[[[top_down_conjecture starts]]]]]]]]]]": unit;
@@ -177,9 +182,9 @@ fun top_down_conjectures (ctxt:Proof.context) trm =
177182
(*
178183
|> parallel_filter_out (fn (_, trm) => eq_over_same_func ctxt trm)
179184
*)
180-
|> parallel_filter_out (fn (_, trm) => SeLFiE_for_Top_Down.run_assertion (Top_Down_Util.mk_pst_to_prove_from_term ctxt trm) SeLFiE_for_Top_Down.has_func_with_three_occs_in_a_row trm)
181-
|> parallel_filter (fn (_, trm) => SeLFiE_for_Top_Down.run_assertion (Top_Down_Util.mk_pst_to_prove_from_term ctxt trm) SeLFiE_for_Top_Down.fvars_in_prem_should_appear_in_concl trm)
182-
|> parallel_filter (fn (_, trm) => SeLFiE_for_Top_Down.run_assertion (Top_Down_Util.mk_pst_to_prove_from_term ctxt trm) SeLFiE_for_Top_Down.does_not_have_trivial_equality trm);
185+
|> parallel_filter_out (fn (_, trm) => run_assertion ctxt trm S4TD.has_func_with_three_occs_in_a_row)
186+
|> parallel_filter (fn (_, trm) => run_assertion ctxt trm S4TD.fvars_in_prem_should_appear_in_concl)
187+
|> parallel_filter (fn (_, trm) => run_assertion ctxt trm S4TD.does_not_have_trivial_equality);
183188
val _ = tracing "[[[[[[[[[[[top_down_conjecture ends]]]]]]]]]]": unit;
184189
in
185190
results

Abduction/Proof_By_Abduction.ML

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -83,15 +83,15 @@ fun loop (counter:int) (pst:state, graph: abduction_graph) =
8383
if counter < 8
8484
then
8585
let
86-
val _ = tracing ("==== In loop. Counter is: " ^ Int.toString counter ^ " =====");
87-
val ctxt = Proof.context_of pst;
88-
val orkeys_worth_expanding = orkeys_tobe_expanded_in ctxt graph: keys;
89-
val _ = tracing ("The number of keys worth expanding is:" ^ Int.toString (length orkeys_worth_expanding));
90-
val _ = tracing "They are:"
91-
val _ = map (print_key ctxt) orkeys_worth_expanding
92-
val (new_pst, graph_w_keys_expanded) = fold expand_ornode_if_original_goral_is_unproved orkeys_worth_expanding (pst, graph): (state * abduction_graph);
93-
val solved = final_goal_proved_completely graph_w_keys_expanded: bool;
94-
val _ = tracing (if solved then " In loop. Solved." else " In loop. Not solved.")
86+
val _ = tracing ("==== In loop. Counter is: " ^ Int.toString counter ^ " =====");
87+
val ctxt = Proof.context_of pst;
88+
val orkeys_worth_expanding = orkeys_tobe_expanded_in ctxt graph: keys;
89+
val _ = tracing ("The number of keys worth expanding is:" ^ Int.toString (length orkeys_worth_expanding));
90+
val _ = tracing "They are:"
91+
val _ = map (print_key ctxt) orkeys_worth_expanding
92+
val (new_pst, graph_w_keys_expanded) = fold expand_ornode_if_original_goral_is_unproved orkeys_worth_expanding (pst, graph): (state * abduction_graph);
93+
val solved = final_goal_proved_completely graph_w_keys_expanded: bool;
94+
val _ = tracing (if solved then " In loop. Solved." else " In loop. Not solved.")
9595
in
9696
(if solved then K I else loop) (counter + 1) (new_pst, graph_w_keys_expanded)
9797
end

Abduction/Seed_Of_Or2And_Edge.ML

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,13 @@ fun apply_PSL_to_get_seeds_of_or2and_edges (pst:Proof.state) =
8888
map mk_proof_key_value script_n_psts: seeds_of_or2and_edge
8989
end;
9090

91+
(*TODO*)
92+
fun condition_to_filter_out_cnjctr (parent_or:term) (pst:Proof.state) (ag:abduction_graph) (cnjctr:term) = true;
93+
94+
datatype conjecture_typ = Explicit_Conjecturing | Implicit_Conjecturing (*tactic application*);
95+
96+
fun filtering_policy Explicit_Conjecturing = ()
97+
9198
fun condition_to_filter_out (parent_or:term) (pst:Proof.state) (ag:abduction_graph) (seed:seed_of_or2and_edge) =
9299
let
93100
val final_goal = get_final_goal_key ag |> snd |> hd: term;
@@ -120,7 +127,11 @@ fun condition_to_filter_out (parent_or:term) (pst:Proof.state) (ag:abduction_gra
120127
fun terms_have_counter_example_in_prems (pst:Proof.state) (terms:terms) =
121128
exists (has_counter_example_in_prems pst) terms: bool;
122129
in
123-
trms_empty orelse too_large () orelse
130+
(*TODO: for each stage we should filter out either
131+
some of conjectures in a seed (Explicit Conjecturing) or
132+
all conjectures in a seed (Implicit Conjecturing)*)
133+
trms_empty orelse
134+
too_large () orelse
124135
eq_to_final_goal () andalso seed_is_from_tactic seed orelse
125136
concl_is_eq_to_final_goal () (*andalso seed_is_from_tactic seed*) orelse
126137
has_func_with_three_occs_in_a_row () orelse

Abduction/Top_Down_Util.ML

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ val get_lemma_names_from_sh_output : theory -> string -> strings;
3434
val assume_cnjctrs_in_pst : (string * term) list -> Proof.state -> Proof.state;
3535
val is_thm_registered : Proof.context -> string -> bool;
3636
val mk_new_lemma_name : Proof.context -> string;
37+
val term_compare : term * term -> order;
3738

3839
end;
3940

@@ -232,4 +233,7 @@ fun mk_new_lemma_name (ctxt:Proof.context): string =
232233
else candidate_name
233234
end
234235

236+
fun term_compare (trm1, trm2) =
237+
Term_Ord.term_ord (standardize_vnames trm1, standardize_vnames trm2);
238+
235239
end;

0 commit comments

Comments
 (0)