97 for @{ML disjE} can be re-assigned and thus one does not have |
96 for @{ML disjE} can be re-assigned and thus one does not have |
98 complete control over which theorem is actually applied. Similarly with the |
97 complete control over which theorem is actually applied. Similarly with the |
99 lookup of @{text [quotes] "disjE"}. Although theorems must have a unique name |
98 lookup of @{text [quotes] "disjE"}. Although theorems must have a unique name |
100 in the theorem database, the string can stand for a dynamically updatable |
99 in the theorem database, the string can stand for a dynamically updatable |
101 theorem list. Also in this case we cannot be sure which theorem is applied. |
100 theorem list. Also in this case we cannot be sure which theorem is applied. |
102 These problems can be nicely prevented by using antiquotations, because then |
101 These problems can be nicely prevented by using antiquotations |
103 the theorems are fixed statically at compile-time. |
102 |
104 |
103 @{ML_response_fake [gray,display] |
|
104 "@{thm \"disjE\"}" |
|
105 "\<lbrakk>?P \<or> ?Q; ?P \<Longrightarrow> ?R; ?Q \<Longrightarrow> ?R\<rbrakk> \<Longrightarrow> ?R"} |
|
106 |
|
107 because then the theorems are fixed statically at compile-time. |
105 |
108 |
106 During the development of automatic proof procedures, you will often find it |
109 During the development of automatic proof procedures, you will often find it |
107 necessary to test a tactic on examples. This can be conveniently done with |
110 necessary to test a tactic on examples. This can be conveniently done with |
108 the command \isacommand{apply}@{text "(tactic \<verbopen> \<dots> \<verbclose>)"}. |
111 the command \isacommand{apply}@{text "(tactic \<verbopen> \<dots> \<verbclose>)"}. |
109 Consider the following sequence of tactics |
112 Consider the following sequence of tactics |
389 *} |
392 *} |
390 |
393 |
391 section {* Simple Tactics\label{sec:simpletacs} *} |
394 section {* Simple Tactics\label{sec:simpletacs} *} |
392 |
395 |
393 text {* |
396 text {* |
394 In this section we will introduce more simple tactics. The |
397 In this section we will introduce more of the simple tactics in Isabelle. The |
395 first one is @{ML_ind print_tac in Tactical}, which is quite useful |
398 first one is @{ML_ind print_tac in Tactical}, which is quite useful |
396 for low-level debugging of tactics. It just prints out a message and the current |
399 for low-level debugging of tactics. It just prints out a message and the current |
397 goal state. Unlike @{ML my_print_tac} shown earlier, it prints the goal state |
400 goal state. Unlike @{ML my_print_tac} shown earlier, it prints the goal state |
398 as the user would see it. For example, processing the proof |
401 as the user would see it. For example, processing the proof |
399 *} |
402 *} |
400 |
403 |
401 lemma |
404 lemma |
402 shows "False \<Longrightarrow> True" |
405 shows "False \<Longrightarrow> True" |
403 apply(tactic {* print_tac "foo message" *}) |
406 apply(tactic {* print_tac "foo message" *}) |
404 txt{*gives:\medskip |
407 txt{*gives: |
405 |
408 \begin{isabelle} |
406 \begin{minipage}{\textwidth}\small |
|
407 @{text "foo message"}\\[3mm] |
409 @{text "foo message"}\\[3mm] |
408 @{prop "False \<Longrightarrow> True"}\\ |
410 @{prop "False \<Longrightarrow> True"}\\ |
409 @{text " 1. False \<Longrightarrow> True"}\\ |
411 @{text " 1. False \<Longrightarrow> True"}\\ |
410 \end{minipage} |
412 \end{isabelle} |
411 *} |
413 *} |
412 (*<*)oops(*>*) |
414 (*<*)oops(*>*) |
413 |
415 |
414 text {* |
416 text {* |
415 A simple tactic for easy discharge of any proof obligations, even difficult ones, is |
417 A simple tactic for easy discharge of any proof obligations, even difficult ones, is |
754 implementing a tactic analysing a goal according to its topmost |
755 implementing a tactic analysing a goal according to its topmost |
755 connective. These simpler methods use tactic combinators, which we will |
756 connective. These simpler methods use tactic combinators, which we will |
756 explain in the next section. But before that we will show how |
757 explain in the next section. But before that we will show how |
757 tactic application can be constrained. |
758 tactic application can be constrained. |
758 |
759 |
759 Since rules are applied using higher-order unification, an automatic proof |
760 \begin{readmore} |
760 procedure might become too fragile, if it just applies inference rules as |
761 The functions @{ML SUBGOAL} and @{ML CSUBGOAL} are defined in @{ML_file "Pure/tactical.ML"}. |
761 shown above. The reason is that a number of rules introduce schematic variables |
762 \end{readmore} |
762 into the goal state. Consider for example the proof |
763 |
|
764 |
|
765 Since @{ML_ind rtac in Tactic} and the like use higher-order unification, an |
|
766 automatic proof procedure based on them might become too fragile, if it just |
|
767 applies theorems as shown above. The reason is that a number of theorems |
|
768 introduce schematic variables into the goal state. Consider for example the |
|
769 proof |
763 *} |
770 *} |
764 |
771 |
765 lemma |
772 lemma |
766 shows "\<forall>x \<in> A. P x \<Longrightarrow> Q x" |
773 shows "\<forall>x \<in> A. P x \<Longrightarrow> Q x" |
767 apply(tactic {* dtac @{thm bspec} 1 *}) |
774 apply(tactic {* dtac @{thm bspec} 1 *}) |
769 @{subgoals [display]} |
776 @{subgoals [display]} |
770 \end{minipage}*} |
777 \end{minipage}*} |
771 (*<*)oops(*>*) |
778 (*<*)oops(*>*) |
772 |
779 |
773 text {* |
780 text {* |
774 where the application of rule @{text bspec} generates two subgoals involving the |
781 where the application of theorem @{text bspec} generates two subgoals involving the |
775 schematic variable @{text "?x"}. Now, if you are not careful, tactics |
782 new schematic variable @{text "?x"}. Now, if you are not careful, tactics |
776 applied to the first subgoal might instantiate this schematic variable in such a |
783 applied to the first subgoal might instantiate this schematic variable in such a |
777 way that the second subgoal becomes unprovable. If it is clear what the @{text "?x"} |
784 way that the second subgoal becomes unprovable. If it is clear what the @{text "?x"} |
778 should be, then this situation can be avoided by introducing a more |
785 should be, then this situation can be avoided by introducing a more |
779 constrained version of the @{text bspec}-rule. One way to give such |
786 constrained version of the @{text bspec}-theorem. One way to give such |
780 constraints is by pre-instantiating theorems with other theorems. |
787 constraints is by pre-instantiating theorems with other theorems. |
781 The function @{ML_ind RS in Drule}, for example, does this. |
788 The function @{ML_ind RS in Drule}, for example, does this. |
782 |
789 |
783 @{ML_response_fake [display,gray] |
790 @{ML_response_fake [display,gray] |
784 "@{thm disjI1} RS @{thm conjI}" "\<lbrakk>?P1; ?Q\<rbrakk> \<Longrightarrow> (?P1 \<or> ?Q1) \<and> ?Q"} |
791 "@{thm disjI1} RS @{thm conjI}" "\<lbrakk>?P1; ?Q\<rbrakk> \<Longrightarrow> (?P1 \<or> ?Q1) \<and> ?Q"} |
785 |
792 |
786 In this example it instantiates the first premise of the @{text conjI}-rule |
793 In this example it instantiates the first premise of the @{text conjI}-theorem |
787 with the rule @{text disjI1}. If the instantiation is impossible, as in the |
794 with the theorem @{text disjI1}. If the instantiation is impossible, as in the |
788 case of |
795 case of |
789 |
796 |
790 @{ML_response_fake_both [display,gray] |
797 @{ML_response_fake_both [display,gray] |
791 "@{thm conjI} RS @{thm mp}" |
798 "@{thm conjI} RS @{thm mp}" |
792 "*** Exception- THM (\"RSN: no unifiers\", 1, |
799 "*** Exception- THM (\"RSN: no unifiers\", 1, |
1087 @{subgoals [display]} |
1100 @{subgoals [display]} |
1088 \end{minipage} *} |
1101 \end{minipage} *} |
1089 (*<*)oops(*>*) |
1102 (*<*)oops(*>*) |
1090 |
1103 |
1091 text {* |
1104 text {* |
1092 In this case no rule applies, but because of @{ML TRY} or the inclusion of @{ML all_tac} |
1105 In this case no theorem applies. But because we wrapped the tactic in a @{ML |
1093 the tactics do not fail. The problem with this is that for the user there is little |
1106 TRY}, it does not fail anymore. The problem is that for the user there is |
1094 chance to see whether or not progress in the proof has been made. By convention |
1107 little chance to see whether progress in the proof has been made, or not. By |
1095 therefore, tactics visible to the user should either change something or fail. |
1108 convention therefore, tactics visible to the user should either change |
1096 |
1109 something or fail. |
|
1110 |
1097 To comply with this convention, we could simply delete the @{ML "K all_tac"} |
1111 To comply with this convention, we could simply delete the @{ML "K all_tac"} |
1098 from the end of the theorem list. As a result @{ML select_tac'} would only |
1112 in @{ML select_tac'} or delete @{ML TRY} from @{ML select_tac''}. But for |
1099 succeed on goals where it can make progress. But for the sake of argument, |
1113 the sake of argument, let us suppose that this deletion is \emph{not} an |
1100 let us suppose that this deletion is \emph{not} an option. In such cases, you can |
1114 option. In such cases, you can use the combinator @{ML_ind CHANGED in |
1101 use the combinator @{ML_ind CHANGED in Tactical} to make sure the subgoal has been changed |
1115 Tactical} to make sure the subgoal has been changed by the tactic. Because |
1102 by the tactic. Because now |
1116 now |
1103 |
|
1104 *} |
1117 *} |
1105 |
1118 |
1106 lemma |
1119 lemma |
1107 shows "E \<Longrightarrow> F" |
1120 shows "E \<Longrightarrow> F" |
1108 apply(tactic {* CHANGED (select_tac' 1) *})(*<*)?(*>*) |
1121 apply(tactic {* CHANGED (select_tac' 1) *})(*<*)?(*>*) |
1154 If you look closely at the goal state above, then you see the tactics @{ML repeat_xmp_tac} |
1166 If you look closely at the goal state above, then you see the tactics @{ML repeat_xmp_tac} |
1155 and @{ML repeat_xmp_tac'} are not yet quite what we are after: the problem is |
1167 and @{ML repeat_xmp_tac'} are not yet quite what we are after: the problem is |
1156 that goals 2 and 3 are not analysed. This is because the tactic |
1168 that goals 2 and 3 are not analysed. This is because the tactic |
1157 is applied repeatedly only to the first subgoal. To analyse also all |
1169 is applied repeatedly only to the first subgoal. To analyse also all |
1158 resulting subgoals, you can use the tactic combinator @{ML_ind REPEAT_ALL_NEW in Tactical}. |
1170 resulting subgoals, you can use the tactic combinator @{ML_ind REPEAT_ALL_NEW in Tactical}. |
1159 Suppose the tactic |
1171 Supposing the tactic |
1160 *} |
1172 *} |
1161 |
1173 |
1162 ML{*val repeat_all_new_xmp_tac = REPEAT_ALL_NEW (CHANGED o select_tac')*} |
1174 ML{*val repeat_all_new_xmp_tac = REPEAT_ALL_NEW (CHANGED o select_tac')*} |
1163 |
1175 |
1164 text {* |
1176 text {* |
1165 you see that the following goal |
1177 you can see that the following goal |
1166 *} |
1178 *} |
1167 |
1179 |
1168 lemma |
1180 lemma |
1169 shows "((\<not>A) \<and> (\<forall>x. B x)) \<and> (C \<longrightarrow> D)" |
1181 shows "((\<not>A) \<and> (\<forall>x. B x)) \<and> (C \<longrightarrow> D)" |
1170 apply(tactic {* repeat_all_new_xmp_tac 1 *}) |
1182 apply(tactic {* repeat_all_new_xmp_tac 1 *}) |
1183 *} |
1195 *} |
1184 |
1196 |
1185 lemma |
1197 lemma |
1186 shows "\<lbrakk>P1 \<or> Q1; P2 \<or> Q2\<rbrakk> \<Longrightarrow> R" |
1198 shows "\<lbrakk>P1 \<or> Q1; P2 \<or> Q2\<rbrakk> \<Longrightarrow> R" |
1187 apply(tactic {* etac @{thm disjE} 1 *}) |
1199 apply(tactic {* etac @{thm disjE} 1 *}) |
1188 txt{* applies the rule to the first assumption yielding the goal state:\smallskip |
1200 txt{* applies the rule to the first assumption yielding the goal state: |
1189 |
1201 \begin{isabelle} |
1190 \begin{minipage}{\textwidth} |
|
1191 @{subgoals [display]} |
1202 @{subgoals [display]} |
1192 \end{minipage}\smallskip |
1203 \end{isabelle} |
1193 |
1204 |
1194 After typing |
1205 After typing |
1195 *} |
1206 *} |
1196 (*<*) |
1207 (*<*) |
1197 oops |
1208 oops |
1198 lemma |
1209 lemma |
1199 shows "\<lbrakk>P1 \<or> Q1; P2 \<or> Q2\<rbrakk> \<Longrightarrow> R" |
1210 shows "\<lbrakk>P1 \<or> Q1; P2 \<or> Q2\<rbrakk> \<Longrightarrow> R" |
1200 apply(tactic {* etac @{thm disjE} 1 *}) |
1211 apply(tactic {* etac @{thm disjE} 1 *}) |
1201 (*>*) |
1212 (*>*) |
1202 back |
1213 back |
1203 txt{* the rule now applies to the second assumption.\smallskip |
1214 txt{* the rule now applies to the second assumption. |
1204 |
1215 \begin{isabelle} |
1205 \begin{minipage}{\textwidth} |
|
1206 @{subgoals [display]} |
1216 @{subgoals [display]} |
1207 \end{minipage} *} |
1217 \end{isabelle} *} |
1208 (*<*)oops(*>*) |
1218 (*<*)oops(*>*) |
1209 |
1219 |
1210 text {* |
1220 text {* |
1211 Sometimes this leads to confusing behaviour of tactics and also has |
1221 Sometimes this leads to confusing behaviour of tactics and also has |
1212 the potential to explode the search space for tactics. |
1222 the potential to explode the search space for tactics. |
1229 \begin{isabelle} |
1239 \begin{isabelle} |
1230 @{text "*** back: no alternatives"}\\ |
1240 @{text "*** back: no alternatives"}\\ |
1231 @{text "*** At command \"back\"."} |
1241 @{text "*** At command \"back\"."} |
1232 \end{isabelle} |
1242 \end{isabelle} |
1233 |
1243 |
1234 Recall that we implemented @{ML select_tac'} on Page~\pageref{tac:selectprime} specifically |
1244 |
1235 so that it always succeeds. We achieved this by adding at the end the tactic @{ML all_tac}. |
1245 \footnote{\bf FIXME: say something about @{ML_ind COND} and COND'} |
1236 We can achieve this also by using the combinator @{ML TRY}. Suppose, for example the |
1246 \footnote{\bf FIXME: PARALLEL-CHOICE PARALLEL-GOALS} |
1237 tactic |
|
1238 *} |
|
1239 |
|
1240 ML{*val select_tac'' = FIRST' [rtac @{thm conjI}, rtac @{thm impI}, |
|
1241 rtac @{thm notI}, rtac @{thm allI}]*} |
|
1242 |
|
1243 text {* |
|
1244 which will fail if none of the rules applies. However, if you prefix it as follows |
|
1245 *} |
|
1246 |
|
1247 ML{*val select_tac''' = TRY o select_tac''*} |
|
1248 |
|
1249 text {* |
|
1250 then the tactic @{ML select_tac''} will be tried out and any failure is harnessed. |
|
1251 We again have to use the construction with \mbox{@{text "TRY o ..."}} since there is |
|
1252 no primed version of @{ML_ind TRY}. The tactic combinator @{ML_ind TRYALL} will try out |
|
1253 a tactic on all subgoals. For example the tactic |
|
1254 *} |
|
1255 |
|
1256 ML{*val triv_tac = TRYALL (rtac @{thm TrueI} ORELSE' etac @{thm FalseE})*} |
|
1257 |
|
1258 text {* |
|
1259 will solve all trivial subgoals involving @{term True} or @{term "False"}. |
|
1260 |
|
1261 (FIXME: say something about @{ML_ind COND} and COND') |
|
1262 |
|
1263 (FIXME: PARALLEL-CHOICE PARALLEL-GOALS) |
|
1264 |
1247 |
1265 \begin{readmore} |
1248 \begin{readmore} |
1266 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"}. |
1267 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"}. |
1268 \end{readmore} |
1251 \end{readmore} |
1269 *} |
1252 *} |
1270 |
1253 |
1271 text {* |
1254 text {* |
1272 \begin{exercise}\label{ex:dyckhoff} |
1255 \begin{exercise}\label{ex:dyckhoff} |
1273 Dyckhoff presents in \cite{Dyckhoff92} inference rules for a sequent |
1256 Dyckhoff presents in \cite{Dyckhoff92} inference rules for a sequent |
1274 calculus, called G4ip, in which no contraction rule is needed in order to be |
1257 calculus, called G4ip, for intuitionistic propositional logic. The |
1275 complete. As a result the rules applied in any order give a simple decision |
1258 interesting feature of this calculus is that no contraction rule is needed |
1276 procedure for propositional intuitionistic logic. His rules are |
1259 in order to be complete. As a result applying the rules exhaustively leads |
|
1260 to simple decision procedure for propositional intuitionistic logic. The task |
|
1261 is to implement this decision procedure as a tactic. His rules are |
1277 |
1262 |
1278 \begin{center} |
1263 \begin{center} |
1279 \def\arraystretch{2.3} |
1264 \def\arraystretch{2.3} |
1280 \begin{tabular}{cc} |
1265 \begin{tabular}{cc} |
1281 \infer[Ax]{A,\varGamma \Rightarrow A}{} & |
1266 \infer[Ax]{A,\varGamma \Rightarrow A}{} & |
1311 {D\longrightarrow B, \varGamma \Rightarrow C \longrightarrow D & |
1296 {D\longrightarrow B, \varGamma \Rightarrow C \longrightarrow D & |
1312 B, \varGamma \Rightarrow G}}\\ |
1297 B, \varGamma \Rightarrow G}}\\ |
1313 \end{tabular} |
1298 \end{tabular} |
1314 \end{center} |
1299 \end{center} |
1315 |
1300 |
1316 Implement a tactic that explores all possibilites of applying these rules to |
1301 Note that in Isabelle the left-rules need to be implemented as elimination |
1317 a propositional formula until a goal state is reached in which all subgoals |
1302 rules. You need to prove separate lemmas corresponding to |
1318 are discharged. Note that in Isabelle the left-rules need to be implemented |
1303 $\longrightarrow_{L_{1..4}}$. The tactic should explore all possibilites of |
1319 as elimination rules. You need to prove separate lemmas corresponding to |
1304 applying these rules to a propositional formula until a goal state is |
1320 $\longrightarrow_{L_{1..4}}$. In order to explore all possibilities of applying |
1305 reached in which all subgoals are discharged. For this you can use the tactic |
1321 the rules, use the tactic combinator @{ML_ind DEPTH_SOLVE in Search}, which searches |
1306 combinator @{ML_ind DEPTH_SOLVE in Search}. |
1322 for a state in which all subgoals are solved. Add also rules for equality and |
|
1323 run your tactic on the de Bruijn formulae discussed in Exercise~\ref{ex:debruijn}. |
|
1324 \end{exercise} |
1307 \end{exercise} |
|
1308 |
|
1309 \begin{exercise} |
|
1310 Add to the previous exercise also rules for equality and run your tactic on |
|
1311 the de Bruijn formulae discussed in Exercise~\ref{ex:debruijn}. |
|
1312 \end{exercise} |
1325 *} |
1313 *} |
1326 |
1314 |
1327 section {* Simplifier Tactics *} |
1315 section {* Simplifier Tactics *} |
1328 |
1316 |
1329 text {* |
1317 text {* |
1330 A lot of convenience in the reasoning with Isabelle derives from its |
1318 A lot of convenience in reasoning with Isabelle derives from its |
1331 powerful simplifier. The power of the simplifier is a strength and a weakness at |
1319 powerful simplifier. We will describe it in this section, whereby |
1332 the same time, because you can easily make the simplifier run into a loop and |
1320 we can, however, only scratch the surface due to its complexity. |
1333 in general its |
1321 |
1334 behaviour can be difficult to predict. There is also a multitude |
1322 The power of the simplifier is a strength and a weakness at the same time, |
1335 of options that you can configure to control the behaviour of the simplifier. |
1323 because you can easily make the simplifier run into a loop and in general |
1336 We describe some of them in this and the next section. |
1324 its behaviour can be difficult to predict. There is also a multitude of |
1337 |
1325 options that you can configure to change the behaviour of the |
1338 There are the following five main tactics behind |
1326 simplifier. There are the following five main tactics behind the simplifier |
1339 the simplifier (in parentheses is their user-level counterpart): |
1327 (in parentheses is their user-level counterpart): |
1340 |
1328 |
1341 \begin{isabelle} |
1329 \begin{isabelle} |
1342 \begin{center} |
1330 \begin{center} |
1343 \begin{tabular}{l@ {\hspace{2cm}}l} |
1331 \begin{tabular}{l@ {\hspace{2cm}}l} |
1344 @{ML_ind simp_tac} & @{text "(simp (no_asm))"} \\ |
1332 @{ML_ind simp_tac in Simplifier} & @{text "(simp (no_asm))"} \\ |
1345 @{ML_ind asm_simp_tac} & @{text "(simp (no_asm_simp))"} \\ |
1333 @{ML_ind asm_simp_tac in Simplifier} & @{text "(simp (no_asm_simp))"} \\ |
1346 @{ML_ind full_simp_tac} & @{text "(simp (no_asm_use))"} \\ |
1334 @{ML_ind full_simp_tac in Simplifier} & @{text "(simp (no_asm_use))"} \\ |
1347 @{ML_ind asm_lr_simp_tac} & @{text "(simp (asm_lr))"} \\ |
1335 @{ML_ind asm_lr_simp_tac in Simplifier} & @{text "(simp (asm_lr))"} \\ |
1348 @{ML_ind asm_full_simp_tac} & @{text "(simp)"} |
1336 @{ML_ind asm_full_simp_tac in Simplifier} & @{text "(simp)"} |
1349 \end{tabular} |
1337 \end{tabular} |
1350 \end{center} |
1338 \end{center} |
1351 \end{isabelle} |
1339 \end{isabelle} |
1352 |
1340 |
1353 All of the tactics take a simpset and an integer as argument (the latter as usual |
1341 All of the tactics take a simpset and an integer as argument (the latter as usual |
1372 If the simplifier cannot make any progress, then it leaves the goal unchanged, |
1360 If the simplifier cannot make any progress, then it leaves the goal unchanged, |
1373 i.e., does not raise any error message. That means if you use it to unfold a |
1361 i.e., does not raise any error message. That means if you use it to unfold a |
1374 definition for a constant and this constant is not present in the goal state, |
1362 definition for a constant and this constant is not present in the goal state, |
1375 you can still safely apply the simplifier. |
1363 you can still safely apply the simplifier. |
1376 |
1364 |
1377 (FIXME: show rewriting of cterms) |
1365 \footnote{\bf FIXME: show rewriting of cterms} |
1378 |
|
1379 |
1366 |
1380 When using the simplifier, the crucial information you have to provide is |
1367 When using the simplifier, the crucial information you have to provide is |
1381 the simpset. If this information is not handled with care, then the |
1368 the simpset. If this information is not handled with care, then, as |
1382 simplifier can easily run into a loop. Therefore a good rule of thumb is to |
1369 mentioned above, the simplifier can easily run into a loop. Therefore a good |
1383 use simpsets that are as minimal as possible. It might be surprising that a |
1370 rule of thumb is to use simpsets that are as minimal as possible. It might |
1384 simpset is more complex than just a simple collection of theorems used as |
1371 be surprising that a simpset is more complex than just a simple collection |
1385 simplification rules. One reason for the complexity is that the simplifier |
1372 of theorems. One reason for the complexity is that the simplifier must be |
1386 must be able to rewrite inside terms and should also be able to rewrite |
1373 able to rewrite inside terms and should also be able to rewrite according to |
1387 according to rules that have preconditions. |
1374 theorems that have premises. |
1388 |
1375 |
1389 |
1376 The rewriting inside terms requires congruence theorems, which |
1390 The rewriting inside terms requires congruence rules, which |
1377 are typically meta-equalities of the form |
1391 are meta-equalities typical of the form |
|
1392 |
1378 |
1393 \begin{isabelle} |
1379 \begin{isabelle} |
1394 \begin{center} |
1380 \begin{center} |
1395 \mbox{\inferrule{@{text "t\<^isub>1 \<equiv> s\<^isub>1 \<dots> t\<^isub>n \<equiv> s\<^isub>n"}} |
1381 \mbox{\inferrule{@{text "t\<^isub>1 \<equiv> s\<^isub>1 \<dots> t\<^isub>n \<equiv> s\<^isub>n"}} |
1396 {@{text "constr t\<^isub>1\<dots>t\<^isub>n \<equiv> constr s\<^isub>1\<dots>s\<^isub>n"}}} |
1382 {@{text "constr t\<^isub>1\<dots>t\<^isub>n \<equiv> constr s\<^isub>1\<dots>s\<^isub>n"}}} |
1397 \end{center} |
1383 \end{center} |
1398 \end{isabelle} |
1384 \end{isabelle} |
1399 |
1385 |
1400 with @{text "constr"} being a constant, like @{const "If"} or @{const "Let"}. |
1386 with @{text "constr"} being a constant, like @{const "If"}, @{const "Let"} |
1401 Every simpset contains only |
1387 and so on. Every simpset contains only one congruence rule for each |
1402 one congruence rule for each term-constructor, which however can be |
1388 term-constructor, which however can be overwritten. The user can declare |
1403 overwritten. The user can declare lemmas to be congruence rules using the |
1389 lemmas to be congruence rules using the attribute @{text "[cong]"}. In HOL, |
1404 attribute @{text "[cong]"}. In HOL, the user usually states these lemmas as |
1390 the user usually states these lemmas as equations, which are then internally |
1405 equations, which are then internally transformed into meta-equations. |
1391 transformed into meta-equations. |
1406 |
1392 |
1407 |
1393 The rewriting with theorems involving premises requires what is in Isabelle |
1408 The rewriting with rules involving preconditions requires what is in |
1394 called a subgoaler, a solver and a looper. These can be arbitrary tactics |
1409 Isabelle called a subgoaler, a solver and a looper. These can be arbitrary |
1395 that can be installed in a simpset and which are executed at various stages |
1410 tactics that can be installed in a simpset and which are called at |
1396 during simplification. However, simpsets also include simprocs, which can |
1411 various stages during simplification. However, simpsets also include |
1397 produce rewrite rules on demand (see next section). Another component are |
1412 simprocs, which can produce rewrite rules on demand (see next |
1398 split-rules, which can simplify for example the ``then'' and ``else'' |
1413 section). Another component are split-rules, which can simplify for example |
1399 branches of if-statements under the corresponding preconditions. |
1414 the ``then'' and ``else'' branches of if-statements under the corresponding |
|
1415 preconditions. |
|
1416 |
|
1417 |
1400 |
1418 \begin{readmore} |
1401 \begin{readmore} |
1419 For more information about the simplifier see @{ML_file "Pure/meta_simplifier.ML"} |
1402 For more information about the simplifier see @{ML_file "Pure/meta_simplifier.ML"} |
1420 and @{ML_file "Pure/simplifier.ML"}. The simplifier for HOL is set up in |
1403 and @{ML_file "Pure/simplifier.ML"}. The generic splitter is implemented in |
1421 @{ML_file "HOL/Tools/simpdata.ML"}. The generic splitter is implemented in |
1404 @{ML_file "Provers/splitter.ML"}. |
1422 @{ML_file "Provers/splitter.ML"}. |
|
1423 \end{readmore} |
1405 \end{readmore} |
1424 |
1406 |
1425 \begin{readmore} |
1407 |
1426 FIXME: Find the right place: Discrimination nets are implemented |
1408 \footnote{\bf FIXME: Find the right place to mention this: Discrimination |
1427 in @{ML_file "Pure/net.ML"}. |
1409 nets are implemented in @{ML_file "Pure/net.ML"}.} |
1428 \end{readmore} |
|
1429 |
1410 |
1430 The most common combinators to modify simpsets are: |
1411 The most common combinators to modify simpsets are: |
1431 |
1412 |
1432 \begin{isabelle} |
1413 \begin{isabelle} |
1433 \begin{tabular}{ll} |
1414 \begin{tabular}{ll} |
1434 @{ML_ind addsimps} & @{ML_ind delsimps}\\ |
1415 @{ML_ind addsimps in MetaSimplifier} & @{ML_ind delsimps in MetaSimplifier}\\ |
1435 @{ML_ind addcongs} & @{ML_ind delcongs}\\ |
1416 @{ML_ind addcongs in MetaSimplifier} & @{ML_ind delcongs in MetaSimplifier}\\ |
1436 @{ML_ind addsimprocs} & @{ML_ind delsimprocs}\\ |
1417 @{ML_ind addsimprocs in MetaSimplifier} & @{ML_ind delsimprocs in MetaSimplifier}\\ |
1437 \end{tabular} |
1418 \end{tabular} |
1438 \end{isabelle} |
1419 \end{isabelle} |
1439 |
1420 |
1440 (FIXME: What about splitters? @{ML addsplits}, @{ML delsplits}) |
1421 \footnote{\bf FIXME: What about splitters? @{ML addsplits}, @{ML delsplits}} |
1441 *} |
1422 *} |
1442 |
1423 |
1443 text_raw {* |
1424 text_raw {* |
1444 \begin{figure}[t] |
1425 \begin{figure}[t] |
1445 \begin{minipage}{\textwidth} |
1426 \begin{minipage}{\textwidth} |
1538 |
1519 |
1539 and also resolve with assumptions. For example: |
1520 and also resolve with assumptions. For example: |
1540 *} |
1521 *} |
1541 |
1522 |
1542 lemma |
1523 lemma |
1543 "True" and "t = t" and "t \<equiv> t" and "False \<Longrightarrow> Foo" and "\<lbrakk>A; B; C\<rbrakk> \<Longrightarrow> A" |
1524 shows "True" |
|
1525 and "t = t" |
|
1526 and "t \<equiv> t" |
|
1527 and "False \<Longrightarrow> Foo" |
|
1528 and "\<lbrakk>A; B; C\<rbrakk> \<Longrightarrow> A" |
1544 apply(tactic {* ALLGOALS (simp_tac HOL_basic_ss) *}) |
1529 apply(tactic {* ALLGOALS (simp_tac HOL_basic_ss) *}) |
1545 done |
1530 done |
1546 |
1531 |
1547 text {* |
1532 text {* |
1548 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 |
1549 and looper are set up in @{ML_ind HOL_basic_ss}. |
1534 and looper are set up in @{ML_ind HOL_basic_ss}. |
1550 |
1535 |
1551 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 |
1552 already many useful simplification and congruence rules for the logical |
1537 already many useful simplification and congruence rules for the logical |
1553 connectives in HOL. |
1538 connectives in HOL. |
1554 |
1539 |
1555 @{ML_response_fake [display,gray] |
1540 @{ML_response_fake [display,gray] |
1556 "print_ss @{context} HOL_ss" |
1541 "print_ss @{context} HOL_ss" |