1 (* Copyright (C) 2005, HELM Team.
3 * This file is part of HELM, an Hypertextual, Electronic
4 * Library of Mathematics, developed at the Computer Science
5 * Department, University of Bologna, Italy.
7 * HELM is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
12 * HELM is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with HELM; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
22 * For details, see the HELM World-Wide-Web page,
23 * http://cs.unibo.it/helm/.
26 (* let _profiler = <:profiler<_profiler>>;; *)
30 (* set to false to disable paramodulation inside auto_tac *)
35 let connect_to_auto = true;;
37 let debug_print = Utils.debug_print;;
39 (* profiling statistics... *)
40 let infer_time = ref 0.;;
41 let forward_simpl_time = ref 0.;;
42 let forward_simpl_new_time = ref 0.;;
43 let backward_simpl_time = ref 0.;;
44 let passive_maintainance_time = ref 0.;;
46 (* limited-resource-strategy related globals *)
47 let processed_clauses = ref 0;; (* number of equalities selected so far... *)
48 let time_limit = ref 0.;; (* in seconds, settable by the user... *)
49 let start_time = ref 0.;; (* time at which the execution started *)
50 let elapsed_time = ref 0.;;
51 (* let maximal_weight = ref None;; *)
52 let maximal_retained_equality = ref None;;
54 (* equality-selection related globals *)
55 let use_fullred = ref true;;
56 let weight_age_ratio = ref 6 (* 5 *);; (* settable by the user *)
57 let weight_age_counter = ref !weight_age_ratio ;;
58 let symbols_ratio = ref 0 (* 3 *);;
59 let symbols_counter = ref 0;;
61 (* non-recursive Knuth-Bendix term ordering by default *)
62 (* Utils.compare_terms := Utils.rpo;; *)
63 (* Utils.compare_terms := Utils.nonrec_kbo;; *)
64 (* Utils.compare_terms := Utils.ao;; *)
67 let derived_clauses = ref 0;;
68 let kept_clauses = ref 0;;
70 (* varbiables controlling the search-space *)
71 let maxdepth = ref 3;;
72 let maxwidth = ref 3;;
74 type theorem = Cic.term * Cic.term * Cic.metasenv;;
76 let symbols_of_equality equality =
77 let (_, _, (_, left, right, _), _,_) = Equality.open_equality equality in
78 let m1 = Utils.symbols_of_term left in
83 let c = Utils.TermMap.find k res in
84 Utils.TermMap.add k (c+v) res
86 Utils.TermMap.add k v res)
87 (Utils.symbols_of_term right) m1
93 module OrderedEquality = struct
94 type t = Equality.equality
97 match Equality.meta_convertibility_eq eq1 eq2 with
100 let w1, _, (ty,left, right, _), m1,_ = Equality.open_equality eq1 in
101 let w2, _, (ty',left', right', _), m2,_ = Equality.open_equality eq2 in
102 match Pervasives.compare w1 w2 with
104 let res = (List.length m1) - (List.length m2) in
105 if res <> 0 then res else
106 Equality.compare eq1 eq2
110 module EqualitySet = Set.Make(OrderedEquality);;
112 type passive_table = Equality.equality list * EqualitySet.t * Indexing.Index.t
113 type active_table = Equality.equality list * Indexing.Index.t
115 Equality.goal_proof * Equality.proof * int * Subst.substitution * Cic.metasenv
117 | ParamodulationFailure of
118 string * active_table * passive_table * Equality.equality_bag
119 | ParamodulationSuccess of
120 new_proof * active_table * passive_table * Equality.equality_bag
123 let list_of_passive (l,_,_) = l ;;
124 let list_of_active (l,_) = l ;;
126 let make_passive eq_list =
128 List.fold_left (fun s e -> EqualitySet.add e s) EqualitySet.empty eq_list
130 (* we have the invariant that the list and the set have the same
132 EqualitySet.elements set, set,
133 List.fold_left Indexing.index Indexing.empty eq_list
136 let make_empty_active () = [], Indexing.empty ;;
137 let make_active eq_list =
138 eq_list, List.fold_left Indexing.index Indexing.empty eq_list
141 let size_of_passive (passive_list, _,_) = List.length passive_list;;
142 let size_of_active (active_list, _) = List.length active_list;;
144 let passive_is_empty = function
145 | [], s , _ when EqualitySet.is_empty s -> true
146 | [], s ,_ -> assert false (* the set and the list should be in sync *)
150 type goals = Equality.goal list * Equality.goal list
152 let no_more_passive_goals g = match g with | _,[] -> true | _ -> false;;
155 let age_factor = 0.01;;
158 selects one equality from passive. The selection strategy is a combination
159 of weight, age and goal-similarity
162 let rec select env g passive =
163 processed_clauses := !processed_clauses + 1;
166 match (List.rev goals) with goal::_ -> goal | _ -> assert false
169 let pos_list, pos_set, pos_table = passive in
170 let remove eq l = List.filter (fun e -> Equality.compare e eq <> 0) l in
171 if !weight_age_ratio > 0 then
172 weight_age_counter := !weight_age_counter - 1;
173 match !weight_age_counter with
175 weight_age_counter := !weight_age_ratio;
176 let skip_giant pos_list pos_set pos_table =
178 | (hd:EqualitySet.elt)::tl ->
179 let w,_,_,_,_ = Equality.open_equality hd in
181 hd, (tl, EqualitySet.remove hd pos_set,
182 Indexing.remove_index pos_table hd)
186 ("+++ skipping giant of size "^string_of_int w^" +++");
188 select env g (tl@[hd],pos_set,pos_table)
191 skip_giant pos_list pos_set pos_table)
194 let rec skip_giant pos_list pos_set =
196 | (hd:EqualitySet.elt)::tl ->
197 let w,_,_,_,_ = Equality.open_equality hd in
198 let pos_set = EqualitySet.remove hd pos_set in
203 ("+++ skipping giant of size "^string_of_int w^" +++");
204 skip_giant tl pos_set)
207 skip_giant pos_list pos_set)
211 | _ when (!symbols_counter > 0) ->
212 (symbols_counter := !symbols_counter - 1;
213 let cardinality map =
214 Utils.TermMap.fold (fun k v res -> res + v) map 0
217 let _, _, term = goal in
218 Utils.symbols_of_term term
220 let card = cardinality symbols in
221 let foldfun k v (r1, r2) =
222 if Utils.TermMap.mem k symbols then
223 let c = Utils.TermMap.find k symbols in
224 let c1 = abs (c - v) in
230 let f equality (i, e) =
232 Utils.TermMap.fold foldfun (symbols_of_equality equality) (0, 0)
234 let c = others + (abs (common - card)) in
235 if c < i then (c, equality)
238 let e1 = EqualitySet.min_elt pos_set in
241 Utils.TermMap.fold foldfun (symbols_of_equality e1) (0, 0)
243 (others + (abs (common - card))), e1
245 let _, current = EqualitySet.fold f pos_set initial in
247 (remove current pos_list, EqualitySet.remove current pos_set))
250 symbols_counter := !symbols_ratio;
252 let w1,_,_,_,_ = Equality.open_equality e1 in
253 let w2,_,_,_,_ = Equality.open_equality e2 in
254 if w1 < w2 then e1 else e2
256 let rec my_min_elt min = function
258 | hd::tl -> my_min_elt (my_min hd min) tl
260 (* let current = EqualitySet.min_elt pos_set in *)
261 let current = my_min_elt (List.hd pos_list) (List.tl pos_list) in
262 current,(remove current pos_list, EqualitySet.remove current pos_set,
263 Indexing.remove_index pos_table current)
267 let filter_dependent bag passive id =
268 let pos_list, pos_set, pos_table = passive in
269 let passive,no_pruned =
271 (fun eq ((list,set,table),no) ->
272 if Equality.depend bag eq id then
273 (list, EqualitySet.remove eq set,Indexing.remove_index table eq),
276 (eq::list,set,table), no)
277 pos_list (([],pos_set,pos_table),0)
280 if no_pruned > 0 then
281 prerr_endline ("+++ pruning "^ string_of_int no_pruned ^" passives +++");
287 (* adds to passive a list of equalities new_pos *)
288 let add_to_passive passive new_pos preferred =
289 let pos_list, pos_set , pos_table = passive in
290 let ok set equality = not (EqualitySet.mem equality set) in
291 let pos = List.filter (ok pos_set) new_pos in
292 let add set equalities =
293 List.fold_left (fun s e -> EqualitySet.add e s) set equalities
295 let pos_head, pos_tail =
297 (fun e -> List.exists (fun x -> Equality.compare x e = 0) preferred)
300 pos_head @ pos_list @ pos_tail, add pos_set pos,
301 List.fold_left Indexing.index pos_table pos
305 (* removes from passive equalities that are estimated impossible to activate
306 within the current time limit *)
307 let prune_passive howmany (active, _) passive =
308 let (pl, ps), tbl = passive in
309 let howmany = float_of_int howmany
310 and ratio = float_of_int !weight_age_ratio in
313 int_of_float (if t -. v < 0.5 then t else v)
315 let in_weight = round (howmany *. ratio /. (ratio +. 1.))
316 and in_age = round (howmany /. (ratio +. 1.)) in
318 (lazy (Printf.sprintf "in_weight: %d, in_age: %d\n" in_weight in_age));
319 let counter = ref !symbols_ratio in
324 counter := !counter - 1;
325 if !counter = 0 then counter := !symbols_ratio in
326 let e = EqualitySet.min_elt ps in
327 let ps' = pickw (w-1) (EqualitySet.remove e ps) in
328 EqualitySet.add e ps'
330 let e = EqualitySet.min_elt ps in
331 let ps' = pickw (w-1) (EqualitySet.remove e ps) in
332 EqualitySet.add e ps'
336 let ps = pickw in_weight ps in
337 let rec picka w s l =
341 | hd::tl when not (EqualitySet.mem hd s) ->
342 let w, s, l = picka (w-1) s tl in
343 w, EqualitySet.add hd s, hd::l
345 let w, s, l = picka w s tl in
350 let _, ps, pl = picka in_age ps pl in
351 if not (EqualitySet.is_empty ps) then
352 maximal_retained_equality := Some (EqualitySet.max_elt ps);
355 (fun e tbl -> Indexing.index tbl e) ps Indexing.empty
361 (** inference of new equalities between current and some in active *)
362 let infer bag eq_uri env current (active_list, active_table) =
364 if Utils.debug_metas then
365 (ignore(Indexing.check_target bag c current "infer1");
366 ignore(List.map (function current -> Indexing.check_target bag c current "infer2") active_list));
368 let bag, copy_of_current = Equality.fix_metas bag current in
369 let active_table = Indexing.index active_table copy_of_current in
370 (* let _ = <:start<current contro active>> in *)
372 Indexing.superposition_right bag eq_uri env active_table current
374 (* let _ = <:stop<current contro active>> in *)
375 if Utils.debug_metas then
378 Indexing.check_target bag c current "sup0") res);
379 let rec infer_positive bag table = function
383 Indexing.superposition_right bag
384 ~subterms_only:true eq_uri env table equality
386 if Utils.debug_metas then
390 Indexing.check_target bag c current "sup2") res);
391 let bag, pos = infer_positive bag table tl in
394 let curr_table = Indexing.index Indexing.empty current in
395 let bag, pos = infer_positive bag curr_table ((*copy_of_current::*)active_list) in
396 if Utils.debug_metas then
399 Indexing.check_target bag c current "sup3") pos);
402 derived_clauses := !derived_clauses + (List.length new_pos);
403 match !maximal_retained_equality with
404 | None -> bag, new_pos
406 ignore(assert false);
407 (* if we have a maximal_retained_equality, we can discard all equalities
408 "greater" than it, as they will never be reached... An equality is
409 greater than maximal_retained_equality if it is bigger
410 wrt. OrderedEquality.compare and it is less similar than
411 maximal_retained_equality to the current goal *)
412 bag, List.filter (fun e -> OrderedEquality.compare e eq <= 0) new_pos
415 let check_for_deep_subsumption env active_table eq =
416 let _,_,(eq_ty, left, right, order),metas,id = Equality.open_equality eq in
417 let check_subsumed deep l r =
419 Equality.mk_tmp_equality(0,(eq_ty,l,r,Utils.Incomparable),metas)in
420 match Indexing.subsumption env active_table eqtmp with
424 let rec aux b (ok_so_far, subsumption_used) t1 t2 =
426 | t1, t2 when not ok_so_far -> ok_so_far, subsumption_used
427 | t1, t2 when subsumption_used -> t1 = t2, subsumption_used
428 | Cic.Appl (h1::l),Cic.Appl (h2::l') ->
429 let rc = check_subsumed b t1 t2 in
435 (fun (ok_so_far, subsumption_used) t t' ->
436 aux true (ok_so_far, subsumption_used) t t')
437 (ok_so_far, subsumption_used) l l'
438 with Invalid_argument _ -> false,subsumption_used)
440 false, subsumption_used
441 | _ -> false, subsumption_used
443 fst (aux false (true,false) left right)
446 (** simplifies current using active and passive *)
447 let forward_simplify bag eq_uri env current (active_list, active_table) =
448 let _, context, _ = env in
449 let demodulate bag table current =
450 let bag, newcurrent =
451 Indexing.demodulation_equality bag eq_uri env table current
453 bag, if Equality.is_identity env newcurrent then None else Some newcurrent
455 let demod bag current =
456 if Utils.debug_metas then
457 ignore (Indexing.check_target bag context current "demod0");
458 let bag, res = demodulate bag active_table current in
459 if Utils.debug_metas then
460 ignore ((function None -> () | Some x ->
461 ignore (Indexing.check_target bag context x "demod1");()) res);
464 let bag, res = demod bag current in
468 if Indexing.in_index active_table c ||
469 check_for_deep_subsumption env active_table c
476 (** simplifies new using active and passive *)
477 let forward_simplify_new bag eq_uri env new_pos active =
478 if Utils.debug_metas then
482 (fun current -> Indexing.check_target bag c current "forward new pos")
485 let active_list, active_table = active in
486 let demodulate bag table target =
488 Indexing.demodulation_equality bag eq_uri env table target
492 (* we could also demodulate using passive. Currently we don't *)
494 List.fold_right (fun x (bag,acc) ->
495 let bag, y = demodulate bag active_table x in
502 if not (Equality.is_identity env e) then
505 EqualitySet.empty new_pos
507 let new_pos = EqualitySet.elements new_pos_set in
508 let subs e = Indexing.subsumption env active_table e = None in
509 let is_duplicate e = not (Indexing.in_index active_table e) in
510 bag, List.filter subs (List.filter is_duplicate new_pos)
514 (** simplifies a goal with equalities in active and passive *)
515 let rec simplify_goal bag env goal (active_list, active_table) =
516 let demodulate table goal = Indexing.demodulation_goal bag env table goal in
517 let changed, goal = demodulate active_table goal in
522 snd (simplify_goal bag env goal (active_list, active_table))
526 let simplify_goals bag env goals active =
527 let a_goals, p_goals = goals in
528 let p_goals = List.map (fun g -> snd (simplify_goal bag env g active)) p_goals in
529 let a_goals = List.map (fun g -> snd (simplify_goal bag env g active)) a_goals in
534 (** simplifies active usign new *)
535 let backward_simplify_active
536 bag eq_uri env new_pos new_table min_weight active
538 let active_list, active_table = active in
539 let bag, active_list, newa, pruned =
541 (fun equality (bag, res, newn,pruned) ->
542 let ew, _, _, _,id = Equality.open_equality equality in
543 if ew < min_weight then
544 bag, equality::res, newn,pruned
547 forward_simplify bag eq_uri env equality (new_pos, new_table)
549 | bag, None -> bag, res, newn, id::pruned
551 if Equality.compare equality e = 0 then
552 bag, e::res, newn, pruned
554 bag, res, e::newn, pruned)
555 active_list (bag, [], [],[])
558 List.exists (Equality.meta_convertibility_eq eq1) where
561 let _, _, _, _,id = Equality.open_equality eq in id
563 let ((active1,pruned),tbl), newa =
565 (fun eq ((res,pruned), tbl) ->
566 if List.mem eq res then
567 (res, (id_of_eq eq)::pruned),tbl
568 else if (Equality.is_identity env eq) || (find eq res) then (
569 (res, (id_of_eq eq)::pruned),tbl
572 (eq::res,pruned), Indexing.index tbl eq)
573 active_list (([],pruned), Indexing.empty),
576 if (Equality.is_identity env eq) then p
581 | [] -> bag, (active1,tbl), None, pruned
582 | _ -> bag, (active1,tbl), Some newa, pruned
586 (** simplifies passive using new *)
587 let backward_simplify_passive
588 bag eq_uri env new_pos new_table min_weight passive
590 let (pl, ps), passive_table = passive in
591 let f bag equality (resl, ress, newn) =
592 let ew, _, _, _ , _ = Equality.open_equality equality in
593 if ew < min_weight then
594 bag, (equality::resl, ress, newn)
597 forward_simplify bag eq_uri env equality (new_pos, new_table)
600 bag, (resl, EqualitySet.remove equality ress, newn)
603 bag, (equality::resl, ress, newn)
605 let ress = EqualitySet.remove equality ress in
606 bag, (resl, ress, e::newn)
608 let bag, (pl, ps, newp) =
609 List.fold_right (fun x (bag,acc) -> f bag x acc) pl (bag,([], ps, [])) in
612 (fun tbl e -> Indexing.index tbl e) Indexing.empty pl
615 | [] -> bag, ((pl, ps), passive_table), None
616 | _ -> bag, ((pl, ps), passive_table), Some (newp)
619 let build_table equations =
622 let ew, _, _, _ , _ = Equality.open_equality e in
623 e::l, Indexing.index t e, min ew w)
624 ([], Indexing.empty, 1000000) equations
628 let backward_simplify bag eq_uri env new' active =
629 let new_pos, new_table, min_weight = build_table new' in
630 let bag, active, newa, pruned =
631 backward_simplify_active bag eq_uri env new_pos new_table min_weight active
633 bag, active, newa, pruned
636 let close bag eq_uri env new' given =
637 let new_pos, new_table, min_weight =
640 let ew, _, _, _ , _ = Equality.open_equality e in
641 e::l, Indexing.index t e, min ew w)
642 ([], Indexing.empty, 1000000) (snd new')
646 let bag, pos = infer bag eq_uri env c (new_pos,new_table) in
651 let is_commutative_law eq =
652 let w, proof, (eq_ty, left, right, order), metas , _ =
653 Equality.open_equality eq
655 match left,right with
656 Cic.Appl[f1;Cic.Meta _ as a1;Cic.Meta _ as b1],
657 Cic.Appl[f2;Cic.Meta _ as a2;Cic.Meta _ as b2] ->
658 f1 = f2 && a1 = b2 && a2 = b1
662 let prova bag eq_uri env new' active =
663 let given = List.filter is_commutative_law (fst active) in
667 (Printf.sprintf "symmetric:\n%s\n"
670 (fun e -> Equality.string_of_equality ~env e)
672 close bag eq_uri env new' given
675 (* returns an estimation of how many equalities in passive can be activated
676 within the current time limit *)
677 let get_selection_estimate () =
678 elapsed_time := (Unix.gettimeofday ()) -. !start_time;
679 (* !processed_clauses * (int_of_float (!time_limit /. !elapsed_time)) *)
681 ceil ((float_of_int !processed_clauses) *.
682 ((!time_limit (* *. 2. *)) /. !elapsed_time -. 1.)))
686 (** initializes the set of goals *)
687 let make_goals goal =
689 and passive = [0, [goal]] in
693 let make_goal_set goal =
697 (** initializes the set of theorems *)
698 let make_theorems theorems =
703 let activate_goal (active, passive) =
706 | goal_conj::tl -> true, (goal_conj::active, tl)
707 | [] -> false, (active, passive)
709 true, (active,passive)
713 let activate_theorem (active, passive) =
715 | theorem::tl -> true, (theorem::active, tl)
716 | [] -> false, (active, passive)
719 let rec simpl bag eq_uri env e others others_simpl =
720 let active = others @ others_simpl in
724 if Equality.is_identity env e then t else Indexing.index t e)
725 Indexing.empty active
728 forward_simplify bag eq_uri env e (active, tbl)
733 | None -> simpl bag eq_uri env hd tl others_simpl
734 | Some e -> simpl bag eq_uri env hd tl (e::others_simpl)
738 | None -> bag, others_simpl
739 | Some e -> bag, e::others_simpl
743 let simplify_equalities bag eq_uri env equalities =
746 (Printf.sprintf "equalities:\n%s\n"
748 (List.map Equality.string_of_equality equalities))));
749 Utils.debug_print (lazy "SIMPLYFYING EQUALITIES...");
750 match equalities with
753 let bag, res = simpl bag eq_uri env hd tl [] in
754 let res = List.rev res in
757 (Printf.sprintf "equalities AFTER:\n%s\n"
759 (List.map Equality.string_of_equality res))));
763 let print_goals goals =
770 (* (string_of_proof p) ^ ", " ^ *) (CicPp.ppterm t)) gl
772 Printf.sprintf "%d: %s" d (String.concat "; " gl')) goals))
775 let pp_goal_set msg goals names =
776 let active_goals, passive_goals = goals in
777 debug_print (lazy ("////" ^ msg));
778 debug_print (lazy ("ACTIVE G: " ^
779 (String.concat "\n " (List.map (fun (_,_,g) -> CicPp.pp g names)
781 debug_print (lazy ("PASSIVE G: " ^
782 (String.concat "\n " (List.map (fun (_,_,g) -> CicPp.pp g names)
786 let check_if_goal_is_subsumed bag ((_,ctx,_) as env) table (goalproof,menv,ty) =
787 (* let names = Utils.names_of_context ctx in *)
789 | Cic.Appl[Cic.MutInd(uri,_,_);eq_ty;left;right]
790 when LibraryObjects.is_eq_URI uri ->
791 (let bag, goal_equation =
792 Equality.mk_equality bag
793 (0,Equality.Exact (Cic.Implicit None),(eq_ty,left,right,Utils.Eq),menv)
795 (* match Indexing.subsumption env table goal_equation with *)
796 match Indexing.unification env table goal_equation with
797 | Some (subst, equality, swapped ) ->
800 ("GOAL SUBSUMED IS: "^Equality.string_of_equality goal_equation ~env);
802 ("GOAL IS SUBSUMED BY: "^Equality.string_of_equality equality ~env);
803 prerr_endline ("SUBST:"^Subst.ppsubst ~names subst);
805 let (_,p,(ty,l,r,_),m,id) = Equality.open_equality equality in
806 let cicmenv = Subst.apply_subst_metasenv subst (m @ menv) in
809 Equality.symmetric bag eq_ty l id uri m
813 bag, Some (goalproof, p, id, subst, cicmenv)
819 let find_all_subsumed bag env table (goalproof,menv,ty) =
821 | Cic.Appl[Cic.MutInd(uri,_,_);eq_ty;left;right]
822 when LibraryObjects.is_eq_URI uri ->
823 let bag, goal_equation =
824 (Equality.mk_equality bag
825 (0,Equality.Exact (Cic.Implicit None),(eq_ty,left,right,Utils.Eq),menv))
828 (fun (subst, equality, swapped) (bag,acc) ->
829 let (_,p,(ty,l,r,_),m,id) = Equality.open_equality equality in
830 let cicmenv = Subst.apply_subst_metasenv subst (m @ menv) in
831 if Utils.debug_metas then
832 Indexing.check_for_duplicates cicmenv "from subsumption";
835 Equality.symmetric bag eq_ty l id uri m
839 bag, (goalproof, p, id, subst, cicmenv)::acc)
840 (Indexing.subsumption_all env table goal_equation) (bag,[])
841 (* (Indexing.unification_all env table goal_equation) *)
846 let check_if_goal_is_identity env = function
847 | (goalproof,m,Cic.Appl[Cic.MutInd(uri,_,ens);eq_ty;left;right])
848 when left = right && LibraryObjects.is_eq_URI uri ->
849 let reflproof = Equality.Exact (Equality.refl_proof uri eq_ty left) in
850 Some (goalproof, reflproof, 0, Subst.empty_subst,m)
851 | (goalproof,m,Cic.Appl[Cic.MutInd(uri,_,ens);eq_ty;left;right])
852 when LibraryObjects.is_eq_URI uri ->
853 (let _,context,_ = env in
856 Founif.unification [] m context left right CicUniv.empty_ugraph
858 let reflproof = Equality.Exact (Equality.refl_proof uri eq_ty left) in
859 let m = Subst.apply_subst_metasenv s m in
860 Some (goalproof, reflproof, 0, s,m)
861 with CicUnification.UnificationFailure _ -> None)
865 let rec check b goal = function
869 | b, None -> check b goal tl
870 | b, (Some _ as ok) -> b, ok
873 let simplify_goal_set bag env goals active =
874 let active_goals, passive_goals = goals in
875 let find (_,_,g) where =
876 List.exists (fun (_,_,g1) -> Equality.meta_convertibility g g1) where
878 (* prova:tengo le passive semplificate
880 List.map (fun g -> snd (simplify_goal env g active)) passive_goals
883 (fun (acc_a,acc_p) goal ->
884 match simplify_goal bag env goal active with
887 if find g acc_p then acc_a,acc_p else acc_a,g::acc_p
889 if find g acc_a then acc_a,acc_p else g::acc_a,acc_p)
890 ([],passive_goals) active_goals
893 let check_if_goals_set_is_solved bag env active passive goals =
894 let active_goals, passive_goals = goals in
896 (fun (bag, proof) goal ->
898 | Some p -> bag, proof
901 (fun b x -> b, check_if_goal_is_identity env x);
902 (fun bag -> check_if_goal_is_subsumed bag env (snd active));
903 (fun bag -> check_if_goal_is_subsumed bag env (last passive))
905 (bag,None) (active_goals @ passive_goals)
908 let infer_goal_set bag env active goals =
909 let active_goals, passive_goals = goals in
910 let rec aux bag = function
911 | [] -> bag, (active_goals, [])
913 let changed, selected = simplify_goal bag env hd active in
914 let (_,m1,t1) = selected in
916 List.exists (fun (_,_,t) -> Equality.meta_convertibility t t1)
922 let passive_goals = tl in
923 let bag, new_passive_goals =
924 if Utils.metas_of_term t1 = [] then
928 Indexing.superposition_left bag env (snd active) selected
930 bag, passive_goals @ new'
932 bag, (selected::active_goals, new_passive_goals)
934 aux bag passive_goals
937 let infer_goal_set_with_current bag env current goals active =
938 let active_goals, passive_goals = simplify_goal_set bag env goals active in
939 let l,table,_ = build_table [current] in
940 let bag, passive_goals =
943 let bag, new' = Indexing.superposition_left bag env table g in
945 (bag, passive_goals) active_goals
947 bag, active_goals, passive_goals
952 let ids = List.map (fun _,_,i,_,_ -> i) p in
956 let ids_of_goal_set (ga,gp) =
957 List.flatten (List.map ids_of_goal ga) @
958 List.flatten (List.map ids_of_goal gp)
961 let size_of_goal_set_a (l,_) = List.length l;;
962 let size_of_goal_set_p (_,l) = List.length l;;
964 let pp_goals label goals context =
965 let names = Utils.names_of_context context in
969 (Printf.sprintf "Current goal: %s = %s\n" label (CicPp.pp g names))))
974 (Printf.sprintf "PASSIVE goal: %s = %s\n" label (CicPp.pp g names))))
978 let print_status iterno goals active passive =
980 (Printf.sprintf "\n%d #ACTIVES: %d #PASSIVES: %d #GOALSET: %d(%d)"
981 iterno (size_of_active active) (size_of_passive passive)
982 (size_of_goal_set_a goals) (size_of_goal_set_p goals)))
985 let add_to_active_aux bag active passive env eq_uri current =
986 debug_print (lazy ("Adding to actives : " ^
987 Equality.string_of_equality ~env current));
988 match forward_simplify bag eq_uri env current active with
989 | bag, None -> None, active, passive, bag
990 | bag, Some current ->
991 let bag, new' = infer bag eq_uri env current active in
993 let al, tbl = active in
994 al @ [current], Indexing.index tbl current
996 let rec simplify bag new' active passive =
998 forward_simplify_new bag eq_uri env new' active
1000 let bag, active, newa, pruned =
1001 backward_simplify bag eq_uri env new' active
1004 List.fold_left (filter_dependent bag) passive pruned
1007 | None -> bag, active, passive, new'
1008 | Some p -> simplify bag (new' @ p) active passive
1010 let bag, active, passive, new' =
1011 simplify bag new' active passive
1013 let passive = add_to_passive passive new' [] in
1014 Some new', active, passive, bag
1017 (** given-clause algorithm with full reduction strategy: NEW implementation *)
1018 (* here goals is a set of goals in OR *)
1020 bag eq_uri ((_,context,_) as env) goals passive active
1021 goal_steps saturation_steps max_time
1023 let initial_time = Unix.gettimeofday () in
1024 let iterations_left iterno =
1025 let now = Unix.gettimeofday () in
1026 let time_left = max_time -. now in
1027 let time_spent_until_now = now -. initial_time in
1028 let iteration_medium_cost =
1029 time_spent_until_now /. (float_of_int iterno)
1031 let iterations_left = time_left /. iteration_medium_cost in
1032 int_of_float iterations_left
1034 let rec step bag goals passive active g_iterno s_iterno =
1035 if g_iterno > goal_steps && s_iterno > saturation_steps then
1036 (ParamodulationFailure ("No more iterations to spend",active,passive,bag))
1037 else if Unix.gettimeofday () > max_time then
1038 (ParamodulationFailure ("No more time to spend",active,passive,bag))
1041 print_status (max g_iterno s_iterno) goals active passive
1042 (* Printf.eprintf ".%!"; *)
1044 (* PRUNING OF PASSIVE THAT WILL NEVER BE PROCESSED *)
1046 let selection_estimate = iterations_left (max g_iterno s_iterno) in
1047 let kept = size_of_passive passive in
1048 if kept > selection_estimate then
1050 (*Printf.eprintf "Too many passive equalities: pruning...";
1051 prune_passive selection_estimate active*) passive
1056 kept_clauses := (size_of_passive passive) + (size_of_active active);
1058 if g_iterno < goal_steps then
1059 infer_goal_set bag env active goals
1063 match check_if_goals_set_is_solved bag env active passive goals with
1066 (Printf.sprintf "\nFound a proof in: %f\n"
1067 (Unix.gettimeofday() -. initial_time)));
1068 ParamodulationSuccess (p,active,passive,bag)
1071 if passive_is_empty passive then
1072 if no_more_passive_goals goals then
1073 ParamodulationFailure
1074 ("No more passive equations/goals",active,passive,bag)
1075 (*maybe this is a success! *)
1077 step bag goals passive active (g_iterno+1) (s_iterno+1)
1080 (* COLLECTION OF GARBAGED EQUALITIES *)
1082 if max g_iterno s_iterno mod 40 = 0 then
1083 (print_status (max g_iterno s_iterno) goals active passive;
1084 let active = List.map Equality.id_of (fst active) in
1085 let passive = List.map Equality.id_of (fst3 passive) in
1086 let goal = ids_of_goal_set goals in
1087 Equality.collect bag active passive goal)
1091 if s_iterno > saturation_steps then
1092 step bag goals passive active (g_iterno+1) (s_iterno+1)
1093 (* ParamodulationFailure ("max saturation steps",active,passive,bag) *)
1095 let current, passive = select env goals passive in
1096 match add_to_active_aux bag active passive env eq_uri current with
1097 | None, active, passive, bag ->
1098 step bag goals passive active (g_iterno+1) (s_iterno+1)
1099 | Some new', active, passive, bag ->
1100 let bag, active_goals, passive_goals =
1101 infer_goal_set_with_current bag env current goals active
1104 let a,b,_ = build_table new' in
1106 simplify_goal_set bag env (active_goals,passive_goals) (a,b)
1110 step bag goals passive active (g_iterno+1) (s_iterno+1)
1113 step bag goals passive active 0 0
1116 let rec saturate_equations bag eq_uri env goal accept_fun passive active =
1117 elapsed_time := Unix.gettimeofday () -. !start_time;
1118 if !elapsed_time > !time_limit then
1119 bag, active, passive
1121 let current, passive = select env ([goal],[]) passive in
1122 let bag, res = forward_simplify bag eq_uri env current active in
1125 saturate_equations bag eq_uri env goal accept_fun passive active
1127 Utils.debug_print (lazy (Printf.sprintf "selected: %s"
1128 (Equality.string_of_equality ~env current)));
1129 let bag, new' = infer bag eq_uri env current active in
1131 if Equality.is_identity env current then active
1133 let al, tbl = active in
1134 al @ [current], Indexing.index tbl current
1136 (* alla fine new' contiene anche le attive semplificate!
1137 * quindi le aggiungo alle passive insieme alle new *)
1138 let rec simplify bag new' active passive =
1139 let bag, new' = forward_simplify_new bag eq_uri env new' active in
1140 let bag, active, newa, pruned =
1141 backward_simplify bag eq_uri env new' active in
1143 List.fold_left (filter_dependent bag) passive pruned in
1145 | None -> bag, active, passive, new'
1146 | Some p -> simplify bag (new' @ p) active passive
1148 let bag, active, passive, new' = simplify bag new' active passive in
1152 (Printf.sprintf "active:\n%s\n"
1155 (fun e -> Equality.string_of_equality ~env e)
1161 (Printf.sprintf "new':\n%s\n"
1164 (fun e -> "Negative " ^
1165 (Equality.string_of_equality ~env e)) new'))))
1167 let new' = List.filter accept_fun new' in
1168 let passive = add_to_passive passive new' [] in
1169 saturate_equations bag eq_uri env goal accept_fun passive active
1172 let default_depth = !maxdepth
1173 and default_width = !maxwidth;;
1176 symbols_counter := 0;
1177 weight_age_counter := !weight_age_ratio;
1178 processed_clauses := 0;
1181 maximal_retained_equality := None;
1183 forward_simpl_time := 0.;
1184 forward_simpl_new_time := 0.;
1185 backward_simpl_time := 0.;
1186 passive_maintainance_time := 0.;
1187 derived_clauses := 0;
1191 let add_to_active bag active passive env ty term newmetas =
1193 match LibraryObjects.eq_URI () with
1194 | None -> active, passive, bag
1197 let bag, current = Equality.equality_of_term bag term ty newmetas in
1198 let bag, current = Equality.fix_metas bag current in
1199 match add_to_active_aux bag active passive env eq_uri current with
1202 | Equality.TermIsNotAnEquality -> active, passive, bag
1206 let eq_of_goal = function
1207 | Cic.Appl [Cic.MutInd(uri,0,_);_;_;_] when LibraryObjects.is_eq_URI uri ->
1209 | _ -> raise (ProofEngineTypes.Fail (lazy ("The goal is not an equality ")))
1212 let eq_and_ty_of_goal = function
1213 | Cic.Appl [Cic.MutInd(uri,0,_);t;_;_] when LibraryObjects.is_eq_URI uri ->
1215 | _ -> raise (ProofEngineTypes.Fail (lazy ("The goal is not an equality ")))
1218 (* fix proof takes in input a term and try to build a metasenv for it *)
1220 let fix_proof metasenv context all_implicits p =
1221 let rec aux metasenv n p =
1224 if all_implicits then
1225 metasenv,Cic.Implicit None
1228 CicMkImplicit.identity_relocation_list_for_metavariable context
1230 let meta = CicSubstitution.lift n (Cic.Meta (i,irl)) in
1233 let _ = CicUtil.lookup_meta i metasenv in metasenv
1234 with CicUtil.Meta_not_found _ ->
1235 debug_print (lazy ("not found: "^(string_of_int i)));
1236 let metasenv,j = CicMkImplicit.mk_implicit_type metasenv [] context in
1237 (i,context,Cic.Meta(j,irl))::metasenv
1243 (fun a (metasenv,l) ->
1244 let metasenv,a' = aux metasenv n a in
1247 in metasenv,Cic.Appl l
1248 | Cic.Lambda(name,s,t) ->
1249 let metasenv,s = aux metasenv n s in
1250 let metasenv,t = aux metasenv (n+1) t in
1251 metasenv,Cic.Lambda(name,s,t)
1252 | Cic.Prod(name,s,t) ->
1253 let metasenv,s = aux metasenv n s in
1254 let metasenv,t = aux metasenv (n+1) t in
1255 metasenv,Cic.Prod(name,s,t)
1256 | Cic.LetIn(name,s,ty,t) ->
1257 let metasenv,s = aux metasenv n s in
1258 let metasenv,ty = aux metasenv n ty in
1259 let metasenv,t = aux metasenv (n+1) t in
1260 metasenv,Cic.LetIn(name,s,ty,t)
1261 | Cic.Const(uri,ens) ->
1264 (fun (v,a) (metasenv,ens) ->
1265 let metasenv,a' = aux metasenv n a in
1266 metasenv,(v,a')::ens)
1269 metasenv,Cic.Const(uri,ens)
1275 let fix_metasenv context metasenv =
1278 let m,t = fix_proof m context false t in
1279 let m = List.filter (fun (j,_,_) -> j<>i) m in
1285 (* status: input proof status
1286 * goalproof: forward steps on goal
1287 * newproof: backward steps
1288 * subsumption_id: the equation used if goal is closed by subsumption
1289 * (0 if not closed by subsumption) (DEBUGGING: can be safely removed)
1290 * subsumption_subst: subst to make newproof and goalproof match
1291 * proof_menv: final metasenv
1296 goalproof newproof subsumption_id subsumption_subst proof_menv
1298 if proof_menv = [] then debug_print (lazy "+++++++++++++++VUOTA")
1299 else debug_print (lazy (CicMetaSubst.ppmetasenv [] proof_menv));
1300 let proof, goalno = status in
1301 let uri, metasenv, _subst, meta_proof, term_to_prove, attrs = proof in
1302 let _, context, type_of_goal = CicUtil.lookup_meta goalno metasenv in
1303 let eq_uri = eq_of_goal type_of_goal in
1304 let names = Utils.names_of_context context in
1305 debug_print (lazy "Proof:");
1307 (Equality.pp_proof bag names goalproof newproof subsumption_subst
1308 subsumption_id type_of_goal));
1310 prerr_endline ("max weight: " ^
1311 (string_of_int (Equality.max_weight goalproof newproof)));
1313 (* generation of the CIC proof *)
1314 (* let metasenv' = List.filter (fun i,_,_ -> i<>goalno) metasenv in *)
1316 List.filter (fun i -> i <> goalno)
1317 (ProofEngineHelpers.compare_metasenvs
1318 ~newmetasenv:metasenv ~oldmetasenv:proof_menv) in
1319 let goal_proof, side_effects_t =
1320 let initial = Equality.add_subst subsumption_subst newproof in
1321 Equality.build_goal_proof bag
1322 eq_uri goalproof initial type_of_goal side_effects
1325 (* Equality.draw_proof bag names goalproof newproof subsumption_id; *)
1326 let goal_proof = Subst.apply_subst subsumption_subst goal_proof in
1327 (* assert (metasenv=[]); *)
1328 let real_menv = fix_metasenv context (proof_menv@metasenv) in
1329 let real_menv,goal_proof =
1330 fix_proof real_menv context false goal_proof in
1332 let real_menv,fixed_proof = fix_proof proof_menv context false goal_proof in
1333 (* prerr_endline ("PROOF: " ^ CicPp.pp goal_proof names); *)
1335 let pp_error goal_proof names error exn =
1336 prerr_endline "THE PROOF DOES NOT TYPECHECK! <begin>";
1337 prerr_endline (CicPp.pp goal_proof names);
1338 prerr_endline "THE PROOF DOES NOT TYPECHECK!";
1339 prerr_endline error;
1340 prerr_endline "THE PROOF DOES NOT TYPECHECK! <end>";
1343 let old_insert_coercions = !CicRefine.insert_coercions in
1344 let goal_proof,goal_ty,real_menv,_ =
1345 (* prerr_endline ("parte la refine per: " ^ (CicPp.pp goal_proof names)); *)
1347 debug_print (lazy (CicPp.ppterm goal_proof));
1348 CicRefine.insert_coercions := false;
1350 CicRefine.type_of_aux'
1351 real_menv context goal_proof CicUniv.empty_ugraph
1353 CicRefine.insert_coercions := old_insert_coercions;
1356 | CicRefine.RefineFailure s
1357 | CicRefine.Uncertain s
1358 | CicRefine.AssertFailure s as exn ->
1359 CicRefine.insert_coercions := old_insert_coercions;
1360 pp_error goal_proof names (Lazy.force s) exn
1361 | CicUtil.Meta_not_found i as exn ->
1362 CicRefine.insert_coercions := old_insert_coercions;
1363 pp_error goal_proof names ("META NOT FOUND: "^string_of_int i) exn
1364 | Invalid_argument "list_fold_left2" as exn ->
1365 CicRefine.insert_coercions := old_insert_coercions;
1366 pp_error goal_proof names "Invalid_argument: list_fold_left2" exn
1368 CicRefine.insert_coercions := old_insert_coercions;
1371 let subst_side_effects,real_menv,_ =
1373 CicUnification.fo_unif_subst [] context real_menv
1374 goal_ty type_of_goal CicUniv.empty_ugraph
1376 | CicUnification.UnificationFailure s
1377 | CicUnification.Uncertain s
1378 | CicUnification.AssertFailure s -> assert false
1379 (* fail "Maybe the local context of metas in the goal was not an IRL" s *)
1381 Utils.debug_print (lazy "+++++++++++++ FINE UNIF");
1383 (goalno,(context,goal_proof,type_of_goal))::subst_side_effects
1386 let metas_of_proof = Utils.metas_of_term goal_proof in
1388 let proof, real_metasenv =
1389 ProofEngineHelpers.subst_meta_and_metasenv_in_proof
1390 proof goalno final_subst
1391 (List.filter (fun i,_,_ -> i<>goalno ) real_menv)
1394 (ProofEngineHelpers.compare_metasenvs
1395 ~oldmetasenv:metasenv ~newmetasenv:real_metasenv) in
1398 List.map (fun i,_,_ -> i) real_metasenv in
1400 final_subst, proof, open_goals
1405 let metas_still_open_in_proof = Utils.metas_of_term goal_proof in
1406 (* prerr_endline (CicPp.pp goal_proof names); *)
1407 let goal_proof = (* Subst.apply_subst subsumption_subst *) goal_proof in
1408 let side_effects_t =
1409 List.map (Subst.apply_subst subsumption_subst) side_effects_t
1411 (* replacing fake mets with real ones *)
1412 (* prerr_endline "replacing metas..."; *)
1413 let irl=CicMkImplicit.identity_relocation_list_for_metavariable context in
1414 CicMetaSubst.ppmetasenv [] proof_menv;
1415 let what, with_what =
1417 (fun (acc1,acc2) i ->
1418 (Cic.Meta(i,[]))::acc1, (Cic.Implicit None)::acc2)
1420 metas_still_open_in_proof
1424 List.mem i metas_still_open_in_proof
1425 (*&& not(List.mem i metas_still_open_in_goal)*))
1429 let goal_proof_menv =
1431 (fun (i,_,_) -> List.mem i metas_still_open_in_proof)
1435 (* we need this fake equality since the metas of the hypothesis may be
1436 * with a real local context *)
1437 ProofEngineReduction.replace_lifting
1438 ~equality:(fun x y ->
1439 match x,y with Cic.Meta(i,_),Cic.Meta(j,_) -> i=j | _-> false)
1440 ~what ~with_what ~where
1442 let goal_proof = replace goal_proof in
1443 (* ok per le meta libere... ma per quelle che c'erano e sono rimaste?
1444 * what mi pare buono, sostituisce solo le meta farlocche *)
1445 let side_effects_t = List.map replace side_effects_t in
1447 List.filter (fun i -> i <> goalno)
1448 (ProofEngineHelpers.compare_metasenvs
1449 ~oldmetasenv:metasenv ~newmetasenv:goal_proof_menv)
1453 * String.concat "," (List.map string_of_int free_metas) ); *)
1454 (* check/refine/... build the new proof *)
1456 ProofEngineReduction.replace
1457 ~what:side_effects ~with_what:side_effects_t
1458 ~equality:(fun i t -> match t with Cic.Meta(j,_)->j=i|_->false)
1461 let goal_proof,goal_ty,real_menv,_ =
1463 CicRefine.type_of_aux' metasenv context goal_proof
1464 CicUniv.empty_ugraph
1466 | CicUtil.Meta_not_found _
1467 | CicRefine.RefineFailure _
1468 | CicRefine.Uncertain _
1469 | CicRefine.AssertFailure _
1470 | Invalid_argument "list_fold_left2" as exn ->
1471 prerr_endline "THE PROOF DOES NOT TYPECHECK!";
1472 prerr_endline (CicPp.pp goal_proof names);
1473 prerr_endline "THE PROOF DOES NOT TYPECHECK!";
1476 prerr_endline "+++++++++++++ METASENV";
1478 (CicMetaSubst.ppmetasenv [] real_menv);
1479 let subst_side_effects,real_menv,_ =
1481 prerr_endline ("XX type_of_goal " ^ CicPp.ppterm type_of_goal);
1482 prerr_endline ("XX replaced_goal " ^ CicPp.ppterm replaced_goal);
1483 prerr_endline ("XX metasenv " ^
1484 CicMetaSubst.ppmetasenv [] (metasenv @ free_metas_menv));
1487 CicUnification.fo_unif_subst [] context real_menv
1488 goal_ty type_of_goal CicUniv.empty_ugraph
1490 | CicUnification.UnificationFailure s
1491 | CicUnification.Uncertain s
1492 | CicUnification.AssertFailure s -> assert false
1493 (* fail "Maybe the local context of metas in the goal was not an IRL" s *)
1496 (goalno,(context,goal_proof,type_of_goal))::subst_side_effects
1499 let metas_of_proof = Utils.metas_of_term goal_proof in
1501 let proof, real_metasenv =
1502 ProofEngineHelpers.subst_meta_and_metasenv_in_proof
1503 proof goalno (CicMetaSubst.apply_subst final_subst)
1504 (List.filter (fun i,_,_ -> i<>goalno ) real_menv)
1507 List.map (fun i,_,_ -> i) real_metasenv in
1510 HExtlib.list_uniq (List.sort Pervasives.compare metas_of_proof)
1513 match free_meta with Some(Cic.Meta(m,_)) when m<>goalno ->[m] | _ ->[]
1518 "GOALS APERTI: %s\nMETASENV PRIMA:\n%s\nMETASENV DOPO:\n%s\n"
1519 (String.concat ", " (List.map string_of_int open_goals))
1520 (CicMetaSubst.ppmetasenv [] metasenv)
1521 (CicMetaSubst.ppmetasenv [] real_metasenv);
1523 final_subst, proof, open_goals
1527 (* **************** HERE ENDS THE PARAMODULATION STUFF ******************** *)
1529 (* exported functions *)
1531 let pump_actives context bag active passive saturation_steps max_time =
1536 (fun acc e -> let _,_,_,menv,_ = Equality.open_equality e in
1537 List.fold_left (fun acc (i,_,_) -> max i acc) acc menv)
1540 (* let active_l = fst active in *)
1541 (* let passive_l = fst passive in *)
1542 (* let ma = max_l active_l in *)
1543 (* let mp = max_l passive_l in *)
1544 match LibraryObjects.eq_URI () with
1545 | None -> active, passive, bag
1547 let env = [],context,CicUniv.empty_ugraph in
1549 given_clause bag eq_uri env ([],[])
1550 passive active 0 saturation_steps max_time
1552 | ParamodulationFailure (_,a,p,b) ->
1554 | ParamodulationSuccess _ ->
1558 let all_subsumed bag status active passive =
1559 let proof, goalno = status in
1560 let uri, metasenv, _subst, meta_proof, term_to_prove, attrs = proof in
1561 let _, context, type_of_goal = CicUtil.lookup_meta goalno metasenv in
1562 let env = metasenv,context,CicUniv.empty_ugraph in
1563 let cleaned_goal = Utils.remove_local_context type_of_goal in
1564 let canonical_menv,other_menv =
1565 List.partition (fun (_,c,_) -> c = context) metasenv in
1566 (* prerr_endline ("other menv = " ^ (CicMetaSubst.ppmetasenv [] other_menv)); *)
1567 let metasenv = List.map (fun (i,_,ty)-> (i,[],ty)) canonical_menv in
1568 let goal = [], List.filter (fun (i,_,_)->i<>goalno) metasenv, cleaned_goal in
1569 debug_print (lazy (string_of_int (List.length (fst active))));
1570 (* we simplify using both actives passives *)
1573 (fun (l,tbl) eq -> eq::l,(Indexing.index tbl eq))
1574 active (list_of_passive passive) in
1575 let (_,_,ty) = goal in
1576 debug_print (lazy ("prima " ^ CicPp.ppterm ty));
1577 let _,goal = simplify_goal bag env goal table in
1578 let (_,_,ty) = goal in
1579 debug_print (lazy ("in mezzo " ^ CicPp.ppterm ty));
1580 let bag, subsumed = find_all_subsumed bag env (snd table) goal in
1581 debug_print (lazy ("dopo " ^ CicPp.ppterm ty));
1582 let subsumed_or_id =
1583 match (check_if_goal_is_identity env goal) with
1585 | Some id -> id::subsumed in
1586 debug_print (lazy "dopo subsumed");
1590 (goalproof,newproof,subsumption_id,subsumption_subst, proof_menv) ->
1591 let subst, proof, gl =
1593 status goalproof newproof subsumption_id subsumption_subst proof_menv
1595 let uri, metasenv, subst, meta_proof, term_to_prove, attrs = proof in
1599 (fun x,_,_ -> not (List.exists (fun y,_,_ -> x=y) other_menv)) metasenv
1601 let proof = uri, newmetasenv, subst, meta_proof, term_to_prove, attrs in
1602 (subst, proof,gl)) subsumed_or_id
1609 bag status active passive goal_steps saturation_steps max_time
1612 let active_l = fst active in
1613 let proof, goalno = status in
1614 let uri, metasenv, _subst, meta_proof, term_to_prove, attrs = proof in
1615 let _, context, type_of_goal = CicUtil.lookup_meta goalno metasenv in
1616 let eq_uri = eq_of_goal type_of_goal in
1617 let cleaned_goal = Utils.remove_local_context type_of_goal in
1618 let metas_occurring_in_goal = CicUtil.metas_of_term cleaned_goal in
1619 let canonical_menv,other_menv =
1620 List.partition (fun (_,c,_) -> c = context) metasenv in
1621 Utils.set_goal_symbols cleaned_goal; (* DISACTIVATED *)
1622 let canonical_menv =
1624 (fun (i,_,ty)-> (i,[],Utils.remove_local_context ty)) canonical_menv
1628 (fun (i,_,_)-> i<>goalno && List.mem_assoc i metas_occurring_in_goal)
1631 let goal = [], metasenv', cleaned_goal in
1632 let env = metasenv,context,CicUniv.empty_ugraph in
1633 debug_print (lazy ">>>>>> ACTIVES >>>>>>>>");
1634 List.iter (fun e -> debug_print (lazy (Equality.string_of_equality ~env e)))
1636 debug_print (lazy ">>>>>>>>>>>>>>");
1637 let goals = make_goal_set goal in
1639 given_clause bag eq_uri env goals passive active
1640 goal_steps saturation_steps max_time
1642 | ParamodulationFailure (msg,a,p,b) ->
1643 if Utils.debug then prerr_endline msg;
1645 | ParamodulationSuccess
1646 ((goalproof,newproof,subsumption_id,subsumption_subst, proof_menv),a,p,b) ->
1647 let subst, proof, gl =
1649 status goalproof newproof subsumption_id subsumption_subst proof_menv
1651 let uri, metasenv, subst, meta_proof, term_to_prove, attrs = proof in
1652 let proof = uri, other_menv@metasenv, subst, meta_proof, term_to_prove, attrs in
1653 Some (subst, proof,gl),a,p, b
1656 let solve_narrowing bag status active passive goal_steps =
1657 let proof, goalno = status in
1658 let uri, metasenv, _subst, meta_proof, term_to_prove, attrs = proof in
1659 let _, context, type_of_goal = CicUtil.lookup_meta goalno metasenv in
1660 let cleaned_goal = Utils.remove_local_context type_of_goal in
1661 let metas_occurring_in_goal = CicUtil.metas_of_term cleaned_goal in
1662 let canonical_menv,other_menv =
1663 List.partition (fun (_,c,_) -> c = context) metasenv in
1664 let canonical_menv =
1666 (fun (i,_,ty)-> (i,[],Utils.remove_local_context ty)) canonical_menv
1670 (fun (i,_,_)-> i<>goalno && List.mem_assoc i metas_occurring_in_goal)
1673 let goal = [], metasenv', cleaned_goal in
1674 let env = metasenv,context,CicUniv.empty_ugraph in
1676 let table = List.fold_left Indexing.index (last passive) (fst active) in
1677 goal :: Indexing.demodulation_all_goal bag env table goal 4
1679 let rec aux newactives newpassives bag = function
1680 | [] -> bag, (newactives, newpassives)
1682 let selected = hd in
1683 let (_,m1,t1) = selected in
1685 List.exists (fun (_,_,t) -> Equality.meta_convertibility t t1)
1689 aux newactives newpassives bag tl
1691 let bag, newpassives =
1692 if Utils.metas_of_term t1 = [] then
1696 Indexing.superposition_left bag env (snd active) selected
1700 (fun x -> let b, x = simplify_goal bag env x active in x)
1703 bag, newpassives @ new'
1705 aux (selected::newactives) newpassives bag tl
1707 let rec do_n bag ag pg = function
1708 | 0 -> None, active, passive, bag
1710 let bag, (ag, pg) = aux [] [] bag (ag @ pg) in
1711 match check_if_goals_set_is_solved bag env active passive (ag,pg) with
1712 | bag, None -> do_n bag ag pg (n-1)
1713 | bag, Some (gproof,newproof,subsumption_id,subsumption_subst,pmenv)->
1714 let subst, proof, gl =
1716 status gproof newproof subsumption_id subsumption_subst pmenv
1718 let uri,metasenv,subst,meta_proof,term_to_prove,attrs = proof in
1720 uri, other_menv@metasenv, subst, meta_proof, term_to_prove, attrs
1722 Some (subst, proof,gl),active,passive, bag
1724 do_n bag [] goals goal_steps
1728 let add_to_passive eql passives =
1729 add_to_passive passives eql eql