]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/style/inductive.xsl
Branch V7_3_new_exportation merged.
[helm.git] / helm / style / inductive.xsl
index 83569d751660cf0008629f29c8986d149b2f0441..1d6dc4dd7b76a815876ad72a69cc90c8f92717ed 100644 (file)
@@ -26,6 +26,7 @@
 
 <!--******************************************************************--> 
 <!-- XSLT version 0.1 of CIC inductive objects to MathML content:     -->
+<!-- Completely revisited: November 2002, Andrea asperti              -->
 <!-- First draft: March 2001, Andrea asperti                          -->
 <!--******************************************************************-->
 
                               xmlns:m="http://www.w3.org/1998/Math/MathML"
                               xmlns:helm="http://www.cs.unibo.it/helm">
 
+<!-- try_inductive essentially checks if the head constant is an
+     invocation of an induction principle. 
+     Si presuppone che il tipo induttivo non sia mutuamente 
+     induttivo. Bisognerebbe andare a vedere l'utlimo parametro
+     del presunto "principio di induzione", tirare fuori il tipo induttivo
+     e vedere se il suo nome coincide con il prefisso di _ind. 
+     Ad esempio nat_double_ind e' definito dall'utente. L'ultimo
+     parametro di nat_double_ind e' di tipo nat, e nat e' diverso
+     da nat_double. Per ora, verifico solo l'esistenza di nat_double,
+     ma questo, benche' non porti ad errore, non copre tutti i
+     casi per quelli mutuamente induttivi -->
+
+
+<xsl:template mode="try_inductive" match="APPLY">
+ <xsl:variable name="id" select="@id"/>
+ <xsl:variable name="uri">
+  <xsl:choose>
+   <xsl:when test="name(*[1])='CONST'">
+    <xsl:value-of select="*[1]/@uri"/>
+   </xsl:when>
+   <xsl:otherwise>
+    <!-- instantiate -->
+    <xsl:value-of select="*[1]/CONST[1]/@uri"/>
+   </xsl:otherwise>
+  </xsl:choose>
+ </xsl:variable>
+ <xsl:choose>
+  <xsl:when test="contains($uri,'_ind.con')">
+   <xsl:variable name="ind_uri" 
+        select="concat(substring-before($uri,'_ind.con'),'.ind')"/>
+   <xsl:variable name="InductiveTypeUrl"><xsl:call-template name="URLofURI4getter"><xsl:with-param name="uri" select="$ind_uri"/></xsl:call-template></xsl:variable>
+   <xsl:variable name="inductive_def" 
+        select="document($InductiveTypeUrl)/InductiveDefinition"/>
+   <xsl:choose>
+    <xsl:when test="$inductive_def">
+     <xsl:variable name="ind_name">
+      <xsl:call-template name="get_name">
+       <xsl:with-param name="uri" select="$uri"/>
+      </xsl:call-template>
+     </xsl:variable>
+     <xsl:apply-templates mode="inductive" select=".">
+      <xsl:with-param name="uri" select="$uri"/>
+      <xsl:with-param name="inductive_def_uri" 
+       select="$ind_uri"/>
+      <xsl:with-param name="inductive_def" select="$inductive_def"/>
+      <xsl:with-param name="inductive_def_index" select="1"/>
+      <xsl:with-param name="inductive_def_name" select="$ind_name"/>
+     </xsl:apply-templates>
+    </xsl:when>
+    <xsl:otherwise>
+     <xsl:apply-templates select="." mode="letin"/>
+    </xsl:otherwise>
+   </xsl:choose>
+  </xsl:when>
+  <xsl:otherwise>
+   <xsl:apply-templates select="." mode="letin"/>
+  </xsl:otherwise>
+ </xsl:choose>
+</xsl:template>
+
 
 <xsl:template mode="inductive" match="APPLY">
+ <xsl:param name="uri" select="''"/> 
  <xsl:param name="inductive_def_uri" select="''"/>
  <xsl:param name="inductive_def" select="/.."/>
  <xsl:param name="inductive_def_index" select="1"/>
  <xsl:param name="inductive_def_name" select="''"/>
- <xsl:param name="section_params" select="0"/>
+ <xsl:variable name="InductiveTypeUrl"><xsl:call-template name="URLofURI4getter"><xsl:with-param name="uri" select="$uri"/></xsl:call-template></xsl:variable>
  <!-- expected_args_type contains the types of the arguments expected by
       the induction principle -->
- <xsl:variable name="InductiveTypeUrl"><xsl:call-template name="URLofURI4getter"><xsl:with-param name="uri" select="*[1]/@uri"/></xsl:call-template></xsl:variable>
  <xsl:variable name="expected_args_types" 
