3 <!-- Copyright (C) 2000, HELM Team -->
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. -->
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. -->
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. -->
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. -->
24 <!-- For details, see the HELM World-Wide-Web page, -->
25 <!-- http://cs.unibo.it/helm/. -->
27 <!--******************************************************************-->
29 <!-- (completely) Revisited: february 2001, Andrea Asperti -->
30 <!-- HELM Group: Asperti, Padovani, Sacerdoti, Schena -->
31 <!--******************************************************************-->
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">
37 <!-- ************************* LOGIC *********************************-->
39 <!-- Proof objects -->
41 <!-- <xsl:key name="typeid" use="@of" match="TYPE"/> -->
43 <!-- ALL this elements does not have inner type -->
44 <xsl:template match="LETIN|PROD|REL|SORT|VAR|META|CONST|MUTIND|MUTCONSTRUCT" mode="noannot">
45 <xsl:apply-templates select="." mode="pure"/>
48 <!-- ALL ELEMENTS WITH A TYPE ARE TRANSLATED AS A PROOF-ELEMENT -->
50 <!-- LAMBDA has inner type only if it is not nested inside another lambda -->
51 <xsl:template match="LAMBDA" mode="noannot">
52 <xsl:variable name="id" select="@id"/>
54 <xsl:when test="$naturalLanguage='yes' and @sort='Prop' and name(../..) != 'LAMBDA'">
55 <m:apply helm:xref="{@id}">
56 <m:csymbol>proof</m:csymbol>
57 <xsl:apply-templates mode="proof_transform" select="."/>
58 <!-- <xsl:apply-templates mode="try_inductive" select="."/> -->
59 <xsl:apply-templates mode="pure" select="$InnerTypes/InnerTypes/TYPE[@of=$id]/*"/>
63 <xsl:apply-templates select="." mode="pure"/>
68 <!-- ALL these elements have inner type -->
69 <xsl:template match="CAST|APPLY|MUTCASE|FIX|COFIX" mode="noannot">
70 <xsl:variable name="id" select="@id"/>
72 <xsl:when test="$naturalLanguage='yes' and @sort='Prop'">
73 <m:apply helm:xref="{@id}">
74 <m:csymbol>proof</m:csymbol>
75 <xsl:apply-templates mode="proof_transform" select="."/>
76 <!-- <xsl:apply-templates mode="try_inductive" select="."/> -->
77 <xsl:apply-templates mode="pure" select="$InnerTypes/InnerTypes/TYPE[@of=$id]/*"/>
82 <xsl:when test="name()='APPLY'">
83 <xsl:apply-templates select="." mode="letin"/>
86 <xsl:apply-templates select="." mode="pure"/>
93 <!-- si presuppone che il tipo induttivo non sia mutuamente
94 induttivo. Bisognerebbe andare a vedere l'utlimo parametro
95 del presunto "principio di induzione", tirare fuori il tipo induttivo
96 e vedere se il suo nome coincide con il prefisso di _ind.
97 Ad esempio nat_double_ind e' definito dall'utente. L'ultimo
98 parametro di nat_double_ind e' di tipo nat, e nat e' diverso
99 da nat_double. Per ora, verifico solo l'esistenza di nat_double,
100 ma questo, benche' non porti ad errore, non copre tutti i
101 casi per quelli mutuamente induttivi -->
103 <xsl:template mode="try_inductive" match="APPLY">
104 <xsl:variable name="id" select="@id"/>
106 <xsl:when test="CONST[1]">
107 <xsl:variable name="uri" select="CONST[1]/@uri"/>
109 <xsl:when test="contains($uri,'_ind.con')">
110 <xsl:variable name="ind_uri"
111 select="concat(substring-before($uri,'_ind.con'),'.ind')"/>
112 <xsl:variable name="inductive_def"
113 select="document(concat(string($absPath),$ind_uri))/InductiveDefinition"/>
114 <!-- check if the corresponding inductive definition actually
117 <xsl:when test="$inductive_def">
118 <xsl:variable name="ind_name">
119 <xsl:call-template name="get_name">
120 <xsl:with-param name="uri" select="$uri"/>
123 <xsl:variable name="no_params">
124 <xsl:call-template name="get_no_params">
125 <xsl:with-param name="first_uri" select="$CICURI"/>
126 <xsl:with-param name="second_uri" select="$uri"/>
129 <xsl:apply-templates mode="inductive" select=".">
130 <xsl:with-param name="inductive_def_uri"
132 <xsl:with-param name="inductive_def"
133 select="$inductive_def"/>
134 <xsl:with-param name="section_params" select="$no_params"/>
135 <xsl:with-param name="inductive_def_index" select="1"/>
136 <xsl:with-param name="inductive_def_name" select="$ind_name"/>
137 </xsl:apply-templates>
140 <xsl:apply-templates mode="letin" select="."/>
145 <xsl:apply-templates mode="letin" select="."/>
150 <xsl:apply-templates mode="letin" select="."/>
156 <xsl:template mode="proof_transform" match="*">
158 <xsl:when test="name()='APPLY'">
159 <xsl:variable name="id" select="@id"/>
161 <!-- NATIND 3 parametri -->
162 <xsl:when test="CONST[attribute::uri='cic:/Coq/Init/Datatypes/nat_ind.con'] and count(child::*) = 4">
164 <m:csymbol>nat_ind</m:csymbol>
165 <xsl:apply-templates mode="noannot" select="*[3]"/>
166 <xsl:apply-templates mode="noannot" select="*[4]"/>
169 <!-- NATIND 4 parametri (nuova versione) -->
171 <xsl:when test="CONST[
172 attribute::uri='cic:/Coq/Init/Datatypes/nat_ind.con']
173 and count(child::*) = 5
174 and name(*[4])='LAMBDA'
175 and name(*[4]/target/*[1])='LAMBDA'">
177 <m:csymbol>nat_ind_complete</m:csymbol>
178 <xsl:apply-templates mode="noannot" select="*[5]"/>
179 <xsl:apply-templates mode="noannot" select="*[3]"/>
180 <m:ci><xsl:value-of select="*[4]/target/@binder"/></m:ci>
181 <m:ci><xsl:value-of select="*[4]/target/*[1]/target/@binder"/></m:ci>
182 <xsl:apply-templates mode="noannot" select="*[4]/target/*[1]/source/*"/>
183 <xsl:apply-templates mode="noannot" select="*[4]/target/*[1]/target/*"/>
188 <xsl:when test="CONST[
189 attribute::uri='cic:/Coq/Init/Logic/Equality/eq_ind.con' or
190 attribute::uri='cic:/Coq/Init/Logic/Logic_lemmas/eq_ind_r.con' or
191 attribute::uri='cic:/Coq/Init/Logic_Type/eqT_ind.con' or
192 attribute::uri='cic:/Coq/Init/Logic_Type/eqT_ind_r.con' or
193 attribute::uri='cic:/Coq/Zarith/auxiliary/eqT_ind_r.con'] and count(child::*) = 7">
195 <m:csymbol>rw_step</m:csymbol>
196 <xsl:apply-templates mode="noannot" select="*[5]"/>
197 <xsl:apply-templates mode="pure" select="*[3]"/>
198 <xsl:apply-templates mode="pure" select="*[6]"/>
199 <xsl:apply-templates mode="proof_transform" select="*[7]"/>
202 <!-- EQUALITY with extra-parameters -->
203 <xsl:when test="CONST[
204 attribute::uri='cic:/Coq/Init/Logic/Equality/eq_ind.con' or
205 attribute::uri='cic:/Coq/Init/Logic/Logic_lemmas/eq_ind_r.con' or
206 attribute::uri='cic:/Coq/Init/Logic_Type/eqT_ind.con' or
207 attribute::uri='cic:/Coq/Init/Logic_Type/eqT_ind_r.con' or
208 attribute::uri='cic:/Coq/Zarith/auxiliary/eqT_ind_r.con'] and count(child::*) > 7">
209 <xsl:variable name="no_extraproofs" select="count(*[position()>7 and @sort='Prop' and (name(.)='LAMBDA' or name(.)='LETIN' or name(.)='APPLY' or name(.)='MUTCASE' or name(.)='FIX' or name(.)='COFIX')])"/>
211 <xsl:when test="$no_extraproofs=0">
213 <m:csymbol>rewrite_and_apply</m:csymbol>
215 <m:csymbol>rw_step</m:csymbol>
216 <xsl:apply-templates mode="noannot" select="*[5]"/>
217 <xsl:apply-templates mode="pure" select="*[3]"/>
218 <xsl:apply-templates mode="pure" select="*[6]"/>
219 <xsl:apply-templates mode="pure" select="*[7]"/>
221 <xsl:apply-templates mode="noannot" select="*[position()>7]"/>
226 <xsl:when test="*[5]/@sort='Prop'">
227 <m:apply helm:xref="{@id}">
228 <m:csymbol>letin</m:csymbol>
230 <m:csymbol>let</m:csymbol>
232 <xsl:call-template name="insert_subscript">
233 <xsl:with-param name="node_value" select="'h1'"/>
236 <xsl:apply-templates mode="noannot" select="*[5]"/>
238 <xsl:call-template name="gen_let">
239 <xsl:with-param name="init_pos" select="1"/>
240 <xsl:with-param name="from" select="7"/>
243 <m:csymbol>rewrite_and_apply</m:csymbol>
245 <m:csymbol>rw_step</m:csymbol>
247 <xsl:call-template name="insert_subscript">
248 <xsl:with-param name="node_value" select="'h1'"/>
251 <xsl:apply-templates mode="pure" select="*[3]"/>
252 <xsl:apply-templates mode="pure" select="*[6]"/>
253 <xsl:apply-templates mode="pure" select="*[7]"/>
255 <xsl:apply-templates mode="flat" select="*[8]">
256 <xsl:with-param name="n">
257 <xsl:value-of select="2"/>
259 </xsl:apply-templates>
264 <m:apply helm:xref="{@id}">
265 <m:csymbol>letin</m:csymbol>
266 <xsl:call-template name="gen_let">
267 <xsl:with-param name="init_pos" select="0"/>
268 <xsl:with-param name="form" select="7"/>
271 <m:csymbol>rewrite_and_apply</m:csymbol>
273 <m:csymbol>rw_step</m:csymbol>
274 <xsl:apply-templates mode="pure" select="*[5]"/>
275 <xsl:apply-templates mode="pure" select="*[3]"/>
276 <xsl:apply-templates mode="pure" select="*[6]"/>
277 <xsl:apply-templates mode="pure" select="*[7]"/>
279 <xsl:apply-templates mode="flat" select="*[8]">
280 <xsl:with-param name="n">
281 <xsl:value-of select="1"/>
283 </xsl:apply-templates>
292 <xsl:when test="CONST[
293 attribute::uri='cic:/Coq/Init/Logic/False_ind.con'] and
294 count(child::*) = 3">
295 <m:apply helm:xref="{@id}">
296 <m:csymbol>false_ind</m:csymbol>
297 <m:ci>cic:/Coq/Init/Logic/False_ind.con</m:ci>
298 <xsl:apply-templates mode="noannot" select="*[3]"/>
301 <!-- gestire meglio il caso di and_ind quando la prova
302 non e' della forma \x.\y.M -->
303 <xsl:when test="CONST[
304 attribute::uri='cic:/Coq/Init/Logic/Conjunction/and_ind.con']
305 and count(child::*) = 6
306 and name(*[5])='LAMBDA'
307 and name(*[5]/target/*[1])='LAMBDA'">
308 <m:apply helm:xref="{@id}">
309 <m:csymbol>and_ind</m:csymbol>
310 <xsl:apply-templates mode="noannot" select="*[6]"/>
311 <m:ci><xsl:call-template name="insert_subscript"><xsl:with-param name="node_value"><xsl:value-of select="*[5]/target/@binder"/></xsl:with-param></xsl:call-template></m:ci>
312 <xsl:apply-templates mode="pure" select="*[5]/source/*"/>
313 <m:ci><xsl:call-template name="insert_subscript"><xsl:with-param name="node_value"><xsl:value-of select="*[5]/target/LAMBDA/target/@binder"/></xsl:with-param></xsl:call-template></m:ci>
314 <xsl:apply-templates mode="pure" select="*[5]/target/LAMBDA/source/*"/>
315 <xsl:apply-templates mode="proof_transform" select="*[5]/target/LAMBDA/target/*"/>
318 <xsl:when test="CONST[
319 attribute::uri='cic:/Coq/Init/Logic/Disjunction/or_ind.con']
320 and count(child::*) = 7">
322 <xsl:when test="name(*[5])='LAMBDA'
323 and name(*[6])='LAMBDA'">
324 <xsl:variable name="definition_url"
325 select="'cic:/Coq/Init/Logic/Disjunction/or.ind'"/>
326 <m:apply helm:xref="{@id}">
327 <m:csymbol>full_or_ind</m:csymbol>
328 <xsl:apply-templates mode="noannot" select="*[7]"/>
329 <xsl:apply-templates mode="pure"
330 select="$InnerTypes/InnerTypes/TYPE[@of=$id]/*"/>
332 <m:csymbol>left_case</m:csymbol>
335 <xsl:value-of select="*[5]/target/@binder"/>
338 <xsl:apply-templates mode="pure" select="*[5]/source/*[1]"/>
341 <xsl:apply-templates mode="noannot" select="*[5]/target/*[1]"/>
344 <m:csymbol>right_case</m:csymbol>
347 <xsl:apply-templates mode="pure" select="*[6]/target/@binder"/>
350 <xsl:apply-templates mode="pure" select="*[6]/source/*[1]"/>
353 <xsl:apply-templates mode="noannot" select="*[6]/target/*[1]"/>
358 <m:apply helm:xref="{@id}">
359 <m:csymbol>or_ind</m:csymbol>
360 <xsl:apply-templates mode="noannot" select="*[7]"/>
361 <xsl:apply-templates mode="pure"
362 select="$InnerTypes/InnerTypes/TYPE[@of=$id]/*"/>
363 <xsl:apply-templates mode="pure" select="*[5]"/>
364 <xsl:apply-templates mode="pure" select="*[6]"/>
369 <!-- ex_ind, exT_ind -->
370 <xsl:when test="(CONST[attribute::uri='cic:/Coq/Init/Logic_Type/exT_ind.con'] or
371 CONST[attribute::uri='cic:/Coq/Init/Logic/First_order_quantifiers/ex_ind.con'])
372 and count(child::*) = 6
373 and name(*[5])='LAMBDA'
374 and name(*[5]/target/*[1])='LAMBDA'">
375 <m:apply helm:xref="{@id}">
376 <m:csymbol>ex_ind</m:csymbol>
377 <xsl:apply-templates mode="noannot" select="*[6]"/>
378 <m:ci><xsl:call-template name="insert_subscript"><xsl:with-param name="node_value"><xsl:value-of select="*[5]/target/@binder"/></xsl:with-param></xsl:call-template></m:ci>
379 <xsl:apply-templates mode="pure" select="*[5]/source/*"/>
380 <m:ci><xsl:call-template name="insert_subscript"><xsl:with-param name="node_value"><xsl:value-of select="*[5]/target/LAMBDA/target/@binder"/></xsl:with-param></xsl:call-template></m:ci>
381 <xsl:apply-templates mode="pure" select="*[5]/target/LAMBDA/source/*"/>
382 <xsl:apply-templates mode="proof_transform" select="*[5]/target/LAMBDA/target/*"/>
385 <xsl:when test="name(*[1])='CONST'">
386 <xsl:apply-templates mode="try_inductive" select="."/>
388 <!-- patch temporanea per la gestione di redex -->
389 <xsl:when test="name(*[1])='LAMBDA' and count(child::*)=2
390 and *[2]/@sort='Prop'">
391 <m:apply helm:xref="{@id}">
392 <m:csymbol>letin</m:csymbol>
394 <m:csymbol>let</m:csymbol>
396 <xsl:call-template name="insert_subscript">
397 <xsl:with-param name="node_value">
398 <xsl:value-of select="*[1]/target/@binder"/>
402 <xsl:apply-templates mode="noannot" select="*[2]"/>
404 <xsl:apply-templates mode="proof_transform" select="*[1]/target/*[1]"/>
408 <xsl:apply-templates select="." mode="letin"/>
413 <xsl:apply-templates select="." mode="pure"/>
419 <xsl:template match="APPLY" mode="letin">
420 <xsl:variable name="no_subproofs" select="count(*[@sort='Prop' and (name(.)='LAMBDA' or name(.)='LETIN' or name(.)='APPLY' or name(.)='MUTCASE' or name(.)='FIX' or name(.)='COFIX')])"/>
421 <!-- <m:cn><xsl:value-of select="$no_subproofs"/></m:cn> -->
423 <xsl:when test="$naturalLanguage='yes' and ($no_subproofs = 1)">
424 <m:apply helm:xref="{@id}">
425 <m:csymbol>letin1</m:csymbol>
426 <xsl:apply-templates mode="noannot" select="*[@sort='Prop' and (name(.)='LAMBDA' or name(.)='LETIN' or name(.)='APPLY' or name(.)='MUTCASE' or name(.)='FIX' or name(.)='COFIX')]"/>
427 <!-- now re-process the application -->
428 <m:apply helm:xref="{@id}">
429 <m:csymbol>app</m:csymbol>
430 <!-- mode previous looks for siblings:
431 call with the first child -->
432 <xsl:apply-templates mode="previous" select="*[1]"/>
436 <xsl:when test="$naturalLanguage='yes' and ($no_subproofs > 1)">
437 <m:apply helm:xref="{@id}">
438 <m:csymbol>letin</m:csymbol>
439 <!-- first process all subproofs (let-in) -->
440 <xsl:call-template name="gen_let"/>
441 <!-- now re-process the application -->
442 <m:apply helm:xref="{@id}">
443 <m:csymbol>app</m:csymbol>
444 <!-- mode flat looks for siblings: call with the first child -->
445 <xsl:apply-templates mode="flat" select="*[1]"/>
450 <xsl:apply-templates mode="pure" select="."/>
455 <xsl:template name="gen_let">
456 <xsl:param name="init_pos" select="0"/>
457 <xsl:param name="from" select="0"/>
458 <xsl:for-each select="*[position()>$from and @sort='Prop' and (name(.)='LAMBDA' or name(.)='LETIN' or name(.)='APPLY' or name(.)='MUTCASE' or name(.)='FIX' or name(.)='COFIX')]">
460 <m:csymbol>let</m:csymbol>
461 <m:ci><xsl:call-template name="insert_subscript"><xsl:with-param name="node_value"><xsl:value-of select="concat('h',position()+$init_pos)"/></xsl:with-param></xsl:call-template></m:ci>
462 <xsl:apply-templates mode="noannot" select="."/>
467 <xsl:template match="*" mode="previous">
469 <xsl:when test="$naturalLanguage='yes' and(@sort='Prop' and (name(.)='LAMBDA' or name(.)='LETIN' or name(.)='APPLY' or name(.)='MUTCASE' or name(.)='FIX' or name(.)='COFIX'))">
470 <m:ci>previous</m:ci>
473 <xsl:apply-templates select="." mode="pure"/>
476 <xsl:apply-templates mode="previous" select="following-sibling::*[1]"/>
479 <xsl:template match="*" mode="flat">
480 <xsl:param name="n" select="1"/>
481 <xsl:variable name="id" select="@id"/>
483 <!-- <xsl:when test="key('typeid',@id)"> -->
484 <!-- <xsl:when test="$InnerTypes/InnerTypes/TYPE[@of=$id]"> -->
485 <xsl:when test="$naturalLanguage='yes' and @sort='Prop' and (name(.)='LAMBDA' or name(.)='LETIN' or name(.)='APPLY' or name(.)='MUTCASE' or name(.)='FIX' or name(.)='COFIX')">
487 <xsl:call-template name="insert_subscript"><xsl:with-param name="node_value"><xsl:value-of select="concat('h',$n)"/></xsl:with-param></xsl:call-template>
489 <xsl:apply-templates mode="flat" select="following-sibling::*[1]">
490 <xsl:with-param name="n" select="$n+1"/>
491 </xsl:apply-templates>
494 <xsl:apply-templates mode="pure" select="."/>
495 <xsl:apply-templates mode="flat" select="following-sibling::*[1]">
496 <xsl:with-param name="n" select="$n"/>
497 </xsl:apply-templates>
502 <!-- Auxiliary functions -->
503 <xsl:template name="get_name">
504 <xsl:param name="uri" select="''"/>
505 <xsl:variable name="sub_after" select="substring-after($uri,'/')"/>
507 <xsl:when test="contains($sub_after,'/')">
508 <xsl:call-template name="get_name">
509 <xsl:with-param name="uri" select="$sub_after"/>
513 <xsl:value-of select="substring-before($sub_after,'_ind.con')"/>
518 <!-- <xsl:template match="APPLY[CONST[
519 attribute::uri='cic:/Coq/Init/Logic/Conjunction/and_ind.con']]" mode="appflat">
521 <xsl:when test="count(child::*) > 4">
522 <m:apply helm:xref="{@id}">
523 <m:csymbol>app</m:csymbol>
524 <xsl:apply-templates mode="pure" select="*[1]"/>
528 <xsl:apply-templates mode="flat" select="*[5]"/>
532 <m:apply helm:xref="{@id}">
533 <m:csymbol>app</m:csymbol>
534 <xsl:apply-templates mode="flat" select="*[1]"/>