CookBook/Package/Ind_Examples.thy
author Christian Urban <urbanc@in.tum.de>
Sat, 14 Feb 2009 00:11:50 +0000
changeset 116 c9ff326e3ce5
parent 115 039845fc96bd
child 120 c39f83d8daeb
permissions -rw-r--r--
more changes to the package chapter
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
32
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
     1
theory Ind_Examples
88
ebbd0dd008c8 adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents: 38
diff changeset
     2
imports Main LaTeXsugar
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
88
ebbd0dd008c8 adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents: 38
diff changeset
     5
section{* Examples of Inductive Definitions \label{sec:ind-examples} *}
32
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
     6
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
     7
text {*
116
c9ff326e3ce5 more changes to the package chapter
Christian Urban <urbanc@in.tum.de>
parents: 115
diff changeset
     8
  Let us first give three examples showing how to define by hand inductive
c9ff326e3ce5 more changes to the package chapter
Christian Urban <urbanc@in.tum.de>
parents: 115
diff changeset
     9
  predicates and then also how to prove by hand characteristic properties
c9ff326e3ce5 more changes to the package chapter
Christian Urban <urbanc@in.tum.de>
parents: 115
diff changeset
    10
  about them, such as introduction rules and induction principles. From
c9ff326e3ce5 more changes to the package chapter
Christian Urban <urbanc@in.tum.de>
parents: 115
diff changeset
    11
  these examples, we will figure out a general method for defining inductive
c9ff326e3ce5 more changes to the package chapter
Christian Urban <urbanc@in.tum.de>
parents: 115
diff changeset
    12
  predicates.  The aim in this section is \emph{not} to write proofs that are as
c9ff326e3ce5 more changes to the package chapter
Christian Urban <urbanc@in.tum.de>
parents: 115
diff changeset
    13
  beautiful as possible, but as close as possible to the ML-code we will 
c9ff326e3ce5 more changes to the package chapter
Christian Urban <urbanc@in.tum.de>
parents: 115
diff changeset
    14
  develop later.
c9ff326e3ce5 more changes to the package chapter
Christian Urban <urbanc@in.tum.de>
parents: 115
diff changeset
    15
88
ebbd0dd008c8 adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents: 38
diff changeset
    16
115
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
    17
  As a first example, let us consider the transitive closure of a relation @{text
116
c9ff326e3ce5 more changes to the package chapter
Christian Urban <urbanc@in.tum.de>
parents: 115
diff changeset
    18
  R}. It is an inductive predicate characterised by the two introduction rules:
88
ebbd0dd008c8 adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents: 38
diff changeset
    19
ebbd0dd008c8 adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents: 38
diff changeset
    20
  \begin{center}
116
c9ff326e3ce5 more changes to the package chapter
Christian Urban <urbanc@in.tum.de>
parents: 115
diff changeset
    21
  @{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
    22
  @{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
    23
  \end{center}
ebbd0dd008c8 adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents: 38
diff changeset
    24
ebbd0dd008c8 adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents: 38
diff changeset
    25
  Note that the @{text trcl} predicate has two different kinds of parameters: the
ebbd0dd008c8 adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents: 38
diff changeset
    26
  first parameter @{text R} stays \emph{fixed} throughout the definition, whereas
116
c9ff326e3ce5 more changes to the package chapter
Christian Urban <urbanc@in.tum.de>
parents: 115
diff changeset
    27
  the second and third parameter changes in the ``recursive call''. This will
c9ff326e3ce5 more changes to the package chapter
Christian Urban <urbanc@in.tum.de>
parents: 115
diff changeset
    28
  become important later on when we deal with fixed parameters and locales. 
88
ebbd0dd008c8 adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents: 38
diff changeset
    29
ebbd0dd008c8 adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents: 38
diff changeset
    30
  Since an inductively defined predicate is the least predicate closed under
ebbd0dd008c8 adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents: 38
diff changeset
    31
  a collection of introduction rules, we define the predicate @{text "trcl R x y"} in
ebbd0dd008c8 adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents: 38
diff changeset
    32
  such a way that it holds if and only if @{text "P x y"} holds for every predicate
ebbd0dd008c8 adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents: 38
diff changeset
    33
  @{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
    34
*}
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
    35
88
ebbd0dd008c8 adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents: 38
diff changeset
    36
definition "trcl R x y \<equiv> 
ebbd0dd008c8 adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents: 38
diff changeset
    37
      \<forall>P. (\<forall>x. P x x) \<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
    38
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
    39
text {*
113
9b6c9d172378 slightly updated
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
    40
  where we quantify over the predicate @{text P}. Note that we have to use the
116
c9ff326e3ce5 more changes to the package chapter
Christian Urban <urbanc@in.tum.de>
parents: 115
diff changeset
    41
  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
    42
  stating this definition (there is no other way for definitions in
c9ff326e3ce5 more changes to the package chapter
Christian Urban <urbanc@in.tum.de>
parents: 115
diff changeset
    43
  HOL). However, the introduction rules and induction principles derived later
c9ff326e3ce5 more changes to the package chapter
Christian Urban <urbanc@in.tum.de>
parents: 115
diff changeset
    44
  should use the corresponding meta-connectives since they simplify the
c9ff326e3ce5 more changes to the package chapter
Christian Urban <urbanc@in.tum.de>
parents: 115
diff changeset
    45
  reasoning for the user.
32
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
    46
116
c9ff326e3ce5 more changes to the package chapter
Christian Urban <urbanc@in.tum.de>
parents: 115
diff changeset
    47
  With this definition, the proof of the induction principle for the transitive
115
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
    48
  closure 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
    49
  connectives in the lemma to object-level connectives using the
c9ff326e3ce5 more changes to the package chapter
Christian Urban <urbanc@in.tum.de>
parents: 115
diff changeset
    50
  proof method @{text atomize} (Line 4), expand the definition of @{text trcl}
115
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
    51
  (Line 5 and 6), eliminate the universal quantifier contained in it (Line 7),
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
    52
  and then solve the goal by assumption (Line 8).
113
9b6c9d172378 slightly updated
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
    53
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
114
13fd0a83d3c3 properly handled linenumbers in ML-text and Isar-proofs
Christian Urban <urbanc@in.tum.de>
parents: 113
diff changeset
    56
lemma %linenos trcl_induct:
113
9b6c9d172378 slightly updated
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
    57
  assumes asm: "trcl R x y"
32
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
    58
  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
    59
apply(atomize (full))
9b6c9d172378 slightly updated
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
    60
apply(cut_tac asm)
9b6c9d172378 slightly updated
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
    61
apply(unfold trcl_def)
9b6c9d172378 slightly updated
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
    62
apply(drule spec[where x=P])
9b6c9d172378 slightly updated
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
    63
apply(assumption)
9b6c9d172378 slightly updated
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
    64
done
88
ebbd0dd008c8 adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents: 38
diff changeset
    65
113
9b6c9d172378 slightly updated
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
    66
text {*
115
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
    67
  The proofs for the introduction are slightly more complicated. We need to prove
116
c9ff326e3ce5 more changes to the package chapter
Christian Urban <urbanc@in.tum.de>
parents: 115
diff changeset
    68
  the facs @{prop "trcl R x x"} and @{prop "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
    69
  In order to prove the first goal, we again unfold the definition and
88
ebbd0dd008c8 adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents: 38
diff changeset
    70
  then apply the introdution rules for @{text "\<forall>"} and @{text "\<longrightarrow>"} as often as possible.
116
c9ff326e3ce5 more changes to the package chapter
Christian Urban <urbanc@in.tum.de>
parents: 115
diff changeset
    71
  We then end up in the goal state:
113
9b6c9d172378 slightly updated
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
    72
*}
88
ebbd0dd008c8 adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents: 38
diff changeset
    73
113
9b6c9d172378 slightly updated
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
    74
(*<*)lemma "trcl R x x"
115
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
    75
apply (unfold trcl_def)
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
    76
apply (rule allI impI)+(*>*)
113
9b6c9d172378 slightly updated
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
    77
txt {* @{subgoals [display]} *}
32
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
    78
(*<*)oops(*>*)
88
ebbd0dd008c8 adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents: 38
diff changeset
    79
113
9b6c9d172378 slightly updated
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
    80
text {*
9b6c9d172378 slightly updated
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
    81
  The two assumptions correspond to the introduction rules, where @{text "trcl
9b6c9d172378 slightly updated
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
    82
  R"} has been replaced by P. Thus, all we have to do is to eliminate the
9b6c9d172378 slightly updated
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
    83
  universal quantifier in front of the first assumption, and then solve the
115
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
    84
  goal by assumption. Thus the proof is:
113
9b6c9d172378 slightly updated
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
    85
*}
9b6c9d172378 slightly updated
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
    86
32
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
    87
lemma trcl_base: "trcl R x x"
113
9b6c9d172378 slightly updated
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
    88
apply(unfold trcl_def)
9b6c9d172378 slightly updated
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
    89
apply(rule allI impI)+
9b6c9d172378 slightly updated
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
    90
apply(drule spec)
9b6c9d172378 slightly updated
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
    91
apply(assumption)
9b6c9d172378 slightly updated
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
    92
done
88
ebbd0dd008c8 adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents: 38
diff changeset
    93
113
9b6c9d172378 slightly updated
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
    94
text {*
116
c9ff326e3ce5 more changes to the package chapter
Christian Urban <urbanc@in.tum.de>
parents: 115
diff changeset
    95
  Since the second @{text trcl}-rule has premises, the proof of its
c9ff326e3ce5 more changes to the package chapter
Christian Urban <urbanc@in.tum.de>
parents: 115
diff changeset
    96
  introduction rule is not as easy. After unfolding the definitions and
c9ff326e3ce5 more changes to the package chapter
Christian Urban <urbanc@in.tum.de>
parents: 115
diff changeset
    97
  applying the introduction rules for @{text "\<forall>"} and @{text "\<longrightarrow>"}, we get the
c9ff326e3ce5 more changes to the package chapter
Christian Urban <urbanc@in.tum.de>
parents: 115
diff changeset
    98
  goal state:
113
9b6c9d172378 slightly updated
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
    99
*}
9b6c9d172378 slightly updated
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
   100
9b6c9d172378 slightly updated
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
   101
(*<*)lemma "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
   102
apply (unfold trcl_def)
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   103
apply (rule allI impI)+(*>*)
113
9b6c9d172378 slightly updated
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
   104
txt {*@{subgoals [display]} *}
9b6c9d172378 slightly updated
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
   105
(*<*)oops(*>*)
9b6c9d172378 slightly updated
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
   106
9b6c9d172378 slightly updated
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
   107
text {*
116
c9ff326e3ce5 more changes to the package chapter
Christian Urban <urbanc@in.tum.de>
parents: 115
diff changeset
   108
  The third and fourth assumption correspond to the first and second
115
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   109
  introduction rule, respectively, whereas the first and second assumption
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   110
  corresponds to the pre\-mises of the introduction rule. Since we want to prove
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   111
  the second introduction rule, we apply the fourth assumption to the goal
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   112
  @{term "P x z"}. In order for the assumption to be applicable as a rule, we have to
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   113
  eliminate the universal quantifier and turn the object-level implications
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   114
  into meta-level ones. This can be accomplished using the @{text rule_format}
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   115
  attribute. Applying the assumption produces the two new subgoals
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   116
*}
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   117
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   118
(*<*)lemma "R x y \<Longrightarrow> trcl R y z \<Longrightarrow> trcl R x z"
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   119
apply (unfold trcl_def)
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   120
apply (rule allI impI)+
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   121
proof -
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   122
  case (goal1 P)
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   123
  have a4: "\<forall>x y z. R x y \<longrightarrow> P y z \<longrightarrow> P x z" by fact
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   124
  show ?case
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   125
    apply (rule a4[rule_format])(*>*)
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   126
txt {*@{subgoals [display]} *}
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   127
(*<*)oops(*>*)
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   128
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   129
text {* 
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   130
  which can be
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   131
  solved using the first and second assumption. The second assumption again
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   132
  involves a quantifier and an implications that have to be eliminated before it
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   133
  can be applied. To avoid potential problems with higher-order unification, 
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   134
  we should explcitly instantiate the universally quantified
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   135
  predicate variable to @{text "P"} and also match explicitly the implications
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   136
  with the the third and fourth assumption. This gives the proof:
32
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   137
*}
113
9b6c9d172378 slightly updated
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
   138
88
ebbd0dd008c8 adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents: 38
diff changeset
   139
32
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   140
lemma trcl_step: "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
   141
apply(unfold trcl_def)
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   142
apply(rule allI impI)+
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   143
proof -
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   144
  case (goal1 P)
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   145
  have a1: "R x y" by fact
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   146
  have a2: "\<forall>P. (\<forall>x. P x x) 
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   147
                  \<longrightarrow> (\<forall>x y z. R x y \<longrightarrow> P y z \<longrightarrow> P x z) \<longrightarrow> P y z" by fact
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   148
  have a3: "\<forall>x. P x x" by fact
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   149
  have a4: "\<forall>x y z. R x y \<longrightarrow> P y z \<longrightarrow> P x z" by fact
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   150
  show "P x z"
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   151
    apply(rule a4[rule_format])
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   152
    apply(rule a1)
116
c9ff326e3ce5 more changes to the package chapter
Christian Urban <urbanc@in.tum.de>
parents: 115
diff changeset
   153
    apply(rule a2[THEN spec[where x=P], THEN mp, THEN mp, OF a3, OF a4])
115
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   154
    done
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   155
qed
32
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   156
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   157
text {*
116
c9ff326e3ce5 more changes to the package chapter
Christian Urban <urbanc@in.tum.de>
parents: 115
diff changeset
   158
  It might be surprising that we are not using the automatic tactics available in
c9ff326e3ce5 more changes to the package chapter
Christian Urban <urbanc@in.tum.de>
parents: 115
diff changeset
   159
  Isabelle for proving this lemmas. After all @{text "blast"} would easily 
c9ff326e3ce5 more changes to the package chapter
Christian Urban <urbanc@in.tum.de>
parents: 115
diff changeset
   160
  dispense of it.
115
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   161
*}
88
ebbd0dd008c8 adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents: 38
diff changeset
   162
115
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   163
lemma trcl_step_blast: "R x y \<Longrightarrow> trcl R y z \<Longrightarrow> trcl R x z"
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   164
apply(unfold trcl_def)
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   165
apply(blast)
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   166
done
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   167
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   168
text {*
116
c9ff326e3ce5 more changes to the package chapter
Christian Urban <urbanc@in.tum.de>
parents: 115
diff changeset
   169
  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
   170
  @{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
   171
  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
   172
  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
   173
  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
   174
  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
   175
  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
   176
116
c9ff326e3ce5 more changes to the package chapter
Christian Urban <urbanc@in.tum.de>
parents: 115
diff changeset
   177
  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
   178
  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
   179
  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
   180
  rules:
88
ebbd0dd008c8 adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents: 38
diff changeset
   181
 
ebbd0dd008c8 adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents: 38
diff changeset
   182
  \begin{center}
116
c9ff326e3ce5 more changes to the package chapter
Christian Urban <urbanc@in.tum.de>
parents: 115
diff changeset
   183
  @{prop[mode=Axiom] "even (0::nat)"} \hspace{5mm}
c9ff326e3ce5 more changes to the package chapter
Christian Urban <urbanc@in.tum.de>
parents: 115
diff changeset
   184
  @{prop[mode=Rule] "odd m \<Longrightarrow> even (Suc m)"} \hspace{5mm}
c9ff326e3ce5 more changes to the package chapter
Christian Urban <urbanc@in.tum.de>
parents: 115
diff changeset
   185
  @{prop[mode=Rule] "even m \<Longrightarrow> odd (Suc m)"}
88
ebbd0dd008c8 adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents: 38
diff changeset
   186
  \end{center}
ebbd0dd008c8 adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents: 38
diff changeset
   187
  
115
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   188
  Since the predicates are mutually inductive, each definition 
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   189
  quantifies over both predicates, below named @{text P} and @{text Q}.
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
88
ebbd0dd008c8 adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents: 38
diff changeset
   192
definition "even n \<equiv> 
ebbd0dd008c8 adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents: 38
diff changeset
   193
  \<forall>P Q. P 0 \<longrightarrow> (\<forall>m. Q m \<longrightarrow> P (Suc m)) 
ebbd0dd008c8 adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents: 38
diff changeset
   194
             \<longrightarrow> (\<forall>m. P m \<longrightarrow> Q (Suc m)) \<longrightarrow> P n"
32
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
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
definition "odd n \<equiv>
ebbd0dd008c8 adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents: 38
diff changeset
   197
  \<forall>P Q. P 0 \<longrightarrow> (\<forall>m. Q m \<longrightarrow> P (Suc m)) 
ebbd0dd008c8 adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents: 38
diff changeset
   198
             \<longrightarrow> (\<forall>m. P m \<longrightarrow> Q (Suc m)) \<longrightarrow> Q n"
32
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   199
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   200
text {*
116
c9ff326e3ce5 more changes to the package chapter
Christian Urban <urbanc@in.tum.de>
parents: 115
diff changeset
   201
  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
   202
  as in the transitive closure example, namely:
32
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   203
*}
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   204
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   205
lemma even_induct:
115
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   206
  assumes asm: "even n"
38
e21b2f888fa2 added a preliminary section about parsing
Christian Urban <urbanc@in.tum.de>
parents: 32
diff changeset
   207
  shows "P 0 \<Longrightarrow> 
e21b2f888fa2 added a preliminary section about parsing
Christian Urban <urbanc@in.tum.de>
parents: 32
diff changeset
   208
             (\<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
   209
apply(atomize (full))
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   210
apply(cut_tac asm)
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   211
apply(unfold even_def)
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   212
apply(drule spec[where x=P])
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   213
apply(drule spec[where x=Q])
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   214
apply(assumption)
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   215
done
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
text {*
116
c9ff326e3ce5 more changes to the package chapter
Christian Urban <urbanc@in.tum.de>
parents: 115
diff changeset
   218
  We omit the other induction principle that has @{term "Q n"} as conclusion.
88
ebbd0dd008c8 adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents: 38
diff changeset
   219
  The proofs of the introduction rules are also very similar to the ones in the
116
c9ff326e3ce5 more changes to the package chapter
Christian Urban <urbanc@in.tum.de>
parents: 115
diff changeset
   220
  @{text "trcl"}-example. We only show the proof of the second introduction rule.
32
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   221
*}
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   222
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   223
lemma evenS: "odd m \<Longrightarrow> even (Suc m)"
115
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   224
apply (unfold odd_def even_def)
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   225
apply (rule allI impI)+
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   226
proof -
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   227
  case (goal1 P)
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   228
  have a1: "\<forall>P Q. P 0 \<longrightarrow> (\<forall>m. Q m \<longrightarrow> P (Suc m)) 
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   229
                             \<longrightarrow> (\<forall>m. P m \<longrightarrow> Q (Suc m)) \<longrightarrow> Q m" by fact
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   230
  have a2: "P 0" by fact
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   231
  have a3: "\<forall>m. Q m \<longrightarrow> P (Suc m)" by fact
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   232
  have a4: "\<forall>m. P m \<longrightarrow> Q (Suc m)" by fact
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   233
  show "P (Suc m)"
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   234
    apply(rule a3[rule_format])
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   235
    apply(rule a1[THEN spec[where x=P], THEN spec[where x=Q],
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   236
	THEN mp, THEN mp, THEN mp, OF a2, OF a3, OF a4])
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   237
    done
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   238
qed
88
ebbd0dd008c8 adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents: 38
diff changeset
   239
32
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   240
text {*
116
c9ff326e3ce5 more changes to the package chapter
Christian Urban <urbanc@in.tum.de>
parents: 115
diff changeset
   241
  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
   242
  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
   243
  
ebbd0dd008c8 adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents: 38
diff changeset
   244
  \begin{center}
ebbd0dd008c8 adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents: 38
diff changeset
   245
  @{term[mode=Rule] "(\<forall>y. R y x \<longrightarrow> accpart R y) \<Longrightarrow> accpart R x"}
ebbd0dd008c8 adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents: 38
diff changeset
   246
  \end{center}
ebbd0dd008c8 adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents: 38
diff changeset
   247
ebbd0dd008c8 adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents: 38
diff changeset
   248
  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
   249
  definition of @{text accpart} is:
32
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   250
*}
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   251
88
ebbd0dd008c8 adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents: 38
diff changeset
   252
definition "accpart R x \<equiv> \<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
   253
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   254
text {*
116
c9ff326e3ce5 more changes to the package chapter
Christian Urban <urbanc@in.tum.de>
parents: 115
diff changeset
   255
  The proof of the induction principle is again straightforward.
32
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   256
*}
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   257
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   258
lemma accpart_induct:
115
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   259
  assumes asm: "accpart R x"
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   260
  shows "(\<And>x. (\<forall>y. R y x \<longrightarrow> P y) \<Longrightarrow> P x) \<Longrightarrow> P x"
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   261
apply(atomize (full))
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   262
apply(cut_tac asm)
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   263
apply(unfold accpart_def)
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   264
apply(drule spec[where x=P])
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   265
apply(assumption)
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   266
done
88
ebbd0dd008c8 adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents: 38
diff changeset
   267
115
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   268
text {*
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   269
  Proving the introduction rule is a little more complicated, because the quantifier
88
ebbd0dd008c8 adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents: 38
diff changeset
   270
  and the implication in the premise. We first convert the meta-level universal quantifier
ebbd0dd008c8 adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents: 38
diff changeset
   271
  and implication to their object-level counterparts. Unfolding the definition of
ebbd0dd008c8 adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents: 38
diff changeset
   272
  @{text accpart} and applying the introduction rules for @{text "\<forall>"} and @{text "\<longrightarrow>"}
ebbd0dd008c8 adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents: 38
diff changeset
   273
  yields the following proof state:
115
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   274
*}
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   275
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   276
(*<*)lemma accpartI: "(\<forall>y. R y x \<longrightarrow> accpart R y) \<Longrightarrow> accpart R x"
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   277
apply (unfold accpart_def)
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   278
apply (rule allI impI)+(*>*)
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   279
txt {* @{subgoals [display]} *}
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   280
(*<*)oops(*>*)
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   281
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   282
text {*
88
ebbd0dd008c8 adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents: 38
diff changeset
   283
  Applying the second assumption produces a proof state with the new local assumption
ebbd0dd008c8 adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents: 38
diff changeset
   284
  @{term "R y x"}, which will then be used to solve the goal @{term "P y"} using the
ebbd0dd008c8 adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents: 38
diff changeset
   285
  first assumption.
32
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   286
*}
88
ebbd0dd008c8 adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents: 38
diff changeset
   287
115
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   288
lemma %small accpartI: "(\<forall>y. R y x \<longrightarrow> accpart R y) \<Longrightarrow> accpart R x"
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   289
apply (unfold accpart_def)
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   290
apply (rule allI impI)+
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   291
proof -
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   292
  case (goal1 P)
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   293
  have a1: "\<forall>y. R y x \<longrightarrow> 
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   294
                   (\<forall>P. (\<forall>x. (\<forall>y. R y x \<longrightarrow> P y) \<longrightarrow> P x) \<longrightarrow> P y)" by fact
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   295
  have a2: "\<forall>x. (\<forall>y. R y x \<longrightarrow> P y) \<longrightarrow> P x" by fact
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   296
  show "P x"
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   297
    apply(rule a2[rule_format])
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   298
    proof -
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   299
      case (goal1 y)
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   300
      have a3: "R y x" by fact
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   301
      show "P y"
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   302
      apply(rule a1[THEN spec[where x=y], THEN mp, OF a3, 
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   303
            THEN spec[where x=P], THEN mp, OF a2])
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   304
      done
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   305
  qed
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   306
qed
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   307
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   308
text {*
116
c9ff326e3ce5 more changes to the package chapter
Christian Urban <urbanc@in.tum.de>
parents: 115
diff changeset
   309
  The point of these examples is to get a feeling what the automatic proofs 
c9ff326e3ce5 more changes to the package chapter
Christian Urban <urbanc@in.tum.de>
parents: 115
diff changeset
   310
  should do in order to solve all inductive definitions we throw at them. For this 
c9ff326e3ce5 more changes to the package chapter
Christian Urban <urbanc@in.tum.de>
parents: 115
diff changeset
   311
  it is instructive to look at the general construction principle 
c9ff326e3ce5 more changes to the package chapter
Christian Urban <urbanc@in.tum.de>
parents: 115
diff changeset
   312
  of inductive definitions, which we shall do in the next section.
115
039845fc96bd some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents: 114
diff changeset
   313
*}
32
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   314
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   315
end