doc-src/TutorialI/Misc/AdvancedInd.thy
changeset 11256 49afcce3bada
parent 11196 bb4ede27fcb7
child 11277 a2bff98d6e5d
equal deleted inserted replaced
11255:ca546b170471 11256:49afcce3bada
   122 *};
   122 *};
   123 
   123 
   124 consts f :: "nat \<Rightarrow> nat";
   124 consts f :: "nat \<Rightarrow> nat";
   125 axioms f_ax: "f(f(n)) < f(Suc(n))";
   125 axioms f_ax: "f(f(n)) < f(Suc(n))";
   126 
   126 
   127 text{*\noindent
   127 text{*
       
   128 \begin{warn}
       
   129 We discourage the use of axioms because of the danger of
       
   130 inconsistencies.  Axiom @{text f_ax} does
       
   131 not introduce an inconsistency because, for example, the identity function
       
   132 satisfies it.  Axioms can be useful in exploratory developments, say when 
       
   133 you assume some well-known theorems so that you can quickly demonstrate some
       
   134 point about methodology.  If your example turns into a substantial proof
       
   135 development, you should replace axioms by theorems.
       
   136 \end{warn}\noindent
   128 The axiom for @{term"f"} implies @{prop"n <= f n"}, which can
   137 The axiom for @{term"f"} implies @{prop"n <= f n"}, which can
   129 be proved by induction on \mbox{@{term"f n"}}. Following the recipe outlined
   138 be proved by induction on \mbox{@{term"f n"}}. Following the recipe outlined
   130 above, we have to phrase the proposition as follows to allow induction:
   139 above, we have to phrase the proposition as follows to allow induction:
   131 *};
   140 *};
   132 
   141 
   195 
   204 
   196 lemma f_incr[rule_format, OF refl]: "\<forall>i. k = f i \<longrightarrow> i \<le> f i";
   205 lemma f_incr[rule_format, OF refl]: "\<forall>i. k = f i \<longrightarrow> i \<le> f i";
   197 (*<*)oops;(*>*)
   206 (*<*)oops;(*>*)
   198 
   207 
   199 text{*
   208 text{*
   200 \begin{warn}
   209 \begin{exercise}
   201 We discourage the use of axioms because of the danger of
   210 From the axiom and lemma for @{term"f"}, show that @{term"f"} is the
   202 inconsistencies.  Axiom @{text f_ax} does
   211 identity function.
   203 not introduce an inconsistency because, for example, the identity function
   212 \end{exercise}
   204 satisfies it.  Axioms can be useful in exploratory developments, say when 
   213 
   205 you assume some well-known theorems so that you can quickly demonstrate some
   214 Method @{text induct_tac} can be applied with any rule $r$
   206 point about methodology.  If your example turns into a substantial proof
       
   207 development, you should replace the axioms by proofs.
       
   208 \end{warn}
       
   209 
       
   210 \bigskip
       
   211 In general, @{text induct_tac} can be applied with any rule $r$
       
   212 whose conclusion is of the form ${?}P~?x@1 \dots ?x@n$, in which case the
   215 whose conclusion is of the form ${?}P~?x@1 \dots ?x@n$, in which case the
   213 format is
   216 format is
   214 \begin{quote}
   217 \begin{quote}
   215 \isacommand{apply}@{text"(induct_tac"} $y@1 \dots y@n$ @{text"rule:"} $r$@{text")"}
   218 \isacommand{apply}@{text"(induct_tac"} $y@1 \dots y@n$ @{text"rule:"} $r$@{text")"}
   216 \end{quote}\index{*induct_tac}%
   219 \end{quote}\index{*induct_tac}%
   217 where $y@1, \dots, y@n$ are variables in the first subgoal.
   220 where $y@1, \dots, y@n$ are variables in the first subgoal.
   218 A further example of a useful induction rule is @{thm[source]length_induct},
   221 The conclusion of $r$ can even be an (iterated) conjunction of formulae of
   219 induction on the length of a list:\indexbold{*length_induct}
   222 the above form in which case the application is
   220 @{thm[display]length_induct[no_vars]}
       
   221 
       
   222 In fact, @{text"induct_tac"} even allows the conclusion of
       
   223 $r$ to be an (iterated) conjunction of formulae of the above form, in
       
   224 which case the application is
       
   225 \begin{quote}
   223 \begin{quote}
   226 \isacommand{apply}@{text"(induct_tac"} $y@1 \dots y@n$ @{text"and"} \dots\ @{text"and"} $z@1 \dots z@m$ @{text"rule:"} $r$@{text")"}
   224 \isacommand{apply}@{text"(induct_tac"} $y@1 \dots y@n$ @{text"and"} \dots\ @{text"and"} $z@1 \dots z@m$ @{text"rule:"} $r$@{text")"}
   227 \end{quote}
   225 \end{quote}
   228 
   226 
   229 \begin{exercise}
   227 A further useful induction rule is @{thm[source]length_induct},
   230 From the axiom and lemma for @{term"f"}, show that @{term"f"} is the
   228 induction on the length of a list\indexbold{*length_induct}
   231 identity function.
   229 @{thm[display]length_induct[no_vars]}
   232 \end{exercise}
   230 which is a special case of @{thm[source]measure_induct}
   233 *};
   231 @{thm[display]measure_induct[no_vars]}
       
   232 where @{term f} may be any function into type @{typ nat}.
       
   233 *}
   234 
   234 
   235 subsection{*Derivation of New Induction Schemas*};
   235 subsection{*Derivation of New Induction Schemas*};
   236 
   236 
   237 text{*\label{sec:derive-ind}
   237 text{*\label{sec:derive-ind}
   238 Induction schemas are ordinary theorems and you can derive new ones
   238 Induction schemas are ordinary theorems and you can derive new ones
   257 text{*\noindent
   257 text{*\noindent
   258 The elimination rule @{thm[source]less_SucE} expresses the case distinction:
   258 The elimination rule @{thm[source]less_SucE} expresses the case distinction:
   259 @{thm[display]"less_SucE"[no_vars]}
   259 @{thm[display]"less_SucE"[no_vars]}
   260 
   260 
   261 Now it is straightforward to derive the original version of
   261 Now it is straightforward to derive the original version of
   262 @{thm[source]nat_less_induct} by manipulting the conclusion of the above lemma:
   262 @{thm[source]nat_less_induct} by manipulating the conclusion of the above
   263 instantiate @{term"n"} by @{term"Suc n"} and @{term"m"} by @{term"n"} and
   263 lemma: instantiate @{term"n"} by @{term"Suc n"} and @{term"m"} by @{term"n"}
   264 remove the trivial condition @{prop"n < Suc n"}. Fortunately, this
   264 and remove the trivial condition @{prop"n < Suc n"}. Fortunately, this
   265 happens automatically when we add the lemma as a new premise to the
   265 happens automatically when we add the lemma as a new premise to the
   266 desired goal:
   266 desired goal:
   267 *};
   267 *};
   268 
   268 
   269 theorem nat_less_induct: "(\<And>n::nat. \<forall>m<n. P m \<Longrightarrow> P n) \<Longrightarrow> P n";
   269 theorem nat_less_induct: "(\<And>n::nat. \<forall>m<n. P m \<Longrightarrow> P n) \<Longrightarrow> P n";