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 *)
32 let connect_to_auto = true;;
35 (* profiling statistics... *)
36 let infer_time = ref 0.;;
37 let forward_simpl_time = ref 0.;;
38 let forward_simpl_new_time = ref 0.;;
39 let backward_simpl_time = ref 0.;;
40 let passive_maintainance_time = ref 0.;;
42 (* limited-resource-strategy related globals *)
43 let processed_clauses = ref 0;; (* number of equalities selected so far... *)
44 let time_limit = ref 0.;; (* in seconds, settable by the user... *)
45 let start_time = ref 0.;; (* time at which the execution started *)
46 let elapsed_time = ref 0.;;
47 (* let maximal_weight = ref None;; *)
48 let maximal_retained_equality = ref None;;
50 (* equality-selection related globals *)
51 let use_fullred = ref true;;
52 let weight_age_ratio = ref 6 (* 5 *);; (* settable by the user *)
53 let weight_age_counter = ref !weight_age_ratio ;;
54 let symbols_ratio = ref 0 (* 3 *);;
55 let symbols_counter = ref 0;;
57 (* non-recursive Knuth-Bendix term ordering by default *)
58 (* Utils.compare_terms := Utils.rpo;; *)
59 (* Utils.compare_terms := Utils.nonrec_kbo;; *)
60 (* Utils.compare_terms := Utils.ao;; *)
63 let derived_clauses = ref 0;;
64 let kept_clauses = ref 0;;
66 (* index of the greatest Cic.Meta created - TODO: find a better way! *)
69 (* varbiables controlling the search-space *)
70 let maxdepth = ref 3;;
71 let maxwidth = ref 3;;
74 Equality.goal_proof * Equality.proof * int * Subst.substitution * Cic.metasenv
76 | ParamodulationFailure of string
77 | ParamodulationSuccess of new_proof
80 (* type goal = Equality.goal_proof * Cic.metasenv * Cic.term;; *)
82 type theorem = Cic.term * Cic.term * Cic.metasenv;;
84 let symbols_of_equality equality =
85 let (_, _, (_, left, right, _), _,_) = Equality.open_equality equality in
86 let m1 = Utils.symbols_of_term left in
91 let c = Utils.TermMap.find k res in
92 Utils.TermMap.add k (c+v) res
94 Utils.TermMap.add k v res)
95 (Utils.symbols_of_term right) m1
101 module OrderedEquality = struct
102 type t = Equality.equality
104 let compare eq1 eq2 =
105 match Equality.meta_convertibility_eq eq1 eq2 with
108 let w1, _, (ty,left, right, _), m1,_ = Equality.open_equality eq1 in
109 let w2, _, (ty',left', right', _), m2,_ = Equality.open_equality eq2 in
110 match Pervasives.compare w1 w2 with
112 let res = (List.length m1) - (List.length m2) in
113 if res <> 0 then res else
114 Equality.compare eq1 eq2
118 module EqualitySet = Set.Make(OrderedEquality);;
120 exception Empty_list;;
122 type passives = Equality.equality list * EqualitySet.t;;
123 type actives = Equality.equality list * Indexing.Index.t;;
125 (* initializes the passive set of equalities
126 * XXX I think EqualitySet.elements should be ok (to eliminate duplicates)
128 let make_passive pos =
130 List.fold_left (fun s e -> EqualitySet.add e s) EqualitySet.empty pos
132 (*EqualitySet.elements*) pos, set
135 let make_active () = [], Indexing.empty ;;
136 let size_of_passive (passive_list, _) = List.length passive_list;;
137 let size_of_active (active_list, _) = List.length active_list;;
138 let passive_is_empty = function
139 | [], s when EqualitySet.is_empty s -> true
140 | [], s -> assert false (* the set and the list should be in sync *)
144 type goals = Equality.goal list * Equality.goal list
146 let no_more_passive_goals g = match g with | _,[] -> true | _ -> false;;
149 let age_factor = 0.01;;
152 selects one equality from passive. The selection strategy is a combination
153 of weight, age and goal-similarity
156 let rec select env g passive =
157 processed_clauses := !processed_clauses + 1;
160 match (List.rev goals) with goal::_ -> goal | _ -> assert false
163 let pos_list, pos_set = passive in
164 let remove eq l = List.filter (fun e -> Equality.compare e eq <> 0) l in
165 if !weight_age_ratio > 0 then
166 weight_age_counter := !weight_age_counter - 1;
167 match !weight_age_counter with
169 weight_age_counter := !weight_age_ratio;
170 let skip_giant pos_list pos_set =
172 | (hd:EqualitySet.elt)::tl ->
173 let w,_,_,_,_ = Equality.open_equality hd in
175 hd, (tl, EqualitySet.remove hd pos_set)
179 ("+++ skipping giant of size "^string_of_int w^" +++");
181 select env g (tl@[hd],pos_set)
184 skip_giant pos_list pos_set)
187 let rec skip_giant pos_list pos_set =
189 | (hd:EqualitySet.elt)::tl ->
190 let w,_,_,_,_ = Equality.open_equality hd in
191 let pos_set = EqualitySet.remove hd pos_set in
196 ("+++ skipping giant of size "^string_of_int w^" +++");
197 skip_giant tl pos_set)
200 skip_giant pos_list pos_set)
204 | _ when (!symbols_counter > 0) ->
205 (symbols_counter := !symbols_counter - 1;
206 let cardinality map =
207 Utils.TermMap.fold (fun k v res -> res + v) map 0
210 let _, _, term = goal in
211 Utils.symbols_of_term term
213 let card = cardinality symbols in
214 let foldfun k v (r1, r2) =
215 if Utils.TermMap.mem k symbols then
216 let c = Utils.TermMap.find k symbols in
217 let c1 = abs (c - v) in
223 let f equality (i, e) =
225 Utils.TermMap.fold foldfun (symbols_of_equality equality) (0, 0)
227 let c = others + (abs (common - card)) in
228 if c < i then (c, equality)
231 let e1 = EqualitySet.min_elt pos_set in
234 Utils.TermMap.fold foldfun (symbols_of_equality e1) (0, 0)
236 (others + (abs (common - card))), e1
238 let _, current = EqualitySet.fold f pos_set initial in
240 (remove current pos_list, EqualitySet.remove current pos_set))
243 symbols_counter := !symbols_ratio;
245 let w1,_,_,_,_ = Equality.open_equality e1 in
246 let w2,_,_,_,_ = Equality.open_equality e2 in
247 if w1 < w2 then e1 else e2
249 let rec my_min_elt min = function
251 | hd::tl -> my_min_elt (my_min hd min) tl
253 (* let current = EqualitySet.min_elt pos_set in *)
254 let current = my_min_elt (List.hd pos_list) (List.tl pos_list) in
255 current,(remove current pos_list, EqualitySet.remove current pos_set)
259 let filter_dependent passive id =
260 let pos_list, pos_set = passive in
261 let passive,no_pruned =
263 (fun eq ((list,set),no) ->
264 if Equality.depend eq id then
265 (list, EqualitySet.remove eq set), no + 1
268 pos_list (([],pos_set),0)
271 if no_pruned > 0 then
272 prerr_endline ("+++ pruning "^ string_of_int no_pruned ^" passives +++");
278 (* adds to passive a list of equalities new_pos *)
279 let add_to_passive passive new_pos preferred =
280 let pos_list, pos_set = passive in
281 let ok set equality = not (EqualitySet.mem equality set) in
282 let pos = List.filter (ok pos_set) new_pos in
283 let add set equalities =
284 List.fold_left (fun s e -> EqualitySet.add e s) set equalities
286 let pos_head, pos_tail =
288 (fun e -> List.exists (fun x -> Equality.compare x e = 0) preferred)
291 assert(pos_head = []);
292 pos_head @ pos_list @ pos_tail, add pos_set pos
296 (* removes from passive equalities that are estimated impossible to activate
297 within the current time limit *)
298 let prune_passive howmany (active, _) passive =
299 let (pl, ps), tbl = passive in
300 let howmany = float_of_int howmany
301 and ratio = float_of_int !weight_age_ratio in
304 int_of_float (if t -. v < 0.5 then t else v)
306 let in_weight = round (howmany *. ratio /. (ratio +. 1.))
307 and in_age = round (howmany /. (ratio +. 1.)) in
309 (lazy (Printf.sprintf "in_weight: %d, in_age: %d\n" in_weight in_age));
310 let counter = ref !symbols_ratio in
315 counter := !counter - 1;
316 if !counter = 0 then counter := !symbols_ratio in
317 let e = EqualitySet.min_elt ps in
318 let ps' = pickw (w-1) (EqualitySet.remove e ps) in
319 EqualitySet.add e ps'
321 let e = EqualitySet.min_elt ps in
322 let ps' = pickw (w-1) (EqualitySet.remove e ps) in
323 EqualitySet.add e ps'
327 let ps = pickw in_weight ps in
328 let rec picka w s l =
332 | hd::tl when not (EqualitySet.mem hd s) ->
333 let w, s, l = picka (w-1) s tl in
334 w, EqualitySet.add hd s, hd::l
336 let w, s, l = picka w s tl in
341 let _, ps, pl = picka in_age ps pl in
342 if not (EqualitySet.is_empty ps) then
343 maximal_retained_equality := Some (EqualitySet.max_elt ps);
346 (fun e tbl -> Indexing.index tbl e) ps Indexing.empty
352 (** inference of new equalities between current and some in active *)
353 let infer eq_uri env current (active_list, active_table) =
355 if Utils.debug_metas then
356 (ignore(Indexing.check_target c current "infer1");
357 ignore(List.map (function current -> Indexing.check_target c current "infer2") active_list));
359 let maxm, copy_of_current = Equality.fix_metas !maxmeta current in
361 let active_table = Indexing.index active_table copy_of_current in
362 (* let _ = <:start<current contro active>> in *)
364 Indexing.superposition_right eq_uri !maxmeta env active_table current
366 (* let _ = <:stop<current contro active>> in *)
367 if Utils.debug_metas then
370 Indexing.check_target c current "sup0") res);
372 let rec infer_positive table = function
376 Indexing.superposition_right
377 ~subterms_only:true eq_uri !maxmeta env table equality
380 if Utils.debug_metas then
384 Indexing.check_target c current "sup2") res);
385 let pos = infer_positive table tl in
389 let maxm, copy_of_current = Equality.fix_metas !maxmeta current in
392 let curr_table = Indexing.index Indexing.empty current in
393 (* let _ = <:start<active contro current>> in *)
394 let pos = infer_positive curr_table ((*copy_of_current::*)active_list) in
395 (* let _ = <:stop<active contro current>> in *)
396 if Utils.debug_metas then
399 Indexing.check_target c current "sup3") pos);
402 derived_clauses := !derived_clauses + (List.length new_pos);
403 match !maximal_retained_equality with
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 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 eq_uri env current (active_list, active_table) =
448 let _, context, _ = env in
449 let demodulate table current =
450 let newmeta, newcurrent =
451 Indexing.demodulation_equality eq_uri !maxmeta env table current
454 if Equality.is_identity env newcurrent then None else Some newcurrent
456 let rec demod current =
457 if Utils.debug_metas then
458 ignore (Indexing.check_target context current "demod0");
459 let res = demodulate active_table current in
460 if Utils.debug_metas then
461 ignore ((function None -> () | Some x ->
462 ignore (Indexing.check_target context x "demod1");()) res);
465 let res = demod current in
469 if Indexing.in_index active_table c ||
470 check_for_deep_subsumption env active_table c
477 (** simplifies new using active and passive *)
478 let forward_simplify_new eq_uri env new_pos active =
479 if Utils.debug_metas then
483 (fun current -> Indexing.check_target c current "forward new pos")
486 let active_list, active_table = active in
487 let demodulate table target =
488 let newmeta, newtarget =
489 Indexing.demodulation_equality eq_uri !maxmeta env table target
494 (* we could also demodulate using passive. Currently we don't *)
495 let new_pos = List.map (demodulate active_table) new_pos in
499 if not (Equality.is_identity env e) then
502 EqualitySet.empty new_pos
504 let new_pos = EqualitySet.elements new_pos_set in
506 let subs e = Indexing.subsumption env active_table e = None in
507 let is_duplicate e = not (Indexing.in_index active_table e) in
508 List.filter subs (List.filter is_duplicate new_pos)
512 (** simplifies a goal with equalities in active and passive *)
513 let rec simplify_goal env goal (active_list, active_table) =
514 let demodulate table goal = Indexing.demodulation_goal env table goal in
515 let changed, goal = demodulate active_table goal in
520 snd (simplify_goal env goal (active_list, active_table))
524 let simplify_goals env goals active =
525 let a_goals, p_goals = goals in
526 let p_goals = List.map (fun g -> snd (simplify_goal env g active)) p_goals in
527 let a_goals = List.map (fun g -> snd (simplify_goal env g active)) a_goals in
532 (** simplifies active usign new *)
533 let backward_simplify_active eq_uri env new_pos new_table min_weight active =
534 let active_list, active_table = active in
535 let active_list, newa, pruned =
537 (fun equality (res, newn,pruned) ->
538 let ew, _, _, _,id = Equality.open_equality equality in
539 if ew < min_weight then
540 equality::res, newn,pruned
543 forward_simplify eq_uri env equality (new_pos, new_table)
545 | None -> res, newn, id::pruned
547 if Equality.compare equality e = 0 then
550 res, e::newn, pruned)
551 active_list ([], [],[])
554 List.exists (Equality.meta_convertibility_eq eq1) where
557 let _, _, _, _,id = Equality.open_equality eq in id
559 let ((active1,pruned),tbl), newa =
561 (fun eq ((res,pruned), tbl) ->
562 if List.mem eq res then
563 (res, (id_of_eq eq)::pruned),tbl
564 else if (Equality.is_identity env eq) || (find eq res) then (
565 (res, (id_of_eq eq)::pruned),tbl
568 (eq::res,pruned), Indexing.index tbl eq)
569 active_list (([],pruned), Indexing.empty),
572 if (Equality.is_identity env eq) then p
577 | [] -> (active1,tbl), None, pruned
578 | _ -> (active1,tbl), Some newa, pruned
582 (** simplifies passive using new *)
583 let backward_simplify_passive eq_uri env new_pos new_table min_weight passive =
584 let (pl, ps), passive_table = passive in
585 let f equality (resl, ress, newn) =
586 let ew, _, _, _ , _ = Equality.open_equality equality in
587 if ew < min_weight then
588 equality::resl, ress, newn
591 forward_simplify eq_uri env equality (new_pos, new_table)
593 | None -> resl, EqualitySet.remove equality ress, newn
596 equality::resl, ress, newn
598 let ress = EqualitySet.remove equality ress in
601 let pl, ps, newp = List.fold_right f pl ([], ps, []) in
604 (fun tbl e -> Indexing.index tbl e) Indexing.empty pl
607 | [] -> ((pl, ps), passive_table), None
608 | _ -> ((pl, ps), passive_table), Some (newp)
611 let build_table equations =
614 let ew, _, _, _ , _ = Equality.open_equality e in
615 e::l, Indexing.index t e, min ew w)
616 ([], Indexing.empty, 1000000) equations
620 let backward_simplify eq_uri env new' active =
621 let new_pos, new_table, min_weight = build_table new' in
622 let active, newa, pruned =
623 backward_simplify_active eq_uri env new_pos new_table min_weight active
625 active, newa, None, pruned
628 let close eq_uri env new' given =
629 let new_pos, new_table, min_weight =
632 let ew, _, _, _ , _ = Equality.open_equality e in
633 e::l, Indexing.index t e, min ew w)
634 ([], Indexing.empty, 1000000) (snd new')
638 let pos = infer eq_uri env c (new_pos,new_table) in
643 let is_commutative_law eq =
644 let w, proof, (eq_ty, left, right, order), metas , _ =
645 Equality.open_equality eq
647 match left,right with
648 Cic.Appl[f1;Cic.Meta _ as a1;Cic.Meta _ as b1],
649 Cic.Appl[f2;Cic.Meta _ as a2;Cic.Meta _ as b2] ->
650 f1 = f2 && a1 = b2 && a2 = b1
654 let prova eq_uri env new' active =
655 let given = List.filter is_commutative_law (fst active) in
659 (Printf.sprintf "symmetric:\n%s\n"
662 (fun e -> Equality.string_of_equality ~env e)
664 close eq_uri env new' given
667 (* returns an estimation of how many equalities in passive can be activated
668 within the current time limit *)
669 let get_selection_estimate () =
670 elapsed_time := (Unix.gettimeofday ()) -. !start_time;
671 (* !processed_clauses * (int_of_float (!time_limit /. !elapsed_time)) *)
673 ceil ((float_of_int !processed_clauses) *.
674 ((!time_limit (* *. 2. *)) /. !elapsed_time -. 1.)))
678 (** initializes the set of goals *)
679 let make_goals goal =
681 and passive = [0, [goal]] in
685 let make_goal_set goal =
689 (** initializes the set of theorems *)
690 let make_theorems theorems =
695 let activate_goal (active, passive) =
698 | goal_conj::tl -> true, (goal_conj::active, tl)
699 | [] -> false, (active, passive)
701 true, (active,passive)
705 let activate_theorem (active, passive) =
707 | theorem::tl -> true, (theorem::active, tl)
708 | [] -> false, (active, passive)
713 let simplify_theorems env theorems ?passive (active_list, active_table) =
714 let pl, passive_table =
717 | Some ((pn, _), (pp, _), pt) -> pn @ pp, Some pt
719 let a_theorems, p_theorems = theorems in
720 let demodulate table theorem =
721 let newmeta, newthm =
722 Indexing.demodulation_theorem !maxmeta env table theorem in
724 theorem != newthm, newthm
726 let foldfun table (a, p) theorem =
727 let changed, theorem = demodulate table theorem in
728 if changed then (a, theorem::p) else (theorem::a, p)
730 let mapfun table theorem = snd (demodulate table theorem) in
731 match passive_table with
733 let p_theorems = List.map (mapfun active_table) p_theorems in
734 List.fold_left (foldfun active_table) ([], p_theorems) a_theorems
735 | Some passive_table ->
736 let p_theorems = List.map (mapfun active_table) p_theorems in
737 let p_theorems, a_theorems =
738 List.fold_left (foldfun active_table) ([], p_theorems) a_theorems in
739 let p_theorems = List.map (mapfun passive_table) p_theorems in
740 List.fold_left (foldfun passive_table) ([], p_theorems) a_theorems
744 let rec simpl eq_uri env e others others_simpl =
745 let active = others @ others_simpl in
748 (fun t e -> Indexing.index t e)
749 Indexing.empty active
751 let res = forward_simplify eq_uri env e (active, tbl) in
755 | None -> simpl eq_uri env hd tl others_simpl
756 | Some e -> simpl eq_uri env hd tl (e::others_simpl)
760 | None -> others_simpl
761 | Some e -> e::others_simpl
765 let simplify_equalities eq_uri env equalities =
768 (Printf.sprintf "equalities:\n%s\n"
770 (List.map Equality.string_of_equality equalities))));
771 Utils.debug_print (lazy "SIMPLYFYING EQUALITIES...");
772 match equalities with
776 List.rev (simpl eq_uri env hd tl [])
780 (Printf.sprintf "equalities AFTER:\n%s\n"
782 (List.map Equality.string_of_equality res))));
786 let print_goals goals =
793 (* (string_of_proof p) ^ ", " ^ *) (CicPp.ppterm t)) gl
795 Printf.sprintf "%d: %s" d (String.concat "; " gl')) goals))
798 let pp_goal_set msg goals names =
799 let active_goals, passive_goals = goals in
800 prerr_endline ("////" ^ msg);
801 prerr_endline ("ACTIVE G: " ^
802 (String.concat "\n " (List.map (fun (_,_,g) -> CicPp.pp g names)
804 prerr_endline ("PASSIVE G: " ^
805 (String.concat "\n " (List.map (fun (_,_,g) -> CicPp.pp g names)
809 let check_if_goal_is_subsumed ((_,ctx,_) as env) table (goalproof,menv,ty) =
810 let names = Utils.names_of_context ctx in
812 | Cic.Appl[Cic.MutInd(uri,_,_);eq_ty;left;right]
813 when LibraryObjects.is_eq_URI uri ->
816 (0,Equality.Exact (Cic.Implicit None),(eq_ty,left,right,Utils.Eq),menv)
818 (* match Indexing.subsumption env table goal_equation with*)
819 match Indexing.unification env table goal_equation with
820 | Some (subst, equality, swapped ) ->
823 ("GOAL SUBSUMED IS: "^Equality.string_of_equality goal_equation ~env);
825 ("GOAL IS SUBSUMED BY: "^Equality.string_of_equality equality ~env);
826 prerr_endline ("SUBST:"^Subst.ppsubst ~names subst);
828 let (_,p,(ty,l,r,_),m,id) = Equality.open_equality equality in
829 let cicmenv = Subst.apply_subst_metasenv subst (m @ menv) in
832 Equality.symmetric eq_ty l id uri m
836 Some (goalproof, p, id, subst, cicmenv)
841 let check_if_goal_is_identity env = function
842 | (goalproof,m,Cic.Appl[Cic.MutInd(uri,_,ens);eq_ty;left;right])
843 when left = right && LibraryObjects.is_eq_URI uri ->
844 let reflproof = Equality.Exact (Equality.refl_proof uri eq_ty left) in
845 Some (goalproof, reflproof, 0, Subst.empty_subst,m)
846 | (goalproof,m,Cic.Appl[Cic.MutInd(uri,_,ens);eq_ty;left;right])
847 when LibraryObjects.is_eq_URI uri ->
848 (let _,context,_ = env in
851 Inference.unification m m context left right CicUniv.empty_ugraph
853 let reflproof = Equality.Exact (Equality.refl_proof uri eq_ty left) in
854 let m = Subst.apply_subst_metasenv s m in
855 Some (goalproof, reflproof, 0, s,m)
860 let rec check goal = function
864 | None -> check goal tl
865 | (Some p) as ok -> ok
868 let simplify_goal_set env goals active =
869 let active_goals, passive_goals = goals in
870 let find (_,_,g) where =
871 List.exists (fun (_,_,g1) -> Equality.meta_convertibility g g1) where
873 (* prova:tengo le passive semplificate
875 List.map (fun g -> snd (simplify_goal env g active)) passive_goals
878 (fun (acc_a,acc_p) goal ->
879 match simplify_goal env goal active with
882 if find g acc_p then acc_a,acc_p else acc_a,g::acc_p
884 if find g acc_a then acc_a,acc_p else g::acc_a,acc_p)
885 ([],passive_goals) active_goals
888 let check_if_goals_set_is_solved env active goals =
889 let active_goals, passive_goals = goals in
896 check_if_goal_is_identity env;
897 check_if_goal_is_subsumed env (snd active)])
898 (* provare active and passive?*)
902 let infer_goal_set env active goals =
903 let active_goals, passive_goals = goals in
904 let rec aux = function
905 | [] -> active_goals, []
907 let changed,selected = simplify_goal env hd active in
910 prerr_endline ("--------------- goal semplificato");
912 let (_,_,t1) = selected in
914 List.exists (fun (_,_,t) -> Equality.meta_convertibility t t1)
920 let passive_goals = tl in
921 let new_passive_goals =
922 if Utils.metas_of_term t1 = [] then passive_goals
924 let newmaxmeta,new' =
925 Indexing.superposition_left env (snd active) selected
928 maxmeta := newmaxmeta;
931 selected::active_goals, new_passive_goals
936 let infer_goal_set_with_current env current goals active =
937 let active_goals, passive_goals =
938 simplify_goal_set env goals active
940 let l,table,_ = build_table [current] in
944 let newmaxmeta, new' = Indexing.superposition_left env table g !maxmeta in
945 maxmeta := newmaxmeta;
947 passive_goals active_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 (** given-clause algorithm with full reduction strategy: NEW implementation *)
986 (* here goals is a set of goals in OR *)
988 eq_uri ((_,context,_) as env) goals theorems passive active max_iterations max_time
990 let initial_time = Unix.gettimeofday () in
991 let iterations_left iterno =
992 let now = Unix.gettimeofday () in
993 let time_left = max_time -. now in
994 let time_spent_until_now = now -. initial_time in
995 let iteration_medium_cost =
996 time_spent_until_now /. (float_of_int iterno)
998 let iterations_left = time_left /. iteration_medium_cost in
999 int_of_float iterations_left
1001 let rec step goals theorems passive active iterno =
1002 if iterno > max_iterations then
1003 (ParamodulationFailure "No more iterations to spend")
1004 else if Unix.gettimeofday () > max_time then
1005 (ParamodulationFailure "No more time to spend")
1008 (* print_status iterno goals active passive *)
1009 Printf.eprintf ".%!";
1011 (* PRUNING OF PASSIVE THAT WILL NEVER BE PROCESSED *)
1013 let selection_estimate = iterations_left iterno in
1014 let kept = size_of_passive passive in
1015 if kept > selection_estimate then
1017 (*Printf.eprintf "Too many passive equalities: pruning...";
1018 prune_passive selection_estimate active*) passive
1023 kept_clauses := (size_of_passive passive) + (size_of_active active);
1024 let goals = infer_goal_set env active goals
1026 match check_if_goals_set_is_solved env active goals with
1029 (Printf.sprintf "\nFound a proof in: %f\n"
1030 (Unix.gettimeofday() -. initial_time));
1031 ParamodulationSuccess p
1034 if passive_is_empty passive then
1035 if no_more_passive_goals goals then
1036 ParamodulationFailure "No more passive equations/goals"
1037 (*maybe this is a success! *)
1039 step goals theorems passive active (iterno+1)
1042 (* COLLECTION OF GARBAGED EQUALITIES *)
1043 if iterno mod 40 = 0 then
1045 print_status iterno goals active passive;
1046 let active = List.map Equality.id_of (fst active) in
1047 let passive = List.map Equality.id_of (fst passive) in
1048 let goal = ids_of_goal_set goals in
1049 Equality.collect active passive goal
1051 let current, passive = select env goals passive in
1052 (* SIMPLIFICATION OF CURRENT *)
1056 Equality.string_of_equality ~env current);
1059 forward_simplify eq_uri env current active
1062 | None -> step goals theorems passive active (iterno+1)
1064 (* GENERATION OF NEW EQUATIONS *)
1065 (* prerr_endline "infer"; *)
1066 let new' = infer eq_uri env current active in
1067 (* prerr_endline "infer goal"; *)
1069 match check_if_goals_set_is_solved env active goals with
1072 (Printf.sprintf "Found a proof in: %f\n"
1073 (Unix.gettimeofday() -. initial_time));
1074 ParamodulationSuccess p
1078 let al, tbl = active in
1079 al @ [current], Indexing.index tbl current
1082 infer_goal_set_with_current env current goals active
1084 (* FORWARD AND BACKWARD SIMPLIFICATION *)
1085 (* prerr_endline "fwd/back simpl"; *)
1086 let rec simplify new' active passive head =
1088 forward_simplify_new eq_uri env new' active
1090 let active, newa, retained, pruned =
1091 backward_simplify eq_uri env new' active
1094 List.fold_left filter_dependent passive pruned
1096 match newa, retained with
1097 | None, None -> active, passive, new', head
1099 | None, Some p -> simplify (new' @ p) active passive head
1100 | Some p, Some rp ->
1101 simplify (new' @ p @ rp) active passive (head @ p)
1103 let active, passive, new', head =
1104 simplify new' active passive []
1106 (* prerr_endline "simpl goal with new"; *)
1108 let a,b,_ = build_table new' in
1109 (* let _ = <:start<simplify_goal_set new>> in *)
1110 let rc = simplify_goal_set env goals (a,b) in
1111 (* let _ = <:stop<simplify_goal_set new>> in *)
1114 let passive = add_to_passive passive new' head in
1115 step goals theorems passive active (iterno+1)
1118 step goals theorems passive active 1
1121 let rec saturate_equations eq_uri env goal accept_fun passive active =
1122 elapsed_time := Unix.gettimeofday () -. !start_time;
1123 if !elapsed_time > !time_limit then
1126 let current, passive = select env ([goal],[]) passive in
1127 let res = forward_simplify eq_uri env current active in
1130 saturate_equations eq_uri env goal accept_fun passive active
1132 Utils.debug_print (lazy (Printf.sprintf "selected: %s"
1133 (Equality.string_of_equality ~env current)));
1134 let new' = infer eq_uri env current active in
1136 if Equality.is_identity env current then active
1138 let al, tbl = active in
1139 al @ [current], Indexing.index tbl current
1141 (* alla fine new' contiene anche le attive semplificate!
1142 * quindi le aggiungo alle passive insieme alle new *)
1143 let rec simplify new' active passive =
1144 let new' = forward_simplify_new eq_uri env new' active in
1145 let active, newa, retained, pruned =
1146 backward_simplify eq_uri env new' active in
1148 List.fold_left filter_dependent passive pruned in
1149 match newa, retained with
1150 | None, None -> active, passive, new'
1152 | None, Some p -> simplify (new' @ p) active passive
1153 | Some p, Some rp -> simplify (new' @ p @ rp) active passive
1155 let active, passive, new' = simplify new' active passive in
1159 (Printf.sprintf "active:\n%s\n"
1162 (fun e -> Equality.string_of_equality ~env e)
1168 (Printf.sprintf "new':\n%s\n"
1171 (fun e -> "Negative " ^
1172 (Equality.string_of_equality ~env e)) new'))))
1174 let new' = List.filter accept_fun new' in
1175 let passive = add_to_passive passive new' [] in
1176 saturate_equations eq_uri env goal accept_fun passive active
1179 let default_depth = !maxdepth
1180 and default_width = !maxwidth;;
1184 symbols_counter := 0;
1185 weight_age_counter := !weight_age_ratio;
1186 processed_clauses := 0;
1189 maximal_retained_equality := None;
1191 forward_simpl_time := 0.;
1192 forward_simpl_new_time := 0.;
1193 backward_simpl_time := 0.;
1194 passive_maintainance_time := 0.;
1195 derived_clauses := 0;
1200 let eq_of_goal = function
1201 | Cic.Appl [Cic.MutInd(uri,0,_);_;_;_] when LibraryObjects.is_eq_URI uri ->
1203 | _ -> raise (ProofEngineTypes.Fail (lazy ("The goal is not an equality ")))
1206 let eq_and_ty_of_goal = function
1207 | Cic.Appl [Cic.MutInd(uri,0,_);t;_;_] when LibraryObjects.is_eq_URI uri ->
1209 | _ -> raise (ProofEngineTypes.Fail (lazy ("The goal is not an equality ")))
1214 dbd ?(full=false) ?(depth=default_depth) ?(width=default_width)
1215 ?(timeout=600.) status =
1216 let module C = Cic in
1218 Indexing.init_index ();
1221 (* CicUnification.unif_ty := false;*)
1222 let proof, goalno = status in
1223 let uri, metasenv, meta_proof, term_to_prove = proof in
1224 let _, context, type_of_goal = CicUtil.lookup_meta goalno metasenv in
1225 let eq_uri = eq_of_goal type_of_goal in
1226 let cleaned_goal = Utils.remove_local_context type_of_goal in
1227 Utils.set_goal_symbols cleaned_goal;
1228 let names = Utils.names_of_context context in
1229 let eq_indexes, equalities, maxm = Inference.find_equalities context proof in
1230 let ugraph = CicUniv.empty_ugraph in
1231 let env = (metasenv, context, ugraph) in
1232 let goal = [], List.filter (fun (i,_,_)->i<>goalno) metasenv, cleaned_goal in
1234 let t1 = Unix.gettimeofday () in
1235 let lib_eq_uris, library_equalities, maxm =
1236 Inference.find_library_equalities caso_strano dbd context (proof, goalno) (maxm+2)
1238 let library_equalities = List.map snd library_equalities in
1239 let t2 = Unix.gettimeofday () in
1242 simplify_equalities eq_uri env (equalities@library_equalities)
1246 (Printf.sprintf "Time to retrieve equalities: %.9f\n" (t2 -. t1)));
1247 let t1 = Unix.gettimeofday () in
1250 let thms = Inference.find_library_theorems dbd env (proof, goalno) lib_eq_uris in
1251 let context_hyp = Inference.find_context_hypotheses env eq_indexes in
1252 context_hyp @ thms, []
1254 let refl_equal = LibraryObjects.eq_refl_URI ~eq:eq_uri in
1255 let t = CicUtil.term_of_uri refl_equal in
1256 let ty, _ = CicTypeChecker.type_of_aux' [] [] t CicUniv.empty_ugraph in
1259 let t2 = Unix.gettimeofday () in
1264 "Theorems:\n-------------------------------------\n%s\n"
1269 "Term: %s, type: %s"
1270 (CicPp.ppterm t) (CicPp.ppterm ty))
1274 (Printf.sprintf "Time to retrieve theorems: %.9f\n" (t2 -. t1)));
1276 let active = make_active () in
1277 let passive = make_passive equalities in
1278 let start = Unix.gettimeofday () in
1281 let goals = make_goals goal in
1282 given_clause_fullred dbd env goals theorems passive active
1284 let goals = make_goal_set goal in
1285 let max_iterations = 10000 in
1286 let max_time = Unix.gettimeofday () +. timeout (* minutes *) in
1288 eq_uri env goals theorems passive active max_iterations max_time
1290 let finish = Unix.gettimeofday () in
1291 (res, finish -. start)
1294 | ParamodulationFailure s ->
1295 raise (ProofEngineTypes.Fail (lazy ("NO proof found: " ^ s)))
1296 | ParamodulationSuccess
1297 (goalproof,newproof,subsumption_id,subsumption_subst, proof_menv) ->
1298 prerr_endline "Proof:";
1300 (Equality.pp_proof names goalproof newproof subsumption_subst
1301 subsumption_id type_of_goal);
1302 (* prerr_endline "ENDOFPROOFS"; *)
1304 prerr_endline ("max weight: " ^
1305 (string_of_int (Equality.max_weight goalproof newproof)));
1307 (* generation of the CIC proof *)
1309 List.filter (fun i -> i <> goalno)
1310 (ProofEngineHelpers.compare_metasenvs
1311 ~newmetasenv:metasenv ~oldmetasenv:proof_menv)
1313 let goal_proof, side_effects_t =
1314 let initial = Equality.add_subst subsumption_subst newproof in
1315 Equality.build_goal_proof
1316 eq_uri goalproof initial type_of_goal side_effects
1319 (* prerr_endline ("PROOF: " ^ CicPp.pp goal_proof names); *)
1320 let goal_proof = Subst.apply_subst subsumption_subst goal_proof in
1321 let metas_still_open_in_proof = Utils.metas_of_term goal_proof in
1322 (*prerr_endline (CicPp.pp goal_proof names);*)
1324 let goal_proof = (* Subst.apply_subst subsumption_subst *) goal_proof in
1325 let side_effects_t =
1326 List.map (Subst.apply_subst subsumption_subst) side_effects_t
1328 (* replacing fake mets with real ones *)
1329 (* prerr_endline "replacing metas..."; *)
1330 let irl=CicMkImplicit.identity_relocation_list_for_metavariable context in
1331 let goal_proof_menv, what, with_what,free_meta =
1333 (fun (acc1,acc2,acc3,uniq) (i,_,ty) ->
1336 acc1, (Cic.Meta(i,[]))::acc2, m::acc3, uniq
1338 [i,context,ty], (Cic.Meta(i,[]))::acc2,
1339 (Cic.Meta(i,irl)) ::acc3,Some (Cic.Meta(i,irl)))
1342 (fun (i,_,_) -> List.mem i metas_still_open_in_proof)
1346 (* we need this fake equality since the metas of the hypothesis may be
1347 * with a real local context *)
1348 ProofEngineReduction.replace_lifting
1349 ~equality:(fun x y ->
1350 match x,y with Cic.Meta(i,_),Cic.Meta(j,_) -> i=j | _-> false)
1351 ~what ~with_what ~where
1353 let goal_proof = replace goal_proof in
1354 (* ok per le meta libere... ma per quelle che c'erano e sono rimaste?
1355 * what mi pare buono, sostituisce solo le meta farlocche *)
1356 let side_effects_t = List.map replace side_effects_t in
1358 List.filter (fun i -> i <> goalno)
1359 (ProofEngineHelpers.compare_metasenvs
1360 ~oldmetasenv:metasenv ~newmetasenv:goal_proof_menv)
1362 (* prerr_endline ("freemetas: " ^ String.concat "," (List.map string_of_int
1364 (* check/refine/... build the new proof *)
1366 ProofEngineReduction.replace
1367 ~what:side_effects ~with_what:side_effects_t
1368 ~equality:(fun i t -> match t with Cic.Meta(j,_)->j=i|_->false)
1371 let subst_side_effects,real_menv,_ =
1372 let fail t s = raise (ProofEngineTypes.Fail (lazy (t^Lazy.force s))) in
1373 let free_metas_menv =
1374 List.map (fun i -> CicUtil.lookup_meta i goal_proof_menv) free_metas
1377 CicUnification.fo_unif_subst [] context (metasenv @ free_metas_menv)
1378 replaced_goal type_of_goal CicUniv.empty_ugraph
1380 | CicUnification.UnificationFailure s
1381 | CicUnification.Uncertain s
1382 | CicUnification.AssertFailure s ->
1383 fail "Maybe the local context of metas in the goal was not an IRL" s
1386 (goalno,(context,goal_proof,type_of_goal))::subst_side_effects
1388 (* prerr_endline ("MENVreal_menv: " ^ CicMetaSubst.ppmetasenv [] real_menv); *)
1391 CicTypeChecker.type_of_aux' real_menv context goal_proof
1392 CicUniv.empty_ugraph
1394 | CicUtil.Meta_not_found _
1395 | CicTypeChecker.TypeCheckerFailure _
1396 | CicTypeChecker.AssertFailure _
1397 | Invalid_argument "list_fold_left2" as exn ->
1398 prerr_endline "THE PROOF DOES NOT TYPECHECK!";
1399 prerr_endline (CicPp.pp goal_proof names);
1400 prerr_endline "THE PROOF DOES NOT TYPECHECK!";
1403 let proof, real_metasenv =
1404 ProofEngineHelpers.subst_meta_and_metasenv_in_proof
1405 proof goalno (CicMetaSubst.apply_subst final_subst) real_menv
1408 match free_meta with Some(Cic.Meta(m,_)) when m<>goalno ->[m] | _ ->[]
1412 "GOALS APERTI: %s\nMETASENV PRIMA:\n%s\nMETASENV DOPO:\n%s\n"
1413 (String.concat ", " (List.map string_of_int open_goals))
1414 (CicMetaSubst.ppmetasenv [] metasenv)
1415 (CicMetaSubst.ppmetasenv [] real_metasenv);
1417 prerr_endline (Printf.sprintf "\nTIME NEEDED: %8.2f" time);
1421 let main _ _ _ _ _ = () ;;
1423 let retrieve_and_print dbd term metasenv ugraph =
1424 let module C = Cic in
1425 let module T = CicTypeChecker in
1426 let module PET = ProofEngineTypes in
1427 let module PP = CicPp in
1428 let proof = None, (1, [], term)::metasenv, C.Meta (1, []), term in
1429 let status = PET.apply_tactic (PrimitiveTactics.intros_tac ()) (proof, 1) in
1430 let proof, goals = status in
1431 let goal' = List.nth goals 0 in
1432 let uri, metasenv, meta_proof, term_to_prove = proof in
1433 let _, context, type_of_goal = CicUtil.lookup_meta goal' metasenv in
1434 let eq_uri = eq_of_goal type_of_goal in
1435 let eq_indexes, equalities, maxm = Inference.find_equalities context proof in
1436 let ugraph = CicUniv.empty_ugraph in
1437 let env = (metasenv, context, ugraph) in
1438 let t1 = Unix.gettimeofday () in
1439 let lib_eq_uris, library_equalities, maxm =
1440 Inference.find_library_equalities false dbd context (proof, goal') (maxm+2) in
1441 let t2 = Unix.gettimeofday () in
1443 let equalities = (* equalities @ *) library_equalities in
1446 (Printf.sprintf "\n\nequalities:\n%s\n"
1450 (* Printf.sprintf "%s: %s" *)
1451 (UriManager.string_of_uri u)
1452 (* (string_of_equality e) *)
1455 Utils.debug_print (lazy "RETR: SIMPLYFYING EQUALITIES...");
1456 let rec simpl e others others_simpl =
1458 let active = (others @ others_simpl) in
1461 (fun t (_, e) -> Indexing.index t e)
1462 Indexing.empty active
1464 let res = forward_simplify eq_uri env e (active, tbl) in
1468 | None -> simpl hd tl others_simpl
1469 | Some e -> simpl hd tl ((u, e)::others_simpl)
1473 | None -> others_simpl
1474 | Some e -> (u, e)::others_simpl
1478 match equalities with
1481 let others = tl in (* List.map (fun e -> (Utils.Positive, e)) tl in *)
1483 List.rev (simpl (*(Positive,*) hd others [])
1487 (Printf.sprintf "\nequalities AFTER:\n%s\n"
1491 Printf.sprintf "%s: %s"
1492 (UriManager.string_of_uri u)
1493 (Equality.string_of_equality e)
1499 (Printf.sprintf "Time to retrieve equalities: %.9f\n" (t2 -. t1)))
1503 let main_demod_equalities dbd term metasenv ugraph =
1504 let module C = Cic in
1505 let module T = CicTypeChecker in
1506 let module PET = ProofEngineTypes in
1507 let module PP = CicPp in
1508 let proof = None, (1, [], term)::metasenv, C.Meta (1, []), term in
1509 let status = PET.apply_tactic (PrimitiveTactics.intros_tac ()) (proof, 1) in
1510 let proof, goals = status in
1511 let goal' = List.nth goals 0 in
1512 let _, metasenv, meta_proof, _ = proof in
1513 let _, context, goal = CicUtil.lookup_meta goal' metasenv in
1514 let eq_uri = eq_of_goal goal in
1515 let eq_indexes, equalities, maxm = Inference.find_equalities context proof in
1516 let lib_eq_uris, library_equalities, maxm =
1517 Inference.find_library_equalities false dbd context (proof, goal') (maxm+2)
1519 let library_equalities = List.map snd library_equalities in
1520 maxmeta := maxm+2; (* TODO ugly!! *)
1521 let irl = CicMkImplicit.identity_relocation_list_for_metavariable context in
1522 let new_meta_goal, metasenv, type_of_goal =
1523 let _, context, ty = CicUtil.lookup_meta goal' metasenv in
1526 (Printf.sprintf "\n\nTRYING TO INFER EQUALITIES MATCHING: %s\n\n"
1527 (CicPp.ppterm ty)));
1528 Cic.Meta (maxm+1, irl),
1529 (maxm+1, context, ty)::metasenv,
1532 let env = (metasenv, context, ugraph) in
1534 let goal = [], [], goal
1537 simplify_equalities eq_uri env (equalities@library_equalities)
1539 let active = make_active () in
1540 let passive = make_passive equalities in
1541 Printf.eprintf "\ncontext:\n%s\n" (PP.ppcontext context);
1542 Printf.eprintf "\nmetasenv:\n%s\n" (Utils.print_metasenv metasenv);
1543 Printf.eprintf "\nequalities:\n%s\n"
1546 (Equality.string_of_equality ~env) equalities));
1547 prerr_endline "--------------------------------------------------";
1548 prerr_endline "GO!";
1549 start_time := Unix.gettimeofday ();
1550 if !time_limit < 1. then time_limit := 60.;
1552 saturate_equations eq_uri env goal (fun e -> true) passive active
1556 List.fold_left (fun s e -> EqualitySet.add e s)
1557 EqualitySet.empty equalities
1560 if not (EqualitySet.mem e initial) then EqualitySet.add e s else s
1566 EqualitySet.elements (List.fold_left addfun EqualitySet.empty p)
1570 EqualitySet.elements (List.fold_left addfun EqualitySet.empty l)
1572 Printf.eprintf "\n\nRESULTS:\nActive:\n%s\n\nPassive:\n%s\n"
1573 (String.concat "\n" (List.map (Equality.string_of_equality ~env) active))
1574 (* (String.concat "\n"
1575 (List.map (fun e -> CicPp.ppterm (term_of_equality e)) active)) *)
1576 (* (String.concat "\n" (List.map (string_of_equality ~env) passive)); *)
1579 (fun e -> CicPp.ppterm (Equality.term_of_equality eq_uri e))
1584 Utils.debug_print (lazy ("EXCEPTION: " ^ (Printexc.to_string e)))
1588 let demodulate_tac ~dbd ((proof,goal)(*s initialstatus*)) =
1589 let curi,metasenv,pbo,pty = proof in
1590 let metano,context,ty = CicUtil.lookup_meta goal metasenv in
1591 let eq_uri = eq_of_goal ty in
1592 let eq_indexes, equalities, maxm =
1593 Inference.find_equalities context proof
1595 let lib_eq_uris, library_equalities, maxm =
1596 Inference.find_library_equalities false dbd context (proof, goal) (maxm+2) in
1597 if library_equalities = [] then prerr_endline "VUOTA!!!";
1598 let irl = CicMkImplicit.identity_relocation_list_for_metavariable context in
1599 let library_equalities = List.map snd library_equalities in
1600 let initgoal = [], [], ty in
1601 let env = (metasenv, context, CicUniv.empty_ugraph) in
1603 simplify_equalities eq_uri env (equalities@library_equalities)
1607 (fun tbl eq -> Indexing.index tbl eq)
1608 Indexing.empty equalities
1610 let changed,(newproof,newmetasenv, newty) =
1611 Indexing.demodulation_goal
1612 (metasenv,context,CicUniv.empty_ugraph) table initgoal
1616 let opengoal = Equality.Exact (Cic.Meta(maxm,irl)) in
1618 Equality.build_goal_proof
1619 eq_uri newproof opengoal ty [] context metasenv
1621 let extended_metasenv = (maxm,context,newty)::metasenv in
1622 let extended_status =
1623 (curi,extended_metasenv,pbo,pty),goal in
1624 let (status,newgoals) =
1625 ProofEngineTypes.apply_tactic
1626 (PrimitiveTactics.apply_tac ~term:proofterm)
1628 (status,maxm::newgoals)
1630 else (* if newty = ty then *)
1631 raise (ProofEngineTypes.Fail (lazy "no progress"))
1632 (*else ProofEngineTypes.apply_tactic
1633 (ReductionTactics.simpl_tac
1634 ~pattern:(ProofEngineTypes.conclusion_pattern None)) initialstatus*)
1637 let demodulate_tac ~dbd = ProofEngineTypes.mk_tactic (demodulate_tac ~dbd);;
1639 let rec find_in_ctx i name = function
1640 | [] -> raise (ProofEngineTypes.Fail (lazy ("Hypothesis not found: " ^ name)))
1641 | Some (Cic.Name name', _)::tl when name = name' -> i
1642 | _::tl -> find_in_ctx (i+1) name tl
1645 let rec position_of i x = function
1646 | [] -> assert false
1647 | j::tl when j <> x -> position_of (i+1) x tl
1652 * auto superposition target = NAME
1653 * [table = NAME_LIST] [demod_table = NAME_LIST] [subterms_only]
1655 * - if table is omitted no superposition will be performed
1656 * - if demod_table is omitted no demodulation will be prformed
1657 * - subterms_only is passed to Indexing.superposition_right
1659 * lists are coded using _ (example: H_H1_H2)
1662 let superposition_tac ~target ~table ~subterms_only ~demod_table status =
1664 Indexing.init_index ();
1665 let proof,goalno = status in
1666 let curi,metasenv,pbo,pty = proof in
1667 let metano,context,ty = CicUtil.lookup_meta goalno metasenv in
1668 let eq_uri,tty = eq_and_ty_of_goal ty in
1669 let env = (metasenv, context, CicUniv.empty_ugraph) in
1670 let names = Utils.names_of_context context in
1671 let eq_index, equalities, maxm = Inference.find_equalities context proof in
1673 let what = find_in_ctx 1 target context in
1674 List.nth equalities (position_of 0 what eq_index)
1679 let others = Str.split (Str.regexp "_") table in
1680 List.map (fun other -> find_in_ctx 1 other context) others
1683 (fun other -> List.nth equalities (position_of 0 other eq_index))
1688 let index = List.fold_left Indexing.index Indexing.empty eq_other in
1690 if table = "" then maxm,[eq_what] else
1691 Indexing.superposition_right
1692 ~subterms_only eq_uri maxm env index eq_what
1694 prerr_endline ("Superposition right:");
1695 prerr_endline ("\n eq: " ^ Equality.string_of_equality eq_what ~env);
1696 prerr_endline ("\n table: ");
1697 List.iter (fun e -> prerr_endline (" " ^ Equality.string_of_equality e ~env)) eq_other;
1698 prerr_endline ("\n result: ");
1699 List.iter (fun e -> prerr_endline (Equality.string_of_equality e ~env)) eql;
1700 prerr_endline ("\n result (cut&paste): ");
1703 let t = Equality.term_of_equality eq_uri e in
1704 prerr_endline (CicPp.pp t names))
1706 prerr_endline ("\n result proofs: ");
1708 prerr_endline (let _,p,_,_,_ = Equality.open_equality e in
1709 let s = match p with Equality.Exact _ -> Subst.empty_subst | Equality.Step (s,_) -> s in
1710 Subst.ppsubst s ^ "\n" ^
1711 CicPp.pp (Equality.build_proof_term eq_uri [] 0 p) names)) eql;
1712 if demod_table <> "" then
1715 if eql = [] then [eq_what] else eql
1718 let demod = Str.split (Str.regexp "_") demod_table in
1719 List.map (fun other -> find_in_ctx 1 other context) demod
1723 (fun demod -> List.nth equalities (position_of 0 demod eq_index))
1726 let table = List.fold_left Indexing.index Indexing.empty eq_demod in
1729 (fun (maxm,acc) e ->
1731 Indexing.demodulation_equality eq_uri maxm env table e
1736 let eql = List.rev eql in
1737 prerr_endline ("\n result [demod]: ");
1739 (fun e -> prerr_endline (Equality.string_of_equality e ~env)) eql;
1740 prerr_endline ("\n result [demod] (cut&paste): ");
1743 let t = Equality.term_of_equality eq_uri e in
1744 prerr_endline (CicPp.pp t names))
1750 let get_stats () = ""
1752 <:show<Saturation.>> ^ Indexing.get_stats () ^ Inference.get_stats () ^
1753 Equality.get_stats ()