2 () (* prerr_endline s *)
5 let nparamod rdb metasenv subst context t table =
6 let nb_iter = ref 200 in
7 let amount_of_time = 20.0 in
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 let timeout = Unix.gettimeofday () +. amount_of_time in
34 (* TODO : fairness condition *)
36 if PassiveSet.is_empty passives then None
37 else let cl = PassiveSet.min_elt passives in
38 Some (snd cl,PassiveSet.remove cl passives)
40 let rec given_clause bag maxvar actives
41 passives g_actives g_passives =
43 decr nb_iter; if !nb_iter = 0 then
44 (*(prerr_endline "Bag :"; prerr_endline (Pp.pp_bag bag);
45 prerr_endline "Active table :";
46 (List.iter (fun x -> prerr_endline (Pp.pp_unit_clause x))
48 raise (Failure "No iterations left !");
49 if Unix.gettimeofday () > timeout then
50 raise (Failure "Timeout !");
54 (* superposition left, simplifications on goals *)
55 debug "infer_left step...";
56 let bag, maxvar, g_actives, g_passives =
57 match select g_passives with
58 | None -> bag, maxvar, g_actives, g_passives
59 | Some (g_current, g_passives) ->
60 debug ("Selected goal : " ^ Pp.pp_unit_clause g_current);
62 Sup.simplify_goal maxvar (snd actives) bag g_current
64 let bag, maxvar, new_goals =
65 Sup.infer_left bag maxvar g_current actives
67 let new_goals = List.fold_left add_passive_clause
68 PassiveSet.empty new_goals
70 bag, maxvar, g_current::g_actives,
71 (PassiveSet.union new_goals g_passives)
74 (Printf.sprintf "Number of active goals : %d"
75 (List.length g_actives));
77 (Printf.sprintf "Number of passive goals : %d"
78 (PassiveSet.cardinal g_passives));
87 * new = supright e'' A'' *
88 * new'= demod A'' new *
90 debug "Forward infer step...";
91 let bag, maxvar, actives, passives, g_passives =
92 let rec aux_simplify passives =
93 match select passives with
94 | None -> assert false
95 | Some (current, passives) ->
96 debug ("Selected fact : " ^ Pp.pp_unit_clause current);
97 (* match Sup.keep_simplified current actives bag maxvar with *)
98 match Sup.one_pass_simplification current actives bag maxvar with
99 | None -> aux_simplify passives
100 | Some x -> x,passives
102 let (current, bag, actives),passives = aux_simplify passives
104 debug ("Fact after simplification :"
105 ^ Pp.pp_unit_clause current);
106 let bag, maxvar, actives, new_clauses =
107 Sup.infer_right bag maxvar current actives
109 debug "Demodulating goals with actives...";
110 (* keep goals demodulated w.r.t. actives and check if solved *)
114 let bag, c = Sup.simplify_goal maxvar (snd actives) bag c in
118 let ctable = IDX.index_unit_clause IDX.DT.empty current in
119 let bag, maxvar, new_goals =
121 (fun (bag,m,acc) g ->
122 let bag, m, ng = Sup.infer_left bag maxvar g
123 ([current],ctable) in
125 (bag,maxvar,[]) g_actives
127 let new_clauses = List.fold_left add_passive_clause
128 PassiveSet.empty new_clauses in
129 let new_goals = List.fold_left add_passive_clause
130 PassiveSet.empty new_goals in
131 bag, maxvar, actives,
132 PassiveSet.union new_clauses passives,
133 PassiveSet.union new_goals g_passives
136 (Printf.sprintf "Number of actives : %d" (List.length (fst actives)));
138 (Printf.sprintf "Number of passives : %d"
139 (PassiveSet.cardinal passives));
140 given_clause bag maxvar actives passives g_actives g_passives
143 let mk_clause bag maxvar (t,ty) =
144 let (proof,ty) = B.saturate t ty in
145 let c, maxvar = Utils.mk_unit_clause maxvar ty proof in
146 let bag, c = Utils.add_to_bag bag c in
149 let bag, maxvar, goal = mk_clause Terms.M.empty 0 t in
150 let g_actives = [] in
151 let g_passives = PassiveSet.singleton (Utils.mk_passive_clause goal) in
152 let passives, bag, maxvar =
154 (fun (cl, bag, maxvar) t ->
155 let bag, maxvar, c = mk_clause bag maxvar t in
156 (add_passive_clause cl c), bag, maxvar)
157 (PassiveSet.empty, bag, maxvar) table
159 let actives = [], IDX.DT.empty in
160 try given_clause bag maxvar actives passives g_actives g_passives
162 | Sup.Success (bag, _, (i,_,_,_)) ->
165 HTopoSort.Make(struct type t=int let compare=Pervasives.compare end)
167 let module C : Set.S with type elt = int =
168 Set.Make(struct type t=int let compare=Pervasives.compare end)
171 let rec traverse ongoal (accg,acce) i =
172 match Terms.M.find i bag with
173 | (_,_,_,Terms.Exact _) -> accg, acce
174 | (_,_,_,Terms.Step (_,i1,i2,_,_,_)) ->
176 if ongoal then C.add i1 accg, acce
177 else accg, C.add i1 acce
179 let acce = C.add i2 acce in
180 traverse false (traverse ongoal (accg,acce) i1) i2
182 traverse true (C.empty,C.empty) id
185 S.topological_sort (C.elements (snd (all i)))
186 (fun i -> C.elements (C.union (snd (all i)) (fst (all i)) ))
189 S.topological_sort (C.elements (fst (all i)))
190 (fun i -> C.elements (fst (all i)))
192 let gsteps = List.rev gsteps in
196 prerr_endline "Proof:";
197 List.iter (fun x -> prerr_endline (string_of_int x);
198 prerr_endline (Pp.pp_unit_clause (Terms.M.find x bag))) l;
200 let proofterm = B.mk_proof bag i l in
201 let metasenv, proofterm =
202 let rec aux k metasenv = function
203 | NCic.Meta _ as t -> metasenv, t
205 let metasenv,i,_,_=NCicMetaSubst.mk_meta metasenv context `Term in
206 metasenv, NCic.Meta (i,(k,NCic.Irl (List.length context)))
207 | t -> NCicUntrusted.map_term_fold_a
208 (fun _ k -> k+1) k aux metasenv t
210 aux 0 metasenv proofterm
212 let metasenv, subst, proofterm, _prooftype =
214 (rdb#set_coerc_db NCicCoercion.empty_db)
215 metasenv subst context proofterm None
217 proofterm, metasenv, subst
218 | Failure _ -> prerr_endline "FAILURE"; assert false