ProgTutorial/Package/Ind_Prelims.thy
author Christian Urban <urbanc@in.tum.de>
Tue, 31 Mar 2009 20:31:18 +0100
changeset 218 7ff7325e3b4e
parent 189 069d525f8f1d
child 219 98d43270024f
permissions -rw-r--r--
started to adapt the rest of chapter 5 to the simplified version without parameters (they will be described in the extension section)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
127
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
     1
theory Ind_Prelims
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
     2
imports Main LaTeXsugar"../Base" Simple_Inductive_Package
32
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
     3
begin
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
     4
127
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
     5
section{* Preliminaries *}
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
     6
  
32
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
     7
text {*
218
7ff7325e3b4e started to adapt the rest of chapter 5 to the simplified version without parameters (they will be described in the extension section)
Christian Urban <urbanc@in.tum.de>
parents: 189
diff changeset
     8
  The user will just give a specification of inductive predicate(s) and
129
e0d368a45537 started a section about simprocs
Christian Urban <urbanc@in.tum.de>
parents: 127
diff changeset
     9
  expects from the package to produce a convenient reasoning
e0d368a45537 started a section about simprocs
Christian Urban <urbanc@in.tum.de>
parents: 127
diff changeset
    10
  infrastructure. This infrastructure needs to be derived from the definition
218
7ff7325e3b4e started to adapt the rest of chapter 5 to the simplified version without parameters (they will be described in the extension section)
Christian Urban <urbanc@in.tum.de>
parents: 189
diff changeset
    11
  that correspond to the specified predicate(s). Before we start with
7ff7325e3b4e started to adapt the rest of chapter 5 to the simplified version without parameters (they will be described in the extension section)
Christian Urban <urbanc@in.tum.de>
parents: 189
diff changeset
    12
  explaining all parts of the package, let us first give four examples showing
7ff7325e3b4e started to adapt the rest of chapter 5 to the simplified version without parameters (they will be described in the extension section)
Christian Urban <urbanc@in.tum.de>
parents: 189
diff changeset
    13
  how to define inductive predicates by hand and then also how to prove by
7ff7325e3b4e started to adapt the rest of chapter 5 to the simplified version without parameters (they will be described in the extension section)
Christian Urban <urbanc@in.tum.de>
parents: 189
diff changeset
    14
  hand properties about them. See Figure \ref{fig:paperpreds} for their usual
7ff7325e3b4e started to adapt the rest of chapter 5 to the simplified version without parameters (they will be described in the extension section)
Christian Urban <urbanc@in.tum.de>
parents: 189
diff changeset
    15
  ``pencil-and-paper'' definitions. From these examples, we will
129
e0d368a45537 started a section about simprocs
Christian Urban <urbanc@in.tum.de>
parents: 127
diff changeset
    16
  figure out a general method for defining inductive predicates.  The aim in
e0d368a45537 started a section about simprocs
Christian Urban <urbanc@in.tum.de>
parents: 127
diff changeset
    17
  this section is \emph{not} to write proofs that are as beautiful as
e0d368a45537 started a section about simprocs
Christian Urban <urbanc@in.tum.de>
parents: 127
diff changeset
    18
  possible, but as close as possible to the ML-code we will develop in later
e0d368a45537 started a section about simprocs
Christian Urban <urbanc@in.tum.de>
parents: 127
diff changeset
    19
  sections.
e0d368a45537 started a section about simprocs
Christian Urban <urbanc@in.tum.de>
parents: 127
diff changeset
    20
218
7ff7325e3b4e started to adapt the rest of chapter 5 to the simplified version without parameters (they will be described in the extension section)
Christian Urban <urbanc@in.tum.de>
parents: 189
diff changeset
    21
  \begin{figure}[t]
7ff7325e3b4e started to adapt the rest of chapter 5 to the simplified version without parameters (they will be described in the extension section)
Christian Urban <urbanc@in.tum.de>
parents: 189
diff changeset
    22
  \begin{boxedminipage}{\textwidth}
127
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
    23
  \begin{center}\small
116
c9ff326e3ce5 more changes to the package chapter
Christian Urban <urbanc@in.tum.de>
parents: 115
diff changeset
    24
  @{prop[mode=Axiom] "trcl R x x"} \hspace{5mm}
c9ff326e3ce5 more changes to the package chapter
Christian Urban <urbanc@in.tum.de>
parents: 115
diff changeset
    25
  @{prop[mode=Rule] "R x y \<Longrightarrow> trcl R y z \<Longrightarrow> trcl R x z"}
88
ebbd0dd008c8 adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents: 38
diff changeset
    26
  \end{center}
218
7ff7325e3b4e started to adapt the rest of chapter 5 to the simplified version without parameters (they will be described in the extension section)
Christian Urban <urbanc@in.tum.de>
parents: 189
diff changeset
    27
  \begin{center}\small
7ff7325e3b4e started to adapt the rest of chapter 5 to the simplified version without parameters (they will be described in the extension section)
Christian Urban <urbanc@in.tum.de>
parents: 189
diff changeset
    28
  @{prop[mode=Axiom] "even (0::nat)"} \hspace{5mm}
7ff7325e3b4e started to adapt the rest of chapter 5 to the simplified version without parameters (they will be described in the extension section)
Christian Urban <urbanc@in.tum.de>
parents: 189
diff changeset
    29
  @{prop[mode=Rule] "odd n \<Longrightarrow> even (Suc n)"} \hspace{5mm}
7ff7325e3b4e started to adapt the rest of chapter 5 to the simplified version without parameters (they will be described in the extension section)
Christian Urban <urbanc@in.tum.de>
parents: 189
diff changeset
    30
  @{prop[mode=Rule] "even n \<Longrightarrow> odd (Suc n)"}
7ff7325e3b4e started to adapt the rest of chapter 5 to the simplified version without parameters (they will be described in the extension section)
Christian Urban <urbanc@in.tum.de>
parents: 189
diff changeset
    31
  \end{center}
7ff7325e3b4e started to adapt the rest of chapter 5 to the simplified version without parameters (they will be described in the extension section)
Christian Urban <urbanc@in.tum.de>
parents: 189
diff changeset
    32
  \begin{center}\small
7ff7325e3b4e started to adapt the rest of chapter 5 to the simplified version without parameters (they will be described in the extension section)
Christian Urban <urbanc@in.tum.de>
parents: 189
diff changeset
    33
  \mbox{\inferrule{@{term "\<And>y. R y x \<Longrightarrow> accpart R y"}}{@{term "accpart R x"}}}
7ff7325e3b4e started to adapt the rest of chapter 5 to the simplified version without parameters (they will be described in the extension section)
Christian Urban <urbanc@in.tum.de>
parents: 189
diff changeset
    34
  \end{center}
7ff7325e3b4e started to adapt the rest of chapter 5 to the simplified version without parameters (they will be described in the extension section)
Christian Urban <urbanc@in.tum.de>
parents: 189
diff changeset
    35
  \begin{center}\small
7ff7325e3b4e started to adapt the rest of chapter 5 to the simplified version without parameters (they will be described in the extension section)
Christian Urban <urbanc@in.tum.de>
parents: 189
diff changeset
    36
  @{prop[mode=Rule] "a\<noteq>b \<Longrightarrow> fresh a (Var b)"}\hspace{5mm}
7ff7325e3b4e started to adapt the rest of chapter 5 to the simplified version without parameters (they will be described in the extension section)
Christian Urban <urbanc@in.tum.de>
parents: 189
diff changeset
    37
  @{prop[mode=Rule] "\<lbrakk>fresh a t; fresh a s\<rbrakk> \<Longrightarrow> fresh a (App t s)"}\\[2mm]
7ff7325e3b4e started to adapt the rest of chapter 5 to the simplified version without parameters (they will be described in the extension section)
Christian Urban <urbanc@in.tum.de>
parents: 189
diff changeset
    38
  @{prop[mode=Axiom] "fresh a (Lam a t)"}\hspace{5mm}
7ff7325e3b4e started to adapt the rest of chapter 5 to the simplified version without parameters (they will be described in the extension section)
Christian Urban <urbanc@in.tum.de>
parents: 189
diff changeset
    39
  @{prop[mode=Rule] "\<lbrakk>a\<noteq>b; fresh a t\<rbrakk> \<Longrightarrow> fresh a (Lam b t)"}
7ff7325e3b4e started to adapt the rest of chapter 5 to the simplified version without parameters (they will be described in the extension section)
Christian Urban <urbanc@in.tum.de>
parents: 189
diff changeset
    40
  \end{center}
7ff7325e3b4e started to adapt the rest of chapter 5 to the simplified version without parameters (they will be described in the extension section)
Christian Urban <urbanc@in.tum.de>
parents: 189
diff changeset
    41
  \end{boxedminipage}
7ff7325e3b4e started to adapt the rest of chapter 5 to the simplified version without parameters (they will be described in the extension section)
Christian Urban <urbanc@in.tum.de>
parents: 189
diff changeset
    42
  \caption{Examples of four ``Pencil-and-paper'' definitions of inductively defined
7ff7325e3b4e started to adapt the rest of chapter 5 to the simplified version without parameters (they will be described in the extension section)
Christian Urban <urbanc@in.tum.de>
parents: 189
diff changeset
    43
  predicates. In formal reasoning with Isabelle, the user just wants to give such 
7ff7325e3b4e started to adapt the rest of chapter 5 to the simplified version without parameters (they will be described in the extension section)
Christian Urban <urbanc@in.tum.de>
parents: 189
diff changeset
    44
  definitions and expects that the reasoning structure is derived automatically. 
7ff7325e3b4e started to adapt the rest of chapter 5 to the simplified version without parameters (they will be described in the extension section)
Christian Urban <urbanc@in.tum.de>
parents: 189
diff changeset
    45
  For this definitional packages need to be implemented.\label{fig:paperpreds}}
7ff7325e3b4e started to adapt the rest of chapter 5 to the simplified version without parameters (they will be described in the extension section)
Christian Urban <urbanc@in.tum.de>
parents: 189
diff changeset
    46
  \end{figure}
88
ebbd0dd008c8 adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents: 38
diff changeset
    47
218
7ff7325e3b4e started to adapt the rest of chapter 5 to the simplified version without parameters (they will be described in the extension section)
Christian Urban <urbanc@in.tum.de>
parents: 189
diff changeset
    48
  We first consider the transitive closure of a relation @{text R}. The user will 
7ff7325e3b4e started to adapt the rest of chapter 5 to the simplified version without parameters (they will be described in the extension section)
Christian Urban <urbanc@in.tum.de>
parents: 189
diff changeset
    49
  state for @{term trcl\<iota>} the specification:
127
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
    50
*}
88
ebbd0dd008c8 adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents: 38
diff changeset
    51
