1 (* LOOPING : COL057-1.ma *)
4 () (* prerr_endline s *)
7 let nparamod rdb metasenv subst context t table =
8 let max_nb_iter = 999999999 in
9 let amount_of_time = 300.0 in
11 let metasenv = metasenv
16 let nb_iter = ref 0 in
17 let module B = NCicBlob.NCicBlob(C) in
18 let module Pp = Pp.Pp (B) in
19 let module FU = FoUnif.Founif(B) in
20 let module IDX = Index.Index(B) in
21 let module Sup = Superposition.Superposition(B) in
22 let module Utils = FoUtils.Utils(B) in
24 let module OrderedPassives =
26 type t = B.t Terms.passive_clause
28 let compare = Utils.compare_passive_clauses
31 let module PassiveSet = Set.Make(OrderedPassives)
33 let add_passive_clause passives cl =
34 PassiveSet.add (Utils.mk_passive_clause cl) passives
36 let timeout = Unix.gettimeofday () +. amount_of_time in
37 (* TODO : fairness condition *)
39 if PassiveSet.is_empty passives then None
40 else let cl = PassiveSet.min_elt passives in
41 Some (snd cl,PassiveSet.remove cl passives)
43 let rec given_clause bag maxvar actives
44 passives g_actives g_passives =
45 (* prerr_endline "Bag :"; prerr_endline (Pp.pp_bag bag);
46 prerr_endline "Active table :";
47 (List.iter (fun x -> prerr_endline (Pp.pp_unit_clause x))
49 incr nb_iter; if !nb_iter = max_nb_iter then
50 raise (Failure "No iterations left !");
51 if Unix.gettimeofday () > timeout then
52 raise (Failure "Timeout !");
56 (* superposition left, simplifications on goals *)
57 debug "infer_left step...";
58 let bag, maxvar, g_actives, g_passives =
59 match select g_passives with
60 | None -> bag, maxvar, g_actives, g_passives
61 | Some (g_current, g_passives) ->
62 debug ("Selected goal : " ^ Pp.pp_unit_clause g_current);
64 Sup.simplify_goal maxvar (snd actives) bag g_current
66 debug "Simplified goal";
67 let bag, maxvar, new_goals =
68 Sup.infer_left bag maxvar g_current actives
70 debug "Performed infer_left step";
71 let new_goals = List.fold_left add_passive_clause
72 PassiveSet.empty new_goals
74 bag, maxvar, g_current::g_actives,
75 (PassiveSet.union new_goals g_passives)
78 (Printf.sprintf "Number of active goals : %d"
79 (List.length g_actives));
81 (Printf.sprintf "Number of passive goals : %d"
82 (PassiveSet.cardinal g_passives));
91 * new = supright e'' A'' *
92 * new'= demod A'' new *
94 debug "Forward infer step...";
95 let bag, maxvar, actives, passives, g_passives =
96 let rec aux_simplify passives =
97 match select passives with
98 | None -> assert false
99 | Some (current, passives) ->
100 debug ("Selected fact : " ^ Pp.pp_unit_clause current);
101 match Sup.keep_simplified current actives bag maxvar with
102 (* match Sup.one_pass_simplification current actives bag maxvar with*)
103 | None -> aux_simplify passives
104 | Some x -> x,passives
106 let (current, bag, actives),passives = aux_simplify passives
108 debug ("Fact after simplification :"
109 ^ Pp.pp_unit_clause current);
110 let bag, maxvar, actives, new_clauses =
111 Sup.infer_right bag maxvar current actives
113 debug "Demodulating goals with actives...";
114 (* keep goals demodulated w.r.t. actives and check if solved *)
118 let bag, c = Sup.simplify_goal maxvar (snd actives) bag c in
122 let ctable = IDX.index_unit_clause IDX.DT.empty current in
123 let bag, maxvar, new_goals =
125 (fun (bag,m,acc) g ->
126 let bag, m, ng = Sup.infer_left bag m g
127 ([current],ctable) in
129 (bag,maxvar,[]) g_actives
131 let new_clauses = List.fold_left add_passive_clause
132 PassiveSet.empty new_clauses in
133 let new_goals = List.fold_left add_passive_clause
134 PassiveSet.empty new_goals in
135 bag, maxvar, actives,
136 PassiveSet.union new_clauses passives,
137 PassiveSet.union new_goals g_passives
140 (Printf.sprintf "Number of actives : %d" (List.length (fst actives)));
142 (Printf.sprintf "Number of passives : %d"
143 (PassiveSet.cardinal passives));
144 given_clause bag maxvar actives passives g_actives g_passives
147 let mk_clause bag maxvar (t,ty) =
148 let (proof,ty) = B.saturate t ty in
149 let c, maxvar = Utils.mk_unit_clause maxvar ty proof in
150 let bag, c = Utils.add_to_bag bag c in
153 let bag, maxvar, goal = mk_clause Terms.M.empty 0 t in
154 let g_actives = [] in
155 let g_passives = PassiveSet.singleton (Utils.mk_passive_clause goal) in
156 let passives, bag, maxvar =
158 (fun (cl, bag, maxvar) t ->
159 let bag, maxvar, c = mk_clause bag maxvar t in
160 (add_passive_clause cl c), bag, maxvar)
161 (PassiveSet.empty, bag, maxvar) table
163 let actives = [], IDX.DT.empty in
164 try given_clause bag maxvar actives passives g_actives g_passives
166 | Sup.Success (bag, _, (i,_,_,_)) ->
168 let rec traverse ongoal (accg,acce) i =
169 match Terms.M.find i bag with
170 | (id,_,_,Terms.Exact _) ->
171 if ongoal then [i],acce else
172 if (List.mem i acce) then accg,acce else accg,acce@[i]
173 | (_,_,_,Terms.Step (_,i1,i2,_,_,_)) ->
174 if (not ongoal) && (List.mem i acce) then accg,acce
177 traverse false (traverse ongoal (accg,acce) i1) i2
179 if ongoal then i::accg,acce else accg,i::acce
181 let gsteps,esteps = traverse true ([],[]) i in
182 (List.rev esteps)@gsteps
184 prerr_endline (Printf.sprintf "Found proof in %d iterations, %fs"
186 (Unix.gettimeofday() -. timeout +. amount_of_time));
187 (* prerr_endline "Proof:";
188 List.iter (fun x -> prerr_endline (string_of_int x);
189 prerr_endline (Pp.pp_unit_clause (Terms.M.find x bag))) l;*)
190 let proofterm = B.mk_proof bag i l in
191 prerr_endline (Printf.sprintf "Got proof term, %fs"
192 (Unix.gettimeofday() -. timeout +. amount_of_time));
193 let metasenv, proofterm =
194 let rec aux k metasenv = function
195 | NCic.Meta _ as t -> metasenv, t
197 let metasenv,i,_,_=NCicMetaSubst.mk_meta metasenv context `Term in
198 metasenv, NCic.Meta (i,(k,NCic.Irl (List.length context)))
199 | t -> NCicUntrusted.map_term_fold_a
200 (fun _ k -> k+1) k aux metasenv t
202 aux 0 metasenv proofterm
204 let metasenv, subst, proofterm, _prooftype =
206 (rdb#set_coerc_db NCicCoercion.empty_db)
207 metasenv subst context proofterm None
209 proofterm, metasenv, subst
210 | Failure _ -> prerr_endline
211 (Printf.sprintf "FAILURE in %d iterations" !nb_iter); assert false