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