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