127
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
    52
simple_inductive
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
    53
  trcl\<iota> :: "('a \<Rightarrow> 'a \<Rightarrow> bool) \<Rightarrow> 'a \<Rightarrow> 'a \<Rightarrow> bool"
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
    54
where
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
    55
  base: "trcl\<iota> R x x"
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
    56
| step: "trcl\<iota> R x y \<Longrightarrow> R y z \<Longrightarrow> trcl\<iota> R x z"
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
    57
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
    58
text {*
218
7ff7325e3b4e started to adapt the rest of chapter 5 to the simplified version without parameters (they will be described in the extension section)
Christian Urban <urbanc@in.tum.de>
parents: 189
diff changeset
    59
  The package has to make an appropriate definition and provide
127
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
    60
  lemmas to reason about the predicate @{term trcl\<iota>}. Since an inductively
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
    61
  defined predicate is the least predicate closed under a collection of
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
    62
  introduction rules, the predicate @{text "trcl R x y"} can be defined so
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
    63
  that it holds if and only if @{text "P x y"} holds for every predicate
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
    64
  @{text P} closed under the rules above. This gives rise to the definition
32
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
    65
*}
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
    66
127
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
    67
definition "trcl \<equiv> 
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
    68
     \<lambda>R x y. \<forall>P. (\<forall>x. P x x) 
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
    69
                  \<longrightarrow> (\<forall>x y z. R x y \<longrightarrow> P y z \<longrightarrow> P x z) \<longrightarrow> P x y"
