]> matita.cs.unibo.it Git - helm.git/blob - helm/software/components/ng_paramodulation/nCicParamod.ml
Final subst returned by superposition and passed around.
[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 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 = NCicProof.mk_proof bag i fo_subst l in
36     print (lazy (Printf.sprintf "Got proof term in %fs"
37                      (Unix.gettimeofday() -. stamp)));
38   let metasenv, proofterm = 
39     let rec aux k metasenv = function
40       | NCic.Meta _ as t -> metasenv, t
41       | NCic.Implicit _ -> 
42           let metasenv, i, _, _ =
43             NCicMetaSubst.mk_meta metasenv context `IsTerm 
44           in
45             metasenv, NCic.Meta (i,(k,NCic.Irl (List.length context)))
46       | t -> NCicUntrusted.map_term_fold_a 
47           (fun _ k -> k+1) k aux metasenv t
48     in
49       aux 0 metasenv proofterm
50   in
51   print (lazy (NCicPp.ppterm ~metasenv ~subst ~context proofterm));
52   let stamp = Unix.gettimeofday () in
53   let metasenv, subst, proofterm, _prooftype = 
54     NCicRefiner.typeof 
55       (rdb#set_coerc_db NCicCoercion.empty_db) 
56       metasenv subst context proofterm None
57   in
58     print (lazy (Printf.sprintf "Refined in %fs"
59                      (Unix.gettimeofday() -. stamp)));
60     proofterm, metasenv, subst
61
62 let nparamod rdb metasenv subst context t table =
63   let module C =
64     struct 
65       let metasenv = metasenv
66       let subst = subst
67       let context = context 
68     end 
69   in
70   let module B = B(C) in
71   let module P = NCicParamod(C) in
72   let module Pp = Pp.Pp(B) in
73   let bag, maxvar = Terms.empty_bag, 0 in
74   let (bag,maxvar), goals = 
75     HExtlib.list_mapi_acc (fun x _ a -> P.mk_goal a x) (bag,maxvar) [t]
76   in
77   let (bag,maxvar), passives = 
78     HExtlib.list_mapi_acc (fun x _ a -> P.mk_passive a x) (bag,maxvar) table
79   in
80   match 
81     P.paramod ~useage:true ~max_steps:max_int ~timeout:(Unix.gettimeofday () +. 300.0) 
82       ~g_passives:goals ~passives (bag,maxvar) 
83   with 
84   | P.Error _ | P.GaveUp | P.Timeout _ -> []
85   | P.Unsatisfiable solutions -> 
86       List.map (readback rdb metasenv subst context) solutions
87 ;;
88   
89 module EmptyC = 
90   struct
91     let metasenv = []
92     let subst = []
93     let context = []
94   end
95
96 module P = NCicParamod(EmptyC)
97
98 type state = P.state
99 let empty_state = P.empty_state
100
101 let forward_infer_step s t ty =
102   let bag = P.bag_of_state s in 
103   let bag,clause = P.mk_passive bag (t,ty) in
104     if Terms.is_eq_clause clause then
105       P.forward_infer_step (P.replace_bag s bag) clause 0
106     else s
107 ;;
108
109 let index_obj s uri =
110   let obj = NCicEnvironment.get_checked_obj uri in
111   match obj with
112     | (_,_,[],[],NCic.Constant(_,_,Some(t),ty,_)) ->
113         forward_infer_step s t ty
114     | _ -> s
115 ;;
116
117 let fast_eq_check rdb metasenv subst context s goal =
118   let stamp = Unix.gettimeofday () in
119   match P.fast_eq_check s goal with
120   | P.Error _ | P.GaveUp | P.Timeout _ -> []
121   | P.Unsatisfiable solutions -> 
122       print (lazy (Printf.sprintf "Got solutions in %fs"
123                      (Unix.gettimeofday() -. stamp)));
124       List.map (readback rdb metasenv subst context) solutions
125 ;;
126