doc-src/Intro/advanced.tex
changeset 3103 98af809fee46
parent 1904 4f77c2fd8f3d
child 3106 5396e99c02af
equal deleted inserted replaced
3102:4d01cdc119d2 3103:98af809fee46
     1 %% $Id$
     1 %% $Id$
     2 \part{Advanced Methods}
     2 \part{Advanced Methods}
     3 Before continuing, it might be wise to try some of your own examples in
     3 Before continuing, it might be wise to try some of your own examples in
     4 Isabelle, reinforcing your knowledge of the basic functions.
     4 Isabelle, reinforcing your knowledge of the basic functions.
     5 
     5 
     6 Look through {\em Isabelle's Object-Logics\/} and try proving some simple
     6 Look through {\em Isabelle's Object-Logics\/} and try proving some
     7 theorems.  You probably should begin with first-order logic ({\tt FOL}
     7 simple theorems.  You probably should begin with first-order logic
     8 or~{\tt LK}).  Try working some of the examples provided, and others from
     8 ({\tt FOL} or~{\tt LK}).  Try working some of the examples provided,
     9 the literature.  Set theory~({\tt ZF}) and Constructive Type Theory~({\tt
     9 and others from the literature.  Set theory~({\tt ZF}) and
    10   CTT}) form a richer world for mathematical reasoning and, again, many
    10 Constructive Type Theory~({\tt CTT}) form a richer world for
    11 examples are in the literature.  Higher-order logic~({\tt HOL}) is
    11 mathematical reasoning and, again, many examples are in the
    12 Isabelle's most sophisticated logic because its types and functions are
    12 literature.  Higher-order logic~({\tt HOL}) is Isabelle's most
    13 identified with those of the meta-logic.
    13 elaborate logic. Its types and functions are identified with those of
       
    14 the meta-logic.
    14 
    15 
    15 Choose a logic that you already understand.  Isabelle is a proof
    16 Choose a logic that you already understand.  Isabelle is a proof
    16 tool, not a teaching tool; if you do not know how to do a particular proof
    17 tool, not a teaching tool; if you do not know how to do a particular proof
    17 on paper, then you certainly will not be able to do it on the machine.
    18 on paper, then you certainly will not be able to do it on the machine.
    18 Even experienced users plan large proofs on paper.
    19 Even experienced users plan large proofs on paper.
    34 \subsection{Deriving a rule using tactics and meta-level assumptions} 
    35 \subsection{Deriving a rule using tactics and meta-level assumptions} 
    35 \label{deriving-example}
    36 \label{deriving-example}
    36 \index{examples!of deriving rules}\index{assumptions!of main goal}
    37 \index{examples!of deriving rules}\index{assumptions!of main goal}
    37 
    38 
    38 The subgoal module supports the derivation of rules, as discussed in
    39 The subgoal module supports the derivation of rules, as discussed in
    39 \S\ref{deriving}.  The \ttindex{goal} command, when supplied a goal of the
    40 \S\ref{deriving}.  The \ttindex{goal} command, when supplied a goal of
    40 form $\List{\theta@1; \ldots; \theta@k} \Imp \phi$, creates $\phi\Imp\phi$
    41 the form $\List{\theta@1; \ldots; \theta@k} \Imp \phi$, creates
    41 as the initial proof state and returns a list consisting of the theorems
    42 $\phi\Imp\phi$ as the initial proof state and returns a list
    42 ${\theta@i\;[\theta@i]}$, for $i=1$, \ldots,~$k$.  These meta-assumptions
    43 consisting of the theorems ${\theta@i\;[\theta@i]}$, for $i=1$,
    43 are also recorded internally, allowing {\tt result} to discharge them
    44 \ldots,~$k$.  These meta-assumptions are also recorded internally,
       
    45 allowing {\tt result} (which is called by {\tt qed}) to discharge them
    44 in the original order.
    46 in the original order.
    45 
    47 
    46 Let us derive $\conj$ elimination using Isabelle.
    48 Let us derive $\conj$ elimination using Isabelle.
    47 Until now, calling {\tt goal} has returned an empty list, which we have
    49 Until now, calling {\tt goal} has returned an empty list, which we have
    48 thrown away.  In this example, the list contains the two premises of the
    50 thrown away.  In this example, the list contains the two premises of the
    89 {\out Level 3}
    91 {\out Level 3}
    90 {\out R}
    92 {\out R}
    91 {\out No subgoals!}
    93 {\out No subgoals!}
    92 \end{ttbox}
    94 \end{ttbox}
    93 Calling \ttindex{topthm} returns the current proof state as a theorem.
    95 Calling \ttindex{topthm} returns the current proof state as a theorem.
    94 Note that it contains assumptions.  Calling \ttindex{result} discharges the
    96 Note that it contains assumptions.  Calling \ttindex{qed} discharges
    95 assumptions --- both occurrences of $P\conj Q$ are discharged as one ---
    97 the assumptions --- both occurrences of $P\conj Q$ are discharged as
    96 and makes the variables schematic.
    98 one --- and makes the variables schematic.
    97 \begin{ttbox}
    99 \begin{ttbox}
    98 topthm();
   100 topthm();
    99 {\out val it = "R  [P & Q, P & Q, [| P; Q |] ==> R]" : thm}
   101 {\out val it = "R  [P & Q, P & Q, [| P; Q |] ==> R]" : thm}
   100 val conjE = result();
   102 qed "conjE";
   101 {\out val conjE = "[| ?P & ?Q; [| ?P; ?Q |] ==> ?R |] ==> ?R" : thm}
   103 {\out val conjE = "[| ?P & ?Q; [| ?P; ?Q |] ==> ?R |] ==> ?R" : thm}
   102 \end{ttbox}
   104 \end{ttbox}
   103 
   105 
   104 
   106 
   105 \subsection{Definitions and derived rules} \label{definitions}
   107 \subsection{Definitions and derived rules} \label{definitions}
   137 For example, the intuitionistic definition of negation given above may seem
   139 For example, the intuitionistic definition of negation given above may seem
   138 peculiar.  Using Isabelle, we shall derive pleasanter negation rules:
   140 peculiar.  Using Isabelle, we shall derive pleasanter negation rules:
   139 \[  \infer[({\neg}I)]{\neg P}{\infer*{\bot}{[P]}}   \qquad
   141 \[  \infer[({\neg}I)]{\neg P}{\infer*{\bot}{[P]}}   \qquad
   140     \infer[({\neg}E)]{Q}{\neg P & P}  \]
   142     \infer[({\neg}E)]{Q}{\neg P & P}  \]
   141 This requires proving the following meta-formulae:
   143 This requires proving the following meta-formulae:
   142 $$ (P\Imp\bot)    \Imp \neg P   \eqno(\neg I)$$
   144 $$ (P\Imp\bot)    \Imp \neg P   \eqno(\neg I) $$
   143 $$ \List{\neg P; P} \Imp Q.       \eqno(\neg E)$$
   145 $$ \List{\neg P; P} \Imp Q.       \eqno(\neg E) $$
   144 
   146 
   145 
   147 
   146 \subsection{Deriving the $\neg$ introduction rule}
   148 \subsection{Deriving the $\neg$ introduction rule}
   147 To derive $(\neg I)$, we may call {\tt goal} with the appropriate
   149 To derive $(\neg I)$, we may call {\tt goal} with the appropriate
   148 formula.  Again, {\tt goal} returns a list consisting of the rule's
   150 formula.  Again, {\tt goal} returns a list consisting of the rule's
   183 by (assume_tac 1);
   185 by (assume_tac 1);
   184 {\out Level 4}
   186 {\out Level 4}
   185 {\out ~P}
   187 {\out ~P}
   186 {\out No subgoals!}
   188 {\out No subgoals!}
   187 \ttbreak
   189 \ttbreak
   188 val notI = result();
   190 qed "notI";
   189 {\out val notI = "(?P ==> False) ==> ~?P" : thm}
   191 {\out val notI = "(?P ==> False) ==> ~?P" : thm}
   190 \end{ttbox}
   192 \end{ttbox}
   191 \indexbold{*notI theorem}
   193 \indexbold{*notI theorem}
   192 
   194 
   193 There is a simpler way of conducting this proof.  The \ttindex{goalw}
   195 There is a simpler way of conducting this proof.  The \ttindex{goalw}
   249 \begin{ttbox}
   251 \begin{ttbox}
   250 by (resolve_tac [minor] 1);
   252 by (resolve_tac [minor] 1);
   251 {\out Level 4}
   253 {\out Level 4}
   252 {\out R}
   254 {\out R}
   253 {\out No subgoals!}
   255 {\out No subgoals!}
   254 val notE = result();
   256 qed "notE";
   255 {\out val notE = "[| ~?P; ?P |] ==> ?R" : thm}
   257 {\out val notE = "[| ~?P; ?P |] ==> ?R" : thm}
   256 \end{ttbox}
   258 \end{ttbox}
   257 \indexbold{*notE theorem}
   259 \indexbold{*notE theorem}
   258 
   260 
   259 \medskip
   261 \medskip
   311 by (assume_tac 1);
   313 by (assume_tac 1);
   312 {\out Level 3}
   314 {\out Level 3}
   313 {\out !!P R. [| ~ P; P |] ==> R}
   315 {\out !!P R. [| ~ P; P |] ==> R}
   314 {\out No subgoals!}
   316 {\out No subgoals!}
   315 \end{ttbox}
   317 \end{ttbox}
   316 Calling \ttindex{result} strips the meta-quantifiers, so the resulting
   318 Calling \ttindex{qed} strips the meta-quantifiers, so the resulting
   317 theorem is the same as before.
   319 theorem is the same as before.
   318 \begin{ttbox}
   320 \begin{ttbox}
   319 val notE = result();
   321 qed "notE";
   320 {\out val notE = "[| ~?P; ?P |] ==> ?R" : thm}
   322 {\out val notE = "[| ~?P; ?P |] ==> ?R" : thm}
   321 \end{ttbox}
   323 \end{ttbox}
   322 Do not use the {\tt!!}\ trick if the premises contain meta-level
   324 Do not use the {\tt!!}\ trick if the premises contain meta-level
   323 connectives, because \ttindex{eresolve_tac} and \ttindex{assume_tac} would
   325 connectives, because \ttindex{eresolve_tac} and \ttindex{assume_tac} would
   324 not be able to handle the resulting assumptions.  The trick is not suitable
   326 not be able to handle the resulting assumptions.  The trick is not suitable
   326 
   328 
   327 
   329 
   328 \section{Defining theories}\label{sec:defining-theories}
   330 \section{Defining theories}\label{sec:defining-theories}
   329 \index{theories!defining|(}
   331 \index{theories!defining|(}
   330 
   332 
   331 Isabelle makes no distinction between simple extensions of a logic --- like
   333 Isabelle makes no distinction between simple extensions of a logic ---
   332 defining a type~$bool$ with constants~$true$ and~$false$ --- and defining
   334 like specifying a type~$bool$ with constants~$true$ and~$false$ ---
   333 an entire logic.  A theory definition has the form
   335 and defining an entire logic.  A theory definition has a form like
   334 \begin{ttbox}
   336 \begin{ttbox}
   335 \(T\) = \(S@1\) + \(\cdots\) + \(S@n\) +
   337 \(T\) = \(S@1\) + \(\cdots\) + \(S@n\) +
   336 classes      {\it class declarations}
   338 classes      {\it class declarations}
   337 default      {\it sort}
   339 default      {\it sort}
   338 types        {\it type declarations and synonyms}
   340 types        {\it type declarations and synonyms}
   339 arities      {\it arity declarations}
   341 arities      {\it type arity declarations}
   340 consts       {\it constant declarations}
   342 consts       {\it constant declarations}
   341 translations {\it translation declarations}
   343 syntax       {\it syntactic constant declarations}
   342 defs         {\it definitions}
   344 translations {\it ast translation rules}
       
   345 defs         {\it meta-logical definitions}
   343 rules        {\it rule declarations}
   346 rules        {\it rule declarations}
   344 end
   347 end
   345 ML           {\it ML code}
   348 ML           {\it ML code}
   346 \end{ttbox}
   349 \end{ttbox}
   347 This declares the theory $T$ to extend the existing theories
   350 This declares the theory $T$ to extend the existing theories
   348 $S@1$,~\ldots,~$S@n$.  It may declare new classes, types, arities
   351 $S@1$,~\ldots,~$S@n$.  It may introduce new classes, types, arities
   349 (overloadings of existing types), constants and rules; it can specify the
   352 (of existing types), constants and rules; it can specify the default
   350 default sort for type variables.  A constant declaration can specify an
   353 sort for type variables.  A constant declaration can specify an
   351 associated concrete syntax.  The translations section specifies rewrite
   354 associated concrete syntax.  The translations section specifies
   352 rules on abstract syntax trees, for defining notations and abbreviations.
   355 rewrite rules on abstract syntax trees, handling notations and
   353 \index{*ML section}
   356 abbreviations.  \index{*ML section} The {\tt ML} section may contain
   354 The {\tt ML} section contains code to perform arbitrary syntactic
   357 code to perform arbitrary syntactic transformations.  The main
   355 transformations.  The main declaration forms are discussed below.
   358 declaration forms are discussed below.  The full syntax can be found
   356 The full syntax can be found in \iflabelundefined{app:TheorySyntax}{the
   359 in \iflabelundefined{app:TheorySyntax}{an appendix of the {\it
   357   appendix of the {\it Reference Manual}}{App.\ts\ref{app:TheorySyntax}}.
   360     Reference Manual}}{App.\ts\ref{app:TheorySyntax}}.  Also note that
   358 
   361 object-logics may add further theory sections, for example {\tt
   359 All the declaration parts can be omitted or repeated and may appear in any
   362   typedef}, {\tt datatype} in \HOL.
   360 order, except that the {\ML} section must be last.  In the simplest case, $T$
   363 
   361 is just the union of $S@1$,~\ldots,~$S@n$.  New theories always extend one or
   364 All the declaration parts can be omitted or repeated and may appear in
   362 more other theories, inheriting their types, constants, syntax, etc.  The
   365 any order, except that the {\ML} section must be last (after the {\tt
   363 theory \thydx{Pure} contains nothing but Isabelle's meta-logic.
   366   end} keyword).  In the simplest case, $T$ is just the union of
   364 
   367 $S@1$,~\ldots,~$S@n$.  New theories always extend one or more other
   365 Each theory definition must reside in a separate file, whose name is the
   368 theories, inheriting their types, constants, syntax, etc.  The theory
   366 theory's with {\tt.thy} appended.  For example, theory {\tt ListFn} resides
   369 \thydx{Pure} contains nothing but Isabelle's meta-logic. The variant
   367 on a file named {\tt ListFn.thy}.  Isabelle uses this convention to locate the
   370 \thydx{CPure} offers the more usual higher-order function application
   368 file containing a given theory; \ttindexbold{use_thy} automatically loads a
   371 syntax $t\,u@1\ldots\,u@n$ instead of $t(u@1,\ldots,u@n)$.
   369 theory's parents before loading the theory itself.
   372 
   370 
   373 Each theory definition must reside in a separate file, whose name is
   371 Calling \ttindexbold{use_thy}~{\tt"{\it T\/}"} reads a theory from the
   374 the theory's with {\tt.thy} appended.  Calling
   372 file {\it T}{\tt.thy}, writes the corresponding {\ML} code to the file
   375 \ttindexbold{use_thy}~{\tt"{\it T\/}"} reads the definition from {\it
   373 {\tt.{\it T}.thy.ML}, reads the latter file, and deletes it if no errors
   376   T}{\tt.thy}, writes a corresponding file of {\ML} code {\tt.{\it
   374 occurred.  This declares the {\ML} structure~$T$, which contains a component
   377     T}.thy.ML}, reads the latter file, and deletes it if no errors
   375 {\tt thy} denoting the new theory, a component for each rule, and everything
   378 occurred.  This declares the {\ML} structure~$T$, which contains a
   376 declared in {\it ML code}.
   379 component {\tt thy} denoting the new theory, a component for each
   377 
   380 rule, and everything declared in {\it ML code}.
   378 Errors may arise during the translation to {\ML} (say, a misspelled keyword)
   381 
   379 or during creation of the new theory (say, a type error in a rule).  But if
   382 Errors may arise during the translation to {\ML} (say, a misspelled
   380 all goes well, {\tt use_thy} will finally read the file {\it T}{\tt.ML}, if
   383 keyword) or during creation of the new theory (say, a type error in a
   381 it exists.  This file typically begins with the {\ML} declaration {\tt
   384 rule).  But if all goes well, {\tt use_thy} will finally read the file
   382 open}~$T$ and contains proofs that refer to the components of~$T$.
   385 {\it T}{\tt.ML} (if it exists).  This file typically contains proofs
   383 
   386 that refer to the components of~$T$. The structure is automatically
   384 When a theory file is modified, many theories may have to be reloaded.
   387 opened, so its components may be referred to by unqualified names,
   385 Isabelle records the modification times and dependencies of theory files.
   388 e.g.\ just {\tt thy} instead of $T${\tt .thy}.
   386 See 
   389 
       
   390 \ttindexbold{use_thy} automatically loads a theory's parents before
       
   391 loading the theory itself.  When a theory file is modified, many
       
   392 theories may have to be reloaded.  Isabelle records the modification
       
   393 times and dependencies of theory files.  See
   387 \iflabelundefined{sec:reloading-theories}{the {\em Reference Manual\/}}%
   394 \iflabelundefined{sec:reloading-theories}{the {\em Reference Manual\/}}%
   388                  {\S\ref{sec:reloading-theories}}
   395                  {\S\ref{sec:reloading-theories}}
   389 for more details.
   396 for more details.
   390 
   397 
   391 
   398 
   416 \end{ttbox}
   423 \end{ttbox}
   417 where $id@1$, \ldots, $id@n$ are \ML{} identifiers and $rule@1$, \ldots,
   424 where $id@1$, \ldots, $id@n$ are \ML{} identifiers and $rule@1$, \ldots,
   418 $rule@n$ are expressions of type~$prop$.  Each rule {\em must\/} be
   425 $rule@n$ are expressions of type~$prop$.  Each rule {\em must\/} be
   419 enclosed in quotation marks.
   426 enclosed in quotation marks.
   420 
   427 
   421 \indexbold{definitions} The {\bf definition part} is similar, but with the
   428 \indexbold{definitions} The {\bf definition part} is similar, but with
   422 keyword {\tt defs} instead of {\tt rules}.  {\bf Definitions} are rules of the
   429 the keyword {\tt defs} instead of {\tt rules}.  {\bf Definitions} are
   423 form $s \equiv t$, and should serve only as abbreviations. The simplest form
   430 rules of the form $s \equiv t$, and should serve only as
   424 of a definition is $f \equiv t$, where $f$ is a constant. Isabelle also
   431 abbreviations. The simplest form of a definition is $f \equiv t$,
   425 allows a derived form where the arguments of~$f$ appear on the left:
   432 where $f$ is a constant. Also allowed are $\eta$-equivalent forms,
   426 \begin{itemize}
   433 where the arguments of~$f$ appear applied on the left-hand side of the
   427 \item In uncurried syntax: $f(x@1,\dots,x@n) \equiv u$ (\FOL, \ZF, \dots)
   434 equation instead of abstracted on the right-hand side.
   428 \item In curried syntax: $f~x@1~\dots~x@n \equiv u$ (\HOL, \HOLCF)
   435 
   429 \end{itemize}
   436 Isabelle checks for common errors in definitions, such as extra
   430 Isabelle checks for common errors in definitions, such as extra variables on
   437 variables on the right-hand side, but currently does not a complete
   431 the right-hand side.  Determined users can write non-conservative
   438 test of well-formedness. Thus determined users can write
   432 `definitions' by using mutual recursion, for example; the consequences of
   439 non-conservative `definitions' by using mutual recursion, for example;
   433 such actions are their responsibility.
   440 the consequences of such actions are their responsibility.
   434 
   441 
   435 \index{examples!of theories} 
   442 \index{examples!of theories} This example theory extends first-order
   436 This theory extends first-order logic by declaring and defining two constants,
   443 logic by declaring and defining two constants, {\em nand} and {\em
   437 {\em nand} and {\em xor}:
   444   xor}:
   438 \begin{ttbox}
   445 \begin{ttbox}
   439 Gate = FOL +
   446 Gate = FOL +
   440 consts  nand,xor :: [o,o] => o
   447 consts  nand,xor :: [o,o] => o
   441 defs    nand_def "nand(P,Q) == ~(P & Q)"
   448 defs    nand_def "nand(P,Q) == ~(P & Q)"
   442         xor_def  "xor(P,Q)  == P & ~Q | ~P & Q"
   449         xor_def  "xor(P,Q)  == P & ~Q | ~P & Q"
   555 Multiple arity declarations may be abbreviated to a single line:
   562 Multiple arity declarations may be abbreviated to a single line:
   556 \begin{ttbox}
   563 \begin{ttbox}
   557 arities \(tycon@1\), \ldots, \(tycon@n\) :: \(arity\)
   564 arities \(tycon@1\), \ldots, \(tycon@n\) :: \(arity\)
   558 \end{ttbox}
   565 \end{ttbox}
   559 
   566 
   560 \begin{warn}
   567 %\begin{warn}
   561 Arity declarations resemble constant declarations, but there are {\it no\/}
   568 %Arity declarations resemble constant declarations, but there are {\it no\/}
   562 quotation marks!  Types and rules must be quoted because the theory
   569 %quotation marks!  Types and rules must be quoted because the theory
   563 translator passes them verbatim to the {\ML} output file.
   570 %translator passes them verbatim to the {\ML} output file.
   564 \end{warn}
   571 %\end{warn}
   565 
   572 
   566 \subsection{Type synonyms}\indexbold{type synonyms}
   573 \subsection{Type synonyms}\indexbold{type synonyms}
   567 Isabelle supports {\bf type synonyms} ({\bf abbreviations}) which are similar
   574 Isabelle supports {\bf type synonyms} ({\bf abbreviations}) which are similar
   568 to those found in \ML.  Such synonyms are defined in the type declaration part
   575 to those found in \ML.  Such synonyms are defined in the type declaration part
   569 and are fairly self explanatory:
   576 and are fairly self explanatory:
   577 types nat
   584 types nat
   578       'a stream = nat => 'a
   585       'a stream = nat => 'a
   579       signal    = nat stream
   586       signal    = nat stream
   580       'a list
   587       'a list
   581 \end{ttbox}
   588 \end{ttbox}
   582 A synonym is merely an abbreviation for some existing type expression.  Hence
   589 A synonym is merely an abbreviation for some existing type expression.
   583 synonyms may not be recursive!  Internally all synonyms are fully expanded.  As
   590 Hence synonyms may not be recursive!  Internally all synonyms are
   584 a consequence Isabelle output never contains synonyms.  Their main purpose is
   591 fully expanded.  As a consequence Isabelle output never contains
   585 to improve the readability of theories.  Synonyms can be used just like any
   592 synonyms.  Their main purpose is to improve the readability of theory
   586 other type:
   593 definitions.  Synonyms can be used just like any other type:
   587 \begin{ttbox}
   594 \begin{ttbox}
   588 consts and,or :: gate
   595 consts and,or :: gate
   589        negate :: signal => signal
   596        negate :: signal => signal
   590 \end{ttbox}
   597 \end{ttbox}
   591 
   598 
   621 \end{ttbox}
   628 \end{ttbox}
   622 This declares a constant $If$ of type $[o,o,o] \To o$ with concrete syntax {\tt
   629 This declares a constant $If$ of type $[o,o,o] \To o$ with concrete syntax {\tt
   623   if~$P$ then~$Q$ else~$R$} as well as {\tt If($P$,$Q$,$R$)}.  Underscores
   630   if~$P$ then~$Q$ else~$R$} as well as {\tt If($P$,$Q$,$R$)}.  Underscores
   624 denote argument positions.  
   631 denote argument positions.  
   625 
   632 
   626 The declaration above does not allow the {\tt if}-{\tt then}-{\tt else}
   633 The declaration above does not allow the {\tt if}-{\tt then}-{\tt
   627 construct to be split across several lines, even if it is too long to fit
   634   else} construct to be printed split across several lines, even if it
   628 on one line.  Pretty-printing information can be added to specify the
   635 is too long to fit on one line.  Pretty-printing information can be
   629 layout of mixfix operators.  For details, see
   636 added to specify the layout of mixfix operators.  For details, see
   630 \iflabelundefined{Defining-Logics}%
   637 \iflabelundefined{Defining-Logics}%
   631     {the {\it Reference Manual}, chapter `Defining Logics'}%
   638     {the {\it Reference Manual}, chapter `Defining Logics'}%
   632     {Chap.\ts\ref{Defining-Logics}}.
   639     {Chap.\ts\ref{Defining-Logics}}.
   633 
   640 
   634 Mixfix declarations can be annotated with priorities, just like
   641 Mixfix declarations can be annotated with priorities, just like
   670         snd     "snd(<a,b>) = b"
   677         snd     "snd(<a,b>) = b"
   671 end
   678 end
   672 \end{ttbox}
   679 \end{ttbox}
   673 
   680 
   674 \begin{warn}
   681 \begin{warn}
   675 The name of the type constructor is~{\tt *} and not {\tt op~*}, as it would
   682   The name of the type constructor is~{\tt *} and not {\tt op~*}, as
   676 be in the case of an infix constant.  Only infix type constructors can have
   683   it would be in the case of an infix constant.  Only infix type
   677 symbolic names like~{\tt *}.  There is no general mixfix syntax for types.
   684   constructors can have symbolic names like~{\tt *}.  General mixfix
       
   685   syntax for types may be introduced via appropriate {\tt syntax}
       
   686   declarations.
   678 \end{warn}
   687 \end{warn}
   679 
   688 
   680 
   689 
   681 \subsection{Overloading}
   690 \subsection{Overloading}
   682 \index{overloading}\index{examples!of theories}
   691 \index{overloading}\index{examples!of theories}
   824         add_def     "m+n == rec(m, n, \%x y. Suc(y))"
   833         add_def     "m+n == rec(m, n, \%x y. Suc(y))"
   825 end
   834 end
   826 \end{ttbox}
   835 \end{ttbox}
   827 In axiom {\tt add_def}, recall that \verb|%| stands for~$\lambda$.
   836 In axiom {\tt add_def}, recall that \verb|%| stands for~$\lambda$.
   828 Loading this theory file creates the \ML\ structure {\tt Nat}, which
   837 Loading this theory file creates the \ML\ structure {\tt Nat}, which
   829 contains the theory and axioms.  Opening structure {\tt Nat} lets us write
   838 contains the theory and axioms.
   830 {\tt induct} instead of {\tt Nat.induct}, and so forth.
       
   831 \begin{ttbox}
       
   832 open Nat;
       
   833 \end{ttbox}
       
   834 
   839 
   835 \subsection{Proving some recursion equations}
   840 \subsection{Proving some recursion equations}
   836 File {\tt FOL/ex/Nat.ML} contains proofs involving this theory of the
   841 File {\tt FOL/ex/Nat.ML} contains proofs involving this theory of the
   837 natural numbers.  As a trivial example, let us derive recursion equations
   842 natural numbers.  As a trivial example, let us derive recursion equations
   838 for \verb$+$.  Here is the zero case:
   843 for \verb$+$.  Here is the zero case:
   844 \ttbreak
   849 \ttbreak
   845 by (resolve_tac [rec_0] 1);
   850 by (resolve_tac [rec_0] 1);
   846 {\out Level 1}
   851 {\out Level 1}
   847 {\out 0 + n = n}
   852 {\out 0 + n = n}
   848 {\out No subgoals!}
   853 {\out No subgoals!}
   849 val add_0 = result();
   854 qed "add_0";
   850 \end{ttbox}
   855 \end{ttbox}
   851 And here is the successor case:
   856 And here is the successor case:
   852 \begin{ttbox}
   857 \begin{ttbox}
   853 goalw Nat.thy [add_def] "Suc(m)+n = Suc(m+n)";
   858 goalw Nat.thy [add_def] "Suc(m)+n = Suc(m+n)";
   854 {\out Level 0}
   859 {\out Level 0}
   857 \ttbreak
   862 \ttbreak
   858 by (resolve_tac [rec_Suc] 1);
   863 by (resolve_tac [rec_Suc] 1);
   859 {\out Level 1}
   864 {\out Level 1}
   860 {\out Suc(m) + n = Suc(m + n)}
   865 {\out Suc(m) + n = Suc(m + n)}
   861 {\out No subgoals!}
   866 {\out No subgoals!}
   862 val add_Suc = result();
   867 qed "add_Suc";
   863 \end{ttbox}
   868 \end{ttbox}
   864 The induction rule raises some complications, which are discussed next.
   869 The induction rule raises some complications, which are discussed next.
   865 \index{theories!defining|)}
   870 \index{theories!defining|)}
   866 
   871 
   867 
   872