32
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
    70
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
    71
text {*
218
7ff7325e3b4e started to adapt the rest of chapter 5 to the simplified version without parameters (they will be described in the extension section)
Christian Urban <urbanc@in.tum.de>
parents: 189
diff changeset
    72
  We have to use the object implication @{text "\<longrightarrow>"} and object quantification
7ff7325e3b4e started to adapt the rest of chapter 5 to the simplified version without parameters (they will be described in the extension section)
Christian Urban <urbanc@in.tum.de>
parents: 189
diff changeset
    73
  @{text "\<forall>"} for stating this definition (there is no other way for
7ff7325e3b4e started to adapt the rest of chapter 5 to the simplified version without parameters (they will be described in the extension section)
Christian Urban <urbanc@in.tum.de>
parents: 189
diff changeset
    74
  definitions in HOL). However, the introduction rules and induction
7ff7325e3b4e started to adapt the rest of chapter 5 to the simplified version without parameters (they will be described in the extension section)
Christian Urban <urbanc@in.tum.de>
parents: 189
diff changeset
    75
  principles associated with the transitive closure should use the meta-connectives, 
7ff7325e3b4e started to adapt the rest of chapter 5 to the simplified version without parameters (they will be described in the extension section)
Christian Urban <urbanc@in.tum.de>
parents: 189
diff changeset
    76
  since they simplify the reasoning for the user.
7ff7325e3b4e started to adapt the rest of chapter 5 to the simplified version without parameters (they will be described in the extension section)
Christian Urban <urbanc@in.tum.de>
parents: 189
diff changeset
    77
32
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
    78
127
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
    79
  With this definition, the proof of the induction principle for @{term trcl}
129
e0d368a45537 started a section about simprocs
Christian Urban <urbanc@in.tum.de>
parents: 127
diff changeset
    80
  is almost immediate. It suffices to convert all the meta-level
116
c9ff326e3ce5 more changes to the package chapter
Christian Urban <urbanc@in.tum.de>
parents: 115
diff changeset
    81
  connectives in the lemma to object-level connectives using the
127
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
    82
  proof method @{text atomize} (Line 4), expand the definition of @{term trcl}
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
    83
  (Line 5 and 6), eliminate the universal quantifier contained in it (Line~7),
218
7ff7325e3b4e started to adapt the rest of chapter 5 to the simplified version without parameters (they will be described in the extension section)
Christian Urban <urbanc@in.tum.de>
parents: 189
diff changeset
    84
  and then solve the goal by @{text assumption} (Line 8).
113
9b6c9d172378 slightly updated
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
    85
32
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
    86
*}
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
    87
