481 @{subgoals [display]} |
481 @{subgoals [display]} |
482 \end{minipage}*} |
482 \end{minipage}*} |
483 (*<*)oops(*>*) |
483 (*<*)oops(*>*) |
484 |
484 |
485 text {* |
485 text {* |
486 The function @{ML_ind resolve_tac} is similar to @{ML rtac}, except that it |
486 The function @{ML_ind resolve_tac in Tactic} is similar to @{ML rtac}, except that it |
487 expects a list of theorems as argument. From this list it will apply the |
487 expects a list of theorems as argument. From this list it will apply the |
488 first applicable theorem (later theorems that are also applicable can be |
488 first applicable theorem (later theorems that are also applicable can be |
489 explored via the lazy sequences mechanism). Given the code |
489 explored via the lazy sequences mechanism). Given the code |
490 *} |
490 *} |
491 |
491 |
677 \isccite{sec:results}. |
677 \isccite{sec:results}. |
678 \end{readmore} |
678 \end{readmore} |
679 |
679 |
680 Similar but less powerful functions than @{ML FOCUS in Subgoal}, respectively |
680 Similar but less powerful functions than @{ML FOCUS in Subgoal}, respectively |
681 @{ML SUBPROOF}, are |
681 @{ML SUBPROOF}, are |
682 @{ML_ind SUBGOAL} and @{ML_ind CSUBGOAL}. They allow you to |
682 @{ML_ind SUBGOAL in Tactical} and @{ML_ind CSUBGOAL in Tactical}. They allow you to |
683 inspect a given subgoal (the former |
683 inspect a given subgoal (the former |
684 presents the subgoal as a @{ML_type term}, while the latter as a @{ML_type |
684 presents the subgoal as a @{ML_type term}, while the latter as a @{ML_type |
685 cterm}). With them you can implement a tactic that applies a rule according |
685 cterm}). With them you can implement a tactic that applies a rule according |
686 to the topmost logic connective in the subgoal (to illustrate this we only |
686 to the topmost logic connective in the subgoal (to illustrate this we only |
687 analyse a few connectives). The code of the tactic is as |
687 analyse a few connectives). The code of the tactic is as |
1240 @{text "*** back: no alternatives"}\\ |
1240 @{text "*** back: no alternatives"}\\ |
1241 @{text "*** At command \"back\"."} |
1241 @{text "*** At command \"back\"."} |
1242 \end{isabelle} |
1242 \end{isabelle} |
1243 |
1243 |
1244 |
1244 |
1245 \footnote{\bf FIXME: say something about @{ML_ind COND} and COND'} |
1245 \footnote{\bf FIXME: say something about @{ML_ind COND in Tactical} and COND'} |
1246 \footnote{\bf FIXME: PARALLEL-CHOICE PARALLEL-GOALS} |
1246 \footnote{\bf FIXME: PARALLEL-CHOICE PARALLEL-GOALS} |
1247 |
1247 |
1248 \begin{readmore} |
1248 \begin{readmore} |
1249 Most tactic combinators described in this section are defined in @{ML_file "Pure/tactical.ML"}. |
1249 Most tactic combinators described in this section are defined in @{ML_file "Pure/tactical.ML"}. |
1250 Some combinators for the purpose of proof search are implemented in @{ML_file "Pure/search.ML"}. |
1250 Some combinators for the purpose of proof search are implemented in @{ML_file "Pure/search.ML"}. |
1529 apply(tactic {* ALLGOALS (simp_tac HOL_basic_ss) *}) |
1529 apply(tactic {* ALLGOALS (simp_tac HOL_basic_ss) *}) |
1530 done |
1530 done |
1531 |
1531 |
1532 text {* |
1532 text {* |
1533 This behaviour is not because of simplification rules, but how the subgoaler, solver |
1533 This behaviour is not because of simplification rules, but how the subgoaler, solver |
1534 and looper are set up in @{ML_ind HOL_basic_ss}. |
1534 and looper are set up in @{ML HOL_basic_ss}. |
1535 |
1535 |
1536 The simpset @{ML_ind HOL_ss} is an extension of @{ML HOL_basic_ss} containing |
1536 The simpset @{ML_ind HOL_ss} is an extension of @{ML HOL_basic_ss} containing |
1537 already many useful simplification and congruence rules for the logical |
1537 already many useful simplification and congruence rules for the logical |
1538 connectives in HOL. |
1538 connectives in HOL. |
1539 |
1539 |
1868 |
1868 |
1869 text {* |
1869 text {* |
1870 Here the pattern is given as @{ML_type term} (instead of @{ML_type cterm}). |
1870 Here the pattern is given as @{ML_type term} (instead of @{ML_type cterm}). |
1871 The function also takes a list of patterns that can trigger the simproc. |
1871 The function also takes a list of patterns that can trigger the simproc. |
1872 Now the simproc is set up and can be explicitly added using |
1872 Now the simproc is set up and can be explicitly added using |
1873 @{ML_ind addsimprocs} to a simpset whenever |
1873 @{ML_ind addsimprocs in MetaSimplifier} to a simpset whenever |
1874 needed. |
1874 needed. |
1875 |
1875 |
1876 Simprocs are applied from inside to outside and from left to right. You can |
1876 Simprocs are applied from inside to outside and from left to right. You can |
1877 see this in the proof |
1877 see this in the proof |
1878 *} |
1878 *} |
2157 left-hand side of the theorem, then @{ML_ind rewr_conv in Conv} fails, raising |
2157 left-hand side of the theorem, then @{ML_ind rewr_conv in Conv} fails, raising |
2158 the exception @{ML CTERM}. |
2158 the exception @{ML CTERM}. |
2159 |
2159 |
2160 This very primitive way of rewriting can be made more powerful by |
2160 This very primitive way of rewriting can be made more powerful by |
2161 combining several conversions into one. For this you can use conversion |
2161 combining several conversions into one. For this you can use conversion |
2162 combinators. The simplest conversion combinator is @{ML_ind then_conv}, |
2162 combinators. The simplest conversion combinator is @{ML_ind then_conv in Conv}, |
2163 which applies one conversion after another. For example |
2163 which applies one conversion after another. For example |
2164 |
2164 |
2165 @{ML_response_fake [display,gray] |
2165 @{ML_response_fake [display,gray] |
2166 "let |
2166 "let |
2167 val conv1 = Thm.beta_conversion false |
2167 val conv1 = Thm.beta_conversion false |
2174 |
2174 |
2175 where we first beta-reduce the term and then rewrite according to |
2175 where we first beta-reduce the term and then rewrite according to |
2176 @{thm [source] true_conj1}. (When running this example recall the |
2176 @{thm [source] true_conj1}. (When running this example recall the |
2177 problem with the pretty-printer normalising all terms.) |
2177 problem with the pretty-printer normalising all terms.) |
2178 |
2178 |
2179 The conversion combinator @{ML_ind else_conv} tries out the |
2179 The conversion combinator @{ML_ind else_conv in Conv} tries out the |
2180 first one, and if it does not apply, tries the second. For example |
2180 first one, and if it does not apply, tries the second. For example |
2181 |
2181 |
2182 @{ML_response_fake [display,gray] |
2182 @{ML_response_fake [display,gray] |
2183 "let |
2183 "let |
2184 val conv = Conv.rewr_conv @{thm true_conj1} else_conv Conv.all_conv |
2184 val conv = Conv.rewr_conv @{thm true_conj1} else_conv Conv.all_conv |
2192 Here the conversion of @{thm [source] true_conj1} only applies |
2192 Here the conversion of @{thm [source] true_conj1} only applies |
2193 in the first case, but fails in the second. The whole conversion |
2193 in the first case, but fails in the second. The whole conversion |
2194 does not fail, however, because the combinator @{ML else_conv in Conv} will then |
2194 does not fail, however, because the combinator @{ML else_conv in Conv} will then |
2195 try out @{ML all_conv in Conv}, which always succeeds. |
2195 try out @{ML all_conv in Conv}, which always succeeds. |
2196 |
2196 |
2197 The conversion combinator @{ML_ind try_conv in Conv} constructs a conversion |
2197 The conversion combinator @{ML_ind try_conv in Conv} constructs a conversion |
2198 which is tried out on a term, but in case of failure just does nothing. |
2198 which is tried out on a term, but in case of failure just does nothing. |
2199 For example |
2199 For example |
2200 |
2200 |
2201 @{ML_response_fake [display,gray] |
2201 @{ML_response_fake [display,gray] |
2202 "let |
2202 "let |
2208 "True \<or> P \<equiv> True \<or> P"} |
2208 "True \<or> P \<equiv> True \<or> P"} |
2209 |
2209 |
2210 Apart from the function @{ML beta_conversion in Thm}, which is able to fully |
2210 Apart from the function @{ML beta_conversion in Thm}, which is able to fully |
2211 beta-normalise a term, the conversions so far are restricted in that they |
2211 beta-normalise a term, the conversions so far are restricted in that they |
2212 only apply to the outer-most level of a @{ML_type cterm}. In what follows we |
2212 only apply to the outer-most level of a @{ML_type cterm}. In what follows we |
2213 will lift this restriction. The combinators @{ML_ind fun_conv in Conv} |
2213 will lift this restriction. The combinators @{ML_ind fun_conv in Conv} |
2214 and @{ML_ind arg_conv in Conv} will apply |
2214 and @{ML_ind arg_conv in Conv} will apply |
2215 a conversion to the first, respectively second, argument of an application. |
2215 a conversion to the first, respectively second, argument of an application. |
2216 For example |
2216 For example |
2217 |
2217 |
2218 @{ML_response_fake [display,gray] |
2218 @{ML_response_fake [display,gray] |
2219 "let |
2219 "let |
2333 conv thm |
2333 conv thm |
2334 end" |
2334 end" |
2335 "?P \<or> \<not> ?P"} |
2335 "?P \<or> \<not> ?P"} |
2336 |
2336 |
2337 Finally, conversions can also be turned into tactics and then applied to |
2337 Finally, conversions can also be turned into tactics and then applied to |
2338 goal states. This can be done with the help of the function @{ML_ind CONVERSION}, |
2338 goal states. This can be done with the help of the function |
|
2339 @{ML_ind CONVERSION in Tactical}, |
2339 and also some predefined conversion combinators that traverse a goal |
2340 and also some predefined conversion combinators that traverse a goal |
2340 state. The combinators for the goal state are: |
2341 state. The combinators for the goal state are: |
2341 |
2342 |
2342 \begin{itemize} |
2343 \begin{itemize} |
2343 \item @{ML_ind params_conv in Conv} for converting under parameters |
2344 \item @{ML_ind params_conv in Conv} for converting under parameters |
2344 (i.e.~where goals are of the form @{text "\<And>x. P x \<Longrightarrow> Q x"}) |
2345 (i.e.~where goals are of the form @{text "\<And>x. P x \<Longrightarrow> Q x"}) |
2345 |
2346 |
2346 \item @{ML_ind prems_conv in Conv} for applying a conversion to all |
2347 \item @{ML_ind prems_conv in Conv} for applying a conversion to all |
2347 premises of a goal, and |
2348 premises of a goal, and |
2348 |
2349 |
2349 \item @{ML_ind concl_conv in Conv} for applying a conversion to the |
2350 \item @{ML_ind concl_conv in Conv} for applying a conversion to the |
2350 conclusion of a goal. |
2351 conclusion of a goal. |
2351 \end{itemize} |
2352 \end{itemize} |
2352 |
2353 |
2353 Assume we want to apply @{ML all_true1_conv} only in the conclusion |
2354 Assume we want to apply @{ML all_true1_conv} only in the conclusion |
2354 of the goal, and @{ML if_true1_conv} should only apply to the premises. |
2355 of the goal, and @{ML if_true1_conv} should only apply to the premises. |
2434 text {* |
2435 text {* |
2435 In Line 3 we destruct the meta-equality into the @{ML_type cterm}s |
2436 In Line 3 we destruct the meta-equality into the @{ML_type cterm}s |
2436 corresponding to the left-hand and right-hand side of the meta-equality. The |
2437 corresponding to the left-hand and right-hand side of the meta-equality. The |
2437 assumption in @{ML unabs_def} is that the right-hand side is an |
2438 assumption in @{ML unabs_def} is that the right-hand side is an |
2438 abstraction. We compute the possibly empty list of abstracted variables in |
2439 abstraction. We compute the possibly empty list of abstracted variables in |
2439 Line 4 using the function @{ML_ind strip_abs_vars}. For this we have to |
2440 Line 4 using the function @{ML_ind strip_abs_vars in Term}. For this we have to |
2440 transform the @{ML_type cterm} into a @{ML_type term}. In Line 5 we |
2441 transform the @{ML_type cterm} into a @{ML_type term}. In Line 5 we |
2441 importing these variables into the context @{ML_text ctxt'}, in order to |
2442 importing these variables into the context @{ML_text ctxt'}, in order to |
2442 export them again in Line 15. In Line 8 we certify the list of variables, |
2443 export them again in Line 15. In Line 8 we certify the list of variables, |
2443 which in turn we apply to the @{ML_text lhs} of the definition using the |
2444 which in turn we apply to the @{ML_text lhs} of the definition using the |
2444 function @{ML_ind list_comb in Drule}. In Line 11 and 12 we generate the |
2445 function @{ML_ind list_comb in Drule}. In Line 11 and 12 we generate the |