68 Isabelle Reference Manual, and Chapter 3 in the Isabelle/Isar Implementation Manual. |
68 Isabelle Reference Manual, and Chapter 3 in the Isabelle/Isar Implementation Manual. |
69 \end{readmore} |
69 \end{readmore} |
70 |
70 |
71 Note that in the code above we use antiquotations for referencing the theorems. Many theorems |
71 Note that in the code above we use antiquotations for referencing the theorems. Many theorems |
72 also have ML-bindings with the same name. Therefore, we could also just have |
72 also have ML-bindings with the same name. Therefore, we could also just have |
73 written @{ML "etac disjE 1"}, or in case where there are no ML-binding obtain |
73 written @{ML "etac disjE 1"}, or in case where there is no ML-binding obtain |
74 the theorem dynamically using the function @{ML thm}; for example |
74 the theorem dynamically using the function @{ML thm}; for example |
75 \mbox{@{ML "etac (thm \"disjE\") 1"}}. Both ways however are considered bad style! |
75 \mbox{@{ML "etac (thm \"disjE\") 1"}}. Both ways however are considered bad style! |
76 The reason |
76 The reason |
77 is that the binding for @{ML disjE} can be re-assigned by the user and thus |
77 is that the binding for @{ML disjE} can be re-assigned by the user and thus |
78 one does not have complete control over which theorem is actually |
78 one does not have complete control over which theorem is actually |
312 form @{text "C \<Longrightarrow> (C)"}; when the proof is finished we are left with @{text |
312 form @{text "C \<Longrightarrow> (C)"}; when the proof is finished we are left with @{text |
313 "(C)"}. Since the goal @{term C} can potentially be an implication, there is |
313 "(C)"}. Since the goal @{term C} can potentially be an implication, there is |
314 a ``protector'' wrapped around it (the wrapper is the outermost constant @{text |
314 a ``protector'' wrapped around it (the wrapper is the outermost constant @{text |
315 "Const (\"prop\", bool \<Rightarrow> bool)"}; however this constant |
315 "Const (\"prop\", bool \<Rightarrow> bool)"}; however this constant |
316 is invisible in the figure). This wrapper prevents that premises of @{text C} are |
316 is invisible in the figure). This wrapper prevents that premises of @{text C} are |
317 mis-interpreted as open subgoals. While tactics can operate on the subgoals |
317 misinterpreted as open subgoals. While tactics can operate on the subgoals |
318 (the @{text "A\<^isub>i"} above), they are expected to leave the conclusion |
318 (the @{text "A\<^isub>i"} above), they are expected to leave the conclusion |
319 @{term C} intact, with the exception of possibly instantiating schematic |
319 @{term C} intact, with the exception of possibly instantiating schematic |
320 variables. If you use the predefined tactics, which we describe in the next |
320 variables. If you use the predefined tactics, which we describe in the next |
321 section, this will always be the case. |
321 section, this will always be the case. |
322 |
322 |
1018 text {* |
1018 text {* |
1019 A lot of convenience in the reasoning with Isabelle derives from its |
1019 A lot of convenience in the reasoning with Isabelle derives from its |
1020 powerful simplifier. The power of simplifier is a strength and a weakness at |
1020 powerful simplifier. The power of simplifier is a strength and a weakness at |
1021 the same time, because you can easily make the simplifier to run into a loop and its |
1021 the same time, because you can easily make the simplifier to run into a loop and its |
1022 behaviour can be difficult to predict. There is also a multitude |
1022 behaviour can be difficult to predict. There is also a multitude |
1023 of options that you can configurate to control the behaviour of the simplifier. |
1023 of options that you can configure to control the behaviour of the simplifier. |
1024 We describe some of them in this and the next section. |
1024 We describe some of them in this and the next section. |
1025 |
1025 |
1026 There are the following five main tactics behind |
1026 There are the following five main tactics behind |
1027 the simplifier (in parentheses is their user-level counterpart): |
1027 the simplifier (in parentheses is their user-level counterpart): |
1028 |
1028 |
1065 simplifier can easily run into a loop. Therefore a good rule of thumb is to |
1065 simplifier can easily run into a loop. Therefore a good rule of thumb is to |
1066 use simpsets that are as minimal as possible. It might be surprising that a |
1066 use simpsets that are as minimal as possible. It might be surprising that a |
1067 simpset is more complex than just a simple collection of theorems used as |
1067 simpset is more complex than just a simple collection of theorems used as |
1068 simplification rules. One reason for the complexity is that the simplifier |
1068 simplification rules. One reason for the complexity is that the simplifier |
1069 must be able to rewrite inside terms and should also be able to rewrite |
1069 must be able to rewrite inside terms and should also be able to rewrite |
1070 according to rules that have precoditions. |
1070 according to rules that have preconditions. |
1071 |
1071 |
1072 |
1072 |
1073 The rewriting inside terms requires congruence rules, which |
1073 The rewriting inside terms requires congruence rules, which |
1074 are meta-equalities typical of the form |
1074 are meta-equalities typical of the form |
1075 |
1075 |
1080 \end{center} |
1080 \end{center} |
1081 \end{isabelle} |
1081 \end{isabelle} |
1082 |
1082 |
1083 with @{text "constr"} being a term-constructor, like @{const "If"} or @{const "Let"}. |
1083 with @{text "constr"} being a term-constructor, like @{const "If"} or @{const "Let"}. |
1084 Every simpset contains only |
1084 Every simpset contains only |
1085 one concruence rule for each term-constructor, which however can be |
1085 one congruence rule for each term-constructor, which however can be |
1086 overwritten. The user can declare lemmas to be congruence rules using the |
1086 overwritten. The user can declare lemmas to be congruence rules using the |
1087 attribute @{text "[cong]"}. In HOL, the user usually states these lemmas as |
1087 attribute @{text "[cong]"}. In HOL, the user usually states these lemmas as |
1088 equations, which are then internally transformed into meta-equations. |
1088 equations, which are then internally transformed into meta-equations. |
1089 |
1089 |
1090 |
1090 |
1093 tactics that can be installed in a simpset and which are called during |
1093 tactics that can be installed in a simpset and which are called during |
1094 various stages during simplification. However, simpsets also include |
1094 various stages during simplification. However, simpsets also include |
1095 simprocs, which can produce rewrite rules on demand (see next |
1095 simprocs, which can produce rewrite rules on demand (see next |
1096 section). Another component are split-rules, which can simplify for example |
1096 section). Another component are split-rules, which can simplify for example |
1097 the ``then'' and ``else'' branches of if-statements under the corresponding |
1097 the ``then'' and ``else'' branches of if-statements under the corresponding |
1098 precoditions. |
1098 preconditions. |
1099 |
1099 |
1100 |
1100 |
1101 \begin{readmore} |
1101 \begin{readmore} |
1102 For more information about the simplifier see @{ML_file "Pure/meta_simplifier.ML"} |
1102 For more information about the simplifier see @{ML_file "Pure/meta_simplifier.ML"} |
1103 and @{ML_file "Pure/simplifier.ML"}. The simplifier for HOL is set up in |
1103 and @{ML_file "Pure/simplifier.ML"}. The simplifier for HOL is set up in |
1147 text_raw {* |
1147 text_raw {* |
1148 \end{isabelle} |
1148 \end{isabelle} |
1149 \end{minipage} |
1149 \end{minipage} |
1150 \caption{The function @{ML MetaSimplifier.dest_ss} returns a record containing |
1150 \caption{The function @{ML MetaSimplifier.dest_ss} returns a record containing |
1151 all printable information stored in a simpset. We are here only interested in the |
1151 all printable information stored in a simpset. We are here only interested in the |
1152 simplifcation rules, congruence rules and simprocs.\label{fig:printss}} |
1152 simplification rules, congruence rules and simprocs.\label{fig:printss}} |
1153 \end{figure} *} |
1153 \end{figure} *} |
1154 |
1154 |
1155 text {* |
1155 text {* |
1156 To see how they work, consider the function in Figure~\ref{fig:printss}, which |
1156 To see how they work, consider the function in Figure~\ref{fig:printss}, which |
1157 prints out some parts of a simpset. If you use it to print out the components of the |
1157 prints out some parts of a simpset. If you use it to print out the components of the |
1229 |
1229 |
1230 text {* |
1230 text {* |
1231 This behaviour is not because of simplification rules, but how the subgoaler, solver |
1231 This behaviour is not because of simplification rules, but how the subgoaler, solver |
1232 and looper are set up in @{ML HOL_basic_ss}. |
1232 and looper are set up in @{ML HOL_basic_ss}. |
1233 |
1233 |
1234 The simpset @{ML HOL_ss} is an extention of @{ML HOL_basic_ss} containing |
1234 The simpset @{ML HOL_ss} is an extension of @{ML HOL_basic_ss} containing |
1235 already many useful simplification and congruence rules for the logical |
1235 already many useful simplification and congruence rules for the logical |
1236 connectives in HOL. |
1236 connectives in HOL. |
1237 |
1237 |
1238 @{ML_response_fake [display,gray] |
1238 @{ML_response_fake [display,gray] |
1239 "print_ss @{context} HOL_ss" |
1239 "print_ss @{context} HOL_ss" |
1392 More importantly, the lemma @{thm [source] perm_compose_aux} can be safely |
1392 More importantly, the lemma @{thm [source] perm_compose_aux} can be safely |
1393 added to the simplifier, because now the right-hand side is not anymore an instance |
1393 added to the simplifier, because now the right-hand side is not anymore an instance |
1394 of the left-hand side. In a sense it freezes all redexes of permutation compositions |
1394 of the left-hand side. In a sense it freezes all redexes of permutation compositions |
1395 after one step. In this way, we can split simplification of permutations |
1395 after one step. In this way, we can split simplification of permutations |
1396 into three phases without the user noticing anything about the auxiliary |
1396 into three phases without the user noticing anything about the auxiliary |
1397 contant. We first freeze any instance of permutation compositions in the term using |
1397 constant. We first freeze any instance of permutation compositions in the term using |
1398 lemma @{thm [source] "perm_aux_expand"} (Line 9); |
1398 lemma @{thm [source] "perm_aux_expand"} (Line 9); |
1399 then simplifiy all other permutations including pushing permutations over |
1399 then simplify all other permutations including pushing permutations over |
1400 other permutations by rule @{thm [source] perm_compose_aux} (Line 10); and |
1400 other permutations by rule @{thm [source] perm_compose_aux} (Line 10); and |
1401 finally ``unfreeze'' all instances of permutation compositions by unfolding |
1401 finally ``unfreeze'' all instances of permutation compositions by unfolding |
1402 the definition of the auxiliary constant. |
1402 the definition of the auxiliary constant. |
1403 *} |
1403 *} |
1404 |
1404 |
1558 |
1558 |
1559 text {* |
1559 text {* |
1560 Here the pattern is given as @{ML_type term} (instead of @{ML_type cterm}). |
1560 Here the pattern is given as @{ML_type term} (instead of @{ML_type cterm}). |
1561 The function also takes a list of patterns that can trigger the simproc. |
1561 The function also takes a list of patterns that can trigger the simproc. |
1562 Now the simproc is set up and can be explicitly added using |
1562 Now the simproc is set up and can be explicitly added using |
1563 @{ML addsimprocs} to a simpset whenerver |
1563 @{ML addsimprocs} to a simpset whenever |
1564 needed. |
1564 needed. |
1565 |
1565 |
1566 Simprocs are applied from inside to outside and from left to right. You can |
1566 Simprocs are applied from inside to outside and from left to right. You can |
1567 see this in the proof |
1567 see this in the proof |
1568 *} |
1568 *} |
1684 |
1684 |
1685 text {* |
1685 text {* |
1686 The advantage of @{ML get_thm_alt} is that it leaves very little room for |
1686 The advantage of @{ML get_thm_alt} is that it leaves very little room for |
1687 something to go wrong; in contrast it is much more difficult to predict |
1687 something to go wrong; in contrast it is much more difficult to predict |
1688 what happens with @{ML arith_tac in Arith_Data}, especially in more complicated |
1688 what happens with @{ML arith_tac in Arith_Data}, especially in more complicated |
1689 circumstances. The disatvantage of @{ML get_thm_alt} is to find a simpset |
1689 circumstances. The disadvantage of @{ML get_thm_alt} is to find a simpset |
1690 that is sufficiently powerful to solve every instance of the lemmas |
1690 that is sufficiently powerful to solve every instance of the lemmas |
1691 we like to prove. This requires careful tuning, but is often necessary in |
1691 we like to prove. This requires careful tuning, but is often necessary in |
1692 ``production code''.\footnote{It would be of great help if there is another |
1692 ``production code''.\footnote{It would be of great help if there is another |
1693 way than tracing the simplifier to obtain the lemmas that are successfully |
1693 way than tracing the simplifier to obtain the lemmas that are successfully |
1694 applied during simplification. Alas, there is none.} |
1694 applied during simplification. Alas, there is none.} |