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