]> matita.cs.unibo.it Git - helm.git/blob - helm/software/components/ng_paramodulation/nCicParamod.ml
The new paramodulation functions instantiated over nCic.
[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 module B(C : NCicBlob.NCicContext): Orderings.Blob 
20   with type t = NCic.term and type input = NCic.term 
21   = Orderings.LPO(NCicBlob.NCicBlob(C))
22
23 module NCicParamod(C : NCicBlob.NCicContext) = Paramod.Paramod(B(C))
24
25 let readback rdb metasenv subst context (bag,i,l) =
26 (*
27   List.iter (fun x ->
28      print_endline (Pp.pp_unit_clause ~margin:max_int
29      (fst(Terms.M.find x bag)))) l; 
30 *)
31   let stamp = Unix.gettimeofday () in
32   let proofterm = NCicProof.mk_proof bag i l in
33     prerr_endline (Printf.sprintf "Got proof term in %fs"
34                      (Unix.gettimeofday() -. stamp));
35   let metasenv, proofterm = 
36     let rec aux k metasenv = function
37       | NCic.Meta _ as t -> metasenv, t
38       | NCic.Implicit _ -> 
39           let metasenv, i, _, _ =
40             NCicMetaSubst.mk_meta metasenv context `IsTerm 
41           in
42             metasenv, NCic.Meta (i,(k,NCic.Irl (List.length context)))
43       | t -> NCicUntrusted.map_term_fold_a 
44           (fun _ k -> k+1) k aux metasenv t
45     in
46       aux 0 metasenv proofterm
47   in
48   prerr_endline "so far 1";
49   prerr_endline (NCicPp.ppterm ~metasenv ~subst ~context proofterm);
50   let metasenv, subst, proofterm, _prooftype = 
51     NCicRefiner.typeof 
52       (rdb#set_coerc_db NCicCoercion.empty_db) 
53       metasenv subst context proofterm None
54   in
55     proofterm, metasenv, subst
56
57 let nparamod rdb metasenv subst context t table =
58   let module C =
59     struct 
60       let metasenv = metasenv
61       let subst = subst
62       let context = context 
63     end 
64   in
65   let module B = B(C) in
66   let module P = NCicParamod(C) in
67   let module Pp = Pp.Pp(B) in
68   let bag, maxvar = Terms.empty_bag, 0 in
69   let (bag,maxvar), goals = 
70     HExtlib.list_mapi_acc (fun x _ a -> P.mk_goal a x) (bag,maxvar) [t]
71   in
72   let (bag,maxvar), passives = 
73     HExtlib.list_mapi_acc (fun x _ a -> P.mk_passive a x) (bag,maxvar) table
74   in
75   match 
76     P.paramod ~useage:true ~max_steps:max_int ~timeout:(Unix.gettimeofday () +. 300.0) 
77       ~g_passives:goals ~passives (bag,maxvar) 
78   with 
79   | P.Error _ | P.GaveUp | P.Timeout _ -> []
80   | P.Unsatisfiable solutions -> 
81       List.map (readback rdb metasenv subst context) solutions
82 ;;
83   
84 module EmptyC = 
85   struct
86     let metasenv = []
87     let subst = []
88     let context = []
89   end
90
91 module P = NCicParamod(EmptyC)
92
93 type state = P.state
94 let empty_state = P.empty_state
95
96 let forward_infer_step s t ty =
97   let bag = P.bag_of_state s in 
98   let bag,clause = P.mk_passive bag (t,ty) in
99     if Terms.is_eq_clause clause then
100       P.forward_infer_step (P.replace_bag s bag) clause 0
101     else (prerr_endline "not and equality"; s)
102 ;;
103
104 let index_obj s uri =
105   let obj = NCicEnvironment.get_checked_obj uri in
106   match obj with
107     | (_,_,[],[],NCic.Constant(_,_,Some(t),ty,_)) ->
108         forward_infer_step s t ty
109     | _ -> s
110 ;;
111
112 let fast_eq_check rdb metasenv subst context s goal =
113   match P.fast_eq_check s goal with
114   | P.Error _ | P.GaveUp | P.Timeout _ -> []
115   | P.Unsatisfiable solutions -> 
116       List.map (readback rdb metasenv subst context) solutions
117 ;;
118