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/.
31 (* 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 | ParamodulationFailure
75 | ParamodulationSuccess of (Inference.proof * Cic.metasenv) option
78 type goal = proof * Cic.metasenv * Cic.term;;
80 type theorem = Cic.term * Cic.term * Cic.metasenv;;
82 let symbols_of_equality (_, _, (_, left, right, _), _) =
83 let m1 = symbols_of_term left in
88 let c = TermMap.find k res in
89 TermMap.add k (c+v) res
92 (symbols_of_term right) m1
98 module OrderedEquality = struct
99 type t = Inference.equality
101 let compare eq1 eq2 =
102 match meta_convertibility_eq eq1 eq2 with
105 let w1, _, (ty, left, right, _), m1 = eq1
106 and w2, _, (ty', left', right', _), m2 = eq2 in
107 match Pervasives.compare w1 w2 with
109 let res = (List.length m1) - (List.length m2) in
110 if res <> 0 then res else Pervasives.compare eq1 eq2
114 module EqualitySet = Set.Make(OrderedEquality);;
116 exception Empty_list;;
118 let passive_is_empty = function
124 let size_of_passive ((passive_list, ps), _) = List.length passive_list
125 (* EqualitySet.cardinal ps *)
129 let size_of_active (active_list, _) = List.length active_list
132 let age_factor = 0.01;;
135 selects one equality from passive. The selection strategy is a combination
136 of weight, age and goal-similarity
139 let rec select env goals passive =
140 processed_clauses := !processed_clauses + 1;
142 match (List.rev goals) with (_, goal::_)::_ -> goal | _ -> assert false
144 let (pos_list, pos_set), passive_table = passive in
145 let remove eq l = List.filter (fun e -> e <> eq) l in
146 if !weight_age_ratio > 0 then
147 weight_age_counter := !weight_age_counter - 1;
148 match !weight_age_counter with
150 weight_age_counter := !weight_age_ratio;
152 | (hd:EqualitySet.elt)::tl ->
154 Indexing.remove_index passive_table hd
155 in hd, ((tl, EqualitySet.remove hd pos_set), passive_table)
157 | _ when (!symbols_counter > 0) ->
158 (symbols_counter := !symbols_counter - 1;
159 let cardinality map =
160 TermMap.fold (fun k v res -> res + v) map 0
163 let _, _, term = goal in
166 let card = cardinality symbols in
167 let foldfun k v (r1, r2) =
168 if TermMap.mem k symbols then
169 let c = TermMap.find k symbols in
170 let c1 = abs (c - v) in
176 let f equality (i, e) =
178 TermMap.fold foldfun (symbols_of_equality equality) (0, 0)
180 let c = others + (abs (common - card)) in
181 if c < i then (c, equality)
184 let e1 = EqualitySet.min_elt pos_set in
187 TermMap.fold foldfun (symbols_of_equality e1) (0, 0)
189 (others + (abs (common - card))), e1
191 let _, current = EqualitySet.fold f pos_set initial in
193 Indexing.remove_index passive_table current
196 ((remove current pos_list, EqualitySet.remove current pos_set),
199 symbols_counter := !symbols_ratio;
200 let current = EqualitySet.min_elt pos_set in
202 Indexing.remove_index passive_table current
205 ((remove current pos_list, EqualitySet.remove current pos_set),
210 (* initializes the passive set of equalities *)
211 let make_passive pos =
212 let set_of equalities =
213 List.fold_left (fun s e -> EqualitySet.add e s) EqualitySet.empty equalities
216 List.fold_left (fun tbl e -> Indexing.index tbl e) Indexing.empty pos
228 (* adds to passive a list of equalities new_pos *)
229 let add_to_passive passive new_pos =
230 let (pos_list, pos_set), table = passive in
231 let ok set equality = not (EqualitySet.mem equality set) in
232 let pos = List.filter (ok pos_set) new_pos in
234 List.fold_left (fun tbl e -> Indexing.index tbl e) table pos
236 let add set equalities =
237 List.fold_left (fun s e -> EqualitySet.add e s) set equalities
239 (pos_list @ pos, add pos_set pos),
244 (* removes from passive equalities that are estimated impossible to activate
245 within the current time limit *)
246 let prune_passive howmany (active, _) passive =
247 let (pl, ps), tbl = passive in
248 let howmany = float_of_int howmany
249 and ratio = float_of_int !weight_age_ratio in
252 int_of_float (if t -. v < 0.5 then t else v)
254 let in_weight = round (howmany *. ratio /. (ratio +. 1.))
255 and in_age = round (howmany /. (ratio +. 1.)) in
257 (lazy (Printf.sprintf "in_weight: %d, in_age: %d\n" in_weight in_age));
258 let symbols, card = None, 0
260 let counter = ref !symbols_ratio in
265 counter := !counter - 1;
266 if !counter = 0 then counter := !symbols_ratio in
267 let e = EqualitySet.min_elt ps in
268 let ps' = pickw (w-1) (EqualitySet.remove e ps) in
269 EqualitySet.add e ps'
271 let e = EqualitySet.min_elt ps in
272 let ps' = pickw (w-1) (EqualitySet.remove e ps) in
273 EqualitySet.add e ps'
277 let ps = pickw in_weight ps in
278 let rec picka w s l =
282 | hd::tl when not (EqualitySet.mem hd s) ->
283 let w, s, l = picka (w-1) s tl in
284 w, EqualitySet.add hd s, hd::l
286 let w, s, l = picka w s tl in
291 let _, ps, pl = picka in_age ps pl in
292 if not (EqualitySet.is_empty ps) then
293 maximal_retained_equality := Some (EqualitySet.max_elt ps);
296 (fun e tbl -> Indexing.index tbl e) ps Indexing.empty
302 (** inference of new equalities between current and some in active *)
303 let infer env current ((active_list:Inference.equality list), active_table) =
305 if Utils.debug_metas then
306 (ignore(Indexing.check_target c current "infer1");
307 ignore(List.map (function current -> Indexing.check_target c current "infer2") active_list));
310 Indexing.superposition_right !maxmeta env active_table current in
311 if Utils.debug_metas then
314 Indexing.check_target c current "sup0") res);
316 let rec infer_positive table = function
320 Indexing.superposition_right !maxmeta env table equality in
322 if Utils.debug_metas then
326 Indexing.check_target c current "sup2") res);
327 let pos = infer_positive table tl in
330 let maxm, copy_of_current = Inference.fix_metas !maxmeta current in
332 let curr_table = Indexing.index Indexing.empty current in
333 let pos = infer_positive curr_table (copy_of_current::active_list)
335 if Utils.debug_metas then
338 Indexing.check_target c current "sup3") pos);
341 derived_clauses := !derived_clauses + (List.length new_pos);
342 match !maximal_retained_equality with
345 ignore(assert false);
346 (* if we have a maximal_retained_equality, we can discard all equalities
347 "greater" than it, as they will never be reached... An equality is
348 greater than maximal_retained_equality if it is bigger
349 wrt. OrderedEquality.compare and it is less similar than
350 maximal_retained_equality to the current goal *)
351 List.filter (fun e -> OrderedEquality.compare e eq <= 0) new_pos
354 (* buttare via sign *)
356 (** simplifies current using active and passive *)
357 let forward_simplify env (sign,current) ?passive (active_list, active_table) =
358 let _, context, _ = env in
362 | Some ((_, _), pt) -> Some pt
364 let demodulate table current =
365 let newmeta, newcurrent =
366 Indexing.demodulation_equality !maxmeta env table sign current in
368 if is_identity env newcurrent then
371 (* (Printf.sprintf "\ncurrent was: %s\nnewcurrent is: %s\n" *)
372 (* (string_of_equality current) *)
373 (* (string_of_equality newcurrent))); *)
376 (* (Printf.sprintf "active is: %s" *)
377 (* (String.concat "\n" *)
378 (* (List.map (fun (_, e) -> (string_of_equality e)) active_list)))); *)
383 let rec demod current =
384 if Utils.debug_metas then
385 ignore (Indexing.check_target context current "demod0");
386 let res = demodulate active_table current in
387 if Utils.debug_metas then
388 ignore ((function None -> () | Some x ->
389 ignore (Indexing.check_target context x "demod1");()) res);
393 match passive_table with
395 | Some passive_table ->
396 match demodulate passive_table newcurrent with
398 | Some newnewcurrent ->
399 if newcurrent <> newnewcurrent then
401 else Some newnewcurrent
403 let res = demod current in
407 if Indexing.in_index active_table c then
410 match passive_table with
412 if Indexing.subsumption env active_table c = None then
416 | Some passive_table ->
417 if Indexing.in_index passive_table c then None
419 if Indexing.subsumption env active_table c = None then
420 if Indexing.subsumption env passive_table c = None then
428 type fs_time_info_t = {
429 mutable build_all: float;
430 mutable demodulate: float;
431 mutable subsumption: float;
434 let fs_time_info = { build_all = 0.; demodulate = 0.; subsumption = 0. };;
437 (** simplifies new using active and passive *)
438 let forward_simplify_new env new_pos ?passive active =
439 if Utils.debug_metas then
443 (fun current -> Indexing.check_target c current "forward new pos")
446 let t1 = Unix.gettimeofday () in
448 let active_list, active_table = active in
452 | Some ((_, _), pt) -> Some pt
454 let t2 = Unix.gettimeofday () in
455 fs_time_info.build_all <- fs_time_info.build_all +. (t2 -. t1);
457 let demodulate sign table target =
458 let newmeta, newtarget =
459 Indexing.demodulation_equality !maxmeta env table sign target in
463 let t1 = Unix.gettimeofday () in
464 (* we could also demodulate using passive. Currently we don't *)
466 List.map (demodulate Positive active_table) new_pos
468 let t2 = Unix.gettimeofday () in
469 fs_time_info.demodulate <- fs_time_info.demodulate +. (t2 -. t1);
474 if not (Inference.is_identity env e) then
475 if EqualitySet.mem e s then s
476 else EqualitySet.add e s
478 EqualitySet.empty new_pos
480 let new_pos = EqualitySet.elements new_pos_set in
483 match passive_table with
485 (fun e -> (Indexing.subsumption env active_table e = None))
486 | Some passive_table ->
487 (fun e -> ((Indexing.subsumption env active_table e = None) &&
488 (Indexing.subsumption env passive_table e = None)))
490 (* let t1 = Unix.gettimeofday () in *)
491 (* let t2 = Unix.gettimeofday () in *)
492 (* fs_time_info.subsumption <- fs_time_info.subsumption +. (t2 -. t1); *)
494 match passive_table with
496 (fun e -> not (Indexing.in_index active_table e))
497 | Some passive_table ->
499 not ((Indexing.in_index active_table e) ||
500 (Indexing.in_index passive_table e)))
502 List.filter subs (List.filter is_duplicate new_pos)
506 (** simplifies a goal with equalities in active and passive *)
507 let rec simplify_goal env goal ?passive (active_list, active_table) =
511 | Some ((_, _), pt) -> Some pt
514 let demodulate table goal =
515 let newmeta, newgoal =
516 Indexing.demodulation_goal !maxmeta env table goal in
518 goal <> newgoal, newgoal
521 match passive_table with
522 | None -> demodulate active_table goal
523 | Some passive_table ->
524 let changed, goal = demodulate active_table goal in
525 let changed', goal = demodulate passive_table goal in
526 (changed || changed'), goal
532 snd (simplify_goal env goal ?passive (active_list, active_table))
536 let simplify_goals env goals ?passive active =
537 let a_goals, p_goals = goals in
542 List.map (fun g -> snd (simplify_goal env g ?passive active)) gl in
548 (fun (a, p) (d, gl) ->
549 let changed = ref false in
553 let c, g = simplify_goal env g ?passive active in
554 changed := !changed || c; g) gl in
555 if !changed then (a, (d, gl)::p) else ((d, gl)::a, p))
556 ([], p_goals) a_goals
562 (** simplifies active usign new *)
563 let backward_simplify_active env new_pos new_table min_weight active =
564 let active_list, active_table = active in
565 let active_list, newa =
567 (fun equality (res, newn) ->
568 let ew, _, _, _ = equality in
569 if ew < min_weight then
572 match forward_simplify env (Utils.Positive, equality) (new_pos, new_table) with
582 List.exists (meta_convertibility_eq eq1) where
586 (fun eq (res, tbl) ->
587 if List.mem eq res then
589 else if (is_identity env eq) || (find eq res) then (
593 eq::res, Indexing.index tbl eq)
594 active_list ([], Indexing.empty),
597 if (is_identity env eq) then p
603 | _ -> active, Some newa
607 (** simplifies passive using new *)
608 let backward_simplify_passive env new_pos new_table min_weight passive =
609 let (pl, ps), passive_table = passive in
610 let f sign equality (resl, ress, newn) =
611 let ew, _, _, _ = equality in
612 if ew < min_weight then
613 equality::resl, ress, newn
615 match forward_simplify env (sign, equality) (new_pos, new_table) with
616 | None -> resl, EqualitySet.remove equality ress, newn
619 equality::resl, ress, newn
621 let ress = EqualitySet.remove equality ress in
624 let pl, ps, newp = List.fold_right (f Positive) pl ([], ps, []) in
627 (fun tbl e -> Indexing.index tbl e) Indexing.empty pl
630 | [] -> ((pl, ps), passive_table), None
631 | _ -> ((pl, ps), passive_table), Some (newp)
635 let backward_simplify env new' ?passive active =
636 let new_pos, new_table, min_weight =
639 let ew, _, _, _ = e in
640 e::l, Indexing.index t e, min ew w)
641 ([], Indexing.empty, 1000000) new'
644 backward_simplify_active env new_pos new_table min_weight active in
647 active, (make_passive []), newa, None
649 active, passive, newa, None
652 backward_simplify_passive env new_pos new_table min_weight passive in
653 active, passive, newa, newp *)
657 let close env new' given =
658 let new_pos, new_table, min_weight =
661 let ew, _, _, _ = e in
662 e::l, Indexing.index t e, min ew w)
663 ([], Indexing.empty, 1000000) (snd new')
667 let pos = infer env c (new_pos,new_table) in
672 let is_commutative_law eq =
673 let w, proof, (eq_ty, left, right, order), metas = eq in
674 match left,right with
675 Cic.Appl[f1;Cic.Meta _ as a1;Cic.Meta _ as b1],
676 Cic.Appl[f2;Cic.Meta _ as a2;Cic.Meta _ as b2] ->
677 f1 = f2 && a1 = b2 && a2 = b1
681 let prova env new' active =
682 let given = List.filter is_commutative_law (fst active) in
686 (Printf.sprintf "symmetric:\n%s\n"
689 (fun e -> string_of_equality ~env e)
694 (* returns an estimation of how many equalities in passive can be activated
695 within the current time limit *)
696 let get_selection_estimate () =
697 elapsed_time := (Unix.gettimeofday ()) -. !start_time;
698 (* !processed_clauses * (int_of_float (!time_limit /. !elapsed_time)) *)
700 ceil ((float_of_int !processed_clauses) *.
701 ((!time_limit (* *. 2. *)) /. !elapsed_time -. 1.)))
705 (** initializes the set of goals *)
706 let make_goals goal =
708 and passive = [0, [goal]] in
713 (** initializes the set of theorems *)
714 let make_theorems theorems =
719 let activate_goal (active, passive) =
722 | goal_conj::tl -> true, (goal_conj::active, tl)
723 | [] -> false, (active, passive)
725 true, (active,passive)
729 let activate_theorem (active, passive) =
731 | theorem::tl -> true, (theorem::active, tl)
732 | [] -> false, (active, passive)
737 let simplify_theorems env theorems ?passive (active_list, active_table) =
738 let pl, passive_table =
741 | Some ((pn, _), (pp, _), pt) ->
742 let pn = List.map (fun e -> (Negative, e)) pn
743 and pp = List.map (fun e -> (Positive, e)) pp in
746 let a_theorems, p_theorems = theorems in
747 let demodulate table theorem =
748 let newmeta, newthm =
749 Indexing.demodulation_theorem !maxmeta env table theorem in
751 theorem != newthm, newthm
753 let foldfun table (a, p) theorem =
754 let changed, theorem = demodulate table theorem in
755 if changed then (a, theorem::p) else (theorem::a, p)
757 let mapfun table theorem = snd (demodulate table theorem) in
758 match passive_table with
760 let p_theorems = List.map (mapfun active_table) p_theorems in
761 List.fold_left (foldfun active_table) ([], p_theorems) a_theorems
762 | Some passive_table ->
763 let p_theorems = List.map (mapfun active_table) p_theorems in
764 let p_theorems, a_theorems =
765 List.fold_left (foldfun active_table) ([], p_theorems) a_theorems in
766 let p_theorems = List.map (mapfun passive_table) p_theorems in
767 List.fold_left (foldfun passive_table) ([], p_theorems) a_theorems
771 let rec simpl env e others others_simpl =
772 let active = others @ others_simpl in
775 (fun t e -> Indexing.index t e)
776 Indexing.empty active
778 let res = forward_simplify env (Positive,e) (active, tbl) in
782 | None -> simpl env hd tl others_simpl
783 | Some e -> simpl env hd tl (e::others_simpl)
787 | None -> others_simpl
788 | Some e -> e::others_simpl
792 let simplify_equalities env equalities =
795 (Printf.sprintf "equalities:\n%s\n"
797 (List.map string_of_equality equalities))));
798 debug_print (lazy "SIMPLYFYING EQUALITIES...");
799 match equalities with
803 List.rev (simpl env hd tl [])
807 (Printf.sprintf "equalities AFTER:\n%s\n"
809 (List.map string_of_equality res))));
813 let print_goals goals =
820 (* (string_of_proof p) ^ ", " ^ *) (CicPp.ppterm t)) gl
822 Printf.sprintf "%d: %s" d (String.concat "; " gl')) goals))
825 let check_if_goal_is_subsumed env (proof,menv,ty) table =
827 | Cic.Appl[Cic.MutInd(uri,_,_);eq_ty;left;right]
828 when UriManager.eq uri (LibraryObjects.eq_URI ()) ->
829 (let goal_equation = 0,proof,(eq_ty,left,right,Eq),menv in
830 match Indexing.subsumption env table goal_equation with
831 | Some (subst, (_,p,_,m)) ->
832 let p = Inference.apply_subst subst (Inference.build_proof_term p) in
834 let rec repl = function
835 | Inference.ProofGoalBlock (_, gp) ->
836 Inference.ProofGoalBlock (Inference.BasicProof ([],p), gp)
837 | Inference.NoProof -> Inference.BasicProof ([],p)
838 | Inference.BasicProof _ -> Inference.BasicProof ([],p)
839 | Inference.SubProof (t, i, p2) ->
840 Inference.SubProof (t, i, repl p2)
845 Some (newp,Inference.apply_subst_metasenv subst m @ menv)
852 (** given-clause algorithm with full reduction strategy *)
853 let rec given_clause_fullred dbd env goals theorems ~passive active =
854 let goals = simplify_goals env goals ~passive active in
855 let _,context,_ = env in
856 let ok, goals = activate_goal goals in
857 (* let theorems = simplify_theorems env theorems ~passive active in *)
859 let names = List.map (HExtlib.map_option (fun (name,_) -> name)) context in
860 let _, _, t = List.hd (snd (List.hd (fst goals))) in
861 let _ = prerr_endline ("goal activated = " ^ (CicPp.pp t names)) in
865 (* (Printf.sprintf "\ngoals = \nactive\n%s\npassive\n%s\n" *)
866 (* (print_goals (fst goals)) (print_goals (snd goals)))); *)
867 (* let current = List.hd (fst goals) in *)
868 (* let p, _, t = List.hd (snd current) in *)
871 (* (Printf.sprintf "goal activated:\n%s\n%s\n" *)
872 (* (CicPp.ppterm t) (string_of_proof p))); *)
875 (* apply_goal_to_theorems dbd env theorems ~passive active goals in *)
876 let iseq uri = UriManager.eq uri (LibraryObjects.eq_URI ()) in
877 match (fst goals) with
878 | (_, [proof, m, Cic.Appl[Cic.MutInd(uri,_,ens);eq_ty;left;right]])::_
879 when left = right && iseq uri ->
881 Cic.Appl [Cic.MutConstruct (* reflexivity *)
882 (LibraryObjects.eq_URI (), 0, 1, []);eq_ty; left]
885 let rec repl = function
886 | Inference.ProofGoalBlock (_, gp) ->
887 Inference.ProofGoalBlock (Inference.BasicProof ([],p), gp)
888 | Inference.NoProof -> Inference.BasicProof ([],p)
889 | Inference.BasicProof _ -> Inference.BasicProof ([],p)
890 | Inference.SubProof (t, i, p2) ->
891 Inference.SubProof (t, i, repl p2)
895 in true, Some (newp,m)
896 | (_, [proof,m,ty])::_ ->
897 (match check_if_goal_is_subsumed env (proof,m,ty) (snd active) with
899 | Some (newproof,m) ->
900 prerr_endline "Proof found by subsumption!";
901 true, Some (newproof,m))
905 ( prerr_endline "esco qui";
907 let s = Printf.sprintf "actives:\n%s\n"
910 (fun (s, e) -> (string_of_sign s) ^ " " ^
911 (string_of_equality ~env e))
913 let sp = Printf.sprintf "passives:\n%s\n"
916 (string_of_equality ~env)
917 (let x,y,_ = passive in (fst x)@(fst y)))) in
920 ParamodulationSuccess (proof))
922 given_clause_fullred_aux dbd env goals theorems passive active
924 (* let ok', theorems = activate_theorem theorems in *)
926 (* let ok, goals = apply_theorem_to_goals env theorems active goals in *)
929 (* match (fst goals) with *)
930 (* | (_, [proof, _, _])::_ -> Some proof *)
931 (* | _ -> assert false *)
933 (* ParamodulationSuccess (proof, env) *)
935 (* given_clause_fullred_aux env goals theorems passive active *)
937 if (passive_is_empty passive) then ParamodulationFailure
938 else given_clause_fullred_aux dbd env goals theorems passive active
940 and given_clause_fullred_aux dbd env goals theorems passive active =
941 prerr_endline (string_of_int !counter ^
942 " MAXMETA: " ^ string_of_int !maxmeta ^
943 " LOCALMAX: " ^ string_of_int !Indexing.local_max ^
944 " #ACTIVES: " ^ string_of_int (size_of_active active) ^
945 " #PASSIVES: " ^ string_of_int (size_of_passive passive));
948 if !counter mod 10 = 0 then
950 let size = HExtlib.estimate_size (passive,active) in
951 let sizep = HExtlib.estimate_size (passive) in
952 let sizea = HExtlib.estimate_size (active) in
953 let (l1,s1),(l2,s2), t = passive in
954 let sizetbl = HExtlib.estimate_size t in
955 let sizel = HExtlib.estimate_size (l1,l2) in
956 let sizes = HExtlib.estimate_size (s1,s2) in
958 prerr_endline ("SIZE: " ^ string_of_int size);
959 prerr_endline ("SIZE P: " ^ string_of_int sizep);
960 prerr_endline ("SIZE A: " ^ string_of_int sizea);
961 prerr_endline ("SIZE TBL: " ^ string_of_int sizetbl ^
962 " SIZE L: " ^ string_of_int sizel ^
963 " SIZE S:" ^ string_of_int sizes);
966 if (size_of_active active) mod 50 = 0 then
967 (let s = Printf.sprintf "actives:\n%s\n"
970 (fun (s, e) -> (string_of_sign s) ^ " " ^
971 (string_of_equality ~env e))
973 let sp = Printf.sprintf "passives:\n%s\n"
976 (string_of_equality ~env)
977 (let x,y,_ = passive in (fst x)@(fst y)))) in
979 prerr_endline sp); *)
980 let time1 = Unix.gettimeofday () in
981 let (_,context,_) = env in
982 let selection_estimate = get_selection_estimate () in
983 let kept = size_of_passive passive in
985 if !time_limit = 0. || !processed_clauses = 0 then
987 else if !elapsed_time > !time_limit then (
988 debug_print (lazy (Printf.sprintf "Time limit (%.2f) reached: %.2f\n"
989 !time_limit !elapsed_time));
991 ) else if kept > selection_estimate then (
993 (lazy (Printf.sprintf ("Too many passive equalities: pruning..." ^^
994 "(kept: %d, selection_estimate: %d)\n")
995 kept selection_estimate));
996 prune_passive selection_estimate active passive
1001 let time2 = Unix.gettimeofday () in
1002 passive_maintainance_time := !passive_maintainance_time +. (time2 -. time1);
1004 kept_clauses := (size_of_passive passive) + (size_of_active active);
1005 match passive_is_empty passive with
1006 | true -> ParamodulationFailure
1007 (* given_clause_fullred dbd env goals theorems passive active *)
1009 let current, passive = select env (fst goals) passive in
1011 ("Selected = " ^ string_of_equality ~env current);
1013 (let w,p,(t,l,r,o),m = current in
1014 " size w: " ^ string_of_int (HExtlib.estimate_size w)^
1015 " size p: " ^ string_of_int (HExtlib.estimate_size p)^
1016 " size t: " ^ string_of_int (HExtlib.estimate_size t)^
1017 " size l: " ^ string_of_int (HExtlib.estimate_size l)^
1018 " size r: " ^ string_of_int (HExtlib.estimate_size r)^
1019 " size o: " ^ string_of_int (HExtlib.estimate_size o)^
1020 " size m: " ^ string_of_int (HExtlib.estimate_size m)^
1021 " size m-c: " ^ string_of_int
1022 (HExtlib.estimate_size (List.map (fun (x,_,_) -> x) m)))) *)
1023 let time1 = Unix.gettimeofday () in
1024 let res = forward_simplify env (Positive, current) ~passive active in
1025 let time2 = Unix.gettimeofday () in
1026 forward_simpl_time := !forward_simpl_time +. (time2 -. time1);
1029 (* weight_age_counter := !weight_age_counter + 1; *)
1030 given_clause_fullred dbd env goals theorems passive active
1032 debug_print (lazy (Printf.sprintf "selected: %s"
1033 (string_of_equality ~env current)));
1034 let t1 = Unix.gettimeofday () in
1035 let new' = infer env current active in
1039 (Printf.sprintf "new' (senza semplificare):\n%s\n"
1042 (fun e -> "Positive " ^
1043 (string_of_equality ~env e)) new'))))
1045 let t2 = Unix.gettimeofday () in
1046 infer_time := !infer_time +. (t2 -. t1);
1048 if is_identity env current then active
1050 let al, tbl = active in
1051 al @ [current], Indexing.index tbl current
1053 let rec simplify new' active passive =
1054 let t1 = Unix.gettimeofday () in
1055 let new' = forward_simplify_new env new'~passive active in
1056 let t2 = Unix.gettimeofday () in
1057 forward_simpl_new_time :=
1058 !forward_simpl_new_time +. (t2 -. t1);
1059 let t1 = Unix.gettimeofday () in
1060 let active, passive, newa, retained =
1061 backward_simplify env new' ~passive active in
1062 let t2 = Unix.gettimeofday () in
1063 backward_simpl_time := !backward_simpl_time +. (t2 -. t1);
1064 match newa, retained with
1065 | None, None -> active, passive, new'
1069 if Utils.debug_metas then
1072 (fun x->Indexing.check_target context x "simplify1")
1075 simplify (new' @ p) active passive
1076 | Some p, Some rp ->
1077 simplify (new' @ p @ rp) active passive
1079 let active, _, new' = simplify new' active passive in
1081 let new1 = prova env new' active in
1082 let new' = (fst new') @ (fst new1), (snd new') @ (snd new1) in
1088 (Printf.sprintf "new1:\n%s\n"
1091 (fun e -> "Negative " ^
1092 (string_of_equality ~env e)) neg) @
1094 (fun e -> "Positive " ^
1095 (string_of_equality ~env e)) pos)))))
1098 let k = size_of_passive passive in
1099 if k < (kept - 1) then
1100 processed_clauses := !processed_clauses + (kept - 1 - k);
1105 (Printf.sprintf "active:\n%s\n"
1108 (fun e -> (string_of_equality ~env e))
1114 (Printf.sprintf "new':\n%s\n"
1117 (fun e -> "Negative " ^
1118 (string_of_equality ~env e)) new')))))
1120 let passive = add_to_passive passive new' in
1121 given_clause_fullred dbd env goals theorems passive active
1125 let profiler0 = HExtlib.profile "P/Saturation.given_clause_fullred"
1127 let given_clause_fullred dbd env goals theorems passive active =
1128 profiler0.HExtlib.profile
1129 (given_clause_fullred dbd env goals theorems passive) active
1133 let rec saturate_equations env goal accept_fun passive active =
1134 elapsed_time := Unix.gettimeofday () -. !start_time;
1135 if !elapsed_time > !time_limit then
1138 let current, passive = select env [1, [goal]] passive in
1139 let res = forward_simplify env (Positive, current) ~passive active in
1142 saturate_equations env goal accept_fun passive active
1144 debug_print (lazy (Printf.sprintf "selected: %s"
1145 (string_of_equality ~env current)));
1146 let new' = infer env current active in
1148 if is_identity env current then active
1150 let al, tbl = active in
1151 al @ [current], Indexing.index tbl current
1153 let rec simplify new' active passive =
1154 let new' = forward_simplify_new env new' ~passive active in
1155 let active, passive, newa, retained =
1156 backward_simplify env new' ~passive active in
1157 match newa, retained with
1158 | None, None -> active, passive, new'
1160 | None, Some p -> simplify (new' @ p) active passive
1161 | Some p, Some rp -> simplify (new' @ p @ rp) active passive
1163 let active, passive, new' = simplify new' active passive in
1167 (Printf.sprintf "active:\n%s\n"
1170 (fun e -> string_of_equality ~env e)
1176 (Printf.sprintf "new':\n%s\n"
1179 (fun e -> "Negative " ^
1180 (string_of_equality ~env e)) new'))))
1182 let new' = List.filter accept_fun new' in
1183 let passive = add_to_passive passive new' in
1184 saturate_equations env goal accept_fun passive active
1188 let main dbd full term metasenv ugraph =
1189 let module C = Cic in
1190 let module T = CicTypeChecker in
1191 let module PET = ProofEngineTypes in
1192 let module PP = CicPp in
1193 let proof = None, (1, [], term)::metasenv, C.Meta (1, []), term in
1194 let status = PET.apply_tactic (PrimitiveTactics.intros_tac ()) (proof, 1) in
1195 let proof, goals = status in
1196 let goal' = List.nth goals 0 in
1197 let _, metasenv, meta_proof, _ = proof in
1198 let _, context, goal = CicUtil.lookup_meta goal' metasenv in
1199 let eq_indexes, equalities, maxm = find_equalities context proof in
1200 let lib_eq_uris, library_equalities, maxm =
1202 find_library_equalities dbd context (proof, goal') (maxm+2)
1204 let library_equalities = List.map snd library_equalities in
1205 maxmeta := maxm+2; (* TODO ugly!! *)
1206 let irl = CicMkImplicit.identity_relocation_list_for_metavariable context in
1207 let new_meta_goal, metasenv, type_of_goal =
1208 let _, context, ty = CicUtil.lookup_meta goal' metasenv in
1211 (Printf.sprintf "\n\nTIPO DEL GOAL: %s\n\n" (CicPp.ppterm ty)));
1212 Cic.Meta (maxm+1, irl),
1213 (maxm+1, context, ty)::metasenv,
1216 let env = (metasenv, context, ugraph) in
1217 let t1 = Unix.gettimeofday () in
1220 let theorems = find_library_theorems dbd env (proof, goal') lib_eq_uris in
1221 let context_hyp = find_context_hypotheses env eq_indexes in
1222 context_hyp @ theorems, []
1225 let us = UriManager.string_of_uri (LibraryObjects.eq_URI ()) in
1226 UriManager.uri_of_string (us ^ "#xpointer(1/1/1)")
1228 let t = CicUtil.term_of_uri refl_equal in
1229 let ty, _ = CicTypeChecker.type_of_aux' [] [] t CicUniv.empty_ugraph in
1232 let t2 = Unix.gettimeofday () in
1235 (Printf.sprintf "Time to retrieve theorems: %.9f\n" (t2 -. t1)));
1240 "Theorems:\n-------------------------------------\n%s\n"
1245 "Term: %s, type: %s" (CicPp.ppterm t) (CicPp.ppterm ty))
1249 let goal = Inference.BasicProof ([],new_meta_goal), [], goal in
1250 let equalities = simplify_equalities env
1251 (equalities@library_equalities) in
1252 let active = make_active () in
1253 let passive = make_passive equalities in
1254 Printf.printf "\ncurrent goal: %s\n"
1255 (let _, _, g = goal in CicPp.ppterm g);
1256 Printf.printf "\ncontext:\n%s\n" (PP.ppcontext context);
1257 Printf.printf "\nmetasenv:\n%s\n" (print_metasenv metasenv);
1258 Printf.printf "\nequalities:\n%s\n"
1261 (string_of_equality ~env) equalities));
1262 (* (equalities @ library_equalities))); *)
1263 print_endline "--------------------------------------------------";
1264 let start = Unix.gettimeofday () in
1265 print_endline "GO!";
1266 start_time := Unix.gettimeofday ();
1268 let goals = make_goals goal in
1269 (if !use_fullred then given_clause_fullred else given_clause_fullred)
1270 dbd env goals theorems passive active
1272 let finish = Unix.gettimeofday () in
1275 | ParamodulationFailure ->
1276 Printf.printf "NO proof found! :-(\n\n"
1277 | ParamodulationSuccess (Some (proof, env)) ->
1278 let proof = Inference.build_proof_term proof in
1279 Printf.printf "OK, found a proof!\n";
1280 (* REMEMBER: we have to instantiate meta_proof, we should use
1281 apply the "apply" tactic to proof and status
1283 let names = names_of_context context in
1284 print_endline (PP.pp proof names);
1287 (fun m (_, _, _, menv) -> m @ menv) metasenv equalities
1292 CicTypeChecker.type_of_aux' newmetasenv context proof ugraph
1294 print_endline (string_of_float (finish -. start));
1296 "\nGOAL was: %s\nPROOF has type: %s\nconvertible?: %s\n\n"
1297 (CicPp.pp type_of_goal names) (CicPp.pp ty names)
1299 (fst (CicReduction.are_convertible
1300 context type_of_goal ty ug)));
1302 Printf.printf "\nEXCEPTION!!! %s\n" (Printexc.to_string e);
1303 Printf.printf "MAXMETA USED: %d\n" !maxmeta;
1304 print_endline (string_of_float (finish -. start));*)
1308 | ParamodulationSuccess None ->
1309 Printf.printf "Success, but no proof?!?\n\n"
1314 ((Printf.sprintf ("infer_time: %.9f\nforward_simpl_time: %.9f\n" ^^
1315 "forward_simpl_new_time: %.9f\n" ^^
1316 "backward_simpl_time: %.9f\n")
1317 !infer_time !forward_simpl_time !forward_simpl_new_time
1318 !backward_simpl_time) ^
1319 (Printf.sprintf "beta_expand_time: %.9f\n"
1320 !Indexing.beta_expand_time) ^
1321 (Printf.sprintf "passive_maintainance_time: %.9f\n"
1322 !passive_maintainance_time) ^
1323 (Printf.sprintf " successful unification/matching time: %.9f\n"
1324 !Indexing.match_unif_time_ok) ^
1325 (Printf.sprintf " failed unification/matching time: %.9f\n"
1326 !Indexing.match_unif_time_no) ^
1327 (Printf.sprintf " indexing retrieval time: %.9f\n"
1328 !Indexing.indexing_retrieval_time) ^
1329 (Printf.sprintf " demodulate_term.build_newtarget_time: %.9f\n"
1330 !Indexing.build_newtarget_time) ^
1331 (Printf.sprintf "derived %d clauses, kept %d clauses.\n"
1332 !derived_clauses !kept_clauses))
1336 print_endline ("EXCEPTION: " ^ (Printexc.to_string exc));
1342 let default_depth = !maxdepth
1343 and default_width = !maxwidth;;
1347 Indexing.local_max := 100;
1348 symbols_counter := 0;
1349 weight_age_counter := !weight_age_ratio;
1350 processed_clauses := 0;
1353 maximal_retained_equality := None;
1355 forward_simpl_time := 0.;
1356 forward_simpl_new_time := 0.;
1357 backward_simpl_time := 0.;
1358 passive_maintainance_time := 0.;
1359 derived_clauses := 0;
1361 Indexing.beta_expand_time := 0.;
1362 Inference.metas_of_proof_time := 0.;
1366 dbd ?(full=false) ?(depth=default_depth) ?(width=default_width) status =
1367 let module C = Cic in
1369 Indexing.init_index ();
1373 (* CicUnification.unif_ty := false;*)
1374 let proof, goal = status in
1376 let uri, metasenv, meta_proof, term_to_prove = proof in
1377 let _, context, goal = CicUtil.lookup_meta goal' metasenv in
1378 prerr_endline ("CTX: " ^ string_of_int (HExtlib.estimate_size context));
1379 let eq_indexes, equalities, maxm = find_equalities context proof in
1380 let new_meta_goal, metasenv, type_of_goal =
1382 CicMkImplicit.identity_relocation_list_for_metavariable context in
1383 let _, context, ty = CicUtil.lookup_meta goal' metasenv in
1385 (lazy (Printf.sprintf "\n\nTIPO DEL GOAL: %s\n" (CicPp.ppterm ty)));
1386 Cic.Meta (maxm+1, irl),
1387 (maxm+1, context, ty)::metasenv,
1390 let ugraph = CicUniv.empty_ugraph in
1391 let env = (metasenv, context, ugraph) in
1392 let goal = Inference.BasicProof ([],new_meta_goal), [], goal in
1394 let t1 = Unix.gettimeofday () in
1395 let lib_eq_uris, library_equalities, maxm =
1396 find_library_equalities dbd context (proof, goal') (maxm+2)
1398 let library_equalities = List.map snd library_equalities in
1399 let t2 = Unix.gettimeofday () in
1401 let equalities = simplify_equalities env (equalities@library_equalities) in
1404 (Printf.sprintf "Time to retrieve equalities: %.9f\n" (t2 -. t1)));
1405 let t1 = Unix.gettimeofday () in
1408 let thms = find_library_theorems dbd env (proof, goal') lib_eq_uris in
1409 let context_hyp = find_context_hypotheses env eq_indexes in
1410 context_hyp @ thms, []
1413 let us = UriManager.string_of_uri (LibraryObjects.eq_URI ()) in
1414 UriManager.uri_of_string (us ^ "#xpointer(1/1/1)")
1416 let t = CicUtil.term_of_uri refl_equal in
1417 let ty, _ = CicTypeChecker.type_of_aux' [] [] t CicUniv.empty_ugraph in
1420 let t2 = Unix.gettimeofday () in
1425 "Theorems:\n-------------------------------------\n%s\n"
1430 "Term: %s, type: %s"
1431 (CicPp.ppterm t) (CicPp.ppterm ty))
1435 (Printf.sprintf "Time to retrieve theorems: %.9f\n" (t2 -. t1)));
1437 let active = make_active () in
1438 let passive = make_passive equalities in
1439 let start = Unix.gettimeofday () in
1441 let goals = make_goals goal in
1442 given_clause_fullred dbd env goals theorems passive active
1444 let finish = Unix.gettimeofday () in
1445 (res, finish -. start)
1448 | ParamodulationSuccess (Some (proof, proof_menv)) ->
1449 prerr_endline "OK, found a proof!";
1450 debug_print (lazy "OK, found a proof!");
1451 let proof = Inference.build_proof_term proof in
1452 let equality_for_replace i t1 =
1454 | C.Meta (n, _) -> n = i
1457 prerr_endline "replacing metas";
1458 let proof_menv, what, with_what =
1460 CicMkImplicit.identity_relocation_list_for_metavariable context
1463 (fun (acc1,acc2,acc3) (i,_,ty) ->
1464 (i,context,ty)::acc1,
1465 (Cic.Meta(i,[]))::acc2,
1466 (Cic.Meta(i,irl)) ::acc3)
1467 ([],[],[]) proof_menv
1469 let proof = ProofEngineReduction.replace_lifting
1474 (* prerr_endline (CicPp.ppterm proof); *)
1475 let names = names_of_context context in
1478 match new_meta_goal with
1479 | C.Meta (i, _) -> i | _ -> assert false
1481 List.filter (fun (i, _, _) -> i <> i1 && i <> goal') metasenv
1483 let newmetasenv = newmetasenv@proof_menv in
1487 prerr_endline "type checking ... ";
1488 CicTypeChecker.type_of_aux' newmetasenv context proof ugraph
1490 prerr_endline (CicPp.pp proof [](* names *));
1494 "\nGOAL was: %s\nPROOF has type: %s\nconvertible?: %s\n"
1495 (CicPp.pp type_of_goal names) (CicPp.pp ty names)
1497 (fst (CicReduction.are_convertible
1498 context type_of_goal ty ug)))));
1500 ProofEngineReduction.replace
1501 ~equality:equality_for_replace
1502 ~what:[goal'] ~with_what:[proof]
1507 (Printf.sprintf "status:\n%s\n%s\n%s\n%s\n"
1508 (match uri with Some uri -> UriManager.string_of_uri uri
1510 (print_metasenv newmetasenv)
1511 (CicPp.pp real_proof [](* names *))
1512 (CicPp.pp term_to_prove names)));
1513 ((uri, newmetasenv, real_proof, term_to_prove),
1514 List.map (fun (i,_,_) -> i) proof_menv)
1515 with CicTypeChecker.TypeCheckerFailure _ ->
1516 debug_print (lazy "THE PROOF DOESN'T TYPECHECK!!!");
1517 debug_print (lazy (CicPp.pp proof names));
1518 raise (ProofEngineTypes.Fail
1519 (lazy "Found a proof, but it doesn't typecheck"))
1521 let tall = fs_time_info.build_all in
1522 let tdemodulate = fs_time_info.demodulate in
1523 let tsubsumption = fs_time_info.subsumption in
1527 (Printf.sprintf "\nTIME NEEDED: %.9f" time) ^
1528 (Printf.sprintf "\ntall: %.9f" tall) ^
1529 (Printf.sprintf "\ntdemod: %.9f" tdemodulate) ^
1530 (Printf.sprintf "\ntsubsumption: %.9f" tsubsumption) ^
1531 (Printf.sprintf "\ninfer_time: %.9f" !infer_time) ^
1532 (Printf.sprintf "\nbeta_expand_time: %.9f\n"
1533 !Indexing.beta_expand_time) ^
1534 (Printf.sprintf "\nmetas_of_proof: %.9f\n"
1535 !Inference.metas_of_proof_time) ^
1536 (Printf.sprintf "\nforward_simpl_times: %.9f" !forward_simpl_time) ^
1537 (Printf.sprintf "\nforward_simpl_new_times: %.9f"
1538 !forward_simpl_new_time) ^
1539 (Printf.sprintf "\nbackward_simpl_times: %.9f" !backward_simpl_time) ^
1540 (Printf.sprintf "\npassive_maintainance_time: %.9f"
1541 !passive_maintainance_time))
1545 raise (ProofEngineTypes.Fail (lazy "NO proof found"))
1548 (* dummy function called within matita to trigger linkage *)
1552 let retrieve_and_print dbd term metasenv ugraph =
1553 let module C = Cic in
1554 let module T = CicTypeChecker in
1555 let module PET = ProofEngineTypes in
1556 let module PP = CicPp in
1557 let proof = None, (1, [], term)::metasenv, C.Meta (1, []), term in
1558 let status = PET.apply_tactic (PrimitiveTactics.intros_tac ()) (proof, 1) in
1559 let proof, goals = status in
1560 let goal' = List.nth goals 0 in
1561 let uri, metasenv, meta_proof, term_to_prove = proof in
1562 let _, context, goal = CicUtil.lookup_meta goal' metasenv in
1563 let eq_indexes, equalities, maxm = find_equalities context proof in
1564 let new_meta_goal, metasenv, type_of_goal =
1566 CicMkImplicit.identity_relocation_list_for_metavariable context in
1567 let _, context, ty = CicUtil.lookup_meta goal' metasenv in
1569 (lazy (Printf.sprintf "\n\nTIPO DEL GOAL: %s\n" (CicPp.ppterm ty)));
1570 Cic.Meta (maxm+1, irl),
1571 (maxm+1, context, ty)::metasenv,
1574 let ugraph = CicUniv.empty_ugraph in
1575 let env = (metasenv, context, ugraph) in
1576 let t1 = Unix.gettimeofday () in
1577 let lib_eq_uris, library_equalities, maxm =
1578 find_library_equalities dbd context (proof, goal') (maxm+2) in
1579 let t2 = Unix.gettimeofday () in
1581 let equalities = (* equalities @ *) library_equalities in
1584 (Printf.sprintf "\n\nequalities:\n%s\n"
1588 (* Printf.sprintf "%s: %s" *)
1589 (UriManager.string_of_uri u)
1590 (* (string_of_equality e) *)
1593 debug_print (lazy "RETR: SIMPLYFYING EQUALITIES...");
1594 let rec simpl e others others_simpl =
1596 let active = List.map (fun (u, e) -> (Positive, e))
1597 (others @ others_simpl) in
1600 (fun t (_, e) -> Indexing.index t e)
1601 Indexing.empty active
1603 let res = forward_simplify env (Positive, e) (active, tbl) in
1607 | None -> simpl hd tl others_simpl
1608 | Some e -> simpl hd tl ((u, e)::others_simpl)
1612 | None -> others_simpl
1613 | Some e -> (u, e)::others_simpl
1617 match equalities with
1620 let others = tl in (* List.map (fun e -> (Positive, e)) tl in *)
1622 List.rev (simpl (*(Positive,*) hd others [])
1626 (Printf.sprintf "\nequalities AFTER:\n%s\n"
1630 Printf.sprintf "%s: %s"
1631 (UriManager.string_of_uri u)
1632 (string_of_equality e)
1638 (Printf.sprintf "Time to retrieve equalities: %.9f\n" (t2 -. t1)))
1642 let main_demod_equalities dbd term metasenv ugraph =
1643 let module C = Cic in
1644 let module T = CicTypeChecker in
1645 let module PET = ProofEngineTypes in
1646 let module PP = CicPp in
1647 let proof = None, (1, [], term)::metasenv, C.Meta (1, []), term in
1648 let status = PET.apply_tactic (PrimitiveTactics.intros_tac ()) (proof, 1) in
1649 let proof, goals = status in
1650 let goal' = List.nth goals 0 in
1651 let _, metasenv, meta_proof, _ = proof in
1652 let _, context, goal = CicUtil.lookup_meta goal' metasenv in
1653 let eq_indexes, equalities, maxm = find_equalities context proof in
1654 let lib_eq_uris, library_equalities, maxm =
1655 find_library_equalities dbd context (proof, goal') (maxm+2)
1657 let library_equalities = List.map snd library_equalities in
1658 maxmeta := maxm+2; (* TODO ugly!! *)
1659 let irl = CicMkImplicit.identity_relocation_list_for_metavariable context in
1660 let new_meta_goal, metasenv, type_of_goal =
1661 let _, context, ty = CicUtil.lookup_meta goal' metasenv in
1664 (Printf.sprintf "\n\nTRYING TO INFER EQUALITIES MATCHING: %s\n\n"
1665 (CicPp.ppterm ty)));
1666 Cic.Meta (maxm+1, irl),
1667 (maxm+1, context, ty)::metasenv,
1670 let env = (metasenv, context, ugraph) in
1672 let goal = Inference.BasicProof ([],new_meta_goal), [], goal in
1673 let equalities = simplify_equalities env (equalities@library_equalities) in
1674 let active = make_active () in
1675 let passive = make_passive equalities in
1676 Printf.printf "\ncontext:\n%s\n" (PP.ppcontext context);
1677 Printf.printf "\nmetasenv:\n%s\n" (print_metasenv metasenv);
1678 Printf.printf "\nequalities:\n%s\n"
1681 (string_of_equality ~env) equalities));
1682 print_endline "--------------------------------------------------";
1683 print_endline "GO!";
1684 start_time := Unix.gettimeofday ();
1685 if !time_limit < 1. then time_limit := 60.;
1687 saturate_equations env goal (fun e -> true) passive active
1691 List.fold_left (fun s e -> EqualitySet.add e s)
1692 EqualitySet.empty equalities
1695 if not (EqualitySet.mem e initial) then EqualitySet.add e s else s
1701 EqualitySet.elements (List.fold_left addfun EqualitySet.empty p)
1705 EqualitySet.elements (List.fold_left addfun EqualitySet.empty l)
1707 Printf.printf "\n\nRESULTS:\nActive:\n%s\n\nPassive:\n%s\n"
1708 (String.concat "\n" (List.map (string_of_equality ~env) active))
1709 (* (String.concat "\n"
1710 (List.map (fun e -> CicPp.ppterm (term_of_equality e)) active)) *)
1711 (* (String.concat "\n" (List.map (string_of_equality ~env) passive)); *)
1713 (List.map (fun e -> CicPp.ppterm (term_of_equality e)) passive));
1717 debug_print (lazy ("EXCEPTION: " ^ (Printexc.to_string e)))
1721 let demodulate_tac ~dbd ~pattern ((proof,goal) as initialstatus) =
1722 let module I = Inference in
1723 let curi,metasenv,pbo,pty = proof in
1724 let metano,context,ty = CicUtil.lookup_meta goal metasenv in
1725 let eq_indexes, equalities, maxm = I.find_equalities context proof in
1726 let lib_eq_uris, library_equalities, maxm =
1727 I.find_library_equalities dbd context (proof, goal) (maxm+2) in
1728 if library_equalities = [] then prerr_endline "VUOTA!!!";
1729 let irl = CicMkImplicit.identity_relocation_list_for_metavariable context in
1730 let library_equalities = List.map snd library_equalities in
1731 let goalterm = Cic.Meta (metano,irl) in
1732 let initgoal = Inference.BasicProof ([],goalterm), [], ty in
1733 let env = (metasenv, context, CicUniv.empty_ugraph) in
1734 let equalities = simplify_equalities env (equalities@library_equalities) in
1737 (fun tbl eq -> Indexing.index tbl eq)
1738 Indexing.empty equalities
1740 let newmeta,(newproof,newmetasenv, newty) = Indexing.demodulation_goal
1741 maxm (metasenv,context,CicUniv.empty_ugraph) table initgoal
1743 if newmeta != maxm then
1745 let opengoal = Cic.Meta(maxm,irl) in
1747 Inference.build_proof_term ~noproof:opengoal newproof in
1748 let extended_metasenv = (maxm,context,newty)::metasenv in
1749 let extended_status =
1750 (curi,extended_metasenv,pbo,pty),goal in
1751 let (status,newgoals) =
1752 ProofEngineTypes.apply_tactic
1753 (PrimitiveTactics.apply_tac ~term:proofterm)
1755 (status,maxm::newgoals)
1757 else if newty = ty then
1758 raise (ProofEngineTypes.Fail (lazy "no progress"))
1759 else ProofEngineTypes.apply_tactic
1760 (ReductionTactics.simpl_tac ~pattern)
1764 let demodulate_tac ~dbd ~pattern =
1765 ProofEngineTypes.mk_tactic (demodulate_tac ~dbd ~pattern)