710 by pat_completeness auto |
709 by pat_completeness auto |
711 (*<*)declare findzero.simps[simp del](*>*) |
710 (*<*)declare findzero.simps[simp del](*>*) |
712 |
711 |
713 text {* |
712 text {* |
714 \noindent Clearly, any attempt of a termination proof must fail. And without |
713 \noindent Clearly, any attempt of a termination proof must fail. And without |
715 that, we do not get the usual rules @{text "findzero.simp"} and |
714 that, we do not get the usual rules @{text "findzero.simps"} and |
716 @{text "findzero.induct"}. So what was the definition good for at all? |
715 @{text "findzero.induct"}. So what was the definition good for at all? |
717 *} |
716 *} |
718 |
717 |
719 subsection {* Domain predicates *} |
718 subsection {* Domain predicates *} |
720 |
719 |
951 recursive call. |
950 recursive call. |
952 |
951 |
953 The predicate @{term "accp findzero_rel"} is the accessible part of |
952 The predicate @{term "accp findzero_rel"} is the accessible part of |
954 that relation. An argument belongs to the accessible part, if it can |
953 that relation. An argument belongs to the accessible part, if it can |
955 be reached in a finite number of steps (cf.~its definition in @{text |
954 be reached in a finite number of steps (cf.~its definition in @{text |
956 "Accessible_Part.thy"}). |
955 "Wellfounded.thy"}). |
957 |
956 |
958 Since the domain predicate is just an abbreviation, you can use |
957 Since the domain predicate is just an abbreviation, you can use |
959 lemmas for @{const accp} and @{const findzero_rel} directly. Some |
958 lemmas for @{const accp} and @{const findzero_rel} directly. Some |
960 lemmas which are occasionally useful are @{text accpI}, @{text |
959 lemmas which are occasionally useful are @{text accpI}, @{text |
961 accp_downward}, and of course the introduction and elimination rules |
960 accp_downward}, and of course the introduction and elimination rules |
1134 |
1133 |
1135 section {* Higher-Order Recursion *} |
1134 section {* Higher-Order Recursion *} |
1136 |
1135 |
1137 text {* |
1136 text {* |
1138 Higher-order recursion occurs when recursive calls |
1137 Higher-order recursion occurs when recursive calls |
1139 are passed as arguments to higher-order combinators such as @{term |
1138 are passed as arguments to higher-order combinators such as @{const |
1140 map}, @{term filter} etc. |
1139 map}, @{term filter} etc. |
1141 As an example, imagine a datatype of n-ary trees: |
1140 As an example, imagine a datatype of n-ary trees: |
1142 *} |
1141 *} |
1143 |
1142 |
1144 datatype 'a tree = |
1143 datatype 'a tree = |
1162 txt {* |
1161 txt {* |
1163 |
1162 |
1164 As usual, we have to give a wellfounded relation, such that the |
1163 As usual, we have to give a wellfounded relation, such that the |
1165 arguments of the recursive calls get smaller. But what exactly are |
1164 arguments of the recursive calls get smaller. But what exactly are |
1166 the arguments of the recursive calls when mirror is given as an |
1165 the arguments of the recursive calls when mirror is given as an |
1167 argument to map? Isabelle gives us the |
1166 argument to @{const map}? Isabelle gives us the |
1168 subgoals |
1167 subgoals |
1169 |
1168 |
1170 @{subgoals[display,indent=0]} |
1169 @{subgoals[display,indent=0]} |
1171 |
1170 |
1172 So the system seems to know that @{const map} only |
1171 So the system seems to know that @{const map} only |
1173 applies the recursive call @{term "mirror"} to elements |
1172 applies the recursive call @{term "mirror"} to elements |
1174 of @{term "l"}, which is essential for the termination proof. |
1173 of @{term "l"}, which is essential for the termination proof. |
1175 |
1174 |
1176 This knowledge about map is encoded in so-called congruence rules, |
1175 This knowledge about @{const map} is encoded in so-called congruence rules, |
1177 which are special theorems known to the \cmd{function} command. The |
1176 which are special theorems known to the \cmd{function} command. The |
1178 rule for map is |
1177 rule for @{const map} is |
1179 |
1178 |
1180 @{thm[display] map_cong} |
1179 @{thm[display] map_cong} |
1181 |
1180 |
1182 You can read this in the following way: Two applications of @{const |
1181 You can read this in the following way: Two applications of @{const |
1183 map} are equal, if the list arguments are equal and the functions |
1182 map} are equal, if the list arguments are equal and the functions |