1117 *} |
1117 *} |
1118 |
1118 |
1119 text_raw {* |
1119 text_raw {* |
1120 \begin{figure}[tp] |
1120 \begin{figure}[tp] |
1121 \begin{isabelle}*} |
1121 \begin{isabelle}*} |
1122 ML{*fun get_parts ss = |
1122 ML{*fun print_ss ctxt ss = |
1123 let |
|
1124 val ({rules, ...}, {congs, procs, ...}) = MetaSimplifier.rep_ss ss |
|
1125 |
|
1126 val rules_list = Net.entries rules |
|
1127 val rnames = map #name rules_list |
|
1128 val rthms = map #thm rules_list |
|
1129 |
|
1130 val congs_list = fst congs |
|
1131 val cnames = map fst congs_list |
|
1132 val cthms = map (#thm o snd) congs_list |
|
1133 |
|
1134 val proc_list = Net.entries procs |
|
1135 in |
|
1136 (rnames ~~ rthms, cnames ~~ cthms) |
|
1137 end |
|
1138 |
|
1139 fun print_parts ctxt ss = |
|
1140 let |
1123 let |
1141 val (simps, congs) = get_parts ss |
1124 val {simps, congs, procs, ...} = MetaSimplifier.dest_ss ss |
1142 |
1125 |
1143 fun name_thm (nm, thm) = |
1126 fun name_thm (nm, thm) = |
1144 " " ^ nm ^ ": " ^ (str_of_thm ctxt thm) |
1127 " " ^ nm ^ ": " ^ (str_of_thm ctxt thm) |
|
1128 fun name_ctrm (nm, ctrm) = |
|
1129 " " ^ nm ^ ": " ^ (str_of_cterms ctxt ctrm) |
1145 |
1130 |
1146 val s1 = ["Simplification rules:"] |
1131 val s1 = ["Simplification rules:"] |
1147 val s2 = map name_thm simps |
1132 val s2 = map name_thm simps |
1148 val s3 = ["Congruences rules:"] |
1133 val s3 = ["Congruences rules:"] |
1149 val s4 = map name_thm congs |
1134 val s4 = map name_thm congs |
|
1135 val s5 = ["Simproc patterns:"] |
|
1136 val s6 = map name_ctrm procs |
1150 in |
1137 in |
1151 (s1 @ s2 @ s3 @ s4) |
1138 (s1 @ s2 @ s3 @ s4 @ s5 @ s6) |
1152 |> separate "\n" |
1139 |> separate "\n" |
1153 |> implode |
1140 |> implode |
1154 |> warning |
1141 |> warning |
1155 end*} |
1142 end*} |
1156 text_raw {* |
1143 text_raw {* |
1157 \end{isabelle} |
1144 \end{isabelle} |
1158 \caption{The function @{ML MetaSimplifier.rep_ss} returns a record containing |
1145 \caption{The function @{ML MetaSimplifier.dest_ss} returns a record containing |
1159 a simpset. We are here only interested in the simplifcation rules, congruence rules and |
1146 all printable information stored in a simpset. We are here only interested in the |
1160 simprocs. The first and third are discrimination nets, which from which we extract |
1147 simplifcation rules, congruence rules and simprocs.\label{fig:printss}} |
1161 lists using @{ML Net.entries}. The congruence rules are stored in |
|
1162 an association list, associating a constant with a rule.\label{fig:prettyss}} |
|
1163 \end{figure} *} |
1148 \end{figure} *} |
1164 |
1149 |
1165 text {* |
1150 text {* |
1166 To see how they work, consider the two functions in Figure~\ref{fig:prettyss}, which |
1151 To see how they work, consider the two functions in Figure~\ref{fig:printss}, which |
1167 print out some parts of a simpset. If you use them to print out the components of the |
1152 print out some parts of a simpset. If you use them to print out the components of the |
1168 empty simpset, in ML @{ML empty_ss} and the most primitive simpset |
1153 empty simpset, in ML @{ML empty_ss} and the most primitive simpset |
1169 |
1154 |
1170 @{ML_response_fake [display,gray] |
1155 @{ML_response_fake [display,gray] |
1171 "print_parts @{context} empty_ss" |
1156 "print_ss @{context} empty_ss" |
1172 "Simplification rules: |
1157 "Simplification rules: |
1173 Congruences rules:"} |
1158 Congruences rules: |
|
1159 Simproc patterns:"} |
1174 |
1160 |
1175 you can see it contains nothing. This simpset is usually not useful, except as a |
1161 you can see it contains nothing. This simpset is usually not useful, except as a |
1176 building block to build bigger simpsets. For example you can add to @{ML empty_ss} |
1162 building block to build bigger simpsets. For example you can add to @{ML empty_ss} |
1177 the simplification rule @{thm [source] Diff_Int} as follows: |
1163 the simplification rule @{thm [source] Diff_Int} as follows: |
1178 *} |
1164 *} |
1181 |
1167 |
1182 text {* |
1168 text {* |
1183 Printing then out the components of the simpset gives: |
1169 Printing then out the components of the simpset gives: |
1184 |
1170 |
1185 @{ML_response_fake [display,gray] |
1171 @{ML_response_fake [display,gray] |
1186 "print_parts @{context} ss1" |
1172 "print_ss @{context} ss1" |
1187 "Simplification rules: |
|
1188 ??.unknown: A - B \<inter> C \<equiv> A - B \<union> (A - C) |
|
1189 Congruences rules:"} |
|
1190 |
|
1191 (FIXME: Why does it print out ??.unknown) |
|
1192 |
|
1193 Adding also the congruence rule @{thm [source] UN_cong} |
|
1194 *} |
|
1195 |
|
1196 ML{*val ss2 = ss1 addcongs [@{thm UN_cong} RS @{thm eq_reflection}] *} |
|
1197 |
|
1198 text {* |
|
1199 gives |
|
1200 |
|
1201 @{ML_response_fake [display,gray] |
|
1202 "print_parts @{context} ss2" |
|
1203 "Simplification rules: |
1173 "Simplification rules: |
1204 ??.unknown: A - B \<inter> C \<equiv> A - B \<union> (A - C) |
1174 ??.unknown: A - B \<inter> C \<equiv> A - B \<union> (A - C) |
1205 Congruences rules: |
1175 Congruences rules: |
1206 UNION: \<lbrakk>A = B; \<And>x. x \<in> B \<Longrightarrow> C x = D x\<rbrakk> \<Longrightarrow> \<Union>x\<in>A. C x \<equiv> \<Union>x\<in>B. D x"} |
1176 Simproc patterns:"} |
|
1177 |
|
1178 (FIXME: Why does it print out ??.unknown) |
|
1179 |
|
1180 Adding also the congruence rule @{thm [source] UN_cong} |
|
1181 *} |
|
1182 |
|
1183 ML{*val ss2 = ss1 addcongs [@{thm UN_cong} RS @{thm eq_reflection}] *} |
|
1184 |
|
1185 text {* |
|
1186 gives |
|
1187 |
|
1188 @{ML_response_fake [display,gray] |
|
1189 "print_ss @{context} ss2" |
|
1190 "Simplification rules: |
|
1191 ??.unknown: A - B \<inter> C \<equiv> A - B \<union> (A - C) |
|
1192 Congruences rules: |
|
1193 UNION: \<lbrakk>A = B; \<And>x. x \<in> B \<Longrightarrow> C x = D x\<rbrakk> \<Longrightarrow> \<Union>x\<in>A. C x \<equiv> \<Union>x\<in>B. D x |
|
1194 Simproc patterns:"} |
1207 |
1195 |
1208 Notice that we had to add these lemmas as meta-equations. The @{ML empty_ss} |
1196 Notice that we had to add these lemmas as meta-equations. The @{ML empty_ss} |
1209 expects this form of the simplification and congruence rules. However, even |
1197 expects this form of the simplification and congruence rules. However, even |
1210 when adding these lemmas to @{ML empty_ss} we do not end up with anything useful yet. |
1198 when adding these lemmas to @{ML empty_ss} we do not end up with anything useful yet. |
1211 |
1199 |
1212 In the context of HOL, the first really useful simpset is @{ML HOL_basic_ss}. While |
1200 In the context of HOL, the first really useful simpset is @{ML HOL_basic_ss}. While |
1213 printing out the components of this simpset |
1201 printing out the components of this simpset |
1214 |
1202 |
1215 @{ML_response_fake [display,gray] |
1203 @{ML_response_fake [display,gray] |
1216 "print_parts @{context} HOL_basic_ss" |
1204 "print_ss @{context} HOL_basic_ss" |
1217 "Simplification rules: |
1205 "Simplification rules: |
1218 Congruences rules:"} |
1206 Congruences rules: |
|
1207 Simproc patterns:"} |
1219 |
1208 |
1220 also produces ``nothing'', the printout is misleading. In fact |
1209 also produces ``nothing'', the printout is misleading. In fact |
1221 the @{ML HOL_basic_ss} is setup so that it can solve goals of the |
1210 the @{ML HOL_basic_ss} is setup so that it can solve goals of the |
1222 form @{thm TrueI}, @{thm refl[no_vars]}, @{term "t \<equiv> t"} and @{thm FalseE[no_vars]}; |
1211 form @{thm TrueI}, @{thm refl[no_vars]}, @{term "t \<equiv> t"} and @{thm FalseE[no_vars]}; |
1223 and also resolve with assumptions. For example: |
1212 and also resolve with assumptions. For example: |
1237 The simpset @{ML HOL_ss} is an extention of @{ML HOL_basic_ss} containing |
1226 The simpset @{ML HOL_ss} is an extention of @{ML HOL_basic_ss} containing |
1238 already many useful simplification and congruence rules for the logical |
1227 already many useful simplification and congruence rules for the logical |
1239 connectives in HOL. |
1228 connectives in HOL. |
1240 |
1229 |
1241 @{ML_response_fake [display,gray] |
1230 @{ML_response_fake [display,gray] |
1242 "print_parts @{context} HOL_ss" |
1231 "print_ss @{context} HOL_ss" |
1243 "Simplification rules: |
1232 "Simplification rules: |
1244 Pure.triv_forall_equality: (\<And>x. PROP V) \<equiv> PROP V |
1233 Pure.triv_forall_equality: (\<And>x. PROP V) \<equiv> PROP V |
1245 HOL.the_eq_trivial: THE x. x = y \<equiv> y |
1234 HOL.the_eq_trivial: THE x. x = y \<equiv> y |
1246 HOL.the_sym_eq_trivial: THE ya. y = ya \<equiv> y |
1235 HOL.the_sym_eq_trivial: THE ya. y = ya \<equiv> y |
1247 \<dots> |
1236 \<dots> |
1248 Congruences rules: |
1237 Congruences rules: |
1249 HOL.simp_implies: \<dots> |
1238 HOL.simp_implies: \<dots> |
1250 \<Longrightarrow> (PROP P =simp=> PROP Q) \<equiv> (PROP P' =simp=> PROP Q') |
1239 \<Longrightarrow> (PROP P =simp=> PROP Q) \<equiv> (PROP P' =simp=> PROP Q') |
1251 op -->: \<lbrakk>P \<equiv> P'; P' \<Longrightarrow> Q \<equiv> Q'\<rbrakk> \<Longrightarrow> P \<longrightarrow> Q \<equiv> P' \<longrightarrow> Q'"} |
1240 op -->: \<lbrakk>P \<equiv> P'; P' \<Longrightarrow> Q \<equiv> Q'\<rbrakk> \<Longrightarrow> P \<longrightarrow> Q \<equiv> P' \<longrightarrow> Q' |
|
1241 Simproc patterns: |
|
1242 \<dots>"} |
1252 |
1243 |
1253 |
1244 |
1254 The simplifier is often used to unfold definitions in a proof. For this the |
1245 The simplifier is often used to unfold definitions in a proof. For this the |
1255 simplifier contains the @{ML rewrite_goals_tac}. Suppose for example the |
1246 simplifier contains the @{ML rewrite_goals_tac}. Suppose for example the |
1256 definition |
1247 definition |
1416 often be done easier by implementing a simproc or a conversion. Both will be |
1407 often be done easier by implementing a simproc or a conversion. Both will be |
1417 explained in the next two chapters. |
1408 explained in the next two chapters. |
1418 |
1409 |
1419 (FIXME: Is it interesting to say something about @{term "op =simp=>"}?) |
1410 (FIXME: Is it interesting to say something about @{term "op =simp=>"}?) |
1420 |
1411 |
1421 (FIXME: Unfortunately one cannot access any simproc, as there is |
|
1422 no @{text rep_proc} in function @{ML get_parts}.) |
|
1423 |
|
1424 (FIXME: What are the second components of the congruence rules---something to |
1412 (FIXME: What are the second components of the congruence rules---something to |
1425 do with weak congruence constants?) |
1413 do with weak congruence constants?) |
1426 |
1414 |
1427 (FIXME: Anything interesting to say about @{ML Simplifier.clear_ss}?) |
1415 (FIXME: Anything interesting to say about @{ML Simplifier.clear_ss}?) |
1428 |
1416 |