]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/ocaml/tactics/paramodulation/saturation.ml
Code restructuring.
[helm.git] / helm / ocaml / tactics / paramodulation / saturation.ml
index 0514ed5033f732389b8221cf903a5ab10118995f..07fbaa41c5a2e5b0a6c35557bcbfccbfaa561e7b 100644 (file)
@@ -847,6 +847,49 @@ let simplify_theorems env theorems ?passive (active_list, active_table) =
 ;;
 
 
+let rec simpl env e others others_simpl =
+  let active = others @ others_simpl in
+  let tbl =
+    List.fold_left
+      (fun t (_, e) -> Indexing.index t e)
+      Indexing.empty active
+  in
+  let res = forward_simplify env e (active, tbl) in
+    match others with
+      | hd::tl -> (
+          match res with
+            | None -> simpl env hd tl others_simpl
+            | Some e -> simpl env hd tl (e::others_simpl)
+        )
+      | [] -> (
+          match res with
+            | None -> others_simpl
+            | Some e -> e::others_simpl
+        )
+;;
+
+let simplify_equalities env equalities =
+  debug_print
+    (lazy 
+       (Printf.sprintf "equalities:\n%s\n"
+          (String.concat "\n"
+             (List.map string_of_equality equalities))));
+  debug_print (lazy "SIMPLYFYING EQUALITIES...");
+  match equalities with
+    | [] -> []
+    | hd::tl ->
+        let others = List.map (fun e -> (Positive, e)) tl in
+        let res =
+          List.rev (List.map snd (simpl env (Positive, hd) others []))
+        in
+          debug_print
+            (lazy
+               (Printf.sprintf "equalities AFTER:\n%s\n"
+                  (String.concat "\n"
+                     (List.map string_of_equality res))));
+          res
+;;
+
 (* applies equality to goal to see if the goal can be closed *)
 let apply_equality_to_goal env equality goal =
   let module C = Cic in
@@ -1826,48 +1869,7 @@ let main dbd full term metasenv ugraph =
   in
   (*try*)
     let goal = Inference.BasicProof new_meta_goal, [], goal in
-    let equalities =
-      let equalities = equalities @ library_equalities in
-      debug_print
-        (lazy 
-           (Printf.sprintf "equalities:\n%s\n"
-              (String.concat "\n"
-                 (List.map string_of_equality equalities))));
-      debug_print (lazy "SIMPLYFYING EQUALITIES...");
-      let rec simpl e others others_simpl =
-        let active = others @ others_simpl in
-        let tbl =
-          List.fold_left
-            (fun t (_, e) -> Indexing.index t e)
-             Indexing.empty active
-        in
-        let res = forward_simplify env e (active, tbl) in
-        match others with
-        | hd::tl -> (
-            match res with
-            | None -> simpl hd tl others_simpl
-            | Some e -> simpl hd tl (e::others_simpl)
-          )
-        | [] -> (
-            match res with
-            | None -> others_simpl
-            | Some e -> e::others_simpl
-          )
-      in
-      match equalities with
-      | [] -> []
-      | hd::tl ->
-          let others = List.map (fun e -> (Positive, e)) tl in
-          let res =
-            List.rev (List.map snd (simpl (Positive, hd) others []))
-          in
-          debug_print
-            (lazy
-               (Printf.sprintf "equalities AFTER:\n%s\n"
-                  (String.concat "\n"
-                     (List.map string_of_equality res))));
-          res
-    in
+    let equalities = simplify_equalities env (equalities@library_equalities) in
     let active = make_active () in
     let passive = make_passive [] equalities in
     Printf.printf "\ncurrent goal: %s\n"
@@ -2005,48 +2007,7 @@ let saturate
     let library_equalities = List.map snd library_equalities in
     let t2 = Unix.gettimeofday () in
     maxmeta := maxm+2;
-    let equalities =
-      let equalities = equalities @ library_equalities in
-      debug_print
-        (lazy
-           (Printf.sprintf "equalities:\n%s\n"
-              (String.concat "\n"
-                 (List.map string_of_equality equalities))));
-      debug_print (lazy "SIMPLYFYING EQUALITIES...");
-      let rec simpl e others others_simpl =
-        let active = others @ others_simpl in
-        let tbl =
-          List.fold_left
-            (fun t (_, e) -> Indexing.index t e)
-             Indexing.empty active
-        in
-        let res = forward_simplify env e (active, tbl) in
-        match others with
-        | hd::tl -> (
-            match res with
-            | None -> simpl hd tl others_simpl
-            | Some e -> simpl hd tl (e::others_simpl)
-          )
-        | [] -> (
-            match res with
-            | None -> others_simpl
-            | Some e -> e::others_simpl
-          )
-      in
-      match equalities with
-      | [] -> []
-      | hd::tl ->
-          let others = List.map (fun e -> (Positive, e)) tl in
-          let res =
-            List.rev (List.map snd (simpl (Positive, hd) others []))
-          in
-          debug_print
-            (lazy
-               (Printf.sprintf "equalities AFTER:\n%s\n"
-                  (String.concat "\n"
-                     (List.map string_of_equality res))));
-          res
-    in
+    let equalities = simplify_equalities env (equalities@library_equalities) in
     debug_print
       (lazy
          (Printf.sprintf "Time to retrieve equalities: %.9f\n" (t2 -. t1)));