114
13fd0a83d3c3 properly handled linenumbers in ML-text and Isar-proofs
Christian Urban <urbanc@in.tum.de>
parents: 113
diff changeset
    88
lemma %linenos trcl_induct:
218
7ff7325e3b4e started to adapt the rest of chapter 5 to the simplified version without parameters (they will be described in the extension section)
Christian Urban <urbanc@in.tum.de>
parents: 189
diff changeset
    89
assumes "trcl R x y"
7ff7325e3b4e started to adapt the rest of chapter 5 to the simplified version without parameters (they will be described in the extension section)
Christian Urban <urbanc@in.tum.de>
parents: 189
diff changeset
    90
shows "(\<And>x. P x x) \<Longrightarrow> (\<And>x y z. R x y \<Longrightarrow> P y z \<Longrightarrow> P x z) \<Longrightarrow> P x y"
113
9b6c9d172378 slightly updated
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
    91
apply(atomize (full))
165
890fbfef6d6b partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents: 129
diff changeset
    92
apply(cut_tac prems)
113
9b6c9d172378 slightly updated
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
    93
apply(unfold trcl_def)
9b6c9d172378 slightly updated
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
    94
apply(drule spec[where x=P])
9b6c9d172378 slightly updated
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
    95
apply(assumption)
9b6c9d172378 slightly updated
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
    96
done
88
ebbd0dd008c8 adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents: 38
diff changeset
    97
113
9b6c9d172378 slightly updated
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
    98
text {*
127
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
    99
  The proofs for the introduction rules are slightly more complicated. 
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   100
  For the first one, we need to prove the following lemma:
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   101
*}
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   102
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   103
lemma %linenos trcl_base: 
218
7ff7325e3b4e started to adapt the rest of chapter 5 to the simplified version without parameters (they will be described in the extension section)
Christian Urban <urbanc@in.tum.de>
parents: 189
diff changeset
   104
shows "trcl R x x"
127
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   105
apply(unfold trcl_def)
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   106
apply(rule allI impI)+
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   107
apply(drule spec)
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   108
apply(assumption)
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   109
done
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   110
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   111
text {*
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   112
  We again unfold first the definition and apply introduction rules 
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   113
  for @{text "\<forall>"} and @{text "\<longrightarrow>"} as often as possible (Lines 3 and 4).
116
c9ff326e3ce5 more changes to the package chapter
Christian Urban <urbanc@in.tum.de>
parents: 115
diff changeset
   114
  We then end up in the goal state:
113
9b6c9d172378 slightly updated
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
   115
*}
88
ebbd0dd008c8 adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents: 38
diff changeset
   116
113
9b6c9d172378 slightly updated
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
   117
(*<*)lemma "trcl R x x"
115
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   118
apply (unfold trcl_def)
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   119
apply (rule allI impI)+(*>*)
113
9b6c9d172378 slightly updated
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
   120
txt {* @{subgoals [display]} *}
32
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   121
(*<*)oops(*>*)
88
ebbd0dd008c8 adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents: 38
diff changeset
   122
113
9b6c9d172378 slightly updated
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
   123
text {*
218
7ff7325e3b4e started to adapt the rest of chapter 5 to the simplified version without parameters (they will be described in the extension section)
Christian Urban <urbanc@in.tum.de>
parents: 189
diff changeset
   124
  The two assumptions come from the definition of @{term trcl} and correspond
7ff7325e3b4e started to adapt the rest of chapter 5 to the simplified version without parameters (they will be described in the extension section)
Christian Urban <urbanc@in.tum.de>
parents: 189
diff changeset
   125
  to the introduction rules. Thus, all we have to do is to eliminate the
7ff7325e3b4e started to adapt the rest of chapter 5 to the simplified version without parameters (they will be described in the extension section)
Christian Urban <urbanc@in.tum.de>
parents: 189
diff changeset
   126
  universal quantifier in front of the first assumption (Line 5), and then
7ff7325e3b4e started to adapt the rest of chapter 5 to the simplified version without parameters (they will be described in the extension section)
Christian Urban <urbanc@in.tum.de>
parents: 189
diff changeset
   127
  solve the goal by assumption (Line 6).
113
9b6c9d172378 slightly updated
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
   128
*}
9b6c9d172378 slightly updated
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
   129
9b6c9d172378 slightly updated
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
   130
text {*
127
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   131
  Next we have to show that the second introduction rule also follows from the
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   132
  definition.  Since this rule has premises, the proof is a bit more
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   133
  involved. After unfolding the definitions and applying the introduction
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   134
  rules for @{text "\<forall>"} and @{text "\<longrightarrow>"}
113
9b6c9d172378 slightly updated
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
   135
*}
9b6c9d172378 slightly updated
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
   136
