src/Doc/Isar_Ref/Framework.thy
author wenzelm
Wed, 10 Feb 2016 09:32:16 +0100
changeset 62275 374d1b6c473d
parent 62271 4cfe65cfd369
child 62276 bed456ada96e
permissions -rw-r--r--
tuned whitespace;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
61656
cfabbc083977 more uniform jEdit properties;
wenzelm
parents: 61493
diff changeset
     1
(*:maxLineLen=78:*)
cfabbc083977 more uniform jEdit properties;
wenzelm
parents: 61493
diff changeset
     2
29716
b6266c4c68fe basic setup for chapter "The Isabelle/Isar Framework";
wenzelm
parents:
diff changeset
     3
theory Framework
42651
e3fdb7c96be5 formal Base theory;
wenzelm
parents: 42626
diff changeset
     4
imports Base Main
29716
b6266c4c68fe basic setup for chapter "The Isabelle/Isar Framework";
wenzelm
parents:
diff changeset
     5
begin
b6266c4c68fe basic setup for chapter "The Isabelle/Isar Framework";
wenzelm
parents:
diff changeset
     6
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
     7
chapter \<open>The Isabelle/Isar Framework \label{ch:isar-framework}\<close>
29716
b6266c4c68fe basic setup for chapter "The Isabelle/Isar Framework";
wenzelm
parents:
diff changeset
     8
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
     9
text \<open>
58552
66fed99e874f prefer @{cite} antiquotation;
wenzelm
parents: 56594
diff changeset
    10
  Isabelle/Isar @{cite "Wenzel:1999:TPHOL" and "Wenzel-PhD" and
62275
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
    11
  "Nipkow-TYPES02" and "Wenzel-Paulson:2006" and "Wenzel:2006:Festschrift"} is
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
    12
  intended as a generic framework for developing formal mathematical documents
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
    13
  with full proof checking. Definitions and proofs are organized as theories.
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
    14
  An assembly of theory sources may be presented as a printed document; see
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
    15
  also \chref{ch:document-prep}.
29716
b6266c4c68fe basic setup for chapter "The Isabelle/Isar Framework";
wenzelm
parents:
diff changeset
    16
62275
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
    17
  The main objective of Isar is the design of a human-readable structured
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
    18
  proof language, which is called the ``primary proof format'' in Isar
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
    19
  terminology. Such a primary proof language is somewhere in the middle
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
    20
  between the extremes of primitive proof objects and actual natural language.
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
    21
  In this respect, Isar is a bit more formalistic than Mizar @{cite
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
    22
  "Trybulec:1993:MizarFeatures" and "Rudnicki:1992:MizarOverview" and
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
    23
  "Wiedijk:1999:Mizar"}, using logical symbols for certain reasoning schemes
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
    24
  where Mizar would prefer English words; see @{cite "Wenzel-Wiedijk:2002"}
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
    25
  for further comparisons of these systems.
29716
b6266c4c68fe basic setup for chapter "The Isabelle/Isar Framework";
wenzelm
parents:
diff changeset
    26
62275
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
    27
  So Isar challenges the traditional way of recording informal proofs in
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
    28
  mathematical prose, as well as the common tendency to see fully formal
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
    29
  proofs directly as objects of some logical calculus (e.g.\ \<open>\<lambda>\<close>-terms in a
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
    30
  version of type theory). In fact, Isar is better understood as an
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
    31
  interpreter of a simple block-structured language for describing the data
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
    32
  flow of local facts and goals, interspersed with occasional invocations of
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
    33
  proof methods. Everything is reduced to logical inferences internally, but
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
    34
  these steps are somewhat marginal compared to the overall bookkeeping of the
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
    35
  interpretation process. Thanks to careful design of the syntax and semantics
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
    36
  of Isar language elements, a formal record of Isar instructions may later
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
    37
  appear as an intelligible text to the attentive reader.
29716
b6266c4c68fe basic setup for chapter "The Isabelle/Isar Framework";
wenzelm
parents:
diff changeset
    38
62275
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
    39
  The Isar proof language has emerged from careful analysis of some inherent
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
    40
  virtues of the existing logical framework of Isabelle/Pure @{cite
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
    41
  "paulson-found" and "paulson700"}, notably composition of higher-order
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
    42
  natural deduction rules, which is a generalization of Gentzen's original
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
    43
  calculus @{cite "Gentzen:1935"}. The approach of generic inference systems
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
    44
  in Pure is continued by Isar towards actual proof texts.
29716
b6266c4c68fe basic setup for chapter "The Isabelle/Isar Framework";
wenzelm
parents:
diff changeset
    45
62275
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
    46
  Concrete applications require another intermediate layer: an object-logic.
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
    47
  Isabelle/HOL @{cite "isa-tutorial"} (simply-typed set-theory) is being used
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
    48
  most of the time; Isabelle/ZF @{cite "isabelle-ZF"} is less extensively
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
    49
  developed, although it would probably fit better for classical mathematics.
29721
df4e53d18ebc added introductory examples;
wenzelm
parents: 29716
diff changeset
    50
61421
e0825405d398 more symbols;
wenzelm
parents: 61420
diff changeset
    51
  \<^medskip>
62275
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
    52
  In order to illustrate natural deduction in Isar, we shall refer to the
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
    53
  background theory and library of Isabelle/HOL. This includes common notions
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
    54
  of predicate logic, naive set-theory etc.\ using fairly standard
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
    55
  mathematical notation. From the perspective of generic natural deduction
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
    56
  there is nothing special about the logical connectives of HOL (\<open>\<and>\<close>, \<open>\<or>\<close>,
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
    57
  \<open>\<forall>\<close>, \<open>\<exists>\<close>, etc.), only the resulting reasoning principles are relevant to the
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
    58
  user. There are similar rules available for set-theory operators (\<open>\<inter>\<close>, \<open>\<union>\<close>,
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
    59
  \<open>\<Inter>\<close>, \<open>\<Union>\<close>, etc.), or any other theory developed in the library (lattice
29735
1da96affdefe misc tuning;
wenzelm
parents: 29733
diff changeset
    60
  theory, topology etc.).
29721
df4e53d18ebc added introductory examples;
wenzelm
parents: 29716
diff changeset
    61
62275
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
    62
  Subsequently we briefly review fragments of Isar proof texts corresponding
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
    63
  directly to such general deduction schemes. The examples shall refer to
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
    64
  set-theory, to minimize the danger of understanding connectives of predicate
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
    65
  logic as something special.
29721
df4e53d18ebc added introductory examples;
wenzelm
parents: 29716
diff changeset
    66
61421
e0825405d398 more symbols;
wenzelm
parents: 61420
diff changeset
    67
  \<^medskip>
62275
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
    68
  The following deduction performs \<open>\<inter>\<close>-introduction, working forwards from
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
    69
  assumptions towards the conclusion. We give both the Isar text, and depict
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
    70
  the primitive rule involved, as determined by unification of the problem
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
    71
  against rules that are declared in the library context.
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
    72
\<close>
29721
df4e53d18ebc added introductory examples;
wenzelm
parents: 29716
diff changeset
    73
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
    74
text_raw \<open>\medskip\begin{minipage}{0.6\textwidth}\<close>
29721
df4e53d18ebc added introductory examples;
wenzelm
parents: 29716
diff changeset
    75
df4e53d18ebc added introductory examples;
wenzelm
parents: 29716
diff changeset
    76
(*<*)
40964
482a8334ee9e prefer 'notepad' over 'example_proof';
wenzelm
parents: 40476
diff changeset
    77
notepad
482a8334ee9e prefer 'notepad' over 'example_proof';
wenzelm
parents: 40476
diff changeset
    78
begin
29721
df4e53d18ebc added introductory examples;
wenzelm
parents: 29716
diff changeset
    79
(*>*)
df4e53d18ebc added introductory examples;
wenzelm
parents: 29716
diff changeset
    80
    assume "x \<in> A" and "x \<in> B"
df4e53d18ebc added introductory examples;
wenzelm
parents: 29716
diff changeset
    81
    then have "x \<in> A \<inter> B" ..
df4e53d18ebc added introductory examples;
wenzelm
parents: 29716
diff changeset
    82
(*<*)
40964
482a8334ee9e prefer 'notepad' over 'example_proof';
wenzelm
parents: 40476
diff changeset
    83
end
29721
df4e53d18ebc added introductory examples;
wenzelm
parents: 29716
diff changeset
    84
(*>*)
df4e53d18ebc added introductory examples;
wenzelm
parents: 29716
diff changeset
    85
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
    86
text_raw \<open>\end{minipage}\begin{minipage}{0.4\textwidth}\<close>
29721
df4e53d18ebc added introductory examples;
wenzelm
parents: 29716
diff changeset
    87
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
    88
text \<open>
29721
df4e53d18ebc added introductory examples;
wenzelm
parents: 29716
diff changeset
    89
  \infer{@{prop "x \<in> A \<inter> B"}}{@{prop "x \<in> A"} & @{prop "x \<in> B"}}
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
    90
\<close>
29721
df4e53d18ebc added introductory examples;
wenzelm
parents: 29716
diff changeset
    91
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
    92
text_raw \<open>\end{minipage}\<close>
29721
df4e53d18ebc added introductory examples;
wenzelm
parents: 29716
diff changeset
    93
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
    94
text \<open>
61421
e0825405d398 more symbols;
wenzelm
parents: 61420
diff changeset
    95
  \<^medskip>
62275
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
    96
  Note that @{command assume} augments the proof context, @{command then}
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
    97
  indicates that the current fact shall be used in the next step, and
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
    98
  @{command have} states an intermediate goal. The two dots ``@{command
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
    99
  ".."}'' refer to a complete proof of this claim, using the indicated facts
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   100
  and a canonical rule from the context. We could have been more explicit here
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   101
  by spelling out the final proof step via the @{command "by"} command:
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   102
\<close>
29721
df4e53d18ebc added introductory examples;
wenzelm
parents: 29716
diff changeset
   103
df4e53d18ebc added introductory examples;
wenzelm
parents: 29716
diff changeset
   104
(*<*)
40964
482a8334ee9e prefer 'notepad' over 'example_proof';
wenzelm
parents: 40476
diff changeset
   105
notepad
482a8334ee9e prefer 'notepad' over 'example_proof';
wenzelm
parents: 40476
diff changeset
   106
