1140 |
1140 |
1141 (FIXME: how to add case-names to goal states - maybe in the |
1141 (FIXME: how to add case-names to goal states - maybe in the |
1142 next section) |
1142 next section) |
1143 *} |
1143 *} |
1144 |
1144 |
|
1145 section {* Setups (TBD) *} |
|
1146 |
|
1147 text {* |
|
1148 In the previous section we used \isacommand{setup} in order to make |
|
1149 a theorem attribute known to Isabelle. What happens behind the scenes |
|
1150 is that \isacommand{setup} expects a function of type |
|
1151 @{ML_type "theory -> theory"}: the input theory is the current theory and the |
|
1152 output the theory where the theory attribute has been stored. |
|
1153 |
|
1154 This is a fundamental principle in Isabelle. A similar situation occurs |
|
1155 for example with declaring constants. The function that declares a |
|
1156 constant on the ML-level is @{ML Sign.add_consts_i}. |
|
1157 If you write\footnote{Recall that ML-code needs to be |
|
1158 enclosed in \isacommand{ML}~@{text "\<verbopen> \<dots> \<verbclose>"}.} |
|
1159 *} |
|
1160 |
|
1161 ML{*Sign.add_consts_i [(@{binding "BAR"}, @{typ "nat"}, NoSyn)] @{theory} *} |
|
1162 |
|
1163 text {* |
|
1164 for declaring the constant @{text "BAR"} with type @{typ nat} and |
|
1165 run the code, then you indeed obtain a theory as result. But if you |
|
1166 query the constant on the Isabelle level using the command \isacommand{term} |
|
1167 |
|
1168 \begin{isabelle} |
|
1169 \isacommand{term}~@{text [quotes] "BAR"}\\ |
|
1170 @{text "> \"BAR\" :: \"'a\""} |
|
1171 \end{isabelle} |
|
1172 |
|
1173 you do not obtain a constant of type @{typ nat}, but a free variable (printed in |
|
1174 blue) of polymorphic type. The problem is that the ML-expression above did |
|
1175 not register the declaration with the current theory. This is what the command |
|
1176 \isacommand{setup} is for. The constant is properly declared with |
|
1177 *} |
|
1178 |
|
1179 setup %gray {* Sign.add_consts_i [(@{binding "BAR"}, @{typ "nat"}, NoSyn)] *} |
|
1180 |
|
1181 text {* |
|
1182 Now |
|
1183 |
|
1184 \begin{isabelle} |
|
1185 \isacommand{term}~@{text [quotes] "BAR"}\\ |
|
1186 @{text "> \"BAR\" :: \"nat\""} |
|
1187 \end{isabelle} |
|
1188 |
|
1189 returns a (black) constant with the type @{typ nat}. |
|
1190 |
|
1191 A similar command is \isacommand{local\_setup}, which expects a function |
|
1192 of type @{ML_type "local_theory -> local_theory"}. Later on we will also |
|
1193 use the commands \isacommand{method\_setup} for installing methods in the |
|
1194 current theory and \isacommand{simproc\_setup} for adding new simprocs to |
|
1195 the current simpset. |
|
1196 *} |
|
1197 |
1145 section {* Theorem Attributes *} |
1198 section {* Theorem Attributes *} |
1146 |
1199 |
1147 text {* |
1200 text {* |
1148 Theorem attributes are @{text "[symmetric]"}, @{text "[THEN \<dots>]"}, @{text |
1201 Theorem attributes are @{text "[symmetric]"}, @{text "[THEN \<dots>]"}, @{text |
1149 "[simp]"} and so on. Such attributes are \emph{neither} tags \emph{nor} flags |
1202 "[simp]"} and so on. Such attributes are \emph{neither} tags \emph{nor} flags |
1217 \begin{isabelle} |
1270 \begin{isabelle} |
1218 \isacommand{thm}~@{text "test[my_sym]"}\\ |
1271 \isacommand{thm}~@{text "test[my_sym]"}\\ |
1219 @{text "> "}~@{thm test[my_sym]} |
1272 @{text "> "}~@{thm test[my_sym]} |
1220 \end{isabelle} |
1273 \end{isabelle} |
1221 |
1274 |
|
1275 An alternative for setting up an attribute is the function @{ML Attrib.setup}. |
|
1276 So instead of using \isacommand{attribute\_setup}, you can also set up the |
|
1277 attribute as follows: |
|
1278 *} |
|
1279 |
|
1280 ML{*Attrib.setup @{binding "my_sym"} (Scan.succeed my_symmetric) |
|
1281 "applying the sym rule" *} |
|
1282 |
|
1283 text {* |
|
1284 This gives a function from @{ML_type "Context.theory -> Context.theory"}, which |
|
1285 can be used for example with \isacommand{setup}. |
|
1286 |
1222 As an example of a slightly more complicated theorem attribute, we implement |
1287 As an example of a slightly more complicated theorem attribute, we implement |
1223 our own version of @{text "[THEN \<dots>]"}. This attribute will take a list of theorems |
1288 our own version of @{text "[THEN \<dots>]"}. This attribute will take a list of theorems |
1224 as argument and resolve the proved theorem with this list (one theorem |
1289 as argument and resolve the proved theorem with this list (one theorem |
1225 after another). The code for this attribute is |
1290 after another). The code for this attribute is |
1226 *} |
1291 *} |
1508 parsing. |
1573 parsing. |
1509 \end{readmore} |
1574 \end{readmore} |
1510 *} |
1575 *} |
1511 |
1576 |
1512 |
1577 |
1513 section {* Setups (TBD) *} |
|
1514 |
|
1515 text {* |
|
1516 In the previous section we used \isacommand{setup} in order to make |
|
1517 a theorem attribute known to Isabelle. What happens behind the scenes |
|
1518 is that \isacommand{setup} expects a function of type |
|
1519 @{ML_type "theory -> theory"}: the input theory is the current theory and the |
|
1520 output the theory where the theory attribute has been stored. |
|
1521 |
|
1522 This is a fundamental principle in Isabelle. A similar situation occurs |
|
1523 for example with declaring constants. The function that declares a |
|
1524 constant on the ML-level is @{ML Sign.add_consts_i}. |
|
1525 If you write\footnote{Recall that ML-code needs to be |
|
1526 enclosed in \isacommand{ML}~@{text "\<verbopen> \<dots> \<verbclose>"}.} |
|
1527 *} |
|
1528 |
|
1529 ML{*Sign.add_consts_i [(@{binding "BAR"}, @{typ "nat"}, NoSyn)] @{theory} *} |
|
1530 |
|
1531 text {* |
|
1532 for declaring the constant @{text "BAR"} with type @{typ nat} and |
|
1533 run the code, then you indeed obtain a theory as result. But if you |
|
1534 query the constant on the Isabelle level using the command \isacommand{term} |
|
1535 |
|
1536 \begin{isabelle} |
|
1537 \isacommand{term}~@{text [quotes] "BAR"}\\ |
|
1538 @{text "> \"BAR\" :: \"'a\""} |
|
1539 \end{isabelle} |
|
1540 |
|
1541 you do not obtain a constant of type @{typ nat}, but a free variable (printed in |
|
1542 blue) of polymorphic type. The problem is that the ML-expression above did |
|
1543 not register the declaration with the current theory. This is what the command |
|
1544 \isacommand{setup} is for. The constant is properly declared with |
|
1545 *} |
|
1546 |
|
1547 setup %gray {* Sign.add_consts_i [(@{binding "BAR"}, @{typ "nat"}, NoSyn)] *} |
|
1548 |
|
1549 text {* |
|
1550 Now |
|
1551 |
|
1552 \begin{isabelle} |
|
1553 \isacommand{term}~@{text [quotes] "BAR"}\\ |
|
1554 @{text "> \"BAR\" :: \"nat\""} |
|
1555 \end{isabelle} |
|
1556 |
|
1557 returns a (black) constant with the type @{typ nat}. |
|
1558 |
|
1559 A similar command is \isacommand{local\_setup}, which expects a function |
|
1560 of type @{ML_type "local_theory -> local_theory"}. Later on we will also |
|
1561 use the commands \isacommand{method\_setup} for installing methods in the |
|
1562 current theory and \isacommand{simproc\_setup} for adding new simprocs to |
|
1563 the current simpset. |
|
1564 *} |
|
1565 |
1578 |
1566 section {* Theories, Contexts and Local Theories (TBD) *} |
1579 section {* Theories, Contexts and Local Theories (TBD) *} |
1567 |
1580 |
1568 text {* |
1581 text {* |
1569 There are theories, proof contexts and local theories (in this order, if you |
1582 There are theories, proof contexts and local theories (in this order, if you |