doc-src/TutorialI/Datatype/document/ABexpr.tex
changeset 17056 05fc32a23b8b
parent 16069 3f2a9f400168
child 17175 1eced27ee0e1
equal deleted inserted replaced
17055:eacce1cd716a 17056:05fc32a23b8b
     1 %
     1 %
     2 \begin{isabellebody}%
     2 \begin{isabellebody}%
     3 \def\isabellecontext{ABexpr}%
     3 \def\isabellecontext{ABexpr}%
     4 \isamarkupfalse%
     4 %
       
     5 \isadelimtheory
       
     6 %
       
     7 \endisadelimtheory
       
     8 %
       
     9 \isatagtheory
       
    10 %
       
    11 \endisatagtheory
       
    12 {\isafoldtheory}%
       
    13 %
       
    14 \isadelimtheory
       
    15 %
       
    16 \endisadelimtheory
       
    17 \isamarkuptrue%
     5 %
    18 %
     6 \begin{isamarkuptext}%
    19 \begin{isamarkuptext}%
     7 \index{datatypes!mutually recursive}%
    20 \index{datatypes!mutually recursive}%
     8 Sometimes it is necessary to define two datatypes that depend on each
    21 Sometimes it is necessary to define two datatypes that depend on each
     9 other. This is called \textbf{mutual recursion}. As an example consider a
    22 other. This is called \textbf{mutual recursion}. As an example consider a
    15 \item boolean expressions contain arithmetic expressions because of
    28 \item boolean expressions contain arithmetic expressions because of
    16   comparisons like ``$m<n$''.
    29   comparisons like ``$m<n$''.
    17 \end{itemize}
    30 \end{itemize}
    18 In Isabelle this becomes%
    31 In Isabelle this becomes%
    19 \end{isamarkuptext}%
    32 \end{isamarkuptext}%
    20 \isamarkuptrue%
    33 \isamarkupfalse%
    21 \isacommand{datatype}\ {\isacharprime}a\ aexp\ {\isacharequal}\ IF\ \ \ {\isachardoublequote}{\isacharprime}a\ bexp{\isachardoublequote}\ {\isachardoublequote}{\isacharprime}a\ aexp{\isachardoublequote}\ {\isachardoublequote}{\isacharprime}a\ aexp{\isachardoublequote}\isanewline
    34 \isacommand{datatype}\ {\isacharprime}a\ aexp\ {\isacharequal}\ IF\ \ \ {\isachardoublequote}{\isacharprime}a\ bexp{\isachardoublequote}\ {\isachardoublequote}{\isacharprime}a\ aexp{\isachardoublequote}\ {\isachardoublequote}{\isacharprime}a\ aexp{\isachardoublequote}\isanewline
    22 \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ {\isacharbar}\ Sum\ \ {\isachardoublequote}{\isacharprime}a\ aexp{\isachardoublequote}\ {\isachardoublequote}{\isacharprime}a\ aexp{\isachardoublequote}\isanewline
    35 \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ {\isacharbar}\ Sum\ \ {\isachardoublequote}{\isacharprime}a\ aexp{\isachardoublequote}\ {\isachardoublequote}{\isacharprime}a\ aexp{\isachardoublequote}\isanewline
    23 \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ {\isacharbar}\ Diff\ {\isachardoublequote}{\isacharprime}a\ aexp{\isachardoublequote}\ {\isachardoublequote}{\isacharprime}a\ aexp{\isachardoublequote}\isanewline
    36 \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ {\isacharbar}\ Diff\ {\isachardoublequote}{\isacharprime}a\ aexp{\isachardoublequote}\ {\isachardoublequote}{\isacharprime}a\ aexp{\isachardoublequote}\isanewline
    24 \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ {\isacharbar}\ Var\ {\isacharprime}a\isanewline
    37 \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ {\isacharbar}\ Var\ {\isacharprime}a\isanewline
    25 \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ {\isacharbar}\ Num\ nat\isanewline
    38 \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ {\isacharbar}\ Num\ nat\isanewline
    26 \isakeyword{and}\ \ \ \ \ \ {\isacharprime}a\ bexp\ {\isacharequal}\ Less\ {\isachardoublequote}{\isacharprime}a\ aexp{\isachardoublequote}\ {\isachardoublequote}{\isacharprime}a\ aexp{\isachardoublequote}\isanewline
    39 \isakeyword{and}\ \ \ \ \ \ {\isacharprime}a\ bexp\ {\isacharequal}\ Less\ {\isachardoublequote}{\isacharprime}a\ aexp{\isachardoublequote}\ {\isachardoublequote}{\isacharprime}a\ aexp{\isachardoublequote}\isanewline
    27 \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ {\isacharbar}\ And\ \ {\isachardoublequote}{\isacharprime}a\ bexp{\isachardoublequote}\ {\isachardoublequote}{\isacharprime}a\ bexp{\isachardoublequote}\isanewline
    40 \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ {\isacharbar}\ And\ \ {\isachardoublequote}{\isacharprime}a\ bexp{\isachardoublequote}\ {\isachardoublequote}{\isacharprime}a\ bexp{\isachardoublequote}\isanewline
    28 \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ {\isacharbar}\ Neg\ \ {\isachardoublequote}{\isacharprime}a\ bexp{\isachardoublequote}\isamarkupfalse%
    41 \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ {\isacharbar}\ Neg\ \ {\isachardoublequote}{\isacharprime}a\ bexp{\isachardoublequote}\isamarkuptrue%
    29 %
    42 %
    30 \begin{isamarkuptext}%
    43 \begin{isamarkuptext}%
    31 \noindent
    44 \noindent
    32 Type \isa{aexp} is similar to \isa{expr} in \S\ref{sec:ExprCompiler},
    45 Type \isa{aexp} is similar to \isa{expr} in \S\ref{sec:ExprCompiler},
    33 except that we have added an \isa{IF} constructor,
    46 except that we have added an \isa{IF} constructor,
    34 fixed the values to be of type \isa{nat} and declared the two binary
    47 fixed the values to be of type \isa{nat} and declared the two binary
    35 operations \isa{Sum} and \isa{Diff}.  Boolean
    48 operations \isa{Sum} and \isa{Diff}.  Boolean
    36 expressions can be arithmetic comparisons, conjunctions and negations.
    49 expressions can be arithmetic comparisons, conjunctions and negations.
    37 The semantics is given by two evaluation functions:%
    50 The semantics is given by two evaluation functions:%
    38 \end{isamarkuptext}%
    51 \end{isamarkuptext}%
    39 \isamarkuptrue%
    52 \isamarkupfalse%
    40 \isacommand{consts}\ \ evala\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequote}{\isacharprime}a\ aexp\ {\isasymRightarrow}\ {\isacharparenleft}{\isacharprime}a\ {\isasymRightarrow}\ nat{\isacharparenright}\ {\isasymRightarrow}\ nat{\isachardoublequote}\isanewline
    53 \isacommand{consts}\ \ evala\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequote}{\isacharprime}a\ aexp\ {\isasymRightarrow}\ {\isacharparenleft}{\isacharprime}a\ {\isasymRightarrow}\ nat{\isacharparenright}\ {\isasymRightarrow}\ nat{\isachardoublequote}\isanewline
    41 \ \ \ \ \ \ \ \ evalb\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequote}{\isacharprime}a\ bexp\ {\isasymRightarrow}\ {\isacharparenleft}{\isacharprime}a\ {\isasymRightarrow}\ nat{\isacharparenright}\ {\isasymRightarrow}\ bool{\isachardoublequote}\isamarkupfalse%
    54 \ \ \ \ \ \ \ \ evalb\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequote}{\isacharprime}a\ bexp\ {\isasymRightarrow}\ {\isacharparenleft}{\isacharprime}a\ {\isasymRightarrow}\ nat{\isacharparenright}\ {\isasymRightarrow}\ bool{\isachardoublequote}\isamarkuptrue%
    42 %
    55 %
    43 \begin{isamarkuptext}%
    56 \begin{isamarkuptext}%
    44 \noindent
    57 \noindent
    45 Both take an expression and an environment (a mapping from variables \isa{{\isacharprime}a} to values
    58 Both take an expression and an environment (a mapping from variables \isa{{\isacharprime}a} to values
    46 \isa{nat}) and return its arithmetic/boolean
    59 \isa{nat}) and return its arithmetic/boolean
    47 value. Since the datatypes are mutually recursive, so are functions that
    60 value. Since the datatypes are mutually recursive, so are functions that
    48 operate on them. Hence they need to be defined in a single \isacommand{primrec}
    61 operate on them. Hence they need to be defined in a single \isacommand{primrec}
    49 section:%
    62 section:%
    50 \end{isamarkuptext}%
    63 \end{isamarkuptext}%
    51 \isamarkuptrue%
    64 \isamarkupfalse%
    52 \isacommand{primrec}\isanewline
    65 \isacommand{primrec}\isanewline
    53 \ \ {\isachardoublequote}evala\ {\isacharparenleft}IF\ b\ a{\isadigit{1}}\ a{\isadigit{2}}{\isacharparenright}\ env\ {\isacharequal}\isanewline
    66 \ \ {\isachardoublequote}evala\ {\isacharparenleft}IF\ b\ a{\isadigit{1}}\ a{\isadigit{2}}{\isacharparenright}\ env\ {\isacharequal}\isanewline
    54 \ \ \ \ \ {\isacharparenleft}if\ evalb\ b\ env\ then\ evala\ a{\isadigit{1}}\ env\ else\ evala\ a{\isadigit{2}}\ env{\isacharparenright}{\isachardoublequote}\isanewline
    67 \ \ \ \ \ {\isacharparenleft}if\ evalb\ b\ env\ then\ evala\ a{\isadigit{1}}\ env\ else\ evala\ a{\isadigit{2}}\ env{\isacharparenright}{\isachardoublequote}\isanewline
    55 \ \ {\isachardoublequote}evala\ {\isacharparenleft}Sum\ a{\isadigit{1}}\ a{\isadigit{2}}{\isacharparenright}\ env\ {\isacharequal}\ evala\ a{\isadigit{1}}\ env\ {\isacharplus}\ evala\ a{\isadigit{2}}\ env{\isachardoublequote}\isanewline
    68 \ \ {\isachardoublequote}evala\ {\isacharparenleft}Sum\ a{\isadigit{1}}\ a{\isadigit{2}}{\isacharparenright}\ env\ {\isacharequal}\ evala\ a{\isadigit{1}}\ env\ {\isacharplus}\ evala\ a{\isadigit{2}}\ env{\isachardoublequote}\isanewline
    56 \ \ {\isachardoublequote}evala\ {\isacharparenleft}Diff\ a{\isadigit{1}}\ a{\isadigit{2}}{\isacharparenright}\ env\ {\isacharequal}\ evala\ a{\isadigit{1}}\ env\ {\isacharminus}\ evala\ a{\isadigit{2}}\ env{\isachardoublequote}\isanewline
    69 \ \ {\isachardoublequote}evala\ {\isacharparenleft}Diff\ a{\isadigit{1}}\ a{\isadigit{2}}{\isacharparenright}\ env\ {\isacharequal}\ evala\ a{\isadigit{1}}\ env\ {\isacharminus}\ evala\ a{\isadigit{2}}\ env{\isachardoublequote}\isanewline
    57 \ \ {\isachardoublequote}evala\ {\isacharparenleft}Var\ v{\isacharparenright}\ env\ {\isacharequal}\ env\ v{\isachardoublequote}\isanewline
    70 \ \ {\isachardoublequote}evala\ {\isacharparenleft}Var\ v{\isacharparenright}\ env\ {\isacharequal}\ env\ v{\isachardoublequote}\isanewline
    58 \ \ {\isachardoublequote}evala\ {\isacharparenleft}Num\ n{\isacharparenright}\ env\ {\isacharequal}\ n{\isachardoublequote}\isanewline
    71 \ \ {\isachardoublequote}evala\ {\isacharparenleft}Num\ n{\isacharparenright}\ env\ {\isacharequal}\ n{\isachardoublequote}\isanewline
    59 \isanewline
    72 \isanewline
    60 \ \ {\isachardoublequote}evalb\ {\isacharparenleft}Less\ a{\isadigit{1}}\ a{\isadigit{2}}{\isacharparenright}\ env\ {\isacharequal}\ {\isacharparenleft}evala\ a{\isadigit{1}}\ env\ {\isacharless}\ evala\ a{\isadigit{2}}\ env{\isacharparenright}{\isachardoublequote}\isanewline
    73 \ \ {\isachardoublequote}evalb\ {\isacharparenleft}Less\ a{\isadigit{1}}\ a{\isadigit{2}}{\isacharparenright}\ env\ {\isacharequal}\ {\isacharparenleft}evala\ a{\isadigit{1}}\ env\ {\isacharless}\ evala\ a{\isadigit{2}}\ env{\isacharparenright}{\isachardoublequote}\isanewline
    61 \ \ {\isachardoublequote}evalb\ {\isacharparenleft}And\ b{\isadigit{1}}\ b{\isadigit{2}}{\isacharparenright}\ env\ {\isacharequal}\ {\isacharparenleft}evalb\ b{\isadigit{1}}\ env\ {\isasymand}\ evalb\ b{\isadigit{2}}\ env{\isacharparenright}{\isachardoublequote}\isanewline
    74 \ \ {\isachardoublequote}evalb\ {\isacharparenleft}And\ b{\isadigit{1}}\ b{\isadigit{2}}{\isacharparenright}\ env\ {\isacharequal}\ {\isacharparenleft}evalb\ b{\isadigit{1}}\ env\ {\isasymand}\ evalb\ b{\isadigit{2}}\ env{\isacharparenright}{\isachardoublequote}\isanewline
    62 \ \ {\isachardoublequote}evalb\ {\isacharparenleft}Neg\ b{\isacharparenright}\ env\ {\isacharequal}\ {\isacharparenleft}{\isasymnot}\ evalb\ b\ env{\isacharparenright}{\isachardoublequote}\isamarkupfalse%
    75 \ \ {\isachardoublequote}evalb\ {\isacharparenleft}Neg\ b{\isacharparenright}\ env\ {\isacharequal}\ {\isacharparenleft}{\isasymnot}\ evalb\ b\ env{\isacharparenright}{\isachardoublequote}\isamarkuptrue%
    63 %
    76 %
    64 \begin{isamarkuptext}%
    77 \begin{isamarkuptext}%
    65 \noindent
    78 \noindent
    66 In the same fashion we also define two functions that perform substitution:%
    79 In the same fashion we also define two functions that perform substitution:%
    67 \end{isamarkuptext}%
    80 \end{isamarkuptext}%
    68 \isamarkuptrue%
    81 \isamarkupfalse%
    69 \isacommand{consts}\ substa\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequote}{\isacharparenleft}{\isacharprime}a\ {\isasymRightarrow}\ {\isacharprime}b\ aexp{\isacharparenright}\ {\isasymRightarrow}\ {\isacharprime}a\ aexp\ {\isasymRightarrow}\ {\isacharprime}b\ aexp{\isachardoublequote}\isanewline
    82 \isacommand{consts}\ substa\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequote}{\isacharparenleft}{\isacharprime}a\ {\isasymRightarrow}\ {\isacharprime}b\ aexp{\isacharparenright}\ {\isasymRightarrow}\ {\isacharprime}a\ aexp\ {\isasymRightarrow}\ {\isacharprime}b\ aexp{\isachardoublequote}\isanewline
    70 \ \ \ \ \ \ \ substb\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequote}{\isacharparenleft}{\isacharprime}a\ {\isasymRightarrow}\ {\isacharprime}b\ aexp{\isacharparenright}\ {\isasymRightarrow}\ {\isacharprime}a\ bexp\ {\isasymRightarrow}\ {\isacharprime}b\ bexp{\isachardoublequote}\isamarkupfalse%
    83 \ \ \ \ \ \ \ substb\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequote}{\isacharparenleft}{\isacharprime}a\ {\isasymRightarrow}\ {\isacharprime}b\ aexp{\isacharparenright}\ {\isasymRightarrow}\ {\isacharprime}a\ bexp\ {\isasymRightarrow}\ {\isacharprime}b\ bexp{\isachardoublequote}\isamarkuptrue%
    71 %
    84 %
    72 \begin{isamarkuptext}%
    85 \begin{isamarkuptext}%
    73 \noindent
    86 \noindent
    74 The first argument is a function mapping variables to expressions, the
    87 The first argument is a function mapping variables to expressions, the
    75 substitution. It is applied to all variables in the second argument. As a
    88 substitution. It is applied to all variables in the second argument. As a
    76 result, the type of variables in the expression may change from \isa{{\isacharprime}a}
    89 result, the type of variables in the expression may change from \isa{{\isacharprime}a}
    77 to \isa{{\isacharprime}b}. Note that there are only arithmetic and no boolean variables.%
    90 to \isa{{\isacharprime}b}. Note that there are only arithmetic and no boolean variables.%
    78 \end{isamarkuptext}%
    91 \end{isamarkuptext}%
    79 \isamarkuptrue%
    92 \isamarkupfalse%
    80 \isacommand{primrec}\isanewline
    93 \isacommand{primrec}\isanewline
    81 \ \ {\isachardoublequote}substa\ s\ {\isacharparenleft}IF\ b\ a{\isadigit{1}}\ a{\isadigit{2}}{\isacharparenright}\ {\isacharequal}\isanewline
    94 \ \ {\isachardoublequote}substa\ s\ {\isacharparenleft}IF\ b\ a{\isadigit{1}}\ a{\isadigit{2}}{\isacharparenright}\ {\isacharequal}\isanewline
    82 \ \ \ \ \ IF\ {\isacharparenleft}substb\ s\ b{\isacharparenright}\ {\isacharparenleft}substa\ s\ a{\isadigit{1}}{\isacharparenright}\ {\isacharparenleft}substa\ s\ a{\isadigit{2}}{\isacharparenright}{\isachardoublequote}\isanewline
    95 \ \ \ \ \ IF\ {\isacharparenleft}substb\ s\ b{\isacharparenright}\ {\isacharparenleft}substa\ s\ a{\isadigit{1}}{\isacharparenright}\ {\isacharparenleft}substa\ s\ a{\isadigit{2}}{\isacharparenright}{\isachardoublequote}\isanewline
    83 \ \ {\isachardoublequote}substa\ s\ {\isacharparenleft}Sum\ a{\isadigit{1}}\ a{\isadigit{2}}{\isacharparenright}\ {\isacharequal}\ Sum\ {\isacharparenleft}substa\ s\ a{\isadigit{1}}{\isacharparenright}\ {\isacharparenleft}substa\ s\ a{\isadigit{2}}{\isacharparenright}{\isachardoublequote}\isanewline
    96 \ \ {\isachardoublequote}substa\ s\ {\isacharparenleft}Sum\ a{\isadigit{1}}\ a{\isadigit{2}}{\isacharparenright}\ {\isacharequal}\ Sum\ {\isacharparenleft}substa\ s\ a{\isadigit{1}}{\isacharparenright}\ {\isacharparenleft}substa\ s\ a{\isadigit{2}}{\isacharparenright}{\isachardoublequote}\isanewline
    84 \ \ {\isachardoublequote}substa\ s\ {\isacharparenleft}Diff\ a{\isadigit{1}}\ a{\isadigit{2}}{\isacharparenright}\ {\isacharequal}\ Diff\ {\isacharparenleft}substa\ s\ a{\isadigit{1}}{\isacharparenright}\ {\isacharparenleft}substa\ s\ a{\isadigit{2}}{\isacharparenright}{\isachardoublequote}\isanewline
    97 \ \ {\isachardoublequote}substa\ s\ {\isacharparenleft}Diff\ a{\isadigit{1}}\ a{\isadigit{2}}{\isacharparenright}\ {\isacharequal}\ Diff\ {\isacharparenleft}substa\ s\ a{\isadigit{1}}{\isacharparenright}\ {\isacharparenleft}substa\ s\ a{\isadigit{2}}{\isacharparenright}{\isachardoublequote}\isanewline
    85 \ \ {\isachardoublequote}substa\ s\ {\isacharparenleft}Var\ v{\isacharparenright}\ {\isacharequal}\ s\ v{\isachardoublequote}\isanewline
    98 \ \ {\isachardoublequote}substa\ s\ {\isacharparenleft}Var\ v{\isacharparenright}\ {\isacharequal}\ s\ v{\isachardoublequote}\isanewline
    86 \ \ {\isachardoublequote}substa\ s\ {\isacharparenleft}Num\ n{\isacharparenright}\ {\isacharequal}\ Num\ n{\isachardoublequote}\isanewline
    99 \ \ {\isachardoublequote}substa\ s\ {\isacharparenleft}Num\ n{\isacharparenright}\ {\isacharequal}\ Num\ n{\isachardoublequote}\isanewline
    87 \isanewline
   100 \isanewline
    88 \ \ {\isachardoublequote}substb\ s\ {\isacharparenleft}Less\ a{\isadigit{1}}\ a{\isadigit{2}}{\isacharparenright}\ {\isacharequal}\ Less\ {\isacharparenleft}substa\ s\ a{\isadigit{1}}{\isacharparenright}\ {\isacharparenleft}substa\ s\ a{\isadigit{2}}{\isacharparenright}{\isachardoublequote}\isanewline
   101 \ \ {\isachardoublequote}substb\ s\ {\isacharparenleft}Less\ a{\isadigit{1}}\ a{\isadigit{2}}{\isacharparenright}\ {\isacharequal}\ Less\ {\isacharparenleft}substa\ s\ a{\isadigit{1}}{\isacharparenright}\ {\isacharparenleft}substa\ s\ a{\isadigit{2}}{\isacharparenright}{\isachardoublequote}\isanewline
    89 \ \ {\isachardoublequote}substb\ s\ {\isacharparenleft}And\ b{\isadigit{1}}\ b{\isadigit{2}}{\isacharparenright}\ {\isacharequal}\ And\ {\isacharparenleft}substb\ s\ b{\isadigit{1}}{\isacharparenright}\ {\isacharparenleft}substb\ s\ b{\isadigit{2}}{\isacharparenright}{\isachardoublequote}\isanewline
   102 \ \ {\isachardoublequote}substb\ s\ {\isacharparenleft}And\ b{\isadigit{1}}\ b{\isadigit{2}}{\isacharparenright}\ {\isacharequal}\ And\ {\isacharparenleft}substb\ s\ b{\isadigit{1}}{\isacharparenright}\ {\isacharparenleft}substb\ s\ b{\isadigit{2}}{\isacharparenright}{\isachardoublequote}\isanewline
    90 \ \ {\isachardoublequote}substb\ s\ {\isacharparenleft}Neg\ b{\isacharparenright}\ {\isacharequal}\ Neg\ {\isacharparenleft}substb\ s\ b{\isacharparenright}{\isachardoublequote}\isamarkupfalse%
   103 \ \ {\isachardoublequote}substb\ s\ {\isacharparenleft}Neg\ b{\isacharparenright}\ {\isacharequal}\ Neg\ {\isacharparenleft}substb\ s\ b{\isacharparenright}{\isachardoublequote}\isamarkuptrue%
    91 %
   104 %
    92 \begin{isamarkuptext}%
   105 \begin{isamarkuptext}%
    93 Now we can prove a fundamental theorem about the interaction between
   106 Now we can prove a fundamental theorem about the interaction between
    94 evaluation and substitution: applying a substitution $s$ to an expression $a$
   107 evaluation and substitution: applying a substitution $s$ to an expression $a$
    95 and evaluating the result in an environment $env$ yields the same result as
   108 and evaluating the result in an environment $env$ yields the same result as
    97 of $s(x)$ under $env$. If you try to prove this separately for arithmetic or
   110 of $s(x)$ under $env$. If you try to prove this separately for arithmetic or
    98 boolean expressions (by induction), you find that you always need the other
   111 boolean expressions (by induction), you find that you always need the other
    99 theorem in the induction step. Therefore you need to state and prove both
   112 theorem in the induction step. Therefore you need to state and prove both
   100 theorems simultaneously:%
   113 theorems simultaneously:%
   101 \end{isamarkuptext}%
   114 \end{isamarkuptext}%
   102 \isamarkuptrue%
   115 \isamarkupfalse%
   103 \isacommand{lemma}\ {\isachardoublequote}evala\ {\isacharparenleft}substa\ s\ a{\isacharparenright}\ env\ {\isacharequal}\ evala\ a\ {\isacharparenleft}{\isasymlambda}x{\isachardot}\ evala\ {\isacharparenleft}s\ x{\isacharparenright}\ env{\isacharparenright}\ {\isasymand}\isanewline
   116 \isacommand{lemma}\ {\isachardoublequote}evala\ {\isacharparenleft}substa\ s\ a{\isacharparenright}\ env\ {\isacharequal}\ evala\ a\ {\isacharparenleft}{\isasymlambda}x{\isachardot}\ evala\ {\isacharparenleft}s\ x{\isacharparenright}\ env{\isacharparenright}\ {\isasymand}\isanewline
   104 \ \ \ \ \ \ \ \ evalb\ {\isacharparenleft}substb\ s\ b{\isacharparenright}\ env\ {\isacharequal}\ evalb\ b\ {\isacharparenleft}{\isasymlambda}x{\isachardot}\ evala\ {\isacharparenleft}s\ x{\isacharparenright}\ env{\isacharparenright}{\isachardoublequote}\isanewline
   117 \ \ \ \ \ \ \ \ evalb\ {\isacharparenleft}substb\ s\ b{\isacharparenright}\ env\ {\isacharequal}\ evalb\ b\ {\isacharparenleft}{\isasymlambda}x{\isachardot}\ evala\ {\isacharparenleft}s\ x{\isacharparenright}\ env{\isacharparenright}{\isachardoublequote}\isanewline
   105 \isamarkupfalse%
   118 %
   106 \isacommand{apply}{\isacharparenleft}induct{\isacharunderscore}tac\ a\ \isakeyword{and}\ b{\isacharparenright}\isamarkupfalse%
   119 \isadelimproof
       
   120 %
       
   121 \endisadelimproof
       
   122 %
       
   123 \isatagproof
       
   124 \isamarkupfalse%
       
   125 \isacommand{apply}{\isacharparenleft}induct{\isacharunderscore}tac\ a\ \isakeyword{and}\ b{\isacharparenright}\isamarkuptrue%
   107 %
   126 %
   108 \begin{isamarkuptxt}%
   127 \begin{isamarkuptxt}%
   109 \noindent
   128 \noindent
   110 The resulting 8 goals (one for each constructor) are proved in one fell swoop:%
   129 The resulting 8 goals (one for each constructor) are proved in one fell swoop:%
   111 \end{isamarkuptxt}%
   130 \end{isamarkuptxt}%
       
   131 \isamarkupfalse%
       
   132 \isacommand{apply}\ simp{\isacharunderscore}all%
       
   133 \endisatagproof
       
   134 {\isafoldproof}%
       
   135 %
       
   136 \isadelimproof
       
   137 %
       
   138 \endisadelimproof
   112 \isamarkuptrue%
   139 \isamarkuptrue%
   113 \isacommand{apply}\ simp{\isacharunderscore}all\isamarkupfalse%
       
   114 \isamarkupfalse%
       
   115 %
   140 %
   116 \begin{isamarkuptext}%
   141 \begin{isamarkuptext}%
   117 In general, given $n$ mutually recursive datatypes $\tau@1$, \dots, $\tau@n$,
   142 In general, given $n$ mutually recursive datatypes $\tau@1$, \dots, $\tau@n$,
   118 an inductive proof expects a goal of the form
   143 an inductive proof expects a goal of the form
   119 \[ P@1(x@1)\ \land \dots \land P@n(x@n) \]
   144 \[ P@1(x@1)\ \land \dots \land P@n(x@n) \]
   132   is really normal, i.e.\ no more \isa{And}s and \isa{Neg}s occur in
   157   is really normal, i.e.\ no more \isa{And}s and \isa{Neg}s occur in
   133   it.  ({\em Hint:} proceed as in \S\ref{sec:boolex} and read the discussion
   158   it.  ({\em Hint:} proceed as in \S\ref{sec:boolex} and read the discussion
   134   of type annotations following lemma \isa{subst{\isacharunderscore}id} below).
   159   of type annotations following lemma \isa{subst{\isacharunderscore}id} below).
   135 \end{exercise}%
   160 \end{exercise}%
   136 \end{isamarkuptext}%
   161 \end{isamarkuptext}%
   137 \isamarkuptrue%
   162 %
   138 \isamarkupfalse%
   163 \isadelimproof
   139 \isamarkupfalse%
   164 %
   140 \isamarkupfalse%
   165 \endisadelimproof
   141 \isamarkupfalse%
   166 %
   142 \isamarkupfalse%
   167 \isatagproof
   143 \isamarkupfalse%
   168 %
   144 \isamarkupfalse%
   169 \endisatagproof
   145 \isamarkupfalse%
   170 {\isafoldproof}%
   146 \isamarkupfalse%
   171 %
   147 \isamarkupfalse%
   172 \isadelimproof
   148 \isamarkupfalse%
   173 %
   149 \isamarkupfalse%
   174 \endisadelimproof
   150 \isamarkupfalse%
   175 %
       
   176 \isadelimproof
       
   177 %
       
   178 \endisadelimproof
       
   179 %
       
   180 \isatagproof
       
   181 %
       
   182 \endisatagproof
       
   183 {\isafoldproof}%
       
   184 %
       
   185 \isadelimproof
       
   186 %
       
   187 \endisadelimproof
       
   188 %
       
   189 \isadelimtheory
       
   190 %
       
   191 \endisadelimtheory
       
   192 %
       
   193 \isatagtheory
       
   194 %
       
   195 \endisatagtheory
       
   196 {\isafoldtheory}%
       
   197 %
       
   198 \isadelimtheory
       
   199 %
       
   200 \endisadelimtheory
   151 \end{isabellebody}%
   201 \end{isabellebody}%
   152 %%% Local Variables:
   202 %%% Local Variables:
   153 %%% mode: latex
   203 %%% mode: latex
   154 %%% TeX-master: "root"
   204 %%% TeX-master: "root"
   155 %%% End:
   205 %%% End: