5 chapter {* The Isabelle/Isar Framework \label{ch:isar-framework} *}
9 \cite{Wenzel:1999:TPHOL,Wenzel-PhD,Nipkow-TYPES02,Wenzel-Paulson:2006,Wenzel:2006:Festschrift}
10 is intended as a generic framework for developing formal
11 mathematical documents with full proof checking. Definitions and
12 proofs are organized as theories. An assembly of theory sources may
13 be presented as a printed document; see also
14 \chref{ch:document-prep}.
16 The main objective of Isar is the design of a human-readable
17 structured proof language, which is called the ``primary proof
18 format'' in Isar terminology. Such a primary proof language is
19 somewhere in the middle between the extremes of primitive proof
20 objects and actual natural language. In this respect, Isar is a bit
21 more formalistic than Mizar
22 \cite{Trybulec:1993:MizarFeatures,Rudnicki:1992:MizarOverview,Wiedijk:1999:Mizar},
23 using logical symbols for certain reasoning schemes where Mizar
24 would prefer English words; see \cite{Wenzel-Wiedijk:2002} for
25 further comparisons of these systems.
27 So Isar challenges the traditional way of recording informal proofs
28 in mathematical prose, as well as the common tendency to see fully
29 formal proofs directly as objects of some logical calculus (e.g.\
30 @{text "\<lambda>"}-terms in a version of type theory). In fact, Isar is
31 better understood as an interpreter of a simple block-structured
32 language for describing the data flow of local facts and goals,
33 interspersed with occasional invocations of proof methods.
34 Everything is reduced to logical inferences internally, but these
35 steps are somewhat marginal compared to the overall bookkeeping of
36 the interpretation process. Thanks to careful design of the syntax
37 and semantics of Isar language elements, a formal record of Isar
38 instructions may later appear as an intelligible text to the
41 The Isar proof language has emerged from careful analysis of some
42 inherent virtues of the existing logical framework of Isabelle/Pure
43 \cite{paulson-found,paulson700}, notably composition of higher-order
44 natural deduction rules, which is a generalization of Gentzen's
45 original calculus \cite{Gentzen:1935}. The approach of generic
46 inference systems in Pure is continued by Isar towards actual proof
49 Concrete applications require another intermediate layer: an
50 object-logic. Isabelle/HOL \cite{isa-tutorial} (simply-typed
51 set-theory) is being used most of the time; Isabelle/ZF
52 \cite{isabelle-ZF} is less extensively developed, although it would
53 probably fit better for classical mathematics.
55 \medskip In order to illustrate natural deduction in Isar, we shall
56 refer to the background theory and library of Isabelle/HOL. This
57 includes common notions of predicate logic, naive set-theory etc.\
58 using fairly standard mathematical notation. From the perspective
59 of generic natural deduction there is nothing special about the
60 logical connectives of HOL (@{text "\<and>"}, @{text "\<or>"}, @{text "\<forall>"},
61 @{text "\<exists>"}, etc.), only the resulting reasoning principles are
62 relevant to the user. There are similar rules available for
63 set-theory operators (@{text "\<inter>"}, @{text "\<union>"}, @{text "\<Inter>"}, @{text
64 "\<Union>"}, etc.), or any other theory developed in the library (lattice
65 theory, topology etc.).
67 Subsequently we briefly review fragments of Isar proof texts
68 corresponding directly to such general deduction schemes. The
69 examples shall refer to set-theory, to minimize the danger of
70 understanding connectives of predicate logic as something special.
72 \medskip The following deduction performs @{text "\<inter>"}-introduction,
73 working forwards from assumptions towards the conclusion. We give
74 both the Isar text, and depict the primitive rule involved, as
75 determined by unification of the problem against rules that are
76 declared in the library context.
79 text_raw {*\medskip\begin{minipage}{0.6\textwidth}*}
84 assume "x \<in> A" and "x \<in> B"
85 then have "x \<in> A \<inter> B" ..
90 text_raw {*\end{minipage}\begin{minipage}{0.4\textwidth}*}
93 \infer{@{prop "x \<in> A \<inter> B"}}{@{prop "x \<in> A"} & @{prop "x \<in> B"}}
96 text_raw {*\end{minipage}*}
99 \medskip\noindent Note that @{command assume} augments the proof
100 context, @{command then} indicates that the current fact shall be
101 used in the next step, and @{command have} states an intermediate
102 goal. The two dots ``@{command ".."}'' refer to a complete proof of
103 this claim, using the indicated facts and a canonical rule from the
104 context. We could have been more explicit here by spelling out the
105 final proof step via the @{command "by"} command:
111 assume "x \<in> A" and "x \<in> B"
112 then have "x \<in> A \<inter> B" by (rule IntI)
118 \noindent The format of the @{text "\<inter>"}-introduction rule represents
119 the most basic inference, which proceeds from given premises to a
120 conclusion, without any nested proof context involved.
122 The next example performs backwards introduction on @{term "\<Inter>\<A>"},
123 the intersection of all sets within a given set. This requires a
124 nested proof of set membership within a local context, where @{term
125 A} is an arbitrary-but-fixed member of the collection:
128 text_raw {*\medskip\begin{minipage}{0.6\textwidth}*}
133 have "x \<in> \<Inter>\<A>"
136 assume "A \<in> \<A>"
137 show "x \<in> A" sorry %noproof
143 text_raw {*\end{minipage}\begin{minipage}{0.4\textwidth}*}
146 \infer{@{prop "x \<in> \<Inter>\<A>"}}{\infer*{@{prop "x \<in> A"}}{@{text "[A][A \<in> \<A>]"}}}
149 text_raw {*\end{minipage}*}
152 \medskip\noindent This Isar reasoning pattern again refers to the
153 primitive rule depicted above. The system determines it in the
154 ``@{command proof}'' step, which could have been spelt out more
155 explicitly as ``@{command proof}~@{text "(rule InterI)"}''. Note
156 that the rule involves both a local parameter @{term "A"} and an
157 assumption @{prop "A \<in> \<A>"} in the nested reasoning. This kind of
158 compound rule typically demands a genuine sub-proof in Isar, working
159 backwards rather than forwards as seen before. In the proof body we
160 encounter the @{command fix}-@{command assume}-@{command show}
161 outline of nested sub-proofs that is typical for Isar. The final
162 @{command show} is like @{command have} followed by an additional
163 refinement of the enclosing claim, using the rule derived from the
166 \medskip The next example involves @{term "\<Union>\<A>"}, which can be
167 characterized as the set of all @{term "x"} such that @{prop "\<exists>A. x
168 \<in> A \<and> A \<in> \<A>"}. The elimination rule for @{prop "x \<in> \<Union>\<A>"} does
169 not mention @{text "\<exists>"} and @{text "\<and>"} at all, but admits to obtain
170 directly a local @{term "A"} such that @{prop "x \<in> A"} and @{prop "A
171 \<in> \<A>"} hold. This corresponds to the following Isar proof and
172 inference rule, respectively:
175 text_raw {*\medskip\begin{minipage}{0.6\textwidth}*}
180 assume "x \<in> \<Union>\<A>"
184 assume "x \<in> A" and "A \<in> \<A>"
185 show C sorry %noproof
191 text_raw {*\end{minipage}\begin{minipage}{0.4\textwidth}*}
194 \infer{@{prop "C"}}{@{prop "x \<in> \<Union>\<A>"} & \infer*{@{prop "C"}~}{@{text "[A][x \<in> A, A \<in> \<A>]"}}}
197 text_raw {*\end{minipage}*}
200 \medskip\noindent Although the Isar proof follows the natural
201 deduction rule closely, the text reads not as natural as
202 anticipated. There is a double occurrence of an arbitrary
203 conclusion @{prop "C"}, which represents the final result, but is
204 irrelevant for now. This issue arises for any elimination rule
205 involving local parameters. Isar provides the derived language
206 element @{command obtain}, which is able to perform the same
207 elimination proof more conveniently:
213 assume "x \<in> \<Union>\<A>"
214 then obtain A where "x \<in> A" and "A \<in> \<A>" ..
220 \noindent Here we avoid to mention the final conclusion @{prop "C"}
221 and return to plain forward reasoning. The rule involved in the
222 ``@{command ".."}'' proof is the same as before.
226 section {* The Pure framework \label{sec:framework-pure} *}
229 The Pure logic \cite{paulson-found,paulson700} is an intuitionistic
230 fragment of higher-order logic \cite{church40}. In type-theoretic
231 parlance, there are three levels of @{text "\<lambda>"}-calculus with
232 corresponding arrows @{text "\<Rightarrow>"}/@{text "\<And>"}/@{text "\<Longrightarrow>"}:
236 @{text "\<alpha> \<Rightarrow> \<beta>"} & syntactic function space (terms depending on terms) \\
237 @{text "\<And>x. B(x)"} & universal quantification (proofs depending on terms) \\
238 @{text "A \<Longrightarrow> B"} & implication (proofs depending on proofs) \\
242 \noindent Here only the types of syntactic terms, and the
243 propositions of proof terms have been shown. The @{text
244 "\<lambda>"}-structure of proofs can be recorded as an optional feature of
245 the Pure inference kernel \cite{Berghofer-Nipkow:2000:TPHOL}, but
246 the formal system can never depend on them due to \emph{proof
249 On top of this most primitive layer of proofs, Pure implements a
250 generic calculus for nested natural deduction rules, similar to
251 \cite{Schroeder-Heister:1984}. Here object-logic inferences are
252 internalized as formulae over @{text "\<And>"} and @{text "\<Longrightarrow>"}.
253 Combining such rule statements may involve higher-order unification
254 \cite{paulson-natural}.
258 subsection {* Primitive inferences *}
261 Term syntax provides explicit notation for abstraction @{text "\<lambda>x ::
262 \<alpha>. b(x)"} and application @{text "b a"}, while types are usually
263 implicit thanks to type-inference; terms of type @{text "prop"} are
264 called propositions. Logical statements are composed via @{text "\<And>x
265 :: \<alpha>. B(x)"} and @{text "A \<Longrightarrow> B"}. Primitive reasoning operates on
266 judgments of the form @{text "\<Gamma> \<turnstile> \<phi>"}, with standard introduction
267 and elimination rules for @{text "\<And>"} and @{text "\<Longrightarrow>"} that refer to
268 fixed parameters @{text "x\<^isub>1, \<dots>, x\<^isub>m"} and hypotheses
269 @{text "A\<^isub>1, \<dots>, A\<^isub>n"} from the context @{text "\<Gamma>"};
270 the corresponding proof terms are left implicit. The subsequent
271 inference rules define @{text "\<Gamma> \<turnstile> \<phi>"} inductively, relative to a
272 collection of axioms:
275 \infer{@{text "\<turnstile> A"}}{(@{text "A"} \text{~axiom})}
277 \infer{@{text "A \<turnstile> A"}}{}
281 \infer{@{text "\<Gamma> \<turnstile> \<And>x. B(x)"}}{@{text "\<Gamma> \<turnstile> B(x)"} & @{text "x \<notin> \<Gamma>"}}
283 \infer{@{text "\<Gamma> \<turnstile> B(a)"}}{@{text "\<Gamma> \<turnstile> \<And>x. B(x)"}}
287 \infer{@{text "\<Gamma> - A \<turnstile> A \<Longrightarrow> B"}}{@{text "\<Gamma> \<turnstile> B"}}
289 \infer{@{text "\<Gamma>\<^sub>1 \<union> \<Gamma>\<^sub>2 \<turnstile> B"}}{@{text "\<Gamma>\<^sub>1 \<turnstile> A \<Longrightarrow> B"} & @{text "\<Gamma>\<^sub>2 \<turnstile> A"}}
292 Furthermore, Pure provides a built-in equality @{text "\<equiv> :: \<alpha> \<Rightarrow> \<alpha> \<Rightarrow>
293 prop"} with axioms for reflexivity, substitution, extensionality,
294 and @{text "\<alpha>\<beta>\<eta>"}-conversion on @{text "\<lambda>"}-terms.
296 \medskip An object-logic introduces another layer on top of Pure,
297 e.g.\ with types @{text "i"} for individuals and @{text "o"} for
298 propositions, term constants @{text "Trueprop :: o \<Rightarrow> prop"} as
299 (implicit) derivability judgment and connectives like @{text "\<and> :: o
300 \<Rightarrow> o \<Rightarrow> o"} or @{text "\<forall> :: (i \<Rightarrow> o) \<Rightarrow> o"}, and axioms for object-level
301 rules such as @{text "conjI: A \<Longrightarrow> B \<Longrightarrow> A \<and> B"} or @{text "allI: (\<And>x. B
302 x) \<Longrightarrow> \<forall>x. B x"}. Derived object rules are represented as theorems of
303 Pure. After the initial object-logic setup, further axiomatizations
304 are usually avoided; plain definitions and derived principles are
309 subsection {* Reasoning with rules \label{sec:framework-resolution} *}
312 Primitive inferences mostly serve foundational purposes. The main
313 reasoning mechanisms of Pure operate on nested natural deduction
314 rules expressed as formulae, using @{text "\<And>"} to bind local
315 parameters and @{text "\<Longrightarrow>"} to express entailment. Multiple
316 parameters and premises are represented by repeating these
317 connectives in a right-associative manner.
319 Since @{text "\<And>"} and @{text "\<Longrightarrow>"} commute thanks to the theorem
320 @{prop "(A \<Longrightarrow> (\<And>x. B x)) \<equiv> (\<And>x. A \<Longrightarrow> B x)"}, we may assume w.l.o.g.\
321 that rule statements always observe the normal form where
322 quantifiers are pulled in front of implications at each level of
323 nesting. This means that any Pure proposition may be presented as a
324 \emph{Hereditary Harrop Formula} \cite{Miller:1991} which is of the
325 form @{text "\<And>x\<^isub>1 \<dots> x\<^isub>m. H\<^isub>1 \<Longrightarrow> \<dots> H\<^isub>n \<Longrightarrow>
326 A"} for @{text "m, n \<ge> 0"}, and @{text "A"} atomic, and @{text
327 "H\<^isub>1, \<dots>, H\<^isub>n"} being recursively of the same format.
328 Following the convention that outermost quantifiers are implicit,
329 Horn clauses @{text "A\<^isub>1 \<Longrightarrow> \<dots> A\<^isub>n \<Longrightarrow> A"} are a special
332 For example, @{text "\<inter>"}-introduction rule encountered before is
333 represented as a Pure theorem as follows:
335 @{text "IntI:"}~@{prop "x \<in> A \<Longrightarrow> x \<in> B \<Longrightarrow> x \<in> A \<inter> B"}
338 \noindent This is a plain Horn clause, since no further nesting on
339 the left is involved. The general @{text "\<Inter>"}-introduction
340 corresponds to a Hereditary Harrop Formula with one additional level
343 @{text "InterI:"}~@{prop "(\<And>A. A \<in> \<A> \<Longrightarrow> x \<in> A) \<Longrightarrow> x \<in> \<Inter>\<A>"}
346 \medskip Goals are also represented as rules: @{text "A\<^isub>1 \<Longrightarrow>
347 \<dots> A\<^isub>n \<Longrightarrow> C"} states that the sub-goals @{text "A\<^isub>1, \<dots>,
348 A\<^isub>n"} entail the result @{text "C"}; for @{text "n = 0"} the
349 goal is finished. To allow @{text "C"} being a rule statement
350 itself, we introduce the protective marker @{text "# :: prop \<Rightarrow>
351 prop"}, which is defined as identity and hidden from the user. We
352 initialize and finish goal states as follows:
355 \begin{array}{c@ {\qquad}c}
356 \infer[(@{inference_def init})]{@{text "C \<Longrightarrow> #C"}}{} &
357 \infer[(@{inference_def finish})]{@{text C}}{@{text "#C"}}
361 \noindent Goal states are refined in intermediate proof steps until
362 a finished form is achieved. Here the two main reasoning principles
363 are @{inference resolution}, for back-chaining a rule against a
364 sub-goal (replacing it by zero or more sub-goals), and @{inference
365 assumption}, for solving a sub-goal (finding a short-circuit with
366 local assumptions). Below @{text "\<^vec>x"} stands for @{text
367 "x\<^isub>1, \<dots>, x\<^isub>n"} (@{text "n \<ge> 0"}).
370 \infer[(@{inference_def resolution})]
371 {@{text "(\<And>\<^vec>x. \<^vec>H \<^vec>x \<Longrightarrow> \<^vec>A (\<^vec>a \<^vec>x))\<vartheta> \<Longrightarrow> C\<vartheta>"}}
374 @{text "\<^vec>A \<^vec>a \<Longrightarrow> B \<^vec>a"} \\
376 @{text "(\<And>\<^vec>x. \<^vec>H \<^vec>x \<Longrightarrow> B' \<^vec>x) \<Longrightarrow> C"} \\
377 @{text "goal unifier:"} &
378 @{text "(\<lambda>\<^vec>x. B (\<^vec>a \<^vec>x))\<vartheta> = B'\<vartheta>"} \\
385 \infer[(@{inference_def assumption})]{@{text "C\<vartheta>"}}
388 @{text "(\<And>\<^vec>x. \<^vec>H \<^vec>x \<Longrightarrow> A \<^vec>x) \<Longrightarrow> C"} \\
389 @{text "assm unifier:"} & @{text "A\<vartheta> = H\<^sub>i\<vartheta>"}~~\text{(for some~@{text "H\<^sub>i"})} \\
393 The following trace illustrates goal-oriented reasoning in
398 \begin{tabular}{r@ {\quad}l}
399 @{text "(A \<and> B \<Longrightarrow> B \<and> A) \<Longrightarrow> #(A \<and> B \<Longrightarrow> B \<and> A)"} & @{text "(init)"} \\
400 @{text "(A \<and> B \<Longrightarrow> B) \<Longrightarrow> (A \<and> B \<Longrightarrow> A) \<Longrightarrow> #\<dots>"} & @{text "(resolution B \<Longrightarrow> A \<Longrightarrow> B \<and> A)"} \\
401 @{text "(A \<and> B \<Longrightarrow> A \<and> B) \<Longrightarrow> (A \<and> B \<Longrightarrow> A) \<Longrightarrow> #\<dots>"} & @{text "(resolution A \<and> B \<Longrightarrow> B)"} \\
402 @{text "(A \<and> B \<Longrightarrow> A) \<Longrightarrow> #\<dots>"} & @{text "(assumption)"} \\
403 @{text "(A \<and> B \<Longrightarrow> B \<and> A) \<Longrightarrow> #\<dots>"} & @{text "(resolution A \<and> B \<Longrightarrow> A)"} \\
404 @{text "#\<dots>"} & @{text "(assumption)"} \\
405 @{text "A \<and> B \<Longrightarrow> B \<and> A"} & @{text "(finish)"} \\
410 Compositions of @{inference assumption} after @{inference
411 resolution} occurs quite often, typically in elimination steps.
412 Traditional Isabelle tactics accommodate this by a combined
413 @{inference_def elim_resolution} principle. In contrast, Isar uses
414 a slightly more refined combination, where the assumptions to be
415 closed are marked explicitly, using again the protective marker
419 \infer[(@{inference refinement})]
420 {@{text "(\<And>\<^vec>x. \<^vec>H \<^vec>x \<Longrightarrow> \<^vec>G' (\<^vec>a \<^vec>x))\<vartheta> \<Longrightarrow> C\<vartheta>"}}
422 @{text "sub\<dash>proof:"} &
423 @{text "\<^vec>G \<^vec>a \<Longrightarrow> B \<^vec>a"} \\
425 @{text "(\<And>\<^vec>x. \<^vec>H \<^vec>x \<Longrightarrow> B' \<^vec>x) \<Longrightarrow> C"} \\
426 @{text "goal unifier:"} &
427 @{text "(\<lambda>\<^vec>x. B (\<^vec>a \<^vec>x))\<vartheta> = B'\<vartheta>"} \\
428 @{text "assm unifiers:"} &
429 @{text "(\<lambda>\<^vec>x. G\<^sub>j (\<^vec>a \<^vec>x))\<vartheta> = #H\<^sub>i\<vartheta>"} \\
430 & \quad (for each marked @{text "G\<^sub>j"} some @{text "#H\<^sub>i"}) \\
434 \noindent Here the @{text "sub\<dash>proof"} rule stems from the
435 main @{command fix}-@{command assume}-@{command show} outline of
436 Isar (cf.\ \secref{sec:framework-subproof}): each assumption
437 indicated in the text results in a marked premise @{text "G"} above.
438 The marking enforces resolution against one of the sub-goal's
439 premises. Consequently, @{command fix}-@{command assume}-@{command
440 show} enables to fit the result of a sub-proof quite robustly into a
441 pending sub-goal, while maintaining a good measure of flexibility.
445 section {* The Isar proof language \label{sec:framework-isar} *}
448 Structured proofs are presented as high-level expressions for
449 composing entities of Pure (propositions, facts, and goals). The
450 Isar proof language allows to organize reasoning within the
451 underlying rule calculus of Pure, but Isar is not another logical
454 Isar is an exercise in sound minimalism. Approximately half of the
455 language is introduced as primitive, the rest defined as derived
456 concepts. The following grammar describes the core language
457 (category @{text "proof"}), which is embedded into theory
458 specification elements such as @{command theorem}; see also
459 \secref{sec:framework-stmt} for the separate category @{text
464 @{text "theory\<dash>stmt"} & = & @{command "theorem"}~@{text "statement proof |"}~~@{command "definition"}~@{text "\<dots> | \<dots>"} \\[1ex]
466 @{text "proof"} & = & @{text "prfx\<^sup>*"}~@{command "proof"}~@{text "method\<^sup>? stmt\<^sup>*"}~@{command "qed"}~@{text "method\<^sup>?"} \\[1ex]
468 @{text prfx} & = & @{command "using"}~@{text "facts"} \\
469 & @{text "|"} & @{command "unfolding"}~@{text "facts"} \\
471 @{text stmt} & = & @{command "{"}~@{text "stmt\<^sup>*"}~@{command "}"} \\
472 & @{text "|"} & @{command "next"} \\
473 & @{text "|"} & @{command "note"}~@{text "name = facts"} \\
474 & @{text "|"} & @{command "let"}~@{text "term = term"} \\
475 & @{text "|"} & @{command "fix"}~@{text "var\<^sup>+"} \\
476 & @{text "|"} & @{command assume}~@{text "\<guillemotleft>inference\<guillemotright> name: props"} \\
477 & @{text "|"} & @{command "then"}@{text "\<^sup>?"}~@{text goal} \\
478 @{text goal} & = & @{command "have"}~@{text "name: props proof"} \\
479 & @{text "|"} & @{command "show"}~@{text "name: props proof"} \\
482 \medskip Simultaneous propositions or facts may be separated by the
483 @{keyword "and"} keyword.
485 \medskip The syntax for terms and propositions is inherited from
486 Pure (and the object-logic). A @{text "pattern"} is a @{text
487 "term"} with schematic variables, to be bound by higher-order
490 \medskip Facts may be referenced by name or proposition. For
491 example, the result of ``@{command have}~@{text "a: A \<langle>proof\<rangle>"}''
492 becomes available both as @{text "a"} and
493 \isacharbackquoteopen@{text "A"}\isacharbackquoteclose. Moreover,
494 fact expressions may involve attributes that modify either the
495 theorem or the background context. For example, the expression
496 ``@{text "a [OF b]"}'' refers to the composition of two facts
497 according to the @{inference resolution} inference of
498 \secref{sec:framework-resolution}, while ``@{text "a [intro]"}''
499 declares a fact as introduction rule in the context.
501 The special fact called ``@{fact this}'' always refers to the last
502 result, as produced by @{command note}, @{command assume}, @{command
503 have}, or @{command show}. Since @{command note} occurs
504 frequently together with @{command then} we provide some
509 @{command from}~@{text a} & @{text "\<equiv>"} & @{command note}~@{text a}~@{command then} \\
510 @{command with}~@{text a} & @{text "\<equiv>"} & @{command from}~@{text "a \<AND> this"} \\
514 The @{text "method"} category is essentially a parameter and may be
515 populated later. Methods use the facts indicated by @{command
516 "then"} or @{command using}, and then operate on the goal state.
517 Some basic methods are predefined: ``@{method "-"}'' leaves the goal
518 unchanged, ``@{method this}'' applies the facts as rules to the
519 goal, ``@{method "rule"}'' applies the facts to another rule and the
520 result to the goal (both ``@{method this}'' and ``@{method rule}''
521 refer to @{inference resolution} of
522 \secref{sec:framework-resolution}). The secondary arguments to
523 ``@{method rule}'' may be specified explicitly as in ``@{text "(rule
524 a)"}'', or picked from the context. In the latter case, the system
525 first tries rules declared as @{attribute (Pure) elim} or
526 @{attribute (Pure) dest}, followed by those declared as @{attribute
529 The default method for @{command proof} is ``@{method rule}''
530 (arguments picked from the context), for @{command qed} it is
531 ``@{method "-"}''. Further abbreviations for terminal proof steps
532 are ``@{command "by"}~@{text "method\<^sub>1 method\<^sub>2"}'' for
533 ``@{command proof}~@{text "method\<^sub>1"}~@{command qed}~@{text
534 "method\<^sub>2"}'', and ``@{command ".."}'' for ``@{command
535 "by"}~@{method rule}, and ``@{command "."}'' for ``@{command
536 "by"}~@{method this}''. The @{command unfolding} element operates
537 directly on the current facts and goal by applying equalities.
539 \medskip Block structure can be indicated explicitly by ``@{command
540 "{"}~@{text "\<dots>"}~@{command "}"}'', although the body of a sub-proof
541 already involves implicit nesting. In any case, @{command next}
542 jumps into the next section of a block, i.e.\ it acts like closing
543 an implicit block scope and opening another one; there is no direct
544 correspondence to subgoals here.
546 The remaining elements @{command fix} and @{command assume} build up
547 a local context (see \secref{sec:framework-context}), while
548 @{command show} refines a pending sub-goal by the rule resulting
549 from a nested sub-proof (see \secref{sec:framework-subproof}).
550 Further derived concepts will support calculational reasoning (see
551 \secref{sec:framework-calc}).
555 subsection {* Context elements \label{sec:framework-context} *}
558 In judgments @{text "\<Gamma> \<turnstile> \<phi>"} of the primitive framework, @{text "\<Gamma>"}
559 essentially acts like a proof context. Isar elaborates this idea
560 towards a higher-level notion, with additional information for
561 type-inference, term abbreviations, local facts, hypotheses etc.
563 The element @{command fix}~@{text "x :: \<alpha>"} declares a local
564 parameter, i.e.\ an arbitrary-but-fixed entity of a given type; in
565 results exported from the context, @{text "x"} may become anything.
566 The @{command assume}~@{text "\<guillemotleft>inference\<guillemotright>"} element provides a
567 general interface to hypotheses: ``@{command assume}~@{text
568 "\<guillemotleft>inference\<guillemotright> A"}'' produces @{text "A \<turnstile> A"} locally, while the
569 included inference tells how to discharge @{text A} from results
570 @{text "A \<turnstile> B"} later on. There is no user-syntax for @{text
571 "\<guillemotleft>inference\<guillemotright>"}, i.e.\ it may only occur internally when derived
572 commands are defined in ML.
574 At the user-level, the default inference for @{command assume} is
575 @{inference discharge} as given below. The additional variants
576 @{command presume} and @{command def} are defined as follows:
580 @{command presume}~@{text A} & @{text "\<equiv>"} & @{command assume}~@{text "\<guillemotleft>weak\<dash>discharge\<guillemotright> A"} \\
581 @{command def}~@{text "x \<equiv> a"} & @{text "\<equiv>"} & @{command fix}~@{text x}~@{command assume}~@{text "\<guillemotleft>expansion\<guillemotright> x \<equiv> a"} \\
586 \infer[(@{inference_def discharge})]{@{text "\<strut>\<Gamma> - A \<turnstile> #A \<Longrightarrow> B"}}{@{text "\<strut>\<Gamma> \<turnstile> B"}}
589 \infer[(@{inference_def "weak\<dash>discharge"})]{@{text "\<strut>\<Gamma> - A \<turnstile> A \<Longrightarrow> B"}}{@{text "\<strut>\<Gamma> \<turnstile> B"}}
592 \infer[(@{inference_def expansion})]{@{text "\<strut>\<Gamma> - (x \<equiv> a) \<turnstile> B a"}}{@{text "\<strut>\<Gamma> \<turnstile> B x"}}
595 \medskip Note that @{inference discharge} and @{inference
596 "weak\<dash>discharge"} differ in the marker for @{prop A}, which is
597 relevant when the result of a @{command fix}-@{command
598 assume}-@{command show} outline is composed with a pending goal,
599 cf.\ \secref{sec:framework-subproof}.
601 The most interesting derived context element in Isar is @{command
602 obtain} \cite[\S5.3]{Wenzel-PhD}, which supports generalized
603 elimination steps in a purely forward manner. The @{command obtain}
604 command takes a specification of parameters @{text "\<^vec>x"} and
605 assumptions @{text "\<^vec>A"} to be added to the context, together
606 with a proof of a case rule stating that this extension is
607 conservative (i.e.\ may be removed from closed results later on):
611 @{text "\<langle>facts\<rangle>"}~~@{command obtain}~@{text "\<^vec>x \<WHERE> \<^vec>A \<^vec>x \<langle>proof\<rangle> \<equiv>"} \\[0.5ex]
612 \quad @{command have}~@{text "case: \<And>thesis. (\<And>\<^vec>x. \<^vec>A \<^vec>x \<Longrightarrow> thesis) \<Longrightarrow> thesis\<rangle>"} \\
613 \quad @{command proof}~@{method "-"} \\
614 \qquad @{command fix}~@{text thesis} \\
615 \qquad @{command assume}~@{text "[intro]: \<And>\<^vec>x. \<^vec>A \<^vec>x \<Longrightarrow> thesis"} \\
616 \qquad @{command show}~@{text thesis}~@{command using}~@{text "\<langle>facts\<rangle> \<langle>proof\<rangle>"} \\
617 \quad @{command qed} \\
618 \quad @{command fix}~@{text "\<^vec>x"}~@{command assume}~@{text "\<guillemotleft>elimination case\<guillemotright> \<^vec>A \<^vec>x"} \\
623 \infer[(@{inference elimination})]{@{text "\<Gamma> \<turnstile> B"}}{
626 @{text "\<Gamma> \<turnstile> \<And>thesis. (\<And>\<^vec>x. \<^vec>A \<^vec>x \<Longrightarrow> thesis) \<Longrightarrow> thesis"} \\[0.2ex]
628 @{text "\<Gamma> \<union> \<^vec>A \<^vec>y \<turnstile> B"} \\[0.2ex]
632 \noindent Here the name ``@{text thesis}'' is a specific convention
633 for an arbitrary-but-fixed proposition; in the primitive natural
634 deduction rules shown before we have occasionally used @{text C}.
635 The whole statement of ``@{command obtain}~@{text x}~@{keyword
636 "where"}~@{text "A x"}'' may be read as a claim that @{text "A x"}
637 may be assumed for some arbitrary-but-fixed @{text "x"}. Also note
638 that ``@{command obtain}~@{text "A \<AND> B"}'' without parameters
639 is similar to ``@{command have}~@{text "A \<AND> B"}'', but the
640 latter involves multiple sub-goals.
642 \medskip The subsequent Isar proof texts explain all context
643 elements introduced above using the formal proof language itself.
644 After finishing a local proof within a block, we indicate the
645 exported result via @{command note}.
652 txt_raw {* \begin{minipage}[t]{0.4\textwidth} *}
655 have "B x" sorry %noproof
658 txt_raw {* \end{minipage}\quad\begin{minipage}[t]{0.4\textwidth} *}(*<*)next(*>*)
661 have B sorry %noproof
663 note `A \<Longrightarrow> B`
664 txt_raw {* \end{minipage}\\[3ex]\begin{minipage}[t]{0.4\textwidth} *}(*<*)next(*>*)
667 have "B x" sorry %noproof
670 txt_raw {* \end{minipage}\quad\begin{minipage}[t]{0.4\textwidth} *}(*<*)next(*>*)
672 obtain x where "A x" sorry %noproof
673 have B sorry %noproof
676 txt_raw {* \end{minipage} *}
682 \bigskip\noindent This illustrates the meaning of Isar context
683 elements without goals getting in between.
686 subsection {* Structured statements \label{sec:framework-stmt} *}
689 The category @{text "statement"} of top-level theorem specifications
690 is defined as follows:
694 @{text "statement"} & @{text "\<equiv>"} & @{text "name: props \<AND> \<dots>"} \\
695 & @{text "|"} & @{text "context\<^sup>* conclusion"} \\[0.5ex]
697 @{text "context"} & @{text "\<equiv>"} & @{text "\<FIXES> vars \<AND> \<dots>"} \\
698 & @{text "|"} & @{text "\<ASSUMES> name: props \<AND> \<dots>"} \\
700 @{text "conclusion"} & @{text "\<equiv>"} & @{text "\<SHOWS> name: props \<AND> \<dots>"} \\
701 & @{text "|"} & @{text "\<OBTAINS> vars \<AND> \<dots> \<WHERE> name: props \<AND> \<dots>"} \\
702 & & \quad @{text "\<BBAR> \<dots>"} \\
705 \medskip\noindent A simple @{text "statement"} consists of named
706 propositions. The full form admits local context elements followed
707 by the actual conclusions, such as ``@{keyword "fixes"}~@{text
708 x}~@{keyword "assumes"}~@{text "A x"}~@{keyword "shows"}~@{text "B
709 x"}''. The final result emerges as a Pure rule after discharging
710 the context: @{prop "\<And>x. A x \<Longrightarrow> B x"}.
712 The @{keyword "obtains"} variant is another abbreviation defined
713 below; unlike @{command obtain} (cf.\
714 \secref{sec:framework-context}) there may be several ``cases''
715 separated by ``@{text "\<BBAR>"}'', each consisting of several
716 parameters (@{text "vars"}) and several premises (@{text "props"}).
717 This specifies multi-branch elimination rules.
721 @{text "\<OBTAINS> \<^vec>x \<WHERE> \<^vec>A \<^vec>x \<BBAR> \<dots> \<equiv>"} \\[0.5ex]
722 \quad @{text "\<FIXES> thesis"} \\
723 \quad @{text "\<ASSUMES> [intro]: \<And>\<^vec>x. \<^vec>A \<^vec>x \<Longrightarrow> thesis \<AND> \<dots>"} \\
724 \quad @{text "\<SHOWS> thesis"} \\
728 Presenting structured statements in such an ``open'' format usually
729 simplifies the subsequent proof, because the outer structure of the
730 problem is already laid out directly. E.g.\ consider the following
731 canonical patterns for @{text "\<SHOWS>"} and @{text "\<OBTAINS>"},
735 text_raw {*\begin{minipage}{0.5\textwidth}*}
739 assumes "A x" and "B y"
743 show "C x y" sorry %noproof
746 text_raw {*\end{minipage}\begin{minipage}{0.5\textwidth}*}
750 where "A x" and "B y"
752 have "A a" and "B b" sorry %noproof
756 text_raw {*\end{minipage}*}
759 \medskip\noindent Here local facts \isacharbackquoteopen@{text "A
760 x"}\isacharbackquoteclose\ and \isacharbackquoteopen@{text "B
761 y"}\isacharbackquoteclose\ are referenced immediately; there is no
762 need to decompose the logical rule structure again. In the second
763 proof the final ``@{command then}~@{command show}~@{text
764 thesis}~@{command ".."}'' involves the local rule case @{text "\<And>x
765 y. A x \<Longrightarrow> B y \<Longrightarrow> thesis"} for the particular instance of terms @{text
766 "a"} and @{text "b"} produced in the body.
770 subsection {* Structured proof refinement \label{sec:framework-subproof} *}
773 By breaking up the grammar for the Isar proof language, we may
774 understand a proof text as a linear sequence of individual proof
775 commands. These are interpreted as transitions of the Isar virtual
776 machine (Isar/VM), which operates on a block-structured
777 configuration in single steps. This allows users to write proof
778 texts in an incremental manner, and inspect intermediate
779 configurations for debugging.
781 The basic idea is analogous to evaluating algebraic expressions on a
782 stack machine: @{text "(a + b) \<cdot> c"} then corresponds to a sequence
783 of single transitions for each symbol @{text "(, a, +, b, ), \<cdot>, c"}.
784 In Isar the algebraic values are facts or goals, and the operations
787 \medskip The Isar/VM state maintains a stack of nodes, each node
788 contains the local proof context, the linguistic mode, and a pending
789 goal (optional). The mode determines the type of transition that
790 may be performed next, it essentially alternates between forward and
791 backward reasoning, with an intermediate stage for chained facts
792 (see \figref{fig:isar-vm}).
796 \includegraphics[width=0.8\textwidth]{Thy/document/isar-vm}
798 \caption{Isar/VM modes}\label{fig:isar-vm}
801 For example, in @{text "state"} mode Isar acts like a mathematical
802 scratch-pad, accepting declarations like @{command fix}, @{command
803 assume}, and claims like @{command have}, @{command show}. A goal
804 statement changes the mode to @{text "prove"}, which means that we
805 may now refine the problem via @{command unfolding} or @{command
806 proof}. Then we are again in @{text "state"} mode of a proof body,
807 which may issue @{command show} statements to solve pending
808 sub-goals. A concluding @{command qed} will return to the original
809 @{text "state"} mode one level upwards. The subsequent Isar/VM
810 trace indicates block structure, linguistic mode, goal state, and
814 text_raw {* \begingroup\footnotesize *}
817 txt_raw {* \begin{minipage}[t]{0.18\textwidth} *}
818 have "A \<longrightarrow> B"
824 txt_raw {* \end{minipage}\quad
825 \begin{minipage}[t]{0.06\textwidth}
833 \begin{minipage}[t]{0.08\textwidth}
840 \end{minipage}\begin{minipage}[t]{0.35\textwidth}
841 @{text "(A \<longrightarrow> B) \<Longrightarrow> #(A \<longrightarrow> B)"} \\
842 @{text "(A \<Longrightarrow> B) \<Longrightarrow> #(A \<longrightarrow> B)"} \\
845 @{text "#(A \<longrightarrow> B)"} \\
846 @{text "A \<longrightarrow> B"} \\
847 \end{minipage}\begin{minipage}[t]{0.4\textwidth}
849 @{text "(resolution impI)"} \\
852 @{text "(refinement #A \<Longrightarrow> B)"} \\
853 @{text "(finish)"} \\
858 text_raw {* \endgroup *}
861 \noindent Here the @{inference refinement} inference from
862 \secref{sec:framework-resolution} mediates composition of Isar
863 sub-proofs nicely. Observe that this principle incorporates some
864 degree of freedom in proof composition. In particular, the proof
865 body allows parameters and assumptions to be re-ordered, or commuted
866 according to Hereditary Harrop Form. Moreover, context elements
867 that are not used in a sub-proof may be omitted altogether. For
871 text_raw {*\begin{minipage}{0.5\textwidth}*}
876 have "\<And>x y. A x \<Longrightarrow> B y \<Longrightarrow> C x y"
879 assume "A x" and "B y"
880 show "C x y" sorry %noproof
883 txt_raw {*\end{minipage}\begin{minipage}{0.5\textwidth}*}
888 have "\<And>x y. A x \<Longrightarrow> B y \<Longrightarrow> C x y"
892 show "C x y" sorry %noproof
895 txt_raw {*\end{minipage}\\[3ex]\begin{minipage}{0.5\textwidth}*}
900 have "\<And>x y. A x \<Longrightarrow> B y \<Longrightarrow> C x y"
907 txt_raw {*\end{minipage}\begin{minipage}{0.5\textwidth}*}
911 have "\<And>x y. A x \<Longrightarrow> B y \<Longrightarrow> C x y"
921 text_raw {*\end{minipage}*}
924 \medskip\noindent Such ``peephole optimizations'' of Isar texts are
925 practically important to improve readability, by rearranging
926 contexts elements according to the natural flow of reasoning in the
927 body, while still observing the overall scoping rules.
929 \medskip This illustrates the basic idea of structured proof
930 processing in Isar. The main mechanisms are based on natural
931 deduction rule composition within the Pure framework. In
932 particular, there are no direct operations on goal states within the
933 proof body. Moreover, there is no hidden automated reasoning
934 involved, just plain unification.
938 subsection {* Calculational reasoning \label{sec:framework-calc} *}
941 The existing Isar infrastructure is sufficiently flexible to support
942 calculational reasoning (chains of transitivity steps) as derived
943 concept. The generic proof elements introduced below depend on
944 rules declared as @{attribute trans} in the context. It is left to
945 the object-logic to provide a suitable rule collection for mixed
946 relations of @{text "="}, @{text "<"}, @{text "\<le>"}, @{text "\<subset>"},
947 @{text "\<subseteq>"} etc. Due to the flexibility of rule composition
948 (\secref{sec:framework-resolution}), substitution of equals by
949 equals is covered as well, even substitution of inequalities
950 involving monotonicity conditions; see also \cite[\S6]{Wenzel-PhD}
951 and \cite{Bauer-Wenzel:2001}.
953 The generic calculational mechanism is based on the observation that
954 rules such as @{text "trans:"}~@{prop "x = y \<Longrightarrow> y = z \<Longrightarrow> x = z"}
955 proceed from the premises towards the conclusion in a deterministic
956 fashion. Thus we may reason in forward mode, feeding intermediate
957 results into rules selected from the context. The course of
958 reasoning is organized by maintaining a secondary fact called
959 ``@{fact calculation}'', apart from the primary ``@{fact this}''
960 already provided by the Isar primitives. In the definitions below,
961 @{attribute OF} refers to @{inference resolution}
962 (\secref{sec:framework-resolution}) with multiple rule arguments,
963 and @{text "trans"} represents to a suitable rule from the context:
965 \begin{matharray}{rcl}
966 @{command "also"}@{text "\<^sub>0"} & \equiv & @{command "note"}~@{text "calculation = this"} \\
967 @{command "also"}@{text "\<^sub>n\<^sub>+\<^sub>1"} & \equiv & @{command "note"}~@{text "calculation = trans [OF calculation this]"} \\[0.5ex]
968 @{command "finally"} & \equiv & @{command "also"}~@{command "from"}~@{text calculation} \\
971 \noindent The start of a calculation is determined implicitly in the
972 text: here @{command also} sets @{fact calculation} to the current
973 result; any subsequent occurrence will update @{fact calculation} by
974 combination with the next result and a transitivity rule. The
975 calculational sequence is concluded via @{command finally}, where
976 the final result is exposed for use in a concluding claim.
978 Here is a canonical proof pattern, using @{command have} to
979 establish the intermediate results:
986 also have "\<dots> = c" sorry
987 also have "\<dots> = d" sorry
988 finally have "a = d" .
994 \noindent The term ``@{text "\<dots>"}'' above is a special abbreviation
995 provided by the Isabelle/Isar syntax layer: it statically refers to
996 the right-hand side argument of the previous statement given in the
997 text. Thus it happens to coincide with relevant sub-expressions in
998 the calculational chain, but the exact correspondence is dependent
999 on the transitivity rules being involved.
1001 \medskip Symmetry rules such as @{prop "x = y \<Longrightarrow> y = x"} are like
1002 transitivities with only one premise. Isar maintains a separate
1003 rule collection declared via the @{attribute sym} attribute, to be
1004 used in fact expressions ``@{text "a [symmetric]"}'', or single-step
1005 proofs ``@{command assume}~@{text "x = y"}~@{command then}~@{command
1006 have}~@{text "y = x"}~@{command ".."}''.