]> matita.cs.unibo.it Git - helm.git/blob - helm/software/components/ng_paramodulation/nCicParamod.ml
ff34709e9c7a262453de6a124ba6e641919b11b6
[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 let nparamod rdb metasenv subst context (g_t,g_ty) table =
15   let module C = 
16     struct
17       let metasenv = metasenv
18       let subst = subst
19       let context = context
20     end
21   in
22   let module B : Orderings.Blob 
23       with type t = NCic.term 
24     = Orderings.NRKBO(NCicBlob.NCicBlob(C))
25   in
26   let module P = Paramod.Paramod(B) in
27   let module Pp = Pp.Pp(B) in
28
29   let rec embed = function
30     | NCic.Meta (i,_) -> Terms.Var i, [i]
31     | NCic.Appl l ->
32         let rec aux acc l = function
33           |[] -> acc@l
34           |hd::tl -> if List.mem hd l then aux acc l tl else aux (hd::acc) l tl
35         in
36         let res,vars = List.fold_left
37           (fun (r,v) t -> let r1,v1 = embed t in (r1::r),aux [] v v1) ([],[]) l
38         in (Terms.Node (List.rev res)), vars
39     | t -> Terms.Leaf t, []
40   in
41
42   let embed t = fst (embed t) in
43
44   let saturate ~is_goal t ty = 
45     let sty, _, args = 
46       NCicMetaSubst.saturate ~delta:max_int C.metasenv C.subst C.context ty 0
47     in
48     let proof = 
49       if args = [] then Terms.Leaf t 
50       else Terms.Node (Terms.Leaf t :: List.map embed args)
51     in
52     let sty = embed sty in
53     proof, if is_goal then [sty],[] else [],[sty]
54   in
55    let goal = saturate ~is_goal:true g_t g_ty in
56    let hypotheses = List.map (fun (t,ty) -> saturate ~is_goal:false t ty) table in
57  (*let (bag,maxvar), passives = 
58     HExtlib.list_mapi_acc (fun x _ a -> P.mk_passive a x) (bag,maxvar) table
59   in
60   let (bag,maxvar), goals = 
61     HExtlib.list_mapi_acc (fun x _ a -> P.mk_goal a x) (bag,maxvar) [t]
62   in*)
63   match 
64     P.paramod ~useage:true ~max_steps:max_int ~print_problem:true
65       goal hypotheses
66   with 
67   | P.Error _ | P.GaveUp | P.Timeout _ -> []
68   | P.Unsatisfiable solutions ->
69   List.map 
70     (fun (bag,i,l) ->
71       (* List.iter (fun x ->
72         print_endline (Pp.pp_unit_clause ~margin:max_int
73           (fst(Terms.M.find x bag)))) l; *)
74       let stamp = Unix.gettimeofday () in
75       let proofterm = NCicProof.mk_proof bag i l in
76       prerr_endline (Printf.sprintf "Got proof term in %fs"
77         (Unix.gettimeofday() -. stamp));
78       let metasenv, proofterm = 
79         let rec aux k metasenv = function
80           | NCic.Meta _ as t -> metasenv, t
81           | NCic.Implicit _ -> 
82               let metasenv,i,_,_=NCicMetaSubst.mk_meta metasenv context `Term in
83               metasenv, NCic.Meta (i,(k,NCic.Irl (List.length context)))
84           | t -> NCicUntrusted.map_term_fold_a 
85                   (fun _ k -> k+1) k aux metasenv t
86         in
87          aux 0 metasenv proofterm
88       in
89       let metasenv, subst, proofterm, _prooftype = 
90         NCicRefiner.typeof 
91           (rdb#set_coerc_db NCicCoercion.empty_db) 
92           metasenv subst context proofterm None
93       in
94       proofterm, metasenv, subst)
95     solutions
96 ;;
97   
98   
99
100