ProgTutorial/Package/Ind_Extensions.thy
author Christian Urban <christian dot urban at kcl dot ac dot uk>
Tue, 28 May 2013 23:26:18 +0100
changeset 546 d84867127c5d
parent 544 501491d56798
child 551 be361e980acf
permissions -rw-r--r--
updated to Isabelle changes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
225
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     1
theory Ind_Extensions
346
0fea8b7a14a1 tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents: 261
diff changeset
     2
imports Simple_Inductive_Package Ind_Intro
225
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     3
begin
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     4
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     5
section {* Extensions of the Package (TBD) *}
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     6
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     7
(*
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     8
text {*
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     9
  In order to add a new inductive predicate to a theory with the help of our
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    10
  package, the user must \emph{invoke} it. For every package, there are
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    11
  essentially two different ways of invoking it, which we will refer to as
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    12
  \emph{external} and \emph{internal}. By external invocation we mean that the
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    13
  package is called from within a theory document. In this case, the
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    14
  specification of the inductive predicate, including type annotations and
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    15
  introduction rules, are given as strings by the user. Before the package can
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    16
  actually make the definition, the type and introduction rules have to be
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    17
  parsed. In contrast, internal invocation means that the package is called by
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    18
  some other package. For example, the function definition package
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    19
  calls the inductive definition package to define the
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    20
  graph of the function. However, it is not a good idea for the function
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    21
  definition package to pass the introduction rules for the function graph to
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    22
  the inductive definition package as strings. 
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    23
  
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    24
In this case, it is better to
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    25
  directly pass the rules to the package as a list of terms, which is more
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    26
  robust than handling strings that are lacking the additional structure of
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    27
  terms. These two ways of invoking the package are reflected in its ML
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    28
  programming interface, which consists of two functions:
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    29
*}
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    30
*)
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    31
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    32
text {*
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    33
  Things to include at the end:
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    34
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    35
  \begin{itemize}
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    36
  \item include the code for the parameters
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    37
  \item say something about add-inductive to return
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    38
  the rules
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    39
  \item say something about the two interfaces for calling packages
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    40
  \end{itemize}
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    41
  
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    42
*}
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    43
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    44
(*
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    45
simple_inductive
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    46
  Even and Odd
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    47
where
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    48
  Even0: "Even 0"
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    49
| EvenS: "Odd n \<Longrightarrow> Even (Suc n)"
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    50
| OddS: "Even n \<Longrightarrow> Odd (Suc n)"
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    51
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    52
thm Even0
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    53
thm EvenS
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    54
thm OddS
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    55
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    56
thm Even_Odd.intros
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    57
thm Even.induct
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    58
thm Odd.induct
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    59
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    60
thm Even_def
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    61
thm Odd_def
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    62
*)
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    63
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    64
(*
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    65
text {* 
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    66
  Second, we want that the user can specify fixed parameters.
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    67
  Remember in the previous section we stated that the user can give the 
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    68
  specification for the transitive closure of a relation @{text R} as 
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    69
*}
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    70
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    71
simple_inductive
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    72
  trcl :: "('a \<Rightarrow> 'a \<Rightarrow> bool) \<Rightarrow> 'a \<Rightarrow> 'a \<Rightarrow> bool"
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    73
where
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    74
  base: "trcl R x x"
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    75
| step: "trcl R x y \<Longrightarrow> R y z \<Longrightarrow> trcl R x z"
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    76
*)
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    77
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    78
(*
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    79
text {*
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    80
  Note that there is no locale given in this specification---the parameter
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    81
  @{text "R"} therefore needs to be included explicitly in @{term trcl\<iota>\<iota>}, but
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    82
  stays fixed throughout the specification. The problem with this way of
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    83
  stating the specification for the transitive closure is that it derives the
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    84
  following induction principle.
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    85
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    86
  \begin{center}\small
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    87
  \mprset{flushleft}
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    88
  \mbox{\inferrule{
404
3d27d77c351f added RANGE
Christian Urban <urbanc@in.tum.de>
parents: 346
diff changeset
    89
             @{thm (prem1)  trcl\<iota>\<iota>.induct[where P=P, where z=R, where za=x, where zb=y]}\\\\
3d27d77c351f added RANGE
Christian Urban <urbanc@in.tum.de>
parents: 346
diff changeset
    90
             @{thm (prem2)  trcl\<iota>\<iota>.induct[where P=P, where z=R, where za=x, where zb=y]}\\\\
3d27d77c351f added RANGE
Christian Urban <urbanc@in.tum.de>
parents: 346
diff changeset
    91
             @{thm (prem3)  trcl\<iota>\<iota>.induct[where P=P, where z=R, where za=x, where zb=y]}}
3d27d77c351f added RANGE
Christian Urban <urbanc@in.tum.de>
parents: 346
diff changeset
    92
            {@{thm (concl)  trcl\<iota>\<iota>.induct[where P=P, where z=R, where za=x, where zb=y]}}}  
225
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    93
  \end{center}
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    94
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    95
  But this does not correspond to the induction principle we derived by hand, which
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    96
  was
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    97
  
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    98
  
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    99
  %\begin{center}\small
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   100
  %\mprset{flushleft}
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   101
  %\mbox{\inferrule{
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   102
  %           @ { thm_style prem1  trcl_induct[no_vars]}\\\\
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   103
  %           @ { thm_style prem2  trcl_induct[no_vars]}\\\\
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   104
  %           @ { thm_style prem3  trcl_induct[no_vars]}}
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   105
  %          {@ { thm_style concl  trcl_induct[no_vars]}}}  
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   106
  %\end{center}
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   107
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   108
  The difference is that in the one derived by hand the relation @{term R} is not
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   109
  a parameter of the proposition @{term P} to be proved and it is also not universally
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   110
  qunatified in the second and third premise. The point is that the parameter @{term R}
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   111
  stays fixed thoughout the definition and we do not want to regard it as an ``ordinary''
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   112
  argument of the transitive closure, but one that can be freely instantiated. 
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   113
  In order to recognise such parameters, we have to extend the specification
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   114
  to include a mechanism to state fixed parameters. The user should be able
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   115
  to write 
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   116
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   117
*}
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   118
*)
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   119
(*
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   120
simple_inductive
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   121
  trcl'' for R :: "'a \<Rightarrow> 'a \<Rightarrow> bool"
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   122
where
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   123
  base: "trcl'' R x x"
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   124
| step: "trcl'' R x y \<Longrightarrow> R y z \<Longrightarrow> trcl'' R x z"
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   125
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   126
simple_inductive
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   127
  accpart'' for R :: "'a \<Rightarrow> 'a \<Rightarrow> bool"
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   128
where
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   129
  accpartI: "(\<And>y. R y x \<Longrightarrow> accpart'' R y) \<Longrightarrow> accpart'' R x"
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   130
*)
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   131
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   132
text {*
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   133
  \begin{exercise}
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   134
  In Section~\ref{sec:nutshell} we required that introduction rules must be of the
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   135
  form
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   136
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   137
  \begin{isabelle}
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   138
  @{text "rule ::= \<And>xs. As \<Longrightarrow> (\<And>ys. Bs \<Longrightarrow> pred ss)\<^isup>* \<Longrightarrow> pred ts"}
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   139
  \end{isabelle}
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   140
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   141
  where the @{text "As"} and @{text "Bs"} can be any collection of formulae
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   142
  not containing the @{text "preds"}. This requirement is important,
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   143
  because if violated, the theory behind the inductive package does not work
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   144
  and also the proofs break. Write code that tests whether the introduction
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   145
  rules given by the user fit into the scheme described above. Hint: It 
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   146
  is not important in which order the premises ar given; the
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   147
  @{text "As"} and @{text "(\<And>ys. Bs \<Longrightarrow> pred ss)"} premises can occur
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   148
  in any order.
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   149
  \end{exercise}
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   150
*}  
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   151
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   152
text_raw {*
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   153
  \begin{exercise}
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   154
  If you define @{text even} and @{text odd} with the standard inductive
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   155
  package
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   156
  \begin{isabelle}
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   157
*}
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   158
inductive 
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   159
  even_2 and odd_2
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   160
where
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   161
  even0_2: "even_2 0"
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   162
| evenS_2: "odd_2 m \<Longrightarrow> even_2 (Suc m)"
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   163
| oddS_2:  "even_2 m \<Longrightarrow> odd_2 (Suc m)"
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   164
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   165
text_raw{*
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   166
  \end{isabelle}
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   167
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   168
  you will see that the generated induction principle for @{text "even'"} (namely
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   169
  @{text "even_2_odd_2.inducts"} has the additional assumptions 
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   170
  @{prop "odd_2 m"} and @{prop "even_2 m"} in the recursive cases. These additional 
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   171
  assumptions can sometimes make ``life easier'' in proofs. Since 
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   172
  more assumptions can be made when proving properties, these induction principles 
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   173
  are called strong inductions principles. However, it is the case that the 
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   174
  ``weak'' induction principles imply the ``strong'' ones. Hint: Prove a property 
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   175
  taking a pair (or tuple in case of more than one predicate) as argument: the 
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   176
  property that you originally want to prove and the predicate(s) over which the 
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   177
  induction proceeds.
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   178
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   179
  Write code that automates the derivation of the strong induction 
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   180
  principles from the weak ones.
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   181
  \end{exercise}
228
fe45fbb111c5 various additions
Christian Urban <urbanc@in.tum.de>
parents: 225
diff changeset
   182
fe45fbb111c5 various additions
Christian Urban <urbanc@in.tum.de>
parents: 225
diff changeset
   183
  \begin{readmore}
fe45fbb111c5 various additions
Christian Urban <urbanc@in.tum.de>
parents: 225
diff changeset
   184
  The standard inductive package is based on least fix-points. It allows more 
fe45fbb111c5 various additions
Christian Urban <urbanc@in.tum.de>
parents: 225
diff changeset
   185
  general introduction rules that can include any monotone operators and also
fe45fbb111c5 various additions
Christian Urban <urbanc@in.tum.de>
parents: 225
diff changeset
   186
  provides a richer reasoning infrastructure. The code of this package can be found in 
261
358f325f4db6 updated to new Isabelle
Christian Urban <urbanc@in.tum.de>
parents: 250
diff changeset
   187
  @{ML_file "HOL/Tools/inductive.ML"}.
228
fe45fbb111c5 various additions
Christian Urban <urbanc@in.tum.de>
parents: 225
diff changeset
   188
  \end{readmore}
225
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   189
*}
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   190
250
ab9e09076462 some polishing; added together with Jasmin more examples to the pretty printing section
Christian Urban <urbanc@in.tum.de>
parents: 228
diff changeset
   191
section {* Definitional Packages *}
ab9e09076462 some polishing; added together with Jasmin more examples to the pretty printing section
Christian Urban <urbanc@in.tum.de>
parents: 228
diff changeset
   192
ab9e09076462 some polishing; added together with Jasmin more examples to the pretty printing section
Christian Urban <urbanc@in.tum.de>
parents: 228
diff changeset
   193
text {* Type declarations *}
ab9e09076462 some polishing; added together with Jasmin more examples to the pretty printing section
Christian Urban <urbanc@in.tum.de>
parents: 228
diff changeset
   194
546
d84867127c5d updated to Isabelle changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 544
diff changeset
   195
(*
539
12861a362099 updated to new isabelle
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 517
diff changeset
   196
ML %grayML{*Typedef.add_typedef_global (@{binding test}, [], NoSyn)
544
501491d56798 updated to simplifier change
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 539
diff changeset
   197
  @{term "{1}::nat set"} NONE (simp_tac @{context} 1) @{theory} *}
546
d84867127c5d updated to Isabelle changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 544
diff changeset
   198
*)
225
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   199
517
d8c376662bb4 removed special ML-setup and replaced it by explicit markups (i.e., %grayML)
Christian Urban <urbanc@in.tum.de>
parents: 464
diff changeset
   200
ML %grayML{*fun pat_completeness_auto ctxt =
423
0a25b35178c3 updated to new isabelle
Christian Urban <urbanc@in.tum.de>
parents: 419
diff changeset
   201
  Pat_Completeness.pat_completeness_tac ctxt 1
464
21b5d0145fe4 updated to new Isabelle
Christian Urban <urbanc@in.tum.de>
parents: 423
diff changeset
   202
    THEN auto_tac ctxt*}
423
0a25b35178c3 updated to new isabelle
Christian Urban <urbanc@in.tum.de>
parents: 419
diff changeset
   203
0a25b35178c3 updated to new isabelle
Christian Urban <urbanc@in.tum.de>
parents: 419
diff changeset
   204
ML {*
0a25b35178c3 updated to new isabelle
Christian Urban <urbanc@in.tum.de>
parents: 419
diff changeset
   205
  val conf = Function_Common.default_config
0a25b35178c3 updated to new isabelle
Christian Urban <urbanc@in.tum.de>
parents: 419
diff changeset
   206
*}
0a25b35178c3 updated to new isabelle
Christian Urban <urbanc@in.tum.de>
parents: 419
diff changeset
   207
0a25b35178c3 updated to new isabelle
Christian Urban <urbanc@in.tum.de>
parents: 419
diff changeset
   208
datatype foo = Foo nat
0a25b35178c3 updated to new isabelle
Christian Urban <urbanc@in.tum.de>
parents: 419
diff changeset
   209
0a25b35178c3 updated to new isabelle
Christian Urban <urbanc@in.tum.de>
parents: 419
diff changeset
   210
local_setup{*Primrec.add_primrec [(@{binding "bar"}, NONE, NoSyn)] 
0a25b35178c3 updated to new isabelle
Christian Urban <urbanc@in.tum.de>
parents: 419
diff changeset
   211
    [(Attrib.empty_binding, @{term "\<And>x. bar (Foo x) = x"})]
0a25b35178c3 updated to new isabelle
Christian Urban <urbanc@in.tum.de>
parents: 419
diff changeset
   212
  #> snd *}
0a25b35178c3 updated to new isabelle
Christian Urban <urbanc@in.tum.de>
parents: 419
diff changeset
   213
0a25b35178c3 updated to new isabelle
Christian Urban <urbanc@in.tum.de>
parents: 419
diff changeset
   214
local_setup{*Function.add_function [(@{binding "baz"}, NONE, NoSyn)] 
0a25b35178c3 updated to new isabelle
Christian Urban <urbanc@in.tum.de>
parents: 419
diff changeset
   215
    [(Attrib.empty_binding, @{term "\<And>x. baz (Foo x) = x"})]
0a25b35178c3 updated to new isabelle
Christian Urban <urbanc@in.tum.de>
parents: 419
diff changeset
   216
      conf pat_completeness_auto #> snd*}
225
7859fc59249a section for further material about simple inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   217
517
d8c376662bb4 removed special ML-setup and replaced it by explicit markups (i.e., %grayML)
Christian Urban <urbanc@in.tum.de>
parents: 464
diff changeset
   218
(*<*)end(*>*)