begin
29721
df4e53d18ebc added introductory examples;
wenzelm
parents: 29716
diff changeset
   107
(*>*)
df4e53d18ebc added introductory examples;
wenzelm
parents: 29716
diff changeset
   108
    assume "x \<in> A" and "x \<in> B"
df4e53d18ebc added introductory examples;
wenzelm
parents: 29716
diff changeset
   109
    then have "x \<in> A \<inter> B" by (rule IntI)
df4e53d18ebc added introductory examples;
wenzelm
parents: 29716
diff changeset
   110
(*<*)
40964
482a8334ee9e prefer 'notepad' over 'example_proof';
wenzelm
parents: 40476
diff changeset
   111
end
29721
df4e53d18ebc added introductory examples;
wenzelm
parents: 29716
diff changeset
   112
(*>*)
df4e53d18ebc added introductory examples;
wenzelm
parents: 29716
diff changeset
   113
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   114
text \<open>
62275
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   115
  The format of the \<open>\<inter>\<close>-introduction rule represents the most basic inference,
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   116
  which proceeds from given premises to a conclusion, without any nested proof
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   117
  context involved.
29721
df4e53d18ebc added introductory examples;
wenzelm
parents: 29716
diff changeset
   118
62275
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   119
  The next example performs backwards introduction on @{term "\<Inter>\<A>"}, the
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   120
  intersection of all sets within a given set. This requires a nested proof of
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   121
  set membership within a local context, where @{term A} is an
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   122
  arbitrary-but-fixed member of the collection:
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   123
\<close>
29721
df4e53d18ebc added introductory examples;
wenzelm
parents: 29716
diff changeset
   124
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   125
text_raw \<open>\medskip\begin{minipage}{0.6\textwidth}\<close>
29721
df4e53d18ebc added introductory examples;
wenzelm
parents: 29716
diff changeset
   126
df4e53d18ebc added introductory examples;
wenzelm
parents: 29716
diff changeset
   127
(*<*)
40964
482a8334ee9e prefer 'notepad' over 'example_proof';
wenzelm
parents: 40476
diff changeset
   128
notepad
482a8334ee9e prefer 'notepad' over 'example_proof';
wenzelm
parents: 40476
diff changeset
   129
begin
29721
df4e53d18ebc added introductory examples;
wenzelm
parents: 29716
diff changeset
   130
(*>*)
df4e53d18ebc added introductory examples;
wenzelm
parents: 29716
diff changeset
   131
    have "x \<in> \<Inter>\<A>"
df4e53d18ebc added introductory examples;
wenzelm
parents: 29716
diff changeset
   132
    proof
df4e53d18ebc added introductory examples;
wenzelm
parents: 29716
diff changeset
   133
      fix A
df4e53d18ebc added introductory examples;
wenzelm
parents: 29716
diff changeset
   134
      assume "A \<in> \<A>"
62271
4cfe65cfd369 more explicit dummy proofs;
wenzelm
parents: 61962
diff changeset
   135
      show "x \<in> A" \<proof>
29721
df4e53d18ebc added introductory examples;
wenzelm
parents: 29716
diff changeset
   136
    qed
df4e53d18ebc added introductory examples;
wenzelm
parents: 29716
diff changeset
   137
(*<*)
40964
482a8334ee9e prefer 'notepad' over 'example_proof';
wenzelm
parents: 40476
diff changeset
   138
end
29721
df4e53d18ebc added introductory examples;
wenzelm
parents: 29716
diff changeset
   139
(*>*)
df4e53d18ebc added introductory examples;
wenzelm
parents: 29716
diff changeset
   140
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   141
text_raw \<open>\end{minipage}\begin{minipage}{0.4\textwidth}\<close>
29721
df4e53d18ebc added introductory examples;
wenzelm
parents: 29716
diff changeset
   142
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   143
text \<open>
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   144
  \infer{@{prop "x \<in> \<Inter>\<A>"}}{\infer*{@{prop "x \<in> A"}}{\<open>[A][A \<in> \<A>]\<close>}}
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   145
\<close>
29721
df4e53d18ebc added introductory examples;
wenzelm
parents: 29716
diff changeset
   146
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   147
text_raw \<open>\end{minipage}\<close>
29721
df4e53d18ebc added introductory examples;
wenzelm
parents: 29716
diff changeset
   148
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   149
text \<open>
61421
e0825405d398 more symbols;
wenzelm
parents: 61420
diff changeset
   150
  \<^medskip>
62275
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   151
  This Isar reasoning pattern again refers to the primitive rule depicted
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   152
  above. The system determines it in the ``@{command proof}'' step, which
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   153
  could have been spelled out more explicitly as ``@{command proof}~\<open>(rule
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   154
  InterI)\<close>''. Note that the rule involves both a local parameter @{term "A"}
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   155
  and an assumption @{prop "A \<in> \<A>"} in the nested reasoning. This kind of
29729
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   156
  compound rule typically demands a genuine sub-proof in Isar, working
62275
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   157
  backwards rather than forwards as seen before. In the proof body we
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   158
  encounter the @{command fix}-@{command assume}-@{command show} outline of
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   159
  nested sub-proofs that is typical for Isar. The final @{command show} is
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   160
  like @{command have} followed by an additional refinement of the enclosing
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   161
  claim, using the rule derived from the proof body.
29721
df4e53d18ebc added introductory examples;
wenzelm
parents: 29716
diff changeset
   162
61421
e0825405d398 more symbols;
wenzelm
parents: 61420
diff changeset
   163
  \<^medskip>
62275
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   164
  The next example involves @{term "\<Union>\<A>"}, which can be characterized as the
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   165
  set of all @{term "x"} such that @{prop "\<exists>A. x \<in> A \<and> A \<in> \<A>"}. The
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   166
  elimination rule for @{prop "x \<in> \<Union>\<A>"} does not mention \<open>\<exists>\<close> and \<open>\<and>\<close> at all,
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   167
  but admits to obtain directly a local @{term "A"} such that @{prop "x \<in> A"}
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   168
  and @{prop "A \<in> \<A>"} hold. This corresponds to the following Isar proof and
29721
df4e53d18ebc added introductory examples;
wenzelm
parents: 29716
diff changeset
   169
  inference rule, respectively:
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   170
\<close>
29721
df4e53d18ebc added introductory examples;
wenzelm
parents: 29716
diff changeset
   171
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   172
text_raw \<open>\medskip\begin{minipage}{0.6\textwidth}\<close>
29721
df4e53d18ebc added introductory examples;
wenzelm
parents: 29716
diff changeset
   173
df4e53d18ebc added introductory examples;
wenzelm
parents: 29716
diff changeset
   174
(*<*)
40964
482a8334ee9e prefer 'notepad' over 'example_proof';
wenzelm
parents: 40476
diff changeset
   175
notepad
482a8334ee9e prefer 'notepad' over 'example_proof';
wenzelm
parents: 40476
diff changeset
   176
begin
29721
df4e53d18ebc added introductory examples;
wenzelm
parents: 29716
diff changeset
   177
(*>*)
df4e53d18ebc added introductory examples;
wenzelm
parents: 29716
diff changeset
   178
    assume "x \<in> \<Union>\<A>"
df4e53d18ebc added introductory examples;
wenzelm
parents: 29716
diff changeset
   179
    then have C
df4e53d18ebc added introductory examples;
wenzelm
parents: 29716
diff changeset
   180
    proof
df4e53d18ebc added introductory examples;
wenzelm
parents: 29716
diff changeset
   181
      fix A
df4e53d18ebc added introductory examples;
wenzelm
parents: 29716
diff changeset
   182
      assume "x \<in> A" and "A \<in> \<A>"
62271
4cfe65cfd369 more explicit dummy proofs;
wenzelm
parents: 61962
diff changeset
   183
      show C \<proof>
29721
df4e53d18ebc added introductory examples;
wenzelm
parents: 29716
diff changeset
   184
    qed
df4e53d18ebc added introductory examples;
wenzelm
parents: 29716
diff changeset
   185
(*<*)
40964
482a8334ee9e prefer 'notepad' over 'example_proof';
wenzelm
parents: 40476
diff changeset
   186
end
29721
df4e53d18ebc added introductory examples;
wenzelm
parents: 29716
diff changeset
   187
(*>*)
df4e53d18ebc added introductory examples;
wenzelm
parents: 29716
diff changeset
   188
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   189
text_raw \<open>\end{minipage}\begin{minipage}{0.4\textwidth}\<close>
29721
df4e53d18ebc added introductory examples;
wenzelm
parents: 29716
diff changeset
   190
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   191
text \<open>
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   192
  \infer{@{prop "C"}}{@{prop "x \<in> \<Union>\<A>"} & \infer*{@{prop "C"}~}{\<open>[A][x \<in> A, A \<in> \<A>]\<close>}}
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   193
\<close>
29721
df4e53d18ebc added introductory examples;
wenzelm
parents: 29716
diff changeset
   194
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   195
text_raw \<open>\end{minipage}\<close>
29721
df4e53d18ebc added introductory examples;
wenzelm
parents: 29716
diff changeset
   196
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   197
text \<open>
61421
e0825405d398 more symbols;
wenzelm
parents: 61420
diff changeset
   198
  \<^medskip>
62275
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   199
  Although the Isar proof follows the natural deduction rule closely, the text
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   200
  reads not as natural as anticipated. There is a double occurrence of an
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   201
  arbitrary conclusion @{prop "C"}, which represents the final result, but is
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   202
  irrelevant for now. This issue arises for any elimination rule involving
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   203
  local parameters. Isar provides the derived language element @{command
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   204
  obtain}, which is able to perform the same elimination proof more
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   205
  conveniently:
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   206
\<close>
29721
df4e53d18ebc added introductory examples;
wenzelm
parents: 29716
diff changeset
   207
df4e53d18ebc added introductory examples;
wenzelm
parents: 29716
diff changeset
   208
(*<*)
40964
482a8334ee9e prefer 'notepad' over 'example_proof';
wenzelm
parents: 40476
diff changeset
   209
notepad
482a8334ee9e prefer 'notepad' over 'example_proof';
wenzelm
parents: 40476
diff changeset
   210
begin
29721
df4e53d18ebc added introductory examples;
wenzelm
parents: 29716
diff changeset
   211
(*>*)
df4e53d18ebc added introductory examples;
wenzelm
parents: 29716
diff changeset
   212
    assume "x \<in> \<Union>\<A>"
