]> matita.cs.unibo.it Git - helm.git/blob - helm/software/components/ng_paramodulation/nCicParamod.ml
16ae66e5da45f76259420625ebd2311247899987
[helm.git] / helm / software / components / ng_paramodulation / nCicParamod.ml
1 (*
2     ||M||  This file is part of HELM, an Hypertextual, Electronic        
3     ||A||  Library of Mathematics, developed at the Computer Science     
4     ||T||  Department, University of Bologna, Italy.                     
5     ||I||                                                                
6     ||T||  HELM is free software; you can redistribute it and/or         
7     ||A||  modify it under the terms of the GNU General Public License   
8     \   /  version 2 or (at your option) any later version.      
9      \ /   This software is distributed as is, NO WARRANTY.     
10       V_______________________________________________________________ *)
11
12 (* $Id: orderings.ml 9869 2009-06-11 22:52:38Z denes $ *)
13
14 NCicBlob.set_default_eqP()
15 ;;
16 NCicProof.set_default_sig()
17 ;;
18
19 let debug _ = ();;
20 let print s = prerr_endline (Lazy.force s);; 
21
22 module B(C : NCicBlob.NCicContext): Orderings.Blob 
23   with type t = NCic.term and type input = NCic.term 
24   = Orderings.LPO(NCicBlob.NCicBlob(C))
25
26 module NCicParamod(C : NCicBlob.NCicContext) = Paramod.Paramod(B(C))
27
28 let readback ?(demod=false) rdb metasenv subst context (bag,i,fo_subst,l) =
29 (*
30   List.iter (fun x ->
31      print_endline (Pp.pp_unit_clause ~margin:max_int
32      (fst(Terms.M.find x bag)))) l; 
33 *)
34   (* let stamp = Unix.gettimeofday () in *)
35   let proofterm,prooftype = NCicProof.mk_proof ~demod bag i fo_subst l in
36   (* debug (lazy (Printf.sprintf "Got proof term in %fs"
37                      (Unix.gettimeofday() -. stamp))); *)
38 (*
39   let metasenv, proofterm = 
40     let rec aux k metasenv = function
41       | NCic.Meta _ as t -> metasenv, t
42       | NCic.Implicit _ -> 
43           let metasenv, i, _, _ =
44             NCicMetaSubst.mk_meta metasenv context `IsTerm 
45           in
46             metasenv, NCic.Meta (i,(k,NCic.Irl (List.length context)))
47       | t -> NCicUntrusted.map_term_fold_a 
48           (fun _ k -> k+1) k aux metasenv t
49     in
50       aux 0 metasenv proofterm
51   in *)
52   debug (lazy (NCicPp.ppterm ~metasenv ~subst ~context proofterm));
53 (*
54   let stamp = Unix.gettimeofday () in
55   let metasenv, subst, proofterm, _prooftype = 
56     NCicRefiner.typeof 
57       (rdb#set_coerc_db NCicCoercion.empty_db) 
58       metasenv subst context proofterm None
59   in
60     print (lazy (Printf.sprintf "Refined in %fs"
61                      (Unix.gettimeofday() -. stamp)));
62 *)
63     proofterm, prooftype, metasenv, subst
64
65 let nparamod rdb metasenv subst context t table =
66   let module C =
67     struct 
68       let metasenv = metasenv
69       let subst = subst
70       let context = context 
71     end 
72   in
73   let module B = B(C) in
74   let module P = NCicParamod(C) in
75   let module Pp = Pp.Pp(B) in
76   let bag, maxvar = Terms.empty_bag, 0 in
77   let (bag,maxvar), goals = 
78     HExtlib.list_mapi_acc (fun x _ a -> P.mk_goal a x) (bag,maxvar) [t]
79   in
80   let (bag,maxvar), passives = 
81     HExtlib.list_mapi_acc (fun x _ a -> P.mk_passive a x) (bag,maxvar) table
82   in
83   match 
84     P.paramod ~useage:true ~max_steps:max_int ~timeout:(Unix.gettimeofday () +. 300.0) 
85       ~g_passives:goals ~passives (bag,maxvar) 
86   with 
87   | P.Error _ | P.GaveUp | P.Timeout _ -> []
88   | P.Unsatisfiable solutions -> 
89       List.map (readback rdb metasenv subst context) solutions
90 ;;
91   
92 module EmptyC = 
93   struct
94     let metasenv = []
95     let subst = []
96     let context = []
97   end
98
99 module CB = NCicBlob.NCicBlob(EmptyC)
100 module P = NCicParamod(EmptyC)
101
102 type state = P.state
103 let empty_state = P.empty_state
104
105 let forward_infer_step s t ty =
106   let bag = P.bag_of_state s in
107   let bag,clause = P.mk_passive bag (t,ty) in
108     if Terms.is_eq_clause clause then
109       P.forward_infer_step (P.replace_bag s bag) clause 0
110     else (debug (lazy "not eq"); s)
111 ;;
112
113 let index_obj s uri =
114   let obj = NCicEnvironment.get_checked_obj uri in
115   debug (lazy ("indexing : " ^ (NUri.string_of_uri uri)));
116   debug (lazy ("no : " ^ (string_of_int (fst (Obj.magic uri)))));
117   match obj with
118     | (_,_,[],[],NCic.Constant(_,_,None,ty,_)) ->
119         let nref = NReference.reference_of_spec uri NReference.Decl in
120         forward_infer_step s (NCic.Const nref) ty
121     | (_,d,[],[],NCic.Constant(_,_,Some(_),ty,_)) ->
122         let nref = NReference.reference_of_spec uri (NReference.Def d) in
123         forward_infer_step s (NCic.Const nref) ty
124     | _ -> s
125 ;;
126
127 let demod rdb metasenv subst context s goal =
128   (* let stamp = Unix.gettimeofday () in *)
129   match P.demod s goal with
130     | P.Error _ | P.GaveUp | P.Timeout _ -> []
131     | P.Unsatisfiable solutions -> 
132       (* print (lazy (Printf.sprintf "Got solutions in %fs"
133                      (Unix.gettimeofday() -. stamp))); *)
134       List.map (readback ~demod:true rdb metasenv subst context) solutions
135 ;;
136
137 let paramod rdb metasenv subst context s goal =
138   (* let stamp = Unix.gettimeofday () in *)
139   match P.nparamod ~useage:true ~max_steps:max_int 
140     ~timeout:(Unix.gettimeofday () +. 300.0) s goal with
141   | P.Error _ | P.GaveUp | P.Timeout _ -> []
142   | P.Unsatisfiable solutions -> 
143       (* print (lazy (Printf.sprintf "Got solutions in %fs"
144                      (Unix.gettimeofday() -. stamp))); *)
145       List.map (readback rdb metasenv subst context) solutions
146 ;;
147
148 let fast_eq_check rdb metasenv subst context s goal =
149   (* let stamp = Unix.gettimeofday () in *)
150   match P.fast_eq_check s goal with
151   | P.Error _ | P.GaveUp | P.Timeout _ -> []
152   | P.Unsatisfiable solutions -> 
153       (* print (lazy (Printf.sprintf "Got solutions in %fs"
154                      (Unix.gettimeofday() -. stamp))); *)
155       List.map (readback rdb metasenv subst context) solutions
156 ;;
157
158 let is_equation metasenv subst context ty =
159   let hty, _, _ = 
160     NCicMetaSubst.saturate ~delta:0 metasenv subst context
161       ty 0 
162   in match hty with
163     | NCic.Appl (eq ::tl) when eq = CB.eqP -> true
164     | _ -> false
165 ;;
166
167
168 (*
169 let demodulate rdb metasenv subst context s goal =
170   (* let stamp = Unix.gettimeofday () in *)
171   match P.fast_eq_check s goal with
172   | P.Error _ | P.GaveUp | P.Timeout _ -> []
173   | P.Unsatisfiable solutions -> 
174       (* print (lazy (Printf.sprintf "Got solutions in %fs"
175                      (Unix.gettimeofday() -. stamp))); *)
176       List.map (readback rdb metasenv subst context) solutions
177 ;;
178 *)