]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/software/components/ng_paramodulation/nCicParamod.ml
Extension of demod to arbtrary predicates (not just equalities).
[helm.git] / helm / software / components / ng_paramodulation / nCicParamod.ml
index fb60d3142ccb526b5520bff439263d576512fae2..16ae66e5da45f76259420625ebd2311247899987 100644 (file)
@@ -25,16 +25,17 @@ module B(C : NCicBlob.NCicContext): Orderings.Blob
 
 module NCicParamod(C : NCicBlob.NCicContext) = Paramod.Paramod(B(C))
 
-let readback rdb metasenv subst context (bag,i,fo_subst,l) =
+let readback ?(demod=false) rdb metasenv subst context (bag,i,fo_subst,l) =
 (*
   List.iter (fun x ->
      print_endline (Pp.pp_unit_clause ~margin:max_int
      (fst(Terms.M.find x bag)))) l; 
 *)
-  let stamp = Unix.gettimeofday () in
-  let proofterm = NCicProof.mk_proof bag i fo_subst l in
-    print (lazy (Printf.sprintf "Got proof term in %fs"
-                    (Unix.gettimeofday() -. stamp)));
+  (* let stamp = Unix.gettimeofday () in *)
+  let proofterm,prooftype = NCicProof.mk_proof ~demod bag i fo_subst l in
+  (* debug (lazy (Printf.sprintf "Got proof term in %fs"
+                    (Unix.gettimeofday() -. stamp))); *)
+(*
   let metasenv, proofterm = 
     let rec aux k metasenv = function
       | NCic.Meta _ as t -> metasenv, t
@@ -47,8 +48,9 @@ let readback rdb metasenv subst context (bag,i,fo_subst,l) =
           (fun _ k -> k+1) k aux metasenv t
     in
       aux 0 metasenv proofterm
-  in
-  print (lazy (NCicPp.ppterm ~metasenv ~subst ~context proofterm));
+  in *)
+  debug (lazy (NCicPp.ppterm ~metasenv ~subst ~context proofterm));
+(*
   let stamp = Unix.gettimeofday () in
   let metasenv, subst, proofterm, _prooftype = 
     NCicRefiner.typeof 
@@ -57,7 +59,8 @@ let readback rdb metasenv subst context (bag,i,fo_subst,l) =
   in
     print (lazy (Printf.sprintf "Refined in %fs"
                     (Unix.gettimeofday() -. stamp)));
-    proofterm, metasenv, subst
+*)
+    proofterm, prooftype, metasenv, subst
 
 let nparamod rdb metasenv subst context t table =
   let module C =
@@ -93,34 +96,83 @@ module EmptyC =
     let context = []
   end
 
+module CB = NCicBlob.NCicBlob(EmptyC)
 module P = NCicParamod(EmptyC)
 
 type state = P.state
 let empty_state = P.empty_state
 
 let forward_infer_step s t ty =
-  let bag = P.bag_of_state s in 
+  let bag = P.bag_of_state s in
   let bag,clause = P.mk_passive bag (t,ty) in
     if Terms.is_eq_clause clause then
       P.forward_infer_step (P.replace_bag s bag) clause 0
-    else s
+    else (debug (lazy "not eq"); s)
 ;;
 
 let index_obj s uri =
   let obj = NCicEnvironment.get_checked_obj uri in
+  debug (lazy ("indexing : " ^ (NUri.string_of_uri uri)));
+  debug (lazy ("no : " ^ (string_of_int (fst (Obj.magic uri)))));
   match obj with
-    | (_,_,[],[],NCic.Constant(_,_,Some(t),ty,_)) ->
-       forward_infer_step s t ty
+    | (_,_,[],[],NCic.Constant(_,_,None,ty,_)) ->
+        let nref = NReference.reference_of_spec uri NReference.Decl in
+       forward_infer_step s (NCic.Const nref) ty
+    | (_,d,[],[],NCic.Constant(_,_,Some(_),ty,_)) ->
+        let nref = NReference.reference_of_spec uri (NReference.Def d) in
+       forward_infer_step s (NCic.Const nref) ty
     | _ -> s
 ;;
 
+let demod rdb metasenv subst context s goal =
+  (* let stamp = Unix.gettimeofday () in *)
+  match P.demod s goal with
+    | P.Error _ | P.GaveUp | P.Timeout _ -> []
+    | P.Unsatisfiable solutions -> 
+      (* print (lazy (Printf.sprintf "Got solutions in %fs"
+                    (Unix.gettimeofday() -. stamp))); *)
+      List.map (readback ~demod:true rdb metasenv subst context) solutions
+;;
+
+let paramod rdb metasenv subst context s goal =
+  (* let stamp = Unix.gettimeofday () in *)
+  match P.nparamod ~useage:true ~max_steps:max_int 
+    ~timeout:(Unix.gettimeofday () +. 300.0) s goal with
+  | P.Error _ | P.GaveUp | P.Timeout _ -> []
+  | P.Unsatisfiable solutions -> 
+      (* print (lazy (Printf.sprintf "Got solutions in %fs"
+                    (Unix.gettimeofday() -. stamp))); *)
+      List.map (readback rdb metasenv subst context) solutions
+;;
+
 let fast_eq_check rdb metasenv subst context s goal =
-  let stamp = Unix.gettimeofday () in
+  (* let stamp = Unix.gettimeofday () in *)
   match P.fast_eq_check s goal with
   | P.Error _ | P.GaveUp | P.Timeout _ -> []
   | P.Unsatisfiable solutions -> 
-      print (lazy (Printf.sprintf "Got solutions in %fs"
-                    (Unix.gettimeofday() -. stamp)));
+      (* print (lazy (Printf.sprintf "Got solutions in %fs"
+                    (Unix.gettimeofday() -. stamp))); *)
       List.map (readback rdb metasenv subst context) solutions
 ;;
 
+let is_equation metasenv subst context ty =
+  let hty, _, _ = 
+    NCicMetaSubst.saturate ~delta:0 metasenv subst context
+      ty 0 
+  in match hty with
+    | NCic.Appl (eq ::tl) when eq = CB.eqP -> true
+    | _ -> false
+;;
+
+
+(*
+let demodulate rdb metasenv subst context s goal =
+  (* let stamp = Unix.gettimeofday () in *)
+  match P.fast_eq_check s goal with
+  | P.Error _ | P.GaveUp | P.Timeout _ -> []
+  | P.Unsatisfiable solutions -> 
+      (* print (lazy (Printf.sprintf "Got solutions in %fs"
+                    (Unix.gettimeofday() -. stamp))); *)
+      List.map (readback rdb metasenv subst context) solutions
+;;
+*)