127
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   137
lemma trcl_step: 
218
7ff7325e3b4e started to adapt the rest of chapter 5 to the simplified version without parameters (they will be described in the extension section)
Christian Urban <urbanc@in.tum.de>
parents: 189
diff changeset
   138
shows "R x y \<Longrightarrow> trcl R y z \<Longrightarrow> trcl R x z"
115
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   139
apply (unfold trcl_def)
127
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   140
apply (rule allI impI)+
113
9b6c9d172378 slightly updated
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
   141
127
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   142
txt {* 
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   143
  we obtain the goal state
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   144
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   145
  @{subgoals [display]} 
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   146
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   147
  To see better where we are, let us explicitly name the assumptions 
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   148
  by starting a subproof.
115
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   149
*}
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   150
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   151
proof -
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   152
  case (goal1 P)
127
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   153
  have p1: "R x y" by fact
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   154
  have p2: "\<forall>P. (\<forall>x. P x x) 
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   155
                  \<longrightarrow> (\<forall>x y z. R x y \<longrightarrow> P y z \<longrightarrow> P x z) \<longrightarrow> P y z" by fact
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   156
  have r1: "\<forall>x. P x x" by fact
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   157
  have r2: "\<forall>x y z. R x y \<longrightarrow> P y z \<longrightarrow> P x z" by fact
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   158
  show "P x z"
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   159
  
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   160
txt {*
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   161
  The assumptions @{text "p1"} and @{text "p2"} correspond to the premises of
218
7ff7325e3b4e started to adapt the rest of chapter 5 to the simplified version without parameters (they will be described in the extension section)
Christian Urban <urbanc@in.tum.de>
parents: 189
diff changeset
   162
  the second introduction rule (unfolded); the assumptions @{text "r1"} and @{text "r2"}
7ff7325e3b4e started to adapt the rest of chapter 5 to the simplified version without parameters (they will be described in the extension section)
Christian Urban <urbanc@in.tum.de>
parents: 189
diff changeset
   163
  come from the definition of @{term trcl} . We apply @{text "r2"} to the goal
127
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   164
  @{term "P x z"}. In order for the assumption to be applicable as a rule, we
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   165
  have to eliminate the universal quantifier and turn the object-level
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   166
  implications into meta-level ones. This can be accomplished using the @{text
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   167
  rule_format} attribute. So we continue the proof with:
115
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   168
32
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   169
*}
113
9b6c9d172378 slightly updated
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
   170
127
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   171
    apply (rule r2[rule_format])
88
ebbd0dd008c8 adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents: 38
diff changeset
   172
127
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   173
txt {*
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   174
  This gives us two new subgoals
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   175
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   176
  @{subgoals [display]} 
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   177
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   178
  which can be solved using assumptions @{text p1} and @{text p2}. The latter
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   179
  involves a quantifier and implications that have to be eliminated before it
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   180
  can be applied. To avoid potential problems with higher-order unification,
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   181
  we explicitly instantiate the quantifier to @{text "P"} and also match
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   182
  explicitly the implications with @{text "r1"} and @{text "r2"}. This gives
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   183
  the proof:
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   184
*}
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   185
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   186
    apply(rule p1)
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   187
    apply(rule p2[THEN spec[where x=P], THEN mp, THEN mp, OF r1, OF r2])
115
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   188
    done
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   189
qed
32
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   190
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   191
text {*
127
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   192
  Now we are done. It might be surprising that we are not using the automatic
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   193
  tactics available in Isabelle for proving this lemmas. After all @{text
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   194
  "blast"} would easily dispense of it.
115
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   195
*}
88
ebbd0dd008c8 adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents: 38
diff changeset
   196
127
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   197
lemma trcl_step_blast: 
218
7ff7325e3b4e started to adapt the rest of chapter 5 to the simplified version without parameters (they will be described in the extension section)
Christian Urban <urbanc@in.tum.de>
parents: 189
diff changeset
   198