-       select="document($InductiveTypeUrl)/Definition/type//PROD[not(ancestor::source)]/source/*[1]"/>
+      select="document($InductiveTypeUrl)/ConstantType/PROD/decl/*[1]"/>
  <xsl:variable name="no_expected_args" select="count($expected_args_types)"/>
- <xsl:variable name="actual_arguments" select="*[position()>(1+$section_params)]"/>
+ <xsl:variable name="actual_arguments" select="*[position()>1]"/>
  <!-- First check that the induction principle is applied to the
       expected number of arguments -->
  <xsl:choose>
     <xsl:when test="string($argsOK) = 'true'">
      <!-- arguments are in the expected form: we create a
           "by_induction" content element -->
-     <!-- no_params is the number of paramters in square brackets -->
+     <!-- no_params is the number of parameters in square brackets -->
      <xsl:variable name="no_params" 
       select="$inductive_def/@noParams"/>
      <!-- the inductive property is the first argument following
            is the uri of the inductive definition -->
       <m:ci><xsl:value-of select="$inductive_def_uri"/></m:ci>
       <!-- next, we have the inductive property, currently not
-           used for rendering (it could be omitted??) -->
+           used for rendering (it could be omitted ??) -->
       <xsl:apply-templates mode="pure" select="$inductive_property"/>
       <!-- each case has its own "inductive_case" element -->
       <!-- the inductive case element is composed by:
          <m:csymbol>case_lhs</m:csymbol>
          <m:ci definitionURL="{$inductive_def_uri}">
           <xsl:value-of select="@name"/>
-         </m:ci>     
+         </m:ci> 
          <xsl:call-template name="get_constructor_args">
-          <xsl:with-param name="no_params" 
-               select="$no_params"/>
-          <xsl:with-param name="constructor_arity" 
-               select="*[1]"/>
-          <xsl:with-param name="actual_arg" 
-               select="$current_arg"/>
-          <xsl:with-param name="inductive_def_name" 
-               select="$inductive_def_name"/>
-          </xsl:call-template>
+          <xsl:with-param name="constructor_args" 
+               select="PROD/decl[position()> $no_params]"/>
+          <xsl:with-param name="actual_args" 
+               select="$current_arg/decl"/>
+          <xsl:with-param name="inductive_def_uri" 
+               select="$inductive_def_uri"/>
+          </xsl:call-template>  
         </m:apply>
         <m:apply>
          <m:csymbol>induction_hypothesis</m:csymbol>
          <xsl:call-template name="get_induction_hypothesis">
-          <xsl:with-param name="no_params" 
-               select="$no_params"/>
-          <xsl:with-param name="constructor_arity" 
-               select="*[1]"/>
-          <xsl:with-param name="actual_arg" 
-               select="$current_arg"/>
-          <xsl:with-param name="inductive_def_name" 
-               select="$inductive_def_name"/>
+          <xsl:with-param name="constructor_args" 
+               select="PROD/decl[position()> $no_params]"/>
+          <xsl:with-param name="actual_args" 
+               select="$current_arg/decl"/>
+          <xsl:with-param name="inductive_def_uri" 
+               select="$inductive_def_uri"/>
          </xsl:call-template>
         </m:apply>
-        <xsl:call-template name="get_body">
-         <xsl:with-param name="no_params" 
-               select="$no_params"/>
-         <xsl:with-param name="constructor_arity" 
-               select="*[1]"/>
-         <xsl:with-param name="actual_arg" select="$current_arg"/>
-         <xsl:with-param name="inductive_def_name" 
-               select="$inductive_def_name"/>
-        </xsl:call-template>
+        <xsl:choose>
+         <xsl:when test="count(PROD/decl) > $no_params">
+          <!-- in this case the actual_arg must be a LAMBDA -->
+          <xsl:call-template name="get_body">
+           <xsl:with-param name="constructor_args" 
+               select="PROD/decl[position()>$no_params]"/>
+           <xsl:with-param name="actual_args" select="$current_arg/decl"/>
+           <xsl:with-param name="inductive_def_uri" 
+               select="$inductive_def_uri"/>
+           <xsl:with-param name="target" 
+               select="$current_arg/target/*[1]"/>
+          </xsl:call-template>
+         </xsl:when>
+         <xsl:otherwise>
+          <xsl:apply-templates mode="noannot" select="$current_arg"/>
+         </xsl:otherwise>
+        </xsl:choose>
        </m:apply>
       </xsl:for-each>
       <!-- the inductive argument is the last argument of extra-args -->
      If this is not the case, not good rendering looks possible.
      Check_args returns a boolean. 
    -->
