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