1 (** {2 Auxiliary functions} *)
3 let uri = UriManager.uri_of_string
5 let const ?(subst = []) uri = Cic.Const (uri, subst)
6 let var ?(subst = []) uri = Cic.Var (uri, subst)
7 let mutconstruct ?(subst = []) uri typeno consno =
8 Cic.MutConstruct (uri, typeno, consno, subst)
9 let mutind ?(subst = []) uri typeno = Cic.MutInd (uri, typeno, subst)
11 let indtyuri_of_uri uri =
12 let index_sharp = String.index uri '#' in
13 let index_num = index_sharp + 3 in
14 (UriManager.uri_of_string (String.sub uri 0 index_sharp),
15 int_of_string(String.sub uri index_num (String.length uri - index_num)) - 1)
17 let indconuri_of_uri uri =
18 let index_sharp = String.index uri '#' in
19 let index_div = String.rindex uri '/' in
20 let index_con = index_div + 1 in
21 (UriManager.uri_of_string (String.sub uri 0 index_sharp),
23 (String.sub uri (index_sharp + 3) (index_div - index_sharp - 3)) - 1,
25 (String.sub uri index_con (String.length uri - index_con)))
27 (* (* NO LONGER USED, see CicUtil.term_of_uri *)
28 let term_of_uri ?(subst = []) uri =
29 let s = UriManager.string_of_uri uri in
32 let len = String.length s in
33 let sub = String.sub s (len -4) 4 in
36 else if sub = ".var" then
41 let (uri, typeno) = indtyuri_of_uri s in
42 mutind ~subst uri typeno
44 | UriManager.IllFormedUri _ | Failure _ | Invalid_argument _ ->
45 (* Constructor of an Inductive Type *)
46 let (uri, typeno, consno) = indconuri_of_uri s in
47 mutconstruct ~subst uri typeno consno)
49 | Invalid_argument _ | Not_found -> raise (UriManager.IllFormedUri s)
52 (** {2 Helm's objects shorthands} *)
56 let eq_SURI = "cic:/Coq/Init/Logic/eq.ind"
57 let eq_URI = uri eq_SURI
58 let eq_XURI = eq_SURI ^ "#xpointer(1/1)"
59 let eq_ind_URI = uri "cic:/Coq/Init/Logic/eq_ind.con"
60 let eq_ind_r_URI = uri "cic:/Coq/Init/Logic/eq_ind_r.con"
61 let true_URI = uri "cic:/Coq/Init/Logic/True.ind"
62 let false_URI = uri "cic:/Coq/Init/Logic/False.ind"
63 let false_ind_URI = uri "cic:/Coq/Init/Logic/False_ind.con"
64 let ex_SURI = "cic:/Coq/Init/Logic/ex.ind"
65 let ex_URI = uri ex_SURI
66 let ex_XURI = ex_SURI ^ "#xpointer(1/1)"
67 let ex_ind_URI = uri "cic:/Coq/Init/Logic/ex_ind.con"
68 let and_SURI = "cic:/Coq/Init/Logic/and.ind"
69 let and_URI = uri and_SURI
70 let and_XURI = and_SURI ^ "#xpointer(1/1)"
71 let and_ind_URI = uri "cic:/Coq/Init/Logic/and_ind.con"
72 let or_SURI = "cic:/Coq/Init/Logic/or.ind"
73 let or_URI = uri or_SURI
74 let or_XURI = or_SURI ^ "#xpointer(1/1)"
75 let not_SURI = "cic:/Coq/Init/Logic/not.con"
76 let not_URI = uri not_SURI
77 let iff_SURI = "cic:/Coq/Init/Logic/iff.con"
78 let iff_URI = uri "cic:/Coq/Init/Logic/iff.con"
79 let sym_eq_URI = uri "cic:/Coq/Init/Logic/sym_eq.con"
80 let trans_eq_URI = uri "cic:/Coq/Init/Logic/trans_eq.con"
81 let absurd_URI = uri "cic:/Coq/Init/Logic/absurd.con"
86 let bool_URI = uri "cic:/Coq/Init/Datatypes/bool.ind"
87 let nat_URI = uri "cic:/Coq/Init/Datatypes/nat.ind"
89 let trueb = mutconstruct bool_URI 0 1
90 let falseb = mutconstruct bool_URI 0 2
91 let zero = mutconstruct nat_URI 0 1
92 let succ = mutconstruct nat_URI 0 2
97 let r_URI = uri "cic:/Coq/Reals/Rdefinitions/R.con"
98 let rplus_SURI = "cic:/Coq/Reals/Rdefinitions/Rplus.con"
99 let rplus_URI = uri rplus_SURI
100 let rminus_SURI = "cic:/Coq/Reals/Rdefinitions/Rminus.con"
101 let rminus_URI = uri rminus_SURI
102 let rmult_SURI = "cic:/Coq/Reals/Rdefinitions/Rmult.con"
103 let rmult_URI = uri rmult_SURI
104 let rdiv_SURI = "cic:/Coq/Reals/Rdefinitions/Rdiv.con"
105 let rdiv_URI = uri rdiv_SURI
106 let ropp_SURI = "cic:/Coq/Reals/Rdefinitions/Ropp.con"
107 let ropp_URI = uri ropp_SURI
108 let rinv_SURI = "cic:/Coq/Reals/Rdefinitions/Rinv.con"
109 let rinv_URI = uri rinv_SURI
110 let r0_SURI = "cic:/Coq/Reals/Rdefinitions/R0.con"
111 let r0_URI = uri r0_SURI
112 let r1_SURI = "cic:/Coq/Reals/Rdefinitions/R1.con"
113 let r1_URI = uri r1_SURI
114 let rle_SURI = "cic:/Coq/Reals/Rdefinitions/Rle.con"
115 let rle_URI = uri rle_SURI
116 let rge_SURI = "cic:/Coq/Reals/Rdefinitions/Rge.con"
117 let rge_URI = uri rge_SURI
118 let rlt_SURI = "cic:/Coq/Reals/Rdefinitions/Rlt.con"
119 let rlt_URI = uri rlt_SURI
120 let rgt_SURI = "cic:/Coq/Reals/Rdefinitions/Rgt.con"
121 let rgt_URI = uri rgt_SURI
122 let rtheory_URI = uri "cic:/Coq/Reals/RIneq/RTheory.con"
123 let rinv_r1_URI = uri "cic:/Coq/Reals/RIneq/Rinv_1.con"
124 let pow_URI = uri "cic:/Coq/Reals/Rfunctions/pow.con"
127 let rplus = const rplus_URI
128 let rmult = const rmult_URI
129 let ropp = const ropp_URI
130 let r0 = const r0_URI
131 let r1 = const r1_URI
132 let rtheory = const rtheory_URI
137 let plus_SURI = "cic:/Coq/Init/Peano/plus.con"
138 let plus_URI = uri plus_SURI
139 let minus_SURI = "cic:/Coq/Init/Peano/minus.con"
140 let minus_URI = uri minus_SURI
141 let mult_SURI = "cic:/Coq/Init/Peano/mult.con"
142 let mult_URI = uri mult_SURI
143 let pred_URI = uri "cic:/Coq/Init/Peano/pred.con"
144 let le_SURI = "cic:/Coq/Init/Peano/le.ind"
145 let le_URI = uri le_SURI
146 let le_XURI = le_SURI ^ "#xpointer(1/1)"
147 let ge_SURI = "cic:/Coq/Init/Peano/ge.con"
148 let ge_URI = uri ge_SURI
149 let lt_SURI = "cic:/Coq/Init/Peano/lt.con"
150 let lt_URI = uri lt_SURI
151 let gt_SURI = "cic:/Coq/Init/Peano/gt.con"
152 let gt_URI = uri gt_SURI
154 let plus = const plus_URI
155 let mult = const mult_URI
156 let pred = const pred_URI
161 let positive_SURI = "cic:/Coq/NArith/BinPos/positive.ind"
162 let positive_URI = uri positive_SURI
163 let xI = mutconstruct positive_URI 0 1
164 let xO = mutconstruct positive_URI 0 2
165 let xH = mutconstruct positive_URI 0 3
166 let pplus_SURI = "cic:/Coq/NArith/BinPos/Pplus.con"
167 let pplus_URI = uri pplus_SURI
168 let pplus = const pplus_URI
169 let pminus_SURI = "cic:/Coq/NArith/BinPos/Pminus.con"
170 let pminus_URI = uri pminus_SURI
171 let pminus = const pminus_URI
172 let pmult_SURI = "cic:/Coq/NArith/BinPos/Pmult.con"
173 let pmult_URI = uri pmult_SURI
174 let pmult = const pmult_URI
179 let zmult_URI = uri "cic:/Coq/ZArith/BinInt/Zmult.con"
180 let zmult = const zmult_URI
181 let zplus_SURI = "cic:/Coq/ZArith/BinInt/Zplus.con"
182 let zplus_URI = uri zplus_SURI
183 let zplus = const zplus_URI
184 let zminus_SURI = "cic:/Coq/ZArith/BinInt/Zminus.con"
185 let zminus_URI = uri zminus_SURI
186 let zminus = const zminus_URI
187 let z_SURI = "cic:/Coq/ZArith/BinInt/Z.ind"
188 let z_URI = uri z_SURI
189 let z0 = mutconstruct z_URI 0 1
190 let zpos = mutconstruct z_URI 0 2
191 let zneg = mutconstruct z_URI 0 3
192 let zopp_SURI = "cic:/Coq/ZArith/BinInt/Zopp.con"
193 let zopp_URI = uri zopp_SURI
194 let zopp = const zopp_URI
195 let zpower_URI = uri "cic:/Coq/ZArith/Zpower/Zpower.con"
198 (** {2 Helpers for creating common terms}
201 exception NegativeInteger
204 if n < 0 then raise NegativeInteger;
205 let rec aux = function
206 | 0 -> Datatypes.zero
207 | n -> Cic.Appl [ Datatypes.succ; (aux (n - 1)) ]
212 if n < 0 then raise NegativeInteger;
213 let rec aux = function
215 | 1 -> Reals.r1 (* to avoid trailing "+ 0" *)
216 | n -> Cic.Appl [ Reals.rplus; Reals.r1; (aux (n - 1)) ]
220 let build_bin_pos n =
221 if n < 1 then raise NegativeInteger;
222 let rec aux = function
224 | n when n mod 2 = 0 -> Cic.Appl [ BinPos.xO; aux (n / 2) ]
225 | n -> Cic.Appl [ BinPos.xI; aux (n / 2) ]