+
+
 <xsl:template name="check_args">
  <xsl:param name="arg_types" select="/.."/>
  <xsl:param name="actual_args" select="/.."/>
  <xsl:param name="bool_var" select="true()"/>
+ <!-- <xsl:value-of select="false()"/> -->
  <xsl:choose>
   <xsl:when test="count($arg_types) = 0">
     <xsl:value-of select="$bool_var"/>
   </xsl:when>
   <xsl:otherwise>
-   <xsl:variable name="no_expected_arg_of_arg">
-    <xsl:apply-templates mode="count_arity" select="$arg_types[1]">
-     <xsl:with-param name="what" select="'PROD'"/>
-    </xsl:apply-templates>
-   </xsl:variable>
-   <xsl:variable name="no_actual_abst_of_arg"> 
-    <xsl:apply-templates mode="count_arity" select="$actual_args[1]">
-     <xsl:with-param name="what" select="'LAMBDA'"/>
-    </xsl:apply-templates>
-   </xsl:variable>
-   <!-- REPLACE WITH EQUALITY ???? -->
+   <xsl:variable name="no_expected_arg_of_arg" 
+                 select="count($arg_types[1]/decl)"/>
+   <xsl:variable name="no_actual_abst_of_arg" 
+                 select="count($actual_args[1]/decl)"/> 
    <xsl:variable name="test_arg" 
-    select="$no_actual_abst_of_arg >= $no_expected_arg_of_arg"/> 
+    select="($no_actual_abst_of_arg >= $no_expected_arg_of_arg)"/> 
    <xsl:call-template name="check_args">
     <xsl:with-param name="arg_types" select="$arg_types[position()>1]"/>
     <xsl:with-param name="actual_args" select="$actual_args[position()>1]"/>
    </xsl:call-template> 
   </xsl:otherwise>
  </xsl:choose>
-</xsl:template>
+</xsl:template> 
 
-<!-- count_arity counts the number of head lambda (or prod) -->
-<xsl:template mode="count_arity" match="*">
- <xsl:param name="what" select="'LAMBDA'"/>
- <xsl:param name="num" select="0"/>
- <!-- MANCANO I CAST ??? -->
- <xsl:choose>
-  <xsl:when test="name(.) = $what">
-   <xsl:apply-templates mode="count_arity" select="target/*[1]">
-    <xsl:with-param name="what" select="$what"/>
-    <xsl:with-param name="num" select="$num+1"/>
-   </xsl:apply-templates>
-  </xsl:when>
-  <xsl:otherwise>
-   <xsl:value-of select="$num"/>
-  </xsl:otherwise>
- </xsl:choose>
-</xsl:template>
 
 <!-- The following three functions are essentially identical
      in their recursive structure.
      single one without a conversion from document tree fragments
      to node-sets. 
 -->
+
 <xsl:template name="get_constructor_args">
- <xsl:param name="no_params" select="0"/>
- <xsl:param name="constructor_arity" select="/.."/>
- <xsl:param name="actual_arg" select="/.."/>
- <xsl:param name="inductive_def_name" select="''"/>
- <xsl:choose>
- <xsl:when test="$no_params = 0">
- <xsl:if test="name($constructor_arity)='PROD'">
+ <xsl:param name="constructor_args" select="/.."/>
+ <xsl:param name="actual_args" select="/.."/>
+ <xsl:param name="inductive_def_uri" select="''"/>
+ <xsl:if test="$constructor_args">
   <m:bvar>
-   <m:ci><xsl:value-of select="$actual_arg/target/@binder"/></m:ci>
+   <m:ci><xsl:value-of select="$actual_args[1]/@binder"/></m:ci>
    <m:type>
-    <xsl:apply-templates mode="pure" select="$actual_arg/source/*[1]"/>
+    <xsl:apply-templates mode="pure" select="$actual_args[1]/*"/>
    </m:type> 
   </m:bvar>
   <xsl:choose>
-   <xsl:when test="$constructor_arity/source//REL[@binder=$inductive_def_name]">
+   <xsl:when test="$constructor_args[1]//MUTIND[@uri=$inductive_def_uri]">
     <xsl:call-template name="get_constructor_args">
     <xsl:with-param name="constructor_arity" 