shows "R x y \<Longrightarrow> trcl R y z \<Longrightarrow> trcl R x z"
115
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   199
apply(unfold trcl_def)
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   200
apply(blast)
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   201
done
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   202
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   203
text {*
116
c9ff326e3ce5 more changes to the package chapter
Christian Urban <urbanc@in.tum.de>
parents: 115
diff changeset
   204
  Experience has shown that it is generally a bad idea to rely heavily on
c9ff326e3ce5 more changes to the package chapter
Christian Urban <urbanc@in.tum.de>
parents: 115
diff changeset
   205
  @{text blast}, @{text auto} and the like in automated proofs. The reason is
c9ff326e3ce5 more changes to the package chapter
Christian Urban <urbanc@in.tum.de>
parents: 115
diff changeset
   206
  that you do not have precise control over them (the user can, for example,
c9ff326e3ce5 more changes to the package chapter
Christian Urban <urbanc@in.tum.de>
parents: 115
diff changeset
   207
  declare new intro- or simplification rules that can throw automatic tactics
c9ff326e3ce5 more changes to the package chapter
Christian Urban <urbanc@in.tum.de>
parents: 115
diff changeset
   208
  off course) and also it is very hard to debug proofs involving automatic
c9ff326e3ce5 more changes to the package chapter
Christian Urban <urbanc@in.tum.de>
parents: 115
diff changeset
   209
  tactics whenever something goes wrong. Therefore if possible, automatic 
218
7ff7325e3b4e started to adapt the rest of chapter 5 to the simplified version without parameters (they will be described in the extension section)
Christian Urban <urbanc@in.tum.de>
parents: 189
diff changeset
   210
  tactics should be avoided or be constrained sufficiently.
115
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   211
116
c9ff326e3ce5 more changes to the package chapter
Christian Urban <urbanc@in.tum.de>
parents: 115
diff changeset
   212
  The method of defining inductive predicates by impredicative quantification
c9ff326e3ce5 more changes to the package chapter
Christian Urban <urbanc@in.tum.de>
parents: 115
diff changeset
   213
  also generalises to mutually inductive predicates. The next example defines
218
7ff7325e3b4e started to adapt the rest of chapter 5 to the simplified version without parameters (they will be described in the extension section)
Christian Urban <urbanc@in.tum.de>
parents: 189
diff changeset
   214
  the predicates @{text even} and @{text odd}. The user will state for this 
7ff7325e3b4e started to adapt the rest of chapter 5 to the simplified version without parameters (they will be described in the extension section)
Christian Urban <urbanc@in.tum.de>
parents: 189
diff changeset
   215
  inductive definition the specification:
32
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   216
*}
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   217
127
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   218
simple_inductive
165
890fbfef6d6b partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents: 129
diff changeset
   219
  even and odd
127
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   220
where
165
890fbfef6d6b partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents: 129
diff changeset
   221
  even0: "even 0"
890fbfef6d6b partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents: 129
diff changeset
   222
| evenS: "odd n \<Longrightarrow> even (Suc n)"
890fbfef6d6b partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents: 129
diff changeset
   223
| oddS: "even n \<Longrightarrow> odd (Suc n)"
32
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   224
127
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   225
text {*
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   226
  Since the predicates @{term even} and @{term odd} are mutually inductive, each 
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   227
  corresponding definition must quantify over both predicates (we name them 
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   228
  below @{text "P"} and @{text "Q"}).
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   229
*}
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   230
165
890fbfef6d6b partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents: 129
diff changeset
   231
definition "even\<iota> \<equiv> 
127
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   232
  \<lambda>n. \<forall>P Q. P 0 \<longrightarrow> (\<forall>m. Q m \<longrightarrow> P (Suc m)) 
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   233
                 \<longrightarrow> (\<forall>m. P m \<longrightarrow> Q (Suc m)) \<longrightarrow> P n"
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   234
165
890fbfef6d6b partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents: 129
diff changeset
   235
definition "odd\<iota> \<equiv>
127
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   236
  \<lambda>n. \<forall>P Q. P 0 \<longrightarrow> (\<forall>m. Q m \<longrightarrow> P (Suc m)) 
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   237
                 \<longrightarrow> (\<forall>m. P m \<longrightarrow> Q (Suc m)) \<longrightarrow> Q n"
32
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   238
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   239
text {*
116
c9ff326e3ce5 more changes to the package chapter
Christian Urban <urbanc@in.tum.de>
parents: 115
diff changeset
   240
  For proving the induction principles, we use exactly the same technique 
c9ff326e3ce5 more changes to the package chapter
Christian Urban <urbanc@in.tum.de>
parents: 115
diff changeset
   241
  as in the transitive closure example, namely:
32
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   242
*}
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   243
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   244
lemma even_induct:
218
7ff7325e3b4e started to adapt the rest of chapter 5 to the simplified version without parameters (they will be described in the extension section)
Christian Urban <urbanc@in.tum.de>
parents: 189
diff changeset
   245
assumes "even n"
7ff7325e3b4e started to adapt the rest of chapter 5 to the simplified version without parameters (they will be described in the extension section)
Christian Urban <urbanc@in.tum.de>
parents: 189
diff changeset
   246
shows "P 0 \<Longrightarrow> (\<And>m. Q m \<Longrightarrow> P (Suc m)) \<Longrightarrow> (\<And>m. P m \<Longrightarrow> Q (Suc m)) \<Longrightarrow> P n"
115
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   247
apply(atomize (full))
165
890fbfef6d6b partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents: 129
diff changeset
   248