@@ -2275,48 +2236,7 @@ let main_demod_equalities dbd term metasenv ugraph =
   let env = (metasenv, context, ugraph) in
   (*try*)
     let goal = Inference.BasicProof new_meta_goal, [], goal in
-    let equalities =
-      let equalities = equalities @ library_equalities in
-      debug_print
-        (lazy 
-           (Printf.sprintf "equalities:\n%s\n"
-              (String.concat "\n"
-                 (List.map string_of_equality equalities))));
-      debug_print (lazy "SIMPLYFYING EQUALITIES...");
-      let rec simpl e others others_simpl =
-        let active = others @ others_simpl in
-        let tbl =
-          List.fold_left
-            (fun t (_, e) -> Indexing.index t e)
-            Indexing.empty active
-        in
-        let res = forward_simplify env e (active, tbl) in
-        match others with
-        | hd::tl -> (
-            match res with
-            | None -> simpl hd tl others_simpl
-            | Some e -> simpl hd tl (e::others_simpl)
-          )
-        | [] -> (
-            match res with
-            | None -> others_simpl
-            | Some e -> e::others_simpl
-          )
-      in
-      match equalities with
-      | [] -> []
-      | hd::tl ->
-          let others = List.map (fun e -> (Positive, e)) tl in
-          let res =
-            List.rev (List.map snd (simpl (Positive, hd) others []))
-          in
-          debug_print
-            (lazy
-               (Printf.sprintf "equalities AFTER:\n%s\n"
-                  (String.concat "\n"
-                     (List.map string_of_equality res))));
-          res
-    in
+    let equalities = simplify_equalities env (equalities@library_equalities) in
     let active = make_active () in
     let passive = make_passive [] equalities in
     Printf.printf "\ncontext:\n%s\n" (PP.ppcontext context);
@@ -2363,3 +2283,50 @@ let main_demod_equalities dbd term metasenv ugraph =
     debug_print (lazy ("EXCEPTION: " ^ (Printexc.to_string e)))
 *)
 ;;
+
+let demodulate_tac ~dbd ~pattern ((proof,goal) as initialstatus) = 
+  let module I = Inference in
+  let curi,metasenv,pbo,pty = proof in
+  let metano,context,ty = CicUtil.lookup_meta goal metasenv in
+  let eq_indexes, equalities, maxm = I.find_equalities context proof in
+  let lib_eq_uris, library_equalities, maxm =
+    I.find_library_equalities dbd context (proof, goal) (maxm+2) in
+  if library_equalities = [] then prerr_endline "VUOTA!!!";
+  let irl = CicMkImplicit.identity_relocation_list_for_metavariable context in
+  let library_equalities = List.map snd library_equalities in
+  let goalterm = Cic.Meta (metano,irl) in
+  let initgoal = Inference.BasicProof goalterm, [], ty in
+  let env = (metasenv, context, CicUniv.empty_ugraph) in
+  let equalities = simplify_equalities env (equalities@library_equalities) in  
+  let table = 
+    List.fold_left 
+      (fun tbl eq -> Indexing.index tbl eq) 
+      Indexing.empty equalities 
+  in
+  let newmeta,(newproof,newmetasenv, newty) = Indexing.demodulation_goal 
+    maxm (metasenv,context,CicUniv.empty_ugraph) table initgoal 
+  in
+  if newmeta != maxm then
+    begin
+      let opengoal = Cic.Meta(maxm,irl) in
+      let proofterm = 
+       Inference.build_proof_term ~noproof:opengoal newproof in
+        let extended_metasenv = (maxm,context,newty)::metasenv in
+       let extended_status = 
+         (curi,extended_metasenv,pbo,pty),goal in
+       let (status,newgoals) = 
+         ProofEngineTypes.apply_tactic 
+           (PrimitiveTactics.apply_tac ~term:proofterm)
+           extended_status in
+       (status,maxm::newgoals)
+    end
+  else if newty = ty then
+    raise (ProofEngineTypes.Fail (lazy "no progress"))
+  else ProofEngineTypes.apply_tactic 
+    (ReductionTactics.simpl_tac ~pattern) 
+    initialstatus
+;;
+
+let demodulate_tac ~dbd ~pattern = 
+  ProofEngineTypes.mk_tactic (demodulate_tac ~dbd ~pattern)
+;;