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