doc-src/TutorialI/Inductive/advanced-examples.tex
author chaieb
Wed, 19 May 2004 11:23:59 +0200
changeset 14758 af3b71a46a1c
parent 12333 ef43a3d6e962
permissions -rw-r--r--
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller. the tactic has also changed and allows the abstaction over fuction occurences whose type is nat or int.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10879
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
     1
% $Id$
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
     2
The premises of introduction rules may contain universal quantifiers and
11173
094b76968484 revisions in response to comments by Tobias
paulson
parents: 11147
diff changeset
     3
monotone functions.  A universal quantifier lets the rule 
094b76968484 revisions in response to comments by Tobias
paulson
parents: 11147
diff changeset
     4
refer to any number of instances of 
094b76968484 revisions in response to comments by Tobias
paulson
parents: 11147
diff changeset
     5
the inductively defined set.  A monotone function lets the rule refer
094b76968484 revisions in response to comments by Tobias
paulson
parents: 11147
diff changeset
     6
to existing constructions (such as ``list of'') over the inductively defined
094b76968484 revisions in response to comments by Tobias
paulson
parents: 11147
diff changeset
     7
set.  The examples below show how to use the additional expressiveness
094b76968484 revisions in response to comments by Tobias
paulson
parents: 11147
diff changeset
     8
and how to reason from the resulting definitions.
10879
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
     9
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
    10
\subsection{Universal Quantifiers in Introduction Rules}
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
    11
\label{sec:gterm-datatype}
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
    12
11411
c315dda16748 indexing
paulson
parents: 11261
diff changeset
    13