-        select="$constructor_arity/target/*[1]"/>
-    <xsl:with-param name="actual_arg" 
-        select="$actual_arg/target/LAMBDA/target/*[1]"/>
-    <xsl:with-param name="inductive_def_name
-               select="$inductive_def_name"/>
+        select="$constructor_args[position()>1]"/>
+    <xsl:with-param name="actual_args
+        select="$actual_args[position()>2]"/>
+    <xsl:with-param name="inductive_def_uri
+               select="$inductive_def_uri"/>
     </xsl:call-template>
    </xsl:when>
    <xsl:otherwise>
     <xsl:call-template name="get_constructor_args">
-    <xsl:with-param name="constructor_arity
-        select="$constructor_arity/target/*[1]"/>
-    <xsl:with-param name="actual_arg" 
-        select="$actual_arg/target/*[1]"/>
-    <xsl:with-param name="inductive_def_name
-               select="$inductive_def_name"/>
+    <xsl:with-param name="constructor_args
+        select="$constructor_args[position()>1]"/>
+    <xsl:with-param name="actual_args
+        select="$actual_args[position()>1]"/>
+    <xsl:with-param name="inductive_def_uri
+               select="$inductive_def_uri"/>
     </xsl:call-template>
    </xsl:otherwise>
   </xsl:choose>
  </xsl:if>
- </xsl:when>
- <xsl:otherwise>
-  <xsl:call-template name="get_constructor_args">
-    <xsl:with-param name="no_params" select="$no_params - 1"/>
-    <xsl:with-param name="constructor_arity" 
-        select="$constructor_arity/target/*[1]"/>
-    <xsl:with-param name="actual_arg" 
-        select="$actual_arg"/>
-    <xsl:with-param name="inductive_def_name" 
-               select="$inductive_def_name"/>
-    </xsl:call-template>
- </xsl:otherwise>
- </xsl:choose>
-</xsl:template>
+</xsl:template> 
 
 <xsl:template name="get_induction_hypothesis">
- <xsl:param name="no_params" select="0"/>
- <xsl:param name="constructor_arity" select="/.."/>
- <xsl:param name="actual_arg" select="/.."/>
- <xsl:param name="inductive_def_name" select="''"/>
- <xsl:choose>
- <xsl:when test="$no_params = 0">
- <xsl:if test="name($constructor_arity)='PROD'">
+ <xsl:param name="constructor_args" select="/.."/>
+ <xsl:param name="actual_args" select="/.."/>
+ <xsl:param name="inductive_def_uri" select="''"/>
+ <xsl:if test="$constructor_args">
   <xsl:choose>
-   <xsl:when test="$constructor_arity/source//REL[@binder=$inductive_def_name]">
+   <xsl:when test="$constructor_args[1]//MUTIND[@uri=$inductive_def_uri]">
     <m:bvar>
      <m:ci>
-      <xsl:value-of select="$actual_arg/target/LAMBDA/target/@binder"/>
+      <xsl:value-of select="$actual_args[2]/@binder"/>
      </m:ci>
      <m:type>
       <xsl:apply-templates mode="pure" 
-           select="$actual_arg/target/LAMBDA/source"/>
+           select="$actual_args[2]/*"/>
      </m:type>
     </m:bvar>
     <xsl:call-template name="get_induction_hypothesis">
-    <xsl:with-param name="constructor_arity
-        select="$constructor_arity/target/*[1]"/>
-    <xsl:with-param name="actual_arg" 
-        select="$actual_arg/target/LAMBDA/target/*[1]"/>
-    <xsl:with-param name="inductive_def_name
-               select="$inductive_def_name"/>
+    <xsl:with-param name="constructor_args
+        select="$constructor_args[position()>1]"/>
+    <xsl:with-param name="actual_args
+        select="$actual_args[position()>2]"/>
+    <xsl:with-param name="inductive_def_uri
+               select="$inductive_def_uri"/>
     </xsl:call-template>
    </xsl:when>
    <xsl:otherwise>
     <xsl:call-template name="get_induction_hypothesis">
-    <xsl:with-param name="constructor_arity
-        select="$constructor_arity/target/*[1]"/>
-    <xsl:with-param name="actual_arg" 
-        select="$actual_arg/target/*[1]"/>
-    <xsl:with-param name="inductive_def_name
-               select="$inductive_def_name"/>
+    <xsl:with-param name="constructor_args
+        select="$constructor_args[position()>1]"/>
+    <xsl:with-param name="actual_args
+        select="$actual_args[position()>1]"/>
+    <xsl:with-param name="inductive_def_uri
+               select="$inductive_def_uri"/> 
     </xsl:call-template>
    </xsl:otherwise>
   </xsl:choose>
  </xsl:if>
