author | wenzelm |
Tue, 24 Mar 2009 18:21:58 +0100 | |
changeset 30709 | d9ca766bf24c |
parent 30552 | 58db56278478 |
child 32836 | 4c6e3e7ac2bf |
permissions | -rw-r--r-- |
30296 | 1 |
% |
2 |
\begin{isabellebody}% |
|
3 |
\def\isabellecontext{Logic}% |
|
4 |
% |
|
5 |
\isadelimtheory |
|
6 |
% |
|
7 |
\endisadelimtheory |
|
8 |
% |
|
9 |
\isatagtheory |
|
10 |
\isacommand{theory}\isamarkupfalse% |
|
11 |
\ Logic\isanewline |
|
12 |
\isakeyword{imports}\ Base\isanewline |
|
13 |
\isakeyword{begin}% |
|
14 |
\endisatagtheory |
|
15 |
{\isafoldtheory}% |
|
16 |
% |
|
17 |
\isadelimtheory |
|
18 |
% |
|
19 |
\endisadelimtheory |
|
20 |
% |
|
21 |
\isamarkupchapter{Primitive logic \label{ch:logic}% |
|
22 |
} |
|
23 |
\isamarkuptrue% |
|
24 |
% |
|
25 |
\begin{isamarkuptext}% |
|
26 |
The logical foundations of Isabelle/Isar are that of the Pure logic, |
|
27 |
which has been introduced as a Natural Deduction framework in |
|
28 |
\cite{paulson700}. This is essentially the same logic as ``\isa{{\isasymlambda}HOL}'' in the more abstract setting of Pure Type Systems (PTS) |
|
29 |
\cite{Barendregt-Geuvers:2001}, although there are some key |
|
30 |
differences in the specific treatment of simple types in |
|
31 |
Isabelle/Pure. |
|
32 |
||
33 |
Following type-theoretic parlance, the Pure logic consists of three |
|
34 |
levels of \isa{{\isasymlambda}}-calculus with corresponding arrows, \isa{{\isasymRightarrow}} for syntactic function space (terms depending on terms), \isa{{\isasymAnd}} for universal quantification (proofs depending on terms), and |
|
35 |
\isa{{\isasymLongrightarrow}} for implication (proofs depending on proofs). |
|
36 |
||
37 |
Derivations are relative to a logical theory, which declares type |
|
38 |
constructors, constants, and axioms. Theory declarations support |
|
39 |
schematic polymorphism, which is strictly speaking outside the |
|
40 |
logic.\footnote{This is the deeper logical reason, why the theory |
|
41 |
context \isa{{\isasymTheta}} is separate from the proof context \isa{{\isasymGamma}} |
|
42 |
of the core calculus.}% |
|
43 |
\end{isamarkuptext}% |
|
44 |
\isamarkuptrue% |
|
45 |
% |
|
46 |
\isamarkupsection{Types \label{sec:types}% |
|
47 |
} |
|
48 |
\isamarkuptrue% |
|
49 |
% |
|
50 |
\begin{isamarkuptext}% |
|
51 |
The language of types is an uninterpreted order-sorted first-order |
|
52 |
algebra; types are qualified by ordered type classes. |
|
53 |
||
54 |
\medskip A \emph{type class} is an abstract syntactic entity |
|
55 |
declared in the theory context. The \emph{subclass relation} \isa{c\isactrlisub {\isadigit{1}}\ {\isasymsubseteq}\ c\isactrlisub {\isadigit{2}}} is specified by stating an acyclic |
|
56 |
generating relation; the transitive closure is maintained |
|
57 |
internally. The resulting relation is an ordering: reflexive, |
|
58 |
transitive, and antisymmetric. |
|
59 |
||
60 |
A \emph{sort} is a list of type classes written as \isa{s\ {\isacharequal}\ {\isacharbraceleft}c\isactrlisub {\isadigit{1}}{\isacharcomma}\ {\isasymdots}{\isacharcomma}\ c\isactrlisub m{\isacharbraceright}}, which represents symbolic |
|
61 |
intersection. Notationally, the curly braces are omitted for |
|
62 |
singleton intersections, i.e.\ any class \isa{c} may be read as |
|
63 |
a sort \isa{{\isacharbraceleft}c{\isacharbraceright}}. The ordering on type classes is extended to |
|
64 |
sorts according to the meaning of intersections: \isa{{\isacharbraceleft}c\isactrlisub {\isadigit{1}}{\isacharcomma}\ {\isasymdots}\ c\isactrlisub m{\isacharbraceright}\ {\isasymsubseteq}\ {\isacharbraceleft}d\isactrlisub {\isadigit{1}}{\isacharcomma}\ {\isasymdots}{\isacharcomma}\ d\isactrlisub n{\isacharbraceright}} iff |
|
65 |
\isa{{\isasymforall}j{\isachardot}\ {\isasymexists}i{\isachardot}\ c\isactrlisub i\ {\isasymsubseteq}\ d\isactrlisub j}. The empty intersection |
|
66 |
\isa{{\isacharbraceleft}{\isacharbraceright}} refers to the universal sort, which is the largest |
|
67 |
element wrt.\ the sort order. The intersections of all (finitely |
|
68 |
many) classes declared in the current theory are the minimal |
|
69 |
elements wrt.\ the sort order. |
|
70 |
||
71 |
\medskip A \emph{fixed type variable} is a pair of a basic name |
|
72 |
(starting with a \isa{{\isacharprime}} character) and a sort constraint, e.g.\ |
|
73 |
\isa{{\isacharparenleft}{\isacharprime}a{\isacharcomma}\ s{\isacharparenright}} which is usually printed as \isa{{\isasymalpha}\isactrlisub s}. |
|
74 |
A \emph{schematic type variable} is a pair of an indexname and a |
|
75 |
sort constraint, e.g.\ \isa{{\isacharparenleft}{\isacharparenleft}{\isacharprime}a{\isacharcomma}\ {\isadigit{0}}{\isacharparenright}{\isacharcomma}\ s{\isacharparenright}} which is usually |
|
76 |
printed as \isa{{\isacharquery}{\isasymalpha}\isactrlisub s}. |
|
77 |
||
78 |
Note that \emph{all} syntactic components contribute to the identity |
|
79 |
of type variables, including the sort constraint. The core logic |
|
80 |
handles type variables with the same name but different sorts as |
|
81 |
different, although some outer layers of the system make it hard to |
|
82 |
produce anything like this. |
|
83 |
||
84 |
A \emph{type constructor} \isa{{\isasymkappa}} is a \isa{k}-ary operator |
|
85 |
on types declared in the theory. Type constructor application is |
|
86 |
written postfix as \isa{{\isacharparenleft}{\isasymalpha}\isactrlisub {\isadigit{1}}{\isacharcomma}\ {\isasymdots}{\isacharcomma}\ {\isasymalpha}\isactrlisub k{\isacharparenright}{\isasymkappa}}. For |
|
87 |
\isa{k\ {\isacharequal}\ {\isadigit{0}}} the argument tuple is omitted, e.g.\ \isa{prop} |
|
88 |
instead of \isa{{\isacharparenleft}{\isacharparenright}prop}. For \isa{k\ {\isacharequal}\ {\isadigit{1}}} the parentheses |
|
89 |
are omitted, e.g.\ \isa{{\isasymalpha}\ list} instead of \isa{{\isacharparenleft}{\isasymalpha}{\isacharparenright}list}. |
|
90 |
Further notation is provided for specific constructors, notably the |
|
91 |
right-associative infix \isa{{\isasymalpha}\ {\isasymRightarrow}\ {\isasymbeta}} instead of \isa{{\isacharparenleft}{\isasymalpha}{\isacharcomma}\ {\isasymbeta}{\isacharparenright}fun}. |
|
92 |
||
93 |
A \emph{type} is defined inductively over type variables and type |
|
94 |
constructors as follows: \isa{{\isasymtau}\ {\isacharequal}\ {\isasymalpha}\isactrlisub s\ {\isacharbar}\ {\isacharquery}{\isasymalpha}\isactrlisub s\ {\isacharbar}\ {\isacharparenleft}{\isasymtau}\isactrlsub {\isadigit{1}}{\isacharcomma}\ {\isasymdots}{\isacharcomma}\ {\isasymtau}\isactrlsub k{\isacharparenright}{\isasymkappa}}. |
|
95 |
||
96 |
A \emph{type abbreviation} is a syntactic definition \isa{{\isacharparenleft}\isactrlvec {\isasymalpha}{\isacharparenright}{\isasymkappa}\ {\isacharequal}\ {\isasymtau}} of an arbitrary type expression \isa{{\isasymtau}} over |
|
97 |
variables \isa{\isactrlvec {\isasymalpha}}. Type abbreviations appear as type |
|
98 |
constructors in the syntax, but are expanded before entering the |
|
99 |
logical core. |
|
100 |
||
101 |
A \emph{type arity} declares the image behavior of a type |
|
102 |
constructor wrt.\ the algebra of sorts: \isa{{\isasymkappa}\ {\isacharcolon}{\isacharcolon}\ {\isacharparenleft}s\isactrlisub {\isadigit{1}}{\isacharcomma}\ {\isasymdots}{\isacharcomma}\ s\isactrlisub k{\isacharparenright}s} means that \isa{{\isacharparenleft}{\isasymtau}\isactrlisub {\isadigit{1}}{\isacharcomma}\ {\isasymdots}{\isacharcomma}\ {\isasymtau}\isactrlisub k{\isacharparenright}{\isasymkappa}} is |
|
103 |
of sort \isa{s} if every argument type \isa{{\isasymtau}\isactrlisub i} is |
|
104 |
of sort \isa{s\isactrlisub i}. Arity declarations are implicitly |
|
105 |
completed, i.e.\ \isa{{\isasymkappa}\ {\isacharcolon}{\isacharcolon}\ {\isacharparenleft}\isactrlvec s{\isacharparenright}c} entails \isa{{\isasymkappa}\ {\isacharcolon}{\isacharcolon}\ {\isacharparenleft}\isactrlvec s{\isacharparenright}c{\isacharprime}} for any \isa{c{\isacharprime}\ {\isasymsupseteq}\ c}. |
|
106 |
||
107 |
\medskip The sort algebra is always maintained as \emph{coregular}, |
|
108 |
which means that type arities are consistent with the subclass |
|
109 |
relation: for any type constructor \isa{{\isasymkappa}}, and classes \isa{c\isactrlisub {\isadigit{1}}\ {\isasymsubseteq}\ c\isactrlisub {\isadigit{2}}}, and arities \isa{{\isasymkappa}\ {\isacharcolon}{\isacharcolon}\ {\isacharparenleft}\isactrlvec s\isactrlisub {\isadigit{1}}{\isacharparenright}c\isactrlisub {\isadigit{1}}} and \isa{{\isasymkappa}\ {\isacharcolon}{\isacharcolon}\ {\isacharparenleft}\isactrlvec s\isactrlisub {\isadigit{2}}{\isacharparenright}c\isactrlisub {\isadigit{2}}} holds \isa{\isactrlvec s\isactrlisub {\isadigit{1}}\ {\isasymsubseteq}\ \isactrlvec s\isactrlisub {\isadigit{2}}} component-wise. |
|
110 |
||
111 |
The key property of a coregular order-sorted algebra is that sort |
|
112 |
constraints can be solved in a most general fashion: for each type |
|
113 |
constructor \isa{{\isasymkappa}} and sort \isa{s} there is a most general |
|
114 |
vector of argument sorts \isa{{\isacharparenleft}s\isactrlisub {\isadigit{1}}{\isacharcomma}\ {\isasymdots}{\isacharcomma}\ s\isactrlisub k{\isacharparenright}} such |
|
115 |
that a type scheme \isa{{\isacharparenleft}{\isasymalpha}\isactrlbsub s\isactrlisub {\isadigit{1}}\isactrlesub {\isacharcomma}\ {\isasymdots}{\isacharcomma}\ {\isasymalpha}\isactrlbsub s\isactrlisub k\isactrlesub {\isacharparenright}{\isasymkappa}} is of sort \isa{s}. |
|
116 |
Consequently, type unification has most general solutions (modulo |
|
117 |
equivalence of sorts), so type-inference produces primary types as |
|
118 |
expected \cite{nipkow-prehofer}.% |
|
119 |
\end{isamarkuptext}% |
|
120 |
\isamarkuptrue% |
|
121 |
% |
|
122 |
\isadelimmlref |
|
123 |
% |
|
124 |
\endisadelimmlref |
|
125 |
% |
|
126 |
\isatagmlref |
|
127 |
% |
|
128 |
\begin{isamarkuptext}% |
|
129 |
\begin{mldecls} |
|
130 |
\indexdef{}{ML type}{class}\verb|type class| \\ |
|
131 |
\indexdef{}{ML type}{sort}\verb|type sort| \\ |
|
132 |
\indexdef{}{ML type}{arity}\verb|type arity| \\ |
|
133 |
\indexdef{}{ML type}{typ}\verb|type typ| \\ |
|
134 |
\indexdef{}{ML}{map\_atyps}\verb|map_atyps: (typ -> typ) -> typ -> typ| \\ |
|
135 |
\indexdef{}{ML}{fold\_atyps}\verb|fold_atyps: (typ -> 'a -> 'a) -> typ -> 'a -> 'a| \\ |
|
136 |
\end{mldecls} |
|
137 |
\begin{mldecls} |
|
138 |
\indexdef{}{ML}{Sign.subsort}\verb|Sign.subsort: theory -> sort * sort -> bool| \\ |
|
139 |
\indexdef{}{ML}{Sign.of\_sort}\verb|Sign.of_sort: theory -> typ * sort -> bool| \\ |
|
30355 | 140 |
\indexdef{}{ML}{Sign.add\_types}\verb|Sign.add_types: (binding * int * mixfix) list -> theory -> theory| \\ |
30296 | 141 |
\indexdef{}{ML}{Sign.add\_tyabbrs\_i}\verb|Sign.add_tyabbrs_i: |\isasep\isanewline% |
30355 | 142 |
\verb| (binding * string list * typ * mixfix) list -> theory -> theory| \\ |
143 |
\indexdef{}{ML}{Sign.primitive\_class}\verb|Sign.primitive_class: binding * class list -> theory -> theory| \\ |
|
30296 | 144 |
\indexdef{}{ML}{Sign.primitive\_classrel}\verb|Sign.primitive_classrel: class * class -> theory -> theory| \\ |
145 |
\indexdef{}{ML}{Sign.primitive\_arity}\verb|Sign.primitive_arity: arity -> theory -> theory| \\ |
|
146 |
\end{mldecls} |
|
147 |
||
148 |
\begin{description} |
|
149 |
||
150 |
\item \verb|class| represents type classes; this is an alias for |
|
151 |
\verb|string|. |
|
152 |
||
153 |
\item \verb|sort| represents sorts; this is an alias for |
|
154 |
\verb|class list|. |
|
155 |
||
156 |
\item \verb|arity| represents type arities; this is an alias for |
|
157 |
triples of the form \isa{{\isacharparenleft}{\isasymkappa}{\isacharcomma}\ \isactrlvec s{\isacharcomma}\ s{\isacharparenright}} for \isa{{\isasymkappa}\ {\isacharcolon}{\isacharcolon}\ {\isacharparenleft}\isactrlvec s{\isacharparenright}s} described above. |
|
158 |
||
159 |
\item \verb|typ| represents types; this is a datatype with |
|
160 |
constructors \verb|TFree|, \verb|TVar|, \verb|Type|. |
|
161 |
||
162 |
\item \verb|map_atyps|~\isa{f\ {\isasymtau}} applies the mapping \isa{f} |
|
163 |
to all atomic types (\verb|TFree|, \verb|TVar|) occurring in \isa{{\isasymtau}}. |
|
164 |
||
165 |
\item \verb|fold_atyps|~\isa{f\ {\isasymtau}} iterates the operation \isa{f} over all occurrences of atomic types (\verb|TFree|, \verb|TVar|) |
|
166 |
in \isa{{\isasymtau}}; the type structure is traversed from left to right. |
|
167 |
||
168 |
\item \verb|Sign.subsort|~\isa{thy\ {\isacharparenleft}s\isactrlisub {\isadigit{1}}{\isacharcomma}\ s\isactrlisub {\isadigit{2}}{\isacharparenright}} |
|
169 |
tests the subsort relation \isa{s\isactrlisub {\isadigit{1}}\ {\isasymsubseteq}\ s\isactrlisub {\isadigit{2}}}. |
|
170 |
||
171 |
\item \verb|Sign.of_sort|~\isa{thy\ {\isacharparenleft}{\isasymtau}{\isacharcomma}\ s{\isacharparenright}} tests whether type |
|
172 |
\isa{{\isasymtau}} is of sort \isa{s}. |
|
173 |
||
174 |
\item \verb|Sign.add_types|~\isa{{\isacharbrackleft}{\isacharparenleft}{\isasymkappa}{\isacharcomma}\ k{\isacharcomma}\ mx{\isacharparenright}{\isacharcomma}\ {\isasymdots}{\isacharbrackright}} declares a new |
|
175 |
type constructors \isa{{\isasymkappa}} with \isa{k} arguments and |
|
176 |
optional mixfix syntax. |
|
177 |
||
178 |
\item \verb|Sign.add_tyabbrs_i|~\isa{{\isacharbrackleft}{\isacharparenleft}{\isasymkappa}{\isacharcomma}\ \isactrlvec {\isasymalpha}{\isacharcomma}\ {\isasymtau}{\isacharcomma}\ mx{\isacharparenright}{\isacharcomma}\ {\isasymdots}{\isacharbrackright}} |
|
179 |
defines a new type abbreviation \isa{{\isacharparenleft}\isactrlvec {\isasymalpha}{\isacharparenright}{\isasymkappa}\ {\isacharequal}\ {\isasymtau}} with |
|
180 |
optional mixfix syntax. |
|
181 |
||
182 |
\item \verb|Sign.primitive_class|~\isa{{\isacharparenleft}c{\isacharcomma}\ {\isacharbrackleft}c\isactrlisub {\isadigit{1}}{\isacharcomma}\ {\isasymdots}{\isacharcomma}\ c\isactrlisub n{\isacharbrackright}{\isacharparenright}} declares a new class \isa{c}, together with class |
|
183 |
relations \isa{c\ {\isasymsubseteq}\ c\isactrlisub i}, for \isa{i\ {\isacharequal}\ {\isadigit{1}}{\isacharcomma}\ {\isasymdots}{\isacharcomma}\ n}. |
|
184 |
||
185 |
\item \verb|Sign.primitive_classrel|~\isa{{\isacharparenleft}c\isactrlisub {\isadigit{1}}{\isacharcomma}\ c\isactrlisub {\isadigit{2}}{\isacharparenright}} declares the class relation \isa{c\isactrlisub {\isadigit{1}}\ {\isasymsubseteq}\ c\isactrlisub {\isadigit{2}}}. |
|
186 |
||
187 |
\item \verb|Sign.primitive_arity|~\isa{{\isacharparenleft}{\isasymkappa}{\isacharcomma}\ \isactrlvec s{\isacharcomma}\ s{\isacharparenright}} declares |
|
188 |
the arity \isa{{\isasymkappa}\ {\isacharcolon}{\isacharcolon}\ {\isacharparenleft}\isactrlvec s{\isacharparenright}s}. |
|
189 |
||
190 |
\end{description}% |
|
191 |
\end{isamarkuptext}% |
|
192 |
\isamarkuptrue% |
|
193 |
% |
|
194 |
\endisatagmlref |
|
195 |
{\isafoldmlref}% |
|
196 |
% |
|
197 |
\isadelimmlref |
|
198 |
% |
|
199 |
\endisadelimmlref |
|
200 |
% |
|
201 |
\isamarkupsection{Terms \label{sec:terms}% |
|
202 |
} |
|
203 |
\isamarkuptrue% |
|
204 |
% |
|
205 |
\begin{isamarkuptext}% |
|
206 |
The language of terms is that of simply-typed \isa{{\isasymlambda}}-calculus |
|
207 |
with de-Bruijn indices for bound variables (cf.\ \cite{debruijn72} |
|
208 |
or \cite{paulson-ml2}), with the types being determined by the |
|
209 |
corresponding binders. In contrast, free variables and constants |
|
210 |
are have an explicit name and type in each occurrence. |
|
211 |
||
212 |
\medskip A \emph{bound variable} is a natural number \isa{b}, |
|
213 |
which accounts for the number of intermediate binders between the |
|
214 |
variable occurrence in the body and its binding position. For |
|
215 |
example, the de-Bruijn term \isa{{\isasymlambda}\isactrlbsub nat\isactrlesub {\isachardot}\ {\isasymlambda}\isactrlbsub nat\isactrlesub {\isachardot}\ {\isadigit{1}}\ {\isacharplus}\ {\isadigit{0}}} would |
|
216 |
correspond to \isa{{\isasymlambda}x\isactrlbsub nat\isactrlesub {\isachardot}\ {\isasymlambda}y\isactrlbsub nat\isactrlesub {\isachardot}\ x\ {\isacharplus}\ y} in a named |
|
217 |
representation. Note that a bound variable may be represented by |
|
218 |
different de-Bruijn indices at different occurrences, depending on |
|
219 |
the nesting of abstractions. |
|
220 |
||
221 |
A \emph{loose variable} is a bound variable that is outside the |
|
222 |
scope of local binders. The types (and names) for loose variables |
|
223 |
can be managed as a separate context, that is maintained as a stack |
|
224 |
of hypothetical binders. The core logic operates on closed terms, |
|
225 |
without any loose variables. |
|
226 |
||
227 |
A \emph{fixed variable} is a pair of a basic name and a type, e.g.\ |
|
228 |
\isa{{\isacharparenleft}x{\isacharcomma}\ {\isasymtau}{\isacharparenright}} which is usually printed \isa{x\isactrlisub {\isasymtau}}. A |
|
229 |
\emph{schematic variable} is a pair of an indexname and a type, |
|
230 |
e.g.\ \isa{{\isacharparenleft}{\isacharparenleft}x{\isacharcomma}\ {\isadigit{0}}{\isacharparenright}{\isacharcomma}\ {\isasymtau}{\isacharparenright}} which is usually printed as \isa{{\isacharquery}x\isactrlisub {\isasymtau}}. |
|
231 |
||
232 |
\medskip A \emph{constant} is a pair of a basic name and a type, |
|
233 |
e.g.\ \isa{{\isacharparenleft}c{\isacharcomma}\ {\isasymtau}{\isacharparenright}} which is usually printed as \isa{c\isactrlisub {\isasymtau}}. Constants are declared in the context as polymorphic |
|
234 |
families \isa{c\ {\isacharcolon}{\isacharcolon}\ {\isasymsigma}}, meaning that all substitution instances |
|
235 |
\isa{c\isactrlisub {\isasymtau}} for \isa{{\isasymtau}\ {\isacharequal}\ {\isasymsigma}{\isasymvartheta}} are valid. |
|
236 |
||
237 |
The vector of \emph{type arguments} of constant \isa{c\isactrlisub {\isasymtau}} |
|
238 |
wrt.\ the declaration \isa{c\ {\isacharcolon}{\isacharcolon}\ {\isasymsigma}} is defined as the codomain of |
|
239 |
the matcher \isa{{\isasymvartheta}\ {\isacharequal}\ {\isacharbraceleft}{\isacharquery}{\isasymalpha}\isactrlisub {\isadigit{1}}\ {\isasymmapsto}\ {\isasymtau}\isactrlisub {\isadigit{1}}{\isacharcomma}\ {\isasymdots}{\isacharcomma}\ {\isacharquery}{\isasymalpha}\isactrlisub n\ {\isasymmapsto}\ {\isasymtau}\isactrlisub n{\isacharbraceright}} presented in canonical order \isa{{\isacharparenleft}{\isasymtau}\isactrlisub {\isadigit{1}}{\isacharcomma}\ {\isasymdots}{\isacharcomma}\ {\isasymtau}\isactrlisub n{\isacharparenright}}. Within a given theory context, |
|
240 |
there is a one-to-one correspondence between any constant \isa{c\isactrlisub {\isasymtau}} and the application \isa{c{\isacharparenleft}{\isasymtau}\isactrlisub {\isadigit{1}}{\isacharcomma}\ {\isasymdots}{\isacharcomma}\ {\isasymtau}\isactrlisub n{\isacharparenright}} of its type arguments. For example, with \isa{plus\ {\isacharcolon}{\isacharcolon}\ {\isasymalpha}\ {\isasymRightarrow}\ {\isasymalpha}\ {\isasymRightarrow}\ {\isasymalpha}}, the instance \isa{plus\isactrlbsub nat\ {\isasymRightarrow}\ nat\ {\isasymRightarrow}\ nat\isactrlesub } corresponds to \isa{plus{\isacharparenleft}nat{\isacharparenright}}. |
|
241 |
||
242 |
Constant declarations \isa{c\ {\isacharcolon}{\isacharcolon}\ {\isasymsigma}} may contain sort constraints |
|
243 |
for type variables in \isa{{\isasymsigma}}. These are observed by |
|
244 |
type-inference as expected, but \emph{ignored} by the core logic. |
|
245 |
This means the primitive logic is able to reason with instances of |
|
246 |
polymorphic constants that the user-level type-checker would reject |
|
247 |
due to violation of type class restrictions. |
|
248 |
||
249 |
\medskip An \emph{atomic} term is either a variable or constant. A |
|
250 |
\emph{term} is defined inductively over atomic terms, with |
|
251 |
abstraction and application as follows: \isa{t\ {\isacharequal}\ b\ {\isacharbar}\ x\isactrlisub {\isasymtau}\ {\isacharbar}\ {\isacharquery}x\isactrlisub {\isasymtau}\ {\isacharbar}\ c\isactrlisub {\isasymtau}\ {\isacharbar}\ {\isasymlambda}\isactrlisub {\isasymtau}{\isachardot}\ t\ {\isacharbar}\ t\isactrlisub {\isadigit{1}}\ t\isactrlisub {\isadigit{2}}}. |
|
252 |
Parsing and printing takes care of converting between an external |
|
253 |
representation with named bound variables. Subsequently, we shall |
|
254 |
use the latter notation instead of internal de-Bruijn |
|
255 |
representation. |
|
256 |
||
257 |
The inductive relation \isa{t\ {\isacharcolon}{\isacharcolon}\ {\isasymtau}} assigns a (unique) type to a |
|
258 |
term according to the structure of atomic terms, abstractions, and |
|
259 |
applicatins: |
|
260 |
\[ |
|
261 |
\infer{\isa{a\isactrlisub {\isasymtau}\ {\isacharcolon}{\isacharcolon}\ {\isasymtau}}}{} |
|
262 |
\qquad |
|
263 |
\infer{\isa{{\isacharparenleft}{\isasymlambda}x\isactrlsub {\isasymtau}{\isachardot}\ t{\isacharparenright}\ {\isacharcolon}{\isacharcolon}\ {\isasymtau}\ {\isasymRightarrow}\ {\isasymsigma}}}{\isa{t\ {\isacharcolon}{\isacharcolon}\ {\isasymsigma}}} |
|
264 |
\qquad |
|
265 |
\infer{\isa{t\ u\ {\isacharcolon}{\isacharcolon}\ {\isasymsigma}}}{\isa{t\ {\isacharcolon}{\isacharcolon}\ {\isasymtau}\ {\isasymRightarrow}\ {\isasymsigma}} & \isa{u\ {\isacharcolon}{\isacharcolon}\ {\isasymtau}}} |
|
266 |
\] |
|
267 |
A \emph{well-typed term} is a term that can be typed according to these rules. |
|
268 |
||
269 |
Typing information can be omitted: type-inference is able to |
|
270 |
reconstruct the most general type of a raw term, while assigning |
|
271 |
most general types to all of its variables and constants. |
|
272 |
Type-inference depends on a context of type constraints for fixed |
|
273 |
variables, and declarations for polymorphic constants. |
|
274 |
||
275 |
The identity of atomic terms consists both of the name and the type |
|
276 |
component. This means that different variables \isa{x\isactrlbsub {\isasymtau}\isactrlisub {\isadigit{1}}\isactrlesub } and \isa{x\isactrlbsub {\isasymtau}\isactrlisub {\isadigit{2}}\isactrlesub } may become the same after type |
|
277 |
instantiation. Some outer layers of the system make it hard to |
|
278 |
produce variables of the same name, but different types. In |
|
279 |
contrast, mixed instances of polymorphic constants occur frequently. |
|
280 |
||
281 |
\medskip The \emph{hidden polymorphism} of a term \isa{t\ {\isacharcolon}{\isacharcolon}\ {\isasymsigma}} |
|
282 |
is the set of type variables occurring in \isa{t}, but not in |
|
283 |
\isa{{\isasymsigma}}. This means that the term implicitly depends on type |
|
284 |
arguments that are not accounted in the result type, i.e.\ there are |
|
285 |
different type instances \isa{t{\isasymvartheta}\ {\isacharcolon}{\isacharcolon}\ {\isasymsigma}} and \isa{t{\isasymvartheta}{\isacharprime}\ {\isacharcolon}{\isacharcolon}\ {\isasymsigma}} with the same type. This slightly |
|
286 |
pathological situation notoriously demands additional care. |
|
287 |
||
288 |
\medskip A \emph{term abbreviation} is a syntactic definition \isa{c\isactrlisub {\isasymsigma}\ {\isasymequiv}\ t} of a closed term \isa{t} of type \isa{{\isasymsigma}}, |
|
289 |
without any hidden polymorphism. A term abbreviation looks like a |
|
290 |
constant in the syntax, but is expanded before entering the logical |
|
291 |
core. Abbreviations are usually reverted when printing terms, using |
|
292 |
\isa{t\ {\isasymrightarrow}\ c\isactrlisub {\isasymsigma}} as rules for higher-order rewriting. |
|
293 |
||
294 |
\medskip Canonical operations on \isa{{\isasymlambda}}-terms include \isa{{\isasymalpha}{\isasymbeta}{\isasymeta}}-conversion: \isa{{\isasymalpha}}-conversion refers to capture-free |
|
295 |
renaming of bound variables; \isa{{\isasymbeta}}-conversion contracts an |
|
296 |
abstraction applied to an argument term, substituting the argument |
|
297 |
in the body: \isa{{\isacharparenleft}{\isasymlambda}x{\isachardot}\ b{\isacharparenright}a} becomes \isa{b{\isacharbrackleft}a{\isacharslash}x{\isacharbrackright}}; \isa{{\isasymeta}}-conversion contracts vacuous application-abstraction: \isa{{\isasymlambda}x{\isachardot}\ f\ x} becomes \isa{f}, provided that the bound variable |
|
298 |
does not occur in \isa{f}. |
|
299 |
||
300 |
Terms are normally treated modulo \isa{{\isasymalpha}}-conversion, which is |
|
301 |
implicit in the de-Bruijn representation. Names for bound variables |
|
302 |
in abstractions are maintained separately as (meaningless) comments, |
|
303 |
mostly for parsing and printing. Full \isa{{\isasymalpha}{\isasymbeta}{\isasymeta}}-conversion is |
|
304 |
commonplace in various standard operations (\secref{sec:obj-rules}) |
|
305 |
that are based on higher-order unification and matching.% |
|
306 |
\end{isamarkuptext}% |
|
307 |
\isamarkuptrue% |
|
308 |
% |
|
309 |
\isadelimmlref |
|
310 |
% |
|
311 |
\endisadelimmlref |
|
312 |
% |
|
313 |
\isatagmlref |
|
314 |
% |
|
315 |
\begin{isamarkuptext}% |
|
316 |
\begin{mldecls} |
|
317 |
\indexdef{}{ML type}{term}\verb|type term| \\ |
|
318 |
\indexdef{}{ML}{op aconv}\verb|op aconv: term * term -> bool| \\ |
|
319 |
\indexdef{}{ML}{map\_types}\verb|map_types: (typ -> typ) -> term -> term| \\ |
|
320 |
\indexdef{}{ML}{fold\_types}\verb|fold_types: (typ -> 'a -> 'a) -> term -> 'a -> 'a| \\ |
|
321 |
\indexdef{}{ML}{map\_aterms}\verb|map_aterms: (term -> term) -> term -> term| \\ |
|
322 |
\indexdef{}{ML}{fold\_aterms}\verb|fold_aterms: (term -> 'a -> 'a) -> term -> 'a -> 'a| \\ |
|
323 |
\end{mldecls} |
|
324 |
\begin{mldecls} |
|
325 |
\indexdef{}{ML}{fastype\_of}\verb|fastype_of: term -> typ| \\ |
|
326 |
\indexdef{}{ML}{lambda}\verb|lambda: term -> term -> term| \\ |
|
327 |
\indexdef{}{ML}{betapply}\verb|betapply: term * term -> term| \\ |
|
328 |
\indexdef{}{ML}{Sign.declare\_const}\verb|Sign.declare_const: Properties.T -> (binding * typ) * mixfix ->|\isasep\isanewline% |
|
329 |
\verb| theory -> term * theory| \\ |
|
330 |
\indexdef{}{ML}{Sign.add\_abbrev}\verb|Sign.add_abbrev: string -> Properties.T -> binding * term ->|\isasep\isanewline% |
|
331 |
\verb| theory -> (term * term) * theory| \\ |
|
332 |
\indexdef{}{ML}{Sign.const\_typargs}\verb|Sign.const_typargs: theory -> string * typ -> typ list| \\ |
|
333 |
\indexdef{}{ML}{Sign.const\_instance}\verb|Sign.const_instance: theory -> string * typ list -> typ| \\ |
|
334 |
\end{mldecls} |
|
335 |
||
336 |
\begin{description} |
|
337 |
||
338 |
\item \verb|term| represents de-Bruijn terms, with comments in |
|
339 |
abstractions, and explicitly named free variables and constants; |
|
340 |
this is a datatype with constructors \verb|Bound|, \verb|Free|, \verb|Var|, \verb|Const|, \verb|Abs|, \verb|op $|. |
|
341 |
||
342 |
\item \isa{t}~\verb|aconv|~\isa{u} checks \isa{{\isasymalpha}}-equivalence of two terms. This is the basic equality relation |
|
343 |
on type \verb|term|; raw datatype equality should only be used |
|
344 |
for operations related to parsing or printing! |
|
345 |
||
346 |
\item \verb|map_types|~\isa{f\ t} applies the mapping \isa{f} to all types occurring in \isa{t}. |
|
347 |
||
348 |
\item \verb|fold_types|~\isa{f\ t} iterates the operation \isa{f} over all occurrences of types in \isa{t}; the term |
|
349 |
structure is traversed from left to right. |
|
350 |
||
351 |
\item \verb|map_aterms|~\isa{f\ t} applies the mapping \isa{f} |
|
352 |
to all atomic terms (\verb|Bound|, \verb|Free|, \verb|Var|, \verb|Const|) occurring in \isa{t}. |
|
353 |
||
354 |
\item \verb|fold_aterms|~\isa{f\ t} iterates the operation \isa{f} over all occurrences of atomic terms (\verb|Bound|, \verb|Free|, |
|
355 |
\verb|Var|, \verb|Const|) in \isa{t}; the term structure is |
|
356 |
traversed from left to right. |
|
357 |
||
358 |
\item \verb|fastype_of|~\isa{t} determines the type of a |
|
359 |
well-typed term. This operation is relatively slow, despite the |
|
360 |
omission of any sanity checks. |
|
361 |
||
362 |
\item \verb|lambda|~\isa{a\ b} produces an abstraction \isa{{\isasymlambda}a{\isachardot}\ b}, where occurrences of the atomic term \isa{a} in the |
|
363 |
body \isa{b} are replaced by bound variables. |
|
364 |
||
365 |
\item \verb|betapply|~\isa{{\isacharparenleft}t{\isacharcomma}\ u{\isacharparenright}} produces an application \isa{t\ u}, with topmost \isa{{\isasymbeta}}-conversion if \isa{t} is an |
|
366 |
abstraction. |
|
367 |
||
368 |
\item \verb|Sign.declare_const|~\isa{properties\ {\isacharparenleft}{\isacharparenleft}c{\isacharcomma}\ {\isasymsigma}{\isacharparenright}{\isacharcomma}\ mx{\isacharparenright}} |
|
369 |
declares a new constant \isa{c\ {\isacharcolon}{\isacharcolon}\ {\isasymsigma}} with optional mixfix |
|
370 |
syntax. |
|
371 |
||
372 |
\item \verb|Sign.add_abbrev|~\isa{print{\isacharunderscore}mode\ properties\ {\isacharparenleft}c{\isacharcomma}\ t{\isacharparenright}} |
|
373 |
introduces a new term abbreviation \isa{c\ {\isasymequiv}\ t}. |
|
374 |
||
375 |
\item \verb|Sign.const_typargs|~\isa{thy\ {\isacharparenleft}c{\isacharcomma}\ {\isasymtau}{\isacharparenright}} and \verb|Sign.const_instance|~\isa{thy\ {\isacharparenleft}c{\isacharcomma}\ {\isacharbrackleft}{\isasymtau}\isactrlisub {\isadigit{1}}{\isacharcomma}\ {\isasymdots}{\isacharcomma}\ {\isasymtau}\isactrlisub n{\isacharbrackright}{\isacharparenright}} |
|
376 |
convert between two representations of polymorphic constants: full |
|
377 |
type instance vs.\ compact type arguments form. |
|
378 |
||
379 |
\end{description}% |
|
380 |
\end{isamarkuptext}% |
|
381 |
\isamarkuptrue% |
|
382 |
% |
|
383 |
\endisatagmlref |
|
384 |
{\isafoldmlref}% |
|
385 |
% |
|
386 |
\isadelimmlref |
|
387 |
% |
|
388 |
\endisadelimmlref |
|
389 |
% |
|
390 |
\isamarkupsection{Theorems \label{sec:thms}% |
|
391 |
} |
|
392 |
\isamarkuptrue% |
|
393 |
% |
|
394 |
\begin{isamarkuptext}% |
|
395 |
A \emph{proposition} is a well-typed term of type \isa{prop}, a |
|
396 |
\emph{theorem} is a proven proposition (depending on a context of |
|
397 |
hypotheses and the background theory). Primitive inferences include |
|
398 |
plain Natural Deduction rules for the primary connectives \isa{{\isasymAnd}} and \isa{{\isasymLongrightarrow}} of the framework. There is also a builtin |
|
399 |
notion of equality/equivalence \isa{{\isasymequiv}}.% |
|
400 |
\end{isamarkuptext}% |
|
401 |
\isamarkuptrue% |
|
402 |
% |
|
403 |
\isamarkupsubsection{Primitive connectives and rules \label{sec:prim-rules}% |
|
404 |
} |
|
405 |
\isamarkuptrue% |
|
406 |
% |
|
407 |
\begin{isamarkuptext}% |
|
408 |
The theory \isa{Pure} contains constant declarations for the |
|
409 |
primitive connectives \isa{{\isasymAnd}}, \isa{{\isasymLongrightarrow}}, and \isa{{\isasymequiv}} of |
|
410 |
the logical framework, see \figref{fig:pure-connectives}. The |
|
411 |
derivability judgment \isa{A\isactrlisub {\isadigit{1}}{\isacharcomma}\ {\isasymdots}{\isacharcomma}\ A\isactrlisub n\ {\isasymturnstile}\ B} is |
|
412 |
defined inductively by the primitive inferences given in |
|
413 |
\figref{fig:prim-rules}, with the global restriction that the |
|
414 |
hypotheses must \emph{not} contain any schematic variables. The |
|
415 |
builtin equality is conceptually axiomatized as shown in |
|
416 |
\figref{fig:pure-equality}, although the implementation works |
|
417 |
directly with derived inferences. |
|
418 |
||
419 |
\begin{figure}[htb] |
|
420 |
\begin{center} |
|
421 |
\begin{tabular}{ll} |
|
422 |
\isa{all\ {\isacharcolon}{\isacharcolon}\ {\isacharparenleft}{\isasymalpha}\ {\isasymRightarrow}\ prop{\isacharparenright}\ {\isasymRightarrow}\ prop} & universal quantification (binder \isa{{\isasymAnd}}) \\ |
|
423 |
\isa{{\isasymLongrightarrow}\ {\isacharcolon}{\isacharcolon}\ prop\ {\isasymRightarrow}\ prop\ {\isasymRightarrow}\ prop} & implication (right associative infix) \\ |
|
424 |
\isa{{\isasymequiv}\ {\isacharcolon}{\isacharcolon}\ {\isasymalpha}\ {\isasymRightarrow}\ {\isasymalpha}\ {\isasymRightarrow}\ prop} & equality relation (infix) \\ |
|
425 |
\end{tabular} |
|
426 |
\caption{Primitive connectives of Pure}\label{fig:pure-connectives} |
|
427 |
\end{center} |
|
428 |
\end{figure} |
|
429 |
||
430 |
\begin{figure}[htb] |
|
431 |
\begin{center} |
|
432 |
\[ |
|
433 |
\infer[\isa{{\isacharparenleft}axiom{\isacharparenright}}]{\isa{{\isasymturnstile}\ A}}{\isa{A\ {\isasymin}\ {\isasymTheta}}} |
|
434 |
\qquad |
|
435 |
\infer[\isa{{\isacharparenleft}assume{\isacharparenright}}]{\isa{A\ {\isasymturnstile}\ A}}{} |
|
436 |
\] |
|
437 |
\[ |
|
438 |
\infer[\isa{{\isacharparenleft}{\isasymAnd}{\isacharunderscore}intro{\isacharparenright}}]{\isa{{\isasymGamma}\ {\isasymturnstile}\ {\isasymAnd}x{\isachardot}\ b{\isacharbrackleft}x{\isacharbrackright}}}{\isa{{\isasymGamma}\ {\isasymturnstile}\ b{\isacharbrackleft}x{\isacharbrackright}} & \isa{x\ {\isasymnotin}\ {\isasymGamma}}} |
|
439 |
\qquad |
|
440 |
\infer[\isa{{\isacharparenleft}{\isasymAnd}{\isacharunderscore}elim{\isacharparenright}}]{\isa{{\isasymGamma}\ {\isasymturnstile}\ b{\isacharbrackleft}a{\isacharbrackright}}}{\isa{{\isasymGamma}\ {\isasymturnstile}\ {\isasymAnd}x{\isachardot}\ b{\isacharbrackleft}x{\isacharbrackright}}} |
|
441 |
\] |
|
442 |
\[ |
|
443 |
\infer[\isa{{\isacharparenleft}{\isasymLongrightarrow}{\isacharunderscore}intro{\isacharparenright}}]{\isa{{\isasymGamma}\ {\isacharminus}\ A\ {\isasymturnstile}\ A\ {\isasymLongrightarrow}\ B}}{\isa{{\isasymGamma}\ {\isasymturnstile}\ B}} |
|
444 |
\qquad |
|
445 |
\infer[\isa{{\isacharparenleft}{\isasymLongrightarrow}{\isacharunderscore}elim{\isacharparenright}}]{\isa{{\isasymGamma}\isactrlsub {\isadigit{1}}\ {\isasymunion}\ {\isasymGamma}\isactrlsub {\isadigit{2}}\ {\isasymturnstile}\ B}}{\isa{{\isasymGamma}\isactrlsub {\isadigit{1}}\ {\isasymturnstile}\ A\ {\isasymLongrightarrow}\ B} & \isa{{\isasymGamma}\isactrlsub {\isadigit{2}}\ {\isasymturnstile}\ A}} |
|
446 |
\] |
|
447 |
\caption{Primitive inferences of Pure}\label{fig:prim-rules} |
|
448 |
\end{center} |
|
449 |
\end{figure} |
|
450 |
||
451 |
\begin{figure}[htb] |
|
452 |
\begin{center} |
|
453 |
\begin{tabular}{ll} |
|
454 |
\isa{{\isasymturnstile}\ {\isacharparenleft}{\isasymlambda}x{\isachardot}\ b{\isacharbrackleft}x{\isacharbrackright}{\isacharparenright}\ a\ {\isasymequiv}\ b{\isacharbrackleft}a{\isacharbrackright}} & \isa{{\isasymbeta}}-conversion \\ |
|
455 |
\isa{{\isasymturnstile}\ x\ {\isasymequiv}\ x} & reflexivity \\ |
|
456 |
\isa{{\isasymturnstile}\ x\ {\isasymequiv}\ y\ {\isasymLongrightarrow}\ P\ x\ {\isasymLongrightarrow}\ P\ y} & substitution \\ |
|
457 |
\isa{{\isasymturnstile}\ {\isacharparenleft}{\isasymAnd}x{\isachardot}\ f\ x\ {\isasymequiv}\ g\ x{\isacharparenright}\ {\isasymLongrightarrow}\ f\ {\isasymequiv}\ g} & extensionality \\ |
|
458 |
\isa{{\isasymturnstile}\ {\isacharparenleft}A\ {\isasymLongrightarrow}\ B{\isacharparenright}\ {\isasymLongrightarrow}\ {\isacharparenleft}B\ {\isasymLongrightarrow}\ A{\isacharparenright}\ {\isasymLongrightarrow}\ A\ {\isasymequiv}\ B} & logical equivalence \\ |
|
459 |
\end{tabular} |
|
460 |
\caption{Conceptual axiomatization of Pure equality}\label{fig:pure-equality} |
|
461 |
\end{center} |
|
462 |
\end{figure} |
|
463 |
||
464 |
The introduction and elimination rules for \isa{{\isasymAnd}} and \isa{{\isasymLongrightarrow}} are analogous to formation of dependently typed \isa{{\isasymlambda}}-terms representing the underlying proof objects. Proof terms |
|
465 |
are irrelevant in the Pure logic, though; they cannot occur within |
|
466 |
propositions. The system provides a runtime option to record |
|
467 |
explicit proof terms for primitive inferences. Thus all three |
|
468 |
levels of \isa{{\isasymlambda}}-calculus become explicit: \isa{{\isasymRightarrow}} for |
|
469 |
terms, and \isa{{\isasymAnd}{\isacharslash}{\isasymLongrightarrow}} for proofs (cf.\ |
|
470 |
\cite{Berghofer-Nipkow:2000:TPHOL}). |
|
471 |
||
472 |
Observe that locally fixed parameters (as in \isa{{\isasymAnd}{\isacharunderscore}intro}) need |
|
473 |
not be recorded in the hypotheses, because the simple syntactic |
|
474 |
types of Pure are always inhabitable. ``Assumptions'' \isa{x\ {\isacharcolon}{\isacharcolon}\ {\isasymtau}} for type-membership are only present as long as some \isa{x\isactrlisub {\isasymtau}} occurs in the statement body.\footnote{This is the key |
|
475 |
difference to ``\isa{{\isasymlambda}HOL}'' in the PTS framework |
|
476 |
\cite{Barendregt-Geuvers:2001}, where hypotheses \isa{x\ {\isacharcolon}\ A} are |
|
477 |
treated uniformly for propositions and types.} |
|
478 |
||
479 |
\medskip The axiomatization of a theory is implicitly closed by |
|
480 |
forming all instances of type and term variables: \isa{{\isasymturnstile}\ A{\isasymvartheta}} holds for any substitution instance of an axiom |
|
481 |
\isa{{\isasymturnstile}\ A}. By pushing substitutions through derivations |
|
482 |
inductively, we also get admissible \isa{generalize} and \isa{instance} rules as shown in \figref{fig:subst-rules}. |
|
483 |
||
484 |
\begin{figure}[htb] |
|
485 |
\begin{center} |
|
486 |
\[ |
|
487 |
\infer{\isa{{\isasymGamma}\ {\isasymturnstile}\ B{\isacharbrackleft}{\isacharquery}{\isasymalpha}{\isacharbrackright}}}{\isa{{\isasymGamma}\ {\isasymturnstile}\ B{\isacharbrackleft}{\isasymalpha}{\isacharbrackright}} & \isa{{\isasymalpha}\ {\isasymnotin}\ {\isasymGamma}}} |
|
488 |
\quad |
|
489 |
\infer[\quad\isa{{\isacharparenleft}generalize{\isacharparenright}}]{\isa{{\isasymGamma}\ {\isasymturnstile}\ B{\isacharbrackleft}{\isacharquery}x{\isacharbrackright}}}{\isa{{\isasymGamma}\ {\isasymturnstile}\ B{\isacharbrackleft}x{\isacharbrackright}} & \isa{x\ {\isasymnotin}\ {\isasymGamma}}} |
|
490 |
\] |
|
491 |
\[ |
|
492 |
\infer{\isa{{\isasymGamma}\ {\isasymturnstile}\ B{\isacharbrackleft}{\isasymtau}{\isacharbrackright}}}{\isa{{\isasymGamma}\ {\isasymturnstile}\ B{\isacharbrackleft}{\isacharquery}{\isasymalpha}{\isacharbrackright}}} |
|
493 |
\quad |
|
494 |
\infer[\quad\isa{{\isacharparenleft}instantiate{\isacharparenright}}]{\isa{{\isasymGamma}\ {\isasymturnstile}\ B{\isacharbrackleft}t{\isacharbrackright}}}{\isa{{\isasymGamma}\ {\isasymturnstile}\ B{\isacharbrackleft}{\isacharquery}x{\isacharbrackright}}} |
|
495 |
\] |
|
496 |
\caption{Admissible substitution rules}\label{fig:subst-rules} |
|
497 |
\end{center} |
|
498 |
\end{figure} |
|
499 |
||
500 |
Note that \isa{instantiate} does not require an explicit |
|
501 |
side-condition, because \isa{{\isasymGamma}} may never contain schematic |
|
502 |
variables. |
|
503 |
||
504 |
In principle, variables could be substituted in hypotheses as well, |
|
505 |
but this would disrupt the monotonicity of reasoning: deriving |
|
506 |
\isa{{\isasymGamma}{\isasymvartheta}\ {\isasymturnstile}\ B{\isasymvartheta}} from \isa{{\isasymGamma}\ {\isasymturnstile}\ B} is |
|
507 |
correct, but \isa{{\isasymGamma}{\isasymvartheta}\ {\isasymsupseteq}\ {\isasymGamma}} does not necessarily hold: |
|
508 |
the result belongs to a different proof context. |
|
509 |
||
510 |
\medskip An \emph{oracle} is a function that produces axioms on the |
|
511 |
fly. Logically, this is an instance of the \isa{axiom} rule |
|
512 |
(\figref{fig:prim-rules}), but there is an operational difference. |
|
513 |
The system always records oracle invocations within derivations of |
|
514 |
theorems by a unique tag. |
|
515 |
||
516 |
Axiomatizations should be limited to the bare minimum, typically as |
|
517 |
part of the initial logical basis of an object-logic formalization. |
|
518 |
Later on, theories are usually developed in a strictly definitional |
|
519 |
fashion, by stating only certain equalities over new constants. |
|
520 |
||
521 |
A \emph{simple definition} consists of a constant declaration \isa{c\ {\isacharcolon}{\isacharcolon}\ {\isasymsigma}} together with an axiom \isa{{\isasymturnstile}\ c\ {\isasymequiv}\ t}, where \isa{t\ {\isacharcolon}{\isacharcolon}\ {\isasymsigma}} is a closed term without any hidden polymorphism. The RHS |
|
522 |
may depend on further defined constants, but not \isa{c} itself. |
|
523 |
Definitions of functions may be presented as \isa{c\ \isactrlvec x\ {\isasymequiv}\ t} instead of the puristic \isa{c\ {\isasymequiv}\ {\isasymlambda}\isactrlvec x{\isachardot}\ t}. |
|
524 |
||
525 |
An \emph{overloaded definition} consists of a collection of axioms |
|
526 |
for the same constant, with zero or one equations \isa{c{\isacharparenleft}{\isacharparenleft}\isactrlvec {\isasymalpha}{\isacharparenright}{\isasymkappa}{\isacharparenright}\ {\isasymequiv}\ t} for each type constructor \isa{{\isasymkappa}} (for |
|
527 |
distinct variables \isa{\isactrlvec {\isasymalpha}}). The RHS may mention |
|
528 |
previously defined constants as above, or arbitrary constants \isa{d{\isacharparenleft}{\isasymalpha}\isactrlisub i{\isacharparenright}} for some \isa{{\isasymalpha}\isactrlisub i} projected from \isa{\isactrlvec {\isasymalpha}}. Thus overloaded definitions essentially work by |
|
529 |
primitive recursion over the syntactic structure of a single type |
|
530 |
argument.% |
|
531 |
\end{isamarkuptext}% |
|
532 |
\isamarkuptrue% |
|
533 |
% |
|
534 |
\isadelimmlref |
|
535 |
% |
|
536 |
\endisadelimmlref |
|
537 |
% |
|
538 |
\isatagmlref |
|
539 |
% |
|
540 |
\begin{isamarkuptext}% |
|
541 |
\begin{mldecls} |
|
542 |
\indexdef{}{ML type}{ctyp}\verb|type ctyp| \\ |
|
543 |
\indexdef{}{ML type}{cterm}\verb|type cterm| \\ |
|
544 |
\indexdef{}{ML}{Thm.ctyp\_of}\verb|Thm.ctyp_of: theory -> typ -> ctyp| \\ |
|
545 |
\indexdef{}{ML}{Thm.cterm\_of}\verb|Thm.cterm_of: theory -> term -> cterm| \\ |
|
546 |
\end{mldecls} |
|
547 |
\begin{mldecls} |
|
548 |
\indexdef{}{ML type}{thm}\verb|type thm| \\ |
|
549 |
\indexdef{}{ML}{proofs}\verb|proofs: int ref| \\ |
|
550 |
\indexdef{}{ML}{Thm.assume}\verb|Thm.assume: cterm -> thm| \\ |
|
551 |
\indexdef{}{ML}{Thm.forall\_intr}\verb|Thm.forall_intr: cterm -> thm -> thm| \\ |
|
552 |
\indexdef{}{ML}{Thm.forall\_elim}\verb|Thm.forall_elim: cterm -> thm -> thm| \\ |
|
553 |
\indexdef{}{ML}{Thm.implies\_intr}\verb|Thm.implies_intr: cterm -> thm -> thm| \\ |
|
554 |
\indexdef{}{ML}{Thm.implies\_elim}\verb|Thm.implies_elim: thm -> thm -> thm| \\ |
|
555 |
\indexdef{}{ML}{Thm.generalize}\verb|Thm.generalize: string list * string list -> int -> thm -> thm| \\ |
|
556 |
\indexdef{}{ML}{Thm.instantiate}\verb|Thm.instantiate: (ctyp * ctyp) list * (cterm * cterm) list -> thm -> thm| \\ |
|
557 |
\indexdef{}{ML}{Thm.axiom}\verb|Thm.axiom: theory -> string -> thm| \\ |
|
558 |
\indexdef{}{ML}{Thm.add\_oracle}\verb|Thm.add_oracle: binding * ('a -> cterm) -> theory|\isasep\isanewline% |
|
559 |
\verb| -> (string * ('a -> thm)) * theory| \\ |
|
560 |
\end{mldecls} |
|
561 |
\begin{mldecls} |
|
562 |
\indexdef{}{ML}{Theory.add\_axioms\_i}\verb|Theory.add_axioms_i: (binding * term) list -> theory -> theory| \\ |
|
563 |
\indexdef{}{ML}{Theory.add\_deps}\verb|Theory.add_deps: string -> string * typ -> (string * typ) list -> theory -> theory| \\ |
|
564 |
\indexdef{}{ML}{Theory.add\_defs\_i}\verb|Theory.add_defs_i: bool -> bool -> (binding * term) list -> theory -> theory| \\ |
|
565 |
\end{mldecls} |
|
566 |
||
567 |
\begin{description} |
|
568 |
||
569 |
\item \verb|ctyp| and \verb|cterm| represent certified types |
|
570 |
and terms, respectively. These are abstract datatypes that |
|
571 |
guarantee that its values have passed the full well-formedness (and |
|
572 |
well-typedness) checks, relative to the declarations of type |
|
573 |
constructors, constants etc. in the theory. |
|
574 |
||
575 |
\item \verb|Thm.ctyp_of|~\isa{thy\ {\isasymtau}} and \verb|Thm.cterm_of|~\isa{thy\ t} explicitly checks types and terms, |
|
576 |
respectively. This also involves some basic normalizations, such |
|
577 |
expansion of type and term abbreviations from the theory context. |
|
578 |
||
579 |
Re-certification is relatively slow and should be avoided in tight |
|
580 |
reasoning loops. There are separate operations to decompose |
|
581 |
certified entities (including actual theorems). |
|
582 |
||
583 |
\item \verb|thm| represents proven propositions. This is an |
|
584 |
abstract datatype that guarantees that its values have been |
|
585 |
constructed by basic principles of the \verb|Thm| module. |
|
586 |
Every \verb|thm| value contains a sliding back-reference to the |
|
587 |
enclosing theory, cf.\ \secref{sec:context-theory}. |
|
588 |
||
589 |
\item \verb|proofs| determines the detail of proof recording within |
|
590 |
\verb|thm| values: \verb|0| records only the names of oracles, |
|
591 |
\verb|1| records oracle names and propositions, \verb|2| additionally |
|
592 |
records full proof terms. Officially named theorems that contribute |
|
593 |
to a result are always recorded. |
|
594 |
||
595 |
\item \verb|Thm.assume|, \verb|Thm.forall_intr|, \verb|Thm.forall_elim|, \verb|Thm.implies_intr|, and \verb|Thm.implies_elim| |
|
596 |
correspond to the primitive inferences of \figref{fig:prim-rules}. |
|
597 |
||
598 |
\item \verb|Thm.generalize|~\isa{{\isacharparenleft}\isactrlvec {\isasymalpha}{\isacharcomma}\ \isactrlvec x{\isacharparenright}} |
|
599 |
corresponds to the \isa{generalize} rules of |
|
600 |
\figref{fig:subst-rules}. Here collections of type and term |
|
601 |
variables are generalized simultaneously, specified by the given |
|
602 |
basic names. |
|
603 |
||
604 |
\item \verb|Thm.instantiate|~\isa{{\isacharparenleft}\isactrlvec {\isasymalpha}\isactrlisub s{\isacharcomma}\ \isactrlvec x\isactrlisub {\isasymtau}{\isacharparenright}} corresponds to the \isa{instantiate} rules |
|
605 |
of \figref{fig:subst-rules}. Type variables are substituted before |
|
606 |
term variables. Note that the types in \isa{\isactrlvec x\isactrlisub {\isasymtau}} |
|
607 |
refer to the instantiated versions. |
|
608 |
||
609 |
\item \verb|Thm.axiom|~\isa{thy\ name} retrieves a named |
|
610 |
axiom, cf.\ \isa{axiom} in \figref{fig:prim-rules}. |
|
611 |
||
612 |
\item \verb|Thm.add_oracle|~\isa{{\isacharparenleft}binding{\isacharcomma}\ oracle{\isacharparenright}} produces a named |
|
613 |
oracle rule, essentially generating arbitrary axioms on the fly, |
|
614 |
cf.\ \isa{axiom} in \figref{fig:prim-rules}. |
|
615 |
||
616 |
\item \verb|Theory.add_axioms_i|~\isa{{\isacharbrackleft}{\isacharparenleft}name{\isacharcomma}\ A{\isacharparenright}{\isacharcomma}\ {\isasymdots}{\isacharbrackright}} declares |
|
617 |
arbitrary propositions as axioms. |
|
618 |
||
619 |
\item \verb|Theory.add_deps|~\isa{name\ c\isactrlisub {\isasymtau}\ \isactrlvec d\isactrlisub {\isasymsigma}} declares dependencies of a named specification |
|
620 |
for constant \isa{c\isactrlisub {\isasymtau}}, relative to existing |
|
621 |
specifications for constants \isa{\isactrlvec d\isactrlisub {\isasymsigma}}. |
|
622 |
||
623 |
\item \verb|Theory.add_defs_i|~\isa{unchecked\ overloaded\ {\isacharbrackleft}{\isacharparenleft}name{\isacharcomma}\ c\ \isactrlvec x\ {\isasymequiv}\ t{\isacharparenright}{\isacharcomma}\ {\isasymdots}{\isacharbrackright}} states a definitional axiom for an existing |
|
624 |
constant \isa{c}. Dependencies are recorded (cf.\ \verb|Theory.add_deps|), unless the \isa{unchecked} option is set. |
|
625 |
||
626 |
\end{description}% |
|
627 |
\end{isamarkuptext}% |
|
628 |
\isamarkuptrue% |
|
629 |
% |
|
630 |
\endisatagmlref |
|
631 |
{\isafoldmlref}% |
|
632 |
% |
|
633 |
\isadelimmlref |
|
634 |
% |
|
635 |
\endisadelimmlref |
|
636 |
% |
|
637 |
\isamarkupsubsection{Auxiliary definitions% |
|
638 |
} |
|
639 |
\isamarkuptrue% |
|
640 |
% |
|
641 |
\begin{isamarkuptext}% |
|
642 |
Theory \isa{Pure} provides a few auxiliary definitions, see |
|
643 |
\figref{fig:pure-aux}. These special constants are normally not |
|
644 |
exposed to the user, but appear in internal encodings. |
|
645 |
||
646 |
\begin{figure}[htb] |
|
647 |
\begin{center} |
|
648 |
\begin{tabular}{ll} |
|
649 |
\isa{conjunction\ {\isacharcolon}{\isacharcolon}\ prop\ {\isasymRightarrow}\ prop\ {\isasymRightarrow}\ prop} & (infix \isa{{\isacharampersand}}) \\ |
|
650 |
\isa{{\isasymturnstile}\ A\ {\isacharampersand}\ B\ {\isasymequiv}\ {\isacharparenleft}{\isasymAnd}C{\isachardot}\ {\isacharparenleft}A\ {\isasymLongrightarrow}\ B\ {\isasymLongrightarrow}\ C{\isacharparenright}\ {\isasymLongrightarrow}\ C{\isacharparenright}} \\[1ex] |
|
651 |
\isa{prop\ {\isacharcolon}{\isacharcolon}\ prop\ {\isasymRightarrow}\ prop} & (prefix \isa{{\isacharhash}}, suppressed) \\ |
|
652 |
\isa{{\isacharhash}A\ {\isasymequiv}\ A} \\[1ex] |
|
653 |
\isa{term\ {\isacharcolon}{\isacharcolon}\ {\isasymalpha}\ {\isasymRightarrow}\ prop} & (prefix \isa{TERM}) \\ |
|
654 |
\isa{term\ x\ {\isasymequiv}\ {\isacharparenleft}{\isasymAnd}A{\isachardot}\ A\ {\isasymLongrightarrow}\ A{\isacharparenright}} \\[1ex] |
|
655 |
\isa{TYPE\ {\isacharcolon}{\isacharcolon}\ {\isasymalpha}\ itself} & (prefix \isa{TYPE}) \\ |
|
656 |
\isa{{\isacharparenleft}unspecified{\isacharparenright}} \\ |
|
657 |
\end{tabular} |
|
658 |
\caption{Definitions of auxiliary connectives}\label{fig:pure-aux} |
|
659 |
\end{center} |
|
660 |
\end{figure} |
|
661 |
||
662 |
Derived conjunction rules include introduction \isa{A\ {\isasymLongrightarrow}\ B\ {\isasymLongrightarrow}\ A\ {\isacharampersand}\ B}, and destructions \isa{A\ {\isacharampersand}\ B\ {\isasymLongrightarrow}\ A} and \isa{A\ {\isacharampersand}\ B\ {\isasymLongrightarrow}\ B}. |
|
663 |
Conjunction allows to treat simultaneous assumptions and conclusions |
|
664 |
uniformly. For example, multiple claims are intermediately |
|
665 |
represented as explicit conjunction, but this is refined into |
|
666 |
separate sub-goals before the user continues the proof; the final |
|
667 |
result is projected into a list of theorems (cf.\ |
|
668 |
\secref{sec:tactical-goals}). |
|
669 |
||
670 |
The \isa{prop} marker (\isa{{\isacharhash}}) makes arbitrarily complex |
|
671 |
propositions appear as atomic, without changing the meaning: \isa{{\isasymGamma}\ {\isasymturnstile}\ A} and \isa{{\isasymGamma}\ {\isasymturnstile}\ {\isacharhash}A} are interchangeable. See |
|
672 |
\secref{sec:tactical-goals} for specific operations. |
|
673 |
||
674 |
The \isa{term} marker turns any well-typed term into a derivable |
|
675 |
proposition: \isa{{\isasymturnstile}\ TERM\ t} holds unconditionally. Although |
|
676 |
this is logically vacuous, it allows to treat terms and proofs |
|
677 |
uniformly, similar to a type-theoretic framework. |
|
678 |
||
679 |
The \isa{TYPE} constructor is the canonical representative of |
|
680 |
the unspecified type \isa{{\isasymalpha}\ itself}; it essentially injects the |
|
681 |
language of types into that of terms. There is specific notation |
|
682 |
\isa{TYPE{\isacharparenleft}{\isasymtau}{\isacharparenright}} for \isa{TYPE\isactrlbsub {\isasymtau}\ itself\isactrlesub }. |
|
683 |
Although being devoid of any particular meaning, the \isa{TYPE{\isacharparenleft}{\isasymtau}{\isacharparenright}} accounts for the type \isa{{\isasymtau}} within the term |
|
684 |
language. In particular, \isa{TYPE{\isacharparenleft}{\isasymalpha}{\isacharparenright}} may be used as formal |
|
685 |
argument in primitive definitions, in order to circumvent hidden |
|
686 |
polymorphism (cf.\ \secref{sec:terms}). For example, \isa{c\ TYPE{\isacharparenleft}{\isasymalpha}{\isacharparenright}\ {\isasymequiv}\ A{\isacharbrackleft}{\isasymalpha}{\isacharbrackright}} defines \isa{c\ {\isacharcolon}{\isacharcolon}\ {\isasymalpha}\ itself\ {\isasymRightarrow}\ prop} in terms of |
|
687 |
a proposition \isa{A} that depends on an additional type |
|
688 |
argument, which is essentially a predicate on types.% |
|
689 |
\end{isamarkuptext}% |
|
690 |
\isamarkuptrue% |
|
691 |
% |
|
692 |
\isadelimmlref |
|
693 |
% |
|
694 |
\endisadelimmlref |
|
695 |
% |
|
696 |
\isatagmlref |
|
697 |
% |
|
698 |
\begin{isamarkuptext}% |
|
699 |
\begin{mldecls} |
|
700 |
\indexdef{}{ML}{Conjunction.intr}\verb|Conjunction.intr: thm -> thm -> thm| \\ |
|
701 |
\indexdef{}{ML}{Conjunction.elim}\verb|Conjunction.elim: thm -> thm * thm| \\ |
|
702 |
\indexdef{}{ML}{Drule.mk\_term}\verb|Drule.mk_term: cterm -> thm| \\ |
|
703 |
\indexdef{}{ML}{Drule.dest\_term}\verb|Drule.dest_term: thm -> cterm| \\ |
|
704 |
\indexdef{}{ML}{Logic.mk\_type}\verb|Logic.mk_type: typ -> term| \\ |
|
705 |
\indexdef{}{ML}{Logic.dest\_type}\verb|Logic.dest_type: term -> typ| \\ |
|
706 |
\end{mldecls} |
|
707 |
||
708 |
\begin{description} |
|
709 |
||
710 |
\item \verb|Conjunction.intr| derives \isa{A\ {\isacharampersand}\ B} from \isa{A} and \isa{B}. |
|
711 |
||
712 |
\item \verb|Conjunction.elim| derives \isa{A} and \isa{B} |
|
713 |
from \isa{A\ {\isacharampersand}\ B}. |
|
714 |
||
715 |
\item \verb|Drule.mk_term| derives \isa{TERM\ t}. |
|
716 |
||
717 |
\item \verb|Drule.dest_term| recovers term \isa{t} from \isa{TERM\ t}. |
|
718 |
||
719 |
\item \verb|Logic.mk_type|~\isa{{\isasymtau}} produces the term \isa{TYPE{\isacharparenleft}{\isasymtau}{\isacharparenright}}. |
|
720 |
||
721 |
\item \verb|Logic.dest_type|~\isa{TYPE{\isacharparenleft}{\isasymtau}{\isacharparenright}} recovers the type |
|
722 |
\isa{{\isasymtau}}. |
|
723 |
||
724 |
\end{description}% |
|
725 |
\end{isamarkuptext}% |
|
726 |
\isamarkuptrue% |
|
727 |
% |
|
728 |
\endisatagmlref |
|
729 |
{\isafoldmlref}% |
|
730 |
% |
|
731 |
\isadelimmlref |
|
732 |
% |
|
733 |
\endisadelimmlref |
|
734 |
% |
|
735 |
\isamarkupsection{Object-level rules \label{sec:obj-rules}% |
|
736 |
} |
|
737 |
\isamarkuptrue% |
|
738 |
% |
|
739 |
\begin{isamarkuptext}% |
|
740 |
The primitive inferences covered so far mostly serve foundational |
|
741 |
purposes. User-level reasoning usually works via object-level rules |
|
742 |
that are represented as theorems of Pure. Composition of rules |
|
743 |
involves \emph{backchaining}, \emph{higher-order unification} modulo |
|
744 |
\isa{{\isasymalpha}{\isasymbeta}{\isasymeta}}-conversion of \isa{{\isasymlambda}}-terms, and so-called |
|
745 |
\emph{lifting} of rules into a context of \isa{{\isasymAnd}} and \isa{{\isasymLongrightarrow}} connectives. Thus the full power of higher-order Natural |
|
746 |
Deduction in Isabelle/Pure becomes readily available.% |
|
747 |
\end{isamarkuptext}% |
|
748 |
\isamarkuptrue% |
|
749 |
% |
|
750 |
\isamarkupsubsection{Hereditary Harrop Formulae% |
|
751 |
} |
|
752 |
\isamarkuptrue% |
|
753 |
% |
|
754 |
\begin{isamarkuptext}% |
|
755 |
The idea of object-level rules is to model Natural Deduction |
|
756 |
inferences in the style of Gentzen \cite{Gentzen:1935}, but we allow |
|
757 |
arbitrary nesting similar to \cite{extensions91}. The most basic |
|
758 |
rule format is that of a \emph{Horn Clause}: |
|
759 |
\[ |
|
760 |
\infer{\isa{A}}{\isa{A\isactrlsub {\isadigit{1}}} & \isa{{\isasymdots}} & \isa{A\isactrlsub n}} |
|
761 |
\] |
|
762 |
where \isa{A{\isacharcomma}\ A\isactrlsub {\isadigit{1}}{\isacharcomma}\ {\isasymdots}{\isacharcomma}\ A\isactrlsub n} are atomic propositions |
|
763 |
of the framework, usually of the form \isa{Trueprop\ B}, where |
|
764 |
\isa{B} is a (compound) object-level statement. This |
|
765 |
object-level inference corresponds to an iterated implication in |
|
766 |
Pure like this: |
|
767 |
\[ |
|
768 |
\isa{A\isactrlsub {\isadigit{1}}\ {\isasymLongrightarrow}\ {\isasymdots}\ A\isactrlsub n\ {\isasymLongrightarrow}\ A} |
|
769 |
\] |
|
770 |
As an example consider conjunction introduction: \isa{A\ {\isasymLongrightarrow}\ B\ {\isasymLongrightarrow}\ A\ {\isasymand}\ B}. Any parameters occurring in such rule statements are |
|
771 |
conceptionally treated as arbitrary: |
|
772 |
\[ |
|
773 |
\isa{{\isasymAnd}x\isactrlsub {\isadigit{1}}\ {\isasymdots}\ x\isactrlsub m{\isachardot}\ A\isactrlsub {\isadigit{1}}\ x\isactrlsub {\isadigit{1}}\ {\isasymdots}\ x\isactrlsub m\ {\isasymLongrightarrow}\ {\isasymdots}\ A\isactrlsub n\ x\isactrlsub {\isadigit{1}}\ {\isasymdots}\ x\isactrlsub m\ {\isasymLongrightarrow}\ A\ x\isactrlsub {\isadigit{1}}\ {\isasymdots}\ x\isactrlsub m} |
|
774 |
\] |
|
775 |
||
776 |
Nesting of rules means that the positions of \isa{A\isactrlsub i} may |
|
777 |
again hold compound rules, not just atomic propositions. |
|
778 |
Propositions of this format are called \emph{Hereditary Harrop |
|
779 |
Formulae} in the literature \cite{Miller:1991}. Here we give an |
|
780 |
inductive characterization as follows: |
|
781 |
||
782 |
\medskip |
|
783 |
\begin{tabular}{ll} |
|
784 |
\isa{\isactrlbold x} & set of variables \\ |
|
785 |
\isa{\isactrlbold A} & set of atomic propositions \\ |
|
786 |
\isa{\isactrlbold H\ \ {\isacharequal}\ \ {\isasymAnd}\isactrlbold x\isactrlsup {\isacharasterisk}{\isachardot}\ \isactrlbold H\isactrlsup {\isacharasterisk}\ {\isasymLongrightarrow}\ \isactrlbold A} & set of Hereditary Harrop Formulas \\ |
|
787 |
\end{tabular} |
|
788 |
\medskip |
|
789 |
||
790 |
\noindent Thus we essentially impose nesting levels on propositions |
|
791 |
formed from \isa{{\isasymAnd}} and \isa{{\isasymLongrightarrow}}. At each level there is a |
|
792 |
prefix of parameters and compound premises, concluding an atomic |
|
793 |
proposition. Typical examples are \isa{{\isasymlongrightarrow}}-introduction \isa{{\isacharparenleft}A\ {\isasymLongrightarrow}\ B{\isacharparenright}\ {\isasymLongrightarrow}\ A\ {\isasymlongrightarrow}\ B} or mathematical induction \isa{P\ {\isadigit{0}}\ {\isasymLongrightarrow}\ {\isacharparenleft}{\isasymAnd}n{\isachardot}\ P\ n\ {\isasymLongrightarrow}\ P\ {\isacharparenleft}Suc\ n{\isacharparenright}{\isacharparenright}\ {\isasymLongrightarrow}\ P\ n}. Even deeper nesting occurs in well-founded |
|
794 |
induction \isa{{\isacharparenleft}{\isasymAnd}x{\isachardot}\ {\isacharparenleft}{\isasymAnd}y{\isachardot}\ y\ {\isasymprec}\ x\ {\isasymLongrightarrow}\ P\ y{\isacharparenright}\ {\isasymLongrightarrow}\ P\ x{\isacharparenright}\ {\isasymLongrightarrow}\ P\ x}, but this |
|
795 |
already marks the limit of rule complexity seen in practice. |
|
796 |
||
797 |
\medskip Regular user-level inferences in Isabelle/Pure always |
|
798 |
maintain the following canonical form of results: |
|
799 |
||
800 |
\begin{itemize} |
|
801 |
||
802 |
\item Normalization by \isa{{\isacharparenleft}A\ {\isasymLongrightarrow}\ {\isacharparenleft}{\isasymAnd}x{\isachardot}\ B\ x{\isacharparenright}{\isacharparenright}\ {\isasymequiv}\ {\isacharparenleft}{\isasymAnd}x{\isachardot}\ A\ {\isasymLongrightarrow}\ B\ x{\isacharparenright}}, |
|
803 |
which is a theorem of Pure, means that quantifiers are pushed in |
|
804 |
front of implication at each level of nesting. The normal form is a |
|
805 |
Hereditary Harrop Formula. |
|
806 |
||
807 |
\item The outermost prefix of parameters is represented via |
|
808 |
schematic variables: instead of \isa{{\isasymAnd}\isactrlvec x{\isachardot}\ \isactrlvec H\ \isactrlvec x\ {\isasymLongrightarrow}\ A\ \isactrlvec x} we have \isa{\isactrlvec H\ {\isacharquery}\isactrlvec x\ {\isasymLongrightarrow}\ A\ {\isacharquery}\isactrlvec x}. |
|
809 |
Note that this representation looses information about the order of |
|
810 |
parameters, and vacuous quantifiers vanish automatically. |
|
811 |
||
812 |
\end{itemize}% |
|
813 |
\end{isamarkuptext}% |
|
814 |
\isamarkuptrue% |
|
815 |
% |
|
816 |
\isadelimmlref |
|
817 |
% |
|
818 |
\endisadelimmlref |
|
819 |
% |
|
820 |
\isatagmlref |
|
821 |
% |
|
822 |
\begin{isamarkuptext}% |
|
823 |
\begin{mldecls} |
|
30552
58db56278478
provide Simplifier.norm_hhf(_protect) as regular simplifier operation;
wenzelm
parents:
30355
diff
changeset
|
824 |
\indexdef{}{ML}{Simplifier.norm\_hhf}\verb|Simplifier.norm_hhf: thm -> thm| \\ |
30296 | 825 |
\end{mldecls} |
826 |
||
827 |
\begin{description} |
|
828 |
||
30552
58db56278478
provide Simplifier.norm_hhf(_protect) as regular simplifier operation;
wenzelm
parents:
30355
diff
changeset
|
829 |
\item \verb|Simplifier.norm_hhf|~\isa{thm} normalizes the given |
30296 | 830 |
theorem according to the canonical form specified above. This is |
831 |
occasionally helpful to repair some low-level tools that do not |
|
832 |
handle Hereditary Harrop Formulae properly. |
|
833 |
||
834 |
\end{description}% |
|
835 |
\end{isamarkuptext}% |
|
836 |
\isamarkuptrue% |
|
837 |
% |
|
838 |
\endisatagmlref |
|
839 |
{\isafoldmlref}% |
|
840 |
% |
|
841 |
\isadelimmlref |
|
842 |
% |
|
843 |
\endisadelimmlref |
|
844 |
% |
|
845 |
\isamarkupsubsection{Rule composition% |
|
846 |
} |
|
847 |
\isamarkuptrue% |
|
848 |
% |
|
849 |
\begin{isamarkuptext}% |
|
850 |
The rule calculus of Isabelle/Pure provides two main inferences: |
|
851 |
\hyperlink{inference.resolution}{\mbox{\isa{resolution}}} (i.e.\ back-chaining of rules) and |
|
852 |
\hyperlink{inference.assumption}{\mbox{\isa{assumption}}} (i.e.\ closing a branch), both modulo |
|
853 |
higher-order unification. There are also combined variants, notably |
|
854 |
\hyperlink{inference.elim-resolution}{\mbox{\isa{elim{\isacharunderscore}resolution}}} and \hyperlink{inference.dest-resolution}{\mbox{\isa{dest{\isacharunderscore}resolution}}}. |
|
855 |
||
856 |
To understand the all-important \hyperlink{inference.resolution}{\mbox{\isa{resolution}}} principle, |
|
857 |
we first consider raw \indexdef{}{inference}{composition}\hypertarget{inference.composition}{\hyperlink{inference.composition}{\mbox{\isa{composition}}}} (modulo |
|
858 |
higher-order unification with substitution \isa{{\isasymvartheta}}): |
|
859 |
\[ |
|
860 |
\infer[(\indexdef{}{inference}{composition}\hypertarget{inference.composition}{\hyperlink{inference.composition}{\mbox{\isa{composition}}}})]{\isa{\isactrlvec A{\isasymvartheta}\ {\isasymLongrightarrow}\ C{\isasymvartheta}}} |
|
861 |
{\isa{\isactrlvec A\ {\isasymLongrightarrow}\ B} & \isa{B{\isacharprime}\ {\isasymLongrightarrow}\ C} & \isa{B{\isasymvartheta}\ {\isacharequal}\ B{\isacharprime}{\isasymvartheta}}} |
|
862 |
\] |
|
863 |
Here the conclusion of the first rule is unified with the premise of |
|
864 |
the second; the resulting rule instance inherits the premises of the |
|
865 |
first and conclusion of the second. Note that \isa{C} can again |
|
866 |
consist of iterated implications. We can also permute the premises |
|
867 |
of the second rule back-and-forth in order to compose with \isa{B{\isacharprime}} in any position (subsequently we shall always refer to |
|
868 |
position 1 w.l.o.g.). |
|
869 |
||
870 |
In \hyperlink{inference.composition}{\mbox{\isa{composition}}} the internal structure of the common |
|
871 |
part \isa{B} and \isa{B{\isacharprime}} is not taken into account. For |
|
872 |
proper \hyperlink{inference.resolution}{\mbox{\isa{resolution}}} we require \isa{B} to be atomic, |
|
873 |
and explicitly observe the structure \isa{{\isasymAnd}\isactrlvec x{\isachardot}\ \isactrlvec H\ \isactrlvec x\ {\isasymLongrightarrow}\ B{\isacharprime}\ \isactrlvec x} of the premise of the second rule. The |
|
874 |
idea is to adapt the first rule by ``lifting'' it into this context, |
|
875 |
by means of iterated application of the following inferences: |
|
876 |
\[ |
|
877 |
\infer[(\indexdef{}{inference}{imp\_lift}\hypertarget{inference.imp-lift}{\hyperlink{inference.imp-lift}{\mbox{\isa{imp{\isacharunderscore}lift}}}})]{\isa{{\isacharparenleft}\isactrlvec H\ {\isasymLongrightarrow}\ \isactrlvec A{\isacharparenright}\ {\isasymLongrightarrow}\ {\isacharparenleft}\isactrlvec H\ {\isasymLongrightarrow}\ B{\isacharparenright}}}{\isa{\isactrlvec A\ {\isasymLongrightarrow}\ B}} |
|
878 |
\] |
|
879 |
\[ |
|
880 |
\infer[(\indexdef{}{inference}{all\_lift}\hypertarget{inference.all-lift}{\hyperlink{inference.all-lift}{\mbox{\isa{all{\isacharunderscore}lift}}}})]{\isa{{\isacharparenleft}{\isasymAnd}\isactrlvec x{\isachardot}\ \isactrlvec A\ {\isacharparenleft}{\isacharquery}\isactrlvec a\ \isactrlvec x{\isacharparenright}{\isacharparenright}\ {\isasymLongrightarrow}\ {\isacharparenleft}{\isasymAnd}\isactrlvec x{\isachardot}\ B\ {\isacharparenleft}{\isacharquery}\isactrlvec a\ \isactrlvec x{\isacharparenright}{\isacharparenright}}}{\isa{\isactrlvec A\ {\isacharquery}\isactrlvec a\ {\isasymLongrightarrow}\ B\ {\isacharquery}\isactrlvec a}} |
|
881 |
\] |
|
882 |
By combining raw composition with lifting, we get full \hyperlink{inference.resolution}{\mbox{\isa{resolution}}} as follows: |
|
883 |
\[ |
|
884 |
\infer[(\indexdef{}{inference}{resolution}\hypertarget{inference.resolution}{\hyperlink{inference.resolution}{\mbox{\isa{resolution}}}})] |
|
885 |
{\isa{{\isacharparenleft}{\isasymAnd}\isactrlvec x{\isachardot}\ \isactrlvec H\ \isactrlvec x\ {\isasymLongrightarrow}\ \isactrlvec A\ {\isacharparenleft}{\isacharquery}\isactrlvec a\ \isactrlvec x{\isacharparenright}{\isacharparenright}{\isasymvartheta}\ {\isasymLongrightarrow}\ C{\isasymvartheta}}} |
|
886 |
{\begin{tabular}{l} |
|
887 |
\isa{\isactrlvec A\ {\isacharquery}\isactrlvec a\ {\isasymLongrightarrow}\ B\ {\isacharquery}\isactrlvec a} \\ |
|
888 |
\isa{{\isacharparenleft}{\isasymAnd}\isactrlvec x{\isachardot}\ \isactrlvec H\ \isactrlvec x\ {\isasymLongrightarrow}\ B{\isacharprime}\ \isactrlvec x{\isacharparenright}\ {\isasymLongrightarrow}\ C} \\ |
|
889 |
\isa{{\isacharparenleft}{\isasymlambda}\isactrlvec x{\isachardot}\ B\ {\isacharparenleft}{\isacharquery}\isactrlvec a\ \isactrlvec x{\isacharparenright}{\isacharparenright}{\isasymvartheta}\ {\isacharequal}\ B{\isacharprime}{\isasymvartheta}} \\ |
|
890 |
\end{tabular}} |
|
891 |
\] |
|
892 |
||
893 |
Continued resolution of rules allows to back-chain a problem towards |
|
894 |
more and sub-problems. Branches are closed either by resolving with |
|
895 |
a rule of 0 premises, or by producing a ``short-circuit'' within a |
|
896 |
solved situation (again modulo unification): |
|
897 |
\[ |
|
898 |
\infer[(\indexdef{}{inference}{assumption}\hypertarget{inference.assumption}{\hyperlink{inference.assumption}{\mbox{\isa{assumption}}}})]{\isa{C{\isasymvartheta}}} |
|
899 |
{\isa{{\isacharparenleft}{\isasymAnd}\isactrlvec x{\isachardot}\ \isactrlvec H\ \isactrlvec x\ {\isasymLongrightarrow}\ A\ \isactrlvec x{\isacharparenright}\ {\isasymLongrightarrow}\ C} & \isa{A{\isasymvartheta}\ {\isacharequal}\ H\isactrlsub i{\isasymvartheta}}~~\text{(for some~\isa{i})}} |
|
900 |
\] |
|
901 |
||
902 |
FIXME \indexdef{}{inference}{elim\_resolution}\hypertarget{inference.elim-resolution}{\hyperlink{inference.elim-resolution}{\mbox{\isa{elim{\isacharunderscore}resolution}}}}, \indexdef{}{inference}{dest\_resolution}\hypertarget{inference.dest-resolution}{\hyperlink{inference.dest-resolution}{\mbox{\isa{dest{\isacharunderscore}resolution}}}}% |
|
903 |
\end{isamarkuptext}% |
|
904 |
\isamarkuptrue% |
|
905 |
% |
|
906 |
\isadelimmlref |
|
907 |
% |
|
908 |
\endisadelimmlref |
|
909 |
% |
|
910 |
\isatagmlref |
|
911 |
% |
|
912 |
\begin{isamarkuptext}% |
|
913 |
\begin{mldecls} |
|
914 |
\indexdef{}{ML}{op RS}\verb|op RS: thm * thm -> thm| \\ |
|
915 |
\indexdef{}{ML}{op OF}\verb|op OF: thm * thm list -> thm| \\ |
|
916 |
\end{mldecls} |
|
917 |
||
918 |
\begin{description} |
|
919 |
||
920 |
\item \isa{rule\isactrlsub {\isadigit{1}}\ RS\ rule\isactrlsub {\isadigit{2}}} resolves \isa{rule\isactrlsub {\isadigit{1}}} with \isa{rule\isactrlsub {\isadigit{2}}} according to the |
|
921 |
\hyperlink{inference.resolution}{\mbox{\isa{resolution}}} principle explained above. Note that the |
|
922 |
corresponding attribute in the Isar language is called \hyperlink{attribute.THEN}{\mbox{\isa{THEN}}}. |
|
923 |
||
924 |
\item \isa{rule\ OF\ rules} resolves a list of rules with the |
|
925 |
first rule, addressing its premises \isa{{\isadigit{1}}{\isacharcomma}\ {\isasymdots}{\isacharcomma}\ length\ rules} |
|
926 |
(operating from last to first). This means the newly emerging |
|
927 |
premises are all concatenated, without interfering. Also note that |
|
928 |
compared to \isa{RS}, the rule argument order is swapped: \isa{rule\isactrlsub {\isadigit{1}}\ RS\ rule\isactrlsub {\isadigit{2}}\ {\isacharequal}\ rule\isactrlsub {\isadigit{2}}\ OF\ {\isacharbrackleft}rule\isactrlsub {\isadigit{1}}{\isacharbrackright}}. |
|
929 |
||
930 |
\end{description}% |
|
931 |
\end{isamarkuptext}% |
|
932 |
\isamarkuptrue% |
|
933 |
% |
|
934 |
\endisatagmlref |
|
935 |
{\isafoldmlref}% |
|
936 |
% |
|
937 |
\isadelimmlref |
|
938 |
% |
|
939 |
\endisadelimmlref |
|
940 |
% |
|
941 |
\isadelimtheory |
|
942 |
% |
|
943 |
\endisadelimtheory |
|
944 |
% |
|
945 |
\isatagtheory |
|
946 |
\isacommand{end}\isamarkupfalse% |
|
947 |
% |
|
948 |
\endisatagtheory |
|
949 |
{\isafoldtheory}% |
|
950 |
% |
|
951 |
\isadelimtheory |
|
952 |
% |
|
953 |
\endisadelimtheory |
|
954 |
\isanewline |
|
955 |
\end{isabellebody}% |
|
956 |
%%% Local Variables: |
|
957 |
%%% mode: latex |
|
958 |
%%% TeX-master: "root" |
|
959 |
%%% End: |