1 (*let nparamod metasenv subst context t table =
2 prerr_endline "========================================";
4 let metasenv = metasenv
9 let module B = NCicBlob.NCicBlob(C) in
10 let module Pp = Pp.Pp (B) in
11 let module FU = FoUnif.Founif(B) in
12 let module IDX = Index.Index(B) in
13 let module Sup = Superposition.Superposition(B) in
14 let module Utils = FoUtils.Utils(B) in*)
16 let test_unification _ = function
17 | Terms.Node [_; _; lhs; rhs] ->
18 prerr_endline "Unification test :";
19 prerr_endline (Pp.pp_foterm lhs);
20 prerr_endline (Pp.pp_foterm rhs);
21 FU.unification [] [] lhs rhs
24 let subst,vars = test_unification [] res in
25 prerr_endline "Result :";
26 prerr_endline (Pp.pp_foterm res);
27 prerr_endline "Substitution :";
28 prerr_endline (Pp.pp_substitution subst)
32 let mk_clause maxvar t =
34 let proof = B.embed (NCic.Rel ~-1) in
35 Utils.mk_unit_clause maxvar ty proof
37 let clause, maxvar = mk_clause 0 t in
38 prerr_endline "Input clause :";
39 prerr_endline (Pp.pp_unit_clause clause);
40 let bag = Utils.empty_bag in
41 let active_clauses, maxvar =
44 let c, m = mk_clause maxvar t in
49 List.fold_left IDX.index_unit_clause IDX.DT.empty active_clauses
51 prerr_endline "Active table:";
52 List.iter (fun uc -> prerr_endline (Pp.pp_unit_clause uc)) active_clauses;
53 let bag, maxvar, _, newclauses =
54 Sup.infer_right bag maxvar clause (active_clauses, table)
56 prerr_endline "Output clauses :";
57 List.iter (fun c -> prerr_endline (Pp.pp_unit_clause c)) newclauses;
58 (* prerr_endline "Proofs: ";
59 prerr_endline (Pp.pp_bag bag); *)
60 prerr_endline "========================================";
67 let nparamod metasenv subst context t table =
68 prerr_endline "========================================";
70 let metasenv = metasenv
75 let module B = NCicBlob.NCicBlob(C) in
76 let module Pp = Pp.Pp (B) in
77 let module FU = FoUnif.Founif(B) in
78 let module IDX = Index.Index(B) in
79 let module Sup = Superposition.Superposition(B) in
80 let module Utils = FoUtils.Utils(B) in
82 let module OrderedPassives =
84 type t = B.t Terms.passive_clause
86 let compare = Utils.compare_passive_clauses
89 let module PassiveSet = Set.Make(OrderedPassives)
91 let add_passive_clause passives cl =
92 PassiveSet.add (Utils.mk_passive_clause cl) passives
94 (* TODO : fairness condition *)
96 if PassiveSet.is_empty passives then None
97 else let cl = PassiveSet.min_elt passives in
98 Some (snd cl,PassiveSet.remove cl passives)
100 let rec given_clause bag maxvar actives passives g_actives g_passives =
102 (* keep goals demodulated w.r.t. actives and check if solved *)
103 (* we may move this at the end of infer_right and simplify with
104 * just new_clauses *)
108 let bag, c = Sup.backward_simplify maxvar (snd actives) bag c in
113 (* backward step : superposition left, simplifications on goals *)
114 debug "Backward infer step...";
115 let bag, maxvar, g_actives, g_passives =
116 match select g_passives with
117 | None -> bag, maxvar, g_actives, g_passives
118 | Some (g_current, g_passives) ->
119 debug ("Selected goal : " ^ Pp.pp_unit_clause g_current);
121 Sup.backward_simplify maxvar (snd actives) bag g_current
123 let bag, maxvar, new_goals =
124 Sup.infer_left bag maxvar g_current actives
126 let new_goals = List.fold_left add_passive_clause
127 PassiveSet.empty new_goals
129 bag, maxvar, g_current::g_actives,
130 (PassiveSet.union new_goals g_passives)
133 (Printf.sprintf "Number of active goals : %d"
134 (List.length g_actives));
136 (Printf.sprintf "Number of passive goals : %d"
137 (PassiveSet.cardinal g_passives));
143 * A' = demod [e'] A *
146 * new = supright e'' A'' *
147 * new'= demod A'' new *
149 debug "Forward infer step...";
150 let bag, maxvar, actives, passives, g_passives =
151 match select passives with
152 | None -> bag, maxvar, actives, passives, g_passives
153 | Some (current, passives) ->
154 debug ("Selected fact : " ^ Pp.pp_unit_clause current);
155 match Sup.forward_simplify (snd actives) bag current with
156 | None -> debug ("Discarded fact");
157 bag, maxvar, actives, passives, g_passives
158 | Some (bag, current) ->
159 debug ("Fact after simplification :" ^ Pp.pp_unit_clause current);
160 let bag, maxvar, actives, new_clauses =
161 Sup.infer_right bag maxvar current actives
163 let ctable = IDX.index_unit_clause IDX.DT.empty current in
164 let bag, maxvar, new_goals =
166 (fun (bag,m,acc) g ->
167 let bag, m, ng = Sup.infer_left bag maxvar g
168 ([current],ctable) in
170 (bag,maxvar,[]) g_actives
172 let new_clauses = List.fold_left add_passive_clause
173 PassiveSet.empty new_clauses in
174 let new_goals = List.fold_left add_passive_clause
175 PassiveSet.empty new_goals in
176 bag, maxvar, actives,
177 PassiveSet.union new_clauses passives,
178 PassiveSet.union new_goals g_passives
181 (Printf.sprintf "Number of actives : %d" (List.length (fst actives)));
183 (Printf.sprintf "Number of passives : %d"
184 (PassiveSet.cardinal passives));
185 given_clause bag maxvar actives passives g_actives g_passives
188 let mk_clause bag maxvar (t,ty) =
189 let (proof,ty) = B.saturate t ty in
190 let c, maxvar = Utils.mk_unit_clause maxvar ty proof in
191 let bag, c = Utils.add_to_bag bag c in
194 let bag, maxvar, goal = mk_clause Terms.M.empty 0 t in
195 let g_actives = [] in
196 let g_passives = PassiveSet.singleton (Utils.mk_passive_clause goal) in
197 let passives, bag, maxvar =
199 (fun (cl, bag, maxvar) t ->
200 let bag, maxvar, c = mk_clause bag maxvar t in
201 (add_passive_clause cl c), bag, maxvar)
202 (PassiveSet.empty, bag, maxvar) table
204 let actives = [], IDX.DT.empty in
205 try given_clause bag maxvar actives passives g_actives g_passives
206 with Sup.Success (bag, _, mp) ->
207 prerr_endline "YES!";
208 prerr_endline "Meeting point :"; prerr_endline (Pp.pp_unit_clause mp);
209 (* prerr_endline "Bag :"; prerr_endline (Pp.pp_bag bag) *)