author | wenzelm |
Sat, 17 Aug 2019 17:57:10 +0200 | |
changeset 70568 | 6e055d313f73 |
parent 70449 | 6e34025981be |
child 70569 | 095dadc62bb5 |
permissions | -rw-r--r-- |
61656 | 1 |
(*:maxLineLen=78:*) |
2 |
||
29755 | 3 |
theory Logic |
4 |
imports Base |
|
5 |
begin |
|
18537 | 6 |
|
58618 | 7 |
chapter \<open>Primitive logic \label{ch:logic}\<close> |
18537 | 8 |
|
58618 | 9 |
text \<open> |
61854 | 10 |
The logical foundations of Isabelle/Isar are that of the Pure logic, which |
11 |
has been introduced as a Natural Deduction framework in @{cite paulson700}. |
|
12 |
This is essentially the same logic as ``\<open>\<lambda>HOL\<close>'' in the more abstract |
|
13 |
setting of Pure Type Systems (PTS) @{cite "Barendregt-Geuvers:2001"}, |
|
14 |
although there are some key differences in the specific treatment of simple |
|
15 |
types in Isabelle/Pure. |
|
20480 | 16 |
|
61854 | 17 |
Following type-theoretic parlance, the Pure logic consists of three levels |
18 |
of \<open>\<lambda>\<close>-calculus with corresponding arrows, \<open>\<Rightarrow>\<close> for syntactic function space |
|
19 |
(terms depending on terms), \<open>\<And>\<close> for universal quantification (proofs |
|
20 |
depending on terms), and \<open>\<Longrightarrow>\<close> for implication (proofs depending on proofs). |
|
20480 | 21 |
|
20537 | 22 |
Derivations are relative to a logical theory, which declares type |
61854 | 23 |
constructors, constants, and axioms. Theory declarations support schematic |
24 |
polymorphism, which is strictly speaking outside the logic.\<^footnote>\<open>This is the |
|
25 |
deeper logical reason, why the theory context \<open>\<Theta>\<close> is separate from the proof |
|
26 |
context \<open>\<Gamma>\<close> of the core calculus: type constructors, term constants, and |
|
27 |
facts (proof constants) may involve arbitrary type schemes, but the type of |
|
28 |
a locally fixed term parameter is also fixed!\<close> |
|
58618 | 29 |
\<close> |
20480 | 30 |
|
31 |
||
58618 | 32 |
section \<open>Types \label{sec:types}\<close> |
20437 | 33 |
|
58618 | 34 |
text \<open> |
61854 | 35 |
The language of types is an uninterpreted order-sorted first-order algebra; |
36 |
types are qualified by ordered type classes. |
|
20480 | 37 |
|
61416 | 38 |
\<^medskip> |
61854 | 39 |
A \<^emph>\<open>type class\<close> is an abstract syntactic entity declared in the theory |
40 |
context. The \<^emph>\<open>subclass relation\<close> \<open>c\<^sub>1 \<subseteq> c\<^sub>2\<close> is specified by stating an |
|
41 |
acyclic generating relation; the transitive closure is maintained |
|
42 |
internally. The resulting relation is an ordering: reflexive, transitive, |
|
43 |
and antisymmetric. |
|
20451 | 44 |
|
61854 | 45 |
A \<^emph>\<open>sort\<close> is a list of type classes written as \<open>s = {c\<^sub>1, \<dots>, c\<^sub>m}\<close>, it |
46 |
represents symbolic intersection. Notationally, the curly braces are omitted |
|
47 |
for singleton intersections, i.e.\ any class \<open>c\<close> may be read as a sort |
|
48 |
\<open>{c}\<close>. The ordering on type classes is extended to sorts according to the |
|
49 |
meaning of intersections: \<open>{c\<^sub>1, \<dots> c\<^sub>m} \<subseteq> {d\<^sub>1, \<dots>, d\<^sub>n}\<close> iff \<open>\<forall>j. \<exists>i. c\<^sub>i \<subseteq> |
|
50 |
d\<^sub>j\<close>. The empty intersection \<open>{}\<close> refers to the universal sort, which is the |
|
51 |
largest element wrt.\ the sort order. Thus \<open>{}\<close> represents the ``full |
|
52 |
sort'', not the empty one! The intersection of all (finitely many) classes |
|
53 |
declared in the current theory is the least element wrt.\ the sort ordering. |
|
20480 | 54 |
|
61416 | 55 |
\<^medskip> |
61854 | 56 |
A \<^emph>\<open>fixed type variable\<close> is a pair of a basic name (starting with a \<open>'\<close> |
57 |
character) and a sort constraint, e.g.\ \<open>('a, s)\<close> which is usually printed |
|
58 |
as \<open>\<alpha>\<^sub>s\<close>. A \<^emph>\<open>schematic type variable\<close> is a pair of an indexname and a sort |
|
59 |
constraint, e.g.\ \<open>(('a, 0), s)\<close> which is usually printed as \<open>?\<alpha>\<^sub>s\<close>. |
|
20451 | 60 |
|
61854 | 61 |
Note that \<^emph>\<open>all\<close> syntactic components contribute to the identity of type |
62 |
variables: basic name, index, and sort constraint. The core logic handles |
|
63 |
type variables with the same name but different sorts as different, although |
|
64 |
the type-inference layer (which is outside the core) rejects anything like |
|
65 |
that. |
|
20451 | 66 |
|
61854 | 67 |
A \<^emph>\<open>type constructor\<close> \<open>\<kappa>\<close> is a \<open>k\<close>-ary operator on types declared in the |
68 |
theory. Type constructor application is written postfix as \<open>(\<alpha>\<^sub>1, \<dots>, \<alpha>\<^sub>k)\<kappa>\<close>. |
|
69 |
For \<open>k = 0\<close> the argument tuple is omitted, e.g.\ \<open>prop\<close> instead of \<open>()prop\<close>. |
|
70 |
For \<open>k = 1\<close> the parentheses are omitted, e.g.\ \<open>\<alpha> list\<close> instead of |
|
71 |
\<open>(\<alpha>)list\<close>. Further notation is provided for specific constructors, notably |
|
72 |
the right-associative infix \<open>\<alpha> \<Rightarrow> \<beta>\<close> instead of \<open>(\<alpha>, \<beta>)fun\<close>. |
|
65446 | 73 |
|
61854 | 74 |
The logical category \<^emph>\<open>type\<close> is defined inductively over type variables and |
75 |
type constructors as follows: \<open>\<tau> = \<alpha>\<^sub>s | ?\<alpha>\<^sub>s | (\<tau>\<^sub>1, \<dots>, \<tau>\<^sub>k)\<kappa>\<close>. |
|
20451 | 76 |
|
61854 | 77 |
A \<^emph>\<open>type abbreviation\<close> is a syntactic definition \<open>(\<^vec>\<alpha>)\<kappa> = \<tau>\<close> of an |
78 |
arbitrary type expression \<open>\<tau>\<close> over variables \<open>\<^vec>\<alpha>\<close>. Type abbreviations |
|
79 |
appear as type constructors in the syntax, but are expanded before entering |
|
80 |
the logical core. |
|
20480 | 81 |
|
61854 | 82 |
A \<^emph>\<open>type arity\<close> declares the image behavior of a type constructor wrt.\ the |
83 |
algebra of sorts: \<open>\<kappa> :: (s\<^sub>1, \<dots>, s\<^sub>k)s\<close> means that \<open>(\<tau>\<^sub>1, \<dots>, \<tau>\<^sub>k)\<kappa>\<close> is of |
|
84 |
sort \<open>s\<close> if every argument type \<open>\<tau>\<^sub>i\<close> is of sort \<open>s\<^sub>i\<close>. Arity declarations |
|
85 |
are implicitly completed, i.e.\ \<open>\<kappa> :: (\<^vec>s)c\<close> entails \<open>\<kappa> :: |
|
61493 | 86 |
(\<^vec>s)c'\<close> for any \<open>c' \<supseteq> c\<close>. |
20491 | 87 |
|
61416 | 88 |
\<^medskip> |
61854 | 89 |
The sort algebra is always maintained as \<^emph>\<open>coregular\<close>, which means that type |
90 |
arities are consistent with the subclass relation: for any type constructor |
|
91 |
\<open>\<kappa>\<close>, and classes \<open>c\<^sub>1 \<subseteq> c\<^sub>2\<close>, and arities \<open>\<kappa> :: (\<^vec>s\<^sub>1)c\<^sub>1\<close> and \<open>\<kappa> :: |
|
92 |
(\<^vec>s\<^sub>2)c\<^sub>2\<close> holds \<open>\<^vec>s\<^sub>1 \<subseteq> \<^vec>s\<^sub>2\<close> component-wise. |
|
20451 | 93 |
|
20491 | 94 |
The key property of a coregular order-sorted algebra is that sort |
20537 | 95 |
constraints can be solved in a most general fashion: for each type |
61854 | 96 |
constructor \<open>\<kappa>\<close> and sort \<open>s\<close> there is a most general vector of argument |
97 |
sorts \<open>(s\<^sub>1, \<dots>, s\<^sub>k)\<close> such that a type scheme \<open>(\<alpha>\<^bsub>s\<^sub>1\<^esub>, \<dots>, \<alpha>\<^bsub>s\<^sub>k\<^esub>)\<kappa>\<close> is of |
|
98 |
sort \<open>s\<close>. Consequently, type unification has most general solutions (modulo |
|
99 |
equivalence of sorts), so type-inference produces primary types as expected |
|
100 |
@{cite "nipkow-prehofer"}. |
|
58618 | 101 |
\<close> |
20451 | 102 |
|
58618 | 103 |
text %mlref \<open> |
20480 | 104 |
\begin{mldecls} |
34921 | 105 |
@{index_ML_type class: string} \\ |
106 |
@{index_ML_type sort: "class list"} \\ |
|
107 |
@{index_ML_type arity: "string * sort list * sort"} \\ |
|
20480 | 108 |
@{index_ML_type typ} \\ |
39846 | 109 |
@{index_ML Term.map_atyps: "(typ -> typ) -> typ -> typ"} \\ |
110 |
@{index_ML Term.fold_atyps: "(typ -> 'a -> 'a) -> typ -> 'a -> 'a"} \\ |
|
20547 | 111 |
\end{mldecls} |
112 |
\begin{mldecls} |
|
20480 | 113 |
@{index_ML Sign.subsort: "theory -> sort * sort -> bool"} \\ |
114 |
@{index_ML Sign.of_sort: "theory -> typ * sort -> bool"} \\ |
|
47174 | 115 |
@{index_ML Sign.add_type: "Proof.context -> binding * int * mixfix -> theory -> theory"} \\ |
42401
9bfaf6819291
updated some theory primitives, which now depend on auxiliary context;
wenzelm
parents:
40255
diff
changeset
|
116 |
@{index_ML Sign.add_type_abbrev: "Proof.context -> |
9bfaf6819291
updated some theory primitives, which now depend on auxiliary context;
wenzelm
parents:
40255
diff
changeset
|
117 |
binding * string list * typ -> theory -> theory"} \\ |
30355 | 118 |
@{index_ML Sign.primitive_class: "binding * class list -> theory -> theory"} \\ |
20480 | 119 |
@{index_ML Sign.primitive_classrel: "class * class -> theory -> theory"} \\ |
120 |
@{index_ML Sign.primitive_arity: "arity -> theory -> theory"} \\ |
|
121 |
\end{mldecls} |
|
122 |
||
69597 | 123 |
\<^descr> Type \<^ML_type>\<open>class\<close> represents type classes. |
20480 | 124 |
|
69597 | 125 |
\<^descr> Type \<^ML_type>\<open>sort\<close> represents sorts, i.e.\ finite intersections of |
126 |
classes. The empty list \<^ML>\<open>[]: sort\<close> refers to the empty class |
|
61854 | 127 |
intersection, i.e.\ the ``full sort''. |
20451 | 128 |
|
69597 | 129 |
\<^descr> Type \<^ML_type>\<open>arity\<close> represents type arities. A triple \<open>(\<kappa>, \<^vec>s, s) |
61854 | 130 |
: arity\<close> represents \<open>\<kappa> :: (\<^vec>s)s\<close> as described above. |
20480 | 131 |
|
69597 | 132 |
\<^descr> Type \<^ML_type>\<open>typ\<close> represents types; this is a datatype with constructors |
133 |
\<^ML>\<open>TFree\<close>, \<^ML>\<open>TVar\<close>, \<^ML>\<open>Type\<close>. |
|
20480 | 134 |
|
69597 | 135 |
\<^descr> \<^ML>\<open>Term.map_atyps\<close>~\<open>f \<tau>\<close> applies the mapping \<open>f\<close> to all atomic types |
136 |
(\<^ML>\<open>TFree\<close>, \<^ML>\<open>TVar\<close>) occurring in \<open>\<tau>\<close>. |
|
20519 | 137 |
|
69597 | 138 |
\<^descr> \<^ML>\<open>Term.fold_atyps\<close>~\<open>f \<tau>\<close> iterates the operation \<open>f\<close> over all |
139 |
occurrences of atomic types (\<^ML>\<open>TFree\<close>, \<^ML>\<open>TVar\<close>) in \<open>\<tau>\<close>; the type |
|
61854 | 140 |
structure is traversed from left to right. |
20494 | 141 |
|
69597 | 142 |
\<^descr> \<^ML>\<open>Sign.subsort\<close>~\<open>thy (s\<^sub>1, s\<^sub>2)\<close> tests the subsort relation \<open>s\<^sub>1 \<subseteq> |
61854 | 143 |
s\<^sub>2\<close>. |
20480 | 144 |
|
69597 | 145 |
\<^descr> \<^ML>\<open>Sign.of_sort\<close>~\<open>thy (\<tau>, s)\<close> tests whether type \<open>\<tau>\<close> is of sort \<open>s\<close>. |
20480 | 146 |
|
69597 | 147 |
\<^descr> \<^ML>\<open>Sign.add_type\<close>~\<open>ctxt (\<kappa>, k, mx)\<close> declares a new type constructors \<open>\<kappa>\<close> |
61854 | 148 |
with \<open>k\<close> arguments and optional mixfix syntax. |
20451 | 149 |
|
69597 | 150 |
\<^descr> \<^ML>\<open>Sign.add_type_abbrev\<close>~\<open>ctxt (\<kappa>, \<^vec>\<alpha>, \<tau>)\<close> defines a new type |
61854 | 151 |
abbreviation \<open>(\<^vec>\<alpha>)\<kappa> = \<tau>\<close>. |
20480 | 152 |
|
69597 | 153 |
\<^descr> \<^ML>\<open>Sign.primitive_class\<close>~\<open>(c, [c\<^sub>1, \<dots>, c\<^sub>n])\<close> declares a new class \<open>c\<close>, |
61854 | 154 |
together with class relations \<open>c \<subseteq> c\<^sub>i\<close>, for \<open>i = 1, \<dots>, n\<close>. |
20480 | 155 |
|
69597 | 156 |
\<^descr> \<^ML>\<open>Sign.primitive_classrel\<close>~\<open>(c\<^sub>1, c\<^sub>2)\<close> declares the class relation |
61854 | 157 |
\<open>c\<^sub>1 \<subseteq> c\<^sub>2\<close>. |
20480 | 158 |
|
69597 | 159 |
\<^descr> \<^ML>\<open>Sign.primitive_arity\<close>~\<open>(\<kappa>, \<^vec>s, s)\<close> declares the arity \<open>\<kappa> :: |
61854 | 160 |
(\<^vec>s)s\<close>. |
58618 | 161 |
\<close> |
20437 | 162 |
|
58618 | 163 |
text %mlantiq \<open> |
39832 | 164 |
\begin{matharray}{rcl} |
61493 | 165 |
@{ML_antiquotation_def "class"} & : & \<open>ML_antiquotation\<close> \\ |
166 |
@{ML_antiquotation_def "sort"} & : & \<open>ML_antiquotation\<close> \\ |
|
167 |
@{ML_antiquotation_def "type_name"} & : & \<open>ML_antiquotation\<close> \\ |
|
168 |
@{ML_antiquotation_def "type_abbrev"} & : & \<open>ML_antiquotation\<close> \\ |
|
169 |
@{ML_antiquotation_def "nonterminal"} & : & \<open>ML_antiquotation\<close> \\ |
|
170 |
@{ML_antiquotation_def "typ"} & : & \<open>ML_antiquotation\<close> \\ |
|
39832 | 171 |
\end{matharray} |
172 |
||
69597 | 173 |
\<^rail>\<open> |
67146 | 174 |
@@{ML_antiquotation class} embedded |
39832 | 175 |
; |
42510
b9c106763325
use @{rail} antiquotation (with some nested markup);
wenzelm
parents:
42401
diff
changeset
|
176 |
@@{ML_antiquotation sort} sort |
39832 | 177 |
; |
42510
b9c106763325
use @{rail} antiquotation (with some nested markup);
wenzelm
parents:
42401
diff
changeset
|
178 |
(@@{ML_antiquotation type_name} | |
b9c106763325
use @{rail} antiquotation (with some nested markup);
wenzelm
parents:
42401
diff
changeset
|
179 |
@@{ML_antiquotation type_abbrev} | |
67146 | 180 |
@@{ML_antiquotation nonterminal}) embedded |
39832 | 181 |
; |
42510
b9c106763325
use @{rail} antiquotation (with some nested markup);
wenzelm
parents:
42401
diff
changeset
|
182 |
@@{ML_antiquotation typ} type |
69597 | 183 |
\<close> |
39832 | 184 |
|
69597 | 185 |
\<^descr> \<open>@{class c}\<close> inlines the internalized class \<open>c\<close> --- as \<^ML_type>\<open>string\<close> |
39832 | 186 |
literal. |
187 |
||
69597 | 188 |
\<^descr> \<open>@{sort s}\<close> inlines the internalized sort \<open>s\<close> --- as \<^ML_type>\<open>string |
189 |
list\<close> literal. |
|
61854 | 190 |
|
191 |
\<^descr> \<open>@{type_name c}\<close> inlines the internalized type constructor \<open>c\<close> --- as |
|
69597 | 192 |
\<^ML_type>\<open>string\<close> literal. |
61854 | 193 |
|
194 |
\<^descr> \<open>@{type_abbrev c}\<close> inlines the internalized type abbreviation \<open>c\<close> --- as |
|
69597 | 195 |
\<^ML_type>\<open>string\<close> literal. |
61854 | 196 |
|
197 |
\<^descr> \<open>@{nonterminal c}\<close> inlines the internalized syntactic type~/ grammar |
|
69597 | 198 |
nonterminal \<open>c\<close> --- as \<^ML_type>\<open>string\<close> literal. |
61854 | 199 |
|
200 |
\<^descr> \<open>@{typ \<tau>}\<close> inlines the internalized type \<open>\<tau>\<close> --- as constructor term for |
|
69597 | 201 |
datatype \<^ML_type>\<open>typ\<close>. |
58618 | 202 |
\<close> |
39832 | 203 |
|
20437 | 204 |
|
58618 | 205 |
section \<open>Terms \label{sec:terms}\<close> |
18537 | 206 |
|
58618 | 207 |
text \<open> |
61854 | 208 |
The language of terms is that of simply-typed \<open>\<lambda>\<close>-calculus with de-Bruijn |
209 |
indices for bound variables (cf.\ @{cite debruijn72} or @{cite |
|
210 |
"paulson-ml2"}), with the types being determined by the corresponding |
|
211 |
binders. In contrast, free variables and constants have an explicit name and |
|
212 |
type in each occurrence. |
|
20514 | 213 |
|
61416 | 214 |
\<^medskip> |
61854 | 215 |
A \<^emph>\<open>bound variable\<close> is a natural number \<open>b\<close>, which accounts for the number |
216 |
of intermediate binders between the variable occurrence in the body and its |
|
217 |
binding position. For example, the de-Bruijn term \<open>\<lambda>\<^bsub>bool\<^esub>. \<lambda>\<^bsub>bool\<^esub>. 1 \<and> 0\<close> |
|
218 |
would correspond to \<open>\<lambda>x\<^bsub>bool\<^esub>. \<lambda>y\<^bsub>bool\<^esub>. x \<and> y\<close> in a named representation. |
|
219 |
Note that a bound variable may be represented by different de-Bruijn indices |
|
220 |
at different occurrences, depending on the nesting of abstractions. |
|
20537 | 221 |
|
61854 | 222 |
A \<^emph>\<open>loose variable\<close> is a bound variable that is outside the scope of local |
223 |
binders. The types (and names) for loose variables can be managed as a |
|
224 |
separate context, that is maintained as a stack of hypothetical binders. The |
|
225 |
core logic operates on closed terms, without any loose variables. |
|
20514 | 226 |
|
61854 | 227 |
A \<^emph>\<open>fixed variable\<close> is a pair of a basic name and a type, e.g.\ \<open>(x, \<tau>)\<close> |
228 |
which is usually printed \<open>x\<^sub>\<tau>\<close> here. A \<^emph>\<open>schematic variable\<close> is a pair of an |
|
229 |
indexname and a type, e.g.\ \<open>((x, 0), \<tau>)\<close> which is likewise printed as |
|
230 |
\<open>?x\<^sub>\<tau>\<close>. |
|
20491 | 231 |
|
61416 | 232 |
\<^medskip> |
61854 | 233 |
A \<^emph>\<open>constant\<close> is a pair of a basic name and a type, e.g.\ \<open>(c, \<tau>)\<close> which is |
234 |
usually printed as \<open>c\<^sub>\<tau>\<close> here. Constants are declared in the context as |
|
235 |
polymorphic families \<open>c :: \<sigma>\<close>, meaning that all substitution instances \<open>c\<^sub>\<tau>\<close> |
|
236 |
for \<open>\<tau> = \<sigma>\<vartheta>\<close> are valid. |
|
20514 | 237 |
|
61854 | 238 |
The vector of \<^emph>\<open>type arguments\<close> of constant \<open>c\<^sub>\<tau>\<close> wrt.\ the declaration \<open>c |
239 |
:: \<sigma>\<close> is defined as the codomain of the matcher \<open>\<vartheta> = {?\<alpha>\<^sub>1 \<mapsto> \<tau>\<^sub>1, |
|
240 |
\<dots>, ?\<alpha>\<^sub>n \<mapsto> \<tau>\<^sub>n}\<close> presented in canonical order \<open>(\<tau>\<^sub>1, \<dots>, \<tau>\<^sub>n)\<close>, corresponding |
|
241 |
to the left-to-right occurrences of the \<open>\<alpha>\<^sub>i\<close> in \<open>\<sigma>\<close>. Within a given theory |
|
242 |
context, there is a one-to-one correspondence between any constant \<open>c\<^sub>\<tau>\<close> and |
|
243 |
the application \<open>c(\<tau>\<^sub>1, \<dots>, \<tau>\<^sub>n)\<close> of its type arguments. For example, with |
|
244 |
\<open>plus :: \<alpha> \<Rightarrow> \<alpha> \<Rightarrow> \<alpha>\<close>, the instance \<open>plus\<^bsub>nat \<Rightarrow> nat \<Rightarrow> nat\<^esub>\<close> corresponds to |
|
61493 | 245 |
\<open>plus(nat)\<close>. |
20480 | 246 |
|
61854 | 247 |
Constant declarations \<open>c :: \<sigma>\<close> may contain sort constraints for type |
248 |
variables in \<open>\<sigma>\<close>. These are observed by type-inference as expected, but |
|
249 |
\<^emph>\<open>ignored\<close> by the core logic. This means the primitive logic is able to |
|
250 |
reason with instances of polymorphic constants that the user-level |
|
251 |
type-checker would reject due to violation of type class restrictions. |
|
20480 | 252 |
|
61416 | 253 |
\<^medskip> |
61854 | 254 |
An \<^emph>\<open>atomic term\<close> is either a variable or constant. The logical category |
255 |
\<^emph>\<open>term\<close> is defined inductively over atomic terms, with abstraction and |
|
256 |
application as follows: \<open>t = b | x\<^sub>\<tau> | ?x\<^sub>\<tau> | c\<^sub>\<tau> | \<lambda>\<^sub>\<tau>. t | t\<^sub>1 t\<^sub>2\<close>. |
|
257 |
Parsing and printing takes care of converting between an external |
|
258 |
representation with named bound variables. Subsequently, we shall use the |
|
259 |
latter notation instead of internal de-Bruijn representation. |
|
20498 | 260 |
|
61854 | 261 |
The inductive relation \<open>t :: \<tau>\<close> assigns a (unique) type to a term according |
262 |
to the structure of atomic terms, abstractions, and applications: |
|
20498 | 263 |
\[ |
61493 | 264 |
\infer{\<open>a\<^sub>\<tau> :: \<tau>\<close>}{} |
20498 | 265 |
\qquad |
61493 | 266 |
\infer{\<open>(\<lambda>x\<^sub>\<tau>. t) :: \<tau> \<Rightarrow> \<sigma>\<close>}{\<open>t :: \<sigma>\<close>} |
20501 | 267 |
\qquad |
61493 | 268 |
\infer{\<open>t u :: \<sigma>\<close>}{\<open>t :: \<tau> \<Rightarrow> \<sigma>\<close> & \<open>u :: \<tau>\<close>} |
20498 | 269 |
\] |
61477 | 270 |
A \<^emph>\<open>well-typed term\<close> is a term that can be typed according to these rules. |
20498 | 271 |
|
61854 | 272 |
Typing information can be omitted: type-inference is able to reconstruct the |
273 |
most general type of a raw term, while assigning most general types to all |
|
274 |
of its variables and constants. Type-inference depends on a context of type |
|
275 |
constraints for fixed variables, and declarations for polymorphic constants. |
|
20514 | 276 |
|
20537 | 277 |
The identity of atomic terms consists both of the name and the type |
61854 | 278 |
component. This means that different variables \<open>x\<^bsub>\<tau>\<^sub>1\<^esub>\<close> and \<open>x\<^bsub>\<tau>\<^sub>2\<^esub>\<close> may |
279 |
become the same after type instantiation. Type-inference rejects variables |
|
280 |
of the same name, but different types. In contrast, mixed instances of |
|
34929 | 281 |
polymorphic constants occur routinely. |
20514 | 282 |
|
61416 | 283 |
\<^medskip> |
61854 | 284 |
The \<^emph>\<open>hidden polymorphism\<close> of a term \<open>t :: \<sigma>\<close> is the set of type variables |
285 |
occurring in \<open>t\<close>, but not in its type \<open>\<sigma>\<close>. This means that the term |
|
286 |
implicitly depends on type arguments that are not accounted in the result |
|
287 |
type, i.e.\ there are different type instances \<open>t\<vartheta> :: \<sigma>\<close> and |
|
288 |
\<open>t\<vartheta>' :: \<sigma>\<close> with the same type. This slightly pathological |
|
289 |
situation notoriously demands additional care. |
|
20514 | 290 |
|
61416 | 291 |
\<^medskip> |
61854 | 292 |
A \<^emph>\<open>term abbreviation\<close> is a syntactic definition \<open>c\<^sub>\<sigma> \<equiv> t\<close> of a closed term |
293 |
\<open>t\<close> of type \<open>\<sigma>\<close>, without any hidden polymorphism. A term abbreviation looks |
|
294 |
like a constant in the syntax, but is expanded before entering the logical |
|
295 |
core. Abbreviations are usually reverted when printing terms, using \<open>t \<rightarrow> |
|
296 |
c\<^sub>\<sigma>\<close> as rules for higher-order rewriting. |
|
20519 | 297 |
|
61416 | 298 |
\<^medskip> |
61854 | 299 |
Canonical operations on \<open>\<lambda>\<close>-terms include \<open>\<alpha>\<beta>\<eta>\<close>-conversion: \<open>\<alpha>\<close>-conversion |
300 |
refers to capture-free renaming of bound variables; \<open>\<beta>\<close>-conversion contracts |
|
301 |
an abstraction applied to an argument term, substituting the argument in the |
|
302 |
body: \<open>(\<lambda>x. b)a\<close> becomes \<open>b[a/x]\<close>; \<open>\<eta>\<close>-conversion contracts vacuous |
|
303 |
application-abstraction: \<open>\<lambda>x. f x\<close> becomes \<open>f\<close>, provided that the bound |
|
304 |
variable does not occur in \<open>f\<close>. |
|
20519 | 305 |
|
61854 | 306 |
Terms are normally treated modulo \<open>\<alpha>\<close>-conversion, which is implicit in the |
307 |
de-Bruijn representation. Names for bound variables in abstractions are |
|
308 |
maintained separately as (meaningless) comments, mostly for parsing and |
|
309 |
printing. Full \<open>\<alpha>\<beta>\<eta>\<close>-conversion is commonplace in various standard |
|
310 |
operations (\secref{sec:obj-rules}) that are based on higher-order |
|
311 |
unification and matching. |
|
58618 | 312 |
\<close> |
18537 | 313 |
|
58618 | 314 |
text %mlref \<open> |
20514 | 315 |
\begin{mldecls} |
316 |
@{index_ML_type term} \\ |
|
46262 | 317 |
@{index_ML_op "aconv": "term * term -> bool"} \\ |
39846 | 318 |
@{index_ML Term.map_types: "(typ -> typ) -> term -> term"} \\ |
319 |
@{index_ML Term.fold_types: "(typ -> 'a -> 'a) -> term -> 'a -> 'a"} \\ |
|
320 |
@{index_ML Term.map_aterms: "(term -> term) -> term -> term"} \\ |
|
321 |
@{index_ML Term.fold_aterms: "(term -> 'a -> 'a) -> term -> 'a -> 'a"} \\ |
|
20547 | 322 |
\end{mldecls} |
323 |
\begin{mldecls} |
|
20514 | 324 |
@{index_ML fastype_of: "term -> typ"} \\ |
20519 | 325 |
@{index_ML lambda: "term -> term -> term"} \\ |
326 |
@{index_ML betapply: "term * term -> term"} \\ |
|
42934 | 327 |
@{index_ML incr_boundvars: "int -> term -> term"} \\ |
42401
9bfaf6819291
updated some theory primitives, which now depend on auxiliary context;
wenzelm
parents:
40255
diff
changeset
|
328 |
@{index_ML Sign.declare_const: "Proof.context -> |
9bfaf6819291
updated some theory primitives, which now depend on auxiliary context;
wenzelm
parents:
40255
diff
changeset
|
329 |
(binding * typ) * mixfix -> theory -> term * theory"} \\ |
33174 | 330 |
@{index_ML Sign.add_abbrev: "string -> binding * term -> |
24972
acafb18a47dc
replaced Sign.add_consts_i by Sign.declare_const;
wenzelm
parents:
24828
diff
changeset
|
331 |
theory -> (term * term) * theory"} \\ |
20519 | 332 |
@{index_ML Sign.const_typargs: "theory -> string * typ -> typ list"} \\ |
333 |
@{index_ML Sign.const_instance: "theory -> string * typ list -> typ"} \\ |
|
20514 | 334 |
\end{mldecls} |
18537 | 335 |
|
69597 | 336 |
\<^descr> Type \<^ML_type>\<open>term\<close> represents de-Bruijn terms, with comments in |
61854 | 337 |
abstractions, and explicitly named free variables and constants; this is a |
338 |
datatype with constructors @{index_ML Bound}, @{index_ML Free}, @{index_ML |
|
339 |
Var}, @{index_ML Const}, @{index_ML Abs}, @{index_ML_op "$"}. |
|
20519 | 340 |
|
69597 | 341 |
\<^descr> \<open>t\<close>~\<^ML_text>\<open>aconv\<close>~\<open>u\<close> checks \<open>\<alpha>\<close>-equivalence of two terms. This is the |
342 |
basic equality relation on type \<^ML_type>\<open>term\<close>; raw datatype equality |
|
61854 | 343 |
should only be used for operations related to parsing or printing! |
20537 | 344 |
|
69597 | 345 |
\<^descr> \<^ML>\<open>Term.map_types\<close>~\<open>f t\<close> applies the mapping \<open>f\<close> to all types occurring |
61854 | 346 |
in \<open>t\<close>. |
347 |
||
69597 | 348 |
\<^descr> \<^ML>\<open>Term.fold_types\<close>~\<open>f t\<close> iterates the operation \<open>f\<close> over all |
61854 | 349 |
occurrences of types in \<open>t\<close>; the term structure is traversed from left to |
350 |
right. |
|
20519 | 351 |
|
69597 | 352 |
\<^descr> \<^ML>\<open>Term.map_aterms\<close>~\<open>f t\<close> applies the mapping \<open>f\<close> to all atomic terms |
353 |
(\<^ML>\<open>Bound\<close>, \<^ML>\<open>Free\<close>, \<^ML>\<open>Var\<close>, \<^ML>\<open>Const\<close>) occurring in \<open>t\<close>. |
|
20537 | 354 |
|
69597 | 355 |
\<^descr> \<^ML>\<open>Term.fold_aterms\<close>~\<open>f t\<close> iterates the operation \<open>f\<close> over all |
356 |
occurrences of atomic terms (\<^ML>\<open>Bound\<close>, \<^ML>\<open>Free\<close>, \<^ML>\<open>Var\<close>, \<^ML>\<open>Const\<close>) in \<open>t\<close>; the term structure is traversed from left to right. |
|
20519 | 357 |
|
69597 | 358 |
\<^descr> \<^ML>\<open>fastype_of\<close>~\<open>t\<close> determines the type of a well-typed term. This |
61854 | 359 |
operation is relatively slow, despite the omission of any sanity checks. |
20519 | 360 |
|
69597 | 361 |
\<^descr> \<^ML>\<open>lambda\<close>~\<open>a b\<close> produces an abstraction \<open>\<lambda>a. b\<close>, where occurrences of |
61854 | 362 |
the atomic term \<open>a\<close> in the body \<open>b\<close> are replaced by bound variables. |
20519 | 363 |
|
69597 | 364 |
\<^descr> \<^ML>\<open>betapply\<close>~\<open>(t, u)\<close> produces an application \<open>t u\<close>, with topmost |
61854 | 365 |
\<open>\<beta>\<close>-conversion if \<open>t\<close> is an abstraction. |
20519 | 366 |
|
69597 | 367 |
\<^descr> \<^ML>\<open>incr_boundvars\<close>~\<open>j\<close> increments a term's dangling bound variables by |
61854 | 368 |
the offset \<open>j\<close>. This is required when moving a subterm into a context where |
369 |
it is enclosed by a different number of abstractions. Bound variables with a |
|
370 |
matching abstraction are unaffected. |
|
42934 | 371 |
|
69597 | 372 |
\<^descr> \<^ML>\<open>Sign.declare_const\<close>~\<open>ctxt ((c, \<sigma>), mx)\<close> declares a new constant \<open>c :: |
61854 | 373 |
\<sigma>\<close> with optional mixfix syntax. |
20519 | 374 |
|
69597 | 375 |
\<^descr> \<^ML>\<open>Sign.add_abbrev\<close>~\<open>print_mode (c, t)\<close> introduces a new term |
61854 | 376 |
abbreviation \<open>c \<equiv> t\<close>. |
20519 | 377 |
|
69597 | 378 |
\<^descr> \<^ML>\<open>Sign.const_typargs\<close>~\<open>thy (c, \<tau>)\<close> and \<^ML>\<open>Sign.const_instance\<close>~\<open>thy |
61854 | 379 |
(c, [\<tau>\<^sub>1, \<dots>, \<tau>\<^sub>n])\<close> convert between two representations of polymorphic |
380 |
constants: full type instance vs.\ compact type arguments form. |
|
58618 | 381 |
\<close> |
18537 | 382 |
|
58618 | 383 |
text %mlantiq \<open> |
39832 | 384 |
\begin{matharray}{rcl} |
61493 | 385 |
@{ML_antiquotation_def "const_name"} & : & \<open>ML_antiquotation\<close> \\ |
386 |
@{ML_antiquotation_def "const_abbrev"} & : & \<open>ML_antiquotation\<close> \\ |
|
387 |
@{ML_antiquotation_def "const"} & : & \<open>ML_antiquotation\<close> \\ |
|
388 |
@{ML_antiquotation_def "term"} & : & \<open>ML_antiquotation\<close> \\ |
|
389 |
@{ML_antiquotation_def "prop"} & : & \<open>ML_antiquotation\<close> \\ |
|
39832 | 390 |
\end{matharray} |
391 |
||
69597 | 392 |
\<^rail>\<open> |
42510
b9c106763325
use @{rail} antiquotation (with some nested markup);
wenzelm
parents:
42401
diff
changeset
|
393 |
(@@{ML_antiquotation const_name} | |
67146 | 394 |
@@{ML_antiquotation const_abbrev}) embedded |
39832 | 395 |
; |
42510
b9c106763325
use @{rail} antiquotation (with some nested markup);
wenzelm
parents:
42401
diff
changeset
|
396 |
@@{ML_antiquotation const} ('(' (type + ',') ')')? |
39832 | 397 |
; |
42510
b9c106763325
use @{rail} antiquotation (with some nested markup);
wenzelm
parents:
42401
diff
changeset
|
398 |
@@{ML_antiquotation term} term |
39832 | 399 |
; |
42510
b9c106763325
use @{rail} antiquotation (with some nested markup);
wenzelm
parents:
42401
diff
changeset
|
400 |
@@{ML_antiquotation prop} prop |
69597 | 401 |
\<close> |
39832 | 402 |
|
61854 | 403 |
\<^descr> \<open>@{const_name c}\<close> inlines the internalized logical constant name \<open>c\<close> --- |
69597 | 404 |
as \<^ML_type>\<open>string\<close> literal. |
61854 | 405 |
|
406 |
\<^descr> \<open>@{const_abbrev c}\<close> inlines the internalized abbreviated constant name \<open>c\<close> |
|
69597 | 407 |
--- as \<^ML_type>\<open>string\<close> literal. |
39832 | 408 |
|
61854 | 409 |
\<^descr> \<open>@{const c(\<^vec>\<tau>)}\<close> inlines the internalized constant \<open>c\<close> with precise |
69597 | 410 |
type instantiation in the sense of \<^ML>\<open>Sign.const_instance\<close> --- as \<^ML>\<open>Const\<close> constructor term for datatype \<^ML_type>\<open>term\<close>. |
39832 | 411 |
|
61854 | 412 |
\<^descr> \<open>@{term t}\<close> inlines the internalized term \<open>t\<close> --- as constructor term for |
69597 | 413 |
datatype \<^ML_type>\<open>term\<close>. |
39832 | 414 |
|
61854 | 415 |
\<^descr> \<open>@{prop \<phi>}\<close> inlines the internalized proposition \<open>\<phi>\<close> --- as constructor |
69597 | 416 |
term for datatype \<^ML_type>\<open>term\<close>. |
58618 | 417 |
\<close> |
39832 | 418 |
|
18537 | 419 |
|
58618 | 420 |
section \<open>Theorems \label{sec:thms}\<close> |
18537 | 421 |
|
58618 | 422 |
text \<open> |
61854 | 423 |
A \<^emph>\<open>proposition\<close> is a well-typed term of type \<open>prop\<close>, a \<^emph>\<open>theorem\<close> is a |
424 |
proven proposition (depending on a context of hypotheses and the background |
|
425 |
theory). Primitive inferences include plain Natural Deduction rules for the |
|
426 |
primary connectives \<open>\<And>\<close> and \<open>\<Longrightarrow>\<close> of the framework. There is also a builtin |
|
61493 | 427 |
notion of equality/equivalence \<open>\<equiv>\<close>. |
58618 | 428 |
\<close> |
20521 | 429 |
|
29758 | 430 |
|
58618 | 431 |
subsection \<open>Primitive connectives and rules \label{sec:prim-rules}\<close> |
18537 | 432 |
|
58618 | 433 |
text \<open> |
61854 | 434 |
The theory \<open>Pure\<close> contains constant declarations for the primitive |
435 |
connectives \<open>\<And>\<close>, \<open>\<Longrightarrow>\<close>, and \<open>\<equiv>\<close> of the logical framework, see |
|
436 |
\figref{fig:pure-connectives}. The derivability judgment \<open>A\<^sub>1, \<dots>, A\<^sub>n \<turnstile> B\<close> |
|
437 |
is defined inductively by the primitive inferences given in |
|
438 |
\figref{fig:prim-rules}, with the global restriction that the hypotheses |
|
439 |
must \<^emph>\<open>not\<close> contain any schematic variables. The builtin equality is |
|
440 |
conceptually axiomatized as shown in \figref{fig:pure-equality}, although |
|
441 |
the implementation works directly with derived inferences. |
|
20521 | 442 |
|
443 |
\begin{figure}[htb] |
|
444 |
\begin{center} |
|
20501 | 445 |
\begin{tabular}{ll} |
61493 | 446 |
\<open>all :: (\<alpha> \<Rightarrow> prop) \<Rightarrow> prop\<close> & universal quantification (binder \<open>\<And>\<close>) \\ |
447 |
\<open>\<Longrightarrow> :: prop \<Rightarrow> prop \<Rightarrow> prop\<close> & implication (right associative infix) \\ |
|
448 |
\<open>\<equiv> :: \<alpha> \<Rightarrow> \<alpha> \<Rightarrow> prop\<close> & equality relation (infix) \\ |
|
20501 | 449 |
\end{tabular} |
20537 | 450 |
\caption{Primitive connectives of Pure}\label{fig:pure-connectives} |
20521 | 451 |
\end{center} |
452 |
\end{figure} |
|
18537 | 453 |
|
20501 | 454 |
\begin{figure}[htb] |
455 |
\begin{center} |
|
20498 | 456 |
\[ |
61493 | 457 |
\infer[\<open>(axiom)\<close>]{\<open>\<turnstile> A\<close>}{\<open>A \<in> \<Theta>\<close>} |
20498 | 458 |
\qquad |
61493 | 459 |
\infer[\<open>(assume)\<close>]{\<open>A \<turnstile> A\<close>}{} |
20498 | 460 |
\] |
461 |
\[ |
|
61493 | 462 |
\infer[\<open>(\<And>\<hyphen>intro)\<close>]{\<open>\<Gamma> \<turnstile> \<And>x. B[x]\<close>}{\<open>\<Gamma> \<turnstile> B[x]\<close> & \<open>x \<notin> \<Gamma>\<close>} |
20498 | 463 |
\qquad |
61493 | 464 |
\infer[\<open>(\<And>\<hyphen>elim)\<close>]{\<open>\<Gamma> \<turnstile> B[a]\<close>}{\<open>\<Gamma> \<turnstile> \<And>x. B[x]\<close>} |
20498 | 465 |
\] |
466 |
\[ |
|
61493 | 467 |
\infer[\<open>(\<Longrightarrow>\<hyphen>intro)\<close>]{\<open>\<Gamma> - A \<turnstile> A \<Longrightarrow> B\<close>}{\<open>\<Gamma> \<turnstile> B\<close>} |
20498 | 468 |
\qquad |
61493 | 469 |
\infer[\<open>(\<Longrightarrow>\<hyphen>elim)\<close>]{\<open>\<Gamma>\<^sub>1 \<union> \<Gamma>\<^sub>2 \<turnstile> B\<close>}{\<open>\<Gamma>\<^sub>1 \<turnstile> A \<Longrightarrow> B\<close> & \<open>\<Gamma>\<^sub>2 \<turnstile> A\<close>} |
20498 | 470 |
\] |
20521 | 471 |
\caption{Primitive inferences of Pure}\label{fig:prim-rules} |
472 |
\end{center} |
|
473 |
\end{figure} |
|
474 |
||
475 |
\begin{figure}[htb] |
|
476 |
\begin{center} |
|
477 |
\begin{tabular}{ll} |
|
61493 | 478 |
\<open>\<turnstile> (\<lambda>x. b[x]) a \<equiv> b[a]\<close> & \<open>\<beta>\<close>-conversion \\ |
479 |
\<open>\<turnstile> x \<equiv> x\<close> & reflexivity \\ |
|
480 |
\<open>\<turnstile> x \<equiv> y \<Longrightarrow> P x \<Longrightarrow> P y\<close> & substitution \\ |
|
481 |
\<open>\<turnstile> (\<And>x. f x \<equiv> g x) \<Longrightarrow> f \<equiv> g\<close> & extensionality \\ |
|
482 |
\<open>\<turnstile> (A \<Longrightarrow> B) \<Longrightarrow> (B \<Longrightarrow> A) \<Longrightarrow> A \<equiv> B\<close> & logical equivalence \\ |
|
20521 | 483 |
\end{tabular} |
20542 | 484 |
\caption{Conceptual axiomatization of Pure equality}\label{fig:pure-equality} |
20501 | 485 |
\end{center} |
486 |
\end{figure} |
|
18537 | 487 |
|
61854 | 488 |
The introduction and elimination rules for \<open>\<And>\<close> and \<open>\<Longrightarrow>\<close> are analogous to |
489 |
formation of dependently typed \<open>\<lambda>\<close>-terms representing the underlying proof |
|
490 |
objects. Proof terms are irrelevant in the Pure logic, though; they cannot |
|
491 |
occur within propositions. The system provides a runtime option to record |
|
52408 | 492 |
explicit proof terms for primitive inferences, see also |
61854 | 493 |
\secref{sec:proof-terms}. Thus all three levels of \<open>\<lambda>\<close>-calculus become |
494 |
explicit: \<open>\<Rightarrow>\<close> for terms, and \<open>\<And>/\<Longrightarrow>\<close> for proofs (cf.\ @{cite |
|
495 |
"Berghofer-Nipkow:2000:TPHOL"}). |
|
20491 | 496 |
|
61854 | 497 |
Observe that locally fixed parameters (as in \<open>\<And>\<hyphen>intro\<close>) need not be recorded |
498 |
in the hypotheses, because the simple syntactic types of Pure are always |
|
499 |
inhabitable. ``Assumptions'' \<open>x :: \<tau>\<close> for type-membership are only present |
|
500 |
as long as some \<open>x\<^sub>\<tau>\<close> occurs in the statement body.\<^footnote>\<open>This is the key |
|
501 |
difference to ``\<open>\<lambda>HOL\<close>'' in the PTS framework @{cite |
|
502 |
"Barendregt-Geuvers:2001"}, where hypotheses \<open>x : A\<close> are treated uniformly |
|
503 |
for propositions and types.\<close> |
|
20501 | 504 |
|
61416 | 505 |
\<^medskip> |
61854 | 506 |
The axiomatization of a theory is implicitly closed by forming all instances |
507 |
of type and term variables: \<open>\<turnstile> A\<vartheta>\<close> holds for any substitution |
|
508 |
instance of an axiom \<open>\<turnstile> A\<close>. By pushing substitutions through derivations |
|
509 |
inductively, we also get admissible \<open>generalize\<close> and \<open>instantiate\<close> rules as |
|
510 |
shown in \figref{fig:subst-rules}. |
|
20501 | 511 |
|
512 |
\begin{figure}[htb] |
|
513 |
\begin{center} |
|
20498 | 514 |
\[ |
61493 | 515 |
\infer{\<open>\<Gamma> \<turnstile> B[?\<alpha>]\<close>}{\<open>\<Gamma> \<turnstile> B[\<alpha>]\<close> & \<open>\<alpha> \<notin> \<Gamma>\<close>} |
20501 | 516 |
\quad |
61493 | 517 |
\infer[\quad\<open>(generalize)\<close>]{\<open>\<Gamma> \<turnstile> B[?x]\<close>}{\<open>\<Gamma> \<turnstile> B[x]\<close> & \<open>x \<notin> \<Gamma>\<close>} |
20498 | 518 |
\] |
519 |
\[ |
|
61493 | 520 |
\infer{\<open>\<Gamma> \<turnstile> B[\<tau>]\<close>}{\<open>\<Gamma> \<turnstile> B[?\<alpha>]\<close>} |
20501 | 521 |
\quad |
61493 | 522 |
\infer[\quad\<open>(instantiate)\<close>]{\<open>\<Gamma> \<turnstile> B[t]\<close>}{\<open>\<Gamma> \<turnstile> B[?x]\<close>} |
20498 | 523 |
\] |
20501 | 524 |
\caption{Admissible substitution rules}\label{fig:subst-rules} |
525 |
\end{center} |
|
526 |
\end{figure} |
|
18537 | 527 |
|
61854 | 528 |
Note that \<open>instantiate\<close> does not require an explicit side-condition, because |
529 |
\<open>\<Gamma>\<close> may never contain schematic variables. |
|
20537 | 530 |
|
61854 | 531 |
In principle, variables could be substituted in hypotheses as well, but this |
532 |
would disrupt the monotonicity of reasoning: deriving \<open>\<Gamma>\<vartheta> \<turnstile> |
|
533 |
B\<vartheta>\<close> from \<open>\<Gamma> \<turnstile> B\<close> is correct, but \<open>\<Gamma>\<vartheta> \<supseteq> \<Gamma>\<close> does not |
|
534 |
necessarily hold: the result belongs to a different proof context. |
|
20542 | 535 |
|
70568 | 536 |
\<^medskip> An \<^emph>\<open>oracle\<close> is a function that produces axioms on the fly. Logically, |
537 |
this is an instance of the \<open>axiom\<close> rule (\figref{fig:prim-rules}), but there |
|
538 |
is an operational difference. The inference kernel records oracle |
|
539 |
invocations within derivations of theorems by a unique tag. This also |
|
540 |
includes implicit type-class reasoning via the order-sorted algebra of class |
|
541 |
relations and type arities (see also @{command_ref instantiation} and |
|
542 |
@{command_ref instance}). |
|
20542 | 543 |
|
61854 | 544 |
Axiomatizations should be limited to the bare minimum, typically as part of |
545 |
the initial logical basis of an object-logic formalization. Later on, |
|
546 |
theories are usually developed in a strictly definitional fashion, by |
|
547 |
stating only certain equalities over new constants. |
|
20542 | 548 |
|
61854 | 549 |
A \<^emph>\<open>simple definition\<close> consists of a constant declaration \<open>c :: \<sigma>\<close> together |
550 |
with an axiom \<open>\<turnstile> c \<equiv> t\<close>, where \<open>t :: \<sigma>\<close> is a closed term without any hidden |
|
551 |
polymorphism. The RHS may depend on further defined constants, but not \<open>c\<close> |
|
552 |
itself. Definitions of functions may be presented as \<open>c \<^vec>x \<equiv> t\<close> |
|
553 |
instead of the puristic \<open>c \<equiv> \<lambda>\<^vec>x. t\<close>. |
|
20542 | 554 |
|
61854 | 555 |
An \<^emph>\<open>overloaded definition\<close> consists of a collection of axioms for the same |
556 |
constant, with zero or one equations \<open>c((\<^vec>\<alpha>)\<kappa>) \<equiv> t\<close> for each type |
|
557 |
constructor \<open>\<kappa>\<close> (for distinct variables \<open>\<^vec>\<alpha>\<close>). The RHS may mention |
|
558 |
previously defined constants as above, or arbitrary constants \<open>d(\<alpha>\<^sub>i)\<close> for |
|
559 |
some \<open>\<alpha>\<^sub>i\<close> projected from \<open>\<^vec>\<alpha>\<close>. Thus overloaded definitions |
|
560 |
essentially work by primitive recursion over the syntactic structure of a |
|
561 |
single type argument. See also @{cite \<open>\S4.3\<close> |
|
562 |
"Haftmann-Wenzel:2006:classes"}. |
|
58618 | 563 |
\<close> |
20498 | 564 |
|
58618 | 565 |
text %mlref \<open> |
20521 | 566 |
\begin{mldecls} |
46253 | 567 |
@{index_ML Logic.all: "term -> term -> term"} \\ |
568 |
@{index_ML Logic.mk_implies: "term * term -> term"} \\ |
|
569 |
\end{mldecls} |
|
570 |
\begin{mldecls} |
|
20521 | 571 |
@{index_ML_type ctyp} \\ |
572 |
@{index_ML_type cterm} \\ |
|
59621
291934bac95e
Thm.cterm_of and Thm.ctyp_of operate on local context;
wenzelm
parents:
58728
diff
changeset
|
573 |
@{index_ML Thm.ctyp_of: "Proof.context -> typ -> ctyp"} \\ |
291934bac95e
Thm.cterm_of and Thm.ctyp_of operate on local context;
wenzelm
parents:
58728
diff
changeset
|
574 |
@{index_ML Thm.cterm_of: "Proof.context -> term -> cterm"} \\ |
46497
89ccf66aa73d
renamed Thm.capply to Thm.apply, and Thm.cabs to Thm.lambda in conformance with similar operations in structure Term and Logic;
wenzelm
parents:
46262
diff
changeset
|
575 |
@{index_ML Thm.apply: "cterm -> cterm -> cterm"} \\ |
89ccf66aa73d
renamed Thm.capply to Thm.apply, and Thm.cabs to Thm.lambda in conformance with similar operations in structure Term and Logic;
wenzelm
parents:
46262
diff
changeset
|
576 |
@{index_ML Thm.lambda: "cterm -> cterm -> cterm"} \\ |
60938 | 577 |
@{index_ML Thm.all: "Proof.context -> cterm -> cterm -> cterm"} \\ |
46253 | 578 |
@{index_ML Drule.mk_implies: "cterm * cterm -> cterm"} \\ |
20547 | 579 |
\end{mldecls} |
580 |
\begin{mldecls} |
|
20521 | 581 |
@{index_ML_type thm} \\ |
50126
3dec88149176
theorem status about oracles/futures is no longer printed by default;
wenzelm
parents:
48985
diff
changeset
|
582 |
@{index_ML Thm.peek_status: "thm -> {oracle: bool, unfinished: bool, failed: bool}"} \\ |
42933 | 583 |
@{index_ML Thm.transfer: "theory -> thm -> thm"} \\ |
20542 | 584 |
@{index_ML Thm.assume: "cterm -> thm"} \\ |
585 |
@{index_ML Thm.forall_intr: "cterm -> thm -> thm"} \\ |
|
586 |
@{index_ML Thm.forall_elim: "cterm -> thm -> thm"} \\ |
|
587 |
@{index_ML Thm.implies_intr: "cterm -> thm -> thm"} \\ |
|
588 |
@{index_ML Thm.implies_elim: "thm -> thm -> thm"} \\ |
|
589 |
@{index_ML Thm.generalize: "string list * string list -> int -> thm -> thm"} \\ |
|
60642
48dd1cefb4ae
simplified Thm.instantiate and derivatives: the LHS refers to non-certified variables -- this merely serves as index into already certified structures (or is ignored);
wenzelm
parents:
59902
diff
changeset
|
590 |
@{index_ML Thm.instantiate: "((indexname * sort) * ctyp) list * ((indexname * typ) * cterm) list |
48dd1cefb4ae
simplified Thm.instantiate and derivatives: the LHS refers to non-certified variables -- this merely serves as index into already certified structures (or is ignored);
wenzelm
parents:
59902
diff
changeset
|
591 |
-> thm -> thm"} \\ |
42401
9bfaf6819291
updated some theory primitives, which now depend on auxiliary context;
wenzelm
parents:
40255
diff
changeset
|
592 |
@{index_ML Thm.add_axiom: "Proof.context -> |
9bfaf6819291
updated some theory primitives, which now depend on auxiliary context;
wenzelm
parents:
40255
diff
changeset
|
593 |
binding * term -> theory -> (string * thm) * theory"} \\ |
39821 | 594 |
@{index_ML Thm.add_oracle: "binding * ('a -> cterm) -> theory -> |
595 |
(string * ('a -> thm)) * theory"} \\ |
|
61261
ddb2da7cb2e4
more explicit Defs.context: use proper name spaces as far as possible;
wenzelm
parents:
61255
diff
changeset
|
596 |
@{index_ML Thm.add_def: "Defs.context -> bool -> bool -> |
42401
9bfaf6819291
updated some theory primitives, which now depend on auxiliary context;
wenzelm
parents:
40255
diff
changeset
|
597 |
binding * term -> theory -> (string * thm) * theory"} \\ |
20547 | 598 |
\end{mldecls} |
599 |
\begin{mldecls} |
|
61261
ddb2da7cb2e4
more explicit Defs.context: use proper name spaces as far as possible;
wenzelm
parents:
61255
diff
changeset
|
600 |
@{index_ML Theory.add_deps: "Defs.context -> string -> |
61255
15865e0c5598
eliminated separate type Theory.dep: use typeargs uniformly for consts/types;
wenzelm
parents:
61246
diff
changeset
|
601 |
Defs.entry -> Defs.entry list -> theory -> theory"} \\ |
70568 | 602 |
@{index_ML Thm_Deps.all_oracles: "thm list -> (string * term option) list"} \\ |
20521 | 603 |
\end{mldecls} |
604 |
||
69597 | 605 |
\<^descr> \<^ML>\<open>Thm.peek_status\<close>~\<open>thm\<close> informs about the current status of the |
61854 | 606 |
derivation object behind the given theorem. This is a snapshot of a |
607 |
potentially ongoing (parallel) evaluation of proofs. The three Boolean |
|
608 |
values indicate the following: \<^verbatim>\<open>oracle\<close> if the finished part contains some |
|
609 |
oracle invocation; \<^verbatim>\<open>unfinished\<close> if some future proofs are still pending; |
|
610 |
\<^verbatim>\<open>failed\<close> if some future proof has failed, rendering the theorem invalid! |
|
50126
3dec88149176
theorem status about oracles/futures is no longer printed by default;
wenzelm
parents:
48985
diff
changeset
|
611 |
|
69597 | 612 |
\<^descr> \<^ML>\<open>Logic.all\<close>~\<open>a B\<close> produces a Pure quantification \<open>\<And>a. B\<close>, where |
61854 | 613 |
occurrences of the atomic term \<open>a\<close> in the body proposition \<open>B\<close> are replaced |
69597 | 614 |
by bound variables. (See also \<^ML>\<open>lambda\<close> on terms.) |
46253 | 615 |
|
69597 | 616 |
\<^descr> \<^ML>\<open>Logic.mk_implies\<close>~\<open>(A, B)\<close> produces a Pure implication \<open>A \<Longrightarrow> B\<close>. |
46253 | 617 |
|
69597 | 618 |
\<^descr> Types \<^ML_type>\<open>ctyp\<close> and \<^ML_type>\<open>cterm\<close> represent certified types and |
61854 | 619 |
terms, respectively. These are abstract datatypes that guarantee that its |
620 |
values have passed the full well-formedness (and well-typedness) checks, |
|
621 |
relative to the declarations of type constructors, constants etc.\ in the |
|
69597 | 622 |
background theory. The abstract types \<^ML_type>\<open>ctyp\<close> and \<^ML_type>\<open>cterm\<close> |
61854 | 623 |
are part of the same inference kernel that is mainly responsible for |
69597 | 624 |
\<^ML_type>\<open>thm\<close>. Thus syntactic operations on \<^ML_type>\<open>ctyp\<close> and \<^ML_type>\<open>cterm\<close> are located in the \<^ML_structure>\<open>Thm\<close> module, even though theorems |
61854 | 625 |
are not yet involved at that stage. |
20542 | 626 |
|
69597 | 627 |
\<^descr> \<^ML>\<open>Thm.ctyp_of\<close>~\<open>ctxt \<tau>\<close> and \<^ML>\<open>Thm.cterm_of\<close>~\<open>ctxt t\<close> explicitly |
61854 | 628 |
check types and terms, respectively. This also involves some basic |
629 |
normalizations, such expansion of type and term abbreviations from the |
|
630 |
underlying theory context. Full re-certification is relatively slow and |
|
631 |
should be avoided in tight reasoning loops. |
|
20547 | 632 |
|
69597 | 633 |
\<^descr> \<^ML>\<open>Thm.apply\<close>, \<^ML>\<open>Thm.lambda\<close>, \<^ML>\<open>Thm.all\<close>, \<^ML>\<open>Drule.mk_implies\<close> |
61854 | 634 |
etc.\ compose certified terms (or propositions) incrementally. This is |
69597 | 635 |
equivalent to \<^ML>\<open>Thm.cterm_of\<close> after unchecked \<^ML_op>\<open>$\<close>, \<^ML>\<open>lambda\<close>, |
636 |
\<^ML>\<open>Logic.all\<close>, \<^ML>\<open>Logic.mk_implies\<close> etc., but there can be a big |
|
61854 | 637 |
difference in performance when large existing entities are composed by a few |
638 |
extra constructions on top. There are separate operations to decompose |
|
46253 | 639 |
certified terms and theorems to produce certified terms again. |
20542 | 640 |
|
69597 | 641 |
\<^descr> Type \<^ML_type>\<open>thm\<close> represents proven propositions. This is an abstract |
61854 | 642 |
datatype that guarantees that its values have been constructed by basic |
69597 | 643 |
principles of the \<^ML_structure>\<open>Thm\<close> module. Every \<^ML_type>\<open>thm\<close> value |
61854 | 644 |
refers its background theory, cf.\ \secref{sec:context-theory}. |
20542 | 645 |
|
69597 | 646 |
\<^descr> \<^ML>\<open>Thm.transfer\<close>~\<open>thy thm\<close> transfers the given theorem to a \<^emph>\<open>larger\<close> |
61854 | 647 |
theory, see also \secref{sec:context}. This formal adjustment of the |
648 |
background context has no logical significance, but is occasionally required |
|
649 |
for formal reasons, e.g.\ when theorems that are imported from more basic |
|
650 |
theories are used in the current situation. |
|
42933 | 651 |
|
69597 | 652 |
\<^descr> \<^ML>\<open>Thm.assume\<close>, \<^ML>\<open>Thm.forall_intr\<close>, \<^ML>\<open>Thm.forall_elim\<close>, \<^ML>\<open>Thm.implies_intr\<close>, and \<^ML>\<open>Thm.implies_elim\<close> correspond to the primitive |
61854 | 653 |
inferences of \figref{fig:prim-rules}. |
20542 | 654 |
|
69597 | 655 |
\<^descr> \<^ML>\<open>Thm.generalize\<close>~\<open>(\<^vec>\<alpha>, \<^vec>x)\<close> corresponds to the |
61854 | 656 |
\<open>generalize\<close> rules of \figref{fig:subst-rules}. Here collections of type and |
657 |
term variables are generalized simultaneously, specified by the given basic |
|
658 |
names. |
|
20521 | 659 |
|
69597 | 660 |
\<^descr> \<^ML>\<open>Thm.instantiate\<close>~\<open>(\<^vec>\<alpha>\<^sub>s, \<^vec>x\<^sub>\<tau>)\<close> corresponds to the |
61854 | 661 |
\<open>instantiate\<close> rules of \figref{fig:subst-rules}. Type variables are |
662 |
substituted before term variables. Note that the types in \<open>\<^vec>x\<^sub>\<tau>\<close> refer |
|
663 |
to the instantiated versions. |
|
20542 | 664 |
|
69597 | 665 |
\<^descr> \<^ML>\<open>Thm.add_axiom\<close>~\<open>ctxt (name, A)\<close> declares an arbitrary proposition as |
61854 | 666 |
axiom, and retrieves it as a theorem from the resulting theory, cf.\ \<open>axiom\<close> |
667 |
in \figref{fig:prim-rules}. Note that the low-level representation in the |
|
668 |
axiom table may differ slightly from the returned theorem. |
|
20542 | 669 |
|
69597 | 670 |
\<^descr> \<^ML>\<open>Thm.add_oracle\<close>~\<open>(binding, oracle)\<close> produces a named oracle rule, |
61854 | 671 |
essentially generating arbitrary axioms on the fly, cf.\ \<open>axiom\<close> in |
672 |
\figref{fig:prim-rules}. |
|
20521 | 673 |
|
69597 | 674 |
\<^descr> \<^ML>\<open>Thm.add_def\<close>~\<open>ctxt unchecked overloaded (name, c \<^vec>x \<equiv> t)\<close> |
61854 | 675 |
states a definitional axiom for an existing constant \<open>c\<close>. Dependencies are |
69597 | 676 |
recorded via \<^ML>\<open>Theory.add_deps\<close>, unless the \<open>unchecked\<close> option is set. |
61854 | 677 |
Note that the low-level representation in the axiom table may differ |
678 |
slightly from the returned theorem. |
|
20542 | 679 |
|
69597 | 680 |
\<^descr> \<^ML>\<open>Theory.add_deps\<close>~\<open>ctxt name c\<^sub>\<tau> \<^vec>d\<^sub>\<sigma>\<close> declares dependencies of |
61854 | 681 |
a named specification for constant \<open>c\<^sub>\<tau>\<close>, relative to existing |
682 |
specifications for constants \<open>\<^vec>d\<^sub>\<sigma>\<close>. This also works for type |
|
683 |
constructors. |
|
70568 | 684 |
|
685 |
\<^descr> \<^ML>\<open>Thm_Deps.all_oracles\<close>~\<open>thms\<close> returns all oracles used in the |
|
686 |
internal derivation of the given theorems; this covers the full graph of |
|
687 |
transitive dependencies. The result contains a name, plus the original |
|
688 |
proposition, if @{ML Proofterm.proofs} was at least @{ML 1} during the |
|
689 |
oracle inference. See also the command @{command_ref "thm_oracles"}. |
|
58618 | 690 |
\<close> |
20521 | 691 |
|
58618 | 692 |
text %mlantiq \<open> |
39832 | 693 |
\begin{matharray}{rcl} |
61493 | 694 |
@{ML_antiquotation_def "ctyp"} & : & \<open>ML_antiquotation\<close> \\ |
695 |
@{ML_antiquotation_def "cterm"} & : & \<open>ML_antiquotation\<close> \\ |
|
696 |
@{ML_antiquotation_def "cprop"} & : & \<open>ML_antiquotation\<close> \\ |
|
697 |
@{ML_antiquotation_def "thm"} & : & \<open>ML_antiquotation\<close> \\ |
|
698 |
@{ML_antiquotation_def "thms"} & : & \<open>ML_antiquotation\<close> \\ |
|
699 |
@{ML_antiquotation_def "lemma"} & : & \<open>ML_antiquotation\<close> \\ |
|
70568 | 700 |
@{ML_antiquotation_def "oracle_name"} & : & \<open>ML_antiquotation\<close> \\ |
39832 | 701 |
\end{matharray} |
702 |
||
69597 | 703 |
\<^rail>\<open> |
42510
b9c106763325
use @{rail} antiquotation (with some nested markup);
wenzelm
parents:
42401
diff
changeset
|
704 |
@@{ML_antiquotation ctyp} typ |
39832 | 705 |
; |
42510
b9c106763325
use @{rail} antiquotation (with some nested markup);
wenzelm
parents:
42401
diff
changeset
|
706 |
@@{ML_antiquotation cterm} term |
39832 | 707 |
; |
42510
b9c106763325
use @{rail} antiquotation (with some nested markup);
wenzelm
parents:
42401
diff
changeset
|
708 |
@@{ML_antiquotation cprop} prop |
39832 | 709 |
; |
62969 | 710 |
@@{ML_antiquotation thm} thm |
42510
b9c106763325
use @{rail} antiquotation (with some nested markup);
wenzelm
parents:
42401
diff
changeset
|
711 |
; |
62969 | 712 |
@@{ML_antiquotation thms} thms |
39832 | 713 |
; |
55029
61a6bf7d4b02
clarified @{rail} syntax: prefer explicit \<newline> symbol;
wenzelm
parents:
54883
diff
changeset
|
714 |
@@{ML_antiquotation lemma} ('(' @'open' ')')? ((prop +) + @'and') \<newline> |
42517
b68e1c27709a
simplified keyword markup (without formal checking);
wenzelm
parents:
42510
diff
changeset
|
715 |
@'by' method method? |
70568 | 716 |
; |
717 |
@@{ML_antiquotation oracle_name} embedded |
|
69597 | 718 |
\<close> |
39832 | 719 |
|
61854 | 720 |
\<^descr> \<open>@{ctyp \<tau>}\<close> produces a certified type wrt.\ the current background theory |
69597 | 721 |
--- as abstract value of type \<^ML_type>\<open>ctyp\<close>. |
61854 | 722 |
|
723 |
\<^descr> \<open>@{cterm t}\<close> and \<open>@{cprop \<phi>}\<close> produce a certified term wrt.\ the current |
|
69597 | 724 |
background theory --- as abstract value of type \<^ML_type>\<open>cterm\<close>. |
39832 | 725 |
|
61854 | 726 |
\<^descr> \<open>@{thm a}\<close> produces a singleton fact --- as abstract value of type |
69597 | 727 |
\<^ML_type>\<open>thm\<close>. |
39832 | 728 |
|
61854 | 729 |
\<^descr> \<open>@{thms a}\<close> produces a general fact --- as abstract value of type |
69597 | 730 |
\<^ML_type>\<open>thm list\<close>. |
39832 | 731 |
|
61854 | 732 |
\<^descr> \<open>@{lemma \<phi> by meth}\<close> produces a fact that is proven on the spot according |
733 |
to the minimal proof, which imitates a terminal Isar proof. The result is an |
|
69597 | 734 |
abstract value of type \<^ML_type>\<open>thm\<close> or \<^ML_type>\<open>thm list\<close>, depending on |
61854 | 735 |
the number of propositions given here. |
39832 | 736 |
|
61854 | 737 |
The internal derivation object lacks a proper theorem name, but it is |
738 |
formally closed, unless the \<open>(open)\<close> option is specified (this may impact |
|
739 |
performance of applications with proof terms). |
|
39832 | 740 |
|
61854 | 741 |
Since ML antiquotations are always evaluated at compile-time, there is no |
742 |
run-time overhead even for non-trivial proofs. Nonetheless, the |
|
743 |
justification is syntactically limited to a single @{command "by"} step. |
|
744 |
More complex Isar proofs should be done in regular theory source, before |
|
745 |
compiling the corresponding ML text that uses the result. |
|
70568 | 746 |
|
747 |
\<^descr> \<open>@{oracle_name a}\<close> inlines the internalized oracle name \<open>a\<close> --- as |
|
748 |
\<^ML_type>\<open>string\<close> literal. |
|
58618 | 749 |
\<close> |
39832 | 750 |
|
751 |
||
58618 | 752 |
subsection \<open>Auxiliary connectives \label{sec:logic-aux}\<close> |
20521 | 753 |
|
61854 | 754 |
text \<open> |
755 |
Theory \<open>Pure\<close> provides a few auxiliary connectives that are defined on top |
|
756 |
of the primitive ones, see \figref{fig:pure-aux}. These special constants |
|
757 |
are useful in certain internal encodings, and are normally not directly |
|
758 |
exposed to the user. |
|
20501 | 759 |
|
760 |
\begin{figure}[htb] |
|
761 |
\begin{center} |
|
20498 | 762 |
\begin{tabular}{ll} |
61493 | 763 |
\<open>conjunction :: prop \<Rightarrow> prop \<Rightarrow> prop\<close> & (infix \<open>&&&\<close>) \\ |
764 |
\<open>\<turnstile> A &&& B \<equiv> (\<And>C. (A \<Longrightarrow> B \<Longrightarrow> C) \<Longrightarrow> C)\<close> \\[1ex] |
|
765 |
\<open>prop :: prop \<Rightarrow> prop\<close> & (prefix \<open>#\<close>, suppressed) \\ |
|
766 |
\<open>#A \<equiv> A\<close> \\[1ex] |
|
767 |
\<open>term :: \<alpha> \<Rightarrow> prop\<close> & (prefix \<open>TERM\<close>) \\ |
|
768 |
\<open>term x \<equiv> (\<And>A. A \<Longrightarrow> A)\<close> \\[1ex] |
|
769 |
\<open>type :: \<alpha> itself\<close> & (prefix \<open>TYPE\<close>) \\ |
|
770 |
\<open>(unspecified)\<close> \\ |
|
20498 | 771 |
\end{tabular} |
20521 | 772 |
\caption{Definitions of auxiliary connectives}\label{fig:pure-aux} |
20501 | 773 |
\end{center} |
774 |
\end{figure} |
|
775 |
||
61854 | 776 |
The introduction \<open>A \<Longrightarrow> B \<Longrightarrow> A &&& B\<close>, and eliminations (projections) \<open>A &&& B |
777 |
\<Longrightarrow> A\<close> and \<open>A &&& B \<Longrightarrow> B\<close> are available as derived rules. Conjunction allows to |
|
778 |
treat simultaneous assumptions and conclusions uniformly, e.g.\ consider \<open>A |
|
779 |
\<Longrightarrow> B \<Longrightarrow> C &&& D\<close>. In particular, the goal mechanism represents multiple claims |
|
780 |
as explicit conjunction internally, but this is refined (via backwards |
|
781 |
introduction) into separate sub-goals before the user commences the proof; |
|
782 |
the final result is projected into a list of theorems using eliminations |
|
783 |
(cf.\ \secref{sec:tactical-goals}). |
|
20498 | 784 |
|
61854 | 785 |
The \<open>prop\<close> marker (\<open>#\<close>) makes arbitrarily complex propositions appear as |
786 |
atomic, without changing the meaning: \<open>\<Gamma> \<turnstile> A\<close> and \<open>\<Gamma> \<turnstile> #A\<close> are |
|
787 |
interchangeable. See \secref{sec:tactical-goals} for specific operations. |
|
20521 | 788 |
|
61854 | 789 |
The \<open>term\<close> marker turns any well-typed term into a derivable proposition: \<open>\<turnstile> |
790 |
TERM t\<close> holds unconditionally. Although this is logically vacuous, it allows |
|
791 |
to treat terms and proofs uniformly, similar to a type-theoretic framework. |
|
20498 | 792 |
|
61854 | 793 |
The \<open>TYPE\<close> constructor is the canonical representative of the unspecified |
794 |
type \<open>\<alpha> itself\<close>; it essentially injects the language of types into that of |
|
795 |
terms. There is specific notation \<open>TYPE(\<tau>)\<close> for \<open>TYPE\<^bsub>\<tau> itself\<^esub>\<close>. Although |
|
796 |
being devoid of any particular meaning, the term \<open>TYPE(\<tau>)\<close> accounts for the |
|
797 |
type \<open>\<tau>\<close> within the term language. In particular, \<open>TYPE(\<alpha>)\<close> may be used as |
|
798 |
formal argument in primitive definitions, in order to circumvent hidden |
|
799 |
polymorphism (cf.\ \secref{sec:terms}). For example, \<open>c TYPE(\<alpha>) \<equiv> A[\<alpha>]\<close> |
|
800 |
defines \<open>c :: \<alpha> itself \<Rightarrow> prop\<close> in terms of a proposition \<open>A\<close> that depends on |
|
801 |
an additional type argument, which is essentially a predicate on types. |
|
58618 | 802 |
\<close> |
20501 | 803 |
|
58618 | 804 |
text %mlref \<open> |
20521 | 805 |
\begin{mldecls} |
806 |
@{index_ML Conjunction.intr: "thm -> thm -> thm"} \\ |
|
807 |
@{index_ML Conjunction.elim: "thm -> thm * thm"} \\ |
|
808 |
@{index_ML Drule.mk_term: "cterm -> thm"} \\ |
|
809 |
@{index_ML Drule.dest_term: "thm -> cterm"} \\ |
|
810 |
@{index_ML Logic.mk_type: "typ -> term"} \\ |
|
811 |
@{index_ML Logic.dest_type: "term -> typ"} \\ |
|
812 |
\end{mldecls} |
|
813 |
||
69597 | 814 |
\<^descr> \<^ML>\<open>Conjunction.intr\<close> derives \<open>A &&& B\<close> from \<open>A\<close> and \<open>B\<close>. |
20542 | 815 |
|
69597 | 816 |
\<^descr> \<^ML>\<open>Conjunction.elim\<close> derives \<open>A\<close> and \<open>B\<close> from \<open>A &&& B\<close>. |
20542 | 817 |
|
69597 | 818 |
\<^descr> \<^ML>\<open>Drule.mk_term\<close> derives \<open>TERM t\<close>. |
20542 | 819 |
|
69597 | 820 |
\<^descr> \<^ML>\<open>Drule.dest_term\<close> recovers term \<open>t\<close> from \<open>TERM t\<close>. |
20542 | 821 |
|
69597 | 822 |
\<^descr> \<^ML>\<open>Logic.mk_type\<close>~\<open>\<tau>\<close> produces the term \<open>TYPE(\<tau>)\<close>. |
20542 | 823 |
|
69597 | 824 |
\<^descr> \<^ML>\<open>Logic.dest_type\<close>~\<open>TYPE(\<tau>)\<close> recovers the type \<open>\<tau>\<close>. |
58618 | 825 |
\<close> |
18537 | 826 |
|
20480 | 827 |
|
58618 | 828 |
subsection \<open>Sort hypotheses\<close> |
52406 | 829 |
|
61854 | 830 |
text \<open> |
831 |
Type variables are decorated with sorts, as explained in \secref{sec:types}. |
|
832 |
This constrains type instantiation to certain ranges of types: variable |
|
833 |
\<open>\<alpha>\<^sub>s\<close> may only be assigned to types \<open>\<tau>\<close> that belong to sort \<open>s\<close>. Within the |
|
834 |
logic, sort constraints act like implicit preconditions on the result \<open>\<lparr>\<alpha>\<^sub>1 |
|
835 |
: s\<^sub>1\<rparr>, \<dots>, \<lparr>\<alpha>\<^sub>n : s\<^sub>n\<rparr>, \<Gamma> \<turnstile> \<phi>\<close> where the type variables \<open>\<alpha>\<^sub>1, \<dots>, \<alpha>\<^sub>n\<close> cover |
|
836 |
the propositions \<open>\<Gamma>\<close>, \<open>\<phi>\<close>, as well as the proof of \<open>\<Gamma> \<turnstile> \<phi>\<close>. |
|
52406 | 837 |
|
61854 | 838 |
These \<^emph>\<open>sort hypothesis\<close> of a theorem are passed monotonically through |
839 |
further derivations. They are redundant, as long as the statement of a |
|
840 |
theorem still contains the type variables that are accounted here. The |
|
841 |
logical significance of sort hypotheses is limited to the boundary case |
|
842 |
where type variables disappear from the proposition, e.g.\ \<open>\<lparr>\<alpha>\<^sub>s : s\<rparr> \<turnstile> \<phi>\<close>. |
|
843 |
Since such dangling type variables can be renamed arbitrarily without |
|
844 |
changing the proposition \<open>\<phi>\<close>, the inference kernel maintains sort hypotheses |
|
845 |
in anonymous form \<open>s \<turnstile> \<phi>\<close>. |
|
52406 | 846 |
|
61854 | 847 |
In most practical situations, such extra sort hypotheses may be stripped in |
848 |
a final bookkeeping step, e.g.\ at the end of a proof: they are typically |
|
849 |
left over from intermediate reasoning with type classes that can be |
|
850 |
satisfied by some concrete type \<open>\<tau>\<close> of sort \<open>s\<close> to replace the hypothetical |
|
851 |
type variable \<open>\<alpha>\<^sub>s\<close>. |
|
852 |
\<close> |
|
52406 | 853 |
|
58618 | 854 |
text %mlref \<open> |
52406 | 855 |
\begin{mldecls} |
856 |
@{index_ML Thm.extra_shyps: "thm -> sort list"} \\ |
|
857 |
@{index_ML Thm.strip_shyps: "thm -> thm"} \\ |
|
858 |
\end{mldecls} |
|
859 |
||
69597 | 860 |
\<^descr> \<^ML>\<open>Thm.extra_shyps\<close>~\<open>thm\<close> determines the extraneous sort hypotheses of |
61854 | 861 |
the given theorem, i.e.\ the sorts that are not present within type |
862 |
variables of the statement. |
|
52406 | 863 |
|
69597 | 864 |
\<^descr> \<^ML>\<open>Thm.strip_shyps\<close>~\<open>thm\<close> removes any extraneous sort hypotheses that |
61854 | 865 |
can be witnessed from the type signature. |
58618 | 866 |
\<close> |
52406 | 867 |
|
61854 | 868 |
text %mlex \<open> |
69597 | 869 |
The following artificial example demonstrates the derivation of \<^prop>\<open>False\<close> with a pending sort hypothesis involving a logically empty sort. |
61854 | 870 |
\<close> |
52406 | 871 |
|
872 |
class empty = |
|
873 |
assumes bad: "\<And>(x::'a) y. x \<noteq> y" |
|
874 |
||
875 |
theorem (in empty) false: False |
|
876 |
using bad by blast |
|
877 |
||
69597 | 878 |
ML_val \<open>\<^assert> (Thm.extra_shyps @{thm false} = [\<^sort>\<open>empty\<close>])\<close> |
52406 | 879 |
|
61854 | 880 |
text \<open> |
881 |
Thanks to the inference kernel managing sort hypothesis according to their |
|
882 |
logical significance, this example is merely an instance of \<^emph>\<open>ex falso |
|
883 |
quodlibet consequitur\<close> --- not a collapse of the logical framework! |
|
884 |
\<close> |
|
52406 | 885 |
|
886 |
||
58618 | 887 |
section \<open>Object-level rules \label{sec:obj-rules}\<close> |
18537 | 888 |
|
58618 | 889 |
text \<open> |
61854 | 890 |
The primitive inferences covered so far mostly serve foundational purposes. |
891 |
User-level reasoning usually works via object-level rules that are |
|
892 |
represented as theorems of Pure. Composition of rules involves |
|
893 |
\<^emph>\<open>backchaining\<close>, \<^emph>\<open>higher-order unification\<close> modulo \<open>\<alpha>\<beta>\<eta>\<close>-conversion of |
|
894 |
\<open>\<lambda>\<close>-terms, and so-called \<^emph>\<open>lifting\<close> of rules into a context of \<open>\<And>\<close> and \<open>\<Longrightarrow>\<close> |
|
895 |
connectives. Thus the full power of higher-order Natural Deduction in |
|
896 |
Isabelle/Pure becomes readily available. |
|
58618 | 897 |
\<close> |
20491 | 898 |
|
29769
03634a9e91ae
improved section on "Hereditary Harrop Formulae";
wenzelm
parents:
29768
diff
changeset
|
899 |
|
58618 | 900 |
subsection \<open>Hereditary Harrop Formulae\<close> |
29769
03634a9e91ae
improved section on "Hereditary Harrop Formulae";
wenzelm
parents:
29768
diff
changeset
|
901 |
|
58618 | 902 |
text \<open> |
61854 | 903 |
The idea of object-level rules is to model Natural Deduction inferences in |
904 |
the style of Gentzen @{cite "Gentzen:1935"}, but we allow arbitrary nesting |
|
69307 | 905 |
similar to @{cite "Schroeder-Heister:1984"}. The most basic rule format is |
906 |
that of a \<^emph>\<open>Horn Clause\<close>: |
|
29768 | 907 |
\[ |
61493 | 908 |
\infer{\<open>A\<close>}{\<open>A\<^sub>1\<close> & \<open>\<dots>\<close> & \<open>A\<^sub>n\<close>} |
29768 | 909 |
\] |
61854 | 910 |
where \<open>A, A\<^sub>1, \<dots>, A\<^sub>n\<close> are atomic propositions of the framework, usually of |
911 |
the form \<open>Trueprop B\<close>, where \<open>B\<close> is a (compound) object-level statement. |
|
912 |
This object-level inference corresponds to an iterated implication in Pure |
|
913 |
like this: |
|
29768 | 914 |
\[ |
61493 | 915 |
\<open>A\<^sub>1 \<Longrightarrow> \<dots> A\<^sub>n \<Longrightarrow> A\<close> |
29768 | 916 |
\] |
61854 | 917 |
As an example consider conjunction introduction: \<open>A \<Longrightarrow> B \<Longrightarrow> A \<and> B\<close>. Any |
918 |
parameters occurring in such rule statements are conceptionally treated as |
|
919 |
arbitrary: |
|
29768 | 920 |
\[ |
61493 | 921 |
\<open>\<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\<close> |
29768 | 922 |
\] |
20491 | 923 |
|
61854 | 924 |
Nesting of rules means that the positions of \<open>A\<^sub>i\<close> may again hold compound |
925 |
rules, not just atomic propositions. Propositions of this format are called |
|
926 |
\<^emph>\<open>Hereditary Harrop Formulae\<close> in the literature @{cite "Miller:1991"}. Here |
|
927 |
we give an inductive characterization as follows: |
|
29768 | 928 |
|
61416 | 929 |
\<^medskip> |
29768 | 930 |
\begin{tabular}{ll} |
61493 | 931 |
\<open>\<^bold>x\<close> & set of variables \\ |
932 |
\<open>\<^bold>A\<close> & set of atomic propositions \\ |
|
933 |
\<open>\<^bold>H = \<And>\<^bold>x\<^sup>*. \<^bold>H\<^sup>* \<Longrightarrow> \<^bold>A\<close> & set of Hereditary Harrop Formulas \\ |
|
29768 | 934 |
\end{tabular} |
61416 | 935 |
\<^medskip> |
29768 | 936 |
|
61854 | 937 |
Thus we essentially impose nesting levels on propositions formed from \<open>\<And>\<close> |
938 |
and \<open>\<Longrightarrow>\<close>. At each level there is a prefix of parameters and compound |
|
939 |
premises, concluding an atomic proposition. Typical examples are |
|
940 |
\<open>\<longrightarrow>\<close>-introduction \<open>(A \<Longrightarrow> B) \<Longrightarrow> A \<longrightarrow> B\<close> or mathematical induction \<open>P 0 \<Longrightarrow> (\<And>n. P n |
|
941 |
\<Longrightarrow> P (Suc n)) \<Longrightarrow> P n\<close>. Even deeper nesting occurs in well-founded induction |
|
942 |
\<open>(\<And>x. (\<And>y. y \<prec> x \<Longrightarrow> P y) \<Longrightarrow> P x) \<Longrightarrow> P x\<close>, but this already marks the limit of |
|
943 |
rule complexity that is usually seen in practice. |
|
29769
03634a9e91ae
improved section on "Hereditary Harrop Formulae";
wenzelm
parents:
29768
diff
changeset
|
944 |
|
61416 | 945 |
\<^medskip> |
61854 | 946 |
Regular user-level inferences in Isabelle/Pure always maintain the following |
947 |
canonical form of results: |
|
29769
03634a9e91ae
improved section on "Hereditary Harrop Formulae";
wenzelm
parents:
29768
diff
changeset
|
948 |
|
61854 | 949 |
\<^item> Normalization by \<open>(A \<Longrightarrow> (\<And>x. B x)) \<equiv> (\<And>x. A \<Longrightarrow> B x)\<close>, which is a theorem of |
950 |
Pure, means that quantifiers are pushed in front of implication at each |
|
951 |
level of nesting. The normal form is a Hereditary Harrop Formula. |
|
29769
03634a9e91ae
improved section on "Hereditary Harrop Formulae";
wenzelm
parents:
29768
diff
changeset
|
952 |
|
61854 | 953 |
\<^item> The outermost prefix of parameters is represented via schematic variables: |
954 |
instead of \<open>\<And>\<^vec>x. \<^vec>H \<^vec>x \<Longrightarrow> A \<^vec>x\<close> we have \<open>\<^vec>H |
|
955 |
?\<^vec>x \<Longrightarrow> A ?\<^vec>x\<close>. Note that this representation looses information |
|
956 |
about the order of parameters, and vacuous quantifiers vanish automatically. |
|
58618 | 957 |
\<close> |
29769
03634a9e91ae
improved section on "Hereditary Harrop Formulae";
wenzelm
parents:
29768
diff
changeset
|
958 |
|
58618 | 959 |
text %mlref \<open> |
29771 | 960 |
\begin{mldecls} |
54883
dd04a8b654fc
proper context for norm_hhf and derived operations;
wenzelm
parents:
53200
diff
changeset
|
961 |
@{index_ML Simplifier.norm_hhf: "Proof.context -> thm -> thm"} \\ |
29771 | 962 |
\end{mldecls} |
963 |
||
69597 | 964 |
\<^descr> \<^ML>\<open>Simplifier.norm_hhf\<close>~\<open>ctxt thm\<close> normalizes the given theorem |
61854 | 965 |
according to the canonical form specified above. This is occasionally |
966 |
helpful to repair some low-level tools that do not handle Hereditary Harrop |
|
967 |
Formulae properly. |
|
58618 | 968 |
\<close> |
29771 | 969 |
|
29769
03634a9e91ae
improved section on "Hereditary Harrop Formulae";
wenzelm
parents:
29768
diff
changeset
|
970 |
|
58618 | 971 |
subsection \<open>Rule composition\<close> |
29769
03634a9e91ae
improved section on "Hereditary Harrop Formulae";
wenzelm
parents:
29768
diff
changeset
|
972 |
|
58618 | 973 |
text \<open> |
61854 | 974 |
The rule calculus of Isabelle/Pure provides two main inferences: @{inference |
975 |
resolution} (i.e.\ back-chaining of rules) and @{inference assumption} |
|
976 |
(i.e.\ closing a branch), both modulo higher-order unification. There are |
|
977 |
also combined variants, notably @{inference elim_resolution} and @{inference |
|
978 |
dest_resolution}. |
|
20491 | 979 |
|
61854 | 980 |
To understand the all-important @{inference resolution} principle, we first |
981 |
consider raw @{inference_def composition} (modulo higher-order unification |
|
982 |
with substitution \<open>\<vartheta>\<close>): |
|
20498 | 983 |
\[ |
61493 | 984 |
\infer[(@{inference_def composition})]{\<open>\<^vec>A\<vartheta> \<Longrightarrow> C\<vartheta>\<close>} |
985 |
{\<open>\<^vec>A \<Longrightarrow> B\<close> & \<open>B' \<Longrightarrow> C\<close> & \<open>B\<vartheta> = B'\<vartheta>\<close>} |
|
20498 | 986 |
\] |
61854 | 987 |
Here the conclusion of the first rule is unified with the premise of the |
988 |
second; the resulting rule instance inherits the premises of the first and |
|
989 |
conclusion of the second. Note that \<open>C\<close> can again consist of iterated |
|
990 |
implications. We can also permute the premises of the second rule |
|
991 |
back-and-forth in order to compose with \<open>B'\<close> in any position (subsequently |
|
992 |
we shall always refer to position 1 w.l.o.g.). |
|
20498 | 993 |
|
61854 | 994 |
In @{inference composition} the internal structure of the common part \<open>B\<close> |
995 |
and \<open>B'\<close> is not taken into account. For proper @{inference resolution} we |
|
996 |
require \<open>B\<close> to be atomic, and explicitly observe the structure \<open>\<And>\<^vec>x. |
|
997 |
\<^vec>H \<^vec>x \<Longrightarrow> B' \<^vec>x\<close> of the premise of the second rule. The idea |
|
998 |
is to adapt the first rule by ``lifting'' it into this context, by means of |
|
999 |
iterated application of the following inferences: |
|
20498 | 1000 |
\[ |
61493 | 1001 |
\infer[(@{inference_def imp_lift})]{\<open>(\<^vec>H \<Longrightarrow> \<^vec>A) \<Longrightarrow> (\<^vec>H \<Longrightarrow> B)\<close>}{\<open>\<^vec>A \<Longrightarrow> B\<close>} |
20498 | 1002 |
\] |
1003 |
\[ |
|
61493 | 1004 |
\infer[(@{inference_def all_lift})]{\<open>(\<And>\<^vec>x. \<^vec>A (?\<^vec>a \<^vec>x)) \<Longrightarrow> (\<And>\<^vec>x. B (?\<^vec>a \<^vec>x))\<close>}{\<open>\<^vec>A ?\<^vec>a \<Longrightarrow> B ?\<^vec>a\<close>} |
20498 | 1005 |
\] |
29771 | 1006 |
By combining raw composition with lifting, we get full @{inference |
1007 |
resolution} as follows: |
|
20498 | 1008 |
\[ |
29771 | 1009 |
\infer[(@{inference_def resolution})] |
61493 | 1010 |
{\<open>(\<And>\<^vec>x. \<^vec>H \<^vec>x \<Longrightarrow> \<^vec>A (?\<^vec>a \<^vec>x))\<vartheta> \<Longrightarrow> C\<vartheta>\<close>} |
20498 | 1011 |
{\begin{tabular}{l} |
61493 | 1012 |
\<open>\<^vec>A ?\<^vec>a \<Longrightarrow> B ?\<^vec>a\<close> \\ |
1013 |
\<open>(\<And>\<^vec>x. \<^vec>H \<^vec>x \<Longrightarrow> B' \<^vec>x) \<Longrightarrow> C\<close> \\ |
|
1014 |
\<open>(\<lambda>\<^vec>x. B (?\<^vec>a \<^vec>x))\<vartheta> = B'\<vartheta>\<close> \\ |
|
20498 | 1015 |
\end{tabular}} |
1016 |
\] |
|
1017 |
||
61854 | 1018 |
Continued resolution of rules allows to back-chain a problem towards more |
1019 |
and sub-problems. Branches are closed either by resolving with a rule of 0 |
|
1020 |
premises, or by producing a ``short-circuit'' within a solved situation |
|
1021 |
(again modulo unification): |
|
29771 | 1022 |
\[ |
61493 | 1023 |
\infer[(@{inference_def assumption})]{\<open>C\<vartheta>\<close>} |
61962
9c8fc56032e3
eliminated obscure macro that is in conflict with amsmath.sty;
wenzelm
parents:
61854
diff
changeset
|
1024 |
{\<open>(\<And>\<^vec>x. \<^vec>H \<^vec>x \<Longrightarrow> A \<^vec>x) \<Longrightarrow> C\<close> & \<open>A\<vartheta> = H\<^sub>i\<vartheta>\<close>~~\mbox{(for some~\<open>i\<close>)}} |
29771 | 1025 |
\] |
20498 | 1026 |
|
52422 | 1027 |
%FIXME @{inference_def elim_resolution}, @{inference_def dest_resolution} |
58618 | 1028 |
\<close> |
18537 | 1029 |
|
58618 | 1030 |
text %mlref \<open> |
29768 | 1031 |
\begin{mldecls} |
46262 | 1032 |
@{index_ML_op "RSN": "thm * (int * thm) -> thm"} \\ |
1033 |
@{index_ML_op "RS": "thm * thm -> thm"} \\ |
|
46256 | 1034 |
|
46262 | 1035 |
@{index_ML_op "RLN": "thm list * (int * thm list) -> thm list"} \\ |
1036 |
@{index_ML_op "RL": "thm list * thm list -> thm list"} \\ |
|
46256 | 1037 |
|
46262 | 1038 |
@{index_ML_op "MRS": "thm list * thm -> thm"} \\ |
1039 |
@{index_ML_op "OF": "thm * thm list -> thm"} \\ |
|
29768 | 1040 |
\end{mldecls} |
1041 |
||
61854 | 1042 |
\<^descr> \<open>rule\<^sub>1 RSN (i, rule\<^sub>2)\<close> resolves the conclusion of \<open>rule\<^sub>1\<close> with the |
1043 |
\<open>i\<close>-th premise of \<open>rule\<^sub>2\<close>, according to the @{inference resolution} |
|
1044 |
principle explained above. Unless there is precisely one resolvent it raises |
|
69597 | 1045 |
exception \<^ML>\<open>THM\<close>. |
46256 | 1046 |
|
61854 | 1047 |
This corresponds to the rule attribute @{attribute THEN} in Isar source |
1048 |
language. |
|
46256 | 1049 |
|
61854 | 1050 |
\<^descr> \<open>rule\<^sub>1 RS rule\<^sub>2\<close> abbreviates \<open>rule\<^sub>1 RSN (1, rule\<^sub>2)\<close>. |
29768 | 1051 |
|
61854 | 1052 |
\<^descr> \<open>rules\<^sub>1 RLN (i, rules\<^sub>2)\<close> joins lists of rules. For every \<open>rule\<^sub>1\<close> in |
1053 |
\<open>rules\<^sub>1\<close> and \<open>rule\<^sub>2\<close> in \<open>rules\<^sub>2\<close>, it resolves the conclusion of \<open>rule\<^sub>1\<close> |
|
1054 |
with the \<open>i\<close>-th premise of \<open>rule\<^sub>2\<close>, accumulating multiple results in one |
|
1055 |
big list. Note that such strict enumerations of higher-order unifications |
|
1056 |
can be inefficient compared to the lazy variant seen in elementary tactics |
|
69597 | 1057 |
like \<^ML>\<open>resolve_tac\<close>. |
46256 | 1058 |
|
61854 | 1059 |
\<^descr> \<open>rules\<^sub>1 RL rules\<^sub>2\<close> abbreviates \<open>rules\<^sub>1 RLN (1, rules\<^sub>2)\<close>. |
46256 | 1060 |
|
61854 | 1061 |
\<^descr> \<open>[rule\<^sub>1, \<dots>, rule\<^sub>n] MRS rule\<close> resolves \<open>rule\<^sub>i\<close> against premise \<open>i\<close> of |
1062 |
\<open>rule\<close>, for \<open>i = n, \<dots>, 1\<close>. By working from right to left, newly emerging |
|
1063 |
premises are concatenated in the result, without interfering. |
|
46256 | 1064 |
|
61854 | 1065 |
\<^descr> \<open>rule OF rules\<close> is an alternative notation for \<open>rules MRS rule\<close>, which |
1066 |
makes rule composition look more like function application. Note that the |
|
1067 |
argument \<open>rules\<close> need not be atomic. |
|
46256 | 1068 |
|
61854 | 1069 |
This corresponds to the rule attribute @{attribute OF} in Isar source |
1070 |
language. |
|
58618 | 1071 |
\<close> |
30272 | 1072 |
|
52407 | 1073 |
|
58618 | 1074 |
section \<open>Proof terms \label{sec:proof-terms}\<close> |
52407 | 1075 |
|
61854 | 1076 |
text \<open> |
1077 |
The Isabelle/Pure inference kernel can record the proof of each theorem as a |
|
1078 |
proof term that contains all logical inferences in detail. Rule composition |
|
1079 |
by resolution (\secref{sec:obj-rules}) and type-class reasoning is broken |
|
1080 |
down to primitive rules of the logical framework. The proof term can be |
|
1081 |
inspected by a separate proof-checker, for example. |
|
52407 | 1082 |
|
61854 | 1083 |
According to the well-known \<^emph>\<open>Curry-Howard isomorphism\<close>, a proof can be |
1084 |
viewed as a \<open>\<lambda>\<close>-term. Following this idea, proofs in Isabelle are internally |
|
1085 |
represented by a datatype similar to the one for terms described in |
|
1086 |
\secref{sec:terms}. On top of these syntactic terms, two more layers of |
|
1087 |
\<open>\<lambda>\<close>-calculus are added, which correspond to \<open>\<And>x :: \<alpha>. B x\<close> and \<open>A \<Longrightarrow> B\<close> |
|
1088 |
according to the propositions-as-types principle. The resulting 3-level |
|
1089 |
\<open>\<lambda>\<close>-calculus resembles ``\<open>\<lambda>HOL\<close>'' in the more abstract setting of Pure Type |
|
1090 |
Systems (PTS) @{cite "Barendregt-Geuvers:2001"}, if some fine points like |
|
1091 |
schematic polymorphism and type classes are ignored. |
|
52407 | 1092 |
|
61416 | 1093 |
\<^medskip> |
61854 | 1094 |
\<^emph>\<open>Proof abstractions\<close> of the form \<open>\<^bold>\<lambda>x :: \<alpha>. prf\<close> or \<open>\<^bold>\<lambda>p : A. prf\<close> |
1095 |
correspond to introduction of \<open>\<And>\<close>/\<open>\<Longrightarrow>\<close>, and \<^emph>\<open>proof applications\<close> of the form |
|
1096 |
\<open>p \<cdot> t\<close> or \<open>p \<bullet> q\<close> correspond to elimination of \<open>\<And>\<close>/\<open>\<Longrightarrow>\<close>. Actual types \<open>\<alpha>\<close>, |
|
1097 |
propositions \<open>A\<close>, and terms \<open>t\<close> might be suppressed and reconstructed from |
|
1098 |
the overall proof term. |
|
52407 | 1099 |
|
61416 | 1100 |
\<^medskip> |
61854 | 1101 |
Various atomic proofs indicate special situations within the proof |
1102 |
construction as follows. |
|
52407 | 1103 |
|
61854 | 1104 |
A \<^emph>\<open>bound proof variable\<close> is a natural number \<open>b\<close> that acts as de-Bruijn |
1105 |
index for proof term abstractions. |
|
52407 | 1106 |
|
61854 | 1107 |
A \<^emph>\<open>minimal proof\<close> ``\<open>?\<close>'' is a dummy proof term. This indicates some |
1108 |
unrecorded part of the proof. |
|
52407 | 1109 |
|
61854 | 1110 |
\<open>Hyp A\<close> refers to some pending hypothesis by giving its proposition. This |
1111 |
indicates an open context of implicit hypotheses, similar to loose bound |
|
1112 |
variables or free variables within a term (\secref{sec:terms}). |
|
52407 | 1113 |
|
61854 | 1114 |
An \<^emph>\<open>axiom\<close> or \<^emph>\<open>oracle\<close> \<open>a : A[\<^vec>\<tau>]\<close> refers some postulated \<open>proof |
1115 |
constant\<close>, which is subject to schematic polymorphism of theory content, and |
|
1116 |
the particular type instantiation may be given explicitly. The vector of |
|
1117 |
types \<open>\<^vec>\<tau>\<close> refers to the schematic type variables in the generic |
|
61493 | 1118 |
proposition \<open>A\<close> in canonical order. |
52407 | 1119 |
|
61854 | 1120 |
A \<^emph>\<open>proof promise\<close> \<open>a : A[\<^vec>\<tau>]\<close> is a placeholder for some proof of |
1121 |
polymorphic proposition \<open>A\<close>, with explicit type instantiation as given by |
|
1122 |
the vector \<open>\<^vec>\<tau>\<close>, as above. Unlike axioms or oracles, proof promises |
|
1123 |
may be \<^emph>\<open>fulfilled\<close> eventually, by substituting \<open>a\<close> by some particular proof |
|
1124 |
\<open>q\<close> at the corresponding type instance. This acts like Hindley-Milner |
|
1125 |
\<open>let\<close>-polymorphism: a generic local proof definition may get used at |
|
1126 |
different type instances, and is replaced by the concrete instance |
|
1127 |
eventually. |
|
52407 | 1128 |
|
61854 | 1129 |
A \<^emph>\<open>named theorem\<close> wraps up some concrete proof as a closed formal entity, |
1130 |
in the manner of constant definitions for proof terms. The \<^emph>\<open>proof body\<close> of |
|
1131 |
such boxed theorems involves some digest about oracles and promises |
|
1132 |
occurring in the original proof. This allows the inference kernel to manage |
|
1133 |
this critical information without the full overhead of explicit proof terms. |
|
58618 | 1134 |
\<close> |
52407 | 1135 |
|
52411 | 1136 |
|
58618 | 1137 |
subsection \<open>Reconstructing and checking proof terms\<close> |
52411 | 1138 |
|
61854 | 1139 |
text \<open> |
1140 |
Fully explicit proof terms can be large, but most of this information is |
|
1141 |
redundant and can be reconstructed from the context. Therefore, the |
|
1142 |
Isabelle/Pure inference kernel records only \<^emph>\<open>implicit\<close> proof terms, by |
|
1143 |
omitting all typing information in terms, all term and type labels of proof |
|
1144 |
abstractions, and some argument terms of applications \<open>p \<cdot> t\<close> (if possible). |
|
52411 | 1145 |
|
61854 | 1146 |
There are separate operations to reconstruct the full proof term later on, |
1147 |
using \<^emph>\<open>higher-order pattern unification\<close> @{cite "nipkow-patterns" and |
|
1148 |
"Berghofer-Nipkow:2000:TPHOL"}. |
|
52411 | 1149 |
|
61854 | 1150 |
The \<^emph>\<open>proof checker\<close> expects a fully reconstructed proof term, and can turn |
1151 |
it into a theorem by replaying its primitive inferences within the kernel. |
|
1152 |
\<close> |
|
52411 | 1153 |
|
52412 | 1154 |
|
58618 | 1155 |
subsection \<open>Concrete syntax of proof terms\<close> |
52412 | 1156 |
|
61854 | 1157 |
text \<open> |
1158 |
The concrete syntax of proof terms is a slight extension of the regular |
|
1159 |
inner syntax of Isabelle/Pure @{cite "isabelle-isar-ref"}. Its main |
|
1160 |
syntactic category @{syntax (inner) proof} is defined as follows: |
|
52412 | 1161 |
|
1162 |
\begin{center} |
|
1163 |
\begin{supertabular}{rclr} |
|
1164 |
||
70389 | 1165 |
@{syntax_def (inner) proof} & = & \<open>\<^bold>\<lambda>\<close> \<open>params\<close> \<^verbatim>\<open>.\<close> \<open>proof\<close> \\ |
61493 | 1166 |
& \<open>|\<close> & \<open>proof\<close> \<open>\<cdot>\<close> \<open>any\<close> \\ |
1167 |
& \<open>|\<close> & \<open>proof\<close> \<open>\<bullet>\<close> \<open>proof\<close> \\ |
|
1168 |
& \<open>|\<close> & \<open>id | longid\<close> \\ |
|
52412 | 1169 |
\\ |
1170 |
||
61493 | 1171 |
\<open>param\<close> & = & \<open>idt\<close> \\ |
61503 | 1172 |
& \<open>|\<close> & \<open>idt\<close> \<^verbatim>\<open>:\<close> \<open>prop\<close> \\ |
1173 |
& \<open>|\<close> & \<^verbatim>\<open>(\<close> \<open>param\<close> \<^verbatim>\<open>)\<close> \\ |
|
52412 | 1174 |
\\ |
1175 |
||
61493 | 1176 |
\<open>params\<close> & = & \<open>param\<close> \\ |
1177 |
& \<open>|\<close> & \<open>param\<close> \<open>params\<close> \\ |
|
52412 | 1178 |
|
1179 |
\end{supertabular} |
|
1180 |
\end{center} |
|
1181 |
||
61854 | 1182 |
Implicit term arguments in partial proofs are indicated by ``\<open>_\<close>''. Type |
1183 |
arguments for theorems and axioms may be specified using \<open>p \<cdot> TYPE(type)\<close> |
|
1184 |
(they must appear before any other term argument of a theorem or axiom, but |
|
1185 |
may be omitted altogether). |
|
52412 | 1186 |
|
61416 | 1187 |
\<^medskip> |
61854 | 1188 |
There are separate read and print operations for proof terms, in order to |
1189 |
avoid conflicts with the regular term language. |
|
58618 | 1190 |
\<close> |
52412 | 1191 |
|
58618 | 1192 |
text %mlref \<open> |
52408 | 1193 |
\begin{mldecls} |
1194 |
@{index_ML_type proof} \\ |
|
1195 |
@{index_ML_type proof_body} \\ |
|
65446 | 1196 |
@{index_ML Proofterm.proofs: "int Unsynchronized.ref"} \\ |
70447
755d58b48cec
clarified modules: provide reconstruct_proof / expand_proof at the bottom of proof term construction;
wenzelm
parents:
70401
diff
changeset
|
1197 |
@{index_ML Proofterm.reconstruct_proof: |
70449 | 1198 |
"theory -> term -> proof -> proof"} \\ |
1199 |
@{index_ML Proofterm.expand_proof: "theory -> |
|
52411 | 1200 |
(string * term option) list -> proof -> proof"} \\ |
52412 | 1201 |
@{index_ML Proof_Checker.thm_of_proof: "theory -> proof -> thm"} \\ |
1202 |
@{index_ML Proof_Syntax.read_proof: "theory -> bool -> bool -> string -> proof"} \\ |
|
1203 |
@{index_ML Proof_Syntax.pretty_proof: "Proof.context -> proof -> Pretty.T"} \\ |
|
52408 | 1204 |
\end{mldecls} |
1205 |
||
69597 | 1206 |
\<^descr> Type \<^ML_type>\<open>proof\<close> represents proof terms; this is a datatype with |
61854 | 1207 |
constructors @{index_ML Abst}, @{index_ML AbsP}, @{index_ML_op "%"}, |
1208 |
@{index_ML_op "%%"}, @{index_ML PBound}, @{index_ML MinProof}, @{index_ML |
|
70401
3c9f6aad092f
discontinued Proofterm.Promise (cf. 725438ceae7c);
wenzelm
parents:
70389
diff
changeset
|
1209 |
Hyp}, @{index_ML PAxm}, @{index_ML Oracle}, @{index_ML PThm} as explained |
3c9f6aad092f
discontinued Proofterm.Promise (cf. 725438ceae7c);
wenzelm
parents:
70389
diff
changeset
|
1210 |
above. %FIXME OfClass (!?) |
61854 | 1211 |
|
69597 | 1212 |
\<^descr> Type \<^ML_type>\<open>proof_body\<close> represents the nested proof information of a |
61854 | 1213 |
named theorem, consisting of a digest of oracles and named theorem over some |
1214 |
proof term. The digest only covers the directly visible part of the proof: |
|
1215 |
in order to get the full information, the implicit graph of nested theorems |
|
69597 | 1216 |
needs to be traversed (e.g.\ using \<^ML>\<open>Proofterm.fold_body_thms\<close>). |
52408 | 1217 |
|
69597 | 1218 |
\<^descr> \<^ML>\<open>Thm.proof_of\<close>~\<open>thm\<close> and \<^ML>\<open>Thm.proof_body_of\<close>~\<open>thm\<close> produce the |
61854 | 1219 |
proof term or proof body (with digest of oracles and theorems) from a given |
1220 |
theorem. Note that this involves a full join of internal futures that |
|
1221 |
fulfill pending proof promises, and thus disrupts the natural bottom-up |
|
1222 |
construction of proofs by introducing dynamic ad-hoc dependencies. Parallel |
|
1223 |
performance may suffer by inspecting proof terms at run-time. |
|
52408 | 1224 |
|
69597 | 1225 |
\<^descr> \<^ML>\<open>Proofterm.proofs\<close> specifies the detail of proof recording within |
1226 |
\<^ML_type>\<open>thm\<close> values produced by the inference kernel: \<^ML>\<open>0\<close> records only |
|
1227 |
the names of oracles, \<^ML>\<open>1\<close> records oracle names and propositions, \<^ML>\<open>2\<close> |
|
65446 | 1228 |
additionally records full proof terms. Officially named theorems that |
1229 |
contribute to a result are recorded in any case. |
|
52408 | 1230 |
|
70449 | 1231 |
\<^descr> \<^ML>\<open>Proofterm.reconstruct_proof\<close>~\<open>thy prop prf\<close> turns the implicit |
61854 | 1232 |
proof term \<open>prf\<close> into a full proof of the given proposition. |
52487
48bc24467008
backout dedd7952a62c: static "proofs" value within theory prevents later inferencing with different configuration;
wenzelm
parents:
52486
diff
changeset
|
1233 |
|
61854 | 1234 |
Reconstruction may fail if \<open>prf\<close> is not a proof of \<open>prop\<close>, or if it does not |
1235 |
contain sufficient information for reconstruction. Failure may only happen |
|
1236 |
for proofs that are constructed manually, but not for those produced |
|
1237 |
automatically by the inference kernel. |
|
52411 | 1238 |
|
70449 | 1239 |
\<^descr> \<^ML>\<open>Proofterm.expand_proof\<close>~\<open>thy [thm\<^sub>1, \<dots>, thm\<^sub>n] prf\<close> expands and |
61854 | 1240 |
reconstructs the proofs of all specified theorems, with the given (full) |
1241 |
proof. Theorems that are not unique specified via their name may be |
|
1242 |
disambiguated by giving their proposition. |
|
52411 | 1243 |
|
69597 | 1244 |
\<^descr> \<^ML>\<open>Proof_Checker.thm_of_proof\<close>~\<open>thy prf\<close> turns the given (full) proof |
61854 | 1245 |
into a theorem, by replaying it using only primitive rules of the inference |
1246 |
kernel. |
|
52411 | 1247 |
|
69597 | 1248 |
\<^descr> \<^ML>\<open>Proof_Syntax.read_proof\<close>~\<open>thy b\<^sub>1 b\<^sub>2 s\<close> reads in a proof term. The |
61854 | 1249 |
Boolean flags indicate the use of sort and type information. Usually, typing |
1250 |
information is left implicit and is inferred during proof reconstruction. |
|
1251 |
%FIXME eliminate flags!? |
|
52412 | 1252 |
|
69597 | 1253 |
\<^descr> \<^ML>\<open>Proof_Syntax.pretty_proof\<close>~\<open>ctxt prf\<close> pretty-prints the given proof |
61854 | 1254 |
term. |
58618 | 1255 |
\<close> |
52408 | 1256 |
|
61854 | 1257 |
text %mlex \<open> |
63680 | 1258 |
\<^item> \<^file>\<open>~~/src/HOL/Proofs/ex/Proof_Terms.thy\<close> provides basic examples involving |
1259 |
proof terms. |
|
52410 | 1260 |
|
63680 | 1261 |
\<^item> \<^file>\<open>~~/src/HOL/Proofs/ex/XML_Data.thy\<close> demonstrates export and import of |
1262 |
proof terms via XML/ML data representation. |
|
58618 | 1263 |
\<close> |
52410 | 1264 |
|
18537 | 1265 |
end |