From 801f0eb3eabe1cbcd66d6a3f52c24eb8f1189611 Mon Sep 17 00:00:00 2001 From: Enrico Tassi Date: Tue, 28 Mar 2006 08:22:51 +0000 Subject: [PATCH] more profiling and fixes for paramod --- components/binaries/Makefile | 2 +- components/binaries/saturate/Makefile | 30 ++ .../saturate}/saturate_main.ml | 0 components/cic_proof_checking/cicPp.ml | 12 +- .../cic_proof_checking/cicTypeChecker.ml | 5 +- components/cic_unification/cicMetaSubst.ml | 5 + components/cic_unification/cicUnification.ml | 10 +- components/cic_unification/cicUnification.mli | 1 + components/extlib/hExtlib.ml | 14 +- components/lexicon/lexiconSync.ml | 2 +- components/tactics/inversion.ml | 3 +- components/tactics/inversion_principle.ml | 1 - components/tactics/paramodulation/Makefile | 25 +- components/tactics/paramodulation/indexing.ml | 326 ++++++++++-------- .../tactics/paramodulation/inference.ml | 26 +- .../tactics/paramodulation/saturation.ml | 32 +- matita/tests/bool.ma | 28 +- 17 files changed, 297 insertions(+), 225 deletions(-) create mode 100644 components/binaries/saturate/Makefile rename components/{tactics/paramodulation => binaries/saturate}/saturate_main.ml (100%) diff --git a/components/binaries/Makefile b/components/binaries/Makefile index 523fce7e7..a2b89ee97 100644 --- a/components/binaries/Makefile +++ b/components/binaries/Makefile @@ -1,6 +1,6 @@ H=@ -BINARIES=extractor table_creator utilities +BINARIES=extractor table_creator utilities saturate all: $(BINARIES:%=rec@all@%) opt: $(BINARIES:%=rec@opt@%) diff --git a/components/binaries/saturate/Makefile b/components/binaries/saturate/Makefile new file mode 100644 index 000000000..40ff4c3a7 --- /dev/null +++ b/components/binaries/saturate/Makefile @@ -0,0 +1,30 @@ +H=@ + +REQUIRES = helm-grafite_parser helm-tactics + +INTERFACE_FILES = +IMPLEMENTATION_FILES = $(INTERFACE_FILES:%.mli=%.ml) +EXTRA_OBJECTS_TO_INSTALL = +EXTRA_OBJECTS_TO_CLEAN = \ + saturate saturate.opt + +all: saturate + $(H)echo -n +opt: saturate.opt + $(H)echo -n + +saturate: saturate_main.ml + $(H)echo " OCAMLC $<" + $(H)$(OCAMLFIND) ocamlc \ + -I ../../tactics/paramodulation/ -thread -package "$(REQUIRES)" -linkpkg -o $@ $< + +saturate.opt: saturate_main.ml + $(H)echo " OCAMLOPT $<" + $(H)$(OCAMLFIND) ocamlopt \ + -I ../../tactics/paramodulation/ -thread -package "$(REQUIRES)" -linkpkg -o $@ $< + +clean: + $(H)rm -f *.cm[iox] *.a *.o + $(H)rm -f saturate saturate.opt + +include ../../../Makefile.defs diff --git a/components/tactics/paramodulation/saturate_main.ml b/components/binaries/saturate/saturate_main.ml similarity index 100% rename from components/tactics/paramodulation/saturate_main.ml rename to components/binaries/saturate/saturate_main.ml diff --git a/components/cic_proof_checking/cicPp.ml b/components/cic_proof_checking/cicPp.ml index 2a7a3f2d0..32daa4945 100644 --- a/components/cic_proof_checking/cicPp.ml +++ b/components/cic_proof_checking/cicPp.ml @@ -79,10 +79,10 @@ let rec pp t l = | C.Var (uri,exp_named_subst) -> UriManager.string_of_uri (*UriManager.name_of_uri*) uri ^ pp_exp_named_subst exp_named_subst l | C.Meta (n,l1) -> - "?" ^ (string_of_int n) ^ "[" ^ + "?" ^ (string_of_int n) (* ^ "[" ^ String.concat " ; " (List.rev_map (function None -> "_" | Some t -> pp t l) l1) ^ - "]" + "]" *) | C.Sort s -> (match s with C.Prop -> "Prop" @@ -357,7 +357,7 @@ let rec check_rec ctx string_name = | Cic.Implicit _ -> string_name | Cic.Cast (te,ty) -> check_rec ctx string_name te | Cic.Prod (name,so,dest) -> - let l_string_name = check_rec ctx string_name so in + let _l_string_name = check_rec ctx string_name so in check_rec (name::ctx) string_name dest | Cic.Lambda (name,so,dest) -> let string_name = @@ -390,11 +390,11 @@ let rec check_rec ctx string_name = | _ -> assert false) in remove_prefix name string_name | Cic.MutCase (_,_,_,te,pl) -> - let strig_name = remove_prefix "match" string_name in + let _strig_name = remove_prefix "match" string_name in let string_name = check_rec ctx string_name te in List.fold_right (fun t s -> check_rec ctx s t) pl string_name | Cic.Fix (_,fl) -> - let strig_name = remove_prefix "fix" string_name in + let _strig_name = remove_prefix "fix" string_name in let names = List.map (fun (name,_,_,_) -> name) fl in let onames = List.rev (List.map (function name -> Cic.Name name) names) @@ -402,7 +402,7 @@ let rec check_rec ctx string_name = List.fold_right (fun (_,_,_,bo) s -> check_rec (onames@ctx) s bo) fl string_name | Cic.CoFix (_,fl) -> - let strig_name = remove_prefix "cofix" string_name in + let _strig_name = remove_prefix "cofix" string_name in let names = List.map (fun (name,_,_) -> name) fl in let onames = List.rev (List.map (function name -> Cic.Name name) names) diff --git a/components/cic_proof_checking/cicTypeChecker.ml b/components/cic_proof_checking/cicTypeChecker.ml index 3df3dc354..25fa7ef21 100644 --- a/components/cic_proof_checking/cicTypeChecker.ml +++ b/components/cic_proof_checking/cicTypeChecker.ml @@ -2156,9 +2156,12 @@ let typecheck_obj ~logger uri obj = (** wrappers which instantiate fresh loggers *) +let profiler = HExtlib.profile "K/CicTypeChecker.type_of_aux'" + let type_of_aux' ?(subst = []) metasenv context t ugraph = let logger = new CicLogger.logger in - type_of_aux' ~logger ~subst metasenv context t ugraph + profiler.HExtlib.profile + (type_of_aux' ~logger ~subst metasenv context t) ugraph let typecheck_obj uri obj = let logger = new CicLogger.logger in diff --git a/components/cic_unification/cicMetaSubst.ml b/components/cic_unification/cicMetaSubst.ml index 53efcf96e..353662328 100644 --- a/components/cic_unification/cicMetaSubst.ml +++ b/components/cic_unification/cicMetaSubst.ml @@ -253,6 +253,11 @@ let apply_subst = apply_subst_gen ~appl_fun s t ;; +let profiler = HExtlib.profile "U/CicMetaSubst.apply_subst" +let apply_subst s t = + profiler.HExtlib.profile (apply_subst s) t + + let rec apply_subst_context subst context = (* incr apply_subst_context_counter; diff --git a/components/cic_unification/cicUnification.ml b/components/cic_unification/cicUnification.ml index d1e010ca6..1ca5bb1df 100644 --- a/components/cic_unification/cicUnification.ml +++ b/components/cic_unification/cicUnification.ml @@ -39,10 +39,13 @@ let profiler_beta_expand = HExtlib.profile "fo_unif_subst.beta_expand" let profiler_deref = HExtlib.profile "fo_unif_subst.deref'" let profiler_are_convertible = HExtlib.profile "fo_unif_subst.are_convertible" +let profile = HExtlib.profile "U/CicTypeChecker.type_of_aux'" + let type_of_aux' metasenv subst context term ugraph = let foo () = try - CicTypeChecker.type_of_aux' ~subst metasenv context term ugraph + profile.HExtlib.profile + (CicTypeChecker.type_of_aux' ~subst metasenv context term) ugraph with CicTypeChecker.TypeCheckerFailure msg -> let msg = @@ -129,6 +132,8 @@ let eta_reduce after_beta_expansion after_beta_expansion_body with WrongShape -> after_beta_expansion +let unif_ty = ref true + let rec beta_expand test_equality_only metasenv subst context t arg ugraph = let module S = CicSubstitution in let module C = Cic in @@ -389,7 +394,8 @@ debug_print (lazy ("restringo Meta n." ^ (string_of_int n) ^ "on variable n." ^ (lower m1 m2) (upper m1 m2) ugraph in begin - let subst,metasenv,ugraph1 = + let subst,metasenv,ugraph1 = + if not (!unif_ty) then subst,metasenv,ugraph else let (_,_,meta_type) = CicUtil.lookup_meta n metasenv in (try let tyt,ugraph1 = diff --git a/components/cic_unification/cicUnification.mli b/components/cic_unification/cicUnification.mli index e1a6c2899..5d0b34e28 100644 --- a/components/cic_unification/cicUnification.mli +++ b/components/cic_unification/cicUnification.mli @@ -56,3 +56,4 @@ val fo_unif_subst : Cic.term -> Cic.term -> CicUniv.universe_graph -> Cic.substitution * Cic.metasenv * CicUniv.universe_graph + val unif_ty : bool ref diff --git a/components/extlib/hExtlib.ml b/components/extlib/hExtlib.ml index cf43e15a0..8a0c8cf7d 100644 --- a/components/extlib/hExtlib.ml +++ b/components/extlib/hExtlib.ml @@ -34,9 +34,13 @@ let something_profiled = ref false let _ = if !something_profiled then at_exit - (fun _ -> prerr_endline - (Printf.sprintf "!! %-39s %6s %9s %9s %9s" - "function" "#calls" "total" "max" "average")) + (fun _ -> + prerr_endline + (Printf.sprintf "!! %39s ---------- --------- --------- ---------" + (String.make 39 '-')); + prerr_endline + (Printf.sprintf "!! %-39s %10s %9s %9s %9s" + "function" "#calls" "total" "max" "average")) let profiling_printings = ref (fun _ -> true) let set_profiling_printings f = profiling_printings := f @@ -67,11 +71,11 @@ let profile ?(enable = true) s = in at_exit (fun () -> - if !profiling_printings s && !total <> 0. then + if !profiling_printings s && !calls <> 0 then begin something_profiled := true; prerr_endline - (Printf.sprintf "!! %-39s %6d %9.4f %9.4f %9.4f" + (Printf.sprintf "!! %-39s %10d %9.4f %9.4f %9.4f" s !calls !total !max (!total /. (float_of_int !calls))) end); { profile = profile } diff --git a/components/lexicon/lexiconSync.ml b/components/lexicon/lexiconSync.ml index f88a79971..30031943d 100644 --- a/components/lexicon/lexiconSync.ml +++ b/components/lexicon/lexiconSync.ml @@ -41,7 +41,7 @@ let alias_diff ~from status = status.LexiconEngine.aliases [] let alias_diff = - let profiler = HExtlib.profile "alias_diff (conteggiato anche in include)" in + let profiler = HExtlib.profile "alias_diff(conteg. anche in include)" in fun ~from status -> profiler.HExtlib.profile (alias_diff ~from) status (** given a uri and a type list (the contructors types) builds a list of pairs diff --git a/components/tactics/inversion.ml b/components/tactics/inversion.ml index 0ff369a9a..f5e2a8476 100644 --- a/components/tactics/inversion.ml +++ b/components/tactics/inversion.ml @@ -209,8 +209,7 @@ let private_inversion_tac ~term = (List.map (fun t -> ( match (T.type_of_aux' metasenv context t CicUniv.empty_ugraph) with - (term,graph) -> term - |_ -> assert false)) + (term,graph) -> term)) parameters) in let consno = List.length cons_list in diff --git a/components/tactics/inversion_principle.ml b/components/tactics/inversion_principle.ml index 2138893d3..b16b133ba 100644 --- a/components/tactics/inversion_principle.ml +++ b/components/tactics/inversion_principle.ml @@ -105,7 +105,6 @@ let rec get_prop_arity sort rightparam_tys(*only to name m's*) created_vars_ty Cic.Sort(Cic.Prop)) else Cic.Sort Cic.Prop - | _ -> assert false ;; (* created vars is empty at the beginning *) diff --git a/components/tactics/paramodulation/Makefile b/components/tactics/paramodulation/Makefile index f1b613400..2f3afa5ab 100644 --- a/components/tactics/paramodulation/Makefile +++ b/components/tactics/paramodulation/Makefile @@ -1,23 +1,6 @@ -PACKAGE = dummy - -LOCALLINKOPTS = -package helm-cic_disambiguation,helm-content_pres,helm-grafite,helm-grafite_parser,helm-tactics - -include ../../../Makefile.defs -include ../../Makefile.common - -all $(PACKAGE).cma :saturate - @echo -n -opt $(PACKAGE).cmxa:saturate.opt - @echo -n - -saturate: saturate_main.ml $(LIBRARIES) - @echo " OCAMLC $<" - @$(OCAMLC) $(LOCALLINKOPTS) -thread -linkpkg -o $@ $< -saturate.opt: saturate_main.ml $(LIBRARIES) - @echo " OCAMLOPT $<" - @$(OCAMLOPT) $(LOCALLINKOPTS) -thread -linkpkg -o $@ $< - -clean: - rm -f saturate saturate.opt +all: + @make -C .. $@ +%: + @make -C .. $@ diff --git a/components/tactics/paramodulation/indexing.ml b/components/tactics/paramodulation/indexing.ml index 48abdf84e..b4cf802d0 100644 --- a/components/tactics/paramodulation/indexing.ml +++ b/components/tactics/paramodulation/indexing.ml @@ -45,13 +45,13 @@ let check_equation env equation msg = CicTypeChecker.type_of_aux' metasenv' context right ugraph; () with - CicUtil.Meta_not_found _ as exn -> - begin - prerr_endline msg; - prerr_endline (CicPp.ppterm left); - prerr_endline (CicPp.ppterm right); - raise exn - end + CicUtil.Meta_not_found _ as exn -> + begin + prerr_endline msg; + prerr_endline (CicPp.ppterm left); + prerr_endline (CicPp.ppterm right); + raise exn + end *) type retrieval_mode = Matching | Unification;; @@ -60,10 +60,10 @@ let string_of_res ?env = function None -> "None" | Some (t, s, m, u, ((p,e), eq_URI)) -> - Printf.sprintf "Some: (%s, %s, %s)" - (Utils.string_of_pos p) - (Inference.string_of_equality ?env e) - (CicPp.ppterm t) + Printf.sprintf "Some: (%s, %s, %s)" + (Utils.string_of_pos p) + (Inference.string_of_equality ?env e) + (CicPp.ppterm t) ;; let print_res ?env res = @@ -83,10 +83,10 @@ let print_candidates ?env mode term res = prerr_endline (String.concat "\n" (List.map - (fun (p, e) -> - Printf.sprintf "| (%s, %s)" (Utils.string_of_pos p) - (Inference.string_of_equality ?env e)) - res)); + (fun (p, e) -> + Printf.sprintf "| (%s, %s)" (Utils.string_of_pos p) + (Inference.string_of_equality ?env e)) + res)); ;; @@ -103,7 +103,7 @@ let init_index = Index.init_index let check_disjoint_invariant subst metasenv msg = if (List.exists - (fun (i,_,_) -> (List.exists (fun (j,_) -> i=j) subst)) metasenv) + (fun (i,_,_) -> (List.exists (fun (j,_) -> i=j) subst)) metasenv) then begin prerr_endline ("not disjoint: " ^ msg); @@ -124,9 +124,9 @@ let check_for_duplicates metas msg = let check_res res msg = match res with Some (t, subst, menv, ug, (eq_found, eq_URI)) -> - let eqs = Inference.string_of_equality (snd eq_found) in - check_disjoint_invariant subst menv msg; - check_for_duplicates menv (msg ^ "\nchecking " ^ eqs); + let eqs = Inference.string_of_equality (snd eq_found) in + check_disjoint_invariant subst menv msg; + check_for_duplicates menv (msg ^ "\nchecking " ^ eqs); | None -> () ;; @@ -152,7 +152,7 @@ let check_target context target msg = else () in try CicTypeChecker.type_of_aux' - metas context (Inference.build_proof_term proof) CicUniv.empty_ugraph + metas context (Inference.build_proof_term proof) CicUniv.empty_ugraph with e -> prerr_endline msg; prerr_endline (Inference.string_of_proof proof); @@ -202,6 +202,10 @@ let get_candidates ?env mode tree term = res ;; +let profiler = HExtlib.profile "P/Indexing.get_candidates" + +let get_candidates ?env mode tree term = + profiler.HExtlib.profile (get_candidates ?env mode tree) term let match_unif_time_ok = ref 0.;; let match_unif_time_no = ref 0.;; @@ -242,16 +246,16 @@ let rec find_matches metasenv context ugraph lift_amount term termty = | candidate::tl -> let pos, (_, proof, (ty, left, right, o), metas) = candidate in if Utils.debug_metas then - ignore(check_target context (snd candidate) "find_matches"); + ignore(check_target context (snd candidate) "find_matches"); if Utils.debug_res then - begin - let c = "eq = " ^ (Inference.string_of_equality (snd candidate)) ^ "\n"in - let t = "t = " ^ (CicPp.ppterm term) ^ "\n" in + begin + let c = "eq = " ^ (Inference.string_of_equality (snd candidate)) ^ "\n"in + let t = "t = " ^ (CicPp.ppterm term) ^ "\n" in let m = "metas = " ^ (CicMetaSubst.ppmetasenv [] metas) ^ "\n" in let p = "proof = " ^ (CicPp.ppterm (Inference.build_proof_term proof)) ^ "\n" in - check_for_duplicates metas "gia nella metas"; - check_for_duplicates (metasenv @ metas) ("not disjoint" ^ c ^ t ^ m ^ p) - end; + check_for_duplicates metas "gia nella metas"; + check_for_duplicates (metasenv @ metas) ("not disjoint" ^ c ^ t ^ m ^ p) + end; if check && not (fst (CicReduction.are_convertible ~metasenv context termty ty ugraph)) then ( find_matches metasenv context ugraph lift_amount term termty tl @@ -268,11 +272,11 @@ let rec find_matches metasenv context ugraph lift_amount term termty = match_unif_time_ok := !match_unif_time_ok +. (t2 -. t1); r with - | Inference.MatchingFailure as e -> + | Inference.MatchingFailure as e -> let t2 = Unix.gettimeofday () in match_unif_time_no := !match_unif_time_no +. (t2 -. t1); raise e - | CicUtil.Meta_not_found _ as exn -> raise exn + | CicUtil.Meta_not_found _ as exn -> raise exn in Some (C.Rel (1 + lift_amount), subst', metasenv', ugraph', (candidate, eq_URI)) @@ -283,13 +287,13 @@ let rec find_matches metasenv context ugraph lift_amount term termty = in if o <> U.Incomparable then let res = - try - do_match c eq_URI + try + do_match c eq_URI with Inference.MatchingFailure -> - find_matches metasenv context ugraph lift_amount term termty tl - in - if Utils.debug_res then ignore (check_res res "find1"); - res + find_matches metasenv context ugraph lift_amount term termty tl + in + if Utils.debug_res then ignore (check_res res "find1"); + res else let res = try do_match c eq_URI @@ -312,7 +316,6 @@ let rec find_matches metasenv context ugraph lift_amount term termty = find_matches metasenv context ugraph lift_amount term termty tl ;; - (* as above, but finds all the matching equalities, and the matching condition can be either Inference.matching or Inference.unification @@ -387,6 +390,18 @@ let rec find_all_matches ?(unif_fun=Inference.unification) lift_amount term termty tl ;; +let find_all_matches + ?unif_fun metasenv context ugraph lift_amount term termty l += + let rc = + find_all_matches + ?unif_fun metasenv context ugraph lift_amount term termty l + in + (*prerr_endline "CANDIDATES:"; + List.iter (fun (_,x)->prerr_endline (Inference.string_of_equality x)) l; + prerr_endline ("MATCHING:" ^ CicPp.ppterm term ^ " are " ^ string_of_int + (List.length rc));*) + rc (* returns true if target is subsumed by some equality in table @@ -426,7 +441,7 @@ let subsumption env table target = try let r = Inference.matching menv m context what other ugraph - in + in let t2 = Unix.gettimeofday () in match_unif_time_ok := !match_unif_time_ok +. (t2 -. t1); r @@ -448,20 +463,20 @@ let subsumption env table target = true, subst else let rightr = - match right with - | Cic.Meta _ -> [] - | _ -> + match right with + | Cic.Meta _ -> [] + | _ -> let rightc = get_candidates Matching table right in - find_all_matches ~unif_fun:Inference.matching - metasenv context ugraph 0 right ty rightc + find_all_matches ~unif_fun:Inference.matching + metasenv context ugraph 0 right ty rightc in - ok left rightr + ok left rightr in (* (if r then *) (* debug_print *) -(* (lazy *) -(* (Printf.sprintf "SUBSUMPTION! %s\n%s\n" *) -(* (Inference.string_of_equality target) (Utils.print_subst s)))); *) +(* (lazy *) +(* (Printf.sprintf "SUBSUMPTION! %s\n%s\n" *) +(* (Inference.string_of_equality target) (Utils.print_subst s)))); *) r, s ;; @@ -479,85 +494,85 @@ let rec demodulation_aux ?from ?(typecheck=false) match term with | C.Meta _ -> None | term -> - let termty, ugraph = + let termty, ugraph = if typecheck then CicTypeChecker.type_of_aux' metasenv context term ugraph else C.Implicit None, ugraph - in - let res = + in + let res = find_matches metasenv context ugraph lift_amount term termty candidates - in + in if Utils.debug_res then ignore(check_res res "demod1"); - if res <> None then + if res <> None then res - else + else match term with - | C.Appl l -> - let res, ll = - List.fold_left - (fun (res, tl) t -> - if res <> None then - (res, tl @ [S.lift 1 t]) - else - let r = - demodulation_aux ~from:"1" metasenv context ugraph table - lift_amount t - in - match r with - | None -> (None, tl @ [S.lift 1 t]) - | Some (rel, _, _, _, _) -> (r, tl @ [rel])) - (None, []) l - in ( - match res with - | None -> None - | Some (_, subst, menv, ug, eq_found) -> - Some (C.Appl ll, subst, menv, ug, eq_found) - ) - | C.Prod (nn, s, t) -> - let r1 = - demodulation_aux ~from:"2" - metasenv context ugraph table lift_amount s in ( - match r1 with - | None -> - let r2 = - demodulation_aux metasenv - ((Some (nn, C.Decl s))::context) ugraph - table (lift_amount+1) t - in ( - match r2 with - | None -> None - | Some (t', subst, menv, ug, eq_found) -> - Some (C.Prod (nn, (S.lift 1 s), t'), - subst, menv, ug, eq_found) - ) - | Some (s', subst, menv, ug, eq_found) -> - Some (C.Prod (nn, s', (S.lift 1 t)), - subst, menv, ug, eq_found) - ) - | C.Lambda (nn, s, t) -> - let r1 = - demodulation_aux - metasenv context ugraph table lift_amount s in ( - match r1 with - | None -> - let r2 = - demodulation_aux metasenv - ((Some (nn, C.Decl s))::context) ugraph - table (lift_amount+1) t - in ( - match r2 with - | None -> None - | Some (t', subst, menv, ug, eq_found) -> - Some (C.Lambda (nn, (S.lift 1 s), t'), - subst, menv, ug, eq_found) - ) - | Some (s', subst, menv, ug, eq_found) -> - Some (C.Lambda (nn, s', (S.lift 1 t)), - subst, menv, ug, eq_found) - ) - | t -> - None + | C.Appl l -> + let res, ll = + List.fold_left + (fun (res, tl) t -> + if res <> None then + (res, tl @ [S.lift 1 t]) + else + let r = + demodulation_aux ~from:"1" metasenv context ugraph table + lift_amount t + in + match r with + | None -> (None, tl @ [S.lift 1 t]) + | Some (rel, _, _, _, _) -> (r, tl @ [rel])) + (None, []) l + in ( + match res with + | None -> None + | Some (_, subst, menv, ug, eq_found) -> + Some (C.Appl ll, subst, menv, ug, eq_found) + ) + | C.Prod (nn, s, t) -> + let r1 = + demodulation_aux ~from:"2" + metasenv context ugraph table lift_amount s in ( + match r1 with + | None -> + let r2 = + demodulation_aux metasenv + ((Some (nn, C.Decl s))::context) ugraph + table (lift_amount+1) t + in ( + match r2 with + | None -> None + | Some (t', subst, menv, ug, eq_found) -> + Some (C.Prod (nn, (S.lift 1 s), t'), + subst, menv, ug, eq_found) + ) + | Some (s', subst, menv, ug, eq_found) -> + Some (C.Prod (nn, s', (S.lift 1 t)), + subst, menv, ug, eq_found) + ) + | C.Lambda (nn, s, t) -> + let r1 = + demodulation_aux + metasenv context ugraph table lift_amount s in ( + match r1 with + | None -> + let r2 = + demodulation_aux metasenv + ((Some (nn, C.Decl s))::context) ugraph + table (lift_amount+1) t + in ( + match r2 with + | None -> None + | Some (t', subst, menv, ug, eq_found) -> + Some (C.Lambda (nn, (S.lift 1 s), t'), + subst, menv, ug, eq_found) + ) + | Some (s', subst, menv, ug, eq_found) -> + Some (C.Lambda (nn, s', (S.lift 1 t)), + subst, menv, ug, eq_found) + ) + | t -> + None in if Utils.debug_res then ignore(check_res res "demod_aux output"); res @@ -571,6 +586,8 @@ let demod_counter = ref 1;; exception Foo +let profiler = HExtlib.profile "P/Indexing.demod_eq[build_new_target]" + (** demodulation, when target is an equality *) let rec demodulation_equality ?from newmeta env table sign target = let module C = Cic in @@ -598,9 +615,9 @@ let rec demodulation_equality ?from newmeta env table sign target = if Utils.debug_metas then begin ignore(check_for_duplicates menv "input1"); - ignore(check_disjoint_invariant subst menv "input2"); + ignore(check_disjoint_invariant subst menv "input2"); let substs = CicMetaSubst.ppsubst subst in - ignore(check_target context (snd eq_found) ("input3" ^ substs)) + ignore(check_target context (snd eq_found) ("input3" ^ substs)) end; let pos, (_, proof', (ty, what, other, _), menv') = eq_found in let ty = @@ -669,18 +686,18 @@ let rec demodulation_equality ?from newmeta env table sign target = let newmenv = (* Inference.filter subst *) menv in let _ = if Utils.debug_metas then - try ignore(CicTypeChecker.type_of_aux' + try ignore(CicTypeChecker.type_of_aux' newmenv context (Inference.build_proof_term newproof) ugraph); - () - with exc -> + () + with exc -> prerr_endline "sempre lui"; prerr_endline (CicMetaSubst.ppsubst subst); - prerr_endline (CicPp.ppterm (Inference.build_proof_term newproof)); + prerr_endline (CicPp.ppterm (Inference.build_proof_term newproof)); prerr_endline ("+++++++++++++termine: " ^ (CicPp.ppterm t)); prerr_endline ("+++++++++++++what: " ^ (CicPp.ppterm what)); prerr_endline ("+++++++++++++other: " ^ (CicPp.ppterm other)); prerr_endline ("+++++++++++++subst: " ^ (CicMetaSubst.ppsubst subst)); - raise exc; + raise exc; else () in let left, right = if is_left then newterm, right else left, newterm in @@ -695,37 +712,39 @@ let rec demodulation_equality ?from newmeta env table sign target = ignore(check_target context res "buildnew_target output"); !maxmeta, res in + let build_newtarget is_left x = + profiler.HExtlib.profile (build_newtarget is_left) x + in let res = demodulation_aux ~from:"3" metasenv' context ugraph table 0 left in if Utils.debug_res then check_res res "demod result"; let newmeta, newtarget = match res with | Some t -> - let newmeta, newtarget = build_newtarget true t in - if (Inference.is_weak_identity (metasenv', context, ugraph) newtarget) || + let newmeta, newtarget = build_newtarget true t in + if (Inference.is_weak_identity (metasenv', context, ugraph) newtarget) || (Inference.meta_convertibility_eq target newtarget) then - newmeta, newtarget - else + newmeta, newtarget + else demodulation_equality newmeta env table sign newtarget | None -> - let res = demodulation_aux metasenv' context ugraph table 0 right in - if Utils.debug_res then check_res res "demod result 1"; - match res with - | Some t -> - let newmeta, newtarget = build_newtarget false t in - if (Inference.is_weak_identity (metasenv', context, ugraph) newtarget) || - (Inference.meta_convertibility_eq target newtarget) then - newmeta, newtarget - else - demodulation_equality newmeta env table sign newtarget - | None -> - newmeta, target + let res = demodulation_aux metasenv' context ugraph table 0 right in + if Utils.debug_res then check_res res "demod result 1"; + match res with + | Some t -> + let newmeta, newtarget = build_newtarget false t in + if (Inference.is_weak_identity (metasenv', context, ugraph) newtarget) || + (Inference.meta_convertibility_eq target newtarget) then + newmeta, newtarget + else + demodulation_equality newmeta env table sign newtarget + | None -> + newmeta, target in (* newmeta, newtarget *) newmeta,newtarget ;; - (** Performs the beta expansion of the term "term" w.r.t. "table", i.e. returns the list of all the terms t s.t. "(t term) = t2", for some t2 @@ -851,6 +870,12 @@ let rec betaexpand_term metasenv context ugraph table lift_amount term = r @ res, lifted_term ;; +let profiler = HExtlib.profile "P/Indexing.betaexpand_term" + +let betaexpand_term metasenv context ugraph table lift_amount term = + profiler.HExtlib.profile + (betaexpand_term metasenv context ugraph table lift_amount) term + let sup_l_counter = ref 1;; @@ -872,11 +897,11 @@ let superposition_left newmeta (metasenv, context, ugraph) table target = let expansions, _ = let term = if ordering = U.Gt then left else right in begin - let t1 = Unix.gettimeofday () in - let res = betaexpand_term metasenv context ugraph table 0 term in - let t2 = Unix.gettimeofday () in - beta_expand_time := !beta_expand_time +. (t2 -. t1); - res + let t1 = Unix.gettimeofday () in + let res = betaexpand_term metasenv context ugraph table 0 term in + let t2 = Unix.gettimeofday () in + beta_expand_time := !beta_expand_time +. (t2 -. t1); + res end in let maxmeta = ref newmeta in @@ -996,7 +1021,7 @@ let superposition_right newmeta (metasenv, context, ugraph) table target = in (res left right), (res right left) in - let build_new ordering ((bo, s, m, ug, (eq_found, eq_URI)) as input) = + let build_new ordering (bo, s, m, ug, (eq_found, eq_URI)) = if Utils.debug_metas then ignore (check_target context (snd eq_found) "buildnew1" ); let time1 = Unix.gettimeofday () in @@ -1028,10 +1053,10 @@ let superposition_right newmeta (metasenv, context, ugraph) table target = let w = Utils.compute_equality_weight stat in (w, newproof, stat, newmenv) in if Utils.debug_metas then - ignore (check_target context eq' "buildnew3"); + ignore (check_target context eq' "buildnew3"); let newm, eq' = Inference.fix_metas !maxmeta eq' in if Utils.debug_metas then - ignore (check_target context eq' "buildnew4"); + ignore (check_target context eq' "buildnew4"); newm, eq' in maxmeta := newmeta; @@ -1134,7 +1159,6 @@ let rec demodulation_goal newmeta env table goal = newmeta, goal ;; - (** demodulation, when the target is a theorem *) let rec demodulation_theorem newmeta env table theorem = let module C = Cic in @@ -1161,7 +1185,7 @@ let rec demodulation_theorem newmeta env table theorem = (Inference.build_proof_term newproof, bo) in - let m = Inference.metas_of_term newterm in + (* let m = Inference.metas_of_term newterm in *) !maxmeta, (newterm, newty, menv) in let res = diff --git a/components/tactics/paramodulation/inference.ml b/components/tactics/paramodulation/inference.ml index 6582bfd25..e2f21b25c 100644 --- a/components/tactics/paramodulation/inference.ml +++ b/components/tactics/paramodulation/inference.ml @@ -450,7 +450,10 @@ let unification_simple locked_menv metasenv context t1 t2 ugraph = List.rev subst, menv, ugraph ;; -let profiler = HExtlib.profile "flatten" +let profiler = HExtlib.profile "P/Inference.unif_simple[flatten]" +let profiler2 = HExtlib.profile "P/Inference.unif_simple[flatten_fast]" +let profiler3 = HExtlib.profile "P/Inference.unif_simple[resolve_meta]" +let profiler4 = HExtlib.profile "P/Inference.unif_simple[filter]" let unification_aux b metasenv1 metasenv2 context t1 t2 ugraph = let metasenv = metasenv1 @ metasenv2 in @@ -479,8 +482,25 @@ let unification_aux b metasenv1 metasenv2 context t1 t2 ugraph = let ty = CicMetaSubst.apply_subst subst ty in (i, (context, term, ty))) subst in - let flatten subst = profiler.HExtlib.profile flatten subst in - let subst = flatten subst in + let flatten_fast subst = + let resolve_meta (i, (context, term, ty)) subst = + let term = CicMetaSubst.apply_subst subst term in + let ty = CicMetaSubst.apply_subst subst ty in + (i, (context, term, ty)) + in + let resolve_meta t s = profiler3.HExtlib.profile (resolve_meta t) s in + let filter j (i,_) = i <> j in + let filter a b = profiler4.HExtlib.profile (filter a) b in + List.fold_left + (fun subst (j,(c,t,ty)) as s -> + let s = resolve_meta s subst in + s::(List.filter (filter j) subst)) + subst subst + in + (*let flatten subst = profiler.HExtlib.profile flatten subst in*) + let flatten_fast subst = profiler2.HExtlib.profile flatten_fast subst in + (*let subst = flatten subst in*) +(* let subst = flatten_fast subst in*) subst, menv, ug ;; diff --git a/components/tactics/paramodulation/saturation.ml b/components/tactics/paramodulation/saturation.ml index bf9f8ba57..d52bf09c3 100644 --- a/components/tactics/paramodulation/saturation.ml +++ b/components/tactics/paramodulation/saturation.ml @@ -239,7 +239,6 @@ let rec select env goals passive (active, _) = (Negative, hd), ((tl, EqualitySet.remove hd neg_set), (pos, pos_set), passive_table) | [], (hd:EqualitySet.elt)::tl -> - let w,_,_,_ = hd in let passive_table = Indexing.remove_index passive_table hd in (Positive, hd), @@ -628,7 +627,7 @@ let forward_simplify env (sign, current) ?passive (active_list, active_table) = let res = demodulate active_table current in if Utils.debug_metas then ignore ((function None -> () | Some (_,x) -> - Indexing.check_target context x "demod1";()) res); + ignore (Indexing.check_target context x "demod1");()) res); match res with | None -> None | Some (sign, newcurrent) -> @@ -758,6 +757,8 @@ let forward_simplify_new env (new_neg, new_pos) ?passive active = ;; + + (** simplifies active usign new *) let backward_simplify_active env new_pos new_table min_weight active = let active_list, active_table = active in @@ -1082,7 +1083,7 @@ let apply_equality_to_goal env equality goal = (* (string_of_equality equality) (CicPp.ppterm gterm))); *) try let subst, metasenv', _ = - let menv = metasenv @ metas @ gmetas in + (* let menv = metasenv @ metas @ gmetas in *) Inference.unification metas gmetas context eqterm gterm ugraph in let newproof = @@ -1581,7 +1582,7 @@ let apply_theorem_to_goals env theorems active goals = (* given-clause algorithm with lazy reduction strategy *) let rec given_clause dbd env goals theorems passive active = - let _,context,_ = env in + (* let _,context,_ = env in *) let goals = simplify_goals env goals active in let ok, goals = activate_goal goals in (* let theorems = simplify_theorems env theorems active in *) @@ -1738,7 +1739,6 @@ and given_clause_aux dbd env goals theorems passive active = ) ;; - (** given-clause algorithm with full reduction strategy *) let rec given_clause_fullred dbd env goals theorems passive active = let goals = simplify_goals env goals ~passive active in @@ -1855,7 +1855,8 @@ and given_clause_fullred_aux dbd env goals theorems passive active = given_clause_fullred dbd env goals theorems passive active | false -> let (sign, current), passive = select env (fst goals) passive active in - let names = List.map (HExtlib.map_option (fun (name,_) -> name)) context in + (* let names = + List.map (HExtlib.map_option (fun (name,_) -> name)) context in *) prerr_endline ("Selected = " ^ (string_of_sign sign) ^ " " ^ string_of_equality ~env current); (* (CicPp.pp (Inference.term_of_equality current) names));*) @@ -1925,9 +1926,14 @@ and given_clause_fullred_aux dbd env goals theorems passive active = | None, Some (n, p) -> let nn, np = new' in if Utils.debug_metas then - ignore ( - List.map (fun x -> Indexing.check_target context x "simplify1")n; - List.map (fun x -> Indexing.check_target context x "simplify2")p); + (List.iter + (fun x -> ignore + (Indexing.check_target context x "simplify1")) + n; + List.iter + (fun x -> ignore + (Indexing.check_target context x "simplify2")) + p); simplify (nn @ n, np @ p) active passive | Some (n, p), Some (rn, rp) -> let nn, np = new' in @@ -1992,8 +1998,15 @@ end prova *) in ParamodulationSuccess (proof, env) ) + ;; +let profiler0 = HExtlib.profile "P/Saturation.given_clause_fullred" + +let given_clause_fullred dbd env goals theorems passive active = + profiler0.HExtlib.profile + (given_clause_fullred dbd env goals theorems passive) active + let rec saturate_equations env goal accept_fun passive active = elapsed_time := Unix.gettimeofday () -. !start_time; @@ -2250,6 +2263,7 @@ let saturate Indexing.init_index (); maxdepth := depth; maxwidth := width; +(* CicUnification.unif_ty := false;*) let proof, goal = status in let goal' = goal in let uri, metasenv, meta_proof, term_to_prove = proof in diff --git a/matita/tests/bool.ma b/matita/tests/bool.ma index a49c21cc8..6abd2cbb1 100644 --- a/matita/tests/bool.ma +++ b/matita/tests/bool.ma @@ -120,7 +120,7 @@ theorem bool266: \forall x,y:A. (mult x (add (inv x) y)) = (mult x y). intros.auto paramodulation. qed. - +*) theorem bool507: \forall A:Set. \forall one:A. @@ -141,7 +141,7 @@ theorem bool507: \forall x,y:A. zero = (mult x (mult (inv x) y)). intros.auto paramodulation. qed. - +(* theorem bool515: \forall A:Set. \forall one:A. @@ -243,11 +243,6 @@ theorem bool557: \forall i2: (\forall x:A. (mult x one) = x). \forall inv1: (\forall x:A. (add x (inv x)) = one). \forall inv2: (\forall x:A. (mult x (inv x)) = zero). - (* - \forall hint1: (\forall x,y:A. (add (inv x) (mult y x)) = (add (inv x) y)). - \forall hint2: \forall x,y:A.zero = (mult (inv x) (mult x y)). - \forall hint2: (\forall x,y:A. zero = (mult (inv (add x y)) y)). - *) \forall x,y:A. inv x = (add (inv x) (inv (add y x))). intros.auto paramodulation. @@ -270,11 +265,6 @@ theorem bool609: \forall i2: (\forall x:A. (mult x one) = x). \forall inv1: (\forall x:A. (add x (inv x)) = one). \forall inv2: (\forall x:A. (mult x (inv x)) = zero). - (* - \forall hint1: (\forall x,y:A. (add (inv x) (mult y x)) = (add (inv x) y)). - \forall hint2: \forall x,y:A.zero = (mult (inv x) (mult x y)). - \forall hint2: (\forall x,y:A. zero = (mult (inv (add x y)) y)). - *) \forall x,y:A. inv x = (add (inv (add y x)) (inv x)). intros.auto paramodulation. @@ -378,7 +368,6 @@ theorem bool756simplified: intros; auto paramodulation. qed. -(* 46 sec. *) theorem bool756: \forall A:Set. @@ -411,8 +400,7 @@ cut (mult (add y x) (add x (add y z)) = add x (add y (mult x z))); [auto paramodulation |auto paramodulation] qed. -(* 186 sec *) -*) + theorem bool756full: \forall A:Set. \forall one:A. @@ -434,9 +422,7 @@ theorem bool756full: add x y = add x (add y (mult x z)). intros;auto paramodulation. qed. -(* war=5; active 225, maxmeta 172568 *) -(* war=4; active 249, maxmeta 223220 *) -(* + theorem bool1164: \forall A:Set. \forall one:A. @@ -524,7 +510,7 @@ theorem bool1372: \forall x,y,z:A. add x (add y z) = add (add x z) y. intros.auto paramodulation. -qed.*) +qed. theorem bool381: \forall A:Set. @@ -572,7 +558,6 @@ theorem bool5hint1: (inv (mult x y)) = (add (inv x) (inv y)). intros.auto paramodulation. qed. -(* 90 *) theorem bool5hint2: \forall A:Set. @@ -597,7 +582,6 @@ theorem bool5hint2: (inv (mult x y)) = (add (inv x) (inv y)). intros.auto paramodulation. qed. -(* 41 *) theorem bool5hint3: \forall A:Set. @@ -622,7 +606,6 @@ theorem bool5hint3: (inv (mult x y)) = (add (inv x) (inv y)). intros.auto paramodulation. qed. -(* 41 *) theorem bool5: \forall A:Set. @@ -647,3 +630,4 @@ intros.auto paramodulation. qed. *) + -- 2.39.2