apply(cut_tac prems)
115
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   249
apply(unfold even_def)
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   250
apply(drule spec[where x=P])
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   251
apply(drule spec[where x=Q])
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   252
apply(assumption)
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   253
done
32
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   254
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   255
text {*
127
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   256
  The only difference with the proof @{text "trcl_induct"} is that we have to
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   257
  instantiate here two universal quantifiers.  We omit the other induction
218
7ff7325e3b4e started to adapt the rest of chapter 5 to the simplified version without parameters (they will be described in the extension section)
Christian Urban <urbanc@in.tum.de>
parents: 189
diff changeset
   258
  principle that has @{prop "even n"} as premise and @{term "Q n"} as conclusion.  
7ff7325e3b4e started to adapt the rest of chapter 5 to the simplified version without parameters (they will be described in the extension section)
Christian Urban <urbanc@in.tum.de>
parents: 189
diff changeset
   259
  The proofs of the introduction rules are also very similar to the ones in 
7ff7325e3b4e started to adapt the rest of chapter 5 to the simplified version without parameters (they will be described in the extension section)
Christian Urban <urbanc@in.tum.de>
parents: 189
diff changeset
   260
  the @{text "trcl"}-example. We only show the proof of the second introduction 
7ff7325e3b4e started to adapt the rest of chapter 5 to the simplified version without parameters (they will be described in the extension section)
Christian Urban <urbanc@in.tum.de>
parents: 189
diff changeset
   261
  rule.
32
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   262
*}
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   263
127
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   264
lemma %linenos evenS: 
218
7ff7325e3b4e started to adapt the rest of chapter 5 to the simplified version without parameters (they will be described in the extension section)
Christian Urban <urbanc@in.tum.de>
parents: 189
diff changeset
   265
shows "odd m \<Longrightarrow> even (Suc m)"
115
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   266
apply (unfold odd_def even_def)
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   267
apply (rule allI impI)+
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   268
proof -
165
890fbfef6d6b partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents: 129
diff changeset
   269
  case (goal1 P Q)
127
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   270
  have p1: "\<forall>P Q. P 0 \<longrightarrow> (\<forall>m. Q m \<longrightarrow> P (Suc m)) 
115
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   271
                             \<longrightarrow> (\<forall>m. P m \<longrightarrow> Q (Suc m)) \<longrightarrow> Q m" by fact
127
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   272
  have r1: "P 0" by fact
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   273
  have r2: "\<forall>m. Q m \<longrightarrow> P (Suc m)" by fact
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   274
  have r3: "\<forall>m. P m \<longrightarrow> Q (Suc m)" by fact
115
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   275
  show "P (Suc m)"
127
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   276
    apply(rule r2[rule_format])
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   277
    apply(rule p1[THEN spec[where x=P], THEN spec[where x=Q],
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   278
	           THEN mp, THEN mp, THEN mp, OF r1, OF r2, OF r3])
115
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   279
    done
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   280
qed
88
ebbd0dd008c8 adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents: 38
diff changeset
   281
32
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   282
text {*
218
7ff7325e3b4e started to adapt the rest of chapter 5 to the simplified version without parameters (they will be described in the extension section)
Christian Urban <urbanc@in.tum.de>
parents: 189
diff changeset
   283
  The interesting lines are 7 to 15. The assumptions fall into to categories:
7ff7325e3b4e started to adapt the rest of chapter 5 to the simplified version without parameters (they will be described in the extension section)
Christian Urban <urbanc@in.tum.de>
parents: 189
diff changeset
   284
  @{text p1} corresponds to the premise of the introduction rule; @{text "r1"}
7ff7325e3b4e started to adapt the rest of chapter 5 to the simplified version without parameters (they will be described in the extension section)
Christian Urban <urbanc@in.tum.de>
parents: 189
diff changeset
   285
  to @{text "r3"} come from the definition of @{text "even"}.
127
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   286
  In Line 13, we apply the assumption @{text "r2"} (since we prove the second
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   287
  introduction rule). In Lines 14 and 15 we apply assumption @{text "p1"} (if
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   288
  the second introduction rule had more premises we have to do that for all
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   289
  of them). In order for this assumption to be applicable, the quantifiers
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   290
  need to be instantiated and then also the implications need to be resolved
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   291
  with the other rules.
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   292
218
7ff7325e3b4e started to adapt the rest of chapter 5 to the simplified version without parameters (they will be described in the extension section)
Christian Urban <urbanc@in.tum.de>
parents: 189
diff changeset
   293
  As a final example, we define the accessible part of a relation @{text R}
7ff7325e3b4e started to adapt the rest of chapter 5 to the simplified version without parameters (they will be described in the extension section)
Christian Urban <urbanc@in.tum.de>
parents: 189
diff changeset
   294
  (see Figure~\ref{fig:paperpreds}). There the premsise of the introduction 
7ff7325e3b4e started to adapt the rest of chapter 5 to the simplified version without parameters (they will be described in the extension section)
Christian Urban <urbanc@in.tum.de>
parents: 189
diff changeset
   295
  rule involves a universal quantifier and an implication. The
116
c9ff326e3ce5 more changes to the package chapter
Christian Urban <urbanc@in.tum.de>
parents: 115
diff changeset
   296
  definition of @{text accpart} is:
32
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   297
*}
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   298
127
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   299
definition "accpart \<equiv> \<lambda>R x. \<forall>P. (\<forall>x. (\<forall>y. R y x \<longrightarrow> P y) \<longrightarrow> P x) \<longrightarrow> P x"
32
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   300
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   301
text {*
218
7ff7325e3b4e started to adapt the rest of chapter 5 to the simplified version without parameters (they will be described in the extension section)
Christian Urban <urbanc@in.tum.de>
parents: 189
diff changeset
   302
  The proof of the induction principle is again straightforward and omitted.
7ff7325e3b4e started to adapt the rest of chapter 5 to the simplified version without parameters (they will be described in the extension section)
Christian Urban <urbanc@in.tum.de>
parents: 189
diff changeset
   303
  Proving the introduction rule is a little more complicated, because the 
7ff7325e3b4e started to adapt the rest of chapter 5 to the simplified version without parameters (they will be described in the extension section)
Christian Urban <urbanc@in.tum.de>
parents: 189
diff changeset
   304
  quantifier and the implication in the premise. The proof is as follows.
115
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   305
*}
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   306
127
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   307
lemma %linenos accpartI: 
218
7ff7325e3b4e started to adapt the rest of chapter 5 to the simplified version without parameters (they will be described in the extension section)
Christian Urban <urbanc@in.tum.de>
parents: 189
diff changeset
   308