df4e53d18ebc added introductory examples;
wenzelm
parents: 29716
diff changeset
   213
    then obtain A where "x \<in> A" and "A \<in> \<A>" ..
df4e53d18ebc added introductory examples;
wenzelm
parents: 29716
diff changeset
   214
(*<*)
40964
482a8334ee9e prefer 'notepad' over 'example_proof';
wenzelm
parents: 40476
diff changeset
   215
end
29721
df4e53d18ebc added introductory examples;
wenzelm
parents: 29716
diff changeset
   216
(*>*)
df4e53d18ebc added introductory examples;
wenzelm
parents: 29716
diff changeset
   217
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   218
text \<open>
62275
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   219
  Here we avoid to mention the final conclusion @{prop "C"} and return to
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   220
  plain forward reasoning. The rule involved in the ``@{command ".."}'' proof
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   221
  is the same as before.
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   222
\<close>
29716
b6266c4c68fe basic setup for chapter "The Isabelle/Isar Framework";
wenzelm
parents:
diff changeset
   223
29729
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   224
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   225
section \<open>The Pure framework \label{sec:framework-pure}\<close>
29729
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   226
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   227
text \<open>
58552
66fed99e874f prefer @{cite} antiquotation;
wenzelm
parents: 56594
diff changeset
   228
  The Pure logic @{cite "paulson-found" and "paulson700"} is an intuitionistic
62275
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   229
  fragment of higher-order logic @{cite "church40"}. In type-theoretic
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   230
  parlance, there are three levels of \<open>\<lambda>\<close>-calculus with corresponding arrows
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   231
  \<open>\<Rightarrow>\<close>/\<open>\<And>\<close>/\<open>\<Longrightarrow>\<close>:
29735
1da96affdefe misc tuning;
wenzelm
parents: 29733
diff changeset
   232
61421
e0825405d398 more symbols;
wenzelm
parents: 61420
diff changeset
   233
  \<^medskip>
29735
1da96affdefe misc tuning;
wenzelm
parents: 29733
diff changeset
   234
  \begin{tabular}{ll}
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   235
  \<open>\<alpha> \<Rightarrow> \<beta>\<close> & syntactic function space (terms depending on terms) \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   236
  \<open>\<And>x. B(x)\<close> & universal quantification (proofs depending on terms) \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   237
  \<open>A \<Longrightarrow> B\<close> & implication (proofs depending on proofs) \\
29735
1da96affdefe misc tuning;
wenzelm
parents: 29733
diff changeset
   238
  \end{tabular}
61421
e0825405d398 more symbols;
wenzelm
parents: 61420
diff changeset
   239
  \<^medskip>
29729
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   240
62275
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   241
  Here only the types of syntactic terms, and the propositions of proof terms
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   242
  have been shown. The \<open>\<lambda>\<close>-structure of proofs can be recorded as an optional
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   243
  feature of the Pure inference kernel @{cite "Berghofer-Nipkow:2000:TPHOL"},
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   244
  but the formal system can never depend on them due to \<^emph>\<open>proof irrelevance\<close>.
29735
1da96affdefe misc tuning;
wenzelm
parents: 29733
diff changeset
   245
62275
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   246
  On top of this most primitive layer of proofs, Pure implements a generic
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   247
  calculus for nested natural deduction rules, similar to @{cite
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   248
  "Schroeder-Heister:1984"}. Here object-logic inferences are internalized as
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   249
  formulae over \<open>\<And>\<close> and \<open>\<Longrightarrow>\<close>. Combining such rule statements may involve
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   250
  higher-order unification @{cite "paulson-natural"}.
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   251
\<close>
29729
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   252
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   253
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   254
subsection \<open>Primitive inferences\<close>
29729
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   255
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   256
text \<open>
62275
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   257
  Term syntax provides explicit notation for abstraction \<open>\<lambda>x :: \<alpha>. b(x)\<close> and
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   258
  application \<open>b a\<close>, while types are usually implicit thanks to
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   259
  type-inference; terms of type \<open>prop\<close> are called propositions. Logical
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   260
  statements are composed via \<open>\<And>x :: \<alpha>. B(x)\<close> and \<open>A \<Longrightarrow> B\<close>. Primitive reasoning
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   261
  operates on judgments of the form \<open>\<Gamma> \<turnstile> \<phi>\<close>, with standard introduction and
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   262
  elimination rules for \<open>\<And>\<close> and \<open>\<Longrightarrow>\<close> that refer to fixed parameters \<open>x\<^sub>1, \<dots>,
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   263
  x\<^sub>m\<close> and hypotheses \<open>A\<^sub>1, \<dots>, A\<^sub>n\<close> from the context \<open>\<Gamma>\<close>; the corresponding
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   264
  proof terms are left implicit. The subsequent inference rules define \<open>\<Gamma> \<turnstile> \<phi>\<close>
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   265
  inductively, relative to a collection of axioms:
29729
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   266
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   267
  \[
61962
9c8fc56032e3 eliminated obscure macro that is in conflict with amsmath.sty;
wenzelm
parents: 61656
diff changeset
   268
  \infer{\<open>\<turnstile> A\<close>}{(\<open>A\<close> \mbox{~axiom})}
29729
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   269
  \qquad
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   270
  \infer{\<open>A \<turnstile> A\<close>}{}
29729
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   271
  \]
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   272
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   273
  \[
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   274
  \infer{\<open>\<Gamma> \<turnstile> \<And>x. B(x)\<close>}{\<open>\<Gamma> \<turnstile> B(x)\<close> & \<open>x \<notin> \<Gamma>\<close>}
29729
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   275
  \qquad
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   276
  \infer{\<open>\<Gamma> \<turnstile> B(a)\<close>}{\<open>\<Gamma> \<turnstile> \<And>x. B(x)\<close>}
29729
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   277
  \]
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   278
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   279
  \[
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   280
  \infer{\<open>\<Gamma> - A \<turnstile> A \<Longrightarrow> B\<close>}{\<open>\<Gamma> \<turnstile> B\<close>}
29729
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   281
  \qquad
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   282
  \infer{\<open>\<Gamma>\<^sub>1 \<union> \<Gamma>\<^sub>2 \<turnstile> B\<close>}{\<open>\<Gamma>\<^sub>1 \<turnstile> A \<Longrightarrow> B\<close> & \<open>\<Gamma>\<^sub>2 \<turnstile> A\<close>}
29729
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   283
  \]
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   284
62275
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   285
  Furthermore, Pure provides a built-in equality \<open>\<equiv> :: \<alpha> \<Rightarrow> \<alpha> \<Rightarrow> prop\<close> with
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   286
  axioms for reflexivity, substitution, extensionality, and \<open>\<alpha>\<beta>\<eta>\<close>-conversion
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   287
  on \<open>\<lambda>\<close>-terms.
29729
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   288
61421
e0825405d398 more symbols;
wenzelm
parents: 61420
diff changeset
   289
  \<^medskip>
62275
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   290
  An object-logic introduces another layer on top of Pure, e.g.\ with types
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   291
  \<open>i\<close> for individuals and \<open>o\<close> for propositions, term constants \<open>Trueprop :: o
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   292
  \<Rightarrow> prop\<close> as (implicit) derivability judgment and connectives like \<open>\<and> :: o \<Rightarrow> o
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   293
  \<Rightarrow> o\<close> or \<open>\<forall> :: (i \<Rightarrow> o) \<Rightarrow> o\<close>, and axioms for object-level rules such as
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   294
  \<open>conjI: A \<Longrightarrow> B \<Longrightarrow> A \<and> B\<close> or \<open>allI: (\<And>x. B x) \<Longrightarrow> \<forall>x. B x\<close>. Derived object rules
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   295
  are represented as theorems of Pure. After the initial object-logic setup,
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   296
  further axiomatizations are usually avoided; plain definitions and derived
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   297
  principles are used exclusively.
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   298
\<close>
29729
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   299
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   300
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   301
subsection \<open>Reasoning with rules \label{sec:framework-resolution}\<close>
29729
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   302
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   303
text \<open>
62275
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   304
  Primitive inferences mostly serve foundational purposes. The main reasoning
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   305
  mechanisms of Pure operate on nested natural deduction rules expressed as
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   306
  formulae, using \<open>\<And>\<close> to bind local parameters and \<open>\<Longrightarrow>\<close> to express entailment.
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   307
  Multiple parameters and premises are represented by repeating these
29735
1da96affdefe misc tuning;
wenzelm
parents: 29733
diff changeset
   308
  connectives in a right-associative manner.
