]> matita.cs.unibo.it Git - helm.git/blob - helm/software/components/ng_paramodulation/nCicBlob.ml
saturate cust be called with delta=0
[helm.git] / helm / software / components / ng_paramodulation / nCicBlob.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: terms.mli 9822 2009-06-03 15:37:06Z tassi $ *)
13
14 let eqPref = ref (fun _ -> assert false);;
15 let set_eqP t = eqPref := fun _ -> t;;
16
17 let default_eqP() = 
18   let uri = NUri.uri_of_string "cic:/matita/ng/Plogic/equality/eq.ind" in
19   let ref = NReference.reference_of_spec uri (NReference.Ind(true,0,2)) in
20     NCic.Const ref
21 ;;
22
23 let set_default_eqP() = eqPref := default_eqP
24
25 let set_reference_of_oxuri f = 
26   let eqnew = function 
27       _ -> 
28         let r = f(UriManager.uri_of_string 
29           "cic:/matita/logic/equality/eq.ind#xpointer(1/1)")
30         in
31           NCic.Const r
32   in
33     eqPref := eqnew
34 ;;
35
36
37 module type NCicContext =
38   sig
39     val metasenv : NCic.metasenv
40     val subst : NCic.substitution
41     val context : NCic.context
42   end
43
44 module NCicBlob(C : NCicContext) : Terms.Blob 
45 with type t = NCic.term and type input = NCic.term = struct
46
47   type t = NCic.term
48
49   let eq x y = x = y;;
50     (* NCicReduction.alpha_eq C.metasenv C.subst C.context x y;; *)
51
52   let rec compare x y = 
53     match x,y with
54     | NCic.Rel i, NCic.Rel j -> j-i
55     | NCic.Meta (i,_), NCic.Meta (j,_) -> i-j
56     | NCic.Const r1, NCic.Const r2 -> NReference.compare r1 r2
57     | NCic.Appl l1, NCic.Appl l2 -> FoUtils.lexicograph compare l1 l2
58     | NCic.Rel _, ( NCic.Meta _ | NCic.Const _ | NCic.Appl _ ) -> ~-1
59     | ( NCic.Meta _ | NCic.Const _ | NCic.Appl _ ), NCic.Rel _ -> 1
60     | NCic.Const _, ( NCic.Meta _ | NCic.Appl _ ) -> ~-1
61     | ( NCic.Meta _ | NCic.Appl _ ), NCic.Const _ -> 1
62     | NCic.Appl _, NCic.Meta _ -> ~-1
63     | NCic.Meta _, NCic.Appl _ -> 1
64     | _ -> Pervasives.compare x y
65         (* was assert false, but why? *)
66         
67   ;;
68   
69   let compare x y = 
70     (* if NCicReduction.alpha_eq C.metasenv C.subst C.context x y  then 0 *)
71     if x = y  then 0
72     else compare x y
73   ;;
74
75   let pp t = 
76     NCicPp.ppterm ~context:C.context ~metasenv:C.metasenv ~subst:C.subst t;;
77
78   type input = NCic.term
79
80   let rec embed = function
81     | NCic.Meta (i,_) -> Terms.Var i, [i]
82     | NCic.Appl l ->
83         let rec aux acc l = function
84           |[] -> acc@l
85           |hd::tl -> if List.mem hd l then aux acc l tl else aux (hd::acc) l tl
86         in
87         let res,vars = List.fold_left
88           (fun (r,v) t -> let r1,v1 = embed t in (r1::r),aux [] v v1) ([],[]) l
89         in (Terms.Node (List.rev res)), vars
90     | t -> Terms.Leaf t, []
91   ;;
92
93   let embed t = fst (embed t) ;;
94
95   let saturate t ty = 
96     let sty, _, args = 
97       NCicMetaSubst.saturate ~delta:0 C.metasenv C.subst C.context
98         ty 0
99     in
100     let proof = 
101       if args = [] then Terms.Leaf t 
102       else Terms.Node (Terms.Leaf t :: List.map embed args)
103     in
104     let sty = embed sty in
105     proof, sty
106   ;;
107   
108   let eqP = (!eqPref)()
109   ;;
110
111  end