- </xsl:when>
- <xsl:otherwise>
-  <xsl:call-template name="get_induction_hypothesis">
-    <xsl:with-param name="no_params" select="$no_params - 1"/>
-    <xsl:with-param name="constructor_arity" 
-        select="$constructor_arity/target/*[1]"/>
-    <xsl:with-param name="actual_arg" 
-        select="$actual_arg"/>
-    <xsl:with-param name="inductive_def_name" 
-               select="$inductive_def_name"/>
-    </xsl:call-template>
- </xsl:otherwise>
- </xsl:choose>
 </xsl:template>
 
 <xsl:template name="get_body">
- <xsl:param name="no_params" select="0"/>
- <xsl:param name="constructor_arity" select="/.."/>
- <xsl:param name="actual_arg" select="/.."/>
- <xsl:param name="inductive_def_name" select="''"/>
- <xsl:choose>
- <xsl:when test="$no_params = 0">
+ <xsl:param name="constructor_args" select="/.."/>
+ <xsl:param name="actual_args" select="/.."/>
+ <xsl:param name="inductive_def_uri" select="''"/>
+ <xsl:param name="target" select="/.."/>
  <xsl:choose>
- <xsl:when test="name($constructor_arity)='PROD'">
-  <xsl:choose>
-   <xsl:when test="$constructor_arity/source//REL[@binder=$inductive_def_name]">
-    <xsl:call-template name="get_body">
-    <xsl:with-param name="constructor_arity" 
-        select="$constructor_arity/target/*[1]"/>
-    <xsl:with-param name="actual_arg" 
-        select="$actual_arg/target/LAMBDA/target/*[1]"/>
-    <xsl:with-param name="inductive_def_name" 
-               select="$inductive_def_name"/>
-    </xsl:call-template>
-   </xsl:when>
-   <xsl:otherwise>
-    <xsl:call-template name="get_body">
-    <xsl:with-param name="constructor_arity" 
-        select="$constructor_arity/target/*[1]"/>
-    <xsl:with-param name="actual_arg" 
-        select="$actual_arg/target/*[1]"/>
-    <xsl:with-param name="inductive_def_name" 
-               select="$inductive_def_name"/>
-    </xsl:call-template>
-   </xsl:otherwise>
-  </xsl:choose>
- </xsl:when>
- <xsl:otherwise>
-  <xsl:apply-templates mode="noannot" select="$actual_arg"/>
- </xsl:otherwise> 
- </xsl:choose>
- </xsl:when>
- <xsl:otherwise>
-  <xsl:call-template name="get_body">
-    <xsl:with-param name="no_params" select="$no_params - 1"/>
-    <xsl:with-param name="constructor_arity" 
-        select="$constructor_arity/target/*[1]"/>
-    <xsl:with-param name="actual_arg" 
-        select="$actual_arg"/>
-    <xsl:with-param name="inductive_def_name" 
-               select="$inductive_def_name"/>
-    </xsl:call-template>
- </xsl:otherwise>
+  <xsl:when test="$constructor_args">
+   <xsl:choose>
+    <xsl:when test="$constructor_args[1]//MUTIND[@uri=$inductive_def_uri]">
+     <xsl:call-template name="get_body">
+      <xsl:with-param name="constructor_args" 
+        select="$constructor_args[position()> 1]"/>
+      <xsl:with-param name="actual_args" 
+        select="$actual_args[position()> 2]"/>
+      <xsl:with-param name="inductive_def_uri" 
+               select="$inductive_def_uri"/>
+      <xsl:with-param name="target" 
+               select="$target"/>
+     </xsl:call-template>
+    </xsl:when>
+    <xsl:otherwise>
+     <xsl:call-template name="get_body">
+      <xsl:with-param name="constructor_args" 
+        select="$constructor_args[position()> 1]"/>
+      <xsl:with-param name="actual_args" 
+        select="$actual_args[position()> 1]"/>
+      <xsl:with-param name="inductive_def_uri" 
+               select="$inductive_def_uri"/>
+      <xsl:with-param name="target" 
+               select="$target"/>
+     </xsl:call-template>
+    </xsl:otherwise>
+   </xsl:choose>
+  </xsl:when>
+  <xsl:otherwise>
+   <xsl:choose>
+    <xsl:when test="$actual_args">
+      <xsl:apply-templates select="$actual_args[1]" mode="lambda_prop"/>
+    </xsl:when>
+    <xsl:otherwise>
+     <xsl:apply-templates mode="noannot" select="$target"/>
+    </xsl:otherwise>
+   </xsl:choose>
+  </xsl:otherwise> 
  </xsl:choose>
-</xsl:template>
+</xsl:template> 
 
 </xsl:stylesheet>