ProgTutorial/Package/Ind_Prelims.thy
author Christian Urban <urbanc@in.tum.de>
Thu, 19 Mar 2009 13:28:16 +0100
changeset 189 069d525f8f1d
parent 165 CookBook/Package/Ind_Prelims.thy@890fbfef6d6b
child 218 7ff7325e3b4e
permissions -rw-r--r--
made more of the transition from "CookBook" to "ProgTutorial"
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 {*
129
e0d368a45537 started a section about simprocs
Christian Urban <urbanc@in.tum.de>
parents: 127
diff changeset
     8
  The user will just give a specification of an inductive predicate and
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
e0d368a45537 started a section about simprocs
Christian Urban <urbanc@in.tum.de>
parents: 127
diff changeset
    11
  that correspond to the specified predicate. This will roughly mean that the
e0d368a45537 started a section about simprocs
Christian Urban <urbanc@in.tum.de>
parents: 127
diff changeset
    12
  package has three main parts, namely:
116
c9ff326e3ce5 more changes to the package chapter
Christian Urban <urbanc@in.tum.de>
parents: 115
diff changeset
    13
88
ebbd0dd008c8 adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents: 38
diff changeset
    14
127
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
    15
  \begin{itemize}
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
    16
  \item parsing the specification and typing the parsed input,
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
    17
  \item making the definitions and deriving the reasoning infrastructure, and
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
    18
  \item storing the results in the theory. 
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
    19
  \end{itemize}
88
ebbd0dd008c8 adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents: 38
diff changeset
    20
129
e0d368a45537 started a section about simprocs
Christian Urban <urbanc@in.tum.de>
parents: 127
diff changeset
    21
  Before we start with explaining all parts, let us first give three examples
e0d368a45537 started a section about simprocs
Christian Urban <urbanc@in.tum.de>
parents: 127
diff changeset
    22
  showing how to define inductive predicates by hand and then also how to
e0d368a45537 started a section about simprocs
Christian Urban <urbanc@in.tum.de>
parents: 127
diff changeset
    23
  prove by hand important properties about them. From these examples, we will
e0d368a45537 started a section about simprocs
Christian Urban <urbanc@in.tum.de>
parents: 127
diff changeset
    24
  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
    25
  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
    26
  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
    27
  sections.
e0d368a45537 started a section about simprocs
Christian Urban <urbanc@in.tum.de>
parents: 127
diff changeset
    28
127
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
    29
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
    30
  We first consider the transitive closure of a relation @{text R}. It is
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
    31
  an inductive predicate characterised by the two introduction rules:
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
    32
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
    33
  \begin{center}\small
116
c9ff326e3ce5 more changes to the package chapter
Christian Urban <urbanc@in.tum.de>
parents: 115
diff changeset
    34
  @{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
    35
  @{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
    36
  \end{center}
ebbd0dd008c8 adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents: 38
diff changeset
    37
129
e0d368a45537 started a section about simprocs
Christian Urban <urbanc@in.tum.de>
parents: 127
diff changeset
    38
  In Isabelle, the user will 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
    39
*}
88
ebbd0dd008c8 adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents: 38
diff changeset
    40
127
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
    41
simple_inductive
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
    42
  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
    43
where
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
    44
  base: "trcl\<iota> R x x"
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
    45
| 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
    46
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
    47
text {*
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
    48
  As said above the package has to make an appropriate definition and provide
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
    49
  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
    50
  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
    51
  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
    52
  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
    53
  @{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
    54
*}
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
    55
127
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
    56
definition "trcl \<equiv> 
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
    57
     \<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
    58
                  \<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
    59
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
    60
text {*
127
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
    61
  where we quantify over the predicate @{text P}. We have to use the
116
c9ff326e3ce5 more changes to the package chapter
Christian Urban <urbanc@in.tum.de>
parents: 115
diff changeset
    62
  object implication @{text "\<longrightarrow>"} and object quantification @{text "\<forall>"} for
c9ff326e3ce5 more changes to the package chapter
Christian Urban <urbanc@in.tum.de>
parents: 115
diff changeset
    63
  stating this definition (there is no other way for definitions in
127
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
    64
  HOL). However, the introduction rules and induction principles 
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
    65
  should use the meta-connectives since they simplify the
116
c9ff326e3ce5 more changes to the package chapter
Christian Urban <urbanc@in.tum.de>
parents: 115
diff changeset
    66
  reasoning for the user.
32
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
    67
127
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
    68
  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
    69
  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
    70
  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
    71
  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
    72
  (Line 5 and 6), eliminate the universal quantifier contained in it (Line~7),
115
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
    73
  and then solve the goal by assumption (Line 8).
113
9b6c9d172378 slightly updated
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
    74
32
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
    75
*}
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
    76
114
13fd0a83d3c3 properly handled linenumbers in ML-text and Isar-proofs
Christian Urban <urbanc@in.tum.de>
parents: 113
diff changeset
    77
lemma %linenos trcl_induct:
165
890fbfef6d6b partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents: 129
diff changeset
    78
  assumes "trcl R x y"
32
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
    79
  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
    80
apply(atomize (full))
165
890fbfef6d6b partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents: 129
diff changeset
    81
apply(cut_tac prems)
113
9b6c9d172378 slightly updated
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
    82
apply(unfold trcl_def)
9b6c9d172378 slightly updated
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
    83
apply(drule spec[where x=P])
9b6c9d172378 slightly updated
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
    84
apply(assumption)
9b6c9d172378 slightly updated
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
    85
done
88
ebbd0dd008c8 adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents: 38
diff changeset
    86
113
9b6c9d172378 slightly updated
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
    87
text {*
127
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
    88
  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
    89
  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
    90
*}
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
    91
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
    92
lemma %linenos trcl_base: 
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
    93
  shows "trcl R x x"
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
    94
apply(unfold trcl_def)
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
    95
apply(rule allI impI)+
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
    96
apply(drule spec)
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
    97
apply(assumption)
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
    98
done
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
    99
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   100
text {*
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   101
  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
   102
  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
   103
  We then end up in the goal state:
113
9b6c9d172378 slightly updated
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
   104
*}
88
ebbd0dd008c8 adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents: 38
diff changeset
   105
113
9b6c9d172378 slightly updated
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
   106
(*<*)lemma "trcl R x x"
115
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   107
apply (unfold trcl_def)
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   108
apply (rule allI impI)+(*>*)
113
9b6c9d172378 slightly updated
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
   109
txt {* @{subgoals [display]} *}
32
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   110
(*<*)oops(*>*)
88
ebbd0dd008c8 adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents: 38
diff changeset
   111
113
9b6c9d172378 slightly updated
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
   112
text {*
127
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   113
  The two assumptions correspond to the introduction rules. Thus, all we have
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   114
  to do is to eliminate the universal quantifier in front of the first
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   115
  assumption (Line 5), and then solve the goal by assumption (Line 6).
113
9b6c9d172378 slightly updated
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
   116
*}
9b6c9d172378 slightly updated
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
   117
9b6c9d172378 slightly updated
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
   118
text {*
127
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   119
  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
   120
  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
   121
  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
   122
  rules for @{text "\<forall>"} and @{text "\<longrightarrow>"}
113
9b6c9d172378 slightly updated
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
   123
*}
9b6c9d172378 slightly updated
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
   124
127
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   125
lemma trcl_step: 
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   126
  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
   127
apply (unfold trcl_def)
127
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   128
apply (rule allI impI)+
113
9b6c9d172378 slightly updated
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
   129
127
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   130
txt {* 
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   131
  we obtain the goal state
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   132
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   133
  @{subgoals [display]} 
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   134
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   135
  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
   136
  by starting a subproof.
115
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   137
*}
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   138
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   139
proof -
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   140
  case (goal1 P)
127
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   141
  have p1: "R x y" by fact
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   142
  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
   143
                  \<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
   144
  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
   145
  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
   146
  show "P x z"
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   147
  
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   148
txt {*
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   149
  The assumptions @{text "p1"} and @{text "p2"} correspond to the premises of
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   150
  the second introduction rule; the assumptions @{text "r1"} and @{text "r2"}
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   151
  correspond to the introduction rules. We apply @{text "r2"} to the goal
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   152
  @{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
   153
  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
   154
  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
   155
  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
   156
32
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   157
*}
113
9b6c9d172378 slightly updated
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
   158
127
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   159
    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
   160
127
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   161
txt {*
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   162
  This gives us two new subgoals
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   163
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   164
  @{subgoals [display]} 
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   165
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   166
  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
   167
  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
   168
  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
   169
  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
   170
  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
   171
  the proof:
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   172
*}
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   173
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   174
    apply(rule p1)
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   175
    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
   176
    done
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   177
qed
32
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   178
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   179
text {*
127
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   180
  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
   181
  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
   182
  "blast"} would easily dispense of it.
115
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   183
*}
88
ebbd0dd008c8 adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents: 38
diff changeset
   184
127
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   185
lemma trcl_step_blast: 
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   186
  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
   187
apply(unfold trcl_def)
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   188
apply(blast)
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   189
done
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   190
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   191
text {*
116
c9ff326e3ce5 more changes to the package chapter
Christian Urban <urbanc@in.tum.de>
parents: 115
diff changeset
   192
  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
   193
  @{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
   194
  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
   195
  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
   196
  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
   197
  tactics whenever something goes wrong. Therefore if possible, automatic 
c9ff326e3ce5 more changes to the package chapter
Christian Urban <urbanc@in.tum.de>
parents: 115
diff changeset
   198
  tactics should be avoided or sufficiently constrained.
115
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   199
116
c9ff326e3ce5 more changes to the package chapter
Christian Urban <urbanc@in.tum.de>
parents: 115
diff changeset
   200
  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
   201
  also generalises to mutually inductive predicates. The next example defines
c9ff326e3ce5 more changes to the package chapter
Christian Urban <urbanc@in.tum.de>
parents: 115
diff changeset
   202
  the predicates @{text even} and @{text odd} characterised by the following
c9ff326e3ce5 more changes to the package chapter
Christian Urban <urbanc@in.tum.de>
parents: 115
diff changeset
   203
  rules:
88
ebbd0dd008c8 adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents: 38
diff changeset
   204
 
127
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   205
  \begin{center}\small
116
c9ff326e3ce5 more changes to the package chapter
Christian Urban <urbanc@in.tum.de>
parents: 115
diff changeset
   206
  @{prop[mode=Axiom] "even (0::nat)"} \hspace{5mm}
129
e0d368a45537 started a section about simprocs
Christian Urban <urbanc@in.tum.de>
parents: 127
diff changeset
   207
  @{prop[mode=Rule] "odd n \<Longrightarrow> even (Suc n)"} \hspace{5mm}
e0d368a45537 started a section about simprocs
Christian Urban <urbanc@in.tum.de>
parents: 127
diff changeset
   208
  @{prop[mode=Rule] "even n \<Longrightarrow> odd (Suc n)"}
88
ebbd0dd008c8 adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents: 38
diff changeset
   209
  \end{center}
ebbd0dd008c8 adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents: 38
diff changeset
   210
  
127
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   211
  The user will state for this inductive definition the specification:
32
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   212
*}
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   213
127
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   214
simple_inductive
165
890fbfef6d6b partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents: 129
diff changeset
   215
  even and odd
127
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   216
where
165
890fbfef6d6b partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents: 129
diff changeset
   217
  even0: "even 0"
890fbfef6d6b partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents: 129
diff changeset
   218
| evenS: "odd n \<Longrightarrow> even (Suc n)"
890fbfef6d6b partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents: 129
diff changeset
   219
| oddS: "even n \<Longrightarrow> odd (Suc n)"
32
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   220
127
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   221
text {*
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   222
  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
   223
  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
   224
  below @{text "P"} and @{text "Q"}).
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   225
*}
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   226
165
890fbfef6d6b partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents: 129
diff changeset
   227
definition "even\<iota> \<equiv> 
127
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   228
  \<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
   229
                 \<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
   230
165
890fbfef6d6b partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents: 129
diff changeset
   231
definition "odd\<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> Q n"
32
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   234
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   235
text {*
116
c9ff326e3ce5 more changes to the package chapter
Christian Urban <urbanc@in.tum.de>
parents: 115
diff changeset
   236
  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
   237
  as in the transitive closure example, namely:
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
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   240
lemma even_induct:
165
890fbfef6d6b partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents: 129
diff changeset
   241
  assumes "even n"
38
e21b2f888fa2 added a preliminary section about parsing
Christian Urban <urbanc@in.tum.de>
parents: 32
diff changeset
   242
  shows "P 0 \<Longrightarrow> 
e21b2f888fa2 added a preliminary section about parsing
Christian Urban <urbanc@in.tum.de>
parents: 32
diff changeset
   243
             (\<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
   244
apply(atomize (full))
165
890fbfef6d6b partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents: 129
diff changeset
   245
apply(cut_tac prems)
115
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   246
apply(unfold even_def)
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   247
apply(drule spec[where x=P])
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   248
apply(drule spec[where x=Q])
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   249
apply(assumption)
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   250
done
32
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   251
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   252
text {*
127
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   253
  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
   254
  instantiate here two universal quantifiers.  We omit the other induction
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   255
  principle that has @{term "Q n"} as conclusion.  The proofs of the
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   256
  introduction rules are also very similar to the ones in the @{text
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   257
  "trcl"}-example. We only show the proof of the second introduction rule.
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   258
32
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   259
*}
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   260
127
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   261
lemma %linenos evenS: 
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   262
  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
   263
apply (unfold odd_def even_def)
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   264
apply (rule allI impI)+
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   265
proof -
165
890fbfef6d6b partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents: 129
diff changeset
   266
  case (goal1 P Q)
127
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   267
  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
   268
                             \<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
   269
  have r1: "P 0" by fact
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   270
  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
   271
  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
   272
  show "P (Suc m)"
127
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   273
    apply(rule r2[rule_format])
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   274
    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
   275
	           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
   276
    done
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   277
qed
88
ebbd0dd008c8 adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents: 38
diff changeset
   278
32
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   279
text {*
127
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   280
  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
   281
  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
   282
  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
   283
  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
   284
  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
   285
  with the other rules.
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   286
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   287
116
c9ff326e3ce5 more changes to the package chapter
Christian Urban <urbanc@in.tum.de>
parents: 115
diff changeset
   288
  As a final example, we define the accessible part of a relation @{text R} characterised 
115
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   289
  by the introduction rule
88
ebbd0dd008c8 adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents: 38
diff changeset
   290
  
127
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   291
  \begin{center}\small
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   292
  \mbox{\inferrule{@{term "\<And>y. R y x \<Longrightarrow> accpart R y"}}{@{term "accpart R x"}}}
88
ebbd0dd008c8 adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents: 38
diff changeset
   293
  \end{center}
ebbd0dd008c8 adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents: 38
diff changeset
   294
ebbd0dd008c8 adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents: 38
diff changeset
   295
  whose premise 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 {*
116
c9ff326e3ce5 more changes to the package chapter
Christian Urban <urbanc@in.tum.de>
parents: 115
diff changeset
   302
  The proof of the induction principle is again straightforward.
32
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   303
*}
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   304
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   305
lemma accpart_induct:
165
890fbfef6d6b partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents: 129
diff changeset
   306
  assumes "accpart R x"
127
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   307
  shows "(\<And>x. (\<And>y. R y x \<Longrightarrow> P y) \<Longrightarrow> P x) \<Longrightarrow> P x"
115
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   308
apply(atomize (full))
165
890fbfef6d6b partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents: 129
diff changeset
   309
apply(cut_tac prems)
115
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   310
apply(unfold accpart_def)
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   311
apply(drule spec[where x=P])
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   312
apply(assumption)
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   313
done
88
ebbd0dd008c8 adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents: 38
diff changeset
   314
115
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   315
text {*
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   316
  Proving the introduction rule is a little more complicated, because the quantifier
127
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   317
  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
   318
*}
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   319
127
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   320
lemma %linenos accpartI: 
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   321
  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
   322
apply (unfold accpart_def)
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   323
apply (rule allI impI)+
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   324
proof -
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   325
  case (goal1 P)
127
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   326
  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
   327
                   (\<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
   328
  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
   329
  show "P x"
127
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   330
    apply(rule r1[rule_format])
115
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   331
    proof -
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   332
      case (goal1 y)
127
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   333
      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
   334
      show "P y"
127
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   335
	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
   336
      done
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   337
  qed
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   338
qed
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   339
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   340
text {*
127
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   341
  In Line 11, applying the assumption @{text "r1"} generates a goal state with
74846cb0fff9 updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   342
  the new local assumption @{term "R y x"}, named @{text "r1_prem"} in the 
129
e0d368a45537 started a section about simprocs
Christian Urban <urbanc@in.tum.de>
parents: 127
diff changeset
   343
  proof above (Line 14). This local assumption is used to solve
e0d368a45537 started a section about simprocs
Christian Urban <urbanc@in.tum.de>
parents: 127
diff changeset
   344
  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
   345
116
c9ff326e3ce5 more changes to the package chapter
Christian Urban <urbanc@in.tum.de>
parents: 115
diff changeset
   346
  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
   347
  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
   348
  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
   349
  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
   350
115
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   351
*}
129
e0d368a45537 started a section about simprocs
Christian Urban <urbanc@in.tum.de>
parents: 127
diff changeset
   352
(*<*)end(*>*)