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