\index{ground terms example|(}%
c315dda16748 indexing
paulson
parents: 11261
diff changeset
    14
\index{quantifiers!and inductive definitions|(}%
10879
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
    15
As a running example, this section develops the theory of \textbf{ground
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
    16
terms}: terms constructed from constant and function 
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
    17
symbols but not variables. To simplify matters further, we regard a
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
    18
constant as a function applied to the null argument  list.  Let us declare a
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
    19
datatype \isa{gterm} for the type of ground  terms. It is a type constructor
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
    20
whose argument is a type of  function symbols. 
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
    21
\begin{isabelle}
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
    22
\isacommand{datatype}\ 'f\ gterm\ =\ Apply\ 'f\ "'f\ gterm\ list"
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
    23
\end{isabelle}
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
    24
To try it out, we declare a datatype of some integer operations: 
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
    25
integer constants, the unary minus operator and the addition 
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
    26
operator. 
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
    27
\begin{isabelle}
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
    28
\isacommand{datatype}\ integer_op\ =\ Number\ int\ |\ UnaryMinus\ |\ Plus
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
    29
\end{isabelle}
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
    30
Now the type \isa{integer\_op gterm} denotes the ground 
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
    31
terms built over those symbols.
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
    32
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
    33
The type constructor \texttt{gterm} can be generalized to a function 
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
    34
over sets.  It returns 
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
    35
the set of ground terms that can be formed over a set \isa{F} of function symbols. For
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
    36
example,  we could consider the set of ground terms formed from the finite 
10889
aed0a0450797 wrong font for braces
paulson
parents: 10879
diff changeset
    37
set \isa{\isacharbraceleft Number 2, UnaryMinus,
aed0a0450797 wrong font for braces
paulson
parents: 10879
diff changeset
    38
Plus\isacharbraceright}.
10879
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
    39
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
    40
This concept is inductive. If we have a list \isa{args} of ground terms 
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
    41
over~\isa{F} and a function symbol \isa{f} in \isa{F}, then we 
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
    42
can apply \isa{f} to  \isa{args} to obtain another ground term. 
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
    43
The only difficulty is that the argument list may be of any length. Hitherto, 
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
    44
each rule in an inductive definition referred to the inductively 
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
    45
defined set a fixed number of times, typically once or twice. 
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
    46
A universal quantifier in the premise of the introduction rule 
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
    47
expresses that every element of \isa{args} belongs
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
    48
to our inductively defined set: is a ground term 
11173
094b76968484 revisions in response to comments by Tobias
paulson
parents: 11147
diff changeset
    49
over~\isa{F}.  The function \isa{set} denotes the set of elements in a given 
10879
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
    50
list. 
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
    51
\begin{isabelle}
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
    52
\isacommand{consts}\ gterms\ ::\ "'f\ set\ \isasymRightarrow \ 'f\ gterm\ set"\isanewline
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
    53
\isacommand{inductive}\ "gterms\ F"\isanewline
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
    54
\isakeyword{intros}\isanewline
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
    55
step[intro!]:\ "\isasymlbrakk \isasymforall t\ \isasymin \ set\ args.\ t\ \isasymin \ gterms\ F;\ \ f\ \isasymin \ F\isasymrbrakk \isanewline
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
    56
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \isasymLongrightarrow \ (Apply\ f\ args)\ \isasymin \ gterms\
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
    57
F"
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
    58
\end{isabelle}
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
    59
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
    60
To demonstrate a proof from this definition, let us 
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
    61
show that the function \isa{gterms}
11173
094b76968484 revisions in response to comments by Tobias
paulson
parents: 11147
diff changeset
    62
is \textbf{monotone}.  We shall need this concept shortly.
10879
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
    63
\begin{isabelle}
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
    64
\isacommand{lemma}\ gterms_mono:\ "F\isasymsubseteq G\ \isasymLongrightarrow \ gterms\ F\ \isasymsubseteq \ gterms\ G"\isanewline
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
    65
\isacommand{apply}\ clarify\isanewline
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
    66
\isacommand{apply}\ (erule\ gterms.induct)\isanewline
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
    67
\isacommand{apply}\ blast\isanewline
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
    68
\isacommand{done}
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
    69
\end{isabelle}
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
    70
Intuitively, this theorem says that
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
    71
enlarging the set of function symbols enlarges the set of ground 
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
    72
terms. The proof is a trivial rule induction.
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
    73
First we use the \isa{clarify} method to assume the existence of an element of
11147
d848c6693185 *** empty log message ***
nipkow
parents: 10978
diff changeset
    74
\isa{gterms~F}.  (We could have used \isa{intro subsetI}.)  We then
10879
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
    75
apply rule induction. Here is the resulting subgoal: 
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
    76
\begin{isabelle}
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
    77
\ 1.\ \isasymAnd x\ args\ f.\isanewline
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
    78
\ \ \ \ \ \ \ \isasymlbrakk F\ \isasymsubseteq \ G;\ \isasymforall t\isasymin set\ args.\ t\ \isasymin \ gterms\ F\ \isasymand \ t\ \isasymin \ gterms\ G;\ f\ \isasymin \ F\isasymrbrakk \isanewline
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
    79
\ \ \ \ \ \ \ \isasymLongrightarrow \ Apply\ f\ args\ \isasymin \ gterms\ G%
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
    80
\end{isabelle}
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
    81
%
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
    82
The assumptions state that \isa{f} belongs 
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
    83
to~\isa{F}, which is included in~\isa{G}, and that every element of the list \isa{args} is
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
    84
a ground term over~\isa{G}.  The \isa{blast} method finds this chain of reasoning easily.  
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
    85
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
    86
\begin{warn}
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
    87
Why do we call this function \isa{gterms} instead 
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
    88
of {\isa{gterm}}?  A constant may have the same name as a type.  However,
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
    89
name  clashes could arise in the theorems that Isabelle generates. 
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
    90
Our choice of names keeps {\isa{gterms.induct}} separate from 
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
    91
{\isa{gterm.induct}}.
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
    92
\end{warn}
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
    93
11173
094b76968484 revisions in response to comments by Tobias
paulson
parents: 11147
diff changeset
    94
Call a term \textbf{well-formed} if each symbol occurring in it is applied
094b76968484 revisions in response to comments by Tobias
paulson
parents: 11147
diff changeset
    95
to the correct number of arguments.  (This number is called the symbol's
094b76968484 revisions in response to comments by Tobias
paulson
parents: 11147
diff changeset
    96
\textbf{arity}.)  We can express well-formedness by
094b76968484 revisions in response to comments by Tobias
paulson
parents: 11147
diff changeset
    97
generalizing the inductive definition of
094b76968484 revisions in response to comments by Tobias
paulson
parents: 11147
diff changeset
    98
\isa{gterms}.
094b76968484 revisions in response to comments by Tobias
paulson
parents: 11147
diff changeset
    99
Suppose we are given a function called \isa{arity}, specifying the arities
094b76968484 revisions in response to comments by Tobias
paulson
parents: 11147
diff changeset
   100
of all symbols.  In the inductive step, we have a list \isa{args} of such
094b76968484 revisions in response to comments by Tobias
paulson
parents: 11147
diff changeset
   101
terms and a function  symbol~\isa{f}. If the length of the list matches the
094b76968484 revisions in response to comments by Tobias
paulson
parents: 11147
diff changeset
   102
function's arity  then applying \isa{f} to \isa{args} yields a well-formed
094b76968484 revisions in response to comments by Tobias
paulson
parents: 11147
diff changeset
   103
term. 
10879
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   104
\begin{isabelle}
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   105
\isacommand{consts}\ well_formed_gterm\ ::\ "('f\ \isasymRightarrow \ nat)\ \isasymRightarrow \ 'f\ gterm\ set"\isanewline
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   106
\isacommand{inductive}\ "well_formed_gterm\ arity"\isanewline
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   107
\isakeyword{intros}\isanewline
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   108
step[intro!]:\ "\isasymlbrakk \isasymforall t\ \isasymin \ set\ args.\ t\ \isasymin \ well_formed_gterm\ arity;\ \ \isanewline
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   109
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ length\ args\ =\ arity\ f\isasymrbrakk \isanewline
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   110
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \isasymLongrightarrow \ (Apply\ f\ args)\ \isasymin \ well_formed_gterm\
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   111
arity"
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   112
\end{isabelle}
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   113
%
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   114
The inductive definition neatly captures the reasoning above.
11173
094b76968484 revisions in response to comments by Tobias
paulson
parents: 11147
diff changeset
   115
The universal quantification over the
11411
c315dda16748 indexing
paulson
parents: 11261
diff changeset
   116
\isa{set} of arguments expresses that all of them are well-formed.%
c315dda16748 indexing
paulson
parents: 11261
diff changeset
   117
\index{quantifiers!and inductive definitions|)}
10879
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   118
11173
094b76968484 revisions in response to comments by Tobias
paulson
parents: 11147
diff changeset
   119
11216
279004936bb0 *** empty log message ***
nipkow
parents: 11173
diff changeset
   120
\subsection{Alternative Definition Using a Monotone Function}
10879
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   121
11411
c315dda16748 indexing
paulson
parents: 11261
diff changeset
   122
\index{monotone functions!and inductive definitions|(}% 
c315dda16748 indexing
paulson
parents: 11261
diff changeset
   123
An inductive definition may refer to the
c315dda16748 indexing
paulson
parents: 11261
diff changeset
   124
inductively defined  set through an arbitrary monotone function.  To
c315dda16748 indexing
paulson
parents: 11261
diff changeset
   125
demonstrate this powerful feature, let us
10879
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   126
change the  inductive definition above, replacing the
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   127
quantifier by a use of the function \isa{lists}. This
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   128
function, from the Isabelle theory of lists, is analogous to the
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   129
function \isa{gterms} declared above: if \isa{A} is a set then
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   130
{\isa{lists A}} is the set of lists whose elements belong to
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   131
\isa{A}.  
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   132
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   133
In the inductive definition of well-formed terms, examine the one
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   134
introduction rule.  The first premise states that \isa{args} belongs to
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   135
the \isa{lists} of well-formed terms.  This formulation is more
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   136
direct, if more obscure, than using a universal quantifier.
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   137
\begin{isabelle}
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   138
\isacommand{consts}\ well_formed_gterm'\ ::\ "('f\ \isasymRightarrow \ nat)\ \isasymRightarrow \ 'f\ gterm\ set"\isanewline
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   139
\isacommand{inductive}\ "well_formed_gterm'\ arity"\isanewline
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   140
\isakeyword{intros}\isanewline
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   141
step[intro!]:\ "\isasymlbrakk args\ \isasymin \ lists\ (well_formed_gterm'\ arity);\ \ \isanewline
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   142
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ length\ args\ =\ arity\ f\isasymrbrakk \isanewline
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   143
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \isasymLongrightarrow \ (Apply\ f\ args)\ \isasymin \ well_formed_gterm'\ arity"\isanewline
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   144
\isakeyword{monos}\ lists_mono
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   145
\end{isabelle}
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   146
12333
ef43a3d6e962 minor tweaks
paulson
parents: 11421
diff changeset
   147
We cite the theorem \isa{lists_mono} to justify 
ef43a3d6e962 minor tweaks
paulson
parents: 11421
diff changeset
   148
using the function \isa{lists}.%
ef43a3d6e962 minor tweaks
paulson
parents: 11421
diff changeset
   149
\footnote{This particular theorem is installed by default already, but we
ef43a3d6e962 minor tweaks
paulson
parents: 11421
diff changeset
   150
include the \isakeyword{monos} declaration in order to illustrate its syntax.}
10879
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   151
\begin{isabelle}
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   152
A\ \isasymsubseteq\ B\ \isasymLongrightarrow \ lists\ A\ \isasymsubseteq
11421
paulson
parents: 11411
diff changeset
   153
\ lists\ B\rulenamedx{lists_mono}
10879
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   154
\end{isabelle}
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   155
%
11173
094b76968484 revisions in response to comments by Tobias
paulson
parents: 11147
diff changeset
   156
Why must the function be monotone?  An inductive definition describes
10879
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   157
an iterative construction: each element of the set is constructed by a
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   158
finite number of introduction rule applications.  For example, the
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   159
elements of \isa{even} are constructed by finitely many applications of
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   160
the rules 
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   161
\begin{isabelle}
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   162
0\ \isasymin \ even\isanewline
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   163
n\ \isasymin \ even\ \isasymLongrightarrow \ (Suc\ (Suc\ n))\ \isasymin
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   164
\ even
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   165
\end{isabelle}
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   166
All references to a set in its
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   167
inductive definition must be positive.  Applications of an
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   168
introduction rule cannot invalidate previous applications, allowing the
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   169
construction process to converge.
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   170
The following pair of rules do not constitute an inductive definition:
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   171
\begin{isabelle}
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   172
0\ \isasymin \ even\isanewline
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   173
n\ \isasymnotin \ even\ \isasymLongrightarrow \ (Suc\ n)\ \isasymin
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   174
\ even
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   175
\end{isabelle}
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   176
%
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   177
Showing that 4 is even using these rules requires showing that 3 is not
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   178
even.  It is far from trivial to show that this set of rules
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   179
characterizes the even numbers.  
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   180
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   181
Even with its use of the function \isa{lists}, the premise of our
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   182
introduction rule is positive:
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   183
\begin{isabelle}
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   184
args\ \isasymin \ lists\ (well_formed_gterm'\ arity)
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   185
\end{isabelle}
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   186
To apply the rule we construct a list \isa{args} of previously
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   187
constructed well-formed terms.  We obtain a
11173
094b76968484 revisions in response to comments by Tobias
paulson
parents: 11147
diff changeset
   188
new term, \isa{Apply\ f\ args}.  Because \isa{lists} is monotone,
10879
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   189
applications of the rule remain valid as new terms are constructed.
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   190
Further lists of well-formed
11411
c315dda16748 indexing
paulson
parents: 11261
diff changeset
   191
terms become available and none are taken away.%
c315dda16748 indexing
paulson
parents: 11261
diff changeset
   192
\index{monotone functions!and inductive definitions|)} 
10879
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   193
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   194
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   195
\subsection{A Proof of Equivalence}
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   196
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   197
We naturally hope that these two inductive definitions of ``well-formed'' 
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   198
coincide.  The equality can be proved by separate inclusions in 
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   199
each direction.  Each is a trivial rule induction. 
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   200
\begin{isabelle}
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   201
\isacommand{lemma}\ "well_formed_gterm\ arity\ \isasymsubseteq \ well_formed_gterm'\ arity"\isanewline
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   202
\isacommand{apply}\ clarify\isanewline
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   203
\isacommand{apply}\ (erule\ well_formed_gterm.induct)\isanewline
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   204
\isacommand{apply}\ auto\isanewline
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   205
\isacommand{done}
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   206
\end{isabelle}
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   207
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   208
The \isa{clarify} method gives
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   209
us an element of \isa{well_formed_gterm\ arity} on which to perform 
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   210
induction.  The resulting subgoal can be proved automatically:
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   211
\begin{isabelle}
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   212
{\isadigit{1}}{\isachardot}\ {\isasymAnd}x\ args\ f{\isachardot}\isanewline
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   213
\ \ \ \ \ \ {\isasymlbrakk}{\isasymforall}t{\isasymin}set\ args{\isachardot}\isanewline
11421
paulson
parents: 11411
diff changeset
   214
\ \ \ \ \ \ \ \ \ \ t\ {\isasymin}\ well\_formed\_gterm\ arity\ {\isasymand}\ t\ {\isasymin}\ well\_formed\_gterm{\isacharprime}\ arity{\isacharsemicolon}\isanewline
10879
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   215
\ \ \ \ \ \ \ length\ args\ {\isacharequal}\ arity\ f{\isasymrbrakk}\isanewline
11421
paulson
parents: 11411
diff changeset
   216
\ \ \ \ \ \ {\isasymLongrightarrow}\ Apply\ f\ args\ {\isasymin}\ well\_formed\_gterm{\isacharprime}\ arity%
10879
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   217
\end{isabelle}
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   218
%
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   219
This proof resembles the one given in
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   220
{\S}\ref{sec:gterm-datatype} above, especially in the form of the
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   221
induction hypothesis.  Next, we consider the opposite inclusion:
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   222
\begin{isabelle}
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   223
\isacommand{lemma}\ "well_formed_gterm'\ arity\ \isasymsubseteq \ well_formed_gterm\ arity"\isanewline
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   224
\isacommand{apply}\ clarify\isanewline
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   225
\isacommand{apply}\ (erule\ well_formed_gterm'.induct)\isanewline
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   226
\isacommand{apply}\ auto\isanewline
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   227
\isacommand{done}
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   228
\end{isabelle}
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   229
%
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   230
The proof script is identical, but the subgoal after applying induction may
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   231
be surprising:
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   232
\begin{isabelle}
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   233
1.\ \isasymAnd x\ args\ f.\isanewline
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   234
\ \ \ \ \ \ \isasymlbrakk args\ \isasymin \ lists\ (well_formed_gterm'\ arity\ \isasyminter\isanewline
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   235
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \isacharbraceleft u.\ u\ \isasymin \ well_formed_gterm\ arity\isacharbraceright );\isanewline
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   236
\ \ \ \ \ \ \ length\ args\ =\ arity\ f\isasymrbrakk \isanewline
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   237
\ \ \ \ \ \ \isasymLongrightarrow \ Apply\ f\ args\ \isasymin \ well_formed_gterm\ arity%
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   238
\end{isabelle}
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   239
The induction hypothesis contains an application of \isa{lists}.  Using a
11173
094b76968484 revisions in response to comments by Tobias
paulson
parents: 11147
diff changeset
   240
monotone function in the inductive definition always has this effect.  The
094b76968484 revisions in response to comments by Tobias
paulson
parents: 11147
diff changeset
   241
subgoal may look uninviting, but fortunately 
094b76968484 revisions in response to comments by Tobias
paulson
parents: 11147
diff changeset
   242
\isa{lists} distributes over intersection:
10879
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   243
\begin{isabelle}
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   244
lists\ (A\ \isasyminter \ B)\ =\ lists\ A\ \isasyminter \ lists\ B
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   245
\rulename{lists_Int_eq}
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   246
\end{isabelle}
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   247
%
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   248
Thanks to this default simplification rule, the induction hypothesis 
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   249
is quickly replaced by its two parts:
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   250
\begin{isabelle}
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   251
\ \ \ \ \ \ \ args\ \isasymin \ lists\ (well_formed_gterm'\ arity)\isanewline
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   252
\ \ \ \ \ \ \ args\ \isasymin \ lists\ (well_formed_gterm\ arity)
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   253
\end{isabelle}
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   254
Invoking the rule \isa{well_formed_gterm.step} completes the proof.  The
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   255
call to
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   256
\isa{auto} does all this work.
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   257
11411
c315dda16748 indexing
paulson
parents: 11261
diff changeset
   258
This example is typical of how monotone functions
c315dda16748 indexing
paulson
parents: 11261
diff changeset
   259
\index{monotone functions} can be used.  In particular, many of them
c315dda16748 indexing
paulson
parents: 11261
diff changeset
   260
distribute over intersection.  Monotonicity implies one direction of
c315dda16748 indexing
paulson
parents: 11261
diff changeset
   261
this set equality; we have this theorem:
10879
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   262
\begin{isabelle}
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   263
mono\ f\ \isasymLongrightarrow \ f\ (A\ \isasyminter \ B)\ \isasymsubseteq \
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   264
f\ A\ \isasyminter \ f\ B%
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   265
\rulename{mono_Int}
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   266
\end{isabelle}
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   267
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   268
11173
094b76968484 revisions in response to comments by Tobias
paulson
parents: 11147
diff changeset
   269
\subsection{Another Example of Rule Inversion}
094b76968484 revisions in response to comments by Tobias
paulson
parents: 11147
diff changeset
   270
11411
c315dda16748 indexing
paulson
parents: 11261
diff changeset
   271
\index{rule inversion|(}%
11173
094b76968484 revisions in response to comments by Tobias
paulson
parents: 11147
diff changeset
   272
Does \isa{gterms} distribute over intersection?  We have proved that this
094b76968484 revisions in response to comments by Tobias
paulson
parents: 11147
diff changeset
   273
function is monotone, so \isa{mono_Int} gives one of the inclusions.  The
094b76968484 revisions in response to comments by Tobias
paulson
parents: 11147
diff changeset
   274
opposite inclusion asserts that if \isa{t} is a ground term over both of the
094b76968484 revisions in response to comments by Tobias
paulson
parents: 11147
diff changeset
   275
sets
094b76968484 revisions in response to comments by Tobias
paulson
parents: 11147
diff changeset
   276
\isa{F} and~\isa{G} then it is also a ground term over their intersection,
094b76968484 revisions in response to comments by Tobias
paulson
parents: 11147
diff changeset
   277
\isa{F\isasyminter G}.
11261
51bcafc7bfca suggestions from OHeimb
paulson
parents: 11216
diff changeset
   278
\begin{isabelle}
51bcafc7bfca suggestions from OHeimb
paulson
parents: 11216
diff changeset
   279
\isacommand{lemma}\ gterms_IntI:\isanewline
51bcafc7bfca suggestions from OHeimb
paulson
parents: 11216
diff changeset
   280
\ \ \ \ \ "t\ \isasymin \ gterms\ F\ \isasymLongrightarrow \ t\ \isasymin \ gterms\ G\ \isasymlongrightarrow \ t\ \isasymin \ gterms\ (F\isasyminter
51bcafc7bfca suggestions from OHeimb
paulson
parents: 11216
diff changeset
   281
G)"
51bcafc7bfca suggestions from OHeimb
paulson
parents: 11216
diff changeset
   282
\end{isabelle}
11173
094b76968484 revisions in response to comments by Tobias
paulson
parents: 11147
diff changeset
   283
Attempting this proof, we get the assumption 
11261
51bcafc7bfca suggestions from OHeimb
paulson
parents: 11216
diff changeset
   284
\isa{Apply\ f\ args\ \isasymin\ gterms\ G}, which cannot be broken down. 
11173
094b76968484 revisions in response to comments by Tobias
paulson
parents: 11147
diff changeset
   285
It looks like a job for rule inversion:
094b76968484 revisions in response to comments by Tobias
paulson
parents: 11147
diff changeset
   286
\begin{isabelle}
11411
c315dda16748 indexing
paulson
parents: 11261
diff changeset
   287
\commdx{inductive\protect\_cases}\ gterm_Apply_elim\ [elim!]:\ "Apply\ f\ args\
11173
094b76968484 revisions in response to comments by Tobias
paulson
parents: 11147
diff changeset
   288
\isasymin\ gterms\ F"
094b76968484 revisions in response to comments by Tobias
paulson
parents: 11147
diff changeset
   289
\end{isabelle}
094b76968484 revisions in response to comments by Tobias
paulson
parents: 11147
diff changeset
   290
%
094b76968484 revisions in response to comments by Tobias
paulson
parents: 11147
diff changeset
   291
Here is the result.
094b76968484 revisions in response to comments by Tobias
paulson
parents: 11147
diff changeset
   292
\begin{isabelle}
094b76968484 revisions in response to comments by Tobias
paulson
parents: 11147
diff changeset
   293
\isasymlbrakk Apply\ f\ args\ \isasymin \ gterms\ F;\isanewline
094b76968484 revisions in response to comments by Tobias
paulson
parents: 11147
diff changeset
   294
\ \isasymlbrakk
094b76968484 revisions in response to comments by Tobias
paulson
parents: 11147
diff changeset
   295
\isasymforall t\isasymin set\ args.\ t\ \isasymin \ gterms\ F;\ f\ \isasymin
094b76968484 revisions in response to comments by Tobias
paulson
parents: 11147
diff changeset
   296
\ F\isasymrbrakk \ \isasymLongrightarrow \ P\isasymrbrakk\isanewline
094b76968484 revisions in response to comments by Tobias
paulson
parents: 11147
diff changeset
   297
\isasymLongrightarrow \ P%
094b76968484 revisions in response to comments by Tobias
paulson
parents: 11147
diff changeset
   298
\rulename{gterm_Apply_elim}
094b76968484 revisions in response to comments by Tobias
paulson
parents: 11147
diff changeset
   299
\end{isabelle}
094b76968484 revisions in response to comments by Tobias
paulson
parents: 11147
diff changeset
   300
This rule replaces an assumption about \isa{Apply\ f\ args} by 
094b76968484 revisions in response to comments by Tobias
paulson
parents: 11147
diff changeset
   301
assumptions about \isa{f} and~\isa{args}.  
094b76968484 revisions in response to comments by Tobias
paulson
parents: 11147
diff changeset
   302
No cases are discarded (there was only one to begin
094b76968484 revisions in response to comments by Tobias
paulson
parents: 11147
diff changeset
   303
with) but the rule applies specifically to the pattern \isa{Apply\ f\ args}.
094b76968484 revisions in response to comments by Tobias
paulson
parents: 11147
diff changeset
   304
It can be applied repeatedly as an elimination rule without looping, so we
094b76968484 revisions in response to comments by Tobias
paulson
parents: 11147
diff changeset
   305
have given the
094b76968484 revisions in response to comments by Tobias
paulson
parents: 11147
diff changeset
   306
\isa{elim!}\ attribute. 
10879
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   307
11173
094b76968484 revisions in response to comments by Tobias
paulson
parents: 11147
diff changeset
   308
Now we can prove the other half of that distributive law.
094b76968484 revisions in response to comments by Tobias
paulson
parents: 11147
diff changeset
   309
\begin{isabelle}
094b76968484 revisions in response to comments by Tobias
paulson
parents: 11147
diff changeset
   310
\isacommand{lemma}\ gterms_IntI\ [rule_format,\ intro!]:\isanewline
094b76968484 revisions in response to comments by Tobias
paulson
parents: 11147
diff changeset
   311
\ \ \ \ \ "t\ \isasymin \ gterms\ F\ \isasymLongrightarrow \ t\ \isasymin \ gterms\ G\ \isasymlongrightarrow \ t\ \isasymin \ gterms\ (F\isasyminter G)"\isanewline
094b76968484 revisions in response to comments by Tobias
paulson
parents: 11147
diff changeset
   312
\isacommand{apply}\ (erule\ gterms.induct)\isanewline
094b76968484 revisions in response to comments by Tobias
paulson
parents: 11147
diff changeset
   313
\isacommand{apply}\ blast\isanewline
094b76968484 revisions in response to comments by Tobias
paulson
parents: 11147
diff changeset
   314
\isacommand{done}
094b76968484 revisions in response to comments by Tobias
paulson
parents: 11147
diff changeset
   315
\end{isabelle}
094b76968484 revisions in response to comments by Tobias
paulson
parents: 11147
diff changeset
   316
%
094b76968484 revisions in response to comments by Tobias
paulson
parents: 11147
diff changeset
   317
The proof begins with rule induction over the definition of
094b76968484 revisions in response to comments by Tobias
paulson
parents: 11147
diff changeset
   318
\isa{gterms}, which leaves a single subgoal:  
094b76968484 revisions in response to comments by Tobias
paulson
parents: 11147
diff changeset
   319
\begin{isabelle}
094b76968484 revisions in response to comments by Tobias
paulson
parents: 11147
diff changeset
   320
1.\ \isasymAnd args\ f.\isanewline
094b76968484 revisions in response to comments by Tobias
paulson
parents: 11147
diff changeset
   321
\ \ \ \ \ \ \isasymlbrakk \isasymforall t\isasymin set\ args.\ t\ \isasymin \ gterms\ F\ \isasymand\isanewline
094b76968484 revisions in response to comments by Tobias
paulson
parents: 11147
diff changeset
   322
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ (t\ \isasymin \ gterms\ G\ \isasymlongrightarrow \ t\ \isasymin \ gterms\ (F\ \isasyminter \ G));\isanewline
094b76968484 revisions in response to comments by Tobias
paulson
parents: 11147
diff changeset
   323
\ \ \ \ \ \ \ f\ \isasymin \ F\isasymrbrakk \isanewline
094b76968484 revisions in response to comments by Tobias
paulson
parents: 11147
diff changeset
   324
\ \ \ \ \ \ \isasymLongrightarrow \ Apply\ f\ args\ \isasymin \ gterms\ G\ \isasymlongrightarrow \ Apply\ f\ args\ \isasymin \ gterms\ (F\ \isasyminter \ G)
094b76968484 revisions in response to comments by Tobias
paulson
parents: 11147
diff changeset
   325
\end{isabelle}
094b76968484 revisions in response to comments by Tobias
paulson
parents: 11147
diff changeset
   326
%
094b76968484 revisions in response to comments by Tobias
paulson
parents: 11147
diff changeset
   327
To prove this, we assume \isa{Apply\ f\ args\ \isasymin \
094b76968484 revisions in response to comments by Tobias
paulson
parents: 11147
diff changeset
   328
gterms\ G}.  Rule inversion, in the form of \isa{gterm_Apply_elim}, infers
094b76968484 revisions in response to comments by Tobias
paulson
parents: 11147
diff changeset
   329
that every element of \isa{args} belongs to 
094b76968484 revisions in response to comments by Tobias
paulson
parents: 11147
diff changeset
   330
\isa{gterms~G}; hence (by the induction hypothesis) it belongs
094b76968484 revisions in response to comments by Tobias
paulson
parents: 11147
diff changeset
   331
to \isa{gterms\ (F\ \isasyminter \ G)}.  Rule inversion also yields
094b76968484 revisions in response to comments by Tobias
paulson
parents: 11147
diff changeset
   332
\isa{f\ \isasymin\ G} and hence \isa{f\ \isasymin \ F\ \isasyminter \ G}. 
094b76968484 revisions in response to comments by Tobias
paulson
parents: 11147
diff changeset
   333
All of this reasoning is done by \isa{blast}.
094b76968484 revisions in response to comments by Tobias
paulson
parents: 11147
diff changeset
   334
094b76968484 revisions in response to comments by Tobias
paulson
parents: 11147
diff changeset
   335
\smallskip
094b76968484 revisions in response to comments by Tobias
paulson
parents: 11147
diff changeset
   336
Our distributive law is a trivial consequence of previously-proved results:
094b76968484 revisions in response to comments by Tobias
paulson
parents: 11147
diff changeset
   337
\begin{isabelle}
094b76968484 revisions in response to comments by Tobias
paulson
parents: 11147
diff changeset
   338
\isacommand{theorem}\ gterms_Int_eq\ [simp]:\isanewline
094b76968484 revisions in response to comments by Tobias
paulson
parents: 11147
diff changeset
   339
\ \ \ \ \ "gterms\ (F\isasyminter G)\ =\ gterms\ F\ \isasyminter \ gterms\ G"\isanewline
094b76968484 revisions in response to comments by Tobias
paulson
parents: 11147
diff changeset
   340
\isacommand{by}\ (blast\ intro!:\ mono_Int\ monoI\ gterms_mono)
094b76968484 revisions in response to comments by Tobias
paulson
parents: 11147
diff changeset
   341
\end{isabelle}
11411
c315dda16748 indexing
paulson
parents: 11261
diff changeset
   342
\index{rule inversion|)}%
c315dda16748 indexing
paulson
parents: 11261
diff changeset
   343
\index{ground terms example|)}
10879
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   344
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   345
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   346
\begin{exercise}
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   347
A function mapping function symbols to their 
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   348
types is called a \textbf{signature}.  Given a type 
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   349
ranging over type symbols, we can represent a function's type by a
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   350
list of argument types paired with the result type. 
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   351
Complete this inductive definition:
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   352
\begin{isabelle}
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   353
\isacommand{consts}\ well_typed_gterm::\ "('f\ \isasymRightarrow \ 't\ list\ *\ 't)\ \isasymRightarrow \ ('f\ gterm\ *\ 't)set"\isanewline
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   354
\isacommand{inductive}\ "well_typed_gterm\ sig"\isanewline
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   355
\end{isabelle}
ca2b00c4bba7 renaming to avoid clashes
paulson
parents:
diff changeset
   356
\end{exercise}