author | Christian Urban <urbanc@in.tum.de> |
Fri, 20 Feb 2009 23:19:41 +0000 | |
changeset 127 | 74846cb0fff9 |
parent 124 | CookBook/Package/Ind_Examples.thy@0b9fa606a746 |
child 129 | e0d368a45537 |
permissions | -rw-r--r-- |
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 | 3 |
begin |
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 | 7 |
text {* |
127
74846cb0fff9
updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents:
124
diff
changeset
|
8 |
On the Isabelle level, the user will just give a specification of an |
74846cb0fff9
updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents:
124
diff
changeset
|
9 |
inductive predicate and expects from the package to produce a convenient |
74846cb0fff9
updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents:
124
diff
changeset
|
10 |
reasoning infrastructure. This infrastructure needs to be derived from the |
74846cb0fff9
updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents:
124
diff
changeset
|
11 |
definition that correspond to the specified predicate. This will roughly |
74846cb0fff9
updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents:
124
diff
changeset
|
12 |
mean that the 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 |
|
127
74846cb0fff9
updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents:
124
diff
changeset
|
21 |
Before we start with explaining all parts, |
74846cb0fff9
updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents:
124
diff
changeset
|
22 |
let us first give three examples showing how to define inductive predicates |
74846cb0fff9
updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents:
124
diff
changeset
|
23 |
by hand and then also how to prove by hand important properties about |
74846cb0fff9
updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents:
124
diff
changeset
|
24 |
them. From these examples, we will figure out a general method for defining |
74846cb0fff9
updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents:
124
diff
changeset
|
25 |
inductive predicates. The aim in this section is \emph{not} to write proofs |
74846cb0fff9
updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents:
124
diff
changeset
|
26 |
that are as beautiful as possible, but as close as possible to the ML-code |
74846cb0fff9
updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents:
124
diff
changeset
|
27 |
we will develop in later sections. |
74846cb0fff9
updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents:
124
diff
changeset
|
28 |
|
74846cb0fff9
updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents:
124
diff
changeset
|
29 |
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
|
30 |
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
|
31 |
|
74846cb0fff9
updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents:
124
diff
changeset
|
32 |
\begin{center}\small |
116
c9ff326e3ce5
more changes to the package chapter
Christian Urban <urbanc@in.tum.de>
parents:
115
diff
changeset
|
33 |
@{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
|
34 |
@{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
|
35 |
\end{center} |
ebbd0dd008c8
adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents:
38
diff
changeset
|
36 |
|
127
74846cb0fff9
updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents:
124
diff
changeset
|
37 |
In Isabelle the user will state for @{term trcl\<iota>} the specification: |
74846cb0fff9
updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents:
124
diff
changeset
|
38 |
*} |
88
ebbd0dd008c8
adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents:
38
diff
changeset
|
39 |
|
127
74846cb0fff9
updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents:
124
diff
changeset
|
40 |
simple_inductive |
74846cb0fff9
updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents:
124
diff
changeset
|
41 |
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
|
42 |
where |
74846cb0fff9
updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents:
124
diff
changeset
|
43 |
base: "trcl\<iota> R x x" |
74846cb0fff9
updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents:
124
diff
changeset
|
44 |
| 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
|
45 |
|
74846cb0fff9
updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents:
124
diff
changeset
|
46 |
text {* |
74846cb0fff9
updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents:
124
diff
changeset
|
47 |
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
|
48 |
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
|
49 |
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
|
50 |
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
|
51 |
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
|
52 |
@{text P} closed under the rules above. This gives rise to the definition |
32 | 53 |
*} |
54 |
||
127
74846cb0fff9
updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents:
124
diff
changeset
|
55 |
definition "trcl \<equiv> |
74846cb0fff9
updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents:
124
diff
changeset
|
56 |
\<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
|
57 |
\<longrightarrow> (\<forall>x y z. R x y \<longrightarrow> P y z \<longrightarrow> P x z) \<longrightarrow> P x y" |
32 | 58 |
|
59 |
text {* |
|
127
74846cb0fff9
updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents:
124
diff
changeset
|
60 |
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
|
61 |
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
|
62 |
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
|
63 |
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
|
64 |
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
|
65 |
reasoning for the user. |
32 | 66 |
|
127
74846cb0fff9
updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents:
124
diff
changeset
|
67 |
With this definition, the proof of the induction principle for @{term trcl} |
115
039845fc96bd
some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents:
114
diff
changeset
|
68 |
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
|
69 |
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
|
70 |
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
|
71 |
(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
|
72 |
and then solve the goal by assumption (Line 8). |
113 | 73 |
|
32 | 74 |
*} |
75 |
||
114
13fd0a83d3c3
properly handled linenumbers in ML-text and Isar-proofs
Christian Urban <urbanc@in.tum.de>
parents:
113
diff
changeset
|
76 |
lemma %linenos trcl_induct: |
113 | 77 |
assumes asm: "trcl R x y" |
32 | 78 |
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 | 79 |
apply(atomize (full)) |
80 |
apply(cut_tac asm) |
|
81 |
apply(unfold trcl_def) |
|
82 |
apply(drule spec[where x=P]) |
|
83 |
apply(assumption) |
|
84 |
done |
|
88
ebbd0dd008c8
adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents:
38
diff
changeset
|
85 |
|
113 | 86 |
text {* |
127
74846cb0fff9
updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents:
124
diff
changeset
|
87 |
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
|
88 |
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
|
89 |
*} |
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 |
lemma %linenos trcl_base: |
74846cb0fff9
updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents:
124
diff
changeset
|
92 |
shows "trcl R x x" |
74846cb0fff9
updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents:
124
diff
changeset
|
93 |
apply(unfold trcl_def) |
74846cb0fff9
updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents:
124
diff
changeset
|
94 |
apply(rule allI impI)+ |
74846cb0fff9
updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents:
124
diff
changeset
|
95 |
apply(drule spec) |
74846cb0fff9
updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents:
124
diff
changeset
|
96 |
apply(assumption) |
74846cb0fff9
updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents:
124
diff
changeset
|
97 |
done |
74846cb0fff9
updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents:
124
diff
changeset
|
98 |
|
74846cb0fff9
updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents:
124
diff
changeset
|
99 |
text {* |
74846cb0fff9
updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents:
124
diff
changeset
|
100 |
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
|
101 |
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
|
102 |
We then end up in the goal state: |
113 | 103 |
*} |
88
ebbd0dd008c8
adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents:
38
diff
changeset
|
104 |
|
113 | 105 |
(*<*)lemma "trcl R x x" |
115
039845fc96bd
some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents:
114
diff
changeset
|
106 |
apply (unfold trcl_def) |
039845fc96bd
some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents:
114
diff
changeset
|
107 |
apply (rule allI impI)+(*>*) |
113 | 108 |
txt {* @{subgoals [display]} *} |
32 | 109 |
(*<*)oops(*>*) |
88
ebbd0dd008c8
adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents:
38
diff
changeset
|
110 |
|
113 | 111 |
text {* |
127
74846cb0fff9
updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents:
124
diff
changeset
|
112 |
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
|
113 |
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
|
114 |
assumption (Line 5), and then solve the goal by assumption (Line 6). |
113 | 115 |
*} |
116 |
||
117 |
text {* |
|
127
74846cb0fff9
updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents:
124
diff
changeset
|
118 |
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
|
119 |
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
|
120 |
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
|
121 |
rules for @{text "\<forall>"} and @{text "\<longrightarrow>"} |
113 | 122 |
*} |
123 |
||
127
74846cb0fff9
updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents:
124
diff
changeset
|
124 |
lemma trcl_step: |
74846cb0fff9
updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents:
124
diff
changeset
|
125 |
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
|
126 |
apply (unfold trcl_def) |
127
74846cb0fff9
updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents:
124
diff
changeset
|
127 |
apply (rule allI impI)+ |
113 | 128 |
|
127
74846cb0fff9
updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents:
124
diff
changeset
|
129 |
txt {* |
74846cb0fff9
updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents:
124
diff
changeset
|
130 |
we obtain the goal state |
74846cb0fff9
updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents:
124
diff
changeset
|
131 |
|
74846cb0fff9
updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents:
124
diff
changeset
|
132 |
@{subgoals [display]} |
74846cb0fff9
updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents:
124
diff
changeset
|
133 |
|
74846cb0fff9
updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents:
124
diff
changeset
|
134 |
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
|
135 |
by starting a subproof. |
115
039845fc96bd
some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents:
114
diff
changeset
|
136 |
*} |
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 |
proof - |
039845fc96bd
some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents:
114
diff
changeset
|
139 |
case (goal1 P) |
127
74846cb0fff9
updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents:
124
diff
changeset
|
140 |
have p1: "R x y" by fact |
74846cb0fff9
updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents:
124
diff
changeset
|
141 |
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
|
142 |
\<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
|
143 |
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
|
144 |
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
|
145 |
show "P x z" |
74846cb0fff9
updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents:
124
diff
changeset
|
146 |
|
74846cb0fff9
updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents:
124
diff
changeset
|
147 |
txt {* |
74846cb0fff9
updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents:
124
diff
changeset
|
148 |
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
|
149 |
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
|
150 |
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
|
151 |
@{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
|
152 |
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
|
153 |
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
|
154 |
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
|
155 |
|
32 | 156 |
*} |
113 | 157 |
|
127
74846cb0fff9
updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents:
124
diff
changeset
|
158 |
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
|
159 |
|
127
74846cb0fff9
updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents:
124
diff
changeset
|
160 |
txt {* |
74846cb0fff9
updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents:
124
diff
changeset
|
161 |
This gives us two new subgoals |
74846cb0fff9
updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents:
124
diff
changeset
|
162 |
|
74846cb0fff9
updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents:
124
diff
changeset
|
163 |
@{subgoals [display]} |
74846cb0fff9
updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents:
124
diff
changeset
|
164 |
|
74846cb0fff9
updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents:
124
diff
changeset
|
165 |
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
|
166 |
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
|
167 |
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
|
168 |
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
|
169 |
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
|
170 |
the proof: |
74846cb0fff9
updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents:
124
diff
changeset
|
171 |
*} |
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 |
apply(rule p1) |
74846cb0fff9
updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents:
124
diff
changeset
|
174 |
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
|
175 |
done |
039845fc96bd
some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents:
114
diff
changeset
|
176 |
qed |
32 | 177 |
|
178 |
text {* |
|
127
74846cb0fff9
updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents:
124
diff
changeset
|
179 |
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
|
180 |
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
|
181 |
"blast"} would easily dispense of it. |
115
039845fc96bd
some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents:
114
diff
changeset
|
182 |
*} |
88
ebbd0dd008c8
adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents:
38
diff
changeset
|
183 |
|
127
74846cb0fff9
updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents:
124
diff
changeset
|
184 |
lemma trcl_step_blast: |
74846cb0fff9
updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents:
124
diff
changeset
|
185 |
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
|
186 |
apply(unfold trcl_def) |
039845fc96bd
some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents:
114
diff
changeset
|
187 |
apply(blast) |
039845fc96bd
some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents:
114
diff
changeset
|
188 |
done |
039845fc96bd
some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents:
114
diff
changeset
|
189 |
|
039845fc96bd
some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents:
114
diff
changeset
|
190 |
text {* |
116
c9ff326e3ce5
more changes to the package chapter
Christian Urban <urbanc@in.tum.de>
parents:
115
diff
changeset
|
191 |
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
|
192 |
@{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
|
193 |
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
|
194 |
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
|
195 |
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
|
196 |
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
|
197 |
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
|
198 |
|
116
c9ff326e3ce5
more changes to the package chapter
Christian Urban <urbanc@in.tum.de>
parents:
115
diff
changeset
|
199 |
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
|
200 |
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
|
201 |
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
|
202 |
rules: |
88
ebbd0dd008c8
adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents:
38
diff
changeset
|
203 |
|
127
74846cb0fff9
updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents:
124
diff
changeset
|
204 |
\begin{center}\small |
116
c9ff326e3ce5
more changes to the package chapter
Christian Urban <urbanc@in.tum.de>
parents:
115
diff
changeset
|
205 |
@{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
|
206 |
@{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
|
207 |
@{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
|
208 |
\end{center} |
ebbd0dd008c8
adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents:
38
diff
changeset
|
209 |
|
127
74846cb0fff9
updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents:
124
diff
changeset
|
210 |
The user will state for this inductive definition the specification: |
32 | 211 |
*} |
212 |
||
127
74846cb0fff9
updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents:
124
diff
changeset
|
213 |
simple_inductive |
74846cb0fff9
updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents:
124
diff
changeset
|
214 |
even\<iota> and odd\<iota> |
74846cb0fff9
updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents:
124
diff
changeset
|
215 |
where |
74846cb0fff9
updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents:
124
diff
changeset
|
216 |
even0: "even\<iota> 0" |
74846cb0fff9
updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents:
124
diff
changeset
|
217 |
| evenS: "odd\<iota> n \<Longrightarrow> even\<iota> (Suc n)" |
74846cb0fff9
updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents:
124
diff
changeset
|
218 |
| oddS: "even\<iota> n \<Longrightarrow> odd\<iota> (Suc n)" |
32 | 219 |
|
127
74846cb0fff9
updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents:
124
diff
changeset
|
220 |
text {* |
74846cb0fff9
updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents:
124
diff
changeset
|
221 |
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
|
222 |
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
|
223 |
below @{text "P"} and @{text "Q"}). |
74846cb0fff9
updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents:
124
diff
changeset
|
224 |
*} |
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 |
definition "even \<equiv> |
74846cb0fff9
updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents:
124
diff
changeset
|
227 |
\<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
|
228 |
\<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
|
229 |
|
74846cb0fff9
updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents:
124
diff
changeset
|
230 |
definition "odd \<equiv> |
74846cb0fff9
updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents:
124
diff
changeset
|
231 |
\<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
|
232 |
\<longrightarrow> (\<forall>m. P m \<longrightarrow> Q (Suc m)) \<longrightarrow> Q n" |
32 | 233 |
|
234 |
text {* |
|
116
c9ff326e3ce5
more changes to the package chapter
Christian Urban <urbanc@in.tum.de>
parents:
115
diff
changeset
|
235 |
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
|
236 |
as in the transitive closure example, namely: |
32 | 237 |
*} |
238 |
||
239 |
lemma even_induct: |
|
115
039845fc96bd
some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents:
114
diff
changeset
|
240 |
assumes asm: "even n" |
38
e21b2f888fa2
added a preliminary section about parsing
Christian Urban <urbanc@in.tum.de>
parents:
32
diff
changeset
|
241 |
shows "P 0 \<Longrightarrow> |
e21b2f888fa2
added a preliminary section about parsing
Christian Urban <urbanc@in.tum.de>
parents:
32
diff
changeset
|
242 |
(\<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
|
243 |
apply(atomize (full)) |
039845fc96bd
some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents:
114
diff
changeset
|
244 |
apply(cut_tac asm) |
039845fc96bd
some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents:
114
diff
changeset
|
245 |
apply(unfold even_def) |
039845fc96bd
some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents:
114
diff
changeset
|
246 |
apply(drule spec[where x=P]) |
039845fc96bd
some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents:
114
diff
changeset
|
247 |
apply(drule spec[where x=Q]) |
039845fc96bd
some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents:
114
diff
changeset
|
248 |
apply(assumption) |
039845fc96bd
some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents:
114
diff
changeset
|
249 |
done |
32 | 250 |
|
251 |
text {* |
|
127
74846cb0fff9
updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents:
124
diff
changeset
|
252 |
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
|
253 |
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
|
254 |
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
|
255 |
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
|
256 |
"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
|
257 |
|
32 | 258 |
*} |
259 |
||
127
74846cb0fff9
updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents:
124
diff
changeset
|
260 |
lemma %linenos evenS: |
74846cb0fff9
updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents:
124
diff
changeset
|
261 |
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
|
262 |
apply (unfold odd_def even_def) |
039845fc96bd
some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents:
114
diff
changeset
|
263 |
apply (rule allI impI)+ |
039845fc96bd
some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents:
114
diff
changeset
|
264 |
proof - |
039845fc96bd
some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents:
114
diff
changeset
|
265 |
case (goal1 P) |
127
74846cb0fff9
updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents:
124
diff
changeset
|
266 |
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
|
267 |
\<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
|
268 |
have r1: "P 0" by fact |
74846cb0fff9
updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents:
124
diff
changeset
|
269 |
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
|
270 |
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
|
271 |
show "P (Suc m)" |
127
74846cb0fff9
updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents:
124
diff
changeset
|
272 |
apply(rule r2[rule_format]) |
74846cb0fff9
updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents:
124
diff
changeset
|
273 |
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
|
274 |
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
|
275 |
done |
039845fc96bd
some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents:
114
diff
changeset
|
276 |
qed |
88
ebbd0dd008c8
adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents:
38
diff
changeset
|
277 |
|
32 | 278 |
text {* |
127
74846cb0fff9
updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents:
124
diff
changeset
|
279 |
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
|
280 |
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
|
281 |
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
|
282 |
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
|
283 |
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
|
284 |
with the other rules. |
74846cb0fff9
updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents:
124
diff
changeset
|
285 |
|
74846cb0fff9
updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents:
124
diff
changeset
|
286 |
|
116
c9ff326e3ce5
more changes to the package chapter
Christian Urban <urbanc@in.tum.de>
parents:
115
diff
changeset
|
287 |
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
|
288 |
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
|
289 |
|
127
74846cb0fff9
updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents:
124
diff
changeset
|
290 |
\begin{center}\small |
74846cb0fff9
updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents:
124
diff
changeset
|
291 |
\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
|
292 |
\end{center} |
ebbd0dd008c8
adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents:
38
diff
changeset
|
293 |
|
ebbd0dd008c8
adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents:
38
diff
changeset
|
294 |
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
|
295 |
definition of @{text accpart} is: |
32 | 296 |
*} |
297 |
||
127
74846cb0fff9
updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents:
124
diff
changeset
|
298 |
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 | 299 |
|
300 |
text {* |
|
116
c9ff326e3ce5
more changes to the package chapter
Christian Urban <urbanc@in.tum.de>
parents:
115
diff
changeset
|
301 |
The proof of the induction principle is again straightforward. |
32 | 302 |
*} |
303 |
||
304 |
lemma accpart_induct: |
|
115
039845fc96bd
some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents:
114
diff
changeset
|
305 |
assumes asm: "accpart R x" |
127
74846cb0fff9
updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents:
124
diff
changeset
|
306 |
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
|
307 |
apply(atomize (full)) |
039845fc96bd
some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents:
114
diff
changeset
|
308 |
apply(cut_tac asm) |
039845fc96bd
some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents:
114
diff
changeset
|
309 |
apply(unfold accpart_def) |
039845fc96bd
some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents:
114
diff
changeset
|
310 |
apply(drule spec[where x=P]) |
039845fc96bd
some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents:
114
diff
changeset
|
311 |
apply(assumption) |
039845fc96bd
some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents:
114
diff
changeset
|
312 |
done |
88
ebbd0dd008c8
adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents:
38
diff
changeset
|
313 |
|
115
039845fc96bd
some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents:
114
diff
changeset
|
314 |
text {* |
039845fc96bd
some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents:
114
diff
changeset
|
315 |
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
|
316 |
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
|
317 |
*} |
039845fc96bd
some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents:
114
diff
changeset
|
318 |
|
127
74846cb0fff9
updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents:
124
diff
changeset
|
319 |
lemma %linenos accpartI: |
74846cb0fff9
updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents:
124
diff
changeset
|
320 |
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
|
321 |
apply (unfold accpart_def) |
039845fc96bd
some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents:
114
diff
changeset
|
322 |
apply (rule allI impI)+ |
039845fc96bd
some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents:
114
diff
changeset
|
323 |
proof - |
039845fc96bd
some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents:
114
diff
changeset
|
324 |
case (goal1 P) |
127
74846cb0fff9
updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents:
124
diff
changeset
|
325 |
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
|
326 |
(\<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
|
327 |
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
|
328 |
show "P x" |
127
74846cb0fff9
updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents:
124
diff
changeset
|
329 |
apply(rule r1[rule_format]) |
115
039845fc96bd
some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents:
114
diff
changeset
|
330 |
proof - |
039845fc96bd
some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents:
114
diff
changeset
|
331 |
case (goal1 y) |
127
74846cb0fff9
updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents:
124
diff
changeset
|
332 |
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
|
333 |
show "P y" |
127
74846cb0fff9
updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents:
124
diff
changeset
|
334 |
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
|
335 |
done |
039845fc96bd
some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents:
114
diff
changeset
|
336 |
qed |
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 |
|
039845fc96bd
some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents:
114
diff
changeset
|
339 |
text {* |
127
74846cb0fff9
updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents:
124
diff
changeset
|
340 |
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
|
341 |
the new local assumption @{term "R y x"}, named @{text "r1_prem"} in the |
74846cb0fff9
updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents:
124
diff
changeset
|
342 |
proof above (Line 14). This local assumption will be used to solve |
74846cb0fff9
updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents:
124
diff
changeset
|
343 |
the goal @{term "P y"} using the assumption @{text "p1"}. |
124
0b9fa606a746
added to the first-steps section
Christian Urban <urbanc@in.tum.de>
parents:
120
diff
changeset
|
344 |
|
116
c9ff326e3ce5
more changes to the package chapter
Christian Urban <urbanc@in.tum.de>
parents:
115
diff
changeset
|
345 |
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
|
346 |
should do in order to solve all inductive definitions we throw at them. |
74846cb0fff9
updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents:
124
diff
changeset
|
347 |
This is usually the first step in writing a package. |
74846cb0fff9
updated and added two tentative recipes
Christian Urban <urbanc@in.tum.de>
parents:
124
diff
changeset
|
348 |
|
115
039845fc96bd
some update of the package introduction
Christian Urban <urbanc@in.tum.de>
parents:
114
diff
changeset
|
349 |
*} |
32 | 350 |
|
351 |
end |