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.
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_______________________________________________________________ *)
12 (* $Id: terms.mli 9822 2009-06-03 15:37:06Z tassi $ *)
14 let eqPref = ref (fun _ -> assert false);;
15 let set_eqP t = eqPref := fun _ -> t;;
18 let uri = NUri.uri_of_string "cic:/matita/basics/logic/eq.ind" in
19 let ref = NReference.reference_of_spec uri (NReference.Ind(true,0,2)) in
23 let equivalence_relation =
24 let uri = NUri.uri_of_string "cic:/matita/ng/properties/relations/eq_rel.con"
26 let ref = NReference.reference_of_spec uri (NReference.Fix(0,1,2))
30 let uri = NUri.uri_of_string "cic:/matita/ng/sets/setoids/eq.con" in
31 let ref = NReference.reference_of_spec uri (NReference.Fix(0,0,2))
34 let set_default_eqP() = eqPref := default_eqP
36 module type NCicContext =
38 val metasenv : NCic.metasenv
39 val subst : NCic.substitution
40 val context : NCic.context
43 module NCicBlob(C : NCicContext) : Terms.Blob
44 with type t = NCic.term and type input = NCic.term = struct
49 (* NCicReduction.alpha_eq C.metasenv C.subst C.context x y;; *)
51 let height_of_ref = function
52 | NReference.Def h -> h
53 | NReference.Fix(_,_,h) -> h
56 let compare_refs (NReference.Ref (u1,r1)) (NReference.Ref (u2,r2)) =
57 let x = height_of_ref r2 - height_of_ref r1 in
59 Hashtbl.hash (NUri.string_of_uri u1,r1) -
60 Hashtbl.hash (NUri.string_of_uri u2,r2)
65 | NCic.Rel i, NCic.Rel j -> j-i
66 | NCic.Meta (i,_), NCic.Meta (j,_) -> i-j
67 | NCic.Const r1, NCic.Const r2 -> compare_refs r1 r2
68 (*NReference.compare r1 r2*)
69 | NCic.Appl l1, NCic.Appl l2 -> FoUtils.lexicograph compare l1 l2
70 | NCic.Rel _, ( NCic.Meta _ | NCic.Const _ | NCic.Appl _ ) -> ~-1
71 | ( NCic.Meta _ | NCic.Const _ | NCic.Appl _ ), NCic.Rel _ -> 1
72 | NCic.Const _, ( NCic.Meta _ | NCic.Appl _ ) -> ~-1
73 | ( NCic.Meta _ | NCic.Appl _ ), NCic.Const _ -> 1
74 | NCic.Appl _, NCic.Meta _ -> ~-1
75 | NCic.Meta _, NCic.Appl _ -> 1
76 | _ -> Pervasives.compare x y
77 (* was assert false, but why? *)
82 (* CSC: NCicPp.status is the best I can put here *)
83 if NCicReduction.alpha_eq (new NCicPp.status) [] [] [] x y then 0
92 | Terms.Node [ Terms.Leaf eqt ; ty; l; r ] when eq eqP eqt ->
95 | Terms.Node [ Terms.Leaf eqt ; _; Terms.Node [Terms.Leaf eqt2 ; ty]; l; r]
96 when eq equivalence_relation eqt && eq setoid_eq eqt2 ->
101 (* CSC: NCicPp.status is the best I can put here *)
102 (new NCicPp.status)#ppterm ~context:C.context
103 ~metasenv:C.metasenv ~subst:C.subst t;;
105 type input = NCic.term
107 let rec embed = function
108 | NCic.Meta (i,_) -> Terms.Var i, [i]
110 let rec aux acc l = function
112 |hd::tl -> if List.mem hd l then aux acc l tl else aux (hd::acc) l tl
114 let res,vars = List.fold_left
115 (fun (r,v) t -> let r1,v1 = embed t in (r1::r),aux [] v v1) ([],[]) l
116 in (Terms.Node (List.rev res)), vars
117 | t -> Terms.Leaf t, []
120 let embed t = fst (embed t) ;;
124 (* CSC: NCicPp.status is the best I can put here *)
125 NCicMetaSubst.saturate (new NCicPp.status) ~delta:0 C.metasenv C.subst
129 if args = [] then Terms.Leaf t
130 else Terms.Node (Terms.Leaf t :: List.map embed args)
132 let sty = embed sty in