92 |
92 |
93 lemmas myrule = simple[THEN spec, THEN mp, THEN mp]; |
93 lemmas myrule = simple[THEN spec, THEN mp, THEN mp]; |
94 |
94 |
95 text{*\noindent |
95 text{*\noindent |
96 or the wholesale stripping of @{text"\<forall>"} and |
96 or the wholesale stripping of @{text"\<forall>"} and |
97 @{text"\<longrightarrow>"} in the conclusion via @{text"rulify"} |
97 @{text"\<longrightarrow>"} in the conclusion via @{text"rulified"} |
98 *}; |
98 *}; |
99 |
99 |
100 lemmas myrule = simple[rulify]; |
100 lemmas myrule = simple[rulified]; |
101 |
101 |
102 text{*\noindent |
102 text{*\noindent |
103 yielding @{thm"myrule"[no_vars]}. |
103 yielding @{thm"myrule"[no_vars]}. |
104 You can go one step further and include these derivations already in the |
104 You can go one step further and include these derivations already in the |
105 statement of your original lemma, thus avoiding the intermediate step: |
105 statement of your original lemma, thus avoiding the intermediate step: |
106 *}; |
106 *}; |
107 |
107 |
108 lemma myrule[rulify]: "\\<forall>y. A y \\<longrightarrow> B y \<longrightarrow> B y & A y"; |
108 lemma myrule[rulified]: "\\<forall>y. A y \\<longrightarrow> B y \<longrightarrow> B y & A y"; |
109 (*<*) |
109 (*<*) |
110 by blast; |
110 by blast; |
111 (*>*) |
111 (*>*) |
112 |
112 |
113 text{* |
113 text{* |
132 be helpful. We show how to apply such induction schemas by an example. |
132 be helpful. We show how to apply such induction schemas by an example. |
133 |
133 |
134 Structural induction on @{typ"nat"} is |
134 Structural induction on @{typ"nat"} is |
135 usually known as ``mathematical induction''. There is also ``complete |
135 usually known as ``mathematical induction''. There is also ``complete |
136 induction'', where you must prove $P(n)$ under the assumption that $P(m)$ |
136 induction'', where you must prove $P(n)$ under the assumption that $P(m)$ |
137 holds for all $m<n$. In Isabelle, this is the theorem @{thm[source]less_induct}: |
137 holds for all $m<n$. In Isabelle, this is the theorem @{thm [source] nat_less_induct}: |
138 @{thm[display]"less_induct"[no_vars]} |
138 @{thm[display] nat_less_induct [no_vars]} |
139 Here is an example of its application. |
139 Here is an example of its application. |
140 *}; |
140 *}; |
141 |
141 |
142 consts f :: "nat => nat"; |
142 consts f :: "nat => nat"; |
143 axioms f_ax: "f(f(n)) < f(Suc(n))"; |
143 axioms f_ax: "f(f(n)) < f(Suc(n))"; |
153 *}; |
153 *}; |
154 |
154 |
155 lemma f_incr_lem: "\\<forall>i. k = f i \\<longrightarrow> i \\<le> f i"; |
155 lemma f_incr_lem: "\\<forall>i. k = f i \\<longrightarrow> i \\<le> f i"; |
156 |
156 |
157 txt{*\noindent |
157 txt{*\noindent |
158 To perform induction on @{term"k"} using @{thm[source]less_induct}, we use the same |
158 To perform induction on @{term"k"} using @{thm [source] nat_less_induct}, we use the same |
159 general induction method as for recursion induction (see |
159 general induction method as for recursion induction (see |
160 \S\ref{sec:recdef-induction}): |
160 \S\ref{sec:recdef-induction}): |
161 *}; |
161 *}; |
162 |
162 |
163 apply(induct_tac k rule:less_induct); |
163 apply(induct_tac k rule: nat_less_induct); |
164 (*<*) |
164 (*<*) |
165 apply(rule allI); |
165 apply(rule allI); |
166 apply(case_tac i); |
166 apply(case_tac i); |
167 apply(simp); |
167 apply(simp); |
168 (*>*) |
168 (*>*) |
180 \ \ \ \ \ \ \ {\isasymlbrakk}{\isasymforall}\mbox{m}.\ \mbox{m}\ <\ \mbox{n}\ {\isasymlongrightarrow}\ ({\isasymforall}\mbox{i}.\ \mbox{m}\ =\ f\ \mbox{i}\ {\isasymlongrightarrow}\ \mbox{i}\ {\isasymle}\ f\ \mbox{i});\ \mbox{i}\ =\ Suc\ \mbox{nat}{\isasymrbrakk}\isanewline |
180 \ \ \ \ \ \ \ {\isasymlbrakk}{\isasymforall}\mbox{m}.\ \mbox{m}\ <\ \mbox{n}\ {\isasymlongrightarrow}\ ({\isasymforall}\mbox{i}.\ \mbox{m}\ =\ f\ \mbox{i}\ {\isasymlongrightarrow}\ \mbox{i}\ {\isasymle}\ f\ \mbox{i});\ \mbox{i}\ =\ Suc\ \mbox{nat}{\isasymrbrakk}\isanewline |
181 \ \ \ \ \ \ \ {\isasymLongrightarrow}\ \mbox{n}\ =\ f\ \mbox{i}\ {\isasymlongrightarrow}\ \mbox{i}\ {\isasymle}\ f\ \mbox{i} |
181 \ \ \ \ \ \ \ {\isasymLongrightarrow}\ \mbox{n}\ =\ f\ \mbox{i}\ {\isasymlongrightarrow}\ \mbox{i}\ {\isasymle}\ f\ \mbox{i} |
182 \end{isabelle} |
182 \end{isabelle} |
183 *}; |
183 *}; |
184 |
184 |
185 by(blast intro!: f_ax Suc_leI intro:le_less_trans); |
185 by(blast intro!: f_ax Suc_leI intro: le_less_trans); |
186 |
186 |
187 text{*\noindent |
187 text{*\noindent |
188 It is not surprising if you find the last step puzzling. |
188 It is not surprising if you find the last step puzzling. |
189 The proof goes like this (writing @{term"j"} instead of @{typ"nat"}). |
189 The proof goes like this (writing @{term"j"} instead of @{typ"nat"}). |
190 Since @{prop"i = Suc j"} it suffices to show |
190 Since @{prop"i = Suc j"} it suffices to show |
204 proofs. |
204 proofs. |
205 |
205 |
206 We can now derive the desired @{prop"i <= f i"} from @{text"f_incr"}: |
206 We can now derive the desired @{prop"i <= f i"} from @{text"f_incr"}: |
207 *}; |
207 *}; |
208 |
208 |
209 lemmas f_incr = f_incr_lem[rulify, OF refl]; |
209 lemmas f_incr = f_incr_lem[rulified, OF refl]; |
210 |
210 |
211 text{*\noindent |
211 text{*\noindent |
212 The final @{thm[source]refl} gets rid of the premise @{text"?k = f ?i"}. Again, |
212 The final @{thm[source]refl} gets rid of the premise @{text"?k = f ?i"}. Again, |
213 we could have included this derivation in the original statement of the lemma: |
213 we could have included this derivation in the original statement of the lemma: |
214 *}; |
214 *}; |
215 |
215 |
216 lemma f_incr[rulify, OF refl]: "\\<forall>i. k = f i \\<longrightarrow> i \\<le> f i"; |
216 lemma f_incr[rulified, OF refl]: "\\<forall>i. k = f i \\<longrightarrow> i \\<le> f i"; |
217 (*<*)oops;(*>*) |
217 (*<*)oops;(*>*) |
218 |
218 |
219 text{* |
219 text{* |
220 \begin{exercise} |
220 \begin{exercise} |
221 From the above axiom and lemma for @{term"f"} show that @{term"f"} is the |
221 From the above axiom and lemma for @{term"f"} show that @{term"f"} is the |
240 subsection{*Derivation of new induction schemas*}; |
240 subsection{*Derivation of new induction schemas*}; |
241 |
241 |
242 text{*\label{sec:derive-ind} |
242 text{*\label{sec:derive-ind} |
243 Induction schemas are ordinary theorems and you can derive new ones |
243 Induction schemas are ordinary theorems and you can derive new ones |
244 whenever you wish. This section shows you how to, using the example |
244 whenever you wish. This section shows you how to, using the example |
245 of @{thm[source]less_induct}. Assume we only have structural induction |
245 of @{thm [source] nat_less_induct}. Assume we only have structural induction |
246 available for @{typ"nat"} and want to derive complete induction. This |
246 available for @{typ"nat"} and want to derive complete induction. This |
247 requires us to generalize the statement first: |
247 requires us to generalize the statement first: |
248 *}; |
248 *}; |
249 |
249 |
250 lemma induct_lem: "(\\<And>n::nat. \\<forall>m<n. P m \\<Longrightarrow> P n) \\<Longrightarrow> \\<forall>m<n. P m"; |
250 lemma induct_lem: "(\\<And>n::nat. \\<forall>m<n. P m \\<Longrightarrow> P n) \\<Longrightarrow> \\<forall>m<n. P m"; |
266 text{*\noindent |
266 text{*\noindent |
267 The elimination rule @{thm[source]less_SucE} expresses the case distinction: |
267 The elimination rule @{thm[source]less_SucE} expresses the case distinction: |
268 @{thm[display]"less_SucE"[no_vars]} |
268 @{thm[display]"less_SucE"[no_vars]} |
269 |
269 |
270 Now it is straightforward to derive the original version of |
270 Now it is straightforward to derive the original version of |
271 @{thm[source]less_induct} by manipulting the conclusion of the above lemma: |
271 @{thm [source] nat_less_induct} by manipulting the conclusion of the above lemma: |
272 instantiate @{term"n"} by @{term"Suc n"} and @{term"m"} by @{term"n"} and |
272 instantiate @{term"n"} by @{term"Suc n"} and @{term"m"} by @{term"n"} and |
273 remove the trivial condition @{prop"n < Sc n"}. Fortunately, this |
273 remove the trivial condition @{prop"n < Sc n"}. Fortunately, this |
274 happens automatically when we add the lemma as a new premise to the |
274 happens automatically when we add the lemma as a new premise to the |
275 desired goal: |
275 desired goal: |
276 *}; |
276 *}; |
277 |
277 |
278 theorem less_induct: "(\\<And>n::nat. \\<forall>m<n. P m \\<Longrightarrow> P n) \\<Longrightarrow> P n"; |
278 theorem nat_less_induct: "(\\<And>n::nat. \\<forall>m<n. P m \\<Longrightarrow> P n) \\<Longrightarrow> P n"; |
279 by(insert induct_lem, blast); |
279 by(insert induct_lem, blast); |
280 |
280 |
281 text{*\noindent |
281 text{*\noindent |
282 Finally we should mention that HOL already provides the mother of all |
282 Finally we should mention that HOL already provides the mother of all |
283 inductions, \emph{wellfounded induction} (@{thm[source]wf_induct}): |
283 inductions, \emph{wellfounded induction} (@{thm[source]wf_induct}): |
284 @{thm[display]"wf_induct"[no_vars]} |
284 @{thm[display]"wf_induct"[no_vars]} |
285 where @{term"wf r"} means that the relation @{term"r"} is wellfounded. |
285 where @{term"wf r"} means that the relation @{term"r"} is wellfounded. |
286 For example @{thm[source]less_induct} is the special case where @{term"r"} is |
286 For example @{thm [source] nat_less_induct} is the special case where @{term"r"} is |
287 @{text"<"} on @{typ"nat"}. For details see the library. |
287 @{text"<"} on @{typ"nat"}. For details see the library. |
288 *}; |
288 *}; |
289 |
289 |
290 (*<*) |
290 (*<*) |
291 end |
291 end |