]> matita.cs.unibo.it Git - helm.git/blob - helm/style/arith.xsl
Modified Files:
[helm.git] / helm / style / arith.xsl
1 <?xml version="1.0"?>
2
3 <!-- Copyright (C) 2000, HELM Team                                     -->
4 <!--                                                                   -->
5 <!-- This file is part of HELM, an Hypertextual, Electronic            -->
6 <!-- Library of Mathematics, developed at the Computer Science         -->
7 <!-- Department, University of Bologna, Italy.                         -->
8 <!--                                                                   -->
9 <!-- HELM is free software; you can redistribute it and/or             -->
10 <!-- modify it under the terms of the GNU General Public License       -->
11 <!-- as published by the Free Software Foundation; either version 2    -->
12 <!-- of the License, or (at your option) any later version.            -->
13 <!--                                                                   -->
14 <!-- HELM is distributed in the hope that it will be useful,           -->
15 <!-- but WITHOUT ANY WARRANTY; without even the implied warranty of    -->
16 <!-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the     -->
17 <!-- GNU General Public License for more details.                      -->
18 <!--                                                                   -->
19 <!-- You should have received a copy of the GNU General Public License -->
20 <!-- along with HELM; if not, write to the Free Software               -->
21 <!-- Foundation, Inc., 59 Temple Place - Suite 330, Boston,            -->
22 <!-- MA  02111-1307, USA.                                              -->
23 <!--                                                                   -->
24 <!-- For details, see the HELM World-Wide-Web page,                    -->
25 <!-- http://cs.unibo.it/helm/.                                         -->
26
27 <!--******************************************************************--> 
28 <!-- Arithmetics                                                      -->
29 <!-- First draft: March 20 2001, Ferruccio Guidi                      -->
30 <!-- Zarith: July 2001, Andrea Asperti                                -->
31 <!--******************************************************************-->
32
33 <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
34                               xmlns:m="http://www.w3.org/1998/Math/MathML"
35                               xmlns:helm="http://www.cs.unibo.it/helm">
36
37 <!-- ************************** ARITHMETICS ****************************** -->
38
39 <!-- S and O -->
40 <xsl:template match="APPLY[*[position()=1 and name()='MUTCONSTRUCT' and @uri='cic:/Coq/Init/Datatypes/nat.ind' and @noConstr='2'] and count(*)=2]" mode="pure">
41    <xsl:apply-templates select="*[2]" mode="succ">
42     <xsl:with-param name="n" select="1"/>
43     <xsl:with-param name="iden" select="@id"/>
44    </xsl:apply-templates>
45 </xsl:template>
46
47 <xsl:template match="*" mode="succ">
48  <xsl:param name="n" select="0"/>
49  <xsl:param name="iden" select="''"/>
50  <xsl:choose>
51   <xsl:when test="name()='APPLY' and *[position()=1 and name()='MUTCONSTRUCT'
52 and @uri='cic:/Coq/Init/Datatypes/nat.ind' and @noConstr='2']">
53    <xsl:apply-templates select="*[2]" mode="succ">
54     <xsl:with-param name="n" select="$n +1"/>
55     <xsl:with-param name="iden" select="$iden"/>
56    </xsl:apply-templates>
57   </xsl:when>
58   <xsl:when test="name()='MUTCONSTRUCT' and @uri='cic:/Coq/Init/Datatypes/nat.ind' and @noConstr='1'">
59    <m:cn helm:xref="{$iden}"><xsl:value-of select="$n"/></m:cn>
60   </xsl:when>
61   <xsl:otherwise>
62    <m:apply helm:xref="{$iden}">
63     <m:plus/>
64     <m:cn><xsl:value-of select="$n"/></m:cn>
65     <xsl:apply-templates select="." mode="pure"/>
66    </m:apply>
67   </xsl:otherwise>
68  </xsl:choose>
69 </xsl:template>
70
71
72 <xsl:template match="APPLY[MUTIND/@uri='cic:/Coq/Init/Peano/le.ind']" mode="pure">
73    <xsl:call-template name="mk-mml-op-noannot">
74       <xsl:with-param name="arity" select="2"/>
75       <xsl:with-param name="c-tag" select="MUTIND"/>
76       <xsl:with-param name="m-tag" select="'leq'"/>
77    </xsl:call-template>
78 </xsl:template>
79
80 <xsl:template match="APPLY[CONST/@uri='cic:/Coq/Init/Peano/lt.con']" mode="pure">
81    <xsl:call-template name="mk-mml-op-noannot">
82       <xsl:with-param name="arity" select="2"/>
83       <xsl:with-param name="c-tag" select="CONST"/>
84       <xsl:with-param name="m-tag" select="'lt'"/>
85    </xsl:call-template>
86 </xsl:template>
87
88 <xsl:template match="APPLY[CONST/@uri='cic:/Coq/Init/Peano/ge.con']" mode="pure">
89    <xsl:call-template name="mk-mml-op-noannot">
90       <xsl:with-param name="arity" select="2"/>
91       <xsl:with-param name="c-tag" select="CONST"/>
92       <xsl:with-param name="m-tag" select="'geq'"/>
93    </xsl:call-template>
94 </xsl:template>
95
96 <xsl:template match="APPLY[CONST/@uri='cic:/Coq/Init/Peano/gt.con']" mode="pure">
97    <xsl:call-template name="mk-mml-op-noannot">
98       <xsl:with-param name="arity" select="2"/>
99       <xsl:with-param name="c-tag" select="CONST"/>
100       <xsl:with-param name="m-tag" select="'gt'"/>
101    </xsl:call-template>
102 </xsl:template>
103
104 <xsl:template match="APPLY[CONST/@uri='cic:/Coq/Init/Peano/plus.con']" mode="pure">
105    <xsl:call-template name="mk-mml-op-noannot">
106       <xsl:with-param name="arity" select="2"/>
107       <xsl:with-param name="c-tag" select="CONST"/>
108       <xsl:with-param name="m-tag" select="'plus'"/>
109    </xsl:call-template>
110 </xsl:template>
111
112 <xsl:template match="APPLY[CONST/@uri='cic:/Coq/Arith/Minus/minus.con']" mode="pure">
113    <xsl:call-template name="mk-mml-op-noannot">
114       <xsl:with-param name="arity" select="2"/>
115       <xsl:with-param name="c-tag" select="CONST"/>
116       <xsl:with-param name="m-tag" select="'minus'"/>
117    </xsl:call-template>
118 </xsl:template>
119
120 <xsl:template match="APPLY[CONST/@uri='cic:/Coq/Init/Peano/mult.con']" mode="pure">
121    <xsl:call-template name="mk-mml-op-noannot">
122       <xsl:with-param name="arity" select="2"/>
123       <xsl:with-param name="c-tag" select="CONST"/>
124       <xsl:with-param name="m-tag" select="'times'"/>
125    </xsl:call-template>
126 </xsl:template>
127
128 <xsl:template match="APPLY[CONST/@uri='cic:/Coq/Arith/Min/min.con']" mode="pure">
129    <xsl:call-template name="mk-mml-op-noannot">
130       <xsl:with-param name="arity" select="2"/>
131       <xsl:with-param name="c-tag" select="CONST"/>
132       <xsl:with-param name="m-tag" select="'min'"/>
133    </xsl:call-template>
134 </xsl:template>
135
136 <!-- **************************** Zarith ******************************** -->
137
138
139 <xsl:template match="APPLY[CONST/@uri='cic:/Coq/ZArith/zarith_aux/Zle.con']" mode="pure">
140    <xsl:call-template name="mk-mml-op-noannot">
141       <xsl:with-param name="arity" select="2"/>
142       <xsl:with-param name="c-tag" select="CONST"/>
143       <xsl:with-param name="m-tag" select="'leq'"/>
144    </xsl:call-template>
145 </xsl:template>
146
147 <xsl:template match="APPLY[CONST/@uri='cic:/Coq/ZArith/zarith_aux/Zlt.con']" mode="pure">
148    <xsl:call-template name="mk-mml-op-noannot">
149       <xsl:with-param name="arity" select="2"/>
150       <xsl:with-param name="c-tag" select="CONST"/>
151       <xsl:with-param name="m-tag" select="'lt'"/>
152    </xsl:call-template>
153 </xsl:template>
154
155 <xsl:template match="APPLY[CONST/@uri='cic:/Coq/ZArith/zarith_aux/Zge.con']" mode="pure">
156    <xsl:call-template name="mk-mml-op-noannot">
157       <xsl:with-param name="arity" select="2"/>
158       <xsl:with-param name="c-tag" select="CONST"/>
159       <xsl:with-param name="m-tag" select="'geq'"/>
160    </xsl:call-template>
161 </xsl:template>
162
163 <xsl:template match="APPLY[CONST/@uri='cic:/Coq/ZArith/zarith_aux/Zgt.con']" mode="pure">
164    <xsl:call-template name="mk-mml-op-noannot">
165       <xsl:with-param name="arity" select="2"/>
166       <xsl:with-param name="c-tag" select="CONST"/>
167       <xsl:with-param name="m-tag" select="'gt'"/>
168    </xsl:call-template>
169 </xsl:template>
170
171 <xsl:template match="APPLY[CONST/@uri='cic:/Coq/ZArith/fast_integer/fast_integers/Zplus.con']" mode="pure">
172    <xsl:call-template name="mk-mml-op-noannot">
173       <xsl:with-param name="arity" select="2"/>
174       <xsl:with-param name="c-tag" select="CONST"/>
175       <xsl:with-param name="m-tag" select="'plus'"/>
176    </xsl:call-template>
177 </xsl:template>
178
179 <xsl:template match="APPLY[CONST/@uri='cic:/Coq/ZArith/zarith_aux/Zminus.con']" mode="pure">
180    <xsl:call-template name="mk-mml-op-noannot">
181       <xsl:with-param name="arity" select="2"/>
182       <xsl:with-param name="c-tag" select="CONST"/>
183       <xsl:with-param name="m-tag" select="'minus'"/>
184    </xsl:call-template>
185 </xsl:template>
186
187 <xsl:template match="APPLY[CONST/@uri='cic:/Coq/ZArith/fast_integer/fast_integers/Zopp.con']" mode="pure">
188    <xsl:call-template name="mk-mml-op-noannot">
189       <xsl:with-param name="arity" select="1"/>
190       <xsl:with-param name="c-tag" select="CONST"/>
191       <xsl:with-param name="m-tag" select="'minus'"/>
192    </xsl:call-template>
193 </xsl:template>
194
195 <xsl:template match="APPLY[CONST/@uri='cic:/Coq/ZArith/fast_integer/fast_integers/Zmult.con']" mode="pure">
196    <xsl:call-template name="mk-mml-op-noannot">
197       <xsl:with-param name="arity" select="2"/>
198       <xsl:with-param name="c-tag" select="CONST"/>
199       <xsl:with-param name="m-tag" select="'times'"/>
200    </xsl:call-template>
201 </xsl:template>
202
203 <xsl:template match="APPLY[CONST/@uri='cic:/Coq/ZArith/zarith_aux/Zmin.con']" mode="pure">
204    <xsl:call-template name="mk-mml-op-noannot">
205       <xsl:with-param name="arity" select="2"/>
206       <xsl:with-param name="c-tag" select="CONST"/>
207       <xsl:with-param name="m-tag" select="'min'"/>
208    </xsl:call-template>
209 </xsl:template>
210
211 <xsl:template match="APPLY[CONST/@uri='cic:/Coq/ZArith/zarith_aux/absolu.con']" mode="pure">
212    <xsl:call-template name="mk-mml-op-noannot">
213       <xsl:with-param name="arity" select="1"/>
214       <xsl:with-param name="c-tag" select="CONST"/>
215       <xsl:with-param name="m-tag" select="'abs'"/>
216    </xsl:call-template>
217 </xsl:template>
218
219 <!-- POS, NEG e ZERO -->
220
221 <xsl:template match="APPLY[*[position()=1 and name()='MUTCONSTRUCT' and @uri='cic:/Coq/ZArith/fast_integer/fast_integers/Z.ind' and @noConstr='2'] and count(*)=2]" mode="pure">
222    <xsl:apply-templates select="*[2]" mode="Zpositive">
223     <xsl:with-param name="base" select="0"/>
224     <xsl:with-param name="exp" select="1"/>
225     <xsl:with-param name="iden" select="*[2]/@id"/>
226    </xsl:apply-templates>
227 </xsl:template>
228  
229 <xsl:template match="APPLY[*[position()=1 and name()='MUTCONSTRUCT' and @uri='cic:/Coq/ZArith/fast_integer/fast_integers/Z.ind' and @noConstr='3'] and count(*)=2]" mode="pure">
230    <m:apply helm:xref="{@id}">
231     <m:minus definitionURL="{*[1]/@uri}" helm:xref="{*[1]/@id}"/>
232     <xsl:apply-templates select="*[2]" mode="Zpositive">
233      <xsl:with-param name="base" select="0"/>
234      <xsl:with-param name="exp" select="1"/>
235      <xsl:with-param name="iden" select="*[2]/@id"/>
236     </xsl:apply-templates>
237    </m:apply>
238 </xsl:template>
239
240 <xsl:template match="MUTCONSTRUCT[@uri='cic:/Coq/ZArith/fast_integer/fast_integers/Z.ind' and @noConstr='1']" mode="pure">
241    <m:ci definitionURL="{@uri}" helm:xref="{@id}">0</m:ci>
242 </xsl:template>
243
244 <!-- prova di notazione per positive -->
245
246 <xsl:template match="APPLY[*[position()=1 and name()='MUTCONSTRUCT' and @uri='cic:/Coq/ZArith/fast_integer/fast_integers/positive.ind']]" mode="pure">
247    <xsl:apply-templates select="." mode="Zpositive">
248     <xsl:with-param name="base" select="0"/>
249     <xsl:with-param name="exp" select="1"/>
250     <xsl:with-param name="iden" select="@id"/>
251    </xsl:apply-templates>
252 </xsl:template>
253
254 <xsl:template match="MUTCONSTRUCT[@uri='cic:/Coq/ZArith/fast_integer/fast_integers/positive.ind' and @noConstr='3']" mode="pure">
255  <m:ci definitionURL="{@uri}" helm:xref="{@id}">1</m:ci>
256 </xsl:template> 
257
258 <xsl:template match="*" mode="Zpositive">
259  <xsl:param name="base" select="0"/>
260  <xsl:param name="exp" select="1"/>
261  <xsl:param name="iden" select="''"/>
262  <xsl:choose>
263   <xsl:when test="name()='APPLY' and *[position()=1 and name()='MUTCONSTRUCT'
264 and @uri='cic:/Coq/ZArith/fast_integer/fast_integers/positive.ind' and @noConstr='1']">
265    <xsl:apply-templates select="*[2]" mode="Zpositive">
266     <xsl:with-param name="base" select="$base + $exp"/>
267     <xsl:with-param name="exp" select="2 * $exp"/>
268     <xsl:with-param name="iden" select="$iden"/>
269    </xsl:apply-templates>
270   </xsl:when>
271   <xsl:when test="name()='APPLY' and *[position()=1 and name()='MUTCONSTRUCT' 
272 and @uri='cic:/Coq/ZArith/fast_integer/fast_integers/positive.ind' and @noConstr='2']">
273    <xsl:apply-templates select="*[2]" mode="Zpositive">
274     <xsl:with-param name="base" select="$base"/>
275     <xsl:with-param name="exp" select="2 * $exp"/>
276     <xsl:with-param name="iden" select="$iden"/>
277    </xsl:apply-templates>
278   </xsl:when>
279   <xsl:when test="name()='MUTCONSTRUCT' and @uri='cic:/Coq/ZArith/fast_integer/fast_integers/positive.ind' and @noConstr='3'">
280    <m:ci helm:xref="{$iden}"><xsl:value-of select="$base + $exp"/></m:ci>
281   </xsl:when>
282   <xsl:otherwise>
283    <xsl:choose>
284     <xsl:when test="$base = 0">
285      <xsl:choose>
286       <xsl:when test="$exp = 1">
287        <xsl:apply-templates select="." mode="pure"/>
288       </xsl:when>
289       <xsl:otherwise>
290        <m:apply helm:xref="{$iden}">
291         <m:times/>
292         <m:ci><xsl:value-of select="$exp"/></m:ci>
293         <xsl:apply-templates select="." mode="pure"/>
294        </m:apply>
295       </xsl:otherwise>
296      </xsl:choose>
297     </xsl:when>
298     <xsl:otherwise>
299      <m:apply helm:xref="{$iden}">
300       <m:plus/>
301       <m:ci><xsl:value-of select="$base"/></m:ci>
302       <xsl:choose>
303        <xsl:when test="$exp = 1">
304         <xsl:apply-templates select="." mode="pure"/>
305        </xsl:when>
306        <xsl:otherwise>
307         <m:apply helm:xref="{$iden}">
308          <m:times/>
309          <m:ci><xsl:value-of select="$exp"/></m:ci>
310          <xsl:apply-templates select="." mode="pure"/>
311         </m:apply>
312        </xsl:otherwise>
313       </xsl:choose>
314      </m:apply>
315     </xsl:otherwise>
316    </xsl:choose>
317   </xsl:otherwise>
318  </xsl:choose>
319 </xsl:template>
320
321
322 </xsl:stylesheet>