2 () (* prerr_endline s *)
5 let nparamod rdb metasenv subst context t table =
6 let nb_iter = ref 200 in
7 prerr_endline "========================================";
9 let metasenv = metasenv
14 let module B = NCicBlob.NCicBlob(C) in
15 let module Pp = Pp.Pp (B) in
16 let module FU = FoUnif.Founif(B) in
17 let module IDX = Index.Index(B) in
18 let module Sup = Superposition.Superposition(B) in
19 let module Utils = FoUtils.Utils(B) in
21 let module OrderedPassives =
23 type t = B.t Terms.passive_clause
25 let compare = Utils.compare_passive_clauses
28 let module PassiveSet = Set.Make(OrderedPassives)
30 let add_passive_clause passives cl =
31 PassiveSet.add (Utils.mk_passive_clause cl) passives
33 (* TODO : fairness condition *)
35 if PassiveSet.is_empty passives then None
36 else let cl = PassiveSet.min_elt passives in
37 Some (snd cl,PassiveSet.remove cl passives)
39 let rec given_clause bag maxvar actives
40 passives g_actives g_passives =
42 decr nb_iter; if !nb_iter = 0 then
43 (*(prerr_endline "Bag :"; prerr_endline (Pp.pp_bag bag);
44 prerr_endline "Active table :";
45 (List.iter (fun x -> prerr_endline (Pp.pp_unit_clause x))
47 raise (Failure "Timeout !");
51 (* superposition left, simplifications on goals *)
52 debug "infer_left step...";
53 let bag, maxvar, g_actives, g_passives =
54 match select g_passives with
55 | None -> bag, maxvar, g_actives, g_passives
56 | Some (g_current, g_passives) ->
57 debug ("Selected goal : " ^ Pp.pp_unit_clause g_current);
59 Sup.simplify_goal maxvar (snd actives) bag g_current
61 let bag, maxvar, new_goals =
62 Sup.infer_left bag maxvar g_current actives
64 let new_goals = List.fold_left add_passive_clause
65 PassiveSet.empty new_goals
67 bag, maxvar, g_current::g_actives,
68 (PassiveSet.union new_goals g_passives)
71 (Printf.sprintf "Number of active goals : %d"
72 (List.length g_actives));
74 (Printf.sprintf "Number of passive goals : %d"
75 (PassiveSet.cardinal g_passives));
84 * new = supright e'' A'' *
85 * new'= demod A'' new *
87 debug "Forward infer step...";
88 let bag, maxvar, actives, passives, g_passives =
89 let rec aux_simplify passives =
90 match select passives with
91 | None -> assert false
92 | Some (current, passives) ->
93 debug ("Selected fact : " ^ Pp.pp_unit_clause current);
94 match Sup.keep_simplified current actives bag with
95 (* match Sup.one_pass_simplification current actives bag with *)
96 | None -> aux_simplify passives
97 | Some x -> x,passives
99 let (current, bag, actives),passives = aux_simplify passives
101 debug ("Fact after simplification :"
102 ^ Pp.pp_unit_clause current);
103 let bag, maxvar, actives, new_clauses =
104 Sup.infer_right bag maxvar current actives
106 debug "Demodulating goals with actives...";
107 (* keep goals demodulated w.r.t. actives and check if solved *)
111 let bag, c = Sup.simplify_goal maxvar (snd actives) bag c in
115 let ctable = IDX.index_unit_clause IDX.DT.empty current in
116 let bag, maxvar, new_goals =
118 (fun (bag,m,acc) g ->
119 let bag, m, ng = Sup.infer_left bag maxvar g
120 ([current],ctable) in
122 (bag,maxvar,[]) g_actives
124 let new_clauses = List.fold_left add_passive_clause
125 PassiveSet.empty new_clauses in
126 let new_goals = List.fold_left add_passive_clause
127 PassiveSet.empty new_goals in
128 bag, maxvar, actives,
129 PassiveSet.union new_clauses passives,
130 PassiveSet.union new_goals g_passives
133 (Printf.sprintf "Number of actives : %d" (List.length (fst actives)));
135 (Printf.sprintf "Number of passives : %d"
136 (PassiveSet.cardinal passives));
137 given_clause bag maxvar actives passives g_actives g_passives
140 let mk_clause bag maxvar (t,ty) =
141 let (proof,ty) = B.saturate t ty in
142 let c, maxvar = Utils.mk_unit_clause maxvar ty proof in
143 let bag, c = Utils.add_to_bag bag c in
146 let bag, maxvar, goal = mk_clause Terms.M.empty 0 t in
147 let g_actives = [] in
148 let g_passives = PassiveSet.singleton (Utils.mk_passive_clause goal) in
149 let passives, bag, maxvar =
151 (fun (cl, bag, maxvar) t ->
152 let bag, maxvar, c = mk_clause bag maxvar t in
153 (add_passive_clause cl c), bag, maxvar)
154 (PassiveSet.empty, bag, maxvar) table
156 let actives = [], IDX.DT.empty in
157 try given_clause bag maxvar actives passives g_actives g_passives
159 | Sup.Success (bag, _, (i,_,_,_)) ->
162 HTopoSort.Make(struct type t=int let compare=Pervasives.compare end)
164 let module C : Set.S with type elt = int =
165 Set.Make(struct type t=int let compare=Pervasives.compare end)
168 let rec traverse acc i =
169 match Terms.M.find i bag with
170 | (_,_,_,Terms.Exact _) -> acc
171 | (_,_,_,Terms.Step (_,i1,i2,_,_,_)) ->
172 traverse (traverse (C.add i1 (C.add i2 acc)) i1) i2
174 C.elements (traverse C.empty id)
176 S.topological_sort (all i) all
178 prerr_endline "YES!";
179 prerr_endline "Proof:";
181 prerr_endline (Pp.pp_unit_clause (Terms.M.find x bag))) l;
182 let proofterm = B.mk_proof bag l in
184 (NCicPp.ppterm ~metasenv:C.metasenv ~subst:C.subst ~context:C.context
186 let _metasenv, _subst, _proofterm, _prooftype =
187 NCicRefiner.typeof rdb C.metasenv C.subst C.context proofterm None
190 | Failure _ -> prerr_endline "FAILURE";