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