1 (* Copyright (C) 2005, HELM Team.
3 * This file is part of HELM, an Hypertextual, Electronic
4 * Library of Mathematics, developed at the Computer Science
5 * Department, University of Bologna, Italy.
7 * HELM is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
12 * HELM is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with HELM; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
22 * For details, see the HELM World-Wide-Web page,
23 * http://cs.unibo.it/helm/.
28 (** {2 Auxiliary functions} *)
30 let uri = UriManager.uri_of_string
32 let const ?(subst = []) uri = Cic.Const (uri, subst)
33 let var ?(subst = []) uri = Cic.Var (uri, subst)
34 let mutconstruct ?(subst = []) uri typeno consno =
35 Cic.MutConstruct (uri, typeno, consno, subst)
36 let mutind ?(subst = []) uri typeno = Cic.MutInd (uri, typeno, subst)
38 let indtyuri_of_uri uri =
39 let index_sharp = String.index uri '#' in
40 let index_num = index_sharp + 3 in
41 (UriManager.uri_of_string (String.sub uri 0 index_sharp),
42 int_of_string(String.sub uri index_num (String.length uri - index_num)) - 1)
44 let indconuri_of_uri uri =
45 let index_sharp = String.index uri '#' in
46 let index_div = String.rindex uri '/' in
47 let index_con = index_div + 1 in
48 (UriManager.uri_of_string (String.sub uri 0 index_sharp),
50 (String.sub uri (index_sharp + 3) (index_div - index_sharp - 3)) - 1,
52 (String.sub uri index_con (String.length uri - index_con)))
54 (** {2 Helm's objects shorthands} *)
58 let eq_SURI = "cic:/Coq/Init/Logic/eq.ind"
59 let eq_URI = uri eq_SURI
60 let eq_XURI = eq_SURI ^ "#xpointer(1/1)"
61 let eq_ind_URI = uri "cic:/Coq/Init/Logic/eq_ind.con"
62 let eq_ind_r_URI = uri "cic:/Coq/Init/Logic/eq_ind_r.con"
63 let true_URI = uri "cic:/Coq/Init/Logic/True.ind"
64 let false_URI = uri "cic:/Coq/Init/Logic/False.ind"
65 let false_ind_URI = uri "cic:/Coq/Init/Logic/False_ind.con"
66 let ex_SURI = "cic:/Coq/Init/Logic/ex.ind"
67 let ex_URI = uri ex_SURI
68 let ex_XURI = ex_SURI ^ "#xpointer(1/1)"
69 let ex_ind_URI = uri "cic:/Coq/Init/Logic/ex_ind.con"
70 let and_SURI = "cic:/Coq/Init/Logic/and.ind"
71 let and_URI = uri and_SURI
72 let and_XURI = and_SURI ^ "#xpointer(1/1)"
73 let and_ind_URI = uri "cic:/Coq/Init/Logic/and_ind.con"
74 let or_SURI = "cic:/Coq/Init/Logic/or.ind"
75 let or_URI = uri or_SURI
76 let or_XURI = or_SURI ^ "#xpointer(1/1)"
77 let not_SURI = "cic:/Coq/Init/Logic/not.con"
78 let not_URI = uri not_SURI
79 let iff_SURI = "cic:/Coq/Init/Logic/iff.con"
80 let iff_URI = uri "cic:/Coq/Init/Logic/iff.con"
81 let sym_eq_URI = uri "cic:/Coq/Init/Logic/sym_eq.con"
82 let trans_eq_URI = uri "cic:/Coq/Init/Logic/trans_eq.con"
83 let absurd_URI = uri "cic:/Coq/Init/Logic/absurd.con"
88 let bool_URI = uri "cic:/Coq/Init/Datatypes/bool.ind"
89 let nat_URI = uri "cic:/Coq/Init/Datatypes/nat.ind"
91 let trueb = mutconstruct bool_URI 0 1
92 let falseb = mutconstruct bool_URI 0 2
93 let zero = mutconstruct nat_URI 0 1
94 let succ = mutconstruct nat_URI 0 2
99 let r_URI = uri "cic:/Coq/Reals/Rdefinitions/R.con"
100 let rplus_SURI = "cic:/Coq/Reals/Rdefinitions/Rplus.con"
101 let rplus_URI = uri rplus_SURI
102 let rminus_SURI = "cic:/Coq/Reals/Rdefinitions/Rminus.con"
103 let rminus_URI = uri rminus_SURI
104 let rmult_SURI = "cic:/Coq/Reals/Rdefinitions/Rmult.con"
105 let rmult_URI = uri rmult_SURI
106 let rdiv_SURI = "cic:/Coq/Reals/Rdefinitions/Rdiv.con"
107 let rdiv_URI = uri rdiv_SURI
108 let ropp_SURI = "cic:/Coq/Reals/Rdefinitions/Ropp.con"
109 let ropp_URI = uri ropp_SURI
110 let rinv_SURI = "cic:/Coq/Reals/Rdefinitions/Rinv.con"
111 let rinv_URI = uri rinv_SURI
112 let r0_SURI = "cic:/Coq/Reals/Rdefinitions/R0.con"
113 let r0_URI = uri r0_SURI
114 let r1_SURI = "cic:/Coq/Reals/Rdefinitions/R1.con"
115 let r1_URI = uri r1_SURI
116 let rle_SURI = "cic:/Coq/Reals/Rdefinitions/Rle.con"
117 let rle_URI = uri rle_SURI
118 let rge_SURI = "cic:/Coq/Reals/Rdefinitions/Rge.con"
119 let rge_URI = uri rge_SURI
120 let rlt_SURI = "cic:/Coq/Reals/Rdefinitions/Rlt.con"
121 let rlt_URI = uri rlt_SURI
122 let rgt_SURI = "cic:/Coq/Reals/Rdefinitions/Rgt.con"
123 let rgt_URI = uri rgt_SURI
124 let rtheory_URI = uri "cic:/Coq/Reals/RIneq/RTheory.con"
125 let rinv_r1_URI = uri "cic:/Coq/Reals/RIneq/Rinv_1.con"
126 let pow_URI = uri "cic:/Coq/Reals/Rfunctions/pow.con"
129 let rplus = const rplus_URI
130 let rmult = const rmult_URI
131 let ropp = const ropp_URI
132 let r0 = const r0_URI
133 let r1 = const r1_URI
134 let rtheory = const rtheory_URI
139 let plus_SURI = "cic:/Coq/Init/Peano/plus.con"
140 let plus_URI = uri plus_SURI
141 let minus_SURI = "cic:/Coq/Init/Peano/minus.con"
142 let minus_URI = uri minus_SURI
143 let mult_SURI = "cic:/Coq/Init/Peano/mult.con"
144 let mult_URI = uri mult_SURI
145 let pred_URI = uri "cic:/Coq/Init/Peano/pred.con"
146 let le_SURI = "cic:/Coq/Init/Peano/le.ind"
147 let le_URI = uri le_SURI
148 let le_XURI = le_SURI ^ "#xpointer(1/1)"
149 let ge_SURI = "cic:/Coq/Init/Peano/ge.con"
150 let ge_URI = uri ge_SURI
151 let lt_SURI = "cic:/Coq/Init/Peano/lt.con"
152 let lt_URI = uri lt_SURI
153 let gt_SURI = "cic:/Coq/Init/Peano/gt.con"
154 let gt_URI = uri gt_SURI
156 let plus = const plus_URI
157 let mult = const mult_URI
158 let pred = const pred_URI
163 let positive_SURI = "cic:/Coq/NArith/BinPos/positive.ind"
164 let positive_URI = uri positive_SURI
165 let xI = mutconstruct positive_URI 0 1
166 let xO = mutconstruct positive_URI 0 2
167 let xH = mutconstruct positive_URI 0 3
168 let pplus_SURI = "cic:/Coq/NArith/BinPos/Pplus.con"
169 let pplus_URI = uri pplus_SURI
170 let pplus = const pplus_URI
171 let pminus_SURI = "cic:/Coq/NArith/BinPos/Pminus.con"
172 let pminus_URI = uri pminus_SURI
173 let pminus = const pminus_URI
174 let pmult_SURI = "cic:/Coq/NArith/BinPos/Pmult.con"
175 let pmult_URI = uri pmult_SURI
176 let pmult = const pmult_URI
181 let zmult_URI = uri "cic:/Coq/ZArith/BinInt/Zmult.con"
182 let zmult = const zmult_URI
183 let zplus_SURI = "cic:/Coq/ZArith/BinInt/Zplus.con"
184 let zplus_URI = uri zplus_SURI
185 let zplus = const zplus_URI
186 let zminus_SURI = "cic:/Coq/ZArith/BinInt/Zminus.con"
187 let zminus_URI = uri zminus_SURI
188 let zminus = const zminus_URI
189 let z_SURI = "cic:/Coq/ZArith/BinInt/Z.ind"
190 let z_URI = uri z_SURI
191 let z0 = mutconstruct z_URI 0 1
192 let zpos = mutconstruct z_URI 0 2
193 let zneg = mutconstruct z_URI 0 3
194 let zopp_SURI = "cic:/Coq/ZArith/BinInt/Zopp.con"
195 let zopp_URI = uri zopp_SURI
196 let zopp = const zopp_URI
197 let zpower_URI = uri "cic:/Coq/ZArith/Zpower/Zpower.con"
200 (** {2 Helpers for creating common terms}
203 exception NegativeInteger
206 if n < 0 then raise NegativeInteger;
207 let rec aux = function
208 | 0 -> Datatypes.zero
209 | n -> Cic.Appl [ Datatypes.succ; (aux (n - 1)) ]
214 if n < 0 then raise NegativeInteger;
215 let rec aux = function
217 | 1 -> Reals.r1 (* to avoid trailing "+ 0" *)
218 | n -> Cic.Appl [ Reals.rplus; Reals.r1; (aux (n - 1)) ]
222 let build_bin_pos n =
223 if n < 1 then raise NegativeInteger;
224 let rec aux = function
226 | n when n mod 2 = 0 -> Cic.Appl [ BinPos.xO; aux (n / 2) ]
227 | n -> Cic.Appl [ BinPos.xI; aux (n / 2) ]