34 |
34 |
35 \subsection{Deriving a rule using tactics and meta-level assumptions} |
35 \subsection{Deriving a rule using tactics and meta-level assumptions} |
36 \label{deriving-example} |
36 \label{deriving-example} |
37 \index{examples!of deriving rules} |
37 \index{examples!of deriving rules} |
38 |
38 |
39 The subgoal module supports the derivation of rules. The \ttindex{goal} |
39 The subgoal module supports the derivation of rules, as discussed in |
40 command, when supplied a goal of the form $\List{\theta@1; \ldots; |
40 \S\ref{deriving}. The \ttindex{goal} command, when supplied a goal of the |
41 \theta@k} \Imp \phi$, creates $\phi\Imp\phi$ as the initial proof state and |
41 form $\List{\theta@1; \ldots; \theta@k} \Imp \phi$, creates $\phi\Imp\phi$ |
42 returns a list consisting of the theorems |
42 as the initial proof state and returns a list consisting of the theorems |
43 ${\theta@i\;[\theta@i]}$, for $i=1$, \ldots,~$k$. These meta-assumptions are |
43 ${\theta@i\;[\theta@i]}$, for $i=1$, \ldots,~$k$. These meta-assumptions |
44 also recorded internally, allowing \ttindex{result} to discharge them in the |
44 are also recorded internally, allowing \ttindex{result} to discharge them |
45 original order. |
45 in the original order. |
46 |
46 |
47 Let us derive $\conj$ elimination~(\S\ref{deriving}) using Isabelle. |
47 Let us derive $\conj$ elimination using Isabelle. |
48 Until now, calling \ttindex{goal} has returned an empty list, which we have |
48 Until now, calling \ttindex{goal} has returned an empty list, which we have |
49 thrown away. In this example, the list contains the two premises of the |
49 thrown away. In this example, the list contains the two premises of the |
50 rule. We bind them to the \ML\ identifiers {\tt major} and {\tt |
50 rule. We bind them to the \ML\ identifiers {\tt major} and {\tt |
51 minor}:\footnote{Some ML compilers will print a message such as {\em |
51 minor}:\footnote{Some ML compilers will print a message such as {\em |
52 binding not exhaustive}. This warns that {\tt goal} must return a |
52 binding not exhaustive}. This warns that {\tt goal} must return a |
351 associated concrete syntax. The translations section specifies rewrite |
351 associated concrete syntax. The translations section specifies rewrite |
352 rules on abstract syntax trees, for defining notations and abbreviations. |
352 rules on abstract syntax trees, for defining notations and abbreviations. |
353 The {\ML} section contains code to perform arbitrary syntactic |
353 The {\ML} section contains code to perform arbitrary syntactic |
354 transformations. The main declaration forms are discussed below. |
354 transformations. The main declaration forms are discussed below. |
355 The full syntax can be found in \iflabelundefined{app:TheorySyntax}{the |
355 The full syntax can be found in \iflabelundefined{app:TheorySyntax}{the |
356 appendix of the {\it Reference Manual}}{Appendix~\ref{app:TheorySyntax}}. |
356 appendix of the {\it Reference Manual}}{App.\ts\ref{app:TheorySyntax}}. |
357 |
357 |
358 All the declaration parts can be omitted. In the simplest case, $T$ is |
358 All the declaration parts can be omitted. In the simplest case, $T$ is |
359 just the union of $S@1$,~\ldots,~$S@n$. New theories always extend one |
359 just the union of $S@1$,~\ldots,~$S@n$. New theories always extend one |
360 or more other theories, inheriting their types, constants, syntax, etc. |
360 or more other theories, inheriting their types, constants, syntax, etc. |
361 The theory \ttindexbold{Pure} contains nothing but Isabelle's meta-logic. |
361 The theory \ttindexbold{Pure} contains nothing but Isabelle's meta-logic. |
516 Arity declarations resemble constant declarations, but there are {\it no\/} |
516 Arity declarations resemble constant declarations, but there are {\it no\/} |
517 quotation marks! Types and rules must be quoted because the theory |
517 quotation marks! Types and rules must be quoted because the theory |
518 translator passes them verbatim to the {\ML} output file. |
518 translator passes them verbatim to the {\ML} output file. |
519 \end{warn} |
519 \end{warn} |
520 |
520 |
521 \subsection{Type synonyms} |
521 \subsection{Type synonyms}\indexbold{types!synonyms} |
522 \indexbold{types!synonyms}\index{types!abbreviations|see{synonyms}} |
|
523 |
|
524 Isabelle supports {\bf type synonyms} ({\bf abbreviations}) which are similar |
522 Isabelle supports {\bf type synonyms} ({\bf abbreviations}) which are similar |
525 to those found in ML. Such synonyms are defined in the type declaration part |
523 to those found in \ML. Such synonyms are defined in the type declaration part |
526 and are fairly self explanatory: |
524 and are fairly self explanatory: |
527 \begin{ttbox} |
525 \begin{ttbox} |
528 types gate = "[o,o] => o" |
526 types gate = "[o,o] => o" |
529 'a pred = "'a => o" |
527 'a pred = "'a => o" |
530 ('a,'b)nuf = "'b => 'a" |
528 ('a,'b)nuf = "'b => 'a" |
531 \end{ttbox} |
529 \end{ttbox} |
532 Type declarations and synonyms can be mixed arbitrarily: |
530 Type declarations and synonyms can be mixed arbitrarily: |
533 \begin{ttbox} |
531 \begin{ttbox} |
534 types nat |
532 types nat |
535 'a stream = "nat => 'a" |
533 'a stream = "nat => 'a" |
536 signal = "nat stream" |
534 signal = "nat stream" |
537 'a list |
535 'a list |
538 \end{ttbox} |
536 \end{ttbox} |
539 A synonym is merely an abbreviation for some existing type expression. Hence |
537 A synonym is merely an abbreviation for some existing type expression. Hence |
540 synonyms may not be recursive! Internally all synonyms are fully expanded. As |
538 synonyms may not be recursive! Internally all synonyms are fully expanded. As |
541 a consequence Isabelle output never contains synonyms. Their main purpose is |
539 a consequence Isabelle output never contains synonyms. Their main purpose is |
542 to improve the readability of theories. Synonyms can be used just like any |
540 to improve the readability of theories. Synonyms can be used just like any |
543 other type: |
541 other type: |
544 \begin{ttbox} |
542 \begin{ttbox} |
545 consts and,or :: "gate" |
543 consts and,or :: "gate" |
546 negate :: "signal => signal" |
544 negate :: "signal => signal" |
547 \end{ttbox} |
545 \end{ttbox} |
639 subclass of $k$ existing classes: |
637 subclass of $k$ existing classes: |
640 \begin{ttbox} |
638 \begin{ttbox} |
641 \(id\) < \(c@1\), \ldots, \(c@k\) |
639 \(id\) < \(c@1\), \ldots, \(c@k\) |
642 \end{ttbox} |
640 \end{ttbox} |
643 Type classes allow constants to be overloaded. As suggested in |
641 Type classes allow constants to be overloaded. As suggested in |
644 \S\ref{polymorphic}, let us define the class $arith$ of ``arithmetic'' |
642 \S\ref{polymorphic}, let us define the class $arith$ of arithmetic |
645 types with the constants ${+} :: [\alpha,\alpha]\To \alpha$ and $0,1 {::} |
643 types with the constants ${+} :: [\alpha,\alpha]\To \alpha$ and $0,1 {::} |
646 \alpha$, for $\alpha{::}arith$. We introduce $arith$ as a subclass of |
644 \alpha$, for $\alpha{::}arith$. We introduce $arith$ as a subclass of |
647 $term$ and add the three polymorphic constants of this class. |
645 $term$ and add the three polymorphic constants of this class. |
648 \index{examples!of theories} |
646 \index{examples!of theories} |
649 \begin{ttbox} |
647 \begin{ttbox} |
697 |
695 |
698 Section\ts\ref{sec:logical-syntax} has formalized a first-order logic, |
696 Section\ts\ref{sec:logical-syntax} has formalized a first-order logic, |
699 including a type~$nat$ and the constants $0::nat$ and $Suc::nat\To nat$. |
697 including a type~$nat$ and the constants $0::nat$ and $Suc::nat\To nat$. |
700 Let us introduce the Peano axioms for mathematical induction and the |
698 Let us introduce the Peano axioms for mathematical induction and the |
701 freeness of $0$ and~$Suc$: |
699 freeness of $0$ and~$Suc$: |
702 \[ \vcenter{\infer[(induct)*]{P[n/x]}{P[0/x] & \infer*{P[Suc(x)/x]}{[P]}}} |
700 \[ \vcenter{\infer[(induct)]{P[n/x]}{P[0/x] & \infer*{P[Suc(x)/x]}{[P]}}} |
703 \qquad \parbox{4.5cm}{provided $x$ is not free in any assumption except~$P$} |
701 \qquad \parbox{4.5cm}{provided $x$ is not free in any assumption except~$P$} |
704 \] |
702 \] |
705 \[ \infer[(Suc\_inject)]{m=n}{Suc(m)=Suc(n)} \qquad |
703 \[ \infer[(Suc\_inject)]{m=n}{Suc(m)=Suc(n)} \qquad |
706 \infer[(Suc\_neq\_0)]{R}{Suc(m)=0} |
704 \infer[(Suc\_neq\_0)]{R}{Suc(m)=0} |
707 \] |
705 \] |
750 |
748 |
751 \subsection{Declaring the theory to Isabelle} |
749 \subsection{Declaring the theory to Isabelle} |
752 \index{examples!of theories} |
750 \index{examples!of theories} |
753 Let us create the theory \ttindexbold{Nat} starting from theory~\verb$FOL$, |
751 Let us create the theory \ttindexbold{Nat} starting from theory~\verb$FOL$, |
754 which contains only classical logic with no natural numbers. We declare |
752 which contains only classical logic with no natural numbers. We declare |
755 the 0-place type constructor $nat$ and the constants $rec$ and~$Suc$: |
753 the 0-place type constructor $nat$ and the associated constants. Note that |
|
754 the constant~0 requires a mixfix annotation because~0 is not a legal |
|
755 identifier, and could not otherwise be written in terms: |
756 \begin{ttbox} |
756 \begin{ttbox} |
757 Nat = FOL + |
757 Nat = FOL + |
758 types nat |
758 types nat |
759 arities nat :: term |
759 arities nat :: term |
760 consts "0" :: "nat" ("0") |
760 consts "0" :: "nat" ("0") |
833 and \ttindexbold{dres_inst_tac} are similar, but perform elim-resolution |
833 and \ttindexbold{dres_inst_tac} are similar, but perform elim-resolution |
834 and destruct-resolution, respectively. |
834 and destruct-resolution, respectively. |
835 \end{description} |
835 \end{description} |
836 The list {\it insts} consists of pairs $[(v@1,e@1), \ldots, (v@n,e@n)]$, |
836 The list {\it insts} consists of pairs $[(v@1,e@1), \ldots, (v@n,e@n)]$, |
837 where $v@1$, \ldots, $v@n$ are names of schematic variables in the rule --- |
837 where $v@1$, \ldots, $v@n$ are names of schematic variables in the rule --- |
838 with no leading question marks!! --- and $e@1$, \ldots, $e@n$ are |
838 with no leading question marks! --- and $e@1$, \ldots, $e@n$ are |
839 expressions giving their instantiations. The expressions are type-checked |
839 expressions giving their instantiations. The expressions are type-checked |
840 in the context of a particular subgoal: free variables receive the same |
840 in the context of a particular subgoal: free variables receive the same |
841 types as they have in the subgoal, and parameters may appear. Type |
841 types as they have in the subgoal, and parameters may appear. Type |
842 variable instantiations may appear in~{\it insts}, but they are seldom |
842 variable instantiations may appear in~{\it insts}, but they are seldom |
843 required: {\tt res_inst_tac} instantiates type variables automatically |
843 required: {\tt res_inst_tac} instantiates type variables automatically |