29729
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   309
62275
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   310
  Since \<open>\<And>\<close> and \<open>\<Longrightarrow>\<close> commute thanks to the theorem @{prop "(A \<Longrightarrow> (\<And>x. B x)) \<equiv>
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   311
  (\<And>x. A \<Longrightarrow> B x)"}, we may assume w.l.o.g.\ that rule statements always observe
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   312
  the normal form where quantifiers are pulled in front of implications at
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   313
  each level of nesting. This means that any Pure proposition may be presented
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   314
  as a \<^emph>\<open>Hereditary Harrop Formula\<close> @{cite "Miller:1991"} which is of the form
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   315
  \<open>\<And>x\<^sub>1 \<dots> x\<^sub>m. H\<^sub>1 \<Longrightarrow> \<dots> H\<^sub>n \<Longrightarrow> A\<close> for \<open>m, n \<ge> 0\<close>, and \<open>A\<close> atomic, and \<open>H\<^sub>1, \<dots>,
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   316
  H\<^sub>n\<close> being recursively of the same format. Following the convention that
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   317
  outermost quantifiers are implicit, Horn clauses \<open>A\<^sub>1 \<Longrightarrow> \<dots> A\<^sub>n \<Longrightarrow> A\<close> are a
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   318
  special case of this.
29729
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   319
62275
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   320
  For example, \<open>\<inter>\<close>-introduction rule encountered before is represented as a
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   321
  Pure theorem as follows:
29735
1da96affdefe misc tuning;
wenzelm
parents: 29733
diff changeset
   322
  \[
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   323
  \<open>IntI:\<close>~@{prop "x \<in> A \<Longrightarrow> x \<in> B \<Longrightarrow> x \<in> A \<inter> B"}
29735
1da96affdefe misc tuning;
wenzelm
parents: 29733
diff changeset
   324
  \]
1da96affdefe misc tuning;
wenzelm
parents: 29733
diff changeset
   325
62275
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   326
  This is a plain Horn clause, since no further nesting on the left is
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   327
  involved. The general \<open>\<Inter>\<close>-introduction corresponds to a Hereditary Harrop
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   328
  Formula with one additional level of nesting:
29735
1da96affdefe misc tuning;
wenzelm
parents: 29733
diff changeset
   329
  \[
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   330
  \<open>InterI:\<close>~@{prop "(\<And>A. A \<in> \<A> \<Longrightarrow> x \<in> A) \<Longrightarrow> x \<in> \<Inter>\<A>"}
29735
1da96affdefe misc tuning;
wenzelm
parents: 29733
diff changeset
   331
  \]
1da96affdefe misc tuning;
wenzelm
parents: 29733
diff changeset
   332
61421
e0825405d398 more symbols;
wenzelm
parents: 61420
diff changeset
   333
  \<^medskip>
62275
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   334
  Goals are also represented as rules: \<open>A\<^sub>1 \<Longrightarrow> \<dots> A\<^sub>n \<Longrightarrow> C\<close> states that the
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   335
  sub-goals \<open>A\<^sub>1, \<dots>, A\<^sub>n\<close> entail the result \<open>C\<close>; for \<open>n = 0\<close> the goal is
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   336
  finished. To allow \<open>C\<close> being a rule statement itself, we introduce the
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   337
  protective marker \<open># :: prop \<Rightarrow> prop\<close>, which is defined as identity and
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   338
  hidden from the user. We initialize and finish goal states as follows:
29729
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   339
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   340
  \[
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   341
  \begin{array}{c@ {\qquad}c}
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   342
  \infer[(@{inference_def init})]{\<open>C \<Longrightarrow> #C\<close>}{} &
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   343
  \infer[(@{inference_def finish})]{\<open>C\<close>}{\<open>#C\<close>}
29729
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   344
  \end{array}
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   345
  \]
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   346
62275
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   347
  Goal states are refined in intermediate proof steps until a finished form is
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   348
  achieved. Here the two main reasoning principles are @{inference
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   349
  resolution}, for back-chaining a rule against a sub-goal (replacing it by
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   350
  zero or more sub-goals), and @{inference assumption}, for solving a sub-goal
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   351
  (finding a short-circuit with local assumptions). Below \<open>\<^vec>x\<close> stands
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   352
  for \<open>x\<^sub>1, \<dots>, x\<^sub>n\<close> (\<open>n \<ge> 0\<close>).
29729
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   353
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   354
  \[
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   355
  \infer[(@{inference_def resolution})]
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   356
  {\<open>(\<And>\<^vec>x. \<^vec>H \<^vec>x \<Longrightarrow> \<^vec>A (\<^vec>a \<^vec>x))\<vartheta> \<Longrightarrow> C\<vartheta>\<close>}
29729
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   357
  {\begin{tabular}{rl}
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   358
    \<open>rule:\<close> &
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   359
    \<open>\<^vec>A \<^vec>a \<Longrightarrow> B \<^vec>a\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   360
    \<open>goal:\<close> &
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   361
    \<open>(\<And>\<^vec>x. \<^vec>H \<^vec>x \<Longrightarrow> B' \<^vec>x) \<Longrightarrow> C\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   362
    \<open>goal unifier:\<close> &
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   363
    \<open>(\<lambda>\<^vec>x. B (\<^vec>a \<^vec>x))\<vartheta> = B'\<vartheta>\<close> \\
29729
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   364
   \end{tabular}}
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   365
  \]
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   366
61421
e0825405d398 more symbols;
wenzelm
parents: 61420
diff changeset
   367
  \<^medskip>
29729
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   368
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   369
  \[
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   370
  \infer[(@{inference_def assumption})]{\<open>C\<vartheta>\<close>}
29729
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   371
  {\begin{tabular}{rl}
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   372
    \<open>goal:\<close> &
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   373
    \<open>(\<And>\<^vec>x. \<^vec>H \<^vec>x \<Longrightarrow> A \<^vec>x) \<Longrightarrow> C\<close> \\
61962
9c8fc56032e3 eliminated obscure macro that is in conflict with amsmath.sty;
wenzelm
parents: 61656
diff changeset
   374
    \<open>assm unifier:\<close> & \<open>A\<vartheta> = H\<^sub>i\<vartheta>\<close>~~\mbox{(for some~\<open>H\<^sub>i\<close>)} \\
29729
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   375
   \end{tabular}}
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   376
  \]
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   377
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   378
  The following trace illustrates goal-oriented reasoning in
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   379
  Isabelle/Pure:
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   380
29735
1da96affdefe misc tuning;
wenzelm
parents: 29733
diff changeset
   381
  {\footnotesize
61421
e0825405d398 more symbols;
wenzelm
parents: 61420
diff changeset
   382
  \<^medskip>
29735
1da96affdefe misc tuning;
wenzelm
parents: 29733
diff changeset
   383
  \begin{tabular}{r@ {\quad}l}
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   384
  \<open>(A \<and> B \<Longrightarrow> B \<and> A) \<Longrightarrow> #(A \<and> B \<Longrightarrow> B \<and> A)\<close> & \<open>(init)\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   385
  \<open>(A \<and> B \<Longrightarrow> B) \<Longrightarrow> (A \<and> B \<Longrightarrow> A) \<Longrightarrow> #\<dots>\<close> & \<open>(resolution B \<Longrightarrow> A \<Longrightarrow> B \<and> A)\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   386
  \<open>(A \<and> B \<Longrightarrow> A \<and> B) \<Longrightarrow> (A \<and> B \<Longrightarrow> A) \<Longrightarrow> #\<dots>\<close> & \<open>(resolution A \<and> B \<Longrightarrow> B)\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   387
  \<open>(A \<and> B \<Longrightarrow> A) \<Longrightarrow> #\<dots>\<close> & \<open>(assumption)\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   388
  \<open>(A \<and> B \<Longrightarrow> A \<and> B) \<Longrightarrow> #\<dots>\<close> & \<open>(resolution A \<and> B \<Longrightarrow> A)\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   389
  \<open>#\<dots>\<close> & \<open>(assumption)\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   390
  \<open>A \<and> B \<Longrightarrow> B \<and> A\<close> & \<open>(finish)\<close> \\
29729
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   391
  \end{tabular}
61421
e0825405d398 more symbols;
wenzelm
parents: 61420
diff changeset
   392
  \<^medskip>
29735
1da96affdefe misc tuning;
wenzelm
parents: 29733
diff changeset
   393
  }
29729
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   394
62275
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   395
  Compositions of @{inference assumption} after @{inference resolution} occurs
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   396
  quite often, typically in elimination steps. Traditional Isabelle tactics
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   397
  accommodate this by a combined @{inference_def elim_resolution} principle.
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   398
  In contrast, Isar uses a slightly more refined combination, where the
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   399
  assumptions to be closed are marked explicitly, using again the protective
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   400
  marker \<open>#\<close>:
29729
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   401
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   402
  \[
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   403
  \infer[(@{inference refinement})]
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   404
  {\<open>(\<And>\<^vec>x. \<^vec>H \<^vec>x \<Longrightarrow> \<^vec>G' (\<^vec>a \<^vec>x))\<vartheta> \<Longrightarrow> C\<vartheta>\<close>}
29729
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   405
  {\begin{tabular}{rl}
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   406
    \<open>sub\<hyphen>proof:\<close> &
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   407
    \<open>\<^vec>G \<^vec>a \<Longrightarrow> B \<^vec>a\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   408
    \<open>goal:\<close> &
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   409
    \<open>(\<And>\<^vec>x. \<^vec>H \<^vec>x \<Longrightarrow> B' \<^vec>x) \<Longrightarrow> C\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   410
    \<open>goal unifier:\<close> &
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   411
    \<open>(\<lambda>\<^vec>x. B (\<^vec>a \<^vec>x))\<vartheta> = B'\<vartheta>\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   412
    \<open>assm unifiers:\<close> &
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   413
    \<open>(\<lambda>\<^vec>x. G\<^sub>j (\<^vec>a \<^vec>x))\<vartheta> = #H\<^sub>i\<vartheta>\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   414
    & \quad (for each marked \<open>G\<^sub>j\<close> some \<open>#H\<^sub>i\<close>) \\
29729
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   415
   \end{tabular}}
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   416
  \]
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   417
62275
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   418
  Here the \<open>sub\<hyphen>proof\<close> rule stems from the main @{command fix}-@{command
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   419
  assume}-@{command show} outline of Isar (cf.\
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   420
  \secref{sec:framework-subproof}): each assumption indicated in the text
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   421
  results in a marked premise \<open>G\<close> above. The marking enforces resolution
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   422
  against one of the sub-goal's premises. Consequently, @{command
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   423
  fix}-@{command assume}-@{command show} enables to fit the result of a
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   424
  sub-proof quite robustly into a pending sub-goal, while maintaining a good
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   425
  measure of flexibility.
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   426
\<close>
29729
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   427
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   428
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   429
section \<open>The Isar proof language \label{sec:framework-isar}\<close>
29729
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   430
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   431
text \<open>
62275
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   432
  Structured proofs are presented as high-level expressions for composing
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   433
  entities of Pure (propositions, facts, and goals). The Isar proof language
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   434
  allows to organize reasoning within the underlying rule calculus of Pure,
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   435
  but Isar is not another logical calculus!
29729
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   436
62275
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   437
  Isar is an exercise in sound minimalism. Approximately half of the language
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   438
  is introduced as primitive, the rest defined as derived concepts. The
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   439
  following grammar describes the core language (category \<open>proof\<close>), which is
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   440
  embedded into theory specification elements such as @{command theorem}; see
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   441
  also \secref{sec:framework-stmt} for the separate category \<open>statement\<close>.
29729
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   442
61421
e0825405d398 more symbols;
wenzelm
parents: 61420
diff changeset
   443
  \<^medskip>
29729
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   444
  \begin{tabular}{rcl}
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   445
    \<open>theory\<hyphen>stmt\<close> & = & @{command "theorem"}~\<open>statement proof  |\<close>~~@{command "definition"}~\<open>\<dots>  |  \<dots>\<close> \\[1ex]
29729
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   446
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   447
    \<open>proof\<close> & = & \<open>prfx\<^sup>*\<close>~@{command "proof"}~\<open>method\<^sup>? stmt\<^sup>*\<close>~@{command "qed"}~\<open>method\<^sup>?\<close> \\[1ex]
29729
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   448
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   449
    \<open>prfx\<close> & = & @{command "using"}~\<open>facts\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   450
    & \<open>|\<close> & @{command "unfolding"}~\<open>facts\<close> \\
29729
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   451
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   452
    \<open>stmt\<close> & = & @{command "{"}~\<open>stmt\<^sup>*\<close>~@{command "}"} \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   453
    & \<open>|\<close> & @{command "next"} \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   454
    & \<open>|\<close> & @{command "note"}~\<open>name = facts\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   455
    & \<open>|\<close> & @{command "let"}~\<open>term = term\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   456
    & \<open>|\<close> & @{command "fix"}~\<open>var\<^sup>+\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   457
    & \<open>|\<close> & @{command assume}~\<open>\<guillemotleft>inference\<guillemotright> name: props\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   458
    & \<open>|\<close> & @{command "then"}\<open>\<^sup>?\<close>~\<open>goal\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   459
    \<open>goal\<close> & = & @{command "have"}~\<open>name: props proof\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   460
    & \<open>|\<close> & @{command "show"}~\<open>name: props proof\<close> \\
29729
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   461
  \end{tabular}
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   462
61421
e0825405d398 more symbols;
wenzelm
parents: 61420
diff changeset
   463
  \<^medskip>
62275
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   464
  Simultaneous propositions or facts may be separated by the @{keyword "and"}
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   465
  keyword.
29729
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   466
61421
e0825405d398 more symbols;
wenzelm
parents: 61420
diff changeset
   467
  \<^medskip>
62275
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   468
  The syntax for terms and propositions is inherited from Pure (and the
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   469
  object-logic). A \<open>pattern\<close> is a \<open>term\<close> with schematic variables, to be bound
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   470
  by higher-order matching.
29729
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   471
61421
e0825405d398 more symbols;
wenzelm
parents: 61420
diff changeset
   472
  \<^medskip>
62275
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   473
  Facts may be referenced by name or proposition. For example, the result of
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   474
  ``@{command have}~\<open>a: A \<langle>proof\<rangle>\<close>'' becomes available both as \<open>a\<close> and
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   475
  \isacharbackquoteopen\<open>A\<close>\isacharbackquoteclose. Moreover, fact expressions
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   476
  may involve attributes that modify either the theorem or the background
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   477
  context. For example, the expression ``\<open>a [OF b]\<close>'' refers to the
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   478
  composition of two facts according to the @{inference resolution} inference
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   479
  of \secref{sec:framework-resolution}, while ``\<open>a [intro]\<close>'' declares a fact
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   480
  as introduction rule in the context.
29729
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   481
62275
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   482
  The special fact called ``@{fact this}'' always refers to the last result,
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   483
  as produced by @{command note}, @{command assume}, @{command have}, or
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   484
  @{command show}. Since @{command note} occurs frequently together with
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   485
  @{command then} we provide some abbreviations:
29729
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   486
61421
e0825405d398 more symbols;
wenzelm
parents: 61420
diff changeset
   487
  \<^medskip>
29737
866841668584 replaced 'assm' by 'assume' -- regular 'assume' is default, if inference is omitted;
wenzelm
parents: 29735
diff changeset
   488
  \begin{tabular}{rcl}
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   489
    @{command from}~\<open>a\<close> & \<open>\<equiv>\<close> & @{command note}~\<open>a\<close>~@{command then} \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   490
    @{command with}~\<open>a\<close> & \<open>\<equiv>\<close> & @{command from}~\<open>a \<AND> this\<close> \\
29737
866841668584 replaced 'assm' by 'assume' -- regular 'assume' is default, if inference is omitted;
wenzelm
parents: 29735
diff changeset
   491
  \end{tabular}
61421
e0825405d398 more symbols;
wenzelm
parents: 61420
diff changeset
   492
  \<^medskip>
29737
866841668584 replaced 'assm' by 'assume' -- regular 'assume' is default, if inference is omitted;
wenzelm
parents: 29735
diff changeset
   493
62275
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   494
  The \<open>method\<close> category is essentially a parameter and may be populated later.
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   495
  Methods use the facts indicated by @{command "then"} or @{command using},
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   496
  and then operate on the goal state. Some basic methods are predefined:
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   497
  ``@{method "-"}'' leaves the goal unchanged, ``@{method this}'' applies the
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   498
  facts as rules to the goal, ``@{method (Pure) "rule"}'' applies the facts to
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   499
  another rule and the result to the goal (both ``@{method this}'' and
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   500
  ``@{method (Pure) rule}'' refer to @{inference resolution} of
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   501
  \secref{sec:framework-resolution}). The secondary arguments to ``@{method
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   502
  (Pure) rule}'' may be specified explicitly as in ``\<open>(rule a)\<close>'', or picked
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   503
  from the context. In the latter case, the system first tries rules declared
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   504
  as @{attribute (Pure) elim} or @{attribute (Pure) dest}, followed by those
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   505
  declared as @{attribute (Pure) intro}.
29729
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   506
62275
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   507
  The default method for @{command proof} is ``@{method standard}'' (arguments
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   508
  picked from the context), for @{command qed} it is ``@{method "succeed"}''.
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   509
  Further abbreviations for terminal proof steps are ``@{command
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   510
  "by"}~\<open>method\<^sub>1 method\<^sub>2\<close>'' for ``@{command proof}~\<open>method\<^sub>1\<close>~@{command
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   511
  qed}~\<open>method\<^sub>2\<close>'', and ``@{command ".."}'' for ``@{command "by"}~@{method
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   512
  standard}, and ``@{command "."}'' for ``@{command "by"}~@{method this}''.
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   513
  The @{command unfolding} element operates directly on the current facts and
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   514
  goal by applying equalities.
29729
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   515
61421
e0825405d398 more symbols;
wenzelm
parents: 61420
diff changeset
   516
  \<^medskip>
e0825405d398 more symbols;
wenzelm
parents: 61420
diff changeset
   517
  Block structure can be indicated explicitly by ``@{command
62275
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   518
  "{"}~\<open>\<dots>\<close>~@{command "}"}'', although the body of a sub-proof already involves
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   519
  implicit nesting. In any case, @{command next} jumps into the next section
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   520
  of a block, i.e.\ it acts like closing an implicit block scope and opening
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   521
  another one; there is no direct correspondence to subgoals here.
29729
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   522
62275
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   523
  The remaining elements @{command fix} and @{command assume} build up a local
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   524
  context (see \secref{sec:framework-context}), while @{command show} refines
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   525
  a pending sub-goal by the rule resulting from a nested sub-proof (see
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   526
  \secref{sec:framework-subproof}). Further derived concepts will support
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   527
  calculational reasoning (see \secref{sec:framework-calc}).
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   528
\<close>
29729
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   529
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   530
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   531
subsection \<open>Context elements \label{sec:framework-context}\<close>
29729
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   532
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   533
text \<open>
62275
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   534
  In judgments \<open>\<Gamma> \<turnstile> \<phi>\<close> of the primitive framework, \<open>\<Gamma>\<close> essentially acts like a
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   535
  proof context. Isar elaborates this idea towards a higher-level notion, with
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   536
  additional information for type-inference, term abbreviations, local facts,
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   537
  hypotheses etc.
29729
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   538
62275
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   539
  The element @{command fix}~\<open>x :: \<alpha>\<close> declares a local parameter, i.e.\ an
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   540
  arbitrary-but-fixed entity of a given type; in results exported from the
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   541
  context, \<open>x\<close> may become anything. The @{command assume}~\<open>\<guillemotleft>inference\<guillemotright>\<close>
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   542
  element provides a general interface to hypotheses: ``@{command
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   543
  assume}~\<open>\<guillemotleft>inference\<guillemotright> A\<close>'' produces \<open>A \<turnstile> A\<close> locally, while the included
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   544
  inference tells how to discharge \<open>A\<close> from results \<open>A \<turnstile> B\<close> later on. There is
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   545
  no user-syntax for \<open>\<guillemotleft>inference\<guillemotright>\<close>, i.e.\ it may only occur internally when
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   546
  derived commands are defined in ML.
29737
866841668584 replaced 'assm' by 'assume' -- regular 'assume' is default, if inference is omitted;
wenzelm
parents: 29735
diff changeset
   547
866841668584 replaced 'assm' by 'assume' -- regular 'assume' is default, if inference is omitted;
wenzelm
parents: 29735
diff changeset
   548
  At the user-level, the default inference for @{command assume} is
62275
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   549
  @{inference discharge} as given below. The additional variants @{command
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   550
  presume} and @{command def} are defined as follows:
29737
866841668584 replaced 'assm' by 'assume' -- regular 'assume' is default, if inference is omitted;
wenzelm
parents: 29735
diff changeset
   551
61421
e0825405d398 more symbols;
wenzelm
parents: 61420
diff changeset
   552
  \<^medskip>
29737
866841668584 replaced 'assm' by 'assume' -- regular 'assume' is default, if inference is omitted;
wenzelm
parents: 29735
diff changeset
   553
  \begin{tabular}{rcl}
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   554
    @{command presume}~\<open>A\<close> & \<open>\<equiv>\<close> & @{command assume}~\<open>\<guillemotleft>weak\<hyphen>discharge\<guillemotright> A\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   555
    @{command def}~\<open>x \<equiv> a\<close> & \<open>\<equiv>\<close> & @{command fix}~\<open>x\<close>~@{command assume}~\<open>\<guillemotleft>expansion\<guillemotright> x \<equiv> a\<close> \\
29737
866841668584 replaced 'assm' by 'assume' -- regular 'assume' is default, if inference is omitted;
wenzelm
parents: 29735
diff changeset
   556
  \end{tabular}
61421
e0825405d398 more symbols;
wenzelm
parents: 61420
diff changeset
   557
  \<^medskip>
29729
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   558
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   559
  \[
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   560
  \infer[(@{inference_def discharge})]{\<open>\<strut>\<Gamma> - A \<turnstile> #A \<Longrightarrow> B\<close>}{\<open>\<strut>\<Gamma> \<turnstile> B\<close>}
29737
866841668584 replaced 'assm' by 'assume' -- regular 'assume' is default, if inference is omitted;
wenzelm
parents: 29735
diff changeset
   561
  \]
866841668584 replaced 'assm' by 'assume' -- regular 'assume' is default, if inference is omitted;
wenzelm
parents: 29735
diff changeset
   562
  \[
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   563
  \infer[(@{inference_def "weak\<hyphen>discharge"})]{\<open>\<strut>\<Gamma> - A \<turnstile> A \<Longrightarrow> B\<close>}{\<open>\<strut>\<Gamma> \<turnstile> B\<close>}
29737
866841668584 replaced 'assm' by 'assume' -- regular 'assume' is default, if inference is omitted;
wenzelm
parents: 29735
diff changeset
   564
  \]
866841668584 replaced 'assm' by 'assume' -- regular 'assume' is default, if inference is omitted;
wenzelm
parents: 29735
diff changeset
   565
  \[
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   566
  \infer[(@{inference_def expansion})]{\<open>\<strut>\<Gamma> - (x \<equiv> a) \<turnstile> B a\<close>}{\<open>\<strut>\<Gamma> \<turnstile> B x\<close>}
29729
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   567
  \]
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   568
61421
e0825405d398 more symbols;
wenzelm
parents: 61420
diff changeset
   569
  \<^medskip>
62275
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   570
  Note that @{inference discharge} and @{inference "weak\<hyphen>discharge"} differ in
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   571
  the marker for @{prop A}, which is relevant when the result of a @{command
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   572
  fix}-@{command assume}-@{command show} outline is composed with a pending
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   573
  goal, cf.\ \secref{sec:framework-subproof}.
29729
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   574
62275
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   575
  The most interesting derived context element in Isar is @{command obtain}
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   576
  @{cite \<open>\S5.3\<close> "Wenzel-PhD"}, which supports generalized elimination steps
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   577
  in a purely forward manner. The @{command obtain} command takes a
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   578
  specification of parameters \<open>\<^vec>x\<close> and assumptions \<open>\<^vec>A\<close> to be
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   579
  added to the context, together with a proof of a case rule stating that this
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   580
  extension is conservative (i.e.\ may be removed from closed results later
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   581
  on):
29729
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   582
61421
e0825405d398 more symbols;
wenzelm
parents: 61420
diff changeset
   583
  \<^medskip>
29729
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   584
  \begin{tabular}{l}
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   585
  \<open>\<langle>facts\<rangle>\<close>~~@{command obtain}~\<open>\<^vec>x \<WHERE> \<^vec>A \<^vec>x  \<langle>proof\<rangle> \<equiv>\<close> \\[0.5ex]
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   586
  \quad @{command have}~\<open>case: \<And>thesis. (\<And>\<^vec>x. \<^vec>A \<^vec>x \<Longrightarrow> thesis) \<Longrightarrow> thesis\<rangle>\<close> \\
29729
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   587
  \quad @{command proof}~@{method "-"} \\
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   588
  \qquad @{command fix}~\<open>thesis\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   589
  \qquad @{command assume}~\<open>[intro]: \<And>\<^vec>x. \<^vec>A \<^vec>x \<Longrightarrow> thesis\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   590
  \qquad @{command show}~\<open>thesis\<close>~@{command using}~\<open>\<langle>facts\<rangle> \<langle>proof\<rangle>\<close> \\
29729
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   591
  \quad @{command qed} \\
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   592
  \quad @{command fix}~\<open>\<^vec>x\<close>~@{command assume}~\<open>\<guillemotleft>elimination case\<guillemotright> \<^vec>A \<^vec>x\<close> \\
29729
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   593
  \end{tabular}
61421
e0825405d398 more symbols;
wenzelm
parents: 61420
diff changeset
   594
  \<^medskip>
29729
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   595
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   596
  \[
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   597
  \infer[(@{inference elimination})]{\<open>\<Gamma> \<turnstile> B\<close>}{
29729
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   598
    \begin{tabular}{rl}
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   599
    \<open>case:\<close> &
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   600
    \<open>\<Gamma> \<turnstile> \<And>thesis. (\<And>\<^vec>x. \<^vec>A \<^vec>x \<Longrightarrow> thesis) \<Longrightarrow> thesis\<close> \\[0.2ex]
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   601
    \<open>result:\<close> &
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   602
    \<open>\<Gamma> \<union> \<^vec>A \<^vec>y \<turnstile> B\<close> \\[0.2ex]
29729
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   603
    \end{tabular}}
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   604
  \]
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   605
62275
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   606
  Here the name ``\<open>thesis\<close>'' is a specific convention for an
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   607
  arbitrary-but-fixed proposition; in the primitive natural deduction rules
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   608
  shown before we have occasionally used \<open>C\<close>. The whole statement of
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   609
  ``@{command obtain}~\<open>x\<close>~@{keyword "where"}~\<open>A x\<close>'' may be read as a claim
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   610
  that \<open>A x\<close> may be assumed for some arbitrary-but-fixed \<open>x\<close>. Also note that
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   611
  ``@{command obtain}~\<open>A \<AND> B\<close>'' without parameters is similar to
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   612
  ``@{command have}~\<open>A \<AND> B\<close>'', but the latter involves multiple
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   613
  sub-goals.
29729
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   614
61421
e0825405d398 more symbols;
wenzelm
parents: 61420
diff changeset
   615
  \<^medskip>
62275
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   616
  The subsequent Isar proof texts explain all context elements introduced
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   617
  above using the formal proof language itself. After finishing a local proof
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   618
  within a block, we indicate the exported result via @{command note}.
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   619
\<close>
29729
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   620
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   621
(*<*)
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   622
theorem True
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   623
proof
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   624
(*>*)
58999
ed09ae4ea2d8 uniform treatment of all document markup commands: 'text' and 'txt' merely differ in LaTeX style;
wenzelm
parents: 58618
diff changeset
   625
  text_raw \<open>\begin{minipage}[t]{0.45\textwidth}\<close>
29729
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   626
  {
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   627
    fix x
62271
4cfe65cfd369 more explicit dummy proofs;
wenzelm
parents: 61962
diff changeset
   628
    have "B x" \<proof>
29729
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   629
  }
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   630
  note \<open>\<And>x. B x\<close>
58999
ed09ae4ea2d8 uniform treatment of all document markup commands: 'text' and 'txt' merely differ in LaTeX style;
wenzelm
parents: 58618
diff changeset
   631
  text_raw \<open>\end{minipage}\quad\begin{minipage}[t]{0.45\textwidth}\<close>(*<*)next(*>*)
29735
1da96affdefe misc tuning;
wenzelm
parents: 29733
diff changeset
   632
  {
1da96affdefe misc tuning;
wenzelm
parents: 29733
diff changeset
   633
    assume A
62271
4cfe65cfd369 more explicit dummy proofs;
wenzelm
parents: 61962
diff changeset
   634
    have B \<proof>
29735
1da96affdefe misc tuning;
wenzelm
parents: 29733
diff changeset
   635
  }
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   636
  note \<open>A \<Longrightarrow> B\<close>
58999
ed09ae4ea2d8 uniform treatment of all document markup commands: 'text' and 'txt' merely differ in LaTeX style;
wenzelm
parents: 58618
diff changeset
   637
  text_raw \<open>\end{minipage}\\[3ex]\begin{minipage}[t]{0.45\textwidth}\<close>(*<*)next(*>*)
29729
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   638
  {
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   639
    def x \<equiv> a
62271
4cfe65cfd369 more explicit dummy proofs;
wenzelm
parents: 61962
diff changeset
   640
    have "B x" \<proof>
29729
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   641
  }
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   642
  note \<open>B a\<close>
58999
ed09ae4ea2d8 uniform treatment of all document markup commands: 'text' and 'txt' merely differ in LaTeX style;
wenzelm
parents: 58618
diff changeset
   643
  text_raw \<open>\end{minipage}\quad\begin{minipage}[t]{0.45\textwidth}\<close>(*<*)next(*>*)
29729
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   644
  {
62271
4cfe65cfd369 more explicit dummy proofs;
wenzelm
parents: 61962
diff changeset
   645
    obtain x where "A x" \<proof>
4cfe65cfd369 more explicit dummy proofs;
wenzelm
parents: 61962
diff changeset
   646
    have B \<proof>
29729
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   647
  }
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   648
  note \<open>B\<close>
58999
ed09ae4ea2d8 uniform treatment of all document markup commands: 'text' and 'txt' merely differ in LaTeX style;
wenzelm
parents: 58618
diff changeset
   649
  text_raw \<open>\end{minipage}\<close>
29729
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   650
(*<*)
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   651
qed
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   652
(*>*)
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   653
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   654
text \<open>
61421
e0825405d398 more symbols;
wenzelm
parents: 61420
diff changeset
   655
  \<^bigskip>
62275
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   656
  This illustrates the meaning of Isar context elements without goals getting
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   657
  in between.
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   658
\<close>
29729
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   659
61421
e0825405d398 more symbols;
wenzelm
parents: 61420
diff changeset
   660
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   661
subsection \<open>Structured statements \label{sec:framework-stmt}\<close>
29729
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   662
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   663
text \<open>
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   664
  The category \<open>statement\<close> of top-level theorem specifications
29729
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   665
  is defined as follows:
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   666
61421
e0825405d398 more symbols;
wenzelm
parents: 61420
diff changeset
   667
  \<^medskip>
29729
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   668
  \begin{tabular}{rcl}
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   669
  \<open>statement\<close> & \<open>\<equiv>\<close> & \<open>name: props \<AND> \<dots>\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   670
  & \<open>|\<close> & \<open>context\<^sup>* conclusion\<close> \\[0.5ex]
29729
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   671
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   672
  \<open>context\<close> & \<open>\<equiv>\<close> & \<open>\<FIXES> vars \<AND> \<dots>\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   673
  & \<open>|\<close> & \<open>\<ASSUMES> name: props \<AND> \<dots>\<close> \\
29729
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   674
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   675
  \<open>conclusion\<close> & \<open>\<equiv>\<close> & \<open>\<SHOWS> name: props \<AND> \<dots>\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   676
  & \<open>|\<close> & \<open>\<OBTAINS> vars \<AND> \<dots> \<WHERE> name: props \<AND> \<dots>\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   677
  & & \quad \<open>\<BBAR> \<dots>\<close> \\
29729
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   678
  \end{tabular}
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   679
61421
e0825405d398 more symbols;
wenzelm
parents: 61420
diff changeset
   680
  \<^medskip>
62275
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   681
  A simple \<open>statement\<close> consists of named propositions. The full form admits
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   682
  local context elements followed by the actual conclusions, such as
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   683
  ``@{keyword "fixes"}~\<open>x\<close>~@{keyword "assumes"}~\<open>A x\<close>~@{keyword "shows"}~\<open>B
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   684
  x\<close>''. The final result emerges as a Pure rule after discharging the context:
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   685
  @{prop "\<And>x. A x \<Longrightarrow> B x"}.
29729
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   686
62275
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   687
  The @{keyword "obtains"} variant is another abbreviation defined below;
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   688
  unlike @{command obtain} (cf.\ \secref{sec:framework-context}) there may be
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   689
  several ``cases'' separated by ``\<open>\<BBAR>\<close>'', each consisting of several
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   690
  parameters (\<open>vars\<close>) and several premises (\<open>props\<close>). This specifies
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   691
  multi-branch elimination rules.
29729
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   692
61421
e0825405d398 more symbols;
wenzelm
parents: 61420
diff changeset
   693
  \<^medskip>
29729
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   694
  \begin{tabular}{l}
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   695
  \<open>\<OBTAINS> \<^vec>x \<WHERE> \<^vec>A \<^vec>x   \<BBAR>   \<dots>   \<equiv>\<close> \\[0.5ex]
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   696
  \quad \<open>\<FIXES> thesis\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   697
  \quad \<open>\<ASSUMES> [intro]: \<And>\<^vec>x. \<^vec>A \<^vec>x \<Longrightarrow> thesis  \<AND>  \<dots>\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   698
  \quad \<open>\<SHOWS> thesis\<close> \\
29729
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   699
  \end{tabular}
61421
e0825405d398 more symbols;
wenzelm
parents: 61420
diff changeset
   700
  \<^medskip>
29729
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   701
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   702
  Presenting structured statements in such an ``open'' format usually
62275
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   703
  simplifies the subsequent proof, because the outer structure of the problem
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   704
  is already laid out directly. E.g.\ consider the following canonical
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   705
  patterns for \<open>\<SHOWS>\<close> and \<open>\<OBTAINS>\<close>, respectively:
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   706
\<close>
29729
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   707
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   708
text_raw \<open>\begin{minipage}{0.5\textwidth}\<close>
29729
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   709
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   710
theorem
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   711
  fixes x and y
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   712
  assumes "A x" and "B y"
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   713
  shows "C x y"
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   714
proof -
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   715
  from \<open>A x\<close> and \<open>B y\<close>
62271
4cfe65cfd369 more explicit dummy proofs;
wenzelm
parents: 61962
diff changeset
   716
  show "C x y" \<proof>
29729
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   717
qed
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   718
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   719
text_raw \<open>\end{minipage}\begin{minipage}{0.5\textwidth}\<close>
29729
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   720
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   721
theorem
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   722
  obtains x and y
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   723
  where "A x" and "B y"
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   724
proof -
62271
4cfe65cfd369 more explicit dummy proofs;
wenzelm
parents: 61962
diff changeset
   725
  have "A a" and "B b" \<proof>
29729
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   726
  then show thesis ..
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   727
qed
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   728
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   729
text_raw \<open>\end{minipage}\<close>
29729
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   730
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   731
text \<open>
61421
e0825405d398 more symbols;
wenzelm
parents: 61420
diff changeset
   732
  \<^medskip>
62275
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   733
  Here local facts \isacharbackquoteopen\<open>A x\<close>\isacharbackquoteclose\ and
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   734
  \isacharbackquoteopen\<open>B y\<close>\isacharbackquoteclose\ are referenced
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   735
  immediately; there is no need to decompose the logical rule structure again.
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   736
  In the second proof the final ``@{command then}~@{command
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   737
  show}~\<open>thesis\<close>~@{command ".."}'' involves the local rule case \<open>\<And>x y. A x \<Longrightarrow> B
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   738
  y \<Longrightarrow> thesis\<close> for the particular instance of terms \<open>a\<close> and \<open>b\<close> produced in the
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   739
  body. \<close>
29729
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   740
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   741
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   742
subsection \<open>Structured proof refinement \label{sec:framework-subproof}\<close>
29729
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   743
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   744
text \<open>
62275
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   745
  By breaking up the grammar for the Isar proof language, we may understand a
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   746
  proof text as a linear sequence of individual proof commands. These are
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   747
  interpreted as transitions of the Isar virtual machine (Isar/VM), which
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   748
  operates on a block-structured configuration in single steps. This allows
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   749
  users to write proof texts in an incremental manner, and inspect
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   750
  intermediate configurations for debugging.
29729
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   751
62275
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   752
  The basic idea is analogous to evaluating algebraic expressions on a stack
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   753
  machine: \<open>(a + b) \<cdot> c\<close> then corresponds to a sequence of single transitions
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   754
  for each symbol \<open>(, a, +, b, ), \<cdot>, c\<close>. In Isar the algebraic values are
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   755
  facts or goals, and the operations are inferences.
29729
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   756
61421
e0825405d398 more symbols;
wenzelm
parents: 61420
diff changeset
   757
  \<^medskip>
62275
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   758
  The Isar/VM state maintains a stack of nodes, each node contains the local
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   759
  proof context, the linguistic mode, and a pending goal (optional). The mode
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   760
  determines the type of transition that may be performed next, it essentially
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   761
  alternates between forward and backward reasoning, with an intermediate
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   762
  stage for chained facts (see \figref{fig:isar-vm}).
29738
05d5615e12d3 added Isar/VM mode transition diagram;
wenzelm
parents: 29737
diff changeset
   763
05d5615e12d3 added Isar/VM mode transition diagram;
wenzelm
parents: 29737
diff changeset
   764
  \begin{figure}[htb]
05d5615e12d3 added Isar/VM mode transition diagram;
wenzelm
parents: 29737
diff changeset
   765
  \begin{center}
48958
12afbf6eb7f9 more standard document preparation within session context;
wenzelm
parents: 48279
diff changeset
   766
  \includegraphics[width=0.8\textwidth]{isar-vm}
29738
05d5615e12d3 added Isar/VM mode transition diagram;
wenzelm
parents: 29737
diff changeset
   767
  \end{center}
05d5615e12d3 added Isar/VM mode transition diagram;
wenzelm
parents: 29737
diff changeset
   768
  \caption{Isar/VM modes}\label{fig:isar-vm}
05d5615e12d3 added Isar/VM mode transition diagram;
wenzelm
parents: 29737
diff changeset
   769
  \end{figure}
05d5615e12d3 added Isar/VM mode transition diagram;
wenzelm
parents: 29737
diff changeset
   770
62275
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   771
  For example, in \<open>state\<close> mode Isar acts like a mathematical scratch-pad,
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   772
  accepting declarations like @{command fix}, @{command assume}, and claims
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   773
  like @{command have}, @{command show}. A goal statement changes the mode to
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   774
  \<open>prove\<close>, which means that we may now refine the problem via @{command
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   775
  unfolding} or @{command proof}. Then we are again in \<open>state\<close> mode of a proof
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   776
  body, which may issue @{command show} statements to solve pending sub-goals.
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   777
  A concluding @{command qed} will return to the original \<open>state\<close> mode one
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   778
  level upwards. The subsequent Isar/VM trace indicates block structure,
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   779
  linguistic mode, goal state, and inferences:
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   780
\<close>
29729
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   781
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   782
text_raw \<open>\begingroup\footnotesize\<close>
40964
482a8334ee9e prefer 'notepad' over 'example_proof';
wenzelm
parents: 40476
diff changeset
   783
(*<*)notepad begin
29729
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   784
(*>*)
58999
ed09ae4ea2d8 uniform treatment of all document markup commands: 'text' and 'txt' merely differ in LaTeX style;
wenzelm
parents: 58618
diff changeset
   785
  text_raw \<open>\begin{minipage}[t]{0.18\textwidth}\<close>
29729
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   786
  have "A \<longrightarrow> B"
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   787
  proof
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   788
    assume A
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   789
    show B
62271
4cfe65cfd369 more explicit dummy proofs;
wenzelm
parents: 61962
diff changeset
   790
      \<proof>
29729
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   791
  qed
58999
ed09ae4ea2d8 uniform treatment of all document markup commands: 'text' and 'txt' merely differ in LaTeX style;
wenzelm
parents: 58618
diff changeset
   792
  text_raw \<open>\end{minipage}\quad
29735
1da96affdefe misc tuning;
wenzelm
parents: 29733
diff changeset
   793
\begin{minipage}[t]{0.06\textwidth}
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   794
\<open>begin\<close> \\
29729
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   795
\\
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   796
\\
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   797
\<open>begin\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   798
\<open>end\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   799
\<open>end\<close> \\
29729
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   800
\end{minipage}
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   801
\begin{minipage}[t]{0.08\textwidth}
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   802
\<open>prove\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   803
\<open>state\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   804
\<open>state\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   805
\<open>prove\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   806
\<open>state\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   807
\<open>state\<close> \\
29735
1da96affdefe misc tuning;
wenzelm
parents: 29733
diff changeset
   808
\end{minipage}\begin{minipage}[t]{0.35\textwidth}
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   809
\<open>(A \<longrightarrow> B) \<Longrightarrow> #(A \<longrightarrow> B)\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   810
\<open>(A \<Longrightarrow> B) \<Longrightarrow> #(A \<longrightarrow> B)\<close> \\
29729
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   811
\\
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   812
\\
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   813
\<open>#(A \<longrightarrow> B)\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   814
\<open>A \<longrightarrow> B\<close> \\
29735
1da96affdefe misc tuning;
wenzelm
parents: 29733
diff changeset
   815
\end{minipage}\begin{minipage}[t]{0.4\textwidth}
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   816
\<open>(init)\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   817
\<open>(resolution impI)\<close> \\
29729
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   818
\\
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   819
\\
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   820
\<open>(refinement #A \<Longrightarrow> B)\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   821
\<open>(finish)\<close> \\
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   822
\end{minipage}\<close>
29729
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   823
(*<*)
40964
482a8334ee9e prefer 'notepad' over 'example_proof';
wenzelm
parents: 40476
diff changeset
   824
end
29729
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   825
(*>*)
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   826
text_raw \<open>\endgroup\<close>
29729
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   827
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   828
text \<open>
61420
ee42cba50933 redundant due to \parindent 0pt;
wenzelm
parents: 60618
diff changeset
   829
  Here the @{inference refinement} inference from
62275
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   830
  \secref{sec:framework-resolution} mediates composition of Isar sub-proofs
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   831
  nicely. Observe that this principle incorporates some degree of freedom in
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   832
  proof composition. In particular, the proof body allows parameters and
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   833
  assumptions to be re-ordered, or commuted according to Hereditary Harrop
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   834
  Form. Moreover, context elements that are not used in a sub-proof may be
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   835
  omitted altogether. For example:
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   836
\<close>
29729
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   837
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   838
text_raw \<open>\begin{minipage}{0.5\textwidth}\<close>
29729
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   839
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   840
(*<*)
40964
482a8334ee9e prefer 'notepad' over 'example_proof';
wenzelm
parents: 40476
diff changeset
   841
notepad
482a8334ee9e prefer 'notepad' over 'example_proof';
wenzelm
parents: 40476
diff changeset
   842
begin
29729
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   843
(*>*)
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   844
  have "\<And>x y. A x \<Longrightarrow> B y \<Longrightarrow> C x y"
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   845
  proof -
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   846
    fix x and y
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   847
    assume "A x" and "B y"
62271
4cfe65cfd369 more explicit dummy proofs;
wenzelm
parents: 61962
diff changeset
   848
    show "C x y" \<proof>
29729
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   849
  qed
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   850
58999
ed09ae4ea2d8 uniform treatment of all document markup commands: 'text' and 'txt' merely differ in LaTeX style;
wenzelm
parents: 58618
diff changeset
   851
text_raw \<open>\end{minipage}\begin{minipage}{0.5\textwidth}\<close>
29729
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   852
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   853
(*<*)
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   854
next
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   855
(*>*)
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   856
  have "\<And>x y. A x \<Longrightarrow> B y \<Longrightarrow> C x y"
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   857
  proof -
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   858
    fix x assume "A x"
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   859
    fix y assume "B y"
62271
4cfe65cfd369 more explicit dummy proofs;
wenzelm
parents: 61962
diff changeset
   860
    show "C x y" \<proof>
29729
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   861
  qed
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   862
58999
ed09ae4ea2d8 uniform treatment of all document markup commands: 'text' and 'txt' merely differ in LaTeX style;
wenzelm
parents: 58618
diff changeset
   863
text_raw \<open>\end{minipage}\\[3ex]\begin{minipage}{0.5\textwidth}\<close>
29729
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   864
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   865
(*<*)
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   866
next
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   867
(*>*)
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   868
  have "\<And>x y. A x \<Longrightarrow> B y \<Longrightarrow> C x y"
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   869
  proof -
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   870
    fix y assume "B y"
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   871
    fix x assume "A x"
62271
4cfe65cfd369 more explicit dummy proofs;
wenzelm
parents: 61962
diff changeset
   872
    show "C x y" \<proof>
29729
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   873
  qed
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   874
58999
ed09ae4ea2d8 uniform treatment of all document markup commands: 'text' and 'txt' merely differ in LaTeX style;
wenzelm
parents: 58618
diff changeset
   875
text_raw \<open>\end{minipage}\begin{minipage}{0.5\textwidth}\<close>
29729
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   876
(*<*)
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   877
next
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   878
(*>*)
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   879
  have "\<And>x y. A x \<Longrightarrow> B y \<Longrightarrow> C x y"
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   880
  proof -
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   881
    fix y assume "B y"
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   882
    fix x
62271
4cfe65cfd369 more explicit dummy proofs;
wenzelm
parents: 61962
diff changeset
   883
    show "C x y" \<proof>
29729
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   884
  qed
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   885
(*<*)
40964
482a8334ee9e prefer 'notepad' over 'example_proof';
wenzelm
parents: 40476
diff changeset
   886
end
29729
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   887
(*>*)
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   888
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   889
text_raw \<open>\end{minipage}\<close>
29729
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   890
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   891
text \<open>
61421
e0825405d398 more symbols;
wenzelm
parents: 61420
diff changeset
   892
  \<^medskip>
62275
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   893
  Such ``peephole optimizations'' of Isar texts are practically important to
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   894
  improve readability, by rearranging contexts elements according to the
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   895
  natural flow of reasoning in the body, while still observing the overall
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   896
  scoping rules.
29729
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   897
61421
e0825405d398 more symbols;
wenzelm
parents: 61420
diff changeset
   898
  \<^medskip>
62275
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   899
  This illustrates the basic idea of structured proof processing in Isar. The
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   900
  main mechanisms are based on natural deduction rule composition within the
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   901
  Pure framework. In particular, there are no direct operations on goal states
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   902
  within the proof body. Moreover, there is no hidden automated reasoning
29729
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   903
  involved, just plain unification.
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   904
\<close>
29729
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   905
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   906
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   907
subsection \<open>Calculational reasoning \label{sec:framework-calc}\<close>
29729
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   908
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   909
text \<open>
29735
1da96affdefe misc tuning;
wenzelm
parents: 29733
diff changeset
   910
  The existing Isar infrastructure is sufficiently flexible to support
62275
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   911
  calculational reasoning (chains of transitivity steps) as derived concept.
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   912
  The generic proof elements introduced below depend on rules declared as
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   913
  @{attribute trans} in the context. It is left to the object-logic to provide
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   914
  a suitable rule collection for mixed relations of \<open>=\<close>, \<open><\<close>, \<open>\<le>\<close>, \<open>\<subset>\<close>, \<open>\<subseteq>\<close>
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   915
  etc. Due to the flexibility of rule composition
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   916
  (\secref{sec:framework-resolution}), substitution of equals by equals is
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   917
  covered as well, even substitution of inequalities involving monotonicity
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   918
  conditions; see also @{cite \<open>\S6\<close> "Wenzel-PhD"} and @{cite
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   919
  "Bauer-Wenzel:2001"}.
29729
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   920
62275
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   921
  The generic calculational mechanism is based on the observation that rules
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   922
  such as \<open>trans:\<close>~@{prop "x = y \<Longrightarrow> y = z \<Longrightarrow> x = z"} proceed from the premises
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   923
  towards the conclusion in a deterministic fashion. Thus we may reason in
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   924
  forward mode, feeding intermediate results into rules selected from the
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   925
  context. The course of reasoning is organized by maintaining a secondary
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   926
  fact called ``@{fact calculation}'', apart from the primary ``@{fact this}''
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   927
  already provided by the Isar primitives. In the definitions below,
29735
1da96affdefe misc tuning;
wenzelm
parents: 29733
diff changeset
   928
  @{attribute OF} refers to @{inference resolution}
62275
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   929
  (\secref{sec:framework-resolution}) with multiple rule arguments, and
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   930
  \<open>trans\<close> represents to a suitable rule from the context:
29729
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   931
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   932
  \begin{matharray}{rcl}
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   933
    @{command "also"}\<open>\<^sub>0\<close> & \equiv & @{command "note"}~\<open>calculation = this\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   934
    @{command "also"}\<open>\<^sub>n\<^sub>+\<^sub>1\<close> & \equiv & @{command "note"}~\<open>calculation = trans [OF calculation this]\<close> \\[0.5ex]
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   935
    @{command "finally"} & \equiv & @{command "also"}~@{command "from"}~\<open>calculation\<close> \\
29729
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   936
  \end{matharray}
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   937
62275
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   938
  The start of a calculation is determined implicitly in the text: here
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   939
  @{command also} sets @{fact calculation} to the current result; any
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   940
  subsequent occurrence will update @{fact calculation} by combination with
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   941
  the next result and a transitivity rule. The calculational sequence is
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   942
  concluded via @{command finally}, where the final result is exposed for use
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   943
  in a concluding claim.
29729
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   944
62275
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   945
  Here is a canonical proof pattern, using @{command have} to establish the
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   946
  intermediate results:
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   947
\<close>
29729
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   948
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   949
(*<*)
40964
482a8334ee9e prefer 'notepad' over 'example_proof';
wenzelm
parents: 40476
diff changeset
   950
notepad
482a8334ee9e prefer 'notepad' over 'example_proof';
wenzelm
parents: 40476
diff changeset
   951
begin
29729
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   952
(*>*)
62271
4cfe65cfd369 more explicit dummy proofs;
wenzelm
parents: 61962
diff changeset
   953
  have "a = b" \<proof>
4cfe65cfd369 more explicit dummy proofs;
wenzelm
parents: 61962
diff changeset
   954
  also have "\<dots> = c" \<proof>
4cfe65cfd369 more explicit dummy proofs;
wenzelm
parents: 61962
diff changeset
   955
  also have "\<dots> = d" \<proof>
29729
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   956
  finally have "a = d" .
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   957
(*<*)
40964
482a8334ee9e prefer 'notepad' over 'example_proof';
wenzelm
parents: 40476
diff changeset
   958
end
29729
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   959
(*>*)
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   960
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   961
text \<open>
62275
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   962
  The term ``\<open>\<dots>\<close>'' above is a special abbreviation provided by the
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   963
  Isabelle/Isar syntax layer: it statically refers to the right-hand side
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   964
  argument of the previous statement given in the text. Thus it happens to
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   965
  coincide with relevant sub-expressions in the calculational chain, but the
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   966
  exact correspondence is dependent on the transitivity rules being involved.
29729
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   967
61421
e0825405d398 more symbols;
wenzelm
parents: 61420
diff changeset
   968
  \<^medskip>
62275
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   969
  Symmetry rules such as @{prop "x = y \<Longrightarrow> y = x"} are like transitivities with
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   970
  only one premise. Isar maintains a separate rule collection declared via the
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   971
  @{attribute sym} attribute, to be used in fact expressions ``\<open>a
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   972
  [symmetric]\<close>'', or single-step proofs ``@{command assume}~\<open>x = y\<close>~@{command
374d1b6c473d tuned whitespace;
wenzelm
parents: 62271
diff changeset
   973
  then}~@{command have}~\<open>y = x\<close>~@{command ".."}''.
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   974
\<close>
29729
c2e926455fcc more on Isar framework -- mostly from Trybulec Festschrift;
wenzelm
parents: 29721
diff changeset
   975
29742
8edd5198dedb tuned spacing;
wenzelm
parents: 29739
diff changeset
   976
end