1 %% $Id$ |
1 %% $Id$ |
2 \part{Advanced Methods} |
2 \part{Advanced Methods} |
3 Before continuing, it might be wise to try some of your own examples in |
3 Before continuing, it might be wise to try some of your own examples in |
4 Isabelle, reinforcing your knowledge of the basic functions. |
4 Isabelle, reinforcing your knowledge of the basic functions. |
5 |
5 |
6 Look through {\em Isabelle's Object-Logics\/} and try proving some simple |
6 Look through {\em Isabelle's Object-Logics\/} and try proving some |
7 theorems. You probably should begin with first-order logic ({\tt FOL} |
7 simple theorems. You probably should begin with first-order logic |
8 or~{\tt LK}). Try working some of the examples provided, and others from |
8 ({\tt FOL} or~{\tt LK}). Try working some of the examples provided, |
9 the literature. Set theory~({\tt ZF}) and Constructive Type Theory~({\tt |
9 and others from the literature. Set theory~({\tt ZF}) and |
10 CTT}) form a richer world for mathematical reasoning and, again, many |
10 Constructive Type Theory~({\tt CTT}) form a richer world for |
11 examples are in the literature. Higher-order logic~({\tt HOL}) is |
11 mathematical reasoning and, again, many examples are in the |
12 Isabelle's most sophisticated logic because its types and functions are |
12 literature. Higher-order logic~({\tt HOL}) is Isabelle's most |
13 identified with those of the meta-logic. |
13 elaborate logic. Its types and functions are identified with those of |
|
14 the meta-logic. |
14 |
15 |
15 Choose a logic that you already understand. Isabelle is a proof |
16 Choose a logic that you already understand. Isabelle is a proof |
16 tool, not a teaching tool; if you do not know how to do a particular proof |
17 tool, not a teaching tool; if you do not know how to do a particular proof |
17 on paper, then you certainly will not be able to do it on the machine. |
18 on paper, then you certainly will not be able to do it on the machine. |
18 Even experienced users plan large proofs on paper. |
19 Even experienced users plan large proofs on paper. |
34 \subsection{Deriving a rule using tactics and meta-level assumptions} |
35 \subsection{Deriving a rule using tactics and meta-level assumptions} |
35 \label{deriving-example} |
36 \label{deriving-example} |
36 \index{examples!of deriving rules}\index{assumptions!of main goal} |
37 \index{examples!of deriving rules}\index{assumptions!of main goal} |
37 |
38 |
38 The subgoal module supports the derivation of rules, as discussed in |
39 The subgoal module supports the derivation of rules, as discussed in |
39 \S\ref{deriving}. The \ttindex{goal} command, when supplied a goal of the |
40 \S\ref{deriving}. The \ttindex{goal} command, when supplied a goal of |
40 form $\List{\theta@1; \ldots; \theta@k} \Imp \phi$, creates $\phi\Imp\phi$ |
41 the form $\List{\theta@1; \ldots; \theta@k} \Imp \phi$, creates |
41 as the initial proof state and returns a list consisting of the theorems |
42 $\phi\Imp\phi$ as the initial proof state and returns a list |
42 ${\theta@i\;[\theta@i]}$, for $i=1$, \ldots,~$k$. These meta-assumptions |
43 consisting of the theorems ${\theta@i\;[\theta@i]}$, for $i=1$, |
43 are also recorded internally, allowing {\tt result} to discharge them |
44 \ldots,~$k$. These meta-assumptions are also recorded internally, |
|
45 allowing {\tt result} (which is called by {\tt qed}) to discharge them |
44 in the original order. |
46 in the original order. |
45 |
47 |
46 Let us derive $\conj$ elimination using Isabelle. |
48 Let us derive $\conj$ elimination using Isabelle. |
47 Until now, calling {\tt goal} has returned an empty list, which we have |
49 Until now, calling {\tt goal} has returned an empty list, which we have |
48 thrown away. In this example, the list contains the two premises of the |
50 thrown away. In this example, the list contains the two premises of the |
326 |
328 |
327 |
329 |
328 \section{Defining theories}\label{sec:defining-theories} |
330 \section{Defining theories}\label{sec:defining-theories} |
329 \index{theories!defining|(} |
331 \index{theories!defining|(} |
330 |
332 |
331 Isabelle makes no distinction between simple extensions of a logic --- like |
333 Isabelle makes no distinction between simple extensions of a logic --- |
332 defining a type~$bool$ with constants~$true$ and~$false$ --- and defining |
334 like specifying a type~$bool$ with constants~$true$ and~$false$ --- |
333 an entire logic. A theory definition has the form |
335 and defining an entire logic. A theory definition has a form like |
334 \begin{ttbox} |
336 \begin{ttbox} |
335 \(T\) = \(S@1\) + \(\cdots\) + \(S@n\) + |
337 \(T\) = \(S@1\) + \(\cdots\) + \(S@n\) + |
336 classes {\it class declarations} |
338 classes {\it class declarations} |
337 default {\it sort} |
339 default {\it sort} |
338 types {\it type declarations and synonyms} |
340 types {\it type declarations and synonyms} |
339 arities {\it arity declarations} |
341 arities {\it type arity declarations} |
340 consts {\it constant declarations} |
342 consts {\it constant declarations} |
341 translations {\it translation declarations} |
343 syntax {\it syntactic constant declarations} |
342 defs {\it definitions} |
344 translations {\it ast translation rules} |
|
345 defs {\it meta-logical definitions} |
343 rules {\it rule declarations} |
346 rules {\it rule declarations} |
344 end |
347 end |
345 ML {\it ML code} |
348 ML {\it ML code} |
346 \end{ttbox} |
349 \end{ttbox} |
347 This declares the theory $T$ to extend the existing theories |
350 This declares the theory $T$ to extend the existing theories |
348 $S@1$,~\ldots,~$S@n$. It may declare new classes, types, arities |
351 $S@1$,~\ldots,~$S@n$. It may introduce new classes, types, arities |
349 (overloadings of existing types), constants and rules; it can specify the |
352 (of existing types), constants and rules; it can specify the default |
350 default sort for type variables. A constant declaration can specify an |
353 sort for type variables. A constant declaration can specify an |
351 associated concrete syntax. The translations section specifies rewrite |
354 associated concrete syntax. The translations section specifies |
352 rules on abstract syntax trees, for defining notations and abbreviations. |
355 rewrite rules on abstract syntax trees, handling notations and |
353 \index{*ML section} |
356 abbreviations. \index{*ML section} The {\tt ML} section may contain |
354 The {\tt ML} section contains code to perform arbitrary syntactic |
357 code to perform arbitrary syntactic transformations. The main |
355 transformations. The main declaration forms are discussed below. |
358 declaration forms are discussed below. The full syntax can be found |
356 The full syntax can be found in \iflabelundefined{app:TheorySyntax}{the |
359 in \iflabelundefined{app:TheorySyntax}{an appendix of the {\it |
357 appendix of the {\it Reference Manual}}{App.\ts\ref{app:TheorySyntax}}. |
360 Reference Manual}}{App.\ts\ref{app:TheorySyntax}}. Also note that |
358 |
361 object-logics may add further theory sections, for example {\tt |
359 All the declaration parts can be omitted or repeated and may appear in any |
362 typedef}, {\tt datatype} in \HOL. |
360 order, except that the {\ML} section must be last. In the simplest case, $T$ |
363 |
361 is just the union of $S@1$,~\ldots,~$S@n$. New theories always extend one or |
364 All the declaration parts can be omitted or repeated and may appear in |
362 more other theories, inheriting their types, constants, syntax, etc. The |
365 any order, except that the {\ML} section must be last (after the {\tt |
363 theory \thydx{Pure} contains nothing but Isabelle's meta-logic. |
366 end} keyword). In the simplest case, $T$ is just the union of |
364 |
367 $S@1$,~\ldots,~$S@n$. New theories always extend one or more other |
365 Each theory definition must reside in a separate file, whose name is the |
368 theories, inheriting their types, constants, syntax, etc. The theory |
366 theory's with {\tt.thy} appended. For example, theory {\tt ListFn} resides |
369 \thydx{Pure} contains nothing but Isabelle's meta-logic. The variant |
367 on a file named {\tt ListFn.thy}. Isabelle uses this convention to locate the |
370 \thydx{CPure} offers the more usual higher-order function application |
368 file containing a given theory; \ttindexbold{use_thy} automatically loads a |
371 syntax $t\,u@1\ldots\,u@n$ instead of $t(u@1,\ldots,u@n)$. |
369 theory's parents before loading the theory itself. |
372 |
370 |
373 Each theory definition must reside in a separate file, whose name is |
371 Calling \ttindexbold{use_thy}~{\tt"{\it T\/}"} reads a theory from the |
374 the theory's with {\tt.thy} appended. Calling |
372 file {\it T}{\tt.thy}, writes the corresponding {\ML} code to the file |
375 \ttindexbold{use_thy}~{\tt"{\it T\/}"} reads the definition from {\it |
373 {\tt.{\it T}.thy.ML}, reads the latter file, and deletes it if no errors |
376 T}{\tt.thy}, writes a corresponding file of {\ML} code {\tt.{\it |
374 occurred. This declares the {\ML} structure~$T$, which contains a component |
377 T}.thy.ML}, reads the latter file, and deletes it if no errors |
375 {\tt thy} denoting the new theory, a component for each rule, and everything |
378 occurred. This declares the {\ML} structure~$T$, which contains a |
376 declared in {\it ML code}. |
379 component {\tt thy} denoting the new theory, a component for each |
377 |
380 rule, and everything declared in {\it ML code}. |
378 Errors may arise during the translation to {\ML} (say, a misspelled keyword) |
381 |
379 or during creation of the new theory (say, a type error in a rule). But if |
382 Errors may arise during the translation to {\ML} (say, a misspelled |
380 all goes well, {\tt use_thy} will finally read the file {\it T}{\tt.ML}, if |
383 keyword) or during creation of the new theory (say, a type error in a |
381 it exists. This file typically begins with the {\ML} declaration {\tt |
384 rule). But if all goes well, {\tt use_thy} will finally read the file |
382 open}~$T$ and contains proofs that refer to the components of~$T$. |
385 {\it T}{\tt.ML} (if it exists). This file typically contains proofs |
383 |
386 that refer to the components of~$T$. The structure is automatically |
384 When a theory file is modified, many theories may have to be reloaded. |
387 opened, so its components may be referred to by unqualified names, |
385 Isabelle records the modification times and dependencies of theory files. |
388 e.g.\ just {\tt thy} instead of $T${\tt .thy}. |
386 See |
389 |
|
390 \ttindexbold{use_thy} automatically loads a theory's parents before |
|
391 loading the theory itself. When a theory file is modified, many |
|
392 theories may have to be reloaded. Isabelle records the modification |
|
393 times and dependencies of theory files. See |
387 \iflabelundefined{sec:reloading-theories}{the {\em Reference Manual\/}}% |
394 \iflabelundefined{sec:reloading-theories}{the {\em Reference Manual\/}}% |
388 {\S\ref{sec:reloading-theories}} |
395 {\S\ref{sec:reloading-theories}} |
389 for more details. |
396 for more details. |
390 |
397 |
391 |
398 |
416 \end{ttbox} |
423 \end{ttbox} |
417 where $id@1$, \ldots, $id@n$ are \ML{} identifiers and $rule@1$, \ldots, |
424 where $id@1$, \ldots, $id@n$ are \ML{} identifiers and $rule@1$, \ldots, |
418 $rule@n$ are expressions of type~$prop$. Each rule {\em must\/} be |
425 $rule@n$ are expressions of type~$prop$. Each rule {\em must\/} be |
419 enclosed in quotation marks. |
426 enclosed in quotation marks. |
420 |
427 |
421 \indexbold{definitions} The {\bf definition part} is similar, but with the |
428 \indexbold{definitions} The {\bf definition part} is similar, but with |
422 keyword {\tt defs} instead of {\tt rules}. {\bf Definitions} are rules of the |
429 the keyword {\tt defs} instead of {\tt rules}. {\bf Definitions} are |
423 form $s \equiv t$, and should serve only as abbreviations. The simplest form |
430 rules of the form $s \equiv t$, and should serve only as |
424 of a definition is $f \equiv t$, where $f$ is a constant. Isabelle also |
431 abbreviations. The simplest form of a definition is $f \equiv t$, |
425 allows a derived form where the arguments of~$f$ appear on the left: |
432 where $f$ is a constant. Also allowed are $\eta$-equivalent forms, |
426 \begin{itemize} |
433 where the arguments of~$f$ appear applied on the left-hand side of the |
427 \item In uncurried syntax: $f(x@1,\dots,x@n) \equiv u$ (\FOL, \ZF, \dots) |
434 equation instead of abstracted on the right-hand side. |
428 \item In curried syntax: $f~x@1~\dots~x@n \equiv u$ (\HOL, \HOLCF) |
435 |
429 \end{itemize} |
436 Isabelle checks for common errors in definitions, such as extra |
430 Isabelle checks for common errors in definitions, such as extra variables on |
437 variables on the right-hand side, but currently does not a complete |
431 the right-hand side. Determined users can write non-conservative |
438 test of well-formedness. Thus determined users can write |
432 `definitions' by using mutual recursion, for example; the consequences of |
439 non-conservative `definitions' by using mutual recursion, for example; |
433 such actions are their responsibility. |
440 the consequences of such actions are their responsibility. |
434 |
441 |
435 \index{examples!of theories} |
442 \index{examples!of theories} This example theory extends first-order |
436 This theory extends first-order logic by declaring and defining two constants, |
443 logic by declaring and defining two constants, {\em nand} and {\em |
437 {\em nand} and {\em xor}: |
444 xor}: |
438 \begin{ttbox} |
445 \begin{ttbox} |
439 Gate = FOL + |
446 Gate = FOL + |
440 consts nand,xor :: [o,o] => o |
447 consts nand,xor :: [o,o] => o |
441 defs nand_def "nand(P,Q) == ~(P & Q)" |
448 defs nand_def "nand(P,Q) == ~(P & Q)" |
442 xor_def "xor(P,Q) == P & ~Q | ~P & Q" |
449 xor_def "xor(P,Q) == P & ~Q | ~P & Q" |
621 \end{ttbox} |
628 \end{ttbox} |
622 This declares a constant $If$ of type $[o,o,o] \To o$ with concrete syntax {\tt |
629 This declares a constant $If$ of type $[o,o,o] \To o$ with concrete syntax {\tt |
623 if~$P$ then~$Q$ else~$R$} as well as {\tt If($P$,$Q$,$R$)}. Underscores |
630 if~$P$ then~$Q$ else~$R$} as well as {\tt If($P$,$Q$,$R$)}. Underscores |
624 denote argument positions. |
631 denote argument positions. |
625 |
632 |
626 The declaration above does not allow the {\tt if}-{\tt then}-{\tt else} |
633 The declaration above does not allow the {\tt if}-{\tt then}-{\tt |
627 construct to be split across several lines, even if it is too long to fit |
634 else} construct to be printed split across several lines, even if it |
628 on one line. Pretty-printing information can be added to specify the |
635 is too long to fit on one line. Pretty-printing information can be |
629 layout of mixfix operators. For details, see |
636 added to specify the layout of mixfix operators. For details, see |
630 \iflabelundefined{Defining-Logics}% |
637 \iflabelundefined{Defining-Logics}% |
631 {the {\it Reference Manual}, chapter `Defining Logics'}% |
638 {the {\it Reference Manual}, chapter `Defining Logics'}% |
632 {Chap.\ts\ref{Defining-Logics}}. |
639 {Chap.\ts\ref{Defining-Logics}}. |
633 |
640 |
634 Mixfix declarations can be annotated with priorities, just like |
641 Mixfix declarations can be annotated with priorities, just like |