doc-src/IsarAdvanced/Codegen/Thy/document/Codegen.tex
changeset 22060 8a37090726e8
parent 21994 dfa5133dbe73
child 22188 a63889770d57
equal deleted inserted replaced
22059:f72cdc0a0af4 22060:8a37090726e8
   119   \end{figure}
   119   \end{figure}
   120 
   120 
   121   The code generator employs a notion of executability
   121   The code generator employs a notion of executability
   122   for three foundational executable ingredients known
   122   for three foundational executable ingredients known
   123   from functional programming:
   123   from functional programming:
   124   \emph{function equations}, \emph{datatypes}, and
   124   \emph{defining equations}, \emph{datatypes}, and
   125   \emph{type classes}. A function equation as a first approximation
   125   \emph{type classes}. A defining equation as a first approximation
   126   is a theorem of the form \isa{f\ t\isactrlisub {\isadigit{1}}\ t\isactrlisub {\isadigit{2}}\ {\isasymdots}\ t\isactrlisub n\ {\isasymequiv}\ t}
   126   is a theorem of the form \isa{f\ t\isactrlisub {\isadigit{1}}\ t\isactrlisub {\isadigit{2}}\ {\isasymdots}\ t\isactrlisub n\ {\isasymequiv}\ t}
   127   (an equation headed by a constant \isa{f} with arguments
   127   (an equation headed by a constant \isa{f} with arguments
   128   \isa{t\isactrlisub {\isadigit{1}}\ t\isactrlisub {\isadigit{2}}\ {\isasymdots}\ t\isactrlisub n} and right hand side \isa{t}.
   128   \isa{t\isactrlisub {\isadigit{1}}\ t\isactrlisub {\isadigit{2}}\ {\isasymdots}\ t\isactrlisub n} and right hand side \isa{t}.
   129   Code generation aims to turn function equations
   129   Code generation aims to turn defining equations
   130   into a functional program by running through
   130   into a functional program by running through
   131   a process (see figure \ref{fig:process}):
   131   a process (see figure \ref{fig:process}):
   132 
   132 
   133   \begin{itemize}
   133   \begin{itemize}
   134 
   134 
   135     \item Out of the vast collection of theorems proven in a
   135     \item Out of the vast collection of theorems proven in a
   136       \qn{theory}, a reasonable subset modeling
   136       \qn{theory}, a reasonable subset modeling
   137       function equations is \qn{selected}.
   137       defining equations is \qn{selected}.
   138 
   138 
   139     \item On those selected theorems, certain
   139     \item On those selected theorems, certain
   140       transformations are carried out
   140       transformations are carried out
   141       (\qn{preprocessing}).  Their purpose is to turn theorems
   141       (\qn{preprocessing}).  Their purpose is to turn theorems
   142       representing non- or badly executable
   142       representing non- or badly executable
   192   in parentheses. These start with a \qn{target language}
   192   in parentheses. These start with a \qn{target language}
   193   identifier, followed by arguments, their semantics
   193   identifier, followed by arguments, their semantics
   194   depending on the target. In the SML case, a filename
   194   depending on the target. In the SML case, a filename
   195   is given where to write the generated code to.
   195   is given where to write the generated code to.
   196 
   196 
   197   Internally, the function equations for all selected
   197   Internally, the defining equations for all selected
   198   constants are taken, including any transitively required
   198   constants are taken, including any transitively required
   199   constants, datatypes and classes, resulting in the following
   199   constants, datatypes and classes, resulting in the following
   200   code:
   200   code:
   201 
   201 
   202   \lstsml{Thy/examples/fac.ML}
   202   \lstsml{Thy/examples/fac.ML}
   244 \isacommand{code{\isacharunderscore}gen}\isamarkupfalse%
   244 \isacommand{code{\isacharunderscore}gen}\isamarkupfalse%
   245 \ bar\ {\isacharparenleft}SML\ {\isachardoublequoteopen}examples{\isacharslash}fail{\isacharunderscore}type{\isachardot}ML{\isachardoublequoteclose}{\isacharparenright}%
   245 \ bar\ {\isacharparenleft}SML\ {\isachardoublequoteopen}examples{\isacharslash}fail{\isacharunderscore}type{\isachardot}ML{\isachardoublequoteclose}{\isacharparenright}%
   246 \begin{isamarkuptext}%
   246 \begin{isamarkuptext}%
   247 \noindent will result in an error. Likewise, generating code
   247 \noindent will result in an error. Likewise, generating code
   248   for constants not yielding
   248   for constants not yielding
   249   a function equation will fail, e.g.~the Hilbert choice
   249   a defining equation will fail, e.g.~the Hilbert choice
   250   operation \isa{SOME}:%
   250   operation \isa{SOME}:%
   251 \end{isamarkuptext}%
   251 \end{isamarkuptext}%
   252 \isamarkuptrue%
   252 \isamarkuptrue%
   253 %
   253 %
   254 \isadelimML
   254 \isadelimML
   287 \isamarkupsubsection{Theorem selection%
   287 \isamarkupsubsection{Theorem selection%
   288 }
   288 }
   289 \isamarkuptrue%
   289 \isamarkuptrue%
   290 %
   290 %
   291 \begin{isamarkuptext}%
   291 \begin{isamarkuptext}%
   292 The list of all function equations in a theory may be inspected
   292 The list of all defining equations in a theory may be inspected
   293   using the \isa{{\isasymPRINTCODETHMS}} command:%
   293   using the \isa{{\isasymPRINTCODETHMS}} command:%
   294 \end{isamarkuptext}%
   294 \end{isamarkuptext}%
   295 \isamarkuptrue%
   295 \isamarkuptrue%
   296 \isacommand{print{\isacharunderscore}codethms}\isamarkupfalse%
   296 \isacommand{print{\isacharunderscore}codethms}\isamarkupfalse%
   297 %
   297 %
   298 \begin{isamarkuptext}%
   298 \begin{isamarkuptext}%
   299 \noindent which displays a table of constant with corresponding
   299 \noindent which displays a table of constant with corresponding
   300   function equations (the additional stuff displayed
   300   defining equations (the additional stuff displayed
   301   shall not bother us for the moment). If this table does
   301   shall not bother us for the moment). If this table does
   302   not provide at least one function
   302   not provide at least one function
   303   equation, the table of primitive definitions is searched
   303   equation, the table of primitive definitions is searched
   304   whether it provides one.
   304   whether it provides one.
   305 
   305 
   306   The typical HOL tools are already set up in a way that
   306   The typical HOL tools are already set up in a way that
   307   function definitions introduced by \isa{{\isasymFUN}},
   307   function definitions introduced by \isa{{\isasymFUN}},
   308   \isa{{\isasymFUNCTION}}, \isa{{\isasymPRIMREC}}
   308   \isa{{\isasymFUNCTION}}, \isa{{\isasymPRIMREC}}
   309   \isa{{\isasymRECDEF}} are implicitly propagated
   309   \isa{{\isasymRECDEF}} are implicitly propagated
   310   to this function equation table. Specific theorems may be
   310   to this defining equation table. Specific theorems may be
   311   selected using an attribute: \emph{code func}. As example,
   311   selected using an attribute: \emph{code func}. As example,
   312   a weight selector function:%
   312   a weight selector function:%
   313 \end{isamarkuptext}%
   313 \end{isamarkuptext}%
   314 \isamarkuptrue%
   314 \isamarkuptrue%
   315 \isacommand{consts}\isamarkupfalse%
   315 \isacommand{consts}\isamarkupfalse%
   345 \endisadelimproof
   345 \endisadelimproof
   346 \isanewline
   346 \isanewline
   347 \isacommand{code{\isacharunderscore}gen}\isamarkupfalse%
   347 \isacommand{code{\isacharunderscore}gen}\isamarkupfalse%
   348 \ pick\ {\isacharparenleft}SML\ {\isachardoublequoteopen}examples{\isacharslash}pick{\isadigit{1}}{\isachardot}ML{\isachardoublequoteclose}{\isacharparenright}%
   348 \ pick\ {\isacharparenleft}SML\ {\isachardoublequoteopen}examples{\isacharslash}pick{\isadigit{1}}{\isachardot}ML{\isachardoublequoteclose}{\isacharparenright}%
   349 \begin{isamarkuptext}%
   349 \begin{isamarkuptext}%
   350 This theorem is now added to the function equation table:
   350 This theorem is now added to the defining equation table:
   351 
   351 
   352   \lstsml{Thy/examples/pick1.ML}
   352   \lstsml{Thy/examples/pick1.ML}
   353 
   353 
   354   It might be convenient to remove the pointless original
   354   It might be convenient to remove the pointless original
   355   equation, using the \emph{nofunc} attribute:%
   355   equation, using the \emph{nofunc} attribute:%
   363 \begin{isamarkuptext}%
   363 \begin{isamarkuptext}%
   364 \lstsml{Thy/examples/pick2.ML}
   364 \lstsml{Thy/examples/pick2.ML}
   365 
   365 
   366   Syntactic redundancies are implicitly dropped. For example,
   366   Syntactic redundancies are implicitly dropped. For example,
   367   using a modified version of the \isa{fac} function
   367   using a modified version of the \isa{fac} function
   368   as function equation, the then redundant (since
   368   as defining equation, the then redundant (since
   369   syntactically subsumed) original function equations
   369   syntactically subsumed) original defining equations
   370   are dropped, resulting in a warning:%
   370   are dropped, resulting in a warning:%
   371 \end{isamarkuptext}%
   371 \end{isamarkuptext}%
   372 \isamarkuptrue%
   372 \isamarkuptrue%
   373 \isacommand{lemma}\isamarkupfalse%
   373 \isacommand{lemma}\isamarkupfalse%
   374 \ {\isacharbrackleft}code\ func{\isacharbrackright}{\isacharcolon}\isanewline
   374 \ {\isacharbrackleft}code\ func{\isacharbrackright}{\isacharcolon}\isanewline
   530 \end{isamarkuptext}%
   530 \end{isamarkuptext}%
   531 \isamarkuptrue%
   531 \isamarkuptrue%
   532 \isacommand{print{\isacharunderscore}codethms}\isamarkupfalse%
   532 \isacommand{print{\isacharunderscore}codethms}\isamarkupfalse%
   533 \ {\isacharparenleft}{\isacharparenright}%
   533 \ {\isacharparenleft}{\isacharparenright}%
   534 \begin{isamarkuptext}%
   534 \begin{isamarkuptext}%
   535 \noindent print all cached function equations (i.e.~\emph{after}
   535 \noindent print all cached defining equations (i.e.~\emph{after}
   536   any applied transformation). Inside the brackets a
   536   any applied transformation). Inside the brackets a
   537   list of constants may be given; their function
   537   list of constants may be given; their function
   538   equations are added to the cache if not already present.%
   538   equations are added to the cache if not already present.%
   539 \end{isamarkuptext}%
   539 \end{isamarkuptext}%
   540 \isamarkuptrue%
   540 \isamarkuptrue%
   601   out: \emph{preprocessing}. There are three possibilities
   601   out: \emph{preprocessing}. There are three possibilities
   602   to customize preprocessing: \emph{inline theorems},
   602   to customize preprocessing: \emph{inline theorems},
   603   \emph{inline procedures} and \emph{generic preprocessors}.
   603   \emph{inline procedures} and \emph{generic preprocessors}.
   604 
   604 
   605   \emph{Inline theorems} are rewriting rules applied to each
   605   \emph{Inline theorems} are rewriting rules applied to each
   606   function equation.  Due to the interpretation of theorems
   606   defining equation.  Due to the interpretation of theorems
   607   of function equations, rewrites are applied to the right
   607   of defining equations, rewrites are applied to the right
   608   hand side and the arguments of the left hand side of an
   608   hand side and the arguments of the left hand side of an
   609   equation, but never to the constant heading the left hand side.
   609   equation, but never to the constant heading the left hand side.
   610   Inline theorems may be declared an undeclared using the
   610   Inline theorems may be declared an undeclared using the
   611   \emph{code inline} or \emph{code noinline} attribute respectively.
   611   \emph{code inline} or \emph{code noinline} attribute respectively.
   612 
   612 
  1353 \isanewline
  1353 \isanewline
  1354 \ \ dummy{\isacharunderscore}set\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequoteopen}{\isacharparenleft}nat\ {\isasymRightarrow}\ nat{\isacharparenright}\ set{\isachardoublequoteclose}\ \isakeyword{where}\isanewline
  1354 \ \ dummy{\isacharunderscore}set\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequoteopen}{\isacharparenleft}nat\ {\isasymRightarrow}\ nat{\isacharparenright}\ set{\isachardoublequoteclose}\ \isakeyword{where}\isanewline
  1355 \ \ {\isachardoublequoteopen}dummy{\isacharunderscore}set\ {\isacharequal}\ {\isacharbraceleft}Suc{\isacharbraceright}{\isachardoublequoteclose}%
  1355 \ \ {\isachardoublequoteopen}dummy{\isacharunderscore}set\ {\isacharequal}\ {\isacharbraceleft}Suc{\isacharbraceright}{\isachardoublequoteclose}%
  1356 \begin{isamarkuptext}%
  1356 \begin{isamarkuptext}%
  1357 Then code generation for \isa{dummy{\isacharunderscore}set} will fail.
  1357 Then code generation for \isa{dummy{\isacharunderscore}set} will fail.
  1358   Why? A glimpse at the function equations will offer:%
  1358   Why? A glimpse at the defining equations will offer:%
  1359 \end{isamarkuptext}%
  1359 \end{isamarkuptext}%
  1360 \isamarkuptrue%
  1360 \isamarkuptrue%
  1361 \isacommand{print{\isacharunderscore}codethms}\isamarkupfalse%
  1361 \isacommand{print{\isacharunderscore}codethms}\isamarkupfalse%
  1362 \ {\isacharparenleft}insert{\isacharparenright}%
  1362 \ {\isacharparenleft}insert{\isacharparenright}%
  1363 \begin{isamarkuptext}%
  1363 \begin{isamarkuptext}%
  1364 This reveals the function equation \isa{insert\ {\isacharquery}a\ {\isacharquery}B\ {\isasymequiv}\ {\isacharbraceleft}x{\isachardot}\ x\ {\isacharequal}\ {\isacharquery}a{\isacharbraceright}\ {\isasymunion}\ {\isacharquery}B}
  1364 This reveals the defining equation \isa{insert\ {\isacharquery}a\ {\isacharquery}B\ {\isasymequiv}\ {\isacharbraceleft}x{\isachardot}\ x\ {\isacharequal}\ {\isacharquery}a{\isacharbraceright}\ {\isasymunion}\ {\isacharquery}B}
  1365   for \isa{insert}, which is operationally meaningless
  1365   for \isa{insert}, which is operationally meaningless
  1366   but forces an equality constraint on the set members
  1366   but forces an equality constraint on the set members
  1367   (which is not satisfiable if the set members are functions).
  1367   (which is not satisfiable if the set members are functions).
  1368   Even when using set of natural numbers (which are an instance
  1368   Even when using set of natural numbers (which are an instance
  1369   of \emph{eq}), we run into a problem:%
  1369   of \emph{eq}), we run into a problem:%
  1402 \isacommand{code{\isacharunderscore}gen}\isamarkupfalse%
  1402 \isacommand{code{\isacharunderscore}gen}\isamarkupfalse%
  1403 \ dummy{\isacharunderscore}set\ foobar{\isacharunderscore}set\ {\isacharparenleft}SML\ {\isachardoublequoteopen}examples{\isacharslash}dirty{\isacharunderscore}set{\isachardot}ML{\isachardoublequoteclose}{\isacharparenright}%
  1403 \ dummy{\isacharunderscore}set\ foobar{\isacharunderscore}set\ {\isacharparenleft}SML\ {\isachardoublequoteopen}examples{\isacharslash}dirty{\isacharunderscore}set{\isachardot}ML{\isachardoublequoteclose}{\isacharparenright}%
  1404 \begin{isamarkuptext}%
  1404 \begin{isamarkuptext}%
  1405 \lstsml{Thy/examples/dirty_set.ML}
  1405 \lstsml{Thy/examples/dirty_set.ML}
  1406 
  1406 
  1407   Reflexive function equations by convention are dropped.
  1407   Reflexive defining equations by convention are dropped.
  1408   But their presence prevents primitive definitions to be
  1408   But their presence prevents primitive definitions to be
  1409   used as function equations:%
  1409   used as defining equations:%
  1410 \end{isamarkuptext}%
  1410 \end{isamarkuptext}%
  1411 \isamarkuptrue%
  1411 \isamarkuptrue%
  1412 \isacommand{print{\isacharunderscore}codethms}\isamarkupfalse%
  1412 \isacommand{print{\isacharunderscore}codethms}\isamarkupfalse%
  1413 \ {\isacharparenleft}insert{\isacharparenright}%
  1413 \ {\isacharparenleft}insert{\isacharparenright}%
  1414 \begin{isamarkuptext}%
  1414 \begin{isamarkuptext}%
  1415 will show \emph{no} function equations for insert.
  1415 will show \emph{no} defining equations for insert.
  1416 
  1416 
  1417   Note that the sort constraints of reflexive equations
  1417   Note that the sort constraints of reflexive equations
  1418   are considered; so%
  1418   are considered; so%
  1419 \end{isamarkuptext}%
  1419 \end{isamarkuptext}%
  1420 \isamarkuptrue%
  1420 \isamarkuptrue%
  1515 \isanewline
  1515 \isanewline
  1516 \ \ arbitrary{\isacharunderscore}option\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequoteopen}{\isacharprime}a\ option{\isachardoublequoteclose}\ \isakeyword{where}\isanewline
  1516 \ \ arbitrary{\isacharunderscore}option\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequoteopen}{\isacharprime}a\ option{\isachardoublequoteclose}\ \isakeyword{where}\isanewline
  1517 \ \ {\isacharbrackleft}symmetric{\isacharcomma}\ code\ inline{\isacharbrackright}{\isacharcolon}\ {\isachardoublequoteopen}arbitrary{\isacharunderscore}option\ {\isacharequal}\ arbitrary{\isachardoublequoteclose}%
  1517 \ \ {\isacharbrackleft}symmetric{\isacharcomma}\ code\ inline{\isacharbrackright}{\isacharcolon}\ {\isachardoublequoteopen}arbitrary{\isacharunderscore}option\ {\isacharequal}\ arbitrary{\isachardoublequoteclose}%
  1518 \begin{isamarkuptext}%
  1518 \begin{isamarkuptext}%
  1519 By that, we replace any \isa{arbitrary} with option type
  1519 By that, we replace any \isa{arbitrary} with option type
  1520   by \isa{arbitrary{\isacharunderscore}option} in function equations.
  1520   by \isa{arbitrary{\isacharunderscore}option} in defining equations.
  1521 
  1521 
  1522   For technical reasons, we further have to provide a
  1522   For technical reasons, we further have to provide a
  1523   synonym for \isa{None} which in code generator view
  1523   synonym for \isa{None} which in code generator view
  1524   is a function rather than a datatype constructor:%
  1524   is a function rather than a datatype constructor:%
  1525 \end{isamarkuptext}%
  1525 \end{isamarkuptext}%
  1672   \indexml{CodegenData.add-func}\verb|CodegenData.add_func: thm -> theory -> theory| \\
  1672   \indexml{CodegenData.add-func}\verb|CodegenData.add_func: thm -> theory -> theory| \\
  1673   \indexml{CodegenData.del-func}\verb|CodegenData.del_func: thm -> theory -> theory| \\
  1673   \indexml{CodegenData.del-func}\verb|CodegenData.del_func: thm -> theory -> theory| \\
  1674   \indexml{CodegenData.add-funcl}\verb|CodegenData.add_funcl: CodegenConsts.const * thm list Susp.T -> theory -> theory| \\
  1674   \indexml{CodegenData.add-funcl}\verb|CodegenData.add_funcl: CodegenConsts.const * thm list Susp.T -> theory -> theory| \\
  1675   \indexml{CodegenData.add-inline}\verb|CodegenData.add_inline: thm -> theory -> theory| \\
  1675   \indexml{CodegenData.add-inline}\verb|CodegenData.add_inline: thm -> theory -> theory| \\
  1676   \indexml{CodegenData.del-inline}\verb|CodegenData.del_inline: thm -> theory -> theory| \\
  1676   \indexml{CodegenData.del-inline}\verb|CodegenData.del_inline: thm -> theory -> theory| \\
  1677   \indexml{CodegenData.add-inline-proc}\verb|CodegenData.add_inline_proc: (theory -> cterm list -> thm list)|\isasep\isanewline%
  1677   \indexml{CodegenData.add-inline-proc}\verb|CodegenData.add_inline_proc: string * (theory -> cterm list -> thm list)|\isasep\isanewline%
  1678 \verb|    -> theory -> theory| \\
  1678 \verb|    -> theory -> theory| \\
  1679   \indexml{CodegenData.add-preproc}\verb|CodegenData.add_preproc: (theory -> thm list -> thm list)|\isasep\isanewline%
  1679   \indexml{CodegenData.del-inline-proc}\verb|CodegenData.del_inline_proc: string -> theory -> theory| \\
       
  1680   \indexml{CodegenData.add-preproc}\verb|CodegenData.add_preproc: string * (theory -> thm list -> thm list)|\isasep\isanewline%
  1680 \verb|    -> theory -> theory| \\
  1681 \verb|    -> theory -> theory| \\
       
  1682   \indexml{CodegenData.del-preproc}\verb|CodegenData.del_preproc: string -> theory -> theory| \\
  1681   \indexml{CodegenData.add-datatype}\verb|CodegenData.add_datatype: string * (((string * sort) list * (string * typ list) list)|\isasep\isanewline%
  1683   \indexml{CodegenData.add-datatype}\verb|CodegenData.add_datatype: string * (((string * sort) list * (string * typ list) list)|\isasep\isanewline%
  1682 \verb|    * thm list Susp.T) -> theory -> theory| \\
  1684 \verb|    * thm list Susp.T) -> theory -> theory| \\
  1683   \indexml{CodegenData.del-datatype}\verb|CodegenData.del_datatype: string -> theory -> theory| \\
  1685   \indexml{CodegenData.del-datatype}\verb|CodegenData.del_datatype: string -> theory -> theory| \\
  1684   \indexml{CodegenData.get-datatype}\verb|CodegenData.get_datatype: theory -> string|\isasep\isanewline%
  1686   \indexml{CodegenData.get-datatype}\verb|CodegenData.get_datatype: theory -> string|\isasep\isanewline%
  1685 \verb|    -> ((string * sort) list * (string * typ list) list) option| \\
  1687 \verb|    -> ((string * sort) list * (string * typ list) list) option| \\
  1693 
  1695 
  1694   \item \verb|CodegenData.del_func|~\isa{thm}~\isa{thy} removes function
  1696   \item \verb|CodegenData.del_func|~\isa{thm}~\isa{thy} removes function
  1695      theorem \isa{thm} from executable content, if present.
  1697      theorem \isa{thm} from executable content, if present.
  1696 
  1698 
  1697   \item \verb|CodegenData.add_funcl|~\isa{{\isacharparenleft}const{\isacharcomma}\ lthms{\isacharparenright}}~\isa{thy} adds
  1699   \item \verb|CodegenData.add_funcl|~\isa{{\isacharparenleft}const{\isacharcomma}\ lthms{\isacharparenright}}~\isa{thy} adds
  1698      suspended function equations \isa{lthms} for constant
  1700      suspended defining equations \isa{lthms} for constant
  1699      \isa{const} to executable content.
  1701      \isa{const} to executable content.
  1700 
  1702 
  1701   \item \verb|CodegenData.add_inline|~\isa{thm}~\isa{thy} adds
  1703   \item \verb|CodegenData.add_inline|~\isa{thm}~\isa{thy} adds
  1702      inlining theorem \isa{thm} to executable content.
  1704      inlining theorem \isa{thm} to executable content.
  1703 
  1705 
  1704   \item \verb|CodegenData.del_inline|~\isa{thm}~\isa{thy} remove
  1706   \item \verb|CodegenData.del_inline|~\isa{thm}~\isa{thy} remove
  1705      inlining theorem \isa{thm} from executable content, if present.
  1707      inlining theorem \isa{thm} from executable content, if present.
  1706 
  1708 
  1707   \item \verb|CodegenData.add_inline_proc|~\isa{f}~\isa{thy} adds
  1709   \item \verb|CodegenData.add_inline_proc|~\isa{{\isacharparenleft}name{\isacharcomma}\ f{\isacharparenright}}~\isa{thy} adds
  1708      inline procedure \isa{f} to executable content;
  1710      inline procedure \isa{f} (named \isa{name}) to executable content;
  1709      \isa{f} is a computation of rewrite rules dependent on
  1711      \isa{f} is a computation of rewrite rules dependent on
  1710      the current theory context and the list of all arguments
  1712      the current theory context and the list of all arguments
  1711      and right hand sides of the function equations belonging
  1713      and right hand sides of the defining equations belonging
  1712      to a certain function definition.
  1714      to a certain function definition.
  1713 
  1715 
  1714   \item \verb|CodegenData.add_preproc|~\isa{f}~\isa{thy} adds
  1716   \item \verb|CodegenData.del_inline_proc|~\isa{name}~\isa{thy} removes
  1715      generic preprocessor \isa{f} to executable content;
  1717      inline procedure named \isa{name} from executable content.
  1716      \isa{f} is a transformation of the function equations belonging
  1718 
       
  1719   \item \verb|CodegenData.add_preproc|~\isa{{\isacharparenleft}name{\isacharcomma}\ f{\isacharparenright}}~\isa{thy} adds
       
  1720      generic preprocessor \isa{f} (named \isa{name}) to executable content;
       
  1721      \isa{f} is a transformation of the defining equations belonging
  1717      to a certain function definition, depending on the
  1722      to a certain function definition, depending on the
  1718      current theory context.
  1723      current theory context.
       
  1724 
       
  1725   \item \verb|CodegenData.del_preproc|~\isa{name}~\isa{thy} removes
       
  1726      generic preprcoessor named \isa{name} from executable content.
  1719 
  1727 
  1720   \item \verb|CodegenData.add_datatype|~\isa{{\isacharparenleft}name{\isacharcomma}\ {\isacharparenleft}spec{\isacharcomma}\ cert{\isacharparenright}{\isacharparenright}}~\isa{thy} adds
  1728   \item \verb|CodegenData.add_datatype|~\isa{{\isacharparenleft}name{\isacharcomma}\ {\isacharparenleft}spec{\isacharcomma}\ cert{\isacharparenright}{\isacharparenright}}~\isa{thy} adds
  1721      a datatype to executable content, with type constructor
  1729      a datatype to executable content, with type constructor
  1722      \isa{name} and specification \isa{spec}; \isa{spec} is
  1730      \isa{name} and specification \isa{spec}; \isa{spec} is
  1723      a pair consisting of a list of type variable with sort
  1731      a pair consisting of a list of type variable with sort
  1743 %
  1751 %
  1744 \isadelimmlref
  1752 \isadelimmlref
  1745 %
  1753 %
  1746 \endisadelimmlref
  1754 \endisadelimmlref
  1747 %
  1755 %
  1748 \isamarkupsubsection{Function equation systems: codegen\_funcgr.ML%
  1756 \isamarkupsubsection{defining equation systems: codegen\_funcgr.ML%
  1749 }
  1757 }
  1750 \isamarkuptrue%
  1758 \isamarkuptrue%
  1751 %
  1759 %
  1752 \begin{isamarkuptext}%
  1760 \begin{isamarkuptext}%
  1753 Out of the executable content of a theory, a normalized
  1761 Out of the executable content of a theory, a normalized
  1754   function equation systems may be constructed containing
  1762   defining equation systems may be constructed containing
  1755   function definitions for constants.  The system is cached
  1763   function definitions for constants.  The system is cached
  1756   until its underlying executable content changes.%
  1764   until its underlying executable content changes.%
  1757 \end{isamarkuptext}%
  1765 \end{isamarkuptext}%
  1758 \isamarkuptrue%
  1766 \isamarkuptrue%
  1759 %
  1767 %
  1775   \end{mldecls}
  1783   \end{mldecls}
  1776 
  1784 
  1777   \begin{description}
  1785   \begin{description}
  1778 
  1786 
  1779   \item \verb|CodegenFuncgr.T| represents
  1787   \item \verb|CodegenFuncgr.T| represents
  1780     a normalized function equation system.
  1788     a normalized defining equation system.
  1781 
  1789 
  1782   \item \verb|CodegenFuncgr.make|~\isa{thy}~\isa{cs}
  1790   \item \verb|CodegenFuncgr.make|~\isa{thy}~\isa{cs}
  1783     returns a normalized function equation system,
  1791     returns a normalized defining equation system,
  1784     with the assertion that it contains any function
  1792     with the assertion that it contains any function
  1785     definition for constants \isa{cs} (if existing).
  1793     definition for constants \isa{cs} (if existing).
  1786 
  1794 
  1787   \item \verb|CodegenFuncgr.funcs|~\isa{funcgr}~\isa{c}
  1795   \item \verb|CodegenFuncgr.funcs|~\isa{funcgr}~\isa{c}
  1788     retrieves function definition for constant \isa{c}.
  1796     retrieves function definition for constant \isa{c}.
  1827   \indexml{CodegenConsts.eq-const}\verb|CodegenConsts.eq_const: CodegenConsts.const * CodegenConsts.const -> bool| \\
  1835   \indexml{CodegenConsts.eq-const}\verb|CodegenConsts.eq_const: CodegenConsts.const * CodegenConsts.const -> bool| \\
  1828   \indexml{CodegenConsts.consts-of}\verb|CodegenConsts.consts_of: theory -> term -> CodegenConsts.const list| \\
  1836   \indexml{CodegenConsts.consts-of}\verb|CodegenConsts.consts_of: theory -> term -> CodegenConsts.const list| \\
  1829   \indexml{CodegenConsts.read-const}\verb|CodegenConsts.read_const: theory -> string -> CodegenConsts.const| \\
  1837   \indexml{CodegenConsts.read-const}\verb|CodegenConsts.read_const: theory -> string -> CodegenConsts.const| \\
  1830   \indexmlstructure{CodegenConsts.Consttab}\verb|structure CodegenConsts.Consttab| \\
  1838   \indexmlstructure{CodegenConsts.Consttab}\verb|structure CodegenConsts.Consttab| \\
  1831   \indexmlstructure{CodegenFuncgr.Constgraph}\verb|structure CodegenFuncgr.Constgraph| \\
  1839   \indexmlstructure{CodegenFuncgr.Constgraph}\verb|structure CodegenFuncgr.Constgraph| \\
  1832   \indexml{CodegenData.typ-func}\verb|CodegenData.typ_func: theory -> thm -> typ| \\
  1840   \indexml{CodegenFunc.typ-func}\verb|CodegenFunc.typ_func: thm -> typ| \\
  1833   \indexml{CodegenData.rewrite-func}\verb|CodegenData.rewrite_func: thm list -> thm -> thm| \\
  1841   \indexml{CodegenFunc.rewrite-func}\verb|CodegenFunc.rewrite_func: thm list -> thm -> thm| \\
  1834   \end{mldecls}
  1842   \end{mldecls}
  1835 
  1843 
  1836   \begin{description}
  1844   \begin{description}
  1837 
  1845 
  1838   \item \verb|CodegenConsts.const_ord|,~\verb|CodegenConsts.eq_const|
  1846   \item \verb|CodegenConsts.const_ord|,~\verb|CodegenConsts.eq_const|
  1845      returns all constant identifiers mentioned in a term \isa{t}.
  1853      returns all constant identifiers mentioned in a term \isa{t}.
  1846 
  1854 
  1847   \item \verb|CodegenConsts.read_const|~\isa{thy}~\isa{s}
  1855   \item \verb|CodegenConsts.read_const|~\isa{thy}~\isa{s}
  1848      reads a constant as a concrete term expression \isa{s}.
  1856      reads a constant as a concrete term expression \isa{s}.
  1849 
  1857 
  1850   \item \verb|CodegenData.typ_func|~\isa{thy}~\isa{thm}
  1858   \item \verb|CodegenFunc.typ_func|~\isa{thm}
  1851      extracts the type of a constant in a function equation \isa{thm}.
  1859      extracts the type of a constant in a defining equation \isa{thm}.
  1852 
  1860 
  1853   \item \verb|CodegenData.rewrite_func|~\isa{rews}~\isa{thm}
  1861   \item \verb|CodegenFunc.rewrite_func|~\isa{rews}~\isa{thm}
  1854      rewrites a function equation \isa{thm} with a set of rewrite
  1862      rewrites a defining equation \isa{thm} with a set of rewrite
  1855      rules \isa{rews}; only arguments and right hand side are rewritten,
  1863      rules \isa{rews}; only arguments and right hand side are rewritten,
  1856      not the head of the function equation.
  1864      not the head of the defining equation.
  1857 
  1865 
  1858   \end{description}%
  1866   \end{description}%
  1859 \end{isamarkuptext}%
  1867 \end{isamarkuptext}%
  1860 \isamarkuptrue%
  1868 \isamarkuptrue%
  1861 %
  1869 %
  1963 %
  1971 %
  1964 \begin{isamarkuptext}%
  1972 \begin{isamarkuptext}%
  1965 Isabelle/HOL's datatype package provides a mechanism to
  1973 Isabelle/HOL's datatype package provides a mechanism to
  1966   extend theories depending on datatype declarations:
  1974   extend theories depending on datatype declarations:
  1967   \emph{datatype hooks}.  For example, when declaring a new
  1975   \emph{datatype hooks}.  For example, when declaring a new
  1968   datatype, a hook proves function equations for equality on
  1976   datatype, a hook proves defining equations for equality on
  1969   that datatype (if possible).%
  1977   that datatype (if possible).%
  1970 \end{isamarkuptext}%
  1978 \end{isamarkuptext}%
  1971 \isamarkuptrue%
  1979 \isamarkuptrue%
  1972 %
  1980 %
  1973 \isadelimmlref
  1981 \isadelimmlref