shows "(\<And>y. R y x \<Longrightarrow> accpart R y) \<Longrightarrow> accpart R x"
115
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   309
apply (unfold accpart_def)
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   310
apply (rule allI impI)+
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   311
proof -
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   312
  case (goal1 P)
127
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   313
  have p1: "\<And>y. R y x \<Longrightarrow> 
115
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   314
                   (\<forall>P. (\<forall>x. (\<forall>y. R y x \<longrightarrow> P y) \<longrightarrow> P x) \<longrightarrow> P y)" by fact
127
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   315
  have r1: "\<forall>x. (\<forall>y. R y x \<longrightarrow> P y) \<longrightarrow> P x" by fact
115
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   316
  show "P x"
127
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   317
    apply(rule r1[rule_format])
115
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   318
    proof -
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   319
      case (goal1 y)
127
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   320
      have r1_prem: "R y x" by fact
115
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   321
      show "P y"
127
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   322
	apply(rule p1[OF r1_prem, THEN spec[where x=P], THEN mp, OF r1])
115
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   323
      done
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   324
  qed
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   325
qed
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   326
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   327
text {*
218
7ff7325e3b4e started to adapt the rest of chapter 5 to the simplified version without parameters (they will be described in the extension section)
Christian Urban <urbanc@in.tum.de>
parents: 189
diff changeset
   328
  There are now two subproofs. The assumptions fall again into two categories (Lines
7ff7325e3b4e started to adapt the rest of chapter 5 to the simplified version without parameters (they will be described in the extension section)
Christian Urban <urbanc@in.tum.de>
parents: 189
diff changeset
   329
  7 to 9). In Line 11, applying the assumption @{text "r1"} generates a goal state 
7ff7325e3b4e started to adapt the rest of chapter 5 to the simplified version without parameters (they will be described in the extension section)
Christian Urban <urbanc@in.tum.de>
parents: 189
diff changeset
   330
  with the new local assumption @{term "R y x"}, named @{text "r1_prem"} in the 
7ff7325e3b4e started to adapt the rest of chapter 5 to the simplified version without parameters (they will be described in the extension section)
Christian Urban <urbanc@in.tum.de>
parents: 189
diff changeset
   331
  proof (Line 14). This local assumption is used to solve
129
e0d368a45537 started a section about simprocs
Christian Urban <urbanc@in.tum.de>
parents: 127
diff changeset
   332
  the goal @{term "P y"} with the help of assumption @{text "p1"}.
124
0b9fa606a746 added to the first-steps section
Christian Urban <urbanc@in.tum.de>
parents: 120
diff changeset
   333
116
c9ff326e3ce5 more changes to the package chapter
Christian Urban <urbanc@in.tum.de>
parents: 115
diff changeset
   334
  The point of these examples is to get a feeling what the automatic proofs 
127
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   335
  should do in order to solve all inductive definitions we throw at them.
129
e0d368a45537 started a section about simprocs
Christian Urban <urbanc@in.tum.de>
parents: 127
diff changeset
   336
  This is usually the first step in writing a package. We next explain
e0d368a45537 started a section about simprocs
Christian Urban <urbanc@in.tum.de>
parents: 127
diff changeset
   337
  the parsing and typing part of the package.
127
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   338
115
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   339
*}
129
e0d368a45537 started a section about simprocs
Christian Urban <urbanc@in.tum.de>
parents: 127
diff changeset
   340
(*<*)end(*>*)