58 explicit information about the result of type-inference. *} |
58 explicit information about the result of type-inference. *} |
59 |
59 |
60 |
60 |
61 section {* Inductive and coinductive definitions \label{sec:hol-inductive} *} |
61 section {* Inductive and coinductive definitions \label{sec:hol-inductive} *} |
62 |
62 |
63 text {* An \emph{inductive definition} specifies the least predicate |
63 text {* |
64 or set @{text R} closed under given rules: applying a rule to |
64 \begin{matharray}{rcl} |
65 elements of @{text R} yields a result within @{text R}. For |
65 @{command_def (HOL) "inductive"} & : & @{text "local_theory \<rightarrow> local_theory"} \\ |
66 example, a structural operational semantics is an inductive |
66 @{command_def (HOL) "inductive_set"} & : & @{text "local_theory \<rightarrow> local_theory"} \\ |
67 definition of an evaluation relation. |
67 @{command_def (HOL) "coinductive"} & : & @{text "local_theory \<rightarrow> local_theory"} \\ |
|
68 @{command_def (HOL) "coinductive_set"} & : & @{text "local_theory \<rightarrow> local_theory"} \\ |
|
69 @{attribute_def (HOL) mono} & : & @{text attribute} \\ |
|
70 \end{matharray} |
|
71 |
|
72 An \emph{inductive definition} specifies the least predicate or set |
|
73 @{text R} closed under given rules: applying a rule to elements of |
|
74 @{text R} yields a result within @{text R}. For example, a |
|
75 structural operational semantics is an inductive definition of an |
|
76 evaluation relation. |
68 |
77 |
69 Dually, a \emph{coinductive definition} specifies the greatest |
78 Dually, a \emph{coinductive definition} specifies the greatest |
70 predicate or set @{text R} that is consistent with given rules: |
79 predicate or set @{text R} that is consistent with given rules: |
71 every element of @{text R} can be seen as arising by applying a rule |
80 every element of @{text R} can be seen as arising by applying a rule |
72 to elements of @{text R}. An important example is using |
81 to elements of @{text R}. An important example is using |
84 defined relation: there must be a monotonicity theorem of the form |
93 defined relation: there must be a monotonicity theorem of the form |
85 @{text "A \<le> B \<Longrightarrow> \<M> A \<le> \<M> B"}, for each premise @{text "\<M> R t"} in an |
94 @{text "A \<le> B \<Longrightarrow> \<M> A \<le> \<M> B"}, for each premise @{text "\<M> R t"} in an |
86 introduction rule. The default rule declarations of Isabelle/HOL |
95 introduction rule. The default rule declarations of Isabelle/HOL |
87 already take care of most common situations. |
96 already take care of most common situations. |
88 |
97 |
89 \begin{matharray}{rcl} |
|
90 @{command_def (HOL) "inductive"} & : & @{text "local_theory \<rightarrow> local_theory"} \\ |
|
91 @{command_def (HOL) "inductive_set"} & : & @{text "local_theory \<rightarrow> local_theory"} \\ |
|
92 @{command_def (HOL) "coinductive"} & : & @{text "local_theory \<rightarrow> local_theory"} \\ |
|
93 @{command_def (HOL) "coinductive_set"} & : & @{text "local_theory \<rightarrow> local_theory"} \\ |
|
94 @{attribute_def (HOL) mono} & : & @{text attribute} \\ |
|
95 \end{matharray} |
|
96 |
|
97 @{rail " |
98 @{rail " |
98 (@@{command (HOL) inductive} | @@{command (HOL) inductive_set} | |
99 (@@{command (HOL) inductive} | @@{command (HOL) inductive_set} | |
99 @@{command (HOL) coinductive} | @@{command (HOL) coinductive_set}) |
100 @@{command (HOL) coinductive} | @@{command (HOL) coinductive_set}) |
100 @{syntax target}? \\ |
101 @{syntax target}? \\ |
101 @{syntax \"fixes\"} (@'for' @{syntax \"fixes\"})? (@'where' clauses)? \\ |
102 @{syntax \"fixes\"} (@'for' @{syntax \"fixes\"})? (@'where' clauses)? \\ |
1249 *} |
1251 *} |
1250 |
1252 |
1251 section {* Quotient types *} |
1253 section {* Quotient types *} |
1252 |
1254 |
1253 text {* |
1255 text {* |
1254 The quotient package defines a new quotient type given a raw type |
|
1255 and a partial equivalence relation. |
|
1256 It also includes automation for transporting definitions and theorems. |
|
1257 It can automatically produce definitions and theorems on the quotient type, |
|
1258 given the corresponding constants and facts on the raw type. |
|
1259 |
|
1260 \begin{matharray}{rcl} |
1256 \begin{matharray}{rcl} |
1261 @{command_def (HOL) "quotient_type"} & : & @{text "local_theory \<rightarrow> proof(prove)"}\\ |
1257 @{command_def (HOL) "quotient_type"} & : & @{text "local_theory \<rightarrow> proof(prove)"}\\ |
1262 @{command_def (HOL) "quotient_definition"} & : & @{text "local_theory \<rightarrow> proof(prove)"}\\ |
1258 @{command_def (HOL) "quotient_definition"} & : & @{text "local_theory \<rightarrow> proof(prove)"}\\ |
1263 @{command_def (HOL) "print_quotmaps"} & : & @{text "context \<rightarrow>"}\\ |
1259 @{command_def (HOL) "print_quotmaps"} & : & @{text "context \<rightarrow>"}\\ |
1264 @{command_def (HOL) "print_quotients"} & : & @{text "context \<rightarrow>"}\\ |
1260 @{command_def (HOL) "print_quotients"} & : & @{text "context \<rightarrow>"}\\ |
1265 @{command_def (HOL) "print_quotconsts"} & : & @{text "context \<rightarrow>"}\\ |
1261 @{command_def (HOL) "print_quotconsts"} & : & @{text "context \<rightarrow>"}\\ |
1266 \end{matharray} |
1262 \end{matharray} |
1267 |
1263 |
|
1264 The quotient package defines a new quotient type given a raw type |
|
1265 and a partial equivalence relation. It also includes automation for |
|
1266 transporting definitions and theorems. It can automatically produce |
|
1267 definitions and theorems on the quotient type, given the |
|
1268 corresponding constants and facts on the raw type. |
|
1269 |
1268 @{rail " |
1270 @{rail " |
1269 @@{command (HOL) quotient_type} (spec + @'and'); |
1271 @@{command (HOL) quotient_type} (spec + @'and'); |
1270 |
1272 |
1271 spec: @{syntax typespec} @{syntax mixfix}? '=' \\ |
1273 spec: @{syntax typespec} @{syntax mixfix}? '=' \\ |
1272 @{syntax type} '/' ('partial' ':')? @{syntax term} \\ |
1274 @{syntax type} '/' ('partial' ':')? @{syntax term} \\ |
1280 constdecl: @{syntax name} ('::' @{syntax type})? @{syntax mixfix}? |
1282 constdecl: @{syntax name} ('::' @{syntax type})? @{syntax mixfix}? |
1281 "} |
1283 "} |
1282 |
1284 |
1283 \begin{description} |
1285 \begin{description} |
1284 |
1286 |
1285 \item @{command (HOL) "quotient_type"} defines quotient types. The injection from a quotient type |
1287 \item @{command (HOL) "quotient_type"} defines quotient types. The |
1286 to a raw type is called @{text rep_t}, its inverse @{text abs_t} unless explicit @{keyword (HOL) |
1288 injection from a quotient type to a raw type is called @{text |
|
1289 rep_t}, its inverse @{text abs_t} unless explicit @{keyword (HOL) |
1287 "morphisms"} specification provides alternative names. |
1290 "morphisms"} specification provides alternative names. |
1288 |
1291 |
1289 \item @{command (HOL) "quotient_definition"} defines a constant on the quotient type. |
1292 \item @{command (HOL) "quotient_definition"} defines a constant on |
1290 |
1293 the quotient type. |
1291 \item @{command (HOL) "print_quotmaps"} prints quotient map functions. |
1294 |
|
1295 \item @{command (HOL) "print_quotmaps"} prints quotient map |
|
1296 functions. |
1292 |
1297 |
1293 \item @{command (HOL) "print_quotients"} prints quotients. |
1298 \item @{command (HOL) "print_quotients"} prints quotients. |
1294 |
1299 |
1295 \item @{command (HOL) "print_quotconsts"} prints quotient constants. |
1300 \item @{command (HOL) "print_quotconsts"} prints quotient constants. |
1296 |
1301 |
1297 \end{description} |
1302 \end{description} |
1298 |
1303 *} |
1299 *} |
1304 |
1300 |
1305 |
1301 section {* Coercive subtyping *} |
1306 section {* Coercive subtyping *} |
1302 |
1307 |
1303 text {* |
1308 text {* |
1304 \begin{matharray}{rcl} |
1309 \begin{matharray}{rcl} |
1305 @{attribute_def (HOL) coercion} & : & @{text attribute} \\ |
1310 @{attribute_def (HOL) coercion} & : & @{text attribute} \\ |
1306 @{attribute_def (HOL) coercion_enabled} & : & @{text attribute} \\ |
1311 @{attribute_def (HOL) coercion_enabled} & : & @{text attribute} \\ |
1307 @{attribute_def (HOL) coercion_map} & : & @{text attribute} \\ |
1312 @{attribute_def (HOL) coercion_map} & : & @{text attribute} \\ |
1308 \end{matharray} |
1313 \end{matharray} |
1309 |
1314 |
|
1315 Coercive subtyping allows the user to omit explicit type |
|
1316 conversions, also called \emph{coercions}. Type inference will add |
|
1317 them as necessary when parsing a term. See |
|
1318 \cite{traytel-berghofer-nipkow-2011} for details. |
|
1319 |
1310 @{rail " |
1320 @{rail " |
1311 @@{attribute (HOL) coercion} (@{syntax term})? |
1321 @@{attribute (HOL) coercion} (@{syntax term})? |
1312 ; |
1322 ; |
1313 "} |
1323 "} |
1314 @{rail " |
1324 @{rail " |
1315 @@{attribute (HOL) coercion_map} (@{syntax term})? |
1325 @@{attribute (HOL) coercion_map} (@{syntax term})? |
1316 ; |
1326 ; |
1317 "} |
1327 "} |
1318 |
1328 |
1319 Coercive subtyping allows the user to omit explicit type conversions, |
|
1320 also called \emph{coercions}. Type inference will add them as |
|
1321 necessary when parsing a term. See |
|
1322 \cite{traytel-berghofer-nipkow-2011} for details. |
|
1323 |
|
1324 \begin{description} |
1329 \begin{description} |
1325 |
1330 |
1326 \item @{attribute (HOL) "coercion"}~@{text "f"} registers a new |
1331 \item @{attribute (HOL) "coercion"}~@{text "f"} registers a new |
1327 coercion function @{text "f :: \<sigma>\<^isub>1 \<Rightarrow> |
1332 coercion function @{text "f :: \<sigma>\<^isub>1 \<Rightarrow> \<sigma>\<^isub>2"} where @{text "\<sigma>\<^isub>1"} and |
1328 \<sigma>\<^isub>2"} where @{text "\<sigma>\<^isub>1"} and @{text |
1333 @{text "\<sigma>\<^isub>2"} are type constructors without arguments. Coercions are |
1329 "\<sigma>\<^isub>2"} are nullary type constructors. Coercions are |
1334 composed by the inference algorithm if needed. Note that the type |
1330 composed by the inference algorithm if needed. Note that the type |
1335 inference algorithm is complete only if the registered coercions |
1331 inference algorithm is complete only if the registered coercions form |
1336 form a lattice. |
1332 a lattice. |
1337 |
1333 |
1338 \item @{attribute (HOL) "coercion_map"}~@{text "map"} registers a |
1334 |
1339 new map function to lift coercions through type constructors. The |
1335 \item @{attribute (HOL) "coercion_map"}~@{text "map"} registers a new |
1340 function @{text "map"} must conform to the following type pattern |
1336 map function to lift coercions through type constructors. The function |
|
1337 @{text "map"} must conform to the following type pattern |
|
1338 |
1341 |
1339 \begin{matharray}{lll} |
1342 \begin{matharray}{lll} |
1340 @{text "map"} & @{text "::"} & |
1343 @{text "map"} & @{text "::"} & |
1341 @{text "f\<^isub>1 \<Rightarrow> \<dots> \<Rightarrow> f\<^isub>n \<Rightarrow> (\<alpha>\<^isub>1, \<dots>, \<alpha>\<^isub>n) t \<Rightarrow> (\<beta>\<^isub>1, \<dots>, \<beta>\<^isub>n) t"} \\ |
1344 @{text "f\<^isub>1 \<Rightarrow> \<dots> \<Rightarrow> f\<^isub>n \<Rightarrow> (\<alpha>\<^isub>1, \<dots>, \<alpha>\<^isub>n) t \<Rightarrow> (\<beta>\<^isub>1, \<dots>, \<beta>\<^isub>n) t"} \\ |
1342 \end{matharray} |
1345 \end{matharray} |
1343 |
1346 |
1344 where @{text "t"} is a type constructor and @{text "f\<^isub>i"} is of |
1347 where @{text "t"} is a type constructor and @{text "f\<^isub>i"} is of type |
1345 type @{text "\<alpha>\<^isub>i \<Rightarrow> \<beta>\<^isub>i"} or |
1348 @{text "\<alpha>\<^isub>i \<Rightarrow> \<beta>\<^isub>i"} or @{text "\<beta>\<^isub>i \<Rightarrow> \<alpha>\<^isub>i"}. Registering a map function |
1346 @{text "\<beta>\<^isub>i \<Rightarrow> \<alpha>\<^isub>i"}. |
1349 overwrites any existing map function for this particular type |
1347 Registering a map function overwrites any existing map function for |
1350 constructor. |
1348 this particular type constructor. |
|
1349 |
|
1350 |
1351 |
1351 \item @{attribute (HOL) "coercion_enabled"} enables the coercion |
1352 \item @{attribute (HOL) "coercion_enabled"} enables the coercion |
1352 inference algorithm. |
1353 inference algorithm. |
1353 |
1354 |
1354 \end{description} |
1355 \end{description} |
1355 |
1356 *} |
1356 *} |
1357 |
1357 |
1358 |
1358 section {* Arithmetic proof support *} |
1359 section {* Arithmetic proof support *} |
1359 |
1360 |
1360 text {* |
1361 text {* |
1361 \begin{matharray}{rcl} |
1362 \begin{matharray}{rcl} |
1362 @{method_def (HOL) arith} & : & @{text method} \\ |
1363 @{method_def (HOL) arith} & : & @{text method} \\ |
1363 @{attribute_def (HOL) arith} & : & @{text attribute} \\ |
1364 @{attribute_def (HOL) arith} & : & @{text attribute} \\ |
1364 @{attribute_def (HOL) arith_split} & : & @{text attribute} \\ |
1365 @{attribute_def (HOL) arith_split} & : & @{text attribute} \\ |
1365 \end{matharray} |
1366 \end{matharray} |
1366 |
1367 |
1367 The @{method (HOL) arith} method decides linear arithmetic problems |
1368 \begin{description} |
1368 (on types @{text nat}, @{text int}, @{text real}). Any current |
1369 |
1369 facts are inserted into the goal before running the procedure. |
1370 \item @{method (HOL) arith} decides linear arithmetic problems (on |
1370 |
1371 types @{text nat}, @{text int}, @{text real}). Any current facts |
1371 The @{attribute (HOL) arith} attribute declares facts that are |
1372 are inserted into the goal before running the procedure. |
1372 always supplied to the arithmetic provers implicitly. |
1373 |
1373 |
1374 \item @{attribute (HOL) arith} declares facts that are supplied to |
1374 The @{attribute (HOL) arith_split} attribute declares case split |
1375 the arithmetic provers implicitly. |
|
1376 |
|
1377 \item @{attribute (HOL) arith_split} attribute declares case split |
1375 rules to be expanded before @{method (HOL) arith} is invoked. |
1378 rules to be expanded before @{method (HOL) arith} is invoked. |
1376 |
1379 |
1377 Note that a simpler (but faster) arithmetic prover is |
1380 \end{description} |
1378 already invoked by the Simplifier. |
1381 |
|
1382 Note that a simpler (but faster) arithmetic prover is already |
|
1383 invoked by the Simplifier. |
1379 *} |
1384 *} |
1380 |
1385 |
1381 |
1386 |
1382 section {* Intuitionistic proof search *} |
1387 section {* Intuitionistic proof search *} |
1383 |
1388 |
1388 |
1393 |
1389 @{rail " |
1394 @{rail " |
1390 @@{method (HOL) iprover} ( @{syntax rulemod} * ) |
1395 @@{method (HOL) iprover} ( @{syntax rulemod} * ) |
1391 "} |
1396 "} |
1392 |
1397 |
1393 The @{method (HOL) iprover} method performs intuitionistic proof |
1398 \begin{description} |
1394 search, depending on specifically declared rules from the context, |
1399 |
1395 or given as explicit arguments. Chained facts are inserted into the |
1400 \item @{method (HOL) iprover} performs intuitionistic proof search, |
1396 goal before commencing proof search. |
1401 depending on specifically declared rules from the context, or given |
|
1402 as explicit arguments. Chained facts are inserted into the goal |
|
1403 before commencing proof search. |
1397 |
1404 |
1398 Rules need to be classified as @{attribute (Pure) intro}, |
1405 Rules need to be classified as @{attribute (Pure) intro}, |
1399 @{attribute (Pure) elim}, or @{attribute (Pure) dest}; here the |
1406 @{attribute (Pure) elim}, or @{attribute (Pure) dest}; here the |
1400 ``@{text "!"}'' indicator refers to ``safe'' rules, which may be |
1407 ``@{text "!"}'' indicator refers to ``safe'' rules, which may be |
1401 applied aggressively (without considering back-tracking later). |
1408 applied aggressively (without considering back-tracking later). |
1402 Rules declared with ``@{text "?"}'' are ignored in proof search (the |
1409 Rules declared with ``@{text "?"}'' are ignored in proof search (the |
1403 single-step @{method (Pure) rule} method still observes these). An |
1410 single-step @{method (Pure) rule} method still observes these). An |
1404 explicit weight annotation may be given as well; otherwise the |
1411 explicit weight annotation may be given as well; otherwise the |
1405 number of rule premises will be taken into account here. |
1412 number of rule premises will be taken into account here. |
1406 *} |
1413 |
|
1414 \end{description} |
|
1415 *} |
|
1416 |
1407 |
1417 |
1408 section {* Model Elimination and Resolution *} |
1418 section {* Model Elimination and Resolution *} |
1409 |
1419 |
1410 text {* |
1420 text {* |
1411 \begin{matharray}{rcl} |
1421 \begin{matharray}{rcl} |
1415 |
1425 |
1416 @{rail " |
1426 @{rail " |
1417 @@{method (HOL) meson} @{syntax thmrefs}? |
1427 @@{method (HOL) meson} @{syntax thmrefs}? |
1418 ; |
1428 ; |
1419 |
1429 |
1420 @@{method (HOL) metis} ( '(' ('partial_types' | 'full_types' | 'no_types' |
1430 @@{method (HOL) metis} |
1421 | @{syntax name}) ')' )? @{syntax thmrefs}? |
1431 ('(' ('partial_types' | 'full_types' | 'no_types' | @{syntax name}) ')')? |
|
1432 @{syntax thmrefs}? |
1422 "} |
1433 "} |
1423 |
1434 |
1424 The @{method (HOL) meson} method implements Loveland's model elimination |
1435 \begin{description} |
1425 procedure \cite{loveland-78}. See @{file "~~/src/HOL/ex/Meson_Test.thy"} for |
1436 |
1426 examples. |
1437 \item @{method (HOL) meson} implements Loveland's model elimination |
1427 |
1438 procedure \cite{loveland-78}. See @{file |
1428 The @{method (HOL) metis} method combines ordered resolution and ordered |
1439 "~~/src/HOL/ex/Meson_Test.thy"} for examples. |
1429 paramodulation to find first-order (or mildly higher-order) proofs. The first |
1440 |
1430 optional argument specifies a type encoding; see the Sledgehammer manual |
1441 \item @{method (HOL) metis} combines ordered resolution and ordered |
1431 \cite{isabelle-sledgehammer} for details. The @{file |
1442 paramodulation to find first-order (or mildly higher-order) proofs. |
1432 "~~/src/HOL/Metis_Examples"} directory contains several small theories |
1443 The first optional argument specifies a type encoding; see the |
1433 developed to a large extent using Metis. |
1444 Sledgehammer manual \cite{isabelle-sledgehammer} for details. The |
1434 *} |
1445 directory @{file "~~/src/HOL/Metis_Examples"} contains several small |
|
1446 theories developed to a large extent using @{method (HOL) metis}. |
|
1447 |
|
1448 \end{description} |
|
1449 *} |
|
1450 |
1435 |
1451 |
1436 section {* Coherent Logic *} |
1452 section {* Coherent Logic *} |
1437 |
1453 |
1438 text {* |
1454 text {* |
1439 \begin{matharray}{rcl} |
1455 \begin{matharray}{rcl} |