]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/software/components/tactics/paramodulation/saturation.ml
more work on matitaprover (no more XML and buris are created).
[helm.git] / helm / software / components / tactics / paramodulation / saturation.ml
index d4ccf8f42bbcc71f172f6b69085c273437541f36..021afb5abdf0ed36f61450e6119d7fdc2230173c 100644 (file)
@@ -23,7 +23,7 @@
  * http://cs.unibo.it/helm/.
  *)
 
-let _profiler = <:profiler<_profiler>>;;
+(* let _profiler = <:profiler<_profiler>>;; *)
 
 (* $Id$ *)
 
@@ -153,11 +153,13 @@ let age_factor = 0.01;;
    of weight, age and goal-similarity
 *)
 
-let rec select env (goals,_) passive =
+let rec select env g passive =
   processed_clauses := !processed_clauses + 1;
+(*
   let goal =
     match (List.rev goals) with goal::_ -> goal | _ -> assert false
   in
+*)
   let pos_list, pos_set = passive in
   let remove eq l = List.filter (fun e -> Equality.compare e eq <> 0) l in
   if !weight_age_ratio > 0 then
@@ -165,20 +167,40 @@ let rec select env (goals,_) passive =
   match !weight_age_counter with
   | 0 -> (
       weight_age_counter := !weight_age_ratio;
+      let skip_giant pos_list pos_set =
+        match pos_list with
+          | (hd:EqualitySet.elt)::tl ->
+              let w,_,_,_,_ = Equality.open_equality hd in
+                if w < 30 then
+                  hd, (tl, EqualitySet.remove hd pos_set)
+                else
+(*
+                  (prerr_endline 
+                    ("+++ skipping giant of size "^string_of_int w^" +++");
+*)
+                  select env g (tl@[hd],pos_set)
+          | _ -> assert false
+                  in
+                   skip_giant pos_list pos_set)
+
+(*
       let rec skip_giant pos_list pos_set =
         match pos_list with
           | (hd:EqualitySet.elt)::tl ->
               let w,_,_,_,_ = Equality.open_equality hd in
               let pos_set = EqualitySet.remove hd pos_set in
-                if w < 500 then
+                if w < 30 then
                   hd, (tl, pos_set)
                 else
                   (prerr_endline 
                     ("+++ skipping giant of size "^string_of_int w^" +++");
                   skip_giant tl pos_set)
           | _ -> assert false
-      in
-        skip_giant pos_list pos_set)
+      in        
+  skip_giant pos_list pos_set)
+
+*)
+(*
   | _ when (!symbols_counter > 0) -> 
      (symbols_counter := !symbols_counter - 1;
       let cardinality map =
@@ -216,6 +238,7 @@ let rec select env (goals,_) passive =
       let _, current = EqualitySet.fold f pos_set initial in
         current,
       (remove current pos_list, EqualitySet.remove current pos_set))
+*)
   | _ ->
       symbols_counter := !symbols_ratio;
       let my_min e1 e2 =
@@ -244,8 +267,10 @@ let filter_dependent passive id =
            (eq::list, set), no)
       pos_list (([],pos_set),0)
   in
+(*
   if no_pruned > 0 then
     prerr_endline ("+++ pruning "^ string_of_int no_pruned ^" passives +++");  
+*)
   passive
 ;;
 
@@ -334,11 +359,11 @@ let infer eq_uri env current (active_list, active_table) =
       let maxm, copy_of_current = Equality.fix_metas !maxmeta current in
         maxmeta := maxm;
       let active_table =  Indexing.index active_table copy_of_current in
-      let _ = <:start<current contro active>> in
+(*       let _ = <:start<current contro active>> in *)
       let maxm, res =
         Indexing.superposition_right eq_uri !maxmeta env active_table current 
       in
