]> matita.cs.unibo.it Git - helm.git/blob - helm/software/components/ng_paramodulation/nCicBlob.ml
Release 0.5.9.
[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 reference_of_oxuri = ref (fun _ -> assert false);;
15 let set_reference_of_oxuri f = reference_of_oxuri := f;;
16
17 module type NCicContext =
18   sig
19     val metasenv : NCic.metasenv
20     val subst : NCic.substitution
21     val context : NCic.context
22   end
23
24 module NCicBlob(C : NCicContext) : Terms.Blob 
25 with type t = NCic.term and type input = NCic.term = struct
26
27   type t = NCic.term
28
29   let eq x y = NCicReduction.alpha_eq C.metasenv C.subst C.context x y;;
30
31   let rec compare x y = 
32     match x,y with
33     | NCic.Rel i, NCic.Rel j -> j-i
34     | NCic.Meta (i,_), NCic.Meta (j,_) -> i-j
35     | NCic.Const r1, NCic.Const r2 -> NReference.compare r1 r2
36     | NCic.Appl l1, NCic.Appl l2 -> FoUtils.lexicograph compare l1 l2
37     | NCic.Rel _, ( NCic.Meta _ | NCic.Const _ | NCic.Appl _ ) -> ~-1
38     | ( NCic.Meta _ | NCic.Const _ | NCic.Appl _ ), NCic.Rel _ -> 1
39     | NCic.Const _, ( NCic.Meta _ | NCic.Appl _ ) -> ~-1
40     | ( NCic.Meta _ | NCic.Appl _ ), NCic.Const _ -> 1
41     | NCic.Appl _, NCic.Meta _ -> ~-1
42     | NCic.Meta _, NCic.Appl _ -> 1
43     | _ -> assert false
44   ;;
45   
46   let compare x y = 
47     if NCicReduction.alpha_eq C.metasenv C.subst C.context x y then 0 
48     else compare x y
49   ;;
50
51   let pp t = 
52     NCicPp.ppterm ~context:C.context ~metasenv:C.metasenv ~subst:C.subst t;;
53
54   type input = NCic.term
55
56   let rec embed = function
57     | NCic.Meta (i,_) -> Terms.Var i, [i]
58     | NCic.Appl l ->
59         let rec aux acc l = function
60           |[] -> acc@l
61           |hd::tl -> if List.mem hd l then aux acc l tl else aux (hd::acc) l tl
62         in
63         let res,vars = List.fold_left
64           (fun (r,v) t -> let r1,v1 = embed t in (r1::r),aux [] v v1) ([],[]) l
65         in (Terms.Node (List.rev res)), vars
66     | t -> Terms.Leaf t, []
67   ;;
68
69   let embed t = fst (embed t) ;;
70
71   let saturate t ty = 
72     let sty, _, args = 
73       NCicMetaSubst.saturate ~delta:max_int C.metasenv C.subst C.context
74         ty 0
75     in
76     let proof = 
77       if args = [] then Terms.Leaf t 
78       else Terms.Node (Terms.Leaf t :: List.map embed args)
79     in
80     let sty = embed sty in
81     proof, sty
82   ;;
83
84   let eqP = 
85     let r = 
86       !reference_of_oxuri 
87        (UriManager.uri_of_string 
88          "cic:/matita/logic/equality/eq.ind#xpointer(1/1)")
89     in
90     NCic.Const r
91   ;;
92
93  end