7 chapter {* Basic language elements \label{ch:pure-syntax} *}
10 Subsequently, we introduce the main part of Pure theory and proof
11 commands, together with fundamental proof methods and attributes.
12 \Chref{ch:gen-tools} describes further Isar elements provided by
13 generic tools and packages (such as the Simplifier) that are either
14 part of Pure Isabelle or pre-installed in most object logics.
15 \Chref{ch:logics} refers to object-logic specific elements (mainly
18 \medskip Isar commands may be either \emph{proper} document
19 constructors, or \emph{improper commands}. Some proof methods and
20 attributes introduced later are classified as improper as well.
21 Improper Isar language elements, which are subsequently marked by
22 ``@{text "\<^sup>*"}'', are often helpful when developing proof
23 documents, while their use is discouraged for the final
24 human-readable outcome. Typical examples are diagnostic commands
25 that print terms or theorems according to the current context; other
26 commands emulate old-style tactical theorem proving.
30 section {* Theory commands *}
32 subsection {* Defining theories \label{sec:begin-thy} *}
35 \begin{matharray}{rcl}
36 @{command_def "header"} & : & \isarkeep{toplevel} \\
37 @{command_def "theory"} & : & \isartrans{toplevel}{theory} \\
38 @{command_def "end"} & : & \isartrans{theory}{toplevel} \\
41 Isabelle/Isar theories are defined via theory, which contain both
42 specifications and proofs; occasionally definitional mechanisms also
43 require some explicit proof.
45 The first ``real'' command of any theory has to be @{command
46 "theory"}, which starts a new theory based on the merge of existing
47 ones. Just preceding the @{command "theory"} keyword, there may be
48 an optional @{command "header"} declaration, which is relevant to
49 document preparation only; it acts very much like a special
50 pre-theory markup command (cf.\ \secref{sec:markup-thy} and
51 \secref{sec:markup-thy}). The @{command "end"} command concludes a
52 theory development; it has to be the very last command of any theory
53 file loaded in batch-mode.
58 'theory' name 'imports' (name +) uses? 'begin'
61 uses: 'uses' ((name | parname) +);
66 \item [@{command "header"}~@{text "text"}] provides plain text
67 markup just preceding the formal beginning of a theory. In actual
68 document preparation the corresponding {\LaTeX} macro @{verbatim
69 "\\isamarkupheader"} may be redefined to produce chapter or section
70 headings. See also \secref{sec:markup-thy} and
71 \secref{sec:markup-prf} for further markup commands.
73 \item [@{command "theory"}~@{text "A \<IMPORTS> B\<^sub>1 \<dots>
74 B\<^sub>n \<BEGIN>"}] starts a new theory @{text A} based on the
75 merge of existing theories @{text "B\<^sub>1 \<dots> B\<^sub>n"}.
77 Due to inclusion of several ancestors, the overall theory structure
78 emerging in an Isabelle session forms a directed acyclic graph
79 (DAG). Isabelle's theory loader ensures that the sources
80 contributing to the development graph are always up-to-date.
81 Changed files are automatically reloaded when processing theory
84 The optional @{keyword_def "uses"} specification declares additional
85 dependencies on extra files (usually ML sources). Files will be
86 loaded immediately (as ML), unless the name is put in parentheses,
87 which merely documents the dependency to be resolved later in the
88 text (typically via explicit @{command_ref "use"} in the body text,
91 \item [@{command "end"}] concludes the current theory definition or
98 subsection {* Markup commands \label{sec:markup-thy} *}
101 \begin{matharray}{rcl}
102 @{command_def "chapter"} & : & \isarkeep{local{\dsh}theory} \\
103 @{command_def "section"} & : & \isarkeep{local{\dsh}theory} \\
104 @{command_def "subsection"} & : & \isarkeep{local{\dsh}theory} \\
105 @{command_def "subsubsection"} & : & \isarkeep{local{\dsh}theory} \\
106 @{command_def "text"} & : & \isarkeep{local{\dsh}theory} \\
107 @{command_def "text_raw"} & : & \isarkeep{local{\dsh}theory} \\
110 Apart from formal comments (see \secref{sec:comments}), markup
111 commands provide a structured way to insert text into the document
112 generated from a theory (see \cite{isabelle-sys} for more
113 information on Isabelle's document preparation tools).
116 ('chapter' | 'section' | 'subsection' | 'subsubsection' | 'text') target? text
124 \item [@{command "chapter"}, @{command "section"}, @{command
125 "subsection"}, and @{command "subsubsection"}] mark chapter and
128 \item [@{command "text"}] specifies paragraphs of plain text.
130 \item [@{command "text_raw"}] inserts {\LaTeX} source into the
131 output, without additional markup. Thus the full range of document
132 manipulations becomes available.
136 The @{text "text"} argument of these markup commands (except for
137 @{command "text_raw"}) may contain references to formal entities
138 (``antiquotations'', see also \secref{sec:antiq}). These are
139 interpreted in the present theory context, or the named @{text
142 Any of these markup elements corresponds to a {\LaTeX} command with
143 the name prefixed by @{verbatim "\\isamarkup"}. For the sectioning
144 commands this is a plain macro with a single argument, e.g.\
145 @{verbatim "\\isamarkupchapter{"}@{text "\<dots>"}@{verbatim "}"} for
146 @{command "chapter"}. The @{command "text"} markup results in a
147 {\LaTeX} environment @{verbatim "\\begin{isamarkuptext}"}~@{text
148 "\<dots>"}~@{verbatim "\\end{isamarkuptext}"}, while @{command "text_raw"}
149 causes the text to be inserted directly into the {\LaTeX} source.
151 \medskip Additional markup commands are available for proofs (see
152 \secref{sec:markup-prf}). Also note that the @{command_ref
153 "header"} declaration (see \secref{sec:begin-thy}) admits to insert
154 section markup just preceding the actual theory definition.
158 subsection {* Type classes and sorts \label{sec:classes} *}
161 \begin{matharray}{rcll}
162 @{command_def "classes"} & : & \isartrans{theory}{theory} \\
163 @{command_def "classrel"} & : & \isartrans{theory}{theory} & (axiomatic!) \\
164 @{command_def "defaultsort"} & : & \isartrans{theory}{theory} \\
165 @{command_def "class_deps"} & : & \isarkeep{theory~|~proof} \\
169 'classes' (classdecl +)
171 'classrel' (nameref ('<' | subseteq) nameref + 'and')
179 \item [@{command "classes"}~@{text "c \<subseteq> c\<^sub>1, \<dots>, c\<^sub>n"}]
180 declares class @{text c} to be a subclass of existing classes @{text
181 "c\<^sub>1, \<dots>, c\<^sub>n"}. Cyclic class structures are not permitted.
183 \item [@{command "classrel"}~@{text "c\<^sub>1 \<subseteq> c\<^sub>2"}] states
184 subclass relations between existing classes @{text "c\<^sub>1"} and
185 @{text "c\<^sub>2"}. This is done axiomatically! The @{command_ref
186 "instance"} command (see \secref{sec:axclass}) provides a way to
187 introduce proven class relations.
189 \item [@{command "defaultsort"}~@{text s}] makes sort @{text s} the
190 new default sort for any type variables given without sort
191 constraints. Usually, the default sort would be only changed when
192 defining a new object-logic.
194 \item [@{command "class_deps"}] visualizes the subclass relation,
195 using Isabelle's graph browser tool (see also \cite{isabelle-sys}).
201 subsection {* Primitive types and type abbreviations \label{sec:types-pure} *}
204 \begin{matharray}{rcll}
205 @{command_def "types"} & : & \isartrans{theory}{theory} \\
206 @{command_def "typedecl"} & : & \isartrans{theory}{theory} \\
207 @{command_def "nonterminals"} & : & \isartrans{theory}{theory} \\
208 @{command_def "arities"} & : & \isartrans{theory}{theory} & (axiomatic!) \\
212 'types' (typespec '=' type infix? +)
214 'typedecl' typespec infix?
216 'nonterminals' (name +)
218 'arities' (nameref '::' arity +)
224 \item [@{command "types"}~@{text "(\<alpha>\<^sub>1, \<dots>, \<alpha>\<^sub>n) t = \<tau>"}]
225 introduces \emph{type synonym} @{text "(\<alpha>\<^sub>1, \<dots>, \<alpha>\<^sub>n) t"}
226 for existing type @{text "\<tau>"}. Unlike actual type definitions, as
227 are available in Isabelle/HOL for example, type synonyms are just
228 purely syntactic abbreviations without any logical significance.
229 Internally, type synonyms are fully expanded.
231 \item [@{command "typedecl"}~@{text "(\<alpha>\<^sub>1, \<dots>, \<alpha>\<^sub>n) t"}]
232 declares a new type constructor @{text t}, intended as an actual
233 logical type (of the object-logic, if available).
235 \item [@{command "nonterminals"}~@{text c}] declares type
236 constructors @{text c} (without arguments) to act as purely
237 syntactic types, i.e.\ nonterminal symbols of Isabelle's inner
238 syntax of terms or types.
240 \item [@{command "arities"}~@{text "t :: (s\<^sub>1, \<dots>, s\<^sub>n)
241 s"}] augments Isabelle's order-sorted signature of types by new type
242 constructor arities. This is done axiomatically! The @{command_ref
243 "instance"} command (see \S\ref{sec:axclass}) provides a way to
244 introduce proven type arities.
250 subsection {* Primitive constants and definitions \label{sec:consts} *}
253 Definitions essentially express abbreviations within the logic. The
254 simplest form of a definition is @{text "c :: \<sigma> \<equiv> t"}, where @{text
255 c} is a newly declared constant. Isabelle also allows derived forms
256 where the arguments of @{text c} appear on the left, abbreviating a
257 prefix of @{text \<lambda>}-abstractions, e.g.\ @{text "c \<equiv> \<lambda>x y. t"} may be
258 written more conveniently as @{text "c x y \<equiv> t"}. Moreover,
259 definitions may be weakened by adding arbitrary pre-conditions:
260 @{text "A \<Longrightarrow> c x y \<equiv> t"}.
262 \medskip The built-in well-formedness conditions for definitional
267 \item Arguments (on the left-hand side) must be distinct variables.
269 \item All variables on the right-hand side must also appear on the
272 \item All type variables on the right-hand side must also appear on
273 the left-hand side; this prohibits @{text "0 :: nat \<equiv> length ([] ::
274 \<alpha> list)"} for example.
276 \item The definition must not be recursive. Most object-logics
277 provide definitional principles that can be used to express
282 Overloading means that a constant being declared as @{text "c :: \<alpha>
283 decl"} may be defined separately on type instances @{text "c ::
284 (\<beta>\<^sub>1, \<dots>, \<beta>\<^sub>n) t decl"} for each type constructor @{text
285 t}. The right-hand side may mention overloaded constants
286 recursively at type instances corresponding to the immediate
287 argument types @{text "\<beta>\<^sub>1, \<dots>, \<beta>\<^sub>n"}. Incomplete
288 specification patterns impose global constraints on all occurrences,
289 e.g.\ @{text "d :: \<alpha> \<times> \<alpha>"} on the left-hand side means that all
290 corresponding occurrences on some right-hand side need to be an
291 instance of this, general @{text "d :: \<alpha> \<times> \<beta>"} will be disallowed.
293 \begin{matharray}{rcl}
294 @{command_def "consts"} & : & \isartrans{theory}{theory} \\
295 @{command_def "defs"} & : & \isartrans{theory}{theory} \\
296 @{command_def "constdefs"} & : & \isartrans{theory}{theory} \\
300 'consts' ((name '::' type mixfix?) +)
302 'defs' ('(' 'unchecked'? 'overloaded'? ')')? \\ (axmdecl prop +)
307 'constdefs' structs? (constdecl? constdef +)
310 structs: '(' 'structure' (vars + 'and') ')'
312 constdecl: ((name '::' type mixfix | name '::' type | name mixfix) 'where'?) | name 'where'
314 constdef: thmdecl? prop
320 \item [@{command "consts"}~@{text "c :: \<sigma>"}] declares constant
321 @{text c} to have any instance of type scheme @{text \<sigma>}. The
322 optional mixfix annotations may attach concrete syntax to the
325 \item [@{command "defs"}~@{text "name: eqn"}] introduces @{text eqn}
326 as a definitional axiom for some existing constant.
328 The @{text "(unchecked)"} option disables global dependency checks
329 for this definition, which is occasionally useful for exotic
330 overloading. It is at the discretion of the user to avoid malformed
331 theory specifications!
333 The @{text "(overloaded)"} option declares definitions to be
334 potentially overloaded. Unless this option is given, a warning
335 message would be issued for any definitional equation with a more
336 special type than that of the corresponding constant declaration.
338 \item [@{command "constdefs"}] provides a streamlined combination of
339 constants declarations and definitions: type-inference takes care of
340 the most general typing of the given specification (the optional
341 type constraint may refer to type-inference dummies ``@{verbatim
342 _}'' as usual). The resulting type declaration needs to agree with
343 that of the specification; overloading is \emph{not} supported here!
345 The constant name may be omitted altogether, if neither type nor
346 syntax declarations are given. The canonical name of the
347 definitional axiom for constant @{text c} will be @{text c_def},
348 unless specified otherwise. Also note that the given list of
349 specifications is processed in a strictly sequential manner, with
350 type-checking being performed independently.
352 An optional initial context of @{text "(structure)"} declarations
353 admits use of indexed syntax, using the special symbol @{verbatim
354 "\<index>"} (printed as ``@{text "\<index>"}''). The latter concept is
355 particularly useful with locales (see also \S\ref{sec:locale}).
361 subsection {* Syntax and translations \label{sec:syn-trans} *}
364 \begin{matharray}{rcl}
365 @{command_def "syntax"} & : & \isartrans{theory}{theory} \\
366 @{command_def "no_syntax"} & : & \isartrans{theory}{theory} \\
367 @{command_def "translations"} & : & \isartrans{theory}{theory} \\
368 @{command_def "no_translations"} & : & \isartrans{theory}{theory} \\
371 \railalias{rightleftharpoons}{\isasymrightleftharpoons}
372 \railterm{rightleftharpoons}
374 \railalias{rightharpoonup}{\isasymrightharpoonup}
375 \railterm{rightharpoonup}
377 \railalias{leftharpoondown}{\isasymleftharpoondown}
378 \railterm{leftharpoondown}
381 ('syntax' | 'no\_syntax') mode? (constdecl +)
383 ('translations' | 'no\_translations') (transpat ('==' | '=>' | '<=' | rightleftharpoons | rightharpoonup | leftharpoondown) transpat +)
386 mode: ('(' ( name | 'output' | name 'output' ) ')')
388 transpat: ('(' nameref ')')? string
394 \item [@{command "syntax"}~@{text "(mode) decls"}] is similar to
395 @{command "consts"}~@{text decls}, except that the actual logical
396 signature extension is omitted. Thus the context free grammar of
397 Isabelle's inner syntax may be augmented in arbitrary ways,
398 independently of the logic. The @{text mode} argument refers to the
399 print mode that the grammar rules belong; unless the @{keyword_ref
400 "output"} indicator is given, all productions are added both to the
401 input and output grammar.
403 \item [@{command "no_syntax"}~@{text "(mode) decls"}] removes
404 grammar declarations (and translations) resulting from @{text
405 decls}, which are interpreted in the same manner as for @{command
408 \item [@{command "translations"}~@{text rules}] specifies syntactic
409 translation rules (i.e.\ macros): parse~/ print rules (@{text "\<rightleftharpoons>"}),
410 parse rules (@{text "\<rightharpoonup>"}), or print rules (@{text "\<leftharpoondown>"}).
411 Translation patterns may be prefixed by the syntactic category to be
412 used for parsing; the default is @{text logic}.
414 \item [@{command "no_translations"}~@{text rules}] removes syntactic
415 translation rules, which are interpreted in the same manner as for
416 @{command "translations"} above.
422 subsection {* Axioms and theorems \label{sec:axms-thms} *}
425 \begin{matharray}{rcll}
426 @{command_def "axioms"} & : & \isartrans{theory}{theory} & (axiomatic!) \\
427 @{command_def "lemmas"} & : & \isarkeep{local{\dsh}theory} \\
428 @{command_def "theorems"} & : & isarkeep{local{\dsh}theory} \\
432 'axioms' (axmdecl prop +)
434 ('lemmas' | 'theorems') target? (thmdef? thmrefs + 'and')
440 \item [@{command "axioms"}~@{text "a: \<phi>"}] introduces arbitrary
441 statements as axioms of the meta-logic. In fact, axioms are
442 ``axiomatic theorems'', and may be referred later just as any other
445 Axioms are usually only introduced when declaring new logical
446 systems. Everyday work is typically done the hard way, with proper
447 definitions and proven theorems.
449 \item [@{command "lemmas"}~@{text "a = b\<^sub>1 \<dots> b\<^sub>n"}]
450 retrieves and stores existing facts in the theory context, or the
451 specified target context (see also \secref{sec:target}). Typical
452 applications would also involve attributes, to declare Simplifier
455 \item [@{command "theorems"}] is essentially the same as @{command
456 "lemmas"}, but marks the result as a different kind of facts.
462 subsection {* Name spaces *}
465 \begin{matharray}{rcl}
466 @{command_def "global"} & : & \isartrans{theory}{theory} \\
467 @{command_def "local"} & : & \isartrans{theory}{theory} \\
468 @{command_def "hide"} & : & \isartrans{theory}{theory} \\
472 'hide' ('(open)')? name (nameref + )
476 Isabelle organizes any kind of name declarations (of types,
477 constants, theorems etc.) by separate hierarchically structured name
478 spaces. Normally the user does not have to control the behavior of
479 name spaces by hand, yet the following commands provide some way to
484 \item [@{command "global"} and @{command "local"}] change the
485 current name declaration mode. Initially, theories start in
486 @{command "local"} mode, causing all names to be automatically
487 qualified by the theory name. Changing this to @{command "global"}
488 causes all names to be declared without the theory prefix, until
489 @{command "local"} is declared again.
491 Note that global names are prone to get hidden accidently later,
492 when qualified names of the same base name are introduced.
494 \item [@{command "hide"}~@{text "space names"}] fully removes
495 declarations from a given name space (which may be @{text "class"},
496 @{text "type"}, @{text "const"}, or @{text "fact"}); with the @{text
497 "(open)"} option, only the base name is hidden. Global
498 (unqualified) names may never be hidden.
500 Note that hiding name space accesses has no impact on logical
501 declarations -- they remain valid internally. Entities that are no
502 longer accessible to the user are printed with the special qualifier
503 ``@{text "??"}'' prefixed to the full internal name.
509 subsection {* Incorporating ML code \label{sec:ML} *}
512 \begin{matharray}{rcl}
513 @{command_def "use"} & : & \isarkeep{theory~|~local{\dsh}theory} \\
514 @{command_def "ML"} & : & \isarkeep{theory~|~local{\dsh}theory} \\
515 @{command_def "ML_val"} & : & \isartrans{\cdot}{\cdot} \\
516 @{command_def "ML_command"} & : & \isartrans{\cdot}{\cdot} \\
517 @{command_def "setup"} & : & \isartrans{theory}{theory} \\
518 @{command_def "method_setup"} & : & \isartrans{theory}{theory} \\
524 ('ML' | 'ML\_val' | 'ML\_command' | 'setup') text
526 'method\_setup' name '=' text text
532 \item [@{command "use"}~@{text "file"}] reads and executes ML
533 commands from @{text "file"}. The current theory context is passed
534 down to the ML toplevel and may be modified, using @{ML
535 "Context.>>"} or derived ML commands. The file name is checked with
536 the @{keyword_ref "uses"} dependency declaration given in the theory
537 header (see also \secref{sec:begin-thy}).
539 \item [@{command "ML"}~@{text "text"}] is similar to @{command
540 "use"}, but executes ML commands directly from the given @{text
543 \item [@{command "ML_val"} and @{command "ML_command"}] are
544 diagnostic versions of @{command "ML"}, which means that the context
545 may not be updated. @{command "ML_val"} echos the bindings produced
546 at the ML toplevel, but @{command "ML_command"} is silent.
548 \item [@{command "setup"}~@{text "text"}] changes the current theory
549 context by applying @{text "text"}, which refers to an ML expression
550 of type @{ML_type "theory -> theory"}. This enables to initialize
551 any object-logic specific tools and packages written in ML, for
554 \item [@{command "method_setup"}~@{text "name = text description"}]
555 defines a proof method in the current theory. The given @{text
556 "text"} has to be an ML expression of type @{ML_type "Args.src ->
557 Proof.context -> Proof.method"}. Parsing concrete method syntax
558 from @{ML_type Args.src} input can be quite tedious in general. The
559 following simple examples are for methods without any explicit
560 arguments, or a list of theorems, respectively.
562 %FIXME proper antiquotations
565 Method.no_args (Method.METHOD (fn facts => foobar_tac))
566 Method.thms_args (fn thms => Method.METHOD (fn facts => foobar_tac))
567 Method.ctxt_args (fn ctxt => Method.METHOD (fn facts => foobar_tac))
568 Method.thms_ctxt_args (fn thms => fn ctxt =>
569 Method.METHOD (fn facts => foobar_tac))
573 Note that mere tactic emulations may ignore the @{text facts}
574 parameter above. Proper proof methods would do something
575 appropriate with the list of current facts, though. Single-rule
576 methods usually do strict forward-chaining (e.g.\ by using @{ML
577 Drule.multi_resolves}), while automatic ones just insert the facts
578 using @{ML Method.insert_tac} before applying the main tactic.
584 subsection {* Syntax translation functions *}
587 \begin{matharray}{rcl}
588 @{command_def "parse_ast_translation"} & : & \isartrans{theory}{theory} \\
589 @{command_def "parse_translation"} & : & \isartrans{theory}{theory} \\
590 @{command_def "print_translation"} & : & \isartrans{theory}{theory} \\
591 @{command_def "typed_print_translation"} & : & \isartrans{theory}{theory} \\
592 @{command_def "print_ast_translation"} & : & \isartrans{theory}{theory} \\
593 @{command_def "token_translation"} & : & \isartrans{theory}{theory} \\
597 ( 'parse\_ast\_translation' | 'parse\_translation' | 'print\_translation' |
598 'typed\_print\_translation' | 'print\_ast\_translation' ) ('(advanced)')? text
601 'token\_translation' text
605 Syntax translation functions written in ML admit almost arbitrary
606 manipulations of Isabelle's inner syntax. Any of the above commands
607 have a single \railqtok{text} argument that refers to an ML
608 expression of appropriate type, which are as follows by default:
610 %FIXME proper antiquotations
612 val parse_ast_translation : (string * (ast list -> ast)) list
613 val parse_translation : (string * (term list -> term)) list
614 val print_translation : (string * (term list -> term)) list
615 val typed_print_translation :
616 (string * (bool -> typ -> term list -> term)) list
617 val print_ast_translation : (string * (ast list -> ast)) list
618 val token_translation :
619 (string * string * (string -> string * real)) list
622 If the @{text "(advanced)"} option is given, the corresponding
623 translation functions may depend on the current theory or proof
624 context. This allows to implement advanced syntax mechanisms, as
625 translations functions may refer to specific theory declarations or
626 auxiliary proof data.
628 See also \cite[\S8]{isabelle-ref} for more information on the
629 general concept of syntax transformations in Isabelle.
631 %FIXME proper antiquotations
633 val parse_ast_translation:
634 (string * (Context.generic -> ast list -> ast)) list
635 val parse_translation:
636 (string * (Context.generic -> term list -> term)) list
637 val print_translation:
638 (string * (Context.generic -> term list -> term)) list
639 val typed_print_translation:
640 (string * (Context.generic -> bool -> typ -> term list -> term)) list
641 val print_ast_translation:
642 (string * (Context.generic -> ast list -> ast)) list
647 subsection {* Oracles *}
650 \begin{matharray}{rcl}
651 @{command_def "oracle"} & : & \isartrans{theory}{theory} \\
654 The oracle interface promotes a given ML function @{ML_text
655 "theory -> T -> term"} to @{ML_text "theory -> T -> thm"}, for some type
656 @{ML_text T} given by the user. This acts like an infinitary
657 specification of axioms -- there is no internal check of the
658 correctness of the results! The inference kernel records oracle
659 invocations within the internal derivation object of theorems, and
660 the pretty printer attaches ``@{text "[!]"}'' to indicate results
661 that are not fully checked by Isabelle inferences.
664 'oracle' name '(' type ')' '=' text
670 \item [@{command "oracle"}~@{text "name (type) = text"}] turns the
671 given ML expression @{text "text"} of type @{ML_text "{theory
672 ->"}~@{text "type"}~@{ML_text "-> term"} into an ML function
673 @{ML_text name} of type @{ML_text "{theory ->"}~@{text
674 "type"}~@{ML_text "-> thm"}.
680 section {* Proof commands *}
683 Proof commands perform transitions of Isar/VM machine
684 configurations, which are block-structured, consisting of a stack of
685 nodes with three main components: logical proof context, current
686 facts, and open goals. Isar/VM transitions are \emph{typed}
687 according to the following three different modes of operation:
691 \item [@{text "proof(prove)"}] means that a new goal has just been
692 stated that is now to be \emph{proven}; the next command may refine
693 it by some proof method, and enter a sub-proof to establish the
696 \item [@{text "proof(state)"}] is like a nested theory mode: the
697 context may be augmented by \emph{stating} additional assumptions,
698 intermediate results etc.
700 \item [@{text "proof(chain)"}] is intermediate between @{text
701 "proof(state)"} and @{text "proof(prove)"}: existing facts (i.e.\
702 the contents of the special ``@{fact_ref this}'' register) have been
703 just picked up in order to be used when refining the goal claimed
708 The proof mode indicator may be read as a verb telling the writer
709 what kind of operation may be performed next. The corresponding
710 typings of proof commands restricts the shape of well-formed proof
711 texts to particular command sequences. So dynamic arrangements of
712 commands eventually turn out as static texts of a certain structure.
713 \Appref{ap:refcard} gives a simplified grammar of the overall
714 (extensible) language emerging that way.
718 subsection {* Markup commands \label{sec:markup-prf} *}
721 \begin{matharray}{rcl}
722 @{command_def "sect"} & : & \isartrans{proof}{proof} \\
723 @{command_def "subsect"} & : & \isartrans{proof}{proof} \\
724 @{command_def "subsubsect"} & : & \isartrans{proof}{proof} \\
725 @{command_def "txt"} & : & \isartrans{proof}{proof} \\
726 @{command_def "txt_raw"} & : & \isartrans{proof}{proof} \\
729 These markup commands for proof mode closely correspond to the ones
730 of theory mode (see \S\ref{sec:markup-thy}).
733 ('sect' | 'subsect' | 'subsubsect' | 'txt' | 'txt\_raw') text
739 subsection {* Context elements \label{sec:proof-context} *}
742 \begin{matharray}{rcl}
743 @{command_def "fix"} & : & \isartrans{proof(state)}{proof(state)} \\
744 @{command_def "assume"} & : & \isartrans{proof(state)}{proof(state)} \\
745 @{command_def "presume"} & : & \isartrans{proof(state)}{proof(state)} \\
746 @{command_def "def"} & : & \isartrans{proof(state)}{proof(state)} \\
749 The logical proof context consists of fixed variables and
750 assumptions. The former closely correspond to Skolem constants, or
751 meta-level universal quantification as provided by the Isabelle/Pure
752 logical framework. Introducing some \emph{arbitrary, but fixed}
753 variable via ``@{command "fix"}~@{text x} results in a local value
754 that may be used in the subsequent proof as any other variable or
755 constant. Furthermore, any result @{text "\<turnstile> \<phi>[x]"} exported from
756 the context will be universally closed wrt.\ @{text x} at the
757 outermost level: @{text "\<turnstile> \<And>x. \<phi>[x]"} (this is expressed in normal
758 form using Isabelle's meta-variables).
760 Similarly, introducing some assumption @{text \<chi>} has two effects.
761 On the one hand, a local theorem is created that may be used as a
762 fact in subsequent proof steps. On the other hand, any result
763 @{text "\<chi> \<turnstile> \<phi>"} exported from the context becomes conditional wrt.\
764 the assumption: @{text "\<turnstile> \<chi> \<Longrightarrow> \<phi>"}. Thus, solving an enclosing goal
765 using such a result would basically introduce a new subgoal stemming
766 from the assumption. How this situation is handled depends on the
767 version of assumption command used: while @{command "assume"}
768 insists on solving the subgoal by unification with some premise of
769 the goal, @{command "presume"} leaves the subgoal unchanged in order
770 to be proved later by the user.
772 Local definitions, introduced by ``@{command "def"}~@{text "x \<equiv>
773 t"}'', are achieved by combining ``@{command "fix"}~@{text x}'' with
774 another version of assumption that causes any hypothetical equation
775 @{text "x \<equiv> t"} to be eliminated by the reflexivity rule. Thus,
776 exporting some result @{text "x \<equiv> t \<turnstile> \<phi>[x]"} yields @{text "\<turnstile>
779 \railalias{equiv}{\isasymequiv}
785 ('assume' | 'presume') (props + 'and')
789 def: thmdecl? \\ name ('==' | equiv) term termpat?
795 \item [@{command "fix"}~@{text x}] introduces a local variable
796 @{text x} that is \emph{arbitrary, but fixed.}
798 \item [@{command "assume"}~@{text "a: \<phi>"} and @{command
799 "presume"}~@{text "a: \<phi>"}] introduce a local fact @{text "\<phi> \<turnstile> \<phi>"} by
800 assumption. Subsequent results applied to an enclosing goal (e.g.\
801 by @{command_ref "show"}) are handled as follows: @{command
802 "assume"} expects to be able to unify with existing premises in the
803 goal, while @{command "presume"} leaves @{text \<phi>} as new subgoals.
805 Several lists of assumptions may be given (separated by
806 @{keyword_ref "and"}; the resulting list of current facts consists
807 of all of these concatenated.
809 \item [@{command "def"}~@{text "x \<equiv> t"}] introduces a local
810 (non-polymorphic) definition. In results exported from the context,
811 @{text x} is replaced by @{text t}. Basically, ``@{command
812 "def"}~@{text "x \<equiv> t"}'' abbreviates ``@{command "fix"}~@{text
813 x}~@{command "assume"}~@{text "x \<equiv> t"}'', with the resulting
814 hypothetical equation solved by reflexivity.
816 The default name for the definitional equation is @{text x_def}.
817 Several simultaneous definitions may be given at the same time.
821 The special name @{fact_ref prems} refers to all assumptions of the
822 current context as a list of theorems. This feature should be used
823 with great care! It is better avoided in final proof texts.
827 subsection {* Facts and forward chaining *}
830 \begin{matharray}{rcl}
831 @{command_def "note"} & : & \isartrans{proof(state)}{proof(state)} \\
832 @{command_def "then"} & : & \isartrans{proof(state)}{proof(chain)} \\
833 @{command_def "from"} & : & \isartrans{proof(state)}{proof(chain)} \\
834 @{command_def "with"} & : & \isartrans{proof(state)}{proof(chain)} \\
835 @{command_def "using"} & : & \isartrans{proof(prove)}{proof(prove)} \\
836 @{command_def "unfolding"} & : & \isartrans{proof(prove)}{proof(prove)} \\
839 New facts are established either by assumption or proof of local
840 statements. Any fact will usually be involved in further proofs,
841 either as explicit arguments of proof methods, or when forward
842 chaining towards the next goal via @{command "then"} (and variants);
843 @{command "from"} and @{command "with"} are composite forms
844 involving @{command "note"}. The @{command "using"} elements
845 augments the collection of used facts \emph{after} a goal has been
846 stated. Note that the special theorem name @{fact_ref this} refers
847 to the most recently established facts, but only \emph{before}
848 issuing a follow-up claim.
851 'note' (thmdef? thmrefs + 'and')
853 ('from' | 'with' | 'using' | 'unfolding') (thmrefs + 'and')
859 \item [@{command "note"}~@{text "a = b\<^sub>1 \<dots> b\<^sub>n"}]
860 recalls existing facts @{text "b\<^sub>1, \<dots>, b\<^sub>n"}, binding
861 the result as @{text a}. Note that attributes may be involved as
862 well, both on the left and right hand sides.
864 \item [@{command "then"}] indicates forward chaining by the current
865 facts in order to establish the goal to be claimed next. The
866 initial proof method invoked to refine that will be offered the
867 facts to do ``anything appropriate'' (see also
868 \secref{sec:proof-steps}). For example, method @{method_ref rule}
869 (see \secref{sec:pure-meth-att}) would typically do an elimination
870 rather than an introduction. Automatic methods usually insert the
871 facts into the goal state before operation. This provides a simple
872 scheme to control relevance of facts in automated proof search.
874 \item [@{command "from"}~@{text b}] abbreviates ``@{command
875 "note"}~@{text b}~@{command "then"}''; thus @{command "then"} is
876 equivalent to ``@{command "from"}~@{text this}''.
878 \item [@{command "with"}~@{text "b\<^sub>1 \<dots> b\<^sub>n"}]
879 abbreviates ``@{command "from"}~@{text "b\<^sub>1 \<dots> b\<^sub>n \<AND>
880 this"}''; thus the forward chaining is from earlier facts together
881 with the current ones.
883 \item [@{command "using"}~@{text "b\<^sub>1 \<dots> b\<^sub>n"}] augments
884 the facts being currently indicated for use by a subsequent
885 refinement step (such as @{command_ref "apply"} or @{command_ref
888 \item [@{command "unfolding"}~@{text "b\<^sub>1 \<dots> b\<^sub>n"}] is
889 structurally similar to @{command "using"}, but unfolds definitional
890 equations @{text "b\<^sub>1, \<dots> b\<^sub>n"} throughout the goal state
895 Forward chaining with an empty list of theorems is the same as not
896 chaining at all. Thus ``@{command "from"}~@{text nothing}'' has no
897 effect apart from entering @{text "prove(chain)"} mode, since
898 @{fact_ref nothing} is bound to the empty list of theorems.
900 Basic proof methods (such as @{method_ref rule}) expect multiple
901 facts to be given in their proper order, corresponding to a prefix
902 of the premises of the rule involved. Note that positions may be
903 easily skipped using something like @{command "from"}~@{text "_
904 \<AND> a \<AND> b"}, for example. This involves the trivial rule
905 @{text "PROP \<psi> \<Longrightarrow> PROP \<psi>"}, which is bound in Isabelle/Pure as
906 ``@{fact_ref "_"}'' (underscore).
908 Automated methods (such as @{method simp} or @{method auto}) just
909 insert any given facts before their usual operation. Depending on
910 the kind of procedure involved, the order of facts is less
915 subsection {* Goal statements \label{sec:goals} *}
918 \begin{matharray}{rcl}
919 \isarcmd{lemma} & : & \isartrans{local{\dsh}theory}{proof(prove)} \\
920 \isarcmd{theorem} & : & \isartrans{local{\dsh}theory}{proof(prove)} \\
921 \isarcmd{corollary} & : & \isartrans{local{\dsh}theory}{proof(prove)} \\
922 \isarcmd{have} & : & \isartrans{proof(state) ~|~ proof(chain)}{proof(prove)} \\
923 \isarcmd{show} & : & \isartrans{proof(state) ~|~ proof(chain)}{proof(prove)} \\
924 \isarcmd{hence} & : & \isartrans{proof(state)}{proof(prove)} \\
925 \isarcmd{thus} & : & \isartrans{proof(state)}{proof(prove)} \\
926 \isarcmd{print_statement}^* & : & \isarkeep{theory~|~proof} \\
929 From a theory context, proof mode is entered by an initial goal
930 command such as @{command "lemma"}, @{command "theorem"}, or
931 @{command "corollary"}. Within a proof, new claims may be
932 introduced locally as well; four variants are available here to
933 indicate whether forward chaining of facts should be performed
934 initially (via @{command_ref "then"}), and whether the final result
935 is meant to solve some pending goal.
937 Goals may consist of multiple statements, resulting in a list of
938 facts eventually. A pending multi-goal is internally represented as
939 a meta-level conjunction (printed as @{text "&&"}), which is usually
940 split into the corresponding number of sub-goals prior to an initial
941 method application, via @{command_ref "proof"}
942 (\secref{sec:proof-steps}) or @{command_ref "apply"}
943 (\secref{sec:tactic-commands}). The @{method_ref induct} method
944 covered in \secref{sec:cases-induct} acts on multiple claims
947 Claims at the theory level may be either in short or long form. A
948 short goal merely consists of several simultaneous propositions
949 (often just one). A long goal includes an explicit context
950 specification for the subsequent conclusion, involving local
951 parameters and assumptions. Here the role of each part of the
952 statement is explicitly marked by separate keywords (see also
953 \secref{sec:locale}); the local assumptions being introduced here
954 are available as @{fact_ref assms} in the proof. Moreover, there
955 are two kinds of conclusions: @{element_def "shows"} states several
956 simultaneous propositions (essentially a big conjunction), while
957 @{element_def "obtains"} claims several simultaneous simultaneous
958 contexts of (essentially a big disjunction of eliminated parameters
959 and assumptions, cf.\ \secref{sec:obtain}).
962 ('lemma' | 'theorem' | 'corollary') target? (goal | longgoal)
964 ('have' | 'show' | 'hence' | 'thus') goal
966 'print\_statement' modes? thmrefs
969 goal: (props + 'and')
971 longgoal: thmdecl? (contextelem *) conclusion
973 conclusion: 'shows' goal | 'obtains' (parname? case + '|')
975 case: (vars + 'and') 'where' (props + 'and')
981 \item [@{command "lemma"}~@{text "a: \<phi>"}] enters proof mode with
982 @{text \<phi>} as main goal, eventually resulting in some fact @{text "\<turnstile>
983 \<phi>"} to be put back into the target context. An additional
984 \railnonterm{context} specification may build up an initial proof
985 context for the subsequent claim; this includes local definitions
986 and syntax as well, see the definition of @{syntax contextelem} in
989 \item [@{command "theorem"}~@{text "a: \<phi>"} and @{command
990 "corollary"}~@{text "a: \<phi>"}] are essentially the same as @{command
991 "lemma"}~@{text "a: \<phi>"}, but the facts are internally marked as
992 being of a different kind. This discrimination acts like a formal
995 \item [@{command "have"}~@{text "a: \<phi>"}] claims a local goal,
996 eventually resulting in a fact within the current logical context.
997 This operation is completely independent of any pending sub-goals of
998 an enclosing goal statements, so @{command "have"} may be freely
999 used for experimental exploration of potential results within a
1002 \item [@{command "show"}~@{text "a: \<phi>"}] is like @{command
1003 "have"}~@{text "a: \<phi>"} plus a second stage to refine some pending
1004 sub-goal for each one of the finished result, after having been
1005 exported into the corresponding context (at the head of the
1006 sub-proof of this @{command "show"} command).
1008 To accommodate interactive debugging, resulting rules are printed
1009 before being applied internally. Even more, interactive execution
1010 of @{command "show"} predicts potential failure and displays the
1011 resulting error as a warning beforehand. Watch out for the
1014 %FIXME proper antiquitation
1016 Problem! Local statement will fail to solve any pending goal
1019 \item [@{command "hence"}] abbreviates ``@{command "then"}~@{command
1020 "have"}'', i.e.\ claims a local goal to be proven by forward
1021 chaining the current facts. Note that @{command "hence"} is also
1022 equivalent to ``@{command "from"}~@{text this}~@{command "have"}''.
1024 \item [@{command "thus"}] abbreviates ``@{command "then"}~@{command
1025 "show"}''. Note that @{command "thus"} is also equivalent to
1026 ``@{command "from"}~@{text this}~@{command "show"}''.
1028 \item [@{command "print_statement"}~@{text a}] prints facts from the
1029 current theory or proof context in long statement form, according to
1030 the syntax for @{command "lemma"} given above.
1034 Any goal statement causes some term abbreviations (such as
1035 @{variable_ref "?thesis"}) to be bound automatically, see also
1036 \secref{sec:term-abbrev}. Furthermore, the local context of a
1037 (non-atomic) goal is provided via the @{case_ref rule_context} case.
1039 The optional case names of @{element_ref "obtains"} have a twofold
1040 meaning: (1) during the of this claim they refer to the the local
1041 context introductions, (2) the resulting rule is annotated
1042 accordingly to support symbolic case splits when used with the
1043 @{method_ref cases} method (cf. \secref{sec:cases-induct}).
1048 Isabelle/Isar suffers theory-level goal statements to contain
1049 \emph{unbound schematic variables}, although this does not conform
1050 to the aim of human-readable proof documents! The main problem
1051 with schematic goals is that the actual outcome is usually hard to
1052 predict, depending on the behavior of the proof methods applied
1053 during the course of reasoning. Note that most semi-automated
1054 methods heavily depend on several kinds of implicit rule
1055 declarations within the current theory context. As this would
1056 also result in non-compositional checking of sub-proofs,
1057 \emph{local goals} are not allowed to be schematic at all.
1058 Nevertheless, schematic goals do have their use in Prolog-style
1059 interactive synthesis of proven results, usually by stepwise
1060 refinement via emulation of traditional Isabelle tactic scripts
1061 (see also \secref{sec:tactic-commands}). In any case, users
1062 should know what they are doing.
1067 subsection {* Initial and terminal proof steps \label{sec:proof-steps} *}
1070 \begin{matharray}{rcl}
1071 @{command_def "proof"} & : & \isartrans{proof(prove)}{proof(state)} \\
1072 @{command_def "qed"} & : & \isartrans{proof(state)}{proof(state) ~|~ theory} \\
1073 @{command_def "by"} & : & \isartrans{proof(prove)}{proof(state) ~|~ theory} \\
1074 @{command_def ".."} & : & \isartrans{proof(prove)}{proof(state) ~|~ theory} \\
1075 @{command_def "."} & : & \isartrans{proof(prove)}{proof(state) ~|~ theory} \\
1076 @{command_def "sorry"} & : & \isartrans{proof(prove)}{proof(state) ~|~ theory} \\
1079 Arbitrary goal refinement via tactics is considered harmful.
1080 Structured proof composition in Isar admits proof methods to be
1081 invoked in two places only.
1085 \item An \emph{initial} refinement step @{command_ref
1086 "proof"}~@{text "m\<^sub>1"} reduces a newly stated goal to a number
1087 of sub-goals that are to be solved later. Facts are passed to
1088 @{text "m\<^sub>1"} for forward chaining, if so indicated by @{text
1089 "proof(chain)"} mode.
1091 \item A \emph{terminal} conclusion step @{command_ref "qed"}~@{text
1092 "m\<^sub>2"} is intended to solve remaining goals. No facts are
1093 passed to @{text "m\<^sub>2"}.
1097 The only other (proper) way to affect pending goals in a proof body
1098 is by @{command_ref "show"}, which involves an explicit statement of
1099 what is to be solved eventually. Thus we avoid the fundamental
1100 problem of unstructured tactic scripts that consist of numerous
1101 consecutive goal transformations, with invisible effects.
1103 \medskip As a general rule of thumb for good proof style, initial
1104 proof methods should either solve the goal completely, or constitute
1105 some well-understood reduction to new sub-goals. Arbitrary
1106 automatic proof tools that are prone leave a large number of badly
1107 structured sub-goals are no help in continuing the proof document in
1108 an intelligible manner.
1110 Unless given explicitly by the user, the default initial method is
1111 ``@{method_ref rule}'', which applies a single standard elimination
1112 or introduction rule according to the topmost symbol involved.
1113 There is no separate default terminal method. Any remaining goals
1114 are always solved by assumption in the very last step.
1123 ('.' | '..' | 'sorry')
1129 \item [@{command "proof"}~@{text "m\<^sub>1"}] refines the goal by
1130 proof method @{text "m\<^sub>1"}; facts for forward chaining are
1131 passed if so indicated by @{text "proof(chain)"} mode.
1133 \item [@{command "qed"}~@{text "m\<^sub>2"}] refines any remaining
1134 goals by proof method @{text "m\<^sub>2"} and concludes the
1135 sub-proof by assumption. If the goal had been @{text "show"} (or
1136 @{text "thus"}), some pending sub-goal is solved as well by the rule
1137 resulting from the result \emph{exported} into the enclosing goal
1138 context. Thus @{text "qed"} may fail for two reasons: either @{text
1139 "m\<^sub>2"} fails, or the resulting rule does not fit to any
1140 pending goal\footnote{This includes any additional ``strong''
1141 assumptions as introduced by @{text "assume"}.} of the enclosing
1142 context. Debugging such a situation might involve temporarily
1143 changing @{command "show"} into @{command "have"}, or weakening the
1144 local context by replacing occurrences of @{command "assume"} by
1145 @{command "presume"}.
1147 \item [@{command "by"}~@{text "m\<^sub>1 m\<^sub>2"}] is a
1148 \emph{terminal proof}\index{proof!terminal}; it abbreviates
1149 @{command "proof"}~@{text "m\<^sub>1"}~@{text "qed"}~@{text
1150 "m\<^sub>2"}, but with backtracking across both methods. Debugging
1151 an unsuccessful @{command "by"}~@{text "m\<^sub>1 m\<^sub>2"}
1152 command can be done by expanding its definition; in many cases
1153 @{command "proof"}~@{text "m\<^sub>1"} (or even @{text
1154 "apply"}~@{text "m\<^sub>1"}) is already sufficient to see the
1157 \item [``@{command ".."}''] is a \emph{default
1158 proof}\index{proof!default}; it abbreviates @{command "by"}~@{text
1161 \item [``@{command "."}''] is a \emph{trivial
1162 proof}\index{proof!trivial}; it abbreviates @{command "by"}~@{text
1165 \item [@{command "sorry"}] is a \emph{fake proof}\index{proof!fake}
1166 pretending to solve the pending claim without further ado. This
1167 only works in interactive development, or if the @{ML
1168 quick_and_dirty} flag is enabled (in ML). Facts emerging from fake
1169 proofs are not the real thing. Internally, each theorem container
1170 is tainted by an oracle invocation, which is indicated as ``@{text
1171 "[!]"}'' in the printed result.
1173 The most important application of @{command "sorry"} is to support
1174 experimentation and top-down proof development.
1180 subsection {* Fundamental methods and attributes \label{sec:pure-meth-att} *}
1183 The following proof methods and attributes refer to basic logical
1184 operations of Isar. Further methods and attributes are provided by
1185 several generic and object-logic specific tools and packages (see
1186 \chref{ch:gen-tools} and \chref{ch:logics}).
1188 \begin{matharray}{rcl}
1189 @{method_def "-"} & : & \isarmeth \\
1190 @{method_def "fact"} & : & \isarmeth \\
1191 @{method_def "assumption"} & : & \isarmeth \\
1192 @{method_def "this"} & : & \isarmeth \\
1193 @{method_def "rule"} & : & \isarmeth \\
1194 @{method_def "iprover"} & : & \isarmeth \\[0.5ex]
1195 @{attribute_def "intro"} & : & \isaratt \\
1196 @{attribute_def "elim"} & : & \isaratt \\
1197 @{attribute_def "dest"} & : & \isaratt \\
1198 @{attribute_def "rule"} & : & \isaratt \\[0.5ex]
1199 @{attribute_def "OF"} & : & \isaratt \\
1200 @{attribute_def "of"} & : & \isaratt \\
1201 @{attribute_def "where"} & : & \isaratt \\
1209 'iprover' ('!' ?) (rulemod *)
1211 rulemod: ('intro' | 'elim' | 'dest') ((('!' | () | '?') nat?) | 'del') ':' thmrefs
1213 ('intro' | 'elim' | 'dest') ('!' | () | '?') nat?
1219 'of' insts ('concl' ':' insts)?
1221 'where' ((name | var | typefree | typevar) '=' (type | term) * 'and')
1227 \item [``@{method "-"}''] does nothing but insert the forward
1228 chaining facts as premises into the goal. Note that command
1229 @{command_ref "proof"} without any method actually performs a single
1230 reduction step using the @{method_ref rule} method; thus a plain
1231 \emph{do-nothing} proof step would be ``@{command "proof"}~@{text
1232 "-"}'' rather than @{command "proof"} alone.
1234 \item [@{method "fact"}~@{text "a\<^sub>1 \<dots> a\<^sub>n"}] composes
1235 some fact from @{text "a\<^sub>1, \<dots>, a\<^sub>n"} (or implicitly from
1236 the current proof context) modulo unification of schematic type and
1237 term variables. The rule structure is not taken into account, i.e.\
1238 meta-level implication is considered atomic. This is the same
1239 principle underlying literal facts (cf.\ \secref{sec:syn-att}):
1240 ``@{command "have"}~@{text "\<phi>"}~@{command "by"}~@{text fact}'' is
1241 equivalent to ``@{command "note"}~@{verbatim "`"}@{text \<phi>}@{verbatim
1242 "`"}'' provided that @{text "\<turnstile> \<phi>"} is an instance of some known
1243 @{text "\<turnstile> \<phi>"} in the proof context.
1245 \item [@{method assumption}] solves some goal by a single assumption
1246 step. All given facts are guaranteed to participate in the
1247 refinement; this means there may be only 0 or 1 in the first place.
1248 Recall that @{command "qed"} (\secref{sec:proof-steps}) already
1249 concludes any remaining sub-goals by assumption, so structured
1250 proofs usually need not quote the @{method assumption} method at
1253 \item [@{method this}] applies all of the current facts directly as
1254 rules. Recall that ``@{command "."}'' (dot) abbreviates ``@{command
1255 "by"}~@{text this}''.
1257 \item [@{method rule}~@{text "a\<^sub>1 \<dots> a\<^sub>n"}] applies some
1258 rule given as argument in backward manner; facts are used to reduce
1259 the rule before applying it to the goal. Thus @{method rule}
1260 without facts is plain introduction, while with facts it becomes
1263 When no arguments are given, the @{method rule} method tries to pick
1264 appropriate rules automatically, as declared in the current context
1265 using the @{attribute intro}, @{attribute elim}, @{attribute dest}
1266 attributes (see below). This is the default behavior of @{command
1267 "proof"} and ``@{command ".."}'' (double-dot) steps (see
1268 \secref{sec:proof-steps}).
1270 \item [@{method iprover}] performs intuitionistic proof search,
1271 depending on specifically declared rules from the context, or given
1272 as explicit arguments. Chained facts are inserted into the goal
1273 before commencing proof search; ``@{method iprover}@{text "!"}''
1274 means to include the current @{fact prems} as well.
1276 Rules need to be classified as @{attribute intro}, @{attribute
1277 elim}, or @{attribute dest}; here the ``@{text "!"} indicator refers
1278 to ``safe'' rules, which may be applied aggressively (without
1279 considering back-tracking later). Rules declared with ``@{text
1280 "?"}'' are ignored in proof search (the single-step @{method rule}
1281 method still observes these). An explicit weight annotation may be
1282 given as well; otherwise the number of rule premises will be taken
1285 \item [@{attribute intro}, @{attribute elim}, and @{attribute dest}]
1286 declare introduction, elimination, and destruct rules, to be used
1287 with the @{method rule} and @{method iprover} methods. Note that
1288 the latter will ignore rules declared with ``@{text "?"}'', while
1289 ``@{text "!"}'' are used most aggressively.
1291 The classical reasoner (see \secref{sec:classical}) introduces its
1292 own variants of these attributes; use qualified names to access the
1293 present versions of Isabelle/Pure, i.e.\ @{attribute "Pure.intro"}.
1295 \item [@{attribute rule}~@{text del}] undeclares introduction,
1296 elimination, or destruct rules.
1298 \item [@{attribute OF}~@{text "a\<^sub>1 \<dots> a\<^sub>n"}] applies some
1299 theorem to all of the given rules @{text "a\<^sub>1, \<dots>, a\<^sub>n"}
1300 (in parallel). This corresponds to the @{ML "op MRS"} operation in
1301 ML, but note the reversed order. Positions may be effectively
1302 skipped by including ``@{verbatim _}'' (underscore) as argument.
1304 \item [@{attribute of}~@{text "t\<^sub>1 \<dots> t\<^sub>n"}] performs
1305 positional instantiation of term variables. The terms @{text
1306 "t\<^sub>1, \<dots>, t\<^sub>n"} are substituted for any schematic
1307 variables occurring in a theorem from left to right; ``@{verbatim
1308 _}'' (underscore) indicates to skip a position. Arguments following
1309 a ``@{keyword "concl"}@{text ":"}'' specification refer to positions
1310 of the conclusion of a rule.
1312 \item [@{attribute "where"}~@{text "x\<^sub>1 = t\<^sub>1 \<AND> \<dots>
1313 \<AND> x\<^sub>n = t\<^sub>n"}] performs named instantiation of
1314 schematic type and term variables occurring in a theorem. Schematic
1315 variables have to be specified on the left-hand side (e.g.\ @{text
1316 "?x1.3"}). The question mark may be omitted if the variable name is
1317 a plain identifier without index. As type instantiations are
1318 inferred from term instantiations, explicit type instantiations are
1325 subsection {* Term abbreviations \label{sec:term-abbrev} *}
1328 \begin{matharray}{rcl}
1329 @{command_def "let"} & : & \isartrans{proof(state)}{proof(state)} \\
1330 @{keyword_def "is"} & : & syntax \\
1333 Abbreviations may be either bound by explicit @{command "let"}@{text
1334 "p \<equiv> t"} statements, or by annotating assumptions or goal statements
1335 with a list of patterns ``@{text "\<IS> p\<^sub>1 \<dots> p\<^sub>n"}''.
1336 In both cases, higher-order matching is invoked to bind
1337 extra-logical term variables, which may be either named schematic
1338 variables of the form @{text ?x}, or nameless dummies ``@{variable
1339 _}'' (underscore). Note that in the @{command "let"} form the
1340 patterns occur on the left-hand side, while the @{keyword "is"}
1341 patterns are in postfix position.
1343 Polymorphism of term bindings is handled in Hindley-Milner style,
1344 similar to ML. Type variables referring to local assumptions or
1345 open goal statements are \emph{fixed}, while those of finished
1346 results or bound by @{command "let"} may occur in \emph{arbitrary}
1347 instances later. Even though actual polymorphism should be rarely
1348 used in practice, this mechanism is essential to achieve proper
1349 incremental type-inference, as the user proceeds to build up the
1350 Isar proof text from left to right.
1352 \medskip Term abbreviations are quite different from local
1353 definitions as introduced via @{command "def"} (see
1354 \secref{sec:proof-context}). The latter are visible within the
1355 logic as actual equations, while abbreviations disappear during the
1356 input process just after type checking. Also note that @{command
1357 "def"} does not support polymorphism.
1360 'let' ((term + 'and') '=' term + 'and')
1364 The syntax of @{keyword "is"} patterns follows \railnonterm{termpat}
1365 or \railnonterm{proppat} (see \secref{sec:term-decls}).
1369 \item [@{command "let"}~@{text "p\<^sub>1 = t\<^sub>1 \<AND>
1370 \<dots>p\<^sub>n = t\<^sub>n"}] binds any text variables in patterns
1371 @{text "p\<^sub>1, \<dots>, p\<^sub>n"} by simultaneous higher-order
1372 matching against terms @{text "t\<^sub>1, \<dots>, t\<^sub>n"}.
1374 \item [@{text "(\<IS> p\<^sub>1 \<dots> p\<^sub>n)"}] resembles @{command
1375 "let"}, but matches @{text "p\<^sub>1, \<dots>, p\<^sub>n"} against the
1376 preceding statement. Also note that @{keyword "is"} is not a
1377 separate command, but part of others (such as @{command "assume"},
1378 @{command "have"} etc.).
1382 Some \emph{implicit} term abbreviations\index{term abbreviations}
1383 for goals and facts are available as well. For any open goal,
1384 @{variable_ref thesis} refers to its object-level statement,
1385 abstracted over any meta-level parameters (if present). Likewise,
1386 @{variable_ref this} is bound for fact statements resulting from
1387 assumptions or finished goals. In case @{variable this} refers to
1388 an object-logic statement that is an application @{text "f t"}, then
1389 @{text t} is bound to the special text variable ``@{variable "\<dots>"}''
1390 (three dots). The canonical application of this convenience are
1391 calculational proofs (see \secref{sec:calculation}).
1395 subsection {* Block structure *}
1398 \begin{matharray}{rcl}
1399 @{command_def "next"} & : & \isartrans{proof(state)}{proof(state)} \\
1400 @{command_def "{"} & : & \isartrans{proof(state)}{proof(state)} \\
1401 @{command_def "}"} & : & \isartrans{proof(state)}{proof(state)} \\
1404 While Isar is inherently block-structured, opening and closing
1405 blocks is mostly handled rather casually, with little explicit
1406 user-intervention. Any local goal statement automatically opens
1407 \emph{two} internal blocks, which are closed again when concluding
1408 the sub-proof (by @{command "qed"} etc.). Sections of different
1409 context within a sub-proof may be switched via @{command "next"},
1410 which is just a single block-close followed by block-open again.
1411 The effect of @{command "next"} is to reset the local proof context;
1412 there is no goal focus involved here!
1414 For slightly more advanced applications, there are explicit block
1415 parentheses as well. These typically achieve a stronger forward
1420 \item [@{command "next"}] switches to a fresh block within a
1421 sub-proof, resetting the local context to the initial one.
1423 \item [@{command "{"} and @{command "}"}] explicitly open and close
1424 blocks. Any current facts pass through ``@{command "{"}''
1425 unchanged, while ``@{command "}"}'' causes any result to be
1426 \emph{exported} into the enclosing context. Thus fixed variables
1427 are generalized, assumptions discharged, and local definitions
1428 unfolded (cf.\ \secref{sec:proof-context}). There is no difference
1429 of @{command "assume"} and @{command "presume"} in this mode of
1430 forward reasoning --- in contrast to plain backward reasoning with
1431 the result exported at @{command "show"} time.
1437 subsection {* Emulating tactic scripts \label{sec:tactic-commands} *}
1440 The Isar provides separate commands to accommodate tactic-style
1441 proof scripts within the same system. While being outside the
1442 orthodox Isar proof language, these might come in handy for
1443 interactive exploration and debugging, or even actual tactical proof
1444 within new-style theories (to benefit from document preparation, for
1445 example). See also \secref{sec:tactics} for actual tactics, that
1446 have been encapsulated as proof methods. Proper proof methods may
1447 be used in scripts, too.
1449 \begin{matharray}{rcl}
1450 @{command_def "apply"}^* & : & \isartrans{proof(prove)}{proof(prove)} \\
1451 @{command_def "apply_end"}^* & : & \isartrans{proof(state)}{proof(state)} \\
1452 @{command_def "done"}^* & : & \isartrans{proof(prove)}{proof(state)} \\
1453 @{command_def "defer"}^* & : & \isartrans{proof}{proof} \\
1454 @{command_def "prefer"}^* & : & \isartrans{proof}{proof} \\
1455 @{command_def "back"}^* & : & \isartrans{proof}{proof} \\
1459 ( 'apply' | 'apply\_end' ) method
1469 \item [@{command "apply"}~@{text m}] applies proof method @{text m}
1470 in initial position, but unlike @{command "proof"} it retains
1471 ``@{text "proof(prove)"}'' mode. Thus consecutive method
1472 applications may be given just as in tactic scripts.
1474 Facts are passed to @{text m} as indicated by the goal's
1475 forward-chain mode, and are \emph{consumed} afterwards. Thus any
1476 further @{command "apply"} command would always work in a purely
1479 \item [@{command "apply_end"}~@{text "m"}] applies proof method
1480 @{text m} as if in terminal position. Basically, this simulates a
1481 multi-step tactic script for @{command "qed"}, but may be given
1482 anywhere within the proof body.
1484 No facts are passed to @{method m} here. Furthermore, the static
1485 context is that of the enclosing goal (as for actual @{command
1486 "qed"}). Thus the proof method may not refer to any assumptions
1487 introduced in the current body, for example.
1489 \item [@{command "done"}] completes a proof script, provided that
1490 the current goal state is solved completely. Note that actual
1491 structured proof commands (e.g.\ ``@{command "."}'' or @{command
1492 "sorry"}) may be used to conclude proof scripts as well.
1494 \item [@{command "defer"}~@{text n} and @{command "prefer"}~@{text
1495 n}] shuffle the list of pending goals: @{command "defer"} puts off
1496 sub-goal @{text n} to the end of the list (@{text "n = 1"} by
1497 default), while @{command "prefer"} brings sub-goal @{text n} to the
1500 \item [@{command "back"}] does back-tracking over the result
1501 sequence of the latest proof command. Basically, any proof command
1502 may return multiple results.
1506 Any proper Isar proof method may be used with tactic script commands
1507 such as @{command "apply"}. A few additional emulations of actual
1508 tactics are provided as well; these would be never used in actual
1509 structured proofs, of course.
1513 subsection {* Meta-linguistic features *}
1516 \begin{matharray}{rcl}
1517 @{command_def "oops"} & : & \isartrans{proof}{theory} \\
1520 The @{command "oops"} command discontinues the current proof
1521 attempt, while considering the partial proof text as properly
1522 processed. This is conceptually quite different from ``faking''
1523 actual proofs via @{command_ref "sorry"} (see
1524 \secref{sec:proof-steps}): @{command "oops"} does not observe the
1525 proof structure at all, but goes back right to the theory level.
1526 Furthermore, @{command "oops"} does not produce any result theorem
1527 --- there is no intended claim to be able to complete the proof
1530 A typical application of @{command "oops"} is to explain Isar proofs
1531 \emph{within} the system itself, in conjunction with the document
1532 preparation tools of Isabelle described in \cite{isabelle-sys}.
1533 Thus partial or even wrong proof attempts can be discussed in a
1534 logically sound manner. Note that the Isabelle {\LaTeX} macros can
1535 be easily adapted to print something like ``@{text "\<dots>"}'' instead of
1536 the keyword ``@{command "oops"}''.
1538 \medskip The @{command "oops"} command is undo-able, unlike
1539 @{command_ref "kill"} (see \secref{sec:history}). The effect is to
1540 get back to the theory just before the opening of the proof.
1544 section {* Other commands *}
1546 subsection {* Diagnostics *}
1549 \begin{matharray}{rcl}
1550 \isarcmd{pr}^* & : & \isarkeep{\cdot} \\
1551 \isarcmd{thm}^* & : & \isarkeep{theory~|~proof} \\
1552 \isarcmd{term}^* & : & \isarkeep{theory~|~proof} \\
1553 \isarcmd{prop}^* & : & \isarkeep{theory~|~proof} \\
1554 \isarcmd{typ}^* & : & \isarkeep{theory~|~proof} \\
1555 \isarcmd{prf}^* & : & \isarkeep{theory~|~proof} \\
1556 \isarcmd{full_prf}^* & : & \isarkeep{theory~|~proof} \\
1559 These diagnostic commands assist interactive development. Note that
1560 @{command undo} does not apply here, the theory or proof
1561 configuration is not changed.
1564 'pr' modes? nat? (',' nat)?
1566 'thm' modes? thmrefs
1574 'prf' modes? thmrefs?
1576 'full\_prf' modes? thmrefs?
1579 modes: '(' (name + ) ')'
1585 \item [@{command "pr"}~@{text "goals, prems"}] prints the current
1586 proof state (if present), including the proof context, current facts
1587 and goals. The optional limit arguments affect the number of goals
1588 and premises to be displayed, which is initially 10 for both.
1589 Omitting limit values leaves the current setting unchanged.
1591 \item [@{command "thm"}~@{text "a\<^sub>1 \<dots> a\<^sub>n"}] retrieves
1592 theorems from the current theory or proof context. Note that any
1593 attributes included in the theorem specifications are applied to a
1594 temporary context derived from the current theory or proof; the
1595 result is discarded, i.e.\ attributes involved in @{text "a\<^sub>1,
1596 \<dots>, a\<^sub>n"} do not have any permanent effect.
1598 \item [@{command "term"}~@{text t} and @{command "prop"}~@{text \<phi>}]
1599 read, type-check and print terms or propositions according to the
1600 current theory or proof context; the inferred type of @{text t} is
1601 output as well. Note that these commands are also useful in
1602 inspecting the current environment of term abbreviations.
1604 \item [@{command "typ"}~@{text \<tau>}] reads and prints types of the
1605 meta-logic according to the current theory or proof context.
1607 \item [@{command "prf"}] displays the (compact) proof term of the
1608 current proof state (if present), or of the given theorems. Note
1609 that this requires proof terms to be switched on for the current
1610 object logic (see the ``Proof terms'' section of the Isabelle
1611 reference manual for information on how to do this).
1613 \item [@{command "full_prf"}] is like @{command "prf"}, but displays
1614 the full proof term, i.e.\ also displays information omitted in the
1615 compact proof term, which is denoted by ``@{verbatim _}''
1620 All of the diagnostic commands above admit a list of @{text modes}
1621 to be specified, which is appended to the current print mode (see
1622 also \cite{isabelle-ref}). Thus the output behavior may be modified
1623 according particular print mode features. For example, @{command
1624 "pr"}~@{text "(latex xsymbols symbols)"} would print the current
1625 proof state with mathematical symbols and special characters
1626 represented in {\LaTeX} source, according to the Isabelle style
1627 \cite{isabelle-sys}.
1629 Note that antiquotations (cf.\ \secref{sec:antiq}) provide a more
1630 systematic way to include formal items into the printed text
1635 subsection {* Inspecting the context *}
1638 \begin{matharray}{rcl}
1639 @{command_def "print_commands"}^* & : & \isarkeep{\cdot} \\
1640 @{command_def "print_theory"}^* & : & \isarkeep{theory~|~proof} \\
1641 @{command_def "print_syntax"}^* & : & \isarkeep{theory~|~proof} \\
1642 @{command_def "print_methods"}^* & : & \isarkeep{theory~|~proof} \\
1643 @{command_def "print_attributes"}^* & : & \isarkeep{theory~|~proof} \\
1644 @{command_def "print_theorems"}^* & : & \isarkeep{theory~|~proof} \\
1645 @{command_def "find_theorems"}^* & : & \isarkeep{theory~|~proof} \\
1646 @{command_def "thms_deps"}^* & : & \isarkeep{theory~|~proof} \\
1647 @{command_def "print_facts"}^* & : & \isarkeep{proof} \\
1648 @{command_def "print_binds"}^* & : & \isarkeep{proof} \\
1652 'print\_theory' ( '!'?)
1655 'find\_theorems' (('(' (nat)? ('with\_dups')? ')')?) (criterion *)
1657 criterion: ('-'?) ('name' ':' nameref | 'intro' | 'elim' | 'dest' |
1658 'simp' ':' term | term)
1664 These commands print certain parts of the theory and proof context.
1665 Note that there are some further ones available, such as for the set
1666 of rules declared for simplifications.
1670 \item [@{command "print_commands"}] prints Isabelle's outer theory
1671 syntax, including keywords and command.
1673 \item [@{command "print_theory"}] prints the main logical content of
1674 the theory context; the ``@{text "!"}'' option indicates extra
1677 \item [@{command "print_syntax"}] prints the inner syntax of types
1678 and terms, depending on the current context. The output can be very
1679 verbose, including grammar tables and syntax translation rules. See
1680 \cite[\S7, \S8]{isabelle-ref} for further information on Isabelle's
1683 \item [@{command "print_methods"}] prints all proof methods
1684 available in the current theory context.
1686 \item [@{command "print_attributes"}] prints all attributes
1687 available in the current theory context.
1689 \item [@{command "print_theorems"}] prints theorems resulting from
1692 \item [@{command "find_theorems"}~@{text criteria}] retrieves facts
1693 from the theory or proof context matching all of given search
1694 criteria. The criterion @{text "name: p"} selects all theorems
1695 whose fully qualified name matches pattern @{text p}, which may
1696 contain ``@{text "*"}'' wildcards. The criteria @{text intro},
1697 @{text elim}, and @{text dest} select theorems that match the
1698 current goal as introduction, elimination or destruction rules,
1699 respectively. The criterion @{text "simp: t"} selects all rewrite
1700 rules whose left-hand side matches the given term. The criterion
1701 term @{text t} selects all theorems that contain the pattern @{text
1702 t} -- as usual, patterns may contain occurrences of the dummy
1703 ``@{verbatim _}'', schematic variables, and type constraints.
1705 Criteria can be preceded by ``@{text "-"}'' to select theorems that
1706 do \emph{not} match. Note that giving the empty list of criteria
1707 yields \emph{all} currently known facts. An optional limit for the
1708 number of printed facts may be given; the default is 40. By
1709 default, duplicates are removed from the search result. Use
1710 @{keyword "with_dups"} to display duplicates.
1712 \item [@{command "thm_deps"}~@{text "a\<^sub>1 \<dots> a\<^sub>n"}]
1713 visualizes dependencies of facts, using Isabelle's graph browser
1714 tool (see also \cite{isabelle-sys}).
1716 \item [@{command "print_facts"}] prints all local facts of the
1717 current context, both named and unnamed ones.
1719 \item [@{command "print_binds"}] prints all term abbreviations
1720 present in the context.
1726 subsection {* History commands \label{sec:history} *}
1729 \begin{matharray}{rcl}
1730 @{command_def "undo"}^{{ * }{ * }} & : & \isarkeep{\cdot} \\
1731 @{command_def "redo"}^{{ * }{ * }} & : & \isarkeep{\cdot} \\
1732 @{command_def "kill"}^{{ * }{ * }} & : & \isarkeep{\cdot} \\
1735 The Isabelle/Isar top-level maintains a two-stage history, for
1736 theory and proof state transformation. Basically, any command can
1737 be undone using @{command "undo"}, excluding mere diagnostic
1738 elements. Its effect may be revoked via @{command "redo"}, unless
1739 the corresponding @{command "undo"} step has crossed the beginning
1740 of a proof or theory. The @{command "kill"} command aborts the
1741 current history node altogether, discontinuing a proof or even the
1742 whole theory. This operation is \emph{not} undo-able.
1745 History commands should never be used with user interfaces such as
1746 Proof~General \cite{proofgeneral,Aspinall:TACAS:2000}, which takes
1747 care of stepping forth and back itself. Interfering by manual
1748 @{command "undo"}, @{command "redo"}, or even @{command "kill"}
1749 commands would quickly result in utter confusion.
1754 subsection {* System operations *}
1757 \begin{matharray}{rcl}
1758 @{command_def "cd"}^* & : & \isarkeep{\cdot} \\
1759 @{command_def "pwd"}^* & : & \isarkeep{\cdot} \\
1760 @{command_def "use_thy"}^* & : & \isarkeep{\cdot} \\
1761 @{command_def "display_drafts"}^* & : & \isarkeep{\cdot} \\
1762 @{command_def "print_drafts"}^* & : & \isarkeep{\cdot} \\
1766 ('cd' | 'use\_thy' | 'update\_thy') name
1768 ('display\_drafts' | 'print\_drafts') (name +)
1774 \item [@{command "cd"}~@{text path}] changes the current directory
1775 of the Isabelle process.
1777 \item [@{command "pwd"}] prints the current working directory.
1779 \item [@{command "use_thy"}~@{text A}] preload theory @{text A}.
1780 These system commands are scarcely used when working interactively,
1781 since loading of theories is done automatically as required.
1783 \item [@{command "display_drafts"}~@{text paths} and @{command
1784 "print_drafts"}~@{text paths}] perform simple output of a given list
1785 of raw source files. Only those symbols that do not require
1786 additional {\LaTeX} packages are displayed properly, everything else