-      let _ = <:stop<current contro active>> in
+(*       let _ = <:stop<current contro active>> in *)
       if Utils.debug_metas then
         ignore(List.map 
                  (function current -> 
@@ -365,9 +390,9 @@ let infer eq_uri env current (active_list, active_table) =
         maxmeta := maxm;
 *)
       let curr_table = Indexing.index Indexing.empty current in
-      let _ = <:start<active contro current>> in
+(*       let _ = <:start<active contro current>> in *)
       let pos = infer_positive curr_table ((*copy_of_current::*)active_list) in
-      let _ = <:stop<active contro current>> in
+(*       let _ = <:stop<active contro current>> in *)
       if Utils.debug_metas then 
         ignore(List.map 
                  (function current -> 
@@ -793,11 +818,13 @@ let check_if_goal_is_subsumed ((_,ctx,_) as env) table (goalproof,menv,ty) =
 (*      match Indexing.subsumption env table goal_equation with*)
        match Indexing.unification env table goal_equation with 
         | Some (subst, equality, swapped ) ->
+(*
             prerr_endline 
-              ("GOAL SUBSUMED IS: " ^ Equality.string_of_equality goal_equation ~env);
+             ("GOAL SUBSUMED IS: "^Equality.string_of_equality goal_equation ~env);
             prerr_endline 
-              ("GOAL IS SUBSUMED BY: " ^ Equality.string_of_equality equality ~env);
-            prerr_endline ("SUBST:" ^ Subst.ppsubst ~names subst);
+             ("GOAL IS SUBSUMED BY: "^Equality.string_of_equality equality ~env);
+            prerr_endline ("SUBST:"^Subst.ppsubst ~names subst);
+*)
             let (_,p,(ty,l,r,_),m,id) = Equality.open_equality equality in
             let cicmenv = Subst.apply_subst_metasenv subst (m @ menv) in
             let p =
@@ -843,6 +870,10 @@ let simplify_goal_set env goals active =
   let find (_,_,g) where =
     List.exists (fun (_,_,g1) -> Equality.meta_convertibility g g1) where
   in
+    (* prova:tengo le passive semplificate 
+  let passive_goals = 
+    List.map (fun g -> snd (simplify_goal env g active)) passive_goals 
+  in *)
     List.fold_left
       (fun (acc_a,acc_p) goal -> 
         match simplify_goal env goal active with 
@@ -864,6 +895,7 @@ let check_if_goals_set_is_solved env active goals =
           check goal [
             check_if_goal_is_identity env;
             check_if_goal_is_subsumed env (snd active)])
+(* provare active and passive?*)
     None active_goals
 ;;
 
@@ -873,8 +905,10 @@ let infer_goal_set env active goals =
     | [] -> active_goals, []
     | hd::tl ->
         let changed,selected = simplify_goal env hd active in
+(*
         if changed then
           prerr_endline ("--------------- goal semplificato");
+*)
         let (_,_,t1) = selected in
         let already_in = 
           List.exists (fun (_,_,t) -> Equality.meta_convertibility t t1) 
@@ -941,6 +975,13 @@ let pp_goals label goals context =
       (snd goals);
 ;;
 
+let print_status iterno goals active passive =
+  print_endline 
+    (Printf.sprintf "\n%d #ACTIVES: %d #PASSIVES: %d #GOALSET: %d(%d)"
+      iterno (size_of_active active) (size_of_passive passive)
+      (size_of_goal_set_a goals) (size_of_goal_set_p goals)) 
+;;
+
 (** given-clause algorithm with full reduction strategy: NEW implementation *)
 (* here goals is a set of goals in OR *)
 let given_clause 
@@ -958,23 +999,14 @@ let given_clause
     int_of_float iterations_left 
   in
   let rec step goals theorems passive active iterno =
-    pp_goals "xxx" goals context;
     if iterno > max_iterations then
       (ParamodulationFailure "No more iterations to spend")
     else if Unix.gettimeofday () > max_time then
       (ParamodulationFailure "No more time to spend")
     else
-(*
-      let _ = prerr_endline "simpl goal with active" in
-      let _ = <:start<simplify goal set active>> in
-      let goals = simplify_goal_set env goals passive active in 
-      let _ = <:stop<simplify goal set active>> in
-*)
       let _ = 
-        prerr_endline 
-         (Printf.sprintf "%d #ACTIVES: %d #PASSIVES: %d #GOALSET: %d(%d)\n"
-           iterno (size_of_active active) (size_of_passive passive)
-           (size_of_goal_set_a goals) (size_of_goal_set_p goals)) 
+(*         print_status iterno goals active passive  *)
+        Printf.printf ".%!";
       in
       (* PRUNING OF PASSIVE THAT WILL NEVER BE PROCESSED *) 
       let passive =
@@ -989,11 +1021,12 @@ let given_clause
           passive
       in
       kept_clauses := (size_of_passive passive) + (size_of_active active);
-      let goals = infer_goal_set env active goals in
+      let goals = infer_goal_set env active goals 
+      in
       match check_if_goals_set_is_solved env active goals with
       | Some p -> 
-          prerr_endline 
-            (Printf.sprintf "Found a proof in: %f\n" 
+          print_endline 
+            (Printf.sprintf "\nFound a proof in: %f\n" 
               (Unix.gettimeofday() -. initial_time));
           ParamodulationSuccess p
       | None -> 
@@ -1009,6 +1042,7 @@ let given_clause
               (* COLLECTION OF GARBAGED EQUALITIES *)
               if iterno mod 40 = 0 then
                 begin
+                  print_status iterno goals active passive;
                   let active = List.map Equality.id_of (fst active) in
                   let passive = List.map Equality.id_of (fst passive) in
                   let goal = ids_of_goal_set goals in
@@ -1016,24 +1050,21 @@ let given_clause
                 end;
               let current, passive = select env goals passive in
               (* SIMPLIFICATION OF CURRENT *)
+(*
               prerr_endline
                     ("Selected : " ^ 
                       Equality.string_of_equality ~env  current);
+*)
               let res = 
                 forward_simplify eq_uri env current active 
               in
               match res with
               | None -> step goals theorems passive active (iterno+1)
               | Some current ->
-(*
-                  prerr_endline 
-                    ("Selected simpl: " ^ 
-                      Equality.string_of_equality ~env  current);
-*)
                   (* GENERATION OF NEW EQUATIONS *)
-                  prerr_endline "infer";
+(*                   prerr_endline "infer"; *)
                   let new' = infer eq_uri env current active in
-                  prerr_endline "infer goal";
+(*                   prerr_endline "infer goal"; *)
 (*
       match check_if_goals_set_is_solved env active goals with
       | Some p -> 
@@ -1051,7 +1082,7 @@ let given_clause
                     infer_goal_set_with_current env current goals active 
                   in
                   (* FORWARD AND BACKWARD SIMPLIFICATION *)
-                  prerr_endline "fwd/back simpl";
+(*                   prerr_endline "fwd/back simpl"; *)
                   let rec simplify new' active passive head =
                     let new' = 
                       forward_simplify_new eq_uri env new' active 
@@ -1072,12 +1103,12 @@ let given_clause
                   let active, passive, new', head = 
                     simplify new' active passive []
                   in
-                  prerr_endline "simpl goal with new";
+(*                   prerr_endline "simpl goal with new"; *)
                   let goals = 
                     let a,b,_ = build_table new' in
-                    let _ = <:start<simplify_goal_set new>> in
+(*                     let _ = <:start<simplify_goal_set new>> in *)
                     let rc = simplify_goal_set env goals (a,b) in
-                    let _ = <:stop<simplify_goal_set new>> in
+(*                     let _ = <:stop<simplify_goal_set new>> in *)
                     rc
                   in
                   let passive = add_to_passive passive new' head in
@@ -1263,11 +1294,15 @@ let saturate
       raise (ProofEngineTypes.Fail (lazy ("NO proof found: " ^ s)))
   | ParamodulationSuccess 
     (goalproof,newproof,subsumption_id,subsumption_subst, proof_menv) ->
-      prerr_endline "OK, found a proof!";
-      prerr_endline 
+      print_endline "Proof:";
+      print_endline 
         (Equality.pp_proof names goalproof newproof subsumption_subst
           subsumption_id type_of_goal);
-      prerr_endline "ENDOFPROOFS";
+(*       prerr_endline "ENDOFPROOFS"; *)
+(*
+      prerr_endline ("max weight: " ^ 
+       (string_of_int (Equality.max_weight goalproof newproof)));
+*)
       (* generation of the CIC proof *)
       let side_effects = 
         List.filter (fun i -> i <> goalno)
@@ -1280,7 +1315,7 @@ let saturate
           eq_uri goalproof initial type_of_goal side_effects
           context proof_menv
       in
-      prerr_endline ("PROOF: " ^ CicPp.pp goal_proof names);
+(*       prerr_endline ("PROOF: " ^ CicPp.pp goal_proof names); *)
       let goal_proof = Subst.apply_subst subsumption_subst goal_proof in
       let metas_still_open_in_proof = Utils.metas_of_term goal_proof in
 (*prerr_endline (CicPp.pp goal_proof names);*)
@@ -1290,7 +1325,7 @@ let saturate
         List.map (Subst.apply_subst subsumption_subst) side_effects_t
       in
       (* replacing fake mets with real ones *)
-      prerr_endline "replacing metas...";
+(*       prerr_endline "replacing metas..."; *)
       let irl=CicMkImplicit.identity_relocation_list_for_metavariable context in
       let goal_proof_menv, what, with_what,free_meta = 
         List.fold_left 
@@ -1323,7 +1358,8 @@ let saturate
           (ProofEngineHelpers.compare_metasenvs 
             ~oldmetasenv:metasenv ~newmetasenv:goal_proof_menv)
       in
-prerr_endline ("freemetas: " ^ String.concat "," (List.map string_of_int free_metas) );
+(* prerr_endline ("freemetas: " ^ String.concat "," (List.map string_of_int
+ * free_metas) ); *)
       (* check/refine/... build the new proof *)
       let replaced_goal = 
         ProofEngineReduction.replace
@@ -1348,7 +1384,7 @@ prerr_endline ("freemetas: " ^ String.concat "," (List.map string_of_int free_me
       let final_subst = 
         (goalno,(context,goal_proof,type_of_goal))::subst_side_effects
       in
-prerr_endline ("MENVreal_menv: " ^ CicMetaSubst.ppmetasenv [] real_menv);
+(* prerr_endline ("MENVreal_menv: " ^ CicMetaSubst.ppmetasenv [] real_menv); *)
       let _ = 
         try
           CicTypeChecker.type_of_aux' real_menv context goal_proof
@@ -1370,12 +1406,14 @@ prerr_endline ("MENVreal_menv: " ^ CicMetaSubst.ppmetasenv [] real_menv);
       let open_goals = 
         match free_meta with Some(Cic.Meta(m,_)) when m<>goalno ->[m] | _ ->[] 
       in
+(*
       Printf.eprintf 
         "GOALS APERTI: %s\nMETASENV PRIMA:\n%s\nMETASENV DOPO:\n%s\n" 
           (String.concat ", " (List.map string_of_int open_goals))
           (CicMetaSubst.ppmetasenv [] metasenv)
           (CicMetaSubst.ppmetasenv [] real_metasenv);
-      prerr_endline (Printf.sprintf "\nTIME NEEDED: %8.2f" time);
+*)
+      print_endline (Printf.sprintf "\nTIME NEEDED: %8.2f" time);
       proof, open_goals
 ;;
 
@@ -1708,8 +1746,10 @@ let superposition_tac ~target ~table ~subterms_only ~demod_table status =
   proof,[goalno]
 ;;
 
-let get_stats () = 
+let get_stats () = "" 
+(*
   <:show<Saturation.>> ^ Indexing.get_stats () ^ Inference.get_stats () ^
   Equality.get_stats